/**
* Put saved notices into the queue for pubsub distribution.
*/
- function onStartEnqueueNotice($notice, &$transports)
+ function onStartEnqueueNotice(Notice $notice, array &$transports)
{
if ($notice->inScope(null)) {
// put our transport first, in case there's any conflict (like OMB)
/*
* If the field being looked for is URI look for the profile
*/
- function onStartProfileCompletionSearch($action, $profile, $search_engine) {
+ public function onStartProfileCompletionSearch(Action $action, Profile $profile, $search_engine) {
if ($action->field == 'uri') {
$profile->joinAdd(array('id', 'user:id'));
$profile->whereAdd('uri LIKE "%' . $profile->escape($q) . '%"');
* @param array &$mention in/out param: set of found mentions
* @return boolean hook return value
*/
- function onEndFindMentions(Profile $sender, $text, &$mentions)
+ function onEndFindMentions(Profile $sender, $text, array &$mentions)
{
$matches = array();
- // Webfinger matches: @user@example.com
- if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\-?\w+\.)*\w+(?:\w+\-\w+)*\.\w+)!',
+ $wmatches = array();
+ // Webfinger matches: @user@example.com or even @user--one.george_orwell@1984.biz
+ if (preg_match_all('!(?:^|\s+)@((?:\w+[\w\-\_\.]?)*(?:[\w\-\_\.]*\w+)@(?:\w+\-?\w+\.)*\w+(?:\w+\-\w+)*\.\w+)!',
$text,
$wmatches,
PREG_OFFSET_CAPTURE)) {
foreach ($wmatches[1] as $wmatch) {
list($target, $pos) = $wmatch;
$this->log(LOG_INFO, "Checking webfinger '$target'");
+ $profile = null;
try {
$oprofile = Ostatus_profile::ensureWebfinger($target);
- if ($oprofile instanceof Ostatus_profile && !$oprofile->isGroup()) {
- $profile = $oprofile->localProfile();
- $text = !empty($profile->nickname) && mb_strlen($profile->nickname) < mb_strlen($target) ?
- $profile->nickname : $target;
- $matches[$pos] = array('mentioned' => array($profile),
- 'type' => 'mention',
- 'text' => $text,
- 'position' => $pos,
- 'length' => mb_strlen($target),
- 'url' => $profile->getUrl());
+ if (!$oprofile instanceof Ostatus_profile || !$oprofile->isPerson()) {
+ continue;
}
+ $profile = $oprofile->localProfile();
+ } catch (OStatusShadowException $e) {
+ // This means we got a local user in the webfinger lookup
+ $profile = $e->profile;
} catch (Exception $e) {
$this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage());
+ continue;
}
+
+ assert($profile instanceof Profile);
+
+ $text = !empty($profile->nickname) && mb_strlen($profile->nickname) < mb_strlen($target)
+ ? $profile->getNickname() // TODO: we could do getFancyName() or getFullname() here
+ : $target;
+ $url = $profile->getUri();
+ if (!common_valid_http_url($url)) {
+ $url = $profile->getUrl();
+ }
+ $matches[$pos] = array('mentioned' => array($profile),
+ 'type' => 'mention',
+ 'text' => $text,
+ 'position' => $pos,
+ 'length' => mb_strlen($target),
+ 'url' => $url);
}
}
* @param Profile &$profile
* @return hook return code
*/
- function onStartCommandGetProfile($command, $arg, &$profile)
+ public function onStartCommandGetProfile(Command $command, $arg, Profile &$profile = null)
{
$oprofile = $this->pullRemoteProfile($arg);
if ($oprofile instanceof Ostatus_profile && !$oprofile->isGroup()) {
* @param User_group &$group
* @return hook return code
*/
- function onStartCommandGetGroup($command, $arg, &$group)
+ function onStartCommandGetGroup(Command $command, $arg, User_group &$group = null)
{
$oprofile = $this->pullRemoteProfile($arg);
if ($oprofile instanceof Ostatus_profile && $oprofile->isGroup()) {
return true;
}
- function onEndShowStatusNetScripts($action) {
+ public function onEndShowStatusNetScripts(Action $action) {
$action->script($this->path('js/ostatus.js'));
return true;
}
* @param string out &$title
* @return mixed hook return code
*/
- function onStartNoticeSourceLink($notice, &$name, &$url, &$title)
+ function onStartNoticeSourceLink(Notice $notice, &$name, &$url, &$title)
{
// If we don't handle this, keep the event handler going
if (!in_array($notice->source, array('ostatus', 'share'))) {
if ($oprofile instanceof Ostatus_profile) {
$oprofile->processFeed($feed, 'push');
} else {
- common_log(LOG_DEBUG, "No ostatus profile for incoming feed $feedsub->uri");
+ common_debug("No ostatus profile for incoming feed $feedsub->uri");
}
}
$other->getBestName());
$act->actor = $profile->asActivityObject();
- $act->object = $other->asActivityObject();
+ $act->objects[] = $other->asActivityObject();
$oprofile->notifyActivity($act, $profile);
$act->actor = $profile->asActivityObject();
$act->verb = ActivityVerb::JOIN;
- $act->object = $oprofile->asActivityObject();
+ $act->objects[] = $oprofile->asActivityObject();
$act->time = time();
// TRANS: Title for joining a remote groep.
$act->actor = $member->asActivityObject();
$act->verb = ActivityVerb::LEAVE;
- $act->object = $oprofile->asActivityObject();
+ $act->objects[] = $oprofile->asActivityObject();
$act->time = time();
// TRANS: Title for leaving a remote group.
$act->actor = $sub->asActivityObject();
$act->verb = ActivityVerb::FOLLOW;
- $act->object = $oprofile->asActivityObject();
+ $act->objects[] = $oprofile->asActivityObject();
$act->time = time();
// TRANS: Title for following a remote list.
$act->actor = $member->asActivityObject();
$act->verb = ActivityVerb::UNFOLLOW;
- $act->object = $oprofile->asActivityObject();
+ $act->objects[] = $oprofile->asActivityObject();
$act->time = time();
// TRANS: Title for unfollowing a remote list.
$notice->getUrl());
$act->actor = $profile->asActivityObject();
- $act->object = $notice->asActivityObject();
+ $act->objects[] = $notice->asActivityObject();
$oprofile->notifyActivity($act, $profile);
$oprofile->query(sprintf($sql, $profile->id, $profile->id));
if ($oprofile->N == 0) {
- common_log(LOG_DEBUG, "No OStatus remote subscribees for $profile->nickname");
+ common_debug("No OStatus remote subscribees for $profile->nickname");
return true;
}
$profile->getBestName());
$act->actor = $profile->asActivityObject();
- $act->object = $act->actor;
+ $act->objects[] = $act->actor;
while ($oprofile->fetch()) {
$oprofile->notifyDeferred($act, $profile);
function onStartGetProfileFromURI($uri, &$profile)
{
// Don't want to do Web-based discovery on our own server,
- // so we check locally first.
+ // so we check locally first. This duplicates the functionality
+ // in the Profile class, since the plugin always runs before
+ // that local lookup, but since we return false it won't run double.
$user = User::getKV('uri', $uri);
-
- if (!empty($user)) {
+ if ($user instanceof User) {
$profile = $user->getProfile();
return false;
+ } else {
+ $group = User_group::getKV('uri', $uri);
+ if ($group instanceof User_group) {
+ $profile = $group->getProfile();
+ return false;
+ }
}
// Now, check remotely
-
try {
$oprofile = Ostatus_profile::ensureProfileURI($uri);
$profile = $oprofile->localProfile();
return true;
}
- public function onProfileDeleteRelated($profile, &$related)
+ public function onProfileDeleteRelated(Profile $profile, array &$related)
{
// Ostatus_profile has a 'profile_id' property, which will be used to find the object
$related[] = 'Ostatus_profile';
$client = new HTTPClient();
$client->setBody($envxml);
$response = $client->post($endpoint_uri, $headers);
- } catch (HTTP_Request2_Exception $e) {
+ } catch (Exception $e) {
common_log(LOG_ERR, "Salmon post to $endpoint_uri failed: " . $e->getMessage());
return false;
}