Code Cleanup

This commit is contained in:
Andy Dixon
2024-09-18 21:30:32 +01:00
parent 7bf6d31693
commit a07febc5a6
9 changed files with 136 additions and 112 deletions
+4 -2
View File
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PublishConfigData" remoteFilesAllowedToDisappearOnAutoupload="false">
<component name="PublishConfigData" deleteMissingItems="true" createEmptyFolders="true" remoteFilesAllowedToDisappearOnAutoupload="false" confirmBeforeUploading="false" confirmBeforeDeletion="false">
<option name="confirmBeforeDeletion" value="false" />
<option name="confirmBeforeUploading" value="false" />
<serverData>
<paths name="Hostinger">
<serverdata>
<mappings>
<mapping local="$PROJECT_DIR$" web="/" />
<mapping deploy="/" local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>
+2 -2
View File
@@ -4,11 +4,11 @@ require_once "../init.php";
switch ($_REQUEST["action"]) {
case "save":
if(!empty($_POST['uri']) && !empty($_POST['content'])) {
if (!empty($_POST['uri']) && !empty($_POST['content'])) {
$_SESSION['core']->saveContent($_POST['uri'], $_POST['content']);
die("Page Updated.");
} else {
die('Unable to save page');
}
break;
};
}
+43 -37
View File
@@ -9,17 +9,19 @@ body {
flex-flow: column;
height: 100%;
}
.pageContainer .controls {
flex: 0 1 auto;
height:70px;
background-color:#666666;
height: 70px;
background-color: #666666;
border-bottom: 1px solid #1a1a1a;
-webkit-box-shadow: 0px 10px 13px -7px #000000, -1px -1px 15px 5px rgba(0,0,0,0);
box-shadow: 0px 10px 13px -7px #000000, -1px -1px 15px 5px rgba(0,0,0,0);
-webkit-box-shadow: 0px 10px 13px -7px #000000, -1px -1px 15px 5px rgba(0, 0, 0, 0);
box-shadow: 0px 10px 13px -7px #000000, -1px -1px 15px 5px rgba(0, 0, 0, 0);
}
.pageContainer .frame {
flex: 1 1 auto;
border:0;
border: 0;
}
.controls .logo {
@@ -29,6 +31,7 @@ body {
display: block;
position: absolute;
}
.controls .buttonContainer {
width: 400px;
margin: 18px auto;
@@ -45,52 +48,55 @@ body {
margin: 0;
padding: 0;
}
.controls .buttonContainer li {
display: inline;
margin-right: 10px;
}
.blueButton {
box-shadow:inset 0px 0px 15px 3px #23395e;
background:linear-gradient(to bottom, #2e466e 5%, #415989 100%);
background-color:#2e466e;
border-radius:17px;
border:1px solid #1f2f47;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-family:Arial;
font-size:15px;
padding:6px 13px;
text-decoration:none;
text-shadow:0px 1px 0px #263666;
box-shadow: inset 0px 0px 15px 3px #23395e;
background: linear-gradient(to bottom, #2e466e 5%, #415989 100%);
background-color: #2e466e;
border-radius: 17px;
border: 1px solid #1f2f47;
display: inline-block;
cursor: pointer;
color: #ffffff;
font-family: Arial;
font-size: 15px;
padding: 6px 13px;
text-decoration: none;
text-shadow: 0px 1px 0px #263666;
}
.blueButton:hover {
background:linear-gradient(to bottom, #415989 5%, #2e466e 100%);
background-color:#415989;
background: linear-gradient(to bottom, #415989 5%, #2e466e 100%);
background-color: #415989;
}
.greenButton {
box-shadow:inset 0px 0px 15px 3px #3e7327;
background:linear-gradient(to bottom, #77b55a 5%, #72b352 100%);
background-color:#77b55a;
border-radius:17px;
border:1px solid #4b8f29;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-family:Arial;
font-size:15px;
padding:6px 13px;
text-decoration:none;
text-shadow:0px 1px 0px #5b8a3c;
box-shadow: inset 0px 0px 15px 3px #3e7327;
background: linear-gradient(to bottom, #77b55a 5%, #72b352 100%);
background-color: #77b55a;
border-radius: 17px;
border: 1px solid #4b8f29;
display: inline-block;
cursor: pointer;
color: #ffffff;
font-family: Arial;
font-size: 15px;
padding: 6px 13px;
text-decoration: none;
text-shadow: 0px 1px 0px #5b8a3c;
}
.greenButton:hover {
background:linear-gradient(to bottom, #72b352 5%, #77b55a 100%);
background-color:#72b352;
background: linear-gradient(to bottom, #72b352 5%, #77b55a 100%);
background-color: #72b352;
}
.greenButton:active {
position:relative;
top:1px;
position: relative;
top: 1px;
}
+14 -14
View File
@@ -37,26 +37,26 @@ require_once "init.php";
</div>
<iframe id="frameContainer" src="welcome.html" class="frame"></iframe>
</div>
<!-- Modal -->
<div id="editModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal -->
<div id="editModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Edit Content</h4>
</div>
<div class="modal-body">
<textarea id="editor"></textarea>
</div>
<div class="modal-footer">
<button id="saveBtn" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
<div class="modal-header">
<h4 class="modal-title">Edit Content</h4>
</div>
<div class="modal-body">
<textarea id="editor"></textarea>
</div>
<div class="modal-footer">
<button id="saveBtn" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script src="/cms/js/cms.js"></script>
+14 -12
View File
@@ -4,8 +4,8 @@
* This will be used as well to write to the audit log once it has been implemented in code.
*/
$authentication = [
"admin"=>"password",
"editor"=>"password",
"admin" => "password",
"editor" => "password",
];
/**
@@ -14,23 +14,24 @@ $authentication = [
session_start();
require_once "neoCMSCore.php";
if(empty($_SESSION["core"])) {
if (empty($_SESSION["core"])) {
$_SESSION["core"] = new neoCMSCore();
$_SESSION["core"]->users=$authentication;
$_SESSION["core"]->users = $authentication;
}
if(!$_SESSION["core"]->isLoggedIn() && stripos($_SERVER['REQUEST_URI'],"/login")===FALSE){
if (!$_SESSION["core"]->isLoggedIn() && stripos($_SERVER['REQUEST_URI'], "/login") === FALSE) {
header('Location: /cms/login');
die("Redirecting to login..");
}
// str_starts_with compatibility for php 7
if(!function_exists('str_starts_with')) {
function str_starts_with($haystack,$needle) {
if (!function_exists('str_starts_with')) {
function str_starts_with($haystack, $needle)
{
//str_starts_with(string $haystack, string $needle): bool
$strlen_needle = mb_strlen($needle);
if(mb_substr($haystack,0,$strlen_needle)==$needle) {
if (mb_substr($haystack, 0, $strlen_needle) == $needle) {
return true;
}
return false;
@@ -38,17 +39,18 @@ if(!function_exists('str_starts_with')) {
}
//str_ends_with compatibility for php 7
if(!function_exists('str_ends_with')) {
function str_ends_with($haystack,$needle) {
if (!function_exists('str_ends_with')) {
function str_ends_with($haystack, $needle)
{
//str_starts_with(string $haystack, string $needle): bool
$strlen_needle = mb_strlen($needle);
if(mb_substr($haystack,-$strlen_needle,$strlen_needle)==$needle) {
if (mb_substr($haystack, -$strlen_needle, $strlen_needle) == $needle) {
return true;
}
return false;
}
}
$_SESSION["core"]->version='2.00';
$_SESSION["core"]->version = '2.00';
+14 -8
View File
@@ -1,16 +1,16 @@
$(document).ready(function(){
$(document).ready(function () {
var currentDiv;
var iframeDoc;
$('#frameContainer').on('load', function(){
$('#frameContainer').on('load', function () {
// Get the iframe document
var iframe = document.getElementById('frameContainer');
iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
// Set up click handler on divs with class 'editable' in the iframe
$(iframeDoc).find('.editable').css('cursor', 'pointer').click(function(event){
$(iframeDoc).find('.editable').css('cursor', 'pointer').click(function (event) {
event.preventDefault();
currentDiv = $(this);
@@ -37,9 +37,9 @@ $(document).ready(function(){
automatic_uploads: true,
images_reuse_filename: false,
images_upload_credentials: true,
force_br_newlines : false,
force_p_newlines : false,
forced_root_block : '',
force_br_newlines: false,
force_p_newlines: false,
forced_root_block: '',
setup: function (editor) {
editor.on('init', function (e) {
editor.setContent(content);
@@ -51,7 +51,7 @@ $(document).ready(function(){
});
});
$('#saveBtn').click(function(){
$('#saveBtn').click(function () {
// Get the data from TinyMCE
var data = tinymce.get('editor').getContent();
@@ -70,6 +70,12 @@ $(document).ready(function(){
});
$('#savePage').click(() => {
$.post("./controller/",{action:"save",uri:$('#frameContainer').contents().get(0).location.pathname,content:new XMLSerializer().serializeToString($('#frameContainer').contents().get(0))},function(data){alert(data)});
$.post("./controller/", {
action: "save",
uri: $('#frameContainer').contents().get(0).location.pathname,
content: new XMLSerializer().serializeToString($('#frameContainer').contents().get(0))
}, function (data) {
alert(data)
});
});
});
+38 -30
View File
@@ -1,13 +1,25 @@
<?php
class neoCMSCore {
public $auditEnabled=true;
public $users=[];
public $loggedIn=false;
private $loggedInUser='';
public $version='2.0';
public function __construct() {
class neoCMSCore
{
public $auditEnabled = true;
public $users = [];
public $loggedIn = false;
public $version = '2.0';
private $loggedInUser = '';
public function __construct()
{
}
public function login($username, $password)
{
$this->loggedIn = (!empty($this->users[$username]) && $this->users[$username] == $password);
if ($this->loggedIn) $this->loggedInUser = $username;
$this->writeAudit("User login for " . $username . " was " . ($this->loggedIn ? "successful" : "denied due to incorrect credentials") . " from " . $_SERVER['REMOTE_ADDR']);
return $this->loggedIn;
}
/**
@@ -15,41 +27,37 @@ class neoCMSCore {
* @param $value
* @return void
*/
public function writeAudit($value) {
if($this->auditEnabled)
file_put_contents(__DIR__ . "/".date('y-m-d-')."audit.txt", date('Y-m-d H:i:s')."\t".$this->loggedInUser."\t".trim($value)."\n", FILE_APPEND);
public function writeAudit($value)
{
if ($this->auditEnabled)
file_put_contents(__DIR__ . "/" . date('y-m-d-') . "audit.txt", date('Y-m-d H:i:s') . "\t" . $this->loggedInUser . "\t" . trim($value) . "\n", FILE_APPEND);
}
public function login($username, $password) {
$this->loggedIn=(!empty($this->users[$username]) && $this->users[$username]==$password);
if($this->loggedIn) $this->loggedInUser=$username;
$this->writeAudit("User login for ".$username." was ".($this->loggedIn?"successful":"denied due to incorrect credentials")." from ".$_SERVER['REMOTE_ADDR']);
public function isLoggedIn()
{
return $this->loggedIn;
}
public function isLoggedIn() {
return $this->loggedIn;
}
public function getLoggedinUser() {
public function getLoggedinUser()
{
return $this->loggedInUser;
}
public function saveContent($uri,$content) {
$this->writeAudit("Content for ".$uri." was saved.");
$uri=str_replace("../","./",$uri);
public function saveContent($uri, $content)
{
$this->writeAudit("Content for " . $uri . " was saved.");
$uri = str_replace("../", "./", $uri);
//check to see if we're dealing with a default (index.htm{l}) page
if(str_ends_with($uri,"/") || $uri=='/') {
if(file_exists($_SERVER['DOCUMENT_ROOT'].$uri.'index.htm')) {
$uri=$uri.'/index.htm';
}
elseif(file_exists($_SERVER['DOCUMENT_ROOT'].$uri.'index.html')) {
$uri=$uri.'/index.html';
if (str_ends_with($uri, "/") || $uri == '/') {
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $uri . 'index.htm')) {
$uri = $uri . '/index.htm';
} elseif (file_exists($_SERVER['DOCUMENT_ROOT'] . $uri . 'index.html')) {
$uri = $uri . '/index.html';
} else {
die('Unknown default file:'.$uri);
die('Unknown default file:' . $uri);
}
}
file_put_contents($_SERVER['DOCUMENT_ROOT'].$uri,$content);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . $uri, $content);
}
}
+4 -4
View File
@@ -3,21 +3,21 @@
<head>
<meta charset="UTF-8">
<title>Welcome to Our Application</title>
<link rel="stylesheet" href="/cms/css/welcome.style.css">
<link href="/cms/css/welcome.style.css" rel="stylesheet">
</head>
<body>
<header>
<img src="/cms/img/welcomeLogo.png" alt="Application Logo" class="logo">
<img alt="Application Logo" class="logo" src="/cms/img/welcomeLogo.png">
</header>
<main>
<h1>Welcome to NeoCMS</h1>
<p>Put some content in here</p>
<p class="editable">
This box is editable!<br />
This box is editable!<br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Quisque sit amet accumsan tortor. Itaque earum rerum hic tenetur a sapiente delectus.
</p>
<a href="/" class="button">Get Started with your website</a>
<a class="button" href="/">Get Started with your website</a>
</main>
<footer>
<p>&copy; 2024 Andy Dixon</p>
+3 -3
View File
@@ -4,8 +4,8 @@
<title>Iframe Content</title>
</head>
<body>
<div class="editable">This is editable content 1.</div>
<div class="editable">This is editable content 2.</div>
<div class="editable">This is editable content 3.</div>
<div class="editable">This is editable content 1.</div>
<div class="editable">This is editable content 2.</div>
<div class="editable">This is editable content 3.</div>
</body>
</html>