X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FOStatus%2Fclasses%2FOstatus_profile.php;h=ca1708282e9c392cff1a5b452033ffb4ff348de7;hb=d6b28c64830f632bb2f4b6f3c9369b9e56ad217a;hp=fa6170cfdf1bccd468282e8ae4e5c738e0698208;hpb=0d39337683c8f3fd3a996cf3e80e127ab29dd0fd;p=quix0rs-gnu-social.git diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index fa6170cfdf..ca1708282e 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -371,9 +371,10 @@ class Ostatus_profile extends Managed_DataObject * send immediately but won't get the return value. * * @param mixed $entry XML string, Notice, or Activity + * @param Profile $actor Acting profile * @return boolean success */ - public function notifyDeferred($entry, $actor) + public function notifyDeferred($entry, Profile $actor) { if ($this->salmonuri) { $data = array('salmonuri' => $this->salmonuri, @@ -444,10 +445,7 @@ class Ostatus_profile extends Managed_DataObject return; } - for ($i = 0; $i < $entries->length; $i++) { - $entry = $entries->item($i); - $this->processEntry($entry, $feed, $source); - } + $this->processEntries($entries, $feed, $source); } public function processRssFeed(DOMElement $rss, $source) @@ -465,9 +463,18 @@ class Ostatus_profile extends Managed_DataObject $items = $channel->getElementsByTagName('item'); - for ($i = 0; $i < $items->length; $i++) { - $item = $items->item($i); - $this->processEntry($item, $channel, $source); + $this->processEntries($items, $channel, $source); + } + + public function processEntries(DOMNodeList $entries, DOMElement $feed, $source) + { + for ($i = 0; $i < $entries->length; $i++) { + $entry = $entries->item($i); + try { + $this->processEntry($entry, $feed, $source); + } catch (AlreadyFulfilledException $e) { + common_debug('We already had this entry: '.$e->getMessage()); + } } } @@ -480,14 +487,14 @@ class Ostatus_profile extends Managed_DataObject * * @return Notice Notice representing the new (or existing) activity */ - public function processEntry($entry, $feed, $source) + public function processEntry(DOMElement $entry, DOMElement $feed, $source) { $activity = new Activity($entry, $feed); return $this->processActivity($activity, $source); } // TODO: Make this throw an exception - public function processActivity($activity, $source) + public function processActivity(Activity $activity, $source) { $notice = null; @@ -511,7 +518,7 @@ class Ostatus_profile extends Managed_DataObject * @param string $method 'push' or 'salmon' * @return mixed saved Notice or false */ - public function processPost($activity, $method) + public function processPost(Activity $activity, $method) { $actor = ActivityUtils::checkAuthorship($activity, $this->localProfile()); @@ -535,7 +542,7 @@ class Ostatus_profile extends Managed_DataObject */ static public function filterAttention(Profile $sender, array $attention) { - common_log(LOG_DEBUG, "Original reply recipients: " . implode(', ', array_keys($attention))); + common_debug("Original reply recipients: " . implode(', ', array_keys($attention))); $groups = array(); $replies = array(); foreach ($attention as $recipient=>$type) { @@ -557,11 +564,11 @@ class Ostatus_profile extends Managed_DataObject if ($sender->isMember($group)) { $groups[] = $group->id; } else { - common_log(LOG_DEBUG, sprintf('Skipping reply to local group %s as sender %d is not a member', $group->getNickname(), $sender->id)); + common_debug(sprintf('Skipping reply to local group %s as sender %d is not a member', $group->getNickname(), $sender->id)); } continue; } else { - common_log(LOG_DEBUG, "Skipping reply to bogus group $recipient"); + common_debug("Skipping reply to bogus group $recipient"); } } @@ -579,12 +586,12 @@ class Ostatus_profile extends Managed_DataObject continue; } catch (Exception $e) { // Neither a recognizable local nor remote user! - common_log(LOG_DEBUG, "Skipping reply to unrecognized profile $recipient: " . $e->getMessage()); + common_debug("Skipping reply to unrecognized profile $recipient: " . $e->getMessage()); } } - common_log(LOG_DEBUG, "Local reply recipients: " . implode(', ', $replies)); - common_log(LOG_DEBUG, "Local group recipients: " . implode(', ', $groups)); + common_debug("Local reply recipients: " . implode(', ', $replies)); + common_debug("Local group recipients: " . implode(', ', $groups)); return array($groups, $replies); } @@ -875,7 +882,7 @@ class Ostatus_profile extends Managed_DataObject // @todo FIXME: This should be better encapsulated // ripped from oauthstore.php (for old OMB client) - $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar'); + $temp_filename = tempnam(common_get_temp_dir(), 'listener_avatar'); try { $imgData = HTTPClient::quickGet($url); // Make sure it's at least an image file. ImageFile can do the rest. @@ -1100,7 +1107,7 @@ class Ostatus_profile extends Managed_DataObject $discover = false; if (!$homeuri) { - common_log(LOG_DEBUG, __METHOD__ . " empty actor profile URI: " . var_export($activity, true)); + common_debug(__METHOD__ . " empty actor profile URI: " . var_export($activity, true)); // TRANS: Exception. throw new Exception(_m('No profile URI.')); } @@ -1342,7 +1349,7 @@ class Ostatus_profile extends Managed_DataObject // @todo tags from categories if ($profile->id) { - common_log(LOG_DEBUG, "Updating OStatus profile $profile->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true)); + common_debug("Updating OStatus profile $profile->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true)); $profile->update($orig); } } @@ -1366,12 +1373,12 @@ class Ostatus_profile extends Managed_DataObject $group->homepage = self::getActivityObjectHomepage($object, $hints); if ($group->id) { // If no id, we haven't called insert() yet, so don't run update() - common_log(LOG_DEBUG, "Updating OStatus group $group->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true)); + common_debug("Updating OStatus group $group->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true)); $group->update($orig); } } - protected static function updatePeopletag($tag, ActivityObject $object, array $hints=array()) { + protected static function updatePeopletag(Peopletag $tag, ActivityObject $object, array $hints=array()) { $orig = clone($tag); $tag->tag = $object->title; @@ -1387,7 +1394,7 @@ class Ostatus_profile extends Managed_DataObject $tag->tagger = $tagger->profile_id; if ($tag->id) { - common_log(LOG_DEBUG, "Updating OStatus peopletag $tag->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true)); + common_debug("Updating OStatus peopletag $tag->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true)); $tag->update($orig); } } @@ -1789,7 +1796,7 @@ class Ostatus_profile extends Managed_DataObject } else { $actor = $activity->actor; - if (empty($actor)) { + if (!$actor instanceof Profile) { // OK here! assume the default } else if ($actor->id == $this->getUri() || $actor->link == $this->getUri()) { $this->updateFromActivityObject($actor);