X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fothersettings.php;h=8d6e0040470ff451d7f8426eeb9d6aef4ffa0b48;hb=6a848bcc8ac37066f7c4941132195d2d67d3b376;hp=d32a2d651cb390b2d248064d43543f0a233dbb9f;hpb=c911c66fe1ddb9fcea4a1817496f2efaffe26a98;p=quix0rs-gnu-social.git diff --git a/actions/othersettings.php b/actions/othersettings.php index d32a2d651c..8d6e004047 100644 --- a/actions/othersettings.php +++ b/actions/othersettings.php @@ -57,7 +57,7 @@ class OthersettingsAction extends AccountSettingsAction function title() { - return _('Other Settings'); + return _('Other settings'); } /** @@ -96,31 +96,47 @@ class OthersettingsAction extends AccountSettingsAction common_local_url('othersettings'))); $this->elementStart('fieldset'); $this->hidden('token', common_session_token()); + $this->elementStart('ul', 'form_data'); + + $shorteners = array(_('[none]') => array('freeService' => false)); + + Event::handle('GetUrlShorteners', array(&$shorteners)); - $services=array(); - global $_shorteners; - if($_shorteners){ - foreach($_shorteners as $name=>$value) - { - $services[$name]=$name; - if(!empty($value['info']['freeService'])){ - // I18N - $services[$name].=' (free service)'; - } + $services = array(); + foreach($shorteners as $name=>$value) + { + $services[$name]=$name; + if($value['freeService']){ + $services[$name].=_(' (free service)'); } } - asort($services); - $services['']='None'; - - $this->elementStart('ul', 'form_data'); + if($services) + { + asort($services); + + $this->elementStart('li'); + $this->dropdown('urlshorteningservice', _('Shorten URLs with'), + $services, _('Automatic shortening service to use.'), + false, $user->urlshorteningservice); + $this->elementEnd('li'); + } $this->elementStart('li'); - $this->dropdown('urlshorteningservice', _('Shorten URLs with'), - $services, _('Automatic shortening service to use.'), - false, $user->urlshorteningservice); + $this->input('maxurllength', + _('URL longer than'), + (!is_null($this->arg('maxurllength'))) ? + $this->arg('maxurllength') : User_urlshortener_prefs::maxUrlLength($user), + _('URLs longer than this will be shortened.')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('maxnoticelength', + _('Text longer than'), + (!is_null($this->arg('maxnoticelength'))) ? + $this->arg('maxnoticelength') : User_urlshortener_prefs::maxNoticeLength($user), + _('URLs in notices longer than this will be shortened.')); $this->elementEnd('li'); $this->elementStart('li'); $this->checkbox('viewdesigns', _('View profile designs'), - $user->viewdesigns, _('Show or hide profile designs.')); + - $user->viewdesigns, _('Show or hide profile designs.')); $this->elementEnd('li'); $this->elementEnd('ul'); $this->submit('save', _('Save')); @@ -156,6 +172,18 @@ class OthersettingsAction extends AccountSettingsAction $viewdesigns = $this->boolean('viewdesigns'); + $maxurllength = $this->trimmed('maxurllength'); + + if (!Validate::number($maxurllength, array('min' => 0))) { + throw new ClientException(_('Invalid number for max url length.')); + } + + $maxnoticelength = $this->trimmed('maxnoticelength'); + + if (!Validate::number($maxnoticelength, array('min' => 0))) { + throw new ClientException(_('Invalid number for max notice length.')); + } + $user = common_current_user(); assert(!is_null($user)); // should already be checked @@ -175,6 +203,32 @@ class OthersettingsAction extends AccountSettingsAction return; } + $prefs = User_urlshortener_prefs::getPrefs($user); + $orig = null; + + if (empty($prefs)) { + $prefs = new User_urlshortener_prefs(); + + $prefs->user_id = $user->id; + $prefs->created = common_sql_now(); + } else { + $orig = clone($prefs); + } + + $prefs->urlshorteningservice = $urlshorteningservice; + $prefs->maxurllength = $maxurllength; + $prefs->maxnoticelength = $maxnoticelength; + + if (!empty($orig)) { + $result = $prefs->update($orig); + } else { + $result = $prefs->insert(); + } + + if (!$result) { + throw new ServerException(_('Error saving user URL shortening preferences.')); + } + $user->query('COMMIT'); $this->showForm(_('Preferences saved.'), true);