]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/smssettings.php
Check for read vs. read-write access on OAuth authenticated API mehtods.
[quix0rs-gnu-social.git] / actions / smssettings.php
index f214997ec6f9923606f68065166a0f78cfb5d94a..751495d57aad809a548ad990a9a63bc251073ddc 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
  *
  * Settings for SMS
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Settings
- * @package   Laconica
- * @author    Evan Prodromou <evan@controlyourself.ca>
- * @copyright 2008-2009 Control Yourself, Inc.
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2008-2009 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link      http://laconi.ca/
+ * @link      http://status.net/
  */
 
-if (!defined('LACONICA')) {
+if (!defined('STATUSNET') && !defined('LACONICA')) {
     exit(1);
 }
 
-require_once INSTALLDIR.'/lib/settingsaction.php';
+require_once INSTALLDIR.'/lib/connectsettingsaction.php';
 
 /**
  * Settings for SMS
  *
  * @category Settings
- * @package  Laconica
- * @author   Evan Prodromou <evan@controlyourself.ca>
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     http://laconi.ca/
+ * @link     http://status.net/
  *
  * @see      SettingsAction
  */
 
-class SmssettingsAction extends SettingsAction
+class SmssettingsAction extends ConnectSettingsAction
 {
     /**
      * Title of the page
@@ -55,7 +55,7 @@ class SmssettingsAction extends SettingsAction
 
     function title()
     {
-        return _('SMS Settings');
+        return _('SMS settings');
     }
 
     /**
@@ -69,6 +69,12 @@ class SmssettingsAction extends SettingsAction
         return _('You can receive SMS messages through email from %%site.name%%.');
     }
 
+    function showScripts()
+    {
+        parent::showScripts();
+        $this->autofocus('sms');
+    }
+
     /**
      * Content area of the page
      *
@@ -80,83 +86,101 @@ class SmssettingsAction extends SettingsAction
 
     function showContent()
     {
+        if (!common_config('sms', 'enabled')) {
+            $this->element('div', array('class' => 'error'),
+                           _('SMS is not available.'));
+            return;
+        }
+
         $user = common_current_user();
 
         $this->elementStart('form', array('method' => 'post',
-                                          'id' => 'smssettings',
+                                          'id' => 'form_settings_sms',
+                                          'class' => 'form_settings',
                                           'action' =>
                                           common_local_url('smssettings')));
 
+        $this->elementStart('fieldset', array('id' => 'settings_sms_address'));
+        $this->element('legend', null, _('Address'));
         $this->hidden('token', common_session_token());
-        $this->element('h2', null, _('Address'));
 
         if ($user->sms) {
-            $this->elementStart('p');
             $carrier = $user->getCarrier();
-            $this->element('span', 'address confirmed',
+            $this->element('p', 'form_confirmed',
                            $user->sms . ' (' . $carrier->name . ')');
-            $this->element('span', 'input_instructions',
+            $this->element('p', 'form_guide',
                            _('Current confirmed SMS-enabled phone number.'));
             $this->hidden('sms', $user->sms);
             $this->hidden('carrier', $user->carrier);
-            $this->elementEnd('p');
             $this->submit('remove', _('Remove'));
         } else {
             $confirm = $this->getConfirmation();
             if ($confirm) {
                 $carrier = Sms_carrier::staticGet($confirm->address_extra);
-                $this->elementStart('p');
-                $this->element('span', 'address unconfirmed',
+                $this->element('p', 'form_unconfirmed',
                                $confirm->address . ' (' . $carrier->name . ')');
-                $this->element('span', 'input_instructions',
+                $this->element('p', 'form_guide',
                                _('Awaiting confirmation on this phone number.'));
                 $this->hidden('sms', $confirm->address);
                 $this->hidden('carrier', $confirm->address_extra);
-                $this->elementEnd('p');
                 $this->submit('cancel', _('Cancel'));
+
+                $this->elementStart('ul', 'form_data');
+                $this->elementStart('li');
                 $this->input('code', _('Confirmation code'), null,
                              _('Enter the code you received on your phone.'));
+                $this->elementEnd('li');
+                $this->elementEnd('ul');
                 $this->submit('confirm', _('Confirm'));
             } else {
-                $this->input('sms', _('SMS Phone number'),
+                $this->elementStart('ul', 'form_data');
+                $this->elementStart('li');
+                $this->input('sms', _('SMS phone number'),
                              ($this->arg('sms')) ? $this->arg('sms') : null,
                              _('Phone number, no punctuation or spaces, '.
                                'with area code'));
+                $this->elementEnd('li');
+                $this->elementEnd('ul');
                 $this->carrierSelect();
                 $this->submit('add', _('Add'));
             }
         }
+        $this->elementEnd('fieldset');
 
         if ($user->sms) {
-            $this->element('h2', null, _('Incoming email'));
+        $this->elementStart('fieldset', array('id' => 'settings_sms_incoming_email'));
+            $this->element('legend', null, _('Incoming email'));
 
             if ($user->incomingemail) {
-                $this->elementStart('p');
-                $this->element('span', 'address', $user->incomingemail);
-                $this->element('span', 'input_instructions',
+                $this->element('p', 'form_unconfirmed', $user->incomingemail);
+                $this->element('p', 'form_note',
                                _('Send email to this address to post new notices.'));
-                $this->elementEnd('p');
                 $this->submit('removeincoming', _('Remove'));
             }
 
-            $this->elementStart('p');
-            $this->element('span', 'input_instructions',
+            $this->element('p', 'form_guide',
                            _('Make a new email address for posting to; '.
                              'cancels the old one.'));
-            $this->elementEnd('p');
             $this->submit('newincoming', _('New'));
+            $this->elementEnd('fieldset');
         }
 
-        $this->element('h2', null, _('Preferences'));
+        $this->elementStart('fieldset', array('id' => 'settings_sms_preferences'));
+        $this->element('legend', null, _('Preferences'));
 
+        $this->elementStart('ul', 'form_data');
+        $this->elementStart('li');
         $this->checkbox('smsnotify',
                         _('Send me notices through SMS; '.
                           'I understand I may incur '.
                           'exorbitant charges from my carrier.'),
                         $user->smsnotify);
+        $this->elementEnd('li');
+        $this->elementEnd('ul');
 
         $this->submit('save', _('Save'));
 
+        $this->elementEnd('fieldset');
         $this->elementEnd('form');
     }
 
@@ -436,8 +460,9 @@ class SmssettingsAction extends SettingsAction
 
         $cnt = $carrier->find();
 
-        $this->elementStart('p');
-        $this->element('label', array('for' => 'carrier'));
+        $this->elementStart('ul', 'form_data');
+        $this->elementStart('li');
+        $this->element('label', array('for' => 'carrier'), _('Mobile carrier'));
         $this->elementStart('select', array('name' => 'carrier',
                                             'id' => 'carrier'));
         $this->element('option', array('value' => 0),
@@ -447,13 +472,14 @@ class SmssettingsAction extends SettingsAction
                            $carrier->name);
         }
         $this->elementEnd('select');
-        $this->elementEnd('p');
-        $this->element('span', 'input_instructions',
+        $this->element('p', 'form_guide',
                        sprintf(_('Mobile carrier for your phone. '.
                                  'If you know a carrier that accepts ' .
                                  'SMS over email but isn\'t listed here, ' .
                                  'send email to let us know at %s.'),
                                common_config('site', 'email')));
+        $this->elementEnd('li');
+        $this->elementEnd('ul');
     }
 
     /**
@@ -474,6 +500,58 @@ class SmssettingsAction extends SettingsAction
         }
 
         common_redirect(common_local_url('confirmaddress',
-                                         array('code' => $code)));
+                                         array('code' => $code)),
+                        303);
+    }
+
+    /**
+     * Handle a request to remove an incoming email address
+     *
+     * @return void
+     */
+
+    function removeIncoming()
+    {
+        $user = common_current_user();
+
+        if (!$user->incomingemail) {
+            $this->showForm(_('No incoming email address.'));
+            return;
+        }
+
+        $orig = clone($user);
+
+        $user->incomingemail = null;
+
+        if (!$user->updateKeys($orig)) {
+            common_log_db_error($user, 'UPDATE', __FILE__);
+            $this->serverError(_("Couldn't update user record."));
+        }
+
+        $this->showForm(_('Incoming email address removed.'), true);
+    }
+
+    /**
+     * Generate a new incoming email address
+     *
+     * @return void
+     *
+     * @see Emailsettings::newIncoming
+     */
+
+    function newIncoming()
+    {
+        $user = common_current_user();
+
+        $orig = clone($user);
+
+        $user->incomingemail = mail_new_incoming_address();
+
+        if (!$user->updateKeys($orig)) {
+            common_log_db_error($user, 'UPDATE', __FILE__);
+            $this->serverError(_("Couldn't update user record."));
+        }
+
+        $this->showForm(_('New incoming email address added.'), true);
     }
 }