admin | 5ed8bf3 | 2006-10-29 17:44:54 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
| 10 | * @license http://www.codeignitor.com/user_guide/license.html |
| 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Code Igniter HTML Helpers |
| 20 | * |
| 21 | * @package CodeIgniter |
| 22 | * @subpackage Helpers |
| 23 | * @category Helpers |
| 24 | * @author Rick Ellis |
| 25 | * @link http://www.codeigniter.com/user_guide/helpers/html_helper.html |
| 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * Unordered List |
| 32 | * |
| 33 | * Generates an HTML unordered list from an single or multi-dimensional array. |
| 34 | * |
| 35 | * @access public |
| 36 | * @param array |
| 37 | * @param mixed |
| 38 | * @return string |
| 39 | */ |
| 40 | function ul($list, $attributes = '') |
| 41 | { |
| 42 | return _generate_list('ul', $list, $attributes); |
| 43 | } |
| 44 | |
| 45 | // ------------------------------------------------------------------------ |
| 46 | |
| 47 | /** |
| 48 | * Ordered List |
| 49 | * |
| 50 | * Generates an HTML ordered list from an single or multi-dimensional array. |
| 51 | * |
| 52 | * @access public |
| 53 | * @param array |
| 54 | * @param mixed |
| 55 | * @return string |
| 56 | */ |
| 57 | function ol($list, $attributes = '') |
| 58 | { |
| 59 | return _generate_list('ol', $list, $attributes); |
| 60 | } |
| 61 | |
| 62 | // ------------------------------------------------------------------------ |
| 63 | |
| 64 | /** |
| 65 | * Generates the list |
| 66 | * |
| 67 | * Generates an HTML ordered list from an single or multi-dimensional array. |
| 68 | * |
| 69 | * @access private |
| 70 | * @param string |
| 71 | * @param mixed |
| 72 | * @param mixed |
| 73 | * @param intiger |
| 74 | * @return string |
| 75 | */ |
| 76 | function _generate_list($type = 'ul', $list, $attributes = '', $depth = 0) |
| 77 | { |
| 78 | if ( ! is_array($list)) |
| 79 | { |
| 80 | return $list; |
| 81 | } |
| 82 | |
| 83 | $out = str_repeat(" ", $depth); |
| 84 | |
| 85 | $out .= "<".$type._set_attributes($attributes).">\n"; |
| 86 | |
| 87 | foreach ($list as $item) |
| 88 | { |
| 89 | if (is_array($item)) |
| 90 | { |
| 91 | $out .= _list($type, $item, '', $depth+4); |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | $out .= str_repeat(" ", $depth + 2); |
| 96 | |
| 97 | $out .= "<li>".$item."</li>\n"; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | $out .= str_repeat(" ", $depth); |
| 102 | |
| 103 | $out .= "</".$type.">\n"; |
| 104 | |
| 105 | return $out; |
| 106 | } |
| 107 | |
| 108 | // ------------------------------------------------------------------------ |
| 109 | |
| 110 | /** |
| 111 | * Generates the attribute string |
| 112 | * |
| 113 | * @access private |
| 114 | * @param mixed |
| 115 | * @return string |
| 116 | */ |
| 117 | function _set_attributes($attributes) |
| 118 | { |
| 119 | if (is_string($attributes)) |
| 120 | { |
| 121 | return $attributes; |
| 122 | } |
| 123 | |
| 124 | $atts = ''; |
| 125 | foreach ($attributes as $key => $val) |
| 126 | { |
| 127 | $atts .= ' ' . $key . '="' . $val . '"'; |
| 128 | } |
| 129 | |
| 130 | return $atts; |
| 131 | } |
| 132 | ?> |