Exemplo n.º 1
0
 /**
  * Compile a LESS file into CSS and add it to the page generated by the CMS.
  * This method has integrated cache support. The compiled LESS files will be
  * written to the media/lib_fof/compiled directory of your site. If the file
  * cannot be written we will use the $altPath, if specified
  *
  * @param   string   $path        A fancy path definition understood by parsePath pointing to the source LESS file
  * @param   string   $altPath     A fancy path definition understood by parsePath pointing to a precompiled CSS file,
  *                                used when we can't write the generated file to the output directory
  * @param   boolean  $returnPath  Return the URL of the generated CSS file but do not include it. If it can't be
  *                                generated, false is returned and the alt files are not included
  *
  * @see F0FTemplateUtils::parsePath
  *
  * @since 2.0
  *
  * @return  mixed  True = successfully included generated CSS, False = the alternate CSS file was used, null = the source file does not exist
  */
 public static function addLESS($path, $altPath = null, $returnPath = false)
 {
     // Does the cache directory exists and is writeable
     static $sanityCheck = null;
     // Get the local LESS file
     $localFile = self::parsePath($path, true);
     $filesystem = F0FPlatform::getInstance()->getIntegrationObject('filesystem');
     $platformDirs = F0FPlatform::getInstance()->getPlatformBaseDirs();
     if (is_null($sanityCheck)) {
         // Make sure the cache directory exists
         if (!is_dir($platformDirs['public'] . '/media/lib_fof/compiled/')) {
             $sanityCheck = $filesystem->folderCreate($platformDirs['public'] . '/media/lib_fof/compiled/');
         } else {
             $sanityCheck = true;
         }
     }
     // No point continuing if the source file is not there or we can't write to the cache
     if (!$sanityCheck || !is_file($localFile)) {
         if (!$returnPath) {
             if (is_string($altPath)) {
                 self::addCSS($altPath);
             } elseif (is_array($altPath)) {
                 foreach ($altPath as $anAltPath) {
                     self::addCSS($anAltPath);
                 }
             }
         }
         return false;
     }
     // Get the source file's unique ID
     $id = md5(filemtime($localFile) . filectime($localFile) . $localFile);
     // Get the cached file path
     $cachedPath = $platformDirs['public'] . '/media/lib_fof/compiled/' . $id . '.css';
     // Get the LESS compiler
     $lessCompiler = new F0FLess();
     $lessCompiler->formatterName = 'compressed';
     // Should I add an alternative import path?
     $altFiles = self::getAltPaths($path);
     if (isset($altFiles['alternate'])) {
         $currentLocation = realpath(dirname($localFile));
         $normalLocation = realpath(dirname($altFiles['normal']));
         $alternateLocation = realpath(dirname($altFiles['alternate']));
         if ($currentLocation == $normalLocation) {
             $lessCompiler->importDir = array($alternateLocation, $currentLocation);
         } else {
             $lessCompiler->importDir = array($currentLocation, $normalLocation);
         }
     }
     // Compile the LESS file
     $lessCompiler->checkedCompile($localFile, $cachedPath);
     // Add the compiled CSS to the page
     $base_url = rtrim(F0FPlatform::getInstance()->URIbase(), '/');
     if (substr($base_url, -14) == '/administrator') {
         $base_url = substr($base_url, 0, -14);
     }
     $url = $base_url . '/media/lib_fof/compiled/' . $id . '.css';
     if ($returnPath) {
         return $url;
     } else {
         $document = F0FPlatform::getInstance()->getDocument();
         if ($document instanceof JDocument) {
             if (method_exists($document, 'addStyleSheet')) {
                 $document->addStyleSheet($url);
             }
         }
         return true;
     }
 }
Exemplo n.º 2
0
Arquivo: parser.php Projeto: 01J/topm
 /**
  * Advance counter to next occurrence of $what
  * $until - don't include $what in advance
  * $allowNewline, if string, will be used as valid char set
  *
  * @param   [type]   $what          [description]
  * @param   [type]   &$out          [description]
  * @param   boolean  $until         [description]
  * @param   boolean  $allowNewline  [description]
  *
  * @return  boolean
  */
 protected function to($what, &$out, $until = false, $allowNewline = false)
 {
     if (is_string($allowNewline)) {
         $validChars = $allowNewline;
     } else {
         $validChars = $allowNewline ? "." : "[^\n]";
     }
     if (!$this->match('(' . $validChars . '*?)' . F0FLess::preg_quote($what), $m, !$until)) {
         return false;
     }
     if ($until) {
         // Give back $what
         $this->count -= strlen($what);
     }
     $out = $m[1];
     return true;
 }