Example #1
0
function common_linkify_mentions($text, $notice)
{
    $mentions = common_find_mentions($text, $notice);
    // We need to go through in reverse order by position,
    // so our positions stay valid despite our fudging with the
    // string!
    $points = array();
    foreach ($mentions as $mention) {
        $points[$mention['position']] = $mention;
    }
    krsort($points);
    foreach ($points as $position => $mention) {
        $linkText = common_linkify_mention($mention);
        $text = substr_replace($text, $linkText, $position, mb_strlen($mention['text']));
    }
    return $text;
}
Example #2
0
function common_get_attentions($text, Profile $sender, Notice $parent = null)
{
    $mentions = common_find_mentions($text, $sender, $parent);
    $atts = array();
    foreach ($mentions as $mention) {
        foreach ($mention['mentioned'] as $mentioned) {
            $atts[$mentioned->getUri()] = $mentioned->getObjectType();
        }
    }
    if ($parent instanceof Notice) {
        $parentAuthor = $parent->getProfile();
        // afaik groups can't be authors
        $atts[$parentAuthor->getUri()] = ActivityObject::PERSON;
    }
    return $atts;
}
Example #3
0
 /**
  * Pull @-replies from this message's content in StatusNet markup format
  * and save reply records indicating that this message needs to be
  * delivered to those users.
  *
  * Mail notifications to local profiles will be sent later.
  *
  * @return array of integer profile IDs
  */
 function saveReplies()
 {
     $sender = $this->getProfile();
     $replied = array();
     // If it's a reply, save for the replied-to author
     try {
         $parent = $this->getParent();
         $parentauthor = $parent->getProfile();
         $this->saveReply($parentauthor->getID());
         $replied[$parentauthor->getID()] = 1;
         self::blow('reply:stream:%d', $parentauthor->getID());
     } catch (NoParentNoticeException $e) {
         // Not a reply, since it has no parent!
         $parent = null;
     } catch (NoResultException $e) {
         // Parent notice was probably deleted
         $parent = null;
     }
     // @todo ideally this parser information would only
     // be calculated once.
     $mentions = common_find_mentions($this->content, $sender, $parent);
     foreach ($mentions as $mention) {
         foreach ($mention['mentioned'] as $mentioned) {
             // skip if they're already covered
             if (array_key_exists($mentioned->id, $replied)) {
                 continue;
             }
             // Don't save replies from blocked profile to local user
             if ($mentioned->hasBlocked($sender)) {
                 continue;
             }
             $this->saveReply($mentioned->id);
             $replied[$mentioned->id] = 1;
             self::blow('reply:stream:%d', $mentioned->id);
         }
     }
     $recipientIds = array_keys($replied);
     return $recipientIds;
 }
Example #4
0
 /**
  * Pull @-replies from this message's content in StatusNet markup format
  * and save reply records indicating that this message needs to be
  * delivered to those users.
  *
  * Mail notifications to local profiles will be sent later.
  *
  * @return array of integer profile IDs
  */
 function saveReplies()
 {
     // Don't save reply data for repeats
     if (!empty($this->repeat_of)) {
         return array();
     }
     $sender = Profile::staticGet($this->profile_id);
     // @todo ideally this parser information would only
     // be calculated once.
     $mentions = common_find_mentions($this->content, $this);
     $replied = array();
     // store replied only for first @ (what user/notice what the reply directed,
     // we assume first @ is it)
     foreach ($mentions as $mention) {
         foreach ($mention['mentioned'] as $mentioned) {
             // skip if they're already covered
             if (!empty($replied[$mentioned->id])) {
                 continue;
             }
             // Don't save replies from blocked profile to local user
             $mentioned_user = User::staticGet('id', $mentioned->id);
             if (!empty($mentioned_user) && $mentioned_user->hasBlocked($sender)) {
                 continue;
             }
             $reply = new Reply();
             $reply->notice_id = $this->id;
             $reply->profile_id = $mentioned->id;
             $id = $reply->insert();
             if (!$id) {
                 common_log_db_error($reply, 'INSERT', __FILE__);
                 // TRANS: Server exception thrown when a reply cannot be saved.
                 // TRANS: %1$d is a notice ID, %2$d is the ID of the mentioned user.
                 throw new ServerException(sprintf(_("Could not save reply for %1{$d}, %2{$d}."), $this->id, $mentioned->id));
             } else {
                 $replied[$mentioned->id] = 1;
                 self::blow('reply:stream:%d', $mentioned->id);
             }
         }
     }
     $recipientIds = array_keys($replied);
     return $recipientIds;
 }
Example #5
0
 /**
  * Pull @-replies from this message's content in StatusNet markup format
  * and save reply records indicating that this message needs to be
  * delivered to those users.
  *
  * Mail notifications to local profiles will be sent later.
  *
  * @return array of integer profile IDs
  */
 function saveReplies()
 {
     // Don't save reply data for repeats
     if (!empty($this->repeat_of)) {
         return array();
     }
     $sender = Profile::staticGet($this->profile_id);
     $replied = array();
     // If it's a reply, save for the replied-to author
     if (!empty($this->reply_to)) {
         $original = $this->getOriginal();
         if (!empty($original)) {
             // that'd be weird
             $author = $original->getProfile();
             if (!empty($author)) {
                 $this->saveReply($author->id);
                 $replied[$author->id] = 1;
                 self::blow('reply:stream:%d', $author->id);
             }
         }
     }
     // @todo ideally this parser information would only
     // be calculated once.
     $mentions = common_find_mentions($this->content, $this);
     // store replied only for first @ (what user/notice what the reply directed,
     // we assume first @ is it)
     foreach ($mentions as $mention) {
         foreach ($mention['mentioned'] as $mentioned) {
             // skip if they're already covered
             if (!empty($replied[$mentioned->id])) {
                 continue;
             }
             // Don't save replies from blocked profile to local user
             $mentioned_user = User::staticGet('id', $mentioned->id);
             if (!empty($mentioned_user) && $mentioned_user->hasBlocked($sender)) {
                 continue;
             }
             $this->saveReply($mentioned->id);
             $replied[$mentioned->id] = 1;
             self::blow('reply:stream:%d', $mentioned->id);
         }
     }
     $recipientIds = array_keys($replied);
     return $recipientIds;
 }
Example #6
0
 /**
  * Pull @-replies from this message's content in StatusNet markup format
  * and save reply records indicating that this message needs to be
  * delivered to those users.
  *
  * Mail notifications to local profiles will be sent later.
  *
  * @return array of integer profile IDs
  */
 function saveReplies()
 {
     // Don't save reply data for repeats
     if ($this->isRepeat()) {
         return array();
     }
     $sender = $this->getProfile();
     $replied = array();
     // If it's a reply, save for the replied-to author
     try {
         $parent = $this->getParent();
         $parentauthor = $parent->getProfile();
         $this->saveReply($parentauthor->id);
         $replied[$parentauthor->id] = 1;
         self::blow('reply:stream:%d', $parentauthor->id);
     } catch (NoParentNoticeException $e) {
         // Not a reply, since it has no parent!
     }
     // @todo ideally this parser information would only
     // be calculated once.
     $mentions = common_find_mentions($this->content, $this);
     // store replied only for first @ (what user/notice what the reply directed,
     // we assume first @ is it)
     foreach ($mentions as $mention) {
         foreach ($mention['mentioned'] as $mentioned) {
             // skip if they're already covered
             if (array_key_exists($mentioned->id, $replied)) {
                 continue;
             }
             // Don't save replies from blocked profile to local user
             $mentioned_user = User::getKV('id', $mentioned->id);
             if ($mentioned_user instanceof User && $mentioned_user->hasBlocked($sender)) {
                 continue;
             }
             $this->saveReply($mentioned->id);
             $replied[$mentioned->id] = 1;
             self::blow('reply:stream:%d', $mentioned->id);
         }
     }
     $recipientIds = array_keys($replied);
     return $recipientIds;
 }