-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from shane-zentz/V-1.0.4
Add files via upload
- Loading branch information
Showing
22 changed files
with
1,025 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2020 BS-CMS / Shane Zentz | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
BS-CMS (c) 2020 by Shane Zentz (https://www.shanezentz.com/) | ||
|
||
Licensed: MIT | ||
Description: BS-CMS is a simple CMS (content management system) that is a flat-file based system. It uses JSON and XML files | ||
in place of an SQL database. This is the first version, and you should consider it a beta release. In other words | ||
use it at your own risk and do not assume that it is fully correct or bug free or secure. However, feel free | ||
to try it out, use it, find limitations and bugs. Also feel free to submit bugs and improvements through my | ||
github channel, . Enjoy! | ||
|
||
Limitations: BS-CMS was designed to be a bare-bones, simple CMS, and as such does have it's limitations, as almost any | ||
software does. Here is a list of some (but not all) obvious limitations: | ||
. It does not have user permissions, and as such all users are 'master' or 'god mode' users that have all | ||
permissions, and can delete any other users. I hope to fix this in later releases. | ||
. It may contain security flaws that could be exploitable. Use at your own risk. | ||
. At present there is no ability for plugins (called add ons here), this will possibly be added at a later | ||
release. | ||
. It may contain bugs or other flaws. This is my first attempt at a simple, flat-file CMS and as such it may | ||
not be correct or 'the way it should be', but at a simple level it does work. | ||
. At present it only contains the Tiny MCE editor, which is fine, however I will attempt to add other editors in | ||
future releases. Most likely where the end user will have a choice between different editors. | ||
|
||
|
||
BS-CMS uses the following components: | ||
|
||
Bootstrap 4 | ||
Licensed: MIT | ||
URL: https://getbootstrap.com/ | ||
|
||
Lightbox 2 | ||
Licensed: MIT | ||
Author: Lokesh Dhakar | ||
URL: https://lokeshdhakar.com/projects/lightbox2/ | ||
|
||
Tiny MCE | ||
Licensed: GNU Lesser General Public License (LGPL) | ||
URL: https://www.tiny.cloud/ | ||
|
||
jQuery | ||
Licensed: MIT - https://jquery.org/license/ | ||
URL: https://jquery.org/ | ||
|
||
Nestable jQuery plugin | ||
Licensed: Dual-licensed under the BSD or MIT licenses | ||
URL: https://dbushell.com/Nestable/ and https://github.com/dbushell/Nestable | ||
|
||
PHP Simple Router Class (CHRISTOPH STITZ) | ||
Licensed: MIT | ||
URL: https://steampixel.de/en/simple-and-elegant-url-routing-with-php/, https://steampixel.de/en/author/christoph/, https://github.com/steampixel/simplePHPRouter/tree/master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
/* | ||
PHP Simple Router Class (CHRISTOPH STITZ) | ||
Licensed: MIT | ||
URL: https://steampixel.de/en/simple-and-elegant-url-routing-with-php/, https://steampixel.de/en/author/christoph/, https://github.com/steampixel/simplePHPRouter/tree/master | ||
*/ | ||
class Route{ | ||
|
||
private static $routes = Array(); | ||
private static $pathNotFound = null; | ||
private static $methodNotAllowed = null; | ||
|
||
public static function add($expression, $function, $method = 'get'){ | ||
array_push(self::$routes,Array( | ||
'expression' => $expression, | ||
'function' => $function, | ||
'method' => $method | ||
)); | ||
} | ||
|
||
public static function pathNotFound($function){ | ||
self::$pathNotFound = $function; | ||
} | ||
|
||
public static function methodNotAllowed($function){ | ||
self::$methodNotAllowed = $function; | ||
} | ||
|
||
public static function run($basepath = '/'){ | ||
|
||
// Parse current url | ||
$parsed_url = parse_url($_SERVER['REQUEST_URI']);//Parse Uri | ||
|
||
if(isset($parsed_url['path'])){ | ||
$path = $parsed_url['path']; | ||
}else{ | ||
$path = '/'; | ||
} | ||
|
||
// Get current request method | ||
$method = $_SERVER['REQUEST_METHOD']; | ||
|
||
$path_match_found = false; | ||
|
||
$route_match_found = false; | ||
|
||
foreach(self::$routes as $route){ | ||
//var_dump($route); | ||
// If the method matches check the path | ||
|
||
// Add basepath to matching string | ||
if($basepath!=''&&$basepath!='/'){ | ||
$route['expression'] = '('.$basepath.')'.$route['expression']; | ||
} | ||
|
||
// Add 'find string start' automatically | ||
$route['expression'] = '^'.$route['expression']; | ||
|
||
// Add 'find string end' automatically | ||
$route['expression'] = $route['expression'].'$'; | ||
|
||
// echo $route['expression'].'<br/>'; | ||
|
||
// Check path match | ||
if(preg_match('#'.$route['expression'].'#',$path,$matches)){ | ||
|
||
$path_match_found = true; | ||
|
||
// Check method match | ||
if(strtolower($method) == strtolower($route['method'])){ | ||
|
||
array_shift($matches);// Always remove first element. This contains the whole string | ||
|
||
if($basepath!=''&&$basepath!='/'){ | ||
array_shift($matches);// Remove basepath | ||
} | ||
|
||
call_user_func_array($route['function'], $matches); | ||
|
||
$route_match_found = true; | ||
|
||
// Do not check other routes | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// No matching route was found | ||
if(!$route_match_found){ | ||
|
||
// But a matching path exists | ||
if($path_match_found){ | ||
header("HTTP/1.0 405 Method Not Allowed"); | ||
if(self::$methodNotAllowed){ | ||
call_user_func_array(self::$methodNotAllowed, Array($path,$method)); | ||
} | ||
}else{ | ||
header("HTTP/1.0 404 Not Found"); | ||
//echo 'NOT FOUND...'; | ||
if(self::$pathNotFound){ | ||
call_user_func_array(self::$pathNotFound, Array($path)); | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<h2>About BS-CMS</h2> | ||
<p>BS-CMS was created by <a href="https://www.shanezentz.com" target="_blank">Shane Zentz</a> in 2020, mostly as a learning project. After searching the internet I found a few flat file CMS', some were pretty nice, such as Grav and Get Simple, others were not as nice. After a bit of tinkering I decided to try to make my own CMS just because I was looking for a project to work on and had always wanted to create a flat file CMS for my own use. I have created MySQL driven CMS' before, but this was new to me and so was going to be a learning curve. I knew it would be a complex task and had hoped to find a few tutorials to at least point me in the right direction. However, there seem to be very few tutorials (or really any information at all) on how to go about creating a flat file CMS.</p> | ||
<p>So, I set out to work. I tried to learn as much as I could by going through the complicated code on a few open source flat file CMS'. After a bit of working, I had a very simple but working flat file CMS. I have added to it and polished it even more since then. In the end it is just supposed to be a simple, working (for my purposes), and easy to use flat file CMS.</p> | ||
<p>I want to say thanks for using/downloading my project and I hope you find it useful. Feel free to add comments or suggestions or even submit code changes/upgrades, etc.</p> | ||
<p>Shane Zentz</p> | ||
<p>© 2020</p> | ||
<p>Creator of BS-CMS</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<h2>Activity Logs</h2> | ||
<?php | ||
/* BS-CMS (c) 2020 by Shane Zentz | ||
this file just gets all activities from the CMS | ||
*/ | ||
header('Content-Type: text/plain'); | ||
require 'activityClass.php'; | ||
|
||
$act = new Activity(); | ||
|
||
// get the entire activities file...? | ||
echo $act->getActivities(); | ||
echo '<br><hr><br>'; | ||
// button to clear out the activities file... | ||
echo '<form action="clearActivity.php" method="post"><button type="submit" class="btn btn-primary btn-lg" name="action" >Clear Activity History</button></form>'; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
/* Class: Activity | ||
Author: Shane Zentz 2020 | ||
Desc: This class is built to track important events within a CMS. Events could be creating a page, editing | ||
a page, deleting a page, creating a backup, logging in, logging out, updating password, etc. | ||
*/ | ||
|
||
class Activity { | ||
|
||
// properties: | ||
// main activity log file: | ||
protected $activityLog = "activityLog.txt"; | ||
// parts of the activity: | ||
protected $time = ''; // time of activity | ||
protected $date = ''; // date of activity | ||
protected $event = ''; // the event/activity that has occured | ||
protected $user = ''; // the user who caused the event | ||
|
||
// Constructor | ||
public function __construct() | ||
{ | ||
} | ||
|
||
// method to get all of the events in the event/activity log file | ||
public function getActivities(){ | ||
$output = file_get_contents($this->activityLog); | ||
//return $output; | ||
return nl2br(htmlentities($output)); | ||
} | ||
|
||
// method to add an event to the event / activity log file | ||
public function addActivity($user, $event){ | ||
// get current date of activity | ||
$date = $this->currentDate(); | ||
// get current time of activity | ||
$time = $this->currentTime(); | ||
// get user who did activity | ||
$users = $this->user; | ||
// get the event/activity | ||
$act = $this->event; | ||
// string of text | ||
$input = "User: ".$user."\t"."Event: ".$event."\t"."Date: ".$date."\t"."Time: ".$time."\t\n"; | ||
// the activity file | ||
$file = $this->activityLog; | ||
// open the activity log file for writing/appending | ||
|
||
file_put_contents($file, $input, FILE_APPEND | LOCK_EX); | ||
} | ||
|
||
public function clearActivity(){ | ||
$file = $this->activityLog; | ||
// open the activity file in write mode | ||
$fp = fopen($file, "r+"); | ||
// clear content to 0 bits | ||
ftruncate($fp, 0); | ||
//close file | ||
fclose($fp); | ||
// alert user.. | ||
echo '<script type="text/javascript">alert("Activity History Cleared...");</script>'; | ||
header("refresh:2; index.php"); // really should be a fully qualified URI'; | ||
} | ||
|
||
public function currentDate(){ | ||
$date = date('m/d/Y'); | ||
return $date; | ||
} | ||
|
||
public function currentTime(){ | ||
$time = date('H:i:s'); | ||
return $time; | ||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/* BS-CMS (c) 2020 by Shane Zentz | ||
This file is for processing/adding the content from the create a page form/editor, | ||
if all goes right, the new page will be added to the page.xml database file...... | ||
*/ | ||
session_start(); | ||
|
||
if (!isset($_SESSION['nID'])) | ||
{ | ||
header("Location: admin-login.php"); | ||
die(); | ||
} | ||
|
||
require_once('activityClass.php'); | ||
require 'sitemapClass.php'; | ||
|
||
$file = 'database/pages.xml'; | ||
$xml = simplexml_load_file($file); | ||
|
||
$act = new Activity(); | ||
|
||
// get post data sent into variables first: | ||
$pageName = $_POST['pageName']; // page name | ||
$template = $_POST['Template']; // template to use | ||
$metaTitle = $_POST['metaTitle']; // meta title | ||
$metaDescription = $_POST['metaDescription']; // meta description | ||
$bodyContent = base64_encode( $_POST['pageBody'] ); // body contents | ||
$pageUrl = $_POST['pageUrl']; // page url | ||
|
||
// get the index of the last element in the xml file, then increment for the | ||
// inserted element... | ||
$count = count($xml); | ||
if ($count == 0) {$index = 0;} | ||
else { | ||
$last_item = $xml->page[$count-1]; | ||
$last_index = (int) $last_item->index; | ||
$index = $last_index + 1; | ||
} | ||
|
||
// function to check if users created page name and/or url already exists in file... | ||
function pageAlreadyExists($xml, $pageName, $pageUrl){ | ||
$exists = false; | ||
foreach($xml as $list => $val){ | ||
if (($val->pageTitle == $pageName) || ($val->pageURL == $pageUrl)){ | ||
$exists = true; | ||
} | ||
} | ||
|
||
return $exists; | ||
} | ||
|
||
|
||
|
||
|
||
// add logic test to make sure page name / url does not already exist | ||
|
||
if (!pageAlreadyExists($xml, $pageName, $pageUrl)) | ||
{ | ||
|
||
// if page name is unique && url is unique then add the page... | ||
$entry = $xml->addChild('page'); | ||
$entry->addChild('index', $index); | ||
$entry->addChild('pageTitle', $pageName); | ||
$entry->addChild('metaTitle', $metaTitle); | ||
$entry->addChild('metaDescription', $metaDescription); | ||
$entry->addChild('pageURL', $pageUrl); | ||
$entry->addChild('template', $template); | ||
$entry->addChild('bodyContents', $bodyContent); | ||
|
||
|
||
|
||
$xml->asXML($file); | ||
$act->addActivity($_SESSION['username'], "New page created: ".$pageName); | ||
$sitemap = new Sitemap(); | ||
$sitemap->generateSitemap(); | ||
$sitemap->generateHumanSitemap(); | ||
header("refresh:2; index.php"); // really should be a fully qualified URI | ||
echo '<script type="text/javascript">alert("Content Added...");</script>'; | ||
} | ||
|
||
else // the page already exists | ||
{ | ||
header("refresh:2; index.php"); // really should be a fully qualified URI | ||
echo '<script type="text/javascript">alert("That Page Name or Url already exists... Please try again...");</script>'; | ||
} | ||
|
||
?> |
Oops, something went wrong.