/** * Entry point for the script * * @return void * * @since 3.0 */ public function doExecute() { $templates = array(JPATH_ADMINISTRATOR . '/templates/isis/less/template.less' => JPATH_ADMINISTRATOR . '/templates/isis/css/template.css', JPATH_ADMINISTRATOR . '/templates/isis/less/template-rtl.less' => JPATH_ADMINISTRATOR . '/templates/isis/css/template-rtl.css', JPATH_ADMINISTRATOR . '/templates/hathor/less/template.less' => JPATH_ADMINISTRATOR . '/templates/hathor/css/template.css', JPATH_ADMINISTRATOR . '/templates/hathor/less/colour_blue.less' => JPATH_ADMINISTRATOR . '/templates/hathor/css/colour_blue.css', JPATH_ADMINISTRATOR . '/templates/hathor/less/colour_brown.less' => JPATH_ADMINISTRATOR . '/templates/hathor/css/colour_brown.css', JPATH_ADMINISTRATOR . '/templates/hathor/less/colour_standard.less' => JPATH_ADMINISTRATOR . '/templates/hathor/css/colour_standard.css', JPATH_SITE . '/templates/protostar/less/template.less' => JPATH_SITE . '/templates/protostar/css/template.css', __DIR__ . '/less/bootstrap-extended.less' => JPATH_SITE . '/media/jui/css/bootstrap-extended.css', __DIR__ . '/less/bootstrap-rtl.less' => JPATH_SITE . '/media/jui/css/bootstrap-rtl.css'); // Load the RAD layer if (!defined('FOF_INCLUDED')) { require_once JPATH_LIBRARIES . '/fof/include.php'; } $less = new FOFLess(); $less->setFormatter(new FOFLessFormatterJoomla()); foreach ($templates as $source => $output) { try { $less->compileFile($source, $output); } catch (Exception $e) { echo $e->getMessage(); } } }
/** * Compile less using the less compiler under /build. * * @param string $input The relative location of the less file. * * @return boolean true if compilation is successful, false otherwise * * @since 3.2 */ public function compileLess($input) { if ($template = $this->getTemplate()) { $app = JFactory::getApplication(); $client = JApplicationHelper::getClientInfo($template->client_id); $path = JPath::clean($client->path . '/templates/' . $template->element . '/'); $inFile = urldecode(base64_decode($input)); $explodeArray = explode('/', $inFile); $fileName = end($explodeArray); $outFile = reset(explode('.', $fileName)); // Load the RAD layer to use its LESS compiler if (!defined('FOF_INCLUDED')) { require_once JPATH_LIBRARIES . '/fof/include.php'; } $less = new FOFLess(); $less->setFormatter(new FOFLessFormatterJoomla()); try { $less->compileFile($path . $inFile, $path . 'css/' . $outFile . '.css'); return true; } catch (Exception $e) { $app->enqueueMessage($e->getMessage(), 'error'); } } }
/** * Compile a LESS file into CSS and add it to the page generated by the CMS. * This method has integrated cache support. The compiled LESS files will be * written to the media/lib_fof/compiled directory of your site. If the file * cannot be written we will use the $altPath, if specified * * @param string $path A fancy path definition understood by parsePath pointing to the source LESS file * @param string $altPath A fancy path definition understood by parsePath pointing to a precompiled CSS file, used when we can't write the generated file to the output directory * @param boolean $returnPath Return the URL of the generated CSS file but do not include it. If it can't be generated, false is returned and the alt files are not included * * @return mixed True = successfully included generated CSS, False = the alternate CSS file was used, null = the source file does not exist * * @see FOFTemplateUtils::parsePath * * @since 2.0 */ public static function addLESS($path, $altPath = null, $returnPath = false) { // Does the cache directory exists and is writeable static $sanityCheck = null; // Get the local LESS file $localFile = self::parsePath($path, true); JLoader::import('joomla.filesystem.folder'); if (is_null($sanityCheck)) { // Make sure the cache directory exists if (!is_dir(JPATH_SITE . '/media/lib_fof/compiled/')) { $sanityCheck = JFolder::create(JPATH_SITE . '/media/lib_fof/compiled/'); } else { $sanityCheck = true; } } // No point continuing if the source file is not there or we can't write to the cache if (!$sanityCheck || !is_file($localFile)) { if (!$returnPath) { if (is_string($altPath)) { self::addCSS($altPath); } elseif (is_array($altPath)) { foreach ($altPath as $anAltPath) { self::addCSS($anAltPath); } } } return false; } // Get the source file's unique ID $id = md5(filemtime($localFile) . filectime($localFile) . $localFile); // Get the cached file path $cachedPath = JPATH_SITE . '/media/lib_fof/compiled/' . $id . '.css'; // Get the LESS compiler $lessCompiler = new FOFLess(); $lessCompiler->formatterName = 'compressed'; // Should I add an alternative import path? $altFiles = self::getAltPaths($path); if (isset($altFiles['alternate'])) { $currentLocation = realpath(dirname($localFile)); $normalLocation = realpath(dirname($altFiles['normal'])); $alternateLocation = realpath(dirname($altFiles['alternate'])); if ($currentLocation == $normalLocation) { $lessCompiler->importDir = array($alternateLocation, $currentLocation); } else { $lessCompiler->importDir = array($currentLocation, $normalLocation); } } // Compile the LESS file //$lessCompiler->compileFile($localFile, $cachedPath); $lessCompiler->checkedCompile($localFile, $cachedPath); // Add the compiled CSS to the page $base_url = rtrim(JUri::base(), '/'); if (substr($base_url, -14) == '/administrator') { $base_url = substr($base_url, 0, -14); } $url = $base_url . '/media/lib_fof/compiled/' . $id . '.css'; if ($returnPath) { return $url; } else { JFactory::getDocument()->addStyleSheet($url); return true; } }
/** * Compile a LESS file into CSS and add it to the page generated by the CMS. * This method has integrated cache support. The compiled LESS files will be * written to the media/lib_fof/compiled directory of your site. If the file * cannot be written we will use the $altPath, if specified * * @param string $path A fancy path definition understood by parsePath pointing to the source LESS file * @param string $altPath A fancy path definition understood by parsePath pointing to a precompiled CSS file, * used when we can't write the generated file to the output directory * @param boolean $returnPath Return the URL of the generated CSS file but do not include it. If it can't be * generated, false is returned and the alt files are not included * * @see FOFTemplateUtils::parsePath * * @since 2.0 * * @return mixed True = successfully included generated CSS, False = the alternate CSS file was used, null = the source file does not exist */ public static function addLESS($path, $altPath = null, $returnPath = false) { // Does the cache directory exists and is writeable static $sanityCheck = null; // Get the local LESS file $localFile = self::parsePath($path, true); $filesystem = FOFPlatform::getInstance()->getIntegrationObject('filesystem'); $platformDirs = FOFPlatform::getInstance()->getPlatformBaseDirs(); if (is_null($sanityCheck)) { // Make sure the cache directory exists if (!is_dir($platformDirs['public'] . '/media/lib_fof/compiled/')) { $sanityCheck = $filesystem->folderCreate($platformDirs['public'] . '/media/lib_fof/compiled/'); } else { $sanityCheck = true; } } // No point continuing if the source file is not there or we can't write to the cache if (!$sanityCheck || !is_file($localFile)) { if (!$returnPath) { if (is_string($altPath)) { self::addCSS($altPath); } elseif (is_array($altPath)) { foreach ($altPath as $anAltPath) { self::addCSS($anAltPath); } } } return false; } // Get the source file's unique ID $id = md5(filemtime($localFile) . filectime($localFile) . $localFile); // Get the cached file path $cachedPath = $platformDirs['public'] . '/media/lib_fof/compiled/' . $id . '.css'; // Get the LESS compiler $lessCompiler = new FOFLess(); $lessCompiler->formatterName = 'compressed'; // Should I add an alternative import path? $altFiles = self::getAltPaths($path); if (isset($altFiles['alternate'])) { $currentLocation = realpath(dirname($localFile)); $normalLocation = realpath(dirname($altFiles['normal'])); $alternateLocation = realpath(dirname($altFiles['alternate'])); if ($currentLocation == $normalLocation) { $lessCompiler->importDir = array($alternateLocation, $currentLocation); } else { $lessCompiler->importDir = array($currentLocation, $normalLocation); } } // Compile the LESS file $lessCompiler->checkedCompile($localFile, $cachedPath); // Add the compiled CSS to the page $base_url = rtrim(FOFPlatform::getInstance()->URIbase(), '/'); if (substr($base_url, -14) == '/administrator') { $base_url = substr($base_url, 0, -14); } $url = $base_url . '/media/lib_fof/compiled/' . $id . '.css'; if ($returnPath) { return $url; } else { $document = FOFPlatform::getInstance()->getDocument(); if ($document instanceof JDocument) { if (method_exists($document, 'addStyleSheet')) { $document->addStyleSheet($url); } } return true; } }
/** * Advance counter to next occurrence of $what * $until - don't include $what in advance * $allowNewline, if string, will be used as valid char set * * @param [type] $what [description] * @param [type] &$out [description] * @param boolean $until [description] * @param boolean $allowNewline [description] * * @return boolean */ protected function to($what, &$out, $until = false, $allowNewline = false) { if (is_string($allowNewline)) { $validChars = $allowNewline; } else { $validChars = $allowNewline ? "." : "[^\n]"; } if (!$this->match('(' . $validChars . '*?)' . FOFLess::preg_quote($what), $m, !$until)) { return false; } if ($until) { // Give back $what $this->count -= strlen($what); } $out = $m[1]; return true; }