block_grouptrade.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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_grouptrade.php 32768 2013-03-07 09:40:05Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class block_grouptrade extends discuz_block {
  12. var $setting = array();
  13. function block_grouptrade(){
  14. $this->setting = array(
  15. 'tids' => array(
  16. 'title' => 'grouptrade_tids',
  17. 'type' => 'text'
  18. ),
  19. 'uids' => array(
  20. 'title' => 'grouptrade_uids',
  21. 'type' => 'text'
  22. ),
  23. 'keyword' => array(
  24. 'title' => 'grouptrade_keyword',
  25. 'type' => 'text'
  26. ),
  27. 'fids' => array(
  28. 'title' => 'grouptrade_fids',
  29. 'type' => 'text'
  30. ),
  31. 'gtids' => array(
  32. 'title' => 'grouptrade_gtids',
  33. 'type' => 'mselect',
  34. 'value' => array(
  35. ),
  36. ),
  37. 'digest' => array(
  38. 'title' => 'grouptrade_digest',
  39. 'type' => 'mcheckbox',
  40. 'value' => array(
  41. array(1, 'grouptrade_digest_1'),
  42. array(2, 'grouptrade_digest_2'),
  43. array(3, 'grouptrade_digest_3'),
  44. array(0, 'grouptrade_digest_0')
  45. ),
  46. ),
  47. 'stick' => array(
  48. 'title' => 'grouptrade_stick',
  49. 'type' => 'mcheckbox',
  50. 'value' => array(
  51. array(1, 'grouptrade_stick_1'),
  52. array(2, 'grouptrade_stick_2'),
  53. array(3, 'grouptrade_stick_3'),
  54. array(0, 'grouptrade_stick_0')
  55. ),
  56. ),
  57. 'recommend' => array(
  58. 'title' => 'grouptrade_recommend',
  59. 'type' => 'radio'
  60. ),
  61. 'orderby' => array(
  62. 'title' => 'grouptrade_orderby',
  63. 'type'=> 'mradio',
  64. 'value' => array(
  65. array('dateline', 'grouptrade_orderby_dateline'),
  66. array('todayhots', 'grouptrade_orderby_todayhots'),
  67. array('weekhots', 'grouptrade_orderby_weekhots'),
  68. array('monthhots', 'grouptrade_orderby_monthhots'),
  69. ),
  70. 'default' => 'dateline'
  71. ),
  72. 'gviewperm' => array(
  73. 'title' => 'grouptrade_gviewperm',
  74. 'type' => 'mradio',
  75. 'value' => array(
  76. array('-1', 'grouptrade_gviewperm_nolimit'),
  77. array('0', 'grouptrade_gviewperm_only_member'),
  78. array('1', 'grouptrade_gviewperm_all_member')
  79. ),
  80. 'default' => '-1'
  81. ),
  82. 'highlight' => array(
  83. 'title' => 'grouptrade_highlight',
  84. 'type' => 'radio',
  85. 'default' => 0,
  86. ),
  87. 'titlelength' => array(
  88. 'title' => 'grouptrade_titlelength',
  89. 'type' => 'text',
  90. 'default' => 40
  91. ),
  92. 'summarylength' => array(
  93. 'title' => 'grouptrade_summarylength',
  94. 'type' => 'text',
  95. 'default' => 80
  96. ),
  97. 'startrow' => array(
  98. 'title' => 'grouptrade_startrow',
  99. 'type' => 'text',
  100. 'default' => 0
  101. ),
  102. );
  103. }
  104. function name() {
  105. return lang('blockclass', 'blockclass_grouptrade_script_grouptrade');
  106. }
  107. function blockclass() {
  108. return array('trade', lang('blockclass', 'blockclass_group_trade'));
  109. }
  110. function fields() {
  111. return array(
  112. 'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
  113. 'url' => array('name' => lang('blockclass', 'blockclass_grouptrade_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
  114. 'title' => array('name' => lang('blockclass', 'blockclass_grouptrade_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
  115. 'pic' => array('name' => lang('blockclass', 'blockclass_grouptrade_field_pic'), 'formtype' => 'pic', 'datatype' => 'pic'),
  116. 'summary' => array('name' => lang('blockclass', 'blockclass_grouptrade_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
  117. 'totalitems' => array('name' => lang('blockclass', 'blockclass_grouptrade_field_totalitems'), 'formtype' => 'text', 'datatype' => 'int'),
  118. 'author' => array('name' => lang('blockclass', 'blockclass_grouptrade_field_author'), 'formtype' => 'text', 'datatype' => 'text'),
  119. 'authorid' => array('name' => lang('blockclass', 'blockclass_grouptrade_field_authorid'), 'formtype' => 'text', 'datatype' => 'int'),
  120. 'price' => array('name' => lang('blockclass', 'blockclass_grouptrade_field_price'), 'formtype' => 'text', 'datatype' => 'text'),
  121. );
  122. }
  123. function fieldsconvert() {
  124. return array(
  125. 'forum_trade' => array(
  126. 'name' => lang('blockclass', 'blockclass_forum_trade'),
  127. 'script' => 'trade',
  128. 'searchkeys' => array(),
  129. 'replacekeys' => array(),
  130. ),
  131. );
  132. }
  133. function getsetting() {
  134. global $_G;
  135. $settings = $this->setting;
  136. if($settings['gtids']) {
  137. loadcache('grouptype');
  138. $settings['gtids']['value'][] = array(0, lang('portalcp', 'block_all_type'));
  139. foreach($_G['cache']['grouptype']['first'] as $gid=>$group) {
  140. $settings['gtids']['value'][] = array($gid, $group['name']);
  141. if($group['secondlist']) {
  142. foreach($group['secondlist'] as $subgid) {
  143. $settings['gtids']['value'][] = array($subgid, '&nbsp;&nbsp;'.$_G['cache']['grouptype']['second'][$subgid]['name']);
  144. }
  145. }
  146. }
  147. }
  148. return $settings;
  149. }
  150. function getdata($style, $parameter) {
  151. global $_G;
  152. $parameter = $this->cookparameter($parameter);
  153. loadcache('grouptype');
  154. $typeids = array();
  155. if(!empty($parameter['gtids'])) {
  156. if($parameter['gtids'][0] == '0') {
  157. unset($parameter['gtids'][0]);
  158. }
  159. $typeids = $parameter['gtids'];
  160. }
  161. $tids = !empty($parameter['tids']) ? explode(',', $parameter['tids']) : array();
  162. $fids = !empty($parameter['fids']) ? explode(',', $parameter['fids']) : array();
  163. $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array();
  164. $startrow = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0;
  165. $items = isset($parameter['items']) ? intval($parameter['items']) : 10;
  166. $digest = isset($parameter['digest']) ? $parameter['digest'] : 0;
  167. $stick = isset($parameter['stick']) ? $parameter['stick'] : 0;
  168. $orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('dateline','todayhots','weekhots','monthhots')) ? $parameter['orderby'] : 'dateline') : 'dateline';
  169. $titlelength = !empty($parameter['titlelength']) ? intval($parameter['titlelength']) : 40;
  170. $summarylength = !empty($parameter['summarylength']) ? intval($parameter['summarylength']) : 80;
  171. $recommend = !empty($parameter['recommend']) ? 1 : 0;
  172. $keyword = !empty($parameter['keyword']) ? $parameter['keyword'] : '';
  173. $highlight = !empty($parameter['highlight']) ? 1 : 0;
  174. $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();
  175. $gviewperm = isset($parameter['gviewperm']) ? intval($parameter['gviewperm']) : -1;
  176. $gviewwhere = $gviewperm == -1 ? '' : " AND ff.gviewperm='$gviewperm'";
  177. $groups = array();
  178. if(empty($fids) && $typeids) {
  179. $query = DB::query('SELECT f.fid, f.name, ff.description FROM '.DB::table('forum_forum')." f LEFT JOIN ".DB::table('forum_forumfield')." ff ON f.fid = ff.fid WHERE f.fup IN (".dimplode($typeids).") AND threads > 0$gviewwhere");
  180. while($value = DB::fetch($query)) {
  181. $groups[$value['fid']] = $value;
  182. $fids[] = intval($value['fid']);
  183. }
  184. if(empty($fids)){
  185. return array('html' => '', 'data' => '');
  186. }
  187. }
  188. require_once libfile('function/post');
  189. require_once libfile('function/search');
  190. $datalist = $list = $listpids = $threadpids = $aid2pid = $attachtables = array();
  191. $keyword = $keyword ? searchkey($keyword, "tr.subject LIKE '%{text}%'") : '';
  192. $sql = ($fids ? ' AND t.fid IN ('.dimplode($fids).')' : '')
  193. .($tids ? ' AND t.tid IN ('.dimplode($tids).')' : '')
  194. .($digest ? ' AND t.digest IN ('.dimplode($digest).')' : '')
  195. .($stick ? ' AND t.displayorder IN ('.dimplode($stick).')' : '');
  196. if(empty($fids)) {
  197. $sql .= " AND t.isgroup='1'";
  198. if($gviewwhere) {
  199. $sql .= $gviewwhere;
  200. }
  201. }
  202. $where = '';
  203. if(in_array($orderby, array('todayhots','weekhots','monthhots'))) {
  204. $historytime = 0;
  205. switch($orderby) {
  206. case 'todayhots':
  207. $historytime = mktime(0, 0, 0, date('m', TIMESTAMP), date('d', TIMESTAMP), date('Y', TIMESTAMP));
  208. break;
  209. case 'weekhots':
  210. $week = dgmdate(TIMESTAMP, 'w', getglobal('setting/timeformat')) - 1;
  211. $week = $week != -1 ? $week : 6;
  212. $historytime = mktime(0, 0, 0, date('m', TIMESTAMP), date('d', TIMESTAMP) - $week, date('Y', TIMESTAMP));
  213. break;
  214. case 'monthhots':
  215. $historytime = mktime(0, 0, 0, date('m', TIMESTAMP), 1, date('Y', TIMESTAMP));
  216. break;
  217. }
  218. $where = ' AND tr.dateline>='.$historytime;
  219. $orderby = 'totalitems';
  220. }
  221. $where .= ($uids ? ' AND tr.sellerid IN ('.dimplode($uids).')' : '').$keyword;
  222. $where .= ($bannedids ? ' AND tr.pid NOT IN ('.dimplode($bannedids).')' : '');
  223. $where = "$sql AND t.displayorder>='0' $where";
  224. $sqlfrom = " INNER JOIN `".DB::table('forum_thread')."` t ON t.tid=tr.tid ";
  225. $joinmethod = empty($tids) ? 'INNER' : 'LEFT';
  226. if($recommend) {
  227. $sqlfrom .= " $joinmethod JOIN `".DB::table('forum_forumrecommend')."` fc ON fc.tid=tr.tid";
  228. }
  229. $sqlfield = '';
  230. if(empty($fids)) {
  231. $sqlfield = ', f.name groupname';
  232. $sqlfrom .= ' LEFT JOIN '.DB::table('forum_forum').' f ON t.fid=f.fid LEFT JOIN '.DB::table('forum_forumfield').' ff ON f.fid = ff.fid';
  233. }
  234. $sqlfield = $highlight ? ', t.highlight' : '';
  235. $query = DB::query("SELECT tr.pid, tr.tid, tr.aid, tr.price, tr.credit, tr.subject, tr.totalitems, tr.seller, tr.sellerid$sqlfield
  236. FROM ".DB::table('forum_trade')." tr $sqlfrom
  237. WHERE 1$where
  238. ORDER BY tr.$orderby DESC
  239. LIMIT $startrow,$items;"
  240. );
  241. require_once libfile('block_thread', 'class/block/forum');
  242. $bt = new block_thread();
  243. while($data = DB::fetch($query)) {
  244. if($style['getsummary']) {
  245. $threadpids[$data['posttableid']][] = $data['pid'];
  246. }
  247. if($data['aid']) {
  248. $aid2pid[$data['aid']] = $data['pid'];
  249. $attachtable = getattachtableid($data['tid']);
  250. $attachtables[$attachtable][] = $data['aid'];
  251. }
  252. $listpids[] = $data['pid'];
  253. $list[$data['pid']] = array(
  254. 'id' => $data['pid'],
  255. 'idtype' => 'pid',
  256. 'title' => cutstr(str_replace('\\\'', '&#39;', addslashes($data['subject'])), $titlelength, ''),
  257. 'url' => 'forum.php?mod=viewthread&do=tradeinfo&tid='.$data['tid'].'&pid='.$data['pid'],
  258. 'pic' => ($data['aid'] ? '' : $_G['style']['imgdir'].'/nophoto.gif'),
  259. 'picflag' => '0',
  260. 'fields' => array(
  261. 'fulltitle' => str_replace('\\\'', '&#39;', addslashes($data['subject'])),
  262. 'totalitems' => $data['totalitems'],
  263. 'author' => $data['seller'] ? $data['seller'] : $_G['setting']['anonymoustext'],
  264. 'authorid' => $data['sellerid'] ? $data['sellerid'] : 0,
  265. 'price' => ($data['price'] > 0 ? '&yen; '.$data['price'] : '').($data['credit'] > 0 ? ($data['price'] > 0 ? lang('block/grouptrade', 'grouptrade_price_add') : '').$data['credit'].' '.$_G['setting']['extcredits'][$_G['setting']['creditstransextra'][5]]['unit'].$_G['setting']['extcredits'][$_G['setting']['creditstransextra'][5]]['title'] : ''),
  266. )
  267. );
  268. if($highlight && $data['highlight']) {
  269. $list[$data['tid']]['fields']['showstyle'] = $bt->getthreadstyle($data['highlight']);
  270. }
  271. }
  272. if(!empty($listpids)) {
  273. foreach($threadpids as $key => $var) {
  274. $posttable = $key == 0 ? 'forum_post' : 'forum_post_'.$key;
  275. $query = DB::query("SELECT pid, message FROM ".DB::table($posttable)." WHERE pid IN (".dimplode($var).")");
  276. while($result = DB::fetch($query)) {
  277. $list[$result['pid']]['summary'] = messagecutstr($result['message'], $summarylength, '');
  278. }
  279. }
  280. foreach($attachtables as $tableid => $taids) {
  281. $query = DB::query('SELECT aid, attachment, remote FROM '.DB::table('forum_attachment_'.$tableid).' WHERE aid IN ('.dimplode($taids).')');
  282. while($avalue = DB::fetch($query)) {
  283. $list[$aid2pid[$avalue['aid']]]['pic'] = 'forum/'.$avalue['attachment'];
  284. $list[$aid2pid[$avalue['aid']]]['picflag'] = $avalue['remote'] ? '2' : '1';
  285. }
  286. }
  287. foreach($listpids as $key => $value) {
  288. $datalist[] = $list[$value];
  289. }
  290. }
  291. return array('html' => '', 'data' => $datalist);
  292. }
  293. }
  294. ?>