Add basic page editing and saving in control panel
parent
b377e57b5d
commit
aef29f18ab
Binary file not shown.
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../required.php';
|
||||||
|
|
||||||
|
redirectifnotloggedin();
|
||||||
|
|
||||||
|
if (!is_empty($VARS['siteid'])) {
|
||||||
|
if ($database->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();
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<div class="col-12 col-sm-6 col-md-4">
|
||||||
|
<div class="btn btn-success" id="savebtn">
|
||||||
|
<i class="fas fa-save"></i> <?php lang("save"); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form method="GET" action="app.php" class="col-12 col-sm-6 col-md-4">
|
||||||
|
<input type="hidden" name="page" value="editor" />
|
||||||
|
<input type="hidden" name="siteid" value="<?php echo $VARS['siteid']; ?>" />
|
||||||
|
<div class="input-group">
|
||||||
|
<select name="slug" class="form-control">
|
||||||
|
<?php
|
||||||
|
foreach ($pagedata as $p) {
|
||||||
|
$selected = "";
|
||||||
|
if ($slug == $p['slug']) {
|
||||||
|
$selected = " selected";
|
||||||
|
}
|
||||||
|
echo "<option value=\"" . $p['slug'] . "\"$selected>" . $p['title'] . ' (' . $p['slug'] . ')' . "</option>\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<div class="input-group-append">
|
||||||
|
<button type="submit" class="btn btn-primary"><?php lang("edit"); ?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<iframe id="editorframe" src="public/index.php?id=<?php echo $slug; ?>&edit"></iframe>
|
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../required.php';
|
||||||
|
|
||||||
|
redirectifnotloggedin();
|
||||||
|
?>
|
||||||
|
<div class="btn-group">
|
||||||
|
<a href="app.php?page=addsite" class="btn btn-success"><i class="fas fa-plus"></i> <?php lang("new site"); ?></a>
|
||||||
|
</div>
|
||||||
|
<table id="cattable" class="table table-bordered table-hover table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th data-priority="0"></th>
|
||||||
|
<th data-priority="1"><?php lang('actions'); ?></th>
|
||||||
|
<th data-priority="1"><i class="fas fa-font d-none d-md-inline"></i> <?php lang('site name'); ?></th>
|
||||||
|
<th data-priority="2"><i class="fas fa-globe d-none d-md-inline"></i> <?php lang('url'); ?></th>
|
||||||
|
<th data-priority="3"><i class="fas fa-paint-brush d-none d-md-inline"></i> <?php lang('theme'); ?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
$sites = $database->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"];
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td>
|
||||||
|
<a class="btn btn-primary btn-sm" href="app.php?page=editor&siteid=<?php echo $site['siteid']; ?>"><i class="fas fa-edit"></i> <?php lang("editor"); ?></a>
|
||||||
|
<a class="btn btn-secondary btn-sm" href="app.php?page=sitesettings&siteid=<?php echo $site['siteid']; ?>"><i class="fas fa-cog"></i> <?php lang("settings"); ?></a>
|
||||||
|
<a class="btn btn-info btn-sm" href="<?php echo $site['url']; ?>" target="_BLANK"><i class="fas fa-eye"></i> <?php lang("view"); ?></a>
|
||||||
|
</td>
|
||||||
|
<td><?php echo $site['sitename']; ?></td>
|
||||||
|
<td><?php echo $site['url']; ?></td>
|
||||||
|
<td><?php echo $themename; ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th data-priority="0"></th>
|
||||||
|
<th data-priority="1"><?php lang('actions'); ?></th>
|
||||||
|
<th data-priority="1"><i class="fas fa-font d-none d-md-inline"></i> <?php lang('site name'); ?></th>
|
||||||
|
<th data-priority="2"><i class="fas fa-globe d-none d-md-inline"></i> <?php lang('url'); ?></th>
|
||||||
|
<th data-priority="3"><i class="fas fa-paint-brush d-none d-md-inline"></i> <?php lang('theme'); ?></th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../required.php';
|
||||||
|
|
||||||
|
redirectifnotloggedin();
|
||||||
|
|
||||||
|
if (!is_empty($VARS['siteid'])) {
|
||||||
|
if ($database->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');
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form role="form" action="action.php" method="POST">
|
||||||
|
<div class="card border-light-blue">
|
||||||
|
<h3 class="card-header text-light-blue">
|
||||||
|
<i class="fas fa-edit"></i> <?php lang2("editing site", ['site' => "<span id=\"name_title\">" . htmlspecialchars($sitedata['sitename']) . "</span>"]); ?>
|
||||||
|
</h3>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name"><i class="fas fa-font"></i> <?php lang("name"); ?></label>
|
||||||
|
<input type="text" class="form-control" id="name" name="name" placeholder="Foo Bar" required="required" value="<?php echo htmlspecialchars($sitedata['sitename']); ?>" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="url"><i class="fas fa-globe"></i> <?php lang("url"); ?></label>
|
||||||
|
<input type="text" class="form-control" id="url" name="url" placeholder="https://example.com" required="required" value="<?php echo htmlspecialchars($sitedata['url']); ?>" />
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="style"><i class="fas fa-paint-brush"></i> <?php lang('theme'); ?></label>
|
||||||
|
<div class="theme_bin">
|
||||||
|
<?php
|
||||||
|
$themedir = __DIR__ . "/../public/themes/";
|
||||||
|
$themes = array_diff(scandir($themedir), array('..', '.'));
|
||||||
|
foreach ($themes as $t) {
|
||||||
|
if (!file_exists($themedir . "$t/theme.json")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$info = json_decode(file_get_contents($themedir . "$t/theme.json"), TRUE);
|
||||||
|
$ts = $sitedata["theme"] == $t ? " checked" : "";
|
||||||
|
?>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="style" value="<?php echo $t; ?>" <?php echo $ts; ?> />
|
||||||
|
<div class="card theme">
|
||||||
|
<div class="card-body m-0 p-1">
|
||||||
|
<b><?php echo $info['name']; ?></b><br />
|
||||||
|
<?php
|
||||||
|
lang("theme type");
|
||||||
|
echo ": ";
|
||||||
|
if ($info['singlepage'] == true) {
|
||||||
|
lang("single page");
|
||||||
|
} else {
|
||||||
|
lang("multiple page");
|
||||||
|
}
|
||||||
|
?><br />
|
||||||
|
<?php lang("templates");
|
||||||
|
echo ": " . count($info['templates']);
|
||||||
|
?><br />
|
||||||
|
<?php lang("color styles");
|
||||||
|
echo ": " . count($info['colors']);
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" name="siteid" value="<?php echo htmlspecialchars($VARS['siteid']); ?>" />
|
||||||
|
<input type="hidden" name="action" value="sitesettings" />
|
||||||
|
<input type="hidden" name="source" value="sites" />
|
||||||
|
|
||||||
|
<div class="card-footer d-flex">
|
||||||
|
<button type="submit" class="btn btn-success mr-auto"><i class="fas fa-save"></i> <?php lang("save"); ?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
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/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#editorframe {
|
||||||
|
border: 1px solid black;
|
||||||
|
width: 100%;
|
||||||
|
height: 1000px;
|
||||||
|
max-height: calc(100vh - 200px);
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
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/.
|
||||||
|
*/
|
||||||
|
.theme_bin {
|
||||||
|
max-height: 300px;
|
||||||
|
overflow-y: scroll;
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme_bin label input[type=radio] {
|
||||||
|
visibility: hidden;
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme_bin label input[type=radio] + .theme {
|
||||||
|
cursor: pointer;
|
||||||
|
border: 3px solid white;
|
||||||
|
margin: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme_bin label input[type=radio]:checked + .theme {
|
||||||
|
border: 3px solid rgba(0,0,0,.8);
|
||||||
|
}
|
@ -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", "*");
|
||||||
|
}
|
@ -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());
|
||||||
|
});
|
Loading…
Reference in New Issue