/**
  * Get menu html
  * 
  * @param string $key Menu group key
  * @return string 
  */
 public function getMenu($key)
 {
     $menuHTML = '';
     $cacheSettings = Uni_Core_CacheManager::loadCacheSettings();
     $isCacheEnabled = isset($cacheSettings[Fox_Core_Model_Cache::CACHE_CODE_LAYOUT]) ? $cacheSettings[Fox_Core_Model_Cache::CACHE_CODE_LAYOUT] : FALSE;
     $package = Fox::getPreference(Uni_Controller_Action::MODE_ADMIN . '/package');
     $theme = Fox::getPreference(Uni_Controller_Action::MODE_ADMIN . '/theme');
     $cacheMenuBasePath = CACHE_DIR . DIRECTORY_SEPARATOR . Fox_Core_Model_Cache::CACHE_CODE_LAYOUT . DIRECTORY_SEPARATOR . Uni_Controller_Action::MODE_WEB . DIRECTORY_SEPARATOR . $package . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . self::CACHE_MENU_FOLDER;
     file_exists($cacheMenuBasePath) && is_dir($cacheMenuBasePath) || mkdir($cacheMenuBasePath, 0777, TRUE);
     $cacheMenuPath = $cacheMenuBasePath . DIRECTORY_SEPARATOR . $key . '.menu';
     if ($isCacheEnabled && file_exists($cacheMenuPath)) {
         $cacheMenuDoc = new DOMDocument();
         $cacheMenuDoc->loadHTMLFile($cacheMenuPath);
         $menuHTML = $cacheMenuDoc->saveXML();
         unset($cacheMenuDoc);
     } else {
         $menuGroupModel = Fox::getModel('navigation/menugroup');
         $menuGroupModel->load($key, 'key');
         if ($menuGroupModel->getId() && $menuGroupModel->getStatus() == Fox_Navigation_Model_Menugroup::STATUS_ENABLED) {
             $menuModel = Fox::getModel('navigation/menu');
             $menuList = $menuModel->getMenuItemsByGroup($key);
             $mnuDoc = new DOMDocument();
             $mnuDoc->formatOutput = true;
             $mnuRoot = NULL;
             if (count($menuList)) {
                 $mnuRoot = Uni_Data_XDOMDocument::createNode(self::ROOT_TAG, array('class' => 'menu_container'), $mnuDoc);
                 $mnuDoc->appendChild($mnuRoot);
                 foreach ($menuList as $menu) {
                     $node = Uni_Data_XDOMDocument::createNode(self::LEAF_TAG, array('class' => 'menu_nav' . ($menu['style_class'] ? ' ' . $menu['style_class'] : '')), $mnuDoc);
                     if (strpos($menu['link'], 'http://', 0) === 0 || strpos($menu['link'], 'https://', 0) === 0) {
                         $link = $menu['link'];
                     } else {
                         $link = Fox::getUrl($menu['link']);
                     }
                     $link = Uni_Data_XDOMDocument::createNode('a', array('href' => $link, 'target' => $menu['open_window'], 'class' => $menu['style_class']), $mnuDoc);
                     $link->appendChild($mnuDoc->createTextNode($menu['title']));
                     $node->appendChild($link);
                     $mnuRoot->appendChild($node);
                 }
             }
             if (isset($mnuDoc)) {
                 $menuHTML = $mnuDoc->saveXML($mnuRoot);
                 if ($isCacheEnabled) {
                     $mnuDoc->saveHTMLFile($cacheMenuPath);
                     @chmod($cacheMenuPath, 0777);
                 }
             }
             unset($mnuDoc);
         }
     }
     return $menuHTML;
 }
 /**
  * Load module settings data
  * 
  * @param boolean $forceCreate
  * @return array 
  */
 public static function loadPreferences($forceCreate = FALSE)
 {
     if (!$forceCreate && !empty(self::$preferences)) {
         self::$preferences;
     }
     $ds = DIRECTORY_SEPARATOR;
     $preferenceFilePath = CACHE_DIR . $ds . Fox_Core_Model_Cache::CACHE_CODE_PREFERENCE;
     $fileName = 'preference.xml';
     self::$preferences = array();
     $xDom = new Uni_Data_XDOMDocument();
     $cacheSettings = Uni_Core_CacheManager::loadCacheSettings();
     $isCacheEnabled = isset($cacheSettings[Fox_Core_Model_Cache::CACHE_CODE_PREFERENCE]) ? $cacheSettings[Fox_Core_Model_Cache::CACHE_CODE_PREFERENCE] : FALSE;
     if ($forceCreate || !$isCacheEnabled || !file_exists($preferenceFilePath . $ds . $fileName)) {
         if (!file_exists($preferenceFilePath)) {
             if (!@mkdir($preferenceFilePath, 0777, TRUE)) {
                 throw new Exception('"' . $preferenceFilePath . '" not found');
             }
         }
         $xDom->preserveWhiteSpace = false;
         $xDom->formatOutput = true;
         $preferenceModel = Fox::getModel('core/preference');
         $collection = $preferenceModel->getCollection();
         $root = $xDom->createElement('preferences');
         foreach ($collection as $preference) {
             self::$preferences[$preference['name']] = $preference['value'];
             $cData = $xDom->createCDATASection('');
             $cData->appendData($preference['value']);
             $entry = $xDom->createElement('entry');
             $entry->setAttribute('key', $preference['name']);
             $root->appendChild($entry);
             $entry->appendChild($cData);
         }
         $xDom->appendChild($root);
         $doc = $xDom->save($preferenceFilePath . $ds . $fileName);
         @chmod($preferenceFilePath, 0777);
     } else {
         $xDom->load($preferenceFilePath . $ds . $fileName);
         if ($xDom->documentElement->hasChildNodes()) {
             $nodeList = $xDom->documentElement->childNodes;
             foreach ($nodeList as $n) {
                 if ($n->nodeType == XML_ELEMENT_NODE && ($key = $n->getAttribute('key'))) {
                     self::$preferences[$key] = $n->nodeValue;
                 }
             }
         }
     }
     unset($xDom);
     return self::$preferences;
 }
 /**
  * Save action
  */
 function saveAction()
 {
     if ($this->getRequest()->isPost()) {
         try {
             $data = $this->getRequest()->getPost();
             //                Uni_Core_ModuleManager::runSqlUpgrade('News', 'Fox', 'core');
             //                exit;
             Uni_Core_ModuleManager::installModules();
             Uni_Core_ModuleManager::updateModuleStatus($data);
             Uni_Core_Preferences::loadPreferences(TRUE);
             Uni_Core_CacheManager::clearLayoutCache();
             Uni_Core_CacheManager::clearModuleCache();
             Fox::getHelper('core/message')->setInfo('Modules successfully saved.');
         } catch (Exception $e) {
             Fox::getHelper('core/message')->setError($e->getMessage());
         }
     }
     $this->sendRedirect('*/*/');
 }
 /**
  * Creates cache settings
  * @return void
  */
 public static function createCacheSettings()
 {
     self::$cacheArr = array();
     $cacheDoc = new Uni_Data_XDOMDocument();
     $cacheDoc->preserveWhiteSpace = FALSE;
     $cacheDoc->formatOutput = TRUE;
     $ds = DIRECTORY_SEPARATOR;
     $cacheSettingsPath = CACHE_DIR . $ds . 'cache.settings';
     $cacheModel = Fox::getModel('core/cache');
     $collection = $cacheModel->getCollection();
     $root = $cacheDoc->createElement('cache');
     foreach ($collection as $row) {
         self::$cacheArr[$row['cache_code']] = $row['status'];
         $cData = $cacheDoc->createCDATASection('');
         $cData->appendData($row['status']);
         $entry = $cacheDoc->createElement('entry');
         $entry->setAttribute('key', $row['cache_code']);
         $root->appendChild($entry);
         $entry->appendChild($cData);
     }
     $cacheDoc->appendChild($root);
     $cacheDoc->save($cacheSettingsPath);
 }
 /**
  * Clear cache
  */
 protected function clearCache()
 {
     Uni_Core_Preferences::loadPreferences(TRUE);
     Fox::initializePreferences();
     Uni_Core_CacheManager::clearLayoutCache();
 }
 /**
  * Bulk status update action
  */
 public function groupStatusAction()
 {
     try {
         $model = Fox::getModel('core/cache');
         $codes = $this->getGroupActionIds($model);
         $totalIds = count($codes);
         $updateType = '';
         $dependentParams = $this->getRequest()->getParam('dependents', array());
         if (isset($dependentParams['status'])) {
             if ($dependentParams['status'] == Fox_Core_Model_Cache::STATUS_CLEAR) {
                 $updateType = 'cleared';
                 if (in_array(Fox_Core_Model_Cache::CACHE_CODE_PREFERENCE, $codes)) {
                     Uni_Core_Preferences::loadPreferences(TRUE);
                     Fox::initializePreferences();
                 }
                 if (in_array(Fox_Core_Model_Cache::CACHE_CODE_LAYOUT, $codes)) {
                     Uni_Core_CacheManager::clearLayoutCache();
                 }
             } else {
                 if ($dependentParams['status'] == Fox_Core_Model_Cache::STATUS_ENABLED) {
                     $updateType = 'enabled';
                 } else {
                     if ($dependentParams['status'] == Fox_Core_Model_Cache::STATUS_DISABLED) {
                         $updateType = 'disabled';
                     }
                 }
                 $cacheCodes = '\'' . implode('\',\'', $codes) . '\'';
                 $model->update(array('status' => $dependentParams['status']), 'cache_code IN (' . $cacheCodes . ')');
             }
             Uni_Core_CacheManager::createCacheSettings();
             Fox::getHelper('core/message')->setInfo('Total ' . $totalIds . ' cache(s) successfully ' . $updateType . '.');
         }
     } catch (Exception $e) {
         Fox::getHelper('core/message')->setError($e->getMessage());
     }
     echo Zend_Json_Encoder::encode(array('redirect' => Fox::getUrl('*/*/')));
 }
 /**
  * Loades layout defined for particular action
  *
  * @param string $layoutUpdate
  * @param string $updateKey 
  * @return void
  */
 public function load($layoutUpdate = NULL, $updateKey = NULL)
 {
     $this->finalLayout = new Uni_Data_XDOMDocument();
     $this->finalLayout->preserveWhiteSpace = FALSE;
     $this->finalLayout->formatOutput = TRUE;
     $ds = DIRECTORY_SEPARATOR;
     $debug = FALSE;
     if (Uni_Core_Installer::isInstalled()) {
         $cacheSettings = Uni_Core_CacheManager::loadCacheSettings();
         $isCacheEnabled = isset($cacheSettings[Fox_Core_Model_Cache::CACHE_CODE_LAYOUT]) ? $cacheSettings[Fox_Core_Model_Cache::CACHE_CODE_LAYOUT] : FALSE;
         $cacheLayoutBasePath = CACHE_DIR . $ds . Fox_Core_Model_Cache::CACHE_CODE_LAYOUT . $ds . $this->mode . $ds . $this->package . $ds . $this->theme;
         file_exists($cacheLayoutBasePath) && is_dir($cacheLayoutBasePath) || @mkdir($cacheLayoutBasePath, 0777, TRUE);
         $cacheLayoutPath = $cacheLayoutBasePath . $ds . strtolower($this->module) . '_' . strtolower($this->controller) . '_' . strtolower($this->action) . (isset($updateKey) ? '_' . urlencode($updateKey) : '') . '.lxml';
     } else {
         $isCacheEnabled = FALSE;
     }
     if (!$isCacheEnabled || $isCacheEnabled && !file_exists($cacheLayoutPath)) {
         $debug || ob_start();
         $this->layout = new Uni_Core_Layout();
         $this->layout->init();
         $lPaths[] = 'application' . $ds . 'views' . $ds . $this->mode . $ds . $this->package . $ds . $this->theme . $ds . 'layout';
         $lPaths[] = 'application' . $ds . 'views' . $ds . $this->mode . $ds . $this->defaultPackage . $ds . $this->defaultTheme . $ds . 'layout';
         $loadLayout = FALSE;
         foreach ($lPaths as $lBPath) {
             if (file_exists($lBPath . $ds . 'fox.xml')) {
                 $lDPath = $lBPath . $ds . 'fox.xml';
                 break;
             }
         }
         if (isset($lDPath)) {
             $this->xDomFox = new Uni_Data_XDOMDocument();
             $this->xDomFox->load($lDPath);
         } else {
             throw new Exception('Layout not found "' . $lDPath . '"');
         }
         $this->layout->setLayout($this->xDomFox);
         /*             * **************Parsing default Section from all other layouts************** */
         $modules = array_keys(Uni_Fox::getModules());
         foreach ($modules as $module) {
             if ($module != $this->module) {
                 foreach ($lPaths as $lBPath) {
                     if (file_exists($lBPath . $ds . lcfirst($module) . '.xml')) {
                         $lPath = $lBPath . $ds . lcfirst($module) . '.xml';
                         break;
                     }
                 }
                 if (isset($lPath)) {
                     $mLXmlDoc = new Uni_Data_XDOMDocument();
                     $mLXmlDoc->load($lPath);
                     $xpMLXmlDoc = new DOMXPath($mLXmlDoc);
                     $defMLXml = $xpMLXmlDoc->query('/' . self::ROOT . '/global');
                     if ($defMLXml->length > 0) {
                         $this->layout->mergeLayout($defMLXml->item(0), TRUE);
                         $this->layout->showXML();
                     }
                     unset($lPath);
                 }
             }
         }
         foreach ($lPaths as $lBPath) {
             if (file_exists($lBPath . $ds . lcfirst($this->module) . '.xml')) {
                 $lPath = $lBPath . $ds . lcfirst($this->module) . '.xml';
                 break;
             }
         }
         if (isset($lPath)) {
             $this->xDomMain = new Uni_Data_XDOMDocument();
             $this->xDomMain->load($lPath);
         } else {
             throw new Exception('Layout not found "' . $lPath . '"');
         }
         $xpMain = new DOMXPath($this->xDomMain);
         $defGlobal = $xpMain->query('/' . self::ROOT . '/global');
         if ($defGlobal->length > 0) {
             $this->layout->mergeLayout($defGlobal->item(0), TRUE);
         }
         $defMain = $xpMain->query('/' . self::ROOT . '/default');
         if ($defMain->length > 0) {
             $this->layout->mergeLayout($defMain->item(0), TRUE);
         }
         $actMain = $xpMain->query('/' . self::ROOT . '/' . $this->controller . '_' . $this->action);
         if ($actMain->length > 0) {
             $this->layout->mergeLayout($actMain->item(0), TRUE);
         }
         if (isset($layoutUpdate) && isset($updateKey)) {
             $domUpdate = new Uni_Data_XDOMDocument();
             if (!$domUpdate->loadXML('<layout>' . $layoutUpdate . '</layout>')) {
             }
             $this->layout->mergeLayout($domUpdate->documentElement, TRUE);
         }
         $this->layout->prepareHead();
         $this->layout->showXML();
         $this->finalLayout->loadXML($this->layout->saveXML());
         if ($isCacheEnabled) {
             $this->finalLayout->save($cacheLayoutPath);
             @chmod($cacheLayoutPath, 0777);
         }
         unset($this->layout);
         $debug || ob_clean();
     } else {
         if (file_exists($cacheLayoutPath)) {
             $this->finalLayout->load($cacheLayoutPath);
         }
     }
     $this->parse($this->finalLayout);
 }