Dan Brown

Fixed bad image base-urls and forced tinyMCE to use absolute

Also ensured image file existance is checked during base64 conversion
during exports.
Closes #171.
...@@ -48,11 +48,13 @@ class ExportService ...@@ -48,11 +48,13 @@ class ExportService
48 foreach ($imageTagsOutput[0] as $index => $imgMatch) { 48 foreach ($imageTagsOutput[0] as $index => $imgMatch) {
49 $oldImgString = $imgMatch; 49 $oldImgString = $imgMatch;
50 $srcString = $imageTagsOutput[2][$index]; 50 $srcString = $imageTagsOutput[2][$index];
51 - if (strpos(trim($srcString), 'http') !== 0) { 51 + $isLocal = strpos(trim($srcString), 'http') !== 0;
52 - $pathString = public_path($srcString); 52 + if ($isLocal) {
53 + $pathString = public_path(trim($srcString, '/'));
53 } else { 54 } else {
54 $pathString = $srcString; 55 $pathString = $srcString;
55 } 56 }
57 + if ($isLocal && !file_exists($pathString)) continue;
56 $imageContent = file_get_contents($pathString); 58 $imageContent = file_get_contents($pathString);
57 $imageEncoded = 'data:image/' . pathinfo($pathString, PATHINFO_EXTENSION) . ';base64,' . base64_encode($imageContent); 59 $imageEncoded = 'data:image/' . pathinfo($pathString, PATHINFO_EXTENSION) . ';base64,' . base64_encode($imageContent);
58 $newImageString = str_replace($srcString, $imageEncoded, $oldImgString); 60 $newImageString = str_replace($srcString, $imageEncoded, $oldImgString);
......
...@@ -370,7 +370,7 @@ module.exports = function (ngApp, events) { ...@@ -370,7 +370,7 @@ module.exports = function (ngApp, events) {
370 window.ImageManager.showExternal(image => { 370 window.ImageManager.showExternal(image => {
371 let caretPos = currentCaretPos; 371 let caretPos = currentCaretPos;
372 let currentContent = input.val(); 372 let currentContent = input.val();
373 - let mdImageText = "![" + image.name + "](" + image.url + ")"; 373 + let mdImageText = "![" + image.name + "](" + image.thumbs.display + ")";
374 input.val(currentContent.substring(0, caretPos) + mdImageText + currentContent.substring(caretPos)); 374 input.val(currentContent.substring(0, caretPos) + mdImageText + currentContent.substring(caretPos));
375 input.change(); 375 input.change();
376 }); 376 });
...@@ -441,7 +441,7 @@ module.exports = function (ngApp, events) { ...@@ -441,7 +441,7 @@ module.exports = function (ngApp, events) {
441 let selectEnd = input[0].selectionEnd; 441 let selectEnd = input[0].selectionEnd;
442 let content = input[0].value; 442 let content = input[0].value;
443 let selectText = content.substring(selectStart, selectEnd); 443 let selectText = content.substring(selectStart, selectEnd);
444 - let placeholderImage = `/loading.gif#upload${id}`; 444 + let placeholderImage = window.baseUrl(`/loading.gif#upload${id}`);
445 let innerContent = ((selectEnd > selectStart) ? `![${selectText}]` : '![]') + `(${placeholderImage})`; 445 let innerContent = ((selectEnd > selectStart) ? `![${selectText}]` : '![]') + `(${placeholderImage})`;
446 input[0].value = content.substring(0, selectStart) + innerContent + content.substring(selectEnd); 446 input[0].value = content.substring(0, selectStart) + innerContent + content.substring(selectEnd);
447 447
...@@ -458,7 +458,7 @@ module.exports = function (ngApp, events) { ...@@ -458,7 +458,7 @@ module.exports = function (ngApp, events) {
458 let selectStart = input[0].selectionStart; 458 let selectStart = input[0].selectionStart;
459 if (xhr.status === 200 || xhr.status === 201) { 459 if (xhr.status === 200 || xhr.status === 201) {
460 var result = JSON.parse(xhr.responseText); 460 var result = JSON.parse(xhr.responseText);
461 - input[0].value = input[0].value.replace(placeholderImage, result.url); 461 + input[0].value = input[0].value.replace(placeholderImage, result.thumbs.display);
462 input.change(); 462 input.change();
463 } else { 463 } else {
464 console.log('An error occurred uploading the image'); 464 console.log('An error occurred uploading the image');
......
...@@ -20,7 +20,8 @@ function editorPaste(e, editor) { ...@@ -20,7 +20,8 @@ function editorPaste(e, editor) {
20 } 20 }
21 21
22 var id = "image-" + Math.random().toString(16).slice(2); 22 var id = "image-" + Math.random().toString(16).slice(2);
23 - editor.execCommand('mceInsertContent', false, '<img src="/loading.gif" id="' + id + '">'); 23 + var loadingImage = window.baseUrl('/loading.gif');
24 + editor.execCommand('mceInsertContent', false, '<img src="'+ loadingImage +'" id="' + id + '">');
24 25
25 var remoteFilename = "image-" + Date.now() + "." + ext; 26 var remoteFilename = "image-" + Date.now() + "." + ext;
26 formData.append('file', file, remoteFilename); 27 formData.append('file', file, remoteFilename);
...@@ -30,7 +31,7 @@ function editorPaste(e, editor) { ...@@ -30,7 +31,7 @@ function editorPaste(e, editor) {
30 xhr.onload = function () { 31 xhr.onload = function () {
31 if (xhr.status === 200 || xhr.status === 201) { 32 if (xhr.status === 200 || xhr.status === 201) {
32 var result = JSON.parse(xhr.responseText); 33 var result = JSON.parse(xhr.responseText);
33 - editor.dom.setAttrib(id, 'src', result.url); 34 + editor.dom.setAttrib(id, 'src', result.thumbs.display);
34 } else { 35 } else {
35 console.log('An error occurred uploading the image'); 36 console.log('An error occurred uploading the image');
36 console.log(xhr.responseText); 37 console.log(xhr.responseText);
...@@ -63,6 +64,8 @@ var mceOptions = module.exports = { ...@@ -63,6 +64,8 @@ var mceOptions = module.exports = {
63 ], 64 ],
64 body_class: 'page-content', 65 body_class: 'page-content',
65 relative_urls: false, 66 relative_urls: false,
67 + remove_script_host: false,
68 + document_base_url: window.baseUrl('/'),
66 statusbar: false, 69 statusbar: false,
67 menubar: false, 70 menubar: false,
68 paste_data_images: false, 71 paste_data_images: false,
......