public static function addStylesheet($lesspath) { // build less vars, once only static $vars_built = false; $t3less = T3Less::getInstance(); if (!$vars_built) { self::buildVars(); $vars_built = true; } $app = JFactory::getApplication(); $tpl = $app->getTemplate(true); $theme = $tpl->params->get('theme'); $doc = JFactory::getDocument(); if (defined('T3_THEMER')) { // in Themer mode, using js to parse less for faster $doc->addStylesheet(JURI::base(true) . '/' . T3Path::cleanPath($lesspath), 'text/less'); // Add lessjs to process lesscss $doc->addScript(T3_URL . '/js/less-1.3.3.js'); } else { // in development mode, using php to compile less for a better view of development if (preg_match('#(template(-responsive)?.less)#', $lesspath)) { // Development mode is on, try to include less file inside folder less/ // get the less content $lessContent = JFile::read(JPATH_ROOT . '/' . $lesspath); $path = dirname($lesspath); // parse less content if (preg_match_all('#^\\s*@import\\s+"([^"]*)"#im', $lessContent, $matches)) { foreach ($matches[1] as $url) { if ($url == 'vars.less') { continue; } $url = $path . '/' . $url; $cssurl = $t3less->buildCss(T3Path::cleanPath($url)); $doc->addStyleSheet($cssurl); } } } else { $cssurl = $t3less->buildCss(T3Path::cleanPath($lesspath)); $doc->addStyleSheet($cssurl); } // check and add theme less if ($theme && !preg_match('#bootstrap#', $lesspath)) { $themepath = str_replace('/less/', '/less/themes/' . $theme . '/', $lesspath); if (is_file(JPATH_ROOT . '/' . $themepath)) { $cssurl = $t3less->buildCss(T3Path::cleanPath($themepath)); $doc->addStyleSheet($cssurl); } } } }