upload /api/manyou/Service/App.php

Language PHP Lines 257
MD5 Hash c758d6dbc88f414760a58ab85579acd6
Repository https://github.com/kuaileshike/upload.git View Raw File
  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
<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: App.php 29177 2012-03-28 05:56:17Z yexinhao $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

Cloud::loadFile('Service_AppException');

class Cloud_Service_App {

	protected static $_instance;

	public static function getInstance() {

		if (!(self::$_instance instanceof self)) {
			self::$_instance = new self();
		}

		return self::$_instance;
	}

	public function __construct() {

	}

	public function checkCloudStatus() {
		global $_G;

		$res = false;

		$cloudStatus = $_G['setting']['cloud_status'];
		$sId = $_G['setting']['my_siteid'];
		$sKey = $_G['setting']['my_sitekey'];

		if($sId && $sKey) {
			switch($cloudStatus) {
			case 1:
				$res = 'cloud';
				break;
			case 2:
				$res = 'unconfirmed';
				break;
			default:
				$res = 'upgrade';
			}
		} elseif(!$cloudStatus && !$sId && !$sKey) {
			$res = 'register';
		} else {
			throw new Cloud_Service_AppException('Cloud status error!', 52101);
		}

		return $res;
	}

	public function getCloudApps($cache = true) {

		$apps = array();

		if($cache) {
			global $_G;
			$apps = $_G['setting']['cloud_apps'];
		} else {
			$apps = C::t('common_setting')->fetch('cloud_apps', true);
		}

		if (!$apps) {
			$apps = array();
		}
		if (!is_array($apps)) {
			$apps = dunserialize($apps);
		}

		unset($apps[0]);

		return $apps;
	}

	public function getCloudAppStatus($appName, $cache = true) {

		$res = false;

		$apps = $this->getCloudApps($cache);
		if ($apps && $apps[$appName]) {
			$res = ($apps[$appName]['status'] == 'normal');
		}

		return $res;
	}

	public function setCloudAppStatus($appName, $status, $cache = true, $updateCache = true) {

		$method = '_' . strtolower($appName) . 'StatusCallback';
		if(!method_exists($this, $method)) {
			throw new Cloud_Service_AppException('Cloud callback: ' . $method . ' not exists!', 51001);
		}

		try {
			$callbackRes = $this->$method($appName, $status);
		} catch (Exception $e) {
			throw new Cloud_Service_AppException($e);
		}
		if (!$callbackRes) {
			throw new Cloud_Service_AppException('Cloud callback: ' . $method . ' error!', 51003);
		}

		$apps = $this->getCloudApps($cache);

		$app = array('name' => $appName, 'status' => $status);
		$apps[$appName] = $app;

		C::t('common_setting')->update('cloud_apps', $apps);

		if ($updateCache) {
			require_once libfile('function/cache');
			updatecache(array('plugin', 'setting', 'styles'));
			cleartemplatecache();
		}

		return true;
	}

	private function _manyouStatusCallback($appName, $status) {

		$available = 0;
		if($status == 'normal') {
			$available = 1;
		}
		return C::t('common_setting')->update('my_app_status', $available);
	}

	private function _connectStatusCallback($appName, $status) {

		$available = 0;
		if($status == 'normal') {
			$available = 1;
		}

		$setting = C::t('common_setting')->fetch('connect', true);
		if(!$setting) {
			$setting = array();
		}
		$setting['allow'] = $available;

		C::t('common_setting')->update('connect', $setting);

		$this->setPluginAvailable('qqconnect', $available);

		return true;
	}

	private function _securityStatusCallback($appName, $status) {

		$available = 0;
		if($status == 'normal') {
			$available = 1;
		}

		$this->setPluginAvailable('security', $available);

		return true;
	}

	private function _storageStatusCallback($appName, $status) {

		$available = 0;
		if($status == 'normal') {
			$available = 1;
		}

		$this->setPluginAvailable('xf_storage', $available);

		return true;
	}

	private function _statsStatusCallback($appName, $status) {

		$available = 0;
		if($status == 'normal') {
			$available = 1;
		}

		$this->setPluginAvailable('cloudstat', $available);

		return true;
	}

	private function _searchStatusCallback($appName, $status) {

		$available = 0;
		if($status == 'normal') {
			$available = 1;
		}

		C::t('common_setting')->update('my_search_status', $available);

		if($available) {
			Cloud::loadFile('Service_SearchHelper');
			Cloud_Service_SearchHelper::allowSearchForum();
		}

		$this->setPluginAvailable('cloudsearch', $available);

		return true;
	}

	private function _smiliesStatusCallback($appName, $status) {

		$available = 0;
		if($status == 'normal') {
			$available = 1;
		}

		$this->setPluginAvailable('soso_smilies', $available);

		return true;
	}

	private function _qqgroupStatusCallback($appName, $status) {

		$available = 0;
		if($status == 'normal') {
			$available = 1;
		}

		$this->setPluginAvailable('qqgroup', $available);

		return true;
	}

	private function _unionStatusCallback($appName, $status) {

		return true;
	}

	function setPluginAvailable($identifier, $available) {

		$available = intval($available);

		$plugin = C::t('common_plugin')->fetch_by_identifier($identifier);

		if(!$plugin || !$plugin['pluginid']) {
			throw new Cloud_Service_AppException('Cloud plugin: ' . $identifier . ' not exists!', 51108);
		}

		C::t('common_plugin')->update($plugin['pluginid'], array('available' => $available));

		return true;
	}

}
Back to Top