/** * Register module * @throws modules_exception * @return object|bool module */ public function register($module) { core::dprint('[mod_register] ' . $module); $module_class = loader::CLASS_PREFIX . $module; $module_path = loader::get_root() . loader::DIR_MODULES . $module . '/'; $module_file = $module_path . 'module' . loader::DOT_PHP; if (!fs::file_exists($module_file)) { throw new modules_exception('Failed to register module ' . $module . '. File does not exists'); } require_once $module_file; $this->set($module, new $module_class($module_path)); return $this->get($module); }
/** * Create handle * @param array params */ public static function factory($parms = 'smarty') { $smarty = false; // $test = loader::$root_path . loader::DIR_MODULES . 'core/tplparser/smarty/Smarty.class.php'; $test = loader::get_root() . loader::DIR_EXT . 'smarty/Smarty.class.php'; if (fs::file_exists($test)) { require $test; $smarty = new Smarty(); $smarty->compile_check = true; $smarty->force_compile = false; // true; $template = core::get_instance()->get_cfg_var('template'); $smarty->caching = false; //TRUE; //$smarty->cache_lifetime = 3600; $smarty->debugging = core::get_instance()->get_cfg_var('debug_templates'); } else { $smarty = new tplparser_mock(); core::dprint('[tplparser] using mock'); } self::$parser = $smarty; self::set_template($template); return $smarty; }
/** * on editor action * * Called in editor to module * * @return array( * 'layout' = false * 'template' = false * ) */ function on_editor() { core::lib('editor')->assign_module_menu($this->get_editor_actions()); // Controller action $controller_action = ''; // modify ident var 'c' (if empty) if (empty(core::get_params()->c) && !empty($this->editor_default_action)) { core::get_params()->c = $this->editor_default_action; } $controller_action = preg_replace('/[^a-z\\d\\_]/i', '', core::get_params()->c); core::dprint("on_editor controller: " . $controller_action); if (empty($controller_action)) { throw new editor_exception('Empty action'); } // check user has access core::lib('editor')->on_editor($this); // dispatch if (!empty($controller_action)) { $controller_action_file = $this->root_dir . "editor/controllers/{$controller_action}" . loader::DOT_PHP; if (fs::file_exists($controller_action_file, false)) { require $controller_action_file; // run controller object, if present $controller_class = $this->get_name() . '_' . $controller_action . '_controller'; if (class_exists($controller_class, 0)) { core::dprint("run controller object : {$controller_class}"); /** @var editor_controller $controller */ $controller = new $controller_class($this); $controller->run(); $layout = $controller->get_layout(); $template = $controller->get_template(); $this->renderer->set_page_template($layout)->set_main_template($template); } else { throw new core_exception('Bad controller class name ' . $controller_class); } } else { core::dprint('[ERROR] Unable to execute ' . $controller_action_file); } } /* @return main template */ /* return array( 'layout' => $layout, 'template' => $template ); */ }
/** * Create or retrieve object bu class * * module name prefixed with {@see loader::CLASS_PREFIX} * * @param string module_name * @param array config ( order_sql , where_sql, limit_sql ) * tpl_table - template name block * @param boolean standalone (регистрировать в системе или нет) * * @return object (&by ref) * * @throws core_exception */ function class_register($module, $config = array(), $standalone = false) { $tmp = false; /* check modules path if yes, make namespace for it */ $path_prefix = $this->root_dir; /* standalone class support without register in $core->classes db class naming: /classes/module/ +- collection (module_collection) +- item (module_item) */ $m_class = $module . '_collection'; // chroot support // [tf]obsolete: auto chroot to module $f_class_path = $path_prefix . 'classes/' . $module . '/'; $f_class = array($f_class_path . 'collection' . loader::DOT_PHP, $f_class_path . 'item' . loader::DOT_PHP); if (!class_exists($m_class)) { if (!fs::file_exists($f_class[0]) || !fs::file_exists($f_class[1])) { core::dprint("[color=red][ERROR CLASS_REGISTER] file not found; [/color] {$module} ({$f_class_path})"); core::dprint($f_class); throw new core_exception("Class register failed : {$module} in " . $path_prefix, core::E_ERROR); return $tmp; // false; } require_once $f_class[0]; require_once $f_class[1]; } if (!$standalone && isset($this->classes[$module])) { return $this->classes[$module]; } /* use prefix render to {$tpl_table} sql from {$table} */ $table_ = $module; $config['prefix'] = core::get_instance()->get_cfg_var(array('database', 'prefix')); $table_ = $config['prefix'] . $table_; // if not passed, set to module tag if (!isset($config['tpl_table'])) { $config['tpl_table'] = $module; } // new one $config_ = array('load' => true, 'table' => $table_, 'root' => $f_class_path); if ($config !== false) { $config_ = array_merge($config_, $config); } // preload fix if (isset($config['no_preload'])) { unset($config_['load']); } // In editor, check for class with 'editor_' prefix if (core::in_editor()) { $editor_class = 'editor_' . $m_class; if (class_exists($editor_class)) { $m_class = $editor_class; } $config_['in_editor'] = true; } $tmp = new $m_class($config_); if ($standalone) { return $tmp; } $this->classes[$module] = $tmp; return $this->classes[$module]; }
/** * Register module * @throws modules_exception * @return core_module */ public function register($module, $params = null) { $module_class = isset($params['class']) ? $params['class'] : $module; $module_class = (isset($params['prefix']) ? $params['prefix'] : loader::CLASS_PREFIX) . $module_class; $module_path_orig = loader::DIR_MODULES . $module . '/'; $module_path = loader::get_public(); $module_path .= isset($params['path']) ? $params['path'] : loader::DIR_MODULES . $module; $module_path .= '/'; $module_file = $module_path; $module_file .= (isset($params['file']) ? $params['file'] : 'module') . loader::DOT_PHP; core::dprint(array('module::register %s, %s', $module, $module_class), core::E_DEBUG0); if (!fs::file_exists($module_file)) { core::dprint_r(array($module_class, $module_file)); throw new module_exception('Failed to register module ' . $module . '. File does not exists'); } require_once $module_file; if (!class_exists($module_class, 0)) { throw new module_exception('Cant load module ' . $module . ', wrong config?'); } // autotag module, if alternative class used if (!isset($params['tag']) && !empty($params['class'])) { $params['tag'] = $module; } $module_path = loader::fix_path(loader::get_public() . (!empty($params['chroot']) ? $module_path : $module_path_orig)); $this->set($module, new $module_class($module_path, $params)); $newb = $this->get($module); $newb->init_config($this->_get_module_config($module), abs_config::INIT_APPEND); return $newb; }
/** * on editor action * * Called in editor to module */ function on_editor() { $actions_file = "{$this->root_dir}editor/actions.php"; if (file_exists($actions_file)) { // this is array of actions $menu = (require $actions_file); core::lib('editor')->assign_module_menu($menu); } // Включаемый файл $inc_ = ''; /** * @todo * При добавлении новых разделов, * не забудьте прописать в index.tpl * опцию для подключения нового раздела */ // this modify ident var (if its empty)! if (empty(core::get_params()->c) && !empty($this->editor_default_action)) { core::get_params()->c = $this->editor_default_action; } $inc_ = preg_replace('/[^a-z\\d\\_]/i', '', core::get_params()->c); core::dprint("on_editor : " . $inc_); /* подключаем обработчик */ if (!empty($inc_)) { $inc_ = $this->root_dir . "editor/controllers/{$inc_}" . loader::DOT_PHP; if (fs::file_exists($inc_, false)) { require $inc_; } else { core::dprint('[ERROR] Unable to execute ' . $inc_); } } /* @return main template */ return 'index.tpl'; }
/** * Parse module langwords into one * huge array. Used in templates later. * Module lang start with m_ * [lang.var] */ public function import_langwords($module) { $lang = $this->cfg('lang'); $lang_file = loader::get_public(loader::DIR_MODULES) . $module . '/' . loader::DIR_LANGS . $lang; if (fs::file_exists($lang_file)) { $temp = parse_ini_file($lang_file, true); //self::dprint('..language ' . $lang_file . " (x" . count($temp) . ")", core::E_DEBUG1); if ('core' == $module) { $this->langwords = array_merge_recursive($this->langwords, $temp); } else { $this->langwords['_' . $module] = $temp; } } }
/** * Create or retrieve object by class * * module name prefixed with {@see loader::CLASS_PREFIX} * * @param string module_name * @param array config ( order_sql , where_sql, limit_sql ) * tpl_table - template name block * extend - extend base model classes, chrooted in /model/{extend}/*.php, naming: {extend}_base_collection * @param boolean standalone (регистрировать в системе или нет) * * @return abs_collection (&by ref) * * @depricated use $this->model() * * @throws core_exception */ function class_register($model, $config = array(), $standalone = true) { // check for module.model $module = ''; if (is_string($model) && false !== strpos($model, '.')) { $model = explode('.', $model); } if (is_array($model)) { $module = $model[0]; $model = $model[1]; } // call external module if (!empty($module) && $module != $this->get_name()) { return core::module($module)->class_register($model, $config, $standalone); } $_model = $model; $is_extended = false; if (isset($config['extend'])) { $_model = $config['extend'] . '_' . $_model; $is_extended = true; } // return if not standalone & registered if (!$standalone && $this->class_registered($model)) { return $this->classes[$model]; } $tmp = false; $model_prefix = ''; /* * `with_module_prefix` turn on by default on all modules, rather than `users` and `core` * /class/{model}/collectoin.php --> {module}_{model}_collection */ $this_module = $this->get_name(); if ($this_module != 'core' && $this_module != 'users') { $config['with_module_prefix'] = true; } if (isset($config['with_module_prefix'])) { $model_prefix = $this->get_name() . '_'; } /* check modules path if yes, make namespace for it */ $path_prefix = $this->root_dir; /* standalone class support without register in $core->classes db class naming: /classes/model/ +- collection (model_collection) +- item (model_item) */ $m_class = $model_prefix . $model . '_collection'; $m_class_item = $model_prefix . $model . '_item'; // chroot support // [tf]obsolete: auto chroot to module $f_class_path = $path_prefix . 'classes/' . $model . '/'; $f_class = array($f_class_path . 'collection' . loader::DOT_PHP, $f_class_path . 'item' . loader::DOT_PHP); if (!class_exists($m_class, 0)) { if (!fs::file_exists($f_class[0])) { // || !fs::file_exists($f_class[1])) { core::dprint(get_class($this) . "::class_register '{$m_class}' ({$model}) file not found {$f_class[0]}"); core::dprint($f_class); throw new core_exception("Class register failed : {$model} in " . $path_prefix); return $tmp; // false; } require_once $f_class[0]; } if (!class_exists($m_class_item, 0) && fs::file_exists($f_class[1])) { require_once $f_class[1]; } if (!$standalone && isset($this->classes[$model])) { return $this->classes[$model]; } /* use prefix render to {$tpl_table} sql from {$table} */ $table_ = $model_prefix . $model; //autoprefix when create collection //$config['prefix'] = core::get_instance()->get_cfg_var(array('database', 'prefix')); //$table_ = $config['prefix'] . $table_; // if not passed, set to module tag if (!isset($config['tpl_table'])) { $config['tpl_table'] = $model_prefix . $model; } // new one $config_ = array('table' => $table_, 'root' => $f_class_path); if ($config !== false) { $config_ = array_merge($config_, $config); } // preload fix if (isset($config['no_preload']) && isset($config_['load'])) { unset($config_['load']); } if (!class_exists($m_class, 0)) { throw new core_exception('Cant register collection, no class : ' . $m_class); } $tmp = new $m_class($config_); if ($standalone) { return $tmp; } $this->classes[$model] = $tmp; return $this->classes[$model]; }
/** * Parse module langwords into one * huge array. Used in templates later. * Module lang start with m_ * [lang.var] */ public function import_langwords($module) { $lang = $this->get_cfg_var('lang'); $lang_file = loader::get_root() . loader::DIR_MODULES . $module . '/' . loader::DIR_LANGS . $lang; if (fs::file_exists($lang_file)) { $temp = parse_ini_file($lang_file, true); self::dprint('[LANG_INCLUDE] ' . $lang_file . " (x" . count($temp) . ")"); if ('core' == $module) { $this->langwords = array_merge_recursive($this->langwords, $temp); } else { $this->langwords['m_'][$module] = $temp; } } }