/www/wwwroot/huojuantaicom/framework/base/Template.php
ob_start();
}
extract($this->vars, EXTR_OVERWRITE);
eval('?>'.$this->compile($tpl, $isTpl));
if ($return) {
$content = ob_get_contents();
ob_end_clean();
return $content;
}
}
public function compile($tpl, $isTpl = true)
{
if ($isTpl) {
$tplFile = $this->config['TPL_PATH'].$tpl.$this->config['TPL_SUFFIX'];
if (!file_exists($tplFile)) {
throw new \Exception("Template file '{$tplFile}' not found", 500);
}
$tplKey = md5(realpath($tplFile));
} else {
$tplKey = md5($tpl);
}
$ret = unserialize($this->cache->get($tplKey));
if (empty($ret['template']) || ($isTpl && filemtime($tplFile) > ($ret['compile_time']))) {
$template = $isTpl ? file_get_contents($tplFile) : $tpl;
if (false === Hook::listen('templateParse', [$template], $template)) {
foreach ($this->label as $key => $value) {
$template = preg_replace($key, $value, $template);
}
}
$ret = ['template'=>$template, 'compile_time'=>time()];
$this->cache->set($tplKey, serialize($ret), 86400 * 365);
}
return $ret['template'];
}
/www/wwwroot/huojuantaicom/framework/base/Template.php
foreach ($name as $k => $v) {
$this->vars[$k] = $v;
}
} else {
$this->vars[$name] = $value;
}
}
public function display($tpl = '', $return = false, $isTpl = true)
{
if ($return) {
if (ob_get_level()) {
ob_end_flush();
flush();
}
ob_start();
}
extract($this->vars, EXTR_OVERWRITE);
eval('?>'.$this->compile($tpl, $isTpl));
if ($return) {
$content = ob_get_contents();
ob_end_clean();
return $content;
}
}
public function compile($tpl, $isTpl = true)
{
if ($isTpl) {
$tplFile = $this->config['TPL_PATH'].$tpl.$this->config['TPL_SUFFIX'];
if (!file_exists($tplFile)) {
throw new \Exception("Template file '{$tplFile}' not found", 500);
}
$tplKey = md5(realpath($tplFile));
} else {
$tplKey = md5($tpl);
}
/www/wwwroot/huojuantaicom/framework/base/Controller.php
public function assign($name, $value = null)
{
return $this->_getView()->assign($name, $value);
}
public function display($tpl = '', $return = false, $isTpl = true)
{
if ($isTpl) {
if (empty($tpl)) {
$tpl = 'app/'.APP_NAME.'/view/'.strtolower(CONTROLLER_NAME).config('TPL.TPL_DEPR').strtolower(ACTION_NAME);
}
if ($this->layout) {
$this->__template_file = $tpl;
$tpl = $this->layout;
}
}
$this->_getView()->assign(get_object_vars($this));
return $this->_getView()->display($tpl, $return, $isTpl);
}
public function isPost()
{
return $_SERVER['REQUEST_METHOD'] == 'POST';
}
public function redirect($url, $code = 302)
{
header('location:'.$url, true, $code);
exit;
}
public function alert($msg, $url = null, $charset = 'utf-8')
{
header("Content-type: text/html; charset={$charset}");
$alert_msg = "alert('$msg');";
if (empty($url)) {
$go_url = 'history.go(-1);';
} else {
/www/wwwroot/huojuantaicom/app/home/controller/SiteController.php
/**
* 前台模板显示 调用内置的模板引擎.
*
* @param string $name 模板名
* @param bool $type 模板输出
*
* @return void
*/
protected function siteDisplay($name = '', $type = true)
{
// 多语言
if (defined('LANG_OPEN')) {
$tpl = THEME_NAME.'/'.TPL_NAME.'/'.APP_LANG.'/'.$name;
} else {
$tpl = THEME_NAME.'/'.TPL_NAME.'/'.$name;
}
if ($type) {
$this->display($tpl);
} else {
return $this->display($tpl, true);
}
}
/**
* 页面Meda信息组合.
*
* @return array 页面信息
*/
protected function getMedia($title = '', $keywords = '', $description = '')
{
if (empty($title)) {
$title = config('site_title').''.config('site_subtitle');
} else {
$title = $title.' - '.config('site_title').''.config('site_subtitle');
}
if (empty($keywords)) {
$keywords = config('site_keywords');
}
/www/wwwroot/huojuantaicom/app/home/controller/IndexController.php
*/
class IndexController extends SiteController
{
/**
* 主页.
*/
public function index()
{
//MEDIA信息
$media = $this->getMedia();
$this->assign('media', $media);
$this->siteDisplay(config('tpl_index'));
}
/**
* 页面不存在.
*/
public function error404()
{
$this->siteDisplay('error_404');
}
}
/www/wwwroot/huojuantaicom/app/base/controller/ErrorController.php
namespace app\base\controller;
use framework\base\Controller;
class ErrorController extends Controller
{
public function error404($e = null)
{
header('HTTP/1.1 404 Not Found');
header('status: 404 Not Found');
$this->error($e);
}
public function error($e = null)
{
//关闭调试或者是线上版本,不显示详细错误
if (false == config('DEBUG') || 'production' == config('ENV')) {
$home = new \app\home\controller\IndexController();
$home->error404();
} else {
throw $e;
}
}
}
/www/wwwroot/huojuantaicom/app/base/controller/ErrorController.php
error($e);
}
public function error($e = null)
{
//关闭调试或者是线上版本,不显示详细错误
if (false == config('DEBUG') || 'production' == config('ENV')) {
$home = new \app\home\controller\IndexController();
$home->error404();
} else {
throw $e;
}
}
}
/www/wwwroot/huojuantaicom/app/base/hook/AppHook.php
Hook::listen('CheckAdminLang');
}
}
$this->startTime = microtime(true);
}
public function appEnd()
{
//echo microtime(true) - $this->startTime ;
}
public function appError($e)
{
if (404 == $e->getCode()) {
$action = 'error404';
} else {
$action = 'error';
}
obj('app\base\controller\ErrorController')->$action($e);
}
public function routeParseUrl($rewriteRule, $rewriteOn)
{
}
public function actionBefore($obj, $action)
{
}
public function actionAfter($obj, $action)
{
}
}
/www/wwwroot/huojuantaicom/framework/base/Hook.php
return false;
}
foreach (self::$tags[$tag] as $class) {
$result = self::exec($class, $tag, $params);
if (false === $result) {
break;
}
}
return true;
}
protected static function exec($class, $method, $params)
{
static $objArr = [];
if (!isset($objArr[$class])) {
$objArr[$class] = new $class();
}
return call_user_func_array([$objArr[$class], $method], (array) $params);
}
}
/www/wwwroot/huojuantaicom/framework/base/Hook.php
return false;
}
foreach (self::$tags[$tag] as $class) {
$result = self::exec($class, $tag, $params);
if (false === $result) {
break;
}
}
return true;
}
protected static function exec($class, $method, $params)
{
static $objArr = [];
if (!isset($objArr[$class])) {
$objArr[$class] = new $class();
}
return call_user_func_array([$objArr[$class], $method], (array) $params);
}
}
/www/wwwroot/huojuantaicom/framework/base/Hook.php
continue;
}
$class = substr($file, $pos + 1, -4);
$class = "\\app\\base\\hook\\{$class}";
$methods = get_class_methods($class);
foreach ((array) $methods as $method) {
self::$tags[$method][] = $class;
}
}
}
public static function listen($tag, $params = [], &$result = null)
{
if (!isset(self::$tags[$tag])) {
return false;
}
foreach (self::$tags[$tag] as $class) {
$result = self::exec($class, $tag, $params);
if (false === $result) {
break;
}
}
return true;
}
protected static function exec($class, $method, $params)
{
static $objArr = [];
if (!isset($objArr[$class])) {
$objArr[$class] = new $class();
}
return call_user_func_array([$objArr[$class], $method], (array) $params);
}
}
/www/wwwroot/huojuantaicom/framework/base/App.php
if (!class_exists($controller)) {
throw new \Exception("Controller '{$controller}' not found", 404);
}
$obj = new $controller();
if (!method_exists($obj, $action)) {
throw new \Exception("Action '{$controller}::{$action}()' not found", 404);
}
Hook::listen('actionBefore', [$obj, $action]);
$obj->$action();
Hook::listen('actionAfter', [$obj, $action]);
} catch (\Exception $e) {
// //关闭调试或者是线上版本,不显示详细错误
// if (false==config('DEBUG') || 'production' == config('ENV')) {
// $home = new \app\home\controller\IndexController();
// $home->error404();
// } else {
// throw $e;
// }
Hook::listen('appError', [$e]);
}
Hook::listen('appEnd');
}
}
/www/wwwroot/huojuantaicom/framework/core.php
foreach (glob($fileDIR.'*.php') as $file) {
$fileList[$fileDIR][] = $file;
}
}
$fileBase = $baseDir.str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR.$className;
foreach ($fileList[$fileDIR] as $file) {
if (false !== stripos($file, $fileBase)) {
require $file;
return true;
}
}
}
}
return false;
});
App::run();
/www/wwwroot/huojuantaicom/index.php