Compare commits
4 Commits
d56016f8cc
...
4948da4024
Author | SHA1 | Date | |
---|---|---|---|
4948da4024 | |||
ed038beb4e | |||
d011816617 | |||
1501634925 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
.env
|
||||
.DS_Store
|
||||
app/database.db
|
||||
|
|
|
@ -19,17 +19,17 @@ require_once('../app/library.php');
|
|||
/// Autoloader to get all our classes.
|
||||
|
||||
const MAP = [
|
||||
'Article' => 'classes/Article.php',
|
||||
'ArticleComment' => 'classes/ArticleComment.php',
|
||||
'EpisodeComment' => 'classes/EpisodeComment.php',
|
||||
'Project' => 'classes/Project.php',
|
||||
'Show' => 'classes/Show.php',
|
||||
'User' => 'classes/User.php',
|
||||
'Article' => 'models/Article.php',
|
||||
'ArticleComment' => 'models/ArticleComment.php',
|
||||
'EpisodeComment' => 'models/EpisodeComment.php',
|
||||
'Project' => 'models/Project.php',
|
||||
'Show' => 'models/Show.php',
|
||||
'User' => 'models/User.php',
|
||||
|
||||
'DatabaseModule' => 'modules/DatabaseModule.php',
|
||||
'Database' => 'modules/Database.php',
|
||||
'CommunityModule' => 'modules/CommunityModule.php',
|
||||
'DisplayModule' => 'modules/DisplayModule.php',
|
||||
'ParserModule' => 'modules/ParserModule.php',
|
||||
'DisplayModule' => 'modules/DisplayModule.php',
|
||||
'ParserModule' => 'modules/ParserModule.php',
|
||||
|
||||
'CommunityHub' => 'hubs/CommunityHub.php'
|
||||
];
|
||||
|
@ -39,3 +39,6 @@ spl_autoload_register(function ($class) {
|
|||
require_once '../app/' . MAP[$class];
|
||||
return true;
|
||||
});
|
||||
|
||||
// Initialize the database handler
|
||||
Database::init('../app/database.db');
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Article {
|
||||
|
||||
private $ID;
|
||||
private $Title;
|
||||
private $Cover;
|
||||
private $Author;
|
||||
private $Content;
|
||||
private $PostDate;
|
||||
private $Comments;
|
||||
private $Description;
|
||||
|
||||
|
||||
public function __construct($id) {
|
||||
|
||||
$this->ID = $id;
|
||||
|
||||
$this->getArticle($id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function getArticle($id) {
|
||||
|
||||
$db = new DatabaseModule();
|
||||
|
||||
$getArticle = $db->Handle->prepare('SELECT * FROM ms_articles WHERE id = :id');
|
||||
$getArticle->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$getArticle->execute();
|
||||
|
||||
$ArticleInfo = $getArticle->fetch();
|
||||
|
||||
$getArticle->closeCursor();
|
||||
|
||||
|
||||
$this->Title = $ArticleInfo['articleName'];
|
||||
$this->Cover = $ArticleInfo['articleCover'];
|
||||
$this->Author = $ArticleInfo['articleAuthor'];
|
||||
$this->Content = $ArticleInfo['articleContent'];
|
||||
$this->PostDate = betterDate($ArticleInfo['articleDate']);
|
||||
$this->Comments = $ArticleInfo['articleComments'];
|
||||
$this->Description = $ArticleInfo['articleDescription'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function __get($what) {
|
||||
|
||||
if(property_exists($this, $what)) {
|
||||
|
||||
return $this->{$what};
|
||||
|
||||
} else {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function update($what) {
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
class ArticleComment {
|
||||
|
||||
private $ID;
|
||||
private $Author;
|
||||
private $Content;
|
||||
private $PostDate;
|
||||
private $ArticleID;
|
||||
|
||||
|
||||
public function __construct($id) {
|
||||
$this->ID = $id;
|
||||
|
||||
$this->getArticleComment($id);
|
||||
}
|
||||
|
||||
|
||||
private function getArticleComment($id) {
|
||||
|
||||
$db = new DatabaseModule();
|
||||
|
||||
$getArticle = $db->Handle->prepare('SELECT * FROM ms_articlecomments WHERE id = :id');
|
||||
$getArticle->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$getArticle->execute();
|
||||
|
||||
$ArticleInfo = $getArticle->fetch();
|
||||
|
||||
$getArticle->closeCursor();
|
||||
|
||||
$this->Author = $ArticleInfo['commentAuthor'];
|
||||
$this->Content = $ArticleInfo['commentContent'];
|
||||
$this->PostDate = betterDate($ArticleInfo['commentDate']);
|
||||
$this->ArticleID = $ArticleInfo['articleID'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function __get($what) {
|
||||
|
||||
if(property_exists($this, $what)) {
|
||||
|
||||
return $this->{$what};
|
||||
|
||||
} else {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function update($what) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -1,60 +0,0 @@
|
|||
<?php
|
||||
|
||||
class EpisodeComment {
|
||||
|
||||
private $ID;
|
||||
private $Author;
|
||||
private $Content;
|
||||
private $PostDate;
|
||||
private $ShowID;
|
||||
|
||||
|
||||
|
||||
public function __construct($id) {
|
||||
$this->ID = $id;
|
||||
|
||||
$this->getComment($id);
|
||||
}
|
||||
|
||||
|
||||
private function getComment($id) {
|
||||
|
||||
$db = new DatabaseModule();
|
||||
|
||||
$get = $db->Handle->prepare('SELECT * FROM episodecomments WHERE id = :id');
|
||||
$get->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$get->execute();
|
||||
|
||||
$data = $get->fetch();
|
||||
|
||||
$get->closeCursor();
|
||||
|
||||
$this->Author = $data['commentAuthor'];
|
||||
$this->Content = $data['commentContent'];
|
||||
$this->PostDate = betterDate($data['commentDate']);
|
||||
$this->ArticleID = $data['showID'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function __get($what) {
|
||||
|
||||
if(property_exists($this, $what)) {
|
||||
|
||||
return $this->{$what};
|
||||
|
||||
} else {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function update($what) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Project {
|
||||
/* -- User info variables; used for the functions here -- */
|
||||
private $ID;
|
||||
private $Type;
|
||||
private $Desc;
|
||||
private $Title;
|
||||
private $Cover;
|
||||
private $LastUpdate;
|
||||
|
||||
/* -- User class constructor -- */
|
||||
public function __construct($id) {
|
||||
$this->ID = $id;
|
||||
|
||||
$this->getProject($id);
|
||||
}
|
||||
|
||||
/* -- Used in the constructor to access the DB and get all the user's info and populate the variables -- */
|
||||
private function getProject($id) {
|
||||
// Open database connection
|
||||
$db = new DatabaseModule();
|
||||
|
||||
// Get user information from the DB
|
||||
$getProject = $db->Handle->prepare('SELECT * FROM ms_projects WHERE id = :id');
|
||||
$getProject->bindValue(':id', $id, PDO::PARAM_INT); // bind $id to the placeholder
|
||||
$getProject->execute();
|
||||
|
||||
$ProjectInfo = $getProject->fetch(); // get the results from the query
|
||||
|
||||
$getProject->closeCursor(); // close the SELECT query from continuing its search
|
||||
|
||||
// Populate the variables
|
||||
$this->ID = $ProjectInfo["id"];
|
||||
$this->Type = $ProjectInfo["type"];
|
||||
$this->Desc = $ProjectInfo["desc"];
|
||||
$this->Title = $ProjectInfo["title"];
|
||||
$this->Cover = $ProjectInfo["cover"];
|
||||
$this->lastUpdate = betterDate($ProjectInfo["lastUpdate"]);
|
||||
}
|
||||
|
||||
/* -- Returns whatever info needed at the moment -- */
|
||||
public function __get($what) {
|
||||
if(property_exists($this, $what)) {
|
||||
return $this->{$what};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/* -- Updates a value in the DB belonging to the user -- */
|
||||
public function update($what) {
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,108 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Show {
|
||||
|
||||
private $ID;
|
||||
private $Title;
|
||||
private $ShowID;
|
||||
private $Thumbnail;
|
||||
private $Description;
|
||||
private $EpisodeArray;
|
||||
|
||||
private $EpisodeComments;
|
||||
|
||||
private $db;
|
||||
|
||||
private $ThumbPath = "http://localhost:8888//assets/images/Thumbs/Show/";
|
||||
|
||||
|
||||
|
||||
public function __construct($id) {
|
||||
|
||||
$DBM = new DatabaseModule();
|
||||
$this->db = $DBM->Handle;
|
||||
|
||||
$this->ShowID = $id;
|
||||
|
||||
$this->CommentBox = GetTemplate('comments/commentbox');
|
||||
$this->CommentForm = GetTemplate('comments/commentform');
|
||||
|
||||
$this->getData();
|
||||
$this->GetEpisodeList();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function getData() {
|
||||
|
||||
$get = $this->db->prepare('SELECT * FROM ms_projects WHERE showid = :id');
|
||||
$get->bindValue(':id', $this->ShowID, PDO::PARAM_INT); // bind $id to the placeholder
|
||||
$get->execute();
|
||||
|
||||
$data = $get->fetch();
|
||||
|
||||
$get->closeCursor();
|
||||
|
||||
$this->ID = $data["id"];
|
||||
$this->Title = $data["title"];
|
||||
$this->Thumbnail = $this->ThumbPath . $data["thumbnail"];
|
||||
$this->Description = $data["desc"];
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function __get($what) {
|
||||
|
||||
if(property_exists($this, $what)) {
|
||||
|
||||
return $this->{$what};
|
||||
|
||||
} else {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function GetEpisodeList() {
|
||||
|
||||
$get = $this->db->prepare("SELECT * FROM episodes WHERE `show` = :s ORDER BY id DESC");
|
||||
$get->bindValue(':s', $this->ShowID, PDO::PARAM_INT);
|
||||
$get->execute();
|
||||
|
||||
$episodes = $get->fetchAll();
|
||||
|
||||
$get->closeCursor();
|
||||
|
||||
$this->EpisodeArray = $episodes;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function GetEpisodeComments($id) {
|
||||
|
||||
$get = $this->db->prepare('SELECT * FROM episodecomments WHERE showID = :id');
|
||||
$get->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$get->execute();
|
||||
|
||||
$data = $get->fetchAll();
|
||||
|
||||
$list = array();
|
||||
|
||||
foreach($data as $ID) {
|
||||
|
||||
$comment = new EpisodeComment($ID['id']);
|
||||
$poster = new User($comment->Author);
|
||||
|
||||
$list[] = ParseTemplate($this->CommentBox, array('a' => $poster->Avatar, 'u' => $poster->Username, 'c' => BBCode(magicClean($comment->Content)), 'd' => $comment->PostDate));
|
||||
|
||||
}
|
||||
|
||||
return $list;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -1,95 +0,0 @@
|
|||
<?php
|
||||
|
||||
class User {
|
||||
/* -- User info variables; used for the functions here -- */
|
||||
private $Email;
|
||||
private $Title;
|
||||
private $UserID;
|
||||
private $Avatar;
|
||||
private $Gender;
|
||||
private $Badges;
|
||||
private $AboutMe;
|
||||
private $WhatsUp;
|
||||
private $Username;
|
||||
private $BirthDay;
|
||||
private $JoinDate;
|
||||
private $PostCount;
|
||||
private $UserTitle;
|
||||
private $Reputation;
|
||||
private $isVerified;
|
||||
private $MemberLevel;
|
||||
|
||||
/* User Database Handle */
|
||||
private $DB = null;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
public function __construct($id) {
|
||||
// Open database connection
|
||||
$DM = new DatabaseModule();
|
||||
$DM->createUserHandle();
|
||||
$this->DB = $DM->userHandle;
|
||||
|
||||
|
||||
$this->UserID = $id;
|
||||
|
||||
$this->getUser($id);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
private function getUser($id) {
|
||||
$db = $this->DB;
|
||||
|
||||
// Get username and ID from the database
|
||||
$getUser = $db->prepare('SELECT * FROM ms_users WHERE id = :id');
|
||||
$getUser->bindValue(':id', $id, PDO::PARAM_INT); // bind $id to the placeholder
|
||||
$getUser->execute();
|
||||
|
||||
$User = $getUser->fetch(); // get the results from the query
|
||||
|
||||
$getUser->closeCursor(); // close the SELECT query from continuing its search
|
||||
|
||||
// Populate the variable(s)
|
||||
$this->Username = $User['username'];
|
||||
|
||||
$this->Title = $User['title'];
|
||||
$this->Email = $User['email'];
|
||||
$this->Gender = $User['gender'];
|
||||
$this->Badges = $User['badges'];
|
||||
$this->AboutMe = $User['blurb'];
|
||||
$this->WhatsUp = $User['status'];
|
||||
$this->BirthDay = $User['bday'];
|
||||
$this->JoinDate = $User['joindate'];
|
||||
$this->PostCount = $User['posts'];
|
||||
$this->Avatar = $User['avatar'];
|
||||
$this->Reputation = $User['reputation'];
|
||||
$this->MemberLevel = $User['mlevel'];
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
public function __get($what) {
|
||||
|
||||
if(property_exists($this, $what)) {
|
||||
|
||||
return $this->{$what};
|
||||
|
||||
} else {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function update($what) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
35
app/models/Article.php
Executable file
35
app/models/Article.php
Executable file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
class Article
|
||||
{
|
||||
private $ID;
|
||||
private $Title;
|
||||
private $Cover;
|
||||
private $Author;
|
||||
private $Content;
|
||||
private $PostDate;
|
||||
private $Comments;
|
||||
private $Description;
|
||||
|
||||
public function __construct(int $id)
|
||||
{
|
||||
$this->ID = $id;
|
||||
|
||||
$result = Database::select('articles', '*', 'WHERE id = :id', data: [':id' => $id]);
|
||||
|
||||
$ArticleInfo = $result->fetch();
|
||||
|
||||
$this->Title = $ArticleInfo['articleName'];
|
||||
$this->Cover = $ArticleInfo['articleCover'];
|
||||
$this->Author = $ArticleInfo['articleAuthor'];
|
||||
$this->Content = $ArticleInfo['articleContent'];
|
||||
$this->PostDate = betterDate($ArticleInfo['articleDate']);
|
||||
$this->Comments = $ArticleInfo['articleComments'];
|
||||
$this->Description = $ArticleInfo['articleDescription'];
|
||||
}
|
||||
|
||||
public function __get($what)
|
||||
{
|
||||
return property_exists($this, $what) ? $this->{$what} : null;
|
||||
}
|
||||
}
|
29
app/models/ArticleComment.php
Executable file
29
app/models/ArticleComment.php
Executable file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
class ArticleComment
|
||||
{
|
||||
private $ID;
|
||||
private $Author;
|
||||
private $Content;
|
||||
private $PostDate;
|
||||
private $ArticleID;
|
||||
|
||||
public function __construct($id)
|
||||
{
|
||||
$this->ID = $id;
|
||||
|
||||
$result = Database::select('articlecomments', '*', 'WHERE id = :id', data: [':id' => $id]);
|
||||
|
||||
$ArticleInfo = $result->fetch();
|
||||
|
||||
$this->Author = $ArticleInfo['commentAuthor'];
|
||||
$this->Content = $ArticleInfo['commentContent'];
|
||||
$this->PostDate = betterDate($ArticleInfo['commentDate']);
|
||||
$this->ArticleID = $ArticleInfo['articleID'];
|
||||
}
|
||||
|
||||
public function __get($what)
|
||||
{
|
||||
return property_exists($this, $what) ? $this->{$what} : null;
|
||||
}
|
||||
}
|
29
app/models/EpisodeComment.php
Executable file
29
app/models/EpisodeComment.php
Executable file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
class EpisodeComment
|
||||
{
|
||||
private $ID;
|
||||
private $Author;
|
||||
private $Content;
|
||||
private $PostDate;
|
||||
private $ShowID;
|
||||
|
||||
public function __construct($id)
|
||||
{
|
||||
$this->ID = $id;
|
||||
|
||||
$result = Database::select('episodecomments', '*', 'WHERE id = :id', data: [':id' => $id]);
|
||||
|
||||
$data = $result->fetch();
|
||||
|
||||
$this->Author = $data['commentAuthor'];
|
||||
$this->Content = $data['commentContent'];
|
||||
$this->PostDate = betterDate($data['commentDate']);
|
||||
$this->ShowID = $data['showID'];
|
||||
}
|
||||
|
||||
public function __get($what)
|
||||
{
|
||||
return property_exists($this, $what) ? $this->{$what} : null;
|
||||
}
|
||||
}
|
32
app/models/Project.php
Executable file
32
app/models/Project.php
Executable file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
class Project
|
||||
{
|
||||
private $ID;
|
||||
private $Type;
|
||||
private $Desc;
|
||||
private $Title;
|
||||
private $Cover;
|
||||
private $LastUpdate;
|
||||
|
||||
public function __construct($id)
|
||||
{
|
||||
$this->ID = $id;
|
||||
|
||||
$result = Database::select('projects', '*', 'WHERE id = :id', data: [':id' => $id]);
|
||||
|
||||
$data = $result->fetch();
|
||||
|
||||
$this->ID = $data["id"];
|
||||
$this->Type = $data["type"];
|
||||
$this->Desc = $data["desc"];
|
||||
$this->Title = $data["title"];
|
||||
$this->Cover = $data["cover"];
|
||||
$this->LastUpdate = betterDate($data["lastUpdate"]);
|
||||
}
|
||||
|
||||
public function __get($what)
|
||||
{
|
||||
return property_exists($this, $what) ? $this->{$what} : null;
|
||||
}
|
||||
}
|
81
app/models/Show.php
Executable file
81
app/models/Show.php
Executable file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
class Show
|
||||
{
|
||||
private $ID;
|
||||
private $Title;
|
||||
private $ShowID;
|
||||
private $Thumbnail;
|
||||
private $Description;
|
||||
private $EpisodeArray;
|
||||
|
||||
private $EpisodeComments;
|
||||
|
||||
private $ThumbPath = "/assets/images/Thumbs/Show/";
|
||||
|
||||
public string $CommentBox;
|
||||
public string $CommentForm;
|
||||
|
||||
public function __construct($id)
|
||||
{
|
||||
$this->ShowID = $id;
|
||||
|
||||
$this->CommentForm = render('comments/commentform');
|
||||
|
||||
$this->getData();
|
||||
$this->GetEpisodeList();
|
||||
}
|
||||
|
||||
|
||||
private function getData()
|
||||
{
|
||||
$get = Database::select('projects', '*', 'WHERE showid = :id', data: [':id' => $this->ShowID]);
|
||||
|
||||
$data = $get->fetch();
|
||||
|
||||
$this->ID = $data["id"];
|
||||
$this->Title = $data["title"];
|
||||
$this->Thumbnail = $this->ThumbPath . $data["thumbnail"];
|
||||
$this->Description = $data["desc"];
|
||||
}
|
||||
|
||||
|
||||
public function __get($what)
|
||||
{
|
||||
return property_exists($this, $what) ? $this->{$what} : null;
|
||||
}
|
||||
|
||||
|
||||
public function GetEpisodeList()
|
||||
{
|
||||
$get = Database::select('episodes', '*', 'WHERE `show` = :s', 'id DESC', data: [':s' => $this->ShowID]);
|
||||
|
||||
$episodes = $get->fetchAll();
|
||||
|
||||
$this->EpisodeArray = $episodes;
|
||||
}
|
||||
|
||||
|
||||
public function GetEpisodeComments($id)
|
||||
{
|
||||
$get = Database::select('episodecomments', '*', 'WHERE showID = :id', data: [':id' => $id]);
|
||||
|
||||
$data = $get->fetchAll();
|
||||
|
||||
$list = [];
|
||||
|
||||
foreach ($data as $ID) {
|
||||
$comment = new EpisodeComment($ID['id']);
|
||||
$poster = new User($comment->Author);
|
||||
|
||||
$list[] = render('comments/commentbox', [
|
||||
'a' => $poster->Avatar,
|
||||
'u' => $poster->Username,
|
||||
'c' => BBCode(magicClean($comment->Content)),
|
||||
'd' => $comment->PostDate
|
||||
]);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
48
app/models/User.php
Executable file
48
app/models/User.php
Executable file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
class User
|
||||
{
|
||||
private $Email;
|
||||
private $Title;
|
||||
private $UserID;
|
||||
private $Avatar;
|
||||
private $Gender;
|
||||
private $Badges;
|
||||
private $AboutMe;
|
||||
private $WhatsUp;
|
||||
private $Username;
|
||||
private $BirthDay;
|
||||
private $JoinDate;
|
||||
private $PostCount;
|
||||
private $UserTitle;
|
||||
private $Reputation;
|
||||
private $isVerified;
|
||||
private $MemberLevel;
|
||||
|
||||
public function __construct($id)
|
||||
{
|
||||
$this->UserID = $id;
|
||||
|
||||
$result = Database::select('users', '*', 'WHERE id = :id', data: [':id' => $id]);
|
||||
$User = $result->fetch();
|
||||
|
||||
$this->Username = $User['username'];
|
||||
$this->Title = $User['title'];
|
||||
$this->Email = $User['email'];
|
||||
$this->Gender = $User['gender'];
|
||||
$this->Badges = $User['badges'];
|
||||
$this->AboutMe = $User['blurb'];
|
||||
$this->WhatsUp = $User['status'];
|
||||
$this->BirthDay = $User['bday'];
|
||||
$this->JoinDate = $User['joindate'];
|
||||
$this->PostCount = $User['posts'];
|
||||
$this->Avatar = $User['avatar'];
|
||||
$this->Reputation = $User['reputation'];
|
||||
$this->MemberLevel = $User['mlevel'];
|
||||
}
|
||||
|
||||
public function __get($what)
|
||||
{
|
||||
return property_exists($this, $what) ? $this->{$what} : null;
|
||||
}
|
||||
}
|
135
app/modules/Database.php
Executable file
135
app/modules/Database.php
Executable file
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
--- The Database Module
|
||||
--- This module is for the general CRUD methods.
|
||||
--- This module was crafted by Skylear. : )
|
||||
--- Copyright (c) Mad Splash, 2014, all rights reserved.
|
||||
*/
|
||||
|
||||
class Database
|
||||
{
|
||||
/* --- Variables - data the module needs to work with. --- */
|
||||
private static PDO $c;
|
||||
|
||||
/* --- Constructor - creates the module's instance. --- */
|
||||
public static function init(string $path, array $opts = [])
|
||||
{
|
||||
$opts = !empty($opts) ? $opts : [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
];
|
||||
|
||||
// Check to see if the database exists; if not, we have to build the tables
|
||||
$new = !file_exists($path);
|
||||
|
||||
try {
|
||||
self::$c = new PDO("sqlite:$path", null, null, $opts);
|
||||
if ($new) { self::build(); }
|
||||
} catch (PDOException $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/* --- Module Functions - the meat and purpose of the module. --- */
|
||||
/* Create Table - for creating a table when need be.
|
||||
* @param string $name - the name of the table to be created.
|
||||
* @param string $columns - a long string containing the columns to be made.
|
||||
*/
|
||||
public static function createTable($name, $columns) {
|
||||
// No need for creating tables for the time being.
|
||||
}
|
||||
|
||||
/* Select Data - used for getting data from the database.
|
||||
* @return array $selectedRos - an array containing the data.
|
||||
*/
|
||||
public static function select(string $from, string $retrieve, string $condition, string $orderby = '', int $limit = 0, array $data = [])
|
||||
{
|
||||
$query = "SELECT $retrieve FROM $from $condition";
|
||||
if (!empty($orderby)) { $query .= " ORDER BY $orderby"; }
|
||||
if ($limit > 0) { $query .= " LIMIT $limit"; }
|
||||
|
||||
$selectQuery = self::$c->prepare($query);
|
||||
$selectQuery->execute($data);
|
||||
return $selectQuery;
|
||||
}
|
||||
|
||||
public static function count(string $from, string $condition = ''): mixed
|
||||
{
|
||||
$query = "SELECT COUNT(*) FROM $from";
|
||||
if (!empty($condition)) { $query .= " $condition"; }
|
||||
return self::$c->query($query)->fetch();
|
||||
}
|
||||
|
||||
private static function build()
|
||||
{
|
||||
// Create the users table
|
||||
self::$c->exec("CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
email TEXT NOT NULL,
|
||||
title TEXT NOT NULL DEFAULT 'Newbie',
|
||||
gender INTEGER NOT NULL DEFAULT 0,
|
||||
badges TEXT NOT NULL DEFAULT '',
|
||||
blurb TEXT NOT NULL DEFAULT '',
|
||||
status TEXT NOT NULL DEFAULT '',
|
||||
bday DATE NOT NULL DEFAULT '0000-00-00',
|
||||
posts INTEGER NOT NULL DEFAULT 0,
|
||||
avatar TEXT NOT NULL DEFAULT '',
|
||||
reputation INTEGER NOT NULL DEFAULT 0,
|
||||
mlevel INTEGER NOT NULL DEFAULT 0,
|
||||
joindate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);");
|
||||
|
||||
// Create the articles table
|
||||
self::$c->exec("CREATE TABLE articles (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
articleName TEXT NOT NULL,
|
||||
articleCover TEXT NOT NULL,
|
||||
articleAuthor INTEGER NOT NULL DEFAULT 1,
|
||||
articleContent TEXT NOT NULL,
|
||||
articleDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
articleComments INTEGER NOT NULL DEFAULT 0,
|
||||
articleDescription TEXT NOT NULL DEFAULT ''
|
||||
);");
|
||||
|
||||
// Create the article comments table
|
||||
self::$c->exec("CREATE TABLE articlecomments (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
commentAuthor INTEGER NOT NULL,
|
||||
commentContent TEXT NOT NULL,
|
||||
commentDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
articleID INTEGER NOT NULL
|
||||
);");
|
||||
|
||||
// Create the episode comments table
|
||||
self::$c->exec("CREATE TABLE episodecomments (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
commentAuthor INTEGER NOT NULL,
|
||||
commentContent TEXT NOT NULL,
|
||||
commentDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
showID INTEGER NOT NULL
|
||||
);");
|
||||
|
||||
// Create the projects table
|
||||
self::$c->exec("CREATE TABLE projects (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
type TEXT NOT NULL,
|
||||
desc TEXT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
cover TEXT NOT NULL,
|
||||
lastUpdate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);");
|
||||
|
||||
// Create the shows table
|
||||
self::$c->exec("CREATE TABLE shows (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
thumbnail TEXT NOT NULL,
|
||||
desc TEXT NOT NULL,
|
||||
showid INTEGER NOT NULL,
|
||||
lastUpdate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);");
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
--- The Database Module
|
||||
--- This module is for the general CRUD methods.
|
||||
--- This module was crafted by Skylear. : )
|
||||
--- Copyright (c) Mad Splash, 2014, all rights reserved.
|
||||
*/
|
||||
|
||||
class DatabaseModule {
|
||||
/* --- Variables - data the module needs to work with. --- */
|
||||
private $Handle = null;
|
||||
private $userHandle = null;
|
||||
private $FHandle = null;
|
||||
|
||||
/* --- Constructor - creates the module's instance. --- */
|
||||
public function __construct() {
|
||||
$DBUsername = 'root';
|
||||
$DBPassword = 'root';
|
||||
$DBName = 'database';
|
||||
|
||||
try {
|
||||
$DBHandle = new PDO('mysql: host=localhost; dbname=' . $DBName, $DBUsername, $DBPassword);
|
||||
} catch(PDOException $ex) {
|
||||
die("Oops, we failed to the connect to the database. The error: " . $ex->getMessage() . ".");
|
||||
}
|
||||
|
||||
$DBHandle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$DBHandle->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
|
||||
$this->Handle = $DBHandle;
|
||||
}
|
||||
|
||||
public function createUserHandle() {
|
||||
$DBUsername = 'root';
|
||||
$DBPassword = 'root';
|
||||
$DBName = 'database';
|
||||
|
||||
try {
|
||||
$DBHandle = new PDO('mysql: host=localhost; dbname=' . $DBName, $DBUsername, $DBPassword);
|
||||
} catch(PDOException $ex) {
|
||||
die("Oops, we failed to the connect to the database. The error: " . $ex->getMessage() . ".");
|
||||
}
|
||||
|
||||
$DBHandle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$DBHandle->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
|
||||
$this->userHandle = $DBHandle;
|
||||
}
|
||||
|
||||
public function createFHandle() {
|
||||
$DBUsername = 'root';
|
||||
$DBPassword = 'root';
|
||||
$DBName = 'database';
|
||||
|
||||
try {
|
||||
$DBHandle = new PDO('mysql: host=localhost; dbname=' . $DBName, $DBUsername, $DBPassword);
|
||||
} catch(PDOException $ex) {
|
||||
die("Oops, we failed to the connect to the database. The error: " . $ex->getMessage() . ".");
|
||||
}
|
||||
|
||||
$DBHandle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$DBHandle->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
|
||||
$this->FHandle = $DBHandle;
|
||||
}
|
||||
|
||||
public function __get($what) {
|
||||
if(property_exists($this, $what)) {
|
||||
return $this->{$what};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/* --- Module Functions - the meat and purpose of the module. --- */
|
||||
/* Create Table - for creating a table when need be.
|
||||
* @param string $name - the name of the table to be created.
|
||||
* @param string $columns - a long string containing the columns to be made.
|
||||
*/
|
||||
public function createTable($name, $columns) {
|
||||
// No need for creating tables for the time being.
|
||||
}
|
||||
|
||||
/* Select Data - used for getting data from the database.
|
||||
* @return array $selectedRos - an array containing the data.
|
||||
*/
|
||||
public function getData($from, $retrieve, $condition, $limit, $orderby) {
|
||||
$Handle = $this->Handle;
|
||||
|
||||
$query = 'SELECT ' . $retrieve . ' FROM ' . $from . ' ' . $condition . ' ' . $orderby . ' ' . $limit ;
|
||||
|
||||
$selectQuery = $Handle->prepare($query);
|
||||
$selectQuery->execute();
|
||||
$selectedRows = $selectQuery->fetchAll();
|
||||
|
||||
return $selectedRows;
|
||||
}
|
||||
|
||||
public function countRows($which, $condition) {
|
||||
$Handle = $this->Handle;
|
||||
|
||||
$query = 'SELECT COUNT(*) FROM ' . $which . ' ' . $condition;
|
||||
$count = $Handle->query($query);
|
||||
|
||||
return $count->fetch();
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -8,6 +8,11 @@ echo render('header');
|
|||
|
||||
$page = !empty($_GET['page']) && in_array($_GET['page'], PAGES) ? $_GET['page'] : 'home';
|
||||
|
||||
if ($page == 'verify' && (empty($_GET['code']) || empty($_GET['username']))) {
|
||||
header('Location: /');
|
||||
exit;
|
||||
}
|
||||
|
||||
echo render("community/$page");
|
||||
|
||||
echo render('footer');
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
define('SAFE', true);
|
||||
|
||||
$LockedPages = array();
|
||||
|
||||
|
||||
|
||||
if(!empty($_GET['code']) && !empty($_GET['username'])) {
|
||||
include("Pieces/header.htm");
|
||||
|
||||
include("Pieces/Community/verify.htm");
|
||||
|
||||
include("Pieces/footer.htm");
|
||||
} else {
|
||||
header('Location: http://localhost:8888/index.php');
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user