]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/othersettings.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / actions / othersettings.php
index 13460a4bfbd4822fd922e99066a7ebe7ada716b1..4dfc5c28402a9068e02abd4394fdc9a9c957642e 100644 (file)
@@ -98,8 +98,10 @@ class OthersettingsAction extends AccountSettingsAction
         $this->hidden('token', common_session_token());
         $this->elementStart('ul', 'form_data');
 
-        $shorteners = array();
+        $shorteners = array(_('[none]') => array('freeService' => false));
+
         Event::handle('GetUrlShorteners', array(&$shorteners));
+
         $services = array();
         foreach($shorteners as $name=>$value)
         {
@@ -124,10 +126,23 @@ class OthersettingsAction extends AccountSettingsAction
             $this->elementEnd('li');
         }
         $this->elementStart('li');
+        $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');
         // TRANS: Label for checkbox.
         $this->checkbox('viewdesigns', _('View profile designs'),
-                        // TRANS: Tooltip for checkbox.
-                        $user->viewdesigns, _('Show or hide profile designs.'));
+                         -                        $user->viewdesigns, _('Show or hide profile designs.'));
         $this->elementEnd('li');
         $this->elementEnd('ul');
         // TRANS: Button text for saving "Other settings" in profile.
@@ -165,6 +180,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
@@ -185,6 +212,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);