From 7bec455a2120607a0aacb8be03cd60372cc5d0c1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 16:15:22 -0400 Subject: Static method to get a profile based on an URI --- classes/Profile.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'classes') diff --git a/classes/Profile.php b/classes/Profile.php index d7617f0b7..87cfab0e0 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -960,4 +960,24 @@ class Profile extends Memcached_DataObject return $feed; } + + static function fromURI($uri) + { + $profile = null; + + if (Event::handle('StartGetProfileFromURI', array($uri, &$profile))) { + // Get a local user or remote (OMB 0.1) profile + $user = User::staticGet('uri', $uri); + if (!empty($user)) { + $profile = $user->getProfile(); + } else { + $remote_profile = Remote_profile::staticGet('uri', $uri); + if (!empty($remote_profile)) { + $profile = Profile::staticGet('id', $remote_profile->profile_id); + } + } + Event::handle('EndGetProfileFromURI', array($uri, $profile)); + } + + } } -- cgit v1.2.3-54-g00ecf From a2de30b767e23ae848d15a3ce1d3ed9d16fd1df9 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 16:15:51 -0400 Subject: Notice::saveReplies() uses Profile::fromURI() to handle remote profiles too --- classes/Notice.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 0eeebfadf..93456011a 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1014,25 +1014,31 @@ class Notice extends Memcached_DataObject if (empty($uris)) { return; } + $sender = Profile::staticGet($this->profile_id); foreach (array_unique($uris) as $uri) { - $user = User::staticGet('uri', $uri); + $profile = Profile::fromURI($uri); - if (!empty($user)) { - if ($user->hasBlocked($sender)) { - continue; - } + if (empty($profile)) { + common_log(LOG_WARNING, "Unable to determine profile for URI '$uri'"); + continue; + } - $reply = new Reply(); + if ($profile->hasBlocked($sender)) { + common_log(LOG_INFO, "Not saving reply to profile {$profile->id} ($uri) from sender {$sender->id} because of a block."); + continue; + } - $reply->notice_id = $this->id; - $reply->profile_id = $user->id; - common_log(LOG_INFO, __METHOD__ . ": saving reply: notice $this->id to profile $user->id"); + $reply = new Reply(); - $id = $reply->insert(); - } + $reply->notice_id = $this->id; + $reply->profile_id = $profile->id; + + common_log(LOG_INFO, __METHOD__ . ": saving reply: notice $this->id to profile $profile->id"); + + $id = $reply->insert(); } return; -- cgit v1.2.3-54-g00ecf From 974ac48771915406527b4f2e5670c7e7cb5aa314 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 16:55:16 -0400 Subject: bug in Profile::fromURI() wasn't returning profile --- classes/Profile.php | 1 + 1 file changed, 1 insertion(+) (limited to 'classes') diff --git a/classes/Profile.php b/classes/Profile.php index 87cfab0e0..8f8679550 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -979,5 +979,6 @@ class Profile extends Memcached_DataObject Event::handle('EndGetProfileFromURI', array($uri, $profile)); } + return $profile; } } -- cgit v1.2.3-54-g00ecf