admin | b0dd10f | 2006-08-25 17:25:49 +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. |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 10 | * @license http://www.codeignitor.com/user_guide/license.html |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 15 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 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 | * Heading |
| 32 | * |
| 33 | * Generates an HTML heading tag. First param is the data. |
| 34 | * Second param is the size of the heading tag. |
| 35 | * |
| 36 | * @access public |
| 37 | * @param string |
| 38 | * @param integer |
| 39 | * @return string |
| 40 | */ |
| 41 | function heading($data = '', $h = '1') |
| 42 | { |
| 43 | return "<h".$h.">".$data."</h".$h.">"; |
| 44 | } |
admin | 27e4e6e | 2006-10-29 20:19:02 +0000 | [diff] [blame] | 45 | |
| 46 | // ------------------------------------------------------------------------ |
| 47 | |
| 48 | /** |
| 49 | * Unordered List |
| 50 | * |
| 51 | * Generates an HTML unordered list from an single or multi-dimensional array. |
| 52 | * |
| 53 | * @access public |
| 54 | * @param array |
| 55 | * @param mixed |
| 56 | * @return string |
| 57 | */ |
| 58 | function ul($list, $attributes = '') |
| 59 | { |
| 60 | return _list('ul', $list, $attributes); |
| 61 | } |
| 62 | |
| 63 | // ------------------------------------------------------------------------ |
| 64 | |
| 65 | /** |
| 66 | * Ordered List |
| 67 | * |
| 68 | * Generates an HTML ordered list from an single or multi-dimensional array. |
| 69 | * |
| 70 | * @access public |
| 71 | * @param array |
| 72 | * @param mixed |
| 73 | * @return string |
| 74 | */ |
| 75 | function ol($list, $attributes = '') |
| 76 | { |
| 77 | return _list('ol', $list, $attributes); |
| 78 | } |
| 79 | |
| 80 | // ------------------------------------------------------------------------ |
| 81 | |
| 82 | /** |
| 83 | * Generates the list |
| 84 | * |
| 85 | * Generates an HTML ordered list from an single or multi-dimensional array. |
| 86 | * |
| 87 | * @access private |
| 88 | * @param string |
| 89 | * @param mixed |
| 90 | * @param mixed |
| 91 | * @param intiger |
| 92 | * @return string |
| 93 | */ |
| 94 | function _list($type = 'ul', $list, $attributes = '', $depth = 0) |
| 95 | { |
| 96 | // If an array wasn't submitted there's nothing to do... |
| 97 | if ( ! is_array($list)) |
| 98 | { |
| 99 | return $list; |
| 100 | } |
| 101 | |
| 102 | // Set the indentation based on the depth |
| 103 | $out = str_repeat(" ", $depth); |
| 104 | |
| 105 | // Were any attributes submitted? If so generate a string |
| 106 | if (is_array($attributes)) |
| 107 | { |
| 108 | $atts = ''; |
| 109 | foreach ($attributes as $key => $val) |
| 110 | { |
| 111 | $atts .= ' ' . $key . '="' . $val . '"'; |
| 112 | } |
| 113 | $attributes = $atts; |
| 114 | } |
| 115 | |
| 116 | // Write the opening list tag |
| 117 | $out .= "<".$type.$attributes.">\n"; |
| 118 | |
| 119 | // Cycle through the list elements. If an array is |
| 120 | // encountered we will recursively call _list() |
| 121 | |
| 122 | static $_last_list_item = ''; |
| 123 | foreach ($list as $key => $val) |
| 124 | { |
| 125 | $_last_list_item = $key; |
| 126 | |
| 127 | $out .= str_repeat(" ", $depth + 2); |
| 128 | $out .= "<li>"; |
| 129 | |
| 130 | if ( ! is_array($val)) |
| 131 | { |
| 132 | $out .= $val; |
| 133 | } |
| 134 | else |
| 135 | { |
| 136 | $out .= $_last_list_item."\n"; |
| 137 | $out .= _list($type, $val, '', $depth + 4); |
| 138 | $out .= str_repeat(" ", $depth + 2); |
| 139 | } |
| 140 | |
| 141 | $out .= "</li>\n"; |
| 142 | } |
| 143 | |
| 144 | // Set the indentation for the closing tag |
| 145 | $out .= str_repeat(" ", $depth); |
| 146 | |
| 147 | // Write the closing list tag |
| 148 | $out .= "</".$type.">\n"; |
| 149 | |
| 150 | return $out; |
| 151 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 152 | |
| 153 | // ------------------------------------------------------------------------ |
| 154 | |
| 155 | /** |
| 156 | * Generates HTML BR tags based on number supplied |
| 157 | * |
| 158 | * @access public |
| 159 | * @param integer |
| 160 | * @return string |
| 161 | */ |
| 162 | function br($num = 1) |
| 163 | { |
| 164 | return str_repeat("<br />", $num); |
| 165 | } |
| 166 | |
| 167 | // ------------------------------------------------------------------------ |
| 168 | |
| 169 | /** |
| 170 | * Generates non-breaking space entities based on number supplied |
| 171 | * |
| 172 | * @access public |
| 173 | * @param integer |
| 174 | * @return string |
| 175 | */ |
| 176 | function nbs($num = 1) |
| 177 | { |
| 178 | return str_repeat(" ", $num); |
| 179 | } |
| 180 | |
admin | 40d299e | 2006-11-04 05:07:59 +0000 | [diff] [blame] | 181 | // ------------------------------------------------------------------------ |
| 182 | |
| 183 | /** |
| 184 | * Generates meta tags from an array of key/values |
| 185 | * |
| 186 | * @access public |
| 187 | * @param array |
| 188 | * @return string |
| 189 | */ |
| 190 | function meta($meta = array(), $newline = "\n") |
| 191 | { |
| 192 | $str = ''; |
| 193 | foreach ($meta as $key => $val) |
| 194 | { |
| 195 | $str .= '<meta http-equiv="'.$key.'" content="'.$val.'" />'.$newline; |
| 196 | } |
| 197 | |
| 198 | return $str; |
| 199 | } |
| 200 | |
| 201 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 202 | |
| 203 | |
| 204 | ?> |