[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phame/controller/ -> PhameResourceController.php (source)

   1  <?php
   2  
   3  final class PhameResourceController extends CelerityResourceController {
   4  
   5    private $id;
   6    private $hash;
   7    private $name;
   8    private $root;
   9    private $celerityResourceMap;
  10  
  11    public function getCelerityResourceMap() {
  12      return $this->celerityResourceMap;
  13    }
  14  
  15    public function willProcessRequest(array $data) {
  16      $this->id = $data['id'];
  17      $this->hash = $data['hash'];
  18      $this->name = $data['name'];
  19    }
  20  
  21    public function processRequest() {
  22      $request = $this->getRequest();
  23      $user = $request->getUser();
  24  
  25      // We require a visible blog associated with a given skin to serve
  26      // resources, so you can't go fishing around where you shouldn't be.
  27      // However, since these resources may be served off a CDN domain, we're
  28      // bypassing the actual policy check. The blog needs to exist, but you
  29      // don't necessarily need to be able to see it in order to see static
  30      // resources on it.
  31  
  32      $blog = id(new PhameBlogQuery())
  33        ->setViewer(PhabricatorUser::getOmnipotentUser())
  34        ->withIDs(array($this->id))
  35        ->executeOne();
  36      if (!$blog) {
  37        return new Aphront404Response();
  38      }
  39  
  40      $skin = $blog->getSkinRenderer($request);
  41      $spec = $skin->getSpecification();
  42  
  43      $resources = new PhameCelerityResources();
  44      $resources->setSkin($spec);
  45  
  46      $this->root = $spec->getRootDirectory();
  47      $this->celerityResourceMap = new CelerityResourceMap($resources);
  48  
  49      return $this->serveResource($this->name);
  50    }
  51  
  52    protected function buildResourceTransformer() {
  53      $xformer = new CelerityResourceTransformer();
  54      $xformer->setMinify(false);
  55      $xformer->setTranslateURICallback(array($this, 'translateResourceURI'));
  56      return $xformer;
  57    }
  58  
  59    public function translateResourceURI(array $matches) {
  60      $uri = trim($matches[1], "'\" \r\t\n");
  61  
  62      if (Filesystem::pathExists($this->root.$uri)) {
  63        $hash = filemtime($this->root.$uri);
  64      } else {
  65        $hash = '-';
  66      }
  67  
  68      $uri = '/phame/r/'.$this->id.'/'.$hash.'/'.$uri;
  69      return 'url('.$uri.')';
  70    }
  71  
  72  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1