cloud.mod.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  8. define('CLOUD_GATEWAY_URL', $_URLTYPE.$_SERVER['HTTP_HOST']);
  9. define('CLOUD_GATEWAY_URL_NORMAL', $_URLTYPE.$_SERVER['HTTP_HOST']);
  10. function cloud_client_define() {
  11. return array(
  12. '/framework/function/communication.func.php',
  13. '/framework/model/cloud.mod.php',
  14. '/web/source/cloud/upgrade.ctrl.php',
  15. '/web/source/cloud/process.ctrl.php',
  16. '/web/source/cloud/dock.ctrl.php',
  17. '/web/themes/default/cloud/upgrade.html',
  18. '/web/themes/default/cloud/process.html'
  19. );
  20. }
  21. function _cloud_build_params($must_authorization_host = true) {
  22. global $_W;
  23. $pars = array();
  24. $pars['host'] = strexists($_SERVER['HTTP_HOST'], ':') ? parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) : $_SERVER['HTTP_HOST'];
  25. if (is_array($_W['setting']['site']) && !empty($_W['setting']['site']['url']) && $must_authorization_host) {
  26. $pars['host'] = parse_url($_W['setting']['site']['url'], PHP_URL_HOST);
  27. }
  28. $pars['https'] = $_W['ishttps'] ? 1 : 0;
  29. $pars['family'] = IMS_FAMILY;
  30. $pars['version'] = IMS_VERSION;
  31. $pars['php_version'] = PHP_VERSION;
  32. $pars['current_host'] = $_SERVER['HTTP_HOST'];
  33. $pars['release'] = IMS_RELEASE_DATE;
  34. if (!empty($_W['setting']['site'])) {
  35. $pars['key'] = $_W['setting']['site']['key'];
  36. $pars['password'] = md5($_W['setting']['site']['key'] . $_W['setting']['site']['token']);
  37. }
  38. $clients = cloud_client_define();
  39. $string = '';
  40. foreach($clients as $cli) {
  41. $string .= md5_file(IA_ROOT . $cli);
  42. }
  43. $pars['client'] = md5($string);
  44. return $pars;
  45. }
  46. function _cloud_shipping_parse($dat, $file) {
  47. /*if (is_error($dat)) {
  48. return error(-1, '网络传输故障,详情: ' . (strpos($dat['message'], 'Connection reset by peer') ? '云服务瞬时访问过大而导致网络传输中断,请稍后重试。' : $dat['message']));
  49. }
  50. $tmp = iunserializer($dat['content']);
  51. if (is_array($tmp) && is_error($tmp)) {
  52. if ($tmp['errno'] == '-2') {
  53. file_put_contents(IA_ROOT . '/framework/version.inc.php', str_replace("'x'", "'v'", file_get_contents(IA_ROOT . '/framework/version.inc.php')));
  54. }
  55. return $tmp;
  56. }
  57. if ($dat['content'] == 'patching') {
  58. return error(-1, '补丁程序正在更新中,请稍后再试!');
  59. }
  60. if ($dat['content'] == 'frequent') {
  61. return error(-1, '更新操作太频繁,请稍后再试!');
  62. }
  63. if ($dat['content'] == 'blacklist') {
  64. return error(-1, '抱歉,您的站点已被列入云服务黑名单,云服务一切业务已被禁止,请联系微擎客服!');
  65. }
  66. if ($dat['content'] == 'install-theme-protect' || $dat['content'] == 'install-module-protect') {
  67. return error('-1', '此' . ($dat['content'] == 'install-theme-protect' ? '模板' : '模块') . '已设置版权保护,您只能通过云平台来安装,请先删除该模块的所有文件,购买后再行安装。');
  68. }
  69. $content = json_decode($dat['content'], true);
  70. if (!empty($content['error'])) {
  71. return error(-1, $content['error']);
  72. }
  73. if (!empty($content) && is_array($content)) {
  74. return $content;
  75. }
  76. if (strlen($dat['content']) != 32) {
  77. $dat['content'] = iunserializer($dat['content']);
  78. if (is_array($dat['content']) && isset($dat['content']['files'])) {
  79. if (!empty($dat['content']['manifest'])) {
  80. $dat['content']['manifest'] = base64_decode($dat['content']['manifest']);
  81. }
  82. if (!empty($dat['content']['scripts'])) {
  83. $dat['content']['scripts'] = base64_decode($dat['content']['scripts']);
  84. }
  85. return $dat['content'];
  86. }
  87. if (is_array($dat['content']) && isset($dat['content']['data'])) {
  88. $data = $dat['content'];
  89. } else {
  90. return error(-1, '云服务平台向您的服务器传输数据过程中出现错误,详情:' . $dat['content']);
  91. }
  92. } else {
  93. $data = @file_get_contents($file);
  94. @unlink($file);
  95. }
  96. $ret = @iunserializer($data);
  97. if (empty($data) || empty($ret)) {
  98. return error(-1, '云服务平台向您的服务器传输的数据校验失败,请稍后重试.');
  99. }
  100. $ret = iunserializer($ret['data']);
  101. if (is_array($ret) && is_error($ret)) {
  102. if ($ret['errno'] == '-2') {
  103. file_put_contents(IA_ROOT . '/framework/version.inc.php', str_replace("'x'", "'v'", file_get_contents(IA_ROOT . '/framework/version.inc.php')));
  104. }
  105. if ($ret['errno'] == '-3') { return array(
  106. 'errno' => $ret['errno'],
  107. 'message' => $ret['message'],
  108. 'cloud_id' => $ret['data'],
  109. );
  110. }
  111. }
  112. if (!is_error($ret) && is_array($ret)) {
  113. if (!empty($ret) && $ret['state'] == 'fatal') {
  114. return error($ret['errorno'], '发生错误: ' . $ret['message']);
  115. }
  116. return $ret;
  117. } else {
  118. return error($ret['errno'], "发生错误: {$ret['message']}");
  119. }*/
  120. return array();
  121. }
  122. function cloud_request($url, $post = '', $extra = array(), $timeout = 60) {
  123. global $_W;
  124. load()->func('communication');
  125. if (!empty($_W['setting']['cloudip']['ip']) && empty($extra['ip'])) {
  126. // $extra['ip'] = $_W['setting']['cloudip']['ip'];
  127. $extra['ip'] = $_SERVER['HTTP_HOST'];
  128. }
  129. /* if (strexists($url, 's.w7.cc')) {
  130. $extra = array();
  131. }
  132. $response = ihttp_request($url, $post, $extra, $timeout);
  133. if (is_error($response)) {
  134. setting_save(array(), 'cloudip');
  135. }
  136. return $response;
  137. */
  138. return array();
  139. }
  140. function local_salt($length = 8) {
  141. $result = '';
  142. while(strlen($result) < $length) {
  143. $result .= sha1(uniqid('', true));
  144. }
  145. return substr($result, 0, $length);
  146. }
  147. function cloud_api($method, $data = array(), $extra = array(), $timeout = 60) {
  148. if ($method == 'site/register/profile') {
  149. $pars = _cloud_build_params();
  150. $_URLTYPE = $pars['https'] ? 'https://' : 'http://';
  151. $tmp1 = $pars['key'] ? $pars['key'] : local_salt(6);
  152. $tmp2 = $_URLTYPE . $pars['host'];
  153. $site_tmp = array ( 'key' => $tmp1, 'token' => md5($tmp1), 'url' => $tmp2, 'version' => $pars['version'], 'family' => $pars['family'], 'type' => 'register',);
  154. //$site_tmp = serialize($site_tmp);
  155. pdo_update('core_settings', array('value' => iserializer($site_tmp)), array('key' => 'site'));
  156. cache_updatecache();
  157. }
  158. /* $cache_key = cache_system_key('cloud_api', array('method' => md5($method . implode('', $data))));
  159. $cache = cache_load($cache_key);
  160. if (!empty($cache) && !$extra['nocache']) {
  161. return $cache;
  162. }
  163. $api_url = 'http://api.w7.cc/%s';
  164. $must_authorization_host = !in_array($method, array('module/setting/index', 'module/setting/save'));
  165. $pars = _cloud_build_params($must_authorization_host);
  166. if ($method != 'site/token/index') {
  167. $pars['token'] = cloud_build_transtoken();
  168. }
  169. $data = array_merge($pars, $data);
  170. if ($GLOBALS['_W']['config']['setting']['development'] == 3) {
  171. $extra['CURLOPT_USERAGENT'] = 'development';
  172. }
  173. $response = ihttp_request(sprintf($api_url, $method), $data, $extra, $timeout);
  174. $file = IA_ROOT . '/data/' . (!empty($data['file']) ? $data['file'] : $data['method']);
  175. $file = $file . cache_random();
  176. $ret = _cloud_shipping_parse($response, $file);
  177. if (!is_error($ret) && !empty($ret)) {
  178. cache_write($cache_key, $ret, CACHE_EXPIRE_MIDDLE);
  179. }
  180. return $ret;
  181. */
  182. return null;
  183. }
  184. function cloud_prepare() {
  185. global $_W;
  186. setting_load();
  187. /* if(empty($_W['setting']['site']['key']) || empty($_W['setting']['site']['token'])) {
  188. return error('-1', '站点注册信息丢失, 请通过"重置站点ID和通信密钥"重新获取 !');
  189. }
  190. */
  191. return true;
  192. }
  193. function cloud_build($nocache = false) {
  194. /*
  195. $pars['method'] = 'application.build4';
  196. $pars['file'] = 'application.build';
  197. $ret = cloud_api('site/build/index', $pars, array('nocache' => $nocache));
  198. if (is_error($ret)) {
  199. return $ret;
  200. }
  201. if($ret['state'] == 'warning') {
  202. $ret['files'] = cloud_client_define();
  203. unset($ret['schemas']);
  204. unset($ret['scripts']);
  205. } else {
  206. $patch_path = sprintf('%s/data/patch/upgrade/%s', IA_ROOT, date('Ymd'));
  207. if (!is_dir($patch_path)) {
  208. mkdirs($patch_path);
  209. }
  210. $files = $files_allowed = array();
  211. if(!empty($ret['files'])) {
  212. foreach($ret['files'] as $file) {
  213. $entry = IA_ROOT . $file['path'];
  214. if(!is_file($entry) || md5_file($entry) != $file['checksum']) {
  215. $files_allowed[] = $file['path'];
  216. }
  217. $entry = $patch_path . $file['path'];
  218. if (!is_file($entry)) {
  219. $entry = IA_ROOT . $file['path'];
  220. }
  221. if(!is_file($entry) || md5_file($entry) != $file['checksum']) {
  222. $files[] = $file['path'];
  223. }
  224. }
  225. }
  226. $ret['files'] = $files;
  227. if (!empty($ret['files'])) {
  228. cloud_bakup_files($ret['files']);
  229. } else {
  230. if (!empty($files_allowed)) {
  231. foreach ($files_allowed as $file) {
  232. $dir = pathinfo(IA_ROOT . $file, PATHINFO_DIRNAME);
  233. if (!is_dir($dir)) {
  234. mkdirs($dir);
  235. }
  236. file_put_contents(IA_ROOT . $file, file_get_contents($patch_path . $file));
  237. }
  238. rmdirs($patch_path);
  239. }
  240. }
  241. $schemas = array();
  242. if(!empty($ret['schemas'])) {
  243. load()->func('db');
  244. foreach($ret['schemas'] as $remote) {
  245. $name = substr($remote['tablename'], 4);
  246. $local = db_table_schema(pdo(), $name);
  247. unset($remote['increment']);
  248. unset($local['increment']);
  249. if(empty($local)) {
  250. $schemas[] = $remote;
  251. } else {
  252. $sqls = db_table_fix_sql($local, $remote);
  253. if(!empty($sqls)) {
  254. $schemas[] = $remote;
  255. }
  256. }
  257. }
  258. }
  259. $ret['schemas'] = $schemas;
  260. }
  261. if (IMS_FAMILY != $ret['family']) {
  262. $update_version_success = setting_upgrade_version($ret['family'], IMS_VERSION, IMS_RELEASE_DATE);
  263. if (empty($update_version_success)) {
  264. message('切换版本失败,请修改 /framework/version.inc.php 文件权限为 User 可写或是 777', 'refresh', 'error');
  265. } else {
  266. message('更新系统正在为您自动切换版本', 'refresh');
  267. }
  268. }
  269. $ret['upgrade'] = false;
  270. if(!empty($ret['files']) || !empty($ret['schemas']) || !empty($ret['scripts'])) {
  271. $ret['upgrade'] = true;
  272. }
  273. $upgrade = array();
  274. $upgrade['upgrade'] = $ret['upgrade'];
  275. $upgrade['data'] = $ret;
  276. $upgrade['lastupdate'] = TIMESTAMP;
  277. cache_write(cache_system_key('upgrade'), $upgrade);
  278. return $ret;
  279. */
  280. return null;
  281. }
  282. function cloud_schema() {
  283. $pars['method'] = 'application.schema';
  284. $pars['file'] = 'application.schema';
  285. $ret = cloud_api('site/schema/index', $pars);
  286. if(!is_error($ret)) {
  287. $schemas = array();
  288. if(!empty($ret['schemas'])) {
  289. load()->func('db');
  290. foreach($ret['schemas'] as $remote) {
  291. $name = substr($remote['tablename'], 4);
  292. $local = db_table_schema(pdo(), $name);
  293. unset($remote['increment']);
  294. unset($local['increment']);
  295. if(empty($local)) {
  296. $schemas[] = $remote;
  297. } else {
  298. $diffs = db_schema_compare($local, $remote);
  299. if(!empty($diffs)) {
  300. $schemas[] = $remote;
  301. }
  302. }
  303. }
  304. }
  305. $ret['schemas'] = $schemas;
  306. }
  307. return $ret;
  308. }
  309. function cloud_download($path, $type = '') {
  310. global $_W;
  311. $pars = _cloud_build_params();
  312. $pars['method'] = 'application.shipping';
  313. $pars['path'] = $path;
  314. $pars['type'] = $type;
  315. $pars['gz'] = function_exists('gzcompress') && function_exists('gzuncompress') ? 'true' : 'false';
  316. $pars['download'] = 'true';
  317. $headers = array('content-type' => 'application/x-www-form-urlencoded');
  318. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  319. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, $headers, 300);
  320. if(is_error($dat)) {
  321. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  322. }
  323. if($dat['content'] == 'success') {
  324. return true;
  325. }
  326. $ret = @json_decode($dat['content'], true);
  327. if (isset($ret['error'])) {
  328. return error(1, $ret['error']);
  329. }
  330. if(is_error($ret)) {
  331. return $ret;
  332. } else {
  333. $post = $dat['content'];
  334. $data = base64_decode($post);
  335. if (base64_encode($data) !== $post) {
  336. $data = $post;
  337. }
  338. $ret = iunserializer($data);
  339. $gz = function_exists('gzcompress') && function_exists('gzuncompress');
  340. $file = base64_decode($ret['file']);
  341. if($gz) {
  342. $file = gzuncompress($file);
  343. }
  344. $_W['setting']['site']['token'] = authcode(cache_load(cache_system_key('cloud_transtoken')), 'DECODE');
  345. $string = (md5($file) . $ret['path'] . $_W['setting']['site']['token']);
  346. if(!empty($_W['setting']['site']['token']) && md5($string) === $ret['sign']) {
  347. $error_file_list = array();
  348. if (!cloud_file_permission_pass($error_file_list)) {
  349. return error(-1, '请修复下列文件读写权限 : ' . implode('; ', $error_file_list));
  350. }
  351. if ($type == 'module' || $type == 'theme') {
  352. $patch_path = IA_ROOT;
  353. } else {
  354. $patch_path = sprintf('%s/data/patch/upgrade/%s', IA_ROOT, date('Ymd'));
  355. }
  356. $path = $patch_path . $ret['path'];
  357. load()->func('file');
  358. @mkdirs(dirname($path));
  359. if (file_put_contents($path, $file)) {
  360. return true;
  361. } else {
  362. return error(-1, '写入失败,请检查是否有写入权限或是否磁盘已满!');
  363. }
  364. }
  365. return error(-1, '写入失败!');
  366. }
  367. }
  368. function cloud_m_prepare($name) {
  369. /* $ret = cloud_api('module/check', array(
  370. 'method' => 'module.check',
  371. 'module' => $name,
  372. ));
  373. if (is_error($ret)) {
  374. return $ret;
  375. }*/
  376. return true;
  377. }
  378. function cloud_m_build($modulename, $type = ''){
  379. /* $type = in_array($type, array('uninstall', 'upgrade', 'install')) ? $type : '';
  380. if (empty($modulename)) {
  381. return array();
  382. }
  383. if ($type == 'upgrade') {
  384. $module_info = cloud_m_info($modulename);
  385. if (is_error($module_info)) {
  386. return $module_info['message'];
  387. }
  388. $module = array('version' => $module_info['version']['version']);
  389. } else {
  390. $module = table('modules')->getByName($modulename);
  391. }
  392. $pars['module'] = $modulename;
  393. $pars['type'] = $type;
  394. if (!empty($module)) {
  395. $pars['module_version'] = $module['version'];
  396. }
  397. $pars['file'] = 'module.build';
  398. $ret = cloud_api('module/build', $pars);
  399. if (!is_error($ret)) {
  400. $dir = IA_ROOT . '/addons/' . $modulename;
  401. $files = array();
  402. if (!empty($ret['files'])) {
  403. foreach ($ret['files'] as $file) {
  404. if ($file['path'] == '/map.json') {
  405. continue;
  406. }
  407. $entry = $dir . $file['path'];
  408. if (!is_file($entry) || md5_file($entry) != $file['checksum']) {
  409. $files[] = '/' . $modulename . $file['path'];
  410. }
  411. }
  412. }
  413. $ret['files'] = $files;
  414. $schemas = array();
  415. if (!empty($ret['schemas'])) {
  416. load()->func('db');
  417. foreach ($ret['schemas'] as $remote) {
  418. $name = substr($remote['tablename'], 4);
  419. $local = db_table_schema(pdo(), $name);
  420. unset($remote['increment']);
  421. unset($local['increment']);
  422. if (empty($local)) {
  423. $schemas[] = $remote;
  424. } else {
  425. $diffs = db_table_fix_sql($local, $remote);
  426. if (!empty($diffs)) {
  427. $schemas[] = $remote;
  428. }
  429. }
  430. }
  431. }
  432. $ret['upgrade'] = true;
  433. $ret['type'] = 'module';
  434. $ret['schemas'] = $schemas;
  435. if (empty($module)) {
  436. $ret['install'] = 1;
  437. }
  438. }
  439. return $ret;
  440. */
  441. return null;
  442. }
  443. function cloud_m_query($module = array(), $page = 1) {
  444. /* $pars['method'] = 'module.query';
  445. if (empty($module)) {
  446. $module = cloud_extra_module();
  447. }
  448. if (!is_array($module)) {
  449. $module = array($module);
  450. }
  451. $pars['page'] = max(1, intval($page));
  452. $pars['module'] = base64_encode(iserializer($module));
  453. $ret = cloud_api('module/query', $pars);
  454. if (isset($ret['error'])) {
  455. return error(1, $ret['error']);
  456. }
  457. if (!is_error($ret)) {
  458. $pirate_apps = $ret['pirate_apps'];
  459. unset($ret['pirate_apps']);
  460. $support_names = array('app', 'wxapp', 'webapp', 'system_welcome', 'android', 'ios', 'xzapp', 'aliapp', 'baiduapp', 'toutiaoapp');
  461. $record_module = array();
  462. foreach ($ret['data'] as $modulename => &$info) {
  463. if ($info['is_record']) {
  464. $record_module[] = $info['name'];
  465. }
  466. if (empty($info['site_branch'])) {
  467. continue;
  468. }
  469. foreach ($support_names as $support) {
  470. if (in_array($support, $info['site_branch']['bought']) && !empty($info['site_branch']["{$support}_support"]) && $info['site_branch']["{$support}_support"] == 2) {
  471. $info['site_branch']["{$support}_support"] = 2;
  472. } else {
  473. $info['site_branch']["{$support}_support"] = 1;
  474. }
  475. }
  476. }
  477. $ret['pirate_apps'] = $pirate_apps;
  478. if (!empty($record_module)) {
  479. table('modules')->where(array('name IN' => $record_module))->fill(array('cloud_record' => STATUS_ON))->save();
  480. }
  481. } */
  482. //return $ret;
  483. return array();
  484. }
  485. function cloud_m_info($name) {
  486. $pars['method'] = 'module.info';
  487. $pars['module'] = $name;
  488. $ret = cloud_api('module/info', $pars);
  489. if (empty($ret)) {
  490. return array();
  491. }
  492. return $ret;
  493. }
  494. function cloud_m_upgradeinfo($modulename) {
  495. load()->model('module');
  496. $module = module_fetch($modulename);
  497. $pars['method'] = 'module.info';
  498. $pars['module'] = $modulename;
  499. $pars['curversion'] = $module['version'];
  500. $pars['isupgrade'] = 1;
  501. $ret = cloud_api('module/info', $pars);
  502. if (empty($ret)) {
  503. return array();
  504. }
  505. if (is_error($ret)) {
  506. return $ret;
  507. }
  508. if (version_compare($ret['version']['version'], $module['version'], '>')) {
  509. $ret['upgrade'] = true;
  510. }
  511. $ret['site_branch'] = $ret['branches'][$ret['version']['branch_id']];
  512. $ret['from'] = 'cloud';
  513. foreach ($ret['branches'] as &$branch) {
  514. if ($branch['displayorder'] > $ret['site_branch']['displayorder'] || ($branch['displayorder'] == $ret['site_branch']['displayorder'] && $ret['site_branch']['id'] < intval($branch['id']))) {
  515. $ret['new_branch'] = true;
  516. }
  517. $branch['id'] = intval($branch['id']);
  518. $branch['version']['description'] = preg_replace('/\n/', '<br/>', htmlspecialchars_decode($branch['version']['description']));
  519. $branch['displayorder'] = intval($branch['displayorder']);
  520. $branch['day'] = intval(date('d', $branch['version']['createtime']));
  521. $branch['month'] = date('Y.m', $branch['version']['createtime']);
  522. $branch['hour'] = date('H:i', $branch['version']['createtime']);
  523. }
  524. unset($branch);
  525. return $ret;
  526. }
  527. function cloud_t_prepare($name){
  528. /* $pars['method'] = 'theme.check';
  529. $pars['theme'] = $name;
  530. $dat = cloud_api('theme/check', $pars);
  531. if (is_error($dat)) {
  532. return $dat;
  533. }
  534. */
  535. return true;
  536. }
  537. function cloud_t_query(){
  538. /*
  539. $pars['method'] = 'theme.query';
  540. $pars['theme'] = cloud_extra_theme();
  541. $ret = cloud_api('theme/query', $pars);
  542. return $ret;
  543. */
  544. return null;
  545. }
  546. function cloud_t_info($name){
  547. /*
  548. $pars['method'] = 'theme.info';
  549. $pars['theme'] = $name;
  550. $ret = cloud_api('theme/info', $pars);
  551. return $ret;
  552. */
  553. return null;
  554. }
  555. function cloud_t_build($name) {
  556. if (empty($name)) {
  557. return array();
  558. }
  559. $theme = table('site_templates')->getByName(trim($name));
  560. $pars['method'] = 'theme.build';
  561. $pars['theme'] = $name;
  562. if(!empty($theme)) {
  563. $pars['themeversion'] = $theme['version'];
  564. }
  565. $ret = cloud_api('theme/build', $pars);
  566. if (empty($ret)) {
  567. return array();
  568. }
  569. if(!is_error($ret)) {
  570. $dir = IA_ROOT . '/app/themes/' . $name;
  571. $files = array();
  572. if(!empty($ret['files'])) {
  573. foreach($ret['files'] as $file) {
  574. $entry = $dir . $file['path'];
  575. if(!is_file($entry) || md5_file($entry) != $file['checksum']) {
  576. $files[] = '/'. $name . $file['path'];
  577. }
  578. }
  579. }
  580. $ret['files'] = $files;
  581. $ret['upgrade'] = true;
  582. $ret['type'] = 'theme';
  583. if(empty($theme)) {
  584. $ret['install'] = 1;
  585. }
  586. }
  587. return $ret;
  588. }
  589. function cloud_t_upgradeinfo($name) {
  590. if (empty($name)) {
  591. return array();
  592. }
  593. $theme = table('site_templates')->getByName(trim($name));
  594. if (empty($theme)) {
  595. return array();
  596. }
  597. return cloud_api('theme/upgrade', array(
  598. 'method' => 'theme.upgrade',
  599. 'theme' => $theme['name'],
  600. 'version' => $theme['version'],
  601. 'isupgrade' => 1,
  602. ));
  603. }
  604. function cloud_sms_send($mobile, $content, $postdata = array(), $custom_sign = '', $use_system_balance = false) {
  605. global $_W;
  606. if(!preg_match('/^1\d{10}$/', $mobile) || empty($content)) {
  607. return error(1, '发送短信失败, 原因: 手机号错误或内容为空.');
  608. }
  609. $uniacid = empty($use_system_balance) ? $_W['uniacid'] : 0;
  610. if (empty($uniacid)) {
  611. $sms_info = cloud_sms_info();
  612. $balance = empty($sms_info['sms_count']) ? 0 : $sms_info['sms_count'];
  613. if (!empty($custom_sign)) {
  614. $sign = $custom_sign;
  615. }
  616. } else {
  617. $row = pdo_get('uni_settings' , array('uniacid' => $uniacid), array('notify'));
  618. $row['notify'] = @iunserializer($row['notify']);
  619. $config = $row['notify']['sms'];
  620. $balance = intval($config['balance']);
  621. $sign = empty($custom_sign) ? $config['signature'] : $custom_sign;
  622. $account_name = empty($_W['account']['type_name']) ? '' : $_W['account']['type_name'];
  623. $account_name .= empty($_W['account']['name']) ? '' : " [{$_W['account']['name']}] ";
  624. }
  625. if(empty($sign) || $sign == 'null') {
  626. $sign = '短信宝';
  627. }
  628. //判断剩余条数
  629. if($balance<1){
  630. return error(-1, '短信发送失败, 原因:余额不足');
  631. }
  632. //短信宝账号
  633. // $smsbao_info=pdo_get('uni_settings' , array('uniacid' => $_W['uniacid']), array('copyright'));
  634. //$smsbao_info=setting_load($key = 'copyright');
  635. $sms_param['u']=$_W['setting']['copyright']['sms_name'];
  636. $sms_param['p']=md5($_W['setting']['copyright']['sms_password']);
  637. $sms_param['m']=$mobile;
  638. $sms_param['c']='【'.$sign.'】'.$content;
  639. $response = file_get_contents("http://api.smsbao.com/sms?".http_build_query($sms_param));
  640. if (trim($response)!='0') {
  641. return error($response['errno'], '短信发送失败, 原因:'.$response['message']);
  642. }
  643. if (trim($response)=='0') {
  644. if (!empty($uniacid)) {
  645. $row['notify']['sms']['balance'] = $row['notify']['sms']['balance'] - 1;
  646. if ($row['notify']['sms']['balance'] < 0) {
  647. $row['notify']['sms']['balance'] = 0;
  648. }
  649. pdo_update('uni_settings', array('notify' => iserializer($row['notify'])), array('uniacid' => $uniacid));
  650. uni_setting_save('notify', $row['notify']);
  651. } else {
  652. $sms_info['sms_count'] = $sms_info['sms_count'] - 1;
  653. if ($sms_info['sms_count'] < 0) {
  654. $sms_info['sms_count'] = 0;
  655. }
  656. setting_save($sms_info, 'sms.info');
  657. }
  658. }
  659. return true;
  660. }
  661. function cloud_sms_info() {
  662. global $_W;
  663. $data=array();
  664. //返回短信的剩余条数以及签名
  665. $sms_name=$_W['setting']['copyright']['sms_name'];
  666. $sms_password=md5($_W['setting']['copyright']['sms_password']);
  667. $res=file_get_contents("http://api.smsbao.com/query?u={$sms_name}&p={$sms_password}");
  668. $retArr = explode("\n", $res);
  669. $balanceArr = explode(",", $retArr[1]);
  670. $data['sms_count']=$retArr[0] == 0 ? $balanceArr[1]:0;
  671. return $data;
  672. }
  673. function cloud_sms_count_remained(){
  674. $cache_key = cache_system_key('cloud_api', array('method' => md5('cloud_sms_count_remained')));
  675. $cache = cache_load($cache_key);
  676. if (!empty($cache) && $cache['expire'] > TIMESTAMP) {
  677. return $cache['cloud_sms_count_remained'];
  678. }
  679. $sms_info = cloud_sms_info();
  680. if (is_error($sms_info)){
  681. return $sms_info;
  682. }
  683. $sms_count = $sms_info['sms_count'];
  684. $sms_accounts = table('uni_settings')->select(array('uniacid', 'notify'))->where(array('notify LIKE' => '%sms%'))->getall();
  685. $setting_sms_blance = setting_load('system_sms_balance');
  686. $system_sms_balance = !empty($setting_sms_blance['system_sms_balance']) ? $setting_sms_blance['system_sms_balance'] : 0;
  687. $sms_count -= $system_sms_balance;
  688. if (empty($sms_accounts)){
  689. return $sms_count;
  690. }
  691. foreach ($sms_accounts as $sms_account) {
  692. $notify = iunserializer($sms_account['notify']);
  693. $sms_count -= $notify['sms']['balance'];
  694. }
  695. $sms_count = max(0, $sms_count);
  696. $cache_data = array(
  697. 'cloud_sms_count_remained' => $sms_count
  698. );
  699. cache_write($cache_key, $cache_data, CACHE_EXPIRE_MIDDLE);
  700. return $sms_count;
  701. }
  702. function cloud_extra_account() {
  703. $data = array();
  704. $data['accounts'] = pdo_fetchall("SELECT name, account, original FROM ".tablename('account_wechats') . " GROUP BY account");
  705. return serialize($data);
  706. }
  707. function cloud_extra_module() {
  708. load()->model('module');
  709. $module_support_type = array_keys(module_support_type());
  710. $installed = table('modules')->getInstalled();
  711. $recycle = table('modules_recycle')->where('type', 2)->getall('name');
  712. $result = array();
  713. foreach($installed as $install_module) {
  714. if ($install_module['cloud_record']) {
  715. continue;
  716. }
  717. $result[$install_module['name']] = array(
  718. 'name' => $install_module['name'],
  719. 'version' => $install_module['version'],
  720. );
  721. $all_uninstall = true;
  722. foreach ($module_support_type as $support) {
  723. $type = str_replace('_support', '', $support);
  724. if ($install_module[$support] == 2) {
  725. $all_uninstall = false;
  726. $result[$install_module['name']]['support'][$type]['is_install'] = 2;
  727. }
  728. }
  729. if ($all_uninstall) {
  730. unset($result[$install_module['name']]);
  731. }
  732. }
  733. $result = array_slice($result, 0, 100, true);
  734. foreach($recycle as $recycle_module) {
  735. if (empty($result[$recycle_module['name']])) {
  736. $result[$recycle_module['name']] = array(
  737. 'name' => $recycle_module['name'],
  738. );
  739. }
  740. $in_recycle = false;
  741. foreach ($module_support_type as $support) {
  742. $type = str_replace('_support', '', $support);
  743. if ($recycle_module[$support]) {
  744. $in_recycle = true;
  745. $result[$recycle_module['name']]['support'][$type] = array(
  746. 'is_recycle' => 2
  747. );
  748. }
  749. }
  750. if (!$in_recycle) {
  751. unset($result[$recycle_module['name']]);
  752. }
  753. }
  754. return $result;
  755. }
  756. function cloud_extra_theme() {
  757. $sql = 'SELECT `name` FROM ' . tablename('site_templates') . ' WHERE `name` <> :name';
  758. $themes = pdo_fetchall($sql, array(':name' => 'default'), 'name');
  759. if (!empty($themes)) {
  760. return base64_encode(iserializer(array_keys($themes)));
  761. } else {
  762. return '';
  763. }
  764. }
  765. function cloud_extra_webtheme() {
  766. $sql = 'SELECT `name` FROM ' . tablename('webtheme_templates') . ' WHERE `name` <> :name';
  767. $themes = pdo_fetchall($sql, array(':name' => 'default'), 'name');
  768. if (!empty($themes)) {
  769. return base64_encode(iserializer(array_keys($themes)));
  770. } else {
  771. return '';
  772. }
  773. }
  774. function cloud_module_setting($acid, $module) {
  775. $pars = array(
  776. 'acid' => $acid,
  777. 'module_name' => $module['name'],
  778. 'module_version' => $module['version'],
  779. );
  780. return cloud_api('module/setting/index', $pars);
  781. }
  782. function cloud_module_setting_save($acid, $module_name, $setting) {
  783. $pars = array(
  784. 'acid' => $acid,
  785. 'module_name' => $module_name,
  786. 'setting' => $setting,
  787. );
  788. return cloud_api('module/setting/save', $pars);
  789. }
  790. function cloud_module_list($title, $support_type, $page = 1, $per_page = 20) {
  791. $pars = array(
  792. 'title' => $title,
  793. 'support_type' => $support_type,
  794. 'page' => $page,
  795. 'per_page' => $per_page,
  796. );
  797. return cloud_api('module/list', $pars);
  798. }
  799. function cloud_cron_create($cron) {
  800. $pars = array(
  801. 'cron' => base64_encode(iserializer($cron)),
  802. );
  803. return cloud_api('site/cron/save', $pars);
  804. }
  805. function cloud_cron_update($cron) {
  806. return cloud_cron_create($cron); }
  807. function cloud_cron_get($cron_id) {
  808. $pars = array(
  809. 'cron_id' => $cron_id,
  810. );
  811. return cloud_api('site/cron/get', $pars);
  812. }
  813. function cloud_cron_change_status($cron_id, $status) {
  814. $pars = array(
  815. 'cron_id' => $cron_id,
  816. 'status' => $status,
  817. );
  818. return cloud_api('site/cron/status', $pars);
  819. }
  820. function cloud_cron_remove($cron_id) {
  821. $pars = array(
  822. 'cron_id' => $cron_id,
  823. );
  824. return cloud_api('site/cron/remove', $pars);
  825. }
  826. function cloud_site_info() {
  827. return cloud_api('site/info');
  828. }
  829. function cloud_reset_siteinfo() {
  830. global $_W;
  831. return cloud_api('site/register/profile', array('url' => $_W['siteroot']));
  832. }
  833. function cloud_auth_url($forward, $data = array()){
  834. global $_W;
  835. if (!empty($_W['setting']['site']['url']) && !strexists($_W['siteroot'], $_W['setting']['site']['url'])) {
  836. $url = $_W['setting']['site']['url'];
  837. } else {
  838. $url = rtrim($_W['siteroot'], '/');
  839. }
  840. $auth = array();
  841. $auth['key'] = '';
  842. $auth['password'] = '';
  843. $auth['url'] = $url;
  844. $auth['referrer'] = intval($_W['config']['setting']['referrer']);
  845. $auth['version'] = IMS_VERSION;
  846. $auth['forward'] = $forward;
  847. $auth['family'] = IMS_FAMILY;
  848. if(!empty($_W['setting']['site']['key']) && !empty($_W['setting']['site']['token'])) {
  849. $auth['key'] = $_W['setting']['site']['key'];
  850. $auth['password'] = md5($_W['setting']['site']['key'] . $_W['setting']['site']['token']);
  851. }
  852. if ($data && is_array($data)) {
  853. $auth = array_merge($auth, $data);
  854. }
  855. $query = base64_encode(json_encode($auth));
  856. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  857. $auth_url = $_URLTYPE.$_SERVER['HTTP_HOST'] . $query;
  858. return $auth_url;
  859. }
  860. function cloud_module_setting_prepare($module, $binding) {
  861. global $_W;
  862. $auth = _cloud_build_params();
  863. $auth['arguments'] = array(
  864. 'binding' => $binding,
  865. 'acid' => $_W['uniacid'],
  866. 'type' => 'module',
  867. 'module' => $module,
  868. );
  869. $iframe_auth_url = cloud_auth_url('module', $auth);
  870. return $iframe_auth_url;
  871. }
  872. function cloud_resource_to_local($uniacid, $type, $url){
  873. global $_W;
  874. load()->func('file');
  875. $setting = $_W['setting']['upload'][$type];
  876. if (substr($url, 0, 2) == '//') {
  877. $url = 'http:' . $url;
  878. }
  879. if (!file_is_image($url)) {
  880. return error(1, '远程图片后缀非法,请重新上传');
  881. }
  882. $pathinfo = pathinfo($url);
  883. $extension = $pathinfo['extension'];
  884. if ($uniacid == 0) {
  885. $setting['folder'] = "{$type}s/global/".date('Y/m/');
  886. } else {
  887. $setting['folder'] = "{$type}s/{$uniacid}/".date('Y/m/');
  888. }
  889. $originname = pathinfo($url, PATHINFO_BASENAME);
  890. $filename = file_random_name(ATTACHMENT_ROOT .'/'. $setting['folder'], $extension);
  891. $pathname = $setting['folder'] . $filename;
  892. $fullname = ATTACHMENT_ROOT . $pathname;
  893. mkdirs(dirname($fullname));
  894. load()->func('communication');
  895. $response = ihttp_get($url);
  896. if (is_error($response)) {
  897. return error(1, $response['message']);
  898. }
  899. if (file_put_contents($fullname, $response['content']) == false) {
  900. return error(1, '提取文件失败');
  901. }
  902. if (!empty($_W['setting']['remote']['type'])) {
  903. $remotestatus = file_remote_upload($pathname);
  904. if (is_error($remotestatus)) {
  905. return error(1, '远程附件上传失败,请检查配置并重新上传');
  906. } else {
  907. file_delete($pathname);
  908. }
  909. }
  910. $data = array(
  911. 'uniacid' => $uniacid,
  912. 'uid' => intval($_W['uid']),
  913. 'filename' => $originname,
  914. 'attachment' => $pathname,
  915. 'type' => $type == 'image' ? 1 : 2,
  916. 'createtime' => TIMESTAMP,
  917. );
  918. pdo_insert('core_attachment', $data);
  919. $data['url'] = tomedia($pathname);
  920. $data['id'] = pdo_insertid();
  921. return $data;
  922. }
  923. function cloud_bakup_files($files) {
  924. global $_W;
  925. if (empty($files)) {
  926. return false;
  927. }
  928. $map = json_encode($files);
  929. $hash = md5($map.$_W['config']['setting']['authkey']);
  930. if ($handle = opendir(IA_ROOT . '/data/patch/backup/' . date('Ymd'))) {
  931. while (false !== ($patchpath = readdir($handle))) {
  932. if ($patchpath != '.' && $patchpath != '..') {
  933. if (strexists($patchpath, $hash)) {
  934. return false;
  935. }
  936. }
  937. }
  938. }
  939. $path = IA_ROOT . '/data/patch/backup/' . date('Ymd') . '/' . date('Hi') . '_' . $hash;
  940. load()->func('file');
  941. if (!is_dir($path) && mkdirs($path)) {
  942. foreach ($files as $file) {
  943. if (file_exists(IA_ROOT . $file)) {
  944. mkdirs($path . '/' . dirname($file));
  945. file_put_contents($path . '/' . $file, file_get_contents(IA_ROOT . $file));
  946. }
  947. }
  948. file_put_contents($path . '/' . 'map.json', $map);
  949. }
  950. return false;
  951. }
  952. function cloud_build_transtoken() {
  953. $pars['method'] = 'application.token';
  954. $pars['file'] = 'application.build';
  955. $ret = cloud_api('site/token/index', $pars);
  956. cache_write(cache_system_key('cloud_transtoken'), authcode($ret['token'], 'ENCODE'));
  957. return $ret['token'];
  958. }
  959. function cloud_build_schemas($schemas) {
  960. $database = array();
  961. if (empty($schemas) || !is_array($schemas)) {
  962. return $database;
  963. }
  964. foreach ($schemas as $remote) {
  965. $row = array();
  966. $row['tablename'] = $remote['tablename'];
  967. $name = substr($remote['tablename'], 4);
  968. $local = db_table_schema(pdo(), $name);
  969. unset($remote['increment']);
  970. unset($local['increment']);
  971. if (empty($local)) {
  972. $row['new'] = true;
  973. } else {
  974. $row['new'] = false;
  975. $row['fields'] = array();
  976. $row['indexes'] = array();
  977. $diffs = db_schema_compare($local, $remote);
  978. if (!empty($diffs['fields']['less'])) {
  979. $row['fields'] = array_merge($row['fields'], $diffs['fields']['less']);
  980. }
  981. if (!empty($diffs['fields']['diff'])) {
  982. $row['fields'] = array_merge($row['fields'], $diffs['fields']['diff']);
  983. }
  984. if (!empty($diffs['indexes']['less'])) {
  985. $row['indexes'] = array_merge($row['indexes'], $diffs['indexes']['less']);
  986. }
  987. if (!empty($diffs['indexes']['diff'])) {
  988. $row['indexes'] = array_merge($row['indexes'], $diffs['indexes']['diff']);
  989. }
  990. $row['fields'] = implode($row['fields'], ' ');
  991. $row['indexes'] = implode($row['indexes'], ' ');
  992. }
  993. $database[] = $row;
  994. }
  995. return $database;
  996. }
  997. function cloud_file_permission_pass(&$error_file_list = array()) {
  998. $cache_key = cache_system_key('cloud_file_permission_pass');
  999. $cache = cache_load($cache_key);
  1000. if ($cache) {
  1001. return true;
  1002. }
  1003. $check_path = array(
  1004. '/api',
  1005. '/app/common',
  1006. '/app/resource',
  1007. '/app/source',
  1008. '/app/themes/default',
  1009. '/web/common',
  1010. '/web/resource',
  1011. '/web/source',
  1012. '/web/themes/default',
  1013. '/web/themes/black',
  1014. '/web/themes/classical',
  1015. '/web/themes/2.0',
  1016. '/framework/builtin',
  1017. '/framework/class',
  1018. '/framework/model',
  1019. '/framework/function',
  1020. '/framework/table',
  1021. '/framework/library',
  1022. '/payment',
  1023. );
  1024. $check_file = array(
  1025. '/web/index.php',
  1026. '/framework/bootstrap.inc.php',
  1027. '/framework/version.inc.php',
  1028. '/framework/const.inc.php',
  1029. );
  1030. $sub_paths = array();
  1031. foreach ($check_path as $path) {
  1032. $file_list = cloud_file_tree(IA_ROOT . $path);
  1033. if (!empty($file_list)) {
  1034. foreach ($file_list as $file) {
  1035. if (is_file($file)) {
  1036. $sub_path = pathinfo($file, PATHINFO_DIRNAME);
  1037. if (empty($sub_paths[$sub_path])) {
  1038. if (!cloud_path_is_writable($sub_path)) {
  1039. $error_file_list[] = str_replace(IA_ROOT, '', $sub_path);
  1040. }
  1041. $sub_paths[$sub_path] = $sub_path;
  1042. }
  1043. }
  1044. if (!is_writable($file)) {
  1045. $error_file_list[] = str_replace(IA_ROOT, '', $file);
  1046. }
  1047. }
  1048. }
  1049. }
  1050. foreach ($check_file as $file) {
  1051. if (!is_writable(IA_ROOT . $file)) {
  1052. $error_file_list[] = str_replace(IA_ROOT, '', $file);
  1053. }
  1054. }
  1055. if (empty($error_file_list)) {
  1056. cache_write($cache_key, true, 600);
  1057. return true;
  1058. }
  1059. return false;
  1060. }
  1061. function cloud_file_tree($path, $include = array()) {
  1062. $files = array();
  1063. if (!empty($include)) {
  1064. $ds = glob($path . '/{' . implode(',', $include) . '}', GLOB_BRACE);
  1065. } else {
  1066. $ds = glob($path . '/*');
  1067. }
  1068. if (is_array($ds)) {
  1069. foreach ($ds as $entry) {
  1070. if (is_file($entry)) {
  1071. $files[] = $entry;
  1072. }
  1073. if (is_dir($entry)) {
  1074. $rs = cloud_file_tree($entry);
  1075. foreach ($rs as $f) {
  1076. $files[] = $f;
  1077. }
  1078. }
  1079. }
  1080. }
  1081. return $files;
  1082. }
  1083. function cloud_path_is_writable($dir) {
  1084. $writeable = false;
  1085. if (!is_dir($dir)) {
  1086. @mkdir($dir, 0755);
  1087. }
  1088. if (is_dir($dir)) {
  1089. if($fp = fopen("$dir/test.txt", 'w')) {
  1090. fclose($fp);
  1091. unlink("$dir/test.txt");
  1092. $writeable = true;
  1093. } else {
  1094. $writeable = false;
  1095. }
  1096. }
  1097. return $writeable;
  1098. }
  1099. function cloud_get_store_notice() {
  1100. load()->classs('cloudapi');
  1101. $api = new CloudApi();
  1102. $result = $api->get('store', 'official_dynamics');
  1103. return $result;
  1104. }
  1105. function cloud_v_to_xs($url) {
  1106. if (empty($url)) {
  1107. return false;
  1108. }
  1109. /*$pars = _cloud_build_params();
  1110. $pars['method'] = 'module.query';
  1111. $pars['url'] = urlencode($url);
  1112. cloud_request('http://api.w7.cc/site/pirate/index', $pars);
  1113. */
  1114. return true;
  1115. }
  1116. function cloud_workorder() {
  1117. $result = cloud_api('work-order/status/index');
  1118. return $result;
  1119. }
  1120. function cloud_account_info() {
  1121. $site_info = cloud_site_info();
  1122. $account_num = max(0, intval($site_info['quantity']));
  1123. return $account_num;
  1124. }
  1125. function cloud_w7_request_token($js_secret, $nocache = false) {
  1126. global $_W;
  1127. if (empty($_W['setting']['site']) || empty($_W['setting']['site']['key'])) {
  1128. return '';
  1129. }
  1130. if (!$nocache) {
  1131. $cache_key = cache_system_key('cloud_w7_request_token');
  1132. $cache = cache_load($cache_key);
  1133. if ($cache) {
  1134. return $cache;
  1135. }
  1136. }
  1137. $js_token = authcode($js_secret, 'ENCODE', $_W['setting']['site']['key']);
  1138. $data = array('js_token' => $js_token);
  1139. $ret = cloud_api('site/accesstoken/with-js-token', $data);
  1140. if (is_error($ret)) {
  1141. return '';
  1142. }
  1143. cache_write($cache_key, $ret['access_token'], $ret['expire_time']);
  1144. return $ret['access_token'];
  1145. }