1<?php 2/** 3 * XML feed export 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9 ini_set('short_open_tag',"1"); 10 require_once("inc/common.php"); 11 require_once("inc/parser.php"); 12 require_once("inc/feedcreator.class.php"); 13 require_once("inc/auth.php"); 14 15 //set auth header for login 16 if($_REQUEST['login'] && !isset($_SERVER['PHP_AUTH_USER'])){ 17 header('WWW-Authenticate: Basic realm="'.$conf['title'].'"'); 18 header('HTTP/1.0 401 Unauthorized'); 19 auth_logoff(); 20 } 21 22 23 $num = $_REQUEST['num']; 24 $type = $_REQUEST['type']; 25 $mode = $_REQUEST['mode']; 26 $ns = $_REQUEST['ns']; 27 28 switch ($type){ 29 case 'rss': 30 $type = 'RSS0.9'; 31 break; 32 case 'rss2': 33 $type = 'RSS2.0'; 34 break; 35 case 'atom': 36 $type = 'ATOM0.3'; 37 break; 38 default: 39 $type = 'RSS1.0'; 40 } 41 42 //some defaults for the feed 43 $CACHEGROUP = 'feed'; 44 $conf['typography'] = false; 45 $conf['canonical'] = true; 46 $parser['toc'] = false; 47 48 $rss = new UniversalFeedCreator(); 49 $rss = new DokuWikiFeedCreator(); 50 $rss->title = $conf['title']; 51 $rss->link = wl(); 52 $rss->syndicationURL = getBaseURL().'/feed.php'; 53 $rss->cssStyleSheet = getBaseURL().'/feed.css'; 54 55 if($mode == 'list'){ 56 rssListNamespace($rss,$ns); 57 }else{ 58 rssRecentChanges($rss,$num); 59 } 60 61 header('Content-Type: application/xml; charset='.$lang['encoding']); 62 print $rss->createFeed($type,$lang['encoding']); 63 64// ---------------------------------------------------------------- // 65 66/** 67 * Add recent changed to a feed object 68 * 69 * @author Andreas Gohr <andi@splitbrain.org> 70 */ 71function rssRecentChanges(&$rss,$num){ 72 $recents = getRecents($num); 73 foreach(array_keys($recents) as $id){ 74 $desc = cleanDesc(parsedWiki($id)); 75 if(!empty($recents[$id]['sum'])){ 76 $desc = '['.strip_tags($recents[$id]['sum']).'] '.$desc; 77 } 78 $item = new FeedItem(); 79 $item->title = $id; 80 $item->link = wl($id,'rev='.$recents[$id]['date']); 81 $item->description = $desc; 82 $item->date = date('r',$recents[$id]['date']); 83 if(strpos($id,':')!==false){ 84 $item->category = substr($id,0,strrpos($id,':')); 85 } 86 if($recents[$id]['user']){ 87 $item->author = $recents[$id]['user'].'@'; 88 }else{ 89 $item->author = 'anonymous@'; 90 } 91 $item->author .= $recents[$id]['ip']; 92 93 $rss->addItem($item); 94 } 95} 96 97/** 98 * Add all pages of a namespace to a feedobject 99 * 100 * @author Andreas Gohr <andi@splitbrain.org> 101 */ 102function rssListNamespace(&$rss,$ns){ 103 require_once("inc/search.php"); 104 global $conf; 105 106 $ns=':'.cleanID($ns); 107 $ns=str_replace(':','/',$ns); 108 109 $data = array(); 110 sort($data); 111 search($data,$conf['datadir'],'search_list','',$ns); 112 foreach($data as $row){ 113 $id = $row['id']; 114 $date = filemtime(wikiFN($id)); 115 $desc = cleanDesc(parsedWiki($id)); 116 $item = new FeedItem(); 117 $item->title = $id; 118 $item->link = wl($id,'rev='.$date); 119 $item->description = $desc; 120 $item->date = date('r',$date); 121 $rss->addItem($item); 122 } 123} 124 125/** 126 * Clean description for feed inclusion 127 * 128 * Removes HTML tags and line breaks and trims the text to 129 * 250 chars 130 * 131 * @author Andreas Gohr <andi@splitbrain.org> 132 */ 133function cleanDesc($desc){ 134 //remove TOC 135 $desc = strip_tags($desc); 136 $desc = preg_replace('/[\n\r\t]/',' ',$desc); 137 $desc = preg_replace('/ /',' ',$desc); 138 $desc = substr($desc,0,250); 139 $desc = $desc.'...'; 140 return $desc; 141} 142 143?> 144