论坛风格切换
  • 3005阅读
  • 0回复

[常用修复工具]修复主题最后回复的工具 [复制链接]

上一主题 下一主题
离线太史慈
 

发帖
766
金币
626
威望
556
只看楼主 倒序阅读 使用道具 楼主  发表于: 2011-11-19
有些老帖子被顶上来后,要把他弄沉下去,要用这个程序更新处理一下。他会自动更新pw_threads的最后回复时间,和回复人。
至于程序里面为什么不处理,呵呵,性能会有问题的。

保存成repair_lastpost.php,放到pw的根目录下执行。

为了安全起见,最好备分下数据库。
  1. <?php
  2. error_reporting(0);
  3. define('P_W',1);
  4. define('PW_UPLOAD',1);
  5. define('R_P',getdirname(__FILE__));
  6. define('D_P',R_P);
  7. require_once(R_P.'require/common.php');
  8. //require_once(R_P.'lang/up_function.php');
  9. include_once(D_P.'data/bbscache/config.php');
  10. require_once(R_P.'admin/cache.php');
  11. $basename = 'http://'.$_SERVER['HTTP_HOST'].(isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']);
  12. @header("Content-Type:text/html; charset=$db_charset");
  13. include_once(D_P.'data/sql_config.php');
  14. //if ($database=='mysqli' && Pwloaddl('mysqli')===false) {
  15. $database = 'mysql';
  16. require_once Pcv(R_P."require/db_$database.php");
  17. $db = new DB($dbhost,$dbuser,$dbpw,$dbname,$PW,$charset,$pconnect);
  18. $action = $_GET['action'];
  19. $start = $_GET['start'];
  20. !$start && $start = 0;
  21. $percount = 1000;
  22. if (empty($action)) {
  23.     echo '<a href="repair_lastpost.php?action=thread">开始运行修复主题最后发帖工具</a><br /><a href="repair_lastpost.php?action=forum">开始运行修复板块最后发帖工具</a>';exit;
  24. } elseif ($action == 'forum') {
  25.     $query = $db->query("SELECT * FROM pw_forums");
  26.     while ($rt = $db->fetch_array($query)) {
  27.         $last = $db->get_one("SELECT * FROM pw_threads WHERE fid=".$rt['fid']." AND ifcheck=1 ORDER BY lastpost DESC");
  28.         $new_url  = "read.php?tid=$last[tid]";
  29.         $lastpost = $last['subject']."\t".addslashes($last['author'])."\t".$last['postdate']."\t".$new_url;
  30.         $db->update("UPDATE pw_forumdata SET lastpost='".$lastpost."' WHERE fid=".$rt['fid']." LIMIT 1");
  31.     }
  32.     echo '修复板块最后发帖结束';exit;
  33. } elseif ($action == 'thread') {
  34.     require (R_P.'require/updateforum.php');
  35.     $query = $db->query("SELECT tid,ptable,replies,author,postdate FROM pw_threads WHERE tid>$start ORDER BY tid LIMIT $percount");
  36.     while ($rt = $db->fetch_array($query)) {
  37.         ADD_S($rt);
  38.         $lastid = $rt['tid'];
  39.         if($rt['replies']>0){
  40.             $pw_posts = GetPtable($rt['ptable']);
  41.             $last = $db->get_one("SELECT pid,author,postdate FROM $pw_posts WHERE tid=".$rt['tid']." AND ifcheck=1 ORDER BY postdate DESC LIMIT 1");
  42.             if($last['postdate']){
  43.                 $db->update("UPDATE pw_threads SET lastpost=".$last['postdate'].",lastposter='".addslashes($last['author'])."' WHERE tid=".$rt['tid']." LIMIT 1");
  44.             }
  45.         }else{
  46.             $db->update("UPDATE pw_threads SET lastpost=".$rt['postdate'].",lastposter='".addslashes($rt['author'])."' WHERE tid=".$rt['tid']." LIMIT 1");
  47.         }
  48.     }
  49.     $maxid = $db->get_value("SELECT max(tid) FROM pw_threads");
  50.     if ($lastid < $maxid) {
  51.         echo "<meta http-equiv='refresh' content='0;url=$basename?action=last&start=$lastid'>";
  52.     }else{
  53.         echo '修复最后发帖结束';exit;
  54.     }
  55. }
  56. function getdirname($path=null){
  57.     if (!empty($path)) {
  58.         if (strpos($path,'\\')!==false) {
  59.             return substr($path,0,strrpos($path,'\\')).'/';
  60.         } elseif (strpos($path,'/')!==false) {
  61.             return substr($path,0,strrpos($path,'/')).'/';
  62.         }
  63.     }
  64.     return './';
  65. }
  66. function createtable($array){
  67.     global $db,$charset;
  68.     foreach ($array as $key => $value) {
  69.         !$value[1] && $value[1] = 'MyISAM';
  70.         $value[0] = "CREATE TABLE IF NOT EXISTS $key ($value[0]) ";
  71.         if ($db->server_info() > '4.1') {
  72.             $value[0] .= "ENGINE=$value[1]".($charset ? " DEFAULT CHARSET=$charset" : '');
  73.         } else {
  74.             $value[0] .= "TYPE=$value[1]";
  75.         }
  76.         $db->query($value[0]);
  77.     }
  78. }
  79. ?>

[url=http://www.phpwind.com]phpwind[/url]
快速回复
限100 字节
如果您提交过一次失败了,可以用”恢复数据”来恢复帖子内容
 
提到某人:
选择好友
上一个 下一个