/** * Load the Cache with the parameters found in application.ini * * Returns true if the cache can be used, false on fail * * @static * @access private * @return bool */ private static function _loadCache() { $configuration = Zend_Registry::get('configuration'); $lifetime = $configuration->cache->lifetime; // only disable automatic serialization if you know what you're doing $frontendOptions = array('lifetime' => $lifetime ? $lifetime : 0, 'caching' => $configuration->cache->enable, 'cache_id_prefix' => $configuration->cache->namespace . '_', 'automatic_serialization' => true); // making sure it's lowercase $backendName = strtolower($configuration->cache->factory); $backendOptions = array(); if (!self::_isExtensionLoaded($backendName)) { self::$_isLoaded = false; return false; } // if (null !== $configuration->cache->{$backendName}) { foreach ($configuration->cache->{$backendName} as $key => $value) { $backendOptions[$key] = $value; } } self::$_cache = Zend_Cache::factory('Core', $backendName, $frontendOptions, $backendOptions); self::$_isLoaded = true; return true; }
/** * 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 any warnings to display in the dashboard * Each array element returned is an array with two strings: type and description * @access public * @return array */ public function getWarnings() { // warning "categories" $warnings = array('Security Warning' => array(), 'Debug Email' => array(), 'Delete Files' => array(), 'Make Writable' => array(), 'Make Unwritable' => array(), 'Cache Test Failed' => array(), 'Plugin Check' => array()); // check that the default admin user isn't enabled $dotAuth = Dot_Auth::getInstance(); $defaultAdminValid = $dotAuth->process('admin', array("username" => "admin", "password" => "dot"), $storeInSession = false); if ($defaultAdminValid) { $warnings["Security Warning"][] = "Please change the password of the oldest admin user or deactivate him"; } // if the oldest admin have the same email team@dotkernel.com $select = $this->db->select()->from('admin', 'email')->where('isActive = ?', '1')->order('dateCreated asc')->limit(1); $emailAdmin = $this->db->fetchOne($select); if ('*****@*****.**' == $emailAdmin) { $warnings["Debug Email"][] = "Please change the email of the default admin user or deactivate him."; } //if the devEmails is the default one : team@dotkernel.com // why query db when we have it in the Dot_Model if (stripos($this->settings->devEmails, '*****@*****.**') !== false) { $warnings["Debug Email"][] = "Update the setting.devEmails value to reflect your debug email."; } // check for files that should be deleted $filesToDelete = array("dot_kernel.sql", "readme.txt", "dk.php"); foreach ($filesToDelete as $file) { if (file_exists(APPLICATION_PATH . "/" . $file)) { $warnings['Delete Files'][] = $file; } } //ignore permission warning if OS is Windows if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { // warning if application.ini is writable if (is_writable(APPLICATION_PATH . "/configs/application.ini")) { $warnings["Make Unwritable"][] = 'configs/application.ini'; } // only the folders set in application.ini (folders.permission[]) should be writable $folderException = $this->config->folders->permission->toArray(); // go through all folders in the tree $folders = $this->_listDirectory(APPLICATION_PATH); foreach ($folders as $path) { // exceptions are configured in application.ini. they should be writable $isException = false; foreach ($folderException as $exception) { if (strpos($path, $exception) !== false) { $isException = true; break; } } if ($isException) { if (!is_writable($path) && $path === $exception) { $warnings["Make Writable"][] = $path; } } else { if (is_writable($path)) { $warnings["Make Unwritable"][] = $path; } } } // info about how to add exception if (count($warnings["Make Unwritable"])) { $warnings["Make Unwritable"][] = '** <em>It is possible to add your writable folders to the exclude list by adding it as folders.permission[] exception in application.ini</em>'; } } if (Dot_Cache::testCache() == false) { $warnings['Cache Test Failed'][] = 'Cache is not working or disabled'; $warnings['Cache Test Failed'][] = 'Check cache settings or if cache module is supported'; $warnings['Cache Test Failed'][] = '' . 'More info: <a href="http://www.dotkernel.com/dotkernel/caching-in-dotkernel-using-zend-framework/"> Caching in DotKernel</a>'; } if (Dot_Cache::testTags() == false) { $warnings['Cache Test Failed'][] = 'Cache does not support tags'; $warnings['Cache Test Failed'][] = 'Check cache provider in application.ini'; $warnings['Cache Test Failed'][] = '' . 'More info: <a href="http://framework.zend.com/manual/1.12/en/zend.cache.backends.html"> ZF Cache Backends </a>'; } // plugin check $pluginHandler = Plugin_Loader::getInstance(); $pluginData = $pluginHandler->getAllPlugins(); foreach ($pluginData as $plugin) { // check if the class is missing if (!$pluginHandler->pluginExists($plugin['vendor'], $plugin['pluginName'])) { $warnings['Plugin Check'][] = 'Plugin ' . $plugin['pluginName'] . ' (by ' . $plugin['vendor'] . ') is missing'; } // check if the plugin is enabled if (!$plugin['enabled']) { $warnings['Plugin Check'][] = 'Plugin ' . $plugin['pluginName'] . ' (by ' . $plugin['vendor'] . ') is not enabled'; } } return $warnings; }
/** * 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'); }
/** * 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; } }
$systemView->showPHPInfo('phpinfo'); break; case 'apc-info': // display APC or APCu $apcu = null; if (phpversion('apcu')) { $apcu = 'u'; } $systemView->showAPCInfo($apcu); break; case 'delete-key': $result = array("success" => false, "message" => "An error occured, please try again."); if (!isset($_POST['key']) || !isset($_POST['userToken']) || !Dot_Auth::checkUserToken($_POST['userToken'])) { echo Zend_Json::encode($result); exit; } Dot_Cache::remove($_POST['key']); $result = array('succes' => 'true'); echo Zend_Json::encode($result); exit; case 'clear-cache': $result = array("success" => false, "message" => "An error occured, please try again."); if (!isset($_POST['userToken']) || !Dot_Auth::checkUserToken($_POST['userToken'])) { echo Zend_Json::encode($result); exit; } Dot_Cache::clean('all'); $result = array('succes' => 'true'); echo Zend_Json::encode($result); exit; }
/** * Initialize the global variables * @access public * @static * @param int $startTime * @return bool $success */ public static function initialize($startTime) { // Create registry object, as read-only object to store there config, settings, and database $registry = self::_initializeRegistry(); // mark the start time $registry->startTime = $startTime; //Load configuration settings from application.ini file and store it in registry $config = new Zend_Config_Ini(CONFIGURATION_PATH . '/application.ini', APPLICATION_ENV); $registry->configuration = $config; //start the cache Dot_Cache::loadCache(); //Load routes(modules, controllers, actions) settings from router.xml file and store it in registry $registry->router = self::_loadRouter(); // load the plugin configuration $registry->pluginConfiguration = self::_loadPluginConfiguration(); //Load configuration settings from application.ini file and store it in registry $config = new Zend_Config_Ini(CONFIGURATION_PATH . '/application.ini', APPLICATION_ENV); $registry->configuration = $config; // Create connection to database, as singleton , and store it in registry $db = Zend_Db::factory('Pdo_Mysql', $config->database->params->toArray()); $registry->database = $db; //Load specific configuration settings from database, and store it in registry $settings = Dot_Settings::getSettings(); $registry->settings = $settings; //Set PHP configuration settings from application.ini file Dot_Settings::setPhpSettings($config->phpSettings->toArray()); // Extract the route from the URI Dot_Route::setRoute(); // initialize seo options $registry->seo = Dot_Route::getOption(); // initialize default options for dots that may be overwritten $option = Dot_Settings::getOptionVariables($registry->requestModule, 'default'); $registry->option = $option; return true; }