From 978e0c9b28c8fa260f06dc48132b1a65d61b5dc1 Mon Sep 17 00:00:00 2001 From: flashwave Date: Tue, 8 Sep 2015 23:57:33 +0200 Subject: [PATCH] r20150908 --- _sakura/changelog.json | 33 ++++++- _sakura/components/Main.php | 11 ++- _sakura/components/User.php | 17 +++- _sakura/sakura.php | 14 +-- _sakura/templates/yuuno/profile/index.tpl | 9 +- .../templates/yuuno/settings/general.home.tpl | 8 +- .../yuuno/settings/general.options.tpl | 2 +- .../yuuno/settings/general.profile.tpl | 15 ++-- database/structure.sql | 2 +- main/settings.php | 85 ++++++++++++++----- 10 files changed, 144 insertions(+), 52 deletions(-) diff --git a/_sakura/changelog.json b/_sakura/changelog.json index 8787f9a..893fa11 100644 --- a/_sakura/changelog.json +++ b/_sakura/changelog.json @@ -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" + } + ] } diff --git a/_sakura/components/Main.php b/_sakura/components/Main.php index 823b4dc..351861e 100644 --- a/_sakura/components/Main.php +++ b/_sakura/components/Main.php @@ -827,14 +827,17 @@ $errorPage .= ' } // 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 .= ' $round = round($calc); // Return the string - return $round .' '. $times[$secs] . ($round == 1 ? '' : 's') .' ago'; + return $round .' '. $times[$secs] . ($round == 1 ? '' : 's') . $append; } diff --git a/_sakura/components/User.php b/_sakura/components/User.php index 1a7c5ed..673c514 100644 --- a/_sakura/components/User.php +++ b/_sakura/components/User.php @@ -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() { diff --git a/_sakura/sakura.php b/_sakura/sakura.php index b822dc7..9d7963e 100644 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -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' => [ diff --git a/_sakura/templates/yuuno/profile/index.tpl b/_sakura/templates/yuuno/profile/index.tpl index a694b9e..013adc3 100644 --- a/_sakura/templates/yuuno/profile/index.tpl +++ b/_sakura/templates/yuuno/profile/index.tpl @@ -37,15 +37,18 @@ {% endif %}
- Joined {{ profile.data.regdate|date(sakura.dateFormat) }} + Joined {{ profile.elapsed.joined }}
{% if profile.data.lastdate < 1 %} {{ profile.data.username }} hasn't logged in yet. {% else %} - Last Seen on {{ profile.data.lastdate|date(sakura.dateFormat) }} + Last online {{ profile.elapsed.lastOnline }} {% endif %}
{{ profile.data.username }} has {% if not profile.forumStats.posts %}no{% else %}{{ profile.forumStats.posts }}{% endif %} forum post{% if profile.forumStats.posts != 1 %}s{% endif %}. + {% if profile.data.birthday != '0000-00-00' %} +
Age {{ profile.elapsed(' old').birth }} + {% endif %} {% if profile.profileFields %}
{% if session.checkLogin %} @@ -57,7 +60,7 @@ {% if name == 'youtube' %} - {% if field.youtubetype == 'true' %}{{ profile.data.username }}'s Channel{% else %}{{ field.value }}{% endif %} + {% if field.youtubetype == true %}{{ profile.data.username }}'s Channel{% else %}{{ field.value }}{% endif %} {% else %} {% if field.islink %} diff --git a/_sakura/templates/yuuno/settings/general.home.tpl b/_sakura/templates/yuuno/settings/general.home.tpl index 13de5fe..97485a5 100644 --- a/_sakura/templates/yuuno/settings/general.home.tpl +++ b/_sakura/templates/yuuno/settings/general.home.tpl @@ -28,16 +28,16 @@

Friends

Online

-{% 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 %} {{ friend.user.username }}{% if key + 1 != settings.friends.online|length %},{% endif %} {% endfor %} {% else %}

No friends are online.

{% endif %}

Offline

-{% 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 %} {{ friend.user.username }}{% if key + 1 != settings.friends.offline|length %},{% endif %} {% endfor %} {% else %} diff --git a/_sakura/templates/yuuno/settings/general.options.tpl b/_sakura/templates/yuuno/settings/general.options.tpl index 812bebe..be0cab8 100644 --- a/_sakura/templates/yuuno/settings/general.options.tpl +++ b/_sakura/templates/yuuno/settings/general.options.tpl @@ -12,7 +12,7 @@
- +
{% endfor %} diff --git a/_sakura/templates/yuuno/settings/general.profile.tpl b/_sakura/templates/yuuno/settings/general.profile.tpl index c73792d..215ce8b 100644 --- a/_sakura/templates/yuuno/settings/general.profile.tpl +++ b/_sakura/templates/yuuno/settings/general.profile.tpl @@ -1,3 +1,5 @@ +{% set birthday = user.data.birthday|split('-') %} +
@@ -8,12 +10,12 @@

{{ field.name }}

- +
{% if field.addit %} {% for id,addit in field.addit %}
- +
{% endfor %} @@ -26,18 +28,21 @@
Day: Month: Year:
diff --git a/database/structure.sql b/database/structure.sql index b46a441..1ac1780 100644 --- a/database/structure.sql +++ b/database/structure.sql @@ -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`), diff --git a/main/settings.php b/main/settings.php index c206b19..04ab294 100644 --- a/main/settings.php +++ b/main/settings.php @@ -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;