* 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;
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)
$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());
+ }
}
}
*
* @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;
* @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());
*/
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) {
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");
}
}
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);
}
}
}
- // Try to get some hCard data
+ if (in_array(
+ preg_replace('/\s*;.*$/', '', $response->getHeader('Content-Type')),
+ array('application/rss+xml', 'application/atom+xml', 'application/xml', 'text/xml'))
+ ) {
+ $hints['feedurl'] = $response->getUrl();
+ } else {
+ // Try to get some hCard data
- $body = $response->getBody();
+ $body = $response->getBody();
- $hcardHints = DiscoveryHints::hcardHints($body, $finalUrl);
+ $hcardHints = DiscoveryHints::hcardHints($body, $finalUrl);
- if (!empty($hcardHints)) {
- $hints = array_merge($hints, $hcardHints);
+ if (!empty($hcardHints)) {
+ $hints = array_merge($hints, $hcardHints);
+ }
}
// Check if they've got an LRDD header
// @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.
$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.'));
}
// @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);
}
}
$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;
$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);
}
}
} 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);