2005-08-21 06:49:02 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
|
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Backend for helpers.
|
2005-12-28 17:23:12 +00:00
|
|
|
*
|
2005-10-18 22:27:39 +00:00
|
|
|
* Internal methods for the Helpers.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
2005-12-28 17:23:12 +00:00
|
|
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
2005-12-23 21:57:26 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2005-12-28 17:23:12 +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-28 17:23:12 +00:00
|
|
|
* @filesource
|
2005-12-23 21:57:26 +00:00
|
|
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
2005-08-21 06:49:02 +00:00
|
|
|
* @package cake
|
2005-10-09 01:56:21 +00:00
|
|
|
* @subpackage cake.cake.libs.view
|
2005-08-21 06:49:02 +00:00
|
|
|
* @since CakePHP v 0.2.9
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Backend for helpers.
|
|
|
|
*
|
|
|
|
* Long description for class
|
|
|
|
*
|
|
|
|
* @package cake
|
2005-10-09 01:56:21 +00:00
|
|
|
* @subpackage cake.cake.libs.view
|
2005-08-21 06:49:02 +00:00
|
|
|
* @since CakePHP v 0.9.2
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class Helper extends Object
|
|
|
|
{
|
2005-12-27 03:33:44 +00:00
|
|
|
/*************************************************************************
|
2005-08-21 06:49:02 +00:00
|
|
|
* Public variables
|
|
|
|
*************************************************************************/
|
|
|
|
|
2005-12-27 03:33:44 +00:00
|
|
|
/**#@+
|
2005-08-21 06:49:02 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
|
|
|
* Holds tag templates.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @var array
|
|
|
|
*/
|
2005-08-21 06:49:02 +00:00
|
|
|
var $tags = array();
|
|
|
|
|
2005-12-27 03:33:44 +00:00
|
|
|
/**#@-*/
|
2005-08-21 06:49:02 +00:00
|
|
|
|
2005-12-27 03:33:44 +00:00
|
|
|
/*************************************************************************
|
2005-08-21 06:49:02 +00:00
|
|
|
* Public methods
|
|
|
|
*************************************************************************/
|
|
|
|
|
2005-12-27 03:33:44 +00:00
|
|
|
/**#@+
|
2005-08-21 06:49:02 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* Parses tag templates into $this->tags.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2005-08-21 06:49:02 +00:00
|
|
|
function Helper()
|
|
|
|
{
|
2005-12-28 17:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadConfig()
|
|
|
|
{
|
|
|
|
return $this->readConfigFile(CAKE.'config'.DS.'tags.ini.php');
|
2005-08-21 06:49:02 +00:00
|
|
|
}
|
|
|
|
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
|
|
|
* Decides whether to output or return a string.
|
|
|
|
*
|
|
|
|
* Based on AUTO_OUTPUT and $return's value, this method decides whether to
|
|
|
|
* output a string, or return it.
|
|
|
|
*
|
|
|
|
* @param string $str String to be output or returned.
|
|
|
|
* @param boolean $return Whether this method should return a value or
|
|
|
|
* output it. This overrides AUTO_OUTPUT.
|
|
|
|
* @return mixed Either string or boolean value, depends on AUTO_OUTPUT
|
|
|
|
* and $return.
|
|
|
|
*/
|
2005-08-21 06:49:02 +00:00
|
|
|
function output($str, $return = false)
|
|
|
|
{
|
|
|
|
if (AUTO_OUTPUT && $return === false)
|
|
|
|
{
|
|
|
|
if (print $str)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
|
|
|
* Assigns values to tag templates.
|
|
|
|
*
|
|
|
|
* Finds a tag template by $keyName, and replaces $values's keys with
|
|
|
|
* $values's keys.
|
|
|
|
*
|
|
|
|
* @param string $keyName Name of the key in the tag array.
|
|
|
|
* @param array $values Values to be inserted into tag.
|
|
|
|
* @return string Tag with inserted values.
|
|
|
|
*/
|
2005-08-21 06:49:02 +00:00
|
|
|
function assign($keyName, $values)
|
|
|
|
{
|
|
|
|
return str_replace('%%'.array_keys($values).'%%', array_values($values),
|
|
|
|
$this->tags[$keyName]);
|
|
|
|
}
|
2005-12-28 17:23:12 +00:00
|
|
|
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Returns an array of settings in given INI file.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2005-10-18 22:27:39 +00:00
|
|
|
* @param string $fileName
|
|
|
|
* @return array
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2005-08-21 06:49:02 +00:00
|
|
|
function readConfigFile ($fileName)
|
|
|
|
{
|
|
|
|
$fileLineArray = file($fileName);
|
|
|
|
|
|
|
|
foreach ($fileLineArray as $fileLine)
|
|
|
|
{
|
|
|
|
$dataLine = trim($fileLine);
|
|
|
|
$firstChar = substr($dataLine, 0, 1);
|
|
|
|
if ($firstChar != ';' && $dataLine != '')
|
|
|
|
{
|
|
|
|
if ($firstChar == '[' && substr($dataLine, -1, 1) == ']')
|
|
|
|
{
|
|
|
|
// [section block] we might use this later do not know for sure
|
|
|
|
// this could be used to add a key with the section block name
|
|
|
|
// but it adds another array level
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$delimiter = strpos($dataLine, '=');
|
|
|
|
if ($delimiter > 0)
|
|
|
|
{
|
|
|
|
$key = strtolower(trim(substr($dataLine, 0, $delimiter)));
|
|
|
|
$value = trim(substr($dataLine, $delimiter + 1));
|
|
|
|
if (substr($value, 0, 1) == '"' && substr($value, -1) == '"')
|
|
|
|
{
|
|
|
|
$value = substr($value, 1, -1);
|
|
|
|
}
|
|
|
|
$iniSetting[$key] = stripcslashes($value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$iniSetting[strtolower(trim($dataLine))]='';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $iniSetting;
|
|
|
|
}
|
|
|
|
|
2005-12-27 03:33:44 +00:00
|
|
|
/**#@-*/
|
2005-08-21 06:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|