解决微擎框架出现Could not resolve: cloud.zhifun.cc (Domain name not found)问题方法教程

[复制链接]
查看3746 | 回复0 | 2020-3-20 11:02 | 显示全部楼层 |阅读模式
解决微擎框架出现Could not resolve: cloud.zhifun.cc (Domain name not found)问题方法教程

这个问题是因为cloud.zhifun.cc云服务挂了。
我们只需要去替换或者注释这个云服务就行

你可以将下面的代码复制到\framework\model目录下的cloud.mod.php文件
也可以选择覆盖我这个文件

  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.        
  97.         $ret = @iunserializer($data);
  98.         if (empty($data) || empty($ret)) {
  99.                 return error(-1, '云服务平台向您的服务器传输的数据校验失败,请稍后重试.');
  100.         }
  101.         $ret = iunserializer($ret['data']);
  102.         if (is_array($ret) && is_error($ret)) {
  103.                 if ($ret['errno'] == '-2') {
  104.                         file_put_contents(IA_ROOT . '/framework/version.inc.php', str_replace("'x'", "'v'", file_get_contents(IA_ROOT . '/framework/version.inc.php')));
  105.                 }
  106.                 if ($ret['errno'] == '-3') {                         return array(
  107.                                 'errno' => $ret['errno'],
  108.                                 'message' => $ret['message'],
  109.                                 'cloud_id' => $ret['data'],
  110.                         );
  111.                 }
  112.         }
  113.         if (!is_error($ret) && is_array($ret)) {
  114.                 if (!empty($ret) && $ret['state'] == 'fatal') {
  115.                         return error($ret['errorno'], '发生错误: ' . $ret['message']);
  116.                 }
  117.                 return $ret;
  118.         } else {
  119.                 return error($ret['errno'], "发生错误: {$ret['message']}");
  120.         }*/
  121.         return array();
  122. }

  123. function cloud_request($url, $post = '', $extra = array(), $timeout = 60) {
  124.         global $_W;
  125.         load()->func('communication');
  126.         if (!empty($_W['setting']['cloudip']['ip']) && empty($extra['ip'])) {
  127. //        $extra['ip'] = $_W['setting']['cloudip']['ip'];
  128.                 $extra['ip'] = $_SERVER['HTTP_HOST'];
  129.         }
  130. /*        if (strexists($url, 's.w7.cc')) {
  131.                 $extra = array();
  132.         }
  133.         $response = ihttp_request($url, $post, $extra, $timeout);
  134.         if (is_error($response)) {
  135.                 setting_save(array(), 'cloudip');
  136.         }
  137.         return $response;
  138. */
  139.         return array();
  140. }
  141. function local_salt($length = 8) {
  142.         $result = '';
  143.         while(strlen($result) < $length) {
  144.                 $result .= sha1(uniqid('', true));
  145.         }
  146.         return substr($result, 0, $length);
  147. }

  148. function cloud_api($method, $data = array(), $extra = array(), $timeout = 60) {
  149.         if ($method == 'site/register/profile') {
  150.                 $pars = _cloud_build_params();
  151.                                 $_URLTYPE = $pars['https'] ? 'https://' : 'http://';
  152.                                 $tmp1 =  $pars['key'] ? $pars['key'] : local_salt(6);
  153.                                 $tmp2 =  $_URLTYPE . $pars['host'];
  154.                 $site_tmp = array (  'key' => $tmp1,  'token' => md5($tmp1),  'url' => $tmp2,  'version' => $pars['version'],  'family' => $pars['family'],  'type' => 'register',);
  155.                 //$site_tmp = serialize($site_tmp);
  156.                                 pdo_update('core_settings', array('value' => iserializer($site_tmp)), array('key' => 'site'));
  157.                                 cache_updatecache();

  158.         }
  159. /*        $cache_key = cache_system_key('cloud_api', array('method' => md5($method . implode('', $data))));
  160.         $cache = cache_load($cache_key);
  161.         if (!empty($cache) && !$extra['nocache']) {
  162.                 return $cache;
  163.         }
  164.         $api_url = 'http://api.w7.cc/%s';
  165.         $must_authorization_host = !in_array($method, array('module/setting/index', 'module/setting/save'));
  166.         $pars = _cloud_build_params($must_authorization_host);
  167.         if ($method != 'site/token/index') {
  168.                 $pars['token'] = cloud_build_transtoken();
  169.         }
  170.         $data = array_merge($pars, $data);
  171.         if ($GLOBALS['_W']['config']['setting']['development'] == 3) {
  172.                 $extra['CURLOPT_USERAGENT'] = 'development';
  173.         }
  174.         $response = ihttp_request(sprintf($api_url, $method), $data, $extra, $timeout);
  175.         $file = IA_ROOT . '/data/' . (!empty($data['file']) ? $data['file'] : $data['method']);
  176.         $file = $file . cache_random();
  177.         $ret = _cloud_shipping_parse($response, $file);
  178.         if (!is_error($ret) && !empty($ret)) {
  179.                 cache_write($cache_key, $ret, CACHE_EXPIRE_MIDDLE);
  180.         }
  181.         return $ret;
  182. */
  183.         return null;
  184. }

  185. function cloud_prepare() {
  186.         global $_W;
  187.         setting_load();
  188. /*        if(empty($_W['setting']['site']['key']) || empty($_W['setting']['site']['token'])) {
  189.                 return error('-1', '站点注册信息丢失, 请通过"重置站点ID和通信密钥"重新获取 !');
  190.         }
  191.         */
  192.         return true;
  193. }

  194. function cloud_build($nocache = false) {
  195. /*
  196.         $pars['method'] = 'application.build4';
  197.         $pars['file'] = 'application.build';
  198.         $extra = $nocache ? array('nocache' => $nocache) : array();
  199.         $ret = cloud_api('site/build/index', $pars, $extra);
  200.         if (is_error($ret)) {
  201.                 return $ret;
  202.         }

  203.         if($ret['state'] == 'warning') {
  204.                 $ret['files'] = cloud_client_define();
  205.                 unset($ret['schemas']);
  206.                 unset($ret['scripts']);
  207.         } else {
  208.                 $patch_path = sprintf('%s/data/patch/upgrade/%s', IA_ROOT, date('Ymd'));
  209.                 if (!is_dir($patch_path)) {
  210.                         mkdirs($patch_path);
  211.                 }

  212.                 $files = $files_allowed = array();
  213.                 if(!empty($ret['files'])) {
  214.                         foreach($ret['files'] as $file) {
  215.                                 $entry = IA_ROOT . $file['path'];
  216.                                 if(!is_file($entry) || md5_file($entry) != $file['checksum']) {
  217.                                         $files_allowed[] = $file['path'];
  218.                                 }

  219.                                 $entry = $patch_path . $file['path'];
  220.                                 if (!is_file($entry)) {
  221.                                         $entry = IA_ROOT . $file['path'];
  222.                                 }
  223.                                 if(!is_file($entry) || md5_file($entry) != $file['checksum']) {
  224.                                         $files[] = $file['path'];
  225.                                 }
  226.                         }
  227.                 }
  228.                 $ret['files'] = $files;
  229.                 if (!empty($ret['files'])) {
  230.                         cloud_bakup_files($ret['files']);
  231.                 } else {
  232.                         if (!empty($files_allowed)) {
  233.                                 foreach ($files_allowed as $file) {
  234.                                         $dir = pathinfo(IA_ROOT . $file, PATHINFO_DIRNAME);
  235.                                         if (!is_dir($dir)) {
  236.                                                 mkdirs($dir);
  237.                                         }
  238.                                         file_put_contents(IA_ROOT . $file, file_get_contents($patch_path . $file));
  239.                                 }
  240.                                 rmdirs($patch_path);
  241.                         }
  242.                 }
  243.                 $schemas = array();
  244.                 if(!empty($ret['schemas'])) {
  245.                         load()->func('db');
  246.                         foreach($ret['schemas'] as $remote) {
  247.                                 $name = substr($remote['tablename'], 4);
  248.                                 $local = db_table_schema(pdo(), $name);
  249.                                 unset($remote['increment']);
  250.                                 unset($local['increment']);
  251.                                 if(empty($local)) {
  252.                                         $schemas[] = $remote;
  253.                                 } else {
  254.                                         $sqls = db_table_fix_sql($local, $remote);
  255.                                         if(!empty($sqls)) {
  256.                                                 $schemas[] = $remote;
  257.                                         }
  258.                                 }
  259.                         }
  260.                 }
  261.                 $ret['schemas'] = $schemas;
  262.         }

  263.         if (IMS_FAMILY != $ret['family']) {
  264.                 $update_version_success = setting_upgrade_version($ret['family'], IMS_VERSION, IMS_RELEASE_DATE);
  265.                 if (empty($update_version_success)) {
  266.                         message('切换版本失败,请修改 /framework/version.inc.php 文件权限为 User 可写或是 777', 'refresh', 'error');
  267.                 } else {
  268.                         message('更新系统正在为您自动切换版本', 'refresh');
  269.                 }
  270.         }
  271.         $ret['upgrade'] = false;
  272.         if(!empty($ret['files']) || !empty($ret['schemas']) || !empty($ret['scripts'])) {
  273.                 $ret['upgrade'] = true;
  274.         }

  275.         return $ret;
  276. */
  277.     return null;
  278. }

  279. function cloud_schema() {
  280.         $pars['method'] = 'application.schema';
  281.         $pars['file'] = 'application.schema';
  282.         $ret = cloud_api('site/schema/index', $pars);
  283.        
  284.         if(!is_error($ret)) {
  285.                 $schemas = array();
  286.                 if(!empty($ret['schemas'])) {
  287.                         load()->func('db');
  288.                         foreach($ret['schemas'] as $remote) {
  289.                                 $name = substr($remote['tablename'], 4);
  290.                                 $local = db_table_schema(pdo(), $name);
  291.                                 unset($remote['increment']);
  292.                                 unset($local['increment']);
  293.                                 if(empty($local)) {
  294.                                         $schemas[] = $remote;
  295.                                 } else {
  296.                                         $diffs = db_schema_compare($local, $remote);
  297.                                         if(!empty($diffs)) {
  298.                                                 $schemas[] = $remote;
  299.                                         }
  300.                                 }
  301.                         }
  302.                 }
  303.                 $ret['schemas'] = $schemas;
  304.         }
  305.         return $ret;
  306. }

  307. function cloud_download($path, $type = '') {
  308.         global $_W;
  309.         $pars = _cloud_build_params();
  310.         $pars['method'] = 'application.shipping';
  311.         $pars['path'] = $path;
  312.         $pars['type'] = $type;
  313.         $pars['gz'] = function_exists('gzcompress') && function_exists('gzuncompress') ? 'true' : 'false';
  314.         $pars['download'] = 'true';
  315.         $headers = array('content-type' => 'application/x-www-form-urlencoded');
  316.         $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  317.         $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, $headers, 300);
  318.         if(is_error($dat)) {
  319.                 return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  320.         }
  321.         if($dat['content'] == 'success') {
  322.                 return true;
  323.         }
  324.         $ret = @json_decode($dat['content'], true);
  325.         if (isset($ret['error'])) {
  326.                 return error(1, $ret['error']);
  327.         }
  328.         if(is_error($ret)) {
  329.                 return $ret;
  330.         } else {
  331.                 $post = $dat['content'];
  332.                 $data = base64_decode($post);
  333.                 if (base64_encode($data) !== $post) {
  334.                         $data = $post;
  335.                 }
  336.                 $ret = iunserializer($data);
  337.                 $gz = function_exists('gzcompress') && function_exists('gzuncompress');
  338.                 $file = base64_decode($ret['file']);
  339.                 if($gz) {
  340.                         $file = gzuncompress($file);
  341.                 }
  342.                 $_W['setting']['site']['token'] = authcode(cache_load(cache_system_key('cloud_transtoken')), 'DECODE');
  343.                 $string = (md5($file) . $ret['path'] . $_W['setting']['site']['token']);
  344.                 if(!empty($_W['setting']['site']['token']) && md5($string) === $ret['sign']) {
  345.                         $error_file_list = array();
  346.                         if (!cloud_file_permission_pass($error_file_list)) {
  347.                                 return error(-1, '请修复下列文件读写权限 : ' . implode('; ', $error_file_list));
  348.                         }
  349.                                                 if ($type == 'module' || $type == 'theme') {
  350.                                 $patch_path = IA_ROOT;
  351.                         } else {
  352.                                 $patch_path = sprintf('%s/data/patch/upgrade/%s', IA_ROOT, date('Ymd'));
  353.                         }
  354.                         $path = $patch_path . $ret['path'];
  355.                         load()->func('file');
  356.                         @mkdirs(dirname($path));
  357.                         if (file_put_contents($path, $file)) {
  358.                                 return true;
  359.                         } else {
  360.                                 return error(-1, '写入失败,请检查是否有写入权限或是否磁盘已满!');
  361.                         }
  362.                 }
  363.                 return error(-1, '写入失败!');
  364.         }
  365. }

  366. function cloud_m_prepare($name) {
  367. /*        $ret = cloud_api('module/check', array(
  368.                 'method' => 'module.check',
  369.                 'module' => $name,
  370.         ));
  371.         if (is_error($ret)) {
  372.                 return $ret;
  373.         }*/
  374.         return true;
  375. }


  376. function cloud_m_build($modulename, $type = ''){
  377. /*        $type = in_array($type, array('uninstall', 'upgrade', 'install')) ? $type : '';
  378.         if (empty($modulename)) {
  379.                 return array();
  380.         }
  381.         if ($type == 'upgrade') {
  382.                 $module_info = cloud_m_info($modulename);
  383.                 if (is_error($module_info)) {
  384.                         return $module_info['message'];
  385.                 }
  386.                 $module = array('version' => $module_info['version']['version']);
  387.         } else {
  388.                 $module = table('modules')->getByName($modulename);
  389.         }
  390.         $pars['module'] = $modulename;
  391.         $pars['type'] = $type;
  392.         if (!empty($module)) {
  393.                 $pars['module_version'] = $module['version'];
  394.         }
  395.        
  396.         $pars['file'] = 'module.build';
  397.         $ret = cloud_api('module/build', $pars);

  398.         if (!is_error($ret)) {
  399.                 $dir = IA_ROOT . '/addons/' . $modulename;
  400.                 $files = array();
  401.                 if (!empty($ret['files'])) {
  402.                         foreach ($ret['files'] as $file) {
  403.                                 if ($file['path'] == '/map.json') {
  404.                                         continue;
  405.                                 }
  406.                                 $entry = $dir . $file['path'];
  407.                                 if (!is_file($entry) || md5_file($entry) != $file['checksum']) {
  408.                                         $files[] = '/' . $modulename . $file['path'];
  409.                                 }
  410.                         }
  411.                 }
  412.                 $ret['files'] = $files;
  413.                 $schemas = array();
  414.                 if (!empty($ret['schemas'])) {
  415.                         load()->func('db');
  416.                         foreach ($ret['schemas'] as $remote) {
  417.                                 $name = substr($remote['tablename'], 4);
  418.                                 $local = db_table_schema(pdo(), $name);
  419.                                 unset($remote['increment']);
  420.                                 unset($local['increment']);
  421.                                 if (empty($local)) {
  422.                                         $schemas[] = $remote;
  423.                                 } else {
  424.                                         $diffs = db_table_fix_sql($local, $remote);
  425.                                         if (!empty($diffs)) {
  426.                                                 $schemas[] = $remote;
  427.                                         }
  428.                                 }
  429.                         }
  430.                 }
  431.                 $ret['upgrade'] = true;
  432.                 $ret['type'] = 'module';
  433.                 $ret['schemas'] = $schemas;
  434.                                 if (empty($module)) {
  435.                         $ret['install'] = 1;
  436.                 }
  437.         }
  438.         return $ret;
  439.     */
  440.     return null;
  441. }


  442. function cloud_m_query($module = array(), $page = 1) {
  443. /*         $pars['method'] = 'module.query';
  444.         if (empty($module)) {
  445.                 $module = cloud_extra_module();
  446.         }
  447.         if (!is_array($module)) {
  448.                 $module = array($module);
  449.         }
  450.         $pars['page'] = max(1, intval($page));
  451.         $pars['module'] = base64_encode(iserializer($module));
  452.         $ret = cloud_api('module/query', $pars);
  453.         if (isset($ret['error'])) {
  454.                 return error(1, $ret['error']);
  455.         }
  456.         if (!is_error($ret)) {
  457.                 $pirate_apps = $ret['pirate_apps'];
  458.                 unset($ret['pirate_apps']);
  459.                 $support_names = array('app', 'wxapp', 'webapp', 'system_welcome', 'android', 'ios', 'xzapp', 'aliapp', 'baiduapp', 'toutiaoapp');
  460.                 $record_module = array();
  461.                 foreach ($ret['data'] as $modulename => &$info) {
  462.                         if ($info['is_record']) {
  463.                                 $record_module[] = $info['name'];
  464.                         }
  465.                         if (empty($info['site_branch'])) {
  466.                                 continue;
  467.                         }
  468.                         foreach ($support_names as $support) {
  469.                                 if (in_array($support, $info['site_branch']['bought']) && !empty($info['site_branch']["{$support}_support"]) && $info['site_branch']["{$support}_support"] == 2) {
  470.                                         $info['site_branch']["{$support}_support"] = 2;
  471.                                 } else {
  472.                                         $info['site_branch']["{$support}_support"] = 1;
  473.                                 }
  474.                         }
  475.                 }
  476.                 $ret['pirate_apps'] = $pirate_apps;
  477.                 if (!empty($record_module)) {
  478.                         table('modules')->where(array('name IN' => $record_module))->fill(array('cloud_record' => STATUS_ON))->save();
  479.                 }
  480.         } */
  481.         //return $ret;
  482.         return array();
  483. }

  484. function cloud_m_info($name) {
  485.         $pars['method'] = 'module.info';
  486.         $pars['module'] = $name;
  487.         $ret = cloud_api('module/info', $pars);
  488.         if (empty($ret)) {
  489.                 return array();
  490.         }       
  491.         return $ret;
  492. }


  493. function cloud_m_upgradeinfo($modulename) {
  494.         load()->model('module');

  495.         $module = module_fetch($modulename);

  496.         $pars['method'] = 'module.info';
  497.         $pars['module'] = $modulename;
  498.         $pars['curversion'] = $module['version'];
  499.         $pars['isupgrade'] = 1;
  500.         $ret = cloud_api('module/info', $pars);

  501.         if (empty($ret)) {
  502.                 return array();
  503.         }
  504.         if (is_error($ret)) {
  505.                 return $ret;
  506.         }
  507.         if (version_compare($ret['version']['version'], $module['version'], '>')) {
  508.                 $ret['upgrade'] = true;
  509.         }
  510.                 $ret['site_branch'] = $ret['branches'][$ret['version']['branch_id']];
  511.                 $ret['from'] = 'cloud';
  512.                 foreach ($ret['branches'] as &$branch) {
  513.                 if ($branch['displayorder'] > $ret['site_branch']['displayorder'] || ($branch['displayorder'] == $ret['site_branch']['displayorder'] && $ret['site_branch']['id'] < intval($branch['id']))) {
  514.                         $ret['new_branch'] = true;
  515.                         }
  516.                 $branch['id'] = intval($branch['id']);
  517.                 $branch['version']['description'] = preg_replace('/\n/', '<br/>', htmlspecialchars_decode($branch['version']['description']));
  518.                 $branch['displayorder'] = intval($branch['displayorder']);
  519.                 $branch['day'] = intval(date('d', $branch['version']['createtime']));
  520.                 $branch['month'] = date('Y.m', $branch['version']['createtime']);
  521.                 $branch['hour'] = date('H:i', $branch['version']['createtime']);
  522.         }
  523.         unset($branch);
  524.         return $ret;
  525. }

  526. function cloud_t_prepare($name){
  527. /*        $pars['method'] = 'theme.check';
  528.         $pars['theme'] = $name;
  529.         $dat = cloud_api('theme/check', $pars);
  530.         if (is_error($dat)) {
  531.                 return $dat;
  532.         }

  533. */
  534.     return true;
  535. }


  536. function cloud_t_query(){
  537. /*
  538.         $pars['method'] = 'theme.query';
  539.         $pars['theme'] = cloud_extra_theme();
  540.         $ret = cloud_api('theme/query', $pars);
  541.         return $ret;
  542.         */
  543.     return null;
  544. }

  545. function cloud_t_info($name){
  546. /*       
  547.         $pars['method'] = 'theme.info';
  548.         $pars['theme'] = $name;
  549.         $ret = cloud_api('theme/info', $pars);
  550.         return $ret;

  551. */
  552.     return null;
  553. }

  554. function cloud_t_build($name) {
  555.         if (empty($name)) {
  556.                 return array();
  557.         }
  558.         $theme = table('site_templates')->getByName(trim($name));
  559.         $pars['method'] = 'theme.build';
  560.         $pars['theme'] = $name;
  561.         if(!empty($theme)) {
  562.                 $pars['themeversion'] = $theme['version'];
  563.         }
  564.         $ret = cloud_api('theme/build', $pars);
  565.         if (empty($ret)) {
  566.                 return array();
  567.         }       
  568.         if(!is_error($ret)) {
  569.                 $dir = IA_ROOT . '/app/themes/' . $name;
  570.                 $files = array();
  571.                 if(!empty($ret['files'])) {
  572.                         foreach($ret['files'] as $file) {
  573.                                 $entry = $dir . $file['path'];
  574.                                 if(!is_file($entry) || md5_file($entry) != $file['checksum']) {
  575.                                         $files[] = '/'. $name . $file['path'];
  576.                                 }
  577.                         }
  578.                 }
  579.                 $ret['files'] = $files;
  580.                 $ret['upgrade'] = true;
  581.                 $ret['type'] = 'theme';
  582.                                 if(empty($theme)) {
  583.                         $ret['install'] = 1;
  584.                 }
  585.         }
  586.         return $ret;
  587. }


  588. function cloud_t_upgradeinfo($name) {
  589.         if (empty($name)) {
  590.                 return array();
  591.         }
  592.         $theme = table('site_templates')->getByName(trim($name));
  593.         if (empty($theme)) {
  594.                 return array();
  595.         }
  596.         return cloud_api('theme/upgrade', array(
  597.                 'method' => 'theme.upgrade',
  598.                 'theme' => $theme['name'],
  599.                 'version' => $theme['version'],
  600.                 'isupgrade' => 1,
  601.         ));
  602. }

  603. function cloud_sms_send($mobile, $content, $postdata = array(), $custom_sign = '', $use_system_balance = false) {
  604.         global $_W;
  605.         if(!preg_match('/^1\d{10}$/', $mobile) || empty($content)) {
  606.                 return error(1, '发送短信失败, 原因: 手机号错误或内容为空.');
  607.         }
  608.         $uniacid = empty($use_system_balance) ? $_W['uniacid'] : 0;

  609.         if (empty($uniacid)) {
  610.                 $sms_info = cloud_sms_info();
  611.                 $balance = empty($sms_info['sms_count']) ? 0 : $sms_info['sms_count'];
  612.                 if (!empty($custom_sign)) {
  613.                         $sign = $custom_sign;
  614.                 }
  615.         } else {
  616.                 $row = pdo_get('uni_settings' , array('uniacid' => $uniacid), array('notify'));
  617.                 $row['notify'] = @iunserializer($row['notify']);

  618.                 $config = $row['notify']['sms'];
  619.                 $balance = intval($config['balance']);
  620.         
  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. }
复制代码

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

UID
1
贡献
387
丢币
38902
主题
4607
回帖
116
注册时间
2018-9-25
最后登录
2024-4-16