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.
This commit is contained in:
Dan Brown 2016-09-03 19:24:58 +01:00
parent ec17bd8608
commit bbd8fff021
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
3 changed files with 12 additions and 7 deletions

View File

@ -48,11 +48,13 @@ class ExportService
foreach ($imageTagsOutput[0] as $index => $imgMatch) {
$oldImgString = $imgMatch;
$srcString = $imageTagsOutput[2][$index];
if (strpos(trim($srcString), 'http') !== 0) {
$pathString = public_path($srcString);
$isLocal = strpos(trim($srcString), 'http') !== 0;
if ($isLocal) {
$pathString = public_path(trim($srcString, '/'));
} else {
$pathString = $srcString;
}
if ($isLocal && !file_exists($pathString)) continue;
$imageContent = file_get_contents($pathString);
$imageEncoded = 'data:image/' . pathinfo($pathString, PATHINFO_EXTENSION) . ';base64,' . base64_encode($imageContent);
$newImageString = str_replace($srcString, $imageEncoded, $oldImgString);

View File

@ -370,7 +370,7 @@ module.exports = function (ngApp, events) {
window.ImageManager.showExternal(image => {
let caretPos = currentCaretPos;
let currentContent = input.val();
let mdImageText = "![" + image.name + "](" + image.url + ")";
let mdImageText = "![" + image.name + "](" + image.thumbs.display + ")";
input.val(currentContent.substring(0, caretPos) + mdImageText + currentContent.substring(caretPos));
input.change();
});
@ -441,7 +441,7 @@ module.exports = function (ngApp, events) {
let selectEnd = input[0].selectionEnd;
let content = input[0].value;
let selectText = content.substring(selectStart, selectEnd);
let placeholderImage = `/loading.gif#upload${id}`;
let placeholderImage = window.baseUrl(`/loading.gif#upload${id}`);
let innerContent = ((selectEnd > selectStart) ? `![${selectText}]` : '![]') + `(${placeholderImage})`;
input[0].value = content.substring(0, selectStart) + innerContent + content.substring(selectEnd);
@ -458,7 +458,7 @@ module.exports = function (ngApp, events) {
let selectStart = input[0].selectionStart;
if (xhr.status === 200 || xhr.status === 201) {
var result = JSON.parse(xhr.responseText);
input[0].value = input[0].value.replace(placeholderImage, result.url);
input[0].value = input[0].value.replace(placeholderImage, result.thumbs.display);
input.change();
} else {
console.log('An error occurred uploading the image');

View File

@ -20,7 +20,8 @@ function editorPaste(e, editor) {
}
var id = "image-" + Math.random().toString(16).slice(2);
editor.execCommand('mceInsertContent', false, '<img src="/loading.gif" id="' + id + '">');
var loadingImage = window.baseUrl('/loading.gif');
editor.execCommand('mceInsertContent', false, '<img src="'+ loadingImage +'" id="' + id + '">');
var remoteFilename = "image-" + Date.now() + "." + ext;
formData.append('file', file, remoteFilename);
@ -30,7 +31,7 @@ function editorPaste(e, editor) {
xhr.onload = function () {
if (xhr.status === 200 || xhr.status === 201) {
var result = JSON.parse(xhr.responseText);
editor.dom.setAttrib(id, 'src', result.url);
editor.dom.setAttrib(id, 'src', result.thumbs.display);
} else {
console.log('An error occurred uploading the image');
console.log(xhr.responseText);
@ -63,6 +64,8 @@ var mceOptions = module.exports = {
],
body_class: 'page-content',
relative_urls: false,
remove_script_host: false,
document_base_url: window.baseUrl('/'),
statusbar: false,
menubar: false,
paste_data_images: false,