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-12-27 03:33:44 +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/>
|
2006-01-20 07:46:14 +00:00
|
|
|
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
2005-12-23 21:57:26 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-23 21:57:26 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-27 03:33:44 +00:00
|
|
|
* @filesource
|
2006-01-20 07:46:14 +00:00
|
|
|
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
2005-12-23 21:57:26 +00:00
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
2005-08-21 06:49:02 +00:00
|
|
|
* @package cake
|
2005-10-09 01:56:21 +00:00
|
|
|
* @subpackage cake.cake
|
2005-08-21 06:49:02 +00:00
|
|
|
* @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
|
|
|
*/
|
|
|
|
|
2006-03-12 08:56:11 +00:00
|
|
|
|
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);
|
2006-02-18 23:42:21 +00:00
|
|
|
define('HOUR', 60 * MINUTE);
|
2005-06-23 08:32:04 +00:00
|
|
|
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
|
|
|
|
[1285]
Author: phpnut
Date: 10:09:03 PM, Monday, October 31, 2005
Message:
Removed references in the Session class
[1283]
Author: phpnut
Date: 8:47:37 PM, Monday, October 31, 2005
Message:
Added fix to the Controller::constructClassess().
The database should have an instance available if a component will use it.
[1282]
Author: phpnut
Date: 8:36:07 PM, Monday, October 31, 2005
Message:
Updated the Model association methods to correct and error I introduced when reactoring last week.
Added a return from each of the settings in Security::inactiveMins(); This class is not fully implemented.
Updated scaffold and dipatcher with changes to the session class.
Fixed problem with session not working properly.
Added a regenrate id for sessions.
When CAKE_SECURITY is set to high this will regenrate a new session key on each request.
The old session file will be removed from the file system. This is a added security measure.
[1270]
Author: phpnut
Date: 1:55:28 PM, Sunday, October 30, 2005
Message:
Updated Session class to regenrate a new session key on each request when security level set to high.
Updated doc comments in some classes
[1269]
Author: phpnut
Date: 9:49:43 AM, Sunday, October 30, 2005
Message:
Added a fix for Ticket #105
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1286 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-11-01 04:20:28 +00:00
|
|
|
/**
|
|
|
|
* Patch for PHP < 4.3
|
|
|
|
*/
|
2005-12-27 03:33:44 +00:00
|
|
|
if (!function_exists("ob_get_clean"))
|
|
|
|
{
|
|
|
|
function ob_get_clean()
|
[1285]
Author: phpnut
Date: 10:09:03 PM, Monday, October 31, 2005
Message:
Removed references in the Session class
[1283]
Author: phpnut
Date: 8:47:37 PM, Monday, October 31, 2005
Message:
Added fix to the Controller::constructClassess().
The database should have an instance available if a component will use it.
[1282]
Author: phpnut
Date: 8:36:07 PM, Monday, October 31, 2005
Message:
Updated the Model association methods to correct and error I introduced when reactoring last week.
Added a return from each of the settings in Security::inactiveMins(); This class is not fully implemented.
Updated scaffold and dipatcher with changes to the session class.
Fixed problem with session not working properly.
Added a regenrate id for sessions.
When CAKE_SECURITY is set to high this will regenrate a new session key on each request.
The old session file will be removed from the file system. This is a added security measure.
[1270]
Author: phpnut
Date: 1:55:28 PM, Sunday, October 30, 2005
Message:
Updated Session class to regenrate a new session key on each request when security level set to high.
Updated doc comments in some classes
[1269]
Author: phpnut
Date: 9:49:43 AM, Sunday, October 30, 2005
Message:
Added a fix for Ticket #105
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1286 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-11-01 04:20:28 +00:00
|
|
|
{
|
2005-12-27 03:33:44 +00:00
|
|
|
$ob_contents = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
return $ob_contents;
|
[1285]
Author: phpnut
Date: 10:09:03 PM, Monday, October 31, 2005
Message:
Removed references in the Session class
[1283]
Author: phpnut
Date: 8:47:37 PM, Monday, October 31, 2005
Message:
Added fix to the Controller::constructClassess().
The database should have an instance available if a component will use it.
[1282]
Author: phpnut
Date: 8:36:07 PM, Monday, October 31, 2005
Message:
Updated the Model association methods to correct and error I introduced when reactoring last week.
Added a return from each of the settings in Security::inactiveMins(); This class is not fully implemented.
Updated scaffold and dipatcher with changes to the session class.
Fixed problem with session not working properly.
Added a regenrate id for sessions.
When CAKE_SECURITY is set to high this will regenrate a new session key on each request.
The old session file will be removed from the file system. This is a added security measure.
[1270]
Author: phpnut
Date: 1:55:28 PM, Sunday, October 30, 2005
Message:
Updated Session class to regenrate a new session key on each request when security level set to high.
Updated doc comments in some classes
[1269]
Author: phpnut
Date: 9:49:43 AM, Sunday, October 30, 2005
Message:
Added a fix for Ticket #105
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1286 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-11-01 04:20:28 +00:00
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
[1285]
Author: phpnut
Date: 10:09:03 PM, Monday, October 31, 2005
Message:
Removed references in the Session class
[1283]
Author: phpnut
Date: 8:47:37 PM, Monday, October 31, 2005
Message:
Added fix to the Controller::constructClassess().
The database should have an instance available if a component will use it.
[1282]
Author: phpnut
Date: 8:36:07 PM, Monday, October 31, 2005
Message:
Updated the Model association methods to correct and error I introduced when reactoring last week.
Added a return from each of the settings in Security::inactiveMins(); This class is not fully implemented.
Updated scaffold and dipatcher with changes to the session class.
Fixed problem with session not working properly.
Added a regenrate id for sessions.
When CAKE_SECURITY is set to high this will regenrate a new session key on each request.
The old session file will be removed from the file system. This is a added security measure.
[1270]
Author: phpnut
Date: 1:55:28 PM, Sunday, October 30, 2005
Message:
Updated Session class to regenrate a new session key on each request when security level set to high.
Updated doc comments in some classes
[1269]
Author: phpnut
Date: 9:49:43 AM, Sunday, October 30, 2005
Message:
Added a fix for Ticket #105
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1286 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-11-01 04:20:28 +00:00
|
|
|
|
2005-06-23 08:32:04 +00:00
|
|
|
/**
|
|
|
|
* Loads all models.
|
|
|
|
*
|
|
|
|
* @uses listModules()
|
|
|
|
* @uses APP
|
|
|
|
* @uses MODELS
|
|
|
|
*/
|
2006-01-12 02:10:47 +00:00
|
|
|
function loadModels()
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2005-12-27 17:14:32 +00:00
|
|
|
if(!class_exists('AppModel'))
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
|
|
|
if(file_exists(APP.'app_model.php'))
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require(APP.'app_model.php');
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require(CAKE.'app_model.php');
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (phpversion() < 5 && function_exists("overload"))
|
|
|
|
{
|
|
|
|
overload('AppModel');
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (listClasses(MODELS) as $model_fn)
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require (MODELS.$model_fn);
|
2006-01-12 02:10:47 +00:00
|
|
|
if (phpversion() < 5 && function_exists("overload"))
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
list($name) = explode('.', $model_fn);
|
|
|
|
overload(Inflector::camelize($name));
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
2006-02-02 23:01:23 +00:00
|
|
|
/**
|
|
|
|
* Loads a loadPluginController.
|
|
|
|
*
|
|
|
|
* @param string $plugin Name of plugin
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
function loadPluginModels ($plugin)
|
|
|
|
{
|
2006-02-03 03:46:27 +00:00
|
|
|
$pluginAppModel = Inflector::camelize($plugin.'_app_model');
|
|
|
|
$pluginAppModelFile = APP.'plugins'.DS.$plugin.DS.$plugin.'_app_model.php';
|
|
|
|
|
|
|
|
if(!class_exists($pluginAppModel))
|
|
|
|
{
|
|
|
|
if(file_exists($pluginAppModelFile))
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require($pluginAppModelFile);
|
2006-02-03 03:46:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
die('Plugins must have a class named '. $pluginAppModel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phpversion() < 5 && function_exists("overload"))
|
|
|
|
{
|
|
|
|
overload($pluginAppModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
$pluginModelDir = APP.'plugins'.DS.$plugin.DS.'models'.DS;
|
2006-02-02 23:01:23 +00:00
|
|
|
|
|
|
|
foreach (listClasses($pluginModelDir) as $modelFileName)
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require ($pluginModelDir.$modelFileName);
|
2006-02-02 23:01:23 +00:00
|
|
|
if (phpversion() < 5 && function_exists("overload"))
|
|
|
|
{
|
|
|
|
list($name) = explode('.', $modelFileName);
|
|
|
|
overload(Inflector::camelize($name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-01 02:05:01 +00:00
|
|
|
/**
|
|
|
|
* Loads custom view class.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function loadView ($viewClass)
|
|
|
|
{
|
|
|
|
if(!class_exists($viewClass))
|
|
|
|
{
|
|
|
|
$file = Inflector::underscore($viewClass).'.php';
|
|
|
|
if(file_exists(VIEWS.$file))
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
return require(VIEWS.$file);
|
2006-01-01 02:05:01 +00:00
|
|
|
}
|
|
|
|
elseif(file_exists(LIBS.'view'.DS.$file))
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
return require(LIBS.'view'.DS.$file);
|
2006-01-01 02:05:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Loads a model by CamelCase name.
|
|
|
|
*
|
|
|
|
* @uses listModules()
|
|
|
|
* @uses APP
|
|
|
|
* @uses MODELS
|
|
|
|
*/
|
|
|
|
function loadModel($name)
|
|
|
|
{
|
|
|
|
$name = Inflector::underscore($name);
|
|
|
|
|
2006-02-18 23:42:21 +00:00
|
|
|
// Make sure AppModel is loaded
|
2006-01-12 02:10:47 +00:00
|
|
|
if(!class_exists('AppModel'))
|
|
|
|
{
|
|
|
|
if(file_exists(APP.'app_model.php'))
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require(APP.'app_model.php');
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require(CAKE.'app_model.php');
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(file_exists(MODELS.$name.'.php'))
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require (MODELS.$name.'.php');
|
2006-01-12 02:10:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2006-01-01 02:05:01 +00:00
|
|
|
|
2005-06-23 08:32:04 +00:00
|
|
|
/**
|
|
|
|
* Loads all controllers.
|
|
|
|
*
|
|
|
|
* @uses APP
|
|
|
|
* @uses listModules()
|
|
|
|
* @uses HELPERS
|
|
|
|
* @uses CONTROLLERS
|
|
|
|
*/
|
2005-12-27 03:33:44 +00:00
|
|
|
function loadControllers ()
|
|
|
|
{
|
2005-12-27 17:14:32 +00:00
|
|
|
if(!class_exists('AppController'))
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
|
|
|
if(file_exists(APP.'app_controller.php'))
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require(APP.'app_controller.php');
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require(CAKE.'app_controller.php');
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (listClasses(CONTROLLERS) as $controller)
|
|
|
|
{
|
2005-12-27 17:14:32 +00:00
|
|
|
if(!class_exists($controller))
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require (CONTROLLERS.$controller.'.php');
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-01-12 02:10:47 +00:00
|
|
|
* Loads a controller and its helper libraries.
|
|
|
|
*
|
|
|
|
* @param string $name Name of controller
|
|
|
|
* @return boolean Success
|
|
|
|
*/
|
2005-12-27 03:33:44 +00:00
|
|
|
function loadController ($name)
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2005-12-27 17:14:32 +00:00
|
|
|
if(!class_exists('AppController'))
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
|
|
|
if(file_exists(APP.'app_controller.php'))
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require(APP.'app_controller.php');
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require(CAKE.'app_controller.php');
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-01 13:26:23 +00:00
|
|
|
if($name === null)
|
|
|
|
{
|
2006-02-03 04:45:08 +00:00
|
|
|
return true;
|
2006-02-01 13:26:23 +00:00
|
|
|
}
|
2005-12-27 17:14:32 +00:00
|
|
|
if(!class_exists($name.'Controller'))
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
|
|
|
$name = Inflector::underscore($name);
|
|
|
|
if(file_exists(CONTROLLERS.$name.'_controller.php'))
|
|
|
|
{
|
|
|
|
$controller_fn = CONTROLLERS.$name.'_controller.php';
|
|
|
|
}
|
2006-02-16 09:29:28 +00:00
|
|
|
elseif($controller_fn = fileExistsInPath(LIBS.'controller'.DS.$name.'_controller.php'))
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
2006-02-16 09:29:28 +00:00
|
|
|
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-16 09:29:28 +00:00
|
|
|
return false;
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
2006-02-17 10:12:15 +00:00
|
|
|
require($controller_fn);
|
2006-02-16 09:29:28 +00:00
|
|
|
return true;
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
2006-01-02 21:58:12 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
2006-02-01 13:26:23 +00:00
|
|
|
/**
|
|
|
|
* Loads a loadPluginController.
|
|
|
|
*
|
|
|
|
* @param string $plugin Name of plugin
|
|
|
|
* @param string $controller Name of controller to load
|
|
|
|
* @return boolean Success
|
|
|
|
*/
|
|
|
|
function loadPluginController ($plugin, $controller)
|
|
|
|
{
|
2006-02-03 03:46:27 +00:00
|
|
|
|
|
|
|
$pluginAppController = Inflector::camelize($plugin.'_app_controller');
|
|
|
|
$pluginAppControllerFile = APP.'plugins'.DS.$plugin.DS.$plugin.'_app_controller.php';
|
|
|
|
|
|
|
|
if(!class_exists($pluginAppController))
|
2006-02-03 02:37:59 +00:00
|
|
|
{
|
2006-02-03 03:46:27 +00:00
|
|
|
if(file_exists($pluginAppControllerFile))
|
2006-02-03 02:37:59 +00:00
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
require($pluginAppControllerFile);
|
2006-02-03 02:37:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-03 07:12:40 +00:00
|
|
|
return false;
|
2006-02-03 02:37:59 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-01 13:26:23 +00:00
|
|
|
|
2006-02-18 23:42:21 +00:00
|
|
|
if(empty($controller))
|
|
|
|
{
|
|
|
|
if(file_exists(APP.'plugins'.DS.$plugin.DS.'controllers'.DS.$plugin.'_controller.php'))
|
|
|
|
{
|
|
|
|
require(APP.'plugins'.DS.$plugin.DS.'controllers'.DS.$plugin.'_controller.php');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-01 13:26:23 +00:00
|
|
|
if(!class_exists($controller.'Controller'))
|
|
|
|
{
|
|
|
|
$controller = Inflector::underscore($controller);
|
|
|
|
$file = APP.'plugins'.DS.$plugin.DS.'controllers'.DS.$controller.'_controller.php';
|
2006-02-18 23:42:21 +00:00
|
|
|
if(file_exists($file))
|
2006-02-01 13:26:23 +00:00
|
|
|
{
|
2006-02-18 23:42:21 +00:00
|
|
|
require($file);
|
|
|
|
return true;
|
2006-02-01 13:26:23 +00:00
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
elseif(file_exists(APP.'plugins'.DS.$plugin.DS.'controllers'.DS.$plugin.'_controller.php'))
|
2006-02-01 13:26:23 +00:00
|
|
|
{
|
2006-02-18 23:42:21 +00:00
|
|
|
require(APP.'plugins'.DS.$plugin.DS.'controllers'.DS.$plugin.'_controller.php');
|
2006-02-01 13:26:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-02-16 09:29:28 +00:00
|
|
|
}
|
2006-02-01 13:26:23 +00:00
|
|
|
}
|
|
|
|
|
2005-06-23 08:32:04 +00:00
|
|
|
/**
|
2006-01-12 02:10:47 +00:00
|
|
|
* Returns an array of filenames of PHP files in given directory.
|
|
|
|
*
|
|
|
|
* @param string $path Path to scan for files
|
|
|
|
* @return array List of files in directory
|
|
|
|
*/
|
2005-12-27 03:33:44 +00:00
|
|
|
function listClasses($path)
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
$dir = opendir($path);
|
2006-01-13 07:09:02 +00:00
|
|
|
$classes = array();
|
2006-01-12 02:10:47 +00:00
|
|
|
while (false !== ($file = readdir($dir)))
|
|
|
|
{
|
|
|
|
if ((substr($file, -3, 3) == 'php'))
|
|
|
|
{
|
|
|
|
$classes[] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dir);
|
|
|
|
return $classes;
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-01-12 02:10:47 +00:00
|
|
|
* Loads configuration files
|
|
|
|
*
|
|
|
|
* @return boolean Success
|
|
|
|
*/
|
|
|
|
function config()
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
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
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
foreach ($args as $arg)
|
|
|
|
{
|
|
|
|
require_once(LIBS.low($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
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
foreach ($args as $arg)
|
|
|
|
{
|
2006-02-01 13:26:23 +00:00
|
|
|
if(file_exists(APP.'vendors'.DS.$arg.'.php'))
|
|
|
|
{
|
2006-02-28 19:45:28 +00:00
|
|
|
require_once(APP.'vendors'.DS.$arg.'.php');
|
2006-02-01 13:26:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-28 19:45:28 +00:00
|
|
|
require_once(VENDORS.$arg.'.php');
|
2006-02-01 13:26:23 +00:00
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-01-12 02:10:47 +00:00
|
|
|
* Prints out debug information about given variable.
|
2005-09-17 02:22:07 +00:00
|
|
|
*
|
|
|
|
* Only runs if DEBUG level is non-zero.
|
2005-06-23 08:32:04 +00:00
|
|
|
*
|
2005-12-27 03:33:44 +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
|
|
|
*/
|
2006-01-12 02:10:47 +00:00
|
|
|
function debug($var = false, $showHtml = false)
|
2005-06-23 08:32:04 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
if (DEBUG)
|
|
|
|
{
|
|
|
|
print "\n<pre>\n";
|
|
|
|
ob_start();
|
|
|
|
print_r($var);
|
|
|
|
$var = ob_get_clean();
|
|
|
|
|
|
|
|
if ($showHtml)
|
|
|
|
{
|
|
|
|
$var = str_replace('<', '<', str_replace('>', '>', $var));
|
|
|
|
}
|
|
|
|
|
|
|
|
print "{$var}\n</pre>\n";
|
2006-02-18 23:42:21 +00:00
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
2005-12-27 03:33:44 +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
|
|
|
|
*/
|
2006-02-18 23:42:21 +00:00
|
|
|
function getMicrotime()
|
|
|
|
{
|
2005-10-03 04:41:33 +00:00
|
|
|
list($usec, $sec) = explode(" ", microtime());
|
|
|
|
return ((float)$usec + (float)$sec);
|
2006-02-18 23:42:21 +00:00
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
2005-12-27 03:33:44 +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.
|
|
|
|
*
|
2006-02-18 23:42:21 +00:00
|
|
|
* @param array $array
|
2006-01-12 02:10:47 +00:00
|
|
|
* @param string $sortby
|
|
|
|
* @param string $order Sort order asc/desc (ascending or descending).
|
|
|
|
* @param integer $type
|
2005-10-03 04:41:33 +00:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2006-01-12 02:10:47 +00:00
|
|
|
function sortByKey(&$array, $sortby, $order='asc', $type=SORT_NUMERIC)
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
if (!is_array($array))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
2005-12-27 03:33:44 +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,
|
2006-01-12 02:10:47 +00:00
|
|
|
* and the second one's values as values. (Implemented for back-compatibility
|
|
|
|
* with PHP4)
|
2005-10-03 04:41:33 +00:00
|
|
|
*
|
2006-01-12 02:10:47 +00:00
|
|
|
* @param array $a1
|
|
|
|
* @param array $a2
|
2005-10-03 04:41:33 +00:00
|
|
|
* @return mixed Outputs either combined array or false.
|
|
|
|
*/
|
2006-01-12 02:10:47 +00:00
|
|
|
function array_combine($a1, $a2)
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
$a1 = array_values($a1);
|
|
|
|
$a2 = array_values($a2);
|
|
|
|
$c1 = count($a1);
|
|
|
|
$c2 = count($a2);
|
2005-12-27 03:33:44 +00:00
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
if ($c1 != $c2)
|
|
|
|
{
|
2006-02-18 23:42:21 +00:00
|
|
|
return false;// different lenghts
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
if ($c1 <= 0)
|
|
|
|
{
|
2006-02-18 23:42:21 +00:00
|
|
|
return false;// arrays are the same and both are empty
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = array();
|
|
|
|
|
|
|
|
for ($i = 0; $i < $c1; $i++)
|
|
|
|
{
|
|
|
|
$output[$a1[$i]] = $a2[$i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
}
|
|
|
|
|
2005-10-09 01:56:21 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Convenience method for htmlspecialchars.
|
2005-10-09 01:56:21 +00:00
|
|
|
*
|
2005-10-18 22:27:39 +00:00
|
|
|
* @param string $text
|
|
|
|
* @return string
|
2005-10-09 01:56:21 +00:00
|
|
|
*/
|
2005-09-17 02:22:07 +00:00
|
|
|
function h($text)
|
|
|
|
{
|
2005-12-27 03:33:44 +00:00
|
|
|
return htmlspecialchars($text);
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
|
|
|
|
2005-10-09 01:56:21 +00:00
|
|
|
/**
|
2006-01-12 02:10:47 +00:00
|
|
|
* Returns an array of all the given parameters.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* <code>
|
|
|
|
* a('a', 'b')
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* Would return:
|
|
|
|
* <code>
|
|
|
|
* array('a', 'b')
|
|
|
|
* </code>
|
2005-10-09 01:56:21 +00:00
|
|
|
*
|
2005-10-18 22:27:39 +00:00
|
|
|
* @return array
|
2005-10-09 01:56:21 +00:00
|
|
|
*/
|
2005-09-17 02:22:07 +00:00
|
|
|
function a()
|
|
|
|
{
|
2005-12-27 03:33:44 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
return $args;
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
|
|
|
|
2005-10-09 01:56:21 +00:00
|
|
|
/**
|
2006-01-12 02:10:47 +00:00
|
|
|
* Constructs associative array from pairs of arguments.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* <code>
|
|
|
|
* aa('a','b')
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* Would return:
|
|
|
|
* <code>
|
|
|
|
* array('a'=>'b')
|
|
|
|
* </code>
|
2005-10-09 01:56:21 +00:00
|
|
|
*
|
2005-10-18 22:27:39 +00:00
|
|
|
* @return array
|
2005-10-09 01:56:21 +00:00
|
|
|
*/
|
2006-01-12 02:10:47 +00:00
|
|
|
function aa()
|
2005-09-17 02:22:07 +00:00
|
|
|
{
|
2005-12-27 03:33:44 +00:00
|
|
|
$args = func_get_args();
|
2005-10-03 04:41:33 +00:00
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
for ($l = 0, $c = count($args); $l < $c; $l++)
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
if ($l+1 < count($args))
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
$a[$args[$l]] = $args[$l+1];
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
$a[$args[$l]] = null;
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
$l++;
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
|
|
|
return $a;
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* @deprecated Renamed to aa(). Version 0.10.
|
|
|
|
*/
|
|
|
|
function ha()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
return call_user_func_array('aa', $args);
|
|
|
|
}
|
|
|
|
|
2005-10-09 01:56:21 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Convenience method for echo().
|
2005-10-09 01:56:21 +00:00
|
|
|
*
|
2005-10-18 22:27:39 +00:00
|
|
|
* @param string $text String to echo
|
2005-10-09 01:56:21 +00:00
|
|
|
*/
|
2005-09-17 02:22:07 +00:00
|
|
|
function e($text)
|
|
|
|
{
|
2005-12-27 03:33:44 +00:00
|
|
|
echo $text;
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Convenience method for strtolower().
|
|
|
|
*
|
|
|
|
* @param string $str String to lowercase
|
|
|
|
*/
|
|
|
|
function low($str)
|
|
|
|
{
|
|
|
|
return strtolower($str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method for strtoupper().
|
|
|
|
*
|
|
|
|
* @param string $str String to uppercase
|
|
|
|
*/
|
|
|
|
function up($str)
|
|
|
|
{
|
|
|
|
return strtoupper($str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method for str_replace().
|
|
|
|
*
|
|
|
|
* @param string $search String to be replaced
|
|
|
|
* @param string $replace String to insert
|
|
|
|
* @param string $subject String to search
|
|
|
|
*/
|
|
|
|
function r($search, $replace, $subject)
|
|
|
|
{
|
|
|
|
return str_replace($search, $replace, $subject);
|
|
|
|
}
|
|
|
|
|
2005-10-09 01:56:21 +00:00
|
|
|
/**
|
2005-12-27 03:33:44 +00:00
|
|
|
* Print_r convenience function, which prints out <PRE> tags around
|
2005-10-18 22:27:39 +00:00
|
|
|
* the output of given array. Similar to debug().
|
2005-12-27 03:33:44 +00:00
|
|
|
*
|
2006-02-18 23:42:21 +00:00
|
|
|
* @see debug()
|
|
|
|
* @param array $var
|
2005-10-09 01:56:21 +00:00
|
|
|
*/
|
2005-09-17 02:22:07 +00:00
|
|
|
function pr($var)
|
|
|
|
{
|
2005-12-27 03:33:44 +00:00
|
|
|
if(DEBUG > 0)
|
|
|
|
{
|
|
|
|
echo "<pre>";
|
|
|
|
print_r($var);
|
|
|
|
echo "</pre>";
|
|
|
|
}
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
|
|
|
|
2005-10-09 01:56:21 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Display parameter
|
2005-10-09 01:56:21 +00:00
|
|
|
*
|
2006-01-12 02:10:47 +00:00
|
|
|
* @param mixed $p Parameter as string or array
|
2005-10-18 22:27:39 +00:00
|
|
|
* @return string
|
2005-10-09 01:56:21 +00:00
|
|
|
*/
|
2005-09-17 02:22:07 +00:00
|
|
|
function params($p)
|
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
if (!is_array($p) || count($p) == 0)
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
if (is_array($p[0]) && count($p) == 1)
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
|
|
|
return $p[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $p;
|
|
|
|
}
|
|
|
|
}
|
2006-03-12 00:11:40 +00:00
|
|
|
}
|
|
|
|
|
2005-09-17 02:22:07 +00:00
|
|
|
|
2006-03-12 00:11:40 +00:00
|
|
|
/**
|
|
|
|
* Merge a group of arrays
|
|
|
|
*
|
|
|
|
* @param array First array
|
|
|
|
* @param array Second array
|
|
|
|
* @param array Third array
|
|
|
|
* @param array Etc...
|
|
|
|
* @return array All array parameters merged into one
|
|
|
|
*/
|
|
|
|
function am ()
|
|
|
|
{
|
|
|
|
$r = array();
|
|
|
|
foreach (func_get_args() as $a)
|
|
|
|
{
|
|
|
|
if (!is_array($a))
|
|
|
|
{
|
|
|
|
$a = array($a);
|
|
|
|
}
|
|
|
|
$r = array_merge($r, $a);
|
|
|
|
}
|
|
|
|
return $r;
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
|
|
|
|
2005-10-09 01:56:21 +00:00
|
|
|
/**
|
2006-01-12 02:10:47 +00:00
|
|
|
* Returns the REQUEST_URI from the server environment, or, failing that,
|
|
|
|
* constructs a new one, using the PHP_SELF constant and other variables.
|
2005-10-09 01:56:21 +00:00
|
|
|
*
|
2006-01-12 02:10:47 +00:00
|
|
|
* @return string URI
|
2005-10-09 01:56:21 +00:00
|
|
|
*/
|
2005-12-27 03:33:44 +00:00
|
|
|
function setUri()
|
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
if (env('REQUEST_URI'))
|
2005-10-03 04:48:00 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
$uri = env('REQUEST_URI');
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
if (env('argv'))
|
2005-10-03 04:48:00 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
$uri = env('argv');
|
|
|
|
$uri = env('PHP_SELF') .'/'. $uri[0];
|
2005-10-03 04:48:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
$uri = env('PHP_SELF') .'/'. env('QUERY_STRING');
|
2005-10-03 04:48:00 +00:00
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
|
|
|
return $uri;
|
|
|
|
}
|
2006-01-06 04:46:42 +00:00
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Gets an environment variable from available sources.
|
|
|
|
* Used as a backup if $_SERVER/$_ENV are disabled.
|
|
|
|
*
|
|
|
|
* @param string $key Environment variable name.
|
|
|
|
* @return string Environment variable setting.
|
|
|
|
*/
|
|
|
|
function env($key)
|
2006-01-06 04:46:42 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
if (isset($_SERVER[$key]))
|
|
|
|
{
|
|
|
|
return $_SERVER[$key];
|
|
|
|
}
|
|
|
|
elseif (isset($_ENV[$key]))
|
|
|
|
{
|
|
|
|
return $_ENV[$key];
|
|
|
|
}
|
|
|
|
elseif (getenv($key) !== false)
|
|
|
|
{
|
|
|
|
return getenv($key);
|
|
|
|
}
|
2006-01-25 22:40:17 +00:00
|
|
|
if ($key == 'DOCUMENT_ROOT')
|
|
|
|
{
|
|
|
|
$offset = 0;
|
|
|
|
if (!strpos(env('SCRIPT_NAME'), '.php'))
|
|
|
|
{
|
|
|
|
$offset = 4;
|
|
|
|
}
|
|
|
|
return substr(env('SCRIPT_FILENAME'), 0, strlen(env('SCRIPT_FILENAME')) - (strlen(env('SCRIPT_NAME')) + $offset));
|
|
|
|
}
|
|
|
|
if ($key == 'PHP_SELF')
|
|
|
|
{
|
|
|
|
return r(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('file_get_contents'))
|
|
|
|
{
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
|
|
|
* Returns contents of a file as a string.
|
|
|
|
*
|
|
|
|
* @param string $fileName Name of the file.
|
|
|
|
* @param boolean $useIncludePath Wheter the function should use the
|
|
|
|
* include path or not.
|
|
|
|
* @return mixed Boolean false or contents of required file.
|
|
|
|
*/
|
2006-01-12 02:10:47 +00:00
|
|
|
function file_get_contents($fileName, $useIncludePath = false)
|
|
|
|
{
|
|
|
|
$res = fopen($fileName, 'rb', $useIncludePath);
|
|
|
|
if ($res === false)
|
|
|
|
{
|
|
|
|
trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearstatcache();
|
|
|
|
|
|
|
|
if ($fileSize = @filesize($fileName))
|
|
|
|
{
|
|
|
|
$data = fread($res, $fileSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$data = '';
|
|
|
|
while (!feof($res))
|
|
|
|
{
|
|
|
|
$data .= fread($res, 8192);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "$data\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('file_put_contents'))
|
|
|
|
{
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
|
|
|
* Writes data into file.
|
|
|
|
*
|
|
|
|
* If file exists, it will be overwritten. If data is an array, it will be
|
|
|
|
* join()ed with an empty string.
|
|
|
|
*
|
|
|
|
* @param string $fileName File name.
|
|
|
|
* @param mixed $data String or array.
|
|
|
|
*/
|
2006-01-12 02:10:47 +00:00
|
|
|
function file_put_contents($fileName, $data)
|
|
|
|
{
|
|
|
|
if (is_array($data))
|
|
|
|
{
|
|
|
|
$data = join('', $data);
|
|
|
|
}
|
2006-01-22 05:12:28 +00:00
|
|
|
$res = @fopen($fileName, 'w+b');
|
2006-01-12 02:10:47 +00:00
|
|
|
if ($res)
|
|
|
|
{
|
|
|
|
@fwrite($res, $data);
|
|
|
|
}
|
|
|
|
}
|
2006-01-06 04:46:42 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Reads/writes temporary data to cache files or session.
|
|
|
|
*
|
|
|
|
* @param string $path File path within /tmp to save the file.
|
|
|
|
* @param mixed $data The data to save to the temporary file.
|
|
|
|
* @param mixed $expires A valid strtotime string when the data expires.
|
|
|
|
* @param string $target The target of the cached data; either 'cache' or 'public'.
|
|
|
|
* @return mixed The contents of the temporary file.
|
|
|
|
*/
|
|
|
|
function cache($path, $data = null, $expires = '+1 day', $target = 'cache')
|
|
|
|
{
|
2006-03-12 00:11:40 +00:00
|
|
|
if (!is_numeric($expires))
|
2006-01-12 02:10:47 +00:00
|
|
|
{
|
|
|
|
$expires = strtotime($expires);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (low($target))
|
|
|
|
{
|
|
|
|
case 'cache':
|
|
|
|
$filename = CACHE . $path;
|
|
|
|
break;
|
|
|
|
case 'public':
|
|
|
|
$filename = WWW_ROOT . $path;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$now = time();
|
|
|
|
$timediff = $expires - $now;
|
|
|
|
$filetime = @filemtime($filename);
|
|
|
|
|
|
|
|
if ($data == null)
|
|
|
|
{
|
2006-02-18 23:42:21 +00:00
|
|
|
// Read data from file
|
2006-01-12 02:10:47 +00:00
|
|
|
if (file_exists($filename) && $filetime !== false)
|
|
|
|
{
|
|
|
|
if ($filetime + $timediff < $now)
|
|
|
|
{
|
2006-02-18 23:42:21 +00:00
|
|
|
// File has expired
|
2006-01-12 02:10:47 +00:00
|
|
|
@unlink($filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$data = file_get_contents($filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file_put_contents($filename, $data);
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2006-03-12 05:56:07 +00:00
|
|
|
/**
|
|
|
|
* Used to delete files in the cache directories, or clear contents of cache directories
|
|
|
|
*
|
|
|
|
* @param mixed $params As String name to be searched for deletion, if name is a directory all files in directory will be deleted.
|
|
|
|
* If array, names to be searched for deletion.
|
|
|
|
* If clearCache() without params, all files in app/tmp/cache/views will be deleted
|
|
|
|
*
|
|
|
|
* @param string $type Directory in tmp/cache defaults to view directory
|
|
|
|
* @param string $ext The file extension you are deleting
|
|
|
|
* @return true if files found and deleted false otherwise
|
|
|
|
*/
|
|
|
|
function clearCache($params = null, $type = 'views', $ext = '.php')
|
|
|
|
{
|
|
|
|
if(is_string($params) || $params === null)
|
|
|
|
{
|
2006-03-12 18:32:09 +00:00
|
|
|
$params = preg_replace('/\/\//', '/', $params);
|
2006-03-12 05:56:07 +00:00
|
|
|
$cache = CACHE.$type.DS.$params;
|
|
|
|
if(is_file($cache.$ext))
|
|
|
|
{
|
2006-03-12 09:31:36 +00:00
|
|
|
@unlink($cache.$ext);
|
|
|
|
return true;
|
2006-03-12 05:56:07 +00:00
|
|
|
}
|
|
|
|
else if(is_dir($cache))
|
|
|
|
{
|
|
|
|
$files = glob("$cache*");
|
|
|
|
if ($files === false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-03-12 09:31:36 +00:00
|
|
|
|
|
|
|
foreach($files as $file)
|
|
|
|
{
|
|
|
|
if(is_file($file))
|
|
|
|
{
|
|
|
|
@unlink($file);
|
|
|
|
}
|
|
|
|
}
|
2006-03-12 05:56:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$cache = CACHE.$type.DS.'*'.$params.'*'.$ext;
|
|
|
|
$files = glob($cache);
|
|
|
|
if ($files === false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-03-12 09:31:36 +00:00
|
|
|
foreach($files as $file)
|
|
|
|
{
|
|
|
|
if(is_file($file))
|
|
|
|
{
|
|
|
|
@unlink($file);
|
|
|
|
}
|
|
|
|
}
|
2006-03-12 05:56:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(is_array($params))
|
|
|
|
{
|
|
|
|
foreach ($params as $key => $file)
|
|
|
|
{
|
2006-03-12 18:32:09 +00:00
|
|
|
$file = preg_replace('/\/\//', '/', $file);
|
2006-03-12 05:56:07 +00:00
|
|
|
$cache = CACHE.$type.DS.'*'.$file.'*'.$ext;
|
|
|
|
$files[] = glob($cache);
|
|
|
|
}
|
|
|
|
if(!empty($files))
|
|
|
|
{
|
|
|
|
foreach ($files as $key => $delete)
|
|
|
|
{
|
2006-03-12 08:56:11 +00:00
|
|
|
if(is_array($delete))
|
|
|
|
{
|
2006-03-12 09:31:36 +00:00
|
|
|
foreach($delete as $file)
|
|
|
|
{
|
|
|
|
if(is_file($file))
|
|
|
|
{
|
|
|
|
@unlink($file);
|
|
|
|
}
|
|
|
|
}
|
2006-03-12 08:56:11 +00:00
|
|
|
}
|
2006-03-12 05:56:07 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-03-13 03:48:39 +00:00
|
|
|
* Recursively strips slashes from all values in an array
|
2006-03-12 05:56:07 +00:00
|
|
|
*
|
|
|
|
* @param unknown_type $value
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2006-01-12 16:55:46 +00:00
|
|
|
function stripslashes_deep($value)
|
|
|
|
{
|
2006-03-13 03:48:39 +00:00
|
|
|
if (is_array($value))
|
|
|
|
{
|
|
|
|
return array_map('stripslashes_deep', $value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return stripslashes($value);
|
|
|
|
}
|
2006-01-12 16:55:46 +00:00
|
|
|
}
|
2006-03-12 08:56:11 +00:00
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Returns a translated string if one is found,
|
|
|
|
* or the submitted message if not found.
|
|
|
|
*
|
|
|
|
* @param unknown_type $msg
|
|
|
|
* @param unknown_type $return
|
|
|
|
* @return unknown
|
|
|
|
* @todo Not implemented in 0.10.x.x
|
|
|
|
*/
|
2006-03-12 00:11:40 +00:00
|
|
|
function __($msg, $return = null)
|
|
|
|
{
|
|
|
|
if(is_null($return))
|
|
|
|
{
|
|
|
|
echo ($msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
}
|
2006-02-02 11:48:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Counts the dimensions of an array
|
|
|
|
*
|
|
|
|
* @param array $array
|
|
|
|
* @return int The number of dimensions in $array
|
|
|
|
*/
|
|
|
|
function countdim($array)
|
|
|
|
{
|
|
|
|
if (is_array(reset($array)))
|
|
|
|
{
|
2006-02-02 13:51:43 +00:00
|
|
|
$return = countdim(reset($array)) + 1;
|
2006-02-02 11:48:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$return = 1;
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2006-02-08 15:25:34 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Shortcut to Log::write.
|
|
|
|
*/
|
2006-02-08 15:25:34 +00:00
|
|
|
function LogError ($message)
|
|
|
|
{
|
|
|
|
if(!class_exists('CakeLog'))
|
|
|
|
{
|
|
|
|
uses('cake_log');
|
|
|
|
}
|
|
|
|
|
|
|
|
$bad = array("\n", "\r", "\t");
|
|
|
|
$good = ' ';
|
|
|
|
CakeLog::write('error', str_replace($bad, $good, $message));
|
|
|
|
}
|
|
|
|
|
2006-03-12 05:56:07 +00:00
|
|
|
/**
|
|
|
|
* Searches include path for files
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @return Full path to file if exists, otherwise false
|
|
|
|
*/
|
2006-02-16 09:29:28 +00:00
|
|
|
function fileExistsInPath ($file)
|
|
|
|
{
|
|
|
|
$paths = explode(PATH_SEPARATOR, get_include_path());
|
|
|
|
foreach ($paths as $path)
|
|
|
|
{
|
|
|
|
$fullPath = $path . DIRECTORY_SEPARATOR . $file;
|
|
|
|
if (file_exists($fullPath))
|
|
|
|
{
|
|
|
|
return $fullPath;
|
|
|
|
}
|
2006-02-25 19:20:18 +00:00
|
|
|
elseif (file_exists($file))
|
|
|
|
{
|
|
|
|
return $file;
|
|
|
|
}
|
2006-02-16 09:29:28 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-09-17 02:22:07 +00:00
|
|
|
?>
|