cloud_qqgroup.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  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: cloud_qqgroup.php 31974 2012-10-29 06:02:39Z songlixin $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. $op = trim($_GET['op']);
  12. $utilService = Cloud::loadClass('Service_Util');
  13. $signUrl = $utilService->generateSiteSignUrl(array('v' => 2));
  14. $_GET['anchor'] = in_array($_GET['anchor'], array('block', 'list', 'info', 'setting')) ? $_GET['anchor'] : 'block';
  15. if ($_GET['first']) {
  16. $_GET['anchor'] = 'list';
  17. }
  18. $current = array($_GET['anchor'] => 1);
  19. $qqgroupnav = array();
  20. $qqgroupnav[0] = array('qqgroup_menu_block', 'cloud&operation=qqgroup&anchor=block', $current['block']);
  21. $qqgroupnav[1] = array('qqgroup_menu_list', 'cloud&operation=qqgroup&anchor=list', $current['list']);
  22. $qqgroupnav[2] = array('qqgroup_menu_manager', 'cloud&operation=qqgroup&anchor=info', $current['info']);
  23. $qqgroupnav[3] = array('qqgroup_menu_setting', 'cloud&operation=qqgroup&anchor=setting', $current['setting']);
  24. if (!$_G['inajax']) {
  25. cpheader();
  26. }
  27. if($_GET['anchor'] == 'list') {
  28. $utilService->redirect($cloudDomain.'/qun/list/?' . $signUrl);
  29. } elseif($_GET['anchor'] == 'info') {
  30. $utilService->redirect($cloudDomain.'/qun/siteInfo/?' . $signUrl);
  31. } elseif($_GET['anchor'] == 'setting') {
  32. if(submitcheck('settingsubmit')) {
  33. $usergroups = $_POST['groupid'];
  34. $updateData = array(
  35. 'qqgroup_usergroup_feed_list' => serialize($usergroups),
  36. );
  37. C::t('common_setting')->update_batch($updateData);
  38. updatecache('setting');
  39. cpmsg('setting_update_succeed', 'action=cloud&operation=qqgroup&anchor='.$_GET['anchor'], 'succeed');
  40. } else {
  41. $usergroupsfeedlist = unserialize($_G['setting']['qqgroup_usergroup_feed_list']);
  42. $groupselect = array();
  43. foreach (C::t('common_usergroup')->fetch_all_by_radminid(0) as $group) {
  44. $group['type'] = $group['type'] == 'special' && $group['radminid'] ? 'specialadmin' : $group['type'];
  45. $groupselect[$group['type']] .= "<option value=\"$group[groupid]\" ".(in_array($group['groupid'], $usergroupsfeedlist) ? 'selected' : '').">$group[grouptitle]</option>\n";
  46. }
  47. $groupselect = ($groupselect['special'] ? '<optgroup label="'.$lang['usergroups_special'].'">'.$groupselect['special'].'</optgroup>' : '').
  48. ($groupselect['specialadmin'] ? '<optgroup label="'.$lang['usergroups_specialadmin'].'">'.$groupselect['specialadmin'].'</optgroup>' : '').
  49. '<optgroup label="'.$lang['usergroups_system'].'">'.$groupselect['system'].'</optgroup>';
  50. shownav('navcloud', 'menu_cloud_qqgroup');
  51. showsubmenu('menu_cloud_qqgroup', $qqgroupnav);
  52. showtips('qqgroup_setting_tips');
  53. showformheader('cloud&operation=qqgroup&anchor=setting');
  54. showtableheader('qqgroup_feed_setting', '', '', 2);
  55. showsetting('qqgroup_usergroup_feed_list', '', '', '<select name="groupid[]" multiple="multiple" size="10">'.$groupselect.'</select>');
  56. showsubmit('settingsubmit');
  57. showtablefooter();
  58. showformfooter();
  59. }
  60. } elseif($_GET['anchor'] == 'block') {
  61. $perpage = 10;
  62. $maxPage = 10;
  63. $page = intval($_GET['page']);
  64. $page = MAX($page, 1);
  65. $page = MIN($page, $maxPage);
  66. $prevPage = MAX($page - 1, 1);
  67. $nextPage = MIN($page + 1, $maxPage);
  68. if(submitcheck('setMiniportalThreadsSubmit')) {
  69. $topic = $_GET['topic'];
  70. $topic = processMiniportalTopicThread($topic);
  71. if(!$topic) {
  72. cpmsg('qqgroup_msg_deficiency', '', 'error');
  73. }
  74. $normal = $_GET['normal'];
  75. $normal = processMiniportalNormalThreads($normal);
  76. if(!$normal) {
  77. cpmsg('qqgroup_msg_deficiency', '', 'error');
  78. }
  79. $serverResult = sentMiniportalThreadsRemote($topic, $normal);
  80. $threads = array('topic' => $topic, 'normal' => $normal);
  81. if($serverResult['status']) {
  82. storeMiniportalThreads($threads);
  83. cpmsg('qqgroup_msg_save_succeed', 'action=cloud&operation=qqgroup&anchor=block', 'succeed');
  84. } else {
  85. $info = array('threads' => $threads, 'errorIds' => $serverResult['errorIds']);
  86. QQGroupMessage($serverResult['msg'], 'action=cloud&operation=qqgroup&anchor=block&sentResult=1', $info);
  87. }
  88. } elseif($op == 'getTopicThread') {
  89. getTopicThread();
  90. } elseif($op == 'getNormalThread') {
  91. getNormalThread();
  92. } elseif($op == 'uploadImage') {
  93. $tid = intval($_GET['tid']);
  94. if (submitcheck('uploadImageSubmit')) {
  95. ajaxshowheader();
  96. if($uploadImage = QQGroupUpload($tid)) {
  97. echo '<div id="upload_msg_success">'.cplang('qqgroup_msg_upload_succeed').'</div><div id="upload_msg_imgpath" style="display:none;">'.$uploadImage['thumbTarget'].'</div><div id="upload_msg_imgurl" style="display:none;">'.$_G['setting']['attachurl'].$uploadImage['thumbTarget'].'</div>';
  98. } else {
  99. echo '<div id="upload_msg_failure">'.cplang('qqgroup_msg_upload_failure').'</div>';
  100. }
  101. ajaxshowfooter();
  102. } else {
  103. showUploadImageForm($tid);
  104. }
  105. } elseif($op == 'searchForm') {
  106. showSearchThreads();
  107. } else {
  108. shownav('navcloud', 'menu_cloud_qqgroup');
  109. showsubmenu('menu_cloud_qqgroup', $qqgroupnav);
  110. echo '<div id="ajaxwaitid"></div>';
  111. showQQGroupCSS();
  112. showSearchDiv();
  113. showMiniportalPreview();
  114. showQQGroupScript();
  115. }
  116. }
  117. function showSearchForm() {
  118. require_once libfile('function/forumlist');
  119. showformheader('cloud&operation=qqgroup&anchor=block&op=searchForm', 'onSubmit="ajaxGetSearchResultThreads(); return false;"', 'search_form');
  120. showtableheader();
  121. $orderoptions = array('views', 'replies', 'heats', 'dateline', 'lastpost', 'recommends');
  122. $orderoption = '';
  123. foreach($orderoptions as $value) {
  124. $orderoption .= '<option value="'.$value.'" '.($value == 'dateline' ? 'selected="selected"' : '').'>'.cplang('qqgroup_search_order_'.$value).'</option>';
  125. }
  126. $datelineoptions = array(1, 2, 3, 4);
  127. $datelineoption = '';
  128. foreach($datelineoptions as $value) {
  129. $datelineoption .= '<option value="'.$value.'" '.($value == 4 ? 'selected="selected"' : '').'>'.cplang(sprintf('qqgroup_search_dateline_%s', $value)).'</option>';
  130. }
  131. echo '
  132. <tr>
  133. <td><select id="srchorder" name="srchorder" onchange="ajaxChangeSearch();">'.$orderoption.'</select></td>
  134. <td><select id="srchdateline" name="srchdateline" onChange="ajaxChangeSearch();">'.$datelineoption.'</select></td>
  135. <td><label for="srchtid">'.cplang('qqgroup_search_tid').'</label></td>
  136. <td><input type="text" value="" id="srchtid" name="srchtid" style="width:80px;" /></td>
  137. <td><input type="submit" value="'.cplang('qqgroup_search_button').'" id="search_submit" name="search_submit" class="btn" /></td>
  138. </tr>
  139. ';
  140. showtablefooter();
  141. showformfooter();
  142. }
  143. function showSearchThreads() {
  144. global $_G, $page, $perpage;;
  145. $threads = array();
  146. $starttime = 0;
  147. $srchtid = intval($_GET['srchtid']);
  148. $srchorder = in_array($_GET['srchorder'], array('views', 'replies', 'heats', 'dateline', 'lastpost')) ? $_GET['srchorder'] : 'dateline';
  149. $datelinearray = array(1 => 3600, 2 => 86400, 3 => 86400 * 7, 4 => 86400 * 30);
  150. $srchdateline = array_key_exists($_GET['srchdateline'], $datelinearray) ? $datelinearray[$_GET['srchdateline']] : 86400 * 30;
  151. $start = ($page - 1) * $perpage;
  152. if($srchtid) {
  153. $threads = C::t('forum_thread')->fetch_all_by_tid_displayorder($srchtid, 0);
  154. } else {
  155. $starttime = TIMESTAMP - $srchdateline;
  156. $threads = C::t('forum_thread')->fetch_all_by_dateline($starttime, $start, $perpage, $srchorder);
  157. }
  158. $mpurl = ADMINSCRIPT.'?action=cloud&operation=qqgroup&anchor=block&op=searchForm'
  159. .'&srchtid='.$srchtid.'&srchorder='.$srchorder.'&srchdateline='.intval($_GET['srchdateline']);
  160. return showSearchResultThreads($threads, $mpurl);
  161. }
  162. function showSearchResultThreads($threads, $mpurl) {
  163. global $_G;
  164. $threadsOutput = '';
  165. loadcache('forums');
  166. if(empty($threads)) {
  167. $threadsOutput = '
  168. <tr><td colspan="3">'.cplang('qqgroup_search_nothreads').'</td></tr>
  169. ';
  170. } else {
  171. foreach($threads as $thread) {
  172. $thread['subject'] = strip_tags($thread['subject']);
  173. $threadsOutput .= '
  174. <tr id="thread_'.$thread['tid'].'">
  175. <td class="title"><a href="forum.php?mod=viewthread&tid='.$thread['tid'].'" title="'.$thread['subject'].'" target="_blank">'.cutstr($thread['subject'], 45).($thread['attachment'] == 2 ? '&nbsp;<img align="absmiddle" src="static/image/admincp/cloud/image_s.gif" alt="attach_img" title="'.cplang('attach_img').'" />' : '').'</a></td>
  176. <td title="'.dhtmlspecialchars(strip_tags($_G['cache']['forums'][$thread['fid']]['name'])).'">'.cutstr(dhtmlspecialchars(strip_tags($_G['cache']['forums'][$thread['fid']]['name'])), 14, '').'</td>
  177. <td class="qqqun_op"><a id="thread_addtop_'.$thread['tid'].'" href="javascript:;" onClick="addMiniportalTop('.$thread['tid'].')" class="qqqun_op_top" title="'.cplang('qqgroup_ctrl_add_miniportal_topic').'">top</a><a id="thread_addlist_'.$thread['tid'].'" href="javascript:;" onClick="addMiniportalList('.$thread['tid'].')" class="qqqun_op_list" title="'.cplang('qqgroup_ctrl_add_miniportal_normal').'">list</a></td>
  178. </tr>';
  179. }
  180. }
  181. ajaxshowheader();
  182. echo $threadsOutput;
  183. showSearchResultPageLinks(count($threads), $mpurl);
  184. ajaxshowfooter();
  185. }
  186. function showSearchResultPageLinks($num = 0, $mpurl) {
  187. global $_G, $page, $perpage, $maxPage;
  188. $needNext = $page < $maxPage && $num == $perpage ? true : false;
  189. if ($pageLink = QQGroupSearchSimplePage($needNext, $page, $mpurl)) {
  190. echo '<tr><td colspan="3" class="qqqun_pg">'.$pageLink.'</td></tr>';
  191. }
  192. }
  193. function QQGroupSearchSimplePage($needNext, $curpage, $mpurl) {
  194. global $prevPage, $nextPage;
  195. $return = '';
  196. $lang['next'] = lang('core', 'nextpage');
  197. $lang['prev'] = lang('core', 'prevpage');
  198. $searchThreadsRule = 'ajaxGetPageResultThreads(\'%s\', \'%s\');';
  199. $prevClickFunc = addcslashes(sprintf($searchThreadsRule, $prevPage, dhtmlspecialchars($mpurl)), '"');
  200. $nextClickFunc = addcslashes(sprintf($searchThreadsRule, $nextPage, dhtmlspecialchars($mpurl)), '"');
  201. $prev = $curpage > 1 ? '<a href="javascript:;" onClick="'.$prevClickFunc.'" >'.$lang['prev'].'</a>' : '';
  202. $next = $needNext ? '<a href="javascript:;" onClick="'.$nextClickFunc.'" >'.$lang['next'].'</a>' : '';
  203. if($next || $prev) {
  204. $return = $prev.$next;
  205. }
  206. return $return;
  207. }
  208. function getTopicThread() {
  209. global $_G;
  210. $tid = intval($_GET['tid']);
  211. if(empty($tid)) {
  212. ajaxshowheader();
  213. echo showTopicTemplate(0);
  214. ajaxshowfooter();
  215. return false;
  216. }
  217. require_once libfile('function/forum');
  218. require_once libfile('function/discuzcode');
  219. loadforum();
  220. $posttable = $_G['thread']['posttable'];
  221. if(empty($posttable)) {
  222. ajaxshowheader();
  223. echo showTopicTemplate(0);
  224. ajaxshowfooter();
  225. return false;
  226. }
  227. $imagePath = $imageUrl = '';
  228. $subject = strip_tags($_G['thread']['subject']);
  229. $post = C::t('forum_post')->fetch_threadpost_by_tid_invisible($tid);
  230. $pid = intval($post['pid']);
  231. $message = cutstr(strip_tags(discuzcode($post['message'], 1, 0, 1)), 200);
  232. $message = preg_replace('/\[attach\](\d+)\[\/attach\]/is', '', $message);
  233. $imageDir = 'qqgroup';
  234. $imageName = 'miniportal_tid_'.$tid.'.jpg';
  235. $thumbTarget = $imageDir.'/'.$imageName;
  236. if(file_exists($_G['setting']['attachdir'].'./'.$thumbTarget)) {
  237. $imagePath = $thumbTarget;
  238. $imageUrl = $_G['setting']['attachurl'].$imagePath;
  239. } else {
  240. $attachments = C::t('forum_attachment_n')->fetch_all_by_id('tid:' . $tid, 'pid', $pid, '', array('-1', '1'), false, 0, 1);
  241. if($attachments && $attachment = reset($attachments)) {
  242. $imagePath = 'forum/'.$attachment['attachment'];
  243. $imageUrl = $_G['setting']['attachurl'].$imagePath;
  244. }
  245. }
  246. ajaxshowheader();
  247. echo showTopicTemplate($tid, $subject, $message, $imagePath, $imageUrl);
  248. ajaxshowfooter();
  249. }
  250. function showTopicTemplate($tid, $subject = '', $message = '', $imagePath = '', $imageUrl = '') {
  251. $html = '';
  252. if ($tid) {
  253. $html .= '
  254. <div class="qqqun_editor">
  255. <ul>
  256. <li class="e_edit"><a href="javascript:;" title="'.cplang('qqgroup_ctrl_edit').'" onClick="clickTopicEditor(\'title\')">edit</a></li>
  257. <li class="e_pic"><a onclick="showWindow(\'uploadImgWin\', this.href); return false;" href="'.ADMINSCRIPT.'?action=cloud&operation=qqgroup&anchor=block&op=uploadImage&tid='.$tid.'" title="'.cplang('qqgroup_ctrl_upload_image').'">pic</a></li>
  258. <li class="e_del"><a href="javascript:;" title="'.cplang('qqgroup_ctrl_remove').'" onClick="removeTopicThread('.$tid.')">del</a></li>
  259. </ul>
  260. </div>
  261. <dl>
  262. <input type="hidden" name="topic[id]" value="'.$tid.'" />
  263. <input type="hidden" name="topic[displayorder]" value="0" />
  264. <input type="hidden" id="topic_image_value" name="topic[extra][image]" value="'.$imagePath.'" />
  265. <dt class="title"><input id="topic-editor-input-title" type="text" class="px tpx" name="topic[title]" value="'.str_replace(array('\\', '"'), array('&#92;', '&#34;'), $subject).'" onblur="blurTopic(this);" onClick="clickTopicEditor(\'title\');" /></dt>
  266. <dd class="thumb"><a onclick="clickTopicEditor(\'image\'); showWindow(\'uploadImgWin\', this.href); return false;" href="'.ADMINSCRIPT.'?action=cloud&operation=qqgroup&anchor=block&op=uploadImage&tid='.$tid.'" title="'.cplang('qqgroup_ctrl_upload_image').'"><img id="topic_editor_thumb" src="'.($imageUrl ? $imageUrl.'?'.rand() : 'static/image/admincp/cloud/thumb.png').'" alt="'.cplang('qqgroup_ctrl_upload_image').'" /></a></dd>
  267. <dd class="info">
  268. <textarea id="topic-editor-textarea-content" class="pt ipt" onblur="blurTopic(this);" onClick="clickTopicEditor(\'content\');" name="topic[extra][content]">'.$message.'</textarea>
  269. </dd>
  270. </dl>
  271. ';
  272. } else {
  273. $html = '
  274. <dl>
  275. <div class="tips">'.cplang('qqgroup_preview_tips_topic').'</div>
  276. </dl>
  277. ';
  278. }
  279. return $html;
  280. }
  281. function getNormalThread() {
  282. global $_G;
  283. $tid = intval($_GET['tid']);
  284. if(empty($tid)) {
  285. return false;
  286. }
  287. require_once libfile('function/forum');
  288. require_once libfile('function/discuzcode');
  289. loadforum();
  290. $subject = strip_tags($_G['thread']['subject']);
  291. $hasImage = $_G['thread']['attachment'] ? true : false;
  292. ajaxshowheader();
  293. echo showNormalTemplateLi($tid, $subject, $hasImage, true);
  294. ajaxshowfooter();
  295. }
  296. function showNormalTemplateLi($tid, $subject = '', $hasImage = false) {
  297. if ($tid) {
  298. $html = '
  299. <input type="hidden" class="normal_thread_tid" name="normal['.$tid.'][id]" value="'.$tid.'" />
  300. <input type="hidden" name="normal['.$tid.'][hasImage]" value="'.$hasImage.'" />
  301. <input class="preview_displayorder" type="hidden" name="normal['.$tid.'][displayorder]" value="" />
  302. <textarea class="pt" name="normal['.$tid.'][title]" onClick="clickNormalEditor(this);" onblur="blurNormalTextarea(this)">'.$subject.'</textarea>
  303. ';
  304. } else {
  305. $html = '
  306. <div class="tips">'.cplang('qqgroup_preview_tips_normal').'</div>
  307. ';
  308. }
  309. return $html;
  310. }
  311. function getMiniportalThreads() {
  312. $threads = array();
  313. $threads = C::t('common_setting')->fetch('cloud_qqgroup_miniportal_threads', true);
  314. $normalThreads = array();
  315. if($threads['normal']) {
  316. $i = 1;
  317. foreach($threads['normal'] as $tid => $normal) {
  318. $normal['displayorder'] = $i;
  319. $normalThreads[$i] = $normal;
  320. $i++;
  321. }
  322. }
  323. $threads['normalThreads'] = $normalThreads;
  324. return $threads;
  325. }
  326. function getResultThreads() {
  327. global $_G;
  328. $info = $_GET['info'];
  329. $info = dunserialize(base64_decode(trim($info)));
  330. if(!$info) {
  331. return false;
  332. }
  333. $threads = $info['threads'];
  334. if (!$threads) {
  335. return false;
  336. }
  337. $errorIds = $info['errorIds'];
  338. if (!$errorIds) {
  339. $errorIds = array();
  340. }
  341. if($threads['topic']['id'] && in_array($threads['topic']['id'], $errorIds)) {
  342. $threads['topic'] = array();
  343. }
  344. $normalThreads = array();
  345. if($threads['normal']) {
  346. $i = 1;
  347. foreach($threads['normal'] as $tid => $normal) {
  348. if (in_array($tid, $errorIds)) {
  349. unset($theads['normal'][$tid]);
  350. continue;
  351. } else {
  352. $normal['displayorder'] = $i;
  353. $normalThreads[$i] = $normal;
  354. $i++;
  355. }
  356. }
  357. }
  358. $threads['normalThreads'] = $normalThreads;
  359. return $threads;
  360. }
  361. function showSearchDiv() {
  362. echo '<div class="qqqun_bblist">';
  363. showSearchForm();
  364. showSearchResultDiv();
  365. echo '</div>';
  366. }
  367. function showSearchResultDiv() {
  368. echo '
  369. <table class="qqqun_tl">
  370. <tr>
  371. <th>'.cplang('qqgroup_search_threadslist').'</th>
  372. <th width="100">'.cplang('qqgroup_search_inforum').'</th>
  373. <th>'.cplang('qqgroup_search_operation').'</th>
  374. </tr>';
  375. echo '<tbody id="search_result"><tr><td colspan="3">'.cplang('qqgroup_search_loading').'</td></tr></tbody>';
  376. echo '</table>';
  377. }
  378. function showMiniportalPreview() {
  379. global $_G;
  380. if($_GET['sentResult'] && $_GET['info']) {
  381. $mcThreads = getResultThreads();
  382. } else {
  383. $mcThreads = getMiniportalThreads();
  384. }
  385. echo '<div id="qqqun">';
  386. echo '
  387. <div class="qqqun_title">
  388. <em><a href="#">'.cplang('qqgroup_preview_more').'</a></em>
  389. '.cplang('qqgroup_preview_shortname').'
  390. </div>
  391. ';
  392. showformheader('cloud&operation=qqgroup&anchor=block', '', 'previewForm');
  393. $topic = $mcThreads['topic'];
  394. $topicId = intval($topic['id']);
  395. echo '<div class="qqqun_top" id="topicDiv">'.showTopicTemplate($topicId, $topic['title'], $topic['extra']['content'], $topic['extra']['image'], $topic['extra']['image'] ? $_G['setting']['attachurl'].$topic['extra']['image'] : '').'</div>';
  396. echo '<div class="qqqun_list">';
  397. echo '
  398. <div class="qqqun_editor">
  399. <ul>
  400. <li class="e_up"><a href="javascript:;" onClick="moveNormalThread(true);" title="'.cplang('qqgroup_ctrl_up').'">up</a></li>
  401. <li class="e_down"><a href="javascript:;" onClick="moveNormalThread(false);" title="'.cplang('qqgroup_ctrl_down').'">down</a></li>
  402. <li class="e_edit"><a href="javascript:;" onClick="editNormalThread();" title="'.cplang('qqgroup_ctrl_edit').'">edit</a></li>
  403. <li class="e_del"><a href="javascript:;" onClick="removeNormalThread();" title="'.cplang('qqgroup_ctrl_remove').'">del</a></li>
  404. </ul>
  405. </div>
  406. ';
  407. echo '<ul class="qqqun_xl">';
  408. $normalIds = array();
  409. $normalThreads = $mcThreads['normalThreads'];
  410. for($i=1; $i<=5; $i++) {
  411. $normal = $normalThreads[$i];
  412. if($normal) {
  413. $normalIds[] = $normalThreads[$i]['id'];
  414. echo '<li id="normal_thread_'.$i.'" displayorder="'.$i.'">'.showNormalTemplateLi($normalThreads[$i]['id'], $normalThreads[$i]['title'], $normalThreads[$i]['extra']['hasImage']).'</li>';
  415. } else {
  416. if($i == 1) {
  417. echo '<li id="normal_thread_'.$i.'" displayorder="'.$i.'"><div class="tips">'.cplang('qqgroup_preview_tips_normal').'</div></li>';
  418. } else {
  419. echo '<li id="normal_thread_'.$i.'" displayorder="'.$i.'" style="display:none;"></li>';
  420. }
  421. }
  422. }
  423. echo '</ul>';
  424. echo '</div>';
  425. echo '
  426. <div class="qqqun_btn">
  427. <button id="previewFormSubmit" type="submit" class="btn"><span>'.cplang('qqgroup_preview_button').'</span></button>
  428. </div>
  429. ';
  430. echo '<input type="hidden" name="setMiniportalThreadsSubmit" value="1" />';
  431. showformfooter();
  432. echo '</div>';
  433. echo '
  434. <script type="text/javascript">
  435. var selectedTopicId = '.$topicId.';
  436. var selectedNormalIds = ['.implode(', ', $normalIds).'];
  437. </script>
  438. ';
  439. }
  440. function processMiniportalTopicThread($topic) {
  441. if(empty($topic)) {
  442. return false;
  443. }
  444. $id = intval($topic['id']);
  445. if(empty($id)) {
  446. return false;
  447. }
  448. $title = trim($topic['title']);
  449. if(!$title) {
  450. return false;
  451. }
  452. $displayorder = 0;
  453. $content = trim($topic['extra']['content']);
  454. if(!$content) {
  455. return false;
  456. }
  457. $extra = array('image' => strip_tags(trim($topic['extra']['image'])), 'content' => $content);
  458. $newTopic = array('id' => $id, 'idtype' => 1, 'miniportaltype' => 2, 'title' => $title, 'extra' => $extra, 'displayorder' => $displayorder, 'dateline' => TIMESTAMP);
  459. return $newTopic;
  460. }
  461. function processMiniportalNormalThreads($normal) {
  462. $newNormal = array();
  463. $i = 0;
  464. foreach($normal as $thread) {
  465. $thread = processlNormalThread($thread);
  466. if($thread && $thread['id']) {
  467. $i ++;
  468. $thread['displayorder'] = $i;
  469. $newNormal[$thread['id']] = $thread;
  470. }
  471. }
  472. return $newNormal;
  473. }
  474. function processlNormalThread($thread) {
  475. if(empty($thread)) {
  476. return false;
  477. }
  478. $id = intval($thread['id']);
  479. if(empty($id)) {
  480. return false;
  481. }
  482. $title = trim($thread['title']);
  483. if(!$title) {
  484. return false;
  485. }
  486. $displayorder = intval($thread['displayorder']);
  487. $hasImage = $thread['extra']['hasImage'] ? true : false;
  488. $extra = array('hasImage' => $hasImage);
  489. $newThread = array('id' => $id, 'idtype' => 1, 'miniportaltype' => 1, 'title' => $title, 'extra' => $extra, 'displayorder' => $displayorder, 'dateline' => TIMESTAMP);
  490. return $newThread;
  491. }
  492. function storeMiniportalThreads($threads) {
  493. return C::t('common_setting')->update('cloud_qqgroup_miniportal_threads', $threads);
  494. }
  495. function sentMiniportalThreadsRemote($topic, $normal, $gIds = array()) {
  496. global $_G;
  497. if($topic['extra']['image'] && $topic['extra']['image'] = @file_get_contents($_G['setting']['attachdir'].'./'.$topic['extra']['image'])) {
  498. $topic['extra']['image'] = base64_encode($topic['extra']['image']);
  499. }
  500. $groupClient = Cloud::loadClass('Service_Client_QQGroup');
  501. try {
  502. $res = $groupClient->miniportal($topic, $normal, $gIds);
  503. } catch (Cloud_Service_Client_RestfulException $e) {
  504. if ($e->getCode() == 1) {
  505. $res = array('status' => false, 'msg' => cplang('qqgroup_msg_unknown_dns'));
  506. } else {
  507. $res = array('status' => false, 'msg' => cplang('qqgroup_msg_remote_exception', array('errmsg' => $e->getMessage(), 'errno' => $e->getCode())));
  508. }
  509. }
  510. if(!is_array($res)) {
  511. $res = array('status' => false, 'msg' => cplang('qqgroup_msg_remote_error'));
  512. }
  513. return $res;
  514. }
  515. function showUploadImageForm($tid) {
  516. ajaxshowheader();
  517. echo '
  518. <ul class="fwin-menu">
  519. <li class="a"><a>'.cplang('qqgroup_ctrl_upload_image').'</a></li>
  520. <li style="float:right;"><a class="flbc" href="javascript:;" onClick="hideWindow(\'uploadImgWin\')" title="'.cplang('qqgroup_ctrl_close').'">'.cplang('qqgroup_ctrl_close').'</a></li>
  521. </ul>
  522. ';
  523. echo '<div class="c">';
  524. showformheader('cloud&operation=qqgroup&anchor=block&op=uploadImage', 'enctype="multipart/form-data"', 'uploadImage');
  525. echo '<input type="hidden" name="tid" value="'.$tid.'" />';
  526. echo '<input type="hidden" name="uploadImageSubmit" value="1" />';
  527. echo '
  528. <table class="tb">
  529. <tr style="display:none;">
  530. <td id="uploadImageResult" colspan="2" align="center"></td>
  531. </tr>
  532. <tr>
  533. <td width="70" align="right">'.cplang('qqgroup_ctrl_choose_image').'</td>
  534. <td align="left"><input type="file" name="imageFile" size="30" /></td>
  535. </tr>
  536. <tr>
  537. <td align="right"></td>
  538. <td align="left">
  539. <p>'.cplang('qqgroup_ctrl_choose_image_tips').'</p>
  540. </td>
  541. </tr>
  542. </table>
  543. ';
  544. showformfooter();
  545. echo '</div>';
  546. echo '
  547. <div class="o pns"><button class="pn pnc" onClick="ajaxUploadQQGroupImage();"><span>'.cplang('qqgroup_ctrl_upload_image').'</span></button></div>
  548. ';
  549. ajaxshowfooter();
  550. }
  551. function QQGroupUpload($tid) {
  552. global $_G;
  553. $imageDir = 'qqgroup';
  554. $imageName = 'miniportal_tid_'.$tid.'.jpg';
  555. $fieldName = 'imageFile';
  556. $_FILES[$fieldName]['name'] = addslashes(urldecode($_FILES[$fieldName]['name']));
  557. $_FILES[$fieldName]['type'] = addslashes(urldecode($_FILES[$fieldName]['type']));
  558. $upload = new discuz_upload();
  559. $upload->init($_FILES[$fieldName]);
  560. $attach = & $upload->attach;
  561. if (!$attach['isimage']) {
  562. return false;
  563. }
  564. if ($attach['size'] > 5000000) {
  565. return false;
  566. }
  567. $upload->save();
  568. list($imgwidth, $imgheight) = $attach['imageinfo'];
  569. if($imgwidth < 75 || $imgheight < 75) {
  570. @unlink($attach['target']);
  571. return false;
  572. }
  573. require_once libfile('class/image');
  574. $image = new image;
  575. $image->param['thumbquality'] = 100;
  576. $thumbTarget = $imageDir.'/'.$imageName;
  577. @unlink($_G['setting']['attachdir'].'./'.$thumbTarget);
  578. $thumb = $image->Thumb($attach['target'], $thumbTarget, 75, 75) ? 1 : 0;
  579. if(!$thumb && !@copy($attach['target'], $_G['setting']['attachdir'].'./'.$thumbTarget)) {
  580. @unlink($attach['target']);
  581. return false;
  582. }
  583. @unlink($attach['target']);
  584. $res = $attach;
  585. $res['thumbTarget'] = $thumbTarget;
  586. return $res;
  587. }
  588. function showQQGroupScript() {
  589. global $adminscript;
  590. echo
  591. <<<EOF
  592. <script type="text/javascript" src="static/image/admincp/cloud/jquery.min.js"></script>
  593. <script type="text/javascript">
  594. var adminscript = '$adminscript';
  595. </script>
  596. <script type="text/javascript" src="static/image/admincp/cloud/qqgroup.js?v=20121101"></script>
  597. EOF;
  598. }
  599. function showQQGroupCSS() {
  600. echo
  601. <<<EOF
  602. <link href="static/image/admincp/cloud/qqgroup.css" rel="stylesheet" type="text/css" />
  603. EOF;
  604. }
  605. function QQGroupMessage($message, $url = '', $info = '') {
  606. if($url) {
  607. $url = addcslashes(substr($url, 0, 5) == 'http:' ? $url : ADMINSCRIPT . '?' . $url, '\'');
  608. }
  609. if($info) {
  610. $info = base64_encode(serialize($info));
  611. }
  612. $message = "<h4 class=\"infotitle3\">$message</h4>";
  613. $message .= '<form id="qqgroup_message_form" action="'.$url.'" method="POST" style="display:none;">';
  614. $message .= '<textarea name="info" style="display:none;">'.$info.'</textarea>';
  615. $message .= '</form>';
  616. $message .= '<p class="marginbot"><a href="javascript:;" onClick="$(\'qqgroup_message_form\').submit();" class="lightlink">'.cplang('message_return').'</a></p>';
  617. echo '<h3>'.cplang('discuz_message').'</h3><div class="infobox">'.$message.'</div>';
  618. exit();
  619. }