*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
require_once(DOKU_INC.'inc/HTTPClient.php');
require_once(DOKU_INC.'inc/JSON.php');
require_once(DOKU_PLUGIN.'friendfeed/friendfeed.php');
class syntax_plugin_friendfeed extends DokuWiki_Syntax_Plugin {
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'Andreas Gohr',
'email' => 'andi@splitbrain.org',
'date' => '2008-03-30',
'name' => 'Friendfeed Plugin',
'desc' => 'Display data from friendfeed.com',
'url' => 'http://wiki.splitbrain.org/plugin:friendfeed',
);
}
/**
* What kind of syntax are we?
*/
function getType(){
return 'substition';
}
/**
* What about paragraphs?
*/
function getPType(){
return 'block';
}
/**
* Where to sort in?
*/
function getSort(){
return 155;
}
/**
* Connect pattern to lexer
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern('~~friendfeed~~',$mode,'plugin_friendfeed');
}
/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler){
return array();
}
/**
* Create output
*/
function render($format, &$R, $data) {
global $conf;
if($format == 'metadata'){
$this->meta['date']['valid']['age'] = $this->getConf('cachetime');
return true;
}
if($format != 'xhtml') return false;
$user = $this->getConf('user');
$apikey = $this->getConf('apikey');
$s_exclude = $this->getConf('serviceexclude');
$l_exclude = $this->getConf('linkexclude');
$target = ($conf['target']['extern'])? 'target="'.$conf['target']['extern'].'"':'';
$ff = new FriendFeed($user,$pass);
$feed = $ff->fetch_user_feed($user, null, 0, 60);
if(is_null($feed)){
$R->doc .= 'error on fetching friend feed';
return true;
}
$doc = '
';
foreach($feed->entries as $entry){
// skip excludes
if($s_exclude &&
(preg_match('/'.$s_exclude.'/',$entry->service->id) ||
preg_match('/'.$s_exclude.'/',$entry->service->name) )) continue;
if($l_exclude && preg_match('/'.$l_exclude.'/',$entry->link)) continue;
$doc .= '';
// images?
if(count($entry->media)){
$img = ml($entry->media[0]->thumbnails[0]->url,'w=120');
}else{
$img = 'http://www.artviper.net/screenshots/screener.php?q=100&w=120&h=90&sdx=1024&sdy=768&url='.
rawurlencode($entry->link);
}
$doc .= '
';
$doc .= '
';
$doc .= '';
// the link
$doc .= '
'.hsc($entry->title).'';
// use first comment by user as description
$doc .= '
';
if(count($entry->comments) && $entry->comments[0]->user->nickname == $user){
$doc .= $entry->comments[0]->body;
array_shift($entry->comments);
}
// add service
$doc .= ' (shared via '.hsc($entry->service->name).')';
$doc .= '
';
// add comments
$doc .= '
';
if(count($entry->comments)){
foreach($entry->comments as $com){
$doc .= '';
}
}
$doc .= '';
$doc .= '
';
$doc .= '
';
}
$doc .= '
';
$R->doc .= $doc;
return true;
}
/**
* Create Feed output
*
* @fixme contains duplicate code from the render method
*/
function feed() {
global $conf;
$user = $this->getConf('user');
$apikey = $this->getConf('apikey');
$s_exclude = $this->getConf('serviceexclude');
$l_exclude = $this->getConf('linkexclude');
$target = ($conf['target']['extern'])? 'target="'.$conf['target']['extern'].'"':'';
// prepare caching and handle conditional requests
$cache = getCacheName($user.$s_exclude.$l_exclude,'.friendfeed');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Type: application/xml; charset=utf-8');
$cmod = @filemtime($cache);
if($cmod && $cmod+$this->getConf('cachetime') >time()){
http_conditionalRequest($cmod);
if($conf['allowdebug']) header("X-CacheUsed: $cache");
echo io_readFile($cache);
exit;
} else {
http_conditionalRequest(time());
}
$ff = new FriendFeed($user,$pass);
$feed = $ff->fetch_user_feed($user, null, 0, 60);
if(is_null($feed)){
die('error on fetching friendfeed');
}
$rss = new DokuWikiFeedCreator();
$rss->cssStyleSheet = DOKU_URL.'lib/exe/css.php?s=feed';
$rss->title = $user."'s FriendFeed";
foreach($feed->entries as $entry){
// skip excludes
if($s_exclude &&
(preg_match('/'.$s_exclude.'/',$entry->service->id) ||
preg_match('/'.$s_exclude.'/',$entry->service->name) )) continue;
if($l_exclude && preg_match('/'.$l_exclude.'/',$entry->link)) continue;
$item = new FeedItem();
$item->date = date('r',$entry->published);
$item->link = $entry->link;
$item->title = $entry->title;
$doc = '';
// images?
if(count($entry->media)){
$img = ml($entry->media[0]->thumbnails[0]->url,'w=120',true,'&',true);
}else{
$img = 'http://www.artviper.net/screenshots/screener.php?q=100&w=120&h=90&sdx=1024&sdy=768&url='.
rawurlencode($entry->link);
}
$doc .= '';
$doc .= '
';
$doc .= '';
// use first comment by user as description
$doc .= '';
if(count($entry->comments) && $entry->comments[0]->user->nickname == $user){
$doc .= $entry->comments[0]->body;
array_shift($entry->comments);
}
// add service
$doc .= ' (via '.hsc($entry->service->name).')';
$doc .= '
';
$doc .= 'Add Comment';
$item->description = $doc;
$rss->addItem($item);
}
$feed = $rss->createFeed($conf['rss_type'],'utf-8');
io_saveFile($cache,$feed);
echo $feed;
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :