Skip to content
Browse files

- Two standard controllers -- PageController and TestsController

- Helpers for controllers -- each controller has it's own helper in the /app/helpers directory
- /logs and /modules directories
- The application runs just fine without /config/database.php if controllers don't ask for db access
- Changed the name of /public/dispatch.php to /public/index.php, it's nicer and more standard, won't you agree? Kamil's fix for no-mod_rewrite needs to be re-implemented
- Cleanups, fixes, and even one or two comments ;)

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@158 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
1 parent 3dd8d77 commit 4a87a753321926632b7ebfea66b76691e38e6a6c pies committed May 22, 2005
Showing with 5,093 additions and 4,745 deletions.
  1. +1 −1 app/app_controller.php
  2. +1 −1 app/app_model.php
  3. +22 −0 app/controllers/pages_controller.php
  4. +43 −0 app/controllers/tests_controller.php
  5. +2 −0 app/views/layouts/default.thtml
  6. +91 −0 app/views/layouts/test.thtml
  7. +27 −0 app/views/pages/home.thtml
  8. +29 −0 app/views/tests/test_all.thtml
  9. +2 −2 config/core.php
  10. +24 −16 config/paths.php
  11. +53 −47 config/routes.php
  12. +1 −1 config/routes.php.default
  13. +19 −14 index.php
  14. +15 −9 libs/bake.php
  15. +282 −276 libs/basics.php
  16. +0 −2 libs/cache.php
  17. +584 −585 libs/controller.php
  18. +409 −410 libs/dbo.php
  19. +169 −169 libs/dbo_adodb.php
  20. +2 −0 libs/dbo_factory.php
  21. +188 −188 libs/dbo_mysql.php
  22. +194 −194 libs/dbo_postgres.php
  23. +246 −246 libs/dispatcher.php
  24. +121 −121 libs/error_messages.php
  25. +174 −174 libs/flay.php
  26. +1 −4 libs/inflector.php
  27. +20 −0 libs/legacy.php
  28. +621 −621 libs/model.php
  29. +10 −0 libs/object.php
  30. +168 −168 libs/router.php
  31. +286 −286 libs/template.php
  32. +1,061 −1,061 libs/test.php
  33. +5 −1 public/.htaccess
  34. +57 −0 public/css/default.css
  35. +0 −67 public/dispatch.php
  36. +48 −18 public/index.php
  37. +37 −0 public/index_no_mod_rewrite.php
  38. +0 −1 scripts/add.bat
  39. +1 −0 scripts/bake.bat
  40. +47 −47 scripts/{add.php → bake.php}
  41. 0 app/controllers/put_controllers_here → tests/app/controllers/put_controller_tests_here
  42. 0 tests/app/helpers/put_helper_tests_here
  43. 0 tests/app/models/put_model_tests_here
  44. +15 −12 tests/libs/dbo_factory_test.php
  45. +14 −0 tests/libs/dbo_test.php
  46. +3 −3 tests/libs/folder_test.php
  47. 0 vendors/put_vendor_libraries_here
View
2 app/app_controller.php
@@ -42,4 +42,4 @@
class AppController extends Controller {
}
-?>
+?>
View
2 app/app_model.php
@@ -42,4 +42,4 @@
class AppModel extends Model {
}
-?>
+?>
View
22 app/controllers/pages_controller.php
@@ -0,0 +1,22 @@
+<?PHP
+
+class PagesController extends PagesHelper {
+
+ function view () {
+
+ if (!func_num_args())
+ $this->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));
+ }
+
+}
+
+?>
View
43 app/controllers/tests_controller.php
@@ -0,0 +1,43 @@
+<?PHP
+
+uses('test', 'folder', 'inflector');
+
+class TestsController extends TestsHelper {
+
+ function test_all () {
+
+ $this->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);
+ }
+
+}
+
+?>
View
2 app/views/layouts/default.thtml
@@ -8,6 +8,8 @@
<body>
+<h1><?=$title_for_layout?></h1>
+
<?=$content_for_layout?>
</body>
View
91 app/views/layouts/test.thtml
@@ -0,0 +1,91 @@
+<html>
+<head>
+<style type="text/css"><!--
+
+BODY {
+font:normal .9em Arial,sans-serif;
+color:Black;
+}
+TABLE {
+margin-left:3em;
+border-collapse:collapse;
+border:2px solid #DDD;
+}
+TH, TD {
+font:normal .8em Tahoma, sans-serif;
+}
+TH {
+text-align:left;
+padding:.4em .3em .1em .3em;
+}
+TH B {
+font:bold 1.2em Arial,sans-serif;
+}
+TD {
+padding:.1em .55em;
+}
+TR.fail TD {
+font-weight:bold;
+color:#FFF;
+background-color:#F31;
+}
+TR.info TD {
+background-color:#F8F8F8;
+padding:.5em 1em .5em 2em;
+}
+TR.info .ok {
+ color:Green;
+}
+TR.info .not {
+ color:Red;
+}
+TR.info EM {
+ color:Gray;
+ font-style:normal;
+}
+TR.unkn TD {
+background-color:#FF0;
+}
+TR.pass TD, TR.expected TD {
+color:Green;
+}
+
+CODE {
+font-size:1.2em;
+}
+CODE.expected {
+color: green;
+}
+CODE.actual {
+color: red;
+}
+.typeinfo {
+color: gray;
+}
+
+
+.box {
+font-size:3em;
+text-align:center;
+margin-top:1em;
+}
+.box B {
+color:#FFF;
+padding:.3em .6em;
+background-color:#BBB;
+}
+#ok B {
+background-color:#82AF15;
+}
+#error B {
+background-color:#C2361B;
+}
+
+--></style>
+
+<body>
+
+<?=$content_for_layout?>
+
+</body>
+</html>
View
27 app/views/pages/home.thtml
@@ -0,0 +1,27 @@
+<h2>Cake works!</h2>
+
+<p>Your installation of Cake is functional. Edit <code>/app/views/pages/home.thtml</code> to change the contents of this page.</p>
+
+<h2>Introducing Cake</h2>
+
+<p>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 &ndash; they don't usually re-use their code. And I was one of them. (<?=$this->linkOut('continued...','http://sputnik.pl/docs/intro')?>)</p>
+
+<h2>Features</h2>
+
+<p><ul>
+<li>compatibile with PHP4 and PHP5</li>
+<li>supplies integrated <acronym title="Create, Read, Update, Delete">CRUD</acronym> for database and simplified querying so you shouldn't need to write SQL for basic operations (although <em>some</em> familiarity with SQL is strongly recommended)</li>
+<li>request dispatcher with good looking, custom URLs</li>
+<li>fast, flexible templating (PHP syntax with helper methods)</li>
+<li>works from a website subdirectory, with very little Apache configuration involved (requires <code>.htaccess</code> files and <code>mod_rewrite</code> to work; these are available on most web servers)</li>
+</ul></p>
+
+<p>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 <acronym title="Create, Read, Update, Delete">CRUD</acronym> functionality but with no joins between tables yet. The Controller is working and has the most basic functions (including <code>render()</code> for templating).</p>
+
+<h2>Getting involved</h2>
+
+<p><b>NEW! <?=$this->linkOut('My Amazon Wishlish','http://www.amazon.com/gp/registry/registry.html?id=NODP8QT6LFTO')?></b> for when you'll want to show your appreciation.</p>
+
+<p><?=$this->linkOut('Cake PHP Google Group','http://groups-beta.google.com/group/cake-php')?> &middot; <?=$this->linkOut('Cake Wiki (temporary)','http://cake.bplusf.net/')?> &middot; <?=$this->linkOut('Cake TRAC (SVN repository, etc.)','https://developers.nextco.com/cake')?><a href=""></a></p>
+
+<p>See <?=$this->linkOut('Cake website','http://sputnik.pl/cake')?> for more information.</p>
View
29 app/views/tests/test_all.thtml
@@ -0,0 +1,29 @@
+<?PHP if ($success) { ?>
+<p class="box" id="ok"><b>PASSED</b></p>
+<?PHP } else { ?>
+<p class="box" id="error"><b>FAILED</b></p>
+<?PHP } ?>
+
+<table>
+<?PHP foreach ($results as $r) {
+$performed = $r['result']['tests'];
+if ($performed||1) {
+?>
+<tr><th><b><?=$r['name']?></b> <?=$performed?> test<?=$performed==1?'':'s'?></th></tr>
+<?PHP if ($r['result']['tests']) {
+ foreach ($r['result']['details'] as $detail) {
+ if ($detail['failed']) { ?>
+<tr class="fail"><td><?=$r['name']?>::<?=$detail['method']?></td></tr>
+ <?PHP foreach ($detail['errors'] as $error) { ?>
+<tr class="info"><td>
+<span class="ok"><?=$error['expected'][0]?></span> <em><?=$error['expected'][1]?></em><br />
+<span class="not"><?=$error['actual'][0]?></span> <em><?=$error['actual'][1]?></em>
+</td></tr>
+<?PHP
+ }
+ }
+ else { ?>
+<tr class="pass"><td><?=$r['name']?>::<?=$detail['method']?></td></tr>
+
+<?PHP } } } } } ?>
+</table>
View
4 config/core.php
@@ -36,6 +36,6 @@
* - 1: development
* - 2: full debug with sql
*/
-define ('DEBUG', 0);
+define ('DEBUG', 1);
-?>
+?>
View
40 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 @@
/**
* 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);
?>
View
100 config/routes.php
@@ -1,47 +1,53 @@
-<?PHP
-//////////////////////////////////////////////////////////////////////////
-// + $Id$
-// +------------------------------------------------------------------+ //
-// + Cake <https://developers.nextco.com/cake/> + //
-// + Copyright: (c) 2005, Cake Authors/Developers + //
-// + Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> + //
-// + Larry E. Masters aka PhpNut <nut@phpnut.com> + //
-// + Kamil Dzielinski aka Brego <brego.dk@gmail.com> + //
-// +------------------------------------------------------------------+ //
-// + Licensed under The MIT License + //
-// + Redistributions of files must retain the above copyright notice. + //
-// + 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'));
-
-?>
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <https://developers.nextco.com/cake/> + //
+// + Copyright: (c) 2005, Cake Authors/Developers + //
+// + Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> + //
+// + Larry E. Masters aka PhpNut <nut@phpnut.com> + //
+// + Kamil Dzielinski aka Brego <brego.dk@gmail.com> + //
+// +------------------------------------------------------------------+ //
+// + Licensed under The MIT License + //
+// + Redistributions of files must retain the above copyright notice. + //
+// + 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'));
+
+?>
View
2 config/routes.php.default
@@ -44,4 +44,4 @@ $Route->connect ('/', array('controller'=>'Pages', 'action'=>'index'));
*/
$Route->connect ('/test', array('controller'=>'Tests', 'action'=>'test_all'));
-?>
+?>
View
33 index.php
@@ -1,4 +1,4 @@
-<?php
+<?PHP
//////////////////////////////////////////////////////////////////////////
// + $Id$
// +------------------------------------------------------------------+ //
@@ -16,27 +16,32 @@
/**
* This file collects requests if no mod_rewrite is avilable and / is used
* instead of /public/ as a web root.
- *
- * @filesource
- * @author Cake Authors/Developers
- * @copyright Copyright (c) 2005, Cake Authors/Developers
- * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
- * @package cake
- * @since Cake v 0.2.9
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ *
+ * @filesource
+ * @author Cake Authors/Developers
+ * @copyright Copyright (c) 2005, Cake Authors/Developers
+ * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
+ * @package cake
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+/**
+ * Get Cake's root directory
*/
+define ('DS', DIRECTORY_SEPARATOR);
+define ('ROOT', dirname(__FILE__).DS);
/**
* We need to redefine some constants and variables, so that Cake knows it is
* working without mod_rewrite.
*/
define ('BASE_URL', $_SERVER['SCRIPT_NAME']);
-define ('ROOT', dirname($_SERVER['SCRIPT_FILENAME']).'/');
$_GET['url'] = ltrim($_SERVER['PATH_INFO'],'/');
-require ROOT.'public/dispatch.php';
+require (ROOT.'public/dispatch.php');
+
?>
View
24 libs/bake.php
@@ -149,6 +149,9 @@ function __construct ($type, $names) {
$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 @@ function __construct ($type, $names) {
*/
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'), "<p>Edit <b>app/views/{$path}</b> to change this message.</p>"));
+ $this->createFile($fn, sprintf($this->template('view'), "<p>Edit <b>app".DS."views".DS."{$path}</b> to change this message.</p>"));
$this->actions++;
}
@@ -452,11 +455,12 @@ function getModelName ($name) {
* @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,20 +471,20 @@ function createFile ($path, $contents) {
elseif ($key=='y') {
}
else {
- fwrite($this->stdout, "Skip {$path}\n");
+ fwrite($this->stdout, "Skip {$shortPath}\n");
return false;
}
}
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 @@ function createDir ($path) {
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;
}
View
558 libs/basics.php
@@ -1,276 +1,282 @@
-<?PHP
-//////////////////////////////////////////////////////////////////////////
-// + $Id$
-// +------------------------------------------------------------------+ //
-// + Cake <https://developers.nextco.com/cake/> + //
-// + Copyright: (c) 2005, Cake Authors/Developers + //
-// + Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> + //
-// + Larry E. Masters aka PhpNut <nut@phpnut.com> + //
-// + Kamil Dzielinski aka Brego <brego.dk@gmail.com> + //
-// +------------------------------------------------------------------+ //
-// + Licensed under The MIT License + //
-// + Redistributions of files must retain the above copyright notice. + //
-// + 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:
- * <code>
- * uses('inflector', 'object');
- * </code>
- *
- * @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<pre>\n";
- if ($show_html) $var = str_replace('<', '&lt;', str_replace('>', '&gt;', $var));
- print_r($var);
- print "\n</pre>\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;
- }
-}
-
-?>
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <https://developers.nextco.com/cake/> + //
+// + Copyright: (c) 2005, Cake Authors/Developers + //
+// + Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> + //
+// + Larry E. Masters aka PhpNut <nut@phpnut.com> + //
+// + Kamil Dzielinski aka Brego <brego.dk@gmail.com> + //
+// +------------------------------------------------------------------+ //
+// + Licensed under The MIT License + //
+// + Redistributions of files must retain the above copyright notice. + //
+// + 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:
+ * <code>
+ * uses('inflector', 'object');
+ * </code>
+ *
+ * @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<pre>\n";
+ if ($show_html) $var = str_replace('<', '&lt;', str_replace('>', '&gt;', $var));
+ print_r($var);
+ print "\n</pre>\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;
+ }
+}
+
+?>
View
2 libs/cache.php
@@ -39,11 +39,9 @@
/**
* Enter description here...
*
- *
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
- *
*/
class Cache extends Model {
View
1,169 libs/controller.php
@@ -1,586 +1,585 @@
-<?PHP
-//////////////////////////////////////////////////////////////////////////
-// + $Id$
-// +------------------------------------------------------------------+ //
-// + Cake <https://developers.nextco.com/cake/> + //
-// + Copyright: (c) 2005, Cake Authors/Developers + //
-// + Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> + //
-// + Larry E. Masters aka PhpNut <nut@phpnut.com> + //
-// + Kamil Dzielinski aka Brego <brego.dk@gmail.com> + //
-// +------------------------------------------------------------------+ //
-// + Licensed under The MIT License + //
-// + Redistributions of files must retain the above copyright notice. + //
-// + 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("<a href=\"{$this->base}\">START</a>");
- foreach ($this->_crumbs as $crumb) {
- $out[] = "<a href=\"{$this->base}{$crumb[1]}\">{$crumb[0]}</a>";
- }
-
- return join(' &raquo; ', $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)));
- }
-}
-
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <https://developers.nextco.com/cake/> + //
+// + Copyright: (c) 2005, Cake Authors/Developers + //
+// + Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> + //
+// + Larry E. Masters aka PhpNut <nut@phpnut.com> + //
+// + Kamil Dzielinski aka Brego <brego.dk@gmail.com> + //
+// +------------------------------------------------------------------+ //
+// + Licensed under The MIT License + //
+// + Redistributions of files must retain the above copyright notice. + //
+// + 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'] =