From 9ea57e5cb2622a8fc86c0cdd2cb6e73c0219fa51 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Mon, 28 Oct 2013 18:01:39 +0100 Subject: [PATCH] getAcctUri function added with related exception Used in ActivityObject for Atom Title generation. New events: * StartGetProfileAcctUri * EndGetProfileAcctUri --- EVENTS.txt | 8 +++++ classes/Profile.php | 20 +++++++++++ lib/activityobject.php | 8 +++-- lib/profilenoaccturiexception.php | 58 +++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 lib/profilenoaccturiexception.php diff --git a/EVENTS.txt b/EVENTS.txt index 7e08430218..82085ec9de 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -793,6 +793,14 @@ EndGetProfileUri: After determining the canonical URI for a given profile - $profile: the current profile - &$uri: the URI +StartGetProfileAcctUri: Get the acct: URI for a Profile (or throw ProfileNoAcctUriException) +- $profile: Profile of user we want to get acct: URI for +- &$acct: string with the resulting acct: uri + +EndGetProfileAcctUri: Last attempts to get the acct: URI for a Profile (or throw ProfileNoAcctUriException) +- $profile: Profile of user we want to get acct: URI for +- &$acct: string with the resulting acct: uri + StartFavorNotice: Saving a notice as a favorite - $profile: profile of the person faving (can be remote!) - $notice: notice being faved diff --git a/classes/Profile.php b/classes/Profile.php index 0175831a11..d697536b43 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -1349,6 +1349,26 @@ class Profile extends Managed_DataObject return $uri; } + /** + * Returns an assumed acct: URI for a profile. Plugins are required. + * + * @return string $uri + */ + public function getAcctUri() + { + $acct = null; + + if (Event::handle('StartGetProfileAcctUri', array($this, &$acct))) { + Event::handle('EndGetProfileAcctUri', array($this, &$acct)); + } + + if ($acct === null) { + throw new ProfileNoAcctUriException($this); + } + + return $acct; + } + function hasBlocked($other) { $block = Profile_block::exists($this, $other); diff --git a/lib/activityobject.php b/lib/activityobject.php index c09a5ed8dd..5a20ab2c18 100644 --- a/lib/activityobject.php +++ b/lib/activityobject.php @@ -438,8 +438,12 @@ class ActivityObject $object->type = (empty($notice->object_type)) ? ActivityObject::NOTE : $notice->object_type; $object->id = $notice->uri; - $object->title = 'New ' . ActivityObject::canonicalType($notice->object_type) - . ' by ' . $notice->getProfile()->nickname; + $object->title = 'New ' . ActivityObject::canonicalType($object->type) . ' by '; + try { + $object->title .= $notice->getProfile()->getAcctUri(); + } catch (ProfileNoAcctUriException $e) { + $object->title .= $e->profile->nickname; + } $object->content = $notice->rendered; $object->link = $notice->bestUrl(); diff --git a/lib/profilenoaccturiexception.php b/lib/profilenoaccturiexception.php new file mode 100644 index 0000000000..01d56f3aa3 --- /dev/null +++ b/lib/profilenoaccturiexception.php @@ -0,0 +1,58 @@ +. + * + * @category Exception + * @package StatusNet + * @author Mikael Nordfeldth + * @copyright 2013 Free Software Foundation, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://www.gnu.org/software/social/ + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +/** + * Parent class for an exception when a profile is missing + * + * @category Exception + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +class ProfileNoAcctUriException extends ServerException +{ + public $profile = null; + + public function __construct(Profile $profile, $msg=null) + { + $this->profile = $profile; + + if ($msg === null) { + // TRANS: Exception text shown when no profile can be found for a user. + // TRANS: %1$s is a user nickname, $2$d is a user ID (number). + $msg = sprintf(_('Could not get an acct: URI for profile with id==%u'), $this->profile->id); + } + + parent::__construct($msg); + } +}