Exemplo n.º 1
0
 function handlePost($args)
 {
     /*
             // Workaround for PHP returning empty $_POST and $_FILES when POST
             // length > post_max_size in php.ini
             if (empty($_FILES)
                 && empty($_POST)
                 && ($_SERVER['CONTENT_LENGTH'] > 0)
             ) {
                 $msg = _('The server was unable to handle that much POST ' .
                     'data (%s bytes) due to its current configuration.');
                 $this->showForm(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
                 return;
             } */
     $profile = $this->user->getProfile();
     $options = array();
     ToSelector::fillOptions($this, $options);
     try {
         $this->handleUpload();
     } catch (Exception $e) {
         $this->showForm($e->getMessage());
         return;
     }
     common_redirect($photo->uri, 303);
 }
Exemplo n.º 2
0
 function handlePost($args)
 {
     if (empty($this->url)) {
         throw new ClientException(_('Bad URL.'));
     }
     $profile = $this->user->getProfile();
     $options = array();
     ToSelector::fillOptions($this, $options);
     $vid = Video::saveNew($profile, $this->url, $options);
     common_redirect($vid->uri, 303);
 }
Exemplo n.º 3
0
 /**
  * Add a new bookmark
  *
  * @return void
  */
 function handlePost()
 {
     if (empty($this->title)) {
         // TRANS: Client exception thrown when trying to create a new bookmark without a title.
         throw new ClientException(_m('Bookmark must have a title.'));
     }
     if (empty($this->url)) {
         // TRANS: Client exception thrown when trying to create a new bookmark without a URL.
         throw new ClientException(_m('Bookmark must have an URL.'));
     }
     $options = array();
     ToSelector::fillOptions($this, $options);
     $saved = Bookmark::addNew($this->scoped, $this->title, $this->url, $this->tags, $this->description, $options);
 }
Exemplo n.º 4
0
 /**
  * Add a new Poll
  *
  * @return void
  */
 function newPoll()
 {
     if ($this->boolean('ajax')) {
         StatusNet::setApi(true);
     }
     try {
         if (empty($this->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) {
             // 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, $options);
     } catch (ClientException $ce) {
         $this->error = $ce->getMessage();
         $this->showPage();
         return;
     }
     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);
     }
 }
Exemplo n.º 5
0
 /**
  * Add a new event
  *
  * @return void
  */
 function newEvent()
 {
     try {
         if (empty($this->title)) {
             // TRANS: Client exception thrown when trying to post an event without providing a title.
             throw new ClientException(_m('Event must have a title.'));
         }
         if (empty($this->startTime)) {
             // TRANS: Client exception thrown when trying to post an event without providing a start time.
             throw new ClientException(_m('Event must have a start time.'));
         }
         if (empty($this->endTime)) {
             // TRANS: Client exception thrown when trying to post an event without providing an end time.
             throw new ClientException(_m('Event must have an end time.'));
         }
         if (!empty($this->url) && Validate::uri($this->url) === false) {
             // TRANS: Client exception thrown when trying to post an event with an invalid URL.
             throw new ClientException(_m('URL must be valid.'));
         }
         $options = array();
         // Does the heavy-lifting for getting "To:" information
         ToSelector::fillOptions($this, $options);
         $profile = $this->user->getProfile();
         $saved = Happening::saveNew($profile, $this->startTime, $this->endTime, $this->title, $this->location, $this->description, $this->url, $options);
         $event = Happening::fromNotice($saved);
         RSVP::saveNew($profile, $event, RSVP::POSITIVE);
     } catch (ClientException $ce) {
         if ($this->boolean('ajax')) {
             $this->outputAjaxError($ce->getMessage());
             return;
         } else {
             $this->error = $ce->getMessage();
             $this->showPage();
             return;
         }
     }
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Page title after sending a notice.
         $this->element('title', null, _m('Event saved'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $this->showNotice($saved);
         $this->elementEnd('body');
         $this->endHTML();
     } else {
         common_redirect($saved->getUrl(), 303);
     }
 }
Exemplo n.º 6
0
 /**
  * Add a new Question
  *
  * @return void
  */
 function newQuestion()
 {
     if ($this->boolean('ajax')) {
         GNUsocial::setApi(true);
     }
     try {
         if (empty($this->title)) {
             // TRANS: Client exception thrown trying to create a question without a title.
             throw new ClientException(_m('Question must have a title.'));
         }
         // Notice options
         $options = array();
         // Does the heavy-lifting for getting "To:" information
         ToSelector::fillOptions($this, $options);
         $saved = QnA_Question::saveNew($this->user->getProfile(), $this->title, $this->description, $options);
     } catch (ClientException $ce) {
         $this->error = $ce->getMessage();
         $this->showPage();
         return;
     }
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Page title after sending a notice.
         $this->element('title', null, _m('Question posted'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $this->showNotice($saved);
         $this->elementEnd('body');
         $this->endHTML();
     } else {
         common_redirect($saved->getUrl(), 303);
     }
 }
 /**
  * Handle the request
  *
  * Make a new notice for the update, save it, and show it
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->clientError(_('This method requires a POST.'), 400, $this->format);
         return;
     }
     // Workaround for PHP returning empty $_POST and $_FILES when POST
     // length > post_max_size in php.ini
     if (empty($_FILES) && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) {
         // TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit.
         // TRANS: %s is the number of bytes of the CONTENT_LENGTH.
         $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.', 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', intval($_SERVER['CONTENT_LENGTH']));
         $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
         return;
     }
     if (empty($this->status)) {
         $this->clientError(_('Client must provide a \'status\' parameter with a value.'), 400, $this->format);
         return;
     }
     if (empty($this->auth_user)) {
         // TRANS: Client error displayed when updating a status for a non-existing user.
         $this->clientError(_('No such user.'), 404, $this->format);
         return;
     }
     $status_shortened = $this->auth_user->shortenlinks($this->status);
     if (Notice::contentTooLong($status_shortened)) {
         // Note: Twitter truncates anything over 140, flags the status
         // as "truncated."
         $this->clientError(sprintf(_m('That\'s too long. Maximum notice size is %d character.', 'That\'s too long. Maximum notice size is %d characters.', Notice::maxContent()), Notice::maxContent()), 406, $this->format);
         return;
     }
     // Check for commands
     $inter = new CommandInterpreter();
     $cmd = $inter->handle_command($this->auth_user, $status_shortened);
     if ($cmd) {
         if ($this->supported($cmd)) {
             $cmd->execute(new Channel());
         }
         // Cmd not supported?  Twitter just returns your latest status.
         // And, it returns your last status whether the cmd was successful
         // or not!
         $this->notice = $this->auth_user->getCurrentNotice();
     } else {
         $reply_to = null;
         if (!empty($this->in_reply_to_status_id)) {
             // Check whether notice actually exists
             $reply = Notice::staticGet($this->in_reply_to_status_id);
             if ($reply) {
                 $reply_to = $this->in_reply_to_status_id;
             } else {
                 $this->clientError(_('Parent notice not found.'), $code = 404, $this->format);
                 return;
             }
         }
         if (!empty($this->link)) {
             try {
                 $post_url_file = MediaFile::fromLink($this->link, $this->auth_user);
             } catch (Exception $e) {
                 $this->clientError($e->getMessage(), $e->getCode(), $this->format);
                 return;
             }
         }
         $upload2 = null;
         try {
             $upload2 = MediaFile::fromUpload('media2', $this->auth_user);
         } catch (Exception $e) {
             $this->clientError($e->getMessage(), $e->getCode(), $this->format);
             return;
         }
         $upload = null;
         try {
             $upload = MediaFile::fromUpload('media', $this->auth_user);
         } catch (Exception $e) {
             $this->clientError($e->getMessage(), $e->getCode(), $this->format);
             return;
         }
         if (isset($upload)) {
             if (Notice::contentTooLong($status_shortened)) {
                 $upload->delete();
                 // TRANS: Client error displayed exceeding the maximum notice length.
                 // TRANS: %d is the maximum lenth for a notice.
                 $msg = _m('Maximum notice size is %d character, including attachment URL.', 'Maximum notice size is %d characters, including attachment URL.', Notice::maxContent());
                 $this->clientError(sprintf($msg, Notice::maxContent()), 400, $this->format);
             }
         }
         $content = html_entity_decode($status_shortened, ENT_NOQUOTES, 'UTF-8');
         $options = array('reply_to' => $reply_to);
         if ($this->auth_user->shareLocation()) {
             $locOptions = Notice::locationOptions($this->lat, $this->lon, null, null, $this->auth_user->getProfile());
             $options = array_merge($options, $locOptions);
         }
         //dyg add to response to group_id request
         ToSelector::fillOptions($this, $options);
         //end
         if (!empty($this->html_status)) {
             $options['rendered'] = $this->html_status;
         }
         $created = $this->trimmed('created');
         if (!empty($created)) {
             $options['created'] = $created;
         }
         try {
             $this->notice = Notice::saveNew($this->auth_user->id, $content, $this->source, $options);
         } catch (Exception $e) {
             $this->clientError($e->getMessage(), $e->getCode(), $this->format);
             return;
         }
         if (isset($upload)) {
             $upload->attachToNotice($this->notice);
         }
         if (isset($upload2)) {
             $upload2->attachToNotice($this->notice);
         }
         if (isset($post_url_file)) {
             $post_url_file->attachToNotice($this->notice);
         }
     }
     $this->showNotice();
 }
Exemplo n.º 8
0
 /**
  * This doPost saves a new notice, based on arguments
  *
  * If successful, will show the notice, or return an Ajax-y result.
  * If not, it will show an error message -- possibly Ajax-y.
  *
  * Also, if the notice input looks like a command, it will run the
  * command and show the results -- again, possibly ajaxy.
  *
  * @return void
  */
 protected function doPost()
 {
     assert($this->scoped instanceof Profile);
     // XXX: maybe an error instead...
     $user = $this->scoped->getUser();
     $content = $this->trimmed('status_textarea');
     $options = array();
     Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
     if (empty($content)) {
         // TRANS: Client error displayed trying to send a notice without content.
         $this->clientError(_('No content!'));
     }
     $inter = new CommandInterpreter();
     $cmd = $inter->handle_command($user, $content);
     if ($cmd) {
         if (GNUsocial::isAjax()) {
             $cmd->execute(new AjaxWebChannel($this));
         } else {
             $cmd->execute(new WebChannel($this));
         }
         return;
     }
     $content_shortened = $user->shortenLinks($content);
     if (Notice::contentTooLong($content_shortened)) {
         // TRANS: Client error displayed when the parameter "status" is missing.
         // TRANS: %d is the maximum number of character for a notice.
         $this->clientError(sprintf(_m('That\'s too long. Maximum notice size is %d character.', 'That\'s too long. Maximum notice size is %d characters.', Notice::maxContent()), Notice::maxContent()));
     }
     $replyto = $this->int('inreplyto');
     if ($replyto) {
         $options['reply_to'] = $replyto;
     }
     $upload = null;
     try {
         // throws exception on failure
         $upload = MediaFile::fromUpload('attach', $this->scoped);
         if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options))) {
             $content_shortened .= ' ' . $upload->shortUrl();
         }
         Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options));
         if (Notice::contentTooLong($content_shortened)) {
             $upload->delete();
             // TRANS: Client error displayed exceeding the maximum notice length.
             // TRANS: %d is the maximum length for a notice.
             $this->clientError(sprintf(_m('Maximum notice size is %d character, including attachment URL.', 'Maximum notice size is %d characters, including attachment URL.', Notice::maxContent()), Notice::maxContent()));
         }
     } catch (NoUploadedMediaException $e) {
         // simply no attached media to the new notice
     }
     if ($this->scoped->shareLocation()) {
         // use browser data if checked; otherwise profile data
         if ($this->arg('notice_data-geo')) {
             $locOptions = Notice::locationOptions($this->trimmed('lat'), $this->trimmed('lon'), $this->trimmed('location_id'), $this->trimmed('location_ns'), $this->scoped);
         } else {
             $locOptions = Notice::locationOptions(null, null, null, null, $this->scoped);
         }
         $options = array_merge($options, $locOptions);
     }
     $author_id = $this->scoped->id;
     $text = $content_shortened;
     // Does the heavy-lifting for getting "To:" information
     ToSelector::fillOptions($this, $options);
     if (Event::handle('StartNoticeSaveWeb', array($this, &$author_id, &$text, &$options))) {
         $this->stored = Notice::saveNew($this->scoped->id, $content_shortened, 'web', $options);
         if ($upload instanceof MediaFile) {
             $upload->attachToNotice($this->stored);
         }
         Event::handle('EndNoticeSaveWeb', array($this, $this->stored));
     }
     Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content_shortened, &$options));
     if (!GNUsocial::isAjax()) {
         $url = common_local_url('shownotice', array('notice' => $this->stored->id));
         common_redirect($url, 303);
     }
     return _('Saved the notice!');
 }
Exemplo n.º 9
0
 /**
  * Add a new bookmark
  *
  * @return void
  */
 function newBookmark()
 {
     try {
         if (empty($this->title)) {
             // TRANS: Client exception thrown when trying to create a new bookmark without a title.
             throw new ClientException(_m('Bookmark must have a title.'));
         }
         if (empty($this->url)) {
             // TRANS: Client exception thrown when trying to create a new bookmark without a URL.
             throw new ClientException(_m('Bookmark must have an URL.'));
         }
         $options = array();
         ToSelector::fillOptions($this, $options);
         $saved = Bookmark::saveNew($this->user->getProfile(), $this->title, $this->url, $this->tags, $this->description, $options);
     } catch (ClientException $ce) {
         if ($this->boolean('ajax')) {
             throw $ce;
         } else {
             $this->error = $ce->getMessage();
             $this->showPage();
             return;
         }
     }
     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 posting a bookmark.
         $this->element('title', null, _m('Bookmark posted'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $this->showNotice($saved);
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect($saved->bestUrl(), 303);
     }
 }
Exemplo n.º 10
0
 /**
  * Handler method
  *
  * @param array $argarray is ignored since it's now passed in in prepare()
  *
  * @return void
  */
 function handle($argarray = null)
 {
     $options = array();
     // Does the heavy-lifting for getting "To:" information
     ToSelector::fillOptions($this, $options);
     $options['source'] = 'web';
     $profile = $this->user->getProfile();
     $saved = Blog_entry::saveNew($profile, $this->title, $this->content, $options);
     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('Blog entry saved'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $nli = new NoticeListItem($saved, $this);
         $nli->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect($saved->bestUrl(), 303);
     }
 }
Exemplo n.º 11
0
 /**
  * Save a new notice, based on arguments
  *
  * If successful, will show the notice, or return an Ajax-y result.
  * If not, it will show an error message -- possibly Ajax-y.
  *
  * Also, if the notice input looks like a command, it will run the
  * command and show the results -- again, possibly ajaxy.
  *
  * @return void
  */
 function saveNewNotice()
 {
     $user = common_current_user();
     assert($user);
     // XXX: maybe an error instead...
     $content = $this->trimmed('status_textarea');
     $options = array();
     Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
     if (!$content) {
         // TRANS: Client error displayed trying to send a notice without content.
         $this->clientError(_('No content!'));
         return;
     }
     $inter = new CommandInterpreter();
     $cmd = $inter->handle_command($user, $content);
     if ($cmd) {
         if ($this->boolean('ajax')) {
             $cmd->execute(new AjaxWebChannel($this));
         } else {
             $cmd->execute(new WebChannel($this));
         }
         return;
     }
     $content_shortened = $user->shortenLinks($content);
     if (Notice::contentTooLong($content_shortened)) {
         // TRANS: Client error displayed when the parameter "status" is missing.
         // TRANS: %d is the maximum number of character for a notice.
         $this->clientError(sprintf(_m('That\'s too long. Maximum notice size is %d character.', 'That\'s too long. Maximum notice size is %d characters.', Notice::maxContent()), Notice::maxContent()));
     }
     $replyto = intval($this->trimmed('inreplyto'));
     if ($replyto) {
         $options['reply_to'] = $replyto;
     }
     $upload = null;
     $upload = MediaFile::fromUpload('attach');
     if (isset($upload)) {
         if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options))) {
             $content_shortened .= ' ' . $upload->shortUrl();
         }
         Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options));
         if (Notice::contentTooLong($content_shortened)) {
             $upload->delete();
             // TRANS: Client error displayed exceeding the maximum notice length.
             // TRANS: %d is the maximum length for a notice.
             $this->clientError(sprintf(_m('Maximum notice size is %d character, including attachment URL.', 'Maximum notice size is %d characters, including attachment URL.', Notice::maxContent()), Notice::maxContent()));
         }
     }
     if ($user->shareLocation()) {
         // use browser data if checked; otherwise profile data
         if ($this->arg('notice_data-geo')) {
             $locOptions = Notice::locationOptions($this->trimmed('lat'), $this->trimmed('lon'), $this->trimmed('location_id'), $this->trimmed('location_ns'), $user->getProfile());
         } else {
             $locOptions = Notice::locationOptions(null, null, null, null, $user->getProfile());
         }
         $options = array_merge($options, $locOptions);
     }
     $author_id = $user->id;
     $text = $content_shortened;
     // Does the heavy-lifting for getting "To:" information
     ToSelector::fillOptions($this, $options);
     if (Event::handle('StartNoticeSaveWeb', array($this, &$author_id, &$text, &$options))) {
         $notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
         if (isset($upload)) {
             $upload->attachToNotice($notice);
         }
         Event::handle('EndNoticeSaveWeb', array($this, $notice));
     }
     Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content_shortened, &$options));
     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, _('Notice posted'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $this->showNotice($notice);
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         $returnto = $this->trimmed('returnto');
         if ($returnto) {
             $url = common_local_url($returnto, array('nickname' => $user->nickname));
         } else {
             $url = common_local_url('shownotice', array('notice' => $notice->id));
         }
         common_redirect($url, 303);
     }
 }