GeSHi © 2007, DokuWiki and FCKeditor. View source of feed.php for example of using GeSHi
  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.   if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__)).'/');
  10.   require_once(DOKU_INC.'inc/init.php');
  11.   require_once(DOKU_INC.'inc/common.php');
  12.   require_once(DOKU_INC.'inc/events.php');
  13.   require_once(DOKU_INC.'inc/parserutils.php');
  14.   require_once(DOKU_INC.'inc/feedcreator.class.php');
  15.   require_once(DOKU_INC.'inc/auth.php');
  16.   require_once(DOKU_INC.'inc/pageutils.php');
  17.  
  18.   //close session
  19.  
  20.  
  21.   $num   = $_REQUEST['num'];
  22.   $type  = $_REQUEST['type'];
  23.   $mode  = $_REQUEST['mode'];
  24.   $minor = $_REQUEST['minor'];
  25.   $ns    = $_REQUEST['ns'];
  26.   $ltype = $_REQUEST['linkto'];
  27.  
  28.   if($type == '')
  29.     $type = $conf['rss_type'];
  30.  
  31.   switch ($type){
  32.     case 'rss':
  33.        $type = 'RSS0.91';
  34.        $mime = 'text/xml';
  35.        break;
  36.     case 'rss2':
  37.        $type = 'RSS2.0';
  38.        $mime = 'text/xml';
  39.        break;
  40.     case 'atom':
  41.        $type = 'ATOM0.3';
  42.        $mime = 'application/xml';
  43.        break;
  44.     case 'atom1':
  45.        $type = 'ATOM1.0';
  46.        $mime = 'application/atom+xml';
  47.        break;
  48.     default:
  49.        $type = 'RSS1.0';
  50.        $mime = 'application/xml';
  51.   }
  52.  
  53.   // the feed is dynamic - we need a cache for each combo
  54.   // (but most people just use the default feed so it's still effective)
  55.   $cache = getCacheName($num.$type.$mode.$ns.$ltype.$_SERVER['REMOTE_USER'],'.feed');
  56.   $cmod = @filemtime($cache); // 0 if not exists
  57.   if ($cmod && (@filemtime(DOKU_CONF.'local.php')>$cmod || @filemtime(DOKU_CONF.'dokuwiki.php')>$cmod)) {
  58.     // ignore cache if feed prefs may have changed
  59.     $cmod = 0;
  60.   }
  61.  
  62.   // check cacheage and deliver if nothing has changed since last
  63.   // time or the update interval has not passed, also handles conditional requests
  64.   header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  65.   header('Pragma: public');
  66.   header('Content-Type: application/xml; charset=utf-8');
  67.   if($cmod && (($cmod+$conf['rss_update']>time()) || ($cmod>@filemtime($conf['changelog'])))){
  68.     http_conditionalRequest($cmod);
  69.     if($conf['allowdebug']) header("X-CacheUsed: $cache");
  70.     print io_readFile($cache);
  71.     exit;
  72.   } else {
  73.     http_conditionalRequest(time());
  74.   }
  75.  
  76.   // create new feed
  77.   $rss = new DokuWikiFeedCreator();
  78.   $rss->title = $conf['title'].(($ns) ? ' '.$ns : '');
  79.   $rss->link  = DOKU_URL;
  80.   $rss->syndicationURL = DOKU_URL.'feed.php';
  81.   $rss->cssStyleSheet  = DOKU_URL.'lib/exe/css.php?s=feed';
  82.  
  83.   $image = new FeedImage();
  84.   $image->title = $conf['title'];
  85.   $image->url = DOKU_URL."lib/images/favicon.ico";
  86.   $image->link = DOKU_URL;
  87.   $rss->image = $image;
  88.  
  89.   if($mode == 'list'){
  90.     rssListNamespace($rss,$ns);
  91.   }else{
  92.     rssRecentChanges($rss,$num,$ltype,$ns,$minor);
  93.   }
  94.  
  95.   $feed = $rss->createFeed($type,'utf-8');
  96.  
  97.   // save cachefile
  98.   io_saveFile($cache,$feed);
  99.  
  100.   // finally deliver
  101.   print $feed;
  102.  
  103. // ---------------------------------------------------------------- //
  104.  
  105. /**
  106. * Add recent changed pages to a feed object
  107. *
  108. * @author Andreas Gohr <andi@splitbrain.org>
  109. */
  110. function rssRecentChanges(&$rss,$num,$ltype,$ns,$minor){
  111.     global $conf;
  112.     global $auth;
  113.  
  114.     if(!$num) $num = $conf['recent'];
  115.     $guardmail = ($conf['mailguard'] != '' && $conf['mailguard'] != 'none');
  116.  
  117.  
  118.     $flags = RECENTS_SKIP_DELETED;
  119.     if(!$minor) $flags += RECENTS_SKIP_MINORS;
  120.  
  121.     $recents = getRecents(0,$num,$ns,$flags);
  122.  
  123.     foreach($recents as $recent){
  124.         $item = new FeedItem();
  125.         $meta = p_get_metadata($recent['id']);
  126.  
  127.         if($conf['useheading'] && $meta['title']){
  128.             $item->title = $meta['title'];
  129.         }else{
  130.             $item->title = $recent['id'];
  131.         }
  132.         if($conf['rss_show_summary'] && !empty($recent['sum'])){
  133.             $item->title .= ' - '.strip_tags($recent['sum']);
  134.         }
  135.  
  136.         if(empty($ltype)) $ltype = $conf['rss_linkto'];
  137.  
  138.         switch ($ltype){
  139.             case 'page':
  140.                 $item->link = wl($recent['id'],'rev='.$recent['date'],true,'&');
  141.                 break;
  142.             case 'rev':
  143.                 $item->link = wl($recent['id'],'do=revisions&rev='.$recent['date'],true,'&');
  144.                 break;
  145.             case 'current':
  146.                 $item->link = wl($recent['id'], '', true,'&');
  147.                 break;
  148.             case 'diff':
  149.             default:
  150.                 $item->link = wl($recent['id'],'rev='.$recent['date'].'&do=diff',true,'&');
  151.         }
  152.  
  153.         $item->description = $meta['description']['abstract'];
  154.         $item->date        = date('r',$recent['date']);
  155.         $cat = getNS($recent['id']);
  156.         if($cat) $item->category = $cat;
  157.  
  158.         // FIXME should the user be pulled from metadata as well?
  159.         $user = null;
  160.         $user = @$recent['user']; // the @ spares time repeating lookup
  161.         $item->author = '';
  162.  
  163.         if($user && $conf['useacl'] && $auth){
  164.             $userInfo = $auth->getUserData($user);
  165.             $item->author = $userInfo['name'];
  166.             if($guardmail) {
  167.             //cannot obfuscate because some RSS readers may check validity
  168.                 $item->authorEmail = $user.'@'.$recent['ip'];
  169.             }else{
  170.                 $item->authorEmail = $userInfo['mail'];
  171.             }
  172.         }elseif($user){
  173.             // this happens when no ACL but some Apache auth is used
  174.             $item->author      = $user;
  175.             $item->authorEmail = $user.'@'.$recent['ip'];
  176.         }else{
  177.             $item->authorEmail = 'anonymous@'.$recent['ip'];
  178.         }
  179.         $rss->addItem($item);
  180.     }
  181. }
  182.  
  183. /**
  184. * Add all pages of a namespace to a feedobject
  185. *
  186. * @author Andreas Gohr <andi@splitbrain.org>
  187. */
  188. function rssListNamespace(&$rss,$ns){
  189.     require_once(DOKU_INC.'inc/search.php');
  190.     global $conf;
  191.  
  192.     $ns=':'.cleanID($ns);
  193.     $ns=str_replace(':','/',$ns);
  194.  
  195.     $data = array();
  196.     sort($data);
  197.     search($data,$conf['datadir'],'search_list','',$ns);
  198.     foreach($data as $row){
  199.         $item = new FeedItem();
  200.  
  201.         $id   = $row['id'];
  202.         $date = filemtime(wikiFN($id));
  203.         $meta = p_get_metadata($id);
  204.  
  205.         if($conf['useheading'] && $meta['title']){
  206.             $item->title = $meta['title'];
  207.         }else{
  208.             $item->title = $id;
  209.         }
  210.  
  211.         $item->link        = wl($id,'rev='.$date,true,'&');
  212.         $item->description = $meta['description']['abstract'];
  213.         $item->date        = date('r',$date);
  214.         $rss->addItem($item);
  215.   }
  216. }
  217.  
  218. //Setup VIM: ex: et ts=4 enc=utf-8 :
  219. ?>
  220.  
Parsed in 0.386 seconds, using GeSHi 1.0.7.19

 
sources/feed.php.txt · Dernière modification: 2007/12/02 04:57 (édition externe)
 
Recent changes RSS feed Creative Commons License Powered by PHP Valid XHTML 1.0 Valid CSS Donate Driven by DokuWiki