Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14835388
D16597.id39949.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.id39949.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,47 @@
+<?php
+
+final class PhabricatorImageRemarkupRule extends PhutilRemarkupRule {
+ public function getPriority() {
+ // Obviously highest priority because I'm working on it right now
+ // (for real though, what should I make this?)
+ return -9000.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]);
+ $img = $this->newTag(
+ 'img',
+ array('src' => $uri));
+ return $this->getEngine()->storeText($img);
+ } else {
+ $parser = new PhutilSimpleOptions();
+ $keys = $parser->parse($matches[2]);
+ // Create tag using keys
+ }
+ return $matches[2];
+ }
+
+ // 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
Fri, Jan 31, 8:38 PM (5 h, 55 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7079691
Default Alt Text
D16597.id39949.diff (3 KB)
Attached To
Mode
D16597: Remarkup rule to embed images
Attached
Detach File
Event Timeline
Log In to Comment