Page MenuHomePhabricator

D16597.id.diff
No OneTemporary

D16597.id.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2688,6 +2688,7 @@
'PhabricatorIconSetEditField' => 'applications/transactions/editfield/PhabricatorIconSetEditField.php',
'PhabricatorIconSetIcon' => 'applications/files/iconset/PhabricatorIconSetIcon.php',
'PhabricatorImageMacroRemarkupRule' => 'applications/macro/markup/PhabricatorImageMacroRemarkupRule.php',
+ 'PhabricatorImageRemarkupRule' => 'applications/files/markup/PhabricatorImageRemarkupRule.php',
'PhabricatorImageTransformer' => 'applications/files/PhabricatorImageTransformer.php',
'PhabricatorImagemagickSetupCheck' => 'applications/config/check/PhabricatorImagemagickSetupCheck.php',
'PhabricatorInFlightErrorView' => 'applications/config/view/PhabricatorInFlightErrorView.php',
@@ -7523,6 +7524,7 @@
'PhabricatorIconSetEditField' => 'PhabricatorEditField',
'PhabricatorIconSetIcon' => 'Phobject',
'PhabricatorImageMacroRemarkupRule' => 'PhutilRemarkupRule',
+ 'PhabricatorImageRemarkupRule' => 'PhutilRemarkupRule',
'PhabricatorImageTransformer' => 'Phobject',
'PhabricatorImagemagickSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorInFlightErrorView' => 'AphrontView',
diff --git a/src/applications/files/application/PhabricatorFilesApplication.php b/src/applications/files/application/PhabricatorFilesApplication.php
--- a/src/applications/files/application/PhabricatorFilesApplication.php
+++ b/src/applications/files/application/PhabricatorFilesApplication.php
@@ -37,6 +37,7 @@
public function getRemarkupRules() {
return array(
new PhabricatorEmbedFileRemarkupRule(),
+ new PhabricatorImageRemarkupRule(),
);
}
diff --git a/src/applications/files/markup/PhabricatorImageRemarkupRule.php b/src/applications/files/markup/PhabricatorImageRemarkupRule.php
new file mode 100644
--- /dev/null
+++ b/src/applications/files/markup/PhabricatorImageRemarkupRule.php
@@ -0,0 +1,75 @@
+<?php
+
+final class PhabricatorImageRemarkupRule extends PhutilRemarkupRule {
+ public function getPriority() {
+ return 200.0;
+ }
+
+ public function apply($text) {
+ return preg_replace_callback(
+ '@{(image|img) ((?:[^}\\\\]+|\\\\.)*)}@m',
+ array($this, 'markupImage'),
+ $text);
+ }
+
+ public function markupImage(array $matches) {
+ if (!$this->isFlatText($matches[0])) {
+ return $matches[0];
+ }
+ $args = array();
+ $defaults = array(
+ 'uri' => null,
+ 'alt' => null,
+ 'href' => null,
+ 'width' => null,
+ 'height' => null,
+ );
+ $trimmed_match = trim($matches[2]);
+ if ($this->isURI($trimmed_match)) {
+ $args['uri'] = new PhutilURI($trimmed_match);
+ } else {
+ $parser = new PhutilSimpleOptions();
+ $keys = $parser->parse($trimmed_match);
+
+ $uri_key = '';
+ foreach (array('src', 'uri', 'url') as $key) {
+ if (array_key_exists($key, $keys)) {
+ $uri_key = $key;
+ }
+ }
+ if ($uri_key) {
+ $args['uri'] = new PhutilURI($keys[$uri_key]);
+ }
+ $args += $keys;
+ }
+
+ $args += $defaults;
+
+ if ($args['href'] && !PhabricatorEnv::isValidURIForLink($args['href'])) {
+ $args['href'] = null;
+ }
+
+ if ($args['uri']) {
+ $src_uri = id(new PhutilURI('/file/imageproxy/'))
+ ->setQueryParam('uri', (string)$args['uri']);
+ $img = $this->newTag(
+ 'img',
+ array(
+ 'src' => $src_uri,
+ 'alt' => $args['alt'],
+ 'href' => $args['href'],
+ 'width' => $args['width'],
+ 'height' => $args['height'],
+ ));
+ return $this->getEngine()->storeText($img);
+ } else {
+ return $matches[0];
+ }
+ }
+
+ private function isURI($uri_string) {
+ // Very simple check to make sure it starts with either http or https.
+ // If it does, we'll try to treat it like a valid URI
+ return preg_match('~^https?\:\/\/.*\z~i', $uri_string);
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Wed, Mar 12, 5:07 AM (4 h, 8 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7431452
Default Alt Text
D16597.id.diff (3 KB)

Event Timeline