Code Cleanup
This commit is contained in:
+38
-30
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user