From 717b0cf27cd0833deee0a90d8cb652d67db18726 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sat, 10 Oct 2015 23:17:50 +0200 Subject: [PATCH] Huge Database refactor Signed-off-by: Flashwave --- .gitattributes | 20 -- _sakura/changelog.json | 30 ++ _sakura/components/Bans.php | 8 +- _sakura/components/Comments.php | 69 +++++ _sakura/components/Forum.php | 2 +- _sakura/components/Main.php | 34 +-- _sakura/components/News.php | 14 +- _sakura/components/Permissions.php | 39 +-- _sakura/components/Rank.php | 11 + _sakura/components/Sessions.php | 32 +- _sakura/components/Urls.php | 14 +- _sakura/components/User.php | 104 +++---- _sakura/components/Users.php | 220 +++++++------- _sakura/cron.php | 12 +- _sakura/sakura.php | 3 +- .../templates/broomcloset/global/master.tpl | 2 +- _sakura/templates/yuuno/elements/comment.tpl | 14 +- _sakura/templates/yuuno/elements/comments.tpl | 10 +- .../templates/yuuno/elements/indexPanel.tpl | 6 +- _sakura/templates/yuuno/elements/newsPost.tpl | 12 +- _sakura/templates/yuuno/forum/forumEntry.tpl | 2 +- _sakura/templates/yuuno/forum/posting.tpl | 4 +- _sakura/templates/yuuno/forum/topicEntry.tpl | 8 +- _sakura/templates/yuuno/forum/viewtopic.tpl | 18 +- _sakura/templates/yuuno/global/master.tpl | 10 +- _sakura/templates/yuuno/main/banned.tpl | 2 +- _sakura/templates/yuuno/main/faq.tpl | 10 +- _sakura/templates/yuuno/main/memberlist.tpl | 26 +- _sakura/templates/yuuno/main/news.tpl | 6 +- _sakura/templates/yuuno/main/profile.tpl | 28 +- .../templates/yuuno/main/supporttracker.tpl | 8 +- .../yuuno/settings/account.usertitle.tpl | 2 +- .../yuuno/settings/appearance.avatar.tpl | 2 +- .../yuuno/settings/appearance.background.tpl | 2 +- .../yuuno/settings/appearance.signature.tpl | 0 .../yuuno/settings/appearance.userpage.tpl | 2 +- .../yuuno/settings/friends.listing.tpl | 16 +- .../yuuno/settings/friends.requests.tpl | 16 +- .../templates/yuuno/settings/general.home.tpl | 26 +- .../yuuno/settings/general.options.tpl | 6 +- .../yuuno/settings/general.profile.tpl | 12 +- .../yuuno/settings/messages.inbox.tpl | 2 +- .../yuuno/settings/notifications.history.tpl | 30 +- database/data.sql | 137 ++++----- database/structure.sql | 282 +++++++++--------- integrations/SockChat.php | 4 +- public/.htaccess | 5 - public/authenticate.php | 2 +- public/browserconfig.xml | 11 +- public/imageserve.php | 18 +- public/index.php | 6 +- public/manage.php | 2 - public/manifest.json | 2 +- public/news.php | 18 +- public/settings.php | 121 +++++--- 55 files changed, 824 insertions(+), 678 deletions(-) create mode 100644 _sakura/components/Rank.php create mode 100644 _sakura/templates/yuuno/settings/appearance.signature.tpl diff --git a/.gitattributes b/.gitattributes index 412eeda..dfe0770 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,22 +1,2 @@ # Auto detect text files and perform LF normalization * text=auto - -# Custom for Visual Studio -*.cs diff=csharp -*.sln merge=union -*.csproj merge=union -*.vbproj merge=union -*.fsproj merge=union -*.dbproj merge=union - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain diff --git a/_sakura/changelog.json b/_sakura/changelog.json index 90962fa..e0bddd6 100644 --- a/_sakura/changelog.json +++ b/_sakura/changelog.json @@ -3064,6 +3064,36 @@ "type": "ADD", "change": "Added permissions to commenting.", "user": "Flashwave" + }, + { + "type": "FIX", + "change": "Fixed comment reply ID collision.", + "user": "Flashwave" + }, + { + "type": "ADD", + "change": "Added comment voting.", + "user": "Flashwave" + }, + { + "type": "UPD", + "change": "Cleaned up and uniform'd column names.", + "user": "Flashwave" + }, + { + "type": "FIX", + "change": "Fixed static urls in settings.", + "user": "Flashwave" + }, + { + "type": "FIX", + "change": "Fixed settings index friend count not working.", + "user": "Flashwave" + }, + { + "type": "ADD", + "change": "Added signature section to the settings page.", + "user": "Flashwave" } ] diff --git a/_sakura/components/Bans.php b/_sakura/components/Bans.php index c341616..231a0ed 100644 --- a/_sakura/components/Bans.php +++ b/_sakura/components/Bans.php @@ -12,7 +12,7 @@ class Bans { // Attempt to get a ban from this user - $bans = Database::fetch('bans', true, ['uid' => [$uid, '=']]); + $bans = Database::fetch('bans', true, ['user_id' => [$uid, '=']]); // Reverse the array so new bans are listed first $bans = array_reverse($bans); @@ -22,15 +22,15 @@ class Bans // Check if it hasn't expired if ($ban['ban_end'] != 0 && $ban['ban_end'] < time()) { // If it has delete the entry and continue - Database::delete('bans', ['id' => [$ban['uid'], '=']]); + Database::delete('bans', ['id' => [$ban['user_id'], '=']]); continue; } // Return the ban if all checks were passed return [ - 'user' => $ban['uid'], - 'issuer' => $ban['mod_uid'], + 'user' => $ban['user_id'], + 'issuer' => $ban['ban_moderator'], 'issued' => $ban['ban_begin'], 'expires' => $ban['ban_end'], 'reason' => $ban['ban_reason'], diff --git a/_sakura/components/Comments.php b/_sakura/components/Comments.php index b38a270..195c735 100644 --- a/_sakura/components/Comments.php +++ b/_sakura/components/Comments.php @@ -53,6 +53,20 @@ class Comments $comment['comment_poster'] = $this->commenters[$comment['comment_poster']]; $comment['comment_text'] = Main::parseEmotes(Main::cleanString($comment['comment_text'])); + // Get likes and dislikes + $votes = $this->getVotes($comment['comment_id']); + $comment['comment_likes'] = 0; + $comment['comment_dislikes'] = 0; + + // Store amount in their respective variables + foreach ($votes as $vote) { + if ($vote['vote_state']) { + $comment['comment_likes'] += 1; + } else { + $comment['comment_dislikes'] += 1; + } + } + // Add post to posts array $layer[$comment['comment_id']] = $comment; @@ -87,6 +101,17 @@ class Comments } + // Getting comment votes + public function getVotes($cid) + { + + // Get from database + return Database::fetch('comment_votes', true, [ + 'vote_comment' => [$cid, '='], + ]); + + } + // Creating public function makeComment($uid, $reply, $content) { @@ -115,6 +140,50 @@ class Comments } + // Voting + public function makeVote($uid, $cid, $mode) + { + + // Attempt to get previous vote + $vote = Database::fetch('comment_votes', false, [ + 'vote_user' => [$uid, '='], + 'vote_comment' => [$cid, '='], + ]); + + // Check if anything was returned + if ($vote) { + // Check if the vote that's being casted is the same + if ($vote['vote_state'] == $mode) { + // Delete the vote + Database::delete('comment_votes', [ + 'vote_user' => [$uid, '='], + 'vote_comment' => [$cid, '='], + ]); + } else { + // Otherwise update the vote + Database::update('comment_votes', [ + [ + 'vote_state' => $mode, + ], + [ + 'vote_user' => [$uid, '='], + 'vote_comment' => [$cid, '='], + ], + ]); + } + } else { + // Create a vote + Database::insert('comment_votes', [ + 'vote_user' => $uid, + 'vote_comment' => $cid, + 'vote_state' => $mode, + ]); + } + + return true; + + } + // Deleting public function removeComment($cid) { diff --git a/_sakura/components/Forum.php b/_sakura/components/Forum.php index c88f7db..8d594ad 100644 --- a/_sakura/components/Forum.php +++ b/_sakura/components/Forum.php @@ -259,7 +259,7 @@ class Forum 'user' => (new User($post['poster_id'])), 'elapsed' => Main::timeElapsed($post['post_time']), 'is_op' => ($post['poster_id'] == $firstPost['poster_id'] ? '1' : '0'), - 'parsed_post' => self::parseMarkUp($post['post_text'], $post['parse_mode'], $post['enable_emotes']), + 'parsed_post' => self::parseMarkUp($post['post_text'], $post['post_parse'], $post['post_emotes']), 'signature' => empty($_POSTER['userData']['signature']) ? '' : self::parseMarkUp( diff --git a/_sakura/components/Main.php b/_sakura/components/Main.php index 48bc493..d583a58 100644 --- a/_sakura/components/Main.php +++ b/_sakura/components/Main.php @@ -57,12 +57,12 @@ class Main // Split the regex $regex = array_map(function ($arr) { - return $arr['regex']; + return $arr['bbcode_regex']; }, $bbcodes); // Split the replacement $replace = array_map(function ($arr) { - return $arr['replace']; + return $arr['bbcode_replace']; }, $bbcodes); // Do the replacement @@ -145,7 +145,7 @@ class Main 'error_log', false, [ - 'backtrace' => [$backtrace, '=', true], + 'error_backtrace' => [$backtrace, '=', true], 'error_string' => [$errstr, '='], 'error_line' => [$errline, '='], ] @@ -159,14 +159,14 @@ class Main // Log the error Database::insert('error_log', [ - 'id' => $errid, - 'timestamp' => date("r"), - 'revision' => SAKURA_VERSION, + 'error_id' => $errid, + 'error_timestamp' => date("r"), + 'error_revision' => SAKURA_VERSION, 'error_type' => $errno, 'error_line' => $errline, 'error_string' => $errstr, 'error_file' => $errfile, - 'backtrace' => $backtrace, + 'error_backtrace' => $backtrace, ]); } @@ -382,7 +382,7 @@ class Main { // Get contents from the database - $infopage = Database::fetch('infopages', false, ['shorthand' => [$id, '=']]); + $infopage = Database::fetch('infopages', false, ['page_shorthand' => [$id, '=']]); // Return the data if there is any else just return false return count($infopage) ? $infopage : false; @@ -663,7 +663,7 @@ class Main { // Do database call - $faq = Database::fetch('faq', true, null, ['id']); + $faq = Database::fetch('faq', true, null, ['faq_id']); // Return FAQ data return $faq; @@ -783,7 +783,7 @@ class Main $data = []; // Get database stuff - $table = Database::fetch('premium_log', true, null, ['id', true]); + $table = Database::fetch('premium_log', true, null, ['transaction_id', true]); // Add raw table data to data array $data['table'] = $table; @@ -797,11 +797,11 @@ class Main // Calculate the thing foreach ($table as $row) { // Calculate balance - $data['balance'] = $data['balance'] + $row['amount']; + $data['balance'] = $data['balance'] + $row['transaction_amount']; // Add userdata to table - if (!array_key_exists($row['uid'], $data['users'])) { - $data['users'][$row['uid']] = new User($row['uid']); + if (!array_key_exists($row['user_id'], $data['users'])) { + $data['users'][$row['user_id']] = new User($row['user_id']); } } @@ -816,10 +816,10 @@ class Main Database::insert('premium_log', [ - 'uid' => $id, - 'amount' => $amount, - 'date' => time(), - 'comment' => $comment, + 'user_id' => $id, + 'transaction_amount' => $amount, + 'transaction_date' => time(), + 'transaction_comment' => $comment, ]); diff --git a/_sakura/components/News.php b/_sakura/components/News.php index 08f6429..7fbae6c 100644 --- a/_sakura/components/News.php +++ b/_sakura/components/News.php @@ -15,27 +15,27 @@ class News { // Get the news posts and assign them to $posts - $posts = Database::fetch('news', true, ['category' => [$category, '=']], ['id', true]); + $posts = Database::fetch('news', true, ['news_category' => [$category, '=']], ['news_id', true]); // Attach poster data foreach ($posts as $post) { // Check if we already have an object for this user - if (!array_key_exists($post['uid'], $this->posters)) { + if (!array_key_exists($post['user_id'], $this->posters)) { // Create new object - $this->posters[$post['uid']] = new User($post['uid']); + $this->posters[$post['user_id']] = new User($post['user_id']); } // Parse the news post - $post['content_parsed'] = Main::mdParse($post['content']); + $post['news_content_parsed'] = Main::mdParse($post['news_content']); // Attach the poster - $post['poster'] = $this->posters[$post['uid']]; + $post['news_poster'] = $this->posters[$post['user_id']]; // Load comments - $post['comments'] = $this->comments = new Comments('news-' . $category . '-' . $post['id']); + $post['news_comments'] = $this->comments = new Comments('news-' . $category . '-' . $post['news_id']); // Add post to posts array - $this->posts[$post['id']] = $post; + $this->posts[$post['news_id']] = $post; } } diff --git a/_sakura/components/Permissions.php b/_sakura/components/Permissions.php index fed4e5a..8b2d05b 100644 --- a/_sakura/components/Permissions.php +++ b/_sakura/components/Permissions.php @@ -10,12 +10,12 @@ class Permissions // Fallback permission data private static $fallback = [ - 'rid' => 0, - 'uid' => 0, - 'siteperms' => 1, - 'manageperms' => 0, - 'forumperms' => 0, - 'rankinherit' => 111, + 'rank_id' => 0, + 'user_id' => 0, + 'permissions_site' => 1, + 'permissions_manage' => 0, + 'permissions_forums' => 0, + 'permissions_inherit' => 111, ]; @@ -56,6 +56,7 @@ class Permissions 'CREATE_COMMENTS' => 268435456, // User can make comments 'DELETE_COMMENTS' => 536870912, // User can delete own comments 'VOTE_COMMENTS' => 1073741824, // User can vote on comments + 'CHANGE_SIGNATURE' => 2147483648, // User can vote on comments ], @@ -111,7 +112,7 @@ class Permissions // Get permission row for all ranks foreach ($ranks as $rank) { - $getRanks[] = Database::fetch('permissions', false, ['rid' => [$rank, '='], 'uid' => [0, '=']]); + $getRanks[] = Database::fetch('permissions', false, ['rank_id' => [$rank, '='], 'user_id' => [0, '=']]); } // Check if getRanks is empty or if the rank id is 0 return the fallback @@ -126,18 +127,18 @@ class Permissions // Store the data of the current rank in $perms $perms = [ - 'SITE' => $rank['siteperms'], - 'MANAGE' => $rank['manageperms'], - 'FORUM' => $rank['forumperms'], + 'SITE' => $rank['permissions_site'], + 'MANAGE' => $rank['permissions_manage'], + 'FORUM' => $rank['permissions_forums'], ]; } else { // Perform a bitwise OR on the ranks $perms = [ - 'SITE' => $perms['SITE'] | $rank['siteperms'], - 'MANAGE' => $perms['MANAGE'] | $rank['manageperms'], - 'FORUM' => $perms['FORUM'] | $rank['forumperms'], + 'SITE' => $perms['SITE'] | $rank['permissions_site'], + 'MANAGE' => $perms['MANAGE'] | $rank['permissions_manage'], + 'FORUM' => $perms['FORUM'] | $rank['permissions_forums'], ]; } @@ -156,10 +157,10 @@ class Permissions $user = new User($uid); // Attempt to get the permission row of a user - $userPerms = Database::fetch('permissions', false, ['rid' => [0, '='], 'uid' => [$user->data['id'], '=']]); + $userPerms = Database::fetch('permissions', false, ['rank_id' => [0, '='], 'user_id' => [$user->data['user_id'], '=']]); // Get their rank permissions - $rankPerms = self::getRankPermissions(json_decode($user->data['ranks'], true)); + $rankPerms = self::getRankPermissions(json_decode($user->data['user_ranks'], true)); // Just return the rank permissions if no special ones are set if (empty($userPerms)) { @@ -167,21 +168,21 @@ class Permissions } // Split the inherit option things up - $inheritance = str_split($userPerms['rankinherit']); + $inheritance = str_split($userPerms['permissions_inherit']); // Override site permissions if (!$inheritance[0]) { - $rankPerms['SITE'] = $userPerms['siteperms']; + $rankPerms['SITE'] = $userPerms['permissions_site']; } // Override management permissions if (!$inheritance[1]) { - $rankPerms['MANAGE'] = $userPerms['manageperms']; + $rankPerms['MANAGE'] = $userPerms['permissions_manage']; } // Override forum permissions if (!$inheritance[2]) { - $rankPerms['FORUM'] = $userPerms['forumperms']; + $rankPerms['FORUM'] = $userPerms['permissions_forums']; } // Return permissions diff --git a/_sakura/components/Rank.php b/_sakura/components/Rank.php new file mode 100644 index 0000000..add8c94 --- /dev/null +++ b/_sakura/components/Rank.php @@ -0,0 +1,11 @@ + Main::getRemoteIP(), - 'useragent' => Main::cleanString($_SERVER['HTTP_USER_AGENT']), - 'userid' => $userId, - 'skey' => $session, - 'started' => time(), - 'expire' => time() + 604800, - 'remember' => $remember ? '1' : '0', + 'user_id' => $userId, + 'user_ip' => Main::getRemoteIP(), + 'user_agent' => Main::cleanString($_SERVER['HTTP_USER_AGENT']), + 'session_key' => $session, + 'session_start' => time(), + 'session_expire' => time() + 604800, + 'session_remember' => $remember ? '1' : '0', ]); // Return the session key @@ -62,7 +62,7 @@ class Session { // Get session from database - $session = Database::fetch('sessions', true, ['userid' => [$userId, '='], 'skey' => [$sessionId, '=']]); + $session = Database::fetch('sessions', true, ['user_id' => [$userId, '='], 'session_key' => [$sessionId, '=']]); // Check if we actually got something in return if (!count($session)) { @@ -72,9 +72,9 @@ class Session $session = $session[0]; // Check if the session expired - if ($session['expire'] < time()) { + if ($session['session_expire'] < time()) { // If it is delete the session... - self::deleteSession($session['id']); + self::deleteSession($session['session_id']); // ...and return false return false; @@ -83,7 +83,7 @@ class Session // Origin checking if ($ipCheck = Configuration::getConfig('session_check')) { // Split both IPs up - $sessionIP = explode('.', $session['userip']); + $sessionIP = explode('.', $session['user_ip']); $userIP = explode('.', Main::getRemoteIP()); // Take 1 off the ipCheck variable so it's equal to the array keys @@ -124,12 +124,12 @@ class Session } // If the remember flag is set extend the session time - if ($session['remember']) { - Database::update('sessions', [['expire' => time() + 604800], ['id' => [$session['id'], '=']]]); + if ($session['session_remember']) { + Database::update('sessions', [['session_expire' => time() + 604800], ['session_id' => [$session['session_id'], '=']]]); } // Return 2 if the remember flag is set and return 1 if not - return $session['remember'] ? 2 : 1; + return $session['session_remember'] ? 2 : 1; } @@ -138,12 +138,12 @@ class Session { // Check if the session exists - if (!Database::fetch('sessions', [($key ? 'skey' : 'id'), true, [$sessionId, '=']])) { + if (!Database::fetch('sessions', [($key ? 'session_key' : 'session_id'), true, [$sessionId, '=']])) { return false; } // Run the query - Database::delete('sessions', [($key ? 'skey' : 'id') => [$sessionId, '=']]); + Database::delete('sessions', [($key ? 'session_key' : 'session_id') => [$sessionId, '=']]); // Return true if key was found and deleted return true; diff --git a/_sakura/components/Urls.php b/_sakura/components/Urls.php index 8a380eb..37abc14 100644 --- a/_sakura/components/Urls.php +++ b/_sakura/components/Urls.php @@ -205,6 +205,10 @@ class Urls '/settings.php?cat=%s&mode=%s', '/settings/%s/%s', ], + 'SETTING_PAGE' => [ + '/settings.php?cat=%s&mode=%s&page=%u', + '/settings/%s/%s/p%u', + ], // Friend Actions 'FRIEND_ACTION' => [ @@ -239,13 +243,9 @@ class Urls '/settings.php?comment-action=true', '/comments', ], - 'COMMENT_LIKE' => [ - '/settings.php?comment-action=true&id=%u&mode=like&session=%s', - '/comments?id=%u&mode=like&session=%s', - ], - 'COMMENT_DISLIKE' => [ - '/settings.php?comment-action=true&id=%u&mode=dislike&session=%s', - '/comments?id=%u&mode=dislike&session=%s', + 'COMMENT_VOTE' => [ + '/settings.php?comment-action=true&id=%u&mode=vote&state=%u&category=%s&session=%s', + '/comments?id=%u&mode=vote&state=%u&category=%s&session=%s', ], 'COMMENT_DELETE' => [ '/settings.php?comment-action=true&id=%u&category=%s&mode=delete&session=%s', diff --git a/_sakura/components/User.php b/_sakura/components/User.php index e37de3b..176c38c 100644 --- a/_sakura/components/User.php +++ b/_sakura/components/User.php @@ -21,7 +21,7 @@ class User 'users', false, [ - 'id' => [$uid, '=', true], + 'user_id' => [$uid, '=', true], 'username_clean' => [Main::cleanString($uid, true), '=', true], ] ); @@ -43,16 +43,16 @@ class User $this->data = Users::$emptyUser; } - // Decode the json in the userData column - $this->data['userData'] = json_decode(!empty($this->data['userData']) ? $this->data['userData'] : '[]', true); + // Decode the json in the user_data column + $this->data['user_data'] = json_decode(!empty($this->data['user_data']) ? $this->data['user_data'] : '[]', true); // Decode the ranks json array - $ranks = json_decode($this->data['ranks'], true); + $ranks = json_decode($this->data['user_ranks'], true); // Get the rows for all the ranks foreach ($ranks as $rank) { // Store the database row in the array - $this->ranks[$rank] = Database::fetch('ranks', false, ['id' => [$rank, '=']]); + $this->ranks[$rank] = Database::fetch('ranks', false, ['rank_id' => [$rank, '=']]); } // Check if ranks were set @@ -75,7 +75,7 @@ class User { // Check if the main rank is the specified rank - if (in_array($this->mainRank['id'], $ranks)) { + if (in_array($this->mainRank['rank_id'], $ranks)) { return true; } @@ -96,7 +96,7 @@ class User public function colour() { - return empty($this->data['name_colour']) ? $this->mainRank['colour'] : $this->data['name_colour']; + return empty($this->data['user_colour']) ? $this->mainRank['rank_colour'] : $this->data['user_colour']; } @@ -104,7 +104,7 @@ class User public function userTitle() { - return empty($this->data['usertitle']) ? $this->mainRank['title'] : $this->data['usertitle']; + return empty($this->data['user_title']) ? $this->mainRank['rank_title'] : $this->data['user_title']; } @@ -114,8 +114,8 @@ class User return [ - 'long' => Main::getCountryName($this->data['country']), - 'short' => $this->data['country'], + 'long' => Main::getCountryName($this->data['user_country']), + 'short' => $this->data['user_country'], ]; @@ -125,7 +125,7 @@ class User public function checkOnline() { - return $this->data['lastdate'] > (time() - Configuration::getConfig('max_online_time')); + return $this->data['user_last_online'] > (time() - Configuration::getConfig('max_online_time')); } @@ -133,7 +133,7 @@ class User public function forumStats() { - return Forum::getUserStats($this->data['id']); + return Forum::getUserStats($this->data['user_id']); } @@ -141,7 +141,7 @@ class User public function checkFriends($with) { - return Users::checkFriend($this->data['id'], $with); + return Users::checkFriend($this->data['user_id'], $with); } @@ -149,7 +149,7 @@ class User public function getFriends($timestamps = false, $getData = false, $checkOnline = false) { - return Users::getFriends($this->data['id'], $timestamps, $getData, $checkOnline); + return Users::getFriends($this->data['user_id'], $timestamps, $getData, $checkOnline); } @@ -157,7 +157,7 @@ class User public function checkBan() { - return Bans::checkBan($this->data['id']); + return Bans::checkBan($this->data['user_id']); } @@ -165,7 +165,7 @@ class User public function checkPermission($layer, $action) { - return Permissions::check($layer, $action, $this->data['id'], 1); + return Permissions::check($layer, $action, $this->data['user_id'], 1); } @@ -173,7 +173,7 @@ class User public function profileComments() { - return new Comments('profile-' . $this->data['id']); + return new Comments('profile-' . $this->data['user_id']); } @@ -183,9 +183,9 @@ class User return [ - 'joined' => Main::timeElapsed($this->data['regdate'], $append, $none), - 'lastOnline' => Main::timeElapsed($this->data['lastdate'], $append, $none), - 'birth' => Main::timeElapsed(strtotime($this->data['birthday']), $append, $none), + 'joined' => Main::timeElapsed($this->data['user_registered'], $append, $none), + 'lastOnline' => Main::timeElapsed($this->data['user_last_online'], $append, $none), + 'birth' => Main::timeElapsed(strtotime($this->data['user_birthday']), $append, $none), ]; @@ -204,7 +204,7 @@ class User } // Once again if nothing was returned just return null - if (empty($this->data['userData']['profileFields'])) { + if (empty($this->data['user_data']['profileFields'])) { return; } @@ -214,42 +214,42 @@ class User // Check if profile fields aren't fake foreach ($profileFields as $field) { // Completely strip all special characters from the field name - $fieldName = Main::cleanString($field['name'], true, true); + $fieldName = Main::cleanString($field['field_name'], true, true); // Check if the user has the current field set otherwise continue - if (!array_key_exists($fieldName, $this->data['userData']['profileFields'])) { + if (!array_key_exists($fieldName, $this->data['user_data']['profileFields'])) { continue; } // Assign field to output with value $profile[$fieldName] = array(); - $profile[$fieldName]['name'] = $field['name']; - $profile[$fieldName]['value'] = $this->data['userData']['profileFields'][$fieldName]; - $profile[$fieldName]['islink'] = $field['islink']; + $profile[$fieldName]['name'] = $field['field_name']; + $profile[$fieldName]['value'] = $this->data['user_data']['profileFields'][$fieldName]; + $profile[$fieldName]['islink'] = $field['field_link']; // If the field is set to be a link add a value for that as well - if ($field['islink']) { + if ($field['field_link']) { $profile[$fieldName]['link'] = str_replace( '{{ VAL }}', - $this->data['userData']['profileFields'][$fieldName], - $field['linkformat'] + $this->data['user_data']['profileFields'][$fieldName], + $field['field_linkformat'] ); } // Check if we have additional options as well - if ($field['additional'] != null) { + if ($field['field_additional'] != null) { // Decode the json of the additional stuff - $additional = json_decode($field['additional'], true); + $additional = json_decode($field['field_additional'], true); // Go over all additional forms foreach ($additional as $subName => $subField) { // Check if the user has the current field set otherwise continue - if (!array_key_exists($subName, $this->data['userData']['profileFields'])) { + if (!array_key_exists($subName, $this->data['user_data']['profileFields'])) { continue; } // Assign field to output with value - $profile[$fieldName][$subName] = $this->data['userData']['profileFields'][$subName]; + $profile[$fieldName][$subName] = $this->data['user_data']['profileFields'][$subName]; } } } @@ -272,7 +272,7 @@ class User } // Once again if nothing was returned just return null - if (empty($this->data['userData']['userOptions'])) { + if (empty($this->data['user_data']['userOptions'])) { return; } @@ -282,17 +282,17 @@ class User // Check if profile fields aren't fake foreach ($optionFields as $field) { // Check if the user has the current field set otherwise continue - if (!array_key_exists($field['id'], $this->data['userData']['userOptions'])) { + if (!array_key_exists($field['option_id'], $this->data['user_data']['userOptions'])) { continue; } // Make sure the user has the proper permissions to use this option - if (!$this->checkPermission('SITE', $field['require_perm'])) { + if (!$this->checkPermission('SITE', $field['option_permission'])) { continue; } // Assign field to output with value - $options[$field['id']] = $this->data['userData']['userOptions'][$field['id']]; + $options[$field['option_id']] = $this->data['user_data']['userOptions'][$field['option_id']]; } // Return appropiate profile data @@ -305,13 +305,13 @@ class User { // Check if the user has static premium - if (Permissions::check('SITE', 'STATIC_PREMIUM', $this->data['id'], 1)) { + if (Permissions::check('SITE', 'STATIC_PREMIUM', $this->data['user_id'], 1)) { return [2, 0, time() + 1]; } // Attempt to retrieve the premium record from the database $getRecord = Database::fetch('premium', false, [ - 'uid' => [$this->data['id'], '='], + 'user_id' => [$this->data['user_id'], '='], ]); // If nothing was returned just return false @@ -320,14 +320,14 @@ class User } // Check if the Tenshi hasn't expired - if ($getRecord['expiredate'] < time()) { - Users::removeUserPremium($this->data['id']); - Users::updatePremiumMeta($this->data['id']); - return [0, $getRecord['startdate'], $getRecord['expiredate']]; + if ($getRecord['premium_expire'] < time()) { + Users::removeUserPremium($this->data['user_id']); + Users::updatePremiumMeta($this->data['user_id']); + return [0, $getRecord['premium_start'], $getRecord['premium_expire']]; } // Else return the start and expiration date - return [1, $getRecord['startdate'], $getRecord['expiredate']]; + return [1, $getRecord['premium_start'], $getRecord['premium_expire']]; } @@ -337,7 +337,7 @@ class User // Do the database query $warnings = Database::fetch('warnings', true, [ - 'uid' => [$this->data['id'], '='], + 'user_id' => [$this->data['user_id'], '='], ]); // Return all the warnings @@ -349,10 +349,10 @@ class User public function userPage() { - return isset($this->data['userData']['userPage']) ? + return isset($this->data['user_data']['userPage']) ? Main::mdParse( base64_decode( - $this->data['userData']['userPage'] + $this->data['user_data']['userPage'] ), true ) : @@ -366,7 +366,7 @@ class User // Do the database query $changes = Database::fetch('username_history', true, [ - 'user_id' => [$this->data['id'], '='], + 'user_id' => [$this->data['user_id'], '='], ], ['change_id', true]); // Return all the warnings @@ -415,7 +415,7 @@ class User // Insert into username_history table Database::insert('username_history', [ 'change_time' => time(), - 'user_id' => $this->data['id'], + 'user_id' => $this->data['user_id'], 'username_new' => $username, 'username_new_clean' => $username_clean, 'username_old' => $this->data['username'], @@ -429,7 +429,7 @@ class User 'username_clean' => $username_clean, ], [ - 'id' => [$this->data['id'], '='], + 'id' => [$this->data['user_id'], '='], ], ]); @@ -463,7 +463,7 @@ class User 'email' => $email, ], [ - 'id' => [$this->data['id'], '='], + 'id' => [$this->data['user_id'], '='], ], ]); @@ -517,7 +517,7 @@ class User 'password_chan' => time(), ], [ - 'id' => [$this->data['id'], '='], + 'id' => [$this->data['user_id'], '='], ], ]); diff --git a/_sakura/components/Users.php b/_sakura/components/Users.php index 563e214..628da8c 100644 --- a/_sakura/components/Users.php +++ b/_sakura/components/Users.php @@ -32,16 +32,18 @@ class Users 'birthday' => '', 'posts' => 0, 'country' => 'XX', - 'userData' => '[]', + 'user_data' => '[]', ]; // Empty rank template public static $emptyRank = [ - 'id' => 0, - 'rankname' => 'Sakura Rank', - 'multi' => 0, - 'colour' => '#444', - 'description' => 'A hardcoded dummy rank for fallback.', + 'rank_id' => 0, + 'rank_name' => 'Sakura Rank', + 'rank_multiple' => null, + 'rank_hidden' => 1, + 'rank_colour' => '#444', + 'rank_description' => 'A hardcoded dummy rank for fallback.', + 'rank_title' => '', ]; // Check if a user is logged in @@ -115,10 +117,10 @@ class Users // Update last online Database::update('users', [ [ - 'lastdate' => time(), + 'user_last_online' => time(), ], [ - 'id' => [$uid, '='], + 'user_id' => [$uid, '='], ], ]); @@ -324,17 +326,17 @@ class Users 'password_iter' => $password[1], 'email' => $emailClean, 'rank_main' => $userRank[0], - 'ranks' => $userRankJson, + 'user_ranks' => $userRankJson, 'register_ip' => Main::getRemoteIP(), 'last_ip' => Main::getRemoteIP(), - 'regdate' => time(), - 'lastdate' => 0, - 'country' => Main::getCountryCode(), - 'userData' => '[]', + 'user_registered' => time(), + 'user_last_online' => 0, + 'user_country' => Main::getCountryCode(), + 'user_data' => '[]', ]); // Get userid of the new user - $uid = Database::fetch('users', false, ['username_clean' => [$usernameClean, '=']])['id']; + $uid = Database::fetch('users', false, ['username_clean' => [$usernameClean, '=']])['user_id']; // Check if we require e-mail activation if ($requireActive) { @@ -378,12 +380,12 @@ class Users } // Check if the user has the required privs to log in - if (Permissions::check('SITE', 'DEACTIVATED', $user['id'], 1)) { + if (Permissions::check('SITE', 'DEACTIVATED', $user['user_id'], 1)) { return [0, 'NOT_ALLOWED']; } // Generate the verification key - $verk = Main::newActionCode('LOST_PASS', $user['id'], [ + $verk = Main::newActionCode('LOST_PASS', $user['user_id'], [ 'meta' => [ 'password_change' => 1, ], @@ -396,9 +398,9 @@ class Users $message = "Hello " . $user['username'] . ",\r\n\r\n"; $message .= "You are receiving this notification because you have (or someone pretending to be you has) requested a password reset link to be sent for your account on \"" . Configuration::getConfig('sitename') . "\". If you did not request this notification then please ignore it, if you keep receiving it please contact the site administrator.\r\n\r\n"; $message .= "To use this password reset key you need to go to a special page. To do this click the link provided below.\r\n\r\n"; - $message .= "http://" . Configuration::getConfig('url_main') . $urls->format('SITE_FORGOT_PASSWORD') . "?pw=true&uid=" . $user['id'] . "&key=" . $verk . "\r\n\r\n"; + $message .= "http://" . Configuration::getConfig('url_main') . $urls->format('SITE_FORGOT_PASSWORD') . "?pw=true&uid=" . $user['user_id'] . "&key=" . $verk . "\r\n\r\n"; $message .= "If successful you should be able to change your password here.\r\n\r\n"; - $message .= "Alternatively if the above method fails for some reason you can go to http://" . Configuration::getConfig('url_main') . $urls->format('SITE_FORGOT_PASSWORD') . "?pw=true&uid=" . $user['id'] . " and use the key listed below:\r\n\r\n"; + $message .= "Alternatively if the above method fails for some reason you can go to http://" . Configuration::getConfig('url_main') . $urls->format('SITE_FORGOT_PASSWORD') . "?pw=true&uid=" . $user['user_id'] . " and use the key listed below:\r\n\r\n"; $message .= "Verification key: " . $verk . "\r\n\r\n"; $message .= "You can of course change this password yourself via the profile page. If you have any difficulties please contact the site administrator.\r\n\r\n"; $message .= "--\r\n\r\nThanks\r\n\r\n" . Configuration::getConfig('mail_signature'); @@ -452,7 +454,7 @@ class Users 'password_chan' => $time, ], [ - 'id' => [$uid, '='], + 'user_id' => [$uid, '='], ], ]); @@ -486,12 +488,12 @@ class Users } // Check if a user is activated - if (!Permissions::check('SITE', 'DEACTIVATED', $user['id'], 1)) { + if (!Permissions::check('SITE', 'DEACTIVATED', $user['user_id'], 1)) { return [0, 'USER_ALREADY_ACTIVE']; } // Send activation e-mail - self::sendActivationMail($user['id']); + self::sendActivationMail($user['user_id']); // Return success return [1, 'SUCCESS']; @@ -503,10 +505,10 @@ class Users { // Get the user data - $user = Database::fetch('users', false, ['id' => [$uid, '=']]); + $user = Database::fetch('users', false, ['user_id' => [$uid, '=']]); // User is already activated or doesn't even exist - if (count($user) < 2 || !Permissions::check('SITE', 'DEACTIVATED', $user['id'], 1)) { + if (count($user) < 2 || !Permissions::check('SITE', 'DEACTIVATED', $user['user_id'], 1)) { return false; } @@ -514,7 +516,7 @@ class Users $activate = ($customKey ? $customKey : Main::newActionCode('ACTIVATE', $uid, [ 'user' => [ 'rank_main' => 2, - 'ranks' => json_encode([2]), + 'user_ranks' => json_encode([2]), ], ])); @@ -526,10 +528,10 @@ class Users $message .= "Please keep this e-mail for your records. Your account intormation is as follows:\r\n\r\n"; $message .= "----------------------------\r\n\r\n"; $message .= "Username: " . $user['username'] . "\r\n\r\n"; - $message .= "Your profile: http://" . Configuration::getConfig('url_main') . $urls->format('USER_PROFILE', [$user['id']]) . "\r\n\r\n"; + $message .= "Your profile: http://" . Configuration::getConfig('url_main') . $urls->format('USER_PROFILE', [$user['user_id']]) . "\r\n\r\n"; $message .= "----------------------------\r\n\r\n"; $message .= "Please visit the following link in order to activate your account:\r\n\r\n"; - $message .= "http://" . Configuration::getConfig('url_main') . $urls->format('SITE_ACTIVATE') . "?mode=activate&u=" . $user['id'] . "&k=" . $activate . "\r\n\r\n"; + $message .= "http://" . Configuration::getConfig('url_main') . $urls->format('SITE_ACTIVATE') . "?mode=activate&u=" . $user['user_id'] . "&k=" . $activate . "\r\n\r\n"; $message .= "Your password has been securely stored in our database and cannot be retrieved. "; $message .= "In the event that it is forgotten, you will be able to reset it using the email address associated with your account.\r\n\r\n"; $message .= "Thank you for registering.\r\n\r\n"; @@ -554,7 +556,7 @@ class Users { // Get the user data - $user = Database::fetch('users', false, ['id' => [$uid, '=']]); + $user = Database::fetch('users', false, ['user_id' => [$uid, '=']]); // Check if user exists if (!count($user) > 1) { @@ -562,7 +564,7 @@ class Users } // Check if user is already activated - if (!Permissions::check('SITE', 'DEACTIVATED', $user['id'], 1)) { + if (!Permissions::check('SITE', 'DEACTIVATED', $user['user_id'], 1)) { return [0, 'USER_ALREADY_ACTIVE']; } @@ -584,17 +586,17 @@ class Users // Assign the special values $instructionData = json_decode($action[2], true); $rank = $instructionData['user']['rank_main']; - $ranks = $instructionData['user']['ranks']; + $ranks = $instructionData['user']['user_ranks']; } // Activate the account Database::update('users', [ [ 'rank_main' => $rank, - 'ranks' => $ranks, + 'user_ranks' => $ranks, ], [ - 'id' => [$uid, '='], + 'user_id' => [$uid, '='], ], ]); @@ -608,7 +610,7 @@ class Users { // Get the user data - $user = Database::fetch('users', false, ['id' => [$uid, '=']]); + $user = Database::fetch('users', false, ['user_id' => [$uid, '=']]); // Check if user exists if (!count($user) > 1) { @@ -616,7 +618,7 @@ class Users } // Check if user is already deactivated - if (Permissions::check('SITE', 'DEACTIVATED', $user['id'], 1)) { + if (Permissions::check('SITE', 'DEACTIVATED', $user['user_id'], 1)) { return [0, 'USER_ALREADY_DEACTIVE']; } @@ -624,10 +626,10 @@ class Users Database::update('users', [ [ 'rank_main' => 2, - 'ranks' => json_encode([2]), + 'user_ranks' => json_encode([2]), ], [ - 'id' => [$uid, '='], + 'user_id' => [$uid, '='], ], ]); @@ -715,7 +717,7 @@ class Users $user = $userIdIsUserData ? $uid : self::getUser($uid); // Decode the json - $ranks = json_decode($user['ranks'], true); + $ranks = json_decode($user['user_ranks'], true); // Check if the rank we're trying to set is actually there if (!in_array($rid, $ranks)) { @@ -728,7 +730,7 @@ class Users 'rank_main' => $rid, ], [ - 'id' => [$uid, '='], + 'user_id' => [$uid, '='], ], ]); @@ -745,7 +747,7 @@ class Users $user = $userIdIsUserData ? $uid : self::getUser($uid); // Decode the array - $current = json_decode($user['ranks'], true); + $current = json_decode($user['user_ranks'], true); // Go over all the new ranks foreach ($ranks as $rank) { @@ -761,10 +763,10 @@ class Users // Update the row Database::update('users', [ [ - 'ranks' => $current, + 'user_ranks' => $current, ], [ - 'id' => [$uid, '='], + 'user_id' => [$uid, '='], ], ]); @@ -781,7 +783,7 @@ class Users $user = $userIdIsUserData ? $uid : self::getUser($uid); // Get the ranks - $current = json_decode($user['ranks'], true); + $current = json_decode($user['user_ranks'], true); // Check the current ranks for ranks in the set array foreach ($current as $key => $rank) { @@ -797,10 +799,10 @@ class Users // Update the row Database::update('users', [ [ - 'ranks' => $current, + 'user_ranks' => $current, ], [ - 'id' => [$uid, '='], + 'user_id' => [$uid, '='], ], ]); @@ -822,7 +824,7 @@ class Users } // Decode the json for the user's ranks - $uRanks = json_decode($user['ranks'], true); + $uRanks = json_decode($user['user_ranks'], true); // If not go over all ranks and check if the user has them foreach ($ranks as $rank) { @@ -845,10 +847,10 @@ class Users $user = Main::cleanString($user, true); // Do database request - $user = Database::fetch('users', true, [($id ? 'id' : 'username_clean') => [$user, '=']]); + $user = Database::fetch('users', true, [($id ? 'user_id' : 'username_clean') => [$user, '=']]); // Return count (which would return 0, aka false, if nothing was found) - return count($user) ? $user[0]['id'] : false; + return count($user) ? $user[0]['user_id'] : false; } @@ -869,9 +871,9 @@ class Users // Iterate over the fields and clean them up foreach ($profileFields as $field) { - $fields[$field['id']] = $field; - $fields[$field['id']]['ident'] = Main::cleanString($field['name'], true, true); - $fields[$field['id']]['addit'] = json_decode($field['additional'], true); + $fields[$field['field_id']] = $field; + $fields[$field['field_id']]['field_identity'] = Main::cleanString($field['field_name'], true, true); + $fields[$field['field_id']]['field_additional'] = json_decode($field['field_additional'], true); } // Return the yeahs @@ -896,11 +898,11 @@ class Users // Iterate over the fields and clean them up foreach ($optionFields as $field) { - if (!Permissions::check('SITE', $field['require_perm'], Session::$userId, 1)) { + if (!Permissions::check('SITE', $field['option_permission'], Session::$userId, 1)) { continue; } - $fields[$field['id']] = $field; + $fields[$field['option_id']] = $field; } // Return the yeahs @@ -921,7 +923,7 @@ class Users } // Assign the profileData variable - $profileData = ($inputIsData ? $id : self::getUser($id)['userData']); + $profileData = ($inputIsData ? $id : self::getUser($id)['user_data']); // Once again if nothing was returned just return null if (count($profileData) < 1 || $profileData == null || empty($profileData['profileFields'])) { @@ -983,7 +985,7 @@ class Users { // We retrieve the current content from the database - $current = self::getUser($id)['userData']; + $current = self::getUser($id)['user_data']; // Merge the arrays $data = array_merge($current, $data); @@ -994,10 +996,10 @@ class Users // Store it in the database Database::update('users', [ [ - 'userData' => $data, + 'user_data' => $data, ], [ - 'id' => [$id, '='], + 'user_id' => [$id, '='], ], ]); @@ -1016,7 +1018,7 @@ class Users } // Return true if the user was online in the last 5 minutes - return ($user['lastdate'] > (time() - 500)); + return ($user['user_last_online'] > (time() - 500)); } @@ -1028,7 +1030,7 @@ class Users $time = time() - 500; // Get all online users in the past 5 minutes - $getAll = Database::fetch('users', true, ['lastdate' => [$time, '>']]); + $getAll = Database::fetch('users', true, ['user_last_online' => [$time, '>']]); // Return all the online users return $getAll; @@ -1041,27 +1043,27 @@ class Users // Check if there's already a record of premium for this user in the database $getUser = Database::fetch('premium', false, [ - 'uid' => [$id, '='], + 'user_id' => [$id, '='], ]); // Calculate the (new) start and expiration timestamp - $start = isset($getUser['startdate']) ? $getUser['startdate'] : time(); - $expire = isset($getUser['expiredate']) ? $getUser['expiredate'] + $seconds : time() + $seconds; + $start = isset($getUser['premium_start']) ? $getUser['premium_start'] : time(); + $expire = isset($getUser['premium_expire']) ? $getUser['premium_expire'] + $seconds : time() + $seconds; // If the user already exists do an update call, otherwise an insert call if (empty($getUser)) { Database::insert('premium', [ - 'uid' => $id, - 'startdate' => $start, - 'expiredate' => $expire, + 'user_id' => $id, + 'premium_start' => $start, + 'premium_expire' => $expire, ]); } else { Database::update('premium', [ [ - 'expiredate' => $expire, + 'premium_expire' => $expire, ], [ - 'uid' => [$id, '='], + 'user_id' => [$id, '='], ], ]); } @@ -1076,7 +1078,7 @@ class Users { Database::delete('premium', [ - 'uid' => [$id, '='], + 'user_id' => [$id, '='], ]); } @@ -1092,7 +1094,7 @@ class Users // Attempt to retrieve the premium record from the database $getRecord = Database::fetch('premium', false, [ - 'uid' => [$id, '='], + 'user_id' => [$id, '='], ]); // If nothing was returned just return false @@ -1101,14 +1103,14 @@ class Users } // Check if the Tenshi hasn't expired - if ($getRecord['expiredate'] < time()) { + if ($getRecord['premium_expire'] < time()) { self::removeUserPremium($id); self::updatePremiumMeta($id); - return [0, $getRecord['startdate'], $getRecord['expiredate']]; + return [0, $getRecord['premium_start'], $getRecord['premium_expire']]; } // Else return the start and expiration date - return [1, $getRecord['startdate'], $getRecord['expiredate']]; + return [1, $getRecord['premium_start'], $getRecord['premium_expire']]; } @@ -1152,7 +1154,7 @@ class Users { // Execute query - $rank = Database::fetch('ranks', false, ['id' => [$id, '=']]); + $rank = Database::fetch('ranks', false, ['rank_id' => [$id, '=']]); // Return false if no rank was found if (empty($rank)) { @@ -1226,11 +1228,11 @@ class Users } // Skip if inactive and not include deactivated users - if (!$includeInactive && Permissions::check('SITE', 'DEACTIVATED', $user['id'], 1)) { + if (!$includeInactive && Permissions::check('SITE', 'DEACTIVATED', $user['user_id'], 1)) { continue; } - $users[$user['id']] = $user; + $users[$user['user_id']] = $user; } // and return an array with the users @@ -1250,7 +1252,7 @@ class Users // Reorder shit foreach ($getRanks as $rank) { - $ranks[$rank['id']] = $rank; + $ranks[$rank['rank_id']] = $rank; } // and return an array with the ranks @@ -1264,7 +1266,7 @@ class Users // Do the database query $warnings = Database::fetch('warnings', true, ($uid ? [ - ($iid ? 'iid' : 'uid') => [$uid, '='], + ($iid ? 'moderator_id' : 'user_id') => [$uid, '='], ] : null)); // Return all the warnings @@ -1278,14 +1280,14 @@ class Users // Prepare conditions $conditions = array(); - $conditions['uid'] = [($uid ? $uid : Session::$userId), '=']; + $conditions['user_id'] = [($uid ? $uid : Session::$userId), '=']; if ($timediff) { - $conditions['timestamp'] = [time() - $timediff, '>']; + $conditions['alert_timestamp'] = [time() - $timediff, '>']; } if ($excludeRead) { - $conditions['notif_read'] = [0, '=']; + $conditions['alert_read'] = [0, '=']; } // Get notifications for the database @@ -1296,12 +1298,12 @@ class Users // Iterate over all entries foreach ($notifications as $notification) { // If the notifcation is already read skip - if ($notification['notif_read']) { + if ($notification['alert_read']) { continue; } // Mark them as read - self::markNotificationRead($notification['id']); + self::markNotificationRead($notification['user_id']); } } @@ -1317,10 +1319,10 @@ class Users // Execute an update statement Database::update('notifications', [ [ - 'notif_read' => ($mode ? 1 : 0), + 'alert_read' => ($mode ? 1 : 0), ], [ - 'id' => [$id, '='], + 'alert_id' => [$id, '='], ], ]); @@ -1335,15 +1337,15 @@ class Users // Insert it into the database Database::insert('notifications', [ - 'uid' => $user, - 'timestamp' => $time, - 'notif_read' => 0, - 'notif_sound' => ($sound ? 1 : 0), - 'notif_title' => $title, - 'notif_text' => $text, - 'notif_link' => $link, - 'notif_img' => $img, - 'notif_timeout' => $timeout, + 'user_id' => $user, + 'alert_timestamp' => $time, + 'alert_read' => 0, + 'alert_sound' => ($sound ? 1 : 0), + 'alert_title' => $title, + 'alert_text' => $text, + 'alert_link' => $link, + 'alert_img' => $img, + 'alert_timeout' => $timeout, ]); } @@ -1388,7 +1390,7 @@ class Users // Get all friends $getFriends = Database::fetch('friends', true, [ - 'uid' => [$uid, '='], + 'user_id' => [$uid, '='], ]); // Create the friends array @@ -1397,12 +1399,12 @@ class Users // Iterate over the raw database return foreach ($getFriends as $key => $friend) { // Add friend to array - $friends[($timestamps ? $friend['fid'] : $key)] = $getData ? ([ + $friends[($timestamps ? $friend['friend_id'] : $key)] = $getData ? ([ - 'user' => ($_UDATA = self::getUser($friend['fid'])), + 'user' => ($_UDATA = self::getUser($friend['friend_id'])), 'rank' => self::getRank($_UDATA['rank_main']), - ]) : $friend[($timestamps ? 'timestamp' : 'fid')]; + ]) : $friend[($timestamps ? 'friend_timestamp' : 'friend_id')]; } // Check who is online and who isn't @@ -1410,7 +1412,7 @@ class Users // Check each user foreach ($friends as $key => $friend) { $friends[ - self::checkUserOnline($getData ? $friend['user']['id'] : $friend) ? 'online' : 'offline' + self::checkUserOnline($getData ? $friend['user']['user_id'] : $friend) ? 'online' : 'offline' ][] = $friend; } } @@ -1431,7 +1433,7 @@ class Users // Get all friend entries from other people involved the current user $friends = Database::fetch('friends', true, [ - 'fid' => [$uid, '='], + 'friend_id' => [$uid, '='], ]); // Create pending array @@ -1440,10 +1442,10 @@ class Users // Check if the friends are mutual foreach ($friends as $friend) { // Check if the friend is mutual - if (!self::checkFriend($friend['uid'], $uid)) { + if (!self::checkFriend($friend['user_id'], $uid)) { $pending[] = $getData ? ([ - 'user' => ($_UDATA = self::getUser($friend['uid'])), + 'user' => ($_UDATA = self::getUser($friend['user_id'])), 'rank' => self::getRank($_UDATA['rank_main']), ]) : $friend; @@ -1495,15 +1497,15 @@ class Users } // Check if the user already has this user a friend - if (Database::fetch('friends', false, ['fid' => [$uid, '='], 'uid' => [Session::$userId, '=']])) { + if (Database::fetch('friends', false, ['friend_id' => [$uid, '='], 'user_id' => [Session::$userId, '=']])) { return [0, 'ALREADY_FRIENDS']; } // Add friend Database::insert('friends', [ - 'uid' => Session::$userId, - 'fid' => $uid, - 'timestamp' => time(), + 'user_id' => Session::$userId, + 'friend_id' => $uid, + 'friend_timestamp' => time(), ]); // Return true because yay @@ -1516,21 +1518,21 @@ class Users { // Check if the user has this user a friend - if (!Database::fetch('friends', false, ['fid' => [$uid, '='], 'uid' => [Session::$userId, '=']])) { + if (!Database::fetch('friends', false, ['friend_id' => [$uid, '='], 'user_id' => [Session::$userId, '=']])) { return [0, 'ALREADY_REMOVED']; } // Remove friend Database::delete('friends', [ - 'uid' => [Session::$userId, '='], - 'fid' => [$uid, '='], + 'user_id' => [Session::$userId, '='], + 'friend_id' => [$uid, '='], ]); // Attempt to remove the request if ($deleteRequest) { Database::delete('friends', [ - 'fid' => [Session::$userId, '='], - 'uid' => [$uid, '='], + 'friend_id' => [Session::$userId, '='], + 'user_id' => [$uid, '='], ]); } @@ -1543,7 +1545,7 @@ class Users public static function getNewestUserId() { - return Database::fetch('users', false, ['password_algo' => ['nologin', '!=']], ['id', true], ['1'])['id']; + return Database::fetch('users', false, ['password_algo' => ['nologin', '!=']], ['user_id', true], ['1'])['user_id']; } } diff --git a/_sakura/cron.php b/_sakura/cron.php index 3a99540..44a7762 100644 --- a/_sakura/cron.php +++ b/_sakura/cron.php @@ -27,27 +27,27 @@ set_time_limit(0); // Clean expired sessions Database::delete('sessions', [ - 'expire' => [time(), '<'], - 'remember' => ['1', '!='], + 'session_expire' => [time(), '<'], + 'session_remember' => ['1', '!='], ]); // Delete notifications that are older than a month but not unread Database::delete('notifications', [ - 'timestamp' => [(time() - 109500), '<'], - 'notif_read' => ['1', '='], + 'alert_timestamp' => [(time() - 109500), '<'], + 'alert_read' => ['1', '='], ]); // Get expired premium accounts $expiredPremium = Database::fetch('premium', true, [ - 'expiredate' => [time(), '<'], + 'premium_expire' => [time(), '<'], ]); // Process expired premium accounts foreach ($expiredPremium as $expired) { - Users::updatePremiumMeta($expired['uid']); + Users::updatePremiumMeta($expired['user_id']); } diff --git a/_sakura/sakura.php b/_sakura/sakura.php index 3046374..da831fe 100644 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -1,7 +1,7 @@ & Circlestorm + * (c) 2013-2015 Flashwave */ // Declare namespace @@ -38,6 +38,7 @@ require_once ROOT . '_sakura/components/Templates.php'; require_once ROOT . '_sakura/components/Permissions.php'; require_once ROOT . '_sakura/components/Sessions.php'; require_once ROOT . '_sakura/components/User.php'; +require_once ROOT . '_sakura/components/Rank.php'; require_once ROOT . '_sakura/components/Users.php'; require_once ROOT . '_sakura/components/Forum.php'; require_once ROOT . '_sakura/components/News.php'; diff --git a/_sakura/templates/broomcloset/global/master.tpl b/_sakura/templates/broomcloset/global/master.tpl index 3831f57..545fd8a 100644 --- a/_sakura/templates/broomcloset/global/master.tpl +++ b/_sakura/templates/broomcloset/global/master.tpl @@ -87,7 +87,7 @@