* @param object $rss - the FeedCreator Object
* @param array $data - the items to add
* @param array $opt - the feed options
*/
function rss_buildItems(&$rss,&$data,$opt){
global $conf;
global $lang;
global $auth;
$eventData = array(
'rss' => &$rss,
'data' => &$data,
'opt' => &$opt,
);
$event = new Doku_Event('FEED_DATA_PROCESS', $eventData);
if ($event->advise_before(false)){
foreach($data as $ditem){
if(!is_array($ditem)){
// not an array? then only a list of IDs was given
$ditem = array( 'id' => $ditem );
}
$item = new FeedItem();
$id = $ditem['id'];
if(!$ditem['media']) {
$meta = p_get_metadata($id);
}
// add date
if($ditem['date']){
$date = $ditem['date'];
}elseif($meta['date']['modified']){
$date = $meta['date']['modified'];
}else{
$date = @filemtime(wikiFN($id));
}
if($date) $item->date = date('r',$date);
// add title
if($conf['useheading'] && $meta['title']){
$item->title = $meta['title'];
}else{
$item->title = $ditem['id'];
}
if($conf['rss_show_summary'] && !empty($ditem['sum'])){
$item->title .= ' - '.strip_tags($ditem['sum']);
}
// add item link
switch ($opt['link_to']){
case 'page':
if ($ditem['media']) {
$item->link = media_managerURL(array('image' => $id,
'ns' => getNS($id),
'rev' => $date), '&', true);
} else {
$item->link = wl($id,'rev='.$date,true,'&', true);
}
break;
case 'rev':
if ($ditem['media']) {
$item->link = media_managerURL(array('image' => $id,
'ns' => getNS($id),
'rev' => $date,
'tab_details' => 'history'), '&', true);
} else {
$item->link = wl($id,'do=revisions&rev='.$date,true,'&');
}
break;
case 'current':
if ($ditem['media']) {
$item->link = media_managerURL(array('image' => $id,
'ns' => getNS($id)), '&', true);
} else {
$item->link = wl($id, '', true,'&');
}
break;
case 'diff':
default:
if ($ditem['media']) {
$item->link = media_managerURL(array('image' => $id,
'ns' => getNS($id),
'rev' => $date,
'tab_details' => 'history',
'mediado' => 'diff'), '&', true);
} else {
$item->link = wl($id,'rev='.$date.'&do=diff',true,'&');
}
}
// add item content
switch ($opt['item_content']){
case 'diff':
case 'htmldiff':
if ($ditem['media']) {
$revs = getRevisions($id, 0, 1, 8192, true);
$rev = $revs[0];
$src_r = '';
$src_l = '';
if ($size = media_image_preview_size($id, false, new JpegMeta(mediaFN($id)), 300)) {
$more = 'w='.$size[0].'&h='.$size[1].'t='.@filemtime(mediaFN($id));
$src_r = ml($id, $more);
}
if ($rev && $size = media_image_preview_size($id, $rev, new JpegMeta(mediaFN($id, $rev)), 300)){
$more = 'rev='.$rev.'&w='.$size[0].'&h='.$size[1];
$src_l = ml($id, $more);
}
$content = '';
if ($src_r) {
$content = '';
$content .= ''.$rev.' | ';
$content .= ''.$lang['current'].' |
';
$content .= ' | ';
$content .= ' |
';
$content .= '
';
}
} else {
require_once(DOKU_INC.'inc/DifferenceEngine.php');
$revs = getRevisions($id, 0, 1);
$rev = $revs[0];
if($rev){
$df = new Diff(explode("\n",htmlspecialchars(rawWiki($id,$rev))),
explode("\n",htmlspecialchars(rawWiki($id,''))));
}else{
$df = new Diff(array(''),
explode("\n",htmlspecialchars(rawWiki($id,''))));
}
if($opt['item_content'] == 'htmldiff'){
$tdf = new TableDiffFormatter();
$content = '';
$content .= ''.$rev.' | ';
$content .= ''.$lang['current'].' |
';
$content .= $tdf->format($df);
$content .= '
';
}else{
$udf = new UnifiedDiffFormatter();
$content = "\n".$udf->format($df)."\n
";
}
}
break;
case 'html':
if ($ditem['media']) {
if ($size = media_image_preview_size($id, false, new JpegMeta(mediaFN($id)))) {
$more = 'w='.$size[0].'&h='.$size[1].'t='.@filemtime(mediaFN($id));
$src = ml($id, $more);
$content = '';
} else {
$content = '';
}
} else {
$content = p_wiki_xhtml($id,$date,false);
// no TOC in feeds
$content = preg_replace('/().*()/s','',$content);
// make URLs work when canonical is not set, regexp instead of rerendering!
if(!$conf['canonical']){
$base = preg_quote(DOKU_REL,'/');
$content = preg_replace('/(';
} else {
$content = '';
}
} else {
$content = $meta['description']['abstract'];
}
}
$item->description = $content; //FIXME a plugin hook here could be senseful
// add user
# FIXME should the user be pulled from metadata as well?
$user = @$ditem['user']; // the @ spares time repeating lookup
$item->author = '';
if($user && $conf['useacl'] && $auth){
$userInfo = $auth->getUserData($user);
if ($userInfo){
switch ($conf['showuseras']){
case 'username':
$item->author = $userInfo['name'];
break;
default:
$item->author = $user;
break;
}
} else {
$item->author = $user;
}
if($userInfo && !$opt['guardmail']){
$item->authorEmail = $userInfo['mail'];
}else{
//cannot obfuscate because some RSS readers may check validity
$item->authorEmail = $user.'@'.$ditem['ip'];
}
}elseif($user){
// this happens when no ACL but some Apache auth is used
$item->author = $user;
$item->authorEmail = $user.'@'.$ditem['ip'];
}else{
$item->authorEmail = 'anonymous@'.$ditem['ip'];
}
// add category
if(isset($meta['subject'])) {
$item->category = $meta['subject'];
}else{
$cat = getNS($id);
if($cat) $item->category = $cat;
}
// finally add the item to the feed object, after handing it to registered plugins
$evdata = array('item' => &$item,
'opt' => &$opt,
'ditem' => &$ditem,
'rss' => &$rss);
$evt = new Doku_Event('FEED_ITEM_ADD', $evdata);
if ($evt->advise_before()){
$rss->addItem($item);
}
$evt->advise_after(); // for completeness
}
}
$event->advise_after();
}
/**
* Add recent changed pages to the feed object
*
* @author Andreas Gohr
*/
function rssRecentChanges($opt){
global $conf;
$flags = RECENTS_SKIP_DELETED;
if(!$opt['show_minor']) $flags += RECENTS_SKIP_MINORS;
if($opt['content_type'] == 'media' && $conf['mediarevisions']) $flags += RECENTS_MEDIA_CHANGES;
if($opt['content_type'] == 'both' && $conf['mediarevisions']) $flags += RECENTS_MEDIA_PAGES_MIXED;
$recents = getRecents(0,$opt['items'],$opt['namespace'],$flags);
return $recents;
}
/**
* Add all pages of a namespace to the feed object
*
* @author Andreas Gohr
*/
function rssListNamespace($opt){
require_once(DOKU_INC.'inc/search.php');
global $conf;
$ns=':'.cleanID($opt['namespace']);
$ns=str_replace(':','/',$ns);
$data = array();
sort($data);
search($data,$conf['datadir'],'search_list','',$ns);
return $data;
}
/**
* Add the result of a full text search to the feed object
*
* @author Andreas Gohr
*/
function rssSearch($opt){
if(!$opt['search_query']) return;
require_once(DOKU_INC.'inc/fulltext.php');
$data = ft_pageSearch($opt['search_query'],$poswords);
$data = array_keys($data);
return $data;
}
//Setup VIM: ex: et ts=4 :