3 * StatusNet, the distributed open-source microblogging tool
5 * Miscellaneous settings
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Robin Millette <millette@status.net>
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2008-2009 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 require_once INSTALLDIR.'/lib/accountsettingsaction.php';
38 * Miscellaneous settings actions
40 * Currently this just manages URL shortening.
44 * @author Robin Millette <millette@status.net>
45 * @author Zach Copley <zach@status.net>
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47 * @link http://status.net/
49 class OthersettingsAction extends AccountSettingsAction
54 * @return string Title of the page
58 // Page title for a tab in user profile settings.
59 return _('Other settings');
63 * Instructions for use
65 * @return instructions for use
68 function getInstructions()
70 // TRANS: Instructions for tab "Other" in user profile settings.
71 return _('Manage various other options.');
74 function showScripts()
76 parent::showScripts();
77 $this->autofocus('urlshorteningservice');
81 * Content area of the page
83 * Shows a form for uploading an avatar.
88 function showContent()
90 $user = common_current_user();
92 $this->elementStart('form', array('method' => 'post',
93 'id' => 'form_settings_other',
94 'class' => 'form_settings',
96 common_local_url('othersettings')));
97 $this->elementStart('fieldset');
98 $this->hidden('token', common_session_token());
99 $this->elementStart('ul', 'form_data');
101 $shorteners = array();
102 Event::handle('GetUrlShorteners', array(&$shorteners));
104 foreach($shorteners as $name=>$value)
106 $services[$name]=$name;
107 if($value['freeService']){
108 // TRANS: Used as a suffix for free URL shorteners in a dropdown list in the tab "Other" of a
109 // TRANS: user's profile settings. Use of "free" is as in "open", indicating that the
110 // TRANS: information on the shortener site is freely distributable.
111 // TRANS: This message has one space at the beginning. Use your language's word separator
112 // TRANS: here if it has one (most likely a single space).
113 $services[$name].=_(' (free service)');
120 $this->elementStart('li');
121 // TRANS: Label for dropdown with URL shortener services.
122 $this->dropdown('urlshorteningservice', _('Shorten URLs with'),
123 // TRANS: Tooltip for for dropdown with URL shortener services.
124 $services, _('Automatic shortening service to use.'),
125 false, $user->urlshorteningservice);
126 $this->elementEnd('li');
128 $this->elementStart('li');
129 // TRANS: Label for checkbox.
130 $this->checkbox('viewdesigns', _('View profile designs'),
131 // TRANS: Tooltip for checkbox.
132 $user->viewdesigns, _('Show or hide profile designs.'));
133 $this->elementEnd('li');
134 $this->elementEnd('ul');
135 // TRANS: Button text for saving "Other settings" in profile.
136 $this->submit('save', _m('BUTTON','Save'));
137 $this->elementEnd('fieldset');
138 $this->elementEnd('form');
144 * Saves the changes to url-shortening prefs and shows a success or failure
150 function handlePost()
153 $token = $this->trimmed('token');
154 if (!$token || $token != common_session_token()) {
155 $this->showForm(_('There was a problem with your session token. '.
156 'Try again, please.'));
160 $urlshorteningservice = $this->trimmed('urlshorteningservice');
162 if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
163 // TRANS: Form validation error for form "Other settings" in user profile.
164 $this->showForm(_('URL shortening service is too long (maximum 50 characters).'));
168 $viewdesigns = $this->boolean('viewdesigns');
170 $user = common_current_user();
172 assert(!is_null($user)); // should already be checked
174 $user->query('BEGIN');
176 $original = clone($user);
178 $user->urlshorteningservice = $urlshorteningservice;
179 $user->viewdesigns = $viewdesigns;
181 $result = $user->update($original);
183 if ($result === false) {
184 common_log_db_error($user, 'UPDATE', __FILE__);
185 // TRANS: Server error displayed when "Other" settings in user profile could not be updated on the server.
186 $this->serverError(_('Could not update user.'));
190 $user->query('COMMIT');
192 $this->showForm(_('Preferences saved.'), true);