code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function revoke($aro, $aco, $action = "*") {
return $this->_Instance->revoke($aro, $aco, $action);
}
|
Pass-thru function for ACL grant instance. An alias for AclComponent::deny()
@param string $aro ARO The requesting object identifier.
@param string $aco ACO The controlled object identifier.
@param string $action Action (defaults to *)
@return boolean Success
@access public
|
revoke
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function __construct() {
if (strcasecmp(get_class($this), "AclBase") == 0 || !is_subclass_of($this, "AclBase")) {
trigger_error(__("[acl_base] The AclBase class constructor has been called, or the class was instantiated. This class must remain abstract. Please refer to the Cake docs for ACL configuration.", true), E_USER_ERROR);
return NULL;
}
}
|
This class should never be instantiated, just subclassed.
|
__construct
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function initialize(&$component) {
$component->Aro =& $this->Aro;
$component->Aco =& $this->Aco;
}
|
Initializes the containing component and sets the Aro/Aco objects to it.
@param AclComponent $component
@return void
@access public
|
initialize
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function check($aro, $aco, $action = "*") {
if ($aro == null || $aco == null) {
return false;
}
$permKeys = $this->_getAcoKeys($this->Aro->Permission->schema());
$aroPath = $this->Aro->node($aro);
$acoPath = $this->Aco->node($aco);
if (empty($aroPath) || empty($acoPath)) {
trigger_error(__("DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:\nAro: ", true) . print_r($aro, true) . "\nAco: " . print_r($aco, true), E_USER_WARNING);
return false;
}
if ($acoPath == null || $acoPath == array()) {
trigger_error(__("DbAcl::check() - Failed ACO node lookup in permissions check. Node references:\nAro: ", true) . print_r($aro, true) . "\nAco: " . print_r($aco, true), E_USER_WARNING);
return false;
}
$aroNode = $aroPath[0];
$acoNode = $acoPath[0];
if ($action != '*' && !in_array('_' . $action, $permKeys)) {
trigger_error(sprintf(__("ACO permissions key %s does not exist in DbAcl::check()", true), $action), E_USER_NOTICE);
return false;
}
$inherited = array();
$acoIDs = Set::extract($acoPath, '{n}.' . $this->Aco->alias . '.id');
$count = count($aroPath);
for ($i = 0 ; $i < $count; $i++) {
$permAlias = $this->Aro->Permission->alias;
$perms = $this->Aro->Permission->find('all', array(
'conditions' => array(
"{$permAlias}.aro_id" => $aroPath[$i][$this->Aro->alias]['id'],
"{$permAlias}.aco_id" => $acoIDs
),
'order' => array($this->Aco->alias . '.lft' => 'desc'),
'recursive' => 0
));
if (empty($perms)) {
continue;
} else {
$perms = Set::extract($perms, '{n}.' . $this->Aro->Permission->alias);
foreach ($perms as $perm) {
if ($action == '*') {
foreach ($permKeys as $key) {
if (!empty($perm)) {
if ($perm[$key] == -1) {
return false;
} elseif ($perm[$key] == 1) {
$inherited[$key] = 1;
}
}
}
if (count($inherited) === count($permKeys)) {
return true;
}
} else {
switch ($perm['_' . $action]) {
case -1:
return false;
case 0:
continue;
break;
case 1:
return true;
break;
}
}
}
}
}
return false;
}
|
Checks if the given $aro has access to action $action in $aco
@param string $aro ARO The requesting object identifier.
@param string $aco ACO The controlled object identifier.
@param string $action Action (defaults to *)
@return boolean Success (true if ARO has access to action in ACO, false otherwise)
@access public
@link http://book.cakephp.org/view/1249/Checking-Permissions-The-ACL-Component
|
check
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function allow($aro, $aco, $actions = "*", $value = 1) {
$perms = $this->getAclLink($aro, $aco);
$permKeys = $this->_getAcoKeys($this->Aro->Permission->schema());
$save = array();
if ($perms == false) {
trigger_error(__('DbAcl::allow() - Invalid node', true), E_USER_WARNING);
return false;
}
if (isset($perms[0])) {
$save = $perms[0][$this->Aro->Permission->alias];
}
if ($actions == "*") {
$permKeys = $this->_getAcoKeys($this->Aro->Permission->schema());
$save = array_combine($permKeys, array_pad(array(), count($permKeys), $value));
} else {
if (!is_array($actions)) {
$actions = array('_' . $actions);
}
if (is_array($actions)) {
foreach ($actions as $action) {
if ($action{0} != '_') {
$action = '_' . $action;
}
if (in_array($action, $permKeys)) {
$save[$action] = $value;
}
}
}
}
list($save['aro_id'], $save['aco_id']) = array($perms['aro'], $perms['aco']);
if ($perms['link'] != null && !empty($perms['link'])) {
$save['id'] = $perms['link'][0][$this->Aro->Permission->alias]['id'];
} else {
unset($save['id']);
$this->Aro->Permission->id = null;
}
return ($this->Aro->Permission->save($save) !== false);
}
|
Allow $aro to have access to action $actions in $aco
@param string $aro ARO The requesting object identifier.
@param string $aco ACO The controlled object identifier.
@param string $actions Action (defaults to *)
@param integer $value Value to indicate access type (1 to give access, -1 to deny, 0 to inherit)
@return boolean Success
@access public
@link http://book.cakephp.org/view/1248/Assigning-Permissions
|
allow
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function deny($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action, -1);
}
|
Deny access for $aro to action $action in $aco
@param string $aro ARO The requesting object identifier.
@param string $aco ACO The controlled object identifier.
@param string $actions Action (defaults to *)
@return boolean Success
@access public
@link http://book.cakephp.org/view/1248/Assigning-Permissions
|
deny
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function inherit($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action, 0);
}
|
Let access for $aro to action $action in $aco be inherited
@param string $aro ARO The requesting object identifier.
@param string $aco ACO The controlled object identifier.
@param string $actions Action (defaults to *)
@return boolean Success
@access public
|
inherit
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function grant($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action);
}
|
Allow $aro to have access to action $actions in $aco
@param string $aro ARO The requesting object identifier.
@param string $aco ACO The controlled object identifier.
@param string $actions Action (defaults to *)
@return boolean Success
@see allow()
@access public
|
grant
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function revoke($aro, $aco, $action = "*") {
return $this->deny($aro, $aco, $action);
}
|
Deny access for $aro to action $action in $aco
@param string $aro ARO The requesting object identifier.
@param string $aco ACO The controlled object identifier.
@param string $actions Action (defaults to *)
@return boolean Success
@see deny()
@access public
|
revoke
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function getAclLink($aro, $aco) {
$obj = array();
$obj['Aro'] = $this->Aro->node($aro);
$obj['Aco'] = $this->Aco->node($aco);
if (empty($obj['Aro']) || empty($obj['Aco'])) {
return false;
}
return array(
'aro' => Set::extract($obj, 'Aro.0.'.$this->Aro->alias.'.id'),
'aco' => Set::extract($obj, 'Aco.0.'.$this->Aco->alias.'.id'),
'link' => $this->Aro->Permission->find('all', array('conditions' => array(
$this->Aro->Permission->alias . '.aro_id' => Set::extract($obj, 'Aro.0.'.$this->Aro->alias.'.id'),
$this->Aro->Permission->alias . '.aco_id' => Set::extract($obj, 'Aco.0.'.$this->Aco->alias.'.id')
)))
);
}
|
Get an array of access-control links between the given Aro and Aco
@param string $aro ARO The requesting object identifier.
@param string $aco ACO The controlled object identifier.
@return array Indexed array with: 'aro', 'aco' and 'link'
@access public
|
getAclLink
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function _getAcoKeys($keys) {
$newKeys = array();
$keys = array_keys($keys);
foreach ($keys as $key) {
if (!in_array($key, array('id', 'aro_id', 'aco_id'))) {
$newKeys[] = $key;
}
}
return $newKeys;
}
|
Get the keys used in an ACO
@param array $keys Permission model info
@return array ACO keys
@access protected
|
_getAcoKeys
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function check($aro, $aco, $aco_action = null) {
if ($this->config == null) {
$this->config = $this->readConfigFile(CONFIGS . 'acl.ini.php');
}
$aclConfig = $this->config;
if (isset($aclConfig[$aro]['deny'])) {
$userDenies = $this->arrayTrim(explode(",", $aclConfig[$aro]['deny']));
if (array_search($aco, $userDenies)) {
return false;
}
}
if (isset($aclConfig[$aro]['allow'])) {
$userAllows = $this->arrayTrim(explode(",", $aclConfig[$aro]['allow']));
if (array_search($aco, $userAllows)) {
return true;
}
}
if (isset($aclConfig[$aro]['groups'])) {
$userGroups = $this->arrayTrim(explode(",", $aclConfig[$aro]['groups']));
foreach ($userGroups as $group) {
if (array_key_exists($group, $aclConfig)) {
if (isset($aclConfig[$group]['deny'])) {
$groupDenies=$this->arrayTrim(explode(",", $aclConfig[$group]['deny']));
if (array_search($aco, $groupDenies)) {
return false;
}
}
if (isset($aclConfig[$group]['allow'])) {
$groupAllows = $this->arrayTrim(explode(",", $aclConfig[$group]['allow']));
if (array_search($aco, $groupAllows)) {
return true;
}
}
}
}
}
return false;
}
|
Main ACL check function. Checks to see if the ARO (access request object) has access to the
ACO (access control object).Looks at the acl.ini.php file for permissions
(see instructions in /config/acl.ini.php).
@param string $aro ARO
@param string $aco ACO
@param string $aco_action Action
@return boolean Success
@access public
|
check
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function readConfigFile($fileName) {
$fileLineArray = file($fileName);
foreach ($fileLineArray as $fileLine) {
$dataLine = trim($fileLine);
$firstChar = substr($dataLine, 0, 1);
if ($firstChar != ';' && $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 (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
$value = substr($value, 1, -1);
}
$iniSetting[$sectionName][$key]=stripcslashes($value);
} else {
if (!isset($sectionName)) {
$sectionName = '';
}
$iniSetting[$sectionName][strtolower(trim($dataLine))]='';
}
}
}
}
return $iniSetting;
}
|
Parses an INI file and returns an array that reflects the INI file's section structure. Double-quote friendly.
@param string $fileName File
@return array INI section structure
@access public
|
readConfigFile
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function arrayTrim($array) {
foreach ($array as $key => $value) {
$array[$key] = trim($value);
}
array_unshift($array, "");
return $array;
}
|
Removes trailing spaces on all array elements (to prepare for searching)
@param array $array Array to trim
@return array Trimmed array
@access public
|
arrayTrim
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/acl.php
|
MIT
|
function initialize(&$controller, $settings = array()) {
$this->params = $controller->params;
$crud = array('create', 'read', 'update', 'delete');
$this->actionMap = array_merge($this->actionMap, array_combine($crud, $crud));
$this->_methods = $controller->methods;
$prefixes = Router::prefixes();
if (!empty($prefixes)) {
foreach ($prefixes as $prefix) {
$this->actionMap = array_merge($this->actionMap, array(
$prefix . '_index' => 'read',
$prefix . '_add' => 'create',
$prefix . '_edit' => 'update',
$prefix . '_view' => 'read',
$prefix . '_remove' => 'delete',
$prefix . '_create' => 'create',
$prefix . '_read' => 'read',
$prefix . '_update' => 'update',
$prefix . '_delete' => 'delete'
));
}
}
$this->_set($settings);
if (Configure::read() > 0) {
App::import('Debugger');
Debugger::checkSecurityKeys();
}
}
|
Initializes AuthComponent for use in the controller
@param object $controller A reference to the instantiating controller object
@return void
@access public
|
initialize
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function startup(&$controller) {
$isErrorOrTests = (
strtolower($controller->name) == 'cakeerror' ||
(strtolower($controller->name) == 'tests' && Configure::read() > 0)
);
if ($isErrorOrTests) {
return true;
}
$methods = array_flip($controller->methods);
$action = strtolower($controller->params['action']);
$isMissingAction = (
$controller->scaffold === false &&
!isset($methods[$action])
);
if ($isMissingAction) {
return true;
}
if (!$this->__setDefaults()) {
return false;
}
$this->data = $controller->data = $this->hashPasswords($controller->data);
$url = '';
if (isset($controller->params['url']['url'])) {
$url = $controller->params['url']['url'];
}
$url = Router::normalize($url);
$loginAction = Router::normalize($this->loginAction);
$allowedActions = array_map('strtolower', $this->allowedActions);
$isAllowed = (
$this->allowedActions == array('*') ||
in_array($action, $allowedActions)
);
if ($loginAction != $url && $isAllowed) {
return true;
}
if ($loginAction == $url) {
$model =& $this->getModel();
if (empty($controller->data) || !isset($controller->data[$model->alias])) {
if (!$this->Session->check('Auth.redirect') && !$this->loginRedirect && env('HTTP_REFERER')) {
$this->Session->write('Auth.redirect', $controller->referer(null, true));
}
return false;
}
$isValid = !empty($controller->data[$model->alias][$this->fields['username']]) &&
!empty($controller->data[$model->alias][$this->fields['password']]);
if ($isValid) {
$username = $controller->data[$model->alias][$this->fields['username']];
$password = $controller->data[$model->alias][$this->fields['password']];
$data = array(
$model->alias . '.' . $this->fields['username'] => $username,
$model->alias . '.' . $this->fields['password'] => $password
);
if ($this->login($data)) {
if ($this->autoRedirect) {
$controller->redirect($this->redirect(), null, true);
}
return true;
}
}
$this->Session->setFlash($this->loginError, $this->flashElement, array(), 'auth');
$controller->data[$model->alias][$this->fields['password']] = null;
return false;
} else {
$user = $this->user();
if (!$user) {
if (!$this->RequestHandler->isAjax()) {
$this->Session->setFlash($this->authError, $this->flashElement, array(), 'auth');
if (!empty($controller->params['url']) && count($controller->params['url']) >= 2) {
$query = $controller->params['url'];
unset($query['url'], $query['ext']);
$url .= Router::queryString($query, array());
}
$this->Session->write('Auth.redirect', $url);
$controller->redirect($loginAction);
return false;
} elseif (!empty($this->ajaxLogin)) {
$controller->viewPath = 'elements';
echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
$this->_stop();
return false;
} else {
$controller->redirect(null, 403);
}
}
}
if (!$this->authorize) {
return true;
}
extract($this->__authType());
switch ($type) {
case 'controller':
$this->object =& $controller;
break;
case 'crud':
case 'actions':
if (isset($controller->Acl)) {
$this->Acl =& $controller->Acl;
} else {
trigger_error(__('Could not find AclComponent. Please include Acl in Controller::$components.', true), E_USER_WARNING);
}
break;
case 'model':
if (!isset($object)) {
$hasModel = (
isset($controller->{$controller->modelClass}) &&
is_object($controller->{$controller->modelClass})
);
$isUses = (
!empty($controller->uses) && isset($controller->{$controller->uses[0]}) &&
is_object($controller->{$controller->uses[0]})
);
if ($hasModel) {
$object = $controller->modelClass;
} elseif ($isUses) {
$object = $controller->uses[0];
}
}
$type = array('model' => $object);
break;
}
if ($this->isAuthorized($type, null, $user)) {
return true;
}
$this->Session->setFlash($this->authError, $this->flashElement, array(), 'auth');
$controller->redirect($controller->referer(), null, true);
return false;
}
|
Main execution method. Handles redirecting of invalid users, and processing
of login form data.
@param object $controller A reference to the instantiating controller object
@return boolean
@access public
|
startup
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function __setDefaults() {
if (empty($this->userModel)) {
trigger_error(__("Could not find \$userModel. Please set AuthComponent::\$userModel in beforeFilter().", true), E_USER_WARNING);
return false;
}
list($plugin, $model) = pluginSplit($this->userModel);
$defaults = array(
'loginAction' => array(
'controller' => Inflector::underscore(Inflector::pluralize($model)),
'action' => 'login',
'plugin' => Inflector::underscore($plugin),
),
'sessionKey' => 'Auth.' . $model,
'logoutRedirect' => $this->loginAction,
'loginError' => __('Login failed. Invalid username or password.', true),
'authError' => __('You are not authorized to access that location.', true)
);
foreach ($defaults as $key => $value) {
if (empty($this->{$key})) {
$this->{$key} = $value;
}
}
return true;
}
|
Attempts to introspect the correct values for object properties including
$userModel and $sessionKey.
@param object $controller A reference to the instantiating controller object
@return boolean
@access private
|
__setDefaults
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function isAuthorized($type = null, $object = null, $user = null) {
if (empty($user) && !$this->user()) {
return false;
} elseif (empty($user)) {
$user = $this->user();
}
extract($this->__authType($type));
if (!$object) {
$object = $this->object;
}
$valid = false;
switch ($type) {
case 'controller':
$valid = $object->isAuthorized();
break;
case 'actions':
$valid = $this->Acl->check($user, $this->action());
break;
case 'crud':
if (!isset($this->actionMap[$this->params['action']])) {
trigger_error(
sprintf(__('Auth::startup() - Attempted access of un-mapped action "%1$s" in controller "%2$s"', true), $this->params['action'], $this->params['controller']),
E_USER_WARNING
);
} else {
$valid = $this->Acl->check(
$user,
$this->action(':controller'),
$this->actionMap[$this->params['action']]
);
}
break;
case 'model':
$action = $this->params['action'];
if (isset($this->actionMap[$action])) {
$action = $this->actionMap[$action];
}
if (is_string($object)) {
$object = $this->getModel($object);
}
case 'object':
if (!isset($action)) {
$action = $this->action(':action');
}
if (empty($object)) {
trigger_error(sprintf(__('Could not find %s. Set AuthComponent::$object in beforeFilter() or pass a valid object', true), get_class($object)), E_USER_WARNING);
return;
}
if (method_exists($object, 'isAuthorized')) {
$valid = $object->isAuthorized($user, $this->action(':controller'), $action);
} elseif ($object) {
trigger_error(sprintf(__('%s::isAuthorized() is not defined.', true), get_class($object)), E_USER_WARNING);
}
break;
case null:
case false:
return true;
break;
default:
trigger_error(__('Auth::isAuthorized() - $authorize is set to an incorrect value. Allowed settings are: "actions", "crud", "model" or null.', true), E_USER_WARNING);
break;
}
return $valid;
}
|
Determines whether the given user is authorized to perform an action. The type of
authorization used is based on the value of AuthComponent::$authorize or the
passed $type param.
Types:
'controller' will validate against Controller::isAuthorized() if controller instance is
passed in $object
'actions' will validate Controller::action against an AclComponent::check()
'crud' will validate mapActions against an AclComponent::check()
array('model'=> 'name'); will validate mapActions against model
$name::isAuthorized(user, controller, mapAction)
'object' will validate Controller::action against
object::isAuthorized(user, controller, action)
@param string $type Type of authorization
@param mixed $object object, model object, or model name
@param mixed $user The user to check the authorization of
@return boolean True if $user is authorized, otherwise false
@access public
|
isAuthorized
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function __authType($auth = null) {
if ($auth == null) {
$auth = $this->authorize;
}
$object = null;
if (is_array($auth)) {
$type = key($auth);
$object = $auth[$type];
} else {
$type = $auth;
return compact('type');
}
return compact('type', 'object');
}
|
Get authorization type
@param string $auth Type of authorization
@return array Associative array with: type, object
@access private
|
__authType
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function allow() {
$args = func_get_args();
if (empty($args) || $args == array('*')) {
$this->allowedActions = $this->_methods;
} else {
if (isset($args[0]) && is_array($args[0])) {
$args = $args[0];
}
$this->allowedActions = array_merge($this->allowedActions, array_map('strtolower', $args));
}
}
|
Takes a list of actions in the current controller for which authentication is not required, or
no parameters to allow all actions.
@param mixed $action Controller action name or array of actions
@param string $action Controller action name
@param string ... etc.
@return void
@access public
@link http://book.cakephp.org/view/1257/allow
|
allow
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function deny() {
$args = func_get_args();
if (isset($args[0]) && is_array($args[0])) {
$args = $args[0];
}
foreach ($args as $arg) {
$i = array_search(strtolower($arg), $this->allowedActions);
if (is_int($i)) {
unset($this->allowedActions[$i]);
}
}
$this->allowedActions = array_values($this->allowedActions);
}
|
Removes items from the list of allowed actions.
@param mixed $action Controller action name or array of actions
@param string $action Controller action name
@param string ... etc.
@return void
@see AuthComponent::allow()
@access public
@link http://book.cakephp.org/view/1258/deny
|
deny
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function mapActions($map = array()) {
$crud = array('create', 'read', 'update', 'delete');
foreach ($map as $action => $type) {
if (in_array($action, $crud) && is_array($type)) {
foreach ($type as $typedAction) {
$this->actionMap[$typedAction] = $action;
}
} else {
$this->actionMap[$action] = $type;
}
}
}
|
Maps action names to CRUD operations. Used for controller-based authentication.
@param array $map Actions to map
@return void
@access public
@link http://book.cakephp.org/view/1260/mapActions
|
mapActions
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function login($data = null) {
$this->__setDefaults();
$this->_loggedIn = false;
if (empty($data)) {
$data = $this->data;
}
if ($user = $this->identify($data)) {
$this->Session->write($this->sessionKey, $user);
$this->_loggedIn = true;
}
return $this->_loggedIn;
}
|
Manually log-in a user with the given parameter data. The $data provided can be any data
structure used to identify a user in AuthComponent::identify(). If $data is empty or not
specified, POST data from Controller::$data will be used automatically.
After (if) login is successful, the user record is written to the session key specified in
AuthComponent::$sessionKey.
@param mixed $data User object
@return boolean True on login success, false on failure
@access public
@link http://book.cakephp.org/view/1261/login
|
login
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function logout() {
$this->__setDefaults();
$this->Session->delete($this->sessionKey);
$this->Session->delete('Auth.redirect');
$this->_loggedIn = false;
return Router::normalize($this->logoutRedirect);
}
|
Logs a user out, and returns the login action to redirect to.
@param mixed $url Optional URL to redirect the user to after logout
@return string AuthComponent::$loginAction
@see AuthComponent::$loginAction
@access public
@link http://book.cakephp.org/view/1262/logout
|
logout
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function user($key = null) {
$this->__setDefaults();
if (!$this->Session->check($this->sessionKey)) {
return null;
}
if ($key == null) {
$model =& $this->getModel();
return array($model->alias => $this->Session->read($this->sessionKey));
} else {
$user = $this->Session->read($this->sessionKey);
if (isset($user[$key])) {
return $user[$key];
}
return null;
}
}
|
Get the current user from the session.
@param string $key field to retrive. Leave null to get entire User record
@return mixed User record. or null if no user is logged in.
@access public
@link http://book.cakephp.org/view/1264/user
|
user
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function redirect($url = null) {
if (!is_null($url)) {
$redir = $url;
$this->Session->write('Auth.redirect', $redir);
} elseif ($this->Session->check('Auth.redirect')) {
$redir = $this->Session->read('Auth.redirect');
$this->Session->delete('Auth.redirect');
if (Router::normalize($redir) == Router::normalize($this->loginAction)) {
$redir = $this->loginRedirect;
}
} else {
$redir = $this->loginRedirect;
}
return Router::normalize($redir);
}
|
If no parameter is passed, gets the authentication redirect URL.
@param mixed $url Optional URL to write as the login redirect URL.
@return string Redirect URL
@access public
|
redirect
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function validate($object, $user = null, $action = null) {
if (empty($user)) {
$user = $this->user();
}
if (empty($user)) {
return false;
}
return $this->Acl->check($user, $object, $action);
}
|
Validates a user against an abstract object.
@param mixed $object The object to validate the user against.
@param mixed $user Optional. The identity of the user to be validated.
Uses the current user session if none specified. For
valid forms of identifying users, see
AuthComponent::identify().
@param string $action Optional. The action to validate against.
@see AuthComponent::identify()
@return boolean True if the user validates, false otherwise.
@access public
|
validate
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function action($action = ':plugin/:controller/:action') {
$plugin = empty($this->params['plugin']) ? null : Inflector::camelize($this->params['plugin']) . '/';
return str_replace(
array(':controller', ':action', ':plugin/'),
array(Inflector::camelize($this->params['controller']), $this->params['action'], $plugin),
$this->actionPath . $action
);
}
|
Returns the path to the ACO node bound to a controller/action.
@param string $action Optional. The controller/action path to validate the
user against. The current request action is used if
none is specified.
@return boolean ACO node path
@access public
@link http://book.cakephp.org/view/1256/action
|
action
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function &getModel($name = null) {
$model = null;
if (!$name) {
$name = $this->userModel;
}
if (PHP5) {
$model = ClassRegistry::init($name);
} else {
$model =& ClassRegistry::init($name);
}
if (empty($model)) {
trigger_error(__('Auth::getModel() - Model is not set or could not be found', true), E_USER_WARNING);
return null;
}
return $model;
}
|
Returns a reference to the model object specified, and attempts
to load it if it is not found.
@param string $name Model name (defaults to AuthComponent::$userModel)
@return object A reference to a model object
@access public
|
getModel
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function identify($user = null, $conditions = null) {
if ($conditions === false) {
$conditions = array();
} elseif (is_array($conditions)) {
$conditions = array_merge((array)$this->userScope, $conditions);
} else {
$conditions = $this->userScope;
}
$model =& $this->getModel();
if (empty($user)) {
$user = $this->user();
if (empty($user)) {
return null;
}
} elseif (is_object($user) && is_a($user, 'Model')) {
if (!$user->exists()) {
return null;
}
$user = $user->read();
$user = $user[$model->alias];
} elseif (is_array($user) && isset($user[$model->alias])) {
$user = $user[$model->alias];
}
if (is_array($user) && (isset($user[$this->fields['username']]) || isset($user[$model->alias . '.' . $this->fields['username']]))) {
if (isset($user[$this->fields['username']]) && !empty($user[$this->fields['username']]) && !empty($user[$this->fields['password']])) {
if (trim($user[$this->fields['username']]) == '=' || trim($user[$this->fields['password']]) == '=') {
return false;
}
$find = array(
$model->alias.'.'.$this->fields['username'] => $user[$this->fields['username']],
$model->alias.'.'.$this->fields['password'] => $user[$this->fields['password']]
);
} elseif (isset($user[$model->alias . '.' . $this->fields['username']]) && !empty($user[$model->alias . '.' . $this->fields['username']])) {
if (trim($user[$model->alias . '.' . $this->fields['username']]) == '=' || trim($user[$model->alias . '.' . $this->fields['password']]) == '=') {
return false;
}
$find = array(
$model->alias.'.'.$this->fields['username'] => $user[$model->alias . '.' . $this->fields['username']],
$model->alias.'.'.$this->fields['password'] => $user[$model->alias . '.' . $this->fields['password']]
);
} else {
return false;
}
$data = $model->find('first', array(
'conditions' => array_merge($find, $conditions),
'recursive' => 0
));
if (empty($data) || empty($data[$model->alias])) {
return null;
}
} elseif (!empty($user) && is_string($user)) {
$data = $model->find('first', array(
'conditions' => array_merge(array($model->escapeField() => $user), $conditions),
));
if (empty($data) || empty($data[$model->alias])) {
return null;
}
}
if (!empty($data)) {
if (!empty($data[$model->alias][$this->fields['password']])) {
unset($data[$model->alias][$this->fields['password']]);
}
return $data[$model->alias];
}
return null;
}
|
Identifies a user based on specific criteria.
@param mixed $user Optional. The identity of the user to be validated.
Uses the current user session if none specified.
@param array $conditions Optional. Additional conditions to a find.
@return array User record data, or null, if the user could not be identified.
@access public
|
identify
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function hashPasswords($data) {
if (is_object($this->authenticate) && method_exists($this->authenticate, 'hashPasswords')) {
return $this->authenticate->hashPasswords($data);
}
if (is_array($data)) {
$model =& $this->getModel();
if(isset($data[$model->alias])) {
if (isset($data[$model->alias][$this->fields['username']]) && isset($data[$model->alias][$this->fields['password']])) {
$data[$model->alias][$this->fields['password']] = $this->password($data[$model->alias][$this->fields['password']]);
}
}
}
return $data;
}
|
Hash any passwords found in $data using $userModel and $fields['password']
@param array $data Set of data to look for passwords
@return array Data with passwords hashed
@access public
@link http://book.cakephp.org/view/1259/hashPasswords
|
hashPasswords
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function password($password) {
return Security::hash($password, null, true);
}
|
Hash a password with the application's salt value (as defined with Configure::write('Security.salt');
@param string $password Password to hash
@return string Hashed password
@access public
@link http://book.cakephp.org/view/1263/password
|
password
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function shutdown(&$controller) {
if ($this->_loggedIn) {
$this->Session->delete('Auth.redirect');
}
}
|
Component shutdown. If user is logged in, wipe out redirect.
@param object $controller Instantiating controller
@access public
|
shutdown
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/auth.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/auth.php
|
MIT
|
function initialize(&$controller, $settings) {
$this->key = Configure::read('Security.salt');
$this->_set($settings);
if (isset($this->time)) {
$this->__expire($this->time);
}
}
|
Main execution method.
@param object $controller A reference to the instantiating controller object
@access public
|
initialize
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function startup() {
$this->__expire($this->time);
if (isset($_COOKIE[$this->name])) {
$this->__values = $this->__decrypt($_COOKIE[$this->name]);
}
}
|
Start CookieComponent for use in the controller
@access public
|
startup
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function write($key, $value = null, $encrypt = true, $expires = null) {
if (is_null($encrypt)) {
$encrypt = true;
}
$this->__encrypted = $encrypt;
$this->__expire($expires);
if (!is_array($key)) {
$key = array($key => $value);
}
foreach ($key as $name => $value) {
if (strpos($name, '.') === false) {
$this->__values[$name] = $value;
$this->__write("[$name]", $value);
} else {
$names = explode('.', $name, 2);
if (!isset($this->__values[$names[0]])) {
$this->__values[$names[0]] = array();
}
$this->__values[$names[0]] = Set::insert($this->__values[$names[0]], $names[1], $value);
$this->__write('[' . implode('][', $names) . ']', $value);
}
}
$this->__encrypted = true;
}
|
Write a value to the $_COOKIE[$key];
Optional [Name.], required key, optional $value, optional $encrypt, optional $expires
$this->Cookie->write('[Name.]key, $value);
By default all values are encrypted.
You must pass $encrypt false to store values in clear test
You must use this method before any output is sent to the browser.
Failure to do so will result in header already sent errors.
@param mixed $key Key for the value
@param mixed $value Value
@param boolean $encrypt Set to true to encrypt value, false otherwise
@param string $expires Can be either Unix timestamp, or date string
@access public
|
write
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function read($key = null) {
if (empty($this->__values) && isset($_COOKIE[$this->name])) {
$this->__values = $this->__decrypt($_COOKIE[$this->name]);
}
if (is_null($key)) {
return $this->__values;
}
if (strpos($key, '.') !== false) {
$names = explode('.', $key, 2);
$key = $names[0];
}
if (!isset($this->__values[$key])) {
return null;
}
if (!empty($names[1])) {
return Set::extract($this->__values[$key], $names[1]);
}
return $this->__values[$key];
}
|
Read the value of the $_COOKIE[$key];
Optional [Name.], required key
$this->Cookie->read(Name.key);
@param mixed $key Key of the value to be obtained. If none specified, obtain map key => values
@return string or null, value for specified key
@access public
|
read
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function delete($key) {
if (empty($this->__values)) {
$this->read();
}
if (strpos($key, '.') === false) {
if (isset($this->__values[$key]) && is_array($this->__values[$key])) {
foreach ($this->__values[$key] as $idx => $val) {
$this->__delete("[$key][$idx]");
}
}
$this->__delete("[$key]");
unset($this->__values[$key]);
return;
}
$names = explode('.', $key, 2);
if (isset($this->__values[$names[0]])) {
$this->__values[$names[0]] = Set::remove($this->__values[$names[0]], $names[1]);
}
$this->__delete('[' . implode('][', $names) . ']');
}
|
Delete a cookie value
Optional [Name.], required key
$this->Cookie->read('Name.key);
You must use this method before any output is sent to the browser.
Failure to do so will result in header already sent errors.
@param string $key Key of the value to be deleted
@return void
@access public
|
delete
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function destroy() {
if (isset($_COOKIE[$this->name])) {
$this->__values = $this->__decrypt($_COOKIE[$this->name]);
}
foreach ($this->__values as $name => $value) {
if (is_array($value)) {
foreach ($value as $key => $val) {
unset($this->__values[$name][$key]);
$this->__delete("[$name][$key]");
}
}
unset($this->__values[$name]);
$this->__delete("[$name]");
}
}
|
Destroy current cookie
You must use this method before any output is sent to the browser.
Failure to do so will result in header already sent errors.
@return void
@access public
|
destroy
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function type($type = 'cipher') {
$this->__type = 'cipher';
}
|
Will allow overriding default encryption method.
@param string $type Encryption method
@access public
@todo NOT IMPLEMENTED
|
type
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function __expire($expires = null) {
$now = time();
if (is_null($expires)) {
return $this->__expires;
}
$this->__reset = $this->__expires;
if ($expires == 0) {
return $this->__expires = 0;
}
if (is_integer($expires) || is_numeric($expires)) {
return $this->__expires = $now + intval($expires);
}
return $this->__expires = strtotime($expires, $now);
}
|
Set the expire time for a session variable.
Creates a new expire time for a session variable.
$expire can be either integer Unix timestamp or a date string.
Used by write()
CookieComponent::write(string, string, boolean, 8400);
CookieComponent::write(string, string, boolean, '5 Days');
@param mixed $expires Can be either Unix timestamp, or date string
@return int Unix timestamp
@access private
|
__expire
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function __write($name, $value) {
setcookie($this->name . $name, $this->__encrypt($value), $this->__expires, $this->path, $this->domain, $this->secure);
if (!is_null($this->__reset)) {
$this->__expires = $this->__reset;
$this->__reset = null;
}
}
|
Set cookie
@param string $name Name for cookie
@param string $value Value for cookie
@access private
|
__write
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function __delete($name) {
setcookie($this->name . $name, '', time() - 42000, $this->path, $this->domain, $this->secure);
}
|
Sets a cookie expire time to remove cookie value
@param string $name Name of cookie
@access private
|
__delete
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function __encrypt($value) {
if (is_array($value)) {
$value = $this->__implode($value);
}
if ($this->__encrypted === true) {
$type = $this->__type;
$value = "Q2FrZQ==." .base64_encode(Security::$type($value, $this->key));
}
return $value;
}
|
Encrypts $value using var $type method in Security class
@param string $value Value to encrypt
@return string encrypted string
@access private
|
__encrypt
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function __decrypt($values) {
$decrypted = array();
$type = $this->__type;
foreach ((array)$values as $name => $value) {
if (is_array($value)) {
foreach ($value as $key => $val) {
$pos = strpos($val, 'Q2FrZQ==.');
if ($pos !== false) {
$val = substr($val, 8);
$decrypted[$name][$key] = $this->__explode(Security::$type(base64_decode($val), $this->key));
} else {
$decrypted[$name][$key] = $this->__explode($val);
}
}
} else {
$pos = strpos($value, 'Q2FrZQ==.');
if ($pos !== false) {
$value = substr($value, 8);
$decrypted[$name] = $this->__explode(Security::$type(base64_decode($value), $this->key));
} else {
$decrypted[$name] = $this->__explode($value);
}
}
}
return $decrypted;
}
|
Decrypts $value using var $type method in Security class
@param array $values Values to decrypt
@return string decrypted string
@access private
|
__decrypt
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function __implode($array) {
$string = '';
foreach ($array as $key => $value) {
$string .= ',' . $key . '|' . $value;
}
return substr($string, 1);
}
|
Implode method to keep keys are multidimensional arrays
@param array $array Map of key and values
@return string String in the form key1|value1,key2|value2
@access private
|
__implode
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function __explode($string) {
$first = substr($string, 0, 1);
if ($first !== false && ($first === '{' || $first === '[') && function_exists('json_decode')) {
$ret = json_decode($string, true);
return ($ret != null) ? $ret : $string;
}
$array = array();
foreach (explode(',', $string) as $pair) {
$key = explode('|', $pair);
if (!isset($key[1])) {
return $key[0];
}
$array[$key[0]] = $key[1];
}
return $array;
}
|
Explode method to return array from string set in CookieComponent::__implode()
@param string $string String in the form key1|value1,key2|value2
@return mixed If array, map of key and values. If string, value.
@access private
|
__explode
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/cookie.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/cookie.php
|
MIT
|
function initialize(&$controller, $settings = array()) {
$this->Controller =& $controller;
if (Configure::read('App.encoding') !== null) {
$this->charset = Configure::read('App.encoding');
}
$this->_set($settings);
}
|
Initialize component
@param object $controller Instantiating controller
@access public
|
initialize
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function send($content = null, $template = null, $layout = null) {
$this->_createHeader();
if ($template) {
$this->template = $template;
}
if ($layout) {
$this->layout = $layout;
}
if (is_array($content)) {
$content = implode("\n", $content) . "\n";
}
$this->htmlMessage = $this->textMessage = null;
if ($content) {
if ($this->sendAs === 'html') {
$this->htmlMessage = $content;
} elseif ($this->sendAs === 'text') {
$this->textMessage = $content;
} else {
$this->htmlMessage = $this->textMessage = $content;
}
}
if ($this->sendAs === 'text') {
$message = $this->_wrap($content);
} else {
$message = $this->_wrap($content, 998);
}
if ($this->template === null) {
$message = $this->_formatMessage($message);
} else {
$message = $this->_render($message);
}
$message[] = '';
$this->__message = $message;
if (!empty($this->attachments)) {
$this->_attachFiles();
}
if (!empty($this->attachments)) {
$this->__message[] = '';
$this->__message[] = '--' . $this->__boundary . '--';
$this->__message[] = '';
}
$_method = '_' . $this->delivery;
$sent = $this->$_method();
$this->__header = array();
$this->__message = array();
return $sent;
}
|
Send an email using the specified content, template and layout
@param mixed $content Either an array of text lines, or a string with contents
If you are rendering a template this variable will be sent to the templates as `$content`
@param string $template Template to use when sending email
@param string $layout Layout to use to enclose email body
@return boolean Success
@access public
|
send
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function reset() {
$this->template = null;
$this->to = array();
$this->from = null;
$this->replyTo = null;
$this->return = null;
$this->cc = array();
$this->bcc = array();
$this->headers = array();
$this->subject = null;
$this->additionalParams = null;
$this->date = null;
$this->smtpError = null;
$this->attachments = array();
$this->htmlMessage = null;
$this->textMessage = null;
$this->messageId = true;
$this->delivery = 'mail';
$this->__header = array();
$this->__boundary = null;
$this->__message = array();
}
|
Reset all EmailComponent internal variables to be able to send out a new email.
@access public
@link http://book.cakephp.org/view/1285/Sending-Multiple-Emails-in-a-loop
|
reset
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _render($content) {
$viewClass = $this->Controller->view;
if ($viewClass != 'View') {
list($plugin, $viewClass) = pluginSplit($viewClass);
$viewClass = $viewClass . 'View';
App::import('View', $this->Controller->view);
}
$View = new $viewClass($this->Controller);
$View->layout = $this->layout;
$msg = array();
$content = implode("\n", $content);
if ($this->sendAs === 'both') {
$htmlContent = $content;
if (!empty($this->attachments)) {
$msg[] = '--' . $this->__boundary;
$msg[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
$msg[] = '';
}
$msg[] = '--alt-' . $this->__boundary;
$msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
$msg[] = 'Content-Transfer-Encoding: 7bit';
$msg[] = '';
$content = $View->element('email' . DS . 'text' . DS . $this->template, array('content' => $content), true);
$View->layoutPath = 'email' . DS . 'text';
$content = explode("\n", $this->textMessage = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($content)));
$msg = array_merge($msg, $content);
$msg[] = '';
$msg[] = '--alt-' . $this->__boundary;
$msg[] = 'Content-Type: text/html; charset=' . $this->charset;
$msg[] = 'Content-Transfer-Encoding: 7bit';
$msg[] = '';
$htmlContent = $View->element('email' . DS . 'html' . DS . $this->template, array('content' => $htmlContent), true);
$View->layoutPath = 'email' . DS . 'html';
$htmlContent = explode("\n", $this->htmlMessage = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($htmlContent)));
$msg = array_merge($msg, $htmlContent);
$msg[] = '';
$msg[] = '--alt-' . $this->__boundary . '--';
$msg[] = '';
ClassRegistry::removeObject('view');
return $msg;
}
if (!empty($this->attachments)) {
if ($this->sendAs === 'html') {
$msg[] = '';
$msg[] = '--' . $this->__boundary;
$msg[] = 'Content-Type: text/html; charset=' . $this->charset;
$msg[] = 'Content-Transfer-Encoding: 7bit';
$msg[] = '';
} else {
$msg[] = '--' . $this->__boundary;
$msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
$msg[] = 'Content-Transfer-Encoding: 7bit';
$msg[] = '';
}
}
$content = $View->element('email' . DS . $this->sendAs . DS . $this->template, array('content' => $content), true);
$View->layoutPath = 'email' . DS . $this->sendAs;
$content = explode("\n", $rendered = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($content)));
if ($this->sendAs === 'html') {
$this->htmlMessage = $rendered;
} else {
$this->textMessage = $rendered;
}
$msg = array_merge($msg, $content);
ClassRegistry::removeObject('view');
return $msg;
}
|
Render the contents using the current layout and template.
@param string $content Content to render
@return array Email ready to be sent
@access private
|
_render
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _createboundary() {
$this->__boundary = md5(uniqid(time()));
}
|
Create unique boundary identifier
@access private
|
_createboundary
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function header($headers) {
foreach ($headers as $header => $value) {
$this->__header[] = sprintf('%s: %s', trim($header), trim($value));
}
}
|
Sets headers for the message
@access public
@param array Associative array containing headers to be set.
|
header
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _formatMessage($message) {
if (!empty($this->attachments)) {
$prefix = array('--' . $this->__boundary);
if ($this->sendAs === 'text') {
$prefix[] = 'Content-Type: text/plain; charset=' . $this->charset;
} elseif ($this->sendAs === 'html') {
$prefix[] = 'Content-Type: text/html; charset=' . $this->charset;
} elseif ($this->sendAs === 'both') {
$prefix[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
}
$prefix[] = 'Content-Transfer-Encoding: 7bit';
$prefix[] = '';
$message = array_merge($prefix, $message);
}
return $message;
}
|
Format the message by seeing if it has attachments.
@param string $message Message to format
@access private
|
_formatMessage
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _attachFiles() {
$files = array();
foreach ($this->attachments as $filename => $attachment) {
$file = $this->_findFiles($attachment);
if (!empty($file)) {
if (is_int($filename)) {
$filename = basename($file);
}
$files[$filename] = $file;
}
}
foreach ($files as $filename => $file) {
$handle = fopen($file, 'rb');
$data = fread($handle, filesize($file));
$data = chunk_split(base64_encode($data)) ;
fclose($handle);
$this->__message[] = '--' . $this->__boundary;
$this->__message[] = 'Content-Type: application/octet-stream';
$this->__message[] = 'Content-Transfer-Encoding: base64';
$this->__message[] = 'Content-Disposition: attachment; filename="' . basename($filename) . '"';
$this->__message[] = '';
$this->__message[] = $data;
$this->__message[] = '';
}
}
|
Attach files by adding file contents inside boundaries.
@access private
@TODO: modify to use the core File class?
|
_attachFiles
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _findFiles($attachment) {
if (file_exists($attachment)) {
return $attachment;
}
foreach ($this->filePaths as $path) {
if (file_exists($path . DS . $attachment)) {
$file = $path . DS . $attachment;
return $file;
}
}
return null;
}
|
Find the specified attachment in the list of file paths
@param string $attachment Attachment file name to find
@return string Path to located file
@access private
|
_findFiles
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _wrap($message, $lineLength = null) {
$message = $this->_strip($message, true);
$message = str_replace(array("\r\n","\r"), "\n", $message);
$lines = explode("\n", $message);
$formatted = array();
if ($this->_lineLength !== null) {
trigger_error(__('_lineLength cannot be accessed please use lineLength', true), E_USER_WARNING);
$this->lineLength = $this->_lineLength;
}
if (!$lineLength) {
$lineLength = $this->lineLength;
}
foreach ($lines as $line) {
if (substr($line, 0, 1) == '.') {
$line = '.' . $line;
}
$formatted = array_merge($formatted, explode("\n", wordwrap($line, $lineLength, "\n", true)));
}
$formatted[] = '';
return $formatted;
}
|
Wrap the message using EmailComponent::$lineLength
@param string $message Message to wrap
@param integer $lineLength Max length of line
@return array Wrapped message
@access protected
|
_wrap
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _encode($subject) {
$subject = $this->_strip($subject);
$nl = "\r\n";
if ($this->delivery == 'mail') {
$nl = '';
}
$internalEncoding = function_exists('mb_internal_encoding');
if ($internalEncoding) {
$restore = mb_internal_encoding();
mb_internal_encoding($this->charset);
}
$return = mb_encode_mimeheader($subject, $this->charset, 'B', $nl);
if ($internalEncoding) {
mb_internal_encoding($restore);
}
return $return;
}
|
Encode the specified string using the current charset
@param string $subject String to encode
@return string Encoded string
@access private
|
_encode
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _formatAddress($string, $smtp = false) {
$hasAlias = preg_match('/((.*))?\s?<(.+)>/', $string, $matches);
if ($smtp && $hasAlias) {
return $this->_strip('<' . $matches[3] . '>');
} elseif ($smtp) {
return $this->_strip('<' . $string . '>');
}
if ($hasAlias && !empty($matches[2])) {
return $this->_encode(trim($matches[2])) . $this->_strip(' <' . $matches[3] . '>');
}
return $this->_strip($string);
}
|
Format a string as an email address
@param string $string String representing an email address
@return string Email address suitable for email headers or smtp pipe
@access private
|
_formatAddress
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _strip($value, $message = false) {
$search = '%0a|%0d|Content-(?:Type|Transfer-Encoding)\:';
$search .= '|charset\=|mime-version\:|multipart/mixed|(?:[\n\r]+to|b?cc)\:.*';
if ($message !== true) {
$search .= '|\r|\n';
}
$search = '#(?:' . $search . ')#i';
while (preg_match($search, $value)) {
$value = preg_replace($search, '', $value);
}
return $value;
}
|
Remove certain elements (such as bcc:, to:, %0a) from given value.
Helps prevent header injection / mainipulation on user content.
@param string $value Value to strip
@param boolean $message Set to true to indicate main message content
@return string Stripped value
@access private
|
_strip
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _mail() {
$header = implode($this->lineFeed, $this->__header);
$message = implode($this->lineFeed, $this->__message);
if (is_array($this->to)) {
$to = implode(', ', array_map(array($this, '_formatAddress'), $this->to));
} else {
$to = $this->to;
}
if (ini_get('safe_mode')) {
return @mail($to, $this->_encode($this->subject), $message, $header);
}
return @mail($to, $this->_encode($this->subject), $message, $header, $this->additionalParams);
}
|
Wrapper for PHP mail function used for sending out emails
@return bool Success
@access private
|
_mail
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _getSocket($config) {
$this->__smtpConnection =& new CakeSocket($config);
}
|
Helper method to get socket, overridden in tests
@param array $config Config data for the socket.
@return void
@access protected
|
_getSocket
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _smtp() {
App::import('Core', array('CakeSocket'));
$defaults = array(
'host' => 'localhost',
'port' => 25,
'protocol' => 'smtp',
'timeout' => 30
);
$this->smtpOptions = array_merge($defaults, $this->smtpOptions);
$this->_getSocket($this->smtpOptions);
if (!$this->__smtpConnection->connect()) {
$this->smtpError = $this->__smtpConnection->lastError();
return false;
} elseif (!$this->_smtpSend(null, '220')) {
return false;
}
$httpHost = env('HTTP_HOST');
if (isset($this->smtpOptions['client'])) {
$host = $this->smtpOptions['client'];
} elseif (!empty($httpHost)) {
list($host) = explode(':', $httpHost);
} else {
$host = 'localhost';
}
if (!$this->_smtpSend("EHLO {$host}", '250') && !$this->_smtpSend("HELO {$host}", '250')) {
return false;
}
if (isset($this->smtpOptions['username']) && isset($this->smtpOptions['password'])) {
$authRequired = $this->_smtpSend('AUTH LOGIN', '334|503');
if ($authRequired == '334') {
if (!$this->_smtpSend(base64_encode($this->smtpOptions['username']), '334')) {
return false;
}
if (!$this->_smtpSend(base64_encode($this->smtpOptions['password']), '235')) {
return false;
}
} elseif ($authRequired != '503') {
return false;
}
}
if (!$this->_smtpSend('MAIL FROM: ' . $this->_formatAddress($this->from, true))) {
return false;
}
if (!is_array($this->to)) {
$tos = array_map('trim', explode(',', $this->to));
} else {
$tos = $this->to;
}
foreach ($tos as $to) {
if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($to, true))) {
return false;
}
}
foreach ($this->cc as $cc) {
if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($cc, true))) {
return false;
}
}
foreach ($this->bcc as $bcc) {
if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($bcc, true))) {
return false;
}
}
if (!$this->_smtpSend('DATA', '354')) {
return false;
}
$header = implode("\r\n", $this->__header);
$message = implode("\r\n", $this->__message);
if (!$this->_smtpSend($header . "\r\n\r\n" . $message . "\r\n\r\n\r\n.")) {
return false;
}
$this->_smtpSend('QUIT', false);
$this->__smtpConnection->disconnect();
return true;
}
|
Sends out email via SMTP
@return bool Success
@access private
|
_smtp
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _smtpSend($data, $checkCode = '250') {
if (!is_null($data)) {
$this->__smtpConnection->write($data . "\r\n");
}
while ($checkCode !== false) {
$response = '';
$startTime = time();
while (substr($response, -2) !== "\r\n" && ((time() - $startTime) < $this->smtpOptions['timeout'])) {
$response .= $this->__smtpConnection->read();
}
if (substr($response, -2) !== "\r\n") {
$this->smtpError = 'timeout';
return false;
}
$response = end(explode("\r\n", rtrim($response, "\r\n")));
if (preg_match('/^(' . $checkCode . ')(.)/', $response, $code)) {
if ($code[2] === '-') {
continue;
}
return $code[1];
}
$this->smtpError = $response;
return false;
}
return true;
}
|
Protected method for sending data to SMTP connection
@param string $data data to be sent to SMTP server
@param mixed $checkCode code to check for in server response, false to skip
@return bool Success
@access protected
|
_smtpSend
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function _debug() {
$nl = "\n";
$header = implode($nl, $this->__header);
$message = implode($nl, $this->__message);
$fm = '<pre>';
if (is_array($this->to)) {
$to = implode(', ', array_map(array($this, '_formatAddress'), $this->to));
} else {
$to = $this->to;
}
$fm .= sprintf('%s %s%s', 'To:', $to, $nl);
$fm .= sprintf('%s %s%s', 'From:', $this->from, $nl);
$fm .= sprintf('%s %s%s', 'Subject:', $this->_encode($this->subject), $nl);
$fm .= sprintf('%s%3$s%3$s%s', 'Header:', $header, $nl);
$fm .= sprintf('%s%3$s%3$s%s', 'Parameters:', $this->additionalParams, $nl);
$fm .= sprintf('%s%3$s%3$s%s', 'Message:', $message, $nl);
$fm .= '</pre>';
if (isset($this->Controller->Session)) {
$this->Controller->Session->setFlash($fm, 'default', null, 'email');
return true;
}
return $fm;
}
|
Set as controller flash message a debug message showing current settings in component
@return boolean Success
@access private
|
_debug
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/email.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/email.php
|
MIT
|
function __construct() {
$this->__acceptTypes = explode(',', env('HTTP_ACCEPT'));
$this->__acceptTypes = array_map('trim', $this->__acceptTypes);
foreach ($this->__acceptTypes as $i => $type) {
if (strpos($type, ';')) {
$type = explode(';', $type);
$this->__acceptTypes[$i] = trim($type[0]);
}
}
parent::__construct();
}
|
Constructor. Parses the accepted content types accepted by the client using HTTP_ACCEPT
|
__construct
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function initialize(&$controller, $settings = array()) {
if (isset($controller->params['url']['ext'])) {
$this->ext = $controller->params['url']['ext'];
}
$this->params = $controller->params;
$this->_set($settings);
}
|
Initializes the component, gets a reference to Controller::$parameters, and
checks to see if a file extension has been parsed by the Router. If yes, the
corresponding content-type is pushed onto the list of accepted content-types
as the first item.
@param object $controller A reference to the controller
@param array $settings Array of settings to _set().
@return void
@see Router::parseExtensions()
@access public
|
initialize
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function startup(&$controller) {
if (!$this->enabled) {
return;
}
$this->__initializeTypes();
$controller->params['isAjax'] = $this->isAjax();
$isRecognized = (
!in_array($this->ext, array('html', 'htm')) &&
in_array($this->ext, array_keys($this->__requestContent))
);
if (!empty($this->ext) && $isRecognized) {
$this->renderAs($controller, $this->ext);
} elseif ($this->isAjax()) {
$this->renderAs($controller, 'ajax');
} elseif (empty($this->ext) || in_array($this->ext, array('html', 'htm'))) {
$this->respondAs('html', array('charset' => Configure::read('App.encoding')));
}
if ($this->requestedWith('xml')) {
if (!class_exists('XmlNode')) {
App::import('Core', 'Xml');
}
$xml = new Xml(trim(file_get_contents('php://input')));
if (count($xml->children) == 1 && is_object($dataNode = $xml->child('data'))) {
$controller->data = $dataNode->toArray();
} else {
$controller->data = $xml->toArray();
}
}
}
|
The startup method of the RequestHandler enables several automatic behaviors
related to the detection of certain properties of the HTTP request, including:
- Disabling layout rendering for Ajax requests (based on the HTTP_X_REQUESTED_WITH header)
- If Router::parseExtensions() is enabled, the layout and template type are
switched based on the parsed extension. For example, if controller/action.xml
is requested, the view path becomes <i>app/views/controller/xml/action.ctp</i>.
- If a helper with the same name as the extension exists, it is added to the controller.
- If the extension is of a type that RequestHandler understands, it will set that
Content-type in the response header.
- If the XML data is POSTed, the data is parsed into an XML object, which is assigned
to the $data property of the controller, which can then be saved to a model object.
@param object $controller A reference to the controller
@return void
@access public
|
startup
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function beforeRedirect(&$controller, $url, $status = null) {
if (!$this->isAjax()) {
return;
}
foreach ($_POST as $key => $val) {
unset($_POST[$key]);
}
if (is_array($url)) {
$url = Router::url($url + array('base' => false));
}
if (!empty($status)) {
$statusCode = $controller->httpCodes($status);
$code = key($statusCode);
$msg = $statusCode[$code];
$controller->header("HTTP/1.1 {$code} {$msg}");
}
echo $this->requestAction($url, array('return', 'bare' => false));
$this->_stop();
}
|
Handles (fakes) redirects for Ajax requests using requestAction()
@param object $controller A reference to the controller
@param mixed $url A string or array containing the redirect location
@param mixed HTTP Status for redirect
@access public
|
beforeRedirect
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function isAjax() {
return env('HTTP_X_REQUESTED_WITH') === "XMLHttpRequest";
}
|
Returns true if the current HTTP request is Ajax, false otherwise
@return boolean True if call is Ajax
@access public
|
isAjax
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function isFlash() {
return (preg_match('/^(Shockwave|Adobe) Flash/', env('HTTP_USER_AGENT')) == 1);
}
|
Returns true if the current HTTP request is coming from a Flash-based client
@return boolean True if call is from Flash
@access public
|
isFlash
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function isSSL() {
return env('HTTPS');
}
|
Returns true if the current request is over HTTPS, false otherwise.
@return bool True if call is over HTTPS
@access public
|
isSSL
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function isXml() {
return $this->prefers('xml');
}
|
Returns true if the current call accepts an XML response, false otherwise
@return boolean True if client accepts an XML response
@access public
|
isXml
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function isRss() {
return $this->prefers('rss');
}
|
Returns true if the current call accepts an RSS response, false otherwise
@return boolean True if client accepts an RSS response
@access public
|
isRss
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function isAtom() {
return $this->prefers('atom');
}
|
Returns true if the current call accepts an Atom response, false otherwise
@return boolean True if client accepts an RSS response
@access public
|
isAtom
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function isMobile() {
if (defined('REQUEST_MOBILE_UA')) {
$regex = '/' . REQUEST_MOBILE_UA . '/i';
} else {
$regex = '/' . implode('|', $this->mobileUA) . '/i';
}
if (preg_match($regex, env('HTTP_USER_AGENT')) || $this->accepts('wap')) {
return true;
}
return false;
}
|
Returns true if user agent string matches a mobile web browser, or if the
client accepts WAP content.
@return boolean True if user agent is a mobile web browser
@access public
@deprecated Use of constant REQUEST_MOBILE_UA is deprecated and will be removed in future versions
|
isMobile
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function isWap() {
return $this->prefers('wap');
}
|
Returns true if the client accepts WAP content
@return bool
@access public
|
isWap
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function isPost() {
return (strtolower(env('REQUEST_METHOD')) == 'post');
}
|
Returns true if the current call a POST request
@return boolean True if call is a POST
@access public
|
isPost
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function isPut() {
return (strtolower(env('REQUEST_METHOD')) == 'put');
}
|
Returns true if the current call a PUT request
@return boolean True if call is a PUT
@access public
|
isPut
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function isGet() {
return (strtolower(env('REQUEST_METHOD')) == 'get');
}
|
Returns true if the current call a GET request
@return boolean True if call is a GET
@access public
|
isGet
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function isDelete() {
return (strtolower(env('REQUEST_METHOD')) == 'delete');
}
|
Returns true if the current call a DELETE request
@return boolean True if call is a DELETE
@access public
|
isDelete
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function getAjaxVersion() {
if (env('HTTP_X_PROTOTYPE_VERSION') != null) {
return env('HTTP_X_PROTOTYPE_VERSION');
}
return false;
}
|
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
@access public
|
getAjaxVersion
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function setContent($name, $type = null) {
if (is_array($name)) {
$this->__requestContent = array_merge($this->__requestContent, $name);
return;
}
$this->__requestContent[$name] = $type;
}
|
Adds/sets the Content-type(s) for the given name. This method allows
content-types to be mapped to friendly aliases (or extensions), which allows
RequestHandler to automatically respond to requests of that type in the
startup method.
@param string $name The name of the Content-type, i.e. "html", "xml", "css"
@param mixed $type The Content-type or array of Content-types assigned to the name,
i.e. "text/html", or "application/xml"
@return void
@access public
|
setContent
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function getReferer() {
if (env('HTTP_HOST') != null) {
$sessHost = env('HTTP_HOST');
}
if (env('HTTP_X_FORWARDED_HOST') != null) {
$sessHost = env('HTTP_X_FORWARDED_HOST');
}
return trim(preg_replace('/(?:\:.*)/', '', $sessHost));
}
|
Gets the server name from which this request was referred
@return string Server address
@access public
|
getReferer
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function getClientIP($safe = true) {
if (!$safe && 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);
}
|
Gets remote client IP
@return string Client IP address
@access public
|
getClientIP
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function accepts($type = null) {
$this->__initializeTypes();
if ($type == null) {
return $this->mapType($this->__acceptTypes);
} elseif (is_array($type)) {
foreach ($type as $t) {
if ($this->accepts($t) == true) {
return true;
}
}
return false;
} elseif (is_string($type)) {
if (!isset($this->__requestContent[$type])) {
return false;
}
$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 accepts. Acceptance is based on
the file extension parsed by the Router (if present), and by the HTTP_ACCEPT
header.
@param mixed $type Can be null (or no parameter), a string type name, or an
array of types
@return mixed If null or no parameter is passed, returns an array of content
types the client accepts. If a string is passed, returns true
if the client accepts it. If an array is passed, returns true
if the client accepts one or more elements in the array.
@access public
@see RequestHandlerComponent::setContent()
|
accepts
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function requestedWith($type = null) {
if (!$this->isPost() && !$this->isPut()) {
return null;
}
list($contentType) = explode(';', env('CONTENT_TYPE'));
if ($type == null) {
return $this->mapType($contentType);
} elseif (is_array($type)) {
foreach ($type as $t) {
if ($this->requestedWith($t)) {
return $this->mapType($t);
}
}
return false;
} elseif (is_string($type)) {
return ($type == $this->mapType($contentType));
}
}
|
Determines the content type of the data the client has sent (i.e. in a POST request)
@param mixed $type Can be null (or no parameter), a string type name, or an array of types
@return mixed
@access public
|
requestedWith
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function prefers($type = null) {
$this->__initializeTypes();
$accept = $this->accepts();
if ($type == null) {
if (empty($this->ext)) {
if (is_array($accept)) {
return $accept[0];
}
return $accept;
}
return $this->ext;
}
$types = $type;
if (is_string($type)) {
$types = array($type);
}
if (count($types) === 1) {
if (!empty($this->ext)) {
return ($types[0] == $this->ext);
}
return ($types[0] == $accept[0]);
}
$accepts = array();
foreach ($types as $type) {
if (in_array($type, $accept)) {
$accepts[] = $type;
}
}
if (count($accepts) === 0) {
return false;
} elseif (count($types) === 1) {
return ($types[0] === $accepts[0]);
} elseif (count($accepts) === 1) {
return $accepts[0];
}
$acceptedTypes = array();
foreach ($this->__acceptTypes as $type) {
$acceptedTypes[] = $this->mapType($type);
}
$accepts = array_intersect($acceptedTypes, $accepts);
return $accepts[0];
}
|
Determines which content-types the client prefers. If no parameters are given,
the content-type that the client most likely prefers is returned. If $type is
an array, the first item in the array that the client accepts is returned.
Preference is determined primarily by the file extension parsed by the Router
if provided, and secondarily by the list of content-types provided in
HTTP_ACCEPT.
@param mixed $type An optional array of 'friendly' content-type names, i.e.
'html', 'xml', 'js', etc.
@return mixed If $type is null or not provided, the first content-type in the
list, based on preference, is returned.
@access public
@see RequestHandlerComponent::setContent()
|
prefers
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function renderAs(&$controller, $type) {
$this->__initializeTypes();
$options = array('charset' => 'UTF-8');
if (Configure::read('App.encoding') !== null) {
$options = array('charset' => Configure::read('App.encoding'));
}
if ($type == 'ajax') {
$controller->layout = $this->ajaxLayout;
return $this->respondAs('html', $options);
}
$controller->ext = '.ctp';
if (empty($this->__renderType)) {
$controller->viewPath .= DS . $type;
} else {
$remove = preg_replace("/([\/\\\\]{$this->__renderType})$/", DS . $type, $controller->viewPath);
$controller->viewPath = $remove;
}
$this->__renderType = $type;
$controller->layoutPath = $type;
if (isset($this->__requestContent[$type])) {
$this->respondAs($type, $options);
}
$helper = ucfirst($type);
$isAdded = (
in_array($helper, $controller->helpers) ||
array_key_exists($helper, $controller->helpers)
);
if (!$isAdded) {
if (App::import('Helper', $helper)) {
$controller->helpers[] = $helper;
}
}
}
|
Sets the layout and template paths for the content type defined by $type.
@param object $controller A reference to a controller object
@param string $type Type of response to send (e.g: 'ajax')
@return void
@access public
@see RequestHandlerComponent::setContent()
@see RequestHandlerComponent::respondAs()
|
renderAs
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function respondAs($type, $options = array()) {
$this->__initializeTypes();
if (!array_key_exists($type, $this->__requestContent) && strpos($type, '/') === false) {
return false;
}
$defaults = array('index' => 0, 'charset' => null, 'attachment' => false);
$options = array_merge($defaults, $options);
if (strpos($type, '/') === false && isset($this->__requestContent[$type])) {
$cType = null;
if (is_array($this->__requestContent[$type]) && isset($this->__requestContent[$type][$options['index']])) {
$cType = $this->__requestContent[$type][$options['index']];
} elseif (is_array($this->__requestContent[$type]) && isset($this->__requestContent[$type][0])) {
$cType = $this->__requestContent[$type][0];
} elseif (isset($this->__requestContent[$type])) {
$cType = $this->__requestContent[$type];
} else {
return false;
}
if (is_array($cType)) {
if ($this->prefers($cType)) {
$cType = $this->prefers($cType);
} else {
$cType = $cType[0];
}
}
} else {
$cType = $type;
}
if ($cType != null) {
$header = 'Content-type: ' . $cType;
if (!empty($options['charset'])) {
$header .= '; charset=' . $options['charset'];
}
if (!empty($options['attachment'])) {
$this->_header("Content-Disposition: attachment; filename=\"{$options['attachment']}\"");
}
if (Configure::read() < 2 && !defined('CAKEPHP_SHELL') && empty($this->params['requested'])) {
$this->_header($header);
}
$this->__responseTypeSet = $cType;
return true;
}
return false;
}
|
Sets the response header based on type map index name. If DEBUG is greater than 2, the header
is not set.
@param mixed $type Friendly type name, i.e. 'html' or 'xml', or a full content-type,
like 'application/x-shockwave'.
@param array $options If $type is a friendly type name that is associated with
more than one type of content, $index is used to select which content-type to use.
@return boolean Returns false if the friendly type name given in $type does
not exist in the type map, or if the Content-type header has
already been set by this method.
@access public
@see RequestHandlerComponent::setContent()
|
respondAs
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function responseType() {
if ($this->__responseTypeSet == null) {
return null;
}
return $this->mapType($this->__responseTypeSet);
}
|
Returns the current response type (Content-type header), or null if none has been set
@return mixed A string content type alias, or raw content type if no alias map exists,
otherwise null
@access public
|
responseType
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function mapType($ctype) {
if (is_array($ctype)) {
$out = array();
foreach ($ctype as $t) {
$out[] = $this->mapType($t);
}
return $out;
} else {
$keys = array_keys($this->__requestContent);
$count = count($keys);
for ($i = 0; $i < $count; $i++) {
$name = $keys[$i];
$type = $this->__requestContent[$name];
if (is_array($type) && in_array($ctype, $type)) {
return $name;
} elseif (!is_array($type) && $type == $ctype) {
return $name;
}
}
return $ctype;
}
}
|
Maps a content-type back to an alias
@param mixed $type Content type
@return mixed Alias
@access public
|
mapType
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function __initializeTypes() {
if ($this->__typesInitialized) {
return;
}
if (isset($this->__requestContent[$this->ext])) {
$content = $this->__requestContent[$this->ext];
if (is_array($content)) {
$content = $content[0];
}
array_unshift($this->__acceptTypes, $content);
}
$this->__typesInitialized = true;
}
|
Initializes MIME types
@return void
@access private
|
__initializeTypes
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/request_handler.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/request_handler.php
|
MIT
|
function startup(&$controller) {
$this->_action = strtolower($controller->action);
$this->_methodsRequired($controller);
$this->_secureRequired($controller);
$this->_authRequired($controller);
$this->_loginRequired($controller);
$isPost = ($this->RequestHandler->isPost() || $this->RequestHandler->isPut());
$isRequestAction = (
!isset($controller->params['requested']) ||
$controller->params['requested'] != 1
);
if ($isPost && $isRequestAction && $this->validatePost) {
if ($this->_validatePost($controller) === false) {
if (!$this->blackHole($controller, 'auth')) {
return null;
}
}
}
$this->_generateToken($controller);
}
|
Component startup. All security checking happens here.
@param object $controller Instantiating controller
@return void
@access public
|
startup
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/security.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/security.php
|
MIT
|
function requirePost() {
$args = func_get_args();
$this->_requireMethod('Post', $args);
}
|
Sets the actions that require a POST request, or empty for all actions
@return void
@access public
@link http://book.cakephp.org/view/1299/requirePost
|
requirePost
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/security.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/security.php
|
MIT
|
function requireGet() {
$args = func_get_args();
$this->_requireMethod('Get', $args);
}
|
Sets the actions that require a GET request, or empty for all actions
@return void
@access public
|
requireGet
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/security.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/security.php
|
MIT
|
function requirePut() {
$args = func_get_args();
$this->_requireMethod('Put', $args);
}
|
Sets the actions that require a PUT request, or empty for all actions
@return void
@access public
|
requirePut
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/security.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/security.php
|
MIT
|
function requireDelete() {
$args = func_get_args();
$this->_requireMethod('Delete', $args);
}
|
Sets the actions that require a DELETE request, or empty for all actions
@return void
@access public
|
requireDelete
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/security.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/security.php
|
MIT
|
function requireSecure() {
$args = func_get_args();
$this->_requireMethod('Secure', $args);
}
|
Sets the actions that require a request that is SSL-secured, or empty for all actions
@return void
@access public
@link http://book.cakephp.org/view/1300/requireSecure
|
requireSecure
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/security.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/security.php
|
MIT
|
function requireAuth() {
$args = func_get_args();
$this->_requireMethod('Auth', $args);
}
|
Sets the actions that require an authenticated request, or empty for all actions
@return void
@access public
@link http://book.cakephp.org/view/1301/requireAuth
|
requireAuth
|
php
|
Datawalke/Coordino
|
cake/libs/controller/components/security.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/controller/components/security.php
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.