generateSiteSignUrl(array('v' => 2));
$_GET['anchor'] = in_array($_GET['anchor'], array('block', 'list', 'info', 'setting')) ? $_GET['anchor'] : 'block';
if ($_GET['first']) {
$_GET['anchor'] = 'list';
}
$current = array($_GET['anchor'] => 1);
$qqgroupnav = array();
$qqgroupnav[0] = array('qqgroup_menu_block', 'cloud&operation=qqgroup&anchor=block', $current['block']);
$qqgroupnav[1] = array('qqgroup_menu_list', 'cloud&operation=qqgroup&anchor=list', $current['list']);
$qqgroupnav[2] = array('qqgroup_menu_manager', 'cloud&operation=qqgroup&anchor=info', $current['info']);
$qqgroupnav[3] = array('qqgroup_menu_setting', 'cloud&operation=qqgroup&anchor=setting', $current['setting']);
if (!$_G['inajax']) {
cpheader();
}
if($_GET['anchor'] == 'list') {
$utilService->redirect($cloudDomain.'/qun/list/?' . $signUrl);
} elseif($_GET['anchor'] == 'info') {
$utilService->redirect($cloudDomain.'/qun/siteInfo/?' . $signUrl);
} elseif($_GET['anchor'] == 'setting') {
if(submitcheck('settingsubmit')) {
$usergroups = $_POST['groupid'];
$updateData = array(
'qqgroup_usergroup_feed_list' => serialize($usergroups),
);
C::t('common_setting')->update_batch($updateData);
updatecache('setting');
cpmsg('setting_update_succeed', 'action=cloud&operation=qqgroup&anchor='.$_GET['anchor'], 'succeed');
} else {
$usergroupsfeedlist = unserialize($_G['setting']['qqgroup_usergroup_feed_list']);
$groupselect = array();
foreach (C::t('common_usergroup')->fetch_all_by_radminid(0) as $group) {
$group['type'] = $group['type'] == 'special' && $group['radminid'] ? 'specialadmin' : $group['type'];
$groupselect[$group['type']] .= "\n";
}
$groupselect = ($groupselect['special'] ? '' : '').
($groupselect['specialadmin'] ? '' : '').
'';
shownav('navcloud', 'menu_cloud_qqgroup');
showsubmenu('menu_cloud_qqgroup', $qqgroupnav);
showtips('qqgroup_setting_tips');
showformheader('cloud&operation=qqgroup&anchor=setting');
showtableheader('qqgroup_feed_setting', '', '', 2);
showsetting('qqgroup_usergroup_feed_list', '', '', '');
showsubmit('settingsubmit');
showtablefooter();
showformfooter();
}
} elseif($_GET['anchor'] == 'block') {
$perpage = 10;
$maxPage = 10;
$page = intval($_GET['page']);
$page = MAX($page, 1);
$page = MIN($page, $maxPage);
$prevPage = MAX($page - 1, 1);
$nextPage = MIN($page + 1, $maxPage);
if(submitcheck('setMiniportalThreadsSubmit')) {
$topic = $_GET['topic'];
$topic = processMiniportalTopicThread($topic);
if(!$topic) {
cpmsg('qqgroup_msg_deficiency', '', 'error');
}
$normal = $_GET['normal'];
$normal = processMiniportalNormalThreads($normal);
if(!$normal) {
cpmsg('qqgroup_msg_deficiency', '', 'error');
}
$serverResult = sentMiniportalThreadsRemote($topic, $normal);
$threads = array('topic' => $topic, 'normal' => $normal);
if($serverResult['status']) {
storeMiniportalThreads($threads);
cpmsg('qqgroup_msg_save_succeed', 'action=cloud&operation=qqgroup&anchor=block', 'succeed');
} else {
$info = array('threads' => $threads, 'errorIds' => $serverResult['errorIds']);
QQGroupMessage($serverResult['msg'], 'action=cloud&operation=qqgroup&anchor=block&sentResult=1', $info);
}
} elseif($op == 'getTopicThread') {
getTopicThread();
} elseif($op == 'getNormalThread') {
getNormalThread();
} elseif($op == 'uploadImage') {
$tid = intval($_GET['tid']);
if (submitcheck('uploadImageSubmit')) {
ajaxshowheader();
if($uploadImage = QQGroupUpload($tid)) {
echo '
'.cplang('qqgroup_msg_upload_succeed').'
'.$uploadImage['thumbTarget'].'
'.$_G['setting']['attachurl'].$uploadImage['thumbTarget'].'
';
} else {
echo ''.cplang('qqgroup_msg_upload_failure').'
';
}
ajaxshowfooter();
} else {
showUploadImageForm($tid);
}
} elseif($op == 'searchForm') {
showSearchThreads();
} else {
shownav('navcloud', 'menu_cloud_qqgroup');
showsubmenu('menu_cloud_qqgroup', $qqgroupnav);
echo '';
showQQGroupCSS();
showSearchDiv();
showMiniportalPreview();
showQQGroupScript();
}
}
function showSearchForm() {
require_once libfile('function/forumlist');
showformheader('cloud&operation=qqgroup&anchor=block&op=searchForm', 'onSubmit="ajaxGetSearchResultThreads(); return false;"', 'search_form');
showtableheader();
$orderoptions = array('views', 'replies', 'heats', 'dateline', 'lastpost', 'recommends');
$orderoption = '';
foreach($orderoptions as $value) {
$orderoption .= '';
}
$datelineoptions = array(1, 2, 3, 4);
$datelineoption = '';
foreach($datelineoptions as $value) {
$datelineoption .= '';
}
echo '
|
|
|
|
|
';
showtablefooter();
showformfooter();
}
function showSearchThreads() {
global $_G, $page, $perpage;;
$threads = array();
$starttime = 0;
$srchtid = intval($_GET['srchtid']);
$srchorder = in_array($_GET['srchorder'], array('views', 'replies', 'heats', 'dateline', 'lastpost')) ? $_GET['srchorder'] : 'dateline';
$datelinearray = array(1 => 3600, 2 => 86400, 3 => 86400 * 7, 4 => 86400 * 30);
$srchdateline = array_key_exists($_GET['srchdateline'], $datelinearray) ? $datelinearray[$_GET['srchdateline']] : 86400 * 30;
$start = ($page - 1) * $perpage;
if($srchtid) {
$threads = C::t('forum_thread')->fetch_all_by_tid_displayorder($srchtid, 0);
} else {
$starttime = TIMESTAMP - $srchdateline;
$threads = C::t('forum_thread')->fetch_all_by_dateline($starttime, $start, $perpage, $srchorder);
}
$mpurl = ADMINSCRIPT.'?action=cloud&operation=qqgroup&anchor=block&op=searchForm'
.'&srchtid='.$srchtid.'&srchorder='.$srchorder.'&srchdateline='.intval($_GET['srchdateline']);
return showSearchResultThreads($threads, $mpurl);
}
function showSearchResultThreads($threads, $mpurl) {
global $_G;
$threadsOutput = '';
loadcache('forums');
if(empty($threads)) {
$threadsOutput = '
'.cplang('qqgroup_search_nothreads').' |
';
} else {
foreach($threads as $thread) {
$thread['subject'] = strip_tags($thread['subject']);
$threadsOutput .= '
'.cutstr($thread['subject'], 45).($thread['attachment'] == 2 ? ' ' : '').' |
'.cutstr(dhtmlspecialchars(strip_tags($_G['cache']['forums'][$thread['fid']]['name'])), 14, '').' |
toplist |
';
}
}
ajaxshowheader();
echo $threadsOutput;
showSearchResultPageLinks(count($threads), $mpurl);
ajaxshowfooter();
}
function showSearchResultPageLinks($num = 0, $mpurl) {
global $_G, $page, $perpage, $maxPage;
$needNext = $page < $maxPage && $num == $perpage ? true : false;
if ($pageLink = QQGroupSearchSimplePage($needNext, $page, $mpurl)) {
echo ''.$pageLink.' |
';
}
}
function QQGroupSearchSimplePage($needNext, $curpage, $mpurl) {
global $prevPage, $nextPage;
$return = '';
$lang['next'] = lang('core', 'nextpage');
$lang['prev'] = lang('core', 'prevpage');
$searchThreadsRule = 'ajaxGetPageResultThreads(\'%s\', \'%s\');';
$prevClickFunc = addcslashes(sprintf($searchThreadsRule, $prevPage, dhtmlspecialchars($mpurl)), '"');
$nextClickFunc = addcslashes(sprintf($searchThreadsRule, $nextPage, dhtmlspecialchars($mpurl)), '"');
$prev = $curpage > 1 ? ''.$lang['prev'].'' : '';
$next = $needNext ? ''.$lang['next'].'' : '';
if($next || $prev) {
$return = $prev.$next;
}
return $return;
}
function getTopicThread() {
global $_G;
$tid = intval($_GET['tid']);
if(empty($tid)) {
ajaxshowheader();
echo showTopicTemplate(0);
ajaxshowfooter();
return false;
}
require_once libfile('function/forum');
require_once libfile('function/discuzcode');
loadforum();
$posttable = $_G['thread']['posttable'];
if(empty($posttable)) {
ajaxshowheader();
echo showTopicTemplate(0);
ajaxshowfooter();
return false;
}
$imagePath = $imageUrl = '';
$subject = strip_tags($_G['thread']['subject']);
$post = C::t('forum_post')->fetch_threadpost_by_tid_invisible($tid);
$pid = intval($post['pid']);
$message = cutstr(strip_tags(discuzcode($post['message'], 1, 0, 1)), 200);
$message = preg_replace('/\[attach\](\d+)\[\/attach\]/is', '', $message);
$imageDir = 'qqgroup';
$imageName = 'miniportal_tid_'.$tid.'.jpg';
$thumbTarget = $imageDir.'/'.$imageName;
if(file_exists($_G['setting']['attachdir'].'./'.$thumbTarget)) {
$imagePath = $thumbTarget;
$imageUrl = $_G['setting']['attachurl'].$imagePath;
} else {
$attachments = C::t('forum_attachment_n')->fetch_all_by_id('tid:' . $tid, 'pid', $pid, '', array('-1', '1'), false, 0, 1);
if($attachments && $attachment = reset($attachments)) {
$imagePath = 'forum/'.$attachment['attachment'];
$imageUrl = $_G['setting']['attachurl'].$imagePath;
}
}
ajaxshowheader();
echo showTopicTemplate($tid, $subject, $message, $imagePath, $imageUrl);
ajaxshowfooter();
}
function showTopicTemplate($tid, $subject = '', $message = '', $imagePath = '', $imageUrl = '') {
$html = '';
if ($tid) {
$html .= '
-
';
} else {
$html = '
'.cplang('qqgroup_preview_tips_topic').'
';
}
return $html;
}
function getNormalThread() {
global $_G;
$tid = intval($_GET['tid']);
if(empty($tid)) {
return false;
}
require_once libfile('function/forum');
require_once libfile('function/discuzcode');
loadforum();
$subject = strip_tags($_G['thread']['subject']);
$hasImage = $_G['thread']['attachment'] ? true : false;
ajaxshowheader();
echo showNormalTemplateLi($tid, $subject, $hasImage, true);
ajaxshowfooter();
}
function showNormalTemplateLi($tid, $subject = '', $hasImage = false) {
if ($tid) {
$html = '
';
} else {
$html = '
'.cplang('qqgroup_preview_tips_normal').'
';
}
return $html;
}
function getMiniportalThreads() {
$threads = array();
$threads = C::t('common_setting')->fetch('cloud_qqgroup_miniportal_threads', true);
$normalThreads = array();
if($threads['normal']) {
$i = 1;
foreach($threads['normal'] as $tid => $normal) {
$normal['displayorder'] = $i;
$normalThreads[$i] = $normal;
$i++;
}
}
$threads['normalThreads'] = $normalThreads;
return $threads;
}
function getResultThreads() {
global $_G;
$info = $_GET['info'];
$info = dunserialize(base64_decode(trim($info)));
if(!$info) {
return false;
}
$threads = $info['threads'];
if (!$threads) {
return false;
}
$errorIds = $info['errorIds'];
if (!$errorIds) {
$errorIds = array();
}
if($threads['topic']['id'] && in_array($threads['topic']['id'], $errorIds)) {
$threads['topic'] = array();
}
$normalThreads = array();
if($threads['normal']) {
$i = 1;
foreach($threads['normal'] as $tid => $normal) {
if (in_array($tid, $errorIds)) {
unset($theads['normal'][$tid]);
continue;
} else {
$normal['displayorder'] = $i;
$normalThreads[$i] = $normal;
$i++;
}
}
}
$threads['normalThreads'] = $normalThreads;
return $threads;
}
function showSearchDiv() {
echo '';
showSearchForm();
showSearchResultDiv();
echo '
';
}
function showSearchResultDiv() {
echo '
'.cplang('qqgroup_search_threadslist').' |
'.cplang('qqgroup_search_inforum').' |
'.cplang('qqgroup_search_operation').' |
';
echo ''.cplang('qqgroup_search_loading').' |
';
echo '
';
}
function showMiniportalPreview() {
global $_G;
if($_GET['sentResult'] && $_GET['info']) {
$mcThreads = getResultThreads();
} else {
$mcThreads = getMiniportalThreads();
}
echo '';
echo '
';
showformheader('cloud&operation=qqgroup&anchor=block', '', 'previewForm');
$topic = $mcThreads['topic'];
$topicId = intval($topic['id']);
echo '
'.showTopicTemplate($topicId, $topic['title'], $topic['extra']['content'], $topic['extra']['image'], $topic['extra']['image'] ? $_G['setting']['attachurl'].$topic['extra']['image'] : '').'
';
echo '
';
echo '
';
echo '
';
echo '
';
echo '
';
echo '
';
showformfooter();
echo '
';
echo '
';
}
function processMiniportalTopicThread($topic) {
if(empty($topic)) {
return false;
}
$id = intval($topic['id']);
if(empty($id)) {
return false;
}
$title = trim($topic['title']);
if(!$title) {
return false;
}
$displayorder = 0;
$content = trim($topic['extra']['content']);
if(!$content) {
return false;
}
$extra = array('image' => strip_tags(trim($topic['extra']['image'])), 'content' => $content);
$newTopic = array('id' => $id, 'idtype' => 1, 'miniportaltype' => 2, 'title' => $title, 'extra' => $extra, 'displayorder' => $displayorder, 'dateline' => TIMESTAMP);
return $newTopic;
}
function processMiniportalNormalThreads($normal) {
$newNormal = array();
$i = 0;
foreach($normal as $thread) {
$thread = processlNormalThread($thread);
if($thread && $thread['id']) {
$i ++;
$thread['displayorder'] = $i;
$newNormal[$thread['id']] = $thread;
}
}
return $newNormal;
}
function processlNormalThread($thread) {
if(empty($thread)) {
return false;
}
$id = intval($thread['id']);
if(empty($id)) {
return false;
}
$title = trim($thread['title']);
if(!$title) {
return false;
}
$displayorder = intval($thread['displayorder']);
$hasImage = $thread['extra']['hasImage'] ? true : false;
$extra = array('hasImage' => $hasImage);
$newThread = array('id' => $id, 'idtype' => 1, 'miniportaltype' => 1, 'title' => $title, 'extra' => $extra, 'displayorder' => $displayorder, 'dateline' => TIMESTAMP);
return $newThread;
}
function storeMiniportalThreads($threads) {
return C::t('common_setting')->update('cloud_qqgroup_miniportal_threads', $threads);
}
function sentMiniportalThreadsRemote($topic, $normal, $gIds = array()) {
global $_G;
if($topic['extra']['image'] && $topic['extra']['image'] = @file_get_contents($_G['setting']['attachdir'].'./'.$topic['extra']['image'])) {
$topic['extra']['image'] = base64_encode($topic['extra']['image']);
}
$groupClient = Cloud::loadClass('Service_Client_QQGroup');
try {
$res = $groupClient->miniportal($topic, $normal, $gIds);
} catch (Cloud_Service_Client_RestfulException $e) {
if ($e->getCode() == 1) {
$res = array('status' => false, 'msg' => cplang('qqgroup_msg_unknown_dns'));
} else {
$res = array('status' => false, 'msg' => cplang('qqgroup_msg_remote_exception', array('errmsg' => $e->getMessage(), 'errno' => $e->getCode())));
}
}
if(!is_array($res)) {
$res = array('status' => false, 'msg' => cplang('qqgroup_msg_remote_error'));
}
return $res;
}
function showUploadImageForm($tid) {
ajaxshowheader();
echo '
';
echo '';
showformheader('cloud&operation=qqgroup&anchor=block&op=uploadImage', 'enctype="multipart/form-data"', 'uploadImage');
echo '
';
echo '
';
echo '
';
showformfooter();
echo '
';
echo '
';
ajaxshowfooter();
}
function QQGroupUpload($tid) {
global $_G;
$imageDir = 'qqgroup';
$imageName = 'miniportal_tid_'.$tid.'.jpg';
$fieldName = 'imageFile';
$_FILES[$fieldName]['name'] = addslashes(urldecode($_FILES[$fieldName]['name']));
$_FILES[$fieldName]['type'] = addslashes(urldecode($_FILES[$fieldName]['type']));
$upload = new discuz_upload();
$upload->init($_FILES[$fieldName]);
$attach = & $upload->attach;
if (!$attach['isimage']) {
return false;
}
if ($attach['size'] > 5000000) {
return false;
}
$upload->save();
list($imgwidth, $imgheight) = $attach['imageinfo'];
if($imgwidth < 75 || $imgheight < 75) {
@unlink($attach['target']);
return false;
}
require_once libfile('class/image');
$image = new image;
$image->param['thumbquality'] = 100;
$thumbTarget = $imageDir.'/'.$imageName;
@unlink($_G['setting']['attachdir'].'./'.$thumbTarget);
$thumb = $image->Thumb($attach['target'], $thumbTarget, 75, 75) ? 1 : 0;
if(!$thumb && !@copy($attach['target'], $_G['setting']['attachdir'].'./'.$thumbTarget)) {
@unlink($attach['target']);
return false;
}
@unlink($attach['target']);
$res = $attach;
$res['thumbTarget'] = $thumbTarget;
return $res;
}
function showQQGroupScript() {
global $adminscript;
echo
<<
EOF;
}
function showQQGroupCSS() {
echo
<<
EOF;
}
function QQGroupMessage($message, $url = '', $info = '') {
if($url) {
$url = addcslashes(substr($url, 0, 5) == 'http:' ? $url : ADMINSCRIPT . '?' . $url, '\'');
}
if($info) {
$info = base64_encode(serialize($info));
}
$message = "$message
";
$message .= '';
$message .= ''.cplang('message_return').'
';
echo ''.cplang('discuz_message').'
'.$message.'
';
exit();
}