* @link http://status.net/
*/
-if (!defined('STATUSNET')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Bookmark plugin main class
const VERSION = '0.1';
const IMPORTDELICIOUS = 'BookmarkPlugin:IMPORTDELICIOUS';
- var $oldSaveNew = true;
-
/**
* Authorization for importing delicious bookmarks
*
/**
* Map URLs to actions
*
- * @param Net_URL_Mapper $m path-to-action mapper
+ * @param URLMapper $m path-to-action mapper
*
* @return boolean hook value; true means continue processing, false means stop.
*/
- function onRouterInitialized($m)
+ public function onRouterInitialized(URLMapper $m)
{
if (common_config('singleuser', 'enabled')) {
$nickname = User::singleUserNickname();
*
* @return value
*/
- function onPluginVersion(&$versions)
+ function onPluginVersion(array &$versions)
{
$versions[] = array('name' => 'Bookmark',
- 'version' => self::VERSION,
- 'author' => 'Evan Prodromou, Stephane Berube, Jean Baptiste Favre',
- 'homepage' => 'http://status.net/wiki/Plugin:Bookmark',
+ 'version' => GNUSOCIAL_VERSION,
+ 'author' => 'Evan Prodromou, Stephane Berube, Jean Baptiste Favre, Mikael Nordfeldth',
+ 'homepage' => 'https://gnu.io/social',
'description' =>
// TRANS: Plugin description.
- _m('Simple extension for supporting bookmarks. ') .
+ _m('Plugin for posting bookmarks. ') .
'BookmarkList feature has been developped by Stephane Berube. ' .
'Integration has been done by Jean Baptiste Favre.');
return true;
*/
function deleteRelated(Notice $notice)
{
- if ($this->isMyNotice($notice)) {
-
- $nb = Bookmark::getByNotice($notice);
-
- if (!empty($nb)) {
- $nb->delete();
- }
- }
+ try {
+ $nb = Bookmark::fromStored($notice);
+ } catch (NoResultException $e) {
+ throw new AlreadyFulfilledException('Bookmark already gone when deleting: '.$e->getMessage());
+ }
+ $nb->delete();
return true;
}
*
* @return Notice resulting notice
*/
- function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options=array())
+ protected function saveObjectFromActivity(Activity $activity, Notice $stored, array $options=array())
{
- $bookmark = $activity->objects[0];
-
- $relLinkEls = ActivityUtils::getLinks($bookmark->element, 'related');
-
- if (count($relLinkEls) < 1) {
- // TRANS: Client exception thrown when a bookmark is formatted incorrectly.
- throw new ClientException(_m('Expected exactly 1 link '.
- 'rel=related in a Bookmark.'));
- }
-
- if (count($relLinkEls) > 1) {
- common_log(LOG_WARNING,
- "Got too many link rel=related in a Bookmark.");
- }
-
- $linkEl = $relLinkEls[0];
-
- $url = $linkEl->getAttribute('href');
-
- $tags = array();
-
- foreach ($activity->categories as $category) {
- $tags[] = common_canonical_tag($category->term);
- }
-
- if (!empty($activity->time)) {
- $options['created'] = common_sql_date($activity->time);
- }
-
- // Fill in location if available
-
- $location = $activity->context->location;
-
- if ($location) {
- $options['lat'] = $location->lat;
- $options['lon'] = $location->lon;
- if ($location->location_id) {
- $options['location_ns'] = $location->location_ns;
- $options['location_id'] = $location->location_id;
- }
- }
-
- $options['groups'] = array();
- $options['replies'] = array(); // TODO: context->attention
-
- foreach ($activity->context->attention as $attnUrl=>$type) {
- try {
- $other = Profile::fromUri($attnUrl);
- if ($other->isGroup()) {
- $options['groups'][] = $other->id;
- } else {
- $options['replies'][] = $attnUrl;
- }
- } catch (UnknownUriException $e) {
- // We simply don't know this URI, despite lookup attempts.
- }
- }
-
- // Maintain direct reply associations
- // @fixme what about conversation ID?
-
- if (!empty($activity->context->replyToID)) {
- $orig = Notice::getKV('uri',
- $activity->context->replyToID);
- if (!empty($orig)) {
- $options['reply_to'] = $orig->id;
- }
- }
-
- return Bookmark::saveNew($actor,
- $bookmark->title,
- $url,
- $tags,
- $bookmark->summary,
- $options);
+ return Bookmark::saveActivityObject($activity->objects[0], $stored);
}
- function activityObjectFromNotice(Notice $notice)
+ public function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped=null)
{
- assert($this->isMyNotice($notice));
-
- common_log(LOG_INFO,
- "Formatting notice {$notice->uri} as a bookmark.");
-
- $object = new ActivityObject();
- $nb = Bookmark::getByNotice($notice);
-
- $object->id = $notice->uri;
- $object->type = ActivityObject::BOOKMARK;
- $object->title = $nb->title;
- $object->summary = $nb->description;
- $object->link = $notice->getUrl();
-
- // Attributes of the URL
-
- $attachments = $notice->attachments();
-
- if (count($attachments) != 1) {
- // TRANS: Server exception thrown when a bookmark has multiple attachments.
- throw new ServerException(_m('Bookmark notice with the '.
- 'wrong number of attachments.'));
- }
-
- $target = $attachments[0];
-
- $attrs = array('rel' => 'related',
- 'href' => $target->url);
-
- if (!empty($target->title)) {
- $attrs['title'] = $target->title;
+ if (!$this->isMyNotice($stored)) {
+ return true;
}
- $object->extra[] = array('link', $attrs, null);
-
- // Attributes of the thumbnail, if any
-
- try {
- $thumbnail = $target->getThumbnail();
- $tattrs = array('rel' => 'preview',
- 'href' => $thumbnail->url);
-
- if (!empty($thumbnail->width)) {
- $tattrs['media:width'] = $thumbnail->width;
- }
-
- if (!empty($thumbnail->height)) {
- $tattrs['media:height'] = $thumbnail->height;
- }
-
- $object->extra[] = array('link', $tattrs, null);
- } catch (UnsupportedMediaException $e) {
- // No image thumbnail metadata available
- }
+ $this->extendActivity($stored, $act, $scoped);
+ return false;
+ }
- return $object;
+ public function extendActivity(Notice $stored, Activity $act, Profile $scoped=null)
+ {
+ /*$hashtags = array();
+ $taglinks = array();
+
+ foreach ($tags as $tag) {
+ $hashtags[] = '#'.$tag;
+ $attrs = array('href' => Notice_tag::url($tag),
+ 'rel' => $tag,
+ 'class' => 'tag');
+ $taglinks[] = XMLStringer::estring('a', $attrs, $tag);
+ }*/
}
- /**
- * Given a notice list item, returns an adapter specific
- * to this plugin.
- *
- * @param NoticeListItem $nli item to adapt
- *
- * @return NoticeListItemAdapter adapter or null
- */
- function adaptNoticeListItem($nli)
+ function activityObjectFromNotice(Notice $notice)
{
- return new BookmarkListItem($nli);
+ return Bookmark::fromStored($notice)->asActivityObject();
}
function entryForm($out)
function onEndUpgrade()
{
+ printfnq('Making sure Bookmark notices have correct verb and object_type...');
+
// Version 0.9.x of the plugin didn't stamp notices
// with verb and object-type (for obvious reasons). Update
// those notices here.
$notice = new Notice();
- $notice->whereAdd('exists (select uri from bookmark where bookmark.uri = notice.uri)');
- $notice->whereAdd('((object_type is null) or (object_type = "' .ActivityObject::NOTE.'"))');
+ $notice->joinAdd(array('uri', 'bookmark:uri'));
+ $notice->whereAdd('object_type IS NULL OR object_type = '.$notice->_quote(ActivityObject::NOTE));
$notice->find();
$notice->object_type = ActivityObject::BOOKMARK;
$notice->update($original);
}
+
+ printfnq("DONE.\n");
}
public function activityObjectOutputJson(ActivityObject $obj, array &$out)
{
assert($obj->type == ActivityObject::BOOKMARK);
- $bm = Bookmark::getKV('uri', $obj->id);
+ $bm = Bookmark::getByPK(array('uri' => $obj->id));
- if (empty($bm)) {
- throw new ServerException("Unknown bookmark: " . $obj->id);
+ $out['displayName'] = $bm->getTitle();
+ $out['targetUrl'] = $bm->getUrl();
+
+ return true;
+ }
+
+ protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
+ {
+ $nb = Bookmark::fromStored($stored);
+
+ // Whether to nofollow
+ $attrs = array('href' => $nb->getUrl(), 'class' => 'bookmark-title');
+
+ $nf = common_config('nofollow', 'external');
+
+ if ($nf == 'never' || ($nf == 'sometimes' and $out instanceof ShowstreamAction)) {
+ $attrs['rel'] = 'external';
+ } else {
+ $attrs['rel'] = 'nofollow external';
}
- $out['displayName'] = $bm->title;
- $out['targetUrl'] = $bm->url;
+ $out->elementStart('h3');
+ $out->element('a', $attrs, $nb->getTitle());
+ $out->elementEnd('h3');
+
+ // Replies look like "for:" tags
+ $replies = $stored->getReplies();
+ $tags = $stored->getTags();
+
+ if (!empty($nb->description)) {
+ $out->element('p',
+ array('class' => 'bookmark-description'),
+ $nb->description);
+ }
+
+ if (!empty($replies) || !empty($tags)) {
+
+ $out->elementStart('ul', array('class' => 'bookmark-tags'));
+
+ foreach ($replies as $reply) {
+ $other = Profile::getByPK($reply);
+ $out->elementStart('li');
+ $out->element('a', array('rel' => 'tag',
+ 'href' => $other->getUrl(),
+ 'title' => $other->getBestName()),
+ sprintf('for:%s', $other->getNickname()));
+ $out->elementEnd('li');
+ $out->text(' ');
+ }
+
+ foreach ($tags as $tag) {
+ $tag = trim($tag);
+ if (!empty($tag)) {
+ $out->elementStart('li');
+ $out->element('a',
+ array('rel' => 'tag',
+ 'href' => Notice_tag::url($tag)),
+ $tag);
+ $out->elementEnd('li');
+ $out->text(' ');
+ }
+ }
+
+ $out->elementEnd('ul');
+ }
- return true;
}
}