Update modified to Kohana r3823 (svn merge -c19322 vendor/kohana/modified/kohana trunk/kohana)

This commit is contained in:
Bharat Mediratta
2008-12-20 07:38:46 +00:00
parent ad0ddc236c
commit 64f993db6f
8 changed files with 130 additions and 94 deletions

View File

@@ -10,8 +10,8 @@
* @license http://kohanaphp.com/license.html
*/
define('KOHANA_VERSION', '2.2');
define('KOHANA_CODENAME', 'efímera');
define('KOHANA_VERSION', '2.3');
define('KOHANA_CODENAME', 'accipiter');
// Test of Kohana is running in Windows
define('KOHANA_IS_WIN', DIRECTORY_SEPARATOR === '\\');

View File

@@ -975,37 +975,39 @@ final class Kohana {
$file = $class;
}
if (($filepath = self::find_file($type, $file)) === FALSE)
return FALSE;
// Load the file
require $filepath;
if ($type === 'libraries' OR $type === 'helpers')
if ($filename = self::find_file($type, $file))
{
if ($extension = self::find_file($type, self::$configuration['core']['extension_prefix'].$class))
// Load the class
require $filename;
}
else
{
// The class could not be found
return FALSE;
}
if ($filename = self::find_file($type, self::$configuration['core']['extension_prefix'].$class))
{
// Load the class extension
require $filename;
}
elseif ($suffix !== 'Core' AND class_exists($class.'_Core', FALSE))
{
// Class extension to be evaluated
$extension = 'class '.$class.' extends '.$class.'_Core { }';
// Start class analysis
$core = new ReflectionClass($class.'_Core');
if ($core->isAbstract())
{
// Load the extension
require $extension;
// Make the extension abstract
$extension = 'abstract '.$extension;
}
elseif ($suffix !== 'Core' AND class_exists($class.'_Core', FALSE))
{
// Class extension to be evaluated
$extension = 'class '.$class.' extends '.$class.'_Core { }';
// Start class analysis
$core = new ReflectionClass($class.'_Core');
if ($core->isAbstract())
{
// Make the extension abstract
$extension = 'abstract '.$extension;
}
// Transparent class extensions are handled using eval. This is
// a disgusting hack, but it gets the job done.
eval($extension);
}
// Transparent class extensions are handled using eval. This is
// a disgusting hack, but it gets the job done.
eval($extension);
}
return TRUE;

View File

@@ -144,9 +144,10 @@ 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 = '')
public static function input($data, $value = '', $extra = '', $double_encode = TRUE )
{
if ( ! is_array($data))
{
@@ -161,7 +162,7 @@ class form_Core {
);
// For safe form data
$data['value'] = html::specialchars($data['value']);
$data['value'] = html::specialchars($data['value'], $double_encode);
return '<input'.form::attributes($data).' '.$extra.' />';
}
@@ -212,9 +213,10 @@ 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 textarea($data, $value = '', $extra = '')
public static function textarea($data, $value = '', $extra = '', $double_encode = TRUE )
{
if ( ! is_array($data))
{
@@ -227,7 +229,7 @@ class form_Core {
// Value is not part of the attributes
unset($data['value']);
return '<textarea'.form::attributes($data, 'textarea').' '.$extra.'>'.html::specialchars($value).'</textarea>';
return '<textarea'.form::attributes($data, 'textarea').' '.$extra.'>'.html::specialchars($value, $double_encode).'</textarea>';
}
/**

View File

@@ -85,9 +85,10 @@ class valid_Core {
*
* @param string IP address
* @param boolean allow IPv6 addresses
* @param boolean allow private IP networks
* @return boolean
*/
public static function ip($ip, $ipv6 = FALSE, $allow_private = FALSE)
public static function ip($ip, $ipv6 = FALSE, $allow_private = TRUE)
{
// By default do not allow private and reserved range IPs
$flags = FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE;

View File

@@ -303,9 +303,10 @@ class Image_Core {
* @throws Kohana_Exception
* @param string new image filename
* @param integer permissions for new image
* @param boolean keep or discard image process actions
* @return object
*/
public function save($new_image = FALSE, $chmod = 0644)
public function save($new_image = FALSE, $chmod = 0644, $keep_actions = FALSE)
{
// If no new image is defined, use the current image
empty($new_image) and $new_image = $this->image['file'];
@@ -328,37 +329,40 @@ class Image_Core {
chmod($new_image, $chmod);
}
}
// Reset the actions
$this->actions = array();
// Reset actions. Subsequent save() or render() will not apply previous actions.
if ($keep_actions === FALSE)
$this->actions = array();
return $status;
}
/**
* Output the image to the browser.
*
* @return object
*/
public function render()
{
$new_image = $this->image['file'];
// Separate the directory and filename
$dir = pathinfo($new_image, PATHINFO_DIRNAME);
$file = pathinfo($new_image, PATHINFO_BASENAME);
// Normalize the path
$dir = str_replace('\\', '/', realpath($dir)).'/';
// Process the image with the driver
$status = $this->driver->process($this->image, $this->actions, $dir, $file, $render = TRUE);
// Reset the actions
$this->actions = array();
return $status;
}
/**
* Output the image to the browser.
*
* @param boolean keep or discard image process actions
* @return object
*/
public function render($keep_actions = FALSE)
{
$new_image = $this->image['file'];
// Separate the directory and filename
$dir = pathinfo($new_image, PATHINFO_DIRNAME);
$file = pathinfo($new_image, PATHINFO_BASENAME);
// Normalize the path
$dir = str_replace('\\', '/', realpath($dir)).'/';
// Process the image with the driver
$status = $this->driver->process($this->image, $this->actions, $dir, $file, $render = TRUE);
// Reset actions. Subsequent save() or render() will not apply previous actions.
if ($keep_actions === FALSE)
$this->actions = array();
return $status;
}
/**
* Sanitize a given value type.

View File

@@ -130,9 +130,9 @@ class Input_Core {
foreach ($_COOKIE as $key => $val)
{
// Ignore special attributes in RFC2109 compliant cookies
if ($key == '$Version' || $key == '$Path' || $key == '$Domain') {
if ($key == '$Version' OR $key == '$Path' OR $key == '$Domain')
continue;
}
// Sanitize $_COOKIE
$_COOKIE[$this->clean_input_keys($key)] = $this->clean_input_data($val);
}

View File

@@ -32,7 +32,7 @@ class ORM_Core {
protected $related = array();
protected $loaded = FALSE;
protected $saved = FALSE;
protected $sorting = array('id' => 'asc');
protected $sorting;
// Related objects
protected $object_relations = array();
@@ -91,6 +91,12 @@ class ORM_Core {
$this->object_name = strtolower(substr(get_class($this), 0, -6));
$this->object_plural = inflector::plural($this->object_name);
if (!isset($this->sorting))
{
// Default sorting
$this->sorting = array($this->primary_key => 'asc');
}
// Initialize database
$this->__initialize();
@@ -1181,29 +1187,6 @@ class ORM_Core {
return $table;
}
/**
* Outputs ORM iterator joined with given model
* @param $related_model ORM Model the model related to this ORM
* @return ORM iterator
* @author credits to Josh Domagala
*/
public function join_model($related_model)
{
if( !in_array( $related_model->table_name, $this->has_and_belongs_to_many ) )
{
return FALSE;
}
// Get the join table name
$join_table = $this->join_table($related_model->table_name);
// Return ORM iterator of model
return $this
->join($join_table, $this->foreign_key(NULL, $join_table), $this->foreign_key(TRUE))
->where($related_model->foreign_key(NULL, $join_table), $related_model->id)
->find_all();
}
/**
* Returns an ORM model for the given object name;

View File

@@ -56,6 +56,17 @@ class View_Core {
$this->kohana_local_data = array_merge($this->kohana_local_data, $data);
}
}
/**
* Magic method access to test for view property
*
* @param string View property to test for
* @return boolean
*/
public function __isset($key = NULL)
{
return $this->is_set($key);
}
/**
* Sets the view filename.
@@ -117,6 +128,43 @@ class View_Core {
return $this;
}
/**
* Checks for a property existence in the view locally or globally. Unlike the built in __isset(),
* this method can take an array of properties to test simultaneously.
*
* @param string $key property name to test for
* @param array $key array of property names to test for
* @return boolean property test result
* @return array associative array of keys and boolean test result
*/
public function is_set( $key = FALSE )
{
// Setup result;
$result = FALSE;
// If key is an array
if (is_array($key))
{
// Set the result to an array
$result = array();
// Foreach key
foreach ($key as $property)
{
// Set the result to an associative array
$result[$property] = (array_key_exists($property, $this->kohana_local_data) OR array_key_exists($property, self::$kohana_global_data)) ? TRUE : FALSE;
}
}
else
{
// Otherwise just check one property
$result = (array_key_exists($key, $this->kohana_local_data) OR array_key_exists($key, self::$kohana_global_data)) ? TRUE : FALSE;
}
// Return the result
return $result;
}
/**
* Sets a bound variable by reference.
*
@@ -164,10 +212,7 @@ class View_Core {
*/
public function __set($key, $value)
{
if ( ! isset($this->$key))
{
$this->kohana_local_data[$key] = $value;
}
$this->kohana_local_data[$key] = $value;
}
/**
@@ -255,5 +300,4 @@ class View_Core {
return $output;
}
} // End View