mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merging my changes into trunk. This should give us a nice clean trunk to continue with. It's strongly recommended that you merge this version with your sandboxes -- I've added all the phpdoc fields and changed a lot.
I've removed the author/licence information from some files -- such as app/app_controller.php and config/database.php -- as they are not our code and those files need to remain as clean as possible for people not to get lost in them. I've run the tests on this one, but the tests are not as extensive as they should be. If you want to get the test controller etc. check out the version in my sandbox. But we'll probably be moving to SimpleTest soon anyway. git-svn-id: https://svn.cakephp.org/repo/trunk/cake@114 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
bb71238ec1
commit
a778f3c3c3
33 changed files with 4689 additions and 4350 deletions
|
@ -1,114 +1,6 @@
|
||||||
<?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. + //
|
|
||||||
// + 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: AppController
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @filesource
|
|
||||||
* @author Michal Tatarynowicz <tatarynowicz@gmail.com>
|
|
||||||
* @author Larry E. Masters aka PhpNut <nut@phpnut.com>
|
|
||||||
* @author Kamil Dzielinski aka Brego <brego.dk@gmail.com>
|
|
||||||
* @copyright Copyright (c) 2005, Cake Authors/Developers
|
|
||||||
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
|
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.app
|
|
||||||
* @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...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.app
|
|
||||||
* @since Cake v 0.2.9
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class AppController extends Controller {
|
class AppController extends Controller {
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $tags
|
|
||||||
* @param unknown_type $active
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function tags_as_links ($tags, $active=array()) {
|
|
||||||
$tags = is_array($tags)? $tags: Tag::split_tags($tags);
|
|
||||||
|
|
||||||
$links = array();
|
|
||||||
foreach ($tags as $tag) {
|
|
||||||
|
|
||||||
if (in_array($tag, $active))
|
|
||||||
$url_tags = $this->array_except($active, $tag);
|
|
||||||
else
|
|
||||||
$url_tags = array_merge($active, array($tag));
|
|
||||||
|
|
||||||
$url = '/memes/with_tags/'.$this->tags_to_url($url_tags);
|
|
||||||
|
|
||||||
$links[] = $this->link_to($tag, $url, in_array($tag, $active)? array('class'=>'active_tag'): null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return join(' ', $links);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $array
|
|
||||||
* @param unknown_type $except
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function array_except ($array, $except) {
|
|
||||||
if (!is_array($except)) $except = array($except);
|
|
||||||
$out = array();
|
|
||||||
|
|
||||||
foreach ($array as $k=>$v) {
|
|
||||||
if (!in_array($v, $except))
|
|
||||||
$out[$k] = $v;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $tags
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function tags_to_url ($tags) {
|
|
||||||
$out = array();
|
|
||||||
foreach ($tags as $tag)
|
|
||||||
$out[] = urlencode($tag);
|
|
||||||
|
|
||||||
return join('+', $out);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -1,53 +1,5 @@
|
||||||
<?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. + //
|
|
||||||
// + 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: AppModel
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @filesource
|
|
||||||
* @author Michal Tatarynowicz <tatarynowicz@gmail.com>
|
|
||||||
* @author Larry E. Masters aka PhpNut <nut@phpnut.com>
|
|
||||||
* @author Kamil Dzielinski aka Brego <brego.dk@gmail.com>
|
|
||||||
* @copyright Copyright (c) 2005, Cake Authors/Developers
|
|
||||||
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
|
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.app
|
|
||||||
* @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...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.app
|
|
||||||
* @since Cake v 0.2.9
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class AppModel extends Model {
|
class AppModel extends Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
26
config/core.php
Normal file
26
config/core.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Basic configuration
|
||||||
|
*/
|
||||||
|
// Debugging level
|
||||||
|
// 0: production, 1: development, 2: full debug with sql
|
||||||
|
define ('DEBUG', 0);
|
||||||
|
|
||||||
|
// Full-page caching
|
||||||
|
define ('CACHE_PAGES', false);
|
||||||
|
// Cache lifetime in seconds, 0 for debugging, -1 for eternity,
|
||||||
|
define ('CACHE_PAGES_FOR', -1);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Advanced configuration
|
||||||
|
*/
|
||||||
|
// Debug options
|
||||||
|
if (DEBUG) {
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
ini_set('error_reporting', E_ALL);
|
||||||
|
$TIME_START = getmicrotime();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -1,51 +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. + //
|
|
||||||
// + 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:
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @filesource
|
|
||||||
* @author Michal Tatarynowicz <tatarynowicz@gmail.com>
|
|
||||||
* @author Larry E. Masters aka PhpNut <nut@phpnut.com>
|
|
||||||
* @author Kamil Dzielinski aka Brego <brego.dk@gmail.com>
|
|
||||||
* @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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
$DATABASE_CONFIG = array(
|
|
||||||
'devel' => array(
|
|
||||||
'host' => 'localhost',
|
|
||||||
'login' => 'www',
|
|
||||||
'password' => 'www',
|
|
||||||
'database' => 'ease'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
?>
|
|
|
@ -1,51 +1,22 @@
|
||||||
<?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. + //
|
|
||||||
// + 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:
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @filesource
|
|
||||||
* @author Michal Tatarynowicz <tatarynowicz@gmail.com>
|
|
||||||
* @author Larry E. Masters aka PhpNut <nut@phpnut.com>
|
|
||||||
* @author Kamil Dzielinski aka Brego <brego.dk@gmail.com>
|
|
||||||
* @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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
$DATABASE_CONFIG = array(
|
$DATABASE_CONFIG = array(
|
||||||
'devel' => array(
|
'devel' => array(
|
||||||
|
'driver' => 'mysql',
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
'login' => 'cake',
|
'login' => 'login',
|
||||||
'password' => 'cake',
|
'password' => 'password',
|
||||||
'database' => 'cake'
|
'database' => 'database'
|
||||||
)
|
),
|
||||||
|
|
||||||
|
'test' => array(
|
||||||
|
'driver' => 'mysql',
|
||||||
|
'host' => 'localhost',
|
||||||
|
'login' => 'login',
|
||||||
|
'password' => 'password',
|
||||||
|
'database' => 'database'
|
||||||
|
),
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
?>
|
?>
|
19
config/paths.php
Normal file
19
config/paths.php
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?PHP
|
||||||
|
|
||||||
|
define ('ROOT', '../');
|
||||||
|
define ('APP', ROOT.'app/');
|
||||||
|
define ('MODELS', APP.'models/');
|
||||||
|
define ('CONTROLLERS', APP.'controllers/');
|
||||||
|
define ('HELPERS', APP.'helpers/');
|
||||||
|
define ('VIEWS', APP.'views/');
|
||||||
|
define ('CONFIGS', ROOT.'config/');
|
||||||
|
define ('LIBS', ROOT.'libs/');
|
||||||
|
define ('PUBLIC', ROOT.'public/');
|
||||||
|
define ('TESTS', ROOT.'tests/');
|
||||||
|
define ('VENDORS', ROOT.'vendors/');
|
||||||
|
define ('CONTROLLER_TESTS',TESTS.'app/controllers/');
|
||||||
|
define ('HELPER_TESTS', TESTS.'app/helpers/');
|
||||||
|
define ('MODEL_TESTS', TESTS.'app/models/');
|
||||||
|
define ('LIB_TESTS', TESTS.'libs/')
|
||||||
|
|
||||||
|
?>
|
|
@ -1,52 +1,9 @@
|
||||||
<?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. + //
|
|
||||||
// + 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:
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @filesource
|
|
||||||
* @author Michal Tatarynowicz <tatarynowicz@gmail.com>
|
|
||||||
* @author Larry E. Masters aka PhpNut <nut@phpnut.com>
|
|
||||||
* @author Kamil Dzielinski aka Brego <brego.dk@gmail.com>
|
|
||||||
* @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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
# Homepage
|
# Homepage
|
||||||
$Route->connect ('/', array('controller'=>'Memes', 'action'=>'add'));
|
$Route->connect ('/', array('controller'=>'Pages', 'action'=>'index'));
|
||||||
|
|
||||||
# Tags
|
# Tests
|
||||||
$Route->connect ('/tags/popular', array('controller'=>'Tags', 'action'=>'popular'));
|
$Route->connect ('/test', array('controller'=>'Tests', 'action'=>'test_all'));
|
||||||
$Route->connect ('/tags/*', array('controller'=>'Memes', 'action'=>'with_tags'));
|
|
||||||
|
|
||||||
# Default route
|
|
||||||
$Route->connect ('/:controller/:action/*');
|
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -1,54 +1,9 @@
|
||||||
<?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. + //
|
|
||||||
// + 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:
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @filesource
|
|
||||||
* @author Michal Tatarynowicz <tatarynowicz@gmail.com>
|
|
||||||
* @author Larry E. Masters aka PhpNut <nut@phpnut.com>
|
|
||||||
* @author Kamil Dzielinski aka Brego <brego.dk@gmail.com>
|
|
||||||
* @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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
# Homepage
|
# Homepage
|
||||||
$Route->connect ('/', array('controller'=>'Pages', 'action'=>'view', 'home'));
|
$Route->connect ('/', array('controller'=>'Pages', 'action'=>'index'));
|
||||||
|
|
||||||
# Source browser
|
# Tests
|
||||||
#$Route->connect ('/sources/*', array('controller'=>'Sources', 'action'=>'index'));
|
$Route->connect ('/test', array('controller'=>'Tests', 'action'=>'test_all'));
|
||||||
|
|
||||||
# Content pages
|
|
||||||
#$Route->connect ('/*', array('controller'=>'Pages', 'action'=>'view'));
|
|
||||||
|
|
||||||
# Default route
|
|
||||||
$Route->connect ('/:controller/:action/*');
|
|
||||||
|
|
||||||
?>
|
?>
|
34
config/tags.php
Normal file
34
config/tags.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?PHP
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tag generator templates
|
||||||
|
*
|
||||||
|
* Usually there's no need to change those.
|
||||||
|
*/
|
||||||
|
|
||||||
|
define('TAG_LINK', '<a href="%s"%s>%s</a>');
|
||||||
|
|
||||||
|
define('TAG_FORM', '<form %s>');
|
||||||
|
|
||||||
|
define('TAG_INPUT', '<input name="data[%s]" %s/>');
|
||||||
|
define('TAG_HIDDEN', '<input type="hidden" name="data[%s]" %s/>');
|
||||||
|
define('TAG_AREA', '<textarea name="data[%s]"%s>%s</textarea>');
|
||||||
|
define('TAG_CHECKBOX', '<label for="tag_%s"><input type="checkbox" name="data[%s]" id="tag_%s" %s/>%s</label>');
|
||||||
|
define('TAG_RADIOS', '<label for="tag_%s"><input type="radio" name="data[%s]" id="tag_%s" %s/>%s</label>');
|
||||||
|
|
||||||
|
define('TAG_SELECT_START', '<select name="data[%s]"%s>');
|
||||||
|
define('TAG_SELECT_EMPTY', '<option value=""%s></option>');
|
||||||
|
define('TAG_SELECT_OPTION','<option value="%s"%s>%s</option>');
|
||||||
|
define('TAG_SELECT_END', '</select>');
|
||||||
|
|
||||||
|
define('TAG_PASSWORD', '<input type="password" name="data[%s]" %s/>');
|
||||||
|
define('TAG_FILE', '<input type="file" name="%s" %s/>');
|
||||||
|
|
||||||
|
define('TAG_SUBMIT', '<input type="submit" %s/>');
|
||||||
|
|
||||||
|
define('TAG_IMAGE', '<img src="%s" alt="%s" %s/>');
|
||||||
|
|
||||||
|
define('TAG_TABLE_HEADER', '<th%s>%s</th>');
|
||||||
|
define('TAG_TABLE_HEADERS','<tr%s>%s</tr>');
|
||||||
|
define('TAG_TABLE_CELL', '<td%s>%s</td>');
|
||||||
|
define('TAG_TABLE_ROW', '<tr%s>%s</tr>');
|
381
libs/bake.php
381
libs/bake.php
|
@ -90,37 +90,50 @@ class Bake extends Object {
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $model_template = "<?PHP
|
var $dont_ask = false;
|
||||||
|
|
||||||
class %s extends AppModel {
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @param unknown_type $type
|
||||||
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
var $action_template = "
|
function template ($type) {
|
||||||
function %s () {
|
switch ($type) {
|
||||||
|
case 'model': return "<?PHP\n\nclass %s extends AppModel {\n}\n\n?>";
|
||||||
|
case 'action': return "\n\tfunction %s () {\n\t}\n";
|
||||||
|
case 'ctrl': return "<?PHP\n\nclass %s extends %s {\n%s\n}\n\n?>";
|
||||||
|
case 'helper': return "<?PHP\n\nclass %s extends AppController {\n}\n\n?>";
|
||||||
|
case 'test': return '<?PHP
|
||||||
|
|
||||||
|
class %sTest extends TestCase {
|
||||||
|
var $abc;
|
||||||
|
|
||||||
|
// called before the tests
|
||||||
|
function setUp() {
|
||||||
|
$this->abc = new %s ();
|
||||||
}
|
}
|
||||||
";
|
|
||||||
|
|
||||||
/**
|
// called after the tests
|
||||||
* Enter description here...
|
function tearDown() {
|
||||||
*
|
unset($this->abc);
|
||||||
* @var unknown_type
|
}
|
||||||
*/
|
|
||||||
var $controller_template = "<?PHP
|
|
||||||
|
|
||||||
class %s extends AppController {
|
/*
|
||||||
%s
|
function testFoo () {
|
||||||
|
$result = $this->abc->Foo();
|
||||||
|
$expected = \'\';
|
||||||
|
$this->assertEquals($result, $expected);
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>';
|
||||||
";
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -128,48 +141,48 @@ class %s extends AppController {
|
||||||
* @param unknown_type $type
|
* @param unknown_type $type
|
||||||
* @param unknown_type $names
|
* @param unknown_type $names
|
||||||
*/
|
*/
|
||||||
function __construct ($type, $names) {
|
function __construct ($type, $names) {
|
||||||
|
|
||||||
$this->stdin = fopen('php://stdin', 'r');
|
$this->stdin = fopen('php://stdin', 'r');
|
||||||
$this->stdout = fopen('php://stdout', 'w');
|
$this->stdout = fopen('php://stdout', 'w');
|
||||||
$this->stderr = fopen('php://stderr', 'w');
|
$this->stderr = fopen('php://stderr', 'w');
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
|
||||||
case 'model':
|
case 'model':
|
||||||
case 'models':
|
case 'models':
|
||||||
foreach ($names as $model_name)
|
foreach ($names as $model_name)
|
||||||
$this->create_model($model_name);
|
$this->newModel($model_name);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'controller':
|
case 'controller':
|
||||||
case 'ctrl':
|
case 'ctrl':
|
||||||
$controller = array_shift($names);
|
$controller = array_shift($names);
|
||||||
|
|
||||||
$add_actions = array();
|
$add_actions = array();
|
||||||
foreach ($names as $action) {
|
foreach ($names as $action) {
|
||||||
$add_actions[] = $action;
|
$add_actions[] = $action;
|
||||||
$this->create_view($controller, $action);
|
$this->newView($controller, $action);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->create_controller($controller, $add_actions);
|
$this->newController($controller, $add_actions);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'view':
|
case 'view':
|
||||||
case 'views':
|
case 'views':
|
||||||
$r = null;
|
$r = null;
|
||||||
foreach ($names as $model_name) {
|
foreach ($names as $model_name) {
|
||||||
if (preg_match('/^([a-z0-9_]+(?:\/[a-z0-9_]+)*)\/([a-z0-9_]+)$/i', $model_name, $r)) {
|
if (preg_match('/^([a-z0-9_]+(?:\/[a-z0-9_]+)*)\/([a-z0-9_]+)$/i', $model_name, $r)) {
|
||||||
$this->create_view($r[1], $r[2]);
|
$this->newView($r[1], $r[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->actions)
|
if (!$this->actions)
|
||||||
fwrite($this->stderr, "Nothing to do, quitting.\n");
|
fwrite($this->stderr, "Nothing to do, quitting.\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -177,39 +190,41 @@ class %s extends AppController {
|
||||||
* @param unknown_type $controller
|
* @param unknown_type $controller
|
||||||
* @param unknown_type $name
|
* @param unknown_type $name
|
||||||
*/
|
*/
|
||||||
function create_view ($controller, $name) {
|
function newView ($controller, $name) {
|
||||||
$dir = Inflector::underscore($controller);
|
$dir = Inflector::underscore($controller);
|
||||||
$this->create_dir(VIEWS.$dir);
|
$this->createDir(VIEWS.$dir);
|
||||||
$this->create_file(VIEWS.$dir.'/'.strtolower($name).'.thtml', '');
|
$fn = VIEWS.$dir.'/'.strtolower($name).'.thtml';
|
||||||
$this->actions++;
|
$this->createFile($fn, '');
|
||||||
}
|
$this->actions++;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $name
|
* @param unknown_type $controller
|
||||||
* @param unknown_type $actions
|
* @param array $actions
|
||||||
*/
|
*/
|
||||||
function create_controller ($name, $actions=array()) {
|
function newController ($name, $actions=array()) {
|
||||||
$class_name = Inflector::camelize($name).'Controller';
|
$this->makeController($name, $actions);
|
||||||
$content = array();
|
$this->makeControllerTest($name);
|
||||||
foreach ($actions as $action)
|
$this->makeHelper($name);
|
||||||
$content[] = sprintf($this->action_template, ($action));
|
$this->makeHelperTest($name);
|
||||||
|
$this->actions++;
|
||||||
$this->create_file($this->controller_fn($name), sprintf($this->controller_template, $class_name, join('', $content)));
|
}
|
||||||
$this->actions++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $name
|
* @param unknown_type $controller
|
||||||
|
* @param array $actions
|
||||||
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function create_model ($name) {
|
function makeController ($name, $actions) {
|
||||||
$class_name = Inflector::camelize($name);
|
$ctrl = $this->makeControllerName($name);
|
||||||
$this->create_file($this->model_fn($name), sprintf($this->model_template, $class_name));
|
$helper = $this->makeHelperName($name);
|
||||||
$this->actions++;
|
$body = sprintf($this->template('ctrl'), $ctrl, $helper, join('', $this->getActions($actions)));
|
||||||
}
|
return $this->createFile($this->makeControllerFn($name), $body);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -217,9 +232,9 @@ class %s extends AppController {
|
||||||
* @param unknown_type $name
|
* @param unknown_type $name
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function model_fn ($name) {
|
function makeControllerName ($name) {
|
||||||
return MODELS.Inflector::underscore($name).'.php';
|
return Inflector::camelize($name).'Controller';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -227,9 +242,131 @@ class %s extends AppController {
|
||||||
* @param unknown_type $name
|
* @param unknown_type $name
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function controller_fn ($name) {
|
function makeControllerFn ($name) {
|
||||||
return CONTROLLERS.Inflector::underscore($name).'_controller.php';
|
return CONTROLLERS.Inflector::underscore($name).'_controller.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $name
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function makeControllerTest ($name) {
|
||||||
|
$fn = CONTROLLER_TESTS.Inflector::underscore($name).'_controller_test.php';
|
||||||
|
$body = $this->getTestBody($this->makeControllerName($name));
|
||||||
|
return $this->createFile($fn, $body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $name
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function makeHelper ($name) {
|
||||||
|
$body = sprintf($this->template('helper'), $this->makeHelperName($name));
|
||||||
|
return $this->createFile($this->makeHelperFn($name), $body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $name
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function makeHelperName ($name) {
|
||||||
|
return Inflector::camelize($name).'Helper';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $controller
|
||||||
|
* @param array $actions
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function makeHelperFn ($name) {
|
||||||
|
return HELPERS.Inflector::underscore($name).'_helper.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $name
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function makeHelperTest ($name) {
|
||||||
|
$fn = HELPER_TESTS.Inflector::underscore($name).'_helper_test.php';
|
||||||
|
$body = $this->getTestBody($this->makeHelperName($name));
|
||||||
|
return $this->createFile($fn, $body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $as
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function getActions ($as) {
|
||||||
|
$out = array();
|
||||||
|
foreach ($as as $a)
|
||||||
|
$out[] = sprintf($this->template('action'), $a);
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $class
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function getTestBody ($class) {
|
||||||
|
return sprintf($this->template('test'), $class, $class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $name
|
||||||
|
*/
|
||||||
|
function newModel ($name) {
|
||||||
|
$this->createFile($this->getModelFn($name), sprintf($this->template('model'), $this->getModelName($name)));
|
||||||
|
$this->makeModelTest ($name);
|
||||||
|
$this->actions++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $name
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function getModelFn ($name) {
|
||||||
|
return MODELS.Inflector::underscore($name).'.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $name
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function makeModelTest ($name) {
|
||||||
|
$fn = MODEL_TESTS.Inflector::underscore($name).'_test.php';
|
||||||
|
$body = $this->getTestBody($this->getModelName($name));
|
||||||
|
return $this->createFile($fn, $body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $name
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function getModelName ($name) {
|
||||||
|
return Inflector::camelize($name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -238,48 +375,60 @@ class %s extends AppController {
|
||||||
* @param unknown_type $contents
|
* @param unknown_type $contents
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function create_file ($path, $contents) {
|
function createFile ($path, $contents) {
|
||||||
|
|
||||||
if (is_file($path)) {
|
if (is_file($path) && !$this->dont_ask) {
|
||||||
fwrite($this->stdout, "File {$path} exists, overwrite? (y/N) ");
|
fwrite($this->stdout, "File {$path} exists, overwrite? (yNaq) ");
|
||||||
$key = fgets($this->stdin);
|
$key = fgets($this->stdin);
|
||||||
|
|
||||||
if (preg_match("/^q/", $key)) {
|
if (preg_match("/^q/", $key)) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
if (!preg_match("/^y/", $key)) {
|
if (preg_match("/^n/", $key)) {
|
||||||
fwrite($this->stdout, "Skip {$path}\n");
|
fwrite($this->stdout, "Skip {$path}\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
if (preg_match("/^a/", $key)) {
|
||||||
|
$this->dont_ask = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($f = fopen($path, 'w')) {
|
if ($f = fopen($path, 'w')) {
|
||||||
fwrite($f, $contents);
|
fwrite($f, $contents);
|
||||||
fclose($f);
|
fclose($f);
|
||||||
fwrite($this->stdout, "Wrote {$path}\n");
|
fwrite($this->stdout, "Wrote {$path}\n");
|
||||||
return true;
|
// debug ("Wrote {$path}");
|
||||||
}
|
return true;
|
||||||
else {
|
}
|
||||||
fwrite($this->stderr, "Error! Couldn't open {$path} for writing.\n");
|
else {
|
||||||
return false;
|
fwrite($this->stderr, "Error! Couldn't open {$path} for writing.\n");
|
||||||
}
|
// debug ("Error! Couldn't open {$path} for writing.");
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $path
|
* @param unknown_type $path
|
||||||
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function create_dir ($path) {
|
function createDir ($path) {
|
||||||
if (!is_dir($path)) {
|
if (is_dir($path))
|
||||||
if (mkdir($path)) {
|
return true;
|
||||||
fwrite($this->stdout, "Created {$path}\n");
|
|
||||||
}
|
if (mkdir($path)) {
|
||||||
else {
|
fwrite($this->stdout, "Created {$path}\n");
|
||||||
fwrite($this->stderr, "Error! Couldn't create dir {$path}\n");
|
// debug ("Created {$path}");
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
|
fwrite($this->stderr, "Error! Couldn't create dir {$path}\n");
|
||||||
|
// debug ("Error! Couldn't create dir {$path}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
234
libs/basics.php
234
libs/basics.php
|
@ -44,11 +44,11 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function load_libs () {
|
function load_libs () {
|
||||||
foreach (list_modules(LIBS) as $lib) {
|
foreach (list_modules(LIBS) as $lib) {
|
||||||
if ($lib != 'basics') {
|
if ($lib != 'basics') {
|
||||||
include_once (LIBS.$lib.'.php');
|
include_once (LIBS.$lib.'.php');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,10 +56,10 @@ function load_libs () {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function load_models () {
|
function load_models () {
|
||||||
require (APP.'app_model.php');
|
require (APP.'app_model.php');
|
||||||
foreach (list_modules(MODELS) as $model) {
|
foreach (list_modules(MODELS) as $model) {
|
||||||
require (MODELS.$model.'.php');
|
require (MODELS.$model.'.php');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,10 +67,15 @@ function load_models () {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function load_controllers () {
|
function load_controllers () {
|
||||||
require (APP.'app_controller.php');
|
require (APP.'app_controller.php');
|
||||||
foreach (list_modules(CONTROLLERS) as $controller) {
|
|
||||||
require (CONTROLLERS.$controller.'.php');
|
foreach (list_modules(HELPERS) as $helper) {
|
||||||
}
|
require (HELPERS.$helper.'.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (list_modules(CONTROLLERS) as $controller) {
|
||||||
|
require (CONTROLLERS.$controller.'.php');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,23 +86,23 @@ function load_controllers () {
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function list_modules($path, $sort=true) {
|
function list_modules($path, $sort=true) {
|
||||||
if ($d = opendir($path)) {
|
if ($d = opendir($path)) {
|
||||||
$out = array();
|
$out = array();
|
||||||
$r = null;
|
$r = null;
|
||||||
while (false !== ($fn = readdir($d))) {
|
while (false !== ($fn = readdir($d))) {
|
||||||
if (preg_match('#^(.+)\.php$#', $fn, $r)) {
|
if (preg_match('#^(.+)\.php$#', $fn, $r)) {
|
||||||
$out[] = $r[1];
|
$out[] = $r[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($sort || $this->sort) {
|
if ($sort || $this->sort) {
|
||||||
sort($out);
|
sort($out);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,30 +110,60 @@ function list_modules($path, $sort=true) {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function uses_config () {
|
function uses_config () {
|
||||||
global $TIME_START;
|
global $TIME_START;
|
||||||
|
|
||||||
require (CONFIGS.'core.php');
|
require (CONFIGS.'core.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function uses_database () {
|
function uses_database ($level='devel') {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
if (file_exists(CONFIGS.'database.php')) {
|
if ($config = loadDatabaseConfig($level)) {
|
||||||
require (CONFIGS.'database.php');
|
|
||||||
$DB = new DBO ($DATABASE_CONFIG['devel'], DEBUG > 1);
|
$db_driver_class = 'DBO_'.$config['driver'];
|
||||||
}
|
$db_driver_fn = LIBS.strtolower($db_driver_class.'.php');
|
||||||
|
|
||||||
|
if (file_exists($db_driver_fn)) {
|
||||||
|
uses (strtolower($db_driver_class));
|
||||||
|
$DB = new $db_driver_class ($config);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
die('Specified ('.$config['driver'].') database driver not found.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function loadDatabaseConfig ($level='devel') {
|
||||||
|
if (file_exists(CONFIGS.'database.php'))
|
||||||
|
require (CONFIGS.'database.php');
|
||||||
|
|
||||||
|
if (empty($DATABASE_CONFIG))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (empty($DATABASE_CONFIG[$level]))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!is_array($DATABASE_CONFIG[$level]))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return $DATABASE_CONFIG[$level];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function uses_tags () {
|
function uses_tag_generator () {
|
||||||
require (CONFIGS.'tags.php');
|
require (CONFIGS.'tags.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,10 +171,10 @@ function uses_tags () {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function uses () {
|
function uses () {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
foreach ($args as $arg) {
|
foreach ($args as $arg) {
|
||||||
require_once (LIBS.$arg.'.php');
|
require_once (LIBS.$arg.'.php');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,12 +184,12 @@ function uses () {
|
||||||
* @param unknown_type $show_html
|
* @param unknown_type $show_html
|
||||||
*/
|
*/
|
||||||
function debug($var = FALSE, $show_html = false) {
|
function debug($var = FALSE, $show_html = false) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
print "\n<pre>\n";
|
print "\n<pre>\n";
|
||||||
if ($show_html) $var = str_replace('<', '<', str_replace('>', '>', $var));
|
if ($show_html) $var = str_replace('<', '<', str_replace('>', '>', $var));
|
||||||
print_r($var);
|
print_r($var);
|
||||||
print "\n</pre>\n";
|
print "\n</pre>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -165,10 +200,10 @@ if (!function_exists('getMicrotime')) {
|
||||||
*
|
*
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function getMicrotime() {
|
function getMicrotime() {
|
||||||
list($usec, $sec) = explode(" ", microtime());
|
list($usec, $sec) = explode(" ", microtime());
|
||||||
return ((float)$usec + (float)$sec);
|
return ((float)$usec + (float)$sec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!function_exists('sortByKey')) {
|
if (!function_exists('sortByKey')) {
|
||||||
/**
|
/**
|
||||||
|
@ -180,27 +215,52 @@ if (!function_exists('sortByKey')) {
|
||||||
* @param unknown_type $type
|
* @param unknown_type $type
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function sortByKey(&$array, $sortby, $order='asc', $type=SORT_NUMERIC) {
|
function sortByKey(&$array, $sortby, $order='asc', $type=SORT_NUMERIC) {
|
||||||
|
|
||||||
if( is_array($array) ) {
|
if( is_array($array) ) {
|
||||||
|
|
||||||
foreach( $array AS $key => $val )
|
foreach( $array AS $key => $val )
|
||||||
$sa[$key] = $val[$sortby];
|
$sa[$key] = $val[$sortby];
|
||||||
|
|
||||||
if( $order == 'asc' )
|
if( $order == 'asc' )
|
||||||
asort($sa, $type);
|
asort($sa, $type);
|
||||||
else
|
else
|
||||||
arsort($sa, $type);
|
arsort($sa, $type);
|
||||||
|
|
||||||
foreach( $sa as $key=>$val )
|
foreach( $sa as $key=>$val )
|
||||||
$out[] = $array[$key];
|
$out[] = $array[$key];
|
||||||
|
|
||||||
Return $out;
|
Return $out;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Return null;
|
Return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('array_combine')) {
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $a1
|
||||||
|
* @param unknown_type $a2
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function array_combine($a1, $a2) {
|
||||||
|
$a1 = array_values($a1);
|
||||||
|
$a2 = array_values($a2);
|
||||||
|
|
||||||
|
if (count($a1) != count($a2)) return false; // different lenghts
|
||||||
|
if (count($a1) <= 0) return false; // arrays are the same and both are empty
|
||||||
|
|
||||||
|
$output = array();
|
||||||
|
|
||||||
|
for ($i = 0; $i < count($a1); $i++) {
|
||||||
|
$output[$a1[$i]] = $a2[$i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -220,9 +280,9 @@ class neatArray {
|
||||||
* @param unknown_type $value
|
* @param unknown_type $value
|
||||||
* @return neatArray
|
* @return neatArray
|
||||||
*/
|
*/
|
||||||
function neatArray ($value) {
|
function neatArray ($value) {
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -231,16 +291,30 @@ class neatArray {
|
||||||
* @param unknown_type $value
|
* @param unknown_type $value
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function find_in ($field_name, $value) {
|
function findIn ($field_name, $value) {
|
||||||
$out = false;
|
$out = false;
|
||||||
foreach ($this->value as $k=>$v) {
|
foreach ($this->value as $k=>$v) {
|
||||||
if (isset($v[$field_name]) && ($v[$field_name] == $value)) {
|
if (isset($v[$field_name]) && ($v[$field_name] == $value)) {
|
||||||
$out[$k] = $v;
|
$out[$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function cleanup () {
|
||||||
|
$out = is_array($this->value)? array(): null;
|
||||||
|
foreach ($this->value as $k=>$v) {
|
||||||
|
if ($v) {
|
||||||
|
$out[$k] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->value = $out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -61,38 +61,38 @@ class Cache extends Model {
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $id = null;
|
var $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $data = null;
|
var $data = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $for_caching = null;
|
var $for_caching = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $use_table = 'cache';
|
var $use_table = 'cache';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $id
|
* @param unknown_type $id
|
||||||
*/
|
*/
|
||||||
function __construct ($id) {
|
function __construct ($id) {
|
||||||
$this->id = (md5($id));
|
$this->id = (md5($id));
|
||||||
parent::__construct($this->id);
|
parent::__construct($this->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -100,10 +100,10 @@ class Cache extends Model {
|
||||||
* @param unknown_type $id
|
* @param unknown_type $id
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function id ($id=null) {
|
function id ($id=null) {
|
||||||
if (!$id) return $this->id;
|
if (!$id) return $this->id;
|
||||||
return ($this->id = $id);
|
return ($this->id = $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -112,50 +112,50 @@ class Cache extends Model {
|
||||||
* @param unknown_type $keep_for
|
* @param unknown_type $keep_for
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function remember ($content, $keep_for=CACHE_PAGES_FOR) {
|
function remember ($content, $keep_for=CACHE_PAGES_FOR) {
|
||||||
$data = addslashes($this->for_caching.$content);
|
$data = addslashes($this->for_caching.$content);
|
||||||
$expire = date("Y-m-d H:i:s",time()+($keep_for>0? $keep_for: 999999999));
|
$expire = date("Y-m-d H:i:s",time()+($keep_for>0? $keep_for: 999999999));
|
||||||
return $this->query("REPLACE {$this->use_table} (id,data,expire) VALUES ('{$this->id}', '{$data}', '{$expire}')");
|
return $this->query("REPLACE {$this->use_table} (id,data,expire) VALUES ('{$this->id}', '{$data}', '{$expire}')");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function restore () {
|
function restore () {
|
||||||
if (empty($this->data['data']))
|
if (empty($this->data['data']))
|
||||||
return $this->find("id='{$this->id}' AND expire>NOW()");
|
return $this->find("id='{$this->id}' AND expire>NOW()");
|
||||||
|
|
||||||
return $this->data['data'];
|
return $this->data['data'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function has () {
|
function has () {
|
||||||
return is_array($this->data = $this->find("id='{$this->id}' AND expire>NOW()"));
|
return is_array($this->data = $this->find("id='{$this->id}' AND expire>NOW()"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $string
|
* @param unknown_type $string
|
||||||
*/
|
*/
|
||||||
function append ($string) {
|
function append ($string) {
|
||||||
$this->for_caching .= $string;
|
$this->for_caching .= $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function clear () {
|
function clear () {
|
||||||
return $this->query("DELETE FROM {$this->use_table}");
|
return $this->query("DELETE FROM {$this->use_table}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -111,50 +111,61 @@ class Controller extends Template {
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function __construct () {
|
function __construct () {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$r = null;
|
$r = null;
|
||||||
if (!preg_match('/(.*)Controller/i', get_class($this), $r))
|
if (!preg_match('/(.*)Controller/i', get_class($this), $r))
|
||||||
die("Controller::__construct() : Can't get or parse my own class name, exiting.");
|
die("Controller::__construct() : Can't get or parse my own class name, exiting.");
|
||||||
|
|
||||||
$this->name = strtolower($r[1]);
|
$this->name = strtolower($r[1]);
|
||||||
|
|
||||||
if ($this->uses === false) {
|
$model_class = Inflector::singularize($this->name);
|
||||||
if (!$DB)
|
if (($this->uses === false) && class_exists($model_class)) {
|
||||||
die("Controller::__construct() : ".$this->name." controller needs database access, exiting.");
|
if (!$DB)
|
||||||
|
die("Controller::__construct() : ".$this->name." controller needs database access, exiting.");
|
||||||
|
|
||||||
$model_class = Inflector::singularize($this->name);
|
$this->$model_class = new $model_class ();
|
||||||
if (class_exists($model_class))
|
}
|
||||||
$this->$model_class = new $model_class ();
|
elseif ($this->uses) {
|
||||||
}
|
if (!$DB)
|
||||||
elseif ($this->uses) {
|
die("Controller::__construct() : ".$this->name." controller needs database access, exiting.");
|
||||||
if (!$DB)
|
|
||||||
die("Controller::__construct() : ".$this->name." controller needs database access, exiting.");
|
|
||||||
|
|
||||||
$uses = is_array($this->uses)? $this->uses: array($this->uses);
|
$uses = is_array($this->uses)? $this->uses: array($this->uses);
|
||||||
|
|
||||||
foreach ($uses as $model_name) {
|
foreach ($uses as $model_name) {
|
||||||
$model_class = ucfirst(strtolower($model_name));
|
$model_class = ucfirst(strtolower($model_name));
|
||||||
if (class_exists($model_class))
|
if (class_exists($model_class))
|
||||||
$this->$model_name = new $model_name (false);
|
$this->$model_name = new $model_name (false);
|
||||||
else
|
else
|
||||||
die("Controller::__construct() : ".ucfirst($this->name)." requires missing model {$model_class}, exiting.");
|
die("Controller::__construct() : ".ucfirst($this->name)." requires missing model {$model_class}, exiting.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $url
|
* @param unknown_type $url
|
||||||
*/
|
*/
|
||||||
function redirect ($url) {
|
function redirect ($url) {
|
||||||
$this->auto_render = false;
|
$this->auto_render = false;
|
||||||
header ('Location: '.$this->base.$url);
|
header ('Location: '.$this->base.$url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $action
|
||||||
|
*/
|
||||||
|
function setAction ($action) {
|
||||||
|
$this->action = $action;
|
||||||
|
|
||||||
|
$args = func_get_args();
|
||||||
|
call_user_func_array(array(&$this, $action), $args);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -162,17 +173,17 @@ class Controller extends Template {
|
||||||
* @param unknown_type $url
|
* @param unknown_type $url
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function url_for ($url=null) {
|
function urlFor ($url=null) {
|
||||||
if (empty($url)) {
|
if (empty($url)) {
|
||||||
return $this->base.'/'.strtolower($this->params['controller']).'/'.strtolower($this->params['action']);
|
return $this->base.'/'.strtolower($this->params['controller']).'/'.strtolower($this->params['action']);
|
||||||
}
|
}
|
||||||
elseif ($url[0] == '/') {
|
elseif ($url[0] == '/') {
|
||||||
return $this->base . $url;
|
return $this->base . $url;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return $this->base . '/' . strtolower($this->params['controller']) . '/' . $url;
|
return $this->base . '/' . strtolower($this->params['controller']) . '/' . $url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -182,19 +193,19 @@ class Controller extends Template {
|
||||||
* @param unknown_type $insert_after
|
* @param unknown_type $insert_after
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function parse_html_options ($options, $insert_before=' ', $insert_after=null) {
|
function parseHtmlOptions ($options, $insert_before=' ', $insert_after=null) {
|
||||||
if (is_array($options)) {
|
if (is_array($options)) {
|
||||||
$out = array();
|
$out = array();
|
||||||
foreach ($options as $k=>$v) {
|
foreach ($options as $k=>$v) {
|
||||||
$out[] = "{$k}=\"{$v}\"";
|
$out[] = "{$k}=\"{$v}\"";
|
||||||
}
|
}
|
||||||
$out = join(' ', $out);
|
$out = join(' ', $out);
|
||||||
return $out? $insert_before.$out.$insert_after: null;
|
return $out? $insert_before.$out.$insert_after: null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return $options? $insert_before.$options.$insert_after: null;
|
return $options? $insert_before.$options.$insert_after: null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -202,13 +213,13 @@ class Controller extends Template {
|
||||||
* @param unknown_type $title
|
* @param unknown_type $title
|
||||||
* @param unknown_type $url
|
* @param unknown_type $url
|
||||||
* @param unknown_type $html_options
|
* @param unknown_type $html_options
|
||||||
* @param unknown_type $confirm
|
* @param unknown_type $confirm_message
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function link_to ($title, $url, $html_options=null, $confirm=false) {
|
function linkTo ($title, $url, $html_options=null, $confirm_message=false) {
|
||||||
$confirm? $html_options['onClick'] = "return confirm('{$confirm}')": null;
|
$confirm_message? $html_options['onClick'] = "return confirm('{$confirm_message}')": null;
|
||||||
return sprintf(TAG_LINK, $this->url_for($url), $this->parse_html_options($html_options), $title);
|
return sprintf(TAG_LINK, $this->UrlFor($url), $this->parseHtmlOptions($html_options), $title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -218,10 +229,10 @@ class Controller extends Template {
|
||||||
* @param unknown_type $html_options
|
* @param unknown_type $html_options
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function link_out ($title, $url=null, $html_options=null) {
|
function linkOut ($title, $url=null, $html_options=null) {
|
||||||
$url = $url? $url: $title;
|
$url = $url? $url: $title;
|
||||||
return sprintf(TAG_LINK, $url, $this->parse_html_options($html_options), $title);
|
return sprintf(TAG_LINK, $url, $this->parseHtmlOptions($html_options), $title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -231,13 +242,13 @@ class Controller extends Template {
|
||||||
* @param unknown_type $html_options
|
* @param unknown_type $html_options
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function form_tag ($target=null, $type='post', $html_options=null) {
|
function formTag ($target=null, $type='post', $html_options=null) {
|
||||||
$html_options['action'] = $this->url_for($target);
|
$html_options['action'] = $this->UrlFor($target);
|
||||||
$html_options['method'] = $type=='get'? 'get': 'post';
|
$html_options['method'] = $type=='get'? 'get': 'post';
|
||||||
$type == 'file'? $html_options['enctype'] = 'multipart/form-data': null;
|
$type == 'file'? $html_options['enctype'] = 'multipart/form-data': null;
|
||||||
|
|
||||||
return sprintf(TAG_FORM, $this->parse_html_options($html_options, ''));
|
return sprintf(TAG_FORM, $this->parseHtmlOptions($html_options, ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -246,10 +257,10 @@ class Controller extends Template {
|
||||||
* @param unknown_type $html_options
|
* @param unknown_type $html_options
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function submit_tag ($caption='Submit', $html_options=null) {
|
function submitTag ($caption='Submit', $html_options=null) {
|
||||||
$html_options['value'] = $caption;
|
$html_options['value'] = $caption;
|
||||||
return sprintf(TAG_SUBMIT, $this->parse_html_options($html_options, '', ' '));
|
return sprintf(TAG_SUBMIT, $this->parseHtmlOptions($html_options, '', ' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -259,12 +270,26 @@ class Controller extends Template {
|
||||||
* @param unknown_type $html_options
|
* @param unknown_type $html_options
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function input_tag ($tag_name, $size=20, $html_options=null) {
|
function inputTag ($tag_name, $size=20, $html_options=null) {
|
||||||
$html_options['size'] = $size;
|
$html_options['size'] = $size;
|
||||||
$html_options['value'] = isset($html_options['value'])? $html_options['value']: $this->tag_value($tag_name);
|
$html_options['value'] = isset($html_options['value'])? $html_options['value']: $this->tagValue($tag_name);
|
||||||
$this->tag_is_invalid($tag_name)? $html_options['class'] = 'form_error': null;
|
$this->tagIsInvalid($tag_name)? $html_options['class'] = 'form_error': null;
|
||||||
return sprintf(TAG_INPUT, $tag_name, $this->parse_html_options($html_options, '', ' '));
|
return sprintf(TAG_INPUT, $tag_name, $this->parseHtmlOptions($html_options, '', ' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $tag_name
|
||||||
|
* @param unknown_type $size
|
||||||
|
* @param unknown_type $html_options
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function passwordTag ($tag_name, $size=20, $html_options=null) {
|
||||||
|
$html_options['size'] = $size;
|
||||||
|
empty($html_options['value'])? $html_options['value'] = $this->tagValue($tag_name): null;
|
||||||
|
return sprintf(TAG_PASSWORD, $tag_name, $this->parseHtmlOptions($html_options, '', ' '));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -274,24 +299,10 @@ class Controller extends Template {
|
||||||
* @param unknown_type $html_options
|
* @param unknown_type $html_options
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function hidden_tag ($tag_name, $value=null, $html_options=null) {
|
function hiddenTag ($tag_name, $value=null, $html_options=null) {
|
||||||
$html_options['value'] = $value? $value: $this->tag_value($tag_name);
|
$html_options['value'] = $value? $value: $this->tagValue($tag_name);
|
||||||
return sprintf(TAG_HIDDEN, $tag_name, $this->parse_html_options($html_options, '', ' '));
|
return sprintf(TAG_HIDDEN, $tag_name, $this->parseHtmlOptions($html_options, '', ' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $tag_name
|
|
||||||
* @param unknown_type $size
|
|
||||||
* @param unknown_type $html_options
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function password_tag ($tag_name, $size=20, $html_options=null) {
|
|
||||||
$html_options['size'] = $size;
|
|
||||||
$html_options['value'] = $value? $value: $this->tag_value($tag_name);
|
|
||||||
return sprintf(TAG_PASSWORD, $tag_name, $this->parse_html_options($html_options, '', ' '));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -300,9 +311,9 @@ class Controller extends Template {
|
||||||
* @param unknown_type $html_options
|
* @param unknown_type $html_options
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function file_tag ($tag_name, $html_options=null) {
|
function fileTag ($tag_name, $html_options=null) {
|
||||||
return sprintf(TAG_FILE, $tag_name, $this->parse_html_options($html_options, '', ' '));
|
return sprintf(TAG_FILE, $tag_name, $this->parseHtmlOptions($html_options, '', ' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -313,12 +324,12 @@ class Controller extends Template {
|
||||||
* @param unknown_type $html_options
|
* @param unknown_type $html_options
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function area_tag ($tag_name, $cols=60, $rows=10, $html_options=null) {
|
function areaTag ($tag_name, $cols=60, $rows=10, $html_options=null) {
|
||||||
$value = $value? $value: $this->tag_value($tag_name);
|
$value = empty($html_options['value'])? $this->tagValue($tag_name): empty($html_options['value']);
|
||||||
$html_options['cols'] = $cols;
|
$html_options['cols'] = $cols;
|
||||||
$html_options['rows'] = $rows;
|
$html_options['rows'] = $rows;
|
||||||
return sprintf(TAG_AREA, $tag_name, $this->parse_html_options($html_options, ' '), $value);
|
return sprintf(TAG_AREA, $tag_name, $this->parseHtmlOptions($html_options, ' '), $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -328,11 +339,11 @@ class Controller extends Template {
|
||||||
* @param unknown_type $html_options
|
* @param unknown_type $html_options
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function checkbox_tag ($tag_name, $title=null, $html_options=null) {
|
function checkboxTag ($tag_name, $title=null, $html_options=null) {
|
||||||
$this->tag_value($tag_name)? $html_options['checked'] = 'checked ': null;
|
$this->tagValue($tag_name)? $html_options['checked'] = 'checked': null;
|
||||||
$title = $title? $title: ucfirst($tag_name);
|
$title = $title? $title: ucfirst($tag_name);
|
||||||
return sprintf(TAG_CHECKBOX, $tag_name, $tag_name, $tag_name, $this->parse_html_options($html_options, '', ' '), $title);
|
return sprintf(TAG_CHECKBOX, $tag_name, $tag_name, $tag_name, $this->parseHtmlOptions($html_options, '', ' '), $title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -343,19 +354,20 @@ class Controller extends Template {
|
||||||
* @param unknown_type $html_options
|
* @param unknown_type $html_options
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function radio_tags ($tag_name, $options, $inbetween=null, $html_options=null) {
|
function radioTags ($tag_name, $options, $inbetween=null, $html_options=null) {
|
||||||
$value = isset($html_options['value'])? $html_options['value']: $this->tag_value($tag_name);
|
$value = isset($html_options['value'])? $html_options['value']: $this->tagValue($tag_name);
|
||||||
$out = array();
|
$out = array();
|
||||||
foreach ($options as $opt_value=>$opt_title) {
|
foreach ($options as $opt_value=>$opt_title) {
|
||||||
$options_here = array('value' => $opt_value);
|
$options_here = array('value' => $opt_value);
|
||||||
$opt_value==$value? $options_here['checked'] = 'checked': null;
|
$opt_value==$value? $options_here['checked'] = 'checked': null;
|
||||||
$parsed_options = $this->parse_html_options(array_merge($html_options, $options_here), '', ' ');
|
$parsed_options = $this->parseHtmlOptions(array_merge($html_options, $options_here), '', ' ');
|
||||||
$individual_tag_name = "{$tag_name}_{$opt_value}";
|
$individual_tag_name = "{$tag_name}_{$opt_value}";
|
||||||
$out[] = sprintf(TAG_RADIOS, $individual_tag_name, $tag_name, $individual_tag_name, $parsed_options, $opt_title);
|
$out[] = sprintf(TAG_RADIOS, $individual_tag_name, $tag_name, $individual_tag_name, $parsed_options, $opt_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
return join($inbetween, $out);
|
$out = join($inbetween, $out);
|
||||||
}
|
return $out? $out: null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -366,20 +378,35 @@ class Controller extends Template {
|
||||||
* @param unknown_type $inner_options
|
* @param unknown_type $inner_options
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function select_tag ($tag_name, $options, $outer_options=null, $inner_options=null) {
|
function selectTag ($tag_name, $options, $outer_options=null, $inner_options=null) {
|
||||||
$selected = isset($html_options['value'])? $html_options['value']: $this->tag_value($tag_name);
|
if (!is_array($options) || !count($options))
|
||||||
$select[] = sprintf(TAG_SELECT_START, $tag_name, $this->parse_html_options($outer_options));
|
return null;
|
||||||
$select[] = sprintf(TAG_SELECT_EMPTY, $this->parse_html_options($inner_options));
|
$selected = isset($html_options['value'])? $html_options['value']: $this->tagValue($tag_name);
|
||||||
|
$select[] = sprintf(TAG_SELECT_START, $tag_name, $this->parseHtmlOptions($outer_options));
|
||||||
|
$select[] = sprintf(TAG_SELECT_EMPTY, $this->parseHtmlOptions($inner_options));
|
||||||
|
|
||||||
foreach ($options as $name=>$title) {
|
foreach ($options as $name=>$title) {
|
||||||
$options_here = $selected==$name? array_merge($inner_options, array('selected'=>'selected')): $inner_options;
|
$options_here = $selected==$name? array_merge($inner_options, array('selected'=>'selected')): $inner_options;
|
||||||
$select[] = sprintf(TAG_SELECT_OPTION, $name, $this->parse_html_options($options_here), $title);
|
$select[] = sprintf(TAG_SELECT_OPTION, $name, $this->parseHtmlOptions($options_here), $title);
|
||||||
}
|
}
|
||||||
|
|
||||||
$select[] = sprintf(TAG_SELECT_END);
|
$select[] = sprintf(TAG_SELECT_END);
|
||||||
|
|
||||||
return implode("\n", $select);
|
return implode("\n", $select);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $path
|
||||||
|
* @param unknown_type $alt
|
||||||
|
* @param unknown_type $html_options
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function imageTag ($path, $alt=null, $html_options=null) {
|
||||||
|
$url = "{$this->base}/images/{$path}";
|
||||||
|
return sprintf(TAG_IMAGE, $url, $alt, $this->parseHtmlOptions($html_options, '', ' '));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -389,15 +416,15 @@ class Controller extends Template {
|
||||||
* @param unknown_type $th_options
|
* @param unknown_type $th_options
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function table_headers ($names, $tr_options=null, $th_options=null) {
|
function tableHeaders ($names, $tr_options=null, $th_options=null) {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
$out = array();
|
$out = array();
|
||||||
foreach ($names as $arg)
|
foreach ($names as $arg)
|
||||||
$out[] = sprintf(TAG_TABLE_HEADER, $this->parse_html_options($th_options), $arg);
|
$out[] = sprintf(TAG_TABLE_HEADER, $this->parseHtmlOptions($th_options), $arg);
|
||||||
|
|
||||||
return sprintf(TAG_TABLE_HEADERS, $this->parse_html_options($tr_options), join(' ', $out));
|
return sprintf(TAG_TABLE_HEADERS, $this->parseHtmlOptions($tr_options), join(' ', $out));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -407,32 +434,23 @@ class Controller extends Template {
|
||||||
* @param unknown_type $td_options
|
* @param unknown_type $td_options
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function table_cells ($data, $tr_options=null, $td_options=null) {
|
function tableCells ($data, $odd_tr_options=null, $even_tr_options=null) {
|
||||||
if (empty($data[0]) || !is_array($data[0]))
|
if (empty($data[0]) || !is_array($data[0]))
|
||||||
$data = array($data);
|
$data = array($data);
|
||||||
|
|
||||||
foreach ($data as $line) {
|
$count=0;
|
||||||
$cells_out = array();
|
foreach ($data as $line) {
|
||||||
foreach ($line as $cell) $cells_out[] = sprintf(TAG_TABLE_CELL, $this->parse_html_options($td_options), $cell);
|
$count++;
|
||||||
$out[] = join(' ', $cells_out);
|
$cells_out = array();
|
||||||
}
|
foreach ($line as $cell)
|
||||||
|
$cells_out[] = sprintf(TAG_TABLE_CELL, null, $cell);
|
||||||
|
|
||||||
return sprintf(TAG_TABLE_ROW, $this->parse_html_options($tr_options), join("\n", $out));
|
$options = $this->parseHtmlOptions($count%2? $odd_tr_options: $even_tr_options);
|
||||||
}
|
$out[] = sprintf(TAG_TABLE_ROW, $options, join(' ', $cells_out));
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $name
|
|
||||||
* @param unknown_type $alt
|
|
||||||
* @param unknown_type $html_options
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function image_tag ($name, $alt=null, $html_options=null) {
|
|
||||||
$url = "{$this->base}/images/{$name}";
|
|
||||||
return sprintf(TAG_IMAGE, $url, $alt, $this->parse_html_options($html_options, '', ' '));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return join("\n", $out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -441,19 +459,38 @@ class Controller extends Template {
|
||||||
* @param unknown_type $tag_name
|
* @param unknown_type $tag_name
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function tag_value ($tag_name) {
|
function tagValue ($tag_name) {
|
||||||
return isset($this->params['data'][$tag_name])? $this->params['data'][$tag_name]: null;
|
return isset($this->params['data'][$tag_name])? $this->params['data'][$tag_name]: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $field
|
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function tag_is_invalid ($field) {
|
function validate () {
|
||||||
return !empty($this->validation_errors[$field]);
|
$args = func_get_args();
|
||||||
}
|
$errors = call_user_func_array(array(&$this, 'validateErrors'), $args);
|
||||||
|
|
||||||
|
return count($errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function validateErrors () {
|
||||||
|
$objects = func_get_args();
|
||||||
|
if (!count($objects)) return false;
|
||||||
|
|
||||||
|
$errors = array();
|
||||||
|
foreach ($objects as $object) {
|
||||||
|
$errors = array_merge($errors, $object->invalidFields());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->validation_errors = (count($errors)? $errors: false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -462,9 +499,19 @@ class Controller extends Template {
|
||||||
* @param unknown_type $text
|
* @param unknown_type $text
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function validation_error ($field, $text) {
|
function tagErrorMsg ($field, $text) {
|
||||||
return $this->tag_is_invalid($field)? sprintf(SHORT_ERROR_MESSAGE, $text): null;
|
return $this->tagIsInvalid($field)? sprintf(SHORT_ERROR_MESSAGE, $text): null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $field
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function tagIsInvalid ($field) {
|
||||||
|
return !empty($this->validation_errors[$field]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -474,41 +521,29 @@ class Controller extends Template {
|
||||||
* @param unknown_type $name
|
* @param unknown_type $name
|
||||||
* @param unknown_type $link
|
* @param unknown_type $link
|
||||||
*/
|
*/
|
||||||
function add_crumb ($name, $link) {
|
function addCrumb ($name, $link) {
|
||||||
$this->_crumbs[] = array ($name, $link);
|
$this->_crumbs[] = array ($name, $link);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function get_crumbs () {
|
function getCrumbs () {
|
||||||
|
|
||||||
if (count($this->_crumbs)) {
|
if (count($this->_crumbs)) {
|
||||||
|
|
||||||
$out = array("<a href=\"{$this->base}\">START</a>");
|
$out = array("<a href=\"{$this->base}\">START</a>");
|
||||||
foreach ($this->_crumbs as $crumb) {
|
foreach ($this->_crumbs as $crumb) {
|
||||||
$out[] = "<a href=\"{$this->base}{$crumb[1]}\">{$crumb[0]}</a>";
|
$out[] = "<a href=\"{$this->base}{$crumb[1]}\">{$crumb[0]}</a>";
|
||||||
}
|
}
|
||||||
|
|
||||||
return join(' » ', $out);
|
return join(' » ', $out);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $action
|
|
||||||
*/
|
|
||||||
function set_action ($action) {
|
|
||||||
$this->action = $action;
|
|
||||||
|
|
||||||
$args = func_get_args();
|
|
||||||
call_user_func_array(array(&$this, $action), $args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -517,39 +552,10 @@ class Controller extends Template {
|
||||||
* @param unknown_type $name
|
* @param unknown_type $name
|
||||||
* @param unknown_type $message
|
* @param unknown_type $message
|
||||||
*/
|
*/
|
||||||
function error ($code, $name, $message) {
|
function error ($code, $name, $message) {
|
||||||
header ("HTTP/1.0 {$code} {$name}");
|
header ("HTTP/1.0 {$code} {$name}");
|
||||||
print ($this->_do_render(VIEWS.'layouts/error.thtml', array('code'=>$code,'name'=>$name,'message'=>$message)));
|
print ($this->_do_render(VIEWS.'layouts/error.thtml', array('code'=>$code,'name'=>$name,'message'=>$message)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function validates () {
|
|
||||||
$args = func_get_args();
|
|
||||||
$errors = call_user_func_array(array(&$this, 'validation_errors'), $args);
|
|
||||||
|
|
||||||
return count($errors);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function validation_errors () {
|
|
||||||
$objects = func_get_args();
|
|
||||||
if (!count($objects)) return false;
|
|
||||||
|
|
||||||
$errors = array();
|
|
||||||
foreach ($objects as $object) {
|
|
||||||
$errors = array_merge($errors, $object->invalid_fields());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->validation_errors = (count($errors)? $errors: false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
521
libs/dbo-ado.php
521
libs/dbo-ado.php
|
@ -1,521 +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. + //
|
|
||||||
// + 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/ADO
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* A MySQL functions wrapper. Provides ability to get results as arrays
|
|
||||||
* and query logging (with execution time).
|
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
*
|
|
||||||
* <code>
|
|
||||||
* require('dbo.php');
|
|
||||||
*
|
|
||||||
* // create and connect the object
|
|
||||||
* $db = new DBO(array(
|
|
||||||
* 'host'=>'localhost',
|
|
||||||
* 'login'=>'username',
|
|
||||||
* 'password'=>'password',
|
|
||||||
* 'database'=>'database'
|
|
||||||
* 'type'=>'mysql'));
|
|
||||||
*
|
|
||||||
* // read the whole query result array (of rows)
|
|
||||||
* $all_rows = $db->all("SELECT a,b,c FROM table");
|
|
||||||
*
|
|
||||||
* // read the first row with debugging on
|
|
||||||
* $first_row_only = $db->one("SELECT a,b,c FROM table WHERE a=1", TRUE);
|
|
||||||
*
|
|
||||||
* // emulate the usual MySQL way of reading query results
|
|
||||||
* if ($db->q("SELECT a,b,c FROM table")) {
|
|
||||||
* while ( $row = $db->farr() ) {
|
|
||||||
* print $row['a'].$row['b'].$row['c'];
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* // show a log of all queries, sorted by execution time
|
|
||||||
* $db->show_log(TRUE);
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* @filesource
|
|
||||||
* @author Michal Tatarynowicz <tatarynowicz@gmail.com>
|
|
||||||
* @author Larry E. Masters aka PhpNut <nut@phpnut.com>
|
|
||||||
* @author Kamil Dzielinski aka Brego <brego.dk@gmail.com>
|
|
||||||
* @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('adodb/adodb.inc.php');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.libs
|
|
||||||
* @since Cake v 0.2.9
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class DBO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @var unknown_type
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $connected=FALSE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @var unknown_type
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $error=NULL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @var unknown_type
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $insert_id=NULL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @var unknown_type
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $affected=NULL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @var unknown_type
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $took=NULL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @var unknown_type
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
var $_conn=NULL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @var unknown_type
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
var $_result=NULL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @var unknown_type
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
var $_queries_cnt=0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @var unknown_type
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
var $_queries_time=NULL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @var unknown_type
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
var $_queries_log=array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @var unknown_type
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
var $_adodb=NULL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $config
|
|
||||||
* @param unknown_type $DEBUG
|
|
||||||
* @return DBO
|
|
||||||
*/
|
|
||||||
function DBO($config=NULL,$DEBUG=FALSE) {
|
|
||||||
$this->__constructor($config,$DEBUG);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $config
|
|
||||||
* @param unknown_type $DEBUG
|
|
||||||
*/
|
|
||||||
function __constructor($config=NULL,$DEBUG=FALSE) {
|
|
||||||
$this->debug = $DEBUG;
|
|
||||||
if ($DEBUG > 1) register_shutdown_function( array( &$this, "show_log" ) );
|
|
||||||
$this->connect($config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function __destructor() {
|
|
||||||
$this->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $config
|
|
||||||
*/
|
|
||||||
function connect($config) {
|
|
||||||
if($config) {
|
|
||||||
$this->config = $config;
|
|
||||||
if(isset($this->config['type'])) {
|
|
||||||
$this->_adodb = NewADOConnection($this->config['type']);
|
|
||||||
$adodb =& $this->_adodb;
|
|
||||||
$this->connected = $adodb->Connect($this->config['host'],$this->config['login'],$this->config['password'],$this->config['database']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$this->connected)
|
|
||||||
die('Could not connect to DB.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function close() {
|
|
||||||
$adodb =& $this->_adodb;
|
|
||||||
$adodb->close;
|
|
||||||
showLog();
|
|
||||||
$this->_conn = NULL;
|
|
||||||
$this->connected = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $q
|
|
||||||
* @param unknown_type $DEBUG
|
|
||||||
* @param unknown_type $log
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function q($q,$DEBUG=FALSE,$log=TRUE) {
|
|
||||||
Return $this->query($q,$DEBUG,$log);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $q
|
|
||||||
* @param unknown_type $DEBUG
|
|
||||||
* @param unknown_type $log
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function query($q,$DEBUG=FALSE,$log=TRUE) {
|
|
||||||
$adodb =& $this->_adodb;
|
|
||||||
$t = getMicrotime();
|
|
||||||
|
|
||||||
if($log){
|
|
||||||
$this->_result =& $adodb->Execute($q);
|
|
||||||
$result =& $this->_result;
|
|
||||||
$this->took = round((getmicrotime()-$t)*1000, 0);
|
|
||||||
if(!$this->_result && $adodb->ErrorMsg())
|
|
||||||
$this->error = $adodb->ErrorMsg();
|
|
||||||
else
|
|
||||||
$this->error = NULL;
|
|
||||||
|
|
||||||
$this->insert_id = $adodb->Insert_ID();
|
|
||||||
|
|
||||||
$this->affected = $adodb->Affected_Rows();
|
|
||||||
|
|
||||||
$this->num_rows = $result->RecordCount();
|
|
||||||
$this->_log_query($q);
|
|
||||||
|
|
||||||
if($this->debug || $DEBUG) $this->_show_query($q);
|
|
||||||
|
|
||||||
Return $this->error? FALSE: $this->_result;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$this->_result = $adodb->Execute($q);
|
|
||||||
Return $this->_result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function farr() {
|
|
||||||
$result =& $this->_result;
|
|
||||||
return $result->FetchRow();
|
|
||||||
}
|
|
||||||
|
|
||||||
//SAME AS ABOVE?
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $q
|
|
||||||
* @param unknown_type $DEBUG
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function one($q,$DEBUG=FALSE) {
|
|
||||||
$result =& $this->_result;
|
|
||||||
Return $this->query($q,$DEBUG)? $result->FetchRow(): FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $q
|
|
||||||
* @param unknown_type $DEBUG
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function all($q,$DEBUG=FALSE) {
|
|
||||||
if($this->query($q,$DEBUG)) {
|
|
||||||
$result = $this->_result;
|
|
||||||
return $result->GetRows();
|
|
||||||
} else {
|
|
||||||
Return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $name
|
|
||||||
* @param unknown_type $q
|
|
||||||
* @param unknown_type $DEBUG
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function field($name, $q, $DEBUG=FALSE) {
|
|
||||||
$data = $this->one($q, $DEBUG);
|
|
||||||
return empty($data[$name])? false: $data[$name];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function tables() {
|
|
||||||
$adodb =& $this->_adodb;
|
|
||||||
$tables = $adodb->MetaTables('TABLES');
|
|
||||||
|
|
||||||
if (!sizeof($tables)>0) {
|
|
||||||
trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
return $tables;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $table
|
|
||||||
* @param unknown_type $sql
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function has_any($table, $sql) {
|
|
||||||
$out = $this->one("SELECT COUNT(*) AS count FROM {$table} WHERE {$sql}");
|
|
||||||
return is_array($out)? $out['count']: FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function got_connected() {
|
|
||||||
Return $this->connected;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function got_insert_id() {
|
|
||||||
Return $this->insert_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function got_affected() {
|
|
||||||
Return $this->affected;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function got_num_rows() {
|
|
||||||
Return $this->num_rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function got_error() {
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $sorted
|
|
||||||
*/
|
|
||||||
function show_log($sorted=FALSE) {
|
|
||||||
$log = $sorted?
|
|
||||||
sortByKey($this->_queries_log, 'took', 'desc', SORT_NUMERIC):
|
|
||||||
$this->_queries_log;
|
|
||||||
|
|
||||||
print("<table border=1>\n<tr><th colspan=7>{$this->_queries_cnt} queries took {$this->_queries_time} ms</th></tr>\n");
|
|
||||||
print("<tr><td>Nr</td><td>Query</td><td>Error</td><td>Affected</td><td>Num. rows</td><td>Took (ms)</td></tr>\n");
|
|
||||||
|
|
||||||
foreach($log AS $k=>$i) {
|
|
||||||
print("<tr><td>".($k+1)."</td><td>{$i['query']}</td><td>{$i['error']}</td><td align='right'>{$i['affected']}</td><td align='right'>{$i['num_rows']}</td><td align='right'>{$i['took']}</td></tr>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
print("</table>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $q
|
|
||||||
*/
|
|
||||||
function _log_query($q) {
|
|
||||||
$this->_queries_cnt++;
|
|
||||||
$this->_queries_time += $this->took;
|
|
||||||
$this->_queries_log[] = array(
|
|
||||||
'query'=>$q,
|
|
||||||
'error'=>$this->error,
|
|
||||||
'affected'=>$this->affected,
|
|
||||||
'num_rows'=>$this->num_rows,
|
|
||||||
'took'=>$this->took
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
if ($this->error && function_exists('logError'))
|
|
||||||
logError("Query: {$q} RETURNS ERROR {$this->error}");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $q
|
|
||||||
*/
|
|
||||||
function _show_query($q) {
|
|
||||||
$error = $this->error;
|
|
||||||
|
|
||||||
if ($this->debug || $error) {
|
|
||||||
print("<p style=\"text-align:left\"><b>Query:</b> {$q} <small>[Aff:{$this->affected} Num:{$this->num_rows} Took:{$this->took}ms]</small>");
|
|
||||||
if($error) {
|
|
||||||
print("<br /><span style=\"color:Red;text-align:left\"><b>ERROR:</b> {$this->error}</span>");
|
|
||||||
}
|
|
||||||
print('</p>');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('getMicrotime')) {
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function getMicrotime() {
|
|
||||||
list($usec, $sec) = explode(" ", microtime());
|
|
||||||
return ((float)$usec + (float)$sec);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!function_exists('sortByKey')) {
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $array
|
|
||||||
* @param unknown_type $sortby
|
|
||||||
* @param unknown_type $order
|
|
||||||
* @param unknown_type $type
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function sortByKey(&$array, $sortby, $order='asc', $type=SORT_NUMERIC) {
|
|
||||||
|
|
||||||
if( is_array($array) ) {
|
|
||||||
|
|
||||||
foreach( $array AS $key => $val )
|
|
||||||
$sa[$key] = $val[$sortby];
|
|
||||||
|
|
||||||
if( $order == 'asc' )
|
|
||||||
asort($sa, $type);
|
|
||||||
else
|
|
||||||
arsort($sa, $type);
|
|
||||||
|
|
||||||
foreach( $sa as $key=>$val )
|
|
||||||
$out[] = $array[$key];
|
|
||||||
|
|
||||||
Return $out;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
377
libs/dbo.php
377
libs/dbo.php
|
@ -29,30 +29,30 @@
|
||||||
* Example usage:
|
* Example usage:
|
||||||
*
|
*
|
||||||
* <code>
|
* <code>
|
||||||
* require('dbo.php');
|
require('dbo_mysql.php'); // or 'dbo_postgres.php'
|
||||||
*
|
|
||||||
* // create and connect the object
|
// create and connect the object
|
||||||
* $db = new DBO(array(
|
$db = new DBO_MySQL(array( // or 'DBO_Postgres'
|
||||||
* 'host'=>'localhost',
|
'host'=>'localhost',
|
||||||
* 'login'=>'username',
|
'login'=>'username',
|
||||||
* 'password'=>'password',
|
'password'=>'password',
|
||||||
* 'database'=>'database'));
|
'database'=>'database'));
|
||||||
*
|
|
||||||
* // read the whole query result array (of rows)
|
// read the whole query result array (of rows)
|
||||||
* $all_rows = $db->all("SELECT a,b,c FROM table");
|
$all_rows = $db->all("SELECT a,b,c FROM table");
|
||||||
*
|
|
||||||
* // read the first row with debugging on
|
// read the first row with debugging on
|
||||||
* $first_row_only = $db->one("SELECT a,b,c FROM table WHERE a=1", TRUE);
|
$first_row_only = $db->one("SELECT a,b,c FROM table WHERE a=1", TRUE);
|
||||||
*
|
|
||||||
* // emulate the usual MySQL way of reading query results
|
// emulate the usual way of reading query results
|
||||||
* if ($db->q("SELECT a,b,c FROM table")) {
|
if ($db->query("SELECT a,b,c FROM table")) {
|
||||||
* while ( $row = $db->farr() ) {
|
while ( $row = $db->farr() ) {
|
||||||
* print $row['a'].$row['b'].$row['c'];
|
print $row['a'].$row['b'].$row['c'];
|
||||||
* }
|
}
|
||||||
* }
|
}
|
||||||
*
|
|
||||||
* // show a log of all queries, sorted by execution time
|
// show a log of all queries, sorted by execution time
|
||||||
* $db->show_log(TRUE);
|
$db->showLog(TRUE);
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
|
@ -94,7 +94,7 @@ class DBO extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $connected=FALSE;
|
var $connected=FALSE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -102,7 +102,7 @@ class DBO extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $debug=FALSE;
|
var $debug=FALSE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -110,7 +110,7 @@ class DBO extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $error=NULL;
|
var $error=NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -118,7 +118,7 @@ class DBO extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $insert_id=NULL;
|
var $affected=NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -126,7 +126,7 @@ class DBO extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $affected=NULL;
|
var $numRows=NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -134,7 +134,7 @@ class DBO extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $took=NULL;
|
var $took=NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -158,7 +158,7 @@ class DBO extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $_queries_cnt=0;
|
var $_queriesCnt=0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -166,7 +166,7 @@ class DBO extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $_queries_time=NULL;
|
var $_queriesTime=NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -174,7 +174,20 @@ class DBO extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $_queries_log=array();
|
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...
|
* Enter description here...
|
||||||
|
@ -183,12 +196,11 @@ class DBO extends Object {
|
||||||
* @param unknown_type $DEBUG
|
* @param unknown_type $DEBUG
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function __construct($config=NULL,$DEBUG=FALSE) {
|
function __construct ($config=NULL) {
|
||||||
$this->debug = $DEBUG;
|
$this->debug = DEBUG > 1;
|
||||||
if ($DEBUG > 1) register_shutdown_function( array( &$this, "show_log" ) );
|
parent::__construct();
|
||||||
parent::__construct();
|
return $this->connect($config);
|
||||||
Return $this->connect($config);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -198,87 +210,56 @@ class DBO extends Object {
|
||||||
$this->close();
|
$this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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->_conn = @mysql_connect($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...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $db_name
|
* @param unknown_type $db_name
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function use_db ($db_name) {
|
function useDb ($db_name) {
|
||||||
return $this->q("USE {$db_name}");
|
return $this->query("USE {$db_name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function close() {
|
function close () {
|
||||||
@mysql_close();
|
if ($this->debug) $this->showLog();
|
||||||
showLog();
|
$this->disconnect();
|
||||||
$this->_conn = NULL;
|
$this->_conn = NULL;
|
||||||
$this->connected = NULL;
|
$this->connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $q
|
* @param unknown_type $sql
|
||||||
* @param unknown_type $DEBUG
|
|
||||||
* @param unknown_type $log
|
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function q($q,$DEBUG=FALSE,$log=TRUE) {
|
function rawQuery ($sql) {
|
||||||
Return $this->query($q,$DEBUG,$log);
|
$this->took = $this->error = $this->numRows = false;
|
||||||
}
|
return $this->execute($sql);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $q
|
* @param unknown_type $sql
|
||||||
* @param unknown_type $DEBUG
|
|
||||||
* @param unknown_type $log
|
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function query($q,$DEBUG=FALSE,$log=TRUE) {
|
function query($sql) {
|
||||||
$t = getMicrotime();
|
$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->showQuery($sql);
|
||||||
|
|
||||||
if($log){
|
return $this->error? false: $this->_result;
|
||||||
$this->_result = @mysql_query($q);
|
}
|
||||||
$this->took = round((getmicrotime()-$t)*1000, 0);
|
|
||||||
$this->error = mysql_errno()? mysql_errno().': '.mysql_error(): NULL;
|
|
||||||
$this->insert_id = @mysql_insert_id();
|
|
||||||
$this->affected = @mysql_affected_rows();
|
|
||||||
$this->num_rows = @mysql_num_rows($this->_result);
|
|
||||||
$this->_log_query($q);
|
|
||||||
|
|
||||||
if($this->debug || $DEBUG) $this->_show_query($q);
|
|
||||||
|
|
||||||
Return $this->error? FALSE: $this->_result;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Return @mysql_query($q);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -287,86 +268,48 @@ class DBO extends Object {
|
||||||
* @param unknown_type $type
|
* @param unknown_type $type
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function farr($results,$type=MYSQL_BOTH) {
|
function farr ($res=false) {
|
||||||
return mysql_fetch_array($results,$type);
|
return $this->fetchRow($res? $res: $this->_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $q
|
* @param unknown_type $sql
|
||||||
* @param unknown_type $DEBUG
|
|
||||||
* @param unknown_type $type
|
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function one($q,$DEBUG=FALSE,$type=MYSQL_BOTH) {
|
function one ($sql) {
|
||||||
Return $this->query($q,$DEBUG)? mysql_fetch_array($this->_result, $type): FALSE;
|
return $this->query($sql)? $this->farr(): false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $q
|
* @param unknown_type $sql
|
||||||
* @param unknown_type $DEBUG
|
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function all($q,$DEBUG=FALSE) {
|
function all ($sql) {
|
||||||
if($this->query($q,$DEBUG)) {
|
if($this->query($sql)) {
|
||||||
$out=NULL;
|
$out=array();
|
||||||
while($item = mysql_fetch_assoc($this->_result))
|
while($item = $this->farr()) $out[] = $item;
|
||||||
$out[] = $item;
|
return $out;
|
||||||
|
}
|
||||||
Return $out;
|
else {
|
||||||
}
|
return false;
|
||||||
else {
|
}
|
||||||
Return FALSE;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $name
|
* @param unknown_type $name
|
||||||
* @param unknown_type $q
|
* @param unknown_type $sql
|
||||||
* @param unknown_type $DEBUG
|
|
||||||
* @param unknown_type $type
|
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function field($name, $q, $DEBUG=FALSE, $type=MYSQL_BOTH) {
|
function field ($name, $sql) {
|
||||||
$data = $this->one($q, $DEBUG, $type);
|
$data = $this->one($sql);
|
||||||
return empty($data[$name])? false: $data[$name];
|
return empty($data[$name])? false: $data[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
return $this->all("DESC {$table_name}");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -375,114 +318,76 @@ class DBO extends Object {
|
||||||
* @param unknown_type $sql
|
* @param unknown_type $sql
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function has_any($table, $sql='1=1') {
|
function hasAny($table, $sql) {
|
||||||
$out = $this->one("SELECT COUNT(*) AS count FROM {$table} WHERE {$sql}");
|
$out = $this->one("SELECT COUNT(*) AS count FROM {$table}".($sql? " WHERE {$sql}":""));
|
||||||
return is_array($out)? $out['count']: FALSE;
|
return is_array($out)? $out['count']: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function is_connected() {
|
function isConnected() {
|
||||||
Return $this->connected;
|
return $this->connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function last_insert_id() {
|
|
||||||
Return $this->insert_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function last_affected() {
|
|
||||||
Return $this->affected;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function last_num_rows() {
|
|
||||||
Return $this->num_rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function last_error() {
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $sorted
|
* @param unknown_type $sorted
|
||||||
*/
|
*/
|
||||||
function show_log($sorted=FALSE) {
|
function showLog($sorted=false) {
|
||||||
$log = $sorted?
|
$log = $sorted?
|
||||||
sortByKey($this->_queries_log, 'took', 'desc', SORT_NUMERIC):
|
sortByKey($this->_queriesLog, 'took', 'desc', SORT_NUMERIC):
|
||||||
$this->_queries_log;
|
$this->_queriesLog;
|
||||||
|
|
||||||
print("<table border=1>\n<tr><th colspan=7>{$this->_queries_cnt} queries took {$this->_queries_time} ms</th></tr>\n");
|
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");
|
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) {
|
foreach($log AS $k=>$i) {
|
||||||
print("<tr><td>".($k+1)."</td><td>{$i['query']}</td><td>{$i['error']}</td><td align='right'>{$i['affected']}</td><td align='right'>{$i['num_rows']}</td><td align='right'>{$i['took']}</td></tr>\n");
|
print("<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");
|
print("</table>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $q
|
* @param unknown_type $q
|
||||||
*/
|
*/
|
||||||
function _log_query($q) {
|
function logQuery($sql) {
|
||||||
$this->_queries_cnt++;
|
$this->_queriesCnt++;
|
||||||
$this->_queries_time += $this->took;
|
$this->_queriesTime += $this->took;
|
||||||
$this->_queries_log[] = array(
|
$this->_queriesLog[] = array(
|
||||||
'query'=>$q,
|
'query'=>$sql,
|
||||||
'error'=>$this->error,
|
'error'=>$this->error,
|
||||||
'affected'=>$this->affected,
|
'affected'=>$this->affected,
|
||||||
'num_rows'=>$this->num_rows,
|
'numRows'=>$this->numRows,
|
||||||
'took'=>$this->took
|
'took'=>$this->took
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($this->error)
|
||||||
if ($this->error && function_exists('logError'))
|
false; // shouldn't we be logging errors somehow?
|
||||||
logError("Query: {$q} RETURNS ERROR {$this->error}");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $q
|
* @param unknown_type $q
|
||||||
*/
|
*/
|
||||||
function _show_query($q) {
|
function showQuery($sql) {
|
||||||
$error = $this->error;
|
$error = $this->error;
|
||||||
|
|
||||||
if ($this->debug || $error) {
|
|
||||||
print("<p style=\"text-align:left\"><b>Query:</b> {$q} <small>[Aff:{$this->affected} Num:{$this->num_rows} Took:{$this->took}ms]</small>");
|
|
||||||
if($error) {
|
|
||||||
print("<br /><span style=\"color:Red;text-align:left\"><b>ERROR:</b> {$this->error}</span>");
|
|
||||||
}
|
|
||||||
print('</p>');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ($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>');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
235
libs/dbo_adodb.php
Normal file
235
libs/dbo_adodb.php
Normal file
|
@ -0,0 +1,235 @@
|
||||||
|
<?PHP
|
||||||
|
/*
|
||||||
|
* Name: DBO/ADO
|
||||||
|
* Author: Michal Tatarynowicz (tatarynowicz@gmail.com), Giovanni Degani
|
||||||
|
* Licence: Public Domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once(VENDORS.'adodb/adodb.inc.php');
|
||||||
|
|
||||||
|
class DBO_AdoDB extends DBO {
|
||||||
|
|
||||||
|
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.');
|
||||||
|
}
|
||||||
|
|
||||||
|
function disconnect () {
|
||||||
|
return $this->_adodb->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function execute ($sql) {
|
||||||
|
return $this->_adodb->execute($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchRow ($res) {
|
||||||
|
return $res->FetchRow();
|
||||||
|
}
|
||||||
|
|
||||||
|
function tables() {
|
||||||
|
$tables = $this->_adodb->MetaTables('TABLES');
|
||||||
|
|
||||||
|
if (!sizeof($tables)>0) {
|
||||||
|
trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
return $tables;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepare ($data) { die('Please implement DBO::prepare() first.'); }
|
||||||
|
|
||||||
|
function lastError () {
|
||||||
|
return $this->_adodb->ErrorMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
function lastAffected () {
|
||||||
|
return $this->_adodb->Affected_Rows();
|
||||||
|
}
|
||||||
|
|
||||||
|
function lastNumRows () {
|
||||||
|
return $this->_result? $this->_result->RecordCount(): false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lastInsertId () { die('Please implement DBO::lastInsertId() first.'); }
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
function connect($config) {
|
||||||
|
if($config) {
|
||||||
|
$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.');
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
$adodb =& $this->_adodb;
|
||||||
|
$adodb->close;
|
||||||
|
showLog();
|
||||||
|
$this->_conn = NULL;
|
||||||
|
$this->connected = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
function query($q,$DEBUG=FALSE,$log=TRUE) {
|
||||||
|
$adodb =& $this->_adodb;
|
||||||
|
$t = getMicrotime();
|
||||||
|
|
||||||
|
if($log){
|
||||||
|
$this->_result =& $adodb->Execute($q);
|
||||||
|
$result =& $this->_result;
|
||||||
|
$this->took = round((getmicrotime()-$t)*1000, 0);
|
||||||
|
if(!$this->_result && $adodb->ErrorMsg())
|
||||||
|
$this->error = $adodb->ErrorMsg();
|
||||||
|
else
|
||||||
|
$this->error = NULL;
|
||||||
|
|
||||||
|
$this->insert_id = $adodb->Insert_ID();
|
||||||
|
|
||||||
|
$this->affected = $adodb->Affected_Rows();
|
||||||
|
|
||||||
|
$this->num_rows = $result->RecordCount();
|
||||||
|
$this->_logQuery($q);
|
||||||
|
|
||||||
|
if($this->debug || $DEBUG) $this->_showQuery($q);
|
||||||
|
|
||||||
|
Return $this->error? FALSE: $this->_result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->_result = $adodb->Execute($q);
|
||||||
|
Return $this->_result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function farr() {
|
||||||
|
$result =& $this->_result;
|
||||||
|
return $result->FetchRow();
|
||||||
|
}
|
||||||
|
|
||||||
|
//SAME AS ABOVE?
|
||||||
|
function one($q,$DEBUG=FALSE) {
|
||||||
|
$result =& $this->_result;
|
||||||
|
Return $this->query($q,$DEBUG)? $result->FetchRow(): FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
function all($q,$DEBUG=FALSE) {
|
||||||
|
if($this->query($q,$DEBUG)) {
|
||||||
|
$result = $this->_result;
|
||||||
|
return $result->GetRows();
|
||||||
|
} else {
|
||||||
|
Return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function field($name, $q, $DEBUG=FALSE) {
|
||||||
|
$data = $this->one($q, $DEBUG);
|
||||||
|
return empty($data[$name])? false: $data[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
function tables() {
|
||||||
|
$adodb =& $this->_adodb;
|
||||||
|
$tables = $adodb->MetaTables('TABLES');
|
||||||
|
|
||||||
|
if (!sizeof($tables)>0) {
|
||||||
|
trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
return $tables;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fields ($table_name) {
|
||||||
|
return $this->all("DESC {$table_name}");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function hasAny($table, $sql) {
|
||||||
|
$out = $this->one("SELECT COUNT(*) AS count FROM {$table}".($sql? " WHERE {$sql}":""));
|
||||||
|
return is_array($out)? $out['count']: FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isConnected() {
|
||||||
|
Return $this->connected;
|
||||||
|
}
|
||||||
|
function lastInsertId() {
|
||||||
|
Return $this->insert_id;
|
||||||
|
}
|
||||||
|
function lastAffected() {
|
||||||
|
Return $this->affected;
|
||||||
|
}
|
||||||
|
function lastNumRows() {
|
||||||
|
Return $this->num_rows;
|
||||||
|
}
|
||||||
|
function lastError() {
|
||||||
|
return $this->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showLog($sorted=FALSE) {
|
||||||
|
$log = $sorted?
|
||||||
|
sortByKey($this->_queries_log, 'took', 'desc', SORT_NUMERIC):
|
||||||
|
$this->_queries_log;
|
||||||
|
|
||||||
|
print("<table border=1>\n<tr><th colspan=7>{$this->_queries_cnt} queries took {$this->_queries_time} ms</th></tr>\n");
|
||||||
|
print("<tr><td>Nr</td><td>Query</td><td>Error</td><td>Affected</td><td>Num. rows</td><td>Took (ms)</td></tr>\n");
|
||||||
|
|
||||||
|
foreach($log AS $k=>$i) {
|
||||||
|
print("<tr><td>".($k+1)."</td><td>{$i['query']}</td><td>{$i['error']}</td><td align='right'>{$i['affected']}</td><td align='right'>{$i['num_rows']}</td><td align='right'>{$i['took']}</td></tr>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
print("</table>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function _logQuery($q) {
|
||||||
|
$this->_queries_cnt++;
|
||||||
|
$this->_queries_time += $this->took;
|
||||||
|
$this->_queries_log[] = array(
|
||||||
|
'query'=>$q,
|
||||||
|
'error'=>$this->error,
|
||||||
|
'affected'=>$this->affected,
|
||||||
|
'num_rows'=>$this->num_rows,
|
||||||
|
'took'=>$this->took
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if ($this->error && function_exists('logError'))
|
||||||
|
logError("Query: {$q} RETURNS ERROR {$this->error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
function _showQuery($q) {
|
||||||
|
$error = $this->error;
|
||||||
|
|
||||||
|
if ($this->debug || $error) {
|
||||||
|
print("<p style=\"text-align:left\"><b>Query:</b> {$q} <small>[Aff:{$this->affected} Num:{$this->num_rows} Took:{$this->took}ms]</small>");
|
||||||
|
if($error) {
|
||||||
|
print("<br /><span style=\"color:Red;text-align:left\"><b>ERROR:</b> {$this->error}</span>");
|
||||||
|
}
|
||||||
|
print('</p>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
85
libs/dbo_mysql.php
Normal file
85
libs/dbo_mysql.php
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
<?PHP
|
||||||
|
/*
|
||||||
|
* Name: DBO/MySQL
|
||||||
|
* Author: Michal Tatarynowicz (tatarynowicz@gmail.com)
|
||||||
|
* Licence: Public Domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
uses('object', 'dbo');
|
||||||
|
|
||||||
|
class DBO_MySQL extends DBO {
|
||||||
|
|
||||||
|
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.');
|
||||||
|
}
|
||||||
|
|
||||||
|
function disconnect () {
|
||||||
|
return mysql_close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function execute ($sql) {
|
||||||
|
return mysql_query($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchRow ($res) {
|
||||||
|
return mysql_fetch_array($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepare ($data) {
|
||||||
|
return "'".str_replace("'", "\\'", $data)."'";
|
||||||
|
}
|
||||||
|
|
||||||
|
function lastError () {
|
||||||
|
return mysql_errno()? mysql_errno().': '.mysql_error(): null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lastAffected () {
|
||||||
|
return $this->_result? mysql_affected_rows(): false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lastNumRows () {
|
||||||
|
return $this->_result? @mysql_num_rows($this->_result): false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lastInsertId() {
|
||||||
|
Return mysql_insert_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
95
libs/dbo_postgres.php
Normal file
95
libs/dbo_postgres.php
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<?PHP
|
||||||
|
/*
|
||||||
|
* Name: DBO/PostgreSQL
|
||||||
|
* Author: Michal Tatarynowicz (tatarynowicz@gmail.com)
|
||||||
|
* Licence: Public Domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
uses('object', 'dbo');
|
||||||
|
|
||||||
|
class DBO_Postgres extends DBO {
|
||||||
|
|
||||||
|
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.');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function disconnect () {
|
||||||
|
return pg_close($this->_conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
function execute ($sql) {
|
||||||
|
return pg_query($this->_conn, $sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchRow ($res) {
|
||||||
|
return pg_fetch_array($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepare ($data) {
|
||||||
|
return "'".str_replace('"', '\"', str_replace('$', '$', $data))."'";
|
||||||
|
}
|
||||||
|
|
||||||
|
function lastError () {
|
||||||
|
return pg_last_error()? pg_last_error(): null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lastAffected () {
|
||||||
|
return $this->_result? pg_affected_rows($this->_result): false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lastNumRows () {
|
||||||
|
return $this->_result? pg_num_rows($this->_result): false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lastInsertId ($table, $field='id') {
|
||||||
|
$sql = "SELECT CURRVAL('{$table}_{$field}_seq') AS max";
|
||||||
|
$res = $this->rawQuery($sql);
|
||||||
|
$data = $this->fetchRow($res);
|
||||||
|
return $data['max'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -40,9 +40,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Description:
|
||||||
*
|
* Dispatches the request, creating aproppriate models and controllers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uses('error_messages', 'object', 'router', 'cache', 'controller');
|
uses('error_messages', 'object', 'router', 'cache', 'controller');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,21 +61,21 @@ class Dispatcher extends Object {
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $base = false;
|
var $base = false;
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $passed_args = array();
|
var $passed_args = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function __construct () {
|
function __construct () {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -82,72 +83,58 @@ class Dispatcher extends Object {
|
||||||
* @param unknown_type $url
|
* @param unknown_type $url
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function dispatch ($url) {
|
function dispatch ($url) {
|
||||||
global $_POST, $_GET, $_FILES, $_SESSION;
|
global $_POST, $_GET, $_FILES, $_SESSION;
|
||||||
|
|
||||||
if (CACHE_PAGES) {
|
if (CACHE_PAGES) {
|
||||||
$Cache = new Cache($url);
|
$Cache = new Cache($url);
|
||||||
if ($Cache->has()) return print $Cache->restore();
|
if ($Cache->has()) return print $Cache->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->base = $this->parse_base_url();
|
$this->base = $this->parseBaseUrl();
|
||||||
|
$params = $this->parseParams($url);
|
||||||
|
|
||||||
$params = $this->parse_params($url);
|
// if no controller set
|
||||||
|
if (empty($params['controller']))
|
||||||
|
$this->errorNoController($url);
|
||||||
|
|
||||||
if (empty($params['controller'])) {
|
$controller_class = ucfirst($params['controller']).'Controller';
|
||||||
DEBUG?
|
|
||||||
trigger_error (ERROR_NO_CONTROLLER_SET, E_USER_ERROR):
|
|
||||||
$this->error('404', 'Not found', "The requested URL /{$url} was not found on this server (no controller set).");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$controller_class = ucfirst($params['controller']).'Controller';
|
// if specified controller class doesn't exist
|
||||||
|
if (!class_exists($controller_class))
|
||||||
|
$this->errorUnknownController($url, $controller_class);
|
||||||
|
|
||||||
if (!class_exists($controller_class)) {
|
$controller = new $controller_class ($this);
|
||||||
DEBUG?
|
$controller->cache = &$Cache;
|
||||||
trigger_error (sprintf(ERROR_UNKNOWN_CONTROLLER, $controller_class), E_USER_ERROR):
|
$controller->base = $this->base;
|
||||||
$this->error('404', 'Not found', sprintf(ERROR_404, $url, "missing controller \"{$params['controller']}\""));
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$controller = new $controller_class ($this);
|
// if action is not set, and the default Controller::index() method doesn't exist
|
||||||
$controller->cache = &$Cache;
|
if (empty($params['action'])) {
|
||||||
$controller->base = $this->base;
|
if (!method_exists($controller, 'index'))
|
||||||
|
$this->errorNoAction($url);
|
||||||
|
else
|
||||||
|
$params['action'] = 'index';
|
||||||
|
}
|
||||||
|
|
||||||
// if action is not set, and the default Controller::index() method doesn't exist
|
// if the requested action doesn't exist
|
||||||
if (!$params['action'] && !method_exists($controller, 'index')) {
|
if (!method_exists($controller, $params['action']))
|
||||||
DEBUG?
|
$this->errorUnknownAction($url, $controller_class, $params['action']);
|
||||||
trigger_error (ERROR_NO_ACTION_SET, E_USER_ERROR):
|
|
||||||
$this->error('404', 'Not found', "The requested URL /{$url} was not found on this server (no action set).");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
elseif (empty($params['action'])) {
|
|
||||||
$params['action'] = 'index';
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the requested action doesn't exist
|
$controller->params = $params;
|
||||||
if (!method_exists($controller, $params['action'])) {
|
$controller->action = $params['action'];
|
||||||
DEBUG?
|
$controller->data = empty($params['data'])? null: $params['data'];
|
||||||
trigger_error (sprintf(ERROR_NO_ACTION, $params['action'], $controller_class), E_USER_ERROR):
|
$controller->passed_args = empty($params['pass'])? null: $params['pass'];
|
||||||
$this->error('404', 'Not found', sprintf(ERROR_404, $url, "missing controller \"{$params['controller']}\""));
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$controller->params = $params;
|
// EXECUTE THE REQUESTED ACTION
|
||||||
empty($params['data'])? null: $controller->data = $params['data'];
|
call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']);
|
||||||
$controller->action = $params['action'];
|
|
||||||
$controller->passed_args = empty($params['pass'])? null: $params['pass'];
|
|
||||||
|
|
||||||
// EXECUTE THE REQUESTED ACTION
|
if ($controller->auto_render)
|
||||||
call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']);
|
$controller->render();
|
||||||
|
|
||||||
if ($controller->auto_render)
|
if (CACHE_PAGES) $Cache->remember(null);
|
||||||
$controller->render();
|
|
||||||
|
|
||||||
if (CACHE_PAGES) $Cache->remember(null);
|
return $params;
|
||||||
|
}
|
||||||
return $params;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -155,46 +142,47 @@ class Dispatcher extends Object {
|
||||||
* @param unknown_type $from_url
|
* @param unknown_type $from_url
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function parse_params ($from_url) {
|
function parseParams ($from_url) {
|
||||||
global $_POST, $_FILES;
|
global $_POST, $_FILES;
|
||||||
|
|
||||||
// load routes config
|
// load routes config
|
||||||
$Route = new Router();
|
$Route = new Router();
|
||||||
require CONFIGS.'routes.php';
|
require CONFIGS.'routes.php';
|
||||||
$params = $Route->parse ('/'.$from_url);
|
$params = $Route->parse ('/'.$from_url);
|
||||||
|
|
||||||
// add submitted form data
|
// add submitted form data
|
||||||
$params['form'] = $_POST;
|
$params['form'] = $_POST;
|
||||||
if (isset($_POST['data']))
|
if (isset($_POST['data']))
|
||||||
$params['data'] = $_POST['data'];
|
$params['data'] = $_POST['data'];
|
||||||
foreach ($_FILES as $name => $data)
|
|
||||||
$params['form'][$name] = $data;
|
|
||||||
|
|
||||||
return $params;
|
foreach ($_FILES as $name => $data)
|
||||||
}
|
$params['form'][$name] = $data;
|
||||||
|
|
||||||
|
return $params;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function parse_base_url () {
|
function parseBaseUrl () {
|
||||||
global $_SERVER;
|
global $_SERVER;
|
||||||
//non mod_rewrite use:
|
|
||||||
|
//non mod_rewrite use:
|
||||||
if (defined('BASE_URL')) return BASE_URL;
|
if (defined('BASE_URL')) return BASE_URL;
|
||||||
|
|
||||||
|
$doc_root = $_SERVER['DOCUMENT_ROOT'];
|
||||||
|
$script_name = $_SERVER['PHP_SELF'];
|
||||||
|
|
||||||
$doc_root = $_SERVER['DOCUMENT_ROOT'];
|
// if document root ends with 'public', it's probably correctly set
|
||||||
$script_name = $_SERVER['SCRIPT_NAME'];
|
$r = null;
|
||||||
|
if (!ereg('/^.*/public(\/)?$/', $doc_root))
|
||||||
// if document root ends with 'public', it's probably correctly set
|
return preg_match('/^(.*)\/public\/dispatch\.php$/', $script_name, $r)? $r[1]: false;
|
||||||
$r = null;
|
// document root is probably not set to Cake 'public' dir
|
||||||
if (!ereg('/^.*/public(\/)?$/', $doc_root))
|
else
|
||||||
return preg_match('/^(.*)\/public\/dispatch\.php$/', $script_name, $r)? $r[1]: false;
|
return preg_match('/^(.*)\/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...
|
* Enter description here...
|
||||||
|
@ -203,11 +191,72 @@ class Dispatcher extends Object {
|
||||||
* @param unknown_type $name
|
* @param unknown_type $name
|
||||||
* @param unknown_type $message
|
* @param unknown_type $message
|
||||||
*/
|
*/
|
||||||
function error ($code, $name, $message) {
|
function error ($code, $name, $message) {
|
||||||
$controller = new Controller ($this);
|
$controller = new Controller ($this);
|
||||||
$controller->base = $this->base;
|
$controller->base = $this->base;
|
||||||
$controller->error($code, $name, $message);
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -114,7 +114,7 @@ define ('ERROR_CANT_GET_ORIGINAL_IMAGE', '[Image] Couln\'t load original image %
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
define ('ERROR_404', "The requested URL /%s was not found on this server (%s).");
|
define ('ERROR_404', "The requested address /%s was not found on this server."); // second %s contains short error message
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
|
252
libs/flay.php
252
libs/flay.php
|
@ -62,24 +62,24 @@ class Flay extends Object {
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $text = null;
|
var $text = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $allow_html = false;
|
var $allow_html = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $text
|
* @param unknown_type $text
|
||||||
*/
|
*/
|
||||||
function __construct ($text=null) {
|
function __construct ($text=null) {
|
||||||
$this->text = $text;
|
$this->text = $text;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -87,182 +87,98 @@ class Flay extends Object {
|
||||||
* @param unknown_type $text
|
* @param unknown_type $text
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function to_html ($text=null) {
|
function toHtml ($text=null) {
|
||||||
// trim whitespace and disable all HTML
|
$text = $text? $text: $this->text;
|
||||||
$text = str_replace('<', '<', str_replace('>', '>', trim($text? $text: $this->text)));
|
|
||||||
|
|
||||||
// multi-paragraph functions
|
// trim whitespace and disable all HTML
|
||||||
$text = preg_replace('#(?:[\n]{0,2})"""(.*)"""(?:[\n]{0,2})#s', "\n\n%BLOCKQUOTE%\n\n\\1\n\n%ENDBLOCKQUOTE%\n\n", $text);
|
$text = str_replace('<', '<', str_replace('>', '>', trim($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
|
// multi-paragraph functions
|
||||||
$text = preg_replace("#\r\n#", "\n", $text);
|
$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]{2,}#", "%PARAGRAPH%", $text);
|
$text = preg_replace('#(?:[\n]{0,2})===(.*)===(?:[\n]{0,2})#s', "\n\n%CENTER%\n\n\\1\n\n%ENDCENTER%\n\n", $text);
|
||||||
$text = preg_replace('#[\n]{1}#', "%LINEBREAK%", $text);
|
|
||||||
|
|
||||||
// split into paragraphs and parse
|
// pre-parse newlines
|
||||||
$out = '';
|
$text = preg_replace("#\r\n#", "\n", $text);
|
||||||
foreach (split('%PARAGRAPH%', $text) as $line) {
|
$text = preg_replace("#[\n]{2,}#", "%PARAGRAPH%", $text);
|
||||||
|
$text = preg_replace('#[\n]{1}#', "%LINEBREAK%", $text);
|
||||||
|
|
||||||
if ($line) {
|
// split into paragraphs and parse
|
||||||
|
$out = '';
|
||||||
|
foreach (split('%PARAGRAPH%', $text) as $line) {
|
||||||
|
|
||||||
// pre-parse links
|
if ($line) {
|
||||||
$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
|
// pre-parse links
|
||||||
// bold
|
$links = array();
|
||||||
$line = ereg_replace("\*([^\*]*)\*", "<strong>\\1</strong>", $line);
|
$regs = null;
|
||||||
// italic
|
if (preg_match_all('#\[([^\[]{4,})\]#', $line, $regs)) {
|
||||||
$line = ereg_replace("_([^_]*)_", "<em>\\1</em>", $line);
|
foreach ($regs[1] as $reg) {
|
||||||
// entities
|
$links[] = $reg;
|
||||||
$line = str_replace(' - ', ' – ', $line);
|
$line = str_replace("[{$reg}]",'%LINK'.(count($links)-1).'%', $line);
|
||||||
$line = str_replace(' -- ', ' — ', $line);
|
}
|
||||||
$line = str_replace('(C)', '©', $line);
|
}
|
||||||
$line = str_replace('(R)', '®', $line);
|
|
||||||
$line = str_replace('(TM)', '™', $line);
|
|
||||||
|
|
||||||
// guess e-mails
|
// MAIN TEXT FUNCTIONS
|
||||||
$emails = null;
|
// bold
|
||||||
if (preg_match_all("#([_A-Za-z0-9+-+]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#", $line, $emails)) {
|
$line = ereg_replace("\*([^\*]*)\*", "<strong>\\1</strong>", $line);
|
||||||
foreach ($emails[1] as $email) {
|
// italic
|
||||||
$line = str_replace($email, "<a href=\"mailto:{$email}\">{$email}</a>", $line);
|
$line = ereg_replace("_([^_]*)_", "<em>\\1</em>", $line);
|
||||||
}
|
// entities
|
||||||
}
|
$line = str_replace(' - ', ' – ', $line);
|
||||||
// guess links
|
$line = str_replace(' -- ', ' — ', $line);
|
||||||
$urls = null;
|
$line = str_replace('(C)', '©', $line);
|
||||||
if (preg_match_all("#((?:http|https|ftp|nntp)://[^ ]+)#", $line, $urls)) {
|
$line = str_replace('(R)', '®', $line);
|
||||||
foreach ($urls[1] as $url) {
|
$line = str_replace('(TM)', '™', $line);
|
||||||
$line = str_replace($url, "<a href=\"{$url}\">{$url}</a>", $line);
|
|
||||||
}
|
// guess e-mails
|
||||||
}
|
$emails = null;
|
||||||
if (preg_match_all("#(www\.[^ ]+)#", $line, $urls)) {
|
if (preg_match_all("#([_A-Za-z0-9+-+]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#", $line, $emails)) {
|
||||||
foreach ($urls[1] as $url) {
|
foreach ($emails[1] as $email) {
|
||||||
$line = str_replace($url, "<a href=\"{$url}\">{$url}</a>", $line);
|
$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
|
// re-parse links
|
||||||
if (count($links)) {
|
if (count($links)) {
|
||||||
for ($ii=0; $ii<count($links); $ii++) {
|
for ($ii=0; $ii<count($links); $ii++) {
|
||||||
|
|
||||||
if (preg_match('#\.(jpg|jpeg|gif|png)$#', $links[$ii]))
|
if (preg_match('#\.(jpg|jpeg|gif|png)$#', $links[$ii]))
|
||||||
$with = "<img src=\"{$links[$ii]}\" alt=\"\" />";
|
$with = "<img src=\"{$links[$ii]}\" alt=\"\" />";
|
||||||
elseif (preg_match('#^([^\]\ ]+)(?: ([^\]]+))?$#', $links[$ii], $regs))
|
elseif (preg_match('#^([^\]\ ]+)(?: ([^\]]+))?$#', $links[$ii], $regs))
|
||||||
$with = "<a href=\"{$regs[1]}\" target=\"_blank\">".(isset($regs[2])? $regs[2]: $regs[1])."</a>";
|
$with = "<a href=\"{$regs[1]}\" target=\"_blank\">".(isset($regs[2])? $regs[2]: $regs[1])."</a>";
|
||||||
else
|
else
|
||||||
$with = $links[$ii];
|
$with = $links[$ii];
|
||||||
|
|
||||||
$line = str_replace("%LINK{$ii}%", $with, $line);
|
$line = str_replace("%LINK{$ii}%", $with, $line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// re-parse newlines
|
// re-parse newlines
|
||||||
$out .= str_replace('%LINEBREAK%', "<br />\n", "<p>{$line}</p>\n");
|
$out .= str_replace('%LINEBREAK%', "<br />\n", "<p>{$line}</p>\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// re-parse multilines
|
// re-parse multilines
|
||||||
$out = str_replace('<p>%BLOCKQUOTE%</p>', "<blockquote>", $out);
|
$out = str_replace('<p>%BLOCKQUOTE%</p>', "<blockquote>", $out);
|
||||||
$out = str_replace('<p>%ENDBLOCKQUOTE%</p>', "</blockquote>", $out);
|
$out = str_replace('<p>%ENDBLOCKQUOTE%</p>', "</blockquote>", $out);
|
||||||
$out = str_replace('<p>%CENTER%</p>', "<center>", $out);
|
$out = str_replace('<p>%CENTER%</p>', "<center>", $out);
|
||||||
$out = str_replace('<p>%ENDCENTER%</p>', "</center>", $out);
|
$out = str_replace('<p>%ENDCENTER%</p>', "</center>", $out);
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $verbose
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function test ($verbose=false) {
|
|
||||||
$errors = $tests = 0;
|
|
||||||
|
|
||||||
$tests_to_html = array(
|
|
||||||
array(
|
|
||||||
'text'=>"",
|
|
||||||
'html'=>""
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'text'=>"This is a text.",
|
|
||||||
'html'=>"<p>This is a text.</p>\n"
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'text'=>"This is a line.\n\n\nThis is\n another one.\n\n",
|
|
||||||
'html'=>"<p>This is a line.</p>\n<p>This is<br />\n another one.</p>\n"
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'text'=>"This line has *bold*, _italic_, and a _combo *bold* and italic_ texts.",
|
|
||||||
'html'=>"<p>This line has <strong>bold</strong>, <em>italic</em>, and a <em>combo <strong>bold</strong> and italic</em> texts.</p>\n"
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'text'=>"This line has <b>tags</b> which are <br />not allowed.",
|
|
||||||
'html'=>"<p>This line has <b>tags</b> which are <br />not allowed.</p>\n",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'text'=>"[http://sputnik.pl] is a link, but so is [http://sputnik.pl/bla/ this one], and [this is not.",
|
|
||||||
'html'=>"<p><a href=\"http://sputnik.pl\" target=\"_blank\">http://sputnik.pl</a> is a link, but so is <a href=\"http://sputnik.pl/bla/\" target=\"_blank\">this one</a>, and [this is not.</p>\n"
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'text'=>"Why don't we try to insert an image.\n\n[http://sputnik.pl/test.jpg]",
|
|
||||||
'html'=>"<p>Why don't we try to insert an image.</p>\n<p><img src=\"http://sputnik.pl/test.jpg\" alt=\"\" /></p>\n"
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'text'=>"Auto-link my.name+real@my-server.com and example@example.com, should work.",
|
|
||||||
'html'=>"<p>Auto-link <a href=\"mailto:my.name+real@my-server.com\">my.name+real@my-server.com</a> and <a href=\"mailto:example@example.com\">example@example.com</a>, should work.</p>\n"
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'text'=>"\"\"\"This is a blockquote\"\"\"",
|
|
||||||
'html'=>"<blockquote>\n<p>This is a blockquote</p>\n</blockquote>\n"
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'text'=>"How about a blockquote?\"\"\"This is a multiline blockquote.\n\nThis is the second line.\"\"\"\nAnd this is not.",
|
|
||||||
'html'=>"<p>How about a blockquote?</p>\n<blockquote>\n<p>This is a multiline blockquote.</p>\n<p>This is the second line.</p>\n</blockquote>\n<p>And this is not.</p>\n"
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'text'=>"Now auto-link an url such as http://sputnik.pl or www.robocik-malowany.com/dupa[4] - or any other.",
|
|
||||||
'html'=>"<p>Now auto-link an url such as <a href=\"http://sputnik.pl\">http://sputnik.pl</a> or <a href=\"www.robocik-malowany.com/dupa[4]\">www.robocik-malowany.com/dupa[4]</a> – or any other.</p>\n"
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'text'=>"===This be centered===",
|
|
||||||
'html'=>"<center>\n<p>This be centered</p>\n</center>\n"
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'text'=>"===This be centered.\n\nAnd this be centered too,\nalong with this.===\nThis, alas, be not.",
|
|
||||||
'html'=>"<center>\n<p>This be centered.</p>\n<p>And this be centered too,<br />\nalong with this.</p>\n</center>\n<p>This, alas, be not.</p>\n"
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'text'=>"This tests (C)2004 Someone Else, \"Layer Your Apps(R)\" and Cake(TM).",
|
|
||||||
'html'=>"<p>This tests ©2004 Someone Else, \"Layer Your Apps®\" and Cake™.</p>\n"
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($tests_to_html as $test) {
|
|
||||||
$this->text = $test['text'];
|
|
||||||
if ($test['html'] != ($o = $this->to_html())) {
|
|
||||||
debug ("Flay test error:\n Provided: {$test['text']}\n Expected: {$test['html']}\n Received: {$o}", 1);
|
|
||||||
$errors++;
|
|
||||||
}
|
|
||||||
elseif ($verbose) {
|
|
||||||
debug ("Flay test ok:\n Provided: {$test['text']}\n Received: {$o}", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$tests++;
|
|
||||||
}
|
|
||||||
|
|
||||||
debug ("<b>Flay: {$tests} tests, {$errors} errors (".($errors?'FAILED':'PASSED').')</b>');
|
|
||||||
|
|
||||||
return !$errors;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
175
libs/folder.php
175
libs/folder.php
|
@ -61,24 +61,49 @@ class Folder extends Object {
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $path = null;
|
var $path = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $sort = false;
|
var $sort = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $path
|
* @param unknown_type $path
|
||||||
*/
|
*/
|
||||||
function __construct ($path) {
|
function __construct ($path=false) {
|
||||||
$this->path = $path . (preg_match('#\/$#', $path)? '': '/');
|
if (empty($path)) $path = getcwd();
|
||||||
parent::__construct();
|
$this->cd($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function pwd () {
|
||||||
|
return $this->path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $desired_path
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function cd ($desired_path) {
|
||||||
|
$desired_path = realpath($desired_path);
|
||||||
|
$new_path = Folder::isAbsolute($desired_path)?
|
||||||
|
$desired_path:
|
||||||
|
Folder::addPathElement($this->path, $desired_path);
|
||||||
|
|
||||||
|
return is_dir($new_path)? $this->path = $new_path: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -86,29 +111,68 @@ class Folder extends Object {
|
||||||
* @param unknown_type $sort
|
* @param unknown_type $sort
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function ls($sort=true) {
|
function ls($sort=true) {
|
||||||
if ($dir = opendir($this->path)) {
|
if ($dir = opendir($this->path)) {
|
||||||
$dirs = $files = array();
|
$dirs = $files = array();
|
||||||
while (false !== ($n = readdir($dir))) {
|
while (false !== ($n = readdir($dir))) {
|
||||||
if (!preg_match('#^\.+$#', $n)) {
|
if (!preg_match('#^\.+$#', $n)) {
|
||||||
if (is_dir($this->path.$n))
|
if (is_dir($this->addPathElement($this->path, $n)))
|
||||||
$dirs[] = $n;
|
$dirs[] = $n;
|
||||||
else
|
else
|
||||||
$files[] = $n;
|
$files[] = $n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sort || $this->sort) {
|
if ($sort || $this->sort) {
|
||||||
sort($dirs);
|
sort($dirs);
|
||||||
sort($files);
|
sort($files);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array($dirs,$files);
|
return array($dirs,$files);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $pattern
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function findRecursive ($pattern='.*') {
|
||||||
|
$starts_on = $this->path;
|
||||||
|
$out = $this->_findRecursive($pattern);
|
||||||
|
$this->cd($starts_on);
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $pattern
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function _findRecursive ($pattern) {
|
||||||
|
list($dirs, $files) = $this->ls();
|
||||||
|
|
||||||
|
$found = array();
|
||||||
|
foreach ($files as $file) {
|
||||||
|
if (preg_match("/^{$pattern}$/i", $file)) {
|
||||||
|
$found[] = $this->addPathElement($this->path, $file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$start = $this->path;
|
||||||
|
foreach ($dirs as $dir) {
|
||||||
|
$this->cd($this->addPathElement($start, $dir));
|
||||||
|
$found = array_merge($found, $this->findRecursive($pattern));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $found;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -116,11 +180,60 @@ class Folder extends Object {
|
||||||
* @param unknown_type $path
|
* @param unknown_type $path
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function cd ($path) {
|
function isWindowsPath ($path) {
|
||||||
$new_path = preg('#^/#', $path)? $path: $this->path.$path;
|
return preg_match('#^[A-Z]:\\\#i', $path)? true: false;
|
||||||
return is_dir($new_path)? $this->path = $new_path: false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $path
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function isAbsolute ($path) {
|
||||||
|
return preg_match('#^\/#', $path) || preg_match('#^[A-Z]:\\\#i', $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $path
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function isSlashTerm ($path) {
|
||||||
|
return preg_match('#[\\\/]$#', $path)? true: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $path
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function correctSlashFor ($path) {
|
||||||
|
return Folder::isWindowsPath($path)? '\\': '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $path
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function slashTerm ($path) {
|
||||||
|
return $path . (Folder::isSlashTerm($path)? null: Folder::correctSlashFor($path));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $path
|
||||||
|
* @param unknown_type $element
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function addPathElement ($path, $element) {
|
||||||
|
return Folder::slashTerm($path).$element;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -57,15 +57,14 @@ uses('object');
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Inflector extends Object {
|
class Inflector extends Object {
|
||||||
// private
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function __construct () {
|
function __construct () {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -73,29 +72,30 @@ class Inflector extends Object {
|
||||||
* @param unknown_type $word
|
* @param unknown_type $word
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function pluralize ($word) {
|
function pluralize ($word) {
|
||||||
$plural_rules = array(
|
$plural_rules = array(
|
||||||
'/(x|ch|ss|sh)$/' => '\1es', # search, switch, fix, box, process, address
|
'/(x|ch|ss|sh)$/' => '\1es', # search, switch, fix, box, process, address
|
||||||
'/series$/' => '\1series',
|
'/series$/' => '\1series',
|
||||||
'/([^aeiouy]|qu)ies$/' => '\1y',
|
'/([^aeiouy]|qu)ies$/' => '\1y',
|
||||||
'/([^aeiouy]|qu)y$/' => '\1ies', # query, ability, agency
|
'/([^aeiouy]|qu)y$/' => '\1ies', # query, ability, agency
|
||||||
'/(?:([^f])fe|([lr])f)$/' => '\1\2ves', # half, safe, wife
|
'/(?:([^f])fe|([lr])f)$/' => '\1\2ves', # half, safe, wife
|
||||||
'/sis$/' => 'ses', # basis, diagnosis
|
'/sis$/' => 'ses', # basis, diagnosis
|
||||||
'/([ti])um$/' => '\1a', # datum, medium
|
'/([ti])um$/' => '\1a', # datum, medium
|
||||||
'/person$/' => 'people', # person, salesperson
|
'/person$/' => 'people', # person, salesperson
|
||||||
'/man$/' => 'men', # man, woman, spokesman
|
'/man$/' => 'men', # man, woman, spokesman
|
||||||
'/child$/' => 'children', # child
|
'/child$/' => 'children', # child
|
||||||
'/s$/' => 's', # no change (compatibility)
|
'/s$/' => 's', # no change (compatibility)
|
||||||
'/$/' => 's'
|
'/$/' => 's'
|
||||||
);
|
);
|
||||||
foreach ($plural_rules as $rule => $replacement) {
|
|
||||||
if (preg_match($rule, $word)) {
|
|
||||||
return preg_replace($rule, $replacement, $word);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
foreach ($plural_rules as $rule => $replacement) {
|
||||||
}
|
if (preg_match($rule, $word)) {
|
||||||
|
return preg_replace($rule, $replacement, $word);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -103,32 +103,32 @@ class Inflector extends Object {
|
||||||
* @param unknown_type $word
|
* @param unknown_type $word
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function singularize ($word) {
|
function singularize ($word) {
|
||||||
$singular_rules = array(
|
$singular_rules = array(
|
||||||
'/(x|ch|ss)es$/' => '\1',
|
'/(x|ch|ss)es$/' => '\1',
|
||||||
'/movies$/' => 'movie',
|
'/movies$/' => 'movie',
|
||||||
'/series$/' => 'series',
|
'/series$/' => 'series',
|
||||||
'/([^aeiouy]|qu)ies$/' => '\1y',
|
'/([^aeiouy]|qu)ies$/' => '\1y',
|
||||||
'/([lr])ves$/' => '\1f',
|
'/([lr])ves$/' => '\1f',
|
||||||
'/([^f])ves$/' => '\1fe',
|
'/([^f])ves$/' => '\1fe',
|
||||||
'/(analy|ba|diagno|parenthe|progno|synop|the)ses$/' => '\1sis',
|
'/(analy|ba|diagno|parenthe|progno|synop|the)ses$/' => '\1sis',
|
||||||
'/([ti])a$/' => '\1um',
|
'/([ti])a$/' => '\1um',
|
||||||
'/people$/' => 'person',
|
'/people$/' => 'person',
|
||||||
'/men$/' => 'man',
|
'/men$/' => 'man',
|
||||||
'/status$/' => 'status',
|
'/status$/' => 'status',
|
||||||
'/children$/' => 'child',
|
'/children$/' => 'child',
|
||||||
'/news$/' => 'news',
|
'/news$/' => 'news',
|
||||||
'/s$/' => ''
|
'/s$/' => ''
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($singular_rules as $rule => $replacement) {
|
foreach ($singular_rules as $rule => $replacement) {
|
||||||
if (preg_match($rule, $word)) {
|
if (preg_match($rule, $word)) {
|
||||||
return preg_replace($rule, $replacement, $word);
|
return preg_replace($rule, $replacement, $word);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -136,9 +136,9 @@ class Inflector extends Object {
|
||||||
* @param unknown_type $lower_case_and_underscored_word
|
* @param unknown_type $lower_case_and_underscored_word
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function camelize($lower_case_and_underscored_word) {
|
function camelize($lower_case_and_underscored_word) {
|
||||||
return str_replace(" ","",ucwords(str_replace("_"," ",$lower_case_and_underscored_word)));
|
return str_replace(" ","",ucwords(str_replace("_"," ",$lower_case_and_underscored_word)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -146,10 +146,10 @@ class Inflector extends Object {
|
||||||
* @param unknown_type $camel_cased_word
|
* @param unknown_type $camel_cased_word
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function underscore($camel_cased_word) {
|
function underscore($camel_cased_word) {
|
||||||
$camel_cased_word = preg_replace('/([A-Z]+)([A-Z])/','\1_\2',$camel_cased_word);
|
$camel_cased_word = preg_replace('/([A-Z]+)([A-Z])/','\1_\2',$camel_cased_word);
|
||||||
return strtolower(preg_replace('/([a-z])([A-Z])/','\1_\2',$camel_cased_word));
|
return strtolower(preg_replace('/([a-z])([A-Z])/','\1_\2',$camel_cased_word));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -157,9 +157,9 @@ class Inflector extends Object {
|
||||||
* @param unknown_type $lower_case_and_underscored_word
|
* @param unknown_type $lower_case_and_underscored_word
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function humanize($lower_case_and_underscored_word) {
|
function humanize($lower_case_and_underscored_word) {
|
||||||
return ucwords(str_replace("_"," ",$lower_case_and_underscored_word));
|
return ucwords(str_replace("_"," ",$lower_case_and_underscored_word));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -167,9 +167,9 @@ class Inflector extends Object {
|
||||||
* @param unknown_type $class_name
|
* @param unknown_type $class_name
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function tableize($class_name) {
|
function tableize($class_name) {
|
||||||
return Inflector::pluralize(Inflector::underscore($class_name));
|
return Inflector::pluralize(Inflector::underscore($class_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -177,9 +177,9 @@ class Inflector extends Object {
|
||||||
* @param unknown_type $table_name
|
* @param unknown_type $table_name
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function classify($table_name) {
|
function classify($table_name) {
|
||||||
return $this->camelize($this->singularize($table_name));
|
return $this->camelize($this->singularize($table_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -187,77 +187,9 @@ class Inflector extends Object {
|
||||||
* @param unknown_type $class_name
|
* @param unknown_type $class_name
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function foreign_key($class_name) {
|
function foreignKey($class_name) {
|
||||||
return $this->underscore($class_name) . "_id";
|
return $this->underscore($class_name) . "_id";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $verbose
|
|
||||||
*/
|
|
||||||
function test ($verbose=false) {
|
|
||||||
$singulars = array(
|
|
||||||
'search', 'switch', 'fix', 'box', 'process', 'address', 'query', 'ability',
|
|
||||||
'agency', 'half', 'safe', 'wife', 'basis', 'diagnosis', 'datum', 'medium',
|
|
||||||
'person', 'salesperson', 'man', 'woman', 'spokesman', 'child', 'page', 'robot');
|
|
||||||
$plurals = array(
|
|
||||||
'searches', 'switches', 'fixes', 'boxes', 'processes', 'addresses', 'queries', 'abilities',
|
|
||||||
'agencies', 'halves', 'saves', 'wives', 'bases', 'diagnoses', 'data', 'media',
|
|
||||||
'people', 'salespeople', 'men', 'women', 'spokesmen', 'children', 'pages', 'robots');
|
|
||||||
|
|
||||||
$pluralize_errors = 0;
|
|
||||||
$singularize_errors = 0;
|
|
||||||
$tests = 0;
|
|
||||||
foreach (array_combine($singulars, $plurals) as $singular => $plural) {
|
|
||||||
if ($this->pluralize($singular) != $plural) {
|
|
||||||
debug ("Inflector test {$singular} yelded ".$this->pluralize($singular)." (expected {$plural})");
|
|
||||||
$pluralize_errors++;
|
|
||||||
}
|
|
||||||
elseif ($verbose) {
|
|
||||||
debug ("Inflector test ok: {$singular} => {$plural}",1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->singularize($plural) != $singular) {
|
|
||||||
debug ("Inflector test {$plural} yelded ".$this->singularize($plural)." (expected {$singular})");
|
|
||||||
$singularize_errors++;
|
|
||||||
}
|
|
||||||
elseif ($verbose) {
|
|
||||||
debug ("Inflector test ok: {$plural} => {$singular}",1);
|
|
||||||
}
|
|
||||||
$tests++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$errors = $pluralize_errors + $singularize_errors;
|
|
||||||
debug ("<b>Inflector: {$tests} tests, {$errors} errors (".($errors?'FAILED':'PASSED').')</b>');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!function_exists('array_combine')) {
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $a1
|
|
||||||
* @param unknown_type $a2
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function array_combine($a1, $a2) {
|
|
||||||
$a1 = array_values($a1);
|
|
||||||
$a2 = array_values($a2);
|
|
||||||
|
|
||||||
if (count($a1) != count($a2)) return false; // different lenghts
|
|
||||||
if (count($a1) <= 0) return false; // arrays are the same and both are empty
|
|
||||||
|
|
||||||
$output = array();
|
|
||||||
|
|
||||||
for ($i = 0; $i < count($a1); $i++) {
|
|
||||||
$output[$a1[$i]] = $a2[$i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
536
libs/model.php
536
libs/model.php
|
@ -69,7 +69,7 @@ class Model extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $parent = false;
|
var $parent = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -77,7 +77,7 @@ class Model extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $use_table = false;
|
var $use_table = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -85,7 +85,7 @@ class Model extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $id = false;
|
var $id = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -93,23 +93,23 @@ class Model extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $data = array();
|
var $data = array();
|
||||||
// protected
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $table = false;
|
var $table = false;
|
||||||
// private
|
// private
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $_table_info = null;
|
var $_table_info = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -117,7 +117,7 @@ class Model extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $_one_to_many = array();
|
var $_oneToMany = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -125,7 +125,7 @@ class Model extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $_one_to_one = array();
|
var $_oneToOne = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -133,7 +133,7 @@ class Model extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $_has_multiple = array();
|
var $_hasMany = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -142,56 +142,56 @@ class Model extends Object {
|
||||||
* validate with Model::validate()
|
* validate with Model::validate()
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $validate = array();
|
var $validate = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $id
|
* @param unknown_type $id
|
||||||
*/
|
*/
|
||||||
function __construct ($id=false) {
|
function __construct ($id=false) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$this->db = &$DB;
|
$this->db = &$DB;
|
||||||
|
|
||||||
if ($id)
|
if ($id)
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
|
|
||||||
$table_name = $this->use_table? $this->use_table: Inflector::tableize(get_class($this));
|
$table_name = $this->use_table? $this->use_table: Inflector::tableize(get_class($this));
|
||||||
$this->use_table ($table_name);
|
$this->use_table ($table_name);
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->create_links();
|
$this->create_links();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function create_links () {
|
function create_links () {
|
||||||
if (!empty($this->has_many))
|
if (!empty($this->hasMany))
|
||||||
$this->_has_multiple = explode(',', $this->has_many);
|
$this->_hasMany = explode(',', $this->hasMany);
|
||||||
|
|
||||||
foreach ($this->_has_multiple as $model_name) {
|
foreach ($this->_hasMany as $model_name) {
|
||||||
// todo fix strip the model name
|
// todo fix strip the model name
|
||||||
$model_name = Inflector::singularize($model_name);
|
$model_name = Inflector::singularize($model_name);
|
||||||
$this->$model_name = new $model_name();
|
$this->$model_name = new $model_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->relink();
|
$this->relink();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function relink () {
|
function relink () {
|
||||||
foreach ($this->_has_multiple as $model) {
|
foreach ($this->_hasMany as $model) {
|
||||||
$name = Inflector::singularize($model);
|
$name = Inflector::singularize($model);
|
||||||
$this->$name->clear_links();
|
$this->$name->clear_links();
|
||||||
$this->$name->link_many_to_one(get_class($this), $this->id);
|
$this->$name->link_many_to_one(get_class($this), $this->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -199,33 +199,36 @@ class Model extends Object {
|
||||||
* @param unknown_type $model_name
|
* @param unknown_type $model_name
|
||||||
* @param unknown_type $value
|
* @param unknown_type $value
|
||||||
*/
|
*/
|
||||||
function link_many_to_one ($model_name, $value=null) {
|
function link_many_to_one ($model_name, $value=null) {
|
||||||
$table_name = Inflector::tableize($model_name);
|
$table_name = Inflector::tableize($model_name);
|
||||||
$field_name = Inflector::singularize($table_name).'_id';
|
$field_name = Inflector::singularize($table_name).'_id';
|
||||||
$this->_one_to_many[] = array($table_name, $field_name, $value);
|
$this->_one_to_many[] = array($table_name, $field_name, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function clear_links () {
|
function clear_links () {
|
||||||
$this->_one_to_many = array();
|
$this->_one_to_many = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $table_name
|
* @param unknown_type $table_name
|
||||||
*/
|
*/
|
||||||
function use_table ($table_name) {
|
function use_table ($table_name) {
|
||||||
if (!in_array($table_name, $this->db->tables()))
|
if (!in_array($table_name, $this->db->tables())) {
|
||||||
trigger_error (sprintf(ERROR_NO_MODEL_TABLE, get_class($this), $table_name), E_USER_ERROR);
|
trigger_error (sprintf(ERROR_NO_MODEL_TABLE, get_class($this), $table_name), E_USER_ERROR);
|
||||||
else {
|
die();
|
||||||
$this->table = $table_name;
|
}
|
||||||
$this->load_info();
|
else {
|
||||||
}
|
$this->table = $table_name;
|
||||||
}
|
$this->load_info();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -234,20 +237,20 @@ class Model extends Object {
|
||||||
* @param unknown_type $two
|
* @param unknown_type $two
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function set ($one, $two=null) {
|
function set ($one, $two=null) {
|
||||||
$data = is_array($one)? $one: array($one=>$two);
|
$data = is_array($one)? $one: array($one=>$two);
|
||||||
|
|
||||||
foreach ($data as $n => $v) {
|
foreach ($data as $n => $v) {
|
||||||
if (!$this->has_field($n)) {
|
if (!$this->has_field($n)) {
|
||||||
DEBUG?
|
DEBUG?
|
||||||
trigger_error(sprintf(ERROR_NO_FIELD_IN_MODEL_DB, $n, $this->table), E_USER_ERROR):
|
trigger_error(sprintf(ERROR_NO_FIELD_IN_MODEL_DB, $n, $this->table), E_USER_ERROR):
|
||||||
trigger_error('Application error occured, trying to set a field name that doesn\'t exist.', E_USER_WARNING);
|
trigger_error('Application error occured, trying to set a field name that doesn\'t exist.', E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
$n == 'id'? $this->id = $v: $this->data[$n] = $v;
|
$n == 'id'? $this->id = $v: $this->data[$n] = $v;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -255,19 +258,19 @@ class Model extends Object {
|
||||||
*
|
*
|
||||||
* @param unknown_type $id
|
* @param unknown_type $id
|
||||||
*/
|
*/
|
||||||
function set_id ($id) {
|
function set_id ($id) {
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->relink();
|
$this->relink();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function load_info () {
|
function load_info () {
|
||||||
if (empty($this->_table_info))
|
if (empty($this->_table_info))
|
||||||
$this->_table_info = new neatArray($this->db->fields($this->table));
|
$this->_table_info = new neatArray($this->db->fields($this->table));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -275,107 +278,109 @@ class Model extends Object {
|
||||||
* @param unknown_type $name
|
* @param unknown_type $name
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function has_field ($name) {
|
function has_field ($name) {
|
||||||
return $this->_table_info->find_in('Field', $name);
|
return $this->_table_info->findIn('name', $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// returns data from db
|
|
||||||
// requires $this->id
|
|
||||||
// expects coma-separated field list, array of field names, or empty for all fields
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* reads a list of fields from the db
|
||||||
*
|
*
|
||||||
* @param unknown_type $fields
|
* @param string $fields
|
||||||
* @return unknown
|
* @param array $fields
|
||||||
|
* @return array of values
|
||||||
*/
|
*/
|
||||||
function read ($fields=null) {
|
function read ($fields=null) {
|
||||||
return $this->id? $this->find("id = '{$this->id}'", $fields): false;
|
return $this->id? $this->find("id = '{$this->id}'", $fields): false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a field value from db
|
|
||||||
// requires $this->id
|
|
||||||
// requires a field name
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* reads a field from a record
|
||||||
*
|
*
|
||||||
* @param unknown_type $name
|
* @param string $name
|
||||||
* @return unknown
|
* @return field contents
|
||||||
*/
|
*/
|
||||||
function field ($name) {
|
function field ($name) {
|
||||||
if (isset($this->data[$name]))
|
if (isset($this->data[$name]))
|
||||||
return $this->data[$name];
|
return $this->data[$name];
|
||||||
else {
|
else {
|
||||||
if ($this->id && $data = $this->read($name)) {
|
if ($this->id && $data = $this->read($name)) {
|
||||||
return isset($data[$name])? $data[$name]: false;
|
return isset($data[$name])? $data[$name]: false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// saves $this->data to db
|
|
||||||
// if $this->id is set, updates a record, else inserts a records
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* saves model data to the db
|
||||||
*
|
*
|
||||||
* @param unknown_type $data
|
* @param array $data
|
||||||
* @return unknown
|
* @return success
|
||||||
*/
|
*/
|
||||||
function save ($data=null) {
|
function save ($data=null) {
|
||||||
if ($data) $this->set($data);
|
if ($data) $this->set($data);
|
||||||
|
|
||||||
if (!$this->validates())
|
if (!$this->validates())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$lines = array();
|
$fields = $values = array();
|
||||||
foreach ($this->data as $n => $v)
|
foreach ($this->data as $n=>$v) {
|
||||||
$lines[] = "{$n} = '{$v}'";
|
$fields[] = $n;
|
||||||
|
$values[] = $this->db->prepare($v);
|
||||||
|
}
|
||||||
|
|
||||||
// finds if 'created' and 'updated' fields exists and generates sql to handle them
|
if (empty($this->id) && $this->has_field('created')) {
|
||||||
$update_sql = array();
|
$fields[] = 'created';
|
||||||
if ($this->has_field('created') && !$this->id) $update_sql[] = 'created = NOW()';
|
$values[] = date("'Y-m-d H:i:s'");
|
||||||
if ($this->has_field('modified')) $update_sql[] = 'modified = NOW()';
|
}
|
||||||
$update_sql = count($update_sql)? ', '.join(', ', $update_sql): null;
|
if ($this->has_field('modified')) {
|
||||||
|
$fields[] = 'modified';
|
||||||
|
$values[] = 'NOW()';
|
||||||
|
}
|
||||||
|
|
||||||
if (count($lines)) {
|
if(count($fields)){
|
||||||
|
if($this->id){
|
||||||
|
$sql = array();
|
||||||
|
foreach (array_combine($fields, $values) as $field=>$value) {
|
||||||
|
$sql[] = $field.'='.$value;
|
||||||
|
}
|
||||||
|
if($this->db->query("UPDATE {$this->table} SET ".join(',', $sql)." WHERE id = '{$this->id}'") && $this->db->lastAffected()){
|
||||||
|
$this->data = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $this->db->hasAny($this->table, "id = '{$this->id}'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$fields = join(',', $fields);
|
||||||
|
$values = join(',', $values);
|
||||||
|
|
||||||
if ($this->id) {
|
if($this->db->query("INSERT INTO {$this->table} ({$fields}) VALUES ({$values})")) {
|
||||||
if ($this->db->q("UPDATE {$this->table} SET ".join(', ', $lines)."{$update_sql} WHERE id = '{$this->id}'")
|
$this->id = $this->db->lastInsertId($this->table, 'id');
|
||||||
&& $this->db->last_affected()) {
|
return true;
|
||||||
$this->data = false;
|
}
|
||||||
return true;
|
else {
|
||||||
}
|
return false;
|
||||||
else
|
}
|
||||||
return $this->db->has_any($this->table, "id = '{$this->id}'");
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ($this->db->q("INSERT INTO {$this->table} SET ".join(', ', $lines).$update_sql)) {
|
return false;
|
||||||
$this->id = $this->db->last_insert_id();
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// deletes a record from db
|
|
||||||
// requires $this->id
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* deletes a record
|
||||||
*
|
*
|
||||||
* @param unknown_type $id
|
* @param mixed $id
|
||||||
* @return unknown
|
* @return success
|
||||||
*/
|
*/
|
||||||
function remove ($id=null) {
|
function remove ($id=null) {
|
||||||
return $this->del($id);
|
return $this->del($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -383,88 +388,83 @@ class Model extends Object {
|
||||||
* @param unknown_type $id
|
* @param unknown_type $id
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function del ($id=null) {
|
function del ($id=null) {
|
||||||
if ($id) $this->id = $id;
|
if ($id) $this->id = $id;
|
||||||
if ($this->id && $this->db->q("DELETE FROM {$this->table} WHERE id = '{$this->id}'")) {
|
if ($this->id && $this->db->query("DELETE FROM {$this->table} WHERE id = '{$this->id}'")) {
|
||||||
$this->id = false;
|
$this->id = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if record exists in db
|
|
||||||
// requires $this->id
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* checks for existance of a record with set id
|
||||||
*
|
*
|
||||||
* @return unknown
|
* @return true if such record exists
|
||||||
*/
|
*/
|
||||||
function exists () {
|
function exists () {
|
||||||
return $this->id? $this->db->has_any($this->table, "id = '{$this->id}'"): false;
|
return $this->id? $this->db->hasAny($this->table, "id = '{$this->id}'"): false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a row if found, or otherwise null
|
|
||||||
// expects sql conditions, or empty for no conditions
|
|
||||||
// expects coma-separated fields list, array of field names, or empty for all fields
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* reads a single row
|
||||||
*
|
*
|
||||||
* @param unknown_type $conditions
|
* @param string $conditions
|
||||||
* @param unknown_type $fields
|
* @param string $fields
|
||||||
* @return unknown
|
* @return array of fields
|
||||||
*/
|
*/
|
||||||
function find ($conditions = null, $fields = null) {
|
function find ($conditions = null, $fields = null) {
|
||||||
$data = $this->find_all($conditions, $fields, null, 1);
|
$data = $this->findAll($conditions, $fields, null, 1);
|
||||||
return empty($data[0])? false: $data[0];
|
return empty($data[0])? false: $data[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns specified fields from db records matching conditions
|
|
||||||
// expects sql conditions, or empty for no conditions
|
|
||||||
// expects coma-separated fields list, array of field names, or empty for all fields
|
|
||||||
// expects sql order, or empty for default order
|
|
||||||
// expects limit, or empty for no limit
|
|
||||||
// expects page number for offset, or empty for no offset
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* returns specified fields from db records matching conditions
|
||||||
*
|
*
|
||||||
* @param unknown_type $conditions
|
* @param string $conditions
|
||||||
* @param unknown_type $fields
|
* @param string $fields
|
||||||
* @param unknown_type $order
|
* @param string $order
|
||||||
* @param unknown_type $limit
|
* @param int $limit
|
||||||
* @param unknown_type $page
|
* @param int $page
|
||||||
* @return unknown
|
* @return array of records
|
||||||
*/
|
*/
|
||||||
function find_all ($conditions = null, $fields = null, $order = null, $limit = null, $page = null) {
|
function findAll ($conditions = null, $fields = null, $order = null, $limit=50, $page=1) {
|
||||||
if (is_array($fields))
|
if (is_array($fields))
|
||||||
$f = $fields;
|
$f = $fields;
|
||||||
elseif ($fields)
|
elseif ($fields)
|
||||||
$f = array($fields);
|
$f = array($fields);
|
||||||
else
|
else
|
||||||
$f = array('*');
|
$f = array('*');
|
||||||
|
|
||||||
$joins = $whers = array();
|
$condtions = $this->db->prepare($conditions);
|
||||||
|
|
||||||
foreach ($this->_one_to_many as $rule) {
|
$joins = $whers = array();
|
||||||
list($table, $field, $value) = $rule;
|
|
||||||
$joins[] = "LEFT JOIN {$table} ON {$this->table}.{$field} = {$table}.id";
|
|
||||||
$whers[] = "{$this->table}.{$field} = '{$value}'";
|
|
||||||
}
|
|
||||||
|
|
||||||
$joins = count($joins)? join(' ', $joins): null;
|
foreach ($this->_oneToMany as $rule) {
|
||||||
$whers = count($whers)? '('.join(' AND ', $whers).')': null;
|
list($table, $field, $value) = $rule;
|
||||||
$conditions .= ($conditions && $whers? ' AND ': null).$whers;
|
$joins[] = "LEFT JOIN {$table} ON {$this->table}.{$field} = {$table}.id";
|
||||||
|
$whers[] = "{$this->table}.{$field} = '{$value}'";
|
||||||
|
}
|
||||||
|
|
||||||
$data = $this->db->all(
|
$joins = count($joins)? join(' ', $joins): null;
|
||||||
"SELECT "
|
$whers = count($whers)? '('.join(' AND ', $whers).')': null;
|
||||||
.join(', ', $f)
|
$conditions .= ($conditions && $whers? ' AND ': null).$whers;
|
||||||
." FROM {$this->table} {$joins}"
|
|
||||||
.($conditions? " WHERE {$conditions}":null)
|
|
||||||
.($order? " ORDER BY {$order}": null)
|
|
||||||
.($limit? " LIMIT ".($page>0? $limit*($page-1): '0').",{$limit}": null), false, MYSQL_ASSOC);
|
|
||||||
|
|
||||||
return $data;
|
$offset_str = $page > 1? " OFFSET ".$page*$limit: "";
|
||||||
}
|
$limit_str = $limit? " LIMIT {$limit}": "";
|
||||||
|
|
||||||
|
$data = $this->db->all(
|
||||||
|
"SELECT "
|
||||||
|
.join(', ', $f)
|
||||||
|
." FROM {$this->table} {$joins}"
|
||||||
|
.($conditions? " WHERE {$conditions}":null)
|
||||||
|
.($order? " ORDER BY {$order}": null)
|
||||||
|
.$limit_str
|
||||||
|
.$offset_str);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -473,9 +473,9 @@ class Model extends Object {
|
||||||
* @param unknown_type $debug
|
* @param unknown_type $debug
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function find_by_sql ($sql, $debug=0) {
|
function findBySql ($sql, $debug=0) {
|
||||||
return $this->db->all($sql, $debug);
|
return $this->db->all($sql, $debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -484,9 +484,9 @@ class Model extends Object {
|
||||||
* @param unknown_type $fields
|
* @param unknown_type $fields
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function find_all_threaded ($conditions=null, $fields=null) {
|
function findAllThreaded ($conditions=null, $fields=null) {
|
||||||
return $this->_do_thread($this->find_all($conditions, $fields), null);
|
return $this->_doThread($this->findAll($conditions, $fields), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -494,10 +494,10 @@ class Model extends Object {
|
||||||
* @param unknown_type $conditions
|
* @param unknown_type $conditions
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function find_count ($conditions) {
|
function findCount ($conditions) {
|
||||||
list($data) = $this->find_all($conditions, 'COUNT(id) AS count');
|
list($data) = $this->findAll($conditions, 'COUNT(id) AS count');
|
||||||
return $data['count'];
|
return $data['count'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -506,19 +506,19 @@ class Model extends Object {
|
||||||
* @param unknown_type $root
|
* @param unknown_type $root
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function _do_thread ($data, $root) {
|
function _doThread ($data, $root) {
|
||||||
$out = array();
|
$out = array();
|
||||||
|
|
||||||
for ($ii=0; $ii<sizeof($data); $ii++) {
|
for ($ii=0; $ii<sizeof($data); $ii++) {
|
||||||
if ($data[$ii]['parent_id'] == $root) {
|
if ($data[$ii]['parent_id'] == $root) {
|
||||||
$tmp = $data[$ii];
|
$tmp = $data[$ii];
|
||||||
$tmp['children'] = isset($data[$ii]['id'])? $this->_do_thread($data, $data[$ii]['id']): null;
|
$tmp['children'] = isset($data[$ii]['id'])? $this->_do_thread($data, $data[$ii]['id']): null;
|
||||||
$out[] = $tmp;
|
$out[] = $tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -528,12 +528,12 @@ class Model extends Object {
|
||||||
* @param unknown_type $value
|
* @param unknown_type $value
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function find_neighbours ($conditions, $field, $value) {
|
function findNeighbours ($conditions, $field, $value) {
|
||||||
list($prev) = $this->find_all($conditions." AND {$field} < '{$value}'", $field, "{$field} DESC", 1);
|
list($prev) = $this->findAll($conditions." AND {$field} < '{$value}'", $field, "{$field} DESC", 1);
|
||||||
list($next) = $this->find_all($conditions." AND {$field} > '{$value}'", $field, "{$field} ASC", 1);
|
list($next) = $this->findAll($conditions." AND {$field} > '{$value}'", $field, "{$field} ASC", 1);
|
||||||
|
|
||||||
return array('prev'=>$prev['id'], 'next'=>$next['id']);
|
return array('prev'=>$prev['id'], 'next'=>$next['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -541,9 +541,9 @@ class Model extends Object {
|
||||||
* @param unknown_type $sql
|
* @param unknown_type $sql
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function query ($sql) {
|
function query ($sql) {
|
||||||
return $this->db->q($sql);
|
return $this->db->query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -551,11 +551,11 @@ class Model extends Object {
|
||||||
* @param unknown_type $data
|
* @param unknown_type $data
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function validates ($data=null) {
|
function validates ($data=null) {
|
||||||
$errors = count($this->invalid_fields($data));
|
$errors = count($this->invalidFields($data));
|
||||||
|
|
||||||
return $errors == 0;
|
return $errors == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -563,9 +563,9 @@ class Model extends Object {
|
||||||
* @param unknown_type $data
|
* @param unknown_type $data
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function invalid_fields ($data=null) {
|
function invalidFields ($data=null) {
|
||||||
return $this->_invalid_fields($data);
|
return $this->_invalidFields($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -573,22 +573,22 @@ class Model extends Object {
|
||||||
* @param unknown_type $data
|
* @param unknown_type $data
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function _invalid_fields ($data=null) {
|
function _invalidFields ($data=null) {
|
||||||
if (!isset($this->validate))
|
if (!isset($this->validate))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
$data = ($data? $data: (isset($this->data)? $this->data: array()));
|
$data = ($data? $data: (isset($this->data)? $this->data: array()));
|
||||||
$errors = array();
|
$errors = array();
|
||||||
|
|
||||||
foreach ($this->validate as $field_name=>$validator) {
|
foreach ($this->validate as $field_name=>$validator) {
|
||||||
if (isset($data[$field_name])) {
|
if (isset($data[$field_name])) {
|
||||||
if (!preg_match($validator, $data[$field_name]))
|
if (!preg_match($validator, $data[$field_name]))
|
||||||
$errors[$field_name] = 1;
|
$errors[$field_name] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,19 +53,18 @@ class Object {
|
||||||
*
|
*
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
function Object() {
|
function Object() {
|
||||||
$args= func_get_args();
|
$args= func_get_args();
|
||||||
call_user_func_array(array(&$this, '__construct'), $args);
|
call_user_func_array(array(&$this, '__construct'), $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $args
|
* @param unknown_type $args
|
||||||
*/
|
*/
|
||||||
function __construct($args=NULL) {
|
function __construct($args=NULL) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
141
libs/router.php
141
libs/router.php
|
@ -61,15 +61,15 @@ class Router extends Object {
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $routes = array();
|
var $routes = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function __construct () {
|
function __construct () {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -77,35 +77,40 @@ class Router extends Object {
|
||||||
* @param unknown_type $route
|
* @param unknown_type $route
|
||||||
* @param unknown_type $default
|
* @param unknown_type $default
|
||||||
*/
|
*/
|
||||||
function connect ($route, $default=null) {
|
function connect ($route, $default=null) {
|
||||||
$parsed = $names = array ();
|
$parsed = $names = array ();
|
||||||
|
|
||||||
$r = null;
|
$r = null;
|
||||||
if ($route == '' || $route == '/') {
|
if (($route == '') || ($route == '/')) {
|
||||||
$this->routes[] = array('/^[\/]*$/', array(), $default);
|
$regexp = '/^[\/]*$/';
|
||||||
}
|
$this->routes[] = array($route, $regexp, array(), $default);
|
||||||
else {
|
}
|
||||||
if (@preg_match_all('|(?:/([^/]+))|', $route, $r)) {
|
else {
|
||||||
|
$elements = array();
|
||||||
|
foreach (explode('/', $route) as $element)
|
||||||
|
if (trim($element)) $elements[] = $element;
|
||||||
|
|
||||||
foreach ($r[1] as $element) {
|
if (!count($elements))
|
||||||
if (preg_match('/^:(.+)$/', $element, $r)) {
|
return false;
|
||||||
$parsed[] = '(?:\/([^\/]+))?';
|
|
||||||
$names[] = $r[1];
|
|
||||||
}
|
|
||||||
elseif (preg_match('/^\*$/', $element, $r)) {
|
|
||||||
$parsed[] = '(.*)';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$parsed[] = '/'.$element;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$regexp = '#^'.join('', $parsed).'$#';
|
|
||||||
|
|
||||||
$this->routes[] = array($regexp,$names,$default);
|
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...
|
* Enter description here...
|
||||||
|
@ -113,40 +118,60 @@ class Router extends Object {
|
||||||
* @param unknown_type $url
|
* @param unknown_type $url
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function parse ($url) {
|
function parse ($url) {
|
||||||
$out = array();
|
$out = array();
|
||||||
$r = null;
|
$r = null;
|
||||||
|
|
||||||
foreach ($this->routes as $route) {
|
$default_route = array(
|
||||||
list($regexp,$names,$defaults) = $route;
|
'/:controller/:action/* (default)',
|
||||||
|
"#^(?:\/(?:([a-z0-9_\-]+)(?:\/([a-z0-9_\-]+)(?:\/(.*))?)?))[\/]*$#",
|
||||||
|
array('controller', 'action'),
|
||||||
|
array()
|
||||||
|
);
|
||||||
|
|
||||||
if (@preg_match($regexp, $url, $r)) {
|
$this->routes[] = $default_route;
|
||||||
|
|
||||||
array_shift($r);
|
foreach ($this->routes as $route) {
|
||||||
$ii = 0;
|
list($route, $regexp, $names, $defaults) = $route;
|
||||||
foreach ($r as $found) {
|
|
||||||
if (isset($names[$ii]))
|
|
||||||
$out[$names[$ii]] = $found;
|
|
||||||
elseif (preg_match_all('/(?:\/([^\/]+))/', $found, $r)) {
|
|
||||||
$out['pass'] = $r[1];
|
|
||||||
}
|
|
||||||
$ii++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($defaults)) {
|
if (preg_match($regexp, $url, $r)) {
|
||||||
foreach ($defaults as $name => $value) {
|
// remove the first element, which is the url
|
||||||
if (preg_match('/[a-zA-Z_\-]/', $name))
|
array_shift($r);
|
||||||
$out[$name] = $value;
|
|
||||||
else
|
|
||||||
$out['pass'][] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $out;
|
// 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -62,7 +62,7 @@ class Template extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $base = null;
|
var $base = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -70,7 +70,7 @@ class Template extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $layout = 'default';
|
var $layout = 'default';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -78,7 +78,7 @@ class Template extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $auto_render = true;
|
var $auto_render = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -86,7 +86,7 @@ class Template extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $auto_layout = true;
|
var $auto_layout = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -94,7 +94,7 @@ class Template extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $_view_vars = array();
|
var $_view_vars = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -102,24 +102,24 @@ class Template extends Object {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $_page_title = false;
|
var $_page_title = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function __construct () {
|
function __construct () {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $layout
|
* @param unknown_type $layout
|
||||||
*/
|
*/
|
||||||
function set_layout ($layout) {
|
function set_layout ($layout) {
|
||||||
$this->layout = $layout;
|
$this->layout = $layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -128,32 +128,32 @@ class Template extends Object {
|
||||||
* @param unknown_type $two
|
* @param unknown_type $two
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function set($one, $two=null) {
|
function set($one, $two=null) {
|
||||||
return $this->_set_array(is_array($one)? $one: array($one=>$two));
|
return $this->_set_array(is_array($one)? $one: array($one=>$two));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $value
|
* @param unknown_type $value
|
||||||
*/
|
*/
|
||||||
function set_title ($value) {
|
function set_title ($value) {
|
||||||
$this->_page_title = $value;
|
$this->_page_title = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $data
|
* @param unknown_type $data
|
||||||
*/
|
*/
|
||||||
function _set_array($data) {
|
function _set_array($data) {
|
||||||
foreach ($data as $name => $value) {
|
foreach ($data as $name => $value) {
|
||||||
if ($name == 'title')
|
if ($name == 'title')
|
||||||
$this->set_title ($value);
|
$this->set_title ($value);
|
||||||
else
|
else
|
||||||
$this->_view_vars[$name] = $value;
|
$this->_view_vars[$name] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -162,16 +162,16 @@ class Template extends Object {
|
||||||
* @param unknown_type $url
|
* @param unknown_type $url
|
||||||
* @param unknown_type $time
|
* @param unknown_type $time
|
||||||
*/
|
*/
|
||||||
function flash ($message, $url, $time=1) {
|
function flash ($message, $url, $time=1) {
|
||||||
$this->auto_render = false;
|
$this->auto_render = false;
|
||||||
$this->auto_layout = false;
|
$this->auto_layout = false;
|
||||||
|
|
||||||
$this->set('url', $this->base.$url);
|
$this->set('url', $this->base.$url);
|
||||||
$this->set('message', $message);
|
$this->set('message', $message);
|
||||||
$this->set('time', $time);
|
$this->set('time', $time);
|
||||||
|
|
||||||
$this->render(null,false,VIEWS.'layouts/flash.thtml');
|
$this->render(null,false,VIEWS.'layouts/flash.thtml');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -180,33 +180,32 @@ class Template extends Object {
|
||||||
* @param unknown_type $layout
|
* @param unknown_type $layout
|
||||||
* @param unknown_type $file
|
* @param unknown_type $file
|
||||||
*/
|
*/
|
||||||
function render ($action=null, $layout=null, $file=null) {
|
function render ($action=null, $layout=null, $file=null) {
|
||||||
$this->auto_render = false;
|
$this->auto_render = false;
|
||||||
|
|
||||||
if (!$action) $action = $this->action;
|
if (!$action) $action = $this->action;
|
||||||
if ($layout) $this->set_layout($layout);
|
if ($layout) $this->set_layout($layout);
|
||||||
|
|
||||||
$view_fn = $file? $file: $this->_get_view_fn($action);
|
$view_fn = $file? $file: $this->_get_view_fn($action);
|
||||||
|
|
||||||
if (!is_file($view_fn)) {
|
if (!is_file($view_fn)) {
|
||||||
DEBUG? trigger_error (sprintf(ERROR_NO_VIEW, $action, $view_fn), E_USER_ERROR)
|
DEBUG? trigger_error (sprintf(ERROR_NO_VIEW, $action, $view_fn), E_USER_ERROR)
|
||||||
: $this->error('404', 'Not found', sprintf(ERROR_404, '', "missing view \"{$action}\""));
|
: $this->error('404', 'Not found', sprintf(ERROR_404, '', "missing view \"{$action}\""));
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
$out = $this->_do_render($view_fn, $this->_view_vars, 0);
|
$out = $this->_do_render($view_fn, $this->_view_vars, 0);
|
||||||
|
|
||||||
if ($out !== false) {
|
if ($out !== false) {
|
||||||
if ($this->layout && $this->auto_layout) $out = $this->render_layout($out);
|
if ($this->layout && $this->auto_layout) $out = $this->render_layout($out);
|
||||||
if (CACHE_PAGES) $this->cache->append($out);
|
if (CACHE_PAGES) $this->cache->append($out);
|
||||||
print $out;
|
print $out;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$out = $this->_do_render($view_fn, $this->_view_vars, false);
|
$out = $this->_do_render($view_fn, $this->_view_vars, false);
|
||||||
trigger_error (sprintf(ERROR_IN_VIEW, $view_fn, $out), E_USER_ERROR);
|
trigger_error (sprintf(ERROR_IN_VIEW, $view_fn, $out), E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -214,39 +213,39 @@ class Template extends Object {
|
||||||
* @param unknown_type $content_for_layout
|
* @param unknown_type $content_for_layout
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function render_layout ($content_for_layout) {
|
function render_layout ($content_for_layout) {
|
||||||
$layout_fn = $this->_get_layout_fn();
|
$layout_fn = $this->_get_layout_fn();
|
||||||
|
|
||||||
$data_for_layout = array_merge($this->_view_vars, array(
|
$data_for_layout = array_merge($this->_view_vars, array(
|
||||||
'title_for_layout'=>$this->_page_title !== false? $this->_page_title: ucfirst($this->name),
|
'title_for_layout'=>$this->_page_title !== false? $this->_page_title: ucfirst($this->name),
|
||||||
'content_for_layout'=>$content_for_layout));
|
'content_for_layout'=>$content_for_layout));
|
||||||
|
|
||||||
if (is_file($layout_fn)) {
|
if (is_file($layout_fn)) {
|
||||||
$out = $this->_do_render($layout_fn, $data_for_layout);
|
$out = $this->_do_render($layout_fn, $data_for_layout);
|
||||||
|
|
||||||
if ($out === false) {
|
if ($out === false) {
|
||||||
$out = $this->_do_render($layout_fn, $data_for_layout, false);
|
$out = $this->_do_render($layout_fn, $data_for_layout, false);
|
||||||
trigger_error (sprintf(ERROR_IN_LAYOUT, $layout_fn, $out), E_USER_ERROR);
|
trigger_error (sprintf(ERROR_IN_LAYOUT, $layout_fn, $out), E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
trigger_error (sprintf(ERROR_NO_LAYOUT, $this->layout, $layout_fn), E_USER_ERROR);
|
trigger_error (sprintf(ERROR_NO_LAYOUT, $this->layout, $layout_fn), E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function _get_layout_fn() {
|
function _get_layout_fn() {
|
||||||
return VIEWS."layouts/{$this->layout}.thtml";
|
return VIEWS."layouts/{$this->layout}.thtml";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -254,9 +253,9 @@ class Template extends Object {
|
||||||
* @param unknown_type $action
|
* @param unknown_type $action
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function _get_view_fn($action) {
|
function _get_view_fn($action) {
|
||||||
return VIEWS.$this->name."/{$action}.thtml";
|
return VIEWS.$this->name."/{$action}.thtml";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -266,34 +265,33 @@ class Template extends Object {
|
||||||
* @param unknown_type $___play_safe
|
* @param unknown_type $___play_safe
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function _do_render($___view_fn, $___data_for_view, $___play_safe = true) {
|
function _do_render($___view_fn, $___data_for_view, $___play_safe = true) {
|
||||||
extract($___data_for_view, EXTR_SKIP); # load all view variables
|
extract($___data_for_view, EXTR_SKIP); # load all view variables
|
||||||
$BASE = $this->base;
|
$BASE = $this->base;
|
||||||
$params = &$this->params;
|
$params = &$this->params;
|
||||||
$page_title = $this->_page_title;
|
$page_title = $this->_page_title;
|
||||||
ob_start(); # start caching output (eval outputs directly so we need to cache)
|
$data = empty($this->data)? false: $this->data;
|
||||||
|
ob_start(); # start caching output (eval outputs directly so we need to cache)
|
||||||
|
|
||||||
# include the template
|
# include the template
|
||||||
$___play_safe? @include($___view_fn): include($___view_fn);
|
$___play_safe? @include($___view_fn): include($___view_fn);
|
||||||
|
|
||||||
$out = ob_get_contents(); # retrieve cached output
|
$out = ob_get_contents(); # retrieve cached output
|
||||||
ob_end_clean(); # end caching output
|
ob_end_clean(); # end caching output
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* trims a string to a specified length adding elipsis '..' if necessary
|
* trims a string to a specified length adding elipsis '..' if necessary
|
||||||
*
|
*
|
||||||
* @param unknown_type $string
|
* @param unknown_type $string
|
||||||
* @param unknown_type $length
|
* @param unknown_type $length
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function trim_to ($string, $length) {
|
function trim_to ($string, $length) {
|
||||||
return substr($string, 0, $length).(strlen($string)>$length? '..': null);
|
return substr($string, 0, $length).(strlen($string)>$length? '..': null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
625
libs/test.php
Normal file
625
libs/test.php
Normal file
|
@ -0,0 +1,625 @@
|
||||||
|
<?php
|
||||||
|
//
|
||||||
|
// PHP framework for testing, based on the design of "JUnit".
|
||||||
|
//
|
||||||
|
// Written by Fred Yankowski <fred@ontosys.com>
|
||||||
|
// OntoSys, Inc <http://www.OntoSys.com>
|
||||||
|
//
|
||||||
|
// Changes by Michal Tatarynowicz <tatarynowicz@gmail.com>
|
||||||
|
//
|
||||||
|
// $Id: test.php 113 2005-05-16 22:53:41Z pies $
|
||||||
|
|
||||||
|
// Copyright (c) 2000 Fred Yankowski
|
||||||
|
|
||||||
|
// Permission is hereby granted, free of charge, to any person
|
||||||
|
// obtaining a copy of this software and associated documentation
|
||||||
|
// files (the "Software"), to deal in the Software without
|
||||||
|
// restriction, including without limitation the rights to use, copy,
|
||||||
|
// modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
// of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be
|
||||||
|
// included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE |
|
||||||
|
E_CORE_ERROR | E_CORE_WARNING);
|
||||||
|
|
||||||
|
/*
|
||||||
|
interface Test {
|
||||||
|
function run(&$aTestResult);
|
||||||
|
function countTestCases();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
function trace($msg) {
|
||||||
|
return;
|
||||||
|
print($msg);
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (phpversion() >= '4') {
|
||||||
|
function PHPUnit_error_handler($errno, $errstr, $errfile, $errline) {
|
||||||
|
global $PHPUnit_testRunning;
|
||||||
|
$PHPUnit_testRunning[0]->fail("<B>PHP ERROR:</B> ".$errstr." <B>in</B> ".$errfile." <B>at line</B> ".$errline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestException {
|
||||||
|
/* Emulate a Java exception, sort of... */
|
||||||
|
var $message;
|
||||||
|
var $type;
|
||||||
|
function TestException($message, $type = 'FAILURE') {
|
||||||
|
$this->message = $message;
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
function getMessage() {
|
||||||
|
return $this->message;
|
||||||
|
}
|
||||||
|
function getType() {
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Assert {
|
||||||
|
function assert($boolean, $message=0) {
|
||||||
|
if (! $boolean)
|
||||||
|
$this->fail($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
function asEq ($expected, $actual, $message=0) {
|
||||||
|
return $this->assertEquals($expected, $actual, $message);
|
||||||
|
}
|
||||||
|
function assertEquals($expected, $actual, $message=0) {
|
||||||
|
if (gettype($expected) != gettype($actual)) {
|
||||||
|
$this->failNotEquals($expected, $actual, "expected", $message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (phpversion() < '4') {
|
||||||
|
if (is_object($expected) or is_object($actual) or is_array($expected) or is_array($actual)) {
|
||||||
|
$this->error("INVALID TEST: cannot compare arrays or objects in PHP3");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (phpversion() >= '4' && is_object($expected)) {
|
||||||
|
if (get_class($expected) != get_class($actual)) {
|
||||||
|
$this->failNotEquals($expected, $actual, "expected", $message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method_exists($expected, "equals")) {
|
||||||
|
if (! $expected->equals($actual)) {
|
||||||
|
$this->failNotEquals($expected, $actual, "expected", $message);
|
||||||
|
}
|
||||||
|
return; // no further tests after equals()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (phpversion() >= '4.0.4') {
|
||||||
|
if (is_null($expected) != is_null($actual)) {
|
||||||
|
$this->failNotEquals($expected, $actual, "expected", $message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($expected != $actual) {
|
||||||
|
$this->failNotEquals($actual, $expected, "expected", $message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertRegexp($regexp, $actual, $message=false) {
|
||||||
|
if (! preg_match($regexp, $actual)) {
|
||||||
|
$this->failNotEquals($regexp, $actual, "pattern", $message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertEqualsMultilineStrings($string0, $string1,
|
||||||
|
$message="") {
|
||||||
|
$lines0 = split("\n",$string0);
|
||||||
|
$lines1 = split("\n",$string1);
|
||||||
|
if (sizeof($lines0) != sizeof($lines1)) {
|
||||||
|
$this->failNotEquals(sizeof($lines0)." line(s)",
|
||||||
|
sizeof($lines1)." line(s)", "expected", $message);
|
||||||
|
}
|
||||||
|
for($i=0; $i< sizeof($lines0); $i++) {
|
||||||
|
$this->assertEquals(trim($lines0[$i]),
|
||||||
|
trim($lines1[$i]),
|
||||||
|
"line ".($i+1)." of multiline strings differ. ".$message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertFileExists ($fn) {
|
||||||
|
if (!file_exists($fn))
|
||||||
|
$this->failNotEquals($fn, "file not found", "file expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertFileContains ($fn, $str) {
|
||||||
|
if (file_exists($fn)) {
|
||||||
|
$lines = file($fn);
|
||||||
|
$text = implode("\n", $lines);
|
||||||
|
|
||||||
|
if (!preg_match("/{$str}/", $text))
|
||||||
|
$this->failNotEquals($fn, 'expected '.$str, 'expected');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->failNotEquals($fn, 'file doesn\'t exist', 'expected');
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertDirExists ($path) {
|
||||||
|
if (!is_dir($path))
|
||||||
|
$this->failNotEquals($path, "directory not found", "expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertTrue ($value) {
|
||||||
|
if (!$value)
|
||||||
|
$this->failNotEquals($value, true, "expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _formatValue ($value) {
|
||||||
|
|
||||||
|
if (is_object($value) && method_exists($value, "toString")) {
|
||||||
|
$valueStr = $value->toString();
|
||||||
|
}
|
||||||
|
elseif (is_bool($value)) {
|
||||||
|
$valueStr = $value? 'false': 'true';
|
||||||
|
}
|
||||||
|
elseif (is_object($value) || is_array($value)) {
|
||||||
|
$valueStr = serialize($value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$valueStr = str_replace('<', '<', str_replace('>', '>', $value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return array($valueStr, gettype($value));
|
||||||
|
}
|
||||||
|
|
||||||
|
function _old_formatValue($value, $class="") {
|
||||||
|
$translateValue = $value;
|
||||||
|
if (phpversion() >= '4.0.0') {
|
||||||
|
if (is_object($value)) {
|
||||||
|
if (method_exists($value, "toString") ) {
|
||||||
|
$translateValue = $value->toString();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$translateValue = serialize($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (is_array($value)) {
|
||||||
|
$translateValue = serialize($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$htmlValue = "<code class=\"$class\">" . htmlspecialchars($translateValue) . "</code>";
|
||||||
|
if (phpversion() >= '4.0.0') {
|
||||||
|
if (is_bool($value)) {
|
||||||
|
$htmlValue = $value ? "<i>true</i>" : "<i>false</i>";
|
||||||
|
}
|
||||||
|
elseif (phpversion() >= '4.0.4' && is_null($value)) {
|
||||||
|
$htmlValue = "<i>null</i>";
|
||||||
|
}
|
||||||
|
$htmlValue .= " <span class=\"typeinfo\">";
|
||||||
|
$htmlValue .= " type:" . gettype($value);
|
||||||
|
$htmlValue .= is_object($value) ? ", class:" . get_class($value) : "";
|
||||||
|
$htmlValue .= "</span>";
|
||||||
|
}
|
||||||
|
return $htmlValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function failNotEquals ($expected, $actual, $expected_label, $message=null) {
|
||||||
|
$out = array(
|
||||||
|
'message'=>$message,
|
||||||
|
'label'=>$expected_label,
|
||||||
|
'expected'=>$this->_formatValue($expected, "expected"),
|
||||||
|
'actual'=>$this->_formatValue($actual, "actual")
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->fail($out);
|
||||||
|
}
|
||||||
|
|
||||||
|
function old_failNotEquals($expected, $actual, $expected_label, $message=0) {
|
||||||
|
// Private function for reporting failure to match.
|
||||||
|
$str = $message ? ($message . ' ') : '';
|
||||||
|
//$str .= "($expected_label/actual)<br>";
|
||||||
|
$str .= "<br>";
|
||||||
|
$str .= sprintf("%s<br>%s",
|
||||||
|
$this->_formatValue($expected, "expected"),
|
||||||
|
$this->_formatValue($actual, "actual"));
|
||||||
|
$this->fail($str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestCase extends Assert /* implements Test */ {
|
||||||
|
/* Defines context for running tests. Specific context -- such as
|
||||||
|
instance variables, global variables, global state -- is defined
|
||||||
|
by creating a subclass that specializes the setUp() and
|
||||||
|
tearDown() methods. A specific test is defined by a subclass
|
||||||
|
that specializes the runTest() method. */
|
||||||
|
var $fName;
|
||||||
|
var $fClassName;
|
||||||
|
var $fResult;
|
||||||
|
var $fExceptions = array();
|
||||||
|
|
||||||
|
function TestCase($name) {
|
||||||
|
$this->fName = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function run($testResult=0) {
|
||||||
|
/* Run this single test, by calling the run() method of the
|
||||||
|
TestResult object which will in turn call the runBare() method
|
||||||
|
of this object. That complication allows the TestResult object
|
||||||
|
to do various kinds of progress reporting as it invokes each
|
||||||
|
test. Create/obtain a TestResult object if none was passed in.
|
||||||
|
Note that if a TestResult object was passed in, it must be by
|
||||||
|
reference. */
|
||||||
|
if (! $testResult)
|
||||||
|
$testResult = $this->_createResult();
|
||||||
|
$this->fResult = $testResult;
|
||||||
|
$testResult->run(&$this);
|
||||||
|
$this->fResult = 0;
|
||||||
|
return $testResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
function classname() {
|
||||||
|
if (isset($this->fClassName)) {
|
||||||
|
return $this->fClassName;
|
||||||
|
} else {
|
||||||
|
return get_class($this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function countTestCases() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function runTest() {
|
||||||
|
|
||||||
|
if (version_compare(phpversion(), '4') >= 0) {
|
||||||
|
global $PHPUnit_testRunning;
|
||||||
|
eval('$PHPUnit_testRunning[0] = & $this;');
|
||||||
|
|
||||||
|
// Saved ref to current TestCase, so that the error handler
|
||||||
|
// can access it. This code won't even parse in PHP3, so we
|
||||||
|
// hide it in an eval.
|
||||||
|
|
||||||
|
$old_handler = set_error_handler("PHPUnit_error_handler");
|
||||||
|
// errors will now be handled by our error handler
|
||||||
|
}
|
||||||
|
|
||||||
|
$name = $this->name();
|
||||||
|
if ((version_compare(phpversion(), '4') >= 0) && ! method_exists($this, $name)) {
|
||||||
|
$this->error("Method '$name' does not exist");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->$name();
|
||||||
|
|
||||||
|
if (version_compare(phpversion(), '4') >= 0) {
|
||||||
|
restore_error_handler(); // revert to prior error handler
|
||||||
|
$PHPUnit_testRunning = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setUp() /* expect override */ {
|
||||||
|
//print("TestCase::setUp()<br>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function tearDown() /* possible override */ {
|
||||||
|
//print("TestCase::tearDown()<br>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
function _createResult() /* protected */ {
|
||||||
|
/* override this to use specialized subclass of TestResult */
|
||||||
|
return new TestResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fail($message=0) {
|
||||||
|
//printf("TestCase::fail(%s)<br>\n", ($message) ? $message : '');
|
||||||
|
/* JUnit throws AssertionFailedError here. We just record the
|
||||||
|
failure and carry on */
|
||||||
|
$this->fExceptions[] = new TestException(&$message, 'FAILURE');
|
||||||
|
}
|
||||||
|
|
||||||
|
function error($message) {
|
||||||
|
/* report error that requires correction in the test script
|
||||||
|
itself, or (heaven forbid) in this testing infrastructure */
|
||||||
|
$this->fExceptions[] = new TestException(&$message, 'ERROR');
|
||||||
|
$this->fResult->stop(); // [does not work]
|
||||||
|
}
|
||||||
|
|
||||||
|
function failed() {
|
||||||
|
reset($this->fExceptions);
|
||||||
|
while (list($key, $exception) = each($this->fExceptions)) {
|
||||||
|
if ($exception->type == 'FAILURE')
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
function errored() {
|
||||||
|
reset($this->fExceptions);
|
||||||
|
while (list($key, $exception) = each($this->fExceptions)) {
|
||||||
|
if ($exception->type == 'ERROR')
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getExceptions() {
|
||||||
|
return $this->fExceptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
function name() {
|
||||||
|
return $this->fName;
|
||||||
|
}
|
||||||
|
|
||||||
|
function runBare() {
|
||||||
|
$this->setup();
|
||||||
|
$this->runTest();
|
||||||
|
$this->tearDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestSuite /* implements Test */ {
|
||||||
|
/* Compose a set of Tests (instances of TestCase or TestSuite), and
|
||||||
|
run them all. */
|
||||||
|
var $fTests = array();
|
||||||
|
var $fClassname;
|
||||||
|
|
||||||
|
function TestSuite($classname=false) {
|
||||||
|
// Find all methods of the given class whose name starts with
|
||||||
|
// "test" and add them to the test suite.
|
||||||
|
|
||||||
|
// PHP3: We are just _barely_ able to do this with PHP's limited
|
||||||
|
// introspection... Note that PHP seems to store method names in
|
||||||
|
// lower case, and we have to avoid the constructor function for
|
||||||
|
// the TestCase class superclass. Names of subclasses of TestCase
|
||||||
|
// must not start with "Test" since such a class will have a
|
||||||
|
// constructor method name also starting with "test" and we can't
|
||||||
|
// distinquish such a construtor from the real test method names.
|
||||||
|
// So don't name any TestCase subclasses as "Test..."!
|
||||||
|
|
||||||
|
// PHP4: Never mind all that. We can now ignore constructor
|
||||||
|
// methods, so a test class may be named "Test...".
|
||||||
|
|
||||||
|
if (empty($classname))
|
||||||
|
return;
|
||||||
|
$this->fClassname = $classname;
|
||||||
|
|
||||||
|
if (!class_exists($classname)) {
|
||||||
|
user_error('Tested class '.$classname.' doesn\'t appear to exist.', E_USER_WARNING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (floor(phpversion()) >= 4) {
|
||||||
|
// PHP4 introspection, submitted by Dylan Kuhn
|
||||||
|
|
||||||
|
$names = get_class_methods($classname);
|
||||||
|
|
||||||
|
while (list($key, $method) = each($names)) {
|
||||||
|
if (preg_match('/^test/', $method)) {
|
||||||
|
$test = new $classname($method);
|
||||||
|
if (strcasecmp($method, $classname) == 0 || is_subclass_of($test, $method)) {
|
||||||
|
// Ignore the given method name since it is a constructor:
|
||||||
|
// it's the name of our test class or it is the name of a
|
||||||
|
// superclass of our test class. (This code smells funny.
|
||||||
|
// Anyone got a better way?)
|
||||||
|
|
||||||
|
//print "skipping $method<br>";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->addTest($test);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { // PHP3
|
||||||
|
$dummy = new $classname("dummy");
|
||||||
|
$names = (array) $dummy;
|
||||||
|
while (list($key, $value) = each($names)) {
|
||||||
|
$type = gettype($value);
|
||||||
|
if ($type == "user function" && preg_match('/^test/', $key)
|
||||||
|
&& $key != "testcase") {
|
||||||
|
$this->addTest(new $classname($key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addTest($test) {
|
||||||
|
/* Add TestCase or TestSuite to this TestSuite */
|
||||||
|
$this->fTests[] = $test;
|
||||||
|
}
|
||||||
|
|
||||||
|
function run(&$testResult) {
|
||||||
|
/* Run all TestCases and TestSuites comprising this TestSuite,
|
||||||
|
accumulating results in the given TestResult object. */
|
||||||
|
reset($this->fTests);
|
||||||
|
while (list($na, $test) = each($this->fTests)) {
|
||||||
|
if ($testResult->shouldStop())
|
||||||
|
break;
|
||||||
|
$test->run(&$testResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function countTestCases() {
|
||||||
|
/* Number of TestCases comprising this TestSuite (including those
|
||||||
|
in any constituent TestSuites) */
|
||||||
|
$count = 0;
|
||||||
|
reset($fTests);
|
||||||
|
while (list($na, $test_case) = each($this->fTests)) {
|
||||||
|
$count += $test_case->countTestCases();
|
||||||
|
}
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestFailure {
|
||||||
|
/* Record failure of a single TestCase, associating it with the
|
||||||
|
exception that occurred */
|
||||||
|
var $fFailedTestName;
|
||||||
|
var $fException;
|
||||||
|
|
||||||
|
function TestFailure(&$test, &$exception) {
|
||||||
|
$this->fFailedTestName = $test->name();
|
||||||
|
$this->fException = $exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getExceptions() {
|
||||||
|
// deprecated
|
||||||
|
return array($this->fException);
|
||||||
|
}
|
||||||
|
function getException() {
|
||||||
|
return $this->fException;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTestName() {
|
||||||
|
return $this->fFailedTestName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestResult {
|
||||||
|
/* Collect the results of running a set of TestCases. */
|
||||||
|
var $fFailures = array();
|
||||||
|
var $fErrors = array();
|
||||||
|
var $fRunTests = 0;
|
||||||
|
var $fStop = false;
|
||||||
|
|
||||||
|
function TestResult() { }
|
||||||
|
|
||||||
|
function _endTest($test) /* protected */ {
|
||||||
|
/* specialize this for end-of-test action, such as progress
|
||||||
|
reports */
|
||||||
|
}
|
||||||
|
|
||||||
|
function addError($test, $exception) {
|
||||||
|
$this->fErrors[] = new TestFailure(&$test, &$exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addFailure($test, $exception) {
|
||||||
|
$this->fFailures[] = new TestFailure(&$test, &$exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFailures() {
|
||||||
|
return $this->fFailures;
|
||||||
|
}
|
||||||
|
|
||||||
|
function run($test) {
|
||||||
|
/* Run a single TestCase in the context of this TestResult */
|
||||||
|
$this->_startTest($test);
|
||||||
|
$this->fRunTests++;
|
||||||
|
|
||||||
|
$test->runBare();
|
||||||
|
|
||||||
|
/* this is where JUnit would catch AssertionFailedError */
|
||||||
|
$exceptions = $test->getExceptions();
|
||||||
|
reset($exceptions);
|
||||||
|
while (list($key, $exception) = each($exceptions)) {
|
||||||
|
if ($exception->type == 'ERROR')
|
||||||
|
$this->addError($test, $exception);
|
||||||
|
else if ($exception->type == 'FAILURE')
|
||||||
|
$this->addFailure($test, $exception);
|
||||||
|
}
|
||||||
|
// if ($exceptions)
|
||||||
|
// $this->fFailures[] = new TestFailure(&$test, &$exceptions);
|
||||||
|
$this->_endTest($test);
|
||||||
|
}
|
||||||
|
|
||||||
|
function countTests() {
|
||||||
|
return $this->fRunTests;
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldStop() {
|
||||||
|
return $this->fStop;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _startTest($test) /* protected */ {
|
||||||
|
/* specialize this for start-of-test actions */
|
||||||
|
}
|
||||||
|
|
||||||
|
function stop() {
|
||||||
|
/* set indication that the test sequence should halt */
|
||||||
|
$fStop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function errorCount() {
|
||||||
|
return count($this->fErrors);
|
||||||
|
}
|
||||||
|
function failureCount() {
|
||||||
|
return count($this->fFailures);
|
||||||
|
}
|
||||||
|
function countFailures() {
|
||||||
|
// deprecated
|
||||||
|
return $this->failureCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ResultDataMiner extends TestResult {
|
||||||
|
var $tests = null;
|
||||||
|
var $total_tests = 0;
|
||||||
|
var $total_errors = 0;
|
||||||
|
|
||||||
|
function _startTest($test) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function _endTest($test) {
|
||||||
|
$class_name = $test->classname();
|
||||||
|
if (preg_match('/^(.*)test$/i', $class_name, $r))
|
||||||
|
$class_name = $r[1];
|
||||||
|
$method_name = $test->name();
|
||||||
|
if (preg_match('/^test(.*)$/i', $method_name, $r))
|
||||||
|
$method_name = $r[1];
|
||||||
|
|
||||||
|
$errors = null;
|
||||||
|
foreach ($test->getExceptions() as $exception) {
|
||||||
|
$errors[] = $exception->message;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->tests[] = array(
|
||||||
|
'class' => $class_name,
|
||||||
|
'method' => $method_name,
|
||||||
|
'failed' => $test->failed(),
|
||||||
|
'errors' => $errors
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->total_tests++;
|
||||||
|
if ($test->failed()) $this->total_errors++;
|
||||||
|
}
|
||||||
|
|
||||||
|
function report () {
|
||||||
|
return array('tests'=>$this->total_tests, 'errors'=>$this->total_errors, 'details'=>$this->tests);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestRunner {
|
||||||
|
/* Run a suite of tests and report results. */
|
||||||
|
function run($suite) {
|
||||||
|
$result = new ResultDataMiner;
|
||||||
|
$suite->run($result);
|
||||||
|
return $result->report();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -62,10 +62,10 @@ class Time extends Object {
|
||||||
* @param unknown_type $date_string
|
* @param unknown_type $date_string
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function nice ($date_string=null) {
|
function nice ($date_string=null) {
|
||||||
$date = $date_string? strtotime($date_string): time();
|
$date = $date_string? strtotime($date_string): time();
|
||||||
return date("D, M jS Y, H:i", $date);
|
return date("D, M jS Y, H:i", $date);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -73,18 +73,18 @@ class Time extends Object {
|
||||||
* @param unknown_type $date_string
|
* @param unknown_type $date_string
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function nice_short ($date_string=null) {
|
function niceShort ($date_string=null) {
|
||||||
$date = $date_string? Time::fromString($date_string): time();
|
$date = $date_string? Time::fromString($date_string): time();
|
||||||
|
|
||||||
$y = Time::isThisYear($date)? '': ' Y';
|
$y = Time::isThisYear($date)? '': ' Y';
|
||||||
|
|
||||||
if (Time::isToday($date))
|
if (Time::isToday($date))
|
||||||
return "Today, ".date("H:i", $date);
|
return "Today, ".date("H:i", $date);
|
||||||
elseif (Time::wasYesterday($date))
|
elseif (Time::wasYesterday($date))
|
||||||
return "Yesterday, ".date("H:i", $date);
|
return "Yesterday, ".date("H:i", $date);
|
||||||
else
|
else
|
||||||
return date("M jS{$y}, H:i", $date);
|
return date("M jS{$y}, H:i", $date);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -92,9 +92,9 @@ class Time extends Object {
|
||||||
* @param unknown_type $date
|
* @param unknown_type $date
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function isToday ($date) {
|
function isToday ($date) {
|
||||||
return date('Y-m-d', $date) == date('Y-m-d', time());
|
return date('Y-m-d', $date) == date('Y-m-d', time());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -102,9 +102,9 @@ class Time extends Object {
|
||||||
* @param unknown_type $date
|
* @param unknown_type $date
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function isThisYear ($date) {
|
function isThisYear ($date) {
|
||||||
return date('Y', $date) == date('Y', time());
|
return date('Y', $date) == date('Y', time());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -112,9 +112,9 @@ class Time extends Object {
|
||||||
* @param unknown_type $date
|
* @param unknown_type $date
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function wasYesterday ($date) {
|
function wasYesterday ($date) {
|
||||||
return date('Y-m-d', $date) == date('Y-m-d', strtotime('yesterday'));
|
return date('Y-m-d', $date) == date('Y-m-d', strtotime('yesterday'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -122,10 +122,9 @@ class Time extends Object {
|
||||||
* @param unknown_type $date_string
|
* @param unknown_type $date_string
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function fromString ($date_string) {
|
function fromString ($date_string) {
|
||||||
return strtotime($date_string);
|
return strtotime($date_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -61,12 +61,12 @@ define('VALID_EMAIL', '/^([a-z0-9][a-z0-9_\-\.\+]*)@([a-z0-9][a-z0-9\.\-]{0,63}\
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
define('VALID_TAG', '/[a-z_]+/i');
|
define('VALID_TAG', '/[^\ ]+/i');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
define('VALID_TAGS', '/[a-z_ ]+/i');
|
define('VALID_TAGS', '/.+/i');
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -39,82 +39,32 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
## DIRECTORY LAYOUT
|
## DIRECTORY LAYOUT
|
||||||
/**
|
require ('../config/paths.php');
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('ROOT', '../');
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('APP', ROOT.'app/');
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('MODELS', APP.'models/');
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('CONTROLLERS', APP.'controllers/');
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('VIEWS', APP.'views/');
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('CONFIGS', ROOT.'config/');
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('LIBS', ROOT.'libs/');
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('PUBLIC', ROOT.'public/');
|
|
||||||
|
|
||||||
## STARTUP
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Startup
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
require (LIBS.'basics.php');
|
require (LIBS.'basics.php');
|
||||||
uses ('dispatcher', 'dbo');
|
|
||||||
|
uses ('dispatcher');
|
||||||
uses_config();
|
uses_config();
|
||||||
uses_database();
|
uses_database();
|
||||||
uses_tags();
|
uses_tag_generator();
|
||||||
|
|
||||||
## LOAD MODELS & CONTROLLERS
|
|
||||||
##
|
|
||||||
load_models ();
|
load_models ();
|
||||||
load_controllers ();
|
load_controllers ();
|
||||||
|
|
||||||
## START SESSION
|
|
||||||
##
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
## RUN THE SCRIPT
|
## RUN THE SCRIPT
|
||||||
##
|
|
||||||
$url = empty($_GET['url'])? null: $_GET['url'];
|
$url = empty($_GET['url'])? null: $_GET['url'];
|
||||||
$DISPATCHER = new Dispatcher ();
|
$DISPATCHER = new Dispatcher ();
|
||||||
$DISPATCHER->dispatch($url);
|
$DISPATCHER->dispatch($url);
|
||||||
|
|
||||||
## PRINT TIMING
|
if ($DB) $DB->close();
|
||||||
##
|
|
||||||
|
|
||||||
/**
|
## CLEANUP
|
||||||
* Enter description here...
|
if (DEBUG) echo "<!-- ". round(getMicrotime() - $TIME_START, 2) ."s -->";
|
||||||
*
|
|
||||||
*/
|
|
||||||
if (DEBUG) echo "<!-- ". round(getmicrotime() - $TIME_START, 2) ."s -->";
|
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -37,65 +37,15 @@
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
## DIRECTORIES
|
|
||||||
##
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('ROOT', '../');
|
|
||||||
|
|
||||||
/**
|
## START-UP
|
||||||
* Enter description here...
|
require ('../config/paths.php');
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('APP', ROOT.'app/');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('MODELS', APP.'models/');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('CONTROLLERS', APP.'controllers/');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('VIEWS', APP.'views/');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('CONFIGS', ROOT.'config/');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('LIBS', ROOT.'libs/');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define ('PUBLIC', ROOT.'public/');
|
|
||||||
|
|
||||||
## LOAD LIBRARIES
|
|
||||||
##
|
|
||||||
require (LIBS.'basics.php');
|
require (LIBS.'basics.php');
|
||||||
uses ('bake');
|
uses ('bake');
|
||||||
#load_libs ();
|
|
||||||
|
|
||||||
$script_name = array_shift($argv);
|
$waste = array_shift($argv);
|
||||||
$action = array_shift($argv);
|
$product = array_shift($argv);
|
||||||
|
|
||||||
$bake = new Bake ($action, $argv);
|
$bake = new Bake ($product, $argv);
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in a new issue