summaryrefslogtreecommitdiff
path: root/inc/confutils.php
diff options
context:
space:
mode:
authorandi <andi@splitbrain.org>2005-04-15 22:47:35 +0200
committerandi <andi@splitbrain.org>2005-04-15 22:47:35 +0200
commitb625487d2258a6f1f875813206adc9a5857dab24 (patch)
treed58871efbfeb198ad4634add0e496b5cb890b655 /inc/confutils.php
parent4826ab45befb9eb1c664b5d8c8a0f03a7b750b8b (diff)
downloadrpg-b625487d2258a6f1f875813206adc9a5857dab24.tar.gz
rpg-b625487d2258a6f1f875813206adc9a5857dab24.tar.bz2
new parser: more hacking, RSS readded
darcs-hash:20050415204735-9977f-613d9b007452d538dcb8fce4ade5cbec389c4415.gz
Diffstat (limited to 'inc/confutils.php')
-rw-r--r--inc/confutils.php120
1 files changed, 120 insertions, 0 deletions
diff --git a/inc/confutils.php b/inc/confutils.php
new file mode 100644
index 000000000..114fa3024
--- /dev/null
+++ b/inc/confutils.php
@@ -0,0 +1,120 @@
+<?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 the (known) extension and mimetype of a given filename
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function mimetype($file){
+ $ret = array(false,false); // return array
+ $mtypes = getMimeTypes(); // known mimetypes
+ $exts = join('|',array_keys($mtypes)); // known extensions (regexp)
+ if(preg_match('#\.('.$exts.')$#i',$file,$matches)){
+ $ext = strtolower($matches[1]);
+ }
+
+ if($ext && $mtypes[$ext]){
+ $ret = array($ext, $mtypes[$ext]);
+ }
+
+ return $ret;
+}
+
+/**
+ * returns a hash of mimetypes
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function getMimeTypes() {
+ static $mime = NULL;
+ if ( !$mime ) {
+ $mime = confToHash(DOKU_INC . 'conf/mime.conf');
+ }
+ return $mime;
+}
+
+/**
+ * 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;
+}
+
+
+//Setup VIM: ex: et ts=2 enc=utf-8 :