From ce1a5851668be00a766ccbed15e9d7bbb28cf242 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Tue, 9 Oct 2012 09:31:20 -0700 Subject: [PATCH] Make celerity be able to render full uris Summary: ...and use 'em in the phame blog case. Test Plan: viewed blog.phabricator.dev and it actually looked right! Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1373 Differential Revision: https://secure.phabricator.com/D3666 --- .../AphrontApplicationConfiguration.php | 4 +-- .../CelerityStaticResourceResponse.php | 31 ++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/aphront/configuration/AphrontApplicationConfiguration.php b/src/aphront/configuration/AphrontApplicationConfiguration.php index 1d785557ed..e9dabb6695 100644 --- a/src/aphront/configuration/AphrontApplicationConfiguration.php +++ b/src/aphront/configuration/AphrontApplicationConfiguration.php @@ -160,8 +160,8 @@ abstract class AphrontApplicationConfiguration { $path = '/phame/posts/'.trim($path, '/').'/'; } - // TODO - now we need to tell Celerity to render static resources with - // full URIs like secure.phabricator.org/rsrc/blahblah + $celerity = CelerityAPI::getStaticResourceResponse(); + $celerity->setUseFullURI(true); } list($controller, $uri_data) = $this->buildControllerForPath($path); diff --git a/src/infrastructure/celerity/CelerityStaticResourceResponse.php b/src/infrastructure/celerity/CelerityStaticResourceResponse.php index c9416f8e5d..93e1734bab 100644 --- a/src/infrastructure/celerity/CelerityStaticResourceResponse.php +++ b/src/infrastructure/celerity/CelerityStaticResourceResponse.php @@ -33,6 +33,7 @@ final class CelerityStaticResourceResponse { private $metadataBlock = 0; private $behaviors = array(); private $hasRendered = array(); + private $useFullURI = false; public function __construct() { if (isset($_REQUEST['__metablock__'])) { @@ -85,6 +86,19 @@ final class CelerityStaticResourceResponse { return $this; } + /** + * If set to true, Celerity will print full URIs (including the domain) + * for static resources. + */ + public function setUseFullURI($should) { + $this->useFullURI = $should; + return $this; + } + + private function shouldUseFullURI() { + return $this->useFullURI; + } + public function renderSingleResource($symbol) { $map = CelerityResourceMap::getInstance(); $resolved = $map->resolveResources(array($symbol)); @@ -119,18 +133,27 @@ final class CelerityStaticResourceResponse { } private function renderResource(array $resource) { + $uri = $this->getURI($resource['uri']); switch ($resource['type']) { case 'css': - $path = phutil_escape_html($resource['uri']); - return ''; + return ''; case 'js': - $path = phutil_escape_html($resource['uri']); - return ''; } throw new Exception("Unable to render resource."); } + private function getURI($path) { + $path = phutil_escape_html($path); + if ($this->shouldUseFullURI()) { + $uri = PhabricatorEnv::getCDNURI($path); + } else { + $uri = $path; + } + return $uri; + } + public function renderHTMLFooter() { $data = array(); if ($this->metadata) {