system.mod.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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. function system_menu() {
  8. global $we7_system_menu;
  9. require_once IA_ROOT . '/web/common/frames.inc.php';
  10. return $we7_system_menu;
  11. }
  12. function system_shortcut_menu() {
  13. global $_W;
  14. static $shortcut_menu;
  15. load()->model('user');
  16. if (empty($shortcut_menu)) {
  17. $shortcut_menu = array();
  18. $system_menu = system_menu();
  19. $is_main_founder = user_is_founder($_W['uid'], true);
  20. $is_vice_founder = user_is_vice_founder();
  21. $hidden_menu = array_keys((array) pdo_getall('core_menu', array('is_display' => 0), array('id', 'permission_name'), 'permission_name'));
  22. foreach (array('system', 'site') as $top_menu) {
  23. if (!empty($system_menu[$top_menu]['founder']) && !$is_main_founder) {
  24. continue;
  25. }
  26. if (in_array($top_menu, $hidden_menu)) {
  27. continue;
  28. }
  29. $shortcut_menu[$top_menu] = $system_menu[$top_menu];
  30. foreach ($shortcut_menu[$top_menu]['section'] as $section_key => &$section) {
  31. if (!empty($section['founder']) && !$is_main_founder) {
  32. unset($shortcut_menu[$top_menu]['section'][$section_key]);
  33. }
  34. foreach ($section['menu'] as $i => $menu) {
  35. if (!isset($menu['is_display'])) {
  36. $section['menu'][$i]['is_display'] = 1;
  37. }
  38. if (in_array($menu['permission_name'], $hidden_menu)) {
  39. $section['menu'][$i]['is_display'] = 0;
  40. }
  41. }
  42. }
  43. }
  44. $store_setting = $_W['setting']['store'];
  45. if (!in_array('store', $hidden_menu) && ($is_main_founder || empty($store_setting['status']))) {
  46. if (!$is_main_founder && !empty($_W['username']) && !empty($store_setting['permission_status']) && empty($store_setting['permission_status']['close'])) {
  47. if (!in_array($_W['username'], (array)$store_setting['whitelist']) && !empty($store_setting['permission_status']['whitelist'])
  48. || in_array($_W['username'], (array)$store_setting['blacklist']) && !empty($store_setting['permission_status']['blacklist'])
  49. ) {
  50. $system_menu['store'] = array();
  51. }
  52. }
  53. if (!empty($system_menu['store']['section'])) {
  54. $shortcut_menu['store'] = $system_menu['store'];
  55. foreach ($shortcut_menu['store']['section'] as $key => &$section) {
  56. if ($key == 'store_wish_goods' && $_W['setting']['store']['wish_module_status'] == 0) {
  57. $section['is_display'] = 0;
  58. }
  59. if (in_array($key, array('store_manage', 'store_payments', 'store_cash_manage')) && !$is_main_founder) {
  60. $section['is_display'] = 0;
  61. continue;
  62. }
  63. if ($key == 'store_cash' && (!$is_vice_founder || empty($store_setting['cash_status']))) {
  64. $section['is_display'] = 0;
  65. continue;
  66. }
  67. foreach ($section['menu'] as $menu_key => &$menu) {
  68. $menu['is_display'] = 1;
  69. if (in_array($menu_key, $hidden_menu)) {
  70. $menu['is_display'] = 0;
  71. }
  72. if ($key == 'store_goods' && !empty($store_setting[$menu_key])) {
  73. $menu['is_display'] = 0;
  74. }
  75. if ($menu_key == 'store_goods_users_package' && $is_vice_founder) {
  76. $menu['is_display'] = 0;
  77. }
  78. if ($menu_key == 'store_cash_orders' && (!$is_vice_founder || empty($store_setting['cash_status']))) {
  79. $menu['is_display'] = 0;
  80. }
  81. if ($menu_key == 'store_check_cash' && empty($store_setting['cash_status'])) {
  82. $menu['is_display'] = 0;
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. return $shortcut_menu;
  90. }
  91. function system_menu_permission_list($role = '') {
  92. global $_W;
  93. $system_menu = cache_load(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])));
  94. if(empty($system_menu)) {
  95. cache_build_frame_menu();
  96. $system_menu = cache_load(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])));
  97. }
  98. if ($role == ACCOUNT_MANAGE_NAME_OPERATOR) {
  99. unset($system_menu['appmarket']);
  100. unset($system_menu['advertisement']);
  101. unset($system_menu['system']);
  102. }
  103. return $system_menu;
  104. }
  105. function system_database_backup() {
  106. $path = IA_ROOT . '/data/backup/';
  107. load()->func('file');
  108. $reduction = array();
  109. if (!is_dir($path)) {
  110. return array();
  111. }
  112. if ($handle = opendir($path)) {
  113. while (false !== ($bakdir = readdir($handle))) {
  114. if ($bakdir == '.' || $bakdir == '..') {
  115. continue;
  116. }
  117. $times[] = date("Y-m-d H:i:s", filemtime($path.$bakdir));
  118. if (preg_match('/^(?P<time>\d{10})_[a-z\d]{8}$/i', $bakdir, $match)) {
  119. $time = $match['time'];
  120. if ($handle1= opendir($path . $bakdir)) {
  121. while (false !== ($filename = readdir($handle1))) {
  122. if ($filename == '.' || $filename == '..') {
  123. continue;
  124. }
  125. if (preg_match('/^volume-(?P<prefix>[a-z\d]{10})-\d{1,}\.sql$/i', $filename, $match1)) {
  126. $volume_prefix = $match1['prefix'];
  127. if (!empty($volume_prefix)) {
  128. break;
  129. }
  130. }
  131. }
  132. }
  133. $volume_list = array();
  134. for ($i = 1;;) {
  135. $last = $path . $bakdir . "/volume-{$volume_prefix}-{$i}.sql";
  136. array_push($volume_list, $last);
  137. $i++;
  138. $next = $path . $bakdir . "/volume-{$volume_prefix}-{$i}.sql";
  139. if (!is_file($next)) {
  140. break;
  141. }
  142. }
  143. if (is_file($last)) {
  144. $fp = fopen($last, 'r');
  145. fseek($fp, -27, SEEK_END);
  146. $end = fgets($fp);
  147. fclose($fp);
  148. if ($end == '----WeEngine MySQL Dump End') {
  149. $row = array(
  150. 'bakdir' => $bakdir,
  151. 'time' => $time,
  152. 'volume' => $i - 1,
  153. 'volume_list' => $volume_list,
  154. );
  155. $reduction[$bakdir] = $row;
  156. continue;
  157. }
  158. }
  159. }
  160. rmdirs($path . $bakdir);
  161. }
  162. closedir($handle);
  163. }
  164. if (!empty($times)) {
  165. array_multisort($times, SORT_DESC, SORT_STRING, $reduction);
  166. }
  167. return $reduction;
  168. }
  169. function system_database_volume_next($volume_name) {
  170. $next_volume_name = '';
  171. if (!empty($volume_name) && preg_match('/^([^\s]*volume-(?P<prefix>[a-z\d]{10})-)(\d{1,})\.sql$/i', $volume_name, $match)) {
  172. $next_volume_name = $match[1] . ($match[3] + 1) . ".sql";
  173. }
  174. return $next_volume_name;
  175. }
  176. function system_database_volume_restore($volume_name) {
  177. if (empty($volume_name) || !is_file($volume_name)) {
  178. return false;
  179. }
  180. $sql = file_get_contents($volume_name);
  181. pdo_run($sql);
  182. return true;
  183. }
  184. function system_database_backup_delete($delete_dirname) {
  185. $path = IA_ROOT . '/data/backup/';
  186. $dir = $path . $delete_dirname;
  187. if (empty($delete_dirname) || !is_dir($dir)) {
  188. return false;
  189. }
  190. return rmdirs($dir);
  191. }
  192. function system_template_ch_name() {
  193. $result = array(
  194. 'default' => '白色',
  195. 'black' => '黑色',
  196. 'classical' => '经典',
  197. '2.0' => '2.0',
  198. );
  199. return $result;
  200. }
  201. function system_login_template_ch_name() {
  202. $result = array(
  203. 'big' => '大图版',
  204. 'half' => '半屏图版',
  205. 'base' => '基础版'
  206. );
  207. return $result;
  208. }
  209. function system_site_info() {
  210. load()->classs('cloudapi');
  211. $api = new CloudApi();
  212. $site_info = $api->get('site', 'info');
  213. return $site_info;
  214. }
  215. function system_check_statcode($statcode) {
  216. $allowed_stats = array(
  217. 'baidu' => array(
  218. 'enabled' => true,
  219. 'reg' => '/(http[s]?\:)?\/\/hm\.baidu\.com\/hm\.js\?/'
  220. ),
  221. 'qq' => array(
  222. 'enabled' => true,
  223. 'reg' => '/(http[s]?\:)?\/\/tajs\.qq\.com/'
  224. ),
  225. );
  226. foreach($allowed_stats as $key => $item) {
  227. $preg = preg_match($item['reg'], $statcode);
  228. if (!$preg && !$item['enabled']) {
  229. continue;
  230. } else {
  231. return htmlspecialchars_decode($statcode);
  232. }
  233. return safe_gpc_html(htmlspecialchars_decode($statcode));
  234. }
  235. }
  236. function system_check_items() {
  237. return array(
  238. 'mbstring' => array(
  239. 'operate' => 'system_check_php_ext',
  240. 'description' => 'mbstring 扩展',
  241. 'error_message' => '不支持库',
  242. 'solution' => '安装 mbstring 扩展',
  243. 'handle' => 'http://s.w7.cc/wo/problem/46'
  244. ),
  245. 'mcrypt' => array(
  246. 'operate' => 'system_check_php_ext',
  247. 'description' => 'mcrypt 扩展',
  248. 'error_message' => '不支持库',
  249. 'solution' => '安装 mcrypt 扩展',
  250. 'handle' => 'http://s.w7.cc/wo/problem/46'
  251. ),
  252. 'openssl' => array(
  253. 'operate' => 'system_check_php_ext',
  254. 'description' => 'openssl 扩展',
  255. 'error_message' => '不支持库',
  256. 'solution' => '安装 openssl 扩展',
  257. 'handle' => 'http://s.w7.cc/wo/problem/46'
  258. ),
  259. 'system_template' => array(
  260. 'operate' => 'system_check_template',
  261. 'description' => '是否系统皮肤',
  262. 'error_message' => '不是系统皮肤',
  263. 'solution' => '更换系统默认皮肤',
  264. 'handle' => 'https://bbs.w7.cc/thread-33162-1-1.html'
  265. ),
  266. 'max_allowed_packet' => array(
  267. 'operate' => 'system_check_mysql_params',
  268. 'description' => 'mysql max_allowed_packet 值',
  269. 'error_message' => 'max_allowed_packet 小于 20M',
  270. 'solution' => '修改 mysql max_allowed_packet 值',
  271. 'handle' => 'https://bbs.w7.cc/thread-33415-1-1.html'
  272. ),
  273. 'always_populate_raw_post_data' => array(
  274. 'operate' => 'system_check_php_raw_post_data',
  275. 'description' => 'php always_populate_raw_post_data 配置',
  276. 'error_message' => '配置有误',
  277. 'solution' => '修改 php always_populate_raw_post_data 配置为 -1',
  278. 'handle' => 'https://s.w7.cc/wo/problem/134'
  279. ),
  280. );
  281. }
  282. function system_check_php_ext($extension) {
  283. return extension_loaded($extension) ? true : false;
  284. }
  285. function system_check_mysql_params($param) {
  286. $check_result = pdo_fetchall("SHOW GLOBAL VARIABLES LIKE '{$param}'");
  287. return $check_result[0]['Value'] < 1024*1024*20 ? false : true;
  288. }
  289. function system_check_template() {
  290. global $_W;
  291. $current_template = $_W['template'];
  292. $template_ch_name = system_template_ch_name();
  293. return in_array($current_template, array_keys($template_ch_name)) ? true : false;
  294. }
  295. function system_check_php_raw_post_data() {
  296. if (version_compare(PHP_VERSION, '7.0.0') == -1 && version_compare(PHP_VERSION, '5.6.0') >= 0) {
  297. return @ini_get('always_populate_raw_post_data') == '-1';
  298. }
  299. return true;
  300. }
  301. function system_setting_items() {
  302. return array(
  303. 'bind',
  304. 'develop_status',
  305. 'icp',
  306. 'policeicp',
  307. 'login_type',
  308. 'log_status',
  309. 'mobile_status',
  310. 'reason',
  311. 'autosignout',
  312. 'status',
  313. 'welcome_link',
  314. 'login_verify_status',
  315. 'address',
  316. 'blogo',
  317. 'baidumap',
  318. 'background_img',
  319. 'company',
  320. 'companyprofile',
  321. 'description',
  322. 'email',
  323. 'footerleft',
  324. 'footerright',
  325. 'flogo',
  326. 'icon',
  327. 'keywords',
  328. 'leftmenufixed',
  329. 'notice',
  330. 'oauth_bind',
  331. 'phone',
  332. 'person',
  333. 'qq',
  334. 'statcode',
  335. 'slides',
  336. 'showhomepage',
  337. 'sitename',
  338. 'template',
  339. 'login_template',
  340. 'url',
  341. 'verifycode',
  342. 'slide_logo',
  343. 'sms_name',
  344. 'sms_password',
  345. 'sms_sign',
  346. );
  347. }
  348. function system_scrap_file() {
  349. $scrap_file = array(
  350. '/framework/builtin/basic/template/display.html',
  351. '/framework/builtin/basic/module.php',
  352. '/framework/builtin/chats/template/display.html',
  353. '/framework/builtin/custom/template/display.html',
  354. '/framework/builtin/custom/module.php',
  355. '/framework/builtin/images/template/form.html',
  356. '/framework/builtin/images/template/modules.css',
  357. '/framework/builtin/images/module.php',
  358. '/framework/builtin/music/template/form.html',
  359. '/framework/builtin/music/template/modules.css',
  360. '/framework/builtin/music/module.php',
  361. '/framework/builtin/news/template/display.html',
  362. '/framework/builtin/news/module.php',
  363. '/framework/builtin/video/template/form.html',
  364. '/framework/builtin/video/template/modules.css',
  365. '/framework/builtin/video/module.php',
  366. '/framework/builtin/voice/template/form.html',
  367. '/framework/builtin/voice/template/modules.css',
  368. '/framework/builtin/voice/module.php',
  369. '/framework/class/account.class.php',
  370. '/framework/class/agent.class.php',
  371. '/framework/class/ali.pay.class.php',
  372. '/framework/class/webapp.account.class.php',
  373. '/framework/class/weixin.account.class.php',
  374. '/framework/class/weixin.nativepay.php',
  375. '/framework/class/weixin.platform.class.php',
  376. '/framework/class/weixin.pay.class.php',
  377. '/framework/class/wxapp.account.class.php',
  378. '/framework/class/yixin.account.class.php',
  379. '/framework/class/pay.class.php',
  380. '/framework/table/account.table.php',
  381. '/framework/table/job.table.php',
  382. '/framework/table/menu.table.php',
  383. '/framework/table/store.table.php',
  384. '/framework/module/app.mod.php',
  385. '/framework/module/frame.mod.php',
  386. '/framework/module/platform.mod.php',
  387. '/web/source/phoneapp/version.ctrl.php',
  388. '/web/themes/2.0/common/footer-base.html',
  389. '/web/themes/black/common/footer-base.html',
  390. '/web/themes/black/common/footer.html',
  391. '/web/themes/classical/common/footer-base.html',
  392. '/web/themes/default/account/manage-sms-wxapp.html',
  393. '/web/themes/default/account/manage-base-aliapp.html',
  394. '/web/themes/default/account/manage-base-baiduapp.html',
  395. '/web/themes/default/account/manage-base-phoneapp.html',
  396. '/web/themes/default/account/manage-base-toutiaoapp.html',
  397. '/web/themes/default/account/manage-base-webapp.html',
  398. '/web/themes/default/account/manage-base-wxapp.html',
  399. '/web/themes/default/account/manage-base-xzapp.html',
  400. '/web/themes/default/phoneapp/version-home.html',
  401. );
  402. return $scrap_file;
  403. }
  404. function system_star_menu() {
  405. global $_W;
  406. $result = array(
  407. 'mystar' => array(
  408. 'title' => '我的星标',
  409. 'icon' => 'wi wi-star',
  410. 'apiurl' => url('account/display/list_star'),
  411. 'one_page' => 1,
  412. 'hide_sort' => 1,
  413. ),
  414. 'history' => array(
  415. 'title' => '历史查看',
  416. 'icon' => 'wi wi-waiting',
  417. 'apiurl' => url('account/display/history'),
  418. 'one_page' => 1,
  419. 'hide_sort' => 1,
  420. ),
  421. 'platform' => array(
  422. 'title' => '所有平台',
  423. 'icon' => 'wi wi-platform',
  424. 'apiurl' => url('account/display/list', array('type' => 'all')),
  425. 'one_page' => 0,
  426. 'hide_sort' => 0,
  427. ),
  428. 'modules' => array(
  429. 'title' => '所有应用',
  430. 'icon' => 'wi wi-apply',
  431. 'apiurl' => url('module/display/own'),
  432. 'one_page' => 0,
  433. 'hide_sort' => 1,
  434. ),
  435. 'system_welcome_modules' => array(
  436. 'title' => '首页应用',
  437. 'icon' => 'wi wi-apply',
  438. 'apiurl' => url('module/display/system_welcome'),
  439. 'one_page' => 0,
  440. 'hide_sort' => 1,
  441. ),
  442. 'account_recycle' => array(
  443. 'title' => '回收站',
  444. 'icon' => 'wi wi-delete2',
  445. 'apiurl' => url('account/recycle'),
  446. 'one_page' => 0,
  447. 'hide_sort' => 0,
  448. ),
  449. 'platform_children' => array(
  450. 'title' => '平台分类',
  451. 'menu' => array(),
  452. ),
  453. );
  454. if (!in_array(IMS_FAMILY, array('s', 'x'))) {
  455. unset($result['system_welcome_modules']);
  456. }
  457. $account_all = table('account')->searchAccountList();
  458. $result['platform']['num'] = max(0, count($account_all));
  459. foreach (uni_account_type_sign() as $type_sign => $type_sign_info) {
  460. $account_num = uni_user_accounts($_W['uid'], $type_sign);
  461. $result['platform_children']['menu'][$type_sign] = array(
  462. 'title' => $type_sign_info['title'],
  463. 'icon' => $type_sign_info['icon'],
  464. 'num' => max(0, count($account_num)),
  465. 'apiurl' => url('account/display/list', array('type' => $type_sign)),
  466. 'one_page' => 0,
  467. 'hide_sort' => 0,
  468. );
  469. }
  470. return $result;
  471. }