/** * broadcast a notice to all subscribers with SMS notification on * * This function sends SMS messages to all users who have sms addresses; * have sms notification on; and have sms enabled for this particular * subscription. * * @param Notice $notice The notice to broadcast * * @return success flag */ function mail_broadcast_notice_sms($notice) { // Now, get users subscribed to this profile $user = new User(); $UT = common_config('db', 'type') == 'pgsql' ? '"user"' : 'user'; $replies = $notice->getReplies(); $user->query('SELECT nickname, smsemail, incomingemail ' . "FROM {$UT} LEFT OUTER JOIN subscription " . "ON {$UT}.id = subscription.subscriber " . 'AND subscription.subscribed = ' . $notice->profile_id . ' ' . 'AND subscription.subscribed != subscription.subscriber ' . "WHERE {$UT}.id != " . $notice->profile_id . ' ' . "AND {$UT}.smsemail IS NOT null " . "AND {$UT}.smsnotify = 1 " . 'AND (subscription.sms = 1 ' . ($replies ? sprintf("OR {$UT}.id in (%s)", implode(',', $replies)) : '') . ')'); while ($user->fetch()) { common_log(LOG_INFO, 'Sending notice ' . $notice->id . ' to ' . $user->smsemail, __FILE__); $success = mail_send_sms_notice_address($notice, $user->smsemail, $user->incomingemail, $user->nickname); if (!$success) { // XXX: Not sure, but I think that's the right thing to do common_log(LOG_WARNING, 'Sending notice ' . $notice->id . ' to ' . $user->smsemail . ' FAILED, cancelling.', __FILE__); return false; } } $user->free(); unset($user); return true; }
/** * 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; }
function canRead(Notice $notice) { if ($notice->scope & Notice::SITE_SCOPE) { $user = $this->getUser(); if (empty($user)) { return false; } } if ($notice->scope & Notice::ADDRESSEE_SCOPE) { $replies = $notice->getReplies(); if (!in_array($this->id, $replies)) { $groups = $notice->getGroups(); $foundOne = false; foreach ($groups as $group) { if ($this->isMember($group)) { $foundOne = true; break; } } if (!$foundOne) { return false; } } } if ($notice->scope & Notice::FOLLOWER_SCOPE) { $author = $notice->getProfile(); if (!Subscription::exists($this, $author)) { return false; } } return true; }