1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510 |
- <?php
- /**
- * [WeEngine System] Copyright (c) 2014 WE7.CC
- * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
- */
- defined('IN_IA') or exit('Access Denied');
- function cloud_client_define() {
- return array(
- '/framework/function/communication.func.php',
- '/framework/model/cloud.mod.php',
- '/web/source/cloud/upgrade.ctrl.php',
- '/web/source/cloud/dock.ctrl.php',
- '/web/themes/default/cloud/upgrade.html',
- );
- }
- function cloud_not_must_authorization_method() {
- return array(
- 'module/setting/index',
- 'module/setting/save',
- 'sms/info',
- 'sms/sign',
- 'wxapp/info',
- 'wxapp/login/qr-code',
- 'wxapp/login/qr-scan',
- 'wxapp/publish',
- 'wxapp/publish/download',
- 'module/query',
- 'theme/query',
- 'we7/oauth/user-bind/mobile-bind-info',
- 'we7/oauth/user-bind/mobile-code',
- 'we7/oauth/user-bind/complete',
- 'we7/oauth/user-bind/info',
- 'we7/oauth/user-bind/complete-with-accesstoken',
- 'we7/site/console/visible',
- 'we7/site/console/index-url',
- 'we7/site/console/share-url',
- 'site/oauth/user/web-token/verify',
- 'site/oauth/register-url/index',
- 'site/oauth/user/info',
- 'site/token/index',
- 'site/oauth/login-url/index',
- 'site/oauth/access-token/code',
- );
- }
- function _cloud_build_params($must_authorization_host = true) {
- global $_W;
- $pars = array();
- $pars['host'] = strexists($_SERVER['HTTP_HOST'], ':') ? parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) : $_SERVER['HTTP_HOST'];
- if (is_array($_W['setting']['site']) && !empty($_W['setting']['site']['url']) && !$must_authorization_host) {
- $pars['host'] = parse_url($_W['setting']['site']['url'], PHP_URL_HOST);
- }
- $pars['https'] = $_W['ishttps'] ? 1 : 0;
- $pars['family'] = IMS_FAMILY;
- $pars['version'] = IMS_VERSION;
- $pars['php_version'] = PHP_VERSION;
- $pars['current_host'] = $_SERVER['HTTP_HOST'];
- $pars['release'] = IMS_RELEASE_DATE;
- if (!empty($_W['setting']['site'])) {
- $pars['key'] = $_W['setting']['site']['key'];
- $pars['password'] = md5($_W['setting']['site']['key'] . $_W['setting']['site']['token']);
- }
- $clients = cloud_client_define();
- $string = '';
- foreach ($clients as $cli) {
- $string .= md5_file(IA_ROOT . $cli);
- }
- $pars['client'] = md5($string);
- return $pars;
- }
- function _cloud_shipping_parse($dat, $file) {
- if (is_error($dat)) {
- return error(-1, '网络传输故障,详情: ' . (strpos($dat['message'], 'Connection reset by peer') ? '云服务瞬时访问过大而导致网络传输中断,请稍后重试。' : $dat['message']));
- }
- $tmp = iunserializer($dat['content']);
- if (is_array($tmp) && is_error($tmp)) {
- if ($tmp['errno'] == '-2') {
- file_put_contents(IA_ROOT . '/framework/version.inc.php', str_replace("'x'", "'v'", file_get_contents(IA_ROOT . '/framework/version.inc.php')));
- }
- if ($tmp['errno'] == 401) {
- register_shutdown_function('cloud_reset_siteinfo');
- $tmp['message'] = '<div class="text-left"><span class="text-left">1.本域名为非微擎授权域名,系统已帮您自动重置,请使用授权域名访问或 <a href="">刷新重试</a>!</span><br><span class="text-left">2.如您已操作域名修改,请配置当前站点域名访问和https证书!</span><br><span class="text-left">3.刷新后若仍未解决请 <a target="_blank" href="https://task.w7.com/taskrelease?type_id=11&team_id=1">提交工单</a>!</span></div>';
- }
- return $tmp;
- }
- if ($dat['content'] == 'patching') {
- return error(-1, '补丁程序正在更新中,请稍后再试!');
- }
- if ($dat['content'] == 'frequent') {
- return error(-1, '更新操作太频繁,请稍后再试!');
- }
- if ($dat['content'] == 'blacklist') {
- return error(-1, '抱歉,您的站点已被列入云服务黑名单,云服务一切业务已被禁止,请联系微擎客服!');
- }
- if ($dat['content'] == 'install-theme-protect' || $dat['content'] == 'install-module-protect') {
- return error('-1', '此' . ($dat['content'] == 'install-theme-protect' ? '模板' : '模块') . '已设置版权保护,您只能通过云平台来安装,请先删除该模块的所有文件,购买后再行安装。');
- }
- $content = json_decode($dat['content'], true);
- if (!empty($content['error'])) {
- return error(-1, $content['error']);
- }
- if (!empty($content) && is_array($content)) {
- return $content;
- }
- if (strlen($dat['content']) != 32) {
- $dat['content'] = iunserializer($dat['content']);
- if (is_array($dat['content']) && isset($dat['content']['files'])) {
- if (!empty($dat['content']['manifest'])) {
- $dat['content']['manifest'] = base64_decode($dat['content']['manifest']);
- }
- if (!empty($dat['content']['scripts'])) {
- $dat['content']['scripts'] = base64_decode($dat['content']['scripts']);
- }
- return $dat['content'];
- }
- if (is_array($dat['content']) && isset($dat['content']['data'])) {
- $data = $dat['content'];
- } else {
- return error(-1, '云服务平台向您的服务器传输数据过程中出现错误,详情:' . $dat['content']);
- }
- } else {
- $data = @file_get_contents($file);
- @unlink($file);
- }
- $ret = @iunserializer($data);
- if (empty($data) || empty($ret)) {
- return error(-1, '云服务平台向您的服务器传输的数据校验失败.可尝试:1、更新缓存 2、云服务诊断');
- }
- $ret = iunserializer($ret['data']);
- if (is_array($ret) && is_error($ret)) {
- if ($ret['errno'] == '-2') {
- file_put_contents(IA_ROOT . '/framework/version.inc.php', str_replace("'x'", "'v'", file_get_contents(IA_ROOT . '/framework/version.inc.php')));
- }
- if ($ret['errno'] == '-3') {
- return array(
- 'errno' => $ret['errno'],
- 'message' => $ret['message'],
- 'cloud_id' => $ret['data'],
- );
- }
- }
- if (!is_error($ret) && is_array($ret)) {
- if (!empty($ret) && !empty($ret['state']) && $ret['state'] == 'fatal') {
- return error($ret['errorno'], '发生错误: ' . $ret['message']);
- }
- return $ret;
- } else {
- return error($ret['errno'], "发生错误: {$ret['message']}");
- }
- }
- function cloud_request($url, $post = '', $extra = array(), $timeout = 60) {
- global $_W;
- load()->func('communication');
- if (!empty($_W['setting']['cloudip']['ip']) && empty($extra['ip'])) {
- $extra['ip'] = $_W['setting']['cloudip']['ip'];
- }
- if (strexists($url, 's.w7.cc')) {
- $extra = array();
- }
- $response = ihttp_request($url, $post, $extra, $timeout);
- if (is_error($response)) {
- setting_save(array(), 'cloudip');
- }
- return $response;
- }
- function cloud_api($method, $data = array(), $extra = array(), $timeout = 60) {
- global $_W;
- $cache_key = cache_system_key('cloud_api', array('method' => md5($method . json_encode($data))));
- $cache = cache_load($cache_key);
- $extra['use_cache'] = !isset($extra['use_cache']) || !empty($extra['use_cache']) ? true : false;
- if (!empty($cache) && $extra['use_cache']) {
- return $cache;
- }
- $api_url = CLOUD_API_DOMAIN . '/%s';
- $not_must_authorization_method = cloud_not_must_authorization_method();
- $must_authorization_host = !in_array($method, $not_must_authorization_method);
- $pars = _cloud_build_params($must_authorization_host);
- if ($method != 'site/token/index') {
- $pars['token'] = cloud_build_transtoken();
- }
- $data = array_merge($pars, $data);
- if (starts_with($_SERVER['HTTP_USER_AGENT'], 'we7')) {
- $extra['CURLOPT_USERAGENT'] = $_SERVER['HTTP_USER_AGENT'];
- }
- if (!empty($_W['config']['setting']['useragent']) && starts_with($_W['config']['setting']['useragent'], 'we7')) {
- $extra['CURLOPT_USERAGENT'] = $_W['config']['setting']['useragent'];
- }
- $extra['X-We7-Cache'] = cache_random(4, $extra['use_cache']);
- $response = ihttp_request(sprintf($api_url, $method), $data, $extra, $timeout);
- $file = IA_ROOT . '/data/' . (!empty($data['file']) ? $data['file'] : str_replace('/', '', $method));
- $file = $file . cache_random();
- $ret = _cloud_shipping_parse($response, $file);
- if (is_error($ret)) {
- WeUtility::logging('cloud-api-error', array('method' => sprintf($api_url, $method), 'data' => $data, 'extra' => $extra, 'response' => $response), true);
- }
- if (!is_error($ret) && !empty($ret)) {
- if ($method == 'site/token/index') {
- cache_write($cache_key, $ret);
- } else {
- cache_write($cache_key, $ret, CACHE_EXPIRE_MIDDLE);
- }
- }
- return $ret;
- }
- function cloud_prepare() {
- global $_W;
- setting_load();
- if (empty($_W['setting']['site']['key']) || empty($_W['setting']['site']['token'])) {
- register_shutdown_function('cloud_reset_siteinfo');
- return error('-1', '站点注册信息丢失, 系统已帮您重置站点,请刷新重试!如还未解决您可以提交工单解决!');
- }
- return true;
- }
- function cloud_build($use_cache = true) {
- $pars['method'] = 'application.build4';
- $pars['file'] = 'application.build';
- $extra = array('use_cache' => $use_cache);
- $ret = cloud_api('site/build/index', $pars, $extra);
- if (is_error($ret)) {
- return $ret;
- }
- if ($ret['state'] == 'warning') {
- $ret['files'] = cloud_client_define();
- unset($ret['schemas']);
- unset($ret['scripts']);
- } else {
- $patch_path = sprintf('%s/data/patch/upgrade/%s', IA_ROOT, date('Ymd'));
- if (!is_dir($patch_path)) {
- mkdirs($patch_path);
- }
- $files = $files_allowed = array();
- if (!empty($ret['files'])) {
- foreach ($ret['files'] as $file) {
- $entry = IA_ROOT . $file['path'];
- if (!is_file($entry) || md5_file($entry) != $file['checksum']) {
- $files_allowed[] = $file['path'];
- }
- $entry = $patch_path . $file['path'];
- if (!is_file($entry)) {
- $entry = IA_ROOT . $file['path'];
- }
- if (!is_file($entry) || md5_file($entry) != $file['checksum']) {
- $files[] = $file['path'];
- }
- }
- }
- $ret['files'] = $files;
- if (!empty($ret['files'])) {
- cloud_bakup_files($ret['files']);
- } else {
- if (!empty($files_allowed)) {
- foreach ($files_allowed as $file) {
- $dir = pathinfo(IA_ROOT . $file, PATHINFO_DIRNAME);
- if (!is_dir($dir)) {
- mkdirs($dir);
- }
- file_put_contents(IA_ROOT . $file, file_get_contents($patch_path . $file));
- }
- rmdirs($patch_path);
- }
- }
- $schemas = array();
- if (!empty($ret['schemas'])) {
- load()->func('db');
- foreach ($ret['schemas'] as $remote) {
- $name = substr($remote['tablename'], 4);
- $local = db_table_schema(pdo(), $name);
- unset($remote['increment']);
- unset($local['increment']);
- if (empty($local)) {
- $schemas[] = $remote;
- } else {
- $sqls = db_table_fix_sql($local, $remote);
- if (!empty($sqls)) {
- $schemas[] = $remote;
- }
- }
- }
- }
- $ret['schemas'] = $schemas;
- $file_list = cloud_file_tree(IA_ROOT . '/data/update');
- if (!empty($file_list)) {
- foreach ($file_list as $file) {
- $file_basename = pathinfo($file, PATHINFO_BASENAME);
- preg_match('/^update\((\d{12})\-(\d{12})\)\.php$/', $file_basename, $matches);
- if (!is_file($file) || (IMS_RELEASE_DATE >= $matches[2] || empty($matches[2]))) {
- continue;
- }
- $ret['scripts'][] = array(
- 'message' => '微擎升级',
- 'script' => '',
- 'release' => $matches[2],
- 'fname' => $file_basename,
- );
- }
- }
- }
- if (IMS_FAMILY != $ret['family']) {
- $update_version_success = setting_upgrade_version($ret['family'], IMS_VERSION, IMS_RELEASE_DATE);
- if (empty($update_version_success)) {
- message('切换版本失败,请修改 /framework/version.inc.php 文件权限为 User 可写或是 777', 'refresh', 'error');
- } else {
- message('更新系统正在为您自动切换版本', 'refresh');
- }
- }
- $ret['upgrade'] = false;
- if (!empty($ret['files']) || !empty($ret['schemas']) || !empty($ret['scripts'])) {
- $ret['upgrade'] = true;
- }
- return $ret;
- }
- function cloud_check_file() {
- $pars['method'] = 'application.build4';
- $pars['file'] = 'application.build';
- $ret = cloud_api('site/build/index', $pars);
- if (is_error($ret)) {
- return $ret;
- }
- if ($ret['state'] == 'warning') {
- $ret['files'] = cloud_client_define();
- }
- return $ret;
- }
- function cloud_schema() {
- $pars['method'] = 'application.schema';
- $pars['file'] = 'application.schema';
- $ret = cloud_api('site/schema/index', $pars);
- if (!is_error($ret)) {
- $schemas = array();
- if (!empty($ret['schemas'])) {
- load()->func('db');
- foreach ($ret['schemas'] as $remote) {
- $name = substr($remote['tablename'], 4);
- $local = db_table_schema(pdo(), $name);
- unset($remote['increment']);
- unset($local['increment']);
- if (empty($local)) {
- $schemas[] = $remote;
- } else {
- $diffs = db_schema_compare($local, $remote);
- if (!empty($diffs)) {
- $schemas[] = $remote;
- }
- }
- }
- }
- $ret['schemas'] = $schemas;
- }
- return $ret;
- }
- function cloud_download($path, $type = '', $code = '') {
- global $_W;
- $pars = _cloud_build_params();
- $pars['method'] = 'application.shipping';
- $pars['path'] = $path;
- $pars['type'] = $type;
- $pars['gz'] = function_exists('gzcompress') && function_exists('gzuncompress') ? 'true' : 'false';
- $pars['download'] = 'true';
- $pars['token'] = cloud_build_transtoken();
- $pars['code'] = $code;
- if (starts_with($_SERVER['HTTP_USER_AGENT'], 'we7')) {
- $extra['CURLOPT_USERAGENT'] = $_SERVER['HTTP_USER_AGENT'];
- } else {
- $extra = array();
- }
- $extra['X-We7-Cache'] = cache_random();
- $dat = ihttp_request(CLOUD_API_DOMAIN . '/util/shipping/index', $pars, $extra);
- if (is_error($dat)) {
- WeUtility::logging('cloud-api-error', array('method' => CLOUD_API_DOMAIN . '/util/shipping/index', 'data' => $pars, 'extra' => $extra, 'response' => $dat), true);
- return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
- }
- if ($dat['content'] == 'success') {
- return true;
- }
- $content = @json_decode($dat['content'], true);
- if (isset($content['error'])) {
- WeUtility::logging('cloud-api-error', array('method' => CLOUD_API_DOMAIN . '/util/shipping/index', 'data' => $pars, 'extra' => $extra, 'response' => $dat), true);
- return error(1, $content['error']);
- }
- if (is_error($content)) {
- WeUtility::logging('cloud-api-error', array('method' => CLOUD_API_DOMAIN . '/util/shipping/index', 'data' => $pars, 'extra' => $extra, 'response' => $dat), true);
- return $content;
- } else {
- $ret = iunserializer($dat['content']);
- $gz = function_exists('gzcompress') && function_exists('gzuncompress');
- $file = base64_decode($ret['file']);
- if ($gz) {
- $file = gzuncompress($file);
- }
- $_W['setting']['site']['token'] = authcode(cache_load(cache_system_key('cloud_transtoken')), 'DECODE');
- $string = (md5($file) . $ret['path'] . $_W['setting']['site']['token']);
- if (!empty($_W['setting']['site']['token']) && md5($string) === $ret['sign']) {
- $error_file_list = array();
- if (!cloud_file_permission_pass($error_file_list)) {
- return error(-1, '请修复下列文件读写权限 : ' . implode('; ', $error_file_list));
- }
-
- if ($type == 'module' || $type == 'theme') {
- $patch_path = IA_ROOT;
- } else {
- $patch_path = sprintf('%s/data/patch/upgrade/%s', IA_ROOT, date('Ymd'));
- }
- $path = $patch_path . $ret['path'];
- load()->func('file');
- @mkdirs(dirname($path));
- if (file_put_contents($path, $file)) {
- return true;
- } else {
- return error(-1, '写入失败,请检查是否有写入权限或是否磁盘已满!');
- }
- }
- return error(-1, '与云服务校验失败,更新缓存后重试!');
- }
- }
- function cloud_m_prepare($name, $extra = array()) {
- $params = array(
- 'method' => 'module.check',
- 'module' => $name,
- );
- if (!empty($extra)) {
- $params = array_merge($extra, $params);
- }
- $ret = cloud_api('module/check', $params);
- return $ret;
- }
- function cloud_m_code($code) {
- load()->model('extension');
- if (empty($code)) {
- return array();
- }
- $ret = cloud_api('module/code', array('code' => $code));
- if (!is_error($ret)) {
- $manifest = ext_module_manifest_parse($ret['manifest']);
- $modulename = $manifest['application']['identifie'];
- $dir = IA_ROOT . '/addons/' . $modulename;
- $files = array();
- if (!empty($ret['files']['private_file_list'])) {
- $ret['files']['common_file_list'] = array_merge($ret['files']['common_file_list'], $ret['files']['private_file_list']);
- }
- if (!empty($ret['files']['common_file_list'])) {
- foreach ($ret['files']['common_file_list'] as $file) {
- if ($file['path'] == '/map.json') {
- continue;
- }
- if (empty(safe_gpc_path($file['path']))) {
- $messy_code_file .= '<br>/' . $modulename . $file['path'];
- } else {
- $entry = $dir . $file['path'];
- if (!is_file($entry) || md5_file($entry) != $file['checksum']) {
- $files[] = '/' . $modulename . $file['path'];
- }
- }
- }
- }
- $ret['files'] = $files;
- if (!empty($messy_code_file) && !igetcookie($code . '_install')) {
- return error(-2, '包含命名不规范文件,请联系开发者处理或忽略异常文件点击“确定”后再次输入测试码以继续安装。<br>文件如下:' . $messy_code_file);
- }
- $schemas = array();
- if (!empty($ret['schemas'])) {
- load()->func('db');
- foreach ($ret['schemas'] as $remote) {
- $name = substr($remote['tablename'], 4);
- $local = db_table_schema(pdo(), $name);
- unset($remote['increment']);
- unset($local['increment']);
- if (empty($local)) {
- $schemas[] = $remote;
- } else {
- $diffs = db_table_fix_sql($local, $remote);
- if (!empty($diffs)) {
- $schemas[] = $remote;
- }
- }
- }
- }
- $ret['type'] = 'module';
- $ret['schemas'] = $schemas;
- $module = table('modules')->getByName($modulename);
- if (empty($module)) {
- $ret['install'] = STATUS_ON;
- } else {
- $ret['upgrade'] = STATUS_ON;
- }
- }
- return $ret;
- }
- function cloud_m_code_query($use_cache = true) {
- return cloud_api('module/code/query', array(), array('use_cache' => $use_cache));
- }
- function cloud_m_code_generate($data) {
- $result = cloud_api('module/code/generate', array('module_name' => $data['module_name'], 'module_version' => $data['module_version']));
- if (is_error($result)) {
- return $result['message'];
- }
- return $result['code'];
- }
- function cloud_m_code_available($code = array()) {
- return cloud_api('module/code/available', array('code' => $code));
- }
- function cloud_m_build($modulename, $type = 'install') {
- $type = in_array($type, array('uninstall', 'upgrade', 'install')) ? $type : 'install';
- if (empty($modulename)) {
- return array();
- }
- $module_info = cloud_m_info($modulename);
- if (is_error($module_info)) {
- return $module_info;
- }
- $pars['module'] = $modulename;
- $pars['type'] = $type;
- $pars['module_version'] = $module_info['version']['version'];
- $pars['file'] = 'module.build';
- $ret = cloud_api('module/build', $pars);
- if (!is_error($ret)) {
- $dir = IA_ROOT . '/addons/' . $modulename;
- $files = array();
- $messy_code_file = '';
- if (!empty($ret['files'])) {
- foreach ($ret['files'] as $file) {
- if ($file['path'] == '/map.json') {
- continue;
- }
- if (empty(safe_gpc_path($file['path']))) {
- $messy_code_file .= '<br>/' . $modulename . $file['path'];
- } else {
- $entry = $dir . $file['path'];
- if (!is_file($entry) || md5_file($entry) != $file['checksum']) {
- $files[] = '/' . $modulename . $file['path'];
- }
- }
- }
- }
- $ret['files'] = $files;
- if (!empty($messy_code_file) && !igetcookie($modulename . '_install')) {
- return error(-2, '包含命名不规范文件,请联系开发者处理或忽略异常文件点击“确定”后再次点击“去安装”以继续安装。<br>文件如下:' . $messy_code_file);
- }
- $schemas = array();
- if (!empty($ret['schemas'])) {
- load()->func('db');
- foreach ($ret['schemas'] as $remote) {
- $name = substr($remote['tablename'], 4);
- $local = db_table_schema(pdo(), $name);
- unset($remote['increment']);
- unset($local['increment']);
- if (empty($local)) {
- $schemas[] = $remote;
- } else {
- $diffs = db_table_fix_sql($local, $remote);
- if (!empty($diffs)) {
- $schemas[] = $remote;
- }
- }
- }
- }
- $ret['type'] = 'module';
- $ret['schemas'] = $schemas;
-
- $module = table('modules')->getByName($modulename);
- if (empty($module)) {
- $ret['install'] = STATUS_ON;
- } else {
- $ret['upgrade'] = STATUS_ON;
- }
- }
- return $ret;
- }
- function cloud_m_query($module = array(), $page = 1, $use_cache = true) {
- $pars['method'] = 'module.query';
- if (empty($module)) {
- $module = cloud_extra_module();
- }
- if (!is_array($module)) {
- $module = array($module);
- }
- $pars['page'] = max(1, intval($page));
- $pars['module'] = base64_encode(iserializer($module));
- $ret = cloud_api('module/query', $pars, array('use_cache' => $use_cache));
- if (isset($ret['error'])) {
- return error(1, $ret['error']);
- }
- if (!is_error($ret)) {
- $pirate_apps = empty($ret['pirate_apps']) ? array() : $ret['pirate_apps'];
- unset($ret['pirate_apps']);
- $support_names = array('app', 'wxapp', 'webapp', 'system_welcome', 'android', 'ios', 'aliapp', 'baiduapp', 'toutiaoapp');
- $record_module = array();
- foreach ($ret['data'] as $modulename => &$info) {
- if (!empty($info['name'])) {
- $record_module[] = $info['name'];
- }
- if (empty($info['site_branch'])) {
- continue;
- }
- foreach ($support_names as $support) {
- if (is_array($info['site_branch']['bought']) && in_array($support, $info['site_branch']['bought']) && !empty($info['site_branch']["{$support}_support"]) && $info['site_branch']["{$support}_support"] == 2) {
- $info['site_branch']["{$support}_support"] = 2;
- } else {
- $info['site_branch']["{$support}_support"] = 1;
- }
- }
- }
- $ret['pirate_apps'] = $pirate_apps;
- table('modules')->where(array('name IN' => $record_module))->fill(array('cloud_record' => STATUS_ON))->save();
- }
- return $ret;
- }
- function cloud_m_info($name) {
- $pars['method'] = 'module.info';
- $pars['module'] = $name;
- $ret = cloud_api('module/info', $pars);
- return $ret;
- }
- function cloud_m_upgradeinfo($modulename) {
- load()->model('module');
- $module = module_fetch($modulename);
- $pars['method'] = 'module.info';
- $pars['module'] = $modulename;
- $pars['curversion'] = $module['version'];
- $pars['isupgrade'] = 1;
- $ret = cloud_api('module/info', $pars);
- if (empty($ret)) {
- return array();
- }
- if (is_error($ret)) {
- return $ret;
- }
- if (version_compare($ret['version']['version'], $module['version'], '>')) {
- $ret['upgrade'] = true;
- }
- $ret['site_branch'] = $ret['branches'][$ret['version']['branch_id']];
- $ret['from'] = 'cloud';
- foreach ($ret['branches'] as &$branch) {
- if ($branch['displayorder'] > $ret['site_branch']['displayorder'] || ($branch['displayorder'] == $ret['site_branch']['displayorder'] && $ret['site_branch']['id'] < intval($branch['id']))) {
- $ret['new_branch'] = true;
- }
- $branch['id'] = intval($branch['id']);
- $branch['version']['description'] = preg_replace('/\n/', '<br/>', htmlspecialchars_decode($branch['version']['description']));
- $branch['displayorder'] = intval($branch['displayorder']);
- $branch['day'] = intval(date('d', $branch['version']['createtime']));
- $branch['month'] = date('Y.m', $branch['version']['createtime']);
- $branch['hour'] = date('H:i', $branch['version']['createtime']);
- }
- unset($branch);
- return $ret;
- }
- function cloud_t_prepare($name, $extra = array()) {
- $pars = array(
- 'method' => 'theme.check',
- 'theme' => $name,
- );
- if (!empty($extra)) {
- $pars = array_merge($extra, $pars);
- }
- $dat = cloud_api('theme/check', $pars);
- return $dat;
- }
- function cloud_t_query() {
- $pars['method'] = 'theme.query';
- $pars['theme'] = cloud_extra_theme();
- $ret = cloud_api('theme/query', $pars);
- return $ret;
- }
- function cloud_t_info($module_name) {
- $pars['method'] = 'theme.info';
- $pars['theme'] = $module_name;
- $ret = cloud_api('theme/info', $pars);
- return $ret;
- }
- function cloud_t_build($module_name) {
- if (empty($module_name)) {
- return array();
- }
- $theme = table('modules')->getTemplateByName(trim($module_name));
- $pars['method'] = 'theme.build';
- $pars['theme'] = $module_name;
- if (!empty($theme)) {
- $pars['themeversion'] = $theme['version'];
- }
- $ret = cloud_api('theme/build', $pars);
- if (!is_error($ret)) {
- $dir = IA_ROOT . '/app/themes/' . $module_name;
- $files = array();
- if (!empty($ret['files'])) {
- foreach ($ret['files'] as $file) {
- if ($file['path'] == '/map.json') {
- continue;
- }
- $entry = $dir . $file['path'];
- if (!is_file($entry) || md5_file($entry) != $file['checksum']) {
- $files[] = '/' . $module_name . $file['path'];
- }
- }
- }
- $ret['files'] = $files;
- if (!empty($theme) && version_compare($theme['version'], $ret['version']) == -1) {
- $ret['upgrade'] = true;
- } else {
- $ret['upgrade'] = false;
- }
- $ret['type'] = 'theme';
-
- if (empty($theme)) {
- $ret['install'] = 1;
- }
- }
- return $ret;
- }
- function cloud_t_upgradeinfo($module_name) {
- if (empty($module_name)) {
- return array();
- }
- $theme = table('modules')->getTemplateByName(trim($module_name));
- if (empty($theme)) {
- return array();
- }
- return cloud_api('theme/upgrade', array(
- 'method' => 'theme.upgrade',
- 'theme' => $theme['name'],
- 'version' => $theme['version'],
- 'isupgrade' => 1,
- ));
- }
- function cloud_sms_send($mobile, $content, $postdata = array(), $custom_sign = '', $use_system_balance = false) {
- global $_W;
- if (!preg_match('/^1\d{10}$/', $mobile) || empty($content)) {
- return error(1, '发送短信失败, 原因: 手机号错误或内容为空.');
- }
- $sms_send_info = pdo_get('uni_verifycode', array('receiver' => $mobile));
- if (!empty($sms_send_info) && 10 < $sms_send_info['total'] && 7200 >= TIMESTAMP - $sms_send_info['createtime']) {
- return error(-1, '同一手机号两小时内请求发送验证码超出10次');
- }
- $uniacid = empty($use_system_balance) ? $_W['uniacid'] : 0;
- if (empty($uniacid)) {
- $setting_sms_blance = setting_load('system_sms_balance');
- $balance = !empty($setting_sms_blance['system_sms_balance']) ? $setting_sms_blance['system_sms_balance'] : 0;
- $setting_sms_sign = setting_load('site_sms_sign');
- $setting_sms_sign = !empty($setting_sms_sign['site_sms_sign']) ? $setting_sms_sign['site_sms_sign'] : array();
- $sign = !empty($setting_sms_sign['system_sms_sign']) ? $setting_sms_sign['system_sms_sign'] : '';
- } else {
- $row = pdo_get('uni_settings', array('uniacid' => $uniacid), array('notify'));
- $row['notify'] = @iunserializer($row['notify']);
- $config = empty($row['notify']['sms']) ? array() : $row['notify']['sms'];
- $balance = empty($config['balance']) ? 0 : intval($config['balance']);
- $sign = empty($custom_sign) && !empty($config['signature']) ? $config['signature'] : $custom_sign;
- $account_name = empty($_W['account']['type_name']) ? '' : $_W['account']['type_name'];
- $account_name .= empty($_W['account']['name']) ? '' : " [{$_W['account']['name']}] ";
- }
- if (empty($sign) || $sign == 'null') {
- $sign = '微擎';
- }
- $sms_info = cloud_sms_info();
- if ($balance < 1 || empty($sms_info['sms_count'])) {
- return error(-1, '短信不足');
- }
- $pars = _cloud_build_params(false);
- $pars['method'] = 'sms.send';
- $pars['mobile'] = $mobile;
- $pars['uniacid'] = $uniacid;
- $pars['account_name'] = empty($account_name) ? '当前公众号' : $account_name;
- $pars['balance'] = $balance;
- $pars['sign'] = $sign;
- if (!empty($postdata)) {
- $pars['content'] = $content;
- $pars['postdata'] = $postdata;
- } else {
- $pars['content'] = "{$content} 【{$sign}】";
- }
- $extra = array();
- if (starts_with($_SERVER['HTTP_USER_AGENT'], 'we7')) {
- $extra['CURLOPT_USERAGENT'] = $_SERVER['HTTP_USER_AGENT'];
- }
- $response = cloud_request(CLOUD_API_DOMAIN . '/sms/send/index', $pars, $extra);
- if (is_error($response)) {
- return error($response['errno'], '短信发送失败, 原因:' . $response['message']);
- }
- $result = json_decode($response['content'], true);
- if (is_error($result)) {
- return error($result['errno'], $result['message']);
- }
- if (!empty($result['error'])) {
- return error(-1, $result['error']);
- }
- if (intval($result['errno']) != -1) {
- if (!empty($uniacid)) {
- $row['notify']['sms']['balance'] = $row['notify']['sms']['balance'] - 1;
- if ($row['notify']['sms']['balance'] < 0) {
- $row['notify']['sms']['balance'] = 0;
- }
- pdo_update('uni_settings', array('notify' => iserializer($row['notify'])), array('uniacid' => $uniacid));
- uni_setting_save('notify', $row['notify']);
- } else {
- $balance -= 1;
- if ($balance < 0) {
- $balance = 0;
- }
- setting_save($balance, 'system_sms_balance');
- $sms_info['sms_count'] = $sms_info['sms_count'] - 1;
- if ($sms_info['sms_count'] < 0) {
- $sms_info['sms_count'] = 0;
- }
- setting_save($sms_info, 'sms.info');
- }
- }
- return true;
- }
- function cloud_sms_info() {
- return cloud_api('sms/info');
- }
- function cloud_sms_sign($page = 1, $start_time = 0, $end_time = 0, $status_audit = 0, $status_order = 0) {
- $data = array(
- 'page' => max(1, intval($page))
- );
- if ($start_time) {
- $data['start_time'] = $start_time;
- }
- if ($end_time) {
- $data['end_time'] = $end_time;
- }
- if ($status_audit) {
- $data['status_audit'] = $status_audit;
- }
- if ($status_order) {
- $data['status_order'] = $status_order;
- }
- return cloud_api('sms/sign', $data);
- }
- function cloud_sms_log($mobile = 0, $time = array(), $page = 1, $page_size = 10, $status = -1) {
- $time = !empty($time) ? $time : array(strtotime('-7 days'), time());
- return cloud_api('sms/log', array(
- 'mobile' => $mobile,
- 'time' => $time,
- 'page' => $page,
- 'page_size' => $page_size,
- 'status' => $status
- ), array('use_cache' => false));
- }
- function cloud_sms_trade($page = 1, $start_time = 0, $end_time = 0, $status_order = 0) {
- $data = array(
- 'page' => max(1, intval($page))
- );
- if ($start_time) {
- $data['start_time'] = $start_time;
- }
- if ($end_time) {
- $data['end_time'] = $end_time;
- }
- if ($status_order) {
- $data['status_order'] = $status_order;
- }
- if (empty($data['start_time']) && empty($data['end_time'])) {
- $data['start_time'] = strtotime('-1 year');
- $data['end_time'] = time();
- }
- $data['time'] = array($data['start_time'], $data['end_time']);
- return cloud_api('sms/trade', $data);
- }
- function cloud_sms_edit($sign) {
- return cloud_api('sms/re-audit-sign', array('sign_id' => $sign['sign_id'], 'sms_sign' => $sign['sign_content']));
- }
- function cloud_sms_count_remained() {
- $cache_key = cache_system_key('cloud_api', array('method' => md5('cloud_sms_count_remained')));
- $cache = cache_load($cache_key);
- if (!empty($cache) && !empty($cache['expire']) && $cache['expire'] > TIMESTAMP) {
- return $cache['cloud_sms_count_remained'];
- }
- $sms_info = cloud_sms_info();
- if (is_error($sms_info)) {
- return $sms_info;
- }
- $sms_count = $sms_info['sms_count'];
- $sms_accounts = table('uni_settings')->select(array('uniacid', 'notify'))->where(array('notify LIKE' => '%sms%'))->getall();
- $setting_sms_blance = setting_load('system_sms_balance');
- $system_sms_balance = !empty($setting_sms_blance['system_sms_balance']) ? $setting_sms_blance['system_sms_balance'] : 0;
- $sms_count -= $system_sms_balance;
- if (empty($sms_accounts)) {
- return $sms_count;
- }
- foreach ($sms_accounts as $sms_account) {
- $notify = iunserializer($sms_account['notify']);
- $sms_count -= $notify['sms']['balance'];
- }
- $sms_count = max(0, $sms_count);
- $cache_data = array(
- 'cloud_sms_count_remained' => $sms_count
- );
- cache_write($cache_key, $cache_data, CACHE_EXPIRE_MIDDLE);
- return $sms_count;
- }
- function cloud_extra_module() {
- load()->model('module');
- $result = array();
- $cloud = table('modules_cloud')->getUninstallModule(MODULE_CLOUD_UNINSTALL);
- if (empty($cloud)) {
- return $result;
- }
- $module_support_type = array_keys(module_support_type());
- $installed = table('modules')->getInstalled();
- $recycle = table('modules_recycle')->where('type', 2)->getall('name');
- foreach ($installed as $install_module) {
- if ($install_module['cloud_record']) {
- continue;
- }
- $result[$install_module['name']] = array(
- 'name' => $install_module['name'],
- 'version' => $install_module['version'],
- );
- $all_uninstall = true;
- foreach ($module_support_type as $support) {
- $type = str_replace('_support', '', $support);
- if ($install_module[$support] == 2) {
- $all_uninstall = false;
- $result[$install_module['name']]['support'][$type]['is_install'] = 2;
- }
- }
- if ($all_uninstall) {
- unset($result[$install_module['name']]);
- }
- }
- foreach ($recycle as $recycle_module) {
- if (empty($result[$recycle_module['name']])) {
- $result[$recycle_module['name']] = array(
- 'name' => $recycle_module['name'],
- );
- }
- $in_recycle = false;
- foreach ($module_support_type as $support) {
- $type = str_replace('_support', '', $support);
- if ($recycle_module[$support]) {
- $in_recycle = true;
- $result[$recycle_module['name']]['support'][$type] = array(
- 'is_recycle' => 2
- );
- }
- }
- if (!$in_recycle) {
- unset($result[$recycle_module['name']]);
- }
- }
- foreach ($cloud as $cloud_module) {
- if (empty($result[$cloud_module['name']])) {
- $result[$cloud_module['name']] = array(
- 'name' => $cloud_module['name'],
- 'version' => $cloud_module['version'],
- );
- }
- $in_cloud = false;
- foreach ($module_support_type as $support) {
- $type = str_replace('_support', '', $support);
- if ($cloud_module[$support] == 2) {
- $in_cloud = true;
- $result[$cloud_module['name']]['support'][$type] = array(
- 'is_uninstall' => 2
- );
- }
- }
- if (!$in_cloud) {
- unset($result[$cloud_module['name']]);
- }
- }
- return $result;
- }
- function cloud_extra_theme() {
- $themes = pdo_getall('modules', array('application_type' => APPLICATION_TYPE_TEMPLATES, 'name !=' => 'default'), 'name', 'name');
- if (!empty($themes)) {
- return base64_encode(iserializer(array_keys($themes)));
- } else {
- return '';
- }
- }
- function cloud_module_setting($acid, $module) {
- $pars = array(
- 'acid' => $acid,
- 'module_name' => $module['name'],
- 'module_version' => $module['version'],
- );
- return cloud_api('module/setting/index', $pars);
- }
- function cloud_module_setting_save($acid, $module_name, $setting) {
- $pars = array(
- 'acid' => $acid,
- 'module_name' => $module_name,
- 'setting' => $setting,
- );
- return cloud_api('module/setting/save', $pars, array('use_cache' => false));
- }
- function cloud_module_list($title, $support_type, $page = 1, $per_page = 20) {
- $pars = array(
- 'title' => $title,
- 'support_type' => $support_type,
- 'page' => $page,
- 'per_page' => $per_page,
- );
- return cloud_api('module/list', $pars);
- }
- function cloud_site_info() {
- return cloud_api('site/info');
- }
- function cloud_reset_siteinfo() {
- global $_W;
- return cloud_api('site/register/profile', array('url' => $_W['siteroot']));
- }
- function cloud_wxapp_info($moduleinfo) {
- return cloud_api('wxapp/info', $moduleinfo);
- }
- function cloud_wxapp_login_qrcode() {
- return cloud_api('wxapp/login/qr-code', array(), array('use_cache' => false));
- }
- function cloud_wxapp_login_qrscan($uuid) {
- return cloud_api('wxapp/login/qr-scan', $uuid);
- }
- function cloud_wxapp_publish($data) {
- return cloud_api('wxapp/publish', $data);
- }
- function cloud_miniapp_get_package($data) {
- return cloud_api('wxapp/publish/download', $data);
- }
- function cloud_auth_url($forward, $data = array()) {
- global $_W;
- if (!empty($_W['setting']['site']['url']) && !strexists($_W['siteroot'], $_W['setting']['site']['url'])) {
- $url = $_W['setting']['site']['url'];
- } else {
- $url = rtrim($_W['siteroot'], '/');
- }
- $auth = array();
- $auth['key'] = '';
- $auth['password'] = '';
- $auth['url'] = $url;
- $auth['referrer'] = intval($_W['config']['setting']['referrer']);
- $auth['version'] = IMS_VERSION;
- $auth['forward'] = $forward;
- $auth['family'] = IMS_FAMILY;
- if (!empty($_W['setting']['site']['key']) && !empty($_W['setting']['site']['token'])) {
- $auth['key'] = $_W['setting']['site']['key'];
- $auth['password'] = md5($_W['setting']['site']['key'] . $_W['setting']['site']['token']);
- }
- if ($data && is_array($data)) {
- $auth = array_merge($auth, $data);
- }
- $query = base64_encode(json_encode($auth));
- $auth_url = 'https://s.w7.cc/index.php?c=auth&a=passport&__auth=' . $query;
- return $auth_url;
- }
- function cloud_module_setting_prepare($module, $binding) {
- global $_W;
- $auth = _cloud_build_params();
- $auth['arguments'] = array(
- 'binding' => $binding,
- 'acid' => $_W['uniacid'],
- 'type' => 'module',
- 'module' => $module,
- );
- $iframe_auth_url = cloud_auth_url('module', $auth);
- return $iframe_auth_url;
- }
- function cloud_resource_to_local($uniacid, $type, $url) {
- global $_W;
- load()->func('file');
- $setting = $_W['setting']['upload'][$type];
- if (substr($url, 0, 2) == '//') {
- $url = 'http:' . $url;
- }
- if (!file_is_image($url)) {
- return error(1, '远程图片后缀非法,请重新上传');
- }
- $pathinfo = pathinfo($url);
- $extension = $pathinfo['extension'];
- if ($uniacid == 0) {
- $setting['folder'] = "{$type}s/global/" . date('Y/m/');
- } else {
- $setting['folder'] = "{$type}s/{$uniacid}/" . date('Y/m/');
- }
- $originname = pathinfo($url, PATHINFO_BASENAME);
- $filename = file_random_name(ATTACHMENT_ROOT . '/' . $setting['folder'], $extension);
- $pathname = $setting['folder'] . $filename;
- $fullname = ATTACHMENT_ROOT . $pathname;
- mkdirs(dirname($fullname));
- load()->func('communication');
- $response = ihttp_get($url);
- if (is_error($response)) {
- return error(1, $response['message']);
- }
- if (file_put_contents($fullname, $response['content']) == false) {
- return error(1, '提取文件失败');
- }
- if (!empty($_W['setting']['remote']['type'])) {
- $remotestatus = file_remote_upload($pathname);
- if (is_error($remotestatus)) {
- return error(1, '远程附件上传失败,请检查配置并重新上传');
- } else {
- file_delete($pathname);
- }
- }
- $data = array(
- 'uniacid' => $uniacid,
- 'uid' => intval($_W['uid']),
- 'filename' => $originname,
- 'attachment' => $pathname,
- 'type' => $type == 'image' ? 1 : 2,
- 'createtime' => TIMESTAMP,
- );
- pdo_insert('core_attachment', $data);
- $data['url'] = tomedia($pathname);
- $data['id'] = pdo_insertid();
- return $data;
- }
- function cloud_bakup_files($files) {
- global $_W;
- if (empty($files)) {
- return false;
- }
- $map = json_encode($files);
- $hash = md5($map . $_W['config']['setting']['authkey']);
- if ($handle = opendir(IA_ROOT . '/data/patch/backup/' . date('Ymd'))) {
- while (false !== ($patchpath = readdir($handle))) {
- if ($patchpath != '.' && $patchpath != '..') {
- if (strexists($patchpath, $hash)) {
- return false;
- }
- }
- }
- }
- $path = IA_ROOT . '/data/patch/backup/' . date('Ymd') . '/' . date('Hi') . '_' . $hash;
- load()->func('file');
- if (!is_dir($path) && mkdirs($path)) {
- foreach ($files as $file) {
- if (file_exists(IA_ROOT . $file)) {
- mkdirs($path . '/' . dirname($file));
- file_put_contents($path . '/' . $file, file_get_contents(IA_ROOT . $file));
- }
- }
- file_put_contents($path . '/' . 'map.json', $map);
- }
- return false;
- }
- function cloud_build_transtoken() {
- $pars['method'] = 'application.token';
- $pars['file'] = 'application.build';
- $ret = cloud_api('site/token/index', $pars);
- if (!empty($ret['token'])) {
- cache_write(cache_system_key('cloud_transtoken'), authcode($ret['token'], 'ENCODE'));
- return $ret['token'];
- }
- return '';
- }
- function cloud_build_schemas($schemas) {
- $database = array();
- if (empty($schemas) || !is_array($schemas)) {
- return $database;
- }
- foreach ($schemas as $remote) {
- $row = array();
- $row['tablename'] = $remote['tablename'];
- $name = substr($remote['tablename'], 4);
- $local = db_table_schema(pdo(), $name);
- unset($remote['increment']);
- unset($local['increment']);
- if (empty($local)) {
- $row['new'] = true;
- } else {
- $row['new'] = false;
- $row['fields'] = array();
- $row['indexes'] = array();
- $diffs = db_schema_compare($local, $remote);
- if (!empty($diffs['fields']['less'])) {
- $row['fields'] = array_merge($row['fields'], $diffs['fields']['less']);
- }
- if (!empty($diffs['fields']['diff'])) {
- $row['fields'] = array_merge($row['fields'], $diffs['fields']['diff']);
- }
- if (!empty($diffs['indexes']['less'])) {
- $row['indexes'] = array_merge($row['indexes'], $diffs['indexes']['less']);
- }
- if (!empty($diffs['indexes']['diff'])) {
- $row['indexes'] = array_merge($row['indexes'], $diffs['indexes']['diff']);
- }
- $row['fields'] = implode(' ', $row['fields']);
- $row['indexes'] = implode(' ', $row['indexes']);
- }
- $database[] = $row;
- }
- return $database;
- }
- function cloud_file_permission_pass(&$error_file_list = array()) {
- $cache_key = cache_system_key('cloud_file_permission_pass');
- $cache = cache_load($cache_key);
- if ($cache) {
- return true;
- }
- $check_path = array(
- '/api',
- '/app/common',
- '/app/resource',
- '/app/source',
- '/app/themes/default',
- '/web/common',
- '/web/resource',
- '/web/source',
- '/web/themes/default',
- '/web/themes/black',
- '/web/themes/classical',
- '/web/themes/2.0',
- '/framework/builtin',
- '/framework/class',
- '/framework/model',
- '/framework/function',
- '/framework/table',
- '/framework/library',
- '/payment',
- );
- $check_file = array(
- '/web/index.php',
- '/framework/bootstrap.inc.php',
- '/framework/version.inc.php',
- '/framework/const.inc.php',
- );
- $sub_paths = array();
- foreach ($check_path as $path) {
- $file_list = cloud_file_tree(IA_ROOT . $path);
- if (!empty($file_list)) {
- foreach ($file_list as $file) {
- if (is_file($file)) {
- $sub_path = pathinfo($file, PATHINFO_DIRNAME);
- if (empty($sub_paths[$sub_path])) {
- if (!cloud_path_is_writable($sub_path)) {
- $error_file_list[] = str_replace(IA_ROOT, '', $sub_path);
- }
- $sub_paths[$sub_path] = $sub_path;
- }
- }
- if (!is_writable($file)) {
- $error_file_list[] = str_replace(IA_ROOT, '', $file);
- }
- }
- }
- }
- foreach ($check_file as $file) {
- if (!is_writable(IA_ROOT . $file)) {
- $error_file_list[] = str_replace(IA_ROOT, '', $file);
- }
- }
- if (empty($error_file_list)) {
- cache_write($cache_key, true, 600);
- return true;
- }
- return false;
- }
- function cloud_file_tree($path, $include = array()) {
- $files = array();
- if (!empty($include)) {
- $ds = glob($path . '/{' . implode(',', $include) . '}', GLOB_BRACE);
- } else {
- $ds = glob($path . '/*');
- }
- if (is_array($ds)) {
- foreach ($ds as $entry) {
- if (is_file($entry)) {
- $files[] = $entry;
- }
- if (is_dir($entry)) {
- $rs = cloud_file_tree($entry);
- foreach ($rs as $f) {
- $files[] = $f;
- }
- }
- }
- }
- return $files;
- }
- function cloud_path_is_writable($dir) {
- $writeable = false;
- if (!is_dir($dir)) {
- @mkdir($dir, 0755);
- }
- if (is_dir($dir)) {
- if ($fp = fopen("$dir/test.txt", 'w')) {
- fclose($fp);
- unlink("$dir/test.txt");
- $writeable = true;
- } else {
- $writeable = false;
- }
- }
- return $writeable;
- }
- function cloud_get_store_notice() {
- return cloud_api('we7/site/notify/system');
- }
- function cloud_v_to_xs($url) {
- if (empty($url)) {
- return false;
- }
- $pars = _cloud_build_params();
- $pars['method'] = 'module.query';
- $pars['url'] = urlencode($url);
- cloud_request(CLOUD_API_DOMAIN . '/site/pirate/index', $pars);
- return true;
- }
- function cloud_w7_request_token($js_secret, $use_cache = true) {
- global $_W;
- if (empty($js_secret) || empty($_W['setting']['site']) || empty($_W['setting']['site']['key'])) {
- return error(-1, '获取站点信息失败!');
- }
- $cache_key = cache_system_key('cloud_w7_request_token');
- if ($use_cache) {
- $cache = cache_load($cache_key);
- if ($cache) {
- return $cache;
- }
- }
- $js_token = authcode($js_secret, 'ENCODE', $_W['setting']['site']['key']);
- $data = array('js_token' => $js_token);
- $ret = cloud_api('site/accesstoken/with-js-token', $data);
- if (is_error($ret)) {
- return $ret;
- }
- cache_write($cache_key, $ret['access_token'], $ret['expire_time'] - TIMESTAMP);
- return $ret['access_token'];
- }
- function cloud_check_mobile($data) {
- return cloud_api('we7/oauth/user-bind/mobile-bind-info', $data);
- }
- function cloud_unbind_user($uid, $openid = '') {
- return cloud_api('we7/oauth/user-bind/unbind', array('out_user_id' => $uid, 'out_openid' => $openid));
- }
- function cloud_bind_user_info($uid) {
- return cloud_api('we7/oauth/user-bind/info', array('out_user_id' => $uid));
- }
- function cloud_oauth_token($code) {
- return cloud_api('site/oauth/access-token/code', array('code' => $code));
- }
- function cloud_oauth_user($token) {
- return cloud_api('site/oauth/user/info', array('access_token' => $token), array('use_cache' => false));
- }
- function cloud_oauth_login_url($redirect) {
- $result = cloud_api('site/oauth/login-url/index', array('redirect' => $redirect));
- if (empty($result['url'])) {
- return error(-1, '获取授权登录url失败,请联系管理员处理!');
- }
- return $result['url'];
- }
- function cloud_oauth_register_url($data) {
- return cloud_api('site/oauth/register-url/index', $data);
- }
- function cloud_bind_user_token($data) {
- return cloud_api('we7/oauth/user-bind/complete-with-accesstoken', $data);
- }
- function cloud_console_index_url($data) {
- return cloud_api('we7/site/console/index-url', $data);
- }
- function cloud_console_invite_url($redirect = '', $state = array()) {
- return cloud_api('we7/site/console/share-url', array('role_identify' => ACCOUNT_MANAGE_NAME_GENERAL_RULE, 'redirect_route' => $redirect, 'state' => $state), array('use_cache' => false));
- }
- function cloud_console_setting() {
- return cloud_api('we7/site/console/setting', array(), array('use_cache' => false));
- }
- function cloud_rgapi_sign() {
- global $_W;
- $cache_key = cache_system_key('cloud_rgapi_sign');
- $cache = cache_load($cache_key);
- if (!empty($cache)) {
- return $cache;
- }
- load()->library('sdk-module');
- try {
- $api = new \W7\Sdk\Module\Api($_W['setting']['site']['key'], $_W['setting']['site']['token'], '', 0, CLOUD_V3API_DOMAIN_PRE);
- $token = $api->login()->toArray();
- if (!empty($token) && is_array($token)) {
- $token = $token['token'];
- } else {
- return error(-1, 'API授权获取站点授权失败,请联系管理员处理!');
- }
- cache_write($cache_key, $token, CACHE_EXPIRE_LONG * 2);
- return urlencode($token);
- } catch (\W7\Sdk\Module\Exceptions\ApiException $e) {
- return error(-1, $e->getResponse()->getBody()->getContents());
- }
- }
|