人人商城

system.mod.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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_permission_list($role = '') {
  8. global $_W;
  9. $system_menu = cache_load(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])));
  10. if(empty($system_menu)) {
  11. cache_build_frame_menu();
  12. $system_menu = cache_load(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])));
  13. }
  14. if ($role == ACCOUNT_MANAGE_NAME_OPERATOR) {
  15. unset($system_menu['appmarket']);
  16. unset($system_menu['advertisement']);
  17. unset($system_menu['system']);
  18. }
  19. return $system_menu;
  20. }
  21. function system_database_backup() {
  22. $path = IA_ROOT . '/data/backup/';
  23. load()->func('file');
  24. $reduction = array();
  25. if (!is_dir($path)) {
  26. return array();
  27. }
  28. if ($handle = opendir($path)) {
  29. while (false !== ($bakdir = readdir($handle))) {
  30. if ($bakdir == '.' || $bakdir == '..') {
  31. continue;
  32. }
  33. $times[] = date("Y-m-d H:i:s", filemtime($path.$bakdir));
  34. if (preg_match('/^(?P<time>\d{10})_[a-z\d]{8}$/i', $bakdir, $match)) {
  35. $time = $match['time'];
  36. if ($handle1= opendir($path . $bakdir)) {
  37. while (false !== ($filename = readdir($handle1))) {
  38. if ($filename == '.' || $filename == '..') {
  39. continue;
  40. }
  41. if (preg_match('/^volume-(?P<prefix>[a-z\d]{10})-\d{1,}\.sql$/i', $filename, $match1)) {
  42. $volume_prefix = $match1['prefix'];
  43. if (!empty($volume_prefix)) {
  44. break;
  45. }
  46. }
  47. }
  48. }
  49. $volume_list = array();
  50. for ($i = 1;;) {
  51. $last = $path . $bakdir . "/volume-{$volume_prefix}-{$i}.sql";
  52. array_push($volume_list, $last);
  53. $i++;
  54. $next = $path . $bakdir . "/volume-{$volume_prefix}-{$i}.sql";
  55. if (!is_file($next)) {
  56. break;
  57. }
  58. }
  59. if (is_file($last)) {
  60. $fp = fopen($last, 'r');
  61. fseek($fp, -27, SEEK_END);
  62. $end = fgets($fp);
  63. fclose($fp);
  64. if ($end == '----WeEngine MySQL Dump End') {
  65. $row = array(
  66. 'bakdir' => $bakdir,
  67. 'time' => $time,
  68. 'volume' => $i - 1,
  69. 'volume_list' => $volume_list,
  70. );
  71. $reduction[$bakdir] = $row;
  72. continue;
  73. }
  74. }
  75. }
  76. rmdirs($path . $bakdir);
  77. }
  78. closedir($handle);
  79. }
  80. if (!empty($times)) {
  81. array_multisort($times, SORT_DESC, SORT_STRING, $reduction);
  82. }
  83. return $reduction;
  84. }
  85. function system_database_volume_next($volume_name) {
  86. $next_volume_name = '';
  87. if (!empty($volume_name) && preg_match('/^([^\s]*volume-(?P<prefix>[a-z\d]{10})-)(\d{1,})\.sql$/i', $volume_name, $match)) {
  88. $next_volume_name = $match[1] . ($match[3] + 1) . ".sql";
  89. }
  90. return $next_volume_name;
  91. }
  92. function system_database_volume_restore($volume_name) {
  93. if (empty($volume_name) || !is_file($volume_name)) {
  94. return false;
  95. }
  96. $sql = file_get_contents($volume_name);
  97. pdo_run($sql);
  98. return true;
  99. }
  100. function system_database_backup_delete($delete_dirname) {
  101. $path = IA_ROOT . '/data/backup/';
  102. $dir = $path . $delete_dirname;
  103. if (empty($delete_dirname) || !is_dir($dir)) {
  104. return false;
  105. }
  106. return rmdirs($dir);
  107. }
  108. function system_template_ch_name() {
  109. $result = array(
  110. 'default' => '白色',
  111. 'black' => '黑色',
  112. 'classical' => '经典',
  113. );
  114. return $result;
  115. }
  116. function system_site_info() {
  117. load()->classs('cloudapi');
  118. $api = new CloudApi();
  119. $site_info = $api->get('site', 'info');
  120. return $site_info;
  121. }
  122. function system_check_statcode($statcode) {
  123. $allowed_stats = array(
  124. 'baidu' => array(
  125. 'enabled' => true,
  126. 'reg' => '/(http[s]?\:)?\/\/hm\.baidu\.com\/hm\.js\?/'
  127. ),
  128. 'qq' => array(
  129. 'enabled' => true,
  130. 'reg' => '/(http[s]?\:)?\/\/tajs\.qq\.com/'
  131. ),
  132. );
  133. foreach($allowed_stats as $key => $item) {
  134. $preg = preg_match($item['reg'], $statcode);
  135. if ($preg && $item['enabled']) {
  136. return htmlspecialchars_decode($statcode);
  137. } else {
  138. return safe_gpc_html(htmlspecialchars_decode($statcode));
  139. }
  140. }
  141. }