* @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;
*
* @return string Action title
*/
-
function title()
{
- return _('New poll');
+ // TRANS: Title for poll page.
+ return _m('New poll');
}
/**
*
* @return boolean true
*/
-
function prepare($argarray)
{
parent::prepare($argarray);
$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);
}
*
* @return void
*/
-
function handle($argarray=null)
{
parent::handle($argarray);
*
* @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();
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();
}
/**
*
* @return void
*/
-
function showContent()
{
if (!empty($this->error)) {
}
$form = new NewPollForm($this,
- $this->questions,
+ $this->question,
$this->options);
$form->show();
*
* @return boolean is read only action?
*/
-
function isReadOnly($args)
{
if ($_SERVER['REQUEST_METHOD'] == 'GET' ||