Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | 1e6b72c | 2012-01-06 19:09:22 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 9 | * Copyright (c) 2014 - 2018, British Columbia Institute of Technology |
Andrey Andreev | 1e6b72c | 2012-01-06 19:09:22 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 32 | * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 35 | * @since Version 1.0.0 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | /** |
| 41 | * CodeIgniter HTML Helpers |
| 42 | * |
| 43 | * @package CodeIgniter |
| 44 | * @subpackage Helpers |
| 45 | * @category Helpers |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 46 | * @author EllisLab Dev Team |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 47 | * @link https://codeigniter.com/user_guide/helpers/html_helper.html |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 48 | */ |
| 49 | |
| 50 | // ------------------------------------------------------------------------ |
| 51 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 52 | if ( ! function_exists('heading')) |
| 53 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 54 | /** |
| 55 | * Heading |
| 56 | * |
| 57 | * Generates an HTML heading tag. |
| 58 | * |
| 59 | * @param string content |
| 60 | * @param int heading level |
| 61 | * @param string |
| 62 | * @return string |
| 63 | */ |
Greg Aker | 826429c | 2011-04-18 09:40:19 -0500 | [diff] [blame] | 64 | function heading($data = '', $h = '1', $attributes = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 65 | { |
Eric Barnes | acedd2b | 2012-07-29 00:15:40 -0400 | [diff] [blame] | 66 | return '<h'.$h._stringify_attributes($attributes).'>'.$data.'</h'.$h.'>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
| 70 | // ------------------------------------------------------------------------ |
| 71 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 72 | if ( ! function_exists('ul')) |
| 73 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 74 | /** |
| 75 | * Unordered List |
| 76 | * |
| 77 | * Generates an HTML unordered list from an single or multi-dimensional array. |
| 78 | * |
| 79 | * @param array |
| 80 | * @param mixed |
| 81 | * @return string |
| 82 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 83 | function ul($list, $attributes = '') |
| 84 | { |
| 85 | return _list('ul', $list, $attributes); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // ------------------------------------------------------------------------ |
| 90 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 91 | if ( ! function_exists('ol')) |
| 92 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 93 | /** |
| 94 | * Ordered List |
| 95 | * |
| 96 | * Generates an HTML ordered list from an single or multi-dimensional array. |
| 97 | * |
| 98 | * @param array |
| 99 | * @param mixed |
| 100 | * @return string |
| 101 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 102 | function ol($list, $attributes = '') |
| 103 | { |
| 104 | return _list('ol', $list, $attributes); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // ------------------------------------------------------------------------ |
| 109 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 110 | if ( ! function_exists('_list')) |
| 111 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 112 | /** |
| 113 | * Generates the list |
| 114 | * |
| 115 | * Generates an HTML ordered list from an single or multi-dimensional array. |
| 116 | * |
| 117 | * @param string |
| 118 | * @param mixed |
| 119 | * @param mixed |
| 120 | * @param int |
| 121 | * @return string |
| 122 | */ |
Rasmus Lerdorf | e736f49 | 2013-05-18 10:25:03 -0400 | [diff] [blame] | 123 | function _list($type = 'ul', $list = array(), $attributes = '', $depth = 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 124 | { |
| 125 | // If an array wasn't submitted there's nothing to do... |
| 126 | if ( ! is_array($list)) |
| 127 | { |
| 128 | return $list; |
| 129 | } |
| 130 | |
| 131 | // Set the indentation based on the depth |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 132 | $out = str_repeat(' ', $depth) |
| 133 | // Write the opening list tag |
| 134 | .'<'.$type._stringify_attributes($attributes).">\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 135 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 136 | |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 137 | // Cycle through the list elements. If an array is |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 138 | // encountered we will recursively call _list() |
| 139 | |
| 140 | static $_last_list_item = ''; |
| 141 | foreach ($list as $key => $val) |
| 142 | { |
| 143 | $_last_list_item = $key; |
| 144 | |
Andrey Andreev | 1e6b72c | 2012-01-06 19:09:22 +0200 | [diff] [blame] | 145 | $out .= str_repeat(' ', $depth + 2).'<li>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 146 | |
| 147 | if ( ! is_array($val)) |
| 148 | { |
| 149 | $out .= $val; |
| 150 | } |
| 151 | else |
| 152 | { |
Andrey Andreev | 1e6b72c | 2012-01-06 19:09:22 +0200 | [diff] [blame] | 153 | $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] | 154 | } |
| 155 | |
| 156 | $out .= "</li>\n"; |
| 157 | } |
| 158 | |
Andrey Andreev | 1e6b72c | 2012-01-06 19:09:22 +0200 | [diff] [blame] | 159 | // Set the indentation for the closing tag and apply it |
| 160 | return $out.str_repeat(' ', $depth).'</'.$type.">\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
| 164 | // ------------------------------------------------------------------------ |
| 165 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 166 | if ( ! function_exists('img')) |
| 167 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 168 | /** |
| 169 | * Image |
| 170 | * |
| 171 | * Generates an <img /> element |
| 172 | * |
| 173 | * @param mixed |
| 174 | * @param bool |
Eric Barnes | 62ab8b2 | 2012-07-28 14:57:04 -0400 | [diff] [blame] | 175 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 176 | * @return string |
| 177 | */ |
Eric Barnes | 62ab8b2 | 2012-07-28 14:57:04 -0400 | [diff] [blame] | 178 | function img($src = '', $index_page = FALSE, $attributes = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 179 | { |
| 180 | if ( ! is_array($src) ) |
| 181 | { |
| 182 | $src = array('src' => $src); |
| 183 | } |
| 184 | |
Derek Allard | a0905f3 | 2010-07-05 08:11:33 -0400 | [diff] [blame] | 185 | // If there is no alt attribute defined, set it to an empty string |
| 186 | if ( ! isset($src['alt'])) |
| 187 | { |
| 188 | $src['alt'] = ''; |
| 189 | } |
| 190 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 191 | $img = '<img'; |
| 192 | |
Andrey Andreev | 1e6b72c | 2012-01-06 19:09:22 +0200 | [diff] [blame] | 193 | foreach ($src as $k => $v) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 194 | { |
Andrey Andreev | 356bc66 | 2017-03-06 14:39:28 +0200 | [diff] [blame] | 195 | if ($k === 'src' && ! preg_match('#^(data:[a-z,;])|(([a-z]+:)?(?<!data:)//)#i', $v)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 196 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 197 | if ($index_page === TRUE) |
| 198 | { |
Andrey Andreev | 119d8a7 | 2014-01-08 15:27:53 +0200 | [diff] [blame] | 199 | $img .= ' src="'.get_instance()->config->site_url($v).'"'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 200 | } |
| 201 | else |
| 202 | { |
Andrey Andreev | 119d8a7 | 2014-01-08 15:27:53 +0200 | [diff] [blame] | 203 | $img .= ' src="'.get_instance()->config->slash_item('base_url').$v.'"'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | else |
| 207 | { |
Andrey Andreev | 2046b1a | 2012-03-26 21:07:04 +0300 | [diff] [blame] | 208 | $img .= ' '.$k.'="'.$v.'"'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
Andrey Andreev | 6a64f85 | 2012-08-15 11:16:47 +0300 | [diff] [blame] | 212 | return $img._stringify_attributes($attributes).' />'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | |
| 216 | // ------------------------------------------------------------------------ |
| 217 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 218 | if ( ! function_exists('doctype')) |
| 219 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 220 | /** |
| 221 | * Doctype |
| 222 | * |
| 223 | * Generates a page document type declaration |
| 224 | * |
Przemyslaw Tomaszewski | 8711aeb | 2012-07-22 03:28:41 +0200 | [diff] [blame] | 225 | * Examples of valid options: html5, xhtml-11, xhtml-strict, xhtml-trans, |
| 226 | * xhtml-frame, html4-strict, html4-trans, and html4-frame. |
| 227 | * All values are saved in the doctypes config file. |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 228 | * |
| 229 | * @param string type The doctype to be generated |
| 230 | * @return string |
| 231 | */ |
Derek Allard | 93bddd1 | 2009-04-14 19:27:38 +0000 | [diff] [blame] | 232 | function doctype($type = 'xhtml1-strict') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 233 | { |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 234 | static $doctypes; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 235 | |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 236 | if ( ! is_array($doctypes)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 237 | { |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 238 | if (file_exists(APPPATH.'config/doctypes.php')) |
Greg Aker | d96f882 | 2011-12-27 16:23:47 -0600 | [diff] [blame] | 239 | { |
| 240 | include(APPPATH.'config/doctypes.php'); |
| 241 | } |
Eric Barnes | 9280834 | 2011-03-18 09:02:37 -0400 | [diff] [blame] | 242 | |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 243 | if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 244 | { |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 245 | include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); |
| 246 | } |
| 247 | |
| 248 | if (empty($_doctypes) OR ! is_array($_doctypes)) |
| 249 | { |
| 250 | $doctypes = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 251 | return FALSE; |
| 252 | } |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 253 | |
| 254 | $doctypes = $_doctypes; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 257 | return isset($doctypes[$type]) ? $doctypes[$type] : FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
| 261 | // ------------------------------------------------------------------------ |
| 262 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 263 | if ( ! function_exists('link_tag')) |
| 264 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 265 | /** |
| 266 | * Link |
| 267 | * |
| 268 | * Generates link to a CSS file |
| 269 | * |
| 270 | * @param mixed stylesheet hrefs or an array |
| 271 | * @param string rel |
| 272 | * @param string type |
| 273 | * @param string title |
| 274 | * @param string media |
| 275 | * @param bool should index_page be added to the css path |
| 276 | * @return string |
| 277 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 278 | function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) |
| 279 | { |
| 280 | $CI =& get_instance(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 281 | $link = '<link '; |
| 282 | |
| 283 | if (is_array($href)) |
| 284 | { |
Andrey Andreev | 1e6b72c | 2012-01-06 19:09:22 +0200 | [diff] [blame] | 285 | foreach ($href as $k => $v) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 286 | { |
Andrey Andreev | d2e3a6f | 2014-03-12 16:22:46 +0200 | [diff] [blame] | 287 | if ($k === 'href' && ! preg_match('#^([a-z]+:)?//#i', $v)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | { |
| 289 | if ($index_page === TRUE) |
| 290 | { |
Derek Allard | 76763bb | 2009-09-16 11:25:20 +0000 | [diff] [blame] | 291 | $link .= 'href="'.$CI->config->site_url($v).'" '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 292 | } |
| 293 | else |
| 294 | { |
Derek Allard | 76763bb | 2009-09-16 11:25:20 +0000 | [diff] [blame] | 295 | $link .= 'href="'.$CI->config->slash_item('base_url').$v.'" '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | else |
| 299 | { |
Andrey Andreev | 2046b1a | 2012-03-26 21:07:04 +0300 | [diff] [blame] | 300 | $link .= $k.'="'.$v.'" '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 301 | } |
| 302 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 303 | } |
| 304 | else |
| 305 | { |
Emmanuel Grognet | 60f78b4 | 2014-05-16 08:25:15 +0200 | [diff] [blame] | 306 | if (preg_match('#^([a-z]+:)?//#i', $href)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 307 | { |
Derek Allard | 292dcd8 | 2009-09-16 11:26:32 +0000 | [diff] [blame] | 308 | $link .= 'href="'.$href.'" '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 309 | } |
| 310 | elseif ($index_page === TRUE) |
| 311 | { |
Derek Allard | 76763bb | 2009-09-16 11:25:20 +0000 | [diff] [blame] | 312 | $link .= 'href="'.$CI->config->site_url($href).'" '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 313 | } |
| 314 | else |
| 315 | { |
Derek Allard | 76763bb | 2009-09-16 11:25:20 +0000 | [diff] [blame] | 316 | $link .= 'href="'.$CI->config->slash_item('base_url').$href.'" '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | $link .= 'rel="'.$rel.'" type="'.$type.'" '; |
| 320 | |
Alex Bilbie | 773ccc3 | 2012-06-02 11:11:08 +0100 | [diff] [blame] | 321 | if ($media !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 322 | { |
| 323 | $link .= 'media="'.$media.'" '; |
| 324 | } |
| 325 | |
Alex Bilbie | 773ccc3 | 2012-06-02 11:11:08 +0100 | [diff] [blame] | 326 | if ($title !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 327 | { |
| 328 | $link .= 'title="'.$title.'" '; |
| 329 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 330 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 331 | |
Andrey Andreev | 2046b1a | 2012-03-26 21:07:04 +0300 | [diff] [blame] | 332 | return $link."/>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
| 336 | // ------------------------------------------------------------------------ |
| 337 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 338 | if ( ! function_exists('meta')) |
| 339 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 340 | /** |
| 341 | * Generates meta tags from an array of key/values |
| 342 | * |
| 343 | * @param array |
| 344 | * @param string |
| 345 | * @param string |
| 346 | * @param string |
| 347 | * @return string |
| 348 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 349 | function meta($name = '', $content = '', $type = 'name', $newline = "\n") |
| 350 | { |
| 351 | // Since we allow the data to be passes as a string, a simple array |
| 352 | // or a multidimensional one, we need to do a little prepping. |
| 353 | if ( ! is_array($name)) |
| 354 | { |
| 355 | $name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline)); |
| 356 | } |
Andrey Andreev | 2046b1a | 2012-03-26 21:07:04 +0300 | [diff] [blame] | 357 | elseif (isset($name['name'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 358 | { |
| 359 | // Turn single array into multidimensional |
Andrey Andreev | 2046b1a | 2012-03-26 21:07:04 +0300 | [diff] [blame] | 360 | $name = array($name); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | $str = ''; |
| 364 | foreach ($name as $meta) |
| 365 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 366 | $type = (isset($meta['type']) && $meta['type'] !== 'name') ? 'http-equiv' : 'name'; |
Andrey Andreev | ae31eb5 | 2012-05-17 14:54:15 +0300 | [diff] [blame] | 367 | $name = isset($meta['name']) ? $meta['name'] : ''; |
| 368 | $content = isset($meta['content']) ? $meta['content'] : ''; |
| 369 | $newline = isset($meta['newline']) ? $meta['newline'] : "\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 370 | |
| 371 | $str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline; |
| 372 | } |
| 373 | |
| 374 | return $str; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | // ------------------------------------------------------------------------ |
| 379 | |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 380 | if ( ! function_exists('br')) |
| 381 | { |
| 382 | /** |
| 383 | * Generates HTML BR tags based on number supplied |
| 384 | * |
Andrey Andreev | 59f0426 | 2014-02-26 19:04:36 +0200 | [diff] [blame] | 385 | * @deprecated 3.0.0 Use str_repeat() instead |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 386 | * @param int $count Number of times to repeat the tag |
| 387 | * @return string |
| 388 | */ |
| 389 | function br($count = 1) |
| 390 | { |
| 391 | return str_repeat('<br />', $count); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | // ------------------------------------------------------------------------ |
| 396 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 397 | if ( ! function_exists('nbs')) |
| 398 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 399 | /** |
| 400 | * Generates non-breaking space entities based on number supplied |
| 401 | * |
Andrey Andreev | 59f0426 | 2014-02-26 19:04:36 +0200 | [diff] [blame] | 402 | * @deprecated 3.0.0 Use str_repeat() instead |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 403 | * @param int |
| 404 | * @return string |
| 405 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 406 | function nbs($num = 1) |
| 407 | { |
Andrey Andreev | 1e6b72c | 2012-01-06 19:09:22 +0200 | [diff] [blame] | 408 | return str_repeat(' ', $num); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 409 | } |
| 410 | } |