diff --git a/app/index.php b/app/index.php index d2f4a2293..97914ce75 100644 --- a/app/index.php +++ b/app/index.php @@ -26,5 +26,5 @@ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ -include_once('webroot'.DIRECTORY_SEPARATOR.'index.php'); +require_once 'webroot'.DIRECTORY_SEPARATOR.'index.php'; ?> \ No newline at end of file diff --git a/app/webroot/index.php b/app/webroot/index.php index 2b2dcdafc..897f4ff08 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -49,7 +49,7 @@ if (!defined('ROOT')) * Enter description here... * */ - define('ROOT', dirname(dirname(dirname(__FILE__))).DS); + define('ROOT', dirname(dirname(dirname(__FILE__))).DS); } if (!defined('APP_DIR')) @@ -66,9 +66,9 @@ if (!defined('WEBROOT_DIR')) /** * Configuration, directory layout and standard libraries */ +require_once ROOT.'cake'.DS.'basics.php'; require_once ROOT.APP_DIR.DS.'config'.DS.'core.php'; require_once ROOT.'cake'.DS.'config'.DS.'paths.php'; -require_once CAKE.'basics.php'; require_once LIBS.'log.php'; require_once LIBS.'object.php'; require_once LIBS.'session.php'; diff --git a/cake/libs/controller/components/acl.php b/cake/libs/controller/components/acl.php index fb65ef352..f0bdb44c9 100644 --- a/cake/libs/controller/components/acl.php +++ b/cake/libs/controller/components/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 diff --git a/cake/libs/controller/components/acl_base.php b/cake/libs/controller/components/acl_base.php index 16582c667..cf0d584fb 100644 --- a/cake/libs/controller/components/acl_base.php +++ b/cake/libs/controller/components/acl_base.php @@ -72,8 +72,10 @@ class AclBase * @param unknown_type $aco * @param unknown_type $action */ - function check($aro, $aco, $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 92953a969..5656f1393 100644 --- a/cake/libs/controller/components/dbacl/db_acl.php +++ b/cake/libs/controller/components/dbacl/db_acl.php @@ -87,6 +87,11 @@ class DB_ACL extends AclBase trigger_error('ACO permissions key "' . $action . '" does not exist in DB_ACL::check()', E_USER_ERROR); } + if($aroPath == false || $aroPath == null || count($aroPath) == 0 || $tmpAcoPath == false || $tmpAcoPath == null || count($tmpAcoPath) == 0) + { + return null; + } + foreach($tmpAcoPath as $a) { $acoPath[] = $a['Aco']['id']; @@ -111,10 +116,10 @@ class DB_ACL extends AclBase { if(isset($perm['aros_acos'])) { - if($perm['aros_acos'][$key] != 1) - { - return false; - } + if($perm['aros_acos'][$key] != 1) + { + return false; + } } } return true; @@ -151,6 +156,13 @@ class DB_ACL extends AclBase $permKeys = $this->_getAcoKeys($Perms->loadInfo()); $save = array(); + + if($perms == false) + { + // One of the nodes does not exist + return false; + } + if(isset($perms[0])) { $save = $perms[0]['aros_acos']; @@ -173,6 +185,7 @@ class DB_ACL extends AclBase else { // Raise an error + return false; } } @@ -301,13 +314,18 @@ class DB_ACL extends AclBase $qAro = (is_string($aro) ? "alias = '" . addslashes($aro) . "'" : "user_id = {$aro}"); $qAco = (is_string($aco) ? "alias = '" . addslashes($aco) . "'" : "object_id = {$aco}"); - + $obj = array(); $obj['Aro'] = $Aro->find($qAro); $obj['Aco'] = $Aco->find($qAco); $obj['Aro'] = $obj['Aro']['Aro']; $obj['Aco'] = $obj['Aco']['Aco']; + if($obj['Aro'] == null || count($obj['Aro']) == 0 || $obj['Aco'] == null || count($obj['Aco']) == 0) + { + return false; + } + return array( 'aro' => $obj['Aro']['id'], 'aco' => $obj['Aco']['id'], diff --git a/cake/libs/controller/components/dbacl/db_acl.sql b/cake/libs/controller/components/dbacl/db_acl.sql index 2b218248e..ec986a2ae 100644 --- a/cake/libs/controller/components/dbacl/db_acl.sql +++ b/cake/libs/controller/components/dbacl/db_acl.sql @@ -1,6 +1,7 @@ CREATE TABLE `acos` ( `id` int(11) NOT NULL auto_increment, + `model` varchar(255) NOT NULL default '', `object_id` int(11) default NULL, `alias` varchar(255) NOT NULL default '', `lft` int(11) default NULL, @@ -10,6 +11,7 @@ CREATE TABLE `acos` ( CREATE TABLE `aros` ( `id` int(11) NOT NULL auto_increment, + `model` varchar(255) NOT NULL default '', `user_id` int(11) default NULL, `alias` varchar(255) NOT NULL default '', `lft` int(11) default NULL, diff --git a/cake/libs/controller/components/dbacl/models/aclnode.php b/cake/libs/controller/components/dbacl/models/aclnode.php index 066c23b53..fd332368c 100644 --- a/cake/libs/controller/components/dbacl/models/aclnode.php +++ b/cake/libs/controller/components/dbacl/models/aclnode.php @@ -58,29 +58,36 @@ class AclNode extends AppModel * Enter description here... * */ - function __construct() + function __construct($object = null, $parent = null) { parent::__construct(); $this->__setTable(); + if($object != null) + { + $this->create($object, $parent); + } + exit(); } /** * Enter description here... * - * @param unknown_type $link_id - * @param unknown_type $parent_id - * @param unknown_type $alias + * @param unknown_type $object A new ACL object. This can be a string for alias-based ACL, or a Model for object-based ACL + * @param unknown_type $parent The parent object * @return unknown */ - function create($link_id = 0, $parent_id = null, $alias = '') + function create($object = null, $parent = null) { - parent::create(); - if (strtolower(get_class($this)) == "aclnode") { trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR); return NULL; } + parent::create(); + + pr($this->__dataVars()); + exit(); + extract($this->__dataVars()); if($parent_id == null || $parent_id === 0) @@ -208,10 +215,10 @@ class AclNode extends AppModel } /** - * Enter description here... + * The path to a node as an array, where the first element of the array is at the root of the tree, and the last element is the requested node * - * @param unknown_type $id - * @return unknown + * @param mixed $id + * @return array */ function getPath($id) { @@ -223,14 +230,18 @@ class AclNode extends AppModel extract($this->__dataVars()); $item = $this->find($this->_resolveID($id, $secondary_id)); + if($item == null || count($item) == 0) + { + return null; + } return $this->findAll("lft <= {$item[$class]['lft']} and rght >= {$item[$class]['rght']}"); } /** - * Enter description here... + * Gets the child nodes of a specified element * - * @param unknown_type $id - * @return unknown + * @param mixed $id + * @return array */ function getChildren($id) { @@ -246,32 +257,57 @@ class AclNode extends AppModel } /** - * Enter description here... + * Gets a reference to a node object * - * @param unknown_type $id + * @param unknown_type $obj * @param unknown_type $fKey * @return unknown */ - function _resolveID($id, $fKey) + function _resolveID($obj, $fKey) { + extract($this->__dataVars()); + if(is_object($obj)) + { + if(isset($obj->id) && isset($obj->name)) + { + return "model = '{$obj->name}' and {$secondary_id} = {$obj->id}"; + } + return null; + } + else if(is_array($obj)) + { + $keys = array_keys($obj); + $key1 = $keys[0]; + if(is_string($key1) && is_array($obj[$key1]) && isset($obj[$key1]['id'])) + { + return "model = '{$key1}' and {$secondary_id} = {$obj[$key1]['id']}"; + } + return null; + } + else if(is_string($obj)) + { + $path = explode('/', $obj); + + } $key = (is_string($id) ? 'alias' : $fKey); $val = (is_string($id) ? '"' . addslashes($id) . '"' : $id); return "{$key} = {$val}"; } /** - * Enter description here... + * Private method: modifies the left and right values of affected nodes in a tree when a node is added or removed * - * @param unknown_type $table - * @param unknown_type $dir - * @param unknown_type $lft - * @param unknown_type $rght + * @param string $table aros or acos, depending on the tree to be modified + * @param int $dir The direction in which to shift the nodes + * @param int $lft The left position of the node being added or removed + * @param int $rght The right position of the node being added or removed */ function _syncTable($table, $dir, $lft, $rght) { $shift = ($dir == 2 ? 1 : 2); - $this->db->query("UPDATE $table SET rght = rght " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE rght > " . $rght); - $this->db->query("UPDATE $table SET lft = lft " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE lft > " . $lft); + $table = strtolower($table); + $this->db->query("UPDATE {$table} SET rght = rght " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE rght > " . $rght); + $this->db->query("UPDATE {$table} SET lft = lft " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE lft > " . $lft); } /** diff --git a/index.php b/index.php index 2b8fbb9db..68008c797 100644 --- a/index.php +++ b/index.php @@ -39,9 +39,9 @@ define ('APP_DIR', 'app'); define ('DS', DIRECTORY_SEPARATOR); define ('ROOT', dirname(__FILE__).DS); +require_once ROOT.'cake'.DS.'basics.php'; require_once ROOT.APP_DIR.DS.'config'.DS.'core.php'; require_once ROOT.'cake'.DS.'config'.DS.'paths.php'; -require_once CAKE.'basics.php'; $uri = setUri(); @@ -50,24 +50,26 @@ $uri = setUri(); * As mod_rewrite (or .htaccess files) is not working, we need to take care * of what would normally be rewritten, i.e. the static files in /public */ - if ($uri === '/' || $uri === '/index.php') - { - $_GET['url'] = '/'; - include_once (ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php'); - } - else - { - $elements = explode('/index.php', $uri); - if(!empty($elements[1])) - { - $path = $elements[1]; - } - else - { - $path = '/'; - } - $_GET['url'] = $path; +if ($uri === '/' || $uri === '/index.php') +{ + $_GET['url'] = '/'; + require_once ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php'; +} +else +{ + $elements = explode('/index.php', $uri); - include_once (ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php'); - } + if(!empty($elements[1])) + { + $path = $elements[1]; + } + else + { + $path = '/'; + } + + $_GET['url'] = $path; + + require_once ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php'; +} ?> \ No newline at end of file