public function robotsAction()
 {
     $robotsForm = new Application_Form_Robots();
     if (!$this->getRequest()->isPost()) {
         $robotstxtContent = Tools_Filesystem_Tools::getFile('robots.txt');
         $robotsForm->setContent($robotstxtContent);
     } else {
         if ($robotsForm->isValid($this->getRequest()->getParams())) {
             $robotsData = $robotsForm->getValues();
             try {
                 Tools_Filesystem_Tools::saveFile('robots.txt', $robotsData['content']);
                 $this->_helper->response->success('Robots.txt updated.');
             } catch (Exception $e) {
                 $this->_helper->response->fail($e->getMessage());
             }
         }
     }
     $this->view->helpSection = 'robots';
     $this->view->form = $robotsForm;
 }
 private function _uploadTemplatepreview()
 {
     $miscConfig = Zend_Registry::get('misc');
     $currentTheme = $this->_helper->config->getConfig('currentTheme');
     $savePath = $this->_websiteConfig['path'] . $this->_themeConfig['path'] . $currentTheme . DIRECTORY_SEPARATOR . $this->_themeConfig['templatePreview'];
     $name = trim($this->getRequest()->getParam('templateName'));
     $fileMime = $this->_getMimeType();
     switch ($fileMime) {
         case 'image/png':
             $newName = $name . '.png';
             break;
         case 'image/jpg':
         case 'image/jpeg':
             $newName = $name . '.jpg';
             break;
         case 'image/gif':
             $newName = $name . '.gif';
             break;
         default:
             return false;
             break;
     }
     if (!$name || empty($name)) {
         return false;
     }
     $newImageFile = $savePath . $newName;
     //checking for existing images with same name ...
     if (!is_dir($savePath)) {
         if (!Tools_Filesystem_Tools::mkDir($savePath)) {
             return false;
         }
     }
     $existingImages = glob($savePath . $name . '.{png,jpeg,jpg,gif}', GLOB_BRACE);
     // ...and removing them
     foreach ($existingImages as $img) {
         Tools_Filesystem_Tools::deleteFile($img);
     }
     $this->_uploadHandler->addFilter('Rename', array('target' => $newImageFile, 'overwrite' => true));
     $result = $this->_uploadImages($savePath, false);
     if ($result['error'] == false) {
         Tools_Image_Tools::resize($newImageFile, $miscConfig['templatePreviewWidth'], true);
         $result['thumb'] = 'data:' . $fileMime . ';base64,' . base64_encode(Tools_Filesystem_Tools::getFile($newImageFile));
     }
     return $result;
 }
 /**
  * @param $fileNameWithPath
  * @param bool $needle
  * @return string
  */
 protected function _getFileContent($fileNameWithPath, $needle = false)
 {
     if ($needle) {
         return stristr(trim(Tools_Filesystem_Tools::getFile($fileNameWithPath)), $needle);
     } else {
         return trim(Tools_Filesystem_Tools::getFile($fileNameWithPath));
     }
 }
Beispiel #4
0
 public static function minifyJs($jsList)
 {
     $websiteHelper = Zend_Controller_Action_HelperBroker::getExistingHelper('website');
     $cacheHelper = Zend_Controller_Action_HelperBroker::getExistingHelper('cache');
     if (null === ($hashStack = $cacheHelper->load(strtolower(__CLASS__), ''))) {
         $hashStack = array();
     }
     $container = $jsList->getContainer();
     foreach ($container->getArrayCopy() as $js) {
         if (isset($js->attributes['src'])) {
             if (strpos($js->attributes['src'], $websiteHelper->getUrl()) === false) {
                 continue;
                 //ignore file if file from remote
             }
             if (isset($js->attributes['nominify']) || preg_match('/min\\.js$/', $js->attributes['src']) != false) {
                 continue;
                 //ignore file if special attribute given or src ends with 'min.js'
             }
             $path = str_replace($websiteHelper->getUrl(), '', $js->attributes['src']);
             if (!file_exists($websiteHelper->getPath() . $path)) {
                 continue;
             }
             $hash = sha1_file($websiteHelper->getPath() . $path);
             if (!isset($hashStack[$path]) || $hashStack[$path]['hash'] !== $hash) {
                 $hashStack[$path] = array('hash' => $hash, 'content' => JSMin::minify(Tools_Filesystem_Tools::getFile($websiteHelper->getPath() . $path)));
                 Tools_Filesystem_Tools::saveFile($websiteHelper->getPath() . $websiteHelper->getTmp() . $hash . '.min.js', $hashStack[$path]['content']);
             }
             $js->attributes['src'] = $websiteHelper->getUrl() . $websiteHelper->getTmp() . $hash . '.min.js?' . Tools_Filesystem_Tools::basename($path);
         } elseif (!empty($js->source)) {
             if (!isset($js->attributes['nominify'])) {
                 $js->source = JSMin::minify($js->source);
             }
         }
     }
     $cacheHelper->save(strtolower(__CLASS__), $hashStack, '', array(), Helpers_Action_Cache::CACHE_LONG);
     return $jsList;
 }
Beispiel #5
0
 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;
 }
 /**
  * Method return form for editing css files for current theme
  * and saves css file content
  */
 public function editcssAction()
 {
     $cssFiles = $this->_buildCssFileList();
     $defaultCss = $this->_websiteConfig['path'] . $this->_themeConfig['path'] . array_search(self::DEFAULT_CSS_NAME, current($cssFiles));
     $editcssForm = new Application_Form_Css();
     $editcssForm->getElement('cssname')->setMultiOptions($cssFiles);
     $editcssForm->getElement('cssname')->setValue(self::DEFAULT_CSS_NAME);
     //checking, if form was submited via POST then
     if ($this->getRequest()->isPost()) {
         $postParams = $this->getRequest()->getParams();
         if (isset($postParams['getcss']) && !empty($postParams['getcss'])) {
             $cssName = $postParams['getcss'];
             try {
                 $content = Tools_Filesystem_Tools::getFile($this->_websiteConfig['path'] . $this->_themeConfig['path'] . $cssName);
                 $this->_helper->response->response($content, false);
             } catch (Exceptions_SeotoasterException $e) {
                 $this->_helper->response->response($e->getMessage(), true);
             }
         } else {
             if (is_string($postParams['content']) && empty($postParams['content'])) {
                 $editcssForm->getElement('content')->setRequired(false);
             }
             if ($editcssForm->isValid($postParams)) {
                 $cssName = $postParams['cssname'];
                 try {
                     Tools_Filesystem_Tools::saveFile($this->_websiteConfig['path'] . $this->_themeConfig['path'] . $cssName, $postParams['content']);
                     $params = array('websiteUrl' => $this->_helper->website->getUrl(), 'themePath' => $this->_websiteConfig['path'] . $this->_themeConfig['path'], 'currentTheme' => $this->_helper->config->getConfig('currentTheme'));
                     $concatCss = Tools_Factory_WidgetFactory::createWidget('Concatcss', array('refresh' => true), $params);
                     $concatCss->render();
                     $this->_helper->response->response($this->_translator->translate('CSS saved'), false);
                 } catch (Exceptions_SeotoasterException $e) {
                     $this->_helper->response->response($e->getMessage(), true);
                 }
             }
         }
         $this->_helper->response->response($this->_translator->translate('Undefined error'), true);
     } else {
         try {
             $editcssForm->getElement('content')->setValue(Tools_Filesystem_Tools::getFile($defaultCss));
             $editcssForm->getElement('cssname')->setValue(array_search(self::DEFAULT_CSS_NAME, current($cssFiles)));
         } catch (Exceptions_SeotoasterException $e) {
             $this->view->errorMessage = $e->getMessage();
         }
     }
     $this->view->helpSection = 'editcss';
     $this->view->editcssForm = $editcssForm;
 }
Beispiel #7
0
 public static function getSystemVersion()
 {
     try {
         return Tools_Filesystem_Tools::getFile('version.txt');
     } catch (Exceptions_SeotoasterException $se) {
         if (self::debugMode()) {
             error_log($se->getMessage());
         }
     }
     return '';
 }
 public function deleteAction()
 {
     if ($this->getRequest()->isPost()) {
         $plugin = Tools_Plugins_Tools::findPluginByName($this->getRequest()->getParam('id'));
         $plugin->registerObserver(new Tools_Plugins_GarbageCollector(array('action' => Tools_System_GarbageCollector::CLEAN_ONDELETE)));
         $miscData = Zend_Registry::get('misc');
         $sqlFilePath = $this->_helper->website->getPath() . $miscData['pluginsPath'] . $plugin->getName() . '/system/' . Application_Model_Models_Plugin::UNINSTALL_FILE_NAME;
         if (file_exists($sqlFilePath)) {
             $sqlFileContent = Tools_Filesystem_Tools::getFile($sqlFilePath);
             if (strlen($sqlFileContent)) {
                 $queries = Tools_System_SqlSplitter::split($sqlFileContent);
             }
         }
         $delete = Tools_Filesystem_Tools::deleteDir($this->_helper->website->getPath() . 'plugins/' . $plugin->getName());
         if (!$delete) {
             $this->_helper->response->fail('Can\'t remove plugin\'s directory (not enough permissions). Plugin was uninstalled.');
             exit;
         }
         if (is_array($queries) && !empty($queries)) {
             $dbAdapter = Zend_Registry::get('dbAdapter');
             try {
                 array_walk($queries, function ($query, $key, $adapter) {
                     if (strlen(trim($query))) {
                         $adapter->query($query);
                     }
                 }, $dbAdapter);
                 Application_Model_Mappers_PluginMapper::getInstance()->delete($plugin);
             } catch (Exception $e) {
                 error_log($e->getMessage());
                 $this->_helper->response->fail($e->getMessage());
             }
         }
         $this->_helper->cache->clean(null, null, array('plugins'));
         $this->_helper->cache->clean('admin_addmenu', $this->_helper->session->getCurrentUser()->getRoleId());
         $this->_helper->response->success('Removed');
     }
 }