Example #1
0
 /**
  * Parse a fancy path definition into a path relative to the site's root,
  * respecting template overrides, suitable for inclusion of media files.
  * For example, media://com_foobar/css/test.css is parsed into
  * media/com_foobar/css/test.css if no override is found, or
  * templates/mytemplate/media/com_foobar/css/test.css if the current
  * template is called mytemplate and there's a media override for it.
  *
  * The valid protocols are:
  * media://		The media directory or a media override
  * site://		Path relative to site's root (no overrides)
  *
  * @param   string       $path       Fancy path
  * @param   boolean      $localFile  When true, it returns the local path, not the URL
  * @param   Application  $app        The application we're operating under
  *
  * @return  string  Parsed path
  */
 public static function parsePath($path, $localFile = false, $app = null)
 {
     $rootPath = $app->getContainer()->filesystemBase;
     if (!is_object($app)) {
         $app = Application::getInstance();
     }
     if ($localFile) {
         $url = rtrim($rootPath, DIRECTORY_SEPARATOR) . '/';
     } else {
         $url = Uri::base(false, $app->getContainer());
     }
     $altPaths = self::getAltPaths($path, $app);
     $ext = pathinfo($altPaths['normal'], PATHINFO_EXTENSION);
     // We have an uncompressed CSS / JS file. We must look for a minimised file.
     if (in_array($ext, array('css', 'js')) && strstr($altPaths['normal'], '.min.') === false) {
         $minFile = dirname($altPaths['normal']) . '/' . basename($altPaths['normal'], $ext) . 'min.' . $ext;
         $normalFileExists = @file_exists($altPaths['normal']);
         $minFileExists = @file_exists($rootPath . '/' . $minFile);
         // If debug is not enabled prefer the minimised file if it exists
         if ((!defined('AKEEBADEBUG') || !AKEEBADEBUG) && $minFileExists) {
             $altPaths['normal'] = $minFile;
         } elseif ($minFileExists && !$normalFileExists) {
             $altPaths['normal'] = $minFile;
         }
     }
     $filePath = $altPaths['normal'];
     // If AKEEBADEBUG is enabled prefer the debug path, if one exists
     if (defined('AKEEBADEBUG') && AKEEBADEBUG && isset($altPaths['debug'])) {
         if (file_exists($rootPath . '/' . $altPaths['debug'])) {
             $filePath = $altPaths['debug'];
         }
     } elseif (isset($altPaths['alternate'])) {
         // Look for a minimised file, if available
         if (in_array($ext, array('css', 'js')) && strstr($altPaths['alternate'], '.min.') === false) {
             $minFile = dirname($altPaths['alternate']) . '/' . basename($altPaths['alternate'], $ext) . 'min.' . $ext;
             if (@file_exists($rootPath . '/' . $minFile)) {
                 $altPaths['alternate'] = $minFile;
             }
         }
         if (file_exists($rootPath . '/' . $altPaths['alternate'])) {
             $filePath = $altPaths['alternate'];
         }
     }
     $url .= $filePath;
     return $url;
 }