Add page settings editor
This commit is contained in:
parent
a14f9e0a63
commit
a718bba8be
32
action.php
32
action.php
@ -67,7 +67,37 @@ switch ($VARS['action']) {
|
||||
returnToSender("template_missing", $VARS['siteid']);
|
||||
}
|
||||
$database->insert("pages", ["slug" => $slug, "siteid" => $VARS['siteid'], "title" => $VARS['title'], "template" => $VARS['template']]);
|
||||
returnToSender("page_added", $VARS['siteid']);
|
||||
returnToSender("page_added", $VARS['siteid'] . "|" . $database->id());
|
||||
break;
|
||||
case "pagesettings":
|
||||
if (is_empty($VARS['siteid']) || !$database->has("sites", ["siteid" => $VARS['siteid']])) {
|
||||
returnToSender("invalid_parameters");
|
||||
}
|
||||
if (is_empty($VARS['pageid']) || !$database->has("pages", ["AND" => ["pageid" => $VARS['pageid'], "siteid" => $VARS['siteid']]])) {
|
||||
returnToSender("invalid_parameters");
|
||||
}
|
||||
if (is_empty($VARS['title'])) {
|
||||
returnToSender("invalid_parameters", $VARS['siteid']);
|
||||
}
|
||||
if (is_empty($VARS['template'])) {
|
||||
returnToSender("invalid_parameters", $VARS['siteid']);
|
||||
}
|
||||
$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->update(
|
||||
"pages", [
|
||||
"title" => $VARS['title'],
|
||||
"template" => $VARS['template']
|
||||
], [
|
||||
"AND" => [
|
||||
"siteid" => $VARS['siteid'],
|
||||
"pageid" => $VARS['pageid']
|
||||
]
|
||||
]);
|
||||
returnToSender("settings_saved", $VARS['siteid'] . "|" . $VARS['pageid']);
|
||||
break;
|
||||
case "sitesettings":
|
||||
if (!is_empty($VARS['siteid'])) {
|
||||
|
@ -65,4 +65,5 @@ define("STRINGS", [
|
||||
"title" => "Title",
|
||||
"page id" => "Page ID (slug)",
|
||||
"add page" => "Add page",
|
||||
"page settings" => "Page Settings"
|
||||
]);
|
@ -10,6 +10,13 @@ redirectifnotloggedin();
|
||||
if (!is_empty($VARS['arg'])) {
|
||||
// Allow action.php to do a better redirect
|
||||
$VARS['siteid'] = $VARS['arg'];
|
||||
if (strpos($VARS['arg'], "|") !== FALSE) {
|
||||
$arg = explode("|", $VARS['arg'], 2);
|
||||
$VARS['siteid'] = $arg[0];
|
||||
if ($database->has("pages", ["AND" => ["siteid" => $VARS['siteid'], "pageid" => $arg[1]]])) {
|
||||
$VARS['slug'] = $database->get("pages", "slug", ["AND" => ["siteid" => $VARS['siteid'], "pageid" => $arg[1]]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_empty($VARS['siteid'])) {
|
||||
@ -36,6 +43,14 @@ if (!is_empty($VARS['siteid'])) {
|
||||
if (isset($VARS['slug']) && $database->has('pages', ["AND" => ['slug' => $VARS['slug'], 'siteid' => $VARS['siteid']]])) {
|
||||
$slug = $VARS['slug'];
|
||||
}
|
||||
$thispage = $database->get(
|
||||
'pages', [
|
||||
"pageid",
|
||||
"slug",
|
||||
"title",
|
||||
"template"
|
||||
], ["AND" => ["siteid" => $VARS['siteid'], "slug" => $slug]]
|
||||
);
|
||||
} else {
|
||||
header('Location: app.php?page=sites');
|
||||
die();
|
||||
@ -46,11 +61,54 @@ if (!is_empty($VARS['siteid'])) {
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="modal fade" id="pageSettingsModal" tabindex="-1" role="dialog" aria-labelledby="pageSettingsLabel" 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="pageSettingsLabel"><i class="fas fa-cog"></i> <?php lang("page settings"); ?></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body" id="pageSettingsModalBody">
|
||||
<div class="form-group">
|
||||
<label><i class="fas fa-font"></i> <?php lang("title"); ?></label>
|
||||
<input type="text" id="pageSettingsTitle" name="title" class="form-control" required="required" minlength="1" maxlength="200" value="<?php echo $thispage['title']; ?>" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label><i class="fas fa-paint-brush"></i> <?php lang("template"); ?></label>
|
||||
<select id="pageSettingsTemplate" 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) {
|
||||
$selected = "";
|
||||
if ($thispage['template'] == $name) {
|
||||
$selected = " selected";
|
||||
}
|
||||
echo "<option value=\"" . $name . "\"$selected>" . $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="pageid" value="<?php echo $thispage['pageid']; ?>" />
|
||||
<input type="hidden" name="action" value="pagesettings" />
|
||||
<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="pageSettingsModalSave"><i class="fas fa-save"></i> <?php lang("save"); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<h5 class="modal-title" id="newPageLabel"><i class="fas fa-plus"></i> <?php lang("new page"); ?></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
@ -133,11 +191,14 @@ if (!is_empty($VARS['siteid'])) {
|
||||
<div class="btn btn-success" id="savebtn">
|
||||
<i class="fas fa-save"></i> <?php lang("save"); ?>
|
||||
</div>
|
||||
<div class="btn btn-secondary" id="pagesettingsbtn">
|
||||
<i class="fas fa-cog"></i> <?php lang("settings"); ?>
|
||||
</div>
|
||||
<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"); ?>
|
||||
</a>
|
||||
<div class="btn btn-primary" id="newpagebtn">
|
||||
<i class="fas fa-plus"></i> <?php lang("new page"); ?>
|
||||
<i class="fas fa-plus"></i> <?php lang("new"); ?>
|
||||
</div>
|
||||
</div>
|
||||
<span class="badge badge-success d-none" id="savedBadge"><i class="fas fa-check"></i> <?php lang("saved"); ?></span>
|
||||
|
@ -100,4 +100,8 @@ function triggerSave() {
|
||||
|
||||
$("#newpagebtn").click(function () {
|
||||
$("#newPageModal").modal();
|
||||
});
|
||||
|
||||
$("#pagesettingsbtn").click(function () {
|
||||
$("#pageSettingsModal").modal();
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user