diff options
author | andi <andi@splitbrain.org> | 2005-04-10 19:01:15 +0200 |
---|---|---|
committer | andi <andi@splitbrain.org> | 2005-04-10 19:01:15 +0200 |
commit | 4de671bc5e749ac76ad85252df59feb45c749eab (patch) | |
tree | b653219d0ec0b296640ba7b3c742ee989639ae78 /inc/utils.php | |
parent | 2f40443a6ca5a5ddca04b94e4ffc4562c76753c3 (diff) | |
download | rpg-4de671bc5e749ac76ad85252df59feb45c749eab.tar.gz rpg-4de671bc5e749ac76ad85252df59feb45c749eab.tar.bz2 |
new parser - more fixes
darcs-hash:20050410170115-9977f-620a5fccdc80d5af01d0b9aec9f8b1fb8e4c667d.gz
Diffstat (limited to 'inc/utils.php')
-rw-r--r-- | inc/utils.php | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/inc/utils.php b/inc/utils.php new file mode 100644 index 000000000..de98f35ec --- /dev/null +++ b/inc/utils.php @@ -0,0 +1,86 @@ +<?php +/** + * Utilities for collecting data from config files + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Harry Fuecks <hfuecks@gmail.com> + */ + + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); + +/** + * returns a hash of acronyms + * + * @author Harry Fuecks <hfuecks@gmail.com> + */ +function getAcronyms() { + static $acronyms = NULL; + if ( !$acronyms ) { + $acronyms = confToHash(DOKU_INC . 'conf/acronyms.conf'); + } + return $acronyms; +} + +/** + * returns a hash of smileys + * + * @author Harry Fuecks <hfuecks@gmail.com> + */ +function getSmileys() { + static $smileys = NULL; + if ( !$smileys ) { + $smileys = confToHash(DOKU_INC . 'conf/smileys.conf'); + } + return $smileys; +} + +/** + * returns a hash of entities + * + * @author Harry Fuecks <hfuecks@gmail.com> + */ +function getEntities() { + static $entities = NULL; + if ( !$entities ) { + $entities = confToHash(DOKU_INC . 'conf/entities.conf'); + } + return $entities; +} + +/** + * returns a hash of interwikilinks + * + * @author Harry Fuecks <hfuecks@gmail.com> + */ +function getInterwiki() { + static $wikis = NULL; + if ( !$wikis ) { + $wikis = confToHash(DOKU_INC . 'conf/interwiki.conf'); + } + return $wikis; +} + +/** + * Builds a hash from a configfile + * + * @author Harry Fuecks <hfuecks@gmail.com> + */ +function confToHash($file) { + $conf = array(); + $lines = @file( $file ); + if ( !$lines ) { + return $conf; + } + + foreach ( $lines as $line ) { + //ignore comments + $line = preg_replace('/[^&]#.*$/','',$line); + $line = trim($line); + if(empty($line)) continue; + $line = preg_split('/\s+/',$line,2); + // Build the associative array + $conf[$line[0]] = $line[1]; + } + + return $conf; +} |