Skip to content
Browse files

moving cake to a sub directory

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@106 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
1 parent d832800 commit cd86555549ac17aeaa28abecaf450b49ce5ae663 @phpnut phpnut committed May 15, 2005
View
7 .htaccess
@@ -0,0 +1,7 @@
+<IfModule mod_rewrite.c>
+ RewriteEngine on
+ RewriteRule ^$ public/ [L]
+
+ #RewriteCond %{REQUEST_URI} !^/cake$
+ RewriteRule (.*) public/$1 [L]
+</IfModule>
View
104 app/app_controller.php
@@ -0,0 +1,104 @@
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <http://sputnik.pl/cake> + //
+// + Copyright: (c) 2005 Michal Tatarynowicz + //
+// + + //
+// + Author(s): (c) 2005 Michal Tatarynowicz <tatarynowicz@gmail.com> + //
+// + + //
+// +------------------------------------------------------------------+ //
+// + Licensed under the Public Domain Licence + //
+// +------------------------------------------------------------------+ //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: AppController
+ * Enter description here...
+ *
+ * @filesource
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @author Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @copyright Copyright (c) 2005, Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @package cake
+ * @subpackage cake.app
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @license Public_Domain
+ *
+ */
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.app
+ * @since Cake v 0.2.9
+ *
+ */
+class AppController extends Controller {
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tags
+ * @param unknown_type $active
+ * @return unknown
+ */
+ function tags_as_links ($tags, $active=array()) {
+ $tags = is_array($tags)? $tags: Tag::split_tags($tags);
+
+ $links = array();
+ foreach ($tags as $tag) {
+
+ if (in_array($tag, $active))
+ $url_tags = $this->array_except($active, $tag);
+ else
+ $url_tags = array_merge($active, array($tag));
+
+ $url = '/memes/with_tags/'.$this->tags_to_url($url_tags);
+
+ $links[] = $this->link_to($tag, $url, in_array($tag, $active)? array('class'=>'active_tag'): null);
+ }
+
+ return join(' ', $links);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $array
+ * @param unknown_type $except
+ * @return unknown
+ */
+ function array_except ($array, $except) {
+ if (!is_array($except)) $except = array($except);
+ $out = array();
+
+ foreach ($array as $k=>$v) {
+ if (!in_array($v, $except))
+ $out[$k] = $v;
+ }
+
+ return $out;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tags
+ * @return unknown
+ */
+ function tags_to_url ($tags) {
+ $out = array();
+ foreach ($tags as $tag)
+ $out[] = urlencode($tag);
+
+ return join('+', $out);
+ }
+
+}
+
+?>
View
44 app/app_model.php
@@ -0,0 +1,44 @@
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <http://sputnik.pl/cake> + //
+// + Copyright: (c) 2005 Michal Tatarynowicz + //
+// + + //
+// + Author(s): (c) 2005 Michal Tatarynowicz <tatarynowicz@gmail.com> + //
+// + + //
+// +------------------------------------------------------------------+ //
+// + Licensed under the Public Domain Licence + //
+// +------------------------------------------------------------------+ //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: AppModel
+ * Enter description here...
+ *
+ * @filesource
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @author Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @copyright Copyright (c) 2005, Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @package cake
+ * @subpackage cake.app
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @license Public_Domain
+ *
+ */
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.app
+ * @since Cake v 0.2.9
+ *
+ */
+class AppModel extends Model {
+}
+
+?>
View
0 app/controllers/put_controllers_here
No changes.
View
0 app/models/put_models_here
No changes.
View
14 app/views/layouts/default.thtml
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="pl" xml:lang="pl">
+<head>
+ <title><?=$title_for_layout?></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <link rel="stylesheet" type="text/css" href="<?=$BASE?>/css/default.css" />
+</head>
+
+<body>
+
+<?=$content_for_layout?>
+
+</body>
+</html>
View
11 app/views/layouts/error.thtml
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+<html>
+<head>
+<title><?=$code?> <?=$name?></title>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+</head>
+<body>
+<h1><?=$name?></h1>
+<p><?=$message?></p>
+</body>
+</html>
View
19 app/views/layouts/flash.thtml
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="pl" xml:lang="pl">
+<head>
+<title><?=$page_title?></title>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<meta http-equiv="Refresh" content="<?=$time?>;url=<?=$url?>" />
+<style><!--
+P { text-align:center; font:bold 1.1em sans-serif }
+A { color:#444; text-decoration:none }
+A:HOVER { text-decoration: underline; color:#44E }
+--></style>
+</head>
+
+<body>
+
+<p><a href="<?=$url?>"><?=$message?></a></p>
+
+</body>
+</html>
View
0 app/views/put_views_folders_here
No changes.
View
41 config/database.php
@@ -0,0 +1,41 @@
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <http://sputnik.pl/cake> + //
+// + Copyright: (c) 2005 Michal Tatarynowicz + //
+// + + //
+// + Author(s): (c) 2005 Michal Tatarynowicz <tatarynowicz@gmail.com> + //
+// + + //
+// +------------------------------------------------------------------+ //
+// + Licensed under the Public Domain Licence + //
+// +------------------------------------------------------------------+ //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose:
+ * Enter description here...
+ *
+ * @filesource
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @author Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @copyright Copyright (c) 2005, Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @package cake
+ * @subpackage cake.config
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @license Public_Domain
+ *
+ */
+
+$DATABASE_CONFIG = array(
+ 'devel' => array(
+ 'host' => 'localhost',
+ 'login' => 'www',
+ 'password' => 'www',
+ 'database' => 'ease'
+ )
+);
+
+?>
View
41 config/database.php.default
@@ -0,0 +1,41 @@
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <http://sputnik.pl/cake> + //
+// + Copyright: (c) 2005 Michal Tatarynowicz + //
+// + + //
+// + Author(s): (c) 2005 Michal Tatarynowicz <tatarynowicz@gmail.com> + //
+// + + //
+// +------------------------------------------------------------------+ //
+// + Licensed under the Public Domain Licence + //
+// +------------------------------------------------------------------+ //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose:
+ * Enter description here...
+ *
+ * @filesource
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @author Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @copyright Copyright (c) 2005, Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @package cake
+ * @subpackage cake.config
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @license Public_Domain
+ *
+ */
+
+$DATABASE_CONFIG = array(
+ 'devel' => array(
+ 'host' => 'localhost',
+ 'login' => 'cake',
+ 'password' => 'cake',
+ 'database' => 'cake'
+ )
+);
+
+?>
View
42 config/routes.php
@@ -0,0 +1,42 @@
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <http://sputnik.pl/cake> + //
+// + Copyright: (c) 2005 Michal Tatarynowicz + //
+// + + //
+// + Author(s): (c) 2005 Michal Tatarynowicz <tatarynowicz@gmail.com> + //
+// + + //
+// +------------------------------------------------------------------+ //
+// + Licensed under the Public Domain Licence + //
+// +------------------------------------------------------------------+ //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose:
+ * Enter description here...
+ *
+ * @filesource
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @author Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @copyright Copyright (c) 2005, Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @package cake
+ * @subpackage cake.config
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @license Public_Domain
+ *
+ */
+
+# Homepage
+$Route->connect ('/', array('controller'=>'Memes', 'action'=>'add'));
+
+# Tags
+$Route->connect ('/tags/popular', array('controller'=>'Tags', 'action'=>'popular'));
+$Route->connect ('/tags/*', array('controller'=>'Memes', 'action'=>'with_tags'));
+
+# Default route
+$Route->connect ('/:controller/:action/*');
+
+?>
View
44 config/routes.php.default
@@ -0,0 +1,44 @@
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <http://sputnik.pl/cake> + //
+// + Copyright: (c) 2005 Michal Tatarynowicz + //
+// + + //
+// + Author(s): (c) 2005 Michal Tatarynowicz <tatarynowicz@gmail.com> + //
+// + + //
+// +------------------------------------------------------------------+ //
+// + Licensed under the Public Domain Licence + //
+// +------------------------------------------------------------------+ //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose:
+ * Enter description here...
+ *
+ * @filesource
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @author Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @copyright Copyright (c) 2005, Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @package cake
+ * @subpackage cake.config
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @license Public_Domain
+ *
+ */
+
+# Homepage
+$Route->connect ('/', array('controller'=>'Pages', 'action'=>'view', 'home'));
+
+# Source browser
+#$Route->connect ('/sources/*', array('controller'=>'Sources', 'action'=>'index'));
+
+# Content pages
+#$Route->connect ('/*', array('controller'=>'Pages', 'action'=>'view'));
+
+# Default route
+$Route->connect ('/:controller/:action/*');
+
+?>
View
7 docs/CHANGELOG.txt
@@ -0,0 +1,7 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////////////
+// +---------------------------------------------------------------------------------------------------+ //
+// + $Id$
+// + Last Modified: $Date$
+// + Modified By: $LastChangedBy$
+// +---------------------------------------------------------------------------------------------------+ //
+///////////////////////////////////////////////////////////////////////////////////////////////////////////
View
7 docs/CREDITS.txt
@@ -0,0 +1,7 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////////////
+// +---------------------------------------------------------------------------------------------------+ //
+// + $Id$
+// + Last Modified: $Date$
+// + Modified By: $LastChangedBy$
+// +---------------------------------------------------------------------------------------------------+ //
+///////////////////////////////////////////////////////////////////////////////////////////////////////////
View
18 docs/README.txt
@@ -0,0 +1,18 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////////////
+// +---------------------------------------------------------------------------------------------------+ //
+// + $Id$
+// + Last Modified: $Date$
+// + Modified By: $LastChangedBy$
+// +---------------------------------------------------------------------------------------------------+ //
+///////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+This README will be updated
+
+for now visit:
+
+https://developers.nextco.com/cake/
+
+OR:
+
+http://sputnik.pl/cake/
+
View
40 index.php
@@ -0,0 +1,40 @@
+<?php
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <http://sputnik.pl/cake> + //
+// + Copyright: (c) 2005 Michal Tatarynowicz + //
+// + + //
+// + Author(s): (c) 2005 Michal Tatarynowicz <tatarynowicz@gmail.com> + //
+// + + //
+// +------------------------------------------------------------------+ //
+// + Licensed under the Public Domain Licence + //
+// +------------------------------------------------------------------+ //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Enter description here...
+ *
+ * @filesource
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @author Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @copyright Copyright (c) 2005, Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @package cake
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @license Public_Domain
+ *
+ */
+
+/**
+ * Enter description here...
+ *
+ */
+define ('BASE_URL', $_SERVER['SCRIPT_NAME']);
+define ('ROOT', dirname($_SERVER['SCRIPT_FILENAME']).'/');
+
+$_GET['url'] = ltrim($_SERVER['PATH_INFO'],'/');
+
+require ROOT.'public/dispatch.php';
+?>
View
0 libs/adodb/put_adodb_files_here
No changes.
View
275 libs/bake.php
@@ -0,0 +1,275 @@
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <http://sputnik.pl/cake> + //
+// + Copyright: (c) 2005 Michal Tatarynowicz + //
+// + + //
+// + Author(s): (c) 2005 Michal Tatarynowicz <tatarynowicz@gmail.com> + //
+// + + //
+// +------------------------------------------------------------------+ //
+// + Licensed under the Public Domain Licence + //
+// +------------------------------------------------------------------+ //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: Bake
+ * Creates controller, model, view files, and the required directories on demand.
+ * Used by scripts/add.php
+ *
+ * @filesource
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @author Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @copyright Copyright (c) 2005, Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @license Public_Domain
+ *
+ */
+
+/**
+ * Enter description here...
+ *
+ */
+uses('object', 'inflector');
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ *
+ */
+class Bake extends Object {
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $stdin = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $stdout = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $stderr = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $actions = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $model_template = "<?PHP
+
+class %s extends AppModel {
+}
+
+?>
+";
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $action_template = "
+ function %s () {
+ }
+";
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $controller_template = "<?PHP
+
+class %s extends AppController {
+%s
+}
+
+?>
+";
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $type
+ * @param unknown_type $names
+ */
+ function __construct ($type, $names) {
+
+ $this->stdin = fopen('php://stdin', 'r');
+ $this->stdout = fopen('php://stdout', 'w');
+ $this->stderr = fopen('php://stderr', 'w');
+
+ switch ($type) {
+
+ case 'model':
+ case 'models':
+ foreach ($names as $model_name)
+ $this->create_model($model_name);
+ break;
+
+ case 'controller':
+ case 'ctrl':
+ $controller = array_shift($names);
+
+ $add_actions = array();
+ foreach ($names as $action) {
+ $add_actions[] = $action;
+ $this->create_view($controller, $action);
+ }
+
+ $this->create_controller($controller, $add_actions);
+ break;
+
+ case 'view':
+ case 'views':
+ $r = null;
+ foreach ($names as $model_name) {
+ if (preg_match('/^([a-z0-9_]+(?:\/[a-z0-9_]+)*)\/([a-z0-9_]+)$/i', $model_name, $r)) {
+ $this->create_view($r[1], $r[2]);
+ }
+ }
+ break;
+ }
+
+ if (!$this->actions)
+ fwrite($this->stderr, "Nothing to do, quitting.\n");
+
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $controller
+ * @param unknown_type $name
+ */
+ function create_view ($controller, $name) {
+ $dir = Inflector::underscore($controller);
+ $this->create_dir(VIEWS.$dir);
+ $this->create_file(VIEWS.$dir.'/'.strtolower($name).'.thtml', '');
+ $this->actions++;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $name
+ * @param unknown_type $actions
+ */
+ function create_controller ($name, $actions=array()) {
+ $class_name = Inflector::camelize($name).'Controller';
+ $content = array();
+ foreach ($actions as $action)
+ $content[] = sprintf($this->action_template, ($action));
+
+ $this->create_file($this->controller_fn($name), sprintf($this->controller_template, $class_name, join('', $content)));
+ $this->actions++;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $name
+ */
+ function create_model ($name) {
+ $class_name = Inflector::camelize($name);
+ $this->create_file($this->model_fn($name), sprintf($this->model_template, $class_name));
+ $this->actions++;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $name
+ * @return unknown
+ */
+ function model_fn ($name) {
+ return MODELS.Inflector::underscore($name).'.php';
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $name
+ * @return unknown
+ */
+ function controller_fn ($name) {
+ return CONTROLLERS.Inflector::underscore($name).'_controller.php';
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $path
+ * @param unknown_type $contents
+ * @return unknown
+ */
+ function create_file ($path, $contents) {
+
+ if (is_file($path)) {
+ fwrite($this->stdout, "File {$path} exists, overwrite? (y/N) ");
+ $key = fgets($this->stdin);
+
+ if (preg_match("/^q/", $key)) {
+ exit;
+ }
+ if (!preg_match("/^y/", $key)) {
+ fwrite($this->stdout, "Skip {$path}\n");
+ return false;
+ }
+ }
+
+ if ($f = fopen($path, 'w')) {
+ fwrite($f, $contents);
+ fclose($f);
+ fwrite($this->stdout, "Wrote {$path}\n");
+ return true;
+ }
+ else {
+ fwrite($this->stderr, "Error! Couldn't open {$path} for writing.\n");
+ return false;
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $path
+ */
+ function create_dir ($path) {
+ if (!is_dir($path)) {
+ if (mkdir($path)) {
+ fwrite($this->stdout, "Created {$path}\n");
+ }
+ else {
+ fwrite($this->stderr, "Error! Couldn't create dir {$path}\n");
+ }
+ }
+ }
+}
+
+?>
View
236 libs/basics.php
@@ -0,0 +1,236 @@
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <http://sputnik.pl/cake> + //
+// + Copyright: (c) 2005 Michal Tatarynowicz + //
+// + + //
+// + Author(s): (c) 2005 Michal Tatarynowicz <tatarynowicz@gmail.com> + //
+// + + //
+// +------------------------------------------------------------------+ //
+// + Licensed under the Public Domain Licence + //
+// +------------------------------------------------------------------+ //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: Basics
+ * Basic Cake functionalities.
+ *
+ * @filesource
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @author Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @copyright Copyright (c) 2005, Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @license Public_Domain
+ *
+ */
+
+/**
+ * Enter description here...
+ *
+ */
+function load_libs () {
+ foreach (list_modules(LIBS) as $lib) {
+ if ($lib != 'basics') {
+ include_once (LIBS.$lib.'.php');
+ }
+ }
+}
+
+/**
+ * Enter description here...
+ *
+ */
+function load_models () {
+ require (APP.'app_model.php');
+ foreach (list_modules(MODELS) as $model) {
+ require (MODELS.$model.'.php');
+ }
+}
+
+/**
+ * Enter description here...
+ *
+ */
+function load_controllers () {
+ require (APP.'app_controller.php');
+ foreach (list_modules(CONTROLLERS) as $controller) {
+ require (CONTROLLERS.$controller.'.php');
+ }
+}
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $path
+ * @param unknown_type $sort
+ * @return unknown
+ */
+function list_modules($path, $sort=true) {
+ if ($d = opendir($path)) {
+ $out = array();
+ $r = null;
+ while (false !== ($fn = readdir($d))) {
+ if (preg_match('#^(.+)\.php$#', $fn, $r)) {
+ $out[] = $r[1];
+ }
+ }
+ if ($sort || $this->sort) {
+ sort($out);
+ }
+
+ return $out;
+ }
+ else {
+ return false;
+ }
+}
+
+/**
+ * Enter description here...
+ *
+ */
+function uses_config () {
+ global $TIME_START;
+
+ require (CONFIGS.'core.php');
+}
+
+/**
+ * Enter description here...
+ *
+ */
+function uses_database () {
+ global $DB;
+
+ if (file_exists(CONFIGS.'database.php')) {
+ require (CONFIGS.'database.php');
+ $DB = new DBO ($DATABASE_CONFIG['devel'], DEBUG > 1);
+ }
+}
+
+/**
+ * Enter description here...
+ *
+ */
+function uses_tags () {
+ require (CONFIGS.'tags.php');
+}
+
+/**
+ * Enter description here...
+ *
+ */
+function uses () {
+ $args = func_get_args();
+ foreach ($args as $arg) {
+ require_once (LIBS.$arg.'.php');
+ }
+}
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $var
+ * @param unknown_type $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')) {
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function getMicrotime() {
+ list($usec, $sec) = explode(" ", microtime());
+ return ((float)$usec + (float)$sec);
+ }
+}
+if (!function_exists('sortByKey')) {
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $array
+ * @param unknown_type $sortby
+ * @param unknown_type $order
+ * @param unknown_type $type
+ * @return unknown
+ */
+ 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;
+ }
+}
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ *
+ */
+class neatArray {
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $value
+ * @return neatArray
+ */
+ function neatArray ($value) {
+ $this->value = $value;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $field_name
+ * @param unknown_type $value
+ * @return unknown
+ */
+ function find_in ($field_name, $value) {
+ $out = false;
+ foreach ($this->value as $k=>$v) {
+ if (isset($v[$field_name]) && ($v[$field_name] == $value)) {
+ $out[$k] = $v;
+ }
+ }
+
+ return $out;
+ }
+}
+
+?>
View
151 libs/cache.php
@@ -0,0 +1,151 @@
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <http://sputnik.pl/cake> + //
+// + Copyright: (c) 2005 Michal Tatarynowicz + //
+// + + //
+// + Author(s): (c) 2005 Michal Tatarynowicz <tatarynowicz@gmail.com> + //
+// + + //
+// +------------------------------------------------------------------+ //
+// + Licensed under the Public Domain Licence + //
+// +------------------------------------------------------------------+ //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: Cache
+ * Description:
+ *
+ * @filesource
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @author Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @copyright Copyright (c) 2005, Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @license Public_Domain
+ *
+ */
+
+/**
+ * Enter description here...
+ *
+ */
+uses('model');
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ *
+ */
+class Cache extends Model {
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $id = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $data = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $for_caching = null;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ */
+ var $use_table = 'cache';
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $id
+ */
+ function __construct ($id) {
+ $this->id = (md5($id));
+ parent::__construct($this->id);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $id
+ * @return unknown
+ */
+ function id ($id=null) {
+ if (!$id) return $this->id;
+ return ($this->id = $id);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $content
+ * @param unknown_type $keep_for
+ * @return unknown
+ */
+ function remember ($content, $keep_for=CACHE_PAGES_FOR) {
+ $data = addslashes($this->for_caching.$content);
+ $expire = date("Y-m-d H:i:s",time()+($keep_for>0? $keep_for: 999999999));
+ return $this->query("REPLACE {$this->use_table} (id,data,expire) VALUES ('{$this->id}', '{$data}', '{$expire}')");
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function restore () {
+ if (empty($this->data['data']))
+ return $this->find("id='{$this->id}' AND expire>NOW()");
+
+ return $this->data['data'];
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function has () {
+ return is_array($this->data = $this->find("id='{$this->id}' AND expire>NOW()"));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $string
+ */
+ function append ($string) {
+ $this->for_caching .= $string;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function clear () {
+ return $this->query("DELETE FROM {$this->use_table}");
+ }
+}
+
+?>
View
545 libs/controller.php
@@ -0,0 +1,545 @@
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <http://sputnik.pl/cake> + //
+// + Copyright: (c) 2005 Michal Tatarynowicz + //
+// + + //
+// + Author(s): (c) 2005 Michal Tatarynowicz <tatarynowicz@gmail.com> + //
+// + + //
+// +------------------------------------------------------------------+ //
+// + Licensed under the Public Domain Licence + //
+// +------------------------------------------------------------------+ //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * 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
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @author Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @copyright Copyright (c) 2005, Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @license Public_Domain
+ *
+ */
+
+/**
+ * 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]);
+
+ if ($this->uses === false) {
+ if (!$DB)
+ die("Controller::__construct() : ".$this->name." controller needs database access, exiting.");
+
+ $model_class = Inflector::singularize($this->name);
+ if (class_exists($model_class))
+ $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_name (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->auto_render = false;
+ header ('Location: '.$this->base.$url);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $url
+ * @return unknown
+ */
+ function url_for ($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 parse_html_options ($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
+ * @return unknown
+ */
+ function link_to ($title, $url, $html_options=null, $confirm=false) {
+ $confirm? $html_options['onClick'] = "return confirm('{$confirm}')": null;
+ return sprintf(TAG_LINK, $this->url_for($url), $this->parse_html_options($html_options), $title);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $title
+ * @param unknown_type $url
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function link_out ($title, $url=null, $html_options=null) {
+ $url = $url? $url: $title;
+ return sprintf(TAG_LINK, $url, $this->parse_html_options($html_options), $title);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $target
+ * @param unknown_type $type
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function form_tag ($target=null, $type='post', $html_options=null) {
+ $html_options['action'] = $this->url_for($target);
+ $html_options['method'] = $type=='get'? 'get': 'post';
+ $type == 'file'? $html_options['enctype'] = 'multipart/form-data': null;
+
+ return sprintf(TAG_FORM, $this->parse_html_options($html_options, ''));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $caption
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function submit_tag ($caption='Submit', $html_options=null) {
+ $html_options['value'] = $caption;
+ return sprintf(TAG_SUBMIT, $this->parse_html_options($html_options, '', ' '));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @param unknown_type $size
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function input_tag ($tag_name, $size=20, $html_options=null) {
+ $html_options['size'] = $size;
+ $html_options['value'] = isset($html_options['value'])? $html_options['value']: $this->tag_value($tag_name);
+ $this->tag_is_invalid($tag_name)? $html_options['class'] = 'form_error': null;
+ return sprintf(TAG_INPUT, $tag_name, $this->parse_html_options($html_options, '', ' '));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @param unknown_type $value
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function hidden_tag ($tag_name, $value=null, $html_options=null) {
+ $html_options['value'] = $value? $value: $this->tag_value($tag_name);
+ return sprintf(TAG_HIDDEN, $tag_name, $this->parse_html_options($html_options, '', ' '));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @param unknown_type $size
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function password_tag ($tag_name, $size=20, $html_options=null) {
+ $html_options['size'] = $size;
+ $html_options['value'] = $value? $value: $this->tag_value($tag_name);
+ return sprintf(TAG_PASSWORD, $tag_name, $this->parse_html_options($html_options, '', ' '));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function file_tag ($tag_name, $html_options=null) {
+ return sprintf(TAG_FILE, $tag_name, $this->parse_html_options($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 area_tag ($tag_name, $cols=60, $rows=10, $html_options=null) {
+ $value = $value? $value: $this->tag_value($tag_name);
+ $html_options['cols'] = $cols;
+ $html_options['rows'] = $rows;
+ return sprintf(TAG_AREA, $tag_name, $this->parse_html_options($html_options, ' '), $value);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @param unknown_type $title
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function checkbox_tag ($tag_name, $title=null, $html_options=null) {
+ $this->tag_value($tag_name)? $html_options['checked'] = 'checked ': null;
+ $title = $title? $title: ucfirst($tag_name);
+ return sprintf(TAG_CHECKBOX, $tag_name, $tag_name, $tag_name, $this->parse_html_options($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 radio_tags ($tag_name, $options, $inbetween=null, $html_options=null) {
+ $value = isset($html_options['value'])? $html_options['value']: $this->tag_value($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->parse_html_options(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);
+ }
+
+ return join($inbetween, $out);
+ }
+
+/**
+ * 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 select_tag ($tag_name, $options, $outer_options=null, $inner_options=null) {
+ $selected = isset($html_options['value'])? $html_options['value']: $this->tag_value($tag_name);
+ $select[] = sprintf(TAG_SELECT_START, $tag_name, $this->parse_html_options($outer_options));
+ $select[] = sprintf(TAG_SELECT_EMPTY, $this->parse_html_options($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->parse_html_options($options_here), $title);
+ }
+
+ $select[] = sprintf(TAG_SELECT_END);
+
+ return implode("\n", $select);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $names
+ * @param unknown_type $tr_options
+ * @param unknown_type $th_options
+ * @return unknown
+ */
+ function table_headers ($names, $tr_options=null, $th_options=null) {
+ $args = func_get_args();
+
+ $out = array();
+ foreach ($names as $arg)
+ $out[] = sprintf(TAG_TABLE_HEADER, $this->parse_html_options($th_options), $arg);
+
+ return sprintf(TAG_TABLE_HEADERS, $this->parse_html_options($tr_options), join(' ', $out));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $data
+ * @param unknown_type $tr_options
+ * @param unknown_type $td_options
+ * @return unknown
+ */
+ function table_cells ($data, $tr_options=null, $td_options=null) {
+ if (empty($data[0]) || !is_array($data[0]))
+ $data = array($data);
+
+ foreach ($data as $line) {
+ $cells_out = array();
+ foreach ($line as $cell) $cells_out[] = sprintf(TAG_TABLE_CELL, $this->parse_html_options($td_options), $cell);
+ $out[] = join(' ', $cells_out);
+ }
+
+ return sprintf(TAG_TABLE_ROW, $this->parse_html_options($tr_options), join("\n", $out));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $name
+ * @param unknown_type $alt
+ * @param unknown_type $html_options
+ * @return unknown
+ */
+ function image_tag ($name, $alt=null, $html_options=null) {
+ $url = "{$this->base}/images/{$name}";
+ return sprintf(TAG_IMAGE, $url, $alt, $this->parse_html_options($html_options, '', ' '));
+ }
+
+
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $tag_name
+ * @return unknown
+ */
+ function tag_value ($tag_name) {
+ return isset($this->params['data'][$tag_name])? $this->params['data'][$tag_name]: null;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $field
+ * @return unknown
+ */
+ function tag_is_invalid ($field) {
+ return !empty($this->validation_errors[$field]);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $field
+ * @param unknown_type $text
+ * @return unknown
+ */
+ function validation_error ($field, $text) {
+ return $this->tag_is_invalid($field)? sprintf(SHORT_ERROR_MESSAGE, $text): null;
+ }
+
+
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $name
+ * @param unknown_type $link
+ */
+ function add_crumb ($name, $link) {
+ $this->_crumbs[] = array ($name, $link);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function get_crumbs () {
+
+ 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 $action
+ */
+ function set_action ($action) {
+ $this->action = $action;
+
+ $args = func_get_args();
+ call_user_func_array(array(&$this, $action), $args);
+ }
+
+/**
+ * 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->_do_render(VIEWS.'layouts/error.thtml', array('code'=>$code,'name'=>$name,'message'=>$message)));
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function validates () {
+ $args = func_get_args();
+ $errors = call_user_func_array(array(&$this, 'validation_errors'), $args);
+
+ return count($errors);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function validation_errors () {
+ $objects = func_get_args();
+ if (!count($objects)) return false;
+
+ $errors = array();
+ foreach ($objects as $object) {
+ $errors = array_merge($errors, $object->invalid_fields());
+ }
+
+ return $this->validation_errors = (count($errors)? $errors: false);
+ }
+}
+
+?>
View
511 libs/dbo-ado.php
@@ -0,0 +1,511 @@
+<?PHP
+//////////////////////////////////////////////////////////////////////////
+// + $Id$
+// +------------------------------------------------------------------+ //
+// + Cake <http://sputnik.pl/cake> + //
+// + Copyright: (c) 2005 Michal Tatarynowicz + //
+// + + //
+// + Author(s): (c) 2005 Michal Tatarynowicz <tatarynowicz@gmail.com> + //
+// + + //
+// +------------------------------------------------------------------+ //
+// + Licensed under the Public Domain Licence + //
+// +------------------------------------------------------------------+ //
+//////////////////////////////////////////////////////////////////////////
+
+/**
+ * Purpose: DBO/ADO
+ *
+ * Description:
+ * A MySQL functions wrapper. Provides ability to get results as arrays
+ * and query logging (with execution time).
+ *
+ * Example usage:
+ *
+ * <code>
+ * require('dbo.php');
+ *
+ * // create and connect the object
+ * $db = new DBO(array(
+ * 'host'=>'localhost',
+ * 'login'=>'username',
+ * 'password'=>'password',
+ * 'database'=>'database'
+ * 'type'=>'mysql'));
+ *
+ * // 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 MySQL way of reading query results
+ * if ($db->q("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->show_log(TRUE);
+ * </code>
+ *
+ * @filesource
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @author Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @copyright Copyright (c) 2005, Michal Tatarynowicz <tatarynowicz@gmail.com>
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @license Public_Domain
+ *
+ */
+
+/**
+ * Enter description here...
+ *
+ */
+require_once('adodb/adodb.inc.php');
+
+/**
+ * Enter description here...
+ *
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ *
+ */
+class DBO {
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $connected=FALSE;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $error=NULL;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $insert_id=NULL;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access public
+ */
+ var $affected=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 $_queries_cnt=0;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_queries_time=NULL;
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_queries_log=array();
+
+/**
+ * Enter description here...
+ *
+ * @var unknown_type
+ * @access private
+ */
+ var $_adodb=NULL;
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $config
+ * @param unknown_type $DEBUG
+ * @return DBO
+ */
+ function DBO($config=NULL,$DEBUG=FALSE) {
+ $this->__constructor($config,$DEBUG);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $config
+ * @param unknown_type $DEBUG
+ */
+ function __constructor($config=NULL,$DEBUG=FALSE) {
+ $this->debug = $DEBUG;
+ if ($DEBUG > 1) register_shutdown_function( array( &$this, "show_log" ) );
+ $this->connect($config);
+ }
+
+/**
+ * Enter description here...
+ *
+ */
+ function __destructor() {
+ $this->close();
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $config
+ */
+ function connect($config) {
+ if($config) {
+ $this->config = $config;
+ if(isset($this->config['type'])) {
+ $this->_adodb = NewADOConnection($this->config['type']);
+ $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...
+ *
+ */
+ function close() {
+ $adodb =& $this->_adodb;
+ $adodb->close;
+ showLog();
+ $this->_conn = NULL;
+ $this->connected = NULL;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $q
+ * @param unknown_type $DEBUG
+ * @param unknown_type $log
+ * @return unknown
+ */
+ function q($q,$DEBUG=FALSE,$log=TRUE) {
+ Return $this->query($q,$DEBUG,$log);
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $q
+ * @param unknown_type $DEBUG
+ * @param unknown_type $log
+ * @return unknown
+ */
+ function query($q,$DEBUG=FALSE,$log=TRUE) {
+ $adodb =& $this->_adodb;
+ $t = getMicrotime();
+
+ if($log){
+ $this->_result =& $adodb->Execute($q);
+ $result =& $this->_result;
+ $this->took = round((getmicrotime()-$t)*1000, 0);
+ if(!$this->_result && $adodb->ErrorMsg())
+ $this->error = $adodb->ErrorMsg();
+ else
+ $this->error = NULL;
+
+ $this->insert_id = $adodb->Insert_ID();
+
+ $this->affected = $adodb->Affected_Rows();
+
+ $this->num_rows = $result->RecordCount();
+ $this->_log_query($q);
+
+ if($this->debug || $DEBUG) $this->_show_query($q);
+
+ Return $this->error? FALSE: $this->_result;
+ }
+ else {
+ $this->_result = $adodb->Execute($q);
+ Return $this->_result;
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function farr() {
+ $result =& $this->_result;
+ return $result->FetchRow();
+ }
+
+ //SAME AS ABOVE?
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $q
+ * @param unknown_type $DEBUG
+ * @return unknown
+ */
+ function one($q,$DEBUG=FALSE) {
+ $result =& $this->_result;
+ Return $this->query($q,$DEBUG)? $result->FetchRow(): FALSE;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $q
+ * @param unknown_type $DEBUG
+ * @return unknown
+ */
+ function all($q,$DEBUG=FALSE) {
+ if($this->query($q,$DEBUG)) {
+ $result = $this->_result;
+ return $result->GetRows();
+ } else {
+ Return FALSE;
+ }
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $name
+ * @param unknown_type $q
+ * @param unknown_type $DEBUG
+ * @return unknown
+ */
+ function field($name, $q, $DEBUG=FALSE) {
+ $data = $this->one($q, $DEBUG);
+ return empty($data[$name])? false: $data[$name];
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function tables() {
+ $adodb =& $this->_adodb;
+ $tables = $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
+ * @param unknown_type $sql
+ * @return unknown
+ */
+ function has_any($table, $sql) {
+ $out = $this->one("SELECT COUNT(*) AS count FROM {$table} WHERE {$sql}");
+ return is_array($out)? $out['count']: FALSE;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function got_connected() {
+ Return $this->connected;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function got_insert_id() {
+ Return $this->insert_id;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function got_affected() {
+ Return $this->affected;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function got_num_rows() {
+ Return $this->num_rows;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function got_error() {
+ return $this->error;
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $sorted
+ */
+ function show_log($sorted=FALSE) {
+ $log = $sorted?
+ sortByKey($this->_queries_log, 'took', 'desc', SORT_NUMERIC):
+ $this->_queries_log;
+
+ print("<table border=1>\n<tr><th colspan=7>{$this->_queries_cnt} queries took {$this->_queries_time} ms</th></tr>\n");
+ print("<tr><td>Nr</td><td>Query</td><td>Error</td><td>Affected</td><td>Num. rows</td><td>Took (ms)</td></tr>\n");
+
+ foreach($log AS $k=>$i) {
+ print("<tr><td>".($k+1)."</td><td>{$i['query']}</td><td>{$i['error']}</td><td align='right'>{$i['affected']}</td><td align='right'>{$i['num_rows']}</td><td align='right'>{$i['took']}</td></tr>\n");
+ }
+
+ print("</table>\n");
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $q
+ */
+ function _log_query($q) {
+ $this->_queries_cnt++;
+ $this->_queries_time += $this->took;
+ $this->_queries_log[] = array(
+ 'query'=>$q,
+ 'error'=>$this->error,
+ 'affected'=>$this->affected,
+ 'num_rows'=>$this->num_rows,
+ 'took'=>$this->took
+ );
+
+
+ if ($this->error && function_exists('logError'))
+ logError("Query: {$q} RETURNS ERROR {$this->error}");
+ }
+
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $q
+ */
+ function _show_query($q) {
+ $error = $this->error;
+
+ if ($this->debug || $error) {
+ print("<p style=\"text-align:left\"><b>Query:</b> {$q} <small>[Aff:{$this->affected} Num:{$this->num_rows} Took:{$this->took}ms]</small>");
+ if($error) {
+ print("<br /><span style=\"color:Red;text-align:left\"><b>ERROR:</b> {$this->error}</span>");
+ }
+ print('</p>');
+ }
+ }
+
+}
+
+if (!function_exists('getMicrotime')) {
+/**
+ * Enter description here...
+ *
+ * @return unknown
+ */
+ function getMicrotime() {
+ list($usec, $sec) = explode(" ", microtime());
+ return ((float)$usec + (float)$sec);
+ }
+}
+if (!function_exists('sortByKey')) {
+/**
+ * Enter description here...
+ *
+ * @param unknown_type $array
+ * @param unknown_type $sortby
+ * @param unknown_type $order
+ * @param unknown_type $type
+ * @return unknown
+ */
+ 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);
+