コード例 #1
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 T3 assets
  *
  * @return  null
  */
 function updateHead()
 {
     //state parameters
     $devmode = $this->getParam('devmode', 0);
     $themermode = $this->getParam('themermode', 1) && defined('T3_THEMER');
     $theme = $this->getParam('theme', '');
     $minify = $this->getParam('minify', 0);
     $minifyjs = $this->getParam('minify_js', 0);
     // detect RTL
     $doc = JFactory::getDocument();
     $dir = $doc->direction;
     $is_rtl = $dir == 'rtl';
     // As Joomla 3.0 bootstrap is buggy, we will not use it
     // We also prevent both Joomla bootstrap and T3 bootsrap are loaded
     // And upgrade jquery as our Framework require jquery 1.7+ if we are loading jquery from google
     $scripts = array();
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $t3bootstrap = false;
         $jabootstrap = false;
         foreach ($doc->_scripts as $url => $script) {
             if (strpos($url, T3_URL . '/bootstrap/js/bootstrap.js') !== false) {
                 $t3bootstrap = true;
                 if ($jabootstrap) {
                     //we already have the Joomla bootstrap and we also replace to T3 bootstrap
                     continue;
                 }
             }
             if (preg_match('@media/jui/js/bootstrap(.min)?.js@', $url)) {
                 if ($t3bootstrap) {
                     //we have T3 bootstrap, no need to add Joomla bootstrap
                     continue;
                 } else {
                     $scripts[T3_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[T3_URL . '/js/jquery-1.11.2' . ($devmode ? '' : '.min') . '.js'] = $script;
                     $replace = true;
                 }
             }
         }
         if (!$replace) {
             $scripts[$url] = $script;
         }
     }
     $doc->_scripts = $scripts;
     // end update javascript
     //Update css/less based on devmode and themermode
     $root = JURI::root(true);
     $current = JURI::current();
     // $regex       = '@' . preg_quote(T3_TEMPLATE_REL) . '/css/(rtl/)?(.*)\.css((\?|\#).*)?$@i';
     $regex = '@' . preg_quote(T3_TEMPLATE_REL) . '/(.*)\\.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[1];
             // remove rtl
             $fname = preg_replace('@(^|/)rtl/@mi', '\\1', $fname);
             // remove local
             $fname = preg_replace('@^local/@mi', '', $fname);
             // if (($devmode || $themermode) && is_file(T3_TEMPLATE_PATH . '/less/' . $fname . '.less')) {
             if ($devmode || $themermode) {
                 // less file
                 $lfname = preg_replace('@(^|/)css/@mi', '\\1less/', $fname);
                 if (is_file(T3_TEMPLATE_PATH . '/' . $lfname . '.less')) {
                     if ($themermode) {
                         $newurl = T3_TEMPLATE_URL . '/' . $lfname . '.less';
                         $css['mime'] = 'text/less';
                     } else {
                         T3::import('core/less');
                         $newurl = T3Less::buildCss(T3Path::cleanPath(T3_TEMPLATE_REL . '/' . $lfname . '.less'), true);
                     }
                     $stylesheets[$newurl] = $css;
                     continue;
                 }
             }
             $uri = null;
             // detect css available base on direction & theme
             if ($is_rtl && $theme) {
                 // rtl css file
                 $altfname = preg_replace('@(^|/)css/@mi', '\\1css/rtl/' . $theme . '/', $fname);
                 $uri = T3Path::getUrl($altfname . '.css');
             }
             if (!$uri && $is_rtl) {
                 $altfname = preg_replace('@(^|/)css/@mi', '\\1css/rtl/', $fname);
                 $uri = T3Path::getUrl($altfname . '.css');
             }
             if (!$uri && $theme) {
                 $altfname = preg_replace('@(^|/)css/@mi', '\\1css/themes/' . $theme . '/', $fname);
                 $uri = T3Path::getUrl($altfname . '.css');
             }
             if (!$uri) {
                 $uri = T3Path::getUrl($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)) {
         T3::import('core/minify');
         if ($minify) {
             T3Minify::optimizecss($this);
         }
         if ($minifyjs) {
             T3Minify::optimizejs($this);
         }
     }
 }
コード例 #2
0
ファイル: template.php プロジェクト: GitIPFire/Homeworks
 /**
  * Update head - detect if devmode or themermode is enabled and less file existed, use less file instead of css
  */
 function updateHead()
 {
     // As Joomla 3.0 bootstrap is buggy, we will not use it
     // We also prevent both Joomla bootstrap and T3 bootsrap are loaded
     $t3bootstrap = false;
     $jabootstrap = false;
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $doc = JFactory::getDocument();
         $scripts = array();
         foreach ($doc->_scripts as $url => $script) {
             if (strpos($url, T3_URL . '/bootstrap/js/bootstrap.js') !== false) {
                 $t3bootstrap = true;
                 if ($jabootstrap) {
                     //we already have the Joomla bootstrap and we also replace to T3 bootstrap
                     continue;
                 }
             }
             if (preg_match('@media/jui/js/bootstrap(.min)?.js@', $url)) {
                 if ($t3bootstrap) {
                     //we have T3 bootstrap, no need to add Joomla bootstrap
                     continue;
                 } else {
                     $scripts[T3_URL . '/bootstrap/js/bootstrap.js'] = $script;
                 }
                 $jabootstrap = true;
             } else {
                 $scripts[$url] = $script;
             }
         }
         $doc->_scripts = $scripts;
     }
     // end update javascript
     $devmode = $this->getParam('devmode', 0);
     $themermode = $this->getParam('themermode', 1) && defined('T3_THEMER');
     $theme = $this->getParam('theme', '');
     $minify = $this->getParam('minify', 0);
     // not in devmode and in default theme, do nothing
     if (!$devmode && !$themermode && !$theme && !$minify) {
         return;
     }
     $doc = JFactory::getDocument();
     $root = JURI::root(true);
     $regex = '#' . T3_TEMPLATE_URL . '/css/([^/]*)\\.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[1];
             if ($devmode || $themermode) {
                 if (is_file(T3_TEMPLATE_PATH . '/less/' . $fname . '.less')) {
                     if ($themermode) {
                         $newurl = T3_TEMPLATE_URL . '/less/' . $fname . '.less';
                         $css['mime'] = 'text/less';
                     } else {
                         $newurl = JURI::current() . '?t3action=lessc&amp;s=templates/' . T3_TEMPLATE . '/less/' . $fname . '.less';
                     }
                     $stylesheets[$newurl] = $css;
                     continue;
                 }
             } else {
                 if ($theme) {
                     if (is_file(T3_TEMPLATE_PATH . '/css/themes/' . $theme . '/' . $fname . '.css')) {
                         $newurl = T3_TEMPLATE_URL . '/css/themes/' . $theme . '/' . $fname . '.css';
                         $stylesheets[$newurl] = $css;
                         continue;
                     }
                 }
             }
         }
         $stylesheets[$url] = $css;
     }
     // update back
     $doc->_styleSheets = $stylesheets;
     //only check for minify if devmode is disabled
     if (!$devmode && $minify) {
         T3::import('core/minify');
         T3Minify::optimizecss($this);
     }
 }