1b625487dSandi<?php 2b625487dSandi/** 3b625487dSandi * Utilities for collecting data from config files 4b625487dSandi * 5b625487dSandi * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com> 7b625487dSandi */ 8b625487dSandi 900976812SAndreas Gohr if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/'); 10b625487dSandi 11b625487dSandi/** 12b625487dSandi * Returns the (known) extension and mimetype of a given filename 13b625487dSandi * 14b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 15b625487dSandi */ 16b625487dSandifunction mimetype($file){ 17b625487dSandi $ret = array(false,false); // return array 18b625487dSandi $mtypes = getMimeTypes(); // known mimetypes 19b625487dSandi $exts = join('|',array_keys($mtypes)); // known extensions (regexp) 20b625487dSandi if(preg_match('#\.('.$exts.')$#i',$file,$matches)){ 21b625487dSandi $ext = strtolower($matches[1]); 22b625487dSandi } 23b625487dSandi 24b625487dSandi if($ext && $mtypes[$ext]){ 25b625487dSandi $ret = array($ext, $mtypes[$ext]); 26b625487dSandi } 27b625487dSandi 28b625487dSandi return $ret; 29b625487dSandi} 30b625487dSandi 31b625487dSandi/** 32b625487dSandi * returns a hash of mimetypes 33b625487dSandi * 34b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 35b625487dSandi */ 36b625487dSandifunction getMimeTypes() { 37b625487dSandi static $mime = NULL; 38b625487dSandi if ( !$mime ) { 39e7cb32dcSAndreas Gohr $mime = confToHash(DOKU_CONF.'mime.conf'); 40e7cb32dcSAndreas Gohr if (@file_exists(DOKU_CONF.'mime.local.conf')) { 41e7cb32dcSAndreas Gohr $local = confToHash(DOKU_CONF.'mime.local.conf'); 424a9a52beSAndreas Gohr $mime = array_merge($mime, $local); 434a9a52beSAndreas Gohr } 44b625487dSandi } 45b625487dSandi return $mime; 46b625487dSandi} 47b625487dSandi 48b625487dSandi/** 49b625487dSandi * returns a hash of acronyms 50b625487dSandi * 51b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com> 52b625487dSandi */ 53b625487dSandifunction getAcronyms() { 54b625487dSandi static $acronyms = NULL; 55b625487dSandi if ( !$acronyms ) { 56e7cb32dcSAndreas Gohr $acronyms = confToHash(DOKU_CONF.'acronyms.conf'); 57e7cb32dcSAndreas Gohr if (@file_exists(DOKU_CONF.'acronyms.local.conf')) { 58e7cb32dcSAndreas Gohr $local = confToHash(DOKU_CONF.'acronyms.local.conf'); 59d2ee49ceSSteven Danz $acronyms = array_merge($acronyms, $local); 60d2ee49ceSSteven Danz } 61b625487dSandi } 62b625487dSandi return $acronyms; 63b625487dSandi} 64b625487dSandi 65b625487dSandi/** 66b625487dSandi * returns a hash of smileys 67b625487dSandi * 68b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com> 69b625487dSandi */ 70b625487dSandifunction getSmileys() { 71b625487dSandi static $smileys = NULL; 72b625487dSandi if ( !$smileys ) { 73e7cb32dcSAndreas Gohr $smileys = confToHash(DOKU_CONF.'smileys.conf'); 74e7cb32dcSAndreas Gohr if (@file_exists(DOKU_CONF.'smileys.local.conf')) { 75e7cb32dcSAndreas Gohr $local = confToHash(DOKU_CONF.'smileys.local.conf'); 764a9a52beSAndreas Gohr $smileys = array_merge($smileys, $local); 774a9a52beSAndreas Gohr } 78b625487dSandi } 79b625487dSandi return $smileys; 80b625487dSandi} 81b625487dSandi 82b625487dSandi/** 83b625487dSandi * returns a hash of entities 84b625487dSandi * 85b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com> 86b625487dSandi */ 87b625487dSandifunction getEntities() { 88b625487dSandi static $entities = NULL; 89b625487dSandi if ( !$entities ) { 90e7cb32dcSAndreas Gohr $entities = confToHash(DOKU_CONF.'entities.conf'); 91e7cb32dcSAndreas Gohr if (@file_exists(DOKU_CONF.'entities.local.conf')) { 92e7cb32dcSAndreas Gohr $local = confToHash(DOKU_CONF.'entities.local.conf'); 934a9a52beSAndreas Gohr $entities = array_merge($entities, $local); 944a9a52beSAndreas Gohr } 95b625487dSandi } 96b625487dSandi return $entities; 97b625487dSandi} 98b625487dSandi 99b625487dSandi/** 100b625487dSandi * returns a hash of interwikilinks 101b625487dSandi * 102b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com> 103b625487dSandi */ 104b625487dSandifunction getInterwiki() { 105b625487dSandi static $wikis = NULL; 106b625487dSandi if ( !$wikis ) { 107e7cb32dcSAndreas Gohr $wikis = confToHash(DOKU_CONF.'interwiki.conf',true); 108e7cb32dcSAndreas Gohr if (@file_exists(DOKU_CONF.'interwiki.local.conf')) { 109e7cb32dcSAndreas Gohr $local = confToHash(DOKU_CONF.'interwiki.local.conf'); 1104a9a52beSAndreas Gohr $wikis = array_merge($wikis, $local); 1114a9a52beSAndreas Gohr } 112b625487dSandi } 11397a3e4e3Sandi //add sepecial case 'this' 11427a2b085Sandi $wikis['this'] = DOKU_URL.'{NAME}'; 115b625487dSandi return $wikis; 116b625487dSandi} 117b625487dSandi 118b625487dSandi/** 119b9ac8716Schris * returns array of wordblock patterns 120b9ac8716Schris * 121b9ac8716Schris */ 122b9ac8716Schrisfunction getWordblocks() { 123b9ac8716Schris static $wordblocks = NULL; 124b9ac8716Schris if ( !$wordblocks ) { 125b9ac8716Schris $wordblocks = file(DOKU_CONF.'wordblock.conf'); 126b9ac8716Schris if (@file_exists(DOKU_CONF.'wordblock.local.conf')) { 127b9ac8716Schris $local = file(DOKU_CONF.'wordblock.local.conf'); 128b9ac8716Schris $wordblocks = array_merge($wordblocks, $local); 129b9ac8716Schris } 130b9ac8716Schris } 131b9ac8716Schris return $wordblocks; 132b9ac8716Schris} 133b9ac8716Schris 134b9ac8716Schris 135b9ac8716Schris/** 136b625487dSandi * Builds a hash from a configfile 137b625487dSandi * 1383fd0b676Sandi * If $lower is set to true all hash keys are converted to 1393fd0b676Sandi * lower case. 1403fd0b676Sandi * 141b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com> 1423fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 143b625487dSandi */ 14427a2b085Sandifunction confToHash($file,$lower=false) { 145b625487dSandi $conf = array(); 146b625487dSandi $lines = @file( $file ); 147b625487dSandi if ( !$lines ) return $conf; 148b625487dSandi 149b625487dSandi foreach ( $lines as $line ) { 15003ff8795SAndreas Gohr //ignore comments (except escaped ones) 15103ff8795SAndreas Gohr $line = preg_replace('/(?<![&\\\\])#.*$/','',$line); 15203ff8795SAndreas Gohr $line = str_replace('\\#','#',$line); 153b625487dSandi $line = trim($line); 154b625487dSandi if(empty($line)) continue; 155b625487dSandi $line = preg_split('/\s+/',$line,2); 156b625487dSandi // Build the associative array 15727a2b085Sandi if($lower){ 15827a2b085Sandi $conf[strtolower($line[0])] = $line[1]; 15927a2b085Sandi }else{ 160b625487dSandi $conf[$line[0]] = $line[1]; 161b625487dSandi } 16227a2b085Sandi } 163b625487dSandi 164b625487dSandi return $conf; 165b625487dSandi} 166b625487dSandi 167409d7af7SAndreas Gohr/** 168409d7af7SAndreas Gohr * check if the given action was disabled in config 169409d7af7SAndreas Gohr * 170409d7af7SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 171409d7af7SAndreas Gohr * @returns boolean true if enabled, false if disabled 172409d7af7SAndreas Gohr */ 173409d7af7SAndreas Gohrfunction actionOK($action){ 174409d7af7SAndreas Gohr static $disabled = null; 175409d7af7SAndreas Gohr if(is_null($disabled)){ 176409d7af7SAndreas Gohr global $conf; 177409d7af7SAndreas Gohr 178409d7af7SAndreas Gohr // prepare disabled actions array and handle legacy options 179409d7af7SAndreas Gohr $disabled = explode(',',$conf['disableactions']); 180409d7af7SAndreas Gohr $disabled = array_map('trim',$disabled); 181409d7af7SAndreas Gohr if(isset($conf['openregister']) && !$conf['openregister']) $disabled[] = 'register'; 182409d7af7SAndreas Gohr if(isset($conf['resendpasswd']) && !$conf['resendpasswd']) $disabled[] = 'resendpwd'; 183*8c286148SMichael Klier if(isset($conf['subscribers']) && !$conf['subscribers']) { 184*8c286148SMichael Klier $disabled[] = 'subscribe'; 185*8c286148SMichael Klier $disabled[] = 'subscribens'; 186*8c286148SMichael Klier } 187409d7af7SAndreas Gohr $disabled = array_unique($disabled); 188409d7af7SAndreas Gohr } 189409d7af7SAndreas Gohr 190409d7af7SAndreas Gohr return !in_array($action,$disabled); 191409d7af7SAndreas Gohr} 192409d7af7SAndreas Gohr 193b625487dSandi 194b625487dSandi//Setup VIM: ex: et ts=2 enc=utf-8 : 195