/**
  * Loads setting data
  * 
  * @param string $item setting key
  */
 function loadSettingData($item)
 {
     $this->item = $item;
     $modules = Uni_Fox::getModules();
     $doc = new Uni_Data_XDOMDocument();
     if (is_array($modules)) {
         $this->finalMenuTree = new Uni_Data_XDOMDocument();
         $this->finalMenuTree->formatOutput = true;
         $this->root = Uni_Data_XDOMDocument::createNode('settings', NULL, $this->finalMenuTree);
         $this->finalMenuTree->appendChild($this->root);
         foreach ($modules as $module) {
             $filePath = $module['path'] . DIRECTORY_SEPARATOR . 'conf' . DIRECTORY_SEPARATOR . 'setting.xml';
             if (file_exists($filePath)) {
                 if ($doc->load($filePath)) {
                     $xPath = new DOMXPath($doc);
                     $setting = $xPath->query('/settings/setting|items');
                     if ($setting->length > 0) {
                         foreach ($setting as $menu) {
                             $this->getFinalMenuTree($menu);
                         }
                     }
                     $q = '/settings/items/item[@name="' . $item . '"]/sections';
                     $sections = $xPath->query($q);
                     if ($sections->length > 0) {
                         foreach ($sections as $section) {
                             $this->getFinalMenuTree($section);
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * 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;
 }
 /**
  * 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);
 }
 /**
  * Writes xml data to cache file
  *
  * @param array $dataArray
  */
 public function writeData($dataArray)
 {
     $filePath = $this->getReportsFilePath();
     $xDom = new Uni_Data_XDOMDocument();
     $xDom->preserveWhiteSpace = FALSE;
     $xDom->formatOutput = TRUE;
     $root = $xDom->createElement('root');
     foreach ($dataArray as $key => $value) {
         $info = $xDom->createElement('record');
         foreach ($value as $name => $values) {
             if ($name == 'value') {
                 $info->setAttribute('date', $values);
             } else {
                 $detail = $xDom->createElement($name, $values);
                 $info->appendChild($detail);
             }
         }
         $root->appendChild($info);
     }
     $xDom->appendChild($root);
     $xDom->save($filePath);
 }