- 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
This commit is contained in:
pies 2005-05-22 23:24:09 +00:00
parent 3dd8d77b09
commit 4a87a75332
47 changed files with 5096 additions and 4748 deletions

View file

@ -42,4 +42,4 @@
class AppController extends Controller {
}
?>
?>

View file

@ -42,4 +42,4 @@
class AppModel extends Model {
}
?>
?>

View file

@ -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 file

@ -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 file

@ -8,6 +8,8 @@
<body>
<h1><?=$title_for_layout?></h1>
<?=$content_for_layout?>
</body>

View file

@ -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 file

@ -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 file

@ -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 file

@ -36,6 +36,6 @@
* - 1: development
* - 2: full debug with sql
*/
define ('DEBUG', 0);
define ('DEBUG', 1);
?>
?>

View file

@ -36,60 +36,68 @@
* here
*/
if( !defined('ROOT') ){
define ('ROOT', '../');
define ('ROOT', '../');
}
/**
* Path to the application directory.
*/
define ('APP', ROOT.'app'.DS);
define ('APP', ROOT.'app'.DS);
/**
* Path to the application models directory.
*/
define ('MODELS', APP.'models'.DS);
define ('MODELS', APP.'models'.DS);
/**
* Path to the application controllers directory.
*/
define ('CONTROLLERS', APP.'controllers'.DS);
define ('CONTROLLERS', APP.'controllers'.DS);
/**
* Path to the application helpers directory.
*/
define ('HELPERS', APP.'helpers'.DS);
define ('HELPERS', APP.'helpers'.DS);
/**
* Path to the application views directory.
*/
define ('VIEWS', APP.'views'.DS);
define ('VIEWS', APP.'views'.DS);
/**
* Path to the configuration files directory.
*/
define ('CONFIGS', ROOT.'config'.DS);
define ('CONFIGS', ROOT.'config'.DS);
/**
* Path to the libs directory.
*/
define ('LIBS', ROOT.'libs'.DS);
define ('LOGS', ROOT.'logs'.DS);
define ('MODULES', ROOT.'modules'.DS);
define ('LIBS', ROOT.'libs'.DS);
/**
* Path to the logs directory.
*/
define ('LOGS', ROOT.'logs'.DS);
/**
* Path to the modules directory.
*/
define ('MODULES', ROOT.'modules'.DS);
/**
* Path to the public directory.
*/
define ('PUBLIC', ROOT.'public'.DS);
define ('PUBLIC', ROOT.'public'.DS);
/**
* Path to the tests directory.
*/
define ('TESTS', ROOT.'tests'.DS);
define ('TESTS', ROOT.'tests'.DS);
/**
* Path to the vendors directory.
*/
define ('VENDORS', ROOT.'vendors'.DS);
define ('VENDORS', ROOT.'vendors'.DS);
/**
* Path to the controller test directory.
@ -99,16 +107,16 @@ define ('CONTROLLER_TESTS',TESTS.'app'.DS.'controllers'.DS);
/**
* Path to the helpers test directory.
*/
define ('HELPER_TESTS', TESTS.'app'.DS.'helpers'.DS);
define ('HELPER_TESTS', TESTS.'app'.DS.'helpers'.DS);
/**
* Path to the models test directory.
*/
define ('MODEL_TESTS', TESTS.'app'.DS.'models'.DS);
define ('MODEL_TESTS', TESTS.'app'.DS.'models'.DS);
/**
* Path to the lib test directory.
*/
define ('LIB_TESTS', TESTS.'libs'.DS);
define ('LIB_TESTS', TESTS.'libs'.DS);
?>

View file

@ -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 file

@ -44,4 +44,4 @@ $Route->connect ('/', array('controller'=>'Pages', 'action'=>'index'));
*/
$Route->connect ('/test', array('controller'=>'Tests', 'action'=>'test_all'));
?>
?>

View file

@ -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 file

@ -149,6 +149,9 @@ class %sTest extends TestCase {
$this->stdout = fopen('php://stdout', 'w');
$this->stderr = fopen('php://stderr', 'w');
// Output directory name
fwrite($this->stderr, "\n".substr(ROOT,0,strlen(ROOT)-1).":\n".str_repeat('-',strlen(ROOT)+1)."\n");
switch ($type) {
case 'model':
@ -201,10 +204,10 @@ class %sTest extends TestCase {
*/
function newView ($controller, $name) {
$dir = Inflector::underscore($controller);
$path = "{$dir}/".strtolower($name).".thtml";
$path = $dir.DS.strtolower($name).".thtml";
$this->createDir(VIEWS.$dir);
$fn = VIEWS.$path;
$this->createFile($fn, sprintf($this->template('view'), "<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 @@ class %sTest extends TestCase {
* @uses Bake::stderr
*/
function createFile ($path, $contents) {
$shortPath = str_replace(ROOT,null,$path);
if (is_file($path) && !$this->dontAsk) {
fwrite($this->stdout, "File {$path} exists, overwrite? (yNaq) ");
fwrite($this->stdout, "File {$shortPath} exists, overwrite? (yNaq) ");
$key = trim(fgets($this->stdin));
if ($key=='q') {
fwrite($this->stdout, "Quitting.\n");
exit;
@ -467,7 +471,7 @@ class %sTest extends TestCase {
elseif ($key=='y') {
}
else {
fwrite($this->stdout, "Skip {$path}\n");
fwrite($this->stdout, "Skip {$shortPath}\n");
return false;
}
}
@ -475,12 +479,12 @@ class %sTest extends TestCase {
if ($f = fopen($path, 'w')) {
fwrite($f, $contents);
fclose($f);
fwrite($this->stdout, "Wrote {$path}\n");
fwrite($this->stdout, "Wrote {$shortPath}\n");
// debug ("Wrote {$path}");
return true;
}
else {
fwrite($this->stderr, "Error! Couldn't open {$path} for writing.\n");
fwrite($this->stderr, "Error! Couldn't open {$shortPath} for writing.\n");
// debug ("Error! Couldn't open {$path} for writing.");
return false;
}
@ -499,13 +503,15 @@ class %sTest extends TestCase {
if (is_dir($path))
return true;
$shortPath = str_replace(ROOT, null, $path);
if (mkdir($path)) {
fwrite($this->stdout, "Created {$path}\n");
fwrite($this->stdout, "Created {$shortPath}\n");
// debug ("Created {$path}");
return true;
}
else {
fwrite($this->stderr, "Error! Couldn't create dir {$path}\n");
fwrite($this->stderr, "Error! Couldn't create dir {$shortPath}\n");
// debug ("Error! Couldn't create dir {$path}");
return false;
}

View file

@ -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 file

@ -39,11 +39,9 @@ uses('model');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class Cache extends Model {

File diff suppressed because it is too large Load diff

View file

@ -1,411 +1,410 @@
<?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: 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_mysql.php'); // or 'dbo_postgres.php'
*
* // create and connect the object
* $db = new DBO_MySQL(array( // or 'DBO_Postgres'
* 'host'=>'localhost',
* 'login'=>'username',
* 'password'=>'password',
* 'database'=>'database'));
*
* // read the whole query result array (of rows)
* $all_rows = $db->all("SELECT a,b,c FROM table");
*
* // read the first row with debugging on
* $first_row_only = $db->one("SELECT a,b,c FROM table WHERE a=1", TRUE);
*
* // emulate the usual way of reading query results
* if ($db->query("SELECT a,b,c FROM table")) {
* while ( $row = $db->farr() ) {
* print $row['a'].$row['b'].$row['c'];
* }
* }
*
* // show a log of all queries, sorted by execution time
* $db->showLog(TRUE);
* </code>
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*
*/
/**
* Enter description here...
*
*/
uses('object');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class DBO extends Object {
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $connected=FALSE;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $debug=FALSE;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $fullDebug=FALSE;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $error=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $affected=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $numRows=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $took=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_conn=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_result=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_queriesCnt=0;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_queriesTime=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_queriesLog=array();
// specific for each database, implemented in db drivers
function connect ($config) { die('Please implement DBO::connect() first.'); }
function disconnect () { die('Please implement DBO::disconnect() first.'); }
function execute ($sql) { die('Please implement DBO::execute() first.'); }
function fetchRow ($result) { die('Please implement DBO::fetchRow() first.'); }
function tables() { die('Please implement DBO::tables() first.'); }
function fields ($table_name) { die('Please implement DBO::fields() first.'); }
function prepare ($data) { die('Please implement DBO::prepare() first.'); }
function lastError () { die('Please implement DBO::lastError() first.'); }
function lastAffected () { die('Please implement DBO::lastAffected() first.'); }
function lastNumRows ($result){ die('Please implement DBO::lastNumRows() first.'); }
function lastInsertId () { die('Please implement DBO::lastInsertId() first.'); }
/**
* Enter description here...
*
* @param unknown_type $config
* @param unknown_type $DEBUG
* @return unknown
*/
function __construct ($config=NULL) {
$this->debug = DEBUG > 0;
$this->fullDebug = DEBUG > 1;
parent::__construct();
return $this->connect($config);
}
/**
* Enter description here...
*
*/
function __destructor () {
$this->close();
}
/**
* Enter description here...
*
* @param unknown_type $db_name
* @return unknown
*/
function useDb ($db_name) {
return $this->query("USE {$db_name}");
}
/**
* Enter description here...
*
*/
function close () {
if ($this->fullDebug) $this->showLog();
$this->disconnect();
$this->_conn = NULL;
$this->connected = false;
}
/**
* Enter description here...
*
* @param unknown_type $sql
* @return unknown
*/
function rawQuery ($sql) {
$this->took = $this->error = $this->numRows = false;
return $this->execute($sql);
}
/**
* Enter description here...
*
* @param unknown_type $sql
* @return unknown
*/
function query($sql) {
$t = getMicrotime();
$this->_result = $this->execute($sql);
$this->affected = $this->lastAffected();
$this->took = round((getMicrotime()-$t)*1000, 0);
$this->error = $this->lastError();
$this->numRows = $this->lastNumRows($this->_result);
$this->logQuery($sql);
if (($this->debug && $this->error) || ($this->fullDebug))
$this->showQuery($sql);
return $this->error? false: $this->_result;
}
/**
* Returns a single row of results from the _last_ query
*
* @param unknown_type $results
* @param unknown_type $type
* @return unknown
*/
function farr ($res=false) {
return $this->fetchRow($res? $res: $this->_result);
}
/**
* Returns a single row of results for a _given_ query
*
* @param unknown_type $sql
* @return unknown
*/
function one ($sql) {
return $this->query($sql)? $this->farr(): false;
}
/**
* Returns all result rows for a given query
*
* @param unknown_type $sql
* @return unknown
*/
function all ($sql) {
if($this->query($sql)) {
$out=array();
while($item = $this->farr()) $out[] = $item;
return $out;
}
else {
return false;
}
}
/**
* Enter description here...
*
* @param unknown_type $name
* @param unknown_type $sql
* @return unknown
*/
function field ($name, $sql) {
$data = $this->one($sql);
return empty($data[$name])? false: $data[$name];
}
/**
* Enter description here...
*
* @param unknown_type $table
* @param unknown_type $sql
* @return unknown
*/
function hasAny($table, $sql) {
$out = $this->one("SELECT COUNT(*) AS count FROM {$table}".($sql? " WHERE {$sql}":""));
return is_array($out)? $out['count']: false;
}
/**
* Enter description here...
*
* @return unknown
*/
function isConnected() {
return $this->connected;
}
/**
* Enter description here...
*
* @return unknown
*/
function prepareArray($data) {
$out = null;
foreach ($data as $key=>$item) {
$out[$key] = $this->prepare($item);
}
return $out;
}
/**
* Enter description here...
*
* @param unknown_type $sorted
*/
function showLog($sorted=false) {
$log = $sorted?
sortByKey($this->_queriesLog, 'took', 'desc', SORT_NUMERIC):
$this->_queriesLog;
print("<table border=1>\n<tr><th colspan=7>{$this->_queriesCnt} queries took {$this->_queriesTime} 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['numRows']}</td><td align='right'>{$i['took']}</td></tr>\n");
}
print("</table>\n");
}
/**
* Enter description here...
*
* @param unknown_type $q
*/
function logQuery($sql) {
$this->_queriesCnt++;
$this->_queriesTime += $this->took;
$this->_queriesLog[] = array(
'query'=>$sql,
'error'=>$this->error,
'affected'=>$this->affected,
'numRows'=>$this->numRows,
'took'=>$this->took
);
if ($this->error)
false; // shouldn't we be logging errors somehow?
}
/**
* Enter description here...
*
* @param unknown_type $q
*/
function showQuery($sql) {
$error = $this->error;
if (strlen($sql)>200 && !$this->fullDebug)
$sql = substr($sql, 0, 200) .'[...]';
if ($this->debug || $error) {
print("<p style=\"text-align:left\"><b>Query:</b> {$sql} <small>[Aff:{$this->affected} Num:{$this->numRows} Took:{$this->took}ms]</small>");
if($error) {
print("<br /><span style=\"color:Red;text-align:left\"><b>ERROR:</b> {$this->error}</span>");
}
print('</p>');
}
}
}
<?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: 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_mysql.php'); // or 'dbo_postgres.php'
*
* // create and connect the object
* $db = new DBO_MySQL(array( // or 'DBO_Postgres'
* 'host'=>'localhost',
* 'login'=>'username',
* 'password'=>'password',
* 'database'=>'database'));
*
* // read the whole query result array (of rows)
* $all_rows = $db->all("SELECT a,b,c FROM table");
*
* // read the first row with debugging on
* $first_row_only = $db->one("SELECT a,b,c FROM table WHERE a=1", TRUE);
*
* // emulate the usual way of reading query results
* if ($db->query("SELECT a,b,c FROM table")) {
* while ( $row = $db->farr() ) {
* print $row['a'].$row['b'].$row['c'];
* }
* }
*
* // show a log of all queries, sorted by execution time
* $db->showLog(TRUE);
* </code>
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*
*/
/**
* Enter description here...
*
*/
uses('object');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class DBO extends Object {
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $connected=FALSE;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $debug=FALSE;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $fullDebug=FALSE;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $error=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $affected=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $numRows=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $took=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_conn=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_result=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_queriesCnt=0;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_queriesTime=NULL;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_queriesLog=array();
// specific for each database, implemented in db drivers
function connect ($config) { die('Please implement DBO::connect() first.'); }
function disconnect () { die('Please implement DBO::disconnect() first.'); }
function execute ($sql) { die('Please implement DBO::execute() first.'); }
function fetchRow ($result) { die('Please implement DBO::fetchRow() first.'); }
function tables() { die('Please implement DBO::tables() first.'); }
function fields ($table_name) { die('Please implement DBO::fields() first.'); }
function prepare ($data) { die('Please implement DBO::prepare() first.'); }
function lastError () { die('Please implement DBO::lastError() first.'); }
function lastAffected () { die('Please implement DBO::lastAffected() first.'); }
function lastNumRows ($result){ die('Please implement DBO::lastNumRows() first.'); }
function lastInsertId () { die('Please implement DBO::lastInsertId() first.'); }
/**
* Enter description here...
*
* @param unknown_type $config
* @param unknown_type $DEBUG
* @return unknown
*/
function __construct ($config=NULL) {
$this->debug = DEBUG > 0;
$this->fullDebug = DEBUG > 1;
parent::__construct();
return $this->connect($config);
}
/**
* Enter description here...
*
*/
function __destructor () {
$this->close();
}
/**
* Enter description here...
*
* @param unknown_type $db_name
* @return unknown
*/
function useDb ($db_name) {
return $this->query("USE {$db_name}");
}
/**
* Enter description here...
*
*/
function close () {
if ($this->fullDebug) $this->showLog();
$this->disconnect();
$this->_conn = NULL;
$this->connected = false;
}
/**
* Enter description here...
*
* @param unknown_type $sql
* @return unknown
*/
function rawQuery ($sql) {
$this->took = $this->error = $this->numRows = false;
return $this->execute($sql);
}
/**
* Enter description here...
*
* @param unknown_type $sql
* @return unknown
*/
function query($sql) {
$t = getMicrotime();
$this->_result = $this->execute($sql);
$this->affected = $this->lastAffected();
$this->took = round((getMicrotime()-$t)*1000, 0);
$this->error = $this->lastError();
$this->numRows = $this->lastNumRows($this->_result);
$this->logQuery($sql);
if (($this->debug && $this->error) || ($this->fullDebug))
$this->showQuery($sql);
return $this->error? false: $this->_result;
}
/**
* Returns a single row of results from the _last_ query
*
* @param resource $res
* @return unknown
*/
function farr ($res=false) {
return $this->fetchRow($res? $res: $this->_result);
}
/**
* Returns a single row of results for a _given_ query
*
* @param unknown_type $sql
* @return unknown
*/
function one ($sql) {
return $this->query($sql)? $this->farr(): false;
}
/**
* Returns all result rows for a given query
*
* @param unknown_type $sql
* @return unknown
*/
function all ($sql) {
if($this->query($sql)) {
$out=array();
while($item = $this->farr()) $out[] = $item;
return $out;
}
else {
return false;
}
}
/**
* Returns a single field of the first of query results for a given sql query
*
* @param unknown_type $name
* @param unknown_type $sql
* @return unknown
*/
function field ($name, $sql) {
$data = $this->one($sql);
return empty($data[$name])? false: $data[$name];
}
/**
* Checks if the specified table contains any record matching specified SQL
*
* @param unknown_type $table
* @param unknown_type $sql
* @return unknown
*/
function hasAny($table, $sql) {
$out = $this->one("SELECT COUNT(*) AS count FROM {$table}".($sql? " WHERE {$sql}":""));
return is_array($out)? $out['count']: false;
}
/**
* Enter description here...
*
* @return unknown
*/
function isConnected() {
return $this->connected;
}
/**
* Enter description here...
*
* @return unknown
*/
function prepareArray($data) {
$out = null;
foreach ($data as $key=>$item) {
$out[$key] = $this->prepare($item);
}
return $out;
}
/**
* Enter description here...
*
* @param unknown_type $sorted
*/
function showLog($sorted=false) {
$log = $sorted?
sortByKey($this->_queriesLog, 'took', 'desc', SORT_NUMERIC):
$this->_queriesLog;
print("<table border=1>\n<tr><th colspan=7>{$this->_queriesCnt} queries took {$this->_queriesTime} 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['numRows']}</td><td align='right'>{$i['took']}</td></tr>\n");
}
print("</table>\n");
}
/**
* Enter description here...
*
* @param unknown_type $q
*/
function logQuery($sql) {
$this->_queriesCnt++;
$this->_queriesTime += $this->took;
$this->_queriesLog[] = array(
'query'=>$sql,
'error'=>$this->error,
'affected'=>$this->affected,
'numRows'=>$this->numRows,
'took'=>$this->took
);
if ($this->error)
false; // shouldn't we be logging errors somehow?
}
/**
* Enter description here...
*
* @param unknown_type $q
*/
function showQuery($sql) {
$error = $this->error;
if (strlen($sql)>200 && !$this->fullDebug)
$sql = substr($sql, 0, 200) .'[...]';
if ($this->debug || $error) {
print("<p style=\"text-align:left\"><b>Query:</b> {$sql} <small>[Aff:{$this->affected} Num:{$this->numRows} Took:{$this->took}ms]</small>");
if($error) {
print("<br /><span style=\"color:Red;text-align:left\"><b>ERROR:</b> {$this->error}</span>");
}
print('</p>');
}
}
}
?>

View file

@ -1,170 +1,170 @@
<?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: DBO_AdoDB
* AdoDB layer for DBO
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
require_once(VENDORS.'adodb/adodb.inc.php');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class DBO_AdoDB extends DBO {
/**
* Enter description here...
*
* @param unknown_type $config
*/
function connect ($config) {
if($this->config = $config) {
if(isset($this->config['driver'])) {
$this->_adodb = NewADOConnection($this->config['driver']);
$adodb =& $this->_adodb;
$this->connected = $adodb->Connect($this->config['host'],$this->config['login'],$this->config['password'],$this->config['database']);
}
}
if(!$this->connected)
die('Could not connect to DB.');
}
/**
* Enter description here...
*
* @return unknown
*/
function disconnect () {
return $this->_adodb->close();
}
/**
* Enter description here...
*
* @param unknown_type $sql
* @return unknown
*/
function execute ($sql) {
return $this->_adodb->execute($sql);
}
/**
* Enter description here...
*
* @param unknown_type $res
* @return unknown
*/
function fetchRow ($res) {
return $res->FetchRow();
}
/**
* Enter description here...
*
* @return unknown
*/
function tables() {
$tables = $this->_adodb->MetaTables('TABLES');
if (!sizeof($tables)>0) {
trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
exit;
}
return $tables;
}
/**
* Enter description here...
*
* @param unknown_type $table_name
* @return unknown
*/
function fields ($table_name) {
$data = $this->_adodb->MetaColumns($table_name);
$fields = false;
foreach ($data as $item)
$fields[] = array('name'=>$item->name, 'type'=>$item->type);
return $fields;
}
/**
* Enter description here...
*
* @param unknown_type $data
*/
function prepare ($data) { die('Please implement DBO::prepare() first.'); }
/**
* Enter description here...
*
* @return unknown
*/
function lastError () {
return $this->_adodb->ErrorMsg();
}
/**
* Enter description here...
*
* @return unknown
*/
function lastAffected () {
return $this->_adodb->Affected_Rows();
}
/**
* Enter description here...
*
* @return unknown
*/
function lastNumRows () {
return $this->_result? $this->_result->RecordCount(): false;
}
/**
* Enter description here...
*
*/
function lastInsertId () { die('Please implement DBO::lastInsertId() first.'); }
}
<?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: DBO_AdoDB
* AdoDB layer for DBO
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
require_once(VENDORS.'adodb/adodb.inc.php');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class DBO_AdoDB extends DBO {
/**
* Enter description here...
*
* @param unknown_type $config
*/
function connect ($config) {
if($this->config = $config) {
if(isset($this->config['driver'])) {
$this->_adodb = NewADOConnection($this->config['driver']);
$adodb =& $this->_adodb;
$this->connected = $adodb->Connect($this->config['host'],$this->config['login'],$this->config['password'],$this->config['database']);
}
}
if(!$this->connected)
die('Could not connect to DB.');
}
/**
* Enter description here...
*
* @return unknown
*/
function disconnect () {
return $this->_adodb->close();
}
/**
* Enter description here...
*
* @param unknown_type $sql
* @return unknown
*/
function execute ($sql) {
return $this->_adodb->execute($sql);
}
/**
* Enter description here...
*
* @param unknown_type $res
* @return unknown
*/
function fetchRow ($res) {
return $res->FetchRow();
}
/**
* Enter description here...
*
* @return unknown
*/
function tables() {
$tables = $this->_adodb->MetaTables('TABLES');
if (!sizeof($tables)>0) {
trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
exit;
}
return $tables;
}
/**
* Enter description here...
*
* @param unknown_type $table_name
* @return unknown
*/
function fields ($table_name) {
$data = $this->_adodb->MetaColumns($table_name);
$fields = false;
foreach ($data as $item)
$fields[] = array('name'=>$item->name, 'type'=>$item->type);
return $fields;
}
/**
* Enter description here...
*
* @param unknown_type $data
*/
function prepare ($data) { die('Please implement DBO::prepare() first.'); }
/**
* Enter description here...
*
* @return unknown
*/
function lastError () {
return $this->_adodb->ErrorMsg();
}
/**
* Enter description here...
*
* @return unknown
*/
function lastAffected () {
return $this->_adodb->Affected_Rows();
}
/**
* Enter description here...
*
* @return unknown
*/
function lastNumRows () {
return $this->_result? $this->_result->RecordCount(): false;
}
/**
* Enter description here...
*
*/
function lastInsertId () { die('Please implement DBO::lastInsertId() first.'); }
}
?>

View file

@ -45,6 +45,8 @@ uses('object');
class DboFactory extends Object {
function make ($activeConfig) {
if (!class_exists('DATABASE_CONFIG')) return false;
$config = DATABASE_CONFIG::$activeConfig();
// special case for AdoDB -- driver name in the form of 'adodb_drivername'

View file

@ -1,189 +1,189 @@
<?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. + //
// + You may not use this file except in compliance with the License. + //
// + + //
// + You may obtain a copy of the License at: + //
// + License page: http://www.opensource.org/licenses/mit-license.php + //
// +------------------------------------------------------------------+ //
//////////////////////////////////////////////////////////////////////////
/**
* Purpose: DBO_MySQL
* MySQL layer for DBO
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
uses('object', 'dbo');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class DBO_MySQL extends DBO {
/**
* Enter description here...
*
* @param unknown_type $config
* @return unknown
*/
function connect ($config) {
if($config) {
$this->config = $config;
$this->_conn = mysql_pconnect($config['host'],$config['login'],$config['password']);
}
$this->connected = $this->_conn? true: false;
if($this->connected)
Return mysql_select_db($config['database'], $this->_conn);
else
die('Could not connect to DB.');
}
/**
* Enter description here...
*
* @return unknown
*/
function disconnect () {
return mysql_close();
}
/**
* Enter description here...
*
* @param unknown_type $sql
* @return unknown
*/
function execute ($sql) {
return mysql_query($sql);
}
/**
* Enter description here...
*
* @param unknown_type $res
* @return unknown
*/
function fetchRow ($res) {
return mysql_fetch_array($res);
}
/**
* Enter description here...
*
* @return unknown
*/
function tables () {
$result = mysql_list_tables($this->config['database']);
if (!$result) {
trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
exit;
}
else {
$tables = array();
while ($line = mysql_fetch_array($result)) {
$tables[] = $line[0];
}
return $tables;
}
}
/**
* Enter description here...
*
* @param unknown_type $table_name
* @return unknown
*/
function fields ($table_name) {
$data = $this->all("DESC {$table_name}");
$fields = false;
foreach ($data as $item)
$fields[] = array('name'=>$item['Field'], 'type'=>$item['Type']);
return $fields;
}
/**
* Enter description here...
*
* @param unknown_type $data
* @return unknown
*/
function prepare ($data) {
return "'".mysql_real_escape_string($data)."'";
}
/**
* Enter description here...
*
* @return unknown
*/
function lastError () {
return mysql_errno()? mysql_errno().': '.mysql_error(): null;
}
/**
* Enter description here...
*
* @return unknown
*/
function lastAffected () {
return $this->_result? mysql_affected_rows(): false;
}
/**
* Enter description here...
*
* @return unknown
*/
function lastNumRows () {
return $this->_result? @mysql_num_rows($this->_result): false;
}
/**
* Enter description here...
*
* @return unknown
*/
function lastInsertId() {
Return mysql_insert_id();
}
}
<?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. + //
// + You may not use this file except in compliance with the License. + //
// + + //
// + You may obtain a copy of the License at: + //
// + License page: http://www.opensource.org/licenses/mit-license.php + //
// +------------------------------------------------------------------+ //
//////////////////////////////////////////////////////////////////////////
/**
* Purpose: DBO_MySQL
* MySQL layer for DBO
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
uses('object', 'dbo');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class DBO_MySQL extends DBO {
/**
* Enter description here...
*
* @param unknown_type $config
* @return unknown
*/
function connect ($config) {
if($config) {
$this->config = $config;
$this->_conn = mysql_pconnect($config['host'],$config['login'],$config['password']);
}
$this->connected = $this->_conn? true: false;
if($this->connected)
Return mysql_select_db($config['database'], $this->_conn);
else
die('Could not connect to DB.');
}
/**
* Enter description here...
*
* @return unknown
*/
function disconnect () {
return mysql_close();
}
/**
* Enter description here...
*
* @param unknown_type $sql
* @return unknown
*/
function execute ($sql) {
return mysql_query($sql);
}
/**
* Enter description here...
*
* @param unknown_type $res
* @return unknown
*/
function fetchRow ($res) {
return mysql_fetch_array($res);
}
/**
* Enter description here...
*
* @return unknown
*/
function tables () {
$result = mysql_list_tables($this->config['database']);
if (!$result) {
trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
exit;
}
else {
$tables = array();
while ($line = mysql_fetch_array($result)) {
$tables[] = $line[0];
}
return $tables;
}
}
/**
* Enter description here...
*
* @param unknown_type $table_name
* @return unknown
*/
function fields ($table_name) {
$data = $this->all("DESC {$table_name}");
$fields = false;
foreach ($data as $item)
$fields[] = array('name'=>$item['Field'], 'type'=>$item['Type']);
return $fields;
}
/**
* Enter description here...
*
* @param unknown_type $data
* @return unknown
*/
function prepare ($data) {
return "'".mysql_real_escape_string($data)."'";
}
/**
* Enter description here...
*
* @return unknown
*/
function lastError () {
return mysql_errno()? mysql_errno().': '.mysql_error(): null;
}
/**
* Enter description here...
*
* @return unknown
*/
function lastAffected () {
return $this->_result? mysql_affected_rows(): false;
}
/**
* Enter description here...
*
* @return unknown
*/
function lastNumRows () {
return $this->_result? @mysql_num_rows($this->_result): false;
}
/**
* Enter description here...
*
* @return unknown
*/
function lastInsertId() {
Return mysql_insert_id();
}
}
?>

View file

@ -1,195 +1,195 @@
<?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: DBO_Postgres
* Enter description here...
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 1.0.0.114
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
uses('object', 'dbo');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 1.0.0.114
*
*/
class DBO_Postgres extends DBO {
/**
* Enter description here...
*
* @param unknown_type $config
* @return unknown
*/
function connect ($config) {
if($config) {
$this->config = $config;
$this->_conn = pg_pconnect("host={$config['host']} dbname={$config['database']} user={$config['login']} password={$config['password']}");
}
$this->connected = $this->_conn? true: false;
if($this->connected)
return true;
else
die('Could not connect to DB.');
}
/**
* Enter description here...
*
* @return unknown
*/
function disconnect () {
return pg_close($this->_conn);
}
/**
* Enter description here...
*
* @param unknown_type $sql
* @return unknown
*/
function execute ($sql) {
return pg_query($this->_conn, $sql);
}
/**
* Enter description here...
*
* @param unknown_type $res
* @return unknown
*/
function fetchRow ($res) {
return pg_fetch_array($res);
}
/**
* Enter description here...
*
* @return unknown
*/
function tables () {
$sql = "SELECT a.relname AS name
FROM pg_class a, pg_user b
WHERE ( relkind = 'r') and relname !~ '^pg_' AND relname !~ '^sql_'
AND relname !~ '^xin[vx][0-9]+' AND b.usesysid = a.relowner
AND NOT (EXISTS (SELECT viewname FROM pg_views WHERE viewname=a.relname));";
$result = $this->all($sql);
if (!$result) {
trigger_error(ERROR_NO_TABLE_LIST, E_USER_ERROR);
exit;
}
else {
$tables = array();
foreach ($result as $item) $tables[] = $item['name'];
return $tables;
}
}
/**
* Enter description here...
*
* @param unknown_type $table_name
* @return unknown
*/
function fields ($table_name) {
$sql = "SELECT c.relname, a.attname, t.typname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '{$table_name}' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid";
$fields = false;
foreach ($this->all($sql) as $field) {
$fields[] = array(
'name' => $field['attname'],
'type' => $field['typname']);
}
return $fields;
}
/**
* Enter description here...
*
* @param unknown_type $data
* @return unknown
*/
function prepare ($data) {
return "'".str_replace('"', '\"', str_replace('$', '$', $data))."'";
}
/**
* Enter description here...
*
* @return unknown
*/
function lastError () {
return pg_last_error()? pg_last_error(): null;
}
/**
* Enter description here...
*
* @return unknown
*/
function lastAffected () {
return $this->_result? pg_affected_rows($this->_result): false;
}
/**
* Enter description here...
*
* @return unknown
*/
function lastNumRows () {
return $this->_result? pg_num_rows($this->_result): false;
}
/**
* Enter description here...
*
* @param unknown_type $table
* @param unknown_type $field
* @return unknown
*/
function lastInsertId ($table, $field='id') {
$sql = "SELECT CURRVAL('{$table}_{$field}_seq') AS max";
$res = $this->rawQuery($sql);
$data = $this->fetchRow($res);
return $data['max'];
}
}
<?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: DBO_Postgres
* Enter description here...
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 1.0.0.114
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
uses('object', 'dbo');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 1.0.0.114
*
*/
class DBO_Postgres extends DBO {
/**
* Enter description here...
*
* @param unknown_type $config
* @return unknown
*/
function connect ($config) {
if($config) {
$this->config = $config;
$this->_conn = pg_pconnect("host={$config['host']} dbname={$config['database']} user={$config['login']} password={$config['password']}");
}
$this->connected = $this->_conn? true: false;
if($this->connected)
return true;
else
die('Could not connect to DB.');
}
/**
* Enter description here...
*
* @return unknown
*/
function disconnect () {
return pg_close($this->_conn);
}
/**
* Enter description here...
*
* @param unknown_type $sql
* @return unknown
*/
function execute ($sql) {
return pg_query($this->_conn, $sql);
}
/**
* Enter description here...
*
* @param unknown_type $res
* @return unknown
*/
function fetchRow ($res) {
return pg_fetch_array($res);
}
/**
* Enter description here...
*
* @return unknown
*/
function tables () {
$sql = "SELECT a.relname AS name
FROM pg_class a, pg_user b
WHERE ( relkind = 'r') and relname !~ '^pg_' AND relname !~ '^sql_'
AND relname !~ '^xin[vx][0-9]+' AND b.usesysid = a.relowner
AND NOT (EXISTS (SELECT viewname FROM pg_views WHERE viewname=a.relname));";
$result = $this->all($sql);
if (!$result) {
trigger_error(ERROR_NO_TABLE_LIST, E_USER_ERROR);
exit;
}
else {
$tables = array();
foreach ($result as $item) $tables[] = $item['name'];
return $tables;
}
}
/**
* Enter description here...
*
* @param unknown_type $table_name
* @return unknown
*/
function fields ($table_name) {
$sql = "SELECT c.relname, a.attname, t.typname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '{$table_name}' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid";
$fields = false;
foreach ($this->all($sql) as $field) {
$fields[] = array(
'name' => $field['attname'],
'type' => $field['typname']);
}
return $fields;
}
/**
* Enter description here...
*
* @param unknown_type $data
* @return unknown
*/
function prepare ($data) {
return "'".str_replace('"', '\"', str_replace('$', '$', $data))."'";
}
/**
* Enter description here...
*
* @return unknown
*/
function lastError () {
return pg_last_error()? pg_last_error(): null;
}
/**
* Enter description here...
*
* @return unknown
*/
function lastAffected () {
return $this->_result? pg_affected_rows($this->_result): false;
}
/**
* Enter description here...
*
* @return unknown
*/
function lastNumRows () {
return $this->_result? pg_num_rows($this->_result): false;
}
/**
* Enter description here...
*
* @param unknown_type $table
* @param unknown_type $field
* @return unknown
*/
function lastInsertId ($table, $field='id') {
$sql = "SELECT CURRVAL('{$table}_{$field}_seq') AS max";
$res = $this->rawQuery($sql);
$data = $this->fetchRow($res);
return $data['max'];
}
}
?>

View file

@ -1,247 +1,247 @@
<?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: Dispatcher
* Dispatches the request, creating aproppriate models and controllers.
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Description:
* Dispatches the request, creating aproppriate models and controllers.
*/
uses('error_messages', 'object', 'router', 'cache', 'controller');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class Dispatcher extends Object {
/**
* Enter description here...
*
* @var unknown_type
*/
var $base = false;
/**
* Enter description here...
*
* @var unknown_type
*/
var $passed_args = array();
/**
* Enter description here...
*
*/
function __construct () {
$this->base = $this->baseUrl();
parent::__construct();
}
/**
* Enter description here...
*
* @param unknown_type $url
* @return unknown
*/
function dispatch ($url) {
global $_POST, $_GET, $_FILES, $_SESSION;
$params = $this->parseParams($url);
// die if no controller set
if (empty($params['controller']))
$this->errorNoController($url);
$ctrl_name = ucfirst($params['controller']);
$ctrl_class = $ctrl_name.'Controller';
// if specified controller class doesn't exist
if (!loadController($ctrl_name) || !class_exists($ctrl_class))
$this->errorUnknownController($url, $ctrl_name);
$controller = new $ctrl_class ($this);
$controller->cache = &$Cache;
$controller->base = $this->base;
// if action is not set, and the default Controller::index() method doesn't exist
if (empty($params['action'])) {
if (method_exists($controller, 'index'))
$params['action'] = 'index';
else
$this->errorNoAction($url);
}
// if the requested action doesn't exist
if (!method_exists($controller, $params['action']))
$this->errorUnknownAction($url, $ctrl_class, $params['action']);
$controller->params = $params;
$controller->action = $params['action'];
$controller->data = empty($params['data'])? null: $params['data'];
$controller->passed_args = empty($params['pass'])? null: $params['pass'];
// EXECUTE THE REQUESTED ACTION
call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']);
if ($controller->autoRender)
$controller->render();
return $params;
}
/**
* Enter description here...
*
* @param unknown_type $from_url
* @return unknown
*/
function parseParams ($from_url) {
global $_POST, $_FILES;
// load routes config
$Route = new Router();
require CONFIGS.'routes.php';
$params = $Route->parse ('/'.$from_url);
// add submitted form data
$params['form'] = $_POST;
if (isset($_POST['data']))
$params['data'] = $_POST['data'];
foreach ($_FILES as $name => $data)
$params['form'][$name] = $data;
return $params;
}
/**
* Enter description here...
*
* @return unknown
*/
function baseUrl () {
global $_SERVER;
//non mod_rewrite use:
if (defined('BASE_URL')) return BASE_URL;
$doc_root = $_SERVER['DOCUMENT_ROOT'];
$script_name = $_SERVER['PHP_SELF'];
// if document root ends with 'public', it's probably correctly set
$r = null;
if (!ereg('/^.*/public(\/)?$/', $doc_root))
return preg_match('/^(.*)\/public\/dispatch\.php$/', $script_name, $r)? $r[1]: false;
// document root is probably not set to Cake 'public' dir
else
return preg_match('/^(.*)\/dispatch\.php$/', $script_name, $r)? $r[1]: false;
}
/**
* Enter description here...
*
* @param unknown_type $code
* @param unknown_type $name
* @param unknown_type $message
*/
function error ($code, $name, $message) {
$controller = new Controller ($this);
$controller->base = $this->base;
$controller->error($code, $name, $message);
}
/**
* Enter description here...
*
* @param unknown_type $url
* @param unknown_type $message
*/
function error404 ($url, $message) {
$this->error('404', 'Not found', sprintf(ERROR_404, $url, $message));
}
/**
* Enter description here...
*
* @param unknown_type $url
*/
function errorNoController ($url) {
DEBUG?
trigger_error (ERROR_NO_CONTROLLER_SET, E_USER_ERROR):
$this->error404($url, "no controller set");
exit;
}
/**
* Enter description here...
*
* @param unknown_type $url
* @param unknown_type $controller_class
*/
function errorUnknownController ($url, $controller_class) {
DEBUG?
trigger_error (sprintf(ERROR_UNKNOWN_CONTROLLER, $controller_class), E_USER_ERROR):
$this->error404($url, "missing controller \"{$controller_class}\"");
exit;
}
/**
* Enter description here...
*
* @param unknown_type $url
*/
function errorNoAction ($url) {
DEBUG?
trigger_error (ERROR_NO_ACTION_SET, E_USER_ERROR):
$this->error404(sprintf(ERROR_404, $url, "no action set"));
exit;
}
/**
* Enter description here...
*
* @param unknown_type $url
* @param unknown_type $controller_class
* @param unknown_type $action
*/
function errorUnknownAction ($url,$controller_class, $action) {
DEBUG?
trigger_error (sprintf(ERROR_NO_ACTION, $action, $controller_class), E_USER_ERROR):
$this->error404($url, "missing controller \"{$controller_class}\"");
exit;
}
}
<?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: Dispatcher
* Dispatches the request, creating aproppriate models and controllers.
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Description:
* Dispatches the request, creating aproppriate models and controllers.
*/
uses('error_messages', 'object', 'router', 'controller');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class Dispatcher extends Object {
/**
* Enter description here...
*
* @var unknown_type
*/
var $base = false;
/**
* Enter description here...
*
* @var unknown_type
*/
var $passed_args = array();
/**
* Enter description here...
*
*/
function __construct () {
$this->base = $this->baseUrl();
parent::__construct();
}
/**
* Enter description here...
*
* @param unknown_type $url
* @return unknown
*/
function dispatch ($url) {
global $_POST, $_GET, $_FILES, $_SESSION;
$params = $this->parseParams($url);
// die if no controller set
if (empty($params['controller']))
$this->errorNoController($url);
$ctrl_name = ucfirst($params['controller']);
$ctrl_class = $ctrl_name.'Controller';
// if specified controller class doesn't exist
if (!loadController($ctrl_name) || !class_exists($ctrl_class))
$this->errorUnknownController($url, $ctrl_name);
$controller = new $ctrl_class ($this);
$controller->cache = &$Cache;
$controller->base = $this->base;
// if action is not set, and the default Controller::index() method doesn't exist
if (empty($params['action'])) {
if (method_exists($controller, 'index'))
$params['action'] = 'index';
else
$this->errorNoAction($url);
}
// if the requested action doesn't exist
if (!method_exists($controller, $params['action']))
$this->errorUnknownAction($url, $ctrl_class, $params['action']);
$controller->params = $params;
$controller->action = $params['action'];
$controller->data = empty($params['data'])? null: $params['data'];
$controller->passed_args = empty($params['pass'])? null: $params['pass'];
// EXECUTE THE REQUESTED ACTION
call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']);
if ($controller->autoRender)
$controller->render();
return $params;
}
/**
* Enter description here...
*
* @param unknown_type $from_url
* @return unknown
*/
function parseParams ($from_url) {
global $_POST, $_FILES;
// load routes config
$Route = new Router();
require CONFIGS.'routes.php';
$params = $Route->parse ('/'.$from_url);
// add submitted form data
$params['form'] = $_POST;
if (isset($_POST['data']))
$params['data'] = $_POST['data'];
foreach ($_FILES as $name => $data)
$params['form'][$name] = $data;
return $params;
}
/**
* Enter description here...
*
* @return unknown
*/
function baseUrl () {
global $_SERVER;
//non mod_rewrite use:
if (defined('BASE_URL')) return BASE_URL;
$doc_root = $_SERVER['DOCUMENT_ROOT'];
$script_name = $_SERVER['PHP_SELF'];
// if document root ends with 'public', it's probably correctly set
$r = null;
if (!ereg('/^.*/public(\/)?$/', $doc_root))
return preg_match('/^(.*)\/public\/index\.php$/', $script_name, $r)? $r[1]: false;
// document root is probably not set to Cake 'public' dir
else
return preg_match('/^(.*)\/index\.php$/', $script_name, $r)? $r[1]: false;
}
/**
* Enter description here...
*
* @param unknown_type $code
* @param unknown_type $name
* @param unknown_type $message
*/
function error ($code, $name, $message) {
$controller = new Controller ($this);
$controller->base = $this->base;
$controller->error($code, $name, $message);
}
/**
* Enter description here...
*
* @param unknown_type $url
* @param unknown_type $message
*/
function error404 ($url, $message) {
$this->error('404', 'Not found', sprintf(ERROR_404, $url, $message));
}
/**
* Enter description here...
*
* @param unknown_type $url
*/
function errorNoController ($url) {
DEBUG?
trigger_error (ERROR_NO_CONTROLLER_SET, E_USER_ERROR):
$this->error404($url, "no controller set");
exit;
}
/**
* Enter description here...
*
* @param unknown_type $url
* @param unknown_type $controller_class
*/
function errorUnknownController ($url, $controller_class) {
DEBUG?
trigger_error (sprintf(ERROR_UNKNOWN_CONTROLLER, $controller_class), E_USER_ERROR):
$this->error404($url, "missing controller \"{$controller_class}\"");
exit;
}
/**
* Enter description here...
*
* @param unknown_type $url
*/
function errorNoAction ($url) {
DEBUG?
trigger_error (ERROR_NO_ACTION_SET, E_USER_ERROR):
$this->error404(sprintf(ERROR_404, $url, "no action set"));
exit;
}
/**
* Enter description here...
*
* @param unknown_type $url
* @param unknown_type $controller_class
* @param unknown_type $action
*/
function errorUnknownAction ($url,$controller_class, $action) {
DEBUG?
trigger_error (sprintf(ERROR_NO_ACTION, $action, $controller_class), E_USER_ERROR):
$this->error404($url, "missing controller \"{$controller_class}\"");
exit;
}
}
?>

View file

@ -1,122 +1,122 @@
<?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: Error Messages Defines
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
define ('ERROR_UNKNOWN_DATABASE_DRIVER', '[DbFactory] Specified database driver (%s) not found');
/**
* Enter description here...
*
*/
define ('ERROR_NO_CONTROLLER_SET', '[Dispatcher] No default controller, can\'t continue, check routes config');
/**
* Enter description here...
*
*/
define ('ERROR_UNKNOWN_CONTROLLER', '[Dispatcher] Specified controller "%s" doesn\'t exist, create it first');
/**
* Enter description here...
*
*/
define ('ERROR_NO_ACTION', '[Dispatcher] Action "%s" is not defined in the "%s" controller, create it first');
/**
* Enter description here...
*
*/
define ('ERROR_IN_VIEW', '[Controller] Error in view "%s", got: <blockquote>%s</blockquote>');
/**
* Enter description here...
*
*/
define ('ERROR_NO_VIEW', '[Controller] No template file for view "%s" (expected "%s"), create it first');
/**
* Enter description here...
*
*/
define ('ERROR_IN_LAYOUT', '[Controller] Error in layout "%s", got: <blockquote>"%s"</blockquote>');
/**
* Enter description here...
*
*/
define ('ERROR_NO_LAYOUT', '[Controller] Couln\'t find layout "%s" (expected "%s"), create it first');
/**
* Enter description here...
*
*/
define ('ERROR_NO_TABLE_LIST', '[Database] Couldn\'t get table list, check database config');
/**
* Enter description here...
*
*/
define ('ERROR_NO_MODEL_TABLE', '[Model] No DB table for model "%s" (expected "%s"), create it first');
/**
* Enter description here...
*
*/
define ('ERROR_NO_FIELD_IN_MODEL_DB', '[Model::set()] Field "%s" is not present in table "%s", check database schema');
/**
* Enter description here...
*
*/
define ('SHORT_ERROR_MESSAGE', '<div class="error_message"><i>%s</i></div>');
/**
* Enter description here...
*
*/
define ('ERROR_CANT_GET_ORIGINAL_IMAGE', '[Image] Couln\'t load original image %s (tried from "%s")');
/**
* Enter description here...
*
*/
define ('ERROR_404', "The requested address /%s was not found on this server."); // second %s contains short error message
/**
* Enter description here...
*
*/
define ('ERROR_500', "Application error, sorry.");
<?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: Error Messages Defines
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
define ('ERROR_UNKNOWN_DATABASE_DRIVER', '[DbFactory] Specified database driver (%s) not found');
/**
* Enter description here...
*
*/
define ('ERROR_NO_CONTROLLER_SET', '[Dispatcher] No default controller, can\'t continue, check routes config');
/**
* Enter description here...
*
*/
define ('ERROR_UNKNOWN_CONTROLLER', '[Dispatcher] Specified controller "%s" doesn\'t exist, create it first');
/**
* Enter description here...
*
*/
define ('ERROR_NO_ACTION', '[Dispatcher] Action "%s" is not defined in the "%s" controller, create it first');
/**
* Enter description here...
*
*/
define ('ERROR_IN_VIEW', '[Controller] Error in view "%s", got: <blockquote>%s</blockquote>');
/**
* Enter description here...
*
*/
define ('ERROR_NO_VIEW', '[Controller] No template file for view "%s" (expected "%s"), create it first');
/**
* Enter description here...
*
*/
define ('ERROR_IN_LAYOUT', '[Controller] Error in layout "%s", got: <blockquote>"%s"</blockquote>');
/**
* Enter description here...
*
*/
define ('ERROR_NO_LAYOUT', '[Controller] Couln\'t find layout "%s" (expected "%s"), create it first');
/**
* Enter description here...
*
*/
define ('ERROR_NO_TABLE_LIST', '[Database] Couldn\'t get table list, check database config');
/**
* Enter description here...
*
*/
define ('ERROR_NO_MODEL_TABLE', '[Model] No DB table for model "%s" (expected "%s"), create it first');
/**
* Enter description here...
*
*/
define ('ERROR_NO_FIELD_IN_MODEL_DB', '[Model::set()] Field "%s" is not present in table "%s", check database schema');
/**
* Enter description here...
*
*/
define ('SHORT_ERROR_MESSAGE', '<div class="error_message"><i>%s</i></div>');
/**
* Enter description here...
*
*/
define ('ERROR_CANT_GET_ORIGINAL_IMAGE', '[Image] Couln\'t load original image %s (tried from "%s")');
/**
* Enter description here...
*
*/
define ('ERROR_404', "The requested address /%s was not found on this server."); // second %s contains short error message
/**
* Enter description here...
*
*/
define ('ERROR_500', "Application error, sorry.");
?>

View file

@ -1,175 +1,175 @@
<?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: Flay
* Text-to-html parser, similar to Textile or RedCloth, only with somehow different syntax.
* See Flay::test() for examples.
* Test with $flay = new Flay(); $flay->test();
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
uses('object');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class Flay extends Object {
/**
* Enter description here...
*
* @var unknown_type
*/
var $text = null;
/**
* Enter description here...
*
* @var unknown_type
*/
var $allow_html = false;
/**
* Enter description here...
*
* @param unknown_type $text
*/
function __construct ($text=null) {
$this->text = $text;
parent::__construct();
}
/**
* Enter description here...
*
* @param unknown_type $text
* @return unknown
*/
function toHtml ($text=null) {
$text = $text? $text: $this->text;
// trim whitespace and disable all HTML
$text = str_replace('<', '&lt;', str_replace('>', '&gt;', trim($text)));
// multi-paragraph functions
$text = preg_replace('#(?:[\n]{0,2})"""(.*)"""(?:[\n]{0,2})#s', "\n\n%BLOCKQUOTE%\n\n\\1\n\n%ENDBLOCKQUOTE%\n\n", $text);
$text = preg_replace('#(?:[\n]{0,2})===(.*)===(?:[\n]{0,2})#s', "\n\n%CENTER%\n\n\\1\n\n%ENDCENTER%\n\n", $text);
// pre-parse newlines
$text = preg_replace("#\r\n#", "\n", $text);
$text = preg_replace("#[\n]{2,}#", "%PARAGRAPH%", $text);
$text = preg_replace('#[\n]{1}#', "%LINEBREAK%", $text);
// split into paragraphs and parse
$out = '';
foreach (split('%PARAGRAPH%', $text) as $line) {
if ($line) {
// pre-parse links
$links = array();
$regs = null;
if (preg_match_all('#\[([^\[]{4,})\]#', $line, $regs)) {
foreach ($regs[1] as $reg) {
$links[] = $reg;
$line = str_replace("[{$reg}]",'%LINK'.(count($links)-1).'%', $line);
}
}
// MAIN TEXT FUNCTIONS
// bold
$line = ereg_replace("\*([^\*]*)\*", "<strong>\\1</strong>", $line);
// italic
$line = ereg_replace("_([^_]*)_", "<em>\\1</em>", $line);
// entities
$line = str_replace(' - ', ' &ndash; ', $line);
$line = str_replace(' -- ', ' &mdash; ', $line);
$line = str_replace('(C)', '&copy;', $line);
$line = str_replace('(R)', '&reg;', $line);
$line = str_replace('(TM)', '&trade;', $line);
// guess e-mails
$emails = null;
if (preg_match_all("#([_A-Za-z0-9+-+]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#", $line, $emails)) {
foreach ($emails[1] as $email) {
$line = str_replace($email, "<a href=\"mailto:{$email}\">{$email}</a>", $line);
}
}
// guess links
$urls = null;
if (preg_match_all("#((?:http|https|ftp|nntp)://[^ ]+)#", $line, $urls)) {
foreach ($urls[1] as $url) {
$line = str_replace($url, "<a href=\"{$url}\">{$url}</a>", $line);
}
}
if (preg_match_all("#(www\.[^ ]+)#", $line, $urls)) {
foreach ($urls[1] as $url) {
$line = str_replace($url, "<a href=\"{$url}\">{$url}</a>", $line);
}
}
// re-parse links
if (count($links)) {
for ($ii=0; $ii<count($links); $ii++) {
if (preg_match('#\.(jpg|jpeg|gif|png)$#', $links[$ii]))
$with = "<img src=\"{$links[$ii]}\" alt=\"\" />";
elseif (preg_match('#^([^\]\ ]+)(?: ([^\]]+))?$#', $links[$ii], $regs))
$with = "<a href=\"{$regs[1]}\" target=\"_blank\">".(isset($regs[2])? $regs[2]: $regs[1])."</a>";
else
$with = $links[$ii];
$line = str_replace("%LINK{$ii}%", $with, $line);
}
}
// re-parse newlines
$out .= str_replace('%LINEBREAK%', "<br />\n", "<p>{$line}</p>\n");
}
}
// re-parse multilines
$out = str_replace('<p>%BLOCKQUOTE%</p>', "<blockquote>", $out);
$out = str_replace('<p>%ENDBLOCKQUOTE%</p>', "</blockquote>", $out);
$out = str_replace('<p>%CENTER%</p>', "<center>", $out);
$out = str_replace('<p>%ENDCENTER%</p>', "</center>", $out);
return $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 + //
//////////////////////////////////////////////////////////////////////////
/**
* Purpose: Flay
* Text-to-html parser, similar to Textile or RedCloth, only with somehow different syntax.
* See Flay::test() for examples.
* Test with $flay = new Flay(); $flay->test();
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
uses('object');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class Flay extends Object {
/**
* Enter description here...
*
* @var unknown_type
*/
var $text = null;
/**
* Enter description here...
*
* @var unknown_type
*/
var $allow_html = false;
/**
* Enter description here...
*
* @param unknown_type $text
*/
function __construct ($text=null) {
$this->text = $text;
parent::__construct();
}
/**
* Enter description here...
*
* @param unknown_type $text
* @return unknown
*/
function toHtml ($text=null) {
$text = $text? $text: $this->text;
// trim whitespace and disable all HTML
$text = str_replace('<', '&lt;', str_replace('>', '&gt;', trim($text)));
// multi-paragraph functions
$text = preg_replace('#(?:[\n]{0,2})"""(.*)"""(?:[\n]{0,2})#s', "\n\n%BLOCKQUOTE%\n\n\\1\n\n%ENDBLOCKQUOTE%\n\n", $text);
$text = preg_replace('#(?:[\n]{0,2})===(.*)===(?:[\n]{0,2})#s', "\n\n%CENTER%\n\n\\1\n\n%ENDCENTER%\n\n", $text);
// pre-parse newlines
$text = preg_replace("#\r\n#", "\n", $text);
$text = preg_replace("#[\n]{2,}#", "%PARAGRAPH%", $text);
$text = preg_replace('#[\n]{1}#', "%LINEBREAK%", $text);
// split into paragraphs and parse
$out = '';
foreach (split('%PARAGRAPH%', $text) as $line) {
if ($line) {
// pre-parse links
$links = array();
$regs = null;
if (preg_match_all('#\[([^\[]{4,})\]#', $line, $regs)) {
foreach ($regs[1] as $reg) {
$links[] = $reg;
$line = str_replace("[{$reg}]",'%LINK'.(count($links)-1).'%', $line);
}
}
// MAIN TEXT FUNCTIONS
// bold
$line = ereg_replace("\*([^\*]*)\*", "<strong>\\1</strong>", $line);
// italic
$line = ereg_replace("_([^_]*)_", "<em>\\1</em>", $line);
// entities
$line = str_replace(' - ', ' &ndash; ', $line);
$line = str_replace(' -- ', ' &mdash; ', $line);
$line = str_replace('(C)', '&copy;', $line);
$line = str_replace('(R)', '&reg;', $line);
$line = str_replace('(TM)', '&trade;', $line);
// guess e-mails
$emails = null;
if (preg_match_all("#([_A-Za-z0-9+-+]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#", $line, $emails)) {
foreach ($emails[1] as $email) {
$line = str_replace($email, "<a href=\"mailto:{$email}\">{$email}</a>", $line);
}
}
// guess links
$urls = null;
if (preg_match_all("#((?:http|https|ftp|nntp)://[^ ]+)#", $line, $urls)) {
foreach ($urls[1] as $url) {
$line = str_replace($url, "<a href=\"{$url}\">{$url}</a>", $line);
}
}
if (preg_match_all("#(www\.[^ ]+)#", $line, $urls)) {
foreach ($urls[1] as $url) {
$line = str_replace($url, "<a href=\"{$url}\">{$url}</a>", $line);
}
}
// re-parse links
if (count($links)) {
for ($ii=0; $ii<count($links); $ii++) {
if (preg_match('#\.(jpg|jpeg|gif|png)$#', $links[$ii]))
$with = "<img src=\"{$links[$ii]}\" alt=\"\" />";
elseif (preg_match('#^([^\]\ ]+)(?: ([^\]]+))?$#', $links[$ii], $regs))
$with = "<a href=\"{$regs[1]}\" target=\"_blank\">".(isset($regs[2])? $regs[2]: $regs[1])."</a>";
else
$with = $links[$ii];
$line = str_replace("%LINK{$ii}%", $with, $line);
}
}
// re-parse newlines
$out .= str_replace('%LINEBREAK%', "<br />\n", "<p>{$line}</p>\n");
}
}
// re-parse multilines
$out = str_replace('<p>%BLOCKQUOTE%</p>', "<blockquote>", $out);
$out = str_replace('<p>%ENDBLOCKQUOTE%</p>', "</blockquote>", $out);
$out = str_replace('<p>%CENTER%</p>', "<center>", $out);
$out = str_replace('<p>%ENDCENTER%</p>', "</center>", $out);
return $out;
}
}
?>

View file

@ -1,4 +1,4 @@
<?PHP
<?PHP
//////////////////////////////////////////////////////////////////////////
// + $Id$
// +------------------------------------------------------------------+ //
@ -34,18 +34,15 @@
/**
* Enter description here...
*
*/
uses('object');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class Inflector extends Object {

View file

@ -39,4 +39,24 @@ if (version_compare(phpversion(), '5.0') < 0) {
');
}
// needed for old Plog v2
//
function old_lib ($name) {
old_libs ($name);
}
function old_libs () {
if (count($lib_names = func_get_args())) {
foreach ($lib_names as $lib_name) {
require (OLD_LIBS.$lib_name.'.php');
}
return true;
}
else {
return false;
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -31,6 +31,16 @@ uses('log');
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
uses('log');
/**
* Enter description here...
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*/
class Object {
/**

View file

@ -1,169 +1,169 @@
<?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: Router
* Parses the request URL into controller, action, and params
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
uses('object');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class Router extends Object {
/**
* Enter description here...
*
* @var unknown_type
*/
var $routes = array();
/**
* Enter description here...
*
*/
function __construct () {
parent::__construct();
}
/**
* Enter description here...
*
* @param unknown_type $route
* @param unknown_type $default
*/
function connect ($route, $default=null) {
$parsed = $names = array ();
$r = null;
if (($route == '') || ($route == '/')) {
$regexp = '/^[\/]*$/';
$this->routes[] = array($route, $regexp, array(), $default);
}
else {
$elements = array();
foreach (explode('/', $route) as $element)
if (trim($element)) $elements[] = $element;
if (!count($elements))
return false;
foreach ($elements as $element) {
if (preg_match('/^:(.+)$/', $element, $r)) {
$parsed[] = '(?:\/([^\/]+))?';
$names[] = $r[1];
}
elseif (preg_match('/^\*$/', $element, $r)) {
$parsed[] = '(?:\/(.*))?';
}
else {
$parsed[] = '/'.$element;
}
}
$regexp = '#^'.join('', $parsed).'[\/]*$#';
$this->routes[] = array($route, $regexp, $names, $default);
}
return $this->routes;
}
/**
* Enter description here...
*
* @param unknown_type $url
* @return unknown
*/
function parse ($url) {
$out = array();
$r = null;
$default_route = array(
'/:controller/:action/* (default)',
"#^(?:\/(?:([a-z0-9_\-]+)(?:\/([a-z0-9_\-]+)(?:\/(.*))?)?))[\/]*$#",
array('controller', 'action'),
array()
);
$this->routes[] = $default_route;
foreach ($this->routes as $route) {
list($route, $regexp, $names, $defaults) = $route;
if (preg_match($regexp, $url, $r)) {
// $this->log($url.' matched '.$regexp, 'note');
// remove the first element, which is the url
array_shift($r);
// hack, pre-fill the default route names
foreach ($names as $name)
$out[$name] = null;
$ii = 0;
if (is_array($defaults)) {
foreach ($defaults as $name=>$value) {
if (preg_match('#[a-z_\-]#i', $name))
$out[$name] = $value;
else
$out['pass'][] = $value;
}
}
foreach ($r as $found) {
// if $found is a named url element (i.e. ':action')
if (isset($names[$ii])) {
$out[$names[$ii]] = $found;
}
// unnamed elements go in as 'pass'
else {
$pass = new NeatArray(explode('/', $found));
$pass->cleanup();
$out['pass'] = $pass->value;
}
$ii++;
}
break;
}
}
return $out;
}
}
<?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: Router
* Parses the request URL into controller, action, and params
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
uses('object');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class Router extends Object {
/**
* Enter description here...
*
* @var unknown_type
*/
var $routes = array();
/**
* Enter description here...
*
*/
function __construct () {
parent::__construct();
}
/**
* Enter description here...
*
* @param unknown_type $route
* @param unknown_type $default
*/
function connect ($route, $default=null) {
$parsed = $names = array ();
$r = null;
if (($route == '') || ($route == '/')) {
$regexp = '/^[\/]*$/';
$this->routes[] = array($route, $regexp, array(), $default);
}
else {
$elements = array();
foreach (explode('/', $route) as $element)
if (trim($element)) $elements[] = $element;
if (!count($elements))
return false;
foreach ($elements as $element) {
if (preg_match('/^:(.+)$/', $element, $r)) {
$parsed[] = '(?:\/([^\/]+))?';
$names[] = $r[1];
}
elseif (preg_match('/^\*$/', $element, $r)) {
$parsed[] = '(?:\/(.*))?';
}
else {
$parsed[] = '/'.$element;
}
}
$regexp = '#^'.join('', $parsed).'[\/]*$#';
$this->routes[] = array($route, $regexp, $names, $default);
}
return $this->routes;
}
/**
* Enter description here...
*
* @param unknown_type $url
* @return unknown
*/
function parse ($url) {
$out = array();
$r = null;
$default_route = array(
'/:controller/:action/* (default)',
"#^(?:\/(?:([a-z0-9_\-]+)(?:\/([a-z0-9_\-]+)(?:\/(.*))?)?))[\/]*$#",
array('controller', 'action'),
array()
);
$this->routes[] = $default_route;
foreach ($this->routes as $route) {
list($route, $regexp, $names, $defaults) = $route;
if (preg_match($regexp, $url, $r)) {
// $this->log($url.' matched '.$regexp, 'note');
// remove the first element, which is the url
array_shift($r);
// hack, pre-fill the default route names
foreach ($names as $name)
$out[$name] = null;
$ii = 0;
if (is_array($defaults)) {
foreach ($defaults as $name=>$value) {
if (preg_match('#[a-z_\-]#i', $name))
$out[$name] = $value;
else
$out['pass'][] = $value;
}
}
foreach ($r as $found) {
// if $found is a named url element (i.e. ':action')
if (isset($names[$ii])) {
$out[$names[$ii]] = $found;
}
// unnamed elements go in as 'pass'
else {
$pass = new NeatArray(explode('/', $found));
$pass->cleanup();
$out['pass'] = $pass->value;
}
$ii++;
}
break;
}
}
return $out;
}
}
?>

View file

@ -1,287 +1,287 @@
<?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: Renderer
* Templating for Controller class.
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
uses('object');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class Template extends Object {
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $base = null;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $layout = 'default';
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $autoRender = true;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $autoLayout = true;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_view_vars = array();
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_page_title = false;
/**
* Enter description here...
*
*/
function __construct () {
parent::__construct();
}
/**
* Enter description here...
*
* @param unknown_type $layout
*/
function setLayout ($layout) {
$this->layout = $layout;
}
/**
* Enter description here...
*
* @param unknown_type $one
* @param unknown_type $two
* @return unknown
*/
function set($one, $two=null) {
return $this->_setArray(is_array($one)? $one: array($one=>$two));
}
/**
* Enter description here...
*
* @param unknown_type $value
*/
function setTitle ($value) {
$this->_page_title = $value;
}
/**
* Enter description here...
*
* @param unknown_type $data
*/
function _setArray($data) {
foreach ($data as $name => $value) {
if ($name == 'title')
$this->setTitle ($value);
else
$this->_view_vars[$name] = $value;
}
}
/**
* Enter description here...
*
* @param unknown_type $message
* @param unknown_type $url
* @param unknown_type $time
*/
function flash ($message, $url, $time=1) {
$this->autoRender = false;
$this->autoLayout = false;
$this->set('url', $this->base.$url);
$this->set('message', $message);
$this->set('time', $time);
$this->render(null,false,VIEWS.'layouts'.DS.'flash.thtml');
}
/**
* Enter description here...
*
* @param unknown_type $action
* @param unknown_type $layout
* @param unknown_type $file
*/
function render ($action=null, $layout=null, $file=null) {
$this->autoRender = false;
if (!$action) $action = $this->action;
if ($layout) $this->setLayout($layout);
$view_fn = $file? $file: $this->_getViewFn($action);
if (!is_file($view_fn)) {
DEBUG? trigger_error (sprintf(ERROR_NO_VIEW, $action, $view_fn), E_USER_ERROR)
: $this->error('404', 'Not found', sprintf(ERROR_404, '', "missing view \"{$action}\""));
die();
}
$out = $this->_render($view_fn, $this->_view_vars, 0);
if ($out !== false) {
if ($this->layout && $this->autoLayout)
$out = $this->renderLayout($out);
print $out;
}
else {
$out = $this->_render($view_fn, $this->_view_vars, false);
trigger_error (sprintf(ERROR_IN_VIEW, $view_fn, $out), E_USER_ERROR);
}
}
/**
* Enter description here...
*
* @param unknown_type $content_for_layout
* @return unknown
*/
function renderLayout ($content_for_layout) {
$layout_fn = $this->_getLayoutFn();
$data_for_layout = array_merge($this->_view_vars, array(
'title_for_layout'=>$this->_page_title !== false? $this->_page_title: ucfirst($this->name),
'content_for_layout'=>$content_for_layout));
if (is_file($layout_fn)) {
$out = $this->_render($layout_fn, $data_for_layout);
if ($out === false) {
$out = $this->_render($layout_fn, $data_for_layout, false);
trigger_error (sprintf(ERROR_IN_LAYOUT, $layout_fn, $out), E_USER_ERROR);
return false;
}
else {
return $out;
}
}
else {
trigger_error (sprintf(ERROR_NO_LAYOUT, $this->layout, $layout_fn), E_USER_ERROR);
return false;
}
}
/**
* Enter description here...
*
* @return unknown
*/
function _getLayoutFn() {
return VIEWS."layouts".DS."{$this->layout}.thtml";
}
/**
* Enter description here...
*
* @param unknown_type $action
* @return unknown
*/
function _getViewFn($action) {
return VIEWS.$this->name.DS."{$action}.thtml";
}
/**
* Enter description here...
*
* @param unknown_type $___view_fn
* @param unknown_type $___data_for_view
* @param unknown_type $___play_safe
* @return unknown
*/
function _render($___view_fn, $___data_for_view, $___play_safe = true) {
extract($___data_for_view, EXTR_SKIP); # load all view variables
$BASE = $this->base;
$params = &$this->params;
$page_title = $this->_page_title;
ob_start(); # start caching output (eval outputs directly so we need to cache)
# include the template
$___play_safe? @include($___view_fn): include($___view_fn);
$out = ob_get_contents(); # retrieve cached output
ob_end_clean(); # end caching output
return $out;
}
/**
* trims a string to a specified length adding elipsis '..' if necessary
*
* @param unknown_type $string
* @param unknown_type $length
* @return unknown
*/
function trimTo ($string, $length) {
return substr($string, 0, $length).(strlen($string)>$length? '..': null);
}
}
<?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: Renderer
* Templating for Controller class.
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*
*/
uses('object');
/**
* Enter description here...
*
*
* @package cake
* @subpackage cake.libs
* @since Cake v 0.2.9
*
*/
class Template extends Object {
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $base = null;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $layout = 'default';
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $autoRender = true;
/**
* Enter description here...
*
* @var unknown_type
* @access public
*/
var $autoLayout = true;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_view_vars = array();
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_page_title = false;
/**
* Enter description here...
*
*/
function __construct () {
parent::__construct();
}
/**
* Enter description here...
*
* @param unknown_type $layout
*/
function setLayout ($layout) {
$this->layout = $layout;
}
/**
* Enter description here...
*
* @param unknown_type $one
* @param unknown_type $two
* @return unknown
*/
function set($one, $two=null) {
return $this->_setArray(is_array($one)? $one: array($one=>$two));
}
/**
* Enter description here...
*
* @param unknown_type $value
*/
function setTitle ($value) {
$this->_page_title = $value;
}
/**
* Enter description here...
*
* @param unknown_type $data
*/
function _setArray($data) {
foreach ($data as $name => $value) {
if ($name == 'title')
$this->setTitle ($value);
else
$this->_view_vars[$name] = $value;
}
}
/**
* Enter description here...
*
* @param unknown_type $message
* @param unknown_type $url
* @param unknown_type $time
*/
function flash ($message, $url, $time=1) {
$this->autoRender = false;
$this->autoLayout = false;
$this->set('url', $this->base.$url);
$this->set('message', $message);
$this->set('time', $time);
$this->render(null,false,VIEWS.'layouts'.DS.'flash.thtml');
}
/**
* Enter description here...
*
* @param unknown_type $action
* @param unknown_type $layout
* @param unknown_type $file
*/
function render ($action=null, $layout=null, $file=null) {
$this->autoRender = false;
if (!$action) $action = $this->action;
if ($layout) $this->setLayout($layout);
$view_fn = $file? $file: $this->_getViewFn($action);
if (!is_file($view_fn)) {
DEBUG? trigger_error (sprintf(ERROR_NO_VIEW, $action, $view_fn), E_USER_ERROR)
: $this->error('404', 'Not found', sprintf(ERROR_404, '', "missing view \"{$action}\""));
die();
}
$out = $this->_render($view_fn, $this->_view_vars, 0);
if ($out !== false) {
if ($this->layout && $this->autoLayout)
$out = $this->renderLayout($out);
print $out;
}
else {
$out = $this->_render($view_fn, $this->_view_vars, false);
trigger_error (sprintf(ERROR_IN_VIEW, $view_fn, $out), E_USER_ERROR);
}
}
/**
* Enter description here...
*
* @param unknown_type $content_for_layout
* @return unknown
*/
function renderLayout ($content_for_layout) {
$layout_fn = $this->_getLayoutFn();
$data_for_layout = array_merge($this->_view_vars, array(
'title_for_layout'=>$this->_page_title !== false? $this->_page_title: ucfirst($this->name),
'content_for_layout'=>$content_for_layout));
if (is_file($layout_fn)) {
$out = $this->_render($layout_fn, $data_for_layout);
if ($out === false) {
$out = $this->_render($layout_fn, $data_for_layout, false);
trigger_error (sprintf(ERROR_IN_LAYOUT, $layout_fn, $out), E_USER_ERROR);
return false;
}
else {
return $out;
}
}
else {
trigger_error (sprintf(ERROR_NO_LAYOUT, $this->layout, $layout_fn), E_USER_ERROR);
return false;
}
}
/**
* Enter description here...
*
* @return unknown
*/
function _getLayoutFn() {
return VIEWS."layouts".DS."{$this->layout}.thtml";
}
/**
* Enter description here...
*
* @param unknown_type $action
* @return unknown
*/
function _getViewFn($action) {
return VIEWS.$this->name.DS."{$action}.thtml";
}
/**
* Enter description here...
*
* @param unknown_type $___view_fn
* @param unknown_type $___data_for_view
* @param unknown_type $___play_safe
* @return unknown
*/
function _render($___view_fn, $___data_for_view, $___play_safe = true) {
extract($___data_for_view, EXTR_SKIP); # load all view variables
$BASE = $this->base;
$params = &$this->params;
$page_title = $this->_page_title;
ob_start(); # start caching output (eval outputs directly so we need to cache)
# include the template
$___play_safe? @include($___view_fn): include($___view_fn);
$out = ob_get_contents(); # retrieve cached output
ob_end_clean(); # end caching output
return $out;
}
/**
* trims a string to a specified length adding elipsis '..' if necessary
*
* @param unknown_type $string
* @param unknown_type $length
* @return unknown
*/
function trimTo ($string, $length) {
return substr($string, 0, $length).(strlen($string)>$length? '..': null);
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,13 @@
# Based on Rails 0.10.0 .htaccess (www.rubyonrails.com)
<IfModule mod_rewrite.c>
# Redirect all requests not available on the filesystem to Cake
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.php?url=$1 [QSA,L]
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
# In case Cake experiences terminal errors
ErrorDocument 500 500.html
</IfModule>

View file

@ -0,0 +1,57 @@
BODY {
font-size:.9em;
}
BODY, INPUT, TEXTAREA {
font-family:sans-serif;
}
H1 {
font-size:2.1em;
text-align:center;
}
H2 {
font-size:1.8em;
}
H3 {
font-size:1.5em;
}
P {
font-size:1em;
margin-bottom:.5em;
}
A {
white-space:nowrap;
text-decoration:underline;
}
CODE, PRE {
font-family:monospace;
font-size:1.1em !important;
font-size:.95em;
color:#44A;
margin:0;
}
CODE {
color:#227;
white-space:nowrap;
margin:0 .2em;
}
PRE {
margin-left:1em;
}
ACRONYM {
border-bottom:1px dotted;
}
HR {
height:0;
border-top:1px solid #AAA;
}

View file

@ -1,67 +0,0 @@
<?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: Dispatch
* The main "loop"
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.public
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
session_start();
/**
* Get Cake's root directory
*/
define ('DS', DIRECTORY_SEPARATOR);
define ('ROOT', substr(__FILE__, 0, strrpos(dirname(__FILE__), DS)+1));
/**
* Directory layout and basic functions
*/
require (ROOT.'config/core.php');
require (ROOT.'config/paths.php');
require (ROOT.'libs/basics.php');
DEBUG? error_reporting(E_ALL): error_reporting(0);
$TIME_START = getMicrotime();
uses ('folder', 'dispatcher', 'dbo_factory');
config ('tags', 'database');
$DB = DboFactory::make('devel');
loadModels ();
## RUN THE SCRIPT
$url = empty($_GET['url'])? null: $_GET['url'];
$DISPATCHER = new Dispatcher ();
$DISPATCHER->dispatch($url);
## CLEANUP
if (DEBUG) echo "<!-- ". round(getMicrotime() - $TIME_START, 2) ."s -->";
?>

View file

@ -1,4 +1,4 @@
<?php
<?PHP
//////////////////////////////////////////////////////////////////////////
// + $Id$
// +------------------------------------------------------------------+ //
@ -14,24 +14,54 @@
//////////////////////////////////////////////////////////////////////////
/**
* Enter description here...
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.public
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
* Purpose: Dispatch
* The main "loop"
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.public
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
session_start();
/**
* Enter description here...
*
* Get Cake's root directory
*/
header ('dispatch.php?url='.ltrim($_SERVER['PATH_INFO'],'/'));
?>
define ('DS', DIRECTORY_SEPARATOR);
define ('ROOT', dirname(dirname(__FILE__)).DS);
/**
* Directory layout and basic functions
*/
require (ROOT.'config/core.php');
require (ROOT.'config/paths.php');
require (ROOT.'libs/basics.php');
DEBUG? error_reporting(E_ALL): error_reporting(0);
$TIME_START = getMicrotime();
uses ('folder', 'dispatcher', 'dbo_factory');
config ('tags', 'database');
$DB = DboFactory::make('devel');
loadModels ();
## RUN THE SCRIPT
$url = empty($_GET['url'])? null: $_GET['url'];
$DISPATCHER = new Dispatcher ();
$DISPATCHER->dispatch($url);
## CLEANUP
if (DEBUG) echo "<!-- ". round(getMicrotime() - $TIME_START, 2) ."s -->";
?>

View file

@ -0,0 +1,37 @@
<?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 + //
//////////////////////////////////////////////////////////////////////////
/**
* Enter description here...
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.public
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Re-routes the request to dispatch.php
*/
include('dispatch.php')
// header ('dispatch.php?url='.ltrim($_SERVER['PATH_INFO'],'/'));
?>

View file

@ -1 +0,0 @@
@php -q scripts/add.php %1 %2 %3 %4 %5 %6 %7 %8 %9

1
scripts/bake.bat Normal file
View file

@ -0,0 +1 @@
@php -q add.php %1 %2 %3 %4 %5 %6 %7 %8 %9

View file

@ -1,48 +1,48 @@
#!/usr/local/bin/php
<?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 + //
//////////////////////////////////////////////////////////////////////////
/**
* Enter description here...
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.scripts
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* START-UP
*/
define ('DS', DIRECTORY_SEPARATOR);
define ('ROOT', substr(__FILE__, 0, strrpos(dirname(__FILE__), DS)+1));
require (ROOT.'config'.DS.'paths.php');
require (LIBS.'basics.php');
uses ('bake');
$waste = array_shift($argv);
$product = array_shift($argv);
$bake = new Bake ($product, $argv);
#!/usr/local/bin/php
<?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 + //
//////////////////////////////////////////////////////////////////////////
/**
* Enter description here...
*
* @filesource
* @author Cake Authors/Developers
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.scripts
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* START-UP
*/
define ('DS', DIRECTORY_SEPARATOR);
define ('ROOT', dirname(dirname(__FILE__)).DS);
require (ROOT.'config'.DS.'paths.php');
require (LIBS.'basics.php');
uses ('bake');
$waste = array_shift($argv);
$product = array_shift($argv);
$bake = new Bake ($product, $argv);
?>

View file

View file

View file

@ -26,22 +26,25 @@ class DboFactoryTest extends TestCase {
function testMake () {
$output = $this->abc->make('test');
$this->assertTrue(is_object($output));
if (class_exists(DATABASE_CONFIG)) {
$config = DATABASE_CONFIG::test();
if (preg_match('#^(adodb)_.*$#i', $config['driver'], $res)) {
$desired_driver_name = $res[1];
$output = $this->abc->make('test');
$this->assertTrue(is_object($output));
$config = DATABASE_CONFIG::test();
if (preg_match('#^(adodb)_.*$#i', $config['driver'], $res)) {
$desired_driver_name = $res[1];
}
else
$desired_driver_name = $config['driver'];
$desired_class_name = 'dbo_'.strtolower($desired_driver_name);
$output_class_name = is_object($output)? get_class($output): false;
$this->assertEquals($output_class_name, $desired_class_name);
$this->assertTrue($output->connected);
}
else
$desired_driver_name = $config['driver'];
$desired_class_name = 'dbo_'.strtolower($desired_driver_name);
$output_class_name = is_object($output)? get_class($output): false;
$this->assertEquals($output_class_name, $desired_class_name);
$this->assertTrue($output->connected);
}
// this test expect an E_USER_ERROR to occur during it's run

View file

@ -22,10 +22,14 @@ class DboTest extends TestCase {
// this function is defined in PHPUnit_TestCase and overwritten
// here
function tearDown() {
if (!$this->abc) return false;
$this->dropTemporaryTable();
}
function createTemporaryTable () {
if (!$this->abc) return false;
if ($this->abc->config['driver'] == 'postgres')
$sql = 'CREATE TABLE __test (id serial NOT NULL, body CHARACTER VARYING(255))';
else
@ -35,10 +39,14 @@ class DboTest extends TestCase {
}
function dropTemporaryTable () {
if (!$this->abc) return false;
return $this->abc->query("DROP TABLE __test");
}
function testHasImplementation () {
if (!$this->abc) return false;
$functions = array(
'connect',
'disconnect',
@ -59,15 +67,21 @@ class DboTest extends TestCase {
}
function testConnectivity () {
if (!$this->abc) return false;
$this->assertTrue($this->abc->connected);
}
function testFields () {
if (!$this->abc) return false;
$fields = $this->abc->fields('__test');
$this->assertEquals(count($fields), 2, 'equals');
}
function testTables () {
if (!$this->abc) return false;
$this->assertTrue(in_array('__test', $this->abc->tables()));
}
}

View file

@ -27,7 +27,7 @@ class FolderTest extends TestCase {
function testLs () {
$result = $this->abc->ls();
$expected = array(array('css', 'files', 'img'),array('.htaccess', '500.html', 'dispatch.php'));
$expected = array(array('css', 'files', 'img'),array('.htaccess', '500.html', 'index.php', 'index_no_mod_rewrite.php'));
$this->assertEquals($result, $expected);
}
@ -48,8 +48,8 @@ class FolderTest extends TestCase {
}
function testFindRecursive () {
$result = $this->abc->findRecursive('.*\.php');
$expected = array(Folder::addPathElement($this->abc->pwd(), 'dispatch.php'));
$result = $this->abc->findRecursive('.*ex\.php');
$expected = array(Folder::addPathElement($this->abc->pwd(), 'index.php'));
$this->assertEquals($result, $expected);
}

0
vendors/put_vendor_libraries_here vendored Normal file
View file