google.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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: google.php 34713 2014-07-14 02:33:03Z hypowang $
  7. */
  8. @define('IN_API', true);
  9. @define('CURSCRIPT', 'api');
  10. require_once('../../source/class/class_core.php');
  11. require_once('../../source/function/function_home.php');
  12. $cachelist = array();
  13. $discuz = C::app();
  14. $discuz->cachelist = $cachelist;
  15. $discuz->init_cron = false;
  16. $discuz->init_setting = true;
  17. $discuz->init_user = false;
  18. $discuz->init_session = false;
  19. $discuz->init();
  20. $google = new GoogleAPI($discuz);
  21. $google->run();
  22. class GoogleAPI
  23. {
  24. var $core;
  25. var $version = '2.0.0';
  26. function GoogleAPI(&$core) {
  27. $this->core = &$core;
  28. }
  29. function run() {
  30. $this->authcheck();
  31. $method = 'on_'.getgpc('a');
  32. if(method_exists($this, $method)) {
  33. $this->xmlheader();
  34. $this->$method();
  35. $this->xmlfooter();
  36. } else {
  37. $this->error('Unknow command');
  38. }
  39. }
  40. function authcheck() {
  41. $siteuniqueid = C::t('common_setting')->fetch('siteuniqueid');
  42. $auth = md5($siteuniqueid.'DISCUZ*COMSENZ*GOOGLE*API'.substr(time(), 0, 6));
  43. if($auth != getgpc('s')) {
  44. $this->error('Access error');
  45. }
  46. }
  47. function error($message) {
  48. $this->xmlheader();
  49. echo "<error>".$message."</error>";
  50. $this->xmlfooter();
  51. }
  52. function result($message = 'success') {
  53. $this->xmlheader();
  54. echo "<result>".$message."</result>";
  55. $this->xmlfooter();
  56. }
  57. function xmlheader() {
  58. static $isshowed;
  59. if(!$isshowed) {
  60. @header("Content-type: application/xml");
  61. echo "<?xml version=\"1.0\" encoding=\"".CHARSET."\"?>\n<document>\n";
  62. echo "<description>Discuz! API For Google Function</description>\n";
  63. echo "<version>{$this->version}</version>\n";
  64. $isshowed = true;
  65. }
  66. return true;
  67. }
  68. function xmlfooter($halt = true) {
  69. echo "\n</document>\n";
  70. $halt && exit();
  71. }
  72. function on_on() {
  73. C::t('common_setting')->update('google', 1);
  74. $this->result();
  75. }
  76. function on_off() {
  77. C::t('common_setting')->update('google', 0);
  78. $this->result();
  79. }
  80. function on_gtt() {
  81. global $_G;
  82. $tids = explode(',', getgpc('t'));
  83. $msg = getgpc('msg') ? true : false;
  84. $att = getgpc('att') ? true : false;
  85. $posts = getgpc('post') ? explode(',', getgpc('post')) : array();
  86. if($posts) {
  87. $posts[0] = intval($posts[0]);
  88. $posts[1] = intval($posts[1]);
  89. $posts = sprintf('%s , %s', $posts[0], $posts[1]);
  90. }
  91. $xmlcontent .= "<threadsdata>\n";
  92. if(is_array($tids) && !empty($tids)) {
  93. $ftid = $threadlist = $postlist = $attachlist = $pattachlist = array();
  94. foreach ($tids as $tid) {
  95. if(is_numeric($tid)) {
  96. $ftid[] = $tid;
  97. }
  98. }
  99. if($ftid) {
  100. $threads = C::t('forum_thread')->fetch_all_by_tid($ftid);
  101. foreach($threads as $thread) {
  102. $thread['message'] = '';
  103. if($msg) {
  104. if($thread['posttableid']) {
  105. $tablenamelist['forum_post_'.intval($thread['posttableid'])][] = $thread['tid'];
  106. } else {
  107. $tablenamelist['forum_post'][] = $thread['tid'];
  108. }
  109. }
  110. $threadlist[$thread['tid']] = $thread;
  111. }
  112. if($msg) {
  113. foreach($tablenamelist AS $tablename => $tids) {
  114. $pquery = DB::query("SELECT tid, message, pid FROM ".DB::table($tablename)." WHERE tid IN (".dimplode($tids).") AND first=1", 'SILENT');
  115. while($pquery && $post = DB::fetch($pquery)) {
  116. $threadlist[$post['tid']]['message'] = dhtmlspecialchars($post['message']);
  117. if($att) {
  118. $_tid = (string)$post['tid'];
  119. $attachtablename = 'forum_attachment_'.intval($_tid{strlen($_tid)-1});
  120. $aquery = DB::query("SELECT dateline, filename, filesize, attachment, remote, description, readperm, price, isimage, width FROM ".DB::table($attachtablename)." WHERE pid='$post[pid]'");
  121. $attachs = '';
  122. while($aquery && $attach = DB::fetch($aquery)) {
  123. $attach['url'] = (($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/').$attach['attachment'];
  124. unset($attach['attachment'], $attach['remote']);
  125. $attachs .= '<attach>';
  126. foreach($attach as $_k => $_v) {
  127. $attachs .= '<'.$_k.'>'.$_v.'</'.$_k.'>';
  128. }
  129. $attachs .= '</attach>';
  130. $attachlist[$_tid] = $attachs;
  131. }
  132. }
  133. }
  134. if($posts) {
  135. $pquery = DB::query("SELECT tid, pid, authorid, message FROM ".DB::table($tablename)." WHERE tid IN (".dimplode($tids).") AND first=0 LIMIT $posts", 'SILENT');
  136. while($pquery && $post = DB::fetch($pquery)) {
  137. if($att) {
  138. $_tid = (string)$post['tid'];
  139. $attachtablename = 'forum_attachment_'.intval($_tid{strlen($_tid)-1});
  140. $aquery = DB::query("SELECT dateline, filename, filesize, attachment, remote, description, readperm, price, isimage, width FROM ".DB::table($attachtablename)." WHERE pid='$post[pid]'", 'SILENT');
  141. $attachs = '';
  142. while($aquery && $attach = DB::fetch($aquery)) {
  143. $attach['url'] = (($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/').$attach['attachment'];
  144. unset($attach['attachment'], $attach['remote']);
  145. $attachs .= '<attach>';
  146. foreach($attach as $_k => $_v) {
  147. $attachs .= '<'.$_k.'>'.$_v.'</'.$_k.'>';
  148. }
  149. $attachs .= '</attach>';
  150. }
  151. }
  152. $postlist[$post['tid']] .= "<post>\n".
  153. " <pid>".$post['pid']."</pid>\n".
  154. " <authorid>".$post['authorid']."</authorid>\n".
  155. " <message>".dhtmlspecialchars($post['message'])."</message>\n".
  156. ($attachs ? " <attachments>$attachs</attachments>\n" : '').
  157. "</post>\n";
  158. }
  159. }
  160. }
  161. unset($tablenamelist);
  162. }
  163. foreach($threadlist AS $tid => $thread) {
  164. $xmlcontent .=
  165. " <thread>\n".
  166. " <tid>$thread[tid]</tid>\n".
  167. " <fid>$thread[fid]</fid>\n".
  168. " <authorid>$thread[authorid]</authorid>\n".
  169. " <subject>$thread[subject]</subject>\n".
  170. " <views>$thread[views]</views>\n".
  171. " <replies>$thread[replies]</replies>\n".
  172. " <special>$thread[replies]</special>\n".
  173. " <posttableid>$thread[posttableid]</posttableid>\n".
  174. " <dateline>$thread[dateline]</dateline>\n".
  175. " <lastpost>$thread[lastpost]</lastpost>\n".
  176. ($msg ? " <message>$thread[message]</message>\n" : '').
  177. ($attachlist[$tid] ? " <attachments>$attachlist[$tid]</attachments>\n" : '').
  178. " </thread>\n".
  179. ($postlist[$tid] ? " <posts>$postlist[$tid]</posts>\n" : '');
  180. }
  181. }
  182. }
  183. $xmlcontent .= "</threadsdata>";
  184. echo $xmlcontent;
  185. }
  186. function on_gts() {
  187. $xmlcontent = '';
  188. $threads = C::t('forum_thread')->count();
  189. $posts = 0;
  190. loadcache('posttableids');
  191. if($_G['cache']['posttableids']) {
  192. foreach($_G['cache']['posttableids'] AS $tableid) {
  193. $posts += DB::result_first("SELECT COUNT(*) FROM ".DB::table(getposttable($tableid))." LIMIT 1");
  194. }
  195. }
  196. $members = C::t('common_member')->count();
  197. $settings = C::t('common_setting')->fetch_all(array('bbname', 'historyposts'));
  198. $bbname = $settings['bbname'];
  199. $yesterdayposts = $settings['historyposts'];
  200. if(!empty($yesterdayposts)) {
  201. $yesterdayposts = explode("\t", $yesterdayposts);
  202. $yestoday = intval($yesterdayposts[0]);
  203. $mostpost = intval($yesterdayposts[1]);
  204. } else {
  205. $yestoday = $mostpost = 0;
  206. }
  207. $xmlcontent .= "<sitedata>\n".
  208. " <bbname>".dhtmlspecialchars($bbname)."</bbname>\n".
  209. " <threads>$threads</threads>\n".
  210. " <posts>$posts</posts>\n".
  211. " <members>$members</members>\n".
  212. " <yesterdayposts>$yestoday</yesterdayposts>\n".
  213. " <mostposts>$mostpost</mostposts>\n".
  214. "</sitedata>\n";
  215. echo $xmlcontent;
  216. echo "<forumdata>\n";
  217. $query = C::t('forum_forum')->fetch_all_forum_ignore_access();
  218. foreach($query as $forum) {
  219. echo " <$forum[type]>\n".
  220. " <fid>$forum[fid]</fid>\n".
  221. " <fup>$forum[fup]</fup>\n".
  222. " <name>".dhtmlspecialchars($forum['name'])."</name>\n".
  223. " <description>".dhtmlspecialchars($forum['description'])."</description>\n".
  224. " <threads>$forum[threads]</threads>\n".
  225. " <posts>$forum[posts]</posts>\n".
  226. " <todayposts>$forum[todayposts]</todayposts>\n".
  227. " </$forum[type]>\n";
  228. }
  229. echo "</forumdata>";
  230. }
  231. }
  232. ?>