2011-04-14 00:15:48 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group markup
|
|
|
|
*/
|
2012-03-14 00:21:04 +01:00
|
|
|
final class PhabricatorRemarkupRuleImageMacro
|
2011-04-14 00:15:48 +02:00
|
|
|
extends PhutilRemarkupRule {
|
|
|
|
|
2012-07-16 19:35:36 +02:00
|
|
|
private $images;
|
2011-04-14 00:15:48 +02:00
|
|
|
|
|
|
|
public function apply($text) {
|
|
|
|
return preg_replace_callback(
|
2012-04-13 20:30:01 +02:00
|
|
|
'@^([a-zA-Z0-9_\-]+)$@m',
|
2011-04-14 00:15:48 +02:00
|
|
|
array($this, 'markupImageMacro'),
|
|
|
|
$text);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function markupImageMacro($matches) {
|
2012-07-11 20:40:10 +02:00
|
|
|
if ($this->images === null) {
|
|
|
|
$this->images = array();
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
$rows = id(new PhabricatorFileImageMacro())->loadAllWhere(
|
|
|
|
'isDisabled = 0');
|
2012-07-11 20:40:10 +02:00
|
|
|
foreach ($rows as $row) {
|
|
|
|
$this->images[$row->getName()] = $row->getFilePHID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-14 00:15:48 +02:00
|
|
|
if (array_key_exists($matches[1], $this->images)) {
|
2012-04-13 20:30:01 +02:00
|
|
|
$phid = $this->images[$matches[1]];
|
2011-04-14 00:15:48 +02:00
|
|
|
|
2012-01-10 23:48:55 +01:00
|
|
|
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid);
|
|
|
|
if ($file) {
|
|
|
|
$src_uri = $file->getBestURI();
|
|
|
|
} else {
|
|
|
|
$src_uri = null;
|
|
|
|
}
|
2011-04-14 00:15:48 +02:00
|
|
|
|
|
|
|
$img = phutil_render_tag(
|
|
|
|
'img',
|
|
|
|
array(
|
2012-01-10 23:48:55 +01:00
|
|
|
'src' => $src_uri,
|
2011-04-14 00:15:48 +02:00
|
|
|
'alt' => $matches[1],
|
|
|
|
'title' => $matches[1]),
|
|
|
|
null);
|
|
|
|
return $this->getEngine()->storeText($img);
|
|
|
|
} else {
|
|
|
|
return $matches[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|