diff options
Diffstat (limited to 'kohana/helpers')
-rw-r--r-- | kohana/helpers/arr.php | 15 | ||||
-rw-r--r-- | kohana/helpers/form.php | 36 | ||||
-rw-r--r-- | kohana/helpers/url.php | 3 | ||||
-rw-r--r-- | kohana/helpers/valid.php | 2 |
4 files changed, 29 insertions, 27 deletions
diff --git a/kohana/helpers/arr.php b/kohana/helpers/arr.php index 24b03d7f..87f2be1f 100644 --- a/kohana/helpers/arr.php +++ b/kohana/helpers/arr.php @@ -84,7 +84,7 @@ class arr_Core { return $val; } - + /** * Extract one or more keys from an array. Each key given after the first * argument (the array) will be extracted. Keys that do not exist in the @@ -251,13 +251,18 @@ class arr_Core { * @param array input array(s) that will overwrite key array values * @return array */ - public static function overwrite($array1) + public static function overwrite($array1, $array2) { - foreach (array_slice(func_get_args(), 1) as $array2) + foreach (array_intersect_key($array2, $array1) as $key => $value) + { + $array1[$key] = $value; + } + + if (func_num_args() > 2) { - foreach ($array2 as $key => $value) + foreach (array_slice(func_get_args(), 2) as $array2) { - if (array_key_exists($key, $array1)) + foreach (array_intersect_key($array2, $array1) as $key => $value) { $array1[$key] = $value; } diff --git a/kohana/helpers/form.php b/kohana/helpers/form.php index bd656604..0eaec0dc 100644 --- a/kohana/helpers/form.php +++ b/kohana/helpers/form.php @@ -144,10 +144,9 @@ class form_Core { * @param string|array input name or an array of HTML attributes * @param string input value, when using a name * @param string a string to be attached to the end of the attributes - * @param boolean encode existing entities * @return string */ - public static function input($data, $value = '', $extra = '', $double_encode = TRUE ) + public static function input($data, $value = '', $extra = '') { if ( ! is_array($data)) { @@ -161,9 +160,6 @@ class form_Core { 'value' => $value ); - // For safe form data - $data['value'] = html::specialchars($data['value'], $double_encode); - return '<input'.form::attributes($data).' '.$extra.' />'; } @@ -216,7 +212,7 @@ class form_Core { * @param boolean encode existing entities * @return string */ - public static function textarea($data, $value = '', $extra = '', $double_encode = TRUE ) + public static function textarea($data, $value = '', $extra = '', $double_encode = TRUE) { if ( ! is_array($data)) { @@ -243,7 +239,6 @@ class form_Core { */ public static function dropdown($data, $options = NULL, $selected = NULL, $extra = '') { - if ( ! is_array($data)) { $data = array('name' => $data); @@ -263,15 +258,23 @@ class form_Core { } } + if (is_array($selected)) + { + // Multi-select box + $data['multiple'] = 'multiple'; + } + else + { + // Single selection (but converted to an array) + $selected = array($selected); + } + $input = '<select'.form::attributes($data, 'select').' '.$extra.'>'."\n"; foreach ((array) $options as $key => $val) { // Key should always be a string $key = (string) $key; - // Selected must always be a string - $selected = (string) $selected; - if (is_array($val)) { $input .= '<optgroup label="'.$key.'">'."\n"; @@ -280,23 +283,14 @@ class form_Core { // Inner key should always be a string $inner_key = (string) $inner_key; - if (is_array($selected)) - { - $sel = in_array($inner_key, $selected, TRUE); - } - else - { - $sel = ($selected === $inner_key); - } - - $sel = ($sel === TRUE) ? ' selected="selected"' : ''; + $sel = in_array($inner_key, $selected) ? ' selected="selected"' : ''; $input .= '<option value="'.$inner_key.'"'.$sel.'>'.$inner_val.'</option>'."\n"; } $input .= '</optgroup>'."\n"; } else { - $sel = ($selected === $key) ? ' selected="selected"' : ''; + $sel = in_array($key, $selected) ? ' selected="selected"' : ''; $input .= '<option value="'.$key.'"'.$sel.'>'.$val.'</option>'."\n"; } } diff --git a/kohana/helpers/url.php b/kohana/helpers/url.php index 5b3b5fd2..46055299 100644 --- a/kohana/helpers/url.php +++ b/kohana/helpers/url.php @@ -243,6 +243,9 @@ class url_Core { header('Location: '.$uri); } + // We are about to exit, so run the send_headers event + Event::run('system.send_headers'); + exit('<h1>'.$method.' - '.$codes[$method].'</h1>'.$output); } diff --git a/kohana/helpers/valid.php b/kohana/helpers/valid.php index c2cefb5d..916a0c19 100644 --- a/kohana/helpers/valid.php +++ b/kohana/helpers/valid.php @@ -203,7 +203,7 @@ class valid_Core { * @param string date to check * @return boolean */ - public function date($str) + public static function date($str) { return (strtotime($str) !== FALSE); } |