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 @@
-
{{ stats.userCount }}
+
+ + {{ stats.userCount }} +
-
{{ stats.onlineUsers|length }}
+
+ + {{ stats.onlineUsers|length }} +
-
{{ stats.newestUser.data.username }}
+
+ + {{ stats.newestUser.data.username }} +
-
{{ stats.lastRegDate }}
+
+ + {{ stats.lastRegDate }} +
-
{{ stats.topicCount }}/ {{ stats.postCount }}
+
+ + {{ stats.topicCount }}/ {{ stats.postCount }} +
diff --git a/_sakura/templates/yuuno/main/profile.tpl b/_sakura/templates/yuuno/main/profile.tpl index 7d87ef3..e93c262 100755 --- a/_sakura/templates/yuuno/main/profile.tpl +++ b/_sakura/templates/yuuno/main/profile.tpl @@ -34,15 +34,16 @@ {% if user.data.user_id == profile.data.user_id %} {% else %} - {% if profile.checkFriends(user.data.user_id) != 0 %}{% endif %} - + {% if user.checkFriends(profile.data.user_id) != 0 %}{% endif %} + {% endif %}
- - + + - + + {##} {% if not noUserpage %} {% endif %} diff --git a/_sakura/templates/yuuno/profile/friends.tpl b/_sakura/templates/yuuno/profile/friends.tpl new file mode 100644 index 0000000..e69de29 diff --git a/public/content/data/misaki/css/misaki.css b/public/content/data/misaki/css/misaki.css index fab45f4..5428977 100755 --- a/public/content/data/misaki/css/misaki.css +++ b/public/content/data/misaki/css/misaki.css @@ -586,17 +586,16 @@ a:active { * Homepage */ .homepage .frontStats { - margin: 1em 0; + padding-bottom: 5px; width: 100%; display: flex; - justify-content: space-around; - align-items: stretch; - flex-wrap: wrap; font: 2.5em/1em "Exo2-0-LightItalic", sans-serif; text-shadow: 1px 1px 2px rgba(0, 0, 0, .75); } .homepage .frontStats > div { + flex-grow: 1; + flex-shrink: 1; background: rgba(148, 117, 178, .2); box-shadow: 0 2px 6px rgba(0, 0, 0, .75); margin: 5px; @@ -607,6 +606,10 @@ a:active { display: block; } +.homepage .frontStats > div > div > span:not(:first-child) { + float: right; +} + /* * News */ diff --git a/public/profile.php b/public/profile.php index ec4935e..3bead38 100755 --- a/public/profile.php +++ b/public/profile.php @@ -15,6 +15,7 @@ $profile = new User(isset($_GET['u']) ? $_GET['u'] : 0); // Views array $views = [ 'index', + 'friends', 'threads', 'posts', 'comments', diff --git a/public/settings.php b/public/settings.php index 7919b53..da529c0 100755 --- a/public/settings.php +++ b/public/settings.php @@ -232,7 +232,6 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification Templates::render('global/information.tpl', $renderData); exit; } elseif (isset($_REQUEST['friend-action']) && $_REQUEST['friend-action'] && Users::checkLogin()) { - // Friends // Continue $continue = true; @@ -304,8 +303,8 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification if ($continue) { // Execute the action $action = (isset($_REQUEST['add']) ? - Users::addFriend($_REQUEST['add']) : - Users::removeFriend($_REQUEST['remove'], true)); + $currentUser->addFriend($_REQUEST['add']) : + $currentUser->removeFriend($_REQUEST['remove'], true)); // Set the messages $messages = [