コード例 #1
0
ファイル: shorten.php プロジェクト: bashrc/gnusocial-debian
 function handle($args = null)
 {
     parent::handle($args);
     header('Content-Type: text/plain');
     $shortened_text = common_shorten_links($this->text);
     print $shortened_text;
 }
コード例 #2
0
ファイル: Message.php プロジェクト: stevertiqo/StatusNet
 static function saveNew($from, $to, $content, $source)
 {
     $sender = Profile::staticGet('id', $from);
     if (!$sender->hasRight(Right::NEWMESSAGE)) {
         // TRANS: Client exception thrown when a user tries to send a direct message while being banned from sending them.
         throw new ClientException(_('You are banned from sending direct messages.'));
     }
     $msg = new Message();
     $msg->from_profile = $from;
     $msg->to_profile = $to;
     $msg->content = common_shorten_links($content);
     $msg->rendered = common_render_text($content);
     $msg->created = common_sql_now();
     $msg->source = $source;
     $result = $msg->insert();
     if (!$result) {
         common_log_db_error($msg, 'INSERT', __FILE__);
         // TRANS: Message given when a message could not be stored on the server.
         return _('Could not insert message.');
     }
     $orig = clone $msg;
     $msg->uri = common_local_url('showmessage', array('message' => $msg->id));
     $result = $msg->update($orig);
     if (!$result) {
         common_log_db_error($msg, 'UPDATE', __FILE__);
         // TRANS: Message given when a message could not be updated on the server.
         return _('Could not update message with new URI.');
     }
     return $msg;
 }
コード例 #3
0
ファイル: mailhandler.php プロジェクト: stevertiqo/StatusNet
 function handle_message($rawmessage)
 {
     list($from, $to, $msg, $attachments) = $this->parse_message($rawmessage);
     if (!$from || !$to || !$msg) {
         $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) {
         $this->error($from, _('Not a registered user.'));
         return false;
     }
     if (!$this->user_match_to($user, $to)) {
         $this->error($from, _('Sorry, that is not your incoming email address.'));
         return false;
     }
     if (!$user->emailpost) {
         $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 = common_shorten_links($msg);
     if (Notice::contentTooLong($msg)) {
         $this->error($from, sprintf(_('That\'s too long. ' . 'Max notice size is %d chars.'), 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;
     }
 }
コード例 #4
0
ファイル: postnotice.php プロジェクト: Br3nda/laconica
 function save_notice(&$req, &$consumer, &$token)
 {
     $version = $req->get_parameter('omb_version');
     if ($version != OMB_VERSION_01) {
         $this->clientError(_('Unsupported OMB version'), 400);
         return false;
     }
     # First, check to see
     $listenee = $req->get_parameter('omb_listenee');
     $remote_profile = Remote_profile::staticGet('uri', $listenee);
     if (!$remote_profile) {
         $this->clientError(_('Profile unknown'), 403);
         return false;
     }
     $sub = Subscription::staticGet('token', $token->key);
     if (!$sub) {
         $this->clientError(_('No such subscription'), 403);
         return false;
     }
     $content = $req->get_parameter('omb_notice_content');
     $content_shortened = common_shorten_links($content);
     if (mb_strlen($content_shortened) > 140) {
         $this->clientError(_('Invalid notice content'), 400);
         return false;
     }
     $notice_uri = $req->get_parameter('omb_notice');
     if (!Validate::uri($notice_uri) && !common_valid_tag($notice_uri)) {
         $this->clientError(_('Invalid notice uri'), 400);
         return false;
     }
     $notice_url = $req->get_parameter('omb_notice_url');
     if ($notice_url && !common_valid_http_url($notice_url)) {
         $this->clientError(_('Invalid notice url'), 400);
         return false;
     }
     $notice = Notice::staticGet('uri', $notice_uri);
     if (!$notice) {
         $notice = Notice::saveNew($remote_profile->id, $content, 'omb', false, null, $notice_uri);
         if (is_string($notice)) {
             common_server_serror($notice, 500);
             return false;
         }
         common_broadcast_notice($notice, true);
     }
     return true;
 }
コード例 #5
0
ファイル: Message.php プロジェクト: Br3nda/laconica
 static function saveNew($from, $to, $content, $source)
 {
     $msg = new Message();
     $msg->from_profile = $from;
     $msg->to_profile = $to;
     $msg->content = common_shorten_links($content);
     $msg->rendered = common_render_text($content);
     $msg->created = common_sql_now();
     $msg->source = $source;
     $result = $msg->insert();
     if (!$result) {
         common_log_db_error($msg, 'INSERT', __FILE__);
         return _('Could not insert message.');
     }
     $orig = clone $msg;
     $msg->uri = common_local_url('showmessage', array('message' => $msg->id));
     $result = $msg->update($orig);
     if (!$result) {
         common_log_db_error($msg, 'UPDATE', __FILE__);
         return _('Could not update message with new URI.');
     }
     return $msg;
 }
コード例 #6
0
ファイル: xmppmanager.php プロジェクト: himmelex/NTW
 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);
 }
コード例 #7
0
ファイル: facebookaction.php プロジェクト: himmelex/NTW
 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;
     }
 }
コード例 #8
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
  * @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;
 }
コード例 #9
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');
     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);
     }
 }
コード例 #10
0
ファイル: restoreuser.php プロジェクト: stevertiqo/StatusNet
function postNote($user, $activity)
{
    $note = $activity->objects[0];
    $sourceUri = $note->id;
    $notice = Notice::staticGet('uri', $sourceUri);
    if (!empty($notice)) {
        // This is weird.
        $orig = clone $notice;
        $notice->profile_id = $user->id;
        $notice->update($orig);
        return;
    }
    // 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?
                // @todo i18n FIXME: use sprintf and add i18n.
                throw new ClientException("No content for notice {$sourceUri}.");
            }
        }
    }
    // Get (safe!) HTML and text versions of the content
    $rendered = purify($sourceContent);
    $content = html_entity_decode(strip_tags($rendered), ENT_QUOTES, 'UTF-8');
    $shortened = common_shorten_links($content);
    $options = array('is_local' => Notice::LOCAL_PUBLIC, '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?
        list($options['groups'], $options['replies']) = filterAttention($activity->context->attention);
        // 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;
    }
    $saved = Notice::saveNew($user->id, $content, 'restore', $options);
    return $saved;
}
コード例 #11
0
ファイル: facebookaction.php プロジェクト: Br3nda/laconica
 function saveNewNotice()
 {
     $user = $this->flink->getUser();
     $content = $this->trimmed('status_textarea');
     if (!$content) {
         $this->showPage(_('No notice content!'));
         return;
     } else {
         $content_shortened = common_shorten_links($content);
         if (mb_strlen($content_shortened) > 140) {
             $this->showPage(_('That\'s too long. Max notice size is 140 chars.'));
             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');
     $notice = Notice::saveNew($user->id, $content, 'Facebook', 1, $replyto == 'false' ? null : $replyto);
     if (is_string($notice)) {
         $this->showPage($notice);
         return;
     }
     common_broadcast_notice($notice);
     // Also update the user's Facebook status
     $this->updateFacebookStatus($notice);
     $this->updateProfileBox($notice);
 }
コード例 #12
0
ファイル: Ostatus_profile.php プロジェクト: Grasia/bolotweet
 /**
  * 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;
 }
コード例 #13
0
ファイル: Notice.php プロジェクト: a780201/gnu-social
 /**
  * Save a new notice and push it out to subscribers' inboxes.
  * Poster's permissions are checked before sending.
  *
  * @param int $profile_id Profile ID of the poster
  * @param string $content source message text; links may be shortened
  *                        per current user's preference
  * @param string $source source key ('web', 'api', etc)
  * @param array $options Associative array of optional properties:
  *              string 'created' timestamp of notice; defaults to now
  *              int 'is_local' source/gateway ID, one of:
  *                  Notice::LOCAL_PUBLIC    - Local, ok to appear in public timeline
  *                  Notice::REMOTE          - Sent from a remote service;
  *                                            hide from public timeline but show in
  *                                            local "and friends" timelines
  *                  Notice::LOCAL_NONPUBLIC - Local, but hide from public timeline
  *                  Notice::GATEWAY         - From another non-OStatus service;
  *                                            will not appear in public views
  *              float 'lat' decimal latitude for geolocation
  *              float 'lon' decimal longitude for geolocation
  *              int 'location_id' geoname identifier
  *              int 'location_ns' geoname namespace to interpret location_id
  *              int 'reply_to'; notice ID this is a reply to
  *              int 'repeat_of'; notice ID this is a repeat of
  *              string 'uri' unique ID for notice; a unique tag uri (can be url or anything too)
  *              string 'url' permalink to notice; defaults to local notice URL
  *              string 'rendered' rendered HTML version of content
  *              array 'replies' list of profile URIs for reply delivery in
  *                              place of extracting @-replies from content.
  *              array 'groups' list of group IDs to deliver to, in place of
  *                              extracting ! tags from content
  *              array 'tags' list of hashtag strings to save with the notice
  *                           in place of extracting # tags from content
  *              array 'urls' list of attached/referred URLs to save with the
  *                           notice in place of extracting links from content
  *              boolean 'distribute' whether to distribute the notice, default true
  *              string 'object_type' URL of the associated object type (default ActivityObject::NOTE)
  *              string 'verb' URL of the associated verb (default ActivityVerb::POST)
  *              int 'scope' Scope bitmask; default to SITE_SCOPE on private sites, 0 otherwise
  *
  * @fixme tag override
  *
  * @return Notice
  * @throws ClientException
  */
 static function saveNew($profile_id, $content, $source, array $options = null)
 {
     $defaults = array('uri' => null, 'url' => null, 'conversation' => null, 'reply_to' => null, 'repeat_of' => null, 'scope' => null, 'distribute' => true, 'object_type' => null, 'verb' => null);
     if (!empty($options) && is_array($options)) {
         $options = array_merge($defaults, $options);
         extract($options);
     } else {
         extract($defaults);
     }
     if (!isset($is_local)) {
         $is_local = Notice::LOCAL_PUBLIC;
     }
     $profile = Profile::getKV('id', $profile_id);
     if (!$profile instanceof Profile) {
         // TRANS: Client exception thrown when trying to save a notice for an unknown user.
         throw new ClientException(_('Problem saving notice. Unknown user.'));
     }
     $user = User::getKV('id', $profile_id);
     if ($user instanceof User) {
         // Use the local user's shortening preferences, if applicable.
         $final = $user->shortenLinks($content);
     } else {
         $final = common_shorten_links($content);
     }
     if (Notice::contentTooLong($final)) {
         // TRANS: Client exception thrown if a notice contains too many characters.
         throw new ClientException(_('Problem saving notice. Too long.'));
     }
     if (common_config('throttle', 'enabled') && !Notice::checkEditThrottle($profile_id)) {
         common_log(LOG_WARNING, 'Excessive posting by profile #' . $profile_id . '; throttled.');
         // TRANS: Client exception thrown when a user tries to post too many notices in a given time frame.
         throw new ClientException(_('Too many notices too fast; take a breather ' . 'and post again in a few minutes.'));
     }
     if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) {
         common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.');
         // TRANS: Client exception thrown when a user tries to post too many duplicate notices in a given time frame.
         throw new ClientException(_('Too many duplicate messages too quickly;' . ' take a breather and post again in a few minutes.'));
     }
     if (!$profile->hasRight(Right::NEWNOTICE)) {
         common_log(LOG_WARNING, "Attempted post from user disallowed to post: " . $profile->nickname);
         // TRANS: Client exception thrown when a user tries to post while being banned.
         throw new ClientException(_('You are banned from posting notices on this site.'), 403);
     }
     $notice = new Notice();
     $notice->profile_id = $profile_id;
     $autosource = common_config('public', 'autosource');
     // Sandboxed are non-false, but not 1, either
     if (!$profile->hasRight(Right::PUBLICNOTICE) || $source && $autosource && in_array($source, $autosource)) {
         $notice->is_local = Notice::LOCAL_NONPUBLIC;
     } else {
         $notice->is_local = $is_local;
     }
     if (!empty($created)) {
         $notice->created = $created;
     } else {
         $notice->created = common_sql_now();
     }
     if (!$notice->isLocal()) {
         // Only do these checks for non-local notices. Local notices will generate these values later.
         if (!common_valid_http_url($url)) {
             common_debug('Bad notice URL: [' . $url . '], URI: [' . $uri . ']. Cannot link back to original! This is normal for shared notices etc.');
         }
         if (empty($uri)) {
             throw new ServerException('No URI for remote notice. Cannot accept that.');
         }
     }
     $notice->content = $final;
     $notice->source = $source;
     $notice->uri = $uri;
     $notice->url = $url;
     // Get the groups here so we can figure out replies and such
     if (!isset($groups)) {
         $groups = User_group::idsFromText($notice->content, $profile);
     }
     $reply = null;
     // Handle repeat case
     if (!empty($options['repeat_of'])) {
         // Check for a private one
         $repeat = Notice::getByID($options['repeat_of']);
         if ($profile->sameAs($repeat->getProfile())) {
             // TRANS: Client error displayed when trying to repeat an own notice.
             throw new ClientException(_('You cannot repeat your own notice.'));
         }
         if ($repeat->scope != Notice::SITE_SCOPE && $repeat->scope != Notice::PUBLIC_SCOPE) {
             // TRANS: Client error displayed when trying to repeat a non-public notice.
             throw new ClientException(_('Cannot repeat a private notice.'), 403);
         }
         if (!$repeat->inScope($profile)) {
             // The generic checks above should cover this, but let's be sure!
             // TRANS: Client error displayed when trying to repeat a notice you cannot access.
             throw new ClientException(_('Cannot repeat a notice you cannot read.'), 403);
         }
         if ($profile->hasRepeated($repeat)) {
             // TRANS: Client error displayed when trying to repeat an already repeated notice.
             throw new ClientException(_('You already repeated that notice.'));
         }
         $notice->repeat_of = $repeat->id;
         $notice->conversation = $repeat->conversation;
     } else {
         $reply = null;
         // If $reply_to is specified, we check that it exists, and then
         // return it if it does
         if (!empty($reply_to)) {
             $reply = Notice::getKV('id', $reply_to);
         } elseif (in_array($source, array('xmpp', 'mail', 'sms'))) {
             // If the source lacks capability of sending the "reply_to"
             // metadata, let's try to find an inline replyto-reference.
             $reply = self::getInlineReplyTo($profile, $final);
         }
         if ($reply instanceof Notice) {
             if (!$reply->inScope($profile)) {
                 // TRANS: Client error displayed when trying to reply to a notice a the target has no access to.
                 // TRANS: %1$s is a user nickname, %2$d is a notice ID (number).
                 throw new ClientException(sprintf(_('%1$s has no access to notice %2$d.'), $profile->nickname, $reply->id), 403);
             }
             // If it's a repeat, the reply_to should be to the original
             if ($reply->isRepeat()) {
                 $notice->reply_to = $reply->repeat_of;
             } else {
                 $notice->reply_to = $reply->id;
             }
             // But the conversation ought to be the same :)
             $notice->conversation = $reply->conversation;
             // If the original is private to a group, and notice has
             // no group specified, make it to the same group(s)
             if (empty($groups) && $reply->scope & Notice::GROUP_SCOPE) {
                 $groups = array();
                 $replyGroups = $reply->getGroups();
                 foreach ($replyGroups as $group) {
                     if ($profile->isMember($group)) {
                         $groups[] = $group->id;
                     }
                 }
             }
             // Scope set below
         }
         // If we don't know the reply, we might know the conversation!
         // This will happen if a known remote user replies to an
         // unknown remote user - within a known conversation.
         if (empty($notice->conversation) and !empty($options['conversation'])) {
             $conv = Conversation::getKV('uri', $options['conversation']);
             if ($conv instanceof Conversation) {
                 common_debug('Conversation stitched together from (probably) a reply to unknown remote user. Activity creation time (' . $notice->created . ') should maybe be compared to conversation creation time (' . $conv->created . ').');
             } else {
                 // Conversation entry with specified URI was not found, so we must create it.
                 common_debug('Conversation URI not found, so we will create it with the URI given in the options to Notice::saveNew: ' . $options['conversation']);
                 // The insert in Conversation::create throws exception on failure
                 $conv = Conversation::create($options['conversation'], $notice->created);
             }
             $notice->conversation = $conv->getID();
             unset($conv);
         }
     }
     // If it's not part of a conversation, it's the beginning of a new conversation.
     if (empty($notice->conversation)) {
         $conv = Conversation::create();
         $notice->conversation = $conv->getID();
         unset($conv);
     }
     $notloc = new Notice_location();
     if (!empty($lat) && !empty($lon)) {
         $notloc->lat = $lat;
         $notloc->lon = $lon;
     }
     if (!empty($location_ns) && !empty($location_id)) {
         $notloc->location_id = $location_id;
         $notloc->location_ns = $location_ns;
     }
     if (!empty($rendered)) {
         $notice->rendered = $rendered;
     } else {
         $notice->rendered = common_render_content($final, $notice->getProfile(), $notice->hasParent() ? $notice->getParent() : null);
     }
     if (empty($verb)) {
         if ($notice->isRepeat()) {
             $notice->verb = ActivityVerb::SHARE;
             $notice->object_type = ActivityObject::ACTIVITY;
         } else {
             $notice->verb = ActivityVerb::POST;
         }
     } else {
         $notice->verb = $verb;
     }
     if (empty($object_type)) {
         $notice->object_type = empty($notice->reply_to) ? ActivityObject::NOTE : ActivityObject::COMMENT;
     } else {
         $notice->object_type = $object_type;
     }
     if (is_null($scope) && $reply instanceof Notice) {
         $notice->scope = $reply->scope;
     } else {
         $notice->scope = $scope;
     }
     $notice->scope = self::figureOutScope($profile, $groups, $notice->scope);
     if (Event::handle('StartNoticeSave', array(&$notice))) {
         // XXX: some of these functions write to the DB
         try {
             $notice->insert();
             // throws exception on failure, if successful we have an ->id
             if ($notloc->lat && $notloc->lon || $notloc->location_id && $notloc->location_ns) {
                 $notloc->notice_id = $notice->getID();
                 $notloc->insert();
                 // store the notice location if it had any information
             }
         } catch (Exception $e) {
             // Let's test if we managed initial insert, which would imply
             // failing on some update-part (check 'insert()'). Delete if
             // something had been stored to the database.
             if (!empty($notice->id)) {
                 $notice->delete();
             }
             throw $e;
         }
     }
     // Only save 'attention' and metadata stuff (URLs, tags...) stuff if
     // the activityverb is a POST (since stuff like repeat, favorite etc.
     // reasonably handle notifications themselves.
     if (ActivityUtils::compareVerbs($notice->verb, array(ActivityVerb::POST))) {
         if (isset($replies)) {
             $notice->saveKnownReplies($replies);
         } else {
             $notice->saveReplies();
         }
         if (isset($tags)) {
             $notice->saveKnownTags($tags);
         } else {
             $notice->saveTags();
         }
         // Note: groups may save tags, so must be run after tags are saved
         // to avoid errors on duplicates.
         // Note: groups should always be set.
         $notice->saveKnownGroups($groups);
         if (isset($urls)) {
             $notice->saveKnownUrls($urls);
         } else {
             $notice->saveUrls();
         }
     }
     if ($distribute) {
         // Prepare inbox delivery, may be queued to background.
         $notice->distribute();
     }
     return $notice;
 }
コード例 #14
0
ファイル: Notice.php プロジェクト: Br3nda/statusnet-debian
 /**
  * Save a new notice and push it out to subscribers' inboxes.
  * Poster's permissions are checked before sending.
  *
  * @param int $profile_id Profile ID of the poster
  * @param string $content source message text; links may be shortened
  *                        per current user's preference
  * @param string $source source key ('web', 'api', etc)
  * @param array $options Associative array of optional properties:
  *              string 'created' timestamp of notice; defaults to now
  *              int 'is_local' source/gateway ID, one of:
  *                  Notice::LOCAL_PUBLIC    - Local, ok to appear in public timeline
  *                  Notice::REMOTE_OMB      - Sent from a remote OMB service;
  *                                            hide from public timeline but show in
  *                                            local "and friends" timelines
  *                  Notice::LOCAL_NONPUBLIC - Local, but hide from public timeline
  *                  Notice::GATEWAY         - From another non-OMB service;
  *                                            will not appear in public views
  *              float 'lat' decimal latitude for geolocation
  *              float 'lon' decimal longitude for geolocation
  *              int 'location_id' geoname identifier
  *              int 'location_ns' geoname namespace to interpret location_id
  *              int 'reply_to'; notice ID this is a reply to
  *              int 'repeat_of'; notice ID this is a repeat of
  *              string 'uri' unique ID for notice; defaults to local notice URL
  *              string 'url' permalink to notice; defaults to local notice URL
  *              string 'rendered' rendered HTML version of content
  *              array 'replies' list of profile URIs for reply delivery in
  *                              place of extracting @-replies from content.
  *              array 'groups' list of group IDs to deliver to, in place of
  *                              extracting ! tags from content
  *              array 'tags' list of hashtag strings to save with the notice
  *                           in place of extracting # tags from content
  *              array 'urls' list of attached/referred URLs to save with the
  *                           notice in place of extracting links from content
  * @fixme tag override
  *
  * @return Notice
  * @throws ClientException
  */
 static function saveNew($profile_id, $content, $source, $options = null)
 {
     $defaults = array('uri' => null, 'url' => null, 'reply_to' => null, 'repeat_of' => null);
     if (!empty($options)) {
         $options = $options + $defaults;
         extract($options);
     } else {
         extract($defaults);
     }
     if (!isset($is_local)) {
         $is_local = Notice::LOCAL_PUBLIC;
     }
     $profile = Profile::staticGet($profile_id);
     $final = common_shorten_links($content);
     if (Notice::contentTooLong($final)) {
         // TRANS: Client exception thrown if a notice contains too many characters.
         throw new ClientException(_('Problem saving notice. Too long.'));
     }
     if (empty($profile)) {
         // TRANS: Client exception thrown when trying to save a notice for an unknown user.
         throw new ClientException(_('Problem saving notice. Unknown user.'));
     }
     if (common_config('throttle', 'enabled') && !Notice::checkEditThrottle($profile_id)) {
         common_log(LOG_WARNING, 'Excessive posting by profile #' . $profile_id . '; throttled.');
         // TRANS: Client exception thrown when a user tries to post too many notices in a given time frame.
         throw new ClientException(_('Too many notices too fast; take a breather ' . 'and post again in a few minutes.'));
     }
     if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) {
         common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.');
         // TRANS: Client exception thrown when a user tries to post too many duplicate notices in a given time frame.
         throw new ClientException(_('Too many duplicate messages too quickly;' . ' take a breather and post again in a few minutes.'));
     }
     if (!$profile->hasRight(Right::NEWNOTICE)) {
         common_log(LOG_WARNING, "Attempted post from user disallowed to post: " . $profile->nickname);
         // TRANS: Client exception thrown when a user tries to post while being banned.
         throw new ClientException(_('You are banned from posting notices on this site.'), 403);
     }
     $notice = new Notice();
     $notice->profile_id = $profile_id;
     $autosource = common_config('public', 'autosource');
     # Sandboxed are non-false, but not 1, either
     if (!$profile->hasRight(Right::PUBLICNOTICE) || $source && $autosource && in_array($source, $autosource)) {
         $notice->is_local = Notice::LOCAL_NONPUBLIC;
     } else {
         $notice->is_local = $is_local;
     }
     if (!empty($created)) {
         $notice->created = $created;
     } else {
         $notice->created = common_sql_now();
     }
     $notice->content = $final;
     $notice->source = $source;
     $notice->uri = $uri;
     $notice->url = $url;
     // Handle repeat case
     if (isset($repeat_of)) {
         $notice->repeat_of = $repeat_of;
     } else {
         $notice->reply_to = self::getReplyTo($reply_to, $profile_id, $source, $final);
     }
     if (!empty($notice->reply_to)) {
         $reply = Notice::staticGet('id', $notice->reply_to);
         $notice->conversation = $reply->conversation;
     }
     if (!empty($lat) && !empty($lon)) {
         $notice->lat = $lat;
         $notice->lon = $lon;
     }
     if (!empty($location_ns) && !empty($location_id)) {
         $notice->location_id = $location_id;
         $notice->location_ns = $location_ns;
     }
     if (!empty($rendered)) {
         $notice->rendered = $rendered;
     } else {
         $notice->rendered = common_render_content($final, $notice);
     }
     if (Event::handle('StartNoticeSave', array(&$notice))) {
         // XXX: some of these functions write to the DB
         $id = $notice->insert();
         if (!$id) {
             common_log_db_error($notice, 'INSERT', __FILE__);
             // TRANS: Server exception thrown when a notice cannot be saved.
             throw new ServerException(_('Problem saving notice.'));
         }
         // Update ID-dependent columns: URI, conversation
         $orig = clone $notice;
         $changed = false;
         if (empty($uri)) {
             $notice->uri = common_notice_uri($notice);
             $changed = true;
         }
         // If it's not part of a conversation, it's
         // the beginning of a new conversation.
         if (empty($notice->conversation)) {
             $conv = Conversation::create();
             $notice->conversation = $conv->id;
             $changed = true;
         }
         if ($changed) {
             if (!$notice->update($orig)) {
                 common_log_db_error($notice, 'UPDATE', __FILE__);
                 // TRANS: Server exception thrown when a notice cannot be updated.
                 throw new ServerException(_('Problem saving notice.'));
             }
         }
     }
     # Clear the cache for subscribed users, so they'll update at next request
     # XXX: someone clever could prepend instead of clearing the cache
     $notice->blowOnInsert();
     // Save per-notice metadata...
     if (isset($replies)) {
         $notice->saveKnownReplies($replies);
     } else {
         $notice->saveReplies();
     }
     if (isset($tags)) {
         $notice->saveKnownTags($tags);
     } else {
         $notice->saveTags();
     }
     // Note: groups may save tags, so must be run after tags are saved
     // to avoid errors on duplicates.
     if (isset($groups)) {
         $notice->saveKnownGroups($groups);
     } else {
         $notice->saveGroups();
     }
     if (isset($urls)) {
         $notice->saveKnownUrls($urls);
     } else {
         $notice->saveUrls();
     }
     // Prepare inbox delivery, may be queued to background.
     $notice->distribute();
     return $notice;
 }
コード例 #15
0
ファイル: newmessage.php プロジェクト: stevertiqo/StatusNet
 function saveNewMessage()
 {
     // CSRF protection
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         $this->showForm(_('There was a problem with your session token. ' . 'Try again, please.'));
         return;
     }
     $user = common_current_user();
     assert($user);
     // XXX: maybe an error instead...
     if (!$this->content) {
         $this->showForm(_('No content!'));
         return;
     } else {
         $content_shortened = common_shorten_links($this->content);
         if (Message::contentTooLong($content_shortened)) {
             // TRANS: Form validation error displayed when message content is too long.
             // TRANS: %d is the maximum number of characters for a message.
             $this->showForm(sprintf(_m('That\'s too long. Maximum message size is %d character.', 'That\'s too long. Maximum message size is %d characters.', Message::maxContent()), Message::maxContent()));
             return;
         }
     }
     if (!$this->other) {
         $this->showForm(_('No recipient specified.'));
         return;
     } else {
         if (!$user->mutuallySubscribed($this->other)) {
             $this->clientError(_('You can\'t send a message to this user.'), 404);
             return;
         } else {
             if ($user->id == $this->other->id) {
                 $this->clientError(_('Don\'t send a message to yourself; ' . 'just say it to yourself quietly instead.'), 403);
                 return;
             }
         }
     }
     $message = Message::saveNew($user->id, $this->other->id, $this->content, 'web');
     if (is_string($message)) {
         $this->showForm($message);
         return;
     }
     $message->notify();
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         $this->element('title', null, _('Message sent'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $this->element('p', array('id' => 'command_result'), sprintf(_('Direct message to %s sent.'), $this->other->nickname));
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         $url = common_local_url('outbox', array('nickname' => $user->nickname));
         common_redirect($url, 303);
     }
 }
コード例 #16
0
 function create($args, $apidata)
 {
     parent::handle($args);
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->clientError(_('This method requires a POST.'), 400, $apidata['content-type']);
         return;
     }
     $user = $apidata['user'];
     $source = $this->trimmed('source');
     // Not supported by Twitter.
     $reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api');
     if (!$source || in_array($source, $reserved_sources)) {
         $source = 'api';
     }
     $content = $this->trimmed('text');
     if (!$content) {
         $this->clientError(_('No message text!'), $code = 406, $apidata['content-type']);
     } else {
         $content_shortened = common_shorten_links($content);
         if (mb_strlen($content_shortened) > 140) {
             $this->clientError(_('That\'s too long. Max message size is 140 chars.'), $code = 406, $apidata['content-type']);
             return;
         }
     }
     $other = $this->get_user($this->trimmed('user'));
     if (!$other) {
         $this->clientError(_('Recipient user not found.'), $code = 403, $apidata['content-type']);
         return;
     } else {
         if (!$user->mutuallySubscribed($other)) {
             $this->clientError(_('Can\'t send direct messages to users who aren\'t your friend.'), $code = 403, $apidata['content-type']);
             return;
         } else {
             if ($user->id == $other->id) {
                 // Sending msgs to yourself is allowed by Twitter
                 $this->clientError(_('Don\'t send a message to yourself; just say it to yourself quietly instead.'), $code = 403, $apidata['content-type']);
                 return;
             }
         }
     }
     $message = Message::saveNew($user->id, $other->id, html_entity_decode($content, ENT_NOQUOTES, 'UTF-8'), $source);
     if (is_string($message)) {
         $this->serverError($message);
         return;
     }
     $this->notify($user, $other, $message);
     if ($apidata['content-type'] == 'xml') {
         $this->show_single_xml_dmsg($message);
     } elseif ($apidata['content-type'] == 'json') {
         $this->show_single_json_dmsg($message);
     }
 }
コード例 #17
0
ファイル: Notice.php プロジェクト: Grasia/bolotweet
 /**
  * Save a new notice and push it out to subscribers' inboxes.
  * Poster's permissions are checked before sending.
  *
  * @param int $profile_id Profile ID of the poster
  * @param string $content source message text; links may be shortened
  *                        per current user's preference
  * @param string $source source key ('web', 'api', etc)
  * @param array $options Associative array of optional properties:
  *              string 'created' timestamp of notice; defaults to now
  *              int 'is_local' source/gateway ID, one of:
  *                  Notice::LOCAL_PUBLIC    - Local, ok to appear in public timeline
  *                  Notice::REMOTE          - Sent from a remote service;
  *                                            hide from public timeline but show in
  *                                            local "and friends" timelines
  *                  Notice::LOCAL_NONPUBLIC - Local, but hide from public timeline
  *                  Notice::GATEWAY         - From another non-OStatus service;
  *                                            will not appear in public views
  *              float 'lat' decimal latitude for geolocation
  *              float 'lon' decimal longitude for geolocation
  *              int 'location_id' geoname identifier
  *              int 'location_ns' geoname namespace to interpret location_id
  *              int 'reply_to'; notice ID this is a reply to
  *              int 'repeat_of'; notice ID this is a repeat of
  *              string 'uri' unique ID for notice; defaults to local notice URL
  *              string 'url' permalink to notice; defaults to local notice URL
  *              string 'rendered' rendered HTML version of content
  *              array 'replies' list of profile URIs for reply delivery in
  *                              place of extracting @-replies from content.
  *              array 'groups' list of group IDs to deliver to, in place of
  *                              extracting ! tags from content
  *              array 'tags' list of hashtag strings to save with the notice
  *                           in place of extracting # tags from content
  *              array 'urls' list of attached/referred URLs to save with the
  *                           notice in place of extracting links from content
  *              boolean 'distribute' whether to distribute the notice, default true
  *              string 'object_type' URL of the associated object type (default ActivityObject::NOTE)
  *              string 'verb' URL of the associated verb (default ActivityVerb::POST)
  *              int 'scope' Scope bitmask; default to SITE_SCOPE on private sites, 0 otherwise
  *
  * @fixme tag override
  *
  * @return Notice
  * @throws ClientException
  */
 static function saveNew($profile_id, $content, $source, $options = null)
 {
     $defaults = array('uri' => null, 'url' => null, 'reply_to' => null, 'repeat_of' => null, 'scope' => null, 'distribute' => true, 'object_type' => null, 'verb' => null);
     if (!empty($options) && is_array($options)) {
         $options = array_merge($defaults, $options);
         extract($options);
     } else {
         extract($defaults);
     }
     if (!isset($is_local)) {
         $is_local = Notice::LOCAL_PUBLIC;
     }
     $profile = Profile::staticGet('id', $profile_id);
     $user = User::staticGet('id', $profile_id);
     if ($user) {
         // Use the local user's shortening preferences, if applicable.
         $final = $user->shortenLinks($content);
     } else {
         $final = common_shorten_links($content);
     }
     if ($source != 'activity' && $source != 'event') {
         if (Notice::contentTooLong($final)) {
             // TRANS: Client exception thrown if a notice contains too many characters.
             throw new ClientException(_('Problem saving notice. Too long.'));
         }
     }
     if (empty($profile)) {
         // TRANS: Client exception thrown when trying to save a notice for an unknown user.
         throw new ClientException(_('Problem saving notice. Unknown user.'));
     }
     if (common_config('throttle', 'enabled') && !Notice::checkEditThrottle($profile_id)) {
         common_log(LOG_WARNING, 'Excessive posting by profile #' . $profile_id . '; throttled.');
         // TRANS: Client exception thrown when a user tries to post too many notices in a given time frame.
         throw new ClientException(_('Too many notices too fast; take a breather ' . 'and post again in a few minutes.'));
     }
     if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) {
         common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.');
         // TRANS: Client exception thrown when a user tries to post too many duplicate notices in a given time frame.
         throw new ClientException(_('Too many duplicate messages too quickly;' . ' take a breather and post again in a few minutes.'));
     }
     if (!$profile->hasRight(Right::NEWNOTICE)) {
         common_log(LOG_WARNING, "Attempted post from user disallowed to post: " . $profile->nickname);
         // TRANS: Client exception thrown when a user tries to post while being banned.
         throw new ClientException(_('You are banned from posting notices on this site.'), 403);
     }
     $notice = new Notice();
     $notice->profile_id = $profile_id;
     $autosource = common_config('public', 'autosource');
     // Sandboxed are non-false, but not 1, either
     if (!$profile->hasRight(Right::PUBLICNOTICE) || $source && $autosource && in_array($source, $autosource)) {
         $notice->is_local = Notice::LOCAL_NONPUBLIC;
     } else {
         $notice->is_local = $is_local;
     }
     if (!empty($created)) {
         $notice->created = $created;
     } else {
         $notice->created = common_sql_now();
     }
     $notice->content = $final;
     $notice->source = $source;
     $notice->uri = $uri;
     $notice->url = $url;
     // Get the groups here so we can figure out replies and such
     if (!isset($groups)) {
         $groups = self::groupsFromText($notice->content, $profile);
     }
     $reply = null;
     // Handle repeat case
     if (isset($repeat_of)) {
         // Check for a private one
         $repeat = Notice::staticGet('id', $repeat_of);
         if (empty($repeat)) {
             // TRANS: Client exception thrown in notice when trying to repeat a missing or deleted notice.
             throw new ClientException(_('Cannot repeat; original notice is missing or deleted.'));
         }
         if ($profile->id == $repeat->profile_id) {
             // TRANS: Client error displayed when trying to repeat an own notice.
             throw new ClientException(_('You cannot repeat your own notice.'));
         }
         if ($repeat->scope != Notice::SITE_SCOPE && $repeat->scope != Notice::PUBLIC_SCOPE) {
             // TRANS: Client error displayed when trying to repeat a non-public notice.
             throw new ClientException(_('Cannot repeat a private notice.'), 403);
         }
         if (!$repeat->inScope($profile)) {
             // The generic checks above should cover this, but let's be sure!
             // TRANS: Client error displayed when trying to repeat a notice you cannot access.
             throw new ClientException(_('Cannot repeat a notice you cannot read.'), 403);
         }
         if ($profile->hasRepeated($repeat->id)) {
             // TRANS: Client error displayed when trying to repeat an already repeated notice.
             throw new ClientException(_('You already repeated that notice.'));
         }
         $notice->repeat_of = $repeat_of;
     } else {
         $reply = self::getReplyTo($reply_to, $profile_id, $source, $final);
         if (!empty($reply)) {
             if (!$reply->inScope($profile)) {
                 // TRANS: Client error displayed when trying to reply to a notice a the target has no access to.
                 // TRANS: %1$s is a user nickname, %2$d is a notice ID (number).
                 throw new ClientException(sprintf(_('%1$s has no access to notice %2$d.'), $profile->nickname, $reply->id), 403);
             }
             $notice->reply_to = $reply->id;
             $notice->conversation = $reply->conversation;
             // If the original is private to a group, and notice has no group specified,
             // make it to the same group(s)
             if (empty($groups) && $reply->scope | Notice::GROUP_SCOPE) {
                 $groups = array();
                 $replyGroups = $reply->getGroups();
                 foreach ($replyGroups as $group) {
                     if ($profile->isMember($group)) {
                         $groups[] = $group->id;
                     }
                 }
             }
             // Scope set below
         }
     }
     if (!empty($lat) && !empty($lon)) {
         $notice->lat = $lat;
         $notice->lon = $lon;
     }
     if (!empty($location_ns) && !empty($location_id)) {
         $notice->location_id = $location_id;
         $notice->location_ns = $location_ns;
     }
     if (!empty($rendered)) {
         $notice->rendered = $rendered;
     } else {
         $notice->rendered = common_render_content($final, $notice);
     }
     if (empty($verb)) {
         if (!empty($notice->repeat_of)) {
             $notice->verb = ActivityVerb::SHARE;
             $notice->object_type = ActivityObject::ACTIVITY;
         } else {
             $notice->verb = ActivityVerb::POST;
         }
     } else {
         $notice->verb = $verb;
     }
     if (empty($object_type)) {
         $notice->object_type = empty($notice->reply_to) ? ActivityObject::NOTE : ActivityObject::COMMENT;
     } else {
         $notice->object_type = $object_type;
     }
     if (is_null($scope)) {
         // 0 is a valid value
         if (!empty($reply)) {
             $notice->scope = $reply->scope;
         } else {
             $notice->scope = self::defaultScope();
         }
     } else {
         $notice->scope = $scope;
     }
     // For private streams
     $user = $profile->getUser();
     if (!empty($user)) {
         if ($user->private_stream && ($notice->scope == Notice::PUBLIC_SCOPE || $notice->scope == Notice::SITE_SCOPE)) {
             $notice->scope |= Notice::FOLLOWER_SCOPE;
         }
     }
     // Force the scope for private groups
     foreach ($groups as $groupId) {
         $group = User_group::staticGet('id', $groupId);
         if (!empty($group)) {
             if ($group->force_scope) {
                 $notice->scope |= Notice::GROUP_SCOPE;
                 break;
             }
         }
     }
     if (Event::handle('StartNoticeSave', array(&$notice))) {
         // XXX: some of these functions write to the DB
         $id = $notice->insert();
         if (!$id) {
             common_log_db_error($notice, 'INSERT', __FILE__);
             // TRANS: Server exception thrown when a notice cannot be saved.
             throw new ServerException(_('Problem saving notice.'));
         }
         // Update ID-dependent columns: URI, conversation
         $orig = clone $notice;
         $changed = false;
         if (empty($uri)) {
             $notice->uri = common_notice_uri($notice);
             $changed = true;
         }
         // If it's not part of a conversation, it's
         // the beginning of a new conversation.
         if (empty($notice->conversation)) {
             $conv = Conversation::create();
             $notice->conversation = $conv->id;
             $changed = true;
         }
         if ($changed) {
             if (!$notice->update($orig)) {
                 common_log_db_error($notice, 'UPDATE', __FILE__);
                 // TRANS: Server exception thrown when a notice cannot be updated.
                 throw new ServerException(_('Problem saving notice.'));
             }
         }
     }
     // Clear the cache for subscribed users, so they'll update at next request
     // XXX: someone clever could prepend instead of clearing the cache
     $notice->blowOnInsert();
     // Save per-notice metadata...
     if (isset($replies)) {
         $notice->saveKnownReplies($replies);
     } else {
         $notice->saveReplies();
     }
     if (isset($tags)) {
         $notice->saveKnownTags($tags);
     } else {
         $notice->saveTags();
     }
     // Note: groups may save tags, so must be run after tags are saved
     // to avoid errors on duplicates.
     // Note: groups should always be set.
     $notice->saveKnownGroups($groups);
     if (isset($urls)) {
         $notice->saveKnownUrls($urls);
     } else {
         $notice->saveUrls();
     }
     if ($distribute) {
         // Prepare inbox delivery, may be queued to background.
         $notice->distribute();
     }
     return $notice;
 }
コード例 #18
0
ファイル: xmppmanager.php プロジェクト: stevertiqo/StatusNet
 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']);
         // 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);
 }
コード例 #19
0
 /**
  * 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();
 }
コード例 #20
0
ファイル: implugin.php プロジェクト: phpsource/gnu-social
 /**
  * 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);
 }
コード例 #21
0
ファイル: command.php プロジェクト: stevertiqo/StatusNet
 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.'));
     }
 }
コード例 #22
0
ファイル: twitapistatuses.php プロジェクト: Br3nda/laconica
 function update($args, $apidata)
 {
     parent::handle($args);
     if (!in_array($apidata['content-type'], array('xml', 'json'))) {
         $this->clientError(_('API method not found!'), $code = 404);
         return;
     }
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->clientError(_('This method requires a POST.'), 400, $apidata['content-type']);
         return;
     }
     $this->auth_user = $apidata['user'];
     $user = $this->auth_user;
     $status = $this->trimmed('status');
     $source = $this->trimmed('source');
     $in_reply_to_status_id = intval($this->trimmed('in_reply_to_status_id'));
     $reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api');
     if (!$source || in_array($source, $reserved_sources)) {
         $source = 'api';
     }
     if (!$status) {
         // XXX: Note: In this case, Twitter simply returns '200 OK'
         // No error is given, but the status is not posted to the
         // user's timeline.     Seems bad.     Shouldn't we throw an
         // errror? -- Zach
         return;
     } else {
         $status_shortened = common_shorten_links($status);
         if (mb_strlen($status_shortened) > 140) {
             // XXX: Twitter truncates anything over 140, flags the status
             // as "truncated." Sending this error may screw up some clients
             // that assume Twitter will truncate for them.    Should we just
             // truncate too? -- Zach
             $this->clientError(_('That\'s too long. Max notice size is 140 chars.'), $code = 406, $apidata['content-type']);
             return;
         }
     }
     // Check for commands
     $inter = new CommandInterpreter();
     $cmd = $inter->handle_command($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!
         $n = $user->getCurrentNotice();
         $apidata['api_arg'] = $n->id;
     } else {
         $reply_to = null;
         if ($in_reply_to_status_id) {
             // check whether notice actually exists
             $reply = Notice::staticGet($in_reply_to_status_id);
             if ($reply) {
                 $reply_to = $in_reply_to_status_id;
             } else {
                 $this->clientError(_('Not found'), $code = 404, $apidata['content-type']);
                 return;
             }
         }
         $notice = Notice::saveNew($user->id, html_entity_decode($status, ENT_NOQUOTES, 'UTF-8'), $source, 1, $reply_to);
         if (is_string($notice)) {
             $this->serverError($notice);
             return;
         }
         common_broadcast_notice($notice);
         $apidata['api_arg'] = $notice->id;
     }
     $this->show($args, $apidata);
 }
コード例 #23
0
ファイル: postnotice.php プロジェクト: Grasia/bolotweet
 function checkNotice()
 {
     $content = common_shorten_links($_POST['omb_notice_content']);
     if (Notice::contentTooLong($content)) {
         // TRANS: Client error displayed if the notice posted has too many characters.
         $this->clientError(_('Invalid notice content.'), 400);
         return false;
     }
     $license = $_POST['omb_notice_license'];
     $site_license = common_config('license', 'url');
     if ($license && !common_compatible_license($license, $site_license)) {
         // TRANS: Exception thrown if a notice's license is not compatible with the StatusNet site license.
         // TRANS: %1$s is the notice license, %2$s is the StatusNet site's license.
         throw new Exception(sprintf(_('Notice license "%1$s" is not ' . 'compatible with site license "%2$s".'), $license, $site_license));
     }
 }
コード例 #24
0
ファイル: postnotice.php プロジェクト: microcosmx/experiments
 function checkNotice()
 {
     $content = common_shorten_links($_POST['omb_notice_content']);
     if (Notice::contentTooLong($content)) {
         $this->clientError(_('Invalid notice content.'), 400);
         return false;
     }
     $license = $_POST['omb_notice_license'];
     $site_license = common_config('license', 'url');
     if ($license && !common_compatible_license($license, $site_license)) {
         throw new Exception(sprintf(_('Notice license ‘%1$s’ is not ' . 'compatible with site license ‘%2$s’.'), $license, $site_license));
     }
 }
コード例 #25
0
ファイル: newmessage.php プロジェクト: Br3nda/laconica
 function saveNewMessage()
 {
     // CSRF protection
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         $this->showForm(_('There was a problem with your session token. ' . 'Try again, please.'));
         return;
     }
     $user = common_current_user();
     assert($user);
     // XXX: maybe an error instead...
     if (!$this->content) {
         $this->showForm(_('No content!'));
         return;
     } else {
         $content_shortened = common_shorten_links($this->content);
         if (mb_strlen($content_shortened) > 140) {
             $this->showForm(_('That\'s too long. ' . 'Max message size is 140 chars.'));
             return;
         }
     }
     if (!$this->other) {
         $this->showForm(_('No recipient specified.'));
         return;
     } else {
         if (!$user->mutuallySubscribed($this->other)) {
             $this->clientError(_('You can\'t send a message to this user.'), 404);
             return;
         } else {
             if ($user->id == $this->other->id) {
                 $this->clientError(_('Don\'t send a message to yourself; ' . 'just say it to yourself quietly instead.'), 403);
                 return;
             }
         }
     }
     $message = Message::saveNew($user->id, $this->other->id, $this->content, 'web');
     if (is_string($message)) {
         $this->showForm($message);
         return;
     }
     $this->notify($user, $this->other, $message);
     $url = common_local_url('outbox', array('nickname' => $user->nickname));
     common_redirect($url, 303);
 }
コード例 #26
0
ファイル: User.php プロジェクト: Grasia/bolotweet
 /**
  * Find and shorten links in the given text using this user's URL shortening
  * settings.
  *
  * By default, links will be left untouched if the text is shorter than the
  * configured maximum notice length. Pass true for the $always parameter
  * to force all links to be shortened regardless.
  *
  * Side effects: may save file and file_redirection records for referenced URLs.
  *
  * @param string $text
  * @param boolean $always
  * @return string
  */
 public function shortenLinks($text, $always = false)
 {
     return common_shorten_links($text, $always, $this);
 }
コード例 #27
0
 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.'));
     }
 }
コード例 #28
0
ファイル: newnotice.php プロジェクト: Br3nda/laconica
 /**
  * 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!'));
     } else {
         $content_shortened = common_shorten_links($content);
         if (mb_strlen($content_shortened) > 140) {
             $this->clientError(_('That\'s too long. ' . 'Max notice size is 140 chars.'));
         }
     }
     $inter = new CommandInterpreter();
     $cmd = $inter->handle_command($user, $content_shortened);
     if ($cmd) {
         if ($this->boolean('ajax')) {
             $cmd->execute(new AjaxWebChannel($this));
         } else {
             $cmd->execute(new WebChannel($this));
         }
         return;
     }
     $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';
     }
     $notice = Notice::saveNew($user->id, $content, 'web', 1, $replyto == 'false' ? null : $replyto);
     if (is_string($notice)) {
         $this->clientError($notice);
         return;
     }
     common_broadcast_notice($notice);
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $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);
     }
 }
コード例 #29
0
ファイル: command.php プロジェクト: Br3nda/laconica
 function execute($channel)
 {
     $other = User::staticGet('nickname', common_canonical_nickname($this->other));
     $len = mb_strlen($this->text);
     if ($len == 0) {
         $channel->error($this->user, _('No content!'));
         return;
     } else {
         if ($len > 140) {
             $content = common_shorten_links($content);
             if (mb_strlen($content) > 140) {
                 $channel->error($this->user, sprintf(_('Message too long - maximum is 140 characters, you sent %d'), $len));
                 return;
             }
         }
     }
     if (!$other) {
         $channel->error($this->user, _('No such user.'));
         return;
     } else {
         if (!$this->user->mutuallySubscribed($other)) {
             $channel->error($this->user, _('You can\'t send a message to this user.'));
             return;
         } else {
             if ($this->user->id == $other->id) {
                 $channel->error($this->user, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
                 return;
             }
         }
     }
     $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
     if ($message) {
         $channel->output($this->user, sprintf(_('Direct message to %s sent'), $this->other));
     } else {
         $channel->error($this->user, _('Error sending direct message.'));
     }
 }
コード例 #30
0
 /**
  * Handle the request
  *
  * Save the new message
  *
  * @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;
     }
     if (empty($this->content)) {
         $this->clientError(_('No message text!'), 406, $this->format);
     } else {
         $content_shortened = common_shorten_links($this->content);
         if (Message::contentTooLong($content_shortened)) {
             $this->clientError(sprintf(_('That\'s too long. Max message size is %d chars.'), Message::maxContent()), 406, $this->format);
             return;
         }
     }
     if (empty($this->other)) {
         $this->clientError(_('Recipient user not found.'), 403, $this->format);
         return;
     } else {
         if (!$this->user->mutuallySubscribed($this->other)) {
             $this->clientError(_('Can\'t send direct messages to users who aren\'t your friend.'), 403, $this->format);
             return;
         } else {
             if ($this->user->id == $this->other->id) {
                 // Note: sending msgs to yourself is allowed by Twitter
                 $errmsg = 'Don\'t send a message to yourself; ' . 'just say it to yourself quietly instead.';
                 $this->clientError(_($errmsg), 403, $this->format);
                 return;
             }
         }
     }
     $message = Message::saveNew($this->user->id, $this->other->id, html_entity_decode($this->content, ENT_NOQUOTES, 'UTF-8'), $this->source);
     if (is_string($message)) {
         $this->serverError($message);
         return;
     }
     $message->notify();
     if ($this->format == 'xml') {
         $this->showSingleXmlDirectMessage($message);
     } elseif ($this->format == 'json') {
         $this->showSingleJsondirectMessage($message);
     }
 }