diff options
Diffstat (limited to 'kohana/libraries')
-rw-r--r-- | kohana/libraries/Image.php | 62 | ||||
-rw-r--r-- | kohana/libraries/Input.php | 4 | ||||
-rw-r--r-- | kohana/libraries/ORM.php | 31 | ||||
-rw-r--r-- | kohana/libraries/View.php | 54 |
4 files changed, 91 insertions, 60 deletions
diff --git a/kohana/libraries/Image.php b/kohana/libraries/Image.php index 3db810e8..bd723a27 100644 --- a/kohana/libraries/Image.php +++ b/kohana/libraries/Image.php @@ -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. diff --git a/kohana/libraries/Input.php b/kohana/libraries/Input.php index c5289840..a0004621 100644 --- a/kohana/libraries/Input.php +++ b/kohana/libraries/Input.php @@ -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); } diff --git a/kohana/libraries/ORM.php b/kohana/libraries/ORM.php index 4a76701b..7fe126c9 100644 --- a/kohana/libraries/ORM.php +++ b/kohana/libraries/ORM.php @@ -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; diff --git a/kohana/libraries/View.php b/kohana/libraries/View.php index 067ace9c..7a49fd84 100644 --- a/kohana/libraries/View.php +++ b/kohana/libraries/View.php @@ -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. @@ -118,6 +129,43 @@ class View_Core { } /** + * 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. * * @param string name of variable @@ -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
\ No newline at end of file |