Beispiel #1
0
 protected function _load()
 {
     if (!file_exists($this->_themeFullPath . '/' . self::FILENAME) || $this->_refresh) {
         $concatContent = '';
         $cssFiles = $this->_sortCss(Tools_Filesystem_Tools::findFilesByExtension($this->_themeFullPath, self::FILES_EXTENSION, true));
         foreach ($cssFiles as $key => $cssFile) {
             if (in_array(basename($cssFile), $this->_excludeFiles)) {
                 continue;
             }
             $concatContent .= $this->_addCss($cssFile);
         }
         try {
             Tools_Filesystem_Tools::saveFile($this->_themeFullPath . '/' . self::FILENAME, $concatContent);
         } catch (Exceptions_SeotoasterException $ste) {
             return $ste->getMessage();
         }
     }
     return '<link href="' . $this->_toasterOptions['websiteUrl'] . $this->_themeFullPath . '/' . self::FILENAME . '" rel="stylesheet" type="text/css" media="screen" />';
 }
 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;
 }
Beispiel #3
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;
 }
 /**
  * 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 #5
0
 public static function sqlProfiler()
 {
     if (APPLICATION_ENV !== 'development' || !isset($_COOKIE['_profileSql'])) {
         exit;
     }
     $profiler = Zend_Db_Table_Abstract::getDefaultAdapter()->getProfiler();
     $totalTime = $profiler->getTotalElapsedSecs();
     $queryCount = $profiler->getTotalNumQueries();
     $pageUrl = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
     $htmlResult = '<pre id="seotoaster-profiler-out">';
     $htmlResult .= '<h1>' . $pageUrl . '</h1>' . PHP_EOL;
     $htmlResult .= '';
     $htmlResult .= '<table border="1"><thead><tr><th>QUERY</th><th>TIME (sec)</th></tr></thead><tbody>';
     foreach ($profiler->getQueryProfiles() as $query) {
         $htmlResult .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $query->getQuery(), number_format($query->getElapsedSecs(), 6));
     }
     $htmlResult .= '</tbody>';
     $htmlResult .= '<tfoot><tr><th>TOTAL ' . $queryCount . '</th><th>' . number_format($totalTime, 6) . '</th></tr></tfoot>';
     $htmlResult .= '</pre>';
     $pathToTmp = Zend_Controller_Action_HelperBroker::getExistingHelper('website')->getPath() . 'tmp/';
     $reportName = 'sqlprofile_' . '_pid-' . getmypid() . '_' . date('Ymd') . '.html';
     try {
         Tools_Filesystem_Tools::saveFile($pathToTmp . $reportName, $htmlResult);
     } catch (Exception $e) {
     }
     if (!Zend_Controller_Front::getInstance()->getRequest()->isXmlHttpRequest()) {
         echo '<a href="tmp/' . $reportName . '" target="_blank">view sql profile</a>';
     }
 }
Beispiel #6
0
 private function _createFile($content)
 {
     $filePath = $this->_folderСssPath . self::FILE_NAME_PREFIX . $this->_fileCode . '.css';
     try {
         Tools_Filesystem_Tools::saveFile($filePath, $content);
     } catch (Exceptions_SeotoasterException $ste) {
         return $ste->getMessage();
     }
     return str_replace(' ', '%20', $filePath);
 }