From db959ae30700e3924a73350a3a43a2c36b431de7 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 20 Oct 2009 23:23:38 +0200 Subject: Coding Standard Cleanup Ignore-this: 259cb5773c3144c6c706d87298dcf674 darcs-hash:20091020212338-7ad00-6bf1c5c403491f136a1c02af5ecd9f84d7227107.gz --- inc/parserutils.php | 788 ++++++++++++++++++++++++++-------------------------- 1 file changed, 392 insertions(+), 396 deletions(-) (limited to 'inc/parserutils.php') diff --git a/inc/parserutils.php b/inc/parserutils.php index 7887e7a3e..d17ffaa43 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -22,32 +22,32 @@ require_once(DOKU_INC.'inc/cache.php'); * @author Andreas Gohr */ function p_wiki_xhtml($id, $rev='', $excuse=true){ - $file = wikiFN($id,$rev); - $ret = ''; - - //ensure $id is in global $ID (needed for parsing) - global $ID; - $keep = $ID; - $ID = $id; - - if($rev){ - if(@file_exists($file)){ - $ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev)),$info); //no caching on old revisions - }elseif($excuse){ - $ret = p_locale_xhtml('norev'); - } - }else{ - if(@file_exists($file)){ - $ret = p_cached_output($file,'xhtml',$id); - }elseif($excuse){ - $ret = p_locale_xhtml('newpage'); + $file = wikiFN($id,$rev); + $ret = ''; + + //ensure $id is in global $ID (needed for parsing) + global $ID; + $keep = $ID; + $ID = $id; + + if($rev){ + if(@file_exists($file)){ + $ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev)),$info); //no caching on old revisions + }elseif($excuse){ + $ret = p_locale_xhtml('norev'); + } + }else{ + if(@file_exists($file)){ + $ret = p_cached_output($file,'xhtml',$id); + }elseif($excuse){ + $ret = p_locale_xhtml('newpage'); + } } - } - //restore ID (just in case) - $ID = $keep; + //restore ID (just in case) + $ID = $keep; - return $ret; + return $ret; } /** @@ -63,48 +63,48 @@ function p_wiki_xhtml($id, $rev='', $excuse=true){ * @author Harry Fuecks */ function p_wiki_xhtml_summary($id, &$title, $rev='', $excuse=true){ - $file = wikiFN($id,$rev); - $ret = ''; + $file = wikiFN($id,$rev); + $ret = ''; + + //ensure $id is in global $ID (needed for parsing) + global $ID; + $keep = $ID; + $ID = $id; + + if($rev){ + if(@file_exists($file)){ + //no caching on old revisions + $ins = p_get_instructions(io_readWikiPage($file,$id,$rev)); + }elseif($excuse){ + $ret = p_locale_xhtml('norev'); + //restore ID (just in case) + $ID = $keep; + return $ret; + } - //ensure $id is in global $ID (needed for parsing) - global $ID; - $keep = $ID; - $ID = $id; + }else{ - if($rev){ - if(@file_exists($file)){ - //no caching on old revisions - $ins = p_get_instructions(io_readWikiPage($file,$id,$rev)); - }elseif($excuse){ - $ret = p_locale_xhtml('norev'); - //restore ID (just in case) - $ID = $keep; - return $ret; + if(@file_exists($file)){ + // The XHTML for a summary is not cached so use the instruction cache + $ins = p_cached_instructions($file); + }elseif($excuse){ + $ret = p_locale_xhtml('newpage'); + //restore ID (just in case) + $ID = $keep; + return $ret; + } } - }else{ + $ret = p_render('xhtmlsummary',$ins,$info); - if(@file_exists($file)){ - // The XHTML for a summary is not cached so use the instruction cache - $ins = p_cached_instructions($file); - }elseif($excuse){ - $ret = p_locale_xhtml('newpage'); - //restore ID (just in case) - $ID = $keep; - return $ret; + if ( $info['sum_pagetitle'] ) { + $title = $info['sum_pagetitle']; + } else { + $title = $id; } - } - - $ret = p_render('xhtmlsummary',$ins,$info); - - if ( $info['sum_pagetitle'] ) { - $title = $info['sum_pagetitle']; - } else { - $title = $id; - } - $ID = $keep; - return $ret; + $ID = $keep; + return $ret; } /** @@ -113,9 +113,9 @@ function p_wiki_xhtml_summary($id, &$title, $rev='', $excuse=true){ * @author Andreas Gohr */ function p_locale_xhtml($id){ - //fetch parsed locale - $html = p_cached_output(localeFN($id)); - return $html; + //fetch parsed locale + $html = p_cached_output(localeFN($id)); + return $html; } /** @@ -132,7 +132,7 @@ function p_locale_xhtml($id){ * @todo rewrite to use mode instead of hardcoded XHTML */ function p_cached_xhtml($file){ - return p_cached_output($file); + return p_cached_output($file); } /** @@ -142,25 +142,25 @@ function p_cached_xhtml($file){ * @author Chris Smith */ function p_cached_output($file, $format='xhtml', $id='') { - global $conf; - - $cache = new cache_renderer($id, $file, $format); - if ($cache->useCache()) { - $parsed = $cache->retrieveCache(false); - if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n\n"; - } else { - $parsed = p_render($format, p_cached_instructions($file,false,$id), $info); - - if ($info['cache']) { - $cache->storeCache($parsed); //save cachefile - if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n\n"; - }else{ - $cache->removeCache(); //try to delete cachefile - if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n\n"; + global $conf; + + $cache = new cache_renderer($id, $file, $format); + if ($cache->useCache()) { + $parsed = $cache->retrieveCache(false); + if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n\n"; + } else { + $parsed = p_render($format, p_cached_instructions($file,false,$id), $info); + + if ($info['cache']) { + $cache->storeCache($parsed); //save cachefile + if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n\n"; + }else{ + $cache->removeCache(); //try to delete cachefile + if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n\n"; + } } - } - return $parsed; + return $parsed; } /** @@ -171,26 +171,26 @@ function p_cached_output($file, $format='xhtml', $id='') { * @author Andreas Gohr */ function p_cached_instructions($file,$cacheonly=false,$id='') { - global $conf; - static $run = null; - if(is_null($run)) $run = array(); - - $cache = new cache_instructions($id, $file); - - if ($cacheonly || $cache->useCache() || isset($run[$file])) { - return $cache->retrieveCache(); - } else if (@file_exists($file)) { - // no cache - do some work - $ins = p_get_instructions(io_readWikiPage($file,$id)); - if ($cache->storeCache($ins)) { - $run[$file] = true; // we won't rebuild these instructions in the same run again - } else { - msg('Unable to save cache file. Hint: disk full; file permissions; safe_mode setting.',-1); + global $conf; + static $run = null; + if(is_null($run)) $run = array(); + + $cache = new cache_instructions($id, $file); + + if ($cacheonly || $cache->useCache() || isset($run[$file])) { + return $cache->retrieveCache(); + } else if (@file_exists($file)) { + // no cache - do some work + $ins = p_get_instructions(io_readWikiPage($file,$id)); + if ($cache->storeCache($ins)) { + $run[$file] = true; // we won't rebuild these instructions in the same run again + } else { + msg('Unable to save cache file. Hint: disk full; file permissions; safe_mode setting.',-1); + } + return $ins; } - return $ins; - } - return null; + return null; } /** @@ -201,24 +201,24 @@ function p_cached_instructions($file,$cacheonly=false,$id='') { */ function p_get_instructions($text){ - $modes = p_get_parsermodes(); + $modes = p_get_parsermodes(); - // Create the parser - $Parser = & new Doku_Parser(); + // Create the parser + $Parser = & new Doku_Parser(); - // Add the Handler - $Parser->Handler = & new Doku_Handler(); + // Add the Handler + $Parser->Handler = & new Doku_Handler(); - //add modes to parser - foreach($modes as $mode){ - $Parser->addMode($mode['mode'],$mode['obj']); - } + //add modes to parser + foreach($modes as $mode){ + $Parser->addMode($mode['mode'],$mode['obj']); + } - // Do the parsing - trigger_event('PARSER_WIKITEXT_PREPROCESS', $text); - $p = $Parser->parse($text); -// dbg($p); - return $p; + // Do the parsing + trigger_event('PARSER_WIKITEXT_PREPROCESS', $text); + $p = $Parser->parse($text); + // dbg($p); + return $p; } /** @@ -227,37 +227,37 @@ function p_get_instructions($text){ * @author Esther Brunner */ function p_get_metadata($id, $key=false, $render=false){ - global $ID, $INFO, $cache_metadata; - - // cache the current page - // Benchmarking shows the current page's metadata is generally the only page metadata - // accessed several times. This may catch a few other pages, but that shouldn't be an issue. - $cache = ($ID == $id); - $meta = p_read_metadata($id, $cache); - - // metadata has never been rendered before - do it! (but not for non-existent pages) - if ($render && !isset($meta['current']['description']['abstract']) && page_exists($id)){ - $meta = p_render_metadata($id, $meta); - io_saveFile(metaFN($id, '.meta'), serialize($meta)); + global $ID, $INFO, $cache_metadata; + + // cache the current page + // Benchmarking shows the current page's metadata is generally the only page metadata + // accessed several times. This may catch a few other pages, but that shouldn't be an issue. + $cache = ($ID == $id); + $meta = p_read_metadata($id, $cache); + + // metadata has never been rendered before - do it! (but not for non-existent pages) + if ($render && !isset($meta['current']['description']['abstract']) && page_exists($id)){ + $meta = p_render_metadata($id, $meta); + io_saveFile(metaFN($id, '.meta'), serialize($meta)); + + // sync cached copies, including $INFO metadata + if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta; + if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; } + } - // sync cached copies, including $INFO metadata - if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta; - if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; } - } + // filter by $key + if ($key){ + list($key, $subkey) = explode(' ', $key, 2); + $subkey = trim($subkey); - // filter by $key - if ($key){ - list($key, $subkey) = explode(' ', $key, 2); - $subkey = trim($subkey); + if ($subkey) { + return isset($meta['current'][$key][$subkey]) ? $meta['current'][$key][$subkey] : null; + } - if ($subkey) { - return isset($meta['current'][$key][$subkey]) ? $meta['current'][$key][$subkey] : null; + return isset($meta['current'][$key]) ? $meta['current'][$key] : null; } - return isset($meta['current'][$key]) ? $meta['current'][$key] : null; - } - - return $meta['current']; + return $meta['current']; } /** @@ -266,59 +266,59 @@ function p_get_metadata($id, $key=false, $render=false){ * @author Esther Brunner */ function p_set_metadata($id, $data, $render=false, $persistent=true){ - if (!is_array($data)) return false; + if (!is_array($data)) return false; - global $ID; + global $ID; - // cache the current page - $cache = ($ID == $id); - $orig = p_read_metadata($id, $cache); + // cache the current page + $cache = ($ID == $id); + $orig = p_read_metadata($id, $cache); - // render metadata first? - $meta = $render ? p_render_metadata($id, $orig) : $orig; + // render metadata first? + $meta = $render ? p_render_metadata($id, $orig) : $orig; - // now add the passed metadata - $protected = array('description', 'date', 'contributor'); - foreach ($data as $key => $value){ + // now add the passed metadata + $protected = array('description', 'date', 'contributor'); + foreach ($data as $key => $value){ - // be careful with sub-arrays of $meta['relation'] - if ($key == 'relation'){ + // be careful with sub-arrays of $meta['relation'] + if ($key == 'relation'){ - foreach ($value as $subkey => $subvalue){ - $meta['current'][$key][$subkey] = !empty($meta['current'][$key][$subkey]) ? array_merge($meta['current'][$key][$subkey], $subvalue) : $subvalue; - if ($persistent) - $meta['persistent'][$key][$subkey] = !empty($meta['persistent'][$key][$subkey]) ? array_merge($meta['persistent'][$key][$subkey], $subvalue) : $subvalue; - } + foreach ($value as $subkey => $subvalue){ + $meta['current'][$key][$subkey] = !empty($meta['current'][$key][$subkey]) ? array_merge($meta['current'][$key][$subkey], $subvalue) : $subvalue; + if ($persistent) + $meta['persistent'][$key][$subkey] = !empty($meta['persistent'][$key][$subkey]) ? array_merge($meta['persistent'][$key][$subkey], $subvalue) : $subvalue; + } - // be careful with some senisitive arrays of $meta - } elseif (in_array($key, $protected)){ + // be careful with some senisitive arrays of $meta + } elseif (in_array($key, $protected)){ - // these keys, must have subkeys - a legitimate value must be an array - if (is_array($value)) { - $meta['current'][$key] = !empty($meta['current'][$key]) ? array_merge($meta['current'][$key],$value) : $value; + // these keys, must have subkeys - a legitimate value must be an array + if (is_array($value)) { + $meta['current'][$key] = !empty($meta['current'][$key]) ? array_merge($meta['current'][$key],$value) : $value; - if ($persistent) { - $meta['persistent'][$key] = !empty($meta['persistent'][$key]) ? array_merge($meta['persistent'][$key],$value) : $value; - } - } + if ($persistent) { + $meta['persistent'][$key] = !empty($meta['persistent'][$key]) ? array_merge($meta['persistent'][$key],$value) : $value; + } + } - // no special treatment for the rest - } else { - $meta['current'][$key] = $value; - if ($persistent) $meta['persistent'][$key] = $value; + // no special treatment for the rest + } else { + $meta['current'][$key] = $value; + if ($persistent) $meta['persistent'][$key] = $value; + } } - } - // save only if metadata changed - if ($meta == $orig) return true; + // save only if metadata changed + if ($meta == $orig) return true; - // sync cached copies, including $INFO metadata - global $cache_metadata, $INFO; + // sync cached copies, including $INFO metadata + global $cache_metadata, $INFO; - if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta; - if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; } + if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta; + if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; } - return io_saveFile(metaFN($id, '.meta'), serialize($meta)); + return io_saveFile(metaFN($id, '.meta'), serialize($meta)); } /** @@ -356,38 +356,38 @@ function p_purge_metadata($id) { * @return array metadata */ function p_read_metadata($id,$cache=false) { - global $cache_metadata; + global $cache_metadata; - if (isset($cache_metadata[(string)$id])) return $cache_metadata[(string)$id]; + if (isset($cache_metadata[(string)$id])) return $cache_metadata[(string)$id]; - $file = metaFN($id, '.meta'); - $meta = @file_exists($file) ? unserialize(io_readFile($file, false)) : array('current'=>array(),'persistent'=>array()); + $file = metaFN($id, '.meta'); + $meta = @file_exists($file) ? unserialize(io_readFile($file, false)) : array('current'=>array(),'persistent'=>array()); - // convert $meta from old format to new (current+persistent) format - if (!isset($meta['current'])) { - $meta = array('current'=>$meta,'persistent'=>$meta); + // convert $meta from old format to new (current+persistent) format + if (!isset($meta['current'])) { + $meta = array('current'=>$meta,'persistent'=>$meta); - // remove non-persistent keys - unset($meta['persistent']['title']); - unset($meta['persistent']['description']['abstract']); - unset($meta['persistent']['description']['tableofcontents']); - unset($meta['persistent']['relation']['haspart']); - unset($meta['persistent']['relation']['references']); - unset($meta['persistent']['date']['valid']); + // remove non-persistent keys + unset($meta['persistent']['title']); + unset($meta['persistent']['description']['abstract']); + unset($meta['persistent']['description']['tableofcontents']); + unset($meta['persistent']['relation']['haspart']); + unset($meta['persistent']['relation']['references']); + unset($meta['persistent']['date']['valid']); - if (empty($meta['persistent']['description'])) unset($meta['persistent']['description']); - if (empty($meta['persistent']['relation'])) unset($meta['persistent']['relation']); - if (empty($meta['persistent']['date'])) unset($meta['persistent']['date']); + if (empty($meta['persistent']['description'])) unset($meta['persistent']['description']); + if (empty($meta['persistent']['relation'])) unset($meta['persistent']['relation']); + if (empty($meta['persistent']['date'])) unset($meta['persistent']['date']); - // save converted metadata - io_saveFile($file, serialize($meta)); - } + // save converted metadata + io_saveFile($file, serialize($meta)); + } - if ($cache) { - $cache_metadata[(string)$id] = $meta; - } + if ($cache) { + $cache_metadata[(string)$id] = $meta; + } - return $meta; + return $meta; } /** @@ -396,43 +396,42 @@ function p_read_metadata($id,$cache=false) { * @author Esther Brunner */ function p_render_metadata($id, $orig){ - // make sure the correct ID is in global ID - global $ID; - $keep = $ID; - $ID = $id; - - - // add an extra key for the event - to tell event handlers the page whose metadata this is - $orig['page'] = $id; - $evt = new Doku_Event('PARSER_METADATA_RENDER', $orig); - if ($evt->advise_before()) { - - require_once DOKU_INC."inc/parser/metadata.php"; + // make sure the correct ID is in global ID + global $ID; + $keep = $ID; + $ID = $id; + + // add an extra key for the event - to tell event handlers the page whose metadata this is + $orig['page'] = $id; + $evt = new Doku_Event('PARSER_METADATA_RENDER', $orig); + if ($evt->advise_before()) { + + require_once DOKU_INC."inc/parser/metadata.php"; + + // get instructions + $instructions = p_cached_instructions(wikiFN($id),false,$id); + if(is_null($instructions)){ + $ID = $keep; + return null; // something went wrong with the instructions + } - // get instructions - $instructions = p_cached_instructions(wikiFN($id),false,$id); - if(is_null($instructions)){ - $ID = $keep; - return null; // something went wrong with the instructions - } + // set up the renderer + $renderer = & new Doku_Renderer_metadata(); + $renderer->meta = $orig['current']; + $renderer->persistent = $orig['persistent']; - // set up the renderer - $renderer = & new Doku_Renderer_metadata(); - $renderer->meta = $orig['current']; - $renderer->persistent = $orig['persistent']; + // loop through the instructions + foreach ($instructions as $instruction){ + // execute the callback against the renderer + call_user_func_array(array(&$renderer, $instruction[0]), $instruction[1]); + } - // loop through the instructions - foreach ($instructions as $instruction){ - // execute the callback against the renderer - call_user_func_array(array(&$renderer, $instruction[0]), $instruction[1]); + $evt->result = array('current'=>$renderer->meta,'persistent'=>$renderer->persistent); } + $evt->advise_after(); - $evt->result = array('current'=>$renderer->meta,'persistent'=>$renderer->persistent); - } - $evt->advise_after(); - - $ID = $keep; - return $evt->result; + $ID = $keep; + return $evt->result; } /** @@ -441,90 +440,89 @@ function p_render_metadata($id, $orig){ * @author Andreas Gohr */ function p_get_parsermodes(){ - global $conf; + global $conf; - //reuse old data - static $modes = null; - if($modes != null){ - return $modes; - } - - //import parser classes and mode definitions - require_once DOKU_INC . 'inc/parser/parser.php'; - - // we now collect all syntax modes and their objects, then they will - // be sorted and added to the parser in correct order - $modes = array(); - - // add syntax plugins - $pluginlist = plugin_list('syntax'); - if(count($pluginlist)){ - global $PARSER_MODES; - $obj = null; - foreach($pluginlist as $p){ - if(!$obj =& plugin_load('syntax',$p)) continue; //attempt to load plugin into $obj - $PARSER_MODES[$obj->getType()][] = "plugin_$p"; //register mode type - //add to modes - $modes[] = array( - 'sort' => $obj->getSort(), - 'mode' => "plugin_$p", - 'obj' => $obj, - ); - unset($obj); //remove the reference + //reuse old data + static $modes = null; + if($modes != null){ + return $modes; } - } - - // add default modes - $std_modes = array('listblock','preformatted','notoc','nocache', - 'header','table','linebreak','footnote','hr', - 'unformatted','php','html','code','file','quote', - 'internallink','rss','media','externallink', - 'emaillink','windowssharelink','eol'); - if($conf['typography']){ - $std_modes[] = 'quotes'; - $std_modes[] = 'multiplyentity'; - } - foreach($std_modes as $m){ - $class = "Doku_Parser_Mode_$m"; - $obj = new $class(); - $modes[] = array( - 'sort' => $obj->getSort(), - 'mode' => $m, - 'obj' => $obj - ); - } - - // add formatting modes - $fmt_modes = array('strong','emphasis','underline','monospace', - 'subscript','superscript','deleted'); - foreach($fmt_modes as $m){ - $obj = new Doku_Parser_Mode_formatting($m); - $modes[] = array( - 'sort' => $obj->getSort(), - 'mode' => $m, - 'obj' => $obj - ); - } - - // add modes which need files - $obj = new Doku_Parser_Mode_smiley(array_keys(getSmileys())); - $modes[] = array('sort' => $obj->getSort(), 'mode' => 'smiley','obj' => $obj ); - $obj = new Doku_Parser_Mode_acronym(array_keys(getAcronyms())); - $modes[] = array('sort' => $obj->getSort(), 'mode' => 'acronym','obj' => $obj ); - $obj = new Doku_Parser_Mode_entity(array_keys(getEntities())); - $modes[] = array('sort' => $obj->getSort(), 'mode' => 'entity','obj' => $obj ); - - - // add optional camelcase mode - if($conf['camelcase']){ - $obj = new Doku_Parser_Mode_camelcaselink(); - $modes[] = array('sort' => $obj->getSort(), 'mode' => 'camelcaselink','obj' => $obj ); - } - - //sort modes - usort($modes,'p_sort_modes'); - - return $modes; + + //import parser classes and mode definitions + require_once DOKU_INC . 'inc/parser/parser.php'; + + // we now collect all syntax modes and their objects, then they will + // be sorted and added to the parser in correct order + $modes = array(); + + // add syntax plugins + $pluginlist = plugin_list('syntax'); + if(count($pluginlist)){ + global $PARSER_MODES; + $obj = null; + foreach($pluginlist as $p){ + if(!$obj =& plugin_load('syntax',$p)) continue; //attempt to load plugin into $obj + $PARSER_MODES[$obj->getType()][] = "plugin_$p"; //register mode type + //add to modes + $modes[] = array( + 'sort' => $obj->getSort(), + 'mode' => "plugin_$p", + 'obj' => $obj, + ); + unset($obj); //remove the reference + } + } + + // add default modes + $std_modes = array('listblock','preformatted','notoc','nocache', + 'header','table','linebreak','footnote','hr', + 'unformatted','php','html','code','file','quote', + 'internallink','rss','media','externallink', + 'emaillink','windowssharelink','eol'); + if($conf['typography']){ + $std_modes[] = 'quotes'; + $std_modes[] = 'multiplyentity'; + } + foreach($std_modes as $m){ + $class = "Doku_Parser_Mode_$m"; + $obj = new $class(); + $modes[] = array( + 'sort' => $obj->getSort(), + 'mode' => $m, + 'obj' => $obj + ); + } + + // add formatting modes + $fmt_modes = array('strong','emphasis','underline','monospace', + 'subscript','superscript','deleted'); + foreach($fmt_modes as $m){ + $obj = new Doku_Parser_Mode_formatting($m); + $modes[] = array( + 'sort' => $obj->getSort(), + 'mode' => $m, + 'obj' => $obj + ); + } + + // add modes which need files + $obj = new Doku_Parser_Mode_smiley(array_keys(getSmileys())); + $modes[] = array('sort' => $obj->getSort(), 'mode' => 'smiley','obj' => $obj ); + $obj = new Doku_Parser_Mode_acronym(array_keys(getAcronyms())); + $modes[] = array('sort' => $obj->getSort(), 'mode' => 'acronym','obj' => $obj ); + $obj = new Doku_Parser_Mode_entity(array_keys(getEntities())); + $modes[] = array('sort' => $obj->getSort(), 'mode' => 'entity','obj' => $obj ); + + // add optional camelcase mode + if($conf['camelcase']){ + $obj = new Doku_Parser_Mode_camelcaselink(); + $modes[] = array('sort' => $obj->getSort(), 'mode' => 'camelcaselink','obj' => $obj ); + } + + //sort modes + usort($modes,'p_sort_modes'); + + return $modes; } /** @@ -533,8 +531,8 @@ function p_get_parsermodes(){ * @author Andreas Gohr */ function p_sort_modes($a, $b){ - if($a['sort'] == $b['sort']) return 0; - return ($a['sort'] < $b['sort']) ? -1 : 1; + if($a['sort'] == $b['sort']) return 0; + return ($a['sort'] < $b['sort']) ? -1 : 1; } /** @@ -546,64 +544,63 @@ function p_sort_modes($a, $b){ * @author Andreas Gohr */ function p_render($mode,$instructions,&$info){ - if(is_null($instructions)) return ''; + if(is_null($instructions)) return ''; - $Renderer =& p_get_renderer($mode); - if (is_null($Renderer)) return null; + $Renderer =& p_get_renderer($mode); + if (is_null($Renderer)) return null; - $Renderer->reset(); + $Renderer->reset(); - $Renderer->smileys = getSmileys(); - $Renderer->entities = getEntities(); - $Renderer->acronyms = getAcronyms(); - $Renderer->interwiki = getInterwiki(); - #$Renderer->badwords = getBadWords(); + $Renderer->smileys = getSmileys(); + $Renderer->entities = getEntities(); + $Renderer->acronyms = getAcronyms(); + $Renderer->interwiki = getInterwiki(); - // Loop through the instructions - foreach ( $instructions as $instruction ) { - // Execute the callback against the Renderer - call_user_func_array(array(&$Renderer, $instruction[0]),$instruction[1]); - } + // Loop through the instructions + foreach ( $instructions as $instruction ) { + // Execute the callback against the Renderer + call_user_func_array(array(&$Renderer, $instruction[0]),$instruction[1]); + } - //set info array - $info = $Renderer->info; + //set info array + $info = $Renderer->info; - // Post process and return the output - $data = array($mode,& $Renderer->doc); - trigger_event('RENDERER_CONTENT_POSTPROCESS',$data); - return $Renderer->doc; + // Post process and return the output + $data = array($mode,& $Renderer->doc); + trigger_event('RENDERER_CONTENT_POSTPROCESS',$data); + return $Renderer->doc; } function & p_get_renderer($mode) { - global $conf, $plugin_controller; + global $conf, $plugin_controller; - $rname = !empty($conf['renderer_'.$mode]) ? $conf['renderer_'.$mode] : $mode; + $rname = !empty($conf['renderer_'.$mode]) ? $conf['renderer_'.$mode] : $mode; - // try default renderer first: - $file = DOKU_INC."inc/parser/$rname.php"; - if(@file_exists($file)){ - require_once $file; - $rclass = "Doku_Renderer_$rname"; + // try default renderer first: + $file = DOKU_INC."inc/parser/$rname.php"; + if(@file_exists($file)){ + require_once $file; + $rclass = "Doku_Renderer_$rname"; - if ( !class_exists($rclass) ) { - trigger_error("Unable to resolve render class $rclass",E_USER_WARNING); - msg("Renderer '$rname' for $mode not valid",-1); - return null; - } - $Renderer = & new $rclass(); - }else{ - // Maybe a plugin is available? - if (!$plugin_controller->isdisabled($rname)){ - $Renderer =& $plugin_controller->load('renderer',$rname, true); - } + if ( !class_exists($rclass) ) { + trigger_error("Unable to resolve render class $rclass",E_USER_WARNING); + msg("Renderer '$rname' for $mode not valid",-1); + return null; + } + $Renderer = & new $rclass(); + }else{ + // Maybe a plugin is available? + if (!$plugin_controller->isdisabled($rname)){ + $Renderer =& $plugin_controller->load('renderer',$rname, true); + } - if(is_null($Renderer)){ - msg("No renderer '$rname' found for mode '$mode'",-1); - return null; + if(is_null($Renderer)){ + msg("No renderer '$rname' found for mode '$mode'",-1); + return null; + } } - } - return $Renderer; + return $Renderer; } /** @@ -620,7 +617,7 @@ function & p_get_renderer($mode) { * @author Andreas Gohr */ function p_get_first_heading($id, $render=true){ - return p_get_metadata($id,'title',$render); + return p_get_metadata($id,'title',$render); } /** @@ -634,42 +631,41 @@ function p_get_first_heading($id, $render=true){ * @author Andreas Gohr */ function p_xhtml_cached_geshi($code, $language, $wrapper='pre') { - global $conf, $config_cascade; - $language = strtolower($language); - - // remove any leading or trailing blank lines - $code = preg_replace('/^\s*?\n|\s*?\n$/','',$code); - - $cache = getCacheName($language.$code,".code"); - $ctime = @filemtime($cache); - if($ctime && !$_REQUEST['purge'] && - $ctime > filemtime(DOKU_INC.'inc/geshi.php') && // geshi changed - $ctime > @filemtime(DOKU_INC.'inc/geshi/'.$language.'.php') && // language syntax definition changed - $ctime > filemtime(reset($config_cascade['main']['default']))){ // dokuwiki changed - $highlighted_code = io_readFile($cache, false); - - } else { - - require_once(DOKU_INC . 'inc/geshi.php'); - - $geshi = new GeSHi($code, $language, DOKU_INC . 'inc/geshi'); - $geshi->set_encoding('utf-8'); - $geshi->enable_classes(); - $geshi->set_header_type(GESHI_HEADER_PRE); - $geshi->set_link_target($conf['target']['extern']); - - // remove GeSHi's wrapper element (we'll replace it with our own later) - // we need to use a GeSHi wrapper to avoid
throughout the highlighted text - $highlighted_code = trim(preg_replace('!^]*>|$!','',$geshi->parse_code()),"\n\r"); - io_saveFile($cache,$highlighted_code); - } - - // add a wrapper element if required - if ($wrapper) { - return "<$wrapper class=\"code $language\">$highlighted_code"; - } else { - return $highlighted_code; - } + global $conf, $config_cascade; + $language = strtolower($language); + + // remove any leading or trailing blank lines + $code = preg_replace('/^\s*?\n|\s*?\n$/','',$code); + + $cache = getCacheName($language.$code,".code"); + $ctime = @filemtime($cache); + if($ctime && !$_REQUEST['purge'] && + $ctime > filemtime(DOKU_INC.'inc/geshi.php') && // geshi changed + $ctime > @filemtime(DOKU_INC.'inc/geshi/'.$language.'.php') && // language syntax definition changed + $ctime > filemtime(reset($config_cascade['main']['default']))){ // dokuwiki changed + $highlighted_code = io_readFile($cache, false); + + } else { + + require_once(DOKU_INC . 'inc/geshi.php'); + + $geshi = new GeSHi($code, $language, DOKU_INC . 'inc/geshi'); + $geshi->set_encoding('utf-8'); + $geshi->enable_classes(); + $geshi->set_header_type(GESHI_HEADER_PRE); + $geshi->set_link_target($conf['target']['extern']); + + // remove GeSHi's wrapper element (we'll replace it with our own later) + // we need to use a GeSHi wrapper to avoid
throughout the highlighted text + $highlighted_code = trim(preg_replace('!^]*>|$!','',$geshi->parse_code()),"\n\r"); + io_saveFile($cache,$highlighted_code); + } + + // add a wrapper element if required + if ($wrapper) { + return "<$wrapper class=\"code $language\">$highlighted_code"; + } else { + return $highlighted_code; + } } -//Setup VIM: ex: et ts=2 enc=utf-8 : -- cgit v1.2.3