r20150908

This commit is contained in:
flash 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", "20150904",
"20150905", "20150905",
"20150906", "20150906",
"20150907" "20150907",
"20150908"
] ]
@ -2589,6 +2590,36 @@
"user": "Flashwave" "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 // 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 // Subtract the entered timestamp from the current timestamp
$time = time() - $timestamp; $time = time() - $timestamp;
// If the new timestamp is below 1 return a standard string // If the new timestamp is below 1 return a standard string
if($time < 1) if($time < 1) {
return 'Just now';
return $none;
}
// Array containing time "types" // Array containing time "types"
$times = [ $times = [
@ -857,7 +860,7 @@ $errorPage .= '</div>
$round = round($calc); $round = round($calc);
// Return the string // 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 // 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 // Get the user's profile fields
public function profileFields() { public function profileFields() {

View file

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

View file

@ -37,15 +37,18 @@
</div> </div>
{% endif %} {% endif %}
<hr class="default" /> <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 /> <br />
{% if profile.data.lastdate < 1 %} {% if profile.data.lastdate < 1 %}
<b>{{ profile.data.username }} hasn't logged in yet.</b> <b>{{ profile.data.username }} hasn't logged in yet.</b>
{% else %} {% 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 %} {% endif %}
<br /> <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> <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 %} {% if profile.profileFields %}
<hr class="default" /> <hr class="default" />
{% if session.checkLogin %} {% if session.checkLogin %}
@ -57,7 +60,7 @@
</td> </td>
<td style="text-align: right;"> <td style="text-align: right;">
{% if name == 'youtube' %} {% 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 %} {% else %}
{% if field.islink %} {% if field.islink %}
<a href="{{ field.link }}" class="default"> <a href="{{ field.link }}" class="default">

View file

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

View file

@ -12,7 +12,7 @@
</div> </div>
</div> </div>
<div style="padding: 8px 0;"> <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>
</div> </div>
{% endfor %} {% 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"> <form enctype="multipart/form-data" method="post" action="{{ sakura.currentPage }}" id="editProfileForm">
<input type="hidden" name="sessid" value="{{ php.sessionid }}" /> <input type="hidden" name="sessid" value="{{ php.sessionid }}" />
<input type="hidden" name="timestamp" value="{{ php.time }}" /> <input type="hidden" name="timestamp" value="{{ php.time }}" />
@ -8,12 +10,12 @@
<h2>{{ field.name }}</h2> <h2>{{ field.name }}</h2>
</div> </div>
<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> </div>
{% if field.addit %} {% if field.addit %}
{% for id,addit in field.addit %} {% for id,addit in field.addit %}
<div> <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> <label for="{{ id }}" style="font-size: 10px;">{{ addit[1]|raw }}</label>
</div> </div>
{% endfor %} {% endfor %}
@ -26,18 +28,21 @@
</div> </div>
<div style="text-align: center;"> <div style="text-align: center;">
Day: <select name="birthday_day"> Day: <select name="birthday_day">
<option value="0"{% if not birthday[2] %} selected="selected"{% endif %}>--</option>
{% for i in 1..31 %} {% for i in 1..31 %}
<option value="{{ i }}">{{ i }}</option> <option value="{{ i }}"{% if birthday[2] == i %} selected="selected"{% endif %}>{{ i }}</option>
{% endfor %} {% endfor %}
</select> </select>
Month: <select name="birthday_month"> Month: <select name="birthday_month">
<option value="0"{% if not birthday[1] %} selected="selected"{% endif %}>--</option>
{% for i in 1..12 %} {% 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 %} {% endfor %}
</select> </select>
Year: <select name="birthday_year"> 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) %} {% 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 %} {% endfor %}
</select> </select>
</div> </div>

View file

@ -363,7 +363,7 @@ CREATE TABLE `sakura_users` (
`regdate` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Timestamp of account creation.', `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.', `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.', `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.', `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.', `userData` text COLLATE utf8_bin COMMENT 'All additional profile data.',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),

View file

@ -508,15 +508,8 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications
// Go over each additional value // Go over each additional value
foreach($field['additional'] as $addKey => $addVal) { 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 // 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; break;
// Profile // Profile
@ -670,7 +706,7 @@ if(Users::checkLogin()) {
'access' => !$currentUser->checkPermission('SITE', 'DEACTIVATED'), 'access' => !$currentUser->checkPermission('SITE', 'DEACTIVATED'),
'menu' => true 'menu' => true
], ]/*,
'groups' => [ 'groups' => [
'title' => 'Groups', 'title' => 'Groups',
@ -682,7 +718,7 @@ if(Users::checkLogin()) {
'access' => $currentUser->checkPermission('SITE', 'JOIN_GROUPS'), 'access' => $currentUser->checkPermission('SITE', 'JOIN_GROUPS'),
'menu' => true 'menu' => true
] ]*/
] ]
@ -1013,19 +1049,27 @@ if(Users::checkLogin()) {
// Section specific // Section specific
switch($category .'.'. $mode) { switch($category .'.'. $mode) {
// Homepage
case 'general.home':
$renderData['settings'] = [
'friends' => Users::getFriends(null, true, true, true)
];
break;
// Profile // Profile
case 'general.profile': case 'general.profile':
$renderData['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; break;
@ -1034,7 +1078,6 @@ if(Users::checkLogin()) {
case 'general.options': case 'general.options':
$renderData['options'] = [ $renderData['options'] = [
'user' => $currentUser->optionFields(),
'fields' => Users::getOptionFields() 'fields' => Users::getOptionFields()
]; ];