/** * render a .tpl */ public function render($tpl = '') { if ($tpl == '') { $tpl = SsdPHP::getAction() . "/" . SsdPHP::getController(); } return self::$Smarty->fetch($tpl . self::$config['tpl_suffix']); }
public static function writeLog() { if (Config::get('is_write_log', true) !== true) { return false; } $SystemLog = new \App\Task\model\SystemLog(); $_SESSION = !empty($_SESSION) ? $_SESSION : array(); $model = in_array($v = strtolower(SsdPHP::getModel()), self::$_model_map) ? array_search($v, self::$_model_map) : 7; $logData = ['date' => date('Ymd'), 'model' => 1, 'controller' => SsdPHP::getController(), 'action' => SsdPHP::getAction(), 'session_id' => session_id(), 'session_val' => json_encode($_SESSION, JSON_UNESCAPED_UNICODE), 'custom_val' => json_encode(Response::getData(), JSON_UNESCAPED_UNICODE), 'create_time' => $_SERVER['REQUEST_TIME'], 'sql' => json_encode(Mysql::getSqlRecord())]; $s = $SystemLog->addLog($logData); }
public static function fetch($tpl = "") { if (empty($tpl)) { $tpl = SsdPHP::getController() . "/" . SsdPHP::getAction(); } $tpl_real = self::$template_dir . "/" . $tpl . self::$config['tpl_suffix']; if (!is_dir(self::$compile_dir)) { mkdir(self::$compile_dir, 0777, true); } $compiled_file = self::$compile_dir . "/" . base64_encode($tpl) . ".%%.tpl"; if (self::$force_compile || !is_file($compiled_file) || filemtime($tpl_real) > filemtime($compiled_file)) { $compiled_contents = self::_compile(file_get_contents($tpl_real)); file_put_contents($compiled_file, $compiled_contents, LOCK_EX); } ob_start(); include $compiled_file; $content = ob_get_contents(); ob_end_clean(); return $content; }
/** * URL组装 支持不同URL模式 * @param string $url URL表达式,格式:'[模块/控制器/操作#锚点@域名]?参数1=值1&参数2=值2...' * @param string|array $vars 传入的参数,支持数组和字符串 * @param string|boolean $suffix 伪静态后缀,默认为true表示获取配置值 * @param boolean $domain 是否显示域名 * @return string */ function U($url = '', $vars = '', $suffix = true, $domain = false) { // 解析URL $info = parse_url($url); $murl = SsdPHP::getController() . "/" . SsdPHP::getAction(); $url = !empty($info['path']) ? $info['path'] : $murl; if (isset($info['fragment'])) { // 解析锚点 $anchor = $info['fragment']; if (false !== strpos($anchor, '?')) { // 解析参数 list($anchor, $info['query']) = explode('?', $anchor, 2); } if (false !== strpos($anchor, '@')) { // 解析域名 list($anchor, $host) = explode('@', $anchor, 2); } } elseif (false !== strpos($url, '@')) { // 解析域名 list($url, $host) = explode('@', $info['path'], 2); } // 解析子域名 if (isset($host)) { $domain = $host . (strpos($host, '.') ? '' : strstr($_SERVER['HTTP_HOST'], '.')); } elseif ($domain === true) { $domain = $_SERVER['HTTP_HOST']; if (C('APP_SUB_DOMAIN_DEPLOY')) { // 开启子域名部署 $domain = $domain == 'localhost' ? 'localhost' : 'www' . strstr($_SERVER['HTTP_HOST'], '.'); // '子域名'=>array('模块[/控制器]'); foreach (C('APP_SUB_DOMAIN_RULES') as $key => $rule) { $rule = is_array($rule) ? $rule[0] : $rule; if (false === strpos($key, '*') && 0 === strpos($url, $rule)) { $domain = $key . strstr($domain, '.'); // 生成对应子域名 $url = substr_replace($url, '', 0, strlen($rule)); break; } } } } // 解析参数 if (is_string($vars)) { // aaa=1&bbb=2 转换成数组 parse_str($vars, $vars); } elseif (!is_array($vars)) { $vars = array(); } if (isset($info['query'])) { // 解析地址里面参数 合并到vars parse_str($info['query'], $params); $vars = array_merge($params, $vars); } // URL组装 //$depr = C('URL_PATHINFO_DEPR'); //$urlCase = C('URL_CASE_INSENSITIVE'); $depr = SsdPHP::getSplitFlag(); $urlCase = SConfig::get('URL_CASE_INSENSITIVE', true); $url = "/" . $murl . "?"; if ($urlCase) { $url = strtolower($url); } if (!empty($vars)) { $vars = http_build_query($vars); $url .= $vars; } if (isset($anchor)) { $url .= '#' . $anchor; } if ($domain) { $url = ($this->is_ssl() ? 'https://' : 'http://') . $domain . $url; } return $url; }