Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 1 | <?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 Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 8 | * @author ExpressionEngine Dev Team
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 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
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 24 | * @author ExpressionEngine Dev Team
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 25 | * @link http://codeigniter.com/user_guide/helpers/html_helper.html
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 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 | */
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 41 | if (! function_exists('heading'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 42 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 43 | function heading($data = '', $h = '1')
|
| 44 | {
|
| 45 | return "<h".$h.">".$data."</h".$h.">";
|
| 46 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 47 | }
|
| 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 Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 61 | if (! function_exists('ul'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 62 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 63 | function ul($list, $attributes = '')
|
| 64 | {
|
| 65 | return _list('ul', $list, $attributes);
|
| 66 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 67 | }
|
| 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 Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 81 | if (! function_exists('ol'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 82 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 83 | function ol($list, $attributes = '')
|
| 84 | {
|
| 85 | return _list('ol', $list, $attributes);
|
| 86 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 87 | }
|
| 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 Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 103 | if (! function_exists('_list'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 104 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 105 | function _list($type = 'ul', $list, $attributes = '', $depth = 0)
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 106 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 107 | // If an array wasn't submitted there's nothing to do...
|
| 108 | if ( ! is_array($list))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 109 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 110 | return $list;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 111 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 112 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 113 | // 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 Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 118 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 119 | $atts = '';
|
| 120 | foreach ($attributes as $key => $val)
|
| 121 | {
|
| 122 | $atts .= ' ' . $key . '="' . $val . '"';
|
| 123 | }
|
| 124 | $attributes = $atts;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 125 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 126 |
|
| 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 Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 138 | $out .= str_repeat(" ", $depth + 2);
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 139 | $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 Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 153 | }
|
| 154 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 155 | // Set the indentation for the closing tag
|
| 156 | $out .= str_repeat(" ", $depth);
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 157 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 158 | // Write the closing list tag
|
| 159 | $out .= "</".$type.">\n";
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 160 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 161 | return $out;
|
| 162 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 163 | }
|
| 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 Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 174 | if (! function_exists('br'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 175 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 176 | function br($num = 1)
|
| 177 | {
|
| 178 | return str_repeat("<br />", $num);
|
| 179 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 180 | }
|
| 181 |
|
| 182 | // ------------------------------------------------------------------------
|
| 183 |
|
| 184 | /**
|
Derek Allard | 432e973 | 2008-01-30 16:13:57 +0000 | [diff] [blame] | 185 | * Image
|
| 186 | *
|
Derek Allard | f653a2f | 2008-01-30 20:16:01 +0000 | [diff] [blame^] | 187 | * Generates an <img /> element
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 188 | *
|
| 189 | * @access public
|
Derek Allard | f653a2f | 2008-01-30 20:16:01 +0000 | [diff] [blame^] | 190 | * @param mixed
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 191 | * @return string
|
| 192 | */
|
Derek Allard | f653a2f | 2008-01-30 20:16:01 +0000 | [diff] [blame^] | 193 | if (! function_exists('img'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 194 | {
|
Derek Allard | f653a2f | 2008-01-30 20:16:01 +0000 | [diff] [blame^] | 195 | function img($src = '', $index_page = FALSE)
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 196 | {
|
Derek Allard | f653a2f | 2008-01-30 20:16:01 +0000 | [diff] [blame^] | 197 | if ( ! is_array($src) )
|
Derek Allard | 432e973 | 2008-01-30 16:13:57 +0000 | [diff] [blame] | 198 | {
|
Derek Allard | f653a2f | 2008-01-30 20:16:01 +0000 | [diff] [blame^] | 199 | $src = array('src' => $src);
|
| 200 | }
|
| 201 |
|
| 202 | $img = '<img ';
|
| 203 |
|
| 204 | foreach ($src as $k=>$v)
|
| 205 | {
|
| 206 |
|
| 207 | if ($k == 'src' AND strpos($v, '://') === FALSE)
|
Derek Allard | 432e973 | 2008-01-30 16:13:57 +0000 | [diff] [blame] | 208 | {
|
Derek Allard | f653a2f | 2008-01-30 20:16:01 +0000 | [diff] [blame^] | 209 | $CI =& get_instance();
|
| 210 |
|
| 211 | if ($index_page === TRUE)
|
| 212 | {
|
| 213 | $img .= ' src="'.$CI->config->site_url($v).'" ';
|
| 214 | }
|
| 215 | else
|
| 216 | {
|
| 217 | $img .= ' src="'.$CI->config->slash_item('base_url').$v.'" ';
|
| 218 | }
|
Derek Allard | 432e973 | 2008-01-30 16:13:57 +0000 | [diff] [blame] | 219 | }
|
| 220 | else
|
| 221 | {
|
Derek Allard | f653a2f | 2008-01-30 20:16:01 +0000 | [diff] [blame^] | 222 | $img .= " $k=\"$v\" ";
|
Derek Allard | 432e973 | 2008-01-30 16:13:57 +0000 | [diff] [blame] | 223 | }
|
Derek Allard | 432e973 | 2008-01-30 16:13:57 +0000 | [diff] [blame] | 224 | }
|
Derek Allard | f653a2f | 2008-01-30 20:16:01 +0000 | [diff] [blame^] | 225 |
|
| 226 | $img .= '/>';
|
| 227 |
|
| 228 | return $img;
|
Derek Allard | 432e973 | 2008-01-30 16:13:57 +0000 | [diff] [blame] | 229 | }
|
| 230 | }
|
| 231 |
|
| 232 | // ------------------------------------------------------------------------
|
| 233 |
|
| 234 | /**
|
| 235 | * Link
|
| 236 | *
|
| 237 | * Generates link to a CSS file
|
| 238 | *
|
| 239 | * @access public
|
Derek Allard | 165da61 | 2008-01-30 16:36:00 +0000 | [diff] [blame] | 240 | * @param mixed stylesheet hrefs or an array
|
| 241 | * @param string rel
|
| 242 | * @param string type
|
| 243 | * @param string title
|
| 244 | * @param string media
|
Derek Allard | 432e973 | 2008-01-30 16:13:57 +0000 | [diff] [blame] | 245 | * @param boolean should index_page be added to the css path
|
| 246 | * @return string
|
| 247 | */
|
Derek Allard | 0684897 | 2008-01-30 16:55:30 +0000 | [diff] [blame] | 248 | if (! function_exists('link_tag'))
|
Derek Allard | 432e973 | 2008-01-30 16:13:57 +0000 | [diff] [blame] | 249 | {
|
Derek Allard | 0684897 | 2008-01-30 16:55:30 +0000 | [diff] [blame] | 250 | function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
|
Derek Allard | 432e973 | 2008-01-30 16:13:57 +0000 | [diff] [blame] | 251 | {
|
| 252 | $CI =& get_instance();
|
| 253 |
|
Derek Allard | f653a2f | 2008-01-30 20:16:01 +0000 | [diff] [blame^] | 254 | $link = '<link ';
|
Derek Allard | 432e973 | 2008-01-30 16:13:57 +0000 | [diff] [blame] | 255 |
|
| 256 | if (is_array($href))
|
| 257 | {
|
| 258 | foreach ($href as $k=>$v)
|
| 259 | {
|
| 260 | if ($k == 'href' AND strpos($k, '://') === FALSE)
|
| 261 | {
|
| 262 | if ($index_page === TRUE)
|
| 263 | {
|
| 264 | $link .= ' href="'.$CI->config->site_url($v).'" ';
|
| 265 | }
|
| 266 | else
|
| 267 | {
|
| 268 | $link .= ' href="'.$CI->config->slash_item('base_url').$v.'" ';
|
| 269 | }
|
| 270 | }
|
| 271 | else
|
| 272 | {
|
| 273 | $link .= "$k=\"$v\" ";
|
| 274 | }
|
| 275 | }
|
| 276 |
|
| 277 | $link .= "/>\n";
|
| 278 | }
|
| 279 | else
|
| 280 | {
|
| 281 | if ( strpos($href, '://') !== FALSE)
|
| 282 | {
|
| 283 | $link .= ' href="'.$href.'" ';
|
| 284 | }
|
| 285 | elseif ($index_page === TRUE)
|
| 286 | {
|
| 287 | $link .= ' href="'.$CI->config->site_url($href).'" ';
|
| 288 | }
|
| 289 | else
|
| 290 | {
|
| 291 | $link .= ' href="'.$CI->config->slash_item('base_url').$href.'" ';
|
| 292 | }
|
| 293 |
|
| 294 | $link .= 'rel="'.$rel.'" type="'.$type.'" ';
|
| 295 |
|
| 296 | if ($media != '')
|
| 297 | {
|
| 298 | $link .= 'media="'.$media.'" ';
|
| 299 | }
|
| 300 |
|
| 301 | if ($title != '')
|
| 302 | {
|
| 303 | $link .= 'title="'.$title.'" ';
|
| 304 | }
|
| 305 |
|
| 306 | $link .= '/>'."\n";
|
| 307 | }
|
| 308 |
|
| 309 |
|
| 310 | return $link;
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 311 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 312 | }
|
| 313 |
|
| 314 | // ------------------------------------------------------------------------
|
| 315 |
|
| 316 | /**
|
| 317 | * Generates meta tags from an array of key/values
|
| 318 | *
|
| 319 | * @access public
|
| 320 | * @param array
|
| 321 | * @return string
|
| 322 | */
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 323 | if (! function_exists('meta'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 324 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 325 | function meta($meta = array(), $newline = "\n")
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 326 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 327 | $str = '';
|
| 328 | foreach ($meta as $key => $val)
|
| 329 | {
|
| 330 | $str .= '<meta http-equiv="'.$key.'" content="'.$val.'" />'.$newline;
|
| 331 | }
|
| 332 |
|
| 333 | return $str;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 334 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 335 | }
|
| 336 |
|
Derek Allard | 432e973 | 2008-01-30 16:13:57 +0000 | [diff] [blame] | 337 | // ------------------------------------------------------------------------
|
| 338 |
|
| 339 | /**
|
| 340 | * Generates non-breaking space entities based on number supplied
|
| 341 | *
|
| 342 | * @access public
|
| 343 | * @param integer
|
| 344 | * @return string
|
| 345 | */
|
| 346 | if (! function_exists('nbs'))
|
| 347 | {
|
| 348 | function nbs($num = 1)
|
| 349 | {
|
| 350 | return str_repeat(" ", $num);
|
| 351 | }
|
| 352 | }
|
| 353 |
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 354 | ?> |