2011-06-27 08:57:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group markup
|
|
|
|
*/
|
2013-02-26 23:57:41 +01:00
|
|
|
final class PhabricatorPasteRemarkupRule
|
2013-02-27 16:18:30 +01:00
|
|
|
extends PhabricatorRemarkupRuleObject {
|
2011-06-27 08:57:43 +02:00
|
|
|
|
|
|
|
protected function getObjectNamePrefix() {
|
|
|
|
return 'P';
|
|
|
|
}
|
|
|
|
|
2013-02-27 16:18:30 +01:00
|
|
|
protected function loadObjects(array $ids) {
|
|
|
|
$viewer = $this->getEngine()->getConfig('viewer');
|
|
|
|
|
|
|
|
return id(new PhabricatorPasteQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs($ids)
|
2013-03-13 14:44:27 +01:00
|
|
|
->needContent(true)
|
2013-02-27 16:18:30 +01:00
|
|
|
->execute();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-03-13 14:44:27 +01:00
|
|
|
protected function renderObjectEmbed($object, $handle, $options) {
|
|
|
|
$embed_paste = id(new PasteEmbedView())
|
|
|
|
->setPaste($object)
|
|
|
|
->setHandle($handle);
|
|
|
|
|
2013-03-14 17:32:02 +01:00
|
|
|
if (strlen($options)) {
|
|
|
|
$parser = new PhutilSimpleOptions();
|
|
|
|
$opts = $parser->parse(substr($options, 1));
|
|
|
|
|
|
|
|
foreach ($opts as $key => $value) {
|
|
|
|
if ($key == 'lines') {
|
|
|
|
// placeholder for now
|
|
|
|
} else if ($key == 'highlight') {
|
|
|
|
$highlights = explode('&', preg_replace('/\s+/', '', $value));
|
|
|
|
|
|
|
|
$to_highlight = array();
|
|
|
|
foreach ($highlights as $highlight) {
|
|
|
|
$highlight = explode('-', $highlight);
|
|
|
|
|
|
|
|
if (!empty($highlight)) {
|
|
|
|
sort($highlight);
|
|
|
|
$to_highlight = array_merge(
|
|
|
|
$to_highlight,
|
|
|
|
range(head($highlight), last($highlight)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$embed_paste->setHighlights(array_unique($to_highlight));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-03-13 14:44:27 +01:00
|
|
|
return $embed_paste->render();
|
|
|
|
|
|
|
|
}
|
2011-06-27 08:57:43 +02:00
|
|
|
}
|