LifePress
LifePress copied to clipboard
Pinboard tags parsed as a single tag
I have finally turned my back on delicious. It is just not reliable anymore. I want to use Diigo, but the feed does not parse tags properly. I have turned to pinboard.in, but tags are parsed as one single tag. They therefore come out like this: http://i.imgur.com/5kPBAmP.jpg
Is there any way to solve this in the pre db section of the plugin?
The feed section with tags looks like this:
<taxo:topics><rdf:Bag> <rdf:li rdf:resource="http://pinboard.in/u:therourke/t:cinema" />
<rdf:li rdf:resource="http://pinboard.in/u:therourke/t:film" />
<rdf:li rdf:resource="http://pinboard.in/u:therourke/t:horror" />
<rdf:li rdf:resource="http://pinboard.in/u:therourke/t:special" />
<rdf:li rdf:resource="http://pinboard.in/u:therourke/t:effects" />
<rdf:li rdf:resource="http://pinboard.in/u:therourke/t:stream" />
<rdf:li rdf:resource="http://pinboard.in/u:therourke/t:the" />
<rdf:li rdf:resource="http://pinboard.in/u:therourke/t:thing" />
</rdf:Bag></taxo:topics>
I have this section in my plugin, but it doesn't appear to work:
function pre_db($item, $original)
{
if (isset($item->item_data['topics'])) {
foreach ($item->item_data['topics'] as $key => $value) {
$item->item_data['tags'][$key] = $value->term;
}
}
Hope someone can help :-)
So this is because pinboard's RSS uses RSS 1.0's Taxonomy Module to do it's tags. SimplePie (the library used to parse RSS/Atom feeds) does not support the namespace url of: "http://purl.org/rss/1.0/modules/taxonomy/" (see SimplePie Supported XML NameSpaces).
However I was able to get it working by creating a LifePress plugin for pinboard.in using the following code if you'd like to test it out (note it will only fix tags on bookmarks going forward):
/application/plugins/pinboard_in.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Pinboard_in {
function pre_db($item, $original)
{
$item->item_data['tags'] = array();
$topics = $original->get_item_tags('http://purl.org/rss/1.0/modules/taxonomy/', 'topics');
if ($topics) {
$bag = $topics[0]['child']['http://www.w3.org/1999/02/22-rdf-syntax-ns#']['Bag'];
$li = $bag[0]['child']['http://www.w3.org/1999/02/22-rdf-syntax-ns#']['li'];
foreach ($li as $topic) {
$resource = $topic['attribs']['http://www.w3.org/1999/02/22-rdf-syntax-ns#']['resource'];
$item->item_data['tags'][] = substr($resource, strpos($resource, 't:') + 2);
}
}
return $item;
}
function pre_display($item)
{
return $item;
}
}
/* End of file pinboard_in.php */
/* Location: ./application/plugins/pinboard_in.php */
AMAZING
Thanks so much Mitchell. I hope this ends up being useful for others.