spacecp.inc.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. /**
  3. * [Discuz! X] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: spacecp.inc.php 33645 2013-07-25 01:32:20Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. if(!$_G['uid']) {
  12. showmessage('not_loggedin', NULL, array(), array('login' => 1));
  13. }
  14. $pluginop = !empty($_GET['pluginop']) ? $_GET['pluginop'] : 'config';
  15. if (!in_array($pluginop, array('config', 'share', 'new', 'sync_tthread'))) {
  16. showmessage('undefined_action');
  17. }
  18. $sh_type = trim(intval($_GET['sh_type']));
  19. $tid = trim(intval($_GET['thread_id']));
  20. $connectService = Cloud::loadClass('Service_Connect');
  21. if ($pluginop == 'config') {
  22. $connectService->connectMergeMember();
  23. $_G['connect']['is_oauth_user'] = true;
  24. if (empty($_G['member']['conuinsecret'])) {
  25. $_G['connect']['is_oauth_user'] = false;
  26. }
  27. $referer = str_replace($_G['siteurl'], '', dreferer());
  28. if(!empty($_GET['connect_autoshare'])) {
  29. if(strpos($referer, '?') !== false) {
  30. $referer .= '&connect_autoshare=1';
  31. } else {
  32. $referer .= '?connect_autoshare=1';
  33. }
  34. }
  35. $_G['connect']['loginbind_url'] = $_G['siteurl'].'connect.php?mod=login&op=init&type=loginbind&referer='.urlencode($_G['connect']['referer'] ? $_G['connect']['referer'] : 'index.php');
  36. } elseif ($pluginop == 'share') {
  37. $_GET['share_url'] = $_G['connect']['discuz_new_share_url'];
  38. $post = C::t('forum_post')->fetch_threadpost_by_tid_invisible($tid, 0);
  39. $thread = C::t('forum_thread')->fetch_by_tid_displayorder($tid, 0);
  40. require_once libfile('function/post');
  41. $post['message'] = messagesafeclear($post['message']);
  42. $html_content = $connectService->connectParseBbcode($post['message'], $thread['fid'], $post['pid'], $post['htmlon'], $attach_images);
  43. if ($_G['group']['allowgetimage'] && $thread['price'] == 0 && $post['pid']) {
  44. if ($attach_images && is_array($attach_images)) {
  45. $_GET['share_images'] = array_slice($attach_images, 0, 3);
  46. $attach_images = array();
  47. foreach ($_GET['share_images'] as $image) {
  48. $attach_images[] = $image['big'];
  49. }
  50. $_GET['attach_image'] = implode('|', $attach_images);
  51. unset($attach_images);
  52. }
  53. }
  54. if($_GET['sh_type'] == 4){
  55. if($_G['setting']['rewritestatus'] && in_array('forum_viewthread', $_G['setting']['rewritestatus'])) {
  56. $url = rewriteoutput('forum_viewthread', 1, $_G['siteurl'], $tid);
  57. } else {
  58. $url = $_G['siteurl'].'forum.php?mod=viewthread&tid='.$tid;
  59. }
  60. $shareqq_params = array(
  61. 'url' => $url,
  62. 'title' => diconv($thread['subject'], CHARSET, 'UTF-8'),
  63. 'summary' => diconv(cutstr(strip_tags(str_replace('&nbsp;', ' ', $html_content)), 80), CHARSET, 'UTF-8'),
  64. 'desc' => diconv(lang('plugin/qqconnect', 'connect_spacecp_share_qq_default'), CHARSET, 'UTF-8'),
  65. 'site' => 'discuz|',
  66. 'style' => '103',
  67. 'width' => 50,
  68. 'height' => 16
  69. );
  70. $s = '';
  71. foreach($shareqq_params as $key => $val) {
  72. $s .= ($s ? '&' : '').$key.'='.urlencode($val);
  73. }
  74. header('Location: http://connect.qq.com/widget/shareqq/index.html?'.$s);
  75. } else {
  76. $share_message = lang('plugin/qqconnect', 'connect_spacecp_share_a_post', array('bbname' => cutstr($_G['setting']['bbname'], 20,''), 'subject' => cutstr($thread['subject'], 120), 'message' => cutstr(strip_tags(str_replace('&nbsp;', ' ', $html_content)), 80)));
  77. $share_message = str_replace(array('\'', "\r\n", "\r", "\n"), array('"', '', '', ''), $share_message);
  78. }
  79. } elseif ($pluginop == 'new') {
  80. if (trim($_GET['formhash']) != formhash()) {
  81. showmessage('submit_invalid');
  82. }
  83. $sh_type = intval(trim($_POST['sh_type']));
  84. $tid = intval(trim($_POST['thread_id']));
  85. $dialog_id = $_POST['dialog_id'];
  86. $connectService->connectMergeMember();
  87. if($_G['setting']['rewritestatus'] && in_array('forum_viewthread', $_G['setting']['rewritestatus'])) {
  88. $url = rewriteoutput('forum_viewthread', 1, $_G['siteurl'], $tid);
  89. } else {
  90. $url = $_G['siteurl'].'forum.php?mod=viewthread&tid='.$tid;
  91. }
  92. $connectOAuthClient = Cloud::loadClass('Service_Client_ConnectOAuth');
  93. $connectService = Cloud::loadClass('Service_Connect');
  94. if($sh_type == 3) {
  95. $firstpost = C::t('forum_post')->fetch_threadpost_by_tid_invisible($tid, 0);
  96. require_once libfile('function/post');
  97. $firstpost['message'] = messagesafeclear($firstpost['message']);
  98. $summary = $connectService->connectParseBbcode($firstpost['message'], $firstpost['fid'], $firstpost['pid'], $firstpost['htmlon'], $attach_images);
  99. $qzone_params = array(
  100. 'title' => $_POST['share_subject'],
  101. 'url' => $url,
  102. 'comment' => $_POST['reason'],
  103. 'summary' => strip_tags($summary),
  104. 'images' => $_POST['attach_image'],
  105. 'nswb' => '1',
  106. );
  107. if(!$_G['setting']['connect']['oauth2'] || !$_G['member']['conuintoken']) {
  108. try {
  109. $response = $connectOAuthClient->connectAddShare($_G['member']['conopenid'], $_G['member']['conuin'], $_G['member']['conuinsecret'], $qzone_params);
  110. } catch(Exception $e) {
  111. $errorCode = $e->getCode();
  112. }
  113. } else {
  114. try {
  115. $response = $connectOAuthClient->connectAddShare_V2($_G['member']['conopenid'], $_G['member']['conuintoken'], $qzone_params);
  116. } catch(Exception $e) {
  117. $errorCode = $e->getCode();
  118. }
  119. }
  120. if($errorCode) {
  121. $code = $errorCode;
  122. if($errorCode == 41001) {
  123. $message = lang('plugin/qqconnect', 'connect_user_unauthorized', array('login_url' => $_G['connect']['login_url'].'&reauthorize=yes&formhash='.FORMHASH));
  124. } elseif($errorCode == 41003 || $errorCode == 40006) { // access token失效或非法
  125. $message = lang('plugin/qqconnect', 'connect_share_token_outofdate', array('login_url' => $_G['connect']['login_url']));
  126. } elseif ($errorCode == 3021) {
  127. $message = lang('plugin/qqconnect', 'connect_qzone_share_same_url');
  128. } else {
  129. $code = 100;
  130. $message = lang('plugin/qqconnect', 'connect_server_busy');
  131. $connectService->connectErrlog($code, lang('plugin/qqconnect', 'connect_errlog_server_no_response'));
  132. }
  133. } else {
  134. $code = $response['ret'];
  135. $message = lang('plugin/qqconnect', 'connect_share_success');
  136. }
  137. } elseif($sh_type == 2) {
  138. $t_params = array(
  139. 'content' => $_POST['reason'],
  140. );
  141. $aid = intval($_POST['attach_image_id']);
  142. if ($aid) {
  143. $method = 'connectAddPicT';
  144. $attach = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid);
  145. if($attach['remote']) {
  146. $t_params['pic'] = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];
  147. $t_params['remote'] = true;
  148. } else {
  149. $t_params['pic'] = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
  150. }
  151. } else {
  152. $method = 'connectAddT';
  153. }
  154. if(!$_G['setting']['connect']['oauth2'] || !$_G['member']['conuintoken']) {
  155. try {
  156. $response = $connectOAuthClient->$method($_G['member']['conopenid'], $_G['member']['conuin'], $_G['member']['conuinsecret'], $t_params);
  157. } catch(Exception $e) {
  158. $errorCode = $e->getCode();
  159. }
  160. } else {
  161. try {
  162. $method = $method.'_V2';
  163. $response = $connectOAuthClient->$method($_G['member']['conopenid'], $_G['member']['conuintoken'], $t_params);
  164. } catch(Exception $e) {
  165. $errorCode = $e->getCode();
  166. }
  167. }
  168. if($errorCode) {
  169. $code = $errorCode;
  170. if($errorCode == 41001) {
  171. $message = lang('plugin/qqconnect', 'connect_user_unauthorized', array('login_url' => $_G['connect']['login_url'].'&reauthorize=yes&formhash='.FORMHASH));
  172. } elseif($errorCode == 41003 || $errorCode == 40006) { // access token失效或非法
  173. $message = lang('plugin/qqconnect', 'connect_share_token_outofdate', array('login_url' => $_G['connect']['login_url']));
  174. } elseif ($errorCode == 3013) {
  175. $message = lang('plugin/qqconnect', 'connect_qzone_weibo_same_content');
  176. } else if($errorCode == 3020) {
  177. $message = lang('plugin/qqconnect', 'connect_weibo_account_not_signup');
  178. } else {
  179. $code = 100;
  180. $message = lang('plugin/qqconnect', 'connect_server_busy');
  181. $connectService->connectErrlog($code, lang('plugin/qqconnect', 'connect_errlog_server_no_response'));
  182. }
  183. } else {
  184. $thread = C::t('forum_thread')->fetch($tid);
  185. if($response['data']['id'] && $_G['setting']['connect']['t']['reply'] && $thread['tid'] && !$thread['closed'] && !getstatus($thread['status'], 3) && empty($_G['forum']['replyperm'])) {
  186. C::t('#qqconnect#connect_tthreadlog')->insert(array(
  187. 'twid' => $response['data']['id'],
  188. 'tid' => $tid,
  189. 'conopenid' => $_G['member']['conopenid'],
  190. 'pagetime' => 0,
  191. 'lasttwid' => '0',
  192. 'nexttime' => $_G['timestamp'] + 30 * 60,
  193. 'updatetime' => 0,
  194. 'dateline' => $_G['timestamp'],
  195. ));
  196. }
  197. if(!getstatus($thread['status'], 8)) {
  198. C::t('forum_thread')->update($tid, array('status' => setstatus(8, 1, $thread['status'])));
  199. }
  200. $code = $response['ret'];
  201. $message = lang('plugin/qqconnect', 'connect_broadcast_success');
  202. }
  203. }
  204. } elseif($pluginop == 'sync_tthread') {
  205. if (trim($_GET['formhash']) != formhash()) {
  206. showmessage('submit_invalid');
  207. }
  208. if(!$_G['setting']['connect']['t']['reply']) {
  209. exit;
  210. }
  211. $tid = $_GET['tid'];
  212. $processname = 'connect_tthread_'.$tid.'_cache';
  213. if(discuz_process::islocked($processname, 600)) {
  214. exit;
  215. }
  216. $thread = C::t('forum_thread')->fetch($tid);
  217. if(!$thread || $thread['closed'] == 1 || getstatus($thread['status'], 3) || $thread['displayorder'] < 0 || !empty($_G['forum']['replyperm'])) {
  218. discuz_process::unlock($processname);
  219. exit;
  220. }
  221. $updatetime = C::t('#qqconnect#connect_tthreadlog')->fetch_max_updatetime_by_tid($tid);
  222. if($_G['timestamp'] < $updatetime + 10 * 60) {
  223. discuz_process::unlock($processname);
  224. exit;
  225. }
  226. $tthread = C::t('#qqconnect#connect_tthreadlog')->fetch_min_nexttime_by_tid($tid);
  227. if(empty($tthread)) {
  228. discuz_process::unlock($processname);
  229. exit;
  230. }
  231. $connectOAuthClient = Cloud::loadClass('Service_Client_ConnectOAuth');
  232. $connectmember = C::t('#qqconnect#common_member_connect')->fetch_fields_by_openid($tthread['conopenid']);
  233. $param = array();
  234. $param['format'] = 'xml';
  235. $param['flag'] = '2';
  236. $param['rootid'] = $tthread['twid'];
  237. $param['pageflag'] = 2;
  238. $param['pagetime'] = $tthread['pagetime'];
  239. $param['reqnum'] = 20;
  240. $param['twitterid'] = $tthread['lasttwid'];
  241. try {
  242. $response = $connectOAuthClient->connectGetRepostList($tthread['conopenid'], $connectmember['conuin'], $connectmember['conuinsecret'], $param);
  243. } catch(Exception $e) {
  244. showmessage('qqconnect:server_busy');
  245. }
  246. if($response && $response['ret'] == 0 && $response['data']['info']) {
  247. include_once libfile('function/forum');
  248. $forum = C::t('forum_forum')->fetch($thread['fid']);
  249. $pinvisible = $forum['modnewposts'] ? -2 : 0;
  250. $pids = array();
  251. $i = 0;
  252. $responseinfo = array();
  253. if(!isset($response['data']['info'][0])) {
  254. $responseinfo[] = $response['data']['info'];
  255. } else {
  256. $responseinfo = $response['data']['info'];
  257. krsort($responseinfo);
  258. }
  259. foreach($responseinfo as $post) {
  260. $message = trim($post['text']);
  261. $post['username'] = trim($post['name']);
  262. $post['nick'] = trim($post['nick']);
  263. $message = preg_replace("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto):\/\/|www\.)([a-z0-9\/\-_+=.~!%@?#%&;:$\\()|]+\s*)/i", '', $message);
  264. $message = str_replace(explode(' ', lang('plugin/qqconnect', 'connect_reply_filter_smiley')), '', $message);
  265. if($message) {
  266. $newmessage = censor($message, null, true);
  267. if($message != $newmessage) {
  268. continue;
  269. }
  270. } else {
  271. $message = lang('plugin/qqconnect', 'connect_tthread_broadcast');
  272. }
  273. if($_G['setting']['connect']['t']['reply_showauthor']) {
  274. $message .= '[tthread='.$post['username'].', '.$post['nick'].']'.$post['head'].'[/tthread]';
  275. }
  276. $pid = insertpost(array(
  277. 'fid' => $thread['fid'],
  278. 'tid' => $thread['tid'],
  279. 'first' => '0',
  280. 'author' => '',
  281. 'authorid' => '0',
  282. 'subject' => '',
  283. 'dateline' => $_G['timestamp'] + $i,
  284. 'message' => $message,
  285. 'useip' => '',
  286. 'invisible' => $pinvisible,
  287. 'anonymous' => '0',
  288. 'usesig' => '0',
  289. 'htmlon' => '1',
  290. 'bbcodeoff' => '0',
  291. 'smileyoff' => '0',
  292. 'parseurloff' => '0',
  293. 'attachment' => '0',
  294. 'status' => 16,
  295. ));
  296. if($pid) {
  297. $pids[] = $pid;
  298. }
  299. $i++;
  300. }
  301. if($pinvisible) {
  302. updatemoderate('pid', $pids);
  303. C::t('forum_forum')->update_forum_counter($thread['fid'], 0, 0, count($pids), 1);
  304. } else {
  305. $fieldarr = array(
  306. 'lastposter' => array(''),
  307. 'replies' => count($pids),
  308. );
  309. if($thread['lastpost'] < $_G['timestamp']) {
  310. $fieldarr['lastpost'] = array($_G['timestamp']);
  311. }
  312. C::t('forum_thread')->increase($tid, $fieldarr);
  313. $postionid = C::t('forum_post')->fetch_maxposition_by_tid($thread['posttableid'], $tid);
  314. C::t('forum_thread')->update($tid, array('maxposition' => $postionid));
  315. $lastpost = "$thread[tid]\t$thread[subject]\t$_G[timestamp]\t".'';
  316. C::t('forum_forum')->update($thread['fid'], array('lastpost' => $lastpost));
  317. C::t('forum_forum')->update_forum_counter($thread['fid'], 0, count($pids), count($pids));
  318. if($forum['type'] == 'sub') {
  319. C::t('forum_forum')->update($forum['fup'], array('lastpost' => $lastpost));
  320. }
  321. }
  322. $setarr['pagetime'] = $post['timestamp'];
  323. $setarr['lasttwid'] = $post['id'];
  324. if(count($responseinfo) < $param['reqnum']) {
  325. $setarr['nexttime'] = $_G['timestamp'] + 2 * 3600;
  326. } else {
  327. $setarr['nexttime'] = $_G['timestamp'] + 30 * 60;
  328. }
  329. } else {
  330. $setarr['nexttime'] = $_G['timestamp'] + 3 * 3600;
  331. }
  332. $setarr['updatetime'] = $_G['timestamp'];
  333. C::t('#qqconnect#connect_tthreadlog')->update($tthread['twid'], $setarr);
  334. discuz_process::unlock($processname);
  335. exit;
  336. }