예제 #1
0
파일: lesscache.php 프로젝트: Tommar/remate
 public static function Cache(&$less_files, $parser_options = array())
 {
     //prepare the processor
     if (!class_exists('Less_Parser')) {
         include_once 'Less.php';
     }
     $parser = new Less_Parser($parser_options);
     $parser->SetCacheDir(self::$cache_dir);
     $parser->SetImportDirs(self::$import_dirs);
     // combine files
     try {
         foreach ($less_files as $file_path => $uri_or_less) {
             //treat as less markup if there are newline characters
             if (strpos($uri_or_less, "\n") !== false) {
                 $parser->Parse($uri_or_less);
                 continue;
             }
             $parser->ParseFile($file_path, $uri_or_less);
         }
         $compiled = $parser->getCss();
     } catch (Exception $e) {
         self::$error = $e;
         return false;
     }
     $less_files = $parser->allParsedFiles();
     return $compiled;
 }
예제 #2
0
 /**
  * Returns LESS compiler set up for use with MediaWiki
  *
  * @since 1.22
  * @since 1.26 added $extraVars parameter
  * @param Config $config
  * @param array $extraVars Associative array of extra (i.e., other than the
  *   globally-configured ones) that should be used for compilation.
  * @throws MWException
  * @return Less_Parser
  */
 public static function getLessCompiler(Config $config, $extraVars = array())
 {
     // When called from the installer, it is possible that a required PHP extension
     // is missing (at least for now; see bug 47564). If this is the case, throw an
     // exception (caught by the installer) to prevent a fatal error later on.
     if (!class_exists('Less_Parser')) {
         throw new MWException('MediaWiki requires the less.php parser');
     }
     $parser = new Less_Parser();
     $parser->ModifyVars(array_merge(self::getLessVars($config), $extraVars));
     $parser->SetImportDirs(array_fill_keys($config->get('ResourceLoaderLESSImportPaths'), ''));
     $parser->SetOption('relativeUrls', false);
     $parser->SetCacheDir($config->get('CacheDirectory') ?: wfTempDir());
     return $parser;
 }
예제 #3
0
 /**
  * Handle the processing of multiple less files into css
  *
  * @return mixed Compiled css string or false
  *
  */
 static function ParseLess(&$less_files)
 {
     global $dataDir;
     $compiled = false;
     // don't use less if the memory limit is less than 64M
     $limit = @ini_get('memory_limit');
     if ($limit) {
         $limit = \gp\tool::getByteValue($limit);
         //if less than 64M, disable less compiler if we can't increase
         if ($limit < 67108864 && @ini_set('memory_limit', '96M') === false) {
             if (\gp\tool::LoggedIn()) {
                 msg('LESS compilation disabled. Please increase php\'s memory_limit');
             }
             return false;
             //if less than 96M, try to increase
         } elseif ($limit < 100663296) {
             @ini_set('memory_limit', '96M');
         }
     }
     //compiler options
     $options = array();
     //prepare the compiler
     includeFile('thirdparty/less.php/Less.php');
     $parser = new \Less_Parser($options);
     $import_dirs[$dataDir] = \gp\tool::GetDir('/');
     $parser->SetImportDirs($import_dirs);
     $parser->cache_method = 'php';
     $parser->SetCacheDir($dataDir . '/data/_cache');
     // combine files
     try {
         foreach ($less_files as $less) {
             //treat as less markup if there are newline characters
             if (strpos($less, "\n") !== false) {
                 $parser->Parse($less);
                 continue;
             }
             // handle relative and absolute paths
             if (!empty($dataDir) && strpos($less, $dataDir) === false) {
                 $relative = $less;
                 $less = $dataDir . '/' . ltrim($less, '/');
             } else {
                 $relative = substr($less, strlen($dataDir));
             }
             $parser->ParseFile($less, \gp\tool::GetDir(dirname($relative)));
         }
         $compiled = $parser->getCss();
     } catch (Exception $e) {
         if (\gp\tool::LoggedIn()) {
             msg('LESS Compile Failed: ' . $e->getMessage());
         }
         return false;
     }
     // significant difference in used memory 15,000,000 -> 6,000,000. Max still @ 15,000,000
     if (function_exists('gc_collect_cycles')) {
         gc_collect_cycles();
     }
     $less_files = $parser->allParsedFiles();
     return $compiled;
 }