diff options
author | Andreas Gohr <andi@splitbrain.org> | 2006-04-30 20:17:40 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2006-04-30 20:17:40 +0200 |
commit | 95dbfe5721704a800c0f108c048ab3cb5e13de3b (patch) | |
tree | 3e0fa5f8953292d69f242353853f70891c17b1d9 /inc | |
parent | 862763f2e36a5ef7e996bad2579e60b2bd365f39 (diff) | |
download | rpg-95dbfe5721704a800c0f108c048ab3cb5e13de3b.tar.gz rpg-95dbfe5721704a800c0f108c048ab3cb5e13de3b.tar.bz2 |
metadata enhancements
This adds meta data rendering to the indexer process to build missing meta data
in the background.
p_get_first_heading was adjusted to make use of the new meta data mechanisms
A problem with unitialized arrays in p_set_metadata and PHP5 was fixed (I think)
darcs-hash:20060430181740-7ad00-8952fa6beb4fadf6b4321627998442d34febfc8d.gz
Diffstat (limited to 'inc')
-rw-r--r-- | inc/parser/metadata.php | 46 | ||||
-rw-r--r-- | inc/parserutils.php | 38 |
2 files changed, 41 insertions, 43 deletions
diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 0ba59c65e..e7173dda6 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -26,7 +26,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { var $doc = ''; var $meta = array(); - + var $headers = array(); var $capture = true; var $store = ''; @@ -73,7 +73,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { 'level' => $level-$conf['toptoclevel']+1 ); } - + // add to summary if ($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF; } @@ -88,7 +88,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { function p_open(){ if ($this->capture) $this->doc .= DOKU_LF; } - + function p_close(){ if ($this->capture){ if (strlen($this->doc) > 250) $this->capture = false; @@ -112,7 +112,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { function emphasis_open(){} function emphasis_close(){} - + function underline_open(){} function underline_close(){} @@ -144,7 +144,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { $this->doc = ''; } } - + /** * Callback for footnote end syntax * @@ -160,11 +160,11 @@ class Doku_Renderer_metadata extends Doku_Renderer { $this->store = ''; } } - + function listu_open(){ if ($this->capture) $this->doc .= DOKU_LF; } - + function listu_close(){ if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false; } @@ -172,7 +172,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { function listo_open(){ if ($this->capture) $this->doc .= DOKU_LF; } - + function listo_close(){ if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false; } @@ -180,7 +180,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { function listitem_open($level){ if ($this->capture) $this->doc .= str_repeat(DOKU_TAB, $level).'* '; } - + function listitem_close(){ if ($this->capture) $this->doc .= DOKU_LF; } @@ -211,7 +211,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { function quote_open(){ if ($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'“'; } - + function quote_close(){ if ($this->capture){ $this->doc .= '”'; @@ -247,7 +247,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { function singlequoteopening(){ if ($this->capture) $this->doc .= '‘'; } - + function singlequoteclosing(){ if ($this->capture) $this->doc .= '’'; } @@ -255,7 +255,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { function doublequoteopening(){ if ($this->capture) $this->doc .= '“'; } - + function doublequoteclosing(){ if ($this->capture) $this->doc .= '”'; } @@ -271,30 +271,30 @@ class Doku_Renderer_metadata extends Doku_Renderer { */ function internallink($id, $name = NULL){ global $ID; - + $default = $this->_simpleTitle($id); - + // first resolve and clean up the $id resolve_pageid(getNS($ID), $id, $exists); list($id, $hash) = split('#', $id, 2); - + // set metadata $this->meta['relation']['references'][$id] = $exists; // $data = array('relation' => array('isreferencedby' => array($ID => true))); // p_set_metadata($id, $data); - + // add link title to summary if ($this->capture){ $name = $this->_getLinkTitle($name, $default, $id); $this->doc .= $name; - } + } } function externallink($url, $name = NULL){ if ($this->capture){ if ($name) $this->doc .= $name; else $this->doc .= '<'.$url.'>'; - } + } } function interwikilink($match, $name = NULL, $wikiName, $wikiUri){ @@ -302,21 +302,21 @@ class Doku_Renderer_metadata extends Doku_Renderer { list($wikiUri, $hash) = explode('#', $wikiUri, 2); $name = $this->_getLinkTitle($name, $wikiName.'>'.$wikiUri); $this->doc .= $name; - } + } } function windowssharelink($url, $name = NULL){ if ($this->capture){ if ($name) $this->doc .= $name; else $this->doc .= '<'.$url.'>'; - } + } } function emaillink($address, $name = NULL){ if ($this->capture){ if ($name) $this->doc .= $name; else $this->doc .= '<'.$address.'>'; - } + } } function internalmedia($src, $title=NULL, $align=NULL, $width=NULL, @@ -412,7 +412,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { return '['.$title.']'; } } - + } -//Setup VIM: ex: et ts=4 enc=utf-8 :
\ No newline at end of file +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/inc/parserutils.php b/inc/parserutils.php index 981f33cc1..93c2b3604 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -239,23 +239,23 @@ function p_get_instructions($text){ */ function p_get_metadata($id, $key=false, $render=false){ $file = metaFN($id, '.meta'); - + if (@file_exists($file)) $meta = unserialize(io_readFile($file, false)); else $meta = array(); - + // metadata has never been rendered before - do it! if ($render && !$meta['description']['abstract']){ $meta = p_render_metadata($id, $meta); io_saveFile($file, serialize($meta)); } - + // filter by $key if ($key){ list($key, $subkey) = explode(' ', $key, 2); if (trim($subkey)) return $meta[$key][$subkey]; else return $meta[$key]; } - + return $meta; } @@ -266,35 +266,37 @@ function p_get_metadata($id, $key=false, $render=false){ */ function p_set_metadata($id, $data, $render=false){ if (!is_array($data)) return false; - + $orig = p_get_metadata($id); - + // render metadata first? if ($render) $meta = p_render_metadata($id, $orig); else $meta = $orig; - + // 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'){ foreach ($value as $subkey => $subvalue){ $meta[$key][$subkey] = array_merge($meta[$key][$subkey], $subvalue); } - + // be careful with some senisitive arrays of $meta } elseif (in_array($key, $protected)){ if (is_array($value)){ + #FIXME not sure if this is the intended thing: + if(!is_array($meta[$key])) $meta[$key] = array($meta[$key]); $meta[$key] = array_merge($meta[$key], $value); } - + // no special treatment for the rest } else { $meta[$key] = $value; } } - + // save only if metadata changed if ($meta == $orig) return true; return io_saveFile(metaFN($id, '.meta'), serialize($meta)); @@ -314,13 +316,13 @@ function p_render_metadata($id, $orig){ // set up the renderer $renderer = & new Doku_Renderer_metadata(); $renderer->meta = $orig; - + // loop through the instructions foreach ($instructions as $instruction){ // execute the callback against the renderer call_user_func_array(array(&$renderer, $instruction[0]), $instruction[1]); } - + return $renderer->meta; } @@ -476,15 +478,11 @@ function p_render($mode,$instructions,& $info){ /** * Gets the first heading from a file * - * @author Jan Decaluwe <jan@jandecaluwe.com> + * @author Andreas Gohr <andi@splitbrain.org> */ function p_get_first_heading($id){ - $file = wikiFN($id); - if (@file_exists($file)) { - $instructions = p_cached_instructions($file,true); - $meta = $instructions[0][1]; - return isset($meta[0]['first_heading']) ? trim($meta[0]['first_heading']) : NULL; - } + $meta = p_get_metadata($id); + if($meta['title']) return $meta['title']; return NULL; } |