1<?php 2/** 3 * i-net Download Plugin 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author i-net software <tools@inetsoftware.de> 7 * @author Gerry Weissbach <gweissbach@inetsoftware.de> 8 */ 9 10// must be run within Dokuwiki 11if(!defined('DOKU_INC')) die(); 12 13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 14require_once(DOKU_PLUGIN.'action.php'); 15 16class action_plugin_rssbycreated extends DokuWiki_Action_Plugin { 17 18 function register(Doku_Event_Handler $controller) { 19 // Support given via POST 20 $controller->register_hook('FEED_ITEM_ADD', 'BEFORE', $this, 'rss_action'); 21 $controller->register_hook('FEED_DATA_PROCESS', 'BEFORE', $this, 'rss_action_pre'); 22 } 23 24 function rss_action(Doku_Event $event, $args) { 25 global $conf; 26 27 if ( $event->data['opt']['item_content'] == 'abstract' ) { 28 29 $content = p_render('xhtml', p_get_instructions($event->data['item']->description), $info); 30 31 // no TOC in feeds 32 $content = preg_replace('/(<!-- TOC START -->).*(<!-- TOC END -->)/s','',$content); 33 34 // make URLs work when canonical is not set, regexp instead of rerendering! 35 if(!$conf['canonical']){ 36 $base = preg_quote(DOKU_REL,'/'); 37 $content = preg_replace('/(<a href|<img src)="('.$base.')/s','$1="'.DOKU_URL,$content); 38 } 39 40 $event->data['item']->description = $content; 41 } 42 43 $event->data['item']->date = date('r', p_get_metadata($event->data['ditem']['id'],'date created')); 44 45 return true; 46 } 47 48 function rss_action_pre(Doku_Event $event, $args) { 49 global $conf; 50 $event->data['rss']->title = $conf['title']; 51 52 usort($event->data['data'], array($this, "__sortByDate")); 53 return true; 54 } 55 56 function __sortByDate($a, $b) { 57 $aID = $a['id']; 58 $bID = $b['id']; 59 60 return p_get_metadata($a['id'],'date created') <= p_get_metadata($b['id'],'date created'); 61 } 62}