Difference between revisions of "Delicious Extension"
From ThePlaz.com
(add links) |
(move around) |
||
Line 10: | Line 10: | ||
#Copy the CSS code to [[MediaWiki:Common.css]] | #Copy the CSS code to [[MediaWiki:Common.css]] | ||
#Link to the Delicious Code in LocalSettings.php: <code>include("/extensions/Delicious.php");</code> | #Link to the Delicious Code in LocalSettings.php: <code>include("/extensions/Delicious.php");</code> | ||
+ | |||
+ | |||
+ | ==Use== | ||
+ | *User is hardcoded in the script. Someone should make it multi user. | ||
+ | <nowiki><delicious>tag</delicious></nowiki> | ||
==Extension Code== | ==Extension Code== | ||
Line 100: | Line 105: | ||
Save to <code>/extensions/delicious.20.gif</code> | Save to <code>/extensions/delicious.20.gif</code> | ||
− | |||
− | |||
− | |||
[[Category:Tech]] | [[Category:Tech]] | ||
[[Category:MediaWiki]] | [[Category:MediaWiki]] |
Revision as of 20:40, 15 January 2011
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.
The extension uses thumbnails from http://thumbshots.com. I am using the free server, so it only shows the homepage of the site. It's not very useful, but I think it adds some color to the list.
This extension is released under the Creative Commons BY license.
Contents |
Installation
- Save the Extension code as
/extensions/Delicious.php
- Save the Delicious logo to
/extensions/delicious.20.gif
- Copy the CSS code to MediaWiki:Common.css
- Link to the Delicious Code in LocalSettings.php:
include("/extensions/Delicious.php");
Use
- User is hardcoded in the script. Someone should make it multi user.
<delicious>tag</delicious>
Extension Code
<?php # Delicious MediaWiki extension v.1 # 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 .= '<div id="delicious">'; $output .= '<h3><a href="http://delicious.com"><img src="http://wiki.theplaz.com/w/extensions/delicious.20.gif" /><strong style="color:#3274D1">Delicious</strong></a> / <a href="http://delicious.com/theplaz">theplaz</a> / <a href="http://delicious.com/theplaz/'.$tag.'/">'.$tag.'</a></h3>'; 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 .= '<div class="deliciousitem"> <span class="date">'.date("n/j", strtotime($item->pubDate)).'</span> <img src="http://open.thumbshots.org/image.pxf?url='.$item->link.'" /> <div class="info"> <a href="'.$item->link.'" class="title">'.$item->title.'</a> <div class="description">'.$item->description.'</div> <a href="'.$item->link.'" class="url">'.$item->link.'</a> <div class="othertags">'; foreach ($item->category as $category) { $output .= '<a href="http://delicious.com/theplaz/'.$tag.'/">'.$category.'</a> | '; } $output .= '</div></div></div>'; } $output .= '</div>'; 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 "<br /><br />CURL Error: $error"; return FALSE; } return $http_result; } ?>
CSS
#delicious .date{font-size:smaller;color:gray;position:relative;float:left;} #delicious img{padding-right:5px;padding-left:5px;float:left;} #delicious .deliciousitem{padding-top:10px;clear:both;} #delicious .info{padding-left:150px;} #delicious .title{font-weight:700;} #delicious .description{background:url("http://friendfeed.com/static/images/comment-lighter.png?v=2") no-repeat scroll 0 5px transparent;padding-left:18px;}