人人商城

cloud.mod.php 41KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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() {
  22. global $_W;
  23. $pars = array();
  24. if (is_array($_W['setting']['site']) && !empty($_W['setting']['site']['url'])) {
  25. $pars['host'] = parse_url($_W['setting']['site']['url'], PHP_URL_HOST);
  26. }
  27. if (empty($pars['host'])) {
  28. $pars['host'] = $_SERVER['HTTP_HOST'];
  29. }
  30. $pars['family'] = IMS_FAMILY;
  31. $pars['version'] = IMS_VERSION;
  32. $pars['release'] = IMS_RELEASE_DATE;
  33. if (!empty($_W['setting']['site'])) {
  34. $pars['key'] = $_W['setting']['site']['key'];
  35. $pars['password'] = md5($_W['setting']['site']['key'] . $_W['setting']['site']['token']);
  36. }
  37. $clients = cloud_client_define();
  38. $string = '';
  39. foreach($clients as $cli) {
  40. $string .= md5_file(IA_ROOT . $cli);
  41. }
  42. $pars['client'] = md5($string);
  43. return $pars;
  44. }
  45. function _cloud_shipping_parse($dat, $file)
  46. {
  47. }
  48. function cloud_request($url, $post = '', $extra = array(), $timeout = 60) {
  49. global $_W;
  50. load()->func('communication');
  51. if (!empty($_W['setting']['cloudip']['ip']) && empty($extra['ip'])) {
  52. $extra['ip'] = $_SERVER['HTTP_HOST'];
  53. }
  54. return array();
  55. }
  56. function cloud_prepare() {
  57. global $_W;
  58. setting_load();
  59. return true;
  60. }
  61. function cloud_build()
  62. {
  63. return null;
  64. }
  65. function cloud_schema() {
  66. $pars = _cloud_build_params();
  67. $pars['method'] = 'application.schema';
  68. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  69. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  70. $file = IA_ROOT . '/data/application.schema';
  71. $ret = _cloud_shipping_parse($dat, $file);
  72. if(!is_error($ret)) {
  73. $schemas = array();
  74. if(!empty($ret['schemas'])) {
  75. load()->func('db');
  76. foreach($ret['schemas'] as $remote) {
  77. $name = substr($remote['tablename'], 4);
  78. $local = db_table_schema(pdo(), $name);
  79. unset($remote['increment']);
  80. unset($local['increment']);
  81. if(empty($local)) {
  82. $schemas[] = $remote;
  83. } else {
  84. $diffs = db_schema_compare($local, $remote);
  85. if(!empty($diffs)) {
  86. $schemas[] = $remote;
  87. }
  88. }
  89. }
  90. }
  91. $ret['schemas'] = $schemas;
  92. }
  93. return $ret;
  94. }
  95. function cloud_download($path, $type = '') {
  96. $pars = _cloud_build_params();
  97. $pars['method'] = 'application.shipping';
  98. $pars['path'] = $path;
  99. $pars['type'] = $type;
  100. $pars['gz'] = function_exists('gzcompress') && function_exists('gzuncompress') ? 'true' : 'false';
  101. $pars['download'] = 'true';
  102. $headers = array('content-type' => 'application/x-www-form-urlencoded');
  103. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  104. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, $headers, 300);
  105. if(is_error($dat)) {
  106. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  107. }
  108. if($dat['content'] == 'success') {
  109. return true;
  110. }
  111. $ret = @json_decode($dat['content'], true);
  112. if(is_error($ret)) {
  113. return $ret;
  114. } else {
  115. $post = $dat['content'];
  116. $data = base64_decode($post);
  117. if (base64_encode($data) !== $post) {
  118. $data = $post;
  119. }
  120. $ret = iunserializer($data);
  121. $gz = function_exists('gzcompress') && function_exists('gzuncompress');
  122. $file = base64_decode($ret['file']);
  123. if($gz) {
  124. $file = gzuncompress($file);
  125. }
  126. $_W['setting']['site']['token'] = authcode(cache_load('cloud:transtoken'), 'DECODE');
  127. $string = (md5($file) . $ret['path'] . $_W['setting']['site']['token']);
  128. if(!empty($_W['setting']['site']['token']) && md5($string) === $ret['sign']) {
  129. $error_file_list = array();
  130. if (!cloud_file_permission_pass($error_file_list)) {
  131. return error(-1, '请修复下列文件读写权限 : ' . implode('; ', $error_file_list));
  132. }
  133. $path = IA_ROOT . $ret['path'];
  134. load()->func('file');
  135. @mkdirs(dirname($path));
  136. if (file_put_contents($path, $file)) {
  137. if (!empty($ret['extend'])) {
  138. foreach ($ret['extend'] as $file) {
  139. $path = base64_decode($file['path']);
  140. $file = base64_decode($file['file']);
  141. if (empty($path) || empty($file)) {
  142. continue;
  143. }
  144. if($gz) {
  145. $file = gzuncompress($file);
  146. }
  147. $path = IA_ROOT . $path;
  148. @mkdirs(dirname($path));
  149. file_put_contents($path, $file);
  150. }
  151. }
  152. return true;
  153. } else {
  154. return error(-1, '写入失败');
  155. }
  156. }
  157. return error(-1, '写入失败');
  158. }
  159. }
  160. function cloud_m_prepare($name) {
  161. $pars['method'] = 'module.check';
  162. $pars['module'] = $name;
  163. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  164. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  165. if (is_error($dat)) {
  166. return $dat;
  167. }
  168. if ($dat['content'] == 'install-module-protect') {
  169. }
  170. return true;
  171. }
  172. function cloud_m_build($modulename, $type = '')
  173. {
  174. return null;
  175. }
  176. function cloud_m_query($module = array()) {
  177. $pars = _cloud_build_params();
  178. $pars['method'] = 'module.query';
  179. if (empty($module)) {
  180. $pars['module'] = cloud_extra_module();
  181. } else {
  182. if (!is_array($module)) {
  183. $module = array($module);
  184. }
  185. $pars['module'] = base64_encode(iserializer($module));
  186. }
  187. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  188. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  189. $file = IA_ROOT . '/data/module.query';
  190. $ret = _cloud_shipping_parse($dat, $file);
  191. return $ret;
  192. }
  193. function cloud_m_bought() {
  194. $pars = _cloud_build_params();
  195. $pars['method'] = 'module.bought';
  196. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  197. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  198. $file = IA_ROOT . '/data/module.bought';
  199. $ret = _cloud_shipping_parse($dat, $file);
  200. return $ret;
  201. }
  202. function cloud_m_info($name) {
  203. $pars = _cloud_build_params();
  204. $pars['method'] = 'module.info';
  205. $pars['module'] = $name;
  206. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  207. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  208. $file = IA_ROOT . '/data/module.info';
  209. $ret = _cloud_shipping_parse($dat, $file);
  210. return $ret;
  211. }
  212. function cloud_m_upgradeinfo($name) {
  213. $module = pdo_fetch("SELECT name, version FROM ".tablename('modules')." WHERE name = '{$name}'");
  214. $pars = _cloud_build_params();
  215. $pars['method'] = 'module.info';
  216. $pars['module'] = $name;
  217. $pars['curversion'] = $module['version'];
  218. $pars['isupgrade'] = 1;
  219. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  220. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  221. $file = IA_ROOT . '/data/module.info';
  222. $ret = _cloud_shipping_parse($dat, $file);
  223. if (!empty($ret) && !is_error($ret)) {
  224. $ret['site_branch'] = $ret['branches'][$ret['version']['branch_id']];
  225. $ret['from'] = 'cloud';
  226. foreach ($ret['branches'] as &$branch) {
  227. if ($branch['displayorder'] < $ret['site_branch']['displayorder'] || ($ret['site_branch']['displayorder'] == $ret['site_branch']['displayorder'] && $ret['site_branch']['id'] > intval($branch['id']))) {
  228. unset($module['branches'][$branch['id']]);
  229. continue;
  230. }
  231. $branch['id'] = intval($branch['id']);
  232. $branch['version']['description'] = preg_replace('/\n/', '<br/>', $branch['version']['description']);
  233. $branch['displayorder'] = intval($branch['displayorder']);
  234. $branch['day'] = intval(date('d', $branch['version']['createtime']));
  235. $branch['month'] = date('Y.m', $branch['version']['createtime']);
  236. $branch['hour'] = date('H:i', $branch['version']['createtime']);
  237. }
  238. unset($branch);
  239. }
  240. return $ret;
  241. }
  242. function cloud_t_prepare($name)
  243. {
  244. return true;
  245. }
  246. function cloud_t_query()
  247. {
  248. return null;
  249. }
  250. function cloud_t_info($name)
  251. {
  252. return null;
  253. }
  254. function cloud_t_build($name) {
  255. if (empty($name)) {
  256. return array();
  257. }
  258. $sql = 'SELECT * FROM ' . tablename('site_templates') . ' WHERE `name`=:name';
  259. $theme = pdo_fetch($sql, array(':name' => $name));
  260. $pars = _cloud_build_params();
  261. $pars['method'] = 'theme.build';
  262. $pars['theme'] = $name;
  263. if(!empty($theme)) {
  264. $pars['themeversion'] = $theme['version'];
  265. }
  266. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  267. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  268. $file = IA_ROOT . '/data/theme.build';
  269. $ret = _cloud_shipping_parse($dat, $file);
  270. if(!is_error($ret)) {
  271. $dir = IA_ROOT . '/app/themes/' . $name;
  272. $files = array();
  273. if(!empty($ret['files'])) {
  274. foreach($ret['files'] as $file) {
  275. $entry = $dir . $file['path'];
  276. if(!is_file($entry) || md5_file($entry) != $file['checksum']) {
  277. $files[] = '/'. $name . $file['path'];
  278. }
  279. }
  280. }
  281. $ret['files'] = $files;
  282. $ret['upgrade'] = true;
  283. $ret['type'] = 'theme';
  284. if(empty($theme)) {
  285. $ret['install'] = 1;
  286. }
  287. cache_write('cloud:transtoken', authcode($ret['token'], 'ENCODE'));
  288. }
  289. return $ret;
  290. }
  291. function cloud_t_upgradeinfo($name) {
  292. if (empty($name)) {
  293. return array();
  294. }
  295. $sql = 'SELECT `name`, `version` FROM ' . tablename('site_templates') . ' WHERE `name` = :name';
  296. $theme = pdo_fetch($sql, array(':name' => $name));
  297. $pars = _cloud_build_params();
  298. $pars['method'] = 'theme.upgrade';
  299. $pars['theme'] = $theme['name'];
  300. $pars['version'] = $theme['version'];
  301. $pars['isupgrade'] = 1;
  302. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  303. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  304. $file = IA_ROOT . '/data/module.info';
  305. $ret = _cloud_shipping_parse($dat, $file);
  306. return $ret;
  307. }
  308. function cloud_w_prepare($name) {
  309. $pars['method'] = 'webtheme.check';
  310. $pars['webtheme'] = $name;
  311. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  312. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  313. if (is_error($dat)) {
  314. return $dat;
  315. }
  316. if ($dat['content'] == 'install-webtheme-protect') {
  317. return error('-1', '此后台皮肤已设置版权保护,您只能通过云平台来安装。');
  318. }
  319. return true;
  320. }
  321. function cloud_w_query() {
  322. $pars = _cloud_build_params();
  323. $pars['method'] = 'webtheme.query';
  324. $pars['webtheme'] = cloud_extra_webtheme();
  325. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  326. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  327. $file = IA_ROOT . '/data/webtheme.query';
  328. $ret = _cloud_shipping_parse($dat, $file);
  329. return $ret;
  330. }
  331. function cloud_w_info($name) {
  332. $pars = _cloud_build_params();
  333. $pars['method'] = 'webtheme.info';
  334. $pars['webtheme'] = $name;
  335. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  336. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  337. $file = IA_ROOT . '/data/webtheme.info';
  338. $ret = _cloud_shipping_parse($dat, $file);
  339. return $ret;
  340. }
  341. function cloud_w_build($name)
  342. {
  343. $sql = 'SELECT * FROM ' . tablename('webtheme_homepages') . ' WHERE `name`=:name';
  344. $webtheme = pdo_fetch($sql, array(':name' => $name));
  345. $pars = _cloud_build_params();
  346. $pars['method'] = 'webtheme.build';
  347. $pars['webtheme'] = $name;
  348. if(!empty($webtheme)) {
  349. $pars['webtheme_version'] = $webtheme['version'];
  350. }
  351. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  352. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  353. $file = IA_ROOT . '/data/webtheme.build';
  354. $ret = _cloud_shipping_parse($dat, $file);
  355. if(!is_error($ret)) {
  356. $dir = IA_ROOT . '/web/themes/' . $name;
  357. $files = array();
  358. if(!empty($ret['files'])) {
  359. foreach($ret['files'] as $file) {
  360. $entry = $dir . $file['path'];
  361. if(!is_file($entry) || md5_file($entry) != $file['checksum']) {
  362. $files[] = '/'. $name . $file['path'];
  363. }
  364. }
  365. }
  366. $ret['files'] = $files;
  367. $ret['upgrade'] = true;
  368. $ret['type'] = 'webtheme';
  369. if(empty($webtheme)) {
  370. $ret['install'] = 1;
  371. }
  372. cache_write('cloud:transtoken', authcode($ret['token'], 'ENCODE'));
  373. }
  374. return $ret;
  375. }
  376. function cloud_w_upgradeinfo($name)
  377. {
  378. $sql = 'SELECT `name`, `version` FROM ' . tablename('webtheme_homepages') . ' WHERE `name` = :name';
  379. $webtheme = pdo_fetch($sql, array(':name' => $name));
  380. $pars = _cloud_build_params();
  381. $pars['method'] = 'webtheme.upgrade';
  382. $pars['webtheme'] = $webtheme['name'];
  383. $pars['version'] = $webtheme['version'];
  384. $pars['isupgrade'] = 1;
  385. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  386. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  387. $file = IA_ROOT . '/data/webtheme.info';
  388. $ret = _cloud_shipping_parse($dat, $file);
  389. return $ret;
  390. }
  391. function cloud_sms_send($mobile, $content, $postdata = array(), $custom_sign = '') {
  392. global $_W;
  393. if(!preg_match('/^1\d{10}$/', $mobile) || empty($content)) {
  394. return error(1, '发送短信失败, 原因: 手机号错误或内容为空.');
  395. }
  396. if (empty($_W['uniacid'])) {
  397. $sms_info = cloud_sms_info();
  398. $balance = empty($sms_info['sms_count']) ? 0 : $sms_info['sms_count'];
  399. if (!empty($custom_sign)) {
  400. $sign = $custom_sign;
  401. }
  402. } else {
  403. $row = pdo_get('uni_settings' , array('uniacid' => $_W['uniacid']), array('notify'));
  404. $row['notify'] = @iunserializer($row['notify']);
  405. $config = $row['notify']['sms'];
  406. $balance = intval($config['balance']);
  407. $sign = $config['signature'];
  408. }
  409. if(empty($sign)) {
  410. $sign = '短信宝';
  411. }
  412. //判断剩余条数
  413. if($balance<1){
  414. return error(-1, '短信发送失败, 原因:余额不足');
  415. }
  416. //短信宝账号
  417. // $smsbao_info=pdo_get('uni_settings' , array('uniacid' => $_W['uniacid']), array('copyright'));
  418. //$smsbao_info=setting_load($key = 'copyright');
  419. $sms_param['u']=$_W['setting']['copyright']['sms_name'];
  420. $sms_param['p']=md5($_W['setting']['copyright']['sms_password']);
  421. $sms_param['m']=$mobile;
  422. $sms_param['c']='【'.$sign.'】'.$content;
  423. $statusStr = array(
  424. "0" => "短信发送成功",
  425. "-1" => "参数不全",
  426. "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
  427. "30" => "密码错误",
  428. "40" => "账号不存在",
  429. "41" => "余额不足",
  430. "42" => "帐户已过期",
  431. "43" => "IP地址限制",
  432. "50" => "内容含有敏感词"
  433. );
  434. $response = file_get_contents("http://api.smsbao.com/sms?".http_build_query($sms_param));
  435. if (trim($response)!='0') {
  436. return error($response, '短信发送失败, 原因:'.$statusStr[$response]);
  437. }
  438. if (trim($response)=='0') {
  439. if (!empty($_W['uniacid'])) {
  440. $row['notify']['sms']['balance'] = $row['notify']['sms']['balance'] - 1;
  441. if ($row['notify']['sms']['balance'] < 0) {
  442. $row['notify']['sms']['balance'] = 0;
  443. }
  444. pdo_update('uni_settings', array('notify' => iserializer($row['notify'])), array('uniacid' => $_W['uniacid']));
  445. uni_setting_save('notify', $row['notify']);
  446. }
  447. }
  448. return true;
  449. }
  450. /*function cloud_sms_send($mobile, $content, $postdata = array(), $custom_sign = '') {
  451. global $_W;
  452. if(!preg_match('/^1\d{10}$/', $mobile) || empty($content)) {
  453. return error(1, '发送短信失败, 原因: 手机号错误或内容为空.');
  454. }
  455. if (empty($_W['uniacid'])) {
  456. $sms_info = cloud_sms_info();
  457. $balance = empty($sms_info['sms_count']) ? 0 : $sms_info['sms_count'];
  458. if (!empty($custom_sign)) {
  459. $sign = $custom_sign;
  460. }
  461. } else {
  462. $row = pdo_get('uni_settings' , array('uniacid' => $_W['uniacid']), array('notify'));
  463. $row['notify'] = @iunserializer($row['notify']);
  464. $config = $row['notify']['sms'];
  465. $balance = intval($config['balance']);
  466. $sign = $config['signature'];
  467. }
  468. if(empty($sign)) {
  469. $sign = '涛盛微擎团队';
  470. }
  471. $pars = _cloud_build_params();
  472. $pars['method'] = 'sms.sendnew';
  473. $pars['mobile'] = $mobile;
  474. $pars['uniacid'] = $_W['uniacid'];
  475. $pars['balance'] = $balance;
  476. $pars['sign'] = $sign;
  477. if (!empty($postdata)) {
  478. $pars['content'] = $content;
  479. $pars['postdata'] = $postdata;
  480. } else {
  481. $pars['content'] = "{$content} 【{$sign}】";
  482. }
  483. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  484. $response = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  485. if (is_error($response)) {
  486. return error($response['errno'], '短信发送失败, 原因:'.$response['message']);
  487. }
  488. $result = json_decode($response['content'], true);
  489. if (is_error($result)) {
  490. return error($result['errno'], $result['message']);
  491. }
  492. if (intval($result['errno']) != -1) {
  493. if (!empty($_W['uniacid'])) {
  494. $row['notify']['sms']['balance'] = $row['notify']['sms']['balance'] - 1;
  495. if ($row['notify']['sms']['balance'] < 0) {
  496. $row['notify']['sms']['balance'] = 0;
  497. }
  498. pdo_update('uni_settings', array('notify' => iserializer($row['notify'])), array('uniacid' => $_W['uniacid']));
  499. uni_setting_save('notify', $row['notify']);
  500. } else {
  501. $sms_info['sms_count'] = $sms_info['sms_count'] - 1;
  502. if ($sms_info['sms_count'] < 0) {
  503. $sms_info['sms_count'] = 0;
  504. }
  505. setting_save($sms_info, 'sms.info');
  506. }
  507. }
  508. return true;
  509. }
  510. */
  511. function cloud_sms_info() {
  512. global $_W;
  513. $data=array();
  514. //返回短信的剩余条数以及签名
  515. $sms_name=$_W['setting']['copyright']['sms_name'];
  516. $sms_password=md5($_W['setting']['copyright']['sms_password']);
  517. $res=file_get_contents("http://api.smsbao.com/query?u={$sms_name}&p={$sms_password}");
  518. $retArr = explode("\n", $res);
  519. $balanceArr = explode(",", $retArr[1]);
  520. $data['sms_count']=$retArr[0] == 0 ? $balanceArr[1]:0;
  521. return $data;
  522. }
  523. /*function cloud_sms_info() {
  524. global $_W;
  525. $pars = _cloud_build_params();
  526. $pars['method'] = 'sms.info';
  527. $dat = cloud_request($_SERVER['HTTP_HOST'], $pars);
  528. if ($dat['content'] == 'success') {
  529. $setting_key = "sms.info";
  530. $dat = setting_load($setting_key);
  531. return $dat[$setting_key];
  532. }
  533. return array();
  534. }
  535. */
  536. function cloud_extra_account() {
  537. $data = array();
  538. $data['accounts'] = pdo_fetchall("SELECT name, account, original FROM ".tablename('account_wechats') . " GROUP BY account");
  539. return serialize($data);
  540. }
  541. function cloud_extra_module() {
  542. $sql = 'SELECT `name` FROM ' . tablename('modules') . ' WHERE `type` <> :type';
  543. $modules = pdo_fetchall($sql, array(':type' => 'system'), 'name');
  544. if (!empty($modules)) {
  545. return base64_encode(iserializer(array_keys($modules)));
  546. } else {
  547. return '';
  548. }
  549. }
  550. function cloud_extra_theme() {
  551. $sql = 'SELECT `name` FROM ' . tablename('site_templates') . ' WHERE `name` <> :name';
  552. $themes = pdo_fetchall($sql, array(':name' => 'default'), 'name');
  553. if (!empty($themes)) {
  554. return base64_encode(iserializer(array_keys($themes)));
  555. } else {
  556. return '';
  557. }
  558. }
  559. function cloud_extra_webtheme() {
  560. $sql = 'SELECT `name` FROM ' . tablename('webtheme_templates') . ' WHERE `name` <> :name';
  561. $themes = pdo_fetchall($sql, array(':name' => 'default'), 'name');
  562. if (!empty($themes)) {
  563. return base64_encode(iserializer(array_keys($themes)));
  564. } else {
  565. return '';
  566. }
  567. }
  568. function cloud_cron_create($cron) {
  569. $pars = _cloud_build_params();
  570. $pars['method'] = 'cron.create';
  571. $pars['cron'] = base64_encode(iserializer($cron));
  572. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  573. $result = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  574. return _cloud_cron_parse($result);
  575. }
  576. function cloud_cron_update($cron) {
  577. $pars = _cloud_build_params();
  578. $pars['method'] = 'cron.update';
  579. $pars['cron'] = base64_encode(iserializer($cron));
  580. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  581. $result = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  582. return _cloud_cron_parse($result);
  583. }
  584. function cloud_cron_get($cron_id) {
  585. $pars = _cloud_build_params();
  586. $pars['method'] = 'cron.get';
  587. $pars['cron_id'] = $cron_id;
  588. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  589. $result = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  590. return _cloud_cron_parse($result);
  591. }
  592. function cloud_cron_change_status($cron_id, $status) {
  593. $pars = _cloud_build_params();
  594. $pars['method'] = 'cron.status';
  595. $pars['cron_id'] = $cron_id;
  596. $pars['status'] = $status;
  597. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  598. $result = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  599. return _cloud_cron_parse($result);
  600. }
  601. function cloud_cron_remove($cron_id) {
  602. $pars = _cloud_build_params();
  603. $pars['method'] = 'cron.remove';
  604. $pars['cron_id'] = $cron_id;
  605. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  606. $result = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars);
  607. return _cloud_cron_parse($result);
  608. }
  609. function _cloud_cron_parse($result) {
  610. if (empty($result)) {
  611. return error(-1, '没有接收到服务器的传输的数据');
  612. }
  613. if ($result['content'] == 'blacklist') {
  614. return error(-1, '抱歉,您的站点已被列入云服务黑名单,云服务一切业务已被禁止,请联系微擎客服!');
  615. }
  616. $result = json_decode($result['content'], true);
  617. if (null === $result) {
  618. return error(-1, '云服务通讯发生错误,请稍后重新尝试!');
  619. }
  620. $result = $result['message'];
  621. if (is_error($result)) {
  622. return error(-1, $result['message']);
  623. }
  624. return $result;
  625. }
  626. function cloud_auth_url($forward, $data = array()){
  627. global $_W;
  628. if (!empty($_W['setting']['site']['url']) && !strexists($_W['siteroot'], $_W['setting']['site']['url'])) {
  629. $url = $_W['setting']['site']['url'];
  630. } else {
  631. $url = rtrim($_W['siteroot'], '/');
  632. }
  633. $auth = array();
  634. $auth['key'] = '';
  635. $auth['password'] = '';
  636. $auth['url'] = $url;
  637. $auth['referrer'] = intval($_W['config']['setting']['referrer']);
  638. $auth['version'] = IMS_VERSION;
  639. $auth['forward'] = $forward;
  640. $auth['family'] = IMS_FAMILY;
  641. if(!empty($_W['setting']['site']['key']) && !empty($_W['setting']['site']['token'])) {
  642. $auth['key'] = $_W['setting']['site']['key'];
  643. $auth['password'] = md5($_W['setting']['site']['key'] . $_W['setting']['site']['token']);
  644. }
  645. if ($data && is_array($data)) {
  646. $auth = array_merge($auth, $data);
  647. }
  648. $query = base64_encode(json_encode($auth));
  649. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  650. $auth_url = $_URLTYPE.$_SERVER['HTTP_HOST'] . $query;
  651. return $auth_url;
  652. }
  653. function cloud_module_setting_prepare($module, $binding) {
  654. global $_W;
  655. $auth = _cloud_build_params();
  656. $auth['arguments'] = array(
  657. 'binding' => $binding,
  658. 'acid' => $_W['uniacid'],
  659. 'type' => 'module',
  660. 'module' => $module,
  661. );
  662. $iframe_auth_url = cloud_auth_url('module', $auth);
  663. return $iframe_auth_url;
  664. }
  665. function cloud_resource_to_local($uniacid, $type, $url){
  666. global $_W;
  667. load()->func('file');
  668. $setting = $_W['setting']['upload'][$type];
  669. if (!file_is_image($url)) {
  670. return error(1, '远程图片后缀非法,请重新上传');;
  671. }
  672. if (substr($url, 0, 2) == '//') {
  673. $url = 'http:' . $url;
  674. }
  675. $pathinfo = pathinfo($url);
  676. $extension = $pathinfo['extension'];
  677. $originname = $pathinfo['basename'];
  678. $setting['folder'] = "{$type}s/{$uniacid}/".date('Y/m/');
  679. $originname = pathinfo($url, PATHINFO_BASENAME);
  680. $filename = file_random_name(ATTACHMENT_ROOT .'/'. $setting['folder'], $extension);
  681. $pathname = $setting['folder'] . $filename;
  682. $fullname = ATTACHMENT_ROOT . $pathname;
  683. mkdirs(dirname($fullname));
  684. load()->func('communication');
  685. $response = ihttp_get($url);
  686. if (is_error($response)) {
  687. return error(1, $response['message']);
  688. }
  689. if (file_put_contents($fullname, $response['content']) == false) {
  690. return error(1, '提取文件失败');
  691. }
  692. if (!empty($_W['setting']['remote']['type'])) {
  693. $remotestatus = file_remote_upload($pathname);
  694. if (is_error($remotestatus)) {
  695. return error(1, '远程附件上传失败,请检查配置并重新上传');
  696. } else {
  697. file_delete($pathname);
  698. }
  699. }
  700. $data = array(
  701. 'uniacid' => $uniacid,
  702. 'uid' => intval($_W['uid']),
  703. 'filename' => $originname,
  704. 'attachment' => $pathname,
  705. 'type' => $type == 'image' ? 1 : 2,
  706. 'createtime' => TIMESTAMP,
  707. );
  708. pdo_insert('core_attachment', $data);
  709. $data['url'] = tomedia($pathname);
  710. $data['id'] = pdo_insertid();
  711. return $data;
  712. }
  713. function cloud_bakup_files($files) {
  714. global $_W;
  715. if (empty($files)) {
  716. return false;
  717. }
  718. $map = json_encode($files);
  719. $hash = md5($map.$_W['config']['setting']['authkey']);
  720. if ($handle = opendir(IA_ROOT . '/data/patch/' . date('Ymd'))) {
  721. while (false !== ($patchpath = readdir($handle))) {
  722. if ($patchpath != '.' && $patchpath != '..') {
  723. if (strexists($patchpath, $hash)) {
  724. return false;
  725. }
  726. }
  727. }
  728. }
  729. $path = IA_ROOT . '/data/patch/' . date('Ymd') . '/' . date('Hi') . '_' . $hash;
  730. load()->func('file');
  731. if (!is_dir($path) && mkdirs($path)) {
  732. foreach ($files as $file) {
  733. if (file_exists(IA_ROOT . $file)) {
  734. mkdirs($path . '/' . dirname($file));
  735. file_put_contents($path . '/' . $file, file_get_contents(IA_ROOT . $file));
  736. }
  737. }
  738. file_put_contents($path . '/' . 'map.json', $map);
  739. }
  740. return false;
  741. }
  742. function cloud_flow_master_post($flow_master) {
  743. $pars = _cloud_build_params();
  744. $pars['method'] = 'flow.master_post';
  745. $pars['flow_master'] = array(
  746. 'linkman' => $flow_master['linkman'],
  747. 'mobile' => $flow_master['mobile'],
  748. 'address' => $flow_master['address'],
  749. 'id_card_photo' => $flow_master['id_card_photo'], 'business_licence_photo' => $flow_master['business_licence_photo'], );
  750. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  751. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  752. if(is_error($dat)) {
  753. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  754. }
  755. cache_delete("cloud:flow:master");
  756. $ret = @json_decode($dat['content'], true);
  757. return $ret;
  758. }
  759. function cloud_flow_master_get() {
  760. $cachekey = "cloud:flow:master";
  761. $cache = cache_load($cachekey);
  762. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  763. return $cache['setting'];
  764. }
  765. $pars = _cloud_build_params();
  766. $pars['method'] = 'flow.master_get';
  767. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  768. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  769. if(is_error($dat)) {
  770. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  771. }
  772. $ret = @json_decode($dat['content'], true);
  773. if ($ret['status'] == '3') {
  774. cache_write($cachekey, array('expire' => TIMESTAMP + 300, 'setting' => $ret));
  775. } else if ($ret['status'] == '4') {
  776. cache_write($cachekey, array('expire' => TIMESTAMP + 12 * 3600, 'setting' => $ret));
  777. }
  778. return $ret;
  779. }
  780. function cloud_flow_uniaccount_post($uniaccount) {
  781. $pars = _cloud_build_params();
  782. $pars['method'] = 'flow.uniaccount_post';
  783. $pars['uniaccount'] = array(
  784. 'uniacid' => $uniaccount['uniacid'],
  785. );
  786. isset($uniaccount['title']) && $pars['uniaccount']['title'] = $uniaccount['title'];
  787. isset($uniaccount['original']) && $pars['uniaccount']['original'] = $uniaccount['original'];
  788. isset($uniaccount['gh_type']) && $pars['uniaccount']['gh_type'] = $uniaccount['gh_type'];
  789. isset($uniaccount['ad_tags']) && $pars['uniaccount']['ad_tags'] = $uniaccount['ad_tags'];
  790. isset($uniaccount['enable']) && $pars['uniaccount']['enable'] = $uniaccount['enable'];
  791. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  792. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  793. if(is_error($dat)) {
  794. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  795. }
  796. cache_delete("cloud:ad:uniaccount:{$uniaccount['uniacid']}");
  797. cache_delete("cloud:ad:uniaccount:list");
  798. $ret = @json_decode($dat['content'], true);
  799. return $ret;
  800. }
  801. function cloud_flow_uniaccount_get($uniacid) {
  802. $cachekey = "cloud:ad:uniaccount:{$uniacid}";
  803. $cache = cache_load($cachekey);
  804. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  805. return $cache['setting'];
  806. }
  807. $pars = _cloud_build_params();
  808. $pars['method'] = 'flow.uniaccount_get';
  809. $pars['uniaccount'] = array(
  810. 'uniacid' => $uniacid,
  811. );
  812. $pars['md5'] = md5(base64_encode(serialize($pars['uniaccount'])));
  813. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  814. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  815. if(is_error($dat)) {
  816. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  817. }
  818. $ret = @json_decode($dat['content'], true);
  819. cache_write($cachekey, array('expire' => TIMESTAMP + 600, 'setting' => $ret));
  820. return $ret;
  821. }
  822. function cloud_flow_uniaccount_list_get() {
  823. $cachekey = "cloud:ad:uniaccount:list";
  824. $cache = cache_load($cachekey);
  825. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  826. return $cache['setting'];
  827. }
  828. $pars = _cloud_build_params();
  829. $pars['method'] = 'flow.uniaccount_list_get';
  830. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  831. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  832. if(is_error($dat)) {
  833. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  834. }
  835. $ret = @json_decode($dat['content'], true);
  836. cache_write($cachekey, array('expire' => TIMESTAMP + 600, 'setting' => $ret));
  837. return $ret;
  838. }
  839. function cloud_flow_ad_tag_list() {
  840. $cachekey = "cloud:ad:tags";
  841. $cache = cache_load($cachekey);
  842. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  843. return $cache['items'];
  844. }
  845. $pars = _cloud_build_params();
  846. $pars['method'] = 'flow.ad_tag_list';
  847. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  848. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  849. if(is_error($dat)) {
  850. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  851. }
  852. $ret = @json_decode($dat['content'], true);
  853. cache_write($cachekey, array('expire' => TIMESTAMP + 6 * 3600, 'items' => $ret));
  854. return $ret;
  855. }
  856. function cloud_flow_ad_type_list() {
  857. $cachekey = "cloud:ad:type:list";
  858. $cache = cache_load($cachekey);
  859. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  860. return $cache['items'];
  861. }
  862. $pars = _cloud_build_params();
  863. $pars['method'] = 'flow.ad_type_list';
  864. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  865. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  866. if(is_error($dat)) {
  867. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  868. }
  869. $ret = @json_decode($dat['content'], true);
  870. cache_write($cachekey, array('expire' => TIMESTAMP + 3600, 'items' => $ret));
  871. return $ret;
  872. }
  873. function cloud_flow_app_post($uniacid, $module_name, $enable = 0, $ad_types = null) {
  874. $pars = _cloud_build_params();
  875. $pars['method'] = 'flow.app_post';
  876. $pars['uniaccount_app'] = array(
  877. 'uniacid' => $uniacid,
  878. 'module' => $module_name,
  879. );
  880. if (!empty($enable)) {
  881. $pars['uniaccount_app']['enable'] = $enable; }
  882. if (is_array($ad_types)) {
  883. $pars['uniaccount_app']['ad_types'] = $ad_types; }
  884. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  885. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  886. if(is_error($dat)) {
  887. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  888. }
  889. cache_delete("cloud:ad:app:list:{$uniacid}");
  890. $ret = @json_decode($dat['content'], true);
  891. return $ret;
  892. }
  893. function cloud_flow_app_list_get($uniacid) {
  894. $cachekey = "cloud:ad:app:list:{$uniacid}";
  895. $cache = cache_load($cachekey);
  896. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  897. return $cache['setting'];
  898. }
  899. $pars = _cloud_build_params();
  900. $pars['method'] = 'flow.app_list_get';
  901. $pars['uniaccount'] = array(
  902. 'uniacid' => $uniacid,
  903. );
  904. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  905. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  906. if(is_error($dat)) {
  907. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  908. }
  909. $ret = @json_decode($dat['content'], true);
  910. cache_write($cachekey, array('expire' => TIMESTAMP + 300, 'setting' => $ret));
  911. return $ret;
  912. }
  913. function cloud_flow_app_support_list($module_names) {
  914. if (empty($module_names)) {
  915. return array();
  916. }
  917. $cachekey = "cloud:ad:app:support:list";
  918. $cache = cache_load($cachekey);
  919. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  920. return $cache['setting'];
  921. }
  922. $pars = _cloud_build_params();
  923. $pars['method'] = 'flow.app_support_list';
  924. $pars['modules'] = $module_names;
  925. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  926. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  927. if(is_error($dat)) {
  928. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  929. }
  930. $ret = @json_decode($dat['content'], true);
  931. cache_write($cachekey, array('expire' => TIMESTAMP + 300, 'setting' => $ret));
  932. return $ret;
  933. }
  934. function cloud_flow_site_stat_day($condition) {
  935. $cachekey = "cloud:ad:site:finance";
  936. $cache = cache_load($cachekey);
  937. if(!empty($cache) && $cache['expire'] > TIMESTAMP) {
  938. return $cache['info'];
  939. }
  940. $pars = _cloud_build_params();
  941. $pars['method'] = 'flow.site_stat_day';
  942. $pars['condition'] = array();
  943. $pars['condition']['starttime'] = $condition['starttime'];
  944. $pars['condition']['endtime'] = $condition['endtime'];
  945. $pars['condition']['page'] = $condition['page'];
  946. $pars['condition']['size'] = $condition['size'];
  947. $_URLTYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  948. $dat = cloud_request($_URLTYPE.$_SERVER['HTTP_HOST'], $pars, array(), 300);
  949. if(is_error($dat)) {
  950. return error(-1, '网络存在错误, 请稍后重试。' . $dat['message']);
  951. }
  952. $ret = @json_decode($dat['content'], true);
  953. cache_write($cachekey, array('expire' => TIMESTAMP + 300, 'info' => $ret));
  954. return $ret;
  955. }
  956. function cloud_build_transtoken() {
  957. $pars = _cloud_build_params();
  958. $pars['method'] = 'application.token';
  959. $dat = cloud_request(CLOUD_GATEWAY_URL_NORMAL, $pars);
  960. $file = IA_ROOT . '/data/application.build';
  961. $ret = _cloud_shipping_parse($dat, $file);
  962. cache_write('cloud:transtoken', authcode($ret['token'], 'ENCODE'));
  963. return $ret['token'];
  964. }
  965. function cloud_build_schemas($schemas) {
  966. $database = array();
  967. if (empty($schemas) || !is_array($schemas)) {
  968. return $database;
  969. }
  970. foreach ($schemas as $remote) {
  971. $row = array();
  972. $row['tablename'] = $remote['tablename'];
  973. $name = substr($remote['tablename'], 4);
  974. $local = db_table_schema(pdo(), $name);
  975. unset($remote['increment']);
  976. unset($local['increment']);
  977. if (empty($local)) {
  978. $row['new'] = true;
  979. } else {
  980. $row['new'] = false;
  981. $row['fields'] = array();
  982. $row['indexes'] = array();
  983. $diffs = db_schema_compare($local, $remote);
  984. if (!empty($diffs['fields']['less'])) {
  985. $row['fields'] = array_merge($row['fields'], $diffs['fields']['less']);
  986. }
  987. if (!empty($diffs['fields']['diff'])) {
  988. $row['fields'] = array_merge($row['fields'], $diffs['fields']['diff']);
  989. }
  990. if (!empty($diffs['indexes']['less'])) {
  991. $row['indexes'] = array_merge($row['indexes'], $diffs['indexes']['less']);
  992. }
  993. if (!empty($diffs['indexes']['diff'])) {
  994. $row['indexes'] = array_merge($row['indexes'], $diffs['indexes']['diff']);
  995. }
  996. $row['fields'] = implode($row['fields'], ' ');
  997. $row['indexes'] = implode($row['indexes'], ' ');
  998. }
  999. $database[] = $row;
  1000. }
  1001. return $database;
  1002. }
  1003. function cloud_file_permission_pass(&$error_file_list = array()) {
  1004. $check_path = array(
  1005. '/web/common',
  1006. '/web/source',
  1007. '/web/themes/default',
  1008. '/web/themes/black',
  1009. '/framework/class',
  1010. '/framework/model',
  1011. '/framework/function',
  1012. '/framework/table',
  1013. '/framework/library/agent',
  1014. );
  1015. $check_file = array(
  1016. '/web/index.php',
  1017. '/framework/bootstrap.inc.php',
  1018. '/framework/version.inc.php',
  1019. '/framework/const.inc.php',
  1020. );
  1021. $sub_paths = array();
  1022. foreach ($check_path as $path) {
  1023. $file_list = cloud_file_tree(IA_ROOT . $path);
  1024. if (!empty($file_list)) {
  1025. foreach ($file_list as $file) {
  1026. if (is_file($file)) {
  1027. $sub_path = pathinfo($file, PATHINFO_DIRNAME);
  1028. if (empty($sub_paths[$sub_path])) {
  1029. if (!cloud_path_is_writable($sub_path)) {
  1030. $error_file_list[] = str_replace(IA_ROOT, '', $sub_path);
  1031. }
  1032. $sub_paths[$sub_path] = $sub_path;
  1033. }
  1034. }
  1035. if (!is_writable($file)) {
  1036. $error_file_list[] = str_replace(IA_ROOT, '', $file);
  1037. }
  1038. }
  1039. }
  1040. }
  1041. foreach ($check_file as $file) {
  1042. if (!is_writable(IA_ROOT . $file)) {
  1043. $error_file_list[] = str_replace(IA_ROOT, '', $file);;
  1044. }
  1045. }
  1046. return empty($error_file_list) ? true : false;
  1047. }
  1048. function cloud_file_tree($path, $include = array()) {
  1049. $files = array();
  1050. if (!empty($include)) {
  1051. $ds = glob($path . '/{' . implode(',', $include) . '}', GLOB_BRACE);
  1052. } else {
  1053. $ds = glob($path . '/*');
  1054. }
  1055. if (is_array($ds)) {
  1056. foreach ($ds as $entry) {
  1057. if (is_file($entry)) {
  1058. $files[] = $entry;
  1059. }
  1060. if (is_dir($entry)) {
  1061. $rs = cloud_file_tree($entry);
  1062. foreach ($rs as $f) {
  1063. $files[] = $f;
  1064. }
  1065. }
  1066. }
  1067. }
  1068. return $files;
  1069. }
  1070. function cloud_path_is_writable($dir) {
  1071. $writeable = false;
  1072. if (!is_dir($dir)) {
  1073. @mkdir($dir, 0755);
  1074. }
  1075. if (is_dir($dir)) {
  1076. if($fp = fopen("$dir/test.txt", 'w')) {
  1077. fclose($fp);
  1078. unlink("$dir/test.txt");
  1079. $writeable = true;
  1080. } else {
  1081. $writeable = false;
  1082. }
  1083. }
  1084. return $writeable;
  1085. }