$mentions=$this->db->query('SELECT m.*, u.username, u.displayname FROM user_posts_mentions m LEFT JOIN users u ON m.mentionedUserID = u.ID WHERE postID = ?',[$postID])->result_array();
$hashtags=$this->db->query('SELECT * FROM user_posts_hashtags WHERE postID = ?',[$postID])->result_array();
$data=$this->db->query('SELECT * FROM user_posts_likes WHERE postID = (SELECT ID FROM user_posts WHERE uuid = ?) AND likerUserID = ?',[$post['uuid'],$userID])->result_array();
$this->db->cache_on();
if(empty($data)){
$post['userHasLiked']=FALSE;
}else{
$post['userHasLiked']=TRUE;
}
return$post;
}
privatefunctionmergeReplyData($post){
$data=$this->db->query('SELECT uuid, username, displayname FROM user_posts LEFT JOIN users ON users.ID = user_posts.user_id WHERE user_posts.ID = ?',[$post['reply_to']])->result_array();
$data=$this->db->query('SELECT * FROM user_posts WHERE user_id IN (SELECT followedUserID FROM user_followers WHERE followerUserID = ?) OR ID IN(SELECT postID FROM user_posts_mentions WHERE mentionedUserID = ?) OR ID IN (SELECT postID FROM user_posts_likes WHERE likedUserID = ?) OR user_id = ? ORDER BY date DESC LIMIT ? OFFSET ?',[$userID,$userID,$userID,$userID,$amount,$offset])->result_array();
$this->db->cache_on();
$data=$this->preparePostList($data);
return$data;
}
publicfunctiongetPopularPosts($amount,$offset)
{
$this->db->cache_off();
$data=$this->db->query('SELECT * FROM user_posts p ORDER BY ((SELECT count(*) FROM user_posts_likes WHERE postID = p.ID) + (SELECT count(*) FROM user_posts WHERE reply_to = p.ID)) DESC, date DESC LIMIT ? OFFSET ?',[$amount,$offset])->result_array();
$this->db->cache_on();
$data=$this->preparePostList($data);
return$data;
}
publicfunctiongetPostDetails($userID,$uuid)
{
$this->db->cache_off();
$data=$this->db->query('SELECT * FROM user_posts WHERE user_id = ? AND uuid = ?',[$userID,$uuid])->result_array();
$this->db->cache_on();
$data=$this->preparePostList($data);
return$data;
}
publicfunctiongetPostReplies($postID)
{
$this->db->cache_off();
$replies=$this->db->query('SELECT * FROM user_posts WHERE reply_to = ? ORDER BY date',[$postID])->result_array();
$data=$this->db->query('SELECT * FROM user_posts_likes WHERE postID = (SELECT ID FROM user_posts WHERE uuid = ?) AND likerUserID = ?',[$uuid,$userID])->result_array();
$this->db->cache_on();
// IDs needed for handling notifications later
$postUser=$this->db->query('SELECT ID FROM users WHERE ID = (SELECT user_id FROM user_posts WHERE uuid = ?)',[$uuid])->result_array();
$postID=$this->db->query('SELECT ID FROM user_posts WHERE uuid = ?',[$uuid])->result_array();
if(empty($data)){
$this->db->query('INSERT INTO user_posts_likes (postID, likedUserID, likerUserID) VALUES ((SELECT ID FROM user_posts WHERE uuid = ?), (SELECT user_id FROM user_posts WHERE uuid = ?), ?)',[$uuid,$uuid,$userID]);
$data=$this->db->query('SELECT count(*) likeCount FROM user_posts_likes WHERE postID = (SELECT ID FROM user_posts WHERE uuid = ?)',[$uuid])->result_array();
$this->db->cache_on();
return$data[0]['likeCount'];
}
publicfunctionisUUIDValid($uuid)
{
$this->db->cache_off();
$data=$this->db->query('SELECT ID FROM user_posts WHERE uuid = ?',[$uuid])->result_array();
$results=$this->db->query('SELECT * FROM user_posts WHERE content RLIKE ? OR (SELECT username FROM users WHERE ID = user_id) RLIKE ? ORDER BY (SELECT count(*) FROM user_posts_likes WHERE postID = ID) DESC, (SELECT count(*) FROM user_posts WHERE user_posts.reply_to = ID) DESC, date DESC LIMIT ? OFFSET ?',[$query,$query,$limit,$offset])->result_array();
$this->db->query('INSERT INTO user_posts_reports (postID, reason, reasonText) VALUES ((SELECT ID FROM user_posts WHERE uuid = ?), ?, ?)',[$uuid,$reason,$reasonText]);
$this->db->cache_delete('admin','reports');
// Send notification
$postID=$this->db->query('SELECT ID FROM user_posts WHERE uuid = ?',[$uuid])->result_array();