From 42ea7f447f39fbc2f79eaaec31f8c10ede59c5d0 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 11:30:27 +0200 Subject: Many PHPDocs, some unused and dyn declared vars many PHPDocs some unused variables some dynamically declared variables declared --- inc/confutils.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'inc/confutils.php') diff --git a/inc/confutils.php b/inc/confutils.php index 31371d41f..85bf5128c 100644 --- a/inc/confutils.php +++ b/inc/confutils.php @@ -14,6 +14,10 @@ * are returned. * * @author Andreas Gohr + * + * @param string $file file name + * @param bool $knownonly + * @return array with extension, mimetype and if it should be downloaded */ function mimetype($file, $knownonly=true){ $mtypes = getMimeTypes(); // known mimetypes -- cgit v1.2.3 From 79e79377626799a77c11aa7849cb9c64305590c8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 7 Jan 2015 10:47:45 +0100 Subject: Remove error supression for file_exists() In an older version of PHP a file_exists() call would issue a warning when the file did not exist. This was fixed in later PHP releases. Since we require PHP 5.3 now, there's no need to supress any error here anymore. This might even give a minor performance boost. --- inc/confutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/confutils.php') diff --git a/inc/confutils.php b/inc/confutils.php index 85bf5128c..8643a056c 100644 --- a/inc/confutils.php +++ b/inc/confutils.php @@ -206,7 +206,7 @@ function retrieveConfig($type,$fn,$params=null) { foreach (array('default','local','protected') as $config_group) { if (empty($config_cascade[$type][$config_group])) continue; foreach ($config_cascade[$type][$config_group] as $file) { - if (@file_exists($file)) { + if (file_exists($file)) { $config = call_user_func_array($fn,array_merge(array($file),$params)); $combined = array_merge($combined, $config); } -- cgit v1.2.3 From 45ae4bb83834a513e709b960747f964dba90392b Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 17 May 2015 12:56:51 +0200 Subject: Add filtering to remove blank entries from key/value config retrieval This applies to: - acronyms - entities - interwiki - mime - smileys --- inc/confutils.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'inc/confutils.php') diff --git a/inc/confutils.php b/inc/confutils.php index 8643a056c..3e69b20be 100644 --- a/inc/confutils.php +++ b/inc/confutils.php @@ -49,6 +49,7 @@ function getMimeTypes() { static $mime = null; if ( !$mime ) { $mime = retrieveConfig('mime','confToHash'); + $mime = array_filter($mime); } return $mime; } @@ -62,6 +63,7 @@ function getAcronyms() { static $acronyms = null; if ( !$acronyms ) { $acronyms = retrieveConfig('acronyms','confToHash'); + $acronyms = array_filter($acronyms); } return $acronyms; } @@ -75,6 +77,7 @@ function getSmileys() { static $smileys = null; if ( !$smileys ) { $smileys = retrieveConfig('smileys','confToHash'); + $smileys = array_filter($smileys); } return $smileys; } @@ -88,6 +91,7 @@ function getEntities() { static $entities = null; if ( !$entities ) { $entities = retrieveConfig('entities','confToHash'); + $entities = array_filter($entities); } return $entities; } @@ -101,9 +105,11 @@ function getInterwiki() { static $wikis = null; if ( !$wikis ) { $wikis = retrieveConfig('interwiki','confToHash',array(true)); + $wikis = array_filter($wikis); + + //add sepecial case 'this' + $wikis['this'] = DOKU_URL.'{NAME}'; } - //add sepecial case 'this' - $wikis['this'] = DOKU_URL.'{NAME}'; return $wikis; } -- cgit v1.2.3 From 4c353447a306680af86c38db3ef592e29a0cbe60 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 17 May 2015 13:02:07 +0200 Subject: Support negating of config values include earlier in the cascade To negate a config value, prefix the value with an '!'. E.g. to disable recognition of the gopher scheme !gopher This applies to: - scheme - stopwords --- inc/confutils.php | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'inc/confutils.php') diff --git a/inc/confutils.php b/inc/confutils.php index 3e69b20be..7d7c043fa 100644 --- a/inc/confutils.php +++ b/inc/confutils.php @@ -120,7 +120,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; } @@ -133,11 +133,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; } @@ -202,7 +202,7 @@ function confToHash($file,$lower=false) { * @param array $params optional additional params to pass to the callback * @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(); @@ -214,7 +214,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); } } } @@ -353,4 +353,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) == '!') { + $idx = array_search(substr($val,1),$current); + if ($idx !== false) { + unset($current[$idx]); + } + } else { + $current[] = $val; + } + } + + return array_slice($current,0); +} //Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From f266a91942e3eb7558afe54062c5e6a7bbcdf9ee Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Mon, 18 May 2015 20:31:04 +0100 Subject: Ensure filtering only removes empty string values (not other values which PHP evaluates to false) --- inc/confutils.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'inc/confutils.php') diff --git a/inc/confutils.php b/inc/confutils.php index 7d7c043fa..e3805d74e 100644 --- a/inc/confutils.php +++ b/inc/confutils.php @@ -63,7 +63,7 @@ function getAcronyms() { static $acronyms = null; if ( !$acronyms ) { $acronyms = retrieveConfig('acronyms','confToHash'); - $acronyms = array_filter($acronyms); + $acronyms = array_filter($acronyms, 'strlen'); } return $acronyms; } @@ -77,7 +77,7 @@ function getSmileys() { static $smileys = null; if ( !$smileys ) { $smileys = retrieveConfig('smileys','confToHash'); - $smileys = array_filter($smileys); + $smileys = array_filter($smileys, 'strlen'); } return $smileys; } @@ -91,7 +91,7 @@ function getEntities() { static $entities = null; if ( !$entities ) { $entities = retrieveConfig('entities','confToHash'); - $entities = array_filter($entities); + $entities = array_filter($entities, 'strlen'); } return $entities; } @@ -105,7 +105,7 @@ function getInterwiki() { static $wikis = null; if ( !$wikis ) { $wikis = retrieveConfig('interwiki','confToHash',array(true)); - $wikis = array_filter($wikis); + $wikis = array_filter($wikis, 'strlen'); //add sepecial case 'this' $wikis['this'] = DOKU_URL.'{NAME}'; -- cgit v1.2.3 From 3a7669bd1068f34022db08228baeefae2b27d05b Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Mon, 18 May 2015 20:32:49 +0100 Subject: Ensure single value negation is not affected by white space differences --- inc/confutils.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/confutils.php') diff --git a/inc/confutils.php b/inc/confutils.php index e3805d74e..c587bed4d 100644 --- a/inc/confutils.php +++ b/inc/confutils.php @@ -365,12 +365,12 @@ function conf_decodeString($str) { function array_merge_with_removal($current, $new) { foreach ($new as $val) { if (substr($val,0,1) == '!') { - $idx = array_search(substr($val,1),$current); + $idx = array_search(trim(substr($val,1)),$current); if ($idx !== false) { unset($current[$idx]); } } else { - $current[] = $val; + $current[] = trim($val); } } -- cgit v1.2.3 From 10b38f10e6ce99d01c6ca30bcd9992699d6ee049 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Mon, 18 May 2015 20:34:47 +0100 Subject: Define the negation character in a constant --- inc/confutils.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'inc/confutils.php') diff --git a/inc/confutils.php b/inc/confutils.php index c587bed4d..4035d6dd4 100644 --- a/inc/confutils.php +++ b/inc/confutils.php @@ -6,6 +6,12 @@ * @author Harry Fuecks */ +/* + * 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 @@ -364,7 +370,7 @@ function conf_decodeString($str) { */ function array_merge_with_removal($current, $new) { foreach ($new as $val) { - if (substr($val,0,1) == '!') { + if (substr($val,0,1) == DOKU_CONF_NEGATION) { $idx = array_search(trim(substr($val,1)),$current); if ($idx !== false) { unset($current[$idx]); -- cgit v1.2.3 From 4286c64e98499b93056c09498c10709f8909befd Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Thu, 28 May 2015 12:18:36 +0100 Subject: update confToHash() inline documentation for new parameter --- inc/confutils.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'inc/confutils.php') diff --git a/inc/confutils.php b/inc/confutils.php index 4035d6dd4..8b61a8d5b 100644 --- a/inc/confutils.php +++ b/inc/confutils.php @@ -206,6 +206,11 @@ 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,$combine='array_merge') { -- cgit v1.2.3