html.php

Go to the documentation of this file.
00001 <?php
00002 /* SVN FILE: $Id: html_8php-source.html 675 2008-12-26 00:27:14Z gwoo $ */
00003 /**
00004  * Html Helper class file.
00005  *
00006  * Simplifies the construction of HTML elements.
00007  *
00008  * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
00009  * Copyright 2005-2008, Cake Software Foundation, Inc.
00010  *                              1785 E. Sahara Avenue, Suite 490-204
00011  *                              Las Vegas, Nevada 89104
00012  *
00013  * Licensed under The MIT License
00014  * Redistributions of files must retain the above copyright notice.
00015  *
00016  * @filesource
00017  * @copyright       Copyright 2005-2008, Cake Software Foundation, Inc.
00018  * @link                http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
00019  * @package         cake
00020  * @subpackage      cake.cake.libs.view.helpers
00021  * @since           CakePHP(tm) v 0.9.1
00022  * @version         $Revision: 675 $
00023  * @modifiedby      $LastChangedBy: gwoo $
00024  * @lastmodified    $Date: 2008-12-25 16:27:14 -0800 (Thu, 25 Dec 2008) $
00025  * @license         http://www.opensource.org/licenses/mit-license.php The MIT License
00026  */
00027 /**
00028  * Html Helper class for easy use of HTML widgets.
00029  *
00030  * HtmlHelper encloses all methods needed while working with HTML pages.
00031  *
00032  * @package     cake
00033  * @subpackage  cake.cake.libs.view.helpers
00034  */
00035 class HtmlHelper extends Helper {
00036 /**
00037  * Base URL
00038  *
00039  * @var string
00040  * @access public
00041  */
00042     var $base = null;
00043 /**
00044  * URL to current action.
00045  *
00046  * @var string
00047  * @access public
00048  */
00049     var $here = null;
00050 /**
00051  * Parameter array.
00052  *
00053  * @var array
00054  * @access public
00055  */
00056     var $params = array();
00057 /**
00058  * Current action.
00059  *
00060  * @var string
00061  * @access public
00062  */
00063     var $action = null;
00064 /**
00065  * Controller::data;
00066  *
00067  * @var array
00068  * @access public
00069  */
00070     var $data = null;
00071 /**
00072  * Name of model this helper is attached to.
00073  *
00074  * @var string
00075  * @access public
00076  */
00077     var $model = null;
00078 /**
00079  *
00080  * @var string
00081  * @access public
00082  */
00083     var $field = null;
00084 /**
00085  * Breadcrumbs.
00086  *
00087  * @var array
00088  * @access protected
00089  */
00090     var $_crumbs = array();
00091 /**
00092  * Adds a link to the breadcrumbs array.
00093  *
00094  * @param string $name Text for link
00095  * @param string $link URL for link
00096  * @return void
00097  * @access public
00098  */
00099     function addCrumb($name, $link) {
00100         $this->_crumbs[] = array($name, $link);
00101     }
00102 /**
00103  * Returns a charset META-tag.
00104  *
00105  * @param  string  $charset
00106  * @param  boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00107  * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
00108  * @access public
00109  */
00110     function charset($charset = null, $return = false) {
00111         if (is_null($charset)) {
00112             $charset = 'utf-8';
00113         }
00114         return $this->output(sprintf($this->tags['charset'], $charset), $return);
00115     }
00116 /**
00117  * Finds URL for specified action.
00118  *
00119  * Returns an URL pointing to a combination of controller and action. Param
00120  * $url can be:
00121  *  + Empty - the method will find adress to actuall controller/action.
00122  *  + '/' - the method will find base URL of application.
00123  *  + A combination of controller/action - the method will find url for it.
00124  *
00125  * @param  string  $url     Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4"
00126  * @param  boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00127  * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
00128  * @access public
00129  */
00130     function url($url = null, $return = false) {
00131         if (isset($this->plugin)) {
00132             $base = strip_plugin($this->base, $this->plugin);
00133         } else {
00134             $base = $this->base;
00135         }
00136 
00137         if (empty($url)) {
00138             return $this->here;
00139         } elseif ($url{0} == '/') {
00140             $output = $base . $url;
00141         } else {
00142             $output = $base . '/' . Inflector::underscore($this->params['controller']) . '/' . $url;
00143         }
00144 
00145         return $this->output($output, $return);
00146     }
00147 /**
00148  * Creates an HTML link.
00149  *
00150  * If $url starts with "http://" this is treated as an external link. Else,
00151  * it is treated as a path to controller/action and parsed with the
00152  * HtmlHelper::url() method.
00153  *
00154  * If the $url is empty, $title is used instead.
00155  *
00156  * @param  string  $title The content of the A tag.
00157  * @param  string  $url Cake-relative URL, or external URL (starts with http://)
00158  * @param  array    $htmlAttributes Array of HTML attributes.
00159  * @param  string  $confirmMessage Confirmation message.
00160  * @param  boolean $escapeTitle Whether or not the text in the $title variable should be HTML escaped.
00161  * @param  boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00162  * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
00163  * @access public
00164  */
00165     function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true, $return = false) {
00166         if ($escapeTitle === true) {
00167             $title = htmlspecialchars($title, ENT_QUOTES);
00168         } elseif (is_string($escapeTitle)) {
00169             $title = htmlentities($title, ENT_QUOTES);
00170         }
00171         $url = $url ? $url : $title;
00172 
00173         if ($confirmMessage) {
00174             $confirmMessage = str_replace("'", "\'", $confirmMessage);
00175             $confirmMessage = str_replace('"', '\"', $confirmMessage);
00176             $htmlAttributes['onclick']="return confirm('{$confirmMessage}');";
00177         }
00178 
00179         if (((strpos($url, '://')) || (strpos($url, 'javascript:') === 0) || (strpos($url, 'mailto:') === 0) || substr($url,0,1) == '#')) {
00180             $output = sprintf($this->tags['link'], $url, $this->_parseAttributes($htmlAttributes), $title);
00181         } else {
00182             $output = sprintf($this->tags['link'], $this->url($url, true), $this->_parseAttributes($htmlAttributes), $title);
00183         }
00184         return $this->output($output, $return);
00185     }
00186 /**
00187  * Creates a submit widget.
00188  *
00189  * @param  string  $caption Text on submit button
00190  * @param  array    $htmlAttributes Array of HTML attributes.
00191  * @param  boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00192  * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
00193  * @access public
00194  */
00195     function submit($caption = 'Submit', $htmlAttributes = array(), $return = false) {
00196         $htmlAttributes['value'] = $caption;
00197         return $this->output(sprintf($this->tags['submit'], $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
00198     }
00199 /**
00200  * Creates a password input widget.
00201  *
00202  * @param  string  $fieldName Name of a field, like this "Modelname/fieldname"
00203  * @param  array    $htmlAttributes Array of HTML attributes.
00204  * @param  boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00205  * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
00206  * @access public
00207  */
00208     function password($fieldName, $htmlAttributes = array(), $return = false) {
00209         $this->setFormTag($fieldName);
00210         if (!isset($htmlAttributes['value'])) {
00211             $htmlAttributes['value'] = $this->tagValue($fieldName);
00212         }
00213         if (!isset($htmlAttributes['id'])) {
00214             $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
00215         }
00216 
00217         if ($this->tagIsInvalid($this->model, $this->field)) {
00218             if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") {
00219                 $htmlAttributes['class'] .= ' form_error';
00220             } else {
00221                 $htmlAttributes['class'] = 'form_error';
00222             }
00223         }
00224         return $this->output(sprintf($this->tags['password'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return);
00225     }
00226 /**
00227  * Creates a textarea widget.
00228  *
00229  * @param  string  $fieldName Name of a field, like this "Modelname/fieldname"
00230  * @param  array    $htmlAttributes Array of HTML attributes.
00231  * @param  boolean $return  Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00232  * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
00233  * @access public
00234  */
00235     function textarea($fieldName, $htmlAttributes = array(), $return = false) {
00236         $this->setFormTag($fieldName);
00237         $value = $this->tagValue($fieldName);
00238         if (!empty($htmlAttributes['value'])) {
00239             $value = $htmlAttributes['value'];
00240             unset($htmlAttributes['value']);
00241         }
00242         if (!isset($htmlAttributes['id'])) {
00243             $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
00244         }
00245 
00246         if ($this->tagIsInvalid($this->model, $this->field)) {
00247             if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") {
00248                 $htmlAttributes['class'] .= ' form_error';
00249             } else {
00250                 $htmlAttributes['class'] = 'form_error';
00251             }
00252         }
00253         return $this->output(sprintf($this->tags['textarea'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' '), $value), $return);
00254     }
00255 /**
00256  * Creates a checkbox widget.
00257  *
00258  * @param  string  $fieldName Name of a field, like this "Modelname/fieldname"
00259  * @deprecated  string  $title
00260  * @param  array    $htmlAttributes Array of HTML attributes.
00261  * @param  boolean $return  Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00262  * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
00263  * @access public
00264  */
00265     function checkbox($fieldName, $title = null, $htmlAttributes = array(), $return = false) {
00266         $value = $this->tagValue($fieldName);
00267         $notCheckedValue = 0;
00268 
00269         if (!isset($htmlAttributes['id'])) {
00270             $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
00271         }
00272 
00273         if (isset($htmlAttributes['checked'])) {
00274             if ($htmlAttributes['checked'] == 'checked' || intval($htmlAttributes['checked']) === 1 || $htmlAttributes['checked'] === true) {
00275                 $htmlAttributes['checked'] = 'checked';
00276             } else {
00277                 $htmlAttributes['checked'] = null;
00278                 $notCheckedValue = -1;
00279             }
00280         } else {
00281             if (isset($htmlAttributes['value']) || (!class_exists($this->model) && !loadModel($this->model))) {
00282                 $htmlAttributes['checked'] = ($htmlAttributes['value'] == $value) ? 'checked' : null;
00283 
00284                 if ($htmlAttributes['value'] == '0') {
00285                     $notCheckedValue = -1;
00286                 }
00287             } else {
00288                 $model = new $this->model;
00289                 $db =& ConnectionManager::getDataSource($model->useDbConfig);
00290                 $value = $db->boolean($value);
00291                 $htmlAttributes['checked'] = $value ? 'checked' : null;
00292                 $htmlAttributes['value'] = 1;
00293             }
00294         }
00295 
00296         $output = $this->hidden($fieldName, array('value' => $notCheckedValue, 'id' => $htmlAttributes['id'] . '_'), true);
00297         $output .= sprintf($this->tags['checkbox'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, '', ' '));
00298         return $this->output($output, $return);
00299     }
00300 /**
00301  * Creates a link element for CSS stylesheets.
00302  *
00303  * @param string $path Path to CSS file
00304  * @param string $rel Rel attribute. Defaults to "stylesheet".
00305  * @param array $htmlAttributes Array of HTML attributes.
00306  * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00307  * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return.
00308  * @access public
00309  */
00310     function css($path, $rel = 'stylesheet', $htmlAttributes = array(), $return = false) {
00311         $url = "{$this->webroot}" . (COMPRESS_CSS ? 'c' : '') . $this->themeWeb  . CSS_URL . $path . ".css";
00312 
00313         if ($rel == 'import') {
00314             return $this->output(sprintf($this->tags['style'], $this->parseHtmlOptions($htmlAttributes, null, '', ' '), '@import url(' . $url . ');'), $return);
00315         } else {
00316             return $this->output(sprintf($this->tags['css'], $rel, $url, $this->parseHtmlOptions($htmlAttributes, null, '', ' ')), $return);
00317         }
00318     }
00319 /**
00320  * Creates file input widget.
00321  *
00322  * @param string $fieldName Name of a field, like this "Modelname/fieldname"
00323  * @param array $htmlAttributes Array of HTML attributes.
00324  * @param boolean $return Wheter this method should return a valueor output it. This overrides AUTO_OUTPUT.
00325  * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return.
00326  * @access public
00327  */
00328     function file($fieldName, $htmlAttributes = array(), $return = false) {
00329         if (strpos($fieldName, '/')) {
00330             $this->setFormTag($fieldName);
00331             if (!isset($htmlAttributes['id'])) {
00332                 $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
00333             }
00334             return $this->output(sprintf($this->tags['file'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
00335         }
00336         return $this->output(sprintf($this->tags['file_no_model'], $fieldName, $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
00337     }
00338 /**
00339  * Returns the breadcrumb trail as a sequence of &raquo;-separated links.
00340  *
00341  * @param  string  $separator Text to separate crumbs.
00342  * @param  string  $startText This will be the first crumb, if false it defaults to first crumb in array
00343  * @param  boolean $return  Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00344  * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return. If $this->_crumbs is empty, return null.
00345  * @access public
00346  */
00347     function getCrumbs($separator = '&raquo;', $startText = false, $return = false) {
00348         if (count($this->_crumbs)) {
00349             $out = array();
00350             if ($startText) {
00351                 $out[] = $this->link($startText, '/');
00352             }
00353 
00354             foreach ($this->_crumbs as $crumb) {
00355                 $out[] = $this->link($crumb[0], $crumb[1]);
00356             }
00357             return $this->output(join($separator, $out), $return);
00358         } else {
00359             return null;
00360         }
00361     }
00362 /**
00363  * Creates a hidden input field.
00364  *
00365  * @param  string  $fieldName Name of a field, like this "Modelname/fieldname"
00366  * @param  array    $htmlAttributes Array of HTML attributes.
00367  * @param  boolean $return  Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00368  * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT  and $return.
00369  * @access public
00370  */
00371     function hidden($fieldName, $htmlAttributes = array(), $return = false) {
00372         $this->setFormTag($fieldName);
00373         if (!isset($htmlAttributes['value'])) {
00374             $htmlAttributes['value'] = $this->tagValue($fieldName);
00375         }
00376         if (!isset($htmlAttributes['id'])) {
00377             $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
00378         }
00379         return $this->output(sprintf($this->tags['hidden'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return);
00380     }
00381 /**
00382  * Creates a formatted IMG element.
00383  *
00384  * @param string $path Path to the image file, relative to the webroot/img/ directory.
00385  * @param array $htmlAttributes Array of HTML attributes.
00386  * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00387  * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
00388  * @access public
00389  */
00390     function image($path, $htmlAttributes = array(), $return = false) {
00391         if (strpos($path, '://')) {
00392             $url = $path;
00393         } else {
00394             $url = $this->webroot . $this->themeWeb . IMAGES_URL . $path;
00395         }
00396         return $this->output(sprintf($this->tags['image'], $url, $this->parseHtmlOptions($htmlAttributes, null, '', ' ')), $return);
00397     }
00398 /**
00399  * Creates a text input widget.
00400  *
00401  * @param string $fieldNamem Name of a field, like this "Modelname/fieldname"
00402  * @param array $htmlAttributes Array of HTML attributes.
00403  * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00404  * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return.
00405  * @access public
00406  */
00407     function input($fieldName, $htmlAttributes = array(), $return = false) {
00408         $this->setFormTag($fieldName);
00409         if (!isset($htmlAttributes['value'])) {
00410             $htmlAttributes['value'] = $this->tagValue($fieldName);
00411         }
00412 
00413         if (!isset($htmlAttributes['type'])) {
00414             $htmlAttributes['type'] = 'text';
00415         }
00416 
00417         if (!isset($htmlAttributes['id'])) {
00418             $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
00419         }
00420 
00421         if ($this->tagIsInvalid($this->model, $this->field)) {
00422             if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") {
00423                 $htmlAttributes['class'] .= ' form_error';
00424             } else {
00425                 $htmlAttributes['class'] = 'form_error';
00426             }
00427         }
00428         return $this->output(sprintf($this->tags['input'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return);
00429     }
00430  /**
00431  * Returns a formatted SELECT element.
00432  *
00433  * @param string $fieldName Name attribute of the SELECT
00434  * @param array $optionElements Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the SELECT element
00435  * @param mixed $selected Selected option
00436  * @param array $selectAttr Array of HTML options for the opening SELECT element
00437  * @param array $optionAttr Array of HTML options for the enclosed OPTION elements
00438  * @param boolean $show_empty If true, the empty select option is shown
00439  * @param  boolean $return         Whether this method should return a value
00440  * @return string Formatted SELECT element
00441  * @access public
00442  */
00443     function selectTag($fieldName, $optionElements, $selected = null, $selectAttr = array(), $optionAttr = null, $showEmpty = true, $return = false) {
00444         $this->setFormTag($fieldName);
00445         if ($this->tagIsInvalid($this->model, $this->field)) {
00446             if (isset($selectAttr['class']) && trim($selectAttr['class']) != "") {
00447                 $selectAttr['class'] .= ' form_error';
00448             } else {
00449                 $selectAttr['class'] = 'form_error';
00450             }
00451         }
00452         if (!isset($selectAttr['id'])) {
00453             $selectAttr['id'] = $this->model . Inflector::camelize($this->field);
00454         }
00455 
00456         if (!is_array($optionElements)) {
00457             return null;
00458         }
00459 
00460         if (!isset($selected)) {
00461             $selected = $this->tagValue($fieldName);
00462         }
00463 
00464         if (isset($selectAttr) && array_key_exists("multiple", $selectAttr)) {
00465             $select[] = sprintf($this->tags['selectmultiplestart'], $this->model, $this->field, $this->parseHtmlOptions($selectAttr));
00466         } else {
00467             $select[] = sprintf($this->tags['selectstart'], $this->model, $this->field, $this->parseHtmlOptions($selectAttr));
00468         }
00469 
00470         if ($showEmpty == true) {
00471             $select[] = sprintf($this->tags['selectempty'], $this->parseHtmlOptions($optionAttr));
00472         }
00473 
00474         foreach ($optionElements as $name => $title) {
00475             $optionsHere = $optionAttr;
00476 
00477             if (($selected != null) && ($selected == $name)) {
00478                 $optionsHere['selected'] = 'selected';
00479             } elseif (is_array($selected) && in_array($name, $selected)) {
00480                 $optionsHere['selected'] = 'selected';
00481             }
00482 
00483             $select[] = sprintf($this->tags['selectoption'], $name, $this->parseHtmlOptions($optionsHere), h($title));
00484         }
00485 
00486         $select[] = sprintf($this->tags['selectend']);
00487         return $this->output(implode("\n", $select), $return);
00488     }
00489 /**
00490  * Creates a set of radio widgets.
00491  *
00492  * @param  string  $fieldName Name of a field, like this "Modelname/fieldname"
00493  * @param  array    $options            Radio button options array
00494  * @param  array    $inbetween      String that separates the radio buttons.
00495  * @param  array    $htmlAttributes Array of HTML attributes.
00496  * @param  boolean $return  Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00497  * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
00498  * @access public
00499  */
00500     function radio($fieldName, $options, $inbetween = null, $htmlAttributes = array(), $return = false) {
00501 
00502         $this->setFormTag($fieldName);
00503         $value = isset($htmlAttributes['value']) ? $htmlAttributes['value'] : $this->tagValue($fieldName);
00504         $out = array();
00505 
00506         foreach ($options as $optValue => $optTitle) {
00507             $optionsHere = array('value' => $optValue);
00508             if ($value !== false && $optValue == $value) {
00509                 $optionsHere['checked'] = 'checked';
00510             }
00511             $parsedOptions = $this->parseHtmlOptions(array_merge($htmlAttributes, $optionsHere), null, '', ' ');
00512             $individualTagName = "{$this->field}_{$optValue}";
00513             $out[] = sprintf($this->tags['radio'], $this->model, $this->field, $individualTagName, $parsedOptions, $optTitle);
00514         }
00515 
00516         $out = join($inbetween, $out);
00517         return $this->output($out ? $out : null, $return);
00518     }
00519 /**
00520  * Returns a SELECT element for days.
00521  *
00522  * @param string $tagName Prefix name for the SELECT element
00523  * @deprecated  string $value
00524  * @param string $selected Option which is selected.
00525  * @param array $optionAttr Attribute array for the option elements.
00526  * @param boolean $showEmpty Show/hide the empty select option
00527  * @return mixed
00528  * @access public
00529  */
00530     function dayOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00531         if (empty($selected) && $this->tagValue($tagName)) {
00532             $selected = date('d', strtotime($this->tagValue($tagName)));
00533         }
00534         $dayValue = empty($selected) ? ($showEmpty == true ? NULL : date('d')) : $selected;
00535         $days = array('01' => '1', '02' => '2', '03' => '3', '04' => '4', '05' => '5', '06' => '6', '07' => '7', '08' => '8', '09' => '9', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27', '28' => '28', '29' => '29', '30' => '30', '31' => '31');
00536         $option = $this->selectTag($tagName . "_day", $days, $dayValue, $selectAttr, $optionAttr, $showEmpty);
00537         return $option;
00538     }
00539 /**
00540  * Returns a SELECT element for years
00541  *
00542  * @param string $tagName Prefix name for the SELECT element
00543  * @deprecated  string $value
00544  * @param integer $minYear First year in sequence
00545  * @param integer $maxYear Last year in sequence
00546  * @param string $selected Option which is selected.
00547  * @param array $optionAttr Attribute array for the option elements.
00548  * @param boolean $showEmpty Show/hide the empty select option
00549  * @return mixed
00550  * @access public
00551  */
00552     function yearOptionTag($tagName, $value = null, $minYear = null, $maxYear = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00553         if (empty($selected) && ($this->tagValue($tagName))) {
00554             $selected = date('Y', strtotime($this->tagValue($tagName)));
00555         }
00556 
00557         $yearValue = empty($selected) ? ($showEmpty ? NULL : date('Y')) : $selected;
00558         $currentYear = date('Y');
00559         $maxYear = is_null($maxYear) ? $currentYear + 11 : $maxYear + 1;
00560         $minYear = is_null($minYear) ? $currentYear - 60 : $minYear;
00561 
00562         if ($minYear > $maxYear) {
00563             $tmpYear = $minYear;
00564             $minYear = $maxYear;
00565             $maxYear = $tmpYear;
00566         }
00567 
00568         $minYear = $currentYear < $minYear ? $currentYear : $minYear;
00569         $maxYear = $currentYear > $maxYear ? $currentYear : $maxYear;
00570 
00571         for ($yearCounter = $minYear; $yearCounter < $maxYear; $yearCounter++) {
00572             $years[$yearCounter] = $yearCounter;
00573         }
00574 
00575         return $this->selectTag($tagName . "_year", $years, $yearValue, $selectAttr, $optionAttr, $showEmpty);
00576     }
00577 /**
00578  * Returns a SELECT element for months.
00579  *
00580  * @param string $tagName Prefix name for the SELECT element
00581  * @deprecated  string $value
00582  * @param string $selected Option which is selected.
00583  * @param array $optionAttr Attribute array for the option elements.
00584  * @param boolean $showEmpty Show/hide the empty select option
00585  * @return mixed
00586  * @access public
00587  */
00588     function monthOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00589         if (empty($selected) && ($this->tagValue($tagName))) {
00590             $selected = date('m', strtotime($this->tagValue($tagName)));
00591         }
00592         $monthValue = empty($selected) ? ($showEmpty ? NULL : date('m')) : $selected;
00593         $months = array('01' => 'January', '02' => 'February', '03' => 'March', '04' => 'April', '05' => 'May', '06' => 'June', '07' => 'July', '08' => 'August', '09' => 'September', '10' => 'October', '11' => 'November', '12' => 'December');
00594 
00595         return $this->selectTag($tagName . "_month", $months, $monthValue, $selectAttr, $optionAttr, $showEmpty);
00596     }
00597 /**
00598  * Returns a SELECT element for hours.
00599  *
00600  * @param string $tagName Prefix name for the SELECT element
00601  * @deprecated  string $value
00602  * @param boolean $format24Hours True for 24 hours format
00603  * @param string $selected Option which is selected.
00604  * @param array $optionAttr Attribute array for the option elements.
00605  * @return mixed
00606  * @access public
00607  */
00608     function hourOptionTag($tagName, $value = null, $format24Hours = false, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00609         if (empty($selected) && ($this->tagValue($tagName))) {
00610             if ($format24Hours) {
00611                 $selected = date('H', strtotime($this->tagValue($tagName)));
00612             } else {
00613                 $selected = date('g', strtotime($this->tagValue($tagName)));
00614             }
00615         }
00616         if ($format24Hours) {
00617             $hourValue = empty($selected) ? ($showEmpty ? NULL : date('H')) : $selected;
00618         } else {
00619             $hourValue = empty($selected) ? ($showEmpty ? NULL : date('g')) : $selected;
00620             if (isset($selected) && intval($hourValue) == 0 && !$showEmpty) {
00621                 $hourValue = 12;
00622             }
00623         }
00624 
00625         if ($format24Hours) {
00626             $hours = array('00' => '00', '01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23');
00627         } else {
00628             $hours = array('01' => '1', '02' => '2', '03' => '3', '04' => '4', '05' => '5', '06' => '6', '07' => '7', '08' => '8', '09' => '9', '10' => '10', '11' => '11', '12' => '12');
00629         }
00630 
00631         $option = $this->selectTag($tagName . "_hour", $hours, $hourValue, $selectAttr, $optionAttr, $showEmpty);
00632         return $option;
00633     }
00634 /**
00635  * Returns a SELECT element for minutes.
00636  *
00637  * @param string $tagName Prefix name for the SELECT element
00638  * @deprecated  string $value
00639  * @param string $selected Option which is selected.
00640  * @param array $optionAttr Attribute array for the option elements.
00641  * @return mixed
00642  * @access public
00643  */
00644     function minuteOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00645         if (empty($selected) && ($this->tagValue($tagName))) {
00646             $selected = date('i', strtotime($this->tagValue($tagName)));
00647         }
00648         $minValue = empty($selected) ? ($showEmpty ? NULL : date('i')) : $selected;
00649 
00650         for ($minCount = 0; $minCount < 60; $minCount++) {
00651             $mins[sprintf('%02d', $minCount)] = sprintf('%02d', $minCount);
00652         }
00653         $option = $this->selectTag($tagName . "_min", $mins, $minValue, $selectAttr, $optionAttr, $showEmpty);
00654         return $option;
00655     }
00656 
00657 /**
00658  * Returns a SELECT element for AM or PM.
00659  *
00660  * @param string $tagName Prefix name for the SELECT element
00661  * @deprecated  string $value
00662  * @param string $selected Option which is selected.
00663  * @param array $optionAttr Attribute array for the option elements.
00664  * @return mixed
00665  * @access public
00666  */
00667     function meridianOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00668         if (empty($selected) && ($this->tagValue($tagName))) {
00669             $selected = date('a', strtotime($this->tagValue($tagName)));
00670         }
00671         $merValue = empty($selected) ? ($showEmpty ? NULL : date('a')) : $selected;
00672         $meridians = array('am' => 'am', 'pm' => 'pm');
00673 
00674         $option = $this->selectTag($tagName . "_meridian", $meridians, $merValue, $selectAttr, $optionAttr, $showEmpty);
00675         return $option;
00676     }
00677 /**
00678  * Returns a set of SELECT elements for a full datetime setup: day, month and year, and then time.
00679  *
00680  * @param string $tagName Prefix name for the SELECT element
00681  * @param string $dateFormat DMY, MDY, YMD or NONE.
00682  * @param string $timeFormat 12, 24, NONE
00683  * @param string $selected Option which is selected.
00684  * @param array $optionAttr Attribute array for the option elements.
00685  * @return string The HTML formatted OPTION element
00686  * @access public
00687  */
00688     function dateTimeOptionTag($tagName, $dateFormat = 'DMY', $timeFormat = '12', $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00689         $day      = null;
00690         $month    = null;
00691         $year     = null;
00692         $hour     = null;
00693         $min      = null;
00694         $meridian = null;
00695 
00696         if (empty($selected)) {
00697             $selected = $this->tagValue($tagName);
00698         }
00699 
00700         if (!empty($selected)) {
00701 
00702             if (is_int($selected)) {
00703                 $selected = strftime('%Y-%m-%d %H:%M:%S', $selected);
00704             }
00705 
00706             $meridian = 'am';
00707             $pos = strpos($selected, '-');
00708             if ($pos !== false) {
00709                 $date = explode('-', $selected);
00710                 $days = explode(' ', $date[2]);
00711                 $day = $days[0];
00712                 $month = $date[1];
00713                 $year = $date[0];
00714             } else {
00715                 $days[1] = $selected;
00716             }
00717 
00718             if ($timeFormat != 'NONE' && !empty($timeFormat)) {
00719                 $time = explode(':', $days[1]);
00720                 $check = str_replace(':', '', $days[1]);
00721 
00722                 if (($check > 115959) && $timeFormat == '12') {
00723                     $time[0] = $time[0] - 12;
00724                     $meridian = 'pm';
00725                 } elseif ($time[0] > 12) {
00726                     $meridian = 'pm';
00727                 }
00728 
00729                 $hour = $time[0];
00730                 $min = $time[1];
00731             }
00732         }
00733 
00734         $elements = array('Day','Month','Year','Hour','Minute','Meridian');
00735         if (isset($selectAttr['id'])) {
00736             if (is_string($selectAttr['id'])) {
00737                 // build out an array version
00738                 foreach ($elements as $element) {
00739                     $selectAttrName = 'select' . $element . 'Attr';
00740                     ${$selectAttrName} = $selectAttr;
00741                     ${$selectAttrName}['id'] = $selectAttr['id'] . $element;
00742                 }
00743             } elseif (is_array($selectAttr['id'])) {
00744                 // check for missing ones and build selectAttr for each element
00745                 foreach ($elements as $element) {
00746                     $selectAttrName = 'select' . $element . 'Attr';
00747                     ${$selectAttrName} = $selectAttr;
00748                     ${$selectAttrName}['id'] = $selectAttr['id'][strtolower($element)];
00749                 }
00750             }
00751         } else {
00752             // build the selectAttrName with empty id's to pass
00753             foreach ($elements as $element) {
00754                 $selectAttrName = 'select' . $element . 'Attr';
00755                 ${$selectAttrName} = $selectAttr;
00756             }
00757         }
00758 
00759         switch($dateFormat) {
00760             case 'DMY': // so uses the new selex
00761                 $opt = $this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty) . '-' .
00762                 $this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' . $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty);
00763             break;
00764             case 'MDY':
00765                 $opt = $this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' .
00766                 $this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty) . '-' . $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty);
00767             break;
00768             case 'YMD':
00769                 $opt = $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty) . '-' .
00770                 $this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' .
00771                 $this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty);
00772             break;
00773             case 'Y':
00774                 $opt = $this->yearOptionTag($tagName, null, null, null, $selected, $selectYearAttr, $optionAttr, $showEmpty);
00775             break;
00776             case 'NONE':
00777             default:
00778                 $opt = '';
00779             break;
00780         }
00781 
00782         switch($timeFormat) {
00783             case '24':
00784                 $opt .= $this->hourOptionTag($tagName, null, true, $hour, $selectHourAttr, $optionAttr, $showEmpty) . ':' .
00785                 $this->minuteOptionTag($tagName, null, $min, $selectMinuteAttr, $optionAttr, $showEmpty);
00786             break;
00787             case '12':
00788                 $opt .= $this->hourOptionTag($tagName, null, false, $hour, $selectHourAttr, $optionAttr, $showEmpty) . ':' .
00789                 $this->minuteOptionTag($tagName, null, $min, $selectMinuteAttr, $optionAttr, $showEmpty) . ' ' .
00790                 $this->meridianOptionTag($tagName, null, $meridian, $selectMeridianAttr, $optionAttr, $showEmpty);
00791             break;
00792             case 'NONE':
00793             default:
00794                 $opt .= '';
00795             break;
00796         }
00797         return $opt;
00798     }
00799 /**
00800  * Returns a row of formatted and named TABLE headers.
00801  *
00802  * @param array $names      Array of tablenames.
00803  * @param array $trOptions  HTML options for TR elements.
00804  * @param array $thOptions  HTML options for TH elements.
00805  * @param  boolean $return  Wheter this method should return a value
00806  * @return string
00807  * @access public
00808  */
00809     function tableHeaders($names, $trOptions = null, $thOptions = null, $return = false) {
00810         $out = array();
00811         foreach ($names as $arg) {
00812             $out[] = sprintf($this->tags['tableheader'], $this->parseHtmlOptions($thOptions), $arg);
00813         }
00814 
00815         $data = sprintf($this->tags['tablerow'], $this->parseHtmlOptions($trOptions), join(' ', $out));
00816         return $this->output($data, $return);
00817     }
00818 /**
00819  * Returns a formatted string of table rows (TR's with TD's in them).
00820  *
00821  * @param array $data       Array of table data
00822  * @param array $oddTrOptionsHTML options for odd TR elements
00823  * @param array $evenTrOptionsHTML options for even TR elements
00824  * @param  boolean $return  Wheter this method should return a value
00825  * @return string   Formatted HTML
00826  * @access public
00827  */
00828     function tableCells($data, $oddTrOptions = null, $evenTrOptions = null, $return = false) {
00829         if (empty($data[0]) || !is_array($data[0])) {
00830             $data = array($data);
00831         }
00832         static $count = 0;
00833 
00834         foreach ($data as $line) {
00835             $count++;
00836             $cellsOut = array();
00837 
00838             foreach ($line as $cell) {
00839                 $cellsOut[] = sprintf($this->tags['tablecell'], null, $cell);
00840             }
00841             $options = $this->parseHtmlOptions($count % 2 ? $oddTrOptions : $evenTrOptions);
00842             $out[] = sprintf($this->tags['tablerow'], $options, join(' ', $cellsOut));
00843         }
00844         return $this->output(join("\n", $out), $return);
00845     }
00846 /**
00847  * Generates a nested unordered list tree from an array.
00848  *
00849  * @param array $data
00850  * @param array $htmlAttributes
00851  * @param string  $bodyKey
00852  * @param string  $childrenKey
00853  * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
00854  * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return. If $this->_crumbs is empty, return null.
00855  * @access public
00856  */
00857     function guiListTree($data, $htmlAttributes = array(), $bodyKey = 'body', $childrenKey = 'children', $return = false) {
00858         $out="<ul" . $this->_parseAttributes($htmlAttributes) . ">\n";
00859         foreach ($data as $item) {
00860                 $out .= "<li>{$item[$bodyKey]}\n";
00861                 if (isset($item[$childrenKey]) && is_array($item[$childrenKey]) && count($item[$childrenKey])) {
00862                     $out .= $this->guiListTree($item[$childrenKey], $htmlAttributes, $bodyKey, $childrenKey);
00863                 }
00864                 $out .= "</li>\n";
00865         }
00866         $out .= "</ul>\n";
00867         return $this->output($out, $return);
00868     }
00869 /**
00870  * Returns value of $fieldName. False if the tag does not exist.
00871  *
00872  * @param string $fieldName     Fieldname as "Modelname/fieldname" string
00873  * @return string htmlspecialchars Value of the named tag.
00874  * @access public
00875  */
00876     function tagValue($fieldName, $escape = false) {
00877         $this->setFormTag($fieldName);
00878         if (isset($this->params['data'][$this->model][$this->field])) {
00879             return ife($escape, h($this->params['data'][$this->model][$this->field]), $this->params['data'][$this->model][$this->field]);
00880         } elseif (isset($this->data[$this->model][$this->field])) {
00881             return ife($escape, h($this->data[$this->model][$this->field]), $this->data[$this->model][$this->field]);
00882         }
00883         return false;
00884     }
00885 /**
00886  * Returns false if given FORM field has no errors. Otherwise it returns the constant set in the array Model->validationErrors.
00887  *
00888  * @param string $model Model name as string
00889  * @param string $field     Fieldname as string
00890  * @return boolean True on errors.
00891  * @access public
00892  */
00893     function tagIsInvalid($model, $field) {
00894         return empty($this->validationErrors[$model][$field]) ? 0 : $this->validationErrors[$model][$field];
00895     }
00896 /**
00897  * Returns number of errors in a submitted FORM.
00898  *
00899  * @return int Number of errors
00900  * @access public
00901  */
00902     function validate() {
00903         $args = func_get_args();
00904         $errors = call_user_func_array(array(&$this, 'validateErrors'),  $args);
00905         return count($errors);
00906     }
00907 /**
00908  * Validates a FORM according to the rules set up in the Model.
00909  *
00910  * @return int Number of errors
00911  * @access public
00912  */
00913     function validateErrors() {
00914         $objects = func_get_args();
00915         if (!count($objects)) {
00916             return false;
00917         }
00918 
00919         $errors = array();
00920         foreach ($objects as $object) {
00921             $errors = array_merge($errors, $object->invalidFields($object->data));
00922         }
00923         return $this->validationErrors = (count($errors) ? $errors : false);
00924     }
00925 /**
00926  * Returns a formatted error message for given FORM field, NULL if no errors.
00927  *
00928  * @param string $field A field name, like "Modelname/fieldname"
00929  * @param string $text      Error message
00930  * @return string If there are errors this method returns an error message, else NULL.
00931  * @access public
00932  */
00933     function tagErrorMsg($field, $text) {
00934         $error = 1;
00935         $this->setFormTag($field);
00936         if ($error == $this->tagIsInvalid($this->model, $this->field)) {
00937             return sprintf('<div class="error_message">%s</div>', is_array($text) ? (empty($text[$error - 1]) ? 'Error in field' : $text[$error - 1]) : $text);
00938         } else {
00939             return null;
00940         }
00941     }
00942 /**
00943  * Sets this helper's model and field properties to the slash-separated value-pair in $tagValue.
00944  *
00945  * @param string $tagValue A field name, like "Modelname/fieldname"
00946  * @return
00947  * @access public
00948  */
00949     function setFormTag($tagValue) {
00950         return list($this->model, $this->field) = explode("/", $tagValue);
00951     }
00952 /**
00953  * Returns a space-delimited string with items of the $options array. If a
00954  * key of $options array happens to be one of:
00955  *  + 'compact'
00956  *  + 'checked'
00957  *  + 'declare'
00958  *  + 'readonly'
00959  *  + 'disabled'
00960  *  + 'selected'
00961  *  + 'defer'
00962  *  + 'ismap'
00963  *  + 'nohref'
00964  *  + 'noshade'
00965  *  + 'nowrap'
00966  *  + 'multiple'
00967  *  + 'noresize'
00968  *
00969  * And its value is one of:
00970  *  + 1
00971  *  + true
00972  *  + 'true'
00973  *
00974  * Then the value will be reset to be identical with key's name.
00975  * If the value is not one of these 3, the parameter is not output.
00976  *
00977  * @param  array  $options Array of options.
00978  * @param  array  $exclude Array of options to be excluded.
00979  * @param  string $insertBefore String to be inserted before options.
00980  * @param  string $insertAfter  String to be inserted ater options.
00981  * @return string
00982  * @access protected
00983  */
00984     function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
00985         if (is_array($options)) {
00986             $default = array (
00987                 'escape' => true
00988             );
00989             $options = am($default, $options);
00990             if (!is_array($exclude)) {
00991                 $exclude = array();
00992             }
00993             $exclude = am($exclude, array('escape'));
00994             $keys = array_diff(array_keys($options), $exclude);
00995             $values = array_intersect_key(array_values($options), $keys);
00996             $escape = $options['escape'];
00997             $attributes = array();
00998             foreach ($keys as $index => $key) {
00999                 $attributes[] = $this->__formatAttribute($key, $values[$index], $escape);
01000             }
01001             $out = implode(' ', $attributes);
01002         } else {
01003             $out = $options;
01004         }
01005         return $out ? $insertBefore . $out . $insertAfter : '';
01006     }
01007 /**
01008  * @param  string $key
01009  * @param  string $value
01010  * @return string
01011  * @access private
01012  */
01013     function __formatAttribute($key, $value, $escape = true) {
01014         $attribute = '';
01015         $attributeFormat = '%s="%s"';
01016         $minimizedAttributes = array('compact', 'checked', 'declare', 'readonly', 'disabled', 'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize');
01017 
01018         if (in_array($key, $minimizedAttributes)) {
01019             if ($value === 1 || $value === true || $value === 'true' || $value == $key) {
01020                 $attribute = sprintf($attributeFormat, $key, $key);
01021             }
01022         } else {
01023             $attribute = sprintf($attributeFormat, $key, ife($escape, h($value), $value));
01024         }
01025         return $attribute;
01026     }
01027 /**
01028  * @deprecated Name changed to 'textarea'. Version 0.9.2.
01029  * @see     HtmlHelper::textarea()
01030  */
01031     function areaTag($tagName, $cols = 60, $rows = 10, $htmlAttributes = array(), $return = false) {
01032         $htmlAttributes['cols']=$cols;
01033         $htmlAttributes['rows']=$rows;
01034         return $this->textarea($tagName, $htmlAttributes, $return);
01035     }
01036 /**
01037  * @deprecated Name changed to 'charset'. Version 0.9.2.
01038  * @see     HtmlHelper::charset()
01039  */
01040     function charsetTag($charset, $return = false) {
01041         return $this->charset($charset, $return);
01042     }
01043 /**
01044  * @deprecated Name changed to 'checkbox'. Version 0.9.2.
01045  * @see     HtmlHelper::checkbox()
01046  */
01047     function checkboxTag($fieldName, $title = null, $htmlAttributes = array(), $return = false) {
01048         return $this->checkbox($fieldName, $title, $htmlAttributes, $return);
01049     }
01050 /**
01051  * @deprecated Name changed to 'css'. Version 0.9.2.
01052  * @see HtmlHelper::css()
01053  */
01054     function cssTag($path, $rel = 'stylesheet', $htmlAttributes = array(), $return = false) {
01055         return $this->css($path, $rel, $htmlAttributes, $return);
01056     }
01057 /**
01058  * @deprecated Name changed to 'file'. Version 0.9.2.
01059  * @see HtmlHelper::file()
01060  */
01061     function fileTag($fieldName, $htmlAttributes = array(), $return = false) {
01062         return $this->file($fieldName, $htmlAttributes, $return);
01063     }
01064 /**
01065  * @deprecated Name changed to 'hidden'. Version 0.9.2.
01066  * @see     HtmlHelper::hidden()
01067  */
01068     function hiddenTag($tagName, $value = null, $htmlOptions = null) {
01069         $this->setFormTag($tagName);
01070         $htmlOptions['value'] = $value ? $value : $this->tagValue($tagName);
01071         return $this->output(sprintf($this->tags['hidden'], $this->model, $this->field, $this->parseHtmlOptions($htmlOptions, null, '', ' ')));
01072     }
01073 /**
01074  * @deprecated Name changed to 'image'. Version 0.9.2.
01075  * @see     HtmlHelper::image()
01076  */
01077     function imageTag($path, $alt = null, $htmlAttributes = array(), $return = false) {
01078         $htmlAttributes['alt'] = $alt;
01079         return $this->image($path, $htmlAttributes, $return);
01080     }
01081 /**
01082  * @deprecated Name changed to 'input'. Version 0.9.2.
01083  * @see HtmlHelper::input()
01084  */
01085     function inputTag($tagName, $size = 20, $htmlOptions = null) {
01086         $this->setFormTag($tagName);
01087         $htmlOptions['value'] = isset($htmlOptions['value']) ? $htmlOptions['value'] : $this->tagValue($tagName);
01088         $this->tagIsInvalid($this->model, $this->field) ? $htmlOptions['class'] = 'form_error' : null;
01089         return $this->output(sprintf($this->tags['input'], $this->model, $this->field, $this->parseHtmlOptions($htmlOptions, null, '', ' ')));
01090     }
01091 /**
01092  * @deprecated Unified with 'link'. Version 0.9.2.
01093  * @see HtmlHelper::link()
01094  */
01095     function linkOut($title, $url = null, $htmlAttributes = array(), $escapeTitle = true, $return = false) {
01096         return $this->link($title, $url, $htmlAttributes, false, $escapeTitle, $return);
01097     }
01098 /**
01099  * @deprecated Unified with 'link'. Version 0.9.2.
01100  * @see HtmlHelper::link()
01101  */
01102     function linkTo($title, $url, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true, $return = false) {
01103         return $this->link($title, $url, $htmlAttributes, $confirmMessage, $escapeTitle, $return);
01104     }
01105 /**
01106  * @deprecated Name changed to '_parseAttributes'. Version 0.9.2.
01107  * @see HtmlHelper::_parseAttributes()
01108  */
01109     function parseHtmlOptions($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
01110         if (!is_array($exclude))
01111                 $exclude=array();
01112 
01113         if (is_array($options)) {
01114                 $out=array();
01115 
01116                 foreach ($options as $k => $v) {
01117                     if (!in_array($k, $exclude)) {
01118                         $out[] = "{$k}=\"{$v}\"";
01119                     }
01120                 }
01121                 $out = join(' ', $out);
01122                 return $out ? $insertBefore . $out . $insertAfter : null;
01123         } else {
01124                 return $options ? $insertBefore . $options . $insertAfter : null;
01125         }
01126     }
01127 /**
01128  * @deprecated Name changed to 'password'. Version 0.9.2.
01129  * @see HtmlHelper::password()
01130  */
01131     function passwordTag($fieldName, $size = 20, $htmlAttributes = array(), $return = false) {
01132         $args = func_get_args();
01133         return call_user_func_array(array(&$this,
01134                     "password"),       $args);
01135     }
01136 /**
01137  * @deprecated Name changed to 'radio'. Version 0.9.2.
01138  * @see HtmlHelper::radio()
01139  */
01140     function radioTags($fieldName, $options, $inbetween = null, $htmlAttributes = array(), $return = false) {
01141         return $this->radio($fieldName, $options, $inbetween, $htmlAttributes, $return);
01142     }
01143 /**
01144  * @deprecated Name changed to 'url'. Version 0.9.2.
01145  * @see HtmlHelper::url()
01146  */
01147     function urlFor($url) {
01148         return $this->url($url);
01149     }
01150 /**
01151  * @deprecated Name changed to 'submit'. Version 0.9.2.
01152  * @see HtmlHelper::submit()
01153  */
01154     function submitTag() {
01155         $args = func_get_args();
01156         return call_user_func_array(array(&$this, "submit"), $args);
01157     }
01158 /*************************************************************************
01159  * Moved methods
01160  *************************************************************************/
01161 /**
01162  * @deprecated Moved to TextHelper. Version 0.9.2.
01163  */
01164     function trim() {
01165         die("Method HtmlHelper::trim() was moved to TextHelper::trim().");
01166     }
01167 /**
01168  * @deprecated Moved to JavascriptHelper. Version 0.9.2.
01169  */
01170     function javascriptIncludeTag($url) {
01171         die("Method HtmlHelper::javascriptIncludeTag() was moved to JavascriptHelper::link().");
01172     }
01173 /**
01174  * @deprecated Moved to JavascriptHelper. Version 0.9.2.
01175  */
01176     function javascriptTag($script) {
01177         die("Method HtmlHelper::javascriptTag() was moved to JavascriptHelper::codeBlock().");
01178     }
01179 /**
01180  * This is very WYSIWYG unfriendly, use HtmlHelper::url() to get contents of "action" attribute. Version 0.9.2.
01181  * @deprecated Version 0.9.2. Will not be available after 1.1.x.x
01182  * @see FormHelper::create()
01183  */
01184     function formTag($target = null, $type = 'post', $htmlAttributes = array()) {
01185         $htmlAttributes['action']=$this->urlFor ($target);
01186         $htmlAttributes['method']=$type == 'get' ? 'get' : 'post';
01187         $type == 'file' ? $htmlAttributes['enctype'] = 'multipart/form-data' : null;
01188 
01189         $append = '';
01190 
01191         if (isset($this->params['_Token']) && !empty($this->params['_Token'])) {
01192                 $append .= '<p style="display: inline; margin: 0px; padding: 0px;">';
01193                 $append .= $this->hidden('_Token/key', array('value' => $this->params['_Token']['key'], 'id' => '_TokenKey' . mt_rand()), true);
01194                 $append .= '</p>';
01195         }
01196 
01197         return sprintf($this->tags['form'], $this->parseHtmlOptions($htmlAttributes, null, '')) . $append;
01198     }
01199 /**
01200  * This should be done using a content filter.
01201  * @deprecated Version 0.9.2. Will not be available after 1.1.x.x
01202  */
01203     function linkEmail($title, $email = null, $options = null) {
01204         // if no $email, then title contains the email.
01205         if (empty($email))
01206                 $email=$title;
01207 
01208         $match=array();
01209 
01210         // does the address contain extra attributes?
01211         preg_match('!^(.*)(\?.*)$!', $email, $match);
01212 
01213         // plaintext
01214         if (empty($options['encode']) || !empty($match[2])) {
01215                 return sprintf($this->tags['mailto'], $email, $this->parseHtmlOptions($options), $title);
01216         }
01217         // encoded to avoid spiders
01218         else {
01219                 $email_encoded=null;
01220 
01221                 for ($ii = 0; $ii < strlen($email); $ii++) {
01222                     if (preg_match('!\w!', $email[$ii])) {
01223                         $email_encoded .= '%' . bin2hex($email[$ii]);
01224                     } else {
01225                         $email_encoded .= $email[$ii];
01226                     }
01227                 }
01228 
01229                 $title_encoded=null;
01230 
01231                 for ($ii = 0; $ii < strlen($title); $ii++) {
01232                     $title_encoded .= preg_match('/^[A-Za-z0-9]$/', $title[$ii])
01233                         ? '&#x' . bin2hex($title[$ii]) . ';' : $title[$ii];
01234                 }
01235 
01236                 return sprintf($this->tags['mailto'],                              $email_encoded,
01237                                     $this->parseHtmlOptions($options, array('encode')), $title_encoded);
01238         }
01239     }
01240 
01241 /**
01242  * @deprecated Version 0.9.2. Will not be available after 1.1.x.x
01243  */
01244     function tag($name, $options = null, $open = false) {
01245         $tag = "<$name " . $this->parseHtmlOptions($options);
01246         $tag .= $open ? ">" : " />";
01247         return $tag;
01248     }
01249 /**
01250  * @deprecated Version 0.9.2. Will not be available after 1.1.x.x
01251  */
01252     function contentTag($name, $content, $options = null) {
01253         return "<$name " . $this->parseHtmlOptions($options) . ">$content</$name>";
01254     }
01255 
01256 }
01257 ?>