Online Magazine with Flat File Database
← Return

Click here for demo
This demo shows a way of creating relationships between the tables in a flat file database. Arrays with paired values are used to link the 'stories' and 'authors' tables and the 'tags' list. These arrrays are stored in text files, labeled 'maps'. There is a 'date-story' map, a 'story-author' map and a 'tag-story' map, which are all accessed by a function, 'selectMapEntries', that looks for pairs of values that contain both keys.
This code also provides a password-protected administrator page, for adding and editing the content.
CATSTACK Code
Download
CATSTACK/index.php ▾
<?php
session_start();
include ("inc/database-definitions.php");
include ("inc/functions.php");
//include ("inc/functions-no-write.php");
$loggedin = false;
include ("inc/check-if-logged-in.php");
$pageid = getFromQueryString ('page');
if (!$pageid){
$pageid = 'home';
}
include ("inc/header.php");
if (file_exists ("pages/". $pageid . ".php") ){
include ("pages/" . $pageid . ".php");
}
else if (file_exists ("admin-pages/" . $pageid . ".php")) {
if ($loggedin === true) {
include ("admin-pages/" . $pageid . ".php");
}
else {
echo "You must be logged in to access this page";
}
}
else {
echo "This page does not exist<br><br>";
}
include ("inc/footer.php");
?>
CATSTACK/admin.php ▾
<?php
session_start();
include ("inc/database-definitions.php");
include ("inc/functions.php");
//include ("inc/functions-no-write.php");
$loggedin = false;
include ("inc/check-if-logged-in.php");
$adminpage = getFromQueryString ('adminpage');
if (!$adminpage){
$adminpage = 'dashboard';
}
$pageid = $adminpage;
include ("inc/admin-header.php");
if (file_exists ("admin-pages/". $adminpage . ".php") ){
include ("admin-pages/" . $adminpage . ".php");
}
else {
echo "This page does not exist<br><br>";
}
include ("inc/admin-footer.php");
?>CATSTACK/pages
about.php ▾
<h1>About</h1>
<h4>A Collection of Curated, Brilliant, Relevant and Timely Articles on Feline Culture, Philosophy, Politics, Economics, Catcoin, Health, World Affairs, Psychology, Mathematics, Physics, Computers, Technology, Religion, Metphysics, Cosmology, Canine Relations, and CATNIP!</h4> authors.php ▾
<?php
echo "<h1>Authors</h1>";
$authors = getRecordIdsFromFolder ('data/authors');
foreach ($authors as $authorid) {
$authorrecord = readDatabaseRecord ($authorrecordkeys, 'data/authors/' . $authorid . '.txt' );
echo "<a href = 'index.php?page=display-author&author=" . $authorid . "'>";
echo "<h3>" . $authorrecord['name'] ."</h3>";
echo "<img class = 'circle-image' src = 'data/images/" . $authorrecord['image'] . "' alt = '" . $authorid . "'>";
echo "</a>";
}
?> contact.php ▾
<h1>Contact</h1>
You can reach us by email at info@lilaavenue.com or phone at (513) 418-1480. display-author.php ▾
<?php
$authorid = getFromQueryString ('author');
$authorrecord = readDatabaseRecord ($authorrecordkeys, 'data/authors/' . $authorid . '.txt');
echo "<h1>Author </h1>";
if ($authorrecord['image']) {
echo "<img src = 'data/images/" . $authorrecord['image'] . "' alt = '" . $authorrecord['name'] . "' >";
}
echo "<h2>" . $authorrecord['name']. "</h2>";
echo "<h3>" . $authorrecord['description'] . "</h3>";
$selectedarray = selectMapEntries ('data/maps/story-author-map.txt', '', $authorid);
foreach ($selectedarray as $storyid) {
$storyrecord = readDatabaseRecord ($storyrecordkeys, 'data/stories/' . $storyid . '.txt');
echo "<div class = 'gridcolumn'>";
if ($storyrecord['image']) {
echo "<img src = 'data/images/" . $storyrecord['image'] . "' alt = '" . $storyrecord['title'] . "' >";
}
echo "<br><a href = 'index.php?page=display-story&story=" . $storyid . "'><h4>" . $storyrecord['title'] . "</a></h4>";
echo "</div>";
}
if ($loggedin) {
echo "<a class = 'adminbutton' href = 'admin.php?adminpage=add-update-author&author=" . $authorid . "'>Edit</a>";
}
?> display-story.php ▾
<?php
$storyid = getFromQueryString ('story');
$storyrecord = readDatabaseRecord($storyrecordkeys, 'data/stories/' . $storyid. '.txt');
$authorid = $storyrecord['author'];
$authorrecord = readDatabaseRecord($authorrecordkeys, 'data/authors/' . $authorid . '.txt');
echo "<h1>" . $storyrecord['title'] . "</h1>";
if ($storyrecord['image']) {
echo "<img src = 'data/images/" . $storyrecord['image'] . "' alt = '" . $storyrecord['title'] . "' >";
}
?>
<div class = 'content-column left'>
<?php
echo "<br><br><b>Author: ";
echo "<a href = 'index.php?page=display-author&author=" . $authorid ."'>" . $authorrecord['name'] . "</a>";
if ($authorrecord['description']) {
echo ", " . $authorrecord['description'];
}
echo "</b><br><br>";
echo nl2br ($storyrecord['text'] . "<br><br>");
?>
</div><div class = 'sidebar-column'>
<?php
echo "<br><br><b>Tags</b><br>";
$currentarray = selectMapEntries ('data/maps/tag-story-map.txt', '', $storyid);
foreach ($currentarray as $tag) {
echo "<a href = 'index.php?page=display-tag&tag=" . $tag . "'>";
echo showWords ($tag) . "</a><br>";
}
?>
</div>
<?php
if ($loggedin) {
echo "<a class = 'adminbutton' href = 'admin.php?adminpage=add-update-story&story=" . $storyid . "'>Edit</a>";
}
?>
display-tag.php ▾
<h1>Stories for Tag</h1>
<?php
$tag = getFromQueryString ('tag');
echo "<h2>" . showWords ($tag) . "</h2>";
$currentarray = selectMapEntries ('data/maps/tag-story-map.txt', $tag, "");
$tagarray = readArray ('data/tags.txt', ',');
$stories = getRecordsIdFromFolder ('data/stories');
foreach ($stories as $storyid) {
if (in_array($storyid, $currentarray)) {
echo "<a href = 'index.php?page=display-story&story=" . $storyid . "'>" . showWords ($storyid) . "</a><br>";
}
}
?>
home.php ▾
<div class = 'content-column'>
<?php
echo "<h1>Latest Stories </h1>";
$stories = extractFromMap ('data/maps/date-story-map.txt', 1);
foreach ($stories as $storyid) {
echo "<div class = 'gridcolumn'>";
$storyrecord = readDatabaseRecord ($storyrecordkeys, 'data/stories/' . $storyid . '.txt');
if ($storyrecord['image']) {
echo "<img src = 'data/images/" . $storyrecord['image'] . "' alt = '" . $storyrecord['title'] . "' >";
}
echo "<br><a href = 'index.php?page=display-story&story=" . $storyid . "'><h3>" . $storyrecord['title'] . "</h3></a>";
$authorid = $storyrecord['author'] ;
$authorrecord = readDatabaseRecord ($authorrecordkeys, 'data/authors/' . $authorid . '.txt' ) ;
echo "<h5>" . $storyrecord['date'] . "</h5>";
echo "<h5>" . $authorrecord['name'] . "</h5>";
echo "</div>";
}
?>
</div><div class = 'sidebar-column'>
<?php
echo "<h2>Authors</h2>";
$authors = extractFromMap ('data/maps/story-author-map.txt', 1);
$authors = array_unique ($authors);
foreach ($authors as $authorid) {
$authorrecord = readDatabaseRecord ($authorrecordkeys, 'data/authors/' . $authorid . '.txt' );
echo "<a href = 'index.php?page=display-author&author=" . $authorid . "'>";
echo "<b>" . $authorrecord['name'] ."</b><br>";
echo "</a>";
}
echo "<h2>Tags</h2>";
$tagarray = readArray ('data/tags.txt', ',');
foreach ($tagarray as $tag) {
echo "<a href = 'index.php?page=display-tag&tag=" . $tag . "'><b>" . showWords ( $tag) ."</b></a><br>";
}
?>
</div>
login.php ▾
<?php
$pageid = 'login';
if ($_SERVER ["REQUEST_METHOD"] === "POST" ) {
// Checks if the user is trying to log in
if (isset($_POST['username'])) {
if (isset($_POST['password'])) {
if (trim($_POST['username']) === $username && trim($_POST['password']) === $password) {
$_SESSION['admin'] = $username;
$loggedin = true;
echo "<h2>You are now logged in</h2>";
}
}
}
}
if (!$loggedin) {
?>
<h2>Log In</h2>
<h3>Please enter your username and password</h3>
<form method="post" action="index.php?page=login">
<label for = 'username' >Username: </label></b><br>
<input id = 'username' type="text" name="username" value = '<?php echo $username; ?> ' /><br><br>
<label for = password' >Password: </label><br>
<input id = 'password' type="password" name="password" value = '<?php echo $password; ?>' /><br><br><br>
<input class = 'submitbutton' type="submit" value = "Enter" name = 'submit'>
</form>
<?php } ?>
stories.php ▾
<?php
echo "<h1>Stories </h1>";
$dates = extractFromMap ('data/maps/date-story-map.txt', 0);
$stories = extractFromMap ('data/maps/date-story-map.txt', 1);
foreach ($dates as $id => $date) {
if (array_key_exists ($id, $stories)) {
$storyid = $stories[$id] ;
echo "<div class = 'gridcolumn'>";
$storyrecord = readDatabaseRecord ($storyrecordkeys, 'data/stories/' . $storyid . '.txt');
if ($storyrecord['image']) {
echo "<img src = 'data/images/" . $storyrecord['image'] . "' alt = '" . $storyrecord['title'] . "' >";
}
echo "<br><a href = 'index.php?page=display-story&story=" . $storyid . "'><h4>" . $storyrecord['title'] . "</a></h4>";
$authorid = $storyrecord['author'] ;
$authorrecord = readDatabaseRecord ($authorrecordkeys, 'data/authors/' . $authorid . '.txt' ) ;
echo "<h5>" . $storyrecord['date'] . "</h5>";
echo "<h5>" . $authorrecord['name'] . "</h5>";
echo "</div>";
}
}
?>
CATSTACK/inc
admin-footer.php ▾
</div>
<footer>
<a class = 'adminbutton' href = 'admin.php?adminpage=logout'>Logout</a>
<br><br><br>Copyright © <?php echo date('Y'); ?> Susan Rodgers, <a href = 'https://lilaavenue.com'>Lila Avenue</a>
</footer>
</body>
</html>
admin-header.php ▾
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>'CatStack'</title>
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Elsie" rel="stylesheet">
<link rel= 'stylesheet' type='text/css' href= 'inc/style.css'>
</head>
<body>
<div class = 'admin-outerwrap'>
<div class = 'header'>
<a href = 'index.php'>← <h3>CatStack</h3></a>
</div>
check-if-logged-in.php ▾
<?php
$username = trim (file_get_contents ('data/username.txt'));
$password = trim (file_get_contents ('data/password.txt'));
if (isset($_SESSION['admin'])) {
if ($_SESSION['admin'] === $username) {
$loggedin = true;
}
}
?> database-definitions.php ▾
<?php
//Field Delimiters
$dl1 = "%!%";
$dl2 = "%#%";
//Record keys
$storyrecordkeys = array ("title", "author", "date", "text","issue","image") ;
$authorrecordkeys = array ('name', 'phone', 'address', 'email', 'description', 'image');
?> footer.php ▾
</div>
<footer>
<?php
if ($loggedin) {
echo "<a class = 'adminbutton' href = 'admin.php?adminpage=dashboard'>Dashboard</a>";
echo "<a class = 'adminbutton' href = 'admin.php?adminpage=logout'>Logout</a>";
}
else {
echo "<a class = 'adminbutton' href = 'index.php?page=login'>Login</a>";
}
?>
<a href = '../../data/images/download-files/CATSTACK.zip'>Download Code</a>
<br><br><br>Copyright © <?php echo date('Y'); ?> Susan Rodgers, <a href = 'https://lilaavenue.com'>Lila Avenue</a>
</footer>
</body>
</html>
functions-no-write.php ▾
<?php
//This file contains a group of functions that are used in other applications as well
//Not all of them are used by this application
function createRecordId ($name) {
$newname = "";
if ($name !== "") {
$newname = trim ($name);
$newname = str_replace (" " , "-", $newname);
$newname = strtolower ($newname);
$newname = preg_replace('/[^A-Za-z0-9-]/', '', $newname);
$newname = preg_replace('/-+/', '-', $newname);
}
return $newname;
}
function initializeRecord ($keys){
$record = array ();
foreach ($keys as $Id => $key) {
$record[$key] = "";
}
return ($record);
}
function readDatabaseRecord ($keys, $filename) {
//Creates 'record' variable by assigning keys and values to associative array,
global $dl1;
//Initialize record
$record = array();
foreach ($keys as $Id => $key) {
$record[$key] = "";
}
if ($filename && file_exists($filename)) {
$string = file_get_contents ($filename);
$fArray1= explode ($dl1, $string);
foreach ($keys as $Id => $key) {
if (array_key_exists ($Id, $fArray1)) {
$record [$key] = $fArray1[$Id];
}
}
}
return $record;
}
function writeDatabaseRecord ($record, $filename) {
//Stores record variable as text file
global $dl1;
$String = implode ($dl1, $record);
//file_put_contents ($filename, $String);
}
function createAssocArray ($map) {
global $dl1, $dl2;
$assocarray = array();
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Id => $Item1) {
$fArray2 = explode ($dl2, $Item1);
$key = $fArray2[0];
if (array_key_exists (1, $fArray2)) {
$value = $fArray2[1];
$assocarray[$key] = $value;
}
}
return $assocarray;
}
// Maps for table relationships
function addMapEntry ($map, $key1, $key2) {
global $dl1, $dl2;
$fArray1 = readArray ($map, $dl1);
$newentry = $key1 . $dl2 . $key2 . $dl2 . "\n";
array_push ($fArray1, $newentry);
$fArray1 = array_unique ($fArray1);
sort ($fArray1);
//writeArray ($map, $fArray1, $dl1);
}
function removeMapEntries ($map, $key0, $key1) {
//Remove entries containing either or both key0 and key1
global $dl1, $dl2;
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Id => $Item1) {
$fArray2 = explode ($dl2, $Item1);
if (array_key_exists (0, $fArray2) && array_key_exists (1, $fArray2)) {
if ($key0 && $key1 ) {
if ( $fArray2[0] === $key0 && $fArray2[1] === $key1 ) {
unset ($fArray1 [$Id]);
}
}
else if (! $key0 && $key1 ) {
if ($fArray2[1] === $key1) {
unset ($fArray1 [$Id]);
}
}
else if ($key0 && !$key1) {
if ($fArray2[0] === $key0) {
unset ($fArray1 [$Id]);
}
}
}
}
//writeArray ($map, $fArray1, $dl1);
}
function selectMapEntries ($map, $key0, $key1) {
//for many-to-many relationships
//returns an array with selected key
global $dl1, $dl2;
$fArray1 = readArray ($map, $dl1);
$selectedarray = array();
if ($key0 && !$key1 ) {
foreach ($fArray1 as $Item1) {
$fArray2 = explode ($dl2, $Item1);
if (array_key_exists (1, $fArray2)) {
if ($fArray2[0] == $key0 ){
array_push ($selectedarray, $fArray2[1]);
}
}
}
}
else if (!$key0 && $key1) {
foreach ($fArray1 as $Item1) {
$fArray2 = explode ($dl2, $Item1);
if (array_key_exists (1, $fArray2)) {
if ($fArray2[1] === $key1) {
array_push ($selectedarray, $fArray2[0]);
}
}
}
}
return $selectedarray;
}
function selectMapKey ($map, $key0, $key1) {
//For one-to-many relationships
//returns an single value
global $dl1, $dl2;
$returnvalue = '';
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Id => $Item1) {
$fArray2 = explode ($dl2, $Item1);
if ( array_key_exists (1, $fArray2)) {
if (!$key0 && $key1) {
if ($fArray2[1] === $key1) {
$returnvalue = $fArray2[0];
break;
}
}
else if ($key0 && ! $key1) {
if ($fArray2[0] === $key0){
$returnvalue = $fArray2[1];
break;
}
}
}
}
return $returnvalue;
}
function extractFromMap($map, $key) {
//returns a new array of either the the first or second columns
global $dl1, $dl2;
$selectedarray = array();
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Item1) {
$fArray2 = explode ($dl2, $Item1);
if ($key == 0) {
array_push ($selectedarray, $fArray2[0]);
}
else if ($key == 1) {
if (array_key_exists (1, $fArray2)) {
array_push ($selectedarray, $fArray2[1]);
}
}
}
return $selectedarray;
}
function moveToTrash ($table, $recordid) {
$oldfilename = 'data/' . $table . '/' . $recordid . '.txt';
$newfilename = 'data/trash/' . $table . '----' . $recordid . '.txt';
if (file_exists ($oldfilename)) {
// rename ($oldfilename, $newfilename);
}
}
//ARRAYS
function readArray ($filename, $delimiter){
$fArray1 = array();
if (file_exists($filename)) {
$String = file_get_contents ($filename);
if ($String !== "") {
$fArray1 = explode ($delimiter, $String);
}
}
return $fArray1;
}
function writeArray ($filename, $array, $delimiter){
$String = implode ($delimiter, $array);
//file_put_contents ($filename, $String);
}
function addNameToArray ($filename, $name, $delimiter) {
if (file_exists($filename)) {
$String = file_get_contents ($filename);
$fArray1 = explode ($delimiter, $String);
array_push ($fArray1, $name);
$fArray1 = array_unique ($fArray1);
sort ($fArray1);
$String = implode ($delimiter, $fArray1);
$String = preg_replace('/,+/', ',', $String);
$String = ltrim ($String, $delimiter);
//file_put_contents ($filename, $String);
}
}
function removeNameFromArray ($filename, $name, $delimiter) {
if (file_exists($filename)) {
$String = file_get_contents ($filename);
$fArray = explode ($delimiter, $String);
foreach ($fArray as $Id => $Item) {
$Item = trim ($Item);
if ($Item === $name) {
unset ($fArray [$Id]);
}
}
array_values ($fArray);
sort ($fArray);
$String = implode ($delimiter, $fArray);
//file_put_contents ($filename, $String);
}
}
//Validate 'GET' value
function getFromQueryString ($label) {
$value = "";
if (isset ($_GET[$label])) {
$value = $_GET[$label];
if (specialChars($value) || strlen ($value) > 300) {
//Invalid input
$value = '';
}
}
return $value;
}
//Filter input text for record delimiters
function sanitizeFormInput($text) {
global $dl1, $dl2;
$text = trim($text);
$text = str_replace ($dl1, '', $text);
$text = str_replace ($dl2, '', $text);
return $text;
}
function showWords ($text) {
$fancytext = str_replace (',', ', ', $text);
$fancytext = ucwords (str_replace ('-', ' ', $fancytext));
return $fancytext;
}
function assignPostValuesToRecord ($postarray, $keys) {
//Assign values to record
$record = array();
foreach ($keys as $Id => $key) {
$record[$key] = "";
if (isset ($postarray[$key])) {
$record[$key] = sanitizeFormInput ($postarray[$key]);
}
}
return $record;
}
function saveToLog ($text) {
global $dl1, $dl2;
$currenttime = date ("h-i:sa");
$date = date ("Y-m-d");
$filename = 'data/log.txt';
$String = file_get_contents ($filename);
$String = $String . "\n\n " . $date . " " . $currenttime . " ". $text;
//file_put_contents ($filename, $String);
}
function formatDate ($inputdate) {
$returndate = '';
if (is_numeric (substr ($inputdate, 0,4))) {
//format yyyy/mm/dd
$month = substr ($inputdate, 5, 2);
$day = substr ($inputdate, 8,2);
$year = substr ($inputdate, 0, 4);
$returndate = $year . '-' . $month . '-' . $day;
}
else if (is_numeric (substr ($inputdate, 0, 2))) {
//Year is last mm/dd/yyyy
$month = substr ($inputdate, 0, 2);
$day = substr ($inputdate, 3,2);
$year = substr ($inputdate, 6, 4);
$returndate = $year . '-' . $month . '-' . $day;
}
else {
//default current date
$returndate = date('Y-m-d');
}
return $returndate;
}
//CHECK FOR DUPLICATE EMAILS
function checkForDuplicateEmail ($sendtoemail, $message) {
global $dl1, $dl2;
$error = false;
$emailarchive = readArray ('data/email-archive.txt', $dl1);
$emailentry = date ("Y-m-d") . $dl2 .$sendtoemail . $dl2 . $message . "\n";
if ( in_array ($emailentry, $emailarchive)) {
$error = true;
echo "<div class = 'error'>Message is a duplicate</div>";
}
else {
array_push ( $emailarchive, $emailentry);
$String = implode ($dl1, $emailarchive);
//file_put_contents ('data/email-archive.txt', $String);
}
return $error;
}
function randomString () {
$String = "";
$chars = "abcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$size = strlen($chars);
for ($i = 0; $i < 7; $i++) {
$String .= $chars[rand(0, $size - 1)];
}
return $String;
}
function specialChars($str) {
return preg_match("/[^a-zA-Z0-9-:!?*'@#$,\.\s\)\(]/", $str) > 0;
}
function notPhoneNumber($str) {
return preg_match('/[^0-9-\)\(\s]/', $str) > 0;
}
function getRecordIdsFromFolder ($folder) {
$Newarray = array();
$Array1 = scandir ($folder);
foreach ($Array1 as $Item1) {
if (substr ($Item1, 0, 1) !== '.') {
$Recordid = str_replace (".txt", "", $Item1);
$Recordid = str_replace ('.php', '', $Recordid);
$Recordid = str_replace ('.css', '', $Recordid);
$Recordid = trim ($Recordid);
array_push ($Newarray, $Recordid);
}
}
return $Newarray;
}
?>
functions.php ▾
<?php
//This file contains a group of functions that are used in other applications as well
//Not all of them are used by this applicatio
function createRecordId ($name) {
$newname = "";
if ($name !== "") {
$newname = trim ($name);
$newname = str_replace (" " , "-", $newname);
$newname = strtolower ($newname);
$newname = preg_replace('/[^A-Za-z0-9-]/', '', $newname);
$newname = preg_replace('/-+/', '-', $newname);
}
return $newname;
}
function initializeRecord ($keys){
$record = array ();
foreach ($keys as $Id => $key) {
$record[$key] = "";
}
return ($record);
}
function readDatabaseRecord ($keys, $filename) {
//Creates 'record' variable by assigning keys and values to associative array,
global $dl1;
//Initialize record
$record = array();
foreach ($keys as $Id => $key) {
$record[$key] = "";
}
if ($filename && file_exists($filename)) {
$string = file_get_contents ($filename);
$fArray1= explode ($dl1, $string);
foreach ($keys as $Id => $key) {
if (array_key_exists ($Id, $fArray1)) {
$record [$key] = $fArray1[$Id];
}
}
}
return $record;
}
function writeDatabaseRecord ($record, $filename) {
//Stores record variable as text file
global $dl1;
$String = implode ($dl1, $record);
file_put_contents ($filename, $String);
}
function createAssocArray ($map) {
global $dl1, $dl2;
$assocarray = array();
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Id => $Item1) {
$fArray2 = explode ($dl2, $Item1);
$key = $fArray2[0];
if (array_key_exists (1, $fArray2)) {
$value = $fArray2[1];
$assocarray[$key] = $value;
}
}
return $assocarray;
}
// Maps for table relationships
function addMapEntry ($map, $key1, $key2) {
global $dl1, $dl2;
$fArray1 = readArray ($map, $dl1);
$newentry = $key1 . $dl2 . $key2 . $dl2 . "\n";
array_push ($fArray1, $newentry);
$fArray1 = array_unique ($fArray1);
sort ($fArray1);
writeArray ($map, $fArray1, $dl1);
}
function removeMapEntries ($map, $key0, $key1) {
//Remove entries containing either or both key0 and key1
global $dl1, $dl2;
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Id => $Item1) {
$fArray2 = explode ($dl2, $Item1);
if (array_key_exists (0, $fArray2) && array_key_exists (1, $fArray2)) {
if ($key0 && $key1 ) {
if ( $fArray2[0] === $key0 && $fArray2[1] === $key1 ) {
unset ($fArray1 [$Id]);
}
}
else if (! $key0 && $key1 ) {
if ($fArray2[1] === $key1) {
unset ($fArray1 [$Id]);
}
}
else if ($key0 && !$key1) {
if ($fArray2[0] === $key0) {
unset ($fArray1 [$Id]);
}
}
}
}
writeArray ($map, $fArray1, $dl1);
}
function selectMapEntries ($map, $key0, $key1) {
//for many-to-many relationships
//returns an array with selected key
global $dl1, $dl2;
$fArray1 = readArray ($map, $dl1);
$selectedarray = array();
if ($key0 && !$key1 ) {
foreach ($fArray1 as $Item1) {
$fArray2 = explode ($dl2, $Item1);
if (array_key_exists (1, $fArray2)) {
if ($fArray2[0] == $key0 ){
array_push ($selectedarray, $fArray2[1]);
}
}
}
}
else if (!$key0 && $key1) {
foreach ($fArray1 as $Item1) {
$fArray2 = explode ($dl2, $Item1);
if (array_key_exists (1, $fArray2)) {
if ($fArray2[1] === $key1) {
array_push ($selectedarray, $fArray2[0]);
}
}
}
}
return $selectedarray;
}
function selectMapKey ($map, $key0, $key1) {
//For one-to-many relationships
//returns an single value
global $dl1, $dl2;
$returnvalue = '';
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Id => $Item1) {
$fArray2 = explode ($dl2, $Item1);
if ( array_key_exists (1, $fArray2)) {
if (!$key0 && $key1) {
if ($fArray2[1] === $key1) {
$returnvalue = $fArray2[0];
break;
}
}
else if ($key0 && ! $key1) {
if ($fArray2[0] === $key0){
$returnvalue = $fArray2[1];
break;
}
}
}
}
return $returnvalue;
}
function extractFromMap($map, $key) {
//returns a new array of either the the first or second columns
global $dl1, $dl2;
$selectedarray = array();
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Item1) {
$fArray2 = explode ($dl2, $Item1);
if ($key == 0) {
array_push ($selectedarray, $fArray2[0]);
}
else if ($key == 1) {
if (array_key_exists (1, $fArray2)) {
array_push ($selectedarray, $fArray2[1]);
}
}
}
return $selectedarray;
}
function moveToTrash ($table, $recordid) {
$oldfilename = 'data/' . $table . '/' . $recordid . '.txt';
$newfilename = 'data/trash/' . $table . '----' . $recordid . '.txt';
if (file_exists ($oldfilename)) {
rename ($oldfilename, $newfilename);
}
}
//ARRAYS
function readArray ($filename, $delimiter){
$fArray1 = array();
if (file_exists($filename)) {
$String = file_get_contents ($filename);
if ($String !== "") {
$fArray1 = explode ($delimiter, $String);
}
}
return $fArray1;
}
function writeArray ($filename, $array, $delimiter){
$String = implode ($delimiter, $array);
file_put_contents ($filename, $String);
}
function addNameToArray ($filename, $name, $delimiter) {
if (file_exists($filename)) {
$String = file_get_contents ($filename);
$fArray1 = explode ($delimiter, $String);
array_push ($fArray1, $name);
$fArray1 = array_unique ($fArray1);
sort ($fArray1);
$String = implode ($delimiter, $fArray1);
$String = preg_replace('/,+/', ',', $String);
$String = ltrim ($String, $delimiter);
file_put_contents ($filename, $String);
}
}
function removeNameFromArray ($filename, $name, $delimiter) {
if (file_exists($filename)) {
$String = file_get_contents ($filename);
$fArray = explode ($delimiter, $String);
foreach ($fArray as $Id => $Item) {
$Item = trim ($Item);
if ($Item === $name) {
unset ($fArray [$Id]);
}
}
array_values ($fArray);
sort ($fArray);
$String = implode ($delimiter, $fArray);
file_put_contents ($filename, $String);
}
}
//Validate 'GET' value
function getFromQueryString ($label) {
$value = "";
if (isset ($_GET[$label])) {
$value = $_GET[$label];
if (specialChars($value) || strlen ($value) > 300) {
//Invalid input
$value = '';
}
}
return $value;
}
//Filter input text for record delimiters
function sanitizeFormInput($text) {
global $dl1, $dl2;
$text = trim($text);
$text = str_replace ($dl1, '', $text);
$text = str_replace ($dl2, '', $text);
return $text;
}
function showWords ($text) {
$fancytext = str_replace (',', ', ', $text);
$fancytext = ucwords (str_replace ('-', ' ', $fancytext));
return $fancytext;
}
function assignPostValuesToRecord ($postarray, $keys) {
//Assign values to record
$record = array();
foreach ($keys as $Id => $key) {
$record[$key] = "";
if (isset ($postarray[$key])) {
$record[$key] = sanitizeFormInput ($postarray[$key]);
}
}
return $record;
}
function saveToLog ($text) {
global $dl1, $dl2;
$currenttime = date ("h-i:sa");
$date = date ("Y-m-d");
$filename = 'data/log.txt';
$String = file_get_contents ($filename);
$String = $String . "\n\n " . $date . " " . $currenttime . " ". $text;
file_put_contents ($filename, $String);
}
function formatDate ($inputdate) {
$returndate = '';
if (is_numeric (substr ($inputdate, 0,4))) {
//format yyyy/mm/dd
$month = substr ($inputdate, 5, 2);
$day = substr ($inputdate, 8,2);
$year = substr ($inputdate, 0, 4);
$returndate = $year . '-' . $month . '-' . $day;
}
else if (is_numeric (substr ($inputdate, 0, 2))) {
//Year is last mm/dd/yyyy
$month = substr ($inputdate, 0, 2);
$day = substr ($inputdate, 3,2);
$year = substr ($inputdate, 6, 4);
$returndate = $year . '-' . $month . '-' . $day;
}
else {
//default current date
$returndate = date('Y-m-d');
}
return $returndate;
}
//CHECK FOR DUPLICATE EMAILS
function checkForDuplicateEmail ($sendtoemail, $message) {
global $dl1, $dl2;
$error = false;
$emailarchive = readArray ('data/email-archive.txt', $dl1);
$emailentry = date ("Y-m-d") . $dl2 .$sendtoemail . $dl2 . $message . "\n";
if ( in_array ($emailentry, $emailarchive)) {
$error = true;
echo "<div class = 'error'>Message is a duplicate</div>";
}
else {
array_push ( $emailarchive, $emailentry);
$String = implode ($dl1, $emailarchive);
file_put_contents ('data/email-archive.txt', $String);
}
return $error;
}
function randomString () {
$String = "";
$chars = "abcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$size = strlen($chars);
for ($i = 0; $i < 7; $i++) {
$String .= $chars[rand(0, $size - 1)];
}
return $String;
}
function specialChars($str) {
return preg_match("/[^a-zA-Z0-9-:!?*'@#$,\.\s\)\(]/", $str) > 0;
}
function notPhoneNumber($str) {
return preg_match('/[^0-9-\)\(\s]/', $str) > 0;
}
function getRecordIdsFromFolder ($folder) {
$Newarray = array();
$Array1 = scandir ($folder);
foreach ($Array1 as $Item1) {
if (substr ($Item1, 0, 1) !== '.') {
$Recordid = str_replace (".txt", "", $Item1);
$Recordid = str_replace ('.php', '', $Recordid);
$Recordid = str_replace ('.css', '', $Recordid);
$Recordid = trim ($Recordid);
array_push ($Newarray, $Recordid);
}
}
return $Newarray;
}
?>
header.php ▾
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>'CatStack'</title>
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Elsie" rel="stylesheet">
<link rel= 'stylesheet' type='text/css' href= 'inc/style.css'>
</head>
<body>
<div class = 'outerwrap <?php echo $pageid; ?>'>
<a class = 'return' href = '../../magazine'>← Return</a><br><br>
<div class = 'headerwrap'>
<a class = 'menuitem' href = 'index.php?page=home'>Home</a>
<a class = 'menuitem' href = 'index.php?page=about'>About</a>
<a class = 'menuitem' href = 'index.php?page=stories'>Stories</a>
<a class = 'menuitem' href = 'index.php?page=authors'>Authors</a>
<a class = 'menuitem' href = 'index.php?page=contact'>Contact</a>
<br>
<a href = 'index.php'><div class = 'site-title'>CatStack</div></a>
<b>Discover What Really Smart Cats are Thinking!</b>
</div>
style.css ▾
@font-face {
font-family: Changa;
src: url('../data/fonts/Changa-Regular.ttf');
}
@font-face {
font-family: AmaticSC;
src: url('../data/fonts/AmaticSC-Bold.ttf');
}
@font-face {
font-family: Comfortaa;
src: url('../data/fonts/Comfortaa-Regular.ttf');
}
@font-face {
font-family: ComfortaaLight;
src: url('../data/fonts/Comfortaa-Light.ttf');
}
body {
font-family: 'Arial', sans-serif;
font-family: 'Comfortaa', sans-serif;
text-align: center;
line-height: 180%;
background-color: #c0e0df;
}
a {
text-decoration: none;
color: black;
}
a:hover {
color: purple;
}
img {
max-width: 400px;
}
img.circle-image {
width: 100px;
border: 1px solid #bbb;
border-radius: 50%;
}
/** HEADER AND MENU STYLES */
.site-title {
font-family: 'AmaticSC', serif;
font-size: 60px;
margin: 20px auto 30px auto;
color: black;
letter-spacing: 5px;
text-transform: uppercase;
}
h1 {
color: #fe013a;
letter-spacing: 3px;
margin: 30px auto;
text-transform: uppercase;
text-align: center;
font-size: 40px;
font-family: 'Changa', sans-serif;
}
h2 {
line-height: 150%;
font-family: 'Changa', sans-serif;
color: #fe013a;
text-align: center;
text-transform: uppercase;
}
h3 {
font-family: 'Comfortaa', sans-serif;
font-size: 16px;
}
h4 {
margin: 20px auto;
text-align: center;
}
h5 {
font-size: 12px;
margin: 0 auto;
color: #666;
font-family: 'Arial', sans-serif;
}
/** STANDARD PAGE SECTION STYLES */
.outerwrap, .admin-outerwrap {
width: 1000px;
max-width: 100%;
text-align: center;
margin: auto;
}
.admin-outerwrap {
width: 1300px;
}
.headerwrap {
padding: 20px 0;
margin: auto;
background-color: #eee;
padding: 0 20px 20px 20px;
border: 5px solid #a1ddda;
}
.menuitem, .content-column, .sidebar-column, .half-column {
display: inline-block;
box-sizing: border-box;
vertical-align: top;
max-width: 100%;
}
.menuitem {
padding: 0 10px;
border: 1px solid #bbb;
margin: 20px 5px;
font-size: 16px;
color: black;
}
.content-column {
width: 80%;
}
.sidebar-column {
width: 20%;
text-align: center;
padding-left: 20px;
}
.left {
text-align: left;
}
.half-column {
width: 50%;
}
a.centered {
text-align: center;
display: block;
margin: auto;
}
.gridcolumn, .input-gridcolumn, .admin-gridcolumn {
display: inline-block;
width: 200px;
max-width: 100%;
box-sizing: border-box;
margin: 15px;
padding: 15px 20px;
vertical-align: top;
border: 1px solid #cbd5e0;
background-color: white;
line-height: 150%;
height: 340px;
border-radius: 10px;
}
.gridcolumn img {
max-width: 100%;
max-height: 160px;
border-radius: 0;
}
.input-gridcolumn img {
max-width: 100%;
height: 100px;
max-height: auto;
}
.admin-gridcolumn {
height: 100%;
border-radius: 0;
}
/** Styles for 'display-story' page*/
.display-story img {
width: 300px;
max-width: 100%;
display: block;
margin: auto;
}
/** Input form styles */
.adminbutton, input.submitbutton {
color: white;
margin: 5px auto;
padding: 5px 7px;
font-size: 14px;
cursor: pointer;
text-decoration: none;
background-color: #3e4871;
border-radius: 2px;
font-style: normal;
width: 140px;
text-align: center;
max-width: 100%;
display: block;
}
input.submitbutton {
background-color: darkmagenta;
margin: 0;
}
textarea, input {
padding: 5px 10px;
font-size: 16px;
width: 100%;
max-width: 100%;
box-sizing: border-box;
}
label {
font-weight: bold;
}
input[type=checkbox], input[type=radio] {
max-width: 20px;
padding: 0;
margin: 3px;
vertical-align: middle;
}
.login input {
width: auto;
margin: auto;
}
.box {
display: block;
border: 1px solid #bbb;
margin: 10px;
width: 50px;
text-align: center;
padding: 5px;
}
footer {
margin: 100px auto;
}
/** BREAKPOINTS */
@media only screen and (max-width: 800px) {
.content-column, .sidebar-column {
width: 100%;
padding: 0 20px;
}
}
CATSTACK/admin-pages
add-update-author.php ▾
<?php
$authorid = getFromQueryString ('author');
$authorrecord = readDatabaseRecord($authorrecordkeys, 'data/authors/' . $authorid . '.txt');
//RETRIEVE FORM INPUT
if ($_SERVER ["REQUEST_METHOD"] == "POST" ) {
//Check if new author - if so, create id
$error = false;
if (!$authorid ) {
$authorid = createRecordId ($_POST['name']);
if ($authorid === '') {
echo "<div class = 'error'>Unable to create record id from title</div>";
$error = true;
}
//Check if file already exists
else if (file_exists ('data/authors/' . $authorid . '.txt')) {
echo "<div class = 'error'>author already exists</div>";
$error = true;
}
}
if ($error === false) {
//ASSIGN INPUT TO RECORD FIELDS
$authorrecord = assignPostValuesToRecord ($_POST, $authorrecordkeys);
writeDatabaseRecord ($authorrecord, 'data/authors/' . $authorid . '.txt');
}
}
if ($authorid) {
echo "<h2>Edit author</h2>";
echo "<h3>" . $authorrecord['name'] . "</h3>";
}
else {
echo "<h2>New author</h2>";
$authorrecord['date'] = date('Y-m-d');
}
?>
<form method='post' action='admin.php?adminpage=add-update-author&author=<?php echo $authorid;?>'>
<div class = 'content-column left'>
<?php
foreach ($authorrecordkeys as $key) {
if ($key === 'text') {
echo showWords ( $key);
echo "<textarea name = '" . $key . "' rows = '10' >" . $authorrecord[$key] . "</textarea>";
}
else if ($key !== 'image') {
echo showWords ( $key);
echo "<br><input type = 'text' name = '" .$key . "' value= '" . $authorrecord[$key] . "' />";
}
echo "<br><br>";
}
?>
<br><br>
<input class = 'submitbutton' type = 'submit' name = 'submit' value='Submit'/>
</div><div class = 'sidebar-column'>
<a class = 'adminbutton' href = 'admin.php?adminpage=dashboard'>Dashboard</a>
<a class = 'adminbutton' href = 'index.php?page=display-author&author=<?php echo $authorid; ?>'>View</a>
<a class = 'adminbutton' href = 'admin.php?adminpage=remove-author&author=<?php echo $authorid; ?>'>Remove</a>
</div>
<?php
echo "<br><br><b>Select Image for Author</b><br>";
$array1 = scandir ('data/images');
for ($i = 2; $i < count ($array1); $i++) {
echo "<div class = 'input-gridcolumn'>";
if ($authorrecord['image'] == $array1[$i] ){
echo "<label for = '" . $i . "'> " . $array1[$i] . "</label>";
echo "<input id = '" . $i . "' type = 'radio' name = 'image' value = '" . $array1[$i] . "' checked/>";
}
else {
echo "<label for = '" . $i . "'> " . $array1[$i] . "</label>";
echo "<input id = '" . $i . "' type = 'radio' name = 'image' value = '" . $array1[$i] . "' />";
}
echo "<br><img src = 'data/images/" . $array1[$i] . "' alt = 'img' >";
echo "</div>";
}
?>
</form>
add-update-story.php ▾
<?php
$storyid = getFromQueryString ('story');
$storyrecord = readDatabaseRecord($storyrecordkeys, 'data/stories/' . $storyid . '.txt');
//RETRIEVE FORM INPUT
if ($_SERVER ["REQUEST_METHOD"] == "POST" ) {
//Check if new story - if so, create id
$error = false;
if (!$storyid ) {
if (isset ($_POST['title'])) {
$storyid = createRecordId ($_POST['title']);
if ($storyid === '') {
echo "<div class = 'error'>Unable to create record id from title</div>";
$error = true;
}
//Check if file already exists
else if (file_exists ('data/stories/' . $storyid . '.txt')) {
echo "<div class = 'error'>Story already exists</div>";
$error = true;
}
}
else {
echo "</div class = 'error'>Missing story Ttile</div>";
$error = true;
}
}
if (!$error ) {
//ASSIGN INPUT TO RECORD FIELDS
$storyrecord = assignPostValuesToRecord($_POST, $storyrecordkeys);
//Check date format
if ($storyrecord['date'] ) {
if (is_numeric (substr ($storyrecord['date'], 0,4))) {
//format yyyy/mm/dd
$month = substr ($storyrecord['date'], 5, 2);
$day = substr ($storyrecord['date'], 8,2);
$year = substr ($storyrecord['date'], 0, 4);
$storyrecord['date'] = $year . '-' . $month . '-' . $day;
}
else {
//format mm/dd/yyyy
$month = substr ($storyrecord['date'], 0, 2);
$day = substr ($storyrecord['date'], 3,2);
$year = substr ($storyrecord['date'], 6, 4);
$storyrecord['date'] = $year . '-' . $month . '-' . $day;
}
}
else {
//default current date
$storyrecord['date'] = date('Y-m-d');
}
removeMapEntries ("data/maps/tag-story-map.txt", "", $storyid);
if (isset ($_POST['selected'])) {
$selected = $_POST['selected'];
foreach ($selected as $tag) {
addMapEntry ("data/maps/tag-story-map.txt", $tag, $storyid);
}
}
writeDatabaseRecord ($storyrecord, 'data/stories/' . $storyid . '.txt');
removeMapEntries ('data/maps/story-author-map.txt', $storyid, '');
addMapEntry ('data/maps/story-author-map.txt', $storyid, $storyrecord['author']);
removeMapEntries ('data/maps/date-story-map.txt', '', $storyid);
addMapEntryReverse ('data/maps/date-story-map.txt', $storyrecord['date'], $storyid);
}
}
if ($storyid) {
echo "<h2>Edit Story</h2>";
echo "<h3>" . $storyrecord['title'] . "</h3>";
}
else {
echo "<h2>New Story</h2>";
$storyrecord['date'] = date('Y-m-d');
}
?>
<form method='post' action='admin.php?adminpage=add-update-story&story=<?php echo $storyid;?>'>
<div class = 'content-column left'>
<?php
echo "<label for = 'title'>Title</label><br>";
echo "<textarea id = 'title' name = 'title' rows = '1' >" . $storyrecord['title'] . "</textarea>";
echo "<br><br><label for = 'date' >Date</label><br>";
echo "<input id = 'date' type = 'date' name = 'date' value = '" . $storyrecord['date'] . "'/>";
echo "<br><br><label for = 'text' >Text</label><br>";
echo "<textarea id = 'text' name = 'text' rows = '10' >" . $storyrecord['text'] . "</textarea>";
echo "<br><br><b>Author</b><br>";
$authors = getRecordsIdFromFolder ('data/authors');
foreach ($authors as $authorid) {
$authorrecord = readDatabaseRecord ($authorrecordkeys, 'data/authors/' . $authorid . '.txt');
if ($storyrecord['author'] === $authorid) {
echo "<input id = '" . $authorid . "' type = 'radio' name = 'author' value = '" . $authorid . "' checked/>";
}
else {
echo "<input id = '" . $authorid . "' type = 'radio' name = 'author' value = '" . $authorid . "'/>";
}
echo "<label for = '" . $authorid . "'>";
echo showWords ($authorid) . "</label><br>";
}
echo "<br><br><b>Tags</b><br>";
$currentarray = selectMapEntries ('data/maps/tag-story-map.txt', '', $storyid);
$tagarray = readArray ('data/tags.txt', ',');
foreach ($tagarray as $tag) {
if (in_array($tag, $currentarray)) {
echo "<input id = '" . $tag . "' class = 'checkbox' type = 'checkbox' name = 'selected[]' value = '" . $tag . "' checked />";
}
else {
echo "<input id = '" . $tag . "' class = 'checkbox' type = 'checkbox' name = 'selected[]' value = '" . $tag . "' />";
}
echo "<label for = '" .$tag . "'>";
echo showWords ($tag);
echo "</label>";
echo "<br>";
}
echo "<br><br><input type = 'submit' class = 'submitbutton' name = 'submit' value = 'Save' />";
?>
</div><div class = 'sidebar-column'>
<a class = 'adminbutton' href = 'admin.php?adminpage=dashboard'>Dashboard</a>
<a class = 'adminbutton' href = 'index.php?page=display-story&story=<?php echo $storyid; ?>'>View</a>
<a class = 'adminbutton' href = 'admin.php?adminpage=remove-story&story=<?php echo $storyid; ?>'>Remove</a>
</div>
<?php
echo "<br><br><b>Select Image for Story</b><br>";
$array1 = scandir ('data/images');
for ($i = 2; $i < count ($array1); $i++) {
echo "<div class = 'input-gridcolumn'>";
if ($storyrecord['image'] == $array1[$i] ){
echo "<label for = '" . $i . "'> " . $array1[$i] . "</label>";
echo "<input id = '" . $i . "' type = 'radio' name = 'image' value = '" . $array1[$i] . "' checked/>";
}
else {
echo "<label for = '" . $i . "'> " . $array1[$i] . "</label>";
echo "<input id = '" . $i . "' type = 'radio' name = 'image' value = '" . $array1[$i] . "' />";
}
echo "<br><img src = 'data/images/" . $array1[$i] . "' alt = 'img' >";
echo "</div>";
}
?>
</form>
dashboard.php ▾
<h1>Dashboard</h1>
<div class = 'content-column'>
<div class = 'half-column'>
<h3>Stories</h3>
<?php
$prevyear = $prevquarter = '';
$datearray = extractFromMap ('data/maps/date-story-map.txt', 0);
$storyarray = extractFromMap ('data/maps/date-story-map.txt', 1);
$prevyear = '';
echo "<div>";
foreach ($datearray as $id => $date) {
$year = substr ($date, 0, 4);
if ($year !== $prevyear) {
echo "</div><div class = 'admin-gridcolumn'><b>" . $year . "</b><br>";
$prevyear = $year;
}
if (array_key_exists ($id, $storyarray)) {
$storyid = $storyarray[$id];
$storyrecord = readDatabaseRecord ($storyrecordkeys, 'data/stories/' . $storyid . '.txt');
echo "<a href = 'admin.php?adminpage=add-update-story&story=" . $storyid . "'>" . $storyrecord['title'] . "</a><br><br>";
}
}
echo "</div>";
?>
</div><div class = 'half-column'>
<h3>Authors</h3>
<?php
$authors = getRecordsIdFromFolder ('data/authors');
foreach ($authors as $authorid) {
$authorrecord = readDatabaseRecord ($authorrecordkeys, 'data/authors/' . $authorid . '.txt');
echo "<a href = 'admin.php?adminpage=add-update-author&author=" . $authorid . "'>" . $authorrecord['name'] . "</a><br>";
}
echo "<h3>Tags</h3>";
$tagarray = readArray ('data/tags.txt', ",");
foreach ($tagarray as $tag) {
echo "<a href = 'admin.php?adminpage=update-tag&tag=" . $tag . "'>" . showWords ($tag) . "</a><br>";
}
?>
</div>
</div><div class = 'sidebar-column'>
<a class = 'adminbutton' href = 'admin.php?adminpage=add-update-story'>Add Story</a>
<a class = 'adminbutton' href = 'admin.php?adminpage=add-update-author'>Add Author</a>
<a class = 'adminbutton' href = 'admin.php?adminpage=manage-tags'>Manage Tags</a>
</div>
logout.php ▾
<?php
session_unset();
session_destroy();
$pageid = 'logout';
$loggedin = false;
echo "You are now logged out. ";
?>
manage-tags.php ▾
<?php
$tagarray = readArray ('data/tags.txt', ",");
?>
<h1>Manage Tags </h1>
<div class = 'content-column'>
<?php
if ($_SERVER ["REQUEST_METHOD"] == "POST" ) {
if (isset ($_POST['newtag'])) {
$newtag = createRecordId ($_POST['newtag']) ;
if ($newtag) {
addNameToArray ('data/tags.txt', $newtag,',');
}
else {
echo "<div class = 'error'>Invalid characters in tag</div>";
}
}
if (isset ($_POST['tag-to-remove'])) {
$tagtoremove = $_POST['tag-to-remove'];
removeNameFromArray ("data/tags.txt", $tagtoremove, ",");
removeMapEntries ('data/maps/tag-story-map.txt', $tagtoremove, "");
}
$tagarray = readArray ('data/tags.txt', ",");
}
?>
<div class = 'half-column'>
<?php
echo "<h3>All Tags</h3>";
foreach ($tagarray as $tag) {
echo "<a href = 'admin.php?adminpage=update-tag&tag=" . $tag . "'>" . $tag . "</a><br>";
}
?>
<br><br>
</div><div class = 'half-column'>
<form method = 'post' action = 'admin.php?adminpage=manage-tags'>
<label for = 'newtag'>New tag</label>
<br><input id = 'newtag' name = 'newtag' />
<br><br><input class = 'submitbutton' name = 'submit-new' type = 'submit' value='Update'>
</form>
<br>
<form method = 'post' action = 'admin.php?adminpage=manage-tags'>
<label for="tag-to-remove">Choose a tag to remove</label><br>
<select name="tag-to-remove" id="tag-to-remove">
<?php
foreach ($tagarray as $tag) {
echo "<option value= '" . $tag . "'>" . $tag . "</option>";
}
?>
</select>
<br><input class = 'submitbutton' name = 'submit-remove' type = 'submit' value='Remove'>
</form>
</div>
</div><div class = 'sidebar-column'>
<a class = 'adminbutton' href = 'admin.php?adminpage=dashboard'>Dashboard</a>
</div>
remove-author.php ▾
<?php
$authorid = getFromQueryString ('author');
$authorrecord = readDatabaseRecord ($authorrecordkeys, 'data/authors/' . $authorid . '.txt' );
$removeflag = false;
if ($_SERVER ["REQUEST_METHOD"] == "POST" ) {
if (isset($_POST ['removeflag'])) {
if ($_POST['removeflag'] === "REMOVE") {
moveToTrash ('authors', $authorid) ;
$removeflag = true;
}
}
}
?>
<div class = 'content-column'>
<h3>Remove </h3>
<?php
if ($removeflag === false) {
?>
<form method = 'post' action = 'admin.php?adminpage=remove-author&author=<?php echo $authorid ?>'>
<h3>Are you sure you want to move <?php echo $authorrecord['name'] ; ?> to the Trash Bin?</h3><br>
NO: <input type = 'radio' name = 'removeflag' value = '' checked />
YES: <input type = 'radio' name = 'removeflag' value = 'REMOVE' />
<br><br><input class = 'submitbutton' type = 'submit' name = 'submit' value='Remove'/>
</form>
<?php
}
else {
echo "This author has been removed";
}
?>
</div><div class = 'sidebar-column'>
<a class = 'adminbutton' href = 'admin.php?adminpage=dashboard'>Dashboard</a>
</div>
remove-story.php ▾
<?php
$storyid = getFromQueryString ('story');
$storyrecord = readDatabaseRecord ($storyrecordkeys, 'data/stories/' . $storyid . '.txt' );
$removeflag = false;
if ($_SERVER ["REQUEST_METHOD"] == "POST" ) {
if (isset($_POST ['removeflag'])) {
if ($_POST['removeflag'] === "REMOVE") {
moveToTrash ('stories', $storyid) ;
$removeflag = true;
}
}
}
?>
<div class = 'content-column'>
<h3>Remove </h3>
<?php
if ($removeflag === false) {
?>
<form method = 'post' action = 'admin.php?adminpage=remove-story&story=<?php echo $storyid ?>'>
<h3>Are you sure you want to move <?php echo $storyrecord['title'] ; ?> to the Trash Bin?</h3><br>
NO: <input type = 'radio' name = 'removeflag' value = '' checked />
YES: <input type = 'radio' name = 'removeflag' value = 'REMOVE' />
<br><br><input class = 'submitbutton' type = 'submit' name = 'submit' value='Remove'/>
</form>
<?php
}
else {
echo "This story has been removed";
}
?>
</div><div class = 'sidebar-column'>
<a class = 'adminbutton' href = 'admin.php?adminpage=dashboard'>Dashboard</a>
</div>
update-tag.php ▾
<?php
$tag = getFromQueryString ('tag');
if ($_SERVER ["REQUEST_METHOD"] == "POST" ) {
removeMapEntries ("data/maps/tag-story-map.txt", $tag, "");
if (isset ($_POST['selected'])) {
$selected = $_POST['selected'];
foreach ($selected as $storyid) {
$storyid = trim ($storyid);
addMapEntry ("data/maps/tag-story-map.txt", $tag, $storyid);
}
}
}
echo " <h1>Update Tag</h1>";
echo "<h2>" . showWords ($tag) . "</h2>";
?>
<div class = 'content-column left'>
<?php
echo "<form method = 'post' action = 'admin.php?adminpage=update-tag&tag=" . $tag . " '> ";
$currentarray = selectMapEntries ('data/maps/tag-story-map.txt', $tag, "");
$tagarray = readArray ('data/tags.txt', ',');
$stories = getRecordsIdFromFolder ('data/stories');
foreach ($stories as $storyid) {
$stories = selectMapEntries ('data/tag-story-map.txt', '', $storyid);
if (in_array($storyid, $currentarray)) {
echo "<input id = '" . $storyid . "' class = 'checkbox' type = 'checkbox' name = 'selected[]' value = '" . $storyid . "' checked />";
}
else {
echo "<input id = '" . $storyid . "' class = 'checkbox' type = 'checkbox' name = 'selected[]' value = '" . $storyid . "' /> ";
}
echo "<label for = '" .$storyid . "'>";
echo "<a href = 'admin.php?adminpage=add-update-story&story=" . $storyid . "'>" . showWords ($storyid ). "</a>";
echo "</label>";
echo "<br>";
}
echo "<input class = 'submitbutton' name = 'submit-record' type = 'submit' value='Select'> ";
echo "</form> ";
?>
</div><div class = 'sidebar-column'>
<br><a class = 'adminbutton' href = 'admin.php?adminpage=dashboard'>Dashboard</a>
<a class = 'adminbutton' href = 'admin.php?adminpage=manage-tags'>Manage Tags</a>
</div>
CATSTACK/data
authors ▾
bob-cat.txt
catzilla.txt
miss-kitty.txt
princess.txt
priscilla-paddypaws.txt
professor-fluffy.txt
ralph.txt
willow.txt
catzilla.txt
miss-kitty.txt
princess.txt
priscilla-paddypaws.txt
professor-fluffy.txt
ralph.txt
willow.txt
fonts ▾
AmaticSC-Bold.ttf
AmaticSC-Regular.ttf
Changa-Regular.ttf
Comfortaa-Light.ttf
Comfortaa-Regular.ttf
AmaticSC-Regular.ttf
Changa-Regular.ttf
Comfortaa-Light.ttf
Comfortaa-Regular.ttf
images ▾
Holly-in-grass3.jpg
Horace.jpg
Money.jpg
Ralph-window.jpg
Ralph-with-squishables.jpg
Scottie1.jpg
Scottie2.jpg
Sophie2.jpg
addict.jpg
barkleythedoggie.jpg
bob.jpg
bobcat.jpg
box.jpg
bubbles.jpg
business-cat.jpg
catnip.jpg
delilah.jpg
fish-or-checken.jpg
iguana.jpg
izzy-on-floor.jpg
izzy-on-floor2.jpg
izzy.jpg
kitty.jpg
litter-box.jpg
misskitty.JPG
misskitty.jpg
nappy.jpg
new-bob.jpg
new-lizard.jpg
nippy.jpg
outdoors.jpg
owl.jpg
paddypaws.jpg
ritchie.jpg
rotated-izzy-on-floor.jpg
skippy.jpg
spike.jpg
squeekie.jpg
stampie.jpg
tanny-2.jpg
tuna.jpg
what-is-money.jpg
willow.jpg
with-mouse.jpg
Horace.jpg
Money.jpg
Ralph-window.jpg
Ralph-with-squishables.jpg
Scottie1.jpg
Scottie2.jpg
Sophie2.jpg
addict.jpg
barkleythedoggie.jpg
bob.jpg
bobcat.jpg
box.jpg
bubbles.jpg
business-cat.jpg
catnip.jpg
delilah.jpg
fish-or-checken.jpg
iguana.jpg
izzy-on-floor.jpg
izzy-on-floor2.jpg
izzy.jpg
kitty.jpg
litter-box.jpg
misskitty.JPG
misskitty.jpg
nappy.jpg
new-bob.jpg
new-lizard.jpg
nippy.jpg
outdoors.jpg
owl.jpg
paddypaws.jpg
ritchie.jpg
rotated-izzy-on-floor.jpg
skippy.jpg
spike.jpg
squeekie.jpg
stampie.jpg
tanny-2.jpg
tuna.jpg
what-is-money.jpg
willow.jpg
with-mouse.jpg
maps ▾
date-story-map.txt
story-author-map.txt
tag-story-map.txt
story-author-map.txt
tag-story-map.txt
password.txt ▾
LoveToEatThemMousies stories ▾
are-you-a-fish-cat-or-a-chicken-cat.txt
catnip-how-to-tell-if-you-are-an-addict.txt
catnip-in-history.txt
controlling-the-litter-box.txt
customer-service-is-overrated.txt
enjoying-the-outdoors.txt
extreme-challenges.txt
how-to-be-a-complete-pest.txt
how-to-raise-successful-kittens.txt
nappy-new-year.txt
overcoming-tolerance.txt
seven-habits-of-highly-effective-cats.txt
seven-ways-to-get-a-fatter-tummy.txt
the-cat-inspired-business.txt
walking-your-person.txt
what-is-money.txt
why-do-dogs-exist.txt
catnip-how-to-tell-if-you-are-an-addict.txt
catnip-in-history.txt
controlling-the-litter-box.txt
customer-service-is-overrated.txt
enjoying-the-outdoors.txt
extreme-challenges.txt
how-to-be-a-complete-pest.txt
how-to-raise-successful-kittens.txt
nappy-new-year.txt
overcoming-tolerance.txt
seven-habits-of-highly-effective-cats.txt
seven-ways-to-get-a-fatter-tummy.txt
the-cat-inspired-business.txt
walking-your-person.txt
what-is-money.txt
why-do-dogs-exist.txt
tags.txt ▾
health,philosophy,opinion,education,naps trash ▾
authors----horace.txt
authors----squeekie.txt
stories----bob-cat.txt
stories----test.txt
authors----squeekie.txt
stories----bob-cat.txt
stories----test.txt
username.txt ▾
MissKitty