diff options
Diffstat (limited to 'views/default')
| -rw-r--r-- | views/default/html/tag.php | 47 | ||||
| -rw-r--r-- | views/default/input/checkboxes.php | 56 | ||||
| -rw-r--r-- | views/default/input/default.php | 48 | ||||
| -rw-r--r-- | views/default/input/form.php | 39 | ||||
| -rw-r--r-- | views/default/input/longtext.php | 33 | ||||
| -rw-r--r-- | views/default/input/option.php | 17 | ||||
| -rw-r--r-- | views/default/input/plaintext.php | 18 | ||||
| -rw-r--r-- | views/default/input/pulldown.php | 55 | ||||
| -rw-r--r-- | views/default/input/tags.php | 28 | 
9 files changed, 298 insertions, 43 deletions
| 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 @@ +<?php + +// 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']); +} + +$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 @@ +<?php +/** + * Elgg checkbox input + * Displays a checkbox input field + * NB: This also includes a hidden input with the same name as the checkboxes + * to make sure something is sent to the server.  The default value is 0. + * If using JS, be specific to avoid selecting the hidden default value: + * 	$('input[type=checkbox][name=internalname]) + * + * @package Elgg + * @subpackage Core + * @author Curverider Ltd + * @link http://elgg.org/ + * + * @uses string $vars['internalname'] The name of the input fields (Forced to an array by appending []) + * @uses array $vars['options'] An array of strings representing the label => 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 "<label>".elgg_view('input/checkbox', $opts)."$label</label><br />"; +	} +}
\ 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[] = "<input";
 -foreach ($attributes as $attr => $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 @@ +<?php +/** + * Create a form for data submission. + * Use this view for forms rather than creating a form tag in the wild as it provides + * extra security which help prevent CSRF attacks. + * + * @package Elgg + * @subpackage Core + * @author Curverider Ltd + * @link http://elgg.org/ + * + * @uses $vars['body'] The body of the form (made up of other input/xxx views and html + * @uses $vars['method'] Method (default POST) + * @uses $vars['enctype'] How the form is encoded, default blank + * @uses $vars['action'] URL of the action being called + * @uses $vars['disable_security'] Force the securitytokens not to be added to this form (@todo what's the point??) + * + */ + + +$defaults = array( +	'method' => '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 @@ +<?php +/** + * Elgg long text input + * Displays a long text input field + * + * @package Elgg + * @subpackage Core + * @author Curverider Ltd + * @link http://elgg.org/ + * + * @uses $vars['value'] The current value, if any + * @uses $vars['js'] Any Javascript to enter into the input tag + * @uses $vars['internalname'] The name of the input field + * + */ + +$defaults = array( +	'class' => '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 @@ +<?php + +$overrides = array( +	'tag' => '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 @@ +<?php +/** + *  + */ + +$defaults = array( +	'class' => '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 @@ +<?php + +/** + * Elgg pulldown input + * Displays a pulldown input field + * + * @package Elgg + * @subpackage Core + * @author Curverider Ltd + * @link http://elgg.org/ + * + * @uses $vars['value'] The current value, if any + * @uses $vars['js'] Any Javascript to enter into the input tag + * @uses $vars['internalname'] The name of the input field + * @uses $vars['options'] An array of strings representing the options for the pulldown field + * @uses $vars['options_values'] An associative array of "value" => "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 @@ +<?php +/** + * Elgg tag input + * Displays a tag input field + * + * @package Elgg + * @subpackage Core + * @author Curverider Ltd + * @link http://elgg.org/ + * + * @uses $vars['value'] The current value, if any - string or array - tags will be encoded + * @uses $vars['js'] Any Javascript to enter into the input tag + * @uses $vars['internalname'] The name of the input field + * @uses $vars['internalid'] The id of the input field + * @uses $vars['class'] CSS class override + * @uses $vars['disabled'] Is the input field disabled? + */ + + +$defaults = array( +	'class' => '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 | 
