Ejemplo n.º 1
0
 public static function prepare($tpl)
 {
     //set the compress tool
     self::$exclude = $tpl->getParam('minify_exclude', '');
     self::$jstool = $tpl->getParam('minify_js_tool', 'jsmin');
     if (self::$exclude) {
         self::$exclude = '@' . preg_replace('@[,]+@', '|', preg_quote(self::$exclude)) . '@';
     }
 }
Ejemplo n.º 2
0
 /**
  * Update head - detect if devmode or themermode is enabled and less file existed, use less file instead of css
  * We also detect and update jQuery, Bootstrap to use CANVAS assets
  *
  * @return  null
  */
 function updateHead()
 {
     //state parameters
     $devmode = $this->getParam('devmode', 0);
     $themermode = $this->getParam('themermode', 1) && defined('CANVAS_THEMER');
     $theme = $this->getParam('theme', '');
     $minify = $this->getParam('minify', 0);
     $minifyjs = $this->getParam('minify_js', 0);
     // As Joomla 3.0 bootstrap is buggy, we will not use it
     // We also prevent both Joomla bootstrap and CANVAS bootsrap are loaded
     // And upgrade jquery as our Framework require jquery 1.7+ if we are loading jquery from google
     $doc = JFactory::getDocument();
     $scripts = array();
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $canvasbootstrap = false;
         $jabootstrap = false;
         foreach ($doc->_scripts as $url => $script) {
             if (strpos($url, CANVAS_URL . '/bootstrap/js/bootstrap.js') !== false) {
                 $canvasbootstrap = true;
                 if ($jabootstrap) {
                     //we already have the Joomla bootstrap and we also replace to CANVAS bootstrap
                     continue;
                 }
             }
             if (preg_match('@media/jui/js/bootstrap(.min)?.js@', $url)) {
                 if ($canvasbootstrap) {
                     //we have CANVAS bootstrap, no need to add Joomla bootstrap
                     continue;
                 } else {
                     $scripts[CANVAS_URL . '/bootstrap/js/bootstrap.js'] = $script;
                 }
                 $jabootstrap = true;
             } else {
                 $scripts[$url] = $script;
             }
         }
         $doc->_scripts = $scripts;
         $scripts = array();
     }
     // VIRTUE MART / JSHOPPING compatible
     foreach ($doc->_scripts as $url => $script) {
         $replace = false;
         if (strpos($url, '//ajax.googleapis.com/ajax/libs/jquery/') !== false && preg_match_all('@/jquery/(\\d+(\\.\\d+)*)?/@msU', $url, $jqver) || preg_match_all('@(^|\\/)jquery([-_]*(\\d+(\\.\\d+)+))?(\\.min)?\\.js@i', $url, $jqver)) {
             $idx = strpos($url, '//ajax.googleapis.com/ajax/libs/jquery/') !== false ? 1 : 3;
             if (is_array($jqver) && isset($jqver[$idx]) && isset($jqver[$idx][0])) {
                 $jqver = explode('.', $jqver[$idx][0]);
                 if (isset($jqver[0]) && (int) $jqver[0] <= 1 && isset($jqver[1]) && (int) $jqver[1] < 7) {
                     $scripts[CANVAS_URL . '/js/jquery-1.8.3' . ($devmode ? '' : '.min') . '.js'] = $script;
                     $replace = true;
                 }
             }
         }
         if (!$replace) {
             $scripts[$url] = $script;
         }
     }
     $doc->_scripts = $scripts;
     // end update javascript
     // detect RTL
     $dir = $doc->direction;
     $is_rtl = $dir == 'rtl';
     //Update css/less based on devmode and themermode
     $root = JURI::root(true);
     $current = JURI::current();
     $regex = '@' . preg_quote(CANVAS_TEMPLATE_REL) . '/css/(rtl/)?(.*)\\.css((\\?|\\#).*)?$@i';
     $stylesheets = array();
     foreach ($doc->_styleSheets as $url => $css) {
         // detect if this css in template css
         if (preg_match($regex, $url, $match)) {
             $fname = $match[2];
             if (($devmode || $themermode) && is_file(CANVAS_TEMPLATE_PATH . '/less/' . $fname . '.less')) {
                 if ($themermode) {
                     $newurl = CANVAS_TEMPLATE_URL . '/less/' . $fname . '.less';
                     $css['mime'] = 'text/less';
                 } else {
                     CANVAS::import('core/less');
                     $newurl = CANVASLess::buildCss(CANVASPath::cleanPath('templates/' . CANVAS_TEMPLATE . '/less/' . $fname . '.less'), true);
                 }
                 $stylesheets[$newurl] = $css;
             } else {
                 $uri = null;
                 // detect css available base on direction & theme
                 if ($is_rtl && $theme) {
                     $uri = CANVASPath::getUrl('css/rtl/themes' . $theme . '/' . $fname . '.css');
                 }
                 if (!$uri && $is_rtl) {
                     $uri = CANVASPath::getUrl('css/rtl/' . $fname . '.css');
                 }
                 if (!$uri && $theme) {
                     $uri = CANVASPath::getUrl('css/themes/' . $theme . '/' . $fname . '.css');
                 }
                 if (!$uri) {
                     $uri = CANVASPath::getUrl('css/' . $fname . '.css');
                 }
                 if ($uri) {
                     $stylesheets[$uri] = $css;
                 }
             }
             continue;
         }
         $stylesheets[$url] = $css;
     }
     // update back
     $doc->_styleSheets = $stylesheets;
     //only check for minify if devmode is disabled
     if (!$devmode && ($minify || $minifyjs)) {
         CANVAS::import('core/minify');
         if ($minify) {
             CANVASMinify::optimizecss($this);
         }
         if ($minifyjs) {
             CANVASMinify::optimizejs($this);
         }
     }
 }