add() 공개 정적인 메소드

动态添加行为扩展到某个标签
public static add ( string $tag, mixed $behavior, boolean $first = false ) : void
$tag string 标签名称
$behavior mixed 行为名称
$first boolean 是否放到开头执行
리턴 void
 public function run(&$parms)
 {
     //安装时不执行
     if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
         return;
     }
     $data = S('global_hooks');
     if (!$data) {
         $hooks = M('Hooks', "common_")->getField('name,addons');
         foreach ($hooks as $key => $value) {
             if ($value) {
                 $map['status'] = 1;
                 $names = explode(',', $value);
                 $map['name'] = array('IN', $names);
                 $data = M('Addons', "common_")->where($map)->getField('id,name');
                 if ($data) {
                     $addons = array_intersect($names, $data);
                     Hook::add($key, array_map('get_addon_class', $addons));
                 }
             }
         }
         S('global_hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
예제 #2
0
 /**
  * @param mixed $content
  */
 public function run(&$content)
 {
     /**
      *  //真不知道说什么好。。。
      *      这里      原因是tp 不能把tag放在项目配置中,只能放在common中,而common模块先于install 初始化
      *     so。。。。。
      *
      */
     if (C('DB_TYPE') == 'GreenCMS_DB_TYPE') {
     } else {
         if (isset($_GET['m']) && strtolower($_GET['m']) == 'install') {
             return;
         }
         $data = S('hooks');
         if (!$data) {
             $hooks = M('Hooks')->getField('name,addons');
             foreach ($hooks as $key => $value) {
                 if ($value) {
                     $map['status'] = 1;
                     $names = explode(',', $value);
                     $map['name'] = array('IN', $names);
                     $data = M('Addons')->where($map)->getField('id,name');
                     if ($data) {
                         $addons = array_intersect($names, $data);
                         Hook::add($key, $addons);
                     }
                 }
             }
             S('hooks', Hook::get());
         } else {
             Hook::import($data, false);
         }
     }
 }
예제 #3
0
 public function run(&$content)
 {
     if (isset($_GET['m']) && $_GET['m'] === 'Install') {
         return;
     }
     $data = S('hooks');
     if (!$data) {
         $hooks = M('Hooks')->getField('name,addons');
         foreach ($hooks as $key => $value) {
             if ($value) {
                 $map['status'] = 1;
                 $names = explode(',', $value);
                 $map['name'] = array('IN', $names);
                 $data = M('Addons')->where($map)->getField('id,name');
                 if ($data) {
                     $addons = array_intersect($names, $data);
                     Hook::add($key, array_map('get_addon_class', $addons));
                 }
             }
         }
         S('hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
예제 #4
0
 public function run(&$content)
 {
     if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
         return;
     }
     $data = S('hooks');
     if (!$data) {
         $hooks = M('hooks')->getField('name,addons');
         foreach ($hooks as $key => $value) {
             if ($value) {
                 $map['status'] = 1;
                 $names = explode(',', $value);
                 $map['name'] = array('IN', $names);
                 $data = (array) M('addons')->where($map)->getField('id,name');
                 $data_plugin = (array) M('plugin')->where($map)->getField('id,name');
                 $data = array_merge($data, $data_plugin);
                 if ($data) {
                     $addons = array_intersect($names, $data);
                     Hook::add($key, array_map('get_addon_class', $addons));
                 }
             }
         }
         S('hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
예제 #5
0
 /**
  * 行为扩展的执行入口必须是run
  * @author jry <*****@*****.**>
  */
 public function run(&$content)
 {
     // 安装模式下直接返回
     if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
         return;
     }
     // 添加插件配置
     $addon_config['ADDON_PATH'] = './Addons/';
     $addon_config['AUTOLOAD_NAMESPACE'] = C('AUTOLOAD_NAMESPACE');
     $addon_config['AUTOLOAD_NAMESPACE']['Addons'] = $addon_config['ADDON_PATH'];
     C($addon_config);
     $data = S('hooks');
     if (!$data || APP_DEBUG === true) {
         $hooks = D('Admin/Hook')->getField('name,addons');
         foreach ($hooks as $key => $value) {
             if ($value) {
                 $map['status'] = 1;
                 $names = explode(',', $value);
                 $map['name'] = array('IN', $names);
                 $data = D('Admin/Addon')->where($map)->getField('id,name');
                 if ($data) {
                     $addons = array_intersect($names, $data);
                     Hook::add($key, array_map('get_addon_class', $addons));
                 }
             }
         }
         S('hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
예제 #6
0
 public function run(&$content)
 {
     if (!file_exist(UPLOAD_PATH . 'install.lock')) {
         return true;
     }
     $data = S('common_behavior_hooks');
     if (!$data) {
         $hooks = M('hooks')->where(array('status' => 1))->getField('name, addons');
         foreach ($hooks as $key => $value) {
             if ($value) {
                 $map['status'] = 1;
                 $names = explode(',', $value);
                 $map['name'] = array('IN', $names);
                 $data = M('addons')->where($map)->getField('id, name');
                 if ($data) {
                     $addons = array_intersect($names, $data);
                     Hook::add($key, array_map('get_addon_class', $addons));
                 }
             }
         }
         S('common_behavior_hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
예제 #7
0
파일: hookTest.php 프로젝트: Lofanmi/think
 public function testRun()
 {
     Hook::add('my_pos', '\\tests\\thinkphp\\library\\think\\behavior\\One');
     Hook::add('my_pos', ['\\tests\\thinkphp\\library\\think\\behavior\\Two']);
     Hook::add('my_pos', '\\tests\\thinkphp\\library\\think\\behavior\\Three', true);
     $data['id'] = 0;
     $data['name'] = 'thinkphp';
     Hook::listen('my_pos', $data);
     $this->assertEquals(2, $data['id']);
     $this->assertEquals('thinkphp', $data['name']);
     $this->assertEquals(['\\tests\\thinkphp\\library\\think\\behavior\\Three', '\\tests\\thinkphp\\library\\think\\behavior\\One', '\\tests\\thinkphp\\library\\think\\behavior\\Two'], Hook::get('my_pos'));
 }
예제 #8
0
 /**
  * @todo: 发送评论
  * @author Saki <*****@*****.**>
  * @date 2014-12-22 上午9:34:18
  * @version V1.0
  */
 public function PostComment()
 {
     $model = new \Admin\Model\ArticleCommentModel();
     $post = $_POST['ArticleComment'];
     $id = $post['aid'];
     $comment_id = $model->createComment($post);
     //发送邮件,这里为游客发送评论,则为管理员邮箱收到邮件
     if ($comment_id) {
         \Think\Hook::listen('postComment', $comment_id);
         \Think\Hook::add('postComment', 'Home\\Behaviors\\emailBehavior');
     }
     $this->redirect('Article/view', array('id' => $id, 'p' => 1));
 }
예제 #9
0
 public function app_init()
 {
     $bags = self::$tags;
     foreach ($bags as $hook => $classes) {
         foreach ($classes as $class) {
             $tags = Hook::get($hook);
             if (class_exists($class)) {
                 if (!array_search($class, $tags)) {
                     Hook::add($hook, $class);
                 }
             }
         }
     }
 }
 /**
  * @todo: 发送评论-后台管理员发送
  * @author Saki <*****@*****.**>
  * @date 2014-12-22 上午9:34:18
  * @version V1.0
  */
 public function PostComment()
 {
     $model = new \Admin\Model\ArticleCommentModel();
     $post = $_POST['ArticleComment'];
     $id = $post['aid'];
     $admin_info = $this->admin_info;
     $post['is_admin'] = $admin_info['id'];
     $comment_id = $model->createComment($post);
     if ($comment_id) {
         \Think\Hook::listen('postComment', $comment_id);
         \Think\Hook::add('postComment', 'Home\\Behaviors\\emailBehavior');
     }
     $this->redirect('ArticleList/view', array('id' => $id, 'p' => 1));
 }
 public function run(&$content)
 {
     if (isset($_GET['g']) && strtolower($_GET['g']) === 'install') {
         return;
     }
     $data = S('hooks');
     if (!$data) {
         is_array($plugins = M('Plugins')->where("status=1")->getField("name,hooks")) ? null : ($plugins = array());
         foreach ($plugins as $plugin => $hooks) {
             if ($hooks) {
                 $hooks = explode(",", $hooks);
                 foreach ($hooks as $hook) {
                     Hook::add($hook, $plugin);
                 }
             }
         }
         S('hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
 public function hookAction()
 {
     Hook::add('ad', 'Behavior\\adBehavior');
     //添加一个行为钩子
     $this->display();
 }
 /**
  * 行为扩展的执行入口必须是run
  * @author jry <*****@*****.**>
  */
 public function run(&$content)
 {
     // 安装模式下直接返回
     if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
         return;
     }
     // 如果是后台并且不是Admin模块则设置默认控制器层为Admin
     if (MODULE_MARK === 'Admin' && MODULE_NAME !== 'Admin') {
         $oc_config['DEFAULT_C_LAYER'] = 'Admin';
     }
     // 当前模块模版参数配置
     $oc_config['TMPL_PARSE_STRING'] = C('TMPL_PARSE_STRING');
     // 先取出配置文件中定义的否则会被覆盖
     $oc_config['TMPL_PARSE_STRING']['__IMG__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/img';
     $oc_config['TMPL_PARSE_STRING']['__CSS__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/css';
     $oc_config['TMPL_PARSE_STRING']['__JS__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/js';
     $oc_config['TMPL_PARSE_STRING']['__LIBS__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/libs';
     // 获取当前主题的名称
     $current_theme = D('Admin/Theme')->where(array('current' => 1))->order('id asc')->getField('name');
     if ($current_theme) {
         // 前台Home模块静态资源路径及模板继承基本模板
         $home_public_path = './Theme/' . $current_theme . '/Home/Public';
         if (is_dir($home_public_path)) {
             $oc_config['HOME_PUBLIC_LAYOUT'] = $home_public_path . '/layout.html';
             $oc_config['TMPL_PARSE_STRING']['__HOME_IMG__'] = __ROOT__ . '/' . $home_public_path . '/img';
             $oc_config['TMPL_PARSE_STRING']['__HOME_CSS__'] = __ROOT__ . '/' . $home_public_path . '/css';
             $oc_config['TMPL_PARSE_STRING']['__HOME_JS__'] = __ROOT__ . '/' . $home_public_path . '/js';
             $oc_config['TMPL_PARSE_STRING']['__HOME_LIBS__'] = __ROOT__ . '/' . $home_public_path . '/libs';
         }
         // 如果当前主题存在User模板则改变相关配置
         if (is_dir('./Theme/' . $current_theme . '/User')) {
             $oc_config['USER_CENTER_SIDE'] = './Theme/' . $current_theme . '/User/Index/side.html';
             $oc_config['USER_CENTER_FORM'] = './Theme/' . $current_theme . '/User/Builder/form.html';
             $oc_config['USER_CENTER_LIST'] = './Theme/' . $current_theme . '/User/Builder/list.html';
             $oc_config['USER_LOGIN_MODAL'] = './Theme/' . $current_theme . '/User/User/login_modal.html';
         }
         // 当前主题
         $current_theme_path = './Theme/' . $current_theme . '/' . MODULE_NAME . '/';
         //当前主题文件夹路径
         if (is_dir($current_theme_path)) {
             if (MODULE_MARK === 'Home') {
                 $oc_config['VIEW_PATH'] = $current_theme_path;
             }
             $oc_config['CURRENT_THEME'] = $current_theme;
             //默认主题设为当前主题
             // 各模块自带静态资源路径
             $module_public_path = './Theme/' . $current_theme . '/' . MODULE_NAME . '/Public';
             if (is_dir($module_public_path)) {
                 $oc_config['TMPL_PARSE_STRING']['__IMG__'] = __ROOT__ . '/' . $module_public_path . '/img';
                 $oc_config['TMPL_PARSE_STRING']['__CSS__'] = __ROOT__ . '/' . $module_public_path . '/css';
                 $oc_config['TMPL_PARSE_STRING']['__JS__'] = __ROOT__ . '/' . $module_public_path . '/js';
                 $oc_config['TMPL_PARSE_STRING']['__LIBS__'] = __ROOT__ . '/' . $module_public_path . '/libs';
             }
         }
     }
     C($oc_config);
     // 添加配置
     // 读取数据库中的配置
     $system_config = S('DB_CONFIG_DATA');
     if (!$system_config) {
         // 获取所有系统配置
         $system_config = D('Admin/Config')->lists();
         // SESSION与COOKIE与前缀设置避免冲突
         $system_config['SESSION_PREFIX'] = ENV_PRE . MODULE_MARK . '_';
         // Session前缀
         $system_config['COOKIE_PREFIX'] = ENV_PRE . MODULE_MARK . '_';
         // Cookie前缀
         // 获取所有安装的模块配置
         $module_list = D('Admin/Module')->where(array('status' => '1'))->select();
         foreach ($module_list as $val) {
             $module_config[strtolower($val['name'] . '_config')] = json_decode($val['config'], true);
             $module_config[strtolower($val['name'] . '_config')]['module_name'] = $val['name'];
         }
         if ($module_config) {
             // 合并模块配置
             $system_config = array_merge($system_config, $module_config);
             // 加载模块标签库及行为扩展
             $system_config['TAGLIB_PRE_LOAD'] = explode(',', C('TAGLIB_PRE_LOAD'));
             // 先取出配置文件中定义的否则会被覆盖
             foreach ($module_config as $key => $val) {
                 // 加载模块标签库
                 if ($val['taglib']) {
                     foreach ($val['taglib'] as $tag) {
                         $tag_path = APP_PATH . $val['module_name'] . '/' . 'TagLib' . '/' . $tag . '.class.php';
                         if (is_file($tag_path)) {
                             $system_config['TAGLIB_PRE_LOAD'][] = $val['module_name'] . '\\TagLib\\' . $tag;
                         }
                     }
                 }
                 // 加载模块行为扩展
                 if ($val['behavior']) {
                     foreach ($val['behavior'] as $bhv) {
                         $bhv_path = APP_PATH . $val['module_name'] . '/' . 'Behavior' . '/' . $bhv . 'Behavior.class.php';
                         if (is_file($bhv_path)) {
                             \Think\Hook::add('corethink_behavior', $val['module_name'] . '\\Behavior\\' . $bhv . 'Behavior');
                         }
                     }
                 }
             }
             $system_config['TAGLIB_PRE_LOAD'] = implode(',', $system_config['TAGLIB_PRE_LOAD']);
         }
         // 加载Formbuilder扩展类型
         $system_config['FORM_ITEM_TYPE'] = C('FORM_ITEM_TYPE');
         $formbuilder_extend = explode(',', D('Admin/Hook')->getFieldByName('FormBuilderExtend', 'addons'));
         if ($formbuilder_extend) {
             $addon_object = D('Admin/Addon');
             foreach ($formbuilder_extend as $val) {
                 $temp = json_decode($addon_object->getFieldByName($val, 'config'), true);
                 if ($temp['status']) {
                     $form_type[$temp['form_item_type_name']] = array($temp['form_item_type_title'], $temp['form_item_type_field']);
                     $system_config['FORM_ITEM_TYPE'] = array_merge($system_config['FORM_ITEM_TYPE'], $form_type);
                 }
             }
         }
         S('DB_CONFIG_DATA', $system_config, 3600);
         // 缓存配置
     }
     // 移动端强制后台传统视图
     if (is_wap()) {
         $system_config['ADMIN_TABS'] = 0;
     }
     C($system_config);
     // 添加配置
 }
예제 #14
0
파일: common.php 프로젝트: LoveOyy/woaini
    $ssidarr = S("ssid_" . $ssid);
    if (!$ssidarr) {
        return;
    }
    if (!isset($ssidarr['session_die_time']) or $ssidarr['session_die_time'] > time()) {
        S("ssid_" . $_GET['ssid'], false);
        return;
    }
    foreach ($ssidarr as $k => $v) {
        \think\Session::set($k, $v);
    }
});
\think\Hook::add("app_end", function () {
    if (isset($_GET['ssid'])) {
        if (isset($_SESSION)) {
            S("ssid_" . $_GET['ssid'], $_SESSION);
        }
    }
});
function system_error($k)
{
    header("Content-type: application/json");
    $system_error = C("system_error");
    echo json_encode($system_error[$k]);
    die;
}
function throw_out($k)
{
    header("Content-type: application/json");
    $error = C("error");
    $error = $error[CONTROLLER_NAME . "_" . ACTION_NAME];
 /**
  * 行为扩展的执行入口必须是run
  * @author jry <*****@*****.**>
  */
 public function run(&$content)
 {
     // 安装模式下直接返回
     if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
         return;
     }
     // 数据缓存前缀
     // 获取ThinkPHP控制器分级时控制器名称
     $controller_name = explode('/', CONTROLLER_NAME);
     if (sizeof($controller_name) === 2) {
         C('DATA_CACHE_PREFIX', ENV_PRE . MODULE_NAME . '_' . $controller_name[0] . '_');
     } else {
         C('DATA_CACHE_PREFIX', ENV_PRE . MODULE_NAME . '_');
     }
     // 读取数据库中的配置
     $system_config = S('DB_CONFIG_DATA');
     if (!$system_config) {
         // 获取所有系统配置
         $system_config = D('Admin/Config')->lists();
         // 获取所有安装的模块配置
         $module_list = D('Admin/Module')->where(array('status' => '1'))->select();
         foreach ($module_list as $val) {
             $module_config[strtolower($val['name'] . '_config')] = json_decode($val['config'], true);
             $module_config[strtolower($val['name'] . '_config')]['module_name'] = $val['name'];
         }
         if ($module_config) {
             // 合并模块配置
             $system_config = array_merge($system_config, $module_config);
             // 加载模块标签库及行为扩展
             $system_config['TAGLIB_PRE_LOAD'] = explode(',', C('TAGLIB_PRE_LOAD'));
             // 先取出配置文件中定义的否则会被覆盖
             foreach ($module_config as $key => $val) {
                 // 加载模块标签库
                 if ($val['taglib']) {
                     foreach ($val['taglib'] as $tag) {
                         $system_config['TAGLIB_PRE_LOAD'][] = $val['module_name'] . '\\TagLib\\' . $tag . '';
                     }
                 }
                 // 加载模块行为扩展
                 if ($val['behavior']) {
                     foreach ($val['behavior'] as $bhv) {
                         \Think\Hook::add('corethink_behavior', $val['module_name'] . '\\Behavior\\' . $bhv . 'Behavior');
                     }
                 }
             }
             $system_config['TAGLIB_PRE_LOAD'] = implode(',', $system_config['TAGLIB_PRE_LOAD']);
         }
         // 获取当前主题的名称
         $current_theme = D('Admin/Theme')->where(array('current' => 1))->order('id asc')->find();
         // 当前模块模版参数配置
         $system_config['TMPL_PARSE_STRING'] = C('TMPL_PARSE_STRING');
         // 先取出配置文件中定义的否则会被覆盖
         $system_config['TMPL_PARSE_STRING']['__IMG__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/img';
         $system_config['TMPL_PARSE_STRING']['__CSS__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/css';
         $system_config['TMPL_PARSE_STRING']['__JS__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/js';
         $system_config['TMPL_PARSE_STRING']['__LIBS__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/libs';
         if ($current_theme) {
             $current_theme['module'] = explode(',', $current_theme['module']);
             $current_theme['module'][] = 'Home';
             // 强制支持主题对Home的支持
             // 一旦开启主题那么前台必须启用主题相关模版(后台无需支持主题)
             $theme_public_path = './Theme/' . $current_theme['name'] . '/Home/Public';
             if (is_dir($theme_public_path)) {
                 $system_config['TMPL_PARSE_STRING']['__HOME_IMG__'] = __ROOT__ . '/' . $theme_public_path . '/img';
                 $system_config['TMPL_PARSE_STRING']['__HOME_CSS__'] = __ROOT__ . '/' . $theme_public_path . '/css';
                 $system_config['TMPL_PARSE_STRING']['__HOME_JS__'] = __ROOT__ . '/' . $theme_public_path . '/js';
                 $system_config['TMPL_PARSE_STRING']['__HOME_LIBS__'] = __ROOT__ . '/' . $theme_public_path . '/libs';
             }
             // 如果启用的主题配置里勾选了当前模块那么当前模块启用主题相关模版否则仍启用系统模版
             if (in_array(MODULE_NAME, $current_theme['module'])) {
                 $system_config['CURRENT_THEME'] = $current_theme['name'];
                 // 设置当前主题
                 $theme_public_path = './Theme/' . $current_theme['name'] . '/' . MODULE_NAME . '/Public';
                 $theme_wap_path = './Theme/' . $current_theme['name'] . '/' . MODULE_NAME . '/wap';
                 if (is_dir($theme_public_path)) {
                     $system_config['TMPL_PARSE_STRING']['__IMG__'] = __ROOT__ . '/' . $theme_public_path . '/img';
                     $system_config['TMPL_PARSE_STRING']['__CSS__'] = __ROOT__ . '/' . $theme_public_path . '/css';
                     $system_config['TMPL_PARSE_STRING']['__JS__'] = __ROOT__ . '/' . $theme_public_path . '/js';
                     $system_config['TMPL_PARSE_STRING']['__LIBS__'] = __ROOT__ . '/' . $theme_public_path . '/libs';
                 }
                 // 判断是否含有wap专用模版
                 if (is_dir($theme_wap_path)) {
                     $system_config['HAS_WAP'] = 'wap';
                 }
             }
         } else {
             // 判断是否含有wap专用模版
             if (sizeof($controller_name) === 2) {
                 if (is_dir(APP_PATH . MODULE_NAME . '/View/Home/wap')) {
                     $system_config['HAS_WAP'] = 'wap';
                 }
             } else {
                 if (is_dir(APP_PATH . MODULE_NAME . '/View/wap')) {
                     $system_config['HAS_WAP'] = 'wap';
                 }
             }
         }
         // 不直接在config里配置这些参数而要在这里配置是为了支持功能模块的相关架构
         if (MODULE_NAME === 'Admin' || $controller_name[0] === 'Admin') {
             // Admin后台与模块后台标记
             $system_config['MODULE_MARK'] = 'Admin';
             // SESSION与COOKIE与前缀设置避免冲突
             $system_config['SESSION_PREFIX'] = ENV_PRE . 'Admin_';
             // Session前缀
             $system_config['COOKIE_PREFIX'] = ENV_PRE . 'Admin_';
             // Cookie前缀
             // 错误页面模板
             $system_config['TMPL_ACTION_ERROR'] = APP_PATH . 'Admin/View/Public/think/error.html';
             // 错误跳转对应的模板文件
             $system_config['TMPL_ACTION_SUCCESS'] = APP_PATH . 'Admin/View/Public/think/success.html';
             // 成功跳转对应的模板文件
             $system_config['TMPL_EXCEPTION_FILE'] = APP_PATH . 'Admin/View/Public/think/exception.html';
             // 异常页面的模板文件
         } else {
             if (MODULE_NAME === 'Home' || $controller_name[0] === 'Home') {
                 // Home前台与模块前台标记
                 $system_config['MODULE_MARK'] = 'Home';
                 // SESSION与COOKIE与前缀设置避免冲突
                 $system_config['SESSION_PREFIX'] = ENV_PRE . 'Home_';
                 // Session前缀
                 $system_config['COOKIE_PREFIX'] = ENV_PRE . 'Home_';
                 // Cookie前缀
                 // 错误页面模板
                 $system_config['TMPL_ACTION_ERROR'] = APP_PATH . 'Home/View/Public/think/error.html';
                 // 错误跳转对应的模板文件
                 $system_config['TMPL_ACTION_SUCCESS'] = APP_PATH . 'Home/View/Public/think/success.html';
                 // 成功跳转对应的模板文件
                 $system_config['TMPL_EXCEPTION_FILE'] = APP_PATH . 'Home/View/Public/think/exception.html';
                 // 异常页面的模板文件
             }
         }
         S('DB_CONFIG_DATA', $system_config, 3600);
         // 缓存配置
     }
     C($system_config);
     // 添加配置
     // 如果存在wap专用模版同时又确实是wap方式访问则设置WAP标记
     if (C('HAS_WAP') && is_wap()) {
         C('IS_WAP', C('HAS_WAP'));
     }
     // 检测系统授权
     if ($system_config['MODULE_MARK'] === 'Home' && C('CT_USERNAME') !== 'trial') {
         $sn_decode = \Think\Crypt::decrypt(C('CT_SN'), md5(sha1(C('CT_USERNAME'))));
         if ($sn_decode) {
             $sn_decode = explode('[ct]', base64_decode($sn_decode));
             $sn_decode_server = json_decode($sn_decode[0], true);
             if (!in_array($_SERVER['SERVER_NAME'], $sn_decode_server)) {
                 die('很抱歉,该域名未授权!请联系:<a href="http://www.corethink.cn">http://www.corethink.cn</a>');
             }
             if (md5(sha1(C('CT_USERNAME'))) !== $sn_decode[1]) {
                 die('很抱歉,该帐号未授权!请联系:<a href="http://www.corethink.cn">http://www.corethink.cn</a>');
             }
         } else {
             die('很抱歉,您的授权已过期!请联系:<a href="http://www.corethink.cn">http://www.corethink.cn</a>');
         }
     }
 }
예제 #16
0
 /**
  * 行为扩展的执行入口必须是run
  * @author jry <*****@*****.**>
  */
 public function run(&$content)
 {
     // 安装模式下直接返回
     if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
         return;
     }
     // 读取数据库中的配置
     $system_config = S('DB_CONFIG_DATA');
     if (!$system_config || APP_DEBUG === true) {
         // 获取所有系统配置
         $system_config = D('Admin/Config')->lists();
         // SESSION与COOKIE与前缀设置避免冲突
         $system_config['SESSION_PREFIX'] = strtolower(ENV_PRE . MODULE_MARK . '_');
         // Session前缀
         $system_config['COOKIE_PREFIX'] = strtolower(ENV_PRE . MODULE_MARK . '_');
         // Cookie前缀
         // Session数据表
         $system_config['SESSION_TABLE'] = C('DB_PREFIX') . 'admin_session';
         // 获取所有安装的模块配置
         $module_list = D('Admin/Module')->where(array('status' => '1'))->select();
         foreach ($module_list as $val) {
             $module_config[strtolower($val['name'] . '_config')] = json_decode($val['config'], true);
             $module_config[strtolower($val['name'] . '_config')]['module_name'] = $val['name'];
         }
         if ($module_config) {
             // 合并模块配置
             $system_config = array_merge($system_config, $module_config);
             // 加载模块标签库及行为扩展
             $system_config['TAGLIB_PRE_LOAD'] = explode(',', C('TAGLIB_PRE_LOAD'));
             // 先取出配置文件中定义的否则会被覆盖
             foreach ($module_config as $key => $val) {
                 // 加载模块标签库
                 if (isset($val['taglib'])) {
                     foreach ($val['taglib'] as $tag) {
                         $tag_path = APP_PATH . $val['module_name'] . '/' . 'TagLib' . '/' . $tag . '.class.php';
                         if (is_file($tag_path)) {
                             $system_config['TAGLIB_PRE_LOAD'][] = $val['module_name'] . '\\TagLib\\' . $tag;
                         }
                     }
                 }
                 // 加载模块行为扩展
                 if (isset($val['behavior'])) {
                     foreach ($val['behavior'] as $bhv) {
                         $bhv_path = APP_PATH . $val['module_name'] . '/' . 'Behavior' . '/' . $bhv . 'Behavior.class.php';
                         if (is_file($bhv_path)) {
                             \Think\Hook::add('corethink_behavior', $val['module_name'] . '\\Behavior\\' . $bhv . 'Behavior');
                         }
                     }
                 }
             }
             $system_config['TAGLIB_PRE_LOAD'] = implode(',', $system_config['TAGLIB_PRE_LOAD']);
         }
         S('DB_CONFIG_DATA', $system_config, 3600);
         // 缓存配置
     }
     // 系统主页地址配置
     $system_config['TOP_HOME_DOMAIN'] = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'];
     $system_config['HOME_DOMAIN'] = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'];
     $system_config['HOME_PAGE'] = $system_config['HOME_DOMAIN'] . __ROOT__;
     $system_config['TOP_HOME_PAGE'] = $system_config['TOP_HOME_DOMAIN'] . __ROOT__;
     // 如果是后台并且不是Admin模块则设置默认控制器层为Admin
     if (MODULE_MARK === 'Admin' && MODULE_NAME !== 'Admin') {
         $system_config['DEFAULT_C_LAYER'] = 'Admin';
         $system_config['VIEW_PATH'] = APP_PATH . MODULE_NAME . '/View/Admin/';
     }
     // 静态资源域名
     $current_domain = $system_config['TOP_HOME_PAGE'];
     $system_config['CURRENT_DOMAIN'] = $current_domain;
     // 模版参数配置
     $system_config['TMPL_PARSE_STRING'] = C('TMPL_PARSE_STRING');
     // 先取出配置文件中定义的否则会被覆盖
     $system_config['TMPL_PARSE_STRING']['__IMG__'] = $current_domain . '/' . APP_PATH . MODULE_NAME . '/View/Public/img';
     $system_config['TMPL_PARSE_STRING']['__CSS__'] = $current_domain . '/' . APP_PATH . MODULE_NAME . '/View/Public/css';
     $system_config['TMPL_PARSE_STRING']['__JS__'] = $current_domain . '/' . APP_PATH . MODULE_NAME . '/View/Public/js';
     $system_config['TMPL_PARSE_STRING']['__LIBS__'] = $current_domain . '/' . APP_PATH . MODULE_NAME . '/View/Public/libs';
     C($system_config);
     // 添加配置
 }