a
This commit is contained in:
parent
a28cfd6e69
commit
7f64894882
9 changed files with 142 additions and 103 deletions
|
@ -187,6 +187,22 @@ class Urls
|
||||||
'/profile.php?u=%u&view=comments',
|
'/profile.php?u=%u&view=comments',
|
||||||
'/u/%u/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' => [
|
'USER_GROUP' => [
|
||||||
'/group.php?g=%u',
|
'/group.php?g=%u',
|
||||||
'/g/%u',
|
'/g/%u',
|
||||||
|
|
|
@ -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
|
// Check if the user is friends with the currently authenticated
|
||||||
public function checkFriends($with)
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1439,8 +1439,11 @@ class Users
|
||||||
|
|
||||||
// Check if the friends are mutual
|
// Check if the friends are mutual
|
||||||
foreach ($friends as $friend) {
|
foreach ($friends as $friend) {
|
||||||
|
// Create user object
|
||||||
|
$user = new User($uid);
|
||||||
|
|
||||||
// Check if the friend is mutual
|
// Check if the friend is mutual
|
||||||
if (!self::checkFriend($friend['user_id'], $uid)) {
|
if (!$user->checkFriends($friend['user_id'])) {
|
||||||
$pending[] = $getData ? ([
|
$pending[] = $getData ? ([
|
||||||
|
|
||||||
'user' => ($_UDATA = self::getUser($friend['user_id'])),
|
'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
|
// Get the ID of the newest user
|
||||||
public static function getNewestUserId()
|
public static function getNewestUserId()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,17 +1,32 @@
|
||||||
<div class="frontStats">
|
<div class="frontStats">
|
||||||
<div title="We have {{ stats.userCount }} user{% if stats.userCount != 1 %}s{% endif %}">
|
<div title="We have {{ stats.userCount }} user{% if stats.userCount != 1 %}s{% endif %}">
|
||||||
<div><span class="fa fa-line-chart"></span> <span>{{ stats.userCount }}</span></div>
|
<div>
|
||||||
|
<span class="fa fa-line-chart"></span>
|
||||||
|
<span>{{ stats.userCount }}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div title="Active in the last 5 minutes: {% for amount,onlineUser in stats.onlineUsers %}{{ onlineUser.username }}{% if amount != (stats.onlineUsers|length - 1) %}, {% endif %}{% endfor %}">
|
<div title="Active in the last 5 minutes: {% for amount,onlineUser in stats.onlineUsers %}{{ onlineUser.username }}{% if amount != (stats.onlineUsers|length - 1) %}, {% endif %}{% endfor %}">
|
||||||
<div><span class="fa fa-users"></span> <span>{{ stats.onlineUsers|length }}</span></div>
|
<div>
|
||||||
|
<span class="fa fa-users"></span>
|
||||||
|
<span>{{ stats.onlineUsers|length }}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div title="Our newest user is {{ stats.newestUser.data.username }}">
|
<div title="Our newest user is {{ stats.newestUser.data.username }}">
|
||||||
<div><span class="fa fa-user-plus"></span> <a href="/u/{{ stats.newestUser.data.user_id }}" style="color: {{ stats.newestUser.colour }}">{{ stats.newestUser.data.username }}</a></div>
|
<div>
|
||||||
|
<span class="fa fa-user-plus"></span>
|
||||||
|
<span><a href="/u/{{ stats.newestUser.data.user_id }}" style="color: {{ stats.newestUser.colour }}">{{ stats.newestUser.data.username }}</a></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div title="It has been {{ stats.lastRegDate }} since the last user registered">
|
<div title="It has been {{ stats.lastRegDate }} since the last user registered">
|
||||||
<div><span class="fa fa-clock-o"></span> <span>{{ stats.lastRegDate }}</span></div>
|
<div>
|
||||||
|
<span class="fa fa-clock-o"></span>
|
||||||
|
<span>{{ stats.lastRegDate }}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div title="The forum has {{ stats.topicCount }} thread{% if stats.topicCount != 1 %}s{% endif %} consisting out of {{ stats.postCount }} post{% if stats.postCount != 1 %}s{% endif %}">
|
<div title="The forum has {{ stats.topicCount }} thread{% if stats.topicCount != 1 %}s{% endif %} consisting out of {{ stats.postCount }} post{% if stats.postCount != 1 %}s{% endif %}">
|
||||||
<div><span class="fa fa-list"></span> <span>{{ stats.topicCount }}</span><span style="font-size: .5em; line-height: 1em">/ {{ stats.postCount }}</span></div>
|
<div>
|
||||||
|
<span class="fa fa-list"></span>
|
||||||
|
<span>{{ stats.topicCount }}<span style="font-size: .5em; line-height: 1em">/ {{ stats.postCount }}</span></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -34,15 +34,16 @@
|
||||||
{% if user.data.user_id == profile.data.user_id %}
|
{% if user.data.user_id == profile.data.user_id %}
|
||||||
<a class="fa fa-pencil-square-o" title="Edit your profile" href="{{ urls.format('SETTING_MODE', ['general', 'profile']) }}"></a>
|
<a class="fa fa-pencil-square-o" title="Edit your profile" href="{{ urls.format('SETTING_MODE', ['general', 'profile']) }}"></a>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if profile.checkFriends(user.data.user_id) != 0 %}<a class="fa fa-{% if profile.checkFriends(user.data.user_id) == 2 %}heart{% else %}star{% endif %}" title="You are friends"></a>{% endif %}
|
{% if user.checkFriends(profile.data.user_id) != 0 %}<a class="fa fa-{% if user.checkFriends(profile.data.user_id) == 2 %}heart{% else %}star{% endif %}" title="You are friends"></a>{% endif %}
|
||||||
<a class="fa fa-user-{% if profile.checkFriends(user.data.user_id) == 0 %}plus{% else %}times{% endif %}" title="{% if profile.checkFriends(user.data.user_id) == 0 %}Add {{ legacyprofile.data.username }} as a friend{% else %}Remove friend{% endif %}" href="{% if profile.checkFriends(user.data.user_id) == 0 %}{{ urls.format('FRIEND_ADD', [profile.data.user_id, php.sessionid, php.time, sakura.currentPage]) }}{% else %}{{ urls.format('FRIEND_REMOVE', [profile.data.user_id, php.sessionid, php.time, sakura.currentPage]) }}{% endif %}" id="profileFriendToggle"></a>
|
<a class="fa fa-user-{% if user.checkFriends(profile.data.user_id) == 0 %}plus{% else %}times{% endif %}" title="{% if user.checkFriends(profile.data.user_id) == 0 %}Add {{ legacyprofile.data.username }} as a friend{% else %}Remove friend{% endif %}" href="{% if user.checkFriends(profile.data.user_id) == 0 %}{{ urls.format('FRIEND_ADD', [profile.data.user_id, php.sessionid, php.time, sakura.currentPage]) }}{% else %}{{ urls.format('FRIEND_REMOVE', [profile.data.user_id, php.sessionid, php.time, sakura.currentPage]) }}{% endif %}" id="profileFriendToggle"></a>
|
||||||
<a class="fa fa-exclamation-circle" title="Report {{ profile.data.username }}" href="{{ urls.format('USER_REPORT', [profile.data.user_id]) }}"></a>
|
<a class="fa fa-exclamation-circle" title="Report {{ profile.data.username }}" href="{{ urls.format('USER_REPORT', [profile.data.user_id]) }}"></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<hr class="default" />
|
<hr class="default" />
|
||||||
<a class="fa fa-file-text-o" title="View {{ profile.data.username }}'s profile page" href="{{ urls.format('USER_PROFILE', [profile.data.user_id]) }}"></a>
|
<a class="fa fa-file-text-o" title="View {{ profile.data.username }}'s user page" href="{{ urls.format('USER_PROFILE', [profile.data.user_id]) }}"></a>
|
||||||
<a class="fa fa-plus-square" title="View {{ profile.data.username }}'s threads" href="{{ urls.format('USER_THREADS', [profile.data.user_id]) }}"></a>
|
<a class="fa fa-list" title="View {{ profile.data.username }}'s threads" href="{{ urls.format('USER_THREADS', [profile.data.user_id]) }}"></a>
|
||||||
<a class="fa fa-reply" title="View {{ profile.data.username }}'s posts" href="{{ urls.format('USER_POSTS', [profile.data.user_id]) }}"></a>
|
<a class="fa fa-reply" title="View {{ profile.data.username }}'s posts" href="{{ urls.format('USER_POSTS', [profile.data.user_id]) }}"></a>
|
||||||
<a class="fa fa-users" title="View {{ profile.data.username }}'s friends" href="{{ urls.format('USER_FRIENDS', [profile.data.user_id]) }}"></a>
|
<a class="fa fa-user-plus" title="View {{ profile.data.username }}'s friends" href="{{ urls.format('USER_FRIENDS', [profile.data.user_id]) }}"></a>
|
||||||
|
{#<a class="fa fa-users" title="View {{ profile.data.username }}'s groups" href="{{ urls.format('USER_GROUPS', [profile.data.user_id]) }}"></a>#}
|
||||||
{% if not noUserpage %}
|
{% if not noUserpage %}
|
||||||
<a class="fa fa-comments-o" title="View {{ profile.data.username }}'s profile comments" href="{{ urls.format('USER_COMMENTS', [profile.data.user_id]) }}"></a>
|
<a class="fa fa-comments-o" title="View {{ profile.data.username }}'s profile comments" href="{{ urls.format('USER_COMMENTS', [profile.data.user_id]) }}"></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
0
_sakura/templates/yuuno/profile/friends.tpl
Normal file
0
_sakura/templates/yuuno/profile/friends.tpl
Normal file
|
@ -586,17 +586,16 @@ a:active {
|
||||||
* Homepage
|
* Homepage
|
||||||
*/
|
*/
|
||||||
.homepage .frontStats {
|
.homepage .frontStats {
|
||||||
margin: 1em 0;
|
padding-bottom: 5px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-around;
|
|
||||||
align-items: stretch;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
font: 2.5em/1em "Exo2-0-LightItalic", sans-serif;
|
font: 2.5em/1em "Exo2-0-LightItalic", sans-serif;
|
||||||
text-shadow: 1px 1px 2px rgba(0, 0, 0, .75);
|
text-shadow: 1px 1px 2px rgba(0, 0, 0, .75);
|
||||||
}
|
}
|
||||||
|
|
||||||
.homepage .frontStats > div {
|
.homepage .frontStats > div {
|
||||||
|
flex-grow: 1;
|
||||||
|
flex-shrink: 1;
|
||||||
background: rgba(148, 117, 178, .2);
|
background: rgba(148, 117, 178, .2);
|
||||||
box-shadow: 0 2px 6px rgba(0, 0, 0, .75);
|
box-shadow: 0 2px 6px rgba(0, 0, 0, .75);
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
|
@ -607,6 +606,10 @@ a:active {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.homepage .frontStats > div > div > span:not(:first-child) {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* News
|
* News
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -15,6 +15,7 @@ $profile = new User(isset($_GET['u']) ? $_GET['u'] : 0);
|
||||||
// Views array
|
// Views array
|
||||||
$views = [
|
$views = [
|
||||||
'index',
|
'index',
|
||||||
|
'friends',
|
||||||
'threads',
|
'threads',
|
||||||
'posts',
|
'posts',
|
||||||
'comments',
|
'comments',
|
||||||
|
|
|
@ -232,7 +232,6 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
|
||||||
Templates::render('global/information.tpl', $renderData);
|
Templates::render('global/information.tpl', $renderData);
|
||||||
exit;
|
exit;
|
||||||
} elseif (isset($_REQUEST['friend-action']) && $_REQUEST['friend-action'] && Users::checkLogin()) {
|
} elseif (isset($_REQUEST['friend-action']) && $_REQUEST['friend-action'] && Users::checkLogin()) {
|
||||||
// Friends
|
|
||||||
// Continue
|
// Continue
|
||||||
$continue = true;
|
$continue = true;
|
||||||
|
|
||||||
|
@ -304,8 +303,8 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
|
||||||
if ($continue) {
|
if ($continue) {
|
||||||
// Execute the action
|
// Execute the action
|
||||||
$action = (isset($_REQUEST['add']) ?
|
$action = (isset($_REQUEST['add']) ?
|
||||||
Users::addFriend($_REQUEST['add']) :
|
$currentUser->addFriend($_REQUEST['add']) :
|
||||||
Users::removeFriend($_REQUEST['remove'], true));
|
$currentUser->removeFriend($_REQUEST['remove'], true));
|
||||||
|
|
||||||
// Set the messages
|
// Set the messages
|
||||||
$messages = [
|
$messages = [
|
||||||
|
|
Reference in a new issue