Difference between revisions of "Delicious Extension"

From ThePlaz.com

Jump to: navigation, search
(post initial version)

Revision as of 14:34, 24 July 2010

I made a delicious extension for my MediaWiki site. The extension lets you insert all of the stories with a given tag into the wiki. Note, I made the extension for my purposes; not general use. This means the extension has 2 downsides: right now it is hard coded to my username and the you have to edit a CSS file and add an image somewhere. These things can be easily modified by someone in the future. (If someone does modify the code, I would be glad to host/link to your modifications). Also, when you manually add the css to MediaWiki:Common.css you do not impact load times as much as if the CSS would be a separate file that the script calls.

This extension is released under the Creative Commons BY license.

Contents

Installation

  1. Save the Extension code as /extensions/Delicious.php
  2. Save the Delicious logo to /extensions/delicious.20
  3. Copy the CSS code to MediaWiki:Common.css
  4. Link to the Delicious Code in LocalSettings.php: include("/extensions/Delicious.php");

Extension Code

<?php

  1. Delicious MediaWiki extension v.1
  2. Michael Plasmeier (http://theplaz.com) 2010.07


$wgExtensionFunctions[] = 'wfDelicious'; $wgExtensionCredits['parserhook'][] = array(

       'name' => 'Delicious Reader',
       'description' => 'Displays Delicious sets.',
       'author' => 'Michael Plasmeier (ThePlaz)',
       'url' => 'http://theplaz.com/'

);

function wfDelicious() {

       global $wgParser;
       $wgParser->setHook('delicious', 'renderDeliciousTag');

}

function renderDeliciousTag($tag){ $feed_xml = getURL('http://feeds.delicious.com/v2/rss/theplaz/'.$tag); $feed = simplexml_load_string($feed_xml); $output = ;

$output .= '
'; $output .= '

<a href="http://delicious.com"><img src="delicious.20.gif" />Delicious</a> / <a href="http://delicious.com/theplaz">theplaz</a> / <a href="http://delicious.com/theplaz/'.$tag.'/">'.$tag.'</a>

';

foreach ($feed->channel->item as $item) { /*["title"]=> string(62) "Design // Amtrak Subway Map - Cameron Booth | Graphic Designer" ["pubDate"]=> string(31) "Wed, 21 Jul 2010 20:36:56 +0000" ["guid"]=> string(65) "http://delicious.com/url/87905d02fb6498d8852245d398a3e5bc#theplaz" ["link"]=> string(36) "http://www.cambooth.net/archives/246" ["comments"]=> string(57) "http://delicious.com/url/87905d02fb6498d8852245d398a3e5bc" ["source"]=> string(19) "theplaz's bookmarks" ["description"]=> string(18) "A really nice job!" ["category"]=> array(2) { [0]=> string(6) "design" [1]=> string(7) "transit" } } */

$output .= '

'.date("n/j", strtotime($item->pubDate)).' <img src="http://open.thumbshots.org/image.pxf?url='.$item->link.'" />

<a href="'.$item->link.'" class="title">'.$item->title.'</a>

'.$item->description.'

<a href="'.$item->link.'" class="url">'.$item->link.'</a>

';

foreach ($item->category as $category) { $output .= '<a href="http://delicious.com/theplaz/'.$tag.'/">'.$category.'</a> | '; }

$output .= '
';

}

$output .= '
';

return $output; }

function getURL($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$http_result = curl_exec($ch); $error = curl_error($ch); $http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE); //var_dump(curl_getinfo($ch));

curl_close($ch);

//should really throw an exception here if ($error) { print "

CURL Error: $error"; return FALSE; }

return $http_result; }


?>

CSS

Image