vBulletin HACK----书签/收藏夹


原因:vBulletin没有,此功能能方便注册用户将一些自己觉得有用的话题收藏起来,以便日后浏览,或随时查阅。
优点:只增加了一个数据表,而且秉承我一贯的作风,采用伸缩记录法——有记录则记录、无记录则留空。不浪费数据库空间。
缺点:因为数据表的结构和管理程序都很简单,所以没有采用目录式管理,也许对于书签比较多的用户管理上会有些麻烦。但因为功能不一定颇受欢迎,所以没有弄得太复杂。也许有些朋友喜欢收藏的是帖子(Post)而不是话题(Thread)。
自评:从ActiveUBB得到的灵感,觉得这个玩意的实用性还有些,所以……

步骤:
⒈打开你管理MySQL的工具(以往我是些一个程序做的,但我觉得应该自己去了解一下,如果实在不想,再向我索取这个程序),打开讨论区的数据库,输入“
CREATE TABLE favorites (
  userid INT UNSIGNED NOT NULL,
  threadid INT UNSIGNED NOT NULL,
  dateline INT UNSIGNED NOT NULL
)
”,建立一张表,退出;

⒉将以下文字贴到名为 favorites.php 的新文件当中,上载到讨论区根目录下:“
<?php

require("global.php");

checkipban();

if (isset(
$action)==and $action=="") {
  
$action="view";
}

  
$username=$bbusername;
  
$password=$bbpassword;

  
//check valid username and password and get user id
  
$userid=verifyusername($username,$password);

// ############################### start add favorites ###############################
if ($action=="add") {

  
// Check if user added
  
if ($favsinfo=$DB_site->query_first("SELECT * FROM favorites WHERE userid=$userid AND threadid=$threadid")) {
    echo 
standarderror($bbtitle,gettemplate("error_favadded",0));
    exit;
  }

  
$DB_site->query("INSERT INTO favorites VALUES ($userid,$threadid,".time().")");

  eval(
"echo standardredirect($bbtitle,"".gettemplate("redirect_favaddthanks")."","showthread.php?threadid=$threadid");");
}

// ############################### start view favorites ###############################
if ($action=="view") {

  if (
$userfavs=$DB_site->query("SELECT favorites.dateline AS adddate,thread.forumid,
                                        thread.title AS title,user.username,
                                        thread.dateline AS threaddate,thread.iconid,
                                        favorites.threadid,icon.iconpath,
                                        icon.title AS icontitle,thread.replycount
                                        FROM favorites
                                        LEFT JOIN thread ON (thread.threadid = favorites.threadid) 
                                        LEFT JOIN user ON (user.userid = $userid) 
                                        LEFT JOIN icon ON (icon.iconid = thread.iconid)
                                        WHERE favorites.userid=$userid
                                        ORDER BY favorites.dateline DESC"
)) {
    while (
$userfav=$DB_site->fetch_array($userfavs)) {

      
$counter++;

      
$threadid=$userfav[threadid];
      
$forumid=$userfav[forumid];

      
$threaddate=date($dateformat,$userfav[threaddate]+(($timeoffset+$bbtimezoneoffset)*3600));
      
$threadtime=date($timeformat,$userfav[threaddate]+(($timeoffset+$bbtimezoneoffset)*3600));
      
$favdate=date($dateformat,$userfav[adddate]+(($timeoffset+$bbtimezoneoffset)*3600));
      
$favtime=date($timeformat,$userfav[adddate]+(($timeoffset+$bbtimezoneoffset)*3600));

      if (
$wordwrap!=0) {
        
$userfav[title]=dowordwrap($userfav[title]);
      }
      
$threadtitle=htmlspecialchars($userfav[title]);

      if (
$showicons==and $userfav[iconid]!=0) {
        
$threadicon="<img src="$userfav[iconpath]" alt="$userfav[icontitle]" border=0>";
      } else {
        
$threadicon="&nbsp;";
      }

      
$threadusername=htmlspecialchars($userfav[username]);

// thread multipage
  
if (($userfav[replycount]+1)>$maxposts and $linktopages==1) {

    
$totalpages=($userfav[replycount]+1)/$maxposts;
    if (
$totalpages!=intval($totalpages)) {
      
$totalpages=intval($totalpages)+1;
    }

    
$acurpage=0;
    
$pagenumbers="";
    while (
$acurpage++<$totalpages) {
      if (
$acurpage==$maxmultipage) {
        
$pagenumbers.=" ... <a href="showthread.php?threadid=$threadid&pagenumber=lastpage">后面页</a>";
        break;
      } else {
        
$pagenumbers.=" <a href="showthread.php?threadid=$threadid&pagenumber=$acurpage">$acurpage</a> ";
      }
    }
    eval(
"$pagenav = "".gettemplate("multipagenav")."";");
  } else {
    
$pagenav="";
  }

// end thread multipage

    
eval("$showfavbits .= "".gettemplate("showfavbit")."";");

    }
  }
  if (
$counter==0) {
    
$showfavbits "<tr><td colspan=6 align=center bgcolor="{secondaltcolor}">无</td></tr>";
  } else {
    
$showdelete="    <p align=right><input type=submit name=dodelete value=删除>
    <input type=hidden name=action value=dodelete>
    <input type=hidden name=favs value=$counter>"
;
  }

// parse header ##################
$foruminfo=$DB_site->query_first("SELECT title,description,categoryid,active,titleimage,threadtemplate,threadbittemplate,replyimage,newthreadimage,closedthreadimage,headertemplate,useadvheader,footertemplate,useadvfooter,rulestemplate,allowbbcode,allowimages,allowhtml,allowsmilies FROM forum WHERE forumid=1");

if (
$foruminfo[headertemplate]!="") {
  if (
$foruminfo[useadvheader]==1) {
    eval(
gettemplate("$foruminfo[headertemplate]").";");
  } else {
    eval(
"$header = "".gettemplate("$foruminfo[headertemplate]")."";");
  }
}
if (
$foruminfo[footertemplate]!="") {
  if (
$foruminfo[useadvfooter]==1) {
    eval(
gettemplate("$foruminfo[footertemplate]").";");
  } else {
    eval(
"$footer = "".gettemplate("$foruminfo[footertemplate]")."";");
  }
}

eval(
"echo dovars("".gettemplate("showfav")."");");


}

// ############################### start delete favorites ###############################
if ($action=="dodelete") {

  for (
$i=1$i<=$favs$i++) {
    if (${
"d$i"}<>"") {
      
$DB_site->query("DELETE FROM favorites WHERE threadid=${"d$i"} AND userid=$userid");
    }
  }
  eval(
"echo standardredirect($bbtitle,"".gettemplate("redirect_favdelthanks")."","favorites.php");");
}

?>
”;

⒊控制面板->模板->新增,新增 error_favadded ,内容“
此话题已经存在于您的收藏夹内!请使用后退键自行返回话题
”,新增 redirect_favaddthanks ,内容“
感谢您收藏话题, $username. 您现在将返回该话题.
”,新增 redirect_favdelthanks ,内容“
感谢您删除您的话题收藏, $username. 您现在将返回该话题.
”,新增 showfav ,内容“
{htmldoctype}
<HTML>
<HEAD><TITLE>$bbtitle - $username 的收藏夹</title>
$cssinclude
</head>
<body>
$header


<table border="0" width="100%"><tr>
<td valign="top" align="left"><a href="index.php"><img src="$titleimage" border="0"></a></td>
<td valign="middle" align="center" nowrap>$fivelinks</td>
</tr></table>

<table border="0" width="100%" cellpadding="2"><tr>
<td width="100%"><normalfont><b>$username 的收藏夹</b></normalfont></td>
</tr></table>

<form action=favorites.php method=post>
<table width=100% border=0 cellspacing=1 cellpadding=4>
<TR>
<td align=center bgcolor="{tableheadbgcolor}">&nbsp;
</td>

<td bgcolor="{tableheadbgcolor}" width="100%"><smallfont COLOR="{tableheadtextcolor}"><B>话题</B></smallfont></td>

<td align=center bgcolor="{tableheadbgcolor}" nowrap><smallfont COLOR="{tableheadtextcolor}"><B>发起人</B></smallfont>
</td>

<td align=center bgcolor="{tableheadbgcolor}" nowrap><smallfont COLOR="{tableheadtextcolor}"><B>发起时间</B></smallfont>
</td>

<td align=center bgcolor="{tableheadbgcolor}" nowrap><smallfont COLOR="{tableheadtextcolor}"><B>收藏时间</B></smallfont>
</td>

<td bgcolor="{tableheadbgcolor}" nowrap><smallfont COLOR="{tableheadtextcolor}"><B>删除</B></smallfont></td></tr>

$showfavbits

</table>
$showdelete
</form>
$footer

</body>
</html>
”,新增 showfavbit ,内容“
<TR>
<td align=center bgcolor="{secondaltcolor}">
$threadicon
</td>

<td bgcolor="{firstaltcolor}" width="100%"><normalfont>
<A HREF="showthread.php?threadid=$threadid" target="_blank"><img src="images/newwin.gif" border="0"></a>
<A HREF="showthread.php?threadid=$threadid">$threadtitle</a>
<smallfont>$pagenav</smallfont></normalfont>
</td>

<td align=center bgcolor="{secondaltcolor}" nowrap>
<normalfont>$threadusername</normalfont>
</td>

<td align=center bgcolor="{firstaltcolor}" nowrap>
<normalfont>$threaddate $threadtime</normalfont>
</td>

<td align=center bgcolor="{secondaltcolor}" nowrap>
<normalfont>$favdate $favtime</normalfont>
</td>

<td bgcolor="{firstaltcolor}" align=center>
<normalfont><input type=checkbox name=d$counter value=$threadid></normalfont>
</td></tr>
”;

⒋控制面板->模板->编辑,编辑 fivelinks ,有你觉得适当的位置,加入“
<A HREF="favorites.php?action=view"><img src="images/top_favorites.gif" alt="收藏夹/书签" border=0></A>
”(当然,你得准备一个 top_favorites.gif 这个图象文件),保存;编辑 showthread ,查找“
<smallfont><img src="images/printer.gif" border="0"> <a href="printthread.php?threadid=$threadid">可打印版本</a></smallfont>
”,在后面加入“
<smallfont><img src="images/favorites.gif" border="0"> <a href="favorites.php?action=add&threadid=$threadid">收藏此话题</a></smallfont>
”,保存,退出,完成!

使用很方便,全部已经做了连接。
范例:http://gogosoft.oso.com.cn/forum/