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) {
|
2013-02-12 08:42:37 +01:00
|
|
|
return $this->replaceHTML(
|
2013-01-29 23:22:36 +01: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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-12 08:42:37 +01:00
|
|
|
$name = (string)$matches[1];
|
|
|
|
|
|
|
|
if (array_key_exists($name, $this->images)) {
|
|
|
|
$phid = $this->images[$name];
|
2011-04-14 00:15:48 +02:00
|
|
|
|
2012-01-10 23:48:55 +01:00
|
|
|
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid);
|
2013-01-27 03:59:35 +01:00
|
|
|
$style = null;
|
|
|
|
$src_uri = null;
|
2012-01-10 23:48:55 +01:00
|
|
|
if ($file) {
|
|
|
|
$src_uri = $file->getBestURI();
|
2013-01-27 03:59:35 +01:00
|
|
|
$file_data = $file->getMetadata();
|
2013-02-05 03:32:03 +01:00
|
|
|
$height = idx($file_data, PhabricatorFile::METADATA_IMAGE_HEIGHT);
|
2013-01-27 04:03:00 +01:00
|
|
|
$width = idx($file_data, PhabricatorFile::METADATA_IMAGE_WIDTH);
|
2013-01-27 03:59:35 +01:00
|
|
|
if ($height && $width) {
|
|
|
|
$style = sprintf(
|
|
|
|
'height: %dpx; width: %dpx;',
|
|
|
|
$height,
|
|
|
|
$width
|
|
|
|
);
|
|
|
|
}
|
2012-01-10 23:48:55 +01:00
|
|
|
}
|
2011-04-14 00:15:48 +02:00
|
|
|
|
2013-01-18 03:39:02 +01:00
|
|
|
$img = phutil_tag(
|
2011-04-14 00:15:48 +02:00
|
|
|
'img',
|
|
|
|
array(
|
2012-01-10 23:48:55 +01:00
|
|
|
'src' => $src_uri,
|
2011-04-14 00:15:48 +02:00
|
|
|
'alt' => $matches[1],
|
2013-01-18 03:39:02 +01:00
|
|
|
'title' => $matches[1],
|
2013-01-27 15:01:27 +01:00
|
|
|
'style' => $style,
|
2013-01-18 03:39:02 +01:00
|
|
|
));
|
2011-04-14 00:15:48 +02:00
|
|
|
return $this->getEngine()->storeText($img);
|
|
|
|
} else {
|
|
|
|
return $matches[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|