1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Always use absolute URIs for static resources

Summary: I think this is simpler and better than making them conditional. In properly configured installs this should have no impact (they already use a CDN URI). In not-quite-properly configured installs this will add a trivial, highly-compressible number of bytes to the source. In all cases we have less code.

Test Plan: Loaded some pages, everything worked.

Reviewers: btrahan, vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D3709
This commit is contained in:
epriestley 2012-10-16 09:44:53 -07:00
parent 1a63938b33
commit b9f84ebba8
2 changed files with 16 additions and 32 deletions

View file

@ -165,9 +165,6 @@ abstract class AphrontApplicationConfiguration {
// do crazy stuff here if it wants.
$path = '/phame/live/'.$blog->getID().'/'.$path;
$celerity = CelerityAPI::getStaticResourceResponse();
$celerity->setUseFullURI(true);
}
list($controller, $uri_data) = $this->buildControllerForPath($path);

View file

@ -33,7 +33,6 @@ final class CelerityStaticResourceResponse {
private $metadataBlock = 0;
private $behaviors = array();
private $hasRendered = array();
private $useFullURI = false;
public function __construct() {
if (isset($_REQUEST['__metablock__'])) {
@ -86,19 +85,6 @@ 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));
@ -129,31 +115,32 @@ final class CelerityStaticResourceResponse {
$output[] = $this->renderResource($resource);
}
return implode("\n", $output);
return implode("\n", $output)."\n";
}
private function renderResource(array $resource) {
$uri = $this->getURI($resource['uri']);
$uri = PhabricatorEnv::getCDNURI($resource['uri']);
switch ($resource['type']) {
case 'css':
return '<link rel="stylesheet" type="text/css" href="'.$uri.'" />';
return phutil_render_tag(
'link',
array(
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => $uri,
));
case 'js':
return '<script type="text/javascript" src="'.$uri.'">'.
'</script>';
return phutil_render_tag(
'script',
array(
'type' => 'text/javascript',
'src' => $uri,
),
'');
}
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) {