Skip to content

Commit

Permalink
Implements size checking for ctrl-v image insertions
Browse files Browse the repository at this point in the history
  • Loading branch information
turnermm committed Nov 21, 2018
1 parent 1c079e9 commit e820290
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions action/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function register(Doku_Event_Handler $controller) {
}

function ckgedit_save_preprocess(Doku_Event $event){
global $ACT;
global $ACT,$INPUT;
if (!isset($_REQUEST['ckgedit']) || ! is_array($ACT) || !(isset($ACT['save']) || isset($ACT['preview']))) return;
if (isset($_REQUEST["fontdel"]) ) {
msg($this->getLang("fontdel"),1);
Expand All @@ -26,7 +26,9 @@ function ckgedit_save_preprocess(Doku_Event $event){
msg($this->getLang("formatdel"),1);
}


$img_size = $INPUT->int('broken_image');
if($img_size) msg($this->getLang('broken_image') . $img_size/1000000 . 'M' );


global $TEXT, $conf;

Expand Down
1 change: 1 addition & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@
$lang['off'] ='off';
$lang['js']['on'] ='on';
$lang['js']['off'] ='off';
$lang['broken_image'] = 'Use the imagePaste plugin with the Dokuwiki Mediamanager. Raw data of Ctrl-v images cannot exceed 1M. This image is: ';
15 changes: 13 additions & 2 deletions script.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,23 @@ var HTMLParser_Elements = new Array();
// Special Elements (can contain anything)
var special = makeMap("script,style");


//define ('BROKEN_IMAGE', DOKU_URL . 'lib/plugins/ckgedit/fckeditor/userfiles/blink.jpg?nolink&33x34');
var broken_image ='http://' + location.host + DOKU_BASE + '/lib/plugins/ckgedit/fckeditor/userfiles/blink.jpg?nolink&33x34';
HTMLParser = this.HTMLParser = function( html, handler ) {
var index, chars, match, stack = [], last = html;

html = html.replace(/(<img.*?src="data:image\/\w+;base64,\s*)(.*?)(\/>)/gm,
function(match, p1, p2) {
if(p2.length > 1000000 ) {
jQuery('#dw__editform').append('<input type="hidden" id="broken_image" name="broken_image" value="' + p2.length +'" />');
return '{{' + broken_image + '}}';
}
return match;
});
html = html.replace(/~~OPEN_HTML_BLOCK~~/gm , '~~START_HTML_BLOCK~~') ;
html = html.replace(/~~END_HTML_BLOCK~~/gm , '~~CLOSE_HTML_BLOCK~~') ;
if(html.match(/~~START_HTML_BLOCK~~/gm) ){ //adopted [\s\S] from Goyvaerts, Reg. Exp. Cookbook (O'Reilly)

if(html.match(/~~START_HTML_BLOCK~~/gm) ){ //adopted [\s\S] from Goyvaerts, Reg. Exp. Cookbook (O'Reilly)
if(!JSINFO['htmlok']) {
html = html.replace(/~~START_HTML_BLOCK~~|~~CLOSE_HTML_BLOCK~~/gm,"");
}
Expand Down

0 comments on commit e820290

Please sign in to comment.