[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PholioRemarkupRule extends PhabricatorObjectRemarkupRule { 4 5 protected function getObjectNamePrefix() { 6 return 'M'; 7 } 8 9 protected function getObjectIDPattern() { 10 // Match "M123", "M123/456", and "M123/456/". Users can hit the latter 11 // forms when clicking comment anchors on a mock page. 12 return '[1-9]\d*(?:/[1-9]\d*/?)?'; 13 } 14 15 protected function getObjectHref($object, $handle, $id) { 16 $href = $handle->getURI(); 17 18 // If the ID has a `M123/456` component, link to that specific image. 19 $id = explode('/', $id); 20 if (isset($id[1])) { 21 $href = $href.'/'.$id[1].'/'; 22 } 23 24 return $href; 25 } 26 27 protected function loadObjects(array $ids) { 28 // Strip off any image ID components of the URI. 29 $map = array(); 30 foreach ($ids as $id) { 31 $map[head(explode('/', $id))][] = $id; 32 } 33 34 $viewer = $this->getEngine()->getConfig('viewer'); 35 $mocks = id(new PholioMockQuery()) 36 ->setViewer($viewer) 37 ->needCoverFiles(true) 38 ->needImages(true) 39 ->needTokenCounts(true) 40 ->withIDs(array_keys($map)) 41 ->execute(); 42 43 $results = array(); 44 foreach ($mocks as $mock) { 45 $ids = idx($map, $mock->getID(), array()); 46 foreach ($ids as $id) { 47 $results[$id] = $mock; 48 } 49 } 50 51 return $results; 52 } 53 54 protected function renderObjectEmbed($object, $handle, $options) { 55 $embed_mock = id(new PholioMockEmbedView()) 56 ->setMock($object); 57 58 if (strlen($options)) { 59 $parser = new PhutilSimpleOptions(); 60 $opts = $parser->parse(substr($options, 1)); 61 62 if (isset($opts['image'])) { 63 $images = array_unique( 64 explode('&', preg_replace('/\s+/', '', $opts['image']))); 65 66 $embed_mock->setImages($images); 67 } 68 } 69 70 return $embed_mock->render(); 71 } 72 73 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |