r20151110

Signed-off-by: Flashwave <me@flash.moe>
This commit is contained in:
Pachira 2015-11-11 00:34:48 +01:00
parent b5809d5fe8
commit 4093327895
3 changed files with 87 additions and 23 deletions

View file

@ -168,11 +168,17 @@ class User
}
// Check if a user is online
public function checkOnline()
public function isOnline()
{
return $this->data['user_last_online'] > (time() - Config::getConfig('max_online_time'));
}
// Compatibility
public function checkOnline()
{
return $this->isOnline();
}
// Get user's forum statistics
public function forumStats()
{
@ -304,32 +310,94 @@ class User
}
// Check if the user is friends with the currently authenticated
public function checkFriends($with)
public function isFriends($with)
{
// Get the friend's friends
$friend = in_array($this->data['user_id'], (new User($with))->getFriends());
// Accepted from this user
$user = Database::count('friends', [
'user_id' => [$this->id(), '='],
'friend_id' => [$with, '='],
])[0];
// Get the user's friends
$self = in_array($with, $this->getFriends());
// And the other user
$friend = Database::count('friends', [
'user_id' => [$with, '='],
'friend_id' => [$this->id(), '='],
])[0];
// Check if the friend is actually in the user's array
if ($friend && $self) {
return 2;
if ($user && $friend) {
return 2; // Mutual friends
} elseif ($user) {
return 1; // Pending request
}
// Check if the friend is actually in the user's array
if ($self) {
return 1;
}
// Return true if all went through
// Else return 0
return 0;
}
// Get all the friend of this user
public function getFriends($timestamps = false, $getData = false, $checkOnline = false)
// Compat.
public function checkFriends($with)
{
return Users::getFriends($this->data['user_id'], $timestamps, $getData, $checkOnline);
return $this->isFriends($with);
}
// Get all the friend of this user
public function friends($level = 0)
{
// User ID container
$users = [];
// Select the correct level
switch ($level) {
case 2:
// Get all the current user's friends
$self = array_column(Database::fetch('friends', true, ['user_id' => [$this->id(), '=']]), 'friend_id');
// Get all the people that added this user as a friend
$others = array_column(Database::fetch('friends', true, ['friend_id' => [$this->id(), '=']]), 'user_id');
// Create a difference map
$users = array_intersect($self, $others);
break;
case 1:
$users = array_column(Database::fetch('friends', true, ['user_id' => [$this->id(), '=']]), 'friend_id');
break;
case 0:
default:
// Get all the current user's friends
$self = array_column(Database::fetch('friends', true, ['user_id' => [$this->id(), '=']]), 'friend_id');
// Get all the people that added this user as a friend
$others = array_column(Database::fetch('friends', true, ['friend_id' => [$this->id(), '=']]), 'user_id');
// Create a difference map
$users = array_merge($others, $self);
break;
case -1:
// Get all the current user's friends
$self = array_column(Database::fetch('friends', true, ['user_id' => [$this->id(), '=']]), 'friend_id');
// Get all the people that added this user as a friend
$others = array_column(Database::fetch('friends', true, ['friend_id' => [$this->id(), '=']]), 'user_id');
// Create a difference map
$users = array_diff($others, $self);
break;
}
// Create the storage array
$objects = [];
// Get all users
foreach ($users as $user) {
// Create new object
$objects[$user] = new User($user);
}
// Return the objects
return $objects;
}
// Compatibility
public function getFriends()
{
return $this->friends();
}
// Check if the user is banned

View file

@ -8,7 +8,7 @@
namespace Sakura;
// Define Sakura version
define('SAKURA_VERSION', '20151108');
define('SAKURA_VERSION', '20151110');
define('SAKURA_VLABEL', 'Eminence');
define('SAKURA_COLOUR', '#6C3082');
define('SAKURA_STABLE', false);

View file

@ -19,9 +19,7 @@ $template->setTemplate($templateName);
if (isset($_GET['p'])) {
// Set default variables
$renderData['page'] = [
'content' => Main::mdParse("# Unable to load the requested info page.\r\n\r\nCheck the URL and try again."),
];
// Set page id
@ -31,11 +29,9 @@ if (isset($_GET['p'])) {
if ($ipData = Main::loadInfoPage($pageId)) {
// Assign new proper variable
$renderData['page'] = [
'id' => $pageId,
'title' => $ipData['page_title'],
'content' => Main::mdParse($ipData['page_content']),
];
}