예제 #1
0
    }
    echo "</div>";
    echo "</div>";
    // For small devices hides extra info
    echo "<div id='Bar{$f_p_id}' class='collapse hidden-sm hidden-md hidden-lg'>";
    echo "<div class='col-xs-12'>";
    // Display total replys
    // Display total topic replys
    echo "<div class='btn btn-info btn-xs'>";
    echo "Replies <span class='badge'>{$row2->total_topic_replys}</span>";
    echo "</div>";
    // Display total sweets
    echo Sweets::getTotalSweets($f_p_id, 'Forum_Topic', 'Forum_Topic_Reply');
    // Display total views
    echo "<div class='btn btn-info btn-xs'> Views <span class='badge'>";
    echo PageViews::views('false', $f_p_id, 'Forum_Topic', $data['current_userID']);
    echo "</span></div>";
    // Check to see if there has been a reply for this topic.  If not then don't show anything.
    if (isset($row2->LR_UserID)) {
        // Display Last Reply User Name
        $rp_user_name2 = CurrentUserData::getUserName($row2->LR_UserID);
        //Display how long ago this was posted
        echo "<Br> Last Reply by <a href='" . DIR . "Profile/{$row2->LR_UserID}/' style='font-weight: bold'>{$rp_user_name2}</a> " . TimeDiff::dateDiff("now", "{$row2->LR_TimeStamp}", 1) . " ago ";
    }
    echo "</div>";
    echo "</div>";
    echo "</div></td></tr>";
}
// End query
echo "</table>";
// Display Create New Topic Button if user is logged in
예제 #2
0
 public function topic($id, $current_page = null)
 {
     // Check if user is logged in
     if ($this->auth->isLoggedIn()) {
         // Get Current User's ID
         $u_id = $this->auth->user_info();
     } else {
         //Url::redirect();
     }
     // Get Cat ID for this topic
     $topic_forum_id = $this->model->forum_topic_cat_id($id);
     // Get Requested Topic's Title and Description
     $data['forum_cat'] = $this->model->forum_cat($topic_forum_id);
     $data['forum_cat_des'] = $this->model->forum_cat_des($topic_forum_id);
     $data['forum_topics'] = $this->model->forum_topics($topic_forum_id);
     // Get Requested Topic Information
     $data['topic_id'] = $id;
     $data['title'] = $this->model->topic_title($id);
     $data['topic_creator'] = $this->model->topic_creator($id);
     $data['topic_date'] = $this->model->topic_date($id);
     $data['topic_content'] = $this->model->topic_content($id);
     $data['topic_edit_date'] = $this->model->topic_edit_date($id);
     $data['topic_status'] = $this->model->topic_status($id);
     $data['topic_allow'] = $this->model->topic_allow($id);
     // Get hidden information if there is any
     $data['hidden_userID'] = $this->model->topic_hidden_userID($id);
     $data['hidden_reason'] = $this->model->topic_hidden_reason($id);
     $data['hidden_timestamp'] = $this->model->topic_hidden_timestamp($id);
     // Check to see if current user owns the origianal post
     $data['current_userID'] = $u_id;
     $data['topic_userID'] = $this->model->topic_userID($id);
     // Get current page number
     if ($current_page > 1) {
         $data['current_page'] = $current_page;
     }
     // Check to see if current user is admin
     $data['is_admin'] = $this->auth->checkIsAdmin($u_id);
     // Check to see if current user is moderator
     $data['is_mod'] = $this->auth->checkIsMod($u_id);
     // Check to see if current user is a new user
     $data['is_new_user'] = $this->auth->checkIsNewUser($u_id);
     // Get replys that are related to Requested Topic
     $data['topic_replys'] = $this->model->forum_topic_replys($id, $this->pagesReply->getLimit($current_page, $this->forum_topic_reply_limit));
     // Check to see if user has posted on this topic
     $data['checkUserPosted'] = $this->model->checkUserPosted($id, $u_id);
     // If user has not yet posted, then we set subcribe to true for new posts
     if ($data['checkUserPosted'] == true) {
         // Check to see if current user is subscribed to this topic
         $data['is_user_subscribed'] = $this->model->checkTopicSubscribe($id, $u_id);
     } else {
         $data['is_user_subscribed'] = true;
     }
     // Set total number of messages for paginator
     $total_num_replys = $this->model->getTotalReplys($id);
     $this->pagesReply->setTotal($total_num_replys);
     // Send page links to view
     $pageFormat = DIR . "Topic/{$id}/";
     // URL page where pages are
     $data['pageLinks'] = $this->pagesReply->pageLinks($pageFormat, null, $current_page);
     // Get related images if any
     $data['forum_topic_images'] = $this->model->getForumImagesTopic($id);
     // Check to see if user is submitting a new topic reply
     if (isset($_POST['submit'])) {
         // Check to make sure the csrf token is good
         if (Csrf::isTokenValid()) {
             // Get Action from POST
             $data['action'] = Request::post('action');
             $data['edit_reply_id'] = Request::post('edit_reply_id');
             // Check to see if user is editing topic
             if ($data['action'] == "update_topic") {
                 // Get data from post
                 $data['forum_content'] = strip_tags(Request::post('forum_content'));
                 $data['forum_title'] = strip_tags(Request::post('forum_title'));
                 // Check to make sure user completed all required fields in form
                 if (empty($data['forum_title'])) {
                     // Subject field is empty
                     $error[] = 'Topic Title Field is Blank!';
                 }
                 if (empty($data['forum_content'])) {
                     // Subject field is empty
                     $error[] = 'Topic Content Field is Blank!';
                 }
                 // Check to make sure user owns the content they are trying to edit
                 // Get the id of the user that owns the post that is getting edited
                 if ($u_id != $this->model->getTopicOwner($id)) {
                     // User does not own this content
                     $error[] = 'You Do Not Own The Content You Were Trying To Edit!';
                 }
                 // Check for errors before sending message
                 if (count($error) == 0) {
                     // No Errors, lets submit the new topic to db
                     if ($this->model->updateTopic($id, $data['forum_title'], $data['forum_content'])) {
                         // Success
                         SuccessHelper::push('You Have Successfully Updated a Topic', 'Topic/' . $id);
                     } else {
                         // Fail
                         $error[] = 'Edit Topic Failed';
                     }
                 }
                 // End Form Complete Check
             } else {
                 if ($data['action'] == "update_reply") {
                     // Get data from post
                     $data['fpr_content'] = strip_tags(Request::post('fpr_content'));
                     // Check to make sure user completed all required fields in form
                     if (empty($data['fpr_content'])) {
                         // Subject field is empty
                         $error[] = 'Topic Reply Content Field is Blank!';
                     }
                     // Check to make sure user owns the content they are trying to edit
                     // Get the id of the user that owns the post that is getting edited
                     if ($u_id != $this->model->getReplyOwner($data['edit_reply_id'])) {
                         // User does not own this content
                         $error[] = 'You Do Not Own The Content You Were Trying To Edit!';
                     }
                     // Check for errors before sending message
                     if (count($error) == 0) {
                         // No Errors, lets submit the new topic to db
                         if ($this->model->updateTopicReply($data['edit_reply_id'], $data['fpr_content'])) {
                             // Success
                             SuccessHelper::push('You Have Successfully Updated a Topic Reply', 'Topic/' . $id . '/' . $redirect_page_num . '/#topicreply' . $data['edit_reply_id']);
                         } else {
                             // Fail
                             $error[] = 'Edit Topic Reply Failed';
                         }
                     }
                     // End Form Complete Check
                 } else {
                     if ($data['action'] == "new_reply") {
                         // Get data from post
                         $data['fpr_content'] = strip_tags(Request::post('fpr_content'));
                         // Check to make sure user completed all required fields in form
                         if (empty($data['fpr_content'])) {
                             // Subject field is empty
                             $error[] = 'Topic Reply Content Field is Blank!';
                         }
                         // Check for errors before sending message
                         if (count($error) == 0) {
                             // No Errors, lets submit the new topic to db
                             if ($this->model->sendTopicReply($u_id, $id, $topic_forum_id, $data['fpr_content'], $data['is_user_subscribed'])) {
                                 // Get Submitted Reply ID
                                 $reply_id = $this->model->lastTopicReplyID($id);
                                 // Check to see if post is going on a new page
                                 $page_reply_limit = $this->forum_topic_reply_limit;
                                 $redirect_page_num = ceil(($total_num_replys + 1) / $page_reply_limit);
                                 // Send emails to those who are subscribed to this topic
                                 $this->model->sendTopicSubscribeEmails($id, $u_id, $data['title'], $data['forum_cat'], $data['fpr_content']);
                                 // Check for image upload with this topic
                                 $picture = file_exists($_FILES['forumImage']['tmp_name']) || is_uploaded_file($_FILES['forumImage']['tmp_name']) ? $_FILES['forumImage'] : array();
                                 // Make sure image is being uploaded before going further
                                 if (sizeof($picture) > 0 && $data['is_new_user'] != true) {
                                     // Get image size
                                     $check = getimagesize($picture['tmp_name']);
                                     // Get file size for db
                                     $file_size = $picture['size'];
                                     // Make sure image size is not too large
                                     if ($picture['size'] < 5000000 && $check && ($check['mime'] == "image/jpeg" || $check['mime'] == "image/png" || $check['mime'] == "image/gif")) {
                                         if (!file_exists('images/forum-pics')) {
                                             mkdir('images/forum-pics', 0777, true);
                                         }
                                         // Upload the image to server
                                         $image = new SimpleImage($picture['tmp_name']);
                                         $new_image_name = "forum-image-topic-reply-uid{$u_id}-fid{$id}-ftid{$reply_id}";
                                         $dir = 'images/forum-pics/' . $new_image_name . '.gif';
                                         $image->best_fit(400, 300)->save($dir);
                                         $forumImage = $dir;
                                         // Make sure image was Successfull
                                         if ($forumImage) {
                                             // Add new image to database
                                             if ($this->model->sendNewImage($u_id, $new_image_name, $dir, $file_size, $topic_forum_id, $id, $reply_id)) {
                                                 $img_success = "<br> Image Successfully Uploaded";
                                             } else {
                                                 $img_success = "<br> No Image Uploaded";
                                             }
                                         }
                                     } else {
                                         $img_success = "<br> Image was NOT uploaded because the file size was too large!";
                                     }
                                 }
                                 // Success
                                 SuccessHelper::push('You Have Successfully Created a New Topic Reply' . $img_success, 'Topic/' . $id . '/' . $redirect_page_num . '/#topicreply' . $reply_id);
                                 $data['hide_form'] = "true";
                             } else {
                                 // Fail
                                 $error[] = 'New Topic Reply Create Failed';
                             }
                         }
                         // End Form Complete Check
                     } else {
                         if ($data['action'] == "lock_topic" && ($data['is_admin'] == true || $data['is_mod'] == true)) {
                             // Update database with topic locked (2)
                             if ($this->model->updateTopicLockStatus($id, "2")) {
                                 SuccessHelper::push('You Have Successfully Locked This Topic', 'Topic/' . $id);
                             }
                         } else {
                             if ($data['action'] == "unlock_topic" && ($data['is_admin'] == true || $data['is_mod'] == true)) {
                                 // Update the database with topic unlocked (1)
                                 if ($this->model->updateTopicLockStatus($id, "1")) {
                                     SuccessHelper::push('You Have Successfully UnLocked This Topic', 'Topic/' . $id);
                                 }
                             } else {
                                 if ($data['action'] == "hide_topic" && ($data['is_admin'] == true || $data['is_mod'] == true)) {
                                     // Update database with topic hidden (TRUE)
                                     $hide_reason = Request::post('hide_reason');
                                     if ($this->model->updateTopicHideStatus($id, "FALSE", $u_id, $hide_reason)) {
                                         SuccessHelper::push('You Have Successfully Hidden This Topic', 'Topic/' . $id);
                                     }
                                 } else {
                                     if ($data['action'] == "unhide_topic" && ($data['is_admin'] == true || $data['is_mod'] == true)) {
                                         // Update the database with topic unhide (FALSE)
                                         if ($this->model->updateTopicHideStatus($id, "TRUE", $u_id, "UnHide")) {
                                             SuccessHelper::push('You Have Successfully UnHide This Topic', 'Topic/' . $id);
                                         }
                                     } else {
                                         if ($data['action'] == "hide_reply" && ($data['is_admin'] == true || $data['is_mod'] == true)) {
                                             // Update database with topic reply hidden (TRUE)
                                             $hide_reason = Request::post('hide_reason');
                                             $reply_id = Request::post('reply_id');
                                             $reply_url = Request::post('reply_url');
                                             if ($this->model->updateReplyHideStatus($reply_id, "FALSE", $u_id, $hide_reason)) {
                                                 SuccessHelper::push('You Have Successfully Hidden Topic Reply', $reply_url);
                                             }
                                         } else {
                                             if ($data['action'] == "unhide_reply" && ($data['is_admin'] == true || $data['is_mod'] == true)) {
                                                 // Update the database with topic reply unhide (FALSE)
                                                 $reply_id = Request::post('reply_id');
                                                 $reply_url = Request::post('reply_url');
                                                 if ($this->model->updateReplyHideStatus($reply_id, "TRUE", $u_id, "UnHide")) {
                                                     SuccessHelper::push('You Have Successfully UnHide Topic Reply', $reply_url);
                                                 }
                                             } else {
                                                 if ($data['action'] == "subscribe" && isset($u_id)) {
                                                     // Update users topic subcrition status as true
                                                     if ($this->model->updateTopicSubcrition($id, $u_id, "true")) {
                                                         SuccessHelper::push('You Have Successfully Subscribed to this Topic', 'Topic/' . $id);
                                                     }
                                                 } else {
                                                     if ($data['action'] == "unsubscribe" && isset($u_id)) {
                                                         // Update users topic subcrition status as false
                                                         if ($this->model->updateTopicSubcrition($id, $u_id, "false")) {
                                                             SuccessHelper::push('You Have Successfully UnSubscribed from this Topic', 'Topic/' . $id);
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             // End Action Check
         }
         // End token check
     }
     // End post check
     // Update and Get Views Data
     $data['PageViews'] = PageViews::views('true', $id, 'Forum_Topic', $u_id);
     // Get Recent Posts List for Sidebar
     $data['forum_recent_posts'] = $this->model->forum_recent_posts();
     // Setup Breadcrumbs
     $data['breadcrumbs'] = "\n  \t\t\t<li><a href='" . DIR . "'>Home</a></li>\n        <li><a href='" . DIR . "Forum'>" . $this->forum_title . "</a></li>\n        <li><a href='" . DIR . "Topics/{$topic_forum_id}'>" . $data['forum_cat'] . "</a>\n  \t\t\t<li class='active'>" . $data['title'] . "</li>\n  \t\t";
     // Ready the token!
     $data['csrf_token'] = Csrf::makeToken();
     // Send data to view
     View::renderTemplate('header', $data);
     View::renderModule('Forum/views/topic', $data, $error, $success);
     View::renderModule('Forum/views/forum_sidebar', $data);
     View::renderTemplate('footer', $data);
 }