@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 91 lines 2.2 kB view raw
1<?php 2 3final class PholioRemarkupRule extends PhabricatorObjectRemarkupRule { 4 5 protected function getObjectNamePrefix() { 6 return 'M'; 7 } 8 9 /** 10 * @return string Regex which defines a valid object ID 11 */ 12 protected function getObjectIDPattern() { 13 // Match "M123", "M123/456", and "M123/456/". Users can hit the latter 14 // forms when clicking comment anchors on a mock page. 15 return '[1-9]\d*(?:/[1-9]\d*/?)?'; 16 } 17 18 protected function getObjectHref( 19 $object, 20 PhabricatorObjectHandle $handle, 21 $id) { 22 23 $href = $handle->getURI(); 24 25 // If the ID has a `M123/456` component, link to that specific image. 26 $id = explode('/', $id); 27 if (isset($id[1])) { 28 $href = $href.'/'.$id[1].'/'; 29 } 30 31 if ($this->getEngine()->getConfig('uri.full')) { 32 $href = PhabricatorEnv::getURI($href); 33 } 34 35 return $href; 36 } 37 38 protected function loadObjects(array $ids) { 39 // Strip off any image ID components of the URI. 40 $map = array(); 41 foreach ($ids as $id) { 42 $map[head(explode('/', $id))][] = $id; 43 } 44 45 $viewer = $this->getEngine()->getConfig('viewer'); 46 $mocks = id(new PholioMockQuery()) 47 ->setViewer($viewer) 48 ->needCoverFiles(true) 49 ->needImages(true) 50 ->needTokenCounts(true) 51 ->withIDs(array_keys($map)) 52 ->execute(); 53 54 $results = array(); 55 foreach ($mocks as $mock) { 56 $ids = idx($map, $mock->getID(), array()); 57 foreach ($ids as $id) { 58 $results[$id] = $mock; 59 } 60 } 61 62 return $results; 63 } 64 65 protected function renderObjectEmbed( 66 $object, 67 PhabricatorObjectHandle $handle, 68 $options) { 69 70 $viewer = $this->getEngine()->getConfig('viewer'); 71 72 $embed_mock = id(new PholioMockEmbedView()) 73 ->setUser($viewer) 74 ->setMock($object); 75 76 if (strlen($options)) { 77 $parser = new PhutilSimpleOptions(); 78 $opts = $parser->parse(substr($options, 1)); 79 80 if (isset($opts['image'])) { 81 $images = array_unique( 82 explode('&', preg_replace('/\s+/', '', $opts['image']))); 83 84 $embed_mock->setImages($images); 85 } 86 } 87 88 return $embed_mock->render(); 89 } 90 91}