function onEndShowScripts($action)
 {
     $action->inlineScript('var Notice_maxContent = ' . Notice::maxContent());
     if (common_logged_in()) {
         $action->script($this->path('shorten.js'));
     }
 }
 function onEndShowScripts($action)
 {
     $action->inlineScript('var Notice_maxContent = ' . Notice::maxContent());
     if (common_logged_in()) {
         $action->script('plugins/ClientSideShorten/shorten.js');
     }
 }
Esempio n. 3
0
 function handle_message($rawmessage)
 {
     list($from, $to, $msg, $attachments) = $this->parse_message($rawmessage);
     if (!$from || !$to || !$msg) {
         // TRANS: Error message in incoming mail handler used when an incoming e-mail cannot be processed.
         $this->error(null, _('Could not parse message.'));
     }
     common_log(LOG_INFO, "Mail from {$from} to {$to} with " . count($attachments) . ' attachment(s): ' . substr($msg, 0, 20));
     $user = $this->user_from_header($from);
     if (!$user) {
         // TRANS: Error message in incoming mail handler used when an incoming e-mail is not from a registered user.
         $this->error($from, _('Not a registered user.'));
         return false;
     }
     if (!$this->user_match_to($user, $to)) {
         // TRANS: Error message in incoming mail handler used when an incoming e-mail is not from a user's incoming e-mail address.
         $this->error($from, _('Sorry, that is not your incoming email address.'));
         return false;
     }
     if (!$user->emailpost) {
         // TRANS: Error message in incoming mail handler used when no incoming e-mail is allowed.
         $this->error($from, _('Sorry, no incoming email allowed.'));
         return false;
     }
     $response = $this->handle_command($user, $from, $msg);
     if ($response) {
         return true;
     }
     $msg = $this->cleanup_msg($msg);
     $msg = $user->shortenLinks($msg);
     if (Notice::contentTooLong($msg)) {
         // TRANS: Error message in incoming mail handler used when an incoming e-mail contains too many characters.
         $this->error($from, 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()));
     }
     $mediafiles = array();
     foreach ($attachments as $attachment) {
         $mf = null;
         try {
             $mf = MediaFile::fromFileHandle($attachment, $user);
         } catch (ClientException $ce) {
             $this->error($from, $ce->getMessage());
         }
         $msg .= ' ' . $mf->shortUrl();
         array_push($mediafiles, $mf);
         fclose($attachment);
     }
     $err = $this->add_notice($user, $msg, $mediafiles);
     if (is_string($err)) {
         $this->error($from, $err);
         return false;
     } else {
         return true;
     }
 }
 static function maxNoticeLength($user)
 {
     $def = common_config('url', 'maxnoticelength');
     if ($def == -1) {
         $def = Notice::maxContent();
     }
     $prefs = self::getPrefs($user);
     if (empty($prefs)) {
         return $def;
     } else {
         return $prefs->maxnoticelength;
     }
 }
 static function maxNoticeLength($user)
 {
     $def = common_config('url', 'maxnoticelength');
     if ($def == -1) {
         /*
          * maxContent==0 means infinite length,
          * but maxNoticeLength==0 means "always shorten"
          * so if maxContent==0 we must set this to -1
          */
         $def = Notice::maxContent() ?: -1;
     }
     $prefs = self::getPrefs($user);
     if (empty($prefs)) {
         return $def;
     } else {
         return $prefs->maxnoticelength;
     }
 }
Esempio n. 6
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!');
 }
Esempio n. 7
0
function common_shorten_links($text)
{
    $maxLength = Notice::maxContent();
    if ($maxLength == 0 || mb_strlen($text) <= $maxLength) {
        return $text;
    }
    return common_replace_urls_callback($text, array('File_redirection', 'makeShort'));
}
 /**
  * Handle the request
  *
  * Make a new notice for the update, save it, and show it
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     // 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']));
     }
     if (empty($this->status)) {
         // TRANS: Client error displayed when the parameter "status" is missing.
         $this->clientError(_('Client must provide a \'status\' parameter with a value.'));
     }
     if (is_null($this->scoped)) {
         // TRANS: Client error displayed when updating a status for a non-existing user.
         $this->clientError(_('No such user.'), 404);
     }
     /* Do not call shortenLinks until the whole notice has been build */
     // Check for commands
     $inter = new CommandInterpreter();
     $cmd = $inter->handle_command($this->auth_user, $this->status);
     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::getKV($this->in_reply_to_status_id);
             if ($reply) {
                 $reply_to = $this->in_reply_to_status_id;
             } else {
                 // TRANS: Client error displayed when replying to a non-existing notice.
                 $this->clientError(_('Parent notice not found.'), 404);
             }
         }
         $upload = null;
         try {
             $upload = MediaFile::fromUpload('media', $this->scoped);
             $this->status .= ' ' . $upload->shortUrl();
             /* Do not call shortenLinks until the whole notice has been build */
         } catch (NoUploadedMediaException $e) {
             // There was no uploaded media for us today.
         }
         /* Do call shortenlinks here & check notice length since notice is about to be saved & sent */
         $status_shortened = $this->auth_user->shortenLinks($this->status);
         if (Notice::contentTooLong($status_shortened)) {
             if ($upload instanceof MediaFile) {
                 $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());
             /* Use HTTP 413 error code (Request Entity Too Large)
              * instead of basic 400 for better understanding
              */
             $this->clientError(sprintf($msg, Notice::maxContent()), 413);
         }
         $content = html_entity_decode($status_shortened, ENT_NOQUOTES, 'UTF-8');
         $options = array('reply_to' => $reply_to);
         if ($this->scoped->shareLocation()) {
             $locOptions = Notice::locationOptions($this->lat, $this->lon, null, null, $this->scoped);
             $options = array_merge($options, $locOptions);
         }
         try {
             $this->notice = Notice::saveNew($this->scoped->id, $content, $this->source, $options);
         } catch (Exception $e) {
             $this->clientError($e->getMessage(), $e->getCode());
         }
         if (isset($upload)) {
             $upload->attachToNotice($this->notice);
         }
     }
     $this->showNotice();
 }
Esempio n. 9
0
 function onStartShowNoticeFormData($form)
 {
     if (!$this->serveMobile) {
         return true;
     }
     $form->out->element('textarea', array('id' => 'notice_data-text', 'cols' => 15, 'rows' => 4, 'name' => 'status_textarea'), $form->content ? $form->content : '');
     $contentLimit = Notice::maxContent();
     if ($contentLimit > 0) {
         $form->out->element('div', array('id' => 'notice_text-count'), $contentLimit);
     }
     if (common_config('attachments', 'uploads')) {
         if ($this->mobileFeatures['inputfiletype']) {
             $form->out->element('label', array('for' => 'notice_data-attach'), _('Attach'));
             $form->out->element('input', array('id' => 'notice_data-attach', 'type' => 'file', 'name' => 'attach', 'title' => _('Attach a file')));
             $form->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
         }
     }
     if ($form->action) {
         $form->out->hidden('notice_return-to', $form->action, 'returnto');
     }
     $form->out->hidden('notice_in-reply-to', $form->inreplyto, 'inreplyto');
     return false;
 }
Esempio n. 10
0
/**
 * Find and shorten links in a given chunk of text if it's longer than the
 * configured notice content limit (or unconditionally).
 *
 * Side effects: may save file and file_redirection records for referenced URLs.
 *
 * Pass the $user option or call $user->shortenLinks($text) to ensure the proper
 * user's options are used; otherwise the current web session user's setitngs
 * will be used or ur1.ca if there is no active web login.
 *
 * @param string $text
 * @param boolean $always (optional)
 * @param User $user (optional)
 *
 * @return string
 */
function common_shorten_links($text, $always = false, User $user = null)
{
    $maxLength = Notice::maxContent();
    if (!$always && ($maxLength == 0 || mb_strlen($text) <= $maxLength)) {
        return $text;
    }
    return common_replace_urls_callback($text, array('File_redirection', 'makeShort'), $user);
}
Esempio n. 11
0
 static function saveNew($profile, $title, $content, $options = null)
 {
     if (is_null($options)) {
         $options = array();
     }
     $be = new Blog_entry();
     $be->id = (string) new UUID();
     $be->profile_id = $profile->id;
     $be->title = $title;
     // Note: not HTML-protected
     $be->content = self::purify($content);
     if (array_key_exists('summary', $options)) {
         $be->summary = self::purify($options['summary']);
     } else {
         // Already purified
         $be->summary = self::summarize($be->content);
     }
     // Don't save an identical summary
     if ($be->summary == $be->content) {
         $be->summary = null;
     }
     $url = common_local_url('showblogentry', array('id' => $be->id));
     if (!array_key_exists('uri', $options)) {
         $options['uri'] = $url;
     }
     $be->uri = $options['uri'];
     if (!array_key_exists('url', $options)) {
         $options['url'] = $url;
     }
     $be->url = $options['url'];
     if (!array_key_exists('created', $options)) {
         $be->created = common_sql_now();
     }
     $be->created = $options['created'];
     $be->modified = common_sql_now();
     $be->insert();
     // Use user's preferences for short URLs, if possible
     try {
         $user = $profile->getUser();
         $shortUrl = File_redirection::makeShort($url, empty($user) ? null : $user);
     } catch (Exception $e) {
         // Don't let this stop us.
         $shortUrl = $url;
     }
     // XXX: this might be too long.
     if (!empty($be->summary)) {
         $options['rendered'] = $be->summary . ' ' . XMLStringer::estring('a', array('href' => $url, 'class' => 'blog-entry'), _('More...'));
         $text = html_entity_decode(strip_tags($be->summary), ENT_QUOTES, 'UTF-8');
     } else {
         $options['rendered'] = $be->content;
         $text = html_entity_decode(strip_tags($be->content), ENT_QUOTES, 'UTF-8');
     }
     if (Notice::contentTooLong($text)) {
         $text = substr($text, 0, Notice::maxContent() - mb_strlen($shortUrl) - 2) . '… ' . $shortUrl;
     }
     // Override this no matter what.
     $options['object_type'] = self::TYPE;
     $source = array_key_exists('source', $options) ? $options['source'] : 'web';
     $saved = Notice::saveNew($profile->id, $text, $source, $options);
     return $saved;
 }
Esempio n. 12
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));
     }
 }
Esempio n. 13
0
 /**
  * Save a new question notice
  *
  * @param Profile $profile
  * @param string  $question
  * @param string  $title
  * @param string  $description
  * @param array   $option // and whatnot
  *
  * @return Notice saved notice
  */
 static function saveNew($profile, $title, $description, $options = array())
 {
     $q = new QnA_Question();
     $q->id = UUID::gen();
     $q->profile_id = $profile->id;
     $q->title = $title;
     $q->description = $description;
     if (array_key_exists('created', $options)) {
         $q->created = $options['created'];
     } else {
         $q->created = common_sql_now();
     }
     if (array_key_exists('uri', $options)) {
         $q->uri = $options['uri'];
     } else {
         $q->uri = common_local_url('qnashowquestion', array('id' => $q->id));
     }
     common_log(LOG_DEBUG, "Saving question: {$q->id} {$q->uri}");
     $q->insert();
     if (Notice::contentTooLong($q->title . ' ' . $q->uri)) {
         $max = Notice::maxContent();
         $uriLen = mb_strlen($q->uri);
         $targetLen = $max - ($uriLen + 15);
         $title = mb_substr($q->title, 0, $targetLen) . '…';
     }
     $content = $title . ' ' . $q->uri;
     $link = '<a href="' . htmlspecialchars($q->uri) . '">' . htmlspecialchars($q->title) . '</a>';
     // TRANS: Rendered version of the notice content creating a question.
     // TRANS: %s a link to the question as link description.
     $rendered = sprintf(_m('Question: %s'), $link);
     $tags = array('question');
     $replies = array();
     $options = array_merge(array('urls' => array(), 'rendered' => $rendered, 'tags' => $tags, 'replies' => $replies, 'object_type' => self::OBJECT_TYPE), $options);
     if (!array_key_exists('uri', $options)) {
         $options['uri'] = $q->uri;
     }
     $saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options);
     return $saved;
 }
Esempio n. 14
0
 static function shorten($content, $notice)
 {
     $short = null;
     if (Notice::contentTooLong($content)) {
         common_debug("content too long");
         $max = Notice::maxContent();
         // TRANS: Link description for link to full notice text if it is longer than
         // TRANS: what will be dispplayed.
         $ellipsis = _m('…');
         $short = mb_substr($content, 0, $max - 1);
         $short .= sprintf('<a href="%1$s" rel="more" title="%2$s">%3$s</a>', $notice->getUrl(), _m('more...'), $ellipsis);
     } else {
         $short = $content;
     }
     return $short;
 }
 /**
  * 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();
 }
Esempio n. 16
0
 function handle($channel)
 {
     $notice = $this->getNotice($this->other);
     $recipient = $notice->getProfile();
     $len = mb_strlen($this->text);
     if ($len == 0) {
         // TRANS: Command exception text shown when trying to reply to a notice without providing content for the reply.
         $channel->error($this->user, _('No content!'));
         return;
     }
     $this->text = common_shorten_links($this->text);
     if (Notice::contentTooLong($this->text)) {
         // XXX: i18n. Needs plural support.
         // TRANS: Message given if content of a notice for a reply is too long.
         // TRANS: %1$d is the maximum number of characters, %2$d is the number of submitted characters.
         $channel->error($this->user, sprintf(_('Notice too long - maximum is %1$d characters, you sent %2$d.'), Notice::maxContent(), mb_strlen($this->text)));
         return;
     }
     $notice = Notice::saveNew($this->user->id, $this->text, $channel->source(), array('reply_to' => $notice->id));
     if ($notice) {
         // TRANS: Text shown having sent a reply to a notice successfully.
         // TRANS: %s is the nickname of the user of the notice the reply was sent to.
         $channel->output($this->user, sprintf(_('Reply to %s sent.'), $recipient->nickname));
     } else {
         // TRANS: Error text shown when a reply to a notice fails with an unknown reason.
         $channel->error($this->user, _('Error saving notice.'));
     }
 }
Esempio n. 17
0
 /**
  * Process an incoming post activity from this remote feed.
  * @param Activity $activity
  * @param string $method 'push' or 'salmon'
  * @return mixed saved Notice or false
  * @todo FIXME: Break up this function, it's getting nasty long
  */
 public function processPost($activity, $method)
 {
     $notice = null;
     $oprofile = $this->checkAuthorship($activity);
     if (empty($oprofile)) {
         return null;
     }
     // It's not always an ActivityObject::NOTE, but... let's just say it is.
     $note = $activity->objects[0];
     // The id URI will be used as a unique identifier for for the notice,
     // protecting against duplicate saves. It isn't required to be a URL;
     // tag: URIs for instance are found in Google Buzz feeds.
     $sourceUri = $note->id;
     $dupe = Notice::staticGet('uri', $sourceUri);
     if ($dupe) {
         common_log(LOG_INFO, "OStatus: ignoring duplicate post: {$sourceUri}");
         return $dupe;
     }
     // We'll also want to save a web link to the original notice, if provided.
     $sourceUrl = null;
     if ($note->link) {
         $sourceUrl = $note->link;
     } else {
         if ($activity->link) {
             $sourceUrl = $activity->link;
         } else {
             if (preg_match('!^https?://!', $note->id)) {
                 $sourceUrl = $note->id;
             }
         }
     }
     // Use summary as fallback for content
     if (!empty($note->content)) {
         $sourceContent = $note->content;
     } else {
         if (!empty($note->summary)) {
             $sourceContent = $note->summary;
         } else {
             if (!empty($note->title)) {
                 $sourceContent = $note->title;
             } else {
                 // @todo FIXME: Fetch from $sourceUrl?
                 // TRANS: Client exception. %s is a source URI.
                 throw new ClientException(sprintf(_m('No content for notice %s.'), $sourceUri));
             }
         }
     }
     // Get (safe!) HTML and text versions of the content
     $rendered = $this->purify($sourceContent);
     $content = html_entity_decode(strip_tags($rendered), ENT_QUOTES, 'UTF-8');
     $shortened = common_shorten_links($content);
     // If it's too long, try using the summary, and make the
     // HTML an attachment.
     $attachment = null;
     if (Notice::contentTooLong($shortened)) {
         $attachment = $this->saveHTMLFile($note->title, $rendered);
         $summary = html_entity_decode(strip_tags($note->summary), ENT_QUOTES, 'UTF-8');
         if (empty($summary)) {
             $summary = $content;
         }
         $shortSummary = common_shorten_links($summary);
         if (Notice::contentTooLong($shortSummary)) {
             $url = common_shorten_url($sourceUrl);
             $shortSummary = substr($shortSummary, 0, Notice::maxContent() - (mb_strlen($url) + 2));
             $content = $shortSummary . ' ' . $url;
             // We mark up the attachment link specially for the HTML output
             // so we can fold-out the full version inline.
             // @todo FIXME i18n: This tooltip will be saved with the site's default language
             // TRANS: Shown when a notice is longer than supported and/or when attachments are present. At runtime
             // TRANS: this will usually be replaced with localised text from StatusNet core messages.
             $showMoreText = _m('Show more');
             $attachUrl = common_local_url('attachment', array('attachment' => $attachment->id));
             $rendered = common_render_text($shortSummary) . '<a href="' . htmlspecialchars($attachUrl) . '"' . ' class="attachment more"' . ' title="' . htmlspecialchars($showMoreText) . '">' . '&#8230;' . '</a>';
         }
     }
     $options = array('is_local' => Notice::REMOTE, 'url' => $sourceUrl, 'uri' => $sourceUri, 'rendered' => $rendered, 'replies' => array(), 'groups' => array(), 'peopletags' => array(), 'tags' => array(), 'urls' => array());
     // Check for optional attributes...
     if (!empty($activity->time)) {
         $options['created'] = common_sql_date($activity->time);
     }
     if ($activity->context) {
         // Any individual or group attn: targets?
         $replies = $activity->context->attention;
         $options['groups'] = $this->filterReplies($oprofile, $replies);
         $options['replies'] = $replies;
         // Maintain direct reply associations
         // @todo FIXME: What about conversation ID?
         if (!empty($activity->context->replyToID)) {
             $orig = Notice::staticGet('uri', $activity->context->replyToID);
             if (!empty($orig)) {
                 $options['reply_to'] = $orig->id;
             }
         }
         $location = $activity->context->location;
         if ($location) {
             $options['lat'] = $location->lat;
             $options['lon'] = $location->lon;
             if ($location->location_id) {
                 $options['location_ns'] = $location->location_ns;
                 $options['location_id'] = $location->location_id;
             }
         }
     }
     if ($this->isPeopletag()) {
         $options['peopletags'][] = $this->localPeopletag();
     }
     // Atom categories <-> hashtags
     foreach ($activity->categories as $cat) {
         if ($cat->term) {
             $term = common_canonical_tag($cat->term);
             if ($term) {
                 $options['tags'][] = $term;
             }
         }
     }
     // Atom enclosures -> attachment URLs
     foreach ($activity->enclosures as $href) {
         // @todo FIXME: Save these locally or....?
         $options['urls'][] = $href;
     }
     try {
         $saved = Notice::saveNew($oprofile->profile_id, $content, 'ostatus', $options);
         if ($saved) {
             Ostatus_source::saveNew($saved, $this, $method);
             if (!empty($attachment)) {
                 File_to_post::processNew($attachment->id, $saved->id);
             }
         }
     } catch (Exception $e) {
         common_log(LOG_ERR, "OStatus save of remote message {$sourceUri} failed: " . $e->getMessage());
         throw $e;
     }
     common_log(LOG_INFO, "OStatus saved remote message {$sourceUri} as notice id {$saved->id}");
     return $saved;
 }
Esempio n. 18
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...
     $this->content = $this->trimmed('status_textarea');
     $groupid = $this->trimmed('inreplyto');
     $options = array();
     if (!$this->content) {
         // TRANS: Client error displayed trying to send a notice without content.
         $this->clientError(_('Mensaje vacío!!'));
         return;
     }
     $content_shortened = $user->shortenLinks($this->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('Contenido demasiado largo! El tamaño máximo de caracteres es ' . Notice::maxContent() . '.');
     }
     $replyto = intval($this->trimmed('inreplyto'));
     if ($replyto) {
         $options['reply_to'] = $replyto;
     }
     $upload = null;
     $upload = MediaFile::fromUpload('attach');
     if (isset($upload)) {
         $content_shortened .= ' ' . $upload->shortUrl();
         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('Contenido demasiado largo! El tamaño máximo de caracteres ' . 'es ' . Notice::maxContent() . ', incluyendo la URL del adjunto.');
         }
     }
     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
     $notice_to = $this->trimmed('notice_to');
     $options['groups'] = array($notice_to);
     $notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
     if (isset($upload)) {
         $upload->attachToNotice($notice);
     }
     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->element('p', array('class' => 'notice-task-posted'), 'Tarea completada correctamente, mensaje publicado.');
         $this->elementEnd('body');
         $this->elementEnd('html');
     }
 }
Esempio n. 19
0
 function saveStatus($status)
 {
     $profile = $this->ensureProfile($status->user);
     if (empty($profile)) {
         common_log(LOG_ERR, $this->name() . ' - Problem saving notice. No associated Profile.');
         return null;
     }
     $statusId = twitter_id($status);
     $statusUri = $this->makeStatusURI($status->user->screen_name, $statusId);
     // check to see if we've already imported the status
     $n2s = Notice_to_status::staticGet('status_id', $statusId);
     if (!empty($n2s)) {
         common_log(LOG_INFO, $this->name() . " - Ignoring duplicate import: {$statusId}");
         return Notice::staticGet('id', $n2s->notice_id);
     }
     // If it's a retweet, save it as a repeat!
     if (!empty($status->retweeted_status)) {
         common_log(LOG_INFO, "Status {$statusId} is a retweet of " . twitter_id($status->retweeted_status) . ".");
         $original = $this->saveStatus($status->retweeted_status);
         if (empty($original)) {
             return null;
         } else {
             $author = $original->getProfile();
             // TRANS: Message used to repeat a notice. RT is the abbreviation of 'retweet'.
             // TRANS: %1$s is the repeated user's name, %2$s is the repeated notice.
             $content = sprintf(_m('RT @%1$s %2$s'), $author->nickname, $original->content);
             if (Notice::contentTooLong($content)) {
                 $contentlimit = Notice::maxContent();
                 $content = mb_substr($content, 0, $contentlimit - 4) . ' ...';
             }
             $repeat = Notice::saveNew($profile->id, $content, 'twitter', array('repeat_of' => $original->id, 'uri' => $statusUri, 'is_local' => Notice::GATEWAY));
             common_log(LOG_INFO, "Saved {$repeat->id} as a repeat of {$original->id}");
             Notice_to_status::saveNew($repeat->id, $statusId);
             return $repeat;
         }
     }
     $notice = new Notice();
     $notice->profile_id = $profile->id;
     $notice->uri = $statusUri;
     $notice->url = $statusUri;
     $notice->created = strftime('%Y-%m-%d %H:%M:%S', strtotime($status->created_at));
     $notice->source = 'twitter';
     $notice->reply_to = null;
     $replyTo = twitter_id($status, 'in_reply_to_status_id');
     if (!empty($replyTo)) {
         common_log(LOG_INFO, "Status {$statusId} is a reply to status {$replyTo}");
         $n2s = Notice_to_status::staticGet('status_id', $replyTo);
         if (empty($n2s)) {
             common_log(LOG_INFO, "Couldn't find local notice for status {$replyTo}");
         } else {
             $reply = Notice::staticGet('id', $n2s->notice_id);
             if (empty($reply)) {
                 common_log(LOG_INFO, "Couldn't find local notice for status {$replyTo}");
             } else {
                 common_log(LOG_INFO, "Found local notice {$reply->id} for status {$replyTo}");
                 $notice->reply_to = $reply->id;
                 $notice->conversation = $reply->conversation;
             }
         }
     }
     if (empty($notice->conversation)) {
         $conv = Conversation::create();
         $notice->conversation = $conv->id;
         common_log(LOG_INFO, "No known conversation for status {$statusId} so making a new one {$conv->id}.");
     }
     $notice->is_local = Notice::GATEWAY;
     $notice->content = html_entity_decode($status->text, ENT_QUOTES, 'UTF-8');
     $notice->rendered = $this->linkify($status);
     if (Event::handle('StartNoticeSave', array(&$notice))) {
         $id = $notice->insert();
         if (!$id) {
             common_log_db_error($notice, 'INSERT', __FILE__);
             common_log(LOG_ERR, $this->name() . ' - Problem saving notice.');
         }
         Event::handle('EndNoticeSave', array($notice));
     }
     Notice_to_status::saveNew($notice->id, $statusId);
     $this->saveStatusMentions($notice, $status);
     $this->saveStatusAttachments($notice, $status);
     $notice->blowOnInsert();
     return $notice;
 }
Esempio n. 20
0
 function add_notice(&$user, &$pl)
 {
     $body = trim($pl['body']);
     $content_shortened = $user->shortenLinks($body);
     if (Notice::contentTooLong($content_shortened)) {
         $from = jabber_normalize_jid($pl['from']);
         // TRANS: Response to XMPP source when it sent too long a message.
         // TRANS: %1$d the maximum number of allowed characters (used for plural), %2$d is the sent number.
         $this->from_site($from, sprintf(_m('Message too long. Maximum is %1$d character, you sent %2$d.', 'Message too long. Maximum is %1$d characters, you sent %2$d.', Notice::maxContent()), Notice::maxContent(), mb_strlen($content_shortened)));
         return;
     }
     try {
         $notice = Notice::saveNew($user->id, $content_shortened, 'xmpp');
     } catch (Exception $e) {
         $this->log(LOG_ERR, $e->getMessage());
         $this->from_site($user->jabber, $e->getMessage());
         return;
     }
     common_broadcast_notice($notice);
     $this->log(LOG_INFO, 'Added notice ' . $notice->id . ' from user ' . $user->nickname);
     $notice->free();
     unset($notice);
 }
Esempio n. 21
0
 /**
  * Helper for handling incoming messages
  * Your incoming message handler will probably want to call this function
  *
  * @param string $from screenname the message was sent from
  * @param string $message message contents
  *
  * @param boolean success
  */
 protected function addNotice($screenname, $user, $body)
 {
     $body = trim(strip_tags($body));
     $content_shortened = common_shorten_links($body);
     if (Notice::contentTooLong($content_shortened)) {
         $this->sendFromSite($screenname, sprintf(_m('Message too long - maximum is %1$d character, you sent %2$d.', 'Message too long - maximum is %1$d characters, you sent %2$d.', Notice::maxContent()), Notice::maxContent(), mb_strlen($content_shortened)));
         return;
     }
     try {
         $notice = Notice::saveNew($user->id, $content_shortened, $this->transport);
     } catch (Exception $e) {
         common_log(LOG_ERR, $e->getMessage());
         $this->sendFromSite($from, $e->getMessage());
         return;
     }
     common_log(LOG_INFO, 'Added notice ' . $notice->id . ' from user ' . $user->nickname);
     $notice->free();
     unset($notice);
 }
 /**
  * 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');
     if (!$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 = common_shorten_links($content);
     if (Notice::contentTooLong($content_shortened)) {
         $this->clientError(sprintf(_('That\'s too long. ' . 'Max notice size is %d chars.'), Notice::maxContent()));
     }
     $replyto = $this->trimmed('inreplyto');
     #If an ID of 0 is wrongly passed here, it will cause a database error,
     #so override it...
     if ($replyto == 0) {
         $replyto = 'false';
     }
     $upload = null;
     $upload = MediaFile::fromUpload('attach');
     if (isset($upload)) {
         $content_shortened .= ' ' . $upload->shortUrl();
         if (Notice::contentTooLong($content_shortened)) {
             $upload->delete();
             $this->clientError(sprintf(_('Max notice size is %d chars, including attachment URL.'), Notice::maxContent()));
         }
     }
     $options = array('reply_to' => $replyto == 'false' ? null : $replyto);
     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);
     }
     $notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
     if (isset($upload)) {
         $upload->attachToNotice($notice);
     }
     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');
         $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);
     }
 }
 function handle($channel)
 {
     $notice = $this->getNotice($this->other);
     $recipient = $notice->getProfile();
     $len = mb_strlen($this->text);
     if ($len == 0) {
         $channel->error($this->user, _('No content!'));
         return;
     }
     $this->text = common_shorten_links($this->text);
     if (Notice::contentTooLong($this->text)) {
         $channel->error($this->user, sprintf(_('Notice too long - maximum is %d characters, you sent %d'), Notice::maxContent(), mb_strlen($this->text)));
         return;
     }
     $notice = Notice::saveNew($this->user->id, $this->text, $channel->source(), array('reply_to' => $notice->id));
     if ($notice) {
         $channel->output($this->user, sprintf(_('Reply to %s sent'), $recipient->nickname));
     } else {
         $channel->error($this->user, _('Error saving notice.'));
     }
 }
 /**
  * Process an incoming post activity from this remote feed.
  * @param Activity $activity
  * @param string $method 'push' or 'salmon'
  * @return mixed saved Notice or false
  * @fixme break up this function, it's getting nasty long
  */
 public function processPost($activity, $method)
 {
     if ($this->isGroup()) {
         // A group feed will contain posts from multiple authors.
         // @fixme validate these profiles in some way!
         $oprofile = self::ensureActorProfile($activity);
         if ($oprofile->isGroup()) {
             // Groups can't post notices in StatusNet.
             common_log(LOG_WARNING, "OStatus: skipping post with group listed as author: {$oprofile->uri} in feed from {$this->uri}");
             return false;
         }
     } else {
         $actor = $activity->actor;
         if (empty($actor)) {
             // OK here! assume the default
         } else {
             if ($actor->id == $this->uri || $actor->link == $this->uri) {
                 $this->updateFromActivityObject($actor);
             } else {
                 throw new Exception("Got an actor '{$actor->title}' ({$actor->id}) on single-user feed for {$this->uri}");
             }
         }
         $oprofile = $this;
     }
     // It's not always an ActivityObject::NOTE, but... let's just say it is.
     $note = $activity->objects[0];
     // The id URI will be used as a unique identifier for for the notice,
     // protecting against duplicate saves. It isn't required to be a URL;
     // tag: URIs for instance are found in Google Buzz feeds.
     $sourceUri = $note->id;
     $dupe = Notice::staticGet('uri', $sourceUri);
     if ($dupe) {
         common_log(LOG_INFO, "OStatus: ignoring duplicate post: {$sourceUri}");
         return false;
     }
     // We'll also want to save a web link to the original notice, if provided.
     $sourceUrl = null;
     if ($note->link) {
         $sourceUrl = $note->link;
     } else {
         if ($activity->link) {
             $sourceUrl = $activity->link;
         } else {
             if (preg_match('!^https?://!', $note->id)) {
                 $sourceUrl = $note->id;
             }
         }
     }
     // Use summary as fallback for content
     if (!empty($note->content)) {
         $sourceContent = $note->content;
     } else {
         if (!empty($note->summary)) {
             $sourceContent = $note->summary;
         } else {
             if (!empty($note->title)) {
                 $sourceContent = $note->title;
             } else {
                 // @fixme fetch from $sourceUrl?
                 throw new ClientException("No content for notice {$sourceUri}");
             }
         }
     }
     // Get (safe!) HTML and text versions of the content
     $rendered = $this->purify($sourceContent);
     $content = html_entity_decode(strip_tags($rendered));
     $shortened = common_shorten_links($content);
     // If it's too long, try using the summary, and make the
     // HTML an attachment.
     $attachment = null;
     if (Notice::contentTooLong($shortened)) {
         $attachment = $this->saveHTMLFile($note->title, $rendered);
         $summary = html_entity_decode(strip_tags($note->summary));
         if (empty($summary)) {
             $summary = $content;
         }
         $shortSummary = common_shorten_links($summary);
         if (Notice::contentTooLong($shortSummary)) {
             $url = common_shorten_url($sourceUrl);
             $shortSummary = substr($shortSummary, 0, Notice::maxContent() - (mb_strlen($url) + 2));
             $content = $shortSummary . ' ' . $url;
             // We mark up the attachment link specially for the HTML output
             // so we can fold-out the full version inline.
             $attachUrl = common_local_url('attachment', array('attachment' => $attachment->id));
             $rendered = common_render_text($shortSummary) . '<a href="' . htmlspecialchars($attachUrl) . '"' . ' class="attachment more"' . ' title="' . htmlspecialchars(_m('Show more')) . '">' . '&#8230;' . '</a>';
         }
     }
     $options = array('is_local' => Notice::REMOTE_OMB, 'url' => $sourceUrl, 'uri' => $sourceUri, 'rendered' => $rendered, 'replies' => array(), 'groups' => array(), 'tags' => array(), 'urls' => array());
     // Check for optional attributes...
     if (!empty($activity->time)) {
         $options['created'] = common_sql_date($activity->time);
     }
     if ($activity->context) {
         // Any individual or group attn: targets?
         $replies = $activity->context->attention;
         $options['groups'] = $this->filterReplies($oprofile, $replies);
         $options['replies'] = $replies;
         // Maintain direct reply associations
         // @fixme what about conversation ID?
         if (!empty($activity->context->replyToID)) {
             $orig = Notice::staticGet('uri', $activity->context->replyToID);
             if (!empty($orig)) {
                 $options['reply_to'] = $orig->id;
             }
         }
         $location = $activity->context->location;
         if ($location) {
             $options['lat'] = $location->lat;
             $options['lon'] = $location->lon;
             if ($location->location_id) {
                 $options['location_ns'] = $location->location_ns;
                 $options['location_id'] = $location->location_id;
             }
         }
     }
     // Atom categories <-> hashtags
     foreach ($activity->categories as $cat) {
         if ($cat->term) {
             $term = common_canonical_tag($cat->term);
             if ($term) {
                 $options['tags'][] = $term;
             }
         }
     }
     // Atom enclosures -> attachment URLs
     foreach ($activity->enclosures as $href) {
         // @fixme save these locally or....?
         $options['urls'][] = $href;
     }
     try {
         $saved = Notice::saveNew($oprofile->profile_id, $content, 'ostatus', $options);
         if ($saved) {
             Ostatus_source::saveNew($saved, $this, $method);
             if (!empty($attachment)) {
                 File_to_post::processNew($attachment->id, $saved->id);
             }
         }
     } catch (Exception $e) {
         common_log(LOG_ERR, "OStatus save of remote message {$sourceUri} failed: " . $e->getMessage());
         throw $e;
     }
     common_log(LOG_INFO, "OStatus saved remote message {$sourceUri} as notice id {$saved->id}");
     return $saved;
 }
 /**
  * Handle the request
  *
  * Make a new notice for the update, save it, and show it
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     // 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']));
     }
     if (empty($this->status)) {
         // TRANS: Client error displayed when the parameter "status" is missing.
         $this->clientError(_('Client must provide a \'status\' parameter with a value.'));
     }
     if (is_null($this->scoped)) {
         // TRANS: Client error displayed when updating a status for a non-existing user.
         $this->clientError(_('No such user.'), 404);
     }
     /* Do not call shortenlinks until the whole notice has been build */
     // Check for commands
     $inter = new CommandInterpreter();
     $cmd = $inter->handle_command($this->auth_user, $this->status);
     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::getKV($this->in_reply_to_status_id);
             if ($reply) {
                 $reply_to = $this->in_reply_to_status_id;
             } else {
                 // TRANS: Client error displayed when replying to a non-existing notice.
                 $this->clientError(_('Parent notice not found.'), 404);
             }
         }
         $upload = null;
         try {
             $upload = MediaFile::fromUpload('media', $this->scoped);
         } catch (NoUploadedMediaException $e) {
             // There was no uploaded media for us today.
         }
         if (isset($upload)) {
             $this->status .= ' ' . $upload->shortUrl();
             /* Do not call shortenlinks until the whole notice has been build */
         }
         // in Qvitter we shorten _before_ posting, so disble shortening here
         $status_shortened = $this->status;
         if (Notice::contentTooLong($status_shortened)) {
             if ($upload instanceof MediaFile) {
                 $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());
             /* Use HTTP 413 error code (Request Entity Too Large)
              * instead of basic 400 for better understanding
              */
             $this->clientError(sprintf($msg, Notice::maxContent()), 413);
         }
         $content = html_entity_decode($status_shortened, ENT_NOQUOTES, 'UTF-8');
         $options = array('reply_to' => $reply_to);
         // -------------------------------------------------------------
         // -------- Qvitter's post-to-the-right-group stuff! -----------
         // -------------------------------------------------------------
         // guess the groups by the content first, if we don't have group id:s as meta data
         $profile = Profile::getKV('id', $this->scoped->id);
         $guessed_groups = User_group::groupsFromText($content, $profile);
         // if the user has specified any group id:s, correct the guesswork
         if (strlen($this->post_to_groups) > 0) {
             // get the groups that the user wants to post to
             $group_ids = explode(':', $this->post_to_groups);
             $correct_groups = array();
             foreach ($group_ids as $group_id) {
                 $correct_groups[] = User_group::getKV('id', $group_id);
             }
             // correct the guesses
             $corrected_group_ids = array();
             foreach ($guessed_groups as $guessed_group) {
                 $id_to_keep = $guessed_group->id;
                 foreach ($correct_groups as $k => $correct_group) {
                     if ($correct_group->nickname == $guessed_group->nickname) {
                         $id_to_keep = $correct_group->id;
                         unset($correct_groups[$k]);
                         break;
                     }
                 }
                 $corrected_group_ids[$id_to_keep] = true;
             }
             // but we still want to post to all of the groups that the user specified by id
             // even if we couldn't use it to correct a bad guess
             foreach ($correct_groups as $correct_group) {
                 $corrected_group_ids[$correct_group->id] = true;
             }
             $options['groups'] = array_keys($corrected_group_ids);
         } else {
             $guessed_ids = array();
             foreach ($guessed_groups as $guessed_group) {
                 $guessed_ids[$guessed_group->id] = true;
             }
             $options['groups'] = array_keys($guessed_ids);
         }
         // -------------------------------------------------------------
         // ------ End of Qvitter's post-to-the-right-group stuff! ------
         // -------------------------------------------------------------
         if ($this->scoped->shareLocation()) {
             $locOptions = Notice::locationOptions($this->lat, $this->lon, null, null, $this->scoped);
             $options = array_merge($options, $locOptions);
         }
         try {
             $this->notice = Notice::saveNew($this->scoped->id, $content, $this->source, $options);
         } catch (Exception $e) {
             $this->clientError($e->getMessage(), $e->getCode());
         }
         if (isset($upload)) {
             $upload->attachToNotice($this->notice);
         }
     }
     $this->showNotice();
 }
Esempio n. 26
0
 function saveNewNotice()
 {
     $user = $this->flink->getUser();
     $content = $this->trimmed('status_textarea');
     if (!$content) {
         $this->showPage(_m('No notice content!'));
         return;
     } else {
         $content_shortened = common_shorten_links($content);
         if (Notice::contentTooLong($content_shortened)) {
             $this->showPage(sprintf(_m('That\'s too long. Max notice size is %d chars.'), Notice::maxContent()));
             return;
         }
     }
     $inter = new CommandInterpreter();
     $cmd = $inter->handle_command($user, $content_shortened);
     if ($cmd) {
         // XXX fix this
         $cmd->execute(new WebChannel());
         return;
     }
     $replyto = $this->trimmed('inreplyto');
     try {
         $notice = Notice::saveNew($user->id, $content, 'web', array('reply_to' => $replyto == 'false' ? null : $replyto));
     } catch (Exception $e) {
         $this->showPage($e->getMessage());
         return;
     }
 }
Esempio n. 27
0
 function add_notice(&$user, &$pl)
 {
     $body = trim($pl['body']);
     $content_shortened = common_shorten_links($body);
     if (Notice::contentTooLong($content_shortened)) {
         $from = jabber_normalize_jid($pl['from']);
         $this->from_site($from, sprintf(_('Message too long - maximum is %1$d characters, you sent %2$d.'), Notice::maxContent(), mb_strlen($content_shortened)));
         return;
     }
     try {
         $notice = Notice::saveNew($user->id, $content_shortened, 'xmpp');
     } catch (Exception $e) {
         $this->log(LOG_ERR, $e->getMessage());
         $this->from_site($user->jabber, $e->getMessage());
         return;
     }
     common_broadcast_notice($notice);
     $this->log(LOG_INFO, 'Added notice ' . $notice->id . ' from user ' . $user->nickname);
     $notice->free();
     unset($notice);
 }
 /**
  * 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) {
         $msg = _('The server was unable to handle that much POST ' . 'data (%s bytes) due to its current configuration.');
         $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)) {
         $this->clientError(_('No such user.'), 404, $this->format);
         return;
     }
     $status_shortened = common_shorten_links($this->status);
     if (Notice::contentTooLong($status_shortened)) {
         // Note: Twitter truncates anything over 140, flags the status
         // as "truncated."
         $this->clientError(sprintf(_('That\'s too long. Max notice size is %d chars.'), 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(_('Not found.'), $code = 404, $this->format);
                 return;
             }
         }
         $upload = null;
         try {
             $upload = MediaFile::fromUpload('media', $this->auth_user);
         } catch (ClientException $ce) {
             $this->clientError($ce->getMessage());
             return;
         }
         if (isset($upload)) {
             $status_shortened .= ' ' . $upload->shortUrl();
             if (Notice::contentTooLong($status_shortened)) {
                 $upload->delete();
                 $msg = _('Max notice size is %d chars, ' . 'including attachment URL.');
                 $this->clientError(sprintf($msg, Notice::maxContent()));
             }
         }
         $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);
         }
         try {
             $this->notice = Notice::saveNew($this->auth_user->id, $content, $this->source, $options);
         } catch (Exception $e) {
             $this->clientError($e->getMessage());
             return;
         }
         if (isset($upload)) {
             $upload->attachToNotice($this->notice);
         }
     }
     $this->showNotice();
 }
Esempio n. 29
0
 /**
  * Data elements
  *
  * @return void
  */
 function formData()
 {
     if (Event::handle('StartShowNoticeFormData', array($this))) {
         $this->out->element('label', array('for' => 'notice_data-text'), sprintf(_('What\'s up, %s?'), $this->user->nickname));
         // XXX: vary by defined max size
         $this->out->element('textarea', array('id' => 'notice_data-text', 'cols' => 35, 'rows' => 4, 'name' => 'status_textarea'), $this->content ? $this->content : '');
         $contentLimit = Notice::maxContent();
         if ($contentLimit > 0) {
             $this->out->elementStart('dl', 'form_note');
             $this->out->element('dt', null, _('Available characters'));
             $this->out->element('dd', array('id' => 'notice_text-count'), $contentLimit);
             $this->out->elementEnd('dl');
         }
         if (common_config('attachments', 'uploads')) {
             $this->out->element('label', array('for' => 'notice_data-attach'), _('Attach'));
             $this->out->element('input', array('id' => 'notice_data-attach', 'type' => 'file', 'name' => 'attach', 'title' => _('Attach a file')));
             $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
         }
         if ($this->action) {
             $this->out->hidden('notice_return-to', $this->action, 'returnto');
         }
         $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
         if ($this->user->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('id' => 'notice_data-geo_wrap', 'title' => common_local_url('geocode')));
             $this->out->checkbox('notice_data-geo', _('Share my location'), true);
             $this->out->elementEnd('div');
             $this->out->inlineScript(' var NoticeDataGeo_text = {' . 'ShareDisable: ' . json_encode(_('Do not share my location')) . ',' . 'ErrorTimeout: ' . json_encode(_('Sorry, retrieving your geo location is taking longer than expected, please try again later')) . '}');
         }
         Event::handle('EndShowNoticeFormData', array($this));
     }
 }
Esempio n. 30
0
 /**
  * Data elements
  *
  * @return void
  */
 function formData()
 {
     if (Event::handle('StartShowNoticeFormData', array($this))) {
         $this->out->element('label', array('for' => 'notice_data-text'), sprintf(_m('What\'s up, %s?'), $this->user->nickname));
         // XXX: vary by defined max size
         $this->out->element('textarea', array('id' => 'notice_data-text', 'cols' => 35, 'rows' => 4, 'name' => 'status_textarea'), $this->content ? $this->content : '');
         $contentLimit = Notice::maxContent();
         if ($contentLimit > 0) {
             $this->out->elementStart('dl', 'form_note');
             $this->out->element('dt', null, _m('Available characters'));
             $this->out->element('dd', array('id' => 'notice_text-count'), $contentLimit);
             $this->out->elementEnd('dl');
         }
         if ($this->action) {
             $this->out->hidden('notice_return-to', $this->action, 'returnto');
         }
         $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
         Event::handle('StartShowNoticeFormData', array($this));
     }
 }