/**
  * Controller predispatch method
  *
  * Called before action method
  */
 public function preDispatch()
 {
     parent::preDispatch();
     if (!('installer' == strtolower($this->getRequest()->getModuleName()) && 'wizard' == strtolower($this->getRequest()->getControllerName()) && 'finish' == strtolower($this->getRequest()->getActionName())) && Uni_Core_Installer::isInstalled()) {
         $this->sendRedirect('');
     }
 }
 /**
  * Application startup method
  * 
  * @return void
  */
 public static function runApp()
 {
     try {
         $application = new Uni_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/system.xml');
         $bs = $application->bootstrap();
         $bs->run();
         if (!Uni_Core_Installer::isInstalled()) {
             throw new Exception('Application is not installed.', 9999);
         }
     } catch (Exception $e) {
         $systemConfigPath = CONFIG_DIR . DIRECTORY_SEPARATOR . 'system.xml';
         if ($e->getCode() == 9999 || !(file_exists($systemConfigPath) && is_readable($systemConfigPath))) {
             $urlParts = explode('/', $_SERVER['REQUEST_URI']);
             $urlPattern = '';
             if (count($urlParts) > 2) {
                 for ($i = 0; $i < count($urlParts); $i++) {
                     if ($urlParts[$i] == 'installer') {
                         $urlPattern = $urlParts[$i];
                         break;
                     }
                 }
             }
             if (!(strtolower($urlPattern) == 'installer')) {
                 self::runInstaller();
             } else {
                 self::$modeRun = FALSE;
                 Fox::setMode('installer');
                 $application = new Uni_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/system_default.xml');
                 try {
                     $application->bootstrap()->run();
                 } catch (Exception $e) {
                     if (Uni_Core_Installer::isInstalled()) {
                         echo $e->getMessage() . '<br/>';
                         echo $e->getTraceAsString();
                     }
                 }
             }
         } else {
             echo $e->getMessage();
         }
     }
 }
 /**
  * Finish setup action
  */
 public function finishAction()
 {
     if (Uni_Core_Installer::isInstalled()) {
         Fox::getModel('installer/session')->setCurrentStep(5);
         $this->loadLayout();
         $this->renderLayout();
         Fox::getModel('installer/session')->unsetAllData();
     } else {
         $this->sendRedirect('*/*');
     }
 }
 /**
  * Retrieve website base url
  * 
  * Automatically switches to secure url if enabled
  * 
  * @return string
  */
 public static function getSiteUrl()
 {
     if (self::$mode == Uni_Controller_Action::MODE_INSTALL && !Uni_Core_Installer::isInstalled()) {
         $front = Zend_Controller_Front::getInstance();
         return 'http://' . $_SERVER['HTTP_HOST'] . $front->getBaseUrl() . '/';
     } else {
         if (self::isSecureUrlEnabled()) {
             return self::getSiteSecureUrl();
         }
     }
     return self::getPreference('web/unsecure/base_url');
 }
 /**
  * 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);
 }