cachelist = $cachelist;
$discuz->init_cron = false;
$discuz->init_setting = true;
$discuz->init_user = false;
$discuz->init_session = false;
$discuz->init();
$google = new GoogleAPI($discuz);
$google->run();
class GoogleAPI
{
var $core;
var $version = '2.0.0';
function GoogleAPI(&$core) {
$this->core = &$core;
}
function run() {
$this->authcheck();
$method = 'on_'.getgpc('a');
if(method_exists($this, $method)) {
$this->xmlheader();
$this->$method();
$this->xmlfooter();
} else {
$this->error('Unknow command');
}
}
function authcheck() {
$siteuniqueid = C::t('common_setting')->fetch('siteuniqueid');
$auth = md5($siteuniqueid.'DISCUZ*COMSENZ*GOOGLE*API'.substr(time(), 0, 6));
if($auth != getgpc('s')) {
$this->error('Access error');
}
}
function error($message) {
$this->xmlheader();
echo "".$message."";
$this->xmlfooter();
}
function result($message = 'success') {
$this->xmlheader();
echo "".$message."";
$this->xmlfooter();
}
function xmlheader() {
static $isshowed;
if(!$isshowed) {
@header("Content-type: application/xml");
echo "\n\n";
echo "Discuz! API For Google Function\n";
echo "{$this->version}\n";
$isshowed = true;
}
return true;
}
function xmlfooter($halt = true) {
echo "\n\n";
$halt && exit();
}
function on_on() {
C::t('common_setting')->update('google', 1);
$this->result();
}
function on_off() {
C::t('common_setting')->update('google', 0);
$this->result();
}
function on_gtt() {
global $_G;
$tids = explode(',', getgpc('t'));
$msg = getgpc('msg') ? true : false;
$att = getgpc('att') ? true : false;
$posts = getgpc('post') ? explode(',', getgpc('post')) : array();
if($posts) {
$posts[0] = intval($posts[0]);
$posts[1] = intval($posts[1]);
$posts = sprintf('%s , %s', $posts[0], $posts[1]);
}
$xmlcontent .= "\n";
if(is_array($tids) && !empty($tids)) {
$ftid = $threadlist = $postlist = $attachlist = $pattachlist = array();
foreach ($tids as $tid) {
if(is_numeric($tid)) {
$ftid[] = $tid;
}
}
if($ftid) {
$threads = C::t('forum_thread')->fetch_all_by_tid($ftid);
foreach($threads as $thread) {
$thread['message'] = '';
if($msg) {
if($thread['posttableid']) {
$tablenamelist['forum_post_'.intval($thread['posttableid'])][] = $thread['tid'];
} else {
$tablenamelist['forum_post'][] = $thread['tid'];
}
}
$threadlist[$thread['tid']] = $thread;
}
if($msg) {
foreach($tablenamelist AS $tablename => $tids) {
$pquery = DB::query("SELECT tid, message, pid FROM ".DB::table($tablename)." WHERE tid IN (".dimplode($tids).") AND first=1", 'SILENT');
while($pquery && $post = DB::fetch($pquery)) {
$threadlist[$post['tid']]['message'] = dhtmlspecialchars($post['message']);
if($att) {
$_tid = (string)$post['tid'];
$attachtablename = 'forum_attachment_'.intval($_tid{strlen($_tid)-1});
$aquery = DB::query("SELECT dateline, filename, filesize, attachment, remote, description, readperm, price, isimage, width FROM ".DB::table($attachtablename)." WHERE pid='$post[pid]'");
$attachs = '';
while($aquery && $attach = DB::fetch($aquery)) {
$attach['url'] = (($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/').$attach['attachment'];
unset($attach['attachment'], $attach['remote']);
$attachs .= '';
foreach($attach as $_k => $_v) {
$attachs .= '<'.$_k.'>'.$_v.''.$_k.'>';
}
$attachs .= '';
$attachlist[$_tid] = $attachs;
}
}
}
if($posts) {
$pquery = DB::query("SELECT tid, pid, authorid, message FROM ".DB::table($tablename)." WHERE tid IN (".dimplode($tids).") AND first=0 LIMIT $posts", 'SILENT');
while($pquery && $post = DB::fetch($pquery)) {
if($att) {
$_tid = (string)$post['tid'];
$attachtablename = 'forum_attachment_'.intval($_tid{strlen($_tid)-1});
$aquery = DB::query("SELECT dateline, filename, filesize, attachment, remote, description, readperm, price, isimage, width FROM ".DB::table($attachtablename)." WHERE pid='$post[pid]'", 'SILENT');
$attachs = '';
while($aquery && $attach = DB::fetch($aquery)) {
$attach['url'] = (($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/').$attach['attachment'];
unset($attach['attachment'], $attach['remote']);
$attachs .= '';
foreach($attach as $_k => $_v) {
$attachs .= '<'.$_k.'>'.$_v.''.$_k.'>';
}
$attachs .= '';
}
}
$postlist[$post['tid']] .= "\n".
" ".$post['pid']."\n".
" ".$post['authorid']."\n".
" ".dhtmlspecialchars($post['message'])."\n".
($attachs ? " $attachs\n" : '').
"\n";
}
}
}
unset($tablenamelist);
}
foreach($threadlist AS $tid => $thread) {
$xmlcontent .=
" \n".
" $thread[tid]\n".
" $thread[fid]\n".
" $thread[authorid]\n".
" $thread[subject]\n".
" $thread[views]\n".
" $thread[replies]\n".
" $thread[replies]\n".
" $thread[posttableid]\n".
" $thread[dateline]\n".
" $thread[lastpost]\n".
($msg ? " $thread[message]\n" : '').
($attachlist[$tid] ? " $attachlist[$tid]\n" : '').
" \n".
($postlist[$tid] ? " $postlist[$tid]\n" : '');
}
}
}
$xmlcontent .= "";
echo $xmlcontent;
}
function on_gts() {
$xmlcontent = '';
$threads = C::t('forum_thread')->count();
$posts = 0;
loadcache('posttableids');
if($_G['cache']['posttableids']) {
foreach($_G['cache']['posttableids'] AS $tableid) {
$posts += DB::result_first("SELECT COUNT(*) FROM ".DB::table(getposttable($tableid))." LIMIT 1");
}
}
$members = C::t('common_member')->count();
$settings = C::t('common_setting')->fetch_all(array('bbname', 'historyposts'));
$bbname = $settings['bbname'];
$yesterdayposts = $settings['historyposts'];
if(!empty($yesterdayposts)) {
$yesterdayposts = explode("\t", $yesterdayposts);
$yestoday = intval($yesterdayposts[0]);
$mostpost = intval($yesterdayposts[1]);
} else {
$yestoday = $mostpost = 0;
}
$xmlcontent .= "\n".
" ".dhtmlspecialchars($bbname)."\n".
" $threads\n".
" $posts\n".
" $members\n".
" $yestoday\n".
" $mostpost\n".
"\n";
echo $xmlcontent;
echo "\n";
$query = C::t('forum_forum')->fetch_all_forum_ignore_access();
foreach($query as $forum) {
echo " <$forum[type]>\n".
" $forum[fid]\n".
" $forum[fup]\n".
" ".dhtmlspecialchars($forum['name'])."\n".
" ".dhtmlspecialchars($forum['description'])."\n".
" $forum[threads]\n".
" $forum[posts]\n".
" $forum[todayposts]\n".
" $forum[type]>\n";
}
echo "";
}
}
?>