" alt="" class="forum-logo"/></a>

    <p class="followers">
        <?php 
echo number_format($category['followers']);
?>
 follower<?php 
echo $category['followers'] > 1 ? "s" : "";
?>
    </p>

    <?php 
if ($userID = buckys_is_logged_in()) {
    ?>
        <?php 
    if (BuckysForumFollower::isFollow($category['categoryID'])) {
        ?>
            <?php 
        if ($userID != $category['creatorID']) {
            ?>
                <a href="/forum/category.php?action=unfollow&id=<?php 
            echo $category['categoryID'];
            ?>
&<?php 
            echo buckys_get_form_token();
            ?>
=1&return=<?php 
            echo base64_encode($_SERVER["REQUEST_URI"]);
            ?>
"
                    class="forum-action-button forum-action-button-inactive" <?php 
 /**
  * @param $categoryID
  * @param $applicants
  */
 public static function approveApplicants($categoryID, $applicants)
 {
     global $db;
     foreach ($applicants as $aid) {
         $query = $db->prepare("UPDATE " . TABLE_FORUM_MODERATORS . " SET `status`='Approved' WHERE categoryID=%d AND userID=%d", $categoryID, $aid);
         $db->query($query);
         //Make the user follow the forum
         if (!BuckysForumFollower::isFollow($categoryID, $aid)) {
             BuckysForumFollower::followForum($aid, $categoryID);
         }
     }
 }
require dirname(dirname(__FILE__)) . '/includes/bootstrap.php';
$categoryID = isset($_GET['id']) ? $_GET['id'] : 0;
if (isset($_REQUEST['action'])) {
    if ($_REQUEST['action'] == 'follow' || $_REQUEST['action'] == 'unfollow') {
        if (!($userID = buckys_is_logged_in()) && buckys_check_form_token('request')) {
            buckys_redirect(isset($_REQUEST['return']) ? base64_decode($_REQUEST['return']) : '/forum', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
        }
        $category = BuckysForumCategory::getCategory($categoryID);
        if (!$category || $_REQUEST['action'] == 'follow' && BuckysForumFollower::isFollow($category['categoryID'], $userID) || $_REQUEST['action'] == 'unfollow' && !BuckysForumFollower::isFollow($category['categoryID'], $userID) || $category['creatorID'] == $userID) {
            buckys_redirect(isset($_REQUEST['return']) ? base64_decode($_REQUEST['return']) : '/forum', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
        }
        if ($_REQUEST['action'] == 'follow') {
            BuckysForumFollower::followForum($userID, $categoryID);
            buckys_add_message(MSG_FOLLOW_FORUM_SUCCESS);
        } else {
            BuckysForumFollower::unfollowForum($userID, $categoryID);
            buckys_add_message(MSG_UNFOLLOW_FORUM_SUCCESS);
        }
        buckys_redirect(isset($_REQUEST['return']) ? base64_decode($_REQUEST['return']) : '/forum');
    }
}
$category = BuckysForumCategory::getCategory($categoryID);
if (!$category) {
    buckys_redirect('/forum');
}
//Getting Topics by category id
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'recent';
switch ($orderby) {
    case 'recent':
        $orderbyString = 'lastReplyDate DESC';
 /**
  * Create New Account
  *
  * @param Array $data
  * @return bool|int|null|string
  */
 public static function createNewAccount($data)
 {
     global $db;
     $data = array_map('trim', $data);
     if ($data['firstName'] == '' || $data['lastName'] == '') {
         buckys_add_message(MSG_USERNAME_EMPTY_ERROR, MSG_TYPE_ERROR);
         return false;
     }
     //Check Email Address
     if (!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\\._-]+)+\$/", $data['email'])) {
         buckys_add_message(MSG_INVALID_EMAIL, MSG_TYPE_ERROR);
         return false;
     }
     //Check Email Duplication
     if (BuckysUser::checkEmailDuplication($data['email'])) {
         //If this one is banned?
         if (BuckysUser::getUserStatus($data['email']) == BuckysUser::STATUS_USER_DELETED) {
             buckys_add_message(MSG_EMAIL_BANNED, MSG_TYPE_ERROR);
         } else {
             buckys_add_message(MSG_EMAIL_EXIST, MSG_TYPE_ERROR);
         }
         return false;
     }
     if (!$data['password'] || !$data['password2']) {
         buckys_add_message(MSG_EMPTY_PASSWORD, MSG_TYPE_ERROR);
         return false;
     }
     if ($data['password'] != $data['password2']) {
         buckys_add_message(MSG_NOT_MATCH_PASSWORD, MSG_TYPE_ERROR);
         return false;
     }
     if (!buckys_check_password_strength($data['password'])) {
         buckys_add_message(MSG_PASSWORD_STRENGTH_ERROR, MSG_TYPE_ERROR);
         return false;
     }
     //Create Token
     $token = md5(mt_rand(0, 99999) . time() . $data['email'] . mt_rand(0, 99999));
     $password = buckys_encrypt_password($data['password']);
     //Create New Account
     $newId = $db->insertFromArray(TABLE_USERS, ['firstName' => $data['firstName'], 'lastName' => $data['lastName'], 'email' => $data['email'], 'email_visibility' => -1, 'password' => $password, 'thumbnail' => '', 'user_type' => 'Registered', 'user_acl_id' => 2, 'ip_addr' => $_SERVER['REMOTE_ADDR'], 'created_date' => date('Y-m-d H:i:s'), 'token' => $token]);
     if (!$newId) {
         buckys_add_message($db->getLastError(), MSG_TYPE_ERROR);
         return false;
     }
     //Create New Record on the users_stats table
     $db->insertFromArray(TABLE_USERS_STATS, ['userID' => $newId, 'pageFollowers' => 0, 'likes' => 0, 'comments' => 0, 'voteUps' => 0, 'replies' => 0, 'reputation' => 0]);
     //Make new user to follow all categories
     BuckysForumFollower::followBasicForums($newId);
     $url_protocol = "http://";
     if (SITE_USING_SSL == true) {
         $url_protocol = "https://";
     }
     //Send an email to new user with a validation link
     $link = $url_protocol . $_SERVER['HTTP_HOST'] . "/register.php?action=verify&email=" . $data['email'] . "&token=" . $token;
     $title = "Please verify your account.";
     $body = "Dear " . $data['firstName'] . " " . $data['lastName'] . "\n\n" . "Thanks for your registration. \n" . "To complete your registration, please verify your email address by clicking the below link:. \n" . $link . "\n\n" . TNB_DOMAIN;
     buckys_sendmail($data['email'], $data['firstName'] . " " . $data['lastName'], $title, $body);
     return $newId;
 }
 /**
  * @param $id
  * @param $name
  * @param $description
  * @return bool|int|null|string
  */
 public static function saveCategory($id, $name, $description)
 {
     global $db;
     $userID = buckys_is_logged_in();
     if (!$id) {
         //New Category
         //Getting Sort Order
         $query = "SELECT max(sortOrder) FROM " . TABLE_FORUM_CATEGORIES . " WHERE parentID=" . USER_FORUM_CATEGORY;
         $sortOrder = $db->getVar($query);
         $sortOrder = !$sortOrder ? 1 : $sortOrder + 1;
         $query = $db->prepare("INSERT INTO " . TABLE_FORUM_CATEGORIES . "(`categoryName`, `description`,`sortOrder`, `creatorID`, `parentID`, `createdDate`)VALUES(%s, %s, %d, %d, %d, %s)", $name, $description, $sortOrder, $userID, USER_FORUM_CATEGORY, date("Y-m-d H:i:s"));
         $id = $db->insert($query);
         if (!$id) {
             buckys_add_message($db->last_error, MSG_TYPE_ERROR);
             return false;
         }
         //Make the user to follow this forum
         BuckysForumFollower::followForum($userID, $id);
     } else {
         $query = $db->prepare("UPDATE " . TABLE_FORUM_CATEGORIES . " SET `categoryName`=%s, `description`=%s  WHERE `categoryID`=%d", $name, $description, $id);
         $db->query($query);
     }
     return $id;
 }