|
有些老帖子被顶上来后,要把他弄沉下去,要用这个程序更新处理一下。他会自动更新pw_threads的最后回复时间,和回复人。 至于程序里面为什么不处理,呵呵,性能会有问题的。 保存成repair_lastpost.php,放到pw的根目录下执行。 为了安全起见,最好备分下数据库。 - <?php
- error_reporting(0);
- define('P_W',1);
- define('PW_UPLOAD',1);
- define('R_P',getdirname(__FILE__));
- define('D_P',R_P);
- require_once(R_P.'require/common.php');
- //require_once(R_P.'lang/up_function.php');
- include_once(D_P.'data/bbscache/config.php');
- require_once(R_P.'admin/cache.php');
- $basename = 'http://'.$_SERVER['HTTP_HOST'].(isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']);
- @header("Content-Type:text/html; charset=$db_charset");
- include_once(D_P.'data/sql_config.php');
- //if ($database=='mysqli' && Pwloaddl('mysqli')===false) {
- $database = 'mysql';
- require_once Pcv(R_P."require/db_$database.php");
- $db = new DB($dbhost,$dbuser,$dbpw,$dbname,$PW,$charset,$pconnect);
- $action = $_GET['action'];
- $start = $_GET['start'];
- !$start && $start = 0;
- $percount = 1000;
- if (empty($action)) {
- echo '<a href="repair_lastpost.php?action=thread">开始运行修复主题最后发帖工具</a><br /><a href="repair_lastpost.php?action=forum">开始运行修复板块最后发帖工具</a>';exit;
- } elseif ($action == 'forum') {
- $query = $db->query("SELECT * FROM pw_forums");
- while ($rt = $db->fetch_array($query)) {
- $last = $db->get_one("SELECT * FROM pw_threads WHERE fid=".$rt['fid']." AND ifcheck=1 ORDER BY lastpost DESC");
- $new_url = "read.php?tid=$last[tid]";
- $lastpost = $last['subject']."\t".addslashes($last['author'])."\t".$last['postdate']."\t".$new_url;
- $db->update("UPDATE pw_forumdata SET lastpost='".$lastpost."' WHERE fid=".$rt['fid']." LIMIT 1");
- }
- echo '修复板块最后发帖结束';exit;
- } elseif ($action == 'thread') {
- require (R_P.'require/updateforum.php');
- $query = $db->query("SELECT tid,ptable,replies,author,postdate FROM pw_threads WHERE tid>$start ORDER BY tid LIMIT $percount");
- while ($rt = $db->fetch_array($query)) {
- ADD_S($rt);
- $lastid = $rt['tid'];
- if($rt['replies']>0){
- $pw_posts = GetPtable($rt['ptable']);
- $last = $db->get_one("SELECT pid,author,postdate FROM $pw_posts WHERE tid=".$rt['tid']." AND ifcheck=1 ORDER BY postdate DESC LIMIT 1");
- if($last['postdate']){
- $db->update("UPDATE pw_threads SET lastpost=".$last['postdate'].",lastposter='".addslashes($last['author'])."' WHERE tid=".$rt['tid']." LIMIT 1");
- }
- }else{
- $db->update("UPDATE pw_threads SET lastpost=".$rt['postdate'].",lastposter='".addslashes($rt['author'])."' WHERE tid=".$rt['tid']." LIMIT 1");
- }
- }
- $maxid = $db->get_value("SELECT max(tid) FROM pw_threads");
- if ($lastid < $maxid) {
- echo "<meta http-equiv='refresh' content='0;url=$basename?action=last&start=$lastid'>";
- }else{
- echo '修复最后发帖结束';exit;
- }
- }
- function getdirname($path=null){
- if (!empty($path)) {
- if (strpos($path,'\\')!==false) {
- return substr($path,0,strrpos($path,'\\')).'/';
- } elseif (strpos($path,'/')!==false) {
- return substr($path,0,strrpos($path,'/')).'/';
- }
- }
- return './';
- }
- function createtable($array){
- global $db,$charset;
- foreach ($array as $key => $value) {
- !$value[1] && $value[1] = 'MyISAM';
- $value[0] = "CREATE TABLE IF NOT EXISTS $key ($value[0]) ";
- if ($db->server_info() > '4.1') {
- $value[0] .= "ENGINE=$value[1]".($charset ? " DEFAULT CHARSET=$charset" : '');
- } else {
- $value[0] .= "TYPE=$value[1]";
- }
- $db->query($value[0]);
- }
- }
- ?>
|