forked from GNUsocial/gnu-social
Make AtomPub work for bookmarks
This commit is contained in:
parent
6393326557
commit
7b9ea62259
@ -449,8 +449,7 @@ class BookmarkPlugin extends Plugin
|
|||||||
|
|
||||||
common_log(LOG_INFO, "BookmarkPlugin called for new feed entry.");
|
common_log(LOG_INFO, "BookmarkPlugin called for new feed entry.");
|
||||||
|
|
||||||
if ($activity->verb == ActivityVerb::POST &&
|
if (self::_isPostBookmark($activity)) {
|
||||||
$activity->objects[0]->type == ActivityObject::BOOKMARK) {
|
|
||||||
|
|
||||||
common_log(LOG_INFO, "Importing activity {$activity->id} as a bookmark.");
|
common_log(LOG_INFO, "Importing activity {$activity->id} as a bookmark.");
|
||||||
|
|
||||||
@ -480,8 +479,7 @@ class BookmarkPlugin extends Plugin
|
|||||||
|
|
||||||
function onStartHandleSalmonTarget($activity, $target) {
|
function onStartHandleSalmonTarget($activity, $target) {
|
||||||
|
|
||||||
if ($activity->verb == ActivityVerb::POST &&
|
if (self::_isPostBookmark($activity)) {
|
||||||
$activity->objects[0]->type == ActivityObject::BOOKMARK) {
|
|
||||||
|
|
||||||
$this->log(LOG_INFO, "Checking {$activity->id} as a valid Salmon slap.");
|
$this->log(LOG_INFO, "Checking {$activity->id} as a valid Salmon slap.");
|
||||||
|
|
||||||
@ -515,10 +513,33 @@ class BookmarkPlugin extends Plugin
|
|||||||
return true;
|
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)
|
static private function _postRemoteBookmark(Ostatus_profile $author, Activity $activity)
|
||||||
{
|
{
|
||||||
$bookmark = $activity->objects[0];
|
$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');
|
$relLinkEls = ActivityUtils::getLinks($bookmark->element, 'related');
|
||||||
|
|
||||||
if (count($relLinkEls) < 1) {
|
if (count($relLinkEls) < 1) {
|
||||||
@ -539,11 +560,9 @@ class BookmarkPlugin extends Plugin
|
|||||||
$tags[] = common_canonical_tag($category->term);
|
$tags[] = common_canonical_tag($category->term);
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = array('uri' => $bookmark->id,
|
if (!empty($activity->time)) {
|
||||||
'url' => $bookmark->link,
|
$options['created'] = common_sql_date($activity->time);
|
||||||
'created' => common_sql_date($activity->time),
|
}
|
||||||
'is_local' => Notice::REMOTE_OMB,
|
|
||||||
'source' => 'ostatus');
|
|
||||||
|
|
||||||
// Fill in location if available
|
// Fill in location if available
|
||||||
|
|
||||||
@ -564,8 +583,8 @@ class BookmarkPlugin extends Plugin
|
|||||||
$options['replies'] = array();
|
$options['replies'] = array();
|
||||||
|
|
||||||
foreach ($replies as $replyURI) {
|
foreach ($replies as $replyURI) {
|
||||||
$profile = Profile::fromURI($replyURI);
|
$other = Profile::fromURI($replyURI);
|
||||||
if (!empty($profile)) {
|
if (!empty($other)) {
|
||||||
$options['replies'][] = $replyURI;
|
$options['replies'][] = $replyURI;
|
||||||
} else {
|
} else {
|
||||||
$group = User_group::staticGet('uri', $replyURI);
|
$group = User_group::staticGet('uri', $replyURI);
|
||||||
@ -586,12 +605,18 @@ class BookmarkPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bookmark::saveNew($author->localProfile(),
|
return Bookmark::saveNew($profile,
|
||||||
$bookmark->title,
|
$bookmark->title,
|
||||||
$url,
|
$url,
|
||||||
$tags,
|
$tags,
|
||||||
$bookmark->summary,
|
$bookmark->summary,
|
||||||
$options);
|
$options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static private function _isPostBookmark($activity)
|
||||||
|
{
|
||||||
|
return ($activity->verb == ActivityVerb::POST &&
|
||||||
|
$activity->objects[0]->type == ActivityObject::BOOKMARK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user