diff --git a/app/app_controller.php b/app/app_controller.php
index 7cbb91384..52c703e3f 100644
--- a/app/app_controller.php
+++ b/app/app_controller.php
@@ -42,4 +42,4 @@
class AppController extends Controller {
}
-?>
+?>
\ No newline at end of file
diff --git a/app/app_model.php b/app/app_model.php
index 058db2fa4..53942d3b5 100644
--- a/app/app_model.php
+++ b/app/app_model.php
@@ -42,4 +42,4 @@
class AppModel extends Model {
}
-?>
+?>
\ No newline at end of file
diff --git a/app/controllers/pages_controller.php b/app/controllers/pages_controller.php
new file mode 100644
index 000000000..137eab636
--- /dev/null
+++ b/app/controllers/pages_controller.php
@@ -0,0 +1,22 @@
+redirect('/');
+
+ $path = func_get_args();
+ if (!count($path))
+ $this->redirect('/');
+
+ $this->set('page', $path[0]);
+ $this->set('subpage', empty($path[1])? null: $path[1]);
+ $this->set('title', ucfirst($path[count($path)-1]));
+ $this->render(join('/', $path));
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/app/controllers/tests_controller.php b/app/controllers/tests_controller.php
new file mode 100644
index 000000000..9cc5dc220
--- /dev/null
+++ b/app/controllers/tests_controller.php
@@ -0,0 +1,43 @@
+layout = 'test';
+
+ $tests_folder = new Folder('../tests');
+
+ $results = array();
+ $total_errors = 0;
+ foreach ($tests_folder->findRecursive('.*\.php') as $test) {
+ if (preg_match('/^(.+)\.php/i', basename($test), $r)) {
+ require_once($test);
+ $test_name = Inflector::Camelize($r[1]);
+ if (preg_match('/^(.+)Test$/i', $test_name, $r)) {
+ $module_name = $r[1];
+ }
+ else {
+ $module_name = $test_name;
+ }
+ $suite = new TestSuite($test_name);
+ $result = TestRunner::run($suite);
+
+ $total_errors += $result['errors'];
+
+ $results[] = array(
+ 'name'=>$module_name,
+ 'result'=>$result,
+ );
+ }
+ }
+
+ $this->set('success', !$total_errors);
+ $this->set('results', $results);
+ }
+
+}
+
+?>
diff --git a/app/views/layouts/default.thtml b/app/views/layouts/default.thtml
index 1af4dead0..b5f156897 100644
--- a/app/views/layouts/default.thtml
+++ b/app/views/layouts/default.thtml
@@ -8,6 +8,8 @@
+=$title_for_layout?>
+
=$content_for_layout?>
diff --git a/app/views/layouts/test.thtml b/app/views/layouts/test.thtml
new file mode 100644
index 000000000..b28fe401c
--- /dev/null
+++ b/app/views/layouts/test.thtml
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+=$content_for_layout?>
+
+
+
\ No newline at end of file
diff --git a/app/views/pages/home.thtml b/app/views/pages/home.thtml
new file mode 100644
index 000000000..2bf22191a
--- /dev/null
+++ b/app/views/pages/home.thtml
@@ -0,0 +1,27 @@
+Cake works!
+
+Your installation of Cake is functional. Edit /app/views/pages/home.thtml
to change the contents of this page.
+
+Introducing Cake
+
+Cake is a structure of libraries, classes and run-time infrastructure for PHP programmers. It's also what I use at work. It's based on certain conventions, so you may find it rigid at first. The directory structure is already layed out, and it's different from what most people use. From what I've experienced, great many PHP programmers start as web- or graphic-designers, i.e. they are not university-educated programmers as many in the C++ and Java-land. They invent their own, peculiar ways of solving problems and stick to them. Perhaps that's why so few people use Pear and Pecl libraries – they don't usually re-use their code. And I was one of them. (=$this->linkOut('continued...','http://sputnik.pl/docs/intro')?>)
+
+Features
+
+
+- compatibile with PHP4 and PHP5
+- supplies integrated CRUD for database and simplified querying so you shouldn't need to write SQL for basic operations (although some familiarity with SQL is strongly recommended)
+- request dispatcher with good looking, custom URLs
+- fast, flexible templating (PHP syntax with helper methods)
+- works from a website subdirectory, with very little Apache configuration involved (requires
.htaccess
files and mod_rewrite
to work; these are available on most web servers)
+
+
+Cake is in it's early infancy, but it works and I'm using it on a few projects. Currently the Dispatcher is working, the Model has CRUD functionality but with no joins between tables yet. The Controller is working and has the most basic functions (including render()
for templating).
+
+Getting involved
+
+NEW! =$this->linkOut('My Amazon Wishlish','http://www.amazon.com/gp/registry/registry.html?id=NODP8QT6LFTO')?> for when you'll want to show your appreciation.
+
+=$this->linkOut('Cake PHP Google Group','http://groups-beta.google.com/group/cake-php')?> · =$this->linkOut('Cake Wiki (temporary)','http://cake.bplusf.net/')?> · =$this->linkOut('Cake TRAC (SVN repository, etc.)','https://developers.nextco.com/cake')?>
+
+See =$this->linkOut('Cake website','http://sputnik.pl/cake')?> for more information.
diff --git a/app/views/tests/test_all.thtml b/app/views/tests/test_all.thtml
new file mode 100644
index 000000000..c429417fc
--- /dev/null
+++ b/app/views/tests/test_all.thtml
@@ -0,0 +1,29 @@
+
+PASSED
+
+FAILED
+
+
+
+
+=$r['name']?> =$performed?> test=$performed==1?'':'s'?> |
+
+=$r['name']?>::=$detail['method']?> |
+
+
+=$error['expected'][0]?> =$error['expected'][1]?>
+=$error['actual'][0]?> =$error['actual'][1]?>
+ |
+
+=$r['name']?>::=$detail['method']?> |
+
+
+
diff --git a/config/core.php b/config/core.php
index 4786cd50c..4c36f1432 100644
--- a/config/core.php
+++ b/config/core.php
@@ -36,6 +36,6 @@
* - 1: development
* - 2: full debug with sql
*/
-define ('DEBUG', 0);
+define ('DEBUG', 1);
-?>
+?>
\ No newline at end of file
diff --git a/config/paths.php b/config/paths.php
index fba63b3ea..00bb762f8 100644
--- a/config/paths.php
+++ b/config/paths.php
@@ -36,60 +36,68 @@
* here
*/
if( !defined('ROOT') ){
- define ('ROOT', '../');
+ define ('ROOT', '../');
}
/**
* Path to the application directory.
*/
-define ('APP', ROOT.'app'.DS);
+define ('APP', ROOT.'app'.DS);
/**
* Path to the application models directory.
*/
-define ('MODELS', APP.'models'.DS);
+define ('MODELS', APP.'models'.DS);
/**
* Path to the application controllers directory.
*/
-define ('CONTROLLERS', APP.'controllers'.DS);
+define ('CONTROLLERS', APP.'controllers'.DS);
/**
* Path to the application helpers directory.
*/
-define ('HELPERS', APP.'helpers'.DS);
+define ('HELPERS', APP.'helpers'.DS);
/**
* Path to the application views directory.
*/
-define ('VIEWS', APP.'views'.DS);
+define ('VIEWS', APP.'views'.DS);
/**
* Path to the configuration files directory.
*/
-define ('CONFIGS', ROOT.'config'.DS);
+define ('CONFIGS', ROOT.'config'.DS);
/**
* Path to the libs directory.
*/
-define ('LIBS', ROOT.'libs'.DS);
-define ('LOGS', ROOT.'logs'.DS);
-define ('MODULES', ROOT.'modules'.DS);
+define ('LIBS', ROOT.'libs'.DS);
+
+/**
+ * Path to the logs directory.
+ */
+define ('LOGS', ROOT.'logs'.DS);
+
+/**
+ * Path to the modules directory.
+ */
+define ('MODULES', ROOT.'modules'.DS);
/**
* Path to the public directory.
*/
-define ('PUBLIC', ROOT.'public'.DS);
+define ('PUBLIC', ROOT.'public'.DS);
/**
* Path to the tests directory.
*/
-define ('TESTS', ROOT.'tests'.DS);
+define ('TESTS', ROOT.'tests'.DS);
/**
* Path to the vendors directory.
*/
-define ('VENDORS', ROOT.'vendors'.DS);
+define ('VENDORS', ROOT.'vendors'.DS);
/**
* Path to the controller test directory.
@@ -99,16 +107,16 @@ define ('CONTROLLER_TESTS',TESTS.'app'.DS.'controllers'.DS);
/**
* Path to the helpers test directory.
*/
-define ('HELPER_TESTS', TESTS.'app'.DS.'helpers'.DS);
+define ('HELPER_TESTS', TESTS.'app'.DS.'helpers'.DS);
/**
* Path to the models test directory.
*/
-define ('MODEL_TESTS', TESTS.'app'.DS.'models'.DS);
+define ('MODEL_TESTS', TESTS.'app'.DS.'models'.DS);
/**
* Path to the lib test directory.
*/
-define ('LIB_TESTS', TESTS.'libs'.DS);
+define ('LIB_TESTS', TESTS.'libs'.DS);
?>
diff --git a/config/routes.php b/config/routes.php
index 4470ba581..f7b70d620 100644
--- a/config/routes.php
+++ b/config/routes.php
@@ -1,47 +1,53 @@
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * In this file, you set up routes to your controllers and their actions.
- * Routes are very important mechanism that allows you to freely connect
- * different urls to chosen controllers and their actions (functions).
- *
- * @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.config
- * @since Cake v 0.2.9
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
- *
- */
-
-/**
- * Here, we are connecting '/' (base path) to controller called 'Pages', and
- * its action called 'index' - note there are no additional params passed.
- */
-$Route->connect ('/', array('controller'=>'Pages', 'action'=>'index'));
-
-/**
- * Here we connect url '/test' to our test controller. This is helpfull in
- * developement.
- */
-$Route->connect ('/test', array('controller'=>'Tests', 'action'=>'test_all'));
-
-?>
+ + //
+// + 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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * In this file, you set up routes to your controllers and their actions.
+ * Routes are very important mechanism that allows you to freely connect
+ * different urls to chosen controllers and their actions (functions).
+ *
+ * @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.config
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ *
+ */
+
+/**
+ * Here, we are connecting '/' (base path) to controller called 'Pages', and
+ * its action called 'index' - note there are no additional params passed.
+ */
+$Route->connect ('/', array('controller'=>'Pages', 'action'=>'view', 'home'));
+
+/**
+ * Here we connect url '/test' to our test controller. This is helpfull in
+ * developement.
+ */
+$Route->connect ('/test', array('controller'=>'Tests', 'action'=>'test_all'));
+
+/**
+ * Now we connect the rest of Pages controller's urls
+ * This needs to be the last one, as it takes in any and all remaining urls
+ */
+$Route->connect ('/*', array('controller'=>'Pages', 'action'=>'view'));
+
+?>
\ No newline at end of file
diff --git a/config/routes.php.default b/config/routes.php.default
index 4470ba581..86ac906e0 100644
--- a/config/routes.php.default
+++ b/config/routes.php.default
@@ -44,4 +44,4 @@ $Route->connect ('/', array('controller'=>'Pages', 'action'=>'index'));
*/
$Route->connect ('/test', array('controller'=>'Tests', 'action'=>'test_all'));
-?>
+?>
\ No newline at end of file
diff --git a/index.php b/index.php
index 7fa9038be..df5eb0ed9 100644
--- a/index.php
+++ b/index.php
@@ -1,4 +1,4 @@
-
\ No newline at end of file
diff --git a/libs/bake.php b/libs/bake.php
index ff21217cd..da1f5ee6e 100644
--- a/libs/bake.php
+++ b/libs/bake.php
@@ -149,6 +149,9 @@ class %sTest extends TestCase {
$this->stdout = fopen('php://stdout', 'w');
$this->stderr = fopen('php://stderr', 'w');
+ // Output directory name
+ fwrite($this->stderr, "\n".substr(ROOT,0,strlen(ROOT)-1).":\n".str_repeat('-',strlen(ROOT)+1)."\n");
+
switch ($type) {
case 'model':
@@ -201,10 +204,10 @@ class %sTest extends TestCase {
*/
function newView ($controller, $name) {
$dir = Inflector::underscore($controller);
- $path = "{$dir}/".strtolower($name).".thtml";
+ $path = $dir.DS.strtolower($name).".thtml";
$this->createDir(VIEWS.$dir);
$fn = VIEWS.$path;
- $this->createFile($fn, sprintf($this->template('view'), "Edit app/views/{$path} to change this message.
"));
+ $this->createFile($fn, sprintf($this->template('view'), "Edit app".DS."views".DS."{$path} to change this message.
"));
$this->actions++;
}
@@ -452,11 +455,12 @@ class %sTest extends TestCase {
* @uses Bake::stderr
*/
function createFile ($path, $contents) {
+ $shortPath = str_replace(ROOT,null,$path);
if (is_file($path) && !$this->dontAsk) {
- fwrite($this->stdout, "File {$path} exists, overwrite? (yNaq) ");
+ fwrite($this->stdout, "File {$shortPath} exists, overwrite? (yNaq) ");
$key = trim(fgets($this->stdin));
-
+
if ($key=='q') {
fwrite($this->stdout, "Quitting.\n");
exit;
@@ -467,7 +471,7 @@ class %sTest extends TestCase {
elseif ($key=='y') {
}
else {
- fwrite($this->stdout, "Skip {$path}\n");
+ fwrite($this->stdout, "Skip {$shortPath}\n");
return false;
}
}
@@ -475,12 +479,12 @@ class %sTest extends TestCase {
if ($f = fopen($path, 'w')) {
fwrite($f, $contents);
fclose($f);
- fwrite($this->stdout, "Wrote {$path}\n");
+ fwrite($this->stdout, "Wrote {$shortPath}\n");
// debug ("Wrote {$path}");
return true;
}
else {
- fwrite($this->stderr, "Error! Couldn't open {$path} for writing.\n");
+ fwrite($this->stderr, "Error! Couldn't open {$shortPath} for writing.\n");
// debug ("Error! Couldn't open {$path} for writing.");
return false;
}
@@ -499,13 +503,15 @@ class %sTest extends TestCase {
if (is_dir($path))
return true;
+ $shortPath = str_replace(ROOT, null, $path);
+
if (mkdir($path)) {
- fwrite($this->stdout, "Created {$path}\n");
+ fwrite($this->stdout, "Created {$shortPath}\n");
// debug ("Created {$path}");
return true;
}
else {
- fwrite($this->stderr, "Error! Couldn't create dir {$path}\n");
+ fwrite($this->stderr, "Error! Couldn't create dir {$shortPath}\n");
// debug ("Error! Couldn't create dir {$path}");
return false;
}
diff --git a/libs/basics.php b/libs/basics.php
index 41581d438..32ee4e888 100644
--- a/libs/basics.php
+++ b/libs/basics.php
@@ -1,276 +1,282 @@
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Basic Cake functionalities.
- *
- * @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
- *
- */
-
-/**
- * Loads all models.
- *
- * @uses listModules()
- * @uses APP
- * @uses MODELS
- */
-function loadModels () {
- require (APP.'app_model.php');
- foreach (listClasses(MODELS) as $model_fn) {
- require (MODELS.$model_fn);
- }
-}
-
-/**
- * Loads all controllers.
- *
- * @uses APP
- * @uses listModules()
- * @uses HELPERS
- * @uses CONTROLLERS
- */
-function loadControllers () {
- require (APP.'app_controller.php');
-
- foreach (listClasses(HELPERS) as $helper) {
- require (HELPERS.$helper.'.php');
- }
-
- foreach (listClasses(CONTROLLERS) as $controller) {
- require (CONTROLLERS.$controller.'.php');
- }
-}
-
-/**
- * Loads a controller and it's helper libraries
- *
- * @param string $name
- * @return boolean
- */
-function loadController ($name) {
- $controller_fn = CONTROLLERS.Inflector::underscore($name).'_controller.php';
- $helper_fn = HELPERS.Inflector::underscore($name).'_helper.php';
-
- require(APP.'app_controller.php');
-
- if (file_exists($helper_fn))
- require($helper_fn);
-
- return file_exists($controller_fn)? require($controller_fn): false;
-}
-
-/**
- * Lists PHP files in a specified directory
- *
- * @param string $path
- * @return array
- */
-function listClasses($path) {
- $modules = new Folder($path);
- return $modules->find('(.+)\.php');
-}
-
-/**
- * Loads configuration files
- */
-function config () {
- $args = func_get_args();
- foreach ($args as $arg) {
- require_once (CONFIGS.$arg.'.php');
- }
-}
-
-/**
- * Loads component/components from LIBS.
- *
- * Example:
- *
- * uses('inflector', 'object');
- *
- *
- * @uses LIBS
- */
-function uses () {
- $args = func_get_args();
- foreach ($args as $arg) {
- require_once (LIBS.strtolower($arg).'.php');
- }
-}
-
-/**
- * Setup a debug point.
- *
- * @param boolean $var
- * @param boolean $show_html
- */
-function debug($var = false, $show_html = false) {
- if (DEBUG) {
- print "\n\n";
- if ($show_html) $var = str_replace('<', '<', str_replace('>', '>', $var));
- print_r($var);
- print "\n
\n";
- }
-}
-
-
-if (!function_exists('getMicrotime')) {
-
-/**
- * Returns microtime for execution time checking.
- *
- * @return integer
- */
- function getMicrotime() {
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$usec + (float)$sec);
- }
-}
-if (!function_exists('sortByKey')) {
-/**
- * Sorts given $array by key $sortby.
- *
- * @param array $array
- * @param string $sortby
- * @param string $order
- * @param integer $type
- * @return mixed
- */
- function sortByKey(&$array, $sortby, $order='asc', $type=SORT_NUMERIC) {
-
- if( is_array($array) ) {
-
- foreach( $array AS $key => $val )
- $sa[$key] = $val[$sortby];
-
- if( $order == 'asc' )
- asort($sa, $type);
- else
- arsort($sa, $type);
-
- foreach( $sa as $key=>$val )
- $out[] = $array[$key];
-
- return $out;
-
- }
- else
- return null;
- }
-}
-
-if (!function_exists('array_combine')) {
-/**
- * Combines given identical arrays by using the first array's values as keys,
- * and second one's values as values.
- *
- * @param array $a1
- * @param array $a2
- * @return mixed Outputs either combined array or false.
- */
- function array_combine($a1, $a2) {
- $a1 = array_values($a1);
- $a2 = array_values($a2);
- $c1 = count($a1);
- $c2 = count($a2);
-
- if ($c1 != $c2) return false; // different lenghts
- if ($c1 <= 0) return false; // arrays are the same and both are empty
-
- $output = array();
-
- for ($i = 0; $i < $c1; $i++) {
- $output[$a1[$i]] = $a2[$i];
- }
-
- return $output;
- }
-}
-
-/**
- * Class used for internal manipulation of multiarrays (arrays of arrays)
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 0.2.9
- */
-class NeatArray {
- /**
- * Value of NeatArray.
- *
- * @var array
- * @access public
- */
- var $value;
-
- /**
- * Constructor.
- *
- * @param array $value
- * @access public
- * @uses NeatArray::value
- */
- function NeatArray ($value) {
- $this->value = $value;
- }
-
- /**
- * Checks wheter $fieldName with $value exists in this NeatArray object.
- *
- * @param string $fieldName
- * @param string $value
- * @return mixed
- * @access public
- * @uses NeatArray::value
- */
- function findIn ($fieldName, $value) {
- $out = false;
- foreach ($this->value as $k=>$v) {
- if (isset($v[$fieldName]) && ($v[$fieldName] == $value)) {
- $out[$k] = $v;
- }
- }
-
- return $out;
- }
-
- /**
- * Checks if $this->value is array, and removes all empty elements.
- *
- * @access public
- * @uses NeatArray::value
- */
- function cleanup () {
- $out = is_array($this->value)? array(): null;
- foreach ($this->value as $k=>$v) {
- if ($v) {
- $out[$k] = $v;
- }
- }
- $this->value = $out;
- }
-}
-
-?>
+ + //
+// + 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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Basic Cake functionalities.
+ *
+ * @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
+ *
+ */
+
+/**
+ * Loads all models.
+ *
+ * @uses listModules()
+ * @uses APP
+ * @uses MODELS
+ */
+function loadModels () {
+ require (APP.'app_model.php');
+ foreach (listClasses(MODELS) as $model_fn) {
+ require (MODELS.$model_fn);
+ }
+}
+
+/**
+ * Loads all controllers.
+ *
+ * @uses APP
+ * @uses listModules()
+ * @uses HELPERS
+ * @uses CONTROLLERS
+ */
+function loadControllers () {
+ require (APP.'app_controller.php');
+
+ foreach (listClasses(HELPERS) as $helper) {
+ require (HELPERS.$helper.'.php');
+ }
+
+ foreach (listClasses(CONTROLLERS) as $controller) {
+ require (CONTROLLERS.$controller.'.php');
+ }
+}
+
+/**
+ * Loads a controller and it's helper libraries
+ *
+ * @param string $name
+ * @return boolean
+ */
+function loadController ($name) {
+ $controller_fn = CONTROLLERS.Inflector::underscore($name).'_controller.php';
+ $helper_fn = HELPERS.Inflector::underscore($name).'_helper.php';
+
+ require(APP.'app_controller.php');
+
+ if (file_exists($helper_fn))
+ require($helper_fn);
+
+ return file_exists($controller_fn)? require($controller_fn): false;
+}
+
+/**
+ * Lists PHP files in a specified directory
+ *
+ * @param string $path
+ * @return array
+ */
+function listClasses($path) {
+ $modules = new Folder($path);
+ return $modules->find('(.+)\.php');
+}
+
+/**
+ * Loads configuration files
+ */
+function config () {
+ $args = func_get_args();
+ foreach ($args as $arg) {
+ if (file_exists(CONFIGS.$arg.'.php')) {
+ require_once (CONFIGS.$arg.'.php');
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+}
+
+/**
+ * Loads component/components from LIBS.
+ *
+ * Example:
+ *
+ * uses('inflector', 'object');
+ *
+ *
+ * @uses LIBS
+ */
+function uses () {
+ $args = func_get_args();
+ foreach ($args as $arg) {
+ require_once (LIBS.strtolower($arg).'.php');
+ }
+}
+
+/**
+ * Setup a debug point.
+ *
+ * @param boolean $var
+ * @param boolean $show_html
+ */
+function debug($var = false, $show_html = false) {
+ if (DEBUG) {
+ print "\n\n";
+ if ($show_html) $var = str_replace('<', '<', str_replace('>', '>', $var));
+ print_r($var);
+ print "\n
\n";
+ }
+}
+
+
+if (!function_exists('getMicrotime')) {
+
+/**
+ * Returns microtime for execution time checking.
+ *
+ * @return integer
+ */
+ function getMicrotime() {
+ list($usec, $sec) = explode(" ", microtime());
+ return ((float)$usec + (float)$sec);
+ }
+}
+if (!function_exists('sortByKey')) {
+/**
+ * Sorts given $array by key $sortby.
+ *
+ * @param array $array
+ * @param string $sortby
+ * @param string $order
+ * @param integer $type
+ * @return mixed
+ */
+ function sortByKey(&$array, $sortby, $order='asc', $type=SORT_NUMERIC) {
+
+ if( is_array($array) ) {
+
+ foreach( $array AS $key => $val )
+ $sa[$key] = $val[$sortby];
+
+ if( $order == 'asc' )
+ asort($sa, $type);
+ else
+ arsort($sa, $type);
+
+ foreach( $sa as $key=>$val )
+ $out[] = $array[$key];
+
+ return $out;
+
+ }
+ else
+ return null;
+ }
+}
+
+if (!function_exists('array_combine')) {
+/**
+ * Combines given identical arrays by using the first array's values as keys,
+ * and second one's values as values.
+ *
+ * @param array $a1
+ * @param array $a2
+ * @return mixed Outputs either combined array or false.
+ */
+ function array_combine($a1, $a2) {
+ $a1 = array_values($a1);
+ $a2 = array_values($a2);
+ $c1 = count($a1);
+ $c2 = count($a2);
+
+ if ($c1 != $c2) return false; // different lenghts
+ if ($c1 <= 0) return false; // arrays are the same and both are empty
+
+ $output = array();
+
+ for ($i = 0; $i < $c1; $i++) {
+ $output[$a1[$i]] = $a2[$i];
+ }
+
+ return $output;
+ }
+}
+
+/**
+ * Class used for internal manipulation of multiarrays (arrays of arrays)
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ */
+class NeatArray {
+ /**
+ * Value of NeatArray.
+ *
+ * @var array
+ * @access public
+ */
+ var $value;
+
+ /**
+ * Constructor.
+ *
+ * @param array $value
+ * @access public
+ * @uses NeatArray::value
+ */
+ function NeatArray ($value) {
+ $this->value = $value;
+ }
+
+ /**
+ * Checks wheter $fieldName with $value exists in this NeatArray object.
+ *
+ * @param string $fieldName
+ * @param string $value
+ * @return mixed
+ * @access public
+ * @uses NeatArray::value
+ */
+ function findIn ($fieldName, $value) {
+ $out = false;
+ foreach ($this->value as $k=>$v) {
+ if (isset($v[$fieldName]) && ($v[$fieldName] == $value)) {
+ $out[$k] = $v;
+ }
+ }
+
+ return $out;
+ }
+
+ /**
+ * Checks if $this->value is array, and removes all empty elements.
+ *
+ * @access public
+ * @uses NeatArray::value
+ */
+ function cleanup () {
+ $out = is_array($this->value)? array(): null;
+ foreach ($this->value as $k=>$v) {
+ if ($v) {
+ $out[$k] = $v;
+ }
+ }
+ $this->value = $out;
+ }
+}
+
+?>
diff --git a/libs/cache.php b/libs/cache.php
index 3eebc2763..1ffb3d90b 100644
--- a/libs/cache.php
+++ b/libs/cache.php
@@ -39,11 +39,9 @@ uses('model');
/**
* Enter description here...
*
- *
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
- *
*/
class Cache extends Model {
diff --git a/libs/controller.php b/libs/controller.php
index 6e5801a4e..eac3a4107 100644
--- a/libs/controller.php
+++ b/libs/controller.php
@@ -1,586 +1,585 @@
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Purpose: Controller
- * Application controller (controllers are where you put all the actual code) based on RoR (www.rubyonrails.com)
- * Provides basic functionality, such as rendering views (aka displaying templates).
- * Automatically selects model name from on singularized object class name
- * and creates the model object if proper class exists.
- *
- * @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('model', 'template', 'inflector');
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 0.2.9
- *
- */
-class Controller extends Template {
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $name = null;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $parent = null;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $action = null;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $use_model = null;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access private
- */
- var $uses = false;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access private
- */
- var $_crumbs = array();
-
-/**
- * Enter description here...
- *
- */
- function __construct () {
- global $DB;
-
- $r = null;
- if (!preg_match('/(.*)Controller/i', get_class($this), $r))
- die("Controller::__construct() : Can't get or parse my own class name, exiting.");
-
- $this->name = strtolower($r[1]);
-
- $model_class = Inflector::singularize($this->name);
- if (($this->uses === false) && class_exists($model_class)) {
- if (!$DB)
- die("Controller::__construct() : ".$this->name." controller needs database access, exiting.");
-
- $this->$model_class = new $model_class ();
- }
- elseif ($this->uses) {
- if (!$DB)
- die("Controller::__construct() : ".$this->name." controller needs database access, exiting.");
-
- $uses = is_array($this->uses)? $this->uses: array($this->uses);
-
- foreach ($uses as $model_name) {
- $model_class = ucfirst(strtolower($model_name));
-
- if (class_exists($model_class)) {
- $this->$model_name = new $model_class (false);
- }
- else
- die("Controller::__construct() : ".ucfirst($this->name)." requires missing model {$model_class}, exiting.");
- }
- }
-
- parent::__construct();
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $url
- */
- function redirect ($url) {
- $this->autoRender = false;
- header ('Location: '.$this->base.$url);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $action
- */
- function setAction ($action) {
- $this->action = $action;
-
- $args = func_get_args();
- call_user_func_array(array(&$this, $action), $args);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $url
- * @return unknown
- */
- function urlFor ($url=null) {
- if (empty($url)) {
- return $this->base.'/'.strtolower($this->params['controller']).'/'.strtolower($this->params['action']);
- }
- elseif ($url[0] == '/') {
- return $this->base . $url;
- }
- else {
- return $this->base . '/' . strtolower($this->params['controller']) . '/' . $url;
- }
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $options
- * @param unknown_type $insert_before
- * @param unknown_type $insert_after
- * @return unknown
- */
- function parseHtmlOptions ($options, $insert_before=' ', $insert_after=null) {
- if (is_array($options)) {
- $out = array();
- foreach ($options as $k=>$v) {
- $out[] = "{$k}=\"{$v}\"";
- }
- $out = join(' ', $out);
- return $out? $insert_before.$out.$insert_after: null;
- }
- else {
- return $options? $insert_before.$options.$insert_after: null;
- }
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $title
- * @param unknown_type $url
- * @param unknown_type $html_options
- * @param unknown_type $confirm_message
- * @return unknown
- */
- function linkTo ($title, $url, $html_options=null, $confirm_message=false) {
- $confirm_message? $html_options['onClick'] = "return confirm('{$confirm_message}')": null;
- return sprintf(TAG_LINK, $this->UrlFor($url), $this->parseHtmlOptions($html_options), $title);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $title
- * @param unknown_type $url
- * @param unknown_type $html_options
- * @return unknown
- */
- function linkOut ($title, $url=null, $html_options=null) {
- $url = $url? $url: $title;
- return sprintf(TAG_LINK, $url, $this->parseHtmlOptions($html_options), $title);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $target
- * @param unknown_type $type
- * @param unknown_type $html_options
- * @return unknown
- */
- function formTag ($target=null, $type='post', $html_options=null) {
- $html_options['action'] = $this->UrlFor($target);
- $html_options['method'] = $type=='get'? 'get': 'post';
- $type == 'file'? $html_options['enctype'] = 'multipart/form-data': null;
-
- return sprintf(TAG_FORM, $this->parseHtmlOptions($html_options, ''));
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $caption
- * @param unknown_type $html_options
- * @return unknown
- */
- function submitTag ($caption='Submit', $html_options=null) {
- $html_options['value'] = $caption;
- return sprintf(TAG_SUBMIT, $this->parseHtmlOptions($html_options, '', ' '));
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $tag_name
- * @param unknown_type $size
- * @param unknown_type $html_options
- * @return unknown
- */
- function inputTag ($tag_name, $size=20, $html_options=null) {
- $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, '', ' '));
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $tag_name
- * @param unknown_type $size
- * @param unknown_type $html_options
- * @return unknown
- */
- 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, '', ' '));
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $tag_name
- * @param unknown_type $value
- * @param unknown_type $html_options
- * @return unknown
- */
- 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, '', ' '));
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $tag_name
- * @param unknown_type $html_options
- * @return unknown
- */
- function fileTag ($tag_name, $html_options=null) {
- return sprintf(TAG_FILE, $tag_name, $this->parseHtmlOptions($html_options, '', ' '));
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $tag_name
- * @param unknown_type $cols
- * @param unknown_type $rows
- * @param unknown_type $html_options
- * @return unknown
- */
- function areaTag ($tag_name, $cols=60, $rows=10, $html_options=null) {
- $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);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $tag_name
- * @param unknown_type $title
- * @param unknown_type $html_options
- * @return unknown
- */
- 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);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $tag_name
- * @param unknown_type $options
- * @param unknown_type $inbetween
- * @param unknown_type $html_options
- * @return unknown
- */
- function radioTags ($tag_name, $options, $inbetween=null, $html_options=null) {
- $value = isset($html_options['value'])? $html_options['value']: $this->tagValue($tag_name);
- $out = array();
- 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), '', ' ');
- $individual_tag_name = "{$tag_name}_{$opt_value}";
- $out[] = sprintf(TAG_RADIOS, $individual_tag_name, $tag_name, $individual_tag_name, $parsed_options, $opt_title);
- }
-
- $out = join($inbetween, $out);
- return $out? $out: null;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $tag_name
- * @param unknown_type $options
- * @param unknown_type $outer_options
- * @param unknown_type $inner_options
- * @return unknown
- */
- function selectTag ($tag_name, $options, $outer_options=null, $inner_options=null) {
- if (!is_array($options) || !count($options))
- return null;
- $selected = isset($html_options['value'])? $html_options['value']: $this->tagValue($tag_name);
- $select[] = sprintf(TAG_SELECT_START, $tag_name, $this->parseHtmlOptions($outer_options));
- $select[] = sprintf(TAG_SELECT_EMPTY, $this->parseHtmlOptions($inner_options));
-
- foreach ($options as $name=>$title) {
- $options_here = $selected==$name? array_merge($inner_options, array('selected'=>'selected')): $inner_options;
- $select[] = sprintf(TAG_SELECT_OPTION, $name, $this->parseHtmlOptions($options_here), $title);
- }
-
- $select[] = sprintf(TAG_SELECT_END);
-
- return implode("\n", $select);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $path
- * @param unknown_type $alt
- * @param unknown_type $html_options
- * @return unknown
- */
- function imageTag ($path, $alt=null, $html_options=null) {
- $url = "{$this->base}/images/{$path}";
- return sprintf(TAG_IMAGE, $url, $alt, $this->parseHtmlOptions($html_options, '', ' '));
- }
-
-
-/**
- * Returns a CSS link meta-tag
- *
- * @param string $path
- * @param string $rel
- * @param array $html_options
- * @return string
- */
- function cssTag ($path, $rel='stylesheet', $html_options=null) {
- $url = "{$this->base}/css/{$path}.css";
- return sprintf(TAG_CSS, $rel, $url, $this->parseHtmlOptions($html_options, '', ' '));
- }
-
-
-/**
- * Returns a charset meta-tag
- *
- * @param string $charset
- * @return string
- */
- function charsetTag ($charset) {
- return sprintf(TAG_CHARSET, $charset);
- }
-
-
-/**
- * Enter description here...
- *
- * @param unknown_type $names
- * @param unknown_type $tr_options
- * @param unknown_type $th_options
- * @return unknown
- */
- function tableHeaders ($names, $tr_options=null, $th_options=null) {
- $args = func_get_args();
-
- $out = array();
- foreach ($names as $arg)
- $out[] = sprintf(TAG_TABLE_HEADER, $this->parseHtmlOptions($th_options), $arg);
-
- return sprintf(TAG_TABLE_HEADERS, $this->parseHtmlOptions($tr_options), join(' ', $out));
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $data
- * @param unknown_type $tr_options
- * @param unknown_type $td_options
- * @return unknown
- */
- function tableCells ($data, $odd_tr_options=null, $even_tr_options=null) {
- if (empty($data[0]) || !is_array($data[0]))
- $data = array($data);
-
- $count=0;
- foreach ($data as $line) {
- $count++;
- $cells_out = array();
- foreach ($line as $cell)
- $cells_out[] = sprintf(TAG_TABLE_CELL, null, $cell);
-
- $options = $this->parseHtmlOptions($count%2? $odd_tr_options: $even_tr_options);
- $out[] = sprintf(TAG_TABLE_ROW, $options, join(' ', $cells_out));
- }
-
- return join("\n", $out);
- }
-
-
-/**
- * Enter description here...
- *
- * @param unknown_type $tag_name
- * @return unknown
- */
- function tagValue ($tag_name) {
- return isset($this->params['data'][$tag_name])? $this->params['data'][$tag_name]: false;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function validate () {
- $args = func_get_args();
- $errors = call_user_func_array(array(&$this, 'validateErrors'), $args);
-
- return count($errors);
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function validateErrors () {
- $objects = func_get_args();
- if (!count($objects)) return false;
-
- $errors = array();
- foreach ($objects as $object) {
- $errors = array_merge($errors, $object->invalidFields($object->data));
- }
-
- return $this->validationErrors = (count($errors)? $errors: false);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $field
- * @param unknown_type $text
- * @return unknown
- */
- function tagErrorMsg ($field, $text) {
- if ($error = $this->tagIsInvalid($field)) {
- return sprintf(SHORT_ERROR_MESSAGE, is_array($text)? (empty($text[$error-1])? 'Error in field': $text[$error-1]): $text);
- }
- else {
- return null;
- }
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $field
- * @return unknown
- */
- function tagIsInvalid ($field) {
- return empty($this->validationErrors[$field])? 0: $this->validationErrors[$field];
- }
-
-
-
-/**
- * Enter description here...
- *
- * @param unknown_type $name
- * @param unknown_type $link
- */
- function addCrumb ($name, $link) {
- $this->_crumbs[] = array ($name, $link);
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function getCrumbs () {
-
- if (count($this->_crumbs)) {
-
- $out = array("base}\">START");
- foreach ($this->_crumbs as $crumb) {
- $out[] = "base}{$crumb[1]}\">{$crumb[0]}";
- }
-
- return join(' » ', $out);
- }
- else
- return null;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $code
- * @param unknown_type $name
- * @param unknown_type $message
- */
- function error ($code, $name, $message) {
- header ("HTTP/1.0 {$code} {$name}");
- print ($this->_render(VIEWS.'layouts/error.thtml', array('code'=>$code,'name'=>$name,'message'=>$message)));
- }
-}
-
+ + //
+// + 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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: Controller
+ * Application controller (controllers are where you put all the actual code) based on RoR (www.rubyonrails.com)
+ * Provides basic functionality, such as rendering views (aka displaying templates).
+ * Automatically selects model name from on singularized object class name
+ * and creates the model object if proper class exists.
+ *
+ * @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('model', 'template', 'inflector');
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ *
+ */
+class Controller extends Template {
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $name = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $parent = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $action = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $use_model = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $uses = false;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_crumbs = array();
+
+/**
+ * Enter description here...
+ *
+ */
+ function __construct () {
+ global $DB;
+
+ $r = null;
+ if (!preg_match('/(.*)Controller/i', get_class($this), $r))
+ die("Controller::__construct() : Can't get or parse my own class name, exiting.");
+
+ $this->name = strtolower($r[1]);
+
+ $model_class = Inflector::singularize($this->name);
+ if (($this->uses === false) && class_exists($model_class)) {
+ if (!$DB)
+ die("Controller::__construct() : ".$this->name." controller needs database access, exiting.");
+
+ $this->$model_class = new $model_class ();
+ }
+ elseif ($this->uses) {
+ if (!$DB)
+ die("Controller::__construct() : ".$this->name." controller needs database access, exiting.");
+
+ $uses = is_array($this->uses)? $this->uses: array($this->uses);
+
+ foreach ($uses as $model_name) {
+ $model_class = ucfirst(strtolower($model_name));
+
+ if (class_exists($model_class)) {
+ $this->$model_name = new $model_class (false);
+ }
+ else
+ die("Controller::__construct() : ".ucfirst($this->name)." requires missing model {$model_class}, exiting.");
+ }
+ }
+
+ parent::__construct();
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $url
+ */
+ function redirect ($url) {
+ $this->autoRender = false;
+ header ('Location: '.$this->base.$url);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $action
+ */
+ function setAction ($action) {
+ $this->action = $action;
+
+ $args = func_get_args();
+ call_user_func_array(array(&$this, $action), $args);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $url
+ * @return unknown
+ */
+ function urlFor ($url=null) {
+ if (empty($url)) {
+ return $this->base.'/'.strtolower($this->params['controller']).'/'.strtolower($this->params['action']);
+ }
+ elseif ($url[0] == '/') {
+ return $this->base . $url;
+ }
+ else {
+ return $this->base . '/' . strtolower($this->params['controller']) . '/' . $url;
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $options
+ * @param unknown_type $insert_before
+ * @param unknown_type $insert_after
+ * @return unknown
+ */
+ function parseHtmlOptions ($options, $insert_before=' ', $insert_after=null) {
+ if (is_array($options)) {
+ $out = array();
+ foreach ($options as $k=>$v) {
+ $out[] = "{$k}=\"{$v}\"";
+ }
+ $out = join(' ', $out);
+ return $out? $insert_before.$out.$insert_after: null;
+ }
+ else {
+ return $options? $insert_before.$options.$insert_after: null;
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $title
+ * @param unknown_type $url
+ * @param unknown_type $html_options
+ * @param unknown_type $confirm_message
+ * @return unknown
+ */
+ function linkTo ($title, $url, $html_options=null, $confirm_message=false) {
+ $confirm_message? $html_options['onClick'] = "return confirm('{$confirm_message}')": null;
+ return sprintf(TAG_LINK, $this->UrlFor($url), $this->parseHtmlOptions($html_options), $title);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $title
+ * @param unknown_type $url
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function linkOut ($title, $url=null, $html_options=null) {
+ $url = $url? $url: $title;
+ return sprintf(TAG_LINK, $url, $this->parseHtmlOptions($html_options), $title);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $target
+ * @param unknown_type $type
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function formTag ($target=null, $type='post', $html_options=null) {
+ $html_options['action'] = $this->UrlFor($target);
+ $html_options['method'] = $type=='get'? 'get': 'post';
+ $type == 'file'? $html_options['enctype'] = 'multipart/form-data': null;
+
+ return sprintf(TAG_FORM, $this->parseHtmlOptions($html_options, ''));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $caption
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function submitTag ($caption='Submit', $html_options=null) {
+ $html_options['value'] = $caption;
+ return sprintf(TAG_SUBMIT, $this->parseHtmlOptions($html_options, '', ' '));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @param unknown_type $size
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function inputTag ($tag_name, $size=20, $html_options=null) {
+ $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, '', ' '));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @param unknown_type $size
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ 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, '', ' '));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @param unknown_type $value
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ 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, '', ' '));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function fileTag ($tag_name, $html_options=null) {
+ return sprintf(TAG_FILE, $tag_name, $this->parseHtmlOptions($html_options, '', ' '));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @param unknown_type $cols
+ * @param unknown_type $rows
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function areaTag ($tag_name, $cols=60, $rows=10, $html_options=null) {
+ $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);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @param unknown_type $title
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ 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);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @param unknown_type $options
+ * @param unknown_type $inbetween
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function radioTags ($tag_name, $options, $inbetween=null, $html_options=null) {
+ $value = isset($html_options['value'])? $html_options['value']: $this->tagValue($tag_name);
+ $out = array();
+ 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), '', ' ');
+ $individual_tag_name = "{$tag_name}_{$opt_value}";
+ $out[] = sprintf(TAG_RADIOS, $individual_tag_name, $tag_name, $individual_tag_name, $parsed_options, $opt_title);
+ }
+
+ $out = join($inbetween, $out);
+ return $out? $out: null;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @param unknown_type $options
+ * @param unknown_type $outer_options
+ * @param unknown_type $inner_options
+ * @return unknown
+ */
+ function selectTag ($tag_name, $options, $outer_options=null, $inner_options=null) {
+ if (!is_array($options) || !count($options))
+ return null;
+ $selected = isset($html_options['value'])? $html_options['value']: $this->tagValue($tag_name);
+ $select[] = sprintf(TAG_SELECT_START, $tag_name, $this->parseHtmlOptions($outer_options));
+ $select[] = sprintf(TAG_SELECT_EMPTY, $this->parseHtmlOptions($inner_options));
+
+ foreach ($options as $name=>$title) {
+ $options_here = $selected==$name? array_merge($inner_options, array('selected'=>'selected')): $inner_options;
+ $select[] = sprintf(TAG_SELECT_OPTION, $name, $this->parseHtmlOptions($options_here), $title);
+ }
+
+ $select[] = sprintf(TAG_SELECT_END);
+
+ return implode("\n", $select);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $path
+ * @param unknown_type $alt
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function imageTag ($path, $alt=null, $html_options=null) {
+ $url = "{$this->base}/images/{$path}";
+ return sprintf(TAG_IMAGE, $url, $alt, $this->parseHtmlOptions($html_options, '', ' '));
+ }
+
+
+/**
+ * Returns a CSS link meta-tag
+ *
+ * @param string $path
+ * @param string $rel
+ * @param array $html_options
+ * @return string
+ */
+ function cssTag ($path, $rel='stylesheet', $html_options=null) {
+ $url = "{$this->base}/css/{$path}.css";
+ return sprintf(TAG_CSS, $rel, $url, $this->parseHtmlOptions($html_options, '', ' '));
+ }
+
+
+/**
+ * Returns a charset meta-tag
+ *
+ * @param string $charset
+ * @return string
+ */
+ function charsetTag ($charset) {
+ return sprintf(TAG_CHARSET, $charset);
+ }
+
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $names
+ * @param unknown_type $tr_options
+ * @param unknown_type $th_options
+ * @return unknown
+ */
+ function tableHeaders ($names, $tr_options=null, $th_options=null) {
+ $args = func_get_args();
+
+ $out = array();
+ foreach ($names as $arg)
+ $out[] = sprintf(TAG_TABLE_HEADER, $this->parseHtmlOptions($th_options), $arg);
+
+ return sprintf(TAG_TABLE_HEADERS, $this->parseHtmlOptions($tr_options), join(' ', $out));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $data
+ * @param unknown_type $tr_options
+ * @param unknown_type $td_options
+ * @return unknown
+ */
+ function tableCells ($data, $odd_tr_options=null, $even_tr_options=null) {
+ if (empty($data[0]) || !is_array($data[0]))
+ $data = array($data);
+
+ $count=0;
+ foreach ($data as $line) {
+ $count++;
+ $cells_out = array();
+ foreach ($line as $cell)
+ $cells_out[] = sprintf(TAG_TABLE_CELL, null, $cell);
+
+ $options = $this->parseHtmlOptions($count%2? $odd_tr_options: $even_tr_options);
+ $out[] = sprintf(TAG_TABLE_ROW, $options, join(' ', $cells_out));
+ }
+
+ return join("\n", $out);
+ }
+
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @return unknown
+ */
+ function tagValue ($tag_name) {
+ return isset($this->params['data'][$tag_name])? $this->params['data'][$tag_name]: false;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function validate () {
+ $args = func_get_args();
+ $errors = call_user_func_array(array(&$this, 'validateErrors'), $args);
+
+ return count($errors);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function validateErrors () {
+ $objects = func_get_args();
+ if (!count($objects)) return false;
+
+ $errors = array();
+ foreach ($objects as $object) {
+ $errors = array_merge($errors, $object->invalidFields($object->data));
+ }
+
+ return $this->validationErrors = (count($errors)? $errors: false);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $field
+ * @param unknown_type $text
+ * @return unknown
+ */
+ function tagErrorMsg ($field, $text) {
+ if ($error = $this->tagIsInvalid($field)) {
+ return sprintf(SHORT_ERROR_MESSAGE, is_array($text)? (empty($text[$error-1])? 'Error in field': $text[$error-1]): $text);
+ }
+ else {
+ return null;
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $field
+ * @return unknown
+ */
+ function tagIsInvalid ($field) {
+ return empty($this->validationErrors[$field])? 0: $this->validationErrors[$field];
+ }
+
+
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $name
+ * @param unknown_type $link
+ */
+ function addCrumb ($name, $link) {
+ $this->_crumbs[] = array ($name, $link);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function getCrumbs () {
+
+ if (count($this->_crumbs)) {
+
+ $out = array("base}\">START");
+ foreach ($this->_crumbs as $crumb) {
+ $out[] = "base}{$crumb[1]}\">{$crumb[0]}";
+ }
+
+ return join(' » ', $out);
+ }
+ else
+ return null;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $code
+ * @param unknown_type $name
+ * @param unknown_type $message
+ */
+ function error ($code, $name, $message) {
+ header ("HTTP/1.0 {$code} {$name}");
+ print ($this->_render(VIEWS.'layouts/error.thtml', array('code'=>$code,'name'=>$name,'message'=>$message)));
+ }
+}
+
?>
\ No newline at end of file
diff --git a/libs/dbo.php b/libs/dbo.php
index 30e2f37b8..eee5aa232 100644
--- a/libs/dbo.php
+++ b/libs/dbo.php
@@ -1,411 +1,410 @@
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Purpose: DBO/ADO
- *
- * Description:
- * A MySQL functions wrapper. Provides ability to get results as arrays
- * and query logging (with execution time).
- *
- * Example usage:
- *
- *
- * require('dbo_mysql.php'); // or 'dbo_postgres.php'
- *
- * // create and connect the object
- * $db = new DBO_MySQL(array( // or 'DBO_Postgres'
- * 'host'=>'localhost',
- * 'login'=>'username',
- * 'password'=>'password',
- * 'database'=>'database'));
- *
- * // read the whole query result array (of rows)
- * $all_rows = $db->all("SELECT a,b,c FROM table");
- *
- * // read the first row with debugging on
- * $first_row_only = $db->one("SELECT a,b,c FROM table WHERE a=1", TRUE);
- *
- * // emulate the usual way of reading query results
- * if ($db->query("SELECT a,b,c FROM table")) {
- * while ( $row = $db->farr() ) {
- * print $row['a'].$row['b'].$row['c'];
- * }
- * }
- *
- * // show a log of all queries, sorted by execution time
- * $db->showLog(TRUE);
- *
- *
- * @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('object');
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 0.2.9
- *
- */
-class DBO extends Object {
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $connected=FALSE;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $debug=FALSE;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $fullDebug=FALSE;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $error=NULL;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $affected=NULL;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $numRows=NULL;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $took=NULL;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access private
- */
- var $_conn=NULL;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access private
- */
- var $_result=NULL;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access private
- */
- var $_queriesCnt=0;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access private
- */
- var $_queriesTime=NULL;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access private
- */
- var $_queriesLog=array();
-
- // 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 tables() { die('Please implement DBO::tables() first.'); }
- function fields ($table_name) { die('Please implement DBO::fields() first.'); }
- function prepare ($data) { die('Please implement DBO::prepare() first.'); }
- function lastError () { 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.'); }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $config
- * @param unknown_type $DEBUG
- * @return unknown
- */
- function __construct ($config=NULL) {
- $this->debug = DEBUG > 0;
- $this->fullDebug = DEBUG > 1;
- parent::__construct();
- return $this->connect($config);
- }
-
-/**
- * Enter description here...
- *
- */
- function __destructor () {
- $this->close();
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $db_name
- * @return unknown
- */
- function useDb ($db_name) {
- return $this->query("USE {$db_name}");
- }
-
-/**
- * Enter description here...
- *
- */
- function close () {
- if ($this->fullDebug) $this->showLog();
- $this->disconnect();
- $this->_conn = NULL;
- $this->connected = false;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $sql
- * @return unknown
- */
- function rawQuery ($sql) {
- $this->took = $this->error = $this->numRows = false;
- return $this->execute($sql);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $sql
- * @return unknown
- */
- function query($sql) {
- $t = getMicrotime();
- $this->_result = $this->execute($sql);
- $this->affected = $this->lastAffected();
- $this->took = round((getMicrotime()-$t)*1000, 0);
- $this->error = $this->lastError();
- $this->numRows = $this->lastNumRows($this->_result);
- $this->logQuery($sql);
- if (($this->debug && $this->error) || ($this->fullDebug))
- $this->showQuery($sql);
-
- return $this->error? false: $this->_result;
- }
-
-/**
- * Returns a single row of results from the _last_ query
- *
- * @param unknown_type $results
- * @param unknown_type $type
- * @return unknown
- */
- function farr ($res=false) {
- return $this->fetchRow($res? $res: $this->_result);
- }
-
-/**
- * Returns a single row of results for a _given_ query
- *
- * @param unknown_type $sql
- * @return unknown
- */
- function one ($sql) {
- return $this->query($sql)? $this->farr(): false;
- }
-
-/**
- * Returns all result rows for a given query
- *
- * @param unknown_type $sql
- * @return unknown
- */
- function all ($sql) {
- if($this->query($sql)) {
- $out=array();
- while($item = $this->farr()) $out[] = $item;
- return $out;
- }
- else {
- return false;
- }
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $name
- * @param unknown_type $sql
- * @return unknown
- */
- function field ($name, $sql) {
- $data = $this->one($sql);
- return empty($data[$name])? false: $data[$name];
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $table
- * @param unknown_type $sql
- * @return unknown
- */
- function hasAny($table, $sql) {
- $out = $this->one("SELECT COUNT(*) AS count FROM {$table}".($sql? " WHERE {$sql}":""));
- return is_array($out)? $out['count']: false;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function isConnected() {
- return $this->connected;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function prepareArray($data) {
- $out = null;
- foreach ($data as $key=>$item) {
- $out[$key] = $this->prepare($item);
- }
- return $out;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $sorted
- */
- function showLog($sorted=false) {
- $log = $sorted?
- sortByKey($this->_queriesLog, 'took', 'desc', SORT_NUMERIC):
- $this->_queriesLog;
-
- print("\n{$this->_queriesCnt} queries took {$this->_queriesTime} ms |
\n");
- print("Nr | Query | Error | Affected | Num. rows | Took (ms) |
\n");
-
- foreach($log AS $k=>$i) {
- print("".($k+1)." | {$i['query']} | {$i['error']} | {$i['affected']} | {$i['numRows']} | {$i['took']} |
\n");
- }
-
- print("
\n");
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $q
- */
- function logQuery($sql) {
- $this->_queriesCnt++;
- $this->_queriesTime += $this->took;
- $this->_queriesLog[] = array(
- 'query'=>$sql,
- 'error'=>$this->error,
- 'affected'=>$this->affected,
- 'numRows'=>$this->numRows,
- 'took'=>$this->took
- );
-
- if ($this->error)
- false; // shouldn't we be logging errors somehow?
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $q
- */
- function showQuery($sql) {
- $error = $this->error;
-
- if (strlen($sql)>200 && !$this->fullDebug)
- $sql = substr($sql, 0, 200) .'[...]';
-
- if ($this->debug || $error) {
- print("Query: {$sql} [Aff:{$this->affected} Num:{$this->numRows} Took:{$this->took}ms]");
- if($error) {
- print("
ERROR: {$this->error}");
- }
- print('
');
- }
- }
-}
-
+ + //
+// + 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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: DBO/ADO
+ *
+ * Description:
+ * A MySQL functions wrapper. Provides ability to get results as arrays
+ * and query logging (with execution time).
+ *
+ * Example usage:
+ *
+ *
+ * require('dbo_mysql.php'); // or 'dbo_postgres.php'
+ *
+ * // create and connect the object
+ * $db = new DBO_MySQL(array( // or 'DBO_Postgres'
+ * 'host'=>'localhost',
+ * 'login'=>'username',
+ * 'password'=>'password',
+ * 'database'=>'database'));
+ *
+ * // read the whole query result array (of rows)
+ * $all_rows = $db->all("SELECT a,b,c FROM table");
+ *
+ * // read the first row with debugging on
+ * $first_row_only = $db->one("SELECT a,b,c FROM table WHERE a=1", TRUE);
+ *
+ * // emulate the usual way of reading query results
+ * if ($db->query("SELECT a,b,c FROM table")) {
+ * while ( $row = $db->farr() ) {
+ * print $row['a'].$row['b'].$row['c'];
+ * }
+ * }
+ *
+ * // show a log of all queries, sorted by execution time
+ * $db->showLog(TRUE);
+ *
+ *
+ * @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('object');
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ *
+ */
+class DBO extends Object {
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $connected=FALSE;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $debug=FALSE;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $fullDebug=FALSE;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $error=NULL;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $affected=NULL;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $numRows=NULL;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $took=NULL;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_conn=NULL;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_result=NULL;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_queriesCnt=0;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_queriesTime=NULL;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_queriesLog=array();
+
+ // 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 tables() { die('Please implement DBO::tables() first.'); }
+ function fields ($table_name) { die('Please implement DBO::fields() first.'); }
+ function prepare ($data) { die('Please implement DBO::prepare() first.'); }
+ function lastError () { 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.'); }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $config
+ * @param unknown_type $DEBUG
+ * @return unknown
+ */
+ function __construct ($config=NULL) {
+ $this->debug = DEBUG > 0;
+ $this->fullDebug = DEBUG > 1;
+ parent::__construct();
+ return $this->connect($config);
+ }
+
+/**
+ * Enter description here...
+ *
+ */
+ function __destructor () {
+ $this->close();
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $db_name
+ * @return unknown
+ */
+ function useDb ($db_name) {
+ return $this->query("USE {$db_name}");
+ }
+
+/**
+ * Enter description here...
+ *
+ */
+ function close () {
+ if ($this->fullDebug) $this->showLog();
+ $this->disconnect();
+ $this->_conn = NULL;
+ $this->connected = false;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $sql
+ * @return unknown
+ */
+ function rawQuery ($sql) {
+ $this->took = $this->error = $this->numRows = false;
+ return $this->execute($sql);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $sql
+ * @return unknown
+ */
+ function query($sql) {
+ $t = getMicrotime();
+ $this->_result = $this->execute($sql);
+ $this->affected = $this->lastAffected();
+ $this->took = round((getMicrotime()-$t)*1000, 0);
+ $this->error = $this->lastError();
+ $this->numRows = $this->lastNumRows($this->_result);
+ $this->logQuery($sql);
+ if (($this->debug && $this->error) || ($this->fullDebug))
+ $this->showQuery($sql);
+
+ return $this->error? false: $this->_result;
+ }
+
+/**
+ * Returns a single row of results from the _last_ query
+ *
+ * @param resource $res
+ * @return unknown
+ */
+ function farr ($res=false) {
+ return $this->fetchRow($res? $res: $this->_result);
+ }
+
+/**
+ * Returns a single row of results for a _given_ query
+ *
+ * @param unknown_type $sql
+ * @return unknown
+ */
+ function one ($sql) {
+ return $this->query($sql)? $this->farr(): false;
+ }
+
+/**
+ * Returns all result rows for a given query
+ *
+ * @param unknown_type $sql
+ * @return unknown
+ */
+ function all ($sql) {
+ if($this->query($sql)) {
+ $out=array();
+ while($item = $this->farr()) $out[] = $item;
+ return $out;
+ }
+ else {
+ return false;
+ }
+ }
+
+/**
+ * Returns a single field of the first of query results for a given sql query
+ *
+ * @param unknown_type $name
+ * @param unknown_type $sql
+ * @return unknown
+ */
+ function field ($name, $sql) {
+ $data = $this->one($sql);
+ return empty($data[$name])? false: $data[$name];
+ }
+
+/**
+ * Checks if the specified table contains any record matching specified SQL
+ *
+ * @param unknown_type $table
+ * @param unknown_type $sql
+ * @return unknown
+ */
+ function hasAny($table, $sql) {
+ $out = $this->one("SELECT COUNT(*) AS count FROM {$table}".($sql? " WHERE {$sql}":""));
+ return is_array($out)? $out['count']: false;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function isConnected() {
+ return $this->connected;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function prepareArray($data) {
+ $out = null;
+ foreach ($data as $key=>$item) {
+ $out[$key] = $this->prepare($item);
+ }
+ return $out;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $sorted
+ */
+ function showLog($sorted=false) {
+ $log = $sorted?
+ sortByKey($this->_queriesLog, 'took', 'desc', SORT_NUMERIC):
+ $this->_queriesLog;
+
+ print("\n{$this->_queriesCnt} queries took {$this->_queriesTime} ms |
\n");
+ print("Nr | Query | Error | Affected | Num. rows | Took (ms) |
\n");
+
+ foreach($log AS $k=>$i) {
+ print("".($k+1)." | {$i['query']} | {$i['error']} | {$i['affected']} | {$i['numRows']} | {$i['took']} |
\n");
+ }
+
+ print("
\n");
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $q
+ */
+ function logQuery($sql) {
+ $this->_queriesCnt++;
+ $this->_queriesTime += $this->took;
+ $this->_queriesLog[] = array(
+ 'query'=>$sql,
+ 'error'=>$this->error,
+ 'affected'=>$this->affected,
+ 'numRows'=>$this->numRows,
+ 'took'=>$this->took
+ );
+
+ if ($this->error)
+ false; // shouldn't we be logging errors somehow?
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $q
+ */
+ function showQuery($sql) {
+ $error = $this->error;
+
+ if (strlen($sql)>200 && !$this->fullDebug)
+ $sql = substr($sql, 0, 200) .'[...]';
+
+ if ($this->debug || $error) {
+ print("Query: {$sql} [Aff:{$this->affected} Num:{$this->numRows} Took:{$this->took}ms]");
+ if($error) {
+ print("
ERROR: {$this->error}");
+ }
+ print('
');
+ }
+ }
+}
+
?>
\ No newline at end of file
diff --git a/libs/dbo_adodb.php b/libs/dbo_adodb.php
index e4df82ac4..1ec323564 100644
--- a/libs/dbo_adodb.php
+++ b/libs/dbo_adodb.php
@@ -1,170 +1,170 @@
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Purpose: DBO_AdoDB
- * 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
- */
-
-/**
- * Enter description here...
- *
- */
-require_once(VENDORS.'adodb/adodb.inc.php');
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 0.2.9
- *
- */
-class DBO_AdoDB extends DBO {
-
-/**
- * Enter description here...
- *
- * @param unknown_type $config
- */
- 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.');
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function disconnect () {
- return $this->_adodb->close();
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $sql
- * @return unknown
- */
- function execute ($sql) {
- return $this->_adodb->execute($sql);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $res
- * @return unknown
- */
- function fetchRow ($res) {
- return $res->FetchRow();
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function tables() {
- $tables = $this->_adodb->MetaTables('TABLES');
-
- if (!sizeof($tables)>0) {
- trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
- exit;
- }
- return $tables;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $table_name
- * @return unknown
- */
- 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;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $data
- */
- function prepare ($data) { die('Please implement DBO::prepare() first.'); }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function lastError () {
- return $this->_adodb->ErrorMsg();
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function lastAffected () {
- return $this->_adodb->Affected_Rows();
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function lastNumRows () {
- return $this->_result? $this->_result->RecordCount(): false;
- }
-
-/**
- * Enter description here...
- *
- */
- 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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: DBO_AdoDB
+ * 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
+ */
+
+/**
+ * Enter description here...
+ *
+ */
+require_once(VENDORS.'adodb/adodb.inc.php');
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ *
+ */
+class DBO_AdoDB extends DBO {
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $config
+ */
+ 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.');
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function disconnect () {
+ return $this->_adodb->close();
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $sql
+ * @return unknown
+ */
+ function execute ($sql) {
+ return $this->_adodb->execute($sql);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $res
+ * @return unknown
+ */
+ function fetchRow ($res) {
+ return $res->FetchRow();
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function tables() {
+ $tables = $this->_adodb->MetaTables('TABLES');
+
+ if (!sizeof($tables)>0) {
+ trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
+ exit;
+ }
+ return $tables;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $table_name
+ * @return unknown
+ */
+ 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;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $data
+ */
+ function prepare ($data) { die('Please implement DBO::prepare() first.'); }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function lastError () {
+ return $this->_adodb->ErrorMsg();
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function lastAffected () {
+ return $this->_adodb->Affected_Rows();
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function lastNumRows () {
+ return $this->_result? $this->_result->RecordCount(): false;
+ }
+
+/**
+ * Enter description here...
+ *
+ */
+ function lastInsertId () { die('Please implement DBO::lastInsertId() first.'); }
+}
+
?>
\ No newline at end of file
diff --git a/libs/dbo_factory.php b/libs/dbo_factory.php
index 210087367..ce7bca60b 100644
--- a/libs/dbo_factory.php
+++ b/libs/dbo_factory.php
@@ -45,6 +45,8 @@ uses('object');
class DboFactory extends Object {
function make ($activeConfig) {
+ if (!class_exists('DATABASE_CONFIG')) return false;
+
$config = DATABASE_CONFIG::$activeConfig();
// special case for AdoDB -- driver name in the form of 'adodb_drivername'
diff --git a/libs/dbo_mysql.php b/libs/dbo_mysql.php
index 9ec98bb27..90fcb37b1 100644
--- a/libs/dbo_mysql.php
+++ b/libs/dbo_mysql.php
@@ -1,189 +1,189 @@
- + //
-// + 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 + //
-// +------------------------------------------------------------------+ //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Purpose: DBO_MySQL
- * 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
- */
-
-/**
- * Enter description here...
- *
- */
-
-uses('object', 'dbo');
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 0.2.9
- *
- */
-class DBO_MySQL extends DBO {
-
-/**
- * Enter description here...
- *
- * @param unknown_type $config
- * @return unknown
- */
- 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.');
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function disconnect () {
- return mysql_close();
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $sql
- * @return unknown
- */
- function execute ($sql) {
- return mysql_query($sql);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $res
- * @return unknown
- */
- function fetchRow ($res) {
- return mysql_fetch_array($res);
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function tables () {
- $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;
- }
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $table_name
- * @return unknown
- */
- 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;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $data
- * @return unknown
- */
- function prepare ($data) {
- return "'".mysql_real_escape_string($data)."'";
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function lastError () {
- return mysql_errno()? mysql_errno().': '.mysql_error(): null;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function lastAffected () {
- return $this->_result? mysql_affected_rows(): false;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function lastNumRows () {
- return $this->_result? @mysql_num_rows($this->_result): false;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- 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 + //
+// +------------------------------------------------------------------+ //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: DBO_MySQL
+ * 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
+ */
+
+/**
+ * Enter description here...
+ *
+ */
+
+uses('object', 'dbo');
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ *
+ */
+class DBO_MySQL extends DBO {
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $config
+ * @return unknown
+ */
+ 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.');
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function disconnect () {
+ return mysql_close();
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $sql
+ * @return unknown
+ */
+ function execute ($sql) {
+ return mysql_query($sql);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $res
+ * @return unknown
+ */
+ function fetchRow ($res) {
+ return mysql_fetch_array($res);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function tables () {
+ $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;
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $table_name
+ * @return unknown
+ */
+ 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;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $data
+ * @return unknown
+ */
+ function prepare ($data) {
+ return "'".mysql_real_escape_string($data)."'";
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function lastError () {
+ return mysql_errno()? mysql_errno().': '.mysql_error(): null;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function lastAffected () {
+ return $this->_result? mysql_affected_rows(): false;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function lastNumRows () {
+ return $this->_result? @mysql_num_rows($this->_result): false;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function lastInsertId() {
+ Return mysql_insert_id();
+ }
+
+}
+
?>
\ No newline at end of file
diff --git a/libs/dbo_postgres.php b/libs/dbo_postgres.php
index d3e1220e5..c1618c931 100644
--- a/libs/dbo_postgres.php
+++ b/libs/dbo_postgres.php
@@ -1,195 +1,195 @@
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Purpose: DBO_Postgres
- * Enter description here...
- *
- * @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
- */
-
-/**
- * Enter description here...
- *
- */
-
-uses('object', 'dbo');
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 1.0.0.114
- *
- */
-class DBO_Postgres extends DBO {
-
-/**
- * Enter description here...
- *
- * @param unknown_type $config
- * @return unknown
- */
- 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.');
-
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function disconnect () {
- return pg_close($this->_conn);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $sql
- * @return unknown
- */
- function execute ($sql) {
- return pg_query($this->_conn, $sql);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $res
- * @return unknown
- */
- function fetchRow ($res) {
- return pg_fetch_array($res);
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function 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) {
- $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;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $data
- * @return unknown
- */
- function prepare ($data) {
- return "'".str_replace('"', '\"', str_replace('$', '$', $data))."'";
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function lastError () {
- return pg_last_error()? pg_last_error(): null;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function lastAffected () {
- return $this->_result? pg_affected_rows($this->_result): false;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function lastNumRows () {
- return $this->_result? pg_num_rows($this->_result): false;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $table
- * @param unknown_type $field
- * @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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: DBO_Postgres
+ * Enter description here...
+ *
+ * @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
+ */
+
+/**
+ * Enter description here...
+ *
+ */
+
+uses('object', 'dbo');
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 1.0.0.114
+ *
+ */
+class DBO_Postgres extends DBO {
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $config
+ * @return unknown
+ */
+ 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.');
+
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function disconnect () {
+ return pg_close($this->_conn);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $sql
+ * @return unknown
+ */
+ function execute ($sql) {
+ return pg_query($this->_conn, $sql);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $res
+ * @return unknown
+ */
+ function fetchRow ($res) {
+ return pg_fetch_array($res);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function 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) {
+ $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;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $data
+ * @return unknown
+ */
+ function prepare ($data) {
+ return "'".str_replace('"', '\"', str_replace('$', '$', $data))."'";
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function lastError () {
+ return pg_last_error()? pg_last_error(): null;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function lastAffected () {
+ return $this->_result? pg_affected_rows($this->_result): false;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function lastNumRows () {
+ return $this->_result? pg_num_rows($this->_result): false;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $table
+ * @param unknown_type $field
+ * @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/dispatcher.php b/libs/dispatcher.php
index 82662ba8c..73e523c9f 100644
--- a/libs/dispatcher.php
+++ b/libs/dispatcher.php
@@ -1,247 +1,247 @@
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Purpose: Dispatcher
- * Dispatches the request, creating aproppriate models and controllers.
- *
- * @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
- */
-
-/**
- * Description:
- * Dispatches the request, creating aproppriate models and controllers.
- */
-
-uses('error_messages', 'object', 'router', 'cache', 'controller');
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 0.2.9
- *
- */
-class Dispatcher extends Object {
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $base = false;
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $passed_args = array();
-
-/**
- * Enter description here...
- *
- */
- function __construct () {
- $this->base = $this->baseUrl();
- parent::__construct();
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $url
- * @return unknown
- */
- function dispatch ($url) {
- global $_POST, $_GET, $_FILES, $_SESSION;
-
- $params = $this->parseParams($url);
-
- // die if no controller set
- if (empty($params['controller']))
- $this->errorNoController($url);
-
- $ctrl_name = ucfirst($params['controller']);
- $ctrl_class = $ctrl_name.'Controller';
-
- // if specified controller class doesn't exist
- if (!loadController($ctrl_name) || !class_exists($ctrl_class))
- $this->errorUnknownController($url, $ctrl_name);
-
- $controller = new $ctrl_class ($this);
- $controller->cache = &$Cache;
- $controller->base = $this->base;
-
- // if action is not set, and the default Controller::index() method doesn't exist
- if (empty($params['action'])) {
- if (method_exists($controller, 'index'))
- $params['action'] = 'index';
- else
- $this->errorNoAction($url);
- }
-
- // if the requested action doesn't exist
- if (!method_exists($controller, $params['action']))
- $this->errorUnknownAction($url, $ctrl_class, $params['action']);
-
- $controller->params = $params;
- $controller->action = $params['action'];
- $controller->data = empty($params['data'])? null: $params['data'];
- $controller->passed_args = empty($params['pass'])? null: $params['pass'];
-
- // EXECUTE THE REQUESTED ACTION
- call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']);
-
- if ($controller->autoRender)
- $controller->render();
-
- return $params;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $from_url
- * @return unknown
- */
- function parseParams ($from_url) {
- global $_POST, $_FILES;
-
- // load routes config
- $Route = new Router();
- require CONFIGS.'routes.php';
- $params = $Route->parse ('/'.$from_url);
-
- // add submitted form data
- $params['form'] = $_POST;
- if (isset($_POST['data']))
- $params['data'] = $_POST['data'];
-
- foreach ($_FILES as $name => $data)
- $params['form'][$name] = $data;
-
- return $params;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function baseUrl () {
- global $_SERVER;
-
- //non mod_rewrite use:
- if (defined('BASE_URL')) return BASE_URL;
-
- $doc_root = $_SERVER['DOCUMENT_ROOT'];
- $script_name = $_SERVER['PHP_SELF'];
-
- // if document root ends with 'public', it's probably correctly set
- $r = null;
- if (!ereg('/^.*/public(\/)?$/', $doc_root))
- return preg_match('/^(.*)\/public\/dispatch\.php$/', $script_name, $r)? $r[1]: false;
- // document root is probably not set to Cake 'public' dir
- else
- return preg_match('/^(.*)\/dispatch\.php$/', $script_name, $r)? $r[1]: false;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $code
- * @param unknown_type $name
- * @param unknown_type $message
- */
- function error ($code, $name, $message) {
- $controller = new Controller ($this);
- $controller->base = $this->base;
- $controller->error($code, $name, $message);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $url
- * @param unknown_type $message
- */
- function error404 ($url, $message) {
- $this->error('404', 'Not found', sprintf(ERROR_404, $url, $message));
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $url
- */
- function errorNoController ($url) {
- DEBUG?
- trigger_error (ERROR_NO_CONTROLLER_SET, E_USER_ERROR):
- $this->error404($url, "no controller set");
- exit;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $url
- * @param unknown_type $controller_class
- */
- function errorUnknownController ($url, $controller_class) {
- DEBUG?
- trigger_error (sprintf(ERROR_UNKNOWN_CONTROLLER, $controller_class), E_USER_ERROR):
- $this->error404($url, "missing controller \"{$controller_class}\"");
- exit;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $url
- */
- function errorNoAction ($url) {
- DEBUG?
- trigger_error (ERROR_NO_ACTION_SET, E_USER_ERROR):
- $this->error404(sprintf(ERROR_404, $url, "no action set"));
- exit;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $url
- * @param unknown_type $controller_class
- * @param unknown_type $action
- */
- function errorUnknownAction ($url,$controller_class, $action) {
- DEBUG?
- trigger_error (sprintf(ERROR_NO_ACTION, $action, $controller_class), E_USER_ERROR):
- $this->error404($url, "missing controller \"{$controller_class}\"");
- exit;
- }
-}
-
+ + //
+// + 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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: Dispatcher
+ * Dispatches the request, creating aproppriate models and controllers.
+ *
+ * @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
+ */
+
+/**
+ * Description:
+ * Dispatches the request, creating aproppriate models and controllers.
+ */
+
+uses('error_messages', 'object', 'router', 'controller');
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ *
+ */
+class Dispatcher extends Object {
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $base = false;
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $passed_args = array();
+
+/**
+ * Enter description here...
+ *
+ */
+ function __construct () {
+ $this->base = $this->baseUrl();
+ parent::__construct();
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $url
+ * @return unknown
+ */
+ function dispatch ($url) {
+ global $_POST, $_GET, $_FILES, $_SESSION;
+
+ $params = $this->parseParams($url);
+
+ // die if no controller set
+ if (empty($params['controller']))
+ $this->errorNoController($url);
+
+ $ctrl_name = ucfirst($params['controller']);
+ $ctrl_class = $ctrl_name.'Controller';
+
+ // if specified controller class doesn't exist
+ if (!loadController($ctrl_name) || !class_exists($ctrl_class))
+ $this->errorUnknownController($url, $ctrl_name);
+
+ $controller = new $ctrl_class ($this);
+ $controller->cache = &$Cache;
+ $controller->base = $this->base;
+
+ // if action is not set, and the default Controller::index() method doesn't exist
+ if (empty($params['action'])) {
+ if (method_exists($controller, 'index'))
+ $params['action'] = 'index';
+ else
+ $this->errorNoAction($url);
+ }
+
+ // if the requested action doesn't exist
+ if (!method_exists($controller, $params['action']))
+ $this->errorUnknownAction($url, $ctrl_class, $params['action']);
+
+ $controller->params = $params;
+ $controller->action = $params['action'];
+ $controller->data = empty($params['data'])? null: $params['data'];
+ $controller->passed_args = empty($params['pass'])? null: $params['pass'];
+
+ // EXECUTE THE REQUESTED ACTION
+ call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']);
+
+ if ($controller->autoRender)
+ $controller->render();
+
+ return $params;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $from_url
+ * @return unknown
+ */
+ function parseParams ($from_url) {
+ global $_POST, $_FILES;
+
+ // load routes config
+ $Route = new Router();
+ require CONFIGS.'routes.php';
+ $params = $Route->parse ('/'.$from_url);
+
+ // add submitted form data
+ $params['form'] = $_POST;
+ if (isset($_POST['data']))
+ $params['data'] = $_POST['data'];
+
+ foreach ($_FILES as $name => $data)
+ $params['form'][$name] = $data;
+
+ return $params;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function baseUrl () {
+ global $_SERVER;
+
+ //non mod_rewrite use:
+ if (defined('BASE_URL')) return BASE_URL;
+
+ $doc_root = $_SERVER['DOCUMENT_ROOT'];
+ $script_name = $_SERVER['PHP_SELF'];
+
+ // if document root ends with 'public', it's probably correctly set
+ $r = null;
+ if (!ereg('/^.*/public(\/)?$/', $doc_root))
+ return preg_match('/^(.*)\/public\/index\.php$/', $script_name, $r)? $r[1]: false;
+ // document root is probably not set to Cake 'public' dir
+ else
+ return preg_match('/^(.*)\/index\.php$/', $script_name, $r)? $r[1]: false;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $code
+ * @param unknown_type $name
+ * @param unknown_type $message
+ */
+ function error ($code, $name, $message) {
+ $controller = new Controller ($this);
+ $controller->base = $this->base;
+ $controller->error($code, $name, $message);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $url
+ * @param unknown_type $message
+ */
+ function error404 ($url, $message) {
+ $this->error('404', 'Not found', sprintf(ERROR_404, $url, $message));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $url
+ */
+ function errorNoController ($url) {
+ DEBUG?
+ trigger_error (ERROR_NO_CONTROLLER_SET, E_USER_ERROR):
+ $this->error404($url, "no controller set");
+ exit;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $url
+ * @param unknown_type $controller_class
+ */
+ function errorUnknownController ($url, $controller_class) {
+ DEBUG?
+ trigger_error (sprintf(ERROR_UNKNOWN_CONTROLLER, $controller_class), E_USER_ERROR):
+ $this->error404($url, "missing controller \"{$controller_class}\"");
+ exit;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $url
+ */
+ function errorNoAction ($url) {
+ DEBUG?
+ trigger_error (ERROR_NO_ACTION_SET, E_USER_ERROR):
+ $this->error404(sprintf(ERROR_404, $url, "no action set"));
+ exit;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $url
+ * @param unknown_type $controller_class
+ * @param unknown_type $action
+ */
+ function errorUnknownAction ($url,$controller_class, $action) {
+ DEBUG?
+ trigger_error (sprintf(ERROR_NO_ACTION, $action, $controller_class), E_USER_ERROR):
+ $this->error404($url, "missing controller \"{$controller_class}\"");
+ exit;
+ }
+}
+
?>
\ No newline at end of file
diff --git a/libs/error_messages.php b/libs/error_messages.php
index 5f89635fd..e623e1ee5 100644
--- a/libs/error_messages.php
+++ b/libs/error_messages.php
@@ -1,122 +1,122 @@
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Purpose: Error Messages Defines
- *
- * @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...
- *
- */
-define ('ERROR_UNKNOWN_DATABASE_DRIVER', '[DbFactory] Specified database driver (%s) not found');
-
-/**
- * Enter description here...
- *
- */
-define ('ERROR_NO_CONTROLLER_SET', '[Dispatcher] No default controller, can\'t continue, check routes config');
-
-/**
- * Enter description here...
- *
- */
-define ('ERROR_UNKNOWN_CONTROLLER', '[Dispatcher] Specified controller "%s" doesn\'t exist, create it first');
-
-/**
- * Enter description here...
- *
- */
-define ('ERROR_NO_ACTION', '[Dispatcher] Action "%s" is not defined in the "%s" controller, create it first');
-
-/**
- * Enter description here...
- *
- */
-define ('ERROR_IN_VIEW', '[Controller] Error in view "%s", got: %s
');
-
-/**
- * Enter description here...
- *
- */
-define ('ERROR_NO_VIEW', '[Controller] No template file for view "%s" (expected "%s"), create it first');
-
-/**
- * Enter description here...
- *
- */
-define ('ERROR_IN_LAYOUT', '[Controller] Error in layout "%s", got: "%s"
');
-
-/**
- * Enter description here...
- *
- */
-define ('ERROR_NO_LAYOUT', '[Controller] Couln\'t find layout "%s" (expected "%s"), create it first');
-
-/**
- * Enter description here...
- *
- */
-define ('ERROR_NO_TABLE_LIST', '[Database] Couldn\'t get table list, check database config');
-
-/**
- * Enter description here...
- *
- */
-define ('ERROR_NO_MODEL_TABLE', '[Model] No DB table for model "%s" (expected "%s"), create it first');
-
-/**
- * Enter description here...
- *
- */
-define ('ERROR_NO_FIELD_IN_MODEL_DB', '[Model::set()] Field "%s" is not present in table "%s", check database schema');
-
-/**
- * Enter description here...
- *
- */
-define ('SHORT_ERROR_MESSAGE', '%s
');
-
-/**
- * Enter description here...
- *
- */
-define ('ERROR_CANT_GET_ORIGINAL_IMAGE', '[Image] Couln\'t load original image %s (tried from "%s")');
-
-/**
- * Enter description here...
- *
- */
-define ('ERROR_404', "The requested address /%s was not found on this server."); // second %s contains short error message
-
-/**
- * Enter description here...
- *
- */
-define ('ERROR_500', "Application error, sorry.");
-
+ + //
+// + 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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: Error Messages Defines
+ *
+ * @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...
+ *
+ */
+define ('ERROR_UNKNOWN_DATABASE_DRIVER', '[DbFactory] Specified database driver (%s) not found');
+
+/**
+ * Enter description here...
+ *
+ */
+define ('ERROR_NO_CONTROLLER_SET', '[Dispatcher] No default controller, can\'t continue, check routes config');
+
+/**
+ * Enter description here...
+ *
+ */
+define ('ERROR_UNKNOWN_CONTROLLER', '[Dispatcher] Specified controller "%s" doesn\'t exist, create it first');
+
+/**
+ * Enter description here...
+ *
+ */
+define ('ERROR_NO_ACTION', '[Dispatcher] Action "%s" is not defined in the "%s" controller, create it first');
+
+/**
+ * Enter description here...
+ *
+ */
+define ('ERROR_IN_VIEW', '[Controller] Error in view "%s", got: %s
');
+
+/**
+ * Enter description here...
+ *
+ */
+define ('ERROR_NO_VIEW', '[Controller] No template file for view "%s" (expected "%s"), create it first');
+
+/**
+ * Enter description here...
+ *
+ */
+define ('ERROR_IN_LAYOUT', '[Controller] Error in layout "%s", got: "%s"
');
+
+/**
+ * Enter description here...
+ *
+ */
+define ('ERROR_NO_LAYOUT', '[Controller] Couln\'t find layout "%s" (expected "%s"), create it first');
+
+/**
+ * Enter description here...
+ *
+ */
+define ('ERROR_NO_TABLE_LIST', '[Database] Couldn\'t get table list, check database config');
+
+/**
+ * Enter description here...
+ *
+ */
+define ('ERROR_NO_MODEL_TABLE', '[Model] No DB table for model "%s" (expected "%s"), create it first');
+
+/**
+ * Enter description here...
+ *
+ */
+define ('ERROR_NO_FIELD_IN_MODEL_DB', '[Model::set()] Field "%s" is not present in table "%s", check database schema');
+
+/**
+ * Enter description here...
+ *
+ */
+define ('SHORT_ERROR_MESSAGE', '%s
');
+
+/**
+ * Enter description here...
+ *
+ */
+define ('ERROR_CANT_GET_ORIGINAL_IMAGE', '[Image] Couln\'t load original image %s (tried from "%s")');
+
+/**
+ * Enter description here...
+ *
+ */
+define ('ERROR_404', "The requested address /%s was not found on this server."); // second %s contains short error message
+
+/**
+ * Enter description here...
+ *
+ */
+define ('ERROR_500', "Application error, sorry.");
+
?>
\ No newline at end of file
diff --git a/libs/flay.php b/libs/flay.php
index 89c2c0896..706ba7f95 100644
--- a/libs/flay.php
+++ b/libs/flay.php
@@ -1,175 +1,175 @@
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Purpose: Flay
- * Text-to-html parser, similar to Textile or RedCloth, only with somehow different syntax.
- * See Flay::test() for examples.
- * Test with $flay = new Flay(); $flay->test();
- *
- * @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('object');
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 0.2.9
- *
- */
-class Flay extends Object {
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $text = null;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $allow_html = false;
-
-/**
- * Enter description here...
- *
- * @param unknown_type $text
- */
- function __construct ($text=null) {
- $this->text = $text;
- parent::__construct();
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $text
- * @return unknown
- */
- function toHtml ($text=null) {
- $text = $text? $text: $this->text;
-
- // trim whitespace and disable all HTML
- $text = str_replace('<', '<', str_replace('>', '>', trim($text)));
-
- // multi-paragraph functions
- $text = preg_replace('#(?:[\n]{0,2})"""(.*)"""(?:[\n]{0,2})#s', "\n\n%BLOCKQUOTE%\n\n\\1\n\n%ENDBLOCKQUOTE%\n\n", $text);
- $text = preg_replace('#(?:[\n]{0,2})===(.*)===(?:[\n]{0,2})#s', "\n\n%CENTER%\n\n\\1\n\n%ENDCENTER%\n\n", $text);
-
- // pre-parse newlines
- $text = preg_replace("#\r\n#", "\n", $text);
- $text = preg_replace("#[\n]{2,}#", "%PARAGRAPH%", $text);
- $text = preg_replace('#[\n]{1}#', "%LINEBREAK%", $text);
-
- // split into paragraphs and parse
- $out = '';
- foreach (split('%PARAGRAPH%', $text) as $line) {
-
- if ($line) {
-
- // pre-parse links
- $links = array();
- $regs = null;
- if (preg_match_all('#\[([^\[]{4,})\]#', $line, $regs)) {
- foreach ($regs[1] as $reg) {
- $links[] = $reg;
- $line = str_replace("[{$reg}]",'%LINK'.(count($links)-1).'%', $line);
- }
- }
-
- // MAIN TEXT FUNCTIONS
- // bold
- $line = ereg_replace("\*([^\*]*)\*", "\\1", $line);
- // italic
- $line = ereg_replace("_([^_]*)_", "\\1", $line);
- // entities
- $line = str_replace(' - ', ' – ', $line);
- $line = str_replace(' -- ', ' — ', $line);
- $line = str_replace('(C)', '©', $line);
- $line = str_replace('(R)', '®', $line);
- $line = str_replace('(TM)', '™', $line);
-
- // guess e-mails
- $emails = null;
- if (preg_match_all("#([_A-Za-z0-9+-+]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#", $line, $emails)) {
- foreach ($emails[1] as $email) {
- $line = str_replace($email, "{$email}", $line);
- }
- }
- // guess links
- $urls = null;
- if (preg_match_all("#((?:http|https|ftp|nntp)://[^ ]+)#", $line, $urls)) {
- foreach ($urls[1] as $url) {
- $line = str_replace($url, "{$url}", $line);
- }
- }
- if (preg_match_all("#(www\.[^ ]+)#", $line, $urls)) {
- foreach ($urls[1] as $url) {
- $line = str_replace($url, "{$url}", $line);
- }
- }
-
-
- // re-parse links
- if (count($links)) {
- for ($ii=0; $ii";
- elseif (preg_match('#^([^\]\ ]+)(?: ([^\]]+))?$#', $links[$ii], $regs))
- $with = "".(isset($regs[2])? $regs[2]: $regs[1])."";
- else
- $with = $links[$ii];
-
- $line = str_replace("%LINK{$ii}%", $with, $line);
- }
- }
-
- // re-parse newlines
- $out .= str_replace('%LINEBREAK%', "
\n", "{$line}
\n");
- }
- }
-
- // re-parse multilines
- $out = str_replace('%BLOCKQUOTE%
', "", $out);
- $out = str_replace('%ENDBLOCKQUOTE%
', "
", $out);
- $out = str_replace('%CENTER%
', "", $out);
- $out = str_replace('%ENDCENTER%
', "", $out);
-
- return $out;
- }
-}
-
+ + //
+// + 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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: Flay
+ * Text-to-html parser, similar to Textile or RedCloth, only with somehow different syntax.
+ * See Flay::test() for examples.
+ * Test with $flay = new Flay(); $flay->test();
+ *
+ * @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('object');
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ *
+ */
+class Flay extends Object {
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $text = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $allow_html = false;
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $text
+ */
+ function __construct ($text=null) {
+ $this->text = $text;
+ parent::__construct();
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $text
+ * @return unknown
+ */
+ function toHtml ($text=null) {
+ $text = $text? $text: $this->text;
+
+ // trim whitespace and disable all HTML
+ $text = str_replace('<', '<', str_replace('>', '>', trim($text)));
+
+ // multi-paragraph functions
+ $text = preg_replace('#(?:[\n]{0,2})"""(.*)"""(?:[\n]{0,2})#s', "\n\n%BLOCKQUOTE%\n\n\\1\n\n%ENDBLOCKQUOTE%\n\n", $text);
+ $text = preg_replace('#(?:[\n]{0,2})===(.*)===(?:[\n]{0,2})#s', "\n\n%CENTER%\n\n\\1\n\n%ENDCENTER%\n\n", $text);
+
+ // pre-parse newlines
+ $text = preg_replace("#\r\n#", "\n", $text);
+ $text = preg_replace("#[\n]{2,}#", "%PARAGRAPH%", $text);
+ $text = preg_replace('#[\n]{1}#', "%LINEBREAK%", $text);
+
+ // split into paragraphs and parse
+ $out = '';
+ foreach (split('%PARAGRAPH%', $text) as $line) {
+
+ if ($line) {
+
+ // pre-parse links
+ $links = array();
+ $regs = null;
+ if (preg_match_all('#\[([^\[]{4,})\]#', $line, $regs)) {
+ foreach ($regs[1] as $reg) {
+ $links[] = $reg;
+ $line = str_replace("[{$reg}]",'%LINK'.(count($links)-1).'%', $line);
+ }
+ }
+
+ // MAIN TEXT FUNCTIONS
+ // bold
+ $line = ereg_replace("\*([^\*]*)\*", "\\1", $line);
+ // italic
+ $line = ereg_replace("_([^_]*)_", "\\1", $line);
+ // entities
+ $line = str_replace(' - ', ' – ', $line);
+ $line = str_replace(' -- ', ' — ', $line);
+ $line = str_replace('(C)', '©', $line);
+ $line = str_replace('(R)', '®', $line);
+ $line = str_replace('(TM)', '™', $line);
+
+ // guess e-mails
+ $emails = null;
+ if (preg_match_all("#([_A-Za-z0-9+-+]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#", $line, $emails)) {
+ foreach ($emails[1] as $email) {
+ $line = str_replace($email, "{$email}", $line);
+ }
+ }
+ // guess links
+ $urls = null;
+ if (preg_match_all("#((?:http|https|ftp|nntp)://[^ ]+)#", $line, $urls)) {
+ foreach ($urls[1] as $url) {
+ $line = str_replace($url, "{$url}", $line);
+ }
+ }
+ if (preg_match_all("#(www\.[^ ]+)#", $line, $urls)) {
+ foreach ($urls[1] as $url) {
+ $line = str_replace($url, "{$url}", $line);
+ }
+ }
+
+
+ // re-parse links
+ if (count($links)) {
+ for ($ii=0; $ii";
+ elseif (preg_match('#^([^\]\ ]+)(?: ([^\]]+))?$#', $links[$ii], $regs))
+ $with = "".(isset($regs[2])? $regs[2]: $regs[1])."";
+ else
+ $with = $links[$ii];
+
+ $line = str_replace("%LINK{$ii}%", $with, $line);
+ }
+ }
+
+ // re-parse newlines
+ $out .= str_replace('%LINEBREAK%', "
\n", "{$line}
\n");
+ }
+ }
+
+ // re-parse multilines
+ $out = str_replace('%BLOCKQUOTE%
', "", $out);
+ $out = str_replace('%ENDBLOCKQUOTE%
', "
", $out);
+ $out = str_replace('%CENTER%
', "", $out);
+ $out = str_replace('%ENDCENTER%
', "", $out);
+
+ return $out;
+ }
+}
+
?>
\ No newline at end of file
diff --git a/libs/inflector.php b/libs/inflector.php
index fc979c8a9..4aca8a5db 100644
--- a/libs/inflector.php
+++ b/libs/inflector.php
@@ -1,4 +1,4 @@
-
\ No newline at end of file
diff --git a/libs/model.php b/libs/model.php
index c2115a933..39aa92e8f 100644
--- a/libs/model.php
+++ b/libs/model.php
@@ -1,622 +1,622 @@
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Purpose: Model
- * DBO-backed object data model, loosly based on RoR (www.rubyonrails.com).
- * Automatically selects db table name based on pluralized lowercase object class name
- * (i.e. class 'User' => table 'users'; class 'Man' => table 'men')
- * The table is required to have at least 'id auto_increment', 'created datetime',
- * and 'modified datetime' fields
- *
- * To do:
- * - schema-related cross-table ($has_one, $has_many, $belongs_to)
- *
- * @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('object', 'validators', 'inflector');
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 0.2.9
- *
- */
-class Model extends Object {
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $parent = false;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $use_table = false;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $id = false;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $data = array();
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $table = false;
- // private
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access private
- */
- var $_table_info = null;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access private
- */
- var $_oneToMany = array();
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access private
- */
- var $_oneToOne = array();
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access private
- */
- var $_hasMany = array();
-
-/**
- * Enter description here...
- *
- * append entries for validation as ('field_name' => '/^perl_compat_regexp$/') that has to match with preg_match()
- * validate with Model::validate()
- * @var unknown_type
- */
- var $validate = array();
-
-/**
- * Append entries for validation as ('field_name' => '/^perl_compat_regexp$/') that has to match with preg_match()
- * validate with Model::validate()
- * @var unknown_type
- */
- var $validationErrors = null;
-
-/**
- * Constructor binds the Model's database table
- *
- * @param unknown_type $id
- */
- function __construct ($id=false) {
- global $DB;
-
- $this->db = &$DB;
-
- if ($id)
- $this->id = $id;
-
- $table_name = $this->use_table? $this->use_table: Inflector::tableize(get_class($this));
- $this->useTable ($table_name);
- parent::__construct();
- $this->createLinks();
- }
-
-/**
- * Enter description here...
- *
- */
- function createLinks () {
- if (!empty($this->hasMany))
- $this->_hasMany = explode(',', $this->hasMany);
-
- foreach ($this->_hasMany as $model_name) {
- // todo fix strip the model name
- $model_name = Inflector::singularize($model_name);
- $this->$model_name = new $model_name();
- }
-
- $this->relink();
- }
-
-/**
- * Enter description here...
- *
- */
- function relink () {
- foreach ($this->_hasMany as $model) {
- $name = Inflector::singularize($model);
- $this->$name->clearLinks();
- $this->$name->linkManyToOne(get_class($this), $this->id);
- }
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $model_name
- * @param unknown_type $value
- */
- function linkManyToOne ($model_name, $value=null) {
- $table_name = Inflector::tableize($model_name);
- $field_name = Inflector::singularize($table_name).'_id';
- $this->_one_to_many[] = array($table_name, $field_name, $value);
- }
-
-/**
- * Enter description here...
- *
- */
- function clearLinks () {
- $this->_one_to_many = array();
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $table_name
- */
- function useTable ($table_name) {
- if (!in_array($table_name, $this->db->tables())) {
- trigger_error (sprintf(ERROR_NO_MODEL_TABLE, get_class($this), $table_name), E_USER_ERROR);
- die();
- }
- else {
- $this->table = $table_name;
- $this->loadInfo();
- }
- }
-
-
-/**
- * Enter description here...
- *
- * @param unknown_type $one
- * @param unknown_type $two
- * @return unknown
- */
- function set ($one, $two=null) {
- $this->validationErrors = null;
- $data = is_array($one)? $one: array($one=>$two);
-
- foreach ($data as $n => $v) {
-/*
- if (!$this->hasField($n)) {
- DEBUG?
- trigger_error(sprintf(ERROR_NO_FIELD_IN_MODEL_DB, $n, $this->table), E_USER_ERROR):
- trigger_error('Application error occured, trying to set a field name that doesn\'t exist.', E_USER_WARNING);
- }
-*/
- $n == 'id'? $this->id = $v: $this->data[$n] = $v;
- }
-
- return $data;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $id
- */
- function setId ($id) {
- $this->id = $id;
- $this->relink();
- }
-
-/**
- * Enter description here...
- *
- */
- function loadInfo () {
- if (empty($this->_table_info))
- $this->_table_info = new NeatArray($this->db->fields($this->table));
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $name
- * @return unknown
- */
- function hasField ($name) {
- if (empty($this->_table_info)) $this->loadInfo();
- return $this->_table_info->findIn('name', $name);
- }
-
-/**
- * reads a list of fields from the db
- *
- * @param string $fields
- * @param array $fields
- * @return array of values
- */
- function read ($fields=null) {
- $this->validationErrors = null;
- return $this->id? $this->find("id = '{$this->id}'", $fields): false;
- }
-
-/**
- * reads a field from a record
- *
- * @param string $name
- * @return field contents
- */
- function field ($name) {
- if (isset($this->data[$name]))
- return $this->data[$name];
- else {
- if ($this->id && $data = $this->read($name)) {
- return isset($data[$name])? $data[$name]: false;
- }
- else {
- return false;
- }
- }
- }
-
-/**
- * saves a single field to the db
- *
- * @param string $name
- * @param mixed $value
- * @return success
- */
- function saveField($name, $value) {
- return $this->save(array($name=>$value), false);
- }
-
-/**
- * saves model data to the db
- *
- * @param array $data
- * @return success
- */
- function save ($data=null, $validate=true) {
- if ($data) $this->set($data);
-
- if ($validate && !$this->validates())
- return false;
-
- $fields = $values = array();
- foreach ($this->data as $n=>$v) {
- if ($this->hasField($n)) {
- $fields[] = $n;
- $values[] = $this->db->prepare($v);
- }
- }
-
- if (empty($this->id) && $this->hasField('created') && !in_array('created', $fields)) {
- $fields[] = 'created';
- $values[] = date("'Y-m-d H:i:s'");
- }
- if ($this->hasField('modified') && !in_array('modified', $fields)) {
- $fields[] = 'modified';
- $values[] = 'NOW()';
- }
-
- if(count($fields)){
- if($this->id){
- $sql = array();
- foreach (array_combine($fields, $values) as $field=>$value) {
- $sql[] = $field.'='.$value;
- }
- if($this->db->query("UPDATE {$this->table} SET ".join(',', $sql)." WHERE id = '{$this->id}'") && $this->db->lastAffected()){
- $this->data = false;
- return true;
- }
- else {
- return $this->db->hasAny($this->table, "id = '{$this->id}'");
- }
- }
- else {
- $fields = join(',', $fields);
- $values = join(',', $values);
-
- if($this->db->query("INSERT INTO {$this->table} ({$fields}) VALUES ({$values})")) {
- $this->id = $this->db->lastInsertId($this->table, 'id');
- return true;
- }
- else {
- return false;
- }
- }
- }
- else {
- return false;
- }
-
- }
-
-/**
- * deletes a record
- *
- * @param mixed $id
- * @return success
- */
- function remove ($id=null) {
- return $this->del($id);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $id
- * @return unknown
- */
- function del ($id=null) {
- if ($id) $this->id = $id;
- if ($this->id && $this->db->query("DELETE FROM {$this->table} WHERE id = '{$this->id}'")) {
- $this->id = false;
- return true;
- }
- else
- return false;
- }
-
-/**
- * checks for existance of a record with set id
- *
- * @return true if such record exists
- */
- function exists () {
- return $this->id? $this->db->hasAny($this->table, "id = '{$this->id}'"): false;
- }
-
-
-/**
- * checks for existance of a record with specified conditions
- *
- * @return true if such record exists
- */
- function hasAny ($sql_conditions=null) {
- return $this->db->hasAny($this->table, $sql_conditions);
- }
-
-
-/**
- * reads a single row
- *
- * @param string $conditions
- * @param string $fields
- * @return array of fields
- */
- function find ($conditions = null, $fields = null) {
- $data = $this->findAll($conditions, $fields, null, 1);
- return empty($data[0])? false: $data[0];
- }
-
-/**
- * returns specified fields from db records matching conditions
- *
- * @param string $conditions
- * @param string $fields
- * @param string $order
- * @param int $limit
- * @param int $page
- * @return array of records
- */
- function findAll ($conditions = null, $fields = null, $order = null, $limit=50, $page=1) {
- if (is_array($fields))
- $f = $fields;
- elseif ($fields)
- $f = array($fields);
- else
- $f = array('*');
-
- $condtions = $this->db->prepare($conditions);
-
- $joins = $whers = array();
-
- foreach ($this->_oneToMany as $rule) {
- list($table, $field, $value) = $rule;
- $joins[] = "LEFT JOIN {$table} ON {$this->table}.{$field} = {$table}.id";
- $whers[] = "{$this->table}.{$field} = '{$value}'";
- }
-
- $joins = count($joins)? join(' ', $joins): null;
- $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}": "";
-
- $data = $this->db->all(
- "SELECT "
- .join(', ', $f)
- ." FROM {$this->table} {$joins}"
- .($conditions? " WHERE {$conditions}":null)
- .($order? " ORDER BY {$order}": null)
- .$limit_str
- .$offset_str);
-
- return $data;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $sql
- * @param unknown_type $debug
- * @return unknown
- */
- function findBySql ($sql, $debug=0) {
- return $this->db->all($sql, $debug);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $conditions
- * @return unknown
- */
- function findCount ($conditions) {
- list($data) = $this->findAll($conditions, 'COUNT(id) AS count');
- return $data['count'];
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $conditions
- * @param unknown_type $fields
- * @return unknown
- */
- function findAllThreaded ($conditions=null, $fields=null, $sort=null) {
- return $this->_doThread($this->findAll($conditions, $fields, $sort), null);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $data
- * @param unknown_type $root
- * @return unknown
- */
- function _doThread ($data, $root) {
- $out = array();
-
- for ($ii=0; $ii_doThread($data, $data[$ii]['id']): null;
- $out[] = $tmp;
- }
- }
-
- return $out;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $conditions
- * @param unknown_type $field
- * @param unknown_type $value
- * @return unknown
- */
- function findNeighbours ($conditions, $field, $value) {
- list($prev) = $this->findAll($conditions." AND {$field} < '{$value}'", $field, "{$field} DESC", 1);
- list($next) = $this->findAll($conditions." AND {$field} > '{$value}'", $field, "{$field} ASC", 1);
-
- return array('prev'=>$prev['id'], 'next'=>$next['id']);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $sql
- * @return unknown
- */
- function query ($sql) {
- return $this->db->query($sql);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $data
- * @return unknown
- */
- function validates ($data=null) {
- $errors = count($this->invalidFields($data? $data: $this->data));
-
- return $errors == 0;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $data
- * @return unknown
- */
- function invalidFields ($data=null) {
- return $this->_invalidFields($data);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $data
- * @return unknown
- */
- function _invalidFields ($data=null) {
- if (!isset($this->validate))
- return true;
-
- if (is_array($this->validationErrors))
- return $this->validationErrors;
-
- $data = ($data? $data: (isset($this->data)? $this->data: array()));
- $errors = array();
-
- foreach ($this->validate as $field_name=>$validator) {
- if (!isset($data[$field_name]) || !preg_match($validator, $data[$field_name]))
- $errors[$field_name] = 1;
- }
-
- $this->validationErrors = $errors;
- return $errors;
- }
-
-}
-
+ + //
+// + 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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: Model
+ * DBO-backed object data model, loosly based on RoR (www.rubyonrails.com).
+ * Automatically selects db table name based on pluralized lowercase object class name
+ * (i.e. class 'User' => table 'users'; class 'Man' => table 'men')
+ * The table is required to have at least 'id auto_increment', 'created datetime',
+ * and 'modified datetime' fields
+ *
+ * To do:
+ * - schema-related cross-table ($has_one, $has_many, $belongs_to)
+ *
+ * @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('object', 'validators', 'inflector');
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ *
+ */
+class Model extends Object {
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $parent = false;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $use_table = false;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $id = false;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $data = array();
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $table = false;
+ // private
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_table_info = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_oneToMany = array();
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_oneToOne = array();
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_hasMany = array();
+
+/**
+ * Enter description here...
+ *
+ * append entries for validation as ('field_name' => '/^perl_compat_regexp$/') that has to match with preg_match()
+ * validate with Model::validate()
+ * @var unknown_type
+ */
+ var $validate = array();
+
+/**
+ * Append entries for validation as ('field_name' => '/^perl_compat_regexp$/') that has to match with preg_match()
+ * validate with Model::validate()
+ * @var unknown_type
+ */
+ var $validationErrors = null;
+
+/**
+ * Constructor binds the Model's database table
+ *
+ * @param unknown_type $id
+ */
+ function __construct ($id=false) {
+ global $DB;
+
+ $this->db = &$DB;
+
+ if ($id)
+ $this->id = $id;
+
+ $table_name = $this->use_table? $this->use_table: Inflector::tableize(get_class($this));
+ $this->useTable ($table_name);
+ parent::__construct();
+ $this->createLinks();
+ }
+
+/**
+ * Enter description here...
+ *
+ */
+ function createLinks () {
+ if (!empty($this->hasMany))
+ $this->_hasMany = explode(',', $this->hasMany);
+
+ foreach ($this->_hasMany as $model_name) {
+ // todo fix strip the model name
+ $model_name = Inflector::singularize($model_name);
+ $this->$model_name = new $model_name();
+ }
+
+ $this->relink();
+ }
+
+/**
+ * Enter description here...
+ *
+ */
+ function relink () {
+ foreach ($this->_hasMany as $model) {
+ $name = Inflector::singularize($model);
+ $this->$name->clearLinks();
+ $this->$name->linkManyToOne(get_class($this), $this->id);
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $model_name
+ * @param unknown_type $value
+ */
+ function linkManyToOne ($model_name, $value=null) {
+ $table_name = Inflector::tableize($model_name);
+ $field_name = Inflector::singularize($table_name).'_id';
+ $this->_one_to_many[] = array($table_name, $field_name, $value);
+ }
+
+/**
+ * Enter description here...
+ *
+ */
+ function clearLinks () {
+ $this->_one_to_many = array();
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $table_name
+ */
+ function useTable ($table_name) {
+ if (!in_array($table_name, $this->db->tables())) {
+ trigger_error (sprintf(ERROR_NO_MODEL_TABLE, get_class($this), $table_name), E_USER_ERROR);
+ die();
+ }
+ else {
+ $this->table = $table_name;
+ $this->loadInfo();
+ }
+ }
+
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $one
+ * @param unknown_type $two
+ * @return unknown
+ */
+ function set ($one, $two=null) {
+ $this->validationErrors = null;
+ $data = is_array($one)? $one: array($one=>$two);
+
+ foreach ($data as $n => $v) {
+/*
+ if (!$this->hasField($n)) {
+ DEBUG?
+ trigger_error(sprintf(ERROR_NO_FIELD_IN_MODEL_DB, $n, $this->table), E_USER_ERROR):
+ trigger_error('Application error occured, trying to set a field name that doesn\'t exist.', E_USER_WARNING);
+ }
+*/
+ $n == 'id'? $this->id = $v: $this->data[$n] = $v;
+ }
+
+ return $data;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $id
+ */
+ function setId ($id) {
+ $this->id = $id;
+ $this->relink();
+ }
+
+/**
+ * Enter description here...
+ *
+ */
+ function loadInfo () {
+ if (empty($this->_table_info))
+ $this->_table_info = new NeatArray($this->db->fields($this->table));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $name
+ * @return unknown
+ */
+ function hasField ($name) {
+ if (empty($this->_table_info)) $this->loadInfo();
+ return $this->_table_info->findIn('name', $name);
+ }
+
+/**
+ * reads a list of fields from the db
+ *
+ * @param string $fields
+ * @param array $fields
+ * @return array of values
+ */
+ function read ($fields=null) {
+ $this->validationErrors = null;
+ return $this->id? $this->find("id = '{$this->id}'", $fields): false;
+ }
+
+/**
+ * reads a field from a record
+ *
+ * @param string $name
+ * @return field contents
+ */
+ function field ($name) {
+ if (isset($this->data[$name]))
+ return $this->data[$name];
+ else {
+ if ($this->id && $data = $this->read($name)) {
+ return isset($data[$name])? $data[$name]: false;
+ }
+ else {
+ return false;
+ }
+ }
+ }
+
+/**
+ * saves a single field to the db
+ *
+ * @param string $name
+ * @param mixed $value
+ * @return success
+ */
+ function saveField($name, $value) {
+ return $this->save(array($name=>$value), false);
+ }
+
+/**
+ * saves model data to the db
+ *
+ * @param array $data
+ * @return success
+ */
+ function save ($data=null, $validate=true) {
+ if ($data) $this->set($data);
+
+ if ($validate && !$this->validates())
+ return false;
+
+ $fields = $values = array();
+ foreach ($this->data as $n=>$v) {
+ if ($this->hasField($n)) {
+ $fields[] = $n;
+ $values[] = $this->db->prepare($v);
+ }
+ }
+
+ if (empty($this->id) && $this->hasField('created') && !in_array('created', $fields)) {
+ $fields[] = 'created';
+ $values[] = date("'Y-m-d H:i:s'");
+ }
+ if ($this->hasField('modified') && !in_array('modified', $fields)) {
+ $fields[] = 'modified';
+ $values[] = 'NOW()';
+ }
+
+ if(count($fields)){
+ if($this->id){
+ $sql = array();
+ foreach (array_combine($fields, $values) as $field=>$value) {
+ $sql[] = $field.'='.$value;
+ }
+ if($this->db->query("UPDATE {$this->table} SET ".join(',', $sql)." WHERE id = '{$this->id}'") && $this->db->lastAffected()){
+ $this->data = false;
+ return true;
+ }
+ else {
+ return $this->db->hasAny($this->table, "id = '{$this->id}'");
+ }
+ }
+ else {
+ $fields = join(',', $fields);
+ $values = join(',', $values);
+
+ if($this->db->query("INSERT INTO {$this->table} ({$fields}) VALUES ({$values})")) {
+ $this->id = $this->db->lastInsertId($this->table, 'id');
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ }
+ else {
+ return false;
+ }
+
+ }
+
+/**
+ * deletes a record
+ *
+ * @param mixed $id
+ * @return success
+ */
+ function remove ($id=null) {
+ return $this->del($id);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $id
+ * @return unknown
+ */
+ function del ($id=null) {
+ if ($id) $this->id = $id;
+ if ($this->id && $this->db->query("DELETE FROM {$this->table} WHERE id = '{$this->id}'")) {
+ $this->id = false;
+ return true;
+ }
+ else
+ return false;
+ }
+
+/**
+ * checks for existance of a record with set id
+ *
+ * @return true if such record exists
+ */
+ function exists () {
+ return $this->id? $this->db->hasAny($this->table, "id = '{$this->id}'"): false;
+ }
+
+
+/**
+ * checks for existance of a record with specified conditions
+ *
+ * @return true if such record exists
+ */
+ function hasAny ($sql_conditions=null) {
+ return $this->db->hasAny($this->table, $sql_conditions);
+ }
+
+
+/**
+ * reads a single row
+ *
+ * @param string $conditions
+ * @param string $fields
+ * @return array of fields
+ */
+ function find ($conditions = null, $fields = null) {
+ $data = $this->findAll($conditions, $fields, null, 1);
+ return empty($data[0])? false: $data[0];
+ }
+
+/**
+ * returns specified fields from db records matching conditions
+ *
+ * @param string $conditions
+ * @param string $fields
+ * @param string $order
+ * @param int $limit
+ * @param int $page
+ * @return array of records
+ */
+ function findAll ($conditions = null, $fields = null, $order = null, $limit=50, $page=1) {
+ if (is_array($fields))
+ $f = $fields;
+ elseif ($fields)
+ $f = array($fields);
+ else
+ $f = array('*');
+
+ $condtions = $this->db->prepare($conditions);
+
+ $joins = $whers = array();
+
+ foreach ($this->_oneToMany as $rule) {
+ list($table, $field, $value) = $rule;
+ $joins[] = "LEFT JOIN {$table} ON {$this->table}.{$field} = {$table}.id";
+ $whers[] = "{$this->table}.{$field} = '{$value}'";
+ }
+
+ $joins = count($joins)? join(' ', $joins): null;
+ $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}": "";
+
+ $data = $this->db->all(
+ "SELECT "
+ .join(', ', $f)
+ ." FROM {$this->table} {$joins}"
+ .($conditions? " WHERE {$conditions}":null)
+ .($order? " ORDER BY {$order}": null)
+ .$limit_str
+ .$offset_str);
+
+ return $data;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $sql
+ * @param unknown_type $debug
+ * @return unknown
+ */
+ function findBySql ($sql, $debug=0) {
+ return $this->db->all($sql, $debug);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $conditions
+ * @return unknown
+ */
+ function findCount ($conditions) {
+ list($data) = $this->findAll($conditions, 'COUNT(id) AS count');
+ return $data['count'];
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $conditions
+ * @param unknown_type $fields
+ * @return unknown
+ */
+ function findAllThreaded ($conditions=null, $fields=null, $sort=null) {
+ return $this->_doThread($this->findAll($conditions, $fields, $sort), null);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $data
+ * @param unknown_type $root
+ * @return unknown
+ */
+ function _doThread ($data, $root) {
+ $out = array();
+
+ for ($ii=0; $ii_doThread($data, $data[$ii]['id']): null;
+ $out[] = $tmp;
+ }
+ }
+
+ return $out;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $conditions
+ * @param unknown_type $field
+ * @param unknown_type $value
+ * @return unknown
+ */
+ function findNeighbours ($conditions, $field, $value) {
+ list($prev) = $this->findAll($conditions." AND {$field} < '{$value}'", $field, "{$field} DESC", 1);
+ list($next) = $this->findAll($conditions." AND {$field} > '{$value}'", $field, "{$field} ASC", 1);
+
+ return array('prev'=>$prev['id'], 'next'=>$next['id']);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $sql
+ * @return unknown
+ */
+ function query ($sql) {
+ return $this->db->query($sql);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $data
+ * @return unknown
+ */
+ function validates ($data=null) {
+ $errors = count($this->invalidFields($data? $data: $this->data));
+
+ return $errors == 0;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $data
+ * @return unknown
+ */
+ function invalidFields ($data=null) {
+ return $this->_invalidFields($data);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $data
+ * @return unknown
+ */
+ function _invalidFields ($data=null) {
+ if (!isset($this->validate))
+ return true;
+
+ if (is_array($this->validationErrors))
+ return $this->validationErrors;
+
+ $data = ($data? $data: (isset($this->data)? $this->data: array()));
+ $errors = array();
+
+ foreach ($this->validate as $field_name=>$validator) {
+ if (!isset($data[$field_name]) || !preg_match($validator, $data[$field_name]))
+ $errors[$field_name] = 1;
+ }
+
+ $this->validationErrors = $errors;
+ return $errors;
+ }
+
+}
+
?>
\ No newline at end of file
diff --git a/libs/object.php b/libs/object.php
index dd5e417e3..45bd55f4c 100644
--- a/libs/object.php
+++ b/libs/object.php
@@ -31,6 +31,16 @@ uses('log');
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
+
+uses('log');
+
+/**
+ * Enter description here...
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ */
class Object {
/**
diff --git a/libs/router.php b/libs/router.php
index acbaa351b..fe720f764 100644
--- a/libs/router.php
+++ b/libs/router.php
@@ -1,169 +1,169 @@
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Purpose: Router
- * Parses the request URL into controller, action, and params
- *
- * @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('object');
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 0.2.9
- *
- */
-class Router extends Object {
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $routes = array();
-
-/**
- * Enter description here...
- *
- */
- function __construct () {
- parent::__construct();
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $route
- * @param unknown_type $default
- */
- function connect ($route, $default=null) {
- $parsed = $names = array ();
-
- $r = null;
- if (($route == '') || ($route == '/')) {
- $regexp = '/^[\/]*$/';
- $this->routes[] = array($route, $regexp, array(), $default);
- }
- else {
- $elements = array();
- foreach (explode('/', $route) as $element)
- if (trim($element)) $elements[] = $element;
-
- if (!count($elements))
- return false;
-
- foreach ($elements as $element) {
- if (preg_match('/^:(.+)$/', $element, $r)) {
- $parsed[] = '(?:\/([^\/]+))?';
- $names[] = $r[1];
- }
- elseif (preg_match('/^\*$/', $element, $r)) {
- $parsed[] = '(?:\/(.*))?';
- }
- else {
- $parsed[] = '/'.$element;
- }
- }
- $regexp = '#^'.join('', $parsed).'[\/]*$#';
- $this->routes[] = array($route, $regexp, $names, $default);
- }
-
- return $this->routes;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $url
- * @return unknown
- */
- function parse ($url) {
- $out = array();
- $r = null;
-
- $default_route = array(
- '/:controller/:action/* (default)',
- "#^(?:\/(?:([a-z0-9_\-]+)(?:\/([a-z0-9_\-]+)(?:\/(.*))?)?))[\/]*$#",
- array('controller', 'action'),
- array()
- );
-
- $this->routes[] = $default_route;
-
- foreach ($this->routes as $route) {
- list($route, $regexp, $names, $defaults) = $route;
-
- if (preg_match($regexp, $url, $r)) {
- // $this->log($url.' matched '.$regexp, 'note');
- // remove the first element, which is the url
- array_shift($r);
-
- // hack, pre-fill the default route names
- foreach ($names as $name)
- $out[$name] = null;
-
- $ii = 0;
-
- if (is_array($defaults)) {
- foreach ($defaults as $name=>$value) {
- if (preg_match('#[a-z_\-]#i', $name))
- $out[$name] = $value;
- else
- $out['pass'][] = $value;
- }
- }
-
- foreach ($r as $found) {
- // if $found is a named url element (i.e. ':action')
- if (isset($names[$ii])) {
- $out[$names[$ii]] = $found;
- }
- // unnamed elements go in as 'pass'
- else {
- $pass = new NeatArray(explode('/', $found));
- $pass->cleanup();
- $out['pass'] = $pass->value;
- }
- $ii++;
- }
- break;
- }
- }
-
- return $out;
- }
-}
-
+ + //
+// + 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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: Router
+ * Parses the request URL into controller, action, and params
+ *
+ * @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('object');
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ *
+ */
+class Router extends Object {
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $routes = array();
+
+/**
+ * Enter description here...
+ *
+ */
+ function __construct () {
+ parent::__construct();
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $route
+ * @param unknown_type $default
+ */
+ function connect ($route, $default=null) {
+ $parsed = $names = array ();
+
+ $r = null;
+ if (($route == '') || ($route == '/')) {
+ $regexp = '/^[\/]*$/';
+ $this->routes[] = array($route, $regexp, array(), $default);
+ }
+ else {
+ $elements = array();
+ foreach (explode('/', $route) as $element)
+ if (trim($element)) $elements[] = $element;
+
+ if (!count($elements))
+ return false;
+
+ foreach ($elements as $element) {
+ if (preg_match('/^:(.+)$/', $element, $r)) {
+ $parsed[] = '(?:\/([^\/]+))?';
+ $names[] = $r[1];
+ }
+ elseif (preg_match('/^\*$/', $element, $r)) {
+ $parsed[] = '(?:\/(.*))?';
+ }
+ else {
+ $parsed[] = '/'.$element;
+ }
+ }
+ $regexp = '#^'.join('', $parsed).'[\/]*$#';
+ $this->routes[] = array($route, $regexp, $names, $default);
+ }
+
+ return $this->routes;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $url
+ * @return unknown
+ */
+ function parse ($url) {
+ $out = array();
+ $r = null;
+
+ $default_route = array(
+ '/:controller/:action/* (default)',
+ "#^(?:\/(?:([a-z0-9_\-]+)(?:\/([a-z0-9_\-]+)(?:\/(.*))?)?))[\/]*$#",
+ array('controller', 'action'),
+ array()
+ );
+
+ $this->routes[] = $default_route;
+
+ foreach ($this->routes as $route) {
+ list($route, $regexp, $names, $defaults) = $route;
+
+ if (preg_match($regexp, $url, $r)) {
+ // $this->log($url.' matched '.$regexp, 'note');
+ // remove the first element, which is the url
+ array_shift($r);
+
+ // hack, pre-fill the default route names
+ foreach ($names as $name)
+ $out[$name] = null;
+
+ $ii = 0;
+
+ if (is_array($defaults)) {
+ foreach ($defaults as $name=>$value) {
+ if (preg_match('#[a-z_\-]#i', $name))
+ $out[$name] = $value;
+ else
+ $out['pass'][] = $value;
+ }
+ }
+
+ foreach ($r as $found) {
+ // if $found is a named url element (i.e. ':action')
+ if (isset($names[$ii])) {
+ $out[$names[$ii]] = $found;
+ }
+ // unnamed elements go in as 'pass'
+ else {
+ $pass = new NeatArray(explode('/', $found));
+ $pass->cleanup();
+ $out['pass'] = $pass->value;
+ }
+ $ii++;
+ }
+ break;
+ }
+ }
+
+ return $out;
+ }
+}
+
?>
\ No newline at end of file
diff --git a/libs/template.php b/libs/template.php
index 132444cb1..3590a9435 100644
--- a/libs/template.php
+++ b/libs/template.php
@@ -1,287 +1,287 @@
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Purpose: Renderer
- * Templating for Controller class.
- *
- * @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('object');
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 0.2.9
- *
- */
-class Template extends Object {
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $base = null;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $layout = 'default';
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $autoRender = true;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access public
- */
- var $autoLayout = true;
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access private
- */
- var $_view_vars = array();
-
-/**
- * Enter description here...
- *
- * @var unknown_type
- * @access private
- */
- var $_page_title = false;
-
-/**
- * Enter description here...
- *
- */
- function __construct () {
- parent::__construct();
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $layout
- */
- function setLayout ($layout) {
- $this->layout = $layout;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $one
- * @param unknown_type $two
- * @return unknown
- */
- function set($one, $two=null) {
- return $this->_setArray(is_array($one)? $one: array($one=>$two));
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $value
- */
- function setTitle ($value) {
- $this->_page_title = $value;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $data
- */
- function _setArray($data) {
- foreach ($data as $name => $value) {
- if ($name == 'title')
- $this->setTitle ($value);
- else
- $this->_view_vars[$name] = $value;
- }
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $message
- * @param unknown_type $url
- * @param unknown_type $time
- */
- function flash ($message, $url, $time=1) {
- $this->autoRender = false;
- $this->autoLayout = false;
-
- $this->set('url', $this->base.$url);
- $this->set('message', $message);
- $this->set('time', $time);
-
- $this->render(null,false,VIEWS.'layouts'.DS.'flash.thtml');
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $action
- * @param unknown_type $layout
- * @param unknown_type $file
- */
- function render ($action=null, $layout=null, $file=null) {
- $this->autoRender = false;
-
- if (!$action) $action = $this->action;
- if ($layout) $this->setLayout($layout);
-
- $view_fn = $file? $file: $this->_getViewFn($action);
-
- if (!is_file($view_fn)) {
- DEBUG? trigger_error (sprintf(ERROR_NO_VIEW, $action, $view_fn), E_USER_ERROR)
- : $this->error('404', 'Not found', sprintf(ERROR_404, '', "missing view \"{$action}\""));
- die();
- }
-
- $out = $this->_render($view_fn, $this->_view_vars, 0);
-
- if ($out !== false) {
- if ($this->layout && $this->autoLayout)
- $out = $this->renderLayout($out);
- print $out;
- }
- else {
- $out = $this->_render($view_fn, $this->_view_vars, false);
- trigger_error (sprintf(ERROR_IN_VIEW, $view_fn, $out), E_USER_ERROR);
- }
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $content_for_layout
- * @return unknown
- */
- function renderLayout ($content_for_layout) {
- $layout_fn = $this->_getLayoutFn();
-
- $data_for_layout = array_merge($this->_view_vars, array(
- 'title_for_layout'=>$this->_page_title !== false? $this->_page_title: ucfirst($this->name),
- 'content_for_layout'=>$content_for_layout));
-
- if (is_file($layout_fn)) {
- $out = $this->_render($layout_fn, $data_for_layout);
-
- if ($out === false) {
- $out = $this->_render($layout_fn, $data_for_layout, false);
- trigger_error (sprintf(ERROR_IN_LAYOUT, $layout_fn, $out), E_USER_ERROR);
- return false;
- }
- else {
- return $out;
- }
- }
- else {
- trigger_error (sprintf(ERROR_NO_LAYOUT, $this->layout, $layout_fn), E_USER_ERROR);
- return false;
- }
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function _getLayoutFn() {
- return VIEWS."layouts".DS."{$this->layout}.thtml";
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $action
- * @return unknown
- */
- function _getViewFn($action) {
- return VIEWS.$this->name.DS."{$action}.thtml";
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $___view_fn
- * @param unknown_type $___data_for_view
- * @param unknown_type $___play_safe
- * @return unknown
- */
- function _render($___view_fn, $___data_for_view, $___play_safe = true) {
- extract($___data_for_view, EXTR_SKIP); # load all view variables
- $BASE = $this->base;
- $params = &$this->params;
- $page_title = $this->_page_title;
- ob_start(); # start caching output (eval outputs directly so we need to cache)
-
- # include the template
- $___play_safe? @include($___view_fn): include($___view_fn);
-
- $out = ob_get_contents(); # retrieve cached output
- ob_end_clean(); # end caching output
-
- return $out;
- }
-
-/**
- * trims a string to a specified length adding elipsis '..' if necessary
- *
- * @param unknown_type $string
- * @param unknown_type $length
- * @return unknown
- */
- function trimTo ($string, $length) {
- return substr($string, 0, $length).(strlen($string)>$length? '..': null);
- }
-}
-
+ + //
+// + 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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: Renderer
+ * Templating for Controller class.
+ *
+ * @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('object');
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ *
+ */
+class Template extends Object {
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $base = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $layout = 'default';
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $autoRender = true;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $autoLayout = true;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_view_vars = array();
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_page_title = false;
+
+/**
+ * Enter description here...
+ *
+ */
+ function __construct () {
+ parent::__construct();
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $layout
+ */
+ function setLayout ($layout) {
+ $this->layout = $layout;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $one
+ * @param unknown_type $two
+ * @return unknown
+ */
+ function set($one, $two=null) {
+ return $this->_setArray(is_array($one)? $one: array($one=>$two));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $value
+ */
+ function setTitle ($value) {
+ $this->_page_title = $value;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $data
+ */
+ function _setArray($data) {
+ foreach ($data as $name => $value) {
+ if ($name == 'title')
+ $this->setTitle ($value);
+ else
+ $this->_view_vars[$name] = $value;
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $message
+ * @param unknown_type $url
+ * @param unknown_type $time
+ */
+ function flash ($message, $url, $time=1) {
+ $this->autoRender = false;
+ $this->autoLayout = false;
+
+ $this->set('url', $this->base.$url);
+ $this->set('message', $message);
+ $this->set('time', $time);
+
+ $this->render(null,false,VIEWS.'layouts'.DS.'flash.thtml');
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $action
+ * @param unknown_type $layout
+ * @param unknown_type $file
+ */
+ function render ($action=null, $layout=null, $file=null) {
+ $this->autoRender = false;
+
+ if (!$action) $action = $this->action;
+ if ($layout) $this->setLayout($layout);
+
+ $view_fn = $file? $file: $this->_getViewFn($action);
+
+ if (!is_file($view_fn)) {
+ DEBUG? trigger_error (sprintf(ERROR_NO_VIEW, $action, $view_fn), E_USER_ERROR)
+ : $this->error('404', 'Not found', sprintf(ERROR_404, '', "missing view \"{$action}\""));
+ die();
+ }
+
+ $out = $this->_render($view_fn, $this->_view_vars, 0);
+
+ if ($out !== false) {
+ if ($this->layout && $this->autoLayout)
+ $out = $this->renderLayout($out);
+ print $out;
+ }
+ else {
+ $out = $this->_render($view_fn, $this->_view_vars, false);
+ trigger_error (sprintf(ERROR_IN_VIEW, $view_fn, $out), E_USER_ERROR);
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $content_for_layout
+ * @return unknown
+ */
+ function renderLayout ($content_for_layout) {
+ $layout_fn = $this->_getLayoutFn();
+
+ $data_for_layout = array_merge($this->_view_vars, array(
+ 'title_for_layout'=>$this->_page_title !== false? $this->_page_title: ucfirst($this->name),
+ 'content_for_layout'=>$content_for_layout));
+
+ if (is_file($layout_fn)) {
+ $out = $this->_render($layout_fn, $data_for_layout);
+
+ if ($out === false) {
+ $out = $this->_render($layout_fn, $data_for_layout, false);
+ trigger_error (sprintf(ERROR_IN_LAYOUT, $layout_fn, $out), E_USER_ERROR);
+ return false;
+ }
+ else {
+ return $out;
+ }
+ }
+ else {
+ trigger_error (sprintf(ERROR_NO_LAYOUT, $this->layout, $layout_fn), E_USER_ERROR);
+ return false;
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function _getLayoutFn() {
+ return VIEWS."layouts".DS."{$this->layout}.thtml";
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $action
+ * @return unknown
+ */
+ function _getViewFn($action) {
+ return VIEWS.$this->name.DS."{$action}.thtml";
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $___view_fn
+ * @param unknown_type $___data_for_view
+ * @param unknown_type $___play_safe
+ * @return unknown
+ */
+ function _render($___view_fn, $___data_for_view, $___play_safe = true) {
+ extract($___data_for_view, EXTR_SKIP); # load all view variables
+ $BASE = $this->base;
+ $params = &$this->params;
+ $page_title = $this->_page_title;
+ ob_start(); # start caching output (eval outputs directly so we need to cache)
+
+ # include the template
+ $___play_safe? @include($___view_fn): include($___view_fn);
+
+ $out = ob_get_contents(); # retrieve cached output
+ ob_end_clean(); # end caching output
+
+ return $out;
+ }
+
+/**
+ * trims a string to a specified length adding elipsis '..' if necessary
+ *
+ * @param unknown_type $string
+ * @param unknown_type $length
+ * @return unknown
+ */
+ function trimTo ($string, $length) {
+ return substr($string, 0, $length).(strlen($string)>$length? '..': null);
+ }
+}
+
?>
\ No newline at end of file
diff --git a/libs/test.php b/libs/test.php
index 7cc9e56b7..ca7f1de1c 100644
--- a/libs/test.php
+++ b/libs/test.php
@@ -1,1062 +1,1062 @@
- + //
-// + OntoSys, Inc + //
-// + + //
-// + Changes by Michal Tatarynowicz + //
-// +---------------------------------------------------------------------+ //
-// + Permission is hereby granted, free of charge, to any person + //
-// + obtaining a copy of this software and associated documentation + //
-// + files (the "Software"), to deal in the Software without + //
-// + restriction, including without limitation the rights to use, copy, + //
-// + modify, merge, publish, distribute, sublicense, and/or sell copies + //
-// + of the Software, and to permit persons to whom the Software is + //
-// + furnished to do so, subject to the following conditions: + //
-// + + //
-// + The above copyright notice and this permission notice shall be + //
-// + included in all copies or substantial portions of the Software. + //
-// + + //
-// + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + //
-// + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + //
-// + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + //
-// + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + //
-// + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + //
-// + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + //
-// + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + //
-// + SOFTWARE. + //
-/////////////////////////////////////////////////////////////////////////////
-
-/**
- * Purpose: PHP framework for testing, based on the design of "JUnit".
- *
- * @filesource
- * @author Fred Yankowski
- * @copyright Copyright (c) 2000 Fred Yankowski
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 1.0.0.0
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
- */
-
-/**
- * Enter description here...
- *
- * @param unknown_type $msg
- */
-function trace($msg) {
- return;
- print($msg);
- flush();
-}
-/**
- * Enter description here...
- *
- */
-if (phpversion() >= '4') {
-/**
- * Enter description here...
- *
- * @param unknown_type $errno
- * @param unknown_type $errstr
- * @param unknown_type $errfile
- * @param unknown_type $errline
- */
- function PHPUnit_error_handler($errno, $errstr, $errfile, $errline) {
- global $PHPUnit_testRunning;
- $PHPUnit_testRunning[0]->fail("PHP ERROR: ".$errstr." in ".$errfile." at line ".$errline);
- }
-}
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 1.0.0.0
- *
- */
-class TestException {
- /* Emulate a Java exception, sort of... */
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $message;
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $type;
-/**
- * Enter description here...
- *
- * @param unknown_type $message
- * @param unknown_type $type
- * @return TestException
- */
- function TestException($message, $type = 'FAILURE') {
- $this->message = $message;
- $this->type = $type;
- }
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function getMessage() {
- return $this->message;
- }
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function getType() {
- return $this->type;
- }
-}
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 1.0.0.0
- *
- */
-class Assert {
-/**
- * Enter description here...
- *
- * @param unknown_type $boolean
- * @param unknown_type $message
- */
- function assert($boolean, $message=0) {
- if (! $boolean)
- $this->fail($message);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $expected
- * @param unknown_type $actual
- * @param unknown_type $message
- * @return unknown
- */
- function asEq ($expected, $actual, $message=0) {
- return $this->assertEquals($expected, $actual, $message);
- }
-/**
- * Enter description here...
- *
- * @param unknown_type $expected
- * @param unknown_type $actual
- * @param unknown_type $message
- */
- function assertEquals($expected, $actual, $message=0) {
- if (gettype($expected) != gettype($actual)) {
- $this->failNotEquals($expected, $actual, "expected", $message);
- return;
- }
-
- if (phpversion() < '4') {
- if (is_object($expected) or is_object($actual) or is_array($expected) or is_array($actual)) {
- $this->error("INVALID TEST: cannot compare arrays or objects in PHP3");
- return;
- }
- }
-
- if (phpversion() >= '4' && is_object($expected)) {
- if (get_class($expected) != get_class($actual)) {
- $this->failNotEquals($expected, $actual, "expected", $message);
- return;
- }
-
- if (method_exists($expected, "equals")) {
- if (! $expected->equals($actual)) {
- $this->failNotEquals($expected, $actual, "expected", $message);
- }
- return; // no further tests after equals()
- }
- }
-
- if (phpversion() >= '4.0.4') {
- if (is_null($expected) != is_null($actual)) {
- $this->failNotEquals($expected, $actual, "expected", $message);
- return;
- }
- }
-
- if ($expected != $actual) {
- $this->failNotEquals($actual, $expected, "expected", $message);
- }
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $regexp
- * @param unknown_type $actual
- * @param unknown_type $message
- */
- function assertRegexp($regexp, $actual, $message=false) {
- if (! preg_match($regexp, $actual)) {
- $this->failNotEquals($regexp, $actual, "pattern", $message);
- }
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $string0
- * @param unknown_type $string1
- * @param unknown_type $message
- */
- function assertEqualsMultilineStrings($string0, $string1,
- $message="") {
- $lines0 = split("\n",$string0);
- $lines1 = split("\n",$string1);
- if (sizeof($lines0) != sizeof($lines1)) {
- $this->failNotEquals(sizeof($lines0)." line(s)",
- sizeof($lines1)." line(s)", "expected", $message);
- }
- for($i=0; $i< sizeof($lines0); $i++) {
- $this->assertEquals(trim($lines0[$i]),
- trim($lines1[$i]),
- "line ".($i+1)." of multiline strings differ. ".$message);
- }
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $fn
- */
- function assertFileExists ($fn) {
- if (!file_exists($fn))
- $this->failNotEquals($fn, "file not found", "file expected");
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $fn
- * @param unknown_type $str
- */
- function assertFileContains ($fn, $str) {
- if (file_exists($fn)) {
- $lines = file($fn);
- $text = implode("\n", $lines);
-
- if (!preg_match("/{$str}/", $text))
- $this->failNotEquals($fn, 'expected '.$str, 'expected');
- }
- else
- $this->failNotEquals($fn, 'file doesn\'t exist', 'expected');
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $path
- */
- function assertDirExists ($path) {
- if (!is_dir($path))
- $this->failNotEquals($path, "directory not found", "expected");
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $value
- */
- function assertTrue ($value) {
- if (!$value)
- $this->failNotEquals($value, true, "expected");
- }
-
-
-/**
- * Enter description here...
- *
- * @param mixed $value
- * @return string
- */
- function _formatValue ($value) {
-
- if (is_object($value) && method_exists($value, "toString")) {
- $valueStr = $value->toString();
- }
- elseif (is_bool($value)) {
- $valueStr = $value? 'false': 'true';
- }
- elseif (is_object($value) || is_array($value)) {
- $valueStr = serialize($value);
- }
- else {
- $valueStr = str_replace('<', '<', str_replace('>', '>', $value));
- }
-
- return array($valueStr, gettype($value));
- }
-
-
-/**
- * Enter description here...
- *
- * @param unknown_type $expected
- * @param unknown_type $actual
- * @param unknown_type $expected_label
- * @param unknown_type $message
- */
- function failNotEquals ($expected, $actual, $expected_label, $message=null) {
- $out = array(
- 'message'=>$message,
- 'label'=>$expected_label,
- 'expected'=>$this->_formatValue($expected, "expected"),
- 'actual'=>$this->_formatValue($actual, "actual")
- );
-
- $this->fail($out);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $expected
- * @param unknown_type $actual
- * @param unknown_type $expected_label
- * @param unknown_type $message
- */
- function old_failNotEquals($expected, $actual, $expected_label, $message=0) {
- // Private function for reporting failure to match.
- $str = $message ? ($message . ' ') : '';
- //$str .= "($expected_label/actual)
";
- $str .= "
";
- $str .= sprintf("%s
%s",
- $this->_formatValue($expected, "expected"),
- $this->_formatValue($actual, "actual"));
- $this->fail($str);
- }
-}
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 1.0.0.0
- *
- */
-class TestCase extends Assert /* implements Test */ {
- /* Defines context for running tests. Specific context -- such as
- instance variables, global variables, global state -- is defined
- by creating a subclass that specializes the setUp() and
- tearDown() methods. A specific test is defined by a subclass
- that specializes the runTest() method. */
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $fName;
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $fClassName;
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $fResult;
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $fExceptions = array();
-
-/**
- * Enter description here...
- *
- * @param unknown_type $name
- * @return TestCase
- */
- function TestCase($name) {
- $this->fName = $name;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $testResult
- * @return unknown
- */
- function run($testResult=0) {
- /* Run this single test, by calling the run() method of the
- TestResult object which will in turn call the runBare() method
- of this object. That complication allows the TestResult object
- to do various kinds of progress reporting as it invokes each
- test. Create/obtain a TestResult object if none was passed in.
- Note that if a TestResult object was passed in, it must be by
- reference. */
- if (! $testResult)
- $testResult = $this->_createResult();
- $this->fResult = $testResult;
- $testResult->run(&$this);
- $this->fResult = 0;
- return $testResult;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function classname() {
- if (isset($this->fClassName)) {
- return $this->fClassName;
- } else {
- return get_class($this);
- }
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function countTestCases() {
- return 1;
- }
-
-/**
- * Enter description here...
- *
- */
- function runTest() {
-
- if (version_compare(phpversion(), '4') >= 0) {
- global $PHPUnit_testRunning;
- eval('$PHPUnit_testRunning[0] = & $this;');
-
- // Saved ref to current TestCase, so that the error handler
- // can access it. This code won't even parse in PHP3, so we
- // hide it in an eval.
-
- $old_handler = set_error_handler("PHPUnit_error_handler");
- // errors will now be handled by our error handler
- }
-
- $name = $this->name();
- if ((version_compare(phpversion(), '4') >= 0) && ! method_exists($this, $name)) {
- $this->error("Method '$name' does not exist");
- }
- else
- $this->$name();
-
- if (version_compare(phpversion(), '4') >= 0) {
- restore_error_handler(); // revert to prior error handler
- $PHPUnit_testRunning = null;
- }
- }
-
-/**
- * Enter description here...
- *
- */
- function setUp() /* expect override */ {
- //print("TestCase::setUp()
\n");
- }
-
-/**
- * Enter description here...
- *
- */
- function tearDown() /* possible override */ {
- //print("TestCase::tearDown()
\n");
- }
-
- ////////////////////////////////////////////////////////////////
-
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function _createResult() /* protected */ {
- /* override this to use specialized subclass of TestResult */
- return new TestResult;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $message
- */
- function fail($message=0) {
- //printf("TestCase::fail(%s)
\n", ($message) ? $message : '');
- /* JUnit throws AssertionFailedError here. We just record the
- failure and carry on */
- $this->fExceptions[] = new TestException(&$message, 'FAILURE');
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $message
- */
- function error($message) {
- /* report error that requires correction in the test script
- itself, or (heaven forbid) in this testing infrastructure */
- $this->fExceptions[] = new TestException(&$message, 'ERROR');
- $this->fResult->stop(); // [does not work]
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function failed() {
- reset($this->fExceptions);
- while (list($key, $exception) = each($this->fExceptions)) {
- if ($exception->type == 'FAILURE')
- return true;
- }
- return false;
- }
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function errored() {
- reset($this->fExceptions);
- while (list($key, $exception) = each($this->fExceptions)) {
- if ($exception->type == 'ERROR')
- return true;
- }
- return false;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function getExceptions() {
- return $this->fExceptions;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function name() {
- return $this->fName;
- }
-
-/**
- * Enter description here...
- *
- */
- function runBare() {
- $this->setup();
- $this->runTest();
- $this->tearDown();
- }
-}
-
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 1.0.0.0
- *
- */
-class TestSuite /* implements Test */ {
- /* Compose a set of Tests (instances of TestCase or TestSuite), and
- run them all. */
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $fTests = array();
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $fClassname;
-
-/**
- * Enter description here...
- *
- * @param unknown_type $classname
- * @return TestSuite
- */
- function TestSuite($classname=false) {
- // Find all methods of the given class whose name starts with
- // "test" and add them to the test suite.
-
- // PHP3: We are just _barely_ able to do this with PHP's limited
- // introspection... Note that PHP seems to store method names in
- // lower case, and we have to avoid the constructor function for
- // the TestCase class superclass. Names of subclasses of TestCase
- // must not start with "Test" since such a class will have a
- // constructor method name also starting with "test" and we can't
- // distinquish such a construtor from the real test method names.
- // So don't name any TestCase subclasses as "Test..."!
-
- // PHP4: Never mind all that. We can now ignore constructor
- // methods, so a test class may be named "Test...".
-
- if (empty($classname))
- return;
- $this->fClassname = $classname;
-
- if (!class_exists($classname)) {
- user_error('Tested class '.$classname.' doesn\'t appear to exist.', E_USER_WARNING);
- return;
- }
-
- if (floor(phpversion()) >= 4) {
- // PHP4 introspection, submitted by Dylan Kuhn
-
- $names = get_class_methods($classname);
-
- while (list($key, $method) = each($names)) {
- if (preg_match('/^test/', $method)) {
- $test = new $classname($method);
- if (strcasecmp($method, $classname) == 0 || is_subclass_of($test, $method)) {
- // Ignore the given method name since it is a constructor:
- // it's the name of our test class or it is the name of a
- // superclass of our test class. (This code smells funny.
- // Anyone got a better way?)
-
- //print "skipping $method
";
- }
- else {
- $this->addTest($test);
- }
- }
- }
- }
- else { // PHP3
- $dummy = new $classname("dummy");
- $names = (array) $dummy;
- while (list($key, $value) = each($names)) {
- $type = gettype($value);
- if ($type == "user function" && preg_match('/^test/', $key)
- && $key != "testcase") {
- $this->addTest(new $classname($key));
- }
- }
- }
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $test
- */
- function addTest($test) {
- /* Add TestCase or TestSuite to this TestSuite */
- $this->fTests[] = $test;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $testResult
- */
- function run(&$testResult) {
- /* Run all TestCases and TestSuites comprising this TestSuite,
- accumulating results in the given TestResult object. */
- reset($this->fTests);
- while (list($na, $test) = each($this->fTests)) {
- if ($testResult->shouldStop())
- break;
- $test->run(&$testResult);
- }
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function countTestCases() {
- /* Number of TestCases comprising this TestSuite (including those
- in any constituent TestSuites) */
- $count = 0;
- reset($fTests);
- while (list($na, $test_case) = each($this->fTests)) {
- $count += $test_case->countTestCases();
- }
- return $count;
- }
-}
-
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 1.0.0.0
- *
- */
-class TestFailure {
- /* Record failure of a single TestCase, associating it with the
- exception that occurred */
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $fFailedTestName;
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $fException;
-
-/**
- * Enter description here...
- *
- * @param unknown_type $test
- * @param unknown_type $exception
- * @return TestFailure
- */
- function TestFailure(&$test, &$exception) {
- $this->fFailedTestName = $test->name();
- $this->fException = $exception;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function getExceptions() {
- // deprecated
- return array($this->fException);
- }
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function getException() {
- return $this->fException;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function getTestName() {
- return $this->fFailedTestName;
- }
-}
-
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 1.0.0.0
- *
- */
-class TestResult {
- /* Collect the results of running a set of TestCases. */
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $fFailures = array();
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $fErrors = array();
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $fRunTests = 0;
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $fStop = false;
-
-/**
- * Enter description here...
- *
- * @return TestResult
- */
- function TestResult() { }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $test
- */
- function _endTest($test) /* protected */ {
- /* specialize this for end-of-test action, such as progress
- reports */
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $test
- * @param unknown_type $exception
- */
- function addError($test, $exception) {
- $this->fErrors[] = new TestFailure(&$test, &$exception);
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $test
- * @param unknown_type $exception
- */
- function addFailure($test, $exception) {
- $this->fFailures[] = new TestFailure(&$test, &$exception);
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function getFailures() {
- return $this->fFailures;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $test
- */
- function run($test) {
- /* Run a single TestCase in the context of this TestResult */
- $this->_startTest($test);
- $this->fRunTests++;
-
- $test->runBare();
-
- /* this is where JUnit would catch AssertionFailedError */
- $exceptions = $test->getExceptions();
- reset($exceptions);
- while (list($key, $exception) = each($exceptions)) {
- if ($exception->type == 'ERROR')
- $this->addError($test, $exception);
- else if ($exception->type == 'FAILURE')
- $this->addFailure($test, $exception);
- }
- // if ($exceptions)
- // $this->fFailures[] = new TestFailure(&$test, &$exceptions);
- $this->_endTest($test);
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function countTests() {
- return $this->fRunTests;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function shouldStop() {
- return $this->fStop;
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $test
- */
- function _startTest($test) /* protected */ {
- /* specialize this for start-of-test actions */
- }
-
-/**
- * Enter description here...
- *
- */
- function stop() {
- /* set indication that the test sequence should halt */
- $fStop = true;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function errorCount() {
- return count($this->fErrors);
- }
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function failureCount() {
- return count($this->fFailures);
- }
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function countFailures() {
- // deprecated
- return $this->failureCount();
- }
-}
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 1.0.0.0
- *
- */
-class ResultDataMiner extends TestResult {
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $tests = null;
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $total_tests = 0;
-/**
- * Enter description here...
- *
- * @var unknown_type
- */
- var $total_errors = 0;
-
-/**
- * Enter description here...
- *
- * @param unknown_type $test
- */
- function _startTest($test) {
- }
-
-/**
- * Enter description here...
- *
- * @param unknown_type $test
- */
- function _endTest($test) {
- $class_name = $test->classname();
- if (preg_match('/^(.*)test$/i', $class_name, $r))
- $class_name = $r[1];
- $method_name = $test->name();
- if (preg_match('/^test(.*)$/i', $method_name, $r))
- $method_name = $r[1];
-
- $errors = null;
- foreach ($test->getExceptions() as $exception) {
- $errors[] = $exception->message;
- }
-
- $this->tests[] = array(
- 'class' => $class_name,
- 'method' => $method_name,
- 'failed' => $test->failed(),
- 'errors' => $errors
- );
-
- $this->total_tests++;
- if ($test->failed()) $this->total_errors++;
- }
-
-/**
- * Enter description here...
- *
- * @return unknown
- */
- function report () {
- return array('tests'=>$this->total_tests, 'errors'=>$this->total_errors, 'details'=>$this->tests);
- }
-
-}
-
-/**
- * Enter description here...
- *
- *
- * @package cake
- * @subpackage cake.libs
- * @since Cake v 1.0.0.0
- *
- */
-class TestRunner {
- /* Run a suite of tests and report results. */
-/**
- * Enter description here...
- *
- * @param unknown_type $suite
- * @return unknown
- */
- function run($suite) {
- $result = new ResultDataMiner;
- $suite->run($result);
- return $result->report();
- }
-}
-
+ + //
+// + OntoSys, Inc + //
+// + + //
+// + Changes by Michal Tatarynowicz + //
+// +---------------------------------------------------------------------+ //
+// + Permission is hereby granted, free of charge, to any person + //
+// + obtaining a copy of this software and associated documentation + //
+// + files (the "Software"), to deal in the Software without + //
+// + restriction, including without limitation the rights to use, copy, + //
+// + modify, merge, publish, distribute, sublicense, and/or sell copies + //
+// + of the Software, and to permit persons to whom the Software is + //
+// + furnished to do so, subject to the following conditions: + //
+// + + //
+// + The above copyright notice and this permission notice shall be + //
+// + included in all copies or substantial portions of the Software. + //
+// + + //
+// + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + //
+// + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + //
+// + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + //
+// + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + //
+// + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + //
+// + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + //
+// + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + //
+// + SOFTWARE. + //
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: PHP framework for testing, based on the design of "JUnit".
+ *
+ * @filesource
+ * @author Fred Yankowski
+ * @copyright Copyright (c) 2000 Fred Yankowski
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 1.0.0.0
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ */
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $msg
+ */
+function trace($msg) {
+ return;
+ print($msg);
+ flush();
+}
+/**
+ * Enter description here...
+ *
+ */
+if (phpversion() >= '4') {
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $errno
+ * @param unknown_type $errstr
+ * @param unknown_type $errfile
+ * @param unknown_type $errline
+ */
+ function PHPUnit_error_handler($errno, $errstr, $errfile, $errline) {
+ global $PHPUnit_testRunning;
+ $PHPUnit_testRunning[0]->fail("PHP ERROR: ".$errstr." in ".$errfile." at line ".$errline);
+ }
+}
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 1.0.0.0
+ *
+ */
+class TestException {
+ /* Emulate a Java exception, sort of... */
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $message;
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $type;
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $message
+ * @param unknown_type $type
+ * @return TestException
+ */
+ function TestException($message, $type = 'FAILURE') {
+ $this->message = $message;
+ $this->type = $type;
+ }
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function getMessage() {
+ return $this->message;
+ }
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function getType() {
+ return $this->type;
+ }
+}
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 1.0.0.0
+ *
+ */
+class Assert {
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $boolean
+ * @param unknown_type $message
+ */
+ function assert($boolean, $message=0) {
+ if (! $boolean)
+ $this->fail($message);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $expected
+ * @param unknown_type $actual
+ * @param unknown_type $message
+ * @return unknown
+ */
+ function asEq ($expected, $actual, $message=0) {
+ return $this->assertEquals($expected, $actual, $message);
+ }
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $expected
+ * @param unknown_type $actual
+ * @param unknown_type $message
+ */
+ function assertEquals($expected, $actual, $message=0) {
+ if (gettype($expected) != gettype($actual)) {
+ $this->failNotEquals($expected, $actual, "expected", $message);
+ return;
+ }
+
+ if (phpversion() < '4') {
+ if (is_object($expected) or is_object($actual) or is_array($expected) or is_array($actual)) {
+ $this->error("INVALID TEST: cannot compare arrays or objects in PHP3");
+ return;
+ }
+ }
+
+ if (phpversion() >= '4' && is_object($expected)) {
+ if (get_class($expected) != get_class($actual)) {
+ $this->failNotEquals($expected, $actual, "expected", $message);
+ return;
+ }
+
+ if (method_exists($expected, "equals")) {
+ if (! $expected->equals($actual)) {
+ $this->failNotEquals($expected, $actual, "expected", $message);
+ }
+ return; // no further tests after equals()
+ }
+ }
+
+ if (phpversion() >= '4.0.4') {
+ if (is_null($expected) != is_null($actual)) {
+ $this->failNotEquals($expected, $actual, "expected", $message);
+ return;
+ }
+ }
+
+ if ($expected != $actual) {
+ $this->failNotEquals($actual, $expected, "expected", $message);
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $regexp
+ * @param unknown_type $actual
+ * @param unknown_type $message
+ */
+ function assertRegexp($regexp, $actual, $message=false) {
+ if (! preg_match($regexp, $actual)) {
+ $this->failNotEquals($regexp, $actual, "pattern", $message);
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $string0
+ * @param unknown_type $string1
+ * @param unknown_type $message
+ */
+ function assertEqualsMultilineStrings($string0, $string1,
+ $message="") {
+ $lines0 = split("\n",$string0);
+ $lines1 = split("\n",$string1);
+ if (sizeof($lines0) != sizeof($lines1)) {
+ $this->failNotEquals(sizeof($lines0)." line(s)",
+ sizeof($lines1)." line(s)", "expected", $message);
+ }
+ for($i=0; $i< sizeof($lines0); $i++) {
+ $this->assertEquals(trim($lines0[$i]),
+ trim($lines1[$i]),
+ "line ".($i+1)." of multiline strings differ. ".$message);
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $fn
+ */
+ function assertFileExists ($fn) {
+ if (!file_exists($fn))
+ $this->failNotEquals($fn, "file not found", "file expected");
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $fn
+ * @param unknown_type $str
+ */
+ function assertFileContains ($fn, $str) {
+ if (file_exists($fn)) {
+ $lines = file($fn);
+ $text = implode("\n", $lines);
+
+ if (!preg_match("/{$str}/", $text))
+ $this->failNotEquals($fn, 'expected '.$str, 'expected');
+ }
+ else
+ $this->failNotEquals($fn, 'file doesn\'t exist', 'expected');
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $path
+ */
+ function assertDirExists ($path) {
+ if (!is_dir($path))
+ $this->failNotEquals($path, "directory not found", "expected");
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $value
+ */
+ function assertTrue ($value) {
+ if (!$value)
+ $this->failNotEquals($value, true, "expected");
+ }
+
+
+/**
+ * Enter description here...
+ *
+ * @param mixed $value
+ * @return string
+ */
+ function _formatValue ($value) {
+
+ if (is_object($value) && method_exists($value, "toString")) {
+ $valueStr = $value->toString();
+ }
+ elseif (is_bool($value)) {
+ $valueStr = $value? 'false': 'true';
+ }
+ elseif (is_object($value) || is_array($value)) {
+ $valueStr = serialize($value);
+ }
+ else {
+ $valueStr = str_replace('<', '<', str_replace('>', '>', $value));
+ }
+
+ return array($valueStr, gettype($value));
+ }
+
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $expected
+ * @param unknown_type $actual
+ * @param unknown_type $expected_label
+ * @param unknown_type $message
+ */
+ function failNotEquals ($expected, $actual, $expected_label, $message=null) {
+ $out = array(
+ 'message'=>$message,
+ 'label'=>$expected_label,
+ 'expected'=>$this->_formatValue($expected, "expected"),
+ 'actual'=>$this->_formatValue($actual, "actual")
+ );
+
+ $this->fail($out);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $expected
+ * @param unknown_type $actual
+ * @param unknown_type $expected_label
+ * @param unknown_type $message
+ */
+ function old_failNotEquals($expected, $actual, $expected_label, $message=0) {
+ // Private function for reporting failure to match.
+ $str = $message ? ($message . ' ') : '';
+ //$str .= "($expected_label/actual)
";
+ $str .= "
";
+ $str .= sprintf("%s
%s",
+ $this->_formatValue($expected, "expected"),
+ $this->_formatValue($actual, "actual"));
+ $this->fail($str);
+ }
+}
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 1.0.0.0
+ *
+ */
+class TestCase extends Assert /* implements Test */ {
+ /* Defines context for running tests. Specific context -- such as
+ instance variables, global variables, global state -- is defined
+ by creating a subclass that specializes the setUp() and
+ tearDown() methods. A specific test is defined by a subclass
+ that specializes the runTest() method. */
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $fName;
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $fClassName;
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $fResult;
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $fExceptions = array();
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $name
+ * @return TestCase
+ */
+ function TestCase($name) {
+ $this->fName = $name;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $testResult
+ * @return unknown
+ */
+ function run($testResult=0) {
+ /* Run this single test, by calling the run() method of the
+ TestResult object which will in turn call the runBare() method
+ of this object. That complication allows the TestResult object
+ to do various kinds of progress reporting as it invokes each
+ test. Create/obtain a TestResult object if none was passed in.
+ Note that if a TestResult object was passed in, it must be by
+ reference. */
+ if (! $testResult)
+ $testResult = $this->_createResult();
+ $this->fResult = $testResult;
+ $testResult->run(&$this);
+ $this->fResult = 0;
+ return $testResult;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function classname() {
+ if (isset($this->fClassName)) {
+ return $this->fClassName;
+ } else {
+ return get_class($this);
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function countTestCases() {
+ return 1;
+ }
+
+/**
+ * Enter description here...
+ *
+ */
+ function runTest() {
+
+ if (version_compare(phpversion(), '4') >= 0) {
+ global $PHPUnit_testRunning;
+ eval('$PHPUnit_testRunning[0] = & $this;');
+
+ // Saved ref to current TestCase, so that the error handler
+ // can access it. This code won't even parse in PHP3, so we
+ // hide it in an eval.
+
+ $old_handler = set_error_handler("PHPUnit_error_handler");
+ // errors will now be handled by our error handler
+ }
+
+ $name = $this->name();
+ if ((version_compare(phpversion(), '4') >= 0) && ! method_exists($this, $name)) {
+ $this->error("Method '$name' does not exist");
+ }
+ else
+ $this->$name();
+
+ if (version_compare(phpversion(), '4') >= 0) {
+ restore_error_handler(); // revert to prior error handler
+ $PHPUnit_testRunning = null;
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ */
+ function setUp() /* expect override */ {
+ //print("TestCase::setUp()
\n");
+ }
+
+/**
+ * Enter description here...
+ *
+ */
+ function tearDown() /* possible override */ {
+ //print("TestCase::tearDown()
\n");
+ }
+
+ ////////////////////////////////////////////////////////////////
+
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function _createResult() /* protected */ {
+ /* override this to use specialized subclass of TestResult */
+ return new TestResult;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $message
+ */
+ function fail($message=0) {
+ //printf("TestCase::fail(%s)
\n", ($message) ? $message : '');
+ /* JUnit throws AssertionFailedError here. We just record the
+ failure and carry on */
+ $this->fExceptions[] = new TestException(&$message, 'FAILURE');
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $message
+ */
+ function error($message) {
+ /* report error that requires correction in the test script
+ itself, or (heaven forbid) in this testing infrastructure */
+ $this->fExceptions[] = new TestException(&$message, 'ERROR');
+ $this->fResult->stop(); // [does not work]
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function failed() {
+ reset($this->fExceptions);
+ while (list($key, $exception) = each($this->fExceptions)) {
+ if ($exception->type == 'FAILURE')
+ return true;
+ }
+ return false;
+ }
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function errored() {
+ reset($this->fExceptions);
+ while (list($key, $exception) = each($this->fExceptions)) {
+ if ($exception->type == 'ERROR')
+ return true;
+ }
+ return false;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function getExceptions() {
+ return $this->fExceptions;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function name() {
+ return $this->fName;
+ }
+
+/**
+ * Enter description here...
+ *
+ */
+ function runBare() {
+ $this->setup();
+ $this->runTest();
+ $this->tearDown();
+ }
+}
+
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 1.0.0.0
+ *
+ */
+class TestSuite /* implements Test */ {
+ /* Compose a set of Tests (instances of TestCase or TestSuite), and
+ run them all. */
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $fTests = array();
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $fClassname;
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $classname
+ * @return TestSuite
+ */
+ function TestSuite($classname=false) {
+ // Find all methods of the given class whose name starts with
+ // "test" and add them to the test suite.
+
+ // PHP3: We are just _barely_ able to do this with PHP's limited
+ // introspection... Note that PHP seems to store method names in
+ // lower case, and we have to avoid the constructor function for
+ // the TestCase class superclass. Names of subclasses of TestCase
+ // must not start with "Test" since such a class will have a
+ // constructor method name also starting with "test" and we can't
+ // distinquish such a construtor from the real test method names.
+ // So don't name any TestCase subclasses as "Test..."!
+
+ // PHP4: Never mind all that. We can now ignore constructor
+ // methods, so a test class may be named "Test...".
+
+ if (empty($classname))
+ return;
+ $this->fClassname = $classname;
+
+ if (!class_exists($classname)) {
+ user_error('Tested class '.$classname.' doesn\'t appear to exist.', E_USER_WARNING);
+ return;
+ }
+
+ if (floor(phpversion()) >= 4) {
+ // PHP4 introspection, submitted by Dylan Kuhn
+
+ $names = get_class_methods($classname);
+
+ while (list($key, $method) = each($names)) {
+ if (preg_match('/^test/', $method)) {
+ $test = new $classname($method);
+ if (strcasecmp($method, $classname) == 0 || is_subclass_of($test, $method)) {
+ // Ignore the given method name since it is a constructor:
+ // it's the name of our test class or it is the name of a
+ // superclass of our test class. (This code smells funny.
+ // Anyone got a better way?)
+
+ //print "skipping $method
";
+ }
+ else {
+ $this->addTest($test);
+ }
+ }
+ }
+ }
+ else { // PHP3
+ $dummy = new $classname("dummy");
+ $names = (array) $dummy;
+ while (list($key, $value) = each($names)) {
+ $type = gettype($value);
+ if ($type == "user function" && preg_match('/^test/', $key)
+ && $key != "testcase") {
+ $this->addTest(new $classname($key));
+ }
+ }
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $test
+ */
+ function addTest($test) {
+ /* Add TestCase or TestSuite to this TestSuite */
+ $this->fTests[] = $test;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $testResult
+ */
+ function run(&$testResult) {
+ /* Run all TestCases and TestSuites comprising this TestSuite,
+ accumulating results in the given TestResult object. */
+ reset($this->fTests);
+ while (list($na, $test) = each($this->fTests)) {
+ if ($testResult->shouldStop())
+ break;
+ $test->run(&$testResult);
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function countTestCases() {
+ /* Number of TestCases comprising this TestSuite (including those
+ in any constituent TestSuites) */
+ $count = 0;
+ reset($fTests);
+ while (list($na, $test_case) = each($this->fTests)) {
+ $count += $test_case->countTestCases();
+ }
+ return $count;
+ }
+}
+
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 1.0.0.0
+ *
+ */
+class TestFailure {
+ /* Record failure of a single TestCase, associating it with the
+ exception that occurred */
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $fFailedTestName;
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $fException;
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $test
+ * @param unknown_type $exception
+ * @return TestFailure
+ */
+ function TestFailure(&$test, &$exception) {
+ $this->fFailedTestName = $test->name();
+ $this->fException = $exception;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function getExceptions() {
+ // deprecated
+ return array($this->fException);
+ }
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function getException() {
+ return $this->fException;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function getTestName() {
+ return $this->fFailedTestName;
+ }
+}
+
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 1.0.0.0
+ *
+ */
+class TestResult {
+ /* Collect the results of running a set of TestCases. */
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $fFailures = array();
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $fErrors = array();
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $fRunTests = 0;
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $fStop = false;
+
+/**
+ * Enter description here...
+ *
+ * @return TestResult
+ */
+ function TestResult() { }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $test
+ */
+ function _endTest($test) /* protected */ {
+ /* specialize this for end-of-test action, such as progress
+ reports */
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $test
+ * @param unknown_type $exception
+ */
+ function addError($test, $exception) {
+ $this->fErrors[] = new TestFailure(&$test, &$exception);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $test
+ * @param unknown_type $exception
+ */
+ function addFailure($test, $exception) {
+ $this->fFailures[] = new TestFailure(&$test, &$exception);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function getFailures() {
+ return $this->fFailures;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $test
+ */
+ function run($test) {
+ /* Run a single TestCase in the context of this TestResult */
+ $this->_startTest($test);
+ $this->fRunTests++;
+
+ $test->runBare();
+
+ /* this is where JUnit would catch AssertionFailedError */
+ $exceptions = $test->getExceptions();
+ reset($exceptions);
+ while (list($key, $exception) = each($exceptions)) {
+ if ($exception->type == 'ERROR')
+ $this->addError($test, $exception);
+ else if ($exception->type == 'FAILURE')
+ $this->addFailure($test, $exception);
+ }
+ // if ($exceptions)
+ // $this->fFailures[] = new TestFailure(&$test, &$exceptions);
+ $this->_endTest($test);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function countTests() {
+ return $this->fRunTests;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function shouldStop() {
+ return $this->fStop;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $test
+ */
+ function _startTest($test) /* protected */ {
+ /* specialize this for start-of-test actions */
+ }
+
+/**
+ * Enter description here...
+ *
+ */
+ function stop() {
+ /* set indication that the test sequence should halt */
+ $fStop = true;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function errorCount() {
+ return count($this->fErrors);
+ }
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function failureCount() {
+ return count($this->fFailures);
+ }
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function countFailures() {
+ // deprecated
+ return $this->failureCount();
+ }
+}
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 1.0.0.0
+ *
+ */
+class ResultDataMiner extends TestResult {
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $tests = null;
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $total_tests = 0;
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $total_errors = 0;
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $test
+ */
+ function _startTest($test) {
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $test
+ */
+ function _endTest($test) {
+ $class_name = $test->classname();
+ if (preg_match('/^(.*)test$/i', $class_name, $r))
+ $class_name = $r[1];
+ $method_name = $test->name();
+ if (preg_match('/^test(.*)$/i', $method_name, $r))
+ $method_name = $r[1];
+
+ $errors = null;
+ foreach ($test->getExceptions() as $exception) {
+ $errors[] = $exception->message;
+ }
+
+ $this->tests[] = array(
+ 'class' => $class_name,
+ 'method' => $method_name,
+ 'failed' => $test->failed(),
+ 'errors' => $errors
+ );
+
+ $this->total_tests++;
+ if ($test->failed()) $this->total_errors++;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function report () {
+ return array('tests'=>$this->total_tests, 'errors'=>$this->total_errors, 'details'=>$this->tests);
+ }
+
+}
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 1.0.0.0
+ *
+ */
+class TestRunner {
+ /* Run a suite of tests and report results. */
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $suite
+ * @return unknown
+ */
+ function run($suite) {
+ $result = new ResultDataMiner;
+ $suite->run($result);
+ return $result->report();
+ }
+}
+
?>
\ No newline at end of file
diff --git a/public/.htaccess b/public/.htaccess
index bee15b3c9..d62ca53b7 100644
--- a/public/.htaccess
+++ b/public/.htaccess
@@ -1,9 +1,13 @@
# Based on Rails 0.10.0 .htaccess (www.rubyonrails.com)
+
+
# Redirect all requests not available on the filesystem to Cake
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
-RewriteRule ^(.*)$ dispatch.php?url=$1 [QSA,L]
+RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
# In case Cake experiences terminal errors
ErrorDocument 500 500.html
+
+
diff --git a/public/css/default.css b/public/css/default.css
index e69de29bb..e50770bb9 100644
--- a/public/css/default.css
+++ b/public/css/default.css
@@ -0,0 +1,57 @@
+BODY {
+font-size:.9em;
+}
+
+BODY, INPUT, TEXTAREA {
+font-family:sans-serif;
+}
+
+H1 {
+font-size:2.1em;
+text-align:center;
+}
+
+H2 {
+font-size:1.8em;
+}
+
+H3 {
+font-size:1.5em;
+}
+
+P {
+font-size:1em;
+margin-bottom:.5em;
+}
+
+A {
+white-space:nowrap;
+text-decoration:underline;
+}
+
+CODE, PRE {
+font-family:monospace;
+font-size:1.1em !important;
+font-size:.95em;
+color:#44A;
+margin:0;
+}
+
+CODE {
+color:#227;
+white-space:nowrap;
+margin:0 .2em;
+}
+
+PRE {
+margin-left:1em;
+}
+
+ACRONYM {
+border-bottom:1px dotted;
+}
+
+HR {
+height:0;
+border-top:1px solid #AAA;
+}
diff --git a/public/dispatch.php b/public/dispatch.php
deleted file mode 100644
index 37643677d..000000000
--- a/public/dispatch.php
+++ /dev/null
@@ -1,67 +0,0 @@
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Purpose: Dispatch
- * The main "loop"
- *
- * @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.public
- * @since Cake v 0.2.9
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
- */
-
-session_start();
-
-/**
- * Get Cake's root directory
- */
-define ('DS', DIRECTORY_SEPARATOR);
-define ('ROOT', substr(__FILE__, 0, strrpos(dirname(__FILE__), DS)+1));
-
-/**
- * Directory layout and basic functions
- */
-require (ROOT.'config/core.php');
-require (ROOT.'config/paths.php');
-require (ROOT.'libs/basics.php');
-
-DEBUG? error_reporting(E_ALL): error_reporting(0);
-
-$TIME_START = getMicrotime();
-
-uses ('folder', 'dispatcher', 'dbo_factory');
-config ('tags', 'database');
-
-$DB = DboFactory::make('devel');
-
-loadModels ();
-
-## RUN THE SCRIPT
-$url = empty($_GET['url'])? null: $_GET['url'];
-$DISPATCHER = new Dispatcher ();
-$DISPATCHER->dispatch($url);
-
-## CLEANUP
-if (DEBUG) echo "";
-
-?>
diff --git a/public/index.php b/public/index.php
index 0a51647db..43cb2f504 100644
--- a/public/index.php
+++ b/public/index.php
@@ -1,4 +1,4 @@
-
+define ('DS', DIRECTORY_SEPARATOR);
+define ('ROOT', dirname(dirname(__FILE__)).DS);
+
+/**
+ * Directory layout and basic functions
+ */
+require (ROOT.'config/core.php');
+require (ROOT.'config/paths.php');
+require (ROOT.'libs/basics.php');
+
+DEBUG? error_reporting(E_ALL): error_reporting(0);
+
+$TIME_START = getMicrotime();
+
+uses ('folder', 'dispatcher', 'dbo_factory');
+config ('tags', 'database');
+
+$DB = DboFactory::make('devel');
+
+loadModels ();
+
+## RUN THE SCRIPT
+$url = empty($_GET['url'])? null: $_GET['url'];
+$DISPATCHER = new Dispatcher ();
+$DISPATCHER->dispatch($url);
+
+## CLEANUP
+if (DEBUG) echo "";
+
+?>
\ No newline at end of file
diff --git a/public/index_no_mod_rewrite.php b/public/index_no_mod_rewrite.php
new file mode 100644
index 000000000..26bd5e96c
--- /dev/null
+++ b/public/index_no_mod_rewrite.php
@@ -0,0 +1,37 @@
+ + //
+// + 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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Enter description here...
+ *
+ * @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.public
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+
+/**
+ * Re-routes the request to dispatch.php
+ */
+include('dispatch.php')
+// header ('dispatch.php?url='.ltrim($_SERVER['PATH_INFO'],'/'));
+?>
diff --git a/scripts/add.bat b/scripts/add.bat
deleted file mode 100644
index 2eb456cfc..000000000
--- a/scripts/add.bat
+++ /dev/null
@@ -1 +0,0 @@
-@php -q scripts/add.php %1 %2 %3 %4 %5 %6 %7 %8 %9
\ No newline at end of file
diff --git a/scripts/bake.bat b/scripts/bake.bat
new file mode 100644
index 000000000..1c8cdd926
--- /dev/null
+++ b/scripts/bake.bat
@@ -0,0 +1 @@
+@php -q add.php %1 %2 %3 %4 %5 %6 %7 %8 %9
\ No newline at end of file
diff --git a/scripts/add.php b/scripts/bake.php
similarity index 93%
rename from scripts/add.php
rename to scripts/bake.php
index a736cec67..a131538f8 100644
--- a/scripts/add.php
+++ b/scripts/bake.php
@@ -1,48 +1,48 @@
-#!/usr/local/bin/php
- + //
-// + 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 + //
-//////////////////////////////////////////////////////////////////////////
-
-/**
- * Enter description here...
- *
- * @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.scripts
- * @since Cake v 0.2.9
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
- */
-
-/**
- * START-UP
- */
-define ('DS', DIRECTORY_SEPARATOR);
-define ('ROOT', substr(__FILE__, 0, strrpos(dirname(__FILE__), DS)+1));
-
-require (ROOT.'config'.DS.'paths.php');
-require (LIBS.'basics.php');
-uses ('bake');
-
-$waste = array_shift($argv);
-$product = array_shift($argv);
-
-$bake = new Bake ($product, $argv);
-
+#!/usr/local/bin/php
+ + //
+// + 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 + //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Enter description here...
+ *
+ * @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.scripts
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+
+/**
+ * START-UP
+ */
+define ('DS', DIRECTORY_SEPARATOR);
+define ('ROOT', dirname(dirname(__FILE__)).DS);
+
+require (ROOT.'config'.DS.'paths.php');
+require (LIBS.'basics.php');
+uses ('bake');
+
+$waste = array_shift($argv);
+$product = array_shift($argv);
+
+$bake = new Bake ($product, $argv);
+
?>
\ No newline at end of file
diff --git a/app/controllers/put_controllers_here b/tests/app/controllers/put_controller_tests_here
similarity index 100%
rename from app/controllers/put_controllers_here
rename to tests/app/controllers/put_controller_tests_here
diff --git a/tests/app/helpers/put_helper_tests_here b/tests/app/helpers/put_helper_tests_here
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/app/models/put_model_tests_here b/tests/app/models/put_model_tests_here
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/libs/dbo_factory_test.php b/tests/libs/dbo_factory_test.php
index 35cf66386..844322e5f 100644
--- a/tests/libs/dbo_factory_test.php
+++ b/tests/libs/dbo_factory_test.php
@@ -26,22 +26,25 @@ class DboFactoryTest extends TestCase {
function testMake () {
- $output = $this->abc->make('test');
- $this->assertTrue(is_object($output));
+ if (class_exists(DATABASE_CONFIG)) {
- $config = DATABASE_CONFIG::test();
- if (preg_match('#^(adodb)_.*$#i', $config['driver'], $res)) {
- $desired_driver_name = $res[1];
+ $output = $this->abc->make('test');
+ $this->assertTrue(is_object($output));
+
+ $config = DATABASE_CONFIG::test();
+ if (preg_match('#^(adodb)_.*$#i', $config['driver'], $res)) {
+ $desired_driver_name = $res[1];
+ }
+ else
+ $desired_driver_name = $config['driver'];
+
+ $desired_class_name = 'dbo_'.strtolower($desired_driver_name);
+ $output_class_name = is_object($output)? get_class($output): false;
+
+ $this->assertEquals($output_class_name, $desired_class_name);
+
+ $this->assertTrue($output->connected);
}
- else
- $desired_driver_name = $config['driver'];
-
- $desired_class_name = 'dbo_'.strtolower($desired_driver_name);
- $output_class_name = is_object($output)? get_class($output): false;
-
- $this->assertEquals($output_class_name, $desired_class_name);
-
- $this->assertTrue($output->connected);
}
// this test expect an E_USER_ERROR to occur during it's run
diff --git a/tests/libs/dbo_test.php b/tests/libs/dbo_test.php
index d503ce968..06c9db41c 100644
--- a/tests/libs/dbo_test.php
+++ b/tests/libs/dbo_test.php
@@ -22,10 +22,14 @@ class DboTest extends TestCase {
// this function is defined in PHPUnit_TestCase and overwritten
// here
function tearDown() {
+ if (!$this->abc) return false;
+
$this->dropTemporaryTable();
}
function createTemporaryTable () {
+ if (!$this->abc) return false;
+
if ($this->abc->config['driver'] == 'postgres')
$sql = 'CREATE TABLE __test (id serial NOT NULL, body CHARACTER VARYING(255))';
else
@@ -35,10 +39,14 @@ class DboTest extends TestCase {
}
function dropTemporaryTable () {
+ if (!$this->abc) return false;
+
return $this->abc->query("DROP TABLE __test");
}
function testHasImplementation () {
+ if (!$this->abc) return false;
+
$functions = array(
'connect',
'disconnect',
@@ -59,15 +67,21 @@ class DboTest extends TestCase {
}
function testConnectivity () {
+ if (!$this->abc) return false;
+
$this->assertTrue($this->abc->connected);
}
function testFields () {
+ if (!$this->abc) return false;
+
$fields = $this->abc->fields('__test');
$this->assertEquals(count($fields), 2, 'equals');
}
function testTables () {
+ if (!$this->abc) return false;
+
$this->assertTrue(in_array('__test', $this->abc->tables()));
}
}
diff --git a/tests/libs/folder_test.php b/tests/libs/folder_test.php
index bf62eaaa5..0a323164a 100644
--- a/tests/libs/folder_test.php
+++ b/tests/libs/folder_test.php
@@ -27,7 +27,7 @@ class FolderTest extends TestCase {
function testLs () {
$result = $this->abc->ls();
- $expected = array(array('css', 'files', 'img'),array('.htaccess', '500.html', 'dispatch.php'));
+ $expected = array(array('css', 'files', 'img'),array('.htaccess', '500.html', 'index.php', 'index_no_mod_rewrite.php'));
$this->assertEquals($result, $expected);
}
@@ -48,8 +48,8 @@ class FolderTest extends TestCase {
}
function testFindRecursive () {
- $result = $this->abc->findRecursive('.*\.php');
- $expected = array(Folder::addPathElement($this->abc->pwd(), 'dispatch.php'));
+ $result = $this->abc->findRecursive('.*ex\.php');
+ $expected = array(Folder::addPathElement($this->abc->pwd(), 'index.php'));
$this->assertEquals($result, $expected);
}
diff --git a/vendors/put_vendor_libraries_here b/vendors/put_vendor_libraries_here
new file mode 100644
index 000000000..e69de29bb