@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * Include a CSS or JS static resource by name. This function records a
5 * dependency for the current page, so when a response is generated it can be
6 * included. You can call this method from any context, and it is recommended
7 * you invoke it as close to the actual dependency as possible so that page
8 * dependencies are minimized.
9 *
10 * For more information, see @{article:Adding New CSS and JS}.
11 *
12 * @param string $symbol Name of the celerity module to include. This is
13 * whatever you annotated as "@provides" in the file.
14 * @param string $source_name (optional)
15 * @return void
16 */
17function require_celerity_resource($symbol, $source_name = 'phabricator') {
18 $response = CelerityAPI::getStaticResourceResponse();
19 $response->requireResource($symbol, $source_name);
20}
21
22
23/**
24 * Generate a node ID which is guaranteed to be unique for the current page,
25 * even across Ajax requests. You should use this method to generate IDs for
26 * nodes which require a uniqueness guarantee.
27 *
28 * @return string A string appropriate for use as an 'id' attribute on a DOM
29 * node. It is guaranteed to be unique for the current page, even
30 * if the current request is a subsequent Ajax request.
31 */
32function celerity_generate_unique_node_id() {
33 static $uniq = 0;
34 $response = CelerityAPI::getStaticResourceResponse();
35 $block = $response->getMetadataBlock();
36
37 return 'UQ'.$block.'_'.($uniq++);
38}
39
40
41/**
42 * Get the versioned URI for a raw resource, like an image.
43 *
44 * @param string $resource Path to the raw image.
45 * @param string $source (optional) Defaults to 'phabricator'
46 * @return string Versioned path to the image, if one is available.
47 */
48function celerity_get_resource_uri($resource, $source = 'phabricator') {
49 $resource = ltrim($resource, '/');
50
51 $map = CelerityResourceMap::getNamedInstance($source);
52 $response = CelerityAPI::getStaticResourceResponse();
53 return $response->getURI($map, $resource);
54}