From 419c4e01ba3a8b8a038cee32c1fce7d1883532c1 Mon Sep 17 00:00:00 2001 From: Evan Winslow Date: Sun, 17 Oct 2010 10:51:18 +0000 Subject: Added checkboxes, form, longtext, option, plaintext, pulldown, and tags input views. Kept things dry by creating a html/tag view that takes care of outputting attributes/body. --- views/default/html/tag.php | 47 ++++++++++++++++++++++++++++++++ views/default/input/checkboxes.php | 56 ++++++++++++++++++++++++++++++++++++++ views/default/input/default.php | 48 ++++---------------------------- views/default/input/form.php | 39 ++++++++++++++++++++++++++ views/default/input/longtext.php | 33 ++++++++++++++++++++++ views/default/input/option.php | 17 ++++++++++++ views/default/input/plaintext.php | 18 ++++++++++++ views/default/input/pulldown.php | 55 +++++++++++++++++++++++++++++++++++++ views/default/input/tags.php | 28 +++++++++++++++++++ 9 files changed, 298 insertions(+), 43 deletions(-) create mode 100644 views/default/html/tag.php create mode 100644 views/default/input/checkboxes.php create mode 100644 views/default/input/form.php create mode 100644 views/default/input/longtext.php create mode 100644 views/default/input/option.php create mode 100644 views/default/input/plaintext.php create mode 100644 views/default/input/pulldown.php create mode 100644 views/default/input/tags.php diff --git a/views/default/html/tag.php b/views/default/html/tag.php new file mode 100644 index 000000000..d2f888d49 --- /dev/null +++ b/views/default/html/tag.php @@ -0,0 +1,47 @@ +$value) { + unset($vars[$key]); +} + +// backwards compatibility code +if (isset($vars['internalname'])) { + $vars['name'] = $vars['internalname']; + unset($vars['internalname']); +} + +if (isset($vars['internalid'])) { + $vars['id'] = $vars['internalid']; + unset($vars['internalid']); +} + +$js = ''; +if (isset($vars['js'])) { + $js = $vars['js']; + unset($vars['js']); +} + +$tag = $vars['tag']; + +//Build the input +$element = array(); + +$element[] = "<$tag"; +foreach ($attributes as $attr => $val) { + if ($val === TRUE) { + $element[] = $attr; + } elseif ($val !== FALSE) { + $val = htmlspecialchars($val); + $element[] = "$attr=\"$val\""; + } +} +$element[] = $js; +$element[] = "/>"; + +echo implode(" ", $element); \ No newline at end of file diff --git a/views/default/input/checkboxes.php b/views/default/input/checkboxes.php new file mode 100644 index 000000000..95460a6a8 --- /dev/null +++ b/views/default/input/checkboxes.php @@ -0,0 +1,56 @@ + option for the each checkbox field + * @uses string $vars['internalid'] The id for each input field. Optional (Only use this with a single value.) + * @uses string $vars['default'] The default value to send if nothing is checked. Optional, defaults to 0. + * @uses bool $vars['disabled'] Make all input elements disabled. Optional. + * @uses string $vars['value'] The current value. Optional. + * @uses string $vars['class'] The class of each input element. Optional. + * @uses string $vars['js'] Any Javascript to enter into the input tag. Optional. + * + */ + +$defaults = array( + 'class' => 'input-checkboxes', + 'default' => 0, + 'disabled' => FALSE, +); + +$args = array_merge($defaults, $vars); + +$value_array = (is_array($args['value'])) ? array_map('strtolower', $args['value']) : array(strtolower($args['value'])); + +$options = $args['options']; + +if ($options) { + // include a default value so if nothing is checked 0 will be passed. + if ($args['internalname']) { + echo elgg_view('input/hidden', array('internalname' => $args['internalname'], 'value' => $args['default'])); + } + + foreach($options as $option => $label) { + $opts = array( + 'value' => $option, + 'checked' => in_array(strtolower($option), $value_array)), + 'class' => $args['class'], + 'disabled' => $args['disabled'], + 'js' => $args['js'], + 'internalname' => $args['internalname'].'[]', + ); + + echo "
"; + } +} \ No newline at end of file diff --git a/views/default/input/default.php b/views/default/input/default.php index 0577b34e5..4f4eecc59 100644 --- a/views/default/input/default.php +++ b/views/default/input/default.php @@ -15,53 +15,15 @@ * including javascript event attributes such as onclick. */ -// remove all the junk that elgg_view throws into $vars - -unset($vars['config']); -unset($vars['url']); -unset($vars['page_owner']); -unset($vars['page_owner_user']); -foreach ($_SESSION as $key=>$value) { - unset($vars[$key]); -} - -// backwards compatibility code -if (isset($vars['internalname'])) { - $vars['name'] = $vars['internalname']; - unset($vars['internalname']); -} - -if (isset($vars['internalid'])) { - $vars['id'] = $vars['internalid']; - unset($vars['internalid']); -} - -$js = ''; -if (isset($vars['js'])) { - $js = $vars['js']; - unset($vars['js']); -} - // default attributes $defaults = array( 'type' => 'text', ); -$attributes = array_merge($defaults, $vars); - -//Build the input -$element = array(); +$overrides = array( + 'tag' => 'input', +); -$element[] = " $val) { - if ($val === TRUE) { - $element[] = $attr; - } elseif ($val !== FALSE) { - $val = htmlspecialchars($val); - $element[] = "$attr=\"$val\""; - } -} -$element[] = $js; -$element[] = "/>"; +$args = array_merge($defaults, $vars, $overrides); -echo implode(" ", $element); \ No newline at end of file +echo elgg_view('html/tag', $args); \ No newline at end of file diff --git a/views/default/input/form.php b/views/default/input/form.php new file mode 100644 index 000000000..e6b4f299e --- /dev/null +++ b/views/default/input/form.php @@ -0,0 +1,39 @@ + 'POST', + 'body' => '', +); + +$overrides = array( + 'tag' => 'form', +); + +$disable_security = $vars['disable_security']; +unset($vars['disable_security']); + +$args = array_merge($defaults, $vars, $overrides); + +if ($disable_security != TRUE) { + $args['body'] .= elgg_view('input/securitytoken'); +} + +echo elgg_view('html/tag', $args); diff --git a/views/default/input/longtext.php b/views/default/input/longtext.php new file mode 100644 index 000000000..a19c7dde8 --- /dev/null +++ b/views/default/input/longtext.php @@ -0,0 +1,33 @@ + 'input-textarea', +); + +$overrides = array( + 'tag' => 'textarea', +); + +$args = array_merge($defaults, $vars, $overrides); + +if (isset($args['value'])) { + $args['body'] = $args['value']; +} + +$args['class'] = $args['class'].' input-richtext'; + +echo elgg_view('html/tag', $args); \ No newline at end of file diff --git a/views/default/input/option.php b/views/default/input/option.php new file mode 100644 index 000000000..eab1dc4d2 --- /dev/null +++ b/views/default/input/option.php @@ -0,0 +1,17 @@ + 'option', +); + +$args = array_merge($vars, $overrides); + +if (!isset($args['body'])) { + $args['body'] = $args['value']; +} + +if (isset($args['body'])) { + $args['body'] = htmlentities($args['body'], ENT_QUOTES, 'UTF-8'); +} + +echo elgg_view('html/tag', $args); \ No newline at end of file diff --git a/views/default/input/plaintext.php b/views/default/input/plaintext.php new file mode 100644 index 000000000..4c8cdac57 --- /dev/null +++ b/views/default/input/plaintext.php @@ -0,0 +1,18 @@ + 'input-textarea', +); + +$overrides = array( + 'tag' => 'textarea', +); + +if (isset($vars['value'])) { + $vars['body'] = $value; +} + +echo elgg_view('html/tag', array_merge($defaults, $vars, $overrides)); \ No newline at end of file diff --git a/views/default/input/pulldown.php b/views/default/input/pulldown.php new file mode 100644 index 000000000..49c126c77 --- /dev/null +++ b/views/default/input/pulldown.php @@ -0,0 +1,55 @@ + "option" where "value" is an internal name and "option" is + * the value displayed on the button. Replaces $vars['options'] when defined. + */ + +$defaults = array( + 'class' => 'input-pulldown', +); + +$overrides = array( + 'tag' => 'select', +); + +$args = array_merge($defaults, $vars, $overrides); + +$body = ''; + +if ($vars['options_values']) { + foreach($vars['options_values'] as $value => $option) { + $option_args = array( + 'value' => $value, + 'body' => $option, + 'selected' => ($value == $args['value']), + ); + + $body .= elgg_view('input/option', $option_args); + } +} else { + foreach($vars['options'] as $option) { + $option_args = array( + 'body' => $option, + 'selected' => ($option == $args['value']), + ); + + $body .= elgg_view('input/option', $option_args); + } +} + +$args['body'] = $body; + +echo elgg_view('html/tag', $args); diff --git a/views/default/input/tags.php b/views/default/input/tags.php new file mode 100644 index 000000000..92e163e5e --- /dev/null +++ b/views/default/input/tags.php @@ -0,0 +1,28 @@ + 'input-tags', +); + +if (isset($vars['value']) && is_array($vars['value'])) { + $vars['value'] = implode(", ", $vars['value']); +} + +echo elgg_view('input/text', array_merge($defaults, $vars)); \ No newline at end of file -- cgit v1.2.3