コード例 #1
0
ファイル: fileretriever.php プロジェクト: educakanchay/educa
 /**
  * 
  * @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
ファイル: base.php プロジェクト: educakanchay/educa
 /**
  * Fetches HTML to be sent to browser
  * 
  * @return string
  */
 public function getHtml()
 {
     $sHtml = preg_replace($this->getHeadRegex(), strtr($this->sHeadHtml, array('\\' => '\\\\', '$' => '\\$')), $this->sHtml, 1);
     if (is_null($sHtml) || $sHtml == '') {
         throw new Exception(JchPlatformUtility::translate('Error occured while trying to get html'));
     }
     return $sHtml;
 }
コード例 #3
0
ファイル: http.php プロジェクト: educakanchay/educa
 /**
  * 
  * @param type $sPath
  * @param type $aPost
  * @return type
  * @throws Exception
  */
 public function request($sPath, $aPost = array())
 {
     if (!$this->oHttpAdapter) {
         throw new BadFunctionCallException(JchPlatformUtility::translate('No Http Adapter present'));
     }
     $oUri = JUri::getInstance($sPath);
     $oResponse = $this->oHttpAdapter->request('GET', $oUri, $aPost);
     $return = array('body' => $oResponse->body, 'code' => $oResponse->code);
     return $return;
 }
コード例 #4
0
ファイル: http.php プロジェクト: naka211/myloyal
 /**
  * 
  * @param type $sPath
  * @param type $aPost
  * @return type
  * @throws Exception
  */
 public function request($sPath, $aPost = null, $aHeaders = null, $sUserAgent = '')
 {
     if (!$this->oHttpAdapter) {
         throw new BadFunctionCallException(JchPlatformUtility::translate('No Http Adapter present'));
     }
     $oUri = JUri::getInstance($sPath);
     $method = !isset($aPost) ? 'GET' : 'POST';
     $oResponse = $this->oHttpAdapter->request($method, $oUri, $aPost, $aHeaders, 10, $sUserAgent);
     $return = array('body' => $oResponse->body, 'code' => $oResponse->code);
     return $return;
 }
コード例 #5
0
ファイル: jchoptimize.php プロジェクト: grlf/eyedock
 /**
  * Static method to initialize the plugin
  * 
  * @param type $params  Plugin parameters
  */
 public static function optimize($oParams, $sHtml)
 {
     if (version_compare(PHP_VERSION, '5.3.0', '<')) {
         throw new Exception(JchPlatformUtility::translate('PHP Version less than 5.3.0. Exiting plugin...'));
     }
     $pcre_version = preg_replace('#(^\\d++\\.\\d++).++$#', '$1', PCRE_VERSION);
     if (version_compare($pcre_version, '7.2', '<')) {
         throw new Exception(JchPlatformUtility::translate('PCRE Version less than 7.2. Exiting plugin...'));
     }
     $JchOptimize = new JchOptimize($oParams);
     return $JchOptimize->process($sHtml);
 }
コード例 #6
0
ファイル: html.php プロジェクト: fritzdenim/pangMoves
 public function getOriginalHtml()
 {
     JCH_DEBUG ? JchPlatformProfiler::mark('beforeGetHtml') : null;
     $url = home_url() . '/?jchbackend=1';
     try {
         $oFileRetriever = JchOptimizeFileRetriever::getInstance();
         $response = $oFileRetriever->getFileContents($url);
         if ($oFileRetriever->response_code != 200) {
             throw new Exception(JchPlatformUtility::translate('Failed fetching front end HTML with response code ' . $oFileRetriever->response_code));
         }
         JCH_DEBUG ? JchPlatformProfiler::mark('afterGetHtml') : null;
         return $response;
     } catch (Exception $e) {
         JchOptimizeLogger::log($url . ': ' . $e->getMessage(), $this->params);
         JCH_DEBUG ? JchPlatformProfiler::mark('afterGetHtml)') : null;
         throw new RunTimeException(_('Load or refresh the front-end site first then refresh this page ' . 'to populate the multi select exclude lists.'));
     }
 }
コード例 #7
0
ファイル: fileretriever.php プロジェクト: irovast/eyedock
 /**
  * 
  * @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(JchPlatformUtility::translate('No Http Adapter available'));
         }
         $this->response_code = 0;
         try {
             $response = $oHttpAdapter->request($sPath, $aPost, $aHeader);
             $this->response_code = $response['code'];
             if (!isset($response) || $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());
         } 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;
 }
コード例 #8
0
ファイル: loader.php プロジェクト: educakanchay/educa
/**
 * Autoloader for plugin classes
 * 
 * @param type $class
 * @return boolean
 */
function loadJchOptimizeClass($sClass)
{
    $class = $sClass;
    $prefix = substr($class, 0, 3);
    // If the class already exists do nothing.
    if (class_exists($class, false)) {
        return true;
    }
    if ($prefix !== 'Jch') {
        return false;
    } else {
        $class = str_replace($prefix, '', $class);
    }
    if (strpos($class, '\\') !== FALSE) {
        $filename = str_replace('Optimize\\', '', $class);
        $file = dirname(__FILE__) . '/libs/' . $filename . '.php';
    } elseif (strpos($class, 'Platform') === 0) {
        $filename = strtolower(str_replace('Platform', '', $class));
        $file = dirname(dirname(__FILE__)) . '/platform/' . $filename . '.php';
    } elseif (strpos($class, 'Interface') === 0) {
        $filename = strtolower(str_replace('Interface', '', $class));
        $file = dirname(__FILE__) . '/interfaces/' . $filename . '.php';
    } else {
        $filename = str_replace('Optimize', '', $class);
        $filename = strtolower($class == 'Optimize' ? 'jchoptimize' : $filename);
        $file = dirname(__FILE__) . '/' . $filename . '.php';
    }
    if (!file_exists($file)) {
        throw new Exception(sprintf(JchPlatformUtility::translate('File not found: %s'), $file));
    } else {
        include_once $file;
        if (!class_exists($sClass) && !interface_exists($sClass)) {
            throw new Exception(sprintf(JchPlatformUtility::translate('Class not found: %s'), $sClass));
        }
    }
}
コード例 #9
0
ファイル: combiner.php プロジェクト: sam-akopyan/hamradio
 /**
  * 
  * @param type $sContent
  * @param type $sUrl
  */
 protected function minifyContent($sContent, $sType, $aUrl)
 {
     if ($this->params->get($sType . '_minify', 0) && preg_match('#\\s++#', trim($sContent))) {
         $sUrl = $this->prepareFileUrl($aUrl, $sType);
         $sMinifiedContent = trim($sType == 'css' ? CSS_Optimize::optimize($sContent) : JS_Optimize::optimize($sContent));
         if (is_null($sMinifiedContent) || $sMinifiedContent == '') {
             JchOptimizeLogger::log(sprintf(JchPlatformUtility::translate('Error occurred trying to minify: %s'), $aUrl['url']), $this->params);
             $sMinifiedContent = $sContent;
         }
         return $sMinifiedContent;
     }
     return $sContent;
 }
コード例 #10
0
ファイル: helper.php プロジェクト: educakanchay/kanchay
 /**
  * If parameter is set will minify HTML before sending to browser; 
  * Inline CSS and JS will also be minified if respective parameters are set
  * 
  * @return string                       Optimized HTML
  * @throws Exception
  */
 public static function minifyHtml($sHtml, $oParams)
 {
     JCH_DEBUG ? JchPlatformProfiler::mark('beforeMinifyHtml plgSystem (JCH Optimize)') : null;
     $aOptions = array();
     if ($oParams->get('css_minify', 0)) {
         $aOptions['cssMinifier'] = array('JchOptimize\\CSS_Optimize', 'process');
     }
     if ($oParams->get('js_minify', 0)) {
         $aOptions['jsMinifier'] = array('JchOptimize\\JS_Optimize', 'minify');
     }
     $aOptions['minify_level'] = $oParams->get('html_minify_level', 2);
     if ($oParams->get('html_minify', 0)) {
         $sHtmlMin = HTML_Optimize::minify($sHtml, $aOptions);
         if ($sHtmlMin == '') {
             JchOptimizeLogger::log(JchPlatformUtility::translate('Error while minifying HTML'), $oParams);
             $sHtmlMin = $sHtml;
         }
         $sHtml = $sHtmlMin;
     }
     JCH_DEBUG ? JchPlatformProfiler::mark('afterMinifyHtml plgSystem (JCH Optimize)') : null;
     return $sHtml;
 }
コード例 #11
0
ファイル: admin.php プロジェクト: fritzdenim/pangMoves
 /**
  * 
  * @return type
  */
 public static function getUtilityIcons()
 {
     $aButtons = array();
     $aButtons[1]['link'] = JchPlatformPaths::adminController('browsercaching');
     $aButtons[1]['icon'] = 'fa-globe';
     $aButtons[1]['color'] = '#51A351';
     $aButtons[1]['text'] = JchPlatformUtility::translate('Leverage browser caching');
     $aButtons[1]['script'] = '';
     $aButtons[1]['class'] = 'enabled';
     $aButtons[1]['tooltip'] = JchPlatformUtility::translate('Use this button to add codes to your htaccess file to leverage browser caching.');
     $aButtons[3]['link'] = JchPlatformPaths::adminController('filepermissions');
     $aButtons[3]['icon'] = 'fa-file-text';
     $aButtons[3]['color'] = '#166BEC';
     $aButtons[3]['text'] = JchPlatformUtility::translate('Fix file permissions');
     $aButtons[3]['script'] = '';
     $aButtons[3]['class'] = 'enabled';
     $aButtons[3]['tooltip'] = JchPlatformUtility::translate('If your site has lost CSS formatting after enabling the plugin, the problem could be that the plugin files were installed with incorrect file permissions so the browser cannot access the cached combined file. Click here to correct the plugin\'s file permissions.');
     $aButtons[5]['link'] = JchPlatformPaths::adminController('cleancache');
     $aButtons[5]['icon'] = 'fa-times-circle';
     $aButtons[5]['color'] = '#C0110A';
     $aButtons[5]['text'] = JchPlatformUtility::translate('Clean Cache');
     $aButtons[5]['script'] = '';
     $aButtons[5]['class'] = 'enabled';
     $aButtons[5]['tooltip'] = JchPlatformUtility::translate('Click this button to clean the plugin\'s cache and page cache. If you have edited any CSS or javascript files you need to clean the cache so the changes can be visible.');
     return $aButtons;
 }
コード例 #12
0
ファイル: helper.php プロジェクト: proyectoseb/ShoppyStore
 /**
  * If parameter is set will minify HTML before sending to browser; 
  * Inline CSS and JS will also be minified if respective parameters are set
  * 
  * @return string                       Optimized HTML
  * @throws Exception
  */
 public static function minifyHtml($sHtml, $oParams)
 {
     JCH_DEBUG ? JchPlatformProfiler::start('MinifyHtml') : null;
     if ($oParams->get('html_minify', 0)) {
         $aOptions = array();
         if ($oParams->get('css_minify', 0)) {
             $aOptions['cssMinifier'] = array('JchOptimize\\CSS_Optimize', 'optimize');
         }
         if ($oParams->get('js_minify', 0)) {
             $aOptions['jsMinifier'] = array('JchOptimize\\JS_Optimize', 'optimize');
         }
         $aOptions['minify_level'] = $oParams->get('html_minify_level', 2);
         $sHtmlMin = HTML_Optimize::optimize($sHtml, $aOptions);
         if ($sHtmlMin == '') {
             JchOptimizeLogger::log(JchPlatformUtility::translate('Error while minifying HTML'), $oParams);
             $sHtmlMin = $sHtml;
         }
         $sHtml = $sHtmlMin;
         JCH_DEBUG ? JchPlatformProfiler::stop('MinifyHtml', TRUE) : null;
     }
     return $sHtml;
 }
コード例 #13
0
ファイル: cssparser.php プロジェクト: educakanchay/educa
 /**
  * Converts url of background images in css files to absolute path
  * 
  * @param string $sContent
  * @return string
  */
 public function correctUrl($sContent)
 {
     $sCorrectedContent = preg_replace_callback("#{$this->l}|{$this->b}|url\\(\\s*+\\K['\"]?((?(?<=['\"])[^'\"\\)]++|(?>(?:(?<=\\\\)[\\s)])?[^\\s)]*+)*?(?=(?<!\\\\)[\\s)])))['\"]?#i", array(__CLASS__, '_correctUrlCB'), $sContent);
     if (is_null($sCorrectedContent)) {
         throw new Exception(JchPlatformUtility::translate('Failed correcting urls of background images'));
     }
     $sContent = $sCorrectedContent;
     return $sContent;
 }
コード例 #14
0
ファイル: parser.php プロジェクト: sam-akopyan/hamradio
 /**
  * Get the search area to be used..head section or body
  * 
  * @param type $sHead   
  * @return type
  */
 public function getBodyHtml()
 {
     if ($this->sBodyHtml == '') {
         if (preg_match($this->getBodyRegex(), $this->sHtml, $aBodyMatches) === FALSE || empty($aBodyMatches)) {
             throw new Exception(JchPlatformUtility::translate('Error occurred while trying to match for search area.' . ' Check your template for open and closing body tags'));
         }
         $this->sBodyHtml = $aBodyMatches[0];
     }
     return $this->sBodyHtml;
 }
コード例 #15
0
ファイル: combiner.php プロジェクト: irovast/eyedock
 /**
  * Resolves @imports in css files, fetching contents of these files and adding them to the aggregated file
  * 
  * @param string $sContent      
  * @return string
  */
 protected function replaceImports($sContent)
 {
     if ($this->params->get('pro_replaceImports', '1')) {
         $oCssParser = $this->oCssParser;
         $u = $oCssParser->u;
         $sImportFileContents = preg_replace_callback("#(?>@?[^@'\"/]*+(?:{$u}|/|\\()?)*?\\K(?:@import url\\((?=[^\\)]+\\.(?:css|php))([^\\)]+)\\)([^;]*);|\\K\$)#", array(__CLASS__, 'getImportFileContents'), $sContent);
         if (is_null($sImportFileContents)) {
             JchOptimizeLogger::log(JchPlatformUtility::translate('Failed getting @import file contents'), $this->params);
             return $sContent;
         }
         $sContent = $sImportFileContents;
     } else {
         $sContent = parent::replaceImports($sContent);
     }
     return $sContent;
 }
コード例 #16
0
ファイル: linkbuilder.php プロジェクト: educakanchay/educa
 /**
  * Use generated id to cache aggregated file
  *
  * @param string $sType           css or js
  * @param string $sLink           Url for aggregated file
  */
 protected function processLink($sType, $sLink)
 {
     //JCH_DEBUG ? JchPlatformProfiler::mark('beforeProcessLink plgSystem (JCH Optimize)') : null;
     $aLinks = $this->oParser->getReplacedFiles();
     $sId = $this->getCacheId($aLinks[$sType], $sType);
     $aArgs = array($aLinks[$sType], $sType, $this->oParser);
     $oCombiner = new JchOptimizeCombiner($this->oParser);
     $aFunction = array(&$oCombiner, 'getContents');
     $bCached = $this->loadCache($aFunction, $aArgs, $sId);
     if ($bCached === FALSE) {
         throw new Exception(JchPlatformUtility::translate('Error creating cache file'));
     }
     $iTime = (int) $this->params->get('lifetime', '30');
     $sUrl = $this->buildUrl($sId, $sType, $iTime, $this->isGZ());
     if ($sType == 'css' && $this->params->get('pro_optimizeCssDelivery', '0')) {
         $sCriticalCss = '<style type="text/css">' . $this->sLnEnd . $bCached['criticalcss'] . $this->sLnEnd . '</style>' . $this->sLnEnd . '</head>';
         $sHeadHtml = str_replace('</head>', $sCriticalCss, $this->oParser->getHeadHtml());
         $this->oParser->setSearchArea($sHeadHtml, 'head');
         $sUrl = str_replace('JCHI', '0', $sUrl);
         $this->loadCssAsync($sUrl);
     } else {
         $sNewLink = str_replace('URL', $sUrl, $sLink);
         $this->replaceLink($sNewLink, $sType);
     }
     //JCH_DEBUG ? JchPlatformProfiler::mark('afterProcessLink plgSystem (JCH Optimize)') : null;
 }
コード例 #17
0
ファイル: combiner.php プロジェクト: educakanchay/educa
 /**
  * 
  * @param type $sContent
  * @param type $sUrl
  */
 protected function minifyContent($sContent, $sType, $aUrl)
 {
     if ($this->params->get($sType . '_minify', 0) && preg_match('#\\s++#', trim($sContent))) {
         $sUrl = isset($aUrl['url']) ? $aUrl['url'] : ($sType == 'css' ? 'Style' : 'Script') . ' Declaration';
         JCH_DEBUG ? JchPlatformProfiler::mark('beforeMinifyContent - "' . $sUrl . '" plgSystem (JCH Optimize)') : null;
         $sMinifiedContent = trim($sType == 'css' ? CSS_Optimize::process($sContent) : JS_Optimize::minify($sContent));
         if (is_null($sMinifiedContent) || $sMinifiedContent == '') {
             JchOptimizeLogger::log(sprintf(JchPlatformUtility::translate('Error occurred trying to minify: %s'), $aUrl['url']), $this->params);
             $sMinifiedContent = $sContent;
         }
         JCH_DEBUG ? JchPlatformProfiler::mark('afterMinifyContent - "' . $sUrl . '" plgSystem (JCH Optimize)') : null;
         return $sMinifiedContent;
     }
     return $sContent;
 }
コード例 #18
0
ファイル: parser.php プロジェクト: grlf/eyedock
 /**
  * 
  * @return type
  */
 public function lazyLoadImages()
 {
     if ($this->params->get('pro_lazyload', '0')) {
         JCH_DEBUG ? JchPlatformProfiler::start('LazyLoadImages') : null;
         $sLazyLoadBodyHtml = preg_replace($this->getLazyLoadRegex(), 'data-src="$1" src="' . JchOptimizeHelper::cookieLessDomain($this->params) . JchPlatformPaths::imageFolder() . 'placeholder.gif" data-jchll="true"', $this->getBodyHtml());
         if (is_null($sLazyLoadBodyHtml)) {
             JchOptimizeLogger::log(JchPlatformUtility::translate('Lazy load images function failed'), $this->params);
             return;
         }
         if (preg_match($this->getBodyRegex(), $sLazyLoadBodyHtml, $aBodyMatches) === FALSE || empty($aBodyMatches)) {
             JchOptimizeLogger::log(JchPlatformUtility::translate('Failed retrieving body in lazy load images function'), $this->params);
             return;
         }
         $this->sBodyHtml = $aBodyMatches[0];
         JCH_DEBUG ? JchPlatformProfiler::stop('LazyLoadImages', TRUE) : null;
     }
 }
コード例 #19
0
ファイル: parser.php プロジェクト: educakanchay/educa
 /**
  * 
  * @param type $sRegex
  * @param type $sType
  * @param type $sSection
  * @param type $aCBArgs
  * @throws Exception
  */
 protected function searchArea($sRegex, $sSection, $aCBArgs)
 {
     JCH_DEBUG ? JchPlatformProfiler::mark('beforeSearchArea - ' . $sSection . ' plgSystem (JCH Optimize)') : null;
     $obj = $this;
     $sProcessedHtml = preg_replace_callback($sRegex, function ($aMatches) use($obj, $aCBArgs, $sSection) {
         return $obj->replaceScripts($aMatches, $aCBArgs, $sSection);
     }, $this->{'s' . ucfirst($sSection) . 'Html'});
     JCH_DEBUG ? JchPlatformProfiler::mark('afterSearchArea - ' . $sSection . ' plgSystem (JCH Optimize)') : null;
     if (is_null($sProcessedHtml)) {
         throw new Exception(sprintf(JchPlatformUtility::translate('Error while parsing for links in %1$s' . ' ...turn off combine %1$s option'), $sSection));
     }
     $this->{'s' . ucfirst($sSection) . 'Html'} = $sProcessedHtml;
 }
コード例 #20
0
ファイル: linkbuilder.php プロジェクト: sam-akopyan/hamradio
 /**
  * Use generated id to cache aggregated file
  *
  * @param string $sType           css or js
  * @param string $sLink           Url for aggregated file
  */
 protected function getCombinedFiles($aLinks, $sId, $sType)
 {
     JCH_DEBUG ? JchPlatformProfiler::start('GetCombinedFiles - ' . $sType) : null;
     $aArgs = array($aLinks, $sType, $this->oParser);
     $oCombiner = new JchOptimizeCombiner($this->params);
     $aFunction = array(&$oCombiner, 'getContents');
     $bCached = $this->loadCache($aFunction, $aArgs, $sId);
     if ($bCached === FALSE) {
         throw new Exception(JchPlatformUtility::translate('Error creating cache file'));
     }
     JCH_DEBUG ? JchPlatformProfiler::stop('GetCombinedFiles - ' . $sType, TRUE) : null;
     return $bCached;
 }
コード例 #21
0
ファイル: linkbuilder.php プロジェクト: educakanchay/kanchay
 /**
  * Use generated id to cache aggregated file
  *
  * @param string $sType           css or js
  * @param string $sLink           Url for aggregated file
  */
 protected function combineFiles($aLinks, $sId, $sType)
 {
     //JCH_DEBUG ? JchPlatformProfiler::mark('beforeProcessLink plgSystem (JCH Optimize)') : null;
     $aArgs = array($aLinks, $sType, $this->oParser);
     $oCombiner = new JchOptimizeCombiner($this->params);
     $aFunction = array(&$oCombiner, 'getContents');
     $bCached = $this->loadCache($aFunction, $aArgs, $sId);
     if ($bCached === FALSE) {
         throw new Exception(JchPlatformUtility::translate('Error creating cache file'));
     }
     return $bCached;
     //JCH_DEBUG ? JchPlatformProfiler::mark('afterProcessLink plgSystem (JCH Optimize)') : null;
 }
コード例 #22
0
ファイル: parser.php プロジェクト: educakanchay/kanchay
 /**
  * Get the search area to be used..head section or body
  * 
  * @param type $sHead   
  * @return type
  */
 public function getBodyHtml()
 {
     //JCH_DEBUG ? JchPlatformProfiler::mark('beforeGetSearchArea plgSystem (JCH Optimize)') : null;
     if ($this->sBodyHtml == '') {
         if (preg_match($this->getBodyRegex(), $this->sHtml, $aBodyMatches) === FALSE || empty($aBodyMatches)) {
             throw new Exception(JchPlatformUtility::translate('Error occurred while trying to match for search area.' . ' Check your template for open and closing body tags'));
         }
         $this->sBodyHtml = $aBodyMatches[0];
     }
     //JCH_DEBUG ? JchPlatformProfiler::mark('afterGetSearchArea plgSystem (JCH Optimize)') : null;
     return $this->sBodyHtml;
 }
コード例 #23
0
ファイル: cssparser.php プロジェクト: sam-akopyan/hamradio
 /**
  * Converts url of background images in css files to absolute path
  * 
  * @param string $sContent
  * @return string
  */
 public function correctUrl($sContent, $aUrl)
 {
     $obj = $this;
     $sCorrectedContent = preg_replace_callback("#(?>[(]?[^('\\\\/\"]*+(?:{$this->e}|/)?)*?(?:(?<=url)\\(\\s*+\\K['\"]?((?<!['\"])[^\\s)]*+|(?<!')[^\"]*+|[^']*+)['\"]?|\\K\$)#i", function ($aMatches) use($aUrl, $obj) {
         return $obj->_correctUrlCB($aMatches, $aUrl);
     }, $sContent);
     if (is_null($sCorrectedContent)) {
         throw new Exception(JchPlatformUtility::translate('Failed correcting urls of background images'));
     }
     $sContent = $sCorrectedContent;
     return $sContent;
 }
コード例 #24
0
 /**
  * Uses regex to find css declarations containing background images to include in sprite
  * 
  * @param string $sCss  Aggregated css file
  * @return array        Array of css declarations and image urls to replace with sprite
  */
 public function processCssUrls($sCss, $bBackend = FALSE)
 {
     //JCH_DEBUG ? JchPlatformProfiler::mark('beforeProcessCssUrls plgSystem (JCH Optimize)') : null;
     $params = $this->params;
     $aRegexStart = array();
     $aRegexStart[0] = '
                     #(?:{
                             (?=\\s*+(?>[^}\\s:]++[:\\s]++)*?url\\(
                                     (?=[^)]+\\.(?:png|gif|jpe?g))
                             ([^)]+)\\))';
     $aRegexStart[1] = '
                     (?=\\s*+(?>[^}\\s:]++[:\\s]++)*?no-repeat)';
     $aRegexStart[2] = '
                     (?(?=\\s*(?>[^};]++[;\\s]++)*?background(?:-position)?\\s*+:\\s*+(?:[^;}\\s]++[^}\\S]++)*?
                             (?<p>(?:[tblrc](?:op|ottom|eft|ight|enter)|-?[0-9]+(?:%|[c-x]{2})?))(?:\\s+(?&p))?)
                                     (?=\\s*(?>[^};]++[;\\s]++)*?background(?:-position)?\\s*+:\\s*+(?>[^;}\\s]++[\\s]++)*?
                                             (?:left|top|0(?:%|[c-x]{2})?)\\s+(?:left|top|0(?:%|[c-x]{2})?)
                                     )
                     )';
     $sRegexMiddle = '   
                     [^{}]++} )';
     $sRegexEnd = '#isx';
     $aIncludeImages = JchOptimize::getArray($params->get('csg_include_images'));
     $aExcludeImages = JchOptimize::getArray($params->get('csg_exclude_images'));
     $sIncImagesRegex = '';
     if (!empty($aIncludeImages[0])) {
         foreach ($aIncludeImages as &$sImage) {
             $sImage = preg_quote($sImage, '#');
         }
         $sIncImagesRegex .= '
                             |(?:{
                                     (?=\\s*+(?>[^}\\s:]++[:\\s]++)*?url';
         $sIncImagesRegex .= ' (?=[^)]* [/(](?:' . implode('|', $aIncludeImages) . ')\\))';
         $sIncImagesRegex .= '\\(([^)]+)\\)
                                     )
                                     [^{}]++ })';
     }
     $sExImagesRegex = '';
     if (!empty($aExcludeImages[0])) {
         $sExImagesRegex .= '(?=\\s*+(?>[^}\\s:]++[:\\s]++)*?url\\(
                                                     [^)]++  (?<!';
         foreach ($aExcludeImages as &$sImage) {
             $sImage = preg_quote($sImage, '#');
         }
         $sExImagesRegex .= implode('|', $aExcludeImages) . ')\\)
                                                     )';
     }
     $sRegexStart = implode('', $aRegexStart);
     $sRegex = $sRegexStart . $sExImagesRegex . $sRegexMiddle . $sIncImagesRegex . $sRegexEnd;
     if (preg_match_all($sRegex, $sCss, $aMatches) === FALSE) {
         throw new Exception(JchPlatformUtility::translate('Error occurred matching for images to sprite'));
     }
     if (isset($aMatches[3])) {
         $total = count($aMatches[1]);
         for ($i = 0; $i < $total; $i++) {
             $aMatches[1][$i] = trim($aMatches[1][$i]) ? $aMatches[1][$i] : $aMatches[3][$i];
         }
     }
     if ($bBackend) {
         $aImages = array();
         $aImagesMatches = array();
         $aImgRegex = array();
         $aImgRegex[0] = $aRegexStart[0];
         $aImgRegex[2] = $aRegexStart[1];
         $aImgRegex[4] = $sRegexMiddle;
         $aImgRegex[5] = $sRegexEnd;
         $sImgRegex = implode('', $aImgRegex);
         if (preg_match_all($sImgRegex, $sCss, $aImagesMatches) === FALSE) {
             throw new Exception(JchPlatformUtility::translate('Error occurred matching for images to include'));
         }
         $aImagesMatches[0] = array_diff($aImagesMatches[0], $aMatches[0]);
         $aImagesMatches[1] = array_diff($aImagesMatches[1], $aMatches[1]);
         $oCssSpriteGen = new CssSpriteGen($this->getImageLibrary(), $this->params, $bBackend);
         $aImages['include'] = $oCssSpriteGen->CreateSprite($aImagesMatches[1]);
         $aImages['exclude'] = $oCssSpriteGen->CreateSprite($aMatches[1]);
         return $aImages;
     }
     //JCH_DEBUG ? JchPlatformProfiler::mark('afterProcessCssUrls plgSystem (JCH Optimize)') : null;
     return $aMatches;
 }
コード例 #25
0
ファイル: ajax.php プロジェクト: fritzdenim/pangMoves
 /**
  * 
  * @return string
  */
 public static function fileTree()
 {
     $root = rtrim(JchPlatformPaths::rootPath(), '/\\');
     $dir = urldecode(JchPlatformUtility::get('dir', '', 'string', 'post'));
     $view = urldecode(JchPlatformUtility::get('view', '', 'string', 'post'));
     $initial = urldecode(JchPlatformUtility::get('initial', '0', 'string', 'post'));
     $dir = JchPlatformUtility::decrypt($dir) . '/';
     if ($view != 'tree') {
         $header = '<div id="files-container-header"><ul class="jqueryFileTree"><li><span>&lt;root&gt;' . $dir . '</span></li>';
         $header .= '<li class="check-all"><span><input type="checkbox"></span><span><em>Check all</em></span>' . '<span><em>' . JchPlatformUtility::translate('Width') . ' (px)</em></span>' . '<span><em>' . JchPlatformUtility::translate('Height') . ' (px)</em></span></li></ul></div><div class="files-content">';
         $display = '';
     } else {
         $display = 'style="display: none;"';
         $header = '';
     }
     $response = '';
     if (file_exists($root . $dir)) {
         $files = scandir($root . $dir);
         //                        $files = JchPlatformUtility::lsFiles($root . $dir, '\.(?:gif|jpe?g|png)$', FALSE);
         natcasesort($files);
         if (count($files) > 2) {
             /* The 2 accounts for . and .. */
             $response .= '';
             $response = $header;
             if ($initial && $view == 'tree') {
                 $response .= '<div class="files-content"><ul class="jqueryFileTree">';
                 $response .= '<li class="directory expanded"><a href="#" rel="">&lt;root&gt;</a>';
             }
             $response .= '<ul class="jqueryFileTree" ' . $display . '>';
             foreach ($files as $file) {
                 if (file_exists($root . $dir . $file) && $file != '.' && $file != '..' && is_dir($root . $dir . $file)) {
                     $response .= '<li class="directory collapsed">' . self::item($file, $dir, $view, 'dir') . '</li>';
                 }
             }
             // All files
             if ($view != 'tree') {
                 foreach ($files as $file) {
                     if (file_exists($root . $dir . $file) && preg_match('#\\.(?:gif|jpe?g|png|GIF|JPE?G|PNG)$#', $file) && !is_dir($root . $dir . $file)) {
                         $ext = preg_replace('/^.*\\./', '', $file);
                         $response .= '<li class="file ext_' . strtolower($ext) . '">' . self::item($file, $dir, $view, 'file') . '</li>';
                     }
                 }
             }
             $response .= '</ul>';
             if ($initial && $view == 'tree') {
                 $response .= '</li></ul></div>';
             }
         }
     }
     return $response;
 }