diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/images/smileys/index.php | 48 | ||||
-rw-r--r-- | lib/plugins/action.php | 2 | ||||
-rw-r--r-- | lib/plugins/config/_test/configuration.test.php | 33 | ||||
-rw-r--r-- | lib/plugins/config/_test/data/config.php | 16 | ||||
-rw-r--r-- | lib/plugins/config/_test/data/metadata.php | 13 | ||||
-rw-r--r-- | lib/plugins/config/settings/config.class.php | 118 | ||||
-rw-r--r-- | lib/plugins/config/settings/config.metadata.php | 3 | ||||
-rw-r--r-- | lib/plugins/popularity/action.php | 2 | ||||
-rw-r--r-- | lib/plugins/safefnrecode/action.php | 2 | ||||
-rw-r--r-- | lib/plugins/testing/action.php | 3 |
10 files changed, 225 insertions, 15 deletions
diff --git a/lib/images/smileys/index.php b/lib/images/smileys/index.php new file mode 100644 index 000000000..9a2905b33 --- /dev/null +++ b/lib/images/smileys/index.php @@ -0,0 +1,48 @@ +<!DOCTYPE html> +<html lang="en" dir="ltr"> +<head> + <title>simleys</title> + + <style type="text/css"> + body { + background-color: #ccc; + font-family: Arial; + } + + .box { + width: 200px; + float:left; + padding: 0.5em; + margin: 0; + } + + .white { + background-color: #fff; + } + + .black { + background-color: #000; + } + </style> + +</head> +<body> + +<div class="white box"> +<?php +foreach (glob('*.gif') as $img) { + echo '<img src="'.$img.'" alt="'.$img.'" title="'.$img.'" /> '; +} +?> +</div> + +<div class="black box"> +<?php +foreach (glob('*.gif') as $img) { + echo '<img src="'.$img.'" alt="'.$img.'" title="'.$img.'" /> '; +} +?> +</div> + +</body> +</html> diff --git a/lib/plugins/action.php b/lib/plugins/action.php index 885bd7c96..a2ad969d7 100644 --- a/lib/plugins/action.php +++ b/lib/plugins/action.php @@ -17,7 +17,7 @@ class DokuWiki_Action_Plugin extends DokuWiki_Plugin { /** * Registers a callback function for a given event */ - function register($controller) { + function register(Doku_Event_Handler $controller) { trigger_error('register() not implemented in '.get_class($this), E_USER_WARNING); } } diff --git a/lib/plugins/config/_test/configuration.test.php b/lib/plugins/config/_test/configuration.test.php new file mode 100644 index 000000000..ee03f3849 --- /dev/null +++ b/lib/plugins/config/_test/configuration.test.php @@ -0,0 +1,33 @@ +<?php + +class plugin_config_configuration_test extends DokuWikiTest { + + private $config = ''; + private $meta = ''; + + function __construct() { + $this->config = dirname(__FILE__).'/data/config.php'; + $this->meta = dirname(__FILE__).'/data/metadata.php'; + require_once(dirname(__FILE__).'/../settings/config.class.php'); + } + + function test_readconfig() { + $confmgr = new configuration($this->meta); + + $conf = $confmgr->_read_config($this->config); + + //print_r($conf); + + $this->assertEquals('42', $conf['int1']); + $this->assertEquals('6*7', $conf['int2']); + + $this->assertEquals('Hello World', $conf['str1']); + $this->assertEquals('G\'day World', $conf['str2']); + $this->assertEquals('Hello World', $conf['str3']); + $this->assertEquals("Hello 'World'", $conf['str4']); + $this->assertEquals('Hello "World"', $conf['str5']); + + $this->assertEquals(array('foo', 'bar', 'baz'), $conf['arr1']); + } + +}
\ No newline at end of file diff --git a/lib/plugins/config/_test/data/config.php b/lib/plugins/config/_test/data/config.php new file mode 100644 index 000000000..15d6359ad --- /dev/null +++ b/lib/plugins/config/_test/data/config.php @@ -0,0 +1,16 @@ +<?php + + +$conf['int1'] = 42; +$conf['int2'] = 6*7; + +$conf['str1'] = 'Hello World'; +$conf['str2'] = 'G\'day World'; +$conf['str3'] = "Hello World"; +$conf['str4'] = "Hello 'World'"; +$conf['str5'] = "Hello \"World\""; + +$conf['arr1'] = array('foo','bar','baz'); + +$conf['foo']['bar'] = 'x1'; +$conf['foo']['baz'] = 'x2'; diff --git a/lib/plugins/config/_test/data/metadata.php b/lib/plugins/config/_test/data/metadata.php new file mode 100644 index 000000000..12902e525 --- /dev/null +++ b/lib/plugins/config/_test/data/metadata.php @@ -0,0 +1,13 @@ +<?php + +$meta['int1'] = array('numeric'); +$meta['int2'] = array('numeric'); + +$meta['str1'] = array('string'); +$meta['str2'] = array('string'); +$meta['str3'] = array('string'); +$meta['str4'] = array('string'); +$meta['str5'] = array('string'); + +$meta['arr1'] = array('array'); + diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php index e6d085bcb..d4d98ee01 100644 --- a/lib/plugins/config/settings/config.class.php +++ b/lib/plugins/config/settings/config.class.php @@ -6,6 +6,9 @@ * @author Ben Coburn <btcoburn@silicodon.net> */ + +if(!defined('CM_KEYMARKER')) define('CM_KEYMARKER','____'); + if (!class_exists('configuration')) { class configuration { @@ -46,14 +49,8 @@ if (!class_exists('configuration')) { $this->_local_files = $config_cascade['main']['local']; $this->_protected_files = $config_cascade['main']['protected']; -# if (isset($file['default'])) $this->_default_file = $file['default']; -# if (isset($file['local'])) $this->_local_file = $file['local']; -# if (isset($file['protected'])) $this->_protected_file = $file['protected']; - $this->locked = $this->_is_locked(); - $this->_metadata = array_merge($meta, $this->get_plugintpl_metadata($conf['template'])); - $this->retrieve_settings(); } @@ -149,7 +146,6 @@ if (!class_exists('configuration')) { if (!$file) return array(); $config = array(); -# $file = eval('return '.$file.';'); if ($this->_format == 'php') { @@ -197,9 +193,6 @@ if (!class_exists('configuration')) { function _out_footer() { $out = ''; if ($this->_format == 'php') { - # if ($this->_protected_file) { - # $out .= "\n@include(".$this->_protected_file.");\n"; - # } $out .= "\n// end auto-generated content\n"; } @@ -211,7 +204,6 @@ if (!class_exists('configuration')) { function _is_locked() { if (!$this->_local_files) return true; -# $local = eval('return '.$this->_local_file.';'); $local = $this->_local_files[0]; if (!is_writable(dirname($local))) return true; @@ -467,6 +459,110 @@ if (!class_exists('setting')) { } } + +if (!class_exists('setting_array')) { + class setting_array extends setting { + + /** + * Create an array from a string + * + * @param $string + * @return array + */ + protected function _from_string($string){ + $array = explode(',', $string); + $array = array_map('trim', $array); + $array = array_filter($array); + $array = array_unique($array); + return $array; + } + + /** + * Create a string from an array + * + * @param $array + * @return string + */ + protected function _from_array($array){ + return join(', ', (array) $array); + } + + /** + * update setting with user provided value $input + * if value fails error check, save it + * + * @param string $input + * @return bool true if changed, false otherwise (incl. on error) + */ + function update($input) { + if (is_null($input)) return false; + if ($this->is_protected()) return false; + + $input = $this->_from_string($input); + + $value = is_null($this->_local) ? $this->_default : $this->_local; + if ($value == $input) return false; + + foreach($input as $item){ + if ($this->_pattern && !preg_match($this->_pattern,$item)) { + $this->_error = true; + $this->_input = $input; + return false; + } + } + + $this->_local = $input; + return true; + } + + protected function _escape($string) { + $tr = array("\\" => '\\\\', "'" => '\\\''); + return "'".strtr( cleanText($string), $tr)."'"; + } + + /** + * generate string to save setting value to file according to $fmt + */ + function out($var, $fmt='php') { + + if ($this->is_protected()) return ''; + if (is_null($this->_local) || ($this->_default == $this->_local)) return ''; + + $out = ''; + + if ($fmt=='php') { + $vals = array_map(array($this, '_escape'), $this->_local); + $out = '$'.$var."['".$this->_out_key()."'] = array(".join(', ',$vals).");\n"; + } + + return $out; + } + + function html(&$plugin, $echo=false) { + $value = ''; + $disable = ''; + + if ($this->is_protected()) { + $value = $this->_protected; + $disable = 'disabled="disabled"'; + } else { + if ($echo && $this->_error) { + $value = $this->_input; + } else { + $value = is_null($this->_local) ? $this->_default : $this->_local; + } + } + + $key = htmlspecialchars($this->_key); + $value = htmlspecialchars($this->_from_array($value)); + + $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>'; + $input = '<input id="config___'.$key.'" name="config['.$key.']" type="text" class="edit" value="'.$value.'" '.$disable.'/>'; + return array($label,$input); + } + } +} + if (!class_exists('setting_string')) { class setting_string extends setting { function html(&$plugin, $echo=false) { diff --git a/lib/plugins/config/settings/config.metadata.php b/lib/plugins/config/settings/config.metadata.php index 3607f56c6..582452917 100644 --- a/lib/plugins/config/settings/config.metadata.php +++ b/lib/plugins/config/settings/config.metadata.php @@ -32,6 +32,9 @@ * separated list of checked choices * 'fieldset' - used to group configuration settings, but is not itself a setting. To make this clear in * the language files the keys for this type should start with '_'. + * 'array' - a simple (one dimensional) array of string values, shown as comma separated list in the + * config manager but saved as PHP array(). Values may not contain commas themselves. + * _pattern matching on the array values supported. * * Single Setting (source: settings/extra.class.php) * ------------------------------------------------- diff --git a/lib/plugins/popularity/action.php b/lib/plugins/popularity/action.php index bf11efba6..1c7a2f65d 100644 --- a/lib/plugins/popularity/action.php +++ b/lib/plugins/popularity/action.php @@ -18,7 +18,7 @@ class action_plugin_popularity extends Dokuwiki_Action_Plugin { /** * Register its handlers with the dokuwiki's event controller */ - function register(&$controller) { + function register(Doku_Event_Handler $controller) { $controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, '_autosubmit', array()); } diff --git a/lib/plugins/safefnrecode/action.php b/lib/plugins/safefnrecode/action.php index 5d3eaae3a..aae11c437 100644 --- a/lib/plugins/safefnrecode/action.php +++ b/lib/plugins/safefnrecode/action.php @@ -13,7 +13,7 @@ require_once DOKU_PLUGIN.'action.php'; class action_plugin_safefnrecode extends DokuWiki_Action_Plugin { - public function register(Doku_Event_Handler &$controller) { + public function register(Doku_Event_Handler $controller) { $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'handle_indexer_tasks_run'); diff --git a/lib/plugins/testing/action.php b/lib/plugins/testing/action.php index e829847b6..a242ab0b7 100644 --- a/lib/plugins/testing/action.php +++ b/lib/plugins/testing/action.php @@ -7,7 +7,8 @@ * @author Tobias Sarnowski <tobias@trustedco.de> */ class action_plugin_testing extends DokuWiki_Action_Plugin { - function register(&$controller) { + + function register(Doku_Event_Handler $controller) { $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'dokuwikiStarted'); } |