google.php
8.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: google.php 34713 2014-07-14 02:33:03Z hypowang $
*/
@define('IN_API', true);
@define('CURSCRIPT', 'api');
require_once('../../source/class/class_core.php');
require_once('../../source/function/function_home.php');
$cachelist = array();
$discuz = C::app();
$discuz->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 "<error>".$message."</error>";
$this->xmlfooter();
}
function result($message = 'success') {
$this->xmlheader();
echo "<result>".$message."</result>";
$this->xmlfooter();
}
function xmlheader() {
static $isshowed;
if(!$isshowed) {
@header("Content-type: application/xml");
echo "<?xml version=\"1.0\" encoding=\"".CHARSET."\"?>\n<document>\n";
echo "<description>Discuz! API For Google Function</description>\n";
echo "<version>{$this->version}</version>\n";
$isshowed = true;
}
return true;
}
function xmlfooter($halt = true) {
echo "\n</document>\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 .= "<threadsdata>\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 .= '<attach>';
foreach($attach as $_k => $_v) {
$attachs .= '<'.$_k.'>'.$_v.'</'.$_k.'>';
}
$attachs .= '</attach>';
$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 .= '<attach>';
foreach($attach as $_k => $_v) {
$attachs .= '<'.$_k.'>'.$_v.'</'.$_k.'>';
}
$attachs .= '</attach>';
}
}
$postlist[$post['tid']] .= "<post>\n".
" <pid>".$post['pid']."</pid>\n".
" <authorid>".$post['authorid']."</authorid>\n".
" <message>".dhtmlspecialchars($post['message'])."</message>\n".
($attachs ? " <attachments>$attachs</attachments>\n" : '').
"</post>\n";
}
}
}
unset($tablenamelist);
}
foreach($threadlist AS $tid => $thread) {
$xmlcontent .=
" <thread>\n".
" <tid>$thread[tid]</tid>\n".
" <fid>$thread[fid]</fid>\n".
" <authorid>$thread[authorid]</authorid>\n".
" <subject>$thread[subject]</subject>\n".
" <views>$thread[views]</views>\n".
" <replies>$thread[replies]</replies>\n".
" <special>$thread[replies]</special>\n".
" <posttableid>$thread[posttableid]</posttableid>\n".
" <dateline>$thread[dateline]</dateline>\n".
" <lastpost>$thread[lastpost]</lastpost>\n".
($msg ? " <message>$thread[message]</message>\n" : '').
($attachlist[$tid] ? " <attachments>$attachlist[$tid]</attachments>\n" : '').
" </thread>\n".
($postlist[$tid] ? " <posts>$postlist[$tid]</posts>\n" : '');
}
}
}
$xmlcontent .= "</threadsdata>";
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 .= "<sitedata>\n".
" <bbname>".dhtmlspecialchars($bbname)."</bbname>\n".
" <threads>$threads</threads>\n".
" <posts>$posts</posts>\n".
" <members>$members</members>\n".
" <yesterdayposts>$yestoday</yesterdayposts>\n".
" <mostposts>$mostpost</mostposts>\n".
"</sitedata>\n";
echo $xmlcontent;
echo "<forumdata>\n";
$query = C::t('forum_forum')->fetch_all_forum_ignore_access();
foreach($query as $forum) {
echo " <$forum[type]>\n".
" <fid>$forum[fid]</fid>\n".
" <fup>$forum[fup]</fup>\n".
" <name>".dhtmlspecialchars($forum['name'])."</name>\n".
" <description>".dhtmlspecialchars($forum['description'])."</description>\n".
" <threads>$forum[threads]</threads>\n".
" <posts>$forum[posts]</posts>\n".
" <todayposts>$forum[todayposts]</todayposts>\n".
" </$forum[type]>\n";
}
echo "</forumdata>";
}
}
?>