Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +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 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 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 | debcc36 | 2012-01-07 02:05:29 +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 | debcc36 | 2012-01-07 02:05:29 +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 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * CodeIgniter URL Helpers |
| 32 | * |
| 33 | * @package CodeIgniter |
| 34 | * @subpackage Helpers |
| 35 | * @category Helpers |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 36 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/helpers/url_helper.html |
| 38 | */ |
| 39 | |
| 40 | // ------------------------------------------------------------------------ |
| 41 | |
| 42 | /** |
| 43 | * Site URL |
| 44 | * |
| 45 | * Create a local URL based on your basepath. Segments can be passed via the |
| 46 | * first parameter either as a string or an array. |
| 47 | * |
| 48 | * @access public |
| 49 | * @param string |
| 50 | * @return string |
| 51 | */ |
| 52 | if ( ! function_exists('site_url')) |
| 53 | { |
| 54 | function site_url($uri = '') |
| 55 | { |
| 56 | $CI =& get_instance(); |
| 57 | return $CI->config->site_url($uri); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // ------------------------------------------------------------------------ |
| 62 | |
| 63 | /** |
| 64 | * Base URL |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 65 | * |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 66 | * Create a local URL based on your basepath. |
| 67 | * Segments can be passed in as a string or an array, same as site_url |
| 68 | * or a URL to a file can be passed in, e.g. to an image file. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 69 | * |
| 70 | * @access public |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 71 | * @param string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 72 | * @return string |
| 73 | */ |
| 74 | if ( ! function_exists('base_url')) |
| 75 | { |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 76 | function base_url($uri = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 77 | { |
| 78 | $CI =& get_instance(); |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 79 | return $CI->config->base_url($uri); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
| 83 | // ------------------------------------------------------------------------ |
| 84 | |
| 85 | /** |
| 86 | * Current URL |
| 87 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 88 | * Returns the full URL (including segments) of the page where this |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 89 | * function is placed |
| 90 | * |
| 91 | * @access public |
| 92 | * @return string |
| 93 | */ |
| 94 | if ( ! function_exists('current_url')) |
| 95 | { |
| 96 | function current_url() |
| 97 | { |
| 98 | $CI =& get_instance(); |
| 99 | return $CI->config->site_url($CI->uri->uri_string()); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // ------------------------------------------------------------------------ |
| 104 | /** |
| 105 | * URL String |
| 106 | * |
| 107 | * Returns the URI segments. |
| 108 | * |
| 109 | * @access public |
| 110 | * @return string |
| 111 | */ |
| 112 | if ( ! function_exists('uri_string')) |
| 113 | { |
| 114 | function uri_string() |
| 115 | { |
| 116 | $CI =& get_instance(); |
| 117 | return $CI->uri->uri_string(); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // ------------------------------------------------------------------------ |
| 122 | |
| 123 | /** |
| 124 | * Index page |
| 125 | * |
| 126 | * Returns the "index_page" from your config file |
| 127 | * |
| 128 | * @access public |
| 129 | * @return string |
| 130 | */ |
| 131 | if ( ! function_exists('index_page')) |
| 132 | { |
| 133 | function index_page() |
| 134 | { |
| 135 | $CI =& get_instance(); |
| 136 | return $CI->config->item('index_page'); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // ------------------------------------------------------------------------ |
| 141 | |
| 142 | /** |
| 143 | * Anchor Link |
| 144 | * |
| 145 | * Creates an anchor based on the local URL. |
| 146 | * |
| 147 | * @access public |
| 148 | * @param string the URL |
| 149 | * @param string the link title |
| 150 | * @param mixed any attributes |
| 151 | * @return string |
| 152 | */ |
| 153 | if ( ! function_exists('anchor')) |
| 154 | { |
| 155 | function anchor($uri = '', $title = '', $attributes = '') |
| 156 | { |
| 157 | $title = (string) $title; |
| 158 | |
| 159 | if ( ! is_array($uri)) |
| 160 | { |
| 161 | $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri; |
| 162 | } |
| 163 | else |
| 164 | { |
| 165 | $site_url = site_url($uri); |
| 166 | } |
| 167 | |
| 168 | if ($title == '') |
| 169 | { |
| 170 | $title = $site_url; |
| 171 | } |
| 172 | |
| 173 | if ($attributes != '') |
| 174 | { |
| 175 | $attributes = _parse_attributes($attributes); |
| 176 | } |
| 177 | |
| 178 | return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>'; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // ------------------------------------------------------------------------ |
| 183 | |
| 184 | /** |
| 185 | * Anchor Link - Pop-up version |
| 186 | * |
| 187 | * Creates an anchor based on the local URL. The link |
| 188 | * opens a new window based on the attributes specified. |
| 189 | * |
| 190 | * @access public |
| 191 | * @param string the URL |
| 192 | * @param string the link title |
| 193 | * @param mixed any attributes |
| 194 | * @return string |
| 195 | */ |
| 196 | if ( ! function_exists('anchor_popup')) |
| 197 | { |
| 198 | function anchor_popup($uri = '', $title = '', $attributes = FALSE) |
| 199 | { |
| 200 | $title = (string) $title; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 201 | $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri; |
| 202 | |
| 203 | if ($title == '') |
| 204 | { |
| 205 | $title = $site_url; |
| 206 | } |
| 207 | |
| 208 | if ($attributes === FALSE) |
| 209 | { |
| 210 | return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title."</a>"; |
| 211 | } |
| 212 | |
| 213 | if ( ! is_array($attributes)) |
| 214 | { |
| 215 | $attributes = array(); |
| 216 | } |
| 217 | |
| 218 | foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val) |
| 219 | { |
| 220 | $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key]; |
| 221 | unset($attributes[$key]); |
| 222 | } |
| 223 | |
| 224 | if ($attributes != '') |
| 225 | { |
| 226 | $attributes = _parse_attributes($attributes); |
| 227 | } |
| 228 | |
| 229 | return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\"$attributes>".$title."</a>"; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // ------------------------------------------------------------------------ |
| 234 | |
| 235 | /** |
| 236 | * Mailto Link |
| 237 | * |
| 238 | * @access public |
| 239 | * @param string the email address |
| 240 | * @param string the link title |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 241 | * @param mixed any attributes |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 242 | * @return string |
| 243 | */ |
| 244 | if ( ! function_exists('mailto')) |
| 245 | { |
| 246 | function mailto($email, $title = '', $attributes = '') |
| 247 | { |
| 248 | $title = (string) $title; |
| 249 | |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 250 | if ($title == '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 251 | { |
| 252 | $title = $email; |
| 253 | } |
| 254 | |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 255 | return '<a href="mailto:'.$email.'"'._parse_attributes($attributes).'>'.$title.'</a>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | |
| 259 | // ------------------------------------------------------------------------ |
| 260 | |
| 261 | /** |
| 262 | * Encoded Mailto Link |
| 263 | * |
| 264 | * Create a spam-protected mailto link written in Javascript |
| 265 | * |
| 266 | * @access public |
| 267 | * @param string the email address |
| 268 | * @param string the link title |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 269 | * @param mixed any attributes |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | * @return string |
| 271 | */ |
| 272 | if ( ! function_exists('safe_mailto')) |
| 273 | { |
| 274 | function safe_mailto($email, $title = '', $attributes = '') |
| 275 | { |
| 276 | $title = (string) $title; |
| 277 | |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 278 | if ($title == '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 279 | { |
| 280 | $title = $email; |
| 281 | } |
| 282 | |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 283 | $x = str_split('<a href="mailto:', 1); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 284 | |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 285 | for ($i = 0, $l = strlen($email); $i < $l; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 286 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 287 | $x[] = '|'.ord($email[$i]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | $x[] = '"'; |
| 291 | |
| 292 | if ($attributes != '') |
| 293 | { |
| 294 | if (is_array($attributes)) |
| 295 | { |
| 296 | foreach ($attributes as $key => $val) |
| 297 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 298 | $x[] = ' '.$key.'="'; |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 299 | for ($i = 0, $l = strlen($val); $i < $l; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 300 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 301 | $x[] = '|'.ord($val[$i]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 302 | } |
| 303 | $x[] = '"'; |
| 304 | } |
| 305 | } |
| 306 | else |
| 307 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 308 | for ($i = 0, $l = strlen($attributes); $i < $l; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 309 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 310 | $x[] = $attributes[$i]; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | $x[] = '>'; |
| 316 | |
| 317 | $temp = array(); |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 318 | for ($i = 0, $l = strlen($title); $i < $l; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 319 | { |
| 320 | $ordinal = ord($title[$i]); |
| 321 | |
| 322 | if ($ordinal < 128) |
| 323 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 324 | $x[] = '|'.$ordinal; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 325 | } |
| 326 | else |
| 327 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 328 | if (count($temp) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 329 | { |
| 330 | $count = ($ordinal < 224) ? 2 : 3; |
| 331 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 332 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 333 | $temp[] = $ordinal; |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 334 | if (count($temp) === $count) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 335 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 336 | $number = ($count === 3) |
| 337 | ? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64) |
| 338 | : (($temp[0] % 32) * 64) + ($temp[1] % 64); |
| 339 | $x[] = '|'.$number; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 340 | $count = 1; |
| 341 | $temp = array(); |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>'; |
| 347 | |
| 348 | $x = array_reverse($x); |
| 349 | ob_start(); |
| 350 | |
| 351 | ?><script type="text/javascript"> |
| 352 | //<![CDATA[ |
| 353 | var l=new Array(); |
| 354 | <?php |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 355 | for ($i = 0, $c = count($x); $i < $c; $i++) { ?>l[<?php echo $i; ?>]='<?php echo $x[$i]; ?>';<?php } ?> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 356 | |
| 357 | for (var i = l.length-1; i >= 0; i=i-1){ |
| 358 | if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";"); |
| 359 | else document.write(unescape(l[i]));} |
| 360 | //]]> |
| 361 | </script><?php |
| 362 | |
| 363 | $buffer = ob_get_contents(); |
| 364 | ob_end_clean(); |
| 365 | return $buffer; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | // ------------------------------------------------------------------------ |
| 370 | |
| 371 | /** |
| 372 | * Auto-linker |
| 373 | * |
| 374 | * Automatically links URL and Email addresses. |
| 375 | * Note: There's a bit of extra code here to deal with |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 376 | * URLs or emails that end in a period. We'll strip these |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 377 | * off and add them after the link. |
| 378 | * |
| 379 | * @access public |
| 380 | * @param string the string |
| 381 | * @param string the type: email, url, or both |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 382 | * @param bool whether to create pop-up links |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 383 | * @return string |
| 384 | */ |
| 385 | if ( ! function_exists('auto_link')) |
| 386 | { |
| 387 | function auto_link($str, $type = 'both', $popup = FALSE) |
| 388 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 389 | if ($type !== 'email' && preg_match_all('#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i', $str, $matches)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 390 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 391 | $pop = ($popup) ? ' target="_blank" ' : ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 392 | |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 393 | for ($i = 0, $c = count($matches[0]); $i < $c; $i++) |
| 394 | { |
| 395 | if (preg_match('|\.$|', $matches[6][$i])) |
| 396 | { |
| 397 | $period = '.'; |
| 398 | $matches[6][$i] = substr($matches[6][$i], 0, -1); |
| 399 | } |
| 400 | else |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 401 | { |
| 402 | $period = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 403 | } |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 404 | |
| 405 | $str = str_replace($matches[0][$i], |
| 406 | $matches[1][$i].'<a href="http'.$matches[4][$i].'://' |
| 407 | .$matches[5][$i].$matches[6][$i].'"'.$pop.'>http' |
| 408 | .$matches[4][$i].'://'.$matches[5][$i] |
| 409 | .$matches[6][$i].'</a>'.$period, |
| 410 | $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 414 | if ($type !== 'url' && preg_match_all('/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i', $str, $matches)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 415 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 416 | for ($i = 0, $c = count($matches); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 417 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 418 | if (preg_match('|\.$|', $matches[3][$i])) |
| 419 | { |
| 420 | $period = '.'; |
| 421 | $matches[3][$i] = substr($matches[3][$i], 0, -1); |
| 422 | } |
| 423 | else |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 424 | { |
| 425 | $period = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 426 | } |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 427 | |
| 428 | $str = str_replace($matches[0][$i], safe_mailto($matches[1][$i].'@'.$matches[2][$i].'.'.$matches[3][$i]).$period, $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | |
| 432 | return $str; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | // ------------------------------------------------------------------------ |
| 437 | |
| 438 | /** |
| 439 | * Prep URL |
| 440 | * |
Derek Jones | d265871 | 2010-03-22 11:05:01 -0500 | [diff] [blame] | 441 | * Simply adds the http:// part if no scheme is included |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 442 | * |
| 443 | * @access public |
| 444 | * @param string the URL |
| 445 | * @return string |
| 446 | */ |
| 447 | if ( ! function_exists('prep_url')) |
| 448 | { |
| 449 | function prep_url($str = '') |
| 450 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 451 | if ($str === 'http://' OR $str == '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 452 | { |
| 453 | return ''; |
| 454 | } |
| 455 | |
Robin Sowell | d2167a0 | 2010-09-14 15:05:42 -0400 | [diff] [blame] | 456 | $url = parse_url($str); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 457 | |
Robin Sowell | d2167a0 | 2010-09-14 15:05:42 -0400 | [diff] [blame] | 458 | if ( ! $url OR ! isset($url['scheme'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 459 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 460 | return 'http://'.$str; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | return $str; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | // ------------------------------------------------------------------------ |
| 468 | |
| 469 | /** |
| 470 | * Create URL Title |
| 471 | * |
| 472 | * Takes a "title" string as input and creates a |
tubalmartin | 1a69710 | 2012-03-04 16:01:11 +0100 | [diff] [blame] | 473 | * human-friendly URL string with a "separator" string |
| 474 | * as the word separator. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 475 | * |
| 476 | * @access public |
| 477 | * @param string the string |
tubalmartin | 1a69710 | 2012-03-04 16:01:11 +0100 | [diff] [blame] | 478 | * @param string the separator |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 479 | * @return string |
| 480 | */ |
| 481 | if ( ! function_exists('url_title')) |
| 482 | { |
tubalmartin | 1a69710 | 2012-03-04 16:01:11 +0100 | [diff] [blame] | 483 | function url_title($str, $separator = '-', $lowercase = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 484 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 485 | if ($separator === 'dash') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 486 | { |
tubalmartin | 1a69710 | 2012-03-04 16:01:11 +0100 | [diff] [blame] | 487 | $separator = '-'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 488 | } |
tubalmartin | 1a69710 | 2012-03-04 16:01:11 +0100 | [diff] [blame] | 489 | else if ($separator == 'underscore') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 490 | { |
tubalmartin | 1a69710 | 2012-03-04 16:01:11 +0100 | [diff] [blame] | 491 | $separator = '_'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 492 | } |
tubalmartin | 1a69710 | 2012-03-04 16:01:11 +0100 | [diff] [blame] | 493 | |
| 494 | $q_separator = preg_quote($separator); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 495 | |
| 496 | $trans = array( |
tubalmartin | 1a69710 | 2012-03-04 16:01:11 +0100 | [diff] [blame] | 497 | '&.+?;' => '', |
| 498 | '[^a-z0-9 _-]' => '', |
| 499 | '\s+' => $separator, |
| 500 | '('.$q_separator.')+' => $separator |
tubalmartin | 3edd88e | 2012-03-03 22:10:34 +0100 | [diff] [blame] | 501 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 502 | |
| 503 | $str = strip_tags($str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 504 | foreach ($trans as $key => $val) |
| 505 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 506 | $str = preg_replace('#'.$key.'#i', $val, $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Derek Jones | 40a2fc8 | 2008-12-09 19:41:25 +0000 | [diff] [blame] | 509 | if ($lowercase === TRUE) |
| 510 | { |
| 511 | $str = strtolower($str); |
| 512 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 513 | |
Phil Sturgeon | a2bd363 | 2012-03-04 15:32:58 +0000 | [diff] [blame^] | 514 | return trim(trim($str, $separator)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | |
| 518 | // ------------------------------------------------------------------------ |
| 519 | |
| 520 | /** |
| 521 | * Header Redirect |
| 522 | * |
| 523 | * Header redirect in two flavors |
| 524 | * For very fine grained control over headers, you could use the Output |
| 525 | * Library's set_header() function. |
| 526 | * |
| 527 | * @access public |
| 528 | * @param string the URL |
Eric Barnes | f318950 | 2011-08-23 21:40:59 -0400 | [diff] [blame] | 529 | * @param string the method: location or refresh |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 530 | * @return string |
| 531 | */ |
| 532 | if ( ! function_exists('redirect')) |
| 533 | { |
Brandon Jones | 50e5dbb | 2011-11-07 15:51:05 -0500 | [diff] [blame] | 534 | function redirect($uri = '', $method = 'auto', $http_response_code = 302) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 535 | { |
Derek Jones | 534be03 | 2009-02-10 18:47:47 +0000 | [diff] [blame] | 536 | if ( ! preg_match('#^https?://#i', $uri)) |
| 537 | { |
| 538 | $uri = site_url($uri); |
| 539 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 540 | |
Brandon Jones | 50e5dbb | 2011-11-07 15:51:05 -0500 | [diff] [blame] | 541 | // IIS environment likely? Use 'refresh' for better compatibility |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 542 | if (DIRECTORY_SEPARATOR !== '/' && $method === 'auto') |
Brandon Jones | 50e5dbb | 2011-11-07 15:51:05 -0500 | [diff] [blame] | 543 | { |
| 544 | $method = 'refresh'; |
| 545 | } |
| 546 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 547 | switch($method) |
| 548 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 549 | case 'refresh': |
| 550 | header('Refresh:0;url='.$uri); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 551 | break; |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 552 | default: |
| 553 | header('Location: '.$uri, TRUE, $http_response_code); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 554 | break; |
| 555 | } |
| 556 | exit; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | // ------------------------------------------------------------------------ |
| 561 | |
| 562 | /** |
| 563 | * Parse out the attributes |
| 564 | * |
| 565 | * Some of the functions use this |
| 566 | * |
| 567 | * @access private |
| 568 | * @param array |
| 569 | * @param bool |
| 570 | * @return string |
| 571 | */ |
| 572 | if ( ! function_exists('_parse_attributes')) |
| 573 | { |
| 574 | function _parse_attributes($attributes, $javascript = FALSE) |
| 575 | { |
| 576 | if (is_string($attributes)) |
| 577 | { |
| 578 | return ($attributes != '') ? ' '.$attributes : ''; |
| 579 | } |
| 580 | |
| 581 | $att = ''; |
| 582 | foreach ($attributes as $key => $val) |
| 583 | { |
| 584 | if ($javascript == TRUE) |
| 585 | { |
| 586 | $att .= $key . '=' . $val . ','; |
| 587 | } |
| 588 | else |
| 589 | { |
| 590 | $att .= ' ' . $key . '="' . $val . '"'; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | if ($javascript == TRUE AND $att != '') |
| 595 | { |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 596 | return substr($att, 0, -1); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | return $att; |
| 600 | } |
| 601 | } |
| 602 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 603 | /* End of file url_helper.php */ |
Andrey Andreev | debcc36 | 2012-01-07 02:05:29 +0200 | [diff] [blame] | 604 | /* Location: ./system/helpers/url_helper.php */ |