/** * @param string $model * @param string $mode * @return bool * @throws AException */ public function model($model, $mode = '') { //force mode alows to load models for ALL extensions to bypass extension enabled only status $force = ''; if ($mode == 'force') { $force = 'all'; } $file = DIR_APP_SECTION . 'model/' . $model . '.php'; if ($this->registry->has('extensions') && ($result = $this->extensions->isExtensionResource('M', $model, $force))) { if (is_file($file)) { $warning = new AWarning("Extension <b>{$result['extension']}</b> override model <b>{$model}</b>"); $warning->toDebug(); } $file = $result['file']; } $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model); if (file_exists($file)) { include_once $file; $this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry)); } else { if ($mode != 'silent') { throw new AException(AC_ERR_LOAD, 'Error: Could not load model ' . $model . ' from ' . $file); } else { return false; } } }
public function __call($method, $args) { if (!$this->registry->has('extensions')) { return null; } array_unshift($args, $this); $return = call_user_func_array(array($this->extensions, $method), $args); return $return; }
/** * Данные пользователя * @param string $key название поля в таблице * @return string|object данные пользователя */ public static function get($key = null) { if (Registry::has('user')) { $user = Registry::get('user'); return $key ? $user->{$key} : $user; } }
function post_list() { // only run on the first call if (!Registry::has('rwar_post_archive')) { // capture original article if one is set if ($article = Registry::get('article')) { Registry::set('original_article', $article); } } if (!($posts = Registry::get('rwar_post_archive'))) { $posts = Post::where('status', '=', 'published')->sort('created', 'desc')->get(); Registry::set('rwar_post_archive', $posts = new Items($posts)); } if ($result = $posts->valid()) { // register single post Registry::set('article', $posts->current()); // move to next $posts->next(); } else { // back to the start $posts->rewind(); // reset original article Registry::set('article', Registry::get('original_article')); // remove items Registry::set('rwar_post_archive', false); } return $result; }
/** * Получение настроек * @param string $key Имя настройки * @return string Значение настройки */ public static function get($key) { if (!Registry::has('setting')) { Registry::set('setting', App::arrayAssoc(self::all(), 'name', 'value')); } return Registry::get('setting')[$key]; }
/** * Destructor function * * Sets the previous URL to the current URL, so the that next request * can refer to it easily and know whatthe previous request URL was. */ public function __destruct() { if (Registry::has('router')) { $this->_zula->resetCwd(); if ($this->storePrevious === true && $this->_dispatcher->getStatusCode() != 404) { $_SESSION['previous_url'] = $this->_router->getCurrentUrl(); } $_SESSION['last_activity'] = time(); } }
/** * @param string $model * @param string $mode * @return bool * @throws AException */ public function model($model, $mode = '') { //force mode alows to load models for ALL extensions to bypass extension enabled only status //This might be helpful in storefront. In admin all installed extenions are available $force = ''; if ($mode == 'force') { $force = 'all'; } //mode to force load storefront model $section = DIR_APP_SECTION; if ($mode == 'storefront') { $section = DIR_ROOT . '/storefront/'; } $file = $section . 'model/' . $model . '.php'; if ($this->registry->has('extensions') && ($result = $this->extensions->isExtensionResource('M', $model, $force, $mode))) { if (is_file($file)) { $warning = new AWarning("Extension <b>{$result['extension']}</b> override model <b>{$model}</b>"); $warning->toDebug(); } $file = $result['file']; } $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model); $obj_name = 'model_' . str_replace('/', '_', $model); //if modal is loaded return it back if (is_object($this->registry->get($obj_name))) { return $this->registry->get($obj_name); } else { if (file_exists($file)) { include_once $file; $this->registry->set($obj_name, new $class($this->registry)); return $this->registry->get($obj_name); } else { if ($mode != 'silent') { $backtrace = debug_backtrace(); $file_info = $backtrace[0]['file'] . ' on line ' . $backtrace[0]['line']; throw new AException(AC_ERR_LOAD, 'Error: Could not load model ' . $model . ' from ' . $file_info); return false; } else { return false; } } } }
/** * Main method that is called on all loggers from * the Log class. * * @param string $message * @param int $level * @param string $file * @param int $line * @return bool */ public function logMessage($msg, $level, $file = 'unknown', $line = 0) { $fileName = $this->makeFileName($level); $filePath = $this->logDir . '/' . $fileName; if (!zula_is_writable($this->logDir)) { return false; } $uid = Registry::has('session') ? $this->_session->getUserId() : 'unknown'; $msgFormat = '[%1$s] [%2$s | uid %3$s] [%4$s] -- (%5$s:%6$d) %7$s' . "\r\n"; $entry = sprintf($msgFormat, date('c'), zula_get_client_ip(), $uid, $this->levelName($level), basename($file), $line, $msg); return error_log($entry, 3, $filePath); }
/** * Detect file for default or extension language * @param string $filename * @param string $language_dir_name * @return null|string */ protected function _detect_language_xml_file($filename, $language_dir_name = 'english') { if (empty($filename)) { return null; } $file_path = $this->language_path . $language_dir_name . '/' . $filename . '.xml'; if ($this->registry->has('extensions') && ($result = $this->registry->get('extensions')->isExtensionLanguageFile($filename, $language_dir_name, $this->is_admin))) { if (is_file($file_path)) { $warning = new AWarning("Extension <b>{$result['extension']}</b> overrides language file <b>{$filename}</b>"); $warning->toDebug(); } $file_path = $result['file']; } return $file_path; }
/** * Listener for 'bootstrap_loaded' hook. * Adds in required JS files for the editor to display * * @return array */ public function hookBootstrapLoaded() { if ($this->loadEditor === true && Registry::has('theme')) { foreach (new DirectoryIterator($this->_zula->getDir('js') . '/tinymce/plugins') as $file) { if (substr($file, 0, 1) != '.' && $file->isDir()) { $tinyMcePlugins[] = $file->getFileName(); } } $tinyMcePlugins = implode(',', $tinyMcePlugins); $this->_theme->addHead('js', array(), 'var tcmEditor = {defaultFormat: "' . Editor::defaultFormat() . '", tinymcePlugins: "' . $tinyMcePlugins . '"};'); $this->_theme->addJsFile('tinymce/jquery.tinymce.js'); $this->_theme->addJsFile('js/init.js', true, 'editor'); } return true; }
/** * Generates a DateTime object using the given parameters. * * @param string $time A string which represents the current time. * @param string|\DateTimeZone $timezone The locale to set the timezone. */ public function __construct($time = 'now', $timezone = 'UTC') { if (Registry::has('config')) { $timezoneString = Registry::get('config')->get('timezone'); if (!empty($timezoneString)) { $this->timeZoneLocal = new \DateTimeZone($timezoneString); } } if (!isset($this->timeZoneLocal)) { $this->timeZoneLocal = new \DateTimeZone(SERVER_TIMEZONE); } if (is_string($timezone)) { $timezone = new \DateTimeZone($timezone); } $this->timeZone = $timezone; parent::__construct($time, $timezone); }
/** * Check if the currently installed version is supported * by this upgrader * * @return bool|string */ public function indexSection() { $_SESSION['upgradeStage'] = 1; if (Registry::has('sql') && in_array(_PROJECT_VERSION, $this->supportedVersions)) { if (isset($_SESSION['upgradeStage'])) { ++$_SESSION['upgradeStage']; } $_SESSION['project_version'] = _PROJECT_VERSION; // Set the event and redirect to next stage $langStr = t('Found version "%1$s" and will upgrade to "%2$s"'); $this->_event->success(sprintf($langStr, _PROJECT_VERSION, _PROJECT_LATEST_VERSION)); return zula_redirect($this->_router->makeUrl('upgrade', 'security')); } $langStr = t('Version %s is not supported by this upgrader'); $this->_event->error(sprintf($langStr, _PROJECT_VERSION)); if ($this->_zula->getMode() == 'cli') { $this->_zula->setExitCode(3); return false; } else { return zula_redirect($this->_router->makeUrl('index')); } }
/** * Logs the error that has occurred via the main Logger * if set to log error messages. * * @param string $summary * @param string $details * @param int $level * @return bool */ protected function logError($message, $level, $file = null, $line = null) { if ($this->logErrors && Registry::has('log')) { return $this->_log->message($message, $level, $file, $line); } }
/** * Add in the right RSS feed to the HTML head * * @param array $rData * @return array */ public function hookCntrlrPreDispatch($rData) { if (Registry::has('theme')) { if ($rData['module'] != 'rss' && $rData['controller'] != 'feed') { // Get the default feed try { $defFeed = array(); $defFeed[] = $this->_config->get('rss/default_feed'); if (!Rss::feedExists($defFeed[0])) { unset($defFeed[0]); } } catch (Config_KeyNoExist $e) { $this->_log->message('RSS config key "rss/default_feed" does not exist, unable to add default feed to head.', Log::L_WARNING); } // Find all the RSS feeds for the current page $feeds = Hooks::notifyAll('rss_insert_head', $rData['module'], $rData['controller'], $rData['section']); if (is_array($feeds)) { foreach (array_filter(array_merge($defFeed, $feeds)) as $feed) { // Add all found feeds to head $rss = new Rss($feed); if ($rss->hasFeedInfo()) { $details = array('rel' => 'alternate', 'type' => 'application/rss+xml', 'href' => $this->_router->makeFullUrl('rss', 'feed', $feed), 'title' => $rss->getFeedInfo('title')); $this->_theme->addHead('link', $details); } else { $this->_log->message('Feed "' . $feed . '" does not have feed info set.', Log::L_WARNING); } } } } } return $rData; }
/** * Данные роутов * @return object данные роутов */ public static function router($key) { if (Registry::has('router')) { return Registry::get('router')[$key]; } }
<?php require '../engine/registry.php'; $registry = new Registry(); $registry->set('a', "1"); $registry->set('b', "2"); echo $registry->get('a'); echo "<br/>"; echo $registry->has('b'); echo "<br/>"; echo $registry->has('c'); echo "<br/>"; echo $registry->get('d');
*/ require $zula->getDir('zula') . '/setup.php'; } else { $zula->loadLib('ugmanager'); try { $uid = $session->identify($_SESSION['auth']['key'], $_SESSION['auth']['for']); if ($uid === false) { throw new Exception(); } } catch (Exception $e) { $uid = $session->identify(); # Identify as guest for fail safe } } define('_ACL_ENABLED', (bool) $config->get('acl/enable')); if (Registry::has('sql')) { $acl = $zula->loadLib('acl'); } Hooks::load(); // Load the main router of the correct type if ($input->has('get', 'ns') || function_exists('apache_get_modules') && !in_array('mod_rewrite', apache_get_modules())) { $router = new Router(); } else { $router = new Router($config->get('url_router/type')); } Registry::register('router', $router); /** * Microsoft Web App Gallery (Feature #221) support. */ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && file_exists('msInstall.php')) { return require 'msInstall.php';
/** * Run application * * @staticvar boolean $is_init * @staticvar array $routes * @param $route (optional, ex: 'my/route->action') * @return void */ public function run($route = null) { static $is_init = false; static $routes = []; // routes stack for current request if (!$is_init) { $this->log->trace('Initializing', Logger::CATEGORY_DRONE); // param default values $default = [self::KEY_DEBUG => true, self::KEY_ERROR_BACKTRACE => true, self::KEY_ERROR_HANDLER => ['\\Drone\\Core', 'errorHandler'], self::KEY_ERROR_LOG => false, self::KEY_EXT_TEMPLATE => '.tpl', self::KEY_EXT_WEB => '.htm', self::KEY_PATH_CONTROLLER => PATH_ROOT . '_app/mod', self::KEY_PATH_TEMPLATE => PATH_ROOT . '_app/tpl', self::KEY_PATH_TEMPLATE_GLOBAL => PATH_ROOT . '_app/tpl/_global']; // init param default values foreach ($default as $k => $v) { if (!Registry::has($k)) { Registry::set($k, $v); } } // set default error handler if (is_array(Registry::get(self::KEY_ERROR_HANDLER))) { set_error_handler(Registry::get(self::KEY_ERROR_HANDLER)); } // init paths $this->__formatDir(Registry::get(self::KEY_PATH_CONTROLLER)); $this->__formatDir(Registry::get(self::KEY_PATH_TEMPLATE)); $this->__formatDir(Registry::get(self::KEY_PATH_TEMPLATE_GLOBAL)); $is_init = true; } Registry::set(self::KEY_ROUTE_CONTROLLER, false); // init controller if ($route !== null) { $routes[] = $route; // cache route $route = new Route(null, $route); Registry::set([self::KEY_ROUTE_CONTROLLER => $route->getController(), self::KEY_ROUTE_CLASS => $route->getClass(), self::KEY_ROUTE_TEMPLATE => $route->getController()]); if ($route->isAction()) { Registry::set(self::KEY_ROUTE_ACTION, $route->getAction()); } $this->log->trace('Route set: \'' . Registry::get(self::KEY_ROUTE_CONTROLLER) . '\'', Logger::CATEGORY_DRONE); } else { $is_index = false; $request = $_SERVER['REQUEST_URI']; $this->log->trace('Process request: \'' . $request . '\'', Logger::CATEGORY_DRONE); Registry::set(self::KEY_REQUEST, $request); if (($pos = strpos($request, '?')) !== false) { $request = substr($request, 0, $pos); } unset($pos); $routes[] = $request; if (substr($request, -1) != '/') { // ensure request has web extension if (substr($request, -strlen(Registry::get(self::KEY_EXT_WEB))) === Registry::get(self::KEY_EXT_WEB)) { // do not allow direct access to index like '/path/index.htm' if (basename($request) === 'index' . Registry::get(self::KEY_EXT_WEB)) { $this->error(self::ERROR_404); // kick direct index request return; } // rm web extension $request = substr($request, 0, strlen($request) - strlen(Registry::get(self::KEY_EXT_WEB))); } else { $this->error(self::ERROR_404); // kick request return; } } else { $is_index = true; } $r = null; foreach ($this->__routes as $r) { if ($rf = $r->matchFile($request)) { $this->log->trace('Route file loaded: \'' . $r->getController() . '\'', Logger::CATEGORY_DRONE); foreach ($rf as $k => $v) { $r = new Route($k, $v); if ($r->match($request)) { break 2; // match } } } else { if ($r->match($request)) { break; // match } } $r = null; // no match } if ($r) { $this->log->trace('Route (mapped) detected: \'' . $r->getPath() . '\'', Logger::CATEGORY_DRONE); Registry::set([self::KEY_ROUTE_CONTROLLER => $r->getController(), self::KEY_ROUTE_CLASS => $r->getClass(), self::KEY_ROUTE_TEMPLATE => $r->getController()]); if ($r->isAction()) { Registry::set(self::KEY_ROUTE_ACTION, $r->getAction()); } $this->view->setRouteParams($r->getParams()); // set route params } unset($r); // test static routes if (Registry::get(self::KEY_ROUTE_CONTROLLER) === false) { $request = str_replace('/', DIRECTORY_SEPARATOR, $request); if ($is_index) { $request .= 'index'; } Registry::set([self::KEY_ROUTE_CONTROLLER => $request, self::KEY_ROUTE_TEMPLATE => $request]); $this->log->trace('Route (static) detected: \'' . Registry::get(self::KEY_ROUTE_CONTROLLER) . '\'', Logger::CATEGORY_DRONE); } // cleanup unset($is_index, $request); } if (max(array_count_values($routes)) > 1) { $routes = []; // reset $this->error(self::ERROR_500, 'Route loop detected'); return; } // set full paths + extensions Registry::set(self::KEY_ROUTE_CONTROLLER, Registry::get(self::KEY_PATH_CONTROLLER) . ltrim(Registry::get(self::KEY_ROUTE_CONTROLLER), DIRECTORY_SEPARATOR) . '.php'); Registry::set(self::KEY_ROUTE_TEMPLATE, Registry::get(self::KEY_PATH_TEMPLATE) . ltrim(Registry::get(self::KEY_ROUTE_TEMPLATE), DIRECTORY_SEPARATOR) . Registry::get(self::KEY_EXT_TEMPLATE)); try { $this->view->resetTemplate(); // reset template (for multiple runs like errors) $this->view->setDefaultTemplate(Registry::get(self::KEY_ROUTE_TEMPLATE)); // set default template $this->error(false); // reset error flag if (is_file(Registry::get(self::KEY_ROUTE_CONTROLLER))) { ob_start(); // buffer output $this->__hooks(self::HOOK_BEFORE, 'before'); if (isset($this->__hooks[self::HOOK_BEFORE])) { foreach ($this->__hooks[self::HOOK_BEFORE] as $hook) { require $hook; } } $this->log->trace('Loading controller: \'' . Registry::get(self::KEY_ROUTE_CONTROLLER) . '\'', Logger::CATEGORY_DRONE); require_once Registry::get(self::KEY_ROUTE_CONTROLLER); $this->__headersSend(); // send headers $controller_class = Registry::get(self::KEY_ROUTE_CLASS); // call controller action if (Registry::has(self::KEY_ROUTE_ACTION)) { $this->log->trace('Calling action: \'' . Registry::get(self::KEY_ROUTE_ACTION) . '\' on controller class \'' . $controller_class . '\'', Logger::CATEGORY_DRONE); if (!class_exists($controller_class, false)) { if (count($routes) > 1) { $this->log->fatal('Multiple route controllers not found loop detected', Logger::CATEGORY_DRONE); $this->stop(); } $this->error(self::ERROR_500, 'Class \'' . $controller_class . '\' not found when calling route action'); return; } if (!method_exists($controller_class, Registry::get(self::KEY_ROUTE_ACTION))) { $this->error(self::ERROR_500, 'Method \'' . $controller_class . '::' . Registry::get(self::KEY_ROUTE_ACTION) . '\' not found when calling route action'); return; } // set controller instance $controller = new $controller_class(); if (method_exists($controller, '__before')) { $controller->__before(); } // call controller action $controller->{Registry::get(self::KEY_ROUTE_ACTION)}(); if (method_exists($controller, '__after')) { $controller->__after(); } } else { if ($this->deny(null)) { $this->error(self::ERROR_404, 'Deny no action'); return; } } unset($controller_class); // cleanup if (!Registry::get(self::KEY_DEBUG)) { $this->__bufferClean(); } $this->__hooks(self::HOOK_MIDDLE, 'middle'); if (isset($this->__hooks[self::HOOK_MIDDLE])) { foreach ($this->__hooks[self::HOOK_MIDDLE] as $hook) { require $hook; } } // view display template if (!is_null($this->view->getTemplate())) { $this->log->trace('Loading view template: \'' . $this->view->getTemplate() . '\'', Logger::CATEGORY_DRONE); if (!is_file($this->view->getTemplate())) { $this->error(self::ERROR_500, 'View template \'' . $this->view->getTemplate() . '\' not found'); return; } if (isset($controller)) { extract(get_object_vars($controller), EXTR_OVERWRITE); } // extract all view public properties for variable use in template extract(get_object_vars($this->view), EXTR_OVERWRITE); if (strlen($this->view->getTemplateHeader()) > 0) { include $this->view->getTemplateHeader(); } require $this->view->getTemplate(); if (strlen($this->view->getTemplateFooter()) > 0) { include $this->view->getTemplateFooter(); } } if (!$this->error()) { ob_end_flush(); // flush buffer $this->stop(); // finalize application } else { ob_end_clean(); // clean buffer $this->error(self::ERROR_500); // call 500 error handler } } else { $this->error(self::ERROR_404); } } catch (\Exception $ex) { $this->error($ex); } }
/** * Provides some common, default tags that can be used in * every view file * * @return array */ protected function getDefaultTags() { if (!($tags = $this->_cache->get('view_default_tags'))) { try { $tmpLang = explode('.', $this->_config->get('locale/default')); $lang = $tmpLang[0]; } catch (Config_KeyNoExist $e) { $lang = 'en'; } $tags = array('DIR_BASE' => _BASE_DIR, 'DIR_ASSETS' => $this->_zula->getDir('assets', true), 'DIR_JAVASCRIPT' => $this->_zula->getDir('js', true), 'DIR_THEME' => $this->_zula->getDir('themes', true), 'DIR_UPLOADS' => $this->_zula->getDir('uploads', true), 'SITE_SLOGAN' => $this->_config->get('config/slogan'), 'SITE_TITLE' => $this->_config->get('config/title'), 'URL_ADMIN' => $this->_router->makeUrl(null, null, null, 'admin'), 'URL_MAIN' => $this->_router->makeUrl(null, null, null, 'main'), 'LANGUAGE' => $lang); // Add in the tags that will *not* have characters convereted to HTML entities $tags['plain'] = array('SITE_TITLE' => $tags['SITE_TITLE'], 'SITE_SLOGAN' => $tags['SITE_SLOGAN']); $this->_cache->add('view_default_tags', $tags); } // Add in some tags which should not be cached $tags['URL_CURRENT_ST'] = $this->_router->makeUrl(''); $tags['META_DESCRIPTION'] = $this->_config->get('meta/description'); $tags['META_KEYWORDS'] = $this->_config->get('meta/keywords'); if (Registry::has('theme')) { $theme = Registry::get('theme'); $tags['DIR_CUR_THEME'] = $tags['DIR_THEME'] . '/' . $theme->getDetail('name'); $tags['THEME_STYLE'] = $theme->getDetail('style'); } return $tags; }
/** * Function returns all tpl with pre or post prefixes for all enabled extensions * @param string $route - relative path of file. * @return array|bool */ public function getAllPrePostTemplates($route) { if (!$this->registry->has('config')) { return false; } $ext_section = IS_ADMIN ? DIR_EXT_ADMIN : DIR_EXT_STORE; $tmpl_id = IS_ADMIN ? $this->registry->get('config')->get('admin_template') : $this->registry->get('config')->get('config_storefront_template'); $file = $ext_section . DIR_EXT_TEMPLATE . $tmpl_id . '/template/' . $route; $source = $this->extension_templates; $section = trim($ext_section, '/'); //list only enabled extensions $extensions_lookup_list = $this->enabled_extensions; $output = array(); foreach ($extensions_lookup_list as $ext) { //looking for active template tpl $f = DIR_EXT . $ext . $file; $ext_tpls = is_array($source[$ext][$section]) ? $source[$ext][$section] : array(); if (in_array($route, $ext_tpls)) { if (is_file($f)) { $output[$ext] = array('file' => $f, 'extension' => $ext, 'base_path' => $file); } //if active template tpl not found - looking for default if (!isset($output[$ext])) { //check default template $f = DIR_EXT . $ext . $ext_section . DIR_EXT_TEMPLATE . 'default/template/' . $route; if (is_file($f)) { $output[] = array('file' => $f, 'extension' => $ext, 'base_path' => $ext_section . DIR_EXT_TEMPLATE . 'default/template/' . $route); } } } } return $output; }
/** * Gets all disabled modules either from SQL or the stored array * * @return array */ public static function getDisabledModules() { if (is_null(self::$disabledModules)) { if (!Registry::has('sql')) { return array(); } self::$disabledModules = Registry::get('sql')->query('SELECT name FROM {PREFIX}modules WHERE disabled = 1')->fetchAll(PDO::FETCH_COLUMN); } return self::$disabledModules; }
/** * Plural version of t() * * @param string $string1 * @param string $string2 * @param int $n * @param string $textDomain * @return string */ function nt($string1, $string2, $n, $textDomain = null) { if (Registry::has('i18n')) { return Registry::get('i18n')->nt($string1, $string2, $n, $textDomain); } else { trigger_error('nt() no i18n engine has currently been loaded', E_USER_WARNING); return $string1; } }
/** * Save the layout file and updates/inserts SQL entry if needed * * @param string $path * @return bool */ public function save($path = null) { $path = trim($path) ? $path : $this->path; if ((file_exists($path) && zula_is_writable($path) || !file_exists($path) && zula_is_writable(dirname($path))) && $this->dom->save($path)) { if (Registry::has('sql')) { if ($regex = $this->getRegex()) { $pdoSt = $this->_sql->prepare('INSERT INTO {PREFIX}layouts (name, regex) VALUES (?, ?) ON DUPLICATE KEY UPDATE regex = VALUES(regex)'); $pdoSt->execute(array($this->name, $this->getRegex())); } else { $pdoSt = $this->_sql->prepare('DELETE FROM {PREFIX}layouts WHERE name = ?'); $pdoSt->execute(array($this->name)); } } return true; } else { return false; } }
/** * Builds a form for a user to use which will allow him/her/it to alter the rules * for an ACL Resource and Roles. * * If providing multiple resources, you can also provide specific ACL role hints for * default selection. * * A prefix can be set which will limit which Roles should be shown within the form, * by default - it is anything that begins with 'group_' * * @param mixed $resource * @param string $prefix * @return string|bool */ public function buildForm($resource, $prefix = 'group_') { /** * Get the role tree for the guest group/role, so that better defaults can be * set for the checkboxes, each role it inherits will be checked. */ $guestGroup = $this->_ugmanager->getGroup(Ugmanager::_GUEST_GID); $roleHint = array(); foreach ($this->getRoleTree($guestGroup['role_id'], true) as $tmpRole) { $roleHint[] = $tmpRole['id']; } $rootRole = $this->getRole('group_root'); $roleHint[] = $rootRole['id']; # Makes root default as well // Build the correct array structure for the resources $roles = $this->getAllRoles($prefix); # Get all of the roles that match the prefix to be used later $resources = array(); foreach ((array) $resource as $name => $details) { if (is_array($details)) { // We have a provided RESOURCE [0] and ROLE HINT [1] $tmpResource = $details[0]; if ($this->roleExists($details[1])) { $tmpRoleHint = array($rootRole['id']); foreach ($this->getRoleTree($details[1], true) as $role) { array_unshift($tmpRoleHint, $role['id']); } } } else { $tmpResource = $details; } if (!preg_match(self::_REGEX_PATTERN, $tmpResource)) { trigger_error('Acl::buildForm() Resource name must only contain alphanumeric chars, underscore and hyphen (A-Z, a-z, 0-9, _, -), was given "' . $tmpResource . '"'); return false; } /** * If the role, check if the roles have access to it which will then * be used later on in the view to provided if the checkbox should be checked */ $roleAccess = array(); foreach ($roles as $role) { try { $role['access'] = (bool) $this->_input->post('acl_resources/' . $tmpResource . '/' . $role['name']); } catch (Input_KeyNoExist $e) { if ($this->resourceExists($tmpResource)) { $role['access'] = $this->check($tmpResource, $role['name'], false); } else { $role['access'] = in_array($role['id'], isset($tmpRoleHint) ? $tmpRoleHint : $roleHint); } } $role['short_name'] = zula_substr($role['name'], strlen($prefix)); $roleAccess[] = $role; } $resources[] = array('title' => is_int($name) ? $tmpResource : $name, 'name' => $tmpResource, 'roles' => $roleAccess); } if (Registry::has('theme')) { $this->_theme->addJsFile('general.js'); } // Construct the main view file $view = new View('acl_form.html'); $view->assign(array('resources' => $resources, 'roles' => $roleAccess)); return $view->getOutput(); }
/** * Loads the main configuration ini file and adds it to the registry. * The 'config' directory will be updated to have the provided profile * appended to it, e.g. './config' becomes './config/default' * * @param string $profile * @return object */ public function loadConfig($profile) { if (Registry::has('config') && Registry::has('config_ini')) { return Registry::get('config'); } $configDir = $this->getDir('config') . '/' . $profile; try { $configIni = new Config_ini(); $configIni->load($configDir . '/config.ini.php'); Registry::register('config_ini', $configIni); // Merge the ini configuration in to the main config library $config = new Config(); $config->load($configIni); Registry::register('config', $config); // Store the profile name and update the 'config' dir value $this->setDir('config', $configDir); $this->configProfile = $profile; $this->configPath = $configDir . '/config.ini.php'; return $config; } catch (Config_Ini_FileNoExist $e) { throw new Zula_Exception('Zula configuration file "' . $configDir . '/config.ini.php" does not exist or is not readable', 8); } }