Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author ExpressionEngine Dev Team |
Greg Aker | 0711dc8 | 2011-01-05 10:49:40 -0600 | [diff] [blame] | 9 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html |
| 11 | * @link http://codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * CodeIgniter HTML Helpers |
| 20 | * |
| 21 | * @package CodeIgniter |
| 22 | * @subpackage Helpers |
| 23 | * @category Helpers |
| 24 | * @author ExpressionEngine Dev Team |
| 25 | * @link http://codeigniter.com/user_guide/helpers/html_helper.html |
| 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * Heading |
| 32 | * |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 33 | * Generates an HTML heading tag. First param is the data. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | if ( ! function_exists('heading')) |
| 42 | { |
Greg Aker | 826429c | 2011-04-18 09:40:19 -0500 | [diff] [blame] | 43 | function heading($data = '', $h = '1', $attributes = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 44 | { |
Greg Aker | 826429c | 2011-04-18 09:40:19 -0500 | [diff] [blame] | 45 | $attributes = ($attributes != '') ? ' '.$attributes : $attributes; |
| 46 | return "<h".$h.$attributes.">".$data."</h".$h.">"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |
| 50 | // ------------------------------------------------------------------------ |
| 51 | |
| 52 | /** |
| 53 | * Unordered List |
| 54 | * |
| 55 | * Generates an HTML unordered list from an single or multi-dimensional array. |
| 56 | * |
| 57 | * @access public |
| 58 | * @param array |
| 59 | * @param mixed |
| 60 | * @return string |
| 61 | */ |
| 62 | if ( ! function_exists('ul')) |
| 63 | { |
| 64 | function ul($list, $attributes = '') |
| 65 | { |
| 66 | return _list('ul', $list, $attributes); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // ------------------------------------------------------------------------ |
| 71 | |
| 72 | /** |
| 73 | * Ordered List |
| 74 | * |
| 75 | * Generates an HTML ordered list from an single or multi-dimensional array. |
| 76 | * |
| 77 | * @access public |
| 78 | * @param array |
| 79 | * @param mixed |
| 80 | * @return string |
| 81 | */ |
| 82 | if ( ! function_exists('ol')) |
| 83 | { |
| 84 | function ol($list, $attributes = '') |
| 85 | { |
| 86 | return _list('ol', $list, $attributes); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // ------------------------------------------------------------------------ |
| 91 | |
| 92 | /** |
| 93 | * Generates the list |
| 94 | * |
| 95 | * Generates an HTML ordered list from an single or multi-dimensional array. |
| 96 | * |
| 97 | * @access private |
| 98 | * @param string |
| 99 | * @param mixed |
| 100 | * @param mixed |
Derek Allard | 4e8d66a | 2010-03-15 12:23:27 -0400 | [diff] [blame] | 101 | * @param integer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 102 | * @return string |
| 103 | */ |
| 104 | if ( ! function_exists('_list')) |
| 105 | { |
| 106 | function _list($type = 'ul', $list, $attributes = '', $depth = 0) |
| 107 | { |
| 108 | // If an array wasn't submitted there's nothing to do... |
| 109 | if ( ! is_array($list)) |
| 110 | { |
| 111 | return $list; |
| 112 | } |
| 113 | |
| 114 | // Set the indentation based on the depth |
| 115 | $out = str_repeat(" ", $depth); |
| 116 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 117 | // Were any attributes submitted? If so generate a string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 118 | if (is_array($attributes)) |
| 119 | { |
| 120 | $atts = ''; |
| 121 | foreach ($attributes as $key => $val) |
| 122 | { |
| 123 | $atts .= ' ' . $key . '="' . $val . '"'; |
| 124 | } |
| 125 | $attributes = $atts; |
| 126 | } |
Eric Barnes | 6addf31 | 2011-07-18 00:13:07 -0400 | [diff] [blame] | 127 | elseif (is_string($attributes) AND strlen($attributes) > 0) |
| 128 | { |
| 129 | $attributes = ' '. $attributes; |
| 130 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 131 | |
| 132 | // Write the opening list tag |
| 133 | $out .= "<".$type.$attributes.">\n"; |
| 134 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 135 | // Cycle through the list elements. If an array is |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 136 | // encountered we will recursively call _list() |
| 137 | |
| 138 | static $_last_list_item = ''; |
| 139 | foreach ($list as $key => $val) |
| 140 | { |
| 141 | $_last_list_item = $key; |
| 142 | |
| 143 | $out .= str_repeat(" ", $depth + 2); |
| 144 | $out .= "<li>"; |
| 145 | |
| 146 | if ( ! is_array($val)) |
| 147 | { |
| 148 | $out .= $val; |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | $out .= $_last_list_item."\n"; |
| 153 | $out .= _list($type, $val, '', $depth + 4); |
| 154 | $out .= str_repeat(" ", $depth + 2); |
| 155 | } |
| 156 | |
| 157 | $out .= "</li>\n"; |
| 158 | } |
| 159 | |
| 160 | // Set the indentation for the closing tag |
| 161 | $out .= str_repeat(" ", $depth); |
| 162 | |
| 163 | // Write the closing list tag |
| 164 | $out .= "</".$type.">\n"; |
| 165 | |
| 166 | return $out; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // ------------------------------------------------------------------------ |
| 171 | |
| 172 | /** |
| 173 | * Generates HTML BR tags based on number supplied |
| 174 | * |
| 175 | * @access public |
| 176 | * @param integer |
| 177 | * @return string |
| 178 | */ |
| 179 | if ( ! function_exists('br')) |
| 180 | { |
| 181 | function br($num = 1) |
| 182 | { |
| 183 | return str_repeat("<br />", $num); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | // ------------------------------------------------------------------------ |
| 188 | |
| 189 | /** |
| 190 | * Image |
| 191 | * |
| 192 | * Generates an <img /> element |
| 193 | * |
| 194 | * @access public |
| 195 | * @param mixed |
| 196 | * @return string |
| 197 | */ |
| 198 | if ( ! function_exists('img')) |
| 199 | { |
| 200 | function img($src = '', $index_page = FALSE) |
| 201 | { |
| 202 | if ( ! is_array($src) ) |
| 203 | { |
| 204 | $src = array('src' => $src); |
| 205 | } |
| 206 | |
Derek Allard | a0905f3 | 2010-07-05 08:11:33 -0400 | [diff] [blame] | 207 | // If there is no alt attribute defined, set it to an empty string |
| 208 | if ( ! isset($src['alt'])) |
| 209 | { |
| 210 | $src['alt'] = ''; |
| 211 | } |
| 212 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 213 | $img = '<img'; |
| 214 | |
| 215 | foreach ($src as $k=>$v) |
| 216 | { |
| 217 | |
| 218 | if ($k == 'src' AND strpos($v, '://') === FALSE) |
| 219 | { |
| 220 | $CI =& get_instance(); |
| 221 | |
| 222 | if ($index_page === TRUE) |
| 223 | { |
Greg Aker | f7d162a | 2010-11-09 14:52:28 -0600 | [diff] [blame] | 224 | $img .= ' src="'.$CI->config->site_url($v).'"'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 225 | } |
| 226 | else |
| 227 | { |
Greg Aker | f7d162a | 2010-11-09 14:52:28 -0600 | [diff] [blame] | 228 | $img .= ' src="'.$CI->config->slash_item('base_url').$v.'"'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | else |
| 232 | { |
Greg Aker | f7d162a | 2010-11-09 14:52:28 -0600 | [diff] [blame] | 233 | $img .= " $k=\"$v\""; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | |
| 237 | $img .= '/>'; |
| 238 | |
| 239 | return $img; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | // ------------------------------------------------------------------------ |
| 244 | |
| 245 | /** |
| 246 | * Doctype |
| 247 | * |
| 248 | * Generates a page document type declaration |
| 249 | * |
| 250 | * Valid options are xhtml-11, xhtml-strict, xhtml-trans, xhtml-frame, |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 251 | * html4-strict, html4-trans, and html4-frame. Values are saved in the |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 252 | * doctypes config file. |
| 253 | * |
| 254 | * @access public |
| 255 | * @param string type The doctype to be generated |
| 256 | * @return string |
| 257 | */ |
| 258 | if ( ! function_exists('doctype')) |
| 259 | { |
Derek Allard | 93bddd1 | 2009-04-14 19:27:38 +0000 | [diff] [blame] | 260 | function doctype($type = 'xhtml1-strict') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 261 | { |
| 262 | global $_doctypes; |
| 263 | |
| 264 | if ( ! is_array($_doctypes)) |
| 265 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 266 | if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) |
bubbafoley | 0ea0414 | 2011-03-17 14:55:41 -0500 | [diff] [blame] | 267 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 268 | include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); |
bubbafoley | 0ea0414 | 2011-03-17 14:55:41 -0500 | [diff] [blame] | 269 | } |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 270 | elseif (is_file(APPPATH.'config/doctypes.php')) |
bubbafoley | 0ea0414 | 2011-03-17 14:55:41 -0500 | [diff] [blame] | 271 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 272 | include(APPPATH.'config/doctypes.php'); |
bubbafoley | 0ea0414 | 2011-03-17 14:55:41 -0500 | [diff] [blame] | 273 | } |
Eric Barnes | 9280834 | 2011-03-18 09:02:37 -0400 | [diff] [blame] | 274 | |
bubbafoley | 0ea0414 | 2011-03-17 14:55:41 -0500 | [diff] [blame] | 275 | if ( ! is_array($_doctypes)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 276 | { |
| 277 | return FALSE; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | if (isset($_doctypes[$type])) |
| 282 | { |
| 283 | return $_doctypes[$type]; |
| 284 | } |
| 285 | else |
| 286 | { |
| 287 | return FALSE; |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | // ------------------------------------------------------------------------ |
| 293 | |
| 294 | /** |
| 295 | * Link |
| 296 | * |
| 297 | * Generates link to a CSS file |
| 298 | * |
| 299 | * @access public |
| 300 | * @param mixed stylesheet hrefs or an array |
| 301 | * @param string rel |
| 302 | * @param string type |
| 303 | * @param string title |
| 304 | * @param string media |
| 305 | * @param boolean should index_page be added to the css path |
| 306 | * @return string |
| 307 | */ |
| 308 | if ( ! function_exists('link_tag')) |
| 309 | { |
| 310 | function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) |
| 311 | { |
| 312 | $CI =& get_instance(); |
| 313 | |
| 314 | $link = '<link '; |
| 315 | |
| 316 | if (is_array($href)) |
| 317 | { |
| 318 | foreach ($href as $k=>$v) |
| 319 | { |
| 320 | if ($k == 'href' AND strpos($v, '://') === FALSE) |
| 321 | { |
| 322 | if ($index_page === TRUE) |
| 323 | { |
Derek Allard | 76763bb | 2009-09-16 11:25:20 +0000 | [diff] [blame] | 324 | $link .= 'href="'.$CI->config->site_url($v).'" '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 325 | } |
| 326 | else |
| 327 | { |
Derek Allard | 76763bb | 2009-09-16 11:25:20 +0000 | [diff] [blame] | 328 | $link .= 'href="'.$CI->config->slash_item('base_url').$v.'" '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | else |
| 332 | { |
| 333 | $link .= "$k=\"$v\" "; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | $link .= "/>"; |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | if ( strpos($href, '://') !== FALSE) |
| 342 | { |
Derek Allard | 292dcd8 | 2009-09-16 11:26:32 +0000 | [diff] [blame] | 343 | $link .= 'href="'.$href.'" '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 344 | } |
| 345 | elseif ($index_page === TRUE) |
| 346 | { |
Derek Allard | 76763bb | 2009-09-16 11:25:20 +0000 | [diff] [blame] | 347 | $link .= 'href="'.$CI->config->site_url($href).'" '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 348 | } |
| 349 | else |
| 350 | { |
Derek Allard | 76763bb | 2009-09-16 11:25:20 +0000 | [diff] [blame] | 351 | $link .= 'href="'.$CI->config->slash_item('base_url').$href.'" '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | $link .= 'rel="'.$rel.'" type="'.$type.'" '; |
| 355 | |
| 356 | if ($media != '') |
| 357 | { |
| 358 | $link .= 'media="'.$media.'" '; |
| 359 | } |
| 360 | |
| 361 | if ($title != '') |
| 362 | { |
| 363 | $link .= 'title="'.$title.'" '; |
| 364 | } |
| 365 | |
| 366 | $link .= '/>'; |
| 367 | } |
| 368 | |
| 369 | |
| 370 | return $link; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | // ------------------------------------------------------------------------ |
| 375 | |
| 376 | /** |
| 377 | * Generates meta tags from an array of key/values |
| 378 | * |
| 379 | * @access public |
| 380 | * @param array |
| 381 | * @return string |
| 382 | */ |
| 383 | if ( ! function_exists('meta')) |
| 384 | { |
| 385 | function meta($name = '', $content = '', $type = 'name', $newline = "\n") |
| 386 | { |
| 387 | // Since we allow the data to be passes as a string, a simple array |
| 388 | // or a multidimensional one, we need to do a little prepping. |
| 389 | if ( ! is_array($name)) |
| 390 | { |
| 391 | $name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline)); |
| 392 | } |
| 393 | else |
| 394 | { |
| 395 | // Turn single array into multidimensional |
| 396 | if (isset($name['name'])) |
| 397 | { |
| 398 | $name = array($name); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | $str = ''; |
| 403 | foreach ($name as $meta) |
| 404 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 405 | $type = ( ! isset($meta['type']) OR $meta['type'] == 'name') ? 'name' : 'http-equiv'; |
| 406 | $name = ( ! isset($meta['name'])) ? '' : $meta['name']; |
| 407 | $content = ( ! isset($meta['content'])) ? '' : $meta['content']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 408 | $newline = ( ! isset($meta['newline'])) ? "\n" : $meta['newline']; |
| 409 | |
| 410 | $str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline; |
| 411 | } |
| 412 | |
| 413 | return $str; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | // ------------------------------------------------------------------------ |
| 418 | |
| 419 | /** |
| 420 | * Generates non-breaking space entities based on number supplied |
| 421 | * |
| 422 | * @access public |
| 423 | * @param integer |
| 424 | * @return string |
| 425 | */ |
| 426 | if ( ! function_exists('nbs')) |
| 427 | { |
| 428 | function nbs($num = 1) |
| 429 | { |
| 430 | return str_repeat(" ", $num); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | |
| 435 | /* End of file html_helper.php */ |
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 436 | /* Location: ./system/helpers/html_helper.php */ |