diff --git a/_sakura/components/Urls.php b/_sakura/components/Urls.php index b9915a8..4e66a20 100755 --- a/_sakura/components/Urls.php +++ b/_sakura/components/Urls.php @@ -187,6 +187,22 @@ class Urls '/profile.php?u=%u&view=comments', '/u/%u/comments', ], + 'USER_FRIENDS' => [ + '/profile.php?u=%u&view=friends', + '/u/%u/friends', + ], + 'USER_GROUPS' => [ + '/profile.php?u=%u&view=groups', + '/u/%u/groups', + ], + 'USER_THREADS' => [ + '/profile.php?u=%u&view=threads', + '/u/%u/threads', + ], + 'USER_POSTS' => [ + '/profile.php?u=%u&view=posts', + '/u/%u/posts', + ], 'USER_GROUP' => [ '/group.php?g=%u', '/g/%u', diff --git a/_sakura/components/User.php b/_sakura/components/User.php index e0c363b..72d7d80 100755 --- a/_sakura/components/User.php +++ b/_sakura/components/User.php @@ -126,11 +126,96 @@ class User } + // Add a new friend + public function addFriend($uid) + { + + // Create the foreign object + $user = new User($uid); + + // Validate that the user exists + if ($user->checkPermission('SITE', 'DEACTIVATED')) { + return [0, 'USER_NOT_EXIST']; + } + + // Get check + $check = $this->checkFriends($uid); + + // Check if the user already has this user a friend + if ($check) { + return [0, 'ALREADY_FRIENDS']; + } + + // Add friend + Database::insert('friends', [ + 'user_id' => Session::$userId, + 'friend_id' => $uid, + 'friend_timestamp' => time(), + ]); + + // Return true because yay + return [1, $check == 2 ? 'FRIENDS' : 'NOT_MUTUAL']; + + } + + // Remove a friend + public function removeFriend($uid, $deleteRequest = false) + { + + // Create the foreign object + $user = new User($uid); + + // Validate that the user exists + if ($user->checkPermission('SITE', 'DEACTIVATED')) { + return [0, 'USER_NOT_EXIST']; + } + + // Check if the user has this user a friend + if (!$this->checkFriends($uid)) { + return [0, 'ALREADY_REMOVED']; + } + + // Remove friend + Database::delete('friends', [ + 'user_id' => [Session::$userId, '='], + 'friend_id' => [$uid, '='], + ]); + + // Attempt to remove the request + if ($deleteRequest) { + Database::delete('friends', [ + 'friend_id' => [Session::$userId, '='], + 'user_id' => [$uid, '='], + ]); + } + + // Return true because yay + return [1, 'REMOVED']; + + } + // Check if the user is friends with the currently authenticated public function checkFriends($with) { - return Users::checkFriend($this->data['user_id'], $with); + // Get the friend's friends + $friend = in_array($this->data['user_id'], (new User($with))->getFriends()); + + // Get the user's friends + $self = in_array($with, $this->getFriends()); + + // Check if the friend is actually in the user's array + if ($friend && $self) { + return 2; + } + + // Check if the friend is actually in the user's array + if ($self) { + return 1; + } + + // Return true if all went through + return 0; } diff --git a/_sakura/components/Users.php b/_sakura/components/Users.php index dbb36c8..d1414f9 100755 --- a/_sakura/components/Users.php +++ b/_sakura/components/Users.php @@ -1439,8 +1439,11 @@ class Users // Check if the friends are mutual foreach ($friends as $friend) { + // Create user object + $user = new User($uid); + // Check if the friend is mutual - if (!self::checkFriend($friend['user_id'], $uid)) { + if (!$user->checkFriends($friend['user_id'])) { $pending[] = $getData ? ([ 'user' => ($_UDATA = self::getUser($friend['user_id'])), @@ -1455,90 +1458,6 @@ class Users } - // Check if a friend is mutual - public static function checkFriend($fid, $uid = null) - { - - // Assign $uid - if (!$uid) { - $uid = Session::$userId; - } - - // Get the user's friends - $self = self::getFriends($uid); - - // Check if the friend is actually in the user's array - if (!in_array($fid, $self)) { - return 0; - } - - // Get the friend's friends - $friend = self::getFriends($fid); - - // Check if the friend is actually in the user's array - if (in_array($uid, $friend)) { - return 2; - } - - // Return true if all went through - return 1; - - } - - // Adding a friend - public static function addFriend($uid) - { - - // Validate that the user exists - if (!self::getUser($uid)) { - return [0, 'USER_NOT_EXIST']; - } - - // Check if the user already has this user a friend - if (Database::fetch('friends', false, ['friend_id' => [$uid, '='], 'user_id' => [Session::$userId, '=']])) { - return [0, 'ALREADY_FRIENDS']; - } - - // Add friend - Database::insert('friends', [ - 'user_id' => Session::$userId, - 'friend_id' => $uid, - 'friend_timestamp' => time(), - ]); - - // Return true because yay - return [1, self::checkFriend($uid) == 2 ? 'FRIENDS' : 'NOT_MUTUAL']; - - } - - // Removing a friend - public static function removeFriend($uid, $deleteRequest = false) - { - - // Check if the user has this user a friend - if (!Database::fetch('friends', false, ['friend_id' => [$uid, '='], 'user_id' => [Session::$userId, '=']])) { - return [0, 'ALREADY_REMOVED']; - } - - // Remove friend - Database::delete('friends', [ - 'user_id' => [Session::$userId, '='], - 'friend_id' => [$uid, '='], - ]); - - // Attempt to remove the request - if ($deleteRequest) { - Database::delete('friends', [ - 'friend_id' => [Session::$userId, '='], - 'user_id' => [$uid, '='], - ]); - } - - // Return true because yay - return [1, 'REMOVED']; - - } - // Get the ID of the newest user public static function getNewestUserId() { diff --git a/_sakura/templates/misaki/elements/statsHeader.tpl b/_sakura/templates/misaki/elements/statsHeader.tpl index 0234da7..ea821fc 100755 --- a/_sakura/templates/misaki/elements/statsHeader.tpl +++ b/_sakura/templates/misaki/elements/statsHeader.tpl @@ -1,17 +1,32 @@