PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/api/google/google.php

https://github.com/kuaileshike/upload
PHP | 208 lines | 175 code | 27 blank | 6 comment | 22 complexity | 5ab624f2aa9633c3effee179a67212fb MD5 | raw file
  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 29236 2012-03-30 05:34:47Z chenmengshu $
  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 = '1.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') && ip2long($_SERVER['REMOTE_ADDR']) != 2096036344 && ip2long($_SERVER['REMOTE_ADDR']) != 2096036256) {
  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. $tids = explode(',', getgpc('t'));
  82. $msg = getgpc('msg') ? true : false;
  83. $xmlcontent .= "<threadsdata>\n";
  84. if(is_array($tids) && !empty($tids)) {
  85. $ftid = $mark = '';
  86. foreach ($tids as $tid) {
  87. if(is_numeric($tid)) {
  88. $ftid .= $mark."'$tid'";
  89. $mark = ',';
  90. }
  91. }
  92. if($ftid) {
  93. $threads = C::t('forum_thread')->fetch_all_by_tid($ftid);
  94. foreach($threads as $thread) {
  95. $thread['message'] = '';
  96. if($msg) {
  97. if($thread['posttableid']) {
  98. $tablenamelist['forum_post_'.intval($thread['posttableid'])][] = $thread['tid'];
  99. } else {
  100. $tablenamelist['forum_post'][] = $thread['tid'];
  101. }
  102. }
  103. $threadlist[$thread['tid']] = $thread;
  104. }
  105. if($msg) {
  106. foreach($tablenamelist AS $tablename => $tids) {
  107. $pquery = DB::query("SELECT tid, message FROM ".DB::table($tablename)." WHERE tid IN (".dimplode($tids).") AND first=1", 'SILENT');
  108. while($pquery && $post = DB::fetch($pquery)) {
  109. $threadlist[$post['tid']]['message'] = dhtmlspecialchars($post['message']);
  110. }
  111. }
  112. unset($tablenamelist);
  113. }
  114. foreach($threadlist AS $tid => $thread) {
  115. $xmlcontent .=
  116. " <thread>\n".
  117. " <tid>$thread[tid]</tid>\n".
  118. " <fid>$thread[fid]</fid>\n".
  119. " <authorid>$thread[authorid]</authorid>\n".
  120. " <subject>$thread[subject]</subject>\n".
  121. " <views>$thread[views]</views>\n".
  122. " <replies>$thread[replies]</replies>\n".
  123. " <special>$thread[replies]</special>\n".
  124. " <posttableid>$thread[posttableid]</posttableid>\n".
  125. " <dateline>$thread[dateline]</dateline>\n".
  126. " <lastpost>$thread[lastpost]</lastpost>\n".
  127. ($msg ? " <message>$thread[message]</message>\n" : '').
  128. " </thread>\n";
  129. }
  130. }
  131. }
  132. $xmlcontent .= "</threadsdata>";
  133. echo $xmlcontent;
  134. }
  135. function on_gts() {
  136. $xmlcontent = '';
  137. $threads = C::t('forum_thread')->count();
  138. $posts = 0;
  139. loadcache('posttableids');
  140. if($_G['cache']['posttableids']) {
  141. foreach($_G['cache']['posttableids'] AS $tableid) {
  142. $posts += DB::result_first("SELECT COUNT(*) FROM ".DB::table(getposttable($tableid))." LIMIT 1");
  143. }
  144. }
  145. $members = C::t('common_member')->count();
  146. $settings = C::t('common_setting')->fetch_all(array('bbname', 'historyposts'));
  147. $bbname = $settings['bbname'];
  148. $yesterdayposts = $settings['historyposts'];
  149. if(!empty($yesterdayposts)) {
  150. $yesterdayposts = explode("\t", $yesterdayposts);
  151. $yestoday = intval($yesterdayposts[0]);
  152. $mostpost = intval($yesterdayposts[1]);
  153. } else {
  154. $yestoday = $mostpost = 0;
  155. }
  156. $xmlcontent .= "<sitedata>\n".
  157. " <bbname>".dhtmlspecialchars($bbname)."</bbname>\n".
  158. " <threads>$threads</threads>\n".
  159. " <posts>$posts</posts>\n".
  160. " <members>$members</members>\n".
  161. " <yesterdayposts>$yestoday</yesterdayposts>\n".
  162. " <mostposts>$mostpost</mostposts>\n".
  163. "</sitedata>\n";
  164. echo $xmlcontent;
  165. echo "<forumdata>\n";
  166. $query = C::t('forum_forum')->fetch_all_forum_ignore_access();
  167. foreach($query as $forum) {
  168. echo " <$forum[type]>\n".
  169. " <fid>$forum[fid]</fid>\n".
  170. " <fup>$forum[fup]</fup>\n".
  171. " <name>".dhtmlspecialchars($forum['name'])."</name>\n".
  172. " <description>".dhtmlspecialchars($forum['description'])."</description>\n".
  173. " <threads>$forum[threads]</threads>\n".
  174. " <posts>$forum[posts]</posts>\n".
  175. " <todayposts>$forum[todayposts]</todayposts>\n".
  176. " </$forum[type]>\n";
  177. }
  178. echo "</forumdata>";
  179. }
  180. }
  181. ?>