summaryrefslogtreecommitdiff
path: root/inc/confutils.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2015-06-26 11:07:20 +0200
committerAndreas Gohr <andi@splitbrain.org>2015-06-26 11:07:20 +0200
commit5ddba4576a304c9e62b028c97ee466d79de12429 (patch)
tree03199c579f9302f0ed1e0b47f9c597a7f9bd2fc7 /inc/confutils.php
parent5114259bf530b89afbb21bd693b1da3f96016b7f (diff)
parent71c46303d9cd8a321e58a7e7255d13f0d5a5c4eb (diff)
downloadrpg-5ddba4576a304c9e62b028c97ee466d79de12429.tar.gz
rpg-5ddba4576a304c9e62b028c97ee466d79de12429.tar.bz2
Merge branch 'master' into styler
* master: (26 commits) translation update translation update Replace old constructor call by __construct() in dokuwiki_xmlrpc_server translation update change two spaces to a space translation update translation update translation update translation update Upgrade to jQuery 1.11.3 and jQueryUI 1.11.4 closes #1175 update confToHash() inline documentation for new parameter translation update Plugins can send usage data fixed isBundled() check when remote info is unavailable avoid accessing nonexistant array key. fixes #1165 translation update Define the negation character in a constant Ensure single value negation is not affected by white space differences Ensure filtering only removes empty string values (not other values which PHP evaluates to false) translation update ...
Diffstat (limited to 'inc/confutils.php')
-rw-r--r--inc/confutils.php58
1 files changed, 49 insertions, 9 deletions
diff --git a/inc/confutils.php b/inc/confutils.php
index 8643a056c..8b61a8d5b 100644
--- a/inc/confutils.php
+++ b/inc/confutils.php
@@ -6,6 +6,12 @@
* @author Harry Fuecks <hfuecks@gmail.com>
*/
+/*
+ * line prefix used to negate single value config items
+ * (scheme.conf & stopwords.conf), e.g.
+ * !gopher
+ */
+const DOKU_CONF_NEGATION = '!';
/**
* Returns the (known) extension and mimetype of a given filename
@@ -49,6 +55,7 @@ function getMimeTypes() {
static $mime = null;
if ( !$mime ) {
$mime = retrieveConfig('mime','confToHash');
+ $mime = array_filter($mime);
}
return $mime;
}
@@ -62,6 +69,7 @@ function getAcronyms() {
static $acronyms = null;
if ( !$acronyms ) {
$acronyms = retrieveConfig('acronyms','confToHash');
+ $acronyms = array_filter($acronyms, 'strlen');
}
return $acronyms;
}
@@ -75,6 +83,7 @@ function getSmileys() {
static $smileys = null;
if ( !$smileys ) {
$smileys = retrieveConfig('smileys','confToHash');
+ $smileys = array_filter($smileys, 'strlen');
}
return $smileys;
}
@@ -88,6 +97,7 @@ function getEntities() {
static $entities = null;
if ( !$entities ) {
$entities = retrieveConfig('entities','confToHash');
+ $entities = array_filter($entities, 'strlen');
}
return $entities;
}
@@ -101,9 +111,11 @@ function getInterwiki() {
static $wikis = null;
if ( !$wikis ) {
$wikis = retrieveConfig('interwiki','confToHash',array(true));
+ $wikis = array_filter($wikis, 'strlen');
+
+ //add sepecial case 'this'
+ $wikis['this'] = DOKU_URL.'{NAME}';
}
- //add sepecial case 'this'
- $wikis['this'] = DOKU_URL.'{NAME}';
return $wikis;
}
@@ -114,7 +126,7 @@ function getInterwiki() {
function getWordblocks() {
static $wordblocks = null;
if ( !$wordblocks ) {
- $wordblocks = retrieveConfig('wordblock','file');
+ $wordblocks = retrieveConfig('wordblock','file',null,'array_merge_with_removal');
}
return $wordblocks;
}
@@ -127,11 +139,11 @@ function getWordblocks() {
function getSchemes() {
static $schemes = null;
if ( !$schemes ) {
- $schemes = retrieveConfig('scheme','file');
+ $schemes = retrieveConfig('scheme','file',null,'array_merge_with_removal');
+ $schemes = array_map('trim', $schemes);
+ $schemes = preg_replace('/^#.*/', '', $schemes);
+ $schemes = array_filter($schemes);
}
- $schemes = array_map('trim', $schemes);
- $schemes = preg_replace('/^#.*/', '', $schemes);
- $schemes = array_filter($schemes);
return $schemes;
}
@@ -194,9 +206,14 @@ function confToHash($file,$lower=false) {
* @param string $type the configuration settings to be read, must correspond to a key/array in $config_cascade
* @param callback $fn the function used to process the configuration file into an array
* @param array $params optional additional params to pass to the callback
+ * @param callback $combine the function used to combine arrays of values read from different configuration files;
+ * the function takes two parameters,
+ * $combined - the already read & merged configuration values
+ * $new - array of config values from the config cascade file being currently processed
+ * and returns an array of the merged configuration values.
* @return array configuration values
*/
-function retrieveConfig($type,$fn,$params=null) {
+function retrieveConfig($type,$fn,$params=null,$combine='array_merge') {
global $config_cascade;
if(!is_array($params)) $params = array();
@@ -208,7 +225,7 @@ function retrieveConfig($type,$fn,$params=null) {
foreach ($config_cascade[$type][$config_group] as $file) {
if (file_exists($file)) {
$config = call_user_func_array($fn,array_merge(array($file),$params));
- $combined = array_merge($combined, $config);
+ $combined = $combine($combined, $config);
}
}
}
@@ -347,4 +364,27 @@ function conf_decodeString($str) {
return $str;
}
}
+
+/**
+ * array combination function to remove negated values (prefixed by !)
+ *
+ * @param array $current
+ * @param array $new
+ *
+ * @return array the combined array, numeric keys reset
+ */
+function array_merge_with_removal($current, $new) {
+ foreach ($new as $val) {
+ if (substr($val,0,1) == DOKU_CONF_NEGATION) {
+ $idx = array_search(trim(substr($val,1)),$current);
+ if ($idx !== false) {
+ unset($current[$idx]);
+ }
+ } else {
+ $current[] = trim($val);
+ }
+ }
+
+ return array_slice($current,0);
+}
//Setup VIM: ex: et ts=4 :