Renaming branched version directory

git-svn-id: https://svn.cakephp.org/repo/branches/1.1.x.x@3085 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-06-14 18:02:37 +00:00
parent e5c074a0dc
commit 9d19dee879
45 changed files with 2935 additions and 2406 deletions

View file

@ -36,110 +36,102 @@
* @package cake
* @subpackage cake.cake.libs.controller.components
*/
class AclComponent extends Object{
var $_instance = null;
var $controller = true;
class AclComponent extends Object {
var $_instance = null;
var $controller = true;
/**
* Constructor. Will return an instance of the correct ACL class.
*
*/
function __construct() {
$this->getACL();
}
function __construct() {
$this->getACL();
}
/**
* Static function used to gain an instance of the correct ACL class.
*
* @return MyACL
*/
function &getACL() {
if ($this->_instance == null) {
uses('controller' . DS . 'components' . DS . ACL_FILENAME);
$classname =ACL_CLASSNAME;
$this->_instance=new $classname;
}
return $this->_instance;
}
function &getACL() {
if ($this->_instance == null) {
uses('controller' . DS . 'components' . DS . ACL_FILENAME);
$classname = ACL_CLASSNAME;
$this->_instance = new $classname;
}
return $this->_instance;
}
/**
* Empty class defintion, to be overridden in subclasses.
*
*/
function _initACL() {
}
function _initACL() {
}
/**
* Pass-thru function for ACL check instance.
*
* @return boolean
*/
function check($aro, $aco, $action = "*") {
return $this->_instance->check($aro, $aco, $action);
}
function check($aro, $aco, $action = "*") {
return $this->_instance->check($aro, $aco, $action);
}
/**
* Pass-thru function for ACL allow instance.
*
* @return boolean
*/
function allow($aro, $aco, $action = "*") {
return $this->_instance->allow($aro, $aco, $action);
}
function allow($aro, $aco, $action = "*") {
return $this->_instance->allow($aro, $aco, $action);
}
/**
* Pass-thru function for ACL deny instance.
*
* @return boolean
*/
function deny($aro, $aco, $action = "*") {
return $this->_instance->deny($aro, $aco, $action);
}
function deny($aro, $aco, $action = "*") {
return $this->_instance->deny($aro, $aco, $action);
}
/**
* Pass-thru function for ACL inherit instance.
*
* @return boolean
*/
function inherit($aro, $aco, $action = "*") {
return $this->_instance->inherit($aro, $aco, $action);
}
function inherit($aro, $aco, $action = "*") {
return $this->_instance->inherit($aro, $aco, $action);
}
/**
* Pass-thru function for ACL grant instance.
*
* @return boolean
*/
function grant($aro, $aco, $action = "*") {
return $this->_instance->grant($aro, $aco, $action);
}
function grant($aro, $aco, $action = "*") {
return $this->_instance->grant($aro, $aco, $action);
}
/**
* Pass-thru function for ACL grant instance.
*
* @return boolean
*/
function revoke($aro, $aco, $action = "*") {
return $this->_instance->revoke($aro, $aco, $action);
}
function revoke($aro, $aco, $action = "*") {
return $this->_instance->revoke($aro, $aco, $action);
}
/**
* Pass-thru function for ACL getAro instance.
*
* @return Aro
*/
function getAro($id) {
return $this->_instance->getAro($id);
}
function getAro($id) {
return $this->_instance->getAro($id);
}
/**
* Pass-thru function for ACL getAco instance.
*
* @return Aco
*/
function getAco($id) {
return $this->_instance->getAco($id);
}
function getAco($id) {
return $this->_instance->getAco($id);
}
}
?>

View file

@ -29,7 +29,6 @@
*/
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');
uses('controller' . DS . 'components' . DS . 'dbacl' . DS . 'models' . DS . 'acoaction');
@ -43,15 +42,14 @@ uses('controller' . DS . 'components' . DS . 'dbacl' . DS . 'models' . DS . 'aro
* @subpackage cake.cake.libs.controller.components.dbacl
*/
class DB_ACL extends AclBase{
class DB_ACL extends AclBase {
/**
* Enter description here...
*
*/
function __construct() {
}
function __construct() {
}
/**
* Enter description here...
*
@ -60,200 +58,193 @@ class DB_ACL extends AclBase{
* @param unknown_type $action
* @return unknown
*/
function check($aro, $aco, $action = "*") {
$Perms=new ArosAco();
$Aro =new Aro();
$Aco =new Aco();
function check($aro, $aco, $action = "*") {
$Perms = new ArosAco();
$Aro = new Aro();
$Aco = new Aco();
if ($aro == null || $aco == null) {
return false;
}
if ($aro == null || $aco == null) {
return false;
}
$permKeys =$this->_getAcoKeys($Perms->loadInfo());
$aroPath =$Aro->getPath($aro);
$tmpAcoPath=$Aco->getPath($aco);
$acoPath=array();
$permKeys = $this->_getAcoKeys($Perms->loadInfo());
$aroPath = $Aro->getPath($aro);
$tmpAcoPath = $Aco->getPath($aco);
if ($action != '*' && !in_array('_' . $action, $permKeys)) {
trigger_error('ACO permissions key "' . $action . '" does not exist in DB_ACL::check()',
E_USER_NOTICE);
return false;
}
if ($tmpAcoPath === null) {
return false;
}
foreach($tmpAcoPath as $a) {
$acoPath[] = $a['Aco']['id'];
}
$acoPath = array();
for($i = count($aroPath) - 1; $i >= 0; $i--) {
$perms = $Perms->findAll(array('ArosAco.aro_id' => $aroPath[$i]['Aro']['id'],
'ArosAco.aco_id' => $acoPath), null,
'Aco.lft asc');
if ($action != '*' && !in_array('_' . $action, $permKeys)) {
trigger_error('ACO permissions key "' . $action . '" does not exist in DB_ACL::check()', E_USER_NOTICE);
return false;
}
if ($perms == null || count($perms) == 0) {
continue;
} else {
foreach($perms as $perm) {
if ($action == '*') {
// ARO must be cleared for ALL ACO actions
foreach($permKeys as $key) {
if (isset($perm['ArosAco'])) {
if ($perm['ArosAco'][$key] != 1) {
return false;
}
}
foreach($tmpAcoPath as $a) {
$acoPath[] = $a['Aco']['id'];
}
for($i = count($aroPath) - 1; $i >= 0; $i--) {
$perms = $Perms->findAll(array(
'ArosAco.aro_id' => $aroPath[$i]['Aro']['id'],
'ArosAco.aco_id' => $acoPath), null,
'Aco.lft asc'
);
if ($perms == null || count($perms) == 0) {
continue;
} else {
foreach($perms as $perm) {
if ($action == '*') {
// ARO must be cleared for ALL ACO actions
foreach($permKeys as $key) {
if (isset($perm['ArosAco'])) {
if ($perm['ArosAco'][$key] != 1) {
return false;
}
}
}
return true;
} else {
switch($perm['ArosAco']['_' . $action]) {
case -1:
return false;
case 0:
continue;
break;
case 1:
return true;
} else {
switch($perm['ArosAco']['_' . $action])
{
case -1: return false;
case 0:
continue;
break;
case 1: return true;
}
}
}
break;
}
}
}
}
return false;
}
}
}
return false;
}
/**
* Allow
*
* @return boolean
*/
function allow($aro, $aco, $action = "*", $value = 1) {
$Perms =new ArosAco();
$perms =$this->getAclLink($aro, $aco);
$permKeys=$this->_getAcoKeys($Perms->loadInfo());
$save=array();
function allow($aro, $aco, $action = "*", $value = 1) {
$Perms = new ArosAco();
$perms = $this->getAclLink($aro, $aco);
$permKeys = $this->_getAcoKeys($Perms->loadInfo());
$save = array();
if ($perms == false) {
trigger_error('DB_ACL::allow() - Invalid node', E_USER_WARNING);
if ($perms == false) {
trigger_error('DB_ACL::allow() - Invalid node', E_USER_WARNING);
return false;
}
if (isset($perms[0])) {
$save = $perms[0]['ArosAco'];
}
if ($action == "*") {
$permKeys = $this->_getAcoKeys($Perms->loadInfo());
foreach($permKeys as $key) {
$save[$key] = $value;
}
} else {
if (in_array('_' . $action, $permKeys)) {
$save['_' . $action] = $value;
} else {
trigger_error('DB_ACL::allow() - Invalid ACO action', E_USER_WARNING);
return false;
}
}
}
if (isset($perms[0])) {
$save = $perms[0]['ArosAco'];
}
if ($action == "*") {
$permKeys=$this->_getAcoKeys($Perms->loadInfo());
foreach($permKeys as $key) {
$save[$key] = $value;
}
} else {
if (in_array('_' . $action, $permKeys)) {
$save['_' . $action] = $value;
} else {
trigger_error('DB_ACL::allow() - Invalid ACO action', E_USER_WARNING);
return false;
}
}
$save['aro_id']=$perms['aro'];
$save['aco_id']=$perms['aco'];
if ($perms['link'] != null && count($perms['link']) > 0) {
$save['id'] = $perms['link'][0]['ArosAco']['id'];
}
return $Perms->save(array('ArosAco' => $save));
}
$save['aro_id'] = $perms['aro'];
$save['aco_id'] = $perms['aco'];
if ($perms['link'] != null && count($perms['link']) > 0) {
$save['id'] = $perms['link'][0]['ArosAco']['id'];
}
return $Perms->save(array('ArosAco' => $save));
}
/**
* Deny
*
* @return boolean
*/
function deny($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action, -1);
}
function deny($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action, -1);
}
/**
* Inherit
*
* @return boolean
*/
function inherit($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action, 0);
}
function inherit($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action, 0);
}
/**
* Allow alias
*
* @return boolean
*/
function grant($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action);
}
function grant($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action);
}
/**
* Deny alias
*
* @return boolean
*/
function revoke($aro, $aco, $action = "*") {
return $this->deny($aro, $aco, $action);
}
function revoke($aro, $aco, $action = "*") {
return $this->deny($aro, $aco, $action);
}
/**
* Get an ARO object from the given id or alias
*
* @param mixed $id
* @return Aro
*/
function getAro($id = null) {
return $this->__getObject($id, 'Aro');
}
function getAro($id = null) {
return $this->__getObject($id, 'Aro');
}
/**
* Get an ACO object from the given id or alias
*
* @param mixed $id
* @return Aco
*/
function getAco($id = null) {
return $this->__getObject($id, 'Aco');
}
function getAco($id = null) {
return $this->__getObject($id, 'Aco');
}
/**
* Privaate method
* Private method
*
*/
function __getObject($id = null, $object) {
if ($id == null) {
trigger_error('Null id provided in DB_ACL::get' . $object, E_USER_WARNING);
return null;
}
function __getObject($id = null, $object) {
if ($id == null) {
trigger_error('Null id provided in DB_ACL::get' . $object, E_USER_WARNING);
return null;
}
$obj=new $object;
$obj = new $object;
if (is_numeric($id)) {
$key='user_id';
if (is_numeric($id)) {
$key = 'user_id';
if ($object == 'Aco') {
$key = 'object_id';
}
if ($object == 'Aco') {
$key = 'object_id';
}
$conditions=array($object . '.' . $key => $id);
} else {
$conditions = array($object . '.alias' => $id);
}
$tmp =$obj->find($conditions);
$obj->id=$tmp[$object]['id'];
return $obj;
}
$conditions = array($object . '.' . $key => $id);
} else {
$conditions = array($object . '.alias' => $id);
}
$tmp = $obj->find($conditions);
$obj->id = $tmp[$object]['id'];
return $obj;
}
/**
* Get an array of access-control links between the given Aro and Aco
*
@ -261,45 +252,47 @@ class DB_ACL extends AclBase{
* @param mixed $aco
* @return array
*/
function getAclLink($aro, $aco) {
$Aro =new Aro();
$Aco =new Aco();
$Link =new ArosAco();
function getAclLink($aro, $aco) {
$Aro = new Aro();
$Aco = new Aco();
$Link = new ArosAco();
$obj=array();
$obj['Aro']=$Aro->find($Aro->_resolveID($aro));
$obj['Aco']=$Aco->find($Aco->_resolveID($aco));
$obj['Aro']=$obj['Aro']['Aro'];
$obj['Aco']=$obj['Aco']['Aco'];
$obj = array();
$obj['Aro'] = $Aro->find($Aro->_resolveID($aro));
$obj['Aco'] = $Aco->find($Aco->_resolveID($aco));
$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'],
'link' => $Link->findAll(array('ArosAco.aro_id' => $obj['Aro']['id'],
'ArosAco.aco_id' => $obj['Aco']['id'])));
}
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'],
'link' => $Link->findAll(array(
'ArosAco.aro_id' => $obj['Aro']['id'],
'ArosAco.aco_id' => $obj['Aco']['id']
))
);
}
/**
* Enter description here...
*
* @param unknown_type $keys
* @return unknown
*/
function _getAcoKeys($keys) {
$newKeys=array();
$keys=$keys->value;
function _getAcoKeys($keys) {
$newKeys = array();
$keys = $keys->value;
foreach($keys as $key) {
if ($key['name'] != 'id' && $key['name'] != 'aro_id' && $key['name'] != 'aco_id') {
$newKeys[] = $key['name'];
}
}
return $newKeys;
}
foreach($keys as $key) {
if ($key['name'] != 'id' && $key['name'] != 'aro_id' && $key['name'] != 'aco_id') {
$newKeys[] = $key['name'];
}
}
return $newKeys;
}
}
?>

View file

@ -69,10 +69,12 @@ class AclNode extends AppModel {
$parent = $parent[$class];
$this->_syncTable(1, $parent['lft'], $parent['lft']);
}
$return = $this->save(array($class => array($secondary_id => $link_id,
'alias' => $alias,
'lft' => $parent['lft'] + 1,
'rght' => $parent['lft'] + 2)));
$return = $this->save(array($class => array(
$secondary_id => $link_id,
'alias' => $alias,
'lft' => $parent['lft'] + 1,
'rght' => $parent['lft'] + 2
)));
$this->id = $this->getLastInsertID();
return $return;
}
@ -103,10 +105,8 @@ class AclNode extends AppModel {
$object = $object[$class];
$parent = $this->getParent($id);
if (($parent == null && $parent_id == null)
|| ($parent_id == $parent[$class][$secondary_id] && $parent_id != null)
|| ($parent_id == $parent[$class]['alias'] && $parent_id != null)) {
return false;
if (($parent == null && $parent_id == null) || ($parent_id == $parent[$class][$secondary_id] && $parent_id != null) || ($parent_id == $parent[$class]['alias'] && $parent_id != null)) {
return false;
}
if ($parent_id == null) {
@ -245,4 +245,5 @@ class AclNode extends AppModel {
return $vars;
}
}
?>

View file

@ -43,7 +43,7 @@ if (!class_exists('AppModel')) {
* @subpackage cake.cake.libs.controller.components.dbacl.models
*
*/
class AcoAction extends AppModel{
class AcoAction extends AppModel {
/**
* Enter description here...
*

View file

@ -37,7 +37,7 @@
* @subpackage cake.cake.libs.controller.components.dbacl.models
*
*/
class Aro extends AclNode{
class Aro extends AclNode {
/**
* Enter description here...

View file

@ -37,8 +37,13 @@
* @subpackage cake.cake.libs.controller.components.dbacl.models
*/
class ArosAco extends AppModel{
class ArosAco extends AppModel {
/**
* Enter description here...
*
* @var unknown_type
*/
var $cacheQueries = false;
/**
* Enter description here...
*

View file

@ -38,12 +38,17 @@ uses('controller/components/acl_base');
*/
class INI_ACL extends AclBase{
/**
* Array with configuration, parsed from ini file
*/
var $config = null;
/**
* The constructor must be overridden, as AclBase is abstract.
*
*/
function __construct() {
}
function __construct() {
}
/**
* Main ACL check function. Checks to see if the ARO (access request object) has access to the ACO (access control object).
@ -53,63 +58,66 @@ class INI_ACL extends AclBase{
* @param string $aco
* @return boolean
*/
function check($aro, $aco, $aco_action = null) {
$aclConfig=$this->readConfigFile(CONFIGS . 'acl.ini.php');
function check($aro, $aco, $aco_action = null) {
if ($this->config == null) {
$this->config = $this->readConfigFile(CONFIGS . 'acl.ini.php');
}
$aclConfig = $this->config;
//First, if the user is specifically denied, then DENY
if (isset($aclConfig[$aro]['deny'])) {
$userDenies=$this->arrayTrim(explode(",", $aclConfig[$aro]['deny']));
//First, if the user is specifically denied, then DENY
if (isset($aclConfig[$aro]['deny'])) {
$userDenies = $this->arrayTrim(explode(",", $aclConfig[$aro]['deny']));
if (array_search($aco, $userDenies)) {
//echo "User Denied!";
return false;
if (array_search($aco, $userDenies)) {
//echo "User Denied!";
return false;
}
}
//Second, if the user is specifically allowed, then ALLOW
if (isset($aclConfig[$aro]['allow'])) {
$userAllows = $this->arrayTrim(explode(",", $aclConfig[$aro]['allow']));
if (array_search($aco, $userAllows)) {
//echo "User Allowed!";
return true;
}
}
//Check group permissions
if (isset($aclConfig[$aro]['groups'])) {
$userGroups = $this->arrayTrim(explode(",", $aclConfig[$aro]['groups']));
foreach($userGroups as $group) {
//If such a group exists,
if (array_key_exists($group, $aclConfig)) {
//If the group is specifically denied, then DENY
if (isset($aclConfig[$group]['deny'])) {
$groupDenies=$this->arrayTrim(explode(",", $aclConfig[$group]['deny']));
if (array_search($aco, $groupDenies)) {
//echo("Group Denied!");
return false;
}
}
//If the group is specifically allowed, then ALLOW
if (isset($aclConfig[$group]['allow'])) {
$groupAllows = $this->arrayTrim(explode(",", $aclConfig[$group]['allow']));
if (array_search($aco, $groupAllows)) {
//echo("Group Allowed!");
return true;
}
}
}
}
}
}
//Second, if the user is specifically allowed, then ALLOW
if (isset($aclConfig[$aro]['allow'])) {
$userAllows=$this->arrayTrim(explode(",", $aclConfig[$aro]['allow']));
if (array_search($aco, $userAllows)) {
//echo "User Allowed!";
return true;
}
}
//Check group permissions
if (isset($aclConfig[$aro]['groups'])) {
$userGroups=$this->arrayTrim(explode(",", $aclConfig[$aro]['groups']));
foreach($userGroups as $group) {
//If such a group exists,
if (array_key_exists($group, $aclConfig)) {
//If the group is specifically denied, then DENY
if (isset($aclConfig[$group]['deny'])) {
$groupDenies=$this->arrayTrim(explode(",", $aclConfig[$group]['deny']));
if (array_search($aco, $groupDenies)) {
//echo("Group Denied!");
return false;
}
}
//If the group is specifically allowed, then ALLOW
if (isset($aclConfig[$group]['allow'])) {
$groupAllows=$this->arrayTrim(explode(",", $aclConfig[$group]['allow']));
if (array_search($aco, $groupAllows)) {
//echo("Group Allowed!");
return true;
}
}
}
}
}
//Default, DENY
//echo("DEFAULT: DENY.");
return false;
}
//Default, DENY
//echo("DEFAULT: DENY.");
return false;
}
/**
* Parses an INI file and returns an array that reflects the INI file's section structure. Double-quote friendly.
@ -117,42 +125,42 @@ class INI_ACL extends AclBase{
* @param string $fileName
* @return array
*/
function readConfigFile($fileName) {
$fileLineArray=file($fileName);
function readConfigFile($fileName) {
$fileLineArray = file($fileName);
foreach($fileLineArray as $fileLine) {
foreach($fileLineArray as $fileLine) {
$dataLine = trim($fileLine);
$firstChar=substr($dataLine, 0, 1);
$firstChar = substr($dataLine, 0, 1);
if ($firstChar != ';' && $dataLine != '') {
if ($firstChar == '[' && substr($dataLine, -1, 1) == ']') {
$sectionName = preg_replace('/[\[\]]/', '', $dataLine);
} else {
$delimiter=strpos($dataLine, '=');
if ($firstChar == '[' && substr($dataLine, -1, 1) == ']') {
$sectionName = preg_replace('/[\[\]]/', '', $dataLine);
} else {
$delimiter = strpos($dataLine, '=');
if ($delimiter > 0) {
$key =strtolower(trim(substr($dataLine, 0, $delimiter)));
$value=trim(substr($dataLine, $delimiter + 1));
if ($delimiter > 0) {
$key = strtolower(trim(substr($dataLine, 0, $delimiter)));
$value = trim(substr($dataLine, $delimiter + 1));
if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
$value = substr($value, 1, -1);
}
if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
$value = substr($value, 1, -1);
}
$iniSetting[$sectionName][$key]=stripcslashes($value);
} else {
if (!isset($sectionName)) {
$sectionName = '';
}
$iniSetting[$sectionName][$key]=stripcslashes($value);
} else {
if (!isset($sectionName)) {
$sectionName = '';
}
$iniSetting[$sectionName][strtolower(trim($dataLine))]='';
}
}
$iniSetting[$sectionName][strtolower(trim($dataLine))]='';
}
}
} else {
}
}
}
return $iniSetting;
}
return $iniSetting;
}
/**
* Removes trailing spaces on all array elements (to prepare for searching)
@ -160,16 +168,16 @@ class INI_ACL extends AclBase{
* @param array $array
* @return array
*/
function arrayTrim($array) {
foreach($array as $element) {
$element = trim($element);
}
function arrayTrim($array) {
foreach($array as $element) {
$element = trim($element);
}
//Adding this element keeps array_search from returning 0:
//0 is the first key, which may be correct, but 0 is interpreted as false.
//Adding this element makes all the keys be positive integers.
array_unshift($array, "");
return $array;
}
//Adding this element keeps array_search from returning 0:
//0 is the first key, which may be correct, but 0 is interpreted as false.
//Adding this element makes all the keys be positive integers.
array_unshift($array, "");
return $array;
}
}
?>

View file

@ -29,8 +29,8 @@
*/
if (!defined('REQUEST_MOBILE_UA')) {
define('REQUEST_MOBILE_UA',
'(AvantGo|BlackBerry|DoCoMo|NetFront|Nokia|PalmOS|PalmSource|portalmmm|Plucker|ReqwirelessWeb|SonyEricsson|Symbian|UP\.Browser|Windows CE|Xiino)');
define('REQUEST_MOBILE_UA',
'(AvantGo|BlackBerry|DoCoMo|NetFront|Nokia|PalmOS|PalmSource|portalmmm|Plucker|ReqwirelessWeb|SonyEricsson|Symbian|UP\.Browser|Windows CE|Xiino)');
}
/**
@ -41,159 +41,143 @@ if (!defined('REQUEST_MOBILE_UA')) {
*
*/
class RequestHandlerComponent extends Object{
var $controller = true;
var $controller = true;
var $ajaxLayout = 'ajax';
var $ajaxLayout = 'ajax';
var $disableStartup = false;
var $disableStartup = false;
var $__requestContent = array('js' => 'text/javascript',
'css' => 'text/css',
'html' => 'text/html',
'form' => 'application/x-www-form-urlencoded',
'file' => 'multipart/form-data',
'xhtml' => array('application/xhtml+xml',
'application/xhtml',
'text/xhtml'),
'xml' => array('application/xml',
'text/xml'),
'rss' => 'application/rss+xml',
'atom' => 'application/atom+xml');
var $__requestContent = array(
'js' => 'text/javascript',
'css' => 'text/css',
'html' => 'text/html',
'form' => 'application/x-www-form-urlencoded',
'file' => 'multipart/form-data',
'xhtml' => array('application/xhtml+xml', 'application/xhtml', 'text/xhtml'),
'xml' => array('application/xml', 'text/xml'),
'rss' => 'application/rss+xml',
'atom' => 'application/atom+xml'
);
var $__acceptTypes = array();
var $__acceptTypes = array();
function __construct() {
$this->__acceptTypes=explode(',', env('HTTP_ACCEPT'));
foreach($this->__acceptTypes as $i => $type) {
if (strpos($type, ';')) {
$type =explode(';', $type);
$this->__acceptTypes[$i]=$type[0];
}
}
parent::__construct();
}
function __construct() {
$this->__acceptTypes = explode(',', env('HTTP_ACCEPT'));
foreach($this->__acceptTypes as $i => $type) {
if (strpos($type, ';')) {
$type = explode(';', $type);
$this->__acceptTypes[$i] = $type[0];
}
}
parent::__construct();
}
/**
* Startup
*
* @param object A reference to the controller
* @return null
*/
function startup(&$controller) {
if ($this->disableStartup) {
return;
}
$this->setAjax($controller);
}
function startup(&$controller) {
if ($this->disableStartup) {
return;
}
$this->setAjax($controller);
}
/**
* Sets a controller's layout based on whether or not the current call is Ajax
*
* @param object The controller object
* @return null
*/
function setAjax(&$controller) {
if ($this->isAjax()) {
$controller->layout=$this->ajaxLayout;
// Add UTF-8 header for IE6 on XPsp2 bug
header ('Content-Type: text/html; charset=UTF-8');
}
}
function setAjax(&$controller) {
if ($this->isAjax()) {
$controller->layout=$this->ajaxLayout;
// Add UTF-8 header for IE6 on XPsp2 bug
header ('Content-Type: text/html; charset=UTF-8');
}
}
/**
* Returns true if the current call is from Ajax, false otherwise
*
* @return bool True if call is Ajax
*/
function isAjax() {
if (env('HTTP_X_REQUESTED_WITH') != null) {
return env('HTTP_X_REQUESTED_WITH') == "XMLHttpRequest";
} else {
return false;
}
}
function isAjax() {
if (env('HTTP_X_REQUESTED_WITH') != null) {
return env('HTTP_X_REQUESTED_WITH') == "XMLHttpRequest";
} else {
return false;
}
}
/**
* Returns true if the current call accepts an XML response, false otherwise
*
* @return bool True if client accepts an XML response
*/
function isXml() {
return $this->accepts('xml');
}
function isXml() {
return $this->accepts('xml');
}
/**
* Returns true if the current call accepts an RSS response, false otherwise
*
* @return bool True if client accepts an RSS response
*/
function isRss() {
return $this->accepts('rss');
}
function isRss() {
return $this->accepts('rss');
}
/**
* Returns true if the current call accepts an RSS response, false otherwise
*
* @return bool True if client accepts an RSS response
*/
function isAtom() {
return $this->accepts('atom');
}
function isAtom() {
return $this->accepts('atom');
}
/**
* Returns true if the current call a POST request
*
* @return bool True if call is a POST
*/
function isPost() {
return (strtolower(env('REQUEST_METHOD')) == 'post');
}
function isPost() {
return (strtolower(env('REQUEST_METHOD')) == 'post');
}
/**
* Returns true if the current call a PUT request
*
* @return bool True if call is a PUT
*/
function isPut() {
return (strtolower(env('REQUEST_METHOD')) == 'put');
}
function isPut() {
return (strtolower(env('REQUEST_METHOD')) == 'put');
}
/**
* Returns true if the current call a GET request
*
* @return bool True if call is a GET
*/
function isGet() {
return (strtolower(env('REQUEST_METHOD')) == 'get');
}
function isGet() {
return (strtolower(env('REQUEST_METHOD')) == 'get');
}
/**
* Returns true if the current call a DELETE request
*
* @return bool True if call is a DELETE
*/
function isDelete() {
return (strtolower(env('REQUEST_METHOD')) == 'delete');
}
function isDelete() {
return (strtolower(env('REQUEST_METHOD')) == 'delete');
}
/**
* Gets Prototype version if call is Ajax, otherwise empty string.
* The Prototype library sets a special "Prototype version" HTTP header.
*
* @return string Prototype version of component making Ajax call
*/
function getAjaxVersion() {
if (env('HTTP_X_PROTOTYPE_VERSION') != null) {
return env('HTTP_X_PROTOTYPE_VERSION');
}
return false;
}
function getAjaxVersion() {
if (env('HTTP_X_PROTOTYPE_VERSION') != null) {
return env('HTTP_X_PROTOTYPE_VERSION');
}
return false;
}
/**
* Adds/sets the Content-type(s) for the given name
*
@ -201,109 +185,96 @@ class RequestHandlerComponent extends Object{
* @param mixed $type The Content-type or array of Content-types assigned to the name
* @return void
*/
function setContent($name, $type) {
$this->__requestContent[$name]=$type;
}
function setContent($name, $type) {
$this->__requestContent[$name] = $type;
}
/**
* Gets the server name from which this request was referred
*
* @return string Server address
*/
function getReferrer() {
if (env('HTTP_HOST') != null) {
$sess_host = env('HTTP_HOST');
}
if (env('HTTP_X_FORWARDED_HOST') != null) {
$sess_host = env('HTTP_X_FORWARDED_HOST');
}
return trim(preg_replace('/:.*/', '', $sess_host));
}
function getReferrer() {
if (env('HTTP_HOST') != null) {
$sess_host = env('HTTP_HOST');
}
if (env('HTTP_X_FORWARDED_HOST') != null) {
$sess_host = env('HTTP_X_FORWARDED_HOST');
}
return trim(preg_replace('/:.*/', '', $sess_host));
}
/**
* Gets remote client IP
*
* @return string Client IP address
*/
function getClientIP() {
if (env('HTTP_X_FORWARDED_FOR') != null) {
$ipaddr = preg_replace('/,.*/', '', env('HTTP_X_FORWARDED_FOR'));
} else {
if (env('HTTP_CLIENT_IP') != null) {
$ipaddr = env('HTTP_CLIENT_IP');
} else {
$ipaddr = env('REMOTE_ADDR');
}
}
function getClientIP() {
if (env('HTTP_X_FORWARDED_FOR') != null) {
$ipaddr = preg_replace('/,.*/', '', env('HTTP_X_FORWARDED_FOR'));
} else {
if (env('HTTP_CLIENT_IP') != null) {
$ipaddr = env('HTTP_CLIENT_IP');
} else {
$ipaddr = env('REMOTE_ADDR');
}
}
if (env('HTTP_CLIENTADDRESS') != null) {
$tmpipaddr=env('HTTP_CLIENTADDRESS');
if (!empty($tmpipaddr)) {
$ipaddr = preg_replace('/,.*/', '', $tmpipaddr);
}
}
return trim($ipaddr);
}
if (env('HTTP_CLIENTADDRESS') != null) {
$tmpipaddr = env('HTTP_CLIENTADDRESS');
if (!empty($tmpipaddr)) {
$ipaddr = preg_replace('/,.*/', '', $tmpipaddr);
}
}
return trim($ipaddr);
}
/**
* Returns true if user agent string matches a mobile web browser
*
* @return bool True if user agent is a mobile web browser
*/
function isMobile() {
return (preg_match('/' . REQUEST_MOBILE_UA . '/i', env('HTTP_USER_AGENT')) > 0);
}
function isMobile() {
return (preg_match('/' . REQUEST_MOBILE_UA . '/i', env('HTTP_USER_AGENT')) > 0);
}
/**
* Strips extra whitespace from output
*
* @param string $str
*/
function stripWhitespace($str) {
$r=preg_replace('/[\n\r\t]+/', '', $str);
return preg_replace('/\s{2,}/', ' ', $r);
}
function stripWhitespace($str) {
$r = preg_replace('/[\n\r\t]+/', '', $str);
return preg_replace('/\s{2,}/', ' ', $r);
}
/**
* Strips image tags from output
*
* @param string $str
*/
function stripImages($str) {
$str=preg_replace('/(<a[^>]*>)(<img[^>]+alt=")([^"]*)("[^>]*>)(<\/a>)/i', '$1$3$5<br />', $str);
$str=preg_replace('/(<img[^>]+alt=")([^"]*)("[^>]*>)/i', '$2<br />', $str);
$str=preg_replace('/<img[^>]*>/i', '', $str);
return $str;
}
function stripImages($str) {
$str = preg_replace('/(<a[^>]*>)(<img[^>]+alt=")([^"]*)("[^>]*>)(<\/a>)/i', '$1$3$5<br />', $str);
$str = preg_replace('/(<img[^>]+alt=")([^"]*)("[^>]*>)/i', '$2<br />', $str);
$str = preg_replace('/<img[^>]*>/i', '', $str);
return $str;
}
/**
* Strips scripts and stylesheets from output
*
* @param string $str
*/
function stripScripts($str) {
return preg_replace(
'/(<link[^>]+rel="[^"]*stylesheet"[^>]*>|<img[^>]*>|style="[^"]*")|<script[^>]*>.*?<\/script>|<style[^>]*>.*?<\/style>|<!--.*?-->/i',
'',
$str);
}
function stripScripts($str) {
return preg_replace('/(<link[^>]+rel="[^"]*stylesheet"[^>]*>|<img[^>]*>|style="[^"]*")|<script[^>]*>.*?<\/script>|<style[^>]*>.*?<\/style>|<!--.*?-->/i', '', $str);
}
/**
* Strips extra whitespace, images, scripts and stylesheets from output
*
* @param string $str
*/
function stripAll($str) {
$str=$this->stripWhitespace($str);
$str=$this->stripImages($str);
$str=$this->stripScripts($str);
return $str;
}
function stripAll($str) {
$str = $this->stripWhitespace($str);
$str = $this->stripImages($str);
$str = $this->stripScripts($str);
return $str;
}
/**
* Strips the specified tags from output
*
@ -312,17 +283,16 @@ class RequestHandlerComponent extends Object{
* @param string $tag
* @param string ...
*/
function stripTags() {
$params=params(func_get_args());
$str =$params[0];
function stripTags() {
$params = params(func_get_args());
$str = $params[0];
for($i = 1; $i < count($params); $i++) {
$str = preg_replace('/<' . $params[$i] . '[^>]*>/i', '', $str);
$str =preg_replace('/<\/' . $params[$i] . '[^>]*>/i', '', $str);
}
return $str;
}
for($i = 1; $i < count($params); $i++) {
$str = preg_replace('/<' . $params[$i] . '[^>]*>/i', '', $str);
$str = preg_replace('/<\/' . $params[$i] . '[^>]*>/i', '', $str);
}
return $str;
}
/**
* Determines which content types the client accepts
@ -335,43 +305,41 @@ class RequestHandlerComponent extends Object{
* if the client accepts one or more elements in the array.
* @access public
*/
function accepts($type = null) {
if ($type == null) {
return $this->__acceptTypes;
} else if(is_array($type)) {
foreach($type as $t) {
if ($this->accepts($t) == true) {
return true;
}
function accepts($type = null) {
if ($type == null) {
return $this->__acceptTypes;
} else if(is_array($type)) {
foreach($type as $t) {
if ($this->accepts($t) == true) {
return true;
}
}
return false;
} else if(is_string($type)) {
// If client only accepts */*, then assume default HTML browser
if ($type == 'html' && $this->__acceptTypes === array('*/*')) {
return true;
}
if (!in_array($type, array_keys($this->__requestContent))) {
return false;
} else if(is_string($type)) {
// If client only accepts */*, then assume default HTML browser
if ($type == 'html' && $this->__acceptTypes === array('*/*')) {
return true;
}
$content = $this->__requestContent[$type];
if (is_array($content)) {
foreach($content as $c) {
if (in_array($c, $this->__acceptTypes)) {
return true;
}
}
if (!in_array($type, array_keys($this->__requestContent))) {
return false;
} else {
if (in_array($content, $this->__acceptTypes)) {
return true;
}
$content=$this->__requestContent[$type];
if (is_array($content)) {
foreach($content as $c) {
if (in_array($c, $this->__acceptTypes)) {
return true;
}
}
} else {
if (in_array($content, $this->__acceptTypes)) {
return true;
}
}
}
}
}
}
}
/**
* Determines which content types the client prefers
*
@ -379,10 +347,11 @@ class RequestHandlerComponent extends Object{
* @returns mixed
* @access public
*/
function prefers($type = null) {
if ($type == null) {
return $this->accepts(null);
}
}
function prefers($type = null) {
if ($type == null) {
return $this->accepts(null);
}
}
}
?>

View file

@ -43,11 +43,23 @@ class SessionComponent extends Object{
* Enter description here...
*
*/
function __construct($base = null) {
$this->CakeSession=new CakeSession($base);
parent::__construct();
}
function __construct($base = null) {
$this->CakeSession = new CakeSession($base);
parent::__construct();
}
/**
* Startup method. Copies controller data locally for rendering flash messages.
*
*/
function startup(&$controller) {
$this->base = $controller->base;
$this->webroot = $controller->webroot;
$this->here = $controller->here;
$this->params = $controller->params;
$this->action = $controller->action;
$this->data = $controller->data;
$this->plugin = $controller->plugin;
}
/**
* Enter description here...
*
@ -57,10 +69,9 @@ class SessionComponent extends Object{
* @param unknown_type $value
* @return unknown
*/
function write($name, $value) {
return $this->CakeSession->writeSessionVar($name, $value);
}
function write($name, $value) {
return $this->CakeSession->writeSessionVar($name, $value);
}
/**
* Enter description here...
*
@ -70,10 +81,9 @@ class SessionComponent extends Object{
* @param unknown_type $name
* @return unknown
*/
function read($name = null) {
return $this->CakeSession->readSessionVar($name);
}
function read($name = null) {
return $this->CakeSession->readSessionVar($name);
}
/**
* Enter description here...
*
@ -82,19 +92,17 @@ class SessionComponent extends Object{
* @param unknown_type $name
* @return unknown
*/
function del($name) {
return $this->CakeSession->delSessionVar($name);
}
function del($name) {
return $this->CakeSession->delSessionVar($name);
}
/**
* Enter description here...
* @param unknown_type $name
* @return unknown
*/
function delete($name) {
return $this->del($name);
}
function delete($name) {
return $this->del($name);
}
/**
* Enter description here...
*
@ -103,10 +111,9 @@ class SessionComponent extends Object{
* @param unknown_type $name
* @return unknown
*/
function check($name) {
return $this->CakeSession->checkSessionVar($name);
}
function check($name) {
return $this->CakeSession->checkSessionVar($name);
}
/**
* Enter description here...
*
@ -114,10 +121,9 @@ class SessionComponent extends Object{
*
* @return string Last session error
*/
function error() {
return $this->CakeSession->getLastError();
}
function error() {
return $this->CakeSession->getLastError();
}
/**
* Enter description here...
*
@ -129,38 +135,43 @@ class SessionComponent extends Object{
* @param string $key Message key, default is 'flash'
* @return string Last session error
*/
function setFlash($flashMessage, $layout = 'default', $params = array(), $key = 'flash') {
if ($layout == 'default') {
$out = '<div id="' . $key . 'Message" class="message">' . $flashMessage . '</div>';
} else if($layout == '' || $layout == null) {
$out = $flashMessage;
} else {
$ctrl =null;
$view =new View($ctrl);
$view->layout =$layout;
$view->pageTitle='';
$view->_viewVars=$params;
$out =$view->renderLayout($flashMessage);
}
$this->write('Message.' . $key, $out);
}
function setFlash($flashMessage, $layout = 'default', $params = array(), $key = 'flash') {
if ($layout == 'default') {
$out = '<div id="' . $key . 'Message" class="message">' . $flashMessage . '</div>';
} else if($layout == '' || $layout == null) {
$out = $flashMessage;
} else {
$ctrl = null;
$view = new View($ctrl);
$view->base = $this->base;
$view->webroot = $this->webroot;
$view->here = $this->here;
$view->params = $this->params;
$view->action = $this->action;
$view->data = $this->data;
$view->plugin = $this->plugin;
$view->helpers = array('Html');
$view->layout = $layout;
$view->pageTitle = '';
$view->_viewVars = $params;
$out = $view->renderLayout($flashMessage);
}
$this->write('Message.' . $key, $out);
}
/**
* Use like this. $this->Session->flash();
*
* @param string $key Optional message key
* @return null
*/
function flash($key = 'flash') {
if ($this->check('Message.' . $key)) {
e($this->read('Message.' . $key));
$this->del('Message.' . $key);
} else {
return false;
}
}
function flash($key = 'flash') {
if ($this->check('Message.' . $key)) {
e($this->read('Message.' . $key));
$this->del('Message.' . $key);
} else {
return false;
}
}
/**
* Enter description here...
*
@ -169,10 +180,9 @@ class SessionComponent extends Object{
*
* @return boolean
*/
function renew() {
$this->CakeSession->renew();
}
function renew() {
$this->CakeSession->renew();
}
/**
* Enter description here...
*
@ -182,10 +192,9 @@ class SessionComponent extends Object{
*
* @return boolean
*/
function valid() {
return $this->CakeSession->isValid();
}
function valid() {
return $this->CakeSession->isValid();
}
/**
* Enter description here...
*
@ -193,8 +202,9 @@ class SessionComponent extends Object{
* Used to destroy Sessions
*
*/
function destroy() {
$this->CakeSession->destroyInvalid();
}
function destroy() {
$this->CakeSession->destroyInvalid();
}
}
?>