Cloud.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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: Cloud.php 29177 2012-03-28 05:56:17Z yexinhao $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class Cloud_Service_Server_Cloud extends Cloud_Service_Server_Restful {
  12. protected static $_instance;
  13. public static function getInstance() {
  14. if (!(self::$_instance instanceof self)) {
  15. self::$_instance = new self();
  16. }
  17. return self::$_instance;
  18. }
  19. public function onCloudGetApps($appName = '') {
  20. $appService = Cloud::loadClass('Service_App');
  21. $utilService = Cloud::loadClass('Service_Util');
  22. $apps = $appService->getCloudApps(false);
  23. if ($appName) {
  24. $apps = array($appName => $apps[$appName]);
  25. }
  26. $apps['apiVersion'] = $utilService->getApiVersion();
  27. $apps['siteInfo'] = $this->_getBaseInfo();
  28. return $apps;
  29. }
  30. public function onCloudSetApps($apps) {
  31. if (!is_array($apps)) {
  32. return false;
  33. }
  34. $appService = Cloud::loadClass('Service_App');
  35. $utilService = Cloud::loadClass('Service_Util');
  36. $res = array();
  37. $res['apiVersion'] = $utilService->getApiVersion();
  38. foreach ($apps as $appName => $status) {
  39. $res[$appName] = $appService->setCloudAppStatus($appName, $status, false, false);
  40. }
  41. try {
  42. require_once libfile('function/cache');
  43. updatecache(array('plugin', 'setting', 'styles'));
  44. cleartemplatecache();
  45. } catch (Exception $e) {
  46. }
  47. $res['siteInfo'] = $this->_getBaseInfo();
  48. return $res;
  49. }
  50. public function onCloudOpenCloud() {
  51. $appService = Cloud::loadClass('Service_App');
  52. $utilService = Cloud::loadClass('Service_Util');
  53. $this->_openCloud();
  54. $res = array();
  55. $res['status'] = true;
  56. $res['siteInfo'] = $this->_getBaseInfo();
  57. return $res;
  58. }
  59. protected function _openCloud() {
  60. require_once libfile('function/cache');
  61. $result = C::t('common_setting')->update('cloud_status', 1);
  62. try {
  63. C::t('common_setting')->delete(array('connectsiteid', 'connectsitekey', 'my_siteid_old', 'my_sitekey_sign_old'));
  64. } catch (Exception $e) {
  65. }
  66. updatecache('setting');
  67. return true;
  68. }
  69. protected function _getBaseInfo() {
  70. global $_G;
  71. $info = array();
  72. loadcache(array('userstats', 'historyposts'));
  73. $indexData = memory('get', 'forum_index_page_1');
  74. if(is_array($indexData) && $indexData) {
  75. $indexData = array();
  76. $info['threads'] = $indexData['threads'] ? $indexData['threads'] : 0;
  77. $info['todayPosts'] = $indexData['todayposts'] ? $indexData['todayposts'] : 0;
  78. $info['allPosts'] = $indexData['posts'] ? $indexData['posts'] : 0;
  79. } else {
  80. $threads = $posts = $todayposts = 0;
  81. $query = C::t('forum_forum')->fetch_all_by_status(1, 0);
  82. foreach($query as $forum) {
  83. if($forum['type'] != 'group') {
  84. $threads += $forum['threads'];
  85. $posts += $forum['posts'];
  86. $todayposts += $forum['todayposts'];
  87. }
  88. }
  89. $info['threads'] = $threads ? $threads : 0;
  90. $info['allPosts'] = $posts ? $posts : 0;
  91. $info['todayPosts'] = $todayposts ? $todayposts : 0;
  92. }
  93. $info['members'] = $_G['cache']['userstats']['totalmembers'] ? intval($_G['cache']['userstats']['totalmembers']) : 0;
  94. $postdata = $_G['cache']['historyposts'] ? explode("\t", $_G['cache']['historyposts']) : array(0,0);
  95. $info['yesterdayPosts'] = intval($postdata[0]);
  96. return $info;
  97. }
  98. public function onCloudGetStats() {
  99. global $_G;
  100. $info = array();
  101. $tableprelen = strlen(C::t('common_setting')->get_tablepre());
  102. $table = array(
  103. 'forum_thread' => 'threads',
  104. 'forum_post' => 'allPosts',
  105. 'common_member' => 'members'
  106. );
  107. foreach(C::t('common_setting')->fetch_all_table_status() as $row) {
  108. $tablename = substr($row['Name'], $tableprelen);
  109. if(!isset($table[$tablename])) {
  110. continue;
  111. }
  112. $info[$table[$tablename]] = $row['Rows'];
  113. }
  114. loadcache(array('historyposts'));
  115. $postdata = $_G['cache']['historyposts'] ? explode("\t", $_G['cache']['historyposts']) : array(0,0);
  116. $info['yesterdayPosts'] = intval($postdata[0]);
  117. $postnum = 0;
  118. $postrow = 0;
  119. $avg_posts = C::t('common_stat')->fetch_post_avg();
  120. $info['avgPosts'] = intval($avg_posts);
  121. $info['statsCode'] = $_G['setting']['statcode'];
  122. return $info;
  123. }
  124. }