news.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 178 行
PHP
178 行
<?php
// $Id: index.php,v 1.1.1.1 2005/11/10 19:51:04 phppp Exp $
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: phppp (D.J., infomax@gmail.com) //
// URL: http://xoopsforge.com, http://xoops.org.cn //
// Project: Article Project //
// ------------------------------------------------------------------------ //
include('header.php');
xoops_cp_header();
include XOOPS_ROOT_PATH."/modules/".$xoopsModule->getVar("dirname")."/include/vars.php";
include_once XOOPS_ROOT_PATH.'/class/database/sqlutility.php';
$file = XOOPS_ROOT_PATH."/modules/".$xoopsModule->getVar("dirname")."/sql/mysql.sql";
$fp = fopen($file, 'r');
$sql_queries = trim(fread($fp, filesize($file)));
SqlUtility::splitMySqlFile($pieces, $sql_queries);
foreach ($pieces as $query) {
// [0] contains the prefixed query
// [4] contains unprefixed table name
$prefixed_query = SqlUtility::prefixQuery(trim($query), $GLOBALS["xoopsDB"]->prefix());
if ($prefixed_query != false) {
$GLOBALS["xoopsDB"]->queryF($prefixed_query[0]);
}
}
foreach($xoopsModule->getInfo("tables") as $table){
$sql = "TRUNCATE TABLE ".$GLOBALS["xoopsDB"]->prefix($table);
$GLOBALS["xoopsDB"]->queryF($sql);
$sql_reset = "ALTER TABLE ".$xoopsDB->prefix($table). " AUTO_INCREMENT = 1;";
$xoopsDB->queryF($sql_reset);
xoops_message("succeed with emptying TABLE {$table}");
}
$sql =
" INSERT INTO ".art_DB_prefix("category").
" (cat_id, cat_title, cat_pid, cat_image, cat_description)".
" SELECT ".
" topic_id, topic_title, topic_pid, topic_imgurl, topic_description".
" FROM ".$GLOBALS['xoopsDB']->prefix("topics").
" ORDER BY topic_id ASC"
;
$result = $xoopsDB->queryF($sql);
xoops_message("succeed with building CATEGORY table: ". $count = $xoopsDB->getAffectedRows());
$sql =
" INSERT INTO ".art_DB_prefix("article").
" (art_id, art_title, cat_id, uid, art_keywords, art_summary, art_time_create, art_time_submit, art_time_publish, art_counter, art_rating, art_rates, art_comments)".
" SELECT ".
" storyid, title, topicid, uid, keywords, hometext, created, created, published, counter, FLOOR(rating * votes), votes, comments".
" FROM ".$GLOBALS['xoopsDB']->prefix("stories").
" ORDER BY storyid ASC"
;
$result = $xoopsDB->queryF($sql);
xoops_message("succeed with building ARTICLE table: ".$count = $xoopsDB->getAffectedRows());
$sql =
" INSERT INTO ".art_DB_prefix("artcat").
" (art_id, cat_id, uid, ac_register, ac_publish)".
" SELECT ".
" storyid, topicid, uid, created, published".
" FROM ".$GLOBALS['xoopsDB']->prefix("stories").
" ORDER BY storyid ASC"
;
$result = $xoopsDB->queryF($sql);
xoops_message("succeed with building ARTICLE-CATEGORY table: ".$count = $xoopsDB->getAffectedRows());
$sql =
" INSERT INTO ".art_DB_prefix("text").
" (text_id, art_id, text_body, dohtml, dosmiley, dobr, doimage, doxcode)".
" SELECT ".
" storyid, storyid, bodytext, (2-nohtml) DIV 2, (2-nosmiley) DIV 2, 1, 1, 1".
" FROM ".$GLOBALS['xoopsDB']->prefix("stories").
" ORDER BY storyid ASC"
;
$result = $xoopsDB->queryF($sql);
xoops_message("succeed with building TEXT table: ".$count = $xoopsDB->getAffectedRows());
$sql =
" INSERT INTO ".art_DB_prefix("rate").
" (rate_id, art_id, uid, rate_rating, rate_time)".
" SELECT ".
" ratingid, storyid, ratinguser, rating, ratingtimestamp".
" FROM ".$GLOBALS['xoopsDB']->prefix("stories_votedata").
" ORDER BY ratingid ASC"
;
$result = $xoopsDB->queryF($sql);
xoops_message("succeed with building RATE table: ".$count = $xoopsDB->getAffectedRows());
$sql_read = " SELECT cat_id FROM ".art_DB_prefix("category");
$result_read = $xoopsDB->query($sql_read);
$count = 0;
while( list($cat_id) = $xoopsDB->fetchRow($result_read) ) {
$sql_sel = " SELECT art_id FROM ".art_DB_prefix("article").
" WHERE cat_id = {$cat_id}".
" ORDER BY art_id DESC";
$result = $xoopsDB->query($sql_sel, 10);
$arts = array();
while( list($art_id) = $xoopsDB->fetchRow($result)) {
$arts[] = $art_id;
}
$sql_write =
" UPDATE ".art_DB_prefix("category").
" SET cat_lastarticles = ". $xoopsDB->quoteString(serialize($arts)).
" WHERE ".
" cat_id = {$cat_id}"
;
$result = $xoopsDB->queryF($sql_write);
$count++;
}
xoops_message("succeed with building lastarticles for category: ".$count);
$sql_read = " SELECT art_id, text_id FROM ".art_DB_prefix("text");
$result_read = $xoopsDB->query($sql_read);
$count = 0;
while( list($art_id, $text_id) = $xoopsDB->fetchRow($result_read) ) {
$sql =
" UPDATE ".art_DB_prefix("article").
" SET art_pages = ". $xoopsDB->quoteString(serialize(array($text_id))).
" WHERE ".
" art_id = {$art_id}"
;
$result = $xoopsDB->queryF($sql);
$count++;
}
xoops_message("succeed with updating articles: ".$count);
if ($tag_handler = @xoops_getmodulehandler("tag", "tag", true)) {
$sql = " SELECT art_id, art_keywords".
" FROM ".art_DB_prefix("article");
$result = $GLOBALS['xoopsDB']->query($sql);
$count = 0;
while( list($art_id, $keywords) = $GLOBALS['xoopsDB']->fetchRow($result) ){
if(empty($keywords)) continue;
$tag_handler->updateByItem($keywords, $art_id, $xoopsModule->getVar("mid"));
$count++;
}
xoops_message("succeed with updating tags: ".$count);
}
xoops_cp_footer();
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?