function common_find_mentions($text, $notice) { $mentions = array(); $sender = Profile::staticGet('id', $notice->profile_id); if (empty($sender)) { return $mentions; } if (Event::handle('StartFindMentions', array($sender, $text, &$mentions))) { // Get the context of the original notice, if any $originalAuthor = null; $originalNotice = null; $originalMentions = array(); // Is it a reply? if (!empty($notice) && !empty($notice->reply_to)) { $originalNotice = Notice::staticGet('id', $notice->reply_to); if (!empty($originalNotice)) { $originalAuthor = Profile::staticGet('id', $originalNotice->profile_id); $ids = $originalNotice->getReplies(); foreach ($ids as $id) { $repliedTo = Profile::staticGet('id', $id); if (!empty($repliedTo)) { $originalMentions[$repliedTo->nickname] = $repliedTo; } } } } preg_match_all('/^T ([A-Z0-9]{1,64}) /u', $text, $tmatches, PREG_OFFSET_CAPTURE); preg_match_all('/(?:^|\\s+)@([' . NICKNAME_FMT . ']{1,64})/', $text, $atmatches, PREG_OFFSET_CAPTURE); $matches = array_merge($tmatches[1], $atmatches[1]); foreach ($matches as $match) { $nickname = common_canonical_nickname($match[0]); // Try to get a profile for this nickname. // Start with conversation context, then go to // sender context. if (!empty($originalAuthor) && $originalAuthor->nickname == $nickname) { $mentioned = $originalAuthor; } else { if (!empty($originalMentions) && array_key_exists($nickname, $originalMentions)) { $mentioned = $originalMentions[$nickname]; } else { $mentioned = common_relative_profile($sender, $nickname); } } if (!empty($mentioned)) { $user = User::staticGet('id', $mentioned->id); if ($user) { $url = common_local_url('userbyid', array('id' => $user->id)); } else { $url = $mentioned->profileurl; } $mention = array('mentioned' => array($mentioned), 'text' => $match[0], 'position' => $match[1], 'url' => $url); if (!empty($mentioned->fullname)) { $mention['title'] = $mentioned->fullname; } $mentions[] = $mention; } } // @#tag => mention of all subscriptions tagged 'tag' preg_match_all('/(?:^|[\\s\\.\\,\\:\\;]+)@#([\\pL\\pN_\\-\\.]{1,64})/u', $text, $hmatches, PREG_OFFSET_CAPTURE); foreach ($hmatches[1] as $hmatch) { $tag = common_canonical_tag($hmatch[0]); $tagged = Profile_tag::getTagged($sender->id, $tag); $url = common_local_url('subscriptions', array('nickname' => $sender->nickname, 'tag' => $tag)); $mentions[] = array('mentioned' => $tagged, 'text' => $hmatch[0], 'position' => $hmatch[1], 'url' => $url); } Event::handle('EndFindMentions', array($sender, $text, &$mentions)); } return $mentions; }
/** * Save a new notice bookmark * * @param Profile $profile To save the bookmark for * @param string $title Title of the bookmark * @param string $url URL of the bookmark * @param mixed $rawtags array of tags or string * @param string $description Description of the bookmark * @param array $options Options for the Notice::saveNew() * * @return Notice saved notice */ static function saveNew($profile, $title, $url, $rawtags, $description, $options = null) { if (!common_valid_http_url($url)) { throw new ClientException(_m('Only web bookmarks can be posted (HTTP or HTTPS).')); } $nb = self::getByURL($profile, $url); if (!empty($nb)) { // TRANS: Client exception thrown when trying to save a new bookmark that already exists. throw new ClientException(_m('Bookmark already exists.')); } if (empty($options)) { $options = array(); } if (array_key_exists('uri', $options)) { $other = Bookmark::getKV('uri', $options['uri']); if (!empty($other)) { // TRANS: Client exception thrown when trying to save a new bookmark that already exists. throw new ClientException(_m('Bookmark already exists.')); } } if (is_string($rawtags)) { if (empty($rawtags)) { $rawtags = array(); } else { $rawtags = preg_split('/[\\s,]+/', $rawtags); } } $nb = new Bookmark(); $nb->id = UUID::gen(); $nb->profile_id = $profile->id; $nb->url = $url; $nb->title = $title; $nb->description = $description; if (array_key_exists('created', $options)) { $nb->created = $options['created']; } else { $nb->created = common_sql_now(); } if (array_key_exists('uri', $options)) { $nb->uri = $options['uri']; } else { // FIXME: hacks to work around router bugs in // queue daemons $r = Router::get(); $path = $r->build('showbookmark', array('id' => $nb->id)); if (empty($path)) { $nb->uri = common_path('bookmark/' . $nb->id, false, false); } else { $nb->uri = common_local_url('showbookmark', array('id' => $nb->id), null, null, false); } } $nb->insert(); $tags = array(); $replies = array(); // filter "for:nickname" tags foreach ($rawtags as $tag) { if (strtolower(mb_substr($tag, 0, 4)) == 'for:') { // skip if done by caller if (!array_key_exists('replies', $options)) { $nickname = mb_substr($tag, 4); $other = common_relative_profile($profile, $nickname); if (!empty($other)) { $replies[] = $other->getUri(); } } } else { $tags[] = common_canonical_tag($tag); } } $hashtags = array(); $taglinks = array(); foreach ($tags as $tag) { $hashtags[] = '#' . $tag; $attrs = array('href' => Notice_tag::url($tag), 'rel' => $tag, 'class' => 'tag'); $taglinks[] = XMLStringer::estring('a', $attrs, $tag); } // Use user's preferences for short URLs, if possible try { $user = User::getKV('id', $profile->id); $shortUrl = File_redirection::makeShort($url, empty($user) ? null : $user); } catch (Exception $e) { // Don't let this stop us. $shortUrl = $url; } // TRANS: Bookmark content. // TRANS: %1$s is a title, %2$s is a short URL, %3$s is the bookmark description, // TRANS: %4$s is space separated list of hash tags. $content = sprintf(_m('"%1$s" %2$s %3$s %4$s'), $title, $shortUrl, $description, implode(' ', $hashtags)); // TRANS: Rendered bookmark content. // TRANS: %1$s is a URL, %2$s the bookmark title, %3$s is the bookmark description, // TRANS: %4$s is space separated list of hash tags. $rendered = sprintf(_m('<span class="xfolkentry">' . '<a class="taggedlink" href="%1$s">%2$s</a> ' . '<span class="description">%3$s</span> ' . '<span class="meta">%4$s</span>' . '</span>'), htmlspecialchars($url), htmlspecialchars($title), htmlspecialchars($description), implode(' ', $taglinks)); $options = array_merge(array('urls' => array($url), 'rendered' => $rendered, 'tags' => $tags, 'replies' => $replies, 'object_type' => ActivityObject::BOOKMARK), $options); if (!array_key_exists('uri', $options)) { $options['uri'] = $nb->uri; } try { $saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options); } catch (Exception $e) { $nb->delete(); throw $e; } if (empty($saved)) { $nb->delete(); } return $saved; }
/** * Find @-mentions in the given text, using the given notice object as context. * References will be resolved with common_relative_profile() against the user * who posted the notice. * * Note the return data format is internal, to be used for building links and * such. Should not be used directly; rather, call common_linkify_mentions(). * * @param string $text * @param Notice $notice notice in whose context we're building links * * @return array * * @access private */ function common_find_mentions($text, $notice) { $mentions = array(); $sender = Profile::staticGet('id', $notice->profile_id); if (empty($sender)) { return $mentions; } if (Event::handle('StartFindMentions', array($sender, $text, &$mentions))) { // Get the context of the original notice, if any $originalAuthor = null; $originalNotice = null; $originalMentions = array(); // Is it a reply? if (!empty($notice) && !empty($notice->reply_to)) { $originalNotice = Notice::staticGet('id', $notice->reply_to); if (!empty($originalNotice)) { $originalAuthor = Profile::staticGet('id', $originalNotice->profile_id); $ids = $originalNotice->getReplies(); foreach ($ids as $id) { $repliedTo = Profile::staticGet('id', $id); if (!empty($repliedTo)) { $originalMentions[$repliedTo->nickname] = $repliedTo; } } } } $matches = common_find_mentions_raw($text); foreach ($matches as $match) { try { $nickname = Nickname::normalize($match[0]); } catch (NicknameException $e) { // Bogus match? Drop it. continue; } // Try to get a profile for this nickname. // Start with conversation context, then go to // sender context. if (!empty($originalAuthor) && $originalAuthor->nickname == $nickname) { $mentioned = $originalAuthor; } else { if (!empty($originalMentions) && array_key_exists($nickname, $originalMentions)) { $mentioned = $originalMentions[$nickname]; } else { $mentioned = common_relative_profile($sender, $nickname); } } if (!empty($mentioned)) { $user = User::staticGet('id', $mentioned->id); if ($user) { $url = common_local_url('userbyid', array('id' => $user->id)); } else { $url = $mentioned->profileurl; } $mention = array('mentioned' => array($mentioned), 'text' => $match[0], 'position' => $match[1], 'url' => $url); if (!empty($mentioned->fullname)) { $mention['title'] = $mentioned->fullname; } $mentions[] = $mention; } } // @#tag => mention of all subscriptions tagged 'tag' preg_match_all('/(?:^|[\\s\\.\\,\\:\\;]+)@#([\\pL\\pN_\\-\\.]{1,64})/', $text, $hmatches, PREG_OFFSET_CAPTURE); foreach ($hmatches[1] as $hmatch) { $tag = common_canonical_tag($hmatch[0]); $plist = Profile_list::getByTaggerAndTag($sender->id, $tag); if (!empty($plist) && !$plist->private) { $tagged = $sender->getTaggedSubscribers($tag); $url = common_local_url('showprofiletag', array('tagger' => $sender->nickname, 'tag' => $tag)); $mentions[] = array('mentioned' => $tagged, 'text' => $hmatch[0], 'position' => $hmatch[1], 'url' => $url); } } Event::handle('EndFindMentions', array($sender, $text, &$mentions)); } return $mentions; }
function execute($channel) { $target_nickname = common_canonical_nickname($this->other); $target = common_relative_profile($this->user, $target_nickname); if (!$target) { $channel->error($this->user, _('No such user.')); return; } $notice = $target->getCurrentNotice(); if (!$notice) { $channel->error($this->user, _('User has no last notice')); return; } $notice_content = $notice->content; $channel->output($this->user, $target_nickname . ": " . $notice_content); }
/** * Find @-mentions in the given text, using the given notice object as context. * References will be resolved with common_relative_profile() against the user * who posted the notice. * * Note the return data format is internal, to be used for building links and * such. Should not be used directly; rather, call common_linkify_mentions(). * * @param string $text * @param Profile $sender the Profile that is sending the current text * @param Notice $parent the Notice this text is in reply to, if any * * @return array * * @access private */ function common_find_mentions($text, Profile $sender, Notice $parent = null) { $mentions = array(); if (Event::handle('StartFindMentions', array($sender, $text, &$mentions))) { // Get the context of the original notice, if any $origMentions = array(); // Does it have a parent notice for context? if ($parent instanceof Notice) { $ids = $parent->getReplies(); // replied-to _profile ids_ foreach ($ids as $id) { try { $repliedTo = Profile::getByID($id); $origMentions[$repliedTo->getNickname()] = $repliedTo; } catch (NoResultException $e) { // continue foreach } } } $matches = common_find_mentions_raw($text); foreach ($matches as $match) { try { $nickname = Nickname::normalize($match[0]); } catch (NicknameException $e) { // Bogus match? Drop it. continue; } // Try to get a profile for this nickname. // Start with conversation context, then go to // sender context. if ($parent instanceof Notice && $parent->getProfile()->getNickname() === $nickname) { $mentioned = $parent->getProfile(); } else { if (!empty($origMentions) && array_key_exists($nickname, $origMentions)) { $mentioned = $origMentions[$nickname]; } else { // sets to null if no match $mentioned = common_relative_profile($sender, $nickname); } } if ($mentioned instanceof Profile) { $user = User::getKV('id', $mentioned->id); try { $url = $mentioned->getUrl(); } catch (InvalidUrlException $e) { $url = common_local_url('userbyid', array('id' => $mentioned->getID())); } $mention = array('mentioned' => array($mentioned), 'type' => 'mention', 'text' => $match[0], 'position' => $match[1], 'length' => mb_strlen($match[0]), 'title' => $mentioned->getFullname(), 'url' => $url); $mentions[] = $mention; } } // @#tag => mention of all subscriptions tagged 'tag' preg_match_all('/(?:^|[\\s\\.\\,\\:\\;]+)@#([\\pL\\pN_\\-\\.]{1,64})/', $text, $hmatches, PREG_OFFSET_CAPTURE); foreach ($hmatches[1] as $hmatch) { $tag = common_canonical_tag($hmatch[0]); $plist = Profile_list::getByTaggerAndTag($sender->getID(), $tag); if (!$plist instanceof Profile_list || $plist->private) { continue; } $tagged = $sender->getTaggedSubscribers($tag); $url = common_local_url('showprofiletag', array('nickname' => $sender->getNickname(), 'tag' => $tag)); $mentions[] = array('mentioned' => $tagged, 'type' => 'list', 'text' => $hmatch[0], 'position' => $hmatch[1], 'length' => mb_strlen($hmatch[0]), 'url' => $url); } preg_match_all('/(?:^|[\\s\\.\\,\\:\\;]+)!(' . Nickname::DISPLAY_FMT . ')/', $text, $hmatches, PREG_OFFSET_CAPTURE); foreach ($hmatches[1] as $hmatch) { $nickname = Nickname::normalize($hmatch[0]); $group = User_group::getForNickname($nickname, $sender); if (!$group instanceof User_group || !$sender->isMember($group)) { continue; } $profile = $group->getProfile(); $mentions[] = array('mentioned' => array($profile), 'type' => 'group', 'text' => $hmatch[0], 'position' => $hmatch[1], 'length' => mb_strlen($hmatch[0]), 'url' => $group->permalink(), 'title' => $group->getFancyName()); } Event::handle('EndFindMentions', array($sender, $text, &$mentions)); } return $mentions; }
/** * Look up a local or remote profile by nickname. * * @return Profile * @throws CommandException */ function getProfile($arg) { $profile = null; if (Event::handle('StartCommandGetProfile', array($this, $arg, &$profile))) { $profile = common_relative_profile($this->user, common_canonical_nickname($arg)); } Event::handle('EndCommandGetProfile', array($this, $arg, &$profile)); if (!$profile) { throw new CommandException(sprintf(_('Could not find a user with nickname %s'), $arg)); } return $profile; }
/** * Look up a local or remote profile by nickname. * * @return Profile * @throws CommandException */ function getProfile($arg) { $profile = null; if (Event::handle('StartCommandGetProfile', array($this, $arg, &$profile))) { $profile = common_relative_profile($this->user, common_canonical_nickname($arg)); } Event::handle('EndCommandGetProfile', array($this, $arg, &$profile)); if (!$profile) { // TRANS: Message given requesting a profile for a non-existing user. // TRANS: %s is the nickname of the user for which the profile could not be found. throw new CommandException(sprintf(_('Could not find a user with nickname %s.'), $arg)); } return $profile; }
/** * Determine which notice, if any, a new notice is in reply to. * * For conversation tracking, we try to see where this notice fits * in the tree. Beware that this may very well give false positives * and add replies to wrong threads (if there have been newer posts * by the same user as we're replying to). * * @param Profile $sender Author profile * @param string $content Final notice content * * @return integer ID of replied-to notice, or null for not a reply. */ static function getInlineReplyTo(Profile $sender, $content) { // Is there an initial @ or T? if (preg_match('/^T ([A-Z0-9]{1,64}) /', $content, $match) || preg_match('/^@([a-z0-9]{1,64})\\s+/', $content, $match)) { $nickname = common_canonical_nickname($match[1]); } else { return null; } // Figure out who that is. $recipient = common_relative_profile($sender, $nickname, common_sql_now()); if ($recipient instanceof Profile) { // Get their last notice $last = $recipient->getCurrentNotice(); if ($last instanceof Notice) { return $last; } // Maybe in the future we want to handle something else below // so don't return getCurrentNotice() immediately. } return null; }
/** * Find @-mentions in the given text, using the given notice object as context. * References will be resolved with common_relative_profile() against the user * who posted the notice. * * Note the return data format is internal, to be used for building links and * such. Should not be used directly; rather, call common_linkify_mentions(). * * @param string $text * @param Notice $notice notice in whose context we're building links * * @return array * * @access private */ function common_find_mentions($text, Notice $notice) { // The getProfile call throws NoProfileException on failure $sender = $notice->getProfile(); $mentions = array(); if (Event::handle('StartFindMentions', array($sender, $text, &$mentions))) { // Get the context of the original notice, if any $origAuthor = null; $origNotice = null; $origMentions = array(); // Is it a reply? if ($notice instanceof Notice) { try { $origNotice = $notice->getParent(); $origAuthor = $origNotice->getProfile(); $ids = $origNotice->getReplies(); foreach ($ids as $id) { $repliedTo = Profile::getKV('id', $id); if ($repliedTo instanceof Profile) { $origMentions[$repliedTo->nickname] = $repliedTo; } } } catch (NoProfileException $e) { common_log(LOG_WARNING, sprintf('Notice %d author profile id %d does not exist', $origNotice->id, $origNotice->profile_id)); } catch (NoParentNoticeException $e) { // This notice is not in reply to anything } catch (Exception $e) { common_log(LOG_WARNING, __METHOD__ . ' got exception ' . get_class($e) . ' : ' . $e->getMessage()); } } $matches = common_find_mentions_raw($text); foreach ($matches as $match) { try { $nickname = Nickname::normalize($match[0]); } catch (NicknameException $e) { // Bogus match? Drop it. continue; } // Try to get a profile for this nickname. // Start with conversation context, then go to // sender context. if ($origAuthor instanceof Profile && $origAuthor->nickname == $nickname) { $mentioned = $origAuthor; } else { if (!empty($origMentions) && array_key_exists($nickname, $origMentions)) { $mentioned = $origMentions[$nickname]; } else { $mentioned = common_relative_profile($sender, $nickname); } } if ($mentioned instanceof Profile) { $user = User::getKV('id', $mentioned->id); if ($user instanceof User) { $url = common_local_url('userbyid', array('id' => $user->id)); } else { $url = $mentioned->profileurl; } $mention = array('mentioned' => array($mentioned), 'type' => 'mention', 'text' => $match[0], 'position' => $match[1], 'url' => $url); if (!empty($mentioned->fullname)) { $mention['title'] = $mentioned->fullname; } $mentions[] = $mention; } } // @#tag => mention of all subscriptions tagged 'tag' preg_match_all('/(?:^|[\\s\\.\\,\\:\\;]+)@#([\\pL\\pN_\\-\\.]{1,64})/', $text, $hmatches, PREG_OFFSET_CAPTURE); foreach ($hmatches[1] as $hmatch) { $tag = common_canonical_tag($hmatch[0]); $plist = Profile_list::getByTaggerAndTag($sender->id, $tag); if (!$plist instanceof Profile_list || $plist->private) { continue; } $tagged = $sender->getTaggedSubscribers($tag); $url = common_local_url('showprofiletag', array('tagger' => $sender->nickname, 'tag' => $tag)); $mentions[] = array('mentioned' => $tagged, 'type' => 'list', 'text' => $hmatch[0], 'position' => $hmatch[1], 'url' => $url); } preg_match_all('/(?:^|[\\s\\.\\,\\:\\;]+)!(' . Nickname::DISPLAY_FMT . ')/', $text, $hmatches, PREG_OFFSET_CAPTURE); foreach ($hmatches[1] as $hmatch) { $nickname = Nickname::normalize($hmatch[0]); $group = User_group::getForNickname($nickname, $sender); if (!$group instanceof User_group || !$sender->isMember($group)) { continue; } $profile = $group->getProfile(); $mentions[] = array('mentioned' => array($profile), 'type' => 'group', 'text' => $hmatch[0], 'position' => $hmatch[1], 'url' => $group->permalink(), 'title' => $group->getFancyName()); } Event::handle('EndFindMentions', array($sender, $text, &$mentions)); } return $mentions; }
/** * Determine which notice, if any, a new notice is in reply to. * * For conversation tracking, we try to see where this notice fits * in the tree. Rough algorithm is: * * if (reply_to is set and valid) { * return reply_to; * } else if ((source not API or Web) and (content starts with "T NAME" or "@name ")) { * return ID of last notice by initial @name in content; * } * * Note that all @nickname instances will still be used to save "reply" records, * so the notice shows up in the mentioned users' "replies" tab. * * @param integer $reply_to ID passed in by Web or API * @param integer $profile_id ID of author * @param string $source Source tag, like 'web' or 'gwibber' * @param string $content Final notice content * * @return integer ID of replied-to notice, or null for not a reply. */ static function getReplyTo($reply_to, $profile_id, $source, $content) { static $lb = array('xmpp', 'mail', 'sms', 'omb'); // If $reply_to is specified, we check that it exists, and then // return it if it does if (!empty($reply_to)) { $reply_notice = Notice::staticGet('id', $reply_to); if (!empty($reply_notice)) { return $reply_to; } } // If it's not a "low bandwidth" source (one where you can't set // a reply_to argument), we return. This is mostly web and API // clients. if (!in_array($source, $lb)) { return null; } // Is there an initial @ or T? if (preg_match('/^T ([A-Z0-9]{1,64}) /', $content, $match) || preg_match('/^@([a-z0-9]{1,64})\\s+/', $content, $match)) { $nickname = common_canonical_nickname($match[1]); } else { return null; } // Figure out who that is. $sender = Profile::staticGet('id', $profile_id); if (empty($sender)) { return null; } $recipient = common_relative_profile($sender, $nickname, common_sql_now()); if (empty($recipient)) { return null; } // Get their last notice $last = $recipient->getCurrentNotice(); if (!empty($last)) { return $last->id; } }
function common_at_link($sender_id, $nickname) { $sender = Profile::staticGet($sender_id); $recipient = common_relative_profile($sender, common_canonical_nickname($nickname)); if ($recipient) { $user = User::staticGet('id', $recipient->id); if ($user) { $url = common_local_url('userbyid', array('id' => $user->id)); } else { $url = $recipient->profileurl; } $xs = new XMLStringer(false); $xs->elementStart('span', 'vcard'); $xs->elementStart('a', array('href' => $url, 'class' => 'url')); $xs->element('span', 'fn nickname', $nickname); $xs->elementEnd('a'); $xs->elementEnd('span'); return $xs->getString(); } else { return $nickname; } }
/** * Save a new notice bookmark * * @param Profile $profile To save the bookmark for * @param string $title Title of the bookmark * @param string $url URL of the bookmark * @param array $rawtags array of tags * @param string $description Description of the bookmark * @param array $options Options for the Notice::saveNew() * * @return Notice saved notice */ static function addNew(Profile $actor, $title, $url, array $rawtags, $description, array $options = array()) { $act = new Activity(); $act->verb = ActivityVerb::POST; $act->time = time(); $act->actor = $actor->asActivityObject(); $actobj = new ActivityObject(); $actobj->type = ActivityObject::BOOKMARK; $actobj->title = $title; $actobj->summary = $description; $actobj->extra[] = array('link', array('rel' => 'related', 'href' => $url), null); $act->objects[] = $actobj; $act->enclosures[] = $url; $tags = array(); $replies = array(); // filter "for:nickname" tags foreach ($rawtags as $tag) { if (strtolower(mb_substr($tag, 0, 4)) == 'for:') { // skip if done by caller if (!array_key_exists('replies', $options)) { $nickname = mb_substr($tag, 4); $other = common_relative_profile($actor, $nickname); if (!empty($other)) { $replies[] = $other->getUri(); } } } else { $tags[] = common_canonical_tag($tag); } } $hashtags = array(); $taglinks = array(); foreach ($tags as $tag) { $hashtags[] = '#' . $tag; $attrs = array('href' => Notice_tag::url($tag), 'rel' => $tag, 'class' => 'tag'); $taglinks[] = XMLStringer::estring('a', $attrs, $tag); } // Use user's preferences for short URLs, if possible // FIXME: Should be possible to with the Profile object... try { $user = $actor->getUser(); $shortUrl = File_redirection::makeShort($url, empty($user) ? null : $user); } catch (Exception $e) { // Don't let this stop us. $shortUrl = $url; } // TRANS: Rendered bookmark content. // TRANS: %1$s is a URL, %2$s the bookmark title, %3$s is the bookmark description, // TRANS: %4$s is space separated list of hash tags. $actobj->content = sprintf(_m('<span class="xfolkentry">' . '<a class="taggedlink" href="%1$s">%2$s</a> ' . '<span class="description">%3$s</span> ' . '<span class="meta">%4$s</span>' . '</span>'), htmlspecialchars($url), htmlspecialchars($title), htmlspecialchars($description), implode(' ', $taglinks)); foreach ($tags as $term) { $catEl = new AtomCategory(); $catEl->term = $term; $activity->categories[] = $catEl; } $options = array_merge(array('urls' => array($url), 'rendered' => $rendered, 'tags' => $tags, 'replies' => $replies, 'object_type' => ActivityObject::BOOKMARK), $options); return Notice::saveActivity($act, $actor, $options); }
function saveReplies() { // Alternative reply format $tname = false; if (preg_match('/^T ([A-Z0-9]{1,64}) /', $this->content, $match)) { $tname = $match[1]; } // extract all @messages $cnt = preg_match_all('/(?:^|\\s)@([a-z0-9]{1,64})/', $this->content, $match); $names = array(); if ($cnt || $tname) { // XXX: is there another way to make an array copy? $names = $tname ? array_unique(array_merge(array(strtolower($tname)), $match[1])) : array_unique($match[1]); } $sender = Profile::staticGet($this->profile_id); $replied = array(); // store replied only for first @ (what user/notice what the reply directed, // we assume first @ is it) for ($i = 0; $i < count($names); $i++) { $nickname = $names[$i]; $recipient = common_relative_profile($sender, $nickname, $this->created); if (!$recipient) { continue; } if ($i == 0 && $recipient->id != $sender->id && !$this->reply_to) { // Don't save reply to self $reply_for = $recipient; $recipient_notice = $reply_for->getCurrentNotice(); if ($recipient_notice) { $orig = clone $this; $this->reply_to = $recipient_notice->id; $this->update($orig); } } // Don't save replies from blocked profile to local user $recipient_user = User::staticGet('id', $recipient->id); if ($recipient_user && $recipient_user->hasBlocked($sender)) { continue; } $reply = new Reply(); $reply->notice_id = $this->id; $reply->profile_id = $recipient->id; $id = $reply->insert(); if (!$id) { $last_error =& PEAR::getStaticProperty('DB_DataObject', 'lastError'); common_log(LOG_ERR, 'DB error inserting reply: ' . $last_error->message); common_server_error(sprintf(_('DB error inserting reply: %s'), $last_error->message)); return; } else { $replied[$recipient->id] = 1; } } // Hash format replies, too $cnt = preg_match_all('/(?:^|\\s)@#([a-z0-9]{1,64})/', $this->content, $match); if ($cnt) { foreach ($match[1] as $tag) { $tagged = Profile_tag::getTagged($sender->id, $tag); foreach ($tagged as $t) { if (!$replied[$t->id]) { // Don't save replies from blocked profile to local user $t_user = User::staticGet('id', $t->id); if ($t_user && $t_user->hasBlocked($sender)) { continue; } $reply = new Reply(); $reply->notice_id = $this->id; $reply->profile_id = $t->id; $id = $reply->insert(); if (!$id) { common_log_db_error($reply, 'INSERT', __FILE__); return; } else { $replied[$recipient->id] = 1; } } } } } foreach (array_keys($replied) as $recipient) { $user = User::staticGet('id', $recipient); if ($user) { mail_notify_attn($user, $this); } } }