示例#1
0
 /**
  * 
  * @param type $sPath
  * @return type
  */
 public function getFileContents($sPath, $aPost = array(), $sOrigPath = '')
 {
     if (strpos($sPath, 'http') === 0 || !empty($aPost)) {
         if (!$this->oHttpAdapter->available()) {
             throw new Exception(JchPlatformUtility::translate('No Http Adapter available'));
         }
         try {
             $response = $this->oHttpAdapter->request($sPath, $aPost);
             if ($response === FALSE) {
                 throw new RuntimeException(sprintf(JchPlatformUtility::translate('Failed getting file contents from %s'), $sPath));
             }
         } catch (RuntimeException $ex) {
             JchOptimizelogger::log($sPath . ': ' . $ex->getMessage(), JchPlatformPlugin::getPluginParams());
             $response['code'] = 404;
         } catch (BadFunctionCallException $ex) {
             throw new Exception($ex->getMessage());
         }
         if ($response['code'] >= 400) {
             $sPath = $sOrigPath == '' ? $sPath : $sOrigPath;
             $sContents = $this->notFound($sPath);
         } else {
             $sContents = $response['body'];
         }
     } else {
         if (file_exists($sPath)) {
             $sContents = @file_get_contents($sPath);
         } elseif ($this->oHttpAdapter->available()) {
             $sUriPath = JchPlatformPaths::path2Url($sPath);
             $sContents = $this->getFileContents($sUriPath, array(), $sPath);
         } else {
             $sContents = $this->notFound($sPath);
         }
     }
     return $sContents;
 }
示例#2
0
文件: plugin.php 项目: grlf/eyedock
 /**
  * 
  * @param type $params
  */
 public static function saveSettings($params)
 {
     $oPlugin = JchPlatformPlugin::getPlugin();
     $oPlugin->params = $params->toArray();
     $oData = new JRegistry($oPlugin);
     $aData = $oData->toArray();
     $oController = new JControllerLegacy();
     $oController->addModelPath(JPATH_ADMINISTRATOR . '/components/com_plugins/models', 'PluginsModel');
     $oPluginModel = $oController->getModel('Plugin', 'PluginsModel');
     if ($oPluginModel->save($aData) === FALSE) {
         JchOptimizeLogger::log(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $oPluginModel->getError()), $params);
     }
 }
示例#3
0
 protected function getOptions()
 {
     $plugin = JchPlatformPlugin::getPlugin();
     $pluginParams = new JRegistry();
     $pluginParams->loadString($plugin->params);
     $pluginParams->set('sprite-path', JchPlatformPaths::spriteDir());
     $CssSpriteGenClass = 'JchOptimize\\CssSpriteGen';
     $CssSpriteGen = new $CssSpriteGenClass(JchOptimizeSpriteGenerator::getImageLibrary(), $pluginParams);
     $aSpriteFormats = $CssSpriteGen->GetSpriteFormats();
     $this->default = $aSpriteFormats[0];
     $options = array();
     foreach ($aSpriteFormats as $sSpriteFormat) {
         $option = JHtml::_('select.option', $sSpriteFormat, $sSpriteFormat, 'value', 'text');
         $options[] = $option;
     }
     reset($options);
     return $options;
 }
 /**
  * 
  * @param type $sPath
  * @return type
  */
 public function getFileContents($sPath, $aPost = null, $aHeader = null, $sOrigPath = '')
 {
     $oHttpAdapter = $this->getHttpAdapter();
     if (strpos($sPath, 'http') === 0) {
         if (!$oHttpAdapter->available()) {
             throw new Exception('No Http Adapter available');
         }
         $this->response_code = 0;
         try {
             $sUserAgent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
             $response = $oHttpAdapter->request($sPath, $aPost, $aHeader, $sUserAgent);
             $this->response_code = $response['code'];
             if (!isset($response) || $response === FALSE) {
                 throw new RuntimeException(sprintf('Failed getting file contents from %s', $sPath));
             }
         } catch (RuntimeException $ex) {
             JchOptimizelogger::log($sPath . ': ' . $ex->getMessage(), JchPlatformPlugin::getPluginParams());
         } catch (Exception $ex) {
             throw new Exception($sPath . ': ' . $ex->getMessage());
         }
         if ($this->response_code != 200 && !$this->allow_400) {
             $sPath = $sOrigPath == '' ? $sPath : $sOrigPath;
             $sContents = $this->notFound($sPath);
         } else {
             $sContents = $response['body'];
         }
     } else {
         if (file_exists($sPath)) {
             $sContents = @file_get_contents($sPath);
         } elseif ($oHttpAdapter->available()) {
             $sUriPath = JchPlatformPaths::path2Url($sPath);
             $sContents = $this->getFileContents($sUriPath, null, null, $sPath);
         } else {
             $sContents = $this->notFound($sPath);
         }
     }
     return $sContents;
 }
示例#5
0
 /**
  * 
  * @staticvar string $sContents
  * @return boolean
  */
 public static function checkModRewriteEnabled($params)
 {
     $oFileRetriever = JchOptimizeFileRetriever::getInstance();
     if (!$oFileRetriever->isHttpAdapterAvailable()) {
         $params->set('htaccess', '0');
     } else {
         $oUri = JchPlatformUri::getInstance();
         $sUrl = $oUri->toString(array('scheme', 'user', 'pass', 'host', 'port')) . JchPlatformPaths::assetPath() . JchPlatformPaths::rewriteBase() . 'test_mod_rewrite';
         $sContents = $oFileRetriever->getFileContents($sUrl);
         if ($sContents == 'TRUE') {
             $params->set('htaccess', '1');
         } else {
             $params->set('htaccess', '0');
         }
     }
     JchPlatformPlugin::saveSettings($params);
 }
 /**
  * 
  * @param JchPlatformSettings $params
  */
 public static function clearHiddenValues(JchPlatformSettings $params)
 {
     $params->set('hidden_containsgf', '');
     JchPlatformPlugin::saveSettings($params);
 }
示例#7
0
 /**
  * 
  * @staticvar string $sContents
  * @return boolean
  */
 public static function checkModRewriteEnabled($params)
 {
     JCH_DEBUG ? JchPlatformProfiler::start('CheckModRewriteEnabled') : null;
     $oFileRetriever = JchOptimizeFileRetriever::getInstance();
     if (!$oFileRetriever->isHttpAdapterAvailable()) {
         $params->set('htaccess', 0);
     } else {
         $oUri = JchPlatformUri::getInstance();
         $sUrl = $oUri->toString(array('scheme', 'user', 'pass', 'host', 'port')) . JchPlatformPaths::assetPath(TRUE);
         $sUrl2 = JchPlatformPaths::rewriteBase() . 'test_mod_rewrite';
         try {
             $sContents = $oFileRetriever->getFileContents($sUrl . $sUrl2);
             if ($sContents == 'TRUE') {
                 $params->set('htaccess', 1);
             } else {
                 $sContents2 = $oFileRetriever->getFileContents($sUrl . '3' . $sUrl2);
                 if ($sContents2 == 'TRUE') {
                     $params->set('htaccess', 3);
                 } else {
                     $params->set('htaccess', 0);
                 }
             }
         } catch (Exception $e) {
             $params->set('htaccess', 0);
         }
     }
     JchPlatformPlugin::saveSettings($params);
     JCH_DEBUG ? JchPlatformProfiler::stop('CheckModRewriteEnabled', TRUE) : null;
 }
 /**
  * 
  * @param type $type
  * @param type $parent
  */
 public function postflight($type, $parent)
 {
     require_once JPATH_ROOT . '/plugins/system/jch_optimize/jchoptimize/loader.php';
     require_once JPATH_ROOT . '/plugins/system/jch_optimize/fields/autoorder.php';
     if ($type == 'install') {
         JFormFieldAutoorder::fixFilePermissions(true);
     }
     if ($type == 'update') {
         JFormFieldAutoorder::cleanCache(true);
         $params = JchPlatformPlugin::getPluginParams();
         if (($exludeAllExtensions = $params->get('excludeAllExtensions', '')) !== '') {
             $params->set('includeAllExtensions', !$exludeAllExtensions);
             $params->set('excludeAllExtensions', '');
             JchPlatformPlugin::saveSettings($params);
         }
     }
     JFormFieldAutoorder::orderPlugins(true);
 }
示例#9
0
 /**
  * Fetches the contents of files declared with @import 
  * 
  * @param array $aMatches       Array of regex matches
  * @return string               file contents
  */
 protected function getImportFileContents($aMatches)
 {
     if (!isset($aMatches[1]) || $aMatches[1] == '' || preg_match('#^(?>\\(|/(?>/|\\*))#', $aMatches[0]) || $this->oParser->isHttpAdapterAvailable($aMatches[1]) || preg_match('#^https#', $aMatches[1]) && !extension_loaded('openssl') || preg_match('#://#', $aMatches[1]) && !preg_match('#^http#', $aMatches[1])) {
         return $aMatches[0];
     }
     if ($this->oParser->isDuplicated($aMatches[1])) {
         return '';
     }
     if (strpos($aMatches[1], 'fonts.googleapis.com') !== FALSE) {
         $containsgf = JchOptimizeHelper::getArray($this->params->get('hidden_containsgf', array()));
         if (!in_array($this->current_file, $containsgf)) {
             $containsgf[] = $this->current_file;
             $this->params->set('hidden_containsgf', implode(',', $containsgf));
             JchPlatformPlugin::saveSettings($this->params);
         }
     }
     $aUrlArray = array();
     $aUrlArray[0]['url'] = $aMatches[1];
     $aUrlArray[0]['media'] = $aMatches[2];
     //$aUrlArray[0]['id']    = md5($aUrlArray[0]['url'] . $this->oParser->sFileHash);
     $oCssParser = $this->oCssParser;
     $sFileContents = $this->combineFiles($aUrlArray, 'css', $oCssParser);
     if ($sFileContents === FALSE) {
         return $aMatches[0];
     }
     return $sFileContents;
 }