public static function updateSystemCache() { $setting_file = WEB_ROOT_DIR . self::$cache_file; // FFile::rmDir(WEB_ROOT_DIR . 'data/system/'); $t = new FTable('setting'); $settings = $t->select(); $setting_write = array(); foreach ($settings as $row) { $setting_write[$row['setting_key']] = $row['setting_value']; } FFile::save($setting_file, "<?php\n" . 'return ' . var_export($setting_write, true) . ';'); FCache::flush(); }
/** * @param $tpl_file * @param string $save_file 保存目录,相对于data目录 * @param bool $isSubTpl * @return string 模板文件主体 * @internal param string $content 模板文件主体 */ public function compile($tpl_file, $save_file = "", $isSubTpl = false) { $content = file_get_contents($tpl_file); $compiled_content = $this->parse($content); $header_comment = "Create On##" . time() . "|Compiled from##" . $this->template_path . $this->template_name; $str = "<? if(!defined('FLIB')) exit('Access Denied'); global \$_F; "; if (!$isSubTpl) { $str .= "\$tpl_file_mtime = " . intval(filemtime($tpl_file)) . ";"; } $str .= "/*{$header_comment}*/ ?>{$compiled_content}"; if ($save_file) { FFile::save($save_file, $str); } return $str; }
public static function makeThumbPic($pic_file, $size = '100x100') { if (!file_exists($pic_file)) { return 'thumb_error_for_src_pic_not_exits'; } list($w, $h) = explode('x', $size); if (!$w || !$h) { throw new Exception("size 参数错误!必须是 100x100 这样的形式。"); } $thumb_file = "{$pic_file}.{$size}.jpg"; FFile::mkdir(dirname($thumb_file)); $fImage = new FImage(); $fImage->open($pic_file)->thumb($w, $h, FImage::THUMB_CENTER)->save($thumb_file); return true; }
/** * +---------------------------------------------------------- * 日志直接写入 * +---------------------------------------------------------- * @static * @access public * +---------------------------------------------------------- * * @param string $message 日志信息 * @param int|string $type 日志记录方式 * @param string $level 日志级别 * * @return void */ static function write($message, $type = 'common', $level = self::LOG_LEVEL_INFO) { global $_F; if (is_array($message)) { $message = json_encode($message); } $now = date("Y-m-d H:i:s"); $log_file_size = FConfig::get('logger.LOG_FILE_SIZE'); $log_file_size = $log_file_size ? $log_file_size : 1024000; $file_log_path = FConfig::get('logger.LOG_PATH'); $file_log_path = $file_log_path ? $file_log_path : F_APP_ROOT . 'data/logs/'; // $file_log_path = $file_log_path; if ($_F['run_in'] == 'shell') { $file_log_path .= $_F['run_in'] . '/'; } elseif (isset($_F['module'])) { $file_log_path .= $_F['module'] . '/'; } if ($type) { $file_log_path .= "{$type}/"; } $file_log_path .= date('Y-m-d') . '.log'; FFile::mkdir(dirname($file_log_path)); if (is_file($file_log_path) && floor($log_file_size) <= filesize($file_log_path)) { rename($file_log_path, str_replace(basename($file_log_path), date('Y-m-d.H_i_s') . '.log', $file_log_path)); } $write_content = "{$now}\t{$level}"; if ($_SERVER['REQUEST_URI']) { $write_content .= "\tURL:http:/" . "/{$_F['http_host']}{$_F['uri']}\t" . ($_F['refer'] ? "REFER:{$_F['refer']}" : ''); // } else { // $write_content .= "\t{$_F['run_in']}\t{$_F['module']}"; } $write_content .= "\t{$message}\r\n"; file_put_contents($file_log_path, $write_content, FILE_APPEND); }
/** * 清空 cache */ public function _flush() { global $_F; $this->connect(); if (FConfig::get('global.memcache.enable')) { $_F['memcache']->flush(); return; } // 清除文件缓存 $cache_dir = dirname(self::getCacheDir() . 'file'); if (is_dir($cache_dir)) { $cache_dir_new = $cache_dir . '.bak_' . $_F['http_host'] . '_' . date('Y-m-d_H_i_s') . rand(1000, 9999); rename($cache_dir, $cache_dir_new); FFile::rmDir($cache_dir_new . '/'); } }
/** * +---------------------------------------------------------- * 日志直接写入 * +---------------------------------------------------------- * @static * @access public * +---------------------------------------------------------- * * @param string $message 日志信息 * @param string $level 日志级别 * @param int|string $type 日志记录方式 * @param string $destination 写入目标 * @param string $extra 额外参数 * +---------------------------------------------------------- * * @return void +---------------------------------------------------------- */ static function write($message, $level = self::LOG_LEVEL_ERR, $type = '', $destination = '', $extra = '') { $now = date("Y-m-d H:i:s"); $type = $type ? $type : FConfig::get('logger.LOG_TYPE'); if (self::LOG_TYPE_FILE == $type) { // 文件方式记录日志 if (empty($destination)) { $destination = FConfig::get('logger.LOG_PATH') . date('Y-m-d') . '.log'; } FFile::mkdir(dirname($destination)); //检测日志文件大小,超过配置大小则备份日志文件重新生成 if (is_file($destination) && floor(FConfig::get('logger.LOG_FILE_SIZE')) <= filesize($destination)) { rename($destination, str_replace(basename($destination), date('Y-m-d.H_i_s') . '.log', $destination)); } } else { $destination = $destination ? $destination : ''; $extra = $extra ? $extra : FConfig::get('logger.LOG_EXTRA'); } error_log("{$now}\t" . $_SERVER['REQUEST_URI'] . "\t{$level}\t{$message}\r\n", $type, $destination, $extra); }