[ Index ]
 

Code source de CakePHP 1.1.13.4450

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/cake/libs/view/helpers/ -> html.php (source)

   1  <?php
   2  /* SVN FILE: $Id: html.php 4409 2007-02-02 13:20:59Z phpnut $ */
   3  /**
   4   * Html Helper class file.
   5   *
   6   * Simplifies the construction of HTML elements.
   7   *
   8   * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
   9   * Copyright 2005-2007, Cake Software Foundation, Inc.
  10   *                                1785 E. Sahara Avenue, Suite 490-204
  11   *                                Las Vegas, Nevada 89104
  12   *
  13   * Licensed under The MIT License
  14   * Redistributions of files must retain the above copyright notice.
  15   *
  16   * @filesource
  17   * @copyright        Copyright 2005-2007, Cake Software Foundation, Inc.
  18   * @link                http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
  19   * @package            cake
  20   * @subpackage        cake.cake.libs.view.helpers
  21   * @since            CakePHP(tm) v 0.9.1
  22   * @version            $Revision: 4409 $
  23   * @modifiedby        $LastChangedBy: phpnut $
  24   * @lastmodified    $Date: 2007-02-02 07:20:59 -0600 (Fri, 02 Feb 2007) $
  25   * @license            http://www.opensource.org/licenses/mit-license.php The MIT License
  26   */
  27  /**
  28   * Html Helper class for easy use of HTML widgets.
  29   *
  30   * HtmlHelper encloses all methods needed while working with HTML pages.
  31   *
  32   * @package        cake
  33   * @subpackage    cake.cake.libs.view.helpers
  34   */
  35  class HtmlHelper extends Helper {
  36  /**
  37   * Base URL
  38   *
  39   * @var string
  40   * @access public
  41   */
  42      var $base = null;
  43  /**
  44   * URL to current action.
  45   *
  46   * @var string
  47   * @access public
  48   */
  49      var $here = null;
  50  /**
  51   * Parameter array.
  52   *
  53   * @var array
  54   * @access public
  55   */
  56      var $params = array();
  57  /**
  58   * Current action.
  59   *
  60   * @var string
  61   * @access public
  62   */
  63      var $action = null;
  64  /**
  65   * Controller::data;
  66   *
  67   * @var array
  68   * @access public
  69   */
  70      var $data = null;
  71  /**
  72   * Name of model this helper is attached to.
  73   *
  74   * @var string
  75   * @access public
  76   */
  77      var $model = null;
  78  /**
  79   *
  80   * @var string
  81   * @access public
  82   */
  83      var $field = null;
  84  /**
  85   * Breadcrumbs.
  86   *
  87   * @var    array
  88   * @access protected
  89   */
  90      var $_crumbs = array();
  91  /**
  92   * Adds a link to the breadcrumbs array.
  93   *
  94   * @param string $name Text for link
  95   * @param string $link URL for link
  96   * @return void
  97   * @access public
  98   */
  99  	function addCrumb($name, $link) {
 100          $this->_crumbs[] = array($name, $link);
 101      }
 102  /**
 103   * Returns a charset META-tag.
 104   *
 105   * @param  string  $charset
 106   * @param  boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 107   * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
 108   * @access public
 109   */
 110  	function charset($charset, $return = false) {
 111          return $this->output(sprintf($this->tags['charset'], $charset), $return);
 112      }
 113  /**
 114   * Finds URL for specified action.
 115   *
 116   * Returns an URL pointing to a combination of controller and action. Param
 117   * $url can be:
 118   *    + Empty - the method will find adress to actuall controller/action.
 119   *    + '/' - the method will find base URL of application.
 120   *    + A combination of controller/action - the method will find url for it.
 121   *
 122   * @param  string  $url        Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4"
 123   * @param  boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 124   * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
 125   * @access public
 126   */
 127  	function url($url = null, $return = false) {
 128          if (isset($this->plugin)) {
 129              $base = strip_plugin($this->base, $this->plugin);
 130          } else {
 131              $base = $this->base;
 132          }
 133  
 134          if (empty($url)) {
 135              return $this->here;
 136          } elseif($url{0} == '/') {
 137              $output = $base . $url;
 138          } else {
 139              $output = $base . '/' . Inflector::underscore($this->params['controller']) . '/' . $url;
 140          }
 141  
 142          return $this->output($output, $return);
 143      }
 144  /**
 145   * Creates an HTML link.
 146   *
 147   * If $url starts with "http://" this is treated as an external link. Else,
 148   * it is treated as a path to controller/action and parsed with the
 149   * HtmlHelper::url() method.
 150   *
 151   * If the $url is empty, $title is used instead.
 152   *
 153   * @param  string  $title The content of the A tag.
 154   * @param  string  $url Cake-relative URL, or external URL (starts with http://)
 155   * @param  array    $htmlAttributes Array of HTML attributes.
 156   * @param  string  $confirmMessage Confirmation message.
 157   * @param  boolean $escapeTitle    Whether or not the text in the $title variable should be HTML escaped.
 158   * @param  boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 159   * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
 160   * @access public
 161   */
 162  	function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true, $return = false) {
 163          if ($escapeTitle === true) {
 164              $title = htmlspecialchars($title, ENT_QUOTES);
 165          } elseif (is_string($escapeTitle)) {
 166              $title = htmlentities($title, ENT_QUOTES);
 167          }
 168          $url = $url ? $url : $title;
 169  
 170          if ($confirmMessage) {
 171              if ($escapeTitle === true || is_string($escapeTitle)) {
 172                  $confirmMessage = htmlspecialchars($confirmMessage, ENT_NOQUOTES);
 173              } else {
 174                  $confirmMessage = htmlentities($confirmMessage, ENT_NOQUOTES);
 175              }
 176              $confirmMessage = str_replace("'", "\'", $confirmMessage);
 177              $confirmMessage = str_replace('"', '&quot;', $confirmMessage);
 178              $htmlAttributes['onclick']="return confirm('{$confirmMessage}');";
 179          }
 180  
 181          if (((strpos($url, '://')) || (strpos($url, 'javascript:') === 0) || (strpos($url, 'mailto:') === 0) || $url{0} == '#')) {
 182              $output = sprintf($this->tags['link'], $url, $this->_parseAttributes($htmlAttributes), $title);
 183          } else {
 184              $output = sprintf($this->tags['link'], $this->url($url, true), $this->_parseAttributes($htmlAttributes), $title);
 185          }
 186          return $this->output($output, $return);
 187      }
 188  /**
 189   * Creates a submit widget.
 190   *
 191   * @param  string  $caption Text on submit button
 192   * @param  array    $htmlAttributes Array of HTML attributes.
 193   * @param  boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 194   * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
 195   * @access public
 196   */
 197  	function submit($caption = 'Submit', $htmlAttributes = array(), $return = false) {
 198          $htmlAttributes['value'] = $caption;
 199          return $this->output(sprintf($this->tags['submit'], $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
 200      }
 201  /**
 202   * Creates a password input widget.
 203   *
 204   * @param  string  $fieldName Name of a field, like this "Modelname/fieldname"
 205   * @param  array    $htmlAttributes Array of HTML attributes.
 206   * @param  boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 207   * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
 208   * @access public
 209   */
 210  	function password($fieldName, $htmlAttributes = array(), $return = false) {
 211          $this->setFormTag($fieldName);
 212          if (!isset($htmlAttributes['value'])) {
 213              $htmlAttributes['value'] = $this->tagValue($fieldName);
 214          }
 215          if (!isset($htmlAttributes['id'])) {
 216              $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
 217          }
 218  
 219          if ($this->tagIsInvalid($this->model, $this->field)) {
 220              if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") {
 221                  $htmlAttributes['class'] .= ' form_error';
 222              } else {
 223                  $htmlAttributes['class'] = 'form_error';
 224              }
 225          }
 226          return $this->output(sprintf($this->tags['password'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return);
 227      }
 228  /**
 229   * Creates a textarea widget.
 230   *
 231   * @param  string  $fieldName Name of a field, like this "Modelname/fieldname"
 232   * @param  array    $htmlAttributes Array of HTML attributes.
 233   * @param  boolean $return    Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 234   * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
 235   * @access public
 236   */
 237  	function textarea($fieldName, $htmlAttributes = array(), $return = false) {
 238          $this->setFormTag($fieldName);
 239          $value = $this->tagValue($fieldName);
 240          if (!empty($htmlAttributes['value'])) {
 241              $value = $htmlAttributes['value'];
 242              unset($htmlAttributes['value']);
 243          }
 244          if (!isset($htmlAttributes['id'])) {
 245              $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
 246          }
 247  
 248          if ($this->tagIsInvalid($this->model, $this->field)) {
 249              if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") {
 250                  $htmlAttributes['class'] .= ' form_error';
 251              } else {
 252                  $htmlAttributes['class'] = 'form_error';
 253              }
 254          }
 255          return $this->output(sprintf($this->tags['textarea'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' '), $value), $return);
 256      }
 257  /**
 258   * Creates a checkbox widget.
 259   *
 260   * @param  string  $fieldName Name of a field, like this "Modelname/fieldname"
 261   * @deprecated  string  $title
 262   * @param  array    $htmlAttributes Array of HTML attributes.
 263   * @param  boolean $return    Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 264   * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
 265   * @access public
 266   */
 267  	function checkbox($fieldName, $title = null, $htmlAttributes = array(), $return = false) {
 268          $value = $this->tagValue($fieldName);
 269          $notCheckedValue = 0;
 270  
 271          if (!isset($htmlAttributes['id'])) {
 272              $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
 273          }
 274  
 275          if (isset($htmlAttributes['checked'])) {
 276              if ($htmlAttributes['checked'] == 'checked' || intval($htmlAttributes['checked']) === 1 || $htmlAttributes['checked'] === true) {
 277                  $htmlAttributes['checked'] = 'checked';
 278              } else {
 279                  $htmlAttributes['checked'] = null;
 280                  $notCheckedValue = -1;
 281              }
 282          } else {
 283              if (isset($htmlAttributes['value']) || (!class_exists($this->model) && !loadModel($this->model))) {
 284                  $htmlAttributes['checked'] = ($htmlAttributes['value'] == $value) ? 'checked' : null;
 285  
 286                  if ($htmlAttributes['value'] == '0') {
 287                      $notCheckedValue = -1;
 288                  }
 289              } else {
 290                  $model = new $this->model;
 291                  $db =& ConnectionManager::getDataSource($model->useDbConfig);
 292                  $value = $db->boolean($value);
 293                  $htmlAttributes['checked'] = $value ? 'checked' : null;
 294                  $htmlAttributes['value'] = 1;
 295              }
 296          }
 297  
 298          $output = $this->hidden($fieldName, array('value' => $notCheckedValue, 'id' => $htmlAttributes['id'] . '_'), true);
 299          $output .= sprintf($this->tags['checkbox'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, '', ' '));
 300          return $this->output($output, $return);
 301      }
 302  /**
 303   * Creates a link element for CSS stylesheets.
 304   *
 305   * @param string $path Path to CSS file
 306   * @param string $rel Rel attribute. Defaults to "stylesheet".
 307   * @param array $htmlAttributes Array of HTML attributes.
 308   * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 309   * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return.
 310   * @access public
 311   */
 312  	function css($path, $rel = 'stylesheet', $htmlAttributes = array(), $return = false) {
 313          $url = "{$this->webroot}" . (COMPRESS_CSS ? 'c' : '') . $this->themeWeb  . CSS_URL . $path . ".css";
 314  
 315          if ($rel == 'import') {
 316              return $this->output(sprintf($this->tags['style'], $this->parseHtmlOptions($htmlAttributes, null, '', ' '), '@import url(' . $url . ');'), $return);
 317          } else {
 318              return $this->output(sprintf($this->tags['css'], $rel, $url, $this->parseHtmlOptions($htmlAttributes, null, '', ' ')), $return);
 319          }
 320      }
 321  /**
 322   * Creates file input widget.
 323   *
 324   * @param string $fieldName Name of a field, like this "Modelname/fieldname"
 325   * @param array $htmlAttributes Array of HTML attributes.
 326   * @param boolean $return Wheter this method should return a valueor output it. This overrides AUTO_OUTPUT.
 327   * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return.
 328   * @access public
 329   */
 330  	function file($fieldName, $htmlAttributes = array(), $return = false) {
 331          if (strpos($fieldName, '/')) {
 332              $this->setFormTag($fieldName);
 333              if (!isset($htmlAttributes['id'])) {
 334                  $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
 335              }
 336              return $this->output(sprintf($this->tags['file'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
 337          }
 338          return $this->output(sprintf($this->tags['file_no_model'], $fieldName, $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
 339      }
 340  /**
 341   * Returns the breadcrumb trail as a sequence of &raquo;-separated links.
 342   *
 343   * @param  string  $separator Text to separate crumbs.
 344   * @param  string  $startText This will be the first crumb, if false it defaults to first crumb in array
 345   * @param  boolean $return    Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 346   * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return. If $this->_crumbs is empty, return null.
 347   * @access public
 348   */
 349  	function getCrumbs($separator = '&raquo;', $startText = false, $return = false) {
 350          if (count($this->_crumbs)) {
 351              $out = array();
 352              if ($startText) {
 353                  $out[] = $this->link($startText, '/');
 354              }
 355  
 356              foreach($this->_crumbs as $crumb) {
 357                  $out[] = $this->link($crumb[0], $crumb[1]);
 358              }
 359              return $this->output(join($separator, $out), $return);
 360          } else {
 361              return null;
 362          }
 363      }
 364  /**
 365   * Creates a hidden input field.
 366   *
 367   * @param  string  $fieldName Name of a field, like this "Modelname/fieldname"
 368   * @param  array    $htmlAttributes Array of HTML attributes.
 369   * @param  boolean $return    Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 370   * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT  and $return.
 371   * @access public
 372   */
 373  	function hidden($fieldName, $htmlAttributes = array(), $return = false) {
 374          $this->setFormTag($fieldName);
 375          if (!isset($htmlAttributes['value'])) {
 376              $htmlAttributes['value'] = $this->tagValue($fieldName);
 377          }
 378          if (!isset($htmlAttributes['id'])) {
 379              $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
 380          }
 381          return $this->output(sprintf($this->tags['hidden'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return);
 382      }
 383  /**
 384   * Creates a formatted IMG element.
 385   *
 386   * @param string $path Path to the image file, relative to the webroot/img/ directory.
 387   * @param array    $htmlAttributes Array of HTML attributes.
 388   * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 389   * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
 390   * @access public
 391   */
 392  	function image($path, $htmlAttributes = array(), $return = false) {
 393          if (strpos($path, '://')) {
 394              $url = $path;
 395          } else {
 396              $url = $this->webroot . $this->themeWeb . IMAGES_URL . $path;
 397          }
 398          return $this->output(sprintf($this->tags['image'], $url, $this->parseHtmlOptions($htmlAttributes, null, '', ' ')), $return);
 399      }
 400  /**
 401   * Creates a text input widget.
 402   *
 403   * @param string $fieldNamem Name of a field, like this "Modelname/fieldname"
 404   * @param array $htmlAttributes Array of HTML attributes.
 405   * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 406   * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return.
 407   * @access public
 408   */
 409  	function input($fieldName, $htmlAttributes = array(), $return = false) {
 410          $this->setFormTag($fieldName);
 411          if (!isset($htmlAttributes['value'])) {
 412              $htmlAttributes['value'] = $this->tagValue($fieldName);
 413          }
 414  
 415          if (!isset($htmlAttributes['type'])) {
 416              $htmlAttributes['type'] = 'text';
 417          }
 418  
 419          if (!isset($htmlAttributes['id'])) {
 420              $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
 421          }
 422  
 423          if ($this->tagIsInvalid($this->model, $this->field)) {
 424              if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") {
 425                  $htmlAttributes['class'] .= ' form_error';
 426              } else {
 427                  $htmlAttributes['class'] = 'form_error';
 428              }
 429          }
 430          return $this->output(sprintf($this->tags['input'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return);
 431      }
 432   /**
 433   * Returns a formatted SELECT element.
 434   *
 435   * @param string $fieldName Name attribute of the SELECT
 436   * @param array $optionElements Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the SELECT element
 437   * @param mixed $selected Selected option
 438   * @param array $selectAttr Array of HTML options for the opening SELECT element
 439   * @param array $optionAttr Array of HTML options for the enclosed OPTION elements
 440   * @param boolean $show_empty If true, the empty select option is shown
 441   * @param  boolean $return         Whether this method should return a value
 442   * @return string Formatted SELECT element
 443   * @access public
 444   */
 445  	function selectTag($fieldName, $optionElements, $selected = null, $selectAttr = array(), $optionAttr = null, $showEmpty = true, $return = false) {
 446          $this->setFormTag($fieldName);
 447          if ($this->tagIsInvalid($this->model, $this->field)) {
 448              if (isset($selectAttr['class']) && trim($selectAttr['class']) != "") {
 449                  $selectAttr['class'] .= ' form_error';
 450              } else {
 451                  $selectAttr['class'] = 'form_error';
 452              }
 453          }
 454          if (!isset($selectAttr['id'])) {
 455              $selectAttr['id'] = $this->model . Inflector::camelize($this->field);
 456          }
 457  
 458          if (!is_array($optionElements)) {
 459              return null;
 460          }
 461  
 462          if (!isset($selected)) {
 463              $selected = $this->tagValue($fieldName);
 464          }
 465  
 466          if (isset($selectAttr) && array_key_exists("multiple", $selectAttr)) {
 467              $select[] = sprintf($this->tags['selectmultiplestart'], $this->model, $this->field, $this->parseHtmlOptions($selectAttr));
 468          } else {
 469              $select[] = sprintf($this->tags['selectstart'], $this->model, $this->field, $this->parseHtmlOptions($selectAttr));
 470          }
 471  
 472          if ($showEmpty == true) {
 473              $select[] = sprintf($this->tags['selectempty'], $this->parseHtmlOptions($optionAttr));
 474          }
 475  
 476          foreach($optionElements as $name => $title) {
 477              $optionsHere = $optionAttr;
 478  
 479              if (($selected != null) && ($selected == $name)) {
 480                  $optionsHere['selected'] = 'selected';
 481              } else if(is_array($selected) && in_array($name, $selected)) {
 482                  $optionsHere['selected'] = 'selected';
 483              }
 484  
 485              $select[] = sprintf($this->tags['selectoption'], $name, $this->parseHtmlOptions($optionsHere), h($title));
 486          }
 487  
 488          $select[] = sprintf($this->tags['selectend']);
 489          return $this->output(implode("\n", $select), $return);
 490      }
 491  /**
 492   * Creates a set of radio widgets.
 493   *
 494   * @param  string  $fieldName Name of a field, like this "Modelname/fieldname"
 495   * @param  array    $options            Radio button options array
 496   * @param  array    $inbetween        String that separates the radio buttons.
 497   * @param  array    $htmlAttributes Array of HTML attributes.
 498   * @param  boolean $return    Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 499   * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return.
 500   * @access public
 501   */
 502  	function radio($fieldName, $options, $inbetween = null, $htmlAttributes = array(), $return = false) {
 503  
 504          $this->setFormTag($fieldName);
 505          $value = isset($htmlAttributes['value']) ? $htmlAttributes['value'] : $this->tagValue($fieldName);
 506          $out = array();
 507  
 508          foreach($options as $optValue => $optTitle) {
 509              $optionsHere = array('value' => $optValue);
 510              $optValue == $value ? $optionsHere['checked'] = 'checked' : null;
 511              $parsedOptions = $this->parseHtmlOptions(array_merge($htmlAttributes, $optionsHere), null, '', ' ');
 512              $individualTagName = "{$this->field}_{$optValue}";
 513              $out[] = sprintf($this->tags['radio'], $this->model, $this->field, $individualTagName, $parsedOptions, $optTitle);
 514          }
 515  
 516          $out = join($inbetween, $out);
 517          return $this->output($out ? $out : null, $return);
 518      }
 519  /**
 520   * Returns a SELECT element for days.
 521   *
 522   * @param string $tagName Prefix name for the SELECT element
 523   * @deprecated  string $value
 524   * @param string $selected Option which is selected.
 525   * @param array $optionAttr Attribute array for the option elements.
 526   * @param boolean $showEmpty Show/hide the empty select option
 527   * @return mixed
 528   * @access public
 529   */
 530  	function dayOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
 531          if (empty($selected) && $this->tagValue($tagName)) {
 532              $selected = date('d', strtotime($this->tagValue($tagName)));
 533          }
 534          $dayValue = empty($selected) ? ($showEmpty == true ? NULL : date('d')) : $selected;
 535          $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');
 536          $option = $this->selectTag($tagName . "_day", $days, $dayValue, $selectAttr, $optionAttr, $showEmpty);
 537          return $option;
 538      }
 539  /**
 540   * Returns a SELECT element for years
 541   *
 542   * @param string $tagName Prefix name for the SELECT element
 543   * @deprecated  string $value
 544   * @param integer $minYear First year in sequence
 545   * @param integer $maxYear Last year in sequence
 546   * @param string $selected Option which is selected.
 547   * @param array $optionAttr Attribute array for the option elements.
 548   * @param boolean $showEmpty Show/hide the empty select option
 549   * @return mixed
 550   * @access public
 551   */
 552  	function yearOptionTag($tagName, $value = null, $minYear = null, $maxYear = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
 553          if (empty($selected) && ($this->tagValue($tagName))) {
 554              $selected = date('Y', strtotime($this->tagValue($tagName)));
 555          }
 556  
 557          $yearValue = empty($selected) ? ($showEmpty ? NULL : date('Y')) : $selected;
 558          $currentYear = date('Y');
 559          $maxYear = is_null($maxYear) ? $currentYear + 11 : $maxYear + 1;
 560          $minYear = is_null($minYear) ? $currentYear - 60 : $minYear;
 561  
 562          if ($minYear > $maxYear) {
 563              $tmpYear = $minYear;
 564              $minYear = $maxYear;
 565              $maxYear = $tmpYear;
 566          }
 567  
 568          $minYear = $currentYear < $minYear ? $currentYear : $minYear;
 569          $maxYear = $currentYear > $maxYear ? $currentYear : $maxYear;
 570  
 571          for($yearCounter = $minYear; $yearCounter < $maxYear; $yearCounter++) {
 572              $years[$yearCounter] = $yearCounter;
 573          }
 574  
 575          return $this->selectTag($tagName . "_year", $years, $yearValue, $selectAttr, $optionAttr, $showEmpty);
 576      }
 577  /**
 578   * Returns a SELECT element for months.
 579   *
 580   * @param string $tagName Prefix name for the SELECT element
 581   * @deprecated  string $value
 582   * @param string $selected Option which is selected.
 583   * @param array $optionAttr Attribute array for the option elements.
 584   * @param boolean $showEmpty Show/hide the empty select option
 585   * @return mixed
 586   * @access public
 587   */
 588  	function monthOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
 589          if (empty($selected) && ($this->tagValue($tagName))) {
 590              $selected = date('m', strtotime($this->tagValue($tagName)));
 591          }
 592          $monthValue = empty($selected) ? ($showEmpty ? NULL : date('m')) : $selected;
 593          $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');
 594  
 595          return $this->selectTag($tagName . "_month", $months, $monthValue, $selectAttr, $optionAttr, $showEmpty);
 596      }
 597  /**
 598   * Returns a SELECT element for hours.
 599   *
 600   * @param string $tagName Prefix name for the SELECT element
 601   * @deprecated  string $value
 602   * @param boolean $format24Hours True for 24 hours format
 603   * @param string $selected Option which is selected.
 604   * @param array $optionAttr Attribute array for the option elements.
 605   * @return mixed
 606   * @access public
 607   */
 608  	function hourOptionTag($tagName, $value = null, $format24Hours = false, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
 609          if (empty($selected) && ($this->tagValue($tagName))) {
 610              if ($format24Hours) {
 611                  $selected = date('H', strtotime($this->tagValue($tagName)));
 612              } else {
 613                  $selected = date('g', strtotime($this->tagValue($tagName)));
 614              }
 615          }
 616          if ($format24Hours) {
 617              $hourValue = empty($selected) ? ($showEmpty ? NULL : date('H')) : $selected;
 618          } else {
 619              $hourValue = empty($selected) ? ($showEmpty ? NULL : date('g')) : $selected;
 620              if (isset($selected) && intval($hourValue) == 0 && !$showEmpty) {
 621                  $hourValue = 12;
 622              }
 623          }
 624  
 625          if ($format24Hours) {
 626              $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');
 627          } else {
 628              $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');
 629          }
 630  
 631          $option = $this->selectTag($tagName . "_hour", $hours, $hourValue, $selectAttr, $optionAttr, $showEmpty);
 632          return $option;
 633      }
 634  /**
 635   * Returns a SELECT element for minutes.
 636   *
 637   * @param string $tagName Prefix name for the SELECT element
 638   * @deprecated  string $value
 639   * @param string $selected Option which is selected.
 640   * @param array $optionAttr Attribute array for the option elements.
 641   * @return mixed
 642   * @access public
 643   */
 644  	function minuteOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
 645          if (empty($selected) && ($this->tagValue($tagName))) {
 646              $selected = date('i', strtotime($this->tagValue($tagName)));
 647          }
 648          $minValue = empty($selected) ? ($showEmpty ? NULL : date('i')) : $selected;
 649  
 650          for($minCount = 0; $minCount < 60; $minCount++) {
 651              $mins[sprintf('%02d', $minCount)] = sprintf('%02d', $minCount);
 652          }
 653          $option = $this->selectTag($tagName . "_min", $mins, $minValue, $selectAttr, $optionAttr, $showEmpty);
 654          return $option;
 655      }
 656  
 657  /**
 658   * Returns a SELECT element for AM or PM.
 659   *
 660   * @param string $tagName Prefix name for the SELECT element
 661   * @deprecated  string $value
 662   * @param string $selected Option which is selected.
 663   * @param array $optionAttr Attribute array for the option elements.
 664   * @return mixed
 665   * @access public
 666   */
 667  	function meridianOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
 668          if (empty($selected) && ($this->tagValue($tagName))) {
 669              $selected = date('a', strtotime($this->tagValue($tagName)));
 670          }
 671          $merValue = empty($selected) ? ($showEmpty ? NULL : date('a')) : $selected;
 672          $meridians = array('am' => 'am', 'pm' => 'pm');
 673  
 674          $option = $this->selectTag($tagName . "_meridian", $meridians, $merValue, $selectAttr, $optionAttr, $showEmpty);
 675          return $option;
 676      }
 677  /**
 678   * Returns a set of SELECT elements for a full datetime setup: day, month and year, and then time.
 679   *
 680   * @param string $tagName Prefix name for the SELECT element
 681   * @param string $dateFormat DMY, MDY, YMD or NONE.
 682   * @param string $timeFormat 12, 24, NONE
 683   * @param string $selected Option which is selected.
 684   * @param array $optionAttr Attribute array for the option elements.
 685   * @return string The HTML formatted OPTION element
 686   * @access public
 687   */
 688  	function dateTimeOptionTag($tagName, $dateFormat = 'DMY', $timeFormat = '12', $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
 689          $day      = null;
 690          $month    = null;
 691          $year     = null;
 692          $hour     = null;
 693          $min      = null;
 694          $meridian = null;
 695  
 696          if (empty($selected)) {
 697              $selected = $this->tagValue($tagName);
 698          }
 699  
 700          if (!empty($selected)) {
 701  
 702              if (is_int($selected)) {
 703                  $selected = strftime('%Y-%m-%d %H:%M:%S', $selected);
 704              }
 705  
 706              $meridian = 'am';
 707              $pos = strpos($selected, '-');
 708              if($pos !== false){
 709                  $date = explode('-', $selected);
 710                  $days = explode(' ', $date[2]);
 711                  $day = $days[0];
 712                  $month = $date[1];
 713                  $year = $date[0];
 714              } else {
 715                  $days[1] = $selected;
 716              }
 717  
 718              if ($timeFormat != 'NONE' && !empty($timeFormat)) {
 719                  $time = explode(':', $days[1]);
 720  
 721                  if (($time[0] > 12) && $timeFormat == '12') {
 722                      $time[0] = $time[0] - 12;
 723                      $meridian = 'pm';
 724                  } elseif($time[0] > 12) {
 725                      $meridian = 'pm';
 726                  }
 727  
 728                  $hour = $time[0];
 729                  $min = $time[1];
 730              }
 731          }
 732  
 733          $elements = array('Day','Month','Year','Hour','Minute','Meridian');
 734          if (isset($selectAttr['id'])) {
 735              if (is_string($selectAttr['id'])) {
 736                  // build out an array version
 737                  foreach ($elements as $element) {
 738                      $selectAttrName = 'select' . $element . 'Attr';
 739                      ${$selectAttrName} = $selectAttr;
 740                      ${$selectAttrName}['id'] = $selectAttr['id'] . $element;
 741                  }
 742              } elseif (is_array($selectAttr['id'])) {
 743                  // check for missing ones and build selectAttr for each element
 744                  foreach ($elements as $element) {
 745                      $selectAttrName = 'select' . $element . 'Attr';
 746                      ${$selectAttrName} = $selectAttr;
 747                      ${$selectAttrName}['id'] = $selectAttr['id'][strtolower($element)];
 748                  }
 749              }
 750          } else {
 751              // build the selectAttrName with empty id's to pass
 752              foreach ($elements as $element) {
 753                  $selectAttrName = 'select' . $element . 'Attr';
 754                  ${$selectAttrName} = $selectAttr;
 755              }
 756          }
 757  
 758          switch($dateFormat) {
 759              case 'DMY': // so uses the new selex
 760                  $opt = $this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty) . '-' .
 761                  $this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' . $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty);
 762              break;
 763              case 'MDY':
 764                  $opt = $this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' .
 765                  $this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty) . '-' . $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty);
 766              break;
 767              case 'YMD':
 768                  $opt = $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty) . '-' .
 769                  $this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' .
 770                  $this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty);
 771              break;
 772              case 'Y':
 773                  $opt = $this->yearOptionTag($tagName, null, null, null, $selected, $selectYearAttr, $optionAttr, $showEmpty);
 774              break;
 775              case 'NONE':
 776              default:
 777                  $opt = '';
 778              break;
 779          }
 780  
 781          switch($timeFormat) {
 782              case '24':
 783                  $opt .= $this->hourOptionTag($tagName, null, true, $hour, $selectHourAttr, $optionAttr, $showEmpty) . ':' .
 784                  $this->minuteOptionTag($tagName, null, $min, $selectMinuteAttr, $optionAttr, $showEmpty);
 785              break;
 786              case '12':
 787                  $opt .= $this->hourOptionTag($tagName, null, false, $hour, $selectHourAttr, $optionAttr, $showEmpty) . ':' .
 788                  $this->minuteOptionTag($tagName, null, $min, $selectMinuteAttr, $optionAttr, $showEmpty) . ' ' .
 789                  $this->meridianOptionTag($tagName, null, $meridian, $selectMeridianAttr, $optionAttr, $showEmpty);
 790              break;
 791              case 'NONE':
 792              default:
 793                  $opt .= '';
 794              break;
 795          }
 796          return $opt;
 797      }
 798  /**
 799   * Returns a row of formatted and named TABLE headers.
 800   *
 801   * @param array $names        Array of tablenames.
 802   * @param array $trOptions    HTML options for TR elements.
 803   * @param array $thOptions    HTML options for TH elements.
 804   * @param  boolean $return    Wheter this method should return a value
 805   * @return string
 806   * @access public
 807   */
 808  	function tableHeaders($names, $trOptions = null, $thOptions = null, $return = false) {
 809          $out = array();
 810          foreach($names as $arg) {
 811              $out[] = sprintf($this->tags['tableheader'], $this->parseHtmlOptions($thOptions), $arg);
 812          }
 813  
 814          $data = sprintf($this->tags['tablerow'], $this->parseHtmlOptions($trOptions), join(' ', $out));
 815          return $this->output($data, $return);
 816      }
 817  /**
 818   * Returns a formatted string of table rows (TR's with TD's in them).
 819   *
 820   * @param array $data        Array of table data
 821   * @param array $oddTrOptionsHTML options for odd TR elements
 822   * @param array $evenTrOptionsHTML options for even TR elements
 823   * @param  boolean $return    Wheter this method should return a value
 824   * @return string    Formatted HTML
 825   * @access public
 826   */
 827  	function tableCells($data, $oddTrOptions = null, $evenTrOptions = null, $return = false) {
 828          if (empty($data[0]) || !is_array($data[0])) {
 829              $data = array($data);
 830          }
 831          static $count = 0;
 832  
 833          foreach($data as $line) {
 834              $count++;
 835              $cellsOut = array();
 836  
 837              foreach($line as $cell) {
 838                  $cellsOut[] = sprintf($this->tags['tablecell'], null, $cell);
 839              }
 840              $options = $this->parseHtmlOptions($count % 2 ? $oddTrOptions : $evenTrOptions);
 841              $out[] = sprintf($this->tags['tablerow'], $options, join(' ', $cellsOut));
 842          }
 843          return $this->output(join("\n", $out), $return);
 844      }
 845  /**
 846   * Generates a nested unordered list tree from an array.
 847   *
 848   * @param array    $data
 849   * @param array    $htmlAttributes
 850   * @param string  $bodyKey
 851   * @param string  $childrenKey
 852   * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
 853   * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return. If $this->_crumbs is empty, return null.
 854   * @access public
 855   */
 856  	function guiListTree($data, $htmlAttributes = array(), $bodyKey = 'body', $childrenKey = 'children', $return = false) {
 857          $out="<ul" . $this->_parseAttributes($htmlAttributes) . ">\n";
 858          foreach($data as $item) {
 859                  $out .= "<li>{$item[$bodyKey]}\n";
 860                  if (isset($item[$childrenKey]) && is_array($item[$childrenKey]) && count($item[$childrenKey])) {
 861                      $out .= $this->guiListTree($item[$childrenKey], $htmlAttributes, $bodyKey, $childrenKey);
 862                  }
 863                  $out .= "</li>\n";
 864          }
 865          $out .= "</ul>\n";
 866          return $this->output($out, $return);
 867      }
 868  /**
 869   * Returns value of $fieldName. False if the tag does not exist.
 870   *
 871   * @param string $fieldName        Fieldname as "Modelname/fieldname" string
 872   * @return string htmlspecialchars Value of the named tag.
 873   * @access public
 874   */
 875  	function tagValue($fieldName) {
 876          $this->setFormTag($fieldName);
 877          if (isset($this->params['data'][$this->model][$this->field])) {
 878              return h($this->params['data'][$this->model][$this->field]);
 879          } elseif(isset($this->data[$this->model][$this->field])) {
 880              return h($this->data[$this->model][$this->field]);
 881          }
 882          return false;
 883      }
 884  /**
 885   * Returns false if given FORM field has no errors. Otherwise it returns the constant set in the array Model->validationErrors.
 886   *
 887   * @param string $model Model name as string
 888   * @param string $field        Fieldname as string
 889   * @return boolean True on errors.
 890   * @access public
 891   */
 892  	function tagIsInvalid($model, $field) {
 893          return empty($this->validationErrors[$model][$field]) ? 0 : $this->validationErrors[$model][$field];
 894      }
 895  /**
 896   * Returns number of errors in a submitted FORM.
 897   *
 898   * @return int Number of errors
 899   * @access public
 900   */
 901  	function validate() {
 902          $args = func_get_args();
 903          $errors = call_user_func_array(array(&$this, 'validateErrors'),  $args);
 904          return count($errors);
 905      }
 906  /**
 907   * Validates a FORM according to the rules set up in the Model.
 908   *
 909   * @return int Number of errors
 910   * @access public
 911   */
 912  	function validateErrors() {
 913          $objects = func_get_args();
 914          if (!count($objects)) {
 915              return false;
 916          }
 917  
 918          $errors = array();
 919          foreach($objects as $object) {
 920              $errors = array_merge($errors, $object->invalidFields($object->data));
 921          }
 922          return $this->validationErrors = (count($errors) ? $errors : false);
 923      }
 924  /**
 925   * Returns a formatted error message for given FORM field, NULL if no errors.
 926   *
 927   * @param string $field A field name, like "Modelname/fieldname"
 928   * @param string $text        Error message
 929   * @return string If there are errors this method returns an error message, else NULL.
 930   * @access public
 931   */
 932  	function tagErrorMsg($field, $text) {
 933          $error = 1;
 934          $this->setFormTag($field);
 935          if ($error == $this->tagIsInvalid($this->model, $this->field)) {
 936              return sprintf('<div class="error_message">%s</div>', is_array($text) ? (empty($text[$error - 1]) ? 'Error in field' : $text[$error - 1]) : $text);
 937          } else {
 938              return null;
 939          }
 940      }
 941  /**
 942   * Sets this helper's model and field properties to the slash-separated value-pair in $tagValue.
 943   *
 944   * @param string $tagValue A field name, like "Modelname/fieldname"
 945   * @return
 946   * @access public
 947   */
 948  	function setFormTag($tagValue) {
 949          return list($this->model, $this->field) = explode("/", $tagValue);
 950      }
 951  /**
 952   * Returns a space-delimited string with items of the $options array. If a
 953   * key of $options array happens to be one of:
 954   *    + 'compact'
 955   *    + 'checked'
 956   *    + 'declare'
 957   *    + 'readonly'
 958   *    + 'disabled'
 959   *    + 'selected'
 960   *    + 'defer'
 961   *    + 'ismap'
 962   *    + 'nohref'
 963   *    + 'noshade'
 964   *    + 'nowrap'
 965   *    + 'multiple'
 966   *    + 'noresize'
 967   *
 968   * And its value is one of:
 969   *    + 1
 970   *    + true
 971   *    + 'true'
 972   *
 973   * Then the value will be reset to be identical with key's name.
 974   * If the value is not one of these 3, the parameter is not output.
 975   *
 976   * @param  array  $options Array of options.
 977   * @param  array  $exclude Array of options to be excluded.
 978   * @param  string $insertBefore String to be inserted before options.
 979   * @param  string $insertAfter  String to be inserted ater options.
 980   * @return string
 981   * @access protected
 982   */
 983  	function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
 984          $minimizedAttributes = array('compact', 'checked', 'declare', 'readonly', 'disabled', 'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize');
 985          if (!is_array($exclude)) {
 986              $exclude = array();
 987          }
 988  
 989          if (is_array($options)) {
 990              $out = array();
 991  
 992              foreach($options as $key => $value) {
 993                  if (!in_array($key, $exclude)) {
 994                      if (in_array($key, $minimizedAttributes) && ($value === 1 || $value === true || $value === 'true' || in_array($value, $minimizedAttributes))) {
 995                          $value = $key;
 996                      } elseif(in_array($key, $minimizedAttributes)) {
 997                          continue;
 998                      }
 999                      $out[] = "{$key}=\"{$value}\"";
1000                  }
1001              }
1002              $out = join(' ', $out);
1003              return $out ? $insertBefore . $out . $insertAfter : null;
1004          } else {
1005              return $options ? $insertBefore . $options . $insertAfter : null;
1006          }
1007      }
1008  /**
1009   * @deprecated Name changed to 'textarea'. Version 0.9.2.
1010   * @see        HtmlHelper::textarea()
1011   */
1012  	function areaTag($tagName, $cols = 60, $rows = 10, $htmlAttributes = array(), $return = false) {
1013          $htmlAttributes['cols']=$cols;
1014          $htmlAttributes['rows']=$rows;
1015          return $this->textarea($tagName, $htmlAttributes, $return);
1016      }
1017  /**
1018   * @deprecated Name changed to 'charset'. Version 0.9.2.
1019   * @see        HtmlHelper::charset()
1020   */
1021  	function charsetTag($charset, $return = false) {
1022          return $this->charset($charset, $return);
1023      }
1024  /**
1025   * @deprecated Name changed to 'checkbox'. Version 0.9.2.
1026   * @see        HtmlHelper::checkbox()
1027   */
1028  	function checkboxTag($fieldName, $title = null, $htmlAttributes = array(), $return = false) {
1029          return $this->checkbox($fieldName, $title, $htmlAttributes, $return);
1030      }
1031  /**
1032   * @deprecated Name changed to 'css'. Version 0.9.2.
1033   * @see HtmlHelper::css()
1034   */
1035  	function cssTag($path, $rel = 'stylesheet', $htmlAttributes = array(), $return = false) {
1036          return $this->css($path, $rel, $htmlAttributes, $return);
1037      }
1038  /**
1039   * @deprecated Name changed to 'file'. Version 0.9.2.
1040   * @see HtmlHelper::file()
1041   */
1042  	function fileTag($fieldName, $htmlAttributes = array(), $return = false) {
1043          return $this->file($fieldName, $htmlAttributes, $return);
1044      }
1045  /**
1046   * @deprecated Name changed to 'hidden'. Version 0.9.2.
1047   * @see        HtmlHelper::hidden()
1048   */
1049  	function hiddenTag($tagName, $value = null, $htmlOptions = null) {
1050          $this->setFormTag($tagName);
1051          $htmlOptions['value'] = $value ? $value : $this->tagValue($tagName);
1052          return $this->output(sprintf($this->tags['hidden'], $this->model, $this->field, $this->parseHtmlOptions($htmlOptions, null, '', ' ')));
1053      }
1054  /**
1055   * @deprecated Name changed to 'image'. Version 0.9.2.
1056   * @see        HtmlHelper::image()
1057   */
1058  	function imageTag($path, $alt = null, $htmlAttributes = array(), $return = false) {
1059          $htmlAttributes['alt'] = $alt;
1060          return $this->image($path, $htmlAttributes, $return);
1061      }
1062  /**
1063   * @deprecated Name changed to 'input'. Version 0.9.2.
1064   * @see HtmlHelper::input()
1065   */
1066  	function inputTag($tagName, $size = 20, $htmlOptions = null) {
1067          $this->setFormTag($tagName);
1068          $htmlOptions['value'] = isset($htmlOptions['value']) ? $htmlOptions['value'] : $this->tagValue($tagName);
1069          $this->tagIsInvalid($this->model, $this->field) ? $htmlOptions['class'] = 'form_error' : null;
1070          return $this->output(sprintf($this->tags['input'], $this->model, $this->field, $this->parseHtmlOptions($htmlOptions, null, '', ' ')));
1071      }
1072  /**
1073   * @deprecated Unified with 'link'. Version 0.9.2.
1074   * @see HtmlHelper::link()
1075   */
1076  	function linkOut($title, $url = null, $htmlAttributes = array(), $escapeTitle = true, $return = false) {
1077          return $this->link($title, $url, $htmlAttributes, false, $escapeTitle, $return);
1078      }
1079  /**
1080   * @deprecated Unified with 'link'. Version 0.9.2.
1081   * @see HtmlHelper::link()
1082   */
1083  	function linkTo($title, $url, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true, $return = false) {
1084          return $this->link($title, $url, $htmlAttributes, $confirmMessage, $escapeTitle, $return);
1085      }
1086  /**
1087   * @deprecated Name changed to '_parseAttributes'. Version 0.9.2.
1088   * @see HtmlHelper::_parseAttributes()
1089   */
1090  	function parseHtmlOptions($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
1091          if (!is_array($exclude))
1092                  $exclude=array();
1093  
1094          if (is_array($options)) {
1095                  $out=array();
1096  
1097                  foreach($options as $k => $v) {
1098                      if (!in_array($k, $exclude)) {
1099                          $out[] = "{$k}=\"{$v}\"";
1100                      }
1101                  }
1102                  $out = join(' ', $out);
1103                  return $out ? $insertBefore . $out . $insertAfter : null;
1104          } else {
1105                  return $options ? $insertBefore . $options . $insertAfter : null;
1106          }
1107      }
1108  /**
1109   * @deprecated Name changed to 'password'. Version 0.9.2.
1110   * @see HtmlHelper::password()
1111   */
1112  	function passwordTag($fieldName, $size = 20, $htmlAttributes = array(), $return = false) {
1113          $args = func_get_args();
1114          return call_user_func_array(array(&$this,
1115                      "password"),       $args);
1116      }
1117  /**
1118   * @deprecated Name changed to 'radio'. Version 0.9.2.
1119   * @see HtmlHelper::radio()
1120   */
1121  	function radioTags($fieldName, $options, $inbetween = null, $htmlAttributes = array(), $return = false) {
1122          return $this->radio($fieldName, $options, $inbetween, $htmlAttributes, $return);
1123      }
1124  /**
1125   * @deprecated Name changed to 'url'. Version 0.9.2.
1126   * @see HtmlHelper::url()
1127   */
1128  	function urlFor($url) {
1129          return $this->url($url);
1130      }
1131  /**
1132   * @deprecated Name changed to 'submit'. Version 0.9.2.
1133   * @see HtmlHelper::submit()
1134   */
1135  	function submitTag() {
1136          $args = func_get_args();
1137          return call_user_func_array(array(&$this, "submit"), $args);
1138      }
1139  /*************************************************************************
1140   * Moved methods
1141   *************************************************************************/
1142  /**
1143   * @deprecated Moved to TextHelper. Version 0.9.2.
1144   */
1145  	function trim() {
1146          die("Method HtmlHelper::trim() was moved to TextHelper::trim().");
1147      }
1148  /**
1149   * @deprecated Moved to JavascriptHelper. Version 0.9.2.
1150   */
1151  	function javascriptIncludeTag($url) {
1152          die("Method HtmlHelper::javascriptIncludeTag() was moved to JavascriptHelper::link().");
1153      }
1154  /**
1155   * @deprecated Moved to JavascriptHelper. Version 0.9.2.
1156   */
1157  	function javascriptTag($script) {
1158          die("Method HtmlHelper::javascriptTag() was moved to JavascriptHelper::codeBlock().");
1159      }
1160  /**
1161   * This is very WYSIWYG unfriendly, use HtmlHelper::url() to get contents of "action" attribute. Version 0.9.2.
1162   * @deprecated Version 0.9.2. Will not be available after 1.1.x.x
1163   * @see FormHelper::create()
1164   */
1165  	function formTag($target = null, $type = 'post', $htmlAttributes = array()) {
1166          $htmlAttributes['action']=$this->UrlFor($target);
1167          $htmlAttributes['method']=$type == 'get' ? 'get' : 'post';
1168          $type == 'file' ? $htmlAttributes['enctype'] = 'multipart/form-data' : null;
1169          $token='';
1170  
1171          if (isset($this->params['_Token']) && !empty($this->params['_Token'])) {
1172                  $token = $this->hidden('_Token/key', array('value' => $this->params['_Token']['key']), true);
1173          }
1174  
1175          return sprintf($this->tags['form'], $this->parseHtmlOptions($htmlAttributes, null, '')) . $token;
1176      }
1177  /**
1178   * This should be done using a content filter.
1179   * @deprecated Version 0.9.2. Will not be available after 1.1.x.x
1180   */
1181  	function linkEmail($title, $email = null, $options = null) {
1182          // if no $email, then title contains the email.
1183          if (empty($email))
1184                  $email=$title;
1185  
1186          $match=array();
1187  
1188          // does the address contain extra attributes?
1189          preg_match('!^(.*)(\?.*)$!', $email, $match);
1190  
1191          // plaintext
1192          if (empty($options['encode']) || !empty($match[2])) {
1193                  return sprintf($this->tags['mailto'], $email, $this->parseHtmlOptions($options), $title);
1194          }
1195          // encoded to avoid spiders
1196          else {
1197                  $email_encoded=null;
1198  
1199                  for($ii = 0; $ii < strlen($email); $ii++) {
1200                      if (preg_match('!\w!', $email[$ii])) {
1201                          $email_encoded .= '%' . bin2hex($email[$ii]);
1202                      } else {
1203                          $email_encoded .= $email[$ii];
1204                      }
1205                  }
1206  
1207                  $title_encoded=null;
1208  
1209                  for($ii = 0; $ii < strlen($title); $ii++) {
1210                      $title_encoded .= preg_match('/^[A-Za-z0-9]$/', $title[$ii])
1211                          ? '&#x' . bin2hex($title[$ii]) . ';' : $title[$ii];
1212                  }
1213  
1214                  return sprintf($this->tags['mailto'],                              $email_encoded,
1215                                      $this->parseHtmlOptions($options, array('encode')), $title_encoded);
1216          }
1217      }
1218  
1219  /**
1220   * @deprecated Version 0.9.2. Will not be available after 1.1.x.x
1221   */
1222  	function tag($name, $options = null, $open = false) {
1223          $tag = "<$name " . $this->parseHtmlOptions($options);
1224          $tag .= $open ? ">" : " />";
1225          return $tag;
1226      }
1227  /**
1228   * @deprecated Version 0.9.2. Will not be available after 1.1.x.x
1229   */
1230  	function contentTag($name, $content, $options = null) {
1231          return "<$name " . $this->parseHtmlOptions($options) . ">$content</$name>";
1232      }
1233  
1234  }
1235  ?>


Généré le : Sun Feb 25 19:27:47 2007 par Balluche grâce à PHPXref 0.7