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

@ -6,4 +6,4 @@
// +---------------------------------------------------------------------------------------------------+ //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
1.1.2.2955
1.1.4.3083

View file

@ -17,11 +17,11 @@ background:#003d4c;
a{
color:#003d4c;
text-decoration:none;
text-decoration:underline;
}
a:hover{
color:#003d4c;
text-decoration:underline;
text-decoration:none;
}
a img{
@ -77,6 +77,7 @@ padding:0 2em;
#container{
text-align:left;
margin-left:0px;
min-width: 960px;
}
#header{
@ -189,9 +190,8 @@ background:url(images/nav_item_bg.gif) no-repeat bottom left;
table {
width: 100%;
border: 0px;
border: 1px solid #003d4c;
color:#333;
border: 1px solid #ccc;
background-color: #fff;
clear:both;
padding: 0;
@ -205,7 +205,7 @@ th {
border-right: 1px solid #003d4c;
border-bottom: 1px solid #003d4c;
text-align: center;
padding:2px;
padding:1px;
}
table tr td {
border-right: 1px solid #ccc;
@ -240,20 +240,29 @@ dd {
vertical-align:top;
}
/* scaffold buttons */
/* notices and errors */
p.error, error_message {
color: #e32000;
font-size: 18px;
background-color: #fff;
margin: 8px 4px;
}
p.error em {
font-size: 18px;
color: #003d4c;
}
.notice {
color: #DB8101;
background-color: #ddd;
display: block;
padding: 1em;
color: #656565;
font-size: 14px;
background-color: #f4f4f4;
padding: 4px;
display:block;
}
.tip {
color: #DB8101;
color: #e32000;
background-color: #ddd;
display: block;
padding: 1em;
}
@ -263,6 +272,3 @@ ul.actions {
margin-left: 10px;
width: 200px;
}
li {
list-style-image: url("images/arrow.gif");
}

View file

@ -129,12 +129,6 @@ form div label.labelCheckbox, form div label.labelRadio {
form div fieldset label.labelCheckbox, form div fieldset label.labelRadio {
margin: 0px 0px 5px 0px;
}
p.error {
color: #DB8101;
background-color: #DBA941;
font-size: 14px;
padding: 1em;
}
form div input, form div select, form div textarea {
padding: 1px 3px;

View file

@ -129,6 +129,8 @@
} else {
return false;
}
} else {
return true;
}
}
/**
@ -165,14 +167,14 @@
require(CAKE . 'app_controller.php');
}
}
$loadedControllers=array();
$loadedControllers = array();
foreach($paths->controllerPaths as $path) {
foreach(listClasses($path)as $controller) {
foreach(listClasses($path) as $controller) {
if (file_exists($path . $controller . '.php')) {
if (!key_exists($controller, $loadedControllers)) {
require($path . $controller . '.php');
$loadedControllers[$controller]=$controller;
$loadedControllers[$controller] = $controller;
}
}
}
@ -252,13 +254,126 @@
if (file_exists($file)) {
require($file);
return true;
} elseif (file_exists(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php'))
{
} elseif (file_exists(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php')) {
require(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php');
return true;
} else {
return false;
}
} else {
return true;
}
}
/**
* Loads a helper
*
* @param string $name Name of helper
* @return boolean Success
*/
function loadHelper($name) {
$paths = Configure::getInstance();
if ($name === null) {
return true;
}
if (!class_exists($name . 'Helper')) {
$name=Inflector::underscore($name);
foreach($paths->helperPaths as $path) {
if (file_exists($path . $name . '.php')) {
require($path . $name . '.php');
return true;
}
}
if ($helper_fn = fileExistsInPath(LIBS . 'view' . DS . 'helpers' . DS . $name . '.php')) {
if (file_exists($helper_fn)) {
require($helper_fn);
return true;
} else {
return false;
}
}
} else {
return true;
}
}
/**
* Loads a plugin's helper
*
* @param string $plugin Name of plugin
* @param string $helper Name of helper to load
* @return boolean Success
*/
function loadPluginHelper($plugin, $helper) {
if (!class_exists($helper . 'Helper')) {
$helper = Inflector::underscore($helper);
$file = APP . 'plugins' . DS . $plugin . DS . 'views' . DS . 'helpers' . DS . $helper . '.php';
if (file_exists($file)) {
require($file);
return true;
} else {
return false;
}
} else {
return true;
}
}
/**
* Loads a component
*
* @param string $name Name of component
* @return boolean Success
*/
function loadComponent($name) {
$paths = Configure::getInstance();
if ($name === null) {
return true;
}
if (!class_exists($name . 'Component')) {
$name=Inflector::underscore($name);
foreach($paths->componentPaths as $path) {
if (file_exists($path . $name . '.php')) {
require($path . $name . '.php');
return true;
}
}
if ($component_fn = fileExistsInPath(LIBS . 'controller' . DS . 'components' . DS . $name . '.php')) {
if (file_exists($component_fn)) {
require($component_fn);
return true;
} else {
return false;
}
}
} else {
return true;
}
}
/**
* Loads a plugin's component
*
* @param string $plugin Name of plugin
* @param string $helper Name of component to load
* @return boolean Success
*/
function loadPluginComponent($plugin, $component) {
if (!class_exists($component . 'Component')) {
$component = Inflector::underscore($component);
$file = APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . 'components' . DS . $component . '.php';
if (file_exists($file)) {
require($file);
return true;
} else {
return false;
}
} else {
return true;
}
}
/**
@ -344,7 +459,7 @@
*/
function debug($var = false, $showHtml = false) {
if (DEBUG) {
print "\n<pre>\n";
print "\n<pre class=\"cake_debug\">\n";
ob_start();
print_r($var);
$var = ob_get_clean();
@ -362,7 +477,7 @@
*/
if (!function_exists('getMicrotime')) {
function getMicrotime() {
list($usec, $sec)=explode(" ", microtime());
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
}
@ -886,7 +1001,7 @@
if (!is_dir($path)) {
return chmod($path, $mode);
}
$di = opendir($path);
$dir = opendir($path);
while($file = readdir($dir)) {
if ($file != '.' && $file != '..') {
@ -911,4 +1026,24 @@
return false;
}
}
/**
* removed the plugin name from the base url
*
* @param string $base
* @param string $plugin
* @return base url with plugin name removed if present
*/
function strip_plugin($base, $plugin){
if ($plugin != null) {
$base = preg_replace('/' . $plugin . '/', '', $base);
$base = str_replace('//', '', $base);
$pos1 = strrpos($base, '/');
$char = strlen($base) - 1;
if ($pos1 == $char) {
$base = substr($base, 0, $char);
}
}
return $base;
}
?>

View file

@ -105,6 +105,9 @@ blockend = "</div>"
; Tag template for a CSS link tag.
css = "<link rel="%s" type="text/css" href="%s" %s/>"
; Tag template for a CSS tag block.
style = "<style type="text/css"%s>%s</style>"
; Tag template for a charset meta-tag.
charset = "<meta http-equiv="Content-Type" content="text/html; charset=%s" />"

View file

@ -89,10 +89,7 @@ class Dispatcher extends Object {
if(!class_exists($ctrlClass)) {
if (!loadController($ctrlName)) {
$plugin = $ctrlName;
$pluginName = Inflector::camelize($params['action']);
$pluginClass = $pluginName.'Controller';
if (!loadPluginController(Inflector::underscore($ctrlName), $pluginName)) {
if(preg_match('/([\\.]+)/', $ctrlName)) {
return $this->cakeError('error404', array(
@ -104,10 +101,19 @@ class Dispatcher extends Object {
$missingController = true;
}
} else {
$params['plugin'] = Inflector::underscore($ctrlName);
}
}
}
}
if(isset($params['plugin'])){
$plugin = $params['plugin'];
$pluginName = Inflector::camelize($params['action']);
$pluginClass = $pluginName.'Controller';
$ctrlClass = $pluginClass;
$oldAction = $params['action'];
$params = $this->_restructureParams($params);
$plugin = Inflector::underscore($ctrlName);
$this->plugin = $plugin;
loadPluginModels($plugin);
$this->base = $this->base.'/'.Inflector::underscore($ctrlName);
@ -115,16 +121,12 @@ class Dispatcher extends Object {
if(empty($params['controller']) || !class_exists($pluginClass)) {
$params['controller'] = Inflector::underscore($ctrlName);
$ctrlClass = $ctrlName.'Controller';
if (!is_null($params['action'])) {
array_unshift($params['pass'], $params['action']);
}
$params['action'] = $oldAction;
}
}
}
}
}
if(defined('CAKE_ADMIN')) {
if(isset($params[CAKE_ADMIN])) {

View file

@ -34,7 +34,7 @@
* @package cake
* @subpackage cake.cake.libs
*/
class Configure extends Object{
class Configure extends Object {
/**
* Hold array with paths to view files
*
@ -56,6 +56,20 @@ class Configure extends Object{
* @access public
*/
var $modelPaths = array();
/**
* Enter description here...
*
* @var array
* @access public
*/
var $helperPaths = array();
/**
* Enter description here...
*
* @var array
* @access public
*/
var $componentPaths = array();
/**
* Return a singleton instance of Configure.
*
@ -81,7 +95,7 @@ class Configure extends Object{
$_this->modelPaths[] = MODELS;
if (isset($modelPaths)) {
foreach($modelPaths as $value) {
$this->modelPaths[] = $value;
$_this->modelPaths[] = $value;
}
}
}
@ -97,7 +111,7 @@ class Configure extends Object{
$_this->viewPaths[] = VIEWS . 'errors' . DS;
if (isset($viewPaths)) {
foreach($viewPaths as $value) {
$this->viewPaths[] = $value;
$_this->viewPaths[] = $value;
}
}
}
@ -112,7 +126,37 @@ class Configure extends Object{
$_this->controllerPaths[] = CONTROLLERS;
if (isset($controllerPaths)) {
foreach($controllerPaths as $value) {
$this->controllerPaths[] = $value;
$_this->controllerPaths[] = $value;
}
}
}
/**
* Sets the var helperPaths
*
* @param array $helperPaths
* @access private
*/
function __buildHelperPaths($helperPaths) {
$_this =& Configure::getInstance();
$_this->helperPaths[] = HELPERS;
if (isset($helperPaths)) {
foreach($helperPaths as $value) {
$_this->helperPaths[] = $value;
}
}
}
/**
* Sets the var componentPaths
*
* @param array $componentPaths
* @access private
*/
function __buildComponentPaths($componentPaths) {
$_this =& Configure::getInstance();
$_this->componentPaths[] = COMPONENTS;
if (isset($componentPaths)) {
foreach($componentPaths as $value) {
$_this->componentPaths[] = $value;
}
}
}
@ -124,14 +168,19 @@ class Configure extends Object{
* @access private
*/
function __loadBootstrap() {
$_this =&Configure::getInstance();
$modelPaths =null;
$viewPaths =null;
$controllerPaths=null;
$_this =& Configure::getInstance();
$modelPaths = null;
$viewPaths = null;
$controllerPaths = null;
$helperPaths = null;
$componentPaths = null;
require APP_PATH . 'config' . DS . 'bootstrap.php';
$_this->__buildModelPaths($modelPaths);
$_this->__buildViewPaths($viewPaths);
$_this->__buildControllerPaths($controllerPaths);
$_this->__buildHelperPaths($helperPaths);
$_this->__buildComponentPaths($componentPaths);
}
}
?>

View file

@ -1,6 +1,5 @@
<?php
/* SVN FILE: $Id$ */
/**
*
*
@ -25,22 +24,19 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
*
*
* @package cake
* @subpackage cake.cake.libs.controller
*/
class Component extends Object{
class Component extends Object {
/**
* Enter description here...
*
* @var unknown_type
*/
var $components = array();
/**
* Enter description here...
*
@ -53,25 +49,22 @@ class Component extends Object{
*
* @return Component
*/
function Component(&$controller) {
$this->controller=&$controller;
function __construct(&$controller) {
$this->controller =& $controller;
if ($this->controller->components !== false) {
$loaded=array();
$loaded=$this->_loadComponents($loaded, $this->controller->components);
$loaded = array();
$loaded = $this->_loadComponents($loaded, $this->controller->components);
foreach(array_keys($loaded)as $component) {
$tempComponent = &$loaded[$component];
$tempComponent =& $loaded[$component];
if (isset($tempComponent->components) && is_array($tempComponent->components)) {
foreach($tempComponent->components as $subComponent) {
$this->controller->{$component}->{$subComponent}= &$loaded[$subComponent];
$this->controller->{$component}->{$subComponent} =& $loaded[$subComponent];
}
}
}
}
}
/**
* Enter description here...
*
@ -81,59 +74,46 @@ class Component extends Object{
*/
function &_loadComponents(&$loaded, $components) {
foreach($components as $component) {
$componentCn = $component . 'Component';
if (in_array($component, array_keys($loaded)) !== true) {
$componentFn=Inflector::underscore($component) . '.php';
if (file_exists(
APP . 'plugins' . DS . $this->controller->plugin . DS . 'controllers' . DS . 'components' . DS . $componentFn)) {
$componentFn = APP . 'plugins' . DS . $this->controller->plugin . DS . 'controllers' . DS
. 'components' . DS . $componentFn;
} else if(file_exists(COMPONENTS . $componentFn)) {
$componentFn = COMPONENTS . $componentFn;
} else if($componentFn
= fileExistsInPath(LIBS . 'controller' . DS . 'components' . DS . $componentFn)) {
}
$componentCn=$component . 'Component';
if (is_file($componentFn)) {
if (!class_exists($componentCn)) {
require_once $componentFn;
if (is_null($this->controller->plugin) || !loadPluginComponent($this->controller->plugin, $component)) {
if (!loadComponent($component)) {
return $this->cakeError('missingComponentFile', array(array(
'className' => $this->controller->name,
'component' => $component,
'file' => Inflector::underscore($componentCn) . '.php',
'base' => $this->controller->base
)));
}
}
if (!class_exists($componentCn)) {
$componentFn = Inflector::underscore($component) . '.php';
return $this->cakeError('missingComponentClass', array(array(
'className' => $this->controller->name,
'component' => $component,
'file' => $componentFn,
'base' => $this->controller->base
)));
}
}
if (class_exists($componentCn) === true) {
if ($componentCn == 'SessionComponent') {
$param = $this->controller->base . '/';
} else {
$param = null;
}
$this->controller->{$component}=&new $componentCn($param);
$loaded[$component] =&$this->controller->{$component};
if (isset($this->controller->{$component}->components)
&& is_array($this->controller->{$component}->components)) {
$loaded = &$this->_loadComponents($loaded,
$this->controller->{$component}->components);
}
} else {
return $this->cakeError('missingComponentClass',
array(array('className' => $this->controller->name,
'component' => $component,
'file' => $componentFn,
'base' => $this->controller->base)));
}
} else {
return $this->cakeError('missingComponentFile',
array(array('className' => $this->controller->name,
'component' => $component,
'file' => $componentFn,
'base' => $this->controller->base)));
$this->controller->{$component} =& new $componentCn($param);
$loaded[$component] =& $this->controller->{$component};
if (isset($this->controller->{$component}->components) && is_array($this->controller->{$component}->components)) {
$loaded =& $this->_loadComponents($loaded, $this->controller->{$component}->components);
}
}
}
return $loaded;
}
}
?>

View file

@ -36,7 +36,8 @@
* @package cake
* @subpackage cake.cake.libs.controller.components
*/
class AclComponent extends Object{
class AclComponent extends Object {
var $_instance = null;
var $controller = true;
@ -47,7 +48,6 @@ class AclComponent extends Object{
function __construct() {
$this->getACL();
}
/**
* Static function used to gain an instance of the correct ACL class.
*
@ -56,20 +56,18 @@ class AclComponent extends Object{
function &getACL() {
if ($this->_instance == null) {
uses('controller' . DS . 'components' . DS . ACL_FILENAME);
$classname =ACL_CLASSNAME;
$this->_instance=new $classname;
$classname = ACL_CLASSNAME;
$this->_instance = new $classname;
}
return $this->_instance;
}
/**
* Empty class defintion, to be overridden in subclasses.
*
*/
function _initACL() {
}
/**
* Pass-thru function for ACL check instance.
*
@ -78,7 +76,6 @@ class AclComponent extends Object{
function check($aro, $aco, $action = "*") {
return $this->_instance->check($aro, $aco, $action);
}
/**
* Pass-thru function for ACL allow instance.
*
@ -87,7 +84,6 @@ class AclComponent extends Object{
function allow($aro, $aco, $action = "*") {
return $this->_instance->allow($aro, $aco, $action);
}
/**
* Pass-thru function for ACL deny instance.
*
@ -96,7 +92,6 @@ class AclComponent extends Object{
function deny($aro, $aco, $action = "*") {
return $this->_instance->deny($aro, $aco, $action);
}
/**
* Pass-thru function for ACL inherit instance.
*
@ -105,7 +100,6 @@ class AclComponent extends Object{
function inherit($aro, $aco, $action = "*") {
return $this->_instance->inherit($aro, $aco, $action);
}
/**
* Pass-thru function for ACL grant instance.
*
@ -114,7 +108,6 @@ class AclComponent extends Object{
function grant($aro, $aco, $action = "*") {
return $this->_instance->grant($aro, $aco, $action);
}
/**
* Pass-thru function for ACL grant instance.
*
@ -123,7 +116,6 @@ class AclComponent extends Object{
function revoke($aro, $aco, $action = "*") {
return $this->_instance->revoke($aro, $aco, $action);
}
/**
* Pass-thru function for ACL getAro instance.
*
@ -132,7 +124,6 @@ class AclComponent extends Object{
function getAro($id) {
return $this->_instance->getAro($id);
}
/**
* Pass-thru function for ACL getAco instance.
*
@ -142,4 +133,5 @@ class AclComponent extends Object{
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,7 +42,7 @@ 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...
@ -51,7 +50,6 @@ class DB_ACL extends AclBase{
*/
function __construct() {
}
/**
* Enter description here...
*
@ -61,22 +59,26 @@ class DB_ACL extends AclBase{
* @return unknown
*/
function check($aro, $aco, $action = "*") {
$Perms=new ArosAco();
$Aro =new Aro();
$Aco =new Aco();
$Perms = new ArosAco();
$Aro = new Aro();
$Aco = new Aco();
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 ($tmpAcoPath === null) {
return false;
}
$acoPath = array();
if ($action != '*' && !in_array('_' . $action, $permKeys)) {
trigger_error('ACO permissions key "' . $action . '" does not exist in DB_ACL::check()',
E_USER_NOTICE);
trigger_error('ACO permissions key "' . $action . '" does not exist in DB_ACL::check()', E_USER_NOTICE);
return false;
}
@ -85,9 +87,11 @@ class DB_ACL extends AclBase{
}
for($i = count($aroPath) - 1; $i >= 0; $i--) {
$perms = $Perms->findAll(array('ArosAco.aro_id' => $aroPath[$i]['Aro']['id'],
$perms = $Perms->findAll(array(
'ArosAco.aro_id' => $aroPath[$i]['Aro']['id'],
'ArosAco.aco_id' => $acoPath), null,
'Aco.lft asc');
'Aco.lft asc'
);
if ($perms == null || count($perms) == 0) {
continue;
@ -105,35 +109,32 @@ class DB_ACL extends AclBase{
return true;
} else {
switch($perm['ArosAco']['_' . $action])
{
case -1: return false;
switch($perm['ArosAco']['_' . $action]) {
case -1:
return false;
case 0:
continue;
break;
case 1: return true;
case 1:
return true;
break;
}
}
}
}
}
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();
$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);
@ -145,7 +146,7 @@ class DB_ACL extends AclBase{
}
if ($action == "*") {
$permKeys=$this->_getAcoKeys($Perms->loadInfo());
$permKeys = $this->_getAcoKeys($Perms->loadInfo());
foreach($permKeys as $key) {
$save[$key] = $value;
@ -159,16 +160,14 @@ class DB_ACL extends AclBase{
}
}
$save['aro_id']=$perms['aro'];
$save['aco_id']=$perms['aco'];
$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
*
@ -177,7 +176,6 @@ class DB_ACL extends AclBase{
function deny($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action, -1);
}
/**
* Inherit
*
@ -186,7 +184,6 @@ class DB_ACL extends AclBase{
function inherit($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action, 0);
}
/**
* Allow alias
*
@ -195,7 +192,6 @@ class DB_ACL extends AclBase{
function grant($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action);
}
/**
* Deny alias
*
@ -204,7 +200,6 @@ class DB_ACL extends AclBase{
function revoke($aro, $aco, $action = "*") {
return $this->deny($aro, $aco, $action);
}
/**
* Get an ARO object from the given id or alias
*
@ -214,7 +209,6 @@ class DB_ACL extends AclBase{
function getAro($id = null) {
return $this->__getObject($id, 'Aro');
}
/**
* Get an ACO object from the given id or alias
*
@ -224,9 +218,8 @@ class DB_ACL extends AclBase{
function getAco($id = null) {
return $this->__getObject($id, 'Aco');
}
/**
* Privaate method
* Private method
*
*/
function __getObject($id = null, $object) {
@ -235,25 +228,23 @@ class DB_ACL extends AclBase{
return null;
}
$obj=new $object;
$obj = new $object;
if (is_numeric($id)) {
$key='user_id';
$key = 'user_id';
if ($object == 'Aco') {
$key = 'object_id';
}
$conditions=array($object . '.' . $key => $id);
$conditions = array($object . '.' . $key => $id);
} else {
$conditions = array($object . '.alias' => $id);
}
$tmp =$obj->find($conditions);
$obj->id=$tmp[$object]['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
*
@ -262,27 +253,29 @@ class DB_ACL extends AclBase{
* @return array
*/
function getAclLink($aro, $aco) {
$Aro =new Aro();
$Aco =new Aco();
$Link =new ArosAco();
$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)
{
if ($obj['Aro'] == null || count($obj['Aro']) == 0 || $obj['Aco'] == null || count($obj['Aco']) == 0) {
return false;
}
return array('aro' => $obj['Aro']['id'],
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'])));
'link' => $Link->findAll(array(
'ArosAco.aro_id' => $obj['Aro']['id'],
'ArosAco.aco_id' => $obj['Aco']['id']
))
);
}
/**
* Enter description here...
*
@ -290,16 +283,16 @@ class DB_ACL extends AclBase{
* @return unknown
*/
function _getAcoKeys($keys) {
$newKeys=array();
$keys=$keys->value;
$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;
}
}
?>

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,
$return = $this->save(array($class => array(
$secondary_id => $link_id,
'alias' => $alias,
'lft' => $parent['lft'] + 1,
'rght' => $parent['lft'] + 2)));
'rght' => $parent['lft'] + 2
)));
$this->id = $this->getLastInsertID();
return $return;
}
@ -103,9 +105,7 @@ 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)) {
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;
}
@ -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,6 +38,11 @@ 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.
*
@ -54,11 +59,14 @@ class INI_ACL extends AclBase{
* @return boolean
*/
function check($aro, $aco, $aco_action = null) {
$aclConfig=$this->readConfigFile(CONFIGS . 'acl.ini.php');
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']));
$userDenies = $this->arrayTrim(explode(",", $aclConfig[$aro]['deny']));
if (array_search($aco, $userDenies)) {
//echo "User Denied!";
@ -68,7 +76,7 @@ class INI_ACL extends AclBase{
//Second, if the user is specifically allowed, then ALLOW
if (isset($aclConfig[$aro]['allow'])) {
$userAllows=$this->arrayTrim(explode(",", $aclConfig[$aro]['allow']));
$userAllows = $this->arrayTrim(explode(",", $aclConfig[$aro]['allow']));
if (array_search($aco, $userAllows)) {
//echo "User Allowed!";
@ -78,7 +86,7 @@ class INI_ACL extends AclBase{
//Check group permissions
if (isset($aclConfig[$aro]['groups'])) {
$userGroups=$this->arrayTrim(explode(",", $aclConfig[$aro]['groups']));
$userGroups = $this->arrayTrim(explode(",", $aclConfig[$aro]['groups']));
foreach($userGroups as $group) {
//If such a group exists,
@ -95,7 +103,7 @@ class INI_ACL extends AclBase{
//If the group is specifically allowed, then ALLOW
if (isset($aclConfig[$group]['allow'])) {
$groupAllows=$this->arrayTrim(explode(",", $aclConfig[$group]['allow']));
$groupAllows = $this->arrayTrim(explode(",", $aclConfig[$group]['allow']));
if (array_search($aco, $groupAllows)) {
//echo("Group Allowed!");
@ -118,21 +126,21 @@ class INI_ACL extends AclBase{
* @return array
*/
function readConfigFile($fileName) {
$fileLineArray=file($fileName);
$fileLineArray = file($fileName);
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, '=');
$delimiter = strpos($dataLine, '=');
if ($delimiter > 0) {
$key =strtolower(trim(substr($dataLine, 0, $delimiter)));
$value=trim(substr($dataLine, $delimiter + 1));
$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);

View file

@ -47,34 +47,31 @@ class RequestHandlerComponent extends Object{
var $disableStartup = false;
var $__requestContent = array('js' => 'text/javascript',
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'),
'xhtml' => array('application/xhtml+xml', 'application/xhtml', 'text/xhtml'),
'xml' => array('application/xml', 'text/xml'),
'rss' => 'application/rss+xml',
'atom' => 'application/atom+xml');
'atom' => 'application/atom+xml'
);
var $__acceptTypes = array();
function __construct() {
$this->__acceptTypes=explode(',', env('HTTP_ACCEPT'));
$this->__acceptTypes = explode(',', env('HTTP_ACCEPT'));
foreach($this->__acceptTypes as $i => $type) {
if (strpos($type, ';')) {
$type =explode(';', $type);
$this->__acceptTypes[$i]=$type[0];
$type = explode(';', $type);
$this->__acceptTypes[$i] = $type[0];
}
}
parent::__construct();
}
/**
* Startup
*
@ -85,10 +82,8 @@ class RequestHandlerComponent extends Object{
if ($this->disableStartup) {
return;
}
$this->setAjax($controller);
}
/**
* Sets a controller's layout based on whether or not the current call is Ajax
*
@ -103,7 +98,6 @@ class RequestHandlerComponent extends Object{
header ('Content-Type: text/html; charset=UTF-8');
}
}
/**
* Returns true if the current call is from Ajax, false otherwise
*
@ -116,7 +110,6 @@ class RequestHandlerComponent extends Object{
return false;
}
}
/**
* Returns true if the current call accepts an XML response, false otherwise
*
@ -125,7 +118,6 @@ class RequestHandlerComponent extends Object{
function isXml() {
return $this->accepts('xml');
}
/**
* Returns true if the current call accepts an RSS response, false otherwise
*
@ -134,7 +126,6 @@ class RequestHandlerComponent extends Object{
function isRss() {
return $this->accepts('rss');
}
/**
* Returns true if the current call accepts an RSS response, false otherwise
*
@ -143,7 +134,6 @@ class RequestHandlerComponent extends Object{
function isAtom() {
return $this->accepts('atom');
}
/**
* Returns true if the current call a POST request
*
@ -152,7 +142,6 @@ class RequestHandlerComponent extends Object{
function isPost() {
return (strtolower(env('REQUEST_METHOD')) == 'post');
}
/**
* Returns true if the current call a PUT request
*
@ -161,7 +150,6 @@ class RequestHandlerComponent extends Object{
function isPut() {
return (strtolower(env('REQUEST_METHOD')) == 'put');
}
/**
* Returns true if the current call a GET request
*
@ -170,7 +158,6 @@ class RequestHandlerComponent extends Object{
function isGet() {
return (strtolower(env('REQUEST_METHOD')) == 'get');
}
/**
* Returns true if the current call a DELETE request
*
@ -179,7 +166,6 @@ class RequestHandlerComponent extends Object{
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.
@ -190,10 +176,8 @@ class RequestHandlerComponent extends Object{
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
*
@ -202,9 +186,8 @@ class RequestHandlerComponent extends Object{
* @return void
*/
function setContent($name, $type) {
$this->__requestContent[$name]=$type;
$this->__requestContent[$name] = $type;
}
/**
* Gets the server name from which this request was referred
*
@ -218,10 +201,8 @@ class RequestHandlerComponent extends Object{
if (env('HTTP_X_FORWARDED_HOST') != null) {
$sess_host = env('HTTP_X_FORWARDED_HOST');
}
return trim(preg_replace('/:.*/', '', $sess_host));
}
/**
* Gets remote client IP
*
@ -239,16 +220,14 @@ class RequestHandlerComponent extends Object{
}
if (env('HTTP_CLIENTADDRESS') != null) {
$tmpipaddr=env('HTTP_CLIENTADDRESS');
$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
*
@ -257,53 +236,45 @@ class RequestHandlerComponent extends Object{
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);
$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);
$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);
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);
$str = $this->stripWhitespace($str);
$str = $this->stripImages($str);
$str = $this->stripScripts($str);
return $str;
}
/**
* Strips the specified tags from output
*
@ -313,14 +284,13 @@ class RequestHandlerComponent extends Object{
* @param string ...
*/
function stripTags() {
$params=params(func_get_args());
$str =$params[0];
$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);
$str = preg_replace('/<\/' . $params[$i] . '[^>]*>/i', '', $str);
}
return $str;
}
@ -344,7 +314,6 @@ class RequestHandlerComponent extends Object{
return true;
}
}
return false;
} else if(is_string($type)) {
// If client only accepts */*, then assume default HTML browser
@ -356,7 +325,7 @@ class RequestHandlerComponent extends Object{
return false;
}
$content=$this->__requestContent[$type];
$content = $this->__requestContent[$type];
if (is_array($content)) {
foreach($content as $c) {
@ -371,7 +340,6 @@ class RequestHandlerComponent extends Object{
}
}
}
/**
* Determines which content types the client prefers
*
@ -385,4 +353,5 @@ class RequestHandlerComponent extends Object{
}
}
}
?>

View file

@ -44,10 +44,22 @@ class SessionComponent extends Object{
*
*/
function __construct($base = null) {
$this->CakeSession=new CakeSession($base);
$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...
*
@ -60,7 +72,6 @@ class SessionComponent extends Object{
function write($name, $value) {
return $this->CakeSession->writeSessionVar($name, $value);
}
/**
* Enter description here...
*
@ -73,7 +84,6 @@ class SessionComponent extends Object{
function read($name = null) {
return $this->CakeSession->readSessionVar($name);
}
/**
* Enter description here...
*
@ -85,7 +95,6 @@ class SessionComponent extends Object{
function del($name) {
return $this->CakeSession->delSessionVar($name);
}
/**
* Enter description here...
* @param unknown_type $name
@ -94,7 +103,6 @@ class SessionComponent extends Object{
function delete($name) {
return $this->del($name);
}
/**
* Enter description here...
*
@ -106,7 +114,6 @@ class SessionComponent extends Object{
function check($name) {
return $this->CakeSession->checkSessionVar($name);
}
/**
* Enter description here...
*
@ -117,7 +124,6 @@ class SessionComponent extends Object{
function error() {
return $this->CakeSession->getLastError();
}
/**
* Enter description here...
*
@ -135,17 +141,23 @@ class SessionComponent extends Object{
} 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);
$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();
*
@ -160,7 +172,6 @@ class SessionComponent extends Object{
return false;
}
}
/**
* Enter description here...
*
@ -172,7 +183,6 @@ class SessionComponent extends Object{
function renew() {
$this->CakeSession->renew();
}
/**
* Enter description here...
*
@ -185,7 +195,6 @@ class SessionComponent extends Object{
function valid() {
return $this->CakeSession->isValid();
}
/**
* Enter description here...
*
@ -197,4 +206,5 @@ class SessionComponent extends Object{
$this->CakeSession->destroyInvalid();
}
}
?>

View file

@ -54,6 +54,12 @@ class Controller extends Object{
* @var string Current URL
*/
var $here = null;
/**
* The webroot of the application
*
* @var string
*/
var $webroot = null;
/**
* Action to be performed.
*
@ -75,6 +81,20 @@ class Controller extends Object{
* @access protected
*/
var $helpers = array('Html');
/**
* Parameters received in the current request, i.e. GET and POST data
*
* @var array
* @access public
*/
var $params = array();
/**
* POST'ed model data
*
* @var array
* @access public
*/
var $data = array();
/**
* Enter description here...
*
@ -186,34 +206,32 @@ class Controller extends Object{
*/
function __construct() {
if ($this->name === null) {
$r=null;
$r = null;
if (!preg_match('/(.*)Controller/i', get_class($this), $r)) {
die ("Controller::__construct() : Can't get or parse my own class name, exiting.");
}
$this->name=$r[1];
$this->name = $r[1];
}
if ($this->viewPath == null) {
$this->viewPath = Inflector::underscore($this->name);
}
$this->modelClass=ucwords(Inflector::singularize($this->name));
$this->modelKey =Inflector::underscore($this->modelClass);
$this->modelClass = ucwords(Inflector::singularize($this->name));
$this->modelKey = Inflector::underscore($this->modelClass);
if (!defined('AUTO_SESSION') || AUTO_SESSION == true) {
$this->components[] = 'Session';
}
if (is_subclass_of($this, 'AppController')) {
$appVars=get_class_vars('AppController');
$appVars = get_class_vars('AppController');
foreach(array('components',
'helpers',
'uses')as $var) {
foreach(array('components', 'helpers', 'uses') as $var) {
if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
$diff =array_diff($appVars[$var], $this->{$var});
$this->{$var}=array_merge($this->{$var}, $diff);
$diff = array_diff($appVars[$var], $this->{$var});
$this->{$var} = array_merge($this->{$var}, $diff);
}
}
}
@ -255,7 +273,7 @@ class Controller extends Object{
} else {
$this->_persist($this->modelClass . 'registry', true, $object, 'registry');
$this->_persist($this->modelClass, true, $object);
$this->modelNames[]=$this->modelClass;
$this->modelNames[] = $this->modelClass;
return true;
}
} elseif ($this->uses === false) {
@ -306,11 +324,12 @@ class Controller extends Object{
function redirect($url, $status = null) {
$this->autoRender = false;
$pos = strpos($url, '://');
$base = strip_plugin($this->base, $this->plugin);
if ($pos === false) {
if (strpos($url, '/') !== 0) {
$url = '/' . $url;
}
$url = $this->base . $url;
$url = $base . $url;
}
if (function_exists('session_write_close')) {
@ -318,7 +337,8 @@ class Controller extends Object{
}
if ($status != null) {
$codes = array(100 => "HTTP/1.1 100 Continue",
$codes = array(
100 => "HTTP/1.1 100 Continue",
101 => "HTTP/1.1 101 Switching Protocols",
200 => "HTTP/1.1 200 OK",
201 => "HTTP/1.1 201 Created",
@ -356,7 +376,8 @@ class Controller extends Object{
501 => "HTTP/1.1 501 Not Implemented",
502 => "HTTP/1.1 502 Bad Gateway",
503 => "HTTP/1.1 503 Service Unavailable",
504 => "HTTP/1.1 504 Gateway Time-out");
504 => "HTTP/1.1 504 Gateway Time-out"
);
if (isset($codes[$status])) {
header($codes[$status]);
@ -439,16 +460,11 @@ class Controller extends Object{
* @return unknown
*/
function render($action = null, $layout = null, $file = null) {
$viewClass=$this->view;
if ($this->view != 'View' && !class_exists($viewClass)) {
$viewClass = $this->view;
if ($this->view != 'View') {
$viewClass = $this->view . 'View';
loadView($this->view);
}
if ($this->view != 'View') {
$viewClass = $this->view . 'View';
}
$this->beforeRender();
$this->_viewClass =& new $viewClass($this);
@ -459,7 +475,7 @@ class Controller extends Object{
}
}
}
$this->autoRender=false;
$this->autoRender = false;
return $this->_viewClass->render($action, $layout, $file);
}
/**
@ -472,6 +488,7 @@ class Controller extends Object{
function referer($default = null, $local = false) {
$ref = env('HTTP_REFERER');
$base = FULL_BASE_URL . $this->webroot;
if ($ref != null && (defined(FULL_BASE_URL) || FULL_BASE_URL)) {
if (strpos($ref, $base) === 0) {
return substr($ref, strlen($base) - 1);
@ -545,8 +562,8 @@ class Controller extends Object{
* @param unknown_type $time
*/
function flashOut($message, $url, $pause = 1) {
$this->autoRender=false;
$this->autoLayout=false;
$this->autoRender = false;
$this->autoLayout = false;
$this->set('url', $url);
$this->set('message', $message);
$this->set('pause', $pause);
@ -587,7 +604,7 @@ class Controller extends Object{
$fieldNames[$tabl['name']]['prompt'] = Inflector::humanize($niceName);
$fieldNames[$tabl['name']]['model'] = $fkNames[1];
$fieldNames[$tabl['name']]['modelKey'] = $this->{$model}->tableToModel[$fieldNames[$tabl['name']]['table']];
$fieldNames[$tabl['name']]['controller']=Inflector::pluralize($this->{$model}->tableToModel[$fkNames[0]]);
$fieldNames[$tabl['name']]['controller'] = Inflector::pluralize($this->{$model}->tableToModel[$fkNames[0]]);
$fieldNames[$tabl['name']]['foreignKey'] = true;
} else if('created' != $tabl['name'] && 'updated' != $tabl['name']) {
@ -597,8 +614,8 @@ class Controller extends Object{
} else if('updated' == $tabl['name']) {
$fieldNames[$tabl['name']]['prompt'] = 'Modified';
}
$fieldNames[$tabl['name']]['tagName']=$model . '/' . $tabl['name'];
$validationFields=$objRegistryModel->validate;
$fieldNames[$tabl['name']]['tagName'] = $model . '/' . $tabl['name'];
$validationFields = $objRegistryModel->validate;
if (isset($validationFields[$tabl['name']])) {
if (VALID_NOT_EMPTY == $validationFields[$tabl['name']]) {
@ -618,7 +635,7 @@ class Controller extends Object{
switch($type) {
case "text":
$fieldNames[$tabl['name']]['type']='area';
$fieldNames[$tabl['name']]['type'] = 'area';
break;
case "string":
if (isset($fieldNames[$tabl['name']]['foreignKey'])) {
@ -673,7 +690,7 @@ class Controller extends Object{
}
}
}
$fieldNames[$tabl['name']]['selected']=$data[$model][$tabl['name']];
$fieldNames[$tabl['name']]['selected'] = $data[$model][$tabl['name']];
}
} else {
$fieldNames[$tabl['name']]['type'] = 'input';
@ -681,7 +698,7 @@ class Controller extends Object{
break;
case "enum":
$fieldNames[$tabl['name']]['type']='select';
$fieldNames[$tabl['name']]['type'] = 'select';
$fieldNames[$tabl['name']]['options'] = array();
$enumValues = split(',', $fieldLength);
@ -864,4 +881,5 @@ class Controller extends Object{
return false;
}
}
?>

View file

@ -103,7 +103,7 @@ class File extends Object{
* @return boolean Success
*/
function write($data, $mode = 'w') {
$fil = $this->getFullPath();
$file = $this->getFullPath();
if (!($handle = fopen($file, $mode))) {
print ("[File] Could not open $file with mode $mode!");
return false;

View file

@ -48,7 +48,6 @@ class ConnectionManager extends Object{
* @access public
*/
var $config = null;
/**
* Holds instances DataSource objects
*
@ -56,7 +55,6 @@ class ConnectionManager extends Object{
* @access private
*/
var $_dataSources = array();
/**
* Contains a list of all file and class names used in Connection settings
*
@ -64,7 +62,6 @@ class ConnectionManager extends Object{
* @access private
*/
var $_connectionsEnum = array();
/**
* Constructor.
*
@ -74,7 +71,6 @@ class ConnectionManager extends Object{
$this->config = new DATABASE_CONFIG();
}
}
/**
* Gets a reference to the ConnectionManger object instance
*
@ -89,7 +85,6 @@ class ConnectionManager extends Object{
return $instance[0];
}
/**
* Gets a reference to a DataSource object
*
@ -97,29 +92,43 @@ class ConnectionManager extends Object{
* @return object
*/
function &getDataSource($name) {
$_this=&ConnectionManager::getInstance();
$_this =& ConnectionManager::getInstance();
if (in_array($name, array_keys($_this->_dataSources))) {
return $_this->_dataSources[$name];
}
$connections=$_this->enumConnectionObjects();
$connections = $_this->enumConnectionObjects();
if (in_array($name, array_keys($connections))) {
$conn =$connections[$name];
$class=$conn['classname'];
$conn = $connections[$name];
$class = $conn['classname'];
$_this->loadDataSource($name);
$_this->_dataSources[$name] =&new $class($_this->config->{$name});
$_this->_dataSources[$name]->configKeyName=$name;
$_this->_dataSources[$name] =& new $class($_this->config->{$name});
$_this->_dataSources[$name]->configKeyName = $name;
} else {
trigger_error("ConnectionManager::getDataSource - Non-existent data source {$name}",
E_USER_ERROR);
trigger_error("ConnectionManager::getDataSource - Non-existent data source {$name}", E_USER_ERROR);
return null;
}
return $_this->_dataSources[$name];
}
/**
* Gets a DataSource name from an object reference
*
* @param object $source
* @return string
*/
function getSourceName(&$source) {
$_this =& ConnectionManager::getInstance();
$names = array_keys($_this->_dataSources);
for ($i = 0; $i < count($names); $i++) {
if ($_this->_dataSources[$names[$i]] === $source) {
return $names[$i];
}
}
return null;
}
/**
* Loads the DataSource class for the given connection name
*
@ -127,9 +136,10 @@ class ConnectionManager extends Object{
* @return boolean True on success, false on failure or if the class is already loaded
*/
function loadDataSource($connName) {
$_this =&ConnectionManager::getInstance();
$connections=$_this->enumConnectionObjects();
$conn =$connections[$connName];
$_this =& ConnectionManager::getInstance();
$connections = $_this->enumConnectionObjects();
$conn = $connections[$connName];
if (class_exists($conn['classname'])) {
return false;
@ -138,13 +148,12 @@ class ConnectionManager extends Object{
if (fileExistsInPath(LIBS . 'model' . DS . $conn['filename'] . '.php')) {
require (LIBS . 'model' . DS . $conn['filename'] . '.php');
} else if(file_exists(MODELS . $conn['filename'] . '.php')) {
require (MODELS . $conn['filename'] . '.php');
require (MODELS . 'datasources' . DS . $conn['filename'] . '.php');
} else {
trigger_error('Unable to load DataSource file ' . $conn['filename'] . '.php', E_USER_ERROR);
return null;
}
}
/**
* Gets a list of class and file names associated with the user-defined DataSource connections
*
@ -152,30 +161,30 @@ class ConnectionManager extends Object{
* (as defined in Connections), and the value is an array with keys 'filename' and 'classname'.
*/
function enumConnectionObjects() {
$_this=&ConnectionManager::getInstance();
$_this =& ConnectionManager::getInstance();
if (!empty($_this->_connectionsEnum)) {
return $_this->_connectionsEnum;
}
$connections=get_object_vars($_this->config);
$connections = get_object_vars($_this->config);
if ($connections != null) {
foreach($connections as $name => $config) {
if (isset($config['driver']) && $config['driver'] != null && $config['driver'] != '') {
$filename='dbo_' . $config['driver'];
$classname=Inflector::camelize(strtolower('DBO_' . $config['driver']));
if (!isset($config['datasource'])) {
$config['datasource'] = 'dbo';
}
if (isset($config['driver']) && $config['driver'] != null && !empty($config['driver'])) {
$filename = $config['datasource'] . DS . $config['datasource'] . '_' . $config['driver'];
$classname = Inflector::camelize(strtolower($config['datasource'] . '_' . $config['driver']));
} else {
$filename=$config['datasource'] . '_source';
$classname=Inflector::camelize(strtolower($config['datasource'] . '_source'));
$filename = $config['datasource'] . '_source';
$classname = Inflector::camelize(strtolower($config['datasource'] . '_source'));
}
// TODO 2.0: Change 'dbo' to $config['datasource']
$filename='dbo' . DS . $filename;
$_this->_connectionsEnum[$name]=array('filename' => $filename,
'classname' => $classname);
$_this->_connectionsEnum[$name] = array('filename' => $filename, 'classname' => $classname);
}
return $this->_connectionsEnum;
} else {
$this->cakeError('missingConnection', array(array('className' => 'ConnectionManager')));

View file

@ -222,18 +222,18 @@ class DataSource extends Object{
*/
function __cacheDescription($object, $data = null) {
if (DEBUG > 0) {
$expires = "+10 seconds";
$expires = "+15 seconds";
} else {
$expires = "+999 days";
}
if ($data !== null) {
$this->__descriptions[$object]=&$data;
$this->__descriptions[$object] =& $data;
$cache = serialize($data);
} else {
$cache = null;
}
$new = cache('models' . DS . strtolower(get_class($this)) . '_' . $object, $cache, $expires);
$new = cache('models' . DS . ConnectionManager::getSourceName($this) . '_' . $object, $cache, $expires);
if ($new != null) {
$new = unserialize($new);
@ -276,10 +276,10 @@ class DataSource extends Object{
if (isset($this->__descriptions[$model->table])) {
return $this->__descriptions[$model->table];
}
$cache=$this->__cacheDescription($model->table);
$cache = $this->__cacheDescription($model->tablePrefix.$model->table);
if ($cache !== null) {
$this->__descriptions[$model->table]=&$cache;
$this->__descriptions[$model->table] =& $cache;
return $cache;
}
return null;
@ -355,11 +355,11 @@ class DataSource extends Object{
* @param unknown_type $assocData
* @param Model $model
* @param Model $linkModel
* @param unknown_type $index
* @param array $stack
* @return unknown
*/
function insertQueryData($query, $data, $association, $assocData, &$model, &$linkModel, $index) {
$keys=array('{$__cakeID__$}', '{$__cakeForeignKey__$}');
function insertQueryData($query, $data, $association, $assocData, &$model, &$linkModel, $stack) {
$keys = array('{$__cakeID__$}', '{$__cakeForeignKey__$}');
foreach($keys as $key) {
$val = null;
@ -367,10 +367,22 @@ class DataSource extends Object{
if (strpos($query, $key) !== false) {
switch($key) {
case '{$__cakeID__$}':
if (isset($data[$index][$model->name])) {
if (isset($data[$index][$model->name][$model->primaryKey])) {
$val = $data[$index][$model->name][$model->primaryKey];
if (isset($data[$model->name]) || isset($data[$association])) {
if (isset($data[$model->name][$model->primaryKey])) {
$val = $data[$model->name][$model->primaryKey];
} elseif (isset($data[$association][$model->primaryKey])) {
$val = $data[$association][$model->primaryKey];
}
} else {
$found = false;
foreach (array_reverse($stack) as $assoc) {
if (isset($data[$assoc]) && isset($data[$assoc][$model->primaryKey])) {
$val = $data[$assoc][$model->primaryKey];
$found = true;
break;
}
}
if (!$found) {
$val = '';
}
}
@ -380,10 +392,24 @@ class DataSource extends Object{
foreach($model->$name as $assocName => $assoc) {
if ($assocName === $association) {
if (isset($assoc['foreignKey'])) {
$foreignKey=$assoc['foreignKey'];
$foreignKey = $assoc['foreignKey'];
if (isset($data[$index][$model->name][$foreignKey])) {
$val = $data[$index][$model->name][$foreignKey];
if (isset($data[$model->name][$foreignKey])) {
$val = $data[$model->name][$foreignKey];
} elseif (isset($data[$association][$foreignKey])) {
$val = $data[$association][$foreignKey];
} else {
$found = false;
foreach (array_reverse($stack) as $assoc) {
if (isset($data[$assoc]) && isset($data[$assoc][$model->primaryKey])) {
$val = $data[$assoc][$model->primaryKey];
$found = true;
break;
}
}
if (!$found) {
$val = '';
}
}
}
break 3;
@ -442,13 +468,6 @@ class DataSource extends Object{
}
return $data;
}
/**
* To-be-overridden in subclasses.
*
*/
function buildSchemaQuery($schema) {
die ("Implement in DBO");
}
/**
* Closes the current datasource.
*

View file

@ -129,7 +129,7 @@ class DboSource extends DataSource {
}
if (DEBUG > 0) {
$expires = "+10 seconds";
$expires = "+30 seconds";
} else {
$expires = "+999 days";
}
@ -137,7 +137,7 @@ class DboSource extends DataSource {
if ($data != null) {
$data = serialize($data);
}
$filename = strtolower(get_class($this)) . '_' . $this->config['database'] . '_list';
$filename = ConnectionManager::getSourceName($this) . '_' . $this->config['database'] . '_list';
$new = cache('models' . DS . $filename, $data, $expires);
if ($new != null) {
@ -345,7 +345,7 @@ class DboSource extends DataSource {
} else {
$text = 'query';
}
print ("<table border = \"0\">\n<caption>{$this->_queriesCnt} {$text} took {$this->_queriesTime} ms</caption>\n");
print ("<table id=\"cakeSqlLog\" border = \"0\">\n<caption>{$this->_queriesCnt} {$text} took {$this->_queriesTime} ms</caption>\n");
print ("<thead>\n<tr><th>Nr</th><th>Query</th><th>Error</th><th>Affected</th><th>Num. rows</th><th>Took (ms)</th></tr>\n</thead>\n<tbody>\n");
foreach($log as $k => $i) {
@ -481,7 +481,7 @@ class DboSource extends DataSource {
}
foreach($model->__associations as $type) {
foreach($model->{$type}as $assoc => $assocData) {
foreach($model->{$type} as $assoc => $assocData) {
if ($model->recursive > -1) {
$linkModel =& $model->{$assocData['className']};
@ -506,7 +506,7 @@ class DboSource extends DataSource {
if ($model->recursive > 0) {
foreach($model->__associations as $type) {
foreach($model->{$type}as $assoc => $assocData) {
foreach($model->{$type} as $assoc => $assocData) {
$db = null;
$linkModel =& $model->{$assocData['className']};
@ -524,7 +524,8 @@ class DboSource extends DataSource {
}
if (isset($db) && $db != null) {
$db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1);
$stack = array($assoc);
$db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1, $stack);
unset($db);
}
}
@ -546,26 +547,34 @@ class DboSource extends DataSource {
* @return unknown
*/
function __filterResults(&$results, &$model, $filtered = array()) {
$filtering = array();
$associations = am($model->belongsTo, $model->hasOne, $model->hasMany, $model->hasAndBelongsToMany);
$count = count($results);
for($i = 0; $i < $count; $i++) {
if (is_array($results[$i])) {
$keys = array_keys($results[$i]);
$count2 = count($keys);
for($j = 0; $j < $count2; $j++) {
$key = $keys[$j];
if ($model->name != $key && !in_array($key, $filtered)) {
$key = $keys[$j];
if (isset($associations[$key])) {
$className = $associations[$key]['className'];
} else {
$className = $key;
}
if ($model->name != $className && !in_array($key, $filtered)) {
if (!in_array($key, $filtering)) {
$filtering[] = $key;
}
if (isset($model->{$key}) && is_object($model->{$key})) {
$data = $model->{$key}->afterFind(array(array($key => $results[$i][$key])));
if (isset($model->{$className}) && is_object($model->{$className})) {
$data = $model->{$className}->afterFind(array(array($key => $results[$i][$key])));
} else {
$data = $model->{$associations[$key]['className']}->afterFind(array(array($key => $results[$i][$key])));
$data = $model->{$className}->afterFind(array(array($key => $results[$i][$key])));
}
$results[$i][$key] = $data[0][$key];
}
@ -586,8 +595,9 @@ class DboSource extends DataSource {
* @param unknown_type $external
* @param unknown_type $resultSet
* @param integer $recursive Number of levels of association
* @param array $stack
*/
function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive) {
function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive, $stack) {
$query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet);
if ($query) {
@ -601,20 +611,24 @@ class DboSource extends DataSource {
}
return null;
}
$count = count($resultSet);
$count = count($resultSet);
for($i = 0; $i < $count; $i++) {
$row =& $resultSet[$i];
$q = $this->insertQueryData($query, $resultSet, $association, $assocData, $model, $linkModel, $i);
$q = $this->insertQueryData($query, $resultSet[$i], $association, $assocData, $model, $linkModel, $stack);
$fetch = $this->fetchAll($q, $model->cacheQueries, $model->name);
if (!empty($fetch) && is_array($fetch)) {
if ($recursive > 0) {
foreach($linkModel->__associations as $type1) {
foreach($linkModel->{$type1}as $assoc1 => $assocData1) {
foreach($linkModel->{$type1} as $assoc1 => $assocData1) {
$deepModel =& $linkModel->{$assocData1['className']};
if ($deepModel->name != $model->name) {
$this->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1);
$tmpStack = $stack;
$tmpStack[] = $assoc1;
$this->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack);
}
}
}
@ -637,6 +651,7 @@ class DboSource extends DataSource {
* @param unknown_type $type
*/
function __mergeAssociation(&$data, $merge, $association, $type) {
if (isset($merge[0]) && !isset($merge[0][$association])) {
$association = Inflector::pluralize($association);
}
@ -711,7 +726,7 @@ class DboSource extends DataSource {
$sql = $queryData['selfJoin'][0];
$sql .= ' ' . join(' ', $queryData['joins']);
$sql .= $this->conditions($queryData['conditions']) . ' ' . $this->order($queryData['order']);
$sql .= ' ' . $this->limit($queryData['limit']);
$sql .= ' ' . $this->limit($queryData['limit'], $queryData['offset']);
$result = preg_replace('/FROM/', $replace, $sql);
return $result;
}
@ -730,8 +745,11 @@ class DboSource extends DataSource {
* @return unknown
*/
function generateAssociationQuery(&$model, &$linkModel, $type, $association = null, $assocData = array(), &$queryData, $external = false, &$resultSet) {
$this->__scrubQueryData($queryData);
$this->__scrubQueryData($assocData);
$joinedOnSelf = false;
if ($linkModel == null) {
if (array_key_exists('selfJoin', $queryData)) {
return $this->generateSelfAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet);
@ -746,7 +764,7 @@ class DboSource extends DataSource {
$sql = 'SELECT ';
if ($this->goofyLimit) {
$sql .= $this->limit($queryData['limit']);
$sql .= $this->limit($queryData['limit'], $queryData['offset']);
}
$sql .= ' ' . join(', ', $this->fields($model, $model->name, $queryData['fields'])) . $joinFields . ' FROM ';
$sql .= $this->fullTableName($model) . ' ' . $this->alias;
@ -754,7 +772,7 @@ class DboSource extends DataSource {
$sql .= $this->conditions($queryData['conditions']) . ' ' . $this->order($queryData['order']);
if (!$this->goofyLimit) {
$sql .= ' ' . $this->limit($queryData['limit']);
$sql .= ' ' . $this->limit($queryData['limit'], $queryData['offset']);
}
}
return $sql;
@ -779,7 +797,7 @@ class DboSource extends DataSource {
$limit = '';
if (isset($queryData['limit']) && !empty($queryData['limit'])) {
$limit = $this->limit($queryData['limit']);
$limit = $this->limit($queryData['limit'], $queryData['offset']);
}
$sql = 'SELECT ';
@ -851,7 +869,7 @@ class DboSource extends DataSource {
if ($external) {
$limit = '';
if (isset($assocData['limit'])) {
$limit = $this->limit($assocData['limit']);
$limit = $this->limit($assocData['limit'], $queryData['offset']);
}
if (!isset($assocData['fields'])) {
@ -905,11 +923,20 @@ class DboSource extends DataSource {
if (isset($assocData['conditions']) && !empty($assocData['conditions'])) {
if (is_array($queryData['conditions'])) {
$queryData['conditions'] = array_merge($assocData['conditions'], $queryData['conditions']);
$queryData['conditions'] = array_merge((array)$assocData['conditions'], $queryData['conditions']);
} else {
if (!empty($queryData['conditions'])){
$queryData['conditions'] = array($queryData['conditions']);
if (is_array($assocData['conditions'])){
array_merge($queryData['conditions'],$assocData['conditions']);
} else {
$queryData['conditions'][] = $assocData['conditions'];
}
} else {
$queryData['conditions'] = $assocData['conditions'];
}
}
}
if (!in_array($sql, $queryData['joins'])) {
$queryData['joins'][] = $sql;
@ -925,7 +952,7 @@ class DboSource extends DataSource {
$limit = '';
if (isset($assocData['limit'])) {
$limit = $this->limit($assocData['limit']);
$limit = $this->limit($assocData['limit'], $queryData['offset']);
}
$conditions = $assocData['conditions'];
@ -966,7 +993,7 @@ class DboSource extends DataSource {
$limit = '';
if (isset($assocData['limit'])) {
$limit = $this->limit($assocData['limit']);
$limit = $this->limit($assocData['limit'], $queryData['offset']);
}
$sql = 'SELECT ';
@ -1005,9 +1032,14 @@ class DboSource extends DataSource {
function update(&$model, $fields = array(), $values = array()) {
$updates = array();
$combined = array_combine($fields, $values);
foreach($combined as $field => $value) {
if ($value === null) {
$updates[] = $this->name($field) . ' = NULL';
} else {
$updates[] = $this->name($field) . ' = ' . $this->value($value, $model->getColumnType($field));
}
}
$sql = 'UPDATE ' . $this->fullTableName($model);
$sql .= ' SET ' . join(',', $updates);
$sql .= ' WHERE ' . $this->name($model->primaryKey) . ' = ' . $this->value($model->getID(), $model->getColumnType($model->primaryKey));
@ -1091,6 +1123,10 @@ class DboSource extends DataSource {
if (!isset($data['limit'])) {
$data['limit'] = '';
}
if (!isset($data['offset'])) {
$data['offset'] = null;
}
}
/**
* Generates the fields list of an SQL query.
@ -1193,30 +1229,34 @@ class DboSource extends DataSource {
}
function conditionKeysToString($conditions) {
$data = null;
$out = array();
$operator = null;
$bool = array('and', 'or', 'and not', 'or not', 'xor', '||', '&&');
foreach($conditions as $key => $value) {
if (in_array(strtolower(trim($key)), $bool)) {
$out[] = '(' . join(') ' . $key . ' (', $this->conditionKeysToString($value)) . ')';
} else {
if (is_array($value)) {
$data = $this->name($key) . ' IN (';
if (is_array($value) && !empty($value)) {
$keys = array_keys($value);
if ($keys[0] === 0) {
$data = $this->name($key) . ' IN (';
foreach($value as $valElement) {
$data .= $this->value($valElement) . ', ';
}
$data[strlen($data) - 2] = ')';
} else {
$out[] = '(' . join(') AND (', $this->conditionKeysToString($value)) . ')';
}
} elseif(is_numeric($key)) {
$data = ' ' . $value;
} elseif($value === null) {
$data = $this->name($key) . ' = NULL';
} elseif($value === '') {
$data = $this->name($key) . " = ''";
} elseif(preg_match(
'/^([a-z]*\\([a-z0-9]*\\)\\x20?|(?:like\\x20)|(?:or\\x20)|(?:between\\x20)|(?:regexp\\x20)|[<> = !]{1,3}\\x20?)?(.*)/i', $value, $match)) {
} elseif(preg_match('/^([a-z]*\\([a-z0-9]*\\)\\x20?|(?:like\\x20)|(?:or\\x20)|(?:between\\x20)|(?:regexp\\x20)|[<> = !]{1,3}\\x20?)?(.*)/i', $value, $match)) {
if (preg_match('/(\\x20[\\w]*\\x20)/', $key, $regs)) {
$clause = $regs['1'];
$key = preg_replace('/' . $regs['1'] . '/', '', $key);
@ -1238,7 +1278,9 @@ class DboSource extends DataSource {
}
}
$out[] = $operator . $data;
if ($data != null) {
$out[] = $data;
}
}
}
return $out;
@ -1370,8 +1412,14 @@ class DboSource extends DataSource {
if ($this->fullDebug) {
$this->showLog();
}
$this->_conn = NULL;
$this->connected = false;
$this->disconnect();
}
/**
* To-be-overridden in subclasses.
*
*/
function buildSchemaQuery($schema) {
die ("Implement in DBO");
}
/**
* Destructor. Closes connection to the database.
@ -1392,7 +1440,8 @@ class DboSource extends DataSource {
* @return boolean True if the table has a matching record, else false
*/
function hasAny($model, $sql) {
$out = $this->one("SELECT COUNT(*) " . $this->alias . "count FROM " . $this->fullTableName($model) . ($sql ? ' ' . $sql : ''));
$sql = $this->conditions($sql);
$out = $this->one("SELECT COUNT(*) " . $this->alias . "count FROM " . $this->fullTableName($model) . ' ' . ($sql ? ' ' . $sql : 'WHERE 1 = 1'));
if (is_array($out)) {
return $out[0]['count'];

View file

@ -0,0 +1,452 @@
<?php
/* SVN FILE: $Id$ */
/**
* MySQLi layer for DBO
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
* Copyright (c) 2006, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs.model.dbo
* @since CakePHP v 1.1.4.2974
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Include DBO.
*/
uses('model'.DS.'datasources'.DS.'dbo_source');
/**
* Short description for class.
*
* Long description for class
*
* @package cake
* @subpackage cake.cake.libs.model.dbo
*/
class DboMysqli extends DboSource {
/**
* Enter description here...
*
* @var unknown_type
*/
var $description = "Mysqli DBO Driver";
/**
* Enter description here...
*
* @var unknown_type
*/
var $startQuote = "`";
/**
* Enter description here...
*
* @var unknown_type
*/
var $endQuote = "`";
/**
* Base configuration settings for Mysqli driver
*
* @var array
*/
var $_baseConfig = array('persistent' => true,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'cake',
'port' => '3306',
'connect' => 'mysqli_pconnect');
/**
* Mysqli column definition
*
* @var array
*/
var $columns = array('primary_key' => array('name' => 'int(11) DEFAULT NULL auto_increment'),
'string' => array('name' => 'varchar', 'limit' => '255'),
'text' => array('name' => 'text'),
'integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'),
'float' => array('name' => 'float', 'formatter' => 'floatval'),
'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
'timestamp' => array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
'time' => array('name' => 'time', 'format' => 'H:i:s', 'formatter' => 'date'),
'date' => array('name' => 'date', 'format' => 'Y-m-d', 'formatter' => 'date'),
'binary' => array('name' => 'blob'),
'boolean' => array('name' => 'tinyint', 'limit' => '1'));
/**
* Connects to the database using options in the given configuration array.
*
* @return boolean True if the database could be connected, else false
*/
function connect() {
$config = $this->config;
$connect = $config['connect'];
$this->connected = false;
if (!$config['persistent']) {
$this->connection = mysqli_connect($config['host'], $config['login'], $config['password'], true);
} else {
$this->connection = $connect($config['host'], $config['login'], $config['password']);
}
if (mysqli_select_db($this->connection, $config['database'])) {
$this->connected = true;
}
return $this->connected;
}
/**
* Disconnects from database.
*
* @return boolean True if the database could be disconnected, else false
*/
function disconnect() {
$this->connected = !@mysqli_close($this->connection);
return !$this->connected;
}
/**
* Executes given SQL statement.
*
* @param string $sql SQL statement
* @return resource Result resource identifier
* @access protected
*/
function _execute($sql) {
return mysqli_query($this->connection, $sql);
}
/**
* Returns a row from given resultset as an array .
*
* @param bool $assoc Associative array only, or both?
* @return array The fetched row as an array
*/
function fetchRow($assoc = false) {
if(is_resource($this->_result)) {
$this->resultSet($this->_result);
$resultRow = $this->fetchResult();
return $resultRow;
} else {
return null;
}
}
/**
* Returns an array of sources (tables) in the database.
*
* @return array Array of tablenames in the database
*/
function listSources() {
$cache = parent::listSources();
if ($cache != null) {
return $cache;
}
$result = $this->_execute('SHOW TABLES FROM ' . $this->config['database'] . ';');
if (!$result) {
return array();
} else {
$tables = array();
while ($line = mysqli_fetch_array($result)) {
$tables[] = $line[0];
}
parent::listSources($tables);
return $tables;
}
}
/**
* Returns an array of the fields in given table name.
*
* @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type
*/
function describe(&$model) {
$cache = parent::describe($model);
if ($cache != null) {
return $cache;
}
$fields = false;
$cols = $this->_execute('DESCRIBE ' . $this->fullTableName($model));
foreach ($cols as $column) {
$colKey = array_keys($column);
if (isset($column[$colKey[0]]) && !isset($column[0])) {
$column[0] = $column[$colKey[0]];
}
if (isset($column[0])) {
$fields[] = array('name' => $column[0]['Field'], 'type' => $this->column($column[0]['Type']), 'null' => $column[0]['Null']);
}
}
$this->__cacheDescription($model->tablePrefix.$model->table, $fields);
return $fields;
}
/**
* Returns a quoted name of $data for use in an SQL statement.
*
* @param string $data Name (table.field) to be prepared for use in an SQL statement
* @return string Quoted for MySQL
*/
function name($data) {
if ($data == '*') {
return '*';
}
$pos = strpos($data, '`');
if ($pos === false) {
$data = '`'. str_replace('.', '`.`', $data) .'`';
}
return $data;
}
/**
* Returns a quoted and escaped string of $data for use in an SQL statement.
*
* @param string $data String to be prepared for use in an SQL statement
* @param string $column The column into which this data will be inserted
* @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided
* @return string Quoted and escaped data
*/
function value($data, $column = null, $safe = false) {
$parent = parent::value($data, $column, $safe);
if ($parent != null) {
return $parent;
}
if ($data === null) {
return 'NULL';
}
if($data == '') {
return "''";
}
switch ($column) {
case 'boolean':
$data = $this->boolean((bool)$data);
break;
default:
if (ini_get('magic_quotes_gpc') == 1) {
$data = stripslashes($data);
}
$data = mysqli_real_escape_string($this->connection, $data);
break;
}
return "'" . $data . "'";
}
/**
* Begin a transaction
*
* @param unknown_type $model
* @return boolean True on success, false on fail
* (i.e. if the database/model does not support transactions).
*/
function begin(&$model) {
if (parent::begin($model)) {
if ($this->execute('START TRANSACTION')) {
$this->__transactionStarted = true;
return true;
}
}
return false;
}
/**
* Commit a transaction
*
* @param unknown_type $model
* @return boolean True on success, false on fail
* (i.e. if the database/model does not support transactions,
* or a transaction has not started).
*/
function commit(&$model) {
if (parent::commit($model)) {
$this->__transactionStarted;
return $this->execute('COMMIT');
}
return false;
}
/**
* Rollback a transaction
*
* @param unknown_type $model
* @return boolean True on success, false on fail
* (i.e. if the database/model does not support transactions,
* or a transaction has not started).
*/
function rollback(&$model) {
if (parent::rollback($model)) {
return $this->execute('ROLLBACK');
}
return false;
}
/**
* Returns a formatted error message from previous database operation.
*
* @return string Error message with error number
*/
function lastError() {
if (mysqli_errno($this->connection)) {
return mysqli_errno($this->connection).': '.mysqli_error($this->connection);
}
return null;
}
/**
* Returns number of affected rows in previous database operation. If no previous operation exists,
* this returns false.
*
* @return int Number of affected rows
*/
function lastAffected() {
if ($this->_result) {
return mysqli_affected_rows($this->connection);
}
return null;
}
/**
* Returns number of rows in previous resultset. If no previous resultset exists,
* this returns false.
*
* @return int Number of rows in resultset
*/
function lastNumRows() {
if ($this->_result and is_resource($this->_result)) {
return @mysqli_num_rows($this->_result);
}
return null;
}
/**
* Returns the ID generated from the previous INSERT operation.
*
* @param unknown_type $source
* @return in
*/
function lastInsertId($source = null) {
$id = mysqli_insert_id($this->connection);
if ($id) {
return $id;
}
$data = $this->fetchAll('SELECT LAST_INSERT_ID() as id From '.$source);
if ($data && isset($data[0]['id'])) {
return $data[0]['id'];
}
}
/**
* Converts database-layer column types to basic types
*
* @param string $real Real database-layer column type (i.e. "varchar(255)")
* @return string Abstract column type (i.e. "string")
*/
function column($real) {
if (is_array($real)) {
$col = $real['name'];
if (isset($real['limit']))
{
$col .= '('.$real['limit'].')';
}
return $col;
}
$col = r(')', '', $real);
$limit = null;
@list($col, $limit) = explode('(', $col);
if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
return $col;
}
if ($col == 'tinyint' && $limit == '1') {
return 'boolean';
}
if (strpos($col, 'int') !== false) {
return 'integer';
}
if (strpos($col, 'char') !== false || $col == 'tinytext') {
return 'string';
}
if (strpos($col, 'text') !== false) {
return 'text';
}
if (strpos($col, 'blob') !== false) {
return 'binary';
}
if (in_array($col, array('float', 'double', 'decimal'))) {
return 'float';
}
if (strpos($col, 'enum') !== false) {
return "enum($limit)";
}
return 'text';
}
/**
* Enter description here...
*
* @param unknown_type $results
*/
function resultSet(&$results) {
$this->results =& $results;
$this->map = array();
$num_fields = mysqli_num_fields($results);
$index = 0;
$j = 0;
while ($j < $num_fields) {
$column = mysqli_fetch_field($results,$j);
if (!empty($column->table)) {
$this->map[$index++] = array($column->table, $column->name);
} else {
$this->map[$index++] = array(0, $column->name);
}
$j++;
}
}
/**
* Fetches the next row from the current result set
*
* @return unknown
*/
function fetchResult() {
if ($row = mysqli_fetch_row($this->results)) {
$resultRow = array();
$i = 0;
foreach ($row as $index => $field) {
list($table, $column) = $this->map[$index];
$resultRow[$table][$column] = $row[$index];
$i++;
}
return $resultRow;
} else {
return false;
}
}
/**
* Enter description here...
*
* @param unknown_type $schema
* @return unknown
*/
function buildSchemaQuery($schema) {
$search = array('{AUTOINCREMENT}', '{PRIMARY}', '{UNSIGNED}', '{FULLTEXT}',
'{FULLTEXT_MYSQL}', '{BOOLEAN}', '{UTF_8}');
$replace = array('int(11) not null auto_increment', 'primary key', 'unsigned',
'FULLTEXT', 'FULLTEXT', 'enum (\'true\', \'false\') NOT NULL default \'true\'',
'/*!40100 CHARACTER SET utf8 COLLATE utf8_unicode_ci */');
$query = trim(r($search, $replace, $schema));
return $query;
}
}
?>

View file

@ -72,7 +72,9 @@ class DboOdbc extends DboSource{
var $_baseConfig = array('persistent' => true,
'login' => 'root',
'password' => '',
'database' => 'cake');
'database' => 'cake',
'connect' => 'odbc_pconnect'
);
/**
* Enter description here...
@ -100,11 +102,11 @@ class DboOdbc extends DboSource{
* @return boolean True if the database could be connected, else false
*/
function connect() {
$config =$this->config;
$connect =$config['connect'];
$config = $this->config;
$connect = $config['connect'];
$this->connected =false;
$this->connection=$connect($config['database'], $config['login'], $config['password']);
$this->connected = false;
$this->connection = $connect($config['database'], $config['login'], $config['password']);
if ($this->connection) {
$this->connected = true;
@ -142,34 +144,45 @@ class DboOdbc extends DboSource{
function fetchRow($assoc = false) {
if (is_resource($this->_result)) {
$this->resultSet($this->_result);
$resultRow=$this->fetchResult();
$resultRow = $this->fetchResult();
return $resultRow;
} else {
return null;
}
}
/**
* Returns an array of sources (tables) in the database.
*
* @return array Array of tablenames in the database
*/
function listSources() {
$result=odbc_tables($this->connection);
if (!$result) {
return array();
} else {
$tables=array();
while($line = odbc_fetch_array($result)) {
$tables[] = strtolower($line['TABLE_NAME']);
$cache = parent::listSources();
if ($cache != null) {
return $cache;
}
/*$result = odbc_tables($this->connection);
if (function_exists('odbc_fetch_row')) {
echo 'GOOD';
} else {
echo 'BAD';
}*/
$result = odbc_tables($this->connection);
$tables = array();
while (odbc_fetch_row($result)) {
array_push($tables, odbc_result($result, "TABLE_NAME"));
}
foreach( $tables as $t ) {
echo "$t\n";
}
parent::listSources($tables);
return $tables;
}
}
/**
* Returns an array of the fields in given table name.
*

View file

@ -359,7 +359,6 @@ class Model extends Object{
$return = $db->query($method, $params, $this);
return true;
}
/**
* Bind model associations on the fly.
*
@ -386,7 +385,6 @@ class Model extends Object{
}
return true;
}
/**
* Turn off associations on the fly.
*
@ -404,7 +402,6 @@ class Model extends Object{
}
return true;
}
/**
* Private helper method to create a set of associations.
*
@ -418,14 +415,14 @@ class Model extends Object{
if (!is_array($this->{$type})) {
$this->{$type} = explode(',', $this->{$type});
foreach($this->{$type}as $i => $className) {
foreach($this->{$type} as $i => $className) {
$className = trim($className);
unset ($this->{$type}[$i]);
$this->{$type}[$className] = array();
}
}
foreach($this->{$type}as $assoc => $value) {
foreach($this->{$type} as $assoc => $value) {
if (is_numeric($assoc)) {
unset ($this->{$type}[$assoc]);
$assoc = $value;
@ -458,16 +455,15 @@ class Model extends Object{
$colKey = Inflector::underscore($className);
if (ClassRegistry::isKeySet($colKey)) {
$this->{$className} = ClassRegistry::getObject($colKey);
$this->{$className} =& ClassRegistry::getObject($colKey);
} else {
$this->{$className} = new $className();
$this->{$className} =& new $className();
}
$this->alias[$assoc] = $this->{$className}->table;
$this->tableToModel[$this->{$className}->table] = $className;
$this->modelToTable[$className] = $this->{$className}->table;
}
/**
* Build array-based association from string.
*
@ -524,7 +520,6 @@ class Model extends Object{
}
}
}
/**
* Sets a custom table for your controller class. Used by your controller to select a database table.
*
@ -558,7 +553,6 @@ class Model extends Object{
$this->loadInfo();
}
}
/**
* This function does two things: 1) it scans the array $one for the primary key,
* and if that's found, it sets the current id to the value of $one[id].
@ -602,7 +596,6 @@ class Model extends Object{
}
return $data;
}
/**
* Returns an array of table metadata (column names and types) from the database.
*
@ -616,7 +609,6 @@ class Model extends Object{
}
return $this->_tableInfo;
}
/**
* Returns an associative array of field names and column types.
*
@ -633,7 +625,6 @@ class Model extends Object{
}
return $cols;
}
/**
* Returns the column type of a column in the model
*
@ -653,7 +644,6 @@ class Model extends Object{
}
return null;
}
/**
* Returns true if this Model has given field in its database table.
*
@ -670,7 +660,6 @@ class Model extends Object{
}
return null;
}
/**
* Initializes the model for writing a new record.
*
@ -682,7 +671,6 @@ class Model extends Object{
$this->data = array();
return true;
}
/**
* Deprecated
*
@ -690,7 +678,6 @@ class Model extends Object{
function setId($id) {
$this->id = $id;
}
/**
* Deprecated. Use query() instead.
*
@ -698,7 +685,6 @@ class Model extends Object{
function findBySql($sql) {
return $this->query($sql);
}
/**
* Returns a list of fields from the database
*
@ -727,7 +713,6 @@ class Model extends Object{
return false;
}
}
/**
* Returns contents of a field in a query matching given conditions.
*
@ -762,7 +747,6 @@ class Model extends Object{
return false;
}
}
/**
* Saves a single field to the database.
*
@ -774,7 +758,6 @@ class Model extends Object{
function saveField($name, $value, $validate = false) {
return $this->save(array($this->name => array($name => $value)), $validate);
}
/**
* Saves model data to the database.
* By default, validation occurs before save.
@ -842,14 +825,12 @@ class Model extends Object{
$values[] = date('Y-m-d H:i:s');
}
if ($this->hasField('modified')
&& !in_array('modified', $fields) && ($whitelist && in_array('modified', $fieldList) || !$whitelist)) {
if ($this->hasField('modified') && !in_array('modified', $fields) && ($whitelist && in_array('modified', $fieldList) || !$whitelist)) {
$fields[] = 'modified';
$values[] = date('Y-m-d H:i:s');
}
if ($this->hasField('updated')
&& !in_array('updated', $fields) && ($whitelist && in_array('updated', $fieldList) || !$whitelist)) {
if ($this->hasField('updated') && !in_array('updated', $fields) && ($whitelist && in_array('updated', $fieldList) || !$whitelist)) {
$fields[] = 'updated';
$values[] = date('Y-m-d H:i:s');
}
@ -900,7 +881,6 @@ class Model extends Object{
return false;
}
}
/**
* Saves model hasAndBelongsToMany data to the database.
*
@ -943,18 +923,18 @@ class Model extends Object{
for($count = 0; $count < $total; $count++) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$db->execute("DELETE FROM {$joinTable[$count]} WHERE {$mainKey[$count]} = '{$id}'");
$table = $db->name($db->fullTableName($joinTable[$count]));
$db->execute("DELETE FROM {$table} WHERE {$mainKey[$count]} = '{$id}'");
if (!empty($newValue[$count])) {
$secondCount = count($newValue[$count]);
for($x = 0; $x < $secondCount; $x++) {
$db->execute("INSERT INTO {$joinTable[$count]} ({$fields[$count]}) VALUES {$newValue[$count][$x]}");
$db->execute("INSERT INTO {$table} ({$fields[$count]}) VALUES {$newValue[$count][$x]}");
}
}
}
}
/**
* Synonym for del().
*
@ -962,10 +942,9 @@ class Model extends Object{
* @see function del
* @return boolean True on success
*/
function remove($id = null) {
return $this->del($id);
function remove($id = null, $cascade = true) {
return $this->del($id, $cascade);
}
/**
* Removes record for given id. If no id is given, the current id is used. Returns true on success.
*
@ -995,7 +974,6 @@ class Model extends Object{
return false;
}
/**
* Alias for del()
*
@ -1005,7 +983,6 @@ class Model extends Object{
function delete($id = null, $cascade = true) {
return $this->del($id, $cascade);
}
/**
* Cascades model deletes to hasMany relationships.
*
@ -1027,7 +1004,6 @@ class Model extends Object{
}
}
}
/**
* Cascades model deletes to hasOne relationships.
*
@ -1049,7 +1025,6 @@ class Model extends Object{
}
}
}
/**
* Cascades model deletes to HABTM join keys.
*
@ -1059,13 +1034,10 @@ class Model extends Object{
*/
function _deleteMulti($id) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
foreach($this->hasAndBelongsToMany as $assoc => $data) {
$db->execute("DELETE FROM " . $db->name($data['joinTable']) . " WHERE "
. $db->name($data['foreignKey']) . " = '{$id}'");
$db->execute("DELETE FROM " . $db->name($db->fullTableName($data['joinTable'])) . " WHERE " . $db->name($data['foreignKey']) . " = '{$id}'");
}
}
/**
* Returns true if a record with set id exists.
*
@ -1080,12 +1052,10 @@ class Model extends Object{
}
$db =& ConnectionManager::getDataSource($this->useDbConfig);
return $db->hasAny($this, $db->conditions(array($this->primaryKey => $id)));
return $db->hasAny($this, array($this->primaryKey => $id));
}
return false;
}
/**
* Returns true if a record that meets given conditions exists
*
@ -1095,7 +1065,6 @@ class Model extends Object{
function hasAny($conditions = null) {
return ($this->findCount($conditions) != false);
}
/**
* Return a single row as a resultset array.
* By using the $recursive parameter, the call can access further "levels of association" than
@ -1116,7 +1085,6 @@ class Model extends Object{
return $data[0];
}
/**
* Returns a resultset array with specified fields from database matching given conditions.
* By using the $recursive parameter, the call can access further "levels of association" than
@ -1131,20 +1099,15 @@ class Model extends Object{
* @return array Array of records
*/
function findAll($conditions = null, $fields = null, $order = null, $limit = null, $page = 1, $recursive = null) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$this->id = $this->getID();
$offset = 0;
$offset = null;
if ($page > 1) {
if ($page > 1 && $limit != null) {
$offset = ($page - 1) * $limit;
}
$limit_str = '';
if ($limit) {
$limit_str = $db->limit($limit, $offset);
}
if ($order == null) {
$order = array();
} else {
@ -1154,8 +1117,10 @@ class Model extends Object{
$queryData = array('conditions' => $conditions,
'fields' => $fields,
'joins' => array(),
'limit' => $limit_str,
'order' => $order);
'limit' => $limit,
'offset' => $offset,
'order' => $order
);
if (!$this->beforeFind($queryData)) {
return null;
@ -1169,7 +1134,6 @@ class Model extends Object{
return $return;
}
/**
* Method is called only when bindTo<ModelName>() is used.
* This resets the association arrays for the model back
@ -1188,7 +1152,6 @@ class Model extends Object{
unset ($this->__backAssociation);
return true;
}
/**
* Runs a direct query against the bound DataSource, and returns the result.
*
@ -1213,7 +1176,6 @@ class Model extends Object{
return $data;
}
/**
* Returns number of rows matching given SQL condition.
*
@ -1231,7 +1193,6 @@ class Model extends Object{
return false;
}
/**
* Special findAll variation for tables joined to themselves.
* The table needs the fields id and parent_id to work.
@ -1245,7 +1206,6 @@ class Model extends Object{
function findAllThreaded($conditions = null, $fields = null, $sort = null) {
return $this->__doThread(Model::findAll($conditions, $fields, $sort), null);
}
/**
* Private, recursive helper method for findAllThreaded.
*
@ -1260,8 +1220,7 @@ class Model extends Object{
$sizeOf = sizeof($data);
for($ii = 0; $ii < $sizeOf; $ii++) {
if (($data[$ii][$this->name]['parent_id'] == $root)
|| (($root === null) && ($data[$ii][$this->name]['parent_id'] == '0'))) {
if (($data[$ii][$this->name]['parent_id'] == $root) || (($root === null) && ($data[$ii][$this->name]['parent_id'] == '0'))) {
$tmp = $data[$ii];
if (isset($data[$ii][$this->name][$this->primaryKey])) {
@ -1276,7 +1235,6 @@ class Model extends Object{
return $out;
}
/**
* Returns an array with keys "prev" and "next" that holds the id's of neighbouring data,
* which is useful when creating paged lists.
@ -1306,7 +1264,6 @@ class Model extends Object{
return array('prev' => $prev, 'next' => $next);
}
/**
* Returns a resultset for given SQL statement. Generic SQL queries should be made with this method.
*
@ -1318,22 +1275,16 @@ class Model extends Object{
$db =& ConnectionManager::getDataSource($this->useDbConfig);
return call_user_func_array(array(&$db, 'query'), $params);
}
/**
* Returns true if all fields pass validation, otherwise false.
*
* @param array $data POST data
* @return boolean True if there are no errors
*/
function validates($data = null) {
if ($data == null) {
$data = $this->data;
}
function validates($data = array()) {
$errors = $this->invalidFields($data);
return count($errors) == 0;
}
/**
* Returns an array of invalid fields.
*
@ -1341,6 +1292,10 @@ class Model extends Object{
* @return array Array of invalid fields
*/
function invalidFields($data = array()) {
if (empty($data)) {
$data = $this->data;
}
if (!$this->beforeValidate()) {
return false;
}
@ -1349,10 +1304,9 @@ class Model extends Object{
return true;
}
if (!empty($data)){
if (!empty($data)) {
$data = $data;
}
elseif (isset($this->data)){
} elseif (isset($this->data)) {
$data = $this->data;
}
@ -1367,7 +1321,6 @@ class Model extends Object{
}
return $this->validationErrors;
}
/**
* Sets a field as invalid
*
@ -1378,10 +1331,8 @@ class Model extends Object{
if (!is_array($this->validationErrors)) {
$this->validationErrors = array();
}
$this->validationErrors[$field] = 1;
}
/**
* Returns true if given field name is a foreign key in this Model.
*
@ -1396,10 +1347,8 @@ class Model extends Object{
$foreignKeys[] = $data['foreignKey'];
}
}
return (bool)(in_array($field, $foreignKeys));
}
/**
* Gets the display field for this model
*
@ -1408,7 +1357,6 @@ class Model extends Object{
function getDisplayField() {
return $this->displayField;
}
/**
* Returns a resultset array with specified fields from database matching given conditions.
* Method can be used to generate option lists for SELECT elements.
@ -1423,10 +1371,10 @@ class Model extends Object{
function generateList($conditions = null, $order = null, $limit = null, $keyPath = null, $valuePath = null) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
if ($keyPath == null && $valuePath == null) {
if ($keyPath == null && $valuePath == null && $this->hasField($this->displayField)) {
$fields = array($this->primaryKey, $this->displayField);
} else {
$fields = '*';
$fields = null;
}
$result = $this->findAll($conditions, $fields, $order, $limit, 1, 0);
@ -1447,7 +1395,6 @@ class Model extends Object{
return $return;
}
}
/**
* Escapes the field name and prepends the model name. Escaping will be done according to the current database driver's rules.
*
@ -1458,7 +1405,6 @@ class Model extends Object{
$db =& ConnectionManager::getDataSource($this->useDbConfig);
return $db->name($this->name) . '.' . $db->name($field);
}
/**
* Returns the current record's ID
*
@ -1484,7 +1430,6 @@ class Model extends Object{
return false;
}
/**
* Returns the ID of the last record this Model inserted
*
@ -1493,7 +1438,6 @@ class Model extends Object{
function getLastInsertID() {
return $this->getInsertID();
}
/**
* Returns the ID of the last record this Model inserted
*
@ -1502,7 +1446,6 @@ class Model extends Object{
function getInsertID() {
return $this->__insertID;
}
/**
* Returns the number of rows returned from the last query
*
@ -1513,7 +1456,6 @@ class Model extends Object{
$db =& ConnectionManager::getDataSource($this->useDbConfig);
return $db->lastNumRows();
}
/**
* Returns the number of rows affected by the last query
*
@ -1524,7 +1466,6 @@ class Model extends Object{
$db =& ConnectionManager::getDataSource($this->useDbConfig);
return $db->lastAffected();
}
/**
* Sets the DataSource to which this model is bound
*
@ -1546,7 +1487,6 @@ class Model extends Object{
return $this->cakeError('missingConnection', array(array('className' => $this->name)));
}
}
/**
* Before find callback
*
@ -1556,7 +1496,6 @@ class Model extends Object{
function beforeFind(&$queryData) {
return true;
}
/**
* After find callback. Can be used to modify any results returned by find and findAll.
*
@ -1566,7 +1505,6 @@ class Model extends Object{
function afterFind($results) {
return $results;
}
/**
* Before save callback
*
@ -1575,7 +1513,6 @@ class Model extends Object{
function beforeSave() {
return true;
}
/**
* After save callback
*
@ -1584,7 +1521,6 @@ class Model extends Object{
function afterSave() {
return true;
}
/**
* Before delete callback
*
@ -1593,7 +1529,6 @@ class Model extends Object{
function beforeDelete() {
return true;
}
/**
* After delete callback
*
@ -1602,7 +1537,6 @@ class Model extends Object{
function afterDelete() {
return true;
}
/**
* Before validate callback
*
@ -1611,7 +1545,6 @@ class Model extends Object{
function beforeValidate() {
return true;
}
/**
* Private method. Clears cache for this model
*
@ -1640,7 +1573,6 @@ class Model extends Object{
//Will use for query cache deleting
}
}
/**
* Called when serializing a model
*

View file

@ -341,7 +341,6 @@ class Model extends Object{
}
}
}
/**
* Handles custom method calls, like findBy<field> for DB models,
* and custom RPC calls for remote data sources
@ -355,7 +354,6 @@ class Model extends Object{
$db =& ConnectionManager::getDataSource($this->useDbConfig);
return $db->query($method, $params, $this);
}
/**
* Bind model associations on the fly.
*
@ -382,7 +380,6 @@ class Model extends Object{
}
return true;
}
/**
* Turn off associations on the fly.
*
@ -400,7 +397,6 @@ class Model extends Object{
}
return true;
}
/**
* Private helper method to create a set of associations.
*
@ -414,14 +410,14 @@ class Model extends Object{
if (!is_array($this->{$type})) {
$this->{$type} = explode(',', $this->{$type});
foreach($this->{$type}as $i => $className) {
foreach($this->{$type} as $i => $className) {
$className = trim($className);
unset ($this->{$type}[$i]);
$this->{$type}[$className] = array();
}
}
foreach($this->{$type}as $assoc => $value) {
foreach($this->{$type} as $assoc => $value) {
if (is_numeric($assoc)) {
unset ($this->{$type}[$assoc]);
$assoc = $value;
@ -442,7 +438,6 @@ class Model extends Object{
$this->__generateAssociation($type);
}
}
/**
* Private helper method to create associated models of given class.
* @param string $assoc
@ -463,7 +458,6 @@ class Model extends Object{
$this->tableToModel[$this->{$className}->table] = $className;
$this->modelToTable[$className] = $this->{$className}->table;
}
/**
* Build array-based association from string.
*
@ -520,7 +514,6 @@ class Model extends Object{
}
}
}
/**
* Sets a custom table for your controller class. Used by your controller to select a database table.
*
@ -554,7 +547,6 @@ class Model extends Object{
$this->loadInfo();
}
}
/**
* This function does two things: 1) it scans the array $one for the primary key,
* and if that's found, it sets the current id to the value of $one[id].
@ -598,7 +590,6 @@ class Model extends Object{
}
return $data;
}
/**
* Returns an array of table metadata (column names and types) from the database.
*
@ -612,7 +603,6 @@ class Model extends Object{
}
return $this->_tableInfo;
}
/**
* Returns an associative array of field names and column types.
*
@ -629,7 +619,6 @@ class Model extends Object{
}
return $cols;
}
/**
* Returns the column type of a column in the model
*
@ -649,7 +638,6 @@ class Model extends Object{
}
return null;
}
/**
* Returns true if this Model has given field in its database table.
*
@ -666,7 +654,6 @@ class Model extends Object{
}
return null;
}
/**
* Initializes the model for writing a new record.
*
@ -678,7 +665,6 @@ class Model extends Object{
$this->data = array();
return true;
}
/**
* Deprecated
*
@ -686,7 +672,6 @@ class Model extends Object{
function setId($id) {
$this->id = $id;
}
/**
* Deprecated. Use query() instead.
*
@ -694,7 +679,6 @@ class Model extends Object{
function findBySql($sql) {
return $this->query($sql);
}
/**
* Returns a list of fields from the database
*
@ -838,14 +822,12 @@ class Model extends Object{
$values[] = date('Y-m-d H:i:s');
}
if ($this->hasField('modified')
&& !in_array('modified', $fields) && ($whitelist && in_array('modified', $fieldList) || !$whitelist)) {
if ($this->hasField('modified') && !in_array('modified', $fields) && ($whitelist && in_array('modified', $fieldList) || !$whitelist)) {
$fields[] = 'modified';
$values[] = date('Y-m-d H:i:s');
}
if ($this->hasField('updated')
&& !in_array('updated', $fields) && ($whitelist && in_array('updated', $fieldList) || !$whitelist)) {
if ($this->hasField('updated') && !in_array('updated', $fields) && ($whitelist && in_array('updated', $fieldList) || !$whitelist)) {
$fields[] = 'updated';
$values[] = date('Y-m-d H:i:s');
}
@ -896,7 +878,6 @@ class Model extends Object{
return false;
}
}
/**
* Saves model hasAndBelongsToMany data to the database.
*
@ -939,18 +920,18 @@ class Model extends Object{
for($count = 0; $count < $total; $count++) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$db->execute("DELETE FROM {$joinTable[$count]} WHERE {$mainKey[$count]} = '{$id}'");
$table = $db->name($db->fullTableName($joinTable[$count]));
$db->execute("DELETE FROM {$table} WHERE {$mainKey[$count]} = '{$id}'");
if (!empty($newValue[$count])) {
$secondCount = count($newValue[$count]);
for($x = 0; $x < $secondCount; $x++) {
$db->execute("INSERT INTO {$joinTable[$count]} ({$fields[$count]}) VALUES {$newValue[$count][$x]}");
$db->execute("INSERT INTO {$table} ({$fields[$count]}) VALUES {$newValue[$count][$x]}");
}
}
}
}
/**
* Synonym for del().
*
@ -958,10 +939,9 @@ class Model extends Object{
* @see function del
* @return boolean True on success
*/
function remove($id = null) {
return $this->del($id);
function remove($id = null, $cascade = true) {
return $this->del($id, $cascade);
}
/**
* Removes record for given id. If no id is given, the current id is used. Returns true on success.
*
@ -991,7 +971,6 @@ class Model extends Object{
return false;
}
/**
* Alias for del()
*
@ -1001,7 +980,6 @@ class Model extends Object{
function delete($id = null, $cascade = true) {
return $this->del($id, $cascade);
}
/**
* Cascades model deletes to hasMany relationships.
*
@ -1023,7 +1001,6 @@ class Model extends Object{
}
}
}
/**
* Cascades model deletes to hasOne relationships.
*
@ -1045,7 +1022,6 @@ class Model extends Object{
}
}
}
/**
* Cascades model deletes to HABTM join keys.
*
@ -1055,13 +1031,10 @@ class Model extends Object{
*/
function _deleteMulti($id) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
foreach($this->hasAndBelongsToMany as $assoc => $data) {
$db->execute("DELETE FROM " . $db->name($data['joinTable']) . " WHERE "
. $db->name($data['foreignKey']) . " = '{$id}'");
$db->execute("DELETE FROM " . $db->name($db->fullTableName($data['joinTable'])) . " WHERE " . $db->name($data['foreignKey']) . " = '{$id}'");
}
}
/**
* Returns true if a record with set id exists.
*
@ -1076,12 +1049,10 @@ class Model extends Object{
}
$db =& ConnectionManager::getDataSource($this->useDbConfig);
return $db->hasAny($this, $db->conditions(array($this->primaryKey => $id)));
return $db->hasAny($this, array($this->primaryKey => $id));
}
return false;
}
/**
* Returns true if a record that meets given conditions exists
*
@ -1091,7 +1062,6 @@ class Model extends Object{
function hasAny($conditions = null) {
return ($this->findCount($conditions) != false);
}
/**
* Return a single row as a resultset array.
* By using the $recursive parameter, the call can access further "levels of association" than
@ -1112,7 +1082,6 @@ class Model extends Object{
return $data[0];
}
/**
* Returns a resultset array with specified fields from database matching given conditions.
* By using the $recursive parameter, the call can access further "levels of association" than
@ -1127,20 +1096,15 @@ class Model extends Object{
* @return array Array of records
*/
function findAll($conditions = null, $fields = null, $order = null, $limit = null, $page = 1, $recursive = null) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$this->id = $this->getID();
$offset = 0;
$offset = null;
if ($page > 1) {
if ($page > 1 && $limit != null) {
$offset = ($page - 1) * $limit;
}
$limit_str = '';
if ($limit) {
$limit_str = $db->limit($limit, $offset);
}
if ($order == null) {
$order = array();
} else {
@ -1150,8 +1114,10 @@ class Model extends Object{
$queryData = array('conditions' => $conditions,
'fields' => $fields,
'joins' => array(),
'limit' => $limit_str,
'order' => $order);
'limit' => $limit,
'offset' => $offset,
'order' => $order
);
if (!$this->beforeFind($queryData)) {
return null;
@ -1165,7 +1131,6 @@ class Model extends Object{
return $return;
}
/**
* Method is called only when bindTo<ModelName>() is used.
* This resets the association arrays for the model back
@ -1184,7 +1149,6 @@ class Model extends Object{
unset ($this->__backAssociation);
return true;
}
/**
* Runs a direct query against the bound DataSource, and returns the result.
*
@ -1209,7 +1173,6 @@ class Model extends Object{
return $data;
}
/**
* Returns number of rows matching given SQL condition.
*
@ -1227,7 +1190,6 @@ class Model extends Object{
return false;
}
/**
* Special findAll variation for tables joined to themselves.
* The table needs the fields id and parent_id to work.
@ -1241,7 +1203,6 @@ class Model extends Object{
function findAllThreaded($conditions = null, $fields = null, $sort = null) {
return $this->__doThread(Model::findAll($conditions, $fields, $sort), null);
}
/**
* Private, recursive helper method for findAllThreaded.
*
@ -1256,8 +1217,7 @@ class Model extends Object{
$sizeOf = sizeof($data);
for($ii = 0; $ii < $sizeOf; $ii++) {
if (($data[$ii][$this->name]['parent_id'] == $root)
|| (($root === null) && ($data[$ii][$this->name]['parent_id'] == '0'))) {
if (($data[$ii][$this->name]['parent_id'] == $root) || (($root === null) && ($data[$ii][$this->name]['parent_id'] == '0'))) {
$tmp = $data[$ii];
if (isset($data[$ii][$this->name][$this->primaryKey])) {
@ -1272,7 +1232,6 @@ class Model extends Object{
return $out;
}
/**
* Returns an array with keys "prev" and "next" that holds the id's of neighbouring data,
* which is useful when creating paged lists.
@ -1302,7 +1261,6 @@ class Model extends Object{
return array('prev' => $prev, 'next' => $next);
}
/**
* Returns a resultset for given SQL statement. Generic SQL queries should be made with this method.
*
@ -1314,22 +1272,16 @@ class Model extends Object{
$db =& ConnectionManager::getDataSource($this->useDbConfig);
return call_user_func_array(array(&$db, 'query'), $params);
}
/**
* Returns true if all fields pass validation, otherwise false.
*
* @param array $data POST data
* @return boolean True if there are no errors
*/
function validates($data = null) {
if ($data == null) {
$data = $this->data;
}
function validates($data = array()) {
$errors = $this->invalidFields($data);
return count($errors) == 0;
}
/**
* Returns an array of invalid fields.
*
@ -1337,6 +1289,10 @@ class Model extends Object{
* @return array Array of invalid fields
*/
function invalidFields($data = array()) {
if (empty($data)) {
$data = $this->data;
}
if (!$this->beforeValidate()) {
return false;
}
@ -1345,10 +1301,9 @@ class Model extends Object{
return true;
}
if (!empty($data)){
if (!empty($data)) {
$data = $data;
}
elseif (isset($this->data)){
} elseif (isset($this->data)) {
$data = $this->data;
}
@ -1363,7 +1318,6 @@ class Model extends Object{
}
return $this->validationErrors;
}
/**
* Sets a field as invalid
*
@ -1374,10 +1328,8 @@ class Model extends Object{
if (!is_array($this->validationErrors)) {
$this->validationErrors = array();
}
$this->validationErrors[$field] = 1;
}
/**
* Returns true if given field name is a foreign key in this Model.
*
@ -1392,10 +1344,8 @@ class Model extends Object{
$foreignKeys[] = $data['foreignKey'];
}
}
return (bool)(in_array($field, $foreignKeys));
}
/**
* Gets the display field for this model
*
@ -1404,7 +1354,6 @@ class Model extends Object{
function getDisplayField() {
return $this->displayField;
}
/**
* Returns a resultset array with specified fields from database matching given conditions.
* Method can be used to generate option lists for SELECT elements.
@ -1419,10 +1368,10 @@ class Model extends Object{
function generateList($conditions = null, $order = null, $limit = null, $keyPath = null, $valuePath = null) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
if ($keyPath == null && $valuePath == null) {
if ($keyPath == null && $valuePath == null && $this->hasField($this->displayField)) {
$fields = array($this->primaryKey, $this->displayField);
} else {
$fields = '*';
$fields = null;
}
$result = $this->findAll($conditions, $fields, $order, $limit, 1, 0);
@ -1443,7 +1392,6 @@ class Model extends Object{
return $return;
}
}
/**
* Escapes the field name and prepends the model name. Escaping will be done according to the current database driver's rules.
*
@ -1454,7 +1402,6 @@ class Model extends Object{
$db =& ConnectionManager::getDataSource($this->useDbConfig);
return $db->name($this->name) . '.' . $db->name($field);
}
/**
* Returns the current record's ID
*
@ -1480,7 +1427,6 @@ class Model extends Object{
return false;
}
/**
* Returns the ID of the last record this Model inserted
*
@ -1489,7 +1435,6 @@ class Model extends Object{
function getLastInsertID() {
return $this->getInsertID();
}
/**
* Returns the ID of the last record this Model inserted
*
@ -1498,7 +1443,6 @@ class Model extends Object{
function getInsertID() {
return $this->__insertID;
}
/**
* Returns the number of rows returned from the last query
*
@ -1509,7 +1453,6 @@ class Model extends Object{
$db =& ConnectionManager::getDataSource($this->useDbConfig);
return $db->lastNumRows();
}
/**
* Returns the number of rows affected by the last query
*
@ -1520,7 +1463,6 @@ class Model extends Object{
$db =& ConnectionManager::getDataSource($this->useDbConfig);
return $db->lastAffected();
}
/**
* Sets the DataSource to which this model is bound
*
@ -1542,7 +1484,6 @@ class Model extends Object{
return $this->cakeError('missingConnection', array(array('className' => $this->name)));
}
}
/**
* Before find callback
*
@ -1552,7 +1493,6 @@ class Model extends Object{
function beforeFind(&$queryData) {
return true;
}
/**
* After find callback. Can be used to modify any results returned by find and findAll.
*
@ -1562,7 +1502,6 @@ class Model extends Object{
function afterFind($results) {
return $results;
}
/**
* Before save callback
*
@ -1571,7 +1510,6 @@ class Model extends Object{
function beforeSave() {
return true;
}
/**
* After save callback
*
@ -1580,7 +1518,6 @@ class Model extends Object{
function afterSave() {
return true;
}
/**
* Before delete callback
*
@ -1589,7 +1526,6 @@ class Model extends Object{
function beforeDelete() {
return true;
}
/**
* After delete callback
*
@ -1598,7 +1534,6 @@ class Model extends Object{
function afterDelete() {
return true;
}
/**
* Before validate callback
*
@ -1607,7 +1542,6 @@ class Model extends Object{
function beforeValidate() {
return true;
}
/**
* Private method. Clears cache for this model
*
@ -1636,7 +1570,6 @@ class Model extends Object{
//Will use for query cache deleting
}
}
/**
* Called when serializing a model
*

View file

@ -84,12 +84,15 @@ class Object{
function requestAction($url, $extra = array()) {
if (!empty($url)) {
$dispatcher =& new Dispatcher();
if(isset($this->plugin)){
$extra['plugin'] = $this->plugin;
}
if (in_array('return', $extra)) {
$extra['return'] = 0;
$extra['bare'] = 1;
ob_start();
$out=$dispatcher->dispatch($url, $extra);
$out=ob_get_clean();
$out = $dispatcher->dispatch($url, $extra);
$out = ob_get_clean();
return $out;
} else {
$extra['return'] = 1;

View file

@ -426,8 +426,8 @@ class CakeSession extends Object{
$table = $db->fullTableName(CAKE_SESSION_TABLE);
$row = $db->query("SELECT " . $db->name($table.'.data') . " FROM " . $db->name($table) . " WHERE " . $db->name($table.'.id') . " = " . $db->value($key), false);
if ($row && $row[0][$table]['data']) {
return $row[0][$table]['data'];
if ($row && $row[0][CAKE_SESSION_TABLE]['data']) {
return $row[0][CAKE_SESSION_TABLE]['data'];
} else {
return false;
}
@ -527,7 +527,7 @@ class CakeSession extends Object{
$factor = 10;
break;
case 'medium':
$facto = 100;
$factor = 100;
break;
case 'low':
$factor = 300;
@ -538,17 +538,17 @@ class CakeSession extends Object{
}
$expires = time() + CAKE_SESSION_TIMEOUT * $factor;
$row = $db->query("SELECT COUNT(id) AS count FROM " . $db->name($table) . " WHERE "
. $db->name($table.'.id') . " = "
. $db->name('id') . " = "
. $db->value($key), false);
if ($row[0][0]['count'] > 0) {
$db->execute("UPDATE " . $db->name($table) . " SET " . $db->name('data') . " = "
. $db->value($value) . ", " . $db->name($table.'.expires') . " = "
. $db->value($expires) . " WHERE " . $db->name($table.'.id') . " = "
. $db->value($value) . ", " . $db->name('expires') . " = "
. $db->value($expires) . " WHERE " . $db->name('id') . " = "
. $db->value($key));
} else {
$db->execute("INSERT INTO " . $db->name($table) . " (" . $db->name('data') . ","
. $db->name($table.'.expires') . "," . $db->name($table.'.id')
. $db->name('expires') . "," . $db->name('id')
. ") VALUES (" . $db->value($value) . ", " . $db->value($expires) . ", "
. $db->value($key) . ")");
}

View file

@ -36,14 +36,7 @@
* @package cake
* @subpackage cake.cake.libs.view
*/
class Helper extends Object{
/*************************************************************************
* Public variables
*************************************************************************/
/**#@+
* @access public
*/
class Helper extends Object {
/**
* Holds tag templates.
@ -52,34 +45,21 @@ class Helper extends Object{
* @var array
*/
var $tags = array();
/**#@-*/
/*************************************************************************
* Public methods
*************************************************************************/
/**#@+
* @access public
*/
/**
* Parses tag templates into $this->tags.
*
* @return void
*/
function loadConfig() {
$config=fileExistsInPath(CAKE . 'config' . DS . 'tags.ini.php');
$cakeConfig=$this->readConfigFile($config);
$config = fileExistsInPath(CAKE . 'config' . DS . 'tags.ini.php');
$cakeConfig = $this->readConfigFile($config);
if (file_exists(APP . 'config' . DS . 'tags.ini.php')) {
$appConfig=$this->readConfigFile(APP . 'config' . DS . 'tags.ini.php');
$cakeConfig=array_merge($cakeConfig, $appConfig);
$appConfig = $this->readConfigFile(APP . 'config' . DS . 'tags.ini.php');
$cakeConfig = am($cakeConfig, $appConfig);
}
return $cakeConfig;
}
/**
* Decides whether to output or return a string.
*
@ -100,7 +80,6 @@ class Helper extends Object{
return $str;
}
}
/**
* Assigns values to tag templates.
*
@ -121,11 +100,11 @@ class Helper extends Object{
* @return array
*/
function readConfigFile($fileName) {
$fileLineArray=file($fileName);
$fileLineArray = file($fileName);
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) == ']') {
@ -133,17 +112,17 @@ class Helper extends Object{
// this could be used to add a key with the section block name
// but it adds another array level
} else {
$delimiter=strpos($dataLine, '=');
$delimiter = strpos($dataLine, '=');
if ($delimiter > 0) {
$key =strtolower(trim(substr($dataLine, 0, $delimiter)));
$value=trim(substr($dataLine, $delimiter + 1));
$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[$key]=stripcslashes($value);
$iniSetting[$key] = stripcslashes($value);
} else {
$iniSetting[strtolower(trim($dataLine))] = '';
}
@ -161,7 +140,6 @@ class Helper extends Object{
*/
function afterRender() {
}
/**#@-*/
}
?>

View file

@ -654,8 +654,8 @@ class AjaxHelper extends Helper {
case 'requestHeaders':
$keys = array();
foreach ($value as $key => $val) {
$keys[] = '"' . $key . '"';
$keys[] = '"' . $val . '"';
$keys[] = "'" . $key . "'";
$keys[] = "'" . $val . "'";
}
$js_options['requestHeaders'] = '[' . join(', ', $keys) . ']';
break;
@ -762,13 +762,18 @@ class AjaxHelper extends Helper {
function afterRender() {
if (env('HTTP_X_UPDATE') != null && count($this->__ajaxBuffer) > 0) {
$data = array();
$divs = explode(' ', env('HTTP_X_UPDATE'));
foreach ($this->__ajaxBuffer as $key => $val) {
if (in_array($key, $divs)) {
$data[] = $key . ':"' . rawurlencode($val) . '"';
}
}
$out = 'var __ajaxUpdater__ = {' . join(', ', $data) . '};' . "\n";
$out .= 'for (n in __ajaxUpdater__) { if (typeof __ajaxUpdater__[n] == "string" && $(n)) Element.update($(n), unescape(__ajaxUpdater__[n])); }';
@ob_end_clean();
e($this->Javascript->codeBlock($out));
exit();
}

View file

@ -1,6 +1,5 @@
<?php
/* SVN FILE: $Id$ */
/**
* Automatic generation of HTML FORMs from given data.
*
@ -27,27 +26,22 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Tag template for a div with a class attribute.
*/
define('TAG_DIV', '<div class="%s">%s</div>');
define('TAG_DIV', '<div class="%s">%s</div>');
/**
* Tag template for a paragraph with a class attribute.
*/
define('TAG_P_CLASS', '<p class="%s">%s</p>');
define('TAG_P_CLASS', '<p class="%s">%s</p>');
/**
* Tag template for a label with a for attribute.
*/
define('TAG_LABEL', '<label for="%s">%s</label>');
define('TAG_LABEL', '<label for="%s">%s</label>');
/**
* Tag template for a fieldset with a legend tag inside.
*/
define('TAG_FIELDSET', '<fieldset><legend>%s</legend>%s</label>');
define('TAG_FIELDSET', '<fieldset><legend>%s</legend>%s</label>');
/**
* Form helper library.
*
@ -65,7 +59,6 @@ class FormHelper extends Helper{
*/
function FormHelper() {
}
/**
* Returns a formatted error message for given FORM field, NULL if no errors.
*
@ -82,7 +75,6 @@ class FormHelper extends Helper{
return false;
}
}
/**
* Returns a formatted LABEL element for HTML FORMs.
*
@ -93,7 +85,6 @@ class FormHelper extends Helper{
function labelTag($tagName, $text) {
return sprintf(TAG_LABEL, strtolower(str_replace('/', '_', $tagName)), $text);
}
/**
* Returns a formatted DIV tag for HTML FORMs.
*
@ -104,7 +95,6 @@ class FormHelper extends Helper{
function divTag($class, $text) {
return sprintf(TAG_DIV, $class, $text);
}
/**
* Returns a formatted P tag with class for HTML FORMs.
*
@ -115,7 +105,6 @@ class FormHelper extends Helper{
function pTag($class, $text) {
return sprintf(TAG_P_CLASS, $class, $text);
}
/**
* Returns a formatted INPUT tag for HTML FORMs.
*
@ -127,32 +116,25 @@ class FormHelper extends Helper{
* @param array $htmlOptions HTML options array.
* @return string The formatted INPUT element, with a label and wrapped in a div.
*/
function generateInputDiv($tagName, $prompt, $required = false, $errorMsg = null, $size = 20,
$htmlOptions = null) {
function generateInputDiv($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions = null) {
$htmlOptions['id'] = strtolower(str_replace('/', '_', $tagName));
$htmlAttributes = $htmlOptions;
$htmlAttributes['size'] = $size;
$str = $this->Html->input($tagName, $htmlAttributes);
$strLabel = $this->labelTag($tagName, $prompt);
$divClass = "optional";
if ($required) {
$divClass = "required";
}
$strError = ""; // initialize the error to empty.
$strError = "";
if ($this->isFieldError($tagName)) {
// if it was an error that occured, then add the error message, and append " error" to the div tag.
$strError = $this->pTag('error', $errorMsg);
$divClass = sprintf("%s error", $divClass);
}
$divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
return $this->divTag($divClass, $divTagInside);
}
/**
* Returns a formatted CHECKBOX tag inside a DIV for HTML FORMs.
*
@ -163,32 +145,24 @@ class FormHelper extends Helper{
* @param array $htmlOptions HTML options array.
* @return string The formatted checkbox div
*/
function generateCheckboxDiv($tagName, $prompt, $required = false, $errorMsg = null, $htmlOptions = null)
{
$htmlOptions['class']="inputCheckbox";
$htmlOptions['id'] =strtolower(str_replace('/', '_', $tagName));
;
$str =$this->Html->checkbox($tagName, null, $htmlOptions);
$strLabel =$this->labelTag($tagName, $prompt);
$divClass ="optional";
if ($required)
$divClass="required";
$strError=""; // initialize the error to empty.
function generateCheckboxDiv($tagName, $prompt, $required = false, $errorMsg = null, $htmlOptions = null) {
$htmlOptions['class'] = "inputCheckbox";
$htmlOptions['id'] = strtolower(str_replace('/', '_', $tagName));
$str = $this->Html->checkbox($tagName, null, $htmlOptions);
$strLabel = $this->labelTag($tagName, $prompt);
$divClass = "optional";
if ($required) {
$divClass = "required";
}
$strError = "";
if ($this->isFieldError($tagName)) {
// if it was an error that occured, then add the error message, and append " error" to the div tag.
$strError=$this->pTag('error', $errorMsg);
$divClass=sprintf("%s error", $divClass);
$strError = $this->pTag('error', $errorMsg);
$divClass = sprintf("%s error", $divClass);
}
$divTagInside=sprintf("%s %s %s", $strError, $strLabel, $str);
$divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
return $this->divTag($divClass, $divTagInside);
}
/**
* Returns a formatted date option element for HTML FORMs.
*
@ -201,34 +175,24 @@ class FormHelper extends Helper{
* @param array $htmlOptions HTML options array
* @return string Date option wrapped in a div.
*/
function generateDate($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions =
null,
$selected = null) {
function generateDate($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions = null, $selected = null) {
$htmlOptions['id']=strtolower(str_replace('/', '_', $tagName));
;
$str =$this->Html->dateTimeOptionTag($tagName, 'MDY', 'NONE', $selected, $htmlOptions);
$strLabel =$this->labelTag($tagName, $prompt);
$divClass ="optional";
if ($required)
$divClass="required";
$strError=""; // initialize the error to empty.
$str = $this->Html->dateTimeOptionTag($tagName, 'MDY', 'NONE', $selected, $htmlOptions);
$strLabel = $this->labelTag($tagName, $prompt);
$divClass = "optional";
if ($required) {
$divClass = "required";
}
$strError = "";
if ($this->isFieldError($tagName)) {
// if it was an error that occured, then add the error message, and append " error" to the div tag.
$strError=$this->pTag('error', $errorMsg);
$divClass=sprintf("%s error", $divClass);
$strError = $this->pTag('error', $errorMsg);
$divClass = sprintf("%s error", $divClass);
}
$divTagInside=sprintf("%s %s %s", $strError, $strLabel, $str);
$requiredDiv =$this->divTag($divClass, $divTagInside);
$divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
$requiredDiv = $this->divTag($divClass, $divTagInside);
return $this->divTag("date", $requiredDiv);
}
/**
* Returns a formatted datetime option element for HTML FORMs.
*
@ -242,33 +206,24 @@ class FormHelper extends Helper{
* @param array $selected Selected index in the dateTimeOption tag.
* @return string The formatted datetime option element wrapped in a div.
*/
function generateDateTime($tagName, $prompt, $required = false, $errorMsg = null, $size = 20,
$htmlOptions = null, $selected = null) {
function generateDateTime($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions = null, $selected = null) {
$htmlOptions['id']=strtolower(str_replace('/', '_', $tagName));
;
$str =$this->Html->dateTimeOptionTag($tagName, 'MDY', '12', $selected, $htmlOptions);
$strLabel =$this->labelTag($tagName, $prompt);
$divClass ="optional";
if ($required)
$divClass="required";
$strError=""; // initialize the error to empty.
$str = $this->Html->dateTimeOptionTag($tagName, 'MDY', '12', $selected, $htmlOptions);
$strLabel = $this->labelTag($tagName, $prompt);
$divClass = "optional";
if ($required) {
$divClass = "required";
}
$strError = "";
if ($this->isFieldError($tagName)) {
// if it was an error that occured, then add the error message, and append " error" to the div tag.
$strError=$this->pTag('error', $errorMsg);
$divClass=sprintf("%s error", $divClass);
$strError = $this->pTag('error', $errorMsg);
$divClass = sprintf("%s error", $divClass);
}
$divTagInside=sprintf("%s %s %s", $strError, $strLabel, $str);
$requiredDiv =$this->divTag($divClass, $divTagInside);
$divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
$requiredDiv = $this->divTag($divClass, $divTagInside);
return $this->divTag("date", $requiredDiv);
}
/**
* Returns a formatted TEXTAREA inside a DIV for use with HTML forms.
*
@ -281,33 +236,27 @@ class FormHelper extends Helper{
* @param array $htmlOptions HTML options array.
* @return string The formatted TEXTAREA element, wrapped in a div.
*/
function generateAreaDiv($tagName, $prompt, $required = false, $errorMsg = null, $cols = 60, $rows = 10,
$htmlOptions = null) {
$htmlOptions['id'] =strtolower(str_replace('/', '_', $tagName));
$htmlAttributes =$htmlOptions;
$htmlAttributes['cols']=$cols;
$htmlAttributes['rows']=$rows;
$str =$this->Html->textarea($tagName, $htmlAttributes);
$strLabel =$this->labelTag($tagName, $prompt);
function generateAreaDiv($tagName, $prompt, $required = false, $errorMsg = null, $cols = 60, $rows = 10, $htmlOptions = null) {
$htmlOptions['id'] = strtolower(str_replace('/', '_', $tagName));
$htmlAttributes = $htmlOptions;
$htmlAttributes['cols'] = $cols;
$htmlAttributes['rows'] = $rows;
$str = $this->Html->textarea($tagName, $htmlAttributes);
$strLabel = $this->labelTag($tagName, $prompt);
$divClass = "optional";
$divClass ="optional";
if ($required)
if ($required) {
$divClass="required";
$strError=""; // initialize the error to empty.
}
$strError = "";
if ($this->isFieldError($tagName)) {
// if it was an error that occured, then add the error message, and append " error" to the div tag.
$strError=$this->pTag('error', $errorMsg);
$divClass=sprintf("%s error", $divClass);
$strError = $this->pTag('error', $errorMsg);
$divClass = sprintf("%s error", $divClass);
}
$divTagInside=sprintf("%s %s %s", $strError, $strLabel, $str);
$divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
return $this->divTag($divClass, $divTagInside);
}
/**
* Returns a formatted SELECT tag for HTML FORMs.
*
@ -321,31 +270,24 @@ class FormHelper extends Helper{
* @param string $errorMsg Text that will appear if an error has occurred
* @return string The formatted INPUT element, wrapped in a div
*/
function generateSelectDiv($tagName, $prompt, $options, $selected = null, $selectAttr = null,
$optionAttr = null, $required = false, $errorMsg = null) {
$selectAttr['id']=strtolower(str_replace('/', '_', $tagName));
$str =$this->Html->selectTag($tagName, $options, $selected, $selectAttr, $optionAttr);
$strLabel =$this->labelTag($tagName, $prompt);
$divClass ="optional";
function generateSelectDiv($tagName, $prompt, $options, $selected = null, $selectAttr = null, $optionAttr = null, $required = false, $errorMsg = null) {
$selectAttr['id'] = strtolower(str_replace('/', '_', $tagName));
$str = $this->Html->selectTag($tagName, $options, $selected, $selectAttr, $optionAttr);
$strLabel = $this->labelTag($tagName, $prompt);
$divClass = "optional";
if ($required) {
$divClass = "required";
}
$strError=""; // initialize the error to empty.
$strError = "";
if ($this->isFieldError($tagName)) {
// if it was an error that occured, then add the error message, and append " error" to the div tag.
$strError=$this->pTag('error', $errorMsg);
$divClass=sprintf("%s error", $divClass);
}
$divTagInside=sprintf("%s %s %s", $strError, $strLabel, $str);
$divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
return $this->divTag($divClass, $divTagInside);
}
/**
* Returns a formatted submit widget for HTML FORMs.
*
@ -356,7 +298,6 @@ class FormHelper extends Helper{
function generateSubmitDiv($displayText, $htmlOptions = null) {
return $this->divTag('submit', $this->Html->submitTag($displayText, $htmlOptions));
}
/**
* Generates a form to go onto a HtmlHelper object.
*
@ -365,10 +306,11 @@ class FormHelper extends Helper{
* @return string The completed form specified by the $fields parameter
*/
function generateFields($fields, $readOnly = false) {
$strFormFields='';
$strFormFields = '';
foreach($fields as $field) {
if (isset($field['type'])) {
if (!isset($field['required'])) {
$field['required'] = false;
}
@ -385,34 +327,23 @@ class FormHelper extends Helper{
$field['htmlOptions']['READONLY'] = "readonly";
}
switch($field['type'])
{
switch($field['type']) {
case "input":
if (!isset($field['size'])) {
$field['size'] = 40;
}
$strFormFields=
$strFormFields . $this->generateInputDiv($field['tagName'], $field['prompt'],
$field['required'],
$field['errorMsg'], $field['size'],
$field['htmlOptions']);
$strFormFields = $strFormFields . $this->generateInputDiv($field['tagName'], $field['prompt'],
$field['required'], $field['errorMsg'], $field['size'], $field['htmlOptions']);
break;
case "checkbox":
$strFormFields=
$strFormFields . $this->generateCheckboxDiv($field['tagName'], $field['prompt'],
$field['required'],
$field['errorMsg'],
$field['htmlOptions']);
$strFormFields = $strFormFields . $this->generateCheckboxDiv($field['tagName'], $field['prompt'],
$field['required'], $field['errorMsg'], $field['htmlOptions']);
break;
case "select":
case "selectMultiple":
if ("selectMultiple" == $field['type']) {
$field['selectAttr']['multiple']='multiple';
$field['selectAttr']['class'] ='selectMultiple';
$field['selectAttr']['multiple'] = 'multiple';
$field['selectAttr']['class'] = 'selectMultiple';
}
if (!isset($field['selected'])) {
@ -434,17 +365,9 @@ class FormHelper extends Helper{
if (!isset($field['options'])) {
$field['options'] = null;
}
$strFormFields=
$strFormFields . $this->generateSelectDiv($field['tagName'], $field['prompt'],
$field['options'],
$field['selected'],
$field['selectAttr'],
$field['optionsAttr'],
$field['required'],
$field['errorMsg']);
$strFormFields = $strFormFields . $this->generateSelectDiv($field['tagName'], $field['prompt'], $field['options'],
$field['selected'], $field['selectAttr'], $field['optionsAttr'], $field['required'], $field['errorMsg']);
break;
case "area":
if (!isset($field['rows'])) {
$field['rows'] = 10;
@ -453,54 +376,39 @@ class FormHelper extends Helper{
if (!isset($field['cols'])) {
$field['cols'] = 60;
}
$strFormFields=
$strFormFields . $this->generateAreaDiv($field['tagName'], $field['prompt'],
$field['required'],
$field['errorMsg'], $field['cols'],
$field['rows'],
$field['htmlOptions']);
$strFormFields = $strFormFields . $this->generateAreaDiv($field['tagName'], $field['prompt'],
$field['required'], $field['errorMsg'], $field['cols'], $field['rows'], $field['htmlOptions']);
break;
case "fieldset":
$strFieldsetFields=$this->generateFields($field['fields']);
$strFieldSet =sprintf('
<fieldset><legend>%s</legend><div class="notes"><h4>%s</h4><p class="last">%s</p></div>%s</fieldset>', $field['legend'], $field['noteHeading'], $field['note'],
$strFieldsetFields);
$strFormFields =$strFormFields . $strFieldSet;
$strFieldsetFields = $this->generateFields($field['fields']);
$strFieldSet = sprintf(' <fieldset><legend>%s</legend><div class="notes"><h4>%s</h4><p class="last">%s</p></div>%s</fieldset>',
$field['legend'], $field['noteHeading'], $field['note'], $strFieldsetFields);
$strFormFields = $strFormFields . $strFieldSet;
break;
case "hidden":
$strFormFields=$strFormFields . $this->Html->hiddenTag($field['tagName']);
if(!isset($field['value'])){
$field['value'] = null;
}
$strFormFields = $strFormFields . $this->Html->hiddenTag($field['tagName'], $field['value']);
break;
case "date":
if (!isset($field['selected'])) {
$field['selected'] = null;
}
$strFormFields=
$strFormFields . $this->generateDate($field['tagName'], $field['prompt'], null,
$strFormFields = $strFormFields . $this->generateDate($field['tagName'], $field['prompt'], null,
null, null, null, $field['selected']);
break;
case "datetime":
if (!isset($field['selected'])) {
$field['selected'] = null;
}
$strFormFields=$strFormFields
. $this->generateDateTime($field['tagName'], $field['prompt'], '', '', '', '',
$field['selected']);
$strFormFields = $strFormFields . $this->generateDateTime($field['tagName'], $field['prompt'], '', '', '', '', $field['selected']);
break;
default:
break;
default: break;
}
}
}
return $strFormFields;
}
}

View file

@ -129,18 +129,7 @@ class HtmlHelper extends Helper {
* @return mixed Either string or boolean value, depends on AUTO_OUTPUT and $return.
*/
function url($url = null, $return = false) {
$base = $this->base;
if ($this->plugin != null) {
$base = preg_replace('/' . $this->plugin . '/', '', $this->base);
$base = str_replace('//', '', $base);
$pos1 = strrpos($base, '/');
$char = strlen($base) - 1;
if ($pos1 == $char) {
$base = substr($base, 0, $char);
}
}
$base = strip_plugin($this->base, $this->plugin);
if (empty($url)) {
return $this->here;
} elseif($url{0} == '/') {
@ -148,7 +137,8 @@ class HtmlHelper extends Helper {
} else {
$output = $base . '/' . strtolower($this->params['controller']) . '/' . $url;
}
return $this->output(preg_replace('/&([^a])/', '&amp;\1', $output), $return);
return $this->output($output, $return);
}
/**
* Creates an HTML link.
@ -212,6 +202,9 @@ class HtmlHelper extends Helper {
if (!isset($htmlAttributes['value'])) {
$htmlAttributes['value'] = $this->tagValue($fieldName);
}
if (!isset($htmlAttributes['id'])) {
$htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
}
if ($this->tagIsInvalid($this->model, $this->field)) {
if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") {
@ -237,6 +230,9 @@ class HtmlHelper extends Helper {
$value = $htmlAttributes['value'];
unset($htmlAttributes['value']);
}
if (!isset($htmlAttributes['id'])) {
$htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
}
if ($this->tagIsInvalid($this->model, $this->field)) {
if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") {
@ -272,6 +268,9 @@ class HtmlHelper extends Helper {
$htmlAttributes['checked'] = $value ? 'checked' : null;
$htmlAttributes['value'] = 1;
}
if (!isset($htmlAttributes['id'])) {
$htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
}
$output = $this->hidden($fieldName, array('value' => $notCheckedValue), true);
$output .= sprintf($this->tags['checkbox'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, '', ' '));
return $this->output($output, $return);
@ -287,8 +286,12 @@ class HtmlHelper extends Helper {
*/
function css($path, $rel = 'stylesheet', $htmlAttributes = null, $return = false) {
$url = "{$this->webroot}" . (COMPRESS_CSS ? 'c' : '') . CSS_URL . $this->themeWeb . $path . ".css";
if ($rel == 'import') {
return $this->output(sprintf($this->tags['style'], $this->parseHtmlOptions($htmlAttributes, null, '', ' '), '@import url(' . $url . ');'), $return);
} else {
return $this->output(sprintf($this->tags['css'], $rel, $url, $this->parseHtmlOptions($htmlAttributes, null, '', ' ')), $return);
}
}
/**
* Creates file input widget.
*
@ -300,6 +303,9 @@ class HtmlHelper extends Helper {
function file($fieldName, $htmlAttributes = null, $return = false) {
if (strpos($fieldName, '/')) {
$this->setFormTag($fieldName);
if (!isset($htmlAttributes['id'])) {
$htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
}
return $this->output(sprintf($this->tags['file'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
}
return $this->output(sprintf($this->tags['file_no_model'], $fieldName, $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
@ -340,6 +346,9 @@ class HtmlHelper extends Helper {
if (!isset($htmlAttributes['value'])) {
$htmlAttributes['value'] = $this->tagValue($fieldName);
}
if (!isset($htmlAttributes['id'])) {
$htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
}
return $this->output(sprintf($this->tags['hidden'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return);
}
/**
@ -400,9 +409,11 @@ class HtmlHelper extends Helper {
* @return mixed Either string or boolean value, depends on AUTO_OUTPUT and $return.
*/
function radio($fieldName, $options, $inbetween = null, $htmlAttributes = array(), $return = false) {
$this->setFormTag($fieldName);
$value = isset($htmlAttributes['value']) ? $htmlAttributes['value'] : $this->tagValue($fieldName);
$out = array();
foreach($options as $optValue => $optTitle) {
$optionsHere = array('value' => $optValue);
$optValue == $value ? $optionsHere['checked'] = 'checked' : null;
@ -805,6 +816,9 @@ class HtmlHelper extends Helper {
$selectAttr['class'] = 'form_error';
}
}
if (!isset($selectAttr['id'])) {
$selectAttr['id'] = $this->model . Inflector::camelize($this->field);
}
if (!is_array($optionElements)) {
return null;
@ -815,11 +829,9 @@ class HtmlHelper extends Helper {
}
if (isset($selectAttr) && array_key_exists("multiple", $selectAttr)) {
$select[] = sprintf($this->tags['selectmultiplestart'], $this->model, $this->field,
$this->parseHtmlOptions($selectAttr));
$select[] = sprintf($this->tags['selectmultiplestart'], $this->model, $this->field, $this->parseHtmlOptions($selectAttr));
} else {
$select[] = sprintf($this->tags['selectstart'], $this->model, $this->field,
$this->parseHtmlOptions($selectAttr));
$select[] = sprintf($this->tags['selectstart'], $this->model, $this->field, $this->parseHtmlOptions($selectAttr));
}
if ($showEmpty == true) {
@ -835,12 +847,10 @@ class HtmlHelper extends Helper {
$optionsHere['selected'] = 'selected';
}
$select[]
=sprintf($this->tags['selectoption'], $name, $this->parseHtmlOptions($optionsHere), $title);
$select[] = sprintf($this->tags['selectoption'], $name, $this->parseHtmlOptions($optionsHere), $title);
}
$select[]=sprintf($this->tags['selectend']);
$select[] = sprintf($this->tags['selectend']);
return $this->output(implode("\n", $select), $return);
}
/**
@ -855,9 +865,8 @@ class HtmlHelper extends Helper {
* @see HtmlHelper::submit()
*/
function submitTag() {
$args=func_get_args();
return call_user_func_array(array(&$this,
"submit"), $args);
$args = func_get_args();
return call_user_func_array(array(&$this, "submit"), $args);
}
/*************************************************************************
* Moved methods
@ -1101,6 +1110,9 @@ class HtmlHelper extends Helper {
$hourValue = !isset($selected) ? date('H') : $selected;
} else {
$hourValue = !isset($selected) ? date('g') : $selected;
if (intval($hourValue) == 0) {
$hourValue = 12;
}
}
if ($format24Hours) {
@ -1179,6 +1191,10 @@ class HtmlHelper extends Helper {
}
$meridian = 'am';
$selected = trim($selected);
if (strpos($selected, ' ') === false) {
$selected = '0000-00-00 ' . $selected;
}
$date = explode('-', $selected);
$days = explode(' ', $date[2]);

View file

@ -36,19 +36,27 @@
*/
class JavascriptHelper extends Helper{
var $_cachedEvents = array();
var $_cacheEvents = false;
var $_cacheToFile = false;
var $_cacheAll = false;
var $_rules = array();
/**
* Returns a JavaScript script tag.
*
* @param string $script The JavaScript to be wrapped in SCRIPT tags.
* @param boolean $allowCache Allows the script to be cached if non-event caching is active
* @return string The full SCRIPT element, with the JavaScript inside it.
*/
function codeBlock($script) {
function codeBlock($script, $allowCache = true) {
if ($this->_cacheEvents && $this->_cacheAll && $allowCache) {
$this->_cachedEvents[] = $script;
} else {
return sprintf($this->tags['javascriptblock'], $script);
}
}
/**
* Returns a JavaScript include tag (SCRIPT element)
*
@ -56,12 +64,11 @@ class JavascriptHelper extends Helper{
* @return string
*/
function link($url) {
if (strpos($url, ".") === false)
if (strpos($url, ".") === false) {
$url .= ".js";
}
return sprintf($this->tags['javascriptlink'], $this->webroot . JS_URL . $this->themeWeb . $url);
}
/**
* Returns a JavaScript include tag for an externally-hosted script
*
@ -69,12 +76,11 @@ class JavascriptHelper extends Helper{
* @return string
*/
function linkOut($url) {
if (strpos($url, ".") === false)
if (strpos($url, ".") === false) {
$url .= ".js";
}
return sprintf($this->tags['javascriptlink'], $url);
}
/**
* Escape carriage returns and single and double quotes for JavaScript segments.
*
@ -82,18 +88,10 @@ class JavascriptHelper extends Helper{
* @return string escaped string
*/
function escapeScript($script) {
$script=str_replace(array("\r\n",
"\n",
"\r"), '\n',
$script);
$script=str_replace(array('"',
"'"), array('\"',
"\\'"), $script);
$script = r(array("\r\n", "\n", "\r"), '\n', $script);
$script = r(array('"', "'"), array('\"', "\\'"), $script);
return $script;
}
/**
* Escape a string to be JavaScript friendly.
*
@ -108,13 +106,8 @@ class JavascriptHelper extends Helper{
* @return string Escaped string.
*/
function escapeString($string) {
$escape=array("\r\n" => '\n',
"\r" => '\n',
"\n" => '\n',
'"' => '\"',
"'" => "\\'");
return str_replace(array_keys($escape), array_values($escape), $string);
$escape = array("\r\n" => '\n', "\r" => '\n', "\n" => '\n', '"' => '\"', "'" => "\\'");
return r(array_keys($escape), array_values($escape), $string);
}
/**
* Attach an event to an element. Used with the Prototype library.
@ -125,42 +118,93 @@ class JavascriptHelper extends Helper{
* @param boolean $useCapture default true
* @return boolean true on success
*/
function event($object, $event, $observer, $useCapture = false) {
function event($object, $event, $observer = null, $useCapture = false) {
if ($useCapture == true) {
$useCapture = "true";
} else {
$useCapture = "false";
}
$b="Event.observe($object, '$event', function(event){ $observer }, $useCapture);";
if ($object == 'window' || strpos($object, '$(') !== false || strpos($object, '"') !== false || strpos($object, '\'') !== false) {
$b = "Event.observe($object, '$event', function(event){ $observer }, $useCapture);";
} else {
$chars = array('#', ' ', ', ', '.', ':');
$found = false;
foreach ($chars as $char) {
if (strpos($object, $char) !== false) {
$found = true;
break;
}
}
if ($found) {
$this->_rules[$object] = $event;
} else {
$b = "Event.observe(\$('$object'), '$event', function(event){ $observer }, $useCapture);";
}
}
if (isset($b) && !empty($b)) {
if ($this->_cacheEvents === true) {
$this->_cachedEvents[]=$b;
return true;
$this->_cachedEvents[] = $b;
return;
} else {
return $this->codeBlock($b);
}
}
}
/**
* Cache JavaScript events created with event()
*
* @param boolean $file If true, code will be written to a file
* @param boolean $all If true, all code written with JavascriptHelper will be sent to a file
* @return null
*/
function cacheEvents() {
$this->_cacheEvents=true;
function cacheEvents($file = false, $all = false) {
$this->_cacheEvents = true;
$this->_cacheToFile = $file;
$this->_cacheAll = $all;
}
/**
* Write cached JavaScript events
*
* @return string A single code block of all cached JavaScript events created with event()
* @return string
*/
function writeEvents() {
$this->_cacheEvents=false;
return $this->codeBlock("\n" . implode("\n", $this->_cachedEvents) . "\n");
$rules = array();
if (!empty($this->_rules)) {
foreach ($this->_rules as $sel => $event) {
$rules[] = "\t'{$sel}': function(element, event) {\n\t\t{$event}\n\t}";
}
$this->_cacheEvents = true;
}
if ($this->_cacheEvents) {
$this->_cacheEvents = false;
$events = $this->_cachedEvents;
$data = implode("\n", $events);
$this->_cachedEvents = array();
if (!empty($rules)) {
$data .= "\n\nvar SelectorRules = {\n" . implode(",\n\n", $rules) . "\n}\n";
$data .= "\nEventSelectors.start(SelectorRules);\n";
}
if (!empty($events) || !empty($rules)) {
if ($this->_cacheToFile) {
$filename = md5($data);
if (!file_exists(JS . $filename . '.js')) {
cache(r(WWW_ROOT, '', JS) . $filename . '.js', $data, '+999 days', 'public');
}
return $this->link($filename);
} else {
return $this->codeBlock("\n" . $data . "\n");
}
}
}
}
/**
* Includes the Prototype Javascript library (and anything else) inside a single script tag.
*
@ -172,8 +216,8 @@ class JavascriptHelper extends Helper{
*/
function includeScript($script = "") {
if ($script == "") {
$files =scandir(JS);
$javascript='';
$files = scandir(JS);
$javascript = '';
foreach($files as $file) {
if (substr($file, -3) == '.js') {
@ -183,10 +227,8 @@ class JavascriptHelper extends Helper{
} else {
$javascript = file_get_contents(JS . "$script.js") . "\n\n";
}
return $this->codeBlock("\n\n" . $javascript);
}
/**
* Generates a JavaScript object in JavaScript Object Notation (JSON)
* from an array
@ -200,25 +242,24 @@ class JavascriptHelper extends Helper{
* @param string $q The type of quote to use
* @return string A JSON code block
*/
function object($data = array(), $block = false, $prefix = '', $postfix = '', $stringKeys = array(),
$quoteKeys = true, $q = "\"") {
function object($data = array(), $block = false, $prefix = '', $postfix = '', $stringKeys = array(), $quoteKeys = true, $q = "\"") {
if (is_object($data)) {
$data = get_object_vars($data);
}
$out=array();
$key=array();
$out = array();
$key = array();
if (is_array($data)) {
$keys = array_keys($data);
}
$numeric=true;
$numeric = true;
if (!empty($keys)) {
foreach($keys as $key) {
if (!is_numeric($key)) {
$numeric=false;
$numeric = false;
break;
}
}
@ -228,12 +269,9 @@ class JavascriptHelper extends Helper{
if (is_array($val) || is_object($val)) {
$val = $this->object($val, false, '', '', $stringKeys, $quoteKeys, $q);
} else {
if ((!count($stringKeys) && !is_numeric($val) && !is_bool($val))
|| ($quoteKeys && in_array($key, $stringKeys))
|| (!$quoteKeys && !in_array($key, $stringKeys))) {
if ((!count($stringKeys) && !is_numeric($val) && !is_bool($val)) || ($quoteKeys && in_array($key, $stringKeys)) || (!$quoteKeys && !in_array($key, $stringKeys))) {
$val = $q . $val . $q;
}
if (trim($val) == '') {
$val = 'null';
}
@ -243,7 +281,7 @@ class JavascriptHelper extends Helper{
$val = $key . ':' . $val;
}
$out[]=$val;
$out[] = $val;
}
if (!$numeric) {
@ -251,8 +289,7 @@ class JavascriptHelper extends Helper{
} else {
$rt = '[' . join(', ', $out) . ']';
}
$rt=$prefix . $rt . $postfix;
$rt = $prefix . $rt . $postfix;
if ($block) {
$rt = $this->codeBlock($rt);
@ -260,5 +297,14 @@ class JavascriptHelper extends Helper{
return $rt;
}
/**
* AfterRender callback. Writes any cached events to the view, or to a temp file.
*
* @return null
*/
function afterRender() {
echo $this->writeEvents();
}
}
?>

View file

@ -29,7 +29,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CakePHP : The PHP Rapid Development Framework :: <?php echo $title_for_layout?></title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="<?php echo $html->url('/favicon.ico');?>" type="image/x-icon" />
<?php echo $html->charset('UTF-8')?>
<?php echo $html->css('cake.basic', 'stylesheet', array("media"=>"all" ));?>
<?php echo $html->css('cake.forms', 'stylesheet', array("media"=>"all" ));?>

View file

@ -35,9 +35,8 @@
<p style="background:#DBA941;padding:4px;font-size: 16px;">Cake<?php echo $connected->isConnected() ? ' is able to' : ' is not able to';?> connect to the database.</p>
<br />
<?php endif; ?>
<h1>CakePHP</h1>
<p>If you plan to upgrade from an older version, you may also want to read the <a href="http://cakephp.org/pages/changelog">changelog</a></p>
<h2>CakePHP release information is on CakeForge</h2>
<a href="http://cakeforge.org/projects/cakephp">Read the release notes and get the latest version</a>
<h2>Editing this Page</h2>
<p>
@ -62,15 +61,15 @@ to rapidly develop robust web applications, without any loss to flexibility.
<ul><li>Get your own CakePHP gear - Doughnate to Cake</li></ul></li>
<li><a href="http://www.cakephp.org">CakePHP</a>
<ul><li>The Rapid Development Framework</li></ul></li>
<li><a href="http://manual.cakephp.org">CakePHPManual</a>
<li><a href="http://manual.cakephp.org">CakePHP Manual</a>
<ul><li>Your Rapid Development Cookbook</li></ul></li>
<li><a href="http://wiki.cakephp.org">CakePHPWiki</a>
<li><a href="http://wiki.cakephp.org">CakePHP Wiki</a>
<ul><li>The Community for CakePHP</li></ul></li>
<li><a href="http://api.cakephp.org">CakePHPAPI</a>
<li><a href="http://api.cakephp.org">CakePHP API</a>
<ul><li>Docblock Your Best Friend</li></ul></li>
<li><a href="http://www.cakeforge.org">CakeForge</a>
<ul><li>Open Development for CakePHP</li></ul></li>
<li><a href="https://trac.cakephp.org/">CakePHPTrac</a>
<li><a href="https://trac.cakephp.org/">CakePHP Trac</a>
<ul><li>For the Development of CakePHP (Tickets, SVN browser, Roadmap, Changelogs)</li></ul></li>
<li><a href="http://groups-beta.google.com/group/cake-php">CakePHP Google Group</a>
<ul><li>Community mailing list</li></ul></li>

View file

@ -386,11 +386,10 @@ class View extends Object{
* @return mixed Rendered output, or false on error
*/
function renderLayout($content_for_layout) {
$layout_fn=$this->_getLayoutFileName();
$layout_fn = $this->_getLayoutFileName();
if (DEBUG > 2 && $this->controller != null) {
$debug = View::_render(LIBS . 'view' . DS . 'templates' . DS . 'elements' . DS
. 'dump.thtml', array('controller' => $this->controller), false);
$debug = View::_render(LIBS . 'view' . DS . 'templates' . DS . 'elements' . DS . 'dump.thtml', array('controller' => $this->controller), false);
} else {
$debug = '';
}
@ -401,32 +400,44 @@ class View extends Object{
$pageTitle = Inflector::humanize($this->viewPath);
}
$data_for_layout=array_merge($this->_viewVars, array('title_for_layout' => $pageTitle,
$data_for_layout = array_merge(
$this->_viewVars,
array(
'title_for_layout' => $pageTitle,
'content_for_layout' => $content_for_layout,
'cakeDebug' => $debug));
'cakeDebug' => $debug
)
);
if (is_file($layout_fn)) {
$data_for_layout=array_merge($data_for_layout, $this->loaded);
if (empty($this->loaded) && !empty($this->helpers)) {
$loadHelpers = true;
} else {
$loadHelpers = false;
$data_for_layout = array_merge($data_for_layout, $this->loaded);
}
if (substr($layout_fn, -5) === 'thtml') {
$out = View::_render($layout_fn, $data_for_layout, false, true);
$out = View::_render($layout_fn, $data_for_layout, $loadHelpers, true);
} else {
$out = $this->_render($layout_fn, $data_for_layout, false);
$out = $this->_render($layout_fn, $data_for_layout, $loadHelpers);
}
if ($out === false) {
$out=$this->_render($layout_fn, $data_for_layout);
trigger_error(
sprintf(__("Error in layout %s, got: <blockquote>%s</blockquote>"), $layout_fn, $out),
E_USER_ERROR);
$out = $this->_render($layout_fn, $data_for_layout);
trigger_error(sprintf(__("Error in layout %s, got: <blockquote>%s</blockquote>"), $layout_fn, $out), E_USER_ERROR);
return false;
} else {
return $out;
}
} else {
return $this->cakeError('missingLayout', array(array('layout' => $this->layout,
return $this->cakeError('missingLayout', array(
array(
'layout' => $this->layout,
'file' => $layout_fn,
'base' => $this->base)));
'base' => $this->base
)
));
}
}
@ -436,7 +447,7 @@ class View extends Object{
* @param string $layout Name of layout.
*/
function setLayout($layout) {
$this->layout=$layout;
$this->layout = $layout;
}
/**
@ -465,8 +476,8 @@ class View extends Object{
* @access private
*/
function _getViewFileName($action) {
$action=Inflector::underscore($action);
$paths =Configure::getInstance();
$action = Inflector::underscore($action);
$paths = Configure::getInstance();
if (!is_null($this->webservices)) {
$type = strtolower($this->webservices) . DS;
@ -474,28 +485,26 @@ class View extends Object{
$type = null;
}
$position=strpos($action, '..');
$position = strpos($action, '..');
if ($position === false) {
} else {
$action=explode('/', $action);
$i =array_search('..', $action);
unset ($action[$i - 1]);
unset ($action[$i]);
$action = explode('/', $action);
$i = array_search('..', $action);
unset($action[$i - 1]);
unset($action[$i]);
$action='..' . DS . implode(DS, $action);
}
foreach($paths->viewPaths as $path) {
if (file_exists($path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext)) {
$viewFileName=$path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext;
$viewFileName = $path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext;
return $viewFileName;
}
}
if ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'errors' . DS . $type
. $action . '.thtml')) {
} elseif($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $this->viewPath . DS
. $type . $action . '.thtml')) {
if ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'errors' . DS . $type . $action . '.thtml')) {
} elseif($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $this->viewPath . DS . $type . $action . '.thtml')) {
} else {
$viewFileName = VIEWS . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext;
}
@ -517,19 +526,15 @@ class View extends Object{
}
if (isset($this->plugin) && !is_null($this->plugin)) {
if (file_exists(
APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . $this->ext)) {
$layoutFileName=
APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . $this->ext;
if (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . $this->ext)) {
$layoutFileName = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . $this->ext;
return $layoutFileName;
}
}
if (file_exists(LAYOUTS . $this->subDir . $type . "{$this->layout}$this->ext")) {
$layoutFileName = LAYOUTS . $this->subDir . $type . "{$this->layout}$this->ext";
} elseif($layoutFileName
= fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . "layouts" . DS . $type . "{$this->layout}.thtml"))
{
} elseif($layoutFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . "layouts" . DS . $type . "{$this->layout}.thtml")) {
} else {
$layoutFileName = LAYOUTS . $type . "{$this->layout}$this->ext";
}
@ -548,14 +553,12 @@ class View extends Object{
*/
function _render($___viewFn, $___dataForView, $loadHelpers = true, $cached = false) {
if ($this->helpers != false && $loadHelpers === true) {
$helperVars = array();
$loadedHelpers = array();
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
foreach(array_keys($loadedHelpers) as $helper) {
$replace = strtolower(substr($helper, 0, 1));
$camelBackedHelper = preg_replace('/\\w/', $replace, $helper, 1);
$helperVars[] = $camelBackedHelper;
${$camelBackedHelper} =& $loadedHelpers[$helper];
@ -564,7 +567,7 @@ class View extends Object{
${$camelBackedHelper}->{$subHelper} =& $loadedHelpers[$subHelper];
}
}
$this->loaded[$camelBackedHelper]=(${$camelBackedHelper});
$this->loaded[$camelBackedHelper] = (${$camelBackedHelper});
}
}
@ -582,8 +585,12 @@ class View extends Object{
}
if ($this->helpers != false && $loadHelpers === true) {
foreach ($helperVars as $helper) {
${$helper}->afterRender();
foreach ($loadedHelpers as $helper) {
if (is_object($helper)) {
if (is_subclass_of($helper, 'Helper') || is_subclass_of($helper, 'helper')) {
$helper->afterRender();
}
}
}
}
@ -597,11 +604,11 @@ class View extends Object{
$cache->view = &$this;
}
$cache->base =$this->base;
$cache->here =$this->here;
$cache->action =$this->action;
$cache->controllerName=$this->params['controller'];
$cache->cacheAction =$this->controller->cacheAction;
$cache->base = $this->base;
$cache->here = $this->here;
$cache->action = $this->action;
$cache->controllerName = $this->params['controller'];
$cache->cacheAction = $this->controller->cacheAction;
$cache->cache($___viewFn, $out, $cached);
}
}
@ -628,18 +635,8 @@ class View extends Object{
if (in_array($helper, array_keys($loaded)) !== true) {
if (!class_exists($helperCn)) {
$helperFn = Inflector::underscore($helper) . '.php';
if (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'helpers' . DS . $helperFn)) {
$helperFn = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'helpers' . DS . $helperFn;
} else if(file_exists(HELPERS . $helperFn)) {
$helperFn = HELPERS . $helperFn;
} else if($helperFn = fileExistsInPath(LIBS . 'view' . DS . 'helpers' . DS . $helperFn)) {
}
if (is_file($helperFn)) {
require $helperFn;
} else {
if (is_null($this->plugin) || !loadPluginHelper($this->plugin, $helper)) {
if (!loadHelper($helper)) {
return $this->cakeError('missingHelperFile', array(array(
'helper' => $helper,
'file' => Inflector::underscore($helper) . '.php',
@ -647,11 +644,18 @@ class View extends Object{
)));
}
}
if (!class_exists($helperCn)) {
return $this->cakeError('missingHelperClass', array(array(
'helper' => $helper,
'file' => Inflector::underscore($helper) . '.php',
'base' => $this->base
)));
}
}
$replace = strtolower(substr($helper, 0, 1));
$camelBackedHelper = preg_replace('/\\w/', $replace, $helper, 1);
if (class_exists($helperCn)) {
${$camelBackedHelper} =& new $helperCn;
${$camelBackedHelper}->view =& $this;
${$camelBackedHelper}->base = $this->base;
@ -673,13 +677,6 @@ class View extends Object{
if (isset(${$camelBackedHelper}->helpers) && is_array(${$camelBackedHelper}->helpers)) {
$loaded = &$this->_loadHelpers($loaded, ${$camelBackedHelper}->helpers);
}
} else {
return $this->cakeError('missingHelperClass', array(array(
'helper' => $helper,
'file' => Inflector::underscore($helper) . '.php',
'base' => $this->base
)));
}
}
}
return $loaded;

View file

@ -27,8 +27,12 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
define ('DS', DIRECTORY_SEPARATOR);
if (function_exists('ini_set')) {
ini_set('display_errors', '1');
ini_set('error_reporting', '7');
}
$app = 'app';
$root = dirname(dirname(dirname(__FILE__)));
$core = null;
@ -61,7 +65,12 @@
break;
}
}
define ('DS', DIRECTORY_SEPARATOR);
if (strlen($app) && $app[0] == DS) {
$cnt = substr_count($root, DS);
$app = str_repeat('..' . DS, $cnt) . $app;
}
define ('ROOT', $root.DS);
define ('APP_DIR', $app);
define ('APP_PATH', $app.DS);
@ -71,6 +80,9 @@
if(function_exists('ini_set')) {
ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.PATH_SEPARATOR.ROOT.DS.APP_DIR.DS);
} else {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
require_once (ROOT.'cake'.DS.'basics.php');
@ -219,12 +231,16 @@ class Bake {
}
}
$password = '';
$blankPassword = false;
while ($password == '') {
while ($password == '' && $blankPassword == false) {
$password = $this->getInput('What is the database password?');
if ($password == '') {
$this->stdout('The password you supplied was empty. Please try again.');
$blank = $this->getInput('The password you supplied was empty. Use an empty password?', array('y', 'n'), 'n');
if($blank == 'y')
{
$blankPassword = true;
}
}
}
$database = '';
@ -272,7 +288,18 @@ class Bake {
}*/
$modelName = '';
$db =& ConnectionManager::getDataSource($dbConnection);
$usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix'];
if ($usePrefix) {
$tables = array();
foreach ($db->listSources() as $table) {
if (! strncmp($table, $usePrefix, strlen($usePrefix))) {
$tables[] = substr($table, strlen($usePrefix));
}
}
} else {
$tables = $db->listSources();
}
$inflect = new Inflector();
$this->stdout('Possible models based on your current database:');
@ -391,7 +418,7 @@ class Bake {
$this->stdout('Done.');
$this->hr();
//if none found...
if(count($hasOneClasses) < 1 && count($hasManyClasses) < 1 && count($hasAndBelongsToManyClasses) < 1 && count($belongsToClasses)) {
if(count($hasOneClasses) < 1 && count($hasManyClasses) < 1 && count($hasAndBelongsToManyClasses) < 1 && count($belongsToClasses) < 1) {
$this->stdout('None found.');
} else {
$this->stdout('Please confirm the following associations:');
@ -502,7 +529,7 @@ class Bake {
$looksGood = $this->getInput('Look okay?', array('y','n'), 'y');
if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') {
if ($inflect->camelize($inflect->singularize($modelTableName)) == $modelClassName) {
if ($modelTableName == $inflect->underscore($inflect->pluralize($modelClassName))) {
// set it to null...
// putting $useTable in the model
// is unnecessary.
@ -842,16 +869,13 @@ class Bake {
}
$tempModel = new $controllerModel();
$actions .= "\n";
$actions .= "\tfunction index()\n";
$actions .= "\t{\n";
$actions .= "\tfunction index() {\n";
$actions .= "\t\t\$this->{$controllerModel}->recursive = 0;\n";
$actions .= "\t\t\$this->set('{$this->lowCtrl}', \$this->{$controllerModel}->findAll());\n";
$actions .= "\t}\n";
$actions .= "\n";
$actions .= "\tfunction add()\n";
$actions .= "\t{\n";
$actions .= "\t\tif(empty(\$this->data))\n";
$actions .= "\t\t{\n";
$actions .= "\tfunction add() {\n";
$actions .= "\t\tif(empty(\$this->data)) {\n";
foreach($tempModel->hasAndBelongsToMany as $association => $relation) {
if(!empty($relation['className'])) {
@ -869,26 +893,17 @@ class Bake {
}
}
$actions .= "\t\t\t\$this->set('{$this->lowCtrl}', null);\n";
$actions .= "\t\t}\n";
$actions .= "\t\telse\n";
$actions .= "\t\t{\n";
$actions .= "\t\t} else {\n";
$actions .= "\t\t\t\$this->cleanUpFields();\n";
$actions .= "\t\t\tif(\$this->{$controllerModel}->save(\$this->data))\n";
$actions .= "\t\t\t{\n";
$actions .= "\t\t\t\tif(is_object(\$this->Session))\n";
$actions .= "\t\t\t\t{\n";
$actions .= "\t\t\tif(\$this->{$controllerModel}->save(\$this->data)) {\n";
$actions .= "\t\t\t\tif(is_object(\$this->Session)) {\n";
$actions .= "\t\t\t\t\t\$this->Session->setFlash('The ".Inflector::humanize($controllerModel)." has been saved');\n";
$actions .= "\t\t\t\t\t\$this->redirect(\$this->viewPath.'/index');\n";
$actions .= "\t\t\t\t}\n";
$actions .= "\t\t\t\telse\n";
$actions .= "\t\t\t\t{\n";
$actions .= "\t\t\t\t} else {\n";
$actions .= "\t\t\t\t\t\$this->flash('{$controllerModel} saved.', \$this->viewPath.'/index');\n";
$actions .= "\t\t\t\t}\n";
$actions .= "\t\t\t}\n";
$actions .= "\t\t\telse\n";
$actions .= "\t\t\t{\n";
$actions .= "\t\t\t\tif(is_object(\$this->Session))\n";
$actions .= "\t\t\t\t{\n";
$actions .= "\t\t\t} else {\n";
$actions .= "\t\t\t\tif(is_object(\$this->Session)) {\n";
$actions .= "\t\t\t\t\t\$this->Session->setFlash('Please correct errors below.');\n";
$actions .= "\t\t\t\t}\n";
$actions .= "\t\t\t\t\$data = \$this->data;\n";
@ -901,10 +916,8 @@ class Bake {
$lowerName = strtolower($association);
$actions .= "\t\t\t\t\${$lowerName} = null;\n";
$actions .= "\t\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n";
$actions .= "\t\t\t\tif(isset(\$data['{$model}']['{$model}']))\n";
$actions .= "\t\t\t\t{\n";
$actions .= "\t\t\t\t\tforeach(\$data['{$model}']['{$model}'] as \$var)\n";
$actions .= "\t\t\t\t\t{\n";
$actions .= "\t\t\t\tif(isset(\$data['{$model}']['{$model}'])) {\n";
$actions .= "\t\t\t\t\tforeach(\$data['{$model}']['{$model}'] as \$var) {\n";
$actions .= "\t\t\t\t\t\t\${$lowerName}[\$var] = \$var;\n";
$actions .= "\t\t\t\t\t}\n";
$actions .= "\t\t\t\t}\n";
@ -922,10 +935,8 @@ class Bake {
$actions .= "\t\t}\n";
$actions .= "\t}\n";
$actions .= "\n";
$actions .= "\tfunction edit(\$id)\n";
$actions .= "\t{\n";
$actions .= "\t\tif(empty(\$this->data))\n";
$actions .= "\t\t{\n";
$actions .= "\tfunction edit(\$id) {\n";
$actions .= "\t\tif(empty(\$this->data)) {\n";
$actions .= "\t\t\t\$data = \$this->{$controllerModel}->read(null, \$id);\n";
$actions .= "\t\t\t\$this->set('{$this->lowCtrl}', \$data );\n";
@ -936,8 +947,7 @@ class Bake {
$lowerName = strtolower($association);
$actions .= "\t\t\t\${$lowerName} = null;\n";
$actions .= "\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n";
$actions .= "\t\t\tforeach(\$data['{$model}'] as \$var)\n";
$actions .= "\t\t\t{\n";
$actions .= "\t\t\tforeach(\$data['{$model}'] as \$var) {\n";
$actions .= "\t\t\t\t\${$lowerName}[\$var['{$associationModel->primaryKey}']] = \$var['{$associationModel->primaryKey}'];\n";
$actions .= "\t\t\t}\n";
$actions .= "\t\t\t\$this->set('selected{$model}', \${$lowerName});\n";
@ -950,26 +960,17 @@ class Bake {
$actions .= "\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n";
}
}
$actions .= "\t\t}\n";
$actions .= "\t\telse\n";
$actions .= "\t\t{\n";
$actions .= "\t\t} else {\n";
$actions .= "\t\t\t\$this->cleanUpFields();\n";
$actions .= "\t\t\tif(\$this->{$controllerModel}->save(\$this->data))\n";
$actions .= "\t\t\t{\n";
$actions .= "\t\t\t\tif(is_object(\$this->Session))\n";
$actions .= "\t\t\t\t{\n";
$actions .= "\t\t\tif(\$this->{$controllerModel}->save(\$this->data)) {\n";
$actions .= "\t\t\t\tif(is_object(\$this->Session)) {\n";
$actions .= "\t\t\t\t\t\$this->Session->setFlash('The ".Inflector::humanize($controllerModel)." has been saved');\n";
$actions .= "\t\t\t\t\t\$this->redirect(\$this->viewPath.'/index');\n";
$actions .= "\t\t\t\t}\n";
$actions .= "\t\t\t\telse\n";
$actions .= "\t\t\t\t{\n";
$actions .= "\t\t\t\t} else {\n";
$actions .= "\t\t\t\t\t\$this->flash('{$controllerModel} saved.', \$this->viewPath.'/index');\n";
$actions .= "\t\t\t\t}\n";
$actions .= "\t\t\t}\n";
$actions .= "\t\t\telse\n";
$actions .= "\t\t\t{\n";
$actions .= "\t\t\t\tif(is_object(\$this->Session))\n";
$actions .= "\t\t\t\t{\n";
$actions .= "\t\t\t} else {\n";
$actions .= "\t\t\t\tif(is_object(\$this->Session)) {\n";
$actions .= "\t\t\t\t\t\$this->Session->setFlash('Please correct errors below.');\n";
$actions .= "\t\t\t\t}\n";
$actions .= "\t\t\t\t\$data = \$this->data;\n";
@ -982,10 +983,8 @@ class Bake {
$lowerName = strtolower($association);
$actions .= "\t\t\t\t\${$lowerName} = null;\n";
$actions .= "\t\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n";
$actions .= "\t\t\t\tif(isset(\$data['{$model}']['{$model}']))\n";
$actions .= "\t\t\t\t{\n";
$actions .= "\t\t\t\t\tforeach(\$data['{$model}']['{$model}'] as \$var)\n";
$actions .= "\t\t\t\t\t{\n";
$actions .= "\t\t\t\tif(isset(\$data['{$model}']['{$model}'])) {\n";
$actions .= "\t\t\t\t\tforeach(\$data['{$model}']['{$model}'] as \$var) {\n";
$actions .= "\t\t\t\t\t\t\${$lowerName}[\$var] = \$var;\n";
$actions .= "\t\t\t\t\t}\n";
$actions .= "\t\t\t\t}\n";
@ -1003,13 +1002,11 @@ class Bake {
$actions .= "\t\t}\n";
$actions .= "\t}\n";
$actions .= "\n";
$actions .= "\tfunction view(\$id)\n";
$actions .= "\t{\n";
$actions .= "\tfunction view(\$id) {\n";
$actions .= "\t\t\$this->set('{$this->lowCtrl}', \$this->{$controllerModel}->read(null, \$id));\n";
$actions .= "\t}\n";
$actions .= "\n";
$actions .= "\tfunction delete(\$id)\n";
$actions .= "\t{\n";
$actions .= "\tfunction delete(\$id) {\n";
$actions .= "\t\t\$this->{$controllerModel}->del(\$id);\n";
$actions .= "\t\t\$this->redirect('/{$this->lowCtrl}/index');\n";
$actions .= "\t}\n";
@ -1890,7 +1887,6 @@ class Bake {
$this->stdout(' -core [path...] Absolute path to Cake\'s cake Folder.');
$this->stdout(' -help Shows this help message.');
$this->stdout(' -project [path...] Generates a new app folder in the path supplied.');
$this->stdout(' Must be used with the -app command.');
$this->stdout(' -root [path...] Absolute path to Cake\'s \app\webroot Folder.');
$this->stdout('');
}
@ -1924,13 +1920,6 @@ class Bake {
$parentPath = explode(DS, $projectPath);
$count = count($parentPath);
$appName = $parentPath[$count - 1];
unset($parentPath[$count - 1]);
$parentPath = implode(DS, $parentPath);
if(!is_writable($parentPath)) {
$projectPath = $this->getInput('The directory path is not writable. Please try again');
$this->project($projectPath);
}
$this->__buildDirLayout($projectPath, $appName);
exit();
}
@ -2019,7 +2008,9 @@ class Bake {
$messages=array();
if (!is_dir($toDir)) {
mkdir($toDir, 0755);
uses('folder');
$folder = new Folder();
$folder->mkdirr($toDir, 0755);
}
if (!is_writable($toDir)) {
@ -2082,7 +2073,8 @@ class Bake {
* Enter description here...
*
*/
function welcome() {
function welcome()
{
$this->stdout('');
$this->stdout(' ___ __ _ _ ___ __ _ _ __ __ __ _ _ ___ ');
$this->stdout('| |__| |_/ |__ |__] |__| |__] |__] |__| |_/ |__ ');

View file

@ -37,7 +37,7 @@
* release/app/.htaccess
* release/app/webroot/.htaccess
*/
//define ('BASE_URL', env('SCRIPT_NAME'));
// define ('BASE_URL', env('SCRIPT_NAME'));
/**
* Set debug level here:
* - 0: production
@ -76,6 +76,13 @@
*
*/
define('CAKE_SESSION_SAVE', 'php');
/**
* If using you own table name for storing sessions
* set the table name here.
* DO NOT INCLUDE PREFIX IF YOU HAVE SET ONE IN database.php
*
*/
define('CAKE_SESSION_TABLE', 'cake_sessions');
/**
* Set a random string of used in session.
*
@ -108,7 +115,7 @@
* name you set CAKE_ADMIN to.
* For example: admin_index, admin_edit
*/
//define('CAKE_ADMIN', 'admin');
// define('CAKE_ADMIN', 'admin');
/**
* The define below is used to turn cake built webservices
* on or off. Default setting is off.

View file

@ -33,34 +33,34 @@
*
* $pluralRules = array('/(s)tatus$/i' => '\1\2tatuses', '/^(ox)$/i' => '\1\2en', '/([m|l])ouse$/i' => '\1ice');
*/
$pluralRules = array();
$pluralRules = array();
/**
* This is a key only array of plural words that should not be inflected.
* Notice the last comma
*
* $uninflectedPlural = array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox');
*/
$uninflectedPlural = array();
$uninflectedPlural = array();
/**
* This is a key => value array of plural irregular words.
* If key matches then the value is returned.
*
* $irregularPlural = array('atlas' => 'atlases', 'beef' => 'beefs', 'brother' => 'brothers')
*/
$irregularPlural = array();
$irregularPlural = array();
/**
* This is a key => value array of regex used to match words.
* If key matches then the value is returned.
*
* $singularRules = array('/(s)tatuses$/i' => '\1\2tatus', '/(matr)ices$/i' =>'\1ix','/(vert|ind)ices$/i')
*/
$singularRules = array();
$singularRules = array();
/**
* This is a key only array of singular words that should not be inflected.
* You should not have to change this value below if you do change it use same format
* as the $uninflectedPlural above.
*/
$uninflectedSingular = $uninflectedPlural;
$uninflectedSingular = $uninflectedPlural;
/**
* This is a key => value array of singular irregular words.
* Most of the time this will be a reverse of the above $irregularPlural array
@ -68,5 +68,5 @@ $uninflectedSingular = $uninflectedPlural;
*
* $irregularSingular = array('atlases' => 'atlas', 'beefs' => 'beef', 'brothers' => 'brother')
*/
$irregularSingular = array_flip($irregularPlural);
$irregularSingular = array_flip($irregularPlural);
?>

View file

@ -33,14 +33,14 @@
* its action called 'display', and we pass a param to select the view file
* to use (in this case, /app/views/pages/home.thtml)...
*/
$Route->connect ('/', array('controller'=>'pages', 'action'=>'display', 'home'));
$Route->connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
/**
* ...and connect the rest of 'Pages' controller's urls.
*/
$Route->connect ('/pages/*', array('controller'=>'pages', 'action'=>'display'));
$Route->connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
/**
* Then we connect url '/test' to our test controller. This is helpfull in
* developement.
*/
$Route->connect ('/tests', array('controller'=>'tests', 'action'=>'index'));
$Route->connect('/tests', array('controller' => 'tests', 'action' => 'index'));
?>

View file

@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CakePHP : <?php echo $title_for_layout;?></title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="<?php echo $html->url('/favicon.ico')?>" type="image/x-icon" />
<?php echo $html->css('generic.basic');?>
<?php echo $html->css('generic.forms');?>
</head>

View file

@ -68,9 +68,10 @@
if (preg_match('|\.\.|', $url) || !preg_match('|^ccss/(.+)$|i', $url, $regs)) {
die('Wrong file name.');
}
$filename = 'css/' . $regs[1];
$filepath = CSS . $regs[1];
$cachepath = CACHE . 'css' . DS . str_replace(array('/','\\'), '-', $regs[1]);
$filename = 'css/' . $regs[1];
$filepath = CSS . $regs[1];
$cachepath = CACHE . 'css' . DS . str_replace(array('/','\\'), '-', $regs[1]);
if (!file_exists($filepath)) {
die('Wrong file name.');

View file

@ -8,7 +8,7 @@ font-family:verdana,helvetica,arial,sans-serif;
font-size:12px;
text-align:center;
color:#333;
background:#fff;
background:#003d4c;
line-height: 18px;
}
@ -18,11 +18,11 @@ line-height: 18px;
a{
color:#003d4c;
text-decoration:none;
text-decoration:underline;
}
a:hover{
color:#003d4c;
text-decoration:underline;
text-decoration:none;
}
a img{
@ -90,6 +90,8 @@ font-weight:normal;
#content{
padding: 10px 40px;
background-color: #fff;
color: #333;
}
#footer{
padding: 6px 10px;
@ -151,20 +153,29 @@ dd {
vertical-align:top;
}
/* scaffold buttons */
/* notices and errors */
p.error, error_message {
color: #e32000;
font-size: 18px;
background-color: #fff;
margin: 8px 4px;
}
p.error em {
font-size: 18px;
color: #003d4c;
}
.notice {
color: #DB8101;
background-color: #ddd;
display: block;
padding: 1em;
color: #656565;
font-size: 14px;
background-color: #f4f4f4;
padding: 4px;
display:block;
}
.tip {
color: #DB8101;
color: #e32000;
background-color: #ddd;
display: block;
padding: 1em;
}

View file

@ -129,12 +129,7 @@ form div label.labelCheckbox, form div label.labelRadio {
form div fieldset label.labelCheckbox, form div fieldset label.labelRadio {
margin: 0px 0px 5px 0px;
}
p.error {
color: #DB8101;
background-color: #DBA941;
font-size: 14px;
padding: 1em;
}
form div input, form div select, form div textarea {
padding: 1px 3px;

View file

@ -76,10 +76,9 @@
}
}
require CORE_PATH . 'cake' . DS . 'bootstrap.php';
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {
} else {
$Dispatcher = new Dispatcher();
$Dispatcher=new Dispatcher();
$Dispatcher->dispatch($url);
}
if (DEBUG) {