2008-05-15 17:28:44 +01:00
|
|
|
<?php
|
2019-09-11 09:25:39 +01:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2009-01-17 22:30:44 +00:00
|
|
|
/**
|
|
|
|
* Change profile settings
|
|
|
|
*
|
|
|
|
* @category Settings
|
2019-09-11 09:25:39 +01:00
|
|
|
* @package GNUsocial
|
2009-08-25 23:19:04 +01:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @author Zach Copley <zach@status.net>
|
2009-09-03 20:42:50 +01:00
|
|
|
* @author Sarven Capadisli <csarven@status.net>
|
2009-08-25 23:12:20 +01:00
|
|
|
* @copyright 2008-2009 StatusNet, Inc.
|
2019-09-11 09:25:39 +01:00
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2008-05-15 17:28:44 +01:00
|
|
|
*/
|
|
|
|
|
2019-09-11 09:25:39 +01:00
|
|
|
defined('GNUSOCIAL') || die();
|
2009-01-17 22:30:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Change profile settings
|
|
|
|
*
|
2019-09-11 09:25:39 +01:00
|
|
|
* @copyright 2008-2009 StatusNet, Inc.
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2009-01-17 22:30:44 +00:00
|
|
|
*/
|
2011-01-23 17:35:35 +00:00
|
|
|
class ProfilesettingsAction extends SettingsAction
|
2008-12-23 19:49:23 +00:00
|
|
|
{
|
2009-01-17 22:30:44 +00:00
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
*
|
|
|
|
* @return string Title of the page
|
|
|
|
*/
|
2019-09-11 09:25:39 +01:00
|
|
|
public function title()
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Page title for profile settings.
|
2009-01-17 22:30:44 +00:00
|
|
|
return _('Profile settings');
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
|
|
|
|
2009-01-17 22:30:44 +00:00
|
|
|
/**
|
|
|
|
* Instructions for use
|
|
|
|
*
|
|
|
|
* @return instructions for use
|
|
|
|
*/
|
2019-09-11 09:25:39 +01:00
|
|
|
public function getInstructions()
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Usage instructions for profile settings.
|
2009-01-17 22:30:44 +00:00
|
|
|
return _('You can update your personal profile info here '.
|
2009-12-23 15:38:09 +00:00
|
|
|
'so people know more about you.');
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-11 09:25:39 +01:00
|
|
|
public function showScripts()
|
2009-09-03 20:42:50 +01:00
|
|
|
{
|
|
|
|
parent::showScripts();
|
2015-02-04 20:25:14 +00:00
|
|
|
$this->autofocus('fullname');
|
2009-09-03 20:42:50 +01:00
|
|
|
}
|
|
|
|
|
2009-01-17 22:30:44 +00:00
|
|
|
/**
|
|
|
|
* Content area of the page
|
|
|
|
*
|
|
|
|
* Shows a form for uploading an avatar.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-09-11 09:25:39 +01:00
|
|
|
public function showContent()
|
2009-01-17 22:30:44 +00:00
|
|
|
{
|
2015-03-06 22:21:57 +00:00
|
|
|
$user = $this->scoped->getUser();
|
2008-12-23 19:19:07 +00:00
|
|
|
|
2009-01-27 06:21:36 +00:00
|
|
|
$this->elementStart('form', array('method' => 'post',
|
2009-12-23 15:38:09 +00:00
|
|
|
'id' => 'form_settings_profile',
|
|
|
|
'class' => 'form_settings',
|
|
|
|
'action' => common_local_url('profilesettings')));
|
2009-01-17 23:49:12 +00:00
|
|
|
$this->elementStart('fieldset');
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Profile settings form legend.
|
2009-01-17 23:49:12 +00:00
|
|
|
$this->element('legend', null, _('Profile information'));
|
2009-01-15 22:57:15 +00:00
|
|
|
$this->hidden('token', common_session_token());
|
2009-01-17 22:30:44 +00:00
|
|
|
|
2009-04-16 18:34:19 +01:00
|
|
|
// too much common patterns here... abstractable?
|
2009-01-19 03:09:13 +00:00
|
|
|
$this->elementStart('ul', 'form_data');
|
2009-04-16 18:34:19 +01:00
|
|
|
if (Event::handle('StartProfileFormData', array($this))) {
|
|
|
|
$this->elementStart('li');
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Field label in form for profile settings.
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->input(
|
|
|
|
'nickname',
|
|
|
|
_('Nickname'),
|
|
|
|
$this->trimmed('nickname') ?: $this->scoped->getNickname(),
|
|
|
|
// TRANS: Tooltip for field label in form for profile settings.
|
|
|
|
_('1-64 lowercase letters or numbers, no punctuation or spaces.'),
|
|
|
|
null,
|
|
|
|
false, // "name" (will be set to id), then "required"
|
|
|
|
(common_config('profile', 'changenick')
|
|
|
|
? ['placeholder' => null]
|
|
|
|
: ['disabled' => 'disabled', 'placeholder' => null])
|
|
|
|
);
|
2009-04-16 18:34:19 +01:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementStart('li');
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Field label in form for profile settings.
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->input(
|
|
|
|
'fullname',
|
|
|
|
_('Full name'),
|
|
|
|
$this->trimmed('fullname') ?: $this->scoped->getFullname(),
|
|
|
|
// TRANS: Instructions for full name text field on profile settings
|
|
|
|
_('A full name is required, if empty it will be set to your nickname.'),
|
|
|
|
null,
|
|
|
|
true
|
|
|
|
);
|
2009-04-16 18:34:19 +01:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementStart('li');
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Field label in form for profile settings.
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->input(
|
|
|
|
'homepage',
|
|
|
|
_('Homepage'),
|
|
|
|
$this->trimmed('homepage') ?: $this->scoped->getHomepage(),
|
|
|
|
// TRANS: Tooltip for field label in form for profile settings.
|
|
|
|
_('URL of your homepage, blog, or profile on another site.')
|
|
|
|
);
|
2009-04-16 18:34:19 +01:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementStart('li');
|
2009-08-21 12:48:30 +01:00
|
|
|
$maxBio = Profile::maxBio();
|
|
|
|
if ($maxBio > 0) {
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Tooltip for field label in form for profile settings. Plural
|
|
|
|
// TRANS: is decided by the number of characters available for the
|
|
|
|
// TRANS: biography (%d).
|
2019-09-11 09:25:39 +01:00
|
|
|
$bioInstr = sprintf(
|
|
|
|
_m('Describe yourself and your interests in %d character.',
|
|
|
|
'Describe yourself and your interests in %d characters.',
|
|
|
|
$maxBio),
|
|
|
|
$maxBio
|
|
|
|
);
|
2009-08-21 12:48:30 +01:00
|
|
|
} else {
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Tooltip for field label in form for profile settings.
|
2011-03-29 22:00:29 +01:00
|
|
|
$bioInstr = _('Describe yourself and your interests.');
|
2009-08-21 12:48:30 +01:00
|
|
|
}
|
2011-03-29 22:00:29 +01:00
|
|
|
// TRANS: Text area label in form for profile settings where users can provide
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: their biography.
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->textarea(
|
|
|
|
'bio',
|
|
|
|
_('Bio'),
|
|
|
|
($this->trimmed('bio') ?: $this->scoped->getDescription()),
|
|
|
|
$bioInstr
|
|
|
|
);
|
2009-04-16 18:34:19 +01:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementStart('li');
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Field label in form for profile settings.
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->input(
|
|
|
|
'location',
|
|
|
|
_('Location'),
|
|
|
|
($this->trimmed('location') ?: $this->scoped->location),
|
|
|
|
// TRANS: Tooltip for field label in form for profile settings.
|
|
|
|
_('Where you are, like "City, State (or Region), Country".')
|
|
|
|
);
|
2009-04-16 18:34:19 +01:00
|
|
|
$this->elementEnd('li');
|
2009-12-28 22:44:05 +00:00
|
|
|
if (common_config('location', 'share') == 'user') {
|
|
|
|
$this->elementStart('li');
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Checkbox label in form for profile settings.
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->checkbox(
|
|
|
|
'sharelocation',
|
|
|
|
_('Share my current location when posting notices'),
|
|
|
|
($this->arg('sharelocation') ?
|
|
|
|
$this->boolean('sharelocation') : $this->scoped->shareLocation())
|
|
|
|
);
|
2009-12-28 22:44:05 +00:00
|
|
|
$this->elementEnd('li');
|
|
|
|
}
|
2009-04-16 18:34:19 +01:00
|
|
|
Event::handle('EndProfileFormData', array($this));
|
|
|
|
$this->elementStart('li');
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Field label in form for profile settings.
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->input(
|
|
|
|
'tags',
|
|
|
|
_('Tags'),
|
|
|
|
($this->trimmed('tags') ?: implode(' ', Profile_tag::getSelfTagsArray($this->scoped))),
|
|
|
|
// TRANS: Tooltip for field label in form for profile settings.
|
|
|
|
_('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated.')
|
|
|
|
);
|
2009-04-16 18:34:19 +01:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementStart('li');
|
|
|
|
$language = common_language();
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Dropdownlist label in form for profile settings.
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->dropdown(
|
|
|
|
'language',
|
|
|
|
_('Language'),
|
|
|
|
// TRANS: Tooltip for dropdown list label in form for profile settings.
|
|
|
|
get_nice_language_list(),
|
|
|
|
_('Preferred language.'),
|
|
|
|
false,
|
|
|
|
$language
|
|
|
|
);
|
2009-04-16 18:34:19 +01:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$timezone = common_timezone();
|
|
|
|
$timezones = array();
|
2019-09-11 09:25:39 +01:00
|
|
|
foreach (DateTimeZone::listIdentifiers() as $k => $v) {
|
2009-04-16 18:34:19 +01:00
|
|
|
$timezones[$v] = $v;
|
|
|
|
}
|
|
|
|
$this->elementStart('li');
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Dropdownlist label in form for profile settings.
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->dropdown(
|
|
|
|
'timezone',
|
|
|
|
_('Timezone'),
|
|
|
|
// TRANS: Tooltip for dropdown list label in form for profile settings.
|
|
|
|
$timezones,
|
|
|
|
_('What timezone are you normally in?'),
|
|
|
|
true,
|
|
|
|
$timezone
|
|
|
|
);
|
2009-04-16 18:34:19 +01:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementStart('li');
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->checkbox(
|
|
|
|
'autosubscribe',
|
|
|
|
// TRANS: Checkbox label in form for profile settings.
|
|
|
|
_('Automatically subscribe to whoever '.
|
|
|
|
'subscribes to me (best for non-humans)'),
|
|
|
|
($this->arg('autosubscribe') ?
|
|
|
|
$this->boolean('autosubscribe') : $user->autosubscribe)
|
|
|
|
);
|
2009-04-16 18:34:19 +01:00
|
|
|
$this->elementEnd('li');
|
2011-03-28 23:13:59 +01:00
|
|
|
$this->elementStart('li');
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->dropdown(
|
|
|
|
'subscribe_policy',
|
|
|
|
// TRANS: Dropdown field label on profile settings, for what policies to apply when someone else tries to subscribe to your updates.
|
|
|
|
_('Subscription policy'),
|
|
|
|
[
|
|
|
|
// TRANS: Dropdown field option for following policy.
|
|
|
|
User::SUBSCRIBE_POLICY_OPEN => _('Let anyone follow me'),
|
|
|
|
// TRANS: Dropdown field option for following policy.
|
|
|
|
User::SUBSCRIBE_POLICY_MODERATE => _('Ask me first'),
|
|
|
|
],
|
|
|
|
// TRANS: Dropdown field title on group edit form.
|
|
|
|
_('Whether other users need your permission to follow your updates.'),
|
|
|
|
false,
|
|
|
|
(empty($user->subscribe_policy) ? User::SUBSCRIBE_POLICY_OPEN : $user->subscribe_policy)
|
|
|
|
);
|
2011-03-28 23:13:59 +01:00
|
|
|
$this->elementEnd('li');
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2016-02-17 21:58:31 +00:00
|
|
|
if (common_config('profile', 'allowprivate') || $user->private_stream) {
|
|
|
|
$this->elementStart('li');
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->checkbox(
|
|
|
|
'private_stream',
|
|
|
|
// TRANS: Checkbox label in profile settings.
|
|
|
|
_('Make updates visible only to my followers'),
|
|
|
|
($this->arg('private_stream') ?
|
|
|
|
$this->boolean('private_stream') : $user->private_stream)
|
|
|
|
);
|
2016-02-17 21:58:31 +00:00
|
|
|
$this->elementEnd('li');
|
|
|
|
}
|
2009-01-17 23:49:12 +00:00
|
|
|
$this->elementEnd('ul');
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Button to save input in profile settings.
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->submit('save', _m('BUTTON', 'Save'));
|
2008-12-23 19:19:07 +00:00
|
|
|
|
2009-01-17 23:49:12 +00:00
|
|
|
$this->elementEnd('fieldset');
|
2009-01-15 22:57:15 +00:00
|
|
|
$this->elementEnd('form');
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
|
|
|
|
2009-01-17 22:30:44 +00:00
|
|
|
/**
|
|
|
|
* Handle a post
|
|
|
|
*
|
|
|
|
* Validate input and save changes. Reload the form with a success
|
|
|
|
* or error message.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-07-17 11:09:24 +01:00
|
|
|
protected function doPost()
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2009-04-16 18:34:19 +01:00
|
|
|
if (Event::handle('StartProfileSaveForm', array($this))) {
|
|
|
|
|
2015-02-04 20:25:14 +00:00
|
|
|
// $nickname will only be set if this changenick value is true.
|
|
|
|
if (common_config('profile', 'changenick') == true) {
|
|
|
|
try {
|
|
|
|
$nickname = Nickname::normalize($this->trimmed('nickname'), true);
|
|
|
|
} catch (NicknameTakenException $e) {
|
2015-07-17 11:09:24 +01:00
|
|
|
// Abort only if the nickname is occupied by _another_ local user profile
|
|
|
|
if (!$this->scoped->sameAs($e->profile)) {
|
|
|
|
throw $e;
|
2015-02-04 20:25:14 +00:00
|
|
|
}
|
2015-07-17 11:09:24 +01:00
|
|
|
// Since the variable wasn't set before the exception was thrown, let's run
|
|
|
|
// the normalize sequence again, but without in-use check this time.
|
|
|
|
$nickname = Nickname::normalize($this->trimmed('nickname'));
|
2013-10-16 13:58:22 +01:00
|
|
|
}
|
2010-11-29 22:15:25 +00:00
|
|
|
}
|
|
|
|
|
2009-04-16 18:34:19 +01:00
|
|
|
$fullname = $this->trimmed('fullname');
|
|
|
|
$homepage = $this->trimmed('homepage');
|
|
|
|
$bio = $this->trimmed('bio');
|
|
|
|
$location = $this->trimmed('location');
|
2019-09-11 09:25:39 +01:00
|
|
|
$autosubscribe = $this->boolean('autosubscribe');
|
2011-03-28 23:13:59 +01:00
|
|
|
$subscribe_policy = $this->trimmed('subscribe_policy');
|
2009-04-16 18:34:19 +01:00
|
|
|
$language = $this->trimmed('language');
|
|
|
|
$timezone = $this->trimmed('timezone');
|
|
|
|
$tagstring = $this->trimmed('tags');
|
|
|
|
|
|
|
|
// Some validation
|
2013-10-16 13:58:22 +01:00
|
|
|
if (!is_null($homepage) && (strlen($homepage) > 0) &&
|
2013-10-07 13:46:09 +01:00
|
|
|
!common_valid_http_url($homepage)) {
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Validation error in form for profile settings.
|
2015-07-17 11:09:24 +01:00
|
|
|
throw new ClientException(_('Homepage is not a valid URL.'));
|
2019-09-11 09:25:39 +01:00
|
|
|
} elseif (!is_null($fullname) && mb_strlen($fullname) > 191) {
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Validation error in form for profile settings.
|
2015-07-17 11:09:24 +01:00
|
|
|
throw new ClientException(_('Full name is too long (maximum 191 characters).'));
|
2019-09-11 09:25:39 +01:00
|
|
|
} elseif (Profile::bioTooLong($bio)) {
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Validation error in form for profile settings.
|
|
|
|
// TRANS: Plural form is used based on the maximum number of allowed
|
|
|
|
// TRANS: characters for the biography (%d).
|
2019-09-11 09:25:39 +01:00
|
|
|
throw new ClientException(sprintf(
|
|
|
|
_m('Bio is too long (maximum %d character).',
|
|
|
|
'Bio is too long (maximum %d characters).',
|
|
|
|
Profile::maxBio()),
|
|
|
|
Profile::maxBio()
|
|
|
|
));
|
|
|
|
} elseif (!is_null($location) && mb_strlen($location) > 191) {
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Validation error in form for profile settings.
|
2015-07-17 11:09:24 +01:00
|
|
|
throw new ClientException(_('Location is too long (maximum 191 characters).'));
|
2019-09-11 09:25:39 +01:00
|
|
|
} elseif (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Validation error in form for profile settings.
|
2015-07-17 11:09:24 +01:00
|
|
|
throw new ClientException(_('Timezone not selected.'));
|
2019-09-11 09:25:39 +01:00
|
|
|
} elseif (!is_null($language) && strlen($language) > 50) {
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Validation error in form for profile settings.
|
2015-07-17 11:09:24 +01:00
|
|
|
throw new ClientException(_('Language is too long (maximum 50 characters).'));
|
2009-04-16 18:34:19 +01:00
|
|
|
}
|
2008-12-23 19:19:07 +00:00
|
|
|
|
2011-03-06 19:13:31 +00:00
|
|
|
$tags = array();
|
|
|
|
$tag_priv = array();
|
|
|
|
if (is_string($tagstring) && strlen($tagstring) > 0) {
|
|
|
|
$tags = preg_split('/[\s,]+/', $tagstring);
|
|
|
|
|
|
|
|
foreach ($tags as &$tag) {
|
|
|
|
$private = @$tag[0] === '.';
|
|
|
|
|
|
|
|
$tag = common_canonical_tag($tag);
|
|
|
|
if (!common_valid_profile_tag($tag)) {
|
|
|
|
// TRANS: Validation error in form for profile settings.
|
|
|
|
// TRANS: %s is an invalid tag.
|
2015-07-17 11:09:24 +01:00
|
|
|
throw new ClientException(sprintf(_('Invalid tag: "%s".'), $tag));
|
2011-03-06 19:13:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$tag_priv[$tag] = $private;
|
2009-04-16 18:34:19 +01:00
|
|
|
}
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2009-01-17 22:30:44 +00:00
|
|
|
|
2015-07-17 11:09:24 +01:00
|
|
|
$user = $this->scoped->getUser();
|
2009-04-16 18:34:19 +01:00
|
|
|
$user->query('BEGIN');
|
2008-12-23 19:19:07 +00:00
|
|
|
|
2016-02-17 21:58:31 +00:00
|
|
|
// Only allow setting private_stream if site policy allows it
|
|
|
|
// (or user already _has_ a private stream, then you can unset it)
|
|
|
|
if (common_config('profile', 'allowprivate') || $user->private_stream) {
|
2019-09-11 09:25:39 +01:00
|
|
|
$private_stream = $this->boolean('private_stream');
|
2016-02-17 21:58:31 +00:00
|
|
|
} else {
|
|
|
|
// if not allowed, we set to the existing value
|
2019-09-11 09:25:39 +01:00
|
|
|
$private_stream = (bool) $user->private_stream;
|
2016-02-17 21:58:31 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 15:38:42 +01:00
|
|
|
// $user->nickname is updated through Profile->update();
|
2008-12-23 19:19:07 +00:00
|
|
|
|
2019-09-11 09:25:39 +01:00
|
|
|
if ((bool) $user->autosubscribe != $autosubscribe
|
|
|
|
|| (bool) $user->private_stream != $private_stream
|
2013-10-17 15:38:42 +01:00
|
|
|
|| $user->timezone != $timezone
|
|
|
|
|| $user->language != $language
|
|
|
|
|| $user->subscribe_policy != $subscribe_policy) {
|
2009-04-16 18:34:19 +01:00
|
|
|
$original = clone($user);
|
2008-12-23 19:19:07 +00:00
|
|
|
|
2011-03-30 21:23:13 +01:00
|
|
|
$user->autosubscribe = $autosubscribe;
|
2013-10-17 15:38:42 +01:00
|
|
|
$user->language = $language;
|
2011-03-30 21:23:13 +01:00
|
|
|
$user->private_stream = $private_stream;
|
2011-03-28 23:13:59 +01:00
|
|
|
$user->subscribe_policy = $subscribe_policy;
|
2013-10-17 15:38:42 +01:00
|
|
|
$user->timezone = $timezone;
|
2008-12-23 19:19:07 +00:00
|
|
|
|
2009-04-16 18:34:19 +01:00
|
|
|
$result = $user->update($original);
|
|
|
|
if ($result === false) {
|
|
|
|
common_log_db_error($user, 'UPDATE', __FILE__);
|
2015-07-17 11:09:24 +01:00
|
|
|
$user->query('ROLLBACK');
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Server error thrown when user profile settings could not be updated to
|
|
|
|
// TRANS: automatically subscribe to any subscriber.
|
2015-07-17 11:09:24 +01:00
|
|
|
throw new ServerException(_('Could not update user for autosubscribe or subscribe_policy.'));
|
2009-04-16 18:34:19 +01:00
|
|
|
}
|
2013-10-17 15:38:42 +01:00
|
|
|
|
|
|
|
// Re-initialize language environment if it changed
|
|
|
|
common_init_language();
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
|
|
|
|
2015-07-17 11:09:24 +01:00
|
|
|
$original = clone($this->scoped);
|
2008-12-23 19:19:07 +00:00
|
|
|
|
2015-07-17 11:09:24 +01:00
|
|
|
if (common_config('profile', 'changenick') == true && $this->scoped->getNickname() !== $nickname) {
|
2015-02-04 20:25:14 +00:00
|
|
|
assert(Nickname::normalize($nickname)===$nickname);
|
2015-07-17 11:09:24 +01:00
|
|
|
common_debug("Changing user nickname from '{$this->scoped->getNickname()}' to '{$nickname}'.");
|
|
|
|
$this->scoped->nickname = $nickname;
|
|
|
|
$this->scoped->profileurl = common_profile_url($this->scoped->getNickname());
|
2015-02-04 20:25:14 +00:00
|
|
|
}
|
2016-02-17 21:43:45 +00:00
|
|
|
$this->scoped->fullname = (mb_strlen($fullname)>0 ? $fullname : $this->scoped->nickname);
|
2015-07-17 11:09:24 +01:00
|
|
|
$this->scoped->homepage = $homepage;
|
|
|
|
$this->scoped->bio = $bio;
|
|
|
|
$this->scoped->location = $location;
|
2009-10-23 16:47:00 +01:00
|
|
|
|
|
|
|
$loc = Location::fromName($location);
|
|
|
|
|
2010-01-07 23:59:07 +00:00
|
|
|
if (empty($loc)) {
|
2015-07-17 11:09:24 +01:00
|
|
|
$this->scoped->lat = null;
|
|
|
|
$this->scoped->lon = null;
|
|
|
|
$this->scoped->location_id = null;
|
|
|
|
$this->scoped->location_ns = null;
|
2010-01-07 23:59:07 +00:00
|
|
|
} else {
|
2015-07-17 11:09:24 +01:00
|
|
|
$this->scoped->lat = $loc->lat;
|
|
|
|
$this->scoped->lon = $loc->lon;
|
|
|
|
$this->scoped->location_id = $loc->location_id;
|
|
|
|
$this->scoped->location_ns = $loc->location_ns;
|
2009-10-23 16:47:00 +01:00
|
|
|
}
|
|
|
|
|
2009-12-28 22:44:05 +00:00
|
|
|
if (common_config('location', 'share') == 'user') {
|
|
|
|
$exists = false;
|
|
|
|
|
2015-07-17 11:09:24 +01:00
|
|
|
$prefs = User_location_prefs::getKV('user_id', $this->scoped->getID());
|
2009-12-28 22:44:05 +00:00
|
|
|
|
|
|
|
if (empty($prefs)) {
|
|
|
|
$prefs = new User_location_prefs();
|
|
|
|
|
2015-07-17 11:09:24 +01:00
|
|
|
$prefs->user_id = $this->scoped->getID();
|
2009-12-28 22:44:05 +00:00
|
|
|
$prefs->created = common_sql_now();
|
|
|
|
} else {
|
|
|
|
$exists = true;
|
|
|
|
$orig = clone($prefs);
|
|
|
|
}
|
|
|
|
|
2019-09-11 09:25:39 +01:00
|
|
|
$prefs->share_location = $this->boolean('sharelocation');
|
2009-12-28 22:44:05 +00:00
|
|
|
|
|
|
|
if ($exists) {
|
|
|
|
$result = $prefs->update($orig);
|
|
|
|
} else {
|
|
|
|
$result = $prefs->insert();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($result === false) {
|
|
|
|
common_log_db_error($prefs, ($exists) ? 'UPDATE' : 'INSERT', __FILE__);
|
2015-07-17 11:09:24 +01:00
|
|
|
$user->query('ROLLBACK');
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Server error thrown when user profile location preference settings could not be updated.
|
2015-07-17 11:09:24 +01:00
|
|
|
throw new ServerException(_('Could not save location prefs.'));
|
2009-12-28 22:44:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 11:09:24 +01:00
|
|
|
common_debug('Old profile: ' . common_log_objstring($original), __FILE__);
|
|
|
|
common_debug('New profile: ' . common_log_objstring($this->scoped), __FILE__);
|
2008-12-23 19:19:07 +00:00
|
|
|
|
2015-07-17 11:09:24 +01:00
|
|
|
$result = $this->scoped->update($original);
|
2008-12-23 19:19:07 +00:00
|
|
|
|
2009-11-19 01:36:55 +00:00
|
|
|
if ($result === false) {
|
2015-07-17 11:09:24 +01:00
|
|
|
common_log_db_error($this->scoped, 'UPDATE', __FILE__);
|
|
|
|
$user->query('ROLLBACK');
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Server error thrown when user profile settings could not be saved.
|
2015-07-17 11:09:24 +01:00
|
|
|
throw new ServerException(_('Could not save profile.'));
|
2009-04-16 18:34:19 +01:00
|
|
|
}
|
2009-01-17 22:30:44 +00:00
|
|
|
|
2009-04-16 18:34:19 +01:00
|
|
|
// Set the user tags
|
2015-07-17 11:09:24 +01:00
|
|
|
$result = Profile_tag::setSelfTags($this->scoped, $tags, $tag_priv);
|
2009-01-17 22:30:44 +00:00
|
|
|
|
2009-04-16 18:34:19 +01:00
|
|
|
$user->query('COMMIT');
|
|
|
|
Event::handle('EndProfileSaveForm', array($this));
|
2008-12-23 19:19:07 +00:00
|
|
|
|
2010-10-19 23:35:39 +01:00
|
|
|
// TRANS: Confirmation shown when user profile settings are saved.
|
2015-07-17 11:09:24 +01:00
|
|
|
return _('Settings saved.');
|
2009-04-16 18:34:19 +01:00
|
|
|
}
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-11 09:25:39 +01:00
|
|
|
public function showAside()
|
|
|
|
{
|
2010-12-13 21:32:39 +00:00
|
|
|
$this->elementStart('div', array('id' => 'aside_primary',
|
|
|
|
'class' => 'aside'));
|
2011-01-17 23:04:10 +00:00
|
|
|
|
|
|
|
$this->elementStart('div', array('id' => 'account_actions',
|
|
|
|
'class' => 'section'));
|
2010-12-29 22:02:04 +00:00
|
|
|
$this->elementStart('ul');
|
|
|
|
if (Event::handle('StartProfileSettingsActions', array($this))) {
|
2015-07-17 11:09:24 +01:00
|
|
|
if ($this->scoped->hasRight(Right::BACKUPACCOUNT)) {
|
2010-12-29 22:02:04 +00:00
|
|
|
$this->elementStart('li');
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->element(
|
|
|
|
'a',
|
|
|
|
['href' => common_local_url('backupaccount')],
|
|
|
|
// TRANS: Option in profile settings to create a backup of the account of the currently logged in user.
|
|
|
|
_('Backup account')
|
|
|
|
);
|
2010-12-29 22:02:04 +00:00
|
|
|
$this->elementEnd('li');
|
|
|
|
}
|
2015-07-17 11:09:24 +01:00
|
|
|
if ($this->scoped->hasRight(Right::DELETEACCOUNT)) {
|
2010-12-29 22:02:04 +00:00
|
|
|
$this->elementStart('li');
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->element(
|
|
|
|
'a',
|
|
|
|
['href' => common_local_url('deleteaccount')],
|
|
|
|
// TRANS: Option in profile settings to delete the account of the currently logged in user.
|
|
|
|
_('Delete account')
|
|
|
|
);
|
2010-12-29 22:02:04 +00:00
|
|
|
$this->elementEnd('li');
|
|
|
|
}
|
2015-07-17 11:09:24 +01:00
|
|
|
if ($this->scoped->hasRight(Right::RESTOREACCOUNT)) {
|
2010-12-29 22:02:04 +00:00
|
|
|
$this->elementStart('li');
|
2019-09-11 09:25:39 +01:00
|
|
|
$this->element(
|
|
|
|
'a',
|
|
|
|
['href' => common_local_url('restoreaccount')],
|
|
|
|
// TRANS: Option in profile settings to restore the account of the currently logged in user from a backup.
|
|
|
|
_('Restore account')
|
|
|
|
);
|
2010-12-29 22:02:04 +00:00
|
|
|
$this->elementEnd('li');
|
|
|
|
}
|
|
|
|
Event::handle('EndProfileSettingsActions', array($this));
|
2010-12-17 23:56:48 +00:00
|
|
|
}
|
2010-12-29 22:02:04 +00:00
|
|
|
$this->elementEnd('ul');
|
2010-12-13 21:32:39 +00:00
|
|
|
$this->elementEnd('div');
|
2011-01-17 23:04:10 +00:00
|
|
|
$this->elementEnd('div');
|
2010-12-13 21:32:39 +00:00
|
|
|
}
|
2008-06-24 02:46:42 +01:00
|
|
|
}
|