* @link http://status.net/
*/
-if (!defined('STATUSNET')) {
- // This check helps protect against security problems;
- // your code file can't be executed directly from the web.
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Class comment
$other = $activity->actor;
$otherUser = User::getKV('uri', $other->id);
- if (!empty($otherUser)) {
- $otherProfile = $otherUser->getProfile();
- } else {
+ if (!$otherUser instanceof User) {
// TRANS: Client exception thrown when trying to force a remote user to subscribe.
throw new Exception(_('Cannot force remote user to subscribe.'));
}
+ $otherProfile = $otherUser->getProfile();
+
// XXX: don't do this for untrusted input!
- Subscription::start($otherProfile, $profile);
+ Subscription::ensureStart($otherProfile, $profile);
} else if (empty($activity->actor)
|| $activity->actor->id == $author->id) {
$other = $activity->objects[0];
- $otherProfile = Profile::fromUri($other->id);
-
- if (empty($otherProfile)) {
+ try {
+ $otherProfile = Profile::fromUri($other->id);
// TRANS: Client exception thrown when trying to subscribe to an unknown profile.
+ } catch (UnknownUriException $e) {
+ // Let's convert it to a client exception instead of server.
throw new ClientException(_('Unknown profile.'));
}
- Subscription::start($profile, $otherProfile);
+ Subscription::ensureStart($profile, $otherProfile);
} else {
// TRANS: Client exception thrown when trying to import an event not related to the importing user.
throw new Exception(_('This activity seems unrelated to our user.'));
$group = User_group::getKV('uri', $uri);
- if (empty($group)) {
+ if (!$group instanceof User_group) {
$oprofile = Ostatus_profile::ensureActivityObjectProfile($activity->objects[0]);
if (!$oprofile->isGroup()) {
// TRANS: Client exception thrown when trying to join a remote group that is not a group.
$notice = Notice::getKV('uri', $sourceUri);
- if (!empty($notice)) {
+ if ($notice instanceof Notice) {
common_log(LOG_INFO, "Notice {$sourceUri} already exists.");
$uri = $profile->getUri();
- if ($uri == $author->id) {
- common_log(LOG_INFO, "Updating notice author from $author->id to $user->uri");
+ if ($uri === $author->id) {
+ common_log(LOG_INFO, sprintf('Updating notice author from %s to %s', $author->id, $user->getUri()));
$orig = clone($notice);
$notice->profile_id = $user->id;
$notice->update($orig);
// Get (safe!) HTML and text versions of the content
- $rendered = $this->purify($sourceContent);
- $content = html_entity_decode(strip_tags($rendered), ENT_QUOTES, 'UTF-8');
+ $rendered = common_purify($sourceContent);
+ $content = common_strip_html($rendered);
$shortened = $user->shortenLinks($content);
// Maintain direct reply associations
// @fixme what about conversation ID?
if (!empty($activity->context->replyToID)) {
- $orig = Notice::getKV('uri',
- $activity->context->replyToID);
- if (!empty($orig)) {
+ $orig = Notice::getKV('uri', $activity->context->replyToID);
+ if ($orig instanceof Notice) {
$options['reply_to'] = $orig->id;
}
}
return $saved;
}
- function filterAttention($attn)
+ protected function filterAttention(array $attn)
{
- $groups = array();
- $replies = array();
+ $groups = array(); // TODO: context->attention
+ $replies = array(); // TODO: context->attention
- foreach (array_unique($attn) as $recipient) {
+ foreach ($attn as $recipient=>$type) {
// Is the recipient a local user?
$user = User::getKV('uri', $recipient);
- if ($user) {
- // @fixme sender verification, spam etc?
+ if ($user instanceof User) {
+ // TODO: @fixme sender verification, spam etc?
$replies[] = $recipient;
continue;
}
}
// Is the recipient a local group?
- // @fixme uri on user_group isn't reliable yet
+ // TODO: @fixme uri on user_group isn't reliable yet
// $group = User_group::getKV('uri', $recipient);
$id = OStatusPlugin::localGroupFromUrl($recipient);
return array($groups, $replies);
}
-
-
- function purify($content)
- {
- require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
-
- $config = array('safe' => 1,
- 'deny_attribute' => 'id,style,on*');
-
- return htmLawed($content, $config);
- }
}