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