public function boot(Application $app)
 {
     // Validate this params.
     $this->validate($app);
     // Define default formatter if not already set.
     $formatter = isset($app['less.formatter']) ? $app['less.formatter'] : self::FORMATTER_CLASSIC;
     $sources = $app['less.sources'];
     $target = $app['less.target'];
     $targetContent = '';
     $needToRecompile = false;
     !is_array($sources) and $sources = array($sources);
     foreach ($sources as $source) {
         if (!$needToRecompile) {
             $needToRecompile = $this->targetNeedsRecompile($source, $target);
         }
         if ($needToRecompile) {
             $handle = new \lessc($source);
             $handle->setFormatter($formatter);
             $targetContent .= $handle->parse();
         }
     }
     if (isset($handle)) {
         if ($targetContent) {
             file_put_contents($target, $targetContent);
             if (isset($app['less.target_mode'])) {
                 chmod($target, $app['less.target_mode']);
             }
         } else {
             throw new \Exception("No content after parsing less source files. Please check your .less files");
         }
     }
 }
示例#2
0
 /**
  * Process asset content
  *
  * @param   string $content
  * @param   Asset  $asset
  *
  * @return  string
  */
 public static function process($content, Asset $asset)
 {
     // Set Less
     $lc = new lessc();
     $lc->importDir = dirname($asset->source_file()) . DIRECTORY_SEPARATOR;
     return $lc->parse($content);
 }
示例#3
0
 /**
  * Parse all the less files resolving the dependencies.
  *
  * @param array $variables
  * @throws Ai1ec_File_Not_Found_Exception|Exception
  * @throws Exception
  * @return string
  */
 public function parse_less_files(array $variables = null)
 {
     // If no variables are passed, initialize from DB, config file, and
     // extension injections in one call.
     if (empty($variables)) {
         $variables = $this->get_saved_variables(false);
     }
     // convert the variables to key / value
     $variables = $this->convert_less_variables_for_parsing($variables);
     // Inject additional constants from extensions.
     $variables = apply_filters('ai1ec_less_constants', $variables);
     // Load the static variables defined in the theme's variables.less file.
     $this->load_static_theme_variables();
     $loader = $this->_registry->get('theme.loader');
     // Allow extensions to add their own LESS files.
     $this->files = apply_filters('ai1ec_less_files', $this->files);
     $this->files[] = 'override.less';
     // Find out the active theme URL.
     $option = $this->_registry->get('model.option');
     $theme = $option->get('ai1ec_current_theme');
     $this->lessc->addImportDir($theme['theme_dir'] . DIRECTORY_SEPARATOR . 'less');
     $import_dirs = array();
     foreach ($this->files as $file) {
         $file_to_parse = null;
         try {
             // Get the filename following our fallback convention
             $file_to_parse = $loader->get_file($file);
         } catch (Ai1ec_Exception $e) {
             // We let child themes override styles of Vortex.
             // So there is no fallback for override and we can continue.
             if ($file !== 'override.less') {
                 throw $e;
             } else {
                 // It's an override, skip it.
                 continue;
             }
         }
         // We prepend the unparsed variables.less file we got earlier.
         // We do this as we do not import that anymore in the less files.
         $this->unparsed_variable_file .= $file_to_parse->get_content();
         // Set the import directories for the file. Includes current directory of
         // file as well as theme directory in core. This is important for
         // dependencies to be resolved correctly.
         $dir = dirname($file_to_parse->get_name());
         if (!isset($import_dirs[$dir])) {
             $import_dirs[$dir] = true;
             $this->lessc->addImportDir($dir);
         }
     }
     $variables['fontdir'] = '~"' . $theme['theme_url'] . '/font"';
     $variables['fontdir_default'] = '~"' . $this->default_theme_url . 'font"';
     $variables['imgdir'] = '~"' . $theme['theme_url'] . '/img"';
     $variables['imgdir_default'] = '~"' . $this->default_theme_url . 'img"';
     try {
         $this->parsed_css = $this->lessc->parse($this->unparsed_variable_file, $variables);
     } catch (Exception $e) {
         throw $e;
     }
     return $this->parsed_css;
 }
 /**
  * Parse all the less files resolving the dependencies.
  *
  * @return string
  */
 public function parse_less_files(array $variables = null)
 {
     global $ai1ec_themes_controller;
     // If no variables are passed i get them from the db
     if (null === $variables) {
         $variables = $this->db_adapter->get_data_from_config(self::DB_KEY_FOR_LESS_VARIABLES);
         // If they are not set in the db, get them from file.
         // this happen when the user switched the theme and triggered a new parse.
         if (false === $variables) {
             $variables = $this->get_less_variable_data_from_config_file(Ai1ec_Less_Factory::create_less_file_instance(Ai1ec_Less_File::USER_VARIABLES_FILE));
         }
     }
     // convert the variables to key / value
     $variables = $this->convert_less_variables_for_parsing($variables);
     // Load the variable.less file to use
     $this->load_less_variables_from_file();
     foreach ($this->files as $file) {
         $filename = '';
         /*
          * @var $file Ai1ec_Less_File
          */
         try {
             // Get the filename following our fallback convention
             $filename = $file->locate_exact_file_to_load_in_theme_folders();
         } catch (Ai1ec_File_Not_Found $e) {
             // We let child themes ovverride properties of vortex.
             // So there is no fallback for override and we can continue.
             if ($file->get_name() !== 'override') {
                 throw $e;
             } else {
                 // it's override, skip it.
                 continue;
             }
         }
         // if the file is a css file, no need to parse it, just serve it as usual.
         if (substr_compare($filename, '.css', -strlen('.css'), strlen('.css')) === 0) {
             $this->parsed_css .= file_get_contents($filename);
             continue;
         }
         // We prepend the unparsed variables.less file we got earlier.
         // We do this as we do not import that anymore in the less files.
         $css_to_parse = $this->unparsed_variable_file . file_get_contents($filename);
         // Set the import dir for the file. This is important as
         // dependencies will be resolved correctly
         $this->lessc->importDir = dirname($filename);
         // Set the font & img dirs
         $active_theme_url = AI1EC_THEMES_URL . '/' . $ai1ec_themes_controller->active_template_url();
         $variables['fontdir'] = '~"' . $active_theme_url . "/font\"";
         $variables['imgdir'] = '~"' . $active_theme_url . "/img\"";
         $variables['fontdir_default'] = '~"' . $this->default_theme_url . "/font\"";
         $variables['imgdir_default'] = '~"' . $this->default_theme_url . "/img\"";
         try {
             $this->parsed_css .= $this->lessc->parse($css_to_parse, $variables);
         } catch (Exception $e) {
             throw $e;
         }
     }
     return $this->parsed_css;
 }
示例#5
0
 /**
  * @return void
  */
 public function compileLessFiles()
 {
     foreach ($this->findLessFiles() as $lessFile) {
         $cssNameFile = self::getCssFileName($lessFile);
         $less = new lessc($lessFile);
         file_put_contents(sfConfig::get('sf_root_dir') . '/' . $this->getCssPaths() . '/' . $cssNameFile, $less->parse());
     }
 }
示例#6
0
 /**
  * @see PreFileFilter::__invoke()
  */
 public static function __invoke($code, \Lohini\WebLoader\WebLoader $loader, $file = NULL)
 {
     if ($file === NULL || strtolower(pathinfo($file, PATHINFO_EXTENSION)) != 'less') {
         return $code;
     }
     $filter = new \lessc($file);
     return $filter->parse();
 }
示例#7
0
 public function filterLoad(AssetInterface $asset)
 {
     $root = $asset->getSourceRoot();
     $path = $asset->getSourcePath();
     $lc = new \lessc();
     if ($root && $path) {
         $lc->importDir = dirname($root . '/' . $path);
     }
     $asset->setContent($lc->parse($asset->getContent()));
 }
 public function compile_less_string($final_string)
 {
     require_once 'lessphp/lessc.inc.php';
     $less_parser = new lessc();
     try {
         $final_string = $less_parser->parse($final_string);
     } catch (Exception $e) {
     }
     return $final_string;
 }
示例#9
0
 public function filterLoad(AssetInterface $asset)
 {
     $sourceUrl = $asset->getSourceUrl();
     if ($sourceUrl && false === strpos($sourceUrl, '://')) {
         $baseDir = self::isAbsolutePath($sourceUrl) ? '' : $this->baseDir . '/';
         $sourceUrl = $baseDir . $sourceUrl;
     }
     $lc = new \lessc($sourceUrl);
     // the way lessc::parse is implemented, the content wins if both url and content are defined
     $asset->setContent($lc->parse($asset->getContent()));
 }
示例#10
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
  */
 public function input($filename, $input)
 {
     if (substr($filename, strlen($this->_settings['ext']) * -1) !== $this->_settings['ext']) {
         return $input;
     }
     App::import('Vendor', 'lessc', array('file' => $this->_settings['path']));
     if (!class_exists('lessc')) {
         throw new Exception(sprintf('Cannot not load filter class "%s".', 'lessc'));
     }
     $lc = new lessc($filename);
     return $lc->parse();
 }
示例#11
0
 /**
  * Parse LESS markup using the lessphp library
  *
  * @param string $text
  * @param string|array $import_dir
  * @return string
  */
 public static function lessphp($text, $import_dir = null)
 {
     // load library
     require_once ICE_LIB_DIR . '/lessphp/less.inc.php';
     // new parser instance
     $less = new lessc();
     // set import dir if applicable
     if ($import_dir) {
         $less->importDir = $import_dir;
     }
     // parse and return it
     return $less->parse($text);
 }
示例#12
0
 /**
  * Filters an asset just before it's dumped.
  *
  * @param AssetInterface $asset
  */
 public function filterDump(AssetInterface $asset)
 {
     $compiler = new \lessc();
     $this->dispatch(new LoadThemeVariables($variables = new Collection()));
     $compiler->setVariables($variables->all());
     if ($dir = $asset->getSourceDirectory()) {
         $compiler->importDir = $dir;
     }
     foreach ($this->loadPaths as $loadPath) {
         $compiler->addImportDir($loadPath);
     }
     $asset->setContent($compiler->parse($this->parser->parse($asset->getContent())));
 }
 public function filterLoad(AssetInterface $asset)
 {
     $root = $asset->getSourceRoot();
     $path = $asset->getSourcePath();
     $lc = new \lessc();
     if ($root && $path) {
         $lc->importDir = dirname($root . '/' . $path);
     }
     foreach ($this->loadPaths as $loadPath) {
         $lc->addImportDir($loadPath);
     }
     $asset->setContent($lc->parse($asset->getContent(), $this->presets));
 }
示例#14
0
文件: less.php 项目: Acidburn0zzz/OEM
 protected static function render_file($path)
 {
     $cache_path = $path . '-cache.css';
     if (!file_exists($cache_path) || filemtime($cache_path) < filemtime($path)) {
         $out = parent::render_file($path);
         $less = new lessc();
         $less->importDir = dirname($path);
         //$less->registerFunction('url', array('LessCompiler', 'url'));
         $css = $less->parse($out);
         $css = str_replace('url("/', 'url("' . URL_ROOT . '/', $css);
         file_put_contents($cache_path, $css);
     }
     return file_get_contents($cache_path);
 }
示例#15
0
文件: Less.php 项目: nabble/ajde
 public static function lessifyCss($css)
 {
     if (substr_count($css, '/*#!less*/') === 0) {
         return $css;
     }
     $less = new lessc();
     try {
         $lesser = $less->parse($css);
     } catch (Exception $e) {
         Ajde_Exception_Log::logException($e);
         return $css;
     }
     return $lesser;
 }
 public function indexAction()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     $filename = $request->getRequestUri();
     $filePath = realpath(dirname(APPLICATION_PATH . '/../private' . $filename));
     // Validate this input
     //   must be alphanumeric / _ - or .
     //   must start with /assets
     //   must end with .css
     //   must be in the application paths private assets directory
     if (strpos($filePath, realpath(APPLICATION_PATH . '/../private/assets')) === 0 && preg_match('/^\\/assets\\/([a-zA-Z0-9\\/_\\-\\.])+\\.css$/', $filename)) {
         $cssInputFile = realpath(APPLICATION_PATH . '/../private' . $filename);
         // Check if its a css file. For optimisation purposes, we just return raw css files as is
         if (file_exists($cssInputFile)) {
             // File exists as a css file, just return the raw file
             $response->setHeader('Content-type', 'text/css; charset: UTF-8', true);
             echo file_get_contents($cssInputFile);
             return;
         } else {
             // File exists as a less file, compile the less file and throw back
             $lessInputFile = realpath(APPLICATION_PATH . '/../private' . str_replace('.css', '.less', $filename));
             $lessCacheTag = preg_replace('/[\\.\\-\\/]/', '_', $lessInputFile);
             // Attempt to load the css from a cache
             $cache = Zend_Cache::factory('File', 'File', array('master_files' => array($lessInputFile), 'lifetime' => 86400), array('cache_dir' => realpath(APPLICATION_PATH . '/../private/cache/css/')));
             if (($fileContents = $cache->load($lessCacheTag)) === false) {
                 // Generate new and cache
                 try {
                     // Parse with the PHP based less parser
                     $lc = new lessc($lessInputFile);
                     $fileContents = $lc->parse();
                     // Cache the file
                     $status = $cache->save($fileContents);
                     //, $lessCacheTag, array());
                 } catch (Exception $ex) {
                     // Throw out request as if it doesn't exist
                     $response->setHttpResponseCode(404);
                     return;
                 }
             }
             $response->setHeader('Content-type', 'text/css; charset: UTF-8', true);
             echo $fileContents;
             return;
         }
     } else {
         // Throw out request as if it doesn't exist
         $response->setHttpResponseCode(404);
     }
 }
示例#17
0
 public function filterLoad(AssetInterface $asset)
 {
     $lc = new \lessc();
     if ($dir = $asset->getSourceDirectory()) {
         $lc->importDir = $dir;
     }
     foreach ($this->loadPaths as $loadPath) {
         $lc->addImportDir($loadPath);
     }
     if ($this->formatter) {
         $lc->setFormatter($this->formatter);
     }
     if (null !== $this->preserveComments) {
         $lc->setPreserveComments($this->preserveComments);
     }
     $asset->setContent($lc->parse($asset->getContent(), $this->presets));
 }
 protected function parseLess($input)
 {
     $parsed = false;
     try {
         //include lessc library
         require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'lessc.inc.php';
         //setup the parser
         $lessc = new lessc();
         if ($this->compress) {
             $lessc->setFormatter("compressed");
         }
         $importDir = array_merge($this->importDir, array(dirname($input)));
         $lessc->setImportDir($importDir);
         //parse the file
         $parsed = $lessc->parse($input);
     } catch (exception $e) {
         throw new CException(__CLASS__ . ': Failed to compile less file with message: ' . $e->getMessage() . '.');
     }
     return $parsed;
 }
示例#19
0
 /**
  * Compiles Bootstrap LESS codes and save the result in database.
  *
  * @return mixed
  */
 function actions($options)
 {
     global $wp_filesystem;
     $uploads = wp_upload_dir();
     if (!empty($options['less'])) {
         require_once plugin_dir_path(__FILE__) . 'lib/lessphp/lessc.inc.php';
         $lessphp = new lessc();
         $lessphp->setVariables(wp_parse_args($options['vars'], $this->default_bootstrap_variables()));
         $less = file_get_contents(dirname(__FILE__) . '/lib/bootstrap/less/mixins.less');
         foreach ($options['less'] as $raw_less) {
             $less .= file_get_contents(dirname(__FILE__) . '/lib/bootstrap/less/' . $raw_less . '.less');
         }
         /* compile LESS and minify the result */
         $css = $this->minify_css($lessphp->parse($less));
         WP_Filesystem();
         $wp_filesystem->put_contents(trailingslashit($uploads['basedir']) . 'bootstrap.css', $css, 0644);
     } else {
         @unlink(trailingslashit($uploads['basedir']) . 'bootstrap.css');
     }
     return $options;
 }
示例#20
0
 /**
  * Execute the build CSS command.
  */
 function execute()
 {
     // Load the LESS compiler class.
     require_once 'lib/pkp/lib/lessphp/lessc.inc.php';
     // Flush if necessary
     if ($this->force) {
         unlink(APPLICATION_STYLES_DIR . '/' . APPLICATION_CSS_WRAPPER);
     }
     // Perform the compile.
     try {
         // KLUDGE pending fix of https://github.com/leafo/lessphp/issues#issue/66
         // Once this issue is fixed, revisit paths and go back to using
         // lessc::ccompile to parse & compile.
         $less = new lessc(APPLICATION_STYLES_DIR . '/' . APPLICATION_LESS_WRAPPER);
         $less->importDir = './';
         file_put_contents(APPLICATION_STYLES_DIR . '/' . APPLICATION_CSS_WRAPPER, $less->parse());
     } catch (exception $ex) {
         echo "ERROR: " . $ex->getMessage() . "\n";
         exit(-1);
     }
     exit(0);
 }
示例#21
0
 /**
  * Compiles .less files, joins and serves CSS.
  * @param Array css files.
  * @param bool Cache the files?
  */
 public static function css(array $files, $cache = true)
 {
     require_once kohana::find_file('vendor', 'lessphp/lessc.inc', 'php');
     $cssname = md5(implode('', $files)) . '.css';
     if ($cache && !file_exists(url::site('media/cache/' . $cssname, 'http')) || !$cache) {
         $content = '';
         foreach ($files as $file) {
             if (strpos($file, 'http') !== false || file_exists($file)) {
                 if (strpos($file, '.less') !== false) {
                     // It's a LESS file that we need to compile
                     $less = @file_get_contents($file);
                     $compiler = new lessc();
                     $content .= $compiler->parse($less);
                 } else {
                     $content .= @file_get_contents($file);
                 }
             }
         }
         file_put_contents('media/cache/' . $cssname, $content);
         unset($content);
     }
     return HTML::style('media/cache/' . $cssname);
 }
示例#22
0
 /**
  * Compiles a `.less` file to a .css and returns the path to the compiled file.
  *
  * @param   mixed   The name(s) of the `.less` files (no path or extension required)
  * @param   string  The desired name of the target `.css` file
  * @return  string  The full path to the compiled `.css` file
  */
 public static function compile($source_names, $target = NULL)
 {
     // Get the config items for this module
     $config = Kohana::config('less');
     // Prepare sources and targets
     $source_names = (array) $source_names;
     $target = $target === NULL ? $source_names[0] : $target;
     // Get the relative paths to the files
     $target = rtrim($config->css_path, DIRECTORY_SEPARATOR . '/') . '/' . $target . '.css';
     $sources = array();
     foreach ($source_names as $source) {
         $sources[] = rtrim($config->less_path, DIRECTORY_SEPARATOR . '/') . '/' . $source . '.less';
     }
     // If we need to compile again, then let's compile!
     if (!$config->lock_css and LESS::need_to_compile($sources, $target)) {
         // Combine sources into one LESS string
         $less = '';
         foreach ($sources as $source) {
             // Get LESS content
             $less .= file_get_contents($source) . "\n\n";
         }
         // Instantiate LESS compiler
         $compiler = new lessc();
         // Importing should be done by the module so that modified times can be compared
         $compiler->importDisabled = TRUE;
         // Parse the LESS file and convert to CSS
         $css = $compiler->parse($less);
         // Minify the CSS if configured to do so
         if ($config->minify) {
             $css = LESS::minify($css);
         }
         // Write the CSS to the target file
         file_put_contents($target, $css);
     }
     // Return the path of the target for use in `HTML::style()`
     return $target;
 }
示例#23
0
 public function filterLoad(AssetInterface $asset)
 {
     $root = $asset->getSourceRoot();
     $path = $asset->getSourcePath();
     $lc = new \lessc();
     if (basename(getcwd()) === 'public') {
         $lc->setVariable('__assetpath__', '"../"');
     } else {
         $lc->setVariable('__assetpath__', '""');
     }
     if ($root && $path) {
         $lc->importDir = dirname($root . '/' . $path);
     }
     foreach ($this->loadPaths as $loadPath) {
         $lc->addImportDir($loadPath);
     }
     if ($this->formatter) {
         $lc->setFormatter($this->formatter);
     }
     if (null !== $this->preserveComments) {
         $lc->setPreserveComments($this->preserveComments);
     }
     $asset->setContent($lc->parse($asset->getContent(), $this->presets));
 }
示例#24
0
 /**
  * Execute lessphp on a .less file or a lessphp cache structure
  * 
  * The lessphp cache structure contains information about a specific
  * less file having been parsed. It can be used as a hint for future
  * calls to determine whether or not a rebuild is required.
  * 
  * The cache structure contains two important keys that may be used
  * externally:
  * 
  * compiled: The final compiled CSS
  * updated: The time (in seconds) the CSS was last compiled
  * 
  * The cache structure is a plain-ol' PHP associative array and can
  * be serialized and unserialized without a hitch.
  * 
  * @param mixed $in Input
  * @param bool $force Force rebuild?
  * @return array lessphp cache structure
  */
 public static function cexecute($in, $force = false)
 {
     // assume no root
     $root = null;
     if (is_string($in)) {
         $root = $in;
     } elseif (is_array($in) and isset($in['root'])) {
         if ($force or !isset($in['files'])) {
             // If we are forcing a recompile or if for some reason the
             // structure does not contain any file information we should
             // specify the root to trigger a rebuild.
             $root = $in['root'];
         } elseif (isset($in['files']) and is_array($in['files'])) {
             foreach ($in['files'] as $fname => $ftime) {
                 if (!file_exists($fname) or filemtime($fname) > $ftime) {
                     // One of the files we knew about previously has changed
                     // so we should look at our incoming root again.
                     $root = $in['root'];
                     break;
                 }
             }
         }
     } else {
         // TODO: Throw an exception? We got neither a string nor something
         // that looks like a compatible lessphp cache structure.
         return null;
     }
     if ($root !== null) {
         // If we have a root value which means we should rebuild.
         $less = new lessc($root);
         $out = array();
         $out['root'] = $root;
         $out['compiled'] = $less->parse();
         $out['files'] = $less->allParsedFiles();
         $out['updated'] = time();
         return $out;
     } else {
         // No changes, pass back the structure
         // we were given initially.
         return $in;
     }
 }
示例#25
0
error_reporting(E_ALL | E_STRICT);
// adds elasticsearch to the include path
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../lib'));
include '../autoload.php';
$content = '';
try {
    if ($_SERVER['REDIRECT_URL']) {
        $uri = parse_url($_SERVER['REDIRECT_URL']);
    } else {
        $uri = parse_url($_SERVER['REQUEST_URI']);
    }
    $xBoilerplate = xBoilerplate::getInstance()->pageStart($uri['path'], $_GET, __DIR__);
    if (substr($uri['path'], 1, 3) == 'css') {
        // Load css
        header('Content-Type: text/css');
        $cssContent = $xBoilerplate->loadCss(substr($uri['path'], 5));
        $less = new lessc();
        $content = $less->parse($cssContent);
    } else {
        if (substr($uri['path'], 1, 2) == 'js') {
            // load js
            header('Content-Type: text/javascript');
            $content = $xBoilerplate->loadJs(substr($uri['path'], 4));
        } else {
            $content = $xBoilerplate->render();
        }
    }
} catch (Exception $e) {
    error_log(print_r($e, true));
}
echo $content;
示例#26
0
 /**
      * old version incl. combining and using simple_dom_html
      *
      *
      *public static function processHtmlLEGACY ($body) {
         $html = str_get_html($body);
 
         if(!$html) {
             return $body;
         }
 
         $styles = $html->find("link[rel=stylesheet/less]");
 
         $stylesheetContents = array();
         $processedPaths = array();
 
         foreach ($styles as $style) {
 
             $media = $style->media;
             if(!$media) {
                 $media = "all";
             }
 
             $source = $style->href;
             $path = "";
             if (is_file(PIMCORE_ASSET_DIRECTORY . $source)) {
                 $path = PIMCORE_ASSET_DIRECTORY . $source;
             }
             else if (is_file(PIMCORE_DOCUMENT_ROOT . $source)) {
                 $path = PIMCORE_DOCUMENT_ROOT . $source;
             }
 
             // add the same file only one time
             if(in_array($path, $processedPaths)) {
                 continue;
             }
 
             if (is_file("file:/".$path)) {
 
                 $compiledContent = self::compile($path, $source);
 
                 $stylesheetContents[$media] .= $compiledContent . "\n";
                 $style->outertext = "";
 
                 $processedPaths[] = $path;
             }
         }
 
         // put compiled contents into single files, grouped by their media type
         if(count($stylesheetContents) > 0) {
             $head = $html->find("head",0);
             foreach ($stylesheetContents as $media => $content) {
                 $stylesheetPath = PIMCORE_TEMPORARY_DIRECTORY."/less_".md5($content).".css";
 
                 if(!is_file($stylesheetPath)) {
                     file_put_contents($stylesheetPath, $content);
                     @chmod($stylesheetPath, 0766);
                 }
 
                 $head->innertext = $head->innertext . "\n" . '<link rel="stylesheet" media="' . $media . '" type="text/css" href="' . str_replace(PIMCORE_DOCUMENT_ROOT,"",$stylesheetPath) . '" />'."\n";
             }
         }
 
         $body = $html->save();
 
         return $body;
     }*/
 public static function compile($path, $source = null)
 {
     $conf = \Pimcore\Config::getSystemConfig();
     $compiledContent = "";
     // check if the file is already compiled in the cache
     //$cacheKey = "less_file_" . md5_file($path);
     //if($contents = Pimcore_Model_Cache::load($cacheKey)) {
     //    return $contents;
     //}
     // use the original less compiler if configured
     if ($conf->outputfilters->lesscpath) {
         $output = array();
         exec($conf->outputfilters->lesscpath . " " . $path, $output);
         $compiledContent = implode(" ", $output);
         // add a comment to the css so that we know it's compiled by lessc
         if (!empty($compiledContent)) {
             $compiledContent = "\n\n/**** compiled with lessc (node.js) ****/\n\n" . $compiledContent;
         }
     }
     // use php implementation of lessc if it doesn't work
     if (empty($compiledContent)) {
         include_once "lessc.inc.php";
         $less = new \lessc();
         $less->importDir = dirname($path);
         $compiledContent = $less->parse(file_get_contents($path));
         // add a comment to the css so that we know it's compiled by lessphp
         $compiledContent = "\n\n/**** compiled with lessphp ****/\n\n" . $compiledContent;
     }
     if ($source) {
         // correct references inside the css
         $compiledContent = self::correctReferences($source, $compiledContent);
     }
     // put the compiled contents into the cache
     //Pimcore_Model_Cache::save($compiledContent, $cacheKey, array("less"));
     return $compiledContent;
 }
示例#27
0
 public static function ccompile($in, $out)
 {
     if (!is_file($out) || filemtime($in) > filemtime($out)) {
         $less = new lessc($in);
         file_put_contents($out, $less->parse());
         return true;
     }
     return false;
 }
/**
 * Generate CSS from the less file when changing colours.
 *
 * @access public
 * @return void
 */
function woocommerce_compile_less_styles()
{
    global $woocommerce;
    $colors = get_option('woocommerce_frontend_css_colors');
    $base_file = $woocommerce->plugin_path() . '/assets/css/woocommerce-base.less';
    $less_file = $woocommerce->plugin_path() . '/assets/css/woocommerce.less';
    $css_file = $woocommerce->plugin_path() . '/assets/css/woocommerce.css';
    // Write less file
    if (is_writable($base_file) && is_writable($css_file)) {
        // Colours changed - recompile less
        if (!class_exists('lessc')) {
            include_once 'includes/lessc.inc.php';
        }
        if (!class_exists('cssmin')) {
            include_once 'includes/cssmin.inc.php';
        }
        try {
            // Set default if colours not set
            if (!$colors['primary']) {
                $colors['primary'] = '#ad74a2';
            }
            if (!$colors['secondary']) {
                $colors['secondary'] = '#f7f6f7';
            }
            if (!$colors['highlight']) {
                $colors['highlight'] = '#85ad74';
            }
            if (!$colors['content_bg']) {
                $colors['content_bg'] = '#ffffff';
            }
            if (!$colors['subtext']) {
                $colors['subtext'] = '#777777';
            }
            // Write new color to base file
            $color_rules = "\n@primary: \t\t" . $colors['primary'] . ";\n@primarytext: \t" . woocommerce_light_or_dark($colors['primary'], 'desaturate(darken(@primary,50%),18%)', 'desaturate(lighten(@primary,50%),18%)') . ";\n\n@secondary: \t" . $colors['secondary'] . ";\n@secondarytext: " . woocommerce_light_or_dark($colors['secondary'], 'desaturate(darken(@secondary,60%),18%)', 'desaturate(lighten(@secondary,60%),18%)') . ";\n\n@highlight: \t" . $colors['highlight'] . ";\n@highlightext:\t" . woocommerce_light_or_dark($colors['highlight'], 'desaturate(darken(@highlight,60%),18%)', 'desaturate(lighten(@highlight,60%),18%)') . ";\n\n@contentbg:\t\t" . $colors['content_bg'] . ";\n\n@subtext:\t\t" . $colors['subtext'] . ";\n\t\t\t";
            file_put_contents($base_file, $color_rules);
            $less = new lessc($less_file);
            $compiled_css = $less->parse();
            $compiled_css = CssMin::minify($compiled_css);
            if ($compiled_css) {
                file_put_contents($css_file, $compiled_css);
            }
        } catch (exception $ex) {
            wp_die(__('Could not compile woocommerce.less:', 'woocommerce') . ' ' . $ex->getMessage());
        }
    }
}
示例#29
0
<?php

header('Content-Type: text/css');
require_once 'csf/csf.php';
CSF::add_library_path('extlib');
CSF::load_library('lessphp/lessc.inc');
$whitelist = array('style.less');
$infile = $_SERVER['QUERY_STRING'];
if (!in_array($infile, $whitelist)) {
    exit;
}
$lc = new lessc($infile);
echo $lc->parse();
示例#30
0
文件: test.php 项目: xdissent/lessphp
echo ($compiling ? "Compiling" : "Running") . " {$count} test" . ($count == 1 ? '' : 's') . ":\n";
function dump($msgs, $depth = 1)
{
    if (!is_array($msgs)) {
        $msgs = array($msgs);
    }
    foreach ($msgs as $m) {
        echo str_repeat("\t", $depth) . ' - ' . $m . "\n";
    }
}
$i = 1;
foreach ($tests as $test) {
    printf("\t[Test %04d/%04d] %s -> %s\n", $i, $count, basename($test['in']), basename($test['out']));
    try {
        ob_start();
        $parsed = trim($compiler->parse(file_get_contents($test['in'])));
        ob_end_clean();
    } catch (exception $e) {
        dump(array("Failed to compile input, reason:", $e->getMessage(), "Aborting"));
        break;
    }
    if ($compiling) {
        file_put_contents($test['out'], $parsed);
    } else {
        if (!is_file($test['out'])) {
            dump(array("Failed to find output file: {$test['out']}", "Maybe you forgot to compile tests?", "Aborting"));
            break;
        }
        $expected = trim(file_get_contents($test['out']));
        if ($expected != $parsed) {
            if ($showDiff) {