common_log(LOG_INFO, "BookmarkPlugin called for new feed entry.");
- if ($activity->verb == ActivityVerb::POST &&
- $activity->objects[0]->type == ActivityObject::BOOKMARK) {
+ if (self::_isPostBookmark($activity)) {
common_log(LOG_INFO, "Importing activity {$activity->id} as a bookmark.");
function onStartHandleSalmonTarget($activity, $target) {
- if ($activity->verb == ActivityVerb::POST &&
- $activity->objects[0]->type == ActivityObject::BOOKMARK) {
+ if (self::_isPostBookmark($activity)) {
$this->log(LOG_INFO, "Checking {$activity->id} as a valid Salmon slap.");
return true;
}
+ function onStartAtomPubNewActivity(&$activity, $user)
+ {
+ if (self::_isPostBookmark($activity)) {
+ $options = array('source' => 'atompub');
+ self::_postBookmark($user->getProfile(), $activity, $options);
+ return false;
+ }
+
+ return true;
+ }
+
static private function _postRemoteBookmark(Ostatus_profile $author, Activity $activity)
{
$bookmark = $activity->objects[0];
+ $options = array('uri' => $bookmark->id,
+ 'url' => $bookmark->link,
+ 'is_local' => Notice::REMOTE_OMB,
+ 'source' => 'ostatus');
+
+ return self::_postBookmark($author->localProfile(), $activity, $options);
+ }
+
+ static private function _postBookmark(Profile $profile, Activity $activity, $options=array())
+ {
+ $bookmark = $activity->objects[0];
+
$relLinkEls = ActivityUtils::getLinks($bookmark->element, 'related');
if (count($relLinkEls) < 1) {
$tags[] = common_canonical_tag($category->term);
}
- $options = array('uri' => $bookmark->id,
- 'url' => $bookmark->link,
- 'created' => common_sql_date($activity->time),
- 'is_local' => Notice::REMOTE_OMB,
- 'source' => 'ostatus');
+ if (!empty($activity->time)) {
+ $options['created'] = common_sql_date($activity->time);
+ }
// Fill in location if available
$options['replies'] = array();
foreach ($replies as $replyURI) {
- $profile = Profile::fromURI($replyURI);
- if (!empty($profile)) {
+ $other = Profile::fromURI($replyURI);
+ if (!empty($other)) {
$options['replies'][] = $replyURI;
} else {
$group = User_group::staticGet('uri', $replyURI);
}
}
- Bookmark::saveNew($author->localProfile(),
+ return Bookmark::saveNew($profile,
$bookmark->title,
$url,
$tags,
$bookmark->summary,
$options);
}
+
+ static private function _isPostBookmark($activity)
+ {
+ return ($activity->verb == ActivityVerb::POST &&
+ $activity->objects[0]->type == ActivityObject::BOOKMARK);
+ }
}