block_groupactivity.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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_groupactivity.php 25525 2011-11-14 04:39:11Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class block_groupactivity extends discuz_block {
  12. var $setting = array();
  13. function block_groupactivity(){
  14. $this->setting = array(
  15. 'tids' => array(
  16. 'title' => 'groupactivity_tids',
  17. 'type' => 'text'
  18. ),
  19. 'uids' => array(
  20. 'title' => 'groupactivity_uids',
  21. 'type' => 'text'
  22. ),
  23. 'keyword' => array(
  24. 'title' => 'groupactivity_keyword',
  25. 'type' => 'text'
  26. ),
  27. 'fids' => array(
  28. 'title' => 'groupactivity_fids',
  29. 'type' => 'text'
  30. ),
  31. 'gtids' => array(
  32. 'title' => 'groupactivity_gtids',
  33. 'type' => 'mselect',
  34. 'value' => array(
  35. ),
  36. ),
  37. 'digest' => array(
  38. 'title' => 'groupactivity_digest',
  39. 'type' => 'mcheckbox',
  40. 'value' => array(
  41. array(1, 'groupactivity_digest_1'),
  42. array(2, 'groupactivity_digest_2'),
  43. array(3, 'groupactivity_digest_3'),
  44. array(0, 'groupactivity_digest_0')
  45. ),
  46. ),
  47. 'stick' => array(
  48. 'title' => 'groupactivity_stick',
  49. 'type' => 'mcheckbox',
  50. 'value' => array(
  51. array(1, 'groupactivity_stick_1'),
  52. array(2, 'groupactivity_stick_2'),
  53. array(3, 'groupactivity_stick_3'),
  54. array(0, 'groupactivity_stick_0')
  55. ),
  56. ),
  57. 'recommend' => array(
  58. 'title' => 'groupactivity_recommend',
  59. 'type' => 'radio'
  60. ),
  61. 'place' => array(
  62. 'title' => 'groupactivity_place',
  63. 'type' => 'text'
  64. ),
  65. 'class' => array(
  66. 'title' => 'groupactivity_class',
  67. 'type' => 'select',
  68. 'value' => array()
  69. ),
  70. 'gender' => array(
  71. 'title' => 'groupactivity_gender',
  72. 'type' => 'mradio',
  73. 'value' => array(
  74. array('', 'groupactivity_gender_0'),
  75. array('1', 'groupactivity_gender_1'),
  76. array('2', 'groupactivity_gender_2'),
  77. ),
  78. 'default' => ''
  79. ),
  80. 'orderby' => array(
  81. 'title' => 'groupactivity_orderby',
  82. 'type'=> 'mradio',
  83. 'value' => array(
  84. array('dateline', 'groupactivity_orderby_dateline'),
  85. array('weekstart', 'groupactivity_orderby_weekstart'),
  86. array('monthstart', 'groupactivity_orderby_monthstart'),
  87. array('weekexp', 'groupactivity_orderby_weekexp'),
  88. array('monthexp', 'groupactivity_orderby_monthexp'),
  89. ),
  90. 'default' => 'dateline'
  91. ),
  92. 'gviewperm' => array(
  93. 'title' => 'groupactivity_gviewperm',
  94. 'type' => 'mradio',
  95. 'value' => array(
  96. array('-1', 'groupactivity_gviewperm_nolimit'),
  97. array('0', 'groupactivity_gviewperm_only_member'),
  98. array('1', 'groupactivity_gviewperm_all_member')
  99. ),
  100. 'default' => '-1'
  101. ),
  102. 'highlight' => array(
  103. 'title' => 'groupactivity_highlight',
  104. 'type' => 'radio',
  105. 'default' => 0,
  106. ),
  107. 'titlelength' => array(
  108. 'title' => 'groupactivity_titlelength',
  109. 'type' => 'text',
  110. 'default' => 40
  111. ),
  112. 'summarylength' => array(
  113. 'title' => 'groupactivity_summarylength',
  114. 'type' => 'text',
  115. 'default' => 80
  116. ),
  117. 'startrow' => array(
  118. 'title' => 'groupactivity_startrow',
  119. 'type' => 'text',
  120. 'default' => 0
  121. ),
  122. );
  123. }
  124. function name() {
  125. return lang('blockclass', 'blockclass_group_activity');
  126. }
  127. function blockclass() {
  128. return array('activity', lang('blockclass', 'blockclass_group_activity'));
  129. }
  130. function fields() {
  131. return array(
  132. 'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
  133. 'url' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
  134. 'title' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
  135. 'pic' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_pic'), 'formtype' => 'pic', 'datatype' => 'pic'),
  136. 'summary' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
  137. 'time' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_time'), 'formtype' => 'text', 'datatype' => 'text'),
  138. 'expiration' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_expiration'), 'formtype' => 'text', 'datatype' => 'text'),
  139. 'author' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_author'), 'formtype' => 'text', 'datatype' => 'text'),
  140. 'authorid' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_authorid'), 'formtype' => 'text', 'datatype' => 'int'),
  141. 'cost' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_cost'), 'formtype' => 'text', 'datatype' => 'int'),
  142. 'place' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_place'), 'formtype' => 'text', 'datatype' => 'text'),
  143. 'class' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_class'), 'formtype' => 'text', 'datatype' => 'text'),
  144. 'gender' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_gender'), 'formtype' => 'text', 'datatype' => 'text'),
  145. 'number' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_number'), 'formtype' => 'text', 'datatype' => 'int'),
  146. 'applynumber' => array('name' => lang('blockclass', 'blockclass_groupactivity_field_applynumber'), 'formtype' => 'text', 'datatype' => 'int'),
  147. );
  148. }
  149. function fieldsconvert() {
  150. return array(
  151. 'forum_activity' => array(
  152. 'name' => lang('blockclass', 'blockclass_forum_activity'),
  153. 'script' => 'activity',
  154. 'searchkeys' => array(),
  155. 'replacekeys' => array(),
  156. ),
  157. );
  158. }
  159. function getsetting() {
  160. global $_G;
  161. $settings = $this->setting;
  162. if($settings['gtids']) {
  163. loadcache('grouptype');
  164. $settings['gtids']['value'][] = array(0, lang('portalcp', 'block_all_type'));
  165. foreach($_G['cache']['grouptype']['first'] as $gid=>$group) {
  166. $settings['gtids']['value'][] = array($gid, $group['name']);
  167. if($group['secondlist']) {
  168. foreach($group['secondlist'] as $subgid) {
  169. $settings['gtids']['value'][] = array($subgid, '&nbsp;&nbsp;'.$_G['cache']['grouptype']['second'][$subgid]['name']);
  170. }
  171. }
  172. }
  173. }
  174. $activitytype = explode("\n", $_G['setting']['activitytype']);
  175. $settings['class']['value'][] = array('', 'groupactivity_class_all');
  176. foreach($activitytype as $item) {
  177. $settings['class']['value'][] = array($item, $item);
  178. }
  179. return $settings;
  180. }
  181. function getdata($style, $parameter) {
  182. global $_G;
  183. $parameter = $this->cookparameter($parameter);
  184. loadcache('grouptype');
  185. $typeids = array();
  186. if(!empty($parameter['gtids'])) {
  187. if($parameter['gtids'][0] == '0') {
  188. unset($parameter['gtids'][0]);
  189. }
  190. $typeids = $parameter['gtids'];
  191. }
  192. $tids = !empty($parameter['tids']) ? explode(',', $parameter['tids']) : array();
  193. $fids = !empty($parameter['fids']) ? explode(',', $parameter['fids']) : array();
  194. $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array();
  195. $startrow = !empty($parameter['startrow']) ? intval($parameter['startrow']) : 0;
  196. $items = !empty($parameter['items']) ? intval($parameter['items']) : 10;
  197. $digest = isset($parameter['digest']) ? $parameter['digest'] : 0;
  198. $stick = isset($parameter['stick']) ? $parameter['stick'] : 0;
  199. $orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('dateline','weekstart','monthstart','weekexp','monthexp')) ? $parameter['orderby'] : 'dateline') : 'dateline';
  200. $titlelength = !empty($parameter['titlelength']) ? intval($parameter['titlelength']) : 40;
  201. $summarylength = !empty($parameter['summarylength']) ? intval($parameter['summarylength']) : 80;
  202. $recommend = !empty($parameter['recommend']) ? 1 : 0;
  203. $keyword = !empty($parameter['keyword']) ? $parameter['keyword'] : '';
  204. $place = !empty($parameter['place']) ? $parameter['place'] : '';
  205. $class = !empty($parameter['class']) ? $parameter['class'] : '';
  206. $gender = !empty($parameter['gender']) ? intval($parameter['gender']) : '';
  207. $gviewperm = isset($parameter['gviewperm']) ? intval($parameter['gviewperm']) : -1;
  208. $highlight = !empty($parameter['highlight']) ? 1 : 0;
  209. $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();
  210. $gviewwhere = $gviewperm == -1 ? '' : " AND ff.gviewperm='$gviewperm'";
  211. $groups = array();
  212. if(empty($fids) && $typeids) {
  213. $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");
  214. while($value = DB::fetch($query)) {
  215. $groups[$value['fid']] = $value;
  216. $fids[] = intval($value['fid']);
  217. }
  218. if(empty($fids)){
  219. return array('html' => '', 'data' => '');
  220. }
  221. }
  222. require_once libfile('function/post');
  223. require_once libfile('function/search');
  224. $datalist = $list = array();
  225. $keyword = $keyword ? searchkey($keyword, "t.subject LIKE '%{text}%'") : '';
  226. $sql = ($fids ? ' AND t.fid IN ('.dimplode($fids).')' : '')
  227. .($tids ? ' AND t.tid IN ('.dimplode($tids).')' : '')
  228. .($bannedids ? ' AND t.tid NOT IN ('.dimplode($bannedids).')' : '')
  229. .($digest ? ' AND t.digest IN ('.dimplode($digest).')' : '')
  230. .($stick ? ' AND t.displayorder IN ('.dimplode($stick).')' : '')
  231. .$keyword;
  232. if(empty($fids)) {
  233. $sql .= " AND t.isgroup='1'";
  234. if($gviewwhere) {
  235. $sql .= $gviewwhere;
  236. }
  237. }
  238. $where = '';
  239. if(in_array($orderby, array('weekstart','monthstart'))) {
  240. $historytime = 0;
  241. switch($orderby) {
  242. case 'weekstart':
  243. $historytime = TIMESTAMP + 86400 * 7;
  244. break;
  245. case 'monthstart':
  246. $historytime = TIMESTAMP + 86400 * 30;
  247. break;
  248. }
  249. $where = ' AND a.starttimefrom >= '.TIMESTAMP.' AND a.starttimefrom<='.$historytime;
  250. $orderby = 'a.starttimefrom ASC';
  251. } elseif(in_array($orderby, array('weekexp','monthexp'))) {
  252. $historytime = 0;
  253. switch($orderby) {
  254. case 'weekexp':
  255. $historytime = TIMESTAMP + 86400 * 7;
  256. break;
  257. case 'monthexp':
  258. $historytime = TIMESTAMP + 86400 * 30;
  259. break;
  260. }
  261. $where = ' AND a.expiration >= '.TIMESTAMP.' AND a.expiration<='.$historytime;
  262. $orderby = 'a.expiration ASC';
  263. } else {
  264. $orderby = 't.dateline DESC';
  265. }
  266. $where .= $uids ? ' AND t.authorid IN ('.dimplode($uids).')' : '';
  267. if($gender) {
  268. $where .= " AND a.gender='$gender'";
  269. }
  270. $where = $sql." AND t.displayorder>='0' ".$where;
  271. $sqlfrom = " INNER JOIN `".DB::table('forum_thread')."` t ON t.tid=a.tid ";
  272. $joinmethod = empty($tids) ? 'INNER' : 'LEFT';
  273. if($recommend) {
  274. $sqlfrom .= " $joinmethod JOIN `".DB::table('forum_forumrecommend')."` fc ON fc.tid=tr.tid";
  275. }
  276. $sqlfield = '';
  277. if(empty($fids)) {
  278. $sqlfield = ', f.name groupname';
  279. $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';
  280. }
  281. $sqlfield = $highlight ? ', t.highlight' : '';
  282. $query = DB::query("SELECT a.*, t.tid, t.subject, t.authorid, t.author$sqlfield
  283. FROM ".DB::table('forum_activity')." a $sqlfrom
  284. WHERE 1$where
  285. ORDER BY $orderby
  286. LIMIT $startrow,$items;"
  287. );
  288. require_once libfile('block_thread', 'class/block/forum');
  289. $bt = new block_thread();
  290. $listtids = $threadtids = $threads = $aid2tid = $attachtables = array();
  291. while($data = DB::fetch($query)) {
  292. $data['time'] = dgmdate($data['starttimefrom']);
  293. if($data['starttimeto']) {
  294. $data['time'] .= ' - '.dgmdate($data['starttimeto']);
  295. }
  296. if($style['getsummary']) {
  297. $threadtids[$data['posttableid']][] = $data['tid'];
  298. }
  299. if($data['aid']) {
  300. $aid2tid[$data['aid']] = $data['tid'];
  301. $attachtable = getattachtableid($data['tid']);
  302. $attachtables[$attachtable][] = $data['aid'];
  303. }
  304. $listtids[] = $data['tid'];
  305. $list[$data['tid']] = array(
  306. 'id' => $data['tid'],
  307. 'idtype' => 'tid',
  308. 'title' => cutstr(str_replace('\\\'', '&#39;', addslashes($data['subject'])), $titlelength, ''),
  309. 'url' => 'forum.php?mod=viewthread&tid='.$data['tid'],
  310. 'pic' => ($data['aid'] ? '' : $_G['style']['imgdir'].'/nophoto.gif'),
  311. 'picflag' => '0',
  312. 'fields' => array(
  313. 'fulltitle' => str_replace('\\\'', '&#39;', addslashes($data['subject'])),
  314. 'time' => $data['time'],
  315. 'expiration' => $data['expiration'] ? dgmdate($data['expiration']) : 'N/A',
  316. 'author' => $data['author'] ? $data['author'] : $_G['setting']['anonymoustext'],
  317. 'authorid' => $data['authorid'] ? $data['authorid'] : 0,
  318. 'cost' => $data['cost'],
  319. 'place' => $data['place'],
  320. 'class' => $data['class'],
  321. 'gender' => $data['gender'],
  322. 'number' => $data['number'],
  323. 'applynumber' => $data['applynumber'],
  324. )
  325. );
  326. if($highlight && $data['highlight']) {
  327. $list[$data['tid']]['fields']['showstyle'] = $bt->getthreadstyle($data['highlight']);
  328. }
  329. }
  330. if(!empty($listtids)) {
  331. $query = DB::query("SELECT tid,COUNT(*) as sum FROM ".DB::table('forum_activityapply')." WHERE tid IN(".dimplode($listtids).") GROUP BY tid");
  332. while($value = DB::fetch($query)) {
  333. $list[$value['tid']]['fields']['applynumber'] = $value['sum'];
  334. }
  335. $threads = $bt->getthread($threadtids, $summarylength, true);
  336. if($threads) {
  337. foreach($threads as $tid => $var) {
  338. $list[$tid]['summary'] = $var;
  339. }
  340. }
  341. foreach($attachtables as $tableid => $taids) {
  342. $query = DB::query('SELECT aid, attachment, remote FROM '.DB::table('forum_attachment_'.$tableid).' WHERE aid IN ('.dimplode($taids).')');
  343. while($avalue = DB::fetch($query)) {
  344. $list[$aid2tid[$avalue['aid']]]['pic'] = 'forum/'.$avalue['attachment'];
  345. $list[$aid2tid[$avalue['aid']]]['picflag'] = $avalue['remote'] ? '2' : '1';
  346. }
  347. }
  348. foreach($listtids as $key => $value) {
  349. $datalist[] = $list[$value];
  350. }
  351. }
  352. return array('html' => '', 'data' => $datalist);
  353. }
  354. }
  355. ?>