cloud_connect.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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_connect.php 33756 2013-08-10 06:32:48Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. $utilService = Cloud::loadClass('Service_Util');
  12. $connectService = Cloud::loadClass('Service_Connect');
  13. $op = $_GET['op'];
  14. $signUrl = $utilService->generateSiteSignUrl();
  15. $_GET['anchor'] = in_array($_GET['anchor'], array('setting', 'service')) ? $_GET['anchor'] : 'setting';
  16. $current = array($_GET['anchor'] => 1);
  17. $connectnav = array();
  18. $connectnav[0] = array('connect_menu_setting', 'cloud&operation=connect&anchor=setting', $current['setting']);
  19. $connectnav[1] = array('connect_menu_service', 'cloud&operation=connect&anchor=service', $current['service']);
  20. if (!$_G['inajax']) {
  21. cpheader();
  22. }
  23. if($_GET['anchor'] == 'service') {
  24. $utilService->redirect($cloudDomain.'/connect/service/?' . $signUrl);
  25. } elseif ($_GET['anchor'] == 'setting') {
  26. $setting = C::t('common_setting')->fetch_all(array('extcredits', 'connect', 'connectsiteid', 'connectsitekey', 'regconnect'));
  27. $setting['connect'] = (array)dunserialize($setting['connect']);
  28. if(!submitcheck('connectsubmit')) {
  29. shownav('navcloud', 'menu_setting_qqconnect');
  30. include_once libfile('function/forumlist');
  31. $forumselect = array();
  32. $forumselect['t'] = '<select name="connectnew[t][fids][]" multiple="multiple" size="10">'.forumselect(FALSE, 0, 0, TRUE).'</select>';
  33. if($setting['connect']['t']['fids']) {
  34. foreach($setting['connect']['t']['fids'] as $v) {
  35. $forumselect['t'] = str_replace('<option value="'.$v.'">', '<option value="'.$v.'" selected>', $forumselect['t']);
  36. }
  37. }
  38. $connectrewardcredits = $connectgroup = $connectguestgroup = '';
  39. $setting['extcredits'] = dunserialize($setting['extcredits']);
  40. for($i = 0; $i <= 8; $i++) {
  41. if($setting['extcredits'][$i]['available']) {
  42. $extcredit = 'extcredits'.$i.' ('.$setting['extcredits'][$i]['title'].')';
  43. $connectrewardcredits .= '<option value="'.$i.'" '.($i == intval($setting['connect']['register_rewardcredit']) ? 'selected' : '').'>'.($i ? $extcredit : $lang['none']).'</option>';
  44. }
  45. }
  46. $groups = C::t('common_usergroup')->fetch_all_by_type('special');
  47. foreach($groups as $group) {
  48. $connectgroup .= "<option value=\"$group[groupid]\" ".($group['groupid'] == $setting['connect']['register_groupid'] ? 'selected' : '').">$group[grouptitle]</option>\n";
  49. $connectguestgroup .= "<option value=\"$group[groupid]\" ".($group['groupid'] == $setting['connect']['guest_groupid'] ? 'selected' : '').">$group[grouptitle]</option>\n";
  50. }
  51. showformheader('cloud&operation=connect');
  52. showtableheader();
  53. showsetting('connect_setting_allow', 'connectnew[allow]', $setting['connect']['allow'], 'radio', 0, 1);
  54. showsetting('setting_access_guest_connect_group', '', '', '<select name="connectnew[guest_groupid]"><option value="0">'.$lang['usergroups_system_0'].'</option>'.$connectguestgroup.'</select>');
  55. showsetting('setting_access_register_connect_birthday', 'connectnew[register_birthday]', $setting['connect']['register_birthday'], 'radio');
  56. showsetting('setting_access_register_connect_gender', 'connectnew[register_gender]', $setting['connect']['register_gender'], 'radio');
  57. showsetting('setting_access_register_connect_uinlimit', 'connectnew[register_uinlimit]', $setting['connect']['register_uinlimit'], 'text');
  58. showsetting('setting_access_register_connect_credit', '', '', '<select name="connectnew[register_rewardcredit]">'.$connectrewardcredits.'</select>');
  59. showsetting('setting_access_register_connect_addcredit', 'connectnew[register_addcredit]', $setting['connect']['register_addcredit'], 'text');
  60. showsetting('setting_access_register_connect_group', '', '', '<select name="connectnew[register_groupid]"><option value="0">'.$lang['usergroups_system_0'].'</option>'.$connectgroup.'</select>');
  61. showsetting('setting_access_register_connect_regverify', 'connectnew[register_regverify]', $setting['connect']['register_regverify'], 'radio');
  62. showsetting('setting_access_register_connect_invite', 'connectnew[register_invite]', $setting['connect']['register_invite'], 'radio');
  63. showsetting('setting_access_register_connect_newbiespan', 'connectnew[newbiespan]', $setting['connect']['newbiespan'], 'text');
  64. showtagfooter('tbody');
  65. showsubmenu('menu_cloud_connect', $connectnav);
  66. showsetting('connect_setting_t_allow', 'connectnew[t][allow]', $setting['connect']['t']['allow'], 'radio', 0, 1);
  67. showsetting('connect_setting_t_fids', '', '', $forumselect['t']);
  68. showsetting('connect_setting_t_group', 'connectnew[t][group]', $setting['connect']['t']['group'], 'radio');
  69. showsetting('connect_setting_t_reply', 'connectnew[t][reply]', $setting['connect']['t']['reply'], 'radio');
  70. showsetting('connect_setting_t_reply_showauthor', 'connectnew[t][reply_showauthor]', $setting['connect']['t']['reply_showauthor'], 'radio');
  71. showtagfooter('tbody');
  72. showsetting('connect_setting_like_allow', 'connectnew[like_allow]', $setting['connect']['like_allow'], 'radio', 0, 1);
  73. showsetting('connect_setting_like_url', 'connectnew[like_qq]', $setting['connect']['like_qq'], 'text');
  74. showtagfooter('tbody');
  75. showsetting('connect_setting_turl_allow', 'connectnew[turl_allow]', $setting['connect']['turl_allow'], 'radio', 0, 1);
  76. showsetting('connect_setting_turl_qq', 'connectnew[turl_qq]', $setting['connect']['turl_qq'], 'text');
  77. showtagfooter('tbody');
  78. showsetting('connect_setting_qshare_allow', 'connectnew[qshare_allow]', $setting['connect']['qshare_allow'], 'radio', 0, 1);
  79. showtagfooter('tbody');
  80. showsetting('connect_setting_weibo_appkey', 'connectnew[qshare_appkey]', $setting['connect']['qshare_appkey'], 'text');
  81. showtagfooter('tbody');
  82. showsubmit('connectsubmit');
  83. showtablefooter();
  84. showformfooter();
  85. } else {
  86. if($_GET['connectnew']['turl_qq'] && !is_numeric($_GET['connectnew']['turl_qq'])) {
  87. cpmsg('connect_setting_turl_qq_failed', '', 'error');
  88. }
  89. if($_GET['connectnew']['like_url']) {
  90. $url = parse_url($_GET['connectnew']['like_url']);
  91. if(!preg_match('/\.qq\.com$/i', $url['host'])) {
  92. cpmsg('connect_like_url_error', '', 'error');
  93. }
  94. }
  95. if($_GET['connectnew']['like_allow'] && $_GET['connectnew']['like_url'] === '') {
  96. cpmsg('connect_like_url_miss', '', 'error');
  97. }
  98. $_GET['connectnew'] = array_merge($setting['connect'], $_GET['connectnew']);
  99. $_GET['connectnew']['like_url'] = $_GET['connectnew']['like_qq'] ? 'http://open.qzone.qq.com/like?url=http%3A%2F%2Fuser.qzone.qq.com%2F'.$_GET['connectnew']['like_qq'].'&width=100&height=21&type=button_num' : '';
  100. $_GET['connectnew']['turl_code'] = '';
  101. $connectnew = serialize($_GET['connectnew']);
  102. $regconnectnew = !$setting['connect']['allow'] && $_GET['connectnew']['allow'] ? 1 : $setting['regconnect'];
  103. C::t('common_setting')->update_batch(array('regconnect' => $regconnectnew, 'connect' => $connectnew));
  104. $connectClient = Cloud::loadClass('Service_Client_Connect');
  105. try {
  106. $res = $connectClient->sync($_GET['connectnew']['like_qq'], $_GET['connectnew']['turl_qq']);
  107. } catch (Cloud_Service_Client_RestfulException $e) {
  108. $res = array('status' => false, 'msg' => cplang('qqgroup_msg_remote_exception', array('errmsg' => $e->getMessage(), 'errno' => $e->getCode())));
  109. }
  110. if(!is_array($res)) {
  111. $res = array('status' => false, 'msg' => 'qqgroup_msg_remote_error');
  112. }
  113. if($res['mblogCode']) {
  114. $_GET['connectnew']['turl_code'] = $res['mblogCode'];
  115. $connectnew = serialize($_GET['connectnew']);
  116. C::t('common_setting')->update('connect', $connectnew);
  117. }
  118. updatecache(array('setting', 'fields_register', 'fields_connect_register'));
  119. cpmsg('connect_update_succeed', 'action=cloud&operation=connect', 'succeed');
  120. }
  121. }