diff --git a/action.php b/action.php index 754b131..b0952d1 100644 --- a/action.php +++ b/action.php @@ -7,7 +7,6 @@ /** * Make things happen when buttons are pressed and forms submitted. */ - require_once __DIR__ . "/required.php"; if ($VARS['action'] !== "signout") { @@ -32,8 +31,24 @@ function returnToSender($msg, $arg = "") { switch ($VARS['action']) { case "saveedits": - $page = $VARS['page']; + header("Content-Type: application/json"); + $slug = $VARS['slug']; + $site = $VARS['site']; $content = $VARS['content']; + if ($database->has("pages", ["AND" => ["slug" => $slug, "siteid" => $site]])) { + $pageid = $database->get("pages", "pageid", ["AND" => ["slug" => $slug, "siteid" => $site]]); + } else { + die(json_encode(["status" => "ERROR", "msg" => "Invalid page or site"])); + } + foreach ($content as $name => $value) { + if ($database->has("components", ["AND" => ["pageid" => $pageid, "name" => $name]])) { + $database->update("components", ["content" => $value], ["AND" => ["pageid" => $pageid, "name" => $name]]); + } else { + $database->insert("components", ["name" => $name, "content" => $value, "pageid" => $pageid]); + } + } + exit(json_encode(["status" => "OK"])); + break; case "signout": session_destroy(); header('Location: index.php'); diff --git a/database.mwb b/database.mwb index 82f3394..ee286d6 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/lang/en_us.php b/lang/en_us.php index f4d5ddd..3c3e7d2 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -28,7 +28,18 @@ define("STRINGS", [ "login server error" => "The login server returned an error: {arg}", "login server user data error" => "The login server refused to provide account information. Try again or contact technical support.", "captcha error" => "There was a problem with the CAPTCHA (robot test). Try again.", + "actions" => "Actions", "home" => "Home", "more" => "More", - "test" => "Test" + "sites" => "Sites", + "theme" => "Theme", + "name" => "Name", + "site name" => "Site Name", + "url" => "URL", + "editing site" => "Editing {site}", + "theme type" => "Theme type", + "single page" => "Single page", + "multiple page" => "Multiple page", + "templates" => "Templates", + "color styles" => "Color styles" ]); \ No newline at end of file diff --git a/lib/themefunctions.php b/lib/themefunctions.php index b1f19db..63eb70e 100644 --- a/lib/themefunctions.php +++ b/lib/themefunctions.php @@ -59,7 +59,11 @@ function get_page_url($echo = true, $slug = null) { if ($slug == null) { $slug = get_page_slug(false); } - $url = get_site_url(false) . "index.php?id=$slug"; + $edit = ""; + if (isset($_GET['edit'])) { + $edit = "&edit"; + } + $url = get_site_url(false) . "index.php?id=$slug$edit"; if ($echo) { echo $url; } else { diff --git a/pages.php b/pages.php index ad2a84f..d45cdec 100644 --- a/pages.php +++ b/pages.php @@ -11,7 +11,30 @@ define("PAGES", [ "navbar" => true, "icon" => "fas fa-home" ], + "sites" => [ + "title" => "sites", + "navbar" => true, + "icon" => "fas fa-sitemap" + ], + "sitesettings" => [ + "title" => "settings", + "styles" => [ + "static/css/themeselector.css" + ], + "scripts" => [ + "static/js/sitesettings.js" + ] + ], + "editor" => [ + "title" => "editor", + "styles" => [ + "static/css/editorparent.css" + ], + "scripts" => [ + "static/js/editorparent.js" + ] + ], "404" => [ "title" => "404 error" ] -]); \ No newline at end of file +]); diff --git a/pages/editor.php b/pages/editor.php new file mode 100644 index 0000000..d197353 --- /dev/null +++ b/pages/editor.php @@ -0,0 +1,71 @@ +has('sites', ['siteid' => $VARS['siteid']])) { + $sitedata = $database->get( + 'sites', [ + 'siteid', + 'sitename', + 'url', + 'theme', + 'color' + ], [ + 'siteid' => $VARS['siteid'] + ]); + $pagedata = $database->select( + 'pages', [ + "pageid", + "slug", + "title", + "template" + ], ["siteid" => $VARS['siteid']] + ); + $slug = "index"; + if (isset($VARS['slug']) && $database->has('pages', ["AND" => ['slug' => $VARS['slug'], 'siteid' => $VARS['siteid']]])) { + $slug = $VARS['slug']; + } + } else { + header('Location: app.php?page=sites'); + die(); + } +} else { + header('Location: app.php?page=sites'); + die(); +} +?> +
+
+
+ +
+
+
+ + +
+ +
+ +
+
+
+
+ + \ No newline at end of file diff --git a/pages/sites.php b/pages/sites.php new file mode 100644 index 0000000..4adf6e4 --- /dev/null +++ b/pages/sites.php @@ -0,0 +1,60 @@ + +
+ +
+ + + + + + + + + + + + select('sites', [ + 'siteid', + 'sitename', + 'url', + 'theme', + 'color' + ]); + foreach ($sites as $site) { + $theme = json_decode(file_get_contents("public/themes/".$site['theme']."/theme.json"), true); + $themename = $theme["name"]; + ?> + + + + + + + + + + + + + + + + + + +
+ + + +
\ No newline at end of file diff --git a/pages/sitesettings.php b/pages/sitesettings.php new file mode 100644 index 0000000..92ef9df --- /dev/null +++ b/pages/sitesettings.php @@ -0,0 +1,97 @@ +has('sites', ['siteid' => $VARS['siteid']])) { + $sitedata = $database->select( + 'sites', [ + 'siteid', + 'sitename', + 'url', + 'theme', + 'color' + ], [ + 'siteid' => $VARS['siteid'] + ])[0]; + } else { + header('Location: app.php?page=sites'); + } +} else { + header('Location: app.php?page=sites'); +} +?> + +
+
+

+ "" . htmlspecialchars($sitedata['sitename']) . ""]); ?> +

+
+
+ + +
+
+ + +
+
+
+
+ +
+ + + +
+
+
+
+
+ + + + + + +
+
\ No newline at end of file diff --git a/public/index.php b/public/index.php index d542b2d..f3448d2 100644 --- a/public/index.php +++ b/public/index.php @@ -19,12 +19,13 @@ include __DIR__ . "/themes/$theme/$template.php"; if (isset($_GET['edit'])) { ?> - + + "); - + $(".sw-editable").each(function () { // Remove leading whitespace added by the template $(this).html($(this).html().trim()); @@ -20,7 +39,7 @@ $(document).ready(function () { ['fontsize', ['fontsize']], ['para', ['ul', 'ol']], ['insert', ['link', 'picture']], - ['misc', ['undo', 'redo', 'fullscreen', 'codeview']] + ['misc', ['undo', 'redo', 'codeview']] ], placeholder: 'Click to edit' }); @@ -30,21 +49,11 @@ $(document).ready(function () { var component = $(this).data("component"); $(this).html(""); }); -}); -function saveEdits() { - var components = []; - $(".sw-editable").each(function (e) { - components[$(this).data("component")] = $(this).summernote('code'); - }); - $(".sw-text-input").each(function (e) { - components[$(this).data("component")] = $(this).val(); - }); - var content = JSON.stringify(components); - console.log(components); - $.post(save_url, { - action: "saveedits", - page: "", - content: content + window.addEventListener('message', function (event) { + console.log("editor: received message: " + event.data); + if (event.data == "save") { + saveEdits(); + } }); -} \ No newline at end of file +}); \ No newline at end of file diff --git a/static/js/editorparent.js b/static/js/editorparent.js new file mode 100644 index 0000000..abee9ff --- /dev/null +++ b/static/js/editorparent.js @@ -0,0 +1,38 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +function save(json) { + var output = JSON.parse(json); + console.log(output); + $.post("action.php", { + action: "saveedits", + source: "editor", + slug: output["slug"], + site: output["site"], + content: output["content"] + }, function (data) { + if (data.status == "OK") { + alert("Saved"); + } else { + alert(data.msg); + } + }); +} + +window.addEventListener('message', function (event) { + //console.log("parent: received message: " + event.data); + if (event.data.startsWith("save ")) { + save(event.data.slice(5)); + } +}); + +$("#savebtn").click(function () { + triggerSave(); +}); + +function triggerSave() { + document.getElementById("editorframe").contentWindow.postMessage("save", "*"); +} \ No newline at end of file diff --git a/static/js/sitesettings.js b/static/js/sitesettings.js new file mode 100644 index 0000000..7e3b16d --- /dev/null +++ b/static/js/sitesettings.js @@ -0,0 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +$('#name').on('input propertychange paste', function () { + $('#name_title').text($('#name').val()); +}); \ No newline at end of file