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() {
|
2006-11-21 21:48:05 +00:00
|
|
|
if(!class_exists('Model')){
|
|
|
|
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
|
|
|
|
|
|
|
foreach($path->modelPaths as $path) {
|
2007-01-22 08:10:43 +00:00
|
|
|
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
|
|
|
|
* @return
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function loadPluginModels($plugin) {
|
2006-11-25 20:30:17 +00:00
|
|
|
if(!class_exists('AppModel')){
|
|
|
|
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-02-09 02:38:19 +00:00
|
|
|
if(is_dir($pluginModelDir)) {
|
|
|
|
foreach(listClasses($pluginModelDir)as $modelFileName) {
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Loads custom view class.
|
|
|
|
*
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function loadView($viewClass) {
|
|
|
|
if (!class_exists($viewClass . 'View')) {
|
|
|
|
$paths = Configure::getInstance();
|
|
|
|
$file = Inflector::underscore($viewClass) . '.php';
|
|
|
|
|
|
|
|
foreach($paths->viewPaths as $path) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Loads a model by CamelCase name.
|
|
|
|
*/
|
2006-11-23 21:39:09 +00:00
|
|
|
function loadModel($name = null) {
|
2006-11-21 21:48:05 +00:00
|
|
|
if(!class_exists('Model')){
|
|
|
|
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-01-13 21:36:10 +00:00
|
|
|
if(strpos($name, '.') !== false){
|
|
|
|
list($plugin, $name) = explode('.', $name);
|
|
|
|
}
|
|
|
|
|
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');
|
|
|
|
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-01-14 01:25:13 +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();
|
2006-11-05 06:29:15 +00:00
|
|
|
foreach($paths->modelPaths as $path) {
|
|
|
|
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;
|
|
|
|
} else {
|
|
|
|
return true;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-13 21:08:52 +00:00
|
|
|
|
|
|
|
function paths(){
|
|
|
|
$directories = Configure::getInstance();
|
|
|
|
$paths = array();
|
|
|
|
|
|
|
|
foreach($directories->modelPaths as $path) {
|
|
|
|
$paths['Models'][] = $path;
|
|
|
|
}
|
|
|
|
foreach($directories->behaviorPaths as $path) {
|
|
|
|
$paths['Behaviors'][] = $path;
|
|
|
|
}
|
|
|
|
foreach($directories->controllerPaths as $path) {
|
|
|
|
$paths['Controllers'][] = $path;
|
|
|
|
}
|
|
|
|
foreach($directories->componentPaths as $path) {
|
|
|
|
$paths['Components'][] = $path;
|
|
|
|
}
|
|
|
|
foreach($directories->helperPaths as $path) {
|
|
|
|
$paths['Helpers'][] = $path;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!class_exists('Folder')){
|
|
|
|
uses('Folder');
|
|
|
|
}
|
|
|
|
|
|
|
|
$folder =& new Folder(APP.'plugins'.DS);
|
|
|
|
$plugins = $folder->ls();
|
|
|
|
$classPaths = array('models', 'models'.DS.'behaviors', 'controllers', 'controllers'.DS.'components', 'views'.DS.'helpers');
|
|
|
|
|
|
|
|
foreach($plugins[0] as $plugin){
|
|
|
|
foreach($classPaths as $path){
|
|
|
|
if(strpos($path, DS) !== false){
|
|
|
|
$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.
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
foreach($paths->controllerPaths as $path) {
|
2006-06-14 18:02:37 +00:00
|
|
|
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-01-13 21:36:10 +00:00
|
|
|
if(strpos($name, '.') !== false){
|
|
|
|
list($plugin, $name) = explode('.', $name);
|
|
|
|
}
|
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');
|
|
|
|
if(is_array($controllers)) {
|
|
|
|
if(array_key_exists($className, $controllers)) {
|
|
|
|
require($controllers[$className]['path']);
|
|
|
|
return true;
|
2007-01-14 01:25:13 +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();
|
2006-05-26 05:29:17 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2006-09-18 20:00:39 +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
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function loadPluginController($plugin, $controller) {
|
|
|
|
$pluginAppController = Inflector::camelize($plugin . '_app_controller');
|
|
|
|
$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)) {
|
2006-10-31 03:42:36 +00:00
|
|
|
if (!class_exists($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;
|
|
|
|
}
|
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-02-01 06:12:18 +00:00
|
|
|
} elseif (!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;
|
|
|
|
} 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-01-13 21:36:10 +00:00
|
|
|
if(strpos($name, '.') !== false){
|
|
|
|
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');
|
|
|
|
|
|
|
|
if(is_array($helpers)) {
|
|
|
|
if(array_key_exists($className, $helpers)) {
|
|
|
|
require($helpers[$className]['path']);
|
|
|
|
return true;
|
2007-01-14 01:25:13 +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();
|
2006-06-14 18:02:37 +00:00
|
|
|
foreach($paths->helperPaths as $path) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Loads a plugin's helper
|
|
|
|
*
|
|
|
|
* @param string $plugin Name of plugin
|
|
|
|
* @param string $helper Name of helper to load
|
|
|
|
* @return boolean Success
|
|
|
|
*/
|
|
|
|
function loadPluginHelper($plugin, $helper) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Loads a component
|
|
|
|
*
|
|
|
|
* @param string $name Name of component
|
|
|
|
* @return boolean Success
|
|
|
|
*/
|
|
|
|
function loadComponent($name) {
|
|
|
|
|
|
|
|
if ($name === null) {
|
|
|
|
return true;
|
|
|
|
}
|
2007-01-13 21:36:10 +00:00
|
|
|
if(strpos($name, '.') !== false){
|
|
|
|
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-01-13 21:08:52 +00:00
|
|
|
if(is_array($components)) {
|
|
|
|
if(array_key_exists($className, $components)) {
|
|
|
|
require($components[$className]['path']);
|
|
|
|
return true;
|
2007-01-14 01:25:13 +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();
|
2006-06-14 18:02:37 +00:00
|
|
|
foreach($paths->componentPaths as $path) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Loads a plugin's component
|
|
|
|
*
|
|
|
|
* @param string $plugin Name of plugin
|
|
|
|
* @param string $helper Name of component to load
|
|
|
|
* @return boolean Success
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-22 14:13:07 +00:00
|
|
|
/**
|
|
|
|
* Loads a behavior
|
|
|
|
*
|
|
|
|
* @param string $name Name of component
|
|
|
|
* @return boolean Success
|
|
|
|
*/
|
|
|
|
function loadBehavior($name) {
|
|
|
|
$paths = Configure::getInstance();
|
|
|
|
|
|
|
|
if ($name === null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_exists($name . 'Behavior')) {
|
|
|
|
$name = Inflector::underscore($name);
|
|
|
|
|
|
|
|
foreach($paths->behaviorPaths as $path) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
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();
|
|
|
|
while(false !== ($file = readdir($dir))) {
|
|
|
|
if ((substr($file, -3, 3) == 'php') && substr($file, 0, 1) != '.') {
|
|
|
|
$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
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function config() {
|
|
|
|
$args = func_get_args();
|
|
|
|
foreach($args as $arg) {
|
|
|
|
if (('database' == $arg) && file_exists(CONFIGS . $arg . '.php')) {
|
|
|
|
include_once(CONFIGS . $arg . '.php');
|
|
|
|
} elseif (file_exists(CONFIGS . $arg . '.php')) {
|
|
|
|
include_once(CONFIGS . $arg . '.php');
|
|
|
|
|
|
|
|
if (count($args) == 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (count($args) == 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2005-06-23 08:32:04 +00:00
|
|
|
/**
|
|
|
|
* Loads component/components from LIBS.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* <code>
|
|
|
|
* uses('flay', 'time');
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* @uses LIBS
|
|
|
|
*/
|
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();
|
|
|
|
for ($i = 0; $i < $c; $i++) {
|
|
|
|
$arg = $args[$i];
|
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
|
|
|
}
|
2006-07-04 01:29:48 +00:00
|
|
|
/**
|
|
|
|
* Normalizes a string or array list
|
|
|
|
*
|
|
|
|
* @param mixed $list
|
|
|
|
* @param boolean $assoc If true, $list will be converted to an associative array
|
|
|
|
* @param string $sep If $list is a string, it will be split into an array with $sep
|
|
|
|
* @param boolean $trim If true, separated strings will be trimmed
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function normalizeList($list, $assoc = true, $sep = ',', $trim = true) {
|
2007-01-20 20:50:57 +00:00
|
|
|
trigger_error('normalizeList Deprecated: use Set::normalize');
|
2006-07-04 01:29:48 +00:00
|
|
|
if (is_string($list)) {
|
|
|
|
$list = explode($sep, $list);
|
|
|
|
if ($trim) {
|
|
|
|
$list = array_map('trim', $list);
|
|
|
|
}
|
2006-08-24 12:40:19 +00:00
|
|
|
if ($assoc) {
|
|
|
|
return normalizeList($list);
|
|
|
|
}
|
2006-07-04 01:29:48 +00:00
|
|
|
} elseif (is_array($list)) {
|
|
|
|
$keys = array_keys($list);
|
|
|
|
$count = count($keys);
|
|
|
|
$numeric = true;
|
|
|
|
|
|
|
|
if (!$assoc) {
|
|
|
|
for ($i = 0; $i < $count; $i++) {
|
|
|
|
if (!is_int($keys[$i])) {
|
|
|
|
$numeric = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$numeric || $assoc) {
|
2006-07-22 14:13:07 +00:00
|
|
|
$newList = array();
|
2006-07-04 01:29:48 +00:00
|
|
|
for ($i = 0; $i < $count; $i++) {
|
|
|
|
if (is_int($keys[$i])) {
|
|
|
|
$newList[$list[$keys[$i]]] = null;
|
|
|
|
} else {
|
|
|
|
$newList[$keys[$i]] = $list[$keys[$i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$list = $newList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $list;
|
|
|
|
}
|
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
|
|
|
*
|
|
|
|
* @return integer
|
|
|
|
*/
|
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.
|
|
|
|
*
|
2006-05-26 05:29:17 +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-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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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
|
|
|
*
|
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-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();
|
|
|
|
for($i = 0; $i < $c1; $i++) {
|
|
|
|
$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
|
|
|
*
|
2005-10-18 22:27:39 +00:00
|
|
|
* @param string $text
|
|
|
|
* @return string
|
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
|
|
|
*
|
2005-10-18 22:27:39 +00:00
|
|
|
* @return array
|
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
|
|
|
*
|
2005-10-18 22:27:39 +00:00
|
|
|
* @return array
|
2005-10-09 01:56:21 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function aa() {
|
|
|
|
$args = func_get_args();
|
|
|
|
for($l = 0, $c = count($args); $l < $c; $l++) {
|
|
|
|
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
|
|
|
|
*/
|
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
|
|
|
|
*/
|
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
|
|
|
|
*/
|
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()
|
|
|
|
* @param array $var
|
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();
|
|
|
|
foreach(func_get_args()as $a) {
|
|
|
|
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');
|
|
|
|
} elseif(env('REQUEST_URI')) {
|
|
|
|
$uri = env('REQUEST_URI');
|
|
|
|
} else {
|
|
|
|
if (env('argv')) {
|
|
|
|
$uri = env('argv');
|
|
|
|
|
|
|
|
if (defined('SERVER_IIS')) {
|
|
|
|
$uri = BASE_URL . $uri[0];
|
|
|
|
} else {
|
|
|
|
$uri = env('PHP_SELF') . '/' . $uri[0];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$uri = env('PHP_SELF') . '/' . env('QUERY_STRING');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $uri;
|
|
|
|
}
|
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;
|
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.
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
if($write === false) {
|
|
|
|
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;
|
|
|
|
if(file_exists($filename)) {
|
|
|
|
$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-01-10 22:43:37 +00:00
|
|
|
} else if(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;
|
|
|
|
} else if(is_dir($cache)) {
|
|
|
|
$files = glob("$cache*");
|
|
|
|
|
|
|
|
if ($files === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($files as $file) {
|
|
|
|
if (is_file($file)) {
|
|
|
|
@unlink($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$cache = CACHE . $type . DS . '*' . $params . '*' . $ext;
|
|
|
|
$files = glob($cache);
|
|
|
|
|
|
|
|
if ($files === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
foreach($files as $file) {
|
|
|
|
if (is_file($file)) {
|
|
|
|
@unlink($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} elseif (is_array($params)) {
|
|
|
|
foreach($params as $key => $file) {
|
|
|
|
$file = preg_replace('/\/\//', '/', $file);
|
|
|
|
$cache = CACHE . $type . DS . '*' . $file . '*' . $ext;
|
|
|
|
$files[] = glob($cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($files)) {
|
|
|
|
foreach($files as $key => $delete) {
|
|
|
|
if (is_array($delete)) {
|
|
|
|
foreach($delete as $file) {
|
|
|
|
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
|
|
|
*
|
|
|
|
* @param unknown_type $value
|
|
|
|
* @return unknown
|
|
|
|
*/
|
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
|
|
|
*
|
2006-12-25 04:42:47 +00:00
|
|
|
* @param string $singular
|
2006-12-22 20:04:15 +00:00
|
|
|
* @param boolean $return
|
|
|
|
* @return 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) {
|
2006-06-14 19:06:14 +00:00
|
|
|
if(!class_exists('I18n')) {
|
|
|
|
uses('i18n');
|
|
|
|
}
|
|
|
|
$calledFrom = debug_backtrace();
|
|
|
|
$dir = dirname($calledFrom[0]['file']);
|
2006-10-18 17:17:29 +00:00
|
|
|
|
2006-12-22 20:04:15 +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.
|
|
|
|
*
|
2006-12-25 04:42:47 +00:00
|
|
|
* @param string $singular
|
|
|
|
* @param string $plural
|
2006-12-22 20:04:15 +00:00
|
|
|
* @param integer $count
|
|
|
|
* @param boolean $return
|
|
|
|
* @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 __n($singular, $plural, $count, $return = false) {
|
2006-06-14 19:06:14 +00:00
|
|
|
if(!class_exists('I18n')) {
|
|
|
|
uses('i18n');
|
|
|
|
}
|
|
|
|
$calledFrom = debug_backtrace();
|
|
|
|
$dir = dirname($calledFrom[0]['file']);
|
2006-10-18 17:17:29 +00:00
|
|
|
|
2006-12-22 20:04:15 +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.
|
|
|
|
*
|
|
|
|
* @param string $domain
|
|
|
|
* @param string $msg
|
|
|
|
* @param string $return
|
|
|
|
* @return translated string if $return is false string will be echoed
|
|
|
|
*/
|
|
|
|
function __d($domain, $msg, $return = false) {
|
|
|
|
if(!class_exists('I18n')) {
|
|
|
|
uses('i18n');
|
|
|
|
}
|
|
|
|
|
|
|
|
if($return === false) {
|
|
|
|
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
|
|
|
|
*
|
2006-12-22 20:04:15 +00:00
|
|
|
* @param string $domain
|
2006-12-25 04:42:47 +00:00
|
|
|
* @param string $singular
|
|
|
|
* @param string $plural
|
2006-12-22 20:04:15 +00:00
|
|
|
* @param integer $count
|
|
|
|
* @param boolean $return
|
|
|
|
* @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) {
|
2006-06-14 19:06:14 +00:00
|
|
|
if(!class_exists('I18n')) {
|
|
|
|
uses('i18n');
|
|
|
|
}
|
2006-10-18 17:17:29 +00:00
|
|
|
|
2006-12-22 20:04:15 +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
|
|
|
|
*
|
2006-12-22 20:04:15 +00:00
|
|
|
* @param string $domain
|
2006-12-25 19:38:28 +00:00
|
|
|
* @param string $msg
|
2006-12-30 01:02:19 +00:00
|
|
|
* @param integer $category
|
2006-12-22 20:04:15 +00:00
|
|
|
* @param boolean $return
|
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) {
|
2006-06-14 19:06:14 +00:00
|
|
|
if(!class_exists('I18n')) {
|
|
|
|
uses('i18n');
|
|
|
|
}
|
2006-10-18 17:17:29 +00:00
|
|
|
|
2006-12-22 20:04:15 +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
|
|
|
|
*
|
2006-12-22 20:04:15 +00:00
|
|
|
* @param string $domain
|
2006-12-25 19:38:28 +00:00
|
|
|
* @param string $singular
|
|
|
|
* @param string $plural
|
|
|
|
* @param integer $count
|
2006-12-30 01:02:19 +00:00
|
|
|
* @param integer $category
|
2006-12-22 20:04:15 +00:00
|
|
|
* @param boolean $return
|
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) {
|
2006-06-14 19:06:14 +00:00
|
|
|
if(!class_exists('I18n')) {
|
|
|
|
uses('i18n');
|
|
|
|
}
|
2006-10-18 17:17:29 +00:00
|
|
|
|
2006-12-22 20:04:15 +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
|
|
|
|
*
|
|
|
|
* @param string $msg
|
2006-12-30 01:02:19 +00:00
|
|
|
* @param integer $category
|
2006-12-25 04:42:47 +00:00
|
|
|
* @param string $return
|
|
|
|
* @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) {
|
2006-06-14 19:06:14 +00:00
|
|
|
if(!class_exists('I18n')) {
|
|
|
|
uses('i18n');
|
|
|
|
}
|
|
|
|
$calledFrom = debug_backtrace();
|
|
|
|
$dir = dirname($calledFrom[0]['file']);
|
2006-10-18 17:17:29 +00:00
|
|
|
|
2006-12-22 20:04:15 +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
|
|
|
|
*
|
|
|
|
* @param array
|
|
|
|
* @param array
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
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++) {
|
|
|
|
if (isset($arg[$i][$valueKey])) {
|
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$valuesDiff[$valueKey] = $valueData;
|
|
|
|
}
|
|
|
|
return $valuesDiff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Computes the intersection of arrays using keys for comparison
|
|
|
|
*
|
|
|
|
* @param array
|
|
|
|
* @param array
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
if (!function_exists('array_intersect_key')) {
|
|
|
|
function array_intersect_key($arr1, $arr2) {
|
|
|
|
$res = array();
|
|
|
|
foreach($arr1 as $key=>$value) {
|
|
|
|
if(array_key_exists($key, $arr2)) {
|
|
|
|
$res[$key] = $arr1[$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
}
|
2006-02-02 11:48:29 +00:00
|
|
|
/**
|
2006-11-10 17:08:31 +00:00
|
|
|
* @deprecated
|
|
|
|
* @see Set::countDim
|
2006-02-02 11:48:29 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function countdim($array) {
|
2006-12-22 22:49:47 +00:00
|
|
|
trigger_error(__('Deprecated: Use Set::countDim instead'), E_USER_WARNING);
|
2006-05-26 05:29:17 +00:00
|
|
|
if (is_array(reset($array))) {
|
|
|
|
$return = countdim(reset($array)) + 1;
|
|
|
|
} 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-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
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @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'));
|
|
|
|
foreach($paths as $path) {
|
|
|
|
$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
|
|
|
|
*
|
|
|
|
* @param string
|
|
|
|
* @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
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param int $mode
|
|
|
|
* @return boolean
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
while($file = readdir($dir)) {
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @param mixed $condition Conditional expression
|
|
|
|
* @param mixed $val1
|
|
|
|
* @param mixed $val2
|
|
|
|
* @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
|
|
|
?>
|