2006-10-18 17:51:29 +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
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
2006-05-26 05:29:17 +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
|
2007-02-02 10:39:45 +00:00
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake
|
2007-02-02 10:39:45 +00:00
|
|
|
* @since CakePHP(tm) v 0.2.9
|
2006-05-26 05:29:17 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @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
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
define('SECOND', 1);
|
|
|
|
define('MINUTE', 60 * SECOND);
|
|
|
|
define('HOUR', 60 * MINUTE);
|
|
|
|
define('DAY', 24 * HOUR);
|
|
|
|
define('WEEK', 7 * DAY);
|
|
|
|
define('MONTH', 30 * DAY);
|
|
|
|
define('YEAR', 365 * DAY);
|
[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
|
|
|
/**
|
2006-10-19 00:37:29 +00:00
|
|
|
* Patch for PHP < 5.0
|
[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
|
|
|
*/
|
2006-10-19 00:37:29 +00:00
|
|
|
if (version_compare(phpversion(), '5.0') < 0) {
|
|
|
|
eval ('
|
|
|
|
function clone($object)
|
|
|
|
{
|
|
|
|
return $object;
|
|
|
|
}');
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
/**
|
|
|
|
* Loads all models.
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function loadModels() {
|
2007-06-20 07:51:52 +00:00
|
|
|
if (!class_exists('Model')) {
|
2006-11-21 21:48:05 +00:00
|
|
|
require LIBS . 'model' . DS . 'model.php';
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
$path = Configure::getInstance();
|
|
|
|
if (!class_exists('AppModel')) {
|
|
|
|
if (file_exists(APP . 'app_model.php')) {
|
|
|
|
require(APP . 'app_model.php');
|
|
|
|
} else {
|
|
|
|
require(CAKE . 'app_model.php');
|
|
|
|
}
|
2006-11-05 06:56:28 +00:00
|
|
|
Overloadable::overload('AppModel');
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-01-22 08:10:43 +00:00
|
|
|
$loadedModels = array();
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($path->modelPaths as $path) {
|
|
|
|
foreach (listClasses($path) as $model_fn) {
|
2006-11-22 21:32:59 +00:00
|
|
|
list($name) = explode('.', $model_fn);
|
|
|
|
$className = Inflector::camelize($name);
|
2007-01-22 08:10:43 +00:00
|
|
|
$loadedModels[$model_fn] = $model_fn;
|
2006-11-22 21:32:59 +00:00
|
|
|
|
|
|
|
if (!class_exists($className)) {
|
2006-05-26 05:29:17 +00:00
|
|
|
require($path . $model_fn);
|
2006-07-30 12:24:03 +00:00
|
|
|
list($name) = explode('.', $model_fn);
|
2006-11-05 06:56:28 +00:00
|
|
|
Overloadable::overload(Inflector::camelize($name));
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-01-21 22:55:58 +00:00
|
|
|
return $loadedModels;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-02-02 23:01:23 +00:00
|
|
|
/**
|
2006-11-05 06:29:15 +00:00
|
|
|
* Loads all plugin models.
|
2006-02-02 23:01:23 +00:00
|
|
|
*
|
|
|
|
* @param string $plugin Name of plugin
|
2007-05-26 09:50:17 +00:00
|
|
|
* @deprecated
|
2006-02-02 23:01:23 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function loadPluginModels($plugin) {
|
2007-06-20 07:51:52 +00:00
|
|
|
if (!class_exists('AppModel')) {
|
2006-11-25 20:30:17 +00:00
|
|
|
loadModel();
|
|
|
|
}
|
2007-02-09 02:38:19 +00:00
|
|
|
|
2006-05-26 05:29:17 +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)) {
|
|
|
|
require($pluginAppModelFile);
|
2007-02-09 02:38:19 +00:00
|
|
|
Overloadable::overload($pluginAppModel);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$pluginModelDir = APP . 'plugins' . DS . $plugin . DS . 'models' . DS;
|
2007-06-20 06:15:35 +00:00
|
|
|
if (is_dir($pluginModelDir)) {
|
|
|
|
foreach (listClasses($pluginModelDir)as $modelFileName) {
|
2007-02-09 02:38:19 +00:00
|
|
|
list($name) = explode('.', $modelFileName);
|
|
|
|
$className = Inflector::camelize($name);
|
2006-07-30 12:24:03 +00:00
|
|
|
|
2007-02-09 02:38:19 +00:00
|
|
|
if (!class_exists($className)) {
|
|
|
|
require($pluginModelDir . $modelFileName);
|
|
|
|
Overloadable::overload($className);
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-01-01 02:05:01 +00:00
|
|
|
/**
|
2007-06-19 13:20:34 +00:00
|
|
|
* Loads custom view class. Use dot notation to load a view class
|
|
|
|
* from a plugin, e.g: plugin.MyView
|
2006-01-01 02:05:01 +00:00
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param string $viewClass Name of the view class to load (camelized)
|
|
|
|
* @return boolean Success
|
2006-01-01 02:05:01 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function loadView($viewClass) {
|
2007-06-20 07:51:52 +00:00
|
|
|
if (strpos($viewClass, '.') !== false) {
|
2007-05-26 09:50:17 +00:00
|
|
|
list($plugin, $viewClass) = explode('.', $viewClass);
|
2007-05-29 13:21:22 +00:00
|
|
|
$file = APP . 'plugins' . DS . Inflector::underscore($plugin) . DS . 'views' . DS . Inflector::underscore($viewClass) . '.php';
|
2007-05-27 19:54:36 +00:00
|
|
|
if (file_exists($file)) {
|
|
|
|
require($file);
|
|
|
|
return true;
|
|
|
|
}
|
2007-05-26 09:50:17 +00:00
|
|
|
}
|
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if (!class_exists($viewClass . 'View')) {
|
|
|
|
$paths = Configure::getInstance();
|
|
|
|
$file = Inflector::underscore($viewClass) . '.php';
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($paths->viewPaths as $path) {
|
2006-05-26 05:29:17 +00:00
|
|
|
if (file_exists($path . $file)) {
|
|
|
|
return require($path . $file);
|
|
|
|
}
|
|
|
|
}
|
2006-01-01 02:05:01 +00:00
|
|
|
|
2006-07-29 04:51:29 +00:00
|
|
|
if ($viewFile = fileExistsInPath(LIBS . 'view' . DS . $file)) {
|
|
|
|
if (file_exists($viewFile)) {
|
|
|
|
require($viewFile);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-26 09:50:17 +00:00
|
|
|
return true;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2007-06-19 13:20:34 +00:00
|
|
|
* Loads a model by CamelCase name if specified, otherwise load model
|
|
|
|
* basic requirements (model and AppModel classes). Use dot notation
|
|
|
|
* to load a model located inside a plugin folder.
|
|
|
|
*
|
|
|
|
* @param $name Name of model to load
|
|
|
|
* @return boolean Success
|
2006-01-12 02:10:47 +00:00
|
|
|
*/
|
2006-11-23 21:39:09 +00:00
|
|
|
function loadModel($name = null) {
|
2007-06-20 07:51:52 +00:00
|
|
|
if (!class_exists('Model')) {
|
2006-11-21 21:48:05 +00:00
|
|
|
require LIBS . 'model' . DS . 'model.php';
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
if (!class_exists('AppModel')) {
|
|
|
|
if (file_exists(APP . 'app_model.php')) {
|
|
|
|
require(APP . 'app_model.php');
|
|
|
|
} else {
|
|
|
|
require(CAKE . 'app_model.php');
|
|
|
|
}
|
2006-11-05 06:29:15 +00:00
|
|
|
Overloadable::overload('AppModel');
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
2007-06-20 07:51:52 +00:00
|
|
|
if (strpos($name, '.') !== false) {
|
2007-01-13 21:36:10 +00:00
|
|
|
list($plugin, $name) = explode('.', $name);
|
2007-05-27 02:32: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)) {
|
|
|
|
require($pluginAppModelFile);
|
|
|
|
Overloadable::overload($pluginAppModel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!class_exists($name)) {
|
|
|
|
$className = $name;
|
|
|
|
$name = Inflector::underscore($name);
|
|
|
|
$path = APP . 'plugins' . DS . $plugin . DS . 'models' . DS;
|
|
|
|
if (file_exists($path . $name . '.php')) {
|
|
|
|
require($path . $name . '.php');
|
|
|
|
Overloadable::overload($className);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2007-01-13 21:36:10 +00:00
|
|
|
}
|
|
|
|
|
2006-11-23 21:39:09 +00:00
|
|
|
if (!is_null($name) && !class_exists($name)) {
|
2006-11-05 06:29:15 +00:00
|
|
|
$className = $name;
|
|
|
|
$name = Inflector::underscore($name);
|
2007-01-09 22:32:48 +00:00
|
|
|
$models = Configure::read('Models');
|
2007-06-20 06:15:35 +00:00
|
|
|
if (is_array($models)) {
|
|
|
|
if (array_key_exists($className, $models)) {
|
2007-01-13 21:08:52 +00:00
|
|
|
require($models[$className]['path']);
|
|
|
|
Overloadable::overload($className);
|
|
|
|
return true;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (isset($models['Core']) && array_key_exists($className, $models['Core'])) {
|
2007-01-13 21:08:52 +00:00
|
|
|
require($models['Core'][$className]['path']);
|
2007-01-09 22:32:48 +00:00
|
|
|
Overloadable::overload($className);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2006-11-05 06:29:15 +00:00
|
|
|
|
2007-01-09 22:32:48 +00:00
|
|
|
$paths = Configure::getInstance();
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($paths->modelPaths as $path) {
|
2006-11-05 06:29:15 +00:00
|
|
|
if (file_exists($path . $name . '.php')) {
|
2007-01-13 21:08:52 +00:00
|
|
|
Configure::store('Models', 'class.paths', array($className => array('path' => $path . $name . '.php')));
|
2006-11-05 06:29:15 +00:00
|
|
|
require($path . $name . '.php');
|
2006-11-05 06:56:28 +00:00
|
|
|
Overloadable::overload($className);
|
2006-11-05 06:29:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-11-05 06:29:15 +00:00
|
|
|
return false;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-05-26 09:50:17 +00:00
|
|
|
return true;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-01-13 21:08:52 +00:00
|
|
|
|
2007-06-19 13:20:34 +00:00
|
|
|
/**
|
|
|
|
* Get CakePHP basic paths as an indexed array.
|
|
|
|
* Resulting array will contain array of paths
|
|
|
|
* indexed by: Models, Behaviors, Controllers,
|
|
|
|
* Components, and Helpers.
|
|
|
|
*
|
|
|
|
* @return array Array of paths indexed by type
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function paths() {
|
2007-01-13 21:08:52 +00:00
|
|
|
$directories = Configure::getInstance();
|
|
|
|
$paths = array();
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($directories->modelPaths as $path) {
|
2007-01-13 21:08:52 +00:00
|
|
|
$paths['Models'][] = $path;
|
|
|
|
}
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($directories->behaviorPaths as $path) {
|
2007-01-13 21:08:52 +00:00
|
|
|
$paths['Behaviors'][] = $path;
|
|
|
|
}
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($directories->controllerPaths as $path) {
|
2007-01-13 21:08:52 +00:00
|
|
|
$paths['Controllers'][] = $path;
|
|
|
|
}
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($directories->componentPaths as $path) {
|
2007-01-13 21:08:52 +00:00
|
|
|
$paths['Components'][] = $path;
|
|
|
|
}
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($directories->helperPaths as $path) {
|
2007-01-13 21:08:52 +00:00
|
|
|
$paths['Helpers'][] = $path;
|
|
|
|
}
|
|
|
|
|
2007-06-20 07:51:52 +00:00
|
|
|
if (!class_exists('Folder')) {
|
2007-01-13 21:08:52 +00:00
|
|
|
uses('Folder');
|
|
|
|
}
|
|
|
|
|
|
|
|
$folder =& new Folder(APP.'plugins'.DS);
|
|
|
|
$plugins = $folder->ls();
|
|
|
|
$classPaths = array('models', 'models'.DS.'behaviors', 'controllers', 'controllers'.DS.'components', 'views'.DS.'helpers');
|
|
|
|
|
2007-06-20 07:51:52 +00:00
|
|
|
foreach ($plugins[0] as $plugin) {
|
|
|
|
foreach ($classPaths as $path) {
|
|
|
|
if (strpos($path, DS) !== false) {
|
2007-01-13 21:08:52 +00:00
|
|
|
$key = explode(DS, $path);
|
|
|
|
$key = $key[1];
|
|
|
|
} else {
|
|
|
|
$key = $path;
|
|
|
|
}
|
|
|
|
$folder->path = APP.'plugins'.DS.$plugin.DS.$path;
|
|
|
|
$paths[Inflector::camelize($plugin)][Inflector::camelize($key)][] = $folder->path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $paths;
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
/**
|
|
|
|
* Loads all controllers.
|
2007-06-19 13:20:34 +00:00
|
|
|
*
|
|
|
|
* @return array Set of loaded controllers
|
2005-06-23 08:32:04 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function loadControllers() {
|
|
|
|
$paths = Configure::getInstance();
|
|
|
|
if (!class_exists('AppController')) {
|
|
|
|
if (file_exists(APP . 'app_controller.php')) {
|
|
|
|
require(APP . 'app_controller.php');
|
|
|
|
} else {
|
|
|
|
require(CAKE . 'app_controller.php');
|
|
|
|
}
|
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
$loadedControllers = array();
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($paths->controllerPaths as $path) {
|
|
|
|
foreach (listClasses($path) as $controller) {
|
2006-12-15 16:18:15 +00:00
|
|
|
list($name) = explode('.', $controller);
|
|
|
|
$className = Inflector::camelize($name);
|
|
|
|
if (loadController($name)) {
|
|
|
|
$loadedControllers[$controller] = $className;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-12-15 16:18:15 +00:00
|
|
|
return $loadedControllers;
|
2006-05-26 05:29:17 +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
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function loadController($name) {
|
|
|
|
if (!class_exists('AppController')) {
|
|
|
|
if (file_exists(APP . 'app_controller.php')) {
|
|
|
|
require(APP . 'app_controller.php');
|
|
|
|
} else {
|
|
|
|
require(CAKE . 'app_controller.php');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($name === null) {
|
|
|
|
return true;
|
|
|
|
}
|
2007-06-20 07:51:52 +00:00
|
|
|
if (strpos($name, '.') !== false) {
|
2007-01-13 21:36:10 +00:00
|
|
|
list($plugin, $name) = explode('.', $name);
|
2007-05-27 02:32:27 +00:00
|
|
|
|
|
|
|
$pluginAppController = Inflector::camelize($plugin . '_app_controller');
|
|
|
|
$plugin = Inflector::underscore($plugin);
|
|
|
|
$pluginAppControllerFile = APP . 'plugins' . DS . $plugin . DS . $plugin . '_app_controller.php';
|
|
|
|
|
|
|
|
if (!class_exists($pluginAppController)) {
|
|
|
|
if (file_exists($pluginAppControllerFile)) {
|
|
|
|
require($pluginAppControllerFile);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($name)) {
|
|
|
|
if (!class_exists(Inflector::camelize($plugin . '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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_exists($name . 'Controller')) {
|
|
|
|
$name = Inflector::underscore($name);
|
|
|
|
$file = APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $name . '_controller.php';
|
|
|
|
|
|
|
|
if (file_exists($file)) {
|
|
|
|
require($file);
|
|
|
|
return true;
|
2007-06-20 07:51:52 +00:00
|
|
|
} elseif (!class_exists(Inflector::camelize($plugin) . 'Controller')) {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (file_exists(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php')) {
|
2007-05-27 02:32:27 +00:00
|
|
|
require(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php');
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2007-01-13 21:36:10 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-01-13 21:08:52 +00:00
|
|
|
$className = $name . 'Controller';
|
|
|
|
if (!class_exists($className)) {
|
|
|
|
$name = Inflector::underscore($className);
|
|
|
|
$controllers = Configure::read('Controllers');
|
2007-06-20 06:15:35 +00:00
|
|
|
if (is_array($controllers)) {
|
|
|
|
if (array_key_exists($className, $controllers)) {
|
2007-01-13 21:08:52 +00:00
|
|
|
require($controllers[$className]['path']);
|
|
|
|
return true;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (isset($controllers['Core']) && array_key_exists($className, $controllers['Core'])) {
|
2007-01-13 21:08:52 +00:00
|
|
|
require($controllers['Core'][$className]['path']);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-01-13 21:08:52 +00:00
|
|
|
$paths = Configure::getInstance();
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($paths->controllerPaths as $path) {
|
2007-01-13 21:08:52 +00:00
|
|
|
if (file_exists($path . $name . '.php')) {
|
|
|
|
Configure::store('Controllers', 'class.paths', array($className => array('path' => $path . $name . '.php')));
|
|
|
|
require($path . $name . '.php');
|
2006-05-26 05:29:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-13 21:08:52 +00:00
|
|
|
if ($controllerFilename = fileExistsInPath(LIBS . 'controller' . DS . $name . '.php')) {
|
|
|
|
if (file_exists($controllerFilename)) {
|
|
|
|
Configure::store('Controllers\'][\'Core', 'class.paths', array($className => array('path' => $controllerFilename)));
|
|
|
|
require($controllerFilename);
|
2006-05-26 05:29:17 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-26 09:50:17 +00:00
|
|
|
return false;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-02-01 13:26:23 +00:00
|
|
|
/**
|
2006-11-05 06:29:15 +00:00
|
|
|
* Loads a plugin's controller.
|
2006-02-01 13:26:23 +00:00
|
|
|
*
|
|
|
|
* @param string $plugin Name of plugin
|
|
|
|
* @param string $controller Name of controller to load
|
|
|
|
* @return boolean Success
|
2007-05-26 09:50:17 +00:00
|
|
|
* @deprecated
|
2006-02-01 13:26:23 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function loadPluginController($plugin, $controller) {
|
|
|
|
$pluginAppController = Inflector::camelize($plugin . '_app_controller');
|
2007-05-26 23:43:35 +00:00
|
|
|
$plugin = Inflector::underscore($plugin);
|
2006-05-26 05:29:17 +00:00
|
|
|
$pluginAppControllerFile = APP . 'plugins' . DS . $plugin . DS . $plugin . '_app_controller.php';
|
|
|
|
if (!class_exists($pluginAppController)) {
|
|
|
|
if (file_exists($pluginAppControllerFile)) {
|
|
|
|
require($pluginAppControllerFile);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($controller)) {
|
2007-05-26 23:43:35 +00:00
|
|
|
if (!class_exists(Inflector::camelize($plugin . 'controller'))) {
|
2006-10-31 03:42:36 +00:00
|
|
|
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-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_exists($controller . 'Controller')) {
|
|
|
|
$controller = Inflector::underscore($controller);
|
|
|
|
$file = APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $controller . '_controller.php';
|
|
|
|
|
|
|
|
if (file_exists($file)) {
|
|
|
|
require($file);
|
|
|
|
return true;
|
2007-06-20 07:51:52 +00:00
|
|
|
} elseif (!class_exists(Inflector::camelize($plugin) . 'Controller')) {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (file_exists(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php')) {
|
2007-02-01 06:12:18 +00:00
|
|
|
require(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php');
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
2007-02-01 06:12:18 +00:00
|
|
|
return true;
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Loads a helper
|
|
|
|
*
|
|
|
|
* @param string $name Name of helper
|
|
|
|
* @return boolean Success
|
|
|
|
*/
|
|
|
|
function loadHelper($name) {
|
2006-10-27 21:41:34 +00:00
|
|
|
if (!class_exists('AppHelper')) {
|
|
|
|
if (file_exists(APP . 'app_helper.php')) {
|
|
|
|
require(APP . 'app_helper.php');
|
|
|
|
} else {
|
|
|
|
require(CAKE . 'app_helper.php');
|
|
|
|
}
|
2006-11-01 20:42:11 +00:00
|
|
|
Overloadable::overload('AppHelper');
|
2006-10-27 21:41:34 +00:00
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
|
|
|
|
if ($name === null) {
|
|
|
|
return true;
|
|
|
|
}
|
2007-06-20 07:51:52 +00:00
|
|
|
if (strpos($name, '.') !== false) {
|
2007-01-13 21:36:10 +00:00
|
|
|
list($plugin, $name) = explode('.', $name);
|
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
|
2007-01-13 21:08:52 +00:00
|
|
|
$className = $name . 'Helper';
|
|
|
|
if (!class_exists($className)) {
|
2006-10-27 21:41:34 +00:00
|
|
|
$name = Inflector::underscore($name);
|
2007-01-13 21:08:52 +00:00
|
|
|
$helpers = Configure::read('Helpers');
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (is_array($helpers)) {
|
|
|
|
if (array_key_exists($className, $helpers)) {
|
2007-01-13 21:08:52 +00:00
|
|
|
require($helpers[$className]['path']);
|
|
|
|
return true;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (isset($helpers['Core']) && array_key_exists($className, $helpers['Core'])) {
|
2007-01-13 21:08:52 +00:00
|
|
|
require($helpers['Core'][$className]['path']);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
|
2007-01-13 21:08:52 +00:00
|
|
|
$paths = Configure::getInstance();
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($paths->helperPaths as $path) {
|
2006-06-14 18:02:37 +00:00
|
|
|
if (file_exists($path . $name . '.php')) {
|
2007-01-13 21:08:52 +00:00
|
|
|
Configure::store('Helpers', 'class.paths', array($className => array('path' => $path . $name . '.php')));
|
2006-06-14 18:02:37 +00:00
|
|
|
require($path . $name . '.php');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-13 21:08:52 +00:00
|
|
|
if ($helperFilename = fileExistsInPath(LIBS . 'view' . DS . 'helpers' . DS . $name . '.php')) {
|
|
|
|
if (file_exists($helperFilename)) {
|
|
|
|
Configure::store('Helpers\'][\'Core', 'class.paths', array($className => array('path' => $helperFilename)));
|
|
|
|
require($helperFilename);
|
2006-06-14 18:02:37 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-26 09:50:17 +00:00
|
|
|
return true;
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Loads a plugin's helper
|
|
|
|
*
|
|
|
|
* @param string $plugin Name of plugin
|
|
|
|
* @param string $helper Name of helper to load
|
|
|
|
* @return boolean Success
|
2007-05-26 09:50:17 +00:00
|
|
|
* @deprecated
|
2006-06-14 18:02:37 +00:00
|
|
|
*/
|
|
|
|
function loadPluginHelper($plugin, $helper) {
|
2007-04-01 08:18:05 +00:00
|
|
|
loadHelper(null);
|
|
|
|
|
2006-06-14 18:02:37 +00:00
|
|
|
if (!class_exists($helper . 'Helper')) {
|
|
|
|
$helper = Inflector::underscore($helper);
|
|
|
|
$file = APP . 'plugins' . DS . $plugin . DS . 'views' . DS . 'helpers' . DS . $helper . '.php';
|
|
|
|
if (file_exists($file)) {
|
|
|
|
require($file);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2007-05-26 09:50:17 +00:00
|
|
|
return true;
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Loads a component
|
|
|
|
*
|
|
|
|
* @param string $name Name of component
|
|
|
|
* @return boolean Success
|
|
|
|
*/
|
|
|
|
function loadComponent($name) {
|
|
|
|
if ($name === null) {
|
|
|
|
return true;
|
|
|
|
}
|
2007-05-26 09:50:17 +00:00
|
|
|
|
2007-06-20 07:51:52 +00:00
|
|
|
if (strpos($name, '.') !== false) {
|
2007-01-13 21:36:10 +00:00
|
|
|
list($plugin, $name) = explode('.', $name);
|
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
|
2007-01-13 21:08:52 +00:00
|
|
|
$className = $name . 'Component';
|
|
|
|
if (!class_exists($className)) {
|
|
|
|
$name = Inflector::underscore($name);
|
|
|
|
$components = Configure::read('Components');
|
2006-06-14 18:02:37 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (is_array($components)) {
|
|
|
|
if (array_key_exists($className, $components)) {
|
2007-01-13 21:08:52 +00:00
|
|
|
require($components[$className]['path']);
|
|
|
|
return true;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (isset($components['Core']) && array_key_exists($className, $components['Core'])) {
|
2007-01-13 21:08:52 +00:00
|
|
|
require($components['Core'][$className]['path']);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$paths = Configure::getInstance();
|
2007-05-26 09:50:17 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($paths->componentPaths as $path) {
|
2006-06-14 18:02:37 +00:00
|
|
|
if (file_exists($path . $name . '.php')) {
|
2007-01-13 21:08:52 +00:00
|
|
|
Configure::store('Components', 'class.paths', array($className => array('path' => $path . $name . '.php')));
|
2006-06-14 18:02:37 +00:00
|
|
|
require($path . $name . '.php');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-13 21:08:52 +00:00
|
|
|
if ($componentFilename = fileExistsInPath(LIBS . 'controller' . DS . 'components' . DS . $name . '.php')) {
|
|
|
|
if (file_exists($componentFilename)) {
|
|
|
|
Configure::store('Components\'][\'Core', 'class.paths', array($className => array('path' => $componentFilename)));
|
|
|
|
require($componentFilename);
|
2006-06-14 18:02:37 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-26 09:50:17 +00:00
|
|
|
return true;
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Loads a plugin's component
|
|
|
|
*
|
|
|
|
* @param string $plugin Name of plugin
|
|
|
|
* @param string $helper Name of component to load
|
|
|
|
* @return boolean Success
|
2007-05-26 09:50:17 +00:00
|
|
|
* @deprecated
|
2006-06-14 18:02:37 +00:00
|
|
|
*/
|
|
|
|
function loadPluginComponent($plugin, $component) {
|
|
|
|
if (!class_exists($component . 'Component')) {
|
|
|
|
$component = Inflector::underscore($component);
|
|
|
|
$file = APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . 'components' . DS . $component . '.php';
|
|
|
|
if (file_exists($file)) {
|
|
|
|
require($file);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-05-26 09:50:17 +00:00
|
|
|
return true;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-07-22 14:13:07 +00:00
|
|
|
/**
|
|
|
|
* Loads a behavior
|
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param string $name Name of behavior
|
2006-07-22 14:13:07 +00:00
|
|
|
* @return boolean Success
|
|
|
|
*/
|
|
|
|
function loadBehavior($name) {
|
|
|
|
if ($name === null) {
|
|
|
|
return true;
|
|
|
|
}
|
2007-06-20 07:51:52 +00:00
|
|
|
if (strpos($name, '.') !== false) {
|
2007-05-26 09:50:17 +00:00
|
|
|
list($plugin, $name) = explode('.', $name);
|
|
|
|
}
|
|
|
|
|
|
|
|
$paths = Configure::getInstance();
|
2006-07-22 14:13:07 +00:00
|
|
|
|
|
|
|
if (!class_exists($name . 'Behavior')) {
|
|
|
|
$name = Inflector::underscore($name);
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($paths->behaviorPaths as $path) {
|
2006-07-22 14:13:07 +00:00
|
|
|
if (file_exists($path . $name . '.php')) {
|
|
|
|
require($path . $name . '.php');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($behavior_fn = fileExistsInPath(LIBS . 'model' . DS . 'behaviors' . DS . $name . '.php')) {
|
|
|
|
if (file_exists($behavior_fn)) {
|
|
|
|
require($behavior_fn);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-26 09:50:17 +00:00
|
|
|
return true;
|
2006-07-22 14:13:07 +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
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function listClasses($path) {
|
|
|
|
$dir = opendir($path);
|
|
|
|
$classes=array();
|
2007-06-20 06:15:35 +00:00
|
|
|
while (false !== ($file = readdir($dir))) {
|
2006-05-26 05:29:17 +00:00
|
|
|
if ((substr($file, -3, 3) == 'php') && substr($file, 0, 1) != '.') {
|
|
|
|
$classes[] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dir);
|
|
|
|
return $classes;
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
/**
|
2007-06-19 13:20:34 +00:00
|
|
|
* Loads configuration files. Receives a set of configuration files
|
|
|
|
* to load.
|
|
|
|
* Example:
|
|
|
|
* <code>
|
|
|
|
* config('config1', 'config2');
|
|
|
|
* </code>
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
|
|
|
* @return boolean Success
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function config() {
|
|
|
|
$args = func_get_args();
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($args as $arg) {
|
2006-05-26 05:29:17 +00:00
|
|
|
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
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function uses() {
|
2006-09-03 06:46:43 +00:00
|
|
|
$args = func_get_args();
|
2006-08-08 21:17:20 +00:00
|
|
|
$c = func_num_args();
|
|
|
|
|
|
|
|
for ($i = 0; $i < $c; $i++) {
|
|
|
|
require_once(LIBS . strtolower($args[$i]) . '.php');
|
2006-05-26 05:29:17 +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
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function vendor($name) {
|
2006-09-03 06:46:43 +00:00
|
|
|
$args = func_get_args();
|
2006-08-08 21:17:20 +00:00
|
|
|
$c = func_num_args();
|
2007-05-26 09:50:17 +00:00
|
|
|
|
2006-08-08 21:17:20 +00:00
|
|
|
for ($i = 0; $i < $c; $i++) {
|
|
|
|
$arg = $args[$i];
|
2007-05-26 09:50:17 +00:00
|
|
|
|
2007-06-20 07:51:52 +00:00
|
|
|
if (strpos($arg, '.') !== false) {
|
2007-05-27 04:10:33 +00:00
|
|
|
$file = explode('.', $arg);
|
|
|
|
$plugin = Inflector::underscore($file[0]);
|
|
|
|
unset($file[0]);
|
|
|
|
$file = implode('.', $file);
|
|
|
|
if (file_exists(APP . 'plugins' . DS . $plugin . DS . 'vendors' . DS . $file . '.php')) {
|
|
|
|
require_once(APP . 'plugins' . DS . $plugin . DS . 'vendors' . DS . $file . '.php');
|
|
|
|
continue;
|
|
|
|
}
|
2007-05-26 09:50:17 +00:00
|
|
|
}
|
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if (file_exists(APP . 'vendors' . DS . $arg . '.php')) {
|
|
|
|
require_once(APP . 'vendors' . DS . $arg . '.php');
|
2007-02-04 02:08:17 +00:00
|
|
|
} elseif (file_exists(VENDORS . $arg . '.php')) {
|
2006-05-26 05:29:17 +00:00
|
|
|
require_once(VENDORS . $arg . '.php');
|
2007-02-04 02:08:17 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-04 02:08:17 +00:00
|
|
|
return true;
|
2006-05-26 05:29:17 +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
|
|
|
*
|
2006-05-26 05:29:17 +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-05-26 05:29:17 +00:00
|
|
|
function debug($var = false, $showHtml = false) {
|
2006-12-05 09:49:59 +00:00
|
|
|
if (Configure::read() > 0) {
|
2006-06-14 18:02:37 +00:00
|
|
|
print "\n<pre class=\"cake_debug\">\n";
|
2006-05-26 05:29:17 +00:00
|
|
|
ob_start();
|
|
|
|
print_r($var);
|
|
|
|
$var = ob_get_clean();
|
2006-01-12 02:10:47 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($showHtml) {
|
|
|
|
$var = str_replace('<', '<', str_replace('>', '>', $var));
|
|
|
|
}
|
|
|
|
print "{$var}\n</pre>\n";
|
|
|
|
}
|
|
|
|
}
|
2005-10-03 04:41:33 +00:00
|
|
|
/**
|
2006-05-26 05:29:17 +00:00
|
|
|
* Returns microtime for execution time checking
|
2005-10-03 04:41:33 +00:00
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @return float Microtime
|
2005-10-03 04:41:33 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
if (!function_exists('getMicrotime')) {
|
|
|
|
function getMicrotime() {
|
2006-06-14 18:02:37 +00:00
|
|
|
list($usec, $sec) = explode(" ", microtime());
|
2006-05-26 05:29:17 +00:00
|
|
|
return ((float)$usec + (float)$sec);
|
|
|
|
}
|
|
|
|
}
|
2005-10-03 04:41:33 +00:00
|
|
|
/**
|
|
|
|
* Sorts given $array by key $sortby.
|
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param array $array Array to sort
|
|
|
|
* @param string $sortby Sort by this key
|
|
|
|
* @param string $order Sort order asc/desc (ascending or descending).
|
|
|
|
* @param integer $type Type of sorting to perform
|
|
|
|
* @return mixed Sorted array
|
2005-10-03 04:41:33 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
if (!function_exists('sortByKey')) {
|
|
|
|
function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC) {
|
|
|
|
if (!is_array($array)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($array as $key => $val) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$sa[$key] = $val[$sortby];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($order == 'asc') {
|
|
|
|
asort($sa, $type);
|
|
|
|
} else {
|
|
|
|
arsort($sa, $type);
|
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($sa as $key => $val) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$out[] = $array[$key];
|
|
|
|
}
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
}
|
2005-10-03 04:41:33 +00:00
|
|
|
/**
|
|
|
|
* Combines given identical arrays by using the first array's values as keys,
|
2006-05-26 05:29:17 +00:00
|
|
|
* and the second one's values as values. (Implemented for back-compatibility with PHP4)
|
2005-10-03 04:41:33 +00:00
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param array $a1 Array to use for keys
|
|
|
|
* @param array $a2 Array to use for values
|
2005-10-03 04:41:33 +00:00
|
|
|
* @return mixed Outputs either combined array or false.
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
if (!function_exists('array_combine')) {
|
|
|
|
function array_combine($a1, $a2) {
|
|
|
|
$a1 = array_values($a1);
|
|
|
|
$a2 = array_values($a2);
|
|
|
|
$c1 = count($a1);
|
|
|
|
$c2 = count($a2);
|
|
|
|
|
|
|
|
if ($c1 != $c2) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($c1 <= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$output=array();
|
2007-06-20 06:15:35 +00:00
|
|
|
for ($i = 0; $i < $c1; $i++) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$output[$a1[$i]] = $a2[$i];
|
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param string $text Text to wrap through htmlspecialchars
|
|
|
|
* @return string Wrapped text
|
2005-10-09 01:56:21 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function h($text) {
|
2006-06-15 14:44:16 +00:00
|
|
|
if (is_array($text)) {
|
2006-12-01 17:10:53 +00:00
|
|
|
return array_map('h', $text);
|
2006-06-15 14:44:16 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
return htmlspecialchars($text);
|
|
|
|
}
|
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
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @return array Array of given parameters
|
2005-10-09 01:56:21 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function a() {
|
|
|
|
$args = func_get_args();
|
|
|
|
return $args;
|
|
|
|
}
|
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
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @return array Associative array
|
2005-10-09 01:56:21 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function aa() {
|
|
|
|
$args = func_get_args();
|
2007-06-20 06:15:35 +00:00
|
|
|
for ($l = 0, $c = count($args); $l < $c; $l++) {
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($l + 1 < count($args)) {
|
|
|
|
$a[$args[$l]] = $args[$l + 1];
|
|
|
|
} else {
|
|
|
|
$a[$args[$l]] = null;
|
|
|
|
}
|
|
|
|
$l++;
|
|
|
|
}
|
|
|
|
return $a;
|
|
|
|
}
|
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
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function e($text) {
|
|
|
|
echo $text;
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Convenience method for strtolower().
|
|
|
|
*
|
|
|
|
* @param string $str String to lowercase
|
2007-06-19 13:20:34 +00:00
|
|
|
* @return string Lowercased string
|
2006-01-12 02:10:47 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function low($str) {
|
|
|
|
return strtolower($str);
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Convenience method for strtoupper().
|
|
|
|
*
|
|
|
|
* @param string $str String to uppercase
|
2007-06-19 13:20:34 +00:00
|
|
|
* @return string Uppercased string
|
2006-01-12 02:10:47 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function up($str) {
|
|
|
|
return strtoupper($str);
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Convenience method for str_replace().
|
|
|
|
*
|
|
|
|
* @param string $search String to be replaced
|
|
|
|
* @param string $replace String to insert
|
|
|
|
* @param string $subject String to search
|
2007-06-19 13:20:34 +00:00
|
|
|
* @return string Replaced string
|
2006-01-12 02:10:47 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
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-05-26 05:29:17 +00:00
|
|
|
* @see debug()
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param array $var Variable to print out
|
2005-10-09 01:56:21 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function pr($var) {
|
2006-12-05 09:49:59 +00:00
|
|
|
if (Configure::read() > 0) {
|
2006-05-26 05:29:17 +00:00
|
|
|
echo "<pre>";
|
|
|
|
print_r($var);
|
|
|
|
echo "</pre>";
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function params($p) {
|
|
|
|
if (!is_array($p) || count($p) == 0) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
if (is_array($p[0]) && count($p) == 1) {
|
|
|
|
return $p[0];
|
|
|
|
} else {
|
|
|
|
return $p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function am() {
|
|
|
|
$r = array();
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach (func_get_args()as $a) {
|
2006-05-26 05:29:17 +00:00
|
|
|
if (!is_array($a)) {
|
|
|
|
$a = array($a);
|
|
|
|
}
|
|
|
|
$r = array_merge($r, $a);
|
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
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
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function setUri() {
|
|
|
|
if (env('HTTP_X_REWRITE_URL')) {
|
|
|
|
$uri = env('HTTP_X_REWRITE_URL');
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (env('REQUEST_URI')) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$uri = env('REQUEST_URI');
|
|
|
|
} else {
|
2007-03-28 16:35:59 +00:00
|
|
|
if ($uri = env('argv')) {
|
2007-04-14 21:35:48 +00:00
|
|
|
if (defined('SERVER_IIS') && SERVER_IIS) {
|
2007-03-28 16:35:59 +00:00
|
|
|
if (key($_GET) && strpos(key($_GET), '?') !== false) {
|
|
|
|
unset($_GET[key($_GET)]);
|
|
|
|
}
|
|
|
|
$uri = preg_split('/\?/', $uri[0], 2);
|
|
|
|
if (isset($uri[1])) {
|
|
|
|
foreach (preg_split('/&/', $uri[1]) as $var) {
|
|
|
|
@list($key, $val) = explode('=', $var);
|
|
|
|
$_GET[$key] = $val;
|
|
|
|
}
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
$uri = BASE_URL . $uri[0];
|
|
|
|
} else {
|
|
|
|
$uri = env('PHP_SELF') . '/' . $uri[0];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$uri = env('PHP_SELF') . '/' . env('QUERY_STRING');
|
|
|
|
}
|
|
|
|
}
|
2007-04-14 21:35:48 +00:00
|
|
|
return preg_replace('/\?url=\//', '', $uri);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-09-05 18:10:59 +00:00
|
|
|
* Gets an environment variable from available sources, and provides emulation
|
|
|
|
* for unsupported or inconsisten environment variables (i.e. DOCUMENT_ROOT on
|
|
|
|
* IIS, or SCRIPT_NAME in CGI mode). Also exposes some additional custom
|
|
|
|
* environment information.
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
|
|
|
* @param string $key Environment variable name.
|
|
|
|
* @return string Environment variable setting.
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function env($key) {
|
2006-09-05 18:10:59 +00:00
|
|
|
|
2006-09-20 19:13:57 +00:00
|
|
|
if ($key == 'HTTPS') {
|
|
|
|
if (isset($_SERVER) && !empty($_SERVER)) {
|
|
|
|
return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on');
|
|
|
|
} else {
|
|
|
|
return (strpos(env('SCRIPT_URI'), 'https://') === 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-05 18:10:59 +00:00
|
|
|
if ($key == 'SCRIPT_NAME') {
|
|
|
|
if (env('CGI_MODE')) {
|
|
|
|
$key = 'SCRIPT_URL';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$val = null;
|
2006-05-26 05:29:17 +00:00
|
|
|
if (isset($_SERVER[$key])) {
|
2006-09-05 18:10:59 +00:00
|
|
|
$val = $_SERVER[$key];
|
2006-05-26 05:29:17 +00:00
|
|
|
} elseif (isset($_ENV[$key])) {
|
2006-09-05 18:10:59 +00:00
|
|
|
$val = $_ENV[$key];
|
2006-05-26 05:29:17 +00:00
|
|
|
} elseif (getenv($key) !== false) {
|
2006-09-05 18:10:59 +00:00
|
|
|
$val = getenv($key);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
2006-09-05 18:10:59 +00:00
|
|
|
if ($key == 'REMOTE_ADDR' && $val == env('SERVER_ADDR')) {
|
|
|
|
$addr = env('HTTP_PC_REMOTE_ADDR');
|
|
|
|
if ($addr != null) {
|
|
|
|
$val = $addr;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-05 18:10:59 +00:00
|
|
|
|
|
|
|
if ($val !== null) {
|
|
|
|
return $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($key) {
|
|
|
|
case '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));
|
|
|
|
break;
|
|
|
|
case 'PHP_SELF':
|
|
|
|
return r(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
|
|
|
|
break;
|
|
|
|
case 'CGI_MODE':
|
|
|
|
return (substr(php_sapi_name(), 0, 3) == 'cgi');
|
|
|
|
break;
|
2007-03-16 14:59:40 +00:00
|
|
|
case 'HTTP_BASE':
|
|
|
|
return preg_replace ('/^([^.])*/i', null, env('HTTP_HOST'));
|
|
|
|
break;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
|
|
|
* Writes data into file.
|
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* If file exists, it will be overwritten. If data is an array, it will be join()ed with an empty string.
|
2006-02-18 23:42:21 +00:00
|
|
|
*
|
|
|
|
* @param string $fileName File name.
|
2006-05-26 05:29:17 +00:00
|
|
|
* @param mixed $data String or array.
|
2007-06-19 13:20:34 +00:00
|
|
|
* @return boolean Success
|
2006-05-26 05:29:17 +00:00
|
|
|
*/
|
|
|
|
if (!function_exists('file_put_contents')) {
|
|
|
|
function file_put_contents($fileName, $data) {
|
|
|
|
if (is_array($data)) {
|
|
|
|
$data = join('', $data);
|
|
|
|
}
|
|
|
|
$res = @fopen($fileName, 'w+b');
|
|
|
|
if ($res) {
|
2006-10-19 18:14:09 +00:00
|
|
|
$write = @fwrite($res, $data);
|
2007-06-20 06:15:35 +00:00
|
|
|
if ($write === false) {
|
2006-10-19 18:14:09 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return $write;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-10-19 18:14:09 +00:00
|
|
|
return false;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Reads/writes temporary data to cache files or session.
|
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @param string $path File path within /tmp to save the file.
|
|
|
|
* @param mixed $data The data to save to the temporary file.
|
2006-01-12 02:10:47 +00:00
|
|
|
* @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.
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
|
2006-07-04 01:29:48 +00:00
|
|
|
|
|
|
|
if (defined('DISABLE_CACHE')) {
|
|
|
|
return null;
|
|
|
|
}
|
2006-11-28 22:34:28 +00:00
|
|
|
$now = time();
|
2006-07-04 01:29:48 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if (!is_numeric($expires)) {
|
2006-11-28 22:34:28 +00:00
|
|
|
$expires = strtotime($expires, $now);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(strtolower($target)) {
|
|
|
|
case 'cache':
|
|
|
|
$filename = CACHE . $path;
|
|
|
|
break;
|
|
|
|
case 'public':
|
|
|
|
$filename = WWW_ROOT . $path;
|
|
|
|
break;
|
2007-01-17 02:41:02 +00:00
|
|
|
case 'tmp':
|
|
|
|
$filename = TMP . $path;
|
|
|
|
break;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-11-28 22:34:28 +00:00
|
|
|
|
|
|
|
$timediff = $expires - $now;
|
2007-02-01 06:39:25 +00:00
|
|
|
$filetime = false;
|
2007-06-20 06:15:35 +00:00
|
|
|
if (file_exists($filename)) {
|
2007-02-01 06:39:25 +00:00
|
|
|
$filetime = @filemtime($filename);
|
|
|
|
}
|
2007-01-13 21:08:52 +00:00
|
|
|
|
2007-02-01 03:34:32 +00:00
|
|
|
if ($data === null) {
|
2006-05-26 05:29:17 +00:00
|
|
|
// Read data from file
|
|
|
|
if (file_exists($filename) && $filetime !== false) {
|
|
|
|
if ($filetime + $timediff < $now) {
|
|
|
|
// File has expired
|
|
|
|
@unlink($filename);
|
|
|
|
} else {
|
|
|
|
$data = file_get_contents($filename);
|
|
|
|
}
|
|
|
|
}
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (is_writable(dirname($filename))) {
|
2006-05-26 05:29:17 +00:00
|
|
|
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.
|
2006-05-26 05:29:17 +00:00
|
|
|
* If array, names to be searched for deletion.
|
|
|
|
* If clearCache() without params, all files in app/tmp/cache/views will be deleted
|
2006-03-12 05:56:07 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function clearCache($params = null, $type = 'views', $ext = '.php') {
|
|
|
|
if (is_string($params) || $params === null) {
|
|
|
|
$params = preg_replace('/\/\//', '/', $params);
|
|
|
|
$cache = CACHE . $type . DS . $params;
|
|
|
|
|
|
|
|
if (is_file($cache . $ext)) {
|
|
|
|
@unlink($cache . $ext);
|
|
|
|
return true;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (is_dir($cache)) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$files = glob("$cache*");
|
|
|
|
|
|
|
|
if ($files === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($files as $file) {
|
2006-05-26 05:29:17 +00:00
|
|
|
if (is_file($file)) {
|
|
|
|
@unlink($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$cache = CACHE . $type . DS . '*' . $params . '*' . $ext;
|
|
|
|
$files = glob($cache);
|
|
|
|
|
|
|
|
if ($files === false) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($files as $file) {
|
2006-05-26 05:29:17 +00:00
|
|
|
if (is_file($file)) {
|
|
|
|
@unlink($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} elseif (is_array($params)) {
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($params as $key => $file) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$file = preg_replace('/\/\//', '/', $file);
|
|
|
|
$cache = CACHE . $type . DS . '*' . $file . '*' . $ext;
|
|
|
|
$files[] = glob($cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($files)) {
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($files as $key => $delete) {
|
2006-05-26 05:29:17 +00:00
|
|
|
if (is_array($delete)) {
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($delete as $file) {
|
2006-05-26 05:29:17 +00:00
|
|
|
if (is_file($file)) {
|
|
|
|
@unlink($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2006-03-12 05:56:07 +00:00
|
|
|
/**
|
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
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param array $value Array of values to strip slashes
|
|
|
|
* @return mixed What is returned from calling stripslashes
|
2006-03-12 05:56:07 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function stripslashes_deep($value) {
|
|
|
|
if (is_array($value)) {
|
|
|
|
$return = array_map('stripslashes_deep', $value);
|
|
|
|
return $return;
|
|
|
|
} else {
|
|
|
|
$return = stripslashes($value);
|
|
|
|
return $return ;
|
|
|
|
}
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-06-14 19:06:14 +00:00
|
|
|
*
|
2006-12-22 20:04:15 +00:00
|
|
|
* Returns a translated string if one is found, or the submitted message if not found.
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param string $singular Text to translate
|
|
|
|
* @param boolean $return Set to true to return translated string, or false to echo
|
|
|
|
* @return mixed translated string if $return is false string will be echoed
|
2006-01-12 02:10:47 +00:00
|
|
|
*/
|
2006-12-25 04:42:47 +00:00
|
|
|
function __($singular, $return = false) {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!class_exists('I18n')) {
|
2006-06-14 19:06:14 +00:00
|
|
|
uses('i18n');
|
|
|
|
}
|
|
|
|
$calledFrom = debug_backtrace();
|
|
|
|
$dir = dirname($calledFrom[0]['file']);
|
2006-10-18 17:17:29 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if ($return === false) {
|
2006-12-25 04:42:47 +00:00
|
|
|
echo I18n::translate($singular, null, null, 5, null, $dir);
|
2006-06-14 19:06:14 +00:00
|
|
|
} else {
|
2006-12-25 04:42:47 +00:00
|
|
|
return I18n::translate($singular, null, null, 5, null, $dir);
|
2006-06-14 19:06:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
2006-12-25 04:42:47 +00:00
|
|
|
* Returns correct plural form of message identified by $singular and $plural for count $count.
|
2006-06-14 19:06:14 +00:00
|
|
|
* Some languages have more than one form for plural messages dependent on the count.
|
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param string $singular Singular text to translate
|
|
|
|
* @param string $plural Plural text
|
|
|
|
* @param integer $count Count
|
|
|
|
* @param boolean $return true to return, false to echo
|
|
|
|
* @return mixed plural form of translated string if $return is false string will be echoed
|
2006-06-14 19:06:14 +00:00
|
|
|
*/
|
2006-12-25 04:42:47 +00:00
|
|
|
function __n($singular, $plural, $count, $return = false) {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!class_exists('I18n')) {
|
2006-06-14 19:06:14 +00:00
|
|
|
uses('i18n');
|
|
|
|
}
|
|
|
|
$calledFrom = debug_backtrace();
|
|
|
|
$dir = dirname($calledFrom[0]['file']);
|
2006-10-18 17:17:29 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if ($return === false) {
|
2006-12-25 04:42:47 +00:00
|
|
|
echo I18n::translate($singular, $plural, null, 5, $count, $dir);
|
2006-06-14 19:06:14 +00:00
|
|
|
} else {
|
2006-12-25 04:42:47 +00:00
|
|
|
return I18n::translate($singular, $plural, null, 5, $count, $dir);
|
2006-06-14 19:06:14 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-25 19:38:28 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Allows you to override the current domain for a single message lookup.
|
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param string $domain Domain
|
|
|
|
* @param string $msg String to translate
|
|
|
|
* @param string $return true to return, false to echo
|
2006-12-25 19:38:28 +00:00
|
|
|
* @return translated string if $return is false string will be echoed
|
|
|
|
*/
|
|
|
|
function __d($domain, $msg, $return = false) {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!class_exists('I18n')) {
|
2006-12-25 19:38:28 +00:00
|
|
|
uses('i18n');
|
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if ($return === false) {
|
2006-12-25 19:38:28 +00:00
|
|
|
echo I18n::translate($msg, null, $domain);
|
|
|
|
} else {
|
|
|
|
return I18n::translate($msg, null, $domain);
|
|
|
|
}
|
|
|
|
}
|
2006-06-14 19:06:14 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Allows you to override the current domain for a single plural message lookup
|
2006-12-25 04:42:47 +00:00
|
|
|
* Returns correct plural form of message identified by $singular and $plural for count $count
|
2006-06-14 19:06:14 +00:00
|
|
|
* from domain $domain
|
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param string $domain Domain
|
|
|
|
* @param string $singular Singular string to translate
|
|
|
|
* @param string $plural Plural
|
|
|
|
* @param integer $count Count
|
|
|
|
* @param boolean $return true to return, false to echo
|
2006-12-22 20:04:15 +00:00
|
|
|
* @return plural form of translated string if $return is false string will be echoed
|
2006-06-14 19:06:14 +00:00
|
|
|
*/
|
2006-12-25 04:42:47 +00:00
|
|
|
function __dn($domain, $singular, $plural, $count, $return = false) {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!class_exists('I18n')) {
|
2006-06-14 19:06:14 +00:00
|
|
|
uses('i18n');
|
|
|
|
}
|
2006-10-18 17:17:29 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if ($return === false) {
|
2006-12-25 19:38:28 +00:00
|
|
|
echo I18n::translate($singular, $plural, $domain, 5, $count);
|
2006-06-14 19:06:14 +00:00
|
|
|
} else {
|
2006-12-25 19:38:28 +00:00
|
|
|
return I18n::translate($singular, $plural, $domain, 5, $count);
|
2006-06-14 19:06:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
2006-12-25 19:38:28 +00:00
|
|
|
* Allows you to override the current domain for a single message lookup.
|
2006-06-14 19:06:14 +00:00
|
|
|
* It also allows you to specify a category.
|
|
|
|
*
|
|
|
|
* The category argument allows a specific category of the locale settings to be used for fetching a message.
|
|
|
|
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
|
|
|
|
*
|
|
|
|
* Note that the category must be specified with a numeric value, instead of the constant name. The values are:
|
|
|
|
* LC_CTYPE 0
|
|
|
|
* LC_NUMERIC 1
|
|
|
|
* LC_TIME 2
|
|
|
|
* LC_COLLATE 3
|
|
|
|
* LC_MONETARY 4
|
|
|
|
* LC_MESSAGES 5
|
|
|
|
* LC_ALL 6
|
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param string $domain Domain
|
|
|
|
* @param string $msg Message to translate
|
|
|
|
* @param integer $category Category
|
|
|
|
* @param boolean $return true to return, false to echo
|
2006-12-25 19:38:28 +00:00
|
|
|
* @return translated string if $return is false string will be echoed
|
2006-06-14 19:06:14 +00:00
|
|
|
*/
|
2006-12-25 19:38:28 +00:00
|
|
|
function __dc($domain, $msg, $category, $return = false) {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!class_exists('I18n')) {
|
2006-06-14 19:06:14 +00:00
|
|
|
uses('i18n');
|
|
|
|
}
|
2006-10-18 17:17:29 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if ($return === false) {
|
2006-12-25 19:38:28 +00:00
|
|
|
echo I18n::translate($msg, null, $domain, $category);
|
2006-05-26 05:29:17 +00:00
|
|
|
} else {
|
2006-12-25 19:38:28 +00:00
|
|
|
return I18n::translate($msg, null, $domain, $category);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2006-06-14 19:06:14 +00:00
|
|
|
/**
|
|
|
|
*
|
2006-12-25 19:38:28 +00:00
|
|
|
* Allows you to override the current domain for a single plural message lookup.
|
2006-06-14 19:06:14 +00:00
|
|
|
* It also allows you to specify a category.
|
2006-12-25 19:38:28 +00:00
|
|
|
* Returns correct plural form of message identified by $singular and $plural for count $count
|
|
|
|
* from domain $domain
|
2006-06-14 19:06:14 +00:00
|
|
|
*
|
|
|
|
* The category argument allows a specific category of the locale settings to be used for fetching a message.
|
|
|
|
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
|
|
|
|
*
|
|
|
|
* Note that the category must be specified with a numeric value, instead of the constant name. The values are:
|
|
|
|
* LC_CTYPE 0
|
|
|
|
* LC_NUMERIC 1
|
|
|
|
* LC_TIME 2
|
|
|
|
* LC_COLLATE 3
|
|
|
|
* LC_MONETARY 4
|
|
|
|
* LC_MESSAGES 5
|
|
|
|
* LC_ALL 6
|
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param string $domain Domain
|
|
|
|
* @param string $singular Singular string to translate
|
|
|
|
* @param string $plural Plural
|
|
|
|
* @param integer $count Count
|
|
|
|
* @param integer $category Category
|
|
|
|
* @param boolean $return true to return, false to echo
|
2006-12-25 19:38:28 +00:00
|
|
|
* @return plural form of translated string if $return is false string will be echoed
|
2006-06-14 19:06:14 +00:00
|
|
|
*/
|
2006-12-25 19:38:28 +00:00
|
|
|
function __dcn($domain, $singular, $plural, $count, $category, $return = false) {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!class_exists('I18n')) {
|
2006-06-14 19:06:14 +00:00
|
|
|
uses('i18n');
|
|
|
|
}
|
2006-10-18 17:17:29 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if ($return === false) {
|
2006-12-25 19:38:28 +00:00
|
|
|
echo I18n::translate($singular, $plural, $domain, $category, $count);
|
2006-06-14 19:06:14 +00:00
|
|
|
} else {
|
2006-12-25 19:38:28 +00:00
|
|
|
return I18n::translate($singular, $plural, $domain, $category, $count);
|
2006-06-14 19:06:14 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-25 04:42:47 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* The category argument allows a specific category of the locale settings to be used for fetching a message.
|
|
|
|
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
|
|
|
|
*
|
|
|
|
* Note that the category must be specified with a numeric value, instead of the constant name. The values are:
|
|
|
|
* LC_CTYPE 0
|
|
|
|
* LC_NUMERIC 1
|
|
|
|
* LC_TIME 2
|
|
|
|
* LC_COLLATE 3
|
|
|
|
* LC_MONETARY 4
|
|
|
|
* LC_MESSAGES 5
|
|
|
|
* LC_ALL 6
|
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param string $msg String to translate
|
|
|
|
* @param integer $category Category
|
|
|
|
* @param string $return true to return, false to echo
|
2006-12-25 04:42:47 +00:00
|
|
|
* @return translated string if $return is false string will be echoed
|
2006-06-14 19:06:14 +00:00
|
|
|
*/
|
2006-12-30 01:02:19 +00:00
|
|
|
function __c($msg, $category, $return = false) {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!class_exists('I18n')) {
|
2006-06-14 19:06:14 +00:00
|
|
|
uses('i18n');
|
|
|
|
}
|
|
|
|
$calledFrom = debug_backtrace();
|
|
|
|
$dir = dirname($calledFrom[0]['file']);
|
2006-10-18 17:17:29 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if ($return === false) {
|
2006-12-25 04:42:47 +00:00
|
|
|
echo I18n::translate($msg, null, null, $category, null, $dir);
|
2006-06-14 19:06:14 +00:00
|
|
|
} else {
|
2006-12-25 04:42:47 +00:00
|
|
|
return I18n::translate($msg, null, null, $category, null, $dir);
|
2006-06-14 19:06:14 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-08 08:59:35 +00:00
|
|
|
/**
|
|
|
|
* Computes the difference of arrays using keys for comparison
|
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param array First array
|
|
|
|
* @param array Second array
|
|
|
|
* @return array Array with different keys
|
2006-12-08 08:59:35 +00:00
|
|
|
*/
|
|
|
|
if (!function_exists('array_diff_key')) {
|
|
|
|
function array_diff_key() {
|
|
|
|
$valuesDiff = array();
|
2006-12-13 04:39:26 +00:00
|
|
|
|
2006-12-08 08:59:35 +00:00
|
|
|
if (func_num_args() < 2) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-12-13 04:39:26 +00:00
|
|
|
|
2006-12-08 08:59:35 +00:00
|
|
|
foreach (func_get_args() as $param) {
|
|
|
|
if (!is_array($param)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$args = func_get_args();
|
|
|
|
foreach ($args[0] as $valueKey => $valueData) {
|
|
|
|
for ($i = 1; $i < func_num_args(); $i++) {
|
2007-04-05 16:09:51 +00:00
|
|
|
if (isset($args[$i][$valueKey])) {
|
2006-12-08 08:59:35 +00:00
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$valuesDiff[$valueKey] = $valueData;
|
|
|
|
}
|
|
|
|
return $valuesDiff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Computes the intersection of arrays using keys for comparison
|
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param array First array
|
|
|
|
* @param array Second array
|
|
|
|
* @return array Array with interesected keys
|
2006-12-08 08:59:35 +00:00
|
|
|
*/
|
|
|
|
if (!function_exists('array_intersect_key')) {
|
|
|
|
function array_intersect_key($arr1, $arr2) {
|
|
|
|
$res = array();
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($arr1 as $key=>$value) {
|
|
|
|
if (array_key_exists($key, $arr2)) {
|
2006-12-08 08:59:35 +00:00
|
|
|
$res[$key] = $arr1[$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
}
|
2006-02-08 15:25:34 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Shortcut to Log::write.
|
2007-06-19 13:20:34 +00:00
|
|
|
*
|
|
|
|
* @param string $message Message to write to log
|
2006-02-18 23:42:21 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +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
|
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param string $file File to look for
|
2006-03-12 05:56:07 +00:00
|
|
|
* @return Full path to file if exists, otherwise false
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function fileExistsInPath($file) {
|
|
|
|
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($paths as $path) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$fullPath = $path . DIRECTORY_SEPARATOR . $file;
|
2006-02-16 09:29:28 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if (file_exists($fullPath)) {
|
|
|
|
return $fullPath;
|
|
|
|
} elseif (file_exists($file)) {
|
|
|
|
return $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2006-03-14 11:54:03 +00:00
|
|
|
/**
|
|
|
|
* Convert forward slashes to underscores and removes first and last underscores in a string
|
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param string String to convert
|
2006-03-14 11:54:03 +00:00
|
|
|
* @return string with underscore remove from start and end of string
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function convertSlash($string) {
|
2006-12-28 05:15:21 +00:00
|
|
|
$string = trim($string,"/");
|
2006-05-26 05:29:17 +00:00
|
|
|
$string = preg_replace('/\/\//', '/', $string);
|
|
|
|
$string = str_replace('/', '_', $string);
|
|
|
|
return $string;
|
|
|
|
}
|
2006-05-09 02:15:47 +00:00
|
|
|
/**
|
|
|
|
* chmod recursively on a directory
|
|
|
|
*
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param string $path Path to chmod
|
|
|
|
* @param int $mode Mode to apply
|
|
|
|
* @return boolean Success
|
2006-05-09 02:15:47 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function chmodr($path, $mode = 0755) {
|
|
|
|
if (!is_dir($path)) {
|
|
|
|
return chmod($path, $mode);
|
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
$dir = opendir($path);
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
while ($file = readdir($dir)) {
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($file != '.' && $file != '..') {
|
|
|
|
$fullpath = $path . '/' . $file;
|
|
|
|
|
|
|
|
if (!is_dir($fullpath)) {
|
|
|
|
if (!chmod($fullpath, $mode)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!chmodr($fullpath, $mode)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dir);
|
|
|
|
|
|
|
|
if (chmod($path, $mode)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2007-01-30 16:34:22 +00:00
|
|
|
/**
|
|
|
|
* Wraps ternary operations. If $condition is a non-empty value, $val1 is returned, otherwise $val2.
|
2007-06-19 13:20:34 +00:00
|
|
|
* Don't use for isset() conditions, or wrap your variable with @ operator:
|
|
|
|
* Example:
|
|
|
|
* <code>
|
|
|
|
* ife(isset($variable), @$variable, 'default');
|
|
|
|
* </code>
|
2007-01-30 16:34:22 +00:00
|
|
|
*
|
|
|
|
* @param mixed $condition Conditional expression
|
2007-06-19 13:20:34 +00:00
|
|
|
* @param mixed $val1 Value to return in case condition matches
|
|
|
|
* @param mixed $val2 Value to return if condition doesn't match
|
2007-01-30 16:34:22 +00:00
|
|
|
* @return mixed $val1 or $val2, depending on whether $condition evaluates to a non-empty expression.
|
|
|
|
*/
|
|
|
|
function ife($condition, $val1 = null, $val2 = null) {
|
|
|
|
if (!empty($condition)) {
|
|
|
|
return $val1;
|
|
|
|
}
|
|
|
|
return $val2;
|
|
|
|
}
|
2005-09-17 02:22:07 +00:00
|
|
|
?>
|