Initial commit of codebase

This commit is contained in:
Junior 2022-02-15 15:14:49 +00:00
parent 769b282306
commit 4427880825
54 changed files with 2569 additions and 0 deletions

35
ajax/getalbuminfo.php Normal file
View File

@ -0,0 +1,35 @@
<?php
require '../header.php';
$data = array();
$data["albumcontents"] = "";
$data["albumtitle"] = "";
$data["albumdescription"] = "";
if ( $_SESSION['currentalbum'] != 0 ) {
$album = new Album($_SESSION['currentalbum']);
if ( $album->getID() == 0 ) {
$_SESSION['currentalbum'] = 0;
} else {
$griditems = Image::getImagesForAlbum($album->getID());
$data["albumtitle"] = $album->getTitle();
$data["albumdescription"] = $album->getDescription();
}
}
if ( $_SESSION['currentalbum'] == 0 ) {
$griditems = Album::getList();
}
foreach ( $griditems as $griditem ) {
$data["albumcontents"] .= "<div class=\"thumbnail_grid\">";
$data["albumcontents"] .= "<img class=\"thumbnail_grid_image albumthumbnail\" id=\"griditem_{$griditem->getID()}\" src=\"{$griditem->getThumbnail(URLSAFE)}\" />";
$data["albumcontents"] .= "<div class=\"thumbnail_grid_title\">{$griditem->getTitle(HTMLSAFE)}</div>";
$data["albumcontents"] .= "</div>\n";
}
$data["currentalbum"] = $_SESSION['currentalbum'];
header('Content-Type: application/json');
echo json_encode($data);
exit();
// vim: set ts=4:sw=4

15
ajax/refreshalbums.php Normal file
View File

@ -0,0 +1,15 @@
<?php
require '../header.php';
requireLogin();
Album::refreshAlbums();
$data = array();
header('Content-Type: application/json');
echo json_encode($data);
exit();
// vim: set ts=4:sw=4

29
ajax/setcurrentalbum.php Normal file
View File

@ -0,0 +1,29 @@
<?php
require '../header.php';
$data = array();
if ( !isset($_REQUEST['albumid']) ) {
$_SESSION['currentalbum'] = 0;
sendResponse($data);
}
$album = new Album($_REQUEST['albumid']);
if ( $album->getID() == 0 ) {
$_SESSION['currentalbum'] = 0;
sendResponse($data);
}
$_SESSION['currentalbum'] = $album->getID();
sendResponse($data);
function sendResponse($data) {
header('Content-Type: application/json');
echo json_encode($data);
exit();
}
exit();
// vim: set ts=4:sw=4

26
ajax/validatelogin.php Normal file
View File

@ -0,0 +1,26 @@
<?php
require '../header.php';
require_anonymous();
if ( !isset($_REQUEST['username']) || !isset($_REQUEST['password']) || !isset($_REQUEST['remember']) ) redirectPage();
$user = User::getUserFromLogin($_REQUEST['username'], $_REQUEST['password']);
$data = array();
if ( $user === User::LOGININVALID ) {
$data['status'] = "invalid";
} else {
$_SESSION['userid'] = $user->getID();
$user->saveLastLogin();
if ( $_REQUEST['remember'] == "1" ) {
$user->setCookie($_SERVER['REMOTE_ADDR']);
}
$data['status'] = "valid";
}
header('Content-Type: application/json');
echo json_encode($data);
exit();

4
albums/index.php Normal file
View File

@ -0,0 +1,4 @@
<?php
header("Location: ../");
exit();

287
class_album.php Normal file
View File

@ -0,0 +1,287 @@
<?php
class Album implements JsonSerializable {
private $id = 0;
private $foldername = "";
private $title = "";
private $thumbnail = "";
private $description = "";
private $createtime = "";
public function getID() {
return intval($this->id);
}
public function getFolderName($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->foldername);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->foldername, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->foldername);
break;
default:
return $this->foldername;
break;
}
}
public function getTitle($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->title);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->title, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->title);
break;
default:
return $this->title;
break;
}
}
public function getThumbnail($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->thumbnail);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->thumbnail, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->thumbnail);
break;
case URLSAFE:
if ( $this->thumbnail == "" ) {
return "graphics/no-image-available_thm.gif";
} else {
return htmlspecialchars(basename(THUMBNAILFOLDER) . "/" . $this->foldername . $this->thumbnail, ENT_QUOTES);
}
break;
default:
return $this->thumbnail;
break;
}
}
public function getDescription($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->description);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->description, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->description);
break;
default:
return $this->description;
break;
}
}
public function getCreateTime($flag = 0) {
switch ($flag) {
case TIMESTAMP:
return strtotime($this->createtime);
break;
case PRETTY:
return date("F j Y H:i:s", strtotime($this->createtime));
break;
default:
return $this->createtime;
break;
}
}
public function setID($id = null) {
if (is_null($id)) return false;
$id = abs(intval($id));
if ($id == 0) return false;
$this->id = $id;
return true;
}
public function setFolderName($foldername = null) {
if (is_null($foldername) || ($foldername == "")) return false;
settype($foldername, "string");
$this->foldername = $foldername;
return true;
}
public function setTitle($title = null) {
if (is_null($title) || ($title == "")) return false;
settype($title, "string");
$this->title = $title;
return true;
}
public function setThumbnail($thumbnail = null) {
if (is_null($thumbnail) || ($thumbnail == "")) return false;
settype($thumbnail, "string");
$this->thumbnail = $thumbnail;
return true;
}
public function setDescription($description = null) {
if (is_null($description) || ($description == "")) return false;
settype($description, "string");
$this->description = $description;
return true;
}
public function refreshImages() {
global $globaldbh;
// Get the images from this album's folder
$imagefiles = glob(ALBUMFOLDER . $this->getFolderName() . "*.[jJpPgG][pPeEiI][gGeEfF]*");
// Remove existing images from the DB if file no longer exists
$images = Image::getImagesForAlbum($this->getID());
foreach ( $images as $index => $image ) {
$albumfile = ALBUMFOLDER . $this->getFolderName() . $image->getFileName();
if ( !in_array($albumfile, $imagefiles) ) {
if ( $image->getFileName() == $this->getThumbnail ) {
$this->setThumbnail("");
$this->save();
}
$image->delete();
} else {
// If this image already exists,
// delete it from the imagefiles list so we only
// create newly identified images in the next step
array_splice($imagefiles, array_search($albumfile, $imagefiles), 1);
}
}
// Add new images
foreach ( $imagefiles as $imagefile ) {
$imagefile = basename($imagefile);
$image = new Image();
$image->setAlbumID($this->getID());
$image->setAlbumFolder($this->getFolderName());
$image->setFileName($imagefile);
$image->setTitle(substr($imagefile, 0, strrpos($imagefile, ".")));
$image->save();
}
}
public static function refreshAlbums() {
global $globaldbh;
// Get the folders inside ALBUMFOLDER
$folders = glob(ALBUMFOLDER . "*", GLOB_ONLYDIR|GLOB_MARK);
// Remove existing albums from DB if folder doesn't exist
$albums = Album::getList();
foreach ( $albums as $index => $album ) {
$albumfolder = ALBUMFOLDER . $album->getFolderName();
if ( !in_array($albumfolder, $folders) ) {
$album->delete();
} else {
// If this album has a folder that exists,
// delete it from the folder list so we only
// create newly identified folders in the next step
array_splice($folders, array_search(ALBUMFOLDER . $album->getFolderName(), $folders), 1);
}
}
// Add albums for new folders
foreach ( $folders as $folder ) {
$folder = substr($folder, strlen(ALBUMFOLDER));
$album = new Album();
$album->setFolderName($folder);
$album->setTitle(substr($folder, 0, -1));
$album->save();
}
// Refresh images for all albums
$albums = Album::getList();
foreach ( $albums as $album ) {
$album->refreshImages();
}
}
public static function getList() {
global $globaldbh;
$query = "SELECT id FROM " . AppDB::TABLE_ALBUMS . " ORDER BY title";
$sth = $globaldbh->prepare($query);
$sth->execute();
$thelist = array();
while ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) {
$thelist[] = new Album($row['id']);
}
return $thelist;
}
public function jsonSerialize() {
return [
'id' => $this->getID(),
'foldername' => $this->getFolderName(),
'title' => $this->getTitle(),
'description' => $this->getDescription(),
'createtime' => $this->getCreateTime(),
'images' => Image::getImagesForAlbum($this->getID())
];
}
public function delete() {
global $globaldbh;
$query = "DELETE FROM " . AppDB::TABLE_ALBUMS . " WHERE id=:id";
$sth = $globaldbh->prepare($query);
$sth->bindValue(":id", (int) $this->getID(), PDO::PARAM_INT);
$sth->execute();
$this->setID(0);
$thumbnailfolder = THUMBNAILFOLDER . $this->getFolderName();
if ( is_dir($thumbnailfolder) ) {
unlink($thumbnailfolder . "*");
rmdir($thumbnailfolder);
}
}
public function save() {
global $globaldbh;
$query = "INSERT INTO " . AppDB::TABLE_ALBUMS . " ";
$query .= "(id, foldername, title, thumbnail, description, createtime) ";
$query .= "VALUES(NULL, :foldername, :title, :thumbnail, :description, NOW()) ";
$query .= "ON DUPLICATE KEY UPDATE ";
$query .= "foldername=:foldername, title=:title, thumbnail=:thumbnail, description=:description";
$sth = $globaldbh->prepare($query);
$sth->bindValue(":id", (int) $this->getID(), PDO::PARAM_INT);
$sth->bindValue(":foldername", $this->getFolderName(), PDO::PARAM_STR);
$sth->bindValue(":title", $this->getTitle(), PDO::PARAM_STR);
$sth->bindValue(":thumbnail", $this->getThumbnail(), PDO::PARAM_STR);
$sth->bindValue(":description", $this->getDescription(), PDO::PARAM_STR);
$sth->execute();
if ( $this->getID() == 0 ) {
$this->setID($globaldbh->lastInsertId());
mkdir(THUMBNAILFOLDER . $this->getFolderName());
}
}
function __construct($reqid = 0) {
global $globaldbh;
$reqid = intval($reqid);
$query = "SELECT id, foldername, title, thumbnail, description, createtime " .
"FROM " . AppDB::TABLE_ALBUMS . " WHERE id=:id";
$sth = $globaldbh->prepare($query);
$sth->bindValue(":id", $reqid, PDO::PARAM_INT);
$sth->execute();
if ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) {
$this->setID($row['id']);
$this->setFolderName($row['foldername']);
$this->setTitle($row['title']);
$this->setThumbnail($row['thumbnail']);
$this->setDescription($row['description']);
$this->createtime = $row['createtime'];
}
}
}
// vim: set ts=4:sw=4

54
class_appdb.php Normal file
View File

@ -0,0 +1,54 @@
<?php
class AppDB {
const TABLE_USERS = "users";
const TABLE_COOKIES = "cookies";
const TABLE_SETTINGS = "settings";
const TABLE_ALBUMS = "albums";
const TABLE_IMAGES = "images";
const TABLE_LINKS = "links";
const DBVERSION = "A000001";
public static function getDBH() {
$dbh = null;
$dbh = new PDO("mysql:host=" . DBHOST . ";dbname=" . DBNAME, DBUSER, DBPASS);
// Try to connect to the database
try {
if ( DBTYPE == "mysql" ) {
$dbh = new PDO("mysql:host=" . DBHOST . ";dbname=" . DBNAME, DBUSER, DBPASS);
} else if ( DBTYPE == "sqlite" ) {
$dbh = new PDO("sqlite:" . SQLITEDB);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->exec("PRAGMA foreign_keys = ON");
} else {
throw new Exception("Bad database configuration in config file!");
}
} catch (PDOException | Exception $e) {
//header('Location: error_db.php?connection=');
echo "Couldn't connect to DB!";
exit();
}
try {
$query = "SELECT version FROM " . AppDB::TABLE_SETTINGS;
$sth = $dbh->prepare($query);
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
if ( !is_array($row) ) throw new Exception("Table seems to be missing");
} catch (PDOException | Exception $e) {
header('Location: error_db.php?tables=');
exit();
}
if ( !isset($row['version']) || ($row['version'] != AppDB::DBVERSION) ) {
//header("Location: error_db.php?version=");
exit();
}
return $dbh;
}
}
// vim: set ts=3:sw=3

316
class_image.php Normal file
View File

@ -0,0 +1,316 @@
<?php
class Image implements JsonSerializable {
private $id = 0;
private $album_id = 0;
private $albumfolder = "";
private $filename = "";
private $title = "";
private $description = "";
private $createtime = "";
const VALID_MIME_TYPES = array(
"image/jpeg",
"image/png",
"image/gif"
);
const MIME_TYPES_EXT = array(
"image/jpeg" => ".jpg",
"image/jpeg" => ".jpeg",
"image/png" => ".png",
"image/gif" => ".gif"
);
const EXT_MIME_TYPES = array(
"jpg" => "image/jpeg",
"jpeg" => "image/jpeg",
"png" => "image/png",
"gif" => "image/gif"
);
public function getID() {
return intval($this->id);
}
public function getAlbumID() {
return intval($this->album_id);
}
public function getCreateTime($flag = 0) {
switch ($flag) {
case TIMESTAMP:
return strtotime($this->createtime);
break;
case PRETTY:
return date("F j Y H:i:s", strtotime($this->createtime));
break;
default:
return $this->createtime;
break;
}
}
public function getFileName($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->filename);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->filename, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->filename);
break;
default:
return $this->filename;
break;
}
}
public function getThumbnail($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->filename);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->filename, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->filename);
break;
case URLSAFE:
return htmlspecialchars(basename(THUMBNAILFOLDER) . "/" . $this->albumfolder . $this->filename, ENT_QUOTES);
break;
default:
return $this->filename;
break;
}
}
public function getAlbumFolder($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->albumfolder);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->albumfolder, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->albumfolder);
break;
default:
return $this->albumfolder;
break;
}
}
public function getTitle($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->title);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->title, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->title);
break;
default:
return $this->title;
break;
}
}
public function getDescription($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->description);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->description, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->description);
break;
default:
return $this->description;
break;
}
}
public function getPathToFile() {
return (dirname($_SERVER['SCRIPT_FILENAME']) . "/" . ALBUMFOLDER . $this->getFileName());
}
public function getURLToFile() {
return (ALBUMFOLDER . $this->getFilePath() . $this->getFileName());
}
public function setID($id = null) {
if (is_null($id)) return false;
$id = abs(intval($id));
if ($id == 0) return false;
$this->id = $id;
return true;
}
public function setAlbumID($id = null) {
if (is_null($id)) return false;
$id = intval($id);
if ($id <= 0) return false;
$this->album_id = $id;
return true;
}
public function setAlbumFolder($folder = null) {
if ( is_null($folder) || ($folder == "") ) return false;
$this->albumfolder = $folder;
}
public function setFileName($name = null) {
if ( is_null($name) || ($name == "") ) return false;
$this->filename = $name;
}
public function setTitle($title = null) {
if ( is_null($title) || ($title == "") ) return false;
$this->title = $title;
}
public function setDescription($description = null) {
if ( is_null($description) || ($description == "") ) return false;
$this->description = $description;
}
public static function getImagesForAlbum($albumid = 0) {
global $globaldbh;
$query = "SELECT id FROM " . AppDB::TABLE_IMAGES . " WHERE album_id=:album_id ORDER BY title";
$sth = $globaldbh->prepare($query);
$sth->bindValue(":album_id", (int) $albumid, PDO::PARAM_INT);
$sth->execute();
$thelist = array();
while ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) {
$thelist[] = new Image($row['id']);
}
return $thelist;
}
public function createThumbnail() {
if ( $this->getAlbumID() == 0 ) return false;
$albumimage = ALBUMFOLDER . $this->getAlbumFolder() . $this->getFileName();
$thumbnailimage = THUMBNAILFOLDER . $this->getAlbumFolder() . $this->getFileName();
$ext = substr($albumimage, strrpos($albumimage, ".") + 1);
// Resize image
list($width, $height) = getimagesize($albumimage);
$ratio = $width/$height;
$maxW = 284;
$maxH = 160;
$newWidth = $maxW;
$newHeight = ($maxW/$width) * $height;
if ( $newHeight > $maxH ) {
$newHeight = $maxH;
$newWidth = ($maxH/$height) * $width;
}
if ( file_exists($thumbnailimage) ) unlink($thumbnailimage);
$newimg = imagecreatetruecolor($newWidth, $newHeight);
switch ( Image::EXT_MIME_TYPES[strtolower($ext)] ) {
case "image/jpeg":
$image = imagecreatefromjpeg($albumimage);
imagecopyresampled($newimg, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
$success = imagejpeg($newimg, $thumbnailimage);
break;
case "image/png":
$image = imagecreatefrompng($albumimage);
imagecopyresampled($newimg, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imagepng($newimg, $thumbnailimage);
break;
case "image/gif":
$image = imagecreatefromgif($albumimage);
imagecopyresampled($newimg, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imagegif($newimg, $thumbnailimage);
break;
}
}
public static function getList() {
global $globaldbh;
$query = "SELECT id FROM " . AppDB::TABLE_IMAGES . " ORDER BY album_id, title";
$sth = $globaldbh->prepare($query);
$sth->execute();
$thelist = array();
while ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) {
$thelist[] = new Image($row['id']);
}
return $thelist;
}
public function jsonSerialize() {
return [
'id' => $this->getID(),
'album_id' => $this->getAlbumID(),
'img' => basename(ALBUMFOLDER) . "/" . $this->albumfolder . "/" . $this->getFileName(),
'createtime' => $this->getCreateTime()
];
}
public function delete() {
global $globaldbh;
$query = "DELETE FROM " . AppDB::TABLE_IMAGES . " WHERE id=:id";
$sth = $globaldbh->prepare($query);
$sth->bindValue(":id", (int) $this->getID(), PDO::PARAM_INT);
$sth->execute();
$this->setID(0);
$thumbnailfile = THUMBNAILFOLDER . $this->getAlbumFolder() . $this->getFileName();
if ( file_exists($thumbnailfile) ) unlink($thumbnailfile);
}
public function save() {
global $globaldbh;
$query = "INSERT INTO " . AppDB::TABLE_IMAGES . " ";
$query .= "(id, album_id, filename, title, description, createtime) ";
$query .= "VALUES(NULL, :album_id, :filename, :title, :description, NOW()) ";
$query .= "ON DUPLICATE KEY UPDATE ";
$query .= "album_id=:album_id, filename=:filename, title=:title, description=:description";
$sth = $globaldbh->prepare($query);
$sth->bindValue(":id", (int) $this->getID(), PDO::PARAM_INT);
$sth->bindValue(":album_id", (int) $this->getAlbumID(), PDO::PARAM_INT);
$sth->bindValue(":filename", $this->getFileName(), PDO::PARAM_STR);
$sth->bindValue(":title", $this->getTitle(), PDO::PARAM_STR);
$sth->bindValue(":description", $this->getDescription(), PDO::PARAM_STR);
$sth->execute();
//print_r($this);
//print_r($sth->errorInfo());
if ( $this->getID() == 0 ) {
$this->setID($globaldbh->lastInsertId());
$this->createThumbnail();
}
}
function __construct($reqid = 0) {
global $globaldbh;
$reqid = intval($reqid);
$query = "SELECT i.id, i.album_id, i.filename, i.title, i.description, i.createtime, a.foldername ";
$query .= "FROM " . AppDB::TABLE_IMAGES . " AS i LEFT JOIN " . AppDB::TABLE_ALBUMS . " as a ON i.album_id=a.id WHERE i.id=:id";
$sth = $globaldbh->prepare($query);
$sth->bindValue(":id", $reqid, PDO::PARAM_INT);
$sth->execute();
if ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) {
$this->setID($row['id']);
$this->setAlbumID($row['album_id']);
$this->setFileName($row['filename']);
$this->setAlbumFolder($row['foldername']);
$this->setTitle($row['title']);
$this->setDescription($row['description']);
$this->createtime = $row['createtime'];
}
}
}
// vim: set ts=4:sw=4

146
class_link.php Normal file
View File

@ -0,0 +1,146 @@
<?php
class Link implements JsonSerializable {
private $id = 0;
private $label = "";
private $url = "";
private $createtime = "";
public function getID() {
return intval($this->id);
}
public function getLabel($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->label);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->label, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->label);
break;
default:
return $this->label;
break;
}
}
public function getURL($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->url);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->url, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->url);
break;
default:
return $this->url;
break;
}
}
public function getCreateTime($flag = 0) {
switch ($flag) {
case TIMESTAMP:
return strtotime($this->createtime);
break;
case PRETTY:
return date("F j Y H:i:s", strtotime($this->createtime));
break;
default:
return $this->createtime;
break;
}
}
public function setID($id = null) {
if (is_null($id)) return false;
$id = abs(intval($id));
if ($id == 0) return false;
$this->id = $id;
return true;
}
public function setFolderName($foldername = null) {
if (is_null($foldername) || ($foldername == "")) return false;
settype($foldername, "string");
$this->foldername = $foldername;
return true;
}
public function setLabel($label = null) {
if (is_null($label) || ($label == "")) return false;
settype($label, "string");
$this->label = $label;
return true;
}
public function setURL($url = null) {
if (is_null($url) || ($url == "")) return false;
settype($url, "string");
$this->url = $url;
return true;
}
public static function getLinks() {
global $globaldbh;
$query = "SELECT id FROM " . AppDB::TABLE_LINKS . " ORDER BY id";
$sth = $globaldbh->prepare($query);
$sth->execute();
$thelist = array();
while ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) {
$thelist[] = new Link($row['id']);
}
return $thelist;
}
public function jsonSerialize() {
return [
'id' => $this->getID(),
'label' => $this->getLabel(),
'url' => $this->getURL(),
'createtime' => $this->getCreateTime()
];
}
public function save() {
global $globaldbh;
$query = "INSERT INTO " . AppDB::TABLE_LINKS . " ";
$query .= "(id, label, url, createtime) ";
$query .= "VALUES(:id, :label, :url, NOW()) ";
$query .= "ON DUPLICATE KEY UPDATE ";
$query .= "label=:label, url=:url";
$sth = $globaldbh->prepare($query);
$sth->bindValue(":id", (int) $this->getID(), PDO::PARAM_INT);
$sth->bindValue(":label", $this->getLabel(), PDO::PARAM_STR);
$sth->bindValue(":url", $this->getURL(), PDO::PARAM_STR);
$sth->execute();
if ( $this->getID() == 0 ) $this->setID($globaldbh->lastInsertId());
}
function __construct($reqid = 0) {
global $globaldbh;
$reqid = intval($reqid);
$query = "SELECT id, label, url, createtime " .
"FROM " . AppDB::TABLE_LINKS . " WHERE id=:id";
$sth = $globaldbh->prepare($query);
$sth->bindValue(":id", $reqid, PDO::PARAM_INT);
$sth->execute();
if ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) {
$this->setID($row['id']);
$this->setLabel($row['label']);
$this->setURL($row['url']);
$this->createtime = $row['createtime'];
}
}
}
// vim: set ts=4:sw=4

425
class_user.php Normal file
View File

@ -0,0 +1,425 @@
<?php
class User {
private $id = 0;
private $username = "";
private $password = "";
private $firstname = "";
private $lastname = "";
// createtime will be stored in the class using the native SQL datetime format
private $createtime = "";
// lastlogin will be stored in the class using the native SQL datetime format
private $lastlogin = "";
// lastbadlogin will be stored in the class using the native SQL datetime format
private $lastbadlogin = "";
private $badlogincount = 0;
// lastupdate will be stored in the class using the native SQL datetime format
private $lastupdate = "";
const COOKIENAME = SESSNAME . "_rememberme";
const ROLE_ADMIN = "admin";
const ROLE_USER = "user";
const ROLE_GUEST = "guest";
const ROLE_VALIDROLES = array(User::ROLE_GUEST, User::ROLE_ADMIN, User::ROLE_USER);
const GUEST = 1000601;
const USER = 1000602;
const ADMIN = 1000603;
const LOGININVALID = 1000604;
const LOGINLOCKED = 1000605;
public function getID() {
return intval($this->id);
}
public function getUsername($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->lastname);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->lastname, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->lastname);
break;
default:
return $this->username;
break;
}
}
public function getFirstName($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->firstname);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->firstname, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->firstname);
break;
default:
return $this->firstname;
break;
}
}
public function getLastName($flag = 0) {
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($this->lastname);
break;
case HTMLFORMSAFE:
return htmlspecialchars($this->lastname, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $this->lastname);
break;
default:
return $this->lastname;
break;
}
}
public function getFullName($flag = 0) {
$fullname = $this->firstname . " " . $this->lastname;
switch ($flag) {
case HTMLSAFE:
return htmlspecialchars($fullname);
break;
case HTMLFORMSAFE:
return htmlspecialchars($fullname, ENT_QUOTES);
break;
case CSVSAFE:
return str_replace('"', '""', $fullname);
break;
default:
return $fullname;
break;
}
}
public function getCreateTime($flag = 0) {
switch ($flag) {
case TIMESTAMP:
return strtotime($this->createtime);
break;
case PRETTY:
return date("F j Y H:i:s", strtotime($this->createtime));
break;
default:
return $this->createtime;
break;
}
}
public function getLastLogin($flag = 0) {
switch ($flag) {
case TIMESTAMP:
return strtotime($this->lastlogin);
break;
case PRETTY:
return (($this->lastlogin == "0000-00-00 00:00:00") || ($this->lastlogin == "")) ? "Never" : date("F j Y H:i:s", strtotime($this->lastlogin));
break;
default:
return $this->lastlogin;
break;
}
}
public function getLastBadLogin($flag = 0) {
switch ($flag) {
case TIMESTAMP:
return strtotime($this->lastbadlogin);
break;
case PRETTY:
return (($this->lastbadlogin == "0000-00-00 00:00:00") || ($this->lastbadlogin == "")) ? "Never" : date("F j Y H:i:s", strtotime($this->lastbadlogin));
break;
default:
return $this->lastbadlogin;
break;
}
}
public function getBadLoginCount() {
return intval($this->badlogincount);
}
public function getLastUpdate($flag = 0) {
switch ($flag) {
case TIMESTAMP:
return strtotime($this->lastupdate);
break;
case PRETTY:
return date("F j Y H:i:s", strtotime($this->lastupdate));
break;
default:
return $this->lastupdate;
break;
}
}
public function setID($id = null) {
if (is_null($id)) return false;
$id = abs(intval($id));
if ($id == 0) return false;
$this->id = $id;
return true;
}
public function setUsername($username = null) {
if (is_null($username) || ($username == "")) return false;
settype($username, "string");
$this->username = $username;
return true;
}
public function setPassword($password = null) {
if (is_null($password)) return false;
$this->password = password_hash($password, PASSWORD_DEFAULT);
return true;
}
public function setPasswordHash($hash = null) {
if (is_null($hash)) return false;
$this->password = $hash;
return true;
}
public function setFirstName($firstname = null) {
if (is_null($firstname) || ($firstname == "")) return false;
settype($firstname, "string");
$this->firstname = $firstname;
return true;
}
public function setLastName($lastname = null) {
if (is_null($lastname) || ($lastname == "")) return false;
settype($lastname, "string");
$this->lastname = $lastname;
return true;
}
public function setBadLoginCount($count = null) {
if (is_null($count)) return false;
$this->badlogincount = intval($count);
}
public function saveLastLogin() {
global $globaldbh;
$query = "UPDATE " . AppDB::TABLE_USERS . " SET lastlogin=:lastlogin WHERE id=:id";
$fields = array();
$fields[':id'] = $this->getID();
$fields[':lastlogin'] = (new DateTime("now", new DateTimeZone("UTC")))->format('Y-m-d H:i:s');
$sth = $globaldbh->prepare($query);
$sth->execute($fields);
}
public static function getUserByUsername($username = null) {
global $globaldbh;
if (is_null($username)) return false;
$query = "SELECT id FROM " . AppDB::TABLE_USERS . " WHERE username=:username";
$fields = array();
$fields[':username'] = $username;
$sth = $globaldbh->prepare($query);
$sth->execute($fields);
if ($row = $sth->fetch()) {
return new User($row['id']);
} else {
return false;
}
}
public function setCookie() {
global $globaldbh;
$query = "DELETE FROM " . AppDB::TABLE_COOKIES . " WHERE user_id=:user_id AND ipaddress=:ipaddress";
$fields = array();
$fields[':user_id'] = $this->getID();
$fields[':ipaddress'] = $_SERVER['REMOTE_ADDR'];
$sth = $globaldbh->prepare($query);
$sth->execute($fields);
$hash = uniqid("", true) . uniqid("", true);
$query = "INSERT INTO " . AppDB::TABLE_COOKIES . " ";
if (DBTYPE == 'mysql') {
$query .= "VALUES(:hash, :user_id, :ipaddress, UTC_TIMESTAMP() + INTERVAL 30 DAY)";
} elseif (DBTYPE == 'sqlite') {
$query .= "VALUES(:hash, :user_id, :ipaddress, DATETIME('NOW','+30 DAY'))";
}
$fields[':hash'] = $hash;
$sth = $globaldbh->prepare($query);
$sth->execute($fields);
setcookie(User::COOKIENAME, $hash, array('expires' => time() + (60 * 60 * 24 * 30), 'path' => "/", 'domain' => $_SERVER['SERVER_NAME'], 'samesite' => 'Lax'));
}
public function saveLastUpdate() {
global $globaldbh;
$query = "UPDATE " . AppDB::TABLE_USERS . " ";
if (DBTYPE == 'mysql') {
$query .= "SET lastupdate=UTC_TIMESTAMP() WHERE id=:id";
} elseif (DBTYPE == 'sqlite') {
$query .= "SET lastupdate=DATETIME('NOW') WHERE id=:id";
}
$fields = array(':id' => $this->getID());
$sth = $globaldbh->prepare($query);
$sth->execute($fields);
}
public function incrementBadLogins() {
global $globaldbh;
$this->badlogincount++;
$query = "UPDATE " . AppDB::TABLE_USERS . " ";
if (DBTYPE == 'mysql') {
$query .= "SET badlogincount=:badlogincount, lastbadlogin=UTC_TIMESTAMP() WHERE id=:id";
} elseif (DBTYPE == 'sqlite') {
$query .= "SET badlogincount=:badlogincount, lastbadlogin=DATETIME('NOW') WHERE id=:id";
}
$fields = array();
$fields[':id'] = $this->getID();
$fields[':badlogincount'] = $this->getBadLoginCount();
$sth = $globaldbh->prepare($query);
$sth->execute($fields);
}
public static function getUserFromLogin($username = null, $password = null) {
global $globaldbh;
$user = User::getUserByUsername($username);
if ($user === false) {
return User::LOGININVALID;
}
if (($user->getBadLoginCount() >= MAXBADLOGINS) && ((strtotime($user->getLastBadLogin()) + (BADLOGINEXPIRATION * 60)) > time())) {
return User::LOGINLOCKED;
}
$query = "SELECT id, password FROM " . AppDB::TABLE_USERS . " WHERE username=:username";
$fields = array(':username' => $username);
$sth = $globaldbh->prepare($query);
$sth->execute($fields);
if ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
if (password_verify($password, $row['password'])) {
$user = new User($row['id']);
$user->setBadLoginCount(0);
$saved = $user->save();
return $user;
}
}
$user->incrementBadLogins();
return User::LOGININVALID;
}
public static function validateUserCookie($hash = null) {
global $globaldbh;
$query = "SELECT user_id FROM " . AppDB::TABLE_COOKIES . " WHERE hash=:hash AND ipaddress=:ipaddress ";
if (DBTYPE == 'mysql') {
$query .= "AND expiration >= UTC_TIMESTAMP()";
} elseif (DBTYPE == 'sqlite') {
$query .= "AND DATETIME(expiration) >= DATETIME('NOW')";
}
$fields = array();
$fields[':hash'] = $hash;
$fields[':ipaddress'] = $_SERVER['REMOTE_ADDR'];
$sth = $globaldbh->prepare($query);
$sth->execute($fields);
if ($row = $sth->fetch()) {
$user = new User($row['user_id']);
return $user->getID();
} else {
return 0;
}
}
public function removeCookie() {
global $globaldbh;
if (!isset($_COOKIE[User::COOKIENAME])) return;
setcookie(User::COOKIENAME, "", time() - 3600, "/", $_SERVER['SERVER_NAME']);
$query = "DELETE FROM " . AppDB::TABLE_COOKIES . " WHERE user_id=:user_id AND ipaddress=:ipaddress";
$fields = array();
$fields[':user_id'] = $this->getID();
$fields[':ipaddress'] = $_SERVER['REMOTE_ADDR'];
$sth = $globaldbh->prepare($query);
$sth->execute($fields);
}
public static function getList($search = null) {
global $globaldbh;
$fields = array();
if (is_null($search)) {
$query = "SELECT id FROM " . AppDB::TABLE_USERS . " ORDER BY firstname, lastname";
} else {
$query = "SELECT id FROM " . AppDB::TABLE_USERS . " WHERE (firstname LIKE :search) OR (lastname LIKE :search) OR (username LIKE :search) ORDER BY firstname, lastname";
$fields[':search'] = "%" . $search . "%";
}
$sth = $globaldbh->prepare($query);
$thelist = array();
if ($sth->execute($fields)) {
while ($row = $sth->fetch()) {
$thelist[] = new User($row['id']);
}
}
return $thelist;
}
public function isLoggedIn() {
if ( $this->getID() != 0 ) { return true; } else { return false; }
}
public function save() {
global $globaldbh;
if ($this->getFirstName() == "") return false;
if ($this->getLastName() == "") return false;
$fields = array();
if ($this->getID() == 0) {
$query = "INSERT INTO " . AppDB::TABLE_USERS . " ";
$query .= "(username, password, firstname, lastname, createtime, lastupdate) ";
$query .= "VALUES(:username, :password, :firstname, :lastname, :createtime, :lastupdate)";
$fields[':password'] = $this->password; // There is no "getter" for password since it should never read outside the class
$fields[':createtime'] = (new DateTime("now", new DateTimeZone("UTC")))->format('Y-m-d H:i:s');
} else {
$query = "UPDATE " . AppDB::TABLE_USERS . " SET username=:username, ";
if ($this->password != "") {
$query .= "password=:password, ";
$fields[':password'] = $this->password; // There is no "getter" for password since it should never read outside the class
}
$query .= "firstname=:firstname, lastname=:lastname, ";
$query .= "lastupdate=:lastupdate, badlogincount=:badlogincount WHERE id=:id";
$fields[':id'] = $this->getID();
$fields[':badlogincount'] = $this->getBadLoginCount();
}
$fields[':username'] = $this->getUsername();
$fields[':firstname'] = $this->getFirstName();
$fields[':lastname'] = $this->getLastName();
$fields[':lastupdate'] = (new DateTime("now", new DateTimeZone("UTC")))->format('Y-m-d H:i:s');
$sth = $globaldbh->prepare($query);
$saved = $sth->execute($fields);
return $saved;
}
function __construct($reqid = 0) {
global $globaldbh;
$reqid = intval($reqid);
$query = "SELECT id, username, firstname, lastname, createtime, lastlogin, " .
"lastbadlogin, badlogincount, lastupdate FROM " . AppDB::TABLE_USERS . " WHERE id=:id";
$fields = array();
$fields[':id'] = $reqid;
$sth = $globaldbh->prepare($query);
if ($sth->execute($fields)) {
if ($row = $sth->fetch()) {
$this->setID($row['id']);
$this->setUsername($row['username']);
$this->setFirstName($row['firstname']);
$this->setLastName($row['lastname']);
$this->createtime = $row['createtime'];
$this->lastlogin = $row['lastlogin'];
$this->lastbadlogin = $row['lastbadlogin'];
$this->setBadLoginCount($row['badlogincount']);
$this->lastupdate = $row['lastupdate'];
}
}
}
}
// vim: set ts=3:sw=3

37
config-dist.php Normal file
View File

@ -0,0 +1,37 @@
<?php
// Session Information
//
define('SESSNAME', 'modelalbums'); // Commonly customized to reference production or development. Must be only letters and numbers!
define('PAGETITLE', 'BWW Model Albums'); // This is the large lebel in the header of each page
// General Configuration
//
define('MAXBADLOGINS', 3); // The number of bad logins before the account is locked
define('BADLOGINEXPIRATION', 10); // The number of minutes the account will remain locked after MAXBADLOGINS
// Domain Information - Used in emails sent to users
//
define('ROOTURL', 'https://www.yoursite.com/');
// Full folder path where uploaded images will reside.!
// This MUST be in the same folder as the app, and MUST have a trailing slash!!!
//
define('ALBUMFOLDER', '/var/www/html/albums/');
// Full folder path where thumbnail images will reside. Must be writable by web server!
// This MUST be in the same folder as the app, and MUST have a trailing slash!!!
//
define('THUMBNAILFOLDER', '/var/www/html/thumbs/');
// Database Type: Valid values are 'mysql' and 'sqlite'
//
define('DBTYPE', 'mysql');
// MySQL Database Configuration. Ignore if not using MySQL
//
define('DBHOST', 'localhost');
define('DBUSER', 'user');
define('DBPASS', 'pass');
define('DBNAME', 'modelalbums');

15
constants.php Normal file
View File

@ -0,0 +1,15 @@
<?php
define("HTMLSAFE", 1000001);
define("HTMLFORMSAFE", 1000002);
define("CSVSAFE", 1000003);
define("URLSAFE", 1000004);
define("TIMESTAMP", 1000101);
define("PRETTY", 1000102);
define("SHORTDATE", 1000103);
define("BOOLEANDB", 1000201);
define("NOLIMIT", 0);
define("NOFLAG", 0);

13
contact.php Executable file
View File

@ -0,0 +1,13 @@
<?php
require "header.php";
includeHTMLHeader();
?>
<!-- insert the page content here -->
<h1>Scale Models</h1>
<p> This is where the page providing contact info goes.</p>
<?php
includeHTMLFooter();

2
core/jquery-3.6.0.min.js vendored Normal file

File diff suppressed because one or more lines are too long

1
core/moment.min.js vendored Normal file

File diff suppressed because one or more lines are too long

1
core/toastr.min.css vendored Normal file

File diff suppressed because one or more lines are too long

2
core/toastr.min.js vendored Normal file

File diff suppressed because one or more lines are too long

62
functions.php Normal file
View File

@ -0,0 +1,62 @@
<?php
function requireLogin() {
global $currentuser;
if ( $_SESSION['userid'] != 0 ) {
return true;
} else {
header('Location: index.php');
exit();
}
return;
}
//
// This function outputs the HTML header along with adding a string
// of text to the page title.
//
function includeHTMLHeader($headertext = "", ...$sheets) {
global $currentuser;
if ($headertext != "") $fullpagetitle = htmlspecialchars($headertext);
$extrasheets = " <!-- Extra CSS included by the current page -->\n";
foreach ( $sheets as $sheet ) {
$extrasheets .= " <link type='text/css' rel='stylesheet' href='css/{$sheet}'/>\n";
}
require 'htmlheader.php';
}
//
// This function outputs the HTML footer along with adding script tags
// for any script files passed to the function. These files are assumed
// to be in the js/ folder.
//
function includeHTMLFooter(...$scripts) {
require 'htmlfooter.php';
foreach ( $scripts as $script ) {
echo "\n <script type='text/javascript' src='js/", trim($script), "'></script>\n";
}
echo " </body>\n";
echo "</html>\n";
}
//
// This function will redirect to the home page if the current session
// has a validated user (i.e. userid != 0).
//
function require_anonymous() {
if ( $_SESSION['userid'] != 0 ) {
header('Location: index.php');
exit();
}
}
//
// A simple function to redirect a page while still in the header
//
function redirectPage($page = null) {
if ( is_null($page) ) $page = "index.php";
header("Location: {$page}");
exit();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
graphics/oldman.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

BIN
graphics/oldman.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
graphics/oldman_head.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

23
header.php Normal file
View File

@ -0,0 +1,23 @@
<?php
require "constants.php";
require "config.php";
require "functions.php";
require "class_appdb.php";
require "class_user.php";
require "class_album.php";
require "class_image.php";
require "class_link.php";
$globaldbh = AppDB::getDBH();
if ( !is_object($globaldbh) || !(get_class($globaldbh) == "PDO") ) {
header('Location: error_db.php?establish=');
exit();
}
if ( php_sapi_name() != "cli" ) {
require 'startsession.php';
}
$currentuser = new User($_SESSION['userid']);

15
htmlfooter.php Executable file
View File

@ -0,0 +1,15 @@
</div>
</div>
<div id="content_footer"></div>
<div id="footer">
Copyright &copy; Big Woods World |
</div>
</div>
<!-- Include jQuery before anything else -->
<script type="text/javascript" src="core/jquery-3.6.0.min.js"></script>
<!-- Toastr library -->
<script type="text/javascript" src="core/toastr.min.js"></script>
<!-- Include time library "moment" -->
<script type="text/javascript" src="core/moment.min.js"></script>
<!-- Script for menu highlighting -->
<script type="text/javascript" src="js/menu.js"></script>

38
htmlheader.php Executable file
View File

@ -0,0 +1,38 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Big Wood's World</title>
<meta name="description" content="Big Wood's World" />
<meta name="keywords" content="The ramblings of an old man." />
<meta http-equiv="content-type" content="text/html; charset=windows-1252" />
<!-- Toastr CSS -->
<link rel="stylesheet" type="text/css" href="core/toastr.min.css" />
<link rel="stylesheet" type="text/css" href="style/style.css" title="style" />
<link rel="shortcut icon" href="graphics/oldman_head.gif">
</head>
<body>
<div id="main">
<div id="header">
<div id="logo">
<div id="logo_text">
<!-- class="logo_colour", allows you to change the colour of the text -->
<h1><a href="index.php"><span class="logo_colour">Big Wood's World</span></a></h1>
<h2>The mind of an old man.</h2>
</div>
</div>
<div id="menubar">
<?php include_once "menu.php"; ?>
</div>
</div>
<div id="content_header"></div>
<div id="site_content">
<div class="sidebar">
<!-- insert your sidebar items here -->
<h3>Latest News</h3>
<?php include_once "news.php"; ?>
<h3>Useful Links</h3>
<?php include_once "links.php"; ?>
</div>
<div id="content">

18
index.php Executable file
View File

@ -0,0 +1,18 @@
<?php
require "header.php";
includeHTMLHeader();
?>
<!-- insert the page content here -->
<h1>Big Woods World</h1>
<p>This site is about me and my journey through life. Its part blog, part diary. Part hay look what I can do, and part grumpy old man.</p>
<p>Having a site like this has nothing to do with narcissistic tendencies but rather its rather therapeutic to have an outlet for the emotions running through my brain. My goal in this project has two parts. First is to have a place to pour out the craziness that lives in my head so it does not build up. Secondly to entertain and maybe elicit a laugh from the rare visitor that stumbles on these pages.</p>
<div style="width: 100%;">
<center><img src="graphics/oldman.gif" alt="Old Man" style="width:300px; margin-left: auto; margin-right: auto"></center>
</div>
<?php
includeHTMLFooter();

1
install/.htaccess Normal file
View File

@ -0,0 +1 @@
Require all denied

174
install/initial_db.sql Normal file
View File

@ -0,0 +1,174 @@
-- MySQL dump 10.14 Distrib 5.5.54-MariaDB, for Linux (x86_64)
--
-- Host: localhost Database: localhost
-- ------------------------------------------------------
-- Server version 5.5.54-MariaDB
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `cookies`
--
DROP TABLE IF EXISTS `cookies`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `cookies` (
`hash` varchar(255) NOT NULL,
`user_id` int(11) unsigned NOT NULL,
`ipaddress` varchar(255) NOT NULL,
`expiration` datetime NOT NULL,
PRIMARY KEY (`hash`),
KEY `cookies_ibfk_1` (`user_id`),
CONSTRAINT `cookies_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `cookies`
--
LOCK TABLES `cookies` WRITE;
/*!40000 ALTER TABLE `cookies` DISABLE KEYS */;
/*!40000 ALTER TABLE `cookies` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `settings`
--
DROP TABLE IF EXISTS `settings`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `settings` (
`version` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `settings`
--
LOCK TABLES `settings` WRITE;
/*!40000 ALTER TABLE `settings` DISABLE KEYS */;
INSERT INTO `settings` VALUES ('A000001');
/*!40000 ALTER TABLE `settings` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `links`
--
DROP TABLE IF EXISTS `links`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `links` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`label` varchar(255) NOT NULL,
`url` text NOT NULL,
`createtime` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `links_ibfk_1` (`label`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
LOCK TABLES `links` WRITE;
/*!40000 ALTER TABLE `links` DISABLE KEYS */;
INSERT INTO `links` VALUES (NULL, 'Slashdot', 'https://slashdot.org/', NOW());
INSERT INTO `links` VALUES (NULL, 'Reddit', 'https://www.reddit.com/', NOW());
INSERT INTO `links` VALUES (NULL, 'Evernote', 'https://www.evernote.com/', NOW());
INSERT INTO `links` VALUES (NULL, 'Suicide Hot Line', 'https://suicidepreventionlifeline.org/', NOW());
/*!40000 ALTER TABLE `links` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `albums`
--
DROP TABLE IF EXISTS `albums`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `albums` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`foldername` varchar(255) NOT NULL,
`title` varchar(255) NOT NULL,
`thumbnail` varchar(255) NOT NULL DEFAULT "",
`description` text NOT NULL,
`createtime` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `al_foldername` (`foldername`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `images`
--
DROP TABLE IF EXISTS `images`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `images` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`album_id` int(11) unsigned NOT NULL,
`filename` varchar(255) NOT NULL,
`title` varchar(255) NOT NULL,
`description` text NOT NULL,
`createtime` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `images_ibfk_1` (`album_id`),
CONSTRAINT `images_ibfk_1` FOREIGN KEY (`album_id`) REFERENCES `albums` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `users`
--
DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`firstname` varchar(255) NOT NULL,
`lastname` varchar(255) NOT NULL,
`createtime` datetime NOT NULL,
`lastlogin` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastbadlogin` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`badlogincount` int(10) unsigned NOT NULL DEFAULT '0',
`lastupdate` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `users`
--
LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` VALUES (1,'admin','$2y$10$5rQiLCLRn6lYB1hLTHrEY..AXXfY31YjjMDeX4XElATH8GMsP.pKy','Admin','User',NOW(),NOW(),'0000-00-00 00:00:00',0,NOW());
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2018-07-26 16:26:40

247
install/m_initial_db.sql Normal file
View File

@ -0,0 +1,247 @@
-- MySQL dump 10.14 Distrib 5.5.54-MariaDB, for Linux (x86_64)
--
-- Host: localhost Database: localhost
-- ------------------------------------------------------
-- Server version 5.5.54-MariaDB
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `cookies`
--
DROP TABLE IF EXISTS `cookies`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `cookies` (
`hash` varchar(255) NOT NULL,
`user_id` int(11) unsigned NOT NULL,
`ipaddress` varchar(255) NOT NULL,
`expiration` datetime NOT NULL,
PRIMARY KEY (`hash`),
KEY `cookies_ibfk_1` (`user_id`),
CONSTRAINT `cookies_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `cookies`
--
LOCK TABLES `cookies` WRITE;
/*!40000 ALTER TABLE `cookies` DISABLE KEYS */;
/*!40000 ALTER TABLE `cookies` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `emailchanges`
--
DROP TABLE IF EXISTS `emailchanges`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `emailchanges` (
`user_id` int(11) unsigned NOT NULL,
`old_email` varchar(255) NOT NULL,
`new_email` varchar(255) NOT NULL,
`changetime` datetime NOT NULL,
KEY `emailchanges_ibfk_1` (`user_id`),
CONSTRAINT `emailchanges_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `emailchanges`
--
LOCK TABLES `emailchanges` WRITE;
/*!40000 ALTER TABLE `emailchanges` DISABLE KEYS */;
/*!40000 ALTER TABLE `emailchanges` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `passwordresets`
--
DROP TABLE IF EXISTS `passwordresets`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `passwordresets` (
`user_id` int(11) unsigned NOT NULL,
`hash` varchar(255) NOT NULL,
`expiration` datetime NOT NULL,
PRIMARY KEY (`user_id`),
CONSTRAINT `passwordresets_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `passwordresets`
--
LOCK TABLES `passwordresets` WRITE;
/*!40000 ALTER TABLE `passwordresets` DISABLE KEYS */;
/*!40000 ALTER TABLE `passwordresets` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `settings`
--
DROP TABLE IF EXISTS `settings`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `settings` (
`version` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `settings`
--
LOCK TABLES `settings` WRITE;
/*!40000 ALTER TABLE `settings` DISABLE KEYS */;
INSERT INTO `settings` VALUES ('A000001');
/*!40000 ALTER TABLE `settings` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `emailchanges`
--
DROP TABLE IF EXISTS `emailchanges`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `emailchanges` (
`user_id` int(11) unsigned NOT NULL,
`old_email` varchar(255) NOT NULL,
`new_email` varchar(255) NOT NULL,
`changetime` datetime NOT NULL,
KEY `emailchanges_ibfk_1` (`user_id`),
CONSTRAINT `emailchanges_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `models`
--
DROP TABLE IF EXISTS `models`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `models` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`owner_id` int(11) unsigned NOT NULL,
`scale` varchar(255) NOT NULL,
`type` varchar(255) NOT NULL,
`complete` enum('false','true') NOT NULL DEFAULT 'true',
`opened` enum('false','true') NOT NULL DEFAULT 'false',
`available` enum('false','true') NOT NULL DEFAULT 'true',
`disabled` enum('false','true') NOT NULL DEFAULT 'false',
`description` text NOT NULL,
`createtime` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `models_ibfk_1` (`owner_id`),
CONSTRAINT `models_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `contacts`
--
DROP TABLE IF EXISTS `contacts`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `contacts` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`subject` varchar(255) NOT NULL,
`message` varchar(255) NOT NULL,
`answered` enum('false','true') NOT NULL DEFAULT 'false',
`response` varchar(255) NOT NULL,
`createtime` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `images`
--
DROP TABLE IF EXISTS `images`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `images` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`model_id` int(11) unsigned NOT NULL,
`filepath` varchar(255) NOT NULL,
`filename` varchar(255) NOT NULL,
`createtime` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `images_ibfk_1` (`model_id`),
CONSTRAINT `images_ibfk_1` FOREIGN KEY (`model_id`) REFERENCES `models` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `users`
--
DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`firstname` varchar(255) NOT NULL,
`lastname` varchar(255) NOT NULL,
`nickname` varchar(255) NOT NULL,
`country` varchar(255) NOT NULL,
`state` varchar(255) NOT NULL DEFAULT '',
`admin` enum('false','true') NOT NULL DEFAULT 'false',
`disabled` enum('false','true') NOT NULL default 'false',
`disabledreason` text NOT NULL,
`createtime` datetime NOT NULL,
`lastlogin` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastbadlogin` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`badlogincount` int(10) unsigned NOT NULL DEFAULT '0',
`lastupdate` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `nickname` (`nickname`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `users`
--
LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` VALUES (1,'admin@admin.lan','$2y$10$5rQiLCLRn6lYB1hLTHrEY..AXXfY31YjjMDeX4XElATH8GMsP.pKy','Admin','User','SiteAdmin','United States','Ohio','true','false','','2018-07-19 12:06:50','2018-07-26 16:10:49','0000-00-00 00:00:00',0,'2018-07-26 16:10:49');
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2018-07-26 16:26:40

30
install/setpassword.php Normal file
View File

@ -0,0 +1,30 @@
<?php
$username = $_SERVER['argv'][1];
require "../constants.php";
require "../config.php";
require "../class_appdb.php";
require "../class_user.php";
$globaldbh = AppDB::getDBH();
if ( !is_object($globaldbh) || !(get_class($globaldbh) == "PDO") ) {
header('Location: error_db.php?establish=');
exit();
}
$user = User::getUserByUsername($username);
$p1 = readline("Enter a new password: ");
$p2 = readline("Confirm new password: ");
if ( $p1 != $p2 ) {
echo "Error: Passwords do not match!!\n\n";
exit();
}
$user->setPassword($p1);
$user->save();
echo "Password changed.\n\n";
exit();
// vim: set ts=3:sw=3

36
js/login.js Normal file
View File

@ -0,0 +1,36 @@
$(document).ready(function() {
$('#btn_loginsubmit').click(function() {
validateLoginForm();
});
$("#username, #password").keyup(function(e) {
if (e.keyCode == 13) {
validateLoginForm();
}
});
});
function validateLoginForm() {
$.ajax({
type: 'POST',
url: 'ajax/validatelogin.php',
data: {
username: $('#username').val(),
password: $('#password').val(),
remember: ($('#remember').prop('checked') ? "1" : "0")
},
dataType: 'json',
success: function(data, stat, jqo) {
if (data.status == "valid") {
window.location.replace('index.php');
} else {
toastr.error("Invalid username or password", "Account Error");
$('#username').focus();
}
},
error: function(jqo, status, error) {
toastr.error("Server error validating credentials!\n" + error, "Server Error");
//console.log(error);
}
});
}

3
js/menu.js Normal file
View File

@ -0,0 +1,3 @@
var page = window.location.pathname.split("/").pop().slice(0, -4);
page = (page == "") ? "index" : page;
$("#menu_"+page).addClass("selected");

74
js/scalemodels.js Normal file
View File

@ -0,0 +1,74 @@
$(document).ready(function() {
$("#btn_refresh").click(function() { refreshAlbums() });
$("#btn_album_0").click(function() { showAlbum($(this)) });
getAlbumInfo();
});
function refreshAlbums() {
toastr.info("Starting refresh of albums.\nThis may take a while if\nthere are many new images.", "Starting Refresh");
$.ajax({
type: 'GET',
url: 'ajax/refreshalbums.php',
dataType: 'json',
success: function(data, stat, jqo) {
toastr.success("Album list refreshed", "Refresh");
},
error: function(jqp, status, error) {
toastr.error("Error refreshing album list!\n" + error, "Server Error");
}
});
}
function getAlbumInfo() {
$.ajax({
type: 'GET',
url: 'ajax/getalbuminfo.php',
dataType: 'json',
success: function(data, stat, jqo) {
if ( data.currentalbum == 0 ) {
$("#albumdetails").addClass("hidden");
} else {
$("#albumdetails").removeClass("hidden");
}
$("#albumtitle").html(data.albumtitle);
$("#albumdescription").html(data.albumdescription);
$("#albumcontents").html(data.albumcontents);
$(".albumthumbnail").click(function() {
if ( data.currentalbum == 0 ) {
showAlbum($(this));
} else {
showImage($(this));
}
});
},
error: function(jqp, status, error) {
toastr.error("Error retrieving album info!\n" + error, "Server Error");
}
});
}
function showImage(clickedElement) {
var imageid = clickedElement.attr("id").substring(clickedElement.attr("id").lastIndexOf("_") + 1);
console.log(imageid);
}
function showAlbum(clickedElement) {
var albumid = clickedElement.attr("id").substring(clickedElement.attr("id").lastIndexOf("_") + 1);
$.ajax({
type: 'GET',
url: 'ajax/setcurrentalbum.php',
dataType: 'json',
data: {
albumid: albumid
},
success: function(data, stat, jqo) {
$("#albumcontents").html("");
getAlbumInfo();
},
error: function(jqp, status, error) {
toastr.error("Error setting current album!\n" + error, "Server Error");
}
});
}
// vim: ts=4:sw=4

10
links.php Normal file
View File

@ -0,0 +1,10 @@
<?php
$links = Link::getLinks();
?>
<ul>
<?php foreach ( $links as $link ) {
echo "<li><a href=\"", $link->getURL(HTMLFORMSAFE), "\">", $link->getLabel(HTMLSAFE), "</a></li>\n";
} ?>
</ul>

30
login.php Executable file
View File

@ -0,0 +1,30 @@
<?php
require "header.php";
includeHTMLHeader();
?>
<!-- insert the page content here -->
<h1>Log In</h1>
<div>
<label for="username"><b>Username</b></label>
<input type="username" placeholder="Enter Username" name="username" id="username" size="40" required>
</div>
<p />
<div>
<label for="password"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="password" id="password" size="40" required>
</div>
<p />
<div>
<label for="remember"><b>Remember Me:</b></label>
<input type="checkbox" name="remember" id="remember" required>
</div>
<p />
<p>
<button id="btn_loginsubmit" style="width: 40%;">Log In</button>
</p>
<?php
includeHTMLFooter("login.js");

9
logout.php Normal file
View File

@ -0,0 +1,9 @@
<?php
require 'header.php';
if ( $currentuser->getID() != 0 ) $currentuser->removeCookie();
session_destroy();
header('Location: index.php');
exit();

13
menu.php Normal file
View File

@ -0,0 +1,13 @@
<ul id="menu">
<!-- put class="selected" in the li tag for the selected page - to highlight which page you're on -->
<li id="menu_index"><a href="index.php">Home</a></li>
<li id="menu_scalemodels"><a href="scalemodels.php">Scale Model Building</a></li>
<li id="menu_movies"><a href="movies.php">Movies</a></li>
<li id="menu_observations"><a href="observations.php">Observations</a></li>
<?php
if ( $currentuser->getID() == 0 ) { ?>
<li id="menu_login"><a href="login.php">Log In</a></li>
<?php } else { ?>
<li id="menu_logout"><a href="logout.php">Log Out</a></li>
<?php } ?>
</ul>

13
movies.php Executable file
View File

@ -0,0 +1,13 @@
<?php
require "header.php";
includeHTMLHeader();
?>
<!-- insert the page content here -->
<h1>Scale Models</h1>
<p> This is where the page to talk about movies goes.</p>
<?php
includeHTMLFooter();

7
news.php Normal file
View File

@ -0,0 +1,7 @@
<h4>New Website Launched</h4>
<h5>July 30, 2018</h5>
<p>Take a look around and let me know what you think.<br /><a href="#">Read more</a></p>
<p></p>
<h4>Trying to not fade into obscurity</h4>
<h5>July 30. 2018</h5>
<p>Trying out my HTML skills which lets be honest are crap.<br /><a href="#">Read more</a></p>

13
observations.php Executable file
View File

@ -0,0 +1,13 @@
<?php
require "header.php";
includeHTMLHeader();
?>
<!-- insert the page content here -->
<h1>Scale Models</h1>
<p> This is where the page to talk about observations (and maybe rant a bit) goes.</p>
<?php
includeHTMLFooter();

42
scalemodels.php Executable file
View File

@ -0,0 +1,42 @@
<?php
require "header.php";
includeHTMLHeader();
$_SESSION['currentalbum'] = 0;
?>
<!-- insert the page content here -->
<h1><span id="btn_album_0" class="textlink">Scale Models</span>
<?php
if ( $currentuser->isLoggedIn() ) {
echo "<span class='textlink smallerlink' id='btn_refresh'>REFRESH</span>\n";
}
?>
</h1>
<div class="albumdetails hidden" id="albumdetails">
<h2>Album Title:</h2>
<div id="albumtitle"></div>
<h2>Album Description:</h2>
<div id="albumdescription"></div>
</div>
<div id="albumcontents">
<?php
/*
$albums = Album::getList();
foreach ( $albums as $album ) {
echo "<div class=\"thumbnail_grid\">";
echo "<img class=\"thumbnail_grid_image albumthumbnail\" id=\"album_{$album->getID()}\" src=\"{$album->getThumbnail(URLSAFE)}\" />";
echo "<div class=\"thumbnail_grid_title\">{$album->getTitle(HTMLSAFE)}</div>";
echo "</div>\n";
}
*/
?>
</div>
<?php
includeHTMLFooter("scalemodels.js");
// vim: set ts=3:sw=3

26
startsession.php Normal file
View File

@ -0,0 +1,26 @@
<?php
if ( php_sapi_name() == "cli" ) exit();
// Start the session
session_name(SESSNAME);
ini_set("session.cookie_samesite", "Lax");
session_start();
// The session variable for the current user
if ( !isset($_SESSION['userid']) ) $_SESSION['userid'] = 0;
// The sesion variable for the currently displayed album
if ( !isset($_SESSION['currentalbum']) ) $_SESSION['currentalbum'] = 0;
// Validate the user from a valid cookie if one exists
if ( isset($_COOKIE[User::COOKIENAME]) && ($_SESSION['userid'] == 0) ) {
$cid = User::validateUserCookie($_COOKIE[User::COOKIENAME]);
if ( $cid != 0 ) {
$user = new User($cid);
$_SESSION['userid'] = $cid;
redirectPage("index.php");
} else {
setcookie(User::COOKIENAME, "", array('expires' => time() - 3600, 'path' => "/", 'domain' => $_SERVER['SERVER_NAME'], 'samesite' => 'Lax'));
}
}

BIN
style/back.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

BIN
style/bg.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 641 KiB

BIN
style/bullet.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 977 B

BIN
style/content.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

BIN
style/graphic.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
style/link.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 515 B

BIN
style/logo.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
style/oldman.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
style/search.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 887 B

273
style/style.css Executable file
View File

@ -0,0 +1,273 @@
html
{ height: 100%;}
*
{ margin: 0;
padding: 0;}
body
{ font: normal .78em arial, sans-serif;
background: #444;
color: #555;}
p
{ padding: 0 0 16px 0;
line-height: 1.7em;}
img
{ border: 0;}
h1, h2, h3, h4, h5, h6
{ font: normal 175% 'century gothic', arial, sans-serif;
color: #111;
margin: 0 0 15px 0;
padding: 15px 0 5px 0;}
h2
{ font: normal 175% 'century gothic', arial, sans-serif;
color: #444;}
h4, h5, h6
{ margin: 0;
padding: 0 0 5px 0;
font: normal 120% arial, sans-serif;
color: #555;}
h5, h6
{ font: italic 95% arial, sans-serif;
padding: 0 0 15px 0;
color: #000;}
h6
{ color: #888;}
a, a:hover
{ outline: none;
color: #111;
text-decoration: underline;}
a:hover
{ text-decoration: none;}
ul
{ margin: 2px 0 22px 17px;}
ul li
{ list-style-type: circle;
margin: 0 0 6px 0;
padding: 0 0 4px 5px;}
ol
{ margin: 8px 0 22px 20px;}
ol li
{ margin: 0 0 11px 0;}
#main, #header, #logo, #menubar, #site_content, #footer, #center
{ margin-left: auto;
margin-right: auto;}
#main
{ width: 910px;
background: url(content.png) repeat-y;}
#header
{ width: 890px;
background: url(back.png) repeat-x;}
#logo
{ width: 890px;
position: relative;
height: 200px;
background: url(logo.jpg) no-repeat;}
#logo #logo_text
{ position: absolute;
top: 0px;
left: 30px;}
#logo h1, #logo h2
{ font: normal 300% 'century gothic', arial, sans-serif;
border-bottom: 0;
text-transform: none;
margin: 0;}
#logo_text h1, #logo_text h1 a, #logo_text h1 a:hover
{ padding: 10px 0 0 0;
color: #FFF;
letter-spacing: 0.1em;
text-decoration: none;}
#logo_text h1 a .logo_colour
{ color: #555;}
#logo_text h2
{ font-size: 130%;
padding: 0;
color: #444;}
#menubar
{ width: 890px;
height: 35px;
padding: 8px 0 0 0;
margin: -45px 0 0 0;
position: relative;
z-index: 1;
float: right;}
ul#menu
{ float: right;
margin: 0;}
ul#menu li
{ float: left;
margin: 5px 0 0 0;
padding: 0 0 0 6px;
list-style: none;}
ul#menu li a
{ letter-spacing: 0em;
font: normal 105% arial, sans-serif;
text-transform: uppercase;
display: block;
float: left;
height: 20px;
text-decoration: none;
padding: 9px 22px 5px 16px;
text-align: center;
color: #FFF;
border: 0;
}
ul#menu li.selected a {
height: 25px;
color: #111;
font-weight: bold;
padding: 7px 22px 5px 16px;
}
ul#menu li.selected {
margin: 7px 0 0 0;
background: #F8F8F8;
}
ul#menu li a:hover
{ color: #888;}
#site_content
{ width: 890px;
overflow: hidden;
background: #F8F8F8;}
.sidebar
{ float: right;
width: 198px;
padding: 20px 25px 15px 15px;}
.sidebar ul
{ width: 178px;
padding: 4px 0 0 0;
margin: 4px 0 30px 0;}
.sidebar li
{ list-style: none;
padding: 0 0 7px 0; }
.sidebar li a, .sidebar li a:hover
{ padding: 0 0 0 40px;
display: block;
background: transparent url(link.png) no-repeat left center;}
.sidebar li a.selected
{ color: #444;
text-decoration: none;}
#content
{ text-align: left;
width: 600px;
float: left;
padding: 20px 0 15px 30px;}
#content ul
{ margin: 2px 0 22px 0px;}
#content ul li
{ list-style-type: none;
background: url(bullet.png) no-repeat;
margin: 0 0 6px 0;
padding: 0 0 4px 25px;
line-height: 1.5em;}
#footer
{ width: 890px;
height: 33px;
padding: 20px 0 4px 0;
text-align: center;
background: #555;
color: #AAA;
border-top: 1px solid #FFF;
letter-spacing: 0.2em;
text-transform: uppercase;
font-size: 80%;}
#footer a
{ color: #FFF;
text-decoration: none;}
#footer a:hover
{ color: #FFF;
text-decoration: none;}
#colours
{ height: 0px;
text-align: right;
padding: 66px 16px 0px 300px;}
table
{ margin: 10px 0 30px 0;}
table tr th, table tr td
{ background: #333;
color: #FFF;
padding: 7px 4px;
text-align: left;}
table tr td
{ background: #eee;
color: #555;
border-top: 1px solid #FFF;}
#center {
margin-left: 250px;
}
.textlink {
cursor: pointer;
}
.smallerlink {
font-style: italic;
font-size: 60%;
}
.thumbnail_grid {
width: 290px;
height: 185px;
border: 1px solid black;
display: inline-block;
padding: 2px;
box-sizing: border-box;
margin-right: 3px;
margin-bottom: 3px;
}
.thumbnail_grid_image {
margin-left: auto;
margin-right: auto;
display: block;
cursor: pointer;
}
.thumbnail_grid_title {
text-align: center;
font-weight: bold;
}
.hidden {
display: none;
}

4
thumbs/index.php Normal file
View File

@ -0,0 +1,4 @@
<?php
header("Location: ../");
exit();