wechat.class.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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: wechat.class.php 36284 2016-12-12 00:47:50Z nemohou $
  7. */
  8. if (!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class plugin_wechat {
  12. function plugin_wechat() {
  13. include_once template('wechat:module');
  14. }
  15. function common() {
  16. global $_G;
  17. if(!$_G['wechat']['setting']) {
  18. $_G['wechat']['setting'] = unserialize($_G['setting']['mobilewechat']);
  19. }
  20. if($_G['uid']) {
  21. if($_G['wechat']['setting']['wechat_qrtype']) {
  22. $_G['wechatuser'] = C::t('#wechat#common_member_wechatmp')->fetch($_G['uid']);
  23. if($_G['wechatuser'] && !$_G['wechatuser']['status']) {
  24. $_G['wechatuser']['isregister'] = 1;
  25. }
  26. } else {
  27. $_G['wechatuser'] = C::t('#wechat#common_member_wechat')->fetch($_G['uid']);
  28. }
  29. if($_G['wechatuser'] && $wechatuser['status'] == 1) {
  30. C::t('#wechat#common_member_wechat')->update($_G['uid'], array('status' => 0));
  31. require_once libfile('function/member');
  32. clearcookies();
  33. }
  34. }
  35. if(!$_G['uid'] && !defined('IN_MOBILE') && $_G['wechat']['setting']['wsq_allow']) {
  36. $_G['setting']['pluginhooks']['global_login_text'] .= wechat_tpl_login_bar();
  37. }
  38. $_G['Plang'] = $_G['setting']['wechatviewpluginid'] ? lang('plugin/'.$_G['setting']['wechatviewpluginid']) : array();
  39. if(!$_G['Plang'] || !$_G['wechatuser']) {
  40. unset($_G['setting']['plugins']['spacecp']['wechat:spacecp']);
  41. }
  42. }
  43. function deletemember($param) {
  44. $uids = $param['param'][0];
  45. $step = $param['step'];
  46. if ($step == 'check' && $uids && is_array($uids)) {
  47. foreach($uids as $uid) {
  48. C::t('#wechat#common_member_wechat')->delete($uid);
  49. }
  50. }
  51. }
  52. function global_login_extra() {
  53. global $_G;
  54. if(!$_G['Plang'] || $_G['inshowmessage'] || !$_G['wechat']['setting']['wsq_allow']) {
  55. return;
  56. }
  57. return wechat_tpl_login_extra_bar();
  58. }
  59. function global_usernav_extra1() {
  60. global $_G;
  61. if(!$_G['Plang'] || $_G['wechatuser'] || !$_G['wechat']['setting']['wsq_allow'] || !$_G['uid']) {
  62. return;
  63. }
  64. return wechat_tpl_user_bar();
  65. }
  66. function global_footer() {
  67. global $_G;
  68. if($_G['wechat']['setting']['wechat_float_qrcode'] && $_G['wechat']['setting']['wsq_siteid'] && $_G['wechat']['setting']['wsq_allow']) {
  69. $modid = $_G['basescript'].'::'.CURMODULE;
  70. if($modid == 'forum::forumdisplay' && !empty($_GET['fid'])) {
  71. $idstr = '&fid='.dintval($_GET['fid']);
  72. return wechat_tpl_float_qrcode($idstr);
  73. } elseif($modid == 'forum::viewthread' && !empty($_GET['tid'])) {
  74. $idstr = '&tid='.dintval($_GET['tid']).'&qrsize=2';
  75. return wechat_tpl_float_qrcode($idstr);
  76. } elseif($modid == 'forum::index') {
  77. return wechat_tpl_float_qrcode();
  78. }
  79. }
  80. }
  81. }
  82. class mobileplugin_wechat {
  83. function common() {
  84. global $_G;
  85. if(!$_G['wechat']['setting']) {
  86. $_G['wechat']['setting'] = unserialize($_G['setting']['mobilewechat']);
  87. }
  88. dsetcookie('mobile', '', -1);
  89. if(!isset($_GET['pluginid'])) {
  90. $redirect = WeChat::redirect(1);
  91. if($redirect) {
  92. dheader('location: '.$redirect);
  93. }
  94. }
  95. }
  96. }
  97. class plugin_wechat_member extends plugin_wechat {
  98. function logging_method() {
  99. global $_G;
  100. if(!$_G['Plang'] || !$_G['wechat']['setting']['wsq_allow']) {
  101. return;
  102. }
  103. return wechat_tpl_login_bar();
  104. }
  105. function register_top_output() {
  106. global $_G;
  107. if(strexists($_GET['referer'], 'wechat:login') && $_G['wechat']['setting']['wsq_allow']) {
  108. return wechat_tpl_register();
  109. }
  110. }
  111. function register_logging_method() {
  112. global $_G;
  113. if(!$_G['Plang'] || !$_G['wechat']['setting']['wsq_allow']) {
  114. return;
  115. }
  116. return wechat_tpl_login_bar();
  117. }
  118. }
  119. class mobileplugin_wechat_forum extends mobileplugin_wechat {
  120. function post_showactivity() {
  121. if(!showActivity::init()) {
  122. return false;
  123. }
  124. showActivity::post();
  125. }
  126. function viewthread_showactivity() {
  127. showActivity::init();
  128. }
  129. function misc_showactivity() {
  130. showActivity::init();
  131. }
  132. }
  133. class plugin_wechat_forum extends plugin_wechat {
  134. function viewthread_showactivity() {
  135. showActivity::init();
  136. }
  137. function viewthread_postheader_output() {
  138. if(!showActivity::init()) {
  139. return array();
  140. }
  141. if($GLOBALS['activity']['starttimeto']) {
  142. global $_G;
  143. $starttimeto = strtotime($GLOBALS['activity']['starttimeto']);
  144. if($starttimeto < TIMESTAMP && $_G['forum_thread']['displayorder'] > 0) {
  145. C::t('forum_thread')->update($_G['tid'], array('displayorder' => 0));
  146. }
  147. }
  148. return showActivity::returnvoters(1);
  149. }
  150. function viewthread_posttop_output() {
  151. if(!showActivity::init()) {
  152. return array();
  153. }
  154. return showActivity::returnvoters(2);
  155. }
  156. function misc_showactivity() {
  157. if(!showActivity::init()) {
  158. return false;
  159. }
  160. showActivity::misc();
  161. }
  162. function post_showactivity() {
  163. if(!showActivity::init()) {
  164. return false;
  165. }
  166. showActivity::post();
  167. }
  168. function viewthread_share_method_output() {
  169. global $_G;
  170. if($_G['wechat']['setting']['wsq_allow']) {
  171. return wechat_tpl_share(showActivity::init());
  172. }
  173. }
  174. function viewthread_postaction() {
  175. global $_G;
  176. if($_G['wechat']['setting']['wsq_allow'] && $_G['adminid'] == 1 && empty($_GET['viewpid'])) {
  177. return array(wechat_tpl_resourcepush());
  178. }
  179. }
  180. }
  181. class WeChat {
  182. static $QRCODE_EXPIRE = 1800;
  183. static public function getqrcode() {
  184. global $_G;
  185. if(!$_G['wechat']['setting']) {
  186. $_G['wechat']['setting'] = unserialize($_G['setting']['mobilewechat']);
  187. }
  188. require_once DISCUZ_ROOT . './source/plugin/wechat/wechat.lib.class.php';
  189. $wechat_client = new WeChatClient($_G['wechat']['setting']['wechat_appId'], $_G['wechat']['setting']['wechat_appsecret']);
  190. $ticket = '';
  191. if(!$_G['cookie']['wechat_ticket'] || $_G['wechat']['setting']['wechat_mtype'] == 1) {
  192. $code = 0;
  193. $i = 0;
  194. do {
  195. $code = rand(100000, 999999);
  196. $codeexists = C::t('#wechat#mobile_wechat_authcode')->fetch_by_code($code);
  197. $i++;
  198. } while($codeexists && $i < 10);
  199. if($_G['wechat']['setting']['wechat_mtype'] == 2) {
  200. $option = array(
  201. 'scene_id' => $code,
  202. 'expire' => self::$QRCODE_EXPIRE,
  203. 'ticketOnly' => '1'
  204. );
  205. $ticket = $wechat_client->getQrcodeTicket($option);
  206. if(!$ticket) {
  207. showmessage('wechat:wechat_message_codefull');
  208. }
  209. dsetcookie('wechat_ticket', authcode($ticket."\t".$code, 'ENCODE'), self::$QRCODE_EXPIRE);
  210. }
  211. } else {
  212. list($ticket, $code) = explode("\t", authcode($_G['cookie']['wechat_ticket'], 'DECODE'));
  213. }
  214. $isqrapi = $ticket ? $ticket : '';
  215. if($codeexists) {
  216. showmessage('wechat:wechat_message_codefull');
  217. }
  218. $qrcodeurl = !$isqrapi ? $_G['setting']['attachurl'].'common/'.$_G['wechat']['setting']['wechat_qrcode'] : $_G['siteurl'].'plugin.php?id=wechat:qrcode&rand='.random(5);
  219. $codeenc = urlencode(base64_encode(authcode($code, 'ENCODE', $_G['config']['security']['authkey'])));
  220. C::t('#wechat#mobile_wechat_authcode')->insert(array('sid' => $_G['cookie']['saltkey'], 'uid' => $_G['uid'], 'code' => $code, 'createtime' => TIMESTAMP), 0, 1);
  221. if(!discuz_process::islocked('clear_wechat_authcode')) {
  222. C::t('#wechat#mobile_wechat_authcode')->delete_history();
  223. discuz_process::unlock('clear_wechat_authcode');
  224. }
  225. return array($isqrapi, $qrcodeurl, $codeenc, $code);
  226. }
  227. static public function redirect($type = '') {
  228. global $_G;
  229. $hook = unserialize($_G['setting']['wechatredirect']);
  230. if (!$hook || !in_array($hook['plugin'], $_G['setting']['plugins']['available'])) {
  231. return;
  232. }
  233. if(!preg_match("/^[\w\_]+$/i", $hook['plugin']) || !preg_match('/^[\w\_\.]+\.php$/i', $hook['include'])) {
  234. return;
  235. }
  236. include_once DISCUZ_ROOT . 'source/plugin/' . $hook['plugin'] . '/' . $hook['include'];
  237. if (!class_exists($hook['class'], false)) {
  238. return;
  239. }
  240. $class = new $hook['class'];
  241. if (!method_exists($class, $hook['method'])) {
  242. return;
  243. }
  244. $return = call_user_func(array($class, $hook['method']), $type);
  245. if($return) {
  246. return $return;
  247. }
  248. }
  249. static public function register($username, $return = 0, $groupid = 0) {
  250. global $_G;
  251. if(!$username) {
  252. return;
  253. }
  254. if(!$_G['wechat']['setting']) {
  255. $_G['wechat']['setting'] = unserialize($_G['setting']['mobilewechat']);
  256. }
  257. loaducenter();
  258. $groupid = !$groupid ? ($_G['wechat']['setting']['wechat_newusergroupid'] ? $_G['wechat']['setting']['wechat_newusergroupid'] : $_G['setting']['newusergroupid']) : $groupid;
  259. $password = md5(random(10));
  260. $email = 'wechat_'.strtolower(random(10)).'@null.null';
  261. $usernamelen = dstrlen($username);
  262. if($usernamelen < 3) {
  263. $username = $username.'_'.random(5);
  264. }
  265. if($usernamelen > 15) {
  266. if(!$return) {
  267. showmessage('profile_username_toolong');
  268. } else {
  269. return;
  270. }
  271. }
  272. $censorexp = '/^('.str_replace(array('\\*', "\r\n", ' '), array('.*', '|', ''), preg_quote(($_G['setting']['censoruser'] = trim($_G['setting']['censoruser'])), '/')).')$/i';
  273. if($_G['setting']['censoruser'] && @preg_match($censorexp, $username)) {
  274. if(!$return) {
  275. showmessage('profile_username_protect');
  276. } else {
  277. return;
  278. }
  279. }
  280. if(!$_G['wechat']['setting']['wechat_disableregrule']) {
  281. loadcache('ipctrl');
  282. if($_G['cache']['ipctrl']['ipregctrl']) {
  283. foreach(explode("\n", $_G['cache']['ipctrl']['ipregctrl']) as $ctrlip) {
  284. if(preg_match("/^(".preg_quote(($ctrlip = trim($ctrlip)), '/').")/", $_G['clientip'])) {
  285. $ctrlip = $ctrlip.'%';
  286. $_G['setting']['regctrl'] = $_G['setting']['ipregctrltime'];
  287. break;
  288. } else {
  289. $ctrlip = $_G['clientip'];
  290. }
  291. }
  292. } else {
  293. $ctrlip = $_G['clientip'];
  294. }
  295. if($_G['setting']['regctrl']) {
  296. if(C::t('common_regip')->count_by_ip_dateline($ctrlip, $_G['timestamp']-$_G['setting']['regctrl']*3600)) {
  297. if(!$return) {
  298. showmessage('register_ctrl', NULL, array('regctrl' => $_G['setting']['regctrl']));
  299. } else {
  300. return;
  301. }
  302. }
  303. }
  304. $setregip = null;
  305. if($_G['setting']['regfloodctrl']) {
  306. $regip = C::t('common_regip')->fetch_by_ip_dateline($_G['clientip'], $_G['timestamp']-86400);
  307. if($regip) {
  308. if($regip['count'] >= $_G['setting']['regfloodctrl']) {
  309. if(!$return) {
  310. showmessage('register_flood_ctrl', NULL, array('regfloodctrl' => $_G['setting']['regfloodctrl']));
  311. } else {
  312. return;
  313. }
  314. } else {
  315. $setregip = 1;
  316. }
  317. } else {
  318. $setregip = 2;
  319. }
  320. }
  321. if($setregip !== null) {
  322. if($setregip == 1) {
  323. C::t('common_regip')->update_count_by_ip($_G['clientip']);
  324. } else {
  325. C::t('common_regip')->insert(array('ip' => $_G['clientip'], 'count' => 1, 'dateline' => $_G['timestamp']));
  326. }
  327. }
  328. }
  329. $uid = uc_user_register(addslashes($username), $password, $email, '', '', $_G['clientip']);
  330. if($uid <= 0) {
  331. if(!$return) {
  332. if($uid == -1) {
  333. showmessage('profile_username_illegal');
  334. } elseif($uid == -2) {
  335. showmessage('profile_username_protect');
  336. } elseif($uid == -3) {
  337. showmessage('profile_username_duplicate');
  338. } elseif($uid == -4) {
  339. showmessage('profile_email_illegal');
  340. } elseif($uid == -5) {
  341. showmessage('profile_email_domain_illegal');
  342. } elseif($uid == -6) {
  343. showmessage('profile_email_duplicate');
  344. } else {
  345. showmessage('undefined_action');
  346. }
  347. } else {
  348. return;
  349. }
  350. }
  351. $init_arr = array('credits' => explode(',', $_G['setting']['initcredits']));
  352. C::t('common_member')->insert($uid, $username, $password, $email, $_G['clientip'], $groupid, $init_arr);
  353. if($_G['setting']['regctrl'] || $_G['setting']['regfloodctrl']) {
  354. C::t('common_regip')->delete_by_dateline($_G['timestamp']-($_G['setting']['regctrl'] > 72 ? $_G['setting']['regctrl'] : 72)*3600);
  355. if($_G['setting']['regctrl']) {
  356. C::t('common_regip')->insert(array('ip' => $_G['clientip'], 'count' => -1, 'dateline' => $_G['timestamp']));
  357. }
  358. }
  359. if($_G['setting']['regverify'] == 2) {
  360. C::t('common_member_validate')->insert(array(
  361. 'uid' => $uid,
  362. 'submitdate' => $_G['timestamp'],
  363. 'moddate' => 0,
  364. 'admin' => '',
  365. 'submittimes' => 1,
  366. 'status' => 0,
  367. 'message' => '',
  368. 'remark' => '',
  369. ), false, true);
  370. manage_addnotify('verifyuser');
  371. }
  372. setloginstatus(array(
  373. 'uid' => $uid,
  374. 'username' => $username,
  375. 'password' => $password,
  376. 'groupid' => $groupid,
  377. ), 0);
  378. include_once libfile('function/stat');
  379. updatestat('register');
  380. return $uid;
  381. }
  382. static public function syncAvatar($uid, $avatar) {
  383. if(!$uid || !$avatar) {
  384. return false;
  385. }
  386. if(!$content = dfsockopen($avatar)) {
  387. return false;
  388. }
  389. $tmpFile = DISCUZ_ROOT.'./data/avatar/'.TIMESTAMP.random(6);
  390. file_put_contents($tmpFile, $content);
  391. if(!is_file($tmpFile)) {
  392. return false;
  393. }
  394. $result = uploadUcAvatar::upload($uid, $tmpFile);
  395. unlink($tmpFile);
  396. C::t('common_member')->update($uid, array('avatarstatus'=>'1'));
  397. return $result;
  398. }
  399. static public function getnewname($openid) {
  400. global $_G;
  401. if(!$_G['wechat']['setting']) {
  402. $_G['wechat']['setting'] = unserialize($_G['setting']['mobilewechat']);
  403. }
  404. $wechat_client = new WeChatClient($_G['wechat']['setting']['wechat_appId'], $_G['wechat']['setting']['wechat_appsecret']);
  405. $userinfo = $wechat_client->getUserInfoById($openid);
  406. if($userinfo) {
  407. $defaultusername = substr(WeChatEmoji::clear($userinfo['nickname']), 0, 15);
  408. loaducenter();
  409. $user = uc_get_user($defaultusername);
  410. if(!empty($user)) {
  411. $defaultusername = cutstr($defaultusername, 7, '').'_'.random(5);
  412. }
  413. } else {
  414. $defaultusername = 'wx_'.random(5);
  415. }
  416. return $defaultusername;
  417. }
  418. }
  419. class uploadUcAvatar {
  420. public static function upload($uid, $localFile) {
  421. global $_G;
  422. if(!$uid || !$localFile) {
  423. return false;
  424. }
  425. list($width, $height, $type, $attr) = getimagesize($localFile);
  426. if(!$width) {
  427. return false;
  428. }
  429. if($width < 10 || $height < 10 || $type == 4) {
  430. return false;
  431. }
  432. $imageType = array(1 => '.gif', 2 => '.jpg', 3 => '.png');
  433. $fileType = $imgType[$type];
  434. if(!$fileType) {
  435. $fileType = '.jpg';
  436. }
  437. $avatarPath = $_G['setting']['attachdir'];
  438. $tmpAvatar = $avatarPath.'./temp/upload'.$uid.$fileType;
  439. file_exists($tmpAvatar) && @unlink($tmpAvatar);
  440. file_put_contents($tmpAvatar, file_get_contents($localFile));
  441. if(!is_file($tmpAvatar)) {
  442. return false;
  443. }
  444. $tmpAvatarBig = './temp/upload'.$uid.'big'.$fileType;
  445. $tmpAvatarMiddle = './temp/upload'.$uid.'middle'.$fileType;
  446. $tmpAvatarSmall = './temp/upload'.$uid.'small'.$fileType;
  447. $image = new image;
  448. if($image->Thumb($tmpAvatar, $tmpAvatarBig, 200, 250, 1) <= 0) {
  449. return false;
  450. }
  451. if($image->Thumb($tmpAvatar, $tmpAvatarMiddle, 120, 120, 1) <= 0) {
  452. return false;
  453. }
  454. if($image->Thumb($tmpAvatar, $tmpAvatarSmall, 48, 48, 2) <= 0) {
  455. return false;
  456. }
  457. $tmpAvatarBig = $avatarPath.$tmpAvatarBig;
  458. $tmpAvatarMiddle = $avatarPath.$tmpAvatarMiddle;
  459. $tmpAvatarSmall = $avatarPath.$tmpAvatarSmall;
  460. $avatar1 = self::byte2hex(file_get_contents($tmpAvatarBig));
  461. $avatar2 = self::byte2hex(file_get_contents($tmpAvatarMiddle));
  462. $avatar3 = self::byte2hex(file_get_contents($tmpAvatarSmall));
  463. $extra = '&avatar1='.$avatar1.'&avatar2='.$avatar2.'&avatar3='.$avatar3;
  464. $result = self::uc_api_post_ex('user', 'rectavatar', array('uid' => $uid), $extra);
  465. @unlink($tmpAvatar);
  466. @unlink($tmpAvatarBig);
  467. @unlink($tmpAvatarMiddle);
  468. @unlink($tmpAvatarSmall);
  469. return true;
  470. }
  471. public static function byte2hex($string) {
  472. $buffer = '';
  473. $value = unpack('H*', $string);
  474. $value = str_split($value[1], 2);
  475. $b = '';
  476. foreach($value as $k => $v) {
  477. $b .= strtoupper($v);
  478. }
  479. return $b;
  480. }
  481. public static function uc_api_post_ex($module, $action, $arg = array(), $extra = '') {
  482. $s = $sep = '';
  483. foreach($arg as $k => $v) {
  484. $k = urlencode($k);
  485. if(is_array($v)) {
  486. $s2 = $sep2 = '';
  487. foreach($v as $k2 => $v2) {
  488. $k2 = urlencode($k2);
  489. $s2 .= "$sep2{$k}[$k2]=".urlencode(uc_stripslashes($v2));
  490. $sep2 = '&';
  491. }
  492. $s .= $sep.$s2;
  493. } else {
  494. $s .= "$sep$k=".urlencode(uc_stripslashes($v));
  495. }
  496. $sep = '&';
  497. }
  498. $postdata = uc_api_requestdata($module, $action, $s, $extra);
  499. return uc_fopen2(UC_API.'/index.php', 500000, $postdata, '', TRUE, UC_IP, 20);
  500. }
  501. }
  502. class showActivity {
  503. public static $init = false;
  504. public static function init() {
  505. global $_G;
  506. if(!$_G['wechat']['setting']['wsq_allow'] || !in_array($_G['tid'], (array)$_G['wechat']['setting']['showactivity']['tids'])) {
  507. return false;
  508. }
  509. if(!self::$init) {
  510. $_G['setting']['allowpostcomment'] = array(0 => 1, 1 => 2);
  511. $_G['setting']['commentnumber'] = 10;
  512. $_G['setting']['commentpostself'] = 0;
  513. $_G['setting']['commentfirstpost'] = 0;
  514. $_G['setting']['fastpost'] = 0;
  515. $_G['setting']['showimages'] = 1;
  516. $_G['setting']['imagelistthumb'] = 1;
  517. $_G['setting']['activitypp'] = 0;
  518. $_G['setting']['disallowfloat'] .= '|reply';
  519. $_G['setting']['guesttipsinthread']['flag'] = 0;
  520. $_G['setting']['nofilteredpost'] = 0;
  521. $_G['group']['allowgetimage'] = 1;
  522. if($_G['basescript'].'::'.CURMODULE == 'forum::post' && $_GET['action'] == 'edit') {
  523. $_G['group']['allowpostactivity'] = true;
  524. $_G['forum']['allowpostspecial'] = 255;
  525. }
  526. $_GET['ordertype'] = empty($_GET['ordertype']) ? 1 : $_GET['ordertype'];
  527. self::$init = true;
  528. }
  529. return true;
  530. }
  531. function misc() {
  532. global $_G;
  533. if(!$_POST || $_GET['action'] != 'activityapplies' && $_GET['action'] != 'activityapplylist') {
  534. return;
  535. }
  536. if(submitcheck('activitysubmit')) {
  537. showmessage('wechat:show_please_reply');
  538. } elseif(submitcheck('activitycancel')) {
  539. showmessage('wechat:show_no_cancel');
  540. } elseif(submitcheck('applylistsubmit') && $_GET['operation'] == 'replenish') {
  541. showmessage('wechat:show_disabled');
  542. }
  543. }
  544. function post() {
  545. global $_G;
  546. if($_GET['action'] != 'reply') {
  547. return;
  548. }
  549. if(submitcheck('replysubmit')) {
  550. $activity = C::t('forum_activity')->fetch($_G['tid']);
  551. if($activity['starttimefrom'] > TIMESTAMP) {
  552. showmessage('wechat:show_no_begin', NULL, array());
  553. }
  554. if($activity['expiration'] && $activity['expiration'] < TIMESTAMP) {
  555. showmessage('activity_stop', NULL, array(), array('login' => 1));
  556. }
  557. if(empty($_GET['attachnew'])) {
  558. showmessage('wechat:show_please_upload');
  559. }
  560. $data = array('tid' => $_G['tid'], 'username' => $_G['username'], 'uid' => $_G['uid'], 'message' => '', 'verified' => 1, 'dateline' => $_G['timestamp']);
  561. C::t('forum_activityapply')->insert($data);
  562. $applynumber = C::t('forum_activityapply')->fetch_count_for_thread($_G['tid']);
  563. C::t('forum_activity')->update($_G['tid'], array('applynumber' => $applynumber));
  564. }
  565. }
  566. function returnvoters($type) {
  567. global $_G;
  568. $return = array();
  569. if($type == 1) {
  570. $posts = DB::fetch_all("SELECT * FROM %t WHERE tid=%d", array('forum_debatepost', $_G['tid']), 'pid');
  571. foreach($GLOBALS['postlist'] as $post) {
  572. $posts[$post['pid']]['voters'] = intval($posts[$post['pid']]['voters']);
  573. $return[] = !$post['first'] ? wechatshowactivity_tpl_voters($posts[$post['pid']]) : '';
  574. }
  575. } else {
  576. foreach($GLOBALS['postlist'] as $post) {
  577. $return[] = !$post['first'] ? wechatshowactivity_tpl_share($post) : '';
  578. }
  579. }
  580. return $return;
  581. }
  582. }