*/
function rss_buildItems(&$rss, &$data, $opt)
{
global $conf;
global $lang;
/* @var AuthPlugin $auth */
global $auth;
$eventData = [
'rss' => &$rss,
'data' => &$data,
'opt' => &$opt,
];
$event = new 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 = ['id' => $ditem];
}
$item = new FeedItem();
$id = $ditem['id'];
if (!$ditem['media']) {
$meta = p_get_metadata($id);
} else {
$meta = [];
}
// add date
if ($ditem['date']) {
$date = $ditem['date'];
} elseif ($ditem['media']) {
$date = @filemtime(mediaFN($id));
} elseif (file_exists(wikiFN($id))) {
$date = @filemtime(wikiFN($id));
} elseif ($meta['date']['modified']) {
$date = $meta['date']['modified'];
} else {
$date = 0;
}
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(
[
'image' => $id,
'ns' => getNS($id),
'rev' => $date
],
'&',
true
);
} else {
$item->link = wl($id, 'rev=' . $date, true, '&');
}
break;
case 'rev':
if ($ditem['media']) {
$item->link = media_managerURL(
[
'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(
[
'image' => $id,
'ns' => getNS($id)
],
'&',
true
);
} else {
$item->link = wl($id, '', true, '&');
}
break;
case 'diff':
default:
if ($ditem['media']) {
$item->link = media_managerURL(
[
'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']) {
$medialog = new MediaChangeLog($id);
$revs = $medialog->getRevisions(0, 1);
$rev = $revs[0];
$src_r = '';
$src_l = '';
if ($size = media_image_preview_size($id, '', new JpegMeta(mediaFN($id)), 300)) {
$more = 'w=' . $size[0] . '&h=' . $size[1] . '&t=' . @filemtime(mediaFN($id));
$src_r = ml($id, $more, true, '&', true);
}
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, true, '&', true);
}
$content = '';
if ($src_r) {
$content = '';
$content .= '' . $rev . ' | ';
$content .= '' . $lang['current'] . ' |
';
$content .= ' | ';
$content .= ' |
';
$content .= '
';
}
} else {
require_once(DOKU_INC . 'inc/DifferenceEngine.php');
$pagelog = new PageChangeLog($id);
$revs = $pagelog->getRevisions(0, 1);
$rev = $revs[0];
if ($rev) {
$df = new Diff(
explode("\n", rawWiki($id, $rev)),
explode("\n", rawWiki($id, ''))
);
} else {
$df = new Diff(
[''],
explode("\n", rawWiki($id, ''))
);
}
if ($opt['item_content'] == 'htmldiff') {
// note: no need to escape diff output, TableDiffFormatter provides 'safe' html
$tdf = new TableDiffFormatter();
$content = '';
$content .= '' . $rev . ' | ';
$content .= '' . $lang['current'] . ' |
';
$content .= $tdf->format($df);
$content .= '
';
} else {
// note: diff output must be escaped, UnifiedDiffFormatter provides plain text
$udf = new UnifiedDiffFormatter();
$content = "\n" . hsc($udf->format($df)) . "\n
";
}
}
break;
case 'html':
if ($ditem['media']) {
if ($size = media_image_preview_size($id, '', new JpegMeta(mediaFN($id)))) {
$more = 'w=' . $size[0] . '&h=' . $size[1] . '&t=' . @filemtime(mediaFN($id));
$src = ml($id, $more, true, '&', true);
$content = '';
} else {
$content = '';
}
} else {
if (@filemtime(wikiFN($id)) === $date) {
$content = p_wiki_xhtml($id, '', false);
} else {
$content = p_wiki_xhtml($id, $date, false);
}
// no TOC in feeds
$content = preg_replace('/().*()/s', '', $content);
// add alignment for images
$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
if (blank($user)) {
$item->author = 'Anonymous';
$item->authorEmail = 'anonymous@undisclosed.example.com';
} else {
$item->author = $user;
$item->authorEmail = $user . '@undisclosed.example.com';
// get real user name if configured
if ($conf['useacl'] && $auth) {
$userInfo = $auth->getUserData($user);
if ($userInfo) {
switch ($conf['showuseras']) {
case 'username':
case 'username_link':
$item->author = $userInfo['name'];
break;
default:
$item->author = $user;
break;
}
} else {
$item->author = $user;
}
}
}
// 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 = [
'item' => &$item,
'opt' => &$opt,
'ditem' => &$ditem,
'rss' => &$rss
];
$evt = new 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 = 0;
if (!$conf['rss_show_deleted']) $flags += RECENTS_SKIP_DELETED;
if (!$opt['show_minor']) $flags += RECENTS_SKIP_MINORS;
if ($opt['only_new']) $flags += RECENTS_ONLY_CREATION;
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 = utf8_encodeFN(str_replace(':', '/', $ns));
$data = [];
$search_opts = [
'depth' => 1,
'pagesonly' => true,
'listfiles' => true
];
search($data, $conf['datadir'], 'search_universal', $search_opts, $ns, $lvl = 1, $opt['sort']);
return $data;
}
/**
* Add the result of a full text search to the feed object
*
* @author Andreas Gohr
*/
function rssSearch($opt)
{
if (!$opt['search_query'] || !actionOK('search')) 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 :