getAcctUri function added with related exception

Used in ActivityObject for Atom Title generation.

New events:
    * StartGetProfileAcctUri
    * EndGetProfileAcctUri
This commit is contained in:
Mikael Nordfeldth 2013-10-28 18:01:39 +01:00
parent addd84aa22
commit 9ea57e5cb2
4 changed files with 92 additions and 2 deletions

View File

@ -793,6 +793,14 @@ EndGetProfileUri: After determining the canonical URI for a given profile
- $profile: the current profile - $profile: the current profile
- &$uri: the URI - &$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 StartFavorNotice: Saving a notice as a favorite
- $profile: profile of the person faving (can be remote!) - $profile: profile of the person faving (can be remote!)
- $notice: notice being faved - $notice: notice being faved

View File

@ -1349,6 +1349,26 @@ class Profile extends Managed_DataObject
return $uri; 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) function hasBlocked($other)
{ {
$block = Profile_block::exists($this, $other); $block = Profile_block::exists($this, $other);

View File

@ -438,8 +438,12 @@ class ActivityObject
$object->type = (empty($notice->object_type)) ? ActivityObject::NOTE : $notice->object_type; $object->type = (empty($notice->object_type)) ? ActivityObject::NOTE : $notice->object_type;
$object->id = $notice->uri; $object->id = $notice->uri;
$object->title = 'New ' . ActivityObject::canonicalType($notice->object_type) $object->title = 'New ' . ActivityObject::canonicalType($object->type) . ' by ';
. ' by ' . $notice->getProfile()->nickname; try {
$object->title .= $notice->getProfile()->getAcctUri();
} catch (ProfileNoAcctUriException $e) {
$object->title .= $e->profile->nickname;
}
$object->content = $notice->rendered; $object->content = $notice->rendered;
$object->link = $notice->bestUrl(); $object->link = $notice->bestUrl();

View File

@ -0,0 +1,58 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Class for an exception when a Profile has no discernable acct: URI
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Exception
* @package StatusNet
* @author Mikael Nordfeldth <mmn@hethane.se>
* @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 <evan@status.net>
* @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);
}
}