1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 5.1.6 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
16 // ------------------------------------------------------------------------
19 * CodeIgniter HTML Helpers
21 * @package CodeIgniter
24 * @author ExpressionEngine Dev Team
25 * @link http://codeigniter.com/user_guide/helpers/html_helper.html
28 // ------------------------------------------------------------------------
33 * Generates an HTML heading tag. First param is the data.
34 * Second param is the size of the heading tag.
41 if ( ! function_exists('heading'))
43 function heading($data = '', $h = '1')
45 return "<h".$h.">".$data."</h".$h.">";
49 // ------------------------------------------------------------------------
54 * Generates an HTML unordered list from an single or multi-dimensional array.
61 if ( ! function_exists('ul'))
63 function ul($list, $attributes = '')
65 return _list('ul', $list, $attributes);
69 // ------------------------------------------------------------------------
74 * Generates an HTML ordered list from an single or multi-dimensional array.
81 if ( ! function_exists('ol'))
83 function ol($list, $attributes = '')
85 return _list('ol', $list, $attributes);
89 // ------------------------------------------------------------------------
94 * Generates an HTML ordered list from an single or multi-dimensional array.
103 if ( ! function_exists('_list'))
105 function _list($type = 'ul', $list, $attributes = '', $depth = 0)
107 // If an array wasn't submitted there's nothing to do...
108 if ( ! is_array($list))
113 // Set the indentation based on the depth
114 $out = str_repeat(" ", $depth);
116 // Were any attributes submitted? If so generate a string
117 if (is_array($attributes))
120 foreach ($attributes as $key => $val)
122 $atts .= ' ' . $key . '="' . $val . '"';
127 // Write the opening list tag
128 $out .= "<".$type.$attributes.">\n";
130 // Cycle through the list elements. If an array is
131 // encountered we will recursively call _list()
133 static $_last_list_item = '';
134 foreach ($list as $key => $val)
136 $_last_list_item = $key;
138 $out .= str_repeat(" ", $depth + 2);
141 if ( ! is_array($val))
147 $out .= $_last_list_item."\n";
148 $out .= _list($type, $val, '', $depth + 4);
149 $out .= str_repeat(" ", $depth + 2);
155 // Set the indentation for the closing tag
156 $out .= str_repeat(" ", $depth);
158 // Write the closing list tag
159 $out .= "</".$type.">\n";
165 // ------------------------------------------------------------------------
168 * Generates HTML BR tags based on number supplied
174 if ( ! function_exists('br'))
176 function br($num = 1)
178 return str_repeat("<br />", $num);
182 // ------------------------------------------------------------------------
187 * Generates an <img /> element
193 if ( ! function_exists('img'))
195 function img($src = '', $index_page = FALSE)
197 if ( ! is_array($src) )
199 $src = array('src' => $src);
202 // If there is no alt attribute defined, set it to an empty string
203 if ( ! isset($src['alt']))
210 foreach ($src as $k=>$v)
213 if ($k == 'src' AND strpos($v, '://') === FALSE)
215 $CI =& get_instance();
217 if ($index_page === TRUE)
219 $img .= ' src="'.$CI->config->site_url($v).'"';
223 $img .= ' src="'.$CI->config->slash_item('base_url').$v.'"';
228 $img .= " $k=\"$v\"";
238 // ------------------------------------------------------------------------
243 * Generates a page document type declaration
245 * Valid options are xhtml-11, xhtml-strict, xhtml-trans, xhtml-frame,
246 * html4-strict, html4-trans, and html4-frame. Values are saved in the
247 * doctypes config file.
250 * @param string type The doctype to be generated
253 if ( ! function_exists('doctype'))
255 function doctype($type = 'xhtml1-strict')
259 if ( ! is_array($_doctypes))
261 if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT))
263 include(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT);
265 elseif (is_file(APPPATH.'config/doctypes'.EXT))
267 include(APPPATH.'config/doctypes'.EXT);
270 if ( ! is_array($_doctypes))
276 if (isset($_doctypes[$type]))
278 return $_doctypes[$type];
287 // ------------------------------------------------------------------------
292 * Generates link to a CSS file
295 * @param mixed stylesheet hrefs or an array
298 * @param string title
299 * @param string media
300 * @param boolean should index_page be added to the css path
303 if ( ! function_exists('link_tag'))
305 function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
307 $CI =& get_instance();
313 foreach ($href as $k=>$v)
315 if ($k == 'href' AND strpos($v, '://') === FALSE)
317 if ($index_page === TRUE)
319 $link .= 'href="'.$CI->config->site_url($v).'" ';
323 $link .= 'href="'.$CI->config->slash_item('base_url').$v.'" ';
328 $link .= "$k=\"$v\" ";
336 if ( strpos($href, '://') !== FALSE)
338 $link .= 'href="'.$href.'" ';
340 elseif ($index_page === TRUE)
342 $link .= 'href="'.$CI->config->site_url($href).'" ';
346 $link .= 'href="'.$CI->config->slash_item('base_url').$href.'" ';
349 $link .= 'rel="'.$rel.'" type="'.$type.'" ';
353 $link .= 'media="'.$media.'" ';
358 $link .= 'title="'.$title.'" ';
369 // ------------------------------------------------------------------------
372 * Generates meta tags from an array of key/values
378 if ( ! function_exists('meta'))
380 function meta($name = '', $content = '', $type = 'name', $newline = "\n")
382 // Since we allow the data to be passes as a string, a simple array
383 // or a multidimensional one, we need to do a little prepping.
384 if ( ! is_array($name))
386 $name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline));
390 // Turn single array into multidimensional
391 if (isset($name['name']))
393 $name = array($name);
398 foreach ($name as $meta)
400 $type = ( ! isset($meta['type']) OR $meta['type'] == 'name') ? 'name' : 'http-equiv';
401 $name = ( ! isset($meta['name'])) ? '' : $meta['name'];
402 $content = ( ! isset($meta['content'])) ? '' : $meta['content'];
403 $newline = ( ! isset($meta['newline'])) ? "\n" : $meta['newline'];
405 $str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline;
412 // ------------------------------------------------------------------------
415 * Generates non-breaking space entities based on number supplied
421 if ( ! function_exists('nbs'))
423 function nbs($num = 1)
425 return str_repeat(" ", $num);
430 /* End of file html_helper.php */
431 /* Location: ./system/helpers/html_helper.php */