helper.php

Go to the documentation of this file.
00001 <?php
00002 /* SVN FILE: $Id: helper_8php-source.html 675 2008-12-26 00:27:14Z gwoo $ */
00003 /**
00004  * Backend for helpers.
00005  *
00006  * Internal methods for the Helpers.
00007  *
00008  * PHP versions 4 and 5
00009  *
00010  * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
00011  * Copyright 2005-2008, Cake Software Foundation, Inc.
00012  *                              1785 E. Sahara Avenue, Suite 490-204
00013  *                              Las Vegas, Nevada 89104
00014  *
00015  * Licensed under The MIT License
00016  * Redistributions of files must retain the above copyright notice.
00017  *
00018  * @filesource
00019  * @copyright       Copyright 2005-2008, Cake Software Foundation, Inc.
00020  * @link                http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
00021  * @package         cake
00022  * @subpackage      cake.cake.libs.view
00023  * @since           CakePHP(tm) v 0.2.9
00024  * @version         $Revision: 675 $
00025  * @modifiedby      $LastChangedBy: gwoo $
00026  * @lastmodified    $Date: 2008-12-25 16:27:14 -0800 (Thu, 25 Dec 2008) $
00027  * @license         http://www.opensource.org/licenses/mit-license.php The MIT License
00028  */
00029 /**
00030  * Backend for helpers.
00031  *
00032  * Long description for class
00033  *
00034  * @package     cake
00035  * @subpackage  cake.cake.libs.view
00036  */
00037 class Helper extends Object {
00038 /**
00039  * Holds tag templates.
00040  *
00041  * @access public
00042  * @var array
00043  */
00044     var $tags = array('link' => '<a href="%s" %s>%s</a>',
00045                             'mailto' => '<a href="mailto:%s" %s>%s</a>',
00046                             'form' => '<form %s>',
00047                             'input' => '<input name="data[%s][%s]" %s/>',
00048                             'textarea' => '<textarea name="data[%s][%s]" %s>%s</textarea>',
00049                             'hidden' => '<input type="hidden" name="data[%s][%s]" %s/>',
00050                             'textarea' => '<textarea name="data[%s][%s]" %s>%s</textarea>',
00051                             'checkbox' => '<input type="checkbox" name="data[%s][%s]" %s/>',
00052                             'radio' => '<input type="radio" name="data[%s][%s]" id="%s" %s />%s',
00053                             'selectstart' => '<select name="data[%s][%s]" %s>',
00054                             'selectmultiplestart' => '<select name="data[%s][%s][]" %s>',
00055                             'selectempty' => '<option value="" %s>&nbsp;</option>',
00056                             'selectoption' => '<option value="%s" %s>%s</option>',
00057                             'selectend' => '</select>',
00058                             'password' => '<input type="password" name="data[%s][%s]" %s/>',
00059                             'file' => '<input type="file" name="data[%s][%s]" %s/>',
00060                             'file_no_model' => '<input type="file" name="%s" %s/>',
00061                             'submit' => '<input type="submit" %s/>',
00062                             'image' => '<img src="%s" %s/>',
00063                             'tableheader' => '<th%s>%s</th>',
00064                             'tableheaderrow' => '<tr%s>%s</tr>',
00065                             'tablecell' => '<td%s>%s</td>',
00066                             'tablerow' => '<tr%s>%s</tr>',
00067                             'block' => '<div%s>%s</div>',
00068                             'blockstart' => '<div%s>',
00069                             'blockend' => '</div>',
00070                             'css' => '<link rel="%s" type="text/css" href="%s" %s/>',
00071                             'style' => '<style type="text/css"%s>%s</style>',
00072                             'charset' => '<meta http-equiv="Content-Type" content="text/html; charset=%s" />',
00073                             'javascriptblock' => '<script type="text/javascript">%s</script>',
00074                             'javascriptlink' => '<script type="text/javascript" src="%s"></script>');
00075 /**
00076  * Parses custom config/tags.ini.php and merges with $this->tags.
00077  *
00078  * @return html tags used by helpers
00079  */
00080     function loadConfig() {
00081 
00082         if (file_exists(APP . 'config' . DS . 'tags.ini.php')) {
00083             $tags = $this->readConfigFile(APP . 'config' . DS . 'tags.ini.php');
00084             $this->tags = am($this->tags, $tags);
00085         }
00086         return $this->tags;
00087     }
00088 /**
00089  * Decides whether to output or return a string.
00090  *
00091  * Based on AUTO_OUTPUT and $return's value, this method decides whether to
00092  * output a string, or return it.
00093  *
00094  * @param  string  $str String to be output or returned.
00095  * @param  boolean $return Whether this method should return a value or output it.
00096  * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
00097  */
00098     function output($str, $return = false) {
00099         if (AUTO_OUTPUT && $return === false) {
00100             echo $str;
00101         } else {
00102             return $str;
00103         }
00104     }
00105 /**
00106  * Assigns values to tag templates.
00107  *
00108  * Finds a tag template by $keyName, and replaces $values's keys with
00109  * $values's keys.
00110  *
00111  * @param  string $keyName Name of the key in the tag array.
00112  * @param  array  $values  Values to be inserted into tag.
00113  * @return string Tag with inserted values.
00114  */
00115     function assign($keyName, $values) {
00116         return str_replace('%%' . array_keys($values) . '%%', array_values($values), $this->tags[$keyName]);
00117     }
00118 /**
00119  * Returns an array of settings in given INI file.
00120  *
00121  * @param string $fileName ini file to read
00122  * @return array of lines from the $fileName
00123  */
00124     function readConfigFile($fileName) {
00125         $fileLineArray = file($fileName);
00126 
00127         foreach ($fileLineArray as $fileLine) {
00128             $dataLine = trim($fileLine);
00129             $firstChar = substr($dataLine, 0, 1);
00130 
00131             if ($firstChar != ';' && $dataLine != '') {
00132                 if ($firstChar == '[' && substr($dataLine, -1, 1) == ']') {
00133                     // [section block] we might use this later do not know for sure
00134                     // this could be used to add a key with the section block name
00135                     // but it adds another array level
00136                 } else {
00137                     $delimiter = strpos($dataLine, '=');
00138 
00139                     if ($delimiter > 0) {
00140                         $key = strtolower(trim(substr($dataLine, 0, $delimiter)));
00141                         $value = trim(stripcslashes(substr($dataLine, $delimiter + 1)));
00142 
00143                         if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
00144                             $value = substr($value, 1, -1);
00145                         }
00146 
00147                         $iniSetting[$key] = $value;
00148 
00149                     } else {
00150                         $iniSetting[strtolower(trim($dataLine))] = '';
00151                     }
00152                 }
00153             } else {
00154             }
00155         }
00156 
00157         return $iniSetting;
00158     }
00159 /**
00160  * After render callback.  Overridden in subclasses.
00161  *
00162  * @return void
00163  */
00164     function afterRender() {
00165     }
00166 }
00167 ?>