/** * Gets the url and filename of a themed file * @param string $file_path * Basically the subpath of the file underneath the web or theme directory */ static function themedUrlAndFilename($file_path) { $filename = false; $theme_url = Pie_Uri::url(self::themeUrl()); $theme_urls = Pie_Config::get('pie', 'theme_urls', array(null)); if (!Pie_Valid::url($file_path)) { $c = count($theme_urls); if ($c > 1) { // At least two theme URLs have been loaded // Do the cascade for ($i = $c - 1; $i >= 0; --$i) { try { $filename = Pie_Uri::filenameFromUrl($theme_urls[$i] . '/' . $file_path); } catch (Exception $e) { continue; } if (file_exists($filename)) { $theme_url = $theme_urls[$i]; break; } } } $file_path = $theme_url . '/' . $file_path; } if (empty($filename)) { try { $filename = Pie_Uri::filenameFromUrl($file_path); } catch (Exception $e) { $filename = null; } } return array($file_path, $filename); }
/** * Returns a <style> tag with the content of all the stylesheets included inline * * @param $styles * If not empty, this associative array contains styles which will be * included at the end of the generated <style> tag. * @param string $slot_name * Optional. If provided, returns only the stylesheets added while filling this slot. * * @return string * the style tags and their contents inline */ static function stylesheetsInline($styles = array(), $slot_name = null) { $styles = self::stylesInline($slot_name, false); if (empty($styles) and empty(self::$stylesheets)) { return ''; } $return = "<style type='text/css'>\n"; if (!empty(self::$stylesheets)) { foreach (self::$stylesheets as $stylesheet) { $href = ''; $media = 'screen, print'; $type = 'text/css'; extract($stylesheet, EXTR_IF_EXISTS); $ob = new Pie_OutputBuffer(); if (Pie_Valid::url($href)) { try { include $href; } catch (Exception $e) { } } else { list($href, $filename) = Pie_Html::themedUrlAndFilename($href); try { Pie::includeFile($filename); } catch (Exception $e) { } } $stylesheet = "\n/* Included inline from {$href} */\n" . $ob->getClean(); $return .= "{$stylesheet}\n"; } } $return .= "/* Included inline from Pie_Response::stylesInline() */\n"; $return .= $styles; $return .= "\n</style>"; return $return; }
/** * Returns what the local filename of a local URL would typically be without any routing. * If not found under docroot, also checks various aliases. * * @param string $url * The url to translate, whether local or an absolute url beginning with the base URL * @return string * The complete filename of the file or directory. * It may not point to an actual file or directory, so use file_exists() or realpath();s */ static function filenamefromUrl($url) { if (Pie_Valid::url($url)) { // This is an absolute URL. Get only the part after the base URL // Run it through proxies first $url = self::proxyDestination($url); $local_url = Pie_Request::tail($url); } else { $local_url = $url; } $parts = explode('?', $local_url); $local_url = $parts[0]; if ($local_url == '' || $local_url[0] != '/') { $local_url = '/' . $local_url; } // Try various aliases first $aliases = Pie_Config::get('pie', 'aliases', array()); foreach ($aliases as $alias => $path) { $alias_len = strlen($alias); if (substr($local_url, 0, $alias_len) == $alias) { return $path . substr($local_url, $alias_len); } } // Otherwise, we should use the document root. $docroot_dir = self::documentRoot(); return $docroot_dir . $local_url; }