1<?php 2/** 3 * Info Plugin: Displays information about various DokuWiki internals 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9 10if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 12require_once(DOKU_PLUGIN.'syntax.php'); 13require_once(DOKU_INC.'inc/search.php'); 14 15/** 16 * All DokuWiki plugins to extend the parser/rendering mechanism 17 * need to inherit from this class 18 */ 19class syntax_plugin_nslist extends DokuWiki_Syntax_Plugin { 20 21 /** 22 * What kind of syntax are we? 23 */ 24 function getType(){ 25 return 'substition'; 26 } 27 28 /** 29 * What about paragraphs? 30 */ 31 function getPType(){ 32 return 'block'; 33 } 34 35 /** 36 * Where to sort in? 37 */ 38 function getSort(){ 39 return 302; 40 } 41 42 43 /** 44 * Connect pattern to lexer 45 */ 46 function connectTo($mode) { 47 $this->Lexer->addSpecialPattern('{{nslist>[^}]*}}',$mode,'plugin_nslist'); 48 } 49 50 51 /** 52 * Handle the match 53 */ 54 function handle($match, $state, $pos, Doku_Handler $handler){ 55 global $ID; 56 $match = substr($match,9,-2); //strip {{nslist> from start and }} from end 57 58 $conf = array( 59 'ns' => getNS($ID), 60 'depth' => 1, 61 'date' => 1, 62 'dsort' => 1 63 ); 64 65 list($ns,$params) = explode(' ',$match,2); 66 $ns = cleanID($ns); 67 68 if(preg_match('/\bnodate\b/i',$params)) $conf['date'] = 0; 69 if(preg_match('/\bnodsort\b/i',$params)) $conf['dsort'] = 0; 70 if(preg_match('/\b(\d+)\b/i',$params,$m)) $conf['depth'] = $m[1]; 71 if($ns) $conf['ns'] = $ns; 72 73 $conf['dir'] = str_replace(':','/',$conf['ns']); 74 75 // prepare data 76 return $conf; 77 } 78 79 /** 80 * Create output 81 */ 82 function render($format, Doku_Renderer $R, $data) { 83 global $conf; 84 global $lang; 85 if($format != 'xhtml') return false; 86 87 88 $opts = array( 89 'depth' => $data['depth'], 90 'listfiles' => true, 91 'listdirs' => false, 92 'pagesonly' => true, 93 'meta' => true 94 ); 95 96 // read the directory 97 $result = array(); 98 search($result,$conf['datadir'],'search_universal',$opts,$data['dir']); 99 100 if($data['dsort']){ 101 usort($result,array($this,'_sort_date')); 102 }else{ 103 usort($result,array($this,'_sort_page')); 104 } 105 106 $R->listu_open(); 107 foreach($result as $item){ 108 $R->listitem_open(1); 109 $R->listcontent_open(); 110 $R->internallink(':'.$item['id']); 111 if($data['date']) $R->cdata(' '.dformat($item['mtime'])); 112 113 $R->listcontent_close(); 114 $R->listitem_close(); 115 } 116 $R->listu_close(); 117 118 return true; 119 } 120 121 function _sort_page($a,$b){ 122 return strcmp($a['id'],$b['id']); 123 } 124 125 function _sort_date($a,$b){ 126 if($b['mtime'] < $a['mtime']){ 127 return -1; 128 }elseif($b['mtime'] > $a['mtime']){ 129 return 1; 130 }else{ 131 return strcmp($a['id'],$b['id']); 132 } 133 } 134 135} 136 137//Setup VIM: ex: et ts=4 enc=utf-8 : 138