blob: f88bc072352132010e1fe52f9c6a6e77c522109b [file] [log] [blame]
Derek Allardd2df9bc2007-04-15 17:41:17 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allardd2df9bc2007-04-15 17:41:17 +000012 * @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
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/helpers/html_helper.html
Derek Allardd2df9bc2007-04-15 17:41:17 +000026 */
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 */
Derek Jones269b9422008-01-28 21:00:20 +000041if (! function_exists('heading'))
Derek Allardd2df9bc2007-04-15 17:41:17 +000042{
Derek Jones269b9422008-01-28 21:00:20 +000043 function heading($data = '', $h = '1')
44 {
45 return "<h".$h.">".$data."</h".$h.">";
46 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000047}
48
49// ------------------------------------------------------------------------
50
51/**
52 * Unordered List
53 *
54 * Generates an HTML unordered list from an single or multi-dimensional array.
55 *
56 * @access public
57 * @param array
58 * @param mixed
59 * @return string
60 */
Derek Jones269b9422008-01-28 21:00:20 +000061if (! function_exists('ul'))
Derek Allardd2df9bc2007-04-15 17:41:17 +000062{
Derek Jones269b9422008-01-28 21:00:20 +000063 function ul($list, $attributes = '')
64 {
65 return _list('ul', $list, $attributes);
66 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000067}
68
69// ------------------------------------------------------------------------
70
71/**
72 * Ordered List
73 *
74 * Generates an HTML ordered list from an single or multi-dimensional array.
75 *
76 * @access public
77 * @param array
78 * @param mixed
79 * @return string
80 */
Derek Jones269b9422008-01-28 21:00:20 +000081if (! function_exists('ol'))
Derek Allardd2df9bc2007-04-15 17:41:17 +000082{
Derek Jones269b9422008-01-28 21:00:20 +000083 function ol($list, $attributes = '')
84 {
85 return _list('ol', $list, $attributes);
86 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000087}
88
89// ------------------------------------------------------------------------
90
91/**
92 * Generates the list
93 *
94 * Generates an HTML ordered list from an single or multi-dimensional array.
95 *
96 * @access private
97 * @param string
98 * @param mixed
99 * @param mixed
100 * @param intiger
101 * @return string
102 */
Derek Jones269b9422008-01-28 21:00:20 +0000103if (! function_exists('_list'))
Derek Allardd2df9bc2007-04-15 17:41:17 +0000104{
Derek Jones269b9422008-01-28 21:00:20 +0000105 function _list($type = 'ul', $list, $attributes = '', $depth = 0)
Derek Allardd2df9bc2007-04-15 17:41:17 +0000106 {
Derek Jones269b9422008-01-28 21:00:20 +0000107 // If an array wasn't submitted there's nothing to do...
108 if ( ! is_array($list))
Derek Allardd2df9bc2007-04-15 17:41:17 +0000109 {
Derek Jones269b9422008-01-28 21:00:20 +0000110 return $list;
Derek Allardd2df9bc2007-04-15 17:41:17 +0000111 }
Derek Allardd2df9bc2007-04-15 17:41:17 +0000112
Derek Jones269b9422008-01-28 21:00:20 +0000113 // Set the indentation based on the depth
114 $out = str_repeat(" ", $depth);
115
116 // Were any attributes submitted? If so generate a string
117 if (is_array($attributes))
Derek Allardd2df9bc2007-04-15 17:41:17 +0000118 {
Derek Jones269b9422008-01-28 21:00:20 +0000119 $atts = '';
120 foreach ($attributes as $key => $val)
121 {
122 $atts .= ' ' . $key . '="' . $val . '"';
123 }
124 $attributes = $atts;
Derek Allardd2df9bc2007-04-15 17:41:17 +0000125 }
Derek Jones269b9422008-01-28 21:00:20 +0000126
127 // Write the opening list tag
128 $out .= "<".$type.$attributes.">\n";
129
130 // Cycle through the list elements. If an array is
131 // encountered we will recursively call _list()
132
133 static $_last_list_item = '';
134 foreach ($list as $key => $val)
135 {
136 $_last_list_item = $key;
137
Derek Allardd2df9bc2007-04-15 17:41:17 +0000138 $out .= str_repeat(" ", $depth + 2);
Derek Jones269b9422008-01-28 21:00:20 +0000139 $out .= "<li>";
140
141 if ( ! is_array($val))
142 {
143 $out .= $val;
144 }
145 else
146 {
147 $out .= $_last_list_item."\n";
148 $out .= _list($type, $val, '', $depth + 4);
149 $out .= str_repeat(" ", $depth + 2);
150 }
151
152 $out .= "</li>\n";
Derek Allardd2df9bc2007-04-15 17:41:17 +0000153 }
154
Derek Jones269b9422008-01-28 21:00:20 +0000155 // Set the indentation for the closing tag
156 $out .= str_repeat(" ", $depth);
Derek Allardd2df9bc2007-04-15 17:41:17 +0000157
Derek Jones269b9422008-01-28 21:00:20 +0000158 // Write the closing list tag
159 $out .= "</".$type.">\n";
Derek Allardd2df9bc2007-04-15 17:41:17 +0000160
Derek Jones269b9422008-01-28 21:00:20 +0000161 return $out;
162 }
Derek Allardd2df9bc2007-04-15 17:41:17 +0000163}
164
165// ------------------------------------------------------------------------
166
167/**
168 * Generates HTML BR tags based on number supplied
169 *
170 * @access public
171 * @param integer
172 * @return string
173 */
Derek Jones269b9422008-01-28 21:00:20 +0000174if (! function_exists('br'))
Derek Allardd2df9bc2007-04-15 17:41:17 +0000175{
Derek Jones269b9422008-01-28 21:00:20 +0000176 function br($num = 1)
177 {
178 return str_repeat("<br />", $num);
179 }
Derek Allardd2df9bc2007-04-15 17:41:17 +0000180}
181
182// ------------------------------------------------------------------------
183
184/**
Derek Allard432e9732008-01-30 16:13:57 +0000185 * Image
186 *
187 * Generates an image tag
Derek Allardd2df9bc2007-04-15 17:41:17 +0000188 *
189 * @access public
190 * @param integer
191 * @return string
192 */
Derek Allard432e9732008-01-30 16:13:57 +0000193if (! function_exists('image'))
Derek Allardd2df9bc2007-04-15 17:41:17 +0000194{
Derek Allard432e9732008-01-30 16:13:57 +0000195 function image($src = '', $alt = '', $index_page = FALSE)
Derek Jones269b9422008-01-28 21:00:20 +0000196 {
Derek Allard432e9732008-01-30 16:13:57 +0000197 $CI =& get_instance();
198
199 $css = '';
200
201 foreach ($stylesheets as $stylesheet)
202 {
203 if (strpos($stylesheet, '://') !== FALSE)
204 {
205 $href = ' href="'.$stylesheet.'"';
206 }
207 elseif ($index_page === TRUE)
208 {
209 $href = ' href="'.$CI->config->site_url($stylesheet).'"';
210 }
211 else
212 {
213 $href = ' href="'.$CI->config->slash_item('base_url').$stylesheet.'"';
214 }
215
216 $media = ($media !== '') ? ' media="'.$media.'"' : '';
217
218 $css .= 'link type="text/css" rel="stylesheet"'.$href.$media.' />'."\n";
219 }
220
221 return $css;
222 }
223}
224
225// ------------------------------------------------------------------------
226
227/**
228 * Link
229 *
230 * Generates link to a CSS file
231 *
232 * @access public
Derek Allard165da612008-01-30 16:36:00 +0000233 * @param mixed stylesheet hrefs or an array
234 * @param string rel
235 * @param string type
236 * @param string title
237 * @param string media
Derek Allard432e9732008-01-30 16:13:57 +0000238 * @param boolean should index_page be added to the css path
239 * @return string
240 */
Derek Allard06848972008-01-30 16:55:30 +0000241if (! function_exists('link_tag'))
Derek Allard432e9732008-01-30 16:13:57 +0000242{
Derek Allard06848972008-01-30 16:55:30 +0000243 function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
Derek Allard432e9732008-01-30 16:13:57 +0000244 {
245 $CI =& get_instance();
246
247 $link = 'link ';
248
249 if (is_array($href))
250 {
251 foreach ($href as $k=>$v)
252 {
253 if ($k == 'href' AND strpos($k, '://') === FALSE)
254 {
255 if ($index_page === TRUE)
256 {
257 $link .= ' href="'.$CI->config->site_url($v).'" ';
258 }
259 else
260 {
261 $link .= ' href="'.$CI->config->slash_item('base_url').$v.'" ';
262 }
263 }
264 else
265 {
266 $link .= "$k=\"$v\" ";
267 }
268 }
269
270 $link .= "/>\n";
271 }
272 else
273 {
274 if ( strpos($href, '://') !== FALSE)
275 {
276 $link .= ' href="'.$href.'" ';
277 }
278 elseif ($index_page === TRUE)
279 {
280 $link .= ' href="'.$CI->config->site_url($href).'" ';
281 }
282 else
283 {
284 $link .= ' href="'.$CI->config->slash_item('base_url').$href.'" ';
285 }
286
287 $link .= 'rel="'.$rel.'" type="'.$type.'" ';
288
289 if ($media != '')
290 {
291 $link .= 'media="'.$media.'" ';
292 }
293
294 if ($title != '')
295 {
296 $link .= 'title="'.$title.'" ';
297 }
298
299 $link .= '/>'."\n";
300 }
301
302
303 return $link;
Derek Jones269b9422008-01-28 21:00:20 +0000304 }
Derek Allardd2df9bc2007-04-15 17:41:17 +0000305}
306
307// ------------------------------------------------------------------------
308
309/**
310 * Generates meta tags from an array of key/values
311 *
312 * @access public
313 * @param array
314 * @return string
315 */
Derek Jones269b9422008-01-28 21:00:20 +0000316if (! function_exists('meta'))
Derek Allardd2df9bc2007-04-15 17:41:17 +0000317{
Derek Jones269b9422008-01-28 21:00:20 +0000318 function meta($meta = array(), $newline = "\n")
Derek Allardd2df9bc2007-04-15 17:41:17 +0000319 {
Derek Jones269b9422008-01-28 21:00:20 +0000320 $str = '';
321 foreach ($meta as $key => $val)
322 {
323 $str .= '<meta http-equiv="'.$key.'" content="'.$val.'" />'.$newline;
324 }
325
326 return $str;
Derek Allardd2df9bc2007-04-15 17:41:17 +0000327 }
Derek Allardd2df9bc2007-04-15 17:41:17 +0000328}
329
Derek Allard432e9732008-01-30 16:13:57 +0000330// ------------------------------------------------------------------------
331
332/**
333 * Generates non-breaking space entities based on number supplied
334 *
335 * @access public
336 * @param integer
337 * @return string
338 */
339if (! function_exists('nbs'))
340{
341 function nbs($num = 1)
342 {
343 return str_repeat("&nbsp;", $num);
344 }
345}
346
adminb0dd10f2006-08-25 17:25:49 +0000347?>