Cloud.php
4.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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: Cloud.php 29177 2012-03-28 05:56:17Z yexinhao $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class Cloud_Service_Server_Cloud extends Cloud_Service_Server_Restful {
protected static $_instance;
public static function getInstance() {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self();
}
return self::$_instance;
}
public function onCloudGetApps($appName = '') {
$appService = Cloud::loadClass('Service_App');
$utilService = Cloud::loadClass('Service_Util');
$apps = $appService->getCloudApps(false);
if ($appName) {
$apps = array($appName => $apps[$appName]);
}
$apps['apiVersion'] = $utilService->getApiVersion();
$apps['siteInfo'] = $this->_getBaseInfo();
return $apps;
}
public function onCloudSetApps($apps) {
if (!is_array($apps)) {
return false;
}
$appService = Cloud::loadClass('Service_App');
$utilService = Cloud::loadClass('Service_Util');
$res = array();
$res['apiVersion'] = $utilService->getApiVersion();
foreach ($apps as $appName => $status) {
$res[$appName] = $appService->setCloudAppStatus($appName, $status, false, false);
}
try {
require_once libfile('function/cache');
updatecache(array('plugin', 'setting', 'styles'));
cleartemplatecache();
} catch (Exception $e) {
}
$res['siteInfo'] = $this->_getBaseInfo();
return $res;
}
public function onCloudOpenCloud() {
$appService = Cloud::loadClass('Service_App');
$utilService = Cloud::loadClass('Service_Util');
$this->_openCloud();
$res = array();
$res['status'] = true;
$res['siteInfo'] = $this->_getBaseInfo();
return $res;
}
protected function _openCloud() {
require_once libfile('function/cache');
$result = C::t('common_setting')->update('cloud_status', 1);
try {
C::t('common_setting')->delete(array('connectsiteid', 'connectsitekey', 'my_siteid_old', 'my_sitekey_sign_old'));
} catch (Exception $e) {
}
updatecache('setting');
return true;
}
protected function _getBaseInfo() {
global $_G;
$info = array();
loadcache(array('userstats', 'historyposts'));
$indexData = memory('get', 'forum_index_page_1');
if(is_array($indexData) && $indexData) {
$indexData = array();
$info['threads'] = $indexData['threads'] ? $indexData['threads'] : 0;
$info['todayPosts'] = $indexData['todayposts'] ? $indexData['todayposts'] : 0;
$info['allPosts'] = $indexData['posts'] ? $indexData['posts'] : 0;
} else {
$threads = $posts = $todayposts = 0;
$query = C::t('forum_forum')->fetch_all_by_status(1, 0);
foreach($query as $forum) {
if($forum['type'] != 'group') {
$threads += $forum['threads'];
$posts += $forum['posts'];
$todayposts += $forum['todayposts'];
}
}
$info['threads'] = $threads ? $threads : 0;
$info['allPosts'] = $posts ? $posts : 0;
$info['todayPosts'] = $todayposts ? $todayposts : 0;
}
$info['members'] = $_G['cache']['userstats']['totalmembers'] ? intval($_G['cache']['userstats']['totalmembers']) : 0;
$postdata = $_G['cache']['historyposts'] ? explode("\t", $_G['cache']['historyposts']) : array(0,0);
$info['yesterdayPosts'] = intval($postdata[0]);
return $info;
}
public function onCloudGetStats() {
global $_G;
$info = array();
$tableprelen = strlen(C::t('common_setting')->get_tablepre());
$table = array(
'forum_thread' => 'threads',
'forum_post' => 'allPosts',
'common_member' => 'members'
);
foreach(C::t('common_setting')->fetch_all_table_status() as $row) {
$tablename = substr($row['Name'], $tableprelen);
if(!isset($table[$tablename])) {
continue;
}
$info[$table[$tablename]] = $row['Rows'];
}
loadcache(array('historyposts'));
$postdata = $_G['cache']['historyposts'] ? explode("\t", $_G['cache']['historyposts']) : array(0,0);
$info['yesterdayPosts'] = intval($postdata[0]);
$postnum = 0;
$postrow = 0;
$avg_posts = C::t('common_stat')->fetch_post_avg();
$info['avgPosts'] = intval($avg_posts);
$info['statsCode'] = $_G['setting']['statcode'];
return $info;
}
}