protected $needLogin = true;
protected $canPost = true;
- protected function prepare(array $args=array()) {
+ protected function prepare(array $args = []) {
parent::prepare($args);
$this->form = $this->form ?: ucfirst($this->action);
class ManagedAction extends Action
{
- protected function prepare(array $args=array())
+ protected function prepare(array $args = [])
{
if (!parent::prepare($args)) {
return false;
* @param Action $out output helper, defaults to null
*/
- function __construct(Action $out=null, array $widgetOpts=array())
+ function __construct(Action $out = null, array $widgetOpts = [])
{
$this->out = $out;
if (!array_key_exists('scoped', $widgetOpts)) {
*/
class PollPlugin extends MicroAppPlugin
{
- const PLUGIN_VERSION = '0.1.0';
+ const PLUGIN_VERSION = '0.1.1';
// @fixme which domain should we use for these namespaces?
- const POLL_OBJECT = 'http://activityschema.org/object/poll';
+ const POLL_OBJECT = 'http://activityschema.org/object/poll';
const POLL_RESPONSE_OBJECT = 'http://activityschema.org/object/poll-response';
- var $oldSaveNew = true;
+ public $oldSaveNew = true;
/**
* Database schema setup
*
- * @see Schema
+ * @return boolean hook value; true means continue processing, false means stop.
* @see ColumnDef
*
- * @return boolean hook value; true means continue processing, false means stop.
+ * @see Schema
*/
- function onCheckSchema()
+ public function onCheckSchema()
{
$schema = Schema::get();
$schema->ensureTable('poll', Poll::schemaDef());
*
* @return boolean hook value
*/
- function onEndShowStyles($action)
+ public function onEndShowStyles($action)
{
$action->cssLink($this->path('css/poll.css'));
return true;
*/
public function onRouterInitialized(URLMapper $m)
{
- $m->connect('main/poll/new',
- array('action' => 'newpoll'));
-
- $m->connect('main/poll/:id',
- array('action' => 'showpoll'),
- array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'));
-
- $m->connect('main/poll/response/:id',
- array('action' => 'showpollresponse'),
- array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'));
-
- $m->connect('main/poll/:id/respond',
- array('action' => 'respondpoll'),
- array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'));
-
- $m->connect('settings/poll',
- array('action' => 'pollsettings'));
+ $m->connect(
+ 'main/poll/new',
+ array('action' => 'newpoll')
+ );
+
+ $m->connect(
+ 'main/poll/:id',
+ array('action' => 'showpoll'),
+ array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')
+ );
+
+ $m->connect(
+ 'main/poll/response/:id',
+ array('action' => 'showpollresponse'),
+ array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')
+ );
+
+ $m->connect(
+ 'main/poll/:id/respond',
+ array('action' => 'respondpoll'),
+ array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')
+ );
+
+ $m->connect(
+ 'settings/poll',
+ array('action' => 'pollsettings')
+ );
return true;
}
*
* @param array &$versions array of version data
*
- * @return value
+ * @return bool true hook value
+ * @throws Exception
*/
- function onPluginVersion(array &$versions)
+ public function onPluginVersion(array &$versions)
{
$versions[] = array('name' => 'Poll',
- 'version' => self::PLUGIN_VERSION,
- 'author' => 'Brion Vibber',
- 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/Poll',
- 'rawdescription' =>
- // TRANS: Plugin description.
- _m('Simple extension for supporting basic polls.'));
+ 'version' => self::PLUGIN_VERSION,
+ 'author' => 'Brion Vibber',
+ 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/Poll',
+ 'rawdescription' =>
+ // TRANS: Plugin description.
+ _m('Simple extension for supporting basic polls.'));
return true;
}
- function types()
+ public function types()
{
return array(self::POLL_OBJECT, self::POLL_RESPONSE_OBJECT);
}
*
* @return boolean hook value
*/
- function deleteRelated(Notice $notice)
+ public function deleteRelated(Notice $notice)
{
$p = Poll::getByNotice($notice);
/**
* Save a poll from an activity
*
- * @param Profile $profile Profile to use as author
* @param Activity $activity Activity to save
- * @param array $options Options to pass to bookmark-saving code
+ * @param Profile $profile Profile to use as author
+ * @param array $options Options to pass to bookmark-saving code
*
* @return Notice resulting notice
+ * @throws Exception if it failed
*/
- function saveNoticeFromActivity(Activity $activity, Profile $profile, array $options=array())
+ public function saveNoticeFromActivity(Activity $activity, Profile $profile, array $options = array())
{
// @fixme
common_log(LOG_DEBUG, "XXX activity: " . var_export($activity, true));
$responseElements = $activity->entry->getElementsByTagNameNS(self::POLL_OBJECT, 'response');
if ($pollElements->length) {
$question = '';
- $opts = array();
+ $opts = [];
$data = $pollElements->item(0);
foreach ($data->getElementsByTagNameNS(self::POLL_OBJECT, 'question') as $node) {
} catch (Exception $e) {
common_log(LOG_DEBUG, "Poll save from ActivityStream data failed: " . $e->getMessage());
}
- } else if ($responseElements->length) {
+ } elseif ($responseElements->length) {
$data = $responseElements->item(0);
$pollUri = $data->getAttribute('poll');
$selection = intval($data->getAttribute('selection'));
common_log(LOG_DEBUG, "Saved Poll_response ok, notice id: " . $notice->id);
return $notice;
} catch (Exception $e) {
- common_log(LOG_DEBUG, "Poll response save fail: " . $e->getMessage());
+ common_log(LOG_DEBUG, "Poll response save fail: " . $e->getMessage());
+ // TRANS: Exception thrown trying to respond to a non-existing poll.
}
} else {
common_log(LOG_DEBUG, "YYY no poll data");
}
}
+ // If it didn't return before
+ throw new ServerException(_m('Failed to save Poll response.'));
}
- function activityObjectFromNotice(Notice $notice)
+ public function activityObjectFromNotice(Notice $notice)
{
assert($this->isMyNotice($notice));
switch ($notice->object_type) {
- case self::POLL_OBJECT:
- return $this->activityObjectFromNoticePoll($notice);
- case self::POLL_RESPONSE_OBJECT:
- return $this->activityObjectFromNoticePollResponse($notice);
- default:
- // TRANS: Exception thrown when performing an unexpected action on a poll.
- // TRANS: %s is the unexpected object type.
- throw new Exception(sprintf(_m('Unexpected type for poll plugin: %s.'), $notice->object_type));
+ case self::POLL_OBJECT:
+ return $this->activityObjectFromNoticePoll($notice);
+ case self::POLL_RESPONSE_OBJECT:
+ return $this->activityObjectFromNoticePollResponse($notice);
+ default:
+ // TRANS: Exception thrown when performing an unexpected action on a poll.
+ // TRANS: %s is the unexpected object type.
+ throw new Exception(sprintf(_m('Unexpected type for poll plugin: %s.'), $notice->object_type));
}
}
- function activityObjectFromNoticePollResponse(Notice $notice)
+ public function activityObjectFromNoticePollResponse(Notice $notice)
{
$object = new ActivityObject();
- $object->id = $notice->uri;
- $object->type = self::POLL_RESPONSE_OBJECT;
- $object->title = $notice->content;
+ $object->id = $notice->uri;
+ $object->type = self::POLL_RESPONSE_OBJECT;
+ $object->title = $notice->content;
$object->summary = $notice->content;
- $object->link = $notice->getUrl();
+ $object->link = $notice->getUrl();
$response = Poll_response::getByNotice($notice);
if ($response) {
return $object;
}
- function activityObjectFromNoticePoll(Notice $notice)
+ public function activityObjectFromNoticePoll(Notice $notice)
{
$object = new ActivityObject();
- $object->id = $notice->uri;
- $object->type = self::POLL_OBJECT;
- $object->title = $notice->content;
+ $object->id = $notice->uri;
+ $object->type = self::POLL_OBJECT;
+ $object->title = $notice->content;
$object->summary = $notice->content;
- $object->link = $notice->getUrl();
+ $object->link = $notice->getUrl();
$poll = Poll::getByNotice($notice);
if ($poll) {
* @param ActivityObject $obj
* @param XMLOutputter $out to add elements at end of object
*/
- function activityObjectOutputAtom(ActivityObject $obj, XMLOutputter $out)
+ public function activityObjectOutputAtom(ActivityObject $obj, XMLOutputter $out)
{
if (isset($obj->pollQuestion)) {
/**
* selection="3" />
*/
$data = array('xmlns:poll' => self::POLL_OBJECT,
- 'poll' => $obj->pollUri,
- 'selection' => $obj->pollSelection);
+ 'poll' => $obj->pollUri,
+ 'selection' => $obj->pollSelection);
$out->element('poll:response', $data, '');
}
}
* }
*/
$data = array('question' => $obj->pollQuestion,
- 'options' => array());
+ 'options' => array());
foreach ($obj->pollOptions as $opt) {
$data['options'][] = $opt;
}
* "selection": 3
* }
*/
- $data = array('poll' => $obj->pollUri,
- 'selection' => $obj->pollSelection);
+ $data = array('poll' => $obj->pollUri,
+ 'selection' => $obj->pollSelection);
$out['pollResponse'] = $data;
}
}
- function entryForm($out)
+ public function entryForm($out)
{
return new NewPollForm($out);
}
// @fixme is this from parent?
- function tag()
+ public function tag()
{
return 'poll';
}
- function appTitle()
+ public function appTitle()
{
// TRANS: Application title.
- return _m('APPTITLE','Poll');
+ return _m('APPTITLE', 'Poll');
}
- function onStartAddNoticeReply($nli, $parent, $child)
+ public function onStartAddNoticeReply($nli, $parent, $child)
{
// Filter out any poll responses
if ($parent->object_type == self::POLL_OBJECT &&
// Hide poll responses for @chuck
- function onEndNoticeWhoGets($notice, &$ni) {
+ public function onEndNoticeWhoGets($notice, &$ni)
+ {
if ($notice->object_type == self::POLL_RESPONSE_OBJECT) {
foreach ($ni as $id => $source) {
$user = User::getKV('id', $id);
* @return boolean hook return
*/
- function onEndAccountSettingsNav($action)
+ public function onEndAccountSettingsNav($action)
{
$action_name = $action->trimmed('action');
- $action->menuItem(common_local_url('pollsettings'),
- // TRANS: Poll plugin menu item on user settings page.
- _m('MENU', 'Polls'),
- // TRANS: Poll plugin tooltip for user settings menu item.
- _m('Configure poll behavior'),
- $action_name === 'pollsettings');
+ $action->menuItem(
+ common_local_url('pollsettings'),
+ // TRANS: Poll plugin menu item on user settings page.
+ _m('MENU', 'Polls'),
+ // TRANS: Poll plugin tooltip for user settings menu item.
+ _m('Configure poll behavior'),
+ $action_name === 'pollsettings'
+ );
return true;
}
- protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
+ protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped = null)
{
if ($stored->object_type == self::POLL_RESPONSE_OBJECT) {
parent::showNoticeContent($stored, $out, $scoped);
*/
class NewPollAction extends Action
{
- protected $user = null;
- protected $error = null;
- protected $complete = null;
+ protected $user = null;
+ protected $error = null;
+ protected $complete = null;
- protected $question = null;
- protected $options = array();
+ protected $question = null;
+ protected $options = array();
/**
* Returns the title of the action
*
* @return string Action title
+ * @throws Exception
*/
- function title()
+ public function title()
{
// TRANS: Title for poll page.
return _m('New poll');
* @return boolean true
* @throws ClientException
*/
- function prepare(array $args = [])
+ public function prepare(array $args = [])
{
parent::prepare($args);
if (empty($this->user)) {
// 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);
+ throw new ClientException(
+ _m('You must be logged in to post a poll.'),
+ 403
+ );
}
if ($this->isPost()) {
* Handler method
*
* @return void
+ * @throws ClientException
+ * @throws InvalidUrlException
+ * @throws ReflectionException
+ * @throws ServerException
*/
- function handle()
+ public function handle()
{
parent::handle();
* Add a new Poll
*
* @return void
+ * @throws ClientException
+ * @throws InvalidUrlException
+ * @throws ReflectionException
+ * @throws ServerException
*/
- function newPoll()
+ public function newPoll()
{
if ($this->boolean('ajax')) {
GNUsocial::setApi(true);
}
try {
if (empty($this->question)) {
- // TRANS: Client exception thrown trying to create a poll without a question.
+ // TRANS: Client exception thrown trying to create a poll without a question.
throw new ClientException(_m('Poll must have a question.'));
}
ToSelector::fillOptions($this, $options);
- $saved = Poll::saveNew($this->user->getProfile(),
- $this->question,
- $this->options,
- $options);
-
+ $saved = Poll::saveNew(
+ $this->user->getProfile(),
+ $this->question,
+ $this->options,
+ $options
+ );
} catch (ClientException $ce) {
$this->error = $ce->getMessage();
$this->showPage();
*
* @return void
*/
- function showNotice(Notice $notice)
+ public function showNotice(Notice $notice)
{
class_exists('NoticeList'); // @fixme hack for autoloader
$nli = new NoticeListItem($notice, $this);
*
* @return void
*/
- function showContent()
+ public function showContent()
{
if (!empty($this->error)) {
$this->element('p', 'error', $this->error);
}
- $form = new NewPollForm($this,
- $this->question,
- $this->options);
+ $form = new NewPollForm(
+ $this,
+ $this->question,
+ $this->options
+ );
$form->show();
*
* @return boolean is read only action?
*/
- function isReadOnly($args)
+ public function isReadOnly($args)
{
if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
$_SERVER['REQUEST_METHOD'] == 'HEAD') {
* @link http://status.net/
*/
-if (!defined('GNUSOCIAL')) { exit(1); }
+if (!defined('GNUSOCIAL')) {
+ exit(1);
+}
class PollSettingsAction extends SettingsAction
{
*
* @return string Page title
*/
- function title()
+ public function title()
{
// TRANS: Page title.
return _m('Poll settings');
* @return string Instructions for use
*/
- function getInstructions()
+ public function getInstructions()
{
// TRANS: Page instructions.
return _m('Set your poll preferences');
protected function getForm()
{
$prefs = User_poll_prefs::getKV('user_id', $this->scoped->getID());
- $form = new PollPrefsForm($this, $prefs);
+ $form = new PollPrefsForm($this, $prefs ? $prefs : null);
return $form;
}
}
$upp->hide_responses = $this->boolean('hide_responses');
- $upp->modified = common_sql_now();
+ $upp->modified = common_sql_now();
if ($orig instanceof User_poll_prefs) {
$upp->update($orig);
* Returns the title of the action
*
* @return string Action title
+ * @throws Exception
*/
- function title()
+ public function title()
{
// TRANS: Page title for poll response.
return _m('Poll response');
*
* @return boolean true
* @throws ClientException
+ * @throws Exception
+ * @throws Exception
*/
- function prepare(array $args = [])
+ public function prepare(array $args = [])
{
parent::prepare($args);
if ($this->boolean('ajax')) {
if (empty($this->user)) {
// TRANS: Client exception thrown trying to respond to a poll while not logged in.
- throw new ClientException(_m('You must be logged in to respond to a poll.'),
- 403);
+ throw new ClientException(
+ _m('You must be logged in to respond to a poll.'),
+ 403
+ );
}
if ($this->isPost()) {
* Handler method
*
* @return void
+ * @throws ClientException
+ * @throws ReflectionException
+ * @throws ServerException
*/
- function handle()
+ public function handle()
{
parent::handle();
* Add a new Poll
*
* @return void
+ * @throws ClientException
+ * @throws ReflectionException
+ * @throws ServerException
*/
- function respondPoll()
+ public function respondPoll()
{
try {
- $notice = Poll_response::saveNew($this->user->getProfile(),
+ Poll_response::saveNew(
+ $this->user->getProfile(),
$this->poll,
- $this->selection);
+ $this->selection
+ );
} catch (ClientException $ce) {
$this->error = $ce->getMessage();
$this->showPage();
*
* @return void
*/
- function showContent()
+ public function showContent()
{
if (!empty($this->error)) {
$this->element('p', 'error', $this->error);
*
* @return boolean is read only action?
*/
- function isReadOnly($args)
+ public function isReadOnly($args)
{
if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
$_SERVER['REQUEST_METHOD'] == 'HEAD') {
{
protected $poll = null;
- function getNotice()
+ public function getNotice()
{
$this->id = $this->trimmed('id');
*
* @return string page tile
*/
- function title()
+ public function title()
{
// TRANS: Page title for a poll.
// TRANS: %1$s is the nickname of the user that created the poll, %2$s is the poll question.
- return sprintf(_m('%1$s\'s poll: %2$s'),
- $this->user->nickname,
- $this->poll->question);
+ return sprintf(
+ _m('%1$s\'s poll: %2$s'),
+ $this->user->nickname,
+ $this->poll->question
+ );
}
/**
* @fixme combine the notice time with poll update time
*/
- function lastModified()
+ public function lastModified()
{
return Action::lastModified();
}
/**
* @fixme combine the notice time with poll update time
*/
- function etag()
+ public function etag()
{
return Action::etag();
}
*
* @see DB_DataObject
*/
-
class Poll extends Managed_DataObject
{
public $__table = 'poll'; // table name
*
* @param Notice $notice Notice to check for
*
- * @return Poll found poll or null
+ * @return get_called_class found poll or null
*/
- static function getByNotice($notice)
+ public static function getByNotice($notice)
{
return self::getKV('uri', $notice->uri);
}
- function getOptions()
+ public function getOptions()
{
return explode("\n", $this->options);
}
/**
* Is this a valid selection index?
*
- * @param numeric $selection (1-based)
+ * @param int $selection (1-based)
* @return boolean
*/
- function isValidSelection($selection)
+ public function isValidSelection($selection)
{
if ($selection != intval($selection)) {
return false;
return true;
}
- function getNotice()
+ public function getNotice()
{
return Notice::getKV('uri', $this->uri);
}
- function getUrl()
+ public function getUrl()
{
return $this->getNotice()->getUrl();
}
* Get the response of a particular user to this poll, if any.
*
* @param Profile $profile
- * @return Poll_response object or null
+ * @return get_called_class object or null
*/
- function getResponse(Profile $profile)
+ public function getResponse(Profile $profile)
{
- $pr = Poll_response::pkeyGet(array('poll_id' => $this->id,
- 'profile_id' => $profile->id));
- return $pr;
+ $pr = Poll_response::pkeyGet(array('poll_id' => $this->id,
+ 'profile_id' => $profile->id));
+ return $pr;
}
- function countResponses()
+ public function countResponses()
{
$pr = new Poll_response();
$pr->poll_id = $this->id;
* Save a new poll notice
*
* @param Profile $profile
- * @param string $question
- * @param array $opts (poll responses)
+ * @param string $question
+ * @param array $opts (poll responses)
*
+ * @param null $options
* @return Notice saved notice
+ * @throws ClientException
*/
- static function saveNew($profile, $question, $opts, $options=null)
+ public static function saveNew($profile, $question, $opts, $options = null)
{
if (empty($options)) {
$options = array();
$p = new Poll();
- $p->id = UUID::gen();
- $p->profile_id = $profile->id;
- $p->question = $question;
- $p->options = implode("\n", $opts);
+ $p->id = UUID::gen();
+ $p->profile_id = $profile->id;
+ $p->question = $question;
+ $p->options = implode("\n", $opts);
if (array_key_exists('created', $options)) {
$p->created = $options['created'];
if (array_key_exists('uri', $options)) {
$p->uri = $options['uri'];
} else {
- $p->uri = common_local_url('showpoll',
- array('id' => $p->id));
+ $p->uri = common_local_url(
+ 'showpoll',
+ array('id' => $p->id)
+ );
}
common_log(LOG_DEBUG, "Saving poll: $p->id $p->uri");
// TRANS: Notice content creating a poll.
// TRANS: %1$s is the poll question, %2$s is a link to the poll.
- $content = sprintf(_m('Poll: %1$s %2$s'),
- $question,
- $p->uri);
+ $content = sprintf(
+ _m('Poll: %1$s %2$s'),
+ $question,
+ $p->uri
+ );
$link = '<a href="' . htmlspecialchars($p->uri) . '">' . htmlspecialchars($question) . '</a>';
// TRANS: Rendered version of the notice content creating a poll.
// TRANS: %s is a link to the poll with the question as link description.
$rendered = sprintf(_m('Poll: %s'), $link);
- $tags = array('poll');
+ $tags = array('poll');
$replies = array();
- $options = array_merge(array('urls' => array(),
- 'rendered' => $rendered,
- 'tags' => $tags,
- 'replies' => $replies,
- 'object_type' => PollPlugin::POLL_OBJECT),
- $options);
+ $options = array_merge(
+ array('urls' => array(),
+ 'rendered' => $rendered,
+ 'tags' => $tags,
+ 'replies' => $replies,
+ 'object_type' => PollPlugin::POLL_OBJECT),
+ $options
+ );
if (!array_key_exists('uri', $options)) {
$options['uri'] = $p->uri;
}
- $saved = Notice::saveNew($profile->id,
- $content,
- array_key_exists('source', $options) ?
- $options['source'] : 'web',
- $options);
+ $saved = Notice::saveNew(
+ $profile->id,
+ $content,
+ array_key_exists('source', $options) ?
+ $options['source'] : 'web',
+ $options
+ );
return $saved;
}
*
* @param Notice $notice Notice to check for
*
- * @return Poll_response found response or null
+ * @return get_called_class found response or null
*/
- static function getByNotice($notice)
+ public static function getByNotice($notice)
{
return self::getKV('uri', $notice->uri);
}
/**
* Get the notice that belongs to this response...
*
- * @return Notice
+ * @return get_called_class
*/
- function getNotice()
+ public function getNotice()
{
return Notice::getKV('uri', $this->uri);
}
- function getUrl()
+ public function getUrl()
{
return $this->getNotice()->getUrl();
}
/**
*
- * @return Poll
+ * @return get_called_class
*/
- function getPoll()
+ public function getPoll()
{
return Poll::getKV('id', $this->poll_id);
}
+
/**
* Save a new poll notice
*
* @param Profile $profile
- * @param Poll $poll the poll being responded to
- * @param int $selection (1-based)
- * @param array $opts (poll responses)
- *
+ * @param Poll $poll the poll being responded to
+ * @param int $selection (1-based)
+ * @param null $options
* @return Notice saved notice
+ * @throws ClientException
*/
- static function saveNew($profile, $poll, $selection, $options=null)
+ public static function saveNew($profile, $poll, $selection, $options = null)
{
if (empty($options)) {
- $options = array();
+ $options = [];
}
if (!$poll->isValidSelection($selection)) {
$answer = $opts[$selection - 1];
$pr = new Poll_response();
- $pr->id = UUID::gen();
- $pr->profile_id = $profile->id;
- $pr->poll_id = $poll->id;
- $pr->selection = $selection;
+ $pr->id = UUID::gen();
+ $pr->profile_id = $profile->id;
+ $pr->poll_id = $poll->id;
+ $pr->selection = $selection;
if (array_key_exists('created', $options)) {
$pr->created = $options['created'];
if (array_key_exists('uri', $options)) {
$pr->uri = $options['uri'];
} else {
- $pr->uri = common_local_url('showpollresponse',
- array('id' => $pr->id));
+ $pr->uri = common_local_url(
+ 'showpollresponse',
+ array('id' => $pr->id)
+ );
}
common_log(LOG_DEBUG, "Saving poll response: $pr->id $pr->uri");
// TRANS: Notice content voting for a poll.
// TRANS: %s is the chosen option in the poll.
- $content = sprintf(_m('voted for "%s"'),
- $answer);
+ $content = sprintf(
+ _m('voted for "%s"'),
+ $answer
+ );
$link = '<a href="' . htmlspecialchars($poll->uri) . '">' . htmlspecialchars($answer) . '</a>';
// TRANS: Rendered version of the notice content voting for a poll.
// TRANS: %s a link to the poll with the chosen option as link description.
$rendered = sprintf(_m('voted for "%s"'), $link);
- $tags = array();
+ $tags = array();
- $options = array_merge(array('urls' => array(),
- 'rendered' => $rendered,
- 'tags' => $tags,
- 'reply_to' => $poll->getNotice()->id,
- 'object_type' => PollPlugin::POLL_RESPONSE_OBJECT),
- $options);
+ $options = array_merge(
+ array('urls' => array(),
+ 'rendered' => $rendered,
+ 'tags' => $tags,
+ 'reply_to' => $poll->getNotice()->id,
+ 'object_type' => PollPlugin::POLL_RESPONSE_OBJECT),
+ $options
+ );
if (!array_key_exists('uri', $options)) {
$options['uri'] = $pr->uri;
}
- $saved = Notice::saveNew($profile->id,
- $content,
- array_key_exists('source', $options) ?
- $options['source'] : 'web',
- $options);
+ $saved = Notice::saveNew(
+ $profile->id,
+ $content,
+ array_key_exists('source', $options) ?
+ $options['source'] : 'web',
+ $options
+ );
return $saved;
}
/**
* Construct a new poll form
*
- * @param HTMLOutputter $out output channel
+ * @param HTMLOutputter $out output channel
*
- * @return void
+ * @param null $question
+ * @param null $options
*/
- function __construct($out=null, $question=null, $options=null)
+ public function __construct(HTMLOutputter $out = null, $question = null, $options = null)
{
parent::__construct($out);
}
*
* @return int ID of the form
*/
- function id()
+ public function id()
{
return 'newpoll-form';
}
*
* @return string class of the form
*/
- function formClass()
+ public function formClass()
{
return 'form_settings ajax-notice';
}
*
* @return string URL of the action
*/
- function action()
+ public function action()
{
return common_local_url('newpoll');
}
*
* @return void
*/
- function formData()
+ public function formData()
{
$this->out->elementStart('fieldset', array('id' => 'newpoll-data'));
$this->out->elementStart('ul', 'form_data');
$this->li();
- $this->out->input('question',
- // TRANS: Field label on the page to create a poll.
- _m('Question'),
- $this->question,
- // TRANS: Field title on the page to create a poll.
- _m('What question are people answering?'),
- 'question',
- true); // HTML5 "required" attribute
+ $this->out->input(
+ 'question',
+ // TRANS: Field label on the page to create a poll.
+ _m('Question'),
+ $this->question,
+ // TRANS: Field title on the page to create a poll.
+ _m('What question are people answering?'),
+ 'question',
+ true
+ ); // HTML5 "required" attribute
$this->unli();
$max = 5;
$default = '';
}
$this->li();
- $this->out->input('poll-option' . ($i + 1),
- // TRANS: Field label for an answer option on the page to create a poll.
- // TRANS: %d is the option number.
- sprintf(_m('Option %d'), $i + 1),
- $default,
- null,
- 'option' . ($i + 1),
- $i<2); // HTML5 "required" attribute for 2 options
+ $this->out->input(
+ 'poll-option' . ($i + 1),
+ // TRANS: Field label for an answer option on the page to create a poll.
+ // TRANS: %d is the option number.
+ sprintf(_m('Option %d'), $i + 1),
+ $default,
+ null,
+ 'option' . ($i + 1),
+ $i < 2
+ ); // HTML5 "required" attribute for 2 options
$this->unli();
}
$this->out->elementEnd('ul');
- $toWidget = new ToSelector($this->out,
- common_current_user(),
- null);
+ $toWidget = new ToSelector(
+ $this->out,
+ common_current_user(),
+ null
+ );
$toWidget->show();
$this->out->elementEnd('fieldset');
*
* @return void
*/
- function formActions()
+ public function formActions()
{
// TRANS: Button text for saving a new poll.
$this->out->submit('poll-submit', _m('BUTTON', 'Save'), 'submit', 'submit');
<?php
-if (!defined('GNUSOCIAL')) { exit(1); }
+if (!defined('GNUSOCIAL')) {
+ exit(1);
+}
class PollPrefsForm extends Form
{
- function __construct(Action $out, User_poll_prefs $prefs=null)
+ public function __construct(Action $out, User_poll_prefs $prefs = null)
{
parent::__construct($out);
$this->prefs = $prefs;
* @return void
*/
- function formData()
+ public function formData()
{
$this->elementStart('fieldset');
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
- $this->checkbox('hide_responses',
- _('Do not deliver poll responses to my home timeline'),
- ($this->prefs instanceof User_poll_prefs && $this->prefs->hide_responses));
+ $this->checkbox(
+ 'hide_responses',
+ _('Do not deliver poll responses to my home timeline'),
+ ($this->prefs instanceof User_poll_prefs && $this->prefs->hide_responses)
+ );
$this->elementEnd('li');
$this->elementEnd('ul');
$this->elementEnd('fieldset');
* @return void
*/
- function formActions()
+ public function formActions()
{
$this->submit('submit', _('Save'));
}
* @return int ID of the form
*/
- function id()
+ public function id()
{
return 'form_poll_prefs';
}
* @return string URL to post to
*/
- function action()
+ public function action()
{
return common_local_url('pollsettings');
}
* @return string the form's class
*/
- function formClass()
+ public function formClass()
{
return 'form_settings';
}
* Construct a new poll form
*
* @param Poll $poll
- * @param HTMLOutputter $out output channel
+ * @param HTMLOutputter $out output channel
*
* @return void
*/
- function __construct(Poll $poll, HTMLOutputter $out)
+ public function __construct(Poll $poll, HTMLOutputter $out)
{
parent::__construct($out);
$this->poll = $poll;
*
* @return int ID of the form
*/
- function id()
+ public function id()
{
return 'pollresponse-form';
}
*
* @return string class of the form
*/
- function formClass()
+ public function formClass()
{
return 'form_settings ajax';
}
*
* @return string URL of the action
*/
- function action()
+ public function action()
{
return common_local_url('respondpoll', array('id' => $this->poll->id));
}
*
* @return void
*/
- function formData()
+ public function formData()
{
$poll = $this->poll;
$out = $this->out;
- $id = "poll-" . $poll->id;
$out->element('p', 'poll-question', $poll->question);
$out->elementStart('ul', 'poll-options');
foreach ($poll->getOptions() as $i => $opt) {
$out->elementStart('li');
$out->elementStart('label');
- $out->element('input', array('type' => 'radio', 'name' => 'pollselection', 'value' => $i + 1), '');
+ $out->element('input', ['type' => 'radio', 'name' => 'pollselection', 'value' => $i + 1], '');
$out->text(' ' . $opt);
$out->elementEnd('label');
$out->elementEnd('li');
*
* @return void
*/
- function formActions()
+ public function formActions()
{
// TRANS: Button text for submitting a poll response.
$this->out->submit('poll-response-submit', _m('BUTTON', 'Submit'), 'submit', 'submit');
* Construct a new poll form
*
* @param Poll $poll
- * @param HTMLOutputter $out output channel
+ * @param HTMLOutputter $out output channel
*
* @return void
*/
- function __construct(Poll $poll, HTMLOutputter $out)
+ public function __construct(Poll $poll, HTMLOutputter $out)
{
parent::__construct($out);
$this->poll = $poll;
*
* @return int ID of the form
*/
- function id()
+ public function id()
{
return 'pollresult-form';
}
*
* @return string class of the form
*/
- function formClass()
+ public function formClass()
{
return 'form_settings ajax';
}
*
* @return string URL of the action
*/
- function action()
+ public function action()
{
return common_local_url('respondpoll', array('id' => $this->poll->id));
}
*
* @return void
*/
- function formData()
+ public function formData()
{
$poll = $this->poll;
$out = $this->out;
$out->elementEnd('td');
$out->elementStart('td');
- $out->element('span', array('class' => 'poll-block',
- 'style' => "width: {$w}px"),
- "\xc2\xa0"); // nbsp
+ $out->element(
+ 'span',
+ array('class' => 'poll-block',
+ 'style' => "width: {$w}px"),
+ "\xc2\xa0"
+ ); // nbsp
$out->text($counts[$i]);
$out->elementEnd('td');
*
* @return void
*/
- function formActions()
+ public function formActions()
{
}
}