]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Poll/newpoll.php
Merge branch 'master' into testing
[quix0rs-gnu-social.git] / plugins / Poll / newpoll.php
index 66386affa9a0a2b6db6869351a7a9c2dfd3a3c3c..e7d5d3dd0d6d32484d7b9cb9e4f83cada24bb1c0 100644 (file)
@@ -43,7 +43,6 @@ if (!defined('STATUSNET')) {
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  * @link      http://status.net/
  */
-
 class NewPollAction extends Action
 {
     protected $user        = null;
@@ -58,10 +57,10 @@ class NewPollAction extends Action
      *
      * @return string Action title
      */
-
     function title()
     {
-        return _('New poll');
+        // TRANS: Title for poll page.
+        return _m('New poll');
     }
 
     /**
@@ -71,7 +70,6 @@ class NewPollAction extends Action
      *
      * @return boolean true
      */
-
     function prepare($argarray)
     {
         parent::prepare($argarray);
@@ -79,7 +77,8 @@ class NewPollAction extends Action
         $this->user = common_current_user();
 
         if (empty($this->user)) {
-            throw new ClientException(_("Must be logged in to post a poll."),
+            // TRANS: Client exception thrown trying to create a poll while not logged in.
+            throw new ClientException(_m('You must be logged in to post a poll.'),
                                       403);
         }
 
@@ -105,7 +104,6 @@ class NewPollAction extends Action
      *
      * @return void
      */
-
     function handle($argarray=null)
     {
         parent::handle($argarray);
@@ -124,22 +122,34 @@ class NewPollAction extends Action
      *
      * @return void
      */
-
     function newPoll()
     {
+        if ($this->boolean('ajax')) {
+            StatusNet::setApi(true);
+        }
         try {
             if (empty($this->question)) {
-                throw new ClientException(_('Poll must have a question.'));
+            // TRANS: Client exception thrown trying to create a poll without a question.
+                throw new ClientException(_m('Poll must have a question.'));
             }
 
             if (count($this->options) < 2) {
-                throw new ClientException(_('Poll must have at least two options.'));
+                // TRANS: Client exception thrown trying to create a poll with fewer than two options.
+                throw new ClientException(_m('Poll must have at least two options.'));
             }
 
+            // Notice options; distinct from choices for the poll
+
+            $options = array();
+
+            // Does the heavy-lifting for getting "To:" information
+
+            ToSelector::fillOptions($this, $options);
 
             $saved = Poll::saveNew($this->user->getProfile(),
-                                              $this->question,
-                                              $this->options);
+                                   $this->question,
+                                   $this->options,
+                                   $options);
 
         } catch (ClientException $ce) {
             $this->error = $ce->getMessage();
@@ -147,7 +157,37 @@ class NewPollAction extends Action
             return;
         }
 
-        common_redirect($saved->bestUrl(), 303);
+        if ($this->boolean('ajax')) {
+            header('Content-Type: text/xml;charset=utf-8');
+            $this->xw->startDocument('1.0', 'UTF-8');
+            $this->elementStart('html');
+            $this->elementStart('head');
+            // TRANS: Page title after sending a notice.
+            $this->element('title', null, _m('Notice posted'));
+            $this->elementEnd('head');
+            $this->elementStart('body');
+            $this->showNotice($saved);
+            $this->elementEnd('body');
+            $this->elementEnd('html');
+        } else {
+            common_redirect($saved->bestUrl(), 303);
+        }
+    }
+
+    /**
+     * Output a notice
+     *
+     * Used to generate the notice code for Ajax results.
+     *
+     * @param Notice $notice Notice that was saved
+     *
+     * @return void
+     */
+    function showNotice($notice)
+    {
+        class_exists('NoticeList'); // @fixme hack for autoloader
+        $nli = new NoticeListItem($notice, $this);
+        $nli->show();
     }
 
     /**
@@ -155,7 +195,6 @@ class NewPollAction extends Action
      *
      * @return void
      */
-
     function showContent()
     {
         if (!empty($this->error)) {
@@ -163,7 +202,7 @@ class NewPollAction extends Action
         }
 
         $form = new NewPollForm($this,
-                                 $this->questions,
+                                 $this->question,
                                  $this->options);
 
         $form->show();
@@ -180,7 +219,6 @@ class NewPollAction extends Action
      *
      * @return boolean is read only action?
      */
-
     function isReadOnly($args)
     {
         if ($_SERVER['REQUEST_METHOD'] == 'GET' ||