discuz文章标签降序升序问题bug

2014年9月30日 发表评论 阅读评论

站帮网的技术人员就是一群畜生,眼里只有钱,涉及技术问题一概是需要你买vip的。

discuz中的标签文章排序http://bbs.shandian.biz/u9-42-1.html

默认是按照升序排序的,我在改他的php代码,想改成降序,主要代码我改成
$query=DB::fetch_all("SELECT * FROM %t WHERE tagid=$id ORDER BY itemid desc limit 0,20", array(‘common_tagitem’));
仍然不行,是怎么回事?代码执行是的正确的,可就是升降序始终没法改变!
我想按照文章的tid降序来排列,可是默认的就是升序,代码找到改了也不行!

我买了你们小米插件才知道你们这个论坛的,现在在做一个电竞社区,没什么人气,就自己弄各种专题,所以这个标签做专题非常好,但是标签的代码问题非常多。我想倒序把最新的帖子排前面默认的却是按照升序来的,怎么改都没效果,但是我如果改其他参数,却立即有反应,所以确定应该是这两个文件里的有注释的代码。
涉及到下面两个文件
source\module\misc\misc_tag.php

<?php

/**
*      [Discuz!] (C)2001-2099 Comsenz Inc.
*      This is NOT a freeware, use is subject to license terms
*
*      $Id: misc_tag.php 32232 2012-12-03 08:57:08Z zhangjie $
*/

if(!defined(‘IN_DISCUZ’)) {
        exit(‘Access Denied’);
}

$id = intval($_GET['id']);
$type = trim($_GET['type']);
$name = trim($_GET['name']);
$page = intval($_GET['page']);
if($type == ‘countitem’) {
        $num = 0;
        if($id) {
                $num = C::t(‘common_tagitem’)->count_by_tagid($id);
        }
        include_once template(‘tag/tag’);
        exit();
}
$taglang = lang(‘tag/template’, ‘tag’);
if($id || $name) {

        $tpp = 20;
        $page = max(1, intval($page));
        $start_limit = ($page – 1) * $tpp;
        if($id) {
                $tag = C::t(‘common_tag’)->fetch_info($id);
        } else {
                if(!preg_match(‘/^([\x7f-\xff_-]|\w|\s)+$/’, $name) || strlen($name) > 20) {
                        showmessage(‘parameters_error’);
                }
                $name = addslashes($name);
                $tag = C::t(‘common_tag’)->fetch_info(0, $name);
        }

        if($tag['status'] == 1) {
                showmessage(‘tag_closed’);
        }
        $tagname = $tag['tagname'];
        $id = $tag['tagid'];
        $searchtagname = $name;
        $navtitle = $tagname ? $taglang.’ – ‘.$tagname : $taglang;
        $metakeywords = $tagname ? $taglang.’ – ‘.$tagname : $taglang;
        $metadescription = $tagname ? $taglang.’ – ‘.$tagname : $taglang;

        $showtype = ”;
        $count = ”;
        $summarylen = 300;

        if($type == ‘thread’) {//—主要是这里
                $showtype = ‘thread’;
                $tidarray = $threadlist = array();
                $count = C::t(‘common_tagitem’)->select($id, 0, ‘tid’, ”, ”, 0, 0, 0, 1);
                if($count) {
                        $query = C::t(‘common_tagitem’)->select($id, 0, ‘tid’, ”, ”, $start_limit, $tpp);
                        foreach($query as $result) {
                                $tidarray[$result['itemid']] = $result['itemid'];
                        }
                        $threadlist = getthreadsbytids($tidarray);
                        $multipage = multi($count, $tpp, $page, "misc.php?mod=tag&id=$tag[tagid]&type=thread");
                }//主要是这里—–
        } elseif($type == ‘blog’) {
                $showtype = ‘blog’;
                $blogidarray = $bloglist = array();
                $count = C::t(‘common_tagitem’)->select($id, 0, ‘blogid’, ”, ”, 0, 0, 0, 1);
                if($count) {
                        $query = C::t(‘common_tagitem’)->select($id, 0, ‘blogid’, ”, ”, $start_limit, $tpp);
                        foreach($query as $result) {
                                $blogidarray[$result['itemid']] = $result['itemid'];
                        }
                        $bloglist = getblogbyid($blogidarray);

                        $multipage = multi($count, $tpp, $page, "misc.php?mod=tag&id=$tag[tagid]&type=blog");
                }
        } else {
                $shownum = 20;

                $tidarray = $threadlist = array();
                $query = C::t(‘common_tagitem’)->select($id, 0, ‘tid’, ”, ”, $shownum);
                foreach($query as $result) {
                        $tidarray[$result['itemid']] = $result['itemid'];
                }
                $threadlist = getthreadsbytids($tidarray);

                if(helper_access::check_module(‘blog’)) {
                        $blogidarray = $bloglist = array();
                        $query = C::t(‘common_tagitem’)->select($id, 0, ‘blogid’, ”, ”, $shownum);
                        foreach($query as $result) {
                                $blogidarray[$result['itemid']] = $result['itemid'];
                        }
                        $bloglist = getblogbyid($blogidarray);
                }

        }

        include_once template(‘tag/tagitem’);

} else {
        $navtitle = $metakeywords = $metadescription = $taglang;
        $viewthreadtags = 100;
        $tagarray = array();
        $query = C::t(‘common_tag’)->fetch_all_by_status(0, ”, $viewthreadtags, 0, 0, ‘DESC’);
        foreach($query as $result) {
                $tagarray[] = $result;
        }
        include_once template(‘tag/tag’);
}

function getthreadsbytids($tidarray) {
        global $_G;

        $threadlist = array();
        if(!empty($tidarray)) {
                loadcache(‘forums’);
                include_once libfile(‘function_misc’, ‘function’);
                $fids = array();
                foreach(C::t(‘forum_thread’)->fetch_all_by_tid($tidarray) as $result) {
                        if(!isset($_G['cache']['forums'][$result['fid']]['name'])) {
                                $fids[$result['fid']] = $result['tid'];
                        } else {
                                $result['name'] = $_G['cache']['forums'][$result['fid']]['name'];
                        }
                        $threadlist[$result['tid']] = procthread($result);
                }
                if(!empty($fids)) {
                        foreach(C::t(‘forum_forum’)->fetch_all_by_fid(array_keys($fids)) as $fid => $forum) {
                                $_G['cache']['forums'][$fid]['forumname'] = $forum['name'];
                                $threadlist[$fids[$fid]]['forumname'] = $forum['name'];
                        }
                }
        }
        return $threadlist;
}

function getblogbyid($blogidarray) {
        global $_G;

        $bloglist = array();
        if(!empty($blogidarray)) {
                $data_blog = C::t(‘home_blog’)->fetch_all($blogidarray, ‘dateline’, ‘DESC’);
                $data_blogfield = C::t(‘home_blogfield’)->fetch_all($blogidarray);

                require_once libfile(‘function/spacecp’);
                require_once libfile(‘function/home’);
                $classarr = array();
                foreach($data_blog as $curblogid => $result) {
                        $result = array_merge($result, (array)$data_blogfield[$curblogid]);
                        $result['dateline'] = dgmdate($result['dateline']);
                        $classarr = getclassarr($result['uid']);
                        $result['classname'] = $classarr[$result[classid]]['classname'];
                        if($result['friend'] == 4) {
                                $result['message'] = $result['pic'] = ”;
                        } else {
                                $result['message'] = getstr($result['message'], $summarylen, 0, 0, 0, -1);
                        }
                        $result['message'] = preg_replace("/&[a-z]+\;/i", ”, $result['message']);
                        if($result['pic']) {
                                $result['pic'] = pic_cover_get($result['pic'], $result['picflag']);
                        }
                        $bloglist[] = $result;
                }
        }
        return $bloglist;
}
?>

\source\class\table\table_common_tagitem.php

<?php

/**
*      [Discuz!] (C)2001-2099 Comsenz Inc.
*      This is NOT a freeware, use is subject to license terms
*
*      $Id: table_common_tagitem.php 27769 2012-02-14 06:29:36Z liulanbo $
*/

if(!defined(‘IN_DISCUZ’)) {
        exit(‘Access Denied’);
}

class table_common_tagitem extends discuz_table
{
        public function __construct() {

                $this->_table = ‘common_tagitem’;
                $this->_pk    = ”;

                parent::__construct();
        }

        public function replace($tagid, $itemid, $idtype) {
                return DB::query(‘REPLACE INTO %t (tagid, itemid, idtype) VALUES (%d, %d, %s)’, array($this->_table, $tagid, $itemid, $idtype));
        }

        public function select($tagid = 0, $itemid = 0, $idtype = ”, $orderfield = ”, $ordertype = ‘DESC’, $limit = 0, $count = 0, $itemidglue = ‘=’, $returnnum = 0) {//—主要是这里
                $data = self::make_where($tagid, $itemid, $idtype, $itemidglue);
                $ordersql = $limitsql = ”;
                if($orderfield) {
                        $ordersql = ‘ ORDER BY ‘.DB::order($orderfield, $ordertype);
                }
                if($limit) {
                        $limitsql = DB::limit($limit, $count);
                }
                if($data) {
                        if($returnnum) {
                                return DB::result_first(‘SELECT count(*) FROM %t WHERE ‘.$data['where'], $data['data']);
                        }
                        return DB::fetch_all(‘SELECT * FROM %t WHERE ‘.$data['where'].$ordersql.$limitsql, $data['data']);
                } else {
                        return false;
                }
        }//主要是这里—–

        public function delete($tagid = 0, $itemid = 0, $idtype = ”) {
                $data = self::make_where($tagid, $itemid, $idtype);
                if($data) {
                        return DB::query(‘DELETE FROM %t WHERE ‘.$data['where'], $data['data']);
                } else {
                        return false;
                }
        }

        private function make_where($tagid = 0, $itemid = 0, $idtype = ”, $itemidglue = ‘=’) {
                $wheresql = ‘ 1′;
                $data = array();
                $data['data'][] = $this->_table;
                if($tagid) {
                        $wheresql .= !is_array($tagid) ? " AND tagid=%d" : " AND tagid IN (%n)";
                        $data['data'][] = $tagid;
                }
                if($itemid) {
                        $wheresql .= !is_array($itemid) ? " AND ".DB::field(‘itemid’, $itemid, $itemidglue) : " AND ".DB::field(‘itemid’, $itemid);
                }
                if($idtype) {
                        $wheresql .= " AND idtype=%s";
                        $data['data'][] = $idtype;
                }
                if($wheresql == ‘ 1′) {
                        return false;
                }
                $data['where'] = $wheresql;
                return $data;
        }

        public function unique($tagid, $itemid, $idtype) {
                DB::query(‘DELETE FROM %t WHERE tagid<>%d AND itemid=%d AND idtype=%s’, array($this->_table, $tagid, $itemid, $idtype));
        }

        public function merge_by_tagids($newid, $tagidarray) {
                if(!is_array($tagidarray)) {
                        $tagidarray = array($tagidarray);
                }
                DB::query(‘UPDATE %t SET tagid=%d WHERE tagid IN (%n)’, array($this->_table, $newid, $tagidarray));
        }

        public function count_by_tagid($tagid) {
                return DB::result_first("SELECT count(*) FROM ".DB::table(‘common_tagitem’)." WHERE tagid=’".intval($tagid)."’");
        }
}

?>


转载请注明来自:[MSN Spaces]http://msn.shandian.biz/815.html

  1. 本文目前尚无任何评论.