blob: 5576c2748d28299af26d1cd3fcc01353b51f78c0 [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
40/**
41 * Site URL
42 *
43 * Create a local URL based on your basepath. Segments can be passed via the
44 * first parameter either as a string or an array.
45 *
Derek Allard2067d1a2008-11-13 22:59:24 +000046 * @param string
47 * @return string
48 */
49if ( ! function_exists('site_url'))
50{
51 function site_url($uri = '')
52 {
53 $CI =& get_instance();
54 return $CI->config->site_url($uri);
55 }
56}
57
58// ------------------------------------------------------------------------
59
60/**
61 * Base URL
Andrey Andreevdebcc362012-01-07 02:05:29 +020062 *
anaxamaxan@blackdog.locald09c51a2011-02-02 23:00:16 -080063 * Create a local URL based on your basepath.
64 * Segments can be passed in as a string or an array, same as site_url
65 * or a URL to a file can be passed in, e.g. to an image file.
Derek Allard2067d1a2008-11-13 22:59:24 +000066 *
Andrey Andreev12220872012-03-26 21:38:56 +030067 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +000068 * @return string
69 */
70if ( ! function_exists('base_url'))
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
81/**
82 * Current URL
83 *
Barry Mienydd671972010-10-04 16:33:58 +020084 * Returns the full URL (including segments) of the page where this
Derek Allard2067d1a2008-11-13 22:59:24 +000085 * function is placed
86 *
Derek Allard2067d1a2008-11-13 22:59:24 +000087 * @return string
88 */
89if ( ! function_exists('current_url'))
90{
91 function current_url()
92 {
93 $CI =& get_instance();
94 return $CI->config->site_url($CI->uri->uri_string());
95 }
96}
97
98// ------------------------------------------------------------------------
99/**
100 * URL String
101 *
102 * Returns the URI segments.
103 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000104 * @return string
105 */
106if ( ! function_exists('uri_string'))
107{
108 function uri_string()
109 {
110 $CI =& get_instance();
111 return $CI->uri->uri_string();
112 }
113}
114
115// ------------------------------------------------------------------------
116
117/**
118 * Index page
119 *
120 * Returns the "index_page" from your config file
121 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000122 * @return string
123 */
124if ( ! function_exists('index_page'))
125{
126 function index_page()
127 {
128 $CI =& get_instance();
129 return $CI->config->item('index_page');
130 }
131}
132
133// ------------------------------------------------------------------------
134
135/**
136 * Anchor Link
137 *
138 * Creates an anchor based on the local URL.
139 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 * @param string the URL
141 * @param string the link title
142 * @param mixed any attributes
143 * @return string
144 */
145if ( ! function_exists('anchor'))
146{
147 function anchor($uri = '', $title = '', $attributes = '')
148 {
149 $title = (string) $title;
150
151 if ( ! is_array($uri))
152 {
Andrey Andreev12220872012-03-26 21:38:56 +0300153 $site_url = preg_match('!^\w+://! i', $uri) ? $uri : site_url($uri);
Derek Allard2067d1a2008-11-13 22:59:24 +0000154 }
155 else
156 {
157 $site_url = site_url($uri);
158 }
159
160 if ($title == '')
161 {
162 $title = $site_url;
163 }
164
165 if ($attributes != '')
166 {
167 $attributes = _parse_attributes($attributes);
168 }
169
170 return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
171 }
172}
173
174// ------------------------------------------------------------------------
175
176/**
177 * Anchor Link - Pop-up version
178 *
179 * Creates an anchor based on the local URL. The link
180 * opens a new window based on the attributes specified.
181 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000182 * @param string the URL
183 * @param string the link title
184 * @param mixed any attributes
185 * @return string
186 */
187if ( ! function_exists('anchor_popup'))
188{
189 function anchor_popup($uri = '', $title = '', $attributes = FALSE)
190 {
191 $title = (string) $title;
Andrey Andreev12220872012-03-26 21:38:56 +0300192 $site_url = preg_match('!^\w+://! i', $uri) ? $uri : site_url($uri);
Derek Allard2067d1a2008-11-13 22:59:24 +0000193
194 if ($title == '')
195 {
196 $title = $site_url;
197 }
198
199 if ($attributes === FALSE)
200 {
Andrey Andreev12220872012-03-26 21:38:56 +0300201 return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title.'</a>';
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 }
203
204 if ( ! is_array($attributes))
205 {
206 $attributes = array();
207 }
208
209 foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val)
210 {
Andrey Andreev12220872012-03-26 21:38:56 +0300211 $atts[$key] = isset($attributes[$key]) ? $attributes[$key] : $val;
Derek Allard2067d1a2008-11-13 22:59:24 +0000212 unset($attributes[$key]);
213 }
214
215 if ($attributes != '')
216 {
217 $attributes = _parse_attributes($attributes);
218 }
219
Andrey Andreev12220872012-03-26 21:38:56 +0300220 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 +0000221 }
222}
223
224// ------------------------------------------------------------------------
225
226/**
227 * Mailto Link
228 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000229 * @param string the email address
230 * @param string the link title
Barry Mienydd671972010-10-04 16:33:58 +0200231 * @param mixed any attributes
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 * @return string
233 */
234if ( ! function_exists('mailto'))
235{
236 function mailto($email, $title = '', $attributes = '')
237 {
238 $title = (string) $title;
239
Andrey Andreevdebcc362012-01-07 02:05:29 +0200240 if ($title == '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 {
242 $title = $email;
243 }
244
Andrey Andreevdebcc362012-01-07 02:05:29 +0200245 return '<a href="mailto:'.$email.'"'._parse_attributes($attributes).'>'.$title.'</a>';
Derek Allard2067d1a2008-11-13 22:59:24 +0000246 }
247}
248
249// ------------------------------------------------------------------------
250
251/**
252 * Encoded Mailto Link
253 *
254 * Create a spam-protected mailto link written in Javascript
255 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000256 * @param string the email address
257 * @param string the link title
Barry Mienydd671972010-10-04 16:33:58 +0200258 * @param mixed any attributes
Derek Allard2067d1a2008-11-13 22:59:24 +0000259 * @return string
260 */
261if ( ! function_exists('safe_mailto'))
262{
263 function safe_mailto($email, $title = '', $attributes = '')
264 {
265 $title = (string) $title;
266
Andrey Andreevdebcc362012-01-07 02:05:29 +0200267 if ($title == '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000268 {
269 $title = $email;
270 }
271
Andrey Andreevdebcc362012-01-07 02:05:29 +0200272 $x = str_split('<a href="mailto:', 1);
Derek Allard2067d1a2008-11-13 22:59:24 +0000273
Andrey Andreevdebcc362012-01-07 02:05:29 +0200274 for ($i = 0, $l = strlen($email); $i < $l; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000275 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200276 $x[] = '|'.ord($email[$i]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000277 }
278
279 $x[] = '"';
280
281 if ($attributes != '')
282 {
283 if (is_array($attributes))
284 {
285 foreach ($attributes as $key => $val)
286 {
Derek Jones4b9c6292011-07-01 17:40:48 -0500287 $x[] = ' '.$key.'="';
Andrey Andreevdebcc362012-01-07 02:05:29 +0200288 for ($i = 0, $l = strlen($val); $i < $l; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000289 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200290 $x[] = '|'.ord($val[$i]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000291 }
292 $x[] = '"';
293 }
294 }
295 else
296 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200297 for ($i = 0, $l = strlen($attributes); $i < $l; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000298 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200299 $x[] = $attributes[$i];
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 }
301 }
302 }
303
304 $x[] = '>';
305
306 $temp = array();
Andrey Andreevdebcc362012-01-07 02:05:29 +0200307 for ($i = 0, $l = strlen($title); $i < $l; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000308 {
309 $ordinal = ord($title[$i]);
310
311 if ($ordinal < 128)
312 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200313 $x[] = '|'.$ordinal;
Derek Allard2067d1a2008-11-13 22:59:24 +0000314 }
315 else
316 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200317 if (count($temp) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000318 {
319 $count = ($ordinal < 224) ? 2 : 3;
320 }
Barry Mienydd671972010-10-04 16:33:58 +0200321
Derek Allard2067d1a2008-11-13 22:59:24 +0000322 $temp[] = $ordinal;
Andrey Andreevdebcc362012-01-07 02:05:29 +0200323 if (count($temp) === $count)
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200325 $number = ($count === 3)
326 ? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64)
327 : (($temp[0] % 32) * 64) + ($temp[1] % 64);
328 $x[] = '|'.$number;
Derek Allard2067d1a2008-11-13 22:59:24 +0000329 $count = 1;
330 $temp = array();
331 }
332 }
333 }
334
335 $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>';
336
337 $x = array_reverse($x);
338 ob_start();
339
340 ?><script type="text/javascript">
341 //<![CDATA[
342 var l=new Array();
343 <?php
Andrey Andreevdebcc362012-01-07 02:05:29 +0200344 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 +0000345
346 for (var i = l.length-1; i >= 0; i=i-1){
347 if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";");
348 else document.write(unescape(l[i]));}
349 //]]>
350 </script><?php
351
352 $buffer = ob_get_contents();
353 ob_end_clean();
354 return $buffer;
355 }
356}
357
358// ------------------------------------------------------------------------
359
360/**
361 * Auto-linker
362 *
363 * Automatically links URL and Email addresses.
364 * Note: There's a bit of extra code here to deal with
Andrey Andreev12220872012-03-26 21:38:56 +0300365 * URLs or emails that end in a period. We'll strip these
Derek Allard2067d1a2008-11-13 22:59:24 +0000366 * off and add them after the link.
367 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 * @param string the string
369 * @param string the type: email, url, or both
Barry Mienydd671972010-10-04 16:33:58 +0200370 * @param bool whether to create pop-up links
Derek Allard2067d1a2008-11-13 22:59:24 +0000371 * @return string
372 */
373if ( ! function_exists('auto_link'))
374{
375 function auto_link($str, $type = 'both', $popup = FALSE)
376 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200377 if ($type !== 'email' && preg_match_all('#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i', $str, $matches))
Derek Allard2067d1a2008-11-13 22:59:24 +0000378 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200379 $pop = ($popup) ? ' target="_blank" ' : '';
Barry Mienydd671972010-10-04 16:33:58 +0200380
Andrey Andreevdebcc362012-01-07 02:05:29 +0200381 for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
382 {
383 if (preg_match('|\.$|', $matches[6][$i]))
384 {
385 $period = '.';
386 $matches[6][$i] = substr($matches[6][$i], 0, -1);
387 }
388 else
Derek Allard2067d1a2008-11-13 22:59:24 +0000389 {
390 $period = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000391 }
Andrey Andreevdebcc362012-01-07 02:05:29 +0200392
393 $str = str_replace($matches[0][$i],
394 $matches[1][$i].'<a href="http'.$matches[4][$i].'://'
395 .$matches[5][$i].$matches[6][$i].'"'.$pop.'>http'
396 .$matches[4][$i].'://'.$matches[5][$i]
397 .$matches[6][$i].'</a>'.$period,
398 $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000399 }
400 }
401
Andrey Andreevdebcc362012-01-07 02:05:29 +0200402 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 +0000403 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200404 for ($i = 0, $c = count($matches); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000405 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200406 if (preg_match('|\.$|', $matches[3][$i]))
407 {
408 $period = '.';
409 $matches[3][$i] = substr($matches[3][$i], 0, -1);
410 }
411 else
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 {
413 $period = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000414 }
Andrey Andreevdebcc362012-01-07 02:05:29 +0200415
416 $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 +0000417 }
418 }
419
420 return $str;
421 }
422}
423
424// ------------------------------------------------------------------------
425
426/**
427 * Prep URL
428 *
Derek Jonesd2658712010-03-22 11:05:01 -0500429 * Simply adds the http:// part if no scheme is included
Derek Allard2067d1a2008-11-13 22:59:24 +0000430 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000431 * @param string the URL
432 * @return string
433 */
434if ( ! function_exists('prep_url'))
435{
436 function prep_url($str = '')
437 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200438 if ($str === 'http://' OR $str == '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000439 {
440 return '';
441 }
442
Robin Sowelld2167a02010-09-14 15:05:42 -0400443 $url = parse_url($str);
Barry Mienydd671972010-10-04 16:33:58 +0200444
Robin Sowelld2167a02010-09-14 15:05:42 -0400445 if ( ! $url OR ! isset($url['scheme']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200447 return 'http://'.$str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000448 }
449
450 return $str;
451 }
452}
453
454// ------------------------------------------------------------------------
455
456/**
457 * Create URL Title
458 *
459 * Takes a "title" string as input and creates a
Andrey Andreev12220872012-03-26 21:38:56 +0300460 * human-friendly URL string with a "separator" string
tubalmartin1a697102012-03-04 16:01:11 +0100461 * as the word separator.
Derek Allard2067d1a2008-11-13 22:59:24 +0000462 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000463 * @param string the string
tubalmartin1a697102012-03-04 16:01:11 +0100464 * @param string the separator
Andrey Andreev12220872012-03-26 21:38:56 +0300465 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000466 * @return string
467 */
468if ( ! function_exists('url_title'))
469{
tubalmartin1a697102012-03-04 16:01:11 +0100470 function url_title($str, $separator = '-', $lowercase = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000471 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200472 if ($separator === 'dash')
Derek Allard2067d1a2008-11-13 22:59:24 +0000473 {
Andrey Andreev12220872012-03-26 21:38:56 +0300474 $separator = '-';
Derek Allard2067d1a2008-11-13 22:59:24 +0000475 }
Andrey Andreev12220872012-03-26 21:38:56 +0300476 elseif ($separator === 'underscore')
Derek Allard2067d1a2008-11-13 22:59:24 +0000477 {
Andrey Andreev12220872012-03-26 21:38:56 +0300478 $separator = '_';
Derek Allard2067d1a2008-11-13 22:59:24 +0000479 }
Andrey Andreev12220872012-03-26 21:38:56 +0300480
tubalmartin1a697102012-03-04 16:01:11 +0100481 $q_separator = preg_quote($separator);
Derek Allard2067d1a2008-11-13 22:59:24 +0000482
483 $trans = array(
Andrey Andreev12220872012-03-26 21:38:56 +0300484 '&.+?;' => '',
485 '[^a-z0-9 _-]' => '',
486 '\s+' => $separator,
487 '('.$q_separator.')+' => $separator
488 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000489
490 $str = strip_tags($str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000491 foreach ($trans as $key => $val)
492 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200493 $str = preg_replace('#'.$key.'#i', $val, $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000494 }
495
Derek Jones40a2fc82008-12-09 19:41:25 +0000496 if ($lowercase === TRUE)
497 {
498 $str = strtolower($str);
499 }
Barry Mienydd671972010-10-04 16:33:58 +0200500
Phil Sturgeona2bd3632012-03-04 15:32:58 +0000501 return trim(trim($str, $separator));
Derek Allard2067d1a2008-11-13 22:59:24 +0000502 }
503}
504
505// ------------------------------------------------------------------------
506
507/**
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 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000514 * @param string the URL
Eric Barnesf3189502011-08-23 21:40:59 -0400515 * @param string the method: location or refresh
Derek Allard2067d1a2008-11-13 22:59:24 +0000516 * @return string
517 */
518if ( ! function_exists('redirect'))
519{
Brandon Jones50e5dbb2011-11-07 15:51:05 -0500520 function redirect($uri = '', $method = 'auto', $http_response_code = 302)
Derek Allard2067d1a2008-11-13 22:59:24 +0000521 {
Derek Jones534be032009-02-10 18:47:47 +0000522 if ( ! preg_match('#^https?://#i', $uri))
523 {
524 $uri = site_url($uri);
525 }
Barry Mienydd671972010-10-04 16:33:58 +0200526
Brandon Jones50e5dbb2011-11-07 15:51:05 -0500527 // IIS environment likely? Use 'refresh' for better compatibility
Andrey Andreevdebcc362012-01-07 02:05:29 +0200528 if (DIRECTORY_SEPARATOR !== '/' && $method === 'auto')
Brandon Jones50e5dbb2011-11-07 15:51:05 -0500529 {
530 $method = 'refresh';
531 }
532
Derek Allard2067d1a2008-11-13 22:59:24 +0000533 switch($method)
534 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200535 case 'refresh':
536 header('Refresh:0;url='.$uri);
Derek Allard2067d1a2008-11-13 22:59:24 +0000537 break;
Andrey Andreevdebcc362012-01-07 02:05:29 +0200538 default:
539 header('Location: '.$uri, TRUE, $http_response_code);
Derek Allard2067d1a2008-11-13 22:59:24 +0000540 break;
541 }
542 exit;
543 }
544}
545
546// ------------------------------------------------------------------------
547
548/**
549 * Parse out the attributes
550 *
551 * Some of the functions use this
552 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 * @param array
554 * @param bool
555 * @return string
556 */
557if ( ! function_exists('_parse_attributes'))
558{
559 function _parse_attributes($attributes, $javascript = FALSE)
560 {
561 if (is_string($attributes))
562 {
563 return ($attributes != '') ? ' '.$attributes : '';
564 }
565
566 $att = '';
567 foreach ($attributes as $key => $val)
568 {
569 if ($javascript == TRUE)
570 {
Andrey Andreev12220872012-03-26 21:38:56 +0300571 $att .= $key.'='.$val.',';
Derek Allard2067d1a2008-11-13 22:59:24 +0000572 }
573 else
574 {
Andrey Andreev12220872012-03-26 21:38:56 +0300575 $att .= ' '.$key.'="'.$val.'"';
Derek Allard2067d1a2008-11-13 22:59:24 +0000576 }
577 }
578
Andrey Andreev12220872012-03-26 21:38:56 +0300579 if ($javascript == TRUE && $att != '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000580 {
Andrey Andreevdebcc362012-01-07 02:05:29 +0200581 return substr($att, 0, -1);
Derek Allard2067d1a2008-11-13 22:59:24 +0000582 }
583
584 return $att;
585 }
586}
587
Derek Allard2067d1a2008-11-13 22:59:24 +0000588/* End of file url_helper.php */
Andrey Andreev12220872012-03-26 21:38:56 +0300589/* Location: ./system/helpers/url_helper.php */