new user api
This commit is contained in:
parent
b159477be2
commit
437e3c1039
4 changed files with 106 additions and 26 deletions
|
@ -2059,7 +2059,7 @@
|
|||
},
|
||||
{
|
||||
"type": "UPD",
|
||||
"change": "Converted most of profile.php to the new user API.",
|
||||
"change": "Converted profile.php to the new user API.",
|
||||
"user": "Flashwave"
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,34 @@ class User {
|
|||
|
||||
}
|
||||
|
||||
// Check if a user is online
|
||||
public function checkOnline() {
|
||||
|
||||
return $this->data['lastdate'] > (time() - Configuration::getConfig('max_online_time'));
|
||||
|
||||
}
|
||||
|
||||
// Get user's forum statistics
|
||||
public function forumStats() {
|
||||
|
||||
return Forum::getUserStats($this->data['id']);
|
||||
|
||||
}
|
||||
|
||||
// Check if the user is friends with the currently authenticated
|
||||
public function checkFriends($with) {
|
||||
|
||||
return Users::checkFriend($this->data['id'], $with);
|
||||
|
||||
}
|
||||
|
||||
// Check if the user is banned
|
||||
public function checkBan() {
|
||||
|
||||
return Bans::checkBan($this->data['id']);
|
||||
|
||||
}
|
||||
|
||||
// Get the user's profile fields
|
||||
public function profileFields() {
|
||||
|
||||
|
@ -158,4 +186,55 @@ class User {
|
|||
|
||||
}
|
||||
|
||||
// Check if user has Premium
|
||||
public function checkPremium() {
|
||||
|
||||
// Check if the user has static premium
|
||||
if(Permissions::check('SITE', 'STATIC_PREMIUM', $this->data['id'], 1)) {
|
||||
|
||||
return [2, 0, time() + 1];
|
||||
|
||||
}
|
||||
|
||||
// Attempt to retrieve the premium record from the database
|
||||
$getRecord = Database::fetch('premium', false, [
|
||||
|
||||
'uid' => [$this->data['id'], '=']
|
||||
|
||||
]);
|
||||
|
||||
// If nothing was returned just return false
|
||||
if(empty($getRecord)) {
|
||||
|
||||
return [0];
|
||||
|
||||
}
|
||||
|
||||
// Check if the Tenshi hasn't expired
|
||||
if($getRecord['expiredate'] < time()) {
|
||||
|
||||
Users::removeUserPremium($this->data['id']);
|
||||
Users::updatePremiumMeta($this->data['id']);
|
||||
return [0, $getRecord['startdate'], $getRecord['expiredate']];
|
||||
|
||||
}
|
||||
|
||||
// Else return the start and expiration date
|
||||
return [1, $getRecord['startdate'], $getRecord['expiredate']];
|
||||
|
||||
}
|
||||
|
||||
// Get all warnings issued to the user
|
||||
public function getWarnings() {
|
||||
|
||||
// Do the database query
|
||||
$warnings = Database::fetch('warnings', true, [
|
||||
'uid' => [$this->data['id'], '=']
|
||||
]);
|
||||
|
||||
// Return all the warnings
|
||||
return $warnings;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% include 'global/header.tpl' %}
|
||||
{% if legacyprofile.notset or profile.data.id < 1 or profile.data.password_algo == 'nologin' %}
|
||||
{% if page.notfound or profile.data.id < 1 or profile.data.password_algo == 'nologin' %}
|
||||
<div class="content standalone" style="padding: 20px;">
|
||||
<h1>The requested user does not exist!</h1>
|
||||
There are a few possible reasons for this:
|
||||
|
@ -15,18 +15,18 @@
|
|||
<div class="content profile">
|
||||
<div class="{% if profile.userPage|length > 1 %}content-right {% endif %}content-column">
|
||||
<div style="text-align: center;">
|
||||
<img src="/a/{{ profile.data.id }}" alt="{{ profile.data.username }}'s Avatar" class="default-avatar-setting" style="box-shadow: 0 3px 7px #{% if profile.is_online %}484{% else %}844{% endif %};" /><br />
|
||||
{% if profile.data.rank_main > 1 and legacyprofile.ban_check|length < 1 %}{# !!! #}
|
||||
<img src="/a/{{ profile.data.id }}" alt="{{ profile.data.username }}'s Avatar" class="default-avatar-setting" style="box-shadow: 0 3px 7px #{% if profile.checkOnline %}484{% else %}844{% endif %};" /><br />
|
||||
{% if profile.data.rank_main > 1 and profile.checkBan|length < 1 %}
|
||||
<span style="font-size: .8em;">{{ profile.userTitle }}</span>
|
||||
<h1 style="color: {{ profile.colour }}; text-shadow: 0 0 7px {% if profile.colour != 'inherit' %}{{ profile.colour }}{% else %}#222{% endif %}; padding: 0 0 2px;">{{ profile.data.username }}</h1>
|
||||
{% if profile.is_premium %}<img src="{{ sakura.content_path }}/images/tenshi.png" alt="Tenshi" /> {% endif %}<img src="{{ sakura.content_path }}/images/flags/{% if profile.country.short|lower == 'eu' %}europeanunion{% else %}{{ profile.country.short|lower }}{% endif %}.png" alt="{{ profile.country.short }}" /> <span style="font-size: .9em; line-height: 11px;">{{ profile.country.long }}</span>
|
||||
{% if profile.checkPremium[0] %}<img src="{{ sakura.content_path }}/images/tenshi.png" alt="Tenshi" /> {% endif %}<img src="{{ sakura.content_path }}/images/flags/{% if profile.country.short|lower == 'eu' %}europeanunion{% else %}{{ profile.country.short|lower }}{% endif %}.png" alt="{{ profile.country.short }}" /> <span style="font-size: .9em; line-height: 11px;">{{ profile.country.long }}</span>
|
||||
{% if user.checklogin %}
|
||||
<div class="user-actions">
|
||||
{% if user.data.id == profile.data.id %}
|
||||
<a class="fa fa-pencil-square-o" title="Edit your profile" href="/settings/profile"></a>
|
||||
{% else %}
|
||||
{% if legacyprofile.friend != 0 %}<a class="fa fa-{% if legacyprofile.friend == 2 %}heart{% else %}star{% endif %}" title="You are friends"></a>{% endif %}
|
||||
<a class="fa fa-user-{% if legacyprofile.friend == 0 %}plus{% else %}times{% endif %}" title="{% if legacyprofile.friend == 0 %}Add {{ legacyprofile.data.username }} as a friend{% else %}Remove friend{% endif %}" href="/friends?{% if legacyprofile.friend == 0 %}add{% else %}remove{% endif %}={{ profile.data.id }}&session={{ php.sessionid }}&time={{ php.time }}&redirect={{ sakura.currentpage }}" id="profileFriendToggle"></a>
|
||||
{% if profile.checkFriends(user.data.id) != 0 %}<a class="fa fa-{% if profile.checkFriends(user.data.id) == 2 %}heart{% else %}star{% endif %}" title="You are friends"></a>{% endif %}
|
||||
<a class="fa fa-user-{% if profile.checkFriends(user.data.id) == 0 %}plus{% else %}times{% endif %}" title="{% if profile.checkFriends(user.data.id) == 0 %}Add {{ legacyprofile.data.username }} as a friend{% else %}Remove friend{% endif %}" href="/friends?{% if profile.checkFriends(user.data.id) == 0 %}add{% else %}remove{% endif %}={{ profile.data.id }}&session={{ php.sessionid }}&time={{ php.time }}&redirect={{ sakura.currentpage }}" id="profileFriendToggle"></a>
|
||||
<a class="fa fa-flag" title="Report {{ profile.data.username }}" href="/u/{{ profile.data.id }}/report"></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
@ -40,7 +40,7 @@
|
|||
<b>Last Seen on</b> {{ profile.data.lastdate|date(sakura.date_format) }}
|
||||
{% endif %}
|
||||
<br />
|
||||
<b>{{ profile.data.username }} has {% if not legacyprofile.forum_stats.posts %}no{% else %}{{ legacyprofile.forum_stats.posts }}{% endif %} forum post{% if legacyprofile.forum_stats.posts != 1 %}s{% endif %}.</b>
|
||||
<b>{{ profile.data.username }} has {% if not profile.forumStats.posts %}no{% else %}{{ profile.forumStats.posts }}{% endif %} forum post{% if profile.forumStats.posts != 1 %}s{% endif %}.</b>
|
||||
{% if profile.profileFields %}
|
||||
<hr class="default" />
|
||||
{% if user.checklogin %}
|
||||
|
@ -77,12 +77,12 @@
|
|||
<b>Account Standing</b>
|
||||
{% if profile.data.rank_main < 2 %}
|
||||
<h2 style="color: #888; text-shadow: 0 0 7px #888; margin-top: 0;">Deactivated</h2>
|
||||
{% elseif legacyprofile.ban_check %}
|
||||
{% elseif profile.checkBan %}
|
||||
<h2 style="color: #222; text-shadow: 0 0 7px #222; margin-top: 0;">Banned</h2>
|
||||
{% else %}
|
||||
{% if legacyprofile.warnings %}
|
||||
{% if profile.getWarnings %}
|
||||
<h2 style="color: red; text-shadow: 0 0 7px #888; margin-top: 0;">Bad</h2>
|
||||
<span style="font-size: 10px; line-height: 10px;">This user has <b>{{ legacyprofile.warnings|length }} warning{% if legacyprofile.warnings|length != 1 %}s{% endif %}</b>.<br />After 5 to 10 warnings (depending on what they are for) this user may be permanently banned.</span>
|
||||
<span style="font-size: 10px; line-height: 10px;">This user has <b>{{ profile.getWarnings|length }} warning{% if profile.getWarnings|length != 1 %}s{% endif %}</b>.<br />After 5 to 10 warnings (depending on what they are for) this user may be permanently banned.</span>
|
||||
{% else %}
|
||||
<h2 style="color: green; text-shadow: 0 0 7px #888; margin-top: 0;">Good</h2>
|
||||
{% endif %}
|
||||
|
|
|
@ -15,23 +15,17 @@ if(isset($_GET['u'])) {
|
|||
// Get the user's context
|
||||
$profile = new User($_GET['u']);
|
||||
|
||||
$renderData['legacyprofile'] = [
|
||||
'notset' => false,
|
||||
'is_premium' => Users::checkUserPremium($profile->data['id'])[0],
|
||||
'is_online' => Users::checkUserOnline($profile->data['id']),
|
||||
'warnings' => Users::getWarnings($profile->data['id']),
|
||||
'friend' => Users::checkFriend($profile->data['id']),
|
||||
'forum_stats' => Forum::getUserStats($profile->data['id']),
|
||||
'ban_check' => Bans::checkBan($profile->data['id'])
|
||||
];
|
||||
|
||||
|
||||
// Assign the object to a renderData variable
|
||||
$renderData['profile'] = $profile;
|
||||
|
||||
$renderData['page'] = [
|
||||
'title' => ($profile->data['id'] < 1 || $profile->data['password_algo'] == 'nologin' ? 'User not found!' : 'Profile of '. $profile->data['username']),
|
||||
'style' => (!empty($profile->data['userData']['profileBackground']) ? [
|
||||
|
||||
'notfound' => false,
|
||||
'title' => ($profile->data['id'] < 1 || $profile->data['password_algo'] == 'nologin' ? 'User not found!' : 'Profile of '. $profile->data['username']),
|
||||
'style' => (!empty($profile->data['userData']['profileBackground']) ? [
|
||||
|
||||
'#userBackground' => [
|
||||
|
||||
'background' => 'url("/bg/'. $profile->data['id'] .'") no-repeat center center / cover transparent !important',
|
||||
'position' => 'fixed',
|
||||
'top' => '0',
|
||||
|
@ -39,14 +33,21 @@ if(isset($_GET['u'])) {
|
|||
'right' => '0',
|
||||
'left' => '0',
|
||||
'z-index' => '-1'
|
||||
|
||||
]
|
||||
|
||||
] : null)
|
||||
|
||||
];
|
||||
|
||||
} else {
|
||||
|
||||
$renderData['legacyprofile']['notset'] = true;
|
||||
$renderData['page']['title'] = 'User not found!';
|
||||
$renderData['page'] = [
|
||||
|
||||
'notfound' => true,
|
||||
'title' => 'User not found!'
|
||||
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue