PageRenderTime 31ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Quản lý website tin tức PHP/discuznews/source/class/block/html/block_sort.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 274 lines | 239 code | 29 blank | 6 comment | 41 complexity | f2d4275ab4568b84995163d4db7fb322 MD5 | raw file
  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_sort.php 29557 2012-04-18 10:10:07Z svn_project_zhangjie $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. require_once libfile('commonblock_html', 'class/block/html');
  12. class block_sort extends commonblock_html {
  13. var $setting = array();
  14. function block_sort(){
  15. $this->setting = array(
  16. 'tids' => array(
  17. 'title' => 'sortlist_tids',
  18. 'type' => 'text'
  19. ),
  20. 'fids' => array(
  21. 'title' => 'sortlist_fids',
  22. 'type' => 'mselect',
  23. 'value' => array()
  24. ),
  25. 'sortids' => array(
  26. 'title' => 'sortlist_sortids',
  27. 'type' => 'mradio',
  28. 'value' => array()
  29. ),
  30. 'digest' => array(
  31. 'title' => 'sortlist_digest',
  32. 'type' => 'mcheckbox',
  33. 'value' => array(
  34. array(1, 'sortlist_digest_1'),
  35. array(2, 'sortlist_digest_2'),
  36. array(3, 'sortlist_digest_3'),
  37. array(0, 'sortlist_digest_0')
  38. ),
  39. ),
  40. 'stick' => array(
  41. 'title' => 'sortlist_stick',
  42. 'type' => 'mcheckbox',
  43. 'value' => array(
  44. array(1, 'sortlist_stick_1'),
  45. array(2, 'sortlist_stick_2'),
  46. array(3, 'sortlist_stick_3'),
  47. array(0, 'sortlist_stick_0')
  48. ),
  49. ),
  50. 'recommend' => array(
  51. 'title' => 'sortlist_recommend',
  52. 'type' => 'radio'
  53. ),
  54. 'orderby' => array(
  55. 'title' => 'sortlist_orderby',
  56. 'type'=> 'mradio',
  57. 'value' => array(
  58. array('lastpost', 'sortlist_orderby_lastpost'),
  59. array('dateline', 'sortlist_orderby_dateline'),
  60. array('replies', 'sortlist_orderby_replies'),
  61. array('views', 'sortlist_orderby_views'),
  62. array('heats', 'sortlist_orderby_heats'),
  63. array('recommends', 'sortlist_orderby_recommends'),
  64. ),
  65. 'default' => 'lastpost'
  66. ),
  67. 'lastpost' => array(
  68. 'title' => 'sortlist_lastpost',
  69. 'type'=> 'mradio',
  70. 'value' => array(
  71. array('0', 'sortlist_lastpost_nolimit'),
  72. array('3600', 'sortlist_lastpost_hour'),
  73. array('86400', 'sortlist_lastpost_day'),
  74. array('604800', 'sortlist_lastpost_week'),
  75. array('2592000', 'sortlist_lastpost_month'),
  76. ),
  77. 'default' => '0'
  78. ),
  79. 'startrow' => array(
  80. 'title' => 'sortlist_startrow',
  81. 'type' => 'text',
  82. 'default' => 0
  83. ),
  84. 'showitems' => array(
  85. 'title' => 'sortlist_showitems',
  86. 'type' => 'text',
  87. 'default' => 10
  88. ),
  89. );
  90. }
  91. function name() {
  92. return lang('blockclass', 'blockclass_html_script_sort');
  93. }
  94. function getsetting() {
  95. global $_G;
  96. $settings = $this->setting;
  97. if($settings['fids']) {
  98. loadcache('forums');
  99. $settings['fids']['value'][] = array(0, lang('portalcp', 'block_all_forum'));
  100. foreach($_G['cache']['forums'] as $fid => $forum) {
  101. $settings['fids']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name']);
  102. }
  103. }
  104. if($settings['sortids']) {
  105. $defaultvalue = '';
  106. $query = DB::query("SELECT typeid, name, special FROM ".DB::table('forum_threadtype')." ORDER BY typeid DESC");
  107. while($threadtype = DB::fetch($query)) {
  108. if($threadtype['special']) {
  109. if(empty($defaultvalue)) {
  110. $defaultvalue = $threadtype['typeid'];
  111. }
  112. $settings['sortids']['value'][] = array($threadtype['typeid'], $threadtype['name']);
  113. }
  114. }
  115. $settings['sortids']['default'] = $defaultvalue;
  116. }
  117. return $settings;
  118. }
  119. function getdata($style, $parameter) {
  120. global $_G;
  121. $parameter = $this->cookparameter($parameter);
  122. loadcache('forums');
  123. $tids = !empty($parameter['tids']) ? explode(',', $parameter['tids']) : array();
  124. $fids = isset($parameter['fids']) && !in_array(0, (array)$parameter['fids']) ? $parameter['fids'] : array_keys($_G['cache']['forums']);
  125. $startrow = !empty($parameter['startrow']) ? intval($parameter['startrow']) : 0;
  126. $items = !empty($parameter['showitems']) ? intval($parameter['showitems']) : 10;
  127. $digest = isset($parameter['digest']) ? $parameter['digest'] : 0;
  128. $stick = isset($parameter['stick']) ? $parameter['stick'] : 0;
  129. $orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';
  130. $lastpost = isset($parameter['lastpost']) ? intval($parameter['lastpost']) : 0;
  131. $recommend = !empty($parameter['recommend']) ? 1 : 0;
  132. $sortid = isset($parameter['sortids']) ? intval($parameter['sortids']) : '';
  133. if($fids) {
  134. $thefids = array();
  135. foreach($fids as $fid) {
  136. if($_G['cache']['forums'][$fid]['type']=='group') {
  137. $thefids[] = $fid;
  138. }
  139. }
  140. if($thefids) {
  141. foreach($_G['cache']['forums'] as $value) {
  142. if($value['fup'] && in_array($value['fup'], $thefids)) {
  143. $fids[] = intval($value['fid']);
  144. }
  145. }
  146. }
  147. $fids = array_unique($fids);
  148. }
  149. $datalist = $list = array();
  150. $threadtypeids = array();
  151. $sql = ($tids ? ' AND t.tid IN ('.dimplode($tids).')' : '')
  152. .($sortid ? ' AND t.sortid='.$sortid : '')
  153. .($fids ? ' AND t.fid IN ('.dimplode($fids).')' : '')
  154. .($digest ? ' AND t.digest IN ('.dimplode($digest).')' : '')
  155. .($stick ? ' AND t.displayorder IN ('.dimplode($stick).')' : '')
  156. ." AND t.closed='0' AND t.isgroup='0'";
  157. if($lastpost) {
  158. $historytime = TIMESTAMP - $lastpost;
  159. $sql .= " AND t.dateline>='$historytime'";
  160. }
  161. if($orderby == 'heats') {
  162. $_G['setting']['indexhot']['days'] = !empty($_G['setting']['indexhot']['days']) ? intval($_G['setting']['indexhot']['days']) : 8;
  163. $heatdateline = TIMESTAMP - 86400 * $_G['setting']['indexhot']['days'];
  164. $sql .= " AND t.dateline>'$heatdateline' AND t.heats>'0'";
  165. }
  166. $sqlfrom = "FROM `".DB::table('forum_thread')."` t";
  167. $joinmethod = empty($tids) ? 'INNER' : 'LEFT';
  168. if($recommend) {
  169. $sqlfrom .= " $joinmethod JOIN `".DB::table('forum_forumrecommend')."` fc ON fc.tid=t.tid";
  170. }
  171. require_once libfile('function/threadsort');
  172. $templatearray = $sortoptionarray = array();
  173. loadcache(array('threadsort_option_'.$sortid, 'threadsort_template_'.$sortid));
  174. sortthreadsortselectoption($sortid);
  175. $templatearray[$sortid] = $_G['cache']['threadsort_template_'.$sortid]['block'];
  176. $sortoptionarray[$sortid] = $_G['cache']['threadsort_option_'.$sortid];
  177. $isthreadtype = (strpos($templatearray[$sortid], '{typename}') !== false || strpos($templatearray[$sortid], '{typename_url}') !== false ) ? true : false;
  178. $threadtypes = array();
  179. if($isthreadtype && $fids) {
  180. foreach(C::t('forum_forumfield')->fetch_all($fids) as $fid => $forum) {
  181. $threadtypes[$fid] = dunserialize($forum['threadtypes']);
  182. }
  183. }
  184. $html = '';
  185. $threadlist = $verify = $verifyuids = array();
  186. $query = DB::query("SELECT t.*
  187. $sqlfrom WHERE 1 $sql
  188. AND t.readperm='0'
  189. AND t.displayorder>='0'
  190. ORDER BY t.$orderby DESC
  191. LIMIT $startrow,$items;"
  192. );
  193. while($thread = DB::fetch($query)) {
  194. if(isset($_G['setting']['verify']['enabled']) && $_G['setting']['verify']['enabled']) {
  195. $verifyuids[$thread['authorid']] = $thread['authorid'];
  196. }
  197. if($thread['highlight']) {
  198. $color = array('', '#EE1B2E', '#EE5023', '#996600', '#3C9D40', '#2897C5', '#2B65B7', '#8F2A90', '#EC1282');
  199. $string = sprintf('%02d', $thread['highlight']);
  200. $stylestr = sprintf('%03b', $string[0]);
  201. $thread['highlight'] = ' style="';
  202. $thread['highlight'] .= $stylestr[0] ? 'font-weight: bold;' : '';
  203. $thread['highlight'] .= $stylestr[1] ? 'font-style: italic;' : '';
  204. $thread['highlight'] .= $stylestr[2] ? 'text-decoration: underline;' : '';
  205. $thread['highlight'] .= $string[1] ? 'color: '.$color[$string[1]] : '';
  206. $thread['highlight'] .= '"';
  207. } else {
  208. $thread['highlight'] = '';
  209. }
  210. $thread['lastposterenc'] = rawurlencode($thread['lastposter']);
  211. $fid = $thread['fid'];
  212. if($thread['typeid'] && $isthreadtype && $threadtypes[$fid] && !empty($threadtypes[$fid]['prefix']) && isset($threadtypes[$fid]['types'][$thread['typeid']])) {
  213. if($threadtypes[$fid]['prefix'] == 1) {
  214. $thread['typehtml'] = '<em>[<a href="forum.php?mod=forumdisplay&fid='.$fid.'&amp;filter=typeid&amp;typeid='.$thread['typeid'].'">'.$threadtypes[$fid]['types'][$thread['typeid']].'</a>]</em>';
  215. } elseif($threadtypes[$fid]['icons'][$thread['typeid']] && $threadtypes[$fid]['prefix'] == 2) {
  216. $thread['typehtml'] = '<em><a title="'.$threadtypes[$fid]['types'][$thread['typeid']].'" href="forum.php?mod=forumdisplay&fid='.$fid.'&amp;filter=typeid&amp;typeid='.$thread['typeid'].'">'.'<img style="vertical-align: middle;padding-right:4px;" src="'.$threadtypes[$fid]['icons'][$thread['typeid']].'" alt="'.$threadtypes[$fid]['types'][$thread['typeid']].'" /></a></em>';
  217. }
  218. $thread['typename'] = $threadtypes[$fid]['types'][$thread['typeid']];
  219. } else {
  220. $thread['typename'] = $thread['typehtml'] = '';
  221. }
  222. $thread['dateline'] = dgmdate($thread['dateline'], 'u', '9999', getglobal('setting/dateformat'));
  223. $thread['lastpost'] = dgmdate($thread['lastpost'], 'u');
  224. $threadlist[$thread['tid']] = $thread;
  225. }
  226. if(!empty($threadlist)) {
  227. if($verifyuids) {
  228. foreach(C::t('common_member_verify')->fetch_all($verifyuids) as $value) {
  229. foreach($_G['setting']['verify'] as $vid => $vsetting) {
  230. if($vsetting['available'] && $vsetting['showicon'] && $value['verify'.$vid] == 1) {
  231. $srcurl = '';
  232. if(!empty($vsetting['icon'])) {
  233. $srcurl = $vsetting['icon'];
  234. }
  235. $verify[$value['uid']] .= "<a href=\"home.php?mod=spacecp&ac=profile&op=verify&vid=$vid\" target=\"_blank\">".(!empty($srcurl) ? '<img src="'.$srcurl.'" class="vm" alt="'.$vsetting['title'].'" title="'.$vsetting['title'].'" />' : $vsetting['title']).'</a>';
  236. }
  237. }
  238. }
  239. }
  240. $html = implode('', showsortmodetemplate($sortid, $fids, $sortoptionarray, $templatearray, $threadlist, array_keys($threadlist), $verify));
  241. }
  242. return array('html' => $html, 'data' => null);
  243. }
  244. }
  245. ?>