/** * Get the versioned URI for a raw resource, like an image. * * @param string Path to the raw image. * @return string Versioned path to the image, if one is available. */ function celerity_get_resource_uri($resource, $source = 'phabricator') { $resource = ltrim($resource, '/'); $map = CelerityResourceMap::getNamedInstance($source); $response = CelerityAPI::getStaticResourceResponse(); return $response->getURI($map, $resource); }
public function processRequest() { $root = dirname(phutil_get_library_root('phabricator')); require_once $root . '/support/phame/libskin.php'; $this->cssResources = array(); $css = $this->getPath('css/'); if (Filesystem::pathExists($css)) { foreach (Filesystem::listDirectory($css) as $path) { if (!preg_match('/.css$/', $path)) { continue; } $this->cssResources[] = phutil_tag('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $this->getResourceURI('css/' . $path))); } } $map = CelerityResourceMap::getNamedInstance('phabricator'); $resource_symbol = 'syntax-highlighting-css'; $resource_uri = $map->getURIForSymbol($resource_symbol); $this->cssResources[] = phutil_tag('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => PhabricatorEnv::getCDNURI($resource_uri))); $this->cssResources = phutil_implode_html("\n", $this->cssResources); $request = $this->getRequest(); // Render page parts in order so the templates execute in order, if we're // using templates. $header = $this->renderHeader(); $content = $this->renderContent($request); $footer = $this->renderFooter(); if (!$content) { $content = $this->render404Page(); } $content = array($header, $content, $footer); $response = new AphrontWebpageResponse(); $response->setContent(phutil_implode_html("\n", $content)); return $response; }
public function buildAjaxResponse($payload, $error = null) { $response = array('error' => $error, 'payload' => $payload); if ($this->metadata) { $response['javelin_metadata'] = $this->metadata; $this->metadata = array(); } if ($this->behaviors) { $response['javelin_behaviors'] = $this->behaviors; $this->behaviors = array(); } $this->resolveResources(); $resources = array(); foreach ($this->packaged as $source_name => $resource_names) { $map = CelerityResourceMap::getNamedInstance($source_name); foreach ($resource_names as $resource_name) { $resources[] = $this->getURI($map, $resource_name); } } if ($resources) { $response['javelin_resources'] = $resources; } return $response; }
public function getCelerityResourceMap() { return CelerityResourceMap::getNamedInstance($this->library); }
public function lintPath($path) { if ($this->shouldIgnorePath($path)) { return; } if (!$this->symbolsBinary) { if (!$this->haveWarnedAboutBinary) { $this->haveWarnedAboutBinary = true; // TODO: Write build documentation for the Javelin binaries and point // the user at it. $this->raiseLintAtLine(1, 0, self::LINT_MISSING_BINARY, pht("The '%s' binary in the Javelin project is not available in %s, " . "so the Javelin linter can't run. This isn't a big concern, " . "but means some Javelin problems can't be automatically detected.", 'javelinsymbols', '$PATH')); } return; } list($uses, $installs) = $this->getUsedAndInstalledSymbolsForPath($path); foreach ($uses as $symbol => $line) { $parts = explode('.', $symbol); foreach ($parts as $part) { if ($part[0] == '_' && $part[1] != '_') { $base = implode('.', array_slice($parts, 0, 2)); if (!array_key_exists($base, $installs)) { $this->raiseLintAtLine($line, 0, self::LINT_PRIVATE_ACCESS, pht("This file accesses private symbol '%s' across file " . "boundaries. You may only access private members and methods " . "from the file where they are defined.", $symbol)); } break; } } } $external_classes = array(); foreach ($uses as $symbol => $line) { $parts = explode('.', $symbol); $class = implode('.', array_slice($parts, 0, 2)); if (!array_key_exists($class, $external_classes) && !array_key_exists($class, $installs)) { $external_classes[$class] = $line; } } $celerity = CelerityResourceMap::getNamedInstance('phabricator'); $path = preg_replace('@^externals/javelinjs/src/@', 'webroot/rsrc/js/javelin/', $path); $need = $external_classes; $resource_name = substr($path, strlen('webroot/')); $requires = $celerity->getRequiredSymbolsForName($resource_name); if (!$requires) { $requires = array(); } foreach ($requires as $key => $requires_symbol) { $requires_name = $celerity->getResourceNameForSymbol($requires_symbol); if ($requires_name === null) { $this->raiseLintAtLine(0, 0, self::LINT_UNKNOWN_DEPENDENCY, pht("This file %s component '%s', but it does not exist. " . "You may need to rebuild the Celerity map.", '@requires', $requires_symbol)); unset($requires[$key]); continue; } if (preg_match('/\\.css$/', $requires_name)) { // If JS requires CSS, just assume everything is fine. unset($requires[$key]); } else { $symbol_path = 'webroot/' . $requires_name; list($ignored, $req_install) = $this->getUsedAndInstalledSymbolsForPath($symbol_path); if (array_intersect_key($req_install, $external_classes)) { $need = array_diff_key($need, $req_install); unset($requires[$key]); } } } foreach ($need as $class => $line) { $this->raiseLintAtLine($line, 0, self::LINT_MISSING_DEPENDENCY, pht("This file uses '%s' but does not @requires the component " . "which installs it. You may need to rebuild the Celerity map.", $class)); } foreach ($requires as $component) { $this->raiseLintAtLine(0, 0, self::LINT_UNNECESSARY_DEPENDENCY, pht("This file %s component '%s' but does not use anything it provides.", '@requires', $component)); } }
protected function getTail() { $request = $this->getRequest(); $user = $request->getUser(); $tail = array(parent::getTail()); $response = CelerityAPI::getStaticResourceResponse(); if (PhabricatorEnv::getEnvConfig('notification.enabled')) { if ($user && $user->isLoggedIn()) { $aphlict_object_id = celerity_generate_unique_node_id(); $aphlict_container_id = celerity_generate_unique_node_id(); $client_uri = PhabricatorEnv::getEnvConfig('notification.client-uri'); $client_uri = new PhutilURI($client_uri); if ($client_uri->getDomain() == 'localhost') { $this_host = $this->getRequest()->getHost(); $this_host = new PhutilURI('http://' . $this_host . '/'); $client_uri->setDomain($this_host->getDomain()); } $map = CelerityResourceMap::getNamedInstance('phabricator'); $swf_uri = $response->getURI($map, 'rsrc/swf/aphlict.swf', true); $enable_debug = PhabricatorEnv::getEnvConfig('notification.debug'); $subscriptions = $this->pageObjects; if ($user) { $subscriptions[] = $user->getPHID(); } Javelin::initBehavior('aphlict-listen', array('id' => $aphlict_object_id, 'containerID' => $aphlict_container_id, 'server' => $client_uri->getDomain(), 'port' => $client_uri->getPort(), 'debug' => $enable_debug, 'swfURI' => $swf_uri, 'pageObjects' => array_fill_keys($this->pageObjects, true), 'subscriptions' => $subscriptions)); $tail[] = phutil_tag('div', array('id' => $aphlict_container_id, 'style' => 'position: absolute; width: 0; height: 0; overflow: hidden;'), ''); } } $tail[] = $response->renderHTMLFooter(); return $tail; }