Add page creation
This commit is contained in:
parent
3db76c4d49
commit
a14f9e0a63
40
action.php
40
action.php
@ -31,6 +31,44 @@ function returnToSender($msg, $arg = "") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch ($VARS['action']) {
|
switch ($VARS['action']) {
|
||||||
|
case "newpage":
|
||||||
|
if (is_empty($VARS['siteid']) || !$database->has("sites", ["siteid" => $VARS['siteid']])) {
|
||||||
|
returnToSender("invalid_parameters");
|
||||||
|
}
|
||||||
|
if (is_empty($VARS['title'])) {
|
||||||
|
returnToSender("invalid_parameters", $VARS['siteid']);
|
||||||
|
}
|
||||||
|
if (!is_empty($VARS['slug'])) {
|
||||||
|
$slug = strtolower($VARS['slug']);
|
||||||
|
$slug = preg_replace("/[^[:alnum:][:space:]]/u", '', $slug);
|
||||||
|
$slug = preg_replace("/[[:space:]]/u", '-', $slug);
|
||||||
|
if ($database->has("pages", ["AND" => ["siteid" => $VARS['siteid'], "slug" => $VARS['slug']]])) {
|
||||||
|
returnToSender("slug_taken", $VARS['siteid']);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Auto-generate a slug
|
||||||
|
$slug = strtolower($VARS['title']);
|
||||||
|
$slug = preg_replace("/[^[:alnum:][:space:]]/u", '', $slug);
|
||||||
|
$slug = preg_replace("/[[:space:]]/u", '-', $slug);
|
||||||
|
if ($database->has("pages", ["AND" => ["siteid" => $VARS['siteid'], "slug" => $slug]])) {
|
||||||
|
$num = 2;
|
||||||
|
while ($database->has("pages", ["AND" => ["siteid" => $VARS['siteid'], "slug" => $slug . $num]])) {
|
||||||
|
$num++;
|
||||||
|
}
|
||||||
|
$slug = $slug . $num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$template = "default";
|
||||||
|
if (!is_empty($VARS['template'])) {
|
||||||
|
$template = preg_replace("/[^A-Za-z0-9]/", '', $VARS['template']);
|
||||||
|
}
|
||||||
|
$theme = $database->get("sites", "theme", ["siteid" => $VARS['siteid']]);
|
||||||
|
if (!file_exists(__DIR__ . "/public/themes/$theme/$template.php")) {
|
||||||
|
returnToSender("template_missing", $VARS['siteid']);
|
||||||
|
}
|
||||||
|
$database->insert("pages", ["slug" => $slug, "siteid" => $VARS['siteid'], "title" => $VARS['title'], "template" => $VARS['template']]);
|
||||||
|
returnToSender("page_added", $VARS['siteid']);
|
||||||
|
break;
|
||||||
case "sitesettings":
|
case "sitesettings":
|
||||||
if (!is_empty($VARS['siteid'])) {
|
if (!is_empty($VARS['siteid'])) {
|
||||||
if (!$database->has("sites", ["siteid" => $VARS['siteid']])) {
|
if (!$database->has("sites", ["siteid" => $VARS['siteid']])) {
|
||||||
@ -62,7 +100,7 @@ switch ($VARS['action']) {
|
|||||||
$database->insert('sites', ["sitename" => $VARS['name'], "url" => $url, "theme" => $theme, "color" => $color]);
|
$database->insert('sites', ["sitename" => $VARS['name'], "url" => $url, "theme" => $theme, "color" => $color]);
|
||||||
$siteid = $database->id();
|
$siteid = $database->id();
|
||||||
$template = (file_exists(__DIR__ . "/public/themes/$theme/home.php") ? "home" : "default");
|
$template = (file_exists(__DIR__ . "/public/themes/$theme/home.php") ? "home" : "default");
|
||||||
$database->insert('pages', ["slug" => "index", "siteid" => $siteid, "title" => "Home", "nav" => "Home", "navorder" => 1, "template" => "template"]);
|
$database->insert('pages', ["slug" => "index", "siteid" => $siteid, "title" => "Home", "nav" => "Home", "navorder" => 1, "template" => $template]);
|
||||||
} else {
|
} else {
|
||||||
$database->update('sites', ["sitename" => $VARS['name'], "url" => $url, "theme" => $theme, "color" => $color], ["siteid" => $VARS['siteid']]);
|
$database->update('sites', ["sitename" => $VARS['name'], "url" => $url, "theme" => $theme, "color" => $color], ["siteid" => $VARS['siteid']]);
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ define("STRINGS", [
|
|||||||
"single page" => "Single page",
|
"single page" => "Single page",
|
||||||
"multiple page" => "Multiple page",
|
"multiple page" => "Multiple page",
|
||||||
"templates" => "Templates",
|
"templates" => "Templates",
|
||||||
|
"template" => "Template",
|
||||||
"color styles" => "Color styles",
|
"color styles" => "Color styles",
|
||||||
"save" => "Save",
|
"save" => "Save",
|
||||||
"edit" => "Edit",
|
"edit" => "Edit",
|
||||||
@ -56,5 +57,12 @@ define("STRINGS", [
|
|||||||
"text" => "Text",
|
"text" => "Text",
|
||||||
"select page or enter url" => "Select a page or enter URL",
|
"select page or enter url" => "Select a page or enter URL",
|
||||||
"edit component" => "Edit component",
|
"edit component" => "Edit component",
|
||||||
"default" => "Default"
|
"default" => "Default",
|
||||||
|
"page added" => "Page added.",
|
||||||
|
"chosen page id slug already taken" => "Chosen page ID (slug) already taken. Choose another.",
|
||||||
|
"template missing" => "Template missing from theme.",
|
||||||
|
"new page" => "New Page",
|
||||||
|
"title" => "Title",
|
||||||
|
"page id" => "Page ID (slug)",
|
||||||
|
"add page" => "Add page",
|
||||||
]);
|
]);
|
@ -16,5 +16,17 @@ define("MESSAGES", [
|
|||||||
"404_error" => [
|
"404_error" => [
|
||||||
"string" => "page not found",
|
"string" => "page not found",
|
||||||
"type" => "info"
|
"type" => "info"
|
||||||
]
|
],
|
||||||
|
"page_added" => [
|
||||||
|
"string" => "page added",
|
||||||
|
"type" => "success"
|
||||||
|
],
|
||||||
|
"slug_taken" => [
|
||||||
|
"string" => "chosen page id slug already taken",
|
||||||
|
"type" => "danger"
|
||||||
|
],
|
||||||
|
"template_missing" => [
|
||||||
|
"string" => "template missing",
|
||||||
|
"type" => "danger"
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
|
@ -7,6 +7,11 @@ require_once __DIR__ . '/../required.php';
|
|||||||
|
|
||||||
redirectifnotloggedin();
|
redirectifnotloggedin();
|
||||||
|
|
||||||
|
if (!is_empty($VARS['arg'])) {
|
||||||
|
// Allow action.php to do a better redirect
|
||||||
|
$VARS['siteid'] = $VARS['arg'];
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_empty($VARS['siteid'])) {
|
if (!is_empty($VARS['siteid'])) {
|
||||||
if ($database->has('sites', ['siteid' => $VARS['siteid']])) {
|
if ($database->has('sites', ['siteid' => $VARS['siteid']])) {
|
||||||
$sitedata = $database->get(
|
$sitedata = $database->get(
|
||||||
@ -41,6 +46,48 @@ if (!is_empty($VARS['siteid'])) {
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<div class="modal fade" id="newPageModal" tabindex="-1" role="dialog" aria-labelledby="newPageLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<form class="modal-content" action="action.php" method="POST">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="newPageLabel"><?php lang("new page"); ?></h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body" id="newPageModalBody">
|
||||||
|
<div class="form-group">
|
||||||
|
<label><i class="fas fa-font"></i> <?php lang("title"); ?></label>
|
||||||
|
<input type="text" id="newPageTitle" name="title" class="form-control" required="required" minlength="1" maxlength="200" />
|
||||||
|
</div>
|
||||||
|
<!--<div class="form-group">
|
||||||
|
<label><i class="fas fa-link"></i> <?php lang("page id"); ?></label>
|
||||||
|
<input type="text" id="newPageSlug" name="slug" class="form-control" placeholder="" minlength="1" maxlength="200" />
|
||||||
|
</div>-->
|
||||||
|
<div class="form-group">
|
||||||
|
<label><i class="fas fa-paint-brush"></i> <?php lang("template"); ?></label>
|
||||||
|
<select id="newPageTemplate" name="template" class="form-control" required="required">
|
||||||
|
<?php
|
||||||
|
$json = file_get_contents(__DIR__ . "/../public/themes/" . $sitedata['theme'] . "/theme.json");
|
||||||
|
$templates = json_decode($json, true)["templates"];
|
||||||
|
foreach ($templates as $name => $value) {
|
||||||
|
echo "<option value=\"" . $name . "\">" . $value['title'] . "</option>\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<input type="hidden" name="siteid" value="<?php echo $sitedata['siteid']; ?>" />
|
||||||
|
<input type="hidden" name="action" value="newpage" />
|
||||||
|
<input type="hidden" name="source" value="editor" />
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php lang("cancel"); ?></button>
|
||||||
|
<button type="submit" class="btn btn-success" id="newPageModalSave"><i class="fas fa-plus"></i> <?php lang("add page"); ?></button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editLabel" aria-hidden="true">
|
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editLabel" aria-hidden="true">
|
||||||
<div class="modal-dialog" role="document">
|
<div class="modal-dialog" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
@ -89,6 +136,9 @@ if (!is_empty($VARS['siteid'])) {
|
|||||||
<a class="btn btn-info" id="viewbtn" target="_BLANK" href="public/index.php?id=<?php echo $slug; ?>&siteid=<?php echo $VARS['siteid']; ?>">
|
<a class="btn btn-info" id="viewbtn" target="_BLANK" href="public/index.php?id=<?php echo $slug; ?>&siteid=<?php echo $VARS['siteid']; ?>">
|
||||||
<i class="fas fa-eye"></i> <?php lang("view"); ?>
|
<i class="fas fa-eye"></i> <?php lang("view"); ?>
|
||||||
</a>
|
</a>
|
||||||
|
<div class="btn btn-primary" id="newpagebtn">
|
||||||
|
<i class="fas fa-plus"></i> <?php lang("new page"); ?>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span class="badge badge-success d-none" id="savedBadge"><i class="fas fa-check"></i> <?php lang("saved"); ?></span>
|
<span class="badge badge-success d-none" id="savedBadge"><i class="fas fa-check"></i> <?php lang("saved"); ?></span>
|
||||||
<div id="reloadprompt" class="badge badge-info d-none">
|
<div id="reloadprompt" class="badge badge-info d-none">
|
||||||
|
@ -96,4 +96,8 @@ $("#savebtn").click(function () {
|
|||||||
|
|
||||||
function triggerSave() {
|
function triggerSave() {
|
||||||
document.getElementById("editorframe").contentWindow.postMessage("save", "*");
|
document.getElementById("editorframe").contentWindow.postMessage("save", "*");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$("#newpagebtn").click(function () {
|
||||||
|
$("#newPageModal").modal();
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user