PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/web raovat.vn php/az24/source/class/block/forum/block_trade.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 273 lines | 247 code | 20 blank | 6 comment | 16 complexity | 6895aa9c220371f3f6f06a994013b8f2 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_trade.php 27675 2012-02-09 07:58:13Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class block_trade extends discuz_block {
  12. var $setting = array();
  13. function block_trade(){
  14. $this->setting = array(
  15. 'tids' => array(
  16. 'title' => 'tradelist_tids',
  17. 'type' => 'text'
  18. ),
  19. 'uids' => array(
  20. 'title' => 'tradelist_uids',
  21. 'type' => 'text'
  22. ),
  23. 'keyword' => array(
  24. 'title' => 'tradelist_keyword',
  25. 'type' => 'text'
  26. ),
  27. 'fids' => array(
  28. 'title' => 'tradelist_fids',
  29. 'type' => 'mselect',
  30. 'value' => array()
  31. ),
  32. 'viewmod' => array(
  33. 'title' => 'threadlist_viewmod',
  34. 'type' => 'radio'
  35. ),
  36. 'digest' => array(
  37. 'title' => 'tradelist_digest',
  38. 'type' => 'mcheckbox',
  39. 'value' => array(
  40. array(1, 'tradelist_digest_1'),
  41. array(2, 'tradelist_digest_2'),
  42. array(3, 'tradelist_digest_3'),
  43. array(0, 'tradelist_digest_0')
  44. ),
  45. ),
  46. 'stick' => array(
  47. 'title' => 'tradelist_stick',
  48. 'type' => 'mcheckbox',
  49. 'value' => array(
  50. array(1, 'tradelist_stick_1'),
  51. array(2, 'tradelist_stick_2'),
  52. array(3, 'tradelist_stick_3'),
  53. array(0, 'tradelist_stick_0')
  54. ),
  55. ),
  56. 'recommend' => array(
  57. 'title' => 'tradelist_recommend',
  58. 'type' => 'radio'
  59. ),
  60. 'orderby' => array(
  61. 'title' => 'tradelist_orderby',
  62. 'type'=> 'mradio',
  63. 'value' => array(
  64. array('dateline', 'tradelist_orderby_dateline'),
  65. array('todayhots', 'tradelist_orderby_todayhots'),
  66. array('weekhots', 'tradelist_orderby_weekhots'),
  67. array('monthhots', 'tradelist_orderby_monthhots'),
  68. ),
  69. 'default' => 'dateline'
  70. ),
  71. 'highlight' => array(
  72. 'title' => 'tradelist_highlight',
  73. 'type' => 'radio',
  74. 'default' => 0,
  75. ),
  76. 'titlelength' => array(
  77. 'title' => 'tradelist_titlelength',
  78. 'type' => 'text',
  79. 'default' => 40
  80. ),
  81. 'summarylength' => array(
  82. 'title' => 'tradelist_summarylength',
  83. 'type' => 'text',
  84. 'default' => 80
  85. ),
  86. 'startrow' => array(
  87. 'title' => 'tradelist_startrow',
  88. 'type' => 'text',
  89. 'default' => 0
  90. ),
  91. );
  92. }
  93. function name() {
  94. return lang('blockclass', 'blockclass_trade_script_trade');
  95. }
  96. function blockclass() {
  97. return array('trade', lang('blockclass', 'blockclass_trade_trade'));
  98. }
  99. function fields() {
  100. return array(
  101. 'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
  102. 'url' => array('name' => lang('blockclass', 'blockclass_trade_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
  103. 'title' => array('name' => lang('blockclass', 'blockclass_trade_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
  104. 'pic' => array('name' => lang('blockclass', 'blockclass_trade_field_pic'), 'formtype' => 'pic', 'datatype' => 'pic'),
  105. 'summary' => array('name' => lang('blockclass', 'blockclass_trade_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
  106. 'totalitems' => array('name' => lang('blockclass', 'blockclass_trade_field_totalitems'), 'formtype' => 'text', 'datatype' => 'int'),
  107. 'author' => array('name' => lang('blockclass', 'blockclass_trade_field_author'), 'formtype' => 'text', 'datatype' => 'text'),
  108. 'authorid' => array('name' => lang('blockclass', 'blockclass_trade_field_authorid'), 'formtype' => 'text', 'datatype' => 'int'),
  109. 'price' => array('name' => lang('blockclass', 'blockclass_trade_field_price'), 'formtype' => 'text', 'datatype' => 'text'),
  110. );
  111. }
  112. function fieldsconvert() {
  113. return array(
  114. 'group_trade' => array(
  115. 'name' => lang('blockclass', 'blockclass_group_trade'),
  116. 'script' => 'grouptrade',
  117. 'searchkeys' => array(),
  118. 'replacekeys' => array(),
  119. ),
  120. );
  121. }
  122. function getsetting() {
  123. global $_G;
  124. $settings = $this->setting;
  125. if($settings['fids']) {
  126. loadcache('forums');
  127. $settings['fids']['value'][] = array(0, lang('portalcp', 'block_all_forum'));
  128. foreach($_G['cache']['forums'] as $fid => $forum) {
  129. $settings['fids']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name']);
  130. }
  131. }
  132. return $settings;
  133. }
  134. function getdata($style, $parameter) {
  135. global $_G;
  136. $parameter = $this->cookparameter($parameter);
  137. loadcache('forums');
  138. $tids = !empty($parameter['tids']) ? explode(',', $parameter['tids']) : array();
  139. $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array();
  140. $startrow = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0;
  141. $items = isset($parameter['items']) ? intval($parameter['items']) : 10;
  142. $digest = isset($parameter['digest']) ? $parameter['digest'] : 0;
  143. $stick = isset($parameter['stick']) ? $parameter['stick'] : 0;
  144. $orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('dateline','todayhots','weekhots','monthhots')) ? $parameter['orderby'] : 'dateline') : 'dateline';
  145. $titlelength = !empty($parameter['titlelength']) ? intval($parameter['titlelength']) : 40;
  146. $summarylength = !empty($parameter['summarylength']) ? intval($parameter['summarylength']) : 80;
  147. $recommend = !empty($parameter['recommend']) ? 1 : 0;
  148. $keyword = !empty($parameter['keyword']) ? $parameter['keyword'] : '';
  149. $viewmod = !empty($parameter['viewmod']) ? 1 : 0;
  150. $highlight = !empty($parameter['highlight']) ? 1 : 0;
  151. $fids = array();
  152. if(!empty($parameter['fids'])) {
  153. if($parameter['fids'][0] == '0') {
  154. unset($parameter['fids'][0]);
  155. }
  156. $fids = $parameter['fids'];
  157. }
  158. $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();
  159. require_once libfile('function/post');
  160. require_once libfile('function/search');
  161. $datalist = $list = $listpids = $threadpids = $aid2pid = $attachtables = array();
  162. $keyword = $keyword ? searchkey($keyword, "t.subject LIKE '%{text}%'") : '';
  163. $sql = ($fids ? ' AND t.fid IN ('.dimplode($fids).')' : '')
  164. .($tids ? ' AND t.tid IN ('.dimplode($tids).')' : '')
  165. .($digest ? ' AND t.digest IN ('.dimplode($digest).')' : '')
  166. .($stick ? ' AND t.displayorder IN ('.dimplode($stick).')' : '')
  167. ." AND t.isgroup='0'";
  168. $where = '';
  169. if(in_array($orderby, array('todayhots','weekhots','monthhots'))) {
  170. $historytime = 0;
  171. switch($orderby) {
  172. case 'todayhots':
  173. $historytime = mktime(0, 0, 0, date('m', TIMESTAMP), date('d', TIMESTAMP), date('Y', TIMESTAMP));
  174. break;
  175. case 'weekhots':
  176. $week = gmdate('w', TIMESTAMP) - 1;
  177. $week = $week != -1 ? $week : 6;
  178. $historytime = mktime(0, 0, 0, date('m', TIMESTAMP), date('d', TIMESTAMP) - $week, date('Y', TIMESTAMP));
  179. break;
  180. case 'monthhots':
  181. $historytime = mktime(0, 0, 0, date('m', TIMESTAMP), 1, date('Y', TIMESTAMP));
  182. break;
  183. }
  184. $where = ' WHERE tr.dateline>='.$historytime;
  185. $orderby = 'totalitems';
  186. }
  187. $where .= ($uids ? ' AND tr.sellerid IN ('.dimplode($uids).')' : '').$keyword;
  188. $where .= ($bannedids ? ' AND tr.pid NOT IN ('.dimplode($bannedids).')' : '');
  189. $sqlfrom = " INNER JOIN `".DB::table('forum_thread')."` t ON t.tid=tr.tid $sql AND t.displayorder>='0'";
  190. $joinmethod = empty($tids) ? 'INNER' : 'LEFT';
  191. if($recommend) {
  192. $sqlfrom .= " $joinmethod JOIN `".DB::table('forum_forumrecommend')."` fc ON fc.tid=tr.tid";
  193. }
  194. $sqlfield = $highlight ? ', t.highlight' : '';
  195. $query = DB::query("SELECT tr.pid, tr.tid, tr.aid, tr.price, tr.credit, tr.subject, tr.totalitems, tr.seller, tr.sellerid$sqlfield
  196. FROM ".DB::table('forum_trade')." tr $sqlfrom $where
  197. ORDER BY tr.$orderby DESC
  198. LIMIT $startrow,$items;"
  199. );
  200. require_once libfile('block_thread', 'class/block/forum');
  201. $bt = new block_thread();
  202. while($data = DB::fetch($query)) {
  203. if($style['getsummary']) {
  204. $threadpids[$data['posttableid']][] = $data['pid'];
  205. }
  206. if($data['aid']) {
  207. $aid2pid[$data['aid']] = $data['pid'];
  208. $attachtable = getattachtableid($data['tid']);
  209. $attachtables[$attachtable][] = $data['aid'];
  210. }
  211. $listpids[] = $data['pid'];
  212. $list[$data['pid']] = array(
  213. 'id' => $data['pid'],
  214. 'idtype' => 'pid',
  215. 'title' => cutstr(str_replace('\\\'', '&#39;', addslashes($data['subject'])), $titlelength, ''),
  216. 'url' => 'forum.php?mod=viewthread&do=tradeinfo&tid='.$data['tid'].'&pid='.$data['pid'].($viewmod ? '&from=portal' : ''),
  217. 'pic' => ($data['aid'] ? '' : $_G['style']['imgdir'].'/nophoto.gif'),
  218. 'picflag' => '0',
  219. 'fields' => array(
  220. 'fulltitle' => str_replace('\\\'', '&#39;', addslashes($data['subject'])),
  221. 'totalitems' => $data['totalitems'],
  222. 'author' => $data['seller'] ? $data['seller'] : $_G['setting']['anonymoustext'],
  223. 'authorid' => $data['sellerid'] ? $data['sellerid'] : 0,
  224. 'price' => ($data['price'] > 0 ? '&yen; '.$data['price'] : '').($data['credit'] > 0 ? ($data['price'] > 0 ? lang('block/tradelist', 'tradelist_price_add') : '').$data['credit'].' '.$_G['setting']['extcredits'][$_G['setting']['creditstransextra'][5]]['unit'].$_G['setting']['extcredits'][$_G['setting']['creditstransextra'][5]]['title'] : ''),
  225. )
  226. );
  227. if($highlight && $data['highlight']) {
  228. $list[$data['tid']]['fields']['showstyle'] = $bt->getthreadstyle($data['highlight']);
  229. }
  230. }
  231. if(!empty($listpids)) {
  232. foreach($threadpids as $key => $var) {
  233. $posttable = $key == 0 ? 'forum_post' : 'forum_post_'.$key;
  234. $query = DB::query("SELECT pid, message FROM ".DB::table($posttable)." WHERE pid IN (".dimplode($var).")");
  235. while($result = DB::fetch($query)) {
  236. $list[$result['pid']]['summary'] = messagecutstr($result['message'], $summarylength);
  237. }
  238. }
  239. foreach($attachtables as $tableid => $taids) {
  240. $query = DB::query('SELECT aid, attachment, remote FROM '.DB::table('forum_attachment_'.$tableid).' WHERE aid IN ('.dimplode($taids).')');
  241. while($avalue = DB::fetch($query)) {
  242. $list[$aid2pid[$avalue['aid']]]['pic'] = 'forum/'.$avalue['attachment'];
  243. $list[$aid2pid[$avalue['aid']]]['picflag'] = $avalue['remote'] ? '2' : '1';
  244. }
  245. }
  246. foreach($listpids as $key => $value) {
  247. $datalist[] = $list[$value];
  248. }
  249. }
  250. return array('html' => '', 'data' => $datalist);
  251. }
  252. }
  253. ?>