2013-02-26 23:59:31 +01:00
|
|
|
<?php
|
|
|
|
|
2014-08-04 16:55:43 +02:00
|
|
|
final class PholioRemarkupRule extends PhabricatorObjectRemarkupRule {
|
2013-02-26 23:59:31 +01:00
|
|
|
|
|
|
|
protected function getObjectNamePrefix() {
|
|
|
|
return 'M';
|
|
|
|
}
|
|
|
|
|
2014-06-15 21:56:11 +02:00
|
|
|
protected function getObjectIDPattern() {
|
|
|
|
// Match "M123", "M123/456", and "M123/456/". Users can hit the latter
|
|
|
|
// forms when clicking comment anchors on a mock page.
|
|
|
|
return '[1-9]\d*(?:/[1-9]\d*/?)?';
|
|
|
|
}
|
|
|
|
|
2015-05-04 23:33:00 +02:00
|
|
|
protected function getObjectHref(
|
|
|
|
$object,
|
|
|
|
PhabricatorObjectHandle $handle,
|
|
|
|
$id) {
|
|
|
|
|
2014-06-15 21:56:11 +02:00
|
|
|
$href = $handle->getURI();
|
|
|
|
|
|
|
|
// If the ID has a `M123/456` component, link to that specific image.
|
|
|
|
$id = explode('/', $id);
|
|
|
|
if (isset($id[1])) {
|
|
|
|
$href = $href.'/'.$id[1].'/';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $href;
|
|
|
|
}
|
|
|
|
|
2013-02-26 23:59:31 +01:00
|
|
|
protected function loadObjects(array $ids) {
|
2014-06-15 21:56:11 +02:00
|
|
|
// Strip off any image ID components of the URI.
|
|
|
|
$map = array();
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
$map[head(explode('/', $id))][] = $id;
|
|
|
|
}
|
|
|
|
|
2013-02-26 23:59:31 +01:00
|
|
|
$viewer = $this->getEngine()->getConfig('viewer');
|
2014-06-15 21:56:11 +02:00
|
|
|
$mocks = id(new PholioMockQuery())
|
2013-02-26 23:59:31 +01:00
|
|
|
->setViewer($viewer)
|
2014-06-14 21:11:19 +02:00
|
|
|
->needCoverFiles(true)
|
2013-03-07 17:23:40 +01:00
|
|
|
->needImages(true)
|
|
|
|
->needTokenCounts(true)
|
2014-06-15 21:56:11 +02:00
|
|
|
->withIDs(array_keys($map))
|
2013-02-26 23:59:31 +01:00
|
|
|
->execute();
|
2014-06-15 21:56:11 +02:00
|
|
|
|
|
|
|
$results = array();
|
|
|
|
foreach ($mocks as $mock) {
|
|
|
|
$ids = idx($map, $mock->getID(), array());
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
$results[$id] = $mock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
2013-02-26 23:59:31 +01:00
|
|
|
}
|
|
|
|
|
2015-05-04 23:33:00 +02:00
|
|
|
protected function renderObjectEmbed(
|
|
|
|
$object,
|
|
|
|
PhabricatorObjectHandle $handle,
|
|
|
|
$options) {
|
|
|
|
|
2013-03-07 17:23:40 +01:00
|
|
|
$embed_mock = id(new PholioMockEmbedView())
|
|
|
|
->setMock($object);
|
|
|
|
|
2013-03-14 17:38:56 +01:00
|
|
|
if (strlen($options)) {
|
|
|
|
$parser = new PhutilSimpleOptions();
|
|
|
|
$opts = $parser->parse(substr($options, 1));
|
|
|
|
|
|
|
|
if (isset($opts['image'])) {
|
|
|
|
$images = array_unique(
|
|
|
|
explode('&', preg_replace('/\s+/', '', $opts['image'])));
|
|
|
|
|
|
|
|
$embed_mock->setImages($images);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-07 17:23:40 +01:00
|
|
|
return $embed_mock->render();
|
|
|
|
}
|
|
|
|
|
2013-02-26 23:59:31 +01:00
|
|
|
}
|