web/lib/Zend/View/Helper/HtmlList.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_View
       
    17  * @subpackage Helper
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: HtmlList.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 
       
    24 /**
       
    25  * Zend_View_Helper_FormELement
       
    26  */
       
    27 require_once 'Zend/View/Helper/FormElement.php';
       
    28 
       
    29 /**
       
    30  * Helper for ordered and unordered lists
       
    31  *
       
    32  * @uses Zend_View_Helper_FormElement
       
    33  * @category   Zend
       
    34  * @package    Zend_View
       
    35  * @subpackage Helper
       
    36  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    38  */
       
    39 class Zend_View_Helper_HtmlList extends Zend_View_Helper_FormElement
       
    40 {
       
    41 
       
    42     /**
       
    43      * Generates a 'List' element.
       
    44      *
       
    45      * @param array   $items   Array with the elements of the list
       
    46      * @param boolean $ordered Specifies ordered/unordered list; default unordered
       
    47      * @param array   $attribs Attributes for the ol/ul tag.
       
    48      * @return string The list XHTML.
       
    49      */
       
    50     public function htmlList(array $items, $ordered = false, $attribs = false, $escape = true)
       
    51     {
       
    52         if (!is_array($items)) {
       
    53             require_once 'Zend/View/Exception.php';
       
    54             $e = new Zend_View_Exception('First param must be an array');
       
    55             $e->setView($this->view);
       
    56             throw $e;
       
    57         }
       
    58 
       
    59         $list = '';
       
    60 
       
    61         foreach ($items as $item) {
       
    62             if (!is_array($item)) {
       
    63                 if ($escape) {
       
    64                     $item = $this->view->escape($item);
       
    65                 }
       
    66                 $list .= '<li>' . $item . '</li>' . self::EOL;
       
    67             } else {
       
    68                 if (6 < strlen($list)) {
       
    69                     $list = substr($list, 0, strlen($list) - 6)
       
    70                      . $this->htmlList($item, $ordered, $attribs, $escape) . '</li>' . self::EOL;
       
    71                 } else {
       
    72                     $list .= '<li>' . $this->htmlList($item, $ordered, $attribs, $escape) . '</li>' . self::EOL;
       
    73                 }
       
    74             }
       
    75         }
       
    76 
       
    77         if ($attribs) {
       
    78             $attribs = $this->_htmlAttribs($attribs);
       
    79         } else {
       
    80             $attribs = '';
       
    81         }
       
    82 
       
    83         $tag = 'ul';
       
    84         if ($ordered) {
       
    85             $tag = 'ol';
       
    86         }
       
    87 
       
    88         return '<' . $tag . $attribs . '>' . self::EOL . $list . '</' . $tag . '>' . self::EOL;
       
    89     }
       
    90 }