Esempio n. 1
0
 /**
  * Save a new poll notice
  *
  * @param Profile $profile
  * @param string  $question
  * @param array   $opts (poll responses)
  *
  * @return Notice saved notice
  */
 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);
     if (array_key_exists('created', $options)) {
         $p->created = $options['created'];
     } else {
         $p->created = common_sql_now();
     }
     if (array_key_exists('uri', $options)) {
         $p->uri = $options['uri'];
     } else {
         $p->uri = common_local_url('showpoll', array('id' => $p->id));
     }
     common_log(LOG_DEBUG, "Saving poll: {$p->id} {$p->uri}");
     $p->insert();
     // 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);
     $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');
     $replies = array();
     $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);
     return $saved;
 }