aboutsummaryrefslogtreecommitdiff
path: root/views/default/input
diff options
context:
space:
mode:
Diffstat (limited to 'views/default/input')
-rw-r--r--views/default/input/access.php65
-rw-r--r--views/default/input/autocomplete.php109
-rw-r--r--views/default/input/button.php14
-rw-r--r--views/default/input/calendar.php4
-rw-r--r--views/default/input/captcha.php2
-rw-r--r--views/default/input/checkbox.php25
-rw-r--r--views/default/input/checkboxes.php116
-rw-r--r--views/default/input/date.php56
-rw-r--r--views/default/input/datepicker.php40
-rw-r--r--views/default/input/dropdown.php71
-rw-r--r--views/default/input/email.php14
-rw-r--r--views/default/input/file.php24
-rw-r--r--views/default/input/form.php24
-rw-r--r--views/default/input/friendspicker.php319
-rw-r--r--views/default/input/hidden.php11
-rw-r--r--views/default/input/location.php27
-rw-r--r--views/default/input/longtext.php44
-rw-r--r--views/default/input/password.php21
-rw-r--r--views/default/input/plaintext.php33
-rw-r--r--views/default/input/pulldown.php55
-rw-r--r--views/default/input/radio.php89
-rw-r--r--views/default/input/reset.php7
-rw-r--r--views/default/input/securitytoken.php4
-rw-r--r--views/default/input/submit.php7
-rw-r--r--views/default/input/tag.php25
-rw-r--r--views/default/input/tags.php25
-rw-r--r--views/default/input/text.php16
-rw-r--r--views/default/input/url.php14
-rw-r--r--views/default/input/userpicker.php178
29 files changed, 877 insertions, 562 deletions
diff --git a/views/default/input/access.php b/views/default/input/access.php
index d4f366363..137eea288 100644
--- a/views/default/input/access.php
+++ b/views/default/input/access.php
@@ -1,57 +1,38 @@
<?php
/**
* Elgg access level input
- * Displays a pulldown input field
- *
- * @package Elgg
- * @subpackage Core
-
-
- *
- * @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
+ * Displays a dropdown input field
*
+ * @uses $vars['value'] The current value, if any
+ * @uses $vars['options_values'] Array of value => label pairs (overrides default)
+ * @uses $vars['name'] The name of the input field
+ * @uses $vars['entity'] Optional. The entity for this access control (uses access_id)
+ * @uses $vars['class'] Additional CSS class
*/
-$class = "input-access";
if (isset($vars['class'])) {
- $class = $vars['class'];
+ $vars['class'] = "elgg-input-access {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-access";
}
-$disabled = false;
-if (isset($vars['disabled'])) {
- $disabled = $vars['disabled'];
-}
+$defaults = array(
+ 'disabled' => false,
+ 'value' => get_default_access(),
+ 'options_values' => get_write_access_array(),
+);
-if (!array_key_exists('value', $vars) || $vars['value'] == ACCESS_DEFAULT) {
- $vars['value'] = get_default_access();
+if (isset($vars['entity'])) {
+ $defaults['value'] = $vars['entity']->access_id;
+ unset($vars['entity']);
}
-if (!isset($vars['value']) || $vars['value'] === FALSE) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
-}
+$vars = array_merge($defaults, $vars);
-if ((!isset($vars['options'])) || (!is_array($vars['options']))) {
- $vars['options'] = array();
- $vars['options'] = get_write_access_array();
+if ($vars['value'] == ACCESS_DEFAULT) {
+ $vars['value'] = get_default_access();
}
-if (is_array($vars['options']) && sizeof($vars['options']) > 0) {
- ?>
-
- <select <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['js'])) echo $vars['js']; ?> <?php if ($disabled) echo ' disabled="yes" '; ?> class="<?php echo $class; ?>">
- <?php
-
- foreach($vars['options'] as $key => $option) {
- if ($key != $vars['value']) {
- echo "<option value=\"{$key}\">". htmlentities($option, ENT_QUOTES, 'UTF-8') ."</option>";
- } else {
- echo "<option value=\"{$key}\" selected=\"selected\">". htmlentities($option, ENT_QUOTES, 'UTF-8') ."</option>";
- }
- }
-
- ?>
- </select>
- <?php
-} \ No newline at end of file
+if (is_array($vars['options_values']) && sizeof($vars['options_values']) > 0) {
+ echo elgg_view('input/dropdown', $vars);
+}
diff --git a/views/default/input/autocomplete.php b/views/default/input/autocomplete.php
index 67d01c0c7..e58eb1ae8 100644
--- a/views/default/input/autocomplete.php
+++ b/views/default/input/autocomplete.php
@@ -7,94 +7,43 @@
*
* @todo This currently only works for ONE AUTOCOMPLETE TEXT FIELD on a page.
*
- * @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['match_on'] Array | str What to match on. all|array(group|user|friend|subtype)
+ * @uses $vars['value'] Current value for the text input
+ * @uses $vars['match_on'] Array | str What to match on. all|array(groups|users|friends)
* @uses $vars['match_owner'] Bool. Match only entities that are owned by logged in user.
- *
+ * @uses $vars['class'] Additional CSS class
*/
-global $autocomplete_js_loaded;
-
-$internalname = $vars['internalname'];
-$value = $vars['value'];
-
-if(!$value) {
- $value= '';
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-input-autocomplete {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-autocomplete";
}
-if($vars['internal_id']) {
- $id_autocomplete = $vars['internal_id'];
-}
+$defaults = array(
+ 'value' => '',
+ 'disabled' => false,
+);
-$ac_url_params = http_build_query(array(
- 'match_on' => $vars['match_on'],
- 'match_owner' => $vars['match_owner'],
-));
-$ac_url = elgg_get_site_url() . 'pg/autocomplete?' . $ac_url_params;
+$vars = array_merge($defaults, $vars);
-if (!isset($autocomplete_js_loaded)) {
- $autocomplete_js_loaded = false;
+$params = array();
+if (isset($vars['match_on'])) {
+ $params['match_on'] = $vars['match_on'];
+ unset($vars['match_on']);
}
+if (isset($vars['match_owner'])) {
+ $params['match_owner'] = $vars['match_owner'];
+ unset($vars['match_owner']);
+}
+$ac_url_params = http_build_query($params);
-?>
-
-<!-- show the input -->
-<input type="text" class='autocomplete' name ='<?php echo $internalname; ?>_autocomplete' value='<?php echo $value?>' />
-<input type="hidden" name="<?php echo $internalname; ?>" value='<?php echo $value; ?>' />
-
-<?php
-if (!$autocomplete_js_loaded) {
- ?>
-
- <!-- include autocomplete -->
- <script language="javascript" type="text/javascript" src="<?php echo elgg_get_site_url(); ?>vendors/jquery/jquery.autocomplete.min.js"></script>
- <script type="text/javascript">
- function bindAutocomplete() {
- $('input[type=text].autocomplete').autocomplete("<?php echo $ac_url; ?>", {
- minChars: 1,
- matchContains: true,
- autoFill: false,
- formatItem: function(row, i, max, term) {
- eval("var info = " + row + ";");
- var r = '';
-
- switch (info.type) {
- case 'user':
- case 'group':
- r = info.icon + info.name + ' - ' + info.desc;
- break;
-
- default:
- r = info.name + ' - ' + info.desc;
- break;
- }
- return r.replace(new RegExp("(" + term + ")", "gi"), "<b>$1</b>");
- }
- });
-
- $('input[type=text].autocomplete').result(function(event, data, formatted) {
- eval("var info = " + data + ";");
- $(this).val(info.name);
-
- var hidden = $(this).next();
- hidden.val(info.guid);
- });
- }
-
- $(document).ready(function() {
- bindAutocomplete();
- });
-
- </script>
+elgg_load_js('elgg.autocomplete');
+elgg_load_js('jquery.ui.autocomplete.html');
- <?php
+?>
- $autocomplete_js_loaded = true;
-} else {
- ?>
- <!-- rebind autocomplete -->
- <script type="text/javascript">bindAutocomplete();</script>
- <?php
-} \ No newline at end of file
+<script type="text/javascript">
+elgg.provide('elgg.autocomplete');
+elgg.autocomplete.url = "<?php echo elgg_get_site_url() . 'livesearch?' . $ac_url_params; ?>";
+</script>
+<input type="text" <?php echo elgg_format_attributes($vars); ?> />
diff --git a/views/default/input/button.php b/views/default/input/button.php
index 1c8bdaf3c..9957fdc54 100644
--- a/views/default/input/button.php
+++ b/views/default/input/button.php
@@ -5,14 +5,18 @@
* @package Elgg
* @subpackage Core
*
- * @uses $vars['src'] Src of an image
+ * @uses $vars['src'] Src of an image
+ * @uses $vars['class'] Additional CSS class
*/
-global $CONFIG;
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-button {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-button";
+}
$defaults = array(
'type' => 'button',
- 'class' => 'submit-button',
);
$vars = array_merge($defaults, $vars);
@@ -29,8 +33,8 @@ switch ($vars['type']) {
}
// blank src if trying to access an offsite image. @todo why?
-if (strpos($vars['src'], $CONFIG->wwwroot) === false) {
+if (isset($vars['src']) && strpos($vars['src'], elgg_get_site_url()) === false) {
$vars['src'] = "";
}
?>
-<input <?php echo elgg_format_attributes($vars); ?> /> \ No newline at end of file
+<input <?php echo elgg_format_attributes($vars); ?> />
diff --git a/views/default/input/calendar.php b/views/default/input/calendar.php
index 553a254ce..52c84ff82 100644
--- a/views/default/input/calendar.php
+++ b/views/default/input/calendar.php
@@ -1,6 +1,6 @@
<?php
-// @deprecated Use datepicker instead.
+// @deprecated Use input/date instead.
-elgg_deprecated_notice('view: input/calendar is deprecated by input/datepicker', 1.8);
+elgg_deprecated_notice('view: input/calendar is deprecated by input/date', 1.8);
echo elgg_view('input/datepicker', $vars); \ No newline at end of file
diff --git a/views/default/input/captcha.php b/views/default/input/captcha.php
index 210e0f50a..1c2e22aaa 100644
--- a/views/default/input/captcha.php
+++ b/views/default/input/captcha.php
@@ -1,6 +1,6 @@
<?php
/**
- * This view provides a hook for third parties to provide captcha behaviour.
+ * This view provides a hook for third parties to provide a CAPTCHA.
*
* @package Elgg
* @subpackage Core
diff --git a/views/default/input/checkbox.php b/views/default/input/checkbox.php
index 59af3216f..3dc75c6c3 100644
--- a/views/default/input/checkbox.php
+++ b/views/default/input/checkbox.php
@@ -10,27 +10,30 @@
* Pass input tag attributes as key value pairs. For a list of allowable
* attributes, see http://www.w3schools.com/tags/tag_input.asp
*
- * @uses mixed $vars['default'] The default value to submit if not checked.
- * Optional, defaults to 0. Set to false for no default.
+ * @uses $vars['default'] The default value to submit if not checked.
+ * Optional, defaults to 0. Set to false for no default.
+ * @uses $vars['class'] Additional CSS class
*/
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-input-checkbox {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-checkbox";
+}
+
$defaults = array(
- 'class' => 'input-checkbox',
+ 'default' => 0,
+ 'disabled' => false,
);
$vars = array_merge($defaults, $vars);
-if (isset($vars['default'])) {
- $default = $vars['default'];
- unset($vars['default']);
-} else {
- $default = 0;
-}
+$default = $vars['default'];
+unset($vars['default']);
if (isset($vars['name']) && $default !== false) {
echo "<input type=\"hidden\" name=\"{$vars['name']}\" value=\"$default\"/>";
}
?>
-
-<input type="checkbox" <?php echo elgg_format_attributes($vars); ?> /> \ No newline at end of file
+<input type="checkbox" <?php echo elgg_format_attributes($vars); ?> />
diff --git a/views/default/input/checkboxes.php b/views/default/input/checkboxes.php
index 4abeabf58..db4b06949 100644
--- a/views/default/input/checkboxes.php
+++ b/views/default/input/checkboxes.php
@@ -2,79 +2,89 @@
/**
* Elgg checkbox input
* Displays a checkbox input field
- * NB: This also includes a hidden input with the same name as the checkboxes
+ *
+ * @note 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]')
+ * $('input[type=checkbox][name=name]')
+ *
+ * @warning Passing integers as labels does not currently work due to a
+ * deprecated hack that will be removed in Elgg 1.9. To use integer labels,
+ * the labels must be character codes: 1 would be &#0049;
*
* @package Elgg
* @subpackage Core
*
- * @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. Set to FALSE for no default.
- * @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.
+ * @uses string $vars['name'] 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['default'] The default value to send if nothing is checked.
+ * Optional, defaults to 0. Set to FALSE for no default.
+ * @uses bool $vars['disabled'] Make all input elements disabled. Optional.
+ * @uses string $vars['value'] The current value. Single value or array. Optional.
+ * @uses string $vars['class'] Additional class of the list. Optional.
+ * @uses string $vars['align'] 'horizontal' or 'vertical' Default: 'vertical'
*
*/
-if (!isset($vars['value']) || $vars['value'] === FALSE) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+$defaults = array(
+ 'align' => 'vertical',
+ 'value' => array(),
+ 'default' => 0,
+ 'disabled' => false,
+ 'options' => array(),
+ 'name' => '',
+);
+
+$vars = array_merge($defaults, $vars);
+
+$class = "elgg-input-checkboxes elgg-{$vars['align']}";
+if (isset($vars['class'])) {
+ $class .= " {$vars['class']}";
+ unset($vars['class']);
}
-$class = (isset($vars['class'])) ? $vars['class'] : 'input-checkboxes';
-$value = (isset($vars['value'])) ? $vars['value'] : NULL;
-$value_array = (is_array($value)) ? array_map('strtolower', $value) : array(strtolower($value));
-$internalname = (isset($vars['internalname'])) ? $vars['internalname'] : '';
-$options = (isset($vars['options']) && is_array($vars['options'])) ? $vars['options'] : array();
-$default = (isset($vars['default'])) ? $vars['default'] : 0;
+$id = '';
+if (isset($vars['id'])) {
+ $id = "id=\"{$vars['id']}\"";
+ unset($vars['id']);
+}
+
+if (is_array($vars['value'])) {
+ $values = array_map('elgg_strtolower', $vars['value']);
+} else {
+ $values = array(elgg_strtolower($vars['value']));
+}
-$id = (isset($vars['internalid'])) ? $vars['internalid'] : '';
-$disabled = (isset($vars['disabled'])) ? $vars['disabled'] : FALSE;
-$js = (isset($vars['js'])) ? $vars['js'] : '';
+$input_vars = $vars;
+$input_vars['default'] = false;
+if ($vars['name']) {
+ $input_vars['name'] = "{$vars['name']}[]";
+}
+unset($input_vars['align']);
+unset($input_vars['options']);
-if ($options) {
+if (count($vars['options']) > 0) {
// include a default value so if nothing is checked 0 will be passed.
- if ($internalname && $default !== FALSE) {
- echo "<input type=\"hidden\" name=\"$internalname\" value=\"$default\">";
+ if ($vars['name'] && $vars['default'] !== false) {
+ echo "<input type=\"hidden\" name=\"{$vars['name']}\" value=\"{$vars['default']}\" />";
}
- foreach ($options as $label => $option) {
- // @hack - This sorta checks if options is not an assoc array and then
- // ignores the label (because it's just the index) and sets the value ($option)
- // as the label.
- // Wow.
- // @todo deprecate in Elgg 1.8
+ echo "<ul class=\"$class\" $id>";
+ foreach ($vars['options'] as $label => $value) {
+ // @deprecated 1.8 Remove in 1.9
if (is_integer($label)) {
- $label = $option;
- }
-
- $input_vars = array(
- 'checked' => in_array(strtolower($option), $value_array),
- 'value' => $option,
- 'disabled' => $disabled,
- 'id' => $id,
- 'js' => $js,
- 'default' => false,
- );
-
- if ($class) {
- $input_vars['class'] = $class;
+ elgg_deprecated_notice('$vars[\'options\'] must be an associative array in input/checkboxes', 1.8);
+ $label = $value;
}
- if ($internalname) {
- $input_vars['name'] = "{$internalname}[]";
- }
+ $input_vars['checked'] = in_array(elgg_strtolower($value), $values);
+ $input_vars['value'] = $value;
$input = elgg_view('input/checkbox', $input_vars);
- echo "<label>{$input}{$label}</label><br />";
+ echo "<li><label>$input$label</label></li>";
}
-} \ No newline at end of file
+ echo '</ul>';
+}
diff --git a/views/default/input/date.php b/views/default/input/date.php
new file mode 100644
index 000000000..828ce5520
--- /dev/null
+++ b/views/default/input/date.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Elgg date input
+ * Displays a text field with a popup date picker.
+ *
+ * The elgg.ui JavaScript library initializes the jQueryUI datepicker based
+ * on the CSS class .elgg-input-date. It uses the ISO 8601 standard for date
+ * representation: yyyy-mm-dd.
+ *
+ * Unix timestamps are supported by setting the 'timestamp' parameter to true.
+ * The date is still displayed to the user in a text format but is submitted as
+ * a unix timestamp in seconds.
+ *
+ * @uses $vars['value'] The current value, if any (as a unix timestamp)
+ * @uses $vars['class'] Additional CSS class
+ * @uses $vars['timestamp'] Store as a Unix timestamp in seconds. Default = false
+ * Note: you cannot use an id with the timestamp option.
+ */
+
+//@todo popup_calendar deprecated in 1.8. Remove in 2.0
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-input-date popup_calendar {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-date popup_calendar";
+}
+
+$defaults = array(
+ 'value' => '',
+ 'disabled' => false,
+ 'timestamp' => false,
+);
+
+$vars = array_merge($defaults, $vars);
+
+$timestamp = $vars['timestamp'];
+unset($vars['timestamp']);
+
+if ($timestamp) {
+ echo elgg_view('input/hidden', array(
+ 'name' => $vars['name'],
+ 'value' => $vars['value'],
+ ));
+
+ $vars['class'] = "{$vars['class']} elgg-input-timestamp";
+ $vars['id'] = $vars['name'];
+ unset($vars['name']);
+ unset($vars['internalname']);
+}
+
+// convert timestamps to text for display
+if (is_numeric($vars['value'])) {
+ $vars['value'] = gmdate('Y-m-d', $vars['value']);
+}
+
+$attributes = elgg_format_attributes($vars);
+echo "<input type=\"text\" $attributes />";
diff --git a/views/default/input/datepicker.php b/views/default/input/datepicker.php
index fceb8b30c..8955e6e53 100644
--- a/views/default/input/datepicker.php
+++ b/views/default/input/datepicker.php
@@ -1,40 +1,6 @@
<?php
/**
- * Elgg datepicker input
- * Displays a text field with a popup date picker.
- *
- * @package Elgg
- * @subpackage Core
- *
- * @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
- *
+ * @deprecated use input/date instead
*/
-
-$cal_name = sanitise_string($vars['internalname']);
-
-if (isset($vars['class'])) {
- $class = "{$vars['class']} popup_calendar";
-} else {
- $class = 'popup_calendar';
-}
-
-if (!isset($vars['value']) || $vars['value'] === FALSE) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
-}
-
-if ($vars['value'] > 86400) {
- //$val = date("F j, Y", $vars['value']);
- $val = date('n/d/Y', $vars['value']);
-} else {
- $val = $vars['value'];
-}
-
-?>
-<input type="text" name="<?php echo $vars['internalname']; ?>" value="<?php echo $val; ?>" />
-<script language="JavaScript">
- $(document).ready(function() {
- $('input[type=text][name=<?php echo $cal_name; ?>]').datepicker();
- });
-</script>
+elgg_deprecated_notice('input/datepicker was deprecated in favor of input/date', 1.8);
+echo elgg_view('input/date', $vars); \ No newline at end of file
diff --git a/views/default/input/dropdown.php b/views/default/input/dropdown.php
new file mode 100644
index 000000000..9f07874f1
--- /dev/null
+++ b/views/default/input/dropdown.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * Elgg dropdown input
+ * Displays a dropdown (select) input field
+ *
+ * @warning Default values of FALSE or NULL will match '' (empty string) but not 0.
+ *
+ * @package Elgg
+ * @subpackage Core
+ *
+ * @uses $vars['value'] The current value, if any
+ * @uses $vars['options'] An array of strings representing the options for the dropdown field
+ * @uses $vars['options_values'] An associative array of "value" => "option"
+ * where "value" is the name and "option" is
+ * the value displayed on the button. Replaces
+ * $vars['options'] when defined.
+ * @uses $vars['class'] Additional CSS class
+ */
+
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-input-dropdown {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-dropdown";
+}
+
+$defaults = array(
+ 'disabled' => false,
+ 'value' => '',
+ 'options_values' => array(),
+ 'options' => array(),
+);
+
+$vars = array_merge($defaults, $vars);
+
+$options_values = $vars['options_values'];
+unset($vars['options_values']);
+
+$options = $vars['options'];
+unset($vars['options']);
+
+$value = $vars['value'];
+unset($vars['value']);
+
+?>
+<select <?php echo elgg_format_attributes($vars); ?>>
+<?php
+
+if ($options_values) {
+ foreach ($options_values as $opt_value => $option) {
+
+ $option_attrs = elgg_format_attributes(array(
+ 'value' => $opt_value,
+ 'selected' => (string)$opt_value == (string)$value,
+ ));
+
+ echo "<option $option_attrs>$option</option>";
+ }
+} else {
+ if (is_array($options)) {
+ foreach ($options as $option) {
+
+ $option_attrs = elgg_format_attributes(array(
+ 'selected' => (string)$option == (string)$value
+ ));
+
+ echo "<option $option_attrs>$option</option>";
+ }
+ }
+}
+?>
+</select>
diff --git a/views/default/input/email.php b/views/default/input/email.php
index c973ff7e4..190fb88c6 100644
--- a/views/default/input/email.php
+++ b/views/default/input/email.php
@@ -5,18 +5,22 @@
*
* @package Elgg
* @subpackage Core
+ *
+ * @uses $vars['class'] Additional CSS class
*/
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-input-email {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-email";
+}
+
$defaults = array(
- 'class' => 'input-text', //@todo input-email?
- 'disabled' => FALSE,
+ 'disabled' => false,
);
$vars = array_merge($defaults, $vars);
-if (!isset($vars['value']) || $vars['value'] === FALSE) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
-}
?>
<input type="text" <?php echo elgg_format_attributes($vars); ?> /> \ No newline at end of file
diff --git a/views/default/input/file.php b/views/default/input/file.php
index 8f0461083..452fe72b9 100644
--- a/views/default/input/file.php
+++ b/views/default/input/file.php
@@ -6,28 +6,26 @@
* @package Elgg
* @subpackage Core
*
- * @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
- * @uses $vars['disabled'] Is the input field disabled?
* @uses $vars['value'] The current value if any
- *
+ * @uses $vars['class'] Additional CSS class
*/
if (!empty($vars['value'])) {
echo elgg_echo('fileexists') . "<br />";
}
-$class = "input-file";
if (isset($vars['class'])) {
- $class = $vars['class'];
+ $vars['class'] = "elgg-input-file {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-file";
}
-$disabled = false;
-if (isset($vars['disabled'])) {
- $disabled = $vars['disabled'];
-}
+$defaults = array(
+ 'disabled' => false,
+ 'size' => 30,
+);
+
+$attrs = array_merge($defaults, $vars);
?>
-<input type="file" size="30" <?php echo $vars['js']; ?> name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> <?php if ($disabled) echo ' disabled="yes" '; ?> class="<?php echo $class; ?>" /> \ No newline at end of file
+<input type="file" <?php echo elgg_format_attributes($attrs); ?> />
diff --git a/views/default/input/form.php b/views/default/input/form.php
index 31c221688..df30133b3 100644
--- a/views/default/input/form.php
+++ b/views/default/input/form.php
@@ -1,14 +1,17 @@
<?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.
+ * Use this view for forms as it provides protection against CSRF attacks.
*
* @package Elgg
* @subpackage Core
*
* @uses $vars['body'] The body of the form (made up of other input/xxx views and html
+ * @uses $vars['action'] The action URL of the form
+ * @uses $vars['method'] The submit method: post (default) or get
+ * @uses $vars['enctype'] Set to 'multipart/form-data' if uploading a file
* @uses $vars['disable_security'] turn off CSRF security by setting to true
+ * @uses $vars['class'] Additional class for the form
*/
$defaults = array(
@@ -18,21 +21,24 @@ $defaults = array(
$vars = array_merge($defaults, $vars);
-$body = $vars['body'];
-unset($vars['body']);
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-form {$vars['class']}";
+} else {
+ $vars['class'] = 'elgg-form';
+}
$vars['action'] = elgg_normalize_url($vars['action']);
-
-// @todo why?
$vars['method'] = strtolower($vars['method']);
+$body = $vars['body'];
+unset($vars['body']);
+
// Generate a security header
if (!$vars['disable_security']) {
- $body .= elgg_view('input/securitytoken');
+ $body = elgg_view('input/securitytoken') . $body;
}
unset($vars['disable_security']);
-
$attributes = elgg_format_attributes($vars);
-echo "<form $attributes>$body</form>"; \ No newline at end of file
+echo "<form $attributes><fieldset>$body</fieldset></form>";
diff --git a/views/default/input/friendspicker.php b/views/default/input/friendspicker.php
new file mode 100644
index 000000000..40708c890
--- /dev/null
+++ b/views/default/input/friendspicker.php
@@ -0,0 +1,319 @@
+<?php
+/**
+ * Elgg friends picker
+ * Lists the friends picker
+ *
+ * @warning Below is the ugliest code in Elgg. It needs to be rewritten or removed
+ *
+ * @package Elgg
+ * @subpackage Core
+ *
+ * @uses $vars['entities'] The array of ElggUser objects
+ * @uses $vars['name']
+ * @uses $vars['value']
+ * @uses $vars['highlight']
+ * @uses $vars['callback']
+ */
+
+elgg_load_js('elgg.friendspicker');
+elgg_load_js('jquery.easing');
+
+
+$chararray = elgg_echo('friendspicker:chararray');
+
+// Initialise name
+if (!isset($vars['name'])) {
+ $name = "friend";
+} else {
+ $name = $vars['name'];
+}
+
+// Are we highlighting default or all?
+if (empty($vars['highlight'])) {
+ $vars['highlight'] = 'default';
+}
+if ($vars['highlight'] != 'all') {
+ $vars['highlight'] = 'default';
+}
+
+// Initialise values
+if (!isset($vars['value'])) {
+ $vars['value'] = array();
+} else {
+ if (!is_array($vars['value'])) {
+ $vars['value'] = (int) $vars['value'];
+ $vars['value'] = array($vars['value']);
+ }
+}
+
+// Initialise whether we're calling back or not
+if (isset($vars['callback'])) {
+ $callback = $vars['callback'];
+} else {
+ $callback = false;
+}
+
+// We need to count the number of friends pickers on the page.
+if (!isset($vars['friendspicker'])) {
+ global $friendspicker;
+ if (!isset($friendspicker)) {
+ $friendspicker = 0;
+ }
+ $friendspicker++;
+} else {
+ $friendspicker = $vars['friendspicker'];
+}
+
+$users = array();
+$activeletters = array();
+
+// Are we displaying form tags and submit buttons?
+// (If we've been given a target, then yes! Otherwise, no.)
+if (isset($vars['formtarget'])) {
+ $formtarget = $vars['formtarget'];
+} else {
+ $formtarget = false;
+}
+
+// Sort users by letter
+if (is_array($vars['entities']) && sizeof($vars['entities'])) {
+ foreach($vars['entities'] as $user) {
+ $letter = elgg_strtoupper(elgg_substr($user->name, 0, 1));
+
+ if (!elgg_substr_count($chararray, $letter)) {
+ $letter = "*";
+ }
+ if (!isset($users[$letter])) {
+ $users[$letter] = array();
+ }
+ $users[$letter][$user->guid] = $user;
+ }
+}
+
+// sort users in letters alphabetically
+foreach ($users as $letter => $letter_users) {
+ usort($letter_users, create_function('$a, $b', '
+ return strcasecmp($a->name, $b->name);
+ '));
+ $users[$letter] = $letter_users;
+}
+
+if (!$callback) {
+ ?>
+
+ <div class="friends-picker-main-wrapper">
+
+ <?php
+
+ if (isset($vars['content'])) {
+ echo $vars['content'];
+ }
+ ?>
+
+ <div id="friends-picker_placeholder<?php echo $friendspicker; ?>">
+
+ <?php
+}
+
+if (!isset($vars['replacement'])) {
+ if ($formtarget) {
+?>
+<?php //@todo JS 1.8: no ?>
+<script language="text/javascript">
+ $(function() { // onload...do
+ $('#collectionMembersForm<?php echo $friendspicker; ?>').submit(function() {
+ var inputs = [];
+ $(':input', this).each(function() {
+ if (this.type != 'checkbox' || (this.type == 'checkbox' && this.checked != false)) {
+ inputs.push(this.name + '=' + escape(this.value));
+ }
+ });
+ jQuery.ajax({
+ type: "POST",
+ data: inputs.join('&'),
+ url: this.action,
+ success: function(){
+ $('a.collectionmembers<?php echo $friendspicker; ?>').click();
+ }
+
+ });
+ return false;
+ })
+ })
+
+ </script>
+
+<!-- Collection members form -->
+<form id="collectionMembersForm<?php echo $friendspicker; ?>" action="<?php echo $formtarget; ?>" method="post"> <!-- action="" method=""> -->
+
+<?php
+ echo elgg_view('input/securitytoken');
+ echo elgg_view('input/hidden', array(
+ 'name' => 'collection_id',
+ 'value' => $vars['collection_id'],
+ ));
+ }
+?>
+
+<div class="friends-picker-wrapper">
+<div id="friends-picker<?php echo $friendspicker; ?>">
+ <div class="friends-picker-container">
+<?php
+
+// Initialise letters
+ $chararray .= "*";
+ $letter = elgg_substr($chararray, 0, 1);
+ $letpos = 0;
+ while (1 == 1) {
+ ?>
+ <div class="panel" title="<?php echo $letter; ?>">
+ <div class="wrapper">
+ <h3><?php echo $letter; ?></h3>
+ <?php
+
+ if (isset($users[$letter])) {
+ ksort($users[$letter]);
+
+ echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
+ $col = 0;
+
+ foreach($users[$letter] as $friend) {
+ if ($col == 0) {
+ echo "<tr>";
+ }
+
+ //echo "<p>" . $user->name . "</p>";
+ $label = elgg_view_entity_icon($friend, 'tiny', array('use_hover' => false));
+ $options[$label] = $friend->getGUID();
+
+ if ($vars['highlight'] == 'all' && !in_array($letter,$activeletters)) {
+ $activeletters[] = $letter;
+ }
+
+
+ if (in_array($friend->getGUID(),$vars['value'])) {
+ $checked = "checked = \"checked\"";
+ if (!in_array($letter,$activeletters) && $vars['highlight'] == 'default') {
+ $activeletters[] = $letter;
+ }
+ } else {
+ $checked = "";
+ }
+ ?>
+
+ <td>
+
+ <input type="checkbox" <?php echo $checked; ?> name="<?php echo $name; ?>[]" value="<?php echo $options[$label]; ?>" />
+
+ </td>
+
+ <td>
+
+ <div style="width: 25px; margin-bottom: 15px;">
+ <?php
+ echo $label;
+ ?>
+ </div>
+ </td>
+ <td style="width: 200px; padding: 5px;">
+ <?php echo $friend->name; ?>
+ </td>
+ <?php
+ $col++;
+ if ($col == 3){
+ echo "</tr>";
+ $col = 0;
+ }
+ }
+ if ($col < 3) {
+ echo "</tr>";
+ }
+
+ echo "</table>";
+ }
+
+?>
+
+ </div>
+ </div>
+<?php
+
+ $substr = elgg_substr($chararray, elgg_strlen($chararray) - 1, 1);
+ if ($letter == $substr) {
+ break;
+ }
+ //$letter++;
+ $letpos++;
+ $letter = elgg_substr($chararray, $letpos, 1);
+ }
+
+?>
+ </div>
+
+<?php
+
+if ($formtarget) {
+
+ if (isset($vars['formcontents']))
+ echo $vars['formcontents'];
+
+?>
+ <div class="clearfix"></div>
+ <div class="friendspicker-savebuttons">
+ <input type="submit" class="elgg-button elgg-button-submit" value="<?php echo elgg_echo('save'); ?>" />
+ <input type="button" class="elgg-button elgg-button-cancel" value="<?php echo elgg_echo('cancel'); ?>" onclick="$('a.collectionmembers<?php echo $friendspicker; ?>').click();" />
+ <br /></div>
+ </form>
+
+<?php
+
+}
+
+?>
+
+</div>
+</div>
+
+<?php
+} else {
+ echo $vars['replacement'];
+}
+if (!$callback) {
+
+?>
+
+</div>
+</div>
+
+
+<?php
+
+}
+
+if (!isset($vars['replacement'])) {
+?>
+<?php //@todo JS 1.8: no ?>
+<script type="text/javascript">
+ // initialise picker
+ $("div#friends-picker<?php echo $friendspicker; ?>").friendsPicker(<?php echo $friendspicker; ?>);
+</script>
+<script type="text/javascript">
+$(document).ready(function () {
+// manually add class to corresponding tab for panels that have content
+<?php
+if (sizeof($activeletters) > 0)
+ //$chararray = elgg_echo('friendspicker:chararray');
+ foreach($activeletters as $letter) {
+ $tab = elgg_strpos($chararray, $letter) + 1;
+?>
+$("div#friends-picker-navigation<?php echo $friendspicker; ?> li.tab<?php echo $tab; ?> a").addClass("tabHasContent");
+<?php
+ }
+
+?>
+});
+</script>
+
+<?php
+
+} \ No newline at end of file
diff --git a/views/default/input/hidden.php b/views/default/input/hidden.php
index a5fb01e73..9c2fc6c08 100644
--- a/views/default/input/hidden.php
+++ b/views/default/input/hidden.php
@@ -1,21 +1,12 @@
<?php
/**
* Create a hidden data field
- * Use this view for forms rather than creating a hidden tag in the wild as it provides
- * extra security which help prevent CSRF attacks.
*
* @package Elgg
* @subpackage Core
*
* @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
- *
*/
-if (!isset($vars['value']) || $vars['value'] === FALSE) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
-}
-
?>
-<input type="hidden" <?php echo $vars['js']; ?> name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> value="<?php echo htmlentities($vars['value'], ENT_QUOTES, 'UTF-8'); ?>" /> \ No newline at end of file
+<input type="hidden" <?php echo elgg_format_attributes($vars); ?> /> \ No newline at end of file
diff --git a/views/default/input/location.php b/views/default/input/location.php
new file mode 100644
index 000000000..4cf05c72a
--- /dev/null
+++ b/views/default/input/location.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Location input field
+ *
+ * @uses $vars['entity'] The ElggEntity that has a location
+ * @uses $vars['value'] The default value for the location
+ * @uses $vars['class'] Additional CSS class
+ */
+
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-input-location {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-location";
+}
+
+$defaults = array(
+ 'disabled' => false,
+);
+
+if (isset($vars['entity'])) {
+ $defaults['value'] = $vars['entity']->location;
+ unset($vars['entity']);
+}
+
+$vars = array_merge($defaults, $vars);
+
+echo elgg_view('input/tag', $vars);
diff --git a/views/default/input/longtext.php b/views/default/input/longtext.php
index d784c6014..61dc7ca19 100644
--- a/views/default/input/longtext.php
+++ b/views/default/input/longtext.php
@@ -1,38 +1,42 @@
<?php
/**
* Elgg long text input
- * Displays a long text input field
+ * Displays a long text input field that can use WYSIWYG editor
*
* @package Elgg
* @subpackage Core
*
- * @uses $vars['value'] The current value, if any - will be html 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
+ * @uses $vars['value'] The current value, if any - will be html encoded
* @uses $vars['disabled'] Is the input field disabled?
+ * @uses $vars['class'] Additional CSS class
*/
-$class = "input-textarea";
if (isset($vars['class'])) {
- $class = $vars['class'];
+ $vars['class'] = "elgg-input-longtext {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-longtext";
}
-$disabled = false;
-if (isset($vars['disabled'])) {
- $disabled = $vars['disabled'];
-}
+$defaults = array(
+ 'value' => '',
+ 'rows' => '10',
+ 'cols' => '50',
+ 'id' => 'elgg-input-' . rand(), //@todo make this more robust
+);
-if (!isset($vars['value']) || $vars['value'] === FALSE) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
-}
+$vars = array_merge($defaults, $vars);
-$value = '';
-if (isset($vars['value'])) {
- $value = $vars['value'];
-}
+$value = $vars['value'];
+unset($vars['value']);
+
+echo elgg_view_menu('longtext', array(
+ 'sort_by' => 'priority',
+ 'class' => 'elgg-menu-hz',
+ 'id' => $vars['id'],
+));
?>
-<textarea class="<?php echo $class; ?>" name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> <?php if ($disabled) echo ' disabled="yes" '; ?> <?php echo $vars['js']; ?>><?php echo htmlentities($value, ENT_QUOTES, 'UTF-8'); ?></textarea> \ No newline at end of file
+<textarea <?php echo elgg_format_attributes($vars); ?>>
+<?php echo htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false); ?>
+</textarea>
diff --git a/views/default/input/password.php b/views/default/input/password.php
index 0d1523977..45f2b20a6 100644
--- a/views/default/input/password.php
+++ b/views/default/input/password.php
@@ -7,15 +7,22 @@
* @subpackage Core
*
* @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['name'] The name of the input field
+ * @uses $vars['class'] Additional CSS class
*/
-$class = $vars['class'];
-if (!$class) {
- $class = "input-password";
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-input-password {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-password";
}
+
+$defaults = array(
+ 'disabled' => false,
+ 'value' => '',
+);
+
+$attrs = array_merge($defaults, $vars);
?>
-<input type="password" <?php if ($vars['disabled']) echo ' disabled="yes" '; ?> <?php echo $vars['js']; ?> name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> value="<?php echo htmlentities($vars['value'], ENT_QUOTES, 'UTF-8'); ?>" class="<?php echo $class; ?>" /> \ No newline at end of file
+<input type="password" <?php echo elgg_format_attributes($attrs); ?> />
diff --git a/views/default/input/plaintext.php b/views/default/input/plaintext.php
index e2b8c5ed2..e92c61ced 100644
--- a/views/default/input/plaintext.php
+++ b/views/default/input/plaintext.php
@@ -6,21 +6,32 @@
* @package Elgg
* @subpackage Core
*
- * @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['value'] The current value, if any
+ * @uses $vars['name'] The name of the input field
+ * @uses $vars['class'] Additional CSS class
+ * @uses $vars['disabled']
*/
-$class = $vars['class'];
-if (!$class) {
- $class = "input-textarea";
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-input-plaintext {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-plaintext";
}
-if (!isset($vars['value']) || $vars['value'] === FALSE) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
-}
+$defaults = array(
+ 'value' => '',
+ 'rows' => '10',
+ 'cols' => '50',
+ 'disabled' => false,
+);
+
+$vars = array_merge($defaults, $vars);
+
+$value = $vars['value'];
+unset($vars['value']);
?>
-<textarea class="<?php echo $class; ?>" name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> <?php if ($vars['disabled']) echo ' disabled="yes" '; ?> <?php echo $vars['js']; ?>><?php echo htmlentities($vars['value'], ENT_QUOTES, 'UTF-8'); ?></textarea> \ No newline at end of file
+<textarea <?php echo elgg_format_attributes($vars); ?>>
+<?php echo htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false); ?>
+</textarea>
diff --git a/views/default/input/pulldown.php b/views/default/input/pulldown.php
index f789d1020..fc0595300 100644
--- a/views/default/input/pulldown.php
+++ b/views/default/input/pulldown.php
@@ -1,56 +1,9 @@
<?php
/**
- * Elgg pulldown input
- * Displays a pulldown input field
+ * Deprecated pulldown input view - use 'input/dropdown' instead.
*
- * NB: Default values of FALSE or NULL will match '' (empty string) and not 0.
- *
- * @package Elgg
- * @subpackage Core
- *
- * @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.
+ * @deprecated 1.8
*/
-$class = $vars['class'];
-if (!$class) {
- $class = "input-pulldown";
-}
-
-if (!isset($vars['value'])) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
-}
-
-?>
-<select name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> <?php echo $vars['js']; ?> <?php if ($vars['disabled']) echo ' disabled="yes" '; ?> class="<?php echo $class; ?>">
-<?php
-
-if ($vars['options_values']) {
- foreach($vars['options_values'] as $value => $option) {
-
- $encoded_value = htmlentities($value, ENT_QUOTES, 'UTF-8');
- $encoded_option = htmlentities($option, ENT_QUOTES, 'UTF-8');
-
- if ((string)$value == (string)$vars['value']) {
- echo "<option value=\"$encoded_value\" selected=\"selected\">$encoded_option</option>";
- } else {
- echo "<option value=\"$encoded_value\">$encoded_option</option>";
- }
- }
-} else {
- foreach($vars['options'] as $option) {
- $encoded_option = htmlentities($option, ENT_QUOTES, 'UTF-8');
-
- if ((string)$option == (string)$vars['value']) {
- echo "<option selected=\"selected\">$encoded_option</option>";
- } else {
- echo "<option>$encoded_option</option>";
- }
- }
-}
-?>
-</select> \ No newline at end of file
+elgg_deprecated_notice("input/pulldown was deprecated by input/dropdown", 1.8, 2);
+echo elgg_view('input/dropdown', $vars);
diff --git a/views/default/input/radio.php b/views/default/input/radio.php
index 0a5885f8b..ef860a773 100644
--- a/views/default/input/radio.php
+++ b/views/default/input/radio.php
@@ -3,43 +3,74 @@
* Elgg radio input
* Displays a radio input field
*
+ * @warning Passing integers as labels does not currently work due to a
+ * deprecated hack that will be removed in Elgg 1.9. To use integer labels,
+ * the labels must be character codes: 1 would be &#0049;
+ *
* @package Elgg
* @subpackage Core
*
- * @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 radio field as "label" => option
- *
+ * @uses $vars['value'] The current value, if any
+ * @uses $vars['name'] The name of the input field
+ * @uses $vars['options'] An array of strings representing the options for the
+ * radio field as "label" => option
+ * @uses $vars['class'] Additional class of the list. Optional.
+ * @uses $vars['align'] 'horizontal' or 'vertical' Default: 'vertical'
*/
-$class = $vars['class'];
-if (!$class) {
- $class = "input-radio";
+$defaults = array(
+ 'align' => 'vertical',
+ 'value' => array(),
+ 'disabled' => false,
+ 'options' => array(),
+ 'name' => '',
+);
+
+$vars = array_merge($defaults, $vars);
+
+$id = '';
+if (isset($vars['id'])) {
+ $id = "id=\"{$vars['id']}\"";
+ unset($vars['id']);
}
-if (!isset($vars['value']) || $vars['value'] === FALSE) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+$class = "elgg-input-radios elgg-{$vars['align']}";
+if (isset($vars['class'])) {
+ $class .= " {$vars['class']}";
+ unset($vars['class']);
}
+unset($vars['align']);
+$vars['class'] = 'elgg-input-radio';
-foreach($vars['options'] as $label => $option) {
- if (strtolower($option) != strtolower($vars['value'])) {
- $selected = "";
- } else {
- $selected = "checked = \"checked\"";
- }
+if (is_array($vars['value'])) {
+ $vars['value'] = array_map('elgg_strtolower', $vars['value']);
+} else {
+ $vars['value'] = array(elgg_strtolower($vars['value']));
+}
- // handle indexed array where label is not specified
- // @todo deprecate in Elgg 1.8
- if (is_integer($label)) {
- $label = $option;
- }
-
- if (isset($vars['internalid'])) {
- $id = "id=\"{$vars['internalid']}\"";
- }
- if ($vars['disabled']) {
- $disabled = ' disabled="yes" ';
+$options = $vars['options'];
+unset($vars['options']);
+
+$value = $vars['value'];
+unset($vars['value']);
+
+if ($options && count($options) > 0) {
+ echo "<ul class=\"$class\" $id>";
+ foreach ($options as $label => $option) {
+
+ $vars['checked'] = in_array(elgg_strtolower($option), $value);
+ $vars['value'] = $option;
+
+ $attributes = elgg_format_attributes($vars);
+
+ // handle indexed array where label is not specified
+ // @deprecated 1.8 Remove in 1.9
+ if (is_integer($label)) {
+ elgg_deprecated_notice('$vars[\'options\'] must be an associative array in input/radio', 1.8);
+ $label = $option;
+ }
+
+ echo "<li><label><input type=\"radio\" $attributes />$label</label></li>";
}
- echo "<label><input type=\"radio\" $disabled {$vars['js']} name=\"{$vars['internalname']}\" $id value=\"".htmlentities($option, ENT_QUOTES, 'UTF-8')."\" {$selected} class=\"$class\" />{$label}</label><br />";
-} \ No newline at end of file
+ echo '</ul>';
+}
diff --git a/views/default/input/reset.php b/views/default/input/reset.php
index d1296e4bf..082da8669 100644
--- a/views/default/input/reset.php
+++ b/views/default/input/reset.php
@@ -2,14 +2,13 @@
/**
* Create a reset input button
*
- * @todo ... huh?
- * Use this view for forms rather than creating a submit/reset button tag in the wild as it provides
- * extra security which help prevent CSRF attacks.
- *
* @package Elgg
* @subpackage Core
+ *
+ * @uses $vars['class'] CSS class that replaces elgg-button-cancel
*/
$vars['type'] = 'reset';
+$vars['class'] = elgg_extract('class', $vars, 'elgg-button-cancel');
echo elgg_view('input/button', $vars); \ No newline at end of file
diff --git a/views/default/input/securitytoken.php b/views/default/input/securitytoken.php
index 9a8cb1ebe..75410848a 100644
--- a/views/default/input/securitytoken.php
+++ b/views/default/input/securitytoken.php
@@ -11,5 +11,5 @@
$ts = time();
$token = generate_action_token($ts);
-echo elgg_view('input/hidden', array('internalname' => '__elgg_token', 'value' => $token));
-echo elgg_view('input/hidden', array('internalname' => '__elgg_ts', 'value' => $ts));
+echo elgg_view('input/hidden', array('name' => '__elgg_token', 'value' => $token));
+echo elgg_view('input/hidden', array('name' => '__elgg_ts', 'value' => $ts));
diff --git a/views/default/input/submit.php b/views/default/input/submit.php
index 39734b807..df369b3b4 100644
--- a/views/default/input/submit.php
+++ b/views/default/input/submit.php
@@ -2,14 +2,13 @@
/**
* Create a submit input button
*
- * @todo ... huh?
- * Use this view for forms rather than creating a submit/reset button tag in the wild as it provides
- * extra security which help prevent CSRF attacks.
- *
* @package Elgg
* @subpackage Core
+ *
+ * @uses $vars['class'] CSS class that replaces elgg-button-submit
*/
$vars['type'] = 'submit';
+$vars['class'] = elgg_extract('class', $vars, 'elgg-button-submit');
echo elgg_view('input/button', $vars); \ No newline at end of file
diff --git a/views/default/input/tag.php b/views/default/input/tag.php
new file mode 100644
index 000000000..8893a18ff
--- /dev/null
+++ b/views/default/input/tag.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * Elgg tag input
+ *
+ * Accepts a single tag value
+ *
+ * @uses $vars['value'] The default value for the tag
+ * @uses $vars['class'] Additional CSS class
+ */
+
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-input-tag {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-tag";
+}
+
+$defaults = array(
+ 'value' => '',
+ 'disabled' => false,
+);
+
+$vars = array_merge($defaults, $vars);
+?>
+
+<input type="text" <?php echo elgg_format_attributes($vars); ?> /> \ No newline at end of file
diff --git a/views/default/input/tags.php b/views/default/input/tags.php
index 6ce074a2a..261cf9f97 100644
--- a/views/default/input/tags.php
+++ b/views/default/input/tags.php
@@ -3,21 +3,30 @@
* Elgg tag input
* Displays a tag input field
*
- * @package Elgg
- * @subpackage Core
+ * @uses $vars['disabled']
+ * @uses $vars['class'] Additional CSS class
+ * @uses $vars['value'] Array of tags or a string
+ * @uses $vars['entity'] Optional. Entity whose tags are being displayed (metadata ->tags)
*/
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-input-tags {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-tags";
+}
+
$defaults = array(
- 'class' => 'input-tags',
- 'disabled' => FALSE,
+ 'value' => '',
+ 'disabled' => false,
);
-$vars = array_merge($defaults, $vars);
-
-if (!isset($vars['value']) || $vars['value'] === FALSE) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+if (isset($vars['entity'])) {
+ $defaults['value'] = $vars['entity']->tags;
+ unset($vars['entity']);
}
+$vars = array_merge($defaults, $vars);
+
if (is_array($vars['value'])) {
$tags = array();
diff --git a/views/default/input/text.php b/views/default/input/text.php
index 9f3076ed3..07ce5c710 100644
--- a/views/default/input/text.php
+++ b/views/default/input/text.php
@@ -5,18 +5,22 @@
*
* @package Elgg
* @subpackage Core
+ *
+ * @uses $vars['class'] Additional CSS class
*/
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-input-text {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-text";
+}
+
$defaults = array(
- 'class' => 'input-text',
- 'disabled' => FALSE,
+ 'value' => '',
+ 'disabled' => false,
);
$vars = array_merge($defaults, $vars);
-if (!isset($vars['value']) || $vars['value'] === FALSE) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
-}
?>
-
<input type="text" <?php echo elgg_format_attributes($vars); ?> /> \ No newline at end of file
diff --git a/views/default/input/url.php b/views/default/input/url.php
index fddf44a5b..e97a316d8 100644
--- a/views/default/input/url.php
+++ b/views/default/input/url.php
@@ -5,17 +5,23 @@
*
* @package Elgg
* @subpackage Core
+ *
+ * @uses $vars['class'] Additional CSS class
*/
+if (isset($vars['class'])) {
+ $vars['class'] = "elgg-input-url {$vars['class']}";
+} else {
+ $vars['class'] = "elgg-input-url";
+}
+
$defaults = array(
- 'class' => 'input-url',
+ 'value' => '',
+ 'disabled' => false,
);
$vars = array_merge($defaults, $vars);
-if (!isset($vars['value']) || $vars['value'] === FALSE) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
-}
?>
<input type="text" <?php echo elgg_format_attributes($vars); ?> />
diff --git a/views/default/input/userpicker.php b/views/default/input/userpicker.php
index 85fbd70f1..8b64d7df5 100644
--- a/views/default/input/userpicker.php
+++ b/views/default/input/userpicker.php
@@ -5,45 +5,43 @@
* @package Elgg
* @subpackage Core
*
- * @uses $vars['value'] The current value, if any
- * @uses $vars['internalname'] The name of the input field
+ * @uses $vars['value'] Array of user guids for already selected users or null
*
+ * The name of the hidden fields is members[]
*
- * pops up defaulted to lazy load friends lists in paginated alphabetical order.
- * upon
+ * @warning Only a single input/userpicker is supported per web page.
*
- * As users are checked they move down to a "users" box.
- * When this happens, a hidden input is created also.
- * {$internalnal}[] with the value th GUID.
+ * Defaults to lazy load user lists in alphabetical order. User needs
+ * to type two characters before seeing the user popup list.
*
+ * As users are selected they move down to a "users" box.
+ * When this happens, a hidden input is created with the
+ * name of members[] and a value of the GUID.
*/
-global $user_picker_js_sent;
+elgg_load_js('elgg.userpicker');
+elgg_load_js('jquery.ui.autocomplete.html');
function user_picker_add_user($user_id) {
$user = get_entity($user_id);
if (!$user || !($user instanceof ElggUser)) {
- return FALSE;
+ return false;
}
- $icon = $user->getIcon('tiny');
-
- $code = '<li class="user-picker-entry">';
- $code .= "<img class=\"livesearch_icon\" src=\"$icon\" />";
- $code .= "$user->name - $user->username";
- $code .= '<div class="delete-button">';
- $code .= "<a onclick=\"userPickerRemoveUser(this, $user_id)\"><strong>X</strong></a>";
- $code .= '</div>';
+ $icon = elgg_view_entity_icon($user, 'tiny', array('use_hover' => false));
+
+ // this html must be synced with the userpicker.js library
+ $code = '<li><div class="elgg-image-block">';
+ $code .= "<div class='elgg-image'>$icon</div>";
+ $code .= "<div class='elgg-image-alt'><a href='#' class='elgg-userpicker-remove'>X</a></div>";
+ $code .= "<div class='elgg-body'>" . $user->name . "</div>";
+ $code .= "</div>";
$code .= "<input type=\"hidden\" name=\"members[]\" value=\"$user_id\">";
$code .= '</li>';
return $code;
}
-if (!isset($vars['value']) || $vars['value'] === FALSE) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
-}
-
// loop over all values and prepare them so that "in" will work in javascript
$values = array();
if (!is_array($vars['value'])) {
@@ -56,123 +54,6 @@ foreach ($vars['value'] as $value) {
// convert the values to a json-encoded list
$json_values = json_encode($values);
-if (!$user_picker_js_sent) {
-?>
-<!-- User picker JS -->
-<script language="javascript" type="text/javascript" src="<?php echo elgg_get_site_url(); ?>vendors/jquery/jquery.autocomplete.min.js"></script>
-<script type="text/javascript">
-// set up a few required variables
-userPickerURL = '<?php echo elgg_get_site_url() ?>pg/livesearch';
-userList = <?php echo $json_values ?>;
-
-function userPickerBindEvents() {
- // binding autocomplete.
- // doing this as an each so we can past this to functions.
- $('.user-picker .search').each(function (i, e) {
- userPickerBindAutocomplete(e);
- });
-
- // changing friends vs all users.
- $('.user-picker .all_users').click(function() {
- // update the extra params for the autocomplete.
- var e = $(this).parents('.user-picker').find('.search');
- var params = userPickerGetSearchParams(e);
- e.setOptions({extraParams: params});
- e.flushCache();
- });
-
- // hitting enter on the text field
-// $('.user-picker .search').bind($.browser.opera ? "keypress" : "keydown", function(event) {
-// if(event.keyCode == 13) {
-//// console.log($(this).val());
-// userPickerAddUser(this);
-// }
-// });
-}
-
-function userPickerBindAutocomplete(e) {
- var params = userPickerGetSearchParams(e);
-
- $(e).autocomplete(userPickerURL, {
- extraParams: params,
- max: 25,
- minChars: 2,
- matchContains: false,
- autoFill: false,
- formatItem: userPickerFormatItem,
- formatResult: function (row, i, max) {
- eval("var info = " + row + ";");
- // returning the just name
- return info.name;
- }
- });
-
- // add users when a result is picked.
- $(e).result(userPickerAddUser);
-}
-
-function userPickerFormatItem(row, i, max, term) {
- eval("var info = " + row + ";");
- var r = '';
- var name = info.name.replace(new RegExp("(" + term + ")", "gi"), "<span class=\"user-picker_highlight\">$1</b>");
- var desc = info.desc.replace(new RegExp("(" + term + ")", "gi"), "<span class=\"user-picker_highlight\">$1</b>");
-
- switch (info.type) {
- case 'user':
- case 'group':
- r = info.icon + name + ' - ' + desc;
- break;
-
- default:
- r = name + ' - ' + desc;
- break;
- }
- return r;
- //return r.replace(new RegExp("(" + term + ")", "gi"), "<span class=\"user-picker_highlight\">$1</b>");
-}
-
-function userPickerAddUser(event, data, formatted) {
- eval("var info = " + data + ";");
-
- // do not allow users to be added multiple times
- if (!(info.guid in userList)) {
- userList[info.guid] = true;
-
- var picker = $(this).parent('.user-picker');
- var users = picker.find('.users');
- var internalName = picker.find('input.internalname').val();
- // not sure why formatted isn't.
- var formatted = userPickerFormatItem(data);
-
- // add guid as hidden input and to list.
- var li = formatted + ' <div class="delete-button"><a onclick="userPickerRemoveUser(this, ' + info.guid + ')"><strong>X</strong></a></div>'
- + '<input type="hidden" name="' + internalName + '[]" value="' + info.guid + '" />';
- $('<li class="user-picker-entry">').html(li).appendTo(users);
-
- $(this).val('');
- }
-}
-
-function userPickerRemoveUser(link, guid) {
- $(link).parents('.user-picker-entry').remove();
-}
-
-function userPickerGetSearchParams(e) {
- if ($(e).parent().find('.all_users').attr('checked')) {
- return {'match_on[]': 'friends'};
- } else {
- return {'match_on[]': 'users'};
- }
-}
-
-$(document).ready(function() {
- userPickerBindEvents();
-});
-</script>
-<?php
- $user_picker_js_sent = true;
-}
-
// create an HTML list of users
$user_list = '';
foreach ($vars['value'] as $user_id) {
@@ -180,14 +61,15 @@ foreach ($vars['value'] as $user_id) {
}
?>
-<div class="user-picker">
- <input class="internalname" type="hidden" name="internalname" value="<?php echo $vars['internalname']; ?>" />
- <input class="search" type="text" name="user_search" size="30"/>
- <span class="controls">
- <label><input class="all_users" type="checkbox" name="match_on" value="true" /><?php echo elgg_echo('userpicker:only_friends'); ?></label>
- </span>
- <div class="results">
- <!-- This space will be filled with users, checkboxes and magic. -->
- </div>
- <ul class="users"><?php echo $user_list; ?></ul>
+<div class="elgg-user-picker">
+ <input type="text" class="elgg-input-user-picker" size="30"/>
+ <label>
+ <input type="checkbox" name="match_on" value="true" />
+ <?php echo elgg_echo('userpicker:only_friends'); ?>
+ </label>
+ <ul class="elgg-user-picker-list"><?php echo $user_list; ?></ul>
</div>
+<script type="text/javascript">
+ // @todo grab the values in the init function rather than using inline JS
+ elgg.userpicker.userList = <?php echo $json_values ?>;
+</script>