1c112d578Sandi<?php 2c112d578Sandi/** 3c112d578Sandi * Utilities for collecting data from config files 4c112d578Sandi * 5c112d578Sandi * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6c112d578Sandi * @author Harry Fuecks <hfuecks@gmail.com> 7c112d578Sandi * @author Andreas Gohr <andi@splitbrain.org> 8c112d578Sandi */ 9c112d578Sandi 10c112d578Sandi if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); 11c112d578Sandi 12c112d578Sandi require_once(DOKU_INC.'inc/confutils.php'); 13c112d578Sandi require_once(DOKU_INC.'inc/pageutils.php'); 14ee20e7d1Sandi require_once(DOKU_INC.'inc/pluginutils.php'); 154b5f4f4eSchris require_once(DOKU_INC.'inc/cache.php'); 16c112d578Sandi 17c112d578Sandi/** 18c112d578Sandi * Returns the parsed Wikitext in XHTML for the given id and revision. 19c112d578Sandi * 20c112d578Sandi * If $excuse is true an explanation is returned if the file 21c112d578Sandi * wasn't found 22c112d578Sandi * 23c112d578Sandi * @author Andreas Gohr <andi@splitbrain.org> 24c112d578Sandi */ 25c112d578Sandifunction p_wiki_xhtml($id, $rev='', $excuse=true){ 26c112d578Sandi $file = wikiFN($id,$rev); 27c112d578Sandi $ret = ''; 28c112d578Sandi 29c112d578Sandi //ensure $id is in global $ID (needed for parsing) 301e76272cSandi global $ID; 313ff8773bSAndreas Gohr $keep = $ID; 321e76272cSandi $ID = $id; 33c112d578Sandi 34c112d578Sandi if($rev){ 35c112d578Sandi if(@file_exists($file)){ 369dc2c2afSandi $ret = p_render('xhtml',p_get_instructions(io_readfile($file)),$info); //no caching on old revisions 37c112d578Sandi }elseif($excuse){ 38c112d578Sandi $ret = p_locale_xhtml('norev'); 39c112d578Sandi } 40c112d578Sandi }else{ 41c112d578Sandi if(@file_exists($file)){ 424b5f4f4eSchris $ret = p_cached_output($file,'xhtml',$id); 43c112d578Sandi }elseif($excuse){ 44c112d578Sandi $ret = p_locale_xhtml('newpage'); 45c112d578Sandi } 46c112d578Sandi } 47c112d578Sandi 483ff8773bSAndreas Gohr //restore ID (just in case) 493ff8773bSAndreas Gohr $ID = $keep; 503ff8773bSAndreas Gohr 51c112d578Sandi return $ret; 52c112d578Sandi} 53c112d578Sandi 54c112d578Sandi/** 556b7b33dcShfuecks * Returns starting summary for a page (e.g. the first few 566b7b33dcShfuecks * paragraphs), marked up in XHTML. 576b7b33dcShfuecks * 586b7b33dcShfuecks * If $excuse is true an explanation is returned if the file 596b7b33dcShfuecks * wasn't found 606b7b33dcShfuecks * 616b7b33dcShfuecks * @param string wiki page id 626b7b33dcShfuecks * @param reference populated with page title from heading or page id 638716966dSAndreas Gohr * @deprecated 648716966dSAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com> 656b7b33dcShfuecks */ 666b7b33dcShfuecksfunction p_wiki_xhtml_summary($id, &$title, $rev='', $excuse=true){ 676b7b33dcShfuecks $file = wikiFN($id,$rev); 686b7b33dcShfuecks $ret = ''; 696b7b33dcShfuecks 706b7b33dcShfuecks //ensure $id is in global $ID (needed for parsing) 716b7b33dcShfuecks global $ID; 726b7b33dcShfuecks $keep = $ID; 736b7b33dcShfuecks $ID = $id; 746b7b33dcShfuecks 756b7b33dcShfuecks if($rev){ 766b7b33dcShfuecks if(@file_exists($file)){ 776b7b33dcShfuecks //no caching on old revisions 786b7b33dcShfuecks $ins = p_get_instructions(io_readfile($file)); 796b7b33dcShfuecks }elseif($excuse){ 806b7b33dcShfuecks $ret = p_locale_xhtml('norev'); 816b7b33dcShfuecks //restore ID (just in case) 826b7b33dcShfuecks $ID = $keep; 836b7b33dcShfuecks return $ret; 846b7b33dcShfuecks } 856b7b33dcShfuecks 866b7b33dcShfuecks }else{ 876b7b33dcShfuecks 886b7b33dcShfuecks if(@file_exists($file)){ 896b7b33dcShfuecks // The XHTML for a summary is not cached so use the instruction cache 906b7b33dcShfuecks $ins = p_cached_instructions($file); 916b7b33dcShfuecks }elseif($excuse){ 926b7b33dcShfuecks $ret = p_locale_xhtml('newpage'); 936b7b33dcShfuecks //restore ID (just in case) 946b7b33dcShfuecks $ID = $keep; 956b7b33dcShfuecks return $ret; 966b7b33dcShfuecks } 976b7b33dcShfuecks } 986b7b33dcShfuecks 996b7b33dcShfuecks $ret = p_render('xhtmlsummary',$ins,$info); 1006b7b33dcShfuecks 1016b7b33dcShfuecks if ( $info['sum_pagetitle'] ) { 1026b7b33dcShfuecks $title = $info['sum_pagetitle']; 1036b7b33dcShfuecks } else { 1046b7b33dcShfuecks $title = $id; 1056b7b33dcShfuecks } 1066b7b33dcShfuecks 1076b7b33dcShfuecks $ID = $keep; 1086b7b33dcShfuecks return $ret; 1096b7b33dcShfuecks} 1106b7b33dcShfuecks 1116b7b33dcShfuecks/** 112c112d578Sandi * Returns the specified local text in parsed format 113c112d578Sandi * 114c112d578Sandi * @author Andreas Gohr <andi@splitbrain.org> 115c112d578Sandi */ 116c112d578Sandifunction p_locale_xhtml($id){ 117c112d578Sandi //fetch parsed locale 1184b5f4f4eSchris $html = p_cached_output(localeFN($id)); 119c112d578Sandi return $html; 120c112d578Sandi} 121c112d578Sandi 122c112d578Sandi/** 1234b5f4f4eSchris * *** DEPRECATED *** 1244b5f4f4eSchris * 1254b5f4f4eSchris * use p_cached_output() 1264b5f4f4eSchris * 127c112d578Sandi * Returns the given file parsed to XHTML 128c112d578Sandi * 129c112d578Sandi * Uses and creates a cachefile 130c112d578Sandi * 1314b5f4f4eSchris * @deprecated 132c112d578Sandi * @author Andreas Gohr <andi@splitbrain.org> 1339dc2c2afSandi * @todo rewrite to use mode instead of hardcoded XHTML 134c112d578Sandi */ 135c112d578Sandifunction p_cached_xhtml($file){ 1364b5f4f4eSchris return p_cached_output($file); 1374b5f4f4eSchris} 1384b5f4f4eSchris 1394b5f4f4eSchris/** 1404b5f4f4eSchris * Returns the given file parsed into the requested output format 1414b5f4f4eSchris * 1424b5f4f4eSchris * @author Andreas Gohr <andi@splitbrain.org> 1434b5f4f4eSchris * @author Chris Smith <chris@jalakai.co.uk> 1444b5f4f4eSchris */ 1454b5f4f4eSchrisfunction p_cached_output($file, $format='xhtml', $id='') { 146c112d578Sandi global $conf; 147c112d578Sandi 1484b5f4f4eSchris $cache = new cache_renderer($id, $file, $format); 1494b5f4f4eSchris if ($cache->useCache()) { 1504b5f4f4eSchris $parsed = $cache->retrieveCache(); 1514b5f4f4eSchris if($conf['allowdebug']) $parsed .= "\n<!-- cachefile {$cache->cache} used -->\n"; 152c112d578Sandi } else { 1534b5f4f4eSchris $parsed = p_render($format, p_cached_instructions($file,false,$id), $info); 154c112d578Sandi 1559dc2c2afSandi if ($info['cache']) { 1564b5f4f4eSchris $cache->storeCache($parsed); //save cachefile 157f42d1c75SAndreas Gohr if($conf['allowdebug']) $parsed .= "\n<!-- no cachefile used, but created -->\n"; 158c112d578Sandi }else{ 1594b5f4f4eSchris $cache->removeCache(); //try to delete cachefile 160f42d1c75SAndreas Gohr if($conf['allowdebug']) $parsed .= "\n<!-- no cachefile used, caching forbidden -->\n"; 161c112d578Sandi } 162c112d578Sandi } 163c112d578Sandi 164c112d578Sandi return $parsed; 165c112d578Sandi} 166c112d578Sandi 167c112d578Sandi/** 168c112d578Sandi * Returns the render instructions for a file 169c112d578Sandi * 170c112d578Sandi * Uses and creates a serialized cache file 171c112d578Sandi * 172c112d578Sandi * @author Andreas Gohr <andi@splitbrain.org> 173c112d578Sandi */ 1744b5f4f4eSchrisfunction p_cached_instructions($file,$cacheonly=false,$id='') { 175c112d578Sandi global $conf; 176c112d578Sandi 1774b5f4f4eSchris $cache = new cache_instructions($id, $file); 178c112d578Sandi 1794b5f4f4eSchris if ($cacheonly || $cache->useCache()) { 1804b5f4f4eSchris return $cache->retrieveCache(); 181c112d578Sandi } else if (@file_exists($file)) { 182c112d578Sandi // no cache - do some work 1836bbae538Sandi $ins = p_get_instructions(io_readfile($file)); 1844b5f4f4eSchris $cache->storeCache($ins); 185c112d578Sandi return $ins; 186c112d578Sandi } 187c112d578Sandi 188c112d578Sandi return NULL; 189c112d578Sandi} 190c112d578Sandi 191c112d578Sandi/** 192c112d578Sandi * turns a page into a list of instructions 193c112d578Sandi * 194c112d578Sandi * @author Harry Fuecks <hfuecks@gmail.com> 195c112d578Sandi * @author Andreas Gohr <andi@splitbrain.org> 196c112d578Sandi */ 1976bbae538Sandifunction p_get_instructions($text){ 198c112d578Sandi 199107b01d6Sandi $modes = p_get_parsermodes(); 200ee20e7d1Sandi 201c112d578Sandi // Create the parser 202c112d578Sandi $Parser = & new Doku_Parser(); 203c112d578Sandi 204c112d578Sandi // Add the Handler 205c112d578Sandi $Parser->Handler = & new Doku_Handler(); 206c112d578Sandi 207107b01d6Sandi //add modes to parser 208107b01d6Sandi foreach($modes as $mode){ 209107b01d6Sandi $Parser->addMode($mode['mode'],$mode['obj']); 210c112d578Sandi } 211c112d578Sandi 212c112d578Sandi // Do the parsing 213677844afSchris trigger_event('PARSER_WIKITEXT_PREPROCESS', $text); 214a2d649c4Sandi $p = $Parser->parse($text); 215ee20e7d1Sandi// dbg($p); 216a2d649c4Sandi return $p; 217c112d578Sandi} 218c112d578Sandi 219c112d578Sandi/** 22039a89382SEsther Brunner * returns the metadata of a page 22139a89382SEsther Brunner * 22239a89382SEsther Brunner * @author Esther Brunner <esther@kaffeehaus.ch> 22339a89382SEsther Brunner */ 22439a89382SEsther Brunnerfunction p_get_metadata($id, $key=false, $render=false){ 2256afe8dcaSchris global $INFO; 2266afe8dcaSchris 2276afe8dcaSchris if ($id == $INFO['id'] && !empty($INFO['meta'])) { 2286afe8dcaSchris $meta = $INFO['meta']; 2296afe8dcaSchris } else { 23039a89382SEsther Brunner $file = metaFN($id, '.meta'); 23139a89382SEsther Brunner 23239a89382SEsther Brunner if (@file_exists($file)) $meta = unserialize(io_readFile($file, false)); 23339a89382SEsther Brunner else $meta = array(); 23439a89382SEsther Brunner 23539a89382SEsther Brunner // metadata has never been rendered before - do it! 23639a89382SEsther Brunner if ($render && !$meta['description']['abstract']){ 23739a89382SEsther Brunner $meta = p_render_metadata($id, $meta); 23839a89382SEsther Brunner io_saveFile($file, serialize($meta)); 23939a89382SEsther Brunner } 2406afe8dcaSchris } 24139a89382SEsther Brunner 24239a89382SEsther Brunner // filter by $key 24339a89382SEsther Brunner if ($key){ 24439a89382SEsther Brunner list($key, $subkey) = explode(' ', $key, 2); 24539a89382SEsther Brunner if (trim($subkey)) return $meta[$key][$subkey]; 24639a89382SEsther Brunner else return $meta[$key]; 24739a89382SEsther Brunner } 24839a89382SEsther Brunner 24939a89382SEsther Brunner return $meta; 25039a89382SEsther Brunner} 25139a89382SEsther Brunner 25239a89382SEsther Brunner/** 25339a89382SEsther Brunner * sets metadata elements of a page 25439a89382SEsther Brunner * 25539a89382SEsther Brunner * @author Esther Brunner <esther@kaffeehaus.ch> 25639a89382SEsther Brunner */ 25739a89382SEsther Brunnerfunction p_set_metadata($id, $data, $render=false){ 25839a89382SEsther Brunner if (!is_array($data)) return false; 25939a89382SEsther Brunner 26039a89382SEsther Brunner $orig = p_get_metadata($id); 26139a89382SEsther Brunner 26239a89382SEsther Brunner // render metadata first? 26339a89382SEsther Brunner if ($render) $meta = p_render_metadata($id, $orig); 26439a89382SEsther Brunner else $meta = $orig; 26539a89382SEsther Brunner 26639a89382SEsther Brunner // now add the passed metadata 26739a89382SEsther Brunner $protected = array('description', 'date', 'contributor'); 26839a89382SEsther Brunner foreach ($data as $key => $value){ 26939a89382SEsther Brunner 27039a89382SEsther Brunner // be careful with sub-arrays of $meta['relation'] 27139a89382SEsther Brunner if ($key == 'relation'){ 27239a89382SEsther Brunner foreach ($value as $subkey => $subvalue){ 27339a89382SEsther Brunner $meta[$key][$subkey] = array_merge($meta[$key][$subkey], $subvalue); 27439a89382SEsther Brunner } 27539a89382SEsther Brunner 27639a89382SEsther Brunner // be careful with some senisitive arrays of $meta 27739a89382SEsther Brunner } elseif (in_array($key, $protected)){ 27839a89382SEsther Brunner if (is_array($value)){ 27995dbfe57SAndreas Gohr #FIXME not sure if this is the intended thing: 28095dbfe57SAndreas Gohr if(!is_array($meta[$key])) $meta[$key] = array($meta[$key]); 28139a89382SEsther Brunner $meta[$key] = array_merge($meta[$key], $value); 28239a89382SEsther Brunner } 28339a89382SEsther Brunner 28439a89382SEsther Brunner // no special treatment for the rest 28539a89382SEsther Brunner } else { 28639a89382SEsther Brunner $meta[$key] = $value; 28739a89382SEsther Brunner } 28839a89382SEsther Brunner } 28939a89382SEsther Brunner 29039a89382SEsther Brunner // save only if metadata changed 29139a89382SEsther Brunner if ($meta == $orig) return true; 2926afe8dcaSchris 2936afe8dcaSchris // check if current page metadata has been altered - if so sync the changes 2946afe8dcaSchris global $INFO; 2956afe8dcaSchris if ($id == $INFO['id'] && isset($INFO['meta'])) { 2966afe8dcaSchris $INFO['meta'] = $meta; 2976afe8dcaSchris } 2986afe8dcaSchris 29939a89382SEsther Brunner return io_saveFile(metaFN($id, '.meta'), serialize($meta)); 30039a89382SEsther Brunner} 30139a89382SEsther Brunner 30239a89382SEsther Brunner/** 30339a89382SEsther Brunner * renders the metadata of a page 30439a89382SEsther Brunner * 30539a89382SEsther Brunner * @author Esther Brunner <esther@kaffeehaus.ch> 30639a89382SEsther Brunner */ 30739a89382SEsther Brunnerfunction p_render_metadata($id, $orig){ 30839a89382SEsther Brunner require_once DOKU_INC."inc/parser/metadata.php"; 30939a89382SEsther Brunner 31039a89382SEsther Brunner // get instructions 3114b5f4f4eSchris $instructions = p_cached_instructions(wikiFN($id),false,$id); 31239a89382SEsther Brunner 31339a89382SEsther Brunner // set up the renderer 31439a89382SEsther Brunner $renderer = & new Doku_Renderer_metadata(); 31539a89382SEsther Brunner $renderer->meta = $orig; 31639a89382SEsther Brunner 31739a89382SEsther Brunner // loop through the instructions 31839a89382SEsther Brunner foreach ($instructions as $instruction){ 31939a89382SEsther Brunner // execute the callback against the renderer 32039a89382SEsther Brunner call_user_func_array(array(&$renderer, $instruction[0]), $instruction[1]); 32139a89382SEsther Brunner } 32239a89382SEsther Brunner 32339a89382SEsther Brunner return $renderer->meta; 32439a89382SEsther Brunner} 32539a89382SEsther Brunner 32639a89382SEsther Brunner/** 327107b01d6Sandi * returns all available parser syntax modes in correct order 328107b01d6Sandi * 329107b01d6Sandi * @author Andreas Gohr <andi@splitbrain.org> 330107b01d6Sandi */ 331107b01d6Sandifunction p_get_parsermodes(){ 332107b01d6Sandi global $conf; 333107b01d6Sandi 334107b01d6Sandi //reuse old data 335107b01d6Sandi static $modes = null; 336107b01d6Sandi if($modes != null){ 337107b01d6Sandi return $modes; 338107b01d6Sandi } 339107b01d6Sandi 340107b01d6Sandi //import parser classes and mode definitions 341107b01d6Sandi require_once DOKU_INC . 'inc/parser/parser.php'; 342107b01d6Sandi 343107b01d6Sandi // we now collect all syntax modes and their objects, then they will 344107b01d6Sandi // be sorted and added to the parser in correct order 345107b01d6Sandi $modes = array(); 346107b01d6Sandi 347107b01d6Sandi // add syntax plugins 348107b01d6Sandi $pluginlist = plugin_list('syntax'); 349107b01d6Sandi if(count($pluginlist)){ 350107b01d6Sandi global $PARSER_MODES; 351107b01d6Sandi $obj = null; 352107b01d6Sandi foreach($pluginlist as $p){ 353c90b2fb1Schris if(!$obj =& plugin_load('syntax',$p)) continue; //attempt to load plugin into $obj 354107b01d6Sandi $PARSER_MODES[$obj->getType()][] = "plugin_$p"; //register mode type 355107b01d6Sandi //add to modes 356107b01d6Sandi $modes[] = array( 357107b01d6Sandi 'sort' => $obj->getSort(), 358107b01d6Sandi 'mode' => "plugin_$p", 359107b01d6Sandi 'obj' => $obj, 360107b01d6Sandi ); 361a46d0d65SAndreas Gohr unset($obj); //remove the reference 362107b01d6Sandi } 363107b01d6Sandi } 364107b01d6Sandi 365107b01d6Sandi // add default modes 366107b01d6Sandi $std_modes = array('listblock','preformatted','notoc','nocache', 367107b01d6Sandi 'header','table','linebreak','footnote','hr', 368107b01d6Sandi 'unformatted','php','html','code','file','quote', 369e77ea1bcSAndreas Gohr 'internallink','rss','media','externallink', 370e77ea1bcSAndreas Gohr 'emaillink','windowssharelink','eol'); 371e77ea1bcSAndreas Gohr if($conf['typography']){ 372e77ea1bcSAndreas Gohr $std_modes[] = 'quotes'; 373e77ea1bcSAndreas Gohr $std_modes[] = 'multiplyentity'; 374e77ea1bcSAndreas Gohr } 375107b01d6Sandi foreach($std_modes as $m){ 376107b01d6Sandi $class = "Doku_Parser_Mode_$m"; 377107b01d6Sandi $obj = new $class(); 378107b01d6Sandi $modes[] = array( 379107b01d6Sandi 'sort' => $obj->getSort(), 380107b01d6Sandi 'mode' => $m, 381107b01d6Sandi 'obj' => $obj 382107b01d6Sandi ); 383107b01d6Sandi } 384107b01d6Sandi 385107b01d6Sandi // add formatting modes 386107b01d6Sandi $fmt_modes = array('strong','emphasis','underline','monospace', 387107b01d6Sandi 'subscript','superscript','deleted'); 388107b01d6Sandi foreach($fmt_modes as $m){ 389107b01d6Sandi $obj = new Doku_Parser_Mode_formatting($m); 390107b01d6Sandi $modes[] = array( 391107b01d6Sandi 'sort' => $obj->getSort(), 392107b01d6Sandi 'mode' => $m, 393107b01d6Sandi 'obj' => $obj 394107b01d6Sandi ); 395107b01d6Sandi } 396107b01d6Sandi 397107b01d6Sandi // add modes which need files 398107b01d6Sandi $obj = new Doku_Parser_Mode_smiley(array_keys(getSmileys())); 399107b01d6Sandi $modes[] = array('sort' => $obj->getSort(), 'mode' => 'smiley','obj' => $obj ); 400107b01d6Sandi $obj = new Doku_Parser_Mode_acronym(array_keys(getAcronyms())); 401107b01d6Sandi $modes[] = array('sort' => $obj->getSort(), 'mode' => 'acronym','obj' => $obj ); 402107b01d6Sandi $obj = new Doku_Parser_Mode_entity(array_keys(getEntities())); 403107b01d6Sandi $modes[] = array('sort' => $obj->getSort(), 'mode' => 'entity','obj' => $obj ); 404107b01d6Sandi 405107b01d6Sandi 406107b01d6Sandi // add optional camelcase mode 407107b01d6Sandi if($conf['camelcase']){ 408107b01d6Sandi $obj = new Doku_Parser_Mode_camelcaselink(); 409107b01d6Sandi $modes[] = array('sort' => $obj->getSort(), 'mode' => 'camelcaselink','obj' => $obj ); 410107b01d6Sandi } 411107b01d6Sandi 412107b01d6Sandi //sort modes 413107b01d6Sandi usort($modes,'p_sort_modes'); 414107b01d6Sandi 415107b01d6Sandi return $modes; 416107b01d6Sandi} 417107b01d6Sandi 418107b01d6Sandi/** 419107b01d6Sandi * Callback function for usort 420107b01d6Sandi * 421107b01d6Sandi * @author Andreas Gohr <andi@splitbrain.org> 422107b01d6Sandi */ 423107b01d6Sandifunction p_sort_modes($a, $b){ 424107b01d6Sandi if($a['sort'] == $b['sort']) return 0; 425107b01d6Sandi return ($a['sort'] < $b['sort']) ? -1 : 1; 426107b01d6Sandi} 427107b01d6Sandi 428107b01d6Sandi/** 429ac83b9d8Sandi * Renders a list of instruction to the specified output mode 430c112d578Sandi * 4319dc2c2afSandi * In the $info array are informations from the renderer returned 4329dc2c2afSandi * 433c112d578Sandi * @author Harry Fuecks <hfuecks@gmail.com> 434c112d578Sandi * @author Andreas Gohr <andi@splitbrain.org> 435c112d578Sandi */ 4369dc2c2afSandifunction p_render($mode,$instructions,& $info){ 437c112d578Sandi if(is_null($instructions)) return ''; 438c112d578Sandi 439c19c9173SBen Coburn if ($mode=='wiki') { msg("Renderer for $mode not valid",-1); return null; } //FIXME!! remove this line when inc/parser/wiki.php works. 440c19c9173SBen Coburn 441c112d578Sandi // Create the renderer 442ac83b9d8Sandi if(!@file_exists(DOKU_INC."inc/parser/$mode.php")){ 443ac83b9d8Sandi msg("No renderer for $mode found",-1); 444ac83b9d8Sandi return null; 445ac83b9d8Sandi } 446ac83b9d8Sandi 447ac83b9d8Sandi require_once DOKU_INC."inc/parser/$mode.php"; 448ac83b9d8Sandi $rclass = "Doku_Renderer_$mode"; 4496b7b33dcShfuecks if ( !class_exists($rclass) ) { 450c19c9173SBen Coburn trigger_error("Unable to resolve render class $rclass",E_USER_WARNING); 451c19c9173SBen Coburn msg("Renderer for $mode not valid",-1); 452c19c9173SBen Coburn return null; 4536b7b33dcShfuecks } 454ac83b9d8Sandi $Renderer = & new $rclass(); #FIXME any way to check for class existance? 455c112d578Sandi 456c112d578Sandi $Renderer->smileys = getSmileys(); 457c112d578Sandi $Renderer->entities = getEntities(); 458c112d578Sandi $Renderer->acronyms = getAcronyms(); 459c112d578Sandi $Renderer->interwiki = getInterwiki(); 460c112d578Sandi #$Renderer->badwords = getBadWords(); 461c112d578Sandi 462c112d578Sandi // Loop through the instructions 463c112d578Sandi foreach ( $instructions as $instruction ) { 464c112d578Sandi // Execute the callback against the Renderer 465c112d578Sandi call_user_func_array(array(&$Renderer, $instruction[0]),$instruction[1]); 466c112d578Sandi } 4679dc2c2afSandi 4689dc2c2afSandi //set info array 4699dc2c2afSandi $info = $Renderer->info; 4709dc2c2afSandi 471677844afSchris // Post process and return the output 472677844afSchris $data = array($mode,& $Renderer->doc); 473677844afSchris trigger_event('RENDERER_CONTENT_POSTPROCESS',$data); 474c112d578Sandi return $Renderer->doc; 475c112d578Sandi} 476c112d578Sandi 477bb0a59d4Sjan/** 478bb0a59d4Sjan * Gets the first heading from a file 479bb0a59d4Sjan * 48095dbfe57SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 481bb0a59d4Sjan */ 482bb0a59d4Sjanfunction p_get_first_heading($id){ 483796bafb3SAndreas Gohr global $conf; 48444a35da6Schris return $conf['useheading'] ? p_get_metadata($id,'title') : null; 485bb0a59d4Sjan} 486bb0a59d4Sjan 4878f7d700cSchris/** 4888f7d700cSchris * Wrapper for GeSHi Code Highlighter, provides caching of its output 4898f7d700cSchris * 4908f7d700cSchris * @author Christopher Smith <chris@jalakai.co.uk> 4918f7d700cSchris */ 4928f7d700cSchrisfunction p_xhtml_cached_geshi($code, $language) { 4938f7d700cSchris $cache = getCacheName($language.$code,".code"); 4948f7d700cSchris 495*8cfffb85Schris if (@file_exists($cache) && !$_REQUEST['purge'] && 496*8cfffb85Schris (filemtime($cache) > filemtime(DOKU_INC . 'inc/geshi.php'))) { 4978f7d700cSchris 4988f7d700cSchris $highlighted_code = io_readFile($cache, false); 499852896daSAndreas Gohr @touch($cache); 5008f7d700cSchris 5018f7d700cSchris } else { 5028f7d700cSchris 5038f7d700cSchris require_once(DOKU_INC . 'inc/geshi.php'); 5048f7d700cSchris 5058f7d700cSchris $geshi = new GeSHi($code, strtolower($language), DOKU_INC . 'inc/geshi'); 5068f7d700cSchris $geshi->set_encoding('utf-8'); 5078f7d700cSchris $geshi->enable_classes(); 5088f7d700cSchris $geshi->set_header_type(GESHI_HEADER_PRE); 5098f7d700cSchris $geshi->set_overall_class("code $language"); 5108f7d700cSchris $geshi->set_link_target($conf['target']['extern']); 5118f7d700cSchris 5128f7d700cSchris $highlighted_code = $geshi->parse_code(); 5138f7d700cSchris 5148f7d700cSchris io_saveFile($cache,$highlighted_code); 5158f7d700cSchris } 5168f7d700cSchris 5178f7d700cSchris return $highlighted_code; 5188f7d700cSchris} 5198f7d700cSchris 520c112d578Sandi//Setup VIM: ex: et ts=2 enc=utf-8 : 521