/** * Index action */ function indexAction() { $filepath = CACHE_DIR . '/analytics/report-' . Fox_Core_Model_Date::getCurrentDate('Y-m-d') . '.xml'; $xDom = new Uni_Data_XDOMDocument(); $xDom->load($filepath); header('Content-Type: text/xml'); echo $xDom->saveXML(); }
/** * 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; }
/** * Load cache settings * @return array */ public static function loadCacheSettings() { if (!empty(self::$cacheArr)) { return self::$cacheArr; } $cacheDoc = new Uni_Data_XDOMDocument(); $ds = DIRECTORY_SEPARATOR; $cacheSettingsPath = CACHE_DIR . $ds . 'cache.settings'; if (file_exists($cacheSettingsPath)) { $cacheDoc->load($cacheSettingsPath); if ($cacheDoc->documentElement->hasChildNodes()) { $nodeList = $cacheDoc->documentElement->childNodes; foreach ($nodeList as $n) { if ($n->nodeType == XML_ELEMENT_NODE && ($key = $n->getAttribute('key'))) { self::$cacheArr[$key] = $n->nodeValue; } } } } else { self::createCacheSettings(); } return self::$cacheArr; }
/** * Uninstall package * * @param string $key valid package key */ public function uninstallPackage($key) { $config = $this->getConfig(); if (!file_exists($config->getInstalledPkgPath() . DS . $key . '.xml')) { throw new Exception("Installation not found."); } $this->setStatus(Fox_Extensionmanager_Model_Package_Status::UNINSTALLING); $packageXml = $config->getInstalledPkgPath() . DS . $key . '.xml'; $document = new Uni_Data_XDOMDocument(); $document->load($packageXml); /*removing package files*/ $xpath = new DomXpath($document); foreach ($xpath->query('//item[@rel="file"]') as $file) { $filePath = Fox::getDirectoryPath() . $file->getAttribute("path"); if (file_exists($filePath) && !is_dir($filePath)) { try { @unlink($filePath); } catch (Exception $e) { } } } /*listing directories to remove*/ $dirs = array(); foreach ($xpath->query('//item[@rel="dir"]') as $file) { $dirPath = Fox::getDirectoryPath() . $file->getAttribute("path"); if (file_exists($dirPath) && is_dir($dirPath)) { try { $dirs[] = $dirPath; } catch (Exception $e) { } } } /*removing empty directories in $dir list*/ if ($dirs) { $dirs = array_reverse($dirs); foreach ($dirs as $dir) { @rmdir($dir); } } /*removing package from installed directory*/ @unlink($packageXml); $this->clearCache(); $this->setStatus(Fox_Extensionmanager_Model_Package_Status::UNINSTALLED); }
/** * 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); }
/** * 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); } } } } } } }