/** * Gets the url and filename of a themed file * @method themedUrlAndFilename * @static * @param {string} $filePath Basically the subpath of the file underneath the web or theme directory * @param {boolean} [$ignoreEnvironment=false] If true, doesn't apply environment transformations * @return {array} A two-element array containing the url and filename */ static function themedUrlAndFilename($filePath, $ignoreEnvironment = false) { /** * @event Q/themedUrlAndFilename {before} * @param {string} file_path * @return {array} */ $result = Q::event('Q/themedUrlAndFilename', compact('file_path'), 'before'); if ($result) { return $result; } if (!$ignoreEnvironment and $environment = Q_Config::get('Q', 'environment', false)) { if ($info = Q_Config::get('Q', 'environments', $environment, false)) { if (!empty($info['files'][$filePath])) { $filePath = $info['files'][$filePath]; } } } $filename = false; if (Q_Valid::url($filePath)) { $url = $filePath; } else { $theme = Q_Uri::url(self::themeUrl()); $themes = self::$themes; $c = count($themes); if ($c > 1) { // At least two theme URLs have been loaded // Do the cascade for ($i = $c - 1; $i >= 0; --$i) { try { $filename = Q_Uri::filenameFromUrl($themes[$i] . '/' . $filePath); } catch (Exception $e) { continue; } if ($filename and file_exists($filename)) { $theme = $themes[$i]; break; } } } $url = $theme . '/' . $filePath; } if (empty($filename)) { try { $filename = Q_Uri::filenameFromUrl($url); } catch (Exception $e) { $filename = null; } } $url = Q_Uri::cachedUrl($url); return array($url, $filename); }