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:
		
							parent
							
								
									ec17bd8608
								
							
						
					
					
						commit
						bbd8fff021
					
				| 
						 | 
					@ -48,11 +48,13 @@ class ExportService
 | 
				
			||||||
            foreach ($imageTagsOutput[0] as $index => $imgMatch) {
 | 
					            foreach ($imageTagsOutput[0] as $index => $imgMatch) {
 | 
				
			||||||
                $oldImgString = $imgMatch;
 | 
					                $oldImgString = $imgMatch;
 | 
				
			||||||
                $srcString = $imageTagsOutput[2][$index];
 | 
					                $srcString = $imageTagsOutput[2][$index];
 | 
				
			||||||
                if (strpos(trim($srcString), 'http') !== 0) {
 | 
					                $isLocal = strpos(trim($srcString), 'http') !== 0;
 | 
				
			||||||
                    $pathString = public_path($srcString);
 | 
					                if ($isLocal) {
 | 
				
			||||||
 | 
					                    $pathString = public_path(trim($srcString, '/'));
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    $pathString = $srcString;
 | 
					                    $pathString = $srcString;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                if ($isLocal && !file_exists($pathString)) continue;
 | 
				
			||||||
                $imageContent = file_get_contents($pathString);
 | 
					                $imageContent = file_get_contents($pathString);
 | 
				
			||||||
                $imageEncoded = 'data:image/' . pathinfo($pathString, PATHINFO_EXTENSION) . ';base64,' . base64_encode($imageContent);
 | 
					                $imageEncoded = 'data:image/' . pathinfo($pathString, PATHINFO_EXTENSION) . ';base64,' . base64_encode($imageContent);
 | 
				
			||||||
                $newImageString = str_replace($srcString, $imageEncoded, $oldImgString);
 | 
					                $newImageString = str_replace($srcString, $imageEncoded, $oldImgString);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -370,7 +370,7 @@ module.exports = function (ngApp, events) {
 | 
				
			||||||
                    window.ImageManager.showExternal(image => {
 | 
					                    window.ImageManager.showExternal(image => {
 | 
				
			||||||
                        let caretPos = currentCaretPos;
 | 
					                        let caretPos = currentCaretPos;
 | 
				
			||||||
                        let currentContent = input.val();
 | 
					                        let currentContent = input.val();
 | 
				
			||||||
                        let mdImageText = "";
 | 
					                        let mdImageText = "";
 | 
				
			||||||
                        input.val(currentContent.substring(0, caretPos) + mdImageText + currentContent.substring(caretPos));
 | 
					                        input.val(currentContent.substring(0, caretPos) + mdImageText + currentContent.substring(caretPos));
 | 
				
			||||||
                        input.change();
 | 
					                        input.change();
 | 
				
			||||||
                    });
 | 
					                    });
 | 
				
			||||||
| 
						 | 
					@ -441,7 +441,7 @@ module.exports = function (ngApp, events) {
 | 
				
			||||||
                    let selectEnd = input[0].selectionEnd;
 | 
					                    let selectEnd = input[0].selectionEnd;
 | 
				
			||||||
                    let content = input[0].value;
 | 
					                    let content = input[0].value;
 | 
				
			||||||
                    let selectText = content.substring(selectStart, selectEnd);
 | 
					                    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})`;
 | 
					                    let innerContent = ((selectEnd > selectStart) ? `![${selectText}]` : '![]') + `(${placeholderImage})`;
 | 
				
			||||||
                    input[0].value = content.substring(0, selectStart) +  innerContent + content.substring(selectEnd);
 | 
					                    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;
 | 
					                        let selectStart = input[0].selectionStart;
 | 
				
			||||||
                        if (xhr.status === 200 || xhr.status === 201) {
 | 
					                        if (xhr.status === 200 || xhr.status === 201) {
 | 
				
			||||||
                            var result = JSON.parse(xhr.responseText);
 | 
					                            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();
 | 
					                            input.change();
 | 
				
			||||||
                        } else {
 | 
					                        } else {
 | 
				
			||||||
                            console.log('An error occurred uploading the image');
 | 
					                            console.log('An error occurred uploading the image');
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,7 +20,8 @@ function editorPaste(e, editor) {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var id = "image-" + Math.random().toString(16).slice(2);
 | 
					            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;
 | 
					            var remoteFilename = "image-" + Date.now() + "." + ext;
 | 
				
			||||||
            formData.append('file', file, remoteFilename);
 | 
					            formData.append('file', file, remoteFilename);
 | 
				
			||||||
| 
						 | 
					@ -30,7 +31,7 @@ function editorPaste(e, editor) {
 | 
				
			||||||
            xhr.onload = function () {
 | 
					            xhr.onload = function () {
 | 
				
			||||||
                if (xhr.status === 200 || xhr.status === 201) {
 | 
					                if (xhr.status === 200 || xhr.status === 201) {
 | 
				
			||||||
                    var result = JSON.parse(xhr.responseText);
 | 
					                    var result = JSON.parse(xhr.responseText);
 | 
				
			||||||
                    editor.dom.setAttrib(id, 'src', result.url);
 | 
					                    editor.dom.setAttrib(id, 'src', result.thumbs.display);
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    console.log('An error occurred uploading the image');
 | 
					                    console.log('An error occurred uploading the image');
 | 
				
			||||||
                    console.log(xhr.responseText);
 | 
					                    console.log(xhr.responseText);
 | 
				
			||||||
| 
						 | 
					@ -63,6 +64,8 @@ var mceOptions = module.exports = {
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    body_class: 'page-content',
 | 
					    body_class: 'page-content',
 | 
				
			||||||
    relative_urls: false,
 | 
					    relative_urls: false,
 | 
				
			||||||
 | 
					    remove_script_host: false,
 | 
				
			||||||
 | 
					    document_base_url: window.baseUrl('/'),
 | 
				
			||||||
    statusbar: false,
 | 
					    statusbar: false,
 | 
				
			||||||
    menubar: false,
 | 
					    menubar: false,
 | 
				
			||||||
    paste_data_images: false,
 | 
					    paste_data_images: false,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue