blob: 58bde17b4536def16599f2a4ec0c305ac72867ae [file] [log] [blame]
Andrey Andreevdebcc362012-01-07 02:05:29 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreevdebcc362012-01-07 02:05:29 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreevdebcc362012-01-07 02:05:29 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * 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 Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * CodeIgniter URL Helpers
30 *
31 * @package CodeIgniter
32 * @subpackage Helpers
33 * @category Helpers
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000035 * @link http://codeigniter.com/user_guide/helpers/url_helper.html
36 */
37
38// ------------------------------------------------------------------------
39
Derek Allard2067d1a2008-11-13 22:59:24 +000040if ( ! function_exists('site_url'))
41{
Timothy Warrenb75faa12012-04-27 12:03:32 -040042 /**
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 * @param string
49 * @return string
50 */
Derek Allard2067d1a2008-11-13 22:59:24 +000051 function site_url($uri = '')
52 {
53 $CI =& get_instance();
54 return $CI->config->site_url($uri);
55 }
56}
57
58// ------------------------------------------------------------------------
59
Derek Allard2067d1a2008-11-13 22:59:24 +000060if ( ! function_exists('base_url'))
61{
Timothy Warrenb75faa12012-04-27 12:03:32 -040062 /**
63 * Base URL
64 *
65 * Create a local URL based on your basepath.
66 * Segments can be passed in as a string or an array, same as site_url
67 * or a URL to a file can be passed in, e.g. to an image file.
68 *
69 * @param string
70 * @return string
71 */
anaxamaxan@blackdog.locald09c51a2011-02-02 23:00:16 -080072 function base_url($uri = '')
Derek Allard2067d1a2008-11-13 22:59:24 +000073 {
74 $CI =& get_instance();
anaxamaxan@blackdog.locald09c51a2011-02-02 23:00:16 -080075 return $CI->config->base_url($uri);
Derek Allard2067d1a2008-11-13 22:59:24 +000076 }
77}
78
79// ------------------------------------------------------------------------
80
Derek Allard2067d1a2008-11-13 22:59:24 +000081if ( ! function_exists('current_url'))
82{
Timothy Warrenb75faa12012-04-27 12:03:32 -040083 /**
84 * Current URL
85 *
86 * Returns the full URL (including segments) of the page where this
87 * function is placed
88 *
89 * @return string
90 */
Derek Allard2067d1a2008-11-13 22:59:24 +000091 function current_url()
92 {
93 $CI =& get_instance();
94 return $CI->config->site_url($CI->uri->uri_string());
95 }
96}
97
98// ------------------------------------------------------------------------
Timothy Warrenb75faa12012-04-27 12:03:32 -040099
Derek Allard2067d1a2008-11-13 22:59:24 +0000100if ( ! function_exists('uri_string'))
101{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400102 /**
103 * URL String
104 *
105 * Returns the URI segments.
106 *
107 * @return string
108 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 function uri_string()
110 {
111 $CI =& get_instance();
112 return $CI->uri->uri_string();
113 }
114}
115
116// ------------------------------------------------------------------------
117
Derek Allard2067d1a2008-11-13 22:59:24 +0000118if ( ! function_exists('index_page'))
119{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400120 /**
121 * Index page
122 *
123 * Returns the "index_page" from your config file
124 *
125 * @return string
126 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000127 function index_page()
128 {
129 $CI =& get_instance();
130 return $CI->config->item('index_page');
131 }
132}
133
134// ------------------------------------------------------------------------
135
Derek Allard2067d1a2008-11-13 22:59:24 +0000136if ( ! function_exists('anchor'))
137{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400138 /**
139 * Anchor Link
140 *
141 * Creates an anchor based on the local URL.
142 *
143 * @param string the URL
144 * @param string the link title
145 * @param mixed any attributes
146 * @return string
147 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 function anchor($uri = '', $title = '', $attributes = '')
149 {
150 $title = (string) $title;
151
152 if ( ! is_array($uri))
153 {
Andrey Andreev12220872012-03-26 21:38:56 +0300154 $site_url = preg_match('!^\w+://! i', $uri) ? $uri : site_url($uri);
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 }
156 else
157 {
158 $site_url = site_url($uri);
159 }
160
Alex Bilbie773ccc32012-06-02 11:11:08 +0100161 if ($title === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000162 {
163 $title = $site_url;
164 }
165
Alex Bilbie773ccc32012-06-02 11:11:08 +0100166 if ($attributes !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 {
168 $attributes = _parse_attributes($attributes);
169 }
170
171 return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
172 }
173}
174
175// ------------------------------------------------------------------------
176
Derek Allard2067d1a2008-11-13 22:59:24 +0000177if ( ! function_exists('anchor_popup'))
178{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400179 /**
180 * Anchor Link - Pop-up version
181 *
182 * Creates an anchor based on the local URL. The link
183 * opens a new window based on the attributes specified.
184 *
185 * @param string the URL
186 * @param string the link title
187 * @param mixed any attributes
188 * @return string
189 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000190 function anchor_popup($uri = '', $title = '', $attributes = FALSE)
191 {
192 $title = (string) $title;
Andrey Andreev12220872012-03-26 21:38:56 +0300193 $site_url = preg_match('!^\w+://! i', $uri) ? $uri : site_url($uri);
Derek Allard2067d1a2008-11-13 22:59:24 +0000194
Alex Bilbie773ccc32012-06-02 11:11:08 +0100195 if ($title === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000196 {
197 $title = $site_url;
198 }
199
200 if ($attributes === FALSE)
201 {
Andrey Andreevae31eb52012-05-17 14:54:15 +0300202 return '<a href="javascript:void(0);" onclick="window.open(\''.$site_url."', '_blank');\">".$title.'</a>';
Derek Allard2067d1a2008-11-13 22:59:24 +0000203 }
204
205 if ( ! is_array($attributes))
206 {
Andrey Andreevf0a84102012-06-16 20:52:20 +0300207 $attributes = array($attributes);
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 }
209
210 foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val)
211 {
Andrey Andreev12220872012-03-26 21:38:56 +0300212 $atts[$key] = isset($attributes[$key]) ? $attributes[$key] : $val;
Derek Allard2067d1a2008-11-13 22:59:24 +0000213 unset($attributes[$key]);
214 }
215
Andrey Andreevf0a84102012-06-16 20:52:20 +0300216 $attributes = empty($attributes) ? '' : _parse_attributes($attributes);
Derek Allard2067d1a2008-11-13 22:59:24 +0000217
Andrey Andreevae31eb52012-05-17 14:54:15 +0300218 return '<a href="javascript:void(0);" onclick="window.open(\''.$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\"".$attributes.'>'.$title.'</a>';
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 }
220}
221
222// ------------------------------------------------------------------------
223
Derek Allard2067d1a2008-11-13 22:59:24 +0000224if ( ! function_exists('mailto'))
225{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400226 /**
227 * Mailto Link
228 *
229 * @param string the email address
230 * @param string the link title
231 * @param mixed any attributes
232 * @return string
233 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 function mailto($email, $title = '', $attributes = '')
235 {
236 $title = (string) $title;
237
Alex Bilbie773ccc32012-06-02 11:11:08 +0100238 if ($title === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000239 {
240 $title = $email;
241 }
242
Andrey Andreevdebcc362012-01-07 02:05:29 +0200243 return '<a href="mailto:'.$email.'"'._parse_attributes($attributes).'>'.$title.'</a>';
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 }
245}
246
247// ------------------------------------------------------------------------
248
Derek Allard2067d1a2008-11-13 22:59:24 +0000249if ( ! function_exists('safe_mailto'))
250{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400251 /**
252 * Encoded Mailto Link
253 *
254 * Create a spam-protected mailto link written in Javascript
255 *
256 * @param string the email address
257 * @param string the link title
258 * @param mixed any attributes
259 * @return string
260 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000261 function safe_mailto($email, $title = '', $attributes = '')
262 {
263 $title = (string) $title;
264
Alex Bilbie773ccc32012-06-02 11:11:08 +0100265 if ($title === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000266 {
267 $title = $email;
268 }
269
Andrey Andreevdebcc362012-01-07 02:05:29 +0200270 $x = str_split('<a href="mailto:', 1);
Derek Allard2067d1a2008-11-13 22:59:24 +0000271
Andrey Andreevdebcc362012-01-07 02:05:29 +0200272 for ($i = 0, $l = strlen($email); $i < $l; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000273 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200274 $x[] = '|'.ord($email[$i]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000275 }
276
277 $x[] = '"';
278
Alex Bilbie773ccc32012-06-02 11:11:08 +0100279 if ($attributes !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 {
281 if (is_array($attributes))
282 {
283 foreach ($attributes as $key => $val)
284 {
Derek Jones4b9c6292011-07-01 17:40:48 -0500285 $x[] = ' '.$key.'="';
Andrey Andreevdebcc362012-01-07 02:05:29 +0200286 for ($i = 0, $l = strlen($val); $i < $l; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000287 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200288 $x[] = '|'.ord($val[$i]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000289 }
290 $x[] = '"';
291 }
292 }
293 else
294 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200295 for ($i = 0, $l = strlen($attributes); $i < $l; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200297 $x[] = $attributes[$i];
Derek Allard2067d1a2008-11-13 22:59:24 +0000298 }
299 }
300 }
301
302 $x[] = '>';
303
304 $temp = array();
Andrey Andreevdebcc362012-01-07 02:05:29 +0200305 for ($i = 0, $l = strlen($title); $i < $l; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000306 {
307 $ordinal = ord($title[$i]);
308
309 if ($ordinal < 128)
310 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200311 $x[] = '|'.$ordinal;
Derek Allard2067d1a2008-11-13 22:59:24 +0000312 }
313 else
314 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200315 if (count($temp) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 {
317 $count = ($ordinal < 224) ? 2 : 3;
318 }
Barry Mienydd671972010-10-04 16:33:58 +0200319
Derek Allard2067d1a2008-11-13 22:59:24 +0000320 $temp[] = $ordinal;
Andrey Andreevdebcc362012-01-07 02:05:29 +0200321 if (count($temp) === $count)
Derek Allard2067d1a2008-11-13 22:59:24 +0000322 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200323 $number = ($count === 3)
324 ? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64)
325 : (($temp[0] % 32) * 64) + ($temp[1] % 64);
326 $x[] = '|'.$number;
Derek Allard2067d1a2008-11-13 22:59:24 +0000327 $count = 1;
328 $temp = array();
329 }
330 }
331 }
332
333 $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>';
334
335 $x = array_reverse($x);
336 ob_start();
337
338 ?><script type="text/javascript">
339 //<![CDATA[
340 var l=new Array();
341 <?php
Andrey Andreevdebcc362012-01-07 02:05:29 +0200342 for ($i = 0, $c = count($x); $i < $c; $i++) { ?>l[<?php echo $i; ?>]='<?php echo $x[$i]; ?>';<?php } ?>
Derek Allard2067d1a2008-11-13 22:59:24 +0000343
344 for (var i = l.length-1; i >= 0; i=i-1){
Alex Bilbie773ccc32012-06-02 11:11:08 +0100345 if (l[i].substring(0, 1) === '|') document.write("&#"+unescape(l[i].substring(1))+";");
Derek Allard2067d1a2008-11-13 22:59:24 +0000346 else document.write(unescape(l[i]));}
347 //]]>
348 </script><?php
349
350 $buffer = ob_get_contents();
351 ob_end_clean();
352 return $buffer;
353 }
354}
355
356// ------------------------------------------------------------------------
357
Derek Allard2067d1a2008-11-13 22:59:24 +0000358if ( ! function_exists('auto_link'))
359{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400360 /**
361 * Auto-linker
362 *
363 * Automatically links URL and Email addresses.
364 * Note: There's a bit of extra code here to deal with
365 * URLs or emails that end in a period. We'll strip these
366 * off and add them after the link.
367 *
368 * @param string the string
369 * @param string the type: email, url, or both
370 * @param bool whether to create pop-up links
371 * @return string
372 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000373 function auto_link($str, $type = 'both', $popup = FALSE)
374 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200375 if ($type !== 'email' && preg_match_all('#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i', $str, $matches))
Derek Allard2067d1a2008-11-13 22:59:24 +0000376 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200377 $pop = ($popup) ? ' target="_blank" ' : '';
Barry Mienydd671972010-10-04 16:33:58 +0200378
Andrey Andreevdebcc362012-01-07 02:05:29 +0200379 for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
380 {
381 if (preg_match('|\.$|', $matches[6][$i]))
382 {
383 $period = '.';
384 $matches[6][$i] = substr($matches[6][$i], 0, -1);
385 }
386 else
Derek Allard2067d1a2008-11-13 22:59:24 +0000387 {
388 $period = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000389 }
Andrey Andreevdebcc362012-01-07 02:05:29 +0200390
391 $str = str_replace($matches[0][$i],
392 $matches[1][$i].'<a href="http'.$matches[4][$i].'://'
393 .$matches[5][$i].$matches[6][$i].'"'.$pop.'>http'
394 .$matches[4][$i].'://'.$matches[5][$i]
395 .$matches[6][$i].'</a>'.$period,
396 $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000397 }
398 }
399
Andrey Andreevdebcc362012-01-07 02:05:29 +0200400 if ($type !== 'url' && preg_match_all('/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i', $str, $matches))
Derek Allard2067d1a2008-11-13 22:59:24 +0000401 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200402 for ($i = 0, $c = count($matches); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000403 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200404 if (preg_match('|\.$|', $matches[3][$i]))
405 {
406 $period = '.';
407 $matches[3][$i] = substr($matches[3][$i], 0, -1);
408 }
409 else
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 {
411 $period = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 }
Andrey Andreevdebcc362012-01-07 02:05:29 +0200413
414 $str = str_replace($matches[0][$i], safe_mailto($matches[1][$i].'@'.$matches[2][$i].'.'.$matches[3][$i]).$period, $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 }
416 }
417
418 return $str;
419 }
420}
421
422// ------------------------------------------------------------------------
423
Derek Allard2067d1a2008-11-13 22:59:24 +0000424if ( ! function_exists('prep_url'))
425{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400426 /**
427 * Prep URL
428 *
429 * Simply adds the http:// part if no scheme is included
430 *
431 * @param string the URL
432 * @return string
433 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000434 function prep_url($str = '')
435 {
Alex Bilbie773ccc32012-06-02 11:11:08 +0100436 if ($str === 'http://' OR $str === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000437 {
438 return '';
439 }
440
Robin Sowelld2167a02010-09-14 15:05:42 -0400441 $url = parse_url($str);
Barry Mienydd671972010-10-04 16:33:58 +0200442
Robin Sowelld2167a02010-09-14 15:05:42 -0400443 if ( ! $url OR ! isset($url['scheme']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000444 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200445 return 'http://'.$str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 }
447
448 return $str;
449 }
450}
451
452// ------------------------------------------------------------------------
453
Derek Allard2067d1a2008-11-13 22:59:24 +0000454if ( ! function_exists('url_title'))
455{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400456 /**
457 * Create URL Title
458 *
459 * Takes a "title" string as input and creates a
460 * human-friendly URL string with a "separator" string
461 * as the word separator.
462 *
463 * @param string the string
464 * @param string the separator
465 * @param bool
466 * @return string
467 */
tubalmartin1a697102012-03-04 16:01:11 +0100468 function url_title($str, $separator = '-', $lowercase = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000469 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200470 if ($separator === 'dash')
Derek Allard2067d1a2008-11-13 22:59:24 +0000471 {
Andrey Andreev12220872012-03-26 21:38:56 +0300472 $separator = '-';
Derek Allard2067d1a2008-11-13 22:59:24 +0000473 }
Andrey Andreev12220872012-03-26 21:38:56 +0300474 elseif ($separator === 'underscore')
Derek Allard2067d1a2008-11-13 22:59:24 +0000475 {
Andrey Andreev12220872012-03-26 21:38:56 +0300476 $separator = '_';
Derek Allard2067d1a2008-11-13 22:59:24 +0000477 }
Andrey Andreev12220872012-03-26 21:38:56 +0300478
tubalmartin1a697102012-03-04 16:01:11 +0100479 $q_separator = preg_quote($separator);
Derek Allard2067d1a2008-11-13 22:59:24 +0000480
481 $trans = array(
Andrey Andreev12220872012-03-26 21:38:56 +0300482 '&.+?;' => '',
483 '[^a-z0-9 _-]' => '',
484 '\s+' => $separator,
485 '('.$q_separator.')+' => $separator
486 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000487
488 $str = strip_tags($str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 foreach ($trans as $key => $val)
490 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200491 $str = preg_replace('#'.$key.'#i', $val, $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 }
493
Derek Jones40a2fc82008-12-09 19:41:25 +0000494 if ($lowercase === TRUE)
495 {
496 $str = strtolower($str);
497 }
Barry Mienydd671972010-10-04 16:33:58 +0200498
Phil Sturgeona2bd3632012-03-04 15:32:58 +0000499 return trim(trim($str, $separator));
Derek Allard2067d1a2008-11-13 22:59:24 +0000500 }
501}
502
503// ------------------------------------------------------------------------
504
Derek Allard2067d1a2008-11-13 22:59:24 +0000505if ( ! function_exists('redirect'))
506{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400507 /**
508 * Header Redirect
509 *
510 * Header redirect in two flavors
511 * For very fine grained control over headers, you could use the Output
512 * Library's set_header() function.
513 *
514 * @param string the URL
515 * @param string the method: location or refresh
516 * @param int
517 * @return string
518 */
Brandon Jones50e5dbb2011-11-07 15:51:05 -0500519 function redirect($uri = '', $method = 'auto', $http_response_code = 302)
Derek Allard2067d1a2008-11-13 22:59:24 +0000520 {
Derek Jones534be032009-02-10 18:47:47 +0000521 if ( ! preg_match('#^https?://#i', $uri))
522 {
523 $uri = site_url($uri);
524 }
Barry Mienydd671972010-10-04 16:33:58 +0200525
Brandon Jones50e5dbb2011-11-07 15:51:05 -0500526 // IIS environment likely? Use 'refresh' for better compatibility
Andrey Andreevdebcc362012-01-07 02:05:29 +0200527 if (DIRECTORY_SEPARATOR !== '/' && $method === 'auto')
Brandon Jones50e5dbb2011-11-07 15:51:05 -0500528 {
529 $method = 'refresh';
530 }
531
Derek Allard2067d1a2008-11-13 22:59:24 +0000532 switch($method)
533 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200534 case 'refresh':
535 header('Refresh:0;url='.$uri);
Derek Allard2067d1a2008-11-13 22:59:24 +0000536 break;
Andrey Andreevdebcc362012-01-07 02:05:29 +0200537 default:
538 header('Location: '.$uri, TRUE, $http_response_code);
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 break;
540 }
541 exit;
542 }
543}
544
545// ------------------------------------------------------------------------
546
Derek Allard2067d1a2008-11-13 22:59:24 +0000547if ( ! function_exists('_parse_attributes'))
548{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400549 /**
550 * Parse out the attributes
551 *
552 * Some of the functions use this
553 *
554 * @param array
555 * @param bool
556 * @return string
557 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000558 function _parse_attributes($attributes, $javascript = FALSE)
559 {
560 if (is_string($attributes))
561 {
Alex Bilbie773ccc32012-06-02 11:11:08 +0100562 return ($attributes !== '') ? ' '.$attributes : '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000563 }
564
565 $att = '';
566 foreach ($attributes as $key => $val)
567 {
Alex Bilbie773ccc32012-06-02 11:11:08 +0100568 if ($javascript === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000569 {
Andrey Andreev12220872012-03-26 21:38:56 +0300570 $att .= $key.'='.$val.',';
Derek Allard2067d1a2008-11-13 22:59:24 +0000571 }
572 else
573 {
Andrey Andreev12220872012-03-26 21:38:56 +0300574 $att .= ' '.$key.'="'.$val.'"';
Derek Allard2067d1a2008-11-13 22:59:24 +0000575 }
576 }
577
Alex Bilbie773ccc32012-06-02 11:11:08 +0100578 if ($javascript === TRUE && $att !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000579 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200580 return substr($att, 0, -1);
Derek Allard2067d1a2008-11-13 22:59:24 +0000581 }
582
583 return $att;
584 }
585}
586
Derek Allard2067d1a2008-11-13 22:59:24 +0000587/* End of file url_helper.php */
Andrey Andreev12220872012-03-26 21:38:56 +0300588/* Location: ./system/helpers/url_helper.php */