From 3903be5dc10c8ce0270ce28c57a5b76df87db4c3 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Sat, 13 Nov 2010 16:25:43 +0100 Subject: Remove metadata conversion from 0a7e3bce (2006-11-26) --- inc/parserutils.php | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'inc/parserutils.php') diff --git a/inc/parserutils.php b/inc/parserutils.php index 27a5190bd..847b0382f 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -337,9 +337,6 @@ function p_purge_metadata($id) { * read the metadata from source/cache for $id * (internal use only - called by p_get_metadata & p_set_metadata) * - * this function also converts the metadata from the original format to - * the current format ('current' & 'persistent' arrays) - * * @author Christopher Smith * * @param string $id absolute wiki page id @@ -356,26 +353,6 @@ function p_read_metadata($id,$cache=false) { $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); - - // 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']); - - // save converted metadata - io_saveFile($file, serialize($meta)); - } - if ($cache) { $cache_metadata[(string)$id] = $meta; } -- cgit v1.2.3 From 1172f8dcef2c8198ddcdaffcdf65a735811d20a3 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Sat, 13 Nov 2010 18:20:51 +0100 Subject: Introduce metadata write wrapper p_save_metadata p_purge_metadata now updates the metadata cache and the INFO array like the other metadata writing functions --- inc/parserutils.php | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'inc/parserutils.php') diff --git a/inc/parserutils.php b/inc/parserutils.php index 847b0382f..b8b063fc3 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -223,7 +223,7 @@ function p_get_instructions($text){ * @author Esther Brunner */ function p_get_metadata($id, $key='', $render=false){ - global $ID, $INFO, $cache_metadata; + global $ID; // cache the current page // Benchmarking shows the current page's metadata is generally the only page metadata @@ -234,11 +234,7 @@ function p_get_metadata($id, $key='', $render=false){ // 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']; } + p_save_metadata($id, $meta); } $val = $meta['current']; @@ -305,13 +301,7 @@ function p_set_metadata($id, $data, $render=false, $persistent=true){ // save only if metadata changed if ($meta == $orig) return true; - // 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']; } - - return io_saveFile(metaFN($id, '.meta'), serialize($meta)); + return p_save_metadata($id, $meta); } /** @@ -321,16 +311,16 @@ function p_set_metadata($id, $data, $render=false, $persistent=true){ * @author Michael Klier */ function p_purge_metadata($id) { - $metafn = metaFN('id', '.meta'); - $meta = p_read_metadata($id); + $meta = p_read_metadata($id); foreach($meta['current'] as $key => $value) { if(is_array($meta[$key])) { $meta['current'][$key] = array(); } else { $meta['current'][$key] = ''; } + } - return io_saveFile(metaFN($id, '.meta'), serialize($meta)); + return p_save_metadata($id, $meta); } /** @@ -360,6 +350,24 @@ function p_read_metadata($id,$cache=false) { return $meta; } +/** + * This is the backend function to save a metadata array to a file + * + * @param string $id absolute wiki page id + * @param array $meta metadata + * + * @return bool success / fail + */ +function p_save_metadata($id, $meta) { + // sync cached copies, including $INFO metadata + global $cache_metadata, $INFO; + + if (isset($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)); +} + /** * renders the metadata of a page * -- cgit v1.2.3 From a365baeef4fc0b6d593043c6db53c01671de9490 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sat, 13 Nov 2010 19:04:26 +0100 Subject: improved some metadata comments --- inc/parserutils.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'inc/parserutils.php') diff --git a/inc/parserutils.php b/inc/parserutils.php index b8b063fc3..a50e3f4f3 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -252,6 +252,15 @@ function p_get_metadata($id, $key='', $render=false){ /** * sets metadata elements of a page * + * @see http://www.dokuwiki.org/devel:metadata#functions_to_get_and_set_metadata + * + * @param String $id is the ID of a wiki page + * @param Array $data is an array with key ⇒ value pairs to be set in the metadata + * @param Boolean $render whether or not the page metadata should be generated with the renderer + * @param Boolean $persistent indicates whether or not the particular metadata value will persist through + * the next metadata rendering. + * @return boolean true on success + * * @author Esther Brunner */ function p_set_metadata($id, $data, $render=false, $persistent=true){ -- cgit v1.2.3