From: Mischa POSLAWSKY Date: Tue, 8 Jul 2014 13:28:23 +0000 (+0200) Subject: edit: page editor and php save handler X-Git-Tag: v1.0~4 X-Git-Url: http://git.shiar.net/minimedit.git/commitdiff_plain/a5242b5cae9f1bfaddd748c0287a6c7e6b8af75d edit: page editor and php save handler Inline CKEditor to alter static contents in
. Assumes wanted v4.1.2 ckeditor.js in ckeditor/. --- diff --git a/edit.js b/edit.js new file mode 100644 index 0000000..fda6bf9 --- /dev/null +++ b/edit.js @@ -0,0 +1,50 @@ +CKEDITOR.plugins.add('inlinesave', { + init: function(editor) { + editor.addCommand( 'inlinesave', { + exec: function (editor) { + var pagename = window.location.pathname.replace(/^\//, '') || 'index'; + var data = 'page='+encodeURIComponent(pagename)+'&body='+encodeURIComponent(editor.getData()); + ajaxpost = new XMLHttpRequest(); + ajaxpost.open('POST', 'edit.php', true); + ajaxpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + ajaxpost.onreadystatechange = function () { + if (ajaxpost.readyState != 4) + return; // not done yet + if (ajaxpost.status != 200) + alert('Foutcode '+ajaxpost.status+' bij opslaan: '+ajaxpost.responseText); + //else alert('ok: '+ajaxpost.responseText); + }; + ajaxpost.send(data); + }, + }); + editor.ui.addButton( 'Inlinesave', { + command: 'inlinesave', + label: editor.lang.save.toolbar, + icon: this.path + '../save/icons/save.png', + }); + } +}); + +CKEDITOR.on('instanceCreated', function (event) { + var editor = event.editor; + editor.on('configLoaded', function () { + var config = editor.config; + config.language = 'nl'; + config.extraPlugins = 'sourcedialog,inlinesave'; + config.format_tags = 'h2;h3;h4;p'; + config.allowedContent = true; + config.entities = false; // keep unicode + config.toolbar = [ + ['Inlinesave', '-', 'ShowBlocks', 'Sourcedialog', '-', 'Undo', 'Redo'], + ['Format'], + ['BulletedList', 'NumberedList', '-', 'Blockquote'], + ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Link'], + ['HorizontalRule', 'Table', 'Image'], + ]; + config.enterMode = CKEDITOR.ENTER_BR; // results in

; ENTER_P does it twice + }); +}); + +var pagebody = document.getElementsByClassName('article')[0]; +pagebody.setAttribute('contenteditable', 'true'); + diff --git a/edit.php b/edit.php new file mode 100644 index 0000000..14bfde0 --- /dev/null +++ b/edit.php @@ -0,0 +1,24 @@ +'."\n\n"; +$append = "\n\n".''."\n"; +$upload = $_POST['body']; + +if (!$upload) + abort('409 input error', "leeg bestand aangeleverd"); + +if (!file_put_contents($filename, $prepend . $upload . $append)) + abort('500 save error', "kon bestand niet overschrijven"); + +print "Bestand opgeslagen"; + diff --git a/footer.html b/footer.html index 7e5febc..bd4ca97 100644 --- a/footer.html +++ b/footer.html @@ -1,3 +1,5 @@


+ +