Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

论坛DIY版块图片附件/非图片附件、普通主题调用

[复制链接]
流年无殇 发表于 2013-6-20 00:14:14 | 显示全部楼层 |阅读模式
DIY模块素材
模块类型: 论坛类
展示风格: 其他
是否原创:
       最近在调试一个论坛,然后发现,论坛头条如果调用帖子中是图片附件(有的时候图片附件含有文字较少,或没有文字),对美工和SEO极为不利,于是在DIY属性寻找,期待寻找到类似于dedecms中的 noflag='p' 的属性,事实证明这个常用的功能在DISCUZ的调用中还不能实现,于是求助于老大@CR180,他耐心倾听我的诉求后,在百忙中抽出时间敲了几下键盘,然后扔给我一个文件说道,拿去,记得备份,\source\class\block\forum\block_thread.php,我大喜,如获至宝。
       于是火速打开FTP,备份block_thread.php,然后上传覆盖。进入DIY,发现图片那一栏,有以下改变:

      通过图片,我们可以看到,属性里面可以调用的3种模式,第一,默认无限制,第二。必须含图片附件,第三,禁止含图片附件,这样我们在调用帖子的时候就更灵活了。下面是block_thread.php代码。

  1. <?php

  2. /**
  3. *      [Discuz!] (C)2001-2099 Comsenz Inc.
  4. *      This is NOT a freeware, use is subject to license terms
  5. *
  6. *      $Id: block_thread.php 32365 2013-01-06 12:23:07Z zhangguosheng $
  7. */

  8. if(!defined('IN_DISCUZ')) {
  9.         exit('Access Denied');
  10. }
  11. class block_thread extends discuz_block {
  12.         var $setting = array();

  13.         function block_thread(){
  14.                 $this->setting = array(
  15.                         'tids' => array(
  16.                                 'title' => 'threadlist_tids',
  17.                                 'type' => 'text'
  18.                         ),
  19.                         'uids' => array(
  20.                                 'title' => 'threadlist_uids',
  21.                                 'type' => 'text'
  22.                         ),
  23.                         'keyword' => array(
  24.                                 'title' => 'threadlist_keyword',
  25.                                 'type' => 'text'
  26.                         ),
  27.                         'tagkeyword' => array(
  28.                                 'title' => 'threadlist_tagkeyword',
  29.                                 'type' => 'text'
  30.                         ),
  31.                         'fids'        => array(
  32.                                 'title' => 'threadlist_fids',
  33.                                 'type' => 'mselect',
  34.                                 'value' => array()
  35.                         ),
  36.                         'typeids' => array(
  37.                                 'title' => 'threadlist_typeids',
  38.                                 'type' => 'text'
  39.                         ),
  40.                         'sortids' => array(
  41.                                 'title' => 'threadlist_sortids',
  42.                                 'type' => 'mselect',
  43.                                 'value' => array()
  44.                         ),
  45.                         'digest' => array(
  46.                                 'title' => 'threadlist_digest',
  47.                                 'type' => 'mcheckbox',
  48.                                 'value' => array(
  49.                                         array(1, 'threadlist_digest_1'),
  50.                                         array(2, 'threadlist_digest_2'),
  51.                                         array(3, 'threadlist_digest_3'),
  52.                                         array(0, 'threadlist_digest_0')
  53.                                 ),
  54.                         ),
  55.                         'stick' => array(
  56.                                 'title' => 'threadlist_stick',
  57.                                 'type' => 'mcheckbox',
  58.                                 'value' => array(
  59.                                         array(1, 'threadlist_stick_1'),
  60.                                         array(2, 'threadlist_stick_2'),
  61.                                         array(3, 'threadlist_stick_3'),
  62.                                         array(0, 'threadlist_stick_0')
  63.                                 ),
  64.                         ),
  65.                         'recommend' => array(
  66.                                 'title' => 'threadlist_recommend',
  67.                                 'type' => 'radio'
  68.                         ),
  69.                         'special' => array(
  70.                                 'title' => 'threadlist_special',
  71.                                 'type' => 'mcheckbox',
  72.                                 'value' => array(
  73.                                         array(1, 'threadlist_special_1'),
  74.                                         array(2, 'threadlist_special_2'),
  75.                                         array(3, 'threadlist_special_3'),
  76.                                         array(4, 'threadlist_special_4'),
  77.                                         array(5, 'threadlist_special_5'),
  78.                                         array(0, 'threadlist_special_0'),
  79.                                 )
  80.                         ),
  81.                         'viewmod' => array(
  82.                                 'title' => 'threadlist_viewmod',
  83.                                 'type' => 'radio'
  84.                         ),
  85.                         'rewardstatus' => array(
  86.                                 'title' => 'threadlist_special_reward',
  87.                                 'type' => 'mradio',
  88.                                 'value' => array(
  89.                                         array(0, 'threadlist_special_reward_0'),
  90.                                         array(1, 'threadlist_special_reward_1'),
  91.                                         array(2, 'threadlist_special_reward_2')
  92.                                 ),
  93.                                 'default' => 0,
  94.                         ),
  95.                         // edit cr180 2013年6月19日 21:49:29
  96.                                         /*
  97.                                                 'picrequired' => array(
  98.                                                         'title' => 'threadlist_picrequired',
  99.                                                         'type' => 'radio',
  100.                                                         'value' => '0'
  101.                                                 ),
  102.                                         */
  103.                         'picrequired' => array(
  104.                                 'title' => 'threadlist_picrequired',
  105.                                 'type' => 'select',
  106.                                 'value' => array(
  107.                                         array(0, '默认无限制'),
  108.                                         array(1, '必须含附件'),
  109.                                         array(2, '禁止含附件')
  110.                                 )
  111.                         ),
  112.                         // end
  113.                         'orderby' => array(
  114.                                 'title' => 'threadlist_orderby',
  115.                                 'type'=> 'mradio',
  116.                                 'value' => array(
  117.                                         array('lastpost', 'threadlist_orderby_lastpost'),
  118.                                         array('dateline', 'threadlist_orderby_dateline'),
  119.                                         array('replies', 'threadlist_orderby_replies'),
  120.                                         array('views', 'threadlist_orderby_views'),
  121.                                         array('heats', 'threadlist_orderby_heats'),
  122.                                         array('recommends', 'threadlist_orderby_recommends'),
  123.                                 ),
  124.                                 'default' => 'lastpost'
  125.                         ),
  126.                         'postdateline' => array(
  127.                                 'title' => 'threadlist_postdateline',
  128.                                 'type'=> 'mradio',
  129.                                 'value' => array(
  130.                                         array('0', 'threadlist_postdateline_nolimit'),
  131.                                         array('3600', 'threadlist_postdateline_hour'),
  132.                                         array('86400', 'threadlist_postdateline_day'),
  133.                                         array('604800', 'threadlist_postdateline_week'),
  134.                                         array('2592000', 'threadlist_postdateline_month'),
  135.                                 ),
  136.                                 'default' => '0'
  137.                         ),
  138.                         'lastpost' => array(
  139.                                 'title' => 'threadlist_lastpost',
  140.                                 'type'=> 'mradio',
  141.                                 'value' => array(
  142.                                         array('0', 'threadlist_lastpost_nolimit'),
  143.                                         array('3600', 'threadlist_lastpost_hour'),
  144.                                         array('86400', 'threadlist_lastpost_day'),
  145.                                         array('604800', 'threadlist_lastpost_week'),
  146.                                         array('2592000', 'threadlist_lastpost_month'),
  147.                                 ),
  148.                                 'default' => '0'
  149.                         ),
  150.                         'highlight' => array(
  151.                                 'title' => 'threadlist_highlight',
  152.                                 'type' => 'radio',
  153.                                 'default' => 0,
  154.                         ),
  155.                         'titlelength' => array(
  156.                                 'title' => 'threadlist_titlelength',
  157.                                 'type' => 'text',
  158.                                 'default' => 40
  159.                         ),
  160.                         'summarylength' => array(
  161.                                 'title' => 'threadlist_summarylength',
  162.                                 'type' => 'text',
  163.                                 'default' => 80
  164.                         ),
  165.                         'startrow' => array(
  166.                                 'title' => 'threadlist_startrow',
  167.                                 'type' => 'text',
  168.                                 'default' => 0
  169.                         ),
  170.                 );
  171.         }

  172.         function name() {
  173.                 return lang('blockclass', 'blockclass_thread_script_thread');
  174.         }

  175.         function blockclass() {
  176.                 return array('thread', lang('blockclass', 'blockclass_forum_thread'));
  177.         }

  178.         function fields() {
  179.                 return array(
  180.                                         'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
  181.                                         'url' => array('name' => lang('blockclass', 'blockclass_thread_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
  182.                                         'title' => array('name' => lang('blockclass', 'blockclass_thread_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
  183.                                         'pic' => array('name' => lang('blockclass', 'blockclass_thread_field_pic'), 'formtype' => 'pic', 'datatype' => 'pic'),
  184.                                         'summary' => array('name' => lang('blockclass', 'blockclass_thread_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
  185.                                         'author' => array('name' => lang('blockclass', 'blockclass_thread_field_author'), 'formtype' => 'text', 'datatype' => 'string'),
  186.                                         'authorid' => array('name' => lang('blockclass', 'blockclass_thread_field_authorid'), 'formtype' => 'text', 'datatype' => 'int'),
  187.                                         'avatar' => array('name' => lang('blockclass', 'blockclass_thread_field_avatar'), 'formtype' => 'text', 'datatype' => 'string'),
  188.                                         'avatar_middle' => array('name' => lang('blockclass', 'blockclass_thread_field_avatar_middle'), 'formtype' => 'text', 'datatype' => 'string'),
  189.                                         'avatar_big' => array('name' => lang('blockclass', 'blockclass_thread_field_avatar_big'), 'formtype' => 'text', 'datatype' => 'string'),
  190.                                         'forumurl' => array('name' => lang('blockclass', 'blockclass_thread_field_forumurl'), 'formtype' => 'text', 'datatype' => 'string'),
  191.                                         'forumname' => array('name' => lang('blockclass', 'blockclass_thread_field_forumname'), 'formtype' => 'text', 'datatype' => 'string'),
  192.                                         'typename' => array('name' => lang('blockclass', 'blockclass_thread_field_typename'), 'formtype' => 'text', 'datatype' => 'string'),
  193.                                         'typeicon' => array('name' => lang('blockclass', 'blockclass_thread_field_typeicon'), 'formtype' => 'text', 'datatype' => 'string'),
  194.                                         'typeurl' => array('name' => lang('blockclass', 'blockclass_thread_field_typeurl'), 'formtype' => 'text', 'datatype' => 'string'),
  195.                                         'sortname' => array('name' => lang('blockclass', 'blockclass_thread_field_sortname'), 'formtype' => 'text', 'datatype' => 'string'),
  196.                                         'sorturl' => array('name' => lang('blockclass', 'blockclass_thread_field_sorturl'), 'formtype' => 'text', 'datatype' => 'string'),
  197.                                         'posts' => array('name' => lang('blockclass', 'blockclass_thread_field_posts'), 'formtype' => 'text', 'datatype' => 'int'),
  198.                                         'todayposts' => array('name' => lang('blockclass', 'blockclass_thread_field_todayposts'), 'formtype' => 'text', 'datatype' => 'int'),
  199.                                         'lastpost' => array('name' => lang('blockclass', 'blockclass_thread_field_lastpost'), 'formtype' => 'date', 'datatype' => 'date'),
  200.                                         'dateline' => array('name' => lang('blockclass', 'blockclass_thread_field_dateline'), 'formtype' => 'date', 'datatype' => 'date'),
  201.                                         'replies' => array('name' => lang('blockclass', 'blockclass_thread_field_replies'), 'formtype' => 'text', 'datatype' => 'int'),
  202.                                         'views' => array('name' => lang('blockclass', 'blockclass_thread_field_views'), 'formtype' => 'text', 'datatype' => 'int'),
  203.                                         'heats' => array('name' => lang('blockclass', 'blockclass_thread_field_heats'), 'formtype' => 'text', 'datatype' => 'int'),
  204.                                         'recommends' => array('name' => lang('blockclass', 'blockclass_thread_field_recommends'), 'formtype' => 'text', 'datatype' => 'int'),
  205.                                 );
  206.         }

  207.         function fieldsconvert() {
  208.                 return array(
  209.                                 'portal_article' => array(
  210.                                         'name' => lang('blockclass', 'blockclass_portal_article'),
  211.                                         'script' => 'article',
  212.                                         'searchkeys' => array('author', 'authorid', 'forumurl', 'forumname', 'posts', 'views', 'replies'),
  213.                                         'replacekeys' => array('username', 'uid', 'caturl', 'catname', 'articles', 'viewnum', 'commentnum'),
  214.                                 ),
  215.                                 'space_blog' => array(
  216.                                         'name' => lang('blockclass', 'blockclass_space_blog'),
  217.                                         'script' => 'blog',
  218.                                         'searchkeys' => array('author', 'authorid', 'views', 'replies'),
  219.                                         'replacekeys' => array('username', 'uid', 'viewnum', 'replynum'),
  220.                                 ),
  221.                                 'group_thread' => array(
  222.                                         'name' => lang('blockclass', 'blockclass_group_thread'),
  223.                                         'script' => 'groupthread',
  224.                                         'searchkeys' => array('forumname', 'forumurl'),
  225.                                         'replacekeys' => array('groupname', 'groupurl'),
  226.                                 ),
  227.                         );
  228.         }

  229.         function getsetting() {
  230.                 global $_G;
  231.                 $settings = $this->setting;

  232.                 if($settings['fids']) {
  233.                         loadcache('forums');
  234.                         $settings['fids']['value'][] = array(0, lang('portalcp', 'block_all_forum'));
  235.                         foreach($_G['cache']['forums'] as $fid => $forum) {
  236.                                 $settings['fids']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat(' ', 4) : ($forum['type'] == 'sub' ? str_repeat(' ', 8) : '')).$forum['name']);
  237.                         }
  238.                 }
  239.                 if($settings['sortids']) {
  240.                         $settings['sortids']['value'][] = array(0, 'threadlist_sortids_all');
  241.                         $query = DB::query("SELECT typeid, name, special FROM ".DB::table('forum_threadtype')." WHERE special>'0' ORDER BY typeid DESC");
  242.                         while($threadtype = DB::fetch($query)) {
  243.                                 $settings['sortids']['value'][] = array($threadtype['typeid'], $threadtype['name']);
  244.                         }
  245.                 }
  246.                 return $settings;
  247.         }

  248.         function getdata($style, $parameter) {
  249.                 global $_G;

  250.                 $returndata = array('html' => '', 'data' => '');
  251.                 $parameter = $this->cookparameter($parameter);

  252.                 loadcache('forums', 'stamps');
  253.                 $tids                = !empty($parameter['tids']) ? explode(',', $parameter['tids']) : array();
  254.                 $uids                = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array();
  255.                 $startrow        = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0;
  256.                 $items                = !empty($parameter['items']) ? intval($parameter['items']) : 10;
  257.                 $digest                = isset($parameter['digest']) ? $parameter['digest'] : 0;
  258.                 $stick                = isset($parameter['stick']) ? $parameter['stick'] : 0;
  259.                 $orderby        = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';
  260.                 $lastpost        = isset($parameter['lastpost']) ? intval($parameter['lastpost']) : 0;
  261.                 $postdateline        = isset($parameter['postdateline']) ? intval($parameter['postdateline']) : 0;
  262.                 $titlelength        = !empty($parameter['titlelength']) ? intval($parameter['titlelength']) : 40;
  263.                 $summarylength        = !empty($parameter['summarylength']) ? intval($parameter['summarylength']) : 80;
  264.                 $recommend        = !empty($parameter['recommend']) ? 1 : 0;
  265.                 $keyword        = !empty($parameter['keyword']) ? $parameter['keyword'] : '';
  266.                 $tagkeyword        = !empty($parameter['tagkeyword']) ? $parameter['tagkeyword'] : '';
  267.                 $typeids        = !empty($parameter['typeids']) ? explode(',',$parameter['typeids']) : array();
  268.                 $sortids        = !empty($parameter['sortids']) && !in_array(0, (array)$parameter['sortids']) ? $parameter['sortids'] : array();
  269.                 $special        = !empty($parameter['special']) ? $parameter['special'] : array();
  270.                 $rewardstatus        = !empty($parameter['rewardstatus']) ? intval($parameter['rewardstatus']) : 0;
  271.                 //$picrequired        = !empty($parameter['picrequired']) ? 1 : 0;
  272.                 $picrequired = in_array($parameter['picrequired'],array('0','1','2')) ? $parameter['picrequired'] : 0; //edit cr180 2013年6月19日 21:48:52
  273.                 $viewmod        = !empty($parameter['viewmod']) ? 1 : 0;
  274.                 $highlight = !empty($parameter['highlight']) ? 1 : 0;

  275.                 $fids = array();
  276.                 if(!empty($parameter['fids'])) {
  277.                         if(isset($parameter['fids'][0]) && $parameter['fids'][0] == '0') {
  278.                                 unset($parameter['fids'][0]);
  279.                         }
  280.                         $fids = $parameter['fids'];
  281.                 }

  282.                 $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();

  283.                 require_once libfile('function/post');
  284.                 require_once libfile('function/search');

  285.                 $datalist = $list = $listtids = $pictids = $pics = $threadtids = $threadtypeids = $tagids = array();
  286.                 $keyword = $keyword ? searchkey($keyword, "t.subject LIKE '%{text}%'") : '';
  287.                 if($tagkeyword) {
  288.                         if(!($tagids = DB::fetch_all('SELECT tagid FROM '.DB::table('common_tag').' WHERE 1'.searchkey($tagkeyword, "tagname LIKE '%{text}%'"), '', 'tagid'))) {
  289.                                 return array('data' => '');
  290.                         }
  291.                 }

  292.                 $threadsorts = $threadtypes = array();
  293.                 $querytmp = DB::query("SELECT typeid, name, special FROM ".DB::table('forum_threadtype')." WHERE special>'0'");
  294.                 while($value = DB::fetch($querytmp)) {
  295.                         $threadsorts[$value['typeid']] = $value;
  296.                 }
  297.                 $querytmp = DB::query("SELECT * FROM ".DB::table('forum_threadclass'));
  298.                 foreach(C::t('forum_threadclass')->range() as $value) {
  299.                         $threadtypes[$value['typeid']] = $value;
  300.                 }

  301.                 $sql = ($fids ? ' AND t.fid IN ('.dimplode($fids).')' : '')
  302.                         .($tids ? ' AND t.tid IN ('.dimplode($tids).')' : '')
  303.                         .($uids ? ' AND t.authorid IN ('.dimplode($uids).')' : '')
  304.                         .($typeids ? ' AND t.typeid IN ('.dimplode($typeids).')' : '')
  305.                         .($sortids ? ' AND t.sortid IN ('.dimplode($sortids).')' : '')
  306.                         .($special ? ' AND t.special IN ('.dimplode($special).')' : '')
  307.                         .((in_array(3, $special) && $rewardstatus) ? ($rewardstatus == 1 ? ' AND t.price < 0' : ' AND t.price > 0') : '')
  308.                         .($digest ? ' AND t.digest IN ('.dimplode($digest).')' : '')
  309.                         .($stick ? ' AND t.displayorder IN ('.dimplode($stick).')' : '')
  310.                         .($bannedids ? ' AND t.tid NOT IN ('.dimplode($bannedids).')' : '')
  311.                         .$keyword
  312.                         ." AND t.isgroup='0'";

  313.                 if($postdateline) {
  314.                         $time = TIMESTAMP - $postdateline;
  315.                         $sql .= " AND t.dateline >= '$time'";
  316.                 }
  317.                 if($lastpost) {
  318.                         $time = TIMESTAMP - $lastpost;
  319.                         $sql .= " AND t.lastpost >= '$time'";
  320.                 }
  321.                 if($orderby == 'heats') {
  322.                         $sql .= " AND t.heats>'0'";
  323.                 }
  324.                 $sqlfrom = $sqlfield = $joinmethodpic = '';

  325.                 if($picrequired) {
  326.                         $joinmethodpic = 'INNER';
  327.                 } else if($style['getpic']) {
  328.                         $joinmethodpic = 'LEFT';
  329.                 }
  330.                 //add cr180 2013年6月19日 21:49:08
  331.                 if($picrequired =='2'){
  332.                         unset($joinmethodpic);
  333.                         $sql .= " AND t.attachment=0";
  334.                 }
  335.                 //end
  336.                
  337.                 if($joinmethodpic) {
  338.                         $sqlfrom .= " $joinmethodpic JOIN `".DB::table('forum_threadimage')."` ti ON t.tid=ti.tid";
  339.                         $sqlfield = ', ti.attachment as attachmenturl, ti.remote';
  340.                 }

  341.                 $joinmethod = empty($tids) ? 'INNER' : 'LEFT';
  342.                 if($recommend) {
  343.                         $sqlfrom .= " $joinmethod JOIN `".DB::table('forum_forumrecommend')."` fc ON fc.tid=t.tid";
  344.                 }

  345.                 if($tagids) {
  346.                         $sqlfrom .= " $joinmethod JOIN `".DB::table('common_tagitem')."` tim ON tim.tagid IN (".dimplode(array_keys($tagids)).") AND tim.itemid=t.tid AND tim.idtype='tid' ";
  347.                 }

  348.                 $maxwhere = '';
  349.                 if(!$tids && !$fids && !$digest && !$stick && $_G['setting']['blockmaxaggregationitem']) {
  350.                         $maxwhere = ($maxid = $this->getmaxid() - $_G['setting']['blockmaxaggregationitem']) > 0 ? 't.tid > '.$maxid.' AND ' : '';
  351.                 }

  352.                 $query = DB::query("SELECT DISTINCT t.*$sqlfield
  353.                         FROM `".DB::table('forum_thread')."` t
  354.                         $sqlfrom WHERE {$maxwhere}t.readperm='0'
  355.                         $sql
  356.                         AND t.displayorder>='0'
  357.                         ORDER BY t.$orderby DESC
  358.                         LIMIT $startrow,$items;"
  359.                         );
  360.                 while($data = DB::fetch($query)) {
  361.                         $_G['block_thread'][$data['tid']] = $data;
  362.                         if($style['getsummary']) {
  363.                                 $threadtids[$data['posttableid']][] = $data['tid'];
  364.                         }
  365.                         $listtids[$data['tid']] = $data['tid'];
  366.                         $list[$data['tid']] = array(
  367.                                 'id' => $data['tid'],
  368.                                 'idtype' => 'tid',
  369.                                 'title' => cutstr(str_replace('\\\'', ''', addslashes($data['subject'])), $titlelength, ''),
  370.                                 'url' => 'forum.php?mod=viewthread&tid='.$data['tid'].($viewmod ? '&from=portal' : ''),
  371.                                 'pic' => $data['attachmenturl'] ? 'forum/'.$data['attachmenturl'] : STATICURL.'image/common/nophoto.gif',
  372.                                 'picflag' => $data['attachmenturl'] ? ($data['remote'] ? '2' : '1') : '0',
  373.                                 'fields' => array(
  374.                                         'fulltitle' => str_replace('\\\'', ''', addslashes($data['subject'])),
  375.                                         'threads' => $data['threads'],
  376.                                         'author' => $data['author'] ? $data['author'] : $_G['setting']['anonymoustext'],
  377.                                         'authorid' => $data['author'] ? $data['authorid'] : 0,
  378.                                         'avatar' => avatar(($data['author'] ? $data['authorid'] : 0), 'small', true, false, false, $_G['setting']['ucenterurl']),
  379.                                         'avatar_middle' => avatar(($data['author'] ? $data['authorid'] : 0), 'middle', true, false, false, $_G['setting']['ucenterurl']),
  380.                                         'avatar_big' => avatar(($data['author'] ? $data['authorid'] : 0), 'big', true, false, false, $_G['setting']['ucenterurl']),
  381.                                         'posts' => $data['posts'],
  382.                                         'todayposts' => $data['todayposts'],
  383.                                         'lastpost' => $data['lastpost'],
  384.                                         'dateline' => $data['dateline'],
  385.                                         'replies' => $data['replies'],
  386.                                         'forumurl' => 'forum.php?mod=forumdisplay&fid='.$data['fid'],
  387.                                         'forumname' => $_G['cache']['forums'][$data['fid']]['name'],
  388.                                         'typename' => $threadtypes[$data['typeid']]['name'],
  389.                                         'typeicon' => $threadtypes[$data['typeid']]['icon'],
  390.                                         'typeurl' => 'forum.php?mod=forumdisplay&fid='.$data['fid'].'&filter=typeid&typeid='.$data['typeid'],
  391.                                         'sortname' => $threadsorts[$data['sortid']]['name'],
  392.                                         'sorturl' => 'forum.php?mod=forumdisplay&fid='.$data['fid'].'&filter=sortid&sortid='.$data['sortid'],
  393.                                         'views' => $data['views'],
  394.                                         'heats' => $data['heats'],
  395.                                         'recommends' => $data['recommends'],
  396.                                         'hourviews' => $data['views'],
  397.                                         'todayviews' => $data['views'],
  398.                                         'weekviews' => $data['views'],
  399.                                         'monthviews' => $data['views']
  400.                                 )
  401.                         );
  402.                         if($highlight && $data['highlight']) {
  403.                                 $list[$data['tid']]['fields']['showstyle'] = $this->getthreadstyle($data['highlight']);
  404.                         }
  405.                 }

  406.                 if($listtids) {
  407.                         $threads = $this->getthread($threadtids, $summarylength);
  408.                         if($threads) {
  409.                                 foreach($threads as $tid => $var) {
  410.                                         $list[$tid]['summary'] = $var;
  411.                                 }
  412.                         }

  413.                         foreach($listtids as $key => $value) {
  414.                                 $datalist[] = $list[$value];
  415.                         }
  416.                 }

  417.                 $returndata['data'] = $datalist;
  418.                 return $returndata;
  419.         }

  420.         function getthread($tidarray, $messagelength = 80, $nospecial = false) {
  421.                 global $_G;
  422.                 if(!$tidarray) {
  423.                         return '';
  424.                 }
  425.                 $notexists = $messagearr = $returnarr = array();
  426.                 foreach($tidarray as $var) {
  427.                         foreach($var as $v) {
  428.                                 if(empty($_G['block_thread'][$v])) {
  429.                                         $notexists[] = $v;
  430.                                 }
  431.                         }
  432.                 }
  433.                 if($notexists) {
  434.                         $query = DB::query("SELECT tid, fid, subject, posttableid, price, special FROM ".DB::table('forum_thread')." WHERE tid IN (".dimplode($notexists).")");
  435.                         while($result = DB::fetch($query)) {
  436.                                 $_G['block_thread'][$result['tid']] = $result;
  437.                         }
  438.                 }
  439.                 foreach($tidarray as $key => $var) {
  440.                         if($key == 0) {
  441.                                 $posttable = 'forum_post';
  442.                         } else {
  443.                                 $posttable = "forum_post_{$key}";
  444.                         }
  445.                         $query = DB::query("SELECT tid, message FROM ".DB::table($posttable)." WHERE tid IN  (".dimplode($var).") AND first=1");
  446.                         while($result = DB::fetch($query)) {
  447.                                 $messagearr[$result['tid']] = $result['message'];
  448.                         }
  449.                 }
  450.                 require_once libfile('function/post');
  451.                 require_once libfile('function/discuzcode');
  452.                 if($messagearr) {
  453.                         foreach($messagearr as $tid => $var) {
  454.                                 $thread = $_G['block_thread'][$tid];
  455.                                 if($nospecial) {
  456.                                         $thread['special'] = 0;
  457.                                 }
  458.                                 if($thread['special'] == 1) {
  459.                                         $polloptions = array();
  460.                                         $multiple = DB::result_first("SELECT multiple FROM ".DB::table('forum_poll')." WHERE tid='$tid'");
  461.                                         $optiontype = $multiple ? 'checkbox' : 'radio';
  462.                                         $query = DB::query("SELECT polloptionid, polloption FROM ".DB::table('forum_polloption')." WHERE tid='$tid' ORDER BY displayorder");
  463.                                         while($polloption = DB::fetch($query)) {
  464.                                                 $polloption['polloption'] = preg_replace("/\[url=(https?){1}:\/\/([^\["']+?)\](.+?)\[\/url\]/i",
  465.                                                         "<a href="\\1://\\2" target="_blank">\\3</a>", $polloption['polloption']);
  466.                                                 $polloptions[] = $polloption;
  467.                                         }
  468.                                 } elseif($thread['special'] == 2) {
  469.                                         $trade = C::t('forum_trade')->fetch_first_goods($tid);
  470.                                         $trade['aid'] = $trade['aid'] ? getforumimg($trade['aid']) : '';
  471.                                         $trades[$tid][] = $trade;
  472.                                 } elseif($thread['special'] == 3) {
  473.                                         $extcredits = $_G['settings']['extcredits'];
  474.                                         $creditstransextra = $_G['settings']['creditstransextra'];
  475.                                         $rewardend = $thread['price'] < 0;
  476.                                         $rewardprice = abs($thread['price']);
  477.                                         $message = messagecutstr($var, $messagelength);
  478.                                 } elseif($thread['special'] == 4) {
  479.                                         $message = messagecutstr($var, $messagelength);
  480.                                         $activity = DB::fetch_first("SELECT aid, number, applynumber FROM ".DB::table('forum_activity')." WHERE tid='$tid'");
  481.                                         $activity['aid'] = $activity['aid'] ? getforumimg($activity['aid']) : '';
  482.                                         $activity['aboutmember'] = $activity['number'] - $activity['applynumber'];
  483.                                 } elseif($thread['special'] == 5) {
  484.                                         $message = messagecutstr($var, $messagelength);
  485.                                         $debate = C::t('forum_debate')->fetch($tid);
  486.                                         $debate['affirmvoteswidth'] = $debate['affirmvotes']  ? intval(80 * (($debate['affirmvotes'] + 1) / ($debate['affirmvotes'] + $debate['negavotes'] + 1))) : 1;
  487.                                         $debate['negavoteswidth'] = $debate['negavotes']  ? intval(80 * (($debate['negavotes'] + 1) / ($debate['affirmvotes'] + $debate['negavotes'] + 1))) : 1;
  488.                                         $debate['affirmpoint'] = discuzcode($debate['affirmpoint'], 0, 0, 0, 1, 1, 0, 0, 0, 0, 0);
  489.                                         $debate['negapoint'] = discuzcode($debate['negapoint'], 0, 0, 0, 1, 1, 0, 0, 0, 0, 0);
  490.                                 } else {
  491.                                         $message = messagecutstr($var, $messagelength);
  492.                                 }
  493.                                 include template('common/block_thread');
  494.                                 $returnarr[$tid] = $return;
  495.                         }
  496.                 }

  497.                 return $returnarr;
  498.         }

  499.         function getpic($tid) {
  500.                 global $_G;
  501.                 if(!$tid) {
  502.                         return '';
  503.                 }
  504.                 $pic = DB::fetch_first("SELECT attachment, remote FROM ".DB::table(getattachtablebytid($tid))." WHERE tid='$tid' AND isimage IN (1, -1) ORDER BY dateline DESC LIMIT 0,1");
  505.                 return $pic;
  506.         }

  507.         function getpics($tids) {
  508.                 $data = array();
  509.                 $tids = !empty($tids) && is_array($tids) ? $tids : array($tids);
  510.                 $tids = array_map('intval', $tids);
  511.                 $tids = array_filter($tids);
  512.                 if(!empty($tids)) {
  513.                         $query = DB::query('SELECT * FROM '.DB::table('forum_threadimage').' WHERE tid IN ('.dimplode($tids).')');
  514.                         while($value = DB::fetch($query)) {
  515.                                 $data[$value['tid']] = $value;
  516.                         }
  517.                 }
  518.                 return $data;
  519.         }

  520.         function getthreadstyle($highlight) {
  521.                 $rt = array();
  522.                 if($highlight) {
  523.                         $color = array('', '#EE1B2E', '#EE5023', '#996600', '#3C9D40', '#2897C5', '#2B65B7', '#8F2A90', '#EC1282');
  524.                         $string = sprintf('%02d', $highlight);
  525.                         $stylestr = sprintf('%03b', $string[0]);
  526.                         $rt = array(
  527.                                 'title_b' => $stylestr[0] ? '1' : '',
  528.                                 'title_i' => $stylestr[1] ? '1' : '',
  529.                                 'title_u' => $stylestr[2] ? '1' : '',
  530.                                 'title_c' => $string[1] ? $color[$string[1]] : '',
  531.                                 );
  532.                 }
  533.                 return $rt;
  534.         }

  535.         function getmaxid() {
  536.                 loadcache('databasemaxid');
  537.                 $data = getglobal('cache/databasemaxid');
  538.                 if(!isset($data['thread']) || TIMESTAMP - $data['thread']['dateline'] >= 86400) {
  539.                         $data['thread']['dateline'] = TIMESTAMP;
  540.                         $data['thread']['id'] = DB::result_first('SELECT MAX(tid) FROM '.DB::table('forum_thread'));
  541.                         savecache('databasemaxid', $data);
  542.                 }
  543.                 return $data['thread']['id'];
  544.         }
  545. }


  546. ?>
复制代码
另外,附上懒人包



收客官2个金币,请别介意。(*^__^*) 嘻嘻……


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
 楼主| 流年无殇 发表于 2013-6-20 00:15:10 | 显示全部楼层
自己占沙发,睡觉。。。
回复

使用道具 举报

襄樊力天网络 发表于 2013-7-20 20:00:20 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

isdvr888 发表于 2013-7-31 16:28:05 | 显示全部楼层
顶楼主一个。
回复

使用道具 举报

37670975 发表于 2013-9-29 05:30:57 | 显示全部楼层
??提示“内容显示错误,无法显示此内容”
回复

使用道具 举报

 楼主| 流年无殇 发表于 2013-9-30 08:17:10 | 显示全部楼层
37670975 发表于 2013-9-29 05:30
??提示“内容显示错误,无法显示此内容”

你的版本是 x3?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-5-3 12:22 , Processed in 0.127019 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表