diff --git a/app/bootstrap.php b/app/bootstrap.php index e0d0ac2..61dd45c 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -19,12 +19,12 @@ 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', 'Database' => 'modules/Database.php', 'CommunityModule' => 'modules/CommunityModule.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'); diff --git a/app/classes/ArticleComment.php b/app/classes/ArticleComment.php deleted file mode 100755 index 6b72e0e..0000000 --- a/app/classes/ArticleComment.php +++ /dev/null @@ -1,59 +0,0 @@ -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) { - - } - - } -?> diff --git a/app/classes/EpisodeComment.php b/app/classes/EpisodeComment.php deleted file mode 100755 index 23c7df1..0000000 --- a/app/classes/EpisodeComment.php +++ /dev/null @@ -1,60 +0,0 @@ -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) { - - } - - } -?> diff --git a/app/classes/Project.php b/app/classes/Project.php deleted file mode 100755 index 5645120..0000000 --- a/app/classes/Project.php +++ /dev/null @@ -1,56 +0,0 @@ -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) { - - } - } -?> diff --git a/app/classes/Show.php b/app/classes/Show.php deleted file mode 100755 index fbe1615..0000000 --- a/app/classes/Show.php +++ /dev/null @@ -1,108 +0,0 @@ -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; - - } - - } -?> diff --git a/app/classes/User.php b/app/classes/User.php deleted file mode 100755 index f0acd35..0000000 --- a/app/classes/User.php +++ /dev/null @@ -1,95 +0,0 @@ -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) { - - } - - } -?> diff --git a/app/classes/Article.php b/app/models/Article.php similarity index 75% rename from app/classes/Article.php rename to app/models/Article.php index fba5427..d8eaaab 100755 --- a/app/classes/Article.php +++ b/app/models/Article.php @@ -15,13 +15,9 @@ class Article { $this->ID = $id; - $getArticle = $db->Handle->prepare('SELECT * FROM ms_articles WHERE id = :id'); - $getArticle->bindValue(':id', $id, PDO::PARAM_INT); - $getArticle->execute(); + $result = Database::select('articles', '*', 'WHERE id = :id', data: [':id' => $id]); - $ArticleInfo = $getArticle->fetch(); - - $getArticle->closeCursor(); + $ArticleInfo = $result->fetch(); $this->Title = $ArticleInfo['articleName']; $this->Cover = $ArticleInfo['articleCover']; diff --git a/app/models/ArticleComment.php b/app/models/ArticleComment.php new file mode 100755 index 0000000..6a9bb5b --- /dev/null +++ b/app/models/ArticleComment.php @@ -0,0 +1,29 @@ +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; + } +} diff --git a/app/models/EpisodeComment.php b/app/models/EpisodeComment.php new file mode 100755 index 0000000..dc06e7c --- /dev/null +++ b/app/models/EpisodeComment.php @@ -0,0 +1,29 @@ +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; + } +} diff --git a/app/models/Project.php b/app/models/Project.php new file mode 100755 index 0000000..c0f0aac --- /dev/null +++ b/app/models/Project.php @@ -0,0 +1,32 @@ +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; + } +} diff --git a/app/models/Show.php b/app/models/Show.php new file mode 100755 index 0000000..452ab78 --- /dev/null +++ b/app/models/Show.php @@ -0,0 +1,81 @@ +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; + } +} diff --git a/app/models/User.php b/app/models/User.php new file mode 100755 index 0000000..76c0608 --- /dev/null +++ b/app/models/User.php @@ -0,0 +1,48 @@ +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; + } +} diff --git a/app/modules/Database.php b/app/modules/Database.php index bbe8e79..ffaf4eb 100755 --- a/app/modules/Database.php +++ b/app/modules/Database.php @@ -39,15 +39,15 @@ class Database /* 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 = '', string $limit = '', array $data = []): array + 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 .= " $orderby"; } - if (!empty($limit)) { $query .= " $limit"; } + if (!empty($orderby)) { $query .= " ORDER BY $orderby"; } + if ($limit > 0) { $query .= " LIMIT $limit"; } $selectQuery = self::$c->prepare($query); $selectQuery->execute($data); - return $selectQuery->fetchAll(); + return $selectQuery; } public function count(string $from, string $condition = ''): mixed