diff --git a/action.php b/action.php index b0952d1..7fd4d04 100644 --- a/action.php +++ b/action.php @@ -41,10 +41,19 @@ switch ($VARS['action']) { 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]]); + if (is_array($value)) { + $json = json_encode($value); + if ($database->has("complex_components", ["AND" => ["pageid" => $pageid, "name" => $name]])) { + $database->update("complex_components", ["content" => $json], ["AND" => ["pageid" => $pageid, "name" => $name]]); + } else { + $database->insert("complex_components", ["name" => $name, "content" => $json, "pageid" => $pageid]); + } } else { - $database->insert("components", ["name" => $name, "content" => $value, "pageid" => $pageid]); + 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"])); diff --git a/lang/en_us.php b/lang/en_us.php index 3c3e7d2..6b0116c 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -30,10 +30,11 @@ define("STRINGS", [ "captcha error" => "There was a problem with the CAPTCHA (robot test). Try again.", "actions" => "Actions", "home" => "Home", - "more" => "More", + "editor" => "Editor", "sites" => "Sites", "theme" => "Theme", "name" => "Name", + "new site" => "New Site", "site name" => "Site Name", "url" => "URL", "editing site" => "Editing {site}", @@ -41,5 +42,16 @@ define("STRINGS", [ "single page" => "Single page", "multiple page" => "Multiple page", "templates" => "Templates", - "color styles" => "Color styles" + "color styles" => "Color styles", + "save" => "Save", + "edit" => "Edit", + "view" => "View", + "cancel" => "Cancel", + "save needed" => "Press Save to see recent changes.", + "saved" => "Saved", + "icon" => "Icon", + "link" => "Link", + "text" => "Text", + "select page or enter url" => "Select a page or enter URL", + "edit component" => "Edit component" ]); \ No newline at end of file diff --git a/lib/requiredpublic.php b/lib/requiredpublic.php index 765be8b..e1d7c7e 100644 --- a/lib/requiredpublic.php +++ b/lib/requiredpublic.php @@ -85,6 +85,12 @@ function getdatabase() { function getsiteid() { global $database; + if (isset($_GET['siteid'])) { + $id = preg_replace("/[^0-9]/", '', $_GET['siteid']); + if ($database->has('sites', ["siteid" => $id])) { + return $id; + } + } return $database->get("sites", "siteid"); } @@ -104,6 +110,9 @@ function getpageslug() { function getpagetemplate() { global $database; $slug = getpageslug(); + if (isset($_GET['template'])) { + return preg_replace("/[^A-Za-z0-9]/", '', $_GET['template']); + } if (!is_null($slug)) { return $database->get("pages", "template", ["AND" => ["slug" => $slug, "siteid" => getsiteid()]]); } diff --git a/lib/themefunctions.php b/lib/themefunctions.php index 662d3f1..754320c 100644 --- a/lib/themefunctions.php +++ b/lib/themefunctions.php @@ -63,7 +63,19 @@ function get_page_url($echo = true, $slug = null) { if (isset($_GET['edit'])) { $edit = "&edit"; } - $url = get_site_url(false) . "index.php?id=$slug$edit"; + $theme = ""; + if (isset($_GET['theme'])) { + $theme = "&theme=" . preg_replace("/[^A-Za-z0-9]/", '', $_GET['theme']); + } + $template = ""; + if (isset($_GET['template'])) { + $template = "&template=" . preg_replace("/[^A-Za-z0-9]/", '', $_GET['template']); + } + $siteid = ""; + if (isset($_GET['siteid'])) { + $siteid = "&siteid=" . preg_replace("/[^0-9]/", '', $_GET['siteid']); + } + $url = get_site_url(false) . "index.php?id=$slug$edit$theme$template$siteid"; if ($echo) { echo $url; } else { @@ -77,7 +89,10 @@ function get_component($name, $context = null, $echo = true) { $context = get_page_slug(false); } $pageid = $db->get("pages", "pageid", ["AND" => ["slug" => $context, "siteid" => getsiteid()]]); - $content = "Edit me"; + $content = ""; + if (isset($_GET['edit'])) { + $content = "Click here to edit me"; + } if ($db->has("components", ["AND" => ["pageid" => $pageid, "name" => $name]])) { $content = $db->get("components", "content", ["AND" => ["pageid" => $pageid, "name" => $name]]); } @@ -111,13 +126,42 @@ function get_complex_component($name, $context = null) { $context = get_page_slug(false); } $pageid = $db->get("pages", "pageid", ["AND" => ["slug" => $context, "siteid" => getsiteid()]]); - $content = null; + $content = ["icon" => "", "link" => "", "text" => ""]; if ($db->has("complex_components", ["AND" => ["pageid" => $pageid, "name" => $name]])) { $content = json_decode($db->get("complex_components", "content", ["AND" => ["pageid" => $pageid, "name" => $name]]), true); } return $content; } +function get_escaped_json($json, $echo = true) { + $text = htmlspecialchars(json_encode($json), ENT_QUOTES, 'UTF-8'); + if ($echo) { + echo $text; + } else { + return $text; + } +} + +/** + * Detects if a string is a URL or a page slug, and returns something usable for href + * @param string $str + * @param boolean $echo + * @return string + */ +function get_url_or_slug($str, $echo = true) { + $url = $str; + if ($str == "") { + $url = "#"; + } else if (strpos($str, "http") !== 0) { + $url = get_page_url(false, $str); + } + if ($echo) { + echo $url; + } else { + return $url; + } +} + function get_page_content($slug = null) { get_component("content", $slug); } @@ -143,10 +187,10 @@ function get_theme_color_url($echo = true) { if ($site["color"] == null) { $site["color"] = "default"; } - if (!file_exists(__DIR__ . "/../public/themes/" . $site["theme"] . "/colors/" . $site['color'])) { + if (!file_exists(__DIR__ . "/../public/themes/" . SITE_THEME . "/colors/" . $site['color'])) { $site['color'] = "default"; } - $url = $site["url"] . "themes/" . $site["theme"] . "/colors/" . $site["color"]; + $url = $site["url"] . "themes/" . SITE_THEME . "/colors/" . $site["color"]; if ($echo) { echo $url; } else { diff --git a/pages/editor.php b/pages/editor.php index d197353..6f7c58d 100644 --- a/pages/editor.php +++ b/pages/editor.php @@ -40,10 +40,60 @@ if (!is_empty($VARS['siteid'])) { die(); } ?> -