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