2011-06-27 08:57:43 +02:00
|
|
|
<?php
|
|
|
|
|
2014-07-10 00:12:48 +02:00
|
|
|
final class PhabricatorPasteRemarkupRule 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') {
|
2013-03-14 18:51:34 +01:00
|
|
|
$embed_paste->setLines(preg_replace('/[^0-9]/', '', $value));
|
2013-03-14 17:32:02 +01:00
|
|
|
} else if ($key == 'highlight') {
|
2013-03-14 18:51:34 +01:00
|
|
|
$highlights = preg_split('/,|&/', preg_replace('/\s+/', '', $value));
|
2013-03-14 17:32:02 +01:00
|
|
|
|
|
|
|
$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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-01 20:04:05 +02:00
|
|
|
return $embed_paste;
|
2013-03-13 14:44:27 +01:00
|
|
|
}
|
2014-07-10 00:12:48 +02:00
|
|
|
|
2011-06-27 08:57:43 +02:00
|
|
|
}
|