summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-03-30 18:09:17 +0000
committerBharat Mediratta <bharat@menalto.com>2009-03-30 18:09:17 +0000
commit9f04fef3e046d7b4778ddf449589c9b1a3a67857 (patch)
tree5b3d859bd977adb15fa396d9db914f9d1b82073f
parent066854424a683f14f70f54e3ef1879e77c409369 (diff)
Updated to r807
-rw-r--r--kohana/config/user_agents.php3
-rw-r--r--kohana/core/Bootstrap.php4
-rw-r--r--kohana/core/Kohana.php32
-rw-r--r--kohana/helpers/feed.php4
-rw-r--r--kohana/helpers/html.php16
-rw-r--r--kohana/helpers/valid.php2
-rw-r--r--kohana/libraries/Database.php79
-rw-r--r--kohana/libraries/Input.php21
-rw-r--r--kohana/libraries/ORM.php58
-rw-r--r--kohana/libraries/Validation.php10
-rw-r--r--kohana/libraries/drivers/Cache/Memcache.php65
-rw-r--r--kohana/libraries/drivers/Database/Mysqli.php6
-rw-r--r--kohana/libraries/drivers/Database/Pgsql.php9
13 files changed, 165 insertions, 144 deletions
diff --git a/kohana/config/user_agents.php b/kohana/config/user_agents.php
index 3432ba1b..c968aebe 100644
--- a/kohana/config/user_agents.php
+++ b/kohana/config/user_agents.php
@@ -64,6 +64,7 @@ $config['browser'] = array
'Camino' => 'Camino',
'Netscape' => 'Netscape',
'OmniWeb' => 'OmniWeb',
+ 'Chrome' => 'Chrome',
'Safari' => 'Safari',
'Konqueror' => 'Konqueror',
'Epiphany' => 'Epiphany',
@@ -93,6 +94,8 @@ $config['mobile'] = array
'ericsson' => 'Ericsson',
'blackBerry' => 'BlackBerry',
'motorola' => 'Motorola',
+ 'iphone' => 'iPhone',
+ 'android' => 'Android',
);
// There are hundreds of bots but these are the most common.
diff --git a/kohana/core/Bootstrap.php b/kohana/core/Bootstrap.php
index 0190eb9d..ad7564c8 100644
--- a/kohana/core/Bootstrap.php
+++ b/kohana/core/Bootstrap.php
@@ -10,8 +10,8 @@
* @license http://kohanaphp.com/license.html
*/
-define('KOHANA_VERSION', '2.3.2');
-define('KOHANA_CODENAME', 'accipiter');
+define('KOHANA_VERSION', '2.3.3');
+define('KOHANA_CODENAME', 'aegolius');
// Test of Kohana is running in Windows
define('KOHANA_IS_WIN', DIRECTORY_SEPARATOR === '\\');
diff --git a/kohana/core/Kohana.php b/kohana/core/Kohana.php
index 7f9b87da..0ee6f631 100644
--- a/kohana/core/Kohana.php
+++ b/kohana/core/Kohana.php
@@ -53,6 +53,7 @@ final class Kohana {
// Internal caches and write status
private static $internal_cache = array();
private static $write_cache;
+ private static $internal_cache_path;
/**
* Sets up the PHP environment. Adds error/exception handling, output
@@ -90,6 +91,12 @@ final class Kohana {
if (self::$cache_lifetime = self::config('core.internal_cache'))
{
+ // Set the directory to be used for the internal cache
+ if ( ! self::$internal_cache_path = self::config('core.internal_cache_path'))
+ {
+ self::$internal_cache_path = APPPATH.'cache/';
+ }
+
// Load cached configuration and language files
self::$internal_cache['configuration'] = self::cache('configuration', self::$cache_lifetime);
self::$internal_cache['language'] = self::cache('language', self::$cache_lifetime);
@@ -570,7 +577,7 @@ final class Kohana {
{
if ($lifetime > 0)
{
- $path = APPPATH.'cache/kohana_'.$name;
+ $path = self::$internal_cache_path.'kohana_'.$name;
if (is_file($path))
{
@@ -606,7 +613,7 @@ final class Kohana {
if ($lifetime < 1)
return FALSE;
- $path = APPPATH.'cache/kohana_'.$name;
+ $path = self::$internal_cache_path.'kohana_'.$name;
if ($data === NULL)
{
@@ -1139,18 +1146,21 @@ final class Kohana {
{
$items = (array) glob($path.'*');
- foreach ($items as $index => $item)
+ if ( ! empty($items))
{
- $files[] = $item = str_replace('\\', '/', $item);
-
- // Handle recursion
- if (is_dir($item) AND $recursive == TRUE)
+ foreach ($items as $index => $item)
{
- // Filename should only be the basename
- $item = pathinfo($item, PATHINFO_BASENAME);
+ $files[] = $item = str_replace('\\', '/', $item);
- // Append sub-directory search
- $files = array_merge($files, self::list_files($directory, TRUE, $path.$item));
+ // Handle recursion
+ if (is_dir($item) AND $recursive == TRUE)
+ {
+ // Filename should only be the basename
+ $item = pathinfo($item, PATHINFO_BASENAME);
+
+ // Append sub-directory search
+ $files = array_merge($files, self::list_files($directory, TRUE, $path.$item));
+ }
}
}
}
diff --git a/kohana/helpers/feed.php b/kohana/helpers/feed.php
index 53b1fd15..c1e0b81f 100644
--- a/kohana/helpers/feed.php
+++ b/kohana/helpers/feed.php
@@ -20,6 +20,10 @@ class feed_Core {
*/
public static function parse($feed, $limit = 0)
{
+ // Check if SimpleXML is installed
+ if( ! function_exists('simplexml_load_file'))
+ throw new Kohana_User_Exception('Feed Error', 'SimpleXML must be installed!');
+
// Make limit an integer
$limit = (int) $limit;
diff --git a/kohana/helpers/html.php b/kohana/helpers/html.php
index daf16a04..375baf38 100644
--- a/kohana/helpers/html.php
+++ b/kohana/helpers/html.php
@@ -50,6 +50,18 @@ class html_Core {
}
/**
+ * Perform a html::specialchars() with additional URL specific encoding.
+ *
+ * @param string string to convert
+ * @param boolean encode existing entities
+ * @return string
+ */
+ public static function specialurlencode($str, $double_encode = TRUE)
+ {
+ return str_replace(' ', '%20', html::specialchars($str, $double_encode));
+ }
+
+ /**
* Create HTML link anchors.
*
* @param string URL or URI string
@@ -80,7 +92,7 @@ class html_Core {
return
// Parsed URL
- '<a href="'.html::specialchars($site_url, FALSE).'"'
+ '<a href="'.html::specialurlencode($site_url, FALSE).'"'
// Attributes empty? Use an empty string
.(is_array($attributes) ? html::attributes($attributes) : '').'>'
// Title empty? Use the parsed URL
@@ -100,7 +112,7 @@ class html_Core {
{
return
// Base URL + URI = full URL
- '<a href="'.html::specialchars(url::base(FALSE, $protocol).$file, FALSE).'"'
+ '<a href="'.html::specialurlencode(url::base(FALSE, $protocol).$file, FALSE).'"'
// Attributes empty? Use an empty string
.(is_array($attributes) ? html::attributes($attributes) : '').'>'
// Title empty? Use the filename part of the URI
diff --git a/kohana/helpers/valid.php b/kohana/helpers/valid.php
index 916a0c19..88cca584 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 (preg_match('/^-?[0-9'.$locale['decimal_point'].']++$/D', (string) $str));
}
/**
diff --git a/kohana/libraries/Database.php b/kohana/libraries/Database.php
index c98faffb..49241675 100644
--- a/kohana/libraries/Database.php
+++ b/kohana/libraries/Database.php
@@ -462,7 +462,18 @@ class Database_Core {
public function where($key, $value = NULL, $quote = TRUE)
{
$quote = (func_num_args() < 2 AND ! is_array($key)) ? -1 : $quote;
- $keys = is_array($key) ? $key : array($key => $value);
+ if (is_object($key))
+ {
+ $keys = array((string) $key => '');
+ }
+ elseif ( ! is_array($key))
+ {
+ $keys = array($key => $value);
+ }
+ else
+ {
+ $keys = $key;
+ }
foreach ($keys as $key => $value)
{
@@ -484,7 +495,18 @@ class Database_Core {
public function orwhere($key, $value = NULL, $quote = TRUE)
{
$quote = (func_num_args() < 2 AND ! is_array($key)) ? -1 : $quote;
- $keys = is_array($key) ? $key : array($key => $value);
+ if (is_object($key))
+ {
+ $keys = array((string) $key => '');
+ }
+ elseif ( ! is_array($key))
+ {
+ $keys = array($key => $value);
+ }
+ else
+ {
+ $keys = $key;
+ }
foreach ($keys as $key => $value)
{
@@ -1172,11 +1194,15 @@ class Database_Core {
* See if a table exists in the database.
*
* @param string table name
+ * @param boolean True to attach table prefix
* @return boolean
*/
- public function table_exists($table_name)
+ public function table_exists($table_name, $prefix = TRUE)
{
- return in_array($this->config['table_prefix'].$table_name, $this->list_tables());
+ if ($prefix)
+ return in_array($this->config['table_prefix'].$table_name, $this->list_tables());
+ else
+ return in_array($table_name, $this->list_tables());
}
/**
@@ -1313,17 +1339,6 @@ class Database_Core {
}
/**
- * Create a prepared statement (experimental).
- *
- * @param string SQL query
- * @return object
- */
- public function stmt_prepare($sql)
- {
- return $this->driver->stmt_prepare($sql, $this->config);
- }
-
- /**
* Pushes existing query space onto the query stack. Use push
* and pop to prevent queries from clashing before they are
* executed
@@ -1381,6 +1396,40 @@ class Database_Core {
return $this;
}
+ /**
+ * Count the number of records in the last query, without LIMIT or OFFSET applied.
+ *
+ * @return integer
+ */
+ public function count_last_query()
+ {
+ if ($sql = $this->last_query())
+ {
+ if (stripos($sql, 'LIMIT') !== FALSE)
+ {
+ // Remove LIMIT from the SQL
+ $sql = preg_replace('/\sLIMIT\s+[^a-z]+/i', ' ', $sql);
+ }
+
+ if (stripos($sql, 'OFFSET') !== FALSE)
+ {
+ // Remove OFFSET from the SQL
+ $sql = preg_replace('/\sOFFSET\s+\d+/i', '', $sql);
+ }
+
+ // Get the total rows from the last query executed
+ $result = $this->query
+ (
+ 'SELECT COUNT(*) AS '.$this->escape_column('total_rows').' '.
+ 'FROM ('.trim($sql).') AS '.$this->escape_table('counted_results')
+ );
+
+ // Return the total number of rows from the query
+ return (int) $result->current()->total_rows;
+ }
+
+ return FALSE;
+ }
} // End Database Class
diff --git a/kohana/libraries/Input.php b/kohana/libraries/Input.php
index 04e8ee4d..4549bf4a 100644
--- a/kohana/libraries/Input.php
+++ b/kohana/libraries/Input.php
@@ -237,17 +237,18 @@ class Input_Core {
if ($this->ip_address !== NULL)
return $this->ip_address;
- if ($ip = $this->server('HTTP_CLIENT_IP'))
- {
- $this->ip_address = $ip;
- }
- elseif ($ip = $this->server('REMOTE_ADDR'))
- {
- $this->ip_address = $ip;
- }
- elseif ($ip = $this->server('HTTP_X_FORWARDED_FOR'))
+ // Server keys that could contain the client IP address
+ $keys = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'REMOTE_ADDR');
+
+ foreach ($keys as $key)
{
- $this->ip_address = $ip;
+ if ($ip = $this->server($key))
+ {
+ $this->ip_address = $ip;
+
+ // An IP address has been found
+ break;
+ }
}
if ($comma = strrpos($this->ip_address, ',') !== FALSE)
diff --git a/kohana/libraries/ORM.php b/kohana/libraries/ORM.php
index aa176089..4cbec50a 100644
--- a/kohana/libraries/ORM.php
+++ b/kohana/libraries/ORM.php
@@ -220,8 +220,16 @@ class ORM_Core {
switch ($num_args)
{
case 0:
- // Support for things like reset_select, reset_write, list_tables
- return $this->db->$method();
+ if (in_array($method, array('open_paren', 'close_paren', 'enable_cache', 'disable_cache')))
+ {
+ // Should return ORM, not Database
+ $this->db->$method();
+ }
+ else
+ {
+ // Support for things like reset_select, reset_write, list_tables
+ return $this->db->$method();
+ }
break;
case 1:
$this->db->$method($args[0]);
@@ -1011,41 +1019,6 @@ class ORM_Core {
}
/**
- * Count the number of records in the last query, without LIMIT or OFFSET applied.
- *
- * @return integer
- */
- public function count_last_query()
- {
- if ($sql = $this->db->last_query())
- {
- if (stripos($sql, 'LIMIT') !== FALSE)
- {
- // Remove LIMIT from the SQL
- $sql = preg_replace('/\sLIMIT\s+[^a-z]+/i', ' ', $sql);
- }
-
- if (stripos($sql, 'OFFSET') !== FALSE)
- {
- // Remove OFFSET from the SQL
- $sql = preg_replace('/\sOFFSET\s+\d+/i', '', $sql);
- }
-
- // Get the total rows from the last query executed
- $result = $this->db->query
- (
- 'SELECT COUNT(*) AS '.$this->db->escape_column('total_rows').' '.
- 'FROM ('.trim($sql).') AS '.$this->db->escape_table('counted_results')
- );
-
- // Return the total number of rows from the query
- return (int) $result->current()->total_rows;
- }
-
- return FALSE;
- }
-
- /**
* Proxy method to Database list_fields.
*
* @param string table name
@@ -1070,17 +1043,6 @@ class ORM_Core {
}
/**
- * Proxy method to Database last_query.
- *
- * @return string
- */
- public function last_query()
- {
- // Proxy to database
- return $this->db->last_query();
- }
-
- /**
* Proxy method to Database field_data.
*
* @chainable
diff --git a/kohana/libraries/Validation.php b/kohana/libraries/Validation.php
index 473425db..e2c8ff17 100644
--- a/kohana/libraries/Validation.php
+++ b/kohana/libraries/Validation.php
@@ -108,12 +108,12 @@ class Validation_Core extends ArrayObject {
public function field_names()
{
// All the fields that are being validated
- $fields = array_unique(array_merge
+ $fields = array_keys(array_merge
(
- array_keys($this->pre_filters),
- array_keys($this->rules),
- array_keys($this->callbacks),
- array_keys($this->post_filters)
+ $this->pre_filters,
+ $this->rules,
+ $this->callbacks,
+ $this->post_filters
));
// Remove wildcard fields
diff --git a/kohana/libraries/drivers/Cache/Memcache.php b/kohana/libraries/drivers/Cache/Memcache.php
index f443b997..acd4c850 100644
--- a/kohana/libraries/drivers/Cache/Memcache.php
+++ b/kohana/libraries/drivers/Cache/Memcache.php
@@ -17,14 +17,11 @@ class Cache_Memcache_Driver implements Cache_Driver {
protected $backend;
protected $flags;
- // The persistent lifetime value for expirations of 0
- protected $persistent_lifetime;
-
// Tags array
- protected $tags;
+ protected static $tags;
// Have the tags been changed?
- protected $tags_changed = FALSE;
+ protected static $tags_changed = FALSE;
public function __construct()
{
@@ -46,34 +43,34 @@ class Cache_Memcache_Driver implements Cache_Driver {
or Kohana::log('error', 'Cache: Connection failed: '.$server['host']);
}
- // Set "persistent lifetime" value to one year
- $this->persistent_lifetime = strtotime('now +1 year');
-
// Load tags
- $this->tags = $this->backend->get(self::TAGS_KEY);
+ self::$tags = $this->backend->get(self::TAGS_KEY);
- if ( ! is_array($this->tags))
+ if ( ! is_array(self::$tags))
{
// Create a new tags array
- $this->tags = array();
+ self::$tags = array();
// Tags have been created
- $this->tags_changed = TRUE;
+ self::$tags_changed = TRUE;
}
}
public function __destruct()
{
- if ($this->tags_changed === TRUE)
+ if (self::$tags_changed === TRUE)
{
// Save the tags
- $this->backend->set(self::TAGS_KEY, $this->tags, $this->flags, $this->persistent_lifetime);
+ $this->backend->set(self::TAGS_KEY, self::$tags, $this->flags, 0);
+
+ // Tags are now unchanged
+ self::$tags_changed = FALSE;
}
}
public function find($tag)
{
- if (isset($this->tags[$tag]) AND $results = $this->backend->get($this->tags[$tag]))
+ if (isset(self::$tags[$tag]) AND $results = $this->backend->get(self::$tags[$tag]))
{
// Return all the found caches
return $results;
@@ -95,22 +92,16 @@ class Cache_Memcache_Driver implements Cache_Driver {
if ( ! empty($tags))
{
// Tags will be changed
- $this->tags_changed = TRUE;
+ self::$tags_changed = TRUE;
foreach ($tags as $tag)
{
// Add the id to each tag
- $this->tags[$tag][$id] = $id;
+ self::$tags[$tag][$id] = $id;
}
}
- if ($lifetime === 0)
- {
- // Using an expiration of zero is unreliable, as memcache may delete
- // it without warning. @see http://php.net/memcache_set
- $lifetime = $this->persistent_lifetime;
- }
- else
+ if ($lifetime !== 0)
{
// Memcache driver expects unix timestamp
$lifetime += time();
@@ -123,14 +114,14 @@ class Cache_Memcache_Driver implements Cache_Driver {
public function delete($id, $tag = FALSE)
{
// Tags will be changed
- $this->tags_changed = TRUE;
+ self::$tags_changed = TRUE;
if ($id === TRUE)
{
if ($status = $this->backend->flush())
{
// Remove all tags, all items have been deleted
- $this->tags = array();
+ self::$tags = array();
// We must sleep after flushing, or overwriting will not work!
// @see http://php.net/manual/en/function.memcache-flush.php#81420
@@ -141,28 +132,28 @@ class Cache_Memcache_Driver implements Cache_Driver {
}
elseif ($tag === TRUE)
{
- if (isset($this->tags[$id]))
+ if (isset(self::$tags[$id]))
{
- foreach ($this->tags[$id] as $_id)
+ foreach (self::$tags[$id] as $_id)
{
// Delete each id in the tag
$this->backend->delete($_id);
}
// Delete the tag
- unset($this->tags[$id]);
+ unset(self::$tags[$id]);
}
return TRUE;
}
else
{
- foreach ($this->tags as $tag => $_ids)
+ foreach (self::$tags as $tag => $_ids)
{
- if (isset($this->tags[$tag][$id]))
+ if (isset(self::$tags[$tag][$id]))
{
// Remove the id from the tags
- unset($this->tags[$tag][$id]);
+ unset(self::$tags[$tag][$id]);
}
}
@@ -173,23 +164,23 @@ class Cache_Memcache_Driver implements Cache_Driver {
public function delete_expired()
{
// Tags will be changed
- $this->tags_changed = TRUE;
+ self::$tags_changed = TRUE;
- foreach ($this->tags as $tag => $_ids)
+ foreach (self::$tags as $tag => $_ids)
{
foreach ($_ids as $id)
{
if ( ! $this->backend->get($id))
{
// This id has disappeared, delete it from the tags
- unset($this->tags[$tag][$id]);
+ unset(self::$tags[$tag][$id]);
}
}
- if (empty($this->tags[$tag]))
+ if (empty(self::$tags[$tag]))
{
// The tag no longer has any valid ids
- unset($this->tags[$tag]);
+ unset(self::$tags[$tag]);
}
}
diff --git a/kohana/libraries/drivers/Database/Mysqli.php b/kohana/libraries/drivers/Database/Mysqli.php
index 3d6bbfbf..13a81281 100644
--- a/kohana/libraries/drivers/Database/Mysqli.php
+++ b/kohana/libraries/drivers/Database/Mysqli.php
@@ -96,12 +96,6 @@ class Database_Mysqli_Driver extends Database_Mysql_Driver {
throw new Kohana_Database_Exception('database.error', $this->show_error());
}
- public function stmt_prepare($sql = '')
- {
- is_object($this->link) or $this->connect();
- return new Kohana_Mysqli_Statement($sql, $this->link);
- }
-
public function escape_str($str)
{
if (!$this->db_config['escape'])
diff --git a/kohana/libraries/drivers/Database/Pgsql.php b/kohana/libraries/drivers/Database/Pgsql.php
index 9758de3c..62a33ad6 100644
--- a/kohana/libraries/drivers/Database/Pgsql.php
+++ b/kohana/libraries/drivers/Database/Pgsql.php
@@ -82,7 +82,8 @@ class Database_Pgsql_Driver extends Database_Driver {
return self::$query_cache[$hash];
}
- return new Pgsql_Result(pg_query($this->link, $sql), $this->link, $this->db_config['object'], $sql);
+ // Suppress warning triggered when a database error occurs (e.g., a constraint violation)
+ return new Pgsql_Result(@pg_query($this->link, $sql), $this->link, $this->db_config['object'], $sql);
}
public function set_charset($charset)
@@ -161,12 +162,6 @@ class Database_Pgsql_Driver extends Database_Driver {
return 'LIMIT '.$limit.' OFFSET '.$offset;
}
- public function stmt_prepare($sql = '')
- {
- is_object($this->link) or $this->connect();
- return new Kohana_Mysqli_Statement($sql, $this->link);
- }
-
public function compile_select($database)
{
$sql = ($database['distinct'] == TRUE) ? 'SELECT DISTINCT ' : 'SELECT ';