diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 4da99d78c..6be64055e 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -39,7 +39,7 @@ uses('error_messages', 'object', 'router', DS.'controller'.DS.'controller', DS.' /** * Dispatcher translates URLs to controller-action-paramter triads. - * + * * Dispatches the request, creating appropriate models and controllers. * * @package cake @@ -53,13 +53,19 @@ class Dispatcher extends Object * @var string */ var $base = false; - + /** * Base URL * @var string */ var $admin = false; +/** + * Base URL + * @var string + */ + var $webservices = null; + /** * Constructor. */ @@ -71,8 +77,8 @@ class Dispatcher extends Object /** * Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the results (if autoRender is set). * - * If no controller of given name can be found, invoke() shows error messages in - * the form of Missing Controllers information. It does the same with Actions (methods of Controllers are called + * If no controller of given name can be found, invoke() shows error messages in + * the form of Missing Controllers information. It does the same with Actions (methods of Controllers are called * Actions). * * @param string $url URL information to work on. @@ -85,7 +91,7 @@ class Dispatcher extends Object $missingAction = false; $missingView = false; $privateAction = false; - + if(defined('CAKE_ADMIN')) { if(isset($params[CAKE_ADMIN])) @@ -102,14 +108,14 @@ class Dispatcher extends Object } } } - + $this->base = $this->baseUrl(); - + if(!in_array('render', array_keys($params))) { $params['render'] = 0; } - + if (empty($params['controller'])) { $missingController = true; @@ -146,32 +152,30 @@ class Dispatcher extends Object $params['controller'] = Inflector::camelize($params['controller']."Controller"); } $controller->missingController = $params['controller']; - $controller->webroot = $this->webroot; - return $this->_invoke($controller, $params ); } else { $controller =& new $ctrlClass($this); } - + $classMethods = get_class_methods($controller); $classVars = get_object_vars($controller); - + if (empty($params['action'])) { $params['action'] = 'index'; } - + if(in_array($params['action'], $classMethods) && strpos($params['action'], '_', 0) === 0) { $privateAction = true; } - + if(!in_array($params['action'], $classMethods)) { $missingAction = true; } - + $controller->base = $this->base; $controller->here = $this->base.'/'.$url; $controller->webroot = $this->webroot; @@ -181,10 +185,12 @@ class Dispatcher extends Object $controller->passed_args = empty($params['pass'])? null: $params['pass']; $controller->autoLayout = !$params['bare']; $controller->autoRender = !$params['render']; + $controller->webservices = $params['webservices']; - if(!defined('AUTO_SESSION') || AUTO_SESSION == true) + if(!is_null($controller->webservices)) { - array_push($controller->components, 'Session'); + array_push($controller->components, $controller->webservices); + array_push($controller->helpers, $controller->webservices); } if((in_array('scaffold', array_keys($classVars))) && ($missingAction === true)) @@ -194,22 +200,22 @@ class Dispatcher extends Object } $controller->constructClasses(); - + if ($missingAction) { $controller->missingAction = $params['action']; $params['action'] = 'missingAction'; } - + if ($privateAction) { $controller->privateAction = $params['action']; $params['action'] = 'privateAction'; } - + return $this->_invoke($controller, $params ); } - + /** * Invokes given controller's render action if autoRender option is set. Otherwise the contents of the operation are returned as a string. * @@ -240,7 +246,7 @@ class Dispatcher extends Object $Route = new Router(); include CONFIGS.'routes.php'; $params = $Route->parse ($from_url); - + // add submitted form data $params['form'] = $_POST; if (isset($_POST['data'])) @@ -254,13 +260,17 @@ class Dispatcher extends Object $params['url'] = (ini_get('magic_quotes_gpc') == 1)? $this->stripslashes_deep($params['url']) : $params['url']; } - + foreach ($_FILES as $name => $data) { $params['form'][$name] = $data; } $params['bare'] = empty($params['ajax'])? (empty($params['bare'])? 0: 1): 1; + if(defined('WEBSERVICES')) + { + $params['webservices'] = empty($params['webservices']) ? null : $params['webservices']; + } return $params; } @@ -270,7 +280,7 @@ class Dispatcher extends Object */ function stripslashes_deep($val) { - return (is_array($val)) ? + return (is_array($val)) ? array_map(array('Dispatcher','stripslashes_deep'), $val) : stripslashes($val); } @@ -280,7 +290,7 @@ class Dispatcher extends Object */ function urldecode_deep($val) { - return (is_array($val)) ? + return (is_array($val)) ? array_map(array('Dispatcher','urldecode_deep'), $val) : urldecode($val); } @@ -298,10 +308,10 @@ class Dispatcher extends Object { $base = BASE_URL.$this->admin; } - + $docRoot = $_SERVER['DOCUMENT_ROOT']; $scriptName = $_SERVER['PHP_SELF']; - + // If document root ends with 'webroot', it's probably correctly set $r = null; if (preg_match('/'.APP_DIR.'\\'.DS.WEBROOT_DIR.'/', $docRoot)) @@ -351,7 +361,7 @@ class Dispatcher extends Object } return $base; } - + /** * Displays an error page (e.g. 404 Not found). * diff --git a/cake/libs/controller/components/acl.php b/cake/libs/controller/components/acl.php index c9ac4fc24..fb65ef352 100644 --- a/cake/libs/controller/components/acl.php +++ b/cake/libs/controller/components/acl.php @@ -41,22 +41,26 @@ * @since CakePHP v 0.10.0.1076 * */ -class AclComponent +class AclComponent extends Object { var $_instance = null; var $controller = true; +/** + * Enter description here... + * + */ function __construct() { $this->getACL(); } - /** - * Static function used to gain an instance of the correct ACL class. - * - * @return MyACL - */ +/** + * Static function used to gain an instance of the correct ACL class. + * + * @return MyACL + */ function &getACL() { if($this->_instance == null) @@ -68,89 +72,93 @@ class AclComponent return $this->_instance; } +/** + * Enter description here... + * + */ function _initACL() { } - /** - * Pass-thru function for ACL check instance. - * - * @return boolean - */ +/** + * Pass-thru function for ACL check instance. + * + * @return boolean + */ function check($aro, $aco, $action = "*") { return $this->_instance->check($aro, $aco, $action); } - /** - * Pass-thru function for ACL allow instance. - * - * @return boolean - */ +/** + * Pass-thru function for ACL allow instance. + * + * @return boolean + */ function allow($aro, $aco, $action = "*") { return $this->_instance->allow($aro, $aco, $action); } - /** - * Pass-thru function for ACL deny instance. - * - * @return boolean - */ +/** + * Pass-thru function for ACL deny instance. + * + * @return boolean + */ function deny($aro, $aco, $action = "*") { return $this->_instance->deny($aro, $aco, $action); } - /** - * Pass-thru function for ACL inherit instance. - * - * @return boolean - */ +/** + * Pass-thru function for ACL inherit instance. + * + * @return boolean + */ function inherit($aro, $aco, $action = "*") { return $this->_instance->inherit($aro, $aco, $action); } - /** - * Pass-thru function for ACL grant instance. - * - * @return boolean - */ +/** + * Pass-thru function for ACL grant instance. + * + * @return boolean + */ function grant($aro, $aco, $action = "*") { return $this->_instance->grant($aro, $aco, $action); } - /** - * Pass-thru function for ACL grant instance. - * - * @return boolean - */ +/** + * Pass-thru function for ACL grant instance. + * + * @return boolean + */ function revoke($aro, $aco, $action = "*") { return $this->_instance->revoke($aro, $aco, $action); } - /** - * Pass-thru function for ACL getAro instance. - * - * @return Aro - */ +/** + * Pass-thru function for ACL getAro instance. + * + * @return Aro + */ function getAro($id) { return $this->_instance->getAro($id); } - /** - * Pass-thru function for ACL getAco instance. - * - * @return Aco - */ +/** + * Pass-thru function for ACL getAco instance. + * + * @return Aco + */ function getAco($id) { return $this->_instance->getAco($id); diff --git a/cake/libs/controller/components/acl_base.php b/cake/libs/controller/components/acl_base.php index cce2ccee6..16582c667 100644 --- a/cake/libs/controller/components/acl_base.php +++ b/cake/libs/controller/components/acl_base.php @@ -1,35 +1,40 @@ + // -// + Copyright: (c) 2005, CakePHP Authors/Developers + // -// + Author(s): Michal Tatarynowicz aka Pies + // -// + Larry E. Masters aka PhpNut + // -// + Kamil Dzielinski aka Brego + // -// +------------------------------------------------------------------+ // -// + Licensed under The MIT License + // -// + Redistributions of files must retain the above copyright notice. + // -// + See: http://www.opensource.org/licenses/mit-license.php + // -////////////////////////////////////////////////////////////////////////// +/* SVN FILE: $Id$ */ /** * Access Control List abstract class. * - * @filesource - * @author CakePHP Authors/Developers - * @copyright Copyright (c) 2005, CakePHP Authors/Developers - * @link https://trac.cakephp.org/wiki/Authors Authors/Developers - * @package cake - * @subpackage cake.cake.libs.controller.components - * @since CakePHP v 0.10.0.1076 - * @version $Revision$ - * @modifiedby $LastChangedBy$ - * @lastmodified $Date$ - * @license http://www.opensource.org/licenses/mit-license.php The MIT License + * Long description for file * + * PHP versions 4 and 5 + * + * CakePHP : Rapid Development Framework + * Copyright (c) 2005, CakePHP Authors/Developers + * + * Author(s): Larry E. Masters aka PhpNut + * Kamil Dzielinski aka Brego + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @author CakePHP Authors/Developers + * @copyright Copyright (c) 2005, CakePHP Authors/Developers + * @link https://trac.cakephp.org/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.cake.libs.controller.components + * @since CakePHP v 0.10.0.1232 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ +/** + * Enter description here... + * + * @return AclBase + */ uses('error_messages'); /** @@ -44,6 +49,11 @@ uses('error_messages'); class AclBase { +/** + * Enter description here... + * + * @return AclBase + */ function AclBase() { //No instantiations or constructor calls (even statically) @@ -55,6 +65,13 @@ class AclBase } +/** + * Enter description here... + * + * @param unknown_type $aro + * @param unknown_type $aco + * @param unknown_type $action + */ function check($aro, $aco, $action = "*") {} } diff --git a/cake/libs/controller/components/dbacl/db_acl.php b/cake/libs/controller/components/dbacl/db_acl.php index 673448be0..92953a969 100644 --- a/cake/libs/controller/components/dbacl/db_acl.php +++ b/cake/libs/controller/components/dbacl/db_acl.php @@ -11,8 +11,7 @@ * CakePHP : Rapid Development Framework * Copyright (c) 2005, CakePHP Authors/Developers * - * Author(s): Michal Tatarynowicz aka Pies - * Larry E. Masters aka PhpNut + * Author(s): Larry E. Masters aka PhpNut * Kamil Dzielinski aka Brego * * Licensed under The MIT License @@ -23,7 +22,7 @@ * @copyright Copyright (c) 2005, CakePHP Authors/Developers * @link https://trac.cakephp.org/wiki/Authors Authors/Developers * @package cake - * @subpackage cake.cake.app.controllers.componenets + * @subpackage cake.cake.app.controllers.componenets.dbacl * @since CakePHP v 0.2.9 * @version $Revision$ * @modifiedby $LastChangedBy$ @@ -31,6 +30,7 @@ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ +uses('inflector'); uses('controller'.DS.'components'.DS.'acl_base'); uses('controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aclnode'); uses('controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aco'); @@ -42,17 +42,29 @@ uses('controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aros_aco'); * In this file you can extend the AclBase. * * @package cake - * @subpackage cake.cake.app.controllers.components + * @subpackage cake.cake.app.controllers.components.dbacl */ class DB_ACL extends AclBase { +/** + * Enter description here... + * + */ function __construct() { } +/** + * Enter description here... + * + * @param unknown_type $aro + * @param unknown_type $aco + * @param unknown_type $action + * @return unknown + */ function check($aro, $aco, $action = "*") { @@ -97,9 +109,12 @@ class DB_ACL extends AclBase // ARO must be cleared for ALL ACO actions foreach($permKeys as $key) { - if($perm['aros_acos'][$key] != 1) + if(isset($perm['aros_acos'])) { - return false; + if($perm['aros_acos'][$key] != 1) + { + return false; + } } } return true; @@ -124,11 +139,11 @@ class DB_ACL extends AclBase return false; } - /** - * Allow - * - * @return boolean - */ +/** + * Allow + * + * @return boolean + */ function allow($aro, $aco, $action = "*", $value = 1) { $Perms = new ArosAco(); @@ -192,41 +207,41 @@ class DB_ACL extends AclBase return true; } - /** - * Deny - * - * @return boolean - */ +/** + * Deny + * + * @return boolean + */ function deny($aro, $aco, $action = "*") { return $this->allow($aro, $aco, $action, -1); } - /** - * Inherit - * - * @return boolean - */ +/** + * Inherit + * + * @return boolean + */ function inherit($aro, $aco, $action = "*") { return $this->allow($aro, $aco, $action, 0); } - /** - * Allow alias - * - * @return boolean - */ +/** + * Allow alias + * + * @return boolean + */ function grant($aro, $aco, $action = "*") { return $this->allow($aro, $aco, $action); } - /** - * Deny alias - * - * @return boolean - */ +/** + * Deny alias + * + * @return boolean + */ function revoke($aro, $aco, $action = "*") { return $this->deny($aro, $aco, $action); @@ -234,6 +249,12 @@ class DB_ACL extends AclBase +/** + * Enter description here... + * + * @param unknown_type $id + * @return unknown + */ function getAro($id = null) { if($id == null) @@ -247,6 +268,12 @@ class DB_ACL extends AclBase } +/** + * Enter description here... + * + * @param unknown_type $id + * @return unknown + */ function getAco($id = null) { if($id == null) @@ -260,6 +287,13 @@ class DB_ACL extends AclBase } +/** + * Enter description here... + * + * @param unknown_type $aro + * @param unknown_type $aco + * @return unknown + */ function getAclLink($aro, $aco) { $Aro = new Aro(); @@ -281,6 +315,12 @@ class DB_ACL extends AclBase ); } +/** + * Enter description here... + * + * @param unknown_type $keys + * @return unknown + */ function _getAcoKeys($keys) { $newKeys = array(); diff --git a/cake/libs/controller/components/dbacl/models/aclnode.php b/cake/libs/controller/components/dbacl/models/aclnode.php index 5e265b617..066c23b53 100644 --- a/cake/libs/controller/components/dbacl/models/aclnode.php +++ b/cake/libs/controller/components/dbacl/models/aclnode.php @@ -1,17 +1,77 @@ + * Copyright (c) 2005, CakePHP Authors/Developers + * + * Author(s): Larry E. Masters aka PhpNut + * Kamil Dzielinski aka Brego + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @author CakePHP Authors/Developers + * @copyright Copyright (c) 2005, CakePHP Authors/Developers + * @link https://trac.cakephp.org/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.cake.libs.controller.components.dbacl.models + * @since CakePHP v 0.10.0.1232 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * Short description. + */ require_once(CAKE . 'app_model.php'); +/** + * Short description for file. + * + * Long description for file + * + * @package cake + * @subpackage cake.cake.libs.controller.components.dbacl.models + * @since CakePHP v 0.10.0.1232 + * + */ class AclNode extends AppModel { +/** + * Enter description here... + * + * @var unknown_type + */ var $useTable = false; +/** + * Enter description here... + * + */ function __construct() { parent::__construct(); $this->__setTable(); } +/** + * Enter description here... + * + * @param unknown_type $link_id + * @param unknown_type $parent_id + * @param unknown_type $alias + * @return unknown + */ function create($link_id = 0, $parent_id = null, $alias = '') { parent::create(); @@ -58,6 +118,13 @@ class AclNode extends AppModel } +/** + * Enter description here... + * + * @param unknown_type $parent_id + * @param unknown_type $id + * @return unknown + */ function setParent($parent_id = null, $id = null) { if (strtolower(get_class($this)) == "aclnode") @@ -121,6 +188,12 @@ class AclNode extends AppModel } +/** + * Enter description here... + * + * @param unknown_type $id + * @return unknown + */ function getParent($id) { $path = $this->getPath($id); @@ -134,6 +207,12 @@ class AclNode extends AppModel } } +/** + * Enter description here... + * + * @param unknown_type $id + * @return unknown + */ function getPath($id) { if (strtolower(get_class($this)) == "aclnode") @@ -147,6 +226,12 @@ class AclNode extends AppModel return $this->findAll("lft <= {$item[$class]['lft']} and rght >= {$item[$class]['rght']}"); } +/** + * Enter description here... + * + * @param unknown_type $id + * @return unknown + */ function getChildren($id) { if (strtolower(get_class($this)) == "aclnode") @@ -160,6 +245,13 @@ class AclNode extends AppModel return $this->findAll("lft > {$item[$class]['lft']} and rght < {$item[$class]['rght']}"); } +/** + * Enter description here... + * + * @param unknown_type $id + * @param unknown_type $fKey + * @return unknown + */ function _resolveID($id, $fKey) { $key = (is_string($id) ? 'alias' : $fKey); @@ -167,6 +259,14 @@ class AclNode extends AppModel return "{$key} = {$val}"; } +/** + * Enter description here... + * + * @param unknown_type $table + * @param unknown_type $dir + * @param unknown_type $lft + * @param unknown_type $rght + */ function _syncTable($table, $dir, $lft, $rght) { $shift = ($dir == 2 ? 1 : 2); @@ -174,17 +274,26 @@ class AclNode extends AppModel $this->db->query("UPDATE $table SET lft = lft " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE lft > " . $lft); } +/** + * Enter description here... + * + * @return unknown + */ function __dataVars() { $vars = array(); - $class = strtolower(get_class($this)); - $vars['secondary_id'] = ($class == 'aro' ? 'user_id' : 'object_id'); + $class = Inflector::camelize(strtolower(get_class($this))); + $vars['secondary_id'] = (strtolower($class) == 'aro' ? 'user_id' : 'object_id'); $vars['data_name'] = $class; $vars['table_name'] = $class . 's'; - $vars['class'] = ucwords($class); + $vars['class'] = Inflector::camelize($class); return $vars; } +/** + * Enter description here... + * + */ function __setTable() { $this->table = strtolower(get_class($this)) . "s"; diff --git a/cake/libs/controller/components/dbacl/models/aco.php b/cake/libs/controller/components/dbacl/models/aco.php index 9eda95f84..8edb77cfe 100644 --- a/cake/libs/controller/components/dbacl/models/aco.php +++ b/cake/libs/controller/components/dbacl/models/aco.php @@ -1,8 +1,53 @@ + * Copyright (c) 2005, CakePHP Authors/Developers + * + * Author(s): Larry E. Masters aka PhpNut + * Kamil Dzielinski aka Brego + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @author CakePHP Authors/Developers + * @copyright Copyright (c) 2005, CakePHP Authors/Developers + * @link https://trac.cakephp.org/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.cake.libs.controller.components.dbacl.models + * @since CakePHP v 0.10.0.1232 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * Short description for file. + * + * Long description for file + * + * @package cake + * @subpackage cake.cake.libs.controller.components.dbacl.models + * @since CakePHP v 0.10.0.1232 + * + */ class Aco extends AclNode { - + var $name = 'Aco'; +/** + * Enter description here... + * + * @var unknown_type + */ var $hasMany = 'ArosAco,AcoActions'; } diff --git a/cake/libs/controller/components/dbacl/models/acoaction.php b/cake/libs/controller/components/dbacl/models/acoaction.php index 0e2c65492..207604c14 100644 --- a/cake/libs/controller/components/dbacl/models/acoaction.php +++ b/cake/libs/controller/components/dbacl/models/acoaction.php @@ -1,9 +1,58 @@ + * Copyright (c) 2005, CakePHP Authors/Developers + * + * Author(s): Larry E. Masters aka PhpNut + * Kamil Dzielinski aka Brego + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @author CakePHP Authors/Developers + * @copyright Copyright (c) 2005, CakePHP Authors/Developers + * @link https://trac.cakephp.org/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.cake.libs.controller.components.dbacl.models + * @since CakePHP v 0.10.0.1232 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * Short description. + */ require_once(CAKE.'app_model.php'); +/** + * Short description for file. + * + * Long description for file + * + * @package cake + * @subpackage cake.cake.libs.controller.components.dbacl.models + * @since CakePHP v 0.10.0.1232 + * + */ class AcoAction extends AppModel { +/** + * Enter description here... + * + * @var unknown_type + */ var $belongsTo = 'Aco'; } diff --git a/cake/libs/controller/components/dbacl/models/aro.php b/cake/libs/controller/components/dbacl/models/aro.php index b43b4f884..28d7f2431 100644 --- a/cake/libs/controller/components/dbacl/models/aro.php +++ b/cake/libs/controller/components/dbacl/models/aro.php @@ -1,8 +1,60 @@ + * Copyright (c) 2005, CakePHP Authors/Developers + * + * Author(s): Larry E. Masters aka PhpNut + * Kamil Dzielinski aka Brego + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @author CakePHP Authors/Developers + * @copyright Copyright (c) 2005, CakePHP Authors/Developers + * @link https://trac.cakephp.org/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.cake.libs.controller.components.dbacl.models + * @since CakePHP v 0.10.0.1232 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * Short description for file. + * + * Long description for file + * + * @package cake + * @subpackage cake.cake.libs.controller.components.dbacl.models + * @since CakePHP v 0.10.0.1232 + * + */ class Aro extends AclNode { - var $hasMany = 'ArosAco'; + +/** + * Enter description here... + * + * @var unknown_type + */ + var $name = 'Aro'; +/** + * Enter description here... + * + * @var unknown_type + */ + var $hasMany = 'ArosAco'; } diff --git a/cake/libs/controller/components/dbacl/models/aros_aco.php b/cake/libs/controller/components/dbacl/models/aros_aco.php index 88c1978b2..81db83a21 100644 --- a/cake/libs/controller/components/dbacl/models/aros_aco.php +++ b/cake/libs/controller/components/dbacl/models/aros_aco.php @@ -1,8 +1,66 @@ + * Copyright (c) 2005, CakePHP Authors/Developers + * + * Author(s): Larry E. Masters aka PhpNut + * Kamil Dzielinski aka Brego + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @author CakePHP Authors/Developers + * @copyright Copyright (c) 2005, CakePHP Authors/Developers + * @link https://trac.cakephp.org/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.cake.libs.controller.components.dbacl.models + * @since CakePHP v 0.10.0.1232 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * Short description for file. + * + * Long description for file + * + * @package cake + * @subpackage cake.cake.libs.controller.components.dbacl.models + * @since CakePHP v 0.10.0.1232 + * + */ class ArosAco extends AppModel { + +/** + * Enter description here... + * + * @var unknown_type + */ + var $name = 'ArosAco'; +/** + * Enter description here... + * + * @var unknown_type + */ var $useTable = 'aros_acos'; +/** + * Enter description here... + * + * @var unknown_type + */ var $belongsTo = 'Aro,Aco'; } diff --git a/cake/libs/controller/components/session.php b/cake/libs/controller/components/session.php index 4d2eaa7c7..ec49f5d08 100644 --- a/cake/libs/controller/components/session.php +++ b/cake/libs/controller/components/session.php @@ -31,7 +31,7 @@ /** * Short description for file. - * + * * Long description for file * * @package cake @@ -39,19 +39,19 @@ * @since CakePHP v 0.10.0.1232 * */ -class SessionComponent extends Object -{ - +class SessionComponent extends Object +{ + /** * Enter description here... * */ - function __construct () + function __construct () { $this->CakeSession = New CakeSession(); parent::__construct(); } - + /** * Enter description here... * @@ -65,7 +65,7 @@ class SessionComponent extends Object { return $this->CakeSession->writeSessionVar($name, $value); } - + /** * Enter description here... * @@ -79,7 +79,7 @@ class SessionComponent extends Object { return $this->CakeSession->readSessionVar($name); } - + /** * Enter description here... * @@ -92,7 +92,7 @@ class SessionComponent extends Object { return $this->CakeSession->delSessionVar($name); } - + /** * Enter description here... * @@ -105,7 +105,7 @@ class SessionComponent extends Object { return $this->CakeSession->checkSessionVar($name); } - + /** * Enter description here... * @@ -117,11 +117,11 @@ class SessionComponent extends Object { return $this->CakeSession->getLastError(); } - + /** * Enter description here... * - * Use like this. $this->Session->setError(); + * Use like this. $this->Session->setFlash('This has been saved'); * * @return string Last session error */ @@ -133,7 +133,7 @@ class SessionComponent extends Object /** * Enter description here... * - * Use like this. $this->Session->setError(); + * Use like this. $this->Session->flash(); * * @return */ @@ -148,9 +148,9 @@ class SessionComponent extends Object { return false; } - + } - + /** * Enter description here... * @@ -164,6 +164,6 @@ class SessionComponent extends Object { return $this->CakeSession->isValid(); } - + } ?> \ No newline at end of file diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index cb9f564a9..75a28ff89 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -167,7 +167,7 @@ class Controller extends Object * @access public */ var $beforeFilter = null; - + /** * Enter description here... * @@ -190,10 +190,14 @@ class Controller extends Object } $this->name = $r[1]; } - + $this->viewPath = Inflector::underscore($this->name); $this->modelClass = Inflector::singularize($this->name); $this->modelKey = Inflector::underscore($this->modelClass); + if(!defined('AUTO_SESSION') || AUTO_SESSION == true) + { + array_push($this->components, 'Session'); + } parent::__construct(); } @@ -205,12 +209,12 @@ class Controller extends Object { $dboFactory = DboFactory::getInstance($this->useDbConfig); $this->db =& $dboFactory; - + if (!empty($this->components)) { $component =& new Component($this); } - + if (!empty($this->beforeFilter)) { if(is_array($this->beforeFilter)) @@ -231,7 +235,7 @@ class Controller extends Object } } } - + if(empty($this->params['pass'])) { $id = false; @@ -272,34 +276,34 @@ class Controller extends Object } } - /** - * Redirects to given $url, after turning off $this->autoRender. - * - * @param unknown_type $url - */ +/** + * Redirects to given $url, after turning off $this->autoRender. + * + * @param unknown_type $url + */ function redirect ($url) { $this->autoRender = false; header ('Location: '.$this->base.$url); } - /** - * Saves a variable to use inside a template. - * - * @param mixed $one A string or an array of data. - * @param string $two Value in case $one is a string (which then works as the key), otherwise unused. - * @return unknown - */ +/** + * Saves a variable to use inside a template. + * + * @param mixed $one A string or an array of data. + * @param string $two Value in case $one is a string (which then works as the key), otherwise unused. + * @return unknown + */ function set($one, $two=null) { return $this->_setArray(is_array($one)? $one: array($one=>$two)); } - /** - * Enter description here... - * - * @param unknown_type $action - */ +/** + * Enter description here... + * + * @param unknown_type $action + */ function setAction ($action) { $this->action = $action; @@ -308,11 +312,11 @@ class Controller extends Object call_user_func_array(array(&$this, $action), $args); } - /** - * Returns number of errors in a submitted FORM. - * - * @return int Number of errors - */ +/** + * Returns number of errors in a submitted FORM. + * + * @return int Number of errors + */ function validate () { $args = func_get_args(); @@ -321,11 +325,11 @@ class Controller extends Object return count($errors); } - /** - * Validates a FORM according to the rules set up in the Model. - * - * @return int Number of errors - */ +/** + * Validates a FORM according to the rules set up in the Model. + * + * @return int Number of errors + */ function validateErrors () { $objects = func_get_args(); @@ -340,15 +344,15 @@ class Controller extends Object return $this->validationErrors = (count($errors)? $errors: false); } - /** - * Gets an instance of the view object & prepares it for rendering the output, then - * asks the view to actualy do the job. - * - * @param unknown_type $action - * @param unknown_type $layout - * @param unknown_type $file - * @return unknown - */ +/** + * Gets an instance of the view object & prepares it for rendering the output, then + * asks the view to actualy do the job. + * + * @param unknown_type $action + * @param unknown_type $layout + * @param unknown_type $file + * @return unknown + */ function render($action=null, $layout=null, $file=null) { $view =& new View($this); @@ -368,111 +372,11 @@ class Controller extends Object } /** - * Renders the Missing Controller web page. + * Sets data for this view. Will set title if the key "title" is in given $data array. * + * @param array $data Array of + * @access private */ - function missingController() - { - $this->autoLayout = true; - $this->pageTitle = 'Missing Controller'; - $this->render('../errors/missingController'); - exit(); - } - -/** - * Renders the Missing Action web page. - * - */ - function missingAction() - { - $this->autoLayout = true; - $this->pageTitle = 'Missing Method in Controller'; - $this->render('../errors/missingAction'); - exit(); - } - -/** - * Renders the Private Action web page. - * - */ - function privateAction() - { - $this->autoLayout = true; - $this->pageTitle = 'Trying to access private method in class'; - $this->render('../errors/privateAction'); - exit(); - } - -/** - * Renders the Missing Database web page. - * - */ - function missingDatabase() - { - $this->autoLayout = true; - $this->pageTitle = 'Scaffold Missing Database Connection'; - $this->render('../errors/missingScaffolddb'); - exit(); - } - -/** - * Renders the Missing Table web page. - * - */ - function missingTable($tableName) - { - $this->autoLayout = true; - $this->missingTableName = $tableName; - $this->pageTitle = 'Missing Database Table'; - $this->render('../errors/missingTable'); - exit(); - } - -/** - * Renders the Missing Helper file web page. - * - */ - function missingHelperFile($file) - { - $this->missingHelperFile = $file; - $this->missingHelperClass = Inflector::camelize($file) . "Helper"; - $this->pageTitle = 'Missing Helper File'; - $this->render('../errors/missingHelperFile'); - exit(); - } - - -/** - * Renders the Missing Helper class web page. - * - */ - function missingHelperClass($class) - { - $this->missingHelperClass = Inflector::camelize($class) . "Helper"; - $this->missingHelperFile = Inflector::underscore($class); - $this->pageTitle = 'Missing Helper Class'; - $this->render('../errors/missingHelperClass'); - exit(); - } - -/** - * Renders the Missing Table web page. - * - */ - function missingConnection() - { - $this->autoLayout = true; - $this->pageTitle = 'Missing Database Connection'; - $this->render('../errors/missingDatabase'); - exit(); - } - - /** - * Sets data for this view. Will set title if the key "title" is in given $data array. - * - * @param array $data Array of - * @access private - */ function _setArray($data) { foreach ($data as $name => $value) @@ -484,25 +388,25 @@ class Controller extends Object } } - /** - * Set the title element of the page. - * - * @param string $pageTitle Text for the title - * @access private - */ +/** + * Set the title element of the page. + * + * @param string $pageTitle Text for the title + * @access private + */ function _setTitle($pageTitle) { $this->pageTitle = $pageTitle; } - /** - * Shows a message to the user $time seconds, then redirects to $url - * Uses flash.thtml as a layout for the messages - * - * @param string $message Message to display to the user - * @param string $url Relative URL to redirect to after the time expires - * @param int $time Time to show the message - */ +/** + * Shows a message to the user $time seconds, then redirects to $url + * Uses flash.thtml as a layout for the messages + * + * @param string $message Message to display to the user + * @param string $url Relative URL to redirect to after the time expires + * @param int $time Time to show the message + */ function flash($message, $url, $pause=1) { $this->autoRender = false; @@ -521,24 +425,24 @@ class Controller extends Object { $flash = LIBS.'view'.DS.'templates'.DS."layouts".DS.'flash.thtml'; } - - - + + + $this->render(null,false,$flash); } - /** - * Shows a message to the user $time seconds, then redirects to $url - * Uses flash.thtml as a layout for the messages - * - * @param string $message Message to display to the user - * @param string $url URL to redirect to after the time expires - * @param int $time Time to show the message - * - * @param unknown_type $message - * @param unknown_type $url - * @param unknown_type $time - */ +/** + * Shows a message to the user $time seconds, then redirects to $url + * Uses flash.thtml as a layout for the messages + * + * @param string $message Message to display to the user + * @param string $url URL to redirect to after the time expires + * @param int $time Time to show the message + * + * @param unknown_type $message + * @param unknown_type $url + * @param unknown_type $time + */ function flashOut($message, $url, $time=1) { $this->autoRender = false; @@ -551,24 +455,24 @@ class Controller extends Object $this->render(null,false,VIEWS.'layouts'.DS.'flash.thtml'); } - /** - * This function creates a $fieldNames array for the view to use. - * @todo Map more database field types to html form fields. - * @todo View the database field types from all the supported databases. - * - */ +/** + * This function creates a $fieldNames array for the view to use. + * @todo Map more database field types to html form fields. + * @todo View the database field types from all the supported databases. + * + */ function generateFieldNames( $data = null, $doCreateOptions = true ) { $fieldNames = array(); - + $model = $this->modelClass; $modelKey = $this->modelKey; $table = $this->{$model}->table; $association = array_search($table,$this->{$model}->alias); - + $classRegistry =& ClassRegistry::getInstance(); $objRegistryModel = $classRegistry->getObject($modelKey); - + foreach ($objRegistryModel->_tableInfo as $tables) { foreach ($tables as $tabl) @@ -638,7 +542,7 @@ class Controller extends Object } switch( $type ) { - + case "text": case "mediumtext": { @@ -658,7 +562,7 @@ class Controller extends Object // get the list of options from the other model. $registry = ClassRegistry::getInstance(); $otherModel = $registry->getObject(Inflector::underscore($fieldNames[$tabl['name']]['modelKey'])); - + if( is_object($otherModel) ) { if( $doCreateOptions ) @@ -668,7 +572,7 @@ class Controller extends Object { foreach( $pass as $key=>$value ) { - + if( $alias.$key == $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] && isset( $value['id'] ) && isset( $value[$otherDisplayField] ) ) { $fieldNames[ $tabl['name']]['options'][$value['id']] = $value[$otherDisplayField]; @@ -691,7 +595,7 @@ class Controller extends Object { $fieldNames[ $tabl['name']]['type'] = 'input'; } - else + else { $fieldNames[ $tabl['name']]['type'] = 'checkbox'; } @@ -721,7 +625,7 @@ class Controller extends Object // get the list of options from the other model. $registry = ClassRegistry::getInstance(); $otherModel = $registry->getObject(Inflector::underscore($fieldNames[$tabl['name']]['modelKey'])); - + if( is_object($otherModel) ) { if( $doCreateOptions ) @@ -783,7 +687,7 @@ class Controller extends Object foreach( $objRegistryModel->_manyToMany as $relation ) { //list($modelName) = $relation; - list($manyAssociation, $modelName, $value) = $relation; + list($manyAssociation, $modelName, $value) = $relation; $modelKeyM = Inflector::underscore($modelName); $modelObject = new $modelName(); @@ -815,7 +719,7 @@ class Controller extends Object } } // end loop through manytomany relations. } - + return $fieldNames; } } diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 9d83a8534..f0e55e6c7 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -38,7 +38,7 @@ uses(DS.'model'.DS.'model', 'inflector', 'object'); /** * Scaffolding is a set of automatic views, forms and controllers for starting web development work faster. * - * Scaffold inspects your database tables, and making educated guesses, sets up a + * Scaffold inspects your database tables, and making educated guesses, sets up a * number of pages for each of your Models. These pages have data forms that work, * and afford the web developer an early look at the data, and the possibility to over-ride * scaffolded actions with custom-made ones. @@ -48,7 +48,7 @@ uses(DS.'model'.DS.'model', 'inflector', 'object'); * @since Cake v 0.10.0.1076 */ class Scaffold extends Object { - + /** * Enter description here... * @@ -106,8 +106,8 @@ class Scaffold extends Object { $this->controllerClass->pageTitle = $this->scaffoldTitle; $this->_renderScaffold($params); } - - + + /** * Enter description here... * @@ -118,7 +118,7 @@ class Scaffold extends Object { { $this->_scaffoldView($params); } - + /** * Renders the List view as the default action (index). * @@ -173,7 +173,7 @@ class Scaffold extends Object { $this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames() ); return $this->controllerClass->render($this->actionView, '', LIBS.'controller'.DS.'templates'.DS.'scaffolds'.DS.'new.thtml'); } - + /** * Renders an Edit view for scaffolded Model. * @@ -194,26 +194,26 @@ class Scaffold extends Object { * Renders a "create new" view for scaffolded Model. * * @param array $params - * @return success on save new form if data is empty or if data does not validate + * @return success on save new form if data is empty or if data does not validate * @access private */ function _scaffoldCreate($params) { - if(empty($this->controllerClass->params['data'])) + if(empty($this->controllerClass->params['data'])) { return $this->_scaffoldNew($params); } - + $this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames() ); $this->_cleanUpFields(); - + if ($this->controllerClass->{$this->modelKey}->save($this->controllerClass->params['data'])) { if(is_object($this->controllerClass->Session)) { $this->controllerClass->Session->setFlash('Your '.Inflector::humanize($this->modelKey).' has been saved.'); $this->controllerClass->redirect('/'.Inflector::underscore($this->controllerClass->viewPath)); - + } else { @@ -225,7 +225,7 @@ class Scaffold extends Object { { if(is_object($this->controllerClass->Session)) { - $this->controllerClass->Session->setFlash('Please correct errors below'); + $this->controllerClass->Session->setFlash('Please correct errors below'); } $this->controllerClass->set('data', $this->controllerClass->params['data']); $this->controllerClass->validateErrors($this->controllerClass->{$this->modelKey}); @@ -242,21 +242,21 @@ class Scaffold extends Object { */ function _scaffoldUpdate($params=array()) { - if(empty($this->controllerClass->params['data'])) + if(empty($this->controllerClass->params['data'])) { return $this->_scaffoldNew($params); } - + $this->_cleanUpFields(); $this->controllerClass->{$this->modelKey}->set($this->controllerClass->params['data']); - + if ( $this->controllerClass->{$this->modelKey}->save()) { if(is_object($this->controllerClass->Session)) { $this->controllerClass->Session->setFlash('Your '.Inflector::humanize($this->modelKey).' has been saved.', '/'); $this->controllerClass->redirect('/'.Inflector::underscore($this->controllerClass->viewPath)); - + } else { @@ -270,7 +270,7 @@ class Scaffold extends Object { { $this->controllerClass->Session->setFlash('The '.Inflector::humanize($this->modelKey).' has been updated.','/'); $this->controllerClass->redirect('/'.Inflector::underscore($this->controllerClass->viewPath)); - + } else { @@ -296,7 +296,7 @@ class Scaffold extends Object { { $this->controllerClass->Session->setFlash('The '.Inflector::humanize($this->modelKey).' with id: '.$id.' has been deleted.', '/'); $this->controllerClass->redirect('/'.Inflector::underscore($this->controllerClass->viewPath)); - + } else { @@ -310,7 +310,7 @@ class Scaffold extends Object { { $this->controllerClass->Session->setFlash('There was an error deleting the '.Inflector::humanize($this->modelKey).' with the id '.$id, '/'); $this->controllerClass->redirect('/'.Inflector::underscore($this->controllerClass->viewPath)); - + } else { @@ -319,7 +319,7 @@ class Scaffold extends Object { } } } - + /** * When methods are now present in a controller * scaffoldView is used to call default Scaffold methods if: @@ -340,15 +340,15 @@ class Scaffold extends Object { { $this->controllerClass->helpers[] = 'Form'; } - + $isDataBaseSet = DboFactory::getInstance($this->controllerClass->useDbConfig); if(!empty($isDataBaseSet)) { $this->controllerClass->constructClasses(); - + if($params['action'] === 'index' || $params['action'] === 'list' || - $params['action'] === 'show' || $params['action'] === 'add' || - $params['action'] === 'create' || $params['action'] === 'edit' || + $params['action'] === 'show' || $params['action'] === 'add' || + $params['action'] === 'create' || $params['action'] === 'edit' || $params['action'] === 'update' || $params['action'] === 'destroy') { switch ($params['action']) @@ -356,36 +356,36 @@ class Scaffold extends Object { case 'index': $this->_scaffoldIndex($params); break; - + case 'show': $this->_scaffoldShow($params); break; - + case 'list': $this->_scaffoldList($params); break; - + case 'add': $this->_scaffoldNew($params); break; - + case 'edit': $this->_scaffoldEdit($params); break; - + case 'create': $this->_scaffoldCreate($params); break; - + case 'update': $this->_scaffoldUpdate($params); break; - + case 'destroy': $this->_scaffoldDestroy($params); break; } - } + } else { $this->controllerClass->layout = 'default'; @@ -396,20 +396,21 @@ class Scaffold extends Object { } else { + $this->controllerClass->constructClasses(); $this->controllerClass->layout = 'default'; call_user_func_array(array($this->controllerClass, 'missingDatabase'), null); exit; } } - + /** * Cleans up the date fields of current Model. - * + * * @access private */ function _cleanUpFields() { - + foreach( $this->controllerClass->{$this->modelKey}->_tableInfo as $table ) { foreach ($table as $field) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index b6b4d9129..e914c60d9 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -3,7 +3,7 @@ /** * Object-relational mapper. - * + * * DBO-backed object data model, for mapping database tables to Cake objects. * * PHP versions 4 and 5 @@ -11,20 +11,19 @@ * CakePHP : Rapid Development Framework * Copyright (c) 2005, CakePHP Authors/Developers * - * Author(s): Michal Tatarynowicz aka Pies - * Larry E. Masters aka PhpNut + * Author(s): Larry E. Masters aka PhpNut * Kamil Dzielinski aka Brego * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * - * @filesource + * @filesource * @author CakePHP Authors/Developers * @copyright Copyright (c) 2005, CakePHP Authors/Developers * @link https://trac.cakephp.org/wiki/Authors Authors/Developers * @package cake * @subpackage cake.cake.libs.model - * @since CakePHP v 0.2.9 + * @since CakePHP v 0.10.0.0 * @version $Revision$ * @modifiedby $LastChangedBy$ * @lastmodified $Date$ @@ -43,7 +42,7 @@ uses('object', 'class_registry', 'validators', 'inflector'); * DBO-backed object data model. * Automatically selects a database table name based on a pluralized lowercase object class name * (i.e. class 'User' => table 'users'; class 'Man' => table 'men') - * The table is required to have at least 'id auto_increment', 'created datetime', + * The table is required to have at least 'id auto_increment', 'created datetime', * and 'modified datetime' fields. * * @package cake @@ -51,9 +50,9 @@ uses('object', 'class_registry', 'validators', 'inflector'); * @since CakePHP v 0.2.9 * */ -class Model extends Object +class Model extends Object { - + /** * Enter description here... * @@ -101,7 +100,7 @@ class Model extends Object * @access public */ var $tableId = null; - + /** * Table metadata * @@ -109,9 +108,9 @@ class Model extends Object * @access private */ var $_tableInfo = null; - + /** - * Array of other Models this Model references in a belongsTo (one-to-one) relationship. + * Array of other Models this Model references in a belongsTo (one-to-one) relationship. * * @var array * @access private @@ -120,16 +119,16 @@ class Model extends Object /** - * Array of other Models this Model references in a hasOne (one-to-one) relationship. + * Array of other Models this Model references in a hasOne (one-to-one) relationship. * * @var array * @access private */ var $_oneToOne = array(); - + /** - * Array of other Models this Model references in a hasMany (one-to-many) relationship. + * Array of other Models this Model references in a hasMany (one-to-many) relationship. * * @var array * @access private @@ -138,7 +137,7 @@ class Model extends Object /** - * Array of other Models this Model references in a hasAndBelongsToMany (many-to-many) relationship. + * Array of other Models this Model references in a hasAndBelongsToMany (many-to-many) relationship. * * @var array * @access private @@ -160,14 +159,14 @@ class Model extends Object * @var array */ var $validationErrors = null; - + /** * Prefix for tables in model. * * @var string */ var $tablePrefix = null; - + /** * Name of the model. * @@ -188,14 +187,14 @@ class Model extends Object * @var unknown_type */ var $tableToModel = array(); - + /** * Enter description here... * * @var unknown_type */ var $alias = array(); - + /** * Constructor. Binds the Model's database table to the object. * @@ -203,37 +202,37 @@ class Model extends Object * @param string $table Database table to use. * @param unknown_type $db Database connection object. */ - function __construct ($id=false, $table=null, $db=null) + function __construct ($id=false, $table=null, $db=null) { if($this->name === null) { $this->name = get_class($this); } - + if($this->tableId === null) { $this->tableId = 'id'; } - - $this->currentModel = Inflector::underscore($this->name); - + + $this->currentModel = Inflector::underscore($this->name); + if($db != null) { $this->db =& $db; } else { - $dboFactory = DboFactory::getInstance(); - $this->db =& $dboFactory ; + $dboFactory = DboFactory::getInstance(); + $this->db =& $dboFactory; if(empty($this->db)) { - $this->_throwMissingConnection(); + $this->missingConnection(); } } - + $classRegistry =& ClassRegistry::getInstance(); $classRegistry->addObject($this->currentModel, $this); - + if ($id) { $this->id = $id; @@ -241,14 +240,14 @@ class Model extends Object if($this->useTable !== false) { $tableName = $table? $table: ($this->useTable? $this->useTable: Inflector::tableize($this->name)); - + if (in_array('settableprefix', get_class_methods($this->name))) { $this->setTablePrefix(); } - + $this->tablePrefix? $this->setTable($this->tablePrefix.$tableName): $this->setTable($tableName); - + parent::__construct(); $this->createLinks(); } @@ -300,14 +299,14 @@ class Model extends Object else { $association = explode(',', $this->belongsTo); - foreach ($association as $className) + foreach ($association as $className) { - $this->_constructAssociatedModels($className , 'Belongs'); + $this->_constructAssociatedModels($className, $className , 'Belongs'); $this->linkAssociation('Belongs', $className, $className, $this->id); } } } - + /** * Enter description here... * @@ -320,15 +319,15 @@ class Model extends Object foreach ($this->hasOne as $association => $associationValue) { $className = $association; - $this->_associationSwitch($className, $className, $associationValue, 'One'); + $this->_associationSwitch($association, $className, $associationValue, 'One'); } } else { $association = explode(',', $this->hasOne); - foreach ($association as $className) + foreach ($association as $className) { - $this->_constructAssociatedModels($className , 'One'); + $this->_constructAssociatedModels($className, $className , 'One'); $this->linkAssociation('One', $className, $className, $this->id); } } @@ -352,9 +351,9 @@ class Model extends Object else { $association = explode(',', $this->hasMany); - foreach ($association as $className) + foreach ($association as $className) { - $this->_constructAssociatedModels($className , 'Many'); + $this->_constructAssociatedModels($className, $className , 'Many'); $this->linkAssociation('Many', $className, $className, $this->id); } } @@ -378,14 +377,14 @@ class Model extends Object else { $association = explode(',', $this->hasAndBelongsToMany); - foreach ($association as $className) + foreach ($association as $className) { - $this->_constructAssociatedModels($className , 'ManyTo'); + $this->_constructAssociatedModels($className, $className , 'ManyTo'); $this->linkAssociation('ManyTo', $className, $className, $this->id); } } } - + /** * Enter description here... * @@ -397,76 +396,76 @@ class Model extends Object function _associationSwitch($association, $className, $associationValue, $type) { $classCreated = false; - + foreach ($associationValue as $option => $optionValue) { if (($option === 'className') && ($classCreated === false)) { $className = $optionValue; } - + if ($classCreated === false) { - $this->_constructAssociatedModels($className , $type); + $this->_constructAssociatedModels($association, $className , $type); $classCreated = true; } - + switch($option) { case 'associationForeignKey': - $this->{$className}->{$this->currentModel.'_associationforeignkey'} = $optionValue; + $this->{$association.'_associationforeignkey'} = $optionValue; break; - + case 'conditions': - $this->{$className}->{$this->currentModel.'_conditions'} = $optionValue; + $this->{$association.'_conditions'} = $optionValue; break; - + case 'counterCache': - $this->{$className}->{$this->currentModel.'_countercache'} = $optionValue; + $this->{$association.'_countercache'} = $optionValue; break; case 'counterSql': - $this->{$className}->{$this->currentModel.'_countersql'} = $optionValue; + $this->{$association.'_countersql'} = $optionValue; break; - + case 'deleteSql': - $this->{$className}->{$this->currentModel.'_deletesql'} = $optionValue; + $this->{$association.'_deletesql'} = $optionValue; break; - + case 'dependent': - $this->{$className}->{$this->currentModel.'_dependent'} = $optionValue; + $this->{$association.'_dependent'} = $optionValue; break; case 'exclusive': - $this->{$className}->{$this->currentModel.'_exclusive'} = $optionValue; + $this->{$association.'_exclusive'} = $optionValue; break; - + case 'finderSql': - $this->{$className}->{$this->currentModel.'_findersql'} = $optionValue; + $this->{$association.'_findersql'} = $optionValue; break; - + case 'foreignKey': - $this->{$className}->{$this->currentModel.'_foreignkey'} = $optionValue; + $this->{$association.'_foreignkey'} = $optionValue; break; - + case 'insertSql': - $this->{$className}->{$this->currentModel.'_insertsql'} = $optionValue; + $this->{$association.'_insertsql'} = $optionValue; break; - + case 'joinTable': - $this->{$className}->{$this->currentModel.'_jointable'} = $optionValue; + $this->{$association.'_jointable'} = $optionValue; break; - + case 'order': - $this->{$className}->{$this->currentModel.'_order'} = $optionValue; + $this->{$association.'_order'} = $optionValue; break; - + case 'uniq': - $this->{$className}->{$this->currentModel.'_uniq'} = $optionValue; + $this->{$association.'_uniq'} = $optionValue; break; - + case 'fields': - $this->{$className}->{$this->currentModel.'_fields'} = $optionValue; + $this->{$association.'_fields'} = $optionValue; break; } } @@ -480,45 +479,45 @@ class Model extends Object * @param unknown_type $type * @access private */ - function _constructAssociatedModels($className, $type) + function _constructAssociatedModels($association, $className, $type) { $collectionKey = Inflector::underscore($className); $classRegistry =& ClassRegistry::getInstance(); - + if(!$classRegistry->isKeySet($collectionKey)) { $this->{$className} = new $className(); } else { - $this->{$className} = $classRegistry->getObject($collectionKey); + $this->{$className} = $classRegistry->getObject($collectionKey); } - + switch($type) { case 'Belongs': - $this->{$className}->{$this->currentModel.'_conditions'} = null; - $this->{$className}->{$this->currentModel.'_order'} = null; - $this->{$className}->{$this->currentModel.'_foreignkey'} = Inflector::singularize($this->{$className}->table).'_id'; - $this->{$className}->{$this->currentModel.'_countercache'} = null; + $this->{$association.'_conditions'} = null; + $this->{$association.'_order'} = null; + $this->{$association.'_foreignkey'} = Inflector::singularize($this->{$className}->table).'_id'; + $this->{$association.'_countercache'} = null; break; - + case 'One': - $this->{$className}->{$this->currentModel.'_conditions'} = null; - $this->{$className}->{$this->currentModel.'_order'} = null; - $this->{$className}->{$this->currentModel.'_dependent'} = null; - $this->{$className}->{$this->currentModel.'_foreignkey'} = Inflector::singularize($this->table).'_id'; + $this->{$association.'_conditions'} = null; + $this->{$association.'_order'} = null; + $this->{$association.'_dependent'} = null; + $this->{$association.'_foreignkey'} = Inflector::singularize($this->table).'_id'; break; case 'Many': - $this->{$className}->{$this->currentModel.'_conditions'} = null; - $this->{$className}->{$this->currentModel.'_order'} = null; - $this->{$className}->{$this->currentModel.'_foreignkey'} = Inflector::singularize($this->table).'_id'; - $this->{$className}->{$this->currentModel.'_fields'} = '*'; - $this->{$className}->{$this->currentModel.'_dependent'} = null; - $this->{$className}->{$this->currentModel.'_exclusive'} = null; - $this->{$className}->{$this->currentModel.'_findersql'} = null; - $this->{$className}->{$this->currentModel.'_countersql'} = null; + $this->{$association.'_conditions'} = null; + $this->{$association.'_order'} = null; + $this->{$association.'_foreignkey'} = Inflector::singularize($this->table).'_id'; + $this->{$association.'_fields'} = '*'; + $this->{$association.'_dependent'} = null; + $this->{$association.'_exclusive'} = null; + $this->{$association.'_findersql'} = null; + $this->{$association.'_countersql'} = null; break; case 'ManyTo': @@ -528,21 +527,21 @@ class Model extends Object $joinTable = $tableSort[0] . '_' . $tableSort[1]; $key1 = Inflector::singularize($this->table) . '_id'; $key2 = Inflector::singularize($this->{$className}->table) . '_id'; - $this->{$className}->{$this->currentModel.'_jointable'} = $joinTable; - $this->{$className}->{$this->currentModel.'_fields'} = '*'; - $this->{$className}->{$this->currentModel.'_foreignkey'} = $key1; - $this->{$className}->{$this->currentModel.'_associationforeignkey'} = $key2; - $this->{$className}->{$this->currentModel.'_conditions'} = null; - $this->{$className}->{$this->currentModel.'_order'} = null; - $this->{$className}->{$this->currentModel.'_uniq'} = null; - $this->{$className}->{$this->currentModel.'_findersql'} = null; - $this->{$className}->{$this->currentModel.'_deletesql'} = null; - $this->{$className}->{$this->currentModel.'_insertsql'} = null; + $this->{$association.'_jointable'} = $joinTable; + $this->{$association.'_fields'} = '*'; + $this->{$association.'_foreignkey'} = $key1; + $this->{$association.'_associationforeignkey'} = $key2; + $this->{$association.'_conditions'} = null; + $this->{$association.'_order'} = null; + $this->{$association.'_uniq'} = null; + $this->{$association.'_findersql'} = null; + $this->{$association.'_deletesql'} = null; + $this->{$association.'_insertsql'} = null; break; } $this->tableToModel[$this->{$className}->table] = $className; } - + /** * Enter description here... * @@ -550,7 +549,7 @@ class Model extends Object * @param unknown_type $tableName * @param unknown_type $value */ - function linkAssociation ($type, $association, $model, $value=null) + function linkAssociation ($type, $association, $model, $value=null) { switch ($type) { @@ -558,34 +557,34 @@ class Model extends Object $this->alias[$association] = $this->{$model}->table; $this->_belongsToOther[] = array($association, $model, $value); break; - + case 'One': $this->alias[$association] = $this->{$model}->table; $this->_oneToOne[] = array($association, $model, $value); break; - + case 'Many': $this->alias[$association] = $this->{$model}->table; $this->_oneToMany[] = array($association, $model, $value); break; - + case 'ManyTo': $this->alias[$association] = $this->{$model}->table; $this->_manyToMany[] = array($association, $model, $value); break; } } - + /** * Sets a custom table for your controller class. Used by your controller to select a database table. * * @param string $tableName Name of the custom table */ - function setTable($tableName) + function setTable($tableName) { - if (!in_array(strtolower($tableName), $this->db->tables())) + if (!in_array(strtolower($tableName), $this->db->tables())) { - $this->_throwMissingTable($tableName); + $this->missingTable($tableName); exit(); } else @@ -602,27 +601,27 @@ class Model extends Object * and if that's found, it sets the current id to the value of $one[id]. * For all other keys than 'id' the keys and values of $one are copied to the 'data' property of this object. * 2) Returns an array with all of $one's keys and values. - * (Alternative indata: two strings, which are mangled to + * (Alternative indata: two strings, which are mangled to * a one-item, two-dimensional array using $one for a key and $two as its value.) * * @param mixed $one Array or string of data * @param string $two Value string for the alternative indata method * @return unknown */ - function set ($one, $two=null) + function set ($one, $two=null) { $this->validationErrors = null; $data = is_array($one)? $one : array($one=>$two); - - foreach ($data as $n => $v) + + foreach ($data as $n => $v) { foreach ($v as $x => $y) { - if($x == 'id') + if($x == $this->tableId) { $this->id = $y; } - $this->data[$n][$x] = $y; + $this->data[$n][$x] = $y; } } return $data; @@ -633,7 +632,7 @@ class Model extends Object * * @param int $id Id */ - function setId ($id) + function setId ($id) { $this->id = $id; } @@ -643,9 +642,9 @@ class Model extends Object * * @return array Array of table metadata */ - function loadInfo () + function loadInfo () { - if (empty($this->_tableInfo)) + if (empty($this->_tableInfo)) { $this->_tableInfo = new NeatArray($this->db->fields($this->table)); } @@ -654,15 +653,15 @@ class Model extends Object /** * Returns true if given field name exists in this Model's database table. - * Starts by loading the metadata into the private property table_info if that is not already set. + * Starts by loading the metadata into the private property table_info if that is not already set. * * @param string $name Name of table to look in * @return boolean */ - function hasField ($name) + function hasField ($name) { if (empty($this->_tableInfo)) - { + { $this->loadInfo(); } return $this->_tableInfo->findIn('name', $name); @@ -673,7 +672,7 @@ class Model extends Object * * @return boolean True on success */ - function create () + function create () { $this->id = false; unset($this->data); @@ -687,7 +686,7 @@ class Model extends Object * @param mixed $fields String of single fieldname, or an array of fieldnames. * @return array Array of database fields */ - function read ($fields=null) + function read ($fields=null) { $this->validationErrors = null; if(is_array($this->id)) @@ -707,28 +706,28 @@ class Model extends Object * @param string $conditions SQL conditions (defaults to NULL) * @return field contents */ - function field ($name, $conditions=null, $order=null) + function field ($name, $conditions=null, $order=null) { if (isset($this->data[$this->name][$name])) { return $this->data[$this->name][$name]; } - - if ($conditions) + + if ($conditions) { $conditions = $this->parseConditions($conditions); } - - if ($data = $this->find($conditions, $name, $order)) + + if ($data = $this->find($conditions, $name, $order)) { return isset($data[$this->name][$name])? $data[$this->name][$name]: false; } - else + else { return false; } } - + /** * Saves a single field to the database. @@ -737,7 +736,7 @@ class Model extends Object * @param mixed $value Value of the field * @return boolean True on success save */ - function saveField($name, $value) + function saveField($name, $value) { return Model::save(array($this->name=>array($name=>$value)), false); } @@ -745,35 +744,35 @@ class Model extends Object /** * Saves model data to the database. * - * @param array $data Data to save. + * @param array $data Data to save. * @param boolean $validate * @return boolean success */ - function save ($data=null, $validate=true) + function save ($data=null, $validate=true) { - if ($data) - { + if ($data) + { $this->set($data); } - + if ($validate && !$this->validates()) { return false; } - + $fields = $values = array(); - + $count = 0; if(count($this->data) > 1) { $weHaveMulti = true; $joined = false; } - else + else { $weHaveMulti = false; } - + foreach ($this->data as $n=>$v) { if(isset($weHaveMulti) && $count > 0 && !empty($this->_manyToMany)) @@ -784,13 +783,13 @@ class Model extends Object { foreach ($v as $x => $y) { - if ($this->hasField($x)) + if ($this->hasField($x)) { $fields[] = $x; - $values[] = (ini_get('magic_quotes_gpc') == 1) ? + $values[] = (ini_get('magic_quotes_gpc') == 1) ? $this->db->prepare(stripslashes($y)) : $this->db->prepare($y); - - if($x == 'id' && !is_numeric($y)) + + if($x == $this->tableId && !is_numeric($y)) { $newID = $y; } @@ -799,13 +798,13 @@ class Model extends Object $count++; } } - - if (empty($this->id) && $this->hasField('created') && !in_array('created', $fields)) + + if (empty($this->id) && $this->hasField('created') && !in_array('created', $fields)) { $fields[] = 'created'; $values[] = date("'Y-m-d H:i:s'"); } - if ($this->hasField('modified') && !in_array('modified', $fields)) + if ($this->hasField('modified') && !in_array('modified', $fields)) { $fields[] = 'modified'; $values[] = 'NOW()'; @@ -819,37 +818,37 @@ class Model extends Object if(!empty($this->id)) { $sql = array(); - foreach (array_combine($fields, $values) as $field=>$value) + foreach (array_combine($fields, $values) as $field=>$value) { $sql[] = $field.'='.$value; } - + $sql = "UPDATE {$this->table} SET ".join(',', $sql)." WHERE id = '{$this->id}'"; - + if ($this->db->query($sql)) { if(!empty($joined)) { $this->_saveMulti($joined, $this->id); - } + } $this->data = false; return true; } - else + else { - return $this->db->hasAny($this->table, "id = '{$this->id}'"); + return $this->db->hasAny($this->table, "$this->tableId = '{$this->id}'"); } } - else + else { $fields = join(',', $fields); $values = join(',', $values); - + $sql = "INSERT INTO {$this->table} ({$fields}) VALUES ({$values})"; - - if($this->db->query($sql)) + + if($this->db->query($sql)) { - $this->id = $this->db->lastInsertId($this->table, 'id'); + $this->id = $this->db->lastInsertId($this->table, $this->tableId); if(!empty($joined)) { if(!$this->id > 0 && isset($newID)) @@ -857,16 +856,16 @@ class Model extends Object $this->id = $newID; } $this->_saveMulti($joined, $this->id); - } + } return true; } - else + else { return false; } } } - else + else { return false; } @@ -875,31 +874,30 @@ class Model extends Object /** * Saves model hasAndBelongsToMany data to the database. * - * @param array $joined Data to save. - * @param string $id + * @param array $joined Data to save. + * @param string $id * @return * @access private */ - function _saveMulti ($joined, $id) + function _saveMulti ($joined, $id) { foreach ($joined as $x => $y) { - foreach ($y as $name => $value) + foreach ($y as $association => $value) { - $name = Inflector::camelize($name); - $joinTable[] = $this->{$name}->{$this->currentModel.'_jointable'}; - $mainKey = $this->{$name}->{$this->currentModel.'_foreignkey'}; + $joinTable[] = $this->{$association.'_jointable'}; + $mainKey = $this->{$association.'_foreignkey'}; $keys[] = $mainKey; - $keys[] = $this->{$name}->{$this->currentModel.'_associationforeignkey'}; + $keys[] = $this->{$association.'_associationforeignkey'}; $fields[] = join(',', $keys); unset($keys); - + foreach ($value as $update) { if(!empty($update)) { - $values[] = (ini_get('magic_quotes_gpc') == 1) ? $this->db->prepare(stripslashes($id)) : $this->db->prepare($id); - $values[] = (ini_get('magic_quotes_gpc') == 1) ? $this->db->prepare(stripslashes($update)) : $this->db->prepare($update); + $values[] = (ini_get('magic_quotes_gpc') == 1) ? $this->db->prepare(stripslashes($id)) : $this->db->prepare($id); + $values[] = (ini_get('magic_quotes_gpc') == 1) ? $this->db->prepare(stripslashes($update)) : $this->db->prepare($update); $values = join(',', $values); $newValues[] = "({$values})"; unset($values); @@ -912,8 +910,9 @@ class Model extends Object } } } - - for ($count = 0; $count < count($joinTable); $count++) + + $total = count($joinTable); + for ($count = 0; $count < $total; $count++) { $this->db->query("DELETE FROM {$joinTable[$count]} WHERE $mainKey = '{$id}'"); if(!empty($newValue[$count])) @@ -922,7 +921,7 @@ class Model extends Object } } } - + /** * Synonym for del(). * @@ -930,7 +929,7 @@ class Model extends Object * @see function del * @return boolean True on success */ - function remove ($id=null) + function remove ($id=null) { return $this->del($id); } @@ -941,13 +940,13 @@ class Model extends Object * @param mixed $id Id of database record to delete * @return boolean True on success */ - function del ($id=null) + function del ($id=null) { if ($id) - { + { $this->id = $id; } - if ($this->id && $this->db->query("DELETE FROM {$this->table} WHERE id = '{$this->id}'")) + if ($this->id && $this->db->query("DELETE FROM {$this->table} WHERE {$this->tableId} = '{$this->id}'")) { $this->id = false; return true; @@ -963,9 +962,9 @@ class Model extends Object * * @return boolean True if such a record exists */ - function exists () + function exists () { - return $this->id? $this->db->hasAny($this->table, "id = '{$this->id}'"): false; + return $this->id? $this->db->hasAny($this->table, "$this->tableId = '{$this->id}'"): false; } /** @@ -973,7 +972,7 @@ class Model extends Object * * @return boolean True if such a record exists */ - function hasAny ($conditions = null) + function hasAny ($conditions = null) { return $this->findCount($conditions); } @@ -986,7 +985,7 @@ class Model extends Object * @param string $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC") * @return array Array of records */ - function find ($conditions = null, $fields = null, $order = null) + function find ($conditions = null, $fields = null, $order = null) { $data = Model::findAll($conditions, $fields, $order, 1); return empty($data[0])? false: $data[0]; @@ -996,16 +995,16 @@ class Model extends Object * @return string * */ - function parseConditions ($conditions) + function parseConditions ($conditions) { - if (is_string($conditions)) + if (is_string($conditions)) { return $conditions; } - elseif (is_array($conditions)) + elseif (is_array($conditions)) { $out = array(); - foreach ($conditions as $key=>$value) + foreach ($conditions as $key=>$value) { $slashedValue = (ini_get('magic_quotes_gpc') == 1) ? $this->db->prepare(stripslashes($value)) : $this->db->prepare($value); //Should remove the = below so LIKE and other compares can be used @@ -1013,7 +1012,7 @@ class Model extends Object } return join(' and ', $out); } - else + else { return null; } @@ -1029,7 +1028,7 @@ class Model extends Object * @param int $page Page number * @return array Array of records */ - function findAll ($conditions = null, $fields = null, $order = null, $limit=50, $page=1) + function findAll ($conditions = null, $fields = null, $order = null, $limit=50, $page=1) { $conditions = $this->parseConditions($conditions); $alias = null; @@ -1045,17 +1044,17 @@ class Model extends Object { $f = array('*'); } - + $joins = $whers = array(); - + if(!empty($this->_oneToOne)) { foreach ($this->_oneToOne as $rule) { list($association, $model, $value) = $rule; - if(!empty($this->{$model}->{$this->currentModel.'_foreignkey'})) + if(!empty($this->{$association.'_foreignkey'})) { - if($this->name == $this->{$model}->name) + if($this->name == $this->{$model}->name and $this->name == $association) { $alias = 'Child_'.$association; } @@ -1063,25 +1062,25 @@ class Model extends Object { $alias = $association; } - $oneToOneConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'}); - $oneToOneOrder = $this->{$model}->{$this->currentModel.'_order'}; - - $joins[] = "LEFT JOIN {$this->{$model}->table} AS `$alias` ON - `$alias`.{$this->{$model}->{$this->currentModel.'_foreignkey'}} = {$this->name}.id" + $oneToOneConditions = $this->parseConditions($this->{$association.'_conditions'}); + $oneToOneOrder = $this->{$association.'_order'}; + + $joins[] = "LEFT JOIN {$this->{$model}->table} AS `$alias` ON + `$alias`.{$this->{$association.'_foreignkey'}} = {$this->name}.id" .($oneToOneConditions? " WHERE {$oneToOneConditions}":null) .($oneToOneOrder? " ORDER BY {$oneToOneOrder}": null); } } } - + if(!empty($this->_belongsToOther)) { foreach ($this->_belongsToOther as $rule) { - list($association, $model, $value) = $rule; - if(!empty($this->{$model}->{$this->currentModel.'_foreignkey'})) + list($association, $model, $value) = $rule; + if(!empty($this->{$association.'_foreignkey'})) { - if($this->name == $this->{$model}->name) + if($this->name == $this->{$model}->name and $this->name == $association) { $alias = 'Child_'.$association; } @@ -1089,43 +1088,43 @@ class Model extends Object { $alias = $association; } - $belongsToOtherConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'}); - $belongsToOtherOrder = $this->{$model}->{$this->currentModel.'_order'}; - - $joins[] = "LEFT JOIN {$this->{$model}->table} AS `$alias` ON {$this->name}.{$this->{$model}->{$this->currentModel.'_foreignkey'}} = `$alias`.id" + $belongsToOtherConditions = $this->parseConditions($this->{$association.'_conditions'}); + $belongsToOtherOrder = $this->{$association.'_order'}; + + $joins[] = "LEFT JOIN {$this->{$model}->table} AS `$alias` ON {$this->name}.{$this->{$association.'_foreignkey'}} = `$alias`.id" .($belongsToOtherConditions? " WHERE {$belongsToOtherConditions}":null) .($belongsToOtherOrder? " ORDER BY {$belongsToOtherOrder}": null); } } } - + $joins = count($joins)? join(' ', $joins): null; $whers = count($whers)? '('.join(' AND ', $whers).')': null; $conditions .= ($conditions && $whers? ' AND ': null).$whers; - + $offset = $page > 1? ($page-1) * $limit: 0; - + $limit_str = $limit ? $this->db->selectLimit($limit, $offset) : ''; - + $sql = "SELECT " .join(', ', $f) ." FROM {$this->table} AS `{$this->name}` {$joins}" .($conditions? " WHERE {$conditions}":null) .($order? " ORDER BY {$order}": null) .$limit_str; - + $data = $this->db->all($sql); - + if(!empty($this->_oneToMany)) { - $newValue = $this->_findOneToMany($data); + $newValue = $this->_findOneToMany($data); if(!empty($newValue)) { $data = $newValue; } } - + if(!empty($this->_manyToMany)) { $newValue = $this->_findManyToMany($data); @@ -1134,10 +1133,10 @@ class Model extends Object $data = $newValue; } } - + return $data; } - + /** * Enter description here... * @@ -1151,30 +1150,30 @@ class Model extends Object foreach ($this->_oneToMany as $rule) { $count = 0; - list($association, $model, $value) = $rule; + list($association, $model, $value) = $rule; foreach ($datacheck as $key => $value1) { foreach ($value1 as $key2 => $value2) { if($key2 === $this->name) { - if($this->{$model}->{$this->currentModel.'_findersql'}) + if($this->{$association.'_findersql'}) { - $tmpSQL = $this->{$model}->{$this->currentModel.'_findersql'}; + $tmpSQL = $this->{$association.'_findersql'}; } - else + else { - $oneToManyConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'}); - $oneToManyOrder = $this->{$model}->{$this->currentModel.'_order'}; - - $tmpSQL = "SELECT {$this->{$model}->{$this->currentModel.'_fields'}} FROM {$this->{$model}->table} AS `{$association}` - WHERE ({$this->{$model}->{$this->currentModel.'_foreignkey'}}) = '{$value2['id']}'" - .($oneToManyConditions? " WHERE {$oneToManyConditions}":null) + $oneToManyConditions = $this->parseConditions($this->{$association.'_conditions'}); + $oneToManyOrder = $this->{$association.'_order'}; + + $tmpSQL = "SELECT {$this->{$association.'_fields'}} FROM {$this->{$model}->table} AS `{$association}` + WHERE ({$this->{$association.'_foreignkey'}}) = '{$value2['id']}'" + .($oneToManyConditions? " {$oneToManyConditions}":null) .($oneToManyOrder? " ORDER BY {$oneToManyOrder}": null); } - + $oneToManySelect[$association] = $this->db->all($tmpSQL); - + if( !empty($oneToManySelect[$association]) && is_array($oneToManySelect[$association])) { $newKey = $association; @@ -1196,14 +1195,14 @@ class Model extends Object } if(empty($newValue) && !empty($original)) { - for ($i = 0; $i< count($original); $i++) + for ($i = 0; $i< count($original); $i++) { $newValue[$i] = $original[$i]; } } elseif(!empty($original)) { - for ($i = 0; $i< count($original); $i++) + for ($i = 0; $i< count($original); $i++) { $newValue[$i] = array_merge($newValue[$i], $original[$i]); } @@ -1214,7 +1213,7 @@ class Model extends Object return $newValue; } } - + /** * Enter description here... * @@ -1228,37 +1227,37 @@ class Model extends Object foreach ($this->_manyToMany as $rule) { $count = 0; - list($association, $model, $value) = $rule; + list($association, $model, $value) = $rule; foreach ($datacheck as $key => $value1) { foreach ($value1 as $key2 => $value2) { if($key2 === $this->name) { - if( 0 == strncmp($key2, $this->{$model}->{$this->currentModel.'_foreignkey'}, $key2) ) + if( 0 == strncmp($key2, $this->{$association.'_foreignkey'}, $key2) ) { if(!empty ($value2['id'])) { - if($this->{$model}->{$this->currentModel.'_findersql'}) + if($this->{$association.'_findersql'}) { - $tmpSQL = $this->{$model}->{$this->currentModel.'_findersql'}; + $tmpSQL = $this->{$association.'_findersql'}; } - else + else { - $manyToManyConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'}); - $manyToManyOrder = $this->{$model}->{$this->currentModel.'_order'}; - - $tmpSQL = "SELECT {$this->{$model}->{$this->currentModel.'_fields'}} FROM {$this->{$model}->table} AS `{$association}` - JOIN {$this->{$model}->{$this->currentModel.'_jointable'}} - ON {$this->{$model}->{$this->currentModel.'_jointable'}}. - {$this->{$model}->{$this->currentModel.'_foreignkey'}} = '$value2[id]' - AND {$this->{$model}->{$this->currentModel.'_jointable'}}. - {$this->{$model}->{$this->currentModel.'_associationforeignkey'}} = `{$association}` .id" + $manyToManyConditions = $this->parseConditions($this->{$association.'_conditions'}); + $manyToManyOrder = $this->{$association.'_order'}; + + $tmpSQL = "SELECT {$this->{$association.'_fields'}} FROM {$this->{$model}->table} AS `{$association}` + JOIN {$this->{$association.'_jointable'}} + ON {$this->{$association.'_jointable'}}. + {$this->{$association.'_foreignkey'}} = '$value2[id]' + AND {$this->{$association.'_jointable'}}. + {$this->{$association.'_associationforeignkey'}} = `{$association}` .id" .($manyToManyConditions? " WHERE {$manyToManyConditions}":null) .($manyToManyOrder? " ORDER BY {$manyToManyOrder}": null); - + } - + $manyToManySelect[$association] = $this->db->all($tmpSQL); } if( !empty($manyToManySelect[$association]) && is_array($manyToManySelect[$association])) @@ -1284,7 +1283,7 @@ class Model extends Object if(empty($newValue) && !empty($original)) { $originalCount = count($original); - for ($i = 0; $i< $originalCount; $i++) + for ($i = 0; $i< $originalCount; $i++) { $newValue[$i] = $original[$i]; } @@ -1292,7 +1291,7 @@ class Model extends Object elseif(!empty($original)) { $originalCount = count($original); - for ($i = 0; $i< $originalCount; $i++) + for ($i = 0; $i< $originalCount; $i++) { $newValue[$i] = array_merge($newValue[$i], $original[$i]); } @@ -1303,14 +1302,14 @@ class Model extends Object return $newValue; } } - + /** * Returns an array of all rows for given SQL statement. * * @param string $sql SQL query * @return array */ - function findBySql ($sql) + function findBySql ($sql) { $data = $this->db->all($sql); foreach ($data as $key => $value) @@ -1334,7 +1333,7 @@ class Model extends Object } /** - * Returns number of rows matching given SQL condition. + * Returns number of rows matching given SQL condition. * * @param string $conditions SQL conditions (WHERE clause conditions) * @return int Number of matching rows @@ -1352,7 +1351,7 @@ class Model extends Object * @param unknown_type $fields * @return unknown */ - function findAllThreaded ($conditions=null, $fields=null, $sort=null) + function findAllThreaded ($conditions=null, $fields=null, $sort=null) { return $this->_doThread(Model::findAll($conditions, $fields, $sort), null); } @@ -1360,25 +1359,25 @@ class Model extends Object /** * Enter description here... * - * @param unknown_type $data + * @param unknown_type $data * @param unknown_type $root NULL or id for root node of operation * @return array * @access private */ - function _doThread ($data, $root) + function _doThread ($data, $root) { $out = array(); - - for ($ii=0; $ii_doThread($data, $data[$ii]['id']): null; $out[] = $tmp; } } - + return $out; } @@ -1391,11 +1390,11 @@ class Model extends Object * @param unknown_type $value * @return array Array with keys "prev" and "next" that holds the id's */ - function findNeighbours ($conditions, $field, $value) + function findNeighbours ($conditions, $field, $value) { @list($prev) = Model::findAll($conditions." AND {$field} < '{$value}'", $field, "{$field} DESC", 1); @list($next) = Model::findAll($conditions." AND {$field} > '{$value}'", $field, "{$field} ASC", 1); - + $prev = isset($prev) ? $prev: false; $next = isset($next) ? $next: false; return array('prev'=>$prev, 'next'=>$next); @@ -1407,7 +1406,7 @@ class Model extends Object * @param string $sql SQL statement * @return array Resultset */ - function query ($sql) + function query ($sql) { return $this->db->query($sql); } @@ -1421,7 +1420,7 @@ class Model extends Object function validates ($data=null) { $errors = count($this->invalidFields($data? $data: $this->data)); - + return $errors == 0; } @@ -1431,7 +1430,7 @@ class Model extends Object * @param array $data Posted data * @return array Array of invalid fields */ - function invalidFields ($data=null) + function invalidFields ($data=null) { return $this->_invalidFields($data); } @@ -1439,11 +1438,11 @@ class Model extends Object /** * Returns an array of invalid fields. * - * @param array $data + * @param array $data * @return array Array of invalid fields * @access private */ - function _invalidFields ($data=null) + function _invalidFields ($data=null) { if (!isset($this->validate)) { @@ -1454,12 +1453,12 @@ class Model extends Object { return $this->validationErrors; } - + $data = ($data? $data: (isset($this->data)? $this->data: array())); $errors = array(); foreach ($data as $table => $field) { - foreach ($this->validate as $field_name=>$validator) + foreach ($this->validate as $field_name=>$validator) { if (isset($data[$table][$field_name]) && !preg_match($validator, $data[$table][$field_name])) { @@ -1470,27 +1469,27 @@ class Model extends Object return $errors; } } - - + + /** * This function determines whether or not a string is a foreign key * * @param string $field Returns true if the input string ends in "_id" * @return True if the field is a foreign key listed in the belongsTo array. */ - function isForeignKey( $field ) + function isForeignKey( $field ) { $foreignKeys = array(); - + if(!empty($this->_belongsToOther)) { - + foreach ($this->_belongsToOther as $rule) { - list($association, $model, $value) = $rule; - $foreignKeys[$this->{$model}->{$this->currentModel.'_foreignkey'}] = $this->{$model}->{$this->currentModel.'_foreignkey'}; + list($association, $model, $value) = $rule; + $foreignKeys[$this->{$association.'_foreignkey'}] = $this->{$association.'_foreignkey'}; } - } + } if( array_key_exists($field, $foreignKeys) ) { @@ -1498,7 +1497,7 @@ class Model extends Object } return false; } - + /** * Enter description here... * @@ -1516,7 +1515,7 @@ class Model extends Object // And if the display field does not exist in the table info structure, use the ID field. if( false == $this->hasField( $dispField ) ) - $dispField = 'id'; + $dispField = $this->tableId; return $dispField; } @@ -1528,32 +1527,7 @@ class Model extends Object */ function getLastInsertID() { - return $this->db->lastInsertId($this->table, 'id'); - } - -/** - * Enter description here... - * - * @param unknown_type $tableName - */ - function _throwMissingTable($tableName) - { - $error =& new Controller(); - $error->missingTable = $this->table; - call_user_func_array(array(&$error, 'missingTable'), $tableName); - exit; - } - -/** - * Enter description here... - * - */ - function _throwMissingConnection() - { - $error =& new Controller(); - $error->missingConnection = $this->name; - call_user_func_array(array(&$error, 'missingConnection'), null); - exit; + return $this->db->lastInsertId($this->table, $this->tableId); } } diff --git a/cake/libs/object.php b/cake/libs/object.php index 85fabf424..47571bcb5 100644 --- a/cake/libs/object.php +++ b/cake/libs/object.php @@ -4,7 +4,7 @@ /** * Object class, allowing __construct and __destruct in PHP4. * - * Also includes methods for logging and the special method RequestAction, + * Also includes methods for logging and the special method RequestAction, * to call other Controllers' Actions from anywhere. * * PHP versions 4 and 5 @@ -40,7 +40,7 @@ uses('log'); /** * Object class, allowing __construct and __destruct in PHP4. * - * Also includes methods for logging and the special method RequestAction, + * Also includes methods for logging and the special method RequestAction, * to call other Controllers' Actions from anywhere. * * @package cake @@ -98,7 +98,7 @@ class Object } /** - * Calls a controller's method from any location. + * Calls a controller's method from any location. * * @param string $url URL in the form of Cake URL ("/controller/method/parameter") * @param array $extra If array includes the key "render" it sets the AutoRender to true. @@ -112,12 +112,12 @@ class Object } else { - $extra['render'] = 1; + $extra['render'] = 1; } $dispatcher =& new Dispatcher(); return $dispatcher->dispatch($url, $extra); } - + /** * API for logging events. * @@ -139,6 +139,123 @@ class Object return $this->_log->write('error', $msg); } } + +/** + * Renders the Missing Controller web page. + * + */ + function missingController() + { + $this->autoLayout = true; + $this->pageTitle = 'Missing Controller'; + $this->render('../errors/missingController'); + exit(); + } + +/** + * Renders the Missing Action web page. + * + */ + function missingAction() + { + $this->autoLayout = true; + $this->pageTitle = 'Missing Method in Controller'; + $this->render('../errors/missingAction'); + exit(); + } + +/** + * Renders the Private Action web page. + * + */ + function privateAction() + { + $this->autoLayout = true; + $this->pageTitle = 'Trying to access private method in class'; + $this->render('../errors/privateAction'); + exit(); + } + +/** + * Renders the Missing View web page. + * + */ + function missingView() + { + //We are simulating action call below, this is not a filename! + $this->autoLayout = true; + $this->missingView = $this->name; + $this->pageTitle = 'Missing View'; + $this->render('../errors/missingView'); + } + +/** + * Renders the Missing Database web page. + * + */ + function missingDatabase() + { + $this->autoLayout = true; + $this->pageTitle = 'Scaffold Missing Database Connection'; + $this->render('../errors/missingScaffolddb'); + exit(); + } + +/** + * Renders the Missing Table web page. + * + */ + function missingTable($tableName) + { + $error =& new Controller(); + $error->constructClasses(); + $error->missingTable = $this->table; + $error->missingTableName = $tableName; + $error->pageTitle = 'Missing Database Table'; + $error->render('../errors/missingTable'); + exit(); + } + +/** + * Renders the Missing Table web page. + * + */ + function missingConnection() + { + $error =& new Controller(); + $error->constructClasses(); + $error->missingConnection = $this->name; + $error->autoLayout = true; + $error->pageTitle = 'Missing Database Connection'; + $error->render('../errors/missingDatabase'); + exit(); + } + +/** + * Renders the Missing Helper file web page. + * + */ + function missingHelperFile($file) + { + $this->missingHelperFile = $file; + $this->missingHelperClass = Inflector::camelize($file) . "Helper"; + $this->pageTitle = 'Missing Helper File'; + $this->render('../errors/missingHelperFile'); + exit(); + } + +/** + * Renders the Missing Helper class web page. + * + */ + function missingHelperClass($class) + { + $this->missingHelperClass = Inflector::camelize($class) . "Helper"; + $this->missingHelperFile = Inflector::underscore($class); + $this->pageTitle = 'Missing Helper Class'; + $this->render('../errors/missingHelperClass'); + exit(); + } } ?> \ No newline at end of file diff --git a/cake/libs/router.php b/cake/libs/router.php index 2e1a670e3..01d1274b4 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -149,6 +149,16 @@ class Router extends Object { $this->connect('/bare/:controller/:action/*', array('bare'=>'1')); $this->connect('/ajax/:controller/:action/*', array('bare'=>'1')); + + if(defined('WEBSERVICES') && WEBSERVICES == 'on' ) + { + $this->connect('/rest/:controller/:action/*', array('webservices'=>'Rest')); + $this->connect('/rss/:controller/:action/*', array('webservices'=>'Rss')); + $this->connect('/soap/:controller/:action/*', array('webservices'=>'Soap')); + $this->connect('/xml/:controller/:action/*', array('webservices'=>'Xml')); + $this->connect('/xmlrpc/:controller/:action/*', array('webservices'=>'XmlRpc')); + } + $this->routes[] = $default_route; foreach ($this->routes as $route) diff --git a/cake/libs/session.php b/cake/libs/session.php index 631c90bb3..d78f05876 100644 --- a/cake/libs/session.php +++ b/cake/libs/session.php @@ -31,7 +31,7 @@ /** * Short description for file. - * + * * Long description for file * * @package cake @@ -82,7 +82,7 @@ class CakeSession extends Object * @var unknown_type */ var $sessionId = null; - + /** * Enter description here... * @@ -96,7 +96,7 @@ class CakeSession extends Object { $this->host = substr($this->host,0, strpos($this->host, ':')); } - + if (empty($this->path)) { $dispatcher =& new Dispatcher(); @@ -110,8 +110,8 @@ class CakeSession extends Object { $this->path = '/'; } - - $this->ip = $_SERVER['REMOTE_ADDR']; + + $this->ip = !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; $this->userAgent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; $this->_initSession(); $this->_begin(); @@ -129,7 +129,7 @@ class CakeSession extends Object $expression = "return isset(".$this->_sessionVarNames($name).");"; return eval($expression); } - + /** * Enter description here... * @@ -147,7 +147,7 @@ class CakeSession extends Object $this->_setError(2, "$name doesn't exist"); return false; } - + /** * Enter description here... * @@ -165,7 +165,7 @@ class CakeSession extends Object return $this->error[$errorNumber]; } } - + /** * Enter description here... * @@ -173,7 +173,7 @@ class CakeSession extends Object */ function getLastError() { - + if($this->lastError) { return $this->getError($this->lastError); @@ -183,7 +183,7 @@ class CakeSession extends Object return false; } } - + /** * Enter description here... * @@ -191,10 +191,10 @@ class CakeSession extends Object */ function isValid() { - + return $this->valid; } - + /** * Enter description here... * @@ -207,7 +207,7 @@ class CakeSession extends Object { return $this->returnSessionVars(); } - + if($this->checkSessionVar($name)) { $result = eval("return ".$this->_sessionVarNames($name).";"); @@ -216,7 +216,7 @@ class CakeSession extends Object $this->_setError(2, "$name doesn't exist"); return false; } - + /** * Enter description here... * @@ -225,7 +225,7 @@ class CakeSession extends Object */ function returnSessionVars() { - + if(!empty($_SESSION)) { $result = eval("return ".$_SESSION.";"); @@ -234,20 +234,20 @@ class CakeSession extends Object $this->_setError(2, "No Session vars set"); return false; } - + /** - * Enter description here... + * Enter description here... * * @param unknown_type $name * @param unknown_type $value */ function writeSessionVar($name, $value) { - + $expression = $this->_sessionVarNames($name); $expression .= " = \$value;"; eval($expression); - } + } /** * Enter description here... @@ -256,17 +256,17 @@ class CakeSession extends Object */ function _begin() { - + if (function_exists('session_write_close')) { session_write_close(); } - - session_cache_limiter("must-revalidate"); + + session_cache_limiter("must-revalidate"); session_start(); $this->_new(); } - + /** * Enter description here... * @@ -279,7 +279,7 @@ class CakeSession extends Object echo ""; die(); } - + /** * Enter description here... * @@ -292,7 +292,7 @@ class CakeSession extends Object echo ""; die(); } - + /** * Enter description here... * @@ -305,7 +305,7 @@ class CakeSession extends Object echo ""; die(); } - + /** * Enter description here... * @@ -313,7 +313,7 @@ class CakeSession extends Object */ function _initSession() { - + switch (CAKE_SECURITY) { case 'high': @@ -328,7 +328,7 @@ class CakeSession extends Object $this->cookieLifeTime = 788940000; break; } - + switch (CAKE_SESSION_SAVE) { case 'cake': @@ -371,7 +371,7 @@ class CakeSession extends Object ini_set('session.gc_maxlifetime', Security::inactiveMins() * 60); break; default : - $config = CONFIGS.CAKE_SESSION_SAVE.'.php.'; + $config = CONFIGS.CAKE_SESSION_SAVE.'.php'; if(is_file($config)) { require_once($config); @@ -382,22 +382,22 @@ class CakeSession extends Object ini_set('session.cookie_lifetime', $this->cookieLifeTime); ini_set('session.cookie_path', $this->path); ini_set('session.gc_probability', 1); - ini_set('session.gc_maxlifetime', Security::inactiveMins() * 60); - } + ini_set('session.gc_maxlifetime', Security::inactiveMins() * 60); + } break; } - + } - + /** * Enter description here... * * @access private - * + * */ function _new() { - + if(!ereg("proxy\.aol\.com$", gethostbyaddr($this->ip))) { if($this->readSessionVar("Config")) @@ -415,7 +415,7 @@ class CakeSession extends Object else { srand((double)microtime() * 1000000); - $this->writeSessionVar('Config.rand', rand()); + $this->writeSessionVar('Config.rand', rand()); $this->writeSessionVar("Config.ip", $this->ip); $this->writeSessionVar("Config.userAgent", $this->userAgent); $this->valid = true; @@ -426,25 +426,25 @@ class CakeSession extends Object if(!$this->readSessionVar("Config")) { srand((double)microtime() * 1000000); - $this->writeSessionVar('Config.rand', rand()); + $this->writeSessionVar('Config.rand', rand()); $this->writeSessionVar("Config.ip", $this->ip); $this->writeSessionVar("Config.userAgent", $this->userAgent); } $this->valid = true; } - + if(CAKE_SECURITY == 'high') { $this->_regenerateId(); } header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); } - + /** * Enter description here... * * @access private - * + * */ function _open() { @@ -453,12 +453,12 @@ class CakeSession extends Object echo ""; die(); } - + /** * Enter description here... * * @access private - * + * */ function _read() { @@ -467,18 +467,18 @@ class CakeSession extends Object echo ""; die(); } - + /** * Enter description here... * * * @access private - * + * */ function _regenerateId() { - + $oldSessionId = session_id(); session_regenerate_id(); $newSessid = session_id(); @@ -504,13 +504,13 @@ class CakeSession extends Object * Enter description here... * * @access private - * + * */ function _renew() { $this->_regenerateId(); } - + /** * Enter description here... * @@ -520,7 +520,7 @@ class CakeSession extends Object */ function _sessionVarNames($name) { - + if(is_string($name)) { if(strpos($name, ".")) @@ -532,7 +532,7 @@ class CakeSession extends Object $names = array($name); } $expression = $expression = "\$_SESSION"; - + foreach($names as $item) { $expression .= is_numeric($item) ? "[$item]" : "['$item']"; @@ -542,7 +542,7 @@ class CakeSession extends Object $this->setError(3, "$name is not a string"); return false; } - + /** * Enter description here... * @@ -552,16 +552,16 @@ class CakeSession extends Object */ function _setError($errorNumber, $errorMessage) { - + if($this->error === false) { $this->error = array(); } - + $this->error[$errorNumber] = $errorMessage; $this->lastError = $errorNumber; } - + /** * Enter description here... * @@ -574,5 +574,5 @@ class CakeSession extends Object echo ""; die(); } -} +} ?> \ No newline at end of file diff --git a/cake/libs/validators.php b/cake/libs/validators.php index 9521b46b9..bd10ccd49 100644 --- a/cake/libs/validators.php +++ b/cake/libs/validators.php @@ -44,7 +44,7 @@ define('VALID_NUMBER', '/^[0-9]+$/'); /** * A valid email address. */ -define('VALID_EMAIL', '/^([a-z0-9][a-z0-9_\-\.\+]*)@([a-z0-9][a-z0-9\.\-]{0,63}\.([a-z][a-z]|com|org|net|biz|info|name|net|pro|aero|coop|museum))$/i'); +define('VALID_EMAIL', '/\\A(?:^([a-z0-9][a-z0-9_\\-\\.\\+]*)@([a-z0-9][a-z0-9\\.\\-]{0,63}\\.(com|org|net|biz|info|name|net|pro|aero|coop|museum|[a-z]{2,4}))$)\\z/i'); /** * A valid year (1000-2999). diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index cda292488..b0e801509 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -35,7 +35,7 @@ uses('object', DS.'view'.DS.'helper'); /** - * View, the V in the MVC triad. + * View, the V in the MVC triad. * * Class holding methods for displaying presentation data. * @@ -167,7 +167,7 @@ class View extends Object * @var boolean */ var $hasRendered = null; - + /** * Enter description here... * @@ -200,6 +200,7 @@ class View extends Object $this->params =& $this->controller->params; $this->data =& $this->controller->data; $this->displayFields =& $this->controller->displayFields; + $this->webservices =& $this->controller->webservices; } /** @@ -219,7 +220,7 @@ class View extends Object /** - * Renders view for given action and layout. If $file is given, that is used + * Renders view for given action and layout. If $file is given, that is used * for a view filename (e.g. customFunkyView.thtml). * * @param string $action Name of action to render for @@ -352,7 +353,7 @@ class View extends Object * Renders a piece of PHP with provided parameters and returns HTML, XML, or any other string. * * This realizes the concept of Elements, (or "partial layouts") - * and the $params array is used to send data to be used in the + * and the $params array is used to send data to be used in the * Element. * * @param string $name Name of template file in the /app/views/elements/ folder @@ -429,18 +430,6 @@ class View extends Object print ($this->_render(VIEWS.'layouts/error.thtml', array('code'=>$code,'name'=>$name,'message'=>$message))); } -/** - * Renders the Missing View web page. - * - */ - function missingView() - { - //We are simulating action call below, this is not a filename! - $this->autoLayout = true; - $this->missingView = $this->name; - $this->render('../errors/missingView'); - } - /************************************************************************** * Private methods. @@ -457,28 +446,36 @@ class View extends Object function _getViewFileName($action) { $action = Inflector::underscore($action); - - $viewFileName = VIEWS.$this->viewPath.DS.$action.'.thtml'; - - if(file_exists(VIEWS.$this->viewPath.DS.$action.'.thtml')) + + if(!is_null($this->webservices)) { - $viewFileName = VIEWS.$this->viewPath.DS.$action.'.thtml'; + $type = strtolower($this->webservices).DS; } - elseif(file_exists(LIBS.'view'.DS.'templates'.DS.'errors'.DS.$action.'.thtml')) + else { - $viewFileName = LIBS.'view'.DS.'templates'.DS.'errors'.DS.$action.'.thtml'; + $type = null; } - elseif(file_exists(LIBS.'view'.DS.'templates'.DS.$this->viewPath.DS.$action.'.thtml')) + $viewFileName = VIEWS.$this->viewPath.DS.$type.$action.'.thtml'; + + if(file_exists(VIEWS.$this->viewPath.DS.$type.$action.'.thtml')) { - $viewFileName = LIBS.'view'.DS.'templates'.DS.$this->viewPath.DS.$action.'.thtml'; + $viewFileName = VIEWS.$this->viewPath.DS.$type.$action.'.thtml'; } - - + elseif(file_exists(LIBS.'view'.DS.'templates'.DS.'errors'.DS.$type.$action.'.thtml')) + { + $viewFileName = LIBS.'view'.DS.'templates'.DS.'errors'.DS.$type.$action.'.thtml'; + } + elseif(file_exists(LIBS.'view'.DS.'templates'.DS.$this->viewPath.DS.$type.$action.'.thtml')) + { + $viewFileName = LIBS.'view'.DS.'templates'.DS.$this->viewPath.DS.$type.$action.'.thtml'; + } + + $viewPath = explode(DS, $viewFileName); $i = array_search('..', $viewPath); unset($viewPath[$i-1]); unset($viewPath[$i]); - + $return = '/'.implode('/', $viewPath); return $return; } @@ -489,21 +486,31 @@ class View extends Object * @return string Filename for layout file (.thtml). * @access private */ - function _getLayoutFileName() - { - if(file_exists(LAYOUTS."{$this->layout}.thtml")) + function _getLayoutFileName() + { + if(!is_null($this->webservices)) + { + $type = strtolower($this->webservices).DS; + } + else + { + $type = null; + } + $layoutFileName = LAYOUTS.$type."{$this->layout}.thtml"; + + if(file_exists(LAYOUTS.$type."{$this->layout}.thtml")) { - $layoutFileName = LAYOUTS."{$this->layout}.thtml"; + $layoutFileName = LAYOUTS.$type."{$this->layout}.thtml"; } - else if(file_exists(LIBS.'view'.DS.'templates'.DS."layouts".DS."{$this->layout}.thtml")) + else if(file_exists(LIBS.'view'.DS.'templates'.DS."layouts".DS.$type."{$this->layout}.thtml")) { - $layoutFileName = LIBS.'view'.DS.'templates'.DS."layouts".DS."{$this->layout}.thtml"; + $layoutFileName = LIBS.'view'.DS.'templates'.DS."layouts".DS.$type."{$this->layout}.thtml"; } return $layoutFileName; } - + /** - * Renders and returns output for given view filename with its + * Renders and returns output for given view filename with its * array of data. * * @param string $___viewFn Filename of the view @@ -521,12 +528,12 @@ class View extends Object { $loadedHelpers = array(); $loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers); - + foreach(array_keys($loadedHelpers) as $helper) { $replace = strtolower(substr($helper, 0, 1)); $camelBackedHelper = preg_replace('/\\w/', $replace, $helper, 1); - + ${$camelBackedHelper} =& $loadedHelpers[$helper]; if(isset(${$camelBackedHelper}->helpers) && is_array(${$camelBackedHelper}->helpers)) { @@ -560,13 +567,13 @@ class View extends Object return $out; } - + /** * Loads helpers, with their dependencies. * * @param array $loaded List of helpers that are already loaded. * @param array $helpers List of helpers to load. - * @return array + * @return array */ function &_loadHelpers(&$loaded, $helpers) { @@ -575,7 +582,7 @@ class View extends Object if(in_array($helper, array_keys($loaded)) !== true) { $helperFn = Inflector::underscore($helper).'.php'; - + if(file_exists(HELPERS.$helperFn)) { $helperFn = HELPERS.$helperFn; @@ -584,7 +591,7 @@ class View extends Object { $helperFn = LIBS.'view'.DS.'helpers'.DS.$helperFn; } - + $helperCn = $helper.'Helper'; $replace = strtolower(substr($helper, 0, 1)); $camelBackedHelper = preg_replace('/\\w/', $replace, $helper, 1); @@ -601,7 +608,7 @@ class View extends Object ${$camelBackedHelper}->params = $this->params; ${$camelBackedHelper}->action = $this->action; ${$camelBackedHelper}->data = $this->data; - + if(!empty($this->validationErrors)) { ${$camelBackedHelper}->validationErrors = $this->validationErrors; @@ -633,7 +640,7 @@ class View extends Object } } } - + return $loaded; } }