2005-06-23 08:32:04 +00:00
|
|
|
<?php
|
2005-08-21 06:49:02 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
2005-06-23 08:32:04 +00:00
|
|
|
|
|
|
|
/**
|
2005-08-25 16:40:50 +00:00
|
|
|
* Basic Cake functionality.
|
2005-06-23 08:32:04 +00:00
|
|
|
*
|
2005-08-25 16:40:50 +00:00
|
|
|
* Core functions for including other source files, loading models and so forth.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright (c) 2005, CakePHP 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.
|
|
|
|
*
|
2005-06-23 08:32:04 +00:00
|
|
|
* @filesource
|
2005-08-21 06:49:02 +00:00
|
|
|
* @author CakePHP Authors/Developers
|
|
|
|
* @copyright Copyright (c) 2005, CakePHP Authors/Developers
|
|
|
|
* @link https://trac.cakephp.org/wiki/Authors Authors/Developers
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.libs
|
|
|
|
* @since CakePHP v 0.2.9
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
2005-06-23 08:32:04 +00:00
|
|
|
* @lastmodified $Date$
|
2005-08-21 06:49:02 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-06-23 08:32:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Basic defines for timing functions.
|
2005-06-23 08:32:04 +00:00
|
|
|
*/
|
2005-10-03 04:41:33 +00:00
|
|
|
define('SECOND', 1);
|
2005-06-23 08:32:04 +00:00
|
|
|
define('MINUTE', 60 * SECOND);
|
|
|
|
define('HOUR', 60 * MINUTE);
|
|
|
|
define('DAY', 24 * HOUR);
|
2005-10-03 04:41:33 +00:00
|
|
|
define('WEEK', 7 * DAY);
|
2005-06-23 08:32:04 +00:00
|
|
|
define('MONTH', 30 * DAY);
|
2005-10-03 04:41:33 +00:00
|
|
|
define('YEAR', 365 * DAY);
|
2005-06-23 08:32:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads all models.
|
|
|
|
*
|
|
|
|
* @uses listModules()
|
|
|
|
* @uses APP
|
|
|
|
* @uses MODELS
|
|
|
|
*/
|
2005-10-03 04:41:33 +00:00
|
|
|
function loadModels ()
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
require (APP.'app_model.php');
|
|
|
|
foreach (listClasses(MODELS) as $model_fn)
|
|
|
|
{
|
|
|
|
require_once (MODELS.$model_fn);
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads all controllers.
|
|
|
|
*
|
|
|
|
* @uses APP
|
|
|
|
* @uses listModules()
|
|
|
|
* @uses HELPERS
|
|
|
|
* @uses CONTROLLERS
|
|
|
|
*/
|
2005-10-03 04:41:33 +00:00
|
|
|
function loadControllers ()
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
require (APP.'app_controller.php');
|
2005-06-23 08:32:04 +00:00
|
|
|
|
2005-10-03 04:41:33 +00:00
|
|
|
foreach (listClasses(HELPERS) as $helper)
|
|
|
|
{
|
|
|
|
require_once (HELPERS.$helper.'.php');
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
|
2005-10-03 04:41:33 +00:00
|
|
|
foreach (listClasses(CONTROLLERS) as $controller)
|
|
|
|
{
|
|
|
|
require_once (CONTROLLERS.$controller.'.php');
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-10-03 04:41:33 +00:00
|
|
|
* Loads a controller and its helper libraries.
|
|
|
|
*
|
|
|
|
* @param string $name Name of controller
|
|
|
|
* @return boolean Success
|
|
|
|
*/
|
|
|
|
function loadController ($name)
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
$controller_fn = CONTROLLERS.Inflector::underscore($name).'_controller.php';
|
|
|
|
$helper_fn = HELPERS.Inflector::underscore($name).'_helper.php';
|
|
|
|
|
|
|
|
require_once(APP.'app_controller.php');
|
|
|
|
|
|
|
|
if (file_exists($helper_fn))
|
|
|
|
require_once($helper_fn);
|
|
|
|
|
|
|
|
return file_exists($controller_fn)? require_once($controller_fn): false;
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-10-03 04:41:33 +00:00
|
|
|
* Lists PHP files in given directory.
|
|
|
|
*
|
|
|
|
* @param string $path Path to scan for files
|
|
|
|
* @return array List of files in directory
|
|
|
|
*/
|
|
|
|
function listClasses($path)
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
$modules = new Folder($path);
|
|
|
|
return $modules->find('(.+)\.php');
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads configuration files
|
2005-08-25 16:40:50 +00:00
|
|
|
*
|
2005-09-17 02:22:07 +00:00
|
|
|
* @return boolean Success
|
2005-06-23 08:32:04 +00:00
|
|
|
*/
|
2005-10-03 04:41:33 +00:00
|
|
|
function config ()
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
foreach ($args as $arg)
|
|
|
|
{
|
|
|
|
if (('database' == $arg) && file_exists(CONFIGS.$arg.'.php'))
|
|
|
|
{
|
|
|
|
include_once(CONFIGS.$arg.'.php');
|
|
|
|
}
|
|
|
|
elseif (file_exists(CONFIGS.$arg.'.php'))
|
|
|
|
{
|
|
|
|
include_once (CONFIGS.$arg.'.php');
|
|
|
|
if (count($args) == 1) return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (count($args) == 1) return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads component/components from LIBS.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* <code>
|
|
|
|
* uses('flay', 'time');
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* @uses LIBS
|
|
|
|
*/
|
2005-10-03 04:41:33 +00:00
|
|
|
function uses ()
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
foreach ($args as $arg)
|
|
|
|
{
|
|
|
|
require_once(LIBS.strtolower($arg).'.php');
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
2005-08-25 16:40:50 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Require given files in the VENDORS directory. Takes optional number of parameters.
|
2005-10-03 04:41:33 +00:00
|
|
|
*
|
|
|
|
* @param string $name Filename without the .php part.
|
|
|
|
*
|
2005-08-25 16:40:50 +00:00
|
|
|
*/
|
2005-10-03 04:41:33 +00:00
|
|
|
function vendor($name)
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
foreach ($args as $arg)
|
|
|
|
{
|
|
|
|
require_once(VENDORS.$arg.'.php');
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Print out debug information about given variable.
|
|
|
|
*
|
|
|
|
* Only runs if DEBUG level is non-zero.
|
2005-06-23 08:32:04 +00:00
|
|
|
*
|
2005-09-17 02:22:07 +00:00
|
|
|
* @param boolean $var Variable to show debug information for.
|
|
|
|
* @param boolean $show_html If set to true, the method prints the debug data in a screen-friendly way.
|
2005-06-23 08:32:04 +00:00
|
|
|
*/
|
2005-10-03 04:41:33 +00:00
|
|
|
function debug($var = false, $show_html = false)
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
if (DEBUG)
|
|
|
|
{
|
|
|
|
print "\n<pre>\n";
|
|
|
|
if ($show_html) $var = str_replace('<', '<', str_replace('>', '>', $var));
|
|
|
|
print_r($var);
|
|
|
|
print "\n</pre>\n";
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-03 04:41:33 +00:00
|
|
|
if (!function_exists('getMicrotime'))
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
/**
|
|
|
|
* Returns microtime for execution time checking.
|
|
|
|
*
|
|
|
|
* @return integer
|
|
|
|
*/
|
|
|
|
function getMicrotime()
|
|
|
|
{
|
|
|
|
list($usec, $sec) = explode(" ", microtime());
|
|
|
|
return ((float)$usec + (float)$sec);
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
2005-10-03 04:41:33 +00:00
|
|
|
if (!function_exists('sortByKey'))
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
/**
|
|
|
|
* Sorts given $array by key $sortby.
|
|
|
|
*
|
|
|
|
* @param array $array
|
|
|
|
* @param string $sortby
|
|
|
|
* @param string $order Sort order asc/desc (ascending or descending).
|
|
|
|
* @param integer $type
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function sortByKey(&$array, $sortby, $order='asc', $type=SORT_NUMERIC)
|
|
|
|
{
|
|
|
|
if (!is_array($array))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
foreach ($array as $key => $val)
|
|
|
|
{
|
|
|
|
$sa[$key] = $val[$sortby];
|
|
|
|
}
|
|
|
|
|
|
|
|
$order == 'asc'
|
|
|
|
? asort($sa, $type)
|
|
|
|
: arsort($sa, $type);
|
|
|
|
|
|
|
|
foreach ($sa as $key=>$val)
|
|
|
|
{
|
|
|
|
$out[] = $array[$key];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
2005-10-03 04:41:33 +00:00
|
|
|
if (!function_exists('array_combine'))
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
/**
|
|
|
|
* Combines given identical arrays by using the first array's values as keys,
|
|
|
|
* and the second one's values as values. (Implemented for back-compatibility with PHP4.)
|
|
|
|
*
|
|
|
|
* @param array $a1
|
|
|
|
* @param array $a2
|
|
|
|
* @return mixed Outputs either combined array or false.
|
|
|
|
*/
|
|
|
|
function array_combine($a1, $a2)
|
|
|
|
{
|
|
|
|
$a1 = array_values($a1);
|
|
|
|
$a2 = array_values($a2);
|
|
|
|
$c1 = count($a1);
|
|
|
|
$c2 = count($a2);
|
|
|
|
|
|
|
|
if ($c1 != $c2) return false; // different lenghts
|
|
|
|
if ($c1 <= 0) return false; // arrays are the same and both are empty
|
|
|
|
|
|
|
|
$output = array();
|
|
|
|
|
|
|
|
for ($i = 0; $i < $c1; $i++)
|
|
|
|
{
|
|
|
|
$output[$a1[$i]] = $a2[$i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
2005-09-17 02:22:07 +00:00
|
|
|
function h($text)
|
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
return htmlspecialchars($text);
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
|
|
|
|
2005-10-03 04:41:33 +00:00
|
|
|
|
2005-09-17 02:22:07 +00:00
|
|
|
function a()
|
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
return $args;
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
|
|
|
|
2005-10-03 04:41:33 +00:00
|
|
|
|
2005-09-17 02:22:07 +00:00
|
|
|
function ha()
|
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
|
|
|
|
for($l=0 ; $l<count($args) ; $l++)
|
|
|
|
{
|
|
|
|
$a[$args[$l]] = $l+1<count($args) ? $args[$l+1] : null;
|
|
|
|
$l++;
|
|
|
|
}
|
|
|
|
return $a;
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
|
|
|
|
2005-10-03 04:41:33 +00:00
|
|
|
|
2005-09-17 02:22:07 +00:00
|
|
|
function e($text)
|
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
echo $text;
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function pr($var)
|
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
if(DEBUG > 0)
|
|
|
|
{
|
|
|
|
echo "<pre>";
|
|
|
|
print_r($var);
|
|
|
|
echo "</pre>";
|
|
|
|
}
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function params($p)
|
|
|
|
{
|
|
|
|
|
2005-10-03 04:41:33 +00:00
|
|
|
if(!is_array($p) || count($p) == 0)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(is_array($p[0]) && count($p) == 1)
|
|
|
|
{
|
|
|
|
return $p[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $p;
|
|
|
|
}
|
|
|
|
}
|
2005-09-17 02:22:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|