vBulletin HACK----话题置顶


原因:1.1.4版本中没有此功能。将重要的话题置顶,会是一个很好的功能。
优点:充分利用原有数据库的结构,不需要更改,安全、有效。
自评:这是从雨声的UBB得到的灵感,实现不是太难,代码是多了些,但不会影响论坛的运行速度,因为几乎全部代码都在判断语句中。

步骤:
⒈打开 forumdisplay.php (显示部分),查找“
$threads=$DB_site->query("SELECT thread.iconid, icon.title AS icontitle, icon.iconpath,threadid,thread.title AS title,
                                 open,lastpost,replycount,postusername,lastposter,notes,views,userindex
                          FROM thread
                          LEFT JOIN icon ON (icon.iconid = thread.iconid)
                          WHERE forumid=$forumid AND visible=1 $datecut
                          ORDER BY lastpost
                          DESC LIMIT $limitlower,$perpage");

$forumdisplaybits = "";
”,替换为“

// Hack set top
// get settop thread
$forumdisplaybits = "";
if ($threads=$DB_site->query("SELECT thread.iconid, icon.title AS icontitle, icon.iconpath,threadid,thread.title AS title,
                                 open,lastpost,replycount,postusername,lastposter,notes,views,userindex
                          FROM thread
                          LEFT JOIN icon ON (icon.iconid = thread.iconid)
                          WHERE forumid=$forumid AND open>1 AND visible=1 $datecut
                          ORDER BY lastpost
                          DESC LIMIT $limitlower,$perpage"));


while ($thread=$DB_site->fetch_array($threads)) {

  // Hack thread size
  $size=0;
  $posts=$DB_site->query("SELECT pagetext FROM post WHERE threadid=".$thread[threadid]);
  while ($post=$DB_site->fetch_array($posts)) $size+=strlen($post[pagetext]);
  $size=iif($size>1024,number_format($size/1024,1)."K",$size);
  // End Hack thread size

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

    $totalpages=($thread[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=$thread[threadid]&pagenumber=lastpage">后面页</a>";
        break;
      } else {
        $pagenumbers.=" <a href="showthread.php?threadid=$thread[threadid]&pagenumber=$acurpage">$acurpage</a> ";
      }
    }
    eval("$pagenav = "".gettemplate("multipagenav")."";");
  } else {
    $pagenav="";
  }

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

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

  $notes=htmlspecialchars($thread[notes]);
  $replies=$thread[replycount];
  $views=$thread[views];
  $firstposter=htmlspecialchars($thread[postusername]);
  $lastposter=htmlspecialchars($thread[lastposter]);
  $lastreplydate=date($dateformat,$thread[lastpost]+(($timeoffset+$bbtimezoneoffset)*3600));
  $lastreplytime=date($timeformat,$thread[lastpost]+(($timeoffset+$bbtimezoneoffset)*3600));

  $gotonew="";

  $newoldhot="folder";
  if ($thread[open]%2==0) {
    $newoldhot="lock".$newoldhot;
  }
  if ($thread[replycount]>=$hotnumber and $usehotthreads==1) {
    $newoldhot="hot".$newoldhot;
  }
  if ($lastvisitdate=="Never") {
    $newoldhot="new".$newoldhot;
  } elseif ($thread[lastpost]>$bblastvisit) {
      $newoldhot="new".$newoldhot;
      eval("$gotonew = "".gettemplate("forumdisplay_gotonew")."";");
  }

  eval("$forumdisplaybits .= "".gettemplate("$usetemplatebit")."";");

}

$threads=$DB_site->query("SELECT thread.iconid, icon.title AS icontitle, icon.iconpath,threadid,thread.title AS title,
                                 open,lastpost,replycount,postusername,lastposter,notes,views,userindex
                          FROM thread
                          LEFT JOIN icon ON (icon.iconid = thread.iconid)
                          WHERE forumid=$forumid AND open<2 AND visible=1 $datecut
                          ORDER BY lastpost
                          DESC LIMIT $limitlower,$perpage");

// End Hack set top
”,此替代段包含本人的话题大小/Size Hack,如果你没有加入,则将“
  // Hack thread size
  $size=0;
  $posts=$DB_site->query("SELECT pagetext FROM post WHERE threadid=".$thread[threadid]);
  while ($post=$DB_site->fetch_array($posts)) $size+=strlen($post[pagetext]);
  $size=iif($size>1024,number_format($size/1024,1)."K",$size);
  // End Hack thread size
”去掉;查找“
  if ($thread[open]==0) {
”,替换为“
  if ($thread[open]%2==0) {
”,保存退出。

⒉打开 posting.php (设置部分),查找“
  if ($threadinfo[open]==1) {
    $DB_site->query("UPDATE thread SET open=0 WHERE threadid=$threadid");
    $action="closing";
  } else {
    $DB_site->query("UPDATE thread SET open=1 WHERE threadid=$threadid");
    $action="opening";
  }
”,替换为“
  if ($threadinfo[open]%2==1) {
    $DB_site->query("UPDATE thread SET open=open-1 WHERE threadid=$threadid");
    $action="关闭";
  } else {
    $DB_site->query("UPDATE thread SET open=open+1 WHERE threadid=$threadid");
    $action="打开";
  }
”(在本人的汉化包装内,此段有两个字没有翻译);在最后加入“
// ############################### start settop thread ###############################
if ($action=="settopthread") {

  $threadid = verifyid("thread",$threadid);

  $threadinfo=$DB_site->query_first("SELECT title,forumid FROM thread WHERE threadid=$threadid");
  if ($wordwrap!=0) {
    $threadinfo[title]=dowordwrap($threadinfo[title]);
  }
  $threadtitle=htmlspecialchars($threadinfo[title]);

  $getthread=$DB_site->query_first("SELECT forumid FROM thread WHERE threadid=$threadid");
  $forumid=$getthread[forumid];
  $foruminfo=$DB_site->query_first("SELECT active,allowposting,title FROM forum WHERE forumid=$forumid");
  $forumtitle=$foruminfo[title];
  if ($foruminfo[active]==0) {
    echo standarderror($bbtitle,gettemplate("error_forumclosed",0));
    exit;
  }

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

  $permissions=getpermissions($bbuserid,$bbusergroupid,$forumid);
  if ($permissions[canview]==0 or ($permissions[canopenclose]==0 and $permissions[canadminedit]==0)) {
    $firstpostinfo=$DB_site->query_first("SELECT userid FROM post WHERE threadid=$threadid ORDER BY dateline LIMIT 1");
    eval("echo standarderror($bbtitle,"".gettemplate("error_nopermission")."");");
    exit;
  } elseif ($permissions[canadminedit]==0) {
    $firstpostinfo=$DB_site->query_first("SELECT userid FROM post WHERE threadid=$threadid ORDER BY dateline LIMIT 1");
    if ($bbuserid!=$firstpostinfo[userid]) {
      eval("echo standarderror($bbtitle,"".gettemplate("error_nopermission")."");");
      exit;
    }
  }

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

}

// ############################### start do settop thread ###############################
if ($action=="dosettop") {

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

  $getthread=$DB_site->query_first("SELECT forumid FROM thread WHERE threadid=$threadid");
  $forumid=$getthread[forumid];

  $foruminfo=$DB_site->query_first("SELECT active,allowposting FROM forum WHERE forumid=$forumid");
  if ($foruminfo[active]==0) {
    echo standarderror($bbtitle,gettemplate("error_forumclosed",0));
    exit;
  }
  $threadinfo=$DB_site->query_first("SELECT open FROM thread WHERE threadid=$threadid");

  $permissions=getpermissions($bbuserid,$bbusergroupid,$forumid);
  if ($permissions[canview]==0 or ($permissions[canopenclose]==0 and $permissions[canadminedit]==0)) {
    $firstpostinfo=$DB_site->query_first("SELECT userid FROM post WHERE threadid=$threadid ORDER BY dateline LIMIT 1");
    eval("echo standarderror($bbtitle,"".gettemplate("error_nopermission")."");");
    exit;
  } elseif ($permissions[canadminedit]==0) {
    $firstpostinfo=$DB_site->query_first("SELECT userid FROM post WHERE threadid=$threadid ORDER BY dateline LIMIT 1");
    if ($bbuserid!=$firstpostinfo[userid]) {
      eval("echo standarderror($bbtitle,"".gettemplate("error_nopermission")."");");
      exit;
    }
  }

  // 3 = Open and Top; 2 = Close and Top
  // 1 = Open; 0 = Close
  if ($threadinfo[open]%2==0) {
    $DB_site->query("UPDATE thread SET open=open+2 WHERE threadid=$threadid");
    $action="设置置顶";
  } else {
    $DB_site->query("UPDATE thread SET open=open-2 WHERE threadid=$threadid");
    $action="取消置顶";
  }

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

}
”,保存退出。

⒊控制面板->模板->添加,《settopthread》,内容为“
{htmldoctype}
<HTML>
<HEAD>
<TITLE>$bbtitle - 设置 / 取消话题置顶</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><a href="index.php">$bbtitle</A> &gt; <a href="forumdisplay.php?forumid=$forumid">$forumtitle</a><br><a href="showthread.php?threadid=$threadid">$threadtitle</a></b></normalfont>

</td><td nowrap align="right">
<smallfont>只有论坛领导(管理员,版主)<br>才可以设置或取消此话题的置顶.</smallfont>
</td></tr></table>

<table border=0 cellpadding=4 border=0 cellspacing=1 width=100%>
<FORM ACTION="postings.php" METHOD="POST">
<tr bgcolor="{tableheadbgcolor}"><TD COLSPAN=2>
<normalfont color="{tableheadtextcolor}"><B>设置 / 取消话题置顶</B></normalfont></td></tr>
<tr bgcolor="{firstaltcolor}"><td>
<normalfont><B>您的用户名:</b></normalfont></td>
<td>
<INPUT TYPE="TEXT" NAME="username" VALUE="$username" SIZE=25 MAXLENGTH=25>&nbsp;&nbsp;
<smallfont><A HREF="member.php?action=signup">想注册为用户?</a></smallfont>
</td></tr>

<tr bgcolor="{secondaltcolor}">
<td>
<normalfont><b>您的密码:</b></normalfont></td>
<td><INPUT TYPE="PASSWORD" NAME="password" VALUE="$password" SIZE=13 MAXLENGTH=13>&nbsp;&nbsp;<smallfont><A HREF="member.php?action=lostpw">忘记您的密码?</A></smallfont>
</td></tr>
</table>

<p align="center">
<INPUT TYPE="SUBMIT" NAME="Submit" VALUE="提交身份认证">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="doopenclose">
<INPUT TYPE="HIDDEN" NAME="threadid" VALUE="$threadid">
</p>
</form>

$footer
”,保存。

⒋控制面板->模板->编辑,打开 showthread ,查找“
<a href="postings.php?action=openclosethread&threadid=$threadid">打开/关闭帖子</a><br>
”,在后面加入“
<a href="postings.php?action=settopthread&threadid=$threadid">设置/取消话题置顶</a><br>
”,保存。完成!