diff --git a/_sakura/changelog.json b/_sakura/changelog.json
index 1748fb0..6204d1b 100644
--- a/_sakura/changelog.json
+++ b/_sakura/changelog.json
@@ -37,7 +37,8 @@
"20150725",
"20150728",
"20150730",
- "20150731"
+ "20150731",
+ "20150807"
]
@@ -1619,6 +1620,19 @@
"change": "Fixed pending friend requests function returning mutual friends instead of requests."
}
+ ],
+
+ "20150807": [
+
+ {
+ "type": "ADD",
+ "change": "Added profile changing frontend."
+ },
+ {
+ "type": "ADD",
+ "change": "Added profile changing backend."
+ }
+
]
}
diff --git a/_sakura/components/Users.php b/_sakura/components/Users.php
index 1d98f55..dc23192 100644
--- a/_sakura/components/Users.php
+++ b/_sakura/components/Users.php
@@ -814,6 +814,7 @@ class Users {
$fields[$field['id']] = $field;
$fields[$field['id']]['ident'] = Main::cleanString($field['name'], true, true);
+ $fields[$field['id']]['addit'] = json_decode($field['additional'], true);
}
@@ -892,6 +893,30 @@ class Users {
}
+ // Updating the profile data of a user
+ public static function updateUserProfileFields($id, $data) {
+
+ // We retrieve the current content from the database
+ $current = self::getUser($id)['userData'];
+
+ // Merge the arrays
+ $data = array_merge($current, ['profileFields' => $data]);
+
+ // Encode the json
+ $data = json_encode($data);
+
+ // Store it in the database
+ Database::update('users', [
+ [
+ 'userData' => $data
+ ],
+ [
+ 'id' => [$id, '=']
+ ]
+ ]);
+
+ }
+
// Getting the profile page of a user
public static function getProfilePage($id, $inputIsData = false) {
diff --git a/_sakura/templates/yuuno/settings/profile.tpl b/_sakura/templates/yuuno/settings/profile.tpl
index 9fc5c6f..f0b9aea 100644
--- a/_sakura/templates/yuuno/settings/profile.tpl
+++ b/_sakura/templates/yuuno/settings/profile.tpl
@@ -10,7 +10,33 @@
These are the external account links etc. on your profile, shouldn't need any additional explanation for this one.
-
+
diff --git a/content/data/yuuno/css/yuuno.css b/content/data/yuuno/css/yuuno.css
index eb4a0f8..7af60bb 100644
--- a/content/data/yuuno/css/yuuno.css
+++ b/content/data/yuuno/css/yuuno.css
@@ -1342,11 +1342,14 @@ a.gotop.exit {
margin: 0 2px 40px;
float: left;
border-radius: 3px;
+ box-shadow: inset 0 0 1px #9475B2;
+ background: #E4CFFF;
}
.settings .friends-list > div:not(:last-child):hover {
margin-bottom: 6px;
background: #C2AFFE;
+ box-shadow: inset 0 0 2px #9475B2;
}
.settings .friends-list > div > .friends-list-data {
@@ -1541,7 +1544,8 @@ button.inputStyling:active {
input[type="text"].inputStyling,
input[type="password"].inputStyling,
-input[type="date"].inputStyling {
+input[type="date"].inputStyling,
+input[type="url"].inputStyling {
padding: 3px 4px;
border: 1px solid #CCC;
box-shadow: inset #DDD 0 0 5px;
@@ -1550,13 +1554,15 @@ input[type="date"].inputStyling {
input[type="text"].inputStyling.red,
input[type="password"].inputStyling.red,
-input[type="date"].inputStyling.red {
+input[type="date"].inputStyling.red,
+input[type="url"].inputStyling.red {
box-shadow: inset 0px 0px 7px #EB5959;
}
input[type="text"].inputStyling.green,
input[type="password"].inputStyling.green,
-input[type="date"].inputStyling.green {
+input[type="date"].inputStyling.green,
+input[type="url"].inputStyling.green {
box-shadow: inset 0px 0px 7px #A9EC8B;
}
diff --git a/main/settings.php b/main/settings.php
index b9746a6..a798301 100644
--- a/main/settings.php
+++ b/main/settings.php
@@ -201,6 +201,134 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications
Templates::render('errors/information.tpl', $renderData);
exit;
+} elseif(isset($_POST['submit']) && isset($_POST['submit'])) {
+
+ // Continue
+ $continue = true;
+
+ // Check if the user is logged in
+ if(!Users::checkLogin() || !$continue) {
+
+ $renderData['page'] = [
+ 'title' => 'Settings',
+ 'redirect' => '/authenticate',
+ 'message' => 'You must be logged in to edit your settings.',
+ 'success' => 0
+ ];
+
+ // Break
+ $continue = false;
+
+ }
+
+ // Check session variables
+ if(!isset($_REQUEST['timestamp']) || $_REQUEST['timestamp'] < time() - 1000 || !isset($_REQUEST['sessid']) || $_REQUEST['sessid'] != session_id() || !$continue) {
+
+ $renderData['page'] = [
+ 'title' => 'Session expired',
+ 'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings',
+ 'message' => 'Your session has expired, please refresh the page and try again.',
+ 'success' => 0
+ ];
+
+ // Break
+ $continue = false;
+
+ }
+
+ // Change settings
+ if($continue) {
+
+ // Switch to the correct mode
+ switch($_POST['mode']) {
+
+ // Profile
+ case 'profile':
+
+ // Get profile fields and create storage var
+ $fields = Users::getProfileFields();
+ $store = [];
+
+ // Go over each field
+ foreach($fields as $field) {
+
+ // Add to the store array
+ if(isset($_POST['profile_'. $field['ident']]) && !empty($_POST['profile_'. $field['ident']])) {
+
+ $store[$field['ident']] = $_POST['profile_'. $field['ident']];
+
+ }
+
+ // Check if there's additional values we should keep in mind
+ if(isset($field['additional']) && !empty($field['additional'])) {
+
+ // Decode the json
+ $field['additional'] = json_decode($field['additional'], true);
+
+ // 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];
+
+ }
+
+ }
+
+ }
+
+ // Update database
+ Users::updateUserProfileFields(Session::$userId, $store);
+
+ // Set render data
+ $renderData['page'] = [
+
+ 'title' => 'Profile update',
+ 'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings',
+ 'message' => 'Your profile has been updated!',
+ 'success' => 1
+
+ ];
+
+ break;
+
+ // Fallback
+ default:
+
+ // Set render data
+ $renderData['page'] = [
+
+ 'title' => 'Unknown action',
+ 'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings',
+ 'message' => 'The requested method does not exist.',
+ 'success' => 0
+
+ ];
+
+ break;
+
+ }
+
+ }
+
+ // Print page contents or if the AJAX request is set only display the render data
+ print isset($_REQUEST['ajax']) ?
+ (
+ $renderData['page']['title']
+ . '|'
+ . $renderData['page']['message']
+ . '|'
+ . $renderData['page']['success']
+ . '|'
+ . $renderData['page']['redirect']
+ ) :
+ Templates::render('errors/information.tpl', $renderData);
+ exit;
+
}
if(Users::checkLogin()) {
@@ -242,8 +370,8 @@ if(Users::checkLogin()) {
// Profile
case 'profile':
$renderData['profile'] = [
- 'user' => Users::getUser(Session::$userId),
- 'fields' => Database::fetch('profilefields')
+ 'user' => Users::getUserProfileFields(Session::$userId),
+ 'fields' => Users::getProfileFields()
];
break;