xref: /dokuwiki/inc/confutils.php (revision e1d9dcc8b460b6f029ac9c8d5d3b8d23b6e73402)
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 */
14*e1d9dcc8SAndreas Gohr
15*e1d9dcc8SAndreas Gohruse dokuwiki\Extension\AuthPlugin;
16*e1d9dcc8SAndreas Gohruse dokuwiki\Extension\Event;
1710b38f10SChristopher Smithconst DOKU_CONF_NEGATION = '!';
18b625487dSandi
19b625487dSandi/**
20b625487dSandi * Returns the (known) extension and mimetype of a given filename
21b625487dSandi *
2227bf7924STom N Harris * If $knownonly is true (the default), then only known extensions
2327bf7924STom N Harris * are returned.
2427bf7924STom N Harris *
25b625487dSandi * @author Andreas Gohr <andi@splitbrain.org>
2642ea7f44SGerrit Uitslag *
2742ea7f44SGerrit Uitslag * @param string $file file name
2842ea7f44SGerrit Uitslag * @param bool   $knownonly
2942ea7f44SGerrit Uitslag * @return array with extension, mimetype and if it should be downloaded
30b625487dSandi */
3127bf7924STom N Harrisfunction mimetype($file, $knownonly=true){
32b625487dSandi    $mtypes = getMimeTypes();     // known mimetypes
33ad74fe66SAdrian Lang    $ext    = strrpos($file, '.');
34ad74fe66SAdrian Lang    if ($ext === false) {
35ad74fe66SAdrian Lang        return array(false, false, false);
3627bf7924STom N Harris    }
37ad74fe66SAdrian Lang    $ext = strtolower(substr($file, $ext + 1));
38ad74fe66SAdrian Lang    if (!isset($mtypes[$ext])){
39ad74fe66SAdrian Lang        if ($knownonly) {
40ad74fe66SAdrian Lang            return array(false, false, false);
41ecebf3a8SAndreas Gohr        } else {
42ad74fe66SAdrian Lang            return array($ext, 'application/octet-stream', true);
4327bf7924STom N Harris        }
44b625487dSandi    }
45ad74fe66SAdrian Lang    if($mtypes[$ext][0] == '!'){
46ad74fe66SAdrian Lang        return array($ext, substr($mtypes[$ext],1), true);
47ad74fe66SAdrian Lang    }else{
48ad74fe66SAdrian Lang        return array($ext, $mtypes[$ext], false);
49ad74fe66SAdrian Lang    }
50b625487dSandi}
51b625487dSandi
52b625487dSandi/**
53b625487dSandi * returns a hash of mimetypes
54b625487dSandi *
55b625487dSandi * @author Andreas Gohr <andi@splitbrain.org>
56b625487dSandi */
57b625487dSandifunction getMimeTypes() {
5849eb6e38SAndreas Gohr    static $mime = null;
59b625487dSandi    if ( !$mime ) {
60cb043f52SChris Smith        $mime = retrieveConfig('mime','confToHash');
6145ae4bb8SChristopher Smith        $mime = array_filter($mime);
62b625487dSandi    }
63b625487dSandi    return $mime;
64b625487dSandi}
65b625487dSandi
66b625487dSandi/**
67b625487dSandi * returns a hash of acronyms
68b625487dSandi *
69b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
70b625487dSandi */
71b625487dSandifunction getAcronyms() {
7249eb6e38SAndreas Gohr    static $acronyms = null;
73b625487dSandi    if ( !$acronyms ) {
74cb043f52SChris Smith        $acronyms = retrieveConfig('acronyms','confToHash');
75f266a919SChristopher Smith        $acronyms = array_filter($acronyms, 'strlen');
76b625487dSandi    }
77b625487dSandi    return $acronyms;
78b625487dSandi}
79b625487dSandi
80b625487dSandi/**
81b625487dSandi * returns a hash of smileys
82b625487dSandi *
83b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
84b625487dSandi */
85b625487dSandifunction getSmileys() {
8649eb6e38SAndreas Gohr    static $smileys = null;
87b625487dSandi    if ( !$smileys ) {
88cb043f52SChris Smith        $smileys = retrieveConfig('smileys','confToHash');
89f266a919SChristopher Smith        $smileys = array_filter($smileys, 'strlen');
90b625487dSandi    }
91b625487dSandi    return $smileys;
92b625487dSandi}
93b625487dSandi
94b625487dSandi/**
95b625487dSandi * returns a hash of entities
96b625487dSandi *
97b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
98b625487dSandi */
99b625487dSandifunction getEntities() {
10049eb6e38SAndreas Gohr    static $entities = null;
101b625487dSandi    if ( !$entities ) {
102cb043f52SChris Smith        $entities = retrieveConfig('entities','confToHash');
103f266a919SChristopher Smith        $entities = array_filter($entities, 'strlen');
104b625487dSandi    }
105b625487dSandi    return $entities;
106b625487dSandi}
107b625487dSandi
108b625487dSandi/**
109b625487dSandi * returns a hash of interwikilinks
110b625487dSandi *
111b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
112b625487dSandi */
113b625487dSandifunction getInterwiki() {
11449eb6e38SAndreas Gohr    static $wikis = null;
115b625487dSandi    if ( !$wikis ) {
1164c6a5eccSAndreas Gohr        $wikis = retrieveConfig('interwiki','confToHash',array(true));
117f266a919SChristopher Smith        $wikis = array_filter($wikis, 'strlen');
11845ae4bb8SChristopher Smith
11997a3e4e3Sandi        //add sepecial case 'this'
12027a2b085Sandi        $wikis['this'] = DOKU_URL.'{NAME}';
12145ae4bb8SChristopher Smith    }
122b625487dSandi    return $wikis;
123b625487dSandi}
124b625487dSandi
125b625487dSandi/**
126fa078663SAndreas Gohr * Returns the jquery script URLs for the versions defined in lib/scripts/jquery/versions
12761537d47SAndreas Gohr *
128fa078663SAndreas Gohr * @trigger CONFUTIL_CDN_SELECT
12961537d47SAndreas Gohr * @return array
13061537d47SAndreas Gohr */
131fa078663SAndreas Gohrfunction getCdnUrls() {
132fa078663SAndreas Gohr    global $conf;
133fa078663SAndreas Gohr
134fa078663SAndreas Gohr    // load version info
13561537d47SAndreas Gohr    $versions = array();
13661537d47SAndreas Gohr    $lines = file(DOKU_INC . 'lib/scripts/jquery/versions');
13761537d47SAndreas Gohr    foreach($lines as $line) {
1386453acd5SAndreas Gohr        $line = trim(preg_replace('/#.*$/', '', $line));
1396453acd5SAndreas Gohr        if($line === '') continue;
14061537d47SAndreas Gohr        list($key, $val) = explode('=', $line, 2);
14161537d47SAndreas Gohr        $key = trim($key);
14261537d47SAndreas Gohr        $val = trim($val);
14361537d47SAndreas Gohr        $versions[$key] = $val;
14461537d47SAndreas Gohr    }
145fa078663SAndreas Gohr
146fa078663SAndreas Gohr    $src = array();
147fa078663SAndreas Gohr    $data = array(
148fa078663SAndreas Gohr        'versions' => $versions,
149fa078663SAndreas Gohr        'src' => &$src
150fa078663SAndreas Gohr    );
151*e1d9dcc8SAndreas Gohr    $event = new Event('CONFUTIL_CDN_SELECT', $data);
152fa078663SAndreas Gohr    if($event->advise_before()) {
153fa078663SAndreas Gohr        if(!$conf['jquerycdn']) {
154fa078663SAndreas Gohr            $jqmod = md5(join('-', $versions));
155fa078663SAndreas Gohr            $src[] = DOKU_BASE . 'lib/exe/jquery.php' . '?tseed=' . $jqmod;
156fa078663SAndreas Gohr        } elseif($conf['jquerycdn'] == 'jquery') {
157fa078663SAndreas Gohr            $src[] = sprintf('https://code.jquery.com/jquery-%s.min.js', $versions['JQ_VERSION']);
158fa078663SAndreas Gohr            $src[] = sprintf('https://code.jquery.com/jquery-migrate-%s.min.js', $versions['JQM_VERSION']);
159fa078663SAndreas Gohr            $src[] = sprintf('https://code.jquery.com/ui/%s/jquery-ui.min.js', $versions['JQUI_VERSION']);
160fa078663SAndreas Gohr        } elseif($conf['jquerycdn'] == 'cdnjs') {
16164159a61SAndreas Gohr            $src[] = sprintf(
16264159a61SAndreas Gohr                'https://cdnjs.cloudflare.com/ajax/libs/jquery/%s/jquery.min.js',
16364159a61SAndreas Gohr                $versions['JQ_VERSION']
16464159a61SAndreas Gohr            );
16564159a61SAndreas Gohr            $src[] = sprintf(
16664159a61SAndreas Gohr                'https://cdnjs.cloudflare.com/ajax/libs/jquery-migrate/%s/jquery-migrate.min.js',
16764159a61SAndreas Gohr                $versions['JQM_VERSION']
16864159a61SAndreas Gohr            );
16964159a61SAndreas Gohr            $src[] = sprintf(
17064159a61SAndreas Gohr                'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/%s/jquery-ui.min.js',
17164159a61SAndreas Gohr                $versions['JQUI_VERSION']
17264159a61SAndreas Gohr            );
173fa078663SAndreas Gohr        }
174fa078663SAndreas Gohr    }
175fa078663SAndreas Gohr    $event->advise_after();
176fa078663SAndreas Gohr
177fa078663SAndreas Gohr    return $src;
17861537d47SAndreas Gohr}
17961537d47SAndreas Gohr
18061537d47SAndreas Gohr/**
181b9ac8716Schris * returns array of wordblock patterns
182b9ac8716Schris *
183b9ac8716Schris */
184b9ac8716Schrisfunction getWordblocks() {
18549eb6e38SAndreas Gohr    static $wordblocks = null;
186b9ac8716Schris    if ( !$wordblocks ) {
1874c353447SChristopher Smith        $wordblocks = retrieveConfig('wordblock','file',null,'array_merge_with_removal');
188b9ac8716Schris    }
189b9ac8716Schris    return $wordblocks;
190b9ac8716Schris}
191b9ac8716Schris
192e3ab6fc5SMichael Hamann/**
193e3ab6fc5SMichael Hamann * Gets the list of configured schemes
194e3ab6fc5SMichael Hamann *
195e3ab6fc5SMichael Hamann * @return array the schemes
196e3ab6fc5SMichael Hamann */
19736f2d7c1SGina Haeussgefunction getSchemes() {
19849eb6e38SAndreas Gohr    static $schemes = null;
19936f2d7c1SGina Haeussge    if ( !$schemes ) {
2004c353447SChristopher Smith        $schemes = retrieveConfig('scheme','file',null,'array_merge_with_removal');
20136f2d7c1SGina Haeussge        $schemes = array_map('trim', $schemes);
20236f2d7c1SGina Haeussge        $schemes = preg_replace('/^#.*/', '', $schemes);
20336f2d7c1SGina Haeussge        $schemes = array_filter($schemes);
2044c353447SChristopher Smith    }
20536f2d7c1SGina Haeussge    return $schemes;
20636f2d7c1SGina Haeussge}
20736f2d7c1SGina Haeussge
208b9ac8716Schris/**
209edcb01e5SGina Haeussge * Builds a hash from an array of lines
210b625487dSandi *
2113fd0b676Sandi * If $lower is set to true all hash keys are converted to
2123fd0b676Sandi * lower case.
2133fd0b676Sandi *
214b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
2153fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org>
216edcb01e5SGina Haeussge * @author Gina Haeussge <gina@foosel.net>
217f50a239bSTakamura *
218f50a239bSTakamura * @param array $lines
219f50a239bSTakamura * @param bool $lower
220f50a239bSTakamura *
221f50a239bSTakamura * @return array
222b625487dSandi */
223edcb01e5SGina Haeussgefunction linesToHash($lines, $lower = false) {
224e5fc893fSAndreas Gohr    $conf = array();
225dd74fecfSMichael Hamann    // remove BOM
226dd74fecfSMichael Hamann    if(isset($lines[0]) && substr($lines[0], 0, 3) == pack('CCC', 0xef, 0xbb, 0xbf))
227dd74fecfSMichael Hamann        $lines[0] = substr($lines[0], 3);
228b625487dSandi    foreach($lines as $line) {
22903ff8795SAndreas Gohr        //ignore comments (except escaped ones)
23003ff8795SAndreas Gohr        $line = preg_replace('/(?<![&\\\\])#.*$/', '', $line);
23103ff8795SAndreas Gohr        $line = str_replace('\\#', '#', $line);
232b625487dSandi        $line = trim($line);
23359ed97f2SAndreas Gohr        if($line === '') continue;
234b625487dSandi        $line = preg_split('/\s+/', $line, 2);
23559ed97f2SAndreas Gohr        $line = array_pad($line, 2, '');
236b625487dSandi        // Build the associative array
23727a2b085Sandi        if($lower) {
23827a2b085Sandi            $conf[strtolower($line[0])] = $line[1];
23927a2b085Sandi        } else {
240b625487dSandi            $conf[$line[0]] = $line[1];
241b625487dSandi        }
24227a2b085Sandi    }
243b625487dSandi
244b625487dSandi    return $conf;
245b625487dSandi}
246b625487dSandi
247409d7af7SAndreas Gohr/**
248edcb01e5SGina Haeussge * Builds a hash from a configfile
249edcb01e5SGina Haeussge *
250edcb01e5SGina Haeussge * If $lower is set to true all hash keys are converted to
251edcb01e5SGina Haeussge * lower case.
252edcb01e5SGina Haeussge *
253edcb01e5SGina Haeussge * @author Harry Fuecks <hfuecks@gmail.com>
254edcb01e5SGina Haeussge * @author Andreas Gohr <andi@splitbrain.org>
255edcb01e5SGina Haeussge * @author Gina Haeussge <gina@foosel.net>
256f50a239bSTakamura *
257f50a239bSTakamura * @param string $file
258f50a239bSTakamura * @param bool $lower
259f50a239bSTakamura *
260f50a239bSTakamura * @return array
261edcb01e5SGina Haeussge */
262edcb01e5SGina Haeussgefunction confToHash($file,$lower=false) {
263edcb01e5SGina Haeussge    $conf = array();
264edcb01e5SGina Haeussge    $lines = @file( $file );
265edcb01e5SGina Haeussge    if ( !$lines ) return $conf;
266edcb01e5SGina Haeussge
267edcb01e5SGina Haeussge    return linesToHash($lines, $lower);
268edcb01e5SGina Haeussge}
269edcb01e5SGina Haeussge
270edcb01e5SGina Haeussge/**
271c9071834SMichael Große * Read a json config file into an array
272c9071834SMichael Große *
273c9071834SMichael Große * @param string $file
274c9071834SMichael Große * @return array
275c9071834SMichael Große */
276c9071834SMichael Großefunction jsonToArray($file)
277c9071834SMichael Große{
278c9071834SMichael Große    $json = file_get_contents($file);
279c9071834SMichael Große
280c9071834SMichael Große    $conf = json_decode($json, true);
281c9071834SMichael Große
282dceb2cc1SMichael Große    if ($conf === null) {
283c9071834SMichael Große        return [];
284c9071834SMichael Große    }
285c9071834SMichael Große
286c9071834SMichael Große    return $conf;
287c9071834SMichael Große}
288c9071834SMichael Große
289c9071834SMichael Große/**
290cb043f52SChris Smith * Retrieve the requested configuration information
291cb043f52SChris Smith *
292cb043f52SChris Smith * @author Chris Smith <chris@jalakai.co.uk>
293cb043f52SChris Smith *
294cb043f52SChris Smith * @param  string   $type     the configuration settings to be read, must correspond to a key/array in $config_cascade
295cb043f52SChris Smith * @param  callback $fn       the function used to process the configuration file into an array
296e3ab6fc5SMichael Hamann * @param  array    $params   optional additional params to pass to the callback
2975a9597bbSTakamura * @param  callback $combine  the function used to combine arrays of values read from different configuration files;
298074b2b3fSTakamura *                            the function takes two parameters,
299074b2b3fSTakamura *                               $combined - the already read & merged configuration values
300074b2b3fSTakamura *                               $new - array of config values from the config cascade file being currently processed
301074b2b3fSTakamura *                            and returns an array of the merged configuration values.
302cb043f52SChris Smith * @return array    configuration values
303cb043f52SChris Smith */
3044c353447SChristopher Smithfunction retrieveConfig($type,$fn,$params=null,$combine='array_merge') {
305cb043f52SChris Smith    global $config_cascade;
306cb043f52SChris Smith
3074c6a5eccSAndreas Gohr    if(!is_array($params)) $params = array();
3084c6a5eccSAndreas Gohr
309cb043f52SChris Smith    $combined = array();
310cb043f52SChris Smith    if (!is_array($config_cascade[$type])) trigger_error('Missing config cascade for "'.$type.'"',E_USER_WARNING);
311b303b92cSChris Smith    foreach (array('default','local','protected') as $config_group) {
312b303b92cSChris Smith        if (empty($config_cascade[$type][$config_group])) continue;
313b303b92cSChris Smith        foreach ($config_cascade[$type][$config_group] as $file) {
31479e79377SAndreas Gohr            if (file_exists($file)) {
3154c6a5eccSAndreas Gohr                $config = call_user_func_array($fn,array_merge(array($file),$params));
3164c353447SChristopher Smith                $combined = $combine($combined, $config);
317cb043f52SChris Smith            }
318cb043f52SChris Smith        }
319b303b92cSChris Smith    }
320cb043f52SChris Smith
321cb043f52SChris Smith    return $combined;
322cb043f52SChris Smith}
323cb043f52SChris Smith
324cb043f52SChris Smith/**
325f8121585SChris Smith * Include the requested configuration information
326f8121585SChris Smith *
327f8121585SChris Smith * @author Chris Smith <chris@jalakai.co.uk>
328f8121585SChris Smith *
329f8121585SChris Smith * @param  string   $type     the configuration settings to be read, must correspond to a key/array in $config_cascade
330f8121585SChris Smith * @return array              list of files, default before local before protected
331f8121585SChris Smith */
332f8121585SChris Smithfunction getConfigFiles($type) {
333f8121585SChris Smith    global $config_cascade;
334f8121585SChris Smith    $files = array();
335f8121585SChris Smith
336f8121585SChris Smith    if (!is_array($config_cascade[$type])) trigger_error('Missing config cascade for "'.$type.'"',E_USER_WARNING);
337f8121585SChris Smith    foreach (array('default','local','protected') as $config_group) {
338f8121585SChris Smith        if (empty($config_cascade[$type][$config_group])) continue;
339f8121585SChris Smith        $files = array_merge($files, $config_cascade[$type][$config_group]);
340f8121585SChris Smith    }
341f8121585SChris Smith
342f8121585SChris Smith    return $files;
343f8121585SChris Smith}
344f8121585SChris Smith
345f8121585SChris Smith/**
346409d7af7SAndreas Gohr * check if the given action was disabled in config
347409d7af7SAndreas Gohr *
348409d7af7SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
3490e2431b7SGerrit Uitslag * @param string $action
350409d7af7SAndreas Gohr * @returns boolean true if enabled, false if disabled
351409d7af7SAndreas Gohr */
352409d7af7SAndreas Gohrfunction actionOK($action){
353409d7af7SAndreas Gohr    static $disabled = null;
354020ea9e1SChristopher Smith    if(is_null($disabled) || defined('SIMPLE_TEST')){
355409d7af7SAndreas Gohr        global $conf;
356*e1d9dcc8SAndreas Gohr        /** @var AuthPlugin $auth */
357de4d479aSAdrian Lang        global $auth;
358409d7af7SAndreas Gohr
359409d7af7SAndreas Gohr        // prepare disabled actions array and handle legacy options
360409d7af7SAndreas Gohr        $disabled = explode(',',$conf['disableactions']);
361409d7af7SAndreas Gohr        $disabled = array_map('trim',$disabled);
362e4eda66bSAndreas Gohr        if((isset($conf['openregister']) && !$conf['openregister']) || is_null($auth) || !$auth->canDo('addUser')) {
363de4d479aSAdrian Lang            $disabled[] = 'register';
364de4d479aSAdrian Lang        }
365e4eda66bSAndreas Gohr        if((isset($conf['resendpasswd']) && !$conf['resendpasswd']) || is_null($auth) || !$auth->canDo('modPass')) {
366de4d479aSAdrian Lang            $disabled[] = 'resendpwd';
367de4d479aSAdrian Lang        }
368e4eda66bSAndreas Gohr        if((isset($conf['subscribers']) && !$conf['subscribers']) || is_null($auth)) {
3693a48618aSAnika Henke            $disabled[] = 'subscribe';
3703a48618aSAnika Henke        }
3713a48618aSAnika Henke        if (is_null($auth) || !$auth->canDo('Profile')) {
3723a48618aSAnika Henke            $disabled[] = 'profile';
3733a48618aSAnika Henke        }
3742a7abf2dSChristopher Smith        if (is_null($auth) || !$auth->canDo('delUser')) {
3752a7abf2dSChristopher Smith            $disabled[] = 'profile_delete';
3762a7abf2dSChristopher Smith        }
3773a48618aSAnika Henke        if (is_null($auth)) {
3783a48618aSAnika Henke            $disabled[] = 'login';
3793a48618aSAnika Henke        }
3803a48618aSAnika Henke        if (is_null($auth) || !$auth->canDo('logout')) {
3813a48618aSAnika Henke            $disabled[] = 'logout';
3823a48618aSAnika Henke        }
383409d7af7SAndreas Gohr        $disabled = array_unique($disabled);
384409d7af7SAndreas Gohr    }
385409d7af7SAndreas Gohr
386409d7af7SAndreas Gohr    return !in_array($action,$disabled);
387409d7af7SAndreas Gohr}
388409d7af7SAndreas Gohr
389fe9ec250SChris Smith/**
390fe9ec250SChris Smith * check if headings should be used as link text for the specified link type
391fe9ec250SChris Smith *
392fe9ec250SChris Smith * @author Chris Smith <chris@jalakai.co.uk>
393fe9ec250SChris Smith *
394fe9ec250SChris Smith * @param   string  $linktype   'content'|'navigation', content applies to links in wiki text
395fe9ec250SChris Smith *                                                      navigation applies to all other links
396e3ab6fc5SMichael Hamann * @return  boolean             true if headings should be used for $linktype, false otherwise
397fe9ec250SChris Smith */
398fe9ec250SChris Smithfunction useHeading($linktype) {
399fe9ec250SChris Smith    static $useHeading = null;
4006506eaacSAndreas Gohr    if(defined('DOKU_UNITTEST')) $useHeading = null; // don't cache during unit tests
401fe9ec250SChris Smith
402fe9ec250SChris Smith    if (is_null($useHeading)) {
403fe9ec250SChris Smith        global $conf;
404fe9ec250SChris Smith
405fe9ec250SChris Smith        if (!empty($conf['useheading'])) {
406fe9ec250SChris Smith            switch ($conf['useheading']) {
40749eb6e38SAndreas Gohr                case 'content':
40849eb6e38SAndreas Gohr                    $useHeading['content'] = true;
40949eb6e38SAndreas Gohr                    break;
41049eb6e38SAndreas Gohr
41149eb6e38SAndreas Gohr                case 'navigation':
41249eb6e38SAndreas Gohr                    $useHeading['navigation'] = true;
41349eb6e38SAndreas Gohr                    break;
414fe9ec250SChris Smith                default:
415fe9ec250SChris Smith                    $useHeading['content'] = true;
416fe9ec250SChris Smith                    $useHeading['navigation'] = true;
417fe9ec250SChris Smith            }
418fe9ec250SChris Smith        } else {
419fe9ec250SChris Smith            $useHeading = array();
420fe9ec250SChris Smith        }
421fe9ec250SChris Smith    }
422fe9ec250SChris Smith
423fe9ec250SChris Smith    return (!empty($useHeading[$linktype]));
424fe9ec250SChris Smith}
425fe9ec250SChris Smith
4263994772aSChris Smith/**
4273994772aSChris Smith * obscure config data so information isn't plain text
4283994772aSChris Smith *
4293994772aSChris Smith * @param string       $str     data to be encoded
4303994772aSChris Smith * @param string       $code    encoding method, values: plain, base64, uuencode.
4313994772aSChris Smith * @return string               the encoded value
4323994772aSChris Smith */
4333994772aSChris Smithfunction conf_encodeString($str,$code) {
4343994772aSChris Smith    switch ($code) {
4353994772aSChris Smith        case 'base64'   : return '<b>'.base64_encode($str);
4363994772aSChris Smith        case 'uuencode' : return '<u>'.convert_uuencode($str);
4373994772aSChris Smith        case 'plain':
4383994772aSChris Smith        default:
4393994772aSChris Smith                          return $str;
4403994772aSChris Smith    }
4413994772aSChris Smith}
4423994772aSChris Smith/**
4433994772aSChris Smith * return obscured data as plain text
4443994772aSChris Smith *
4453994772aSChris Smith * @param  string      $str   encoded data
4463994772aSChris Smith * @return string             plain text
4473994772aSChris Smith */
4483994772aSChris Smithfunction conf_decodeString($str) {
4493994772aSChris Smith    switch (substr($str,0,3)) {
4503994772aSChris Smith        case '<b>' : return base64_decode(substr($str,3));
4513994772aSChris Smith        case '<u>' : return convert_uudecode(substr($str,3));
452b96ff25bSElan Ruusamäe        default:  // not encoded (or unknown)
4533994772aSChris Smith                     return $str;
4543994772aSChris Smith    }
4553994772aSChris Smith}
4564c353447SChristopher Smith
4574c353447SChristopher Smith/**
4584c353447SChristopher Smith * array combination function to remove negated values (prefixed by !)
4594c353447SChristopher Smith *
4604c353447SChristopher Smith * @param  array $current
4614c353447SChristopher Smith * @param  array $new
4624c353447SChristopher Smith *
4634c353447SChristopher Smith * @return array the combined array, numeric keys reset
4644c353447SChristopher Smith */
4654c353447SChristopher Smithfunction array_merge_with_removal($current, $new) {
4664c353447SChristopher Smith    foreach ($new as $val) {
46710b38f10SChristopher Smith        if (substr($val,0,1) == DOKU_CONF_NEGATION) {
4683a7669bdSChristopher Smith            $idx = array_search(trim(substr($val,1)),$current);
4694c353447SChristopher Smith            if ($idx !== false) {
4704c353447SChristopher Smith                unset($current[$idx]);
4714c353447SChristopher Smith            }
4724c353447SChristopher Smith        } else {
4733a7669bdSChristopher Smith            $current[] = trim($val);
4744c353447SChristopher Smith        }
4754c353447SChristopher Smith    }
4764c353447SChristopher Smith
4774c353447SChristopher Smith    return array_slice($current,0);
4784c353447SChristopher Smith}
479e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
480