diff --git a/VERSION.txt b/VERSION.txt index 29516f467..df17f2142 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -6,4 +6,4 @@ // +---------------------------------------------------------------------------------------------------+ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// -0.10.8.1954 \ No newline at end of file +0.10.8.1986 \ No newline at end of file diff --git a/app/webroot/index.php b/app/webroot/index.php index 144db1955..340a1b106 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -28,28 +28,50 @@ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ - /** - * Get Cake's root directory + * These defines should only be edited if you have cake installed in + * a directory layout other than the way it is distributed. + * Each define has a commented line of code that explains what you would change. + * */ -if (!defined('DS')) -{ - define('DS', DIRECTORY_SEPARATOR); -} if (!defined('ROOT')) { - define('ROOT', dirname(dirname(dirname(__FILE__))).DS); + //define('ROOT', 'FULL PATH TO DIRECTORY WHERE APP DIRECTORY IS LOCATED DO NOT ADD A TRAILING DIRECTORY SEPARATOR'; + define('ROOT', dirname(dirname(dirname(__FILE__)))); } if (!defined('APP_DIR')) { + //define('APP_DIR', 'DIRECTORY NAME OF APPLICATION'; define ('APP_DIR', basename(dirname(dirname(__FILE__)))); } +/** + * This only needs to be changed if the cake installed libs are located + * outside of the distributed directory structure. + */ +if (!defined('CAKE_CORE_INCLUDE_PATH')) +{ + //define ('CAKE_CORE_INCLUDE_PATH', FULL PATH TO DIRECTORY WHERE CAKE CORE IS INSTALLED DO NOT ADD A TRAILING DIRECTORY SEPARATOR'; + define('CAKE_CORE_INCLUDE_PATH', ROOT); +} + +/////////////////////////////// +//DO NOT EDIT BELOW THIS LINE// +/////////////////////////////// +if (!defined('DS')) +{ + define('DS', DIRECTORY_SEPARATOR); +} + if (!defined('WEBROOT_DIR')) { define ('WEBROOT_DIR', basename(dirname(__FILE__))); } -require_once ROOT.'cake'.DS.'bootstrap.php'; + +ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.PATH_SEPARATOR.ROOT.DS.APP_DIR.DS); + + +require_once 'cake'.DS.'bootstrap.php'; ?> \ No newline at end of file diff --git a/cake/basics.php b/cake/basics.php index 0748db0a5..5b67fc019 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -247,15 +247,16 @@ function loadController ($name) { $controller_fn = CONTROLLERS.$name.'_controller.php'; } - elseif(file_exists(LIBS.'controller'.DS.$name.'_controller.php')) + elseif($controller_fn = fileExistsInPath(LIBS.'controller'.DS.$name.'_controller.php')) { - $controller_fn = LIBS.'controller'.DS.$name.'_controller.php'; + } else { - $controller_fn = false; + return false; } - return file_exists($controller_fn)? require_once($controller_fn): false; + require_once($controller_fn); + return true; } else { @@ -302,6 +303,10 @@ function loadPluginController ($plugin, $controller) return true; } } + else + { + return true; + } } /** @@ -915,4 +920,18 @@ function LogError ($message) CakeLog::write('error', str_replace($bad, $good, $message)); } +function fileExistsInPath ($file) +{ + $paths = explode(PATH_SEPARATOR, get_include_path()); + foreach ($paths as $path) + { + $fullPath = $path . DIRECTORY_SEPARATOR . $file; + if (file_exists($fullPath)) + { + return $fullPath; + } + } + return false; +} + ?> \ No newline at end of file diff --git a/cake/bootstrap.php b/cake/bootstrap.php index a7c86e1d1..c564d621a 100644 --- a/cake/bootstrap.php +++ b/cake/bootstrap.php @@ -33,9 +33,9 @@ /** * Configuration, directory layout and standard libraries */ -require_once ROOT.'cake'.DS.'basics.php'; -require_once ROOT.APP_DIR.DS.'config'.DS.'core.php'; -require_once ROOT.'cake'.DS.'config'.DS.'paths.php'; +require_once 'cake'.DS.'basics.php'; +require_once ROOT.DS.APP_DIR.DS.'config'.DS.'core.php'; +require_once 'cake'.DS.'config'.DS.'paths.php'; require_once LIBS.'object.php'; require_once LIBS.'session.php'; require_once LIBS.'security.php'; diff --git a/cake/config/paths.php b/cake/config/paths.php index fcd3cb372..8c5554a2e 100644 --- a/cake/config/paths.php +++ b/cake/config/paths.php @@ -36,65 +36,65 @@ */ if(!defined('ROOT')) { - define ('ROOT', '../'); + define ('ROOT', '../'); } if(!defined('WEBROOT_DIR')) { - define ('WEBROOT_DIR', 'webroot'); + define ('WEBROOT_DIR', 'webroot'); } /** * Path to the application's directory. */ -define ('CAKE', ROOT.'cake'.DS); +define ('CAKE', 'cake'.DS); /** * Path to the application's directory. */ -define ('APP', ROOT.APP_DIR.DS); +define ('APP', ROOT.DS.APP_DIR.DS); /** * Path to the application's models directory. */ -define ('MODELS', APP.'models'.DS); +define ('MODELS', APP.'models'.DS); /** * Path to the application's controllers directory. */ -define ('CONTROLLERS', APP.'controllers'.DS); +define ('CONTROLLERS', APP.'controllers'.DS); /** * Path to the application's controllers directory. */ -define ('COMPONENTS', CONTROLLERS.'components'.DS); +define ('COMPONENTS', CONTROLLERS.'components'.DS); /** * Path to the application's views directory. */ -define ('VIEWS', APP.'views'.DS); +define ('VIEWS', APP.'views'.DS); /** * Path to the application's helpers directory. */ -define ('HELPERS', VIEWS.'helpers'.DS); +define ('HELPERS', VIEWS.'helpers'.DS); /** * Path to the application's view's layouts directory. */ -define ('LAYOUTS', VIEWS.'layouts'.DS); +define ('LAYOUTS', VIEWS.'layouts'.DS); /** * Path to the application's view's elements directory. * It's supposed to hold pieces of PHP/HTML that are used on multiple pages * and are not linked to a particular layout (like polls, footers and so on). */ -define ('ELEMENTS', VIEWS.'elements'.DS); +define ('ELEMENTS', VIEWS.'elements'.DS); /** * Path to the configuration files directory. */ -define ('CONFIGS', APP.'config'.DS); +define ('CONFIGS', APP.'config'.DS); /** * Path to the libs directory. @@ -104,67 +104,67 @@ define ('INFLECTIONS', CAKE.'config'.DS.'inflections'.DS); /** * Path to the libs directory. */ -define ('LIBS', CAKE.'libs'.DS); +define ('LIBS', CAKE.'libs'.DS); /** * Path to the logs directory. */ -define ('LOGS', ROOT.'logs'.DS); +define ('LOGS', ROOT.DS.'logs'.DS); /** * Path to the modules directory. */ -define ('MODULES', ROOT.'modules'.DS); +define ('MODULES', ROOT.DS.'modules'.DS); /** * Path to the public directory. */ -define ('WWW_ROOT', APP.WEBROOT_DIR.DS); +define ('WWW_ROOT', APP.WEBROOT_DIR.DS); /** * Path to the public directory. */ -define ('CSS', WWW_ROOT.'css'.DS); +define ('CSS', WWW_ROOT.'css'.DS); /** * Path to the public directory. */ -define ('JS', WWW_ROOT.'js'.DS); +define ('JS', WWW_ROOT.'js'.DS); /** * Path to the scripts direcotry. */ -define('SCRIPTS', CAKE.'scripts'.DS); +define('SCRIPTS', CAKE.'scripts'.DS); /** * Path to the tests directory. */ -define ('TESTS', ROOT.'tests'.DS); +define ('TESTS', ROOT.DS.'tests'.DS); /** * Path to the controller test directory. */ -define ('CONTROLLER_TESTS',TESTS.APP_DIR.DS.'controllers'.DS); +define ('CONTROLLER_TESTS', TESTS.APP_DIR.DS.'controllers'.DS); /** * Path to the helpers test directory. */ -define ('HELPER_TESTS', TESTS.APP_DIR.DS.'helpers'.DS); +define ('HELPER_TESTS', TESTS.APP_DIR.DS.'helpers'.DS); /** * Path to the models' test directory. */ -define ('MODEL_TESTS', TESTS.APP_DIR.DS.'models'.DS); +define ('MODEL_TESTS', TESTS.APP_DIR.DS.'models'.DS); /** * Path to the lib test directory. */ -define ('LIB_TESTS', TESTS.'libs'.DS); +define ('LIB_TESTS', TESTS.'libs'.DS); /** * Path to the temporary files directory. */ -define ('TMP', ROOT.'tmp'.DS); +define ('TMP', APP.'tmp'.DS); /** * Path to the cache files directory. It can be shared between hosts in a multi-server setup. @@ -174,14 +174,14 @@ define('CACHE', TMP.'cache'.DS); /** * Path to the vendors directory. */ -define ('VENDORS', ROOT.'vendors'.DS); +define ('VENDORS', ROOT.DS.'vendors'.DS); /** * Path to the Pear directory * The purporse is to make it easy porting Pear libs into Cake * without setting the include_path PHP variable. */ -define ('PEAR', VENDORS.'Pear'.DS); +define ('PEAR', VENDORS.'Pear'.DS); /** * Full url prefix @@ -203,17 +203,17 @@ unset($httpHost); /** * Web path to the public images directory. */ -define ('IMAGES_URL', 'img/'); +define ('IMAGES_URL', 'img/'); /** * Web path to the CSS files directory. */ -define ('CSS_URL', 'css/'); +define ('CSS_URL', 'css/'); /** * Web path to the js files directory. */ -define ('JS_URL', 'js/'); +define ('JS_URL', 'js/'); ?> \ No newline at end of file diff --git a/cake/libs/controller/component.php b/cake/libs/controller/component.php index 400fe21e1..52b282ff8 100644 --- a/cake/libs/controller/component.php +++ b/cake/libs/controller/component.php @@ -99,9 +99,9 @@ class Component extends Object { $componentFn = COMPONENTS.$componentFn; } - else if(file_exists(LIBS.'controller'.DS.'components'.DS.$componentFn)) + else if($componentFn = fileExistsInPath(LIBS.'controller'.DS.'components'.DS.$componentFn)) { - $componentFn = LIBS.'controller'.DS.'components'.DS.$componentFn; + } $componentCn = $component.'Component'; diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index ceefa5f06..799e34a39 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -454,9 +454,9 @@ class Controller extends Object $ref = env('HTTP_REFERER'); $base = FULL_BASE_URL . $this->webroot; - if ($ref != null && defined(FULL_BASE_URL)) + if ($ref != null && (defined(FULL_BASE_URL) || FULL_BASE_URL)) { - if (strpos(env('HTTP_REFERER'), $base) == 0) + if (strpos($ref, $base) === 0) { return substr($ref, strlen($base) - 1); } @@ -594,7 +594,7 @@ class Controller extends Object $fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($alias.$niceName); $fieldNames[ $tabl['name'] ]['model'] = $fkNames[1]; $fieldNames[ $tabl['name'] ]['modelKey'] = $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']]; - $fieldNames[ $tabl['name'] ]['controller'] = Inflector::pluralize($this->{$model}->tableToModel[Inflector::pluralize($fkNames[0])]); + $fieldNames[ $tabl['name'] ]['controller'] = Inflector::pluralize($this->{$model}->tableToModel[$fkNames[0]]); $fieldNames[ $tabl['name'] ]['foreignKey'] = true; } else if( 'created' != $tabl['name'] && 'updated' != $tabl['name'] ) diff --git a/cake/libs/model/connection_manager.php b/cake/libs/model/connection_manager.php index 34a7a101a..b97f5266c 100644 --- a/cake/libs/model/connection_manager.php +++ b/cake/libs/model/connection_manager.php @@ -117,7 +117,7 @@ class ConnectionManager extends Object } $tail = 'dbo'.DS.$filename.'.php'; - if (file_exists(LIBS.'model'.DS.$tail)) + if (fileExistsInPath(LIBS.'model'.DS.$tail)) { require_once(LIBS.'model'.DS.$tail); } diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 9773793fa..a413ba6ea 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -395,14 +395,14 @@ class DboSource extends DataSource { if (true === $this->generateSelfAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null)) { - $linkedModels[] = $type.$assoc; + $linkedModels[] = $type.'/'.$assoc; } } else { if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null)) { - $linkedModels[] = $type.$assoc; + $linkedModels[] = $type.'/'.$assoc; } } } @@ -419,62 +419,15 @@ class DboSource extends DataSource { foreach($model->{$type} as $assoc => $assocData) { - if (!in_array($type.$assoc, $linkedModels)) + if (!in_array($type.'/'.$assoc, $linkedModels)) { $linkModel =& $model->{$assocData['className']}; - $this->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet); - - if ($model->recursive > 1 && $linkModel->recursive > 0) + $this->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive); + } else { + // Fetch recursively on belongsTo and hasOne + if ($model->recursive > 1) { - foreach($linkModel->__associations as $type1) - { - foreach($linkModel->{$type1} as $assoc1 => $assocData1) - { - $deepModel =& $linkModel->{$assocData1['className']}; - - if ($assoc1 != $model->name) - { - foreach ($resultSet as $i => $data) - { - if (isset($data[$linkModel->name])) - { - foreach ($resultSet[$i][$linkModel->name] as $value) - { - $datas[][$linkModel->name] = $value[$linkModel->primaryKey]; - $fetch = $this->queryDeepAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $array, true, $datas); - unset($datas); - - if (!empty($fetch[0])) - { - foreach ($fetch as $j => $row1) - { - if(!empty($row1)) - { - foreach ($resultSet as $valueResult => $endResult) - { - $count = 0; - foreach ($endResult[$linkModel->name] as $keyCheck) - { - foreach ($row1 as $mas) - { - if($keyCheck[$linkModel->primaryKey] == $mas[$deepModel->name][$assocData1['foreignKey']]) - { - $resultSet[$i][$linkModel->name][$count][$deepModel->name][] = $mas[$deepModel->name]; - } - } - $count++; - } - } - } - } - } - unset($fetch); - } - } - } - } - } - } + //$this->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1); } } } @@ -488,20 +441,6 @@ class DboSource extends DataSource return $resultSet; } - function queryDeepAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet) - { - $query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet); - if ($query) - { - foreach ($resultSet as $i => $row) - { - $q = $this->insertQueryData($query, $resultSet, $association, $assocData, $model, $linkModel, $i); - $fetch[] = $this->fetchAll($q); - } - return $fetch; - } - } - /** * Enter description here... * @@ -515,7 +454,7 @@ class DboSource extends DataSource * @param unknown_type $resultSet * @param integer $recursive Number of levels of association */ - function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet) + function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive) { $query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet); if ($query) @@ -527,21 +466,58 @@ class DboSource extends DataSource if (!empty($fetch) && is_array($fetch)) { - if (isset($fetch[0][$association])) + if ($recursive > 0) { - foreach ($fetch as $j => $row) + foreach($linkModel->__associations as $type1) { - $resultSet[$i][$association][$j] = $row[$association]; - } - } - else - { - $plural = Inflector::pluralize($association); - foreach ($fetch as $j => $row) - { - $resultSet[$i][$plural][$j] = $row[$plural]; + if ($recursive > 1) + { + foreach($linkModel->{$type1} as $assoc1 => $assocData1) + { + $deepModel =& $linkModel->{$assocData1['className']}; + if ($deepModel->name != $model->name) + { + $this->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1); + } + } + } } } + $this->__mergeAssociation($resultSet[$i], $fetch, $association, $type); + } + } + } + } + + function __mergeAssociation(&$data, $merge, $association, $type) + { + if (isset($merge[0]) && !isset($merge[0][$association])) + { + $association = Inflector::pluralize($association); + } + + if ($type == 'belongsTo' || $type == 'hasOne') + { + if (isset($merge[$association])) + { + $data[$association] = $merge[$association][0]; + } + else + { + $data[$association] = $merge[0][$association]; + } + } + else + { + foreach ($merge as $i => $row) + { + if (count($row) == 1) + { + $data[$association][] = $row[$association]; + } + else + { + $data[$association][] = $row; } } } @@ -726,11 +702,12 @@ class DboSource extends DataSource case 'belongsTo': if ($external) { - $conditions = $assocData['conditions']; $sql = 'SELECT * FROM '.$this->name($linkModel->table).' AS '.$this->name($alias); + $conditions = $assocData['conditions']; - $condition = $linkModel->escapeField($assocData['foreignKey']); + $condition = $linkModel->escapeField($linkModel->primaryKey); $condition .= '={$__cake_id__$}'; + if (is_array($conditions)) { $conditions[] = $condition; @@ -743,8 +720,11 @@ class DboSource extends DataSource } $conditions .= $condition; } - $sql .= $this->conditions($queryData['conditions']) . $this->order($queryData['order']); - $sql .= $this->limit($queryData['limit']); + $sql .= $this->conditions($conditions) . $this->order($assocData['order']); + if (isset($assocData['limit'])) + { + $sql .= $this->limit($assocData['limit']); + } return $sql; } else if($joinedOnSelf != true) @@ -995,7 +975,7 @@ class DboSource extends DataSource } $count = count($fields); - if ($count > 1 && $fields[0] != '*') + if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false) { for ($i = 0; $i < $count; $i++) { @@ -1041,27 +1021,27 @@ class DboSource extends DataSource $out = array(); foreach ($conditions as $key => $value) { - // Treat multiple values as an IN condition. - if (is_array($value)) - { - $data = $key . ' IN ('; - foreach ($value as $valElement) - { - $data .= $this->value($valElement) . ', '; - } - // Remove trailing ',' and complete clause. - $data[strlen($data)-2] = ')'; - } - else - { - if (($value != '{$__cake_id__$}') && ($value != '{$__cake_foreignKey__$}')) + if (is_array($value)) + { + $data = $key . ' IN ('; + foreach ($value as $valElement) + { + $data .= $this->value($valElement) . ', '; + } + $data[strlen($data)-2] = ')'; + } + elseif (preg_match('/(?PLIKE\\x20|=\\x20|>\\x20|<\\x20|<=\\x20|>=\\x20|<>\\x20)(?P.*)/i', $value, $match)) + { + $data = $this->name($key) . ' '.$match['expression'].' '. $this->value($match['value']); + } + else + { + if (($value != '{$__cake_id__$}') && ($value != '{$__cake_foreignKey__$}')) { $value = $this->value($value); } + $data = $this->name($key) . '='; - //$slashedValue = $this->value($value); - //TODO: Remove the = below so LIKE and other compares can be used - $data = $key . '='; if ($value === null) { $data .= 'null'; @@ -1070,7 +1050,7 @@ class DboSource extends DataSource { $data .= $value; } - } + } $out[] = $data; } return ' WHERE ' . join(' AND ', $out); @@ -1096,13 +1076,39 @@ class DboSource extends DataSource * @param string $dir Direction (ASC or DESC) * @return string ORDER BY clause */ - function order ($key, $dir = '') + function order ($keys, $dir = '') { - if (trim($key) == '') + if (empty($keys)) { return ''; } - return ' ORDER BY '.$key.' '.$dir; + + if(is_array($keys)) + { + foreach($keys as $key => $value) + { + if(is_numeric($key)) + { + $key = $value; + $value = null; + } + else + { + $value= ' '.$value; + } + $order[] = $this->name($key).$value; + } + return ' ORDER BY '.join(',', $order); + } + else + { + if (preg_match('/(?P\\x20ASC|\\x20DESC)/', $keys, $match)) + { + $dir = $match['direction']; + $keys = preg_replace('/'.$match['direction'].'/', '', $keys); + } + return ' ORDER BY '.$this->name($keys).$dir; + } } /** @@ -1116,7 +1122,6 @@ class DboSource extends DataSource { $this->showLog(); } - //$this->disconnect(); $this->_conn = NULL; $this->connected = false; } diff --git a/cake/libs/model/dbo/dbo_mysql.php b/cake/libs/model/dbo/dbo_mysql.php index 5dfcbc617..402709180 100644 --- a/cake/libs/model/dbo/dbo_mysql.php +++ b/cake/libs/model/dbo/dbo_mysql.php @@ -218,7 +218,7 @@ class DboMysql extends DboSource * @param string $tableName Name of database table to inspect * @return array Fields in table. Keys are name and type */ - function &describe (&$model) + function describe (&$model) { $cache = parent::describe($model); if ($cache != null) @@ -238,7 +238,7 @@ class DboMysql extends DboSource } if (isset($column[0])) { - $fields[] = array('name' => $column[0]['Field'], 'type' => $column[0]['Type']); + $fields[] = array('name' => $column[0]['Field'], 'type' => $column[0]['Type'], 'null' => $column[0]['Null']); } } $this->__cacheDescription($model->table, $fields); @@ -291,7 +291,14 @@ class DboMysql extends DboSource { $data = mysql_real_escape_string($data, $this->connection); } - $return = "'" . $data . "'"; + if(!is_numeric($data)) + { + $return = "'" . $data . "'"; + } + else + { + $return = $data; + } return $return; } diff --git a/cake/libs/model/dbo/dbo_postgres.php b/cake/libs/model/dbo/dbo_postgres.php index 7f23591e8..93c654656 100644 --- a/cake/libs/model/dbo/dbo_postgres.php +++ b/cake/libs/model/dbo/dbo_postgres.php @@ -45,7 +45,6 @@ uses('model'.DS.'datasources'.DS.'dbo_source'); class DboPostgres extends DboSource { - var $description = "PostgreSQL DBO Driver"; var $_baseConfig = array('persistent' => true, @@ -53,8 +52,7 @@ class DboPostgres extends DboSource 'login' => 'root', 'password' => '', 'database' => 'cake', - 'port' => 3306 - ); + 'port' => 3306); var $columns = array( 'primary_key' => array('name' => 'serial primary key'), @@ -67,10 +65,8 @@ class DboPostgres extends DboSource 'time' => array('name' => 'time'), 'date' => array('name' => 'date'), 'binary' => array('name' => 'bytea'), - 'boolean' => array('name' => 'boolean') - ); - - + 'boolean' => array('name' => 'boolean'), + 'number' => array('name' => 'numeric')); /** * Connects to the database using options in the given configuration array. @@ -119,10 +115,6 @@ class DboPostgres extends DboSource function query () { $args = func_get_args(); - echo "
";
-      print_r($args);
-      echo "
"; - die(); if (count($args) == 1) { return $this->fetchAll($args[0]); @@ -130,13 +122,13 @@ class DboPostgres extends DboSource elseif (count($args) > 1 && strpos($args[0], 'findBy') === 0) { $field = Inflector::underscore(str_replace('findBy', '', $args[0])); - $query = '`' . $args[2]->name . '`.`' . $field . '` = ' . $this->value($args[1][0]); + $query = '"' . $args[2]->name . '"."' . $field . '" = ' . $this->value($args[1][0]); return $args[2]->find($query); } elseif (count($args) > 1 && strpos($args[0], 'findAllBy') === 0) { $field = Inflector::underscore(str_replace('findAllBy', '', $args[0])); - $query = '`' . $args[2]->name . '`.`' . $field . '` = ' . $this->value($args[1][0]); + $query = '"' . $args[2]->name . '"."' . $field . '" = ' . $this->value($args[1][0]); return $args[2]->findAll($query); } } @@ -146,9 +138,10 @@ class DboPostgres extends DboSource * * @return array The fetched row as an array */ - function fetchRow () + function fetchRow ($assoc = false) { - return pg_fetch_array($this->_result); + $assoc = ($assoc === false) ? PGSQL_BOTH : PGSQL_ASSOC; + return pg_fetch_array($this->_result, null, $assoc); } /** @@ -158,29 +151,23 @@ class DboPostgres extends DboSource */ function listSources () { - $sql = "SELECT a.relname AS name - FROM pg_class a, pg_user b - WHERE ( relkind = 'r') and relname !~ '^pg_' AND relname !~ '^sql_' - AND relname !~ '^xin[vx][0-9]+' AND b.usesysid = a.relowner - AND NOT (EXISTS (SELECT viewname FROM pg_views WHERE viewname=a.relname));"; + $sql = "SELECT table_name as name FROM information_schema.tables WHERE table_schema = 'public';"; - $this->execute($sql); - $result = $this->fetchRow(); + $result = $this->query($sql); if (!$result) { return null; } - else - { - $tables = array(); - $tables[] = $result['name']; - while ($row = $this->fetchRow()) - { - $tables[] = $row['name']; - } - return $tables; - } + else + { + $tables = array(); + foreach ($result as $item) + { + $tables[] = $item['name']; + } + return $tables; + } } /** @@ -203,6 +190,28 @@ class DboPostgres extends DboSource return $fields; } + /** + * Returns an array of the fields in given table name. + * + * @param string $tableName Name of database table to inspect + * @return array Fields in table. Keys are name and type + */ + function &describe (&$model) + { + $cache = parent::describe($model); + if ($cache != null) + { + return $cache; + } + + $fields = false; + + $fields = $this->query("SELECT column_name as name, data_type as type FROM information_schema.columns WHERE table_name =".$this->name($model->table)); + + $this->__cacheDescription($model->table, $fields); + return $fields; + } + /** * Returns a quoted and escaped string of $data for use in an SQL statement. * diff --git a/cake/libs/model/model_php4.php b/cake/libs/model/model_php4.php index e05d8cb64..a7052294f 100644 --- a/cake/libs/model/model_php4.php +++ b/cake/libs/model/model_php4.php @@ -586,6 +586,23 @@ class Model extends Object return $this->_tableInfo; } +/** + * Returns an associative array of field names and column types. + * + * @return array + */ + function getColumnTypes () + { + $columns = $this->loadInfo(); + $columns = $columns->value; + + $cols = array(); + foreach($columns as $col) { + $cols[$col['name']] = $col['type']; + } + return $cols; + } + /** * Returns true if given field name exists in this Model's database table. * Starts by loading the metadata into the private property table_info if that is not already set. @@ -836,6 +853,7 @@ class Model extends Object if(!$this->id > 0 && isset($newID)) { + $this->__insertID = $newID; $this->id = $newID; } diff --git a/cake/libs/model/model_php5.php b/cake/libs/model/model_php5.php index 581f14cc3..2ab5703d4 100644 --- a/cake/libs/model/model_php5.php +++ b/cake/libs/model/model_php5.php @@ -583,6 +583,23 @@ class Model extends Object return $this->_tableInfo; } +/** + * Returns an associative array of field names and column types. + * + * @return array + */ + function getColumnTypes () + { + $columns = $this->loadInfo(); + $columns = $columns->value; + + $cols = array(); + foreach($columns as $col) { + $cols[$col['name']] = $col['type']; + } + return $cols; + } + /** * Returns true if this Model has given field in its database table. * @@ -832,6 +849,7 @@ class Model extends Object if(!$this->id > 0 && isset($newID)) { + $this->__insertID = $newID; $this->id = $newID; } diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index d8d97980b..098f8244a 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -80,7 +80,7 @@ class Helper extends Object function loadConfig() { - return $this->readConfigFile(CAKE.'config'.DS.'tags.ini.php'); + return $this->readConfigFile($config = fileExistsInPath(CAKE.'config'.DS.'tags.ini.php')); } /** diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index e0000029e..d66fd0400 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -85,8 +85,8 @@ class FormHelper extends Helper if( $error == $this->Html->tagIsInvalid( $this->Html->model, $this->Html->field) ) { return true; - } - else + } + else { return false; } @@ -137,7 +137,7 @@ class FormHelper extends Helper * @param string $errorMsg Text that will appear if an error has occurred. * @param int $size Size attribute for INPUT element * @param array $htmlOptions HTML options array. - * @return string The formatted INPUT element, with a label and wrapped in a div. + * @return string The formatted INPUT element, with a label and wrapped in a div. */ function generateInputDiv($tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null ) { @@ -214,7 +214,7 @@ class FormHelper extends Helper * @param array $htmlOptions HTML options array * @return string Date option wrapped in a div. */ - function generateDate($tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null, $selected ) + function generateDate($tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null, $selected=null ) { $htmlOptions['id'] = strtolower(str_replace('/', '_',$tagName));; $str = $this->Html->dateTimeOptionTag( $tagName, 'MDY' , 'NONE', $selected, $htmlOptions); diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index 228e1a955..028713465 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -290,7 +290,14 @@ class HtmlHelper extends Helper if ($this->tagIsInvalid($this->model, $this->field)) { - $htmlAttributes['class'] = 'form_error'; + if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") + { + $htmlAttributes['class'] .= ' form_error'; + } + else + { + $htmlAttributes['class'] = 'form_error'; + } } return $this->output(sprintf($this->tags['textarea'], $this->model,$this->field, @@ -450,9 +457,21 @@ class HtmlHelper extends Helper $htmlAttributes['type'] = 'text'; } + if (!isset($htmlAttributes['id'])) + { + $htmlAttributes['id'] = $this->model.Inflector::camelize($this->field); + } + if ($this->tagIsInvalid($this->model, $this->field)) { - $htmlAttributes['class'] = 'form_error'; + if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") + { + $htmlAttributes['class'] .= ' form_error'; + } + else + { + $htmlAttributes['class'] = 'form_error'; + } } return $this->output(sprintf($this->tags['input'], $this->model, $this->field, diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index e14bc748f..45a4b9ea2 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -281,7 +281,7 @@ class View extends Object return $this->pluginView($action, $layout); } - if (!is_file($viewFileName)) + if (!is_file($viewFileName) && !$viewFileName = fileExistsInPath($viewFileName)) { if (strtolower(get_class($this)) == 'template') { @@ -306,9 +306,8 @@ class View extends Object { $missingViewFileName = VIEWS.$viewDir.DS.$errorAction.$this->ext; } - elseif(file_exists(LIBS.'view'.DS.'templates'.DS.$viewDir.DS.$errorAction.'.thtml')) + elseif($missingViewFileName = fileExistsInPath(LIBS.'view'.DS.'templates'.DS.$viewDir.DS.$errorAction.'.thtml')) { - $missingViewFileName = LIBS.'view'.DS.'templates'.DS.$viewDir.DS.$errorAction.'.thtml'; } else { @@ -535,20 +534,19 @@ class View extends Object { $viewFileName = VIEWS.'errors'.DS.$this->subDir.$type.$action.$this->ext; } - elseif(file_exists(LIBS.'view'.DS.'templates'.DS.'errors'.DS.$type.$action.'.thtml')) + elseif($viewFileName = fileExistsInPath(LIBS.'view'.DS.'templates'.DS.'errors'.DS.$type.$action.'.thtml')) { - $viewFileName = LIBS.'view'.DS.'templates'.DS.'errors'.DS.$type.$action.'.thtml'; + } - elseif(file_exists(LIBS.'view'.DS.'templates'.DS.$this->viewPath.DS.$type.$action.'.thtml')) + elseif($viewFileName = fileExistsInPath(LIBS.'view'.DS.'templates'.DS.$this->viewPath.DS.$type.$action.'.thtml')) { - $viewFileName = LIBS.'view'.DS.'templates'.DS.$this->viewPath.DS.$type.$action.'.thtml'; + } $viewPath = explode(DS, $viewFileName); $i = array_search('..', $viewPath); unset($viewPath[$i-1]); unset($viewPath[$i]); - $return = '/'.implode('/', $viewPath); return $return; } @@ -585,9 +583,8 @@ class View extends Object { $layoutFileName = LAYOUTS.$this->subDir.$type."{$this->layout}$this->ext"; } - elseif(file_exists(LIBS.'view'.DS.'templates'.DS."layouts".DS.$type."{$this->layout}.thtml")) + elseif($layoutFileName = fileExistsInPath(LIBS.'view'.DS.'templates'.DS."layouts".DS.$type."{$this->layout}.thtml")) { - $layoutFileName = LIBS.'view'.DS.'templates'.DS."layouts".DS.$type."{$this->layout}.thtml"; } return $layoutFileName; } @@ -684,9 +681,9 @@ class View extends Object { $helperFn = HELPERS.$helperFn; } - else if(file_exists(LIBS.'view'.DS.'helpers'.DS.$helperFn)) + else if($helperFn = fileExistsInPath(LIBS.'view'.DS.'helpers'.DS.$helperFn)) { - $helperFn = LIBS.'view'.DS.'helpers'.DS.$helperFn; + } if (is_file($helperFn)) { diff --git a/index.php b/index.php index 07ae87a03..4f6410df3 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ /** * Requests collector. - * + * * This file collects requests if: * - no mod_rewrite is avilable or .htaccess files are not supported * - /public is not set as a web root. @@ -11,14 +11,14 @@ * PHP versions 4 and 5 * * CakePHP : Rapid Development Framework - * Copyright (c) 2006, Cake Software Foundation, Inc. + * Copyright (c) 2006, Cake Software Foundation, Inc. * 1785 E. Sahara Avenue, Suite 490-204 * Las Vegas, Nevada 89104 * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * - * @filesource + * @filesource * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project * @package cake @@ -36,16 +36,28 @@ define ('APP_DIR', 'app'); define ('DS', DIRECTORY_SEPARATOR); define ('ROOT', dirname(__FILE__).DS); -require_once ROOT.'cake'.DS.'basics.php'; -require_once ROOT.APP_DIR.DS.'config'.DS.'core.php'; -require_once ROOT.'cake'.DS.'config'.DS.'paths.php'; +/** + * This only needs to be changed if the cake installed libs are located + * outside of the distributed directory structure. + */ +if (!defined('CAKE_CORE_INCLUDE_PATH')) +{ + //define ('CAKE_CORE_INCLUDE_PATH', FULL PATH TO DIRECTORY WHERE CAKE CORE IS INSTALLED DO NOT ADD A TRAILING DIRECTORY SEPARATOR'; + define('CAKE_CORE_INCLUDE_PATH', ROOT); +} + +ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.PATH_SEPARATOR.ROOT.DS.APP_DIR.DS); + +require_once 'cake'.DS.'basics.php'; +require_once 'config'.DS.'core.php'; +require_once 'cake'.DS.'config'.DS.'paths.php'; $uri = setUri(); /** * As mod_rewrite (or .htaccess files) is not working, we need to take care - * of what would normally be rewritten, i.e. the static files in /public + * of what would normally be rewritten, i.e. the static files in app/webroot/ */ if ($uri === '/' || $uri === '/index.php') {