Example #1
0
 /**
  * 存数据
  *
  * @param string/array $key 支持多存
  * @param $data Value 多存时此项可空
  * @param $lifetime 有效期,默认3600,即1小时,0表示最大值30天(2592000)
  * @return boolean
  */
 public function set($key, $value = null)
 {
     if (is_array($key)) {
         # 支持多存
         $i = 0;
         foreach ($key as $k => $v) {
             if ($this->set((string) $k, $v)) {
                 $i++;
             }
         }
         return $i == count($key) ? true : false;
     }
     $filename = $this->get_filename_by_key($key);
     $this->_format_data($value);
     return File::create_file($filename, $value, null, null, $this->storage);
 }
Example #2
0
 /**
  * 存数据
  *
  * @param string/array $key 支持多存
  * @param $data Value 多存时此项可空
  * @param $lifetime 有效期,默认3600,即1小时,0表示最大值30天(2592000)
  * @return boolean
  */
 public function set($key, $value = null, $lifetime = 3600)
 {
     if (is_array($key)) {
         # 支持多存
         $i = 0;
         foreach ($key as $k => $v) {
             if ($this->set((string) $k, $v, $lifetime)) {
                 $i++;
             }
         }
         return $i == count($key) ? true : false;
     }
     $filename = $this->get_filename_by_key($key);
     if (!is_dir($this->dir)) {
         # 创建初始文件夹
         if (!File::create_dir($this->dir)) {
             return false;
         }
     }
     $data = $this->format_data($lifetime, $value);
     return File::create_file($filename, $data);
 }
Example #3
0
 /**
  * 内部调用保存文件
  *
  */
 public function action_create_file()
 {
     # 目录
     $dir = $this->arguments[0];
     if (!isset(\File::$dir[$dir])) {
         # 目录不允许操作
         static::show_error('目录不允许操作');
     }
     if (!$this->arguments[1]) {
         static::show_error('缺少参数');
     }
     # 文件
     $filename = \File::$dir[$dir] . $this->arguments[1];
     # 内容
     $data = $this->arguments[2];
     if (\File::create_file($filename, $data, $this->arguments[3], $this->arguments[4])) {
         static::show_message('success', null, 1);
     } else {
         # 记录错误日志
         \Core::log('create file(' . $filename . ') error.', 'error');
         static::show_error('执行失败');
     }
 }
Example #4
0
 /**
  * 内部调用保存文件
  *
  */
 public function action_create_file()
 {
     # 目录
     $dir = $this->arguments[0];
     if (!isset(File::$dir[$dir])) {
         # 目录不允许操作
         $this->show_error('目录不允许操作');
     }
     if (!$this->arguments[1]) {
         $this->show_error('缺少参数');
     }
     # 文件
     $filename = File::$dir[$dir] . $this->arguments[1];
     # 内容
     $data = $this->arguments[2];
     if (File::create_file($filename, $data, $this->arguments[3], $this->arguments[4])) {
         $this->show_success();
     } else {
         # 记录错误日志
         Core::log('create file(' . $filename . ') error.', 'error');
         $this->show_error('执行失败');
     }
 }
Example #5
0
 /**
  * 内部调用保存文件
  *
  */
 public function action_create_file()
 {
     # 目录
     $dir = $this->arguments[0];
     if (!isset(File::$dir[$dir])) {
         # 目录不允许操作
         $this->show_error('目录不允许操作');
     }
     if (!$this->arguments[1]) {
         $this->show_error('缺少参数');
     }
     # 文件
     $filename = File::$dir[$dir] . $this->arguments[1];
     # 内容
     $data = $this->arguments[2];
     if (File::create_file($filename, $data, $this->arguments[3], $this->arguments[4])) {
         $this->show_success();
     } else {
         # 记录错误日志
         Core::log('system.error.file.create', array('file' => $filename), LOG_ERR);
         $this->show_error('执行失败');
     }
 }
Example #6
0
 /**
  * 锁定安装
  */
 protected function lock_install()
 {
     $file = DIR_DATA . Core::$project . '/install.lock';
     return File::create_file($file, ' ');
 }
Example #7
0
 /**
  * 存数据
  *
  * @param string/array $key 支持多存
  * @param $data Value 多存时此项可空
  * @param $lifetime 有效期,默认3600,即1小时,0表示最大值30天(2592000)
  * @return boolean
  */
 public function set($key, $value = null, $lifetime = 3600)
 {
     if ($this->is_file_write_disalbed) {
         return false;
     }
     if (is_array($key)) {
         # 支持多存
         $i = 0;
         foreach ($key as $k => $v) {
             if ($this->set((string) $k, $v, $lifetime)) {
                 $i++;
             }
         }
         return $i == count($key) ? true : false;
     }
     $filename = $this->get_filename_by_key($key);
     $value = $this->format_data($lifetime, $value);
     return File::create_file($filename, $value, null, null, $this->storage);
 }
Example #8
0
 /**
  * 重新加载配置
  *
  * @param boolean $from_db 是否强制从数据库中读取,默认true
  * @return Core_Config
  */
 public function reload($from_db = true)
 {
     $tmpfile = DIR_DATA . Core::$project . '/extends_config.txt';
     if (!$from_db && is_file($tmpfile)) {
         # 在data目录中直接读取
         $this->config = unserialize(file_get_contents($tmpfile));
         if (!is_array($this->config)) {
             $this->config = array();
         }
     } else {
         # 没有缓存数据,则直接在数据库里获取
         $db = new Database($this->database);
         $config = $db->from($this->tablename)->get(false, true)->as_array();
         if ($config) {
             foreach ($config as $item) {
                 $this->config[$item['type']][$item['key_name']] = @unserialize(gzuncompress($item['value']));
             }
         } else {
             $this->config = array();
         }
         // 写缓存
         File::create_file($tmpfile, serialize($this->config));
     }
 }
Example #9
0
 /**
  * 将指定的文件同步到其它服务器
  *
  * @param string $filename
  * @return boolean
  */
 public static function sync($file, $storage = 'default')
 {
     $info = File::check_and_get_path($file);
     if (File::can_do_run($storage)) {
         # 本机无需操作
         return true;
     } else {
         if (is_file($file)) {
             # 通过create_file把文件再创建一次
             return File::create_file($file, file_get_contents($file), null, null, $storage);
         }
     }
 }
Example #10
0
 /**
  * 执行输出JS或CSS
  *
  */
 protected function output_css_js_file()
 {
     $file_paths = $this->get_css_or_js_files_array($this->file, $this->suffix);
     # 输出目录
     $out_dir = DIR_ASSETS . 'p-' . Core::$project . (IS_ADMIN_MODE ? DS . '~admin' : '') . DS;
     # 输出文件
     $out_file = $out_dir . $this->file . ($this->is_min ? '.min' : '') . '.' . $this->suffix;
     # md5存放的文件
     $cache_file = DIR_DATA . 'cache/asset_files_md5_' . Core::$project . (IS_ADMIN_MODE ? '~admin' : '') . '_' . str_replace('/', '~', $this->file) . ($this->is_min ? '.min' : '') . '.' . $this->suffix . '.serialize';
     if (is_file($cache_file)) {
         $asset_files_md5 = (array) unserialize(file_get_contents($cache_file));
     } else {
         $asset_files_md5 = array();
     }
     if (is_file($out_file)) {
         $changed = false;
         if ($asset_files_md5) {
             foreach ($file_paths['file_md5'] as $fullpath => $md5) {
                 $debug_path = Core::debug_path($fullpath);
                 if (!isset($asset_files_md5[$debug_path]) || $asset_files_md5[$debug_path] != $md5) {
                     $changed = true;
                     break;
                 }
             }
         } else {
             if (current($file_paths['file_md5']) != md5_file($out_file)) {
                 $changed = true;
             }
         }
     } else {
         $changed = true;
     }
     if ($changed) {
         $content = '';
         if (isset($file_paths['file']) && $file_paths['file']) {
             foreach ($file_paths['file'] as $full_path) {
                 $content .= file_get_contents($full_path);
             }
         }
         if (isset($file_paths['main']) && $file_paths['main']) {
             foreach ($file_paths['main'] as $file => $full_path) {
                 # 内容
                 if (true !== $full_path) {
                     $content .= file_get_contents($full_path);
                 }
                 # 当前文件的扩展
                 if (isset($file_paths['extends'][$file]) && $file_paths['extends'][$file]) {
                     $content .= CRLF . file_get_contents($file_paths['extends'][$file]);
                 }
                 # 加入模块
                 if (isset($file_paths['modules'][$file]) && $file_paths['modules'][$file]) {
                     foreach ($file_paths['modules'][$file] as $file2 => $full_path2) {
                         $content .= CRLF . file_get_contents($full_path2);
                         # 模块文件的扩展文件
                         if (isset($file_paths['extends'][$file2]) && $file_paths['extends'][$file2]) {
                             $content .= CRLF . file_get_contents($file_paths['extends'][$file2]);
                         }
                     }
                 }
             }
         }
         if ($this->suffix === 'css') {
             $this->add_css_image_version($content);
             if (isset($file_paths['prease_css']) && $file_paths['prease_css']) {
                 # 处理LESS,和SCSS
                 $this->prease_css($out_file, $file_paths['prease_css'], $content);
             }
         }
         # 创建文件夹
         File::create_dir(dirname($out_file));
         # 保存文件
         if (File::create_file($out_file, $content)) {
             # 写入文件
             foreach ($file_paths['file_md5'] as $full_path => $md5) {
                 $debug_path = Core::debug_path($full_path);
                 $asset_files_md5[$debug_path] = $md5;
             }
             # 排序2次的用途是保证一些特殊情况下排序能得到纠正,比如有2个key分别是 test1.js 和 test.js 在排序时会有bug
             asort($asset_files_md5);
             asort($asset_files_md5);
             $old_md5_content = serialize($asset_files_md5);
             if (!is_file($cache_file) || md5($old_md5_content) != md5_file($cache_file)) {
                 # 保存MD5列表
                 File::create_file($cache_file, $old_md5_content);
             }
             $this->output_by_file($out_file);
         } else {
             $this->output_by_content($content);
         }
     } else {
         $this->output_by_file($out_file);
     }
 }
Example #11
0
 /**
  * 系统错误,可直接将Exception对象传给$msg
  * @param string/Exception $msg
  */
 public static function show_500($msg = null)
 {
     Core::close_buffers(false);
     # 避免输出的CSS头试抛出页面无法显示
     @header('Content-Type: text/html;charset=' . Core::config('core.charset'), true);
     HttpIO::$status = 500;
     HttpIO::send_headers();
     if (null === $msg) {
         $msg = __('Internal Server Error');
     }
     if (IS_DEBUG && class_exists('ErrException', false)) {
         if ($msg instanceof Exception) {
             throw $msg;
         } else {
             throw new Exception($msg, 0);
         }
     }
     if (IS_CLI) {
         echo "";
         if ($msg instanceof Exception) {
             echo $msg->getMessage() . CRLF;
         } else {
             echo $msg . CRLF;
         }
         echo "";
         echo CRLF;
         exit;
     }
     try {
         if ($msg instanceof Exception) {
             $error = $msg->getMessage();
             $trace_obj = $msg;
         } else {
             $error = $msg;
             $trace_obj = new Exception($msg);
         }
         $error_config = Core::config('core.error500');
         $view = new View('error/500');
         if ($error_config && isset($error_config['close']) && $error_config['close'] == true) {
             # 不记录
             $view->error_saved = false;
         } else {
             $trace_array = array('project' => Core::$project, 'uri' => HttpIO::$uri, 'url' => HttpIO::PROTOCOL . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"], 'post' => HttpIO::POST(null, HttpIO::PARAM_TYPE_OLDDATA), 'get' => $_SERVER['QUERY_STRING'], 'cookie' => HttpIO::COOKIE(null, HttpIO::PARAM_TYPE_OLDDATA), 'client_ip' => HttpIO::IP, 'user_agent' => HttpIO::USER_AGENT, 'referrer' => HttpIO::REFERRER, 'server_ip' => $_SERVER["SERVER_ADDR"], 'trace' => $trace_obj->__toString());
             $date = @date('Y-m-d');
             $no = strtoupper(substr(md5(serialize($trace_array)), 10, 10));
             $error_no = $date . '-' . $no;
             # 其它数据
             $trace_array['server_name'] = function_exists('php_uname') ? php_uname('a') : 'unknown';
             $trace_array['time'] = TIME;
             $trace_array['use_time'] = microtime(1) - START_TIME;
             $trace_array['trace'] = $trace_obj;
             $trace_data = base64_encode(gzcompress(serialize($trace_array), 9));
             unset($trace_array);
             $view->error_saved = true;
             # 记录错误日志
             try {
                 if (isset($error_config['save_type']) && $error_config['save_type']) {
                     $save_type = $error_config['save_type'];
                 } else {
                     $save_type = 'file';
                 }
                 if ($save_type == 'file') {
                     # 文件模式
                     $write_mode = Core::config('core.file_write_mode');
                     if (preg_match('#^(db|cache)://([a-z0-9_]+)/([a-z0-9_]+)$#i', $write_mode, $m)) {
                         $save_type = $m[1];
                         $error_config['type_config'] = $m[2];
                     }
                 }
                 switch ($save_type) {
                     case 'database':
                         $obj = $error_config['type_config'] ? new Database($error_config['type_config']) : new Database();
                         $data = array('time' => strtotime($date . ' 00:00:00'), 'no' => $no, 'log' => $trace_data, 'expire_time' => TIME + 7 * 86400);
                         $obj->insert('error500_log', $data);
                         break;
                     case 'cache':
                         $obj = $error_config['type_config'] ? new Cache($error_config['type_config']) : new Cache();
                         if (!$obj->get($error_no)) {
                             $obj->set($error_no, $trace_data, 7 * 86400);
                         }
                         break;
                     default:
                         $file = DIR_LOG . 'error500' . DS . str_replace('-', DS, $date) . DS . $no . '.log';
                         if (!is_file($file)) {
                             File::create_file($file, $trace_data, null, null, $error_config['type_config'] ? $error_config['type_config'] : 'default');
                         }
                         break;
                 }
             } catch (Exception $e) {
             }
         }
         $view->error_no = $error_no;
         $view->error = $error;
         $view->render(true);
     } catch (Exception $e) {
         list($REQUEST_URI) = explode('?', $_SERVER['REQUEST_URI'], 2);
         $REQUEST_URI = htmlspecialchars(rawurldecode($REQUEST_URI));
         echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . CRLF . '<html>' . CRLF . '<head>' . CRLF . '<title>Internal Server Error</title>' . CRLF . '</head>' . CRLF . '<body>' . CRLF . '<h1>' . __('Internal Server Error') . '</h1>' . CRLF . '<p>The requested URL ' . $REQUEST_URI . ' was error on this server.</p>' . CRLF . '<hr />' . CRLF . $_SERVER['SERVER_SIGNATURE'] . CRLF . '</body>' . CRLF . '</html>';
     }
     exit;
 }
Example #12
0
 /**
  * 存数据
  *
  * @param string/array $key 支持多存
  * @param mixed $value Value 多存时此项可空
  * @param int $lifetime 有效期,默认3600,即1小时,0表示最大值30天(2592000)
  * @return boolean
  */
 public function set($key, $value = null, $lifetime = 3600)
 {
     if ($this->is_file_write_disalbed) {
         return false;
     }
     if (is_array($key)) {
         # 支持多存
         $i = 0;
         foreach ($key as $k => $v) {
             if ($this->set((string) $k, $v, $lifetime)) {
                 $i++;
             }
         }
         $rs = $i === count($key) ? true : false;
         Core::debug()->info(array_keys($key), 'memcache set key');
         return $rs;
     }
     $filename = $this->get_filename_by_key($key);
     $value = $this->format_data($lifetime, $value);
     $rs = File::create_file($filename, $value, null, null, $this->storage);
     if (IS_DEBUG) {
         Core::debug()->info($key, 'file cache set key');
     }
     return $rs;
 }
Example #13
0
 /**
  * 保存runtime配置
  *
  * @param array $config
  */
 protected function save_runtime_config($config)
 {
     return File::create_file(DIR_DATA . Core::$project . DS . 'config_runtime.txt', serialize($config));
 }
    public function action_step_2()
    {
        if (HttpIO::METHOD == 'POST') {
            try {
                $data = $_POST;
                if (empty($data['hostname'])) {
                    throw new Exception('数据库服务器不能空。');
                }
                if (empty($data['database'])) {
                    throw new Exception('数据库名不能空。');
                }
                if (empty($data['username'])) {
                    throw new Exception('数据库用户名不能空。');
                }
                $database = Core::config('admin/core.database');
                if (!$database) {
                    $database = 'default';
                }
                $type = function_exists('mysqli_close') ? 'MySQLI' : 'MySQL';
                if (is_array($data['hostname'])) {
                    $master = trim($data['hostname']['master']);
                    $slaver = explode("\n", str_replace(array("\r", ' '), '', $data['hostname']['slaver']));
                    if (!$slaver || trim($data['hostname']['slaver']) == $master) {
                        $hostname = "'" . $master . "'";
                    } else {
                        $slaver_str = "array\r\n            (";
                        foreach ($slaver as $s) {
                            $slaver_str .= "\r\n                '" . $s . '\',';
                        }
                        $slaver_str .= "\r\n            ),";
                        $hostname = <<<EOF
array
        (
            'master' => '{$master}',
            'slaver' => {$slaver_str}
        )
EOF;
                    }
                } else {
                    $hostname = '\'' . $data['hostname'] . '\'';
                }
                $config_str = <<<EOF
<?php
\$config['{$database}'] = array
(
    'type'       => '{$type}',
    'connection' => array
    (
        //数据库地址
        'hostname'   => {$hostname},
        'port'       => '{$data['port']}',        //端口
        'database'   => '{$data['database']}',    //库名称
        'username'   => '{$data['username']}',    //用户名
        'password'   => '{$data['password']}',    //密码
    ),
    'table_prefix' => '{$data['table_prefix']}',  //表前缀
    'charset'      => 'utf8',
    'caching'      => false,
);
EOF;
                if ($_POST['save'] == 1) {
                    $w = File::create_file(DIR_PROJECT . Core::$project . '/config/database.config' . EXT, $config_str);
                    if ($w) {
                        $this->redirect(Core::url('install/step_3/'));
                    } else {
                        throw new Exception('没有保存配置文件的权限,请手动保存。');
                    }
                }
            } catch (Exception $e) {
                $message = $e->getMessage();
            }
        }
        $view = new View('admin/install/step_2');
        $this->step = 2;
        if (isset($message)) {
            $view->message = $message;
        }
        if (isset($config_str)) {
            $view->config_str = $config_str;
        }
        $view->render();
    }
Example #15
0
 /**
  * 系统错误,可直接将Exception对象传给$msg
  * @param string/Exception $msg
  */
 public static function show_500($msg = null)
 {
     Core::close_buffers(false);
     # 避免输出的CSS头试抛出页面无法显示
     @header('Content-Type: text/html;charset=' . Core::config('charset'), true);
     HttpIO::$status = 500;
     HttpIO::send_headers();
     if (null === $msg) {
         $msg = __('Internal Server Error');
     }
     if (IS_DEBUG && class_exists('DevException', false)) {
         if ($msg instanceof Exception) {
             $e = $msg;
         } else {
             $e = new Exception($msg);
         }
         echo DevException::exception_handler($e, true);
         exit;
     }
     if (IS_CLI) {
         echo "", $msg, CRLF, "", CRLF;
         exit;
     }
     try {
         if ($msg instanceof Exception) {
             $error = $msg->getMessage();
             $trace_obj = $msg;
         } else {
             $error = $msg;
             $trace_obj = new Exception($msg);
         }
         $error_config = Core::config('error500');
         $view = new View('error/500');
         if ($error_config && isset($error_config['close']) && $error_config['close'] == true) {
             # 不记录
             $view->error_saved = false;
             $error_no = '';
         } else {
             $trace_array = array('project' => Core::$project, 'admin_mode' => IS_ADMIN_MODE, 'uri' => HttpIO::$uri, 'url' => HttpIO::PROTOCOL . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"], 'post' => HttpIO::POST(null, HttpIO::PARAM_TYPE_OLDDATA), 'get' => $_SERVER['QUERY_STRING'], 'cookie' => HttpIO::COOKIE(null, HttpIO::PARAM_TYPE_OLDDATA), 'client_ip' => HttpIO::IP, 'user_agent' => HttpIO::USER_AGENT, 'referrer' => HttpIO::REFERRER, 'server_ip' => $_SERVER["SERVER_ADDR"]);
             $date = @date('Y-m-d');
             $no = strtoupper(substr(md5(serialize($trace_array)), 10, 10));
             $error_no = $date . '-' . $no;
             # 其它数据
             $trace_array['server_name'] = function_exists('php_uname') ? php_uname('a') : 'unknown';
             $trace_array['time'] = TIME;
             $trace_array['use_time'] = microtime(1) - START_TIME;
             $trace_array['trace'] = (string) $trace_obj;
             $trace_string = Core::json_encode($trace_array);
             $view->error_saved = true;
             # 记录错误日志
             try {
                 if (isset($error_config['save_type']) && $error_config['save_type']) {
                     $save_type = $error_config['save_type'];
                 } else {
                     $save_type = 'file';
                 }
                 if ($save_type === 'file') {
                     # 文件模式
                     $write_mode = Core::config('file_write_mode');
                     if (preg_match('#^(db|cache|fluent)://(([a-z0-9\\.\\-_]+)(?:\\:|/)([a-z0-9_]+))$#i', $write_mode, $m)) {
                         $save_type = $m[1];
                         $error_config['server'] = $m[2];
                         $error_config['type_config'] = $m[3];
                     }
                 }
                 switch ($save_type) {
                     case 'database':
                         $obj = $error_config['type_config'] ? new Database($error_config['type_config']) : new Database();
                         $data = array('time' => strtotime($date . ' 00:00:00'), 'no' => $no, 'log' => $obj->is_support_object_value() ? $trace_array : $trace_string, 'expire_time' => TIME + 7 * 86400);
                         $obj->insert('error500_log', $data);
                         break;
                     case 'cache':
                         $obj = $error_config['type_config'] ? new Cache($error_config['type_config']) : new Cache();
                         if (!$obj->get($error_no)) {
                             $obj->set($error_no, $trace_string, 7 * 86400);
                         }
                         break;
                     case 'fluent':
                         if (strpos($error_config['server'], ':') !== false) {
                             $fd_server = 'tcp://' . $error_config['server'];
                         } else {
                             $fd_server = 'udp://' . $error_config['server'];
                         }
                         $obj = Fluent::instance($fd_server);
                         $obj->push('system.error500', $trace_array);
                         break;
                     default:
                         $file = DIR_LOG . 'error500' . DS . str_replace('-', DS, $date) . DS . $no . '.log';
                         if (!is_file($file)) {
                             File::create_file($file, date('Y-m-d\\TH:i:s') . ' - ' . $trace_string, null, null, $error_config['type_config'] ? $error_config['type_config'] : 'default');
                         }
                         break;
                 }
             } catch (Exception $e) {
             }
         }
         $view->error_no = $error_no;
         $view->error = $error;
         $view->render(true);
     } catch (Exception $e) {
         list($REQUEST_URI) = explode('?', $_SERVER['REQUEST_URI'], 2);
         $REQUEST_URI = htmlspecialchars(rawurldecode($REQUEST_URI));
         echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . CRLF . '<html>' . CRLF . '<head>' . CRLF . '<title>Internal Server Error</title>' . CRLF . '</head>' . CRLF . '<body>' . CRLF . '<h1>Internal Server Error</h1>' . CRLF . '<p>The requested URL ' . $REQUEST_URI . ' was error on this server.</p>' . CRLF . '<hr />' . CRLF . $_SERVER['SERVER_SIGNATURE'] . '<br/><br/><br/>' . CRLF . 'Powered by MyQEE V' . Core::VERSION . CRLF . '</body>' . CRLF . '</html>';
     }
     exit;
 }
Example #16
0
 /**
  * 重新加载配置
  *
  * @param boolean $from_db 是否强制从数据库中读取,默认true
  * @param string $type 类型
  * @return Core_Config
  */
 public function reload($from_db = true, $type = '')
 {
     $tmp_file = $this->get_config_cache_file(Core::$project, $type);
     if ($this->is_use_cache && !$from_db && is_file($tmp_file)) {
         # 在data目录中直接读取
         $this->config[$type] = @unserialize(file_get_contents($tmp_file));
         if (!is_array($this->config[$type])) {
             $this->config[$type] = array();
         }
     } else {
         # 没有缓存数据,则直接在数据库里获取
         $db = new Database($this->database);
         $config = $db->from($this->tablename)->where('type', $type)->get(false, true)->as_array();
         if ($config) {
             $this->config = array();
             foreach ($config as $item) {
                 $this->config[$item['type']][$item['key_name']] = $this->data_unformat($item['value']);
             }
         } else {
             $this->config = array($type => array());
         }
         if ($this->is_use_cache) {
             // 普通模式下写缓存
             $rs = File::create_file($tmp_file, serialize($this->config));
             if (IS_DEBUG) {
                 Core::debug()->log('save extends config cache ' . ($rs ? 'success' : 'fail') . '.');
             }
         }
     }
 }
Example #17
0
 /**
  * 循环建立目录,多服务器可以自动同步
  *
  * @param string $dir 待创建的文件夹
  * @param boolean $auto_create_default_file 新创建的文件夹,是否自动创建空默认页
  * @param string $storage 物理存储组,不传则为默认
  * @return boolean true/false
  */
 public static function create_dir($dir, $auto_create_default_file = true, $storage = 'default')
 {
     $info = File::check_and_get_path($dir);
     if (File::can_do_run($storage)) {
         if (!is_dir($dir)) {
             if (substr($dir, 0, strlen(DIR_SYSTEM)) == DIR_SYSTEM) {
                 $temp = explode('/', str_replace('\\', '/', substr($dir, strlen(DIR_SYSTEM))));
                 $cur_dir = DIR_SYSTEM;
             } else {
                 $temp = explode('/', str_replace('\\', '/', $dir));
                 $cur_dir = '';
             }
             for ($i = 0; $i < count($temp); $i++) {
                 $cur_dir .= $temp[$i] . '/';
                 if (!@is_dir($cur_dir)) {
                     if (@mkdir($cur_dir, 0755)) {
                         if ($auto_create_default_file) {
                             File::create_file($cur_dir . 'index.html', ' ');
                         }
                     } else {
                         return false;
                     }
                 }
             }
         }
         return true;
     } else {
         return File::call_http_host($storage, 'file/create_dir', $info[0], $info[1], $auto_create_default_file);
     }
 }