1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
\r
5 * An open source application development framework for PHP 4.3.2 or newer
\r
7 * @package CodeIgniter
\r
8 * @author ExpressionEngine Dev Team
\r
9 * @copyright Copyright (c) 2008, EllisLab, Inc.
\r
10 * @license http://codeigniter.com/user_guide/license.html
\r
11 * @link http://codeigniter.com
\r
12 * @since Version 1.0
\r
16 // ------------------------------------------------------------------------
\r
19 * CodeIgniter HTML Helpers
\r
21 * @package CodeIgniter
\r
22 * @subpackage Helpers
\r
24 * @author ExpressionEngine Dev Team
\r
25 * @link http://codeigniter.com/user_guide/helpers/html_helper.html
\r
28 // ------------------------------------------------------------------------
\r
33 * Generates an HTML heading tag. First param is the data.
\r
34 * Second param is the size of the heading tag.
\r
41 if ( ! function_exists('heading'))
\r
43 function heading($data = '', $h = '1')
\r
45 return "<h".$h.">".$data."</h".$h.">";
\r
49 // ------------------------------------------------------------------------
\r
54 * Generates an HTML unordered list from an single or multi-dimensional array.
\r
61 if ( ! function_exists('ul'))
\r
63 function ul($list, $attributes = '')
\r
65 return _list('ul', $list, $attributes);
\r
69 // ------------------------------------------------------------------------
\r
74 * Generates an HTML ordered list from an single or multi-dimensional array.
\r
81 if ( ! function_exists('ol'))
\r
83 function ol($list, $attributes = '')
\r
85 return _list('ol', $list, $attributes);
\r
89 // ------------------------------------------------------------------------
\r
92 * Generates the list
\r
94 * Generates an HTML ordered list from an single or multi-dimensional array.
\r
103 if ( ! function_exists('_list'))
\r
105 function _list($type = 'ul', $list, $attributes = '', $depth = 0)
\r
107 // If an array wasn't submitted there's nothing to do...
\r
108 if ( ! is_array($list))
\r
113 // Set the indentation based on the depth
\r
114 $out = str_repeat(" ", $depth);
\r
116 // Were any attributes submitted? If so generate a string
\r
117 if (is_array($attributes))
\r
120 foreach ($attributes as $key => $val)
\r
122 $atts .= ' ' . $key . '="' . $val . '"';
\r
124 $attributes = $atts;
\r
127 // Write the opening list tag
\r
128 $out .= "<".$type.$attributes.">\n";
\r
130 // Cycle through the list elements. If an array is
\r
131 // encountered we will recursively call _list()
\r
133 static $_last_list_item = '';
\r
134 foreach ($list as $key => $val)
\r
136 $_last_list_item = $key;
\r
138 $out .= str_repeat(" ", $depth + 2);
\r
141 if ( ! is_array($val))
\r
147 $out .= $_last_list_item."\n";
\r
148 $out .= _list($type, $val, '', $depth + 4);
\r
149 $out .= str_repeat(" ", $depth + 2);
\r
152 $out .= "</li>\n";
\r
155 // Set the indentation for the closing tag
\r
156 $out .= str_repeat(" ", $depth);
\r
158 // Write the closing list tag
\r
159 $out .= "</".$type.">\n";
\r
165 // ------------------------------------------------------------------------
\r
168 * Generates HTML BR tags based on number supplied
\r
174 if ( ! function_exists('br'))
\r
176 function br($num = 1)
\r
178 return str_repeat("<br />", $num);
\r
182 // ------------------------------------------------------------------------
\r
187 * Generates an <img /> element
\r
193 if ( ! function_exists('img'))
\r
195 function img($src = '', $index_page = FALSE)
\r
197 if ( ! is_array($src) )
\r
199 $src = array('src' => $src);
\r
204 foreach ($src as $k=>$v)
\r
207 if ($k == 'src' AND strpos($v, '://') === FALSE)
\r
209 $CI =& get_instance();
\r
211 if ($index_page === TRUE)
\r
213 $img .= ' src="'.$CI->config->site_url($v).'" ';
\r
217 $img .= ' src="'.$CI->config->slash_item('base_url').$v.'" ';
\r
222 $img .= " $k=\"$v\" ";
\r
232 // ------------------------------------------------------------------------
\r
237 * Generates link to a CSS file
\r
240 * @param mixed stylesheet hrefs or an array
\r
241 * @param string rel
\r
242 * @param string type
\r
243 * @param string title
\r
244 * @param string media
\r
245 * @param boolean should index_page be added to the css path
\r
248 if ( ! function_exists('link_tag'))
\r
250 function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
\r
252 $CI =& get_instance();
\r
256 if (is_array($href))
\r
258 foreach ($href as $k=>$v)
\r
260 if ($k == 'href' AND strpos($v, '://') === FALSE)
\r
262 if ($index_page === TRUE)
\r
264 $link .= ' href="'.$CI->config->site_url($v).'" ';
\r
268 $link .= ' href="'.$CI->config->slash_item('base_url').$v.'" ';
\r
273 $link .= "$k=\"$v\" ";
\r
281 if ( strpos($href, '://') !== FALSE)
\r
283 $link .= ' href="'.$href.'" ';
\r
285 elseif ($index_page === TRUE)
\r
287 $link .= ' href="'.$CI->config->site_url($href).'" ';
\r
291 $link .= ' href="'.$CI->config->slash_item('base_url').$href.'" ';
\r
294 $link .= 'rel="'.$rel.'" type="'.$type.'" ';
\r
298 $link .= 'media="'.$media.'" ';
\r
303 $link .= 'title="'.$title.'" ';
\r
314 // ------------------------------------------------------------------------
\r
317 * Generates meta tags from an array of key/values
\r
323 if ( ! function_exists('meta'))
\r
325 function meta($name = '', $content = '', $type = 'name', $newline = "\n")
\r
327 // Since we allow the data to be passes as a string, a simple array
\r
328 // or a multidimensional one, we need to do a little prepping.
\r
329 if ( ! is_array($name))
\r
331 $name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline));
\r
335 // Turn single array into multidimensional
\r
336 if (isset($name['name']))
\r
338 $name = array($name);
\r
343 foreach ($name as $meta)
\r
345 $type = ( ! isset($meta['type']) OR $meta['type'] == 'name') ? 'name' : 'http-equiv';
\r
346 $name = ( ! isset($meta['name'])) ? '' : $meta['name'];
\r
347 $content = ( ! isset($meta['content'])) ? '' : $meta['content'];
\r
348 $newline = ( ! isset($meta['newline'])) ? "\n" : $meta['newline'];
\r
350 $str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline;
\r
357 // ------------------------------------------------------------------------
\r
360 * Generates non-breaking space entities based on number supplied
\r
366 if ( ! function_exists('nbs'))
\r
368 function nbs($num = 1)
\r
370 return str_repeat(" ", $num);
\r
375 /* End of file html_helper.php */
\r
376 /* Location: ./system/helpers/html_helper.php */