blob: fa685645a278afc2245332636f3d279fa3e26f8f [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
161 if ($title == '')
162 {
163 $title = $site_url;
164 }
165
166 if ($attributes != '')
167 {
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
195 if ($title == '')
196 {
197 $title = $site_url;
198 }
199
200 if ($attributes === FALSE)
201 {
Andrey Andreev12220872012-03-26 21:38:56 +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 {
207 $attributes = array();
208 }
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
216 if ($attributes != '')
217 {
218 $attributes = _parse_attributes($attributes);
219 }
220
Andrey Andreev12220872012-03-26 21:38:56 +0300221 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 +0000222 }
223}
224
225// ------------------------------------------------------------------------
226
Derek Allard2067d1a2008-11-13 22:59:24 +0000227if ( ! function_exists('mailto'))
228{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400229 /**
230 * Mailto Link
231 *
232 * @param string the email address
233 * @param string the link title
234 * @param mixed any attributes
235 * @return string
236 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 function mailto($email, $title = '', $attributes = '')
238 {
239 $title = (string) $title;
240
Andrey Andreevdebcc362012-01-07 02:05:29 +0200241 if ($title == '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000242 {
243 $title = $email;
244 }
245
Andrey Andreevdebcc362012-01-07 02:05:29 +0200246 return '<a href="mailto:'.$email.'"'._parse_attributes($attributes).'>'.$title.'</a>';
Derek Allard2067d1a2008-11-13 22:59:24 +0000247 }
248}
249
250// ------------------------------------------------------------------------
251
Derek Allard2067d1a2008-11-13 22:59:24 +0000252if ( ! function_exists('safe_mailto'))
253{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400254 /**
255 * Encoded Mailto Link
256 *
257 * Create a spam-protected mailto link written in Javascript
258 *
259 * @param string the email address
260 * @param string the link title
261 * @param mixed any attributes
262 * @return string
263 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000264 function safe_mailto($email, $title = '', $attributes = '')
265 {
266 $title = (string) $title;
267
Andrey Andreevdebcc362012-01-07 02:05:29 +0200268 if ($title == '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000269 {
270 $title = $email;
271 }
272
Andrey Andreevdebcc362012-01-07 02:05:29 +0200273 $x = str_split('<a href="mailto:', 1);
Derek Allard2067d1a2008-11-13 22:59:24 +0000274
Andrey Andreevdebcc362012-01-07 02:05:29 +0200275 for ($i = 0, $l = strlen($email); $i < $l; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200277 $x[] = '|'.ord($email[$i]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000278 }
279
280 $x[] = '"';
281
282 if ($attributes != '')
283 {
284 if (is_array($attributes))
285 {
286 foreach ($attributes as $key => $val)
287 {
Derek Jones4b9c6292011-07-01 17:40:48 -0500288 $x[] = ' '.$key.'="';
Andrey Andreevdebcc362012-01-07 02:05:29 +0200289 for ($i = 0, $l = strlen($val); $i < $l; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000290 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200291 $x[] = '|'.ord($val[$i]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 }
293 $x[] = '"';
294 }
295 }
296 else
297 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200298 for ($i = 0, $l = strlen($attributes); $i < $l; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000299 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200300 $x[] = $attributes[$i];
Derek Allard2067d1a2008-11-13 22:59:24 +0000301 }
302 }
303 }
304
305 $x[] = '>';
306
307 $temp = array();
Andrey Andreevdebcc362012-01-07 02:05:29 +0200308 for ($i = 0, $l = strlen($title); $i < $l; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000309 {
310 $ordinal = ord($title[$i]);
311
312 if ($ordinal < 128)
313 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200314 $x[] = '|'.$ordinal;
Derek Allard2067d1a2008-11-13 22:59:24 +0000315 }
316 else
317 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200318 if (count($temp) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000319 {
320 $count = ($ordinal < 224) ? 2 : 3;
321 }
Barry Mienydd671972010-10-04 16:33:58 +0200322
Derek Allard2067d1a2008-11-13 22:59:24 +0000323 $temp[] = $ordinal;
Andrey Andreevdebcc362012-01-07 02:05:29 +0200324 if (count($temp) === $count)
Derek Allard2067d1a2008-11-13 22:59:24 +0000325 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200326 $number = ($count === 3)
327 ? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64)
328 : (($temp[0] % 32) * 64) + ($temp[1] % 64);
329 $x[] = '|'.$number;
Derek Allard2067d1a2008-11-13 22:59:24 +0000330 $count = 1;
331 $temp = array();
332 }
333 }
334 }
335
336 $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>';
337
338 $x = array_reverse($x);
339 ob_start();
340
341 ?><script type="text/javascript">
342 //<![CDATA[
343 var l=new Array();
344 <?php
Andrey Andreevdebcc362012-01-07 02:05:29 +0200345 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 +0000346
347 for (var i = l.length-1; i >= 0; i=i-1){
348 if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";");
349 else document.write(unescape(l[i]));}
350 //]]>
351 </script><?php
352
353 $buffer = ob_get_contents();
354 ob_end_clean();
355 return $buffer;
356 }
357}
358
359// ------------------------------------------------------------------------
360
Derek Allard2067d1a2008-11-13 22:59:24 +0000361if ( ! function_exists('auto_link'))
362{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400363 /**
364 * Auto-linker
365 *
366 * Automatically links URL and Email addresses.
367 * Note: There's a bit of extra code here to deal with
368 * URLs or emails that end in a period. We'll strip these
369 * off and add them after the link.
370 *
371 * @param string the string
372 * @param string the type: email, url, or both
373 * @param bool whether to create pop-up links
374 * @return string
375 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000376 function auto_link($str, $type = 'both', $popup = FALSE)
377 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200378 if ($type !== 'email' && preg_match_all('#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i', $str, $matches))
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200380 $pop = ($popup) ? ' target="_blank" ' : '';
Barry Mienydd671972010-10-04 16:33:58 +0200381
Andrey Andreevdebcc362012-01-07 02:05:29 +0200382 for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
383 {
384 if (preg_match('|\.$|', $matches[6][$i]))
385 {
386 $period = '.';
387 $matches[6][$i] = substr($matches[6][$i], 0, -1);
388 }
389 else
Derek Allard2067d1a2008-11-13 22:59:24 +0000390 {
391 $period = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 }
Andrey Andreevdebcc362012-01-07 02:05:29 +0200393
394 $str = str_replace($matches[0][$i],
395 $matches[1][$i].'<a href="http'.$matches[4][$i].'://'
396 .$matches[5][$i].$matches[6][$i].'"'.$pop.'>http'
397 .$matches[4][$i].'://'.$matches[5][$i]
398 .$matches[6][$i].'</a>'.$period,
399 $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000400 }
401 }
402
Andrey Andreevdebcc362012-01-07 02:05:29 +0200403 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 +0000404 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200405 for ($i = 0, $c = count($matches); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000406 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200407 if (preg_match('|\.$|', $matches[3][$i]))
408 {
409 $period = '.';
410 $matches[3][$i] = substr($matches[3][$i], 0, -1);
411 }
412 else
Derek Allard2067d1a2008-11-13 22:59:24 +0000413 {
414 $period = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 }
Andrey Andreevdebcc362012-01-07 02:05:29 +0200416
417 $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 +0000418 }
419 }
420
421 return $str;
422 }
423}
424
425// ------------------------------------------------------------------------
426
Derek Allard2067d1a2008-11-13 22:59:24 +0000427if ( ! function_exists('prep_url'))
428{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400429 /**
430 * Prep URL
431 *
432 * Simply adds the http:// part if no scheme is included
433 *
434 * @param string the URL
435 * @return string
436 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000437 function prep_url($str = '')
438 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200439 if ($str === 'http://' OR $str == '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 {
441 return '';
442 }
443
Robin Sowelld2167a02010-09-14 15:05:42 -0400444 $url = parse_url($str);
Barry Mienydd671972010-10-04 16:33:58 +0200445
Robin Sowelld2167a02010-09-14 15:05:42 -0400446 if ( ! $url OR ! isset($url['scheme']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200448 return 'http://'.$str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000449 }
450
451 return $str;
452 }
453}
454
455// ------------------------------------------------------------------------
456
Derek Allard2067d1a2008-11-13 22:59:24 +0000457if ( ! function_exists('url_title'))
458{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400459 /**
460 * Create URL Title
461 *
462 * Takes a "title" string as input and creates a
463 * human-friendly URL string with a "separator" string
464 * as the word separator.
465 *
466 * @param string the string
467 * @param string the separator
468 * @param bool
469 * @return string
470 */
tubalmartin1a697102012-03-04 16:01:11 +0100471 function url_title($str, $separator = '-', $lowercase = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000472 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200473 if ($separator === 'dash')
Derek Allard2067d1a2008-11-13 22:59:24 +0000474 {
Andrey Andreev12220872012-03-26 21:38:56 +0300475 $separator = '-';
Derek Allard2067d1a2008-11-13 22:59:24 +0000476 }
Andrey Andreev12220872012-03-26 21:38:56 +0300477 elseif ($separator === 'underscore')
Derek Allard2067d1a2008-11-13 22:59:24 +0000478 {
Andrey Andreev12220872012-03-26 21:38:56 +0300479 $separator = '_';
Derek Allard2067d1a2008-11-13 22:59:24 +0000480 }
Andrey Andreev12220872012-03-26 21:38:56 +0300481
tubalmartin1a697102012-03-04 16:01:11 +0100482 $q_separator = preg_quote($separator);
Derek Allard2067d1a2008-11-13 22:59:24 +0000483
484 $trans = array(
Andrey Andreev12220872012-03-26 21:38:56 +0300485 '&.+?;' => '',
486 '[^a-z0-9 _-]' => '',
487 '\s+' => $separator,
488 '('.$q_separator.')+' => $separator
489 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000490
491 $str = strip_tags($str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 foreach ($trans as $key => $val)
493 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200494 $str = preg_replace('#'.$key.'#i', $val, $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000495 }
496
Derek Jones40a2fc82008-12-09 19:41:25 +0000497 if ($lowercase === TRUE)
498 {
499 $str = strtolower($str);
500 }
Barry Mienydd671972010-10-04 16:33:58 +0200501
Phil Sturgeona2bd3632012-03-04 15:32:58 +0000502 return trim(trim($str, $separator));
Derek Allard2067d1a2008-11-13 22:59:24 +0000503 }
504}
505
506// ------------------------------------------------------------------------
507
Derek Allard2067d1a2008-11-13 22:59:24 +0000508if ( ! function_exists('redirect'))
509{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400510 /**
511 * Header Redirect
512 *
513 * Header redirect in two flavors
514 * For very fine grained control over headers, you could use the Output
515 * Library's set_header() function.
516 *
517 * @param string the URL
518 * @param string the method: location or refresh
519 * @param int
520 * @return string
521 */
Brandon Jones50e5dbb2011-11-07 15:51:05 -0500522 function redirect($uri = '', $method = 'auto', $http_response_code = 302)
Derek Allard2067d1a2008-11-13 22:59:24 +0000523 {
Derek Jones534be032009-02-10 18:47:47 +0000524 if ( ! preg_match('#^https?://#i', $uri))
525 {
526 $uri = site_url($uri);
527 }
Barry Mienydd671972010-10-04 16:33:58 +0200528
Brandon Jones50e5dbb2011-11-07 15:51:05 -0500529 // IIS environment likely? Use 'refresh' for better compatibility
Andrey Andreevdebcc362012-01-07 02:05:29 +0200530 if (DIRECTORY_SEPARATOR !== '/' && $method === 'auto')
Brandon Jones50e5dbb2011-11-07 15:51:05 -0500531 {
532 $method = 'refresh';
533 }
534
Derek Allard2067d1a2008-11-13 22:59:24 +0000535 switch($method)
536 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200537 case 'refresh':
538 header('Refresh:0;url='.$uri);
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 break;
Andrey Andreevdebcc362012-01-07 02:05:29 +0200540 default:
541 header('Location: '.$uri, TRUE, $http_response_code);
Derek Allard2067d1a2008-11-13 22:59:24 +0000542 break;
543 }
544 exit;
545 }
546}
547
548// ------------------------------------------------------------------------
549
Derek Allard2067d1a2008-11-13 22:59:24 +0000550if ( ! function_exists('_parse_attributes'))
551{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400552 /**
553 * Parse out the attributes
554 *
555 * Some of the functions use this
556 *
557 * @param array
558 * @param bool
559 * @return string
560 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000561 function _parse_attributes($attributes, $javascript = FALSE)
562 {
563 if (is_string($attributes))
564 {
565 return ($attributes != '') ? ' '.$attributes : '';
566 }
567
568 $att = '';
569 foreach ($attributes as $key => $val)
570 {
571 if ($javascript == TRUE)
572 {
Andrey Andreev12220872012-03-26 21:38:56 +0300573 $att .= $key.'='.$val.',';
Derek Allard2067d1a2008-11-13 22:59:24 +0000574 }
575 else
576 {
Andrey Andreev12220872012-03-26 21:38:56 +0300577 $att .= ' '.$key.'="'.$val.'"';
Derek Allard2067d1a2008-11-13 22:59:24 +0000578 }
579 }
580
Andrey Andreev12220872012-03-26 21:38:56 +0300581 if ($javascript == TRUE && $att != '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000582 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200583 return substr($att, 0, -1);
Derek Allard2067d1a2008-11-13 22:59:24 +0000584 }
585
586 return $att;
587 }
588}
589
Derek Allard2067d1a2008-11-13 22:59:24 +0000590/* End of file url_helper.php */
Andrey Andreev12220872012-03-26 21:38:56 +0300591/* Location: ./system/helpers/url_helper.php */