- Controller::imageTag() uses a path set in /config/paths.php

- new Controller::linkEmail() tag generator, with binary encoding (not UTF-8 compatibile)
- Controller::parseHtmlOptions() accepts a new second parameter -- options to exclude
- fixed DBO::farr() (ticked #23)
- fixed and cleaned up DBO layers NEEDS TESTING!
- fixed Template::renderElement(), it didn't use the controller's view vars
- models are loaded only if a database configuration is present

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@247 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
pies 2005-06-14 19:57:01 +00:00
parent 01b0d81dd2
commit 27faaea8ea
13 changed files with 379 additions and 294 deletions

View file

@ -87,6 +87,11 @@ define ('MODULES', ROOT.'modules'.DS);
*/
define ('PUBLIC', ROOT.'public'.DS);
/**
* Web path to the public images directory.
*/
define ('IMAGES', '/img/');
/**
* Path to the tests directory.
*/

View file

@ -21,6 +21,11 @@
*/
define('TAG_LINK', '<a href="%s"%s>%s</a>');
/**
* Tag template for a mailto: link.
*/
define('TAG_MAILTO', '<a href="mailto:%s"%s>%s</a>');
/**
* Tag template for opening form tag.
*/

View file

@ -75,17 +75,9 @@ class Controller extends Template {
var $action = null;
/**
* This Controller's Model.
* An array of names of models the particular controller wants to use.
*
* @var unknown_type
* @access public
*/
var $use_model = null;
/**
* Enter description here...
*
* @var unknown_type
* @var mixed A single name as a string or a list of names as an array.
* @access private
*/
var $uses = false;
@ -194,16 +186,25 @@ class Controller extends Template {
* @param unknown_type $insert_after
* @return string
*/
function parseHtmlOptions ($options, $insert_before=' ', $insert_after=null) {
if (is_array($options)) {
function parseHtmlOptions ($options, $exclude=null, $insert_before=' ', $insert_after=null)
{
if (!is_array($exclude)) $exclude = array();
if (is_array($options))
{
$out = array();
foreach ($options as $k=>$v) {
$out[] = "{$k}=\"{$v}\"";
foreach ($options as $k=>$v)
{
if (!in_array($k, $exclude))
{
$out[] = "{$k}=\"{$v}\"";
}
}
$out = join(' ', $out);
return $out? $insert_before.$out.$insert_after: null;
}
else {
else
{
return $options? $insert_before.$options.$insert_after: null;
}
}
@ -249,7 +250,7 @@ class Controller extends Template {
$html_options['method'] = $type=='get'? 'get': 'post';
$type == 'file'? $html_options['enctype'] = 'multipart/form-data': null;
return sprintf(TAG_FORM, $this->parseHtmlOptions($html_options, ''));
return sprintf(TAG_FORM, $this->parseHtmlOptions($html_options, null, ''));
}
/**
@ -296,7 +297,7 @@ class Controller extends Template {
*/
function submitTag ($caption='Submit', $html_options=null) {
$html_options['value'] = $caption;
return sprintf(TAG_SUBMIT, $this->parseHtmlOptions($html_options, '', ' '));
return sprintf(TAG_SUBMIT, $this->parseHtmlOptions($html_options, null, '', ' '));
}
/**
@ -311,7 +312,7 @@ class Controller extends Template {
$html_options['size'] = $size;
$html_options['value'] = isset($html_options['value'])? $html_options['value']: $this->tagValue($tag_name);
$this->tagIsInvalid($tag_name)? $html_options['class'] = 'form_error': null;
return sprintf(TAG_INPUT, $tag_name, $this->parseHtmlOptions($html_options, '', ' '));
return sprintf(TAG_INPUT, $tag_name, $this->parseHtmlOptions($html_options, null, '', ' '));
}
/**
@ -325,7 +326,7 @@ class Controller extends Template {
function passwordTag ($tag_name, $size=20, $html_options=null) {
$html_options['size'] = $size;
empty($html_options['value'])? $html_options['value'] = $this->tagValue($tag_name): null;
return sprintf(TAG_PASSWORD, $tag_name, $this->parseHtmlOptions($html_options, '', ' '));
return sprintf(TAG_PASSWORD, $tag_name, $this->parseHtmlOptions($html_options, null, '', ' '));
}
/**
@ -338,7 +339,7 @@ class Controller extends Template {
*/
function hiddenTag ($tag_name, $value=null, $html_options=null) {
$html_options['value'] = $value? $value: $this->tagValue($tag_name);
return sprintf(TAG_HIDDEN, $tag_name, $this->parseHtmlOptions($html_options, '', ' '));
return sprintf(TAG_HIDDEN, $tag_name, $this->parseHtmlOptions($html_options, null, '', ' '));
}
/**
@ -349,7 +350,7 @@ class Controller extends Template {
* @return string
*/
function fileTag ($tag_name, $html_options=null) {
return sprintf(TAG_FILE, $tag_name, $this->parseHtmlOptions($html_options, '', ' '));
return sprintf(TAG_FILE, $tag_name, $this->parseHtmlOptions($html_options, null, '', ' '));
}
/**
@ -365,7 +366,7 @@ class Controller extends Template {
$value = empty($html_options['value'])? $this->tagValue($tag_name): empty($html_options['value']);
$html_options['cols'] = $cols;
$html_options['rows'] = $rows;
return sprintf(TAG_AREA, $tag_name, $this->parseHtmlOptions($html_options, ' '), $value);
return sprintf(TAG_AREA, $tag_name, $this->parseHtmlOptions($html_options, null, ' '), $value);
}
/**
@ -379,7 +380,7 @@ class Controller extends Template {
function checkboxTag ($tag_name, $title=null, $html_options=null) {
$this->tagValue($tag_name)? $html_options['checked'] = 'checked': null;
$title = $title? $title: ucfirst($tag_name);
return sprintf(TAG_CHECKBOX, $tag_name, $tag_name, $tag_name, $this->parseHtmlOptions($html_options, '', ' '), $title);
return sprintf(TAG_CHECKBOX, $tag_name, $tag_name, $tag_name, $this->parseHtmlOptions($html_options, null, '', ' '), $title);
}
/**
@ -397,7 +398,7 @@ class Controller extends Template {
foreach ($options as $opt_value=>$opt_title) {
$options_here = array('value' => $opt_value);
$opt_value==$value? $options_here['checked'] = 'checked': null;
$parsed_options = $this->parseHtmlOptions(array_merge($html_options, $options_here), '', ' ');
$parsed_options = $this->parseHtmlOptions(array_merge($html_options, $options_here), null, '', ' ');
$individual_tag_name = "{$tag_name}_{$opt_value}";
$out[] = sprintf(TAG_RADIOS, $individual_tag_name, $tag_name, $individual_tag_name, $parsed_options, $opt_title);
}
@ -447,11 +448,52 @@ class Controller extends Template {
* @return string Formatted IMG tag
*/
function imageTag ($path, $alt=null, $html_options=null) {
$url = "{$this->base}/images/{$path}";
return sprintf(TAG_IMAGE, $url, $alt, $this->parseHtmlOptions($html_options, '', ' '));
$url = $this->base.IMAGES.$path;
return sprintf(TAG_IMAGE, $url, $alt, $this->parseHtmlOptions($html_options, null, '', ' '));
}
/**
* Returns a mailto: link.
*
* @param string $title Title of the link, or the e-mail address (if the same)
* @param string $email E-mail address if different from title
* @param array $options
* @return string Formatted A tag
*/
function linkEmail($title, $email=null, $options=null)
{
// if no $email, then title contains the email.
if (empty($email)) $email = $title;
// does the address contain extra attributes?
preg_match('!^(.*)(\?.*)$!', $email, $match);
// plaintext
if (empty($options['encode']) || !empty($match[2]))
{
return sprintf(TAG_MAILTO, $email, $this->parseHtmlOptions($options), $title);
}
// encoded to avoid spiders
else
{
$email_encoded = null;
for ($ii=0; $ii < strlen($email); $ii++) {
if(preg_match('!\w!',$email[$ii])) {
$email_encoded .= '%' . bin2hex($email[$ii]);
} else {
$email_encoded .= $email[$ii];
}
}
$title_encoded = null;
for ($ii=0; $ii < strlen($title); $ii++) {
$title_encoded .= '&#x' . bin2hex($title[$ii]).';';
}
return sprintf(TAG_MAILTO, $email_encoded, $this->parseHtmlOptions($options, array('encode')), $title_encoded);
}
}
/**
* Returns a LINK element for CSS stylesheets.
*
@ -462,10 +504,9 @@ class Controller extends Template {
*/
function cssTag ($path, $rel='stylesheet', $html_options=null) {
$url = "{$this->base}/css/{$path}.css";
return sprintf(TAG_CSS, $rel, $url, $this->parseHtmlOptions($html_options, '', ' '));
return sprintf(TAG_CSS, $rel, $url, $this->parseHtmlOptions($html_options, null, '', ' '));
}
/**
* Returns a charset meta-tag
*

View file

@ -265,7 +265,6 @@ class DBO extends Object {
return array_map('strtolower', $this->tablesList());
}
/**
* Executes given SQL statement.
*
@ -306,8 +305,16 @@ class DBO extends Object {
* @param resource $res
* @return array A single row of results
*/
function farr ($res=false, $assoc=false) {
return $this->fetchRow($res? $res: $this->_result, $assoc);
function farr ($assoc=false)
{
if ($assoc === false)
{
return $this->fetchRow();
}
else
{
return $this->fetchRow($assoc);
}
}
/**

View file

@ -67,7 +67,7 @@ class DBO_AdoDB extends DBO
if(!$this->connected)
die('Could not connect to DB.');
}
/**
* Disconnects from database.
*
@ -92,12 +92,11 @@ class DBO_AdoDB extends DBO
/**
* 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)
function fetchRow ()
{
return $res->FetchRow();
return $this->_result->FetchRow();
}
/**
@ -105,7 +104,7 @@ class DBO_AdoDB extends DBO
*
* @return array Array of tablenames in the database
*/
function tablesList()
function tablesList ()
{
$tables = $this->_adodb->MetaTables('TABLES');
@ -122,7 +121,7 @@ class DBO_AdoDB 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->_adodb->MetaColumns($table_name);
$fields = false;
@ -146,27 +145,12 @@ class DBO_AdoDB extends DBO
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 ()
function lastError ()
{
return $this->_adodb->ErrorMsg();
}
@ -185,7 +169,7 @@ class DBO_AdoDB extends DBO
* Returns number of rows in previous resultset. If no previous resultset exists,
* this returns false.
*
* @return int Number of rows
* @return int Number of rows in resultset
*/
function lastNumRows ()
{
@ -200,6 +184,21 @@ class DBO_AdoDB extends DBO
* :TODO: To be implemented.
*/
function lastInsertId () { die('Please implement DBO::lastInsertId() first.'); }
/**
* 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
}
}
?>

View file

@ -44,31 +44,31 @@ class DBO_generic extends DBO
{
}
function fetchRow ($result)
function fetchRow ()
{
}
function tablesList()
function tablesList ()
{
}
function fields ($table_name)
function fields ($table_name)
{
}
function prepareValue ($data)
function prepareValue ($data)
{
}
function lastError ($result)
function lastError ()
{
}
function lastAffected ()
function lastAffected ()
{
}
function lastNumRows ($result)
function lastNumRows ()
{
}
@ -76,7 +76,7 @@ class DBO_generic extends DBO
{
}
function selectLimit ($limit, $offset)
function selectLimit ($limit, $offset=null)
{
}

View file

@ -3,20 +3,14 @@
// + $Id$
// +------------------------------------------------------------------+ //
// + Cake <https://developers.nextco.com/cake/> + //
// + Copyright: (c) 2005 Cake Authors/Developers + //
// + + //
// + Copyright: (c) 2005, Cake Authors/Developers + //
// + Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> + //
// + Larry E. Masters aka PhpNut <nut@phpnut.com> + //
// + Kamil Dzielinski aka Brego <brego.dk@gmail.com> + //
// + + //
// +------------------------------------------------------------------+ //
// + 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 + //
//////////////////////////////////////////////////////////////////////////
/**
@ -38,8 +32,8 @@
/**
* Include DBO.
*/
uses('dbo');
/**
* MySQL layer for DBO.
*
@ -47,23 +41,26 @@ uses('dbo');
* @subpackage cake.libs
* @since Cake v 0.2.9
*/
class DBO_MySQL extends DBO {
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) {
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);
return mysql_select_db($config['database'], $this->_conn);
else
die('Could not connect to DB.');
}
@ -73,7 +70,8 @@ class DBO_MySQL extends DBO {
*
* @return boolean True if the database could be disconnected, else false
*/
function disconnect () {
function disconnect ()
{
return mysql_close();
}
@ -81,20 +79,22 @@ class DBO_MySQL extends DBO {
* Executes given SQL statement.
*
* @param string $sql SQL statement
* @return resource MySQL result resource identifier
* @return resource Result resource identifier
*/
function execute ($sql) {
function execute ($sql)
{
return mysql_query($sql);
}
/**
* Returns a row from given resultset as an array .
*
* @param unknown_type $res Resultset
* @param bool $assoc Associative array only, or both?
* @return array The fetched row as an array
*/
function fetchRow ($res, $assoc=false) {
return mysql_fetch_array($res, $assoc? MYSQL_ASSOC: MYSQL_BOTH);
function fetchRow ($assoc=false)
{
return mysql_fetch_array($this->_result, $assoc? MYSQL_ASSOC: MYSQL_BOTH);
}
/**
@ -102,16 +102,20 @@ class DBO_MySQL extends DBO {
*
* @return array Array of tablenames in the database
*/
function tablesList () {
function tablesList ()
{
$result = mysql_list_tables($this->config['database']);
if (!$result) {
if (!$result)
{
trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
exit;
}
else {
else
{
$tables = array();
while ($line = mysql_fetch_array($result)) {
while ($line = mysql_fetch_array($result))
{
$tables[] = $line[0];
}
return $tables;
@ -124,12 +128,13 @@ class DBO_MySQL 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) {
$data = $this->all("DESC {$table_name}");
function fields ($table_name)
{
$fields = false;
$cols = $this->all("DESC {$table_name}");
foreach ($data as $item)
$fields[] = array('name'=>$item['Field'], 'type'=>$item['Type']);
foreach ($cols as $column)
$fields[] = array('name'=>$column['Field'], 'type'=>$column['Type']);
return $fields;
}
@ -140,11 +145,52 @@ class DBO_MySQL 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 "'".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 in resultset
*/
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();
}
/**
* Returns a limit statement in the correct format for the particular database.
*
@ -154,44 +200,7 @@ class DBO_MySQL extends DBO {
*/
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();
return " LIMIT {$limit}".($offset? "{$offset}": null);
}
}

View file

@ -30,13 +30,12 @@
*/
/**
* Include required libraries.
* Create an include path required Pear libraries.
*/
uses('dbo');
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . PEAR);
vendor('Pear/DB');
/**
* Pear::DB layer for DBO.
*
@ -58,7 +57,7 @@ class DBO_Pear extends DBO
* Connects to the database using options in the given configuration array.
*
* @param array $config Configuration array for connecting
* @return unknown
* @return boolean True if the database could be connected, else false
*/
function connect ($config)
{
@ -72,10 +71,7 @@ class DBO_Pear extends DBO
$this->_pear =& DB::connect($dsn, $options);
if (PEAR::isError($this->_pear))
{
die('Could not connect to the database.');
}
return !(PEAR::isError($this->_pear));
}
/**
@ -102,12 +98,11 @@ class DBO_Pear extends DBO
/**
* Returns a row from given resultset as an array .
*
* @param unknown_type $res Resultset
* @return array The fetched row as an array
*/
function fetchRow ($result)
function fetchRow ()
{
return $result->fetchRow(DB_FETCHMODE_ASSOC);
return $this->_result->fetchRow(DB_FETCHMODE_ASSOC);
}
/**
@ -168,7 +163,7 @@ 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;
@ -190,29 +185,14 @@ class DBO_Pear extends DBO
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 ()
{
if (!$result) $result = $this->_result;
return PEAR::isError($result)? $result->getMessage(): null;
return PEAR::isError($this->_result)? $this->_result->getMessage(): null;
}
/**
@ -220,7 +200,7 @@ class DBO_Pear extends DBO
*
* @return int Number of affected rows
*/
function lastAffected ()
function lastAffected ()
{
return $this->_pear->affectedRows();
}
@ -229,12 +209,12 @@ class DBO_Pear extends DBO
* Returns number of rows in previous resultset. If no previous resultset exists,
* this returns false.
*
* @return int Number of rows
* @return int Number of rows in resultset
*/
function lastNumRows ($result)
function lastNumRows ()
{
if (method_exists($result, 'numRows'))
return $result->numRows();
if (method_exists($this->_result, 'numRows'))
return $this->_result->numRows();
else
return false;
}
@ -250,6 +230,18 @@ class DBO_Pear extends DBO
return $this->field('id', "SELECT MAX(id) FROM {$table}");
}
/**
* 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);
}
}
?>

View file

@ -41,7 +41,8 @@ uses('dbo');
* @subpackage cake.libs
* @since Cake v 1.0.0.114
*/
class DBO_Postgres extends DBO {
class DBO_Postgres extends DBO
{
/**
* Connects to the database using options in the given configuration array.
@ -49,8 +50,10 @@ class DBO_Postgres extends DBO {
* @param array $config Configuration array for connecting
* @return True if successfully connected.
*/
function connect ($config) {
if($config) {
function connect ($config)
{
if ($config)
{
$this->config = $config;
$this->_conn = pg_pconnect("host={$config['host']} dbname={$config['database']} user={$config['login']} password={$config['password']}");
}
@ -60,7 +63,6 @@ class DBO_Postgres extends DBO {
return true;
else
die('Could not connect to DB.');
}
/**
@ -68,7 +70,8 @@ class DBO_Postgres extends DBO {
*
* @return boolean True if the database could be disconnected, else false
*/
function disconnect () {
function disconnect ()
{
return pg_close($this->_conn);
}
@ -78,18 +81,19 @@ class DBO_Postgres extends DBO {
* @param string $sql SQL statement
* @return resource Result resource identifier
*/
function execute ($sql) {
function execute ($sql)
{
return pg_query($this->_conn, $sql);
}
/**
* Returns a row from given resultset.
* Returns a row from given resultset as an array .
*
* @param unknown_type $res
* @return unknown
* @return array The fetched row as an array
*/
function fetchRow ($res) {
return pg_fetch_array($res);
function fetchRow ()
{
return pg_fetch_array();
}
/**
@ -97,7 +101,8 @@ class DBO_Postgres extends DBO {
*
* @return array Array of tablenames in the database
*/
function tablesList () {
function tablesList ()
{
$sql = "SELECT a.relname AS name
FROM pg_class a, pg_user b
WHERE ( relkind = 'r') and relname !~ '^pg_' AND relname !~ '^sql_'
@ -106,11 +111,13 @@ class DBO_Postgres extends DBO {
$result = $this->all($sql);
if (!$result) {
if (!$result)
{
trigger_error(ERROR_NO_TABLE_LIST, E_USER_ERROR);
exit;
}
else {
else
{
$tables = array();
foreach ($result as $item) $tables[] = $item['name'];
return $tables;
@ -123,7 +130,8 @@ class DBO_Postgres 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)
{
$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;
@ -142,11 +150,58 @@ class DBO_Postgres 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 "'".pg_escape_string($data)."'";
}
/**
* Returns a formatted error message from previous database operation.
*
* @return string Error message
*/
function lastError ()
{
$last_error = pg_last_error($this->_result);
return $last_error? $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 in resultset
*/
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 int
*/
function lastInsertId ($table, $field='id')
{
$sql = "SELECT CURRVAL('{$table}_{$field}_seq') AS max";
$res = $this->rawQuery($sql);
$data = $this->fetchRow($res);
return $data['max'];
}
/**
* Returns a limit statement in the correct format for the particular database.
*
@ -156,50 +211,9 @@ class DBO_Postgres extends DBO {
*/
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;
return " LIMIT {$limit}".($offset? " OFFSET {$offset}": 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'];
}
}
?>

View file

@ -14,7 +14,6 @@
//////////////////////////////////////////////////////////////////////////
/**
* Purpose: DBO_SQLite
* SQLite layer for DBO
*
* @filesource
@ -31,38 +30,39 @@
*/
/**
* Enter description here...
*
* Include DBO.
*/
uses('dbo');
/**
* SQLite layer for DBO.
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.9.0
*
*/
class DBO_SQLite extends DBO {
class DBO_SQLite extends DBO
{
/**
* We are connecting to the database, and using config['host'] as a filename.
* Connects to the database using config['host'] as a filename.
*
* @param array $config
* @param array $config Configuration array for connecting
* @return mixed
*/
function connect ($config) {
if($config) {
function connect ($config)
{
if ($config)
{
$this->config = $config;
$this->_conn = sqlite_open($config['host']);
}
$this->connected = $this->_conn ? true: false;
$this->connected = $this->_conn? true: false;
if($this->connected==false)
die('Could not connect to DB.');
else
if($this->connected)
return $this->_conn;
else
die('Could not connect to DB.');
}
/**
@ -70,7 +70,8 @@ class DBO_SQLite extends DBO {
*
* @return boolean True if the database could be disconnected, else false
*/
function disconnect () {
function disconnect ()
{
return sqlite_close($this->_conn);
}
@ -80,18 +81,19 @@ class DBO_SQLite extends DBO {
* @param string $sql SQL statement
* @return resource Result resource identifier
*/
function execute ($sql) {
function execute ($sql)
{
return sqlite_query($this->_conn, $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 sqlite_fetch_array($res);
function fetchRow ()
{
return sqlite_fetch_array($this->_result);
}
/**
@ -99,16 +101,20 @@ class DBO_SQLite extends DBO {
*
* @return array Array of tablenames in the database
*/
function tablesList () {
function tablesList ()
{
$result = sqlite_query($this->_conn, "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;");
$this->_conn
if (!$result) {
if (!$result)
{
trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
exit;
}
else {
else
{
$tables = array();
while ($line = sqlite_fetch_array($result)) {
while ($line = sqlite_fetch_array($result))
{
$tables[] = $line[0];
}
return $tables;
@ -138,10 +144,52 @@ $this->_conn
* @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 "'".sqlite_escape_string($data)."'";
}
/**
* Returns a formatted error message from previous database operation.
*
* @return string Error message
*/
function lastError ()
{
return sqlite_last_error($this->_conn)? sqlite_last_error($this->_conn).': '.sqlite_error_string(sqlite_last_error($this->_conn)): 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? sqlite_changes($this->_conn): false;
}
/**
* Returns number of rows in previous resultset. If no previous resultset exists,
* this returns false.
*
* @return int Number of rows in resultset
*/
function lastNumRows ()
{
return $this->_result? sqlite_num_rows($this->_result): false;
}
/**
* Returns the ID generated from the previous INSERT operation.
*
* @return int
*/
function lastInsertId ()
{
return sqlite_last_insert_rowid($this->_conn);
}
/**
* Returns a limit statement in the correct format for the particular database.
*
@ -152,44 +200,7 @@ $this->_conn
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.
*
* @return string Error message
*/
function lastError () {
return sqlite_last_error($this->_conn)? sqlite_last_error($this->_conn).': '.sqlite_error_string(sqlite_last_error($this->_conn)): 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? sqlite_changes($this->_conn): false;
}
/**
* Returns number of rows in previous resultset. If no previous resultset exists,
* this returns false.
*
* @return int Number of rows in resultset
*/
function lastNumRows () {
return $this->_result? sqlite_num_rows($this->_result): false;
}
/**
* Returns the ID generated from the previous INSERT operation.
*
* @return int
*/
function lastInsertId() {
Return sqlite_last_insert_rowid($this->_conn);
return " LIMIT {$limit}".($offset? " OFFSET {$offset}": null);
}
}

View file

@ -264,11 +264,13 @@ class Flay extends Object
* @param unknown_type $string
* @return unknown
*/
function colorMark($words, $string) {
function colorMark($words, $string)
{
$colors = array('yl','gr','rd','bl','fu','cy');
$nextColorIndex = 0;
foreach ($words as $word) {
foreach ($words as $word)
{
$string = preg_replace("/({$word})/i", '<em class="'.$colors[$nextColorIndex%count($colors)]."\">\\1</em>", $string);
$nextColorIndex++;
}
@ -282,7 +284,8 @@ class Flay extends Object
* @param unknown_type $text
* @return unknown
*/
function toClean ($text) {
function toClean ($text)
{
return strip_tags(html_entity_decode($text, ENT_QUOTES));
}

View file

@ -234,7 +234,7 @@ class Template extends Object {
if (!file_exists($fn))
return "(Error rendering {$name})";
return $this->_render($fn, $params);
return $this->_render($fn, array_merge($this->_view_vars, $params));
}
/**

View file

@ -33,8 +33,8 @@
session_start();
/**
* Get Cake's root directory
*/
* Get Cake's root directory
*/
if (!defined('DS'))
define ('DS', DIRECTORY_SEPARATOR);
@ -65,10 +65,9 @@ config ('tags', 'database');
if (class_exists('DATABASE_CONFIG'))
{
$DB = DboFactory::make('devel');
loadModels ();
}
loadModels ();
## RUN THE SCRIPT
$url = empty($_GET['url'])? null: $_GET['url'];
$DISPATCHER = new Dispatcher ();