Build out CMS frontend, add Bootstrap theme, add WYSIWYG editing

master
Skylar Ittner 6 years ago
parent 1897f4984b
commit 7fa0c00cda

@ -31,6 +31,9 @@ function returnToSender($msg, $arg = "") {
}
switch ($VARS['action']) {
case "saveedits":
$page = $VARS['page'];
$content = $VARS['content'];
case "signout":
session_destroy();
header('Location: index.php');

Binary file not shown.

@ -0,0 +1,111 @@
<?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/. */
/**
* This file contains global settings and utility functions.
*/
ob_start(); // allow sending headers after content
// Settings file
require __DIR__ . '/../settings.php';
if (!DEBUG) {
error_reporting(0);
} else {
error_reporting(E_ALL);
ini_set('display_errors', 'On');
}
// Unicode, solves almost all stupid encoding problems
header('Content-Type: text/html; charset=utf-8');
// Strip PHP version
header('X-Powered-By: PHP');
// Security
header('X-Content-Type-Options: nosniff');
header('X-XSS-Protection: 1; mode=block');
header('X-Frame-Options: "DENY"');
header('Referrer-Policy: "no-referrer, strict-origin-when-cross-origin"');
$SECURE_NONCE = base64_encode(random_bytes(8));
//
// Composer
require __DIR__ . '/../vendor/autoload.php';
/**
* Kill off the running process and spit out an error message
* @param string $error error message
*/
function sendError($error) {
global $SECURE_NONCE;
die("<!DOCTYPE html>"
. "<meta charset=\"UTF-8\">"
. "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"
. "<title>Error</title>"
. "<style nonce=\"" . $SECURE_NONCE . "\">"
. "h1 {color: red; font-family: sans-serif; font-size: 20px; margin-bottom: 0px;} "
. "h2 {font-family: sans-serif; font-size: 16px;} "
. "p {font-family: monospace; font-size: 14px; width: 100%; wrap-style: break-word;} "
. "i {font-size: 12px;}"
. "</style>"
. "<h1>A fatal application error has occurred.</h1>"
. "<i>(This isn't your fault.)</i>"
. "<h2>Details:</h2>"
. "<p>" . htmlspecialchars($error) . "</p>");
}
date_default_timezone_set(TIMEZONE);
// Database settings
// Also inits database and stuff
use Medoo\Medoo;
$database;
try {
$database = new Medoo([
'database_type' => DB_TYPE,
'database_name' => DB_NAME,
'server' => DB_SERVER,
'username' => DB_USER,
'password' => DB_PASS,
'charset' => DB_CHARSET
]);
} catch (Exception $ex) {
//header('HTTP/1.1 500 Internal Server Error');
sendError("Database error. Try again later. $ex");
}
function getdatabase() {
global $database;
return $database;
}
function getsiteid() {
global $database;
return $database->get("sites", "siteid");
}
function getpageslug() {
global $database;
if (isset($_GET['id'])) {
$id = $_GET['id'];
} else {
$id = "index";
}
if ($database->has("pages", ["AND" => ["slug" => $id, "siteid" => getsiteid()]])) {
return $id;
}
return null;
}
function getpagetemplate() {
global $database;
$slug = getpageslug();
if (!is_null($slug)) {
return $database->get("pages", "template", ["AND" => ["slug" => $slug, "siteid" => getsiteid()]]);
}
return "404";
}

@ -0,0 +1,149 @@
<?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__ . "/requiredpublic.php";
function get_site_name($echo = true) {
$db = getdatabase();
$title = $db->get('sites', "sitename", ["siteid" => getsiteid()]);
if ($echo) {
echo $title;
} else {
return $title;
}
}
function get_site_url($echo = true) {
$db = getdatabase();
$url = $db->get('sites', "url", ["siteid" => getsiteid()]);
if ($echo) {
echo $url;
} else {
return $url;
}
}
function get_page_title($echo = true) {
$db = getdatabase();
$title = $db->get("pages", "title", ["AND" => ["slug" => getpageslug(), "siteid" => getsiteid()]]);
if ($echo) {
echo $title;
} else {
return $title;
}
}
function get_page_clean_title($echo = true) {
$title = strip_tags(get_page_title(false));
if ($echo) {
echo $title;
} else {
return $title;
}
}
function get_page_slug($echo = true) {
if ($echo) {
echo getpageslug();
} else {
return getpageslug();
}
}
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";
if ($echo) {
echo $url;
} else {
return $url;
}
}
function get_component($name, $context = null, $echo = true) {
$db = getdatabase();
if ($context == null) {
$context = get_page_slug(false);
}
$pageid = $db->get("pages", "pageid", ["AND" => ["slug" => $context, "siteid" => getsiteid()]]);
$content = "";
if ($db->has("components", ["AND" => ["pageid" => $pageid, "name" => $name]])) {
$content = $db->get("components", "content", ["AND" => ["pageid" => $pageid, "name" => $name]]);
}
if ($echo) {
echo $content;
} else {
return $content;
}
}
function get_page_content($slug = null) {
get_component("content", $slug);
}
function get_header() {
}
function get_theme_url($echo = true) {
$db = getdatabase();
$site = $db->get('sites', ["sitename", "url", "theme"], ["siteid" => getsiteid()]);
$url = $site["url"] . "themes/" . $site["theme"];
if ($echo) {
echo $url;
} else {
return $url;
}
}
function get_theme_color_url($echo = true) {
$db = getdatabase();
$site = $db->get('sites', ["sitename", "url", "theme", "color"], ["siteid" => getsiteid()]);
if ($site["color"] == null) {
$site["color"] = "default";
}
if (!file_exists(__DIR__ . "/../public/themes/" . $site["theme"] . "/colors/" . $site['color'])) {
$site['color'] = "default";
}
$url = $site["url"] . "themes/" . $site["theme"] . "/colors/" . $site["color"];
if ($echo) {
echo $url;
} else {
return $url;
}
}
function get_navigation($currentpage = null, $classPrefix = "", $liclass = "", $currentclass = "current", $linkclass = "", $currentlinkclass = "active") {
$db = getdatabase();
$pages = $db->select('pages', ['pageid', 'parentid', 'slug', 'nav'], ["AND" => ["siteid" => getsiteid(), "nav[!]" => null], "ORDER" => ["navorder" => "ASC"]]);
if (is_null($currentpage)) {
$current = getpageslug();
} else {
$current = $currentpage;
}
foreach ($pages as $p) {
$class = $classPrefix . $p['slug'] . " $liclass";
$aclass = $linkclass;
if ($p['slug'] == $current) {
$class .= " $currentclass";
$aclass .= " $currentlinkclass";
}
echo '<li class="' . $class . '">'
. '<a class="' . $aclass . '" href="' . get_page_url(false, $p['slug']) . '">'
. $p['nav']
. '</a>'
. '</li>' . "\n";
}
}
function return_site_ver() {
// Stub for GetSimple
return "SiteWriter";
}

@ -0,0 +1,9 @@
<?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/.
*/
// TODO: Allow access to an uploaded files directory via this script.

@ -0,0 +1,31 @@
<?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__ . "/../lib/requiredpublic.php";
require_once __DIR__ . "/../lib/themefunctions.php";
if (!getsiteid()) {
sendError("No website has been created yet. Please open " . SITE_TITLE . " and make one.");
}
$theme = $database->get("sites", "theme", ["siteid" => getsiteid()]);
$template = getpagetemplate();
include __DIR__ . "/themes/$theme/$template.php";
if (isset($_GET['edit'])) {
?>
<link href="<?php echo URL; ?>/static/css/summernote-lite.css" rel="stylesheet" />
<script src="<?php echo URL; ?>/static/js/summernote-lite.js"></script>
<script src="<?php echo URL; ?>/static/js/editor.js"></script>
<script>
var save_url = "<?php echo URL; ?>/action.php";
var page_slug = "<?php getpageslug(); ?>";
</script>
<?php
}
?>

@ -0,0 +1,27 @@
<?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/.
*/
include __DIR__ . "/inc/header.inc.php";
?>
<main role="main" class="mt-5">
<div class="jumbotron">
<div class="container">
<h1 class="display-4">404 Page Not Found</h1>
<div class="ml-2 lead">
The requested page could not be found.
</div>
</div>
</div>
<div class="container">
</div>
</main>
<?php
include __DIR__ . "/inc/footer.inc.php";
?>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1,40 @@
<?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/.
*/
include __DIR__ . "/inc/header.inc.php";
?>
<main role="main" class="mt-5">
<div class="jumbotron">
<div class="container">
<h1 class="display-4"><?php get_page_title(); ?></h1>
<p class="ml-2 lead sw-editable" data-component="lead"><?php get_component("lead"); ?></p>
</div>
</div>
<div class="container">
<form action="<?php get_site_url(); ?>/contact.php" method="POST">
<div class="row">
<div class="col-12 col-md-6 mb-3">
<label for="name">Name</label>
<input type="text" class="form-control" name="name" id="name" placeholder="" required />
</div>
<div class="col-12 col-md-6 mb-3">
<label for="email">Email</label>
<input type="email" class="form-control" name="email" id="email" placeholder="you@example.com" required />
</div>
<div class="col-12">
<label for="message">Message</label>
<textarea class="form-control" name="message" id="message" placeholder="" required ></textarea>
</div>
</div>
</form>
</div>
</main>
<?php
include __DIR__ . "/inc/footer.inc.php";
?>

@ -0,0 +1,31 @@
<?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/.
*/
include __DIR__ . "/inc/header.inc.php";
?>
<main role="main" class="mt-5">
<div class="jumbotron">
<div class="container">
<h1 class="display-4"><?php get_page_title(); ?></h1>
<div class="ml-2 lead">
<div class="sw-editable" data-component="lead">
<?php get_component("lead"); ?>
</div>
</div>
</div>
</div>
<div class="container">
<div class="sw-editable" data-component="content">
<?php get_page_content(); ?>
</div>
</div>
</main>
<?php
include __DIR__ . "/inc/footer.inc.php";
?>

@ -0,0 +1,45 @@
<?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/.
*/
include __DIR__ . "/inc/header.inc.php";
?>
<main role="main" class="mt-5">
<div class="jumbotron">
<div class="container">
<h1 class="display-4"><?php get_page_title(); ?></h1>
<div class="ml-2 lead">
<div class="sw-editable" data-component="lead">
<?php get_component("lead"); ?>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="sw-editable" data-component="cardrow-1">
<?php get_component("cardrow-1"); ?>
</div>
</div>
<div class="col-md-4">
<div class="sw-editable" data-component="cardrow-2">
<?php get_component("cardrow-2"); ?>
</div>
</div>
<div class="col-md-4">
<div class="sw-editable" data-component="cardrow-3">
<?php get_component("cardrow-3"); ?>
</div>
</div>
</div>
</div>
</main>
<?php
include __DIR__ . "/inc/footer.inc.php";
?>

@ -0,0 +1,12 @@
<?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/.
*/
?>
<script src="<?php get_theme_url(); ?>/assets/jquery-3.3.1.slim.min.js"></script>
<script src="<?php get_theme_url(); ?>/assets/popper.min.js"></script>
<script src="<?php get_theme_url(); ?>/assets/bootstrap.min.js"></script>

@ -0,0 +1,25 @@
<?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/.
*/
?>
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="<?php get_theme_color_url(); ?>/bootstrap.min.css" />
<title><?php get_site_name(); ?></title>
<?php get_header(); ?>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-primary">
<a class="navbar-brand" href="<?php get_site_url(); ?>"><?php get_site_name(); ?></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapse" aria-controls="navbar-collapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="navbar-nav mr-auto">
<?php get_navigation(null, "", "nav-item", "active", "nav-link"); ?>
</ul>
</div>
</nav>

@ -0,0 +1,107 @@
{
"name": "Bootstrap",
"templates": {
"default": {
"title": "Default",
"description": "A regular page."
},
"home": {
"title": "Home",
"description": "A homepage."
},
"contact": {
"title": "Contact",
"description": "A page with a contact form."
}
},
"colors": {
"default": {
"title": "Default",
"description": "Standard Bootstrap theme"
},
"cerulean": {
"title": "Cerulean",
"description": "A calm blue sky"
},
"cosmo": {
"title": "Cosmo",
"description": "An ode to Metro"
},
"cyborg": {
"title": "Cyborg",
"description": "Jet black and electric blue"
},
"darkly": {
"title": "Darkly",
"description": "Flatly in night mode"
},
"flatly": {
"title": "Flatly",
"description": "Flat and modern"
},
"journal": {
"title": "Journal",
"description": "Crisp like a new sheet of paper"
},
"litera": {
"title": "Litera",
"description": "The medium is the message"
},
"lumen": {
"title": "Lumen",
"description": "Light and shadow"
},
"lux": {
"title": "Lux",
"description": "A touch of class"
},
"materia": {
"title": "Materia",
"description": "Material is the metaphor"
},
"minty": {
"title": "Minty",
"description": "A fresh feel"
},
"pulse": {
"title": "Pulse",
"description": "A trace of purple"
},
"sandstone": {
"title": "Sandstone",
"description": "A touch of warmth"
},
"simplex": {
"title": "Simplex",
"description": "Mini and minimalist"
},
"sketchy": {
"title": "Sketchy",
"description": "A hand-drawn look for mockups and mirth"
},
"slate": {
"title": "Slate",
"description": "Shades of gunmetal gray"
},
"solar": {
"title": "Solar",
"description": "A spin on Solarized"
},
"spacelab": {
"title": "Spacelab",
"description": "Silvery and sleek"
},
"superhero": {
"title": "Superhero",
"description": "The brave and the blue"
},
"united": {
"title": "United",
"description": "Ubuntu orange and unique font"
},
"yeti": {
"title": "Yeti",
"description": "A friendly foundation"
}
}
}

@ -32,7 +32,10 @@ define("PORTAL_KEY", "123");
define("TIMEZONE", "America/Denver");
// Base URL for site links.
define('URL', '.');
define('URL', '/sitewriter');
// Folder for public files
define('FILE_UPLOAD_PATH', __DIR__ . '/public/files');
// Use Captcheck on login screen
// https://captcheck.netsyms.com

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

@ -0,0 +1,31 @@
/*
* 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/.
*/
$(".sw-editable").summernote({
airMode: false,
toolbar: [
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough', 'superscript', 'subscript']],
['fontsize', ['fontsize']],
['para', ['ul', 'ol']],
['insert', ['link', 'picture']],
['misc', ['undo', 'redo', 'fullscreen', 'codeview']]
],
placeholder: 'Click to edit'
});
function saveEdits() {
var components = [];
$(".sw-editable").each(function (e) {
components[$(this).data("component")] = $(this).html();
});
var content = JSON.stringify(components);
$.post(save_url, {
action: "saveedits",
page: "",
content: content
});
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save