Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- * Description of ForumGetAndPost
- *
- * @author robert
- */
- class ForumGetAndPost {
- //Get
- public function getAllCategories() {
- $getCategoryResource = mysql_query("SELECT * FROM forum_categories ORDER BY category_name ASC");
- while ($thisCategory = mysql_fetch_array($getCategoryResource)) {
- $category[] = array(
- 'category_id'=>$thisCategory['category_id'],
- 'category_name'=>$thisCategory['category_name']
- );
- }
- return $category;
- }
- public function getAllForumsInCategory($categoryID) {
- $categoryID = mysql_real_escape_string($categoryID);
- $getForumResource = mysql_query("SELECT * FROM forums WHERE category_id = '" . $categoryID . "' ORDER BY forum_title ASC ");
- while ($topicsInForum = mysql_fetch_array($getForumResource)) {
- $forum[] = array (
- 'forum_id'=>$topicsInForum['forum_id'],
- 'forum_title'=>$topicsInForum['forum_title'],
- 'forum_create_time'=>$topicsInForum['forumc_create_time'],
- 'category_id'=>$topicsInForum['category_id'],
- 'forum_description'=>$topicsInForum['forum_description']
- );
- }
- return $forum;
- }
- public function getAllThreadsInTopic($topicid) {
- $topicid = mysql_real_escape_string($topicid);
- $getThreadResource = mysql_query("SELECT * FROM forum_threads WHERE topic_id = '" . $topicid . "' ");
- while ($threadsInTopic = mysql_fetch_array($getThreadResource)) {
- $thread[] = array(
- 'thread_id'=>$threadsInTopic['thread_id'],
- 'thread_title'=>$threadsInTopic['thread_title'],
- 'topic_id'=>$threadsInTopic['topic_id'],
- 'thread_owner'=>$threadsInTopic['thread_owner']
- );
- }
- //$thread = mysql_fetch_assoc($getThreadResource);
- return $thread;
- }
- public function getAllPostsInThread($threadid) {
- $threadid =mysql_real_escape_string($threadid);
- $getPostResource = mysql_query("SELECT * FROM forum_posts WHERE thread_id = '" . $threadid . "' ORDER BY post_create_time ASC");
- while ($postsInTopic = mysql_fetch_array($getPostResource)) {
- $post[] = array (
- 'post_id'=>$postsInTopic['post_id'],
- 'thread_id'=>$postsInTopic['thread_id'],
- 'post_text'=>$postsInTopic['post_text'],
- 'post_create_time'=>$postsInTopic['post_create_time'],
- 'post_owner'=>$postsInTopic['post_owner'],
- 'post_title'=>$postsInTopic['post_title']
- );
- }
- return $post;
- }
- public function getUsersPostCount($postowner) {
- $postowner = mysql_real_escape_string($postowner);
- $postCountResourceID = mysql_query("SELECT * FROM forum_posts WHERE post_owner = '" . $postowner . "'");
- $usersPostCount = mysql_num_rows($postCountResourceID);
- return $usersPostCount;
- }
- public function getNumberOfThreads($topicid) {
- $topicid = mysql_real_escape_string($topicid);
- $numofthreads = mysql_query("SELECT * FROM forum_threads WHERE topic_id='" . $topicid . "' ");
- $numberofthreads = mysql_num_rows($numofthreads);
- return $numberofthreads;
- }
- public function forumIDToName($forumID) {
- $forumID = mysql_real_escape_string($forumID);
- $getForumIDReference = mysql_query(("SELECT * FROM forums WHERE forum_id = '" . $forumID . "' "));
- $forumName = mysql_fetch_array($getForumIDReference);
- return $forumName['forum_title'];
- }
- public function threadIDToName($threadid) {
- $threadid = mysql_real_escape_string($threadid);
- $getTopicReference = mysql_query(("SELECT * FROM forum_threads WHERE thread_id = '" . $threadid . "' "));
- $topicname = mysql_fetch_array($getTopicReference);
- return $topicname['thread_title'];
- }
- public function getMostRecentPost($threadid) {
- $threadidResourceHandler = mysql_query("SELECT *, date_format(post_create_time, '%d/%m/%Y') as post_date, date_format(post_create_time, '%H:%i') as post_time FROM forum_posts WHERE thread_id='" . $threadid['thread_id'] . "' ORDER BY post_create_time DESC LIMIT 1");
- $mostRecentPost = mysql_fetch_assoc($threadidResourceHandler);
- return $mostRecentPost;
- }
- public function getPostInfo($postid) {
- $postIDResourceHandler = mysql_query("SELECT *, date_format(post_create_time, '%d/%m/%Y') as post_date, date_format(post_create_time, '%H:%i') as post_time FROM forum_posts WHERE post_id='" . $postid . "' ");
- $postdate = mysql_fetch_assoc($postIDResourceHandler);
- return $postdate;
- }
- /*public function getForumIdOfTopic($forumid) {
- $numTopicsResourceHandler = mysql_query("SELECT * FROM forum_topics WHERE forum_id ='" . $forumid . "' ");
- }*/
- public function getUsersPosts($userid){
- $getUsersPostsResourceHandler = mysql_query("SELECT * FROM forum_posts WHERE post_owner = '" . $userid . "' ");
- $allUsersPosts = mysql_fetch_array($getUsersPostsResourceHandler);
- return $allUsersPosts;
- }
- //Set
- public function makePost($thread_id, $post_text, $post_owner, $post_create_time, $post_title) {
- $thread_id = mysql_real_escape_string($thread_id);
- $post_text = mysql_real_escape_string($post_text);
- $post_owner = mysql_real_escape_string($post_owner);
- $post_create_time = mysql_real_escape_string($post_create_time);
- $post_title= mysql_real_escape_string($post_title);
- mysql_query("INSERT INTO forum_posts (thread_id, post_text, post_owner, post_create_time, post_title) VALUES('" . $thread_id . "','" . $post_text . "','" . $post_owner . "', '" . $post_create_time . "', '" . $post_title . "')") or die (mysql_error());
- }
- public function makeThread($thread_title, $topic_id, $thread_owner, $post_text) {
- $thread_title = mysql_escape_string(($thread_title));
- mysql_query(" INSERT INTO forum_threads (thread_title, topic_id, thread_owner) VALUES('" . $thread_title . "', '" . $topic_id . "', '" . $thread_owner . "')");
- $thisCategory->makePost(mysql_insert_id(), $post_text, $thread_owner, date("Y-m-d H:i:s"), $thread_title);
- }
- public function makeTopic($topic_title, $forum_id, $forum_topic_description) {
- $topic_title = mysql_escape_string($topic_title);
- $forum_id = mysql_real_escape_string($forum_id);
- $forum_topic_description = mysql_escape_string($forum_topic_description);
- mysql_query(" INSERT INTO forum_topics (topic_title, forum_id, topic_description, topic_create_time) VALUES('" . $topic_title . "', '" . $forum_id . "', '" . $forum_topic_description . "', '" . date("Y-m-d H:i:s") . "')");
- }
- public function makeForum($forumname) {
- $forumname = mysql_escape_string($forumname);
- mysql_query(" INSERT INTO forums VALUES(NULL, '" . $forumname . "')") or die(mysql_error());
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement