Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(file_exists('./config/config.php'))
- {
- require_once './config/config.php';
- }
- else
- {
- require_once '../config/config.php';
- }
- class Database
- {
- var $conn;
- function __construct()
- {
- $this->conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT);
- if (mysqli_connect_errno())
- {
- die('Error connecting to database');
- }
- }
- function __construct1($dbhost, $dbuser, $dbpass, $dbname, $dbport=DB_PORT)
- {
- $this->conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname, $dbport);
- if (mysqli_connect_errno())
- {
- die('Error connecting to database');
- }
- }
- function close_db()
- {
- $this->conn->close();
- }
- function query($query)
- {
- return $this->conn->query($query);
- }
- /*
- * Checks whether the input string is banned.
- * This will check for:
- * 1. IP Addresses
- * 2. Usernames
- * 3. Email Addresses
- * Returns bool
- *
- * $option is the user's userid, username, ip address or email.
- */
- function is_banned($option)
- {
- if($this->is_exempt($option))
- {
- return false;
- }
- $option = $this->conn->real_escape_string($option);
- $query = "SELECT ban_id FROM `bans` WHERE user_id=(SELECT user_id FROM `users` WHERE username='$option') or ip_address='$option' or email='$option'";
- $result = $this->query($query);
- if(!$result or $result->num_rows < 1)
- {
- return false;
- }
- return true;
- }
- function is_exempt($option)
- {
- $option = $this->conn->real_escape_string($option);
- $query = "SELECT exempt_id FROM `exempts` WHERE user_id=(SELECT user_id FROM `users` WHERE username='$option') or ip_address='$option' or email='$option'";
- $result = $this->query($query);
- if(!$result or $result->num_rows < 1)
- {
- return false;
- }
- return true;
- }
- /*
- * Checks to see if a user's pin is defined.
- * Return true if yes
- * Return false if no
- */
- function pin_exists($pin)
- {
- $pin = $this->conn->real_escape_string($pin);
- $query = "SELECT user_id FROM `users` WHERE pin='$pin'";
- $result = $this->query($query);
- if(!$result or $result->num_rows < 1)
- {
- return false;
- }
- return true;
- }
- /*
- * Checks to see if a user's pin is banned.
- * Return true if yes
- * Return false if no
- */
- function pin_is_banned($pin)
- {
- $pin = $this->conn->real_escape_string($pin);
- $query = "SELECT ban_id FROM `bans` WHERE user_id=(SELECT user_id FROM `users` WHERE pin='$pin')";
- $result = $this->query($query);
- if(!$result or $result->num_rows < 1)
- {
- return false;
- }
- return true;
- }
- /*
- * Checks to see if a user's pin is valid (it exists and isn't banned).
- * Return true if yes
- * Return false if no
- */
- function pin_is_valid($pin)
- {
- return (bool)($this->pin_exists($pin) && !$this->pin_is_banned($pin));
- }
- //DOCUMENTATION IS COMING SOON FOR THE FUNCTIONS BELOW
- function username_exists($username)
- {
- $username = $this->conn->real_escape_string($username);
- $query = "SELECT user_id FROM `users` WHERE username='$username'";
- $result = $this->query($query);
- if(!$result or $result->num_rows < 1)
- {
- return false;
- }
- return true;
- }
- function user_id_exists($user_id)
- {
- $user_id = $this->conn->real_escape_string($user_id);
- $query = "SELECT username FROM `users` WHERE user_id='$user_id'";
- $result = $this->query($query);
- if(!$result or $result->num_rows < 1)
- {
- return false;
- }
- return true;
- }
- function get_inviter_id_from_invite_code($code)
- {
- $code = $this->conn->real_escape_string($code);
- $query = "SELECT creator_id FROM `invites` WHERE invite_code=$code";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- return $row['creator_id'];
- }
- }
- function create_user($first, $last, $username, $password, $email, $sec_quest, $sec_ans, $inviter_id, $privilege_level)
- {
- $first = $this->conn->real_escape_string($first);
- $last = $this->conn->real_escape_string($last);
- $salt = $this->create_salt();
- $username = $this->conn->real_escape_string($username);
- $password = hash('sha256', $salt. hash('sha256', $password));
- $email = $this->conn->real_escape_string($email);
- $sec_quest = $this->conn->real_escape_string($sec_quest);
- $sec_ans = hash('sha256', $salt. hash('sha256', $sec_ans));
- $inviter_id = $this->conn->real_escape_string($inviter_id);
- $privilege_level = $this->conn->real_escape_string($privilege_level);
- $pin = $this->generate_pin();
- $date = date('Y-m-d H:i:s');
- require_once './includes/database.php';
- $query = "INSERT INTO `users` VALUES(NULL,'$first','$last','$username','$password','$email','$sec_quest','$sec_ans','$inviter_id','$privilege_level','$date','$pin','0','0','2','$salt','0')";
- return $this->query($query);
- }
- private function create_salt()
- {
- $string = md5(uniqid(rand(), true));
- return substr($string, 0, 4);
- }
- private function generate_pin()
- {
- $num = rand(1000000000,9999999999);
- while($this->pin_exists($num))
- {
- $num = rand(1000000000,9999999999);
- }
- return $num;
- }
- function disable_invite_code($code)
- {
- $code = $this->conn->real_escape_string($code);
- $query = "ALTER `invites` SET used='TRUE' WHERE invite_code='$code'";
- return $this->query($query);
- }
- function get_salt_from_username($username)
- {
- $username = $this->conn->real_escape_string($username);
- $query = "SELECT salt FROM `users` WHERE username='$username'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- return $row['salt'];
- }
- }
- function check_password($username, $password)
- {
- $password = hash('sha256', $this->get_salt_from_username($username) . $password);
- $username = $this->conn->real_escape_string($username);
- $query = "SELECT user_id FROM `users` WHERE (username='$username' AND pass='$password')";
- $result = $this->query($query);
- if(!$result or $result->num_rows < 1)
- {
- return false;
- }
- return true;
- }
- function user_approval_denied($username)
- {
- $username = $this->conn->real_escape_string($username);
- $query = "SELECT approval_denied FROM `users` WHERE username='$username'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- return ($row['approval_denied'] == true);
- }
- }
- function user_is_approved($username)
- {
- $username = $this->conn->real_escape_string($username);
- $query = "SELECT privilege_level FROM `users` WHERE username='$username'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- return ($row['privilege_level'] > 0);
- }
- }
- function sec_ans_is_correct($username, $sec_ans)
- {
- $username = $this->conn->real_escape_string($username);
- $sec_ans = $this->conn->real_escape_string($sec_ans);
- $query = "SELECT user_id FROM `users` WHERE sec_answer='$sec_ans' AND username='$username'";
- $result = $this->query($query);
- if(!$result or $result->num_rows < 1)
- {
- return false;
- }
- return true;
- }
- function change_username_password($username, $password)
- {
- $password = hash('sha256', $this->get_salt_from_username($username) . hash('sha256', $password));
- $username = $this->conn->real_escape_string($username);
- $query = "UPDATE `users` SET pass='$password' WHERE username='$username'";
- $result = $this->query($query);
- return $result;
- }
- function get_email_from_username($username)
- {
- $username = $this->conn->real_escape_string($username);
- $query = "SELECT email FROM `users` WHERE username='$username'";
- $result = $this->query($query);
- if(!$result or $result->num_rows < 1)
- {
- return NULL;
- }
- $row = $result->fetch_assoc();
- return $row['email'];
- }
- function get_pin_from_username($username)
- {
- $username = $this->conn->real_escape_string($username);
- $query = "SELECT pin FROM `users` WHERE username='$username'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- $pin = $row['pin'];
- return $pin;
- }
- return 0;
- }
- function get_sec_quest_from_username($username)
- {
- $username = $this->conn->real_escape_string($username);
- $query = "SELECT sec_question FROM `users` WHERE username='$username'";
- $result = $this->query($query);
- if($result && $result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- $quest = $row['sec_question'];
- return $quest;
- }
- }
- function email_exists($email)
- {
- $email = $this->conn->real_escape_string($email);
- $query = "SELECT user_id FROM `users` WHERE email='$email'";
- $result = $this->query($query);
- if(!$result or $result->num_rows < 1)
- {
- return false;
- }
- return true;
- }
- function get_username_from_email($email)
- {
- $email = $this->conn->real_escape_string($email);
- $query = "SELECT username FROM `users` WHERE email='$email'";
- $result = $this->query($query);
- if($result && $result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- $username = $row['username'];
- return $username;
- }
- }
- function get_user_id_from_username($username)
- {
- $username = $this->conn->real_escape_string($username);
- $query = "SELECT user_id FROM `users` WHERE username='$username'";
- $result = $this->query($query);
- if($result && $result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- $user_id = $row['user_id'];
- return $user_id;
- }
- }
- function get_privilege_level_from_user_id($user_id)
- {
- $user_id = $this->conn->real_escape_string($user_id);
- $query = "SELECT privilege_level FROM `users` WHERE user_id='$user_id'";
- $result = $this->query($query);
- if($result && $result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- $privilege_level = $row['privilege_level'];
- return $privilege_level;
- }
- }
- function cookie_is_valid($cookie)
- {
- $cookie = $this->conn->real_escape_string($cookie);
- $query = "SELECT cookie_id FROM `cookies` WHERE value='$cookie'";
- $result = $this->query($query);
- if(!$result or $result->num_rows < 1)
- {
- return false;
- }
- return true;
- }
- function get_username_from_cookie($cookie)
- {
- $cookie = $this->conn->real_escape_string($cookie);
- $query = "SELECT username FROM `cookies` WHERE value='$cookie'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- return $row['username'];
- }
- }
- function add_cookie($cookie, $username)
- {
- $cookie = $this->conn->real_escape_string($cookie);
- $username = $this->conn->real_escape_string($username);
- $query = "INSERT INTO `cookies` VALUES(NULL, '$username', '$cookie')";
- return $this->query($query);
- }
- function delete_cookie($cookie)
- {
- $cookie = $this->conn->real_escape_string($cookie);
- $query = "DELETE FROM `cookies` WHERE value='$cookie'";
- return $this->query($query);
- }
- function record_user_login($user_id, $ip_address, $user_agent)
- {
- $user_id = $this->conn->real_escape_string($user_id);
- $ip_address = $this->conn->real_escape_string($ip_address);
- $date = $this->conn->real_escape_string(date('Y-m-d H:i:s'));
- $user_agent = $this->conn->real_escape_string($user_agent);
- $query = "INSERT INTO `logins` VALUES(NULL,'$user_id','$ip_address','$date','$user_agent')";
- return $this->query($query);
- }
- function get_login_id($user_id, $datetime) //useful for matching a pageview with a login session
- {
- $user_id = $this->conn->real_escape_string($user_id);
- $datetime = $this->conn->real_escape_string($datetime);
- $query = "SELECT login_id FROM `logins` ORDER BY date DESC WHERE (user_id='$user_id' AND datediff(ss,date,'$date')>0) LIMIT 1";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- return $row['login_id'];
- }
- }
- function record_page_view($user_id, $page_url)
- {
- $user_id = $this->conn->real_escape_string($user_id);
- $page_url = $this->conn->real_escape_string($page_url);
- $date = $this->conn->real_escape_string(date('Y-m-d H:i:s'));
- $query = "INSERT INTO `page_views` VALUES(NULL, '$user_id', '$date', '$page_url')";
- return $result = $this->query($query);
- }
- function upload_image($imagename, $description, $user_id)
- {
- $imagename = $this->conn->real_escape_string($imagename);
- $description = $this->conn->real_escape_string(strip_tags($description));
- $user_id = $this->conn->real_escape_string($user_id);
- $ip = $this->conn->real_escape_string($_SERVER['REMOTE_ADDR']);
- $date = $this->conn->real_escape_string(date("Y-m-d H:i:s", $_SERVER['REQUEST_TIME']));
- $query = "INSERT INTO images VALUES (NULL, '$user_id', '$ip', '$date', '$imagename', '$description', 0)";
- return $this->query($query);
- }
- function invite_code_exists($code)
- {
- $code = $this->conn->real_escape_string($code);
- $query = "SELECT invite_id FROM `invites` WHERE invite_code='$code'";
- $result = $this->query($query);
- if(!$result or $result->num_rows < 1)
- {
- return false;
- }
- return true;
- }
- function invite_code_used($code)
- {
- $code = $this->conn->real_escape_string($code);
- $query = "SELECT used FROM `invites` WHERE invite_code='$code'";
- $result = $this->query($query);
- if(!$result or $result->num_rows < 1)
- {
- return true;
- }
- return false;
- }
- function invite_code_expired($code)//add constant to avoid magic number
- {
- $code = $this->conn->real_escape_string($code);
- $query = "SELECT date FROM `invites` WHERE invite_code='$code'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- $date = $row['date'];
- }
- $date = DateTime($date);
- $interval = $date->diff(date('Y-m-d H:i:s'));
- if(((int)$interval->d) <= 3)
- {
- return false;
- }
- return true;
- }
- function get_article_info_from_invite($code)
- {
- $code = $this->conn->real_escape_string($code);
- $query = "SELECT article_url,article_title FROM `invites` WHERE invite_code='$code'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- return $row;
- }
- }
- function email_matches_invite($email, $invite)
- {
- $email = $this->conn->real_escape_string($email);
- $invite = $this->conn->real_escape_string($invite);
- $query = "SELECT invite_id FROM `invites` WHERE emailed_to='$email' AND invite_code='$invite'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- return true;
- }
- return false;
- }
- function invite_created_from_ip($ip)
- {
- $ip = $this->conn->real_escape_string($ip);
- $query = "SELECT invite_id FROM `invites` WHERE ip_created='$ip'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- return true;
- }
- return false;
- }
- function image_id_exists($id)
- {
- $id = $this->conn->real_escape_string($id);
- $query = "SELECT image_id FROM `images` WHERE image_id='$id'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- return true;
- }
- return false;
- }
- function get_image_score($image_id)
- {
- $image_id = $this->conn->real_escape_string($image_id);
- $query = "SELECT image_id='$image_id',SUM(vote) as vote_score FROM `image_votes` WHERE image_id='$image_id'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- if($row['vote_score'])
- {
- return $row['vote_score'];
- }
- else
- {
- return 0;
- }
- }
- }
- function get_image_info($image_id)
- {
- $image_id = $this->conn->real_escape_string($image_id);
- $query = "SELECT * FROM `images` WHERE image_id='$image_id'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- return $row;
- }
- }
- function get_image_views($image_id)
- {
- $image_id = $this->conn->real_escape_string($image_id);
- $query = "SELECT COUNT(view_id) page_views FROM `page_views` WHERE url LIKE '%/image.php?%id=$image_id%'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- return $row['page_views'];
- }
- }
- function delete_image($image_id)
- {
- $image_id = $this->conn->real_escape_string($image_id);
- $query = "UPDATE `images` SET deleted=TRUE WHERE image_id='$image_id'";
- return $this->query($query);
- }
- function undelete_image($image_id)
- {
- $image_id = $this->conn->real_escape_string($image_id);
- $query = "UPDATE `images` SET deleted=FALSE WHERE image_id='$image_id'";
- return $this->query($query);
- }
- function change_image_vote($image_id, $user_id, $vote)
- {
- $image_id = $this->conn->real_escape_string($image_id);
- $user_id = $this->conn->real_escape_string($user_id);
- $vote = $this->conn->real_escape_string($vote);
- $query = "UPDATE `image_votes` SET vote='$vote' WHERE (image_id='$image_id' AND user_id='$user_id')";
- return $this->query($query);
- }
- function add_image_vote($image_id, $user_id, $vote)
- {
- $image_id = $this->conn->real_escape_string($image_id);
- $user_id = $this->conn->real_escape_string($user_id);
- $vote = $this->conn->real_escape_string($vote);
- $date = $this->conn->real_escape_string(date('Y-m-d H:i:s'));
- $query = "INSERT INTO `image_votes` VALUES(NULL,'$user_id','$vote','$image_id', '$date')";
- return $this->query($query);
- }
- function image_vote_exists($image_id, $user_id)
- {
- $image_id = $this->conn->real_escape_string($image_id);
- $user_id = $this->conn->real_escape_string($user_id);
- $query = "SELECT vote_id FROM `image_votes` WHERE image_id='$image_id' AND user_id='$user_id'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- return true;
- }
- return false;
- }
- function user_has_up_voted($image_id, $user_id)
- {
- $image_id = $this->conn->real_escape_string($image_id);
- $user_id = $this->conn->real_escape_string($user_id);
- $query = "SELECT vote_id FROM `image_votes` WHERE (image_id='$image_id' AND user_id='$user_id') AND vote='1'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- return true;
- }
- return false;
- }
- function user_has_down_voted($image_id, $user_id)
- {
- $image_id = $this->conn->real_escape_string($image_id);
- $user_id = $this->conn->real_escape_string($user_id);
- $query = "SELECT vote_id FROM `image_votes` WHERE (image_id='$image_id' AND user_id='$user_id') AND vote='-1'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- return true;
- }
- return false;
- }
- function user_has_reported_image($image_id, $user_id)
- {
- $image_id = $this->conn->real_escape_string($image_id);
- $user_id = $this->conn->real_escape_string($user_id);
- $query = "SELECT report_id FROM `image_reports` WHERE image_id='$image_id' AND user_id='$user_id'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- return true;
- }
- return false;
- }
- function add_image_report($image_id, $user_id, $reason=NULL)
- {
- $image_id = $this->conn->real_escape_string($image_id);
- $user_id = $this->conn->real_escape_string($user_id);
- $reason = $this->conn->real_escape_string($reason);
- $date = $this->conn->real_escape_string(date('Y-m-d H:i:s'));
- $query = "INSERT INTO `image_reports` VALUES(NULL,'$user_id','$image_id', '$reason', '$date', 0, NULL)";
- return $this->query($query);
- }
- function get_number_images()
- {
- $query = "SELECT COUNT(*) AS image_count FROM `images` WHERE deleted=FALSE";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- return $row['image_count'];
- }
- }
- function submit_comment($commenter_id, $comment, $image_id)
- {
- $d = date("Y-m-d H:i:s", $_SERVER['REQUEST_TIME']);
- $commenter_id = $this->conn->real_escape_string($commenter_id);
- $comment = $this->conn->real_escape_string(strip_tags($comment));
- $image_id = $this->conn->real_escape_string($image_id);
- $query = "INSERT INTO comments VALUES (NULL, '$commenter_id', '$comment', 0, '$d', '$image_id')";
- return $this->query($query);
- }
- function get_comments($image_id)
- {
- $image_id = $this->conn->real_escape_string($image_id);
- $query = "SELECT * FROM `comments` WHERE image_id='$image_id'";
- $result = $this->query($query);
- $results = array();
- while ($temp = $result->fetch_assoc())
- {
- $results[] = $temp;
- }
- return array_reverse($results); // newest comments first
- }
- function get_user_invite_count($user_id)
- {
- $user_id = $this->conn->real_escape_string($user_id);
- $query = "SELECT current_number_invites FROM `users` WHERE user_id='$user_id'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- return $row['current_number_invites'];
- }
- }
- function add_invite($invite, $user_id, $ip_created, $date, $send_to, $article_title, $article_url)
- {
- $invite = $this->conn->real_escape_string($invite);
- $ip_created = $this->conn->real_escape_string($ip_created);
- $date = $this->conn->real_escape_string($date);
- $send_to = $this->conn->real_escape_string($send_to);
- $article_title = $this->conn->real_escape_string($article_title);
- $article_url = $this->conn->real_escape_string($article_url);
- $user_id = $this->conn->real_escape_string($user_id);
- $query = "INSERT INTO `invites` VALUES(NULL,'$user_id','$invite','$send_to','$date','0','$article_url','$article_title','$ip_created')";
- return $this->query($query);
- }
- function subtract_from_invite_count($user_id)
- {
- $user_id = $this->conn->real_escape_string($user_id);
- $query = "ALTER `users` SET current_number_invites=(current_number_invites - 1) WHERE user_id='$user_id'";
- return $this->query($query);
- }
- function comment_id_exists($id)
- {
- $id = $this->conn->real_escape_string($id);
- $query = "SELECT comment_id FROM `comments` WHERE comment_id='$id'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- return true;
- }
- return false;
- }
- function get_comment_info($comment_id)
- {
- $comment_id = $this->conn->real_escape_string($comment_id);
- $query = "SELECT * FROM `comments` WHERE comment_id='$comment_id'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- return $row;
- }
- }
- function delete_comment($comment_id)
- {
- $comment_id = $this->conn->real_escape_string($comment_id);
- $query = "UPDATE `comments` SET deleted=TRUE WHERE comment_id='$comment_id'";
- return $this->query($query);
- }
- function edit_comment($comment_id,$comment)
- {
- $comment_id = $this->conn->real_escape_string($comment_id);
- $comment = $this->conn->real_escape_string($comment);
- $query = "UPDATE `comments` SET comment='$comment' WHERE comment_id='$comment_id'";
- return $this->query($query);
- }
- function add_comment_report($comment_id, $user_id, $reason=NULL)
- {
- $comment_id = $this->conn->real_escape_string($comment_id);
- $user_id = $this->conn->real_escape_string($user_id);
- $reason = $this->conn->real_escape_string($reason);
- $date = $this->conn->real_escape_string(date('Y-m-d H:i:s'));
- $query = "INSERT INTO `comment_reports` VALUES(NULL,'$user_id','$comment_id', '$reason', '$date', 0, NULL)";
- return $this->query($query);
- }
- function get_number_comments($id, $id_type)
- {
- $id = $this->conn->real_escape_string($id);
- if($id_type == 'user_id')
- {
- $query = "SELECT COUNT(*) AS comment_count FROM `comments` WHERE (commenter_id='$id' AND deleted=FALSE)";
- }
- elseif($id_type == 'image_id')
- {
- $query = "SELECT COUNT(*) AS comment_count FROM `comments` WHERE (image_id='$id' AND deleted=FALSE)";
- }
- else
- {
- throw new Exception($id_type .' is not a valid $id_type');
- }
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- return $row['comment_count'];
- }
- }
- function get_username_from_user_id($user_id)
- {
- $user_id = $this->conn->real_escape_string($user_id);
- $query = "SELECT username FROM `users` WHERE user_id='$user_id'";
- $result = $this->query($query);
- if($result && $result->num_rows > 0)
- {
- $row = $result->fetch_assoc();
- $user_id = $row['username'];
- return $user_id;
- }
- }
- function user_has_reported_comment($comment_id, $user_id)
- {
- $comment_id = $this->conn->real_escape_string($comment_id);
- $user_id = $this->conn->real_escape_string($user_id);
- $query = "SELECT report_id FROM `comment_reports` WHERE comment_id='$comment_id' AND user_id='$user_id'";
- $result = $this->query($query);
- if($result->num_rows > 0)
- {
- return true;
- }
- return false;
- }
- }
- /* End of file database.php */
- /* Location: ./includes/database.php */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement