--- /dev/null
+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 <p>; ENTER_P does it twice
+ });
+});
+
+var pagebody = document.getElementsByClassName('article')[0];
+pagebody.setAttribute('contenteditable', 'true');
+
--- /dev/null
+<?php
+function abort($status, $body) {
+ header("HTTP/1.1 $status");
+ print "$body\n";
+ exit;
+}
+
+$filename = $_POST['page'];
+$filename = ltrim($filename, '/');
+if (!preg_match('/^[a-z]+\.html$/', $filename))
+ abort('403 input error', "Ongeldige bestandsnaam: $filename");
+
+$prepend = '<!--#include virtual="common.html" -->'."\n\n";
+$append = "\n\n".'<!--#include virtual="footer.html" -->'."\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";
+