xref: /dokuwiki/inc/confutils.php (revision fa078663938bc6227e460315b2febc92ae93e897)
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
910b38f10SChristopher Smith/*
1010b38f10SChristopher Smith * line prefix used to negate single value config items
1110b38f10SChristopher Smith * (scheme.conf & stopwords.conf), e.g.
1210b38f10SChristopher Smith * !gopher
1310b38f10SChristopher Smith */
1410b38f10SChristopher Smithconst DOKU_CONF_NEGATION = '!';
15b625487dSandi
16b625487dSandi/**
17b625487dSandi * Returns the (known) extension and mimetype of a given filename
18b625487dSandi *
1927bf7924STom N Harris * If $knownonly is true (the default), then only known extensions
2027bf7924STom N Harris * are returned.
2127bf7924STom N Harris *
22b625487dSandi * @author Andreas Gohr <andi@splitbrain.org>
2342ea7f44SGerrit Uitslag *
2442ea7f44SGerrit Uitslag * @param string $file file name
2542ea7f44SGerrit Uitslag * @param bool   $knownonly
2642ea7f44SGerrit Uitslag * @return array with extension, mimetype and if it should be downloaded
27b625487dSandi */
2827bf7924STom N Harrisfunction mimetype($file, $knownonly=true){
29b625487dSandi    $mtypes = getMimeTypes();     // known mimetypes
30ad74fe66SAdrian Lang    $ext    = strrpos($file, '.');
31ad74fe66SAdrian Lang    if ($ext === false) {
32ad74fe66SAdrian Lang        return array(false, false, false);
3327bf7924STom N Harris    }
34ad74fe66SAdrian Lang    $ext = strtolower(substr($file, $ext + 1));
35ad74fe66SAdrian Lang    if (!isset($mtypes[$ext])){
36ad74fe66SAdrian Lang        if ($knownonly) {
37ad74fe66SAdrian Lang            return array(false, false, false);
38ecebf3a8SAndreas Gohr        } else {
39ad74fe66SAdrian Lang            return array($ext, 'application/octet-stream', true);
4027bf7924STom N Harris        }
41b625487dSandi    }
42ad74fe66SAdrian Lang    if($mtypes[$ext][0] == '!'){
43ad74fe66SAdrian Lang        return array($ext, substr($mtypes[$ext],1), true);
44ad74fe66SAdrian Lang    }else{
45ad74fe66SAdrian Lang        return array($ext, $mtypes[$ext], false);
46ad74fe66SAdrian Lang    }
47b625487dSandi}
48b625487dSandi
49b625487dSandi/**
50b625487dSandi * returns a hash of mimetypes
51b625487dSandi *
52b625487dSandi * @author Andreas Gohr <andi@splitbrain.org>
53b625487dSandi */
54b625487dSandifunction getMimeTypes() {
5549eb6e38SAndreas Gohr    static $mime = null;
56b625487dSandi    if ( !$mime ) {
57cb043f52SChris Smith        $mime = retrieveConfig('mime','confToHash');
5845ae4bb8SChristopher Smith        $mime = array_filter($mime);
59b625487dSandi    }
60b625487dSandi    return $mime;
61b625487dSandi}
62b625487dSandi
63b625487dSandi/**
64b625487dSandi * returns a hash of acronyms
65b625487dSandi *
66b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
67b625487dSandi */
68b625487dSandifunction getAcronyms() {
6949eb6e38SAndreas Gohr    static $acronyms = null;
70b625487dSandi    if ( !$acronyms ) {
71cb043f52SChris Smith        $acronyms = retrieveConfig('acronyms','confToHash');
72f266a919SChristopher Smith        $acronyms = array_filter($acronyms, 'strlen');
73b625487dSandi    }
74b625487dSandi    return $acronyms;
75b625487dSandi}
76b625487dSandi
77b625487dSandi/**
78b625487dSandi * returns a hash of smileys
79b625487dSandi *
80b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
81b625487dSandi */
82b625487dSandifunction getSmileys() {
8349eb6e38SAndreas Gohr    static $smileys = null;
84b625487dSandi    if ( !$smileys ) {
85cb043f52SChris Smith        $smileys = retrieveConfig('smileys','confToHash');
86f266a919SChristopher Smith        $smileys = array_filter($smileys, 'strlen');
87b625487dSandi    }
88b625487dSandi    return $smileys;
89b625487dSandi}
90b625487dSandi
91b625487dSandi/**
92b625487dSandi * returns a hash of entities
93b625487dSandi *
94b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
95b625487dSandi */
96b625487dSandifunction getEntities() {
9749eb6e38SAndreas Gohr    static $entities = null;
98b625487dSandi    if ( !$entities ) {
99cb043f52SChris Smith        $entities = retrieveConfig('entities','confToHash');
100f266a919SChristopher Smith        $entities = array_filter($entities, 'strlen');
101b625487dSandi    }
102b625487dSandi    return $entities;
103b625487dSandi}
104b625487dSandi
105b625487dSandi/**
106b625487dSandi * returns a hash of interwikilinks
107b625487dSandi *
108b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
109b625487dSandi */
110b625487dSandifunction getInterwiki() {
11149eb6e38SAndreas Gohr    static $wikis = null;
112b625487dSandi    if ( !$wikis ) {
1134c6a5eccSAndreas Gohr        $wikis = retrieveConfig('interwiki','confToHash',array(true));
114f266a919SChristopher Smith        $wikis = array_filter($wikis, 'strlen');
11545ae4bb8SChristopher Smith
11697a3e4e3Sandi        //add sepecial case 'this'
11727a2b085Sandi        $wikis['this'] = DOKU_URL.'{NAME}';
11845ae4bb8SChristopher Smith    }
119b625487dSandi    return $wikis;
120b625487dSandi}
121b625487dSandi
122b625487dSandi/**
123*fa078663SAndreas Gohr * Returns the jquery script URLs for the versions defined in lib/scripts/jquery/versions
12461537d47SAndreas Gohr *
125*fa078663SAndreas Gohr * @trigger CONFUTIL_CDN_SELECT
12661537d47SAndreas Gohr * @return array
12761537d47SAndreas Gohr */
128*fa078663SAndreas Gohrfunction getCdnUrls() {
129*fa078663SAndreas Gohr    global $conf;
130*fa078663SAndreas Gohr
131*fa078663SAndreas Gohr    // load version info
13261537d47SAndreas Gohr    $versions = array();
13361537d47SAndreas Gohr    $lines = file(DOKU_INC . 'lib/scripts/jquery/versions');
13461537d47SAndreas Gohr    foreach($lines as $line) {
13561537d47SAndreas Gohr        $line = preg_replace('/#.*$/', '', $line);
13661537d47SAndreas Gohr        list($key, $val) = explode('=', $line, 2);
13761537d47SAndreas Gohr        $key = trim($key);
13861537d47SAndreas Gohr        $val = trim($val);
13961537d47SAndreas Gohr        $versions[$key] = $val;
14061537d47SAndreas Gohr    }
141*fa078663SAndreas Gohr
142*fa078663SAndreas Gohr    $src = array();
143*fa078663SAndreas Gohr    $data = array(
144*fa078663SAndreas Gohr        'versions' => $versions,
145*fa078663SAndreas Gohr        'src' => &$src
146*fa078663SAndreas Gohr    );
147*fa078663SAndreas Gohr    $event = new Doku_Event('CONFUTIL_CDN_SELECT', $data);
148*fa078663SAndreas Gohr    if($event->advise_before()) {
149*fa078663SAndreas Gohr        if(!$conf['jquerycdn']) {
150*fa078663SAndreas Gohr            $jqmod = md5(join('-', $versions));
151*fa078663SAndreas Gohr            $src[] = DOKU_BASE . 'lib/exe/jquery.php' . '?tseed=' . $jqmod;
152*fa078663SAndreas Gohr        } elseif($conf['jquerycdn'] == 'jquery') {
153*fa078663SAndreas Gohr            $src[] = sprintf('https://code.jquery.com/jquery-%s.min.js', $versions['JQ_VERSION']);
154*fa078663SAndreas Gohr            $src[] = sprintf('https://code.jquery.com/jquery-migrate-%s.min.js', $versions['JQM_VERSION']);
155*fa078663SAndreas Gohr            $src[] = sprintf('https://code.jquery.com/ui/%s/jquery-ui.min.js', $versions['JQUI_VERSION']);
156*fa078663SAndreas Gohr        } elseif($conf['jquerycdn'] == 'cdnjs') {
157*fa078663SAndreas Gohr            $src[] = sprintf('https://cdnjs.cloudflare.com/ajax/libs/jquery/%s/jquery.min.js', $versions['JQ_VERSION']);
158*fa078663SAndreas Gohr            $src[] = sprintf('https://cdnjs.cloudflare.com/ajax/libs/jquery-migrate/%s/jquery-migrate.min.js', $versions['JQM_VERSION']);
159*fa078663SAndreas Gohr            $src[] = sprintf('https://cdnjs.cloudflare.com/ajax/libs/jqueryui/%s/jquery-ui.min.js', $versions['JQUI_VERSION']);
160*fa078663SAndreas Gohr        }
161*fa078663SAndreas Gohr    }
162*fa078663SAndreas Gohr    $event->advise_after();
163*fa078663SAndreas Gohr
164*fa078663SAndreas Gohr    return $src;
16561537d47SAndreas Gohr}
16661537d47SAndreas Gohr
16761537d47SAndreas Gohr/**
168b9ac8716Schris * returns array of wordblock patterns
169b9ac8716Schris *
170b9ac8716Schris */
171b9ac8716Schrisfunction getWordblocks() {
17249eb6e38SAndreas Gohr    static $wordblocks = null;
173b9ac8716Schris    if ( !$wordblocks ) {
1744c353447SChristopher Smith        $wordblocks = retrieveConfig('wordblock','file',null,'array_merge_with_removal');
175b9ac8716Schris    }
176b9ac8716Schris    return $wordblocks;
177b9ac8716Schris}
178b9ac8716Schris
179e3ab6fc5SMichael Hamann/**
180e3ab6fc5SMichael Hamann * Gets the list of configured schemes
181e3ab6fc5SMichael Hamann *
182e3ab6fc5SMichael Hamann * @return array the schemes
183e3ab6fc5SMichael Hamann */
18436f2d7c1SGina Haeussgefunction getSchemes() {
18549eb6e38SAndreas Gohr    static $schemes = null;
18636f2d7c1SGina Haeussge    if ( !$schemes ) {
1874c353447SChristopher Smith        $schemes = retrieveConfig('scheme','file',null,'array_merge_with_removal');
18836f2d7c1SGina Haeussge        $schemes = array_map('trim', $schemes);
18936f2d7c1SGina Haeussge        $schemes = preg_replace('/^#.*/', '', $schemes);
19036f2d7c1SGina Haeussge        $schemes = array_filter($schemes);
1914c353447SChristopher Smith    }
19236f2d7c1SGina Haeussge    return $schemes;
19336f2d7c1SGina Haeussge}
19436f2d7c1SGina Haeussge
195b9ac8716Schris/**
196edcb01e5SGina Haeussge * Builds a hash from an array of lines
197b625487dSandi *
1983fd0b676Sandi * If $lower is set to true all hash keys are converted to
1993fd0b676Sandi * lower case.
2003fd0b676Sandi *
201b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
2023fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org>
203edcb01e5SGina Haeussge * @author Gina Haeussge <gina@foosel.net>
204b625487dSandi */
205edcb01e5SGina Haeussgefunction linesToHash($lines, $lower=false) {
206e5fc893fSAndreas Gohr    $conf = array();
207dd74fecfSMichael Hamann    // remove BOM
208dd74fecfSMichael Hamann    if (isset($lines[0]) && substr($lines[0],0,3) == pack('CCC',0xef,0xbb,0xbf))
209dd74fecfSMichael Hamann        $lines[0] = substr($lines[0],3);
210b625487dSandi    foreach ( $lines as $line ) {
21103ff8795SAndreas Gohr        //ignore comments (except escaped ones)
21203ff8795SAndreas Gohr        $line = preg_replace('/(?<![&\\\\])#.*$/','',$line);
21303ff8795SAndreas Gohr        $line = str_replace('\\#','#',$line);
214b625487dSandi        $line = trim($line);
215b625487dSandi        if(empty($line)) continue;
216b625487dSandi        $line = preg_split('/\s+/',$line,2);
217b625487dSandi        // Build the associative array
21827a2b085Sandi        if($lower){
21927a2b085Sandi            $conf[strtolower($line[0])] = $line[1];
22027a2b085Sandi        }else{
221b625487dSandi            $conf[$line[0]] = $line[1];
222b625487dSandi        }
22327a2b085Sandi    }
224b625487dSandi
225b625487dSandi    return $conf;
226b625487dSandi}
227b625487dSandi
228409d7af7SAndreas Gohr/**
229edcb01e5SGina Haeussge * Builds a hash from a configfile
230edcb01e5SGina Haeussge *
231edcb01e5SGina Haeussge * If $lower is set to true all hash keys are converted to
232edcb01e5SGina Haeussge * lower case.
233edcb01e5SGina Haeussge *
234edcb01e5SGina Haeussge * @author Harry Fuecks <hfuecks@gmail.com>
235edcb01e5SGina Haeussge * @author Andreas Gohr <andi@splitbrain.org>
236edcb01e5SGina Haeussge * @author Gina Haeussge <gina@foosel.net>
237edcb01e5SGina Haeussge */
238edcb01e5SGina Haeussgefunction confToHash($file,$lower=false) {
239edcb01e5SGina Haeussge    $conf = array();
240edcb01e5SGina Haeussge    $lines = @file( $file );
241edcb01e5SGina Haeussge    if ( !$lines ) return $conf;
242edcb01e5SGina Haeussge
243edcb01e5SGina Haeussge    return linesToHash($lines, $lower);
244edcb01e5SGina Haeussge}
245edcb01e5SGina Haeussge
246edcb01e5SGina Haeussge/**
247cb043f52SChris Smith * Retrieve the requested configuration information
248cb043f52SChris Smith *
249cb043f52SChris Smith * @author Chris Smith <chris@jalakai.co.uk>
250cb043f52SChris Smith *
251cb043f52SChris Smith * @param  string   $type     the configuration settings to be read, must correspond to a key/array in $config_cascade
252cb043f52SChris Smith * @param  callback $fn       the function used to process the configuration file into an array
253e3ab6fc5SMichael Hamann * @param  array    $params   optional additional params to pass to the callback
2544286c64eSChristopher Smith * @param  callback $combine  the function used to combine arrays of values read from different configuration files;
2554286c64eSChristopher Smith *                            the function takes two parameters,
2564286c64eSChristopher Smith *                               $combined - the already read & merged configuration values
2574286c64eSChristopher Smith *                               $new - array of config values from the config cascade file being currently processed
2584286c64eSChristopher Smith *                            and returns an array of the merged configuration values.
259cb043f52SChris Smith * @return array    configuration values
260cb043f52SChris Smith */
2614c353447SChristopher Smithfunction retrieveConfig($type,$fn,$params=null,$combine='array_merge') {
262cb043f52SChris Smith    global $config_cascade;
263cb043f52SChris Smith
2644c6a5eccSAndreas Gohr    if(!is_array($params)) $params = array();
2654c6a5eccSAndreas Gohr
266cb043f52SChris Smith    $combined = array();
267cb043f52SChris Smith    if (!is_array($config_cascade[$type])) trigger_error('Missing config cascade for "'.$type.'"',E_USER_WARNING);
268b303b92cSChris Smith    foreach (array('default','local','protected') as $config_group) {
269b303b92cSChris Smith        if (empty($config_cascade[$type][$config_group])) continue;
270b303b92cSChris Smith        foreach ($config_cascade[$type][$config_group] as $file) {
27179e79377SAndreas Gohr            if (file_exists($file)) {
2724c6a5eccSAndreas Gohr                $config = call_user_func_array($fn,array_merge(array($file),$params));
2734c353447SChristopher Smith                $combined = $combine($combined, $config);
274cb043f52SChris Smith            }
275cb043f52SChris Smith        }
276b303b92cSChris Smith    }
277cb043f52SChris Smith
278cb043f52SChris Smith    return $combined;
279cb043f52SChris Smith}
280cb043f52SChris Smith
281cb043f52SChris Smith/**
282f8121585SChris Smith * Include the requested configuration information
283f8121585SChris Smith *
284f8121585SChris Smith * @author Chris Smith <chris@jalakai.co.uk>
285f8121585SChris Smith *
286f8121585SChris Smith * @param  string   $type     the configuration settings to be read, must correspond to a key/array in $config_cascade
287f8121585SChris Smith * @return array              list of files, default before local before protected
288f8121585SChris Smith */
289f8121585SChris Smithfunction getConfigFiles($type) {
290f8121585SChris Smith    global $config_cascade;
291f8121585SChris Smith    $files = array();
292f8121585SChris Smith
293f8121585SChris Smith    if (!is_array($config_cascade[$type])) trigger_error('Missing config cascade for "'.$type.'"',E_USER_WARNING);
294f8121585SChris Smith    foreach (array('default','local','protected') as $config_group) {
295f8121585SChris Smith        if (empty($config_cascade[$type][$config_group])) continue;
296f8121585SChris Smith        $files = array_merge($files, $config_cascade[$type][$config_group]);
297f8121585SChris Smith    }
298f8121585SChris Smith
299f8121585SChris Smith    return $files;
300f8121585SChris Smith}
301f8121585SChris Smith
302f8121585SChris Smith/**
303409d7af7SAndreas Gohr * check if the given action was disabled in config
304409d7af7SAndreas Gohr *
305409d7af7SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
3060e2431b7SGerrit Uitslag * @param string $action
307409d7af7SAndreas Gohr * @returns boolean true if enabled, false if disabled
308409d7af7SAndreas Gohr */
309409d7af7SAndreas Gohrfunction actionOK($action){
310409d7af7SAndreas Gohr    static $disabled = null;
311020ea9e1SChristopher Smith    if(is_null($disabled) || defined('SIMPLE_TEST')){
312409d7af7SAndreas Gohr        global $conf;
3130e2431b7SGerrit Uitslag        /** @var DokuWiki_Auth_Plugin $auth */
314de4d479aSAdrian Lang        global $auth;
315409d7af7SAndreas Gohr
316409d7af7SAndreas Gohr        // prepare disabled actions array and handle legacy options
317409d7af7SAndreas Gohr        $disabled = explode(',',$conf['disableactions']);
318409d7af7SAndreas Gohr        $disabled = array_map('trim',$disabled);
319e4eda66bSAndreas Gohr        if((isset($conf['openregister']) && !$conf['openregister']) || is_null($auth) || !$auth->canDo('addUser')) {
320de4d479aSAdrian Lang            $disabled[] = 'register';
321de4d479aSAdrian Lang        }
322e4eda66bSAndreas Gohr        if((isset($conf['resendpasswd']) && !$conf['resendpasswd']) || is_null($auth) || !$auth->canDo('modPass')) {
323de4d479aSAdrian Lang            $disabled[] = 'resendpwd';
324de4d479aSAdrian Lang        }
325e4eda66bSAndreas Gohr        if((isset($conf['subscribers']) && !$conf['subscribers']) || is_null($auth)) {
3263a48618aSAnika Henke            $disabled[] = 'subscribe';
3273a48618aSAnika Henke        }
3283a48618aSAnika Henke        if (is_null($auth) || !$auth->canDo('Profile')) {
3293a48618aSAnika Henke            $disabled[] = 'profile';
3303a48618aSAnika Henke        }
3312a7abf2dSChristopher Smith        if (is_null($auth) || !$auth->canDo('delUser')) {
3322a7abf2dSChristopher Smith            $disabled[] = 'profile_delete';
3332a7abf2dSChristopher Smith        }
3343a48618aSAnika Henke        if (is_null($auth)) {
3353a48618aSAnika Henke            $disabled[] = 'login';
3363a48618aSAnika Henke        }
3373a48618aSAnika Henke        if (is_null($auth) || !$auth->canDo('logout')) {
3383a48618aSAnika Henke            $disabled[] = 'logout';
3393a48618aSAnika Henke        }
340409d7af7SAndreas Gohr        $disabled = array_unique($disabled);
341409d7af7SAndreas Gohr    }
342409d7af7SAndreas Gohr
343409d7af7SAndreas Gohr    return !in_array($action,$disabled);
344409d7af7SAndreas Gohr}
345409d7af7SAndreas Gohr
346fe9ec250SChris Smith/**
347fe9ec250SChris Smith * check if headings should be used as link text for the specified link type
348fe9ec250SChris Smith *
349fe9ec250SChris Smith * @author Chris Smith <chris@jalakai.co.uk>
350fe9ec250SChris Smith *
351fe9ec250SChris Smith * @param   string  $linktype   'content'|'navigation', content applies to links in wiki text
352fe9ec250SChris Smith *                                                      navigation applies to all other links
353e3ab6fc5SMichael Hamann * @return  boolean             true if headings should be used for $linktype, false otherwise
354fe9ec250SChris Smith */
355fe9ec250SChris Smithfunction useHeading($linktype) {
356fe9ec250SChris Smith    static $useHeading = null;
357fe9ec250SChris Smith
358fe9ec250SChris Smith    if (is_null($useHeading)) {
359fe9ec250SChris Smith        global $conf;
360fe9ec250SChris Smith
361fe9ec250SChris Smith        if (!empty($conf['useheading'])) {
362fe9ec250SChris Smith            switch ($conf['useheading']) {
36349eb6e38SAndreas Gohr                case 'content':
36449eb6e38SAndreas Gohr                    $useHeading['content'] = true;
36549eb6e38SAndreas Gohr                    break;
36649eb6e38SAndreas Gohr
36749eb6e38SAndreas Gohr                case 'navigation':
36849eb6e38SAndreas Gohr                    $useHeading['navigation'] = true;
36949eb6e38SAndreas Gohr                    break;
370fe9ec250SChris Smith                default:
371fe9ec250SChris Smith                    $useHeading['content'] = true;
372fe9ec250SChris Smith                    $useHeading['navigation'] = true;
373fe9ec250SChris Smith            }
374fe9ec250SChris Smith        } else {
375fe9ec250SChris Smith            $useHeading = array();
376fe9ec250SChris Smith        }
377fe9ec250SChris Smith    }
378fe9ec250SChris Smith
379fe9ec250SChris Smith    return (!empty($useHeading[$linktype]));
380fe9ec250SChris Smith}
381fe9ec250SChris Smith
3823994772aSChris Smith/**
3833994772aSChris Smith * obscure config data so information isn't plain text
3843994772aSChris Smith *
3853994772aSChris Smith * @param string       $str     data to be encoded
3863994772aSChris Smith * @param string       $code    encoding method, values: plain, base64, uuencode.
3873994772aSChris Smith * @return string               the encoded value
3883994772aSChris Smith */
3893994772aSChris Smithfunction conf_encodeString($str,$code) {
3903994772aSChris Smith    switch ($code) {
3913994772aSChris Smith        case 'base64'   : return '<b>'.base64_encode($str);
3923994772aSChris Smith        case 'uuencode' : return '<u>'.convert_uuencode($str);
3933994772aSChris Smith        case 'plain':
3943994772aSChris Smith        default:
3953994772aSChris Smith                          return $str;
3963994772aSChris Smith    }
3973994772aSChris Smith}
3983994772aSChris Smith/**
3993994772aSChris Smith * return obscured data as plain text
4003994772aSChris Smith *
4013994772aSChris Smith * @param  string      $str   encoded data
4023994772aSChris Smith * @return string             plain text
4033994772aSChris Smith */
4043994772aSChris Smithfunction conf_decodeString($str) {
4053994772aSChris Smith    switch (substr($str,0,3)) {
4063994772aSChris Smith        case '<b>' : return base64_decode(substr($str,3));
4073994772aSChris Smith        case '<u>' : return convert_uudecode(substr($str,3));
408b96ff25bSElan Ruusamäe        default:  // not encoded (or unknown)
4093994772aSChris Smith                     return $str;
4103994772aSChris Smith    }
4113994772aSChris Smith}
4124c353447SChristopher Smith
4134c353447SChristopher Smith/**
4144c353447SChristopher Smith * array combination function to remove negated values (prefixed by !)
4154c353447SChristopher Smith *
4164c353447SChristopher Smith * @param  array $current
4174c353447SChristopher Smith * @param  array $new
4184c353447SChristopher Smith *
4194c353447SChristopher Smith * @return array the combined array, numeric keys reset
4204c353447SChristopher Smith */
4214c353447SChristopher Smithfunction array_merge_with_removal($current, $new) {
4224c353447SChristopher Smith    foreach ($new as $val) {
42310b38f10SChristopher Smith        if (substr($val,0,1) == DOKU_CONF_NEGATION) {
4243a7669bdSChristopher Smith            $idx = array_search(trim(substr($val,1)),$current);
4254c353447SChristopher Smith            if ($idx !== false) {
4264c353447SChristopher Smith                unset($current[$idx]);
4274c353447SChristopher Smith            }
4284c353447SChristopher Smith        } else {
4293a7669bdSChristopher Smith            $current[] = trim($val);
4304c353447SChristopher Smith        }
4314c353447SChristopher Smith    }
4324c353447SChristopher Smith
4334c353447SChristopher Smith    return array_slice($current,0);
4344c353447SChristopher Smith}
435e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
436