Esempio n. 1
10
 /**
  * Filters an asset after it has been loaded.
  *
  * @param  \Assetic\Asset\AssetInterface  $asset
  * @return void
  */
 public function filterLoad(AssetInterface $asset)
 {
     $max_nesting_level = ini_get('xdebug.max_nesting_level');
     $memory_limit = ini_get('memory_limit');
     if ($max_nesting_level && $max_nesting_level < 200) {
         ini_set('xdebug.max_nesting_level', 200);
     }
     if ($memory_limit && $memory_limit < 256) {
         ini_set('memory_limit', '256M');
     }
     $root = $asset->getSourceRoot();
     $path = $asset->getSourcePath();
     $dirs = array();
     $lc = new \Less_Parser(array('compress' => true));
     if ($root && $path) {
         $dirs[] = dirname($root . '/' . $path);
     }
     foreach ($this->loadPaths as $loadPath) {
         $dirs[] = $loadPath;
     }
     $lc->SetImportDirs($dirs);
     $url = parse_url($this->getRequest()->getUriForPath(''));
     $absolutePath = str_replace(public_path(), '', $root);
     if (isset($url['path'])) {
         $absolutePath = $url['path'] . $absolutePath;
     }
     $lc->parseFile($root . '/' . $path, $absolutePath);
     $asset->setContent($lc->getCss());
 }
Esempio n. 2
5
 /**
  * @param string $sourceFilePath
  * @return string
  */
 public function process($sourceFilePath)
 {
     $options = ['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER];
     try {
         $parser = new \Less_Parser($options);
         $parser->parseFile($sourceFilePath, '');
         return $parser->getCss();
     } catch (\Exception $e) {
         $messagePrefix = 'CSS compilation from LESS ';
         $this->logger->critical($messagePrefix . $e->getMessage());
         return $messagePrefix . $e->getMessage();
     }
 }
Esempio n. 3
0
 /**
  * @return \Less_Parser
  */
 protected function _initCompiler()
 {
     if ($this->_compiler) {
         return $this->_compiler;
     }
     $options = array('compress' => false, 'strictUnits' => false, 'strictMath' => false, 'relativeUrls' => true, 'cache_method' => false, 'sourceMap' => false, 'indentation' => '    ');
     if ($this->_isDebug()) {
         $options['sourceMap'] = true;
         $options['sourceMapRootpath'] = $this->_options->get('root_path');
         $options['sourceMapBasepath'] = $this->_options->get('root_path');
     }
     // Create compilier
     $this->_compiler = new \Less_Parser($options);
     $this->_compiler->Reset();
     // Global depends
     $mixins = $this->_options->get('autoload');
     foreach ($mixins as $mixin) {
         $this->_compiler->parseFile($mixin);
     }
     // Add custom vars
     $this->_compiler->ModifyVars((array) $this->_options->get('global_vars', []));
     // Set paths
     $importPaths = (array) $this->_options->get('import_paths', []);
     foreach ($importPaths as $fullPath => $relPath) {
         $this->setImportPath($fullPath, $relPath);
     }
     // Set cutsom functions
     $functions = (array) $this->_options->get('functions', [], 'arr');
     foreach ($functions as $name => $function) {
         $this->_compiler->registerFunction($name, $function);
     }
     return $this->_compiler;
 }
Esempio n. 4
0
 /**
  * @param string $path
  * @return string
  */
 protected function _compile($path)
 {
     try {
         $this->_processor->parseFile($path, $this->_tpl->less);
         $resultCss = $this->_processor->getCss();
         return $resultCss;
     } catch (Exception $ex) {
         die('<strong>Less Error (JBlank):</strong><br/><pre>' . $ex->getMessage() . '</pre>');
     }
 }
Esempio n. 5
0
 /**
  * Parse given css file with given vars.
  * 
  * @param  string $file
  * @param  array  $vars
  * 
  * @return string
  */
 public function parse($file, array $vars, $custom)
 {
     $this->parser->parseFile($this->app['base_dir'] . '/assets/less/vendor/bootstrap/' . $file . '.less', $this->app['base_url']);
     $this->parser->modifyVars($vars);
     $css = $this->parser->getCss();
     //parse custom less if any passed
     if ($custom) {
         $this->parser->reset();
         $customCss = $this->parser->parse($custom)->getCss();
     } else {
         $customCss = '';
     }
     return $css . $customCss;
 }
 function compile_botstrap_less_adm($theme, $input, $output = '', $compress = false)
 {
     global $cfg;
     $output = empty($output) ? $input : $output;
     $output = $cfg['themes_dir'] . '/admin/' . $theme . '/css/' . $output . '.css';
     $input = $cfg['themes_dir'] . '/admin/' . $theme . '/less/' . $input . '.less';
     if (file_exists($output) && file_exists($input)) {
         $filetimecss = filemtime($output);
         $filetimeless = filemtime($input);
         //	cot_print('css', cot_date('datetime_full', $filetimecss), 'less', cot_date('datetime_full', $filetimeless), cot_date('datetime_full'), $filetimecss > $filetimeless);
         if ($filetimecss > $filetimeless) {
             return false;
         } else {
             unlink($output);
             //	cot_print("deleted");
         }
     }
     $options = array('relativeUrls' => false);
     if ($compress) {
         $options['compress'] = true;
     }
     $parser = new Less_Parser($options);
     $parser->SetImportDirs(array($cfg['themes_dir'] . '/admin/' . $theme . '/less' => $cfg['themes_dir'] . '/admin/' . $theme . '/less', $cfg['plugins_dir'] . "/bootstrap/bootstrap/less" => $cfg['plugins_dir'] . "/bootstrap/bootstrap/less"));
     $parser->parseFile($input);
     $css = $parser->getCss();
     if (!file_exists($cfg['themes_dir'] . '/admin/' . $theme . '/css')) {
         mkdir($cfg['themes_dir'] . '/admin/' . $theme . '/css');
     }
     file_put_contents($output, $css);
     return true;
 }
Esempio n. 7
0
 /**
  * Make a css file compiled from the LESS files collection
  *
  * @param array $lessFiles LESS files structures array
  *
  * @return array
  */
 public function makeCSS($lessFiles)
 {
     $file = $this->makeLESSResourcePath($lessFiles);
     $path = $this->getCSSResource($lessFiles);
     $url = $this->getCSSResourceURL($path);
     $data = array('file' => $path, 'media' => 'screen', 'url' => $url);
     if ($this->needToCompileLessResource($lessFiles)) {
         try {
             $originalPath = $this->getCSSResource($lessFiles, true);
             if ($path != $originalPath && $this->getLESSResourceHash($lessFiles, true) && $this->getLESSResourceHash($lessFiles, true) == $this->calcLESSResourceHash($lessFiles) && \Includes\Utils\FileManager::isFileReadable($originalPath)) {
                 $content = \Includes\Utils\FileManager::read($originalPath);
             } else {
                 // Need recreate parser for every parseFile
                 $this->parser = new \Less_Parser($this->getLessParserOptions());
                 $this->parser->parseFile($file, '');
                 $this->parser->ModifyVars($this->getModifiedLESSVars($data));
                 $content = $this->prepareLESSContent($this->parser->getCss(), $path, $data);
                 $this->setLESSResourceHash($lessFiles);
             }
             \Includes\Utils\FileManager::mkdirRecursive(dirname($path));
             \Includes\Utils\FileManager::write($path, $content);
         } catch (\Exception $e) {
             \XLite\Logger::getInstance()->registerException($e);
             $data = null;
         }
     }
     return $data;
 }
Esempio n. 8
0
 /**
  * @param string $sourceFilePath
  * @return string
  */
 public function process($sourceFilePath)
 {
     $options = ['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER];
     $parser = new \Less_Parser($options);
     $parser->parseFile($sourceFilePath, '');
     return $parser->getCss();
 }
Esempio n. 9
0
 public function compileFile($fname, $outFname = null)
 {
     if (!is_readable($fname)) {
         throw new Exception('load error: failed to find ' . $fname);
     }
     $pi = pathinfo($fname);
     $oldImport = $this->importDir;
     $this->importDir = (array) $this->importDir;
     $this->importDir[] = realpath($pi['dirname']) . '/';
     $this->allParsedFiles = array();
     $this->addParsedFile($fname);
     $parser = new Less_Parser(array('sourceMap' => $this->sourceMap));
     $parser->SetImportDirs($this->getImportDirs());
     if (count($this->registeredVars)) {
         $parser->ModifyVars($this->registeredVars);
     }
     foreach ($this->libFunctions as $name => $func) {
         $parser->registerFunction($name, $func);
     }
     $parser->parseFile($fname);
     $out = $parser->getCss();
     $parsed = Less_Parser::AllParsedFiles();
     foreach ($parsed as $file) {
         $this->addParsedFile($file);
     }
     $this->importDir = $oldImport;
     if ($outFname !== null) {
         return file_put_contents($outFname, $out);
     }
     return $out;
 }
Esempio n. 10
0
 /**
  * Compare the parser results with the expected css
  *
  */
 function CompareFile($expected_file)
 {
     $less_file = $this->TranslateFile($expected_file);
     $expected_css = trim(file_get_contents($expected_file));
     // Check with standard parser
     echo "\n  " . basename($expected_file);
     echo "\n    - Standard Compiler";
     $parser = new Less_Parser();
     $parser->parseFile($less_file);
     $css = $parser->getCss();
     $css = trim($css);
     $this->assertEquals($expected_css, $css);
     // Check with cache
     if ($this->cache_dir) {
         $options = array('cache_dir' => $this->cache_dir);
         $files = array($less_file => '');
         echo "\n    - Regenerating Cache";
         $css_file_name = Less_Cache::Regen($files, $options);
         $css = file_get_contents($this->cache_dir . '/' . $css_file_name);
         $css = trim($css);
         $this->assertEquals($expected_css, $css);
         // Check using the cached data
         echo "\n    - Using Cache";
         $css_file_name = Less_Cache::Get($files, $options);
         $css = file_get_contents($this->cache_dir . '/' . $css_file_name);
         $css = trim($css);
         $this->assertEquals($expected_css, $css);
     }
 }
function parse_less($filename, $file)
{
    global $less_file, $is_dev;
    $options = array();
    if ($is_dev) {
        $options['sourceMap'] = true;
        $options['sourceMapWriteTo'] = '../css/' . $file . '.map';
        $options['sourceMapURL'] = '../css/' . $file . '.map';
    } else {
        $options['compress'] = true;
    }
    $options['cache_dir'] = '../css_cache';
    try {
        $parser = new Less_Parser($options);
        $parser->parseFile($less_file, '../css/');
        ob_start();
        echo $parser->getCss();
        $css = ob_get_contents();
        ob_end_clean();
        header("Content-type: text/css");
        @file_put_contents('../css/' . $file . '.css', $css);
        return $css;
    } catch (Exception $e) {
        header("Content-type: text/css");
        echo '/* LESS ERROR : ' . "\n\n" . $e->getMessage() . "\n\n" . '*/';
        showError($file . '.less');
    }
}
Esempio n. 12
0
 public function getFormDynamicStyle($id)
 {
     $this->lessParser->parseFile($this->getBaseDir() . '/assets/less/style.less');
     $styleSettings = SCFP()->getSettings()->getStyleSettings();
     $this->lessParser->ModifyVars(array('id' => $id, 'no_border' => !empty($styleSettings['no_border']) ? $styleSettings['no_border'] : '', 'border_size' => !empty($styleSettings['border_size']) ? $styleSettings['border_size'] : '', 'border_style' => !empty($styleSettings['border_style']) ? $styleSettings['border_style'] : '', 'border_color' => !empty($styleSettings['border_color']) ? $styleSettings['border_color'] : '', 'field_label_text_color' => !empty($styleSettings['field_label_text_color']) ? $styleSettings['field_label_text_color'] : '', 'field_label_marker_text_color' => !empty($styleSettings['field_label_marker_text_color']) ? $styleSettings['field_label_marker_text_color'] : '', 'field_text_color' => !empty($styleSettings['field_text_color']) ? $styleSettings['field_text_color'] : '', 'no_background' => !empty($styleSettings['no_background']) ? $styleSettings['no_background'] : '', 'background_color' => !empty($styleSettings['background_color']) ? $styleSettings['background_color'] : '', 'button_color' => !empty($styleSettings['button_color']) ? $styleSettings['button_color'] : '', 'text_color' => !empty($styleSettings['text_color']) ? $styleSettings['text_color'] : '', 'hover_button_color' => !empty($styleSettings['hover_button_color']) ? $styleSettings['hover_button_color'] : '', 'hover_text_color' => !empty($styleSettings['hover_text_color']) ? $styleSettings['hover_text_color'] : ''));
     return '<style type="text/css" >' . $this->lessParser->getCss() . '</style>';
 }
Esempio n. 13
0
 /**
  * @inheritdoc
  * @throws ContentProcessorException
  */
 public function processContent(File $asset)
 {
     $path = $asset->getPath();
     try {
         $parser = new \Less_Parser(['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER]);
         $content = $this->assetSource->getContent($asset);
         if (trim($content) === '') {
             return '';
         }
         $tmpFilePath = $this->temporaryFile->createFile($path, $content);
         gc_disable();
         $parser->parseFile($tmpFilePath, '');
         $content = $parser->getCss();
         gc_enable();
         if (trim($content) === '') {
             $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path;
             $this->logger->critical($errorMessage);
             throw new ContentProcessorException(new Phrase($errorMessage));
         }
         return $content;
     } catch (\Exception $e) {
         $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage();
         $this->logger->critical($errorMessage);
         throw new ContentProcessorException(new Phrase($errorMessage));
     }
 }
Esempio n. 14
0
 /**
  * @return string
  */
 public function getFile()
 {
     // TODO use caching from plugin instead of custom caching to avoid import errors
     // Create less parser
     $parser = new \Less_Parser();
     try {
         // Parse file using direct file path
         $parser->parseFile($this->file['path'], '/');
         // Turn less into css
         $contents = $parser->getCss();
         // get all parsed files
         $parsed_files = $parser::AllParsedFiles();
         // reformat to make them the same format as the scss result parsed files list
         $new_list = array();
         foreach ($parsed_files as $parse_file) {
             $new_list[$parse_file] = filemtime($parse_file);
         }
         // store the new list
         $this->cache->save($this->file['hash'] . "parsed_files", $new_list);
     } catch (\Exception $e) {
         return false;
     }
     // fix absolute paths
     $contents = str_replace(array('../'), str_replace(ROOT, "", dirname($this->file['path'])) . '/../', $contents);
     // return css
     return $contents;
 }
Esempio n. 15
0
 /**
  * Compile the asset and return true on success
  *
  * @throws \Exception
  */
 protected function compile()
 {
     require_once TL_ROOT . '/' . $this->getParserPath();
     $parser = new \Less_Parser();
     $parser->parseFile(TL_ROOT . '/' . $this->getSourceFile()->path);
     $file = $this->getTemporaryFile();
     $file->write($parser->getCss());
 }
Esempio n. 16
0
 public function wpless2csssavecss($creds)
 {
     $plugindir = plugin_dir_path(__FILE__);
     if (!class_exists('Less_Parser')) {
         require $plugindir . 'less-php/Less.php';
     }
     $options = array('compress' => true, 'credits' => $creds);
     $parser = new Less_Parser($options);
     WP_Filesystem($creds);
     global $wp_filesystem;
     if (!$wp_filesystem->exists($rootless = trailingslashit($wp_filesystem->wp_themes_dir()) . trailingslashit(get_stylesheet()) . 'wpless2css/wpless2css.less')) {
         if (!$wp_filesystem->exists($rootless = trailingslashit($wp_filesystem->wp_themes_dir()) . trailingslashit(get_template()) . 'wpless2css/wpless2css.less')) {
             if (!$wp_filesystem->exists($rootless = trailingslashit($wp_filesystem->wp_content_dir()) . 'wpless2css/wpless2css.less')) {
                 wp_die(__('<strong>wpless2css/wpless2css.less</strong> is missing', 'wpless2css'));
             }
         }
     }
     $parser->parseFile($rootless, '../');
     $parser->parse(apply_filters('get_theme_mods', ''));
     if ($extrafiles = apply_filters('add_extra_less_files', '')) {
         foreach ($extrafiles as $extrafile) {
             $parser->parseFile(trailingslashit(str_replace('wp-content/', '', $wp_filesystem->wp_content_dir())) . $extrafile);
         }
     }
     $parser->parse(apply_filters('add_extra_less_code', ''));
     $parser->parse(get_theme_mod('customlesscode'));
     $css = $parser->getCss();
     if (is_rtl()) {
         $css = str_replace('navbar-left', 'navbar-l', $css);
         $css = str_replace('navbar-right', 'navbar-r', $css);
         $css = str_replace('left', 'wasleft', $css);
         $css = str_replace('right', 'left', $css);
         $css = str_replace('wasleft', 'right', $css);
         $css = str_replace('navbar-l', 'navbar-left', $css);
         $css = str_replace('navbar-r', 'navbar-right', $css);
         $css .= ' body{direction: rtl; unicode-bidi: embed;}';
         set_theme_mod('rtl_compiled', 1);
     } else {
         set_theme_mod('rtl_compiled', 0);
     }
     $folder = trailingslashit($wp_filesystem->wp_themes_dir()) . trailingslashit(get_stylesheet()) . '/';
     if (!$wp_filesystem->put_contents($folder . $this->filename, $css, FS_CHMOD_FILE)) {
         wp_die("error saving file!");
     }
     //file_put_contents( $this->folder.$this->filename, $css);
 }
Esempio n. 17
0
 /**
  * This function generates from the customized bootstrap.less und font-awesome.less a combined css file
  *
  * @param string|null $writeTo Where to dump the generated file.
  */
 public static function generateCombinedBootstrapFontAwesomeCSS($writeTo = null)
 {
     // Also change build.xml if you change the default writeTo path here!
     $writeTo = is_string($writeTo) ? $writeTo : 'src/web/bootstrap-font-awesome.css';
     $parser = new \Less_Parser();
     $parser->setOptions(array('relativeUrls' => false, 'compress' => true));
     $parser->parseFile('src/style/bootstrap-font-awesome.less');
     file_put_contents($writeTo, $parser->getCss());
 }
Esempio n. 18
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();
     }
 }
 /**
  * main() method.
  *
  * @return bool|int Success or error code.
  */
 public function main()
 {
     $config = ['custom_bootstrap_less' => Configure::read('App.webroot') . '/css/vendor/bootstrap/less/custom_bootstrap.less', 'target_css' => Configure::read('App.webroot') . '/css/vendor/bootstrap/css/bootstrap_custom.css', 'compress' => false];
     $this->out('Using custom bootstrap.less: ' . $config['custom_bootstrap_less']);
     $lessPhpOptions = ['compress' => $config['compress']];
     $parser = new \Less_Parser($lessPhpOptions);
     $parser->parseFile($config['custom_bootstrap_less']);
     file_put_contents($config['target_css'], $parser->getCss());
     $this->out('Wrote compiled file to: ' . $config['target_css']);
 }
Esempio n. 20
0
 /**
  * Test
  */
 public function testFunction()
 {
     echo "\nBegin Tests";
     $less_file = $this->fixtures_dir . '/functions/less/f1.less';
     $expected_css = file_get_contents($this->fixtures_dir . '/functions/css/f1.css');
     $parser = new Less_Parser();
     $parser->registerFunction('myfunc-reverse', array(__CLASS__, 'reverse'));
     $parser->parseFile($less_file);
     $generated_css = $parser->getCss();
     $this->assertEquals($expected_css, $generated_css);
 }
Esempio n. 21
0
 /**
  * Runs `lessc` against any files that match the configured extension.
  *
  * @param string $filename The name of the input file.
  * @param string $input The content of the file.
  * @return string
  * @throws \Exception
  */
 public function input($filename, $input)
 {
     if (substr($filename, strlen($this->_settings['ext']) * -1) !== $this->_settings['ext']) {
         return $input;
     }
     if (!class_exists('\\Less_Parser')) {
         throw new \Exception('Cannot not load "\\Less_Parser" class. Make sure https://github.com/oyejorge/less.php is installed.');
     }
     $parser = new \Less_Parser();
     return $parser->parseFile($filename)->getCss();
 }
Esempio n. 22
0
 public function less_compile($observer)
 {
     $setting = Mage::helper('creative/data');
     $less_theme_compile = Mage::getStoreConfig('creative_cfg/advanced/less_compile');
     $preset_name = Mage::getStoreConfig('creative_cfg/general/color');
     $device_responsive = Mage::getStoreConfig('creative_cfg/general/device_responsive');
     if (!Mage::app()->getStore()->isAdmin() && $less_theme_compile) {
         if (!class_exists('Less_Parser')) {
             include_once Mage::getBaseDir('lib') . 'Less/Version.php';
             include_once Mage::getBaseDir('lib') . 'Less/Parser.php';
         }
         if (class_exists('Less_Parser') && $less_theme_compile) {
             $skin_base_dir = Mage::getDesign()->getSkinBaseDir();
             $skin_base_url = Mage::getDesign()->getSkinUrl();
             define('LESS_PATH', $skin_base_dir . '/less');
             define('CSS__PATH', $skin_base_dir . '/css');
             $import_dirs = array(LESS_PATH . '/path/' => $skin_base_url . '/less/path/', LESS_PATH . '/bootstrap/' => $skin_base_url . '/less/bootstrap/');
             $options = array('compress' => true);
             if (file_exists(LESS_PATH . '/theme.less') && $less_theme_compile) {
                 if ($preset_name) {
                     $output_cssf = CSS__PATH . '/theme-' . $preset_name . '.css';
                 } else {
                     $output_cssf = CSS__PATH . '/theme-default.css';
                 }
                 $less = new Less_Parser($options);
                 $less->SetImportDirs($import_dirs);
                 $less->parseFile(LESS_PATH . '/theme.less', $skin_base_url . 'css/');
                 if (file_exists(LESS_PATH . '/theme-' . $preset_name . '.less')) {
                     $less->parseFile(LESS_PATH . '/theme-' . $preset_name . '.less', $skin_base_url . 'css/');
                 }
                 if ($device_responsive == 1) {
                     $less->parseFile(LESS_PATH . '/path/yt-responsive.less', $skin_base_url . 'css/');
                 } else {
                     $less->parseFile(LESS_PATH . '/path/yt-non-responsive.less', $skin_base_url . 'css/');
                 }
                 $cache = $less->getCss();
                 file_put_contents($output_cssf, $cache);
             }
         }
     }
 }
Esempio n. 23
0
 public function Compile($less_files, $out_name, $modify_vars = [], $bootstrap_less = "mixins", $mediawiki_less = "mixins")
 {
     $lessphp = new \Less_Parser($this->cache_dir);
     switch ($bootstrap_less) {
         case "mixins":
             $lessphp->parseFile($this->bootstrap_dir . "/variables.less", "");
             $lessphp->parseFile(__DIR__ . "/custom_variables.less", "");
             $lessphp->parseFile($this->bootstrap_mixin, $this->bootstrap_mixin_url);
             break;
         case "full":
             $lessphp->SetImportDirs([$this->bootstrap_dir]);
             $lessphp->parseFile(__DIR__ . "/bootstrap.less", "");
             break;
         case "off":
             break;
     }
     switch ($mediawiki_less) {
         case "mixins":
             $lessphp->parseFile($this->mediawiki_mixin, $this->mediawiki_mixin_url);
             break;
         case "off":
             break;
     }
     foreach ($less_files as $less => $url) {
         $lessphp->parseFile($less, $url);
     }
     if ($modify_vars) {
         $lessphp->ModifyVars($modify_vars);
     }
     $css = $lessphp->getCss();
     file_put_contents($out_name, $css);
 }
Esempio n. 24
0
/**
 * Created by PhpStorm.
 * User: duonglh
 * Date: 8/23/14
 * Time: 3:01 PM
 */
function cupid_generate_less()
{
    require_once 'Less.php';
    $cupid_data = of_get_options();
    try {
        $primary_color = $cupid_data['primary-color'];
        $secondary_color = $cupid_data['secondary-color'];
        $button_color = $cupid_data['button-color'];
        $bullet_color = $cupid_data['bullet-color'];
        $icon_box_color = $cupid_data['icon-box-color'];
        $site_logo_url = $cupid_data['site-logo'];
        $site_logo_white_url = $cupid_data['site-logo-white'];
        $site_logo_url = str_replace(THEME_URL, '', $site_logo_url);
        $site_logo_white_url = str_replace(THEME_URL, '', $site_logo_white_url);
        $css = '@primary_color:' . $primary_color . ';';
        $css .= '@secondary_color:' . $secondary_color . ';';
        $css .= '@button_color:' . $button_color . ';';
        $css .= '@bullet_color:' . $bullet_color . ';';
        $css .= '@icon_box_color:' . $icon_box_color . ';';
        $css .= "@logo_url : '" . $site_logo_url . "';@logo_white_url : '" . $site_logo_white_url . "';";
        $css .= '@theme_url:"' . THEME_URL . '";';
        $style = $css;
        require_once ABSPATH . 'wp-admin/includes/file.php';
        require_once THEME_DIR . "lib/inc-generate-less/custom-css.php";
        $custom_css = cupid_custom_css();
        WP_Filesystem();
        global $wp_filesystem;
        $options = array('compress' => true);
        $parser = new Less_Parser($options);
        $parser->parse($css);
        $parser->parseFile(THEME_DIR . 'assets/css/less/style.less');
        $parser->parse($custom_css);
        $css = $parser->getCss();
        if (!$wp_filesystem->put_contents(THEME_DIR . "style.min.css", $css, FS_CHMOD_FILE)) {
            echo __('Could not save file', 'cupid');
            return '0';
        }
        /*$theme_info = $wp_filesystem->get_contents( THEME_DIR . "theme-info.txt" );
                $parser = new Less_Parser();
                $parser->parse($style);
                $parser->parseFile(THEME_DIR . 'assets/css/less/style.less',THEME_URL);
                $style = $parser->getCss();
        		$parser->parse($custom_css);
                $style = $theme_info . "\n" . $style;
                $style = str_replace("\r\n","\n", $style);
                $wp_filesystem->put_contents( THEME_DIR.   "style.css", $style, FS_CHMOD_FILE);*/
        return '1';
    } catch (Exception $e) {
        echo 'Caught exception: ', $e->getMessage(), "\n";
        return '0';
    }
}
Esempio n. 25
0
 /**
  * @param string $sourceFilePath
  * @return string
  */
 public function process($sourceFilePath)
 {
     $options = ['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER];
     try {
         $parser = new \Less_Parser($options);
         $parser->parseFile($sourceFilePath, '');
         return $parser->getCss();
     } catch (\Exception $e) {
         $errorMessage = self::ERROR_MESSAGE_PREFIX . $e->getMessage();
         $this->logger->critical($errorMessage);
         return $errorMessage;
     }
 }
Esempio n. 26
0
 /**
  * {@inheritdoc}
  */
 public function compile($path, $relativePath)
 {
     $this->parsedFiles = array();
     $parser = new \Less_Parser(array('compress' => true));
     if (!empty($this->importDirs)) {
         $parser->SetImportDirs($this->importDirs);
     }
     $parser->parseFile($path);
     $parser->ModifyVars($this->variables);
     $css = $parser->getCss();
     $this->parsedFiles = $parser->allParsedFiles();
     return $css;
 }
Esempio n. 27
0
 protected function _getInlineCSS()
 {
     require_once $this->_sDirPlugins . 'lessphp/Less.php';
     $oLessParser = new Less_Parser();
     $oConfigBase = new BxBaseConfig();
     $oLessParser->ModifyVars($oConfigBase->aLessConfig);
     foreach ($this->_aFilesCss as $sFile) {
         if (substr($sFile, -5) !== '.less') {
             continue;
         }
         $oLessParser->parseFile($this->_sPathCss . $sFile, $this->_sUrlCss);
     }
     return $oLessParser->getCss();
 }
Esempio n. 28
0
 function css($file, $media = null)
 {
     /**
      * Only initiate automatically if:
      * - webiste is in dev mode
      * - or a ?flush is called
      */
     if (preg_match('/\\.less$/i', $file) || Director::isDev() || isset($_GET['flush'])) {
         /* If file is CSS, check if there is a LESS file */
         if (preg_match('/\\.css$/i', $file)) {
             $less = preg_replace('/\\.css$/i', '.less', $file);
             if (is_file(Director::getAbsFile($less))) {
                 $file = $less;
             }
         }
         /* If less file exists, then check/compile it */
         if (preg_match('/\\.less$/i', $file)) {
             $out = preg_replace('/\\.less$/i', '.css', $file);
             $css_file = Director::getAbsFile($out);
             $options = array();
             /* Automatically compress if in live mode */
             if (Director::isLive()) {
                 $options['compress'] = true;
             }
             try {
                 /* Force recompile & only write to css if updated */
                 if (isset($_GET['flush']) || !Director::isLive()) {
                     /* Create instance */
                     $parser = new Less_Parser($options);
                     if (!empty(self::$variables)) {
                         $parser->ModifyVars(self::$variables);
                     }
                     /* calculate the LESS file's parent URL */
                     $css_dir = rtrim(Director::baseURL(), '/') . Director::makeRelative(dirname(Director::getAbsFile($file)) . '/');
                     $parser->parseFile(Director::getAbsFile($file), $css_dir);
                     $css = $parser->getCss();
                     if (!is_file($css_file) || md5_file($css_file) != md5($css)) {
                         file_put_contents($css_file, $css);
                     }
                 }
             } catch (Exception $ex) {
                 trigger_error("Less.php fatal error: " . $ex->getMessage(), E_USER_ERROR);
             }
             $file = $out;
         }
     }
     /* Return css path */
     return parent::css($file, $media);
 }
Esempio n. 29
0
 /**
  * Test
  */
 public function testMap()
 {
     echo "\nBegin Tests";
     $less_file = $this->fixtures_dir . '/bootstrap3-sourcemap/less/bootstrap.less';
     $map_file = $this->fixtures_dir . '/bootstrap3-sourcemap/expected/bootstrap.map';
     $map_destination = $this->cache_dir . '/bootstrap.map';
     $options['sourceMap'] = true;
     $options['sourceMapWriteTo'] = $map_destination;
     $options['sourceMapURL'] = '/';
     $parser = new Less_Parser($options);
     $parser->parseFile($less_file);
     $css = $parser->getCss();
     $expected_map = file_get_contents($map_file);
     $generated_map = file_get_contents($map_destination);
     $this->assertEquals($expected_map, $generated_map);
 }
 public function register()
 {
     Event::listen('watcher:check', function ($options) {
         $timestamp = strtotime($options->timestamp);
         $reload = false;
         if (isset($options->less_process) && is_array($options->less_process) && $timestamp) {
             $lessCompiler = new \Less_Parser();
             if (isset($options->less_importdirs) && is_array($options->less_importdirs)) {
                 $importDirs = array();
                 foreach ($options->less_importdirs as $importdir) {
                     $importdir = realpath(base_path($importdir));
                     if (is_dir($importdir)) {
                         $importDirs[] = $importdir;
                         foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($importdir)) as $x) {
                             if (!$x->isDir() && $x->getCTime() > $timestamp) {
                                 $reload = true;
                             }
                         }
                     }
                 }
                 $lessCompiler->SetImportDirs($importDirs);
             }
             foreach ($options->less_process as $source => $output) {
                 $source = realpath(base_path($source));
                 $output = realpath(base_path($output));
                 if (!$output) {
                     $output = base_path($output);
                 }
                 if (is_file($source)) {
                     if ($reload) {
                         touch($source);
                     }
                     if (filemtime($source) > $timestamp || $reload) {
                         try {
                             $lessCompiler->parseFile($source, '/');
                             $css = $lessCompiler->getCss();
                             if ($css) {
                                 file_put_contents($output, $css);
                             }
                         } catch (Exception $e) {
                         }
                     }
                 }
             }
         }
     });
 }