summaryrefslogtreecommitdiff
path: root/kohana/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'kohana/helpers')
-rw-r--r--kohana/helpers/arr.php49
-rw-r--r--kohana/helpers/date.php8
-rw-r--r--kohana/helpers/expires.php3
-rw-r--r--kohana/helpers/feed.php6
-rw-r--r--kohana/helpers/form.php2
-rw-r--r--kohana/helpers/request.php2
-rw-r--r--kohana/helpers/valid.php2
7 files changed, 36 insertions, 36 deletions
diff --git a/kohana/helpers/arr.php b/kohana/helpers/arr.php
index 87f2be1f..9f0dc097 100644
--- a/kohana/helpers/arr.php
+++ b/kohana/helpers/arr.php
@@ -152,52 +152,43 @@ class arr_Core {
}
/**
- * Binary search algorithm.
- *
- * @param mixed the value to search for
- * @param array an array of values to search in
- * @param boolean return false, or the nearest value
- * @param mixed sort the array before searching it
- * @return integer
+ * @param mixed $needle the value to search for
+ * @param array $haystack an array of values to search in
+ * @param boolean $sort sort the array now
+ * @return integer|FALSE the index of the match or FALSE when not found
*/
- public static function binary_search($needle, $haystack, $nearest = FALSE, $sort = FALSE)
+ public static function binary_search($needle, $haystack, $sort = FALSE)
{
- if ($sort === TRUE)
+ if ($sort)
{
sort($haystack);
}
- $high = count($haystack);
+ $high = count($haystack) - 1;
$low = 0;
- while ($high - $low > 1)
+ while ($low <= $high)
{
- $probe = ($high + $low) / 2;
- if ($haystack[$probe] < $needle)
+ $mid = ($low + $high) >> 1;
+
+ if ($haystack[$mid] < $needle)
{
- $low = $probe;
+ $low = $mid + 1;
+ }
+ elseif ($haystack[$mid] > $needle)
+ {
+ $high = $mid - 1;
}
else
{
- $high = $probe;
+ return $mid;
}
}
- if ($high == count($haystack) OR $haystack[$high] != $needle)
- {
- if ($nearest === FALSE)
- return FALSE;
-
- // return the nearest value
- $high_distance = $haystack[ceil($low)] - $needle;
- $low_distance = $needle - $haystack[floor($low)];
-
- return ($high_distance >= $low_distance) ? $haystack[ceil($low)] : $haystack[floor($low)];
- }
-
- return $high;
+ return FALSE;
}
+
/**
* Emulates array_merge_recursive, but appends numeric keys and replaces
* associative keys, instead of appending all keys.
@@ -318,4 +309,4 @@ class arr_Core {
return $object;
}
-} // End arr \ No newline at end of file
+} // End arr
diff --git a/kohana/helpers/date.php b/kohana/helpers/date.php
index b926e626..1a5bbacb 100644
--- a/kohana/helpers/date.php
+++ b/kohana/helpers/date.php
@@ -374,7 +374,7 @@ class date_Core {
$span = array();
foreach ($difference as $name => $amount)
{
- if ($name !== $last AND $amount === 0)
+ if ($amount === 0)
{
// Skip empty amounts
continue;
@@ -384,6 +384,12 @@ class date_Core {
$span[] = ($name === $last ? ' and ' : ', ').$amount.' '.($amount === 1 ? inflector::singular($name) : $name);
}
+ // If the difference is less than 60 seconds, remove the preceding and.
+ if (count($span) === 1)
+ {
+ $span[0] = ltrim($span[0], 'and ');
+ }
+
// Replace difference by making the span into a string
$difference = trim(implode('', $span), ',');
}
diff --git a/kohana/helpers/expires.php b/kohana/helpers/expires.php
index 454cf12a..8d8ef0f8 100644
--- a/kohana/helpers/expires.php
+++ b/kohana/helpers/expires.php
@@ -88,7 +88,8 @@ class expires_Core {
{
foreach (headers_list() as $header)
{
- if (stripos($header, 'Last-Modified:') === 0 OR stripos($header, 'Expires:') === 0)
+ if ((session_cache_limiter() == '' AND stripos($header, 'Last-Modified:') === 0)
+ OR stripos($header, 'Expires:') === 0)
{
return FALSE;
}
diff --git a/kohana/helpers/feed.php b/kohana/helpers/feed.php
index c1e0b81f..a84ec512 100644
--- a/kohana/helpers/feed.php
+++ b/kohana/helpers/feed.php
@@ -65,13 +65,15 @@ class feed_Core {
*
* @param array feed information
* @param array items to add to the feed
+ * @param string define which format to use
+ * @param string define which encoding to use
* @return string
*/
- public static function create($info, $items, $format = 'rss2')
+ public static function create($info, $items, $format = 'rss2', $encoding = 'UTF-8')
{
$info += array('title' => 'Generated Feed', 'link' => '', 'generator' => 'KohanaPHP');
- $feed = '<?xml version="1.0"?><rss version="2.0"><channel></channel></rss>';
+ $feed = '<?xml version="1.0" encoding="'.$encoding.'"?><rss version="2.0"><channel></channel></rss>';
$feed = simplexml_load_string($feed);
foreach ($info as $name => $value)
diff --git a/kohana/helpers/form.php b/kohana/helpers/form.php
index 0eaec0dc..70b98167 100644
--- a/kohana/helpers/form.php
+++ b/kohana/helpers/form.php
@@ -233,7 +233,7 @@ class form_Core {
*
* @param string|array input name or an array of HTML attributes
* @param array select options, when using a name
- * @param string option key that should be selected by default
+ * @param string|array option key(s) that should be selected by default
* @param string a string to be attached to the end of the attributes
* @return string
*/
diff --git a/kohana/helpers/request.php b/kohana/helpers/request.php
index 625f9226..091a9d68 100644
--- a/kohana/helpers/request.php
+++ b/kohana/helpers/request.php
@@ -33,7 +33,7 @@ class request_Core {
if (strpos($ref, url::base(FALSE)) === 0)
{
// Remove the base URL from the referrer
- $ref = substr($ref, strlen(url::base(TRUE)));
+ $ref = substr($ref, strlen(url::base(FALSE)));
}
}
diff --git a/kohana/helpers/valid.php b/kohana/helpers/valid.php
index 88cca584..25f90f68 100644
--- a/kohana/helpers/valid.php
+++ b/kohana/helpers/valid.php
@@ -277,7 +277,7 @@ class valid_Core {
{
// Use localeconv to set the decimal_point value: Usually a comma or period.
$locale = localeconv();
- return (preg_match('/^-?[0-9'.$locale['decimal_point'].']++$/D', (string) $str));
+ return (bool) preg_match('/^-?[0-9'.$locale['decimal_point'].']++$/D', (string) $str);
}
/**