diff --git a/libs/bake.php b/libs/bake.php index 083a84486..40cc5bd39 100644 --- a/libs/bake.php +++ b/libs/bake.php @@ -203,7 +203,7 @@ class %sTest extends TestCase { * @uses Bake::actions Adds one action for each run. */ function newView ($controller, $name) { - $controller = Inflector::pluralize($controller); +// $controller = Inflector::pluralize($controller); $dir = Inflector::underscore($controller); $path = $dir.DS.strtolower($name).".thtml"; $this->createDir(VIEWS.$dir); @@ -227,7 +227,7 @@ class %sTest extends TestCase { * @uses Bake::actions Adds one action for each run. */ function newController ($name, $actions=array()) { - $name = Inflector::pluralize($name); +// $name = Inflector::pluralize($name); $this->makeController($name, $actions); $this->makeControllerTest($name); $this->makeHelper($name); diff --git a/libs/basics.php b/libs/basics.php index 21926ab8e..5931802b9 100644 --- a/libs/basics.php +++ b/libs/basics.php @@ -100,7 +100,11 @@ function listClasses($path) function config () { $args = func_get_args(); foreach ($args as $arg) { - if (file_exists(CONFIGS.$arg.'.php')) { + if (('database' == $arg) && file_exists(CONFIGS.$arg.'.php')) + { + include_once(CONFIGS.$arg.'.php'); + } + elseif (file_exists(CONFIGS.$arg.'.php')) { include (CONFIGS.$arg.'.php'); if (count($args) == 1) return true; } @@ -124,19 +128,20 @@ function config () { */ function uses () { - global $loaded; - - if (!is_array($loaded)) - $loaded = array(); - $args = func_get_args(); foreach ($args as $arg) { - if (0 == in_array($arg, $loaded)) - { - require_once(LIBS.strtolower($arg).'.php'); - $loaded[] = $arg; - } + require_once(LIBS.strtolower($arg).'.php'); + } +} + + +function vendor($name) +{ + $args = func_get_args(); + foreach ($args as $arg) + { + require_once(VENDORS.$arg.'.php'); } } diff --git a/libs/dbo.php b/libs/dbo.php index 4c5971ee4..68e0b44af 100644 --- a/libs/dbo.php +++ b/libs/dbo.php @@ -88,6 +88,14 @@ class DBO extends Object { */ var $connected=FALSE; +/** + * Connection configuration. + * + * @var array + * @access public + */ + var $config=FALSE; + /** * Enter description here... * @@ -186,50 +194,6 @@ class DBO extends Object { */ var $_queriesLogMax=200; - // specific for each database, implemented in db drivers - function connect ($config) { - die('Please implement DBO::connect() first.'); - } - - function disconnect () { - die('Please implement DBO::disconnect() first.'); - } - - function execute ($sql) { - die('Please implement DBO::execute() first.'); - } - - function fetchRow ($result) { - die('Please implement DBO::fetchRow() first.'); - } - - function tablesList() { - die('Please implement DBO::tables() first.'); - } - - function fields ($table_name) { - die('Please implement DBO::fields() first.'); - } - - function prepareField ($data) { - die('Please implement DBO::prepareField() first.'); - } - - function lastError ($result) { - die('Please implement DBO::lastError() first.'); - } - - function lastAffected () { - die('Please implement DBO::lastAffected() first.'); - } - - function lastNumRows ($result) { - die('Please implement DBO::lastNumRows() first.'); - } - - function lastInsertId () { - die('Please implement DBO::lastInsertId() first.'); - } /** * Constructor. Sets the level of debug for dbo (fullDebug or debug). diff --git a/libs/dbo_adodb.php b/libs/dbo/dbo_adodb.php similarity index 76% rename from libs/dbo_adodb.php rename to libs/dbo/dbo_adodb.php index c22c136a6..e96c31a7f 100644 --- a/libs/dbo_adodb.php +++ b/libs/dbo/dbo_adodb.php @@ -1,173 +1,205 @@ - + // -// + Copyright: (c) 2005, Cake Authors/Developers + // -// + Author(s): Michal Tatarynowicz aka Pies + // -// + Larry E. Masters aka PhpNut + // -// + Kamil Dzielinski aka Brego + // -// +------------------------------------------------------------------+ // -// + Licensed under The MIT License + // -// + Redistributions of files must retain the above copyright notice. + // -// + See: http://www.opensource.org/licenses/mit-license.php + // -////////////////////////////////////////////////////////////////////////// - -/** - * AdoDB layer for DBO. - * - * @filesource - * @author Cake Authors/Developers - * @copyright Copyright (c) 2005, Cake Authors/Developers - * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - * @version $Revision$ - * @modifiedby $LastChangedBy$ - * @lastmodified $Date$ - * @license http://www.opensource.org/licenses/mit-license.php The MIT License - */ - -/** - * Include AdoDB files. - */ -require_once(VENDORS.'adodb/adodb.inc.php'); - -/** - * AdoDB layer for DBO. - * - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - */ -class DBO_AdoDB extends DBO { - -/** - * Connects to the database using options in the given configuration array. - * - * @param array $config Configuration array for connecting - */ - function connect ($config) { - if($this->config = $config) { - if(isset($this->config['driver'])) { - $this->_adodb = NewADOConnection($this->config['driver']); - - $adodb =& $this->_adodb; - $this->connected = $adodb->Connect($this->config['host'],$this->config['login'],$this->config['password'],$this->config['database']); - } - } - - if(!$this->connected) - die('Could not connect to DB.'); - } - -/** - * Disconnects from database. - * - * @return boolean True if the database could be disconnected, else false - */ - function disconnect () { - return $this->_adodb->close(); - } - -/** - * Executes given SQL statement. - * - * @param string $sql SQL statement - * @return resource Result resource identifier - */ - function execute ($sql) { - return $this->_adodb->execute($sql); - } - -/** - * Returns a row from given resultset as an array . - * - * @param unknown_type $res Resultset - * @return array The fetched row as an array - */ - function fetchRow ($res) { - return $res->FetchRow(); - } - -/** - * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits. - * - * @return array Array of tablenames in the database - */ - function tablesList() { - $tables = $this->_adodb->MetaTables('TABLES'); - - if (!sizeof($tables)>0) { - trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE); - exit; - } - return $tables; - } - -/** - * Returns an array of the fields in given table name. - * - * @param string $table_name Name of database table to inspect - * @return array Fields in table. Keys are name and type - */ - function fields ($table_name) { - $data = $this->_adodb->MetaColumns($table_name); - $fields = false; - - foreach ($data as $item) - $fields[] = array('name'=>$item->name, 'type'=>$item->type); - - return $fields; - } - -/** - * Returns a quoted and escaped string of $data for use in an SQL statement. - * - * @param string $data String to be prepared for use in an SQL statement - * @return string Quoted and escaped - * - * :TODO: To be implemented. - */ - function prepareValue ($data) { die('Please implement DBO::prepare() first.'); } - -/** - * Returns a formatted error message from previous database operation. - * - * @return string Error message - */ - function lastError () { - return $this->_adodb->ErrorMsg(); - } - -/** - * Returns number of affected rows in previous database operation. If no previous operation exists, this returns false. - * - * @return int Number of affected rows - */ - function lastAffected () { - return $this->_adodb->Affected_Rows(); - } - -/** - * Returns number of rows in previous resultset. If no previous resultset exists, - * this returns false. - * - * @return int Number of rows - */ - function lastNumRows () { - return $this->_result? $this->_result->RecordCount(): false; - } - -/** - * Returns the ID generated from the previous INSERT operation. - * - * @return int - * - * :TODO: To be implemented. - */ - function lastInsertId () { die('Please implement DBO::lastInsertId() first.'); } -} - + + // +// + Copyright: (c) 2005, Cake Authors/Developers + // +// + Author(s): Michal Tatarynowicz aka Pies + // +// + Larry E. Masters aka PhpNut + // +// + Kamil Dzielinski aka Brego + // +// +------------------------------------------------------------------+ // +// + Licensed under The MIT License + // +// + Redistributions of files must retain the above copyright notice. + // +// + See: http://www.opensource.org/licenses/mit-license.php + // +////////////////////////////////////////////////////////////////////////// + +/** + * AdoDB layer for DBO. + * + * @filesource + * @author Cake Authors/Developers + * @copyright Copyright (c) 2005, Cake Authors/Developers + * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * Include AdoDB files. + */ +require_once(VENDORS.'adodb/adodb.inc.php'); + +/** + * AdoDB layer for DBO. + * + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + */ +class DBO_AdoDB extends DBO +{ + + /** + * ADOConnection object with which we connect. + * + * @var ADOConnection The connection object. + */ + var $_adodb = null; + +/** + * Connects to the database using options in the given configuration array. + * + * @param array $config Configuration array for connecting + */ + function connect ($config) + { + $this->config = $config; + + $this->_adodb = NewADOConnection($config['driver']); + $adodb =& $this->_adodb; + $this->connected = $adodb->Connect($config['host'], $config['login'], $config['password'], $config['database']); + + if(!$this->connected) + die('Could not connect to DB.'); + } + +/** + * Disconnects from database. + * + * @return boolean True if the database could be disconnected, else false + */ + function disconnect () + { + return $this->_adodb->close(); + } + +/** + * Executes given SQL statement. + * + * @param string $sql SQL statement + * @return resource Result resource identifier + */ + function execute ($sql) + { + return $this->_adodb->execute($sql); + } + +/** + * Returns a row from given resultset as an array . + * + * @param unknown_type $res Resultset + * @return array The fetched row as an array + */ + function fetchRow ($res) + { + return $res->FetchRow(); + } + +/** + * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits. + * + * @return array Array of tablenames in the database + */ + function tablesList() + { + $tables = $this->_adodb->MetaTables('TABLES'); + + if (!sizeof($tables)>0) { + trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE); + exit; + } + return $tables; + } + +/** + * Returns an array of the fields in given table name. + * + * @param string $table_name Name of database table to inspect + * @return array Fields in table. Keys are name and type + */ + function fields ($table_name) + { + $data = $this->_adodb->MetaColumns($table_name); + $fields = false; + + foreach ($data as $item) + $fields[] = array('name'=>$item->name, 'type'=>$item->type); + + return $fields; + } + +/** + * Returns a quoted and escaped string of $data for use in an SQL statement. + * + * @param string $data String to be prepared for use in an SQL statement + * @return string Quoted and escaped + * + * :TODO: To be implemented. + */ + function prepareValue ($data) + { + return $this->_adodb->Quote($data); + } + + + /** + * Returns a limit statement in the correct format for the particular database. + * + * @param int $limit Limit of results returned + * @param int $offset Offset from which to start results + * @return string SQL limit/offset statement + */ + function selectLimit ($limit, $offset=null) + { + return "LIMIT {$limit}".($offset? "{$offset}": null); + // please change to whatever select your database accepts + // adodb doesn't allow us to get the correct limit string out of it + } + +/** + * Returns a formatted error message from previous database operation. + * + * @return string Error message + */ + function lastError () + { + return $this->_adodb->ErrorMsg(); + } + +/** + * Returns number of affected rows in previous database operation. If no previous operation exists, this returns false. + * + * @return int Number of affected rows + */ + function lastAffected () + { + return $this->_adodb->Affected_Rows(); + } + +/** + * Returns number of rows in previous resultset. If no previous resultset exists, + * this returns false. + * + * @return int Number of rows + */ + function lastNumRows () + { + return $this->_result? $this->_result->RecordCount(): false; + } + +/** + * Returns the ID generated from the previous INSERT operation. + * + * @return int + * + * :TODO: To be implemented. + */ + function lastInsertId () { die('Please implement DBO::lastInsertId() first.'); } +} + ?> \ No newline at end of file diff --git a/libs/dbo/dbo_generic.php b/libs/dbo/dbo_generic.php new file mode 100644 index 000000000..fb2920d41 --- /dev/null +++ b/libs/dbo/dbo_generic.php @@ -0,0 +1,85 @@ + + // +// + Copyright: (c) 2005, Cake Authors/Developers + // +// + Author(s): Michal Tatarynowicz aka Pies + // +// + Larry E. Masters aka PhpNut + // +// + Kamil Dzielinski aka Brego + // +// +------------------------------------------------------------------+ // +// + Licensed under The MIT License + // +// + Redistributions of files must retain the above copyright notice. + // +// + See: http://www.opensource.org/licenses/mit-license.php + // +////////////////////////////////////////////////////////////////////////// + +/** + * Generic layer for DBO. + * + * @filesource + * @author Cake Authors/Developers + * @copyright Copyright (c) 2005, Cake Authors/Developers + * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +class DBO_generic extends DBO +{ + + function connect ($config) + { + } + + function disconnect () + { + } + + function execute ($sql) + { + } + + function fetchRow ($result) + { + } + + function tablesList() + { + } + + function fields ($table_name) + { + } + + function prepareValue ($data) + { + } + + function lastError ($result) + { + } + + function lastAffected () + { + } + + function lastNumRows ($result) + { + } + + function lastInsertId () + { + } + + function selectLimit ($limit, $offset) + { + } + +} + +?> \ No newline at end of file diff --git a/libs/dbo_mysql.php b/libs/dbo/dbo_mysql.php similarity index 93% rename from libs/dbo_mysql.php rename to libs/dbo/dbo_mysql.php index 63f3be1fb..e666c681e 100644 --- a/libs/dbo_mysql.php +++ b/libs/dbo/dbo_mysql.php @@ -1,186 +1,199 @@ - + // -// + Copyright: (c) 2005 Cake Authors/Developers + // -// + + // -// + Author(s): Michal Tatarynowicz aka Pies + // -// + Larry E. Masters aka PhpNut + // -// + Kamil Dzielinski aka Brego + // -// + + // -// +------------------------------------------------------------------+ // -// + Licensed under The MIT License + // -// + Redistributions of files must retain the above copyright notice. + // -// + You may not use this file except in compliance with the License. + // -// + + // -// + You may obtain a copy of the License at: + // -// + License page: http://www.opensource.org/licenses/mit-license.php + // -// +------------------------------------------------------------------+ // -////////////////////////////////////////////////////////////////////////// - -/** - * MySQL layer for DBO - * - * @filesource - * @author Cake Authors/Developers - * @copyright Copyright (c) 2005, Cake Authors/Developers - * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - * @version $Revision$ - * @modifiedby $LastChangedBy$ - * @lastmodified $Date$ - * @license http://www.opensource.org/licenses/mit-license.php The MIT License - */ - -/** - * Include DBO. - */ - -uses('dbo'); -/** - * MySQL layer for DBO. - * - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - */ -class DBO_MySQL extends DBO { - -/** - * Connects to the database using options in the given configuration array. - * - * @param array $config Configuration array for connecting - * @return boolean True if the database could be connected, else false - */ - function connect ($config) { - if($config) { - $this->config = $config; - $this->_conn = mysql_pconnect($config['host'],$config['login'],$config['password']); - } - $this->connected = $this->_conn? true: false; - - if($this->connected) - Return mysql_select_db($config['database'], $this->_conn); - else - die('Could not connect to DB.'); - } - -/** - * Disconnects from database. - * - * @return boolean True if the database could be disconnected, else false - */ - function disconnect () { - return mysql_close(); - } - -/** - * Executes given SQL statement. - * - * @param string $sql SQL statement - * @return resource MySQL result resource identifier - */ - function execute ($sql) { - return mysql_query($sql); - } - -/** - * Returns a row from given resultset as an array . - * - * @param unknown_type $res Resultset - * @return array The fetched row as an array - */ - function fetchRow ($res, $assoc=false) { - return mysql_fetch_array($res, $assoc? MYSQL_ASSOC: MYSQL_BOTH); - } - -/** - * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits. - * - * @return array Array of tablenames in the database - */ - function tablesList () { - $result = mysql_list_tables($this->config['database']); - - if (!$result) { - trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE); - exit; - } - else { - $tables = array(); - while ($line = mysql_fetch_array($result)) { - $tables[] = $line[0]; - } - return $tables; - } - } - -/** - * Returns an array of the fields in given table name. - * - * @param string $table_name Name of database table to inspect - * @return array Fields in table. Keys are name and type - */ - function fields ($table_name) { - $data = $this->all("DESC {$table_name}"); - $fields = false; - - foreach ($data as $item) - $fields[] = array('name'=>$item['Field'], 'type'=>$item['Type']); - - return $fields; - } - -/** - * Returns a quoted and escaped string of $data for use in an SQL statement. - * - * @param string $data String to be prepared for use in an SQL statement - * @return string Quoted and escaped - */ - function prepareValue ($data) { - return "'".mysql_real_escape_string($data)."'"; - } - -/** - * Returns a formatted error message from previous database operation. - * - * @return string Error message with error number - */ - function lastError () { - return mysql_errno()? mysql_errno().': '.mysql_error(): null; - } - -/** - * Returns number of affected rows in previous database operation. If no previous operation exists, this returns false. - * - * @return int Number of affected rows - */ - function lastAffected () { - return $this->_result? mysql_affected_rows(): false; - } - -/** - * Returns number of rows in previous resultset. If no previous resultset exists, - * this returns false. - * - * @return int Number of rows - */ - function lastNumRows () { - return $this->_result? @mysql_num_rows($this->_result): false; - } - -/** - * Returns the ID generated from the previous INSERT operation. - * - * @return int - */ - function lastInsertId() { - return mysql_insert_id(); - } - -} - + + // +// + Copyright: (c) 2005 Cake Authors/Developers + // +// + + // +// + Author(s): Michal Tatarynowicz aka Pies + // +// + Larry E. Masters aka PhpNut + // +// + Kamil Dzielinski aka Brego + // +// + + // +// +------------------------------------------------------------------+ // +// + Licensed under The MIT License + // +// + Redistributions of files must retain the above copyright notice. + // +// + You may not use this file except in compliance with the License. + // +// + + // +// + You may obtain a copy of the License at: + // +// + License page: http://www.opensource.org/licenses/mit-license.php + // +// +------------------------------------------------------------------+ // +////////////////////////////////////////////////////////////////////////// + +/** + * MySQL layer for DBO + * + * @filesource + * @author Cake Authors/Developers + * @copyright Copyright (c) 2005, Cake Authors/Developers + * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * Include DBO. + */ + +uses('dbo'); +/** + * MySQL layer for DBO. + * + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + */ +class DBO_MySQL extends DBO { + +/** + * Connects to the database using options in the given configuration array. + * + * @param array $config Configuration array for connecting + * @return boolean True if the database could be connected, else false + */ + function connect ($config) { + if($config) { + $this->config = $config; + $this->_conn = mysql_pconnect($config['host'],$config['login'],$config['password']); + } + $this->connected = $this->_conn? true: false; + + if($this->connected) + Return mysql_select_db($config['database'], $this->_conn); + else + die('Could not connect to DB.'); + } + +/** + * Disconnects from database. + * + * @return boolean True if the database could be disconnected, else false + */ + function disconnect () { + return mysql_close(); + } + +/** + * Executes given SQL statement. + * + * @param string $sql SQL statement + * @return resource MySQL result resource identifier + */ + function execute ($sql) { + return mysql_query($sql); + } + +/** + * Returns a row from given resultset as an array . + * + * @param unknown_type $res Resultset + * @return array The fetched row as an array + */ + function fetchRow ($res, $assoc=false) { + return mysql_fetch_array($res, $assoc? MYSQL_ASSOC: MYSQL_BOTH); + } + +/** + * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits. + * + * @return array Array of tablenames in the database + */ + function tablesList () { + $result = mysql_list_tables($this->config['database']); + + if (!$result) { + trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE); + exit; + } + else { + $tables = array(); + while ($line = mysql_fetch_array($result)) { + $tables[] = $line[0]; + } + return $tables; + } + } + +/** + * Returns an array of the fields in given table name. + * + * @param string $table_name Name of database table to inspect + * @return array Fields in table. Keys are name and type + */ + function fields ($table_name) { + $data = $this->all("DESC {$table_name}"); + $fields = false; + + foreach ($data as $item) + $fields[] = array('name'=>$item['Field'], 'type'=>$item['Type']); + + return $fields; + } + +/** + * Returns a quoted and escaped string of $data for use in an SQL statement. + * + * @param string $data String to be prepared for use in an SQL statement + * @return string Quoted and escaped + */ + function prepareValue ($data) { + return "'".mysql_real_escape_string($data)."'"; + } + + + /** + * Returns a limit statement in the correct format for the particular database. + * + * @param int $limit Limit of results returned + * @param int $offset Offset from which to start results + * @return string SQL limit/offset statement + */ + function selectLimit ($limit, $offset=null) + { + return "LIMIT {$limit}".($offset? "{$offset}": null); + } + +/** + * Returns a formatted error message from previous database operation. + * + * @return string Error message with error number + */ + function lastError () { + return mysql_errno()? mysql_errno().': '.mysql_error(): null; + } + +/** + * Returns number of affected rows in previous database operation. If no previous operation exists, this returns false. + * + * @return int Number of affected rows + */ + function lastAffected () { + return $this->_result? mysql_affected_rows(): false; + } + +/** + * Returns number of rows in previous resultset. If no previous resultset exists, + * this returns false. + * + * @return int Number of rows + */ + function lastNumRows () { + return $this->_result? @mysql_num_rows($this->_result): false; + } + +/** + * Returns the ID generated from the previous INSERT operation. + * + * @return int + */ + function lastInsertId() { + return mysql_insert_id(); + } + +} + ?> \ No newline at end of file diff --git a/libs/dbo_pear.php b/libs/dbo/dbo_pear.php similarity index 61% rename from libs/dbo_pear.php rename to libs/dbo/dbo_pear.php index 08add7a81..2d56e126d 100644 --- a/libs/dbo_pear.php +++ b/libs/dbo/dbo_pear.php @@ -3,20 +3,14 @@ // + $Id$ // +------------------------------------------------------------------+ // // + Cake + // -// + Copyright: (c) 2005 Cake Authors/Developers + // -// + + // +// + Copyright: (c) 2005, Cake Authors/Developers + // // + Author(s): Michal Tatarynowicz aka Pies + // // + Larry E. Masters aka PhpNut + // // + Kamil Dzielinski aka Brego + // -// + + // // +------------------------------------------------------------------+ // // + Licensed under The MIT License + // // + Redistributions of files must retain the above copyright notice. + // -// + You may not use this file except in compliance with the License. + // -// + + // -// + You may obtain a copy of the License at: + // -// + License page: http://www.opensource.org/licenses/mit-license.php + // -// +------------------------------------------------------------------+ // +// + See: http://www.opensource.org/licenses/mit-license.php + // ////////////////////////////////////////////////////////////////////////// /** @@ -36,9 +30,12 @@ */ /** - * Include DBO. + * Include required libraries. */ uses('dbo'); +ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . PEAR); +vendor('Pear/DB'); + /** * Pear::DB layer for DBO. @@ -47,7 +44,15 @@ uses('dbo'); * @subpackage cake.libs * @since Cake v 0.2.9 */ -class DBO_Pear extends DBO { +class DBO_Pear extends DBO +{ + + /** + * PEAR::DB object with which we connect. + * + * @var DB The connection object. + */ + var $_pear = null; /** * Connects to the database using options in the given configuration array. @@ -55,8 +60,22 @@ class DBO_Pear extends DBO { * @param array $config Configuration array for connecting * @return unknown */ - function connect ($config) { - die('Please implement DBO::connect() first.'); + function connect ($config) + { + $this->config = $config; + + $dsn = $config['driver'].'://'.$config['login'].':'.$config['password'].'@'.$config['host'].'/'.$config['database']; + $options = array( + 'debug' => DEBUG-1, + 'portability' => DB_PORTABILITY_ALL, + ); + + $this->_pear =& DB::connect($dsn, $options); + + if (PEAR::isError($this->_pear)) + { + die('Could not connect to the database.'); + } } /** @@ -64,7 +83,8 @@ class DBO_Pear extends DBO { * * @return boolean True if the database could be disconnected, else false */ - function disconnect () { + function disconnect () + { die('Please implement DBO::disconnect() first.'); } @@ -74,7 +94,8 @@ class DBO_Pear extends DBO { * @param string $sql SQL statement * @return resource Result resource identifier */ - function execute ($sql) { + function execute ($sql) + { return $this->_pear->query($sql); } @@ -84,31 +105,59 @@ class DBO_Pear extends DBO { * @param unknown_type $res Resultset * @return array The fetched row as an array */ - function fetchRow ($result) { + function fetchRow ($result) + { return $result->fetchRow(DB_FETCHMODE_ASSOC); } /** * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits. + * :WARNING: :TODO: POSTGRESQL & MYSQL ONLY! Pear::DB doesn't support universal table listing. * * @return array Array of tablenames in the database */ - function tablesList () { // POSTGRESQL ONLY! PEAR:DB DOESN'T SUPPORT LISTING TABLES - $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));"; + function tablesList () + { + $driver = $this->config['driver']; + $tables = array(); + + if ('postgres' == $driver) + { + $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));"; - $result = $this->all($sql); + $result = $this->all($sql); + foreach ($result as $item) + { + $tables[] = $item['name']; + } + } + elseif ('mysql' == $driver) + { + $result = array(); - if (!$result) { + $result = mysql_list_tables($this->config['database']); + while ($item = mysql_fetch_array($result)) + { + $tables[] = $item[0]; + } + } + else + { + die('Please implement DBO_Pear::tablesList() for your database driver.'); + } + + + if (!$result) + { trigger_error(ERROR_NO_TABLE_LIST, E_USER_ERROR); exit; } - else { - $tables = array(); - foreach ($result as $item) $tables[] = $item['name']; + else + { return $tables; } } @@ -119,7 +168,8 @@ class DBO_Pear extends DBO { * @param string $table_name Name of database table to inspect * @return array Fields in table. Keys are name and type */ - function fields ($table_name) { + function fields ($table_name) + { $data = $this->_pear->tableInfo($table_name); $fields = false; @@ -135,16 +185,31 @@ class DBO_Pear extends DBO { * @param string $data String to be prepared for use in an SQL statement * @return string Quoted and escaped */ - function prepareValue ($data) { + function prepareValue ($data) + { return $this->_pear->quoteSmart($data); } + + /** + * Returns a limit statement in the correct format for the particular database. + * + * @param int $limit Limit of results returned + * @param int $offset Offset from which to start results + * @return string SQL limit/offset statement + */ + function selectLimit ($limit, $offset='0') + { + return $this->_pear->modifyLimitQuery('', $offset, $limit); + } + /** * Returns a formatted error message from previous database operation. * * @return string Error message */ - function lastError ($result=null) { + function lastError ($result=null) + { if (!$result) $result = $this->_result; return PEAR::isError($result)? $result->getMessage(): null; @@ -155,7 +220,8 @@ class DBO_Pear extends DBO { * * @return int Number of affected rows */ - function lastAffected () { + function lastAffected () + { return $this->_pear->affectedRows(); } @@ -165,7 +231,8 @@ class DBO_Pear extends DBO { * * @return int Number of rows */ - function lastNumRows ($result) { + function lastNumRows ($result) + { if (method_exists($result, 'numRows')) return $result->numRows(); else @@ -178,11 +245,11 @@ class DBO_Pear extends DBO { * @param string $table Name of the database table * @return int */ - function lastInsertId ($table) { + function lastInsertId ($table) + { return $this->field('id', "SELECT MAX(id) FROM {$table}"); } - } ?> \ No newline at end of file diff --git a/libs/dbo_postgres.php b/libs/dbo/dbo_postgres.php similarity index 93% rename from libs/dbo_postgres.php rename to libs/dbo/dbo_postgres.php index 10481aa3e..2e2a4beef 100644 --- a/libs/dbo_postgres.php +++ b/libs/dbo/dbo_postgres.php @@ -1,192 +1,205 @@ - + // -// + Copyright: (c) 2005, Cake Authors/Developers + // -// + Author(s): Michal Tatarynowicz aka Pies + // -// + Larry E. Masters aka PhpNut + // -// + Kamil Dzielinski aka Brego + // -// +------------------------------------------------------------------+ // -// + Licensed under The MIT License + // -// + Redistributions of files must retain the above copyright notice. + // -// + See: http://www.opensource.org/licenses/mit-license.php + // -////////////////////////////////////////////////////////////////////////// - -/** - * PostgreSQL layer for DBO. - * - * @filesource - * @author Cake Authors/Developers - * @copyright Copyright (c) 2005, Cake Authors/Developers - * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers - * @package cake - * @subpackage cake.libs - * @since Cake v 1.0.0.114 - * @version $Revision$ - * @modifiedby $LastChangedBy$ - * @lastmodified $Date$ - * @license http://www.opensource.org/licenses/mit-license.php The MIT License - */ - -/** - * Include DBO. - */ -uses('dbo'); - -/** - * PostgreSQL layer for DBO. - * - * @package cake - * @subpackage cake.libs - * @since Cake v 1.0.0.114 - */ -class DBO_Postgres extends DBO { - -/** - * Connects to the database using options in the given configuration array. - * - * @param array $config Configuration array for connecting - * @return True if successfully connected. - */ - function connect ($config) { - if($config) { - $this->config = $config; - $this->_conn = pg_pconnect("host={$config['host']} dbname={$config['database']} user={$config['login']} password={$config['password']}"); - } - $this->connected = $this->_conn? true: false; - - if($this->connected) - return true; - else - die('Could not connect to DB.'); - - } - -/** - * Disconnects from database. - * - * @return boolean True if the database could be disconnected, else false - */ - function disconnect () { - return pg_close($this->_conn); - } - -/** - * Executes given SQL statement. - * - * @param string $sql SQL statement - * @return resource Result resource identifier - */ - function execute ($sql) { - return pg_query($this->_conn, $sql); - } - -/** - * Returns a row from given resultset. - * - * @param unknown_type $res - * @return unknown - */ - function fetchRow ($res) { - return pg_fetch_array($res); - } - -/** - * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits. - * - * @return array Array of tablenames in the database - */ - function tablesList () { - $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));"; - - $result = $this->all($sql); - - if (!$result) { - trigger_error(ERROR_NO_TABLE_LIST, E_USER_ERROR); - exit; - } - else { - $tables = array(); - foreach ($result as $item) $tables[] = $item['name']; - return $tables; - } - } - -/** - * Returns an array of the fields in given table name. - * - * @param string $table_name Name of database table to inspect - * @return array Fields in table. Keys are name and type - */ - function fields ($table_name) { - $sql = "SELECT c.relname, a.attname, t.typname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '{$table_name}' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid"; - - $fields = false; - foreach ($this->all($sql) as $field) { - $fields[] = array( - 'name' => $field['attname'], - 'type' => $field['typname']); - } - - return $fields; - } - -/** - * Returns a quoted and escaped string of $data for use in an SQL statement. - * - * @param string $data String to be prepared for use in an SQL statement - * @return string Quoted and escaped - */ - function prepareValue ($data) { - return "'".pg_escape_string($data)."'"; - } - -/** - * Returns a formatted error message from previous database operation. - * - * @return string Error message - */ - function lastError () { - return pg_last_error()? pg_last_error(): null; - } - -/** - * Returns number of affected rows in previous database operation. If no previous operation exists, this returns false. - * - * @return int Number of affected rows - */ - function lastAffected () { - return $this->_result? pg_affected_rows($this->_result): false; - } - -/** - * Returns number of rows in previous resultset. If no previous resultset exists, - * this returns false. - * - * @return int Number of rows - */ - function lastNumRows () { - return $this->_result? pg_num_rows($this->_result): false; - } - -/** - * Returns the ID generated from the previous INSERT operation. - * - * @param string $table Name of the database table - * @param string $field Name of the ID database field. Defaults to "id" - * @return unknown - */ - function lastInsertId ($table, $field='id') { - $sql = "SELECT CURRVAL('{$table}_{$field}_seq') AS max"; - $res = $this->rawQuery($sql); - $data = $this->fetchRow($res); - return $data['max']; - } -} - + + // +// + Copyright: (c) 2005, Cake Authors/Developers + // +// + Author(s): Michal Tatarynowicz aka Pies + // +// + Larry E. Masters aka PhpNut + // +// + Kamil Dzielinski aka Brego + // +// +------------------------------------------------------------------+ // +// + Licensed under The MIT License + // +// + Redistributions of files must retain the above copyright notice. + // +// + See: http://www.opensource.org/licenses/mit-license.php + // +////////////////////////////////////////////////////////////////////////// + +/** + * PostgreSQL layer for DBO. + * + * @filesource + * @author Cake Authors/Developers + * @copyright Copyright (c) 2005, Cake Authors/Developers + * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.libs + * @since Cake v 1.0.0.114 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * Include DBO. + */ +uses('dbo'); + +/** + * PostgreSQL layer for DBO. + * + * @package cake + * @subpackage cake.libs + * @since Cake v 1.0.0.114 + */ +class DBO_Postgres extends DBO { + +/** + * Connects to the database using options in the given configuration array. + * + * @param array $config Configuration array for connecting + * @return True if successfully connected. + */ + function connect ($config) { + if($config) { + $this->config = $config; + $this->_conn = pg_pconnect("host={$config['host']} dbname={$config['database']} user={$config['login']} password={$config['password']}"); + } + $this->connected = $this->_conn? true: false; + + if($this->connected) + return true; + else + die('Could not connect to DB.'); + + } + +/** + * Disconnects from database. + * + * @return boolean True if the database could be disconnected, else false + */ + function disconnect () { + return pg_close($this->_conn); + } + +/** + * Executes given SQL statement. + * + * @param string $sql SQL statement + * @return resource Result resource identifier + */ + function execute ($sql) { + return pg_query($this->_conn, $sql); + } + +/** + * Returns a row from given resultset. + * + * @param unknown_type $res + * @return unknown + */ + function fetchRow ($res) { + return pg_fetch_array($res); + } + +/** + * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits. + * + * @return array Array of tablenames in the database + */ + function tablesList () { + $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));"; + + $result = $this->all($sql); + + if (!$result) { + trigger_error(ERROR_NO_TABLE_LIST, E_USER_ERROR); + exit; + } + else { + $tables = array(); + foreach ($result as $item) $tables[] = $item['name']; + return $tables; + } + } + +/** + * Returns an array of the fields in given table name. + * + * @param string $table_name Name of database table to inspect + * @return array Fields in table. Keys are name and type + */ + function fields ($table_name) { + $sql = "SELECT c.relname, a.attname, t.typname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '{$table_name}' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid"; + + $fields = false; + foreach ($this->all($sql) as $field) { + $fields[] = array( + 'name' => $field['attname'], + 'type' => $field['typname']); + } + + return $fields; + } + +/** + * Returns a quoted and escaped string of $data for use in an SQL statement. + * + * @param string $data String to be prepared for use in an SQL statement + * @return string Quoted and escaped + */ + function prepareValue ($data) { + return "'".pg_escape_string($data)."'"; + } + + + /** + * Returns a limit statement in the correct format for the particular database. + * + * @param int $limit Limit of results returned + * @param int $offset Offset from which to start results + * @return string SQL limit/offset statement + */ + function selectLimit ($limit, $offset=null) + { + return "LIMIT {$limit}".($offset? " OFFSET {$offset}": null); + } + +/** + * Returns a formatted error message from previous database operation. + * + * @return string Error message + */ + function lastError () { + return pg_last_error()? pg_last_error(): null; + } + +/** + * Returns number of affected rows in previous database operation. If no previous operation exists, this returns false. + * + * @return int Number of affected rows + */ + function lastAffected () { + return $this->_result? pg_affected_rows($this->_result): false; + } + +/** + * Returns number of rows in previous resultset. If no previous resultset exists, + * this returns false. + * + * @return int Number of rows + */ + function lastNumRows () { + return $this->_result? pg_num_rows($this->_result): false; + } + +/** + * Returns the ID generated from the previous INSERT operation. + * + * @param string $table Name of the database table + * @param string $field Name of the ID database field. Defaults to "id" + * @return unknown + */ + function lastInsertId ($table, $field='id') { + $sql = "SELECT CURRVAL('{$table}_{$field}_seq') AS max"; + $res = $this->rawQuery($sql); + $data = $this->fetchRow($res); + return $data['max']; + } +} + ?> \ No newline at end of file diff --git a/libs/dbo_sqlite.php b/libs/dbo/dbo_sqlite.php similarity index 92% rename from libs/dbo_sqlite.php rename to libs/dbo/dbo_sqlite.php index 2df7d643d..97ea709c7 100644 --- a/libs/dbo_sqlite.php +++ b/libs/dbo/dbo_sqlite.php @@ -142,6 +142,19 @@ $this->_conn return "'".sqlite_escape_string($data)."'"; } + /** + * Returns a limit statement in the correct format for the particular database. + * + * @param int $limit Limit of results returned + * @param int $offset Offset from which to start results + * @return string SQL limit/offset statement + */ + function selectLimit ($limit, $offset=null) + { + // :TODO: Please verify this with SQLite, untested. + return "LIMIT {$limit}".($offset? " OFFSET {$offset}": null); + } + /** * Returns a formatted error message from previous database operation. * diff --git a/libs/dbo_factory.php b/libs/dbo_factory.php index 3db96ad0b..54594c136 100644 --- a/libs/dbo_factory.php +++ b/libs/dbo_factory.php @@ -32,7 +32,7 @@ * Enter description here... * */ -uses('object'); +uses('object', 'dbo'); config('database'); /** @@ -56,20 +56,27 @@ class DboFactory extends Object { $config = DATABASE_CONFIG::$activeConfig(); - // special case for AdoDB -- driver name in the form of 'adodb_drivername' - if (preg_match('#^adodb_(.*)$#i', $config['driver'], $res)) { - uses('DBO_AdoDB'); + // special case for AdoDB -- driver name in the form of 'adodb-drivername' + if (preg_match('#^adodb[\-_](.*)$#i', $config['driver'], $res)) { + uses('dbo/dbo_adodb'); $config['driver'] = $res[1]; $conn = new DBO_AdoDB($config); return $conn; } + // special case for PEAR:DB -- driver name in the form of 'pear-drivername' + elseif (preg_match('#^pear[\-_](.*)$#i', $config['driver'], $res)) { + uses('dbo/dbo_pear'); + $config['driver'] = $res[1]; + $conn = new DBO_Pear($config); + return $conn; + } // regular, Cake-native db drivers else { $db_driver_class = 'DBO_'.$config['driver']; - $db_driver_fn = LIBS.strtolower($db_driver_class.'.php'); + $db_driver_fn = LIBS.strtolower('dbo'.DS.$db_driver_class.'.php'); if (file_exists($db_driver_fn)) { - uses(strtolower($db_driver_class)); + uses(strtolower('dbo'.DS.$db_driver_class)); return new $db_driver_class ($config); } else { diff --git a/libs/flay.php b/libs/flay.php index 4943b6764..f6c78d8d9 100644 --- a/libs/flay.php +++ b/libs/flay.php @@ -160,14 +160,42 @@ class Flay extends Object // re-parse links if (count($links)) { + for ($ii=0; $ii"; - elseif (preg_match('#^([^\]\ ]+)(?: ([^\]]+))?$#', $links[$ii], $regs)) - $with = "".(isset($regs[2])? $regs[2]: $regs[1]).""; + if (preg_match("#^(http|https|ftp|nntp)://#", $links[$ii])) + { + $prefix = null; + } + else + { + $prefix = 'http://'; + } + + if (preg_match('#^[^\ ]+\.(jpg|jpeg|gif|png)$#', $links[$ii])) + { + $with = "\"\""; + } + elseif (preg_match('#^([^\]\ ]+)(?:\ ([^\]]+))?$#', $links[$ii], $regs)) + { + if (isset($regs[2])) + { + if (preg_match('#\.(jpg|jpeg|gif|png)$#', $regs[2])) + $body = "\"\""; + else + $body = $regs[2]; + + } + else + { + $body = $links[$ii]; + } + $with = "{$body}"; + } else - $with = $links[$ii]; + { + $with = $prefix.$links[$ii]; + } $line = str_replace("%LINK{$ii}%", $with, $line); } diff --git a/libs/model.php b/libs/model.php index cc047a595..0ea0b3718 100644 --- a/libs/model.php +++ b/libs/model.php @@ -575,17 +575,20 @@ class Model extends Object $whers = count($whers)? '('.join(' AND ', $whers).')': null; $conditions .= ($conditions && $whers? ' AND ': null).$whers; - $offset_str = $page > 1? " OFFSET ".$page*$limit: ""; - $limit_str = $limit? " LIMIT {$limit}": ""; + $offset = $page > 1? $page*$limit: 0; + $limit = $limit? $limit: '-1'; - $data = $this->db->all( + $limit_str = $this->db->selectLimit($limit, $offset); + + $sql = "SELECT " .join(', ', $f) ." FROM {$this->table} {$joins}" .($conditions? " WHERE {$conditions}":null) .($order? " ORDER BY {$order}": null) - .$limit_str - .$offset_str); + .$limit_str; + + $data = $this->db->all($sql); return $data; } diff --git a/libs/template.php b/libs/template.php index dcee559ed..480768bde 100644 --- a/libs/template.php +++ b/libs/template.php @@ -92,7 +92,7 @@ class Template extends Object { * @var boolean * @access private */ - var $_page_title = false; + var $pageTitle = false; /** * Choose the layout to be used when rendering. @@ -120,7 +120,7 @@ class Template extends Object { * @param string $pageTitle Text for the title */ function setTitle ($pageTitle) { - $this->_page_title = $pageTitle; + $this->pageTitle = $pageTitle; } /** @@ -200,7 +200,7 @@ class Template extends Object { $layout_fn = $this->_getLayoutFn(); $data_for_layout = array_merge($this->_view_vars, array( - 'title_for_layout'=>$this->_page_title !== false? $this->_page_title: Inflector::humanize($this->viewpath), + 'title_for_layout'=>$this->pageTitle !== false? $this->pageTitle: Inflector::humanize($this->viewpath), 'content_for_layout'=>$content_for_layout)); if (is_file($layout_fn)) { @@ -270,7 +270,7 @@ class Template extends Object { extract($___data_for_view, EXTR_SKIP); # load all view variables $BASE = $this->base; $params = &$this->params; - $page_title = $this->_page_title; + $page_title = $this->pageTitle; ob_start(); # start caching output (eval outputs directly so we need to cache) # include the template diff --git a/public/css/default.css b/public/css/default.css index e50770bb9..05fdc3305 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -12,11 +12,11 @@ text-align:center; } H2 { -font-size:1.8em; +font-size:1.7em; } H3 { -font-size:1.5em; +font-size:1.4em; } P { diff --git a/public/index.php b/public/index.php index c92b2dcbe..220db1fc6 100644 --- a/public/index.php +++ b/public/index.php @@ -44,24 +44,28 @@ if (!defined('ROOT')) /** * Configuration, directory layout and standard libraries */ -require (ROOT.'config/core.php'); -require (ROOT.'config/paths.php'); -require (ROOT.'libs/log.php'); -require (ROOT.'libs/object.php'); -require (ROOT.'libs/neat_array.php'); -require (ROOT.'libs/inflector.php'); -require (ROOT.'libs/basics.php'); -require (ROOT.'libs/folder.php'); +require_once (ROOT.'config/core.php'); +require_once (ROOT.'config/paths.php'); +require_once (ROOT.'libs/log.php'); +require_once (ROOT.'libs/object.php'); +require_once (ROOT.'libs/neat_array.php'); +require_once (ROOT.'libs/inflector.php'); +require_once (ROOT.'libs/basics.php'); DEBUG? error_reporting(E_ALL): error_reporting(0); $TIME_START = getMicrotime(); -uses ('dispatcher', 'dbo_factory'); +uses('folder'); +uses('dispatcher'); +uses('dbo_factory'); config ('tags', 'database'); -$DB = DboFactory::make('devel'); +if (class_exists('DATABASE_CONFIG')) +{ + $DB = DboFactory::make('devel'); +} loadModels ();