Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.61 KB | None | 0 0
  1. <?php
  2. /*
  3.  * To change this template, choose Tools | Templates
  4.  * and open the template in the editor.
  5. */
  6.  
  7. /**
  8.  * Description of ForumGetAndPost
  9.  *
  10.  * @author robert
  11.  */
  12. class ForumGetAndPost {
  13.     //Get
  14.     public function getAllCategories() {
  15.     $getCategoryResource = mysql_query("SELECT * FROM forum_categories ORDER BY category_name ASC");
  16.     while ($thisCategory = mysql_fetch_array($getCategoryResource)) {
  17.         $category[] = array(
  18.             'category_id'=>$thisCategory['category_id'],
  19.             'category_name'=>$thisCategory['category_name']
  20.         );
  21.     }
  22.     return $category;
  23.     }
  24.  
  25.  
  26.  
  27.     public function getAllForumsInCategory($categoryID) {
  28.     $categoryID = mysql_real_escape_string($categoryID);
  29.  
  30.     $getForumResource = mysql_query("SELECT * FROM forums WHERE category_id = '" . $categoryID . "' ORDER BY forum_title ASC ");
  31.  
  32.     while ($topicsInForum = mysql_fetch_array($getForumResource)) {
  33.         $forum[] = array (
  34.             'forum_id'=>$topicsInForum['forum_id'],
  35.             'forum_title'=>$topicsInForum['forum_title'],
  36.             'forum_create_time'=>$topicsInForum['forumc_create_time'],
  37.             'category_id'=>$topicsInForum['category_id'],
  38.             'forum_description'=>$topicsInForum['forum_description']
  39.         );
  40.     }
  41.  
  42.     return $forum;
  43.     }
  44.  
  45.  
  46.  
  47.  
  48.     public function getAllThreadsInTopic($topicid) {
  49.     $topicid = mysql_real_escape_string($topicid);
  50.  
  51.     $getThreadResource = mysql_query("SELECT * FROM forum_threads WHERE topic_id = '" . $topicid . "' ");
  52.  
  53.     while ($threadsInTopic = mysql_fetch_array($getThreadResource)) {
  54.         $thread[] = array(
  55.             'thread_id'=>$threadsInTopic['thread_id'],
  56.             'thread_title'=>$threadsInTopic['thread_title'],
  57.             'topic_id'=>$threadsInTopic['topic_id'],
  58.             'thread_owner'=>$threadsInTopic['thread_owner']
  59.         );
  60.     }
  61.  
  62.     //$thread = mysql_fetch_assoc($getThreadResource);
  63.  
  64.     return $thread;
  65.     }
  66.  
  67.  
  68.  
  69.     public function getAllPostsInThread($threadid) {
  70.     $threadid =mysql_real_escape_string($threadid);
  71.  
  72.     $getPostResource = mysql_query("SELECT * FROM forum_posts WHERE thread_id = '" . $threadid . "' ORDER BY post_create_time ASC");
  73.  
  74.     while ($postsInTopic = mysql_fetch_array($getPostResource)) {
  75.         $post[] = array (
  76.             'post_id'=>$postsInTopic['post_id'],
  77.             'thread_id'=>$postsInTopic['thread_id'],
  78.             'post_text'=>$postsInTopic['post_text'],
  79.             'post_create_time'=>$postsInTopic['post_create_time'],
  80.             'post_owner'=>$postsInTopic['post_owner'],
  81.             'post_title'=>$postsInTopic['post_title']
  82.         );
  83.     }
  84.  
  85.     return $post;
  86.     }
  87.  
  88.     public function getUsersPostCount($postowner) {
  89.     $postowner = mysql_real_escape_string($postowner);
  90.  
  91.     $postCountResourceID = mysql_query("SELECT * FROM forum_posts WHERE post_owner = '" . $postowner . "'");
  92.  
  93.  
  94.     $usersPostCount = mysql_num_rows($postCountResourceID);
  95.  
  96.     return $usersPostCount;
  97.     }
  98.  
  99.     public function getNumberOfThreads($topicid) {
  100.  
  101.     $topicid = mysql_real_escape_string($topicid);
  102.  
  103.     $numofthreads = mysql_query("SELECT * FROM forum_threads WHERE topic_id='" . $topicid . "' ");
  104.     $numberofthreads = mysql_num_rows($numofthreads);
  105.  
  106.     return $numberofthreads;
  107.     }
  108.  
  109.     public function forumIDToName($forumID) {
  110.     $forumID = mysql_real_escape_string($forumID);
  111.     $getForumIDReference = mysql_query(("SELECT * FROM forums WHERE forum_id = '" . $forumID . "' "));
  112.  
  113.     $forumName = mysql_fetch_array($getForumIDReference);
  114.  
  115.     return $forumName['forum_title'];
  116.     }
  117.  
  118.     public function threadIDToName($threadid) {
  119.     $threadid = mysql_real_escape_string($threadid);
  120.     $getTopicReference = mysql_query(("SELECT * FROM forum_threads WHERE thread_id = '" . $threadid . "' "));
  121.  
  122.     $topicname = mysql_fetch_array($getTopicReference);
  123.  
  124.     return $topicname['thread_title'];
  125.     }
  126.  
  127.     public function getMostRecentPost($threadid) {
  128.     $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");
  129.     $mostRecentPost = mysql_fetch_assoc($threadidResourceHandler);
  130.     return $mostRecentPost;
  131.     }
  132.  
  133.     public function getPostInfo($postid) {
  134.     $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 . "' ");
  135.  
  136.     $postdate = mysql_fetch_assoc($postIDResourceHandler);
  137.  
  138.     return $postdate;
  139.     }
  140.  
  141.     /*public function getForumIdOfTopic($forumid) {
  142.     $numTopicsResourceHandler = mysql_query("SELECT * FROM forum_topics WHERE forum_id ='" . $forumid . "' ");
  143.     }*/
  144.  
  145.     public function getUsersPosts($userid){
  146.     $getUsersPostsResourceHandler = mysql_query("SELECT * FROM forum_posts WHERE post_owner = '" . $userid . "' ");
  147.     $allUsersPosts = mysql_fetch_array($getUsersPostsResourceHandler);
  148.  
  149.     return $allUsersPosts;
  150.     }
  151.  
  152.  
  153.  
  154.  
  155.     //Set
  156.     public function makePost($thread_id, $post_text, $post_owner, $post_create_time, $post_title) {
  157.     $thread_id = mysql_real_escape_string($thread_id);
  158.     $post_text = mysql_real_escape_string($post_text);
  159.     $post_owner = mysql_real_escape_string($post_owner);
  160.     $post_create_time = mysql_real_escape_string($post_create_time);
  161.     $post_title= mysql_real_escape_string($post_title);
  162.  
  163.     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());
  164.     }
  165.  
  166.     public function makeThread($thread_title, $topic_id, $thread_owner, $post_text) {
  167.     $thread_title = mysql_escape_string(($thread_title));
  168.     mysql_query(" INSERT INTO forum_threads (thread_title, topic_id, thread_owner) VALUES('" . $thread_title . "', '" . $topic_id . "', '" . $thread_owner  . "')");
  169.     $thisCategory->makePost(mysql_insert_id(), $post_text, $thread_owner, date("Y-m-d H:i:s"), $thread_title);
  170.     }
  171.  
  172.     public function makeTopic($topic_title, $forum_id, $forum_topic_description) {
  173.     $topic_title = mysql_escape_string($topic_title);
  174.     $forum_id = mysql_real_escape_string($forum_id);
  175.     $forum_topic_description = mysql_escape_string($forum_topic_description);
  176.     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") . "')");
  177.     }
  178.  
  179.  
  180.     public function makeForum($forumname) {
  181.     $forumname = mysql_escape_string($forumname);
  182.     mysql_query(" INSERT INTO forums VALUES(NULL, '" . $forumname . "')") or die(mysql_error());
  183.     }
  184.  
  185. }
  186.  
  187. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement