1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-11 17:32:41 +01:00
phorge-phorge/src/infrastructure/markup/rule/PhabricatorRemarkupRuleImageMacro.php
vrana f8dbfdd59d Convert phutil_render_tag(X, Y) to phutil_tag
Summary:
Created with spatch:

  lang=diff
  - phutil_render_tag
  + phutil_tag
    (X, Y)

(and null manually)

Test Plan: Loaded homepage

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4500
2013-01-24 19:08:54 -08:00

51 lines
1.1 KiB
PHP

<?php
/**
* @group markup
*/
final class PhabricatorRemarkupRuleImageMacro
extends PhutilRemarkupRule {
private $images;
public function apply($text) {
return preg_replace_callback(
'@^([a-zA-Z0-9_\-]+)$@m',
array($this, 'markupImageMacro'),
$text);
}
public function markupImageMacro($matches) {
if ($this->images === null) {
$this->images = array();
$rows = id(new PhabricatorFileImageMacro())->loadAllWhere(
'isDisabled = 0');
foreach ($rows as $row) {
$this->images[$row->getName()] = $row->getFilePHID();
}
}
if (array_key_exists($matches[1], $this->images)) {
$phid = $this->images[$matches[1]];
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid);
if ($file) {
$src_uri = $file->getBestURI();
} else {
$src_uri = null;
}
$img = phutil_tag(
'img',
array(
'src' => $src_uri,
'alt' => $matches[1],
'title' => $matches[1],
));
return $this->getEngine()->storeText($img);
} else {
return $matches[1];
}
}
}