block_activity.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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_activity.php 25525 2011-11-14 04:39:11Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class block_activity extends discuz_block {
  12. var $setting = array();
  13. function block_activity(){
  14. $this->setting = array(
  15. 'tids' => array(
  16. 'title' => 'activitylist_tids',
  17. 'type' => 'text'
  18. ),
  19. 'uids' => array(
  20. 'title' => 'activitylist_uids',
  21. 'type' => 'text'
  22. ),
  23. 'keyword' => array(
  24. 'title' => 'activitylist_keyword',
  25. 'type' => 'text'
  26. ),
  27. 'fids' => array(
  28. 'title' => 'activitylist_fids',
  29. 'type' => 'mselect',
  30. 'value' => array()
  31. ),
  32. 'viewmod' => array(
  33. 'title' => 'threadlist_viewmod',
  34. 'type' => 'radio'
  35. ),
  36. 'digest' => array(
  37. 'title' => 'activitylist_digest',
  38. 'type' => 'mcheckbox',
  39. 'value' => array(
  40. array(1, 'activitylist_digest_1'),
  41. array(2, 'activitylist_digest_2'),
  42. array(3, 'activitylist_digest_3'),
  43. array(0, 'activitylist_digest_0')
  44. ),
  45. ),
  46. 'stick' => array(
  47. 'title' => 'activitylist_stick',
  48. 'type' => 'mcheckbox',
  49. 'value' => array(
  50. array(1, 'activitylist_stick_1'),
  51. array(2, 'activitylist_stick_2'),
  52. array(3, 'activitylist_stick_3'),
  53. array(0, 'activitylist_stick_0')
  54. ),
  55. ),
  56. 'recommend' => array(
  57. 'title' => 'activitylist_recommend',
  58. 'type' => 'radio'
  59. ),
  60. 'place' => array(
  61. 'title' => 'activitylist_place',
  62. 'type' => 'text'
  63. ),
  64. 'class' => array(
  65. 'title' => 'activitylist_class',
  66. 'type' => 'select',
  67. 'value' => array()
  68. ),
  69. 'gender' => array(
  70. 'title' => 'activitylist_gender',
  71. 'type' => 'mradio',
  72. 'value' => array(
  73. array('', 'activitylist_gender_0'),
  74. array('1', 'activitylist_gender_1'),
  75. array('2', 'activitylist_gender_2'),
  76. ),
  77. 'default' => ''
  78. ),
  79. 'orderby' => array(
  80. 'title' => 'activitylist_orderby',
  81. 'type'=> 'mradio',
  82. 'value' => array(
  83. array('dateline', 'activitylist_orderby_dateline'),
  84. array('weekstart', 'activitylist_orderby_weekstart'),
  85. array('monthstart', 'activitylist_orderby_monthstart'),
  86. array('weekexp', 'activitylist_orderby_weekexp'),
  87. array('monthexp', 'activitylist_orderby_monthexp'),
  88. array('weekhot', 'activitylist_orderby_weekhot'),
  89. array('monthhot', 'activitylist_orderby_monthhot'),
  90. array('alltimehot', 'activitylist_orderby_alltimehot'),
  91. ),
  92. 'default' => 'dateline'
  93. ),
  94. 'highlight' => array(
  95. 'title' => 'activitylist_highlight',
  96. 'type' => 'radio',
  97. 'default' => 0,
  98. ),
  99. 'titlelength' => array(
  100. 'title' => 'activitylist_titlelength',
  101. 'type' => 'text',
  102. 'default' => 40
  103. ),
  104. 'summarylength' => array(
  105. 'title' => 'activitylist_summarylength',
  106. 'type' => 'text',
  107. 'default' => 80
  108. ),
  109. 'startrow' => array(
  110. 'title' => 'activitylist_startrow',
  111. 'type' => 'text',
  112. 'default' => 0
  113. ),
  114. );
  115. }
  116. function name() {
  117. return lang('blockclass', 'blockclass_activity_script_activity');
  118. }
  119. function blockclass() {
  120. return array('activity', lang('blockclass', 'blockclass_activity_activity'));
  121. }
  122. function fields() {
  123. return array(
  124. 'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
  125. 'url' => array('name' => lang('blockclass', 'blockclass_activity_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
  126. 'title' => array('name' => lang('blockclass', 'blockclass_activity_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
  127. 'pic' => array('name' => lang('blockclass', 'blockclass_activity_field_pic'), 'formtype' => 'pic', 'datatype' => 'pic'),
  128. 'summary' => array('name' => lang('blockclass', 'blockclass_activity_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
  129. 'time' => array('name' => lang('blockclass', 'blockclass_activity_field_time'), 'formtype' => 'text', 'datatype' => 'text'),
  130. 'expiration' => array('name' => lang('blockclass', 'blockclass_activity_field_expiration'), 'formtype' => 'text', 'datatype' => 'text'),
  131. 'author' => array('name' => lang('blockclass', 'blockclass_activity_field_author'), 'formtype' => 'text', 'datatype' => 'text'),
  132. 'authorid' => array('name' => lang('blockclass', 'blockclass_activity_field_authorid'), 'formtype' => 'text', 'datatype' => 'int'),
  133. 'cost' => array('name' => lang('blockclass', 'blockclass_activity_field_cost'), 'formtype' => 'text', 'datatype' => 'int'),
  134. 'place' => array('name' => lang('blockclass', 'blockclass_activity_field_place'), 'formtype' => 'text', 'datatype' => 'text'),
  135. 'class' => array('name' => lang('blockclass', 'blockclass_activity_field_class'), 'formtype' => 'text', 'datatype' => 'text'),
  136. 'gender' => array('name' => lang('blockclass', 'blockclass_activity_field_gender'), 'formtype' => 'text', 'datatype' => 'text'),
  137. 'number' => array('name' => lang('blockclass', 'blockclass_activity_field_number'), 'formtype' => 'text', 'datatype' => 'int'),
  138. 'applynumber' => array('name' => lang('blockclass', 'blockclass_activity_field_applynumber'), 'formtype' => 'text', 'datatype' => 'int'),
  139. );
  140. }
  141. function fieldsconvert() {
  142. return array(
  143. 'group_activity' => array(
  144. 'name' => lang('blockclass', 'blockclass_group_activity'),
  145. 'script' => 'groupactivity',
  146. 'searchkeys' => array(),
  147. 'replacekeys' => array(),
  148. ),
  149. );
  150. }
  151. function getsetting() {
  152. global $_G;
  153. $settings = $this->setting;
  154. if($settings['fids']) {
  155. loadcache('forums');
  156. $settings['fids']['value'][] = array(0, lang('portalcp', 'block_all_forum'));
  157. foreach($_G['cache']['forums'] as $fid => $forum) {
  158. $settings['fids']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name']);
  159. }
  160. }
  161. $activitytype = explode("\n", $_G['setting']['activitytype']);
  162. $settings['class']['value'][] = array('', 'activitylist_class_all');
  163. foreach($activitytype as $item) {
  164. $item = trim($item);
  165. $settings['class']['value'][] = array($item, $item);
  166. }
  167. return $settings;
  168. }
  169. function getdata($style, $parameter) {
  170. global $_G;
  171. $parameter = $this->cookparameter($parameter);
  172. loadcache('forums');
  173. $tids = !empty($parameter['tids']) ? explode(',', $parameter['tids']) : array();
  174. $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array();
  175. $startrow = !empty($parameter['startrow']) ? intval($parameter['startrow']) : 0;
  176. $items = !empty($parameter['items']) ? intval($parameter['items']) : 10;
  177. $digest = isset($parameter['digest']) ? $parameter['digest'] : 0;
  178. $stick = isset($parameter['stick']) ? $parameter['stick'] : 0;
  179. $orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('dateline','weekstart','monthstart','weekexp','monthexp','weekhot','monthhot','alltimehot')) ? $parameter['orderby'] : 'dateline') : 'dateline';
  180. $titlelength = !empty($parameter['titlelength']) ? intval($parameter['titlelength']) : 40;
  181. $summarylength = !empty($parameter['summarylength']) ? intval($parameter['summarylength']) : 80;
  182. $recommend = !empty($parameter['recommend']) ? 1 : 0;
  183. $keyword = !empty($parameter['keyword']) ? $parameter['keyword'] : '';
  184. $place = !empty($parameter['place']) ? $parameter['place'] : '';
  185. $class = !empty($parameter['class']) ? trim($parameter['class']) : '';
  186. $gender = !empty($parameter['gender']) ? intval($parameter['gender']) : '';
  187. $viewmod = !empty($parameter['viewmod']) ? 1 : 0;
  188. $highlight = !empty($parameter['highlight']) ? 1 : 0;
  189. $fids = array();
  190. if(!empty($parameter['fids'])) {
  191. if($parameter['fids'][0] == '0') {
  192. unset($parameter['fids'][0]);
  193. }
  194. $fids = $parameter['fids'];
  195. }
  196. $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();
  197. require_once libfile('function/post');
  198. require_once libfile('function/search');
  199. $datalist = $list = array();
  200. $keyword = $keyword ? searchkey($keyword, "t.subject LIKE '%{text}%'") : '';
  201. $sql = ($fids ? ' AND t.fid IN ('.dimplode($fids).')' : '')
  202. .$keyword
  203. .($tids ? ' AND t.tid IN ('.dimplode($tids).')' : '')
  204. .($bannedids ? ' AND t.tid NOT IN ('.dimplode($bannedids).')' : '')
  205. .($digest ? ' AND t.digest IN ('.dimplode($digest).')' : '')
  206. .($stick ? ' AND t.displayorder IN ('.dimplode($stick).')' : '')
  207. ." AND t.isgroup='0'";
  208. $where = '';
  209. if(in_array($orderby, array('weekstart','monthstart'))) {
  210. $historytime = 0;
  211. switch($orderby) {
  212. case 'weekstart':
  213. $historytime = TIMESTAMP + 86400 * 7;
  214. break;
  215. case 'monthstart':
  216. $historytime = TIMESTAMP + 86400 * 30;
  217. break;
  218. }
  219. $where = ' WHERE a.starttimefrom>='.TIMESTAMP.' AND a.starttimefrom<='.$historytime;
  220. $orderby = 'a.starttimefrom ASC';
  221. } elseif(in_array($orderby, array('weekexp','monthexp'))) {
  222. $historytime = 0;
  223. switch($orderby) {
  224. case 'weekexp':
  225. $historytime = TIMESTAMP + 86400 * 7;
  226. break;
  227. case 'monthexp':
  228. $historytime = TIMESTAMP + 86400 * 30;
  229. break;
  230. }
  231. $where = ' WHERE a.expiration>='.TIMESTAMP.' AND a.expiration<='.$historytime;
  232. $orderby = 'a.expiration ASC';
  233. } elseif(in_array($orderby, array('weekhot','monthhot'))) {
  234. $historytime = 0;
  235. switch($orderby) {
  236. case 'weekhot':
  237. $historytime = TIMESTAMP + 86400 * 7;
  238. break;
  239. case 'monthhot':
  240. $historytime = TIMESTAMP + 86400 * 30;
  241. break;
  242. }
  243. $where = ' WHERE a.expiration>='.TIMESTAMP.' AND a.expiration<='.$historytime;
  244. $orderby = 'a.applynumber DESC';
  245. } elseif($orderby == 'alltimehot') {
  246. $where = ' WHERE (a.expiration>='.TIMESTAMP." OR a.expiration='0')";
  247. $orderby = 'a.applynumber DESC';
  248. } else {
  249. $orderby = 't.dateline DESC';
  250. }
  251. $where .= $uids ? ' AND t.authorid IN ('.dimplode($uids).')' : '';
  252. if($gender) {
  253. $where .= " AND a.gender='$gender'";
  254. }
  255. if($class) {
  256. $where .= " AND a.class='$class'";
  257. }
  258. $sqlfrom = " INNER JOIN `".DB::table('forum_thread')."` t ON t.tid=a.tid $sql AND t.displayorder>='0'";
  259. $joinmethod = empty($tids) ? 'INNER' : 'LEFT';
  260. if($recommend) {
  261. $sqlfrom .= " $joinmethod JOIN `".DB::table('forum_forumrecommend')."` fc ON fc.tid=tr.tid";
  262. }
  263. $sqlfield = $highlight ? ', t.highlight' : '';
  264. $query = DB::query("SELECT a.*, t.tid, t.subject, t.authorid, t.author$sqlfield
  265. FROM ".DB::table('forum_activity')." a $sqlfrom $where
  266. ORDER BY $orderby
  267. LIMIT $startrow,$items;"
  268. );
  269. require_once libfile('block_thread', 'class/block/forum');
  270. $bt = new block_thread();
  271. $listtids = $threadtids = $threads = $aid2tid = $attachtables = array();
  272. while($data = DB::fetch($query)) {
  273. $data['time'] = dgmdate($data['starttimefrom']);
  274. if($data['starttimeto']) {
  275. $data['time'] .= ' - '.dgmdate($data['starttimeto']);
  276. }
  277. if($style['getsummary']) {
  278. $threadtids[$data['posttableid']][] = $data['tid'];
  279. }
  280. if($data['aid']) {
  281. $aid2tid[$data['aid']] = $data['tid'];
  282. $attachtable = getattachtableid($data['tid']);
  283. $attachtables[$attachtable][] = $data['aid'];
  284. }
  285. $listtids[] = $data['tid'];
  286. $list[$data['tid']] = array(
  287. 'id' => $data['tid'],
  288. 'idtype' => 'tid',
  289. 'title' => cutstr(str_replace('\\\'', '&#39;', $data['subject']), $titlelength, ''),
  290. 'url' => 'forum.php?mod=viewthread&tid='.$data['tid'].($viewmod ? '&from=portal' : ''),
  291. 'pic' => ($data['aid'] ? '' : $_G['style']['imgdir'].'/nophoto.gif'),
  292. 'picflag' => '0',
  293. 'fields' => array(
  294. 'fulltitle' => str_replace('\\\'', '&#39;', addslashes($data['subject'])),
  295. 'time' => $data['time'],
  296. 'expiration' => $data['expiration'] ? dgmdate($data['expiration']) : 'N/A',
  297. 'author' => $data['author'] ? $data['author'] : $_G['setting']['anonymoustext'],
  298. 'authorid' => $data['authorid'] ? $data['authorid'] : 0,
  299. 'cost' => $data['cost'],
  300. 'place' => $data['place'],
  301. 'class' => $data['class'],
  302. 'gender' => $data['gender'],
  303. 'number' => $data['number'],
  304. 'applynumber' => $data['applynumber'],
  305. )
  306. );
  307. if($highlight && $data['highlight']) {
  308. $list[$data['tid']]['fields']['showstyle'] = $bt->getthreadstyle($data['highlight']);
  309. }
  310. }
  311. if(!empty($listtids)) {
  312. $query = DB::query("SELECT tid,COUNT(*) as sum FROM ".DB::table('forum_activityapply')." WHERE tid IN(".dimplode($listtids).") GROUP BY tid");
  313. while($value = DB::fetch($query)) {
  314. $list[$value['tid']]['fields']['applynumber'] = $value['sum'];
  315. }
  316. $threads = $bt->getthread($threadtids, $summarylength, true);
  317. if($threads) {
  318. foreach($threads as $tid => $var) {
  319. $list[$tid]['summary'] = $var;
  320. }
  321. }
  322. foreach($attachtables as $tableid => $taids) {
  323. $query = DB::query('SELECT aid, attachment, remote FROM '.DB::table('forum_attachment_'.$tableid).' WHERE aid IN ('.dimplode($taids).')');
  324. while($avalue = DB::fetch($query)) {
  325. $list[$aid2tid[$avalue['aid']]]['pic'] = 'forum/'.$avalue['attachment'];
  326. $list[$aid2tid[$avalue['aid']]]['picflag'] = $avalue['remote'] ? '2' : '1';
  327. }
  328. }
  329. foreach($listtids as $key => $value) {
  330. $datalist[] = $list[$value];
  331. }
  332. }
  333. return array('html' => '', 'data' => $datalist);
  334. }
  335. }
  336. ?>