2011-04-13 15:15:48 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group markup
|
|
|
|
*/
|
2012-03-13 16:21:04 -07:00
|
|
|
final class PhabricatorRemarkupRuleImageMacro
|
2011-04-13 15:15:48 -07:00
|
|
|
extends PhutilRemarkupRule {
|
|
|
|
|
2012-07-16 10:35:36 -07:00
|
|
|
private $images;
|
2011-04-13 15:15:48 -07:00
|
|
|
|
|
|
|
public function apply($text) {
|
|
|
|
return preg_replace_callback(
|
2012-04-13 11:30:01 -07:00
|
|
|
'@^([a-zA-Z0-9_\-]+)$@m',
|
2011-04-13 15:15:48 -07:00
|
|
|
array($this, 'markupImageMacro'),
|
|
|
|
$text);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function markupImageMacro($matches) {
|
2012-07-11 11:40:10 -07: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 14:01:03 -08:00
|
|
|
$rows = id(new PhabricatorFileImageMacro())->loadAllWhere(
|
|
|
|
'isDisabled = 0');
|
2012-07-11 11:40:10 -07:00
|
|
|
foreach ($rows as $row) {
|
|
|
|
$this->images[$row->getName()] = $row->getFilePHID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-13 15:15:48 -07:00
|
|
|
if (array_key_exists($matches[1], $this->images)) {
|
2012-04-13 11:30:01 -07:00
|
|
|
$phid = $this->images[$matches[1]];
|
2011-04-13 15:15:48 -07:00
|
|
|
|
2012-01-10 14:48:55 -08:00
|
|
|
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid);
|
2013-01-26 18:59:35 -08:00
|
|
|
$style = null;
|
|
|
|
$src_uri = null;
|
2012-01-10 14:48:55 -08:00
|
|
|
if ($file) {
|
|
|
|
$src_uri = $file->getBestURI();
|
2013-01-26 18:59:35 -08:00
|
|
|
$file_data = $file->getMetadata();
|
|
|
|
$height = $file_data[PhabricatorFile::METADATA_IMAGE_HEIGHT];
|
|
|
|
$width = $file_data[PhabricatorFile::METADATA_IMAGE_WIDTH];
|
|
|
|
if ($height && $width) {
|
|
|
|
$style = sprintf(
|
|
|
|
'height: %dpx; width: %dpx;',
|
|
|
|
$height,
|
|
|
|
$width
|
|
|
|
);
|
|
|
|
}
|
2012-01-10 14:48:55 -08:00
|
|
|
}
|
2011-04-13 15:15:48 -07:00
|
|
|
|
|
|
|
$img = phutil_render_tag(
|
|
|
|
'img',
|
|
|
|
array(
|
2012-01-10 14:48:55 -08:00
|
|
|
'src' => $src_uri,
|
2011-04-13 15:15:48 -07:00
|
|
|
'alt' => $matches[1],
|
2013-01-26 18:59:35 -08:00
|
|
|
'title' => $matches[1],
|
|
|
|
'style' => $style),
|
2011-04-13 15:15:48 -07:00
|
|
|
null);
|
|
|
|
return $this->getEngine()->storeText($img);
|
|
|
|
} else {
|
|
|
|
return $matches[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|