/** * Dot_Acl constructor. * Make the proper initializations, set roles, resources and permisssions * using Zend_Acl * @access public * @return Dot_Acl */ public function __construct() { $router = Zend_Registry::get('router'); $value = Dot_Cache::load('acl_role'); if ($value != false) { $role = $value; } else { $role = new Zend_Config_Xml(CONFIGURATION_PATH . '/acl/role.xml'); Dot_Cache::save($role, 'acl_role'); } $this->requestModule = Zend_Registry::get('requestModule'); $this->requestController = Zend_Registry::get('requestController'); $this->requestControllerProcessed = Zend_Registry::get('requestControllerProcessed'); $this->requestAction = Zend_Registry::get('requestAction'); // instantiate Zend_Acl $this->acl = new Zend_Acl(); //get resource(controllers) only for the curent module $this->_resource = $router->controllers->{$this->requestModule}; //get permission only for current module $this->_permission = $role->permission->{$this->requestModule}; $this->_role = $role->type; $this->_addRoles(); $this->_addResources(); }
/** * Get the Browser Array from private var or fetch it from cache or XML * @access public * @return array */ public static function getOsArray() { if (!is_null(self::$_osList)) { return self::$_osList; } $registry = Zend_Registry::getInstance(); $cacheKey = 'os_xml'; $value = Dot_Cache::load($cacheKey); if (false != $value) { $os = $value; } else { $xml = new Zend_Config_Xml(CONFIGURATION_PATH . '/useragent/os.xml'); $os = $xml->type->toArray(); self::$_osList = $os; Dot_Cache::save($os, $cacheKey); } return $os; }
/** * Get the option variables from an xml file for the current dots * * Used recursively, first take default.xml values. This values are * overwritten by the xml of the current dots * * This method also stores the options in the cache, for faster access * * @param string $requestModule * @param string $requestController * @return Zend_Config */ public static function getOptionVariables($requestModule, $requestController) { $option = array(); // get the actual controller // fixes the any_inexistent_controller caching // eg: localhost/DotKernel/module/inexistent_controller/ $actualController = 'default'; if ($requestController == 'seo' || in_array($requestController, Dot_Route::getControllersForModule($requestModule))) { $actualController = $requestController; } $cacheKey = 'option_' . $requestModule . '_' . $actualController; $value = Dot_Cache::load($cacheKey); if ($value != false) { $option = $value; return $option; } else { if ('default' == $requestController) { $dirOption = CONFIGURATION_PATH . '/'; $fileOption = 'dots.xml'; } else { $dirOption = CONFIGURATION_PATH . '/dots/'; $fileOption = strtolower($requestController) . '.xml'; } $validFile = new Zend_Validate_File_Exists(); $validFile->setDirectory($dirOption); if ($validFile->isValid($fileOption)) { $xml = new Zend_Config_Xml($dirOption . $fileOption, 'dots'); $arrayOption = $xml->variable->toArray(); foreach ($arrayOption as $v) { if (in_array($v['option'], array('global', $requestModule))) { // first write global, then replace the values with the ones from $requestModule $option = array_replace_recursive($option, $v); } } } // overwritte the default options from dots.xml with the one of the current dots $option = new Zend_Config($option, true); if (Zend_Registry::isRegistered('option')) { $optionRegistered = Zend_Registry::get('option'); $optionRegistered->merge($option); $value = Dot_Cache::save($optionRegistered, $cacheKey); return $optionRegistered; } $value = Dot_Cache::save($option, $cacheKey); return $option; } }
/** * Display the specific menu that was declared in configs/menu.xml file * @access public * @return void */ public function setViewMenu() { $dotAuth = Dot_Auth::getInstance(); if ($dotAuth->hasIdentity('admin')) { // cached menu $value = Dot_Cache::load($this->requestModule . '_menu'); if ($value != false) { $menus = $value; } else { $menu_xml = new Zend_Config_Xml(CONFIGURATION_PATH . '/' . $this->requestModule . '/' . 'menu.xml', 'config'); $menus = $menu_xml->menu; // if we have only one menu, Zend_Config_Xml return a simple array, not an array with key 0(zero) if (is_null($menus->{0})) { $menus = new Zend_Config(array(0 => $menu_xml->menu)); } $menus = $menus->toArray(); // only cache menu if it's not empty if (count($menus) > 0) { Dot_Cache::save($menus, $this->requestModule . '_menu'); } } foreach ($menus as $menu) { // check wether the text following the ">" in the breadcrumb has been set $breadcrumbItem2Set = false; //don't display the menu if display is set to 0, or it doesn't have the ID of 1 if (0 == $menu['display']) { continue; } if (1 != $menu['id']) { continue; } $this->setFile('tpl_menu', 'blocks/menu.tpl'); $this->setFile('tpl_breadcrumbs', 'blocks/breadcrumbs.tpl'); $items = $menu['item']; // if we have only one menu, Zend_Config_Xml return a simple array, not an array with key 0(zero) if (!isset($items[0])) { $items = array(0 => $items); } $this->setBlock('tpl_menu', 'submenu_list', 'submenu_list_block'); $this->setBlock('tpl_menu', 'menu_list', 'menu_list_block'); foreach ($items as $menuItem) { $this->setVar('MENU_TITLE', $menuItem['title']); $this->setVar('MENU_LINK', $this->config->website->params->url . '/' . $this->requestModule . '/' . $menuItem['link']); $this->setVar('MENU_DESCRIPTION', $menuItem['description']); if (false !== stripos($menuItem['link'], $this->requestController . '/')) { //if current menu is the current viewed page $this->setVar('MENU_SELECTED', ' class="selected"'); $this->setVar('BREADCRUMB_TITLE_1', $menuItem['title']); $this->setVar('BREADCRUMB_LINK_1', $this->config->website->params->url . '/' . $this->requestModule . '/' . $menuItem['link']); $this->setVar('BREADCRUMB_DESCRIPTION_1', $menuItem['description']); } else { $this->setVar('MENU_SELECTED', ''); } $subItems = $menuItem['subItems']['subItem']; if (!isset($subItems[0])) { $subItems = array(0 => $subItems); } foreach ($subItems as $subMenuItem) { $this->setVar('SUBMENU_TITLE', $subMenuItem['title']); $this->setVar('SUBMENU_LINK', $this->config->website->params->url . '/' . $this->requestModule . '/' . $subMenuItem['link']); $this->setVar('SUBMENU_DESCRIPTION', $subMenuItem['description']); if (false !== stripos($subMenuItem['link'], $this->requestController . '/' . $this->requestAction . '/')) { //if current submenu is the current viewed page $this->setVar('SUBMENU_SELECTED', ' class="selected"'); $this->setVar('BREADCRUMB_TITLE_2', $subMenuItem['title']); $this->setVar('BREADCRUMB_LINK_2', $this->config->website->params->url . '/' . $this->requestModule . '/' . $subMenuItem['link']); $this->setVar('BREADCRUMB_DESCRIPTION_2', $subMenuItem['description']); $breadcrumbItem2Set = true; } else { $this->setVar('SUBMENU_SELECTED', ''); } $this->parse('submenu_list_block', 'submenu_list', true); } $this->parse('menu_list_block', 'menu_list', true); $this->parse('submenu_list_block', ''); } if (!$breadcrumbItem2Set) { // the second segment of the breadcrumb hasn't been set // this means that the action that is requested doesn't exist in menu.xml // in that case use the action name as the text (replace dashes with spaces and use ucwords) $this->setVar('BREADCRUMB_TITLE_2', ucwords(str_replace('-', ' ', $this->requestAction))); $this->setVar('BREADCRUMB_LINK_2', ""); } } } $this->parse('MENU', 'tpl_menu'); $this->parse('BREADCRUMBS', 'tpl_breadcrumbs'); }
/** * Load Plugin Configuration from Cache * * Was Part of main initialize method * Returns Plugin Configuration from Cache * If cache is not available, it will be loaded from file * * @access private * @static * @return Zend_Config_Xml */ private static function _loadPluginConfiguration() { $pluginConfig = Dot_Cache::load('plugin_configuration'); if ($pluginConfig != false) { // no time to waste return $pluginConfig; } // config needed $config = Zend_Registry::get('configuration'); $pluginConfig = new Zend_Config_Ini(CONFIGURATION_PATH . '/plugins.ini', APPLICATION_ENV); // only save the settings if plugin_config caching is enabled if ($config->cache->cache_plugin_config) { Dot_Cache::save($pluginConfig, 'plugin_configuration'); } return $pluginConfig; }