/* ** 插件名称:博客新贴调用插件 for PW/blog 4.x ** 原 作 者:bg9cx ** 修 改:无言沙漠(deserts) ** 最后更新:2006.01.12 ** 使用说明: ** 1.把插件文件newblog.php复制到博客的根目录,根据你的情况设置$lockurl,$forumurl,$cachetime的值。 ** 2.调用方法 ** 在首页(也可是其他页面)里加入(里面的路径请根据实际情况修改) ** <script src="http://yourhost/blog/newblog.php?cidin=xx&orders=xx&info=xx&num=xx&length=xx&pre=xx&uid=xx"></script> ** 参数说明: ** cidin(out):是调用博客的板块参数,整个博客调用 cidin=all,调用第一个板块:cidid=1;调用2,3板块:cidid=2_3; ** 不显示2和10两个博客的新帖cidout=2_10;依次类推, ** orders(可选,默认为0): 新贴排序方式(0最后回复时间1点击2发表时间) ** num(可选,默认为10): 调用新帖的数目 ** length(可选,默认为70):新贴标题长度限制 ** pre(可选,默认为1): 新贴标题显示前缀参数 ** info(可选): 新贴标题后增加显示信息(0) ** uid(可选): blog的用户id ** 例子:<script src="http://blog.5y6s.net/newblog.php?cidin=all&num=10&length=30&orders=2&pre=1&info=1&uid=2"></script> ** 演示:http://bbs.5y6s.net/profile.php?action=show&uid=2 ** 没有开通“静态目录”功能的朋友将“blog/htm/do_showone/”修改成“blog.php?do_showone/” */
代码:
CODE: <?php $lockurl = '5y6s.net'; //允许调用网址,为空则不开放此功能.如果你的首页为[url]www.5y6s.net[/url]则只需要修改为5y6s.net其他东西不要加 $forumurl = '[url]http://blog.5y6s.net[/url]'; //博客地址。后面不要加'/' $cachetime = '6'; //缓存文件更新时间单位秒
$headin[0] = '<li>';// 标题前字符,可以用图片:<img src=http://localhost/20youth/forum/logo.gif border=0> $headin[1] = '◇ '; $headin[2] = '· '; $headin[3] = '○ '; $headin[4] = '● '; $headin[5] = ''; $info_color = 'red';//标题后增加显示信息颜色,例如作者,时间,点击数
error_reporting(0); set_magic_quotes_runtime(0); if (!get_magic_quotes_gpc()) { Add_S($_GET); } //if (trim($lockurl)==""||strpos($_SERVER['HTTP_REFERER'],$lockurl)===false) //{ // exit("document.write(\"数据被保护,禁止被其他站点调用!或者你没有设置\$lockurl参数。\");"); //} $cidin = $_GET['cidin']; $cidout = $_GET['cidout']; $good = $_GET['good']; $info = $_GET['info']; $num = $_GET['num'] ? $_GET['num'] : 10; $length = $_GET['length'] ? $_GET['length'] : 70; $pre = $_GET['pre'] ? $headin[$_GET['pre']] : $headin[0]; $orders = $_GET['orders'] ? $_GET['orders'] : 0; $uid = $_GET['uid'];
if ($orders == 0) { $listorder='lastpost'; } else if ($orders == 1) { $listorder='hits'; } else if ($orders == 2) { $listorder='postdate'; } else if ($orders ==3 ) { $listorder='lastpost'; } else { $listorder='lastpost'; } $cachefile = './data/cache/new_'.md5("$cidin$cidout$orders$good$num$length$pre$info").'.php';
if ((time() - @filemtime($cachefile) >= $cachetime)) { require 'data/sql_config.php'; mysql_connect($dbhost, $dbuser, $dbpw); mysql_select_db($dbname);
$forumadd = ''; if($cidin != 'all') { $cidin && $forumadd = 'WHERE cid IN (\''.str_replace('_', '\',\'', $cidin).'\')'; $cidout&& $forumadd = 'WHERE cid NOT IN (\''.str_replace('_', '\',\'', $cidout).'\')'; } if ($good == 'yes' && $cidin != 'all') { $forumadd .= "and digest>0"; } if ($good == 'yes' && $cidin == 'all') { $forumadd = "where digest>0"; }
$query = mysql_query("SELECT tid,cid,uid,icon,author,authorid,subject,postdate,hits FROM {$PW}blog where uid=$uid $forumadd ORDER BY $listorder DESC LIMIT 0, $num") or die(mysql_error()); $newlist=""; while ($threads = mysql_fetch_array($query)) { $threads[subject] = substrs($threads[subject], $length); //没有开通“静态目录”功能的朋友将“blog/htm/do_showone/”修改成“blog.php?do_showone/” $newlist .= "document.write(\"<a href=$forumurl/blog/htm/do_showone/tid_$threads[tid].html target=_blank>$pre$threads[subject]</a>\");\n"; switch($info) { case "1"://时间作者 $posttime=date("Y-m-d H:i",$threads[postdate]); $newlist.="document.write(\"(<font color=$info_color>$posttime</font>by<a href=http://$threads[author].5y6s.net/ target=_blank>$threads[author]</a>)<br>\");\n"; break; case "2"://时间 $posttime=date("Y-m-d H:i",$threads[postdate]); $newlist.="document.write(\"(<font color=$info_color>$posttime</font>)<br>\");\n"; break; case "3"://作者 $newlist.="document.write(\"(<a href=http://$threads[author].5y6s.net/ target=_blank><font color=$info_color>$threads[author]</font></a>)<br>\");\n"; break; case "4"://点击 $newlist.="document.write(\"(<font color=$info_color>$threads[hits]</font>)<br>\");\n"; break; default: $newlist.="document.write(\"<br>\");\n"; } } $newlist=$newlist; if($newlist==""){ $newlist="document.write(\"什么都没有!<img src=$forumurl/p_w_picpath/noblog.gif>\");\n"; } echo $newlist; @writeover($cachefile,$newlist); } else { @include($cachefile); } /** *函数列表 */ function writeover($filename,$data,$method="rb+",$iflock=1){ touch($filename); $handle=fopen($filename,$method); if($iflock){ flock($handle,LOCK_EX); } fputs($handle,$data); if($method=="rb+") ftruncate($handle,strlen($data)); fclose($handle); } function substrs($content,$length) { if(strlen($content)>$length){ $num=0; for($i=0;$i<$length-3;$i++) { if(ord($content[$i])>0xa0)$num++; } $num%2==1 ? $content=substr($content,0,$length-4):$content=substr($content,0,$length-3); $content.=' ...'; } return $content; } function Add_S(&$array){ foreach($array as $key=>$value){ if(!is_array($value)){ $array[$key]=addslashes($value); }else{ Add_S($array[$key]); } } } ?>
下面是完整的代码 |