Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15570295
D16597.id39953.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D16597.id39953.diff
View Options
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,57 @@
+<?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) {
+ $uri = '';
+ if ($this->isURI($matches[2])) {
+ $uri = new PhutilURI($matches[2]);
+ } else {
+ $parser = new PhutilSimpleOptions();
+ $keys = $parser->parse($matches[2]);
+ $uri_key = '';
+ foreach (array('src', 'uri', 'url') as $key) {
+ if (array_key_exists($key, $keys)) {
+ $uri_key = $key;
+ }
+ }
+
+ if ($uri_key) {
+ $uri = new PhutilURI($keys[$uri_key]);
+ }
+ }
+ if ($uri) {
+ $img = $this->newTag(
+ 'img',
+ array('src' => '/file/imageproxy/?uri='.$uri));
+ return $this->getEngine()->storeText($img);
+ } else {
+ return $matches[0];
+ }
+ }
+
+ // This can probably be simplified a ton. Even if kept as-is, this probably
+ // isn't the right place to put it
+ private function isURI($uri_string) {
+ $regex = '(https?\:\/\/)?'; // protocol
+ // username and password. Can maybe just remove this piece.
+ $regex .= '([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?';
+ $regex .= '([a-z0-9-.]*)\.([a-z]{2,3})'; // Host or IP
+ $regex .= '(\:[0-9]{2,5})?'; // Port
+ $regex .= '(\/([a-z0-9+\$_-]\.?)+)*\/?'; // Path
+ $regex .= '(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?'; // Query string
+ $regex .= '(#[a-z_.-][a-z0-9+\$_.-]*)?'; // Anchor
+
+ return preg_match("~^$regex$~i", $uri_string);
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, May 5, 3:09 PM (1 d, 3 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7730276
Default Alt Text
D16597.id39953.diff (3 KB)
Attached To
Mode
D16597: Remarkup rule to embed images
Attached
Detach File
Event Timeline
Log In to Comment