r20150908

This commit is contained in:
Pachira 2015-09-08 23:57:33 +02:00
parent 2c109cdef5
commit 978e0c9b28
10 changed files with 144 additions and 52 deletions

View file

@ -60,7 +60,8 @@
"20150904",
"20150905",
"20150906",
"20150907"
"20150907",
"20150908"
]
@ -2589,6 +2590,36 @@
"user": "Flashwave"
}
],
"20150908": [
{
"type": "REM",
"change": "Removed ability to switch to Misaki through the site options (it's currently very broken).",
"user": "Flashwave"
},
{
"type": "UPD",
"change": "Hide Groups menu from the Settings page as the backend functionality is delayed until after the first stable.",
"user": "Flashwave"
},
{
"type": "FIX",
"change": "Fixed checkboxes not doing what they're supposed to do.",
"user": "Flashwave"
},
{
"type": "ADD",
"change": "Added birthdate changing.",
"user": "Flashwave"
},
{
"type": "UPD",
"change": "Made dates on profile a bit more readable.",
"user": "Flashwave"
}
]
}

View file

@ -827,14 +827,17 @@ $errorPage .= '</div>
}
// Time elapsed
public static function timeElapsed($timestamp) {
public static function timeElapsed($timestamp, $append = ' ago', $none = 'Just now') {
// Subtract the entered timestamp from the current timestamp
$time = time() - $timestamp;
// If the new timestamp is below 1 return a standard string
if($time < 1)
return 'Just now';
if($time < 1) {
return $none;
}
// Array containing time "types"
$times = [
@ -857,7 +860,7 @@ $errorPage .= '</div>
$round = round($calc);
// Return the string
return $round .' '. $times[$secs] . ($round == 1 ? '' : 's') .' ago';
return $round .' '. $times[$secs] . ($round == 1 ? '' : 's') . $append;
}

View file

@ -135,9 +135,9 @@ class User {
}
// Get all the friend of this user
public function getFriends() {
public function getFriends($timestamps = false, $getData = false, $checkOnline = false) {
return Users::getFriends($this->data['id']);
return Users::getFriends($this->data['id'], $timestamps, $getData, $checkOnline);
}
@ -155,6 +155,19 @@ class User {
}
// Get amount of time since user events
public function elapsed($append = ' ago', $none = 'Just now') {
return [
'joined' => Main::timeElapsed($this->data['regdate'], $append, $none),
'lastOnline' => Main::timeElapsed($this->data['lastdate'], $append, $none),
'birth' => Main::timeElapsed(strtotime($this->data['birthday']), $append, $none)
];
}
// Get the user's profile fields
public function profileFields() {

View file

@ -8,7 +8,7 @@
namespace Sakura;
// Define Sakura version
define('SAKURA_VERSION', '20150907');
define('SAKURA_VERSION', '20150908');
define('SAKURA_VLABEL', 'Eminence');
define('SAKURA_COLOUR', '#6C3082');
define('SAKURA_STABLE', false);
@ -75,15 +75,7 @@ $currentUser = new User(Session::$userId);
$urls = new Urls();
// Prepare the name of the template to load (outside of SAKURA_NO_TPL because it's used in imageserve.php)
$templateName = defined('SAKURA_MANAGE') ? Configuration::getConfig('manage_style') : (
(
isset($currentUser->data['userData']['userOptions']['useMisaki']) &&
$currentUser->data['userData']['userOptions']['useMisaki'] &&
$currentUser->checkPermission('SITE', 'ALTER_PROFILE')
) ?
'misaki' :
Configuration::getConfig('site_style')
);
$templateName = defined('SAKURA_MANAGE') ? Configuration::getConfig('manage_style') : Configuration::getConfig('site_style');
if(!defined('SAKURA_NO_TPL')) {
@ -98,6 +90,8 @@ if(!defined('SAKURA_NO_TPL')) {
* Attempt to use a class instead of an assoc. array for the
* template variables since twig supports this to make accessing
* certain functions, like the time elapsed function easier.
* Update 2015-09-08: Apparently this will be added in PHP 7 so
* we'll be looking out for that.
*/
'sakura' => [

View file

@ -37,15 +37,18 @@
</div>
{% endif %}
<hr class="default" />
<b>Joined</b> {{ profile.data.regdate|date(sakura.dateFormat) }}
<b>Joined</b> <span title="{{ profile.data.regdate|date(sakura.dateFormat) }}">{{ profile.elapsed.joined }}</span>
<br />
{% if profile.data.lastdate < 1 %}
<b>{{ profile.data.username }} hasn't logged in yet.</b>
{% else %}
<b>Last Seen on</b> {{ profile.data.lastdate|date(sakura.dateFormat) }}
<b>Last online</b> <span title="{{ profile.data.lastdate|date(sakura.dateFormat) }}">{{ profile.elapsed.lastOnline }}</span>
{% endif %}
<br />
<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.data.birthday != '0000-00-00' %}
<br /><b>Age</b> <span title="{{ profile.data.birthday }}">{{ profile.elapsed(' old').birth }}</span>
{% endif %}
{% if profile.profileFields %}
<hr class="default" />
{% if session.checkLogin %}
@ -57,7 +60,7 @@
</td>
<td style="text-align: right;">
{% if name == 'youtube' %}
<a href="https://youtube.com/{% if field.youtubetype == 'true' %}channel{% else %}user{% endif %}/{{ field.value }}" class="default">{% if field.youtubetype == 'true' %}{{ profile.data.username }}'s Channel{% else %}{{ field.value }}{% endif %}</a>
<a href="https://youtube.com/{% if field.youtubetype == true %}channel{% else %}user{% endif %}/{{ field.value }}" class="default">{% if field.youtubetype == true %}{{ profile.data.username }}'s Channel{% else %}{{ field.value }}{% endif %}</a>
{% else %}
{% if field.islink %}
<a href="{{ field.link }}" class="default">

View file

@ -28,16 +28,16 @@
<br />
<h1 class="stylised"><a class="clean" href="/settings/friends/listing">Friends</a></h1>
<h2 style="color: #080;">Online</h2>
{% if settings.friends.online %}
{% for key,friend in settings.friends.online %}
{% if user.getFriends(true, true, true).online %}
{% for key,friend in user.getFriends(true, true, true).online %}
<a href="/u/{{ friend.user.username }}" class="default" style="color: {% if friend.user.name_colour %}{{ friend.user.name_colour }}{% else %}{{ friend.rank.colour }}{% endif %}">{{ friend.user.username }}</a>{% if key + 1 != settings.friends.online|length %},{% endif %}
{% endfor %}
{% else %}
<h4>No friends are online.</h4>
{% endif %}
<h2 style="color: #800;">Offline</h2>
{% if settings.friends.offline %}
{% for key,friend in settings.friends.offline %}
{% if user.getFriends(true, true, true).offline %}
{% for key,friend in user.getFriends(true, true, true).offline %}
<a href="/u/{{ friend.user.username }}" class="default" style="color: {% if friend.user.name_colour %}{{ friend.user.name_colour }}{% else %}{{ friend.rank.colour }}{% endif %}">{{ friend.user.username }}</a>{% if key + 1 != settings.friends.offline|length %},{% endif %}
{% endfor %}
{% else %}

View file

@ -12,7 +12,7 @@
</div>
</div>
<div style="padding: 8px 0;">
<input type="{{ field.formtype }}" name="option_{{ field.id }}" class="inputStyling"{% if options.user[field.id] %}{% if field.formtype == 'checkbox' and options.user[field.id] %} checked="checked" value="option_{{ field.id }}"{% else %} value="{{ options.user[field.id] }}"{% endif %}{% endif %} />
<input type="{{ field.formtype }}" name="option_{{ field.id }}" class="inputStyling"{% if user.data.userData.userOptions[field.id] %}{% if field.formtype == 'checkbox' and user.data.userData.userOptions[field.id] %} checked="checked" value="option_{{ field.id }}"{% else %} value="{{ user.data.userData.userOptions[field.id] }}"{% endif %}{% endif %} />
</div>
</div>
{% endfor %}

View file

@ -1,3 +1,5 @@
{% set birthday = user.data.birthday|split('-') %}
<form enctype="multipart/form-data" method="post" action="{{ sakura.currentPage }}" id="editProfileForm">
<input type="hidden" name="sessid" value="{{ php.sessionid }}" />
<input type="hidden" name="timestamp" value="{{ php.time }}" />
@ -8,12 +10,12 @@
<h2>{{ field.name }}</h2>
</div>
<div>
<input type="{{ field.formtype }}" name="profile_{{ field.ident }}" class="inputStyling" placeholder="{{ field.description }}"{% if profile.user[field.ident].value %}{% if field.formtype == 'checkbox' and profile.user[field.ident].value == 'true' %} checked="checked"{% else %} value="{{ profile.user[field.ident].value }}"{% endif %}{% endif %} />
<input type="{{ field.formtype }}" name="profile_{{ field.ident }}" class="inputStyling" placeholder="{{ field.description }}"{% if user.profileFields[field.ident].value %}{% if field.formtype == 'checkbox' and user.profileFields[field.ident].value == 'true' %} checked="checked" value="profile_{{ field.ident }}"{% else %} value="{{ user.profileFields[field.ident].value }}"{% endif %}{% endif %} />
</div>
{% if field.addit %}
{% for id,addit in field.addit %}
<div>
<input type="{{ addit[0] }}" id="{{ id }}" name="profile_additional_{{ id }}"{% if profile.user[field.ident][id] %}{% if addit[0] == 'checkbox' and profile.user[field.ident][id] == 'true' %} checked="checked"{% else %} value="{{ profile.user[field.ident][id] }}"{% endif %}{% endif %} />
<input type="{{ addit[0] }}" id="{{ id }}" name="profile_additional_{{ id }}"{% if user.profileFields[field.ident][id] %}{% if addit[0] == 'checkbox' and user.profileFields[field.ident][id] == true %} checked="checked"{% else %} value="{{ user.profileFields[field.ident][id] }}"{% endif %}{% endif %} />
<label for="{{ id }}" style="font-size: 10px;">{{ addit[1]|raw }}</label>
</div>
{% endfor %}
@ -26,18 +28,21 @@
</div>
<div style="text-align: center;">
Day: <select name="birthday_day">
<option value="0"{% if not birthday[2] %} selected="selected"{% endif %}>--</option>
{% for i in 1..31 %}
<option value="{{ i }}">{{ i }}</option>
<option value="{{ i }}"{% if birthday[2] == i %} selected="selected"{% endif %}>{{ i }}</option>
{% endfor %}
</select>
Month: <select name="birthday_month">
<option value="0"{% if not birthday[1] %} selected="selected"{% endif %}>--</option>
{% for i in 1..12 %}
<option value="{{ i }}">{{ i }}</option>
<option value="{{ i }}"{% if birthday[1] == i %} selected="selected"{% endif %}>{{ profile.months[i] }}</option>
{% endfor %}
</select>
Year: <select name="birthday_year">
<option value="0"{% if not birthday[0] %} selected="selected"{% endif %}>----</option>
{% for i in "now"|date('Y')..("now"|date('Y') - 100) %}
<option value="{{ i }}">{{ i }}</option>
<option value="{{ i }}"{% if birthday[0] == i %} selected="selected"{% endif %}>{{ i }}</option>
{% endfor %}
</select>
</div>

View file

@ -363,7 +363,7 @@ CREATE TABLE `sakura_users` (
`regdate` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Timestamp of account creation.',
`lastdate` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Last time anything was done on this account.',
`lastunamechange` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Last username change.',
`birthday` date DEFAULT NULL COMMENT 'Birthdate of the user.',
`birthday` date DEFAULT NOT NULL COMMENT 'Birthdate of the user.',
`country` char(2) COLLATE utf8_bin NOT NULL COMMENT 'Contains ISO 3166 country code of user''s registration location.',
`userData` text COLLATE utf8_bin COMMENT 'All additional profile data.',
PRIMARY KEY (`id`),

View file

@ -508,15 +508,8 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications
// Go over each additional value
foreach($field['additional'] as $addKey => $addVal) {
// Skip if the value is empty
if(!isset($_POST['profile_additional_'. $addKey]) || empty($_POST['profile_additional_'. $addKey])) {
continue;
}
// Add to the array
$store[$addKey] = $_POST['profile_additional_'. $addKey];
$store[$addKey] = (isset($_POST['profile_additional_'. $addKey]) || !empty($_POST['profile_additional_'. $addKey])) ? $_POST['profile_additional_'. $addKey] : false;
}
@ -536,6 +529,49 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications
];
// Birthdays
if(isset($_POST['birthday_day']) && isset($_POST['birthday_month']) && isset($_POST['birthday_year'])) {
// Check if the values aren't fucked with
if($_POST['birthday_day'] < 0 || $_POST['birthday_day'] > 31 || $_POST['birthday_month'] < 0 || $_POST['birthday_month'] > 12 || ($_POST['birthday_year'] != 0 && $_POST['birthday_year'] < (date("Y") - 100)) || $_POST['birthday_year'] > date("Y")) {
$renderData['page']['message'] = 'Your birthdate is invalid.';
$renderData['page']['success'] = 0;
break;
}
// Check if the values aren't fucked with
if(($_POST['birthday_day'] < 1 && $_POST['birthday_month'] > 0) || ($_POST['birthday_day'] > 0 && $_POST['birthday_month'] < 1)) {
$renderData['page']['message'] = 'Only setting a day or month is disallowed.';
$renderData['page']['success'] = 0;
break;
}
// Check if the values aren't fucked with
if($_POST['birthday_year'] > 0 && ($_POST['birthday_day'] < 1 || $_POST['birthday_month'] < 1)) {
$renderData['page']['message'] = 'Only setting a year is disallowed.';
$renderData['page']['success'] = 0;
break;
}
$birthdate = implode('-', [$_POST['birthday_year'], $_POST['birthday_month'], $_POST['birthday_day']]);
Database::update('users', [
[
'birthday' => $birthdate
],
[
'id' => [Session::$userId, '=']
]
]);
}
break;
// Profile
@ -670,7 +706,7 @@ if(Users::checkLogin()) {
'access' => !$currentUser->checkPermission('SITE', 'DEACTIVATED'),
'menu' => true
],
]/*,
'groups' => [
'title' => 'Groups',
@ -682,7 +718,7 @@ if(Users::checkLogin()) {
'access' => $currentUser->checkPermission('SITE', 'JOIN_GROUPS'),
'menu' => true
]
]*/
]
@ -1013,19 +1049,27 @@ if(Users::checkLogin()) {
// Section specific
switch($category .'.'. $mode) {
// Homepage
case 'general.home':
$renderData['settings'] = [
'friends' => Users::getFriends(null, true, true, true)
];
break;
// Profile
case 'general.profile':
$renderData['profile'] = [
'user' => $currentUser->profileFields(),
'fields' => Users::getProfileFields()
'fields' => Users::getProfileFields(),
'months' => [
1 => 'January',
2 => 'February',
3 => 'March',
4 => 'April',
5 => 'May',
6 => 'June',
7 => 'July',
8 => 'August',
9 => 'September',
10 => 'October',
11 => 'November',
12 => 'December'
]
];
break;
@ -1034,8 +1078,7 @@ if(Users::checkLogin()) {
case 'general.options':
$renderData['options'] = [
'user' => $currentUser->optionFields(),
'fields' => Users::getOptionFields()
'fields' => Users::getOptionFields()
];
break;