public static function lesscall() { Plazart::import('core/less'); $result = array(); try { PlazartLess::compileAll(); $result['successful'] = JText::_('PLAZART_MSG_COMPILE_SUCCESS'); } catch (Exception $e) { $result['error'] = JText::sprintf('PLAZART_MSG_COMPILE_FAILURE', $e->getMessage()); } echo json_encode($result); }
public static function addStylesheet($lesspath) { // build less vars, once only static $vars_built = false; $plazartless = PlazartLess::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('PLAZART_THEMER')) { // in Themer mode, using js to parse less for faster $doc->addStylesheet(JURI::base(true) . '/' . PlazartPath::cleanPath($lesspath), 'text/less'); // Add lessjs to process lesscss $doc->addScript(PLAZART_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; // $doc->addStyleSheet(JURI::current().'?plazartaction=lessc&s='.PlazartPath::cleanPath($url)); // $cssurl = $plazartless->buildCss(PlazartPath::cleanPath($url)); $doc->addStyleSheet($cssurl); } } } else { // $doc->addStyleSheet(JURI::current().'?plazartaction=lessc&s='.PlazartPath::cleanPath($lesspath)); // $cssurl = $plazartless->buildCss(PlazartPath::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)) { // $doc->addStyleSheet(JURI::current().'?plazartaction=lessc&s='.PlazartPath::cleanPath($themepath)); $cssurl = $plazartless->buildCss(PlazartPath::cleanPath($themepath)); $doc->addStyleSheet($cssurl); } } } }