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

[定制开发功能]门户底层化增加帖子排行增加点击和回复的周、月等数据排行 [复制链接]

上一主题 下一主题
离线rickyleo
 

发帖
315
金币
0
威望
99
只看楼主 倒序阅读 使用道具 楼主  发表于: 2011-10-11

调用需求:
要实现论坛帖子点击和回复的日、周、月、总等四种数据排行.

目前版本里边有的包括:
    1) 回复数总数排行
    2) 回复数每日排行
    3) 回复数每周排行(功能貌似版本没写好,补充了下)
    4) 点击数总数排行
    5) 点击数每日排行

先需要增加新的排序如下:
    1) 回复数每月排行 (replysortmonth)
    2) 点击数每周排行 (hitsortweek)(这个排序是有的,只是在筛选数据的时候没做而已,屏蔽了)
    3) 点击数每月排行 (hitsortmonth)
    
方案如下:
向pw_elements表增加几种新的排序,replysortmonth、hitsortweek、hitsortmonth.
修改如下:

打开thread.php文件,找到:

  1. if ($db_ifpwcache & 64 && $thread['postdate'] > $timestamp-7*24*3600) {
  2.                                 if ($thread['hits'] > $hitsort_judge['hitsortweek'][$this->fid] && $thread['fid'] == $this->fid) {
  3.                                         $updatelist[] = array('hitsortweek', $this->fid, $thread['tid'], $thread['hits'], $thread['postdate'], 0);
  4.                                         $updatetype['hitsortweek'] = 1;
  5.                                 }
  6.                         }


下下下方添加如下代码:

  1. if ($thread['postdate'] > $timestamp-30*24*3600) {
  2.                                 if ($thread['hits'] > $hitsort_judge['hitsortmonth'][$this->fid] && $thread['fid'] == $this->fid) {
  3.                                         $updatelist[] = array('hitsortmonth', $this->fid, $thread['tid'], $thread['hits'], $thread['postdate'], 0);
  4.                                         $updatetype['hitsortmonth'] = 1;
  5.                                 }
  6.                         }



打开lib/elementupdate.class.php文件,找到:

  1. if ($this->ifcache & 64 && $thread['postdate'] > 7 * 24 * 3600) {
  2.                                 if ($thread['hits'] > $hitsort_judge['hitsortweek'][$fid]) {
  3.                                         $this->updatelist[] = array(
  4.                                                 'hitsortweek',
  5.                                                 $fid,
  6.                                                 $thread['tid'],
  7.                                                 $thread['hits'],
  8.                                                 $thread['postdate'],
  9.                                                 0
  10.                                         );
  11.                                         $this->updatetype['hitsortweek'] = 1;
  12.                                 }
  13.                         }


下下下方添加如下代码:

  1. if ($thread['postdate'] > 30 * 24 * 3600) {
  2.                                 if ($thread['hits'] > $hitsort_judge['hitsortmonth'][$fid]) {
  3.                                         $this->updatelist[] = array(
  4.                                                 'hitsortmonth',
  5.                                                 $fid,
  6.                                                 $thread['tid'],
  7.                                                 $thread['hits'],
  8.                                                 $thread['postdate'],
  9.                                                 0
  10.                                         );
  11.                                         $this->updatetype['hitsortmonth'] = 1;
  12.                                 }
  13.                         }


            
找到代码:

  1. if ($this->ifcache & 8 && $postdate > $timestamp - 7 * 24 * 3600) {
  2.                         if ($replies > $this->judge['replysort']['replysortweek'][$fid]) {
  3.                                 $this->updatelist[] = array(
  4.                                         'replysortweek',
  5.                                         $fid,
  6.                                         $tid,
  7.                                         $replies,
  8.                                         $postdate,
  9.                                         $special
  10.                                 );
  11.                                 $this->updatetype['replysortweek'] = 1;
  12.                         }
  13.                 }



下下下方添加如下代码:

  1. if ($postdate > $timestamp - 30 * 24 * 3600) {
  2.                         if ($replies > $this->judge['replysort']['replysortmonth'][$fid]) {
  3.                                 $this->updatelist[] = array(
  4.                                         'replysortmonth',
  5.                                         $fid,
  6.                                         $tid,
  7.                                         $replies,
  8.                                         $postdate,
  9.                                         $special
  10.                                 );
  11.                                 $this->updatetype['replysortmonth'] = 1;
  12.                         }
  13.                 }



找到:

  1. function updateSQL() {
  2.         …………
  3. }



替换成:

  1. function updateSQL() {
  2.                 global $timestamp;
  3.                 if (!$this->updatelist || !$this->updatetype || !$this->mark) return false;
  4.                 $special = (int) $this->special;
  5.                 $judges = array();
  6.                 $todaytime = $weektime = '';
  7.                 foreach ($this->updatetype as $key => $val) {
  8.                         if (in_array($key, array(
  9.                                 'replysort',
  10.                                 'replysortday',
  11.                                 'replysortweek',
  12.                                 'replysortmonth',
  13.                         )) && $this->judge['replysort']) {
  14.                                 $judges['replysort'] = $this->judge['replysort'];
  15.                         }
  16.                         if (in_array($key, array(
  17.                                 'hitsort',
  18.                                 'hitsortday',
  19.                                 'hitsortweek',
  20.                                 'hitsortmonth'
  21.                         )) && $this->judge['hitsort']) {
  22.                                 $judges['hitsort'] = $this->judge['hitsort'];
  23.                         }
  24.                         if (strpos($key, 'day') && !$todaytime) {
  25.                                 $todaytime = $timestamp - 24 * 3600;
  26.                         } elseif (strpos($key, 'week') && !$weektime) {
  27.                                 $weektime = $timestamp - 7 * 24 * 3600;
  28.                         } elseif (strpos($key, 'month') && !$monthtime) {
  29.                                 $monthtime = $timestamp - 30 * 24 * 3600;
  30.                         }
  31.                 }
  32.                 $this->db->update("REPLACE INTO pw_elements (type,mark,id,value,addition,special) VALUES " . S::sqlMulti($this->updatelist, false));
  33.                 $sortlist = array();
  34.                 $dellis = array();
  35.                 $query = $this->db->query("SELECT eid,type,value,addition FROM pw_elements WHERE type IN (" . S::sqlImplode(array_keys($this->updatetype)) . ") AND mark=" . S::sqlEscape($this->mark) . " AND special=" . S::sqlEscape($special) . " ORDER BY type,value DESC");
  36.                 while ($rt = $this->db->fetch_array($query)) {
  37.                         if (strpos($rt['type'], 'day') && $rt['addition'] && $rt['addition'] < $todaytime) {
  38.                                 $dellist[] = $rt['eid'];
  39.                         } elseif (strpos($rt['type'], 'week') && $rt['addition'] && $rt['addition'] < $weektime) {
  40.                                 $dellist[] = $rt['eid'];
  41.                         } elseif (strpos($rt['type'], 'month') && $rt['addition'] && $rt['addition'] < $monthtime) {
  42.                                 $dellist[] = $rt['eid'];
  43.                         } else {
  44.                                 $sortlist[$rt['type']][] = $rt;
  45.                         }
  46.                 }
  47.                 foreach ($sortlist as $key => $value) {
  48.                         if (count($value) > $this->cachenum) {
  49.                                 $tem = array_slice($value, $this->cachenum);
  50.                                 foreach ($tem as $val) {
  51.                                         $dellist[] = $val['eid'];
  52.                                 }
  53.                         }
  54.                         if (in_array($key, array(
  55.                                 'replysort',
  56.                                 'replysortday',
  57.                                 'replysortweek',
  58.                                 'replysortmonth'
  59.                         ))) {
  60.                                 $judgetype = 'replysort';
  61.                                 array_splice($value, $this->cachenum);
  62.                         } elseif (in_array($key, array(
  63.                                 'hitsort',
  64.                                 'hitsortday',
  65.                                 'hitsortweek',
  66.                                 'hitsortmonth'
  67.                         ))) {
  68.                                 $judgetype = 'hitsort';
  69.                                 array_splice($value, $this->cachenum);
  70.                         } else {
  71.                                 $judgetype = '';
  72.                         }
  73.                         if ($judgetype && count($value) == $this->cachenum) {
  74.                                 $tem = end($value);
  75.                                 $judges[$judgetype][$key][$this->mark] = $tem['value'];
  76.                         } else {
  77.                                 $judges[$judgetype][$key][$this->mark] = '0';
  78.                         }
  79.                 }
  80.                 if ($dellist) {
  81.                         $this->db->update("DELETE FROM pw_elements WHERE eid IN (" . S::sqlImplode($dellist) . ")");
  82.                 }
  83.                 if ($judges) {
  84.                         foreach ($judges as $key => $value) {
  85.                                 if ($key == 'replysort') {
  86.                                         if ($value != $this->judge['replysort']) {
  87.                                                 pwCache::setData(D_P . 'data/bbscache/replysort_judge_' . $special . '.php', "<?php\r\n\$replysort_judge=" . pw_var_export($value) . ";\r\n?>");
  88.                                         }
  89.                                 } elseif ($key == 'hitsort') {
  90.                                         pwCache::setData(D_P . 'data/bbscache/hitsort_judge.php', "<?php\r\n\$hitsort_judge=" . pw_var_export($value) . ";\r\n?>");
  91.                                         touch(D_P.'data/bbscache/hitsort_judge.php');
  92.                                 }
  93.                         }
  94.                 }
  95.                 return true;
  96.         }

        

这样修改以后,在帖子列表页的时候会触发更新hitsort相关的element项(定时更新600秒间隔,缓存见data/bbscache/hitsort_judge.php),点击回复的时候会更新replysort相关element项.

这样以后,pw_elements表里边就增加了新的几个排序类型了.接下来开始前台的数据调用,涉及到文件如下:
1、lib/area/source/subjectsource.class.php
2、lib/element.class.php

打开lib/area/source/subjectsource.class.php文件,找到:

  1. 'replysortday'        =>'今日回复',
  2. 'replysortweek'        =>'近期回复',
  3. 'replysort'                =>'回复排行',
  4. 'hitsortday'        =>'今日点击',
  5. 'hitsort'                =>'点击排行',



替换成:
  1. 'replysortday'                =>        '回复日排行',
  2. 'replysortweek'                =>        '回复周排行',
  3. 'replysortmonth'        =>        '回复月排行',
  4. 'replysort'                        =>        '回复总排行',
  5. 'hitsortday'                =>        '点击日排行',
  6. 'hitsortweek'                =>        '点击周排行',
  7. 'hitsortmonth'                =>        '点击月排行',
  8. 'hitsort'                        =>        '点击总排行',



部分是重复的,只是在前台调用的时候显示更加清晰一些,所以这里放心替换。

找到:

  1. function _getDataBySortType($sortType,$fid,$num) {
  2.                 $element = $this->_getElement();
  3.                 …………
  4.         }



替换成:

  1. function _getDataBySortType($sortType,$fid,$num) {
  2.                 $element = $this->_getElement();
  3.                 switch ($sortType) {
  4.                         case 'newsubject':
  5.                                 return $element->newSubject($fid,$num);
  6.                         case 'newreply':
  7.                                 return $element->newReply($fid,$num);
  8.                         case 'digestsubject':
  9.                                 return $element->digestSubject($fid,$num);
  10.                         case 'topsubject':
  11.                                 return $element->areaTopSubject($fid,$num);            
  12.                         case 'highlightsubject':
  13.                                 return $element->highLightSubject($fid,$num);
  14.                         case 'replysort':
  15.                                 return $element->replySort($fid,$num);
  16.                         case 'replysortday':
  17.                                 return $element->replySortDay($fid,$num);
  18.                         case 'replysortweek':
  19.                                 return $element->replySortWeek($fid,$num);
  20.                         case 'replysortmonth':
  21.                                 return $element->replySortMonth($fid,$num);
  22.                         case 'hitsort':
  23.                                 return $element->hitSort($fid,$num);
  24.                         case 'hitsortday':
  25.                                 return $element->hitSortDay($fid,$num);
  26.                         case 'hitsortweek':
  27.                                 return $element->hitSortWeek($fid,$num);
  28.                         case 'hitsortmonth':
  29.                                 return $element->hitSortMonth($fid,$num);
  30.                         default :
  31.                                 return $element->newSubject($fid,$num);
  32.                 }
  33.         }


    
打开lib/element.class.php文件,找到:

  1. function replySortWeek($round=0,$num=0,$special=0){
  2.                 return $this->replySortInterface('replysortweek',$round,$num,$special);
  3.         }



下下下方添加如下代码:

  1. function replySortMonth($round=0,$num=0,$special=0){
  2.                 return $this->replySortInterface('replysortmonth',$round,$num,$special);
  3.         }



找到:

  1. function replySortInterface($type='replysort',$fid=0,$num=0,$special=0){
  2.                 …………
  3.         }



替换成:

  1. function replySortInterface($type='replysort',$fid=0,$num=0,$special=0){
  2.                 !$type && $type = 'replysort';
  3.                 !in_array($type,array('replysort','replysortday','replysortweek','replysortmonth')) && Showmsg('undefined_action');        
  4.                 $num = intval($num) ? intval($num) : $this->defaultnum;
  5.                 $special = (int)$special;
  6.                 $fid = $this->_cookFid($fid);
  7.                 if (($type=='replysort' && ($this->ifpwcache & 2)) || ($type=='replysortday' && ($this->ifpwcache & 4)) || ($type=='replysortweek' && ($this->ifpwcache & 8)) || ($type=='replysortmonth')) {
  8.                         $sqladd = '';
  9.                         $sqladd .= ' AND e.special='.S::sqlEscape($special);
  10.                         $sort = array();
  11.                         $fid && $sqladd .= " AND e.mark IN ($fid) ";
  12.                         $dayTime = PwStrtoTime(get_date(time(),'Ymd'));
  13.                         if ($type == 'replysortday') {
  14.                                 $sqladd .= " AND t.postdate >= $dayTime";
  15.                         }elseif ($type == 'replysortweek') {
  16.                                 $weekTime = $dayTime - 7*24*3600;
  17.                                 $sqladd .= " AND t.postdate >= $weekTime";
  18.                         }elseif ($type == 'replysortmonth') {
  19.                                 $monthTime = $dayTime - 30*24*3600;
  20.                                 $sqladd .= " AND t.postdate >= $monthTime";
  21.                         }
  22.                         if ($special == 2) {
  23.                                 $sql = "SELECT a.*,e.mark as fid FROM pw_elements e LEFT JOIN pw_activity a ON e.id=a.tid WHERE e.type=".S::sqlEscape($type)." $sqladd ORDER BY e.value DESC".S::sqlLimit($num);
  24.                         } elseif ($special == 3) {
  25.                                 global $db_moneyname,$db_rvrcname,$db_creditname,$db_currencyname,$_CREDITDB;
  26.                                 $cType = array(
  27.                                                         'money'                => $db_moneyname,
  28.                                                         'rvrc'                => $db_rvrcname,
  29.                                                         'credit'        => $db_creditname,
  30.                                                         'currency'        => $db_currencyname
  31.                                                 );
  32.                                 foreach ($_CREDITDB as $k => $v) {
  33.                                         $cType[$k] = $v[0];
  34.                                 }
  35.                                 $sql = "SELECT r.tid,r.cbtype,r.catype,r.cbval,r.caval,r.timelimit,t.fid,t.author,t.authorid,t.subject,t.type,t.postdate,t.hits,t.replies FROM pw_elements e LEFT JOIN pw_reward r ON e.id=r.tid LEFT JOIN pw_threads t ON e.id=t.tid WHERE e.type=".S::sqlEscape($type)." $sqladd AND t.ifshield != 1 AND t.locked != 2 ORDER BY e.value DESC".S::sqlLimit($num);
  36.                         } elseif ($special == 4) {
  37.                                 $sql = "SELECT t.tid,t.name,t.icon,t.price,e.mark as fid FROM pw_elements e LEFT JOIN pw_trade t ON e.id=t.tid WHERE e.type=".S::sqlEscape($type)." $sqladd ORDER BY e.value DESC".S::sqlLimit($num);
  38.                         } else {
  39.                                 $sql = "SELECT t.tid,t.fid,t.author,t.authorid,t.subject,t.type,t.postdate,t.hits,t.replies FROM pw_elements e LEFT JOIN pw_threads t ON e.id=t.tid WHERE e.type=".S::sqlEscape($type)." $sqladd AND t.ifshield != 1 AND t.locked != 2 ORDER BY e.value DESC".S::sqlLimit($num);
  40.                         }
  41.                         $query = $this->db->query($sql);
  42.                         while ($rt = $this->db->fetch_array($query)) {
  43.                                 $post = array();
  44.                                 $post['url']     = 'read.php?tid='.$rt['tid'];
  45.                                 $post['authorurl'] = 'u.php?uid=' . $rt['authorid'];
  46.                                 if ($special == 2) {
  47.                                         $post['title']     = $rt['subject'];
  48.                                         $post['value']     = $rt['deadline'];
  49.                                         $post['image']    = '';
  50.                                 } elseif ($special == 3) {
  51.                                         $post['title']     = $rt['subject'];
  52.                                         $post['value']     = $cType[$rt['cbtype']].":".$rt['cbval'];
  53.                                         $post['image']    = '';
  54.                                 } elseif ($special == 4) {
  55.                                         $post['title']     = $rt['name'];
  56.                                         $post['value']     = $rt['price'];
  57.                                         if ($rt['icon']) {
  58.                                                 $pic = geturl($rt['icon'],'show',1);
  59.                                                 if(is_array($pic)){
  60.                                                         $post['image'] = $pic[0];
  61.                                                 } else {
  62.                                                         $post['image'] = 'images/noproduct.gif';
  63.                                                 }
  64.                                         } else {
  65.                                                 $post['image'] = 'images/noproduct.gif';
  66.                                         }
  67.                                 } else {
  68.                                         $post['title']     = $rt['subject'];
  69.                                         $post['value']     = $rt['replies'];
  70.                                         $post['image']    = '';
  71.                                 }
  72.                                 $post['forumname']    = getForumName($rt['fid']);
  73.                                 $post['forumurl']    = getForumUrl($rt['fid']);
  74.                                 list($post['topictypename'],$post['topictypeurl']) = getTopicType($rt['type'],$rt['fid']);
  75.                                 $post['addition'] = $rt;
  76.                                 $sort[] = $post;
  77.                         }
  78.                 } else {
  79.                         $info = $this->singLeton(true,$num);
  80.                         switch ($type) {
  81.                                 case 'replysort':
  82.                                         $time = 0;
  83.                                         break;
  84.                                 case 'replysortday':
  85.                                         $time = 24;
  86.                                         break;
  87.                                 case 'replysortweek':
  88.                                         $time = 7*24;
  89.                                         break;
  90.                                 case 'replysortmonth':
  91.                                         $time = 30*24;
  92.                                         break;
  93.                                 default:
  94.                                         $time = 0;
  95.                         }
  96.                         $sort = $info->getPostList('replysort',$fid,$info->cachenum,$time,$special);
  97.                 }
  98.                 return $sort;
  99.         }


    
找到:

  1. function hitSortInterface($type='hitsort',$fid=0,$num=0,$special=0){
  2.                 …………
  3.         }        


    
替换成:

  1. function hitSortInterface($type='hitsort',$fid=0,$num=0,$special=0){
  2.                 !$type && $type = 'hitsort';
  3.                 !in_array($type,array('hitsort','hitsortday','hitsortweek','hitsortmonth')) && Showmsg('undefined_action');
  4.                 $num = intval($num) ? intval($num) : $this->defaultnum;
  5.                 $fid = $this->_cookFid($fid);
  6.                 if (($type=='hitsort' && ($this->ifpwcache & 16)) || ($type=='hitsortday' && ($this->ifpwcache & 32)) || ($type=='hitsortweek' && ($this->ifpwcache & 64)) || ($type=='hitsortmonth')) {
  7.                         $sqladd = '';
  8.                         $sort = array();
  9.                         $fid && $sqladd .= " AND e.mark IN ($fid) ";
  10.                         $dayTime = PwStrtoTime(get_date(time(),'Ymd'));
  11.                         if ($type == 'hitsortday') {
  12.                                 $sqladd .= " AND t.postdate >= $dayTime";
  13.                         }elseif ($type == 'hitsortweek') {
  14.                                 $weekTime = $dayTime - 7*24*3600;
  15.                                 $sqladd .= " AND t.postdate >= $weekTime";
  16.                         }elseif ($type == 'hitsortmonth') {
  17.                                 $monthTime = $dayTime - 30*24*3600;
  18.                                 $sqladd .= " AND t.postdate >= $monthTime";
  19.                         }
  20.                         $query = $this->db->query("SELECT t.tid,t.fid,t.author,t.authorid,t.subject,t.type,t.postdate,t.hits,t.replies FROM pw_elements e LEFT JOIN pw_threads t ON e.id=t.tid WHERE e.type=".S::sqlEscape($type)." $sqladd AND t.ifshield != 1 AND t.locked != 2 ORDER BY e.value DESC ".S::sqlLimit($num));
  21.                         while ($rt = $this->db->fetch_array($query)) {
  22.                                 if (!$rt['tid']) continue;
  23.                                 $post = array();
  24.                                 $post['url']     = 'read.php?tid='.$rt['tid'];
  25.                                 $post['title']     = $rt['subject'];
  26.                                 $post['value']     = $rt['hits'];
  27.                                 $post['image']    = '';
  28.                                 $post['authorurl'] = 'u.php?uid=' . $rt['authorid'];
  29.                                 $post['forumname']    = getForumName($rt['fid']);
  30.                                 $post['forumurl']    = getForumUrl($rt['fid']);
  31.                                 list($post['topictypename'],$post['topictypeurl']) = getTopicType($rt['type'],$rt['fid']);
  32.                                 $post['addition'] = $rt;
  33.                                 $sort[] = $post;
  34.                         }
  35.                 } else {
  36.                         $info = $this->singLeton(true,$num);
  37.                         switch ($type) {
  38.                                 case 'hitsort':
  39.                                         $time = 0;
  40.                                         break;
  41.                                 case 'hitsortday':
  42.                                         $time = 24;
  43.                                         break;
  44.                                 case 'hitsortweek':
  45.                                         $time = 7*24;
  46.                                         break;
  47.                                 case 'hitsortmonth':
  48.                                         $time = 30*24;
  49.                                         break;
  50.                                 default:
  51.                                         $time = 0;
  52.                         }
  53.                         $sort = $info->getPostList('hitsort',$fid,$info->cachenum,$time);
  54.                 }
  55.                 return $sort;
  56.         }



找到:

  1. function hitSortWeek($round=0,$num=0,$special=0){
  2.                 return $this->hitSortInterface('hitsortweek',$round,$num,$special);
  3.         }



下下下方添加如下代码:

  1. function hitSortMonth($round=0,$num=0,$special=0){
  2.                 return $this->hitSortInterface('hitsortmonth',$round,$num,$special);
  3.         }

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