Update of /cvsroot/php-blog/additional_plugins/serendipity_plugin_delicious
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18472/serendipity_plugin_delicious
Added Files:
serendipity_plugin_delicious.php
Log Message:
adding a del.icio.us plug-in
--- NEW FILE: serendipity_plugin_delicious.php ---
<?php
/*
A del.icio.us plug-in - v0.2.2 (feed edition) Notations
-------------------------------------------------
email: ri...@gm...
download: http://riscky.info:8080/serendipity/archives/4-A-del.icio.us-plug-in-v0.2-feed-edition-notations.html
forum announcement: http://s9y.info/forums/viewtopic.php?p=2880
-------------------------------------------------
About:
A del.icio.us plug-in (feed edition) provides a basic dumbed down del.icio.us integration into Serendipity. Originally the plug-in entitled "Embed my Links" to reflect the main goal of the plug-in; to clone the popular "Remaindered Links" & "Blogmarks" systems, and uses the trendy del.icio.us for its back-end support. The 0.2.x development series will be the last series what supports Serendipity 0.7.x branch.
Fixed:
Fixed some error sniffing logic [v0.2.2]
Removed Onyx Cacheing [v0.2.1]
Better caching system [v0.2]
Added tag & tag intersection support [v0.2]
Handles feed errors in an elegant manner (not perfeect) [v0.2]
Some little stuff too [v0.2]
Known Issues:
* update plug-ins config options don't take effect right away; i.e. if current cache time is 3 hours, you just change feed size from 30 to 10... and just grabed a new feed then you must wait 3 hours from last feed grab must occur before feed size changes -- no working theory's yet
Post release plans:
* 'Public' set up public SVN server to obtain latest version of the plug-in [v0.2.2 commited to serendipity CVS]
* 'API' move to from RSS gets to api gets
* 'Scope' Pair up Serendipity Categories with del.icio.us tags
* 'Temporal' Display only del.icio.us tags in reference to current serendipity time view
* 'Inline' Ability to display del.icio.us content in the main frame
This plug-in should work; any comments etc can be directed towards riscky-\{\@\}-gmail-\[dot\]-com
*/
switch ($serendipity['lang']) {
case 'en':
@define('PLUGIN_DELICIOUS_N', 'A del.icio.us plug-in');
@define('PLUGIN_DELICIOUS_D', 'A clone of the "Remaindered Links" & "Blogmarks" systems, and uses the trendy del.icio.us for its back-end support.');
@define('PLUGIN_DELICIOUS_TITLE_N', 'Sidebar Title');
@define('PLUGIN_DELICIOUS_TITLE_D', 'The title given for the del.icio.us feed plug-in.');
@define('PLUGIN_DELICIOUS_USERNAME_N', 'Username');
@define('PLUGIN_DELICIOUS_USERNAME_D', 'The usename of del.icio.us account you wish to display (Note: if you wish to use display tags, use the form tag/<tag name> i.e. "tag/delicious" tag intersections are also supported "tag/web+css")');
@define('PLUGIN_DELICIOUS_DISPLAYNUMBER_N', 'Number of post to dispaly');
@define('PLUGIN_DELICIOUS_DISPLAYNUMBER_D', 'How many del.icio.us post should be displayed? (Maxium feed size is the default, 30)');
@define('PLUGIN_DELICIOUS_CACHETIME_N', 'When to update the feed?');
@define('PLUGIN_DELICIOUS_CACHETIME_D', 'The contents of a feed are stored in a cache which will be updated as soon as its older than X hours (Default: 1 hours)');
break;
}
class serendipity_plugin_delicious extends serendipity_plugin {
function introspect(&$propbag) {
$propbag->add('name', PLUGIN_DELICIOUS_N);
$propbag->add('description', PLUGIN_DELICIOUS_D);
$propbag->add('author', 'Risck (riscky-\{\@\}-gmail-\[dot\]-com');
$propbag->add('version', '0.2.2 (feed edition)');
$propbag->add('stackable', true);
$propbag->add('configuration',
array( 'sidebarTitle', //
'deliciousID', //
'displayNumber', //
'cacheTime', //
));
}
function introspect_config_item($name, &$propbag) {
switch($name) {
case 'sidebarTitle':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_DELICIOUS_TITLE_N);
$propbag->add('description', PLUGIN_DELICIOUS_TITLE_D);
$propbag->add('default', 'My del.icio.us');
break;
case 'deliciousID':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_DELICIOUS_USERNAME_N);
$propbag->add('description', PLUGIN_DELICIOUS_USERNAME_D);
$propbag->add('default', 'riscky');
break;
case 'displayNumber':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_DELICIOUS_DISPLAYNUMBER_N);
$propbag->add('description', PLUGIN_DELICIOUS_DISPLAYNUMBER_D);
$propbag->add('default', '30');
break;
case 'cacheTime':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_DELICIOUS_CACHETIME_N);
$propbag->add('description', PLUGIN_DELICIOUS_CACHETIME_D);
$propbag->add('default', 1);
break;
default:
return false;
}
return true;
}
function generate_content(&$title) {
global $serendipity;
$title = $this->get_config('sidebarTitle');
$deliciousID = $this->get_config('deliciousID');
if ($this->get_config('displayNumber') < 30 && $this->get_config('displayNumber') >= 1)
{ $displayNumber = $this->get_config('displayNumber'); }
else { $displayNumber = 30; }
if ($this->get_config('cacheTime') > 0)
{ $cacheTime = ($this->get_config('cacheTime') * 3600); }
else { $cacheTime = 3600 + 1 ; }
$gDeliciousURL = 'http://del.icio.us/';
$gDeliciousCacheLoc = './' . 'cache/';
// safe write location... need to have local abilit
$parsedCache = $gDeliciousCacheLoc . md5($deliciousID) . '.cache';
if(!is_file($parsedCache) || ((mktime() - filectime($parsedCache)) > $cacheTime))
{
if (!is_dir($gDeliciousCacheLoc)){ if(!mkdir($gDeliciousCacheLoc, 0775)) {print 'Try to chmod go+rwx';};} else {};
require_once 'bundled-libs/Onyx/RSS.php';
$deliciousFeed = &new Onyx_RSS();
//$deliciousFeed->setCachePath($gDeliciousCacheLoc);
//$deliciousFeed->setExpiryTime($cacheTime);
//$deliciousFeed->parse($gDeliciousURL .'rss/' . $deliciousID, md5($deliciousID) . '.dat');
$deliciousFeed->parse($gDeliciousURL .'rss/' . $deliciousID);
if( $deliciousFeed->numItems() >= 1 )
{
$fileHandle = @fopen($parsedCache, 'w');
if ($fileHandle) {
$deliciousContent = '<ul class="delciousEmbed" style="padding:0.1em;list-style-type:none;font-size:10px;">';
for($i = 0; ($item = $deliciousFeed->getNextItem()) && ($i < $displayNumber); $i++) {
$deliciousContent .=
'<li class="deliciousListItem" style="list-style-type:square;list-style-position:inside;">' .
'<a href="' . delicious_clean_htmlspecialchars($item['link']) .
'" title="' . $item['description'] . '">' . delicious_clean_htmlspecialchars($item['title']) . '</a></li>';
}
$deliciousContent .= '</ul>';
fwrite($fileHandle, $deliciousContent);
fclose($fileHandle);
print $deliciousContent;
}
else {
print 'A del.icio.us error occured! <br />' . 'Error Message: unable to make a delicious file!';
}
}
elseif (is_file($parsedCache)) {
print file_get_contents($parsedCache);
}
else { print 'A del.icio.us error occured! <br />' . 'Error Message: rss failed'; }
}
else { print file_get_contents($parsedCache); }
print '<a href="' . $gDeliciousURL . $deliciousID . '/">(More)</a>';
}
}
function delicious_clean_htmlspecialchars($given, $quote_style = ENT_QUOTES) {
return htmlspecialchars(html_entity_decode($given, $quote_style), $quote_style);
}
?>
|