public function init() { parent::init(); if (!Tools_Security_Acl::isAllowed(Tools_Security_Acl::RESOURCE_CONFIG)) { $this->redirect($this->_helper->website->getUrl(), array('exit' => true)); } $this->view->websiteUrl = $this->_helper->website->getUrl(); $this->_websiteConfig = Zend_Registry::get('website'); $this->view->helpSection = 'config'; $this->_translator = Zend_Registry::get('Zend_Translate'); $this->_configMapper = Application_Model_Mappers_ConfigMapper::getInstance(); }
protected function _initLocale() { $config = Application_Model_Mappers_ConfigMapper::getInstance()->getConfig(); $name = Zend_Locale::getLocaleToTerritory($config['language']); if ($name !== null) { $locale = new Zend_Locale($name); } else { $locale = new Zend_Locale(); } $locale->setCache(Zend_Registry::get('cache')); Zend_Registry::set('Zend_Locale', $locale); }
private function _applyTemplates($themeName, $remove = false) { $themePath = $this->_websiteHelper->getPath() . $this->_themesConfig['path'] . $themeName . DIRECTORY_SEPARATOR; $themeFiles = glob($themePath . '{,mobile/}*.html', GLOB_BRACE); if ($themeFiles !== false) { $themeFiles = array_map(function ($file) use($themePath) { return str_replace($themePath, '', $file); }, $themeFiles); } $themeConfig = false; $errors = array(); //check we are not missing any required template foreach ($this->_protectedTemplates as $template) { if (!in_array($template . '.html', $themeFiles)) { array_push($errors, $this->_translator->translate('Theme missing template: ') . $template); } } if (!empty($errors)) { $this->_error(join('<br />', $errors), self::REST_STATUS_BAD_REQUEST); } //trying to get theme.ini file with templates presets try { $themeConfig = parse_ini_string(Tools_Filesystem_Tools::getFile($themePath . '/' . Tools_Template_Tools::THEME_CONFIGURATION_FILE)); } catch (Exception $e) { $themeConfig = false; } $mapper = Application_Model_Mappers_TemplateMapper::getInstance(); $mapper->clearTemplates(); // this will remove all templates except system required. @see $_protectedTemplates $templateTypeTable = new Application_Model_DbTable_TemplateType(); foreach ($themeFiles as $templateFile) { $templateName = preg_replace(array('~' . DIRECTORY_SEPARATOR . '~', '~\\.html$~'), array('_', ''), $templateFile); $template = $mapper->find($templateName); if (!$template instanceof Application_Model_Models_Template) { $template = new Application_Model_Models_Template(); $template->setName($templateName); } // checking if we have template type in theme.ini or page meet mobile template naming convention if (is_array($themeConfig) && !empty($themeConfig) && array_key_exists($templateName, $themeConfig)) { $templateType = $themeConfig[$templateName]; } elseif (preg_match('~^mobile' . DIRECTORY_SEPARATOR . '~', $templateFile)) { $templateType = Application_Model_Models_Template::TYPE_MOBILE; } if (isset($templateType)) { // checking if we have this type in db or adding it $checkTypeExists = $templateTypeTable->find($templateType); if (!$checkTypeExists->count()) { $checkTypeExists = $templateTypeTable->createRow(array('id' => $templateType, 'title' => ucfirst(preg_replace('/^type/ui', '', $templateType)) . ' Template')); $checkTypeExists->save(); } unset($checkTypeExists); $template->setType($templateType); } // getting template content try { $template->setContent(Tools_Filesystem_Tools::getFile($themePath . DIRECTORY_SEPARATOR . $templateFile)); } catch (Exceptions_SeotoasterException $e) { array_push($errors, 'Can\'t read template file: ' . $templateName); } // saving template to db $mapper->save($template); unset($template, $templateName); } unset($templateTypeTable); //updating config table Application_Model_Mappers_ConfigMapper::getInstance()->save(array('currentTheme' => $themeName)); if (!empty($errors)) { $this->_error(join('<br />', $errors), self::REST_STATUS_BAD_REQUEST); } return true; }