X-Git-Url: https://git.mxchange.org/?p=quix0rs-gnu-social.git;a=blobdiff_plain;f=plugins%2FOStatus%2Fclasses%2FOstatus_profile.php;h=b4df92e2daeb8b092dd5bdf4c71cdd869d7e4b40;hp=fa6170cfdf1bccd468282e8ae4e5c738e0698208;hb=dd93420b08910a8bf9967dad7906351695d1ac55;hpb=0d39337683c8f3fd3a996cf3e80e127ab29dd0fd diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index fa6170cfdf..b4df92e2da 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -371,18 +371,25 @@ 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, - 'entry' => $this->notifyPrepXml($entry), - 'actor' => $actor->getID(), - 'target' => $this->localProfile()->getID()); - - $qm = QueueManager::get(); - return $qm->enqueue($data, 'salmon'); + try { + common_debug("OSTATUS: user {$actor->getNickname()} ({$actor->getID()}) wants to ping {$this->localProfile()->getNickname()} on {$this->salmonuri}"); + $data = array('salmonuri' => $this->salmonuri, + 'entry' => $this->notifyPrepXml($entry), + 'actor' => $actor->getID(), + 'target' => $this->localProfile()->getID()); + + $qm = QueueManager::get(); + return $qm->enqueue($data, 'salmon'); + } catch (Exception $e) { + common_log(LOG_ERR, 'OSTATUS: Something went wrong when creating a Salmon slap: '._ve($e->getMessage())); + return false; + } } return false; @@ -444,10 +451,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 +469,21 @@ 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()); + } catch (ServerException $e) { + // FIXME: This should be UnknownUriException and the ActivityUtils:: findLocalObject should only test one URI + common_log(LOG_ERR, 'Entry threw exception while processing a feed from '.$source.': '.$e->getMessage()); + } } } @@ -480,14 +496,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 +527,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 +551,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 +573,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 +595,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,13 +891,15 @@ 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. if (false === getimagesizefromstring($imgData)) { throw new UnsupportedMediaException(_('Downloaded group avatar was not an image.')); } + file_put_contents($temp_filename, $imgData); unset($imgData); // No need to carry this in memory. @@ -1100,7 +1118,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 +1360,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 +1384,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 +1405,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 +1807,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);