diff --git a/libs/basics.php b/libs/basics.php index 9eded39a9..b8d8f3cf6 100644 --- a/libs/basics.php +++ b/libs/basics.php @@ -387,6 +387,21 @@ class NeatArray { return $this->value = $out; } + function threaded ($root=null, $idKey='id', $parentIdKey='parent_id', $childrenKey='children') { + $out = array(); + + for ($ii=0; $iivalue); $ii++) { + if ($this->value[$ii][$parentIdKey] == $root) { + $tmp = $this->value[$ii]; + $tmp[$childrenKey] = isset($this->value[$ii][$idKey])? + $this->threaded($this->value[$ii][$idKey], $idKey, $parentIdKey, $childrenKey): + null; + $out[] = $tmp; + } + } + + return $out; + } } ?> diff --git a/libs/dbo.php b/libs/dbo.php index fd727204c..033c00b5f 100644 --- a/libs/dbo.php +++ b/libs/dbo.php @@ -176,6 +176,17 @@ class DBO extends Object { */ var $_queriesLog=array(); +/** + * Maximum number of items in query log, to prevent query log taking over + * too much memory on large amounts of queries -- we've had problems at + * ~6000 queries. + * + * @var int Maximum number of queries in the queries log. + * @access private + */ + var $_queriesLogMax=200; + + // specific for each database, implemented in db drivers function connect ($config) { die('Please implement DBO::connect() first.'); @@ -408,6 +419,7 @@ class DBO extends Object { function logQuery($sql) { $this->_queriesCnt++; $this->_queriesTime += $this->took; + $this->_queriesLog[] = array( 'query'=>$sql, 'error'=>$this->error, @@ -416,6 +428,10 @@ class DBO extends Object { 'took'=>$this->took ); + if (count($this->_queriesLog) > $this->_queriesLogMax) { + array_pop($this->_queriesLog); + } + if ($this->error) false; // shouldn't we be logging errors somehow? } diff --git a/libs/dbo_pear.php b/libs/dbo_pear.php new file mode 100644 index 000000000..18d9beefd --- /dev/null +++ b/libs/dbo_pear.php @@ -0,0 +1,188 @@ + + // +// + 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 + // +// +------------------------------------------------------------------+ // +////////////////////////////////////////////////////////////////////////// + +/* + * Name: DBO/Pear + * Pear::DB 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 + */ + +/** + * Enter description here... + * + */ + +uses('dbo'); +/** + * Enter description here... + * + * + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + * + */ +class DBO_Pear extends DBO { + +/** + * Enter description here... + * + * @param unknown_type $config + * @return unknown + */ + function connect ($config) { + die('Please implement DBO::connect() first.'); + } + +/** + * Enter description here... + * + * @return unknown + */ + function disconnect () { + die('Please implement DBO::disconnect() first.'); + } + +/** + * Enter description here... + * + * @param unknown_type $sql + * @return unknown + */ + function execute ($sql) { + return $this->_pear->query($sql); + } + +/** + * Enter description here... + * + * @param unknown_type $res + * @return unknown + */ + function fetchRow ($result) { + return $result->fetchRow(DB_FETCHMODE_ASSOC); + } + +/** + * Enter description here... + * + * @return unknown + */ + function tables () { // 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));"; + + $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; + } + } + +/** + * Enter description here... + * + * @param unknown_type $table_name + * @return unknown + */ + function fields ($table_name) { + $data = $this->_pear->tableInfo($table_name); + $fields = false; + + foreach ($data as $item) + $fields[] = array('name'=>$item['name'], 'type'=>$item['type']); + + return $fields; + } + +/** + * Enter description here... + * + * @param unknown_type $data + * @return unknown + */ + function prepare ($data) { + return $this->_pear->quoteSmart($data); + } + +/** + * Enter description here... + * + * @return unknown + */ + function lastError () { + return PEAR::isError($this->_result)? $this->_result->getMessage(): null; + } + +/** + * Enter description here... + * + * @return unknown + */ + function lastAffected () { + return $this->_pear->affectedRows(); + } + +/** + * Enter description here... + * + * @return unknown + */ + function lastNumRows ($result) { + if (method_exists($result, 'numRows')) + return $result->numRows(); + else + return false; + } + +/** + * Enter description here... + * + * @return unknown + */ + function lastInsertId ($table) { + return $this->field('id', "SELECT MAX(id) FROM {$table}"); + } + + +} + +?> \ No newline at end of file diff --git a/libs/flay.php b/libs/flay.php index 902556fb9..c4fc533a4 100644 --- a/libs/flay.php +++ b/libs/flay.php @@ -151,9 +151,9 @@ class Flay extends Object { $line = str_replace($url, "{$url}", $line); } } - if (preg_match_all("#(www\.[^ ]+)#", $line, $urls)) { + if (preg_match_all("#(www\.[^\n\%\ ]+[^\n\%\,\.\ ])#", $line, $urls)) { foreach ($urls[1] as $url) { - $line = str_replace($url, "{$url}", $line); + $line = str_replace($url, "{$url}", $line); } } diff --git a/libs/legacy.php b/libs/legacy.php index 7fdceefda..0c2247d46 100644 --- a/libs/legacy.php +++ b/libs/legacy.php @@ -40,25 +40,6 @@ if (version_compare(phpversion(), '5.0') < 0) { } -// needed for old Plog v2 -// -function old_lib ($name) { - old_libs ($name); -} - -function old_libs () { - if (count($lib_names = func_get_args())) { - foreach ($lib_names as $lib_name) { - require (OLD_LIBS.$lib_name.'.php'); - } - - return true; - } - else { - return false; - } -} - /** * Replace file_get_contents() * diff --git a/libs/model.php b/libs/model.php index 9d2f62527..75edb5a24 100644 --- a/libs/model.php +++ b/libs/model.php @@ -150,17 +150,25 @@ class Model extends Object { * Constructor. Binds the Model's database table to the object. * * @param unknown_type $id + * @param string $table Database table to use. * @param unknown_type $db Database connection object. */ - function __construct ($id=false, $db=null) { + function __construct ($id=false, $table=null, $db=null) { global $DB; - $this->db = $db? $db: &$DB; + if ($db) + { + $this->db = $db; + } + else + { + $this->db = &$DB; + } if ($id) $this->id = $id; - $table_name = $this->use_table? $this->use_table: Inflector::tableize(get_class($this)); + $table_name = $table? $table: ($this->use_table? $this->use_table: Inflector::tableize(get_class($this))); $this->useTable ($table_name); parent::__construct(); $this->createLinks();