Correcting code structure to standards

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5313 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-06-20 06:15:35 +00:00
parent a9c0b7e406
commit 23dfd90b29
102 changed files with 1401 additions and 1401 deletions

View file

@ -33,7 +33,7 @@
$file = $_GET['file']; $file = $_GET['file'];
$pos = strpos($file, '..'); $pos = strpos($file, '..');
if ($pos === false) { if ($pos === false) {
if(is_file('../../vendors/javascript/'.$file) && (preg_match('/(\/.+)\\.js/', $file))) if (is_file('../../vendors/javascript/'.$file) && (preg_match('/(\/.+)\\.js/', $file)))
{ {
readfile('../../vendors/javascript/'.$file); readfile('../../vendors/javascript/'.$file);
} }

View file

@ -63,7 +63,7 @@ require_once CORE_PATH . 'cake' . DS . 'bootstrap.php';
require_once CAKE . 'basics.php'; require_once CAKE . 'basics.php';
require_once CAKE . 'config' . DS . 'paths.php'; require_once CAKE . 'config' . DS . 'paths.php';
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php'; require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php';
if(DEBUG < 1) { if (DEBUG < 1) {
die('Invalid url.'); die('Invalid url.');
} }
@ -85,13 +85,13 @@ if (!defined('BASE_URL')){
define('CAKE_TEST_OUTPUT_HTML',1); define('CAKE_TEST_OUTPUT_HTML',1);
define('CAKE_TEST_OUTPUT_TEXT',2); define('CAKE_TEST_OUTPUT_TEXT',2);
if(isset($_GET['output']) && $_GET['output'] == 'html') { if (isset($_GET['output']) && $_GET['output'] == 'html') {
define('CAKE_TEST_OUTPUT', CAKE_TEST_OUTPUT_HTML); define('CAKE_TEST_OUTPUT', CAKE_TEST_OUTPUT_HTML);
} else { } else {
define('CAKE_TEST_OUTPUT', CAKE_TEST_OUTPUT_TEXT); define('CAKE_TEST_OUTPUT', CAKE_TEST_OUTPUT_TEXT);
} }
if(!vendor('simpletest' . DS . 'reporter')) { if (!vendor('simpletest' . DS . 'reporter')) {
CakePHPTestHeader(); CakePHPTestHeader();
include CAKE . 'tests' . DS . 'lib' . DS . 'simpletest.php'; include CAKE . 'tests' . DS . 'lib' . DS . 'simpletest.php';
CakePHPTestSuiteFooter(); CakePHPTestSuiteFooter();
@ -118,14 +118,14 @@ if(!vendor('simpletest' . DS . 'reporter')) {
switch (CAKE_TEST_OUTPUT) { switch (CAKE_TEST_OUTPUT) {
case CAKE_TEST_OUTPUT_HTML: case CAKE_TEST_OUTPUT_HTML:
if (isset($_GET['group'])) { if (isset($_GET['group'])) {
if(isset($_GET['app'])) { if (isset($_GET['app'])) {
$show = '?show=groups&amp;app=true'; $show = '?show=groups&amp;app=true';
} else { } else {
$show = '?show=groups'; $show = '?show=groups';
} }
} }
if (isset($_GET['case'])) { if (isset($_GET['case'])) {
if(isset($_GET['app'])) { if (isset($_GET['app'])) {
$show = '??show=cases&amp;app=truee'; $show = '??show=cases&amp;app=truee';
} else { } else {
$show = '?show=cases'; $show = '?show=cases';

View file

@ -50,7 +50,7 @@
* Loads all models. * Loads all models.
*/ */
function loadModels() { function loadModels() {
if(!class_exists('Model')){ if (!class_exists('Model')){
require LIBS . 'model' . DS . 'model.php'; require LIBS . 'model' . DS . 'model.php';
} }
$path = Configure::getInstance(); $path = Configure::getInstance();
@ -64,8 +64,8 @@
} }
$loadedModels = array(); $loadedModels = array();
foreach($path->modelPaths as $path) { foreach ($path->modelPaths as $path) {
foreach(listClasses($path) as $model_fn) { foreach (listClasses($path) as $model_fn) {
list($name) = explode('.', $model_fn); list($name) = explode('.', $model_fn);
$className = Inflector::camelize($name); $className = Inflector::camelize($name);
$loadedModels[$model_fn] = $model_fn; $loadedModels[$model_fn] = $model_fn;
@ -86,7 +86,7 @@
* @deprecated * @deprecated
*/ */
function loadPluginModels($plugin) { function loadPluginModels($plugin) {
if(!class_exists('AppModel')){ if (!class_exists('AppModel')){
loadModel(); loadModel();
} }
@ -100,8 +100,8 @@
} }
$pluginModelDir = APP . 'plugins' . DS . $plugin . DS . 'models' . DS; $pluginModelDir = APP . 'plugins' . DS . $plugin . DS . 'models' . DS;
if(is_dir($pluginModelDir)) { if (is_dir($pluginModelDir)) {
foreach(listClasses($pluginModelDir)as $modelFileName) { foreach (listClasses($pluginModelDir)as $modelFileName) {
list($name) = explode('.', $modelFileName); list($name) = explode('.', $modelFileName);
$className = Inflector::camelize($name); $className = Inflector::camelize($name);
@ -120,7 +120,7 @@
* @return boolean Success * @return boolean Success
*/ */
function loadView($viewClass) { function loadView($viewClass) {
if(strpos($viewClass, '.') !== false){ if (strpos($viewClass, '.') !== false){
list($plugin, $viewClass) = explode('.', $viewClass); list($plugin, $viewClass) = explode('.', $viewClass);
$file = APP . 'plugins' . DS . Inflector::underscore($plugin) . DS . 'views' . DS . Inflector::underscore($viewClass) . '.php'; $file = APP . 'plugins' . DS . Inflector::underscore($plugin) . DS . 'views' . DS . Inflector::underscore($viewClass) . '.php';
if (file_exists($file)) { if (file_exists($file)) {
@ -133,7 +133,7 @@
$paths = Configure::getInstance(); $paths = Configure::getInstance();
$file = Inflector::underscore($viewClass) . '.php'; $file = Inflector::underscore($viewClass) . '.php';
foreach($paths->viewPaths as $path) { foreach ($paths->viewPaths as $path) {
if (file_exists($path . $file)) { if (file_exists($path . $file)) {
return require($path . $file); return require($path . $file);
} }
@ -159,7 +159,7 @@
* @return boolean Success * @return boolean Success
*/ */
function loadModel($name = null) { function loadModel($name = null) {
if(!class_exists('Model')){ if (!class_exists('Model')){
require LIBS . 'model' . DS . 'model.php'; require LIBS . 'model' . DS . 'model.php';
} }
if (!class_exists('AppModel')) { if (!class_exists('AppModel')) {
@ -171,7 +171,7 @@
Overloadable::overload('AppModel'); Overloadable::overload('AppModel');
} }
if(strpos($name, '.') !== false){ if (strpos($name, '.') !== false){
list($plugin, $name) = explode('.', $name); list($plugin, $name) = explode('.', $name);
$pluginAppModel = Inflector::camelize($plugin . '_app_model'); $pluginAppModel = Inflector::camelize($plugin . '_app_model');
@ -200,12 +200,12 @@
$className = $name; $className = $name;
$name = Inflector::underscore($name); $name = Inflector::underscore($name);
$models = Configure::read('Models'); $models = Configure::read('Models');
if(is_array($models)) { if (is_array($models)) {
if(array_key_exists($className, $models)) { if (array_key_exists($className, $models)) {
require($models[$className]['path']); require($models[$className]['path']);
Overloadable::overload($className); Overloadable::overload($className);
return true; return true;
} elseif(isset($models['Core']) && array_key_exists($className, $models['Core'])) { } elseif (isset($models['Core']) && array_key_exists($className, $models['Core'])) {
require($models['Core'][$className]['path']); require($models['Core'][$className]['path']);
Overloadable::overload($className); Overloadable::overload($className);
return true; return true;
@ -213,7 +213,7 @@
} }
$paths = Configure::getInstance(); $paths = Configure::getInstance();
foreach($paths->modelPaths as $path) { foreach ($paths->modelPaths as $path) {
if (file_exists($path . $name . '.php')) { if (file_exists($path . $name . '.php')) {
Configure::store('Models', 'class.paths', array($className => array('path' => $path . $name . '.php'))); Configure::store('Models', 'class.paths', array($className => array('path' => $path . $name . '.php')));
require($path . $name . '.php'); require($path . $name . '.php');
@ -238,23 +238,23 @@
$directories = Configure::getInstance(); $directories = Configure::getInstance();
$paths = array(); $paths = array();
foreach($directories->modelPaths as $path) { foreach ($directories->modelPaths as $path) {
$paths['Models'][] = $path; $paths['Models'][] = $path;
} }
foreach($directories->behaviorPaths as $path) { foreach ($directories->behaviorPaths as $path) {
$paths['Behaviors'][] = $path; $paths['Behaviors'][] = $path;
} }
foreach($directories->controllerPaths as $path) { foreach ($directories->controllerPaths as $path) {
$paths['Controllers'][] = $path; $paths['Controllers'][] = $path;
} }
foreach($directories->componentPaths as $path) { foreach ($directories->componentPaths as $path) {
$paths['Components'][] = $path; $paths['Components'][] = $path;
} }
foreach($directories->helperPaths as $path) { foreach ($directories->helperPaths as $path) {
$paths['Helpers'][] = $path; $paths['Helpers'][] = $path;
} }
if(!class_exists('Folder')){ if (!class_exists('Folder')){
uses('Folder'); uses('Folder');
} }
@ -262,9 +262,9 @@
$plugins = $folder->ls(); $plugins = $folder->ls();
$classPaths = array('models', 'models'.DS.'behaviors', 'controllers', 'controllers'.DS.'components', 'views'.DS.'helpers'); $classPaths = array('models', 'models'.DS.'behaviors', 'controllers', 'controllers'.DS.'components', 'views'.DS.'helpers');
foreach($plugins[0] as $plugin){ foreach ($plugins[0] as $plugin){
foreach($classPaths as $path){ foreach ($classPaths as $path){
if(strpos($path, DS) !== false){ if (strpos($path, DS) !== false){
$key = explode(DS, $path); $key = explode(DS, $path);
$key = $key[1]; $key = $key[1];
} else { } else {
@ -292,8 +292,8 @@
} }
$loadedControllers = array(); $loadedControllers = array();
foreach($paths->controllerPaths as $path) { foreach ($paths->controllerPaths as $path) {
foreach(listClasses($path) as $controller) { foreach (listClasses($path) as $controller) {
list($name) = explode('.', $controller); list($name) = explode('.', $controller);
$className = Inflector::camelize($name); $className = Inflector::camelize($name);
if (loadController($name)) { if (loadController($name)) {
@ -320,7 +320,7 @@
if ($name === null) { if ($name === null) {
return true; return true;
} }
if(strpos($name, '.') !== false){ if (strpos($name, '.') !== false){
list($plugin, $name) = explode('.', $name); list($plugin, $name) = explode('.', $name);
$pluginAppController = Inflector::camelize($plugin . '_app_controller'); $pluginAppController = Inflector::camelize($plugin . '_app_controller');
@ -352,7 +352,7 @@
require($file); require($file);
return true; return true;
} elseif (!class_exists(Inflector::camelize($plugin) . 'Controller')){ } elseif (!class_exists(Inflector::camelize($plugin) . 'Controller')){
if(file_exists(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php')) { if (file_exists(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php')) {
require(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php'); require(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php');
return true; return true;
} else { } else {
@ -367,18 +367,18 @@
if (!class_exists($className)) { if (!class_exists($className)) {
$name = Inflector::underscore($className); $name = Inflector::underscore($className);
$controllers = Configure::read('Controllers'); $controllers = Configure::read('Controllers');
if(is_array($controllers)) { if (is_array($controllers)) {
if(array_key_exists($className, $controllers)) { if (array_key_exists($className, $controllers)) {
require($controllers[$className]['path']); require($controllers[$className]['path']);
return true; return true;
} elseif(isset($controllers['Core']) && array_key_exists($className, $controllers['Core'])) { } elseif (isset($controllers['Core']) && array_key_exists($className, $controllers['Core'])) {
require($controllers['Core'][$className]['path']); require($controllers['Core'][$className]['path']);
return true; return true;
} }
} }
$paths = Configure::getInstance(); $paths = Configure::getInstance();
foreach($paths->controllerPaths as $path) { foreach ($paths->controllerPaths as $path) {
if (file_exists($path . $name . '.php')) { if (file_exists($path . $name . '.php')) {
Configure::store('Controllers', 'class.paths', array($className => array('path' => $path . $name . '.php'))); Configure::store('Controllers', 'class.paths', array($className => array('path' => $path . $name . '.php')));
require($path . $name . '.php'); require($path . $name . '.php');
@ -435,7 +435,7 @@
require($file); require($file);
return true; return true;
} elseif (!class_exists(Inflector::camelize($plugin) . 'Controller')){ } elseif (!class_exists(Inflector::camelize($plugin) . 'Controller')){
if(file_exists(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php')) { if (file_exists(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php')) {
require(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php'); require(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php');
return true; return true;
} else { } else {
@ -464,7 +464,7 @@
if ($name === null) { if ($name === null) {
return true; return true;
} }
if(strpos($name, '.') !== false){ if (strpos($name, '.') !== false){
list($plugin, $name) = explode('.', $name); list($plugin, $name) = explode('.', $name);
} }
@ -473,18 +473,18 @@
$name = Inflector::underscore($name); $name = Inflector::underscore($name);
$helpers = Configure::read('Helpers'); $helpers = Configure::read('Helpers');
if(is_array($helpers)) { if (is_array($helpers)) {
if(array_key_exists($className, $helpers)) { if (array_key_exists($className, $helpers)) {
require($helpers[$className]['path']); require($helpers[$className]['path']);
return true; return true;
} elseif(isset($helpers['Core']) && array_key_exists($className, $helpers['Core'])) { } elseif (isset($helpers['Core']) && array_key_exists($className, $helpers['Core'])) {
require($helpers['Core'][$className]['path']); require($helpers['Core'][$className]['path']);
return true; return true;
} }
} }
$paths = Configure::getInstance(); $paths = Configure::getInstance();
foreach($paths->helperPaths as $path) { foreach ($paths->helperPaths as $path) {
if (file_exists($path . $name . '.php')) { if (file_exists($path . $name . '.php')) {
Configure::store('Helpers', 'class.paths', array($className => array('path' => $path . $name . '.php'))); Configure::store('Helpers', 'class.paths', array($className => array('path' => $path . $name . '.php')));
require($path . $name . '.php'); require($path . $name . '.php');
@ -538,7 +538,7 @@
return true; return true;
} }
if(strpos($name, '.') !== false){ if (strpos($name, '.') !== false){
list($plugin, $name) = explode('.', $name); list($plugin, $name) = explode('.', $name);
} }
@ -547,18 +547,18 @@
$name = Inflector::underscore($name); $name = Inflector::underscore($name);
$components = Configure::read('Components'); $components = Configure::read('Components');
if(is_array($components)) { if (is_array($components)) {
if(array_key_exists($className, $components)) { if (array_key_exists($className, $components)) {
require($components[$className]['path']); require($components[$className]['path']);
return true; return true;
} elseif(isset($components['Core']) && array_key_exists($className, $components['Core'])) { } elseif (isset($components['Core']) && array_key_exists($className, $components['Core'])) {
require($components['Core'][$className]['path']); require($components['Core'][$className]['path']);
return true; return true;
} }
} }
$paths = Configure::getInstance(); $paths = Configure::getInstance();
foreach($paths->componentPaths as $path) { foreach ($paths->componentPaths as $path) {
if (file_exists($path . $name . '.php')) { if (file_exists($path . $name . '.php')) {
Configure::store('Components', 'class.paths', array($className => array('path' => $path . $name . '.php'))); Configure::store('Components', 'class.paths', array($className => array('path' => $path . $name . '.php')));
require($path . $name . '.php'); require($path . $name . '.php');
@ -609,7 +609,7 @@
if ($name === null) { if ($name === null) {
return true; return true;
} }
if(strpos($name, '.') !== false){ if (strpos($name, '.') !== false){
list($plugin, $name) = explode('.', $name); list($plugin, $name) = explode('.', $name);
} }
@ -618,7 +618,7 @@
if (!class_exists($name . 'Behavior')) { if (!class_exists($name . 'Behavior')) {
$name = Inflector::underscore($name); $name = Inflector::underscore($name);
foreach($paths->behaviorPaths as $path) { foreach ($paths->behaviorPaths as $path) {
if (file_exists($path . $name . '.php')) { if (file_exists($path . $name . '.php')) {
require($path . $name . '.php'); require($path . $name . '.php');
return true; return true;
@ -645,7 +645,7 @@
function listClasses($path) { function listClasses($path) {
$dir = opendir($path); $dir = opendir($path);
$classes=array(); $classes=array();
while(false !== ($file = readdir($dir))) { while (false !== ($file = readdir($dir))) {
if ((substr($file, -3, 3) == 'php') && substr($file, 0, 1) != '.') { if ((substr($file, -3, 3) == 'php') && substr($file, 0, 1) != '.') {
$classes[] = $file; $classes[] = $file;
} }
@ -665,7 +665,7 @@
*/ */
function config() { function config() {
$args = func_get_args(); $args = func_get_args();
foreach($args as $arg) { foreach ($args as $arg) {
if (('database' == $arg) && file_exists(CONFIGS . $arg . '.php')) { if (('database' == $arg) && file_exists(CONFIGS . $arg . '.php')) {
include_once(CONFIGS . $arg . '.php'); include_once(CONFIGS . $arg . '.php');
} elseif (file_exists(CONFIGS . $arg . '.php')) { } elseif (file_exists(CONFIGS . $arg . '.php')) {
@ -712,7 +712,7 @@
for ($i = 0; $i < $c; $i++) { for ($i = 0; $i < $c; $i++) {
$arg = $args[$i]; $arg = $args[$i];
if(strpos($arg, '.') !== false){ if (strpos($arg, '.') !== false){
$file = explode('.', $arg); $file = explode('.', $arg);
$plugin = Inflector::underscore($file[0]); $plugin = Inflector::underscore($file[0]);
unset($file[0]); unset($file[0]);
@ -780,7 +780,7 @@
return null; return null;
} }
foreach($array as $key => $val) { foreach ($array as $key => $val) {
$sa[$key] = $val[$sortby]; $sa[$key] = $val[$sortby];
} }
@ -790,7 +790,7 @@
arsort($sa, $type); arsort($sa, $type);
} }
foreach($sa as $key => $val) { foreach ($sa as $key => $val) {
$out[] = $array[$key]; $out[] = $array[$key];
} }
return $out; return $out;
@ -819,7 +819,7 @@
} }
$output=array(); $output=array();
for($i = 0; $i < $c1; $i++) { for ($i = 0; $i < $c1; $i++) {
$output[$a1[$i]] = $a2[$i]; $output[$a1[$i]] = $a2[$i];
} }
return $output; return $output;
@ -873,7 +873,7 @@
*/ */
function aa() { function aa() {
$args = func_get_args(); $args = func_get_args();
for($l = 0, $c = count($args); $l < $c; $l++) { for ($l = 0, $c = count($args); $l < $c; $l++) {
if ($l + 1 < count($args)) { if ($l + 1 < count($args)) {
$a[$args[$l]] = $args[$l + 1]; $a[$args[$l]] = $args[$l + 1];
} else { } else {
@ -962,7 +962,7 @@
*/ */
function am() { function am() {
$r = array(); $r = array();
foreach(func_get_args()as $a) { foreach (func_get_args()as $a) {
if (!is_array($a)) { if (!is_array($a)) {
$a = array($a); $a = array($a);
} }
@ -979,7 +979,7 @@
function setUri() { function setUri() {
if (env('HTTP_X_REWRITE_URL')) { if (env('HTTP_X_REWRITE_URL')) {
$uri = env('HTTP_X_REWRITE_URL'); $uri = env('HTTP_X_REWRITE_URL');
} elseif(env('REQUEST_URI')) { } elseif (env('REQUEST_URI')) {
$uri = env('REQUEST_URI'); $uri = env('REQUEST_URI');
} else { } else {
if ($uri = env('argv')) { if ($uri = env('argv')) {
@ -1086,7 +1086,7 @@
$res = @fopen($fileName, 'w+b'); $res = @fopen($fileName, 'w+b');
if ($res) { if ($res) {
$write = @fwrite($res, $data); $write = @fwrite($res, $data);
if($write === false) { if ($write === false) {
return false; return false;
} else { } else {
return $write; return $write;
@ -1129,7 +1129,7 @@
$timediff = $expires - $now; $timediff = $expires - $now;
$filetime = false; $filetime = false;
if(file_exists($filename)) { if (file_exists($filename)) {
$filetime = @filemtime($filename); $filetime = @filemtime($filename);
} }
@ -1143,7 +1143,7 @@
$data = file_get_contents($filename); $data = file_get_contents($filename);
} }
} }
} else if(is_writable(dirname($filename))) { } elseif (is_writable(dirname($filename))) {
file_put_contents($filename, $data); file_put_contents($filename, $data);
} }
return $data; return $data;
@ -1167,14 +1167,14 @@
if (is_file($cache . $ext)) { if (is_file($cache . $ext)) {
@unlink($cache . $ext); @unlink($cache . $ext);
return true; return true;
} else if(is_dir($cache)) { } elseif (is_dir($cache)) {
$files = glob("$cache*"); $files = glob("$cache*");
if ($files === false) { if ($files === false) {
return false; return false;
} }
foreach($files as $file) { foreach ($files as $file) {
if (is_file($file)) { if (is_file($file)) {
@unlink($file); @unlink($file);
} }
@ -1187,7 +1187,7 @@
if ($files === false) { if ($files === false) {
return false; return false;
} }
foreach($files as $file) { foreach ($files as $file) {
if (is_file($file)) { if (is_file($file)) {
@unlink($file); @unlink($file);
} }
@ -1195,16 +1195,16 @@
return true; return true;
} }
} elseif (is_array($params)) { } elseif (is_array($params)) {
foreach($params as $key => $file) { foreach ($params as $key => $file) {
$file = preg_replace('/\/\//', '/', $file); $file = preg_replace('/\/\//', '/', $file);
$cache = CACHE . $type . DS . '*' . $file . '*' . $ext; $cache = CACHE . $type . DS . '*' . $file . '*' . $ext;
$files[] = glob($cache); $files[] = glob($cache);
} }
if (!empty($files)) { if (!empty($files)) {
foreach($files as $key => $delete) { foreach ($files as $key => $delete) {
if (is_array($delete)) { if (is_array($delete)) {
foreach($delete as $file) { foreach ($delete as $file) {
if (is_file($file)) { if (is_file($file)) {
@unlink($file); @unlink($file);
} }
@ -1243,13 +1243,13 @@
* @return mixed translated string if $return is false string will be echoed * @return mixed translated string if $return is false string will be echoed
*/ */
function __($singular, $return = false) { function __($singular, $return = false) {
if(!class_exists('I18n')) { if (!class_exists('I18n')) {
uses('i18n'); uses('i18n');
} }
$calledFrom = debug_backtrace(); $calledFrom = debug_backtrace();
$dir = dirname($calledFrom[0]['file']); $dir = dirname($calledFrom[0]['file']);
if($return === false) { if ($return === false) {
echo I18n::translate($singular, null, null, 5, null, $dir); echo I18n::translate($singular, null, null, 5, null, $dir);
} else { } else {
return I18n::translate($singular, null, null, 5, null, $dir); return I18n::translate($singular, null, null, 5, null, $dir);
@ -1267,13 +1267,13 @@
* @return mixed plural form of translated string if $return is false string will be echoed * @return mixed plural form of translated string if $return is false string will be echoed
*/ */
function __n($singular, $plural, $count, $return = false) { function __n($singular, $plural, $count, $return = false) {
if(!class_exists('I18n')) { if (!class_exists('I18n')) {
uses('i18n'); uses('i18n');
} }
$calledFrom = debug_backtrace(); $calledFrom = debug_backtrace();
$dir = dirname($calledFrom[0]['file']); $dir = dirname($calledFrom[0]['file']);
if($return === false) { if ($return === false) {
echo I18n::translate($singular, $plural, null, 5, $count, $dir); echo I18n::translate($singular, $plural, null, 5, $count, $dir);
} else { } else {
return I18n::translate($singular, $plural, null, 5, $count, $dir); return I18n::translate($singular, $plural, null, 5, $count, $dir);
@ -1289,11 +1289,11 @@
* @return translated string if $return is false string will be echoed * @return translated string if $return is false string will be echoed
*/ */
function __d($domain, $msg, $return = false) { function __d($domain, $msg, $return = false) {
if(!class_exists('I18n')) { if (!class_exists('I18n')) {
uses('i18n'); uses('i18n');
} }
if($return === false) { if ($return === false) {
echo I18n::translate($msg, null, $domain); echo I18n::translate($msg, null, $domain);
} else { } else {
return I18n::translate($msg, null, $domain); return I18n::translate($msg, null, $domain);
@ -1313,11 +1313,11 @@
* @return plural form of translated string if $return is false string will be echoed * @return plural form of translated string if $return is false string will be echoed
*/ */
function __dn($domain, $singular, $plural, $count, $return = false) { function __dn($domain, $singular, $plural, $count, $return = false) {
if(!class_exists('I18n')) { if (!class_exists('I18n')) {
uses('i18n'); uses('i18n');
} }
if($return === false) { if ($return === false) {
echo I18n::translate($singular, $plural, $domain, 5, $count); echo I18n::translate($singular, $plural, $domain, 5, $count);
} else { } else {
return I18n::translate($singular, $plural, $domain, 5, $count); return I18n::translate($singular, $plural, $domain, 5, $count);
@ -1347,11 +1347,11 @@
* @return translated string if $return is false string will be echoed * @return translated string if $return is false string will be echoed
*/ */
function __dc($domain, $msg, $category, $return = false) { function __dc($domain, $msg, $category, $return = false) {
if(!class_exists('I18n')) { if (!class_exists('I18n')) {
uses('i18n'); uses('i18n');
} }
if($return === false) { if ($return === false) {
echo I18n::translate($msg, null, $domain, $category); echo I18n::translate($msg, null, $domain, $category);
} else { } else {
return I18n::translate($msg, null, $domain, $category); return I18n::translate($msg, null, $domain, $category);
@ -1385,11 +1385,11 @@
* @return plural form of translated string if $return is false string will be echoed * @return plural form of translated string if $return is false string will be echoed
*/ */
function __dcn($domain, $singular, $plural, $count, $category, $return = false) { function __dcn($domain, $singular, $plural, $count, $category, $return = false) {
if(!class_exists('I18n')) { if (!class_exists('I18n')) {
uses('i18n'); uses('i18n');
} }
if($return === false) { if ($return === false) {
echo I18n::translate($singular, $plural, $domain, $category, $count); echo I18n::translate($singular, $plural, $domain, $category, $count);
} else { } else {
return I18n::translate($singular, $plural, $domain, $category, $count); return I18n::translate($singular, $plural, $domain, $category, $count);
@ -1415,13 +1415,13 @@
* @return translated string if $return is false string will be echoed * @return translated string if $return is false string will be echoed
*/ */
function __c($msg, $category, $return = false) { function __c($msg, $category, $return = false) {
if(!class_exists('I18n')) { if (!class_exists('I18n')) {
uses('i18n'); uses('i18n');
} }
$calledFrom = debug_backtrace(); $calledFrom = debug_backtrace();
$dir = dirname($calledFrom[0]['file']); $dir = dirname($calledFrom[0]['file']);
if($return === false) { if ($return === false) {
echo I18n::translate($msg, null, null, $category, null, $dir); echo I18n::translate($msg, null, null, $category, null, $dir);
} else { } else {
return I18n::translate($msg, null, null, $category, null, $dir); return I18n::translate($msg, null, null, $category, null, $dir);
@ -1470,8 +1470,8 @@
if (!function_exists('array_intersect_key')) { if (!function_exists('array_intersect_key')) {
function array_intersect_key($arr1, $arr2) { function array_intersect_key($arr1, $arr2) {
$res = array(); $res = array();
foreach($arr1 as $key=>$value) { foreach ($arr1 as $key=>$value) {
if(array_key_exists($key, $arr2)) { if (array_key_exists($key, $arr2)) {
$res[$key] = $arr1[$key]; $res[$key] = $arr1[$key];
} }
} }
@ -1499,7 +1499,7 @@
*/ */
function fileExistsInPath($file) { function fileExistsInPath($file) {
$paths = explode(PATH_SEPARATOR, ini_get('include_path')); $paths = explode(PATH_SEPARATOR, ini_get('include_path'));
foreach($paths as $path) { foreach ($paths as $path) {
$fullPath = $path . DIRECTORY_SEPARATOR . $file; $fullPath = $path . DIRECTORY_SEPARATOR . $file;
if (file_exists($fullPath)) { if (file_exists($fullPath)) {
@ -1535,7 +1535,7 @@
} }
$dir = opendir($path); $dir = opendir($path);
while($file = readdir($dir)) { while ($file = readdir($dir)) {
if ($file != '.' && $file != '..') { if ($file != '.' && $file != '..') {
$fullpath = $path . '/' . $file; $fullpath = $path . '/' . $file;

View file

@ -46,14 +46,14 @@ if (!defined('PHP5')) {
require LIBS . 'configure.php'; require LIBS . 'configure.php';
$paths = Configure::getInstance(); $paths = Configure::getInstance();
if(isset($cakeCache)) { if (isset($cakeCache)) {
$cache = 'File'; $cache = 'File';
$settings = array(); $settings = array();
if(isset($cakeCache[0])) { if (isset($cakeCache[0])) {
$cache = $cakeCache[0]; $cache = $cakeCache[0];
} }
if(isset($cakeCache[1])) { if (isset($cakeCache[1])) {
$settings = $cakeCache[1]; $settings = $cakeCache[1];
} }
Cache::engine($cache, $settings); Cache::engine($cache, $settings);
@ -135,7 +135,7 @@ if (!defined('PHP5')) {
$v = null; $v = null;
$view = new View($v); $view = new View($v);
$view->renderCache($filename, $TIME_START); $view->renderCache($filename, $TIME_START);
} elseif(file_exists(CACHE . 'views' . DS . convertSlash($uri) . '_index.php')) { } elseif (file_exists(CACHE . 'views' . DS . convertSlash($uri) . '_index.php')) {
uses('controller' . DS . 'component', DS . 'view' . DS . 'view'); uses('controller' . DS . 'component', DS . 'view' . DS . 'view');
$v = null; $v = null;
$view = new View($v); $view = new View($v);

View file

@ -32,10 +32,10 @@
* directory we will define ROOT there, otherwise we set it * directory we will define ROOT there, otherwise we set it
* here. * here.
*/ */
if(!defined('ROOT')) { if (!defined('ROOT')) {
define ('ROOT', '../'); define ('ROOT', '../');
} }
if(!defined('WEBROOT_DIR')) { if (!defined('WEBROOT_DIR')) {
define ('WEBROOT_DIR', 'webroot'); define ('WEBROOT_DIR', 'webroot');
} }
/** /**

View file

@ -211,7 +211,7 @@ class ShellDispatcher {
CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php', CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php',
); );
if(!file_exists(APP_PATH . 'config' . DS . 'core.php')) { if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
$includes[] = CORE_PATH . 'cake' . DS . 'console' . DS . 'libs' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php'; $includes[] = CORE_PATH . 'cake' . DS . 'console' . DS . 'libs' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
} else { } else {
$includes[] = APP_PATH . 'config' . DS . 'core.php'; $includes[] = APP_PATH . 'config' . DS . 'core.php';
@ -257,7 +257,7 @@ class ShellDispatcher {
$this->help(); $this->help();
} else { } else {
$loaded = false; $loaded = false;
foreach($this->shellPaths as $path) { foreach ($this->shellPaths as $path) {
$this->shellPath = $path . $this->shell . ".php"; $this->shellPath = $path . $this->shell . ".php";
if (file_exists($this->shellPath)) { if (file_exists($this->shellPath)) {
$loaded = true; $loaded = true;
@ -268,18 +268,18 @@ class ShellDispatcher {
if ($loaded) { if ($loaded) {
require CONSOLE_LIBS . 'shell.php'; require CONSOLE_LIBS . 'shell.php';
require $this->shellPath; require $this->shellPath;
if(class_exists($this->shellClass)) { if (class_exists($this->shellClass)) {
$command = null; $command = null;
if(isset($this->args[0])) { if (isset($this->args[0])) {
$command = $this->args[0]; $command = $this->args[0];
} }
$this->shellCommand = Inflector::variable($command); $this->shellCommand = Inflector::variable($command);
$shell = new $this->shellClass($this); $shell = new $this->shellClass($this);
$this->shiftArgs(); $this->shiftArgs();
if($command == 'help') { if ($command == 'help') {
if(method_exists($shell, 'help')) { if (method_exists($shell, 'help')) {
$shell->help(); $shell->help();
exit(); exit();
} else { } else {
@ -290,16 +290,16 @@ class ShellDispatcher {
$shell->initialize(); $shell->initialize();
$shell->loadTasks(); $shell->loadTasks();
foreach($shell->taskNames as $task) { foreach ($shell->taskNames as $task) {
$shell->{$task}->initialize(); $shell->{$task}->initialize();
$shell->{$task}->loadTasks(); $shell->{$task}->loadTasks();
} }
$task = Inflector::camelize($command); $task = Inflector::camelize($command);
if(in_array($task, $shell->taskNames)) { if (in_array($task, $shell->taskNames)) {
$shell->{$task}->startup(); $shell->{$task}->startup();
if(isset($this->args[0]) && $this->args[0] == 'help') { if (isset($this->args[0]) && $this->args[0] == 'help') {
if(method_exists($shell->{$task}, 'help')) { if (method_exists($shell->{$task}, 'help')) {
$shell->{$task}->help(); $shell->{$task}->help();
exit(); exit();
} else { } else {
@ -313,11 +313,11 @@ class ShellDispatcher {
$classMethods = get_class_methods($shell); $classMethods = get_class_methods($shell);
$privateMethod = $missingCommand = false; $privateMethod = $missingCommand = false;
if((in_array($command, $classMethods) || in_array(strtolower($command), $classMethods)) && strpos($command, '_', 0) === 0) { if ((in_array($command, $classMethods) || in_array(strtolower($command), $classMethods)) && strpos($command, '_', 0) === 0) {
$privateMethod = true; $privateMethod = true;
} }
if(!in_array($command, $classMethods) && !in_array(strtolower($command), $classMethods)) { if (!in_array($command, $classMethods) && !in_array(strtolower($command), $classMethods)) {
$missingCommand = true; $missingCommand = true;
} }
@ -331,12 +331,12 @@ class ShellDispatcher {
$missingCommand = true; $missingCommand = true;
} }
if($missingCommand && method_exists($shell, 'main')) { if ($missingCommand && method_exists($shell, 'main')) {
$shell->startup(); $shell->startup();
$shell->main(); $shell->main();
} else if($missingCommand && method_exists($shell, 'help')) { } elseif ($missingCommand && method_exists($shell, 'help')) {
$shell->help(); $shell->help();
} else if(!$privateMethod && method_exists($shell, $command)) { } elseif (!$privateMethod && method_exists($shell, $command)) {
$shell->startup(); $shell->startup();
$shell->{$command}(); $shell->{$command}();
} else { } else {
@ -369,14 +369,14 @@ class ShellDispatcher {
$print_options = '(' . implode('/', $options) . ')'; $print_options = '(' . implode('/', $options) . ')';
} }
if($default == null) { if ($default == null) {
$this->stdout($prompt . " $print_options \n" . '> ', false); $this->stdout($prompt . " $print_options \n" . '> ', false);
} else { } else {
$this->stdout($prompt . " $print_options \n" . "[$default] > ", false); $this->stdout($prompt . " $print_options \n" . "[$default] > ", false);
} }
$result = trim(fgets($this->stdin)); $result = trim(fgets($this->stdin));
if($default != null && empty($result)) { if ($default != null && empty($result)) {
return $default; return $default;
} else { } else {
return $result; return $result;
@ -425,15 +425,15 @@ class ShellDispatcher {
$root = dirname(dirname(dirname(__FILE__))); $root = dirname(dirname(dirname(__FILE__)));
$working = $root; $working = $root;
if(!empty($this->params['working'])) { if (!empty($this->params['working'])) {
$root = dirname($this->params['working']); $root = dirname($this->params['working']);
$app = basename($this->params['working']); $app = basename($this->params['working']);
} else { } else {
$this->params['working'] = $root; $this->params['working'] = $root;
} }
if(!empty($this->params['app'])) { if (!empty($this->params['app'])) {
if($this->params['app']{0} == '/') { if ($this->params['app']{0} == '/') {
$root = dirname($this->params['app']); $root = dirname($this->params['app']);
$app = basename($this->params['app']); $app = basename($this->params['app']);
} else { } else {
@ -443,7 +443,7 @@ class ShellDispatcher {
unset($this->params['app']); unset($this->params['app']);
} }
if(in_array($app, array('cake', 'console')) || realpath($root.DS.$app) === dirname(dirname(dirname(__FILE__)))) { if (in_array($app, array('cake', 'console')) || realpath($root.DS.$app) === dirname(dirname(dirname(__FILE__)))) {
$root = dirname(dirname(dirname(__FILE__))); $root = dirname(dirname(dirname(__FILE__)));
$app = 'app'; $app = 'app';
} }
@ -484,12 +484,12 @@ class ShellDispatcher {
$this->stdout("Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp"); $this->stdout("Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp");
$this->stdout("\nAvailable Shells:"); $this->stdout("\nAvailable Shells:");
foreach($this->shellPaths as $path) { foreach ($this->shellPaths as $path) {
if(is_dir($path)) { if (is_dir($path)) {
$shells = listClasses($path); $shells = listClasses($path);
$path = r(CORE_PATH, '', $path); $path = r(CORE_PATH, '', $path);
$this->stdout("\n " . $path . ":"); $this->stdout("\n " . $path . ":");
if(empty($shells)) { if (empty($shells)) {
$this->stdout("\t - none"); $this->stdout("\t - none");
} else { } else {
foreach ($shells as $shell) { foreach ($shells as $shell) {

View file

@ -88,15 +88,15 @@ class AclShell extends Shell {
exit(); exit();
} }
if($this->command && !in_array($this->command, array('help'))) { if ($this->command && !in_array($this->command, array('help'))) {
if(!config('database')) { if (!config('database')) {
$this->out(__("Your database configuration was not found. Take a moment to create one.", true), true); $this->out(__("Your database configuration was not found. Take a moment to create one.", true), true);
$this->args = null; $this->args = null;
return $this->DbConfig->execute(); return $this->DbConfig->execute();
} }
require_once (CONFIGS.'database.php'); require_once (CONFIGS.'database.php');
if(!in_array($this->command, array('initdb'))) { if (!in_array($this->command, array('initdb'))) {
$this->Acl = new AclComponent(); $this->Acl = new AclComponent();
$this->db =& ConnectionManager::getDataSource($this->dataSource); $this->db =& ConnectionManager::getDataSource($this->dataSource);
} }
@ -169,7 +169,7 @@ class AclShell extends Shell {
$data['parent_id'] = $parent; $data['parent_id'] = $parent;
$object->create(); $object->create();
if($object->save($data)) { if ($object->save($data)) {
$this->out(sprintf(__("New %s '%s' created.\n", true), $class, $this->args[2]), true); $this->out(sprintf(__("New %s '%s' created.\n", true), $class, $this->args[2]), true);
} else { } else {
$this->err(sprintf(__("There was a problem creating a new %s '%s'.", true), $class, $this->args[2])); $this->err(sprintf(__("There was a problem creating a new %s '%s'.", true), $class, $this->args[2]));
@ -184,7 +184,7 @@ class AclShell extends Shell {
$this->_checkArgs(2, 'delete'); $this->_checkArgs(2, 'delete');
$this->checkNodeType(); $this->checkNodeType();
extract($this->__dataVars()); extract($this->__dataVars());
if(!$this->Acl->{$class}->delete($this->args[1])) { if (!$this->Acl->{$class}->delete($this->args[1])) {
$this->error(__("Node Not Deleted", true), sprintf(__("There was an error deleting the %s. Check that the node exists", true), $class) . ".\n"); $this->error(__("Node Not Deleted", true), sprintf(__("There was an error deleting the %s. Check that the node exists", true), $class) . ".\n");
} }
$this->out(sprintf(__("%s deleted", true), $class) . ".\n", true); $this->out(sprintf(__("%s deleted", true), $class) . ".\n", true);
@ -233,7 +233,7 @@ class AclShell extends Shell {
//add existence checks for nodes involved //add existence checks for nodes involved
$aro = (is_numeric($this->args[0])) ? intval($this->args[0]) : $this->args[0]; $aro = (is_numeric($this->args[0])) ? intval($this->args[0]) : $this->args[0];
$aco = (is_numeric($this->args[1])) ? intval($this->args[1]) : $this->args[1]; $aco = (is_numeric($this->args[1])) ? intval($this->args[1]) : $this->args[1];
if($this->Acl->allow($aro, $aco, $this->args[2])) { if ($this->Acl->allow($aro, $aco, $this->args[2])) {
$this->out(__("Permission granted.", true), true); $this->out(__("Permission granted.", true), true);
} }
} }
@ -284,15 +284,15 @@ class AclShell extends Shell {
$this->hr(); $this->hr();
$nodeCount = count($nodes); $nodeCount = count($nodes);
$right = $left = array(); $right = $left = array();
for($i = 0; $i < $nodeCount; $i++) { for ($i = 0; $i < $nodeCount; $i++) {
$count = 0; $count = 0;
$right[$i] = $nodes[$i][$class]['rght']; $right[$i] = $nodes[$i][$class]['rght'];
$left[$i] = $nodes[$i][$class]['lft']; $left[$i] = $nodes[$i][$class]['lft'];
if(isset($left[$i]) && isset($left[$i-1]) && $left[$i] > $left[$i-1]) { if (isset($left[$i]) && isset($left[$i-1]) && $left[$i] > $left[$i-1]) {
array_pop($left); array_pop($left);
$count = count($left); $count = count($left);
} }
if(isset($right[$i]) && isset($right[$i-1]) && $right[$i] < $right[$i-1]) { if (isset($right[$i]) && isset($right[$i-1]) && $right[$i] < $right[$i-1]) {
array_pop($right); array_pop($right);
$count = count($right); $count = count($right);
} }
@ -431,7 +431,7 @@ class AclShell extends Shell {
* @access public * @access public
*/ */
function checkNodeType() { function checkNodeType() {
if(!isset($this->args[0])) { if (!isset($this->args[0])) {
return false; return false;
} }
if ($this->args[0] != 'aco' && $this->args[0] != 'aro') { if ($this->args[0] != 'aco' && $this->args[0] != 'aro') {

View file

@ -79,7 +79,7 @@ class ApiShell extends Shell {
if (!preg_match('/' . Inflector::camelize($path) . '$/', $class)) { if (!preg_match('/' . Inflector::camelize($path) . '$/', $class)) {
$class .= Inflector::camelize($path); $class .= Inflector::camelize($path);
} }
} else if(low($path) === low($class)){ } elseif (low($path) === low($class)){
$class = Inflector::camelize($path); $class = Inflector::camelize($path);
} }
@ -103,7 +103,7 @@ class ApiShell extends Shell {
substr(Inflector::underscore($class), 0, strpos(Inflector::underscore($class), '_')) substr(Inflector::underscore($class), 0, strpos(Inflector::underscore($class), '_'))
); );
foreach($candidates as $candidate) { foreach ($candidates as $candidate) {
$File =& new File($path . $candidate . '.php'); $File =& new File($path . $candidate . '.php');
if ($File->exists()) { if ($File->exists()) {
@ -129,7 +129,7 @@ class ApiShell extends Shell {
$this->out(ucwords($class)); $this->out(ucwords($class));
$this->hr(); $this->hr();
foreach($parsed as $method) { foreach ($parsed as $method) {
$this->out("\t" . $method['method'] . "(" . $method['parameters'] . ")", true); $this->out("\t" . $method['method'] . "(" . $method['parameters'] . ")", true);
} }
} }
@ -188,7 +188,7 @@ class ApiShell extends Shell {
$contents = $File->read(); $contents = $File->read();
foreach($methods as $method) { foreach ($methods as $method) {
if (strpos($method, '__') !== 0 && strpos($method, '_') !== 0) { if (strpos($method, '__') !== 0 && strpos($method, '_') !== 0) {
$regex = '/\s+function\s+(' . preg_quote($method, '/') . ')\s*\(([^{]*)\)\s*{/is'; $regex = '/\s+function\s+(' . preg_quote($method, '/') . ')\s*\(([^{]*)\)\s*{/is';

View file

@ -34,7 +34,7 @@
* @package cake * @package cake
* @subpackage cake.cake.console.libs * @subpackage cake.cake.console.libs
*/ */
if(!defined('CAKE_ADMIN')) { if (!defined('CAKE_ADMIN')) {
define('CAKE_ADMIN', null); define('CAKE_ADMIN', null);
} }
class BakeShell extends Shell { class BakeShell extends Shell {
@ -43,11 +43,11 @@ class BakeShell extends Shell {
function main() { function main() {
if(!is_dir(CONFIGS)) { if (!is_dir(CONFIGS)) {
$this->Project->execute(); $this->Project->execute();
} }
if(!config('database')) { if (!config('database')) {
$this->out("Your database configuration was not found. Take a moment to create one.\n"); $this->out("Your database configuration was not found. Take a moment to create one.\n");
$this->args = null; $this->args = null;
return $this->DbConfig->execute(); return $this->DbConfig->execute();

View file

@ -155,7 +155,7 @@ class ConsoleShell extends Shell {
foreach ($result as $field => $value) { foreach ($result as $field => $value) {
if (is_array($value)) { if (is_array($value)) {
foreach($value as $field2 => $value2) { foreach ($value as $field2 => $value2) {
$this->out("\t$field2: $value2"); $this->out("\t$field2: $value2");
} }
@ -168,7 +168,7 @@ class ConsoleShell extends Shell {
} else { // find() output } else { // find() output
$this->out($idx); $this->out($idx);
foreach($results as $field => $value) { foreach ($results as $field => $value) {
if (is_array($value)) { if (is_array($value)) {
foreach ($value as $field2 => $value2) { foreach ($value as $field2 => $value2) {
$this->out("\t$field2: $value2"); $this->out("\t$field2: $value2");

View file

@ -69,28 +69,28 @@ class ExtractShell extends Shell{
var $__output = null; var $__output = null;
function initialize() { function initialize() {
if(isset($this->params['files']) && !is_array($this->params['files'])){ if (isset($this->params['files']) && !is_array($this->params['files'])){
$this->files = explode(',', $this->params['files']); $this->files = explode(',', $this->params['files']);
} }
if(isset($this->params['path'])) { if (isset($this->params['path'])) {
$this->path = $this->params['path']; $this->path = $this->params['path'];
} else { } else {
$this->path = ROOT . DS . APP_DIR; $this->path = ROOT . DS . APP_DIR;
} }
if(isset($this->params['debug'])) { if (isset($this->params['debug'])) {
$this->path = ROOT; $this->path = ROOT;
$this->files = array(__FILE__); $this->files = array(__FILE__);
} }
if(isset($this->params['output'])) { if (isset($this->params['output'])) {
$this->__output = $this->params['output']; $this->__output = $this->params['output'];
} else { } else {
$this->__output = APP . 'locale' . DS; $this->__output = APP . 'locale' . DS;
} }
if(empty($this->files)){ if (empty($this->files)){
$this->files = $this->__searchDirectory(); $this->files = $this->__searchDirectory();
} }
} }
@ -105,12 +105,12 @@ class ExtractShell extends Shell{
$response = ''; $response = '';
$filename = ''; $filename = '';
while($response == '') { while ($response == '') {
$response = $this->in('Would you like to merge all translations into one file?', array('y','n'), 'y'); $response = $this->in('Would you like to merge all translations into one file?', array('y','n'), 'y');
if(strtolower($response) == 'n') { if (strtolower($response) == 'n') {
$this->__oneFile = false; $this->__oneFile = false;
} else { } else {
while($filename == '') { while ($filename == '') {
$filename = $this->in('What should we name this file?', null, $this->__filename); $filename = $this->in('What should we name this file?', null, $this->__filename);
if ($filename == '') { if ($filename == '') {
$this->out('The filesname you supplied was empty. Please try again.'); $this->out('The filesname you supplied was empty. Please try again.');
@ -154,15 +154,15 @@ class ExtractShell extends Shell{
$this->__tokens = array(); $this->__tokens = array();
$lineNumber = 1; $lineNumber = 1;
foreach($allTokens as $token) { foreach ($allTokens as $token) {
if((!is_array($token)) || (($token[0] != T_WHITESPACE) && ($token[0] != T_INLINE_HTML))) { if ((!is_array($token)) || (($token[0] != T_WHITESPACE) && ($token[0] != T_INLINE_HTML))) {
if(is_array($token)) { if (is_array($token)) {
$token[] = $lineNumber; $token[] = $lineNumber;
} }
$this->__tokens[] = $token; $this->__tokens[] = $token;
} }
if(is_array($token)) { if (is_array($token)) {
$lineNumber += count(split("\n", $token[1])) - 1; $lineNumber += count(split("\n", $token[1])) - 1;
} else { } else {
$lineNumber += count(split("\n", $token)) - 1; $lineNumber += count(split("\n", $token)) - 1;
@ -190,7 +190,7 @@ class ExtractShell extends Shell{
$count = 0; $count = 0;
$tokenCount = count($this->__tokens); $tokenCount = count($this->__tokens);
while(($tokenCount - $count) > 3) { while (($tokenCount - $count) > 3) {
list($countToken, $parenthesis, $middle, $right) = array($this->__tokens[$count], $this->__tokens[$count + 1], $this->__tokens[$count + 2], $this->__tokens[$count + 3]); list($countToken, $parenthesis, $middle, $right) = array($this->__tokens[$count], $this->__tokens[$count + 1], $this->__tokens[$count + 2], $this->__tokens[$count + 3]);
if (!is_array($countToken)) { if (!is_array($countToken)) {
$count++; $count++;
@ -198,9 +198,9 @@ class ExtractShell extends Shell{
} }
list($type, $string, $line) = $countToken; list($type, $string, $line) = $countToken;
if(($type == T_STRING) && ($string == $functionname) && ($parenthesis == "(")) { if (($type == T_STRING) && ($string == $functionname) && ($parenthesis == "(")) {
if(in_array($right, array(")", ",")) if (in_array($right, array(")", ","))
&& (is_array($middle) && ($middle[0] == T_CONSTANT_ENCAPSED_STRING))) { && (is_array($middle) && ($middle[0] == T_CONSTANT_ENCAPSED_STRING))) {
if ($this->__oneFile === true) { if ($this->__oneFile === true) {
@ -226,9 +226,9 @@ class ExtractShell extends Shell{
$count = 0; $count = 0;
$tokenCount = count($this->__tokens); $tokenCount = count($this->__tokens);
while(($tokenCount - $count) > 7) { while (($tokenCount - $count) > 7) {
list($countToken, $firstParenthesis) = array($this->__tokens[$count], $this->__tokens[$count + 1]); list($countToken, $firstParenthesis) = array($this->__tokens[$count], $this->__tokens[$count + 1]);
if(!is_array($countToken)) { if (!is_array($countToken)) {
$count++; $count++;
continue; continue;
} }
@ -238,23 +238,23 @@ class ExtractShell extends Shell{
$position = $count; $position = $count;
$depth = 0; $depth = 0;
while($depth == 0) { while ($depth == 0) {
if ($this->__tokens[$position] == "(") { if ($this->__tokens[$position] == "(") {
$depth++; $depth++;
} elseif($this->__tokens[$position] == ")") { } elseif ($this->__tokens[$position] == ")") {
$depth--; $depth--;
} }
$position++; $position++;
} }
if($plural) { if ($plural) {
$end = $position + $shift + 7; $end = $position + $shift + 7;
if($this->__tokens[$position + $shift + 5] === ')') { if ($this->__tokens[$position + $shift + 5] === ')') {
$end = $position + $shift + 5; $end = $position + $shift + 5;
} }
if(empty($shift)) { if (empty($shift)) {
list($singular, $firstComma, $plural, $seoncdComma, $endParenthesis) = array($this->__tokens[$position], $this->__tokens[$position + 1], $this->__tokens[$position + 2], $this->__tokens[$position + 3], $this->__tokens[$end]); list($singular, $firstComma, $plural, $seoncdComma, $endParenthesis) = array($this->__tokens[$position], $this->__tokens[$position + 1], $this->__tokens[$position + 2], $this->__tokens[$position + 3], $this->__tokens[$end]);
$condition = ($seoncdComma == ","); $condition = ($seoncdComma == ",");
} else { } else {
@ -265,7 +265,7 @@ class ExtractShell extends Shell{
(is_array($singular) && ($singular[0] == T_CONSTANT_ENCAPSED_STRING)) && (is_array($singular) && ($singular[0] == T_CONSTANT_ENCAPSED_STRING)) &&
(is_array($plural) && ($plural[0] == T_CONSTANT_ENCAPSED_STRING)); (is_array($plural) && ($plural[0] == T_CONSTANT_ENCAPSED_STRING));
} else { } else {
if($this->__tokens[$position + $shift + 5] === ')') { if ($this->__tokens[$position + $shift + 5] === ')') {
$comma = $this->__tokens[$position + $shift + 3]; $comma = $this->__tokens[$position + $shift + 3];
$end = $position + $shift + 5; $end = $position + $shift + 5;
} else { } else {
@ -279,15 +279,15 @@ class ExtractShell extends Shell{
(is_array($text) && ($text[0] == T_CONSTANT_ENCAPSED_STRING)); (is_array($text) && ($text[0] == T_CONSTANT_ENCAPSED_STRING));
} }
if(($endParenthesis == ")") && $condition) { if (($endParenthesis == ")") && $condition) {
if($this->__oneFile === true) { if ($this->__oneFile === true) {
if($plural) { if ($plural) {
$this->__strings[$this->__formatString($singular[1]) . "\0" . $this->__formatString($plural[1])][$this->__file][] = $line; $this->__strings[$this->__formatString($singular[1]) . "\0" . $this->__formatString($plural[1])][$this->__file][] = $line;
} else { } else {
$this->__strings[$this->__formatString($text[1])][$this->__file][] = $line; $this->__strings[$this->__formatString($text[1])][$this->__file][] = $line;
} }
} else { } else {
if($plural) { if ($plural) {
$this->__strings[$this->__file][$this->__formatString($singular[1]) . "\0" . $this->__formatString($plural[1])][] = $line; $this->__strings[$this->__file][$this->__formatString($singular[1]) . "\0" . $this->__formatString($plural[1])][] = $line;
} else { } else {
$this->__strings[$this->__file][$this->__formatString($text[1])][] = $line; $this->__strings[$this->__file][$this->__formatString($text[1])][] = $line;
@ -302,14 +302,14 @@ class ExtractShell extends Shell{
} }
function __buildFiles() { function __buildFiles() {
$output = ''; $output = '';
foreach($this->__strings as $str => $fileInfo) { foreach ($this->__strings as $str => $fileInfo) {
$occured = $fileList = array(); $occured = $fileList = array();
if($this->__oneFile === true) { if ($this->__oneFile === true) {
foreach($fileInfo as $file => $lines) { foreach ($fileInfo as $file => $lines) {
$occured[] = "$file:" . join(";", $lines); $occured[] = "$file:" . join(";", $lines);
if(isset($this->__fileVersions[$file])) { if (isset($this->__fileVersions[$file])) {
$fileList[] = $this->__fileVersions[$file]; $fileList[] = $this->__fileVersions[$file];
} }
} }
@ -318,7 +318,7 @@ class ExtractShell extends Shell{
$output = "#: $occurances\n"; $output = "#: $occurances\n";
$filename = $this->__filename; $filename = $this->__filename;
if(strpos($str, "\0") === false) { if (strpos($str, "\0") === false) {
$output .= "msgid \"$str\"\n"; $output .= "msgid \"$str\"\n";
$output .= "msgstr \"\"\n"; $output .= "msgstr \"\"\n";
} else { } else {
@ -330,18 +330,18 @@ class ExtractShell extends Shell{
} }
$output .= "\n"; $output .= "\n";
} else { } else {
foreach($fileInfo as $file => $lines) { foreach ($fileInfo as $file => $lines) {
$filename = $str; $filename = $str;
$occured = array("$str:" . join(";", $lines)); $occured = array("$str:" . join(";", $lines));
if(isset($this->__fileVersions[$str])) { if (isset($this->__fileVersions[$str])) {
$fileList[] = $this->__fileVersions[$str]; $fileList[] = $this->__fileVersions[$str];
} }
$occurances = join("\n#: ", $occured); $occurances = join("\n#: ", $occured);
$occurances = str_replace($this->path, '', $occurances); $occurances = str_replace($this->path, '', $occurances);
$output .= "#: $occurances\n"; $output .= "#: $occurances\n";
if(strpos($file, "\0") === false) { if (strpos($file, "\0") === false) {
$output .= "msgid \"$file\"\n"; $output .= "msgid \"$file\"\n";
$output .= "msgstr \"\"\n"; $output .= "msgstr \"\"\n";
} else { } else {
@ -360,8 +360,8 @@ class ExtractShell extends Shell{
function __store($file = 0, $input = 0, $fileList = array(), $get = 0) { function __store($file = 0, $input = 0, $fileList = array(), $get = 0) {
static $storage = array(); static $storage = array();
if(!$get) { if (!$get) {
if(isset($storage[$file])) { if (isset($storage[$file])) {
$storage[$file][1] = array_unique(array_merge($storage[$file][1], $fileList)); $storage[$file][1] = array_unique(array_merge($storage[$file][1], $fileList));
$storage[$file][] = $input; $storage[$file][] = $input;
} else { } else {
@ -378,7 +378,7 @@ class ExtractShell extends Shell{
$output = $this->__store(0, 0, array(), 1); $output = $this->__store(0, 0, array(), 1);
$output = $this->__mergeFiles($output); $output = $this->__mergeFiles($output);
foreach($output as $file => $content) { foreach ($output as $file => $content) {
$tmp = str_replace(array($this->path, '.php','.ctp','.thtml', '.inc','.tpl' ), '', $file); $tmp = str_replace(array($this->path, '.php','.ctp','.thtml', '.inc','.tpl' ), '', $file);
$tmp = str_replace(DS, '.', $tmp); $tmp = str_replace(DS, '.', $tmp);
$file = str_replace('.', '-', $tmp) .'.pot'; $file = str_replace('.', '-', $tmp) .'.pot';
@ -388,9 +388,9 @@ class ExtractShell extends Shell{
$fileList = str_replace(array($this->path), '', $fileList); $fileList = str_replace(array($this->path), '', $fileList);
if(count($fileList) > 1) { if (count($fileList) > 1) {
$fileList = "Generated from files:\n# " . join("\n# ", $fileList); $fileList = "Generated from files:\n# " . join("\n# ", $fileList);
} elseif(count($fileList) == 1) { } elseif (count($fileList) == 1) {
$fileList = "Generated from file: " . join("", $fileList); $fileList = "Generated from file: " . join("", $fileList);
} else { } else {
$fileList = "No version information was available in the source files."; $fileList = "No version information was available in the source files.";
@ -401,17 +401,17 @@ class ExtractShell extends Shell{
} }
} }
function __mergeFiles($output){ function __mergeFiles($output){
foreach($output as $file => $content) { foreach ($output as $file => $content) {
if(count($content) <= 1 && $file != $this->__filename) { if (count($content) <= 1 && $file != $this->__filename) {
@$output[$this->__filename][1] = array_unique(array_merge($output[$this->__filename][1], $content[1])); @$output[$this->__filename][1] = array_unique(array_merge($output[$this->__filename][1], $content[1]));
if(!isset($output[$this->__filename][0])) { if (!isset($output[$this->__filename][0])) {
$output[$this->__filename][0] = $content[0]; $output[$this->__filename][0] = $content[0];
} }
unset($content[0]); unset($content[0]);
unset($content[1]); unset($content[1]);
foreach($content as $msgid) { foreach ($content as $msgid) {
$output[$this->__filename][] = $msgid; $output[$this->__filename][] = $msgid;
} }
unset($output[$file]); unset($output[$file]);
@ -448,7 +448,7 @@ class ExtractShell extends Shell{
function __formatString($string) { function __formatString($string) {
$quote = substr($string, 0, 1); $quote = substr($string, 0, 1);
$string = substr($string, 1, -1); $string = substr($string, 1, -1);
if($quote == '"') { if ($quote == '"') {
$string = stripcslashes($string); $string = stripcslashes($string);
} else { } else {
$string = strtr($string, array("\\'" => "'", "\\\\" => "\\")); $string = strtr($string, array("\\'" => "'", "\\\\" => "\\"));
@ -461,16 +461,16 @@ class ExtractShell extends Shell{
$tokenCount = count($this->__tokens); $tokenCount = count($this->__tokens);
$parenthesis = 1; $parenthesis = 1;
while((($tokenCount - $count) > 0) && $parenthesis) { while ((($tokenCount - $count) > 0) && $parenthesis) {
if(is_array($this->__tokens[$count])) { if (is_array($this->__tokens[$count])) {
$this->out($this->__tokens[$count][1], false); $this->out($this->__tokens[$count][1], false);
} else { } else {
$this->out($this->__tokens[$count], false); $this->out($this->__tokens[$count], false);
if($this->__tokens[$count] == "(") { if ($this->__tokens[$count] == "(") {
$parenthesis++; $parenthesis++;
} }
if($this->__tokens[$count] == ")") { if ($this->__tokens[$count] == ")") {
$parenthesis--; $parenthesis--;
} }
} }
@ -479,16 +479,16 @@ class ExtractShell extends Shell{
$this->out("\n", true); $this->out("\n", true);
} }
function __searchDirectory($path = null) { function __searchDirectory($path = null) {
if($path === null){ if ($path === null){
$path = $this->path .DS; $path = $this->path .DS;
} }
$files = glob("$path*.{php,ctp,thtml,inc,tpl}", GLOB_BRACE); $files = glob("$path*.{php,ctp,thtml,inc,tpl}", GLOB_BRACE);
$dirs = glob("$path*", GLOB_ONLYDIR); $dirs = glob("$path*", GLOB_ONLYDIR);
foreach($dirs as $dir) { foreach ($dirs as $dir) {
if(!preg_match("!(^|.+/)(CVS|.svn)$!", $dir)) { if (!preg_match("!(^|.+/)(CVS|.svn)$!", $dir)) {
$files = array_merge($files, $this->__searchDirectory("$dir" . DS)); $files = array_merge($files, $this->__searchDirectory("$dir" . DS));
if(($id = array_search($dir . DS . 'extract.php', $files)) !== FALSE) { if (($id = array_search($dir . DS . 'extract.php', $files)) !== FALSE) {
unset($files[$id]); unset($files[$id]);
} }
} }

View file

@ -114,8 +114,8 @@ class Shell extends Object {
*/ */
function __construct(&$dispatch) { function __construct(&$dispatch) {
$vars = array('params', 'args', 'shell', 'shellName'=> 'name', 'shellClass'=> 'className', 'shellCommand'=> 'command'); $vars = array('params', 'args', 'shell', 'shellName'=> 'name', 'shellClass'=> 'className', 'shellCommand'=> 'command');
foreach($vars as $key => $var) { foreach ($vars as $key => $var) {
if(is_string($key)){ if (is_string($key)){
$this->{$var} =& $dispatch->{$key}; $this->{$var} =& $dispatch->{$key};
} else { } else {
$this->{$var} =& $dispatch->{$var}; $this->{$var} =& $dispatch->{$var};
@ -125,10 +125,10 @@ class Shell extends Object {
$shellKey = Inflector::underscore($this->name); $shellKey = Inflector::underscore($this->name);
ClassRegistry::addObject($shellKey, $this); ClassRegistry::addObject($shellKey, $this);
ClassRegistry::map($shellKey, $shellKey); ClassRegistry::map($shellKey, $shellKey);
if(!PHP5 && isset($this->args[0]) && strpos(low(get_class($this)), low(Inflector::camelize($this->args[0]))) !== false) { if (!PHP5 && isset($this->args[0]) && strpos(low(get_class($this)), low(Inflector::camelize($this->args[0]))) !== false) {
$dispatch->shiftArgs(); $dispatch->shiftArgs();
} }
if(!PHP5 && isset($this->args[0]) && low($this->command) == low(Inflector::variable($this->args[0])) && method_exists($this, $this->command)) { if (!PHP5 && isset($this->args[0]) && low($this->command) == low(Inflector::variable($this->args[0])) && method_exists($this, $this->command)) {
$dispatch->shiftArgs(); $dispatch->shiftArgs();
} }
$this->Dispatch =& $dispatch; $this->Dispatch =& $dispatch;
@ -170,7 +170,7 @@ class Shell extends Object {
* @return bool * @return bool
*/ */
function _loadDbConfig() { function _loadDbConfig() {
if(config('database')) { if (config('database')) {
if (class_exists('DATABASE_CONFIG')) { if (class_exists('DATABASE_CONFIG')) {
$this->dbConfig = new DATABASE_CONFIG(); $this->dbConfig = new DATABASE_CONFIG();
return true; return true;
@ -190,7 +190,7 @@ class Shell extends Object {
*/ */
function _loadModels() { function _loadModels() {
if($this->uses === null || $this->uses === false) { if ($this->uses === null || $this->uses === false) {
return; return;
} }
@ -198,7 +198,7 @@ class Shell extends Object {
'model'.DS.'datasources'.DS.'dbo_source', 'model'.DS.'model' 'model'.DS.'datasources'.DS.'dbo_source', 'model'.DS.'model'
); );
if($this->uses === true && loadModel()) { if ($this->uses === true && loadModel()) {
$this->AppModel = & new AppModel(false, false, false); $this->AppModel = & new AppModel(false, false, false);
return true; return true;
} }
@ -207,13 +207,13 @@ class Shell extends Object {
$uses = is_array($this->uses) ? $this->uses : array($this->uses); $uses = is_array($this->uses) ? $this->uses : array($this->uses);
$this->modelClass = $uses[0]; $this->modelClass = $uses[0];
foreach($uses as $modelClass) { foreach ($uses as $modelClass) {
$modelKey = Inflector::underscore($modelClass); $modelKey = Inflector::underscore($modelClass);
if(!class_exists($modelClass)){ if (!class_exists($modelClass)){
loadModel($modelClass); loadModel($modelClass);
} }
if(class_exists($modelClass)) { if (class_exists($modelClass)) {
$model =& new $modelClass(); $model =& new $modelClass();
$this->modelNames[] = $modelClass; $this->modelNames[] = $modelClass;
$this->{$modelClass} =& $model; $this->{$modelClass} =& $model;
@ -232,20 +232,20 @@ class Shell extends Object {
* @return bool * @return bool
*/ */
function loadTasks() { function loadTasks() {
if($this->tasks === null || $this->tasks === false) { if ($this->tasks === null || $this->tasks === false) {
return; return;
} }
if ($this->tasks !== true && !empty($this->tasks)) { if ($this->tasks !== true && !empty($this->tasks)) {
$tasks = $this->tasks; $tasks = $this->tasks;
if(!is_array($tasks)) { if (!is_array($tasks)) {
$tasks = array($tasks); $tasks = array($tasks);
} }
foreach($tasks as $taskName) { foreach ($tasks as $taskName) {
$loaded = false; $loaded = false;
foreach($this->Dispatch->shellPaths as $path) { foreach ($this->Dispatch->shellPaths as $path) {
$taskPath = $path . 'tasks' . DS . Inflector::underscore($taskName).'.php'; $taskPath = $path . 'tasks' . DS . Inflector::underscore($taskName).'.php';
if (file_exists($taskPath)) { if (file_exists($taskPath)) {
$loaded = true; $loaded = true;
@ -256,7 +256,7 @@ class Shell extends Object {
if ($loaded) { if ($loaded) {
$taskKey = Inflector::underscore($taskName); $taskKey = Inflector::underscore($taskName);
$taskClass = Inflector::camelize($taskName.'Task'); $taskClass = Inflector::camelize($taskName.'Task');
if(!class_exists($taskClass)) { if (!class_exists($taskClass)) {
require_once $taskPath; require_once $taskPath;
} }
if (ClassRegistry::isKeySet($taskKey)) { if (ClassRegistry::isKeySet($taskKey)) {
@ -277,7 +277,7 @@ class Shell extends Object {
} }
} }
if(!isset($this->{$taskName})) { if (!isset($this->{$taskName})) {
$this->err("Task '".$taskName."' could not be loaded"); $this->err("Task '".$taskName."' could not be loaded");
exit(); exit();
} }
@ -300,21 +300,21 @@ class Shell extends Object {
*/ */
function in($prompt, $options = null, $default = null) { function in($prompt, $options = null, $default = null) {
$in = $this->Dispatch->getInput($prompt, $options, $default); $in = $this->Dispatch->getInput($prompt, $options, $default);
if($options && is_string($options)) { if ($options && is_string($options)) {
if(strpos($options, ',')) { if (strpos($options, ',')) {
$options = explode(',', $options); $options = explode(',', $options);
} else if(strpos($options, '/')) { } elseif (strpos($options, '/')) {
$options = explode('/', $options); $options = explode('/', $options);
} else { } else {
$options = array($options); $options = array($options);
} }
} }
if(is_array($options)) { if (is_array($options)) {
while($in == '' || ($in && (!in_array(low($in), $options) && !in_array(up($in), $options)) && !in_array($in, $options))) { while ($in == '' || ($in && (!in_array(low($in), $options) && !in_array(up($in), $options)) && !in_array($in, $options))) {
$in = $this->Dispatch->getInput($prompt, $options, $default); $in = $this->Dispatch->getInput($prompt, $options, $default);
} }
} }
if($in) { if ($in) {
return $in; return $in;
} }
} }
@ -368,7 +368,7 @@ class Shell extends Object {
* @param unknown_type $command * @param unknown_type $command
*/ */
function _checkArgs($expectedNum, $command = null) { function _checkArgs($expectedNum, $command = null) {
if(!$command) { if (!$command) {
$command = $this->command; $command = $this->command;
} }
if (count($this->args) < $expectedNum) { if (count($this->args) < $expectedNum) {
@ -390,14 +390,14 @@ class Shell extends Object {
if (low($key) == 'q') { if (low($key) == 'q') {
$this->out(__("Quitting.", true) ."\n"); $this->out(__("Quitting.", true) ."\n");
exit; exit;
} else if (low($key) == 'a') { } elseif (low($key) == 'a') {
$this->dont_ask = true; $this->dont_ask = true;
} else if (low($key) != 'y') { } elseif (low($key) != 'y') {
$this->out(__("Skip", true) ." {$path}\n"); $this->out(__("Skip", true) ." {$path}\n");
return false; return false;
} }
} }
if(!class_exists('File')) { if (!class_exists('File')) {
uses('file'); uses('file');
} }
if ($File = new File($path, true)) { if ($File = new File($path, true)) {
@ -414,7 +414,7 @@ class Shell extends Object {
* *
*/ */
function help() { function help() {
if($this->command != null) { if ($this->command != null) {
$this->err("Unknown {$this->name} command '$this->command'.\nFor usage, try 'cake {$this->shell} help'.\n\n"); $this->err("Unknown {$this->name} command '$this->command'.\nFor usage, try 'cake {$this->shell} help'.\n\n");
} else{ } else{
$this->Dispatch->help(); $this->Dispatch->help();

View file

@ -51,21 +51,21 @@ class ControllerTask extends Shell {
* @return void * @return void
*/ */
function execute() { function execute() {
if(empty($this->args)) { if (empty($this->args)) {
$this->__interactive(); $this->__interactive();
} }
if(isset($this->args[0])) { if (isset($this->args[0])) {
$controller = Inflector::camelize($this->args[0]); $controller = Inflector::camelize($this->args[0]);
$actions = null; $actions = null;
if(isset($this->args[1]) && $this->args[1] == 'scaffold') { if (isset($this->args[1]) && $this->args[1] == 'scaffold') {
$this->out('Baking scaffold for ' . $controller); $this->out('Baking scaffold for ' . $controller);
$actions = $this->__bakeActions($controller); $actions = $this->__bakeActions($controller);
} else { } else {
$actions = 'scaffold'; $actions = 'scaffold';
} }
if(isset($this->args[2]) && $this->args[2] == 'admin') { if (isset($this->args[2]) && $this->args[2] == 'admin') {
if($admin = $this->getAdmin()) { if ($admin = $this->getAdmin()) {
$this->out('Adding ' . CAKE_ADMIN .' methods'); $this->out('Adding ' . CAKE_ADMIN .' methods');
if ($actions == 'scaffold') { if ($actions == 'scaffold') {
$actions = $this->__bakeActions($controller, $admin); $actions = $this->__bakeActions($controller, $admin);
@ -155,12 +155,12 @@ class ControllerTask extends Shell {
if (low($wannaDoScaffolding) == 'y' || low($wannaDoScaffolding) == 'yes') { if (low($wannaDoScaffolding) == 'y' || low($wannaDoScaffolding) == 'yes') {
$actions = $this->__bakeActions($controllerName, null, $wannaUseSession); $actions = $this->__bakeActions($controllerName, null, $wannaUseSession);
if($admin) { if ($admin) {
$actions .= $this->__bakeActions($controllerName, $admin, $wannaUseSession); $actions .= $this->__bakeActions($controllerName, $admin, $wannaUseSession);
} }
} }
if($this->interactive === true) { if ($this->interactive === true) {
$this->out(''); $this->out('');
$this->hr(); $this->hr();
$this->out('The following controller will be created:'); $this->out('The following controller will be created:');
@ -171,10 +171,10 @@ class ControllerTask extends Shell {
$this->out(" var \$scaffold;"); $this->out(" var \$scaffold;");
$actions = 'scaffold'; $actions = 'scaffold';
} }
if(count($uses)) { if (count($uses)) {
$this->out("Uses: ", false); $this->out("Uses: ", false);
foreach($uses as $use) { foreach ($uses as $use) {
if ($use != $uses[count($uses) - 1]) { if ($use != $uses[count($uses) - 1]) {
$this->out(ucfirst($use) . ", ", false); $this->out(ucfirst($use) . ", ", false);
} else { } else {
@ -183,10 +183,10 @@ class ControllerTask extends Shell {
} }
} }
if(count($helpers)) { if (count($helpers)) {
$this->out("Helpers: ", false); $this->out("Helpers: ", false);
foreach($helpers as $help) { foreach ($helpers as $help) {
if ($help != $helpers[count($helpers) - 1]) { if ($help != $helpers[count($helpers) - 1]) {
$this->out(ucfirst($help) . ", ", false); $this->out(ucfirst($help) . ", ", false);
} else { } else {
@ -195,10 +195,10 @@ class ControllerTask extends Shell {
} }
} }
if(count($components)) { if (count($components)) {
$this->out("Components: ", false); $this->out("Components: ", false);
foreach($components as $comp) { foreach ($components as $comp) {
if ($comp != $components[count($components) - 1]) { if ($comp != $components[count($components) - 1]) {
$this->out(ucfirst($comp) . ", ", false); $this->out(ucfirst($comp) . ", ", false);
} else { } else {
@ -228,7 +228,7 @@ class ControllerTask extends Shell {
function __bakeActions($controllerName, $admin = null, $wannaUseSession = 'y') { function __bakeActions($controllerName, $admin = null, $wannaUseSession = 'y') {
$currentModelName = $this->_modelName($controllerName); $currentModelName = $this->_modelName($controllerName);
if(!loadModel($currentModelName)) { if (!loadModel($currentModelName)) {
$this->out('You must have a model for this class to build scaffold methods. Please try again.'); $this->out('You must have a model for this class to build scaffold methods. Please try again.');
exit; exit;
} }
@ -246,7 +246,7 @@ class ControllerTask extends Shell {
$actions .= "\t}\n"; $actions .= "\t}\n";
$actions .= "\n"; $actions .= "\n";
$actions .= "\tfunction {$admin}view(\$id = null) {\n"; $actions .= "\tfunction {$admin}view(\$id = null) {\n";
$actions .= "\t\tif(!\$id) {\n"; $actions .= "\t\tif (!\$id) {\n";
if (low($wannaUseSession) == 'y' || low($wannaUseSession) == 'yes') { if (low($wannaUseSession) == 'y' || low($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\$this->Session->setFlash('Invalid {$singularHumanName}.');\n"; $actions .= "\t\t\t\$this->Session->setFlash('Invalid {$singularHumanName}.');\n";
$actions .= "\t\t\t\$this->redirect(array('action'=>'index'), null, true);\n"; $actions .= "\t\t\t\$this->redirect(array('action'=>'index'), null, true);\n";
@ -261,10 +261,10 @@ class ControllerTask extends Shell {
/* ADD ACTION */ /* ADD ACTION */
$compact = array(); $compact = array();
$actions .= "\tfunction {$admin}add() {\n"; $actions .= "\tfunction {$admin}add() {\n";
$actions .= "\t\tif(!empty(\$this->data)) {\n"; $actions .= "\t\tif (!empty(\$this->data)) {\n";
$actions .= "\t\t\t\$this->cleanUpFields();\n"; $actions .= "\t\t\t\$this->cleanUpFields();\n";
$actions .= "\t\t\t\$this->{$currentModelName}->create();\n"; $actions .= "\t\t\t\$this->{$currentModelName}->create();\n";
$actions .= "\t\t\tif(\$this->{$currentModelName}->save(\$this->data)) {\n"; $actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n";
if (low($wannaUseSession) == 'y' || low($wannaUseSession) == 'yes') { if (low($wannaUseSession) == 'y' || low($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\t\$this->Session->setFlash('The ".$singularHumanName." has been saved');\n"; $actions .= "\t\t\t\t\$this->Session->setFlash('The ".$singularHumanName." has been saved');\n";
$actions .= "\t\t\t\t\$this->redirect(array('action'=>'index'), null, true);\n"; $actions .= "\t\t\t\t\$this->redirect(array('action'=>'index'), null, true);\n";
@ -278,8 +278,8 @@ class ControllerTask extends Shell {
} }
$actions .= "\t\t\t}\n"; $actions .= "\t\t\t}\n";
$actions .= "\t\t}\n"; $actions .= "\t\t}\n";
foreach($modelObj->hasAndBelongsToMany as $associationName => $relation) { foreach ($modelObj->hasAndBelongsToMany as $associationName => $relation) {
if(!empty($associationName)) { if (!empty($associationName)) {
$habtmModelName = $this->_modelName($associationName); $habtmModelName = $this->_modelName($associationName);
$habtmSingularName = $this->_singularName($associationName); $habtmSingularName = $this->_singularName($associationName);
$habtmPluralName = $this->_pluralName($associationName); $habtmPluralName = $this->_pluralName($associationName);
@ -287,15 +287,15 @@ class ControllerTask extends Shell {
$compact[] = "'{$habtmPluralName}'"; $compact[] = "'{$habtmPluralName}'";
} }
} }
foreach($modelObj->belongsTo as $associationName => $relation) { foreach ($modelObj->belongsTo as $associationName => $relation) {
if(!empty($associationName)) { if (!empty($associationName)) {
$belongsToModelName = $this->_modelName($associationName); $belongsToModelName = $this->_modelName($associationName);
$belongsToPluralName = $this->_pluralName($associationName); $belongsToPluralName = $this->_pluralName($associationName);
$actions .= "\t\t\${$belongsToPluralName} = \$this->{$currentModelName}->{$belongsToModelName}->generateList();\n"; $actions .= "\t\t\${$belongsToPluralName} = \$this->{$currentModelName}->{$belongsToModelName}->generateList();\n";
$compact[] = "'{$belongsToPluralName}'"; $compact[] = "'{$belongsToPluralName}'";
} }
} }
if(!empty($compact)) { if (!empty($compact)) {
$actions .= "\t\t\$this->set(compact(".join(', ', $compact)."));\n"; $actions .= "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
} }
$actions .= "\t}\n"; $actions .= "\t}\n";
@ -304,7 +304,7 @@ class ControllerTask extends Shell {
/* EDIT ACTION */ /* EDIT ACTION */
$compact = array(); $compact = array();
$actions .= "\tfunction {$admin}edit(\$id = null) {\n"; $actions .= "\tfunction {$admin}edit(\$id = null) {\n";
$actions .= "\t\tif(!\$id && empty(\$this->data)) {\n"; $actions .= "\t\tif (!\$id && empty(\$this->data)) {\n";
if (low($wannaUseSession) == 'y' || low($wannaUseSession) == 'yes') { if (low($wannaUseSession) == 'y' || low($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\$this->Session->setFlash('Invalid {$singularHumanName}');\n"; $actions .= "\t\t\t\$this->Session->setFlash('Invalid {$singularHumanName}');\n";
$actions .= "\t\t\t\$this->redirect(array('action'=>'index'), null, true);\n"; $actions .= "\t\t\t\$this->redirect(array('action'=>'index'), null, true);\n";
@ -313,9 +313,9 @@ class ControllerTask extends Shell {
$actions .= "\t\t\texit();\n"; $actions .= "\t\t\texit();\n";
} }
$actions .= "\t\t}\n"; $actions .= "\t\t}\n";
$actions .= "\t\tif(!empty(\$this->data)) {\n"; $actions .= "\t\tif (!empty(\$this->data)) {\n";
$actions .= "\t\t\t\$this->cleanUpFields();\n"; $actions .= "\t\t\t\$this->cleanUpFields();\n";
$actions .= "\t\t\tif(\$this->{$currentModelName}->save(\$this->data)) {\n"; $actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n";
if (low($wannaUseSession) == 'y' || low($wannaUseSession) == 'yes') { if (low($wannaUseSession) == 'y' || low($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\t\$this->Session->setFlash('The ".$singularHumanName." saved');\n"; $actions .= "\t\t\t\t\$this->Session->setFlash('The ".$singularHumanName." saved');\n";
$actions .= "\t\t\t\t\$this->redirect(array('action'=>'index'), null, true);\n"; $actions .= "\t\t\t\t\$this->redirect(array('action'=>'index'), null, true);\n";
@ -329,12 +329,12 @@ class ControllerTask extends Shell {
} }
$actions .= "\t\t\t}\n"; $actions .= "\t\t\t}\n";
$actions .= "\t\t}\n"; $actions .= "\t\t}\n";
$actions .= "\t\tif(empty(\$this->data)) {\n"; $actions .= "\t\tif (empty(\$this->data)) {\n";
$actions .= "\t\t\t\$this->data = \$this->{$currentModelName}->read(null, \$id);\n"; $actions .= "\t\t\t\$this->data = \$this->{$currentModelName}->read(null, \$id);\n";
$actions .= "\t\t}\n"; $actions .= "\t\t}\n";
foreach($modelObj->hasAndBelongsToMany as $associationName => $relation) { foreach ($modelObj->hasAndBelongsToMany as $associationName => $relation) {
if(!empty($associationName)) { if (!empty($associationName)) {
$habtmModelName = $this->_modelName($associationName); $habtmModelName = $this->_modelName($associationName);
$habtmSingularName = $this->_singularName($associationName); $habtmSingularName = $this->_singularName($associationName);
$habtmPluralName = $this->_pluralName($associationName); $habtmPluralName = $this->_pluralName($associationName);
@ -342,21 +342,21 @@ class ControllerTask extends Shell {
$compact[] = "'{$habtmPluralName}'"; $compact[] = "'{$habtmPluralName}'";
} }
} }
foreach($modelObj->belongsTo as $associationName => $relation) { foreach ($modelObj->belongsTo as $associationName => $relation) {
if(!empty($associationName)) { if (!empty($associationName)) {
$belongsToModelName = $this->_modelName($associationName); $belongsToModelName = $this->_modelName($associationName);
$belongsToPluralName = $this->_pluralName($associationName); $belongsToPluralName = $this->_pluralName($associationName);
$actions .= "\t\t\${$belongsToPluralName} = \$this->{$currentModelName}->{$belongsToModelName}->generateList();\n"; $actions .= "\t\t\${$belongsToPluralName} = \$this->{$currentModelName}->{$belongsToModelName}->generateList();\n";
$compact[] = "'{$belongsToPluralName}'"; $compact[] = "'{$belongsToPluralName}'";
} }
} }
if(!empty($compact)) { if (!empty($compact)) {
$actions .= "\t\t\$this->set(compact(".join(',', $compact)."));\n"; $actions .= "\t\t\$this->set(compact(".join(',', $compact)."));\n";
} }
$actions .= "\t}\n"; $actions .= "\t}\n";
$actions .= "\n"; $actions .= "\n";
$actions .= "\tfunction {$admin}delete(\$id = null) {\n"; $actions .= "\tfunction {$admin}delete(\$id = null) {\n";
$actions .= "\t\tif(!\$id) {\n"; $actions .= "\t\tif (!\$id) {\n";
if (low($wannaUseSession) == 'y' || low($wannaUseSession) == 'yes') { if (low($wannaUseSession) == 'y' || low($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\$this->Session->setFlash('Invalid id for {$singularHumanName}');\n"; $actions .= "\t\t\t\$this->Session->setFlash('Invalid id for {$singularHumanName}');\n";
$actions .= "\t\t\t\$this->redirect(array('action'=>'index'), null, true);\n"; $actions .= "\t\t\t\$this->redirect(array('action'=>'index'), null, true);\n";
@ -364,7 +364,7 @@ class ControllerTask extends Shell {
$actions .= "\t\t\t\$this->flash('Invalid {$singularHumanName}', array('action'=>'index'));\n"; $actions .= "\t\t\t\$this->flash('Invalid {$singularHumanName}', array('action'=>'index'));\n";
} }
$actions .= "\t\t}\n"; $actions .= "\t\t}\n";
$actions .= "\t\tif(\$this->{$currentModelName}->del(\$id)) {\n"; $actions .= "\t\tif (\$this->{$currentModelName}->del(\$id)) {\n";
if (low($wannaUseSession) == 'y' || low($wannaUseSession) == 'yes') { if (low($wannaUseSession) == 'y' || low($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\$this->Session->setFlash('".$singularHumanName." #'.\$id.' deleted');\n"; $actions .= "\t\t\t\$this->Session->setFlash('".$singularHumanName." #'.\$id.' deleted');\n";
$actions .= "\t\t\t\$this->redirect(array('action'=>'index'), null, true);\n"; $actions .= "\t\t\t\$this->redirect(array('action'=>'index'), null, true);\n";
@ -392,14 +392,14 @@ class ControllerTask extends Shell {
$out .= "class $controllerName" . "Controller extends AppController {\n\n"; $out .= "class $controllerName" . "Controller extends AppController {\n\n";
$out .= "\tvar \$name = '$controllerName';\n"; $out .= "\tvar \$name = '$controllerName';\n";
if(low($actions) == 'scaffold') { if (low($actions) == 'scaffold') {
$out .= "\tvar \$scaffold;\n"; $out .= "\tvar \$scaffold;\n";
} else { } else {
if (count($uses)) { if (count($uses)) {
$out .= "\tvar \$uses = array('" . $this->_modelName($controllerName) . "', "; $out .= "\tvar \$uses = array('" . $this->_modelName($controllerName) . "', ";
foreach($uses as $use) { foreach ($uses as $use) {
if ($use != $uses[count($uses) - 1]) { if ($use != $uses[count($uses) - 1]) {
$out .= "'" . $this->_modelName($use) . "', "; $out .= "'" . $this->_modelName($use) . "', ";
} else { } else {
@ -411,7 +411,7 @@ class ControllerTask extends Shell {
$out .= "\tvar \$helpers = array('Html', 'Form' "; $out .= "\tvar \$helpers = array('Html', 'Form' ";
if (count($helpers)) { if (count($helpers)) {
foreach($helpers as $help) { foreach ($helpers as $help) {
if ($help != $helpers[count($helpers) - 1]) { if ($help != $helpers[count($helpers) - 1]) {
$out .= ", '" . Inflector::camelize($help) . "'"; $out .= ", '" . Inflector::camelize($help) . "'";
} else { } else {
@ -424,7 +424,7 @@ class ControllerTask extends Shell {
if (count($components)) { if (count($components)) {
$out .= "\tvar \$components = array("; $out .= "\tvar \$components = array(";
foreach($components as $comp) { foreach ($components as $comp) {
if ($comp != $components[count($components) - 1]) { if ($comp != $components[count($components) - 1]) {
$out .= "'" . Inflector::camelize($comp) . "', "; $out .= "'" . Inflector::camelize($comp) . "', ";
} else { } else {
@ -463,7 +463,7 @@ class ControllerTask extends Shell {
$this->out("Baking unit test for $className..."); $this->out("Baking unit test for $className...");
$Folder =& new Folder($path, true); $Folder =& new Folder($path, true);
if($path = $Folder->cd($path)) { if ($path = $Folder->cd($path)) {
$path = $Folder->slashTerm($path); $path = $Folder->slashTerm($path);
return $this->createFile($path . $filename, $out); return $this->createFile($path . $filename, $out);
} }
@ -536,7 +536,7 @@ class ControllerTask extends Shell {
*/ */
function getAdmin() { function getAdmin() {
$admin = null; $admin = null;
if(defined('CAKE_ADMIN')) { if (defined('CAKE_ADMIN')) {
$admin = CAKE_ADMIN.'_'; $admin = CAKE_ADMIN.'_';
} else { } else {
$this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.'); $this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
@ -545,7 +545,7 @@ class ControllerTask extends Shell {
while ($admin == '') { while ($admin == '') {
$admin = $this->in("What would you like the admin route to be?", null, 'admin'); $admin = $this->in("What would you like the admin route to be?", null, 'admin');
} }
if($this->Project->cakeAdmin($admin) !== true){ if ($this->Project->cakeAdmin($admin) !== true){
$this->out('Unable to write to /app/config/core.php.'); $this->out('Unable to write to /app/config/core.php.');
$this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.'); $this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
exit(); exit();

View file

@ -26,7 +26,7 @@
* @lastmodified $Date$ * @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
if(!class_exists('File')) { if (!class_exists('File')) {
uses('file'); uses('file');
} }
/** /**
@ -43,7 +43,7 @@ class DbConfigTask extends Shell {
* @return void * @return void
*/ */
function execute() { function execute() {
if(empty($this->args)) { if (empty($this->args)) {
$this->__interactive(); $this->__interactive();
} }
} }
@ -65,7 +65,7 @@ class DbConfigTask extends Shell {
while ($persistent == '') { while ($persistent == '') {
$persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n'); $persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n');
} }
if(low($persistent) == 'n') { if (low($persistent) == 'n') {
$persistent = 'false'; $persistent = 'false';
} else { } else {
$persistent = 'true'; $persistent = 'true';
@ -87,7 +87,7 @@ class DbConfigTask extends Shell {
$password = $this->in('Password:'); $password = $this->in('Password:');
if ($password == '') { if ($password == '') {
$blank = $this->in('The password you supplied was empty. Use an empty password?', array('y', 'n'), 'n'); $blank = $this->in('The password you supplied was empty. Use an empty password?', array('y', 'n'), 'n');
if($blank == 'y') if ($blank == 'y')
{ {
$blankPassword = true; $blankPassword = true;
} }
@ -103,12 +103,12 @@ class DbConfigTask extends Shell {
while ($prefix == '') { while ($prefix == '') {
$prefix = $this->in('Table Prefix?', null, 'n'); $prefix = $this->in('Table Prefix?', null, 'n');
} }
if(low($prefix) == 'n') { if (low($prefix) == 'n') {
$prefix = null; $prefix = null;
} }
$config = compact('driver', 'persistent', 'host', 'login', 'password', 'database', 'prefix'); $config = compact('driver', 'persistent', 'host', 'login', 'password', 'database', 'prefix');
while($this->__verify($config) == false) { while ($this->__verify($config) == false) {
$this->__interactive(); $this->__interactive();
} }
@ -162,7 +162,7 @@ class DbConfigTask extends Shell {
$config = am($defaults, $config); $config = am($defaults, $config);
extract($config); extract($config);
if(is_dir(CONFIGS)) { if (is_dir(CONFIGS)) {
$out = "<?php\n"; $out = "<?php\n";
$out .= "class DATABASE_CONFIG {\n\n"; $out .= "class DATABASE_CONFIG {\n\n";
$out .= "\tvar \$default = array(\n"; $out .= "\tvar \$default = array(\n";
@ -172,7 +172,7 @@ class DbConfigTask extends Shell {
$out .= "\t\t'login' => '{$login}',\n"; $out .= "\t\t'login' => '{$login}',\n";
$out .= "\t\t'password' => '{$password}',\n"; $out .= "\t\t'password' => '{$password}',\n";
$out .= "\t\t'database' => '{$database}', \n"; $out .= "\t\t'database' => '{$database}', \n";
if($schema) { if ($schema) {
$out .= "\t\t'schema' => '{$schema}', \n"; $out .= "\t\t'schema' => '{$schema}', \n";
} }
$out .= "\t\t'prefix' => '{$prefix}' \n"; $out .= "\t\t'prefix' => '{$prefix}' \n";

View file

@ -40,7 +40,7 @@ class ModelTask extends Shell {
* @return void * @return void
*/ */
function execute() { function execute() {
if(empty($this->args)) { if (empty($this->args)) {
$this->__interactive(); $this->__interactive();
} }
} }
@ -72,7 +72,7 @@ class ModelTask extends Shell {
$tableIsGood = false; $tableIsGood = false;
$useTable = Inflector::tableize($currentModelName); $useTable = Inflector::tableize($currentModelName);
$fullTableName = $db->fullTableName($useTable, false); $fullTableName = $db->fullTableName($useTable, false);
if(array_search($useTable, $this->__tables) === false) { if (array_search($useTable, $this->__tables) === false) {
$this->out("\nGiven your model named '$currentModelName', Cake would expect a database table named '" . $fullTableName . "'."); $this->out("\nGiven your model named '$currentModelName', Cake would expect a database table named '" . $fullTableName . "'.");
$tableIsGood = $this->in('do you want to use this table?', array('y','n'), 'y'); $tableIsGood = $this->in('do you want to use this table?', array('y','n'), 'y');
} }
@ -80,7 +80,7 @@ class ModelTask extends Shell {
if (low($tableIsGood) == 'n' || low($tableIsGood) == 'no') { if (low($tableIsGood) == 'n' || low($tableIsGood) == 'no') {
$useTable = $this->in('What is the name of the table (enter "null" to use NO table)?'); $useTable = $this->in('What is the name of the table (enter "null" to use NO table)?');
} }
while($tableIsGood == false && low($useTable) != 'null') { while ($tableIsGood == false && low($useTable) != 'null') {
if (is_array($this->__tables) && !in_array($useTable, $this->__tables)) { if (is_array($this->__tables) && !in_array($useTable, $this->__tables)) {
$fullTableName = $db->fullTableName($useTable, false); $fullTableName = $db->fullTableName($useTable, false);
$this->out($fullTableName . ' does not exist.'); $this->out($fullTableName . ' does not exist.');
@ -92,18 +92,18 @@ class ModelTask extends Shell {
} }
$wannaDoValidation = $this->in('Would you like to supply validation criteria for the fields in your model?', array('y','n'), 'y'); $wannaDoValidation = $this->in('Would you like to supply validation criteria for the fields in your model?', array('y','n'), 'y');
if(in_array($useTable, $this->__tables)) { if (in_array($useTable, $this->__tables)) {
loadModel(); loadModel();
$tempModel = new Model(false, $useTable); $tempModel = new Model(false, $useTable);
$modelFields = $db->describe($tempModel); $modelFields = $db->describe($tempModel);
if(isset($modelFields[0]['name']) && $modelFields[0]['name'] != 'id') { if (isset($modelFields[0]['name']) && $modelFields[0]['name'] != 'id') {
$primaryKey = $this->in('What is the primaryKey?', null, $modelFields[0]['name']); $primaryKey = $this->in('What is the primaryKey?', null, $modelFields[0]['name']);
} }
} }
$validate = array(); $validate = array();
if (array_search($useTable, $this->__tables) !== false && (low($wannaDoValidation) == 'y' || low($wannaDoValidation) == 'yes')) { if (array_search($useTable, $this->__tables) !== false && (low($wannaDoValidation) == 'y' || low($wannaDoValidation) == 'yes')) {
foreach($modelFields as $field) { foreach ($modelFields as $field) {
$this->out(''); $this->out('');
$prompt = 'Name: ' . $field['name'] . "\n"; $prompt = 'Name: ' . $field['name'] . "\n";
$prompt .= 'Type: ' . $field['type'] . "\n"; $prompt .= 'Type: ' . $field['type'] . "\n";
@ -117,7 +117,7 @@ class ModelTask extends Shell {
$prompt .= "5- Do not do any validation on this field.\n\n"; $prompt .= "5- Do not do any validation on this field.\n\n";
$prompt .= "... or enter in a valid regex validation string.\n\n"; $prompt .= "... or enter in a valid regex validation string.\n\n";
if($field['null'] == 1 || $field['name'] == $primaryKey || $field['name'] == 'created' || $field['name'] == 'modified') { if ($field['null'] == 1 || $field['name'] == $primaryKey || $field['name'] == 'created' || $field['name'] == 'modified') {
$validation = $this->in($prompt, null, '5'); $validation = $this->in($prompt, null, '5');
} else { } else {
$validation = $this->in($prompt, null, '1'); $validation = $this->in($prompt, null, '1');
@ -147,14 +147,14 @@ class ModelTask extends Shell {
$wannaDoAssoc = $this->in('Would you like to define model associations (hasMany, hasOne, belongsTo, etc.)?', array('y','n'), 'y'); $wannaDoAssoc = $this->in('Would you like to define model associations (hasMany, hasOne, belongsTo, etc.)?', array('y','n'), 'y');
if((low($wannaDoAssoc) == 'y' || low($wannaDoAssoc) == 'yes')) { if ((low($wannaDoAssoc) == 'y' || low($wannaDoAssoc) == 'yes')) {
$this->out('One moment while I try to detect any associations...'); $this->out('One moment while I try to detect any associations...');
$possibleKeys = array(); $possibleKeys = array();
//Look for belongsTo //Look for belongsTo
$i = 0; $i = 0;
foreach($modelFields as $field) { foreach ($modelFields as $field) {
$offset = strpos($field['name'], '_id'); $offset = strpos($field['name'], '_id');
if($field['name'] != $primaryKey && $offset !== false) { if ($field['name'] != $primaryKey && $offset !== false) {
$tmpModelName = $this->_modelNameFromKey($field['name']); $tmpModelName = $this->_modelNameFromKey($field['name']);
$associations['belongsTo'][$i]['alias'] = $tmpModelName; $associations['belongsTo'][$i]['alias'] = $tmpModelName;
$associations['belongsTo'][$i]['className'] = $tmpModelName; $associations['belongsTo'][$i]['className'] = $tmpModelName;
@ -165,14 +165,14 @@ class ModelTask extends Shell {
//Look for hasOne and hasMany and hasAndBelongsToMany //Look for hasOne and hasMany and hasAndBelongsToMany
$i = 0; $i = 0;
$j = 0; $j = 0;
foreach($this->__tables as $otherTable) { foreach ($this->__tables as $otherTable) {
$tempOtherModel = & new Model(false, $otherTable); $tempOtherModel = & new Model(false, $otherTable);
$modelFieldsTemp = $db->describe($tempOtherModel); $modelFieldsTemp = $db->describe($tempOtherModel);
foreach($modelFieldsTemp as $field) { foreach ($modelFieldsTemp as $field) {
if($field['type'] == 'integer' || $field['type'] == 'string') { if ($field['type'] == 'integer' || $field['type'] == 'string') {
$possibleKeys[$otherTable][] = $field['name']; $possibleKeys[$otherTable][] = $field['name'];
} }
if($field['name'] != $primaryKey && $field['name'] == $this->_modelKey($currentModelName)) { if ($field['name'] != $primaryKey && $field['name'] == $this->_modelKey($currentModelName)) {
$tmpModelName = $this->_modelName($otherTable); $tmpModelName = $this->_modelName($otherTable);
$associations['hasOne'][$j]['alias'] = $tmpModelName; $associations['hasOne'][$j]['alias'] = $tmpModelName;
$associations['hasOne'][$j]['className'] = $tmpModelName; $associations['hasOne'][$j]['className'] = $tmpModelName;
@ -185,7 +185,7 @@ class ModelTask extends Shell {
} }
} }
$offset = strpos($otherTable, $useTable . '_'); $offset = strpos($otherTable, $useTable . '_');
if($offset !== false) { if ($offset !== false) {
$offset = strlen($useTable . '_'); $offset = strlen($useTable . '_');
$tmpModelName = $this->_modelName(substr($otherTable, $offset)); $tmpModelName = $this->_modelName(substr($otherTable, $offset));
$associations['hasAndBelongsToMany'][$i]['alias'] = $tmpModelName; $associations['hasAndBelongsToMany'][$i]['alias'] = $tmpModelName;
@ -209,20 +209,20 @@ class ModelTask extends Shell {
$this->out('Done.'); $this->out('Done.');
$this->hr(); $this->hr();
//if none found... //if none found...
if(empty($associations)) { if (empty($associations)) {
$this->out('None found.'); $this->out('None found.');
} else { } else {
$this->out('Please confirm the following associations:'); $this->out('Please confirm the following associations:');
$this->hr(); $this->hr();
if(!empty($associations['belongsTo'])) { if (!empty($associations['belongsTo'])) {
$count = count($associations['belongsTo']); $count = count($associations['belongsTo']);
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if($currentModelName == $associations['belongsTo'][$i]['alias']) { if ($currentModelName == $associations['belongsTo'][$i]['alias']) {
$response = $this->in("{$currentModelName} belongsTo {$associations['belongsTo'][$i]['alias']}\nThis looks like a self join. Do you want to specify an alternate association alias?", array('y','n'), 'y'); $response = $this->in("{$currentModelName} belongsTo {$associations['belongsTo'][$i]['alias']}\nThis looks like a self join. Do you want to specify an alternate association alias?", array('y','n'), 'y');
if('y' == low($response) || 'yes' == low($response)) { if ('y' == low($response) || 'yes' == low($response)) {
$associations['belongsTo'][$i]['alias'] = $this->in("So what is the alias?", null, $associations['belongsTo'][$i]['alias']); $associations['belongsTo'][$i]['alias'] = $this->in("So what is the alias?", null, $associations['belongsTo'][$i]['alias']);
} }
if($currentModelName != $associations['belongsTo'][$i]['alias']) { if ($currentModelName != $associations['belongsTo'][$i]['alias']) {
$response = $this->in("$currentModelName belongsTo {$associations['belongsTo'][$i]['alias']}?", array('y','n'), 'y'); $response = $this->in("$currentModelName belongsTo {$associations['belongsTo'][$i]['alias']}?", array('y','n'), 'y');
} else { } else {
$response = 'n'; $response = 'n';
@ -230,22 +230,22 @@ class ModelTask extends Shell {
} else { } else {
$response = $this->in("$currentModelName belongsTo {$associations['belongsTo'][$i]['alias']}?", array('y','n'), 'y'); $response = $this->in("$currentModelName belongsTo {$associations['belongsTo'][$i]['alias']}?", array('y','n'), 'y');
} }
if('n' == low($response) || 'no' == low($response)) { if ('n' == low($response) || 'no' == low($response)) {
unset($associations['belongsTo'][$i]); unset($associations['belongsTo'][$i]);
} }
} }
$associations['belongsTo'] = array_merge($associations['belongsTo']); $associations['belongsTo'] = array_merge($associations['belongsTo']);
} }
if(!empty($associations['hasOne'])) { if (!empty($associations['hasOne'])) {
$count = count($associations['hasOne']); $count = count($associations['hasOne']);
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if($currentModelName == $associations['hasOne'][$i]['alias']) { if ($currentModelName == $associations['hasOne'][$i]['alias']) {
$response = $this->in("{$currentModelName} hasOne {$associations['hasOne'][$i]['alias']}\nThis looks like a self join. Do you want to specify an alternate association alias?", array('y','n'), 'y'); $response = $this->in("{$currentModelName} hasOne {$associations['hasOne'][$i]['alias']}\nThis looks like a self join. Do you want to specify an alternate association alias?", array('y','n'), 'y');
if('y' == low($response) || 'yes' == low($response)) { if ('y' == low($response) || 'yes' == low($response)) {
$associations['hasOne'][$i]['alias'] = $this->in("So what is the alias?", null, $associations['hasOne'][$i]['alias']); $associations['hasOne'][$i]['alias'] = $this->in("So what is the alias?", null, $associations['hasOne'][$i]['alias']);
} }
if($currentModelName != $associations['hasOne'][$i]['alias']) { if ($currentModelName != $associations['hasOne'][$i]['alias']) {
$response = $this->in("$currentModelName hasOne {$associations['hasOne'][$i]['alias']}?", array('y','n'), 'y'); $response = $this->in("$currentModelName hasOne {$associations['hasOne'][$i]['alias']}?", array('y','n'), 'y');
} else { } else {
$response = 'n'; $response = 'n';
@ -253,22 +253,22 @@ class ModelTask extends Shell {
} else { } else {
$response = $this->in("$currentModelName hasOne {$associations['hasOne'][$i]['alias']}?", array('y','n'), 'y'); $response = $this->in("$currentModelName hasOne {$associations['hasOne'][$i]['alias']}?", array('y','n'), 'y');
} }
if('n' == low($response) || 'no' == low($response)) { if ('n' == low($response) || 'no' == low($response)) {
unset($associations['hasOne'][$i]); unset($associations['hasOne'][$i]);
} }
} }
$associations['hasOne'] = array_merge($associations['hasOne']); $associations['hasOne'] = array_merge($associations['hasOne']);
} }
if(!empty($associations['hasMany'])) { if (!empty($associations['hasMany'])) {
$count = count($associations['hasMany']); $count = count($associations['hasMany']);
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if($currentModelName == $associations['hasMany'][$i]['alias']) { if ($currentModelName == $associations['hasMany'][$i]['alias']) {
$response = $this->in("{$currentModelName} hasMany {$associations['hasMany'][$i]['alias']}\nThis looks like a self join. Do you want to specify an alternate association alias?", array('y','n'), 'y'); $response = $this->in("{$currentModelName} hasMany {$associations['hasMany'][$i]['alias']}\nThis looks like a self join. Do you want to specify an alternate association alias?", array('y','n'), 'y');
if('y' == low($response) || 'yes' == low($response)) { if ('y' == low($response) || 'yes' == low($response)) {
$associations['hasMany'][$i]['alias'] = $this->in("So what is the alias?", null, $associations['hasMany'][$i]['alias']); $associations['hasMany'][$i]['alias'] = $this->in("So what is the alias?", null, $associations['hasMany'][$i]['alias']);
} }
if($currentModelName != $associations['hasMany'][$i]['alias']) { if ($currentModelName != $associations['hasMany'][$i]['alias']) {
$response = $this->in("$currentModelName hasMany {$associations['hasMany'][$i]['alias']}?", array('y','n'), 'y'); $response = $this->in("$currentModelName hasMany {$associations['hasMany'][$i]['alias']}?", array('y','n'), 'y');
} else { } else {
$response = 'n'; $response = 'n';
@ -276,22 +276,22 @@ class ModelTask extends Shell {
} else { } else {
$response = $this->in("$currentModelName hasMany {$associations['hasMany'][$i]['alias']}?", array('y','n'), 'y'); $response = $this->in("$currentModelName hasMany {$associations['hasMany'][$i]['alias']}?", array('y','n'), 'y');
} }
if('n' == low($response) || 'no' == low($response)) { if ('n' == low($response) || 'no' == low($response)) {
unset($associations['hasMany'][$i]); unset($associations['hasMany'][$i]);
} }
} }
$associations['hasMany'] = array_merge($associations['hasMany']); $associations['hasMany'] = array_merge($associations['hasMany']);
} }
if(!empty($associations['hasAndBelongsToMany'])) { if (!empty($associations['hasAndBelongsToMany'])) {
$count = count($associations['hasAndBelongsToMany']); $count = count($associations['hasAndBelongsToMany']);
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if($currentModelName == $associations['hasAndBelongsToMany'][$i]['alias']) { if ($currentModelName == $associations['hasAndBelongsToMany'][$i]['alias']) {
$response = $this->in("{$currentModelName} hasAndBelongsToMany {$associations['hasAndBelongsToMany'][$i]['alias']}\nThis looks like a self join. Do you want to specify an alternate association alias?", array('y','n'), 'y'); $response = $this->in("{$currentModelName} hasAndBelongsToMany {$associations['hasAndBelongsToMany'][$i]['alias']}\nThis looks like a self join. Do you want to specify an alternate association alias?", array('y','n'), 'y');
if('y' == low($response) || 'yes' == low($response)) { if ('y' == low($response) || 'yes' == low($response)) {
$associations['hasAndBelongsToMany'][$i]['alias'] = $this->in("So what is the alias?", null, $associations['hasAndBelongsToMany'][$i]['alias']); $associations['hasAndBelongsToMany'][$i]['alias'] = $this->in("So what is the alias?", null, $associations['hasAndBelongsToMany'][$i]['alias']);
} }
if($currentModelName != $associations['hasAndBelongsToMany'][$i]['alias']) { if ($currentModelName != $associations['hasAndBelongsToMany'][$i]['alias']) {
$response = $this->in("$currentModelName hasAndBelongsToMany {$associations['hasAndBelongsToMany'][$i]['alias']}?", array('y','n'), 'y'); $response = $this->in("$currentModelName hasAndBelongsToMany {$associations['hasAndBelongsToMany'][$i]['alias']}?", array('y','n'), 'y');
} else { } else {
$response = 'n'; $response = 'n';
@ -299,7 +299,7 @@ class ModelTask extends Shell {
} else { } else {
$response = $this->in("$currentModelName hasAndBelongsToMany {$associations['hasAndBelongsToMany'][$i]['alias']}?", array('y','n'), 'y'); $response = $this->in("$currentModelName hasAndBelongsToMany {$associations['hasAndBelongsToMany'][$i]['alias']}?", array('y','n'), 'y');
} }
if('n' == low($response) || 'no' == low($response)) { if ('n' == low($response) || 'no' == low($response)) {
unset($associations['hasAndBelongsToMany'][$i]); unset($associations['hasAndBelongsToMany'][$i]);
} }
} }
@ -308,10 +308,10 @@ class ModelTask extends Shell {
} }
$wannaDoMoreAssoc = $this->in('Would you like to define some additional model associations?', array('y','n'), 'n'); $wannaDoMoreAssoc = $this->in('Would you like to define some additional model associations?', array('y','n'), 'n');
while((low($wannaDoMoreAssoc) == 'y' || low($wannaDoMoreAssoc) == 'yes')) { while ((low($wannaDoMoreAssoc) == 'y' || low($wannaDoMoreAssoc) == 'yes')) {
$assocs = array(1 => 'belongsTo', 2 => 'hasOne', 3 => 'hasMany', 4 => 'hasAndBelongsToMany'); $assocs = array(1 => 'belongsTo', 2 => 'hasOne', 3 => 'hasMany', 4 => 'hasAndBelongsToMany');
$bad = true; $bad = true;
while($bad) { while ($bad) {
$this->out('What is the association type?'); $this->out('What is the association type?');
$prompt = "1- belongsTo\n"; $prompt = "1- belongsTo\n";
$prompt .= "2- hasOne\n"; $prompt .= "2- hasOne\n";
@ -319,7 +319,7 @@ class ModelTask extends Shell {
$prompt .= "4- hasAndBelongsToMany\n"; $prompt .= "4- hasAndBelongsToMany\n";
$assocType = intval($this->in($prompt, null, null)); $assocType = intval($this->in($prompt, null, null));
if(intval($assocType) < 1 || intval($assocType) > 4) { if (intval($assocType) < 1 || intval($assocType) > 4) {
$this->out('The selection you entered was invalid. Please enter a number between 1 and 4.'); $this->out('The selection you entered was invalid. Please enter a number between 1 and 4.');
} else { } else {
$bad = false; $bad = false;
@ -330,13 +330,13 @@ class ModelTask extends Shell {
$associationName = $this->in('What is the name of this association?'); $associationName = $this->in('What is the name of this association?');
$className = $this->in('What className will '.$associationName.' use?', null, $associationName ); $className = $this->in('What className will '.$associationName.' use?', null, $associationName );
$suggestedForeignKey = null; $suggestedForeignKey = null;
if($assocType == '1') { if ($assocType == '1') {
$showKeys = $possibleKeys[$useTable]; $showKeys = $possibleKeys[$useTable];
$suggestedForeignKey = $this->_modelKey($associationName); $suggestedForeignKey = $this->_modelKey($associationName);
} else { } else {
$otherTable = Inflector::tableize($className); $otherTable = Inflector::tableize($className);
if(in_array($otherTable, $this->__tables)) { if (in_array($otherTable, $this->__tables)) {
if($assocType < '4') { if ($assocType < '4') {
$showKeys = $possibleKeys[$otherTable]; $showKeys = $possibleKeys[$otherTable];
} else { } else {
$showKeys = null; $showKeys = null;
@ -347,7 +347,7 @@ class ModelTask extends Shell {
} }
$suggestedForeignKey = $this->_modelKey($currentModelName); $suggestedForeignKey = $this->_modelKey($currentModelName);
} }
if(!empty($showKeys)) { if (!empty($showKeys)) {
$this->out('A helpful List of possible keys'); $this->out('A helpful List of possible keys');
for ($i = 0; $i < count($showKeys); $i++) { for ($i = 0; $i < count($showKeys); $i++) {
$this->out($i + 1 . ". " . $showKeys[$i]); $this->out($i + 1 . ". " . $showKeys[$i]);
@ -357,10 +357,10 @@ class ModelTask extends Shell {
$foreignKey = $showKeys[intval($foreignKey) - 1]; $foreignKey = $showKeys[intval($foreignKey) - 1];
} }
} }
if(!isset($foreignKey)) { if (!isset($foreignKey)) {
$foreignKey = $this->in('What is the foreignKey? Specify your own.', null, $suggestedForeignKey); $foreignKey = $this->in('What is the foreignKey? Specify your own.', null, $suggestedForeignKey);
} }
if($assocType == '4') { if ($assocType == '4') {
$associationForeignKey = $this->in('What is the associationForeignKey?', null, $this->_modelKey($currentModelName)); $associationForeignKey = $this->in('What is the associationForeignKey?', null, $this->_modelKey($currentModelName));
$joinTable = $this->in('What is the joinTable?'); $joinTable = $this->in('What is the joinTable?');
} }
@ -370,7 +370,7 @@ class ModelTask extends Shell {
$associations[$assocs[$assocType]][$i]['alias'] = $associationName; $associations[$assocs[$assocType]][$i]['alias'] = $associationName;
$associations[$assocs[$assocType]][$i]['className'] = $className; $associations[$assocs[$assocType]][$i]['className'] = $className;
$associations[$assocs[$assocType]][$i]['foreignKey'] = $foreignKey; $associations[$assocs[$assocType]][$i]['foreignKey'] = $foreignKey;
if($assocType == '4') { if ($assocType == '4') {
$associations[$assocs[$assocType]][$i]['associationForeignKey'] = $associationForeignKey; $associations[$assocs[$assocType]][$i]['associationForeignKey'] = $associationForeignKey;
$associations[$assocs[$assocType]][$i]['joinTable'] = $joinTable; $associations[$assocs[$assocType]][$i]['joinTable'] = $joinTable;
} }
@ -384,34 +384,34 @@ class ModelTask extends Shell {
$this->out("Model Name: $currentModelName"); $this->out("Model Name: $currentModelName");
$this->out("DB Connection: " . $useDbConfig); $this->out("DB Connection: " . $useDbConfig);
$this->out("DB Table: " . $fullTableName); $this->out("DB Table: " . $fullTableName);
if($primaryKey != 'id') { if ($primaryKey != 'id') {
$this->out("Primary Key: " . $primaryKey); $this->out("Primary Key: " . $primaryKey);
} }
$this->out("Validation: " . print_r($validate, true)); $this->out("Validation: " . print_r($validate, true));
if(!empty($associations)) { if (!empty($associations)) {
$this->out("Associations:"); $this->out("Associations:");
if(!empty($associations['belongsTo'])) { if (!empty($associations['belongsTo'])) {
for($i = 0; $i < count($associations['belongsTo']); $i++) { for ($i = 0; $i < count($associations['belongsTo']); $i++) {
$this->out(" $currentModelName belongsTo {$associations['belongsTo'][$i]['alias']}"); $this->out(" $currentModelName belongsTo {$associations['belongsTo'][$i]['alias']}");
} }
} }
if(!empty($associations['hasOne'])) { if (!empty($associations['hasOne'])) {
for($i = 0; $i < count($associations['hasOne']); $i++) { for ($i = 0; $i < count($associations['hasOne']); $i++) {
$this->out(" $currentModelName hasOne {$associations['hasOne'][$i]['alias']}"); $this->out(" $currentModelName hasOne {$associations['hasOne'][$i]['alias']}");
} }
} }
if(!empty($associations['hasMany'])) { if (!empty($associations['hasMany'])) {
for($i = 0; $i < count($associations['hasMany']); $i++) { for ($i = 0; $i < count($associations['hasMany']); $i++) {
$this->out(" $currentModelName hasMany {$associations['hasMany'][$i]['alias']}"); $this->out(" $currentModelName hasMany {$associations['hasMany'][$i]['alias']}");
} }
} }
if(!empty($associations['hasAndBelongsToMany'])) { if (!empty($associations['hasAndBelongsToMany'])) {
for($i = 0; $i < count($associations['hasAndBelongsToMany']); $i++) { for ($i = 0; $i < count($associations['hasAndBelongsToMany']); $i++) {
$this->out(" $currentModelName hasAndBelongsToMany {$associations['hasAndBelongsToMany'][$i]['alias']}"); $this->out(" $currentModelName hasAndBelongsToMany {$associations['hasAndBelongsToMany'][$i]['alias']}");
} }
} }
@ -426,7 +426,7 @@ class ModelTask extends Shell {
// is unnecessary. // is unnecessary.
$useTable = null; $useTable = null;
} }
if($this->__bake($currentModelName, $useDbConfig, $useTable, $primaryKey, $validate, $associations)) { if ($this->__bake($currentModelName, $useDbConfig, $useTable, $primaryKey, $validate, $associations)) {
if ($this->_checkUnitTest()) { if ($this->_checkUnitTest()) {
$this->__bakeTest($currentModelName); $this->__bakeTest($currentModelName);
} }
@ -467,19 +467,19 @@ class ModelTask extends Shell {
if (count($validate)) { if (count($validate)) {
$out .= "\tvar \$validate = array(\n"; $out .= "\tvar \$validate = array(\n";
$keys = array_keys($validate); $keys = array_keys($validate);
for($i = 0; $i < count($validate); $i++) { for ($i = 0; $i < count($validate); $i++) {
$out .= "\t\t'" . $keys[$i] . "' => " . $validate[$keys[$i]] . ",\n"; $out .= "\t\t'" . $keys[$i] . "' => " . $validate[$keys[$i]] . ",\n";
} }
$out .= "\t);\n"; $out .= "\t);\n";
} }
$out .= "\n"; $out .= "\n";
if(!empty($associations)) { if (!empty($associations)) {
$out.= "\t//The Associations below have been created with all possible keys, those that are not needed can be removed\n"; $out.= "\t//The Associations below have been created with all possible keys, those that are not needed can be removed\n";
if(!empty($associations['belongsTo'])) { if (!empty($associations['belongsTo'])) {
$out .= "\tvar \$belongsTo = array(\n"; $out .= "\tvar \$belongsTo = array(\n";
for($i = 0; $i < count($associations['belongsTo']); $i++) { for ($i = 0; $i < count($associations['belongsTo']); $i++) {
$out .= "\t\t\t'{$associations['belongsTo'][$i]['alias']}' => "; $out .= "\t\t\t'{$associations['belongsTo'][$i]['alias']}' => ";
$out .= "array('className' => '{$associations['belongsTo'][$i]['className']}',\n"; $out .= "array('className' => '{$associations['belongsTo'][$i]['className']}',\n";
$out .= "\t\t\t\t\t\t\t\t'foreignKey' => '{$associations['belongsTo'][$i]['foreignKey']}',\n"; $out .= "\t\t\t\t\t\t\t\t'foreignKey' => '{$associations['belongsTo'][$i]['foreignKey']}',\n";
@ -492,10 +492,10 @@ class ModelTask extends Shell {
$out .= "\t);\n\n"; $out .= "\t);\n\n";
} }
if(!empty($associations['hasOne'])) { if (!empty($associations['hasOne'])) {
$out .= "\tvar \$hasOne = array(\n"; $out .= "\tvar \$hasOne = array(\n";
for($i = 0; $i < count($associations['hasOne']); $i++) { for ($i = 0; $i < count($associations['hasOne']); $i++) {
$out .= "\t\t\t'{$associations['hasOne'][$i]['alias']}' => "; $out .= "\t\t\t'{$associations['hasOne'][$i]['alias']}' => ";
$out .= "array('className' => '{$associations['hasOne'][$i]['className']}',\n"; $out .= "array('className' => '{$associations['hasOne'][$i]['className']}',\n";
$out .= "\t\t\t\t\t\t\t\t'foreignKey' => '{$associations['hasOne'][$i]['foreignKey']}',\n"; $out .= "\t\t\t\t\t\t\t\t'foreignKey' => '{$associations['hasOne'][$i]['foreignKey']}',\n";
@ -508,10 +508,10 @@ class ModelTask extends Shell {
$out .= "\t);\n\n"; $out .= "\t);\n\n";
} }
if(!empty($associations['hasMany'])) { if (!empty($associations['hasMany'])) {
$out .= "\tvar \$hasMany = array(\n"; $out .= "\tvar \$hasMany = array(\n";
for($i = 0; $i < count($associations['hasMany']); $i++) { for ($i = 0; $i < count($associations['hasMany']); $i++) {
$out .= "\t\t\t'{$associations['hasMany'][$i]['alias']}' => "; $out .= "\t\t\t'{$associations['hasMany'][$i]['alias']}' => ";
$out .= "array('className' => '{$associations['hasMany'][$i]['className']}',\n"; $out .= "array('className' => '{$associations['hasMany'][$i]['className']}',\n";
$out .= "\t\t\t\t\t\t\t\t'foreignKey' => '{$associations['hasMany'][$i]['foreignKey']}',\n"; $out .= "\t\t\t\t\t\t\t\t'foreignKey' => '{$associations['hasMany'][$i]['foreignKey']}',\n";
@ -529,10 +529,10 @@ class ModelTask extends Shell {
$out .= "\t);\n\n"; $out .= "\t);\n\n";
} }
if(!empty($associations['hasAndBelongsToMany'])) { if (!empty($associations['hasAndBelongsToMany'])) {
$out .= "\tvar \$hasAndBelongsToMany = array(\n"; $out .= "\tvar \$hasAndBelongsToMany = array(\n";
for($i = 0; $i < count($associations['hasAndBelongsToMany']); $i++) { for ($i = 0; $i < count($associations['hasAndBelongsToMany']); $i++) {
$out .= "\t\t\t'{$associations['hasAndBelongsToMany'][$i]['alias']}' => "; $out .= "\t\t\t'{$associations['hasAndBelongsToMany'][$i]['alias']}' => ";
$out .= "array('className' => '{$associations['hasAndBelongsToMany'][$i]['className']}',\n"; $out .= "array('className' => '{$associations['hasAndBelongsToMany'][$i]['className']}',\n";
$out .= "\t\t\t\t\t\t'joinTable' => '{$associations['hasAndBelongsToMany'][$i]['joinTable']}',\n"; $out .= "\t\t\t\t\t\t'joinTable' => '{$associations['hasAndBelongsToMany'][$i]['joinTable']}',\n";
@ -582,7 +582,7 @@ class ModelTask extends Shell {
$this->out("Baking unit test for $className..."); $this->out("Baking unit test for $className...");
$Folder =& new Folder($path, true); $Folder =& new Folder($path, true);
if($path = $Folder->cd($path)) { if ($path = $Folder->cd($path)) {
$path = $Folder->slashTerm($path); $path = $Folder->slashTerm($path);
return $this->createFile($path . $filename, $out); return $this->createFile($path . $filename, $out);
} }

View file

@ -26,7 +26,7 @@
* @lastmodified $Date$ * @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
if(!class_exists('File')) { if (!class_exists('File')) {
uses('file'); uses('file');
} }
/** /**
@ -51,9 +51,9 @@ class ProjectTask extends Shell {
* @return bool * @return bool
*/ */
function execute($project = null) { function execute($project = null) {
if($project === null) { if ($project === null) {
$project = $this->params['app']; $project = $this->params['app'];
if(isset($this->args[0])) { if (isset($this->args[0])) {
$project = $this->args[0]; $project = $this->args[0];
$this->Dispatch->shiftArgs(); $this->Dispatch->shiftArgs();
} }
@ -63,12 +63,12 @@ class ProjectTask extends Shell {
$app = basename($working); $app = basename($working);
$root = dirname($working) . DS; $root = dirname($working) . DS;
if($project) { if ($project) {
if($project{0} != '/') { if ($project{0} != '/') {
$root = $working; $root = $working;
$app = $project; $app = $project;
} }
if($root{strlen($root) -1} != '/') { if ($root{strlen($root) -1} != '/') {
$root = $root . DS; $root = $root . DS;
} }
@ -77,7 +77,7 @@ class ProjectTask extends Shell {
$response = false; $response = false;
while ($response == false && is_dir($path) === true && config('database') === true) { while ($response == false && is_dir($path) === true && config('database') === true) {
$response = $this->in('A project already exists in this location: '.$project.' Overwrite?', array('y','n'), 'n'); $response = $this->in('A project already exists in this location: '.$project.' Overwrite?', array('y','n'), 'n');
if(low($response) === 'n') { if (low($response) === 'n') {
$this->out('Bake Aborted'); $this->out('Bake Aborted');
exit(); exit();
} }
@ -108,7 +108,7 @@ class ProjectTask extends Shell {
*/ */
function __buildDirLayout($path) { function __buildDirLayout($path) {
$skel = ''; $skel = '';
if(is_dir(CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel') === true) { if (is_dir(CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel') === true) {
$skel = CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel'; $skel = CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel';
} else { } else {
while ($skel == '') { while ($skel == '') {
@ -138,32 +138,32 @@ class ProjectTask extends Shell {
} }
$Folder = new Folder($skel); $Folder = new Folder($skel);
if($Folder->copy($path)) { if ($Folder->copy($path)) {
$path = $Folder->slashTerm($path); $path = $Folder->slashTerm($path);
$this->hr(); $this->hr();
$this->out(__(sprintf("Created: %s in %s", $app, $path), true)); $this->out(__(sprintf("Created: %s in %s", $app, $path), true));
$this->hr(); $this->hr();
if($this->createHome($path, $app)) { if ($this->createHome($path, $app)) {
$this->out('Welcome page created'); $this->out('Welcome page created');
} else { } else {
$this->out('The Welcome page was NOT created'); $this->out('The Welcome page was NOT created');
} }
if($this->cakeSessionString($path) === true ){ if ($this->cakeSessionString($path) === true ){
$this->out('Random hash key created for CAKE_SESSION_STRING'); $this->out('Random hash key created for CAKE_SESSION_STRING');
} else { } else {
$this->err('Unable to generate random hash for CAKE_SESSION_STRING, please change this yourself in ' . CONFIGS . 'core.php'); $this->err('Unable to generate random hash for CAKE_SESSION_STRING, please change this yourself in ' . CONFIGS . 'core.php');
} }
$corePath = $this->corePath($path); $corePath = $this->corePath($path);
if($corePath === true ){ if ($corePath === true ){
$this->out('CAKE_CORE_INCLUDE_PATH set to ' . CAKE_CORE_INCLUDE_PATH); $this->out('CAKE_CORE_INCLUDE_PATH set to ' . CAKE_CORE_INCLUDE_PATH);
} else if($corePath === false){ } elseif ($corePath === false){
$this->err('Unable to to set CAKE_CORE_INCLUDE_PATH, please change this yourself in ' . $path . 'webroot' .DS .'index.php'); $this->err('Unable to to set CAKE_CORE_INCLUDE_PATH, please change this yourself in ' . $path . 'webroot' .DS .'index.php');
} }
if($Folder->chmod($path . DS . 'tmp', 0777) === false) { if ($Folder->chmod($path . DS . 'tmp', 0777) === false) {
$this->err('Could path set permissions on '. $project . DS .'tmp' . DS . '*'); $this->err('Could path set permissions on '. $project . DS .'tmp' . DS . '*');
$this->out('You must manually check that these directories can be wrote to by the server'); $this->out('You must manually check that these directories can be wrote to by the server');
} }
@ -171,8 +171,8 @@ class ProjectTask extends Shell {
$this->err(" '".$app."' could not be created properly"); $this->err(" '".$app."' could not be created properly");
} }
if($verbose) { if ($verbose) {
foreach($Folder->messages() as $message) { foreach ($Folder->messages() as $message) {
$this->out($message); $this->out($message);
} }
} }
@ -207,7 +207,7 @@ class ProjectTask extends Shell {
uses('Security'); uses('Security');
$string = Security::generateAuthKey(); $string = Security::generateAuthKey();
$result = str_replace($match[0], 'define(\'CAKE_SESSION_STRING\', \''.$string.'\');', $contents); $result = str_replace($match[0], 'define(\'CAKE_SESSION_STRING\', \''.$string.'\');', $contents);
if($File->write($result)){ if ($File->write($result)){
return true; return true;
} else { } else {
return false; return false;
@ -222,12 +222,12 @@ class ProjectTask extends Shell {
* @return bool * @return bool
*/ */
function corePath($path){ function corePath($path){
if(dirname($path) !== CAKE_CORE_INCLUDE_PATH) { if (dirname($path) !== CAKE_CORE_INCLUDE_PATH) {
$File =& new File($path . 'webroot' . DS . 'index.php'); $File =& new File($path . 'webroot' . DS . 'index.php');
$contents = $File->read(); $contents = $File->read();
if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) { if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
$result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '".CAKE_CORE_INCLUDE_PATH."');", $contents); $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '".CAKE_CORE_INCLUDE_PATH."');", $contents);
if($File->write($result)){ if ($File->write($result)){
return true; return true;
} else { } else {
return false; return false;
@ -247,7 +247,7 @@ class ProjectTask extends Shell {
$contents = $File->read(); $contents = $File->read();
if (preg_match('%([/\\t\\x20]*define\\(\'CAKE_ADMIN\',[\\t\\x20\'a-z]*\\);)%', $contents, $match)) { if (preg_match('%([/\\t\\x20]*define\\(\'CAKE_ADMIN\',[\\t\\x20\'a-z]*\\);)%', $contents, $match)) {
$result = str_replace($match[0], 'define(\'CAKE_ADMIN\', \''.$name.'\');', $contents); $result = str_replace($match[0], 'define(\'CAKE_ADMIN\', \''.$name.'\');', $contents);
if($File->write($result)){ if ($File->write($result)){
return true; return true;
} else { } else {
return false; return false;

View file

@ -75,48 +75,48 @@ class ViewTask extends Shell {
* @return void * @return void
*/ */
function execute() { function execute() {
if(empty($this->args)) { if (empty($this->args)) {
$this->__interactive(); $this->__interactive();
} }
$controller = $action = $alias = null; $controller = $action = $alias = null;
if(isset($this->args[0])) { if (isset($this->args[0])) {
$this->controllerName = Inflector::camelize($this->args[0]); $this->controllerName = Inflector::camelize($this->args[0]);
$this->controllerPath = Inflector::underscore($this->controllerName); $this->controllerPath = Inflector::underscore($this->controllerName);
} }
if(isset($this->args[1])) { if (isset($this->args[1])) {
$this->template = $this->args[1]; $this->template = $this->args[1];
} }
if(isset($this->args[2])) { if (isset($this->args[2])) {
$action = $this->args[2]; $action = $this->args[2];
} }
if(!$action) { if (!$action) {
$action = $this->template; $action = $this->template;
} }
if(in_array($action, $this->scaffoldActions)) { if (in_array($action, $this->scaffoldActions)) {
$this->bake($action, true); $this->bake($action, true);
} else if($action) { } elseif ($action) {
$this->bake($action, true); $this->bake($action, true);
} else { } else {
$vars = $this->__loadController(); $vars = $this->__loadController();
if($vars) { if ($vars) {
$protected = array( 'object', low($this->controllerName. 'Controller'), 'controller', 'appcontroller', $protected = array( 'object', low($this->controllerName. 'Controller'), 'controller', 'appcontroller',
'tostring', 'requestaction', 'log', 'cakeerror', 'constructclasses', 'redirect', 'set', 'setaction', 'tostring', 'requestaction', 'log', 'cakeerror', 'constructclasses', 'redirect', 'set', 'setaction',
'validate', 'validateerrors', 'render', 'referer', 'flash', 'flashout', 'generatefieldnames', 'validate', 'validateerrors', 'render', 'referer', 'flash', 'flashout', 'generatefieldnames',
'postconditions', 'cleanupfields', 'beforefilter', 'beforerender', 'afterfilter', 'disablecache', 'paginate'); 'postconditions', 'cleanupfields', 'beforefilter', 'beforerender', 'afterfilter', 'disablecache', 'paginate');
$classVars = get_class_vars($this->controllerName . 'Controller'); $classVars = get_class_vars($this->controllerName . 'Controller');
if(array_key_exists('scaffold', $classVars)) { if (array_key_exists('scaffold', $classVars)) {
$methods = $this->scaffoldActions; $methods = $this->scaffoldActions;
} else { } else {
$methods = get_class_methods($this->controllerName . 'Controller'); $methods = get_class_methods($this->controllerName . 'Controller');
} }
foreach($methods as $method) { foreach ($methods as $method) {
if($method{0} != '_' && !in_array(low($method), am($protected, array('delete', CAKE_ADMIN.'_delete')))) { if ($method{0} != '_' && !in_array(low($method), am($protected, array('delete', CAKE_ADMIN.'_delete')))) {
$content = $this->getContent($method, $vars); $content = $this->getContent($method, $vars);
$this->bake($method, $content); $this->bake($method, $content);
} }
@ -153,7 +153,7 @@ class ViewTask extends Shell {
$admin = ''; $admin = '';
if ((low($wannaDoAdmin) == 'y' || low($wannaDoAdmin) == 'yes')) { if ((low($wannaDoAdmin) == 'y' || low($wannaDoAdmin) == 'yes')) {
if(defined('CAKE_ADMIN')) { if (defined('CAKE_ADMIN')) {
$admin = CAKE_ADMIN . '_'; $admin = CAKE_ADMIN . '_';
} else { } else {
$this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.'); $this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
@ -162,7 +162,7 @@ class ViewTask extends Shell {
while ($admin == '') { while ($admin == '') {
$admin = $this->in("What would you like the admin route to be?", null, 'admin'); $admin = $this->in("What would you like the admin route to be?", null, 'admin');
} }
if($this->Project->cakeAdmin($admin) !== true){ if ($this->Project->cakeAdmin($admin) !== true){
$this->err('Unable to write to /app/config/core.php.'); $this->err('Unable to write to /app/config/core.php.');
$this->err('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.'); $this->err('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
exit(); exit();
@ -174,14 +174,14 @@ class ViewTask extends Shell {
if (low($wannaDoScaffold) == 'y' || low($wannaDoScaffold) == 'yes') { if (low($wannaDoScaffold) == 'y' || low($wannaDoScaffold) == 'yes') {
$file = CONTROLLERS . $this->controllerPath . '_controller.php'; $file = CONTROLLERS . $this->controllerPath . '_controller.php';
if($admin) { if ($admin) {
foreach($this->scaffoldActions as $action) { foreach ($this->scaffoldActions as $action) {
$this->scaffoldActions[] = $admin . $action; $this->scaffoldActions[] = $admin . $action;
} }
} }
$vars = $this->__loadController(); $vars = $this->__loadController();
if($vars) { if ($vars) {
foreach($this->scaffoldActions as $action) { foreach ($this->scaffoldActions as $action) {
$content = $this->getContent($action, $vars); $content = $this->getContent($action, $vars);
$this->bake($action, $content); $this->bake($action, $content);
} }
@ -226,11 +226,11 @@ class ViewTask extends Shell {
* @return array Returns an variables to be made available to a view template * @return array Returns an variables to be made available to a view template
*/ */
function __loadController() { function __loadController() {
if(!$this->controllerName) { if (!$this->controllerName) {
$this->err('could not find the controller'); $this->err('could not find the controller');
} }
if(!loadController($this->controllerName)) { if (!loadController($this->controllerName)) {
$file = CONTROLLERS . $this->controllerPath . '_controller.php'; $file = CONTROLLERS . $this->controllerPath . '_controller.php';
$shortPath = $this->shortPath($file); $shortPath = $this->shortPath($file);
$this->err("The file '{$shortPath}' could not be found.\nIn order to bake a view, you'll need to first create the controller."); $this->err("The file '{$shortPath}' could not be found.\nIn order to bake a view, you'll need to first create the controller.");
@ -268,17 +268,17 @@ class ViewTask extends Shell {
* @return bool * @return bool
*/ */
function bake($action, $content = '') { function bake($action, $content = '') {
if($content === true) { if ($content === true) {
$content = $this->getContent(); $content = $this->getContent();
} }
$filename = VIEWS . $this->controllerPath . DS . Inflector::underscore($action) . '.ctp'; $filename = VIEWS . $this->controllerPath . DS . Inflector::underscore($action) . '.ctp';
$Folder =& new Folder(VIEWS . $this->controllerPath, true); $Folder =& new Folder(VIEWS . $this->controllerPath, true);
$errors = $Folder->errors(); $errors = $Folder->errors();
if(empty($errors)) { if (empty($errors)) {
$path = $Folder->slashTerm($Folder->pwd()); $path = $Folder->slashTerm($Folder->pwd());
return $this->createFile($filename, $content); return $this->createFile($filename, $content);
} else { } else {
foreach($errors as $error) { foreach ($errors as $error) {
$this->err($error); $this->err($error);
} }
} }
@ -292,32 +292,32 @@ class ViewTask extends Shell {
* @return string content from template * @return string content from template
*/ */
function getContent($template = null, $vars = null) { function getContent($template = null, $vars = null) {
if(!$template) { if (!$template) {
$template = $this->template; $template = $this->template;
} }
$action = $template; $action = $template;
if(strpos($template, CAKE_ADMIN) !== false) { if (strpos($template, CAKE_ADMIN) !== false) {
$template = str_replace(CAKE_ADMIN.'_', '', $template); $template = str_replace(CAKE_ADMIN.'_', '', $template);
} }
if(in_array($template, array('add', 'edit'))) { if (in_array($template, array('add', 'edit'))) {
$action = $template; $action = $template;
$template = 'form'; $template = 'form';
} }
$loaded = false; $loaded = false;
foreach($this->Dispatch->shellPaths as $path) { foreach ($this->Dispatch->shellPaths as $path) {
$templatePath = $path . 'templates' . DS . 'views' . DS .Inflector::underscore($template).'.ctp'; $templatePath = $path . 'templates' . DS . 'views' . DS .Inflector::underscore($template).'.ctp';
if (file_exists($templatePath) && is_file($templatePath)) { if (file_exists($templatePath) && is_file($templatePath)) {
$loaded = true; $loaded = true;
break; break;
} }
} }
if(!$vars) { if (!$vars) {
$vars = $this->__loadController(); $vars = $this->__loadController();
} }
if($loaded) { if ($loaded) {
extract($vars); extract($vars);
ob_start(); ob_start();
ob_implicit_flush(0); ob_implicit_flush(0);

View file

@ -45,7 +45,7 @@
</div> </div>
<div id="content"> <div id="content">
<?php <?php
if($session->check('Message.flash')): if ($session->check('Message.flash')):
$session->flash(); $session->flash();
endif; endif;
?> ?>

View file

@ -30,7 +30,7 @@
<title><?php echo $page_title?></title> <title><?php echo $page_title?></title>
<?php echo $html->charset(); ?> <?php echo $html->charset(); ?>
<?php if(Configure::read() == 0) { ?> <?php if (Configure::read() == 0) { ?>
<meta http-equiv="Refresh" content="<?php echo $pause?>;url=<?php echo $url?>"/> <meta http-equiv="Refresh" content="<?php echo $pause?>;url=<?php echo $url?>"/>
<?php } ?> <?php } ?>
<style><!-- <style><!--

View file

@ -33,7 +33,7 @@
$file = $_GET['file']; $file = $_GET['file'];
$pos = strpos($file, '..'); $pos = strpos($file, '..');
if ($pos === false) { if ($pos === false) {
if(is_file('../../vendors/javascript/'.$file) && (preg_match('/(\/.+)\\.js/', $file))) if (is_file('../../vendors/javascript/'.$file) && (preg_match('/(\/.+)\\.js/', $file)))
{ {
readfile('../../vendors/javascript/'.$file); readfile('../../vendors/javascript/'.$file);
} }

View file

@ -63,7 +63,7 @@ require_once CORE_PATH . 'cake' . DS . 'bootstrap.php';
require_once CAKE . 'basics.php'; require_once CAKE . 'basics.php';
require_once CAKE . 'config' . DS . 'paths.php'; require_once CAKE . 'config' . DS . 'paths.php';
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php'; require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php';
if(DEBUG < 1) { if (DEBUG < 1) {
die('Invalid url.'); die('Invalid url.');
} }
@ -85,13 +85,13 @@ if (!defined('BASE_URL')){
define('CAKE_TEST_OUTPUT_HTML',1); define('CAKE_TEST_OUTPUT_HTML',1);
define('CAKE_TEST_OUTPUT_TEXT',2); define('CAKE_TEST_OUTPUT_TEXT',2);
if(isset($_GET['output']) && $_GET['output'] == 'html') { if (isset($_GET['output']) && $_GET['output'] == 'html') {
define('CAKE_TEST_OUTPUT', CAKE_TEST_OUTPUT_HTML); define('CAKE_TEST_OUTPUT', CAKE_TEST_OUTPUT_HTML);
} else { } else {
define('CAKE_TEST_OUTPUT', CAKE_TEST_OUTPUT_TEXT); define('CAKE_TEST_OUTPUT', CAKE_TEST_OUTPUT_TEXT);
} }
if(!vendor('simpletest' . DS . 'reporter')) { if (!vendor('simpletest' . DS . 'reporter')) {
CakePHPTestHeader(); CakePHPTestHeader();
include CAKE . 'tests' . DS . 'lib' . DS . 'simpletest.php'; include CAKE . 'tests' . DS . 'lib' . DS . 'simpletest.php';
CakePHPTestSuiteFooter(); CakePHPTestSuiteFooter();
@ -118,14 +118,14 @@ if(!vendor('simpletest' . DS . 'reporter')) {
switch (CAKE_TEST_OUTPUT) { switch (CAKE_TEST_OUTPUT) {
case CAKE_TEST_OUTPUT_HTML: case CAKE_TEST_OUTPUT_HTML:
if (isset($_GET['group'])) { if (isset($_GET['group'])) {
if(isset($_GET['app'])) { if (isset($_GET['app'])) {
$show = '?show=groups&amp;app=true'; $show = '?show=groups&amp;app=true';
} else { } else {
$show = '?show=groups'; $show = '?show=groups';
} }
} }
if (isset($_GET['case'])) { if (isset($_GET['case'])) {
if(isset($_GET['app'])) { if (isset($_GET['app'])) {
$show = '??show=cases&amp;app=truee'; $show = '??show=cases&amp;app=truee';
} else { } else {
$show = '?show=cases'; $show = '?show=cases';

View file

@ -30,14 +30,14 @@
<legend><?php echo "<?php __('".Inflector::humanize($action)."', true);?> <?php __('{$singularHumanName}');?>";?></legend> <legend><?php echo "<?php __('".Inflector::humanize($action)."', true);?> <?php __('{$singularHumanName}');?>";?></legend>
<?php <?php
echo "\t<?php\n"; echo "\t<?php\n";
foreach($fields as $field) { foreach ($fields as $field) {
if($action == 'add' && $field['name'] == $primaryKey) { if ($action == 'add' && $field['name'] == $primaryKey) {
continue; continue;
} else if(!in_array($field['name'], array('created', 'modified', 'updated'))){ } elseif (!in_array($field['name'], array('created', 'modified', 'updated'))){
echo "\t\techo \$form->input('{$field['name']}');\n"; echo "\t\techo \$form->input('{$field['name']}');\n";
} }
} }
foreach($hasAndBelongsToMany as $assocName => $assocData) { foreach ($hasAndBelongsToMany as $assocName => $assocData) {
echo "\t\techo \$form->input('{$assocName}');\n"; echo "\t\techo \$form->input('{$assocName}');\n";
} }
echo "\t?>\n"; echo "\t?>\n";
@ -49,14 +49,14 @@
</div> </div>
<div class="actions"> <div class="actions">
<ul> <ul>
<?php if($action != 'add'):?> <?php if ($action != 'add'):?>
<li><?php echo "<?php echo \$html->link(__('Delete', true), array('action'=>'delete', \$form->value('{$modelClass}.{$primaryKey}')), null, __('Are you sure you want to delete', true).' #' . \$form->value('{$modelClass}.{$primaryKey}')); ?>";?></li> <li><?php echo "<?php echo \$html->link(__('Delete', true), array('action'=>'delete', \$form->value('{$modelClass}.{$primaryKey}')), null, __('Are you sure you want to delete', true).' #' . \$form->value('{$modelClass}.{$primaryKey}')); ?>";?></li>
<?php endif;?> <?php endif;?>
<li><?php echo "<?php echo \$html->link(__('List', true).' '.__('{$pluralHumanName}', true), array('action'=>'index'));?>";?></li> <li><?php echo "<?php echo \$html->link(__('List', true).' '.__('{$pluralHumanName}', true), array('action'=>'index'));?>";?></li>
<?php <?php
foreach($foreignKeys as $field => $value) { foreach ($foreignKeys as $field => $value) {
$otherModelClass = $value['1']; $otherModelClass = $value['1'];
if($otherModelClass != $modelClass) { if ($otherModelClass != $modelClass) {
$otherModelKey = Inflector::underscore($otherModelClass); $otherModelKey = Inflector::underscore($otherModelClass);
$otherControllerName = Inflector::pluralize($otherModelClass); $otherControllerName = Inflector::pluralize($otherModelClass);
$otherControllerPath = Inflector::underscore($otherControllerName); $otherControllerPath = Inflector::underscore($otherControllerName);

View file

@ -6,7 +6,7 @@ $output .="
<span class=\"notice\"> <span class=\"notice\">
<?php <?php
__('Your tmp directory is '); __('Your tmp directory is ');
if(is_writable(TMP)): if (is_writable(TMP)):
__('writable.'); __('writable.');
else: else:
__('NOT writable.'); __('NOT writable.');
@ -34,7 +34,7 @@ $output .="
else: else:
__('NOT working.'); __('NOT working.');
echo '<br />'; echo '<br />';
if(is_writable(TMP)): if (is_writable(TMP)):
__('Edit: config/core.php to insure you have the newset version of this file and the variable \$cakeCache set properly'); __('Edit: config/core.php to insure you have the newset version of this file and the variable \$cakeCache set properly');
endif; endif;
endif; endif;
@ -46,7 +46,7 @@ $output .="
<?php <?php
__('Your database configuration file is '); __('Your database configuration file is ');
\$filePresent = null; \$filePresent = null;
if(file_exists(CONFIGS.'database.php')): if (file_exists(CONFIGS.'database.php')):
__('present.'); __('present.');
\$filePresent = true; \$filePresent = true;
else: else:
@ -67,7 +67,7 @@ if (!empty(\$filePresent)):
<span class=\"notice\"> <span class=\"notice\">
<?php <?php
__('Cake'); __('Cake');
if(\$connected->isConnected()): if (\$connected->isConnected()):
__(' is able to '); __(' is able to ');
else: else:
__(' is NOT able to '); __(' is NOT able to ');

View file

@ -28,7 +28,7 @@
<h2><?php echo "<?php __('{$pluralHumanName}');?>";?></h2> <h2><?php echo "<?php __('{$pluralHumanName}');?>";?></h2>
<table cellpadding="0" cellspacing="0"> <table cellpadding="0" cellspacing="0">
<tr> <tr>
<?php foreach($fields as $field):?> <?php foreach ($fields as $field):?>
<th><?php echo "<?php echo \$paginator->sort('{$field['name']}');?>";?></th> <th><?php echo "<?php echo \$paginator->sort('{$field['name']}');?>";?></th>
<?php endforeach;?> <?php endforeach;?>
<th class="actions"><?php echo "<?php __('Actions');?>";?></th> <th class="actions"><?php echo "<?php __('Actions');?>";?></th>
@ -36,21 +36,21 @@
<?php <?php
echo "<?php echo "<?php
\$i = 0; \$i = 0;
foreach(\${$pluralVar} as \${$singularVar}): foreach (\${$pluralVar} as \${$singularVar}):
\$class = null; \$class = null;
if(\$i++ % 2 == 0) { if (\$i++ % 2 == 0) {
\$class = ' class=\"altrow\"'; \$class = ' class=\"altrow\"';
} }
?>\n"; ?>\n";
echo "\t<tr<?php echo \$class;?>>\n"; echo "\t<tr<?php echo \$class;?>>\n";
foreach($fields as $field) { foreach ($fields as $field) {
if(in_array($field['name'], array_keys($foreignKeys))) { if (in_array($field['name'], array_keys($foreignKeys))) {
$otherModelClass = $foreignKeys[$field['name']][1]; $otherModelClass = $foreignKeys[$field['name']][1];
$otherModelKey = Inflector::underscore($otherModelClass); $otherModelKey = Inflector::underscore($otherModelClass);
$otherControllerName = Inflector::pluralize($otherModelClass); $otherControllerName = Inflector::pluralize($otherModelClass);
$otherControllerPath = Inflector::underscore($otherControllerName); $otherControllerPath = Inflector::underscore($otherControllerName);
if(isset($foreignKeys[$field['name']][2])) { if (isset($foreignKeys[$field['name']][2])) {
$otherModelClass = $foreignKeys[$field['name']][2]; $otherModelClass = $foreignKeys[$field['name']][2];
} }
$otherVariableName = Inflector::variable($otherModelClass); $otherVariableName = Inflector::variable($otherModelClass);
@ -83,9 +83,9 @@ echo "<?php endforeach; ?>\n";
<ul> <ul>
<li><?php echo "<?php echo \$html->link(__('New', true).' '.__('{$singularHumanName}', true), array('action'=>'add')); ?>";?></li> <li><?php echo "<?php echo \$html->link(__('New', true).' '.__('{$singularHumanName}', true), array('action'=>'add')); ?>";?></li>
<?php <?php
foreach($foreignKeys as $field => $value) { foreach ($foreignKeys as $field => $value) {
$otherModelClass = $value['1']; $otherModelClass = $value['1'];
if($otherModelClass != $modelClass) { if ($otherModelClass != $modelClass) {
$otherModelKey = Inflector::underscore($otherModelClass); $otherModelKey = Inflector::underscore($otherModelClass);
$otherControllerName = Inflector::pluralize($otherModelClass); $otherControllerName = Inflector::pluralize($otherModelClass);
$otherControllerPath = Inflector::underscore($otherControllerName); $otherControllerPath = Inflector::underscore($otherControllerName);

View file

@ -29,18 +29,18 @@
<dl> <dl>
<?php <?php
$i = 0; $i = 0;
foreach($fields as $field) { foreach ($fields as $field) {
$class = null; $class = null;
if($i++ % 2 == 0) { if ($i++ % 2 == 0) {
$class = ' class="altrow"'; $class = ' class="altrow"';
} }
if(in_array($field['name'], array_keys($foreignKeys))) { if (in_array($field['name'], array_keys($foreignKeys))) {
$otherModelClass = $foreignKeys[$field['name']][1]; $otherModelClass = $foreignKeys[$field['name']][1];
$otherModelKey = Inflector::underscore($otherModelClass); $otherModelKey = Inflector::underscore($otherModelClass);
$otherControllerName = Inflector::pluralize($otherModelClass); $otherControllerName = Inflector::pluralize($otherModelClass);
$otherControllerPath = Inflector::underscore($otherControllerName); $otherControllerPath = Inflector::underscore($otherControllerName);
if(isset($foreignKeys[$field['name']][2])) { if (isset($foreignKeys[$field['name']][2])) {
$otherModelClass = $foreignKeys[$field['name']][2]; $otherModelClass = $foreignKeys[$field['name']][2];
} }
$otherSingularVar = Inflector::variable($otherModelClass); $otherSingularVar = Inflector::variable($otherModelClass);
@ -65,9 +65,9 @@ foreach($fields as $field) {
echo "\t\t<li><?php echo \$html->link(__('List', true).' '.__('{$pluralHumanName}', true), array('action'=>'index')); ?> </li>\n"; echo "\t\t<li><?php echo \$html->link(__('List', true).' '.__('{$pluralHumanName}', true), array('action'=>'index')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('New', true).' '.__('{$singularHumanName}', true), array('action'=>'add')); ?> </li>\n"; echo "\t\t<li><?php echo \$html->link(__('New', true).' '.__('{$singularHumanName}', true), array('action'=>'add')); ?> </li>\n";
foreach($foreignKeys as $field => $value) { foreach ($foreignKeys as $field => $value) {
$otherModelClass = $value['1']; $otherModelClass = $value['1'];
if($otherModelClass != $modelClass) { if ($otherModelClass != $modelClass) {
$otherModelKey = Inflector::underscore($otherModelClass); $otherModelKey = Inflector::underscore($otherModelClass);
$otherControllerName = Inflector::pluralize($otherModelClass); $otherControllerName = Inflector::pluralize($otherModelClass);
$otherControllerPath = Inflector::underscore($otherControllerName); $otherControllerPath = Inflector::underscore($otherControllerName);
@ -96,13 +96,13 @@ foreach ($hasOne as $assocName => $assocData):
?> ?>
<div class="related"> <div class="related">
<h3><?php echo "<?php __('Related');?> <?php __('{$otherSingularHumanName}');?>";?></h3> <h3><?php echo "<?php __('Related');?> <?php __('{$otherSingularHumanName}');?>";?></h3>
<?php echo "<?php if(!empty(\${$singularVar}['{$assocName}'])):?>\n";?> <?php echo "<?php if (!empty(\${$singularVar}['{$assocName}'])):?>\n";?>
<dl> <dl>
<?php <?php
$i = 0; $i = 0;
foreach($otherFields as $field) { foreach ($otherFields as $field) {
$class = null; $class = null;
if($i++ % 2 == 0) { if ($i++ % 2 == 0) {
$class = ' class="altrow"'; $class = ' class="altrow"';
} }
@ -124,7 +124,7 @@ endforeach;
$relations = array_merge($hasMany, $hasAndBelongsToMany); $relations = array_merge($hasMany, $hasAndBelongsToMany);
$i = 0; $i = 0;
foreach($relations as $assocName => $assocData): foreach ($relations as $assocName => $assocData):
$otherModelKey = Inflector::underscore($assocData['className']); $otherModelKey = Inflector::underscore($assocData['className']);
$otherModelObj =& ClassRegistry::getObject($otherModelKey); $otherModelObj =& ClassRegistry::getObject($otherModelKey);
$otherControllerPath = Inflector::pluralize($otherModelKey); $otherControllerPath = Inflector::pluralize($otherModelKey);
@ -138,11 +138,11 @@ foreach($relations as $assocName => $assocData):
?> ?>
<div class="related"> <div class="related">
<h3><?php echo "<?php __('Related');?> <?php __('{$otherPluralHumanName}');?>";?></h3> <h3><?php echo "<?php __('Related');?> <?php __('{$otherPluralHumanName}');?>";?></h3>
<?php echo "<?php if(!empty(\${$singularVar}['{$assocName}'])):?>\n";?> <?php echo "<?php if (!empty(\${$singularVar}['{$assocName}'])):?>\n";?>
<table cellpadding = "0" cellspacing = "0"> <table cellpadding = "0" cellspacing = "0">
<tr> <tr>
<?php <?php
foreach($otherFields as $field) { foreach ($otherFields as $field) {
echo "\t\t<th>".Inflector::humanize($field['name'])."</th>\n"; echo "\t\t<th>".Inflector::humanize($field['name'])."</th>\n";
} }
?> ?>
@ -151,15 +151,15 @@ foreach($relations as $assocName => $assocData):
<?php <?php
echo "\t<?php echo "\t<?php
\$i = 0; \$i = 0;
foreach(\${$singularVar}['{$assocName}'] as \${$otherSingularVar}): foreach (\${$singularVar}['{$assocName}'] as \${$otherSingularVar}):
\$class = null; \$class = null;
if(\$i++ % 2 == 0) { if (\$i++ % 2 == 0) {
\$class = ' class=\"altrow\"'; \$class = ' class=\"altrow\"';
} }
?>\n"; ?>\n";
echo "\t\t<tr<?php echo \$class;?>>\n"; echo "\t\t<tr<?php echo \$class;?>>\n";
foreach($otherFields as $field) { foreach ($otherFields as $field) {
echo "\t\t\t<td><?php echo \${$otherSingularVar}['{$field['name']}'];?></td>\n"; echo "\t\t\t<td><?php echo \${$otherSingularVar}['{$field['name']}'];?></td>\n";
} }

View file

@ -111,14 +111,14 @@ class Dispatcher extends Object {
if (!loadController($ctrlName)) { if (!loadController($ctrlName)) {
$pluginName = Inflector::camelize($params['action']); $pluginName = Inflector::camelize($params['action']);
if (!loadController($ctrlName . '.' . $pluginName)) { if (!loadController($ctrlName . '.' . $pluginName)) {
if(preg_match('/([\\.]+)/', $ctrlName)) { if (preg_match('/([\\.]+)/', $ctrlName)) {
Router::setRequestInfo(array($params, array('base' => $this->base, 'webroot' => $this->webroot))); Router::setRequestInfo(array($params, array('base' => $this->base, 'webroot' => $this->webroot)));
return $this->cakeError('error404', return $this->cakeError('error404',
array(array('url' => strtolower($ctrlName), array(array('url' => strtolower($ctrlName),
'message' => 'Was not found on this server', 'message' => 'Was not found on this server',
'base' => $this->base))); 'base' => $this->base)));
} elseif(!class_exists($ctrlClass)) { } elseif (!class_exists($ctrlClass)) {
$missingController = true; $missingController = true;
} else { } else {
$params['plugin'] = null; $params['plugin'] = null;
@ -133,7 +133,7 @@ class Dispatcher extends Object {
} }
} }
if(isset($params['plugin'])) { if (isset($params['plugin'])) {
$plugin = $params['plugin']; $plugin = $params['plugin'];
$pluginName = Inflector::camelize($params['action']); $pluginName = Inflector::camelize($params['action']);
$pluginClass = $pluginName.'Controller'; $pluginClass = $pluginName.'Controller';
@ -144,7 +144,7 @@ class Dispatcher extends Object {
loadPluginModels($plugin); loadPluginModels($plugin);
$this->base = $this->base.'/'.Inflector::underscore($ctrlName); $this->base = $this->base.'/'.Inflector::underscore($ctrlName);
if(empty($params['controller']) || !class_exists($pluginClass)) { if (empty($params['controller']) || !class_exists($pluginClass)) {
$params['controller'] = Inflector::underscore($ctrlName); $params['controller'] = Inflector::underscore($ctrlName);
$ctrlClass = $ctrlName.'Controller'; $ctrlClass = $ctrlName.'Controller';
if (!is_null($params['action'])) { if (!is_null($params['action'])) {
@ -158,8 +158,8 @@ class Dispatcher extends Object {
$params['action'] = 'index'; $params['action'] = 'index';
} }
if(defined('CAKE_ADMIN')) { if (defined('CAKE_ADMIN')) {
if(isset($params[CAKE_ADMIN])) { if (isset($params[CAKE_ADMIN])) {
$this->admin = '/'.CAKE_ADMIN ; $this->admin = '/'.CAKE_ADMIN ;
$url = preg_replace('/'.CAKE_ADMIN.'\/?/', '', $url); $url = preg_replace('/'.CAKE_ADMIN.'\/?/', '', $url);
$params['action'] = CAKE_ADMIN.'_'.$params['action']; $params['action'] = CAKE_ADMIN.'_'.$params['action'];
@ -168,7 +168,7 @@ class Dispatcher extends Object {
} }
} }
$base = Router::stripPlugin($this->base, $this->plugin); $base = Router::stripPlugin($this->base, $this->plugin);
if(defined('BASE_URL')) { if (defined('BASE_URL')) {
$this->here = $base . $this->admin . $url; $this->here = $base . $this->admin . $url;
} else { } else {
$this->here = $base . $this->admin . '/' . $url; $this->here = $base . $this->admin . '/' . $url;
@ -191,11 +191,11 @@ class Dispatcher extends Object {
$classMethods = get_class_methods($controller); $classMethods = get_class_methods($controller);
$classVars = get_object_vars($controller); $classVars = get_object_vars($controller);
if((in_array($params['action'], $classMethods) || in_array(strtolower($params['action']), $classMethods)) && strpos($params['action'], '_', 0) === 0) { if ((in_array($params['action'], $classMethods) || in_array(strtolower($params['action']), $classMethods)) && strpos($params['action'], '_', 0) === 0) {
$privateAction = true; $privateAction = true;
} }
if(!in_array($params['action'], $classMethods) && !in_array(strtolower($params['action']), $classMethods)) { if (!in_array($params['action'], $classMethods) && !in_array(strtolower($params['action']), $classMethods)) {
$missingAction = true; $missingAction = true;
} }
@ -206,7 +206,7 @@ class Dispatcher extends Object {
$missingAction = true; $missingAction = true;
} }
if(in_array('return', array_keys($params)) && $params['return'] == 1) { if (in_array('return', array_keys($params)) && $params['return'] == 1) {
$controller->autoRender = false; $controller->autoRender = false;
} }
@ -224,7 +224,7 @@ class Dispatcher extends Object {
$namedArgs = array(); $namedArgs = array();
if (is_array($controller->namedArgs)) { if (is_array($controller->namedArgs)) {
if(array_key_exists($params['action'], $controller->namedArgs)) { if (array_key_exists($params['action'], $controller->namedArgs)) {
$namedArgs = $controller->namedArgs[$params['action']]; $namedArgs = $controller->namedArgs[$params['action']];
} else { } else {
$namedArgs = $controller->namedArgs; $namedArgs = $controller->namedArgs;
@ -241,18 +241,18 @@ class Dispatcher extends Object {
for ($i = 0; $i <= $c; $i++) { for ($i = 0; $i <= $c; $i++) {
if (isset($controller->passedArgs[$i]) && strpos($controller->passedArgs[$i], $controller->argSeparator) !== false) { if (isset($controller->passedArgs[$i]) && strpos($controller->passedArgs[$i], $controller->argSeparator) !== false) {
list($argKey, $argVal) = explode($controller->argSeparator, $controller->passedArgs[$i]); list($argKey, $argVal) = explode($controller->argSeparator, $controller->passedArgs[$i]);
if(empty($namedArgs) || (!empty($namedArgs) && in_array($argKey, array_keys($namedArgs)))) { if (empty($namedArgs) || (!empty($namedArgs) && in_array($argKey, array_keys($namedArgs)))) {
$controller->passedArgs[$argKey] = $argVal; $controller->passedArgs[$argKey] = $argVal;
$controller->namedArgs[$argKey] = $argVal; $controller->namedArgs[$argKey] = $argVal;
unset($controller->passedArgs[$i]); unset($controller->passedArgs[$i]);
unset($params['pass'][$i]); unset($params['pass'][$i]);
} }
} else if($controller->argSeparator === '/') { } elseif ($controller->argSeparator === '/') {
$ii = $i + 1; $ii = $i + 1;
if(isset($controller->passedArgs[$i]) && isset($controller->passedArgs[$ii])) { if (isset($controller->passedArgs[$i]) && isset($controller->passedArgs[$ii])) {
$argKey = $controller->passedArgs[$i]; $argKey = $controller->passedArgs[$i];
$argVal = $controller->passedArgs[$ii]; $argVal = $controller->passedArgs[$ii];
if(empty($namedArgs) || (!empty($namedArgs) && in_array($argKey, array_keys($namedArgs)))) { if (empty($namedArgs) || (!empty($namedArgs) && in_array($argKey, array_keys($namedArgs)))) {
$controller->passedArgs[$argKey] = $argVal; $controller->passedArgs[$argKey] = $argVal;
$controller->namedArgs[$argKey] = $argVal; $controller->namedArgs[$argKey] = $argVal;
unset($controller->passedArgs[$i], $controller->passedArgs[$ii]); unset($controller->passedArgs[$i], $controller->passedArgs[$ii]);
@ -292,14 +292,14 @@ class Dispatcher extends Object {
$controller->layout = $params['layout']; $controller->layout = $params['layout'];
} }
} }
foreach(array('components', 'helpers') as $var) { foreach (array('components', 'helpers') as $var) {
if (isset($params[$var]) && !empty($params[$var]) && is_array($controller->{$var})) { if (isset($params[$var]) && !empty($params[$var]) && is_array($controller->{$var})) {
$diff = array_diff($params[$var], $controller->{$var}); $diff = array_diff($params[$var], $controller->{$var});
$controller->{$var} = array_merge($controller->{$var}, $diff); $controller->{$var} = array_merge($controller->{$var}, $diff);
} }
} }
if(!is_null($controller->webservices)) { if (!is_null($controller->webservices)) {
array_push($controller->components, $controller->webservices); array_push($controller->components, $controller->webservices);
array_push($controller->helpers, $controller->webservices); array_push($controller->helpers, $controller->webservices);
$component =& new Component($controller); $component =& new Component($controller);
@ -361,7 +361,7 @@ class Dispatcher extends Object {
} }
$controller->output =& $output; $controller->output =& $output;
foreach($controller->components as $c) { foreach ($controller->components as $c) {
$path = preg_split('/\/|\./', $c); $path = preg_split('/\/|\./', $c);
$c = $path[count($path) - 1]; $c = $path[count($path) - 1];
if (isset($controller->{$c}) && is_object($controller->{$c}) && is_callable(array($controller->{$c}, 'shutdown'))) { if (isset($controller->{$c}) && is_object($controller->{$c}) && is_callable(array($controller->{$c}, 'shutdown'))) {
@ -382,22 +382,22 @@ class Dispatcher extends Object {
*/ */
function start(&$controller) { function start(&$controller) {
if (!empty($controller->beforeFilter)) { if (!empty($controller->beforeFilter)) {
if(is_array($controller->beforeFilter)) { if (is_array($controller->beforeFilter)) {
foreach($controller->beforeFilter as $filter) { foreach ($controller->beforeFilter as $filter) {
if(is_callable(array($controller,$filter)) && $filter != 'beforeFilter') { if (is_callable(array($controller,$filter)) && $filter != 'beforeFilter') {
$controller->$filter(); $controller->$filter();
} }
} }
} else { } else {
if(is_callable(array($controller, $controller->beforeFilter)) && $controller->beforeFilter != 'beforeFilter') { if (is_callable(array($controller, $controller->beforeFilter)) && $controller->beforeFilter != 'beforeFilter') {
$controller->{$controller->beforeFilter}(); $controller->{$controller->beforeFilter}();
} }
} }
} }
$controller->beforeFilter(); $controller->beforeFilter();
foreach($controller->components as $c) { foreach ($controller->components as $c) {
$path = preg_split('/\/|\./', $c); $path = preg_split('/\/|\./', $c);
$c = $path[count($path) - 1]; $c = $path[count($path) - 1];
if (isset($controller->{$c}) && is_object($controller->{$c}) && is_callable(array($controller->{$c}, 'startup'))) { if (isset($controller->{$c}) && is_object($controller->{$c}) && is_callable(array($controller->{$c}, 'startup'))) {
@ -422,7 +422,7 @@ class Dispatcher extends Object {
$params = Router::parse($fromUrl); $params = Router::parse($fromUrl);
if (ini_get('magic_quotes_gpc') == 1) { if (ini_get('magic_quotes_gpc') == 1) {
if(!empty($_POST)) { if (!empty($_POST)) {
$params['form'] = stripslashes_deep($_POST); $params['form'] = stripslashes_deep($_POST);
} }
} else { } else {
@ -492,7 +492,7 @@ class Dispatcher extends Object {
if (preg_match('/^(.*)\/index\.php$/', $scriptName, $r)) { if (preg_match('/^(.*)\/index\.php$/', $scriptName, $r)) {
if(!empty($r[1])) { if (!empty($r[1])) {
return $base.$r[1]; return $base.$r[1];
} }
} }
@ -504,7 +504,7 @@ class Dispatcher extends Object {
if (preg_match('/^(.*)\\/'.$appDirName.'\\/'.$webrootDirName.'\\/index\\.php$/', $scriptName, $regs)) { if (preg_match('/^(.*)\\/'.$appDirName.'\\/'.$webrootDirName.'\\/index\\.php$/', $scriptName, $regs)) {
if(APP_DIR === 'app') { if (APP_DIR === 'app') {
$appDir = null; $appDir = null;
} else { } else {
$appDir = '/'.APP_DIR; $appDir = '/'.APP_DIR;
@ -533,7 +533,7 @@ class Dispatcher extends Object {
function _restructureParams($params) { function _restructureParams($params) {
$params['controller'] = $params['action']; $params['controller'] = $params['action'];
if(isset($params['pass'][0])) { if (isset($params['pass'][0])) {
$params['action'] = $params['pass'][0]; $params['action'] = $params['pass'][0];
array_shift($params['pass']); array_shift($params['pass']);
} else { } else {

View file

@ -28,16 +28,16 @@
/** /**
* Included libraries. * Included libraries.
*/ */
if(!class_exists('Object')) { if (!class_exists('Object')) {
uses('object'); uses('object');
} }
/** /**
* Set defines if not set in core.php * Set defines if not set in core.php
*/ */
if(!defined('CACHE_DEFAULT_DURATION')) { if (!defined('CACHE_DEFAULT_DURATION')) {
define('CACHE_DEFAULT_DURATION', 3600); define('CACHE_DEFAULT_DURATION', 3600);
} }
if(!defined('CACHE_GC_PROBABILITY')) { if (!defined('CACHE_GC_PROBABILITY')) {
define('CACHE_GC_PROBABILITY', 100); define('CACHE_GC_PROBABILITY', 100);
} }
/** /**
@ -67,7 +67,7 @@ class Cache extends Object {
*/ */
function &getInstance() { function &getInstance() {
static $instance = array(); static $instance = array();
if(!isset($instance[0]) || !$instance[0]) { if (!isset($instance[0]) || !$instance[0]) {
$instance[0] =& new Cache(); $instance[0] =& new Cache();
} }
return $instance[0]; return $instance[0];
@ -85,12 +85,12 @@ class Cache extends Object {
} }
$fileName = strtolower($name); $fileName = strtolower($name);
if(vendor('cache_engines/'.$fileName)) { if (vendor('cache_engines/'.$fileName)) {
return true; return true;
} }
$fileName = dirname(__FILE__) . DS . 'cache' . DS . $fileName . '.php'; $fileName = dirname(__FILE__) . DS . 'cache' . DS . $fileName . '.php';
if(is_readable($fileName)) { if (is_readable($fileName)) {
include $fileName; include $fileName;
return true; return true;
} }
@ -105,7 +105,7 @@ class Cache extends Object {
* @access public * @access public
*/ */
function engine($name = 'File', $params = array()) { function engine($name = 'File', $params = array()) {
if(defined('DISABLE_CACHE')) { if (defined('DISABLE_CACHE')) {
return false; return false;
} }
$_this =& Cache::getInstance(); $_this =& Cache::getInstance();
@ -117,7 +117,7 @@ class Cache extends Object {
$_this->_Engine =& new $cacheClass(); $_this->_Engine =& new $cacheClass();
if ($_this->_Engine->init($params)) { if ($_this->_Engine->init($params)) {
if(time() % CACHE_GC_PROBABILITY == 0) { if (time() % CACHE_GC_PROBABILITY == 0) {
$_this->_Engine->gc(); $_this->_Engine->gc();
} }
return true; return true;
@ -140,21 +140,21 @@ class Cache extends Object {
} }
$key = strval($key); $key = strval($key);
if(empty($key)) { if (empty($key)) {
return false; return false;
} }
if(is_resource($value)) { if (is_resource($value)) {
return false; return false;
} }
$duration = ife(is_string($duration), strtotime($duration), intval($duration)); $duration = ife(is_string($duration), strtotime($duration), intval($duration));
if($duration < 1) { if ($duration < 1) {
return false; return false;
} }
$_this =& Cache::getInstance(); $_this =& Cache::getInstance();
if(!isset($_this->_Engine)) { if (!isset($_this->_Engine)) {
return false; return false;
} }
return $_this->_Engine->write($key, $value, $duration); return $_this->_Engine->write($key, $value, $duration);
@ -167,18 +167,18 @@ class Cache extends Object {
* @access public * @access public
*/ */
function read($key) { function read($key) {
if(defined('DISABLE_CACHE')) { if (defined('DISABLE_CACHE')) {
return false; return false;
} }
$key = strval($key); $key = strval($key);
if(empty($key)) { if (empty($key)) {
return false; return false;
} }
$_this =& Cache::getInstance(); $_this =& Cache::getInstance();
if(!isset($_this->_Engine)) { if (!isset($_this->_Engine)) {
return false; return false;
} }
return $_this->_Engine->read($key); return $_this->_Engine->read($key);
@ -191,17 +191,17 @@ class Cache extends Object {
* @access public * @access public
*/ */
function delete($key) { function delete($key) {
if(defined('DISABLE_CACHE')) { if (defined('DISABLE_CACHE')) {
return false; return false;
} }
$key = strval($key); $key = strval($key);
if(empty($key)) { if (empty($key)) {
return false; return false;
} }
$_this =& Cache::getInstance(); $_this =& Cache::getInstance();
if(!isset($_this->_Engine)) { if (!isset($_this->_Engine)) {
return false; return false;
} }
return $_this->_Engine->delete($key); return $_this->_Engine->delete($key);
@ -213,12 +213,12 @@ class Cache extends Object {
* @access public * @access public
*/ */
function clear() { function clear() {
if(defined('DISABLE_CACHE')) { if (defined('DISABLE_CACHE')) {
return false; return false;
} }
$_this =& Cache::getInstance(); $_this =& Cache::getInstance();
if(!isset($_this->_Engine)) { if (!isset($_this->_Engine)) {
return false; return false;
} }
return $_this->_Engine->clear(); return $_this->_Engine->clear();
@ -230,7 +230,7 @@ class Cache extends Object {
* @access public * @access public
*/ */
function isInitialized() { function isInitialized() {
if(defined('DISABLE_CACHE')) { if (defined('DISABLE_CACHE')) {
return false; return false;
} }
$_this =& Cache::getInstance(); $_this =& Cache::getInstance();
@ -245,7 +245,7 @@ class Cache extends Object {
*/ */
function settings() { function settings() {
$_this =& Cache::getInstance(); $_this =& Cache::getInstance();
if(!is_null($_this->_Engine)) { if (!is_null($_this->_Engine)) {
return $_this->_Engine->settings(); return $_this->_Engine->settings();
} }
} }

View file

@ -82,7 +82,7 @@ class FileEngine extends CacheEngine {
$dir = $folder->slashTerm($dir); $dir = $folder->slashTerm($dir);
} }
if(empty($dir) || !$folder->isAbsolute($dir) || !is_writable($dir)) { if (empty($dir) || !$folder->isAbsolute($dir) || !is_writable($dir)) {
return false; return false;
} }
@ -113,7 +113,7 @@ class FileEngine extends CacheEngine {
function write($key, &$value, $duration = CACHE_DEFAULT_DURATION) { function write($key, &$value, $duration = CACHE_DEFAULT_DURATION) {
$serialized = serialize($value); $serialized = serialize($value);
if(!$serialized) { if (!$serialized) {
return false; return false;
} }
$expires = time() + $duration; $expires = time() + $duration;
@ -152,28 +152,28 @@ class FileEngine extends CacheEngine {
function read($key) { function read($key) {
$filename = $this->_getFilename($key); $filename = $this->_getFilename($key);
if(!is_file($filename) || !is_readable($filename)) { if (!is_file($filename) || !is_readable($filename)) {
return false; return false;
} }
$fp = fopen($filename, 'r'); $fp = fopen($filename, 'r');
if(!$fp) { if (!$fp) {
return false; return false;
} }
if($this->_lock && !flock($fp, LOCK_SH)) { if ($this->_lock && !flock($fp, LOCK_SH)) {
return false; return false;
} }
$expires = fgets($fp, 11); $expires = fgets($fp, 11);
if(intval($expires) < time()) { if (intval($expires) < time()) {
fclose($fp); fclose($fp);
unlink($filename); unlink($filename);
return false; return false;
} }
$data = ''; $data = '';
while(!feof($fp)) { while (!feof($fp)) {
$data .= fgets($fp, 4096); $data .= fgets($fp, 4096);
} }
$data = trim($data); $data = trim($data);
@ -189,11 +189,11 @@ class FileEngine extends CacheEngine {
function _getExpiry($filename) { function _getExpiry($filename) {
$fp = fopen($filename, 'r'); $fp = fopen($filename, 'r');
if(!$fp) { if (!$fp) {
return false; return false;
} }
if($this->_lock && !flock($fp, LOCK_SH)) { if ($this->_lock && !flock($fp, LOCK_SH)) {
return false; return false;
} }
$expires = intval(fgets($fp, 11)); $expires = intval(fgets($fp, 11));
@ -226,21 +226,21 @@ class FileEngine extends CacheEngine {
$threshold = $now - 86400; $threshold = $now - 86400;
} }
while(($entry = $dir->read()) !== false) { while (($entry = $dir->read()) !== false) {
if(strpos($entry, $this->_prefix) !== 0) { if (strpos($entry, $this->_prefix) !== 0) {
continue; continue;
} }
$filename = $this->_dir.$entry; $filename = $this->_dir.$entry;
if($checkExpiry) { if ($checkExpiry) {
$mtime = filemtime($filename); $mtime = filemtime($filename);
if($mtime === false || $mtime > $threshold) { if ($mtime === false || $mtime > $threshold) {
continue; continue;
} }
$expires = $this->_getExpiry($filename); $expires = $this->_getExpiry($filename);
if($expires > $now) { if ($expires > $now) {
continue; continue;
} }
} }
@ -257,7 +257,7 @@ class FileEngine extends CacheEngine {
*/ */
function settings() { function settings() {
$lock = 'false'; $lock = 'false';
if($this->_lock) { if ($this->_lock) {
$lock = 'true'; $lock = 'true';
} }
return array('class' => get_class($this), return array('class' => get_class($this),

View file

@ -56,31 +56,31 @@ class MemcacheEngine extends CacheEngine {
* @access public * @access public
*/ */
function init(&$params) { function init(&$params) {
if(!class_exists('Memcache')) { if (!class_exists('Memcache')) {
return false; return false;
} }
$servers = array('127.0.0.1'); $servers = array('127.0.0.1');
$compress = false; $compress = false;
extract($params); extract($params);
if($compress) { if ($compress) {
$this->_compress = MEMCACHE_COMPRESSED; $this->_compress = MEMCACHE_COMPRESSED;
} else { } else {
$this->_compress = 0; $this->_compress = 0;
} }
if(!is_array($servers)) { if (!is_array($servers)) {
$servers = array($servers); $servers = array($servers);
} }
$this->__Memcache =& new Memcache(); $this->__Memcache =& new Memcache();
$connected = false; $connected = false;
foreach($servers as $server) { foreach ($servers as $server) {
$parts = explode(':', $server); $parts = explode(':', $server);
$host = $parts[0]; $host = $parts[0];
$port = isset($parts[1]) ? $parts[1] : 11211; $port = isset($parts[1]) ? $parts[1] : 11211;
if($this->__Memcache->addServer($host, $port)) { if ($this->__Memcache->addServer($host, $port)) {
$connected = true; $connected = true;
} }
} }

View file

@ -72,7 +72,7 @@ class ModelEngine extends CacheEngine {
$expiryField = 'expires'; $expiryField = 'expires';
extract($params); extract($params);
if(!class_exists($modelName) && !loadModel($modelName)) { if (!class_exists($modelName) && !loadModel($modelName)) {
return false; return false;
} }
$this->_Model = new $modelName; $this->_Model = new $modelName;
@ -99,7 +99,7 @@ class ModelEngine extends CacheEngine {
function write($key, &$value, $duration = CACHE_DEFAULT_DURATION) { function write($key, &$value, $duration = CACHE_DEFAULT_DURATION) {
$serialized = serialize($value); $serialized = serialize($value);
if(!$serialized) { if (!$serialized) {
return false; return false;
} }
$data = array($this->_Model->name => array( $data = array($this->_Model->name => array(
@ -150,7 +150,7 @@ class ModelEngine extends CacheEngine {
*/ */
function settings() { function settings() {
$class = null; $class = null;
if(is_a($this->_Model, 'Model')) { if (is_a($this->_Model, 'Model')) {
$class = get_class($this->_Model); $class = get_class($this->_Model);
} }
return array('class' => get_class($this), return array('class' => get_class($this),

View file

@ -81,7 +81,7 @@ class XcacheEngine extends CacheEngine {
* @access public * @access public
*/ */
function read($key) { function read($key) {
if(xcache_isset($key)) { if (xcache_isset($key)) {
return xcache_get($key); return xcache_get($key);
} }
return false; return false;
@ -106,8 +106,8 @@ class XcacheEngine extends CacheEngine {
$result = true; $result = true;
$this->_phpAuth(); $this->_phpAuth();
for($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++) { for ($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++) {
if(!xcache_clear_cache(XC_TYPE_VAR, $i)) { if (!xcache_clear_cache(XC_TYPE_VAR, $i)) {
$result = false; $result = false;
break; break;
} }
@ -137,9 +137,9 @@ class XcacheEngine extends CacheEngine {
static $backup = array(); static $backup = array();
$keys = array('PHP_AUTH_USER', 'PHP_AUTH_PW'); $keys = array('PHP_AUTH_USER', 'PHP_AUTH_PW');
foreach($keys as $key) { foreach ($keys as $key) {
if($reverse) { if ($reverse) {
if(isset($backup[$key])) { if (isset($backup[$key])) {
$_SERVER[$key] = $backup[$key]; $_SERVER[$key] = $backup[$key];
unset($backup[$key]); unset($backup[$key]);
} else { } else {
@ -147,7 +147,7 @@ class XcacheEngine extends CacheEngine {
} }
} else { } else {
$value = env($key); $value = env($key);
if(!empty($value)) { if (!empty($value)) {
$backup[$key] = $value; $backup[$key] = $value;
} }
$varName = '_' . low($key); $varName = '_' . low($key);

View file

@ -101,7 +101,7 @@ class ClassRegistry {
function isKeySet($key) { function isKeySet($key) {
$_this =& ClassRegistry::getInstance(); $_this =& ClassRegistry::getInstance();
$key = Inflector::underscore($key); $key = Inflector::underscore($key);
if(array_key_exists($key, $_this->__objects)) { if (array_key_exists($key, $_this->__objects)) {
return true; return true;
} elseif (array_key_exists($key, $_this->__map)) { } elseif (array_key_exists($key, $_this->__map)) {
return true; return true;
@ -129,11 +129,11 @@ class ClassRegistry {
$_this =& ClassRegistry::getInstance(); $_this =& ClassRegistry::getInstance();
$key = Inflector::underscore($key); $key = Inflector::underscore($key);
if(isset($_this->__objects[$key])){ if (isset($_this->__objects[$key])){
return $_this->__objects[$key]; return $_this->__objects[$key];
} else { } else {
$key = $_this->__getMap($key); $key = $_this->__getMap($key);
if(isset($_this->__objects[$key])){ if (isset($_this->__objects[$key])){
return $_this->__objects[$key]; return $_this->__objects[$key];
} }
} }

View file

@ -114,19 +114,19 @@ class Configure extends Object {
function write($config, $value = null){ function write($config, $value = null){
$_this =& Configure::getInstance(); $_this =& Configure::getInstance();
if(!is_array($config) && $value !== null) { if (!is_array($config) && $value !== null) {
$name = $_this->__configVarNames($config); $name = $_this->__configVarNames($config);
if(count($name) > 1){ if (count($name) > 1){
$_this->{$name[0]}[$name[1]] = $value; $_this->{$name[0]}[$name[1]] = $value;
} else { } else {
$_this->{$name[0]} = $value; $_this->{$name[0]} = $value;
} }
} else { } else {
foreach($config as $names => $value){ foreach ($config as $names => $value){
$name = $_this->__configVarNames($names); $name = $_this->__configVarNames($names);
if(count($name) > 1){ if (count($name) > 1){
$_this->{$name[0]}[$name[1]] = $value; $_this->{$name[0]}[$name[1]] = $value;
} else { } else {
$_this->{$name[0]} = $value; $_this->{$name[0]} = $value;
@ -142,7 +142,7 @@ class Configure extends Object {
ini_set('display_errors', 1); ini_set('display_errors', 1);
} }
if(!class_exists('Debugger')) { if (!class_exists('Debugger')) {
require LIBS . 'debugger.php'; require LIBS . 'debugger.php';
} }
if (!class_exists('CakeLog')) { if (!class_exists('CakeLog')) {
@ -168,21 +168,21 @@ class Configure extends Object {
*/ */
function read($var = 'debug'){ function read($var = 'debug'){
$_this =& Configure::getInstance(); $_this =& Configure::getInstance();
if($var === 'debug') { if ($var === 'debug') {
if(!isset($_this->debug)){ if (!isset($_this->debug)){
$_this->debug = DEBUG; $_this->debug = DEBUG;
} }
return $_this->debug; return $_this->debug;
} }
$name = $_this->__configVarNames($var); $name = $_this->__configVarNames($var);
if(count($name) > 1){ if (count($name) > 1){
if(isset($_this->{$name[0]}[$name[1]])) { if (isset($_this->{$name[0]}[$name[1]])) {
return $_this->{$name[0]}[$name[1]]; return $_this->{$name[0]}[$name[1]];
} }
return null; return null;
} else { } else {
if(isset($_this->{$name[0]})) { if (isset($_this->{$name[0]})) {
return $_this->{$name[0]}; return $_this->{$name[0]};
} }
return null; return null;
@ -202,7 +202,7 @@ class Configure extends Object {
$_this =& Configure::getInstance(); $_this =& Configure::getInstance();
$name = $_this->__configVarNames($var); $name = $_this->__configVarNames($var);
if(count($name) > 1){ if (count($name) > 1){
unset($_this->{$name[0]}[$name[1]]); unset($_this->{$name[0]}[$name[1]]);
} else { } else {
unset($_this->{$name[0]}); unset($_this->{$name[0]});
@ -230,7 +230,7 @@ class Configure extends Object {
return false; return false;
} }
if(!isset($config)){ if (!isset($config)){
trigger_error(sprintf(__("Configure::load() - no variable \$config found in %s.php", true), $fileName), E_USER_WARNING); trigger_error(sprintf(__("Configure::load() - no variable \$config found in %s.php", true), $fileName), E_USER_WARNING);
return false; return false;
} }
@ -246,7 +246,7 @@ class Configure extends Object {
*/ */
function version() { function version() {
$_this =& Configure::getInstance(); $_this =& Configure::getInstance();
if(!isset($_this->Cake['version'])) { if (!isset($_this->Cake['version'])) {
require(CORE_PATH . 'cake' . DS . 'config' . DS . 'config.php'); require(CORE_PATH . 'cake' . DS . 'config' . DS . 'config.php');
$_this->write($config); $_this->write($config);
} }
@ -268,9 +268,9 @@ class Configure extends Object {
$content = ''; $content = '';
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
$content .= "\$config['$type']['$key']"; $content .= "\$config['$type']['$key']";
if(is_array($value)){ if (is_array($value)){
$content .= " = array("; $content .= " = array(";
foreach($value as $key1 => $value2){ foreach ($value as $key1 => $value2){
$value2 = addslashes($value2); $value2 = addslashes($value2);
$content .= "'$key1' => '$value2', "; $content .= "'$key1' => '$value2', ";
} }
@ -280,7 +280,7 @@ class Configure extends Object {
$content .= " = '$value';\n"; $content .= " = '$value';\n";
} }
} }
if(is_null($type)) { if (is_null($type)) {
$write = false; $write = false;
} }
$_this->__writeConfig($content, $name, $write); $_this->__writeConfig($content, $name, $write);
@ -304,16 +304,16 @@ class Configure extends Object {
} }
$cache = cache('persistent' . DS . $name . '.php', null, $expires); $cache = cache('persistent' . DS . $name . '.php', null, $expires);
if($cache === null){ if ($cache === null){
cache('persistent' . DS . $name . '.php', "<?php\n\$config = array();\n", $expires); cache('persistent' . DS . $name . '.php', "<?php\n\$config = array();\n", $expires);
} }
if($write === true){ if ($write === true){
if(!class_exists('File')){ if (!class_exists('File')){
uses('File'); uses('File');
} }
$fileClass = new File($file); $fileClass = new File($file);
if($fileClass->writable()) { if ($fileClass->writable()) {
$fileClass->append($content); $fileClass->append($content);
} }
} }
@ -345,7 +345,7 @@ class Configure extends Object {
$_this =& Configure::getInstance(); $_this =& Configure::getInstance();
$_this->modelPaths[] = MODELS; $_this->modelPaths[] = MODELS;
if (isset($modelPaths)) { if (isset($modelPaths)) {
foreach($modelPaths as $value) { foreach ($modelPaths as $value) {
$_this->modelPaths[] = $value; $_this->modelPaths[] = $value;
} }
} }
@ -360,7 +360,7 @@ class Configure extends Object {
$_this =& Configure::getInstance(); $_this =& Configure::getInstance();
$_this->viewPaths[] = VIEWS; $_this->viewPaths[] = VIEWS;
if (isset($viewPaths)) { if (isset($viewPaths)) {
foreach($viewPaths as $value) { foreach ($viewPaths as $value) {
$_this->viewPaths[] = $value; $_this->viewPaths[] = $value;
} }
} }
@ -375,7 +375,7 @@ class Configure extends Object {
$_this =& Configure::getInstance(); $_this =& Configure::getInstance();
$_this->controllerPaths[] = CONTROLLERS; $_this->controllerPaths[] = CONTROLLERS;
if (isset($controllerPaths)) { if (isset($controllerPaths)) {
foreach($controllerPaths as $value) { foreach ($controllerPaths as $value) {
$_this->controllerPaths[] = $value; $_this->controllerPaths[] = $value;
} }
} }
@ -390,7 +390,7 @@ class Configure extends Object {
$_this =& Configure::getInstance(); $_this =& Configure::getInstance();
$_this->helperPaths[] = HELPERS; $_this->helperPaths[] = HELPERS;
if (isset($helperPaths)) { if (isset($helperPaths)) {
foreach($helperPaths as $value) { foreach ($helperPaths as $value) {
$_this->helperPaths[] = $value; $_this->helperPaths[] = $value;
} }
} }
@ -405,7 +405,7 @@ class Configure extends Object {
$_this =& Configure::getInstance(); $_this =& Configure::getInstance();
$_this->componentPaths[] = COMPONENTS; $_this->componentPaths[] = COMPONENTS;
if (isset($componentPaths)) { if (isset($componentPaths)) {
foreach($componentPaths as $value) { foreach ($componentPaths as $value) {
$_this->componentPaths[] = $value; $_this->componentPaths[] = $value;
} }
} }
@ -420,7 +420,7 @@ class Configure extends Object {
$_this =& Configure::getInstance(); $_this =& Configure::getInstance();
$_this->behaviorPaths[] = BEHAVIORS; $_this->behaviorPaths[] = BEHAVIORS;
if (isset($behaviorPaths)) { if (isset($behaviorPaths)) {
foreach($behaviorPaths as $value) { foreach ($behaviorPaths as $value) {
$_this->behaviorPaths[] = $value; $_this->behaviorPaths[] = $value;
} }
} }

View file

@ -64,10 +64,10 @@ class Component extends Object {
$this->controller->components = array_merge($this->controller->components, array('Session')); $this->controller->components = array_merge($this->controller->components, array('Session'));
$loaded = $this->_loadComponents($loaded, $this->controller->components); $loaded = $this->_loadComponents($loaded, $this->controller->components);
foreach(array_keys($loaded) as $component) { foreach (array_keys($loaded) as $component) {
$tempComponent =& $loaded[$component]; $tempComponent =& $loaded[$component];
if (isset($tempComponent->components) && is_array($tempComponent->components)) { if (isset($tempComponent->components) && is_array($tempComponent->components)) {
foreach($tempComponent->components as $subComponent) { foreach ($tempComponent->components as $subComponent) {
$this->controller->{$component}->{$subComponent} =& $loaded[$subComponent]; $this->controller->{$component}->{$subComponent} =& $loaded[$subComponent];
} }
} }
@ -88,10 +88,10 @@ class Component extends Object {
function &_loadComponents(&$loaded, $components) { function &_loadComponents(&$loaded, $components) {
$components[] = 'Session'; $components[] = 'Session';
foreach($components as $component) { foreach ($components as $component) {
$parts = preg_split('/\/|\./', $component); $parts = preg_split('/\/|\./', $component);
if(count($parts) === 1) { if (count($parts) === 1) {
$plugin = $this->controller->plugin; $plugin = $this->controller->plugin;
} else { } else {
$plugin = Inflector::underscore($parts['0']); $plugin = Inflector::underscore($parts['0']);

View file

@ -52,7 +52,7 @@ class AclComponent extends Object {
* @return MyACL * @return MyACL
*/ */
function &getACL() { function &getACL() {
if($this->_instance == null) { if ($this->_instance == null) {
$classname = ACL_CLASSNAME; $classname = ACL_CLASSNAME;
$this->_instance = new $classname; $this->_instance = new $classname;
$this->_instance->initialize($this); $this->_instance->initialize($this);
@ -268,7 +268,7 @@ class DB_ACL extends AclBase {
return false; return false;
} }
for($i = count($aroPath) - 1; $i >= 0; $i--) { for ($i = count($aroPath) - 1; $i >= 0; $i--) {
$perms = $this->Aro->Permission->findAll( $perms = $this->Aro->Permission->findAll(
array( array(
'Permission.aro_id' => $aroPath[$i]['Aro']['id'], 'Permission.aro_id' => $aroPath[$i]['Aro']['id'],
@ -280,10 +280,10 @@ class DB_ACL extends AclBase {
if (empty($perms)) { if (empty($perms)) {
continue; continue;
} else { } else {
foreach(Set::extract($perms, '{n}.Permission') as $perm) { foreach (Set::extract($perms, '{n}.Permission') as $perm) {
if ($action == '*') { if ($action == '*') {
// ARO must be cleared for ALL ACO actions // ARO must be cleared for ALL ACO actions
foreach($permKeys as $key) { foreach ($permKeys as $key) {
if (!empty($perm)) { if (!empty($perm)) {
if ($perm[$key] != 1) { if ($perm[$key] != 1) {
return false; return false;
@ -330,16 +330,16 @@ class DB_ACL extends AclBase {
if ($actions == "*") { if ($actions == "*") {
$permKeys = $this->_getAcoKeys($this->Aro->Permission->loadInfo()); $permKeys = $this->_getAcoKeys($this->Aro->Permission->loadInfo());
foreach($permKeys as $key) { foreach ($permKeys as $key) {
$save[$key] = $value; $save[$key] = $value;
} }
} else { } else {
if(!is_array($actions)) { if (!is_array($actions)) {
$actions = array('_' . $actions); $actions = array('_' . $actions);
$actions = am($permKeys, $actions); $actions = am($permKeys, $actions);
} }
if(is_array($actions)) { if (is_array($actions)) {
foreach($actions as $action) { foreach ($actions as $action) {
if ($action{0} != '_') { if ($action{0} != '_') {
$action = '_' . $action; $action = '_' . $action;
} }
@ -448,7 +448,7 @@ class DB_ACL extends AclBase {
$newKeys = array(); $newKeys = array();
$keys = $keys->extract('{n}.name'); $keys = $keys->extract('{n}.name');
foreach($keys as $key) { foreach ($keys as $key) {
if (!in_array($key, array('id', 'aro_id', 'aco_id'))) { if (!in_array($key, array('id', 'aro_id', 'aco_id'))) {
$newKeys[] = $key; $newKeys[] = $key;
} }
@ -511,7 +511,7 @@ class INI_ACL extends AclBase {
if (isset($aclConfig[$aro]['groups'])) { if (isset($aclConfig[$aro]['groups'])) {
$userGroups = $this->arrayTrim(explode(",", $aclConfig[$aro]['groups'])); $userGroups = $this->arrayTrim(explode(",", $aclConfig[$aro]['groups']));
foreach($userGroups as $group) { foreach ($userGroups as $group) {
//If such a group exists, //If such a group exists,
if (array_key_exists($group, $aclConfig)) { if (array_key_exists($group, $aclConfig)) {
//If the group is specifically denied, then DENY //If the group is specifically denied, then DENY
@ -550,7 +550,7 @@ class INI_ACL extends AclBase {
function readConfigFile($fileName) { function readConfigFile($fileName) {
$fileLineArray = file($fileName); $fileLineArray = file($fileName);
foreach($fileLineArray as $fileLine) { foreach ($fileLineArray as $fileLine) {
$dataLine = trim($fileLine); $dataLine = trim($fileLine);
$firstChar = substr($dataLine, 0, 1); $firstChar = substr($dataLine, 0, 1);
@ -590,7 +590,7 @@ class INI_ACL extends AclBase {
* @return array * @return array
*/ */
function arrayTrim($array) { function arrayTrim($array) {
foreach($array as $element) { foreach ($array as $element) {
$element = trim($element); $element = trim($element);
} }

View file

@ -232,7 +232,7 @@ class AuthComponent extends Object {
CAKE_ADMIN . '_delete' => 'delete' CAKE_ADMIN . '_delete' => 'delete'
)); ));
} }
if(Configure::read() > 0) { if (Configure::read() > 0) {
uses('debugger'); uses('debugger');
Debugger::checkSessionKey(); Debugger::checkSessionKey();
} }
@ -266,7 +266,7 @@ class AuthComponent extends Object {
if ($this->_normalizeURL($this->loginAction) == $this->_normalizeURL($url)) { if ($this->_normalizeURL($this->loginAction) == $this->_normalizeURL($url)) {
// We're already at the login action // We're already at the login action
if (empty($controller->data) || !isset($controller->data[$this->userModel])) { if (empty($controller->data) || !isset($controller->data[$this->userModel])) {
if(!$this->Session->check('Auth.redirect')) { if (!$this->Session->check('Auth.redirect')) {
$this->Session->write('Auth.redirect', $controller->referer()); $this->Session->write('Auth.redirect', $controller->referer());
} }
return; return;
@ -537,7 +537,7 @@ class AuthComponent extends Object {
* @return string Redirect URL * @return string Redirect URL
*/ */
function redirect($url = null) { function redirect($url = null) {
if(!is_null($url)) { if (!is_null($url)) {
return $this->Session->write('Auth.redirect', $url); return $this->Session->write('Auth.redirect', $url);
} }
if ($this->Session->check('Auth.redirect')) { if ($this->Session->check('Auth.redirect')) {
@ -638,13 +638,13 @@ class AuthComponent extends Object {
if (empty($user)) { if (empty($user)) {
return null; return null;
} }
} else if (is_object($user) && is_a($user, 'Model')) { } elseif (is_object($user) && is_a($user, 'Model')) {
if (!$user->exists()) { if (!$user->exists()) {
return null; return null;
} }
$user = $user->read(); $user = $user->read();
$user = $user[$this->userModel]; $user = $user[$this->userModel];
} else if (is_array($user) && isset($user[$this->userModel])) { } elseif (is_array($user) && isset($user[$this->userModel])) {
$user = $user[$this->userModel]; $user = $user[$this->userModel];
} }
@ -673,7 +673,7 @@ class AuthComponent extends Object {
if (empty($data) || empty($data[$this->userModel])) { if (empty($data) || empty($data[$this->userModel])) {
return null; return null;
} }
} else if (is_numeric($user)) { } elseif (is_numeric($user)) {
// Assume it's a user's ID // Assume it's a user's ID
$model =& $this->getUserModel(); $model =& $this->getUserModel();
$data = $model->find(am(array($model->escapeField() => $user), $this->userScope)); $data = $model->find(am(array($model->escapeField() => $user), $this->userScope));
@ -683,7 +683,7 @@ class AuthComponent extends Object {
} }
} }
if (isset($data) && !empty($data)) { if (isset($data) && !empty($data)) {
if(!empty($data[$this->userModel][$this->fields['password']])) { if (!empty($data[$this->userModel][$this->fields['password']])) {
unset($data[$this->userModel][$this->fields['password']]); unset($data[$this->userModel][$this->fields['password']]);
} }
return $data[$this->userModel]; return $data[$this->userModel];

View file

@ -29,7 +29,7 @@
/** /**
* Load Security class * Load Security class
*/ */
if(!class_exists('Security')){ if (!class_exists('Security')){
uses('Security'); uses('Security');
} }
/** /**
@ -162,23 +162,23 @@ class CookieComponent extends Object {
* @deprecated use Controller::beforeFilter() to set the properties of the CookieComponent * @deprecated use Controller::beforeFilter() to set the properties of the CookieComponent
*/ */
function initialize(&$controller) { function initialize(&$controller) {
if(is_object($controller)){ if (is_object($controller)){
if(isset($controller->cookieName)) { if (isset($controller->cookieName)) {
$this->name = $controller->cookieName; $this->name = $controller->cookieName;
} }
if(isset($controller->cookieTime)){ if (isset($controller->cookieTime)){
$this->time = $controller->cookieTime; $this->time = $controller->cookieTime;
} }
if(isset($controller->cookieKey)){ if (isset($controller->cookieKey)){
$this->key = $controller->cookieKey; $this->key = $controller->cookieKey;
} }
if(isset($controller->cookiePath)) { if (isset($controller->cookiePath)) {
$this->path = $controller->cookiePath; $this->path = $controller->cookiePath;
} }
if(isset($controller->cookieDomain)) { if (isset($controller->cookieDomain)) {
$this->domain = $controller->cookieDomain; $this->domain = $controller->cookieDomain;
} }
if(isset($controller->cookieSecure)) { if (isset($controller->cookieSecure)) {
$this->secure = $controller->cookieSecure; $this->secure = $controller->cookieSecure;
} }
} }
@ -191,7 +191,7 @@ class CookieComponent extends Object {
function startup() { function startup() {
$this->__expire($this->time); $this->__expire($this->time);
if(isset($_COOKIE[$this->name])) { if (isset($_COOKIE[$this->name])) {
$this->__values = $this->__decrypt($_COOKIE[$this->name]); $this->__values = $this->__decrypt($_COOKIE[$this->name]);
} }
} }
@ -214,17 +214,17 @@ class CookieComponent extends Object {
* @access public * @access public
*/ */
function write($key, $value = null, $encrypt = true, $expires = null) { function write($key, $value = null, $encrypt = true, $expires = null) {
if(is_null($encrypt)){ if (is_null($encrypt)){
$encrypt = true; $encrypt = true;
} }
$this->__encrypted = $encrypt; $this->__encrypted = $encrypt;
$this->__expire($expires); $this->__expire($expires);
if(!is_array($key) && $value !== null) { if (!is_array($key) && $value !== null) {
$name = $this->__cookieVarNames($key); $name = $this->__cookieVarNames($key);
if(count($name) > 1){ if (count($name) > 1){
$this->__values[$name[0]][$name[1]] = $value; $this->__values[$name[0]][$name[1]] = $value;
$this->__write("[".$name[0]."][".$name[1]."]", $value); $this->__write("[".$name[0]."][".$name[1]."]", $value);
} else { } else {
@ -232,10 +232,10 @@ class CookieComponent extends Object {
$this->__write("[".$name[0]."]", $value); $this->__write("[".$name[0]."]", $value);
} }
} else { } else {
foreach($key as $names => $value){ foreach ($key as $names => $value){
$name = $this->__cookieVarNames($names); $name = $this->__cookieVarNames($names);
if(count($name) > 1){ if (count($name) > 1){
$this->__values[$name[0]][$name[1]] = $value; $this->__values[$name[0]][$name[1]] = $value;
$this->__write("[".$name[0]."][".$name[1]."]", $value); $this->__write("[".$name[0]."][".$name[1]."]", $value);
} else { } else {
@ -256,23 +256,23 @@ class CookieComponent extends Object {
* @access public * @access public
*/ */
function read($key = null) { function read($key = null) {
if(empty($this->__values) && isset($_COOKIE[$this->name])) { if (empty($this->__values) && isset($_COOKIE[$this->name])) {
$this->__values = $this->__decrypt($_COOKIE[$this->name]); $this->__values = $this->__decrypt($_COOKIE[$this->name]);
} }
if(is_null($key)){ if (is_null($key)){
return $this->__values; return $this->__values;
} }
$name = $this->__cookieVarNames($key); $name = $this->__cookieVarNames($key);
if(count($name) > 1){ if (count($name) > 1){
if(isset($this->__values[$name[0]])) { if (isset($this->__values[$name[0]])) {
$value = $this->__values[$name[0]][$name[1]]; $value = $this->__values[$name[0]][$name[1]];
return $value; return $value;
} }
return null; return null;
} else { } else {
if(isset($this->__values[$name[0]])) { if (isset($this->__values[$name[0]])) {
$value = $this->__values[$name[0]]; $value = $this->__values[$name[0]];
return $value; return $value;
} }
@ -294,14 +294,14 @@ class CookieComponent extends Object {
function del($key) { function del($key) {
$name = $this->__cookieVarNames($key); $name = $this->__cookieVarNames($key);
if(count($name) > 1){ if (count($name) > 1){
if(isset($this->__values[$name[0]])) { if (isset($this->__values[$name[0]])) {
unset($this->__values[$name[0]][$name[1]]); unset($this->__values[$name[0]][$name[1]]);
$this->__delete("[".$name[0]."][".$name[1]."]"); $this->__delete("[".$name[0]."][".$name[1]."]");
} }
} else { } else {
if(isset($this->__values[$name[0]])) { if (isset($this->__values[$name[0]])) {
if(is_array($this->__values[$name[0]])) { if (is_array($this->__values[$name[0]])) {
foreach ($this->__values[$name[0]] as $key => $value) { foreach ($this->__values[$name[0]] as $key => $value) {
$this->__delete("[".$name[0]."][".$key."]"); $this->__delete("[".$name[0]."][".$key."]");
} }
@ -320,12 +320,12 @@ class CookieComponent extends Object {
* @access public * @access public
*/ */
function destroy() { function destroy() {
if(isset($_COOKIE[$this->name])) { if (isset($_COOKIE[$this->name])) {
$this->__values = $this->__decrypt($_COOKIE[$this->name]); $this->__values = $this->__decrypt($_COOKIE[$this->name]);
} }
foreach ($this->__values as $name => $value) { foreach ($this->__values as $name => $value) {
if(is_array($value)) { if (is_array($value)) {
foreach ($value as $key => $val) { foreach ($value as $key => $val) {
unset($this->__values[$name][$key]); unset($this->__values[$name][$key]);
$this->__delete("[$name][$key]"); $this->__delete("[$name][$key]");
@ -362,7 +362,7 @@ class CookieComponent extends Object {
*/ */
function __expire($expires = null){ function __expire($expires = null){
$now = time(); $now = time();
if(is_null($expires)){ if (is_null($expires)){
return $this->__expires; return $this->__expires;
} }
$this->__reset = $this->__expires; $this->__reset = $this->__expires;
@ -382,7 +382,7 @@ class CookieComponent extends Object {
function __write($name, $value) { function __write($name, $value) {
setcookie($this->name . "$name", $this->__encrypt($value), $this->__expires, $this->path, $this->domain, $this->secure); setcookie($this->name . "$name", $this->__encrypt($value), $this->__expires, $this->path, $this->domain, $this->secure);
if(!is_null($this->__reset)){ if (!is_null($this->__reset)){
$this->__expires = $this->__reset; $this->__expires = $this->__reset;
$this->__reset = null; $this->__reset = null;
} }
@ -405,11 +405,11 @@ class CookieComponent extends Object {
* @access private * @access private
*/ */
function __encrypt($value) { function __encrypt($value) {
if(is_array($value)){ if (is_array($value)){
$value = $this->__implode($value); $value = $this->__implode($value);
} }
if($this->__encrypted === true) { if ($this->__encrypted === true) {
$type = $this->__type; $type = $this->__type;
$value = "Q2FrZQ==." .base64_encode(Security::$type($value, $this->key)); $value = "Q2FrZQ==." .base64_encode(Security::$type($value, $this->key));
} }
@ -426,8 +426,8 @@ class CookieComponent extends Object {
$decrypted = array(); $decrypted = array();
$type = $this->__type; $type = $this->__type;
foreach($values as $name => $value) { foreach ($values as $name => $value) {
if(is_array($value)){ if (is_array($value)){
foreach ($value as $key => $val) { foreach ($value as $key => $val) {
$pos = strpos($val, 'Q2FrZQ==.'); $pos = strpos($val, 'Q2FrZQ==.');
$decrypted[$name][$key] = $this->__explode($val); $decrypted[$name][$key] = $this->__explode($val);
@ -494,7 +494,7 @@ class CookieComponent extends Object {
$array = array(); $array = array();
foreach (explode(',', $string) as $pair) { foreach (explode(',', $string) as $pair) {
$key = explode('|', $pair); $key = explode('|', $pair);
if(!isset($key[1])){ if (!isset($key[1])){
return $key[0]; return $key[0];
} }
$array[$key[0]] = $key[1]; $array[$key[0]] = $key[1];

View file

@ -217,8 +217,8 @@ class EmailComponent extends Object{
$this->__createHeader(); $this->__createHeader();
$this->subject = $this->__encode($this->subject); $this->subject = $this->__encode($this->subject);
if($this->template === null) { if ($this->template === null) {
if(is_array($content)){ if (is_array($content)){
$message = null; $message = null;
foreach ($content as $key => $value){ foreach ($content as $key => $value){
$message .= $value . $this->_newLine; $message .= $value . $this->_newLine;
@ -231,7 +231,7 @@ class EmailComponent extends Object{
$this->__message = $this->__renderTemplate($content); $this->__message = $this->__renderTemplate($content);
} }
if(!empty($this->attachments)) { if (!empty($this->attachments)) {
$this->__attachFiles(); $this->__attachFiles();
} }
@ -274,7 +274,7 @@ class EmailComponent extends Object{
function __renderTemplate($content) { function __renderTemplate($content) {
$View = new View($this->Controller); $View = new View($this->Controller);
$View->layout = $this->layout; $View->layout = $this->layout;
if($this->sendAs === 'both'){ if ($this->sendAs === 'both'){
$htmlContent = $content; $htmlContent = $content;
$msg = '--' . $this->__boundary . $this->_newLine; $msg = '--' . $this->__boundary . $this->_newLine;
$msg .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine; $msg .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
@ -320,14 +320,14 @@ class EmailComponent extends Object{
} }
$addresses = null; $addresses = null;
if(!empty($this->cc)) { if (!empty($this->cc)) {
foreach ($this->cc as $cc) { foreach ($this->cc as $cc) {
$addresses .= $this->__formatAddress($cc) . ', '; $addresses .= $this->__formatAddress($cc) . ', ';
} }
$this->__header .= 'cc: ' . $addresses . $this->_newLine; $this->__header .= 'cc: ' . $addresses . $this->_newLine;
} }
$addresses = null; $addresses = null;
if(!empty($this->bcc)) { if (!empty($this->bcc)) {
foreach ($this->bcc as $bcc) { foreach ($this->bcc as $bcc) {
$addresses .= $this->__formatAddress($bcc) . ', '; $addresses .= $this->__formatAddress($bcc) . ', ';
} }
@ -336,18 +336,18 @@ class EmailComponent extends Object{
$this->__header .= 'X-Mailer: ' . $this->xMailer . $this->_newLine; $this->__header .= 'X-Mailer: ' . $this->xMailer . $this->_newLine;
if(!empty($this->attachments) && $this->sendAs === 'text') { if (!empty($this->attachments) && $this->sendAs === 'text') {
$this->__createBoundary(); $this->__createBoundary();
$this->__header .= 'MIME-Version: 1.0' . $this->_newLine; $this->__header .= 'MIME-Version: 1.0' . $this->_newLine;
$this->__header .= 'Content-Type: multipart/mixed; boundary="' . $this->__boundary . '"' . $this->_newLine; $this->__header .= 'Content-Type: multipart/mixed; boundary="' . $this->__boundary . '"' . $this->_newLine;
} elseif(!empty($this->attachments) && $this->sendAs === 'html') { } elseif (!empty($this->attachments) && $this->sendAs === 'html') {
$this->__createBoundary(); $this->__createBoundary();
$this->__header .= 'MIME-Version: 1.0' . $this->_newLine; $this->__header .= 'MIME-Version: 1.0' . $this->_newLine;
$this->__header .= 'Content-Type: multipart/related; boundary="' . $this->__boundary . '"' . $this->_newLine; $this->__header .= 'Content-Type: multipart/related; boundary="' . $this->__boundary . '"' . $this->_newLine;
} elseif($this->sendAs === 'html') { } elseif ($this->sendAs === 'html') {
$this->__header .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine; $this->__header .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
$this->__header .= 'Content-Transfer-Encoding: 8bit' . $this->_newLine; $this->__header .= 'Content-Transfer-Encoding: 8bit' . $this->_newLine;
} elseif($this->sendAs === 'both') { } elseif ($this->sendAs === 'both') {
$this->__createBoundary(); $this->__createBoundary();
$this->__header .= 'MIME-Version: 1.0' . $this->_newLine; $this->__header .= 'MIME-Version: 1.0' . $this->_newLine;
$this->__header .= 'Content-Type: multipart/alternative; boundary="' . $this->__boundary . '"' . $this->_newLine; $this->__header .= 'Content-Type: multipart/alternative; boundary="' . $this->__boundary . '"' . $this->_newLine;
@ -362,7 +362,7 @@ class EmailComponent extends Object{
function __formatMessage($message){ function __formatMessage($message){
$message = $this->__wrap($message); $message = $this->__wrap($message);
if($this->sendAs === 'both'){ if ($this->sendAs === 'both'){
$this->__message = '--' . $this->__boundary . $this->_newLine; $this->__message = '--' . $this->__boundary . $this->_newLine;
$this->__message .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine; $this->__message .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
$this->__message .= 'Content-Transfer-Encoding: 8bit' . $this->_newLine; $this->__message .= 'Content-Transfer-Encoding: 8bit' . $this->_newLine;
@ -385,11 +385,11 @@ class EmailComponent extends Object{
* @access private * @access private
*/ */
function __attachFiles(){ function __attachFiles(){
foreach($this->attachments as $attachment) { foreach ($this->attachments as $attachment) {
$files[] = $this->__findFiles($attachment); $files[] = $this->__findFiles($attachment);
} }
foreach($files as $file) { foreach ($files as $file) {
$handle = fopen($file, 'rb'); $handle = fopen($file, 'rb');
$data = fread($handle, filesize($file)); $data = fread($handle, filesize($file));
$data = chunk_split(base64_encode($data)) ; $data = chunk_split(base64_encode($data)) ;
@ -410,7 +410,7 @@ class EmailComponent extends Object{
* @access private * @access private
*/ */
function __findFiles($attachment){ function __findFiles($attachment){
foreach($this->filePaths as $path) { foreach ($this->filePaths as $path) {
if (file_exists($path . DS . $attachment)) { if (file_exists($path . DS . $attachment)) {
$file = $path . DS . $attachment; $file = $path . DS . $attachment;
return $file; return $file;
@ -442,7 +442,7 @@ class EmailComponent extends Object{
* @access private * @access private
*/ */
function __encode($subject) { function __encode($subject) {
if(low($this->charset) !== 'iso-8859-15') { if (low($this->charset) !== 'iso-8859-15') {
$start = "=?" . $this->charset . "?B?"; $start = "=?" . $this->charset . "?B?";
$end = "?="; $end = "?=";
$spacer = $end . "\n " . $start; $spacer = $end . "\n " . $start;
@ -467,7 +467,7 @@ class EmailComponent extends Object{
* @access private * @access private
*/ */
function __formatAddress($string){ function __formatAddress($string){
if(strpos($string, '<') !== false){ if (strpos($string, '<') !== false){
$value = explode('<', $string); $value = explode('<', $string);
$string = $this->__encode($value[0]) . ' <' . $value[1]; $string = $this->__encode($value[0]) . ' <' . $value[1];
} }

View file

@ -136,7 +136,7 @@ class RequestHandlerComponent extends Object {
function __construct() { function __construct() {
$this->__acceptTypes = explode(',', env('HTTP_ACCEPT')); $this->__acceptTypes = explode(',', env('HTTP_ACCEPT'));
foreach($this->__acceptTypes as $i => $type) { foreach ($this->__acceptTypes as $i => $type) {
if (strpos($type, ';')) { if (strpos($type, ';')) {
$type = explode(';', $type); $type = explode(';', $type);
$this->__acceptTypes[$i] = $type[0]; $this->__acceptTypes[$i] = $type[0];
@ -389,14 +389,14 @@ class RequestHandlerComponent extends Object {
if ($type == null) { if ($type == null) {
return $this->mapType($this->__acceptTypes); return $this->mapType($this->__acceptTypes);
} else if(is_array($type)) { } elseif (is_array($type)) {
foreach($type as $t) { foreach ($type as $t) {
if ($this->accepts($t) == true) { if ($this->accepts($t) == true) {
return true; return true;
} }
} }
return false; return false;
} else if(is_string($type)) { } elseif (is_string($type)) {
if (!in_array($type, array_keys($this->__requestContent))) { if (!in_array($type, array_keys($this->__requestContent))) {
return false; return false;
@ -405,7 +405,7 @@ class RequestHandlerComponent extends Object {
$content = $this->__requestContent[$type]; $content = $this->__requestContent[$type];
if (is_array($content)) { if (is_array($content)) {
foreach($content as $c) { foreach ($content as $c) {
if (in_array($c, $this->__acceptTypes)) { if (in_array($c, $this->__acceptTypes)) {
return true; return true;
} }
@ -433,14 +433,14 @@ class RequestHandlerComponent extends Object {
if ($type == null) { if ($type == null) {
return $this->mapType(env('CONTENT_TYPE')); return $this->mapType(env('CONTENT_TYPE'));
} else if(is_array($type)) { } elseif (is_array($type)) {
foreach($type as $t) { foreach ($type as $t) {
if ($this->requestedWith($t)) { if ($this->requestedWith($t)) {
return $this->mapType($t); return $this->mapType($t);
} }
} }
return false; return false;
} else if(is_string($type)) { } elseif (is_string($type)) {
return ($type == $this->mapType(env('CONTENT_TYPE'))); return ($type == $this->mapType(env('CONTENT_TYPE')));
} }

View file

@ -146,7 +146,7 @@ class SecurityComponent extends Object {
$this->__authRequired($controller); $this->__authRequired($controller);
$this->__loginRequired($controller); $this->__loginRequired($controller);
if((!isset($controller->params['requested']) || $controller->params['requested'] != 1) && $this->RequestHandler->isPost()) { if ((!isset($controller->params['requested']) || $controller->params['requested'] != 1) && $this->RequestHandler->isPost()) {
$this->__validatePost($controller); $this->__validatePost($controller);
} }
@ -160,7 +160,7 @@ class SecurityComponent extends Object {
*/ */
function requirePost() { function requirePost() {
$this->requirePost = func_get_args(); $this->requirePost = func_get_args();
if(empty($this->requirePost)) { if (empty($this->requirePost)) {
$this->requirePost = array('*'); $this->requirePost = array('*');
} }
} }
@ -172,7 +172,7 @@ class SecurityComponent extends Object {
*/ */
function requireSecure() { function requireSecure() {
$this->requireSecure = func_get_args(); $this->requireSecure = func_get_args();
if(empty($this->requireSecure)) { if (empty($this->requireSecure)) {
$this->requireSecure = array('*'); $this->requireSecure = array('*');
} }
} }
@ -184,7 +184,7 @@ class SecurityComponent extends Object {
*/ */
function requireAuth() { function requireAuth() {
$this->requireAuth = func_get_args(); $this->requireAuth = func_get_args();
if(empty($this->requireAuth)) { if (empty($this->requireAuth)) {
$this->requireAuth = array('*'); $this->requireAuth = array('*');
} }
} }
@ -197,18 +197,18 @@ class SecurityComponent extends Object {
function requireLogin() { function requireLogin() {
$args = func_get_args(); $args = func_get_args();
foreach ($args as $arg) { foreach ($args as $arg) {
if(is_array($arg)) { if (is_array($arg)) {
$this->loginOptions = $arg; $this->loginOptions = $arg;
} else { } else {
$this->requireLogin[] = $arg; $this->requireLogin[] = $arg;
} }
} }
if(empty($this->requireLogin)) { if (empty($this->requireLogin)) {
$this->requireLogin = array('*'); $this->requireLogin = array('*');
} }
if(isset($this->loginOptions['users'])) { if (isset($this->loginOptions['users'])) {
$this->loginUsers =& $this->loginOptions['users']; $this->loginUsers =& $this->loginOptions['users'];
} }
} }
@ -220,20 +220,20 @@ class SecurityComponent extends Object {
* @access public * @access public
*/ */
function loginCredentials($type = null) { function loginCredentials($type = null) {
if(empty($type) || low($type) == 'basic') { if (empty($type) || low($type) == 'basic') {
$login = array('username' => env('PHP_AUTH_USER'), 'password' => env('PHP_AUTH_PW')); $login = array('username' => env('PHP_AUTH_USER'), 'password' => env('PHP_AUTH_PW'));
if($login['username'] != null) { if ($login['username'] != null) {
return $login; return $login;
} }
} }
if($type == '' || low($type) == 'digest') { if ($type == '' || low($type) == 'digest') {
$digest = null; $digest = null;
if(version_compare(phpversion(), '5.1') != -1) { if (version_compare(phpversion(), '5.1') != -1) {
$digest = env('PHP_AUTH_DIGEST'); $digest = env('PHP_AUTH_DIGEST');
} elseif(function_exists('apache_request_headers')) { } elseif (function_exists('apache_request_headers')) {
$headers = apache_request_headers(); $headers = apache_request_headers();
if (isset($headers['Authorization']) && !empty($headers['Authorization']) && substr($headers['Authorization'], 0, 7) == 'Digest ') { if (isset($headers['Authorization']) && !empty($headers['Authorization']) && substr($headers['Authorization'], 0, 7) == 'Digest ') {
$digest = substr($headers['Authorization'], 7); $digest = substr($headers['Authorization'], 7);
@ -244,7 +244,7 @@ class SecurityComponent extends Object {
return null; return null;
} }
if($digest == null) { if ($digest == null) {
return null; return null;
} }
$data = $this->parseDigestAuthData($digest); $data = $this->parseDigestAuthData($digest);
@ -272,7 +272,7 @@ class SecurityComponent extends Object {
* @access public * @access public
*/ */
function parseDigestAuthData($digest) { function parseDigestAuthData($digest) {
if(substr($digest, 0, 7) == 'Digest ') { if (substr($digest, 0, 7) == 'Digest ') {
$digest = substr($digest, 7); $digest = substr($digest, 7);
} }
$keys = array(); $keys = array();
@ -280,12 +280,12 @@ class SecurityComponent extends Object {
$req = array('nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1); $req = array('nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1);
preg_match_all('@(\w+)=([\'"]?)([a-zA-Z0-9=./\_-]+)\2@', $digest, $match, PREG_SET_ORDER); preg_match_all('@(\w+)=([\'"]?)([a-zA-Z0-9=./\_-]+)\2@', $digest, $match, PREG_SET_ORDER);
foreach($match as $i) { foreach ($match as $i) {
$keys[$i[1]] = $i[3]; $keys[$i[1]] = $i[3];
unset($req[$i[1]]); unset($req[$i[1]]);
} }
if(empty($req)) { if (empty($req)) {
return $keys; return $keys;
} else { } else {
return null; return null;
@ -300,9 +300,9 @@ class SecurityComponent extends Object {
* @access public * @access public
*/ */
function blackHole(&$controller, $error = '') { function blackHole(&$controller, $error = '') {
if($this->blackHoleCallback == null) { if ($this->blackHoleCallback == null) {
$code = 404; $code = 404;
if($error == 'login') { if ($error == 'login') {
$code = 401; $code = 401;
} }
$controller->redirect(null, $code, true); $controller->redirect(null, $code, true);
@ -318,10 +318,10 @@ class SecurityComponent extends Object {
* @access private * @access private
*/ */
function __postRequired(&$controller) { function __postRequired(&$controller) {
if(is_array($this->requirePost) && !empty($this->requirePost)) { if (is_array($this->requirePost) && !empty($this->requirePost)) {
if(in_array($controller->action, $this->requirePost) || $this->requirePost == array('*')) { if (in_array($controller->action, $this->requirePost) || $this->requirePost == array('*')) {
if(!$this->RequestHandler->isPost()) { if (!$this->RequestHandler->isPost()) {
if(!$this->blackHole($controller, 'post')) { if (!$this->blackHole($controller, 'post')) {
return null; return null;
} }
} }
@ -337,10 +337,10 @@ class SecurityComponent extends Object {
* @access private * @access private
*/ */
function __secureRequired(&$controller) { function __secureRequired(&$controller) {
if(is_array($this->requireSecure) && !empty($this->requireSecure)) { if (is_array($this->requireSecure) && !empty($this->requireSecure)) {
if(in_array($controller->action, $this->requireSecure) || $this->requireSecure == array('*')) { if (in_array($controller->action, $this->requireSecure) || $this->requireSecure == array('*')) {
if(!$this->RequestHandler->isSSL()) { if (!$this->RequestHandler->isSSL()) {
if(!$this->blackHole($controller, 'secure')) { if (!$this->blackHole($controller, 'secure')) {
return null; return null;
} }
} }
@ -356,25 +356,25 @@ class SecurityComponent extends Object {
* @access private * @access private
*/ */
function __authRequired(&$controller) { function __authRequired(&$controller) {
if(is_array($this->requireAuth) && !empty($this->requireAuth) && !empty($controller->data)) { if (is_array($this->requireAuth) && !empty($this->requireAuth) && !empty($controller->data)) {
if(in_array($controller->action, $this->requireAuth) || $this->requireAuth == array('*')) { if (in_array($controller->action, $this->requireAuth) || $this->requireAuth == array('*')) {
if(!isset($controller->data['__Token'] )) { if (!isset($controller->data['__Token'] )) {
if(!$this->blackHole($controller, 'auth')) { if (!$this->blackHole($controller, 'auth')) {
return null; return null;
} }
} }
$token = $controller->data['__Token']['key']; $token = $controller->data['__Token']['key'];
if($this->Session->check('_Token')) { if ($this->Session->check('_Token')) {
$tData = unserialize($this->Session->read('_Token')); $tData = unserialize($this->Session->read('_Token'));
if(!empty($tData['allowedControllers']) && !in_array($controller->params['controller'], $tData['allowedControllers']) ||!empty($tData['allowedActions']) && !in_array($controller->params['action'], $tData['allowedActions'])) { if (!empty($tData['allowedControllers']) && !in_array($controller->params['controller'], $tData['allowedControllers']) ||!empty($tData['allowedActions']) && !in_array($controller->params['action'], $tData['allowedActions'])) {
if(!$this->blackHole($controller, 'auth')) { if (!$this->blackHole($controller, 'auth')) {
return null; return null;
} }
} }
} else { } else {
if(!$this->blackHole($controller, 'auth')) { if (!$this->blackHole($controller, 'auth')) {
return null; return null;
} }
} }
@ -390,24 +390,24 @@ class SecurityComponent extends Object {
* @access private * @access private
*/ */
function __loginRequired(&$controller) { function __loginRequired(&$controller) {
if(is_array($this->requireLogin) && !empty($this->requireLogin)) { if (is_array($this->requireLogin) && !empty($this->requireLogin)) {
if(in_array($controller->action, $this->requireLogin) || $this->requireLogin == array('*')) { if (in_array($controller->action, $this->requireLogin) || $this->requireLogin == array('*')) {
$login = $this->loginCredentials($this->loginOptions['type']); $login = $this->loginCredentials($this->loginOptions['type']);
if($login == null) { if ($login == null) {
// User hasn't been authenticated yet // User hasn't been authenticated yet
header($this->loginRequest()); header($this->loginRequest());
if(isset($this->loginOptions['prompt'])) { if (isset($this->loginOptions['prompt'])) {
$this->__callback($controller, $this->loginOptions['prompt']); $this->__callback($controller, $this->loginOptions['prompt']);
} else { } else {
$this->blackHole($controller, 'login'); $this->blackHole($controller, 'login');
} }
} else { } else {
if(isset($this->loginOptions['login'])) { if (isset($this->loginOptions['login'])) {
$this->__callback($controller, $this->loginOptions['login'], array($login)); $this->__callback($controller, $this->loginOptions['login'], array($login));
} else { } else {
if(low($this->loginOptions['type']) == 'digest') { if (low($this->loginOptions['type']) == 'digest') {
// Do digest authentication // Do digest authentication
} else { } else {
if (!(in_array($login['username'], array_keys($this->loginUsers)) && $this->loginUsers[$login['username']] == $login['password'])) { if (!(in_array($login['username'], array_keys($this->loginUsers)) && $this->loginUsers[$login['username']] == $login['password'])) {
@ -428,26 +428,26 @@ class SecurityComponent extends Object {
* @access private * @access private
*/ */
function __validatePost(&$controller) { function __validatePost(&$controller) {
if(!empty($controller->data)) { if (!empty($controller->data)) {
if (!isset($controller->data['__Token'])) { if (!isset($controller->data['__Token'])) {
if(!$this->blackHole($controller, 'auth')) { if (!$this->blackHole($controller, 'auth')) {
return null; return null;
} }
} }
$token = $controller->data['__Token']['key']; $token = $controller->data['__Token']['key'];
if($this->Session->check('_Token')) { if ($this->Session->check('_Token')) {
$tData = unserialize($this->Session->read('_Token')); $tData = unserialize($this->Session->read('_Token'));
if($tData['expires'] < time() || $tData['key'] !== $token) { if ($tData['expires'] < time() || $tData['key'] !== $token) {
if(!$this->blackHole($controller, 'auth')) { if (!$this->blackHole($controller, 'auth')) {
return null; return null;
} }
} }
} }
if(!isset($controller->data['__Token']['fields'])) { if (!isset($controller->data['__Token']['fields'])) {
if(!$this->blackHole($controller, 'auth')) { if (!$this->blackHole($controller, 'auth')) {
return null; return null;
} }
} }
@ -455,15 +455,15 @@ class SecurityComponent extends Object {
$check = $controller->data; $check = $controller->data;
unset($check['__Token']['fields']); unset($check['__Token']['fields']);
if(!empty($this->disabledFields)) { if (!empty($this->disabledFields)) {
foreach($check as $model => $fields) { foreach ($check as $model => $fields) {
foreach($fields as $field => $value) { foreach ($fields as $field => $value) {
$key[] = $model . '.' . $field; $key[] = $model . '.' . $field;
} }
unset($field); unset($field);
} }
foreach($this->disabledFields as $value) { foreach ($this->disabledFields as $value) {
$parts = preg_split('/\/|\./', $value); $parts = preg_split('/\/|\./', $value);
if (count($parts) == 1) { if (count($parts) == 1) {
@ -474,7 +474,7 @@ class SecurityComponent extends Object {
} }
foreach ($key1 as $value) { foreach ($key1 as $value) {
if(in_array($value, $key)) { if (in_array($value, $key)) {
$remove = explode('.', $value); $remove = explode('.', $value);
unset($check[$remove['0']][$remove['1']]); unset($check[$remove['0']][$remove['1']]);
} elseif (in_array('_' . $value, $key)) { } elseif (in_array('_' . $value, $key)) {
@ -485,28 +485,28 @@ class SecurityComponent extends Object {
} }
} }
$merge = array(); $merge = array();
foreach($check as $key => $value) { foreach ($check as $key => $value) {
if($key === '__Token') { if ($key === '__Token') {
$field[$key] = $value; $field[$key] = $value;
continue; continue;
} }
$string = substr($key, 0, 1); $string = substr($key, 0, 1);
if($string === '_') { if ($string === '_') {
$newKey = substr($key, 1); $newKey = substr($key, 1);
$controller->data[$newKey] = array(); $controller->data[$newKey] = array();
if(is_array($value)) { if (is_array($value)) {
$values = array_values($value); $values = array_values($value);
$k = array_keys($value); $k = array_keys($value);
$count = count($k); $count = count($k);
for($i = 0; $count > $i; $i++) { for ($i = 0; $count > $i; $i++) {
$field[$key][$k[$i]] = $values[$i]; $field[$key][$k[$i]] = $values[$i];
} }
} }
foreach($k as $lookup) { foreach ($k as $lookup) {
if(isset($controller->data[$newKey][$lookup])){ if (isset($controller->data[$newKey][$lookup])){
unset($controller->data[$key][$lookup]); unset($controller->data[$key][$lookup]);
} elseif ($controller->data[$key][$lookup] === '0') { } elseif ($controller->data[$key][$lookup] === '0') {
$merge[] = $lookup; $merge[] = $lookup;
@ -516,15 +516,15 @@ class SecurityComponent extends Object {
unset($controller->data[$key]); unset($controller->data[$key]);
continue; continue;
} }
if(!array_key_exists($key, $value)) { if (!array_key_exists($key, $value)) {
$field[$key] = array_keys($value); $field[$key] = array_keys($value);
$field[$key] = array_merge($merge, $field[$key]); $field[$key] = array_merge($merge, $field[$key]);
} }
} }
$check = urlencode(Security::hash(serialize(sort($field)) . CAKE_SESSION_STRING)); $check = urlencode(Security::hash(serialize(sort($field)) . CAKE_SESSION_STRING));
if($form !== $check) { if ($form !== $check) {
if(!$this->blackHole($controller, 'auth')) { if (!$this->blackHole($controller, 'auth')) {
return null; return null;
} }
} }
@ -539,7 +539,7 @@ class SecurityComponent extends Object {
* @access private * @access private
*/ */
function __generateToken(&$controller) { function __generateToken(&$controller) {
if(!isset($controller->params['requested']) || $controller->params['requested'] != 1) { if (!isset($controller->params['requested']) || $controller->params['requested'] != 1) {
$authKey = Security::generateAuthKey(); $authKey = Security::generateAuthKey();
$expires = strtotime('+'.Security::inactiveMins().' minutes'); $expires = strtotime('+'.Security::inactiveMins().' minutes');
$token = array('key' => $authKey, $token = array('key' => $authKey,
@ -548,7 +548,7 @@ class SecurityComponent extends Object {
'allowedActions' => $this->allowedActions, 'allowedActions' => $this->allowedActions,
'disabledFields' => $this->disabledFields); 'disabledFields' => $this->disabledFields);
if(!isset($controller->data)) { if (!isset($controller->data)) {
$controller->data = array(); $controller->data = array();
} }
$controller->params['_Token'] = $token; $controller->params['_Token'] = $token;
@ -580,7 +580,7 @@ class SecurityComponent extends Object {
* @access private * @access private
*/ */
function __callback(&$controller, $method, $params = array()) { function __callback(&$controller, $method, $params = array()) {
if(is_callable(array($controller, $method))) { if (is_callable(array($controller, $method))) {
return call_user_func_array(array(&$controller, $method), empty($params) ? null : $params); return call_user_func_array(array(&$controller, $method), empty($params) ? null : $params);
} else { } else {
// Debug::warning('Callback method ' . $method . ' in controller ' . get_class($controller) // Debug::warning('Callback method ' . $method . ' in controller ' . get_class($controller)

View file

@ -95,8 +95,8 @@ class SessionComponent extends CakeSession {
*/ */
function write($name, $value = null) { function write($name, $value = null) {
if ($this->__active === true) { if ($this->__active === true) {
if(is_array($name)) { if (is_array($name)) {
foreach($name as $key => $value) { foreach ($name as $key => $value) {
if (parent::write($key, $value) === false) { if (parent::write($key, $value) === false) {
return false; return false;
} }

View file

@ -320,7 +320,7 @@ class Controller extends Object {
$merge[] = 'uses'; $merge[] = 'uses';
} }
foreach($merge as $var) { foreach ($merge as $var) {
if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) { if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
$this->{$var} = array_merge($this->{$var}, array_diff($appVars[$var], $this->{$var})); $this->{$var} = array_merge($this->{$var}, array_diff($appVars[$var], $this->{$var}));
} }
@ -342,7 +342,7 @@ class Controller extends Object {
* @access public * @access public
*/ */
function constructClasses() { function constructClasses() {
if($this->uses === null || ($this->uses === array())){ if ($this->uses === null || ($this->uses === array())){
return false; return false;
} }
if (empty($this->passedArgs) || !isset($this->passedArgs['0'])) { if (empty($this->passedArgs) || !isset($this->passedArgs['0'])) {
@ -354,12 +354,12 @@ class Controller extends Object {
$object = null; $object = null;
$plugin = null; $plugin = null;
if($this->plugin) { if ($this->plugin) {
$plugin = $this->plugin . '.'; $plugin = $this->plugin . '.';
} }
if($this->uses === false) { if ($this->uses === false) {
if(!class_exists($this->modelClass)){ if (!class_exists($this->modelClass)){
loadModel($plugin . $this->modelClass); loadModel($plugin . $this->modelClass);
} }
} }
@ -393,13 +393,13 @@ class Controller extends Object {
$uses = is_array($this->uses) ? $this->uses : array($this->uses); $uses = is_array($this->uses) ? $this->uses : array($this->uses);
$this->modelClass = $uses[0]; $this->modelClass = $uses[0];
foreach($uses as $modelClass) { foreach ($uses as $modelClass) {
$id = false; $id = false;
$cached = false; $cached = false;
$object = null; $object = null;
$modelKey = Inflector::underscore($modelClass); $modelKey = Inflector::underscore($modelClass);
if(!class_exists($modelClass)){ if (!class_exists($modelClass)){
loadModel($plugin . $modelClass); loadModel($plugin . $modelClass);
} }
@ -538,11 +538,11 @@ class Controller extends Object {
$data = array($one => $two); $data = array($one => $two);
} }
foreach($data as $name => $value) { foreach ($data as $name => $value) {
if ($name == 'title') { if ($name == 'title') {
$this->pageTitle = $value; $this->pageTitle = $value;
} else { } else {
if($two === null) { if ($two === null) {
$this->viewVars[Inflector::variable($name)] = $value; $this->viewVars[Inflector::variable($name)] = $value;
} else { } else {
$this->viewVars[$name] = $value; $this->viewVars[$name] = $value;
@ -589,7 +589,7 @@ class Controller extends Object {
} }
$errors = array(); $errors = array();
foreach($objects as $object) { foreach ($objects as $object) {
$this->{$object->name}->set($object->data); $this->{$object->name}->set($object->data);
$errors = array_merge($errors, $this->{$object->name}->invalidFields()); $errors = array_merge($errors, $this->{$object->name}->invalidFields());
} }
@ -610,14 +610,14 @@ class Controller extends Object {
$viewClass = $this->view; $viewClass = $this->view;
if ($this->view != 'View') { if ($this->view != 'View') {
if(strpos($viewClass, '.') !== false){ if (strpos($viewClass, '.') !== false){
list($plugin, $viewClass) = explode('.', $viewClass); list($plugin, $viewClass) = explode('.', $viewClass);
} }
$viewClass = $viewClass . 'View'; $viewClass = $viewClass . 'View';
loadView($this->view); loadView($this->view);
} }
foreach($this->components as $c) { foreach ($this->components as $c) {
$path = preg_split('/\/|\./', $c); $path = preg_split('/\/|\./', $c);
$c = $path[count($path) - 1]; $c = $path[count($path) - 1];
if (isset($this->{$c}) && is_object($this->{$c}) && is_callable(array($this->{$c}, 'beforeRender'))) { if (isset($this->{$c}) && is_object($this->{$c}) && is_callable(array($this->{$c}, 'beforeRender'))) {
@ -631,7 +631,7 @@ class Controller extends Object {
$this->__viewClass =& new $viewClass($this); $this->__viewClass =& new $viewClass($this);
if (!empty($this->modelNames)) { if (!empty($this->modelNames)) {
$models = array(); $models = array();
foreach($this->modelNames as $currentModel) { foreach ($this->modelNames as $currentModel) {
if (isset($this->$currentModel) && is_a($this->$currentModel, 'Model')) { if (isset($this->$currentModel) && is_a($this->$currentModel, 'Model')) {
$models[] = Inflector::underscore($currentModel); $models[] = Inflector::underscore($currentModel);
} }
@ -640,10 +640,10 @@ class Controller extends Object {
} }
} }
$models = array_diff(ClassRegistry::keys(), $models); $models = array_diff(ClassRegistry::keys(), $models);
foreach($models as $currentModel) { foreach ($models as $currentModel) {
if (ClassRegistry::isKeySet($currentModel)) { if (ClassRegistry::isKeySet($currentModel)) {
$currentObject =& ClassRegistry::getObject($currentModel); $currentObject =& ClassRegistry::getObject($currentModel);
if(is_a($currentObject, 'Model') && !empty($currentObject->validationErrors)) { if (is_a($currentObject, 'Model') && !empty($currentObject->validationErrors)) {
$this->__viewClass->validationErrors[Inflector::camelize($currentModel)] =& $currentObject->validationErrors; $this->__viewClass->validationErrors[Inflector::camelize($currentModel)] =& $currentObject->validationErrors;
} }
} }
@ -667,7 +667,7 @@ class Controller extends Object {
if ($ref != null && defined('FULL_BASE_URL')) { if ($ref != null && defined('FULL_BASE_URL')) {
if (strpos($ref, $base) === 0) { if (strpos($ref, $base) === 0) {
return substr($ref, strlen($base) - 1); return substr($ref, strlen($base) - 1);
} elseif(!$local) { } elseif (!$local) {
return $ref; return $ref;
} }
} }
@ -726,11 +726,11 @@ class Controller extends Object {
$modelKey = $this->modelKey; $modelKey = $this->modelKey;
$modelObj =& ClassRegistry::getObject($modelKey); $modelObj =& ClassRegistry::getObject($modelKey);
foreach($modelObj->_tableInfo->value as $column) { foreach ($modelObj->_tableInfo->value as $column) {
$humanName = $column['name']; $humanName = $column['name'];
if ($modelObj->isForeignKey($column['name'])) { if ($modelObj->isForeignKey($column['name'])) {
foreach($modelObj->belongsTo as $associationName => $assoc) { foreach ($modelObj->belongsTo as $associationName => $assoc) {
if($column['name'] == $assoc['foreignKey']) { if ($column['name'] == $assoc['foreignKey']) {
$humanName = Inflector::underscore($associationName); $humanName = Inflector::underscore($associationName);
$fkNames = $modelObj->keyToTable[$column['name']]; $fkNames = $modelObj->keyToTable[$column['name']];
$fieldNames[$column['name']]['table'] = $fkNames[0]; $fieldNames[$column['name']]['table'] = $fkNames[0];
@ -794,7 +794,7 @@ class Controller extends Object {
case "float": case "float":
if (strcmp($column['name'], $this->$model->primaryKey) == 0) { if (strcmp($column['name'], $this->$model->primaryKey) == 0) {
$fieldNames[$column['name']]['type'] = 'hidden'; $fieldNames[$column['name']]['type'] = 'hidden';
} else if(isset($fieldNames[$column['name']]['foreignKey'])) { } elseif (isset($fieldNames[$column['name']]['foreignKey'])) {
$fieldNames[$column['name']]['type'] = 'select'; $fieldNames[$column['name']]['type'] = 'select';
$fieldNames[$column['name']]['options'] = array(); $fieldNames[$column['name']]['options'] = array();
@ -815,7 +815,7 @@ class Controller extends Object {
$fieldNames[$column['name']]['options'] = array(); $fieldNames[$column['name']]['options'] = array();
$enumValues = split(',', $fieldLength); $enumValues = split(',', $fieldLength);
foreach($enumValues as $enum) { foreach ($enumValues as $enum) {
$enum = trim($enum, "'"); $enum = trim($enum, "'");
$fieldNames[$column['name']]['options'][$enum] = $enum; $fieldNames[$column['name']]['options'][$enum] = $enum;
} }
@ -841,7 +841,7 @@ class Controller extends Object {
} }
} }
foreach($modelObj->hasAndBelongsToMany as $associationName => $assocData) { foreach ($modelObj->hasAndBelongsToMany as $associationName => $assocData) {
$otherModelKey = Inflector::underscore($assocData['className']); $otherModelKey = Inflector::underscore($assocData['className']);
$otherModelObj = &ClassRegistry::getObject($otherModelKey); $otherModelObj = &ClassRegistry::getObject($otherModelKey);
if ($doCreateOptions) { if ($doCreateOptions) {
@ -886,8 +886,8 @@ class Controller extends Object {
$op = ''; $op = '';
} }
foreach($data as $model => $fields) { foreach ($data as $model => $fields) {
foreach($fields as $field => $value) { foreach ($fields as $field => $value) {
$key = $model . '.' . $field; $key = $model . '.' . $field;
if (is_string($op)) { if (is_string($op)) {
$cond[$key] = $this->__postConditionMatch($op, $value); $cond[$key] = $this->__postConditionMatch($op, $value);
@ -942,16 +942,16 @@ class Controller extends Object {
if ($modelClass == null) { if ($modelClass == null) {
$modelClass = $this->modelClass; $modelClass = $this->modelClass;
} }
foreach($this->{$modelClass}->_tableInfo->value as $field) { foreach ($this->{$modelClass}->_tableInfo->value as $field) {
$useNewDate = false; $useNewDate = false;
$dateFields = array('Y'=>'_year', 'm'=>'_month', 'd'=>'_day', 'H'=>'_hour', 'i'=>'_min', 's'=>'_sec'); $dateFields = array('Y'=>'_year', 'm'=>'_month', 'd'=>'_day', 'H'=>'_hour', 'i'=>'_min', 's'=>'_sec');
foreach ($dateFields as $default => $var) { foreach ($dateFields as $default => $var) {
if(isset($this->data[$modelClass][$field['name'] . $var])) { if (isset($this->data[$modelClass][$field['name'] . $var])) {
${$var} = $this->data[$modelClass][$field['name'] . $var]; ${$var} = $this->data[$modelClass][$field['name'] . $var];
unset($this->data[$modelClass][$field['name'] . $var]); unset($this->data[$modelClass][$field['name'] . $var]);
$useNewDate = true; $useNewDate = true;
} else { } else {
if($var == 'year') { if ($var == 'year') {
${$var} = '0000'; ${$var} = '0000';
} else { } else {
${$var} = '00'; ${$var} = '00';
@ -969,12 +969,12 @@ class Controller extends Object {
$newDate = null; $newDate = null;
if (in_array($field['type'], array('datetime', 'timestamp')) && $useNewDate) { if (in_array($field['type'], array('datetime', 'timestamp')) && $useNewDate) {
$newDate = "{$_year}-{$_month}-{$_day} {$_hour}:{$_min}:{$_sec}"; $newDate = "{$_year}-{$_month}-{$_day} {$_hour}:{$_min}:{$_sec}";
} else if ('date' == $field['type'] && $useNewDate) { } elseif ('date' == $field['type'] && $useNewDate) {
$newDate = "{$_year}-{$_month}-{$_day}"; $newDate = "{$_year}-{$_month}-{$_day}";
} else if ('time' == $field['type'] && $useNewDate) { } elseif ('time' == $field['type'] && $useNewDate) {
$newDate = "{$_hour}:{$_min}:{$_sec}"; $newDate = "{$_hour}:{$_min}:{$_sec}";
} }
if($newDate && !in_array($field['name'], array('created', 'updated', 'modified'))) { if ($newDate && !in_array($field['name'], array('created', 'updated', 'modified'))) {
$this->data[$modelClass][$field['name']] = $newDate; $this->data[$modelClass][$field['name']] = $newDate;
} }
} }
@ -1050,7 +1050,7 @@ class Controller extends Object {
$keys = array_keys($options); $keys = array_keys($options);
$count = count($keys); $count = count($keys);
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if (!in_array($keys[$i], $vars)) { if (!in_array($keys[$i], $vars)) {
unset($options[$keys[$i]]); unset($options[$keys[$i]]);
} }
@ -1081,7 +1081,7 @@ class Controller extends Object {
} }
$pageCount = ceil($count / $limit); $pageCount = ceil($count / $limit);
if($page == 'last') { if ($page == 'last') {
$options['page'] = $page = $pageCount; $options['page'] = $page = $pageCount;
} }
@ -1173,18 +1173,18 @@ class Controller extends Object {
* @return unknown * @return unknown
*/ */
function _selectedArray($data, $key = 'id') { function _selectedArray($data, $key = 'id') {
if(!is_array($data)) { if (!is_array($data)) {
$model = $data; $model = $data;
if(!empty($this->data[$model][$model])) { if (!empty($this->data[$model][$model])) {
return $this->data[$model][$model]; return $this->data[$model][$model];
} }
if(!empty($this->data[$model])) { if (!empty($this->data[$model])) {
$data = $this->data[$model]; $data = $this->data[$model];
} }
} }
$array = array(); $array = array();
if(!empty($data)) { if (!empty($data)) {
foreach($data as $var) { foreach ($data as $var) {
$array[$var[$key]] = $var[$key]; $array[$var[$key]] = $var[$key];
} }
} }

View file

@ -149,7 +149,7 @@ class Scaffold extends Object {
$this->{$var} = $controller->{$var}; $this->{$var} = $controller->{$var};
} }
$this->redirect = array('action'=> 'index'); $this->redirect = array('action'=> 'index');
if(!is_null($this->plugin)) { if (!is_null($this->plugin)) {
$this->redirect = '/' . $this->plugin . '/' . $this->viewPath; $this->redirect = '/' . $this->plugin . '/' . $this->viewPath;
} }
@ -157,18 +157,18 @@ class Scaffold extends Object {
$this->controller->helpers[] = 'Form'; $this->controller->helpers[] = 'Form';
} }
if($this->controller->constructClasses() === false) { if ($this->controller->constructClasses() === false) {
return $this->cakeError('missingModel', array(array('className' => $this->modelKey, 'webroot' => '', 'base' => $this->controller->base))); return $this->cakeError('missingModel', array(array('className' => $this->modelKey, 'webroot' => '', 'base' => $this->controller->base)));
} }
if(!empty($controller->uses) && class_exists($controller->uses[0])) { if (!empty($controller->uses) && class_exists($controller->uses[0])) {
$controller->modelClass = $controller->uses[0]; $controller->modelClass = $controller->uses[0];
$controller->modelKey = Inflector::underscore($controller->modelClass); $controller->modelKey = Inflector::underscore($controller->modelClass);
} }
$this->modelClass = $controller->modelClass; $this->modelClass = $controller->modelClass;
$this->modelKey = $controller->modelKey; $this->modelKey = $controller->modelKey;
if(!is_object($this->controller->{$this->modelClass})) { if (!is_object($this->controller->{$this->modelClass})) {
return $this->cakeError('missingModel', array(array('className' => $this->modelClass, 'webroot' => '', 'base' => $controller->base))); return $this->cakeError('missingModel', array(array('className' => $this->modelClass, 'webroot' => '', 'base' => $controller->base)));
} }
$this->ScaffoldModel =& $this->controller->{$this->modelClass}; $this->ScaffoldModel =& $this->controller->{$this->modelClass};
@ -207,7 +207,7 @@ class Scaffold extends Object {
function __scaffoldView($params) { function __scaffoldView($params) {
if ($this->controller->_beforeScaffold('view')) { if ($this->controller->_beforeScaffold('view')) {
if(isset($params['pass'][0])){ if (isset($params['pass'][0])){
$this->ScaffoldModel->id = $params['pass'][0]; $this->ScaffoldModel->id = $params['pass'][0];
} elseif (isset($this->controller->Session) && $this->controller->Session->valid != false) { } elseif (isset($this->controller->Session) && $this->controller->Session->valid != false) {
$this->controller->Session->setFlash(sprintf(__("No id set for %s::view()", true), Inflector::humanize($this->modelKey))); $this->controller->Session->setFlash(sprintf(__("No id set for %s::view()", true), Inflector::humanize($this->modelKey)));
@ -279,7 +279,7 @@ class Scaffold extends Object {
$this->ScaffoldModel->id = $params['pass'][0]; $this->ScaffoldModel->id = $params['pass'][0];
} }
if(!empty($this->controller->data)) { if (!empty($this->controller->data)) {
$this->controller->cleanUpFields(); $this->controller->cleanUpFields();
@ -307,20 +307,20 @@ class Scaffold extends Object {
} }
if (empty($this->controller->data)) { if (empty($this->controller->data)) {
if($this->ScaffoldModel->id) { if ($this->ScaffoldModel->id) {
$this->controller->data = $this->ScaffoldModel->read(); $this->controller->data = $this->ScaffoldModel->read();
} else { } else {
$this->controller->data = $this->ScaffoldModel->create(); $this->controller->data = $this->ScaffoldModel->create();
} }
} }
$associations = am($this->ScaffoldModel->belongsTo, $this->ScaffoldModel->hasAndBelongsToMany); $associations = am($this->ScaffoldModel->belongsTo, $this->ScaffoldModel->hasAndBelongsToMany);
foreach($associations as $assocName => $assocData) { foreach ($associations as $assocName => $assocData) {
$this->controller->set(Inflector::pluralize(Inflector::variable($assocName)), $this->ScaffoldModel->{$assocName}->generateList()); $this->controller->set(Inflector::pluralize(Inflector::variable($assocName)), $this->ScaffoldModel->{$assocName}->generateList());
} }
return $this->__scaffoldForm($formAction); return $this->__scaffoldForm($formAction);
} else if($this->controller->_scaffoldError($action) === false) { } elseif ($this->controller->_scaffoldError($action) === false) {
return $this->__scaffoldError(); return $this->__scaffoldError();
} }
} }
@ -334,7 +334,7 @@ class Scaffold extends Object {
function __scaffoldDelete($params = array()) { function __scaffoldDelete($params = array()) {
if ($this->controller->_beforeScaffold('delete')) { if ($this->controller->_beforeScaffold('delete')) {
if(isset($params['pass'][0])){ if (isset($params['pass'][0])){
$id = $params['pass'][0]; $id = $params['pass'][0];
} elseif (isset($this->controller->Session) && $this->controller->Session->valid != false) { } elseif (isset($this->controller->Session) && $this->controller->Session->valid != false) {
$this->controller->Session->setFlash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey))); $this->controller->Session->setFlash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)));
@ -404,14 +404,14 @@ class Scaffold extends Object {
$db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig); $db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig);
if (isset($db)) { if (isset($db)) {
if(empty($this->scaffoldActions)) { if (empty($this->scaffoldActions)) {
$this->scaffoldActions = array('index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete'); $this->scaffoldActions = array('index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete');
} else if(defined('CAKE_ADMIN') && $this->scaffoldActions == CAKE_ADMIN) { } elseif (defined('CAKE_ADMIN') && $this->scaffoldActions == CAKE_ADMIN) {
$this->scaffoldActions = array(CAKE_ADMIN .'_index', CAKE_ADMIN .'_list', CAKE_ADMIN .'_view', CAKE_ADMIN .'_add', CAKE_ADMIN .'_create', CAKE_ADMIN .'_edit', CAKE_ADMIN .'_update', CAKE_ADMIN .'_delete'); $this->scaffoldActions = array(CAKE_ADMIN .'_index', CAKE_ADMIN .'_list', CAKE_ADMIN .'_view', CAKE_ADMIN .'_add', CAKE_ADMIN .'_create', CAKE_ADMIN .'_edit', CAKE_ADMIN .'_update', CAKE_ADMIN .'_delete');
} }
if (in_array($params['action'], $this->scaffoldActions)) { if (in_array($params['action'], $this->scaffoldActions)) {
if(defined('CAKE_ADMIN')) { if (defined('CAKE_ADMIN')) {
$params['action'] = str_replace(CAKE_ADMIN . '_', '', $params['action']); $params['action'] = str_replace(CAKE_ADMIN . '_', '', $params['action']);
} }
switch($params['action']) { switch($params['action']) {
@ -491,7 +491,7 @@ class Scaffold extends Object {
} }
} }
foreach($paths->viewPaths as $path) { foreach ($paths->viewPaths as $path) {
if (file_exists($path . $this->viewPath . DS . $this->subDir . $type . $scaffoldAction . $this->ext)) { if (file_exists($path . $this->viewPath . DS . $this->subDir . $type . $scaffoldAction . $this->ext)) {
return $path . $this->viewPath . DS . $this->subDir . $type . $scaffoldAction . $this->ext; return $path . $this->viewPath . DS . $this->subDir . $type . $scaffoldAction . $this->ext;
} elseif (file_exists($path . $this->viewPath . DS . 'scaffolds' . DS . $this->subDir . $type . $scaffoldAction . $this->ext)) { } elseif (file_exists($path . $this->viewPath . DS . 'scaffolds' . DS . $this->subDir . $type . $scaffoldAction . $this->ext)) {

View file

@ -55,12 +55,12 @@ class ErrorHandler extends Object{
static $__previousError = null; static $__previousError = null;
$allow = array('.', '/', '_', ' ', '-', '~'); $allow = array('.', '/', '_', ' ', '-', '~');
if(substr(PHP_OS,0,3) == "WIN") { if (substr(PHP_OS,0,3) == "WIN") {
$allow = array_merge($allow, array('\\', ':') ); $allow = array_merge($allow, array('\\', ':') );
} }
$clean = new Sanitize(); $clean = new Sanitize();
$messages = $clean->paranoid($messages, $allow); $messages = $clean->paranoid($messages, $allow);
if(!class_exists('dispatcher')) { if (!class_exists('dispatcher')) {
require CAKE . 'dispatcher.php'; require CAKE . 'dispatcher.php';
} }
$this->__dispatch =& new Dispatcher(); $this->__dispatch =& new Dispatcher();
@ -73,7 +73,7 @@ class ErrorHandler extends Object{
} }
$this->controller =& new AppController(); $this->controller =& new AppController();
if(!empty($this->controller->uses)) { if (!empty($this->controller->uses)) {
$this->controller->constructClasses(); $this->controller->constructClasses();
} }
$this->controller->_initComponents(); $this->controller->_initComponents();

View file

@ -137,10 +137,10 @@ class File extends Object{
* @access public * @access public
*/ */
function safe($name = null, $ext = null) { function safe($name = null, $ext = null) {
if(!$name) { if (!$name) {
$name = $this->name; $name = $this->name;
} }
if(!$ext) { if (!$ext) {
$ext = $this->ext(); $ext = $this->ext();
} }
return preg_replace( "/[^\w\.-]+/", "_", basename($name, $ext)); return preg_replace( "/[^\w\.-]+/", "_", basename($name, $ext));
@ -177,10 +177,10 @@ class File extends Object{
* @access public * @access public
*/ */
function info() { function info() {
if($this->info == null) { if ($this->info == null) {
$this->info = pathinfo($this->pwd()); $this->info = pathinfo($this->pwd());
} }
if(!isset($this->info['filename'])) { if (!isset($this->info['filename'])) {
$this->info['filename'] = $this->filename(); $this->info['filename'] = $this->filename();
} }
return $this->info; return $this->info;
@ -192,10 +192,10 @@ class File extends Object{
* @access public * @access public
*/ */
function ext() { function ext() {
if($this->info == null) { if ($this->info == null) {
$this->info(); $this->info();
} }
if(isset($this->info['extension'])) { if (isset($this->info['extension'])) {
return $this->info['extension']; return $this->info['extension'];
} }
return false; return false;
@ -207,10 +207,10 @@ class File extends Object{
* @access public * @access public
*/ */
function filename() { function filename() {
if($this->info == null) { if ($this->info == null) {
$this->info(); $this->info();
} }
if(isset($this->info['extension'])) { if (isset($this->info['extension'])) {
return basename($this->name, '.'.$this->info['extension']); return basename($this->name, '.'.$this->info['extension']);
} }
return false; return false;

View file

@ -98,14 +98,14 @@ class Flay extends Object{
$text=preg_replace('#[\n]{1}#', "%LINEBREAK%", $text); $text=preg_replace('#[\n]{1}#', "%LINEBREAK%", $text);
$out =''; $out ='';
foreach(split('%PARAGRAPH%', $text)as $line) { foreach (split('%PARAGRAPH%', $text)as $line) {
if ($line) { if ($line) {
if (!$bare) { if (!$bare) {
$links = array(); $links = array();
$regs = null; $regs = null;
if (preg_match_all('#\[([^\[]{4,})\]#', $line, $regs)) { if (preg_match_all('#\[([^\[]{4,})\]#', $line, $regs)) {
foreach($regs[1] as $reg) { foreach ($regs[1] as $reg) {
$links[] = $reg; $links[] = $reg;
$line = str_replace("[{$reg}]", '%LINK' . (count($links) - 1) . '%', $line); $line = str_replace("[{$reg}]", '%LINK' . (count($links) - 1) . '%', $line);
} }
@ -124,7 +124,7 @@ class Flay extends Object{
// guess e-mails // guess e-mails
$emails = null; $emails = null;
if (preg_match_all("#([_A-Za-z0-9+-+]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#", $line, $emails)) { if (preg_match_all("#([_A-Za-z0-9+-+]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#", $line, $emails)) {
foreach($emails[1] as $email) { foreach ($emails[1] as $email) {
$line = str_replace($email, "<a href=\"mailto:{$email}\">{$email}</a>", $line); $line = str_replace($email, "<a href=\"mailto:{$email}\">{$email}</a>", $line);
} }
} }
@ -132,19 +132,19 @@ class Flay extends Object{
if (!$bare) { if (!$bare) {
$urls = null; $urls = null;
if (preg_match_all("#((?:http|https|ftp|nntp)://[^ ]+)#", $line, $urls)) { if (preg_match_all("#((?:http|https|ftp|nntp)://[^ ]+)#", $line, $urls)) {
foreach($urls[1] as $url) { foreach ($urls[1] as $url) {
$line = str_replace($url, "<a href=\"{$url}\">{$url}</a>", $line); $line = str_replace($url, "<a href=\"{$url}\">{$url}</a>", $line);
} }
} }
if (preg_match_all("#(www\.[^\n\%\ ]+[^\n\%\,\.\ ])#", $line, $urls)) { if (preg_match_all("#(www\.[^\n\%\ ]+[^\n\%\,\.\ ])#", $line, $urls)) {
foreach($urls[1] as $url) { foreach ($urls[1] as $url) {
$line = str_replace($url, "<a href=\"http://{$url}\">{$url}</a>", $line); $line = str_replace($url, "<a href=\"http://{$url}\">{$url}</a>", $line);
} }
} }
if (count($links)) { if (count($links)) {
for($ii = 0; $ii < count($links); $ii++) { for ($ii = 0; $ii < count($links); $ii++) {
if (preg_match("#^(http|https|ftp|nntp)://#", $links[$ii])) { if (preg_match("#^(http|https|ftp|nntp)://#", $links[$ii])) {
$prefix = null; $prefix = null;
} else { } else {
@ -207,9 +207,9 @@ class Flay extends Object{
$string = strip_tags($string); $string = strip_tags($string);
$snips = array(); $snips = array();
$rest = $string; $rest = $string;
foreach($words as $word) { foreach ($words as $word) {
if (preg_match_all("/[\s,]+.{0,40}{$word}.{0,40}[\s,]+/i", $rest, $r)) { if (preg_match_all("/[\s,]+.{0,40}{$word}.{0,40}[\s,]+/i", $rest, $r)) {
foreach($r as $result) { foreach ($r as $result) {
$rest = str_replace($result, '', $rest); $rest = str_replace($result, '', $rest);
} }
$snips = array_merge($snips, $r[0]); $snips = array_merge($snips, $r[0]);
@ -234,7 +234,7 @@ class Flay extends Object{
function colorMark($words, $string) { function colorMark($words, $string) {
$colors=array('yl', 'gr', 'rd', 'bl', 'fu', 'cy'); $colors=array('yl', 'gr', 'rd', 'bl', 'fu', 'cy');
$nextColorIndex = 0; $nextColorIndex = 0;
foreach($words as $word) { foreach ($words as $word) {
$string = preg_replace("/({$word})/i", '<em class="' . $colors[$nextColorIndex % count($colors)] . "\">\\1</em>", $string); $string = preg_replace("/({$word})/i", '<em class="' . $colors[$nextColorIndex % count($colors)] . "\">\\1</em>", $string);
$nextColorIndex++; $nextColorIndex++;
} }

View file

@ -88,7 +88,7 @@ class Folder extends Object{
$path = TMP; $path = TMP;
} }
if($mode) { if ($mode) {
$this->mode = strval($mode); $this->mode = strval($mode);
} }
@ -115,10 +115,10 @@ class Folder extends Object{
*/ */
function cd($path) { function cd($path) {
$path = realpath($path); $path = realpath($path);
if(!$this->isAbsolute($path)) { if (!$this->isAbsolute($path)) {
$path = $this->addPathElement($this->path, $path); $path = $this->addPathElement($this->path, $path);
} }
if(is_dir($path) && file_exists($path)) { if (is_dir($path) && file_exists($path)) {
return $this->path = $path; return $this->path = $path;
} }
return false; return false;
@ -136,18 +136,18 @@ class Folder extends Object{
$dirs = $files = array(); $dirs = $files = array();
$dir = opendir($this->path); $dir = opendir($this->path);
if ($dir) { if ($dir) {
while(false !== ($n = readdir($dir))) { while (false !== ($n = readdir($dir))) {
$item = false; $item = false;
if(is_array($exceptions)) { if (is_array($exceptions)) {
if (!in_array($n, $exceptions)) { if (!in_array($n, $exceptions)) {
$item = $n; $item = $n;
} }
} else if ((!preg_match('#^\.+$#', $n) && $exceptions == false) || ($exceptions == true && !preg_match('#^\.(.*)$#', $n))) { } elseif ((!preg_match('#^\.+$#', $n) && $exceptions == false) || ($exceptions == true && !preg_match('#^\.(.*)$#', $n))) {
$item = $n; $item = $n;
} }
if ($item) { if ($item) {
if(is_dir($this->addPathElement($this->path, $item))) { if (is_dir($this->addPathElement($this->path, $item))) {
$dirs[] = $item; $dirs[] = $item;
} else { } else {
$files[] = $item; $files[] = $item;
@ -180,7 +180,7 @@ class Folder extends Object{
list($dirs, $files) = $data; list($dirs, $files) = $data;
$found = array(); $found = array();
foreach($files as $file) { foreach ($files as $file) {
if (preg_match("/^{$regexp_pattern}$/i", $file)) { if (preg_match("/^{$regexp_pattern}$/i", $file)) {
$found[] = $file; $found[] = $file;
} }
@ -211,13 +211,13 @@ class Folder extends Object{
list($dirs, $files) = $this->ls(); list($dirs, $files) = $this->ls();
$found = array(); $found = array();
foreach($files as $file) { foreach ($files as $file) {
if (preg_match("/^{$pattern}$/i", $file)) { if (preg_match("/^{$pattern}$/i", $file)) {
$found[] = $this->addPathElement($this->path, $file); $found[] = $this->addPathElement($this->path, $file);
} }
} }
$start = $this->path; $start = $this->path;
foreach($dirs as $dir) { foreach ($dirs as $dir) {
$this->cd($this->addPathElement($start, $dir)); $this->cd($this->addPathElement($start, $dir));
$found = array_merge($found, $this->findRecursive($pattern)); $found = array_merge($found, $this->findRecursive($pattern));
} }
@ -232,7 +232,7 @@ class Folder extends Object{
* @static * @static
*/ */
function isWindowsPath($path) { function isWindowsPath($path) {
if(preg_match('#^[A-Z]:\\\#i', $path)) { if (preg_match('#^[A-Z]:\\\#i', $path)) {
return true; return true;
} }
return false; return false;
@ -258,7 +258,7 @@ class Folder extends Object{
* @static * @static
*/ */
function isSlashTerm($path) { function isSlashTerm($path) {
if(preg_match('#[\\\/]$#', $path)) { if (preg_match('#[\\\/]$#', $path)) {
return true; return true;
} }
return false; return false;
@ -272,7 +272,7 @@ class Folder extends Object{
* @static * @static
*/ */
function normalizePath($path) { function normalizePath($path) {
if($this->isWindowsPath($path)) { if ($this->isWindowsPath($path)) {
return '\\'; return '\\';
} }
return '/'; return '/';
@ -285,8 +285,8 @@ class Folder extends Object{
* @access public * @access public
* @static * @static
*/ */
function correctSlashFor($path) { function correctSlashfor ($path) {
if($this->isWindowsPath($path)) { if ($this->isWindowsPath($path)) {
return '\\'; return '\\';
} }
return '/'; return '/';
@ -300,10 +300,10 @@ class Folder extends Object{
* @static * @static
*/ */
function slashTerm($path) { function slashTerm($path) {
if($this->isSlashTerm($path)) { if ($this->isSlashTerm($path)) {
return $path; return $path;
} }
return $path . $this->correctSlashFor($path); return $path . $this->correctSlashfor ($path);
} }
/** /**
* Returns $path with $element added, with correct slash in-between. * Returns $path with $element added, with correct slash in-between.
@ -352,7 +352,7 @@ class Folder extends Object{
*/ */
function chmod($path, $mode = false, $exceptions = false) { function chmod($path, $mode = false, $exceptions = false) {
if(!$mode) { if (!$mode) {
$mode = $this->mode; $mode = $this->mode;
} }
@ -361,14 +361,14 @@ class Folder extends Object{
} }
$dir = opendir($path); $dir = opendir($path);
if($dir) { if ($dir) {
while(false !== ($n = readdir($dir))) { while (false !== ($n = readdir($dir))) {
$item = false; $item = false;
if(is_array($exceptions)) { if (is_array($exceptions)) {
if (!in_array($n, $exceptions)) { if (!in_array($n, $exceptions)) {
$item = $n; $item = $n;
} }
} else if ((!preg_match('#^\.+$#', $n) && $exceptions == false) || ($exceptions == true && !preg_match('#^\.(.*)$#', $n))) { } elseif ((!preg_match('#^\.+$#', $n) && $exceptions == false) || ($exceptions == true && !preg_match('#^\.(.*)$#', $n))) {
$item = $n; $item = $n;
} }
@ -415,7 +415,7 @@ class Folder extends Object{
return true; return true;
} }
if(!$mode) { if (!$mode) {
$mode = $this->mode; $mode = $this->mode;
} }
@ -449,13 +449,13 @@ class Folder extends Object{
$directory = $this->slashTerm($this->path); $directory = $this->slashTerm($this->path);
$stack = array($directory); $stack = array($directory);
$count = count($stack); $count = count($stack);
for($i = 0, $j = $count; $i < $j; ++$i) { for ($i = 0, $j = $count; $i < $j; ++$i) {
if (is_file($stack[$i])) { if (is_file($stack[$i])) {
$size += filesize($stack[$i]); $size += filesize($stack[$i]);
} elseif (is_dir($stack[$i])) { } elseif (is_dir($stack[$i])) {
$dir = dir($stack[$i]); $dir = dir($stack[$i]);
if($dir) { if ($dir) {
while(false !== ($entry = $dir->read())) { while (false !== ($entry = $dir->read())) {
if ($entry == '.' || $entry == '..') { if ($entry == '.' || $entry == '..') {
continue; continue;
} }
@ -487,26 +487,26 @@ class Folder extends Object{
$normal_files = glob($path . "*"); $normal_files = glob($path . "*");
$hidden_files = glob($path . "\.?*"); $hidden_files = glob($path . "\.?*");
$files = array_merge($normal_files, $hidden_files); $files = array_merge($normal_files, $hidden_files);
if(is_array($files)) { if (is_array($files)) {
foreach ($files as $file) { foreach ($files as $file) {
if (preg_match("/(\.|\.\.)$/", $file)) { if (preg_match("/(\.|\.\.)$/", $file)) {
continue; continue;
} }
if (is_file($file) === true) { if (is_file($file) === true) {
if(unlink($file)) { if (unlink($file)) {
$this->__messages[] = sprintf(__('%s removed', true), $path); $this->__messages[] = sprintf(__('%s removed', true), $path);
} else { } else {
$this->__errors[] = sprintf(__('%s NOT removed', true), $path); $this->__errors[] = sprintf(__('%s NOT removed', true), $path);
} }
} elseif (is_dir($file) === true) { } elseif (is_dir($file) === true) {
if($this->delete($file) === false) { if ($this->delete($file) === false) {
return false; return false;
} }
} }
} }
} }
$path = substr($path, 0, strlen($path) - 1); $path = substr($path, 0, strlen($path) - 1);
if(rmdir($path) === false) { if (rmdir($path) === false) {
$this->__errors[] = sprintf(__('%s NOT removed', true), $path); $this->__errors[] = sprintf(__('%s NOT removed', true), $path);
return false; return false;
} else { } else {
@ -524,7 +524,7 @@ class Folder extends Object{
*/ */
function copy($options = array()) { function copy($options = array()) {
$to = null; $to = null;
if(is_string($options)) { if (is_string($options)) {
$to = $options; $to = $options;
$options = array(); $options = array();
} }
@ -539,7 +539,7 @@ class Folder extends Object{
return false; return false;
} }
if(!is_dir($toDir)) { if (!is_dir($toDir)) {
$this->mkdir($toDir, $mode); $this->mkdir($toDir, $mode);
} }
@ -550,7 +550,7 @@ class Folder extends Object{
$exceptions = am(array('.','..','.svn'), $options['skip']); $exceptions = am(array('.','..','.svn'), $options['skip']);
$handle = opendir($fromDir); $handle = opendir($fromDir);
if($handle) { if ($handle) {
while (false !== ($item = readdir($handle))) { while (false !== ($item = readdir($handle))) {
if (!in_array($item, $exceptions)) { if (!in_array($item, $exceptions)) {
$from = $this->addPathElement($fromDir, $item); $from = $this->addPathElement($fromDir, $item);
@ -582,7 +582,7 @@ class Folder extends Object{
return false; return false;
} }
if(!empty($this->__errors)) { if (!empty($this->__errors)) {
return false; return false;
} }
return true; return true;
@ -596,13 +596,13 @@ class Folder extends Object{
*/ */
function move($options) { function move($options) {
$to = null; $to = null;
if(is_string($options)) { if (is_string($options)) {
$to = $options; $to = $options;
} }
$options = am(array('to'=> $to, 'from'=> $this->path, 'mode'=> $this->mode, 'skip'=> array()), $options); $options = am(array('to'=> $to, 'from'=> $this->path, 'mode'=> $this->mode, 'skip'=> array()), $options);
if($this->copy($options)) { if ($this->copy($options)) {
if($this->delete($options['from'])) { if ($this->delete($options['from'])) {
return $this->cd($options['to']); return $this->cd($options['to']);
} }
} }

View file

@ -600,7 +600,7 @@ class HttpSocket extends CakeSocket {
$value = (int)$value; $value = (int)$value;
} }
if(preg_match_all('/\[([^\[\]]*)\]/iUs', $key, $matches)) { if (preg_match_all('/\[([^\[\]]*)\]/iUs', $key, $matches)) {
$subKeys = $matches[1]; $subKeys = $matches[1];
$rootKey = substr($key, 0, strpos($key, '[')); $rootKey = substr($key, 0, strpos($key, '['));
if (!empty($rootKey)) { if (!empty($rootKey)) {

View file

@ -107,24 +107,24 @@ class I18n extends Object {
$_this =& I18n::getInstance(); $_this =& I18n::getInstance();
$_this->category = $_this->__categories[$category]; $_this->category = $_this->__categories[$category];
if($_this->__l10n->found === false) { if ($_this->__l10n->found === false) {
$language = Configure::read('Config.language'); $language = Configure::read('Config.language');
if($language === null && !empty($_SESSION['Config']['language'])) { if ($language === null && !empty($_SESSION['Config']['language'])) {
$language = $_SESSION['Config']['language']; $language = $_SESSION['Config']['language'];
} }
$_this->__l10n->get($language); $_this->__l10n->get($language);
$_this->locale = $_this->__l10n->locale; $_this->locale = $_this->__l10n->locale;
} }
if(is_null($domain)) { if (is_null($domain)) {
if (preg_match('/views{0,1}\\'.DS.'([^\/]*)/', $directory, $regs)) { if (preg_match('/views{0,1}\\'.DS.'([^\/]*)/', $directory, $regs)) {
$domain = $regs[1]; $domain = $regs[1];
} elseif (preg_match('/controllers{0,1}\\'.DS.'([^\/]*)/', $directory, $regs)) { } elseif (preg_match('/controllers{0,1}\\'.DS.'([^\/]*)/', $directory, $regs)) {
$domain = $regs[1]; $domain = $regs[1];
} }
if(isset($domain) && $domain == 'templates') { if (isset($domain) && $domain == 'templates') {
if (preg_match('/templates{0,1}\\'.DS.'([^\/]*)/', $directory, $regs)) { if (preg_match('/templates{0,1}\\'.DS.'([^\/]*)/', $directory, $regs)) {
$domain = $regs[1]; $domain = $regs[1];
} }
@ -132,7 +132,7 @@ class I18n extends Object {
$directory = null; $directory = null;
} }
if(!isset($_this->__domains[$_this->category][$domain])) { if (!isset($_this->__domains[$_this->category][$domain])) {
$_this->__bindTextDomain($domain, $directory); $_this->__bindTextDomain($domain, $directory);
} }
@ -149,7 +149,7 @@ class I18n extends Object {
} }
} }
if(!empty($_this->__domains[$_this->category][$domain][$singular])) { if (!empty($_this->__domains[$_this->category][$domain][$singular])) {
if (($trans = $_this->__domains[$_this->category][$domain][$singular]) || ($pli) && ($trans = $_this->__domains[$_this->category][$domain][$plural])) { if (($trans = $_this->__domains[$_this->category][$domain][$singular]) || ($pli) && ($trans = $_this->__domains[$_this->category][$domain][$plural])) {
if (is_array($trans)) { if (is_array($trans)) {
if (!isset($trans[$pli])) { if (!isset($trans[$pli])) {
@ -164,7 +164,7 @@ class I18n extends Object {
} }
} }
if(!empty($pli)) { if (!empty($pli)) {
return($plural); return($plural);
} }
return($singular); return($singular);
@ -308,7 +308,7 @@ class I18n extends Object {
function __bindTextDomain($domain, $directory = null) { function __bindTextDomain($domain, $directory = null) {
$_this =& I18n::getInstance(); $_this =& I18n::getInstance();
$_this->__noLocale = true; $_this->__noLocale = true;
if(is_null($directory)) { if (is_null($directory)) {
$searchPath[] = APP . 'locale'; $searchPath[] = APP . 'locale';
$searchPath[] = CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'locale'; $searchPath[] = CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'locale';
} else { } else {
@ -349,7 +349,7 @@ class I18n extends Object {
} }
} }
if(empty($_this->__domains[$_this->category][$domain])) { if (empty($_this->__domains[$_this->category][$domain])) {
return($domain); return($domain);
} }
@ -360,7 +360,7 @@ class I18n extends Object {
$_this->__domains[$_this->category][$domain]["%po-header"][strtolower($header)] = $line; $_this->__domains[$_this->category][$domain]["%po-header"][strtolower($header)] = $line;
} }
if(isset($_this->__domains[$_this->category][$domain]["%po-header"]["plural-forms"])) { if (isset($_this->__domains[$_this->category][$domain]["%po-header"]["plural-forms"])) {
$switch = preg_replace("/[(){}\\[\\]^\\s*\\]]+/", "", $_this->__domains[$_this->category][$domain]["%po-header"]["plural-forms"]); $switch = preg_replace("/[(){}\\[\\]^\\s*\\]]+/", "", $_this->__domains[$_this->category][$domain]["%po-header"]["plural-forms"]);
$_this->__domains[$_this->category][$domain]["%plural-c"] = $switch; $_this->__domains[$_this->category][$domain]["%plural-c"] = $switch;
} }

View file

@ -188,7 +188,7 @@ class Inflector extends Object {
return $word; return $word;
} }
foreach($pluralRules as $rule => $replacement) { foreach ($pluralRules as $rule => $replacement) {
if (preg_match($rule, $word)) { if (preg_match($rule, $word)) {
$_this->pluralized[$word] = preg_replace($rule, $replacement, $word); $_this->pluralized[$word] = preg_replace($rule, $replacement, $word);
return $_this->pluralized[$word]; return $_this->pluralized[$word];
@ -328,7 +328,7 @@ class Inflector extends Object {
return $word; return $word;
} }
foreach($singularRules as $rule => $replacement) { foreach ($singularRules as $rule => $replacement) {
if (preg_match($rule, $word)) { if (preg_match($rule, $word)) {
$_this->singularized[$word] = preg_replace($rule, $replacement, $word); $_this->singularized[$word] = preg_replace($rule, $replacement, $word);
return $_this->singularized[$word]; return $_this->singularized[$word];

View file

@ -372,7 +372,7 @@ class L10n extends Object {
$this->charset = $this->__l10nCatalog[$this->__l10nMap[DEFAULT_LANGUAGE]]['charset']; $this->charset = $this->__l10nCatalog[$this->__l10nMap[DEFAULT_LANGUAGE]]['charset'];
} }
if($this->default) { if ($this->default) {
$this->languagePath[2] = $this->__l10nCatalog[$this->default]['localeFallback']; $this->languagePath[2] = $this->__l10nCatalog[$this->default]['localeFallback'];
} }
$this->found = true; $this->found = true;
@ -398,7 +398,7 @@ class L10n extends Object {
$this->locale = $this->__l10nCatalog[$langKey]['locale']; $this->locale = $this->__l10nCatalog[$langKey]['locale'];
$this->charset = $this->__l10nCatalog[$langKey]['charset']; $this->charset = $this->__l10nCatalog[$langKey]['charset'];
if($this->default) { if ($this->default) {
$this->languagePath[2] = $this->__l10nCatalog[$this->default]['localeFallback']; $this->languagePath[2] = $this->__l10nCatalog[$this->default]['localeFallback'];
} }
$this->found = true; $this->found = true;

View file

@ -70,7 +70,7 @@ class TranslateBehavior extends ModelBehavior {
$this->runtime[$model->name] = array('fields' => array()); $this->runtime[$model->name] = array('fields' => array());
$db =& ConnectionManager::getDataSource($model->useDbConfig); $db =& ConnectionManager::getDataSource($model->useDbConfig);
if(!$db->connected) { if (!$db->connected) {
trigger_error('Datasource '.$model->useDbConfig.' for I18nBehavior of model '.$model->name.' is not connected', E_USER_ERROR); trigger_error('Datasource '.$model->useDbConfig.' for I18nBehavior of model '.$model->name.' is not connected', E_USER_ERROR);
return false; return false;
} }
@ -83,7 +83,7 @@ class TranslateBehavior extends ModelBehavior {
function beforeFind(&$model, $query) { function beforeFind(&$model, $query) {
$locale = $this->_getLocale($model); $locale = $this->_getLocale($model);
if(is_string($query['fields']) && 'COUNT(*) AS count' == $query['fields']) { if (is_string($query['fields']) && 'COUNT(*) AS count' == $query['fields']) {
$this->runtime[$model->name]['count'] = true; $this->runtime[$model->name]['count'] = true;
$db =& ConnectionManager::getDataSource($model->useDbConfig); $db =& ConnectionManager::getDataSource($model->useDbConfig);
@ -103,21 +103,21 @@ class TranslateBehavior extends ModelBehavior {
return $query; return $query;
} }
if(empty($locale) || is_array($locale)) { if (empty($locale) || is_array($locale)) {
return $query; return $query;
} }
$autoFields = false; $autoFields = false;
if(empty($query['fields'])) { if (empty($query['fields'])) {
$query['fields'] = array($model->name.'.*'); $query['fields'] = array($model->name.'.*');
foreach(array('hasOne', 'belongsTo') as $type) { foreach (array('hasOne', 'belongsTo') as $type) {
foreach($model->{$type} as $key => $value) { foreach ($model->{$type} as $key => $value) {
if(empty($value['fields'])) { if (empty($value['fields'])) {
$query['fields'][] = $key.'.*'; $query['fields'][] = $key.'.*';
} else { } else {
foreach($value['fields'] as $field) { foreach ($value['fields'] as $field) {
$query['fields'][] = $key.'.'.$field; $query['fields'][] = $key.'.'.$field;
} }
} }
@ -130,27 +130,27 @@ class TranslateBehavior extends ModelBehavior {
$tablePrefix = $this->runtime[$model->name]['tablePrefix']; $tablePrefix = $this->runtime[$model->name]['tablePrefix'];
$addFields = array(); $addFields = array();
if(is_array($query['fields'])) { if (is_array($query['fields'])) {
if(in_array($model->name.'.*', $query['fields'])) { if (in_array($model->name.'.*', $query['fields'])) {
foreach($fields as $key => $value) { foreach ($fields as $key => $value) {
$addFields[] = ife(is_numeric($key), $value, $key); $addFields[] = ife(is_numeric($key), $value, $key);
} }
} else { } else {
foreach($fields as $key => $value) { foreach ($fields as $key => $value) {
$field = ife(is_numeric($key), $value, $key); $field = ife(is_numeric($key), $value, $key);
if($autoFields || in_array($model->name.'.'.$field, $query['fields']) || in_array($field, $query['fields'])) { if ($autoFields || in_array($model->name.'.'.$field, $query['fields']) || in_array($field, $query['fields'])) {
$addFields[] = $field; $addFields[] = $field;
} }
} }
} }
} }
if($addFields) { if ($addFields) {
$db =& ConnectionManager::getDataSource($model->useDbConfig); $db =& ConnectionManager::getDataSource($model->useDbConfig);
foreach($addFields as $field) { foreach ($addFields as $field) {
$key = array_search($model->name.'.'.$field, $query['fields']); $key = array_search($model->name.'.'.$field, $query['fields']);
if(false !== $key) { if (false !== $key) {
unset($query['fields'][$key]); unset($query['fields'][$key]);
} }
@ -171,38 +171,38 @@ class TranslateBehavior extends ModelBehavior {
* Callback * Callback
*/ */
function afterFind(&$model, $results, $primary) { function afterFind(&$model, $results, $primary) {
if(!empty($this->runtime[$model->name]['count'])) { if (!empty($this->runtime[$model->name]['count'])) {
unset($this->runtime[$model->name]['count']); unset($this->runtime[$model->name]['count']);
return $results; return $results;
} }
$this->runtime[$model->name]['fields'] = array(); $this->runtime[$model->name]['fields'] = array();
$locale = $this->_getLocale($model); $locale = $this->_getLocale($model);
if(empty($locale) || empty($results)) { if (empty($locale) || empty($results)) {
return $results; return $results;
} }
if(is_array($locale)) { if (is_array($locale)) {
$fields = am($this->settings[$model->name], $this->runtime[$model->name]['fields']); $fields = am($this->settings[$model->name], $this->runtime[$model->name]['fields']);
$emptyFields = array('locale' => ''); $emptyFields = array('locale' => '');
foreach($fields as $key => $value) { foreach ($fields as $key => $value) {
$field = ife(is_numeric($key), $value, $key); $field = ife(is_numeric($key), $value, $key);
$emptyFields[$field] = ''; $emptyFields[$field] = '';
} }
unset($fields); unset($fields);
foreach($results as $key => $row) { foreach ($results as $key => $row) {
$results[$key][$model->name] = am($results[$key][$model->name], $emptyFields); $results[$key][$model->name] = am($results[$key][$model->name], $emptyFields);
} }
unset($emptyFields); unset($emptyFields);
} elseif(!empty($this->runtime[$model->name]['beforeFind'])) { } elseif (!empty($this->runtime[$model->name]['beforeFind'])) {
$beforeFind = $this->runtime[$model->name]['beforeFind']; $beforeFind = $this->runtime[$model->name]['beforeFind'];
foreach($results as $key => $row) { foreach ($results as $key => $row) {
$results[$key][$model->name]['locale'] = $locale; $results[$key][$model->name]['locale'] = $locale;
foreach($beforeFind as $field) { foreach ($beforeFind as $field) {
$value = ife(empty($results[$key]['I18n__'.$field]['content']), '', $results[$key]['I18n__'.$field]['content']); $value = ife(empty($results[$key]['I18n__'.$field]['content']), '', $results[$key]['I18n__'.$field]['content']);
$results[$key][$model->name][$field] = $value; $results[$key][$model->name][$field] = $value;
unset($results[$key]['I18n__'.$field]); unset($results[$key]['I18n__'.$field]);
@ -217,16 +217,16 @@ class TranslateBehavior extends ModelBehavior {
function beforeSave(&$model) { function beforeSave(&$model) {
$locale = $this->_getLocale($model); $locale = $this->_getLocale($model);
if(empty($locale) || is_array($locale)) { if (empty($locale) || is_array($locale)) {
return true; return true;
} }
$fields = am($this->settings[$model->name], $this->runtime[$model->name]['fields']); $fields = am($this->settings[$model->name], $this->runtime[$model->name]['fields']);
$tempData = array(); $tempData = array();
foreach($fields as $key => $value) { foreach ($fields as $key => $value) {
$field = ife(is_numeric($key), $value, $key); $field = ife(is_numeric($key), $value, $key);
if(isset($model->data[$model->name][$field])) { if (isset($model->data[$model->name][$field])) {
$tempData[$field] = $model->data[$model->name][$field]; $tempData[$field] = $model->data[$model->name][$field];
unset($model->data[$model->name][$field]); unset($model->data[$model->name][$field]);
} }
@ -242,7 +242,7 @@ class TranslateBehavior extends ModelBehavior {
function afterSave(&$model, $created) { function afterSave(&$model, $created) {
$locale = $this->_getLocale($model); $locale = $this->_getLocale($model);
if(empty($locale) || is_array($locale) || empty($this->runtime[$model->name]['beforeSave'])) { if (empty($locale) || is_array($locale) || empty($this->runtime[$model->name]['beforeSave'])) {
return true; return true;
} }
$tempData = $this->runtime[$model->name]['beforeSave']; $tempData = $this->runtime[$model->name]['beforeSave'];
@ -252,8 +252,8 @@ class TranslateBehavior extends ModelBehavior {
'model' => $model->name, 'model' => $model->name,
'row_id' => $model->id); 'row_id' => $model->id);
if($created) { if ($created) {
foreach($tempData as $field => $value) { foreach ($tempData as $field => $value) {
$this->_model->Content->create(); $this->_model->Content->create();
$this->_model->Content->save(array('I18nContent' => array('content' => $value))); $this->_model->Content->save(array('I18nContent' => array('content' => $value)));
@ -268,8 +268,8 @@ class TranslateBehavior extends ModelBehavior {
$fields = Set::extract($translations, '{n}.I18nModel.field'); $fields = Set::extract($translations, '{n}.I18nModel.field');
$ids = Set::extract($translations, '{n}.I18nModel.i18n_content_id'); $ids = Set::extract($translations, '{n}.I18nModel.i18n_content_id');
foreach($fields as $key => $field) { foreach ($fields as $key => $field) {
if(array_key_exists($field, $tempData)) { if (array_key_exists($field, $tempData)) {
$this->_model->Content->create(); $this->_model->Content->create();
$this->_model->Content->save(array('I18nContent' => array( $this->_model->Content->save(array('I18nContent' => array(
'id' => $ids[$key], 'id' => $ids[$key],
@ -322,7 +322,7 @@ class TranslateBehavior extends ModelBehavior {
* @return mixed string or false * @return mixed string or false
*/ */
function _getLocale(&$model) { function _getLocale(&$model) {
if(!isset($model->locale) || is_null($model->locale)) { if (!isset($model->locale) || is_null($model->locale)) {
$model->locale = $this->_autoDetectLocale(); $model->locale = $this->_autoDetectLocale();
} }
return $model->locale; return $model->locale;
@ -338,11 +338,11 @@ class TranslateBehavior extends ModelBehavior {
* @return boolean * @return boolean
*/ */
function bindTranslation(&$model, $fields, $reset = true) { function bindTranslation(&$model, $fields, $reset = true) {
if(empty($fields)) { if (empty($fields)) {
return true; return true;
} }
if(is_string($fields)) { if (is_string($fields)) {
$fields = array($fields); $fields = array($fields);
} }
$settings =& $this->settings[$model->name]; $settings =& $this->settings[$model->name];
@ -351,9 +351,9 @@ class TranslateBehavior extends ModelBehavior {
$default = array('className' => 'I18nModel', 'foreignKey' => 'row_id'); $default = array('className' => 'I18nModel', 'foreignKey' => 'row_id');
foreach($fields as $key => $value) { foreach ($fields as $key => $value) {
if(is_numeric($key)) { if (is_numeric($key)) {
$field = $value; $field = $value;
$association = null; $association = null;
} else { } else {
@ -361,33 +361,33 @@ class TranslateBehavior extends ModelBehavior {
$association = $value; $association = $value;
} }
if(in_array($field, $settings)) { if (in_array($field, $settings)) {
$this->settings[$model->name] = array_diff_assoc($settings, array($field)); $this->settings[$model->name] = array_diff_assoc($settings, array($field));
} elseif(array_key_exists($field, $settings)) { } elseif (array_key_exists($field, $settings)) {
unset($settings[$field]); unset($settings[$field]);
} }
if(in_array($field, $runtime)) { if (in_array($field, $runtime)) {
$this->runtime[$model->name]['fields'] = array_diff_assoc($runtime, array($field)); $this->runtime[$model->name]['fields'] = array_diff_assoc($runtime, array($field));
} elseif(array_key_exists($field, $runtime)) { } elseif (array_key_exists($field, $runtime)) {
unset($runtime[$field]); unset($runtime[$field]);
} }
if(is_null($association)) { if (is_null($association)) {
if($reset) { if ($reset) {
$runtime[] = $field; $runtime[] = $field;
} else { } else {
$settings[] = $field; $settings[] = $field;
} }
} else { } else {
if($reset) { if ($reset) {
$runtime[$field] = $association; $runtime[$field] = $association;
} else { } else {
$settings[$field] = $association; $settings[$field] = $association;
} }
foreach(array('hasOne', 'hasMany', 'belongsTo', 'hasAndBelongsToMany') as $type) { foreach (array('hasOne', 'hasMany', 'belongsTo', 'hasAndBelongsToMany') as $type) {
if(isset($model->{$type}[$association]) || isset($model->__backAssociation[$type][$association])) { if (isset($model->{$type}[$association]) || isset($model->__backAssociation[$type][$association])) {
trigger_error('Association '.$association.' is already binded to model '.$model->name, E_USER_ERROR); trigger_error('Association '.$association.' is already binded to model '.$model->name, E_USER_ERROR);
return false; return false;
} }
@ -398,7 +398,7 @@ class TranslateBehavior extends ModelBehavior {
} }
} }
if(!empty($associations)) { if (!empty($associations)) {
$model->bindModel(array('hasMany' => $associations), $reset); $model->bindModel(array('hasMany' => $associations), $reset);
} }
return true; return true;
@ -412,11 +412,11 @@ class TranslateBehavior extends ModelBehavior {
* @return boolean * @return boolean
*/ */
function unbindTranslation(&$model, $fields) { function unbindTranslation(&$model, $fields) {
if(empty($fields)) { if (empty($fields)) {
return true; return true;
} }
if(is_string($fields)) { if (is_string($fields)) {
$fields = array($fields); $fields = array($fields);
} }
$settings =& $this->settings[$model->name]; $settings =& $this->settings[$model->name];
@ -425,8 +425,8 @@ class TranslateBehavior extends ModelBehavior {
$default = array('className' => 'I18nModel', 'foreignKey' => 'row_id'); $default = array('className' => 'I18nModel', 'foreignKey' => 'row_id');
$associations = array(); $associations = array();
foreach($fields as $key => $value) { foreach ($fields as $key => $value) {
if(is_numeric($key)) { if (is_numeric($key)) {
$field = $value; $field = $value;
$association = null; $association = null;
} else { } else {
@ -434,24 +434,24 @@ class TranslateBehavior extends ModelBehavior {
$association = $value; $association = $value;
} }
if(in_array($field, $settings)) { if (in_array($field, $settings)) {
$this->settings[$model->name] = array_diff_assoc($settings, array($field)); $this->settings[$model->name] = array_diff_assoc($settings, array($field));
} elseif (array_key_exists($field, $settings)) { } elseif (array_key_exists($field, $settings)) {
unset($settings[$field]); unset($settings[$field]);
} }
if(in_array($field, $runtime)) { if (in_array($field, $runtime)) {
$this->runtime[$model->name]['fields'] = array_diff_assoc($runtime, array($field)); $this->runtime[$model->name]['fields'] = array_diff_assoc($runtime, array($field));
} elseif(array_key_exists($field, $runtime)) { } elseif (array_key_exists($field, $runtime)) {
unset($runtime[$field]); unset($runtime[$field]);
} }
if(!is_null($association) && (isset($model->hasMany[$association]) || isset($model->__backAssociation['hasMany'][$association]))) { if (!is_null($association) && (isset($model->hasMany[$association]) || isset($model->__backAssociation['hasMany'][$association]))) {
$associations[] = $association; $associations[] = $association;
} }
} }
if(!empty($associations)) { if (!empty($associations)) {
$model->unbindModel(array('hasMany' => $associations), false); $model->unbindModel(array('hasMany' => $associations), false);
} }
return true; return true;

View file

@ -155,9 +155,9 @@ class ConnectionManager extends Object {
return false; return false;
} }
if(file_exists(MODELS . 'datasources' . DS . $conn['filename'] . '.php')) { if (file_exists(MODELS . 'datasources' . DS . $conn['filename'] . '.php')) {
require (MODELS . 'datasources' . DS . $conn['filename'] . '.php'); require (MODELS . 'datasources' . DS . $conn['filename'] . '.php');
} else if (fileExistsInPath(LIBS . 'model' . DS . 'datasources' . DS . $conn['filename'] . '.php')) { } elseif (fileExistsInPath(LIBS . 'model' . DS . 'datasources' . DS . $conn['filename'] . '.php')) {
require (LIBS . 'model' . DS . 'datasources' . DS . $conn['filename'] . '.php'); require (LIBS . 'model' . DS . 'datasources' . DS . $conn['filename'] . '.php');
} else { } else {
trigger_error(sprintf(__('Unable to load DataSource file %s.php', true), $conn['filename']), E_USER_ERROR); trigger_error(sprintf(__('Unable to load DataSource file %s.php', true), $conn['filename']), E_USER_ERROR);
@ -179,7 +179,7 @@ class ConnectionManager extends Object {
$connections = get_object_vars($_this->config); $connections = get_object_vars($_this->config);
if ($connections != null) { if ($connections != null) {
foreach($connections as $name => $config) { foreach ($connections as $name => $config) {
$_this->_connectionsEnum[$name] = $_this->__getDriver($config); $_this->_connectionsEnum[$name] = $_this->__getDriver($config);
} }
return $_this->_connectionsEnum; return $_this->_connectionsEnum;

View file

@ -214,7 +214,7 @@ class DataSource extends Object {
function setConfig($config) { function setConfig($config) {
if (is_array($this->_baseConfig)) { if (is_array($this->_baseConfig)) {
$this->config = $this->_baseConfig; $this->config = $this->_baseConfig;
foreach($config as $key => $val) { foreach ($config as $key => $val) {
$this->config[$key] = $val; $this->config[$key] = $val;
} }
} }
@ -227,7 +227,7 @@ class DataSource extends Object {
* @return void * @return void
*/ */
function __cacheDescription($object, $data = null) { function __cacheDescription($object, $data = null) {
if($this->cacheSources === false){ if ($this->cacheSources === false){
return null; return null;
} }
if (Configure::read() > 0) { if (Configure::read() > 0) {
@ -282,7 +282,7 @@ class DataSource extends Object {
* @return mixed * @return mixed
*/ */
function describe($model) { function describe($model) {
if($this->cacheSources === false){ if ($this->cacheSources === false){
return null; return null;
} }
@ -374,7 +374,7 @@ class DataSource extends Object {
function insertQueryData($query, $data, $association, $assocData, &$model, &$linkModel, $stack) { function insertQueryData($query, $data, $association, $assocData, &$model, &$linkModel, $stack) {
$keys = array('{$__cakeID__$}', '{$__cakeForeignKey__$}'); $keys = array('{$__cakeID__$}', '{$__cakeForeignKey__$}');
foreach($keys as $key) { foreach ($keys as $key) {
$val = null; $val = null;
if (strpos($query, $key) !== false) { if (strpos($query, $key) !== false) {
@ -401,8 +401,8 @@ class DataSource extends Object {
} }
break; break;
case '{$__cakeForeignKey__$}': case '{$__cakeForeignKey__$}':
foreach($model->__associations as $id => $name) { foreach ($model->__associations as $id => $name) {
foreach($model->$name as $assocName => $assoc) { foreach ($model->$name as $assocName => $assoc) {
if ($assocName === $association) { if ($assocName === $association) {
if (isset($assoc['foreignKey'])) { if (isset($assoc['foreignKey'])) {
$foreignKey = $assoc['foreignKey']; $foreignKey = $assoc['foreignKey'];
@ -431,7 +431,7 @@ class DataSource extends Object {
} }
break; break;
} }
if(empty($val) && $val !== '0') { if (empty($val) && $val !== '0') {
return false; return false;
} }
$query = r($key, $this->value($val, $model->getColumnType($model->primaryKey)), $query); $query = r($key, $this->value($val, $model->getColumnType($model->primaryKey)), $query);

View file

@ -220,7 +220,7 @@ class DboAdodb extends DboSource {
$fields = false; $fields = false;
$cols = $this->_adodb->MetaColumns($this->fullTableName($model, false)); $cols = $this->_adodb->MetaColumns($this->fullTableName($model, false));
foreach($cols as $column) { foreach ($cols as $column) {
$fields[] = array('name' => $column->name, $fields[] = array('name' => $column->name,
'type' => $this->column($column->type)); 'type' => $this->column($column->type));
} }
@ -347,7 +347,7 @@ class DboAdodb extends DboSource {
} }
$fields = array_map('trim', $fields); $fields = array_map('trim', $fields);
} else { } else {
foreach($model->_tableInfo->value as $field) { foreach ($model->_tableInfo->value as $field) {
$fields[] = $field['name']; $fields[] = $field['name'];
} }
} }
@ -356,7 +356,7 @@ class DboAdodb extends DboSource {
$count = count($fields); $count = count($fields);
if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false) { if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false) {
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if (!preg_match('/^.+\\(.*\\)/', $fields[$i])) { if (!preg_match('/^.+\\(.*\\)/', $fields[$i])) {
$prepend = ''; $prepend = '';
if (strpos($fields[$i], 'DISTINCT') !== false) { if (strpos($fields[$i], 'DISTINCT') !== false) {
@ -389,7 +389,7 @@ class DboAdodb extends DboSource {
$index = 0; $index = 0;
$j = 0; $j = 0;
while($j < $num_fields) { while ($j < $num_fields) {
$columnName = $fields[$j]; $columnName = $fields[$j];
if (strpos($columnName, '__')) { if (strpos($columnName, '__')) {

View file

@ -358,7 +358,7 @@ class DboDb2 extends DboSource {
* @return array * @return array
*/ */
function update(&$model, $fields = array(), $values = array()) { function update(&$model, $fields = array(), $values = array()) {
foreach($fields as $i => $field) { foreach ($fields as $i => $field) {
if ($field == $model->primaryKey) { if ($field == $model->primaryKey) {
unset ($fields[$i]); unset ($fields[$i]);
unset ($values[$i]); unset ($values[$i]);
@ -377,7 +377,7 @@ class DboDb2 extends DboSource {
function lastError() { function lastError() {
if (db2_stmt_error()) { if (db2_stmt_error()) {
return db2_stmt_error() . ': ' . db2_stmt_errormsg(); return db2_stmt_error() . ': ' . db2_stmt_errormsg();
} else if (db2_conn_error()) { } elseif (db2_conn_error()) {
return db2_conn_error() . ': ' . db2_conn_errormsg(); return db2_conn_error() . ': ' . db2_conn_errormsg();
} }
return null; return null;

View file

@ -280,7 +280,7 @@ class DboFirebird extends DboSource {
* @return array * @return array
*/ */
function update(&$model, $fields = array(), $values = array()) { function update(&$model, $fields = array(), $values = array()) {
foreach($fields as $i => $field) { foreach ($fields as $i => $field) {
if ($field == $model->primaryKey) { if ($field == $model->primaryKey) {
unset ($fields[$i]); unset ($fields[$i]);
unset ($values[$i]); unset ($values[$i]);
@ -445,7 +445,7 @@ class DboFirebird extends DboSource {
$index = 0; $index = 0;
$j = 0; $j = 0;
while($j < $num_fields) { while ($j < $num_fields) {
$column = ibase_field_info($results, $j); $column = ibase_field_info($results, $j);
$this->map[$index++] = array(ucfirst(strtolower($this->modeltmp)), strtolower($column[1])); $this->map[$index++] = array(ucfirst(strtolower($this->modeltmp)), strtolower($column[1]));
$j++; $j++;
@ -481,7 +481,7 @@ class DboFirebird extends DboSource {
$resultRow = array(); $resultRow = array();
$i = 0; $i = 0;
foreach($row as $index => $field) { foreach ($row as $index => $field) {
list($table, $column) = $this->map[$index]; list($table, $column) = $this->map[$index];
if (trim($table) == "") { if (trim($table) == "") {

View file

@ -180,7 +180,7 @@ class DboMssql extends DboSource {
} else { } else {
$tables = array(); $tables = array();
foreach($result as $table) { foreach ($result as $table) {
$tables[] = $table[0]['TABLE_NAME']; $tables[] = $table[0]['TABLE_NAME'];
} }
@ -204,7 +204,7 @@ class DboMssql extends DboSource {
$fields = false; $fields = false;
$cols = $this->fetchAll("SELECT COLUMN_NAME as Field, DATA_TYPE as Type, COL_LENGTH('" . $this->fullTableName($model, false) . "', COLUMN_NAME) as Length, IS_NULLABLE As [Null], COLUMN_DEFAULT as [Default], COLUMNPROPERTY(OBJECT_ID('" . $this->fullTableName($model, false) . "'), COLUMN_NAME, 'IsIdentity') as [Key], NUMERIC_SCALE as Size FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" . $this->fullTableName($model, false) . "'", false); $cols = $this->fetchAll("SELECT COLUMN_NAME as Field, DATA_TYPE as Type, COL_LENGTH('" . $this->fullTableName($model, false) . "', COLUMN_NAME) as Length, IS_NULLABLE As [Null], COLUMN_DEFAULT as [Default], COLUMNPROPERTY(OBJECT_ID('" . $this->fullTableName($model, false) . "'), COLUMN_NAME, 'IsIdentity') as [Key], NUMERIC_SCALE as Size FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" . $this->fullTableName($model, false) . "'", false);
foreach($cols as $column) { foreach ($cols as $column) {
$fields[] = array( $fields[] = array(
'name' => $column[0]['Field'], 'name' => $column[0]['Field'],
'type' => $this->column($column[0]['Type']), 'type' => $this->column($column[0]['Type']),
@ -266,7 +266,7 @@ class DboMssql extends DboSource {
$count = count($fields); $count = count($fields);
if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false) { if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false) {
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$dot = strrpos($fields[$i], '.'); $dot = strrpos($fields[$i], '.');
$fieldAlias = count($this->__fieldMappings); $fieldAlias = count($this->__fieldMappings);
@ -336,7 +336,7 @@ class DboMssql extends DboSource {
* @return array * @return array
*/ */
function update(&$model, $fields = array(), $values = array()) { function update(&$model, $fields = array(), $values = array()) {
foreach($fields as $i => $field) { foreach ($fields as $i => $field) {
if ($field == $model->primaryKey) { if ($field == $model->primaryKey) {
unset ($fields[$i]); unset ($fields[$i]);
unset ($values[$i]); unset ($values[$i]);
@ -475,13 +475,13 @@ class DboMssql extends DboSource {
$index = 0; $index = 0;
$j = 0; $j = 0;
while($j < $num_fields) { while ($j < $num_fields) {
$column = mssql_field_name($results, $j); $column = mssql_field_name($results, $j);
if (strpos($column, '__')) { if (strpos($column, '__')) {
if (isset($this->__fieldMappings[$column]) && strpos($this->__fieldMappings[$column], '.')) { if (isset($this->__fieldMappings[$column]) && strpos($this->__fieldMappings[$column], '.')) {
$map = explode('.', $this->__fieldMappings[$column]); $map = explode('.', $this->__fieldMappings[$column]);
} elseif(isset($this->__fieldMappings[$column])) { } elseif (isset($this->__fieldMappings[$column])) {
$map = array(0, $this->__fieldMappings[$column]); $map = array(0, $this->__fieldMappings[$column]);
} else { } else {
$map = array(0, $column); $map = array(0, $column);
@ -565,7 +565,7 @@ class DboMssql extends DboSource {
$resultRow = array(); $resultRow = array();
$i = 0; $i = 0;
foreach($row as $index => $field) { foreach ($row as $index => $field) {
list($table, $column) = $this->map[$index]; list($table, $column) = $this->map[$index];
$resultRow[$table][$column] = $row[$index]; $resultRow[$table][$column] = $row[$index];
$i++; $i++;

View file

@ -210,7 +210,7 @@ class DboMysql extends DboSource {
return 'NULL'; return 'NULL';
} }
if($data === '') { if ($data === '') {
return "''"; return "''";
} }
@ -221,7 +221,7 @@ class DboMysql extends DboSource {
case 'integer' : case 'integer' :
case 'float' : case 'float' :
case null : case null :
if(is_numeric($data)) { if (is_numeric($data)) {
break; break;
} }
default: default:

View file

@ -199,7 +199,7 @@ class DboMysqli extends DboSource {
return 'NULL'; return 'NULL';
} }
if($data === '') { if ($data === '') {
return "''"; return "''";
} }
@ -210,7 +210,7 @@ class DboMysqli extends DboSource {
case 'integer' : case 'integer' :
case 'float' : case 'float' :
case null : case null :
if(is_numeric($data)) { if (is_numeric($data)) {
break; break;
} }
default: default:

View file

@ -154,7 +154,7 @@ class DboOdbc extends DboSource{
array_push($tables, odbc_result($result, "TABLE_NAME")); array_push($tables, odbc_result($result, "TABLE_NAME"));
} }
foreach( $tables as $t ) { foreach ( $tables as $t ) {
echo "$t\n"; echo "$t\n";
} }
@ -180,11 +180,11 @@ class DboOdbc extends DboSource{
$count=odbc_num_fields($result); $count=odbc_num_fields($result);
for($i = 1; $i <= $count; $i++) { for ($i = 1; $i <= $count; $i++) {
$cols[$i - 1] = odbc_field_name($result, $i); $cols[$i - 1] = odbc_field_name($result, $i);
} }
foreach($cols as $column) { foreach ($cols as $column) {
$type $type
= odbc_field_type( = odbc_field_type(
odbc_exec($this->connection, "SELECT " . $column . " FROM " . $this->fullTableName($model)), odbc_exec($this->connection, "SELECT " . $column . " FROM " . $this->fullTableName($model)),
@ -402,7 +402,7 @@ class DboOdbc extends DboSource{
$index =0; $index =0;
$j =0; $j =0;
while($j < $num_fields) { while ($j < $num_fields) {
$column = odbc_fetch_array($results, $j); $column = odbc_fetch_array($results, $j);
if (!empty($column->table)) { if (!empty($column->table)) {
@ -430,7 +430,7 @@ class DboOdbc extends DboSource{
$resultRow=array(); $resultRow=array();
$i=0; $i=0;
foreach($row as $index => $field) { foreach ($row as $index => $field) {
list($table, $column) = $this->map[$index]; list($table, $column) = $this->map[$index];
$resultRow[$table][$column]=$row[$index]; $resultRow[$table][$column]=$row[$index];
$i++; $i++;

View file

@ -145,11 +145,11 @@ class DboOracle extends DboSource {
if ($this->connection) { if ($this->connection) {
$this->connected = true; $this->connected = true;
if(!empty($config['nls_sort'])) { if (!empty($config['nls_sort'])) {
$this->execute('ALTER SESSION SET NLS_SORT='.$config['nls_sort']); $this->execute('ALTER SESSION SET NLS_SORT='.$config['nls_sort']);
} }
if(!empty($config['nls_comp'])) { if (!empty($config['nls_comp'])) {
$this->execute('ALTER SESSION SET NLS_COMP='.$config['nls_comp']); $this->execute('ALTER SESSION SET NLS_COMP='.$config['nls_comp']);
} }
$this->execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"); $this->execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
@ -165,7 +165,7 @@ class DboOracle extends DboSource {
* @return boolean * @return boolean
*/ */
function setEncoding($lang) { function setEncoding($lang) {
if(!$this->execute('ALTER SESSION SET NLS_LANGUAGE='.$lang)) { if (!$this->execute('ALTER SESSION SET NLS_LANGUAGE='.$lang)) {
return false; return false;
} }
return true; return true;
@ -177,11 +177,11 @@ class DboOracle extends DboSource {
*/ */
function getEncoding() { function getEncoding() {
$sql = 'SELECT VALUE FROM NLS_SESSION_PARAMETERS WHERE PARAMETER=\'NLS_LANGUAGE\''; $sql = 'SELECT VALUE FROM NLS_SESSION_PARAMETERS WHERE PARAMETER=\'NLS_LANGUAGE\'';
if(!$this->execute($sql)) { if (!$this->execute($sql)) {
return false; return false;
} }
if(!$row = $this->fetchRow()) { if (!$row = $this->fetchRow()) {
return false; return false;
} }
return $row[0]['VALUE']; return $row[0]['VALUE'];
@ -193,7 +193,7 @@ class DboOracle extends DboSource {
* @access public * @access public
*/ */
function disconnect() { function disconnect() {
if($this->connection) { if ($this->connection) {
$this->connected = !ocilogoff($this->connection); $this->connected = !ocilogoff($this->connection);
return !$this->connected; return !$this->connected;
} }
@ -216,18 +216,18 @@ class DboOracle extends DboSource {
$fields = preg_split('/,\s+/', $fieldList);//explode(', ', $fieldList); $fields = preg_split('/,\s+/', $fieldList);//explode(', ', $fieldList);
$lastTableName = ''; $lastTableName = '';
foreach($fields as $key => $value) { foreach ($fields as $key => $value) {
if($value != 'COUNT(*) AS count') { if ($value != 'COUNT(*) AS count') {
if(preg_match('/\s+(\w+(\.\w+)*)$/', $value, $matches)) { if (preg_match('/\s+(\w+(\.\w+)*)$/', $value, $matches)) {
$fields[$key] = $matches[1]; $fields[$key] = $matches[1];
if(preg_match('/^(\w+\.)/', $value, $matches)) { if (preg_match('/^(\w+\.)/', $value, $matches)) {
$fields[$key] = $matches[1] . $fields[$key]; $fields[$key] = $matches[1] . $fields[$key];
$lastTableName = $matches[1]; $lastTableName = $matches[1];
} }
} }
/* /*
if(preg_match('/(([[:alnum:]_]+)\.[[:alnum:]_]+)(\s+AS\s+(\w+))?$/i', $value, $matches)) { if (preg_match('/(([[:alnum:]_]+)\.[[:alnum:]_]+)(\s+AS\s+(\w+))?$/i', $value, $matches)) {
$fields[$key] = isset($matches[4]) ? $matches[2] . '.' . $matches[4] : $matches[1]; $fields[$key] = isset($matches[4]) ? $matches[2] . '.' . $matches[4] : $matches[1];
} }
*/ */
@ -235,9 +235,9 @@ class DboOracle extends DboSource {
} }
$this->_map = array(); $this->_map = array();
foreach($fields as $f) { foreach ($fields as $f) {
$e = explode('.', $f); $e = explode('.', $f);
if(count($e) > 1) { if (count($e) > 1) {
$table = $e[0]; $table = $e[0];
$field = strtolower($e[1]); $field = strtolower($e[1]);
} else { } else {
@ -278,17 +278,17 @@ class DboOracle extends DboSource {
*/ */
function _execute($sql) { function _execute($sql) {
$this->_statementId = ociparse($this->connection, $sql); $this->_statementId = ociparse($this->connection, $sql);
if(!$this->_statementId) { if (!$this->_statementId) {
return null; return null;
} }
if($this->__transactionStarted) { if ($this->__transactionStarted) {
$mode = OCI_DEFAULT; $mode = OCI_DEFAULT;
} else { } else {
$mode = OCI_COMMIT_ON_SUCCESS; $mode = OCI_COMMIT_ON_SUCCESS;
} }
if(!ociexecute($this->_statementId, $mode)) { if (!ociexecute($this->_statementId, $mode)) {
return false; return false;
} }
@ -302,7 +302,7 @@ class DboOracle extends DboSource {
break; break;
} }
if($this->_limit >= 1) { if ($this->_limit >= 1) {
ocisetprefetch($this->_statementId, $this->_limit); ocisetprefetch($this->_statementId, $this->_limit);
} else { } else {
ocisetprefetch($this->_statementId, 3000); ocisetprefetch($this->_statementId, 3000);
@ -319,7 +319,7 @@ class DboOracle extends DboSource {
* @access public * @access public
*/ */
function fetchRow() { function fetchRow() {
if($this->_currentRow >= $this->_numRows) { if ($this->_currentRow >= $this->_numRows) {
ocifreestatement($this->_statementId); ocifreestatement($this->_statementId);
$this->_map = null; $this->_map = null;
$this->_results = null; $this->_results = null;
@ -329,10 +329,10 @@ class DboOracle extends DboSource {
} }
$resultRow = array(); $resultRow = array();
foreach($this->_results[$this->_currentRow] as $index => $field) { foreach ($this->_results[$this->_currentRow] as $index => $field) {
list($table, $column) = $this->_map[$index]; list($table, $column) = $this->_map[$index];
if(strpos($column, ' count')) { if (strpos($column, ' count')) {
$resultRow[0]['count'] = $field; $resultRow[0]['count'] = $field;
} else { } else {
$resultRow[$table][$column] = $this->_results[$this->_currentRow][$index]; $resultRow[$table][$column] = $this->_results[$this->_currentRow][$index];
@ -350,7 +350,7 @@ class DboOracle extends DboSource {
*/ */
function sequenceExists($sequence) { function sequenceExists($sequence) {
$sql = "SELECT SEQUENCE_NAME FROM USER_SEQUENCES WHERE SEQUENCE_NAME = '$sequence'"; $sql = "SELECT SEQUENCE_NAME FROM USER_SEQUENCES WHERE SEQUENCE_NAME = '$sequence'";
if(!$this->execute($sql)) { if (!$this->execute($sql)) {
return false; return false;
} }
return $this->fetchRow(); return $this->fetchRow();
@ -386,17 +386,17 @@ class DboOracle extends DboSource {
*/ */
function listSources() { function listSources() {
$cache = parent::listSources(); $cache = parent::listSources();
if($cache != null) { if ($cache != null) {
return $cache; return $cache;
} }
$sql = 'SELECT view_name AS name FROM user_views UNION SELECT table_name AS name FROM user_tables'; $sql = 'SELECT view_name AS name FROM user_views UNION SELECT table_name AS name FROM user_tables';
if(!$this->execute($sql)) { if (!$this->execute($sql)) {
return false; return false;
} }
$sources = array(); $sources = array();
while($r = $this->fetchRow()) { while ($r = $this->fetchRow()) {
$sources[] = $r[0]['name']; $sources[] = $r[0]['name'];
} }
parent::listSources($sources); parent::listSources($sources);
@ -412,18 +412,18 @@ class DboOracle extends DboSource {
function describe(&$model) { function describe(&$model) {
$cache = parent::describe($model); $cache = parent::describe($model);
if($cache != null) { if ($cache != null) {
return $cache; return $cache;
} }
$sql = 'SELECT COLUMN_NAME, DATA_TYPE FROM user_tab_columns WHERE table_name = \''; $sql = 'SELECT COLUMN_NAME, DATA_TYPE FROM user_tab_columns WHERE table_name = \'';
$sql .= strtoupper($this->fullTableName($model)) . '\''; $sql .= strtoupper($this->fullTableName($model)) . '\'';
if(!$this->execute($sql)) { if (!$this->execute($sql)) {
return false; return false;
} }
$fields = array(); $fields = array();
for($i=0; $row = $this->fetchRow(); $i++) { for ($i=0; $row = $this->fetchRow(); $i++) {
$fields[$i]['name'] = strtolower($row[0]['COLUMN_NAME']); $fields[$i]['name'] = strtolower($row[0]['COLUMN_NAME']);
$fields[$i]['type'] = $this->column($row[0]['DATA_TYPE']); $fields[$i]['type'] = $this->column($row[0]['DATA_TYPE']);
} }
@ -493,10 +493,10 @@ class DboOracle extends DboSource {
* @access public * @access public
*/ */
function column($real) { function column($real) {
if(is_array($real)) { if (is_array($real)) {
$col = $real['name']; $col = $real['name'];
if(isset($real['limit'])) { if (isset($real['limit'])) {
$col .= '('.$real['limit'].')'; $col .= '('.$real['limit'].')';
} }
return $col; return $col;
@ -507,28 +507,28 @@ class DboOracle extends DboSource {
$limit = null; $limit = null;
@list($col, $limit) = explode('(', $col); @list($col, $limit) = explode('(', $col);
if(in_array($col, array('date', 'timestamp'))) { if (in_array($col, array('date', 'timestamp'))) {
return $col; return $col;
} }
if(strpos($col, 'number') !== false) { if (strpos($col, 'number') !== false) {
return 'integer'; return 'integer';
} }
if(strpos($col, 'integer') !== false) { if (strpos($col, 'integer') !== false) {
return 'integer'; return 'integer';
} }
if(strpos($col, 'char') !== false) { if (strpos($col, 'char') !== false) {
return 'string'; return 'string';
} }
if(strpos($col, 'text') !== false) { if (strpos($col, 'text') !== false) {
return 'text'; return 'text';
} }
if(strpos($col, 'blob') !== false) { if (strpos($col, 'blob') !== false) {
return 'binary'; return 'binary';
} }
if(in_array($col, array('float', 'double', 'decimal'))) { if (in_array($col, array('float', 'double', 'decimal'))) {
return 'float'; return 'float';
} }
if($col == 'boolean') { if ($col == 'boolean') {
return $col; return $col;
} }
return 'text'; return 'text';
@ -563,11 +563,11 @@ class DboOracle extends DboSource {
$sequence = (!empty($this->sequence)) ? $this->sequence : $source . '_seq'; $sequence = (!empty($this->sequence)) ? $this->sequence : $source . '_seq';
$sql = "SELECT $sequence.currval FROM dual"; $sql = "SELECT $sequence.currval FROM dual";
if(!$this->execute($sql)) { if (!$this->execute($sql)) {
return false; return false;
} }
while($row = $this->fetchRow()) { while ($row = $this->fetchRow()) {
return $row[$sequence]['currval']; return $row[$sequence]['currval'];
} }
return false; return false;
@ -581,7 +581,7 @@ class DboOracle extends DboSource {
function lastError() { function lastError() {
$errors = ocierror(); $errors = ocierror();
if(($errors != null) && (isset($errors["message"]))) { if (($errors != null) && (isset($errors["message"]))) {
return($errors["message"]); return($errors["message"]);
} }
return null; return null;

View file

@ -122,14 +122,14 @@ class DboPear extends DboSource{
$result=$this->all($sql); $result=$this->all($sql);
foreach($result as $item) { foreach ($result as $item) {
$tables[] = $item['name']; $tables[] = $item['name'];
} }
} elseif('mysql' == $driver) { } elseif ('mysql' == $driver) {
$result=array(); $result=array();
$result=mysql_list_tables($this->config['database']); $result=mysql_list_tables($this->config['database']);
while($item = mysql_fetch_array($result)) { while ($item = mysql_fetch_array($result)) {
$tables[] = $item[0]; $tables[] = $item[0];
} }
} else { } else {
@ -154,7 +154,7 @@ class DboPear extends DboSource{
$data =$this->_pear->tableInfo($tableName); $data =$this->_pear->tableInfo($tableName);
$fields=false; $fields=false;
foreach($data as $item) { foreach ($data as $item) {
$fields[] = array('name' => $item['name'], $fields[] = array('name' => $item['name'],
'type' => $item['type']); 'type' => $item['type']);
} }

View file

@ -142,7 +142,7 @@ class DboPostgres extends DboSource {
} else { } else {
$tables = array(); $tables = array();
foreach($result as $item) { foreach ($result as $item) {
$tables[] = $item[0]['name']; $tables[] = $item[0]['name'];
} }
@ -170,7 +170,7 @@ class DboPostgres extends DboSource {
$fields = false; $fields = false;
$cols = $this->fetchAll("SELECT DISTINCT column_name AS name, data_type AS type, is_nullable AS null, column_default AS default, ordinal_position AS position, character_maximum_length AS char_length, character_octet_length AS oct_length FROM information_schema.columns WHERE table_name =" . $this->value($model->tablePrefix . $model->table) . " ORDER BY position"); $cols = $this->fetchAll("SELECT DISTINCT column_name AS name, data_type AS type, is_nullable AS null, column_default AS default, ordinal_position AS position, character_maximum_length AS char_length, character_octet_length AS oct_length FROM information_schema.columns WHERE table_name =" . $this->value($model->tablePrefix . $model->table) . " ORDER BY position");
foreach($cols as $column) { foreach ($cols as $column) {
$colKey = array_keys($column); $colKey = array_keys($column);
if (isset($column[$colKey[0]]) && !isset($column[0])) { if (isset($column[$colKey[0]]) && !isset($column[0])) {
@ -386,7 +386,7 @@ class DboPostgres extends DboSource {
$count = count($fields); $count = count($fields);
if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false) { if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false) {
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if (!preg_match('/^.+\\(.*\\)/', $fields[$i]) && !preg_match('/\s+AS\s+/', $fields[$i])) { if (!preg_match('/^.+\\(.*\\)/', $fields[$i]) && !preg_match('/\s+AS\s+/', $fields[$i])) {
$prepend = ''; $prepend = '';
if (strpos($fields[$i], 'DISTINCT') !== false) { if (strpos($fields[$i], 'DISTINCT') !== false) {
@ -512,7 +512,7 @@ class DboPostgres extends DboSource {
$index = 0; $index = 0;
$j = 0; $j = 0;
while($j < $num_fields) { while ($j < $num_fields) {
$columnName = pg_field_name($results, $j); $columnName = pg_field_name($results, $j);
if (strpos($columnName, '__')) { if (strpos($columnName, '__')) {
@ -534,7 +534,7 @@ class DboPostgres extends DboSource {
$resultRow = array(); $resultRow = array();
$i = 0; $i = 0;
foreach($row as $index => $field) { foreach ($row as $index => $field) {
list($table, $column) = $this->map[$index]; list($table, $column) = $this->map[$index];
$resultRow[$table][$column] = $row[$index]; $resultRow[$table][$column] = $row[$index];
$i++; $i++;

View file

@ -188,7 +188,7 @@ class DboSqlite extends DboSource {
return 'NULL'; return 'NULL';
} }
if($data === '') { if ($data === '') {
return "''"; return "''";
} }

View file

@ -196,7 +196,7 @@ class DboSybase extends DboSource {
return 'NULL'; return 'NULL';
} }
if($data === '') { if ($data === '') {
return "''"; return "''";
} }

View file

@ -116,7 +116,7 @@ class DboSource extends DataSource {
$out = array(); $out = array();
$keys = array_keys($data); $keys = array_keys($data);
$count = count($data); $count = count($data);
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$out[$keys[$i]] = $this->value($data[$keys[$i]]); $out[$keys[$i]] = $this->value($data[$keys[$i]]);
} }
return $out; return $out;
@ -132,7 +132,7 @@ class DboSource extends DataSource {
* @return array * @return array
*/ */
function listSources($data = null) { function listSources($data = null) {
if($this->cacheSources === false){ if ($this->cacheSources === false){
return null; return null;
} }
if ($this->_sources != null) { if ($this->_sources != null) {
@ -209,7 +209,7 @@ class DboSource extends DataSource {
$order = $params[2 + $off]; $order = $params[2 + $off];
} }
if(!array_key_exists(0, $params)) { if (!array_key_exists(0, $params)) {
return false; return false;
} }
@ -249,7 +249,7 @@ class DboSource extends DataSource {
return $args[2]->find($query, $fields, $order, $recursive); return $args[2]->find($query, $fields, $order, $recursive);
} }
} else { } else {
if(isset($args[1]) && $args[1] === true){ if (isset($args[1]) && $args[1] === true){
return $this->fetchAll($args[0], true); return $this->fetchAll($args[0], true);
} }
return $this->fetchAll($args[0], false); return $this->fetchAll($args[0], false);
@ -281,7 +281,7 @@ class DboSource extends DataSource {
$this->error = $this->lastError(); $this->error = $this->lastError();
$this->numRows = $this->lastNumRows($this->_result); $this->numRows = $this->lastNumRows($this->_result);
if($this->fullDebug && Configure::read() > 1) { if ($this->fullDebug && Configure::read() > 1) {
$this->logQuery($sql); $this->logQuery($sql);
} }
@ -331,7 +331,7 @@ class DboSource extends DataSource {
if ($this->execute($sql)) { if ($this->execute($sql)) {
$out = array(); $out = array();
while($item = $this->fetchRow()) { while ($item = $this->fetchRow()) {
$out[] = $item; $out[] = $item;
} }
@ -413,12 +413,12 @@ class DboSource extends DataSource {
print ("<table class=\"cakeSqlLog\" id=\"cakeSqlLog_" . preg_replace('/[^A-Za-z0-9_]/', '_', uniqid(time(), true)) . "\" summary=\"Cake SQL Log\" cellspacing=\"0\" border = \"0\">\n<caption>{$this->_queriesCnt} {$text} took {$this->_queriesTime} ms</caption>\n"); print ("<table class=\"cakeSqlLog\" id=\"cakeSqlLog_" . preg_replace('/[^A-Za-z0-9_]/', '_', uniqid(time(), true)) . "\" summary=\"Cake SQL Log\" cellspacing=\"0\" 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"); 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) { foreach ($log as $k => $i) {
print ("<tr><td>" . ($k + 1) . "</td><td>" . h($i['query']) . "</td><td>{$i['error']}</td><td style = \"text-align: right\">{$i['affected']}</td><td style = \"text-align: right\">{$i['numRows']}</td><td style = \"text-align: right\">{$i['took']}</td></tr>\n"); print ("<tr><td>" . ($k + 1) . "</td><td>" . h($i['query']) . "</td><td>{$i['error']}</td><td style = \"text-align: right\">{$i['affected']}</td><td style = \"text-align: right\">{$i['numRows']}</td><td style = \"text-align: right\">{$i['took']}</td></tr>\n");
} }
print ("</tbody></table>\n"); print ("</tbody></table>\n");
} else { } else {
foreach($log as $k => $i) { foreach ($log as $k => $i) {
print (($k + 1) . ". {$i['query']} {$i['error']}\n"); print (($k + 1) . ". {$i['query']} {$i['error']}\n");
} }
} }
@ -568,8 +568,8 @@ class DboSource extends DataSource {
$queryData['fields'] = $this->fields($model); $queryData['fields'] = $this->fields($model);
} }
foreach($model->__associations as $type) { foreach ($model->__associations as $type) {
foreach($model->{$type} as $assoc => $assocData) { foreach ($model->{$type} as $assoc => $assocData) {
if ($model->recursive > -1) { if ($model->recursive > -1) {
$linkModel =& $model->{$assoc}; $linkModel =& $model->{$assoc};
@ -600,8 +600,8 @@ class DboSource extends DataSource {
$filtered = $this->__filterResults($resultSet, $model); $filtered = $this->__filterResults($resultSet, $model);
if ($model->recursive > 0) { if ($model->recursive > 0) {
foreach($model->__associations as $type) { foreach ($model->__associations as $type) {
foreach($model->{$type} as $assoc => $assocData) { foreach ($model->{$type} as $assoc => $assocData) {
$db = null; $db = null;
$linkModel =& $model->{$assoc}; $linkModel =& $model->{$assoc};
@ -611,7 +611,7 @@ class DboSource extends DataSource {
} else { } else {
$db =& ConnectionManager::getDataSource($linkModel->useDbConfig); $db =& ConnectionManager::getDataSource($linkModel->useDbConfig);
} }
} elseif($model->recursive > 1 && ($type == 'belongsTo' || $type == 'hasOne')) { } elseif ($model->recursive > 1 && ($type == 'belongsTo' || $type == 'hasOne')) {
// Do recursive joins on belongsTo and hasOne relationships // Do recursive joins on belongsTo and hasOne relationships
$db =& $this; $db =& $this;
} else { } else {
@ -647,12 +647,12 @@ class DboSource extends DataSource {
$associations = am($model->belongsTo, $model->hasOne, $model->hasMany, $model->hasAndBelongsToMany); $associations = am($model->belongsTo, $model->hasOne, $model->hasMany, $model->hasAndBelongsToMany);
$count = count($results); $count = count($results);
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if (is_array($results[$i])) { if (is_array($results[$i])) {
$keys = array_keys($results[$i]); $keys = array_keys($results[$i]);
$count2 = count($keys); $count2 = count($keys);
for($j = 0; $j < $count2; $j++) { for ($j = 0; $j < $count2; $j++) {
$key = $keys[$j]; $key = $keys[$j];
if (isset($associations[$key])) { if (isset($associations[$key])) {
@ -707,16 +707,16 @@ class DboSource extends DataSource {
return null; return null;
} }
$count = count($resultSet); $count = count($resultSet);
if($type === 'hasMany' && !isset($assocData['limit'])) { if ($type === 'hasMany' && !isset($assocData['limit'])) {
$ins = array(); $ins = array();
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$in = $this->insertQueryData('{$__cakeID__$}', $resultSet[$i], $association, $assocData, $model, $linkModel, $stack); $in = $this->insertQueryData('{$__cakeID__$}', $resultSet[$i], $association, $assocData, $model, $linkModel, $stack);
if ($in !== false) { if ($in !== false) {
$ins[] = $in; $ins[] = $in;
} }
} }
if(!empty($ins)){ if (!empty($ins)){
$query = r('{$__cakeID__$}', join(', ',$ins), $query); $query = r('{$__cakeID__$}', join(', ',$ins), $query);
$fetch = $this->fetchAll($query, $model->cacheQueries, $model->name); $fetch = $this->fetchAll($query, $model->cacheQueries, $model->name);
} else { } else {
@ -726,8 +726,8 @@ class DboSource extends DataSource {
if (!empty($fetch) && is_array($fetch)) { if (!empty($fetch) && is_array($fetch)) {
if ($recursive > 0) { if ($recursive > 0) {
foreach($linkModel->__associations as $type1) { foreach ($linkModel->__associations as $type1) {
foreach($linkModel->{$type1} as $assoc1 => $assocData1) { foreach ($linkModel->{$type1} as $assoc1 => $assocData1) {
$deepModel =& $linkModel->{$assocData1['className']}; $deepModel =& $linkModel->{$assocData1['className']};
if ($deepModel->alias != $model->name) { if ($deepModel->alias != $model->name) {
@ -746,12 +746,12 @@ class DboSource extends DataSource {
} }
return $this->__mergeHasMany($resultSet, $fetch, $association, $model, $linkModel, $recursive); return $this->__mergeHasMany($resultSet, $fetch, $association, $model, $linkModel, $recursive);
} }
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$row =& $resultSet[$i]; $row =& $resultSet[$i];
$q = $this->insertQueryData($query, $resultSet[$i], $association, $assocData, $model, $linkModel, $stack); $q = $this->insertQueryData($query, $resultSet[$i], $association, $assocData, $model, $linkModel, $stack);
if($q != false){ if ($q != false){
$fetch = $this->fetchAll($q, $model->cacheQueries, $model->name); $fetch = $this->fetchAll($q, $model->cacheQueries, $model->name);
} else { } else {
$fetch = null; $fetch = null;
@ -760,8 +760,8 @@ class DboSource extends DataSource {
if (!empty($fetch) && is_array($fetch)) { if (!empty($fetch) && is_array($fetch)) {
if ($recursive > 0) { if ($recursive > 0) {
foreach($linkModel->__associations as $type1) { foreach ($linkModel->__associations as $type1) {
foreach($linkModel->{$type1} as $assoc1 => $assocData1) { foreach ($linkModel->{$type1} as $assoc1 => $assocData1) {
$deepModel =& $linkModel->{$assocData1['className']}; $deepModel =& $linkModel->{$assocData1['className']};
if ($deepModel->alias != $model->name) { if ($deepModel->alias != $model->name) {
@ -789,12 +789,12 @@ class DboSource extends DataSource {
} }
function __mergeHasMany(&$resultSet, $merge, $association, &$model, &$linkModel){ function __mergeHasMany(&$resultSet, $merge, $association, &$model, &$linkModel){
foreach($resultSet as $key => $value) { foreach ($resultSet as $key => $value) {
$merged[$association] = array(); $merged[$association] = array();
$count = 0; $count = 0;
foreach ($merge as $assoc => $data) { foreach ($merge as $assoc => $data) {
if(isset($value[$model->name]) && $value[$model->name][$model->primaryKey] === $data[$association][$model->hasMany[$association]['foreignKey']]) { if (isset($value[$model->name]) && $value[$model->name][$model->primaryKey] === $data[$association][$model->hasMany[$association]['foreignKey']]) {
if(count($data) > 1) { if (count($data) > 1) {
$temp[] = Set::pushDiff($data[$association], $data); $temp[] = Set::pushDiff($data[$association], $data);
unset($temp[$count][$association]); unset($temp[$count][$association]);
$merged[$association] = $temp; $merged[$association] = $temp;
@ -804,7 +804,7 @@ class DboSource extends DataSource {
} }
$count++; $count++;
} }
if(isset($value[$model->name])){ if (isset($value[$model->name])){
$resultSet[$key] = Set::pushDiff($resultSet[$key], $merged); $resultSet[$key] = Set::pushDiff($resultSet[$key], $merged);
unset($merged); unset($merged);
unset($temp); unset($temp);
@ -831,33 +831,33 @@ class DboSource extends DataSource {
$data[$association] = $merge[$association][0]; $data[$association] = $merge[$association][0];
} else { } else {
if (count($merge[0][$association]) > 1) { if (count($merge[0][$association]) > 1) {
foreach($merge[0] as $assoc => $data2) { foreach ($merge[0] as $assoc => $data2) {
if ($assoc != $association) { if ($assoc != $association) {
$merge[0][$association][$assoc] = $data2; $merge[0][$association][$assoc] = $data2;
} }
} }
} }
if(!isset($data[$association])) { if (!isset($data[$association])) {
if($merge[0][$association] != null) { if ($merge[0][$association] != null) {
$data[$association] = $merge[0][$association]; $data[$association] = $merge[0][$association];
} else { } else {
$data[$association] = array(); $data[$association] = array();
} }
} else { } else {
if(is_array($merge[0][$association])){ if (is_array($merge[0][$association])){
foreach ($data[$association] as $k => $v) { foreach ($data[$association] as $k => $v) {
if(!is_array($v)){ if (!is_array($v)){
$dataAssocTmp[$k] = $v; $dataAssocTmp[$k] = $v;
} }
} }
foreach ($merge[0][$association] as $k => $v) { foreach ($merge[0][$association] as $k => $v) {
if(!is_array($v)){ if (!is_array($v)){
$mergeAssocTmp[$k] = $v; $mergeAssocTmp[$k] = $v;
} }
} }
if(array_keys($merge[0]) === array_keys($data)) { if (array_keys($merge[0]) === array_keys($data)) {
$data[$association][$association] = $merge[0][$association]; $data[$association][$association] = $merge[0][$association];
} else { } else {
$diff = Set::diff($dataAssocTmp, $mergeAssocTmp); $diff = Set::diff($dataAssocTmp, $mergeAssocTmp);
@ -868,11 +868,11 @@ class DboSource extends DataSource {
} }
} else { } else {
if ($merge[0][$association] === false) { if ($merge[0][$association] === false) {
if(!isset($data[$association])){ if (!isset($data[$association])){
$data[$association] = array(); $data[$association] = array();
} }
} else { } else {
foreach($merge as $i => $row) { foreach ($merge as $i => $row) {
if (count($row) == 1) { if (count($row) == 1) {
$data[$association][] = $row[$association]; $data[$association][] = $row[$association];
} else { } else {
@ -925,12 +925,12 @@ class DboSource extends DataSource {
} }
if (!empty($queryData['joins'])) { if (!empty($queryData['joins'])) {
foreach($queryData['joins'] as $join) { foreach ($queryData['joins'] as $join) {
$self['joins'][] = $join; $self['joins'][] = $join;
} }
} }
if($this->__bypass === false) { if ($this->__bypass === false) {
$self['fields'] = am($self['fields'], $this->fields($linkModel, $alias, (isset($assocData['fields']) ? $assocData['fields'] : ''))); $self['fields'] = am($self['fields'], $this->fields($linkModel, $alias, (isset($assocData['fields']) ? $assocData['fields'] : '')));
} }
@ -945,8 +945,8 @@ class DboSource extends DataSource {
} else { } else {
$result = $queryData['selfJoin'][0]; $result = $queryData['selfJoin'][0];
if (!empty($queryData['joins'])) { if (!empty($queryData['joins'])) {
foreach($queryData['joins'] as $join) { foreach ($queryData['joins'] as $join) {
if(!in_array($join, $result['joins'])) { if (!in_array($join, $result['joins'])) {
$result['joins'][] = $join; $result['joins'][] = $join;
} }
} }
@ -981,13 +981,13 @@ class DboSource extends DataSource {
if (empty($queryData['fields'])) { if (empty($queryData['fields'])) {
$queryData['fields'] = $this->fields($model, $model->name); $queryData['fields'] = $this->fields($model, $model->name);
} elseif(!empty($model->hasMany) && $model->recursive > -1) { } elseif (!empty($model->hasMany) && $model->recursive > -1) {
$assocFields = $this->fields($model, $model->name, array("{$model->name}.{$model->primaryKey}")); $assocFields = $this->fields($model, $model->name, array("{$model->name}.{$model->primaryKey}"));
$passedFields = $this->fields($model, $model->name, $queryData['fields']); $passedFields = $this->fields($model, $model->name, $queryData['fields']);
if(count($passedFields) === 1) { if (count($passedFields) === 1) {
$match = strpos($passedFields[0], $assocFields[0]); $match = strpos($passedFields[0], $assocFields[0]);
$match1 = strpos($passedFields[0], 'COUNT('); $match1 = strpos($passedFields[0], 'COUNT(');
if($match === false && $match1 === false){ if ($match === false && $match1 === false){
$queryData['fields'] = array_unique(array_merge($passedFields, $assocFields)); $queryData['fields'] = array_unique(array_merge($passedFields, $assocFields));
} else { } else {
$queryData['fields'] = $passedFields; $queryData['fields'] = $passedFields;
@ -1227,7 +1227,7 @@ class DboSource extends DataSource {
$combined = array_combine($fields, $values); $combined = array_combine($fields, $values);
} }
foreach($combined as $field => $value) { foreach ($combined as $field => $value) {
if ($value === null) { if ($value === null) {
$updates[] = $this->name($field) . ' = NULL'; $updates[] = $this->name($field) . ' = NULL';
} else { } else {
@ -1404,7 +1404,7 @@ class DboSource extends DataSource {
$count = count($fields); $count = count($fields);
if ($count >= 1 && !in_array($fields[0], array('*', 'COUNT(*)'))) { if ($count >= 1 && !in_array($fields[0], array('*', 'COUNT(*)'))) {
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if (!preg_match('/^.+\\(.*\\)/', $fields[$i])) { if (!preg_match('/^.+\\(.*\\)/', $fields[$i])) {
$prepend = ''; $prepend = '';
@ -1464,7 +1464,7 @@ class DboSource extends DataSource {
return ' WHERE 1 = 1'; return ' WHERE 1 = 1';
} }
if (!preg_match('/^WHERE\\x20|^GROUP\\x20BY\\x20|^HAVING\\x20|^ORDER\\x20BY\\x20/i', $conditions, $match)) { if (!preg_match('/^WHERE\\x20|^GROUP\\x20BY\\x20|^HAVING\\x20|^ORDER\\x20BY\\x20/i', $conditions, $match)) {
if($where) { if ($where) {
$clause = ' WHERE '; $clause = ' WHERE ';
} }
} }
@ -1475,7 +1475,7 @@ class DboSource extends DataSource {
} }
return $clause . $conditions; return $clause . $conditions;
} else { } else {
if($where) { if ($where) {
$clause = ' WHERE '; $clause = ' WHERE ';
} }
if (!empty($conditions)) { if (!empty($conditions)) {
@ -1500,7 +1500,7 @@ function conditionKeysToString($conditions, $quoteValues = true) {
$bool = array('and', 'or', 'not', 'and not', 'or not', 'xor', '||', '&&'); $bool = array('and', 'or', 'not', 'and not', 'or not', 'xor', '||', '&&');
$join = ' AND '; $join = ' AND ';
foreach($conditions as $key => $value) { foreach ($conditions as $key => $value) {
if (is_numeric($key) && empty($value)) { if (is_numeric($key) && empty($value)) {
continue; continue;
} elseif (is_numeric($key) && is_string($value)) { } elseif (is_numeric($key) && is_string($value)) {
@ -1530,7 +1530,7 @@ function conditionKeysToString($conditions, $quoteValues = true) {
$data .= ')'; $data .= ')';
} else { } else {
if ($quoteValues) { if ($quoteValues) {
foreach($value as $valElement) { foreach ($value as $valElement) {
$data .= $this->value($valElement) . ', '; $data .= $this->value($valElement) . ', ';
} }
} }
@ -1564,7 +1564,7 @@ function conditionKeysToString($conditions, $quoteValues = true) {
} elseif (empty($mValue)) { } elseif (empty($mValue)) {
$match['1'] = ' = '; $match['1'] = ' = ';
$match['2'] = $match['0']; $match['2'] = $match['0'];
} elseif(!isset($match['2'])) { } elseif (!isset($match['2'])) {
$match['1'] = ' = '; $match['1'] = ' = ';
$match['2'] = $match['0']; $match['2'] = $match['0'];
} }
@ -1574,13 +1574,13 @@ function conditionKeysToString($conditions, $quoteValues = true) {
$data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2']; $data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2'];
} else { } else {
if (!empty($match['2']) && $quoteValues) { if (!empty($match['2']) && $quoteValues) {
if(!preg_match('/[A-Za-z]+\\([a-z0-9]*\\),?\\x20+/', $match['2'])) { if (!preg_match('/[A-Za-z]+\\([a-z0-9]*\\),?\\x20+/', $match['2'])) {
$match['2'] = $this->value($match['2']); $match['2'] = $this->value($match['2']);
} }
$match['2'] = str_replace(' AND ', "' AND '", $match['2']); $match['2'] = str_replace(' AND ', "' AND '", $match['2']);
} }
$data = $this->__quoteFields($key); $data = $this->__quoteFields($key);
if($data === $key) { if ($data === $key) {
$data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2']; $data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2'];
} else { } else {
$data = $data . ' ' . $match['1'] . ' ' . $match['2']; $data = $data . ' ' . $match['1'] . ' ' . $match['2'];
@ -1609,21 +1609,21 @@ function conditionKeysToString($conditions, $quoteValues = true) {
$end = null; $end = null;
$original = $conditions; $original = $conditions;
if(!empty($this->startQuote)) { if (!empty($this->startQuote)) {
$start = preg_quote($this->startQuote); $start = preg_quote($this->startQuote);
} }
if(!empty($this->endQuote)) { if (!empty($this->endQuote)) {
$end = preg_quote($this->endQuote); $end = preg_quote($this->endQuote);
} }
$conditions = str_replace(array($start, $end), '', $conditions); $conditions = str_replace(array($start, $end), '', $conditions);
preg_match_all('/(?:[\'\"][^\'\"\\\]*(?:\\\.[^\'\"\\\]*)*[\'\"])|([a-z0-9_' . $start . $end . ']*\\.[a-z0-9_' . $start . $end . ']*)/i', $conditions, $replace, PREG_PATTERN_ORDER); preg_match_all('/(?:[\'\"][^\'\"\\\]*(?:\\\.[^\'\"\\\]*)*[\'\"])|([a-z0-9_' . $start . $end . ']*\\.[a-z0-9_' . $start . $end . ']*)/i', $conditions, $replace, PREG_PATTERN_ORDER);
if(isset($replace['1']['0'])) { if (isset($replace['1']['0'])) {
$pregCount = count($replace['1']); $pregCount = count($replace['1']);
for($i = 0; $i < $pregCount; $i++) { for ($i = 0; $i < $pregCount; $i++) {
if(!empty($replace['1'][$i]) && !is_numeric($replace['1'][$i])) { if (!empty($replace['1'][$i]) && !is_numeric($replace['1'][$i])) {
$conditions = preg_replace('/\b' . preg_quote($replace['1'][$i]) . '\b/', $this->name($replace['1'][$i]), $conditions); $conditions = preg_replace('/\b' . preg_quote($replace['1'][$i]) . '\b/', $this->name($replace['1'][$i]), $conditions);
} }
} }
@ -1668,7 +1668,7 @@ function conditionKeysToString($conditions, $quoteValues = true) {
} }
if (is_array($keys)) { if (is_array($keys)) {
foreach($keys as $key => $val) { foreach ($keys as $key => $val) {
if (is_numeric($key) && empty($val)) { if (is_numeric($key) && empty($val)) {
unset ($keys[$key]); unset ($keys[$key]);
} }
@ -1683,7 +1683,7 @@ function conditionKeysToString($conditions, $quoteValues = true) {
if (Set::countDim($keys) > 1) { if (Set::countDim($keys) > 1) {
$new = array(); $new = array();
foreach($keys as $val) { foreach ($keys as $val) {
$val = $this->order($val); $val = $this->order($val);
$new[] = $val; $new[] = $val;
} }
@ -1691,7 +1691,7 @@ function conditionKeysToString($conditions, $quoteValues = true) {
$keys = $new; $keys = $new;
} }
foreach($keys as $key => $value) { foreach ($keys as $key => $value) {
if (is_numeric($key)) { if (is_numeric($key)) {
$value = ltrim(r('ORDER BY ', '', $this->order($value))); $value = ltrim(r('ORDER BY ', '', $this->order($value)));
$key = $value; $key = $value;
@ -1729,7 +1729,7 @@ function conditionKeysToString($conditions, $quoteValues = true) {
PREG_PATTERN_ORDER); PREG_PATTERN_ORDER);
$pregCount = count($result['0']); $pregCount = count($result['0']);
for($i = 0; $i < $pregCount; $i++) { for ($i = 0; $i < $pregCount; $i++) {
$keys = preg_replace('/' . $result['0'][$i] . '/', $this->name($result['0'][$i]), $keys); $keys = preg_replace('/' . $result['0'][$i] . '/', $this->name($result['0'][$i]), $keys);
} }
@ -1738,7 +1738,7 @@ function conditionKeysToString($conditions, $quoteValues = true) {
} else { } else {
return ' ORDER BY ' . $keys . ' ' . $direction; return ' ORDER BY ' . $keys . ' ' . $direction;
} }
} elseif(preg_match('/(\\x20ASC|\\x20DESC)/i', $keys, $match)) { } elseif (preg_match('/(\\x20ASC|\\x20DESC)/i', $keys, $match)) {
$direction = $match['1']; $direction = $match['1'];
$keys = preg_replace('/' . $match['1'] . '/', '', $keys); $keys = preg_replace('/' . $match['1'] . '/', '', $keys);
return ' ORDER BY ' . $keys . $direction; return ' ORDER BY ' . $keys . $direction;

View file

@ -368,9 +368,9 @@ class Model extends Overloadable {
$this->id = $id; $this->id = $id;
if($table === false) { if ($table === false) {
$this->useTable = false; $this->useTable = false;
} else if($table) { } elseif ($table) {
$this->useTable = $table; $this->useTable = $table;
} }
@ -485,7 +485,7 @@ class Model extends Overloadable {
return $this->behaviors[$it[1]]->{$it[0]}($this, $params); return $this->behaviors[$it[1]]->{$it[0]}($this, $params);
} }
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if (strpos($methods[$i], '/') === 0 && preg_match($methods[$i] . 'i', $method)) { if (strpos($methods[$i], '/') === 0 && preg_match($methods[$i] . 'i', $method)) {
return call_user_func_array(array($this->behaviors[$call[$i][1]], $call[$i][0]), $pass); return call_user_func_array(array($this->behaviors[$call[$i][1]], $call[$i][0]), $pass);
} }
@ -514,16 +514,16 @@ class Model extends Overloadable {
$model = array($model => $options); $model = array($model => $options);
} }
foreach($model as $name => $options) { foreach ($model as $name => $options) {
if (isset($options['type'])) { if (isset($options['type'])) {
$assoc = $options['type']; $assoc = $options['type'];
} elseif (isset($options[0])) { } elseif (isset($options[0])) {
$assoc = $options[0]; $assoc = $options[0];
} }
if(!$permanent) { if (!$permanent) {
$this->__backAssociation[$assoc] = $this->{$assoc}; $this->__backAssociation[$assoc] = $this->{$assoc};
} }
foreach($model as $key => $value) { foreach ($model as $key => $value) {
$assocName = $key; $assocName = $key;
$modelName = $key; $modelName = $key;
@ -549,12 +549,12 @@ class Model extends Overloadable {
*/ */
function bindModel($params, $reset = true) { function bindModel($params, $reset = true) {
foreach($params as $assoc => $model) { foreach ($params as $assoc => $model) {
if($reset === true) { if ($reset === true) {
$this->__backAssociation[$assoc] = $this->{$assoc}; $this->__backAssociation[$assoc] = $this->{$assoc};
} }
foreach($model as $key => $value) { foreach ($model as $key => $value) {
$assocName = $key; $assocName = $key;
if (is_numeric($key)) { if (is_numeric($key)) {
@ -585,12 +585,12 @@ class Model extends Overloadable {
* @return boolean Always true * @return boolean Always true
*/ */
function unbindModel($params, $reset = true) { function unbindModel($params, $reset = true) {
foreach($params as $assoc => $models) { foreach ($params as $assoc => $models) {
if($reset === true) { if ($reset === true) {
$this->__backAssociation[$assoc] = $this->{$assoc}; $this->__backAssociation[$assoc] = $this->{$assoc};
} }
foreach($models as $model) { foreach ($models as $model) {
$this->__backAssociation = array_merge($this->__backAssociation, $this->{$assoc}); $this->__backAssociation = array_merge($this->__backAssociation, $this->{$assoc});
unset ($this->{$assoc}[$model]); unset ($this->{$assoc}[$model]);
} }
@ -605,18 +605,18 @@ class Model extends Overloadable {
function __createLinks() { function __createLinks() {
// Convert all string-based associations to array based // Convert all string-based associations to array based
foreach($this->__associations as $type) { foreach ($this->__associations as $type) {
if (!is_array($this->{$type})) { if (!is_array($this->{$type})) {
$this->{$type} = explode(',', $this->{$type}); $this->{$type} = explode(',', $this->{$type});
foreach($this->{$type} as $i => $className) { foreach ($this->{$type} as $i => $className) {
$className = trim($className); $className = trim($className);
unset ($this->{$type}[$i]); unset ($this->{$type}[$i]);
$this->{$type}[$className] = array(); $this->{$type}[$className] = array();
} }
} }
foreach($this->{$type} as $assoc => $value) { foreach ($this->{$type} as $assoc => $value) {
if (is_numeric($assoc)) { if (is_numeric($assoc)) {
unset ($this->{$type}[$assoc]); unset ($this->{$type}[$assoc]);
$assoc = $value; $assoc = $value;
@ -649,7 +649,7 @@ class Model extends Overloadable {
function __constructLinkedModel($assoc, $className, $id = false, $table = null, $ds = null) { function __constructLinkedModel($assoc, $className, $id = false, $table = null, $ds = null) {
$colKey = Inflector::underscore($className); $colKey = Inflector::underscore($className);
if(!class_exists($className)) { if (!class_exists($className)) {
if (!loadModel($className)) { if (!loadModel($className)) {
return $this->cakeError('missingModel', array(array('className' => $className))); return $this->cakeError('missingModel', array(array('className' => $className)));
} }
@ -686,10 +686,10 @@ class Model extends Overloadable {
* @access private * @access private
*/ */
function __generateAssociation($type) { function __generateAssociation($type) {
foreach($this->{$type} as $assocKey => $assocData) { foreach ($this->{$type} as $assocKey => $assocData) {
$class = $assocKey; $class = $assocKey;
foreach($this->__associationKeys[$type] as $key) { foreach ($this->__associationKeys[$type] as $key) {
if (!isset($this->{$type}[$assocKey][$key]) || $this->{$type}[$assocKey][$key] == null) { if (!isset($this->{$type}[$assocKey][$key]) || $this->{$type}[$assocKey][$key] == null) {
$data = ''; $data = '';
@ -722,7 +722,7 @@ class Model extends Overloadable {
if ($key == 'foreignKey' && !isset($this->keyToTable[$this->{$type}[$assocKey][$key]])) { if ($key == 'foreignKey' && !isset($this->keyToTable[$this->{$type}[$assocKey][$key]])) {
$this->keyToTable[$this->{$type}[$assocKey][$key]][0] = $this->{$class}->table; $this->keyToTable[$this->{$type}[$assocKey][$key]][0] = $this->{$class}->table;
$this->keyToTable[$this->{$type}[$assocKey][$key]][1] = $this->{$class}->name; $this->keyToTable[$this->{$type}[$assocKey][$key]][1] = $this->{$class}->name;
if($this->{$class}->name != $class) { if ($this->{$class}->name != $class) {
$this->keyToTable[$this->{$type}[$assocKey][$key]][2] = $class; $this->keyToTable[$this->{$type}[$assocKey][$key]][2] = $class;
} }
} }
@ -807,9 +807,9 @@ class Model extends Overloadable {
$data = array($this->name => array($one => $two)); $data = array($this->name => array($one => $two));
} }
foreach($data as $n => $v) { foreach ($data as $n => $v) {
if (is_array($v)) { if (is_array($v)) {
foreach($v as $x => $y) { foreach ($v as $x => $y) {
if ($n == $this->name) { if ($n == $this->name) {
if (isset($this->validationErrors[$x])) { if (isset($this->validationErrors[$x])) {
unset ($this->validationErrors[$x]); unset ($this->validationErrors[$x]);
@ -965,7 +965,7 @@ class Model extends Overloadable {
if ($conditions === null) { if ($conditions === null) {
$conditions = array($this->name . '.' . $this->primaryKey => $this->id); $conditions = array($this->name . '.' . $this->primaryKey => $this->id);
} }
if($this->recursive >= 1) { if ($this->recursive >= 1) {
$recursive = -1; $recursive = -1;
} else { } else {
$recursive = $this->recursive; $recursive = $this->recursive;
@ -1047,7 +1047,7 @@ class Model extends Overloadable {
$weHaveMulti = false; $weHaveMulti = false;
} }
foreach($this->data as $n => $v) { foreach ($this->data as $n => $v) {
if (isset($weHaveMulti) && isset($v[$n]) && $count > 0 && count($this->hasAndBelongsToMany) > 0) { if (isset($weHaveMulti) && isset($v[$n]) && $count > 0 && count($this->hasAndBelongsToMany) > 0) {
$joined[] = $v; $joined[] = $v;
} else { } else {
@ -1058,7 +1058,7 @@ class Model extends Overloadable {
} }
} }
foreach($v as $x => $y) { foreach ($v as $x => $y) {
if ($this->hasField($x) && ($whitelist && in_array($x, $fieldList) || !$whitelist)) { if ($this->hasField($x) && ($whitelist && in_array($x, $fieldList) || !$whitelist)) {
$fields[] = $x; $fields[] = $x;
$values[] = $y; $values[] = $y;
@ -1142,8 +1142,8 @@ class Model extends Overloadable {
*/ */
function __saveMulti($joined, $id) { function __saveMulti($joined, $id) {
$db =& ConnectionManager::getDataSource($this->useDbConfig); $db =& ConnectionManager::getDataSource($this->useDbConfig);
foreach($joined as $x => $y) { foreach ($joined as $x => $y) {
foreach($y as $assoc => $value) { foreach ($y as $assoc => $value) {
if (isset($this->hasAndBelongsToMany[$assoc])) { if (isset($this->hasAndBelongsToMany[$assoc])) {
$joinTable[$assoc] = $this->hasAndBelongsToMany[$assoc]['joinTable']; $joinTable[$assoc] = $this->hasAndBelongsToMany[$assoc]['joinTable'];
$mainKey[$assoc] = $this->hasAndBelongsToMany[$assoc]['foreignKey']; $mainKey[$assoc] = $this->hasAndBelongsToMany[$assoc]['foreignKey'];
@ -1152,7 +1152,7 @@ class Model extends Overloadable {
$fields[$assoc] = join(',', $keys); $fields[$assoc] = join(',', $keys);
unset($keys); unset($keys);
foreach($value as $update) { foreach ($value as $update) {
if (!empty($update)) { if (!empty($update)) {
$values[] = $db->value($id, $this->getColumnType($this->primaryKey)); $values[] = $db->value($id, $this->getColumnType($this->primaryKey));
$values[] = $db->value($update); $values[] = $db->value($update);
@ -1175,7 +1175,7 @@ class Model extends Overloadable {
if (isset($joinTable)) { if (isset($joinTable)) {
$total = count($joinTable); $total = count($joinTable);
if(is_array($newValue)) { if (is_array($newValue)) {
foreach ($newValue as $loopAssoc => $val) { foreach ($newValue as $loopAssoc => $val) {
$db =& ConnectionManager::getDataSource($this->useDbConfig); $db =& ConnectionManager::getDataSource($this->useDbConfig);
$table = $db->name($db->fullTableName($joinTable[$loopAssoc])); $table = $db->name($db->fullTableName($joinTable[$loopAssoc]));
@ -1183,7 +1183,7 @@ class Model extends Overloadable {
if (!empty($newValue[$loopAssoc])) { if (!empty($newValue[$loopAssoc])) {
$secondCount = count($newValue[$loopAssoc]); $secondCount = count($newValue[$loopAssoc]);
for($x = 0; $x < $secondCount; $x++) { for ($x = 0; $x < $secondCount; $x++) {
$db->query("INSERT INTO {$table} ({$fields[$loopAssoc]}) VALUES {$newValue[$loopAssoc][$x]}"); $db->query("INSERT INTO {$table} ({$fields[$loopAssoc]}) VALUES {$newValue[$loopAssoc][$x]}");
} }
} }
@ -1275,7 +1275,7 @@ class Model extends Overloadable {
$savedAssociatons = $this->__backAssociation; $savedAssociatons = $this->__backAssociation;
$this->__backAssociation = array(); $this->__backAssociation = array();
} }
foreach(am($this->hasMany, $this->hasOne) as $assoc => $data) { foreach (am($this->hasMany, $this->hasOne) as $assoc => $data) {
if ($data['dependent'] === true && $cascade === true) { if ($data['dependent'] === true && $cascade === true) {
$model =& $this->{$assoc}; $model =& $this->{$assoc};
@ -1283,8 +1283,8 @@ class Model extends Overloadable {
$model->recursive = -1; $model->recursive = -1;
$records = $model->findAll(array($field => $id), $model->primaryKey); $records = $model->findAll(array($field => $id), $model->primaryKey);
if(!empty($records)) { if (!empty($records)) {
foreach($records as $record) { foreach ($records as $record) {
$model->delete($record[$model->name][$model->primaryKey]); $model->delete($record[$model->name][$model->primaryKey]);
} }
} }
@ -1303,13 +1303,13 @@ class Model extends Overloadable {
*/ */
function _deleteLinks($id) { function _deleteLinks($id) {
$db =& ConnectionManager::getDataSource($this->useDbConfig); $db =& ConnectionManager::getDataSource($this->useDbConfig);
foreach($this->hasAndBelongsToMany as $assoc => $data) { foreach ($this->hasAndBelongsToMany as $assoc => $data) {
if (isset($data['with'])) { if (isset($data['with'])) {
$model =& $this->{$data['with']}; $model =& $this->{$data['with']};
$records = $model->findAll(array($data['foreignKey'] => $id), $model->primaryKey, null, null, null, -1); $records = $model->findAll(array($data['foreignKey'] => $id), $model->primaryKey, null, null, null, -1);
if (!empty($records)) { if (!empty($records)) {
foreach($records as $record) { foreach ($records as $record) {
$model->delete($record[$model->name][$model->primaryKey]); $model->delete($record[$model->name][$model->primaryKey]);
} }
} }
@ -1479,7 +1479,7 @@ class Model extends Overloadable {
* @access private * @access private
*/ */
function __resetAssociations() { function __resetAssociations() {
foreach($this->__associations as $type) { foreach ($this->__associations as $type) {
if (isset($this->__backAssociation[$type])) { if (isset($this->__backAssociation[$type])) {
$this->{$type} = $this->__backAssociation[$type]; $this->{$type} = $this->__backAssociation[$type];
} }
@ -1498,8 +1498,8 @@ class Model extends Overloadable {
$db =& ConnectionManager::getDataSource($this->useDbConfig); $db =& ConnectionManager::getDataSource($this->useDbConfig);
$data = $db->fetchAll($data, $this->cacheQueries); $data = $db->fetchAll($data, $this->cacheQueries);
foreach($data as $key => $value) { foreach ($data as $key => $value) {
foreach($this->tableToModel as $key1 => $value1) { foreach ($this->tableToModel as $key1 => $value1) {
if (isset($data[$key][$key1])) { if (isset($data[$key][$key1])) {
$newData[$key][$value1] = $data[$key][$key1]; $newData[$key][$value1] = $data[$key][$key1];
} }
@ -1594,7 +1594,7 @@ class Model extends Overloadable {
$out = array(); $out = array();
$sizeOf = sizeof($data); $sizeOf = sizeof($data);
for($ii = 0; $ii < $sizeOf; $ii++) { 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]; $tmp = $data[$ii];
@ -1692,7 +1692,7 @@ class Model extends Overloadable {
$Validation = new Validation(); $Validation = new Validation();
foreach($this->validate as $fieldName => $ruleSet) { foreach ($this->validate as $fieldName => $ruleSet) {
if (!is_array($ruleSet) || (is_array($ruleSet) && isset($ruleSet['rule']))) { if (!is_array($ruleSet) || (is_array($ruleSet) && isset($ruleSet['rule']))) {
$ruleSet = array($ruleSet); $ruleSet = array($ruleSet);
} }
@ -1722,7 +1722,7 @@ class Model extends Overloadable {
if ((!isset($data[$fieldName]) && $validator['required'] === true) || (isset($data[$fieldName]) && (empty($data[$fieldName]) && !is_numeric($data[$fieldName])) && $validator['allowEmpty'] === false)) { if ((!isset($data[$fieldName]) && $validator['required'] === true) || (isset($data[$fieldName]) && (empty($data[$fieldName]) && !is_numeric($data[$fieldName])) && $validator['allowEmpty'] === false)) {
$this->invalidate($fieldName, $message); $this->invalidate($fieldName, $message);
} elseif (isset($data[$fieldName])) { } elseif (isset($data[$fieldName])) {
if(empty($data[$fieldName]) && $data[$fieldName] != '0' && $validator['allowEmpty'] === true) { if (empty($data[$fieldName]) && $data[$fieldName] != '0' && $validator['allowEmpty'] === true) {
break; break;
} }
if (is_array($validator['rule'])) { if (is_array($validator['rule'])) {
@ -1788,7 +1788,7 @@ class Model extends Overloadable {
$foreignKeys = array(); $foreignKeys = array();
if (count($this->belongsTo)) { if (count($this->belongsTo)) {
foreach($this->belongsTo as $assoc => $data) { foreach ($this->belongsTo as $assoc => $data) {
$foreignKeys[] = $data['foreignKey']; $foreignKeys[] = $data['foreignKey'];
} }
} }
@ -1822,15 +1822,15 @@ class Model extends Overloadable {
} }
$recursive = $this->recursive; $recursive = $this->recursive;
if($groupPath == null && $recursive >= 1) { if ($groupPath == null && $recursive >= 1) {
$this->recursive = -1; $this->recursive = -1;
} else if($groupPath && $recursive >= 1){ } elseif ($groupPath && $recursive >= 1){
$this->recursive = 0; $this->recursive = 0;
} }
$result = $this->findAll($conditions, $fields, $order, $limit); $result = $this->findAll($conditions, $fields, $order, $limit);
$this->recursive = $recursive; $this->recursive = $recursive;
if(!$result) { if (!$result) {
return false; return false;
} }
@ -1853,7 +1853,7 @@ class Model extends Overloadable {
if (!empty($group)) { if (!empty($group)) {
$c = count($keys); $c = count($keys);
for ($i = 0; $i < $c; $i++) { for ($i = 0; $i < $c; $i++) {
if(!isset($group[$i])) { if (!isset($group[$i])) {
$group[$i] = 0; $group[$i] = 0;
} }
if (!isset($out[$group[$i]])) { if (!isset($out[$group[$i]])) {
@ -1911,7 +1911,7 @@ class Model extends Overloadable {
return false; return false;
} }
foreach($this->id as $id) { foreach ($this->id as $id) {
return $id; return $id;
} }
@ -2107,8 +2107,8 @@ class Model extends Overloadable {
if (defined('CACHE_CHECK') && CACHE_CHECK === true) { if (defined('CACHE_CHECK') && CACHE_CHECK === true) {
$assoc[] = strtolower(Inflector::pluralize($this->name)); $assoc[] = strtolower(Inflector::pluralize($this->name));
foreach($this->__associations as $key => $association) { foreach ($this->__associations as $key => $association) {
foreach($this->$association as $key => $className) { foreach ($this->$association as $key => $className) {
$check = strtolower(Inflector::pluralize($className['className'])); $check = strtolower(Inflector::pluralize($className['className']));
if (!in_array($check, $assoc)) { if (!in_array($check, $assoc)) {

View file

@ -87,7 +87,7 @@ class NeatString{
$chars = preg_split('//', $available_chars, -1, PREG_SPLIT_NO_EMPTY); $chars = preg_split('//', $available_chars, -1, PREG_SPLIT_NO_EMPTY);
$char_count = count($chars); $char_count = count($chars);
$out = ''; $out = '';
for($ii = 0; $ii < $length; $ii++) { for ($ii = 0; $ii < $length; $ii++) {
$out .= $chars[rand(1, $char_count)-1]; $out .= $chars[rand(1, $char_count)-1];
} }
return $out; return $out;

View file

@ -86,11 +86,11 @@ class Object {
*/ */
function requestAction($url, $extra = array()) { function requestAction($url, $extra = array()) {
if (!empty($url)) { if (!empty($url)) {
if(!class_exists('dispatcher')) { if (!class_exists('dispatcher')) {
require CAKE . 'dispatcher.php'; require CAKE . 'dispatcher.php';
} }
$dispatcher =& new Dispatcher(); $dispatcher =& new Dispatcher();
if(isset($this->plugin)){ if (isset($this->plugin)){
$extra['plugin'] = $this->plugin; $extra['plugin'] = $this->plugin;
} }
if (in_array('return', $extra, true)) { if (in_array('return', $extra, true)) {
@ -242,12 +242,12 @@ class Object {
switch($type) { switch($type) {
case 'registry': case 'registry':
$vars = unserialize(${$name}); $vars = unserialize(${$name});
foreach($vars['0'] as $key => $value) { foreach ($vars['0'] as $key => $value) {
loadModel(Inflector::classify($key)); loadModel(Inflector::classify($key));
} }
unset($vars); unset($vars);
$vars = unserialize(${$name}); $vars = unserialize(${$name});
foreach($vars['0'] as $key => $value) { foreach ($vars['0'] as $key => $value) {
ClassRegistry::addObject($key, $value); ClassRegistry::addObject($key, $value);
unset ($value); unset ($value);
} }

View file

@ -78,7 +78,7 @@ class Overloadable extends Object {
* @access private * @access private
*/ */
function __call($method, $params, &$return) { function __call($method, $params, &$return) {
if(!method_exists($this, 'call__')) { if (!method_exists($this, 'call__')) {
trigger_error(sprintf(__('Magic method handler call__ not defined in %s', true), get_class($this)), E_USER_ERROR); trigger_error(sprintf(__('Magic method handler call__ not defined in %s', true), get_class($this)), E_USER_ERROR);
} }
$return = $this->call__($method, $params); $return = $this->call__($method, $params);
@ -130,7 +130,7 @@ class Overloadable2 extends Object {
* @access private * @access private
*/ */
function __call($method, $params, &$return) { function __call($method, $params, &$return) {
if(!method_exists($this, 'call__')) { if (!method_exists($this, 'call__')) {
trigger_error(sprintf(__('Magic method handler call__ not defined in %s', true), get_class($this)), E_USER_ERROR); trigger_error(sprintf(__('Magic method handler call__ not defined in %s', true), get_class($this)), E_USER_ERROR);
} }
$return = $this->call__($method, $params); $return = $this->call__($method, $params);

View file

@ -53,7 +53,7 @@ class Overloadable extends Object {
* @access private * @access private
*/ */
function __call($method, $params) { function __call($method, $params) {
if(!method_exists($this, 'call__')) { if (!method_exists($this, 'call__')) {
trigger_error(sprintf(__('Magic method handler call__ not defined in %s', true), get_class($this)), E_USER_ERROR); trigger_error(sprintf(__('Magic method handler call__ not defined in %s', true), get_class($this)), E_USER_ERROR);
} }
return $this->call__($method, $params); return $this->call__($method, $params);
@ -78,7 +78,7 @@ class Overloadable2 extends Object {
* @access private * @access private
*/ */
function __call($method, $params) { function __call($method, $params) {
if(!method_exists($this, 'call__')) { if (!method_exists($this, 'call__')) {
trigger_error(sprintf(__('Magic method handler call__ not defined in %s', true), get_class($this)), E_USER_ERROR); trigger_error(sprintf(__('Magic method handler call__ not defined in %s', true), get_class($this)), E_USER_ERROR);
} }
return $this->call__($method, $params); return $this->call__($method, $params);

View file

@ -212,7 +212,7 @@ class Router extends Object {
return false; return false;
} }
foreach($elements as $element) { foreach ($elements as $element) {
$q = null; $q = null;
if (preg_match('/^:(.+)$/', $element, $r)) { if (preg_match('/^:(.+)$/', $element, $r)) {
@ -225,7 +225,7 @@ class Router extends Object {
$parsed[] = '(?:\/([^\/]+))?'; $parsed[] = '(?:\/([^\/]+))?';
} }
$names[] = $r[1]; $names[] = $r[1];
} elseif(preg_match('/^\*$/', $element, $r)) { } elseif (preg_match('/^\*$/', $element, $r)) {
$parsed[] = '(?:\/(.*))?'; $parsed[] = '(?:\/(.*))?';
} else { } else {
$parsed[] = '/' . $element; $parsed[] = '/' . $element;
@ -257,7 +257,7 @@ class Router extends Object {
} }
extract($_this->__parseExtension($url)); extract($_this->__parseExtension($url));
foreach($_this->routes as $route) { foreach ($_this->routes as $route) {
list($route, $regexp, $names, $defaults) = $route; list($route, $regexp, $names, $defaults) = $route;
if (preg_match($regexp, $url, $r)) { if (preg_match($regexp, $url, $r)) {
@ -266,12 +266,12 @@ class Router extends Object {
// remove the first element, which is the url // remove the first element, which is the url
array_shift ($r); array_shift ($r);
// hack, pre-fill the default route names // hack, pre-fill the default route names
foreach($names as $name) { foreach ($names as $name) {
$out[$name] = null; $out[$name] = null;
} }
if (is_array($defaults)) { if (is_array($defaults)) {
foreach($defaults as $name => $value) { foreach ($defaults as $name => $value) {
if (preg_match('#[a-zA-Z_\-]#i', $name)) { if (preg_match('#[a-zA-Z_\-]#i', $name)) {
$out[$name] = $_this->stripEscape($value); $out[$name] = $_this->stripEscape($value);
} else { } else {
@ -280,16 +280,16 @@ class Router extends Object {
} }
} }
foreach(Set::filter($r, true) as $key => $found) { foreach (Set::filter($r, true) as $key => $found) {
// if $found is a named url element (i.e. ':action') // if $found is a named url element (i.e. ':action')
if (isset($names[$key])) { if (isset($names[$key])) {
$out[$names[$key]] = $found; $out[$names[$key]] = $found;
} else if (isset($names[$key]) && empty($names[$key]) && empty($out[$names[$key]])) { } elseif (isset($names[$key]) && empty($names[$key]) && empty($out[$names[$key]])) {
break; //leave the default values; break; //leave the default values;
} else { } else {
// unnamed elements go in as 'pass' // unnamed elements go in as 'pass'
$search = explode('/', $found); $search = explode('/', $found);
foreach($search as $k => $value) { foreach ($search as $k => $value) {
$out['pass'][] = $_this->stripEscape($value); $out['pass'][] = $_this->stripEscape($value);
} }
} }
@ -314,14 +314,14 @@ class Router extends Object {
$_this =& Router::getInstance(); $_this =& Router::getInstance();
if ($_this->__parseExtensions) { if ($_this->__parseExtensions) {
if(preg_match('/\.[0-9a-zA-Z]*$/', $url, $match) == 1) { if (preg_match('/\.[0-9a-zA-Z]*$/', $url, $match) == 1) {
$match = substr($match[0], 1); $match = substr($match[0], 1);
if(empty($_this->__validExtensions)) { if (empty($_this->__validExtensions)) {
$url = substr($url, 0, strpos($url, '.' . $match)); $url = substr($url, 0, strpos($url, '.' . $match));
$ext = $match; $ext = $match;
} else { } else {
foreach($_this->__validExtensions as $name) { foreach ($_this->__validExtensions as $name) {
if(strcasecmp($name, $match) === 0) { if (strcasecmp($name, $match) === 0) {
$url = substr($url, 0, strpos($url, '.' . $name)); $url = substr($url, 0, strpos($url, '.' . $name));
$ext = $match; $ext = $match;
} }
@ -457,19 +457,19 @@ class Router extends Object {
$_this =& Router::getInstance(); $_this =& Router::getInstance();
$defaults = $params = array('plugin' => null, 'controller' => null, 'action' => 'index'); $defaults = $params = array('plugin' => null, 'controller' => null, 'action' => 'index');
if(!empty($_this->__params)) { if (!empty($_this->__params)) {
if(!isset($_this->params['requested'])) { if (!isset($_this->params['requested'])) {
$params = $_this->__params[0]; $params = $_this->__params[0];
} else if(isset($_this->params['requested'])) { } elseif (isset($_this->params['requested'])) {
$params = end($_this->__params); $params = end($_this->__params);
} }
} }
$path = array('base' => null); $path = array('base' => null);
if(!empty($_this->__paths)) { if (!empty($_this->__paths)) {
if(!isset($_this->params['requested'])) { if (!isset($_this->params['requested'])) {
$path = $_this->__paths[0]; $path = $_this->__paths[0];
} else if(isset($_this->params['requested'])) { } elseif (isset($_this->params['requested'])) {
$path = end($_this->__paths); $path = end($_this->__paths);
} }
} }
@ -521,7 +521,7 @@ class Router extends Object {
$named = $args = array(); $named = $args = array();
$skip = am(array_keys($_this->__mapped), array('bare', 'action', 'controller', 'plugin', 'ext', '?', '#')); $skip = am(array_keys($_this->__mapped), array('bare', 'action', 'controller', 'plugin', 'ext', '?', '#'));
if(defined('CAKE_ADMIN')) { if (defined('CAKE_ADMIN')) {
$skip[] = CAKE_ADMIN; $skip[] = CAKE_ADMIN;
} }
$_this->__mapped = array(); $_this->__mapped = array();
@ -531,11 +531,11 @@ class Router extends Object {
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if ($i == 0 && is_numeric($keys[$i]) && in_array('id', $keys)) { if ($i == 0 && is_numeric($keys[$i]) && in_array('id', $keys)) {
$args[0] = $url[$keys[$i]]; $args[0] = $url[$keys[$i]];
} else if (is_numeric($keys[$i]) || $keys[$i] == 'id') { } elseif (is_numeric($keys[$i]) || $keys[$i] == 'id') {
$args[] = $url[$keys[$i]]; $args[] = $url[$keys[$i]];
} else if(!empty($path['namedArgs']) && in_array($keys[$i], array_keys($path['namedArgs'])) && !empty($url[$keys[$i]])) { } elseif (!empty($path['namedArgs']) && in_array($keys[$i], array_keys($path['namedArgs'])) && !empty($url[$keys[$i]])) {
$named[] = $keys[$i] . $path['argSeparator'] . $url[$keys[$i]]; $named[] = $keys[$i] . $path['argSeparator'] . $url[$keys[$i]];
} elseif(!empty($url[$keys[$i]]) || is_numeric($url[$keys[$i]])) { } elseif (!empty($url[$keys[$i]]) || is_numeric($url[$keys[$i]])) {
$named[] = $keys[$i] . $path['argSeparator'] . $url[$keys[$i]]; $named[] = $keys[$i] . $path['argSeparator'] . $url[$keys[$i]];
} }
} }
@ -547,7 +547,7 @@ class Router extends Object {
$urlOut = Set::filter(array($url['plugin'], $url['controller'], $url['action'])); $urlOut = Set::filter(array($url['plugin'], $url['controller'], $url['action']));
if($url['plugin'] == $url['controller']) { if ($url['plugin'] == $url['controller']) {
array_shift($urlOut); array_shift($urlOut);
} }
if (defined('CAKE_ADMIN') && isset($url[CAKE_ADMIN]) && $url[CAKE_ADMIN]) { if (defined('CAKE_ADMIN') && isset($url[CAKE_ADMIN]) && $url[CAKE_ADMIN]) {
@ -557,7 +557,7 @@ class Router extends Object {
} }
if (!empty($args)) { if (!empty($args)) {
if($output{strlen($output)-1} == '/') { if ($output{strlen($output)-1} == '/') {
$output .= join('/', Set::filter($args, true)); $output .= join('/', Set::filter($args, true));
} else { } else {
$output .= '/'. join('/', Set::filter($args, true)); $output .= '/'. join('/', Set::filter($args, true));
@ -565,7 +565,7 @@ class Router extends Object {
} }
if (!empty($named)) { if (!empty($named)) {
if($output{strlen($output)-1} == '/') { if ($output{strlen($output)-1} == '/') {
$output .= join('/', Set::filter($named, true)); $output .= join('/', Set::filter($named, true));
} else { } else {
$output .= '/'. join('/', Set::filter($named, true)); $output .= '/'. join('/', Set::filter($named, true));
@ -580,7 +580,7 @@ class Router extends Object {
if (empty($url)) { if (empty($url)) {
return $path['here']; return $path['here'];
} elseif($url{0} == '/') { } elseif ($url{0} == '/') {
$output = $base . $url; $output = $base . $url;
} else { } else {
$output = $base . '/'; $output = $base . '/';
@ -624,8 +624,8 @@ class Router extends Object {
return false; return false;
} }
foreach($pass as $key => $value) { foreach ($pass as $key => $value) {
if(!is_numeric($key)) { if (!is_numeric($key)) {
unset($pass[$key]); unset($pass[$key]);
} }
} }
@ -637,7 +637,7 @@ class Router extends Object {
return array(Router::__mapRoute($route, am($url, array('pass' => $pass))), array()); return array(Router::__mapRoute($route, am($url, array('pass' => $pass))), array());
} elseif (!empty($params) && !empty($route[3])) { } elseif (!empty($params) && !empty($route[3])) {
$required = array_diff(array_keys($defaults), array_keys($url)); $required = array_diff(array_keys($defaults), array_keys($url));
if(!empty($required)) { if (!empty($required)) {
return false; return false;
} }
@ -655,17 +655,17 @@ class Router extends Object {
} }
} else { } else {
$required = array_diff(array_keys($defaults), array_keys($url)); $required = array_diff(array_keys($defaults), array_keys($url));
if(empty($required) && $defaults['plugin'] == $url['plugin'] && $defaults['controller'] == $url['controller'] && $defaults['action'] == $url['action']) { if (empty($required) && $defaults['plugin'] == $url['plugin'] && $defaults['controller'] == $url['controller'] && $defaults['action'] == $url['action']) {
return array(Router::__mapRoute($route, am($url, array('pass' => $pass))), $url); return array(Router::__mapRoute($route, am($url, array('pass' => $pass))), $url);
} }
return false; return false;
} }
if(isset($route[3]['controller']) && !empty($route[3]['controller']) && $url['controller'] != $route[3]['controller']) { if (isset($route[3]['controller']) && !empty($route[3]['controller']) && $url['controller'] != $route[3]['controller']) {
return false; return false;
} }
if(!empty($route[4])) { if (!empty($route[4])) {
foreach ($route[4] as $key => $reg) { foreach ($route[4] as $key => $reg) {
if (isset($url[$key]) && !preg_match('/' . $reg . '/', $url[$key])) { if (isset($url[$key]) && !preg_match('/' . $reg . '/', $url[$key])) {
return false; return false;
@ -786,16 +786,16 @@ class Router extends Object {
*/ */
function stripEscape($param) { function stripEscape($param) {
$_this =& Router::getInstance(); $_this =& Router::getInstance();
if(!is_array($param) || empty($param)) { if (!is_array($param) || empty($param)) {
if(is_bool($param)) { if (is_bool($param)) {
return $param; return $param;
} }
$return = preg_replace('/^[\\t ]*(?:-!)+/', '', $param); $return = preg_replace('/^[\\t ]*(?:-!)+/', '', $param);
return $return; return $return;
} }
foreach($param as $key => $value) { foreach ($param as $key => $value) {
if(is_string($value)) { if (is_string($value)) {
$return[$key] = preg_replace('/^[\\t ]*(?:-!)+/', '', $value); $return[$key] = preg_replace('/^[\\t ]*(?:-!)+/', '', $value);
} else { } else {
foreach ($value as $array => $string) { foreach ($value as $array => $string) {
@ -829,7 +829,7 @@ class Router extends Object {
} }
} }
if(!function_exists('http_build_query')) { if (!function_exists('http_build_query')) {
/** /**
* Implements http_build_query for PHP4. * Implements http_build_query for PHP4.
* *
@ -841,7 +841,7 @@ if(!function_exists('http_build_query')) {
* @see http://php.net/http_build_query * @see http://php.net/http_build_query
*/ */
function http_build_query($data, $prefix = null, $argSep = null, $baseKey = null) { function http_build_query($data, $prefix = null, $argSep = null, $baseKey = null) {
if(empty($argSep)) { if (empty($argSep)) {
$argSep = ini_get('arg_separator.output'); $argSep = ini_get('arg_separator.output');
} }
if (is_object($data)) { if (is_object($data)) {
@ -849,17 +849,17 @@ if(!function_exists('http_build_query')) {
} }
$out = array(); $out = array();
foreach((array)$data as $key => $v) { foreach ((array)$data as $key => $v) {
if(is_numeric($key) && !empty($prefix)) { if (is_numeric($key) && !empty($prefix)) {
$key = $prefix . $key; $key = $prefix . $key;
} }
$key = urlencode($key); $key = urlencode($key);
if(!empty($baseKey)) { if (!empty($baseKey)) {
$key = $baseKey . '[' . $key . ']'; $key = $baseKey . '[' . $key . ']';
} }
if(is_array($v) || is_object($v)) { if (is_array($v) || is_object($v)) {
$out[] = http_build_query($v, $prefix, $argSep, $key); $out[] = http_build_query($v, $prefix, $argSep, $key);
} else { } else {
$out[] = $key . '=' . urlencode($v); $out[] = $key . '=' . urlencode($v);

View file

@ -47,13 +47,13 @@ class Sanitize{
function paranoid($string, $allowed = array()) { function paranoid($string, $allowed = array()) {
$allow = null; $allow = null;
if (!empty($allowed)) { if (!empty($allowed)) {
foreach($allowed as $value) { foreach ($allowed as $value) {
$allow .= "\\$value"; $allow .= "\\$value";
} }
} }
if (is_array($string)) { if (is_array($string)) {
foreach($string as $key => $clean) { foreach ($string as $key => $clean) {
$cleaned[$key] = preg_replace("/[^{$allow}a-zA-Z0-9]/", '', $clean); $cleaned[$key] = preg_replace("/[^{$allow}a-zA-Z0-9]/", '', $clean);
} }
} else { } else {
@ -153,7 +153,7 @@ class Sanitize{
$params = params(func_get_args()); $params = params(func_get_args());
$str = $params[0]; $str = $params[0];
for($i = 1; $i < count($params); $i++) { 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); $str = preg_replace('/<\/' . $params[$i] . '[^>]*>/i', '', $str);
} }
@ -209,7 +209,7 @@ class Sanitize{
* @static * @static
*/ */
function formatColumns(&$model) { function formatColumns(&$model) {
foreach($model->data as $name => $values) { foreach ($model->data as $name => $values) {
if ($name == $model->name) { if ($name == $model->name) {
$curModel =& $model; $curModel =& $model;
} elseif (isset($model->{$name}) && is_object($model->{$name}) && is_subclass_of($model->{$name}, 'Model')) { } elseif (isset($model->{$name}) && is_object($model->{$name}) && is_subclass_of($model->{$name}, 'Model')) {
@ -219,7 +219,7 @@ class Sanitize{
} }
if ($curModel != null) { if ($curModel != null) {
foreach($values as $column => $data) { foreach ($values as $column => $data) {
$colType = $curModel->getColumnType($column); $colType = $curModel->getColumnType($column);
if ($colType != null) { if ($colType != null) {

View file

@ -147,8 +147,8 @@ class Security extends Object{
srand (CIPHER_SEED); srand (CIPHER_SEED);
$out = ''; $out = '';
for($i = 0; $i < strlen($text); $i++) { for ($i = 0; $i < strlen($text); $i++) {
for($j = 0; $j < ord(substr($key, $i % strlen($key), 1)); $j++) { for ($j = 0; $j < ord(substr($key, $i % strlen($key), 1)); $j++) {
$toss = rand(0, 255); $toss = rand(0, 255);
} }
$mask = rand(0, 255); $mask = rand(0, 255);

View file

@ -129,7 +129,7 @@ class CakeSession extends Object {
} }
$this->time = time(); $this->time = time();
if($start === true) { if ($start === true) {
$this->host = env('HTTP_HOST'); $this->host = env('HTTP_HOST');
if (empty($base) || strpos($base, '?')) { if (empty($base) || strpos($base, '?')) {
@ -188,7 +188,7 @@ class CakeSession extends Object {
$names = array($name); $names = array($name);
} }
$expression = "\$_SESSION"; $expression = "\$_SESSION";
foreach($names as $item) { foreach ($names as $item) {
$expression .= is_numeric($item) ? "[$item]" : "['$item']"; $expression .= is_numeric($item) ? "[$item]" : "['$item']";
} }
return $expression; return $expression;
@ -575,7 +575,7 @@ class CakeSession extends Object {
*/ */
function __close() { function __close() {
$probability = mt_rand(1, 150); $probability = mt_rand(1, 150);
if($probability <= 3) { if ($probability <= 3) {
CakeSession::__gc(); CakeSession::__gc();
} }
return true; return true;

View file

@ -76,7 +76,7 @@ class Set extends Object {
function merge($arr1, $arr2 = null) { function merge($arr1, $arr2 = null) {
$args = func_get_args(); $args = func_get_args();
if(is_a($this, 'set')) { if (is_a($this, 'set')) {
$backtrace = debug_backtrace(); $backtrace = debug_backtrace();
$previousCall = low($backtrace[1]['class'].'::'.$backtrace[1]['function']); $previousCall = low($backtrace[1]['class'].'::'.$backtrace[1]['function']);
if ($previousCall != 'set::merge') { if ($previousCall != 'set::merge') {
@ -84,19 +84,19 @@ class Set extends Object {
array_unshift($args, null); array_unshift($args, null);
} }
} }
if(!isset($r)) { if (!isset($r)) {
$r = (array)current($args); $r = (array)current($args);
} }
while(($arg = next($args)) !== false) { while (($arg = next($args)) !== false) {
if (is_a($arg, 'set')) { if (is_a($arg, 'set')) {
$arg = $arg->get(); $arg = $arg->get();
} }
foreach((array)$arg as $key => $val) { foreach ((array)$arg as $key => $val) {
if(is_array($val) && isset($r[$key]) && is_array($r[$key])) { if (is_array($val) && isset($r[$key]) && is_array($r[$key])) {
$r[$key] = Set::merge($r[$key], $val); $r[$key] = Set::merge($r[$key], $val);
} elseif(is_int($key)) { } elseif (is_int($key)) {
$r[] = $val; $r[] = $val;
} else { } else {
$r[$key] = $val; $r[$key] = $val;
@ -135,7 +135,7 @@ class Set extends Object {
*/ */
function pushDiff($array = null, $array2 = null) { function pushDiff($array = null, $array2 = null) {
if ($array2 !== null && is_array($array2)) { if ($array2 !== null && is_array($array2)) {
foreach($array2 as $key => $value) { foreach ($array2 as $key => $value) {
if (!array_key_exists($key, $array)) { if (!array_key_exists($key, $array)) {
$array[$key] = $value; $array[$key] = $value;
} else { } else {
@ -147,7 +147,7 @@ class Set extends Object {
return $array; return $array;
} }
if(!isset($this->value)) { if (!isset($this->value)) {
$this->value = array(); $this->value = array();
} }
$this->value = Set::pushDiff($this->value, Set::__array($array)); $this->value = Set::pushDiff($this->value, Set::__array($array));
@ -332,7 +332,7 @@ class Set extends Object {
return null; return null;
} }
foreach($path as $i => $key) { foreach ($path as $i => $key) {
if (is_numeric($key) && intval($key) > 0 || $key == '0') { if (is_numeric($key) && intval($key) > 0 || $key == '0') {
if (isset($data[intval($key)])) { if (isset($data[intval($key)])) {
$data = $data[intval($key)]; $data = $data[intval($key)];
@ -340,7 +340,7 @@ class Set extends Object {
return null; return null;
} }
} elseif ($key == '{n}') { } elseif ($key == '{n}') {
foreach($data as $j => $val) { foreach ($data as $j => $val) {
$tmp[] = Set::extract($val, array_slice($path, $i + 1)); $tmp[] = Set::extract($val, array_slice($path, $i + 1));
} }
return $tmp; return $tmp;
@ -374,7 +374,7 @@ class Set extends Object {
} }
$_list =& $list; $_list =& $list;
foreach($path as $i => $key) { foreach ($path as $i => $key) {
if (is_numeric($key) && intval($key) > 0 || $key == '0') { if (is_numeric($key) && intval($key) > 0 || $key == '0') {
$key = intval($key); $key = intval($key);
} }
@ -407,7 +407,7 @@ class Set extends Object {
} }
$_list =& $list; $_list =& $list;
foreach($path as $i => $key) { foreach ($path as $i => $key) {
if (is_numeric($key) && intval($key) > 0 || $key == '0') { if (is_numeric($key) && intval($key) > 0 || $key == '0') {
$key = intval($key); $key = intval($key);
} }
@ -445,7 +445,7 @@ class Set extends Object {
$path = explode('.', $path); $path = explode('.', $path);
} }
foreach($path as $i => $key) { foreach ($path as $i => $key) {
if (is_numeric($key) && intval($key) > 0 || $key == '0') { if (is_numeric($key) && intval($key) > 0 || $key == '0') {
$key = intval($key); $key = intval($key);
} }
@ -486,7 +486,7 @@ class Set extends Object {
foreach ($val1 as $key => $val) { foreach ($val1 as $key => $val) {
if (isset($val2[$key]) && $val2[$key] != $val) { if (isset($val2[$key]) && $val2[$key] != $val) {
$out[$key] = $val; $out[$key] = $val;
} else if(!array_key_exists($key, $val2)){ } elseif (!array_key_exists($key, $val2)){
$out[$key] = $val; $out[$key] = $val;
} }
} }

View file

@ -126,12 +126,12 @@ class Validation extends Object {
$this->_extract($check); $this->_extract($check);
} }
if(empty($this->check)) { if (empty($this->check)) {
return false; return false;
} }
$this->regex = '/[^\\dA-Z]/i'; $this->regex = '/[^\\dA-Z]/i';
if($this->_check() === true){ if ($this->_check() === true){
return false; return false;
} else { } else {
return true; return true;
@ -177,7 +177,7 @@ class Validation extends Object {
} }
$this->regex = '/[^\\s]/'; $this->regex = '/[^\\s]/';
if($this->_check() === true){ if ($this->_check() === true){
return false; return false;
} else { } else {
return true; return true;
@ -210,12 +210,12 @@ class Validation extends Object {
$this->check = str_replace(array('-', ' '), '', $this->check); $this->check = str_replace(array('-', ' '), '', $this->check);
if(strlen($this->check) < 13){ if (strlen($this->check) < 13){
return false; return false;
} }
if(!is_null($this->regex)) { if (!is_null($this->regex)) {
if($this->_check()) { if ($this->_check()) {
return $this->_luhn(); return $this->_luhn();
} }
} }
@ -240,23 +240,23 @@ class Validation extends Object {
$card = low($value); $card = low($value);
$this->regex = $cards['all'][$card]; $this->regex = $cards['all'][$card];
if($this->_check()) { if ($this->_check()) {
return $this->_luhn(); return $this->_luhn();
} }
} }
} else { } else {
if($this->type == 'all') { if ($this->type == 'all') {
foreach ($cards['all'] as $key => $value) { foreach ($cards['all'] as $key => $value) {
$this->regex = $value; $this->regex = $value;
if($this->_check()) { if ($this->_check()) {
return $this->_luhn(); return $this->_luhn();
} }
} }
} else { } else {
$this->regex = $cards['fast']; $this->regex = $cards['fast'];
if($this->_check()) { if ($this->_check()) {
return $this->_luhn(); return $this->_luhn();
} }
} }
@ -284,37 +284,37 @@ class Validation extends Object {
switch($operator) { switch($operator) {
case 'isgreater': case 'isgreater':
case '>': case '>':
if($check1 > $check2) { if ($check1 > $check2) {
$return = true; $return = true;
} }
break; break;
case 'isless': case 'isless':
case '<': case '<':
if($check1 < $check2) { if ($check1 < $check2) {
$return = true; $return = true;
} }
break; break;
case 'greaterorequal': case 'greaterorequal':
case '>=': case '>=':
if($check1 >= $check2) { if ($check1 >= $check2) {
$return = true; $return = true;
} }
break; break;
case 'lessorequal': case 'lessorequal':
case '<=': case '<=':
if($check1 <= $check2) { if ($check1 <= $check2) {
$return = true; $return = true;
} }
break; break;
case 'equalto': case 'equalto':
case '==': case '==':
if($check1 == $check2) { if ($check1 == $check2) {
$return = true; $return = true;
} }
break; break;
case 'notequal': case 'notequal':
case '!=': case '!=':
if($check1 != $check2) { if ($check1 != $check2) {
$return = true; $return = true;
} }
break; break;
@ -341,7 +341,7 @@ class Validation extends Object {
if (is_array($check)) { if (is_array($check)) {
$this->_extract($check); $this->_extract($check);
} }
if($this->regex === null){ if ($this->regex === null){
$this->errors[] = __('You must define a regular expression for Validation::custom()', true); $this->errors[] = __('You must define a regular expression for Validation::custom()', true);
return false; return false;
} }
@ -369,14 +369,14 @@ class Validation extends Object {
$this->check = $check; $this->check = $check;
$this->regex = $regex; $this->regex = $regex;
if(!is_null($this->regex)) { if (!is_null($this->regex)) {
return $this->_check(); return $this->_check();
} }
$search = array(); $search = array();
if(is_array($format)){ if (is_array($format)){
foreach($format as $key => $value){ foreach ($format as $key => $value){
$search[$value] = $value; $search[$value] = $value;
} }
} else { } else {
@ -393,7 +393,7 @@ class Validation extends Object {
foreach ($search as $key){ foreach ($search as $key){
$this->regex = $regex[$key]; $this->regex = $regex[$key];
if($this->_check() === true){ if ($this->_check() === true){
return true; return true;
} }
} }
@ -414,11 +414,11 @@ class Validation extends Object {
$this->regex = $regex; $this->regex = $regex;
$this->check = $check; $this->check = $check;
if(!is_null($this->regex)) { if (!is_null($this->regex)) {
return $this->_check(); return $this->_check();
} }
if(is_null($places)) { if (is_null($places)) {
$this->regex = '/^[-+]?[0-9]*\\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?$/'; $this->regex = '/^[-+]?[0-9]*\\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?$/';
return $this->_check(); return $this->_check();
} }
@ -445,12 +445,12 @@ class Validation extends Object {
$this->_extract($check); $this->_extract($check);
} }
if(is_null($this->regex)) { if (is_null($this->regex)) {
$this->regex = '/\\A(?:^([a-z0-9][a-z0-9_\\-\\.\\+]*)@([a-z0-9][a-z0-9\\.\\-]{0,63}\\.(com|org|net|biz|info|name|net|pro|aero|coop|museum|[a-z]{2,4}))$)\\z/i'; $this->regex = '/\\A(?:^([a-z0-9][a-z0-9_\\-\\.\\+]*)@([a-z0-9][a-z0-9\\.\\-]{0,63}\\.(com|org|net|biz|info|name|net|pro|aero|coop|museum|[a-z]{2,4}))$)\\z/i';
} }
$return = $this->_check(); $return = $this->_check();
if($this->deep === false || $this->deep === null) { if ($this->deep === false || $this->deep === null) {
return $return; return $return;
} }
@ -580,7 +580,7 @@ class Validation extends Object {
if (isset($lower) && isset($upper) && $lower > $upper) { if (isset($lower) && isset($upper) && $lower > $upper) {
//error //error
} }
if(is_float($check)) { if (is_float($check)) {
} }
} }
@ -614,7 +614,7 @@ class Validation extends Object {
$this->country = $country; $this->country = $country;
} }
if(is_null($this->regex)) { if (is_null($this->regex)) {
switch ($this->country) { switch ($this->country) {
case 'us': case 'us':
$this->regex = '/1?[-. ]?\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})/'; $this->regex = '/1?[-. ]?\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})/';
@ -642,7 +642,7 @@ class Validation extends Object {
$this->country = $country; $this->country = $country;
} }
if(is_null($this->regex)) { if (is_null($this->regex)) {
switch ($this->country) { switch ($this->country) {
case 'us': case 'us':
$this->regex = '/\\A\\b[0-9]{5}(?:-[0-9]{4})?\\b\\z/i'; $this->regex = '/\\A\\b[0-9]{5}(?:-[0-9]{4})?\\b\\z/i';
@ -676,7 +676,7 @@ class Validation extends Object {
$this->country = $country; $this->country = $country;
} }
if(is_null($this->regex)) { if (is_null($this->regex)) {
switch ($this->country) { switch ($this->country) {
case 'us': case 'us':
$this->regex = '/\\A\\b[0-9]{3}-[0-9]{2}-[0-9]{4}\\b\\z/i'; $this->regex = '/\\A\\b[0-9]{3}-[0-9]{2}-[0-9]{4}\\b\\z/i';
@ -768,8 +768,8 @@ class Validation extends Object {
* @access protected * @access protected
*/ */
function _luhn() { function _luhn() {
if($this->deep === true){ if ($this->deep === true){
if($this->check == 0) { if ($this->check == 0) {
return false; return false;
} }
$sum = 0; $sum = 0;

View file

@ -157,7 +157,7 @@ class Helper extends Overloadable {
function loadConfig($name = 'tags') { function loadConfig($name = 'tags') {
if (file_exists(APP . 'config' . DS . $name .'.php')) { if (file_exists(APP . 'config' . DS . $name .'.php')) {
require(APP . 'config' . DS . $name .'.php'); require(APP . 'config' . DS . $name .'.php');
if(isset($tags)) { if (isset($tags)) {
$this->tags = am($this->tags, $tags); $this->tags = am($this->tags, $tags);
} }
} }
@ -190,14 +190,14 @@ class Helper extends Overloadable {
*/ */
function webroot($file) { function webroot($file) {
$webPath = "{$this->webroot}" . $file; $webPath = "{$this->webroot}" . $file;
if(!empty($this->themeWeb)) { if (!empty($this->themeWeb)) {
$os = env('OS'); $os = env('OS');
if (!empty($os) && strpos($os, 'Windows') !== false) { if (!empty($os) && strpos($os, 'Windows') !== false) {
$path = str_replace('/', '\\', WWW_ROOT . $this->themeWeb . $file); $path = str_replace('/', '\\', WWW_ROOT . $this->themeWeb . $file);
} else { } else {
$path = WWW_ROOT . $this->themeWeb . $file; $path = WWW_ROOT . $this->themeWeb . $file;
} }
if(file_exists($path)){ if (file_exists($path)){
$webPath = "{$this->webroot}" . $this->themeWeb . $file; $webPath = "{$this->webroot}" . $this->themeWeb . $file;
} }
} }
@ -268,7 +268,7 @@ class Helper extends Overloadable {
$values = array_intersect_key(array_values($options), $keys); $values = array_intersect_key(array_values($options), $keys);
$escape = $options['escape']; $escape = $options['escape'];
$attributes = array(); $attributes = array();
foreach($keys as $index => $key) { foreach ($keys as $index => $key) {
$attributes[] = $this->__formatAttribute($key, $values[$index], $escape); $attributes[] = $this->__formatAttribute($key, $values[$index], $escape);
} }
$out = implode(' ', $attributes); $out = implode(' ', $attributes);
@ -305,7 +305,7 @@ class Helper extends Overloadable {
function setFormTag($tagValue) { function setFormTag($tagValue) {
$view =& ClassRegistry::getObject('view'); $view =& ClassRegistry::getObject('view');
if($tagValue === null) { if ($tagValue === null) {
$view->model = null; $view->model = null;
$view->association = null; $view->association = null;
$view->modelId = null; $view->modelId = null;
@ -330,7 +330,7 @@ class Helper extends Overloadable {
$view->modelId = $parts[1]; $view->modelId = $parts[1];
$view->field = $parts[2]; $view->field = $parts[2];
} }
if(!isset($view->model)) { if (!isset($view->model)) {
$view->model = $view->association; $view->model = $view->association;
$view->association = null; $view->association = null;
} }
@ -342,7 +342,7 @@ class Helper extends Overloadable {
*/ */
function model() { function model() {
$view =& ClassRegistry::getObject('view'); $view =& ClassRegistry::getObject('view');
if($view->association == null) { if ($view->association == null) {
return $view->model; return $view->model;
} else { } else {
return $view->association; return $view->association;
@ -591,18 +591,18 @@ class Helper extends Overloadable {
* @access private * @access private
*/ */
function __selectedArray($data, $key = 'id') { function __selectedArray($data, $key = 'id') {
if(!is_array($data)) { if (!is_array($data)) {
$model = $data; $model = $data;
if(!empty($this->data[$model][$model])) { if (!empty($this->data[$model][$model])) {
return $this->data[$model][$model]; return $this->data[$model][$model];
} }
if(!empty($this->data[$model])) { if (!empty($this->data[$model])) {
$data = $this->data[$model]; $data = $this->data[$model];
} }
} }
$array = array(); $array = array();
if(!empty($data)) { if (!empty($data)) {
foreach($data as $var) { foreach ($data as $var) {
$array[$var[$key]] = $var[$key]; $array[$var[$key]] = $var[$key];
} }
} }

View file

@ -605,7 +605,7 @@ class AjaxHelper extends AppHelper {
$url = $this->url($url); $url = $this->url($url);
$options['ajaxOptions'] = $this->__optionsForAjax($options); $options['ajaxOptions'] = $this->__optionsForAjax($options);
foreach($this->ajaxOptions as $opt) { foreach ($this->ajaxOptions as $opt) {
if (isset($options[$opt])) { if (isset($options[$opt])) {
unset($options[$opt]); unset($options[$opt]);
} }
@ -682,7 +682,7 @@ class AjaxHelper extends AppHelper {
); );
$options = $this->_optionsToString($options, array('method')); $options = $this->_optionsToString($options, array('method'));
foreach($options as $key => $value) { foreach ($options as $key => $value) {
switch($key) { switch($key) {
case 'type': case 'type':
$jsOptions['asynchronous'] = ife(($value == 'synchronous'), 'false', 'true'); $jsOptions['asynchronous'] = ife(($value == 'synchronous'), 'false', 'true');
@ -721,13 +721,13 @@ class AjaxHelper extends AppHelper {
* @access private * @access private
*/ */
function __getHtmlOptions($options, $extra = array()) { function __getHtmlOptions($options, $extra = array()) {
foreach($this->ajaxOptions as $key) { foreach ($this->ajaxOptions as $key) {
if (isset($options[$key])) { if (isset($options[$key])) {
unset($options[$key]); unset($options[$key]);
} }
} }
foreach($extra as $key) { foreach ($extra as $key) {
if (isset($options[$key])) { if (isset($options[$key])) {
unset($options[$key]); unset($options[$key]);
} }
@ -747,7 +747,7 @@ class AjaxHelper extends AppHelper {
if (is_array($options)) { if (is_array($options)) {
$out = array(); $out = array();
foreach($options as $k => $v) { foreach ($options as $k => $v) {
if (in_array($k, $acceptable)) { if (in_array($k, $acceptable)) {
$out[] = "$k:$v"; $out[] = "$k:$v";
} }
@ -789,7 +789,7 @@ class AjaxHelper extends AppHelper {
function _buildCallbacks($options) { function _buildCallbacks($options) {
$callbacks = array(); $callbacks = array();
foreach($this->callbacks as $callback) { foreach ($this->callbacks as $callback) {
if (isset($options[$callback])) { if (isset($options[$callback])) {
$name = 'on' . ucfirst($callback); $name = 'on' . ucfirst($callback);
$code = $options[$callback]; $code = $options[$callback];
@ -816,7 +816,7 @@ class AjaxHelper extends AppHelper {
* @return array * @return array
*/ */
function _optionsToString($options, $stringOpts = array()) { function _optionsToString($options, $stringOpts = array()) {
foreach($stringOpts as $option) { foreach ($stringOpts as $option) {
if (isset($options[$option]) && !$options[$option][0] != "'") { if (isset($options[$option]) && !$options[$option][0] != "'") {
if ($options[$option] === true || $options[$option] === 'true') { if ($options[$option] === true || $options[$option] === 'true') {
$options[$option] = 'true'; $options[$option] = 'true';

View file

@ -82,7 +82,7 @@ class CacheHelper extends AppHelper {
$index = null; $index = null;
$count = 0; $count = 0;
foreach($keys as $key => $value) { foreach ($keys as $key => $value) {
if (strpos($check, $value) === 0) { if (strpos($check, $value) === 0) {
$index = $found[$count]; $index = $found[$count];
break; break;
@ -143,7 +143,7 @@ class CacheHelper extends AppHelper {
if (!empty($result['0'])) { if (!empty($result['0'])) {
$count = 0; $count = 0;
foreach($result['0'] as $result) { foreach ($result['0'] as $result) {
if (isset($oresult['0'][$count])) { if (isset($oresult['0'][$count])) {
$this->__replace[] = $result; $this->__replace[] = $result;
$this->__match[] = $oresult['0'][$count]; $this->__match[] = $oresult['0'][$count];
@ -163,7 +163,7 @@ class CacheHelper extends AppHelper {
$count = 0; $count = 0;
if (!empty($this->__match)) { if (!empty($this->__match)) {
foreach($this->__match as $found) { foreach ($this->__match as $found) {
$original = $cache; $original = $cache;
$length = strlen($found); $length = strlen($found);
$position = 0; $position = 0;
@ -171,7 +171,7 @@ class CacheHelper extends AppHelper {
for ($i = 1; $i <= 1; $i++) { for ($i = 1; $i <= 1; $i++) {
$position = strpos($cache, $found, $position); $position = strpos($cache, $found, $position);
if($position !== false) { if ($position !== false) {
$cache = substr($original, 0, $position); $cache = substr($original, 0, $position);
$cache .= $this->__replace[$count]; $cache .= $this->__replace[$count];
$cache .= substr($original, $position + $length); $cache .= substr($original, $position + $length);
@ -203,13 +203,13 @@ class CacheHelper extends AppHelper {
} }
$cache = convertSlash($this->here); $cache = convertSlash($this->here);
if(empty($cache)){ if (empty($cache)){
return; return;
} }
$cache = $cache . '.php'; $cache = $cache . '.php';
$file = '<!--cachetime:' . $cacheTime . '--><?php'; $file = '<!--cachetime:' . $cacheTime . '--><?php';
if(empty($this->plugin)) { if (empty($this->plugin)) {
$file .= ' $file .= '
loadController(\'' . $this->controllerName. '\'); loadController(\'' . $this->controllerName. '\');
loadModels(); loadModels();
@ -244,15 +244,15 @@ class CacheHelper extends AppHelper {
$this->plugin = \'' . $this->plugin . '\'; $this->plugin = \'' . $this->plugin . '\';
$loadedHelpers = array(); $loadedHelpers = array();
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers); $loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
foreach(array_keys($loadedHelpers) as $helper) foreach (array_keys($loadedHelpers) as $helper)
{ {
$replace = strtolower(substr($helper, 0, 1)); $replace = strtolower(substr($helper, 0, 1));
$camelBackedHelper = preg_replace(\'/\\w/\', $replace, $helper, 1); $camelBackedHelper = preg_replace(\'/\\w/\', $replace, $helper, 1);
${$camelBackedHelper} =& $loadedHelpers[$helper]; ${$camelBackedHelper} =& $loadedHelpers[$helper];
if(isset(${$camelBackedHelper}->helpers) && is_array(${$camelBackedHelper}->helpers)) if (isset(${$camelBackedHelper}->helpers) && is_array(${$camelBackedHelper}->helpers))
{ {
foreach(${$camelBackedHelper}->helpers as $subHelper) foreach (${$camelBackedHelper}->helpers as $subHelper)
{ {
${$camelBackedHelper}->{$subHelper} =& $loadedHelpers[$subHelper]; ${$camelBackedHelper}->{$subHelper} =& $loadedHelpers[$subHelper];
} }

View file

@ -1231,17 +1231,17 @@ class FormHelper extends AppHelper {
switch ($name) { switch ($name) {
case 'minute': case 'minute':
for($i = 0; $i < 60; $i++) { for ($i = 0; $i < 60; $i++) {
$data[$i] = sprintf('%02d', $i); $data[$i] = sprintf('%02d', $i);
} }
break; break;
case 'hour': case 'hour':
for($i = 1; $i <= 12; $i++) { for ($i = 1; $i <= 12; $i++) {
$data[sprintf('%02d', $i)] = $i; $data[sprintf('%02d', $i)] = $i;
} }
break; break;
case 'hour24': case 'hour24':
for($i = 0; $i <= 23; $i++) { for ($i = 0; $i <= 23; $i++) {
$data[sprintf('%02d', $i)] = $i; $data[sprintf('%02d', $i)] = $i;
} }
break; break;
@ -1255,12 +1255,12 @@ class FormHelper extends AppHelper {
if (empty($max)) { if (empty($max)) {
$max = 31; $max = 31;
} }
for($i = $min; $i <= $max; $i++) { for ($i = $min; $i <= $max; $i++) {
$data[sprintf('%02d', $i)] = $i; $data[sprintf('%02d', $i)] = $i;
} }
break; break;
case 'month': case 'month':
for($i = 1; $i <= 12; $i++) { for ($i = 1; $i <= 12; $i++) {
$data[sprintf("%02s", $i)] = strftime("%B", mktime(1,1,1,$i,1,1999)); $data[sprintf("%02s", $i)] = strftime("%B", mktime(1,1,1,$i,1,1999));
} }
break; break;

View file

@ -226,9 +226,9 @@ class HtmlHelper extends AppHelper {
* @return string A meta tag containing the specified character set. * @return string A meta tag containing the specified character set.
*/ */
function charset($charset = null) { function charset($charset = null) {
if(is_null($charset)){ if (is_null($charset)){
$charset = Configure::read('charset'); $charset = Configure::read('charset');
if(is_null($charset)){ if (is_null($charset)){
$charset = 'utf-8'; $charset = 'utf-8';
} }
} }
@ -252,7 +252,7 @@ class HtmlHelper extends AppHelper {
* @return string An <a /> element. * @return string An <a /> element.
*/ */
function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true) { function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true) {
if($url !== null) { if ($url !== null) {
$url = $this->url($url); $url = $this->url($url);
} else { } else {
$url = $this->url($title); $url = $this->url($title);
@ -260,17 +260,17 @@ class HtmlHelper extends AppHelper {
$escapeTitle = false; $escapeTitle = false;
} }
if(isset($htmlAttributes['escape'])) { if (isset($htmlAttributes['escape'])) {
$escapeTitle = $htmlAttributes['escape']; $escapeTitle = $htmlAttributes['escape'];
unset($htmlAttributes['escape']); unset($htmlAttributes['escape']);
} }
if($escapeTitle === true) { if ($escapeTitle === true) {
$title = htmlspecialchars($title, ENT_QUOTES); $title = htmlspecialchars($title, ENT_QUOTES);
} elseif(is_string($escapeTitle)) { } elseif (is_string($escapeTitle)) {
$title = htmlentities($title, ENT_QUOTES, $escapeTitle); $title = htmlentities($title, ENT_QUOTES, $escapeTitle);
} }
if(!empty($htmlAttributes['confirm'])) { if (!empty($htmlAttributes['confirm'])) {
$confirmMessage = $htmlAttributes['confirm']; $confirmMessage = $htmlAttributes['confirm'];
unset($htmlAttributes['confirm']); unset($htmlAttributes['confirm']);
} }
@ -339,10 +339,10 @@ class HtmlHelper extends AppHelper {
return $data; return $data;
} }
$out = array(); $out = array();
foreach($data as $key=> $value) { foreach ($data as $key=> $value) {
$out[] = $key.':'.$value.';'; $out[] = $key.':'.$value.';';
} }
if($inline) { if ($inline) {
return 'style="'.join(' ', $out).'"'; return 'style="'.join(' ', $out).'"';
} }
return join("\n", $out); return join("\n", $out);
@ -361,8 +361,8 @@ class HtmlHelper extends AppHelper {
$out[] = $this->link($startText, '/'); $out[] = $this->link($startText, '/');
} }
foreach($this->_crumbs as $crumb) { foreach ($this->_crumbs as $crumb) {
if(!empty($crumb[1])){ if (!empty($crumb[1])){
$out[] = $this->link($crumb[0], $crumb[1]); $out[] = $this->link($crumb[0], $crumb[1]);
} else { } else {
$out[] = $crumb[0]; $out[] = $crumb[0];
@ -407,7 +407,7 @@ class HtmlHelper extends AppHelper {
$value = isset($htmlAttributes['value']) ? $htmlAttributes['value'] : $this->value($fieldName); $value = isset($htmlAttributes['value']) ? $htmlAttributes['value'] : $this->value($fieldName);
$out = array(); $out = array();
foreach($options as $optValue => $optTitle) { foreach ($options as $optValue => $optTitle) {
$optionsHere = array('value' => $optValue); $optionsHere = array('value' => $optValue);
if (!empty($value) && $optValue == $value) { if (!empty($value) && $optValue == $value) {
$optionsHere['checked'] = 'checked'; $optionsHere['checked'] = 'checked';
@ -430,7 +430,7 @@ class HtmlHelper extends AppHelper {
*/ */
function tableHeaders($names, $trOptions = null, $thOptions = null) { function tableHeaders($names, $trOptions = null, $thOptions = null) {
$out = array(); $out = array();
foreach($names as $arg) { foreach ($names as $arg) {
$out[] = sprintf($this->tags['tableheader'], $this->_parseAttributes($thOptions), $arg); $out[] = sprintf($this->tags['tableheader'], $this->_parseAttributes($thOptions), $arg);
} }
$data = sprintf($this->tags['tablerow'], $this->_parseAttributes($trOptions), join(' ', $out)); $data = sprintf($this->tags['tablerow'], $this->_parseAttributes($trOptions), join(' ', $out));
@ -450,11 +450,11 @@ class HtmlHelper extends AppHelper {
} }
static $count = 0; static $count = 0;
foreach($data as $line) { foreach ($data as $line) {
$count++; $count++;
$cellsOut = array(); $cellsOut = array();
foreach($line as $cell) { foreach ($line as $cell) {
$cellsOut[] = sprintf($this->tags['tablecell'], null, $cell); $cellsOut[] = sprintf($this->tags['tablecell'], null, $cell);
} }
$options = $this->_parseAttributes($count % 2 ? $oddTrOptions : $evenTrOptions); $options = $this->_parseAttributes($count % 2 ? $oddTrOptions : $evenTrOptions);
@ -568,7 +568,7 @@ class HtmlHelper extends AppHelper {
} else { } else {
$model = $this->model(); $model = $this->model();
if (isset($htmlAttributes['value']) || (!class_exists($model) && !loadModel($model))) { if (isset($htmlAttributes['value']) || (!class_exists($model) && !loadModel($model))) {
if(isset($htmlAttributes['value']) && $htmlAttributes['value'] == $value){ if (isset($htmlAttributes['value']) && $htmlAttributes['value'] == $value){
$htmlAttributes['checked'] = 'checked'; $htmlAttributes['checked'] = 'checked';
} else { } else {
$htmlAttributes['checked'] = null; $htmlAttributes['checked'] = null;
@ -662,7 +662,7 @@ class HtmlHelper extends AppHelper {
} }
$errors = array(); $errors = array();
foreach($objects as $object) { foreach ($objects as $object) {
$errors = array_merge($errors, $object->invalidFields($object->data)); $errors = array_merge($errors, $object->invalidFields($object->data));
} }
return $this->validationErrors = (count($errors) ? $errors : false); return $this->validationErrors = (count($errors) ? $errors : false);

View file

@ -305,7 +305,7 @@ class JavascriptHelper extends AppHelper {
$files = scandir(JS); $files = scandir(JS);
$javascript = ''; $javascript = '';
foreach($files as $file) { foreach ($files as $file) {
if (substr($file, -3) == '.js') { if (substr($file, -3) == '.js') {
$javascript .= file_get_contents(JS . "{$file}") . "\n\n"; $javascript .= file_get_contents(JS . "{$file}") . "\n\n";
} }
@ -345,7 +345,7 @@ class JavascriptHelper extends AppHelper {
$numeric = (array_values($keys) === array_keys(array_values($keys))); $numeric = (array_values($keys) === array_keys(array_values($keys)));
} }
foreach($data as $key => $val) { foreach ($data as $key => $val) {
if (is_array($val) || is_object($val)) { if (is_array($val) || is_object($val)) {
$val = $this->object($val, false, '', '', $stringKeys, $quoteKeys, $q); $val = $this->object($val, false, '', '', $stringKeys, $quoteKeys, $q);
} else { } else {

View file

@ -89,7 +89,7 @@ class JsHelper extends Overloadable2 {
$if{$len} = null; $if{$len} = null;
} }
$out = 'if(' . $if . ') { ' . $then . ' }'; $out = 'if (' . $if . ') { ' . $then . ' }';
foreach ($elseif as $cond => $exec) { foreach ($elseif as $cond => $exec) {
//$out .= //$out .=
@ -237,7 +237,7 @@ class JsHelper extends Overloadable2 {
$numeric = true; $numeric = true;
if (!empty($keys)) { if (!empty($keys)) {
foreach($keys as $key) { foreach ($keys as $key) {
if (!is_numeric($key)) { if (!is_numeric($key)) {
$numeric = false; $numeric = false;
break; break;
@ -245,7 +245,7 @@ class JsHelper extends Overloadable2 {
} }
} }
foreach($data as $key => $val) { foreach ($data as $key => $val) {
if (is_array($val) || is_object($val)) { if (is_array($val) || is_object($val)) {
$val = $this->object($val, false, '', '', $stringKeys, $quoteKeys, $q); $val = $this->object($val, false, '', '', $stringKeys, $quoteKeys, $q);
} else { } else {

View file

@ -96,33 +96,33 @@ class NumberHelper extends AppHelper {
*/ */
function format($number, $options = false) { function format($number, $options = false) {
$places = 0; $places = 0;
if(is_int($options)) { if (is_int($options)) {
$places = $options; $places = $options;
} }
$seperators = array(',', '.', '-', ':'); $seperators = array(',', '.', '-', ':');
$before = null; $before = null;
if(is_string($options) && !in_array( $options, $seperators)) { if (is_string($options) && !in_array( $options, $seperators)) {
$before = $options; $before = $options;
} }
$seperator = ','; $seperator = ',';
if(!is_array($options) && in_array( $options, $seperators)) { if (!is_array($options) && in_array( $options, $seperators)) {
$seperator = $options; $seperator = $options;
} }
if(is_array($options)) { if (is_array($options)) {
if(isset($options['places'])) { if (isset($options['places'])) {
$places = $options['places']; $places = $options['places'];
unset($options['places']); unset($options['places']);
} }
if(isset($options['before'])) { if (isset($options['before'])) {
$before = $options['before']; $before = $options['before'];
unset($options['before']); unset($options['before']);
} }
if(isset($options['seperator'])) { if (isset($options['seperator'])) {
$seperator = $options['seperator']; $seperator = $options['seperator'];
unset($options['seperator']); unset($options['seperator']);
} }

View file

@ -94,8 +94,8 @@ class PaginatorHelper extends AppHelper {
$options = array('update' => $options); $options = array('update' => $options);
} }
if(!empty($options['paging'])) { if (!empty($options['paging'])) {
if(!isset($this->params['paging'])) { if (!isset($this->params['paging'])) {
$this->params['paging'] = array(); $this->params['paging'] = array();
} }
$this->params['paging'] = am($this->params['paging'], $options['paging']); $this->params['paging'] = am($this->params['paging'], $options['paging']);
@ -103,8 +103,8 @@ class PaginatorHelper extends AppHelper {
} }
$model = $this->defaultModel(); $model = $this->defaultModel();
if(!empty($options[$model])) { if (!empty($options[$model])) {
if(!isset($this->params['paging'][$model])) { if (!isset($this->params['paging'][$model])) {
$this->params['paging'][$model] = array(); $this->params['paging'][$model] = array();
} }
$this->params['paging'][$model] = am($this->params['paging'][$model], $options[$model]); $this->params['paging'][$model] = am($this->params['paging'][$model], $options[$model]);
@ -244,13 +244,13 @@ class PaginatorHelper extends AppHelper {
$model = $options['model']; $model = $options['model'];
unset($options['model']); unset($options['model']);
if(!empty($this->options)) { if (!empty($this->options)) {
$options = am($this->options, $options); $options = am($this->options, $options);
} }
$paging = $this->params($model); $paging = $this->params($model);
$urlOption = null; $urlOption = null;
if(isset($options['url'])) { if (isset($options['url'])) {
$urlOption = $options['url']; $urlOption = $options['url'];
unset($options['url']); unset($options['url']);
} }
@ -434,7 +434,7 @@ class PaginatorHelper extends AppHelper {
$params = $this->params($options['model']); $params = $this->params($options['model']);
unset($options['model']); unset($options['model']);
if($params['pageCount'] <= 1) { if ($params['pageCount'] <= 1) {
return false; return false;
} }
$before = $options['before']; $before = $options['before'];
@ -450,15 +450,15 @@ class PaginatorHelper extends AppHelper {
$out = $before; $out = $before;
if($modulus && $params['pageCount'] > $modulus) { if ($modulus && $params['pageCount'] > $modulus) {
$half = intval($modulus / 2); $half = intval($modulus / 2);
$end = $params['page'] + $half; $end = $params['page'] + $half;
if($end > $params['pageCount']) { if ($end > $params['pageCount']) {
$end = $params['pageCount']; $end = $params['pageCount'];
} }
$start = $params['page'] - ($modulus - ($end - $params['page'])); $start = $params['page'] - ($modulus - ($end - $params['page']));
if($start <= 1) { if ($start <= 1) {
$start = 1; $start = 1;
$end = $params['page'] + ($modulus - $params['page']) + 1; $end = $params['page'] + ($modulus - $params['page']) + 1;
} }
@ -479,7 +479,7 @@ class PaginatorHelper extends AppHelper {
} }
} else { } else {
for ($i = 1; $i <= $params['pageCount']; $i++) { for ($i = 1; $i <= $params['pageCount']; $i++) {
if($i == $params['page']) { if ($i == $params['page']) {
$out .= $i; $out .= $i;
} else { } else {
$out .= $this->link($i, am($options, array('page' => $i))); $out .= $this->link($i, am($options, array('page' => $i)));

View file

@ -64,7 +64,7 @@ class TextHelper extends AppHelper {
$replace = array(); $replace = array();
$with = array(); $with = array();
foreach($phrase as $key => $value) { foreach ($phrase as $key => $value) {
$key = $value; $key = $value;
$value = $highlighter; $value = $highlighter;
@ -97,7 +97,7 @@ class TextHelper extends AppHelper {
function autoLinkUrls($text, $htmlOptions = array()) { function autoLinkUrls($text, $htmlOptions = array()) {
$options = 'array('; $options = 'array(';
foreach($htmlOptions as $option => $value) { foreach ($htmlOptions as $option => $value) {
$options .= "'$option' => '$value', "; $options .= "'$option' => '$value', ";
} }
$options .= ')'; $options .= ')';
@ -118,7 +118,7 @@ class TextHelper extends AppHelper {
function autoLinkEmails($text, $htmlOptions = array()) { function autoLinkEmails($text, $htmlOptions = array()) {
$options = 'array('; $options = 'array(';
foreach($htmlOptions as $option => $value) { foreach ($htmlOptions as $option => $value) {
$options .= "'$option' => '$value', "; $options .= "'$option' => '$value', ";
} }
$options .= ')'; $options .= ')';

View file

@ -94,7 +94,7 @@ class TimeHelper extends AppHelper {
if ($this->isToday($date)) { if ($this->isToday($date)) {
$ret = "Today, " . date("H:i", $date); $ret = "Today, " . date("H:i", $date);
} elseif($this->wasYesterday($date)) { } elseif ($this->wasYesterday($date)) {
$ret = "Yesterday, " . date("H:i", $date); $ret = "Yesterday, " . date("H:i", $date);
} else { } else {
$ret = date("M jS{$y}, H:i", $date); $ret = date("M jS{$y}, H:i", $date);
@ -280,15 +280,15 @@ class TimeHelper extends AppHelper {
// weeks and days // weeks and days
$relative_date .= ($relative_date ? ', ' : '') . $weeks . ' week' . ($weeks > 1 ? 's' : ''); $relative_date .= ($relative_date ? ', ' : '') . $weeks . ' week' . ($weeks > 1 ? 's' : '');
$relative_date .= $days > 0 ? ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '') : ''; $relative_date .= $days > 0 ? ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '') : '';
} elseif($days > 0) { } elseif ($days > 0) {
// days and hours // days and hours
$relative_date .= ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : ''); $relative_date .= ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '');
$relative_date .= $hours > 0 ? ($relative_date ? ', ' : '') . $hours . ' hour' . ($hours > 1 ? 's' : '') : ''; $relative_date .= $hours > 0 ? ($relative_date ? ', ' : '') . $hours . ' hour' . ($hours > 1 ? 's' : '') : '';
} elseif($hours > 0) { } elseif ($hours > 0) {
// hours and minutes // hours and minutes
$relative_date .= ($relative_date ? ', ' : '') . $hours . ' hour' . ($hours > 1 ? 's' : ''); $relative_date .= ($relative_date ? ', ' : '') . $hours . ' hour' . ($hours > 1 ? 's' : '');
$relative_date .= $minutes > 0 ? ($relative_date ? ', ' : '') . $minutes . ' minute' . ($minutes > 1 ? 's' : '') : ''; $relative_date .= $minutes > 0 ? ($relative_date ? ', ' : '') . $minutes . ' minute' . ($minutes > 1 ? 's' : '') : '';
} elseif($minutes > 0) { } elseif ($minutes > 0) {
// minutes only // minutes only
$relative_date .= ($relative_date ? ', ' : '') . $minutes . ' minute' . ($minutes > 1 ? 's' : ''); $relative_date .= ($relative_date ? ', ' : '') . $minutes . ' minute' . ($minutes > 1 ? 's' : '');
} else { } else {

View file

@ -45,7 +45,7 @@
</div> </div>
<div id="content"> <div id="content">
<?php <?php
if($session->check('Message.flash')): if ($session->check('Message.flash')):
$session->flash(); $session->flash();
endif; endif;
?> ?>

View file

@ -30,7 +30,7 @@
<title><?php echo $page_title?></title> <title><?php echo $page_title?></title>
<?php echo $html->charset(); ?> <?php echo $html->charset(); ?>
<?php if(Configure::read() == 0) { ?> <?php if (Configure::read() == 0) { ?>
<meta http-equiv="Refresh" content="<?php echo $pause?>;url=<?php echo $url?>"/> <meta http-equiv="Refresh" content="<?php echo $pause?>;url=<?php echo $url?>"/>
<?php } ?> <?php } ?>
<style><!-- <style><!--

View file

@ -29,7 +29,7 @@
<span class="notice"> <span class="notice">
<?php <?php
__('Your tmp directory is '); __('Your tmp directory is ');
if(is_writable(TMP)): if (is_writable(TMP)):
__('writable.'); __('writable.');
else: else:
__('NOT writable.'); __('NOT writable.');
@ -57,7 +57,7 @@
else: else:
__('NOT working.'); __('NOT working.');
echo '<br />'; echo '<br />';
if(is_writable(TMP)): if (is_writable(TMP)):
__('Edit: config/core.php to insure you have the newset version of this file and the variable $cakeCache set properly'); __('Edit: config/core.php to insure you have the newset version of this file and the variable $cakeCache set properly');
endif; endif;
endif; endif;
@ -69,7 +69,7 @@
<?php <?php
__('Your database configuration file is '); __('Your database configuration file is ');
$filePresent = null; $filePresent = null;
if(file_exists(CONFIGS.'database.php')): if (file_exists(CONFIGS.'database.php')):
__('present.'); __('present.');
$filePresent = true; $filePresent = true;
else: else:
@ -90,7 +90,7 @@ if (!empty($filePresent)):
<span class="notice"> <span class="notice">
<?php <?php
__('Cake'); __('Cake');
if($connected->isConnected()): if ($connected->isConnected()):
__(' is able to '); __(' is able to ');
else: else:
__(' is NOT able to '); __(' is NOT able to ');

View file

@ -29,14 +29,14 @@
<fieldset> <fieldset>
<legend><?php echo Inflector::humanize($this->action).' '. $singularHumanName;?></legend> <legend><?php echo Inflector::humanize($this->action).' '. $singularHumanName;?></legend>
<?php <?php
foreach($fields as $field) { foreach ($fields as $field) {
if($this->action == 'add' && $field['name'] == $primaryKey) { if ($this->action == 'add' && $field['name'] == $primaryKey) {
continue; continue;
} else if(!in_array($field['name'], array('created', 'modified', 'updated'))){ } elseif (!in_array($field['name'], array('created', 'modified', 'updated'))){
echo "\t\t".$form->input($field['name'])."\n"; echo "\t\t".$form->input($field['name'])."\n";
} }
} }
foreach($hasAndBelongsToMany as $assocName => $assocData) { foreach ($hasAndBelongsToMany as $assocName => $assocData) {
echo "\t\t".$form->input($assocName)."\n"; echo "\t\t".$form->input($assocName)."\n";
} }
?> ?>
@ -47,14 +47,14 @@
</div> </div>
<div class="actions"> <div class="actions">
<ul> <ul>
<?php if($this->action != 'add'):?> <?php if ($this->action != 'add'):?>
<li><?php echo $html->link(__('Delete', true), array('action'=>'delete', $form->value($modelClass.'.'.$primaryKey)), null, __('Are you sure you want to delete', true).' #' . $form->value($modelClass.'.'.$primaryKey)); ?></li> <li><?php echo $html->link(__('Delete', true), array('action'=>'delete', $form->value($modelClass.'.'.$primaryKey)), null, __('Are you sure you want to delete', true).' #' . $form->value($modelClass.'.'.$primaryKey)); ?></li>
<?php endif;?> <?php endif;?>
<li><?php echo $html->link(__('List', true).' '.$pluralHumanName, array('action'=>'index'));?></li> <li><?php echo $html->link(__('List', true).' '.$pluralHumanName, array('action'=>'index'));?></li>
<?php <?php
foreach($foreignKeys as $field => $value) { foreach ($foreignKeys as $field => $value) {
$otherModelClass = $value['1']; $otherModelClass = $value['1'];
if($otherModelClass != $modelClass) { if ($otherModelClass != $modelClass) {
$otherModelKey = Inflector::underscore($otherModelClass); $otherModelKey = Inflector::underscore($otherModelClass);
$otherControllerName = Inflector::pluralize($otherModelClass); $otherControllerName = Inflector::pluralize($otherModelClass);
$otherControllerPath = Inflector::underscore($otherControllerName); $otherControllerPath = Inflector::underscore($otherControllerName);

View file

@ -33,28 +33,28 @@ echo $paginator->counter(array(
?></p> ?></p>
<table cellpadding="0" cellspacing="0"> <table cellpadding="0" cellspacing="0">
<tr> <tr>
<?php foreach($fields as $field):?> <?php foreach ($fields as $field):?>
<th><?php echo $paginator->sort("{$field['name']}");?></th> <th><?php echo $paginator->sort("{$field['name']}");?></th>
<?php endforeach;?> <?php endforeach;?>
<th><?php __('Actions');?></th> <th><?php __('Actions');?></th>
</tr> </tr>
<?php <?php
$i = 0; $i = 0;
foreach(${$pluralVar} as ${$singularVar}): foreach (${$pluralVar} as ${$singularVar}):
$class = null; $class = null;
if($i++ % 2 == 0) { if ($i++ % 2 == 0) {
$class = ' class=\"altrow\"'; $class = ' class=\"altrow\"';
} }
echo "\n"; echo "\n";
echo "\t<tr" . $class . ">\n"; echo "\t<tr" . $class . ">\n";
foreach($fields as $field) { foreach ($fields as $field) {
if(in_array($field['name'], array_keys($foreignKeys))) { if (in_array($field['name'], array_keys($foreignKeys))) {
$otherModelClass = $foreignKeys[$field['name']][1]; $otherModelClass = $foreignKeys[$field['name']][1];
$otherModelKey = Inflector::underscore($otherModelClass); $otherModelKey = Inflector::underscore($otherModelClass);
$otherControllerName = Inflector::pluralize($otherModelClass); $otherControllerName = Inflector::pluralize($otherModelClass);
$otherControllerPath = Inflector::underscore($otherControllerName); $otherControllerPath = Inflector::underscore($otherControllerName);
if(isset($foreignKeys[$field['name']][2])) { if (isset($foreignKeys[$field['name']][2])) {
$otherModelClass = $foreignKeys[$field['name']][2]; $otherModelClass = $foreignKeys[$field['name']][2];
} }
$otherVariableName = Inflector::variable($otherModelClass); $otherVariableName = Inflector::variable($otherModelClass);
@ -88,9 +88,9 @@ echo "\n";
<ul> <ul>
<li><?php echo $html->link('New '.$singularHumanName, array('action'=>'add')); ?></li> <li><?php echo $html->link('New '.$singularHumanName, array('action'=>'add')); ?></li>
<?php <?php
foreach($foreignKeys as $field => $value) { foreach ($foreignKeys as $field => $value) {
$otherModelClass = $value['1']; $otherModelClass = $value['1'];
if($otherModelClass != $modelClass) { if ($otherModelClass != $modelClass) {
$otherModelKey = Inflector::underscore($otherModelClass); $otherModelKey = Inflector::underscore($otherModelClass);
$otherControllerName = Inflector::pluralize($otherModelClass); $otherControllerName = Inflector::pluralize($otherModelClass);
$otherControllerPath = Inflector::underscore($otherControllerName); $otherControllerPath = Inflector::underscore($otherControllerName);

View file

@ -29,18 +29,18 @@
<dl> <dl>
<?php <?php
$i = 0; $i = 0;
foreach($fields as $field) { foreach ($fields as $field) {
$class = null; $class = null;
if($i++ % 2 == 0) { if ($i++ % 2 == 0) {
$class = ' class="altrow"'; $class = ' class="altrow"';
} }
if(in_array($field['name'], array_keys($foreignKeys))) { if (in_array($field['name'], array_keys($foreignKeys))) {
$otherModelClass = $foreignKeys[$field['name']][1]; $otherModelClass = $foreignKeys[$field['name']][1];
$otherModelKey = Inflector::underscore($otherModelClass); $otherModelKey = Inflector::underscore($otherModelClass);
$otherControllerName = Inflector::pluralize($otherModelClass); $otherControllerName = Inflector::pluralize($otherModelClass);
$otherControllerPath = Inflector::underscore($otherControllerName); $otherControllerPath = Inflector::underscore($otherControllerName);
if(isset($foreignKeys[$field['name']][2])) { if (isset($foreignKeys[$field['name']][2])) {
$otherModelClass = $foreignKeys[$field['name']][2]; $otherModelClass = $foreignKeys[$field['name']][2];
} }
$otherSingularVar = Inflector::variable($otherModelClass); $otherSingularVar = Inflector::variable($otherModelClass);
@ -65,9 +65,9 @@ foreach($fields as $field) {
echo "\t\t<li>" .$html->link(__('List', true)." ".$pluralHumanName, array('action'=>'index')). " </li>\n"; echo "\t\t<li>" .$html->link(__('List', true)." ".$pluralHumanName, array('action'=>'index')). " </li>\n";
echo "\t\t<li>" .$html->link(__('New', true)." ".$singularHumanName, array('action'=>'add')). " </li>\n"; echo "\t\t<li>" .$html->link(__('New', true)." ".$singularHumanName, array('action'=>'add')). " </li>\n";
foreach($foreignKeys as $field => $value) { foreach ($foreignKeys as $field => $value) {
$otherModelClass = $value['1']; $otherModelClass = $value['1'];
if($otherModelClass != $modelClass) { if ($otherModelClass != $modelClass) {
$otherModelKey = Inflector::underscore($otherModelClass); $otherModelKey = Inflector::underscore($otherModelClass);
$otherControllerName = Inflector::pluralize($otherModelClass); $otherControllerName = Inflector::pluralize($otherModelClass);
$otherControllerPath = Inflector::underscore($otherControllerName); $otherControllerPath = Inflector::underscore($otherControllerName);
@ -95,13 +95,13 @@ foreach ($hasOne as $assocName => $assocData):
?> ?>
<div class="related"> <div class="related">
<h3><?php echo sprintf(__("Related %s", true), $otherPluralHumanName);?></h3> <h3><?php echo sprintf(__("Related %s", true), $otherPluralHumanName);?></h3>
<?php if(!empty(${$singularVar}[$assocName])):?> <?php if (!empty(${$singularVar}[$assocName])):?>
<dl> <dl>
<?php <?php
$i = 0; $i = 0;
foreach($otherFields as $field) { foreach ($otherFields as $field) {
$class = null; $class = null;
if($i++ % 2 == 0) { if ($i++ % 2 == 0) {
$class = ' class="altrow"'; $class = ' class="altrow"';
} }
echo "\t\t<dt{$class}>".Inflector::humanize($field['name'])."</dt>\n"; echo "\t\t<dt{$class}>".Inflector::humanize($field['name'])."</dt>\n";
@ -121,7 +121,7 @@ endforeach;
$relations = array_merge($hasMany, $hasAndBelongsToMany); $relations = array_merge($hasMany, $hasAndBelongsToMany);
$i = 0; $i = 0;
foreach($relations as $assocName => $assocData): foreach ($relations as $assocName => $assocData):
$otherModelKey = Inflector::underscore($assocData['className']); $otherModelKey = Inflector::underscore($assocData['className']);
$otherModelObj =& ClassRegistry::getObject($otherModelKey); $otherModelObj =& ClassRegistry::getObject($otherModelKey);
$otherControllerPath = Inflector::pluralize($otherModelKey); $otherControllerPath = Inflector::pluralize($otherModelKey);
@ -138,11 +138,11 @@ foreach($relations as $assocName => $assocData):
<?php if(!empty(${$singularVar}[$assocName])):?> <?php if (!empty(${$singularVar}[$assocName])):?>
<table cellpadding = "0" cellspacing = "0"> <table cellpadding = "0" cellspacing = "0">
<tr> <tr>
<?php <?php
foreach($otherFields as $field) { foreach ($otherFields as $field) {
echo "\t\t<th>".Inflector::humanize($field['name'])."</th>\n"; echo "\t\t<th>".Inflector::humanize($field['name'])."</th>\n";
} }
?> ?>
@ -150,14 +150,14 @@ foreach($relations as $assocName => $assocData):
</tr> </tr>
<?php <?php
$i = 0; $i = 0;
foreach(${$singularVar}[$assocName] as ${$otherSingularVar}): foreach (${$singularVar}[$assocName] as ${$otherSingularVar}):
$class = null; $class = null;
if($i++ % 2 == 0) { if ($i++ % 2 == 0) {
$class = ' class=\"altrow\"'; $class = ' class=\"altrow\"';
} }
echo "\t\t<tr{$class}>\n"; echo "\t\t<tr{$class}>\n";
foreach($otherFields as $field) { foreach ($otherFields as $field) {
echo "\t\t\t<td>".${$otherSingularVar}[$field['name']]."</td>\n"; echo "\t\t\t<td>".${$otherSingularVar}[$field['name']]."</td>\n";
} }

View file

@ -60,8 +60,8 @@ class ThemeView extends View {
parent::__construct($controller); parent::__construct($controller);
$this->theme =& $controller->theme; $this->theme =& $controller->theme;
if(!empty($this->theme)) { if (!empty($this->theme)) {
if(is_dir(WWW_ROOT . 'themed' . DS . $this->theme)){ if (is_dir(WWW_ROOT . 'themed' . DS . $this->theme)){
$this->themeWeb = 'themed/'. $this->theme .'/'; $this->themeWeb = 'themed/'. $this->theme .'/';
} }
$this->themeElement = 'themed'. DS . $this->theme . DS .'elements'. DS; $this->themeElement = 'themed'. DS . $this->theme . DS .'elements'. DS;
@ -79,7 +79,7 @@ class ThemeView extends View {
*/ */
function error($code, $name, $message) { function error($code, $name, $message) {
$file = VIEWS . $this->themeLayout.'error'.$this->ext; $file = VIEWS . $this->themeLayout.'error'.$this->ext;
if(!file_exists($file)) { if (!file_exists($file)) {
$file = LAYOUTS.'error'.$this->ext; $file = LAYOUTS.'error'.$this->ext;
} }
header ("HTTP/1.0 {$code} {$name}"); header ("HTTP/1.0 {$code} {$name}");
@ -96,7 +96,7 @@ class ThemeView extends View {
* @return unknown * @return unknown
*/ */
function renderElement($name, $params = array()) { function renderElement($name, $params = array()) {
if(isset($params['plugin'])) { if (isset($params['plugin'])) {
$this->plugin = $params['plugin']; $this->plugin = $params['plugin'];
$this->pluginPath = 'plugins' . DS . $this->plugin . DS; $this->pluginPath = 'plugins' . DS . $this->plugin . DS;
$this->pluginPaths = array( $this->pluginPaths = array(
@ -109,34 +109,34 @@ class ThemeView extends View {
$viewPaths = am($this->pluginPaths, $paths->viewPaths); $viewPaths = am($this->pluginPaths, $paths->viewPaths);
$file = null; $file = null;
foreach($viewPaths as $path) { foreach ($viewPaths as $path) {
if(file_exists($path . $this->themeElement . $name . $this->ext)) { if (file_exists($path . $this->themeElement . $name . $this->ext)) {
$file = $path . $this->themeElement . $name . $this->ext; $file = $path . $this->themeElement . $name . $this->ext;
break; break;
} else if(file_exists($path . $this->themeElement . $name . '.thtml')) { } elseif (file_exists($path . $this->themeElement . $name . '.thtml')) {
$file = $path . $this->themeElement . $name . '.thtml'; $file = $path . $this->themeElement . $name . '.thtml';
break; break;
} else if(file_exists($path . 'elements' . DS . $name . $this->ext)) { } elseif (file_exists($path . 'elements' . DS . $name . $this->ext)) {
$file = $path . 'elements' . DS . $name . $this->ext; $file = $path . 'elements' . DS . $name . $this->ext;
break; break;
} else if(file_exists($path . 'elements' . DS . $name . '.thtml')) { } elseif (file_exists($path . 'elements' . DS . $name . '.thtml')) {
$file = $path . 'elements' . DS . $name . '.thtml'; $file = $path . 'elements' . DS . $name . '.thtml';
break; break;
} }
} }
if(!is_null($file)) { if (!is_null($file)) {
$params = array_merge_recursive($params, $this->loaded); $params = array_merge_recursive($params, $this->loaded);
return $this->_render($file, array_merge($this->viewVars, $params), false); return $this->_render($file, array_merge($this->viewVars, $params), false);
} }
if(!is_null($this->pluginPath)) { if (!is_null($this->pluginPath)) {
$file = APP . $this->pluginPath . $this->themeElement . $name . $this->ext; $file = APP . $this->pluginPath . $this->themeElement . $name . $this->ext;
} else { } else {
$file = VIEWS . $this->themeElement . $name . $this->ext; $file = VIEWS . $this->themeElement . $name . $this->ext;
} }
if(Configure::read() > 0) { if (Configure::read() > 0) {
return "Not Found: " . $file; return "Not Found: " . $file;
} }
} }
@ -169,24 +169,24 @@ class ThemeView extends View {
$viewPaths = am($this->pluginPaths, $paths->viewPaths); $viewPaths = am($this->pluginPaths, $paths->viewPaths);
$name = $this->viewPath . DS . $this->subDir . $type . $action; $name = $this->viewPath . DS . $this->subDir . $type . $action;
foreach($viewPaths as $path) { foreach ($viewPaths as $path) {
if(file_exists($path . $this->themePath . $name . $this->ext)) { if (file_exists($path . $this->themePath . $name . $this->ext)) {
return $path . $this->themePath . $name . $this->ext; return $path . $this->themePath . $name . $this->ext;
} else if(file_exists($path . $this->themePath . $name . '.thtml')) { } elseif (file_exists($path . $this->themePath . $name . '.thtml')) {
return $path . $this->themePath . $name . '.thtml'; return $path . $this->themePath . $name . '.thtml';
} else if(file_exists($path . $name . $this->ext)) { } elseif (file_exists($path . $name . $this->ext)) {
return $path . $name . $this->ext; return $path . $name . $this->ext;
} else if(file_exists($path . $name . '.thtml')) { } elseif (file_exists($path . $name . '.thtml')) {
return $path . $name . '.thtml'; return $path . $name . '.thtml';
} }
} }
if ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'errors' . DS . $type . $action . '.ctp')) { if ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'errors' . DS . $type . $action . '.ctp')) {
return $viewFileName; return $viewFileName;
} elseif($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $this->viewPath . DS . $type . $action . '.ctp')) { } elseif ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $this->viewPath . DS . $type . $action . '.ctp')) {
return $viewFileName; return $viewFileName;
} else { } else {
if(!is_null($this->pluginPath)) { if (!is_null($this->pluginPath)) {
$viewFileName = APP . $this->pluginPath . $this->themePath . $name . $this->ext; $viewFileName = APP . $this->pluginPath . $this->themePath . $name . $this->ext;
} else { } else {
$viewFileName = VIEWS . $this->themePath . $name . $this->ext; $viewFileName = VIEWS . $this->themePath . $name . $this->ext;
@ -208,7 +208,7 @@ class ThemeView extends View {
$type = null; $type = null;
} }
if(!is_null($this->layoutPath)) { if (!is_null($this->layoutPath)) {
$type = $this->layoutPath . DS; $type = $this->layoutPath . DS;
} }
@ -216,19 +216,19 @@ class ThemeView extends View {
$viewPaths = am($this->pluginPaths, $paths->viewPaths); $viewPaths = am($this->pluginPaths, $paths->viewPaths);
$name = $this->subDir . $type . $this->layout; $name = $this->subDir . $type . $this->layout;
foreach($viewPaths as $path) { foreach ($viewPaths as $path) {
if(file_exists($path . $this->themeLayout . $name . $this->ext)) { if (file_exists($path . $this->themeLayout . $name . $this->ext)) {
return $path . $this->themeLayout . $name . $this->ext; return $path . $this->themeLayout . $name . $this->ext;
} else if(file_exists($path . $this->themeLayout . $name . '.thtml')) { } elseif (file_exists($path . $this->themeLayout . $name . '.thtml')) {
return $path . $this->themeLayout . $name . '.thtml'; return $path . $this->themeLayout . $name . '.thtml';
} else if(file_exists($path . 'layouts' . DS . $name . $this->ext)) { } elseif (file_exists($path . 'layouts' . DS . $name . $this->ext)) {
return $path . 'layouts' . DS . $name . $this->ext; return $path . 'layouts' . DS . $name . $this->ext;
} else if(file_exists($path . 'layouts' . DS . $name . '.thtml')) { } elseif (file_exists($path . 'layouts' . DS . $name . '.thtml')) {
return $path . 'layouts' . DS . $name . '.thtml'; return $path . 'layouts' . DS . $name . '.thtml';
} }
} }
if(!is_null($this->pluginPath)) { if (!is_null($this->pluginPath)) {
$layoutFileName = APP . $this->pluginPath . 'views' . DS . $this->themeLayout . $name . $this->ext; $layoutFileName = APP . $this->pluginPath . 'views' . DS . $this->themeLayout . $name . $this->ext;
} else { } else {
$layoutFileName = VIEWS . $this->themeLayout . $name . $this->ext; $layoutFileName = VIEWS . $this->themeLayout . $name . $this->ext;
@ -238,11 +238,11 @@ class ThemeView extends View {
if (empty($default) && !empty($type)) { if (empty($default) && !empty($type)) {
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $type . 'default.ctp'); $default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $type . 'default.ctp');
} }
if(empty($default)) { if (empty($default)) {
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $this->layout . '.ctp'); $default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $this->layout . '.ctp');
} }
if(!empty($default)) { if (!empty($default)) {
return $default; return $default;
} }
return $layoutFileName; return $layoutFileName;

View file

@ -282,7 +282,7 @@ class View extends Object {
* @return View * @return View
*/ */
function __construct(&$controller) { function __construct(&$controller) {
if(is_object($controller)) { if (is_object($controller)) {
$count = count($this->__passedVars); $count = count($this->__passedVars);
for ($j = 0; $j < $count; $j++) { for ($j = 0; $j < $count; $j++) {
$var = $this->__passedVars[$j]; $var = $this->__passedVars[$j];
@ -370,7 +370,7 @@ class View extends Object {
*/ */
function renderElement($name, $params = array(), $loadHelpers = false) { function renderElement($name, $params = array(), $loadHelpers = false) {
if(isset($params['plugin'])) { if (isset($params['plugin'])) {
$this->plugin = $params['plugin']; $this->plugin = $params['plugin'];
$this->pluginPath = 'plugins' . DS . $this->plugin . DS; $this->pluginPath = 'plugins' . DS . $this->plugin . DS;
$this->pluginPaths = array( $this->pluginPaths = array(
@ -383,28 +383,28 @@ class View extends Object {
$viewPaths = am($this->pluginPaths, $paths->viewPaths); $viewPaths = am($this->pluginPaths, $paths->viewPaths);
$file = null; $file = null;
foreach($viewPaths as $path) { foreach ($viewPaths as $path) {
if(file_exists($path . 'elements' . DS . $name . $this->ext)) { if (file_exists($path . 'elements' . DS . $name . $this->ext)) {
$file = $path . 'elements' . DS . $name . $this->ext; $file = $path . 'elements' . DS . $name . $this->ext;
break; break;
} else if(file_exists($path . 'elements' . DS . $name . '.thtml')) { } elseif (file_exists($path . 'elements' . DS . $name . '.thtml')) {
$file = $path . 'elements' . DS . $name . '.thtml'; $file = $path . 'elements' . DS . $name . '.thtml';
break; break;
} }
} }
if(!is_null($file)) { if (!is_null($file)) {
$params = array_merge_recursive($params, $this->loaded); $params = array_merge_recursive($params, $this->loaded);
return $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers); return $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers);
} }
if(!is_null($this->pluginPath)) { if (!is_null($this->pluginPath)) {
$file = APP . $this->pluginPath . 'views' . DS . 'elements' . DS . $name . $this->ext; $file = APP . $this->pluginPath . 'views' . DS . 'elements' . DS . $name . $this->ext;
} else { } else {
$file = VIEWS . 'elements' . DS . $name . $this->ext; $file = VIEWS . 'elements' . DS . $name . $this->ext;
} }
if(Configure::read() > 0) { if (Configure::read() > 0) {
return "Not Found: " . $file; return "Not Found: " . $file;
} }
} }
@ -418,19 +418,19 @@ class View extends Object {
* @access public * @access public
*/ */
function element($name, $params = array()) { function element($name, $params = array()) {
if(in_array('cache', array_keys($params))) { if (in_array('cache', array_keys($params))) {
$expires = '+1 day'; $expires = '+1 day';
if($params['cache'] !== true) { if ($params['cache'] !== true) {
$expires = $params['cache']; $expires = $params['cache'];
} }
if($expires) { if ($expires) {
$plugin = null; $plugin = null;
if(isset($params['plugin'])) { if (isset($params['plugin'])) {
$plugin = $params['plugin']; $plugin = $params['plugin'];
} }
$cacheFile = 'element_' . $plugin .'_' . convertSlash($name); $cacheFile = 'element_' . $plugin .'_' . convertSlash($name);
$cache = cache('views' . DS . $cacheFile, null, $expires); $cache = cache('views' . DS . $cacheFile, null, $expires);
if($cache) { if ($cache) {
return $cache; return $cache;
} else { } else {
$element = $this->renderElement($name, $params); $element = $this->renderElement($name, $params);
@ -585,7 +585,7 @@ class View extends Object {
return false; return false;
} }
foreach($data as $name => $value) { foreach ($data as $name => $value) {
if ($name == 'title') { if ($name == 'title') {
$this->pageTitle = $value; $this->pageTitle = $value;
} else { } else {
@ -646,20 +646,20 @@ class View extends Object {
$viewPaths = am($this->pluginPaths, $paths->viewPaths); $viewPaths = am($this->pluginPaths, $paths->viewPaths);
$name = $this->viewPath . DS . $this->subDir . $type . $action; $name = $this->viewPath . DS . $this->subDir . $type . $action;
foreach($viewPaths as $path) { foreach ($viewPaths as $path) {
if(file_exists($path . $name . $this->ext)) { if (file_exists($path . $name . $this->ext)) {
return $path . $name . $this->ext; return $path . $name . $this->ext;
} else if(file_exists($path . $name . '.thtml')) { } elseif (file_exists($path . $name . '.thtml')) {
return $path . $name . '.thtml'; return $path . $name . '.thtml';
} }
} }
if ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'errors' . DS . $type . $action . '.ctp')) { if ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'errors' . DS . $type . $action . '.ctp')) {
return $viewFileName; return $viewFileName;
} elseif($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $this->viewPath . DS . $type . $action . '.ctp')) { } elseif ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $this->viewPath . DS . $type . $action . '.ctp')) {
return $viewFileName; return $viewFileName;
} else { } else {
if(!is_null($this->pluginPath)) { if (!is_null($this->pluginPath)) {
$viewFileName = APP . $this->pluginPath . 'views' . DS . $name . $this->ext; $viewFileName = APP . $this->pluginPath . 'views' . DS . $name . $this->ext;
} else { } else {
$viewFileName = VIEWS . $name . $this->ext; $viewFileName = VIEWS . $name . $this->ext;
@ -682,7 +682,7 @@ class View extends Object {
$type = null; $type = null;
} }
if(!is_null($this->layoutPath)) { if (!is_null($this->layoutPath)) {
$type = $this->layoutPath . DS; $type = $this->layoutPath . DS;
} }
@ -690,15 +690,15 @@ class View extends Object {
$viewPaths = am($this->pluginPaths, $paths->viewPaths); $viewPaths = am($this->pluginPaths, $paths->viewPaths);
$name = $this->subDir . $type . $this->layout; $name = $this->subDir . $type . $this->layout;
foreach($viewPaths as $path) { foreach ($viewPaths as $path) {
if(file_exists($path . 'layouts' . DS . $name . $this->ext)) { if (file_exists($path . 'layouts' . DS . $name . $this->ext)) {
return $path . 'layouts' . DS . $name . $this->ext; return $path . 'layouts' . DS . $name . $this->ext;
} else if(file_exists($path . 'layouts' . DS . $name . '.thtml')) { } elseif (file_exists($path . 'layouts' . DS . $name . '.thtml')) {
return $path . 'layouts' . DS . $name . '.thtml'; return $path . 'layouts' . DS . $name . '.thtml';
} }
} }
if(!is_null($this->pluginPath)) { if (!is_null($this->pluginPath)) {
$layoutFileName = APP . $this->pluginPath . 'views' . DS . 'layouts' . DS . $name . $this->ext; $layoutFileName = APP . $this->pluginPath . 'views' . DS . 'layouts' . DS . $name . $this->ext;
} else { } else {
$layoutFileName = VIEWS . 'layouts' . DS . $name . $this->ext; $layoutFileName = VIEWS . 'layouts' . DS . $name . $this->ext;
@ -708,11 +708,11 @@ class View extends Object {
if (empty($default) && !empty($type)) { if (empty($default) && !empty($type)) {
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $type . 'default.ctp'); $default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $type . 'default.ctp');
} }
if(empty($default)) { if (empty($default)) {
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $this->layout . '.ctp'); $default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $this->layout . '.ctp');
} }
if(!empty($default)) { if (!empty($default)) {
return $default; return $default;
} }
return $layoutFileName; return $layoutFileName;
@ -732,7 +732,7 @@ class View extends Object {
$loadedHelpers = array(); $loadedHelpers = array();
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers); $loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
foreach(array_keys($loadedHelpers) as $helper) { foreach (array_keys($loadedHelpers) as $helper) {
$replace = strtolower(substr($helper, 0, 1)); $replace = strtolower(substr($helper, 0, 1));
$camelBackedHelper = preg_replace('/\\w/', $replace, $helper, 1); $camelBackedHelper = preg_replace('/\\w/', $replace, $helper, 1);
@ -740,7 +740,7 @@ class View extends Object {
if (is_array(${$camelBackedHelper}->helpers) && !empty(${$camelBackedHelper}->helpers)) { if (is_array(${$camelBackedHelper}->helpers) && !empty(${$camelBackedHelper}->helpers)) {
$subHelpers = ${$camelBackedHelper}->helpers; $subHelpers = ${$camelBackedHelper}->helpers;
foreach($subHelpers as $subHelper) { foreach ($subHelpers as $subHelper) {
${$camelBackedHelper}->{$subHelper} =& $loadedHelpers[$subHelper]; ${$camelBackedHelper}->{$subHelper} =& $loadedHelpers[$subHelper];
} }
} }
@ -814,10 +814,10 @@ class View extends Object {
function &_loadHelpers(&$loaded, $helpers) { function &_loadHelpers(&$loaded, $helpers) {
$helpers[] = 'Session'; $helpers[] = 'Session';
foreach($helpers as $helper) { foreach ($helpers as $helper) {
$parts = preg_split('/\/|\./', $helper); $parts = preg_split('/\/|\./', $helper);
if(count($parts) === 1) { if (count($parts) === 1) {
$plugin = $this->plugin; $plugin = $this->plugin;
} else { } else {
$plugin = Inflector::underscore($parts['0']); $plugin = Inflector::underscore($parts['0']);
@ -892,7 +892,7 @@ class View extends Object {
unset ($out); unset ($out);
return; return;
} else { } else {
if($this->layout === 'xml'){ if ($this->layout === 'xml'){
header('Content-type: text/xml'); header('Content-type: text/xml');
} }
$out = str_replace('<!--cachetime:'.$match['1'].'-->', '', $out); $out = str_replace('<!--cachetime:'.$match['1'].'-->', '', $out);
@ -915,7 +915,7 @@ class View extends Object {
$errorAction = 'missingView'; $errorAction = 'missingView';
} }
foreach(array($this->name, 'errors') as $viewDir) { foreach (array($this->name, 'errors') as $viewDir) {
$errorAction = Inflector::underscore($errorAction); $errorAction = Inflector::underscore($errorAction);
if (file_exists(VIEWS . $viewDir . DS . $errorAction . $this->ext)) { if (file_exists(VIEWS . $viewDir . DS . $errorAction . $this->ext)) {
$missingViewFileName = VIEWS . $viewDir . DS . $errorAction . $this->ext; $missingViewFileName = VIEWS . $viewDir . DS . $errorAction . $this->ext;

View file

@ -205,7 +205,7 @@ class XMLNode extends Object {
* @access public * @access public
*/ */
function &first() { function &first() {
if(isset($this->children[0])) { if (isset($this->children[0])) {
return $this->children[0]; return $this->children[0];
} else { } else {
return null; return null;
@ -218,7 +218,7 @@ class XMLNode extends Object {
* @access public * @access public
*/ */
function &last() { function &last() {
if(count($this->children) > 0) { if (count($this->children) > 0) {
return $this->children[count($this->children) - 1]; return $this->children[count($this->children) - 1];
} else { } else {
return null; return null;
@ -234,15 +234,15 @@ class XMLNode extends Object {
function &child($id) { function &child($id) {
$null = null; $null = null;
if(is_int($id)) { if (is_int($id)) {
if(isset($this->children[$id])) { if (isset($this->children[$id])) {
return $this->children[$id]; return $this->children[$id];
} else { } else {
return null; return null;
} }
} elseif(is_string($id)) { } elseif (is_string($id)) {
for($i = 0; $i < count($this->children); $i++) { for ($i = 0; $i < count($this->children); $i++) {
if($this->children[$i]->name == $id) { if ($this->children[$i]->name == $id) {
return $this->children[$i]; return $this->children[$i];
} }
} }
@ -261,8 +261,8 @@ class XMLNode extends Object {
function children($name) { function children($name) {
$nodes = array(); $nodes = array();
$count = count($this->children); $count = count($this->children);
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if($this->children[$i]->name == $name) { if ($this->children[$i]->name == $name) {
$nodes[] =& $this->children[$i]; $nodes[] =& $this->children[$i];
} }
} }
@ -318,7 +318,7 @@ class XMLNode extends Object {
* @access public * @access public
*/ */
function hasChildren() { function hasChildren() {
if(is_array($this->children) && count($this->children) > 0) { if (is_array($this->children) && count($this->children) > 0) {
return true; return true;
} }
return false; return false;
@ -331,36 +331,36 @@ class XMLNode extends Object {
*/ */
function toString() { function toString() {
$d = ''; $d = '';
if($this->name != '') { if ($this->name != '') {
$d .= '<' . $this->name; $d .= '<' . $this->name;
if(is_array($this->attributes) && count($this->attributes) > 0) { if (is_array($this->attributes) && count($this->attributes) > 0) {
foreach($this->attributes as $key => $val) { foreach ($this->attributes as $key => $val) {
$d .= " $key=\"$val\""; $d .= " $key=\"$val\"";
} }
} }
} }
if(!$this->hasChildren() && empty($this->value)) { if (!$this->hasChildren() && empty($this->value)) {
if($this->name != '') { if ($this->name != '') {
$d .= " />\n"; $d .= " />\n";
} }
} else { } else {
if($this->name != '') { if ($this->name != '') {
$d .= ">"; $d .= ">";
} }
if($this->hasChildren()) { if ($this->hasChildren()) {
if (is_string($this->value) || empty($this->value)) { if (is_string($this->value) || empty($this->value)) {
if (!empty($this->value)) { if (!empty($this->value)) {
$d .= $this->value; $d .= $this->value;
} }
$count = count($this->children); $count = count($this->children);
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$d .= $this->children[$i]->toString(); $d .= $this->children[$i]->toString();
} }
} elseif (is_array($this->value)) { } elseif (is_array($this->value)) {
$count = count($this->value); $count = count($this->value);
for($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$d .= $this->value[$i]; $d .= $this->value[$i];
if (isset($this->children[$i])) { if (isset($this->children[$i])) {
$d .= $this->children[$i]->toString(); $d .= $this->children[$i]->toString();
@ -379,7 +379,7 @@ class XMLNode extends Object {
$d .= $this->value; $d .= $this->value;
} }
if($this->name != '' && ($this->hasChildren() || !empty($this->value))) { if ($this->name != '' && ($this->hasChildren() || !empty($this->value))) {
$d .= "</" . $this->name . ">\n"; $d .= "</" . $this->name . ">\n";
} }
} }
@ -403,8 +403,8 @@ class XMLNode extends Object {
*/ */
function __killParent($recursive = true) { function __killParent($recursive = true) {
unset($this->__parent); unset($this->__parent);
if($recursive && $this->hasChildren()) { if ($recursive && $this->hasChildren()) {
for($i = 0; $i < count($this->children); $i++) { for ($i = 0; $i < count($this->children); $i++) {
$this->children[$i]->__killParent(true); $this->children[$i]->__killParent(true);
} }
} }
@ -485,7 +485,7 @@ class XML extends XMLNode {
$this->children = array(); $this->children = array();
if($input != null) { if ($input != null) {
$vars = null; $vars = null;
if (is_string($input)) { if (is_string($input)) {
$this->load($input); $this->load($input);
@ -529,12 +529,12 @@ class XML extends XMLNode {
if (is_string($in)) { if (is_string($in)) {
if(strstr($in, "<")) { if (strstr($in, "<")) {
// Input is raw xml data // Input is raw xml data
$this->__rawData = $in; $this->__rawData = $in;
} else { } else {
// Input is an xml file // Input is an xml file
if(strpos($in, '://') || file_exists($in)) { if (strpos($in, '://') || file_exists($in)) {
$this->__rawData = @file_get_contents($in); $this->__rawData = @file_get_contents($in);
if ($this->__rawData == null) { if ($this->__rawData == null) {
$this->error("XML file $in is empty or could not be read (possible permissions error)."); $this->error("XML file $in is empty or could not be read (possible permissions error).");
@ -572,10 +572,10 @@ class XML extends XMLNode {
$tmpXML = new XMLNode(); $tmpXML = new XMLNode();
$tmpXML->name = $data['tag']; $tmpXML->name = $data['tag'];
if(isset($data['value'])) { if (isset($data['value'])) {
$tmpXML->value = $data['value']; $tmpXML->value = $data['value'];
} }
if(isset($data['attributes'])) { if (isset($data['attributes'])) {
$tmpXML->attributes = $data['attributes']; $tmpXML->attributes = $data['attributes'];
} }
@ -593,10 +593,10 @@ class XML extends XMLNode {
$tmpXML = new XMLNode(); $tmpXML = new XMLNode();
$tmpXML->name = $data['tag']; $tmpXML->name = $data['tag'];
if(isset($data['value'])) { if (isset($data['value'])) {
$tmpXML->value = $data['value']; $tmpXML->value = $data['value'];
} }
if(isset($data['attributes'])) { if (isset($data['attributes'])) {
$tmpXML->attributes = $data['attributes']; $tmpXML->attributes = $data['attributes'];
} }
@ -653,7 +653,7 @@ class XML extends XMLNode {
* @access public * @access public
*/ */
function error($msg, $code = 0, $line = 0) { function error($msg, $code = 0, $line = 0) {
if(DEBUG) { if (DEBUG) {
echo $msg . " " . $code . " " . $line; echo $msg . " " . $code . " " . $line;
} }
} }

View file

@ -627,8 +627,8 @@ class DboSourceTest extends UnitTestCase {
$queryData = array(); $queryData = array();
foreach($this->model->Category2->__associations as $type) { foreach ($this->model->Category2->__associations as $type) {
foreach($this->model->Category2->{$type} as $assoc => $assocData) { foreach ($this->model->Category2->{$type} as $assoc => $assocData) {
$linkModel =& $this->model->Category2->{$assoc}; $linkModel =& $this->model->Category2->{$assoc};
$external = isset($assocData['external']); $external = isset($assocData['external']);
@ -1279,11 +1279,11 @@ class DboSourceTest extends UnitTestCase {
} }
function _buildRelatedModels(&$model) { function _buildRelatedModels(&$model) {
foreach($model->__associations as $type) { foreach ($model->__associations as $type) {
foreach($model->{$type} as $assoc => $assocData) { foreach ($model->{$type} as $assoc => $assocData) {
if (is_string($assocData)) { if (is_string($assocData)) {
$className = $assocData; $className = $assocData;
} else if (isset($assocData['className'])) { } elseif (isset($assocData['className'])) {
$className = $assocData['className']; $className = $assocData['className'];
} }
$model->$className = new $className(); $model->$className = new $className();

View file

@ -125,7 +125,7 @@ class CakeTestCase extends UnitTestCase {
$classRegistry =& ClassRegistry::getInstance(); $classRegistry =& ClassRegistry::getInstance();
$models = array(); $models = array();
foreach($classRegistry->__map as $key => $name) { foreach ($classRegistry->__map as $key => $name) {
$object =& $classRegistry->getObject(Inflector::camelize($key)); $object =& $classRegistry->getObject(Inflector::camelize($key));
if (is_subclass_of($object, 'Model') && ((is_array($params['fixturize']) && in_array($object->name, $params['fixturize'])) || $params['fixturize'] === true)) { if (is_subclass_of($object, 'Model') && ((is_array($params['fixturize']) && in_array($object->name, $params['fixturize'])) || $params['fixturize'] === true)) {
$models[$object->name] = array ( $models[$object->name] = array (
@ -143,7 +143,7 @@ class CakeTestCase extends UnitTestCase {
'drop' => array() 'drop' => array()
); );
foreach($models as $model) { foreach ($models as $model) {
$fixture =& new CakeTestFixture($this->db); $fixture =& new CakeTestFixture($this->db);
$fixture->name = $model['model'] . 'Test'; $fixture->name = $model['model'] . 'Test';
@ -167,19 +167,19 @@ class CakeTestCase extends UnitTestCase {
} }
} }
foreach($this->_queries['create'] as $query) { foreach ($this->_queries['create'] as $query) {
if (isset($query) && $query !== false) { if (isset($query) && $query !== false) {
$this->db->_execute($query); $this->db->_execute($query);
} }
} }
foreach($this->_queries['insert'] as $query) { foreach ($this->_queries['insert'] as $query) {
if (isset($query) && $query !== false) { if (isset($query) && $query !== false) {
$this->db->_execute($query); $this->db->_execute($query);
} }
} }
foreach($models as $model) { foreach ($models as $model) {
$object =& $classRegistry->getObject($model['key']); $object =& $classRegistry->getObject($model['key']);
if ($object !== false) { if ($object !== false) {
@ -198,7 +198,7 @@ class CakeTestCase extends UnitTestCase {
*/ */
function endController(&$controller, $params = array()) { function endController(&$controller, $params = array()) {
if (isset($this->db) && isset($this->_queries) && !empty($this->_queries) && !empty($this->_queries['drop'])) { if (isset($this->db) && isset($this->_queries) && !empty($this->_queries) && !empty($this->_queries['drop'])) {
foreach($this->_queries['drop'] as $query) { foreach ($this->_queries['drop'] as $query) {
if (isset($query) && $query !== false) { if (isset($query) && $query !== false) {
$this->db->_execute($query); $this->db->_execute($query);
} }
@ -258,7 +258,7 @@ class CakeTestCase extends UnitTestCase {
$result = array(); $result = array();
foreach($viewVars as $var) { foreach ($viewVars as $var) {
$result[$var] = $view->getVar($var); $result[$var] = $view->getVar($var);
} }
@ -276,7 +276,7 @@ class CakeTestCase extends UnitTestCase {
$classRegistry =& ClassRegistry::getInstance(); $classRegistry =& ClassRegistry::getInstance();
$keys = array_keys($classRegistry->__objects); $keys = array_keys($classRegistry->__objects);
foreach($keys as $key) { foreach ($keys as $key) {
$key = Inflector::camelize($key); $key = Inflector::camelize($key);
$classRegistry->removeObject($key); $classRegistry->removeObject($key);
} }
@ -310,11 +310,11 @@ class CakeTestCase extends UnitTestCase {
// Create records // Create records
if (isset($this->_fixtures) && isset($this->db) && !in_array(low($method), array('start', 'end'))) { if (isset($this->_fixtures) && isset($this->db) && !in_array(low($method), array('start', 'end'))) {
foreach($this->_fixtures as $fixture) { foreach ($this->_fixtures as $fixture) {
$inserts = $fixture->insert(); $inserts = $fixture->insert();
if (isset($inserts) && !empty($inserts)) { if (isset($inserts) && !empty($inserts)) {
foreach($inserts as $query) { foreach ($inserts as $query) {
if (isset($query) && $query !== false) { if (isset($query) && $query !== false) {
$this->db->_execute($query); $this->db->_execute($query);
} }
@ -334,7 +334,7 @@ class CakeTestCase extends UnitTestCase {
*/ */
function start() { function start() {
if (isset($this->_fixtures) && isset($this->db)) { if (isset($this->_fixtures) && isset($this->db)) {
foreach($this->_fixtures as $fixture) { foreach ($this->_fixtures as $fixture) {
$query = $fixture->create(); $query = $fixture->create();
if (isset($query) && $query !== false) { if (isset($query) && $query !== false) {
@ -350,7 +350,7 @@ class CakeTestCase extends UnitTestCase {
*/ */
function end() { function end() {
if (isset($this->_fixtures) && isset($this->db)) { if (isset($this->_fixtures) && isset($this->db)) {
foreach(array_reverse($this->_fixtures) as $fixture) { foreach (array_reverse($this->_fixtures) as $fixture) {
$query = $fixture->drop(); $query = $fixture->drop();
if (isset($query) && $query !== false) { if (isset($query) && $query !== false) {
@ -368,7 +368,7 @@ class CakeTestCase extends UnitTestCase {
*/ */
function after($method) { function after($method) {
if (isset($this->_fixtures) && isset($this->db) && !in_array(low($method), array('start', 'end'))) { if (isset($this->_fixtures) && isset($this->db) && !in_array(low($method), array('start', 'end'))) {
foreach($this->_fixtures as $fixture) { foreach ($this->_fixtures as $fixture) {
$query = $fixture->truncate(); $query = $fixture->truncate();
if (isset($query) && $query !== false) { if (isset($query) && $query !== false) {
@ -451,7 +451,7 @@ class CakeTestCase extends UnitTestCase {
$this->_fixtures = array(); $this->_fixtures = array();
foreach($this->fixtures as $index => $fixture) { foreach ($this->fixtures as $index => $fixture) {
$fixtureFile = null; $fixtureFile = null;
if (strpos($fixture, 'core.') === 0) { if (strpos($fixture, 'core.') === 0) {
@ -459,7 +459,7 @@ class CakeTestCase extends UnitTestCase {
$fixturePaths = array( $fixturePaths = array(
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'tests' . DS . 'fixtures' CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'tests' . DS . 'fixtures'
); );
} else if (strpos($fixture, 'app.') === 0) { } elseif (strpos($fixture, 'app.') === 0) {
$fixture = substr($fixture, strlen('app.')); $fixture = substr($fixture, strlen('app.'));
$fixturePaths = array( $fixturePaths = array(
APP . 'tests' . DS . 'fixtures' APP . 'tests' . DS . 'fixtures'
@ -471,7 +471,7 @@ class CakeTestCase extends UnitTestCase {
); );
} }
foreach($fixturePaths as $path) { foreach ($fixturePaths as $path) {
if (is_readable($path . DS . $fixture . '_fixture.php')) { if (is_readable($path . DS . $fixture . '_fixture.php')) {
$fixtureFile = $path . DS . $fixture . '_fixture.php'; $fixtureFile = $path . DS . $fixture . '_fixture.php';
break; break;

Some files were not shown because too many files have changed in this diff Show more