flat is justice
This commit is contained in:
parent
d731728e89
commit
4070774a96
3 changed files with 168 additions and 41 deletions
|
@ -1093,6 +1093,101 @@ class Users {
|
|||
|
||||
}
|
||||
|
||||
// Get friends
|
||||
public static function getFriends($uid = null, $timestamps = false) {
|
||||
|
||||
// Assign $uid
|
||||
if(!$uid)
|
||||
$uid = Session::$userId;
|
||||
|
||||
// Get all friends
|
||||
$getFriends = Database::fetch('friends', true, [
|
||||
'uid' => [$uid, '=']
|
||||
]);
|
||||
|
||||
// Create the friends array
|
||||
$friends = [];
|
||||
|
||||
// Iterate over the raw database return
|
||||
foreach($getFriends as $friend) {
|
||||
|
||||
// Add friend to array
|
||||
$friends[($timestamps ? $friend['fid'] : false)] = $friend[($timestamps ? 'timestamp' : 'fid')];
|
||||
|
||||
}
|
||||
|
||||
// Return formatted array
|
||||
return $friends;
|
||||
|
||||
}
|
||||
|
||||
// Check if a friend is mutual
|
||||
public static function checkMutualFriend($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 false;
|
||||
|
||||
// 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 false;
|
||||
|
||||
// Return true if all went through
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
// 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, ['fid' => [$uid, '='], 'uid' => [Session::$userId, '=']]))
|
||||
return [0, 'ALREADY_FRIENDS'];
|
||||
|
||||
// Add friend
|
||||
Database::insert('friends', [
|
||||
'uid' => Session::$userId,
|
||||
'fid' => $uid,
|
||||
'timestamp' => time()
|
||||
]);
|
||||
|
||||
// Return true because yay
|
||||
return [1, Users::checkMutualFriend($uid) ? 'FRIENDS' : 'NOT_MUTUAL'];
|
||||
|
||||
}
|
||||
|
||||
// Removing a friend
|
||||
public static function removeFriend($uid) {
|
||||
|
||||
// Check if the user has this user a friend
|
||||
if(!Database::fetch('friends', false, ['fid' => [$uid, '='], 'uid' => [Session::$userId, '=']]))
|
||||
return [0, 'ALREADY_REMOVED'];
|
||||
|
||||
// Remove friend
|
||||
Database::delete('friends', [
|
||||
'uid' => Session::$userId,
|
||||
'fid' => $uid
|
||||
]);
|
||||
|
||||
// Return true because yay
|
||||
return [1, 'REMOVED'];
|
||||
|
||||
}
|
||||
|
||||
// Checking bans
|
||||
public static function checkBan($uid) {
|
||||
|
||||
|
|
|
@ -14,62 +14,63 @@ RewriteBase /
|
|||
Options +FollowSymLinks -Indexes
|
||||
|
||||
# Rewrite Rules
|
||||
RewriteRule ^feedback/?$ https://github.com/circlestorm/Sakura/issues
|
||||
RewriteRule ^credits/?$ credits.php
|
||||
RewriteRule ^index/?$ index.php
|
||||
RewriteRule ^login/?$|^logout/?$|^activate/?$|^register/?$|^forgotpassword/?|^authenticate/?$ authenticate.php
|
||||
RewriteRule ^donate/?$|^support/?$ donate.php
|
||||
RewriteRule ^contact/?$ infopage.php?r=contact
|
||||
RewriteRule ^changelog/?$ changelog.php
|
||||
RewriteRule ^faq/?$ faq.php
|
||||
RewriteRule ^search/?$ search.php
|
||||
RewriteRule ^feedback/?$ https://github.com/circlestorm/Sakura/issues [L,QSA]
|
||||
RewriteRule ^credits/?$ credits.php [L,QSA]
|
||||
RewriteRule ^index/?$ index.php [L,QSA]
|
||||
RewriteRule ^login/?$|^logout/?$|^activate/?$|^register/?$|^forgotpassword/?|^authenticate/?$ authenticate.php [L,QSA]
|
||||
RewriteRule ^donate/?$|^support/?$ donate.php [L,QSA]
|
||||
RewriteRule ^contact/?$ infopage.php?r=contact [L,QSA]
|
||||
RewriteRule ^changelog/?$ changelog.php [L,QSA]
|
||||
RewriteRule ^faq/?$ faq.php [L,QSA]
|
||||
RewriteRule ^search/?$ search.php [L,QSA]
|
||||
|
||||
## Info pages
|
||||
RewriteRule ^r/([a-z]+)$ infopage.php?r=$1
|
||||
RewriteRule ^r/([a-z]+)$ infopage.php?r=$1 [L,QSA]
|
||||
|
||||
## News
|
||||
RewriteRule ^news/?$ news.php
|
||||
RewriteRule ^news/([0-9]+)$ news.php?id=$1
|
||||
RewriteRule ^news.xml$ news.php?xml
|
||||
RewriteRule ^news/?$ news.php [L,QSA]
|
||||
RewriteRule ^news/([0-9]+)$ news.php?id=$1 [L,QSA]
|
||||
RewriteRule ^news.xml$ news.php?xml [L,QSA]
|
||||
|
||||
## Settings
|
||||
RewriteRule ^settings/?$ settings.php
|
||||
RewriteRule ^settings/([a-z]+)/?$ settings.php?mode=$1
|
||||
RewriteRule ^settings/?$ settings.php [L,QSA]
|
||||
RewriteRule ^settings/([a-z]+)/?$ settings.php?mode=$1 [L,QSA]
|
||||
RewriteRule ^friends/?$ settings.php?friend-action=true [L,QSA]
|
||||
|
||||
## Private Messages
|
||||
RewriteRule ^messages/?$ messages.php
|
||||
RewriteRule ^messages/([a-z]+)/?$ messages.php?mode=$1
|
||||
RewriteRule ^messages/?$ messages.php [L,QSA]
|
||||
RewriteRule ^messages/([a-z]+)/?$ messages.php?mode=$1 [L,QSA]
|
||||
|
||||
## Members
|
||||
RewriteRule ^members/?$ members.php
|
||||
RewriteRule ^members/([a-z]+)/?$ members.php?sort=$1
|
||||
RewriteRule ^members/([0-9]+)/?$ members.php?rank=$1
|
||||
RewriteRule ^members/p([0-9]+)/?$ members.php?page=$1
|
||||
RewriteRule ^members/([a-z]+)/([0-9]+)/?$ members.php?sort=$1&rank=$2
|
||||
RewriteRule ^members/([0-9]+)/p([0-9]+)/?$ members.php?rank=$1&page=$2
|
||||
RewriteRule ^members/([a-z]+)/p([0-9]+)/?$ members.php?sort=$1&page=$2
|
||||
RewriteRule ^members/([a-z]+)/([0-9]+)/p([0-9]+)/?$ members.php?sort=$1&rank=$2&page=$3
|
||||
RewriteRule ^members/?$ members.php [L,QSA]
|
||||
RewriteRule ^members/([a-z]+)/?$ members.php?sort=$1 [L,QSA]
|
||||
RewriteRule ^members/([0-9]+)/?$ members.php?rank=$1 [L,QSA]
|
||||
RewriteRule ^members/p([0-9]+)/?$ members.php?page=$1 [L,QSA]
|
||||
RewriteRule ^members/([a-z]+)/([0-9]+)/?$ members.php?sort=$1&rank=$2 [L,QSA]
|
||||
RewriteRule ^members/([0-9]+)/p([0-9]+)/?$ members.php?rank=$1&page=$2 [L,QSA]
|
||||
RewriteRule ^members/([a-z]+)/p([0-9]+)/?$ members.php?sort=$1&page=$2 [L,QSA]
|
||||
RewriteRule ^members/([a-z]+)/([0-9]+)/p([0-9]+)/?$ members.php?sort=$1&rank=$2&page=$3 [L,QSA]
|
||||
|
||||
## Profiles
|
||||
RewriteRule ^u/?$ profile.php
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/?$ profile.php?u=$1
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/api/?$ profile.php?data
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/header/?$ imageserve.php?m=header&u=$1
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/groups/?$ profile.php?u=$1&view=groups
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/friends/?$ profile.php?u=$1$view=friends
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/threads/?$ profile.php?u=$1$view=threads
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/posts/?$ profile.php?u=$1$view=posts
|
||||
RewriteRule ^u/?$ profile.php [L,QSA]
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/?$ profile.php?u=$1 [L,QSA]
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/api/?$ profile.php?data [L,QSA]
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/header/?$ imageserve.php?m=header&u=$1 [L,QSA]
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/groups/?$ profile.php?u=$1&view=groups [L,QSA]
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/friends/?$ profile.php?u=$1$view=friends [L,QSA]
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/threads/?$ profile.php?u=$1$view=threads [L,QSA]
|
||||
RewriteRule ^u/([A-Za-z0-9_-\s\.]+)/posts/?$ profile.php?u=$1$view=posts [L,QSA]
|
||||
|
||||
# Serving Images
|
||||
RewriteRule ^a/([0-9]+)$|a/([0-9]+).png$ imageserve.php?m=avatar&u=$1
|
||||
RewriteRule ^bg/([0-9]+)$|bg/([0-9]+).png$ imageserve.php?m=background&u=$1
|
||||
RewriteRule ^a/([0-9]+)$|a/([0-9]+).png$ imageserve.php?m=avatar&u=$1 [L,QSA]
|
||||
RewriteRule ^bg/([0-9]+)$|bg/([0-9]+).png$ imageserve.php?m=background&u=$1 [L,QSA]
|
||||
|
||||
# Forum
|
||||
RewriteRule ^forum/?$ forum/index.php
|
||||
RewriteRule ^forum/([0-9]+)/?$ forum/viewforum.php?id=$2
|
||||
RewriteRule ^forum/(thread|topic)/([0-9]+)/?$ forum/viewtopic.php?id=$2
|
||||
RewriteRule ^forum/?$ forum/index.php [L,QSA]
|
||||
RewriteRule ^forum/([0-9]+)/?$ forum/viewforum.php?id=$2 [L,QSA]
|
||||
RewriteRule ^forum/(thread|topic)/([0-9]+)/?$ forum/viewtopic.php?id=$2 [L,QSA]
|
||||
|
||||
# Management
|
||||
RewriteRule ^manage/?$ manage.php
|
||||
RewriteRule ^manage/([a-z\-]+)/?$ manage.php?page=$1&sub=0
|
||||
RewriteRule ^manage/([a-z\-]+)/([a-z\-]+)/?$ manage.php?page=$1&sub=$2
|
||||
RewriteRule ^manage/?$ manage.php [L,QSA]
|
||||
RewriteRule ^manage/([a-z\-]+)/?$ manage.php?page=$1&sub=0 [L,QSA]
|
||||
RewriteRule ^manage/([a-z\-]+)/([a-z\-]+)/?$ manage.php?page=$1&sub=$2 [L,QSA]
|
||||
|
|
|
@ -46,6 +46,37 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications
|
|||
print json_encode($notifications);
|
||||
exit;
|
||||
|
||||
// Friends
|
||||
} elseif(isset($_REQUEST['friend-action']) && $_REQUEST['friend-action']) {
|
||||
|
||||
if(!isset($_REQUEST['session']) || $_REQUEST['session'] !== session_id()) {
|
||||
print Templates::render('errors/information.tpl', array_merge($renderData, ['page' => ['redirect' => $_SERVER['PHP_SELF'], 'message' => 'Invalid session ID, please try again.', 'title' => 'Information']]));
|
||||
exit;
|
||||
}
|
||||
|
||||
if((!isset($_REQUEST['add']) && !isset($_REQUEST['remove'])) || !isset($_REQUEST['time'])) {
|
||||
print Templates::render('errors/information.tpl', array_merge($renderData, ['page' => ['redirect' => $_SERVER['PHP_SELF'], 'message' => 'One or more required parameter is not set.', 'title' => 'Information']]));
|
||||
exit;
|
||||
}
|
||||
|
||||
if((isset($_REQUEST['add']) && $_REQUEST['add'] == Session::$userId) || (isset($_REQUEST['remove']) && $_REQUEST['remove'] == Session::$userId)) {
|
||||
print Templates::render('errors/information.tpl', array_merge($renderData, ['page' => ['redirect' => $_SERVER['PHP_SELF'], 'message' => 'Can\'t add yourself as a friend.', 'title' => 'Information']]));
|
||||
exit;
|
||||
}
|
||||
|
||||
$add = Users::addFriend($_REQUEST['add']);
|
||||
print $add[1];
|
||||
if($add[0]) {
|
||||
$user = Users::getUser(Session::$userId);
|
||||
Users::createNotification($_REQUEST['add'], $user['username'] .' added you as a friend!', 'If you aren\'t mutual friends yet click here to add them as well.', 60000, '//'. Configuration::getLocalConfig('urls', 'main') .'/a/'. $user['id'], '//'. Configuration::getLocalConfig('urls', 'main') .'/u/'. $user['id'], '1');
|
||||
print Templates::render('errors/information.tpl', array_merge($renderData, ['page' => ['redirect' => $_SERVER['PHP_SELF'], 'message' => 'You are now friends!', 'title' => 'Information']]));
|
||||
exit;
|
||||
} else {
|
||||
print Templates::render('errors/information.tpl', array_merge($renderData, ['page' => ['redirect' => $_SERVER['PHP_SELF'], 'message' => 'Something went wrong.', 'title' => 'Information']]));
|
||||
exit;
|
||||
}
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
// Settings page list
|
||||
|
|
Reference in a new issue