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