Example #1
0
 function formData()
 {
     $this->out->elementStart('fieldset', array('id' => 'new_video_data'));
     $this->out->elementStart('ul', 'form_data');
     $this->li();
     $this->out->input('url', _('URL'), null, _('URL of the video'));
     $this->unli();
     $this->out->elementEnd('ul');
     $toWidget = new ToSelector($this->out, common_current_user(), null);
     $toWidget->show();
     $this->out->elementEnd('fieldset');
 }
Example #2
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);
 }
Example #3
0
 function formData()
 {
     $this->out->elementStart('fieldset', array('id' => 'new_photo_data'));
     $this->out->elementStart('ul', 'form_data');
     $this->li();
     $this->out->input('title', _('Title'), null, _('Photo title (optional).'));
     $this->unli();
     $this->li();
     $this->out->element('input', array('name' => 'photo_upload', 'type' => 'file', 'id' => 'photo_upload'));
     $this->unli();
     $this->li();
     $this->textarea('description', _('Description'), null, _('Description of the photo (optional).'));
     $this->unli();
     $this->out->elementEnd('ul');
     $toWidget = new ToSelector($this->out, common_current_user(), null);
     $toWidget->show();
     $this->out->elementEnd('fieldset');
 }
Example #4
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);
 }
Example #5
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);
 }
Example #6
0
 /**
  * Data elements of the form
  *
  * @return void
  */
 function formData()
 {
     $this->out->elementStart('fieldset', array('id' => 'newpoll-data'));
     $this->out->elementStart('ul', 'form_data');
     $this->li();
     $this->out->input('question', _m('Question'), $this->question, _m('What question are people answering?'), 'question', true);
     // HTML5 "required" attribute
     $this->unli();
     $max = 5;
     if (count($this->options) + 1 > $max) {
         $max = count($this->options) + 2;
     }
     for ($i = 0; $i < $max; $i++) {
         // @fixme make extensible
         if (isset($this->options[$i])) {
             $default = $this->options[$i];
         } else {
             $default = '';
         }
         $this->li();
         $this->out->input('poll-option' . ($i + 1), 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->show();
     $this->out->elementEnd('fieldset');
 }
Example #7
0
 /**
  * Data elements of the form
  *
  * @return void
  */
 function formData()
 {
     $this->out->elementStart('fieldset', array('id' => 'new_bookmark_data'));
     $this->out->elementStart('ul', 'form_data');
     $this->li();
     $this->out->input('bookmark-url', _m('LABEL', 'URL'), $this->_url, null, 'url', true);
     // HTML5 "required" attribute
     $this->unli();
     if (!empty($this->_thumbnail)) {
         list($width, $height) = $this->scaleImage($this->_thumbnail->width, $this->_thumbnail->height);
         $this->out->element('img', array('src' => $this->_thumbnail->getUrl(), 'class' => 'bookmarkform-thumbnail', 'width' => $width, 'height' => $height));
     }
     $this->li();
     $this->out->input('bookmark-title', _m('LABEL', 'Title'), $this->_title, null, 'title', true);
     // HTML5 "required" attribute
     $this->unli();
     $this->li();
     $this->out->textarea('bookmark-description', _m('LABEL', 'Notes'), $this->_description, null, 'description');
     $this->unli();
     $this->li();
     $this->out->input('bookmark-tags', _m('LABEL', 'Tags'), $this->_tags, _m('Comma- or space-separated list of tags.'), 'tags');
     $this->unli();
     $this->out->elementEnd('ul');
     $toWidget = new ToSelector($this->out, common_current_user(), null);
     $toWidget->show();
     $this->out->elementEnd('fieldset');
 }
Example #8
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);
     }
 }
Example #9
0
 /**
  * Data elements of the form
  *
  * @return void
  */
 function formData()
 {
     $this->out->elementStart('fieldset', array('id' => 'new_event_data'));
     $this->out->elementStart('ul', 'form_data');
     $this->li();
     $this->out->input('event-title', _m('LABEL', 'Title'), null, _m('Title of the event.'), 'title');
     $this->unli();
     $this->li();
     $this->out->input('event-startdate', _m('LABEL', 'Start date'), null, _m('Date the event starts.'), 'startdate');
     $this->unli();
     $this->li();
     $this->out->input('event-starttime', _m('LABEL', 'Start time'), null, _m('Time the event starts.'), 'starttime');
     $this->unli();
     $this->li();
     $this->out->input('event-enddate', _m('LABEL', 'End date'), null, _m('Date the event ends.'), 'enddate');
     $this->unli();
     $this->li();
     $this->out->input('event-endtime', _m('LABEL', 'End time'), null, _m('Time the event ends.'), 'endtime');
     $this->unli();
     $this->li();
     $this->out->input('event-location', _m('LABEL', 'Location'), null, _m('Event location.'), 'location');
     $this->unli();
     $this->li();
     $this->out->input('event-url', _m('LABEL', 'URL'), null, _m('URL for more information.'), 'url');
     $this->unli();
     $this->li();
     $this->out->input('event-description', _m('LABEL', 'Description'), null, _m('Description of the event.'), 'description');
     $this->unli();
     $this->out->elementEnd('ul');
     $toWidget = new ToSelector($this->out, common_current_user(), null);
     $toWidget->show();
     $this->out->elementEnd('fieldset');
 }
Example #10
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);
     }
 }
Example #11
0
 /**
  * Data elements of the form
  *
  * @return void
  */
 function formData()
 {
     $this->out->elementStart('fieldset', array('id' => 'new_event_data'));
     // Passing in the URL of the Ajax action that the .js for this form hits
     // when selecting event start and end times. JavaScript will try to
     // use a relative path, unless explicitely told where an action is,
     // and that's a bit difficult to calculate since the event form is on
     // so many pages with different paths. It might be worth solving this
     // globally by putting the base site path in the Identifier-URL meta tag
     // or something similar, so it would be easy to calculate the exact path
     // for actions and other things in JavaScripts. -z
     $this->out->hidden('timelist_action_url', common_local_url('timelist'));
     $this->out->elementStart('ul', 'form_data');
     $this->li();
     $this->out->input('event-title', _m('LABEL', 'Title'), null, _m('Title of the event.'), 'title', true);
     // HTML5 "required" attribute
     $this->unli();
     $this->li();
     $today = new DateTime('now');
     $today->setTimezone(new DateTimeZone(common_timezone()));
     $this->out->input('event-startdate', _m('LABEL', 'Start date'), $today->format('m/d/Y'), _m('Date the event starts.'), 'startdate');
     $this->unli();
     $this->li();
     $times = EventTimeList::getTimes($today->format('m/d/Y 12:00') . ' am ' . $today->format('T'));
     $start = EventTimeList::nearestHalfHour($today->format('c'));
     $start->setTimezone(new DateTimeZone(common_timezone()));
     $this->out->dropdown('event-starttime', _m('LABEL', 'Start time'), $times, sprintf(_m("Time the event starts (%s)."), $today->format('T')), false, $start->format('g:ia'));
     // Need to keep JavaScript TZ in sync with PHP TZ
     $this->out->hidden('tz', $today->format('T'));
     $this->out->hidden('now', $today->format('F d, Y H:i:s T'));
     $this->unli();
     $this->li();
     $this->out->input('event-enddate', _m('LABEL', 'End date'), $today->format('m/d/Y'), _m('Date the event ends.'), 'enddate');
     $this->unli();
     $this->li();
     $this->out->dropdown('event-endtime', _m('LABEL', 'End time'), EventTimeList::getTimes($start->format('c'), true), _m('Time the event ends.'), false, null);
     $this->unli();
     $this->li();
     $this->out->input('event-location', _m('LABEL', 'Where?'), null, _m('Event location.'), 'location');
     $this->unli();
     $this->li();
     $this->out->input('event-url', _m('LABEL', 'URL'), null, _m('URL for more information.'), 'url');
     $this->unli();
     $this->li();
     $this->out->input('event-description', _m('LABEL', 'Description'), null, _m('Description of the event.'), 'description', true);
     // HTML5 "required" attribute
     $this->unli();
     $this->out->elementEnd('ul');
     $toWidget = new ToSelector($this->out, common_current_user(), null);
     $toWidget->show();
     $this->out->elementEnd('fieldset');
 }
 /**
  * Data elements of the form
  *
  * @return void
  */
 function formData()
 {
     $this->out->elementStart('fieldset', array('id' => 'new_blog_entry_data'));
     $this->out->elementStart('ul', 'form_data');
     $this->li();
     $this->out->input('blog-entry-title', _m('LABEL', 'Title'), null, _m('Title of the blog entry.'), 'title');
     $this->unli();
     $this->li();
     $this->out->textarea('blog-entry-content', _m('LABEL', 'Text'), null, _m('Text of the blog entry.'), 'content');
     $this->unli();
     $this->out->elementEnd('ul');
     $toWidget = new ToSelector($this->out, common_current_user(), null);
     $toWidget->show();
     $this->out->elementEnd('fieldset');
 }
Example #13
0
 /**
  * Data elements of the form
  *
  * @return void
  */
 function formData()
 {
     $this->out->elementStart('fieldset', array('id' => 'newquestion-data'));
     $this->out->elementStart('ul', 'form_data');
     $this->li();
     $this->out->input('qna-question-title', _m('LABEL', 'Title'), $this->title, _m('The title of your question.'), 'title');
     $this->unli();
     $this->li();
     $this->out->textarea('qna-question-description', _m('LABEL', 'Description'), $this->description, _m('Your question in detail.'), 'description');
     $this->unli();
     $this->out->elementEnd('ul');
     $toWidget = new ToSelector($this->out, common_current_user(), null);
     $toWidget->show();
     $this->out->elementEnd('fieldset');
 }
Example #14
0
 /**
  * Data elements
  *
  * @return void
  */
 function formData()
 {
     if (Event::handle('StartShowNoticeFormData', array($this))) {
         $this->out->element('label', array('for' => 'notice_data-text', 'id' => 'notice_data-text-label'), sprintf(_('What\'s up, %s?'), $this->user->nickname));
         // XXX: vary by defined max size
         $this->out->element('textarea', array('class' => 'notice_data-text', 'required' => 'required', 'placeholder' => $this->placeholderText(), 'cols' => 35, 'rows' => 4, 'name' => 'status_textarea'), $this->content ? $this->content : '');
         $contentLimit = Notice::maxContent();
         if ($contentLimit > 0) {
             $this->out->element('span', array('class' => 'count'), $contentLimit);
         }
         if (common_config('attachments', 'uploads')) {
             $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
             $this->out->element('label', array('class' => 'notice_data-attach', 'for' => $this->id() . '-notice_data-attach'), _('Attach'));
             // The actual input element tends to be hidden with CSS.
             $this->out->element('input', array('class' => 'notice_data-attach', 'type' => 'file', 'name' => 'attach', 'id' => $this->id() . '-notice_data-attach', 'title' => _('Attach a file.')));
         }
         if (!empty($this->actionName)) {
             $this->out->hidden('notice_return-to', $this->actionName, 'returnto');
         }
         $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
         $this->out->elementStart('div', 'to-selector');
         $toWidget = new ToSelector($this->out, $this->user, !empty($this->to_group) ? $this->to_group : $this->to_profile);
         $toWidget->show();
         $this->out->elementEnd('div');
         if ($this->profile->shareLocation()) {
             $this->out->hidden('notice_data-lat', empty($this->lat) ? empty($this->profile->lat) ? null : $this->profile->lat : $this->lat, 'lat');
             $this->out->hidden('notice_data-lon', empty($this->lon) ? empty($this->profile->lon) ? null : $this->profile->lon : $this->lon, 'lon');
             $this->out->hidden('notice_data-location_id', empty($this->location_id) ? empty($this->profile->location_id) ? null : $this->profile->location_id : $this->location_id, 'location_id');
             $this->out->hidden('notice_data-location_ns', empty($this->location_ns) ? empty($this->profile->location_ns) ? null : $this->profile->location_ns : $this->location_ns, 'location_ns');
             $this->out->elementStart('div', array('class' => 'notice_data-geo_wrap', 'data-api' => common_local_url('geocode')));
             // @fixme checkbox method allows no way to change the id without changing the name
             //$this->out->checkbox('notice_data-geo', _('Share my location'), true);
             $this->out->element('input', array('name' => 'notice_data-geo', 'type' => 'checkbox', 'class' => 'checkbox', 'id' => $this->id() . '-notice_data-geo', 'checked' => true));
             $this->out->element('label', array('class' => 'notice_data-geo', 'for' => $this->id() . '-notice_data-geo'), _('Share my location'));
             $this->out->elementEnd('div');
             // TRANS: Text to not share location for a notice in notice form.
             $share_disable_text = _('Do not share my location');
             // TRANS: Timeout error text for location retrieval in notice form.
             $error_timeout_text = _('Sorry, retrieving your geo location is taking longer than expected, please try again later');
             $this->out->inlineScript(' var NoticeDataGeo_text = {' . 'ShareDisable: ' . json_encode($share_disable_text) . ',' . 'ErrorTimeout: ' . json_encode($error_timeout_text) . '}');
         }
         Event::handle('EndShowNoticeFormData', array($this));
     }
 }
Example #15
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);
     }
 }
 /**
  * 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();
 }
Example #18
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!');
 }
 /**
  * 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);
     }
 }
Example #20
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);
     }
 }