Type testing instead of just empty() in OStatusPlugin
This commit is contained in:
parent
261778f6de
commit
0fa00d5106
@ -350,7 +350,7 @@ class OStatusPlugin extends Plugin
|
||||
$this->log(LOG_INFO, "Checking webfinger '$target'");
|
||||
try {
|
||||
$oprofile = Ostatus_profile::ensureWebfinger($target);
|
||||
if ($oprofile && !$oprofile->isGroup()) {
|
||||
if ($oprofile instanceof Ostatus_profile && !$oprofile->isGroup()) {
|
||||
$profile = $oprofile->localProfile();
|
||||
$matches[$pos] = array('mentioned' => array($profile),
|
||||
'type' => 'mention',
|
||||
@ -377,7 +377,7 @@ class OStatusPlugin extends Plugin
|
||||
$this->log(LOG_INFO, "Checking profile address '$url'");
|
||||
try {
|
||||
$oprofile = Ostatus_profile::ensureProfileURL($url);
|
||||
if ($oprofile && !$oprofile->isGroup()) {
|
||||
if ($oprofile instanceof Ostatus_profile && !$oprofile->isGroup()) {
|
||||
$profile = $oprofile->localProfile();
|
||||
$matches[$pos] = array('mentioned' => array($profile),
|
||||
'type' => 'mention',
|
||||
@ -422,7 +422,7 @@ class OStatusPlugin extends Plugin
|
||||
function onStartCommandGetProfile($command, $arg, &$profile)
|
||||
{
|
||||
$oprofile = $this->pullRemoteProfile($arg);
|
||||
if ($oprofile && !$oprofile->isGroup()) {
|
||||
if ($oprofile instanceof Ostatus_profile && !$oprofile->isGroup()) {
|
||||
$profile = $oprofile->localProfile();
|
||||
return false;
|
||||
} else {
|
||||
@ -444,7 +444,7 @@ class OStatusPlugin extends Plugin
|
||||
function onStartCommandGetGroup($command, $arg, &$group)
|
||||
{
|
||||
$oprofile = $this->pullRemoteProfile($arg);
|
||||
if ($oprofile && $oprofile->isGroup()) {
|
||||
if ($oprofile instanceof Ostatus_profile && $oprofile->isGroup()) {
|
||||
$group = $oprofile->localGroup();
|
||||
return false;
|
||||
} else {
|
||||
@ -580,7 +580,7 @@ class OStatusPlugin extends Plugin
|
||||
function onFeedSubSubscriberCount($feedsub, &$count)
|
||||
{
|
||||
$oprofile = Ostatus_profile::getKV('feeduri', $feedsub->uri);
|
||||
if ($oprofile) {
|
||||
if ($oprofile instanceof Ostatus_profile) {
|
||||
$count += $oprofile->subscriberCount();
|
||||
}
|
||||
return true;
|
||||
@ -607,8 +607,7 @@ class OStatusPlugin extends Plugin
|
||||
}
|
||||
|
||||
$oprofile = Ostatus_profile::getKV('profile_id', $other->id);
|
||||
|
||||
if (empty($oprofile)) {
|
||||
if (!$oprofile instanceof Ostatus_profile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -636,8 +635,7 @@ class OStatusPlugin extends Plugin
|
||||
}
|
||||
|
||||
$oprofile = Ostatus_profile::getKV('profile_id', $other->id);
|
||||
|
||||
if (empty($oprofile)) {
|
||||
if (!$oprofile instanceof Ostatus_profile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -666,8 +664,7 @@ class OStatusPlugin extends Plugin
|
||||
}
|
||||
|
||||
$oprofile = Ostatus_profile::getKV('profile_id', $other->id);
|
||||
|
||||
if (empty($oprofile)) {
|
||||
if (!$oprofile instanceof Ostatus_profile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -713,7 +710,10 @@ class OStatusPlugin extends Plugin
|
||||
function onStartJoinGroup($group, $profile)
|
||||
{
|
||||
$oprofile = Ostatus_profile::getKV('group_id', $group->id);
|
||||
if ($oprofile) {
|
||||
if (!$oprofile instanceof Ostatus_profile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$oprofile->subscribe()) {
|
||||
// TRANS: Exception thrown when setup of remote group membership fails.
|
||||
throw new Exception(_m('Could not set up remote group membership.'));
|
||||
@ -749,7 +749,6 @@ class OStatusPlugin extends Plugin
|
||||
throw new Exception(_m('Failed joining remote group.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When one of our local users leaves a remote group, notify the remote
|
||||
@ -768,7 +767,10 @@ class OStatusPlugin extends Plugin
|
||||
function onEndLeaveGroup($group, $profile)
|
||||
{
|
||||
$oprofile = Ostatus_profile::getKV('group_id', $group->id);
|
||||
if ($oprofile) {
|
||||
if (!$oprofile instanceof Ostatus_profile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Drop the PuSH subscription if there are no other subscribers.
|
||||
$oprofile->garbageCollect();
|
||||
|
||||
@ -795,7 +797,6 @@ class OStatusPlugin extends Plugin
|
||||
|
||||
$oprofile->notifyActivity($act, $member);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When one of our local users tries to subscribe to a remote peopletag,
|
||||
@ -811,7 +812,10 @@ class OStatusPlugin extends Plugin
|
||||
function onStartSubscribePeopletag($peopletag, $user)
|
||||
{
|
||||
$oprofile = Ostatus_profile::getKV('peopletag_id', $peopletag->id);
|
||||
if ($oprofile) {
|
||||
if (!$oprofile instanceof Ostatus_profile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$oprofile->subscribe()) {
|
||||
// TRANS: Exception thrown when setup of remote list subscription fails.
|
||||
throw new Exception(_m('Could not set up remote list subscription.'));
|
||||
@ -848,7 +852,6 @@ class OStatusPlugin extends Plugin
|
||||
throw new Exception(_m('Failed subscribing to remote list.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When one of our local users unsubscribes to a remote peopletag, notify the remote
|
||||
@ -863,7 +866,10 @@ class OStatusPlugin extends Plugin
|
||||
function onEndUnsubscribePeopletag($peopletag, $user)
|
||||
{
|
||||
$oprofile = Ostatus_profile::getKV('peopletag_id', $peopletag->id);
|
||||
if ($oprofile) {
|
||||
if (!$oprofile instanceof Ostatus_profile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Drop the PuSH subscription if there are no other subscribers.
|
||||
$oprofile->garbageCollect();
|
||||
|
||||
@ -892,7 +898,6 @@ class OStatusPlugin extends Plugin
|
||||
|
||||
$oprofile->notifyActivity($act, $user);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify remote users when their notices get favorited.
|
||||
@ -903,23 +908,23 @@ class OStatusPlugin extends Plugin
|
||||
*/
|
||||
function onEndFavorNotice(Profile $profile, Notice $notice)
|
||||
{
|
||||
$user = User::getKV('id', $profile->id);
|
||||
|
||||
if (empty($user)) {
|
||||
// Only distribute local users' favor actions, remote users
|
||||
// will have already distributed theirs.
|
||||
if (!$profile->isLocal()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$oprofile = Ostatus_profile::getKV('profile_id', $notice->profile_id);
|
||||
|
||||
if (empty($oprofile)) {
|
||||
if (!$oprofile instanceof Ostatus_profile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$fav = Fave::pkeyGet(array('user_id' => $user->id,
|
||||
'notice_id' => $notice->id));
|
||||
|
||||
if (empty($fav)) {
|
||||
if (!$fav instanceof Fave) {
|
||||
// That's weird.
|
||||
// TODO: Make pkeyGet throw exception, since this is a critical failure.
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -941,8 +946,7 @@ class OStatusPlugin extends Plugin
|
||||
function onEndTagProfile($ptag)
|
||||
{
|
||||
$oprofile = Ostatus_profile::getKV('profile_id', $ptag->tagged);
|
||||
|
||||
if (empty($oprofile)) {
|
||||
if (!$oprofile instanceof Ostatus_profile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -998,8 +1002,7 @@ class OStatusPlugin extends Plugin
|
||||
function onEndUntagProfile($ptag)
|
||||
{
|
||||
$oprofile = Ostatus_profile::getKV('profile_id', $ptag->tagged);
|
||||
|
||||
if (empty($oprofile)) {
|
||||
if (!$oprofile instanceof Ostatus_profile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1049,15 +1052,14 @@ class OStatusPlugin extends Plugin
|
||||
*/
|
||||
function onEndDisfavorNotice(Profile $profile, Notice $notice)
|
||||
{
|
||||
$user = User::getKV('id', $profile->id);
|
||||
|
||||
if (empty($user)) {
|
||||
// Only distribute local users' disfavor actions, remote users
|
||||
// will have already distributed theirs.
|
||||
if (!$profile->isLocal()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$oprofile = Ostatus_profile::getKV('profile_id', $notice->profile_id);
|
||||
|
||||
if (empty($oprofile)) {
|
||||
if (!$oprofile instanceof Ostatus_profile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1103,7 +1105,7 @@ class OStatusPlugin extends Plugin
|
||||
function onStartUserGroupPermalink($group, &$url)
|
||||
{
|
||||
$oprofile = Ostatus_profile::getKV('group_id', $group->id);
|
||||
if ($oprofile) {
|
||||
if ($oprofile instanceof Ostatus_profile) {
|
||||
// @fixme this should probably be in the user_group table
|
||||
// @fixme this uri not guaranteed to be a profile page
|
||||
$url = $oprofile->uri;
|
||||
@ -1290,7 +1292,7 @@ class OStatusPlugin extends Plugin
|
||||
{
|
||||
$oprofile = Ostatus_profile::getKV('profile_id', $profile->id);
|
||||
|
||||
if (empty($oprofile)) {
|
||||
if (!$oprofile instanceof Ostatus_profile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user