Changeset View
Changeset View
Standalone View
Standalone View
src/applications/macro/markup/PhabricatorImageMacroRemarkupRule.php
<?php | <?php | ||||
final class PhabricatorImageMacroRemarkupRule extends PhutilRemarkupRule { | final class PhabricatorImageMacroRemarkupRule extends PhutilRemarkupRule { | ||||
private $macros; | private $macros; | ||||
const KEY_RULE_MACRO = 'rule.macro'; | const KEY_RULE_MACRO = 'rule.macro'; | ||||
const KEY_MACRO_USAGE = 'rule.macro_usage'; | |||||
public function apply($text) { | public function apply($text) { | ||||
return preg_replace_callback( | return preg_replace_callback( | ||||
'@^\s*([a-zA-Z0-9:_\-]+)$@m', | '@^\s*([a-zA-Z0-9:_\-]+)$@m', | ||||
array($this, 'markupImageMacro'), | array($this, 'markupImageMacro'), | ||||
$text); | $text); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | foreach ($metadata as $spec) { | ||||
'height' => $file->getImageHeight(), | 'height' => $file->getImageHeight(), | ||||
'width' => $file->getImageWidth(), | 'width' => $file->getImageWidth(), | ||||
'class' => 'phabricator-remarkup-macro', | 'class' => 'phabricator-remarkup-macro', | ||||
)); | )); | ||||
$engine->overwriteStoredText($spec['token'], $result); | $engine->overwriteStoredText($spec['token'], $result); | ||||
} | } | ||||
$macro_usage_key = self::KEY_MACRO_USAGE; | |||||
$macro_usage = $engine->getTextMetadata($macro_usage_key, array()); | |||||
foreach ($metadata as $spec) { | |||||
if (isset($macro_usage[$spec['phid']])) { | |||||
$macro_usage[$spec['phid']]++; | |||||
} else { | |||||
$macro_usage[$spec['phid']] = 1; | |||||
} | |||||
} | |||||
$engine->setTextMetadata($macro_usage_key, $macro_usage); | |||||
$engine->setTextMetadata($metadata_key, array()); | $engine->setTextMetadata($metadata_key, array()); | ||||
} | } | ||||
} | } |