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/
50 class OthersettingsAction extends AccountSettingsAction
55 * @return string Title of the page
60 return _('Other settings');
64 * Instructions for use
66 * @return instructions for use
69 function getInstructions()
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(_('[none]') => array('freeService' => false));
103 Event::handle('GetUrlShorteners', array(&$shorteners));
106 foreach($shorteners as $name=>$value)
108 $services[$name]=$name;
109 if($value['freeService']){
110 $services[$name].=_(' (free service)');
117 $this->elementStart('li');
118 $this->dropdown('urlshorteningservice', _('Shorten URLs with'),
119 $services, _('Automatic shortening service to use.'),
120 false, $user->urlshorteningservice);
121 $this->elementEnd('li');
123 $this->elementStart('li');
124 $this->input('maxurllength',
125 _('URL longer than'),
126 (!is_null($this->arg('maxurllength'))) ?
127 $this->arg('maxurllength') : User_urlshortener_prefs::maxUrlLength($user),
128 _('URLs longer than this will be shortened.'));
129 $this->elementEnd('li');
130 $this->elementStart('li');
131 $this->input('maxnoticelength',
132 _('Text longer than'),
133 (!is_null($this->arg('maxnoticelength'))) ?
134 $this->arg('maxnoticelength') : User_urlshortener_prefs::maxNoticeLength($user),
135 _('URLs in notices longer than this will be shortened.'));
136 $this->elementEnd('li');
137 $this->elementStart('li');
138 $this->checkbox('viewdesigns', _('View profile designs'),
139 - $user->viewdesigns, _('Show or hide profile designs.'));
140 $this->elementEnd('li');
141 $this->elementEnd('ul');
142 $this->submit('save', _('Save'));
143 $this->elementEnd('fieldset');
144 $this->elementEnd('form');
150 * Saves the changes to url-shortening prefs and shows a success or failure
156 function handlePost()
159 $token = $this->trimmed('token');
160 if (!$token || $token != common_session_token()) {
161 $this->showForm(_('There was a problem with your session token. '.
162 'Try again, please.'));
166 $urlshorteningservice = $this->trimmed('urlshorteningservice');
168 if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
169 $this->showForm(_('URL shortening service is too long (max 50 chars).'));
173 $viewdesigns = $this->boolean('viewdesigns');
175 $maxurllength = $this->trimmed('maxurllength');
177 if (!Validate::number($maxurllength, array('min' => 0))) {
178 throw new ClientException(_('Invalid number for max url length.'));
181 $maxnoticelength = $this->trimmed('maxnoticelength');
183 if (!Validate::number($maxnoticelength, array('min' => 0))) {
184 throw new ClientException(_('Invalid number for max notice length.'));
187 $user = common_current_user();
189 assert(!is_null($user)); // should already be checked
191 $user->query('BEGIN');
193 $original = clone($user);
195 $user->urlshorteningservice = $urlshorteningservice;
196 $user->viewdesigns = $viewdesigns;
198 $result = $user->update($original);
200 if ($result === false) {
201 common_log_db_error($user, 'UPDATE', __FILE__);
202 $this->serverError(_('Couldn\'t update user.'));
206 $prefs = User_urlshortener_prefs::getPrefs($user);
210 $prefs = new User_urlshortener_prefs();
212 $prefs->user_id = $user->id;
213 $prefs->created = common_sql_now();
215 $orig = clone($prefs);
218 $prefs->urlshorteningservice = $urlshorteningservice;
219 $prefs->maxurllength = $maxurllength;
220 $prefs->maxnoticelength = $maxnoticelength;
223 $result = $prefs->update($orig);
225 $result = $prefs->insert();
229 throw new ServerException(_('Error saving user URL shortening preferences.'));
232 $user->query('COMMIT');
234 $this->showForm(_('Preferences saved.'), true);