File indexing completed on 2024-12-22 05:37:13

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_View
0017  * @subpackage Helper
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 
0024 /**
0025  * Zend_View_Helper_FormELement
0026  */
0027 // require_once 'Zend/View/Helper/FormElement.php';
0028 
0029 /**
0030  * Helper for ordered and unordered lists
0031  *
0032  * @uses Zend_View_Helper_FormElement
0033  * @category   Zend
0034  * @package    Zend_View
0035  * @subpackage Helper
0036  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0037  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0038  */
0039 class Zend_View_Helper_HtmlList extends Zend_View_Helper_FormElement
0040 {
0041 
0042     /**
0043      * Generates a 'List' element.
0044      *
0045      * @param array   $items   Array with the elements of the list
0046      * @param boolean $ordered Specifies ordered/unordered list; default unordered
0047      * @param array   $attribs Attributes for the ol/ul tag.
0048      * @return string The list XHTML.
0049      */
0050     public function htmlList(array $items, $ordered = false, $attribs = false, $escape = true)
0051     {
0052         if (!is_array($items)) {
0053             // require_once 'Zend/View/Exception.php';
0054             $e = new Zend_View_Exception('First param must be an array');
0055             $e->setView($this->view);
0056             throw $e;
0057         }
0058 
0059         $list = '';
0060 
0061         foreach ($items as $item) {
0062             if (!is_array($item)) {
0063                 if ($escape) {
0064                     $item = $this->view->escape($item);
0065                 }
0066                 $list .= '<li>' . $item . '</li>' . self::EOL;
0067             } else {
0068                 if (6 < strlen($list)) {
0069                     $list = substr($list, 0, strlen($list) - 6)
0070                      . $this->htmlList($item, $ordered, $attribs, $escape) . '</li>' . self::EOL;
0071                 } else {
0072                     $list .= '<li>' . $this->htmlList($item, $ordered, $attribs, $escape) . '</li>' . self::EOL;
0073                 }
0074             }
0075         }
0076 
0077         if ($attribs) {
0078             $attribs = $this->_htmlAttribs($attribs);
0079         } else {
0080             $attribs = '';
0081         }
0082 
0083         $tag = 'ul';
0084         if ($ordered) {
0085             $tag = 'ol';
0086         }
0087 
0088         return '<' . $tag . $attribs . '>' . self::EOL . $list . '</' . $tag . '>' . self::EOL;
0089     }
0090 }