Skip to content

Commit

Permalink
Image paste from clipboard support (#3808)
Browse files Browse the repository at this point in the history
  • Loading branch information
effone authored and euantorano committed Sep 28, 2019
1 parent 75afe63 commit 4c5451a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
48 changes: 35 additions & 13 deletions inc/class_parser.php
Expand Up @@ -451,20 +451,18 @@ function parse_mycode($message, $options=array())
$message = $this->mycode_parse_quotes($message);

// Convert images when allowed.
if(!empty($this->options['allow_imgcode']))
{
$message = preg_replace_callback("#\[img\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_callback1'), $message);
$message = preg_replace_callback("#\[img=([1-9][0-9]*)x([1-9][0-9]*)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_callback2'), $message);
$message = preg_replace_callback("#\[img align=(left|right)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_callback3'), $message);
$message = preg_replace_callback("#\[img=([1-9][0-9]*)x([1-9][0-9]*) align=(left|right)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_callback4'), $message);
}
else
$allow_imgcode = "";

if(empty($this->options['allow_imgcode']))
{
$message = preg_replace_callback("#\[img\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_disabled_callback1'), $message);
$message = preg_replace_callback("#\[img=([1-9][0-9]*)x([1-9][0-9]*)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_disabled_callback2'), $message);
$message = preg_replace_callback("#\[img align=(left|right)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_disabled_callback3'), $message);
$message = preg_replace_callback("#\[img=([1-9][0-9]*)x([1-9][0-9]*) align=(left|right)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_disabled_callback4'), $message);
$allow_imgcode = "_disabled";
}

$message = preg_replace_callback("#\[img\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img' . $allow_imgcode . '_callback1'), $message);
$message = preg_replace_callback("#\[img=([1-9][0-9]*)x([1-9][0-9]*)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img' . $allow_imgcode . '_callback2'), $message);
$message = preg_replace_callback("#\[img align=(left|right)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img' . $allow_imgcode . '_callback3'), $message);
$message = preg_replace_callback("#\[img=([1-9][0-9]*)x([1-9][0-9]*) align=(left|right)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img' . $allow_imgcode . '_callback4'), $message);
$message = preg_replace_callback("#\[img\](\r\n?|\n?)data:image\/(.+)?(\r\n?|\n?)\[\/img\]#is", array($this, 'mycode_parse_img' . $allow_imgcode . '_callback5'), $message);

// Convert videos when allow.
if(!empty($this->options['allow_videocode']))
Expand Down Expand Up @@ -1270,6 +1268,19 @@ function mycode_parse_img_callback4($matches)
return $this->mycode_parse_img($matches[5], array($matches[1], $matches[2]), $matches[3]);
}

/**
* Parses IMG MyCode.
* Image Data URI Support
*
* @since 1.8.22
* @param array $matches Matches.
* @return string Image code.
*/
function mycode_parse_img_callback5($matches)
{
return '<img src="data:image/' . $matches[2] . '">';
}

/**
* Parses IMG MyCode disabled.
*
Expand Down Expand Up @@ -1332,6 +1343,17 @@ function mycode_parse_img_disabled_callback4($matches)
return $this->mycode_parse_img_disabled($matches[5]);
}

/**
* Parses IMG MyCode disabled.
*
* @return string Raw image code notice.
*/
function mycode_parse_img_disabled_callback5()
{
global $lang;
return $lang->posted_image_uri;
}

/**
* Parses email MyCode.
*
Expand Down Expand Up @@ -1869,4 +1891,4 @@ function encode_url($url)

return $url;
}
}
}
1 change: 1 addition & 0 deletions inc/languages/english/global.lang.php
Expand Up @@ -224,6 +224,7 @@
$l['code'] = "Code:";
$l['php_code'] = "PHP Code:";
$l['posted_image'] = "[Image: {1}]";
$l['posted_image_uri'] = "[Image: Raw base64 data]";
$l['posted_video'] = "[Video: {1}]";
$l['linkback'] = "Original Post";

Expand Down

0 comments on commit 4c5451a

Please sign in to comment.