Code Cleanup

This commit is contained in:
Andy Dixon
2024-10-03 08:07:53 +01:00
committed by Andy Dixon
parent d161239cf1
commit c103a8e6dc
9 changed files with 136 additions and 112 deletions
+4 -2
View File
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <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> <serverData>
<paths name="Hostinger"> <paths name="Hostinger">
<serverdata> <serverdata>
<mappings> <mappings>
<mapping local="$PROJECT_DIR$" web="/" /> <mapping deploy="/" local="$PROJECT_DIR$" web="/" />
</mappings> </mappings>
</serverdata> </serverdata>
</paths> </paths>
+1 -1
View File
@@ -11,4 +11,4 @@ switch ($_REQUEST["action"]) {
die('Unable to save page'); die('Unable to save page');
} }
break; break;
}; }
+6
View File
@@ -9,6 +9,7 @@ body {
flex-flow: column; flex-flow: column;
height: 100%; height: 100%;
} }
.pageContainer .controls { .pageContainer .controls {
flex: 0 1 auto; flex: 0 1 auto;
height: 70px; height: 70px;
@@ -17,6 +18,7 @@ body {
-webkit-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); box-shadow: 0px 10px 13px -7px #000000, -1px -1px 15px 5px rgba(0, 0, 0, 0);
} }
.pageContainer .frame { .pageContainer .frame {
flex: 1 1 auto; flex: 1 1 auto;
border: 0; border: 0;
@@ -29,6 +31,7 @@ body {
display: block; display: block;
position: absolute; position: absolute;
} }
.controls .buttonContainer { .controls .buttonContainer {
width: 400px; width: 400px;
margin: 18px auto; margin: 18px auto;
@@ -45,6 +48,7 @@ body {
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
.controls .buttonContainer li { .controls .buttonContainer li {
display: inline; display: inline;
margin-right: 10px; margin-right: 10px;
@@ -86,10 +90,12 @@ body {
text-decoration: none; text-decoration: none;
text-shadow: 0px 1px 0px #5b8a3c; text-shadow: 0px 1px 0px #5b8a3c;
} }
.greenButton:hover { .greenButton:hover {
background: linear-gradient(to bottom, #72b352 5%, #77b55a 100%); background: linear-gradient(to bottom, #72b352 5%, #77b55a 100%);
background-color: #72b352; background-color: #72b352;
} }
.greenButton:active { .greenButton:active {
position: relative; position: relative;
top: 1px; top: 1px;
+4 -2
View File
@@ -26,7 +26,8 @@ if(!$_SESSION["core"]->isLoggedIn() && stripos($_SERVER['REQUEST_URI'],"/login")
// str_starts_with compatibility for php 7 // str_starts_with compatibility for php 7
if (!function_exists('str_starts_with')) { if (!function_exists('str_starts_with')) {
function str_starts_with($haystack,$needle) { function str_starts_with($haystack, $needle)
{
//str_starts_with(string $haystack, string $needle): bool //str_starts_with(string $haystack, string $needle): bool
$strlen_needle = mb_strlen($needle); $strlen_needle = mb_strlen($needle);
@@ -39,7 +40,8 @@ if(!function_exists('str_starts_with')) {
//str_ends_with compatibility for php 7 //str_ends_with compatibility for php 7
if (!function_exists('str_ends_with')) { if (!function_exists('str_ends_with')) {
function str_ends_with($haystack,$needle) { function str_ends_with($haystack, $needle)
{
//str_starts_with(string $haystack, string $needle): bool //str_starts_with(string $haystack, string $needle): bool
$strlen_needle = mb_strlen($needle); $strlen_needle = mb_strlen($needle);
+7 -1
View File
@@ -70,6 +70,12 @@ $(document).ready(function(){
}); });
$('#savePage').click(() => { $('#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)
});
}); });
}); });
+24 -16
View File
@@ -1,13 +1,25 @@
<?php <?php
class neoCMSCore {
class neoCMSCore
{
public $auditEnabled = true; public $auditEnabled = true;
public $users = []; public $users = [];
public $loggedIn = false; public $loggedIn = false;
private $loggedInUser='';
public $version = '2.0'; public $version = '2.0';
public function __construct() { 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,27 +27,24 @@ class neoCMSCore {
* @param $value * @param $value
* @return void * @return void
*/ */
public function writeAudit($value) { public function writeAudit($value)
{
if ($this->auditEnabled) 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); 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) { public function isLoggedIn()
$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; return $this->loggedIn;
} }
public function isLoggedIn() { public function getLoggedinUser()
return $this->loggedIn; {
}
public function getLoggedinUser() {
return $this->loggedInUser; return $this->loggedInUser;
} }
public function saveContent($uri,$content) { public function saveContent($uri, $content)
{
$this->writeAudit("Content for " . $uri . " was saved."); $this->writeAudit("Content for " . $uri . " was saved.");
$uri = str_replace("../", "./", $uri); $uri = str_replace("../", "./", $uri);
@@ -43,8 +52,7 @@ class neoCMSCore {
if (str_ends_with($uri, "/") || $uri == '/') { if (str_ends_with($uri, "/") || $uri == '/') {
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $uri . 'index.htm')) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . $uri . 'index.htm')) {
$uri = $uri . '/index.htm'; $uri = $uri . '/index.htm';
} } elseif (file_exists($_SERVER['DOCUMENT_ROOT'] . $uri . 'index.html')) {
elseif(file_exists($_SERVER['DOCUMENT_ROOT'].$uri.'index.html')) {
$uri = $uri . '/index.html'; $uri = $uri . '/index.html';
} else { } else {
die('Unknown default file:' . $uri); die('Unknown default file:' . $uri);
+3 -3
View File
@@ -3,11 +3,11 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Welcome to Our Application</title> <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> </head>
<body> <body>
<header> <header>
<img src="/cms/img/welcomeLogo.png" alt="Application Logo" class="logo"> <img alt="Application Logo" class="logo" src="/cms/img/welcomeLogo.png">
</header> </header>
<main> <main>
<h1>Welcome to NeoCMS</h1> <h1>Welcome to NeoCMS</h1>
@@ -17,7 +17,7 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Quisque sit amet accumsan tortor. Itaque earum rerum hic tenetur a sapiente delectus. Quisque sit amet accumsan tortor. Itaque earum rerum hic tenetur a sapiente delectus.
</p> </p>
<a href="/" class="button">Get Started with your website</a> <a class="button" href="/">Get Started with your website</a>
</main> </main>
<footer> <footer>
<p>&copy; 2024 Andy Dixon</p> <p>&copy; 2024 Andy Dixon</p>