global.func.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * 模板风格列表
  4. * @param integer $siteid 站点ID,获取单个站点可使用的模板风格列表
  5. * @param integer $disable 是否显示停用的{1:是,0:否}
  6. */
  7. function template_list($siteid = '', $disable = 0) {
  8. $list = glob(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR);
  9. $arr = $template = array();
  10. if ($siteid) {
  11. $site = pc_base::load_app_class('sites','admin');
  12. $info = $site->get_by_id($siteid);
  13. if($info['template']) $template = explode(',', $info['template']);
  14. }
  15. foreach ($list as $key=>$v) {
  16. $dirname = basename($v);
  17. if ($siteid && !in_array($dirname, $template)) continue;
  18. if (file_exists($v.DIRECTORY_SEPARATOR.'config.php')) {
  19. $arr[$key] = include $v.DIRECTORY_SEPARATOR.'config.php';
  20. if (!$disable && isset($arr[$key]['disable']) && $arr[$key]['disable'] == 1) {
  21. unset($arr[$key]);
  22. continue;
  23. }
  24. } else {
  25. $arr[$key]['name'] = $dirname;
  26. }
  27. $arr[$key]['dirname']=$dirname;
  28. }
  29. return $arr;
  30. }
  31. /**
  32. * 设置config文件
  33. * @param $config 配属信息
  34. * @param $filename 要配置的文件名称
  35. */
  36. function set_config($config, $filename="system") {
  37. $configfile = CACHE_PATH.'configs'.DIRECTORY_SEPARATOR.$filename.'.php';
  38. if(!is_writable($configfile)) showmessage('Please chmod '.$configfile.' to 0777 !');
  39. $pattern = $replacement = array();
  40. foreach($config as $k=>$v) {
  41. if(in_array($k,array('js_path','css_path','img_path','attachment_stat','admin_log','gzip','errorlog','phpsso','phpsso_appid','phpsso_api_url','phpsso_auth_key','phpsso_version','connect_enable', 'upload_url','sina_akey', 'sina_skey', 'snda_enable', 'snda_status', 'snda_akey', 'snda_skey', 'qq_akey', 'qq_skey','qq_appid','qq_appkey','qq_callback','admin_url'))) {
  42. $v = trim($v);
  43. $configs[$k] = $v;
  44. $pattern[$k] = "/'".$k."'\s*=>\s*([']?)[^']*([']?)(\s*),/is";
  45. $replacement[$k] = "'".$k."' => \${1}".$v."\${2}\${3},";
  46. }
  47. }
  48. $str = file_get_contents($configfile);
  49. $str = preg_replace($pattern, $replacement, $str);
  50. return pc_base::load_config('system','lock_ex') ? file_put_contents($configfile, $str, LOCK_EX) : file_put_contents($configfile, $str);
  51. }
  52. /**
  53. * 获取系统信息
  54. */
  55. function get_sysinfo() {
  56. $sys_info['os'] = PHP_OS;
  57. $sys_info['zlib'] = function_exists('gzclose');//zlib
  58. $sys_info['safe_mode'] = (boolean) ini_get('safe_mode');//safe_mode = Off
  59. $sys_info['safe_mode_gid'] = (boolean) ini_get('safe_mode_gid');//safe_mode_gid = Off
  60. $sys_info['timezone'] = function_exists("date_default_timezone_get") ? date_default_timezone_get() : L('no_setting');
  61. $sys_info['socket'] = function_exists('fsockopen') ;
  62. $sys_info['web_server'] = strpos($_SERVER['SERVER_SOFTWARE'], 'PHP')===false ? $_SERVER['SERVER_SOFTWARE'].'PHP/'.phpversion() : $_SERVER['SERVER_SOFTWARE'];
  63. $sys_info['phpv'] = phpversion();
  64. $sys_info['fileupload'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') :'unknown';
  65. return $sys_info;
  66. }
  67. /**
  68. * 检查目录可写性
  69. * @param $dir 目录路径
  70. */
  71. function dir_writeable($dir) {
  72. $writeable = 0;
  73. if(is_dir($dir)) {
  74. if($fp = @fopen("$dir/chkdir.test", 'w')) {
  75. @fclose($fp);
  76. @unlink("$dir/chkdir.test");
  77. $writeable = 1;
  78. } else {
  79. $writeable = 0;
  80. }
  81. }
  82. return $writeable;
  83. }
  84. /**
  85. * 返回错误日志大小,单位MB
  86. */
  87. function errorlog_size() {
  88. $logfile = CACHE_PATH.'error_log.php';
  89. if(file_exists($logfile)) {
  90. return $logsize = pc_base::load_config('system','errorlog') ? round(filesize($logfile) / 1048576 * 100) / 100 : 0;
  91. }
  92. return 0;
  93. }
  94. ?>