import() public static method

批量导入插件
public static import ( array $tags, boolean $recursive = true )
$tags array 插件信息
$recursive boolean 是否递归合并
 /**
  * @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);
         }
     }
 }
 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);
     }
 }
Example #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);
     }
 }
 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);
     }
 }
Example #5
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);
     }
 }
 /**
  * 行为扩展的执行入口必须是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);
     }
 }
Example #7
0
 public function testImport()
 {
     Hook::import(['my_pos' => ['\\tests\\thinkphp\\library\\think\\behavior\\One', '\\tests\\thinkphp\\library\\think\\behavior\\Three']]);
     Hook::import(['my_pos' => ['\\tests\\thinkphp\\library\\think\\behavior\\Two']], false);
     Hook::import(['my_pos' => ['\\tests\\thinkphp\\library\\think\\behavior\\Three', '_overlay' => true]]);
     $data['id'] = 0;
     $data['name'] = 'thinkphp';
     Hook::listen('my_pos', $data);
     $this->assertEquals(3, $data['id']);
 }
Example #8
0
 private static function init()
 {
     // 加载初始化文件
     if (is_file(APP_PATH . 'init' . EXT)) {
         include APP_PATH . 'init' . EXT;
         // 加载模块配置
         $config = Config::get();
     } else {
         // 加载模块配置
         $config = Config::load(APP_PATH . 'config' . EXT);
         // 加载应用状态配置
         if ($config['app_status']) {
             $config = Config::load(APP_PATH . $config['app_status'] . EXT);
         }
         // 读取扩展配置文件
         if ($config['extra_config_list']) {
             foreach ($config['extra_config_list'] as $name => $file) {
                 $filename = APP_PATH . $file . EXT;
                 Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME));
             }
         }
         // 加载别名文件
         if (is_file(APP_PATH . 'alias' . EXT)) {
             Loader::addMap(include APP_PATH . 'alias' . EXT);
         }
         // 加载行为扩展文件
         if (APP_HOOK && is_file(APP_PATH . 'tags' . EXT)) {
             Hook::import(include APP_PATH . 'tags' . EXT);
         }
         // 加载公共文件
         if (is_file(APP_PATH . 'common' . EXT)) {
             include APP_PATH . 'common' . EXT;
         }
     }
     // 注册根命名空间
     if (!empty($config['root_namespace'])) {
         Loader::addNamespace($config['root_namespace']);
     }
     // 加载额外文件
     if (!empty($config['extra_file_list'])) {
         foreach ($config['extra_file_list'] as $file) {
             $file = strpos($file, '.') ? $file : APP_PATH . $file . EXT;
             if (is_file($file)) {
                 include_once $file;
             }
         }
     }
     // 设置系统时区
     date_default_timezone_set($config['default_timezone']);
     // 监听app_init
     APP_HOOK && Hook::listen('app_init');
 }
 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);
     }
 }
Example #10
0
 private static function initModule($module, $config)
 {
     // 定位模块目录
     $module = COMMON_MODULE == $module || !APP_MULTI_MODULE ? '' : $module . DS;
     // 加载初始化文件
     if (is_file(APP_PATH . $module . 'init' . EXT)) {
         include APP_PATH . $module . 'init' . EXT;
     } else {
         $path = APP_PATH . $module;
         // 加载模块配置
         $config = Config::load(APP_PATH . $module . 'config' . CONF_EXT);
         // 加载应用状态配置
         if ($config['app_status']) {
             $config = Config::load(APP_PATH . $module . $config['app_status'] . CONF_EXT);
         }
         // 读取扩展配置文件
         if ($config['extra_config_list']) {
             foreach ($config['extra_config_list'] as $name => $file) {
                 $filename = $path . $file . CONF_EXT;
                 Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME));
             }
         }
         // 加载别名文件
         if (is_file($path . 'alias' . EXT)) {
             Loader::addMap(include $path . 'alias' . EXT);
         }
         // 加载行为扩展文件
         if (APP_HOOK && is_file($path . 'tags' . EXT)) {
             Hook::import(include $path . 'tags' . EXT);
         }
         // 加载公共文件
         if (is_file($path . 'common' . EXT)) {
             include $path . 'common' . EXT;
         }
         // 加载当前模块语言包
         if ($config['lang_switch_on'] && $module) {
             Lang::load($path . 'lang' . DS . LANG_SET . EXT);
         }
     }
 }
Example #11
0
File: App.php Project: GDdark/cici
 /**
  * 初始化应用或模块
  * @access public
  * @param string $module 模块名
  * @return array
  */
 private static function init($module = '')
 {
     // 定位模块目录
     $module = $module ? $module . DS : '';
     // 加载初始化文件
     if (is_file(APP_PATH . $module . 'init' . EXT)) {
         include APP_PATH . $module . 'init' . EXT;
     } else {
         $path = APP_PATH . $module;
         // 加载模块配置
         $config = Config::load(CONF_PATH . $module . 'config' . CONF_EXT);
         // 加载应用状态配置
         if ($config['app_status']) {
             $config = Config::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT);
         }
         // 读取扩展配置文件
         if ($config['extra_config_list']) {
             foreach ($config['extra_config_list'] as $name => $file) {
                 $filename = CONF_PATH . $module . $file . CONF_EXT;
                 Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME));
             }
         }
         // 加载别名文件
         if (is_file(CONF_PATH . $module . 'alias' . EXT)) {
             Loader::addClassMap(include CONF_PATH . $module . 'alias' . EXT);
         }
         // 加载行为扩展文件
         if (is_file(CONF_PATH . $module . 'tags' . EXT)) {
             Hook::import(include CONF_PATH . $module . 'tags' . EXT);
         }
         // 加载公共文件
         if (is_file($path . 'common' . EXT)) {
             include $path . 'common' . EXT;
         }
         // 加载当前模块语言包
         if ($config['lang_switch_on'] && $module) {
             Lang::load($path . 'lang' . DS . Request::instance()->langset() . EXT);
         }
     }
     return Config::get();
 }
Example #12
0
 public function __construct()
 {
     //支持方法
     if (!$this->allowMethod) {
         $this->allowMethod = explode(",", strtolower(SUPPORTED_METHOD));
     }
     //session token
     if (I('server.HTTP_TOKEN')) {
         session(array('id' => I("server.HTTP_TOKEN"), 'expire' => 1800));
         session('[start]');
         $this->user = I("session.user");
         $this->is_super_user = $this->user['is_super_user'];
         if (isset($_SESSION['user']) && (!get_current_company_id() || !get_current_user_id())) {
             return $this->login_required();
         }
     }
     tag('before_controller_construct');
     parent::__construct();
     // 当前请求 =》 auth_node
     $this->current_action_all = sprintf("%s.%s.%s.%s", lcfirst(MODULE_NAME), lcfirst(CONTROLLER_NAME), lcfirst(ACTION_NAME), $this->_method);
     //当前用户所属公司
     if ($this->user or true) {
         $this->company = D("Account/Company")->relation(true)->find(get_current_company_id());
     }
     //当前公司启用应用
     $this->activeApps = $this->baseApps;
     if ($this->company) {
         $this->activeApps = array_merge($this->activeApps, get_array_by_field($this->company['apps'], "alias"));
     }
     //启用应用
     AppService::active($this->activeApps, $this->baseApps);
     //当前模块前端别名
     $this->module_alias = __(sprintf('%s.%s', lcfirst(MODULE_NAME), lcfirst(CONTROLLER_NAME)));
     //导入非当前应用的插件及函数等信息
     foreach ($this->activeApps as $app) {
         $app = ucfirst($app);
         if ($app == APP_NAME or $app == "common") {
             continue;
         }
         // 插件
         if (is_file(APPLICATION_PATH . $app . '/Conf/tags.php')) {
             \Think\Hook::import(require APPLICATION_PATH . $app . '/Conf/tags.php');
         }
         // 函数
         if (is_file(APPLICATION_PATH . $app . '/Common/function.php')) {
             require_once APPLICATION_PATH . $app . '/Common/function.php';
         }
     }
     //基本运行配置
     $this->bootstrapConfigs = parse_yml(ENTRY_PATH . '/config.yaml');
     //当前接口版本
     if (I('server.HTTP_API_VERSION')) {
         define('API_VERSION', I('server.HTTP_API_VERSION'));
     } else {
         define('API_VERSION', false);
     }
     //当前语言
     $this->currentLanguage = $this->bootstrapConfigs["default_language"] ? $this->bootstrapConfigs["default_language"] : 'zh-cn';
     if (I("server.HTTP_CLIENT_LANGUAGE")) {
         $this->currentLanguage = I("server.HTTP_CLIENT_LANGUAGE");
     }
     if (I('get.lang')) {
         $this->currentLanguage = I('get.lang');
     }
     define('CURRENT_LANGUAGE', $this->currentLanguage);
     /*
      * 解析应用配置
      * * */
     $cachedAppConfig = S("configs/app/all");
     if (DEBUG or !$cachedAppConfig) {
         foreach (new RecursiveFileFilterIterator(APP_PATH, "config.yml") as $item) {
             $app = lcfirst(basename(dirname($item)));
             $this->appConfigs[$app] = parse_yml($item);
         }
         S("configs/app/all", $this->appConfigs);
     } else {
         if (!DEBUG && $cachedAppConfig) {
             $this->appConfigs = $cachedAppConfig;
         }
     }
     AppService::$allAppConfigs = $this->appConfigs;
     foreach ($this->appConfigs as $app => $config) {
         $this->bootstrapConfigs['auth_dont_need_login'] = array_merge_recursive($this->bootstrapConfigs['auth_dont_need_login'], (array) $config['auth_dont_need_login']);
         $this->bootstrapConfigs['auth_dont_need_check'] = array_merge_recursive($this->bootstrapConfigs['auth_dont_need_check'], (array) $config['auth_dont_need_check']);
     }
     // 当前表名
     if (!$this->model_name) {
         $this->model_name = ucfirst(CONTROLLER_NAME);
     }
     // 获得用户已授权节点
     $authed_nodes = session('authed_nodes');
     if (DEBUG || !$authed_nodes) {
         $authed_nodes = D('Account/Authorize')->get_authed_nodes();
         session('authed_nodes', $authed_nodes);
     }
     self::$authed_nodes = $authed_nodes;
     AuthorizeService::set_authed_nodes($authed_nodes);
     //当前动作权限检测
     // @todo event, event_get
     $current_node_auth_flag = DEBUG ? 1 : $this->check_permission();
     if (substr($this->_method, 0, 5) !== 'event' && false === $current_node_auth_flag) {
         $node_lang = __(lcfirst(MODULE_NAME) . '.METHODS.' . $this->_method) . ' ' . __(lcfirst(MODULE_NAME) . '.' . ucfirst(CONTROLLER_NAME));
         return $this->httpError(403, __("common.Permission Denied") . ": " . $node_lang . "({$this->current_action_all})");
     }
     $this->current_node_auth_flag = (int) $current_node_auth_flag;
     tag('after_controller_construct');
 }
Example #13
0
 /**
  * 初始化模块
  * @access private
  * @return void
  */
 private static function initModule($path, &$config)
 {
     // 加载初始化文件
     if (is_file($path . 'init' . EXT)) {
         include $path . 'init' . EXT;
     } else {
         // 检测配置文件
         if (is_file($path . 'config' . EXT)) {
             $config = Config::set(include $path . 'config' . EXT);
         }
         // 检测额外配置
         if ($config['extra_config_list']) {
             foreach ($config['extra_config_list'] as $conf) {
                 if (is_file($path . $conf . EXT)) {
                     $config = Config::set(include $path . $conf . EXT);
                 }
             }
         }
         // 加载应用状态配置文件
         if ($config['app_status'] && is_file($path . $config['app_status'] . EXT)) {
             $config = Config::set(include $path . $config['app_status'] . EXT);
         }
         // 加载别名文件
         if (is_file($path . 'alias' . EXT)) {
             Loader::addMap(include $path . 'alias' . EXT);
         }
         // 加载公共文件
         if (is_file($path . 'common' . EXT)) {
             include $path . 'common' . EXT;
         }
         // 加载行为扩展文件
         if (is_file($path . 'tags' . EXT)) {
             Hook::import(include $path . 'tags' . EXT);
         }
     }
 }
Example #14
0
 /**
  * 初始化应用或模块
  * @access public
  * @param string $module 模块名
  * @return array
  */
 private static function init($module = '')
 {
     // 定位模块目录
     $module = $module ? $module . DS : '';
     // 加载初始化文件
     if (is_file(APP_PATH . $module . 'init' . EXT)) {
         include APP_PATH . $module . 'init' . EXT;
     } elseif (is_file(RUNTIME_PATH . $module . 'init' . EXT)) {
         include RUNTIME_PATH . $module . 'init' . EXT;
     } else {
         $path = APP_PATH . $module;
         // 加载模块配置
         $config = Config::load(CONF_PATH . $module . 'config' . CONF_EXT);
         // 读取数据库配置文件
         $filename = CONF_PATH . $module . 'database' . CONF_EXT;
         Config::load($filename, 'database');
         // 读取扩展配置文件
         if (is_dir(CONF_PATH . $module . 'extra')) {
             $dir = CONF_PATH . $module . 'extra';
             $files = scandir($dir);
             foreach ($files as $file) {
                 if (strpos($file, CONF_EXT)) {
                     $filename = $dir . DS . $file;
                     Config::load($filename, pathinfo($file, PATHINFO_FILENAME));
                 }
             }
         }
         // 加载应用状态配置
         if ($config['app_status']) {
             $config = Config::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT);
         }
         // 加载行为扩展文件
         if (is_file(CONF_PATH . $module . 'tags' . EXT)) {
             Hook::import(include CONF_PATH . $module . 'tags' . EXT);
         }
         // 加载公共文件
         if (is_file($path . 'common' . EXT)) {
             include $path . 'common' . EXT;
         }
         // 加载当前模块语言包
         if ($module) {
             Lang::load($path . 'lang' . DS . Request::instance()->langset() . EXT);
         }
     }
     return Config::get();
 }
 /**
  * 启动模拟应用
  */
 public function start()
 {
     spl_autoload_register('\\Think\\PhpunitHelper::autoload');
     register_shutdown_function('\\Think\\PhpunitHelper::fatalError');
     Storage::connect(STORAGE_TYPE);
     $mode = (include is_file(CONF_PATH . 'core.php') ? CONF_PATH . 'core.php' : MODE_PATH . APP_MODE . '.php');
     // 加载核心文件
     foreach ($mode['core'] as $file) {
         if (is_file($file)) {
             if (strpos($file, 'Think/Controller.class.php') !== false || strpos($file, 'Think\\Controller.class.php') !== false || strpos($file, 'Think/View.class.php') !== false || strpos($file, 'Think\\View.class.php') !== false) {
                 // not include
             } else {
                 include_once $file;
             }
         }
     }
     // 加载应用模式配置文件
     foreach ($mode['config'] as $key => $file) {
         is_numeric($key) ? C(load_config($file)) : C($key, load_config($file));
     }
     // 读取当前应用模式对应的配置文件
     if ('common' != APP_MODE && is_file(CONF_PATH . 'config_' . APP_MODE . CONF_EXT)) {
         C(load_config(CONF_PATH . 'config_' . APP_MODE . CONF_EXT));
     }
     // 加载模式别名定义
     if (isset($mode['alias'])) {
         self::addMap(is_array($mode['alias']) ? $mode['alias'] : (include $mode['alias']));
     }
     // 加载应用别名定义文件
     if (is_file(CONF_PATH . 'alias.php')) {
         self::addMap(include CONF_PATH . 'alias.php');
     }
     // 加载模式行为定义
     if (isset($mode['tags'])) {
         \Think\Hook::import(is_array($mode['tags']) ? $mode['tags'] : (include $mode['tags']));
     }
     // 加载应用行为定义
     if (is_file(CONF_PATH . 'tags.php')) {
         // 允许应用增加开发模式配置定义
         \Think\Hook::import(include CONF_PATH . 'tags.php');
     }
     // 加载框架底层语言包
     L(include THINK_PATH . 'Lang/' . strtolower(C('DEFAULT_LANG')) . '.php');
     // 调试模式加载系统默认的配置文件
     C(include THINK_PATH . 'Conf/debug.php');
     // 读取应用调试配置文件
     if (is_file(CONF_PATH . 'debug' . CONF_EXT)) {
         C(include CONF_PATH . 'debug' . CONF_EXT);
     }
     C('HTML_CACHE_ON', false);
     C('LIMIT_ROBOT_VISIT', false);
     C('LIMIT_PROXY_VISIT', false);
     $this->run();
 }