Пример #1
0
 /**
  * Initializes Lessc and cleans less and css paths
  *
  * {@inheritdoc}
  */
 public function __construct(View $View, array $config = [])
 {
     parent::__construct($View, $config);
     // Initialize oyejorge/less.php parser
     require_once ROOT . DS . 'vendor' . DS . 'oyejorge' . DS . 'less.php' . DS . 'lib' . DS . 'Less' . DS . 'Autoloader.php';
     \Less_Autoloader::register();
     $this->css_path = WWW_ROOT . trim($this->css_path, '/');
 }
Пример #2
0
 /**
  * Execute this filter.
  *
  * @param FilterChain The filter chain.
  *
  * @return void
  *
  * @throws <b>FilterException</b> If an erro occurs during execution.
  */
 public function execute($filterChain)
 {
     static $loaded;
     if (!isset($loaded)) {
         // load the filter
         $start_time = microtime(true);
         $need_to_rebuild = true;
         $loaded = true;
         $css_file = $this->getParameter('css_file', null);
         $less_file = $this->getParameter('less_file', null);
         if (!is_null($css_file) && !is_null($less_file)) {
             if (file_exists($less_file)) {
                 if (file_exists($css_file)) {
                     if (filemtime($css_file) >= filemtime($less_file)) {
                         // css file is newer, so skip to the next filter
                         $filterChain->execute();
                         $need_to_rebuild = false;
                     }
                 }
                 if ($need_to_rebuild) {
                     if (file_exists(MO_WEBAPP_DIR . "/vendor/oyejorge/less.php/lib/Less/Autoloader.php")) {
                         \Mojavi\Logging\LoggerManager::error(__METHOD__ . " :: " . sprintf("Building new CSS file because date is %s and less file date is %s", filemtime($css_file), filemtime($less_file)));
                         try {
                             require_once MO_WEBAPP_DIR . "/vendor/oyejorge/less.php/lib/Less/Autoloader.php";
                             \Less_Autoloader::register();
                             $parser = new \Less_Parser(array('compress' => true));
                             $parser->parseFile($less_file, '/');
                             $css = $parser->getCss();
                             file_put_contents($css_file, $css);
                             \Mojavi\Logging\LoggerManager::error(__METHOD__ . " :: " . sprintf("Generated less file in %ss", number_format(microtime(true) - $start_time, 4)));
                         } catch (\Exception $e) {
                             \Mojavi\Logging\LoggerManager::error(__METHOD__ . " :: " . $e->getMessage());
                         }
                         // completed the caching, move on to the next filter
                         $filterChain->execute();
                     } else {
                         // we already loaded this filter, skip to the next filter
                         \Mojavi\Logging\LoggerManager::error(__METHOD__ . " :: " . "Missing Less vendor library, use composer require oyejorge/less.php");
                         $filterChain->execute();
                     }
                 }
             } else {
                 // less file doesn't exist so skip to the next filter
                 \Mojavi\Logging\LoggerManager::error(__METHOD__ . " :: " . "Cannot find less file to compile: " . $less_file);
                 $filterChain->execute();
             }
         } else {
             // less file or css file is not defined, so skip to the next filter
             \Mojavi\Logging\LoggerManager::error(__METHOD__ . " :: " . "less_file or css_file parameter is not defined");
             $filterChain->execute();
         }
     } else {
         // we already loaded this filter, skip to the next filter
         $filterChain->execute();
     }
 }
Пример #3
0
 /**
  *
  */
 function __construct()
 {
     parent::__construct();
     // ensure no one else has loaded lessc already ;)
     if (!class_exists('Less_Cache')) {
         require_once ExtensionManagementUtility::extPath('dyncss_less') . 'Resources/Private/Php/less.php/Autoloader.php';
         \Less_Autoloader::register();
     }
     $this->parser = NULL;
 }
Пример #4
0
 /**
  * Init Less.php library
  * @throws \Exception
  */
 public static function init()
 {
     static $done = false;
     if ($done) {
         return;
     }
     include __DIR__ . '/Less/src/Autoloader.php';
     \Less_Autoloader::register();
     $done = true;
 }
Пример #5
0
 function setUp()
 {
     echo "\nSet-Up: " . get_class($this);
     $root_directory = dirname(dirname(dirname(__FILE__)));
     require_once $root_directory . '/lib/Less/Autoloader.php';
     Less_Autoloader::register();
     $this->fixtures_dir = $root_directory . '/test/Fixtures';
     echo "\n  fixtures_dir: " . $this->fixtures_dir;
     $this->cache_dir = $root_directory . '/test/phpunit/_cache/';
     $this->CheckCacheDirectory();
     echo "\n\n";
 }
Пример #6
0
 protected function load()
 {
     if (!class_exists('Less_Parser')) {
         $path = !empty(WS::env()->config->less->lessphp_dir) ? WS::env()->config->less->lessphp_dir : self::option('less_php_dir');
         if (!is_file($path)) {
             throw new RuntimeException("Install LessPHP:\ncomposer \"oyejorge/less.php\": \"dev-master\" or copy lib (https://github.com/oyejorge/less.php) to {$path}");
         }
         require_once $path . '/lib/Less/Autoloader.php';
         Less_Autoloader::register();
     }
     IO_FS::mkdir($this->output);
 }
Пример #7
0
<?php

/**
 *
 * This file provides the part of lessphp API (https://github.com/leafo/lessphp)
 * to be a drop-in replacement for following products:
 *  - Drupal 7, by the less module v3.0+ (https://drupal.org/project/less)
 *  - Symfony 2
 *
 */
// Register autoloader for non-composer installations
if (!class_exists('Less_Parser')) {
    require_once dirname(__FILE__) . '/lib/Less/Autoloader.php';
    Less_Autoloader::register();
}
class lessc
{
    public static $VERSION = Less_Version::less_version;
    public $importDir = '';
    protected $allParsedFiles = array();
    protected $libFunctions = array();
    protected $registeredVars = array();
    private $formatterName;
    public function __construct($lessc = null, $sourceName = null)
    {
    }
    public function setImportDir($dirs)
    {
        $this->importDir = (array) $dirs;
    }
    public function addImportDir($dir)
Пример #8
0
 protected function loadLessLibrary()
 {
     require_once $this->oFeatureOptions->getPathToInc('Less.php/Autoloader.php');
     Less_Autoloader::register();
 }
Пример #9
0
 /**
  * Write a compiled LESS file to disk
  * @param  [type] $inFileInfo  [description]
  * @param  [type] $outFileInfo [description]
  * @return [type]              [description]
  */
 private function _compileLessFile($inFileInfo, $outFileInfo = null)
 {
     // Input File
     $inFile = null;
     $inPath = null;
     if (isset($inFileInfo['path'])) {
         $inPath = $inFileInfo['path'];
         $inFile = $inFileInfo['file'];
     } else {
         $inFile = (string) $inFileInfo;
     }
     $inFullPath = ($inPath ? $inPath : '') . $inFile;
     // Output File
     $outFile = null;
     $outPath = null;
     if (isset($outFileInfo['path'])) {
         $outPath = $outFileInfo['path'];
         $outFile = $outFileInfo['file'];
     } else {
         if (!is_null($outFileInfo)) {
             $outFile = (string) $outFileInfo;
         }
     }
     if (is_null($outFile)) {
         $outFullPath = ($outPath ? $outPath : '') . preg_replace('/\\.less$/', '', $inFile) . '.css';
     } else {
         $outFullPath = ($outPath ? $outPath : '') . $outFile;
     }
     // Verify File
     if (!is_readable($inFullPath)) {
         throw new Exception('failed to find file ' . $inFullPath);
     }
     // Load Parser
     if (empty($this->_lessParser)) {
         if (!class_exists('Less_Parser')) {
             require_once __DIR__ . '/../lessc/lib/Less/Autoloader.php';
             \Less_Autoloader::register();
         }
         $this->_lessEnvironment = new \Less_Environment();
         $this->_lessParser = new \Less_Parser($this->_lessEnvironment);
     }
     // Parse & Store
     $lessParser = $this->_lessParser;
     if (isset($lessParser)) {
         // Prepare callback for symlink correction
         $importDirs = array();
         if (realpath($inPath) != $inPath && realpath($inPath) . DIRECTORY_SEPARATOR != $inPath) {
             $importDirs[$inPath] = create_function('$fname', 'return array(Less_Environment::normalizePath(\'' . $inPath . '\'.$fname), null);');
         }
         // Reset Parser
         $lessParser->Reset(array('import_dirs' => $importDirs, 'compress' => $this->params->get('compress', false)));
         // Parse & Write Output
         try {
             $lessParser->parseFile($inFullPath);
         } catch (Exception $e) {
             die($e->getMessage());
         }
         file_put_contents($outFullPath, $lessParser->getCss());
     } else {
         throw new Exception('failed to load parser');
     }
 }
Пример #10
0
 /**
  * Method that compiles LESS to CSS file
  * @param (string) Path to LESS file
  * @param (bool) If true additional LESS variables from "jm_bootstrap_variables" parameter will be added
  * @param (bool) Indicates if we are dealing with a file that belongs to template's core. 
  *         If yes, it means that we should add suffix for CSS file because different template styles may use
  *         different variables
  * @param (bool) When true old version of LessC will be used. Otherwise Less_Parser class. 
  */
 protected function lessToCss($lessPath, $useVars = true, $coreStyle = true, $legacyCompiler = false)
 {
     if (class_exists('lessc') == false && $legacyCompiler) {
         require_once JMF_FRAMEWORK_PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'lessc' . DIRECTORY_SEPARATOR . 'lessc.inc.0.4.0.php';
     }
     if (class_exists('Less_Parser') == false && !$legacyCompiler) {
         //require_once JMF_FRAMEWORK_PATH.DIRECTORY_SEPARATOR. 'includes' .DIRECTORY_SEPARATOR. 'libraries' .DIRECTORY_SEPARATOR. 'less_parser' .DIRECTORY_SEPARATOR. 'Less.php';
         require_once JMF_FRAMEWORK_PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'less_parser' . DIRECTORY_SEPARATOR . 'Autoloader.php';
         Less_Autoloader::register();
     }
     $developer_mode = $this->params->get('devmode', false) == '1' ? true : false;
     $filename = JFile::stripExt(JFile::getName($lessPath));
     //$style_id = @JFactory::getApplication()->getTemplate(true)->id;
     $style_id = self::getTemplateStyleId();
     $css_suffix = '';
     // A suffix is simply ID of template style, eg. template.10.css
     if ($style_id > 0 && $coreStyle) {
         $css_suffix = '.' . $style_id;
     }
     // Establishing path to CSS file
     $cssPath = JPath::clean(JMF_TPL_PATH . '/css/' . $filename . $css_suffix . '.css');
     // Checking if LESS file exists. If not we should make sure that we're looking in correct directory
     if (!JFile::exists($lessPath)) {
         $lessPath = JPath::clean(JMF_TPL_PATH . '/less/' . $filename . '.less');
     }
     // If developer mode is disabled and CSS file is not older than LESS file, we do not have to compile LESS file.
     if (JFile::exists($lessPath) && JFile::exists($cssPath)) {
         $lessTime = filemtime($lessPath);
         $cssTime = filemtime($cssPath);
         // checking all dependent less files
         $forceCompile = false;
         if (!empty($this->lessMap) && !empty($this->lessMap[$filename . '.less'])) {
             $depLess = $this->lessMap[$filename . '.less'];
             foreach ($depLess as $depLessFile) {
                 $depName = JPath::clean(JMF_TPL_PATH . '/less/' . $depLessFile);
                 if (JFile::exists($depName)) {
                     $depTime = filemtime($depName);
                     if ($depTime > $cssTime) {
                         $forceCompile = true;
                         break;
                     }
                 }
             }
         }
         if ($lessTime <= $cssTime && $forceCompile == false && $developer_mode == false) {
             return JMF_TPL_URL . '/css/' . $filename . $css_suffix . '.css';
         }
     }
     // At this point, either we are in developer mode or CSS file does not exist or is older than LESS file.
     // But if CSS file does exist, we should delete it
     if (JFile::exists($cssPath)) {
         JFile::delete($cssPath);
     }
     try {
         if ($legacyCompiler) {
             // Initialising LessC compiler
             $less = new lessc();
             // Additional LESS variables
             if ($useVars) {
                 $variables = $this->params->get('jm_bootstrap_variables', array());
                 if (!empty($variables)) {
                     $less->setVariables($variables);
                 }
             }
             // Checked Compile - LessC
             $less->checkedCompile($lessPath, $cssPath);
         } else {
             // Less_Parser compiler
             $less_parser_options = array('compress' => $this->params->get('cssCompress', '0') == '1' ? true : false, 'relativeUrls' => false, 'sourceMap' => false);
             if ($this->params->get('sourceMap', false) == '1') {
                 // maps don't work when compression is enabled
                 $less_parser_options['compress'] = false;
                 $less_parser_options['sourceMap'] = true;
                 $less_parser_options['sourceMapWriteTo'] = JPath::clean(JMF_TPL_PATH . '/css/' . $filename . $css_suffix . '.map');
                 $less_parser_options['sourceMapURL'] = JUri::base(true) . '/templates/' . JMF_TPL . '/css/' . $filename . $css_suffix . '.map';
                 $less_parser_options['sourceMapFilename'] = JUri::base(true) . '/templates/' . JMF_TPL . '/css/' . $filename . $css_suffix . '.css';
                 $less_parser_options['sourceMapBasepath'] = str_replace(DIRECTORY_SEPARATOR, '/', JPATH_ROOT);
                 $less_parser_options['sourceRoot'] = JUri::base(false);
             }
             $less_parser = new Less_Parser($less_parser_options);
             // Additional LESS variables
             if ($useVars) {
                 $variables = $this->params->get('jm_bootstrap_variables', array());
                 if (!empty($variables)) {
                     // Less_Parser
                     $less_parser->ModifyVars($variables);
                 }
             }
             // Less_Parser - LESS file
             $less_parser->parseFile($lessPath, JMF_TPL_URL . '/css');
             // Compilation - Less_Parser
             if ($css_content = $less_parser->getCss()) {
                 if (JFile::write($cssPath, $css_content) == false) {
                     throw new Exception('Cannot save CSS file. Please check your directory permissions.');
                 }
             }
         }
     } catch (exception $e) {
         throw new Exception(JText::sprintf('PLG_SYSTEM_JMFRAMEWORK_LESS_ERROR', $e->getMessage()));
     }
     // Returning CSS file's URL
     return JMF_TPL_URL . '/css/' . $filename . $css_suffix . '.css';
 }
 /**
  * Compiling Scss with less
  *
  * @param string $lessFilename Existing less file absolute
  * path
  * @param string $cssFilename File to be written with
  * compiled CSS
  * @return string
  *
  */
 protected function compileScss($lessFilename, $cssFilename)
 {
     $str_vars = "";
     foreach ($this->variables as $key => $value) {
         $str_vars .= "@" . $key . ": " . $value . ";";
     }
     $extPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('ws_less');
     require_once $extPath . 'Resources/Private/less.php/lib/Less/Autoloader.php';
     Less_Autoloader::register();
     $parser = new Less_Parser();
     if (file_exists($lessFilename)) {
         $parser->parseFile($lessFilename);
         $parser->parse($str_vars);
         $css = $parser->getCss();
         t3lib_div::writeFile($cssFilename, $css);
         return $cssFilename;
     }
     return '';
 }
Пример #12
0
 /**
  * Compiling Scss with less
  *
  * @param string $lessFilename Existing less file absolute
  * path
  * @param string $cssFilename File to be written with
  * compiled CSS
  * @return string
  *
  */
 protected function compileScss($lessFilename, $cssFilename, $vars)
 {
     $extPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('ws_less');
     require_once $extPath . 'Resources/Private/less.php/lib/Less/Autoloader.php';
     \Less_Autoloader::register();
     $parser = new \Less_Parser();
     if (file_exists($lessFilename)) {
         $parser->parseFile($lessFilename);
         $parser->parse($vars);
         $css = $parser->getCss();
         GeneralUtility::writeFile($cssFilename, $css);
         return $cssFilename;
     }
     return '';
 }
Пример #13
0
 /**
  * @param $file
  * @param $output
  * @param $u
  */
 protected function compileLessFile($file, $output, $u, $compress = false)
 {
     include_once 'phar://' . SOBI_PATH . '/lib/services/third-party/less/less.phar.tar.gz/Autoloader.php';
     try {
         Less_Autoloader::register();
         if ($compress) {
             $options = array('compress' => true, 'strictMath' => true);
         } else {
             $options = array();
         }
         $parser = new Less_Parser($options);
         $parser->parseFile($file);
         $css = $parser->getCss();
         if (SPFs::exists($output)) {
             SPFs::delete($output);
         }
         SPFs::write($output, $css);
     } catch (Exception $x) {
         $this->response(Sobi::Url($u), SPLang::e('TP.LESS_FILE_NOT_COMPILED', $x->getMessage()), false, SPC::ERROR_MSG);
     }
 }