blob: 744295f4ce8c21f5cf7058cfff3ac9f578f06e36 [file] [log] [blame]
Derek Jones0b59f272008-05-13 04:22:33 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard5811bf12007-02-20 01:26:08 +00002/**
Derek Allardd2df9bc2007-04-15 17:41:17 +00003 * CodeIgniter
Derek Allard5811bf12007-02-20 01:26:08 +00004 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Rick Ellisdd1e3232008-09-12 23:33:20 +00009 * @copyright Copyright (c) 2008, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allard5811bf12007-02-20 01:26:08 +000012 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
Derek Allardd2df9bc2007-04-15 17:41:17 +000019 * CodeIgniter URL Helpers
Derek Allard5811bf12007-02-20 01:26:08 +000020 *
21 * @package CodeIgniter
22 * @subpackage Helpers
23 * @category Helpers
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/helpers/url_helper.html
Derek Allard5811bf12007-02-20 01:26:08 +000026 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Site URL
32 *
33 * Create a local URL based on your basepath. Segments can be passed via the
34 * first parameter either as a string or an array.
35 *
36 * @access public
37 * @param string
38 * @return string
Derek Allard42597a12008-10-15 14:10:44 +000039 */
Derek Jones0b59f272008-05-13 04:22:33 +000040if ( ! function_exists('site_url'))
Derek Allard5811bf12007-02-20 01:26:08 +000041{
Derek Jones269b9422008-01-28 21:00:20 +000042 function site_url($uri = '')
43 {
44 $CI =& get_instance();
45 return $CI->config->site_url($uri);
46 }
Derek Allard5811bf12007-02-20 01:26:08 +000047}
Rick Ellis9e2c04c2008-08-19 22:12:26 +000048
Derek Allard5811bf12007-02-20 01:26:08 +000049// ------------------------------------------------------------------------
50
51/**
52 * Base URL
53 *
54 * Returns the "base_url" item from your config file
55 *
56 * @access public
57 * @return string
Derek Allard42597a12008-10-15 14:10:44 +000058 */
Derek Jones0b59f272008-05-13 04:22:33 +000059if ( ! function_exists('base_url'))
Derek Allard5811bf12007-02-20 01:26:08 +000060{
Derek Jones269b9422008-01-28 21:00:20 +000061 function base_url()
62 {
63 $CI =& get_instance();
64 return $CI->config->slash_item('base_url');
65 }
Derek Allard5811bf12007-02-20 01:26:08 +000066}
Rick Ellis9e2c04c2008-08-19 22:12:26 +000067
68// ------------------------------------------------------------------------
69
70/**
71 * Current URL
72 *
73 * Returns the full URL (including segments) of the page where this
74 * function is placed
75 *
76 * @access public
77 * @return string
Derek Allard42597a12008-10-15 14:10:44 +000078 */
Rick Ellis9e2c04c2008-08-19 22:12:26 +000079if ( ! function_exists('current_url'))
80{
81 function current_url()
82 {
83 $CI =& get_instance();
84 return $CI->config->site_url($CI->uri->uri_string());
85 }
86}
87
88// ------------------------------------------------------------------------
89/**
90 * URL String
91 *
Derek Allard42597a12008-10-15 14:10:44 +000092 * Returns the URI segments.
Rick Ellis9e2c04c2008-08-19 22:12:26 +000093 *
94 * @access public
95 * @return string
Derek Allard42597a12008-10-15 14:10:44 +000096 */
Rick Ellis9e2c04c2008-08-19 22:12:26 +000097if ( ! function_exists('uri_string'))
98{
99 function uri_string()
100 {
101 $CI =& get_instance();
102 return $CI->uri->uri_string();
103 }
104}
105
Derek Allard5811bf12007-02-20 01:26:08 +0000106// ------------------------------------------------------------------------
107
108/**
109 * Index page
110 *
111 * Returns the "index_page" from your config file
112 *
113 * @access public
114 * @return string
Derek Allard42597a12008-10-15 14:10:44 +0000115 */
Derek Jones0b59f272008-05-13 04:22:33 +0000116if ( ! function_exists('index_page'))
Derek Allard5811bf12007-02-20 01:26:08 +0000117{
Derek Jones269b9422008-01-28 21:00:20 +0000118 function index_page()
119 {
120 $CI =& get_instance();
121 return $CI->config->item('index_page');
122 }
Derek Allard5811bf12007-02-20 01:26:08 +0000123}
Derek Allard42597a12008-10-15 14:10:44 +0000124
Derek Allard5811bf12007-02-20 01:26:08 +0000125// ------------------------------------------------------------------------
126
127/**
128 * Anchor Link
129 *
130 * Creates an anchor based on the local URL.
131 *
132 * @access public
133 * @param string the URL
134 * @param string the link title
135 * @param mixed any attributes
136 * @return string
Derek Allard42597a12008-10-15 14:10:44 +0000137 */
Derek Jones0b59f272008-05-13 04:22:33 +0000138if ( ! function_exists('anchor'))
Derek Allard5811bf12007-02-20 01:26:08 +0000139{
Derek Jones269b9422008-01-28 21:00:20 +0000140 function anchor($uri = '', $title = '', $attributes = '')
141 {
142 $title = (string) $title;
Derek Allard42597a12008-10-15 14:10:44 +0000143
Derek Jones0b59f272008-05-13 04:22:33 +0000144 if ( ! is_array($uri))
Derek Jones269b9422008-01-28 21:00:20 +0000145 {
Derek Jones0b59f272008-05-13 04:22:33 +0000146 $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
Derek Jones269b9422008-01-28 21:00:20 +0000147 }
148 else
149 {
150 $site_url = site_url($uri);
151 }
Derek Allard42597a12008-10-15 14:10:44 +0000152
Derek Jones269b9422008-01-28 21:00:20 +0000153 if ($title == '')
154 {
155 $title = $site_url;
156 }
Derek Allard5811bf12007-02-20 01:26:08 +0000157
Derek Jonescd6f9cd2008-05-07 17:31:03 +0000158 if ($attributes != '')
Derek Jones269b9422008-01-28 21:00:20 +0000159 {
160 $attributes = _parse_attributes($attributes);
161 }
Derek Allard5811bf12007-02-20 01:26:08 +0000162
Derek Jones269b9422008-01-28 21:00:20 +0000163 return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
164 }
Derek Allard5811bf12007-02-20 01:26:08 +0000165}
Derek Allard42597a12008-10-15 14:10:44 +0000166
Derek Allard5811bf12007-02-20 01:26:08 +0000167// ------------------------------------------------------------------------
168
169/**
170 * Anchor Link - Pop-up version
171 *
172 * Creates an anchor based on the local URL. The link
173 * opens a new window based on the attributes specified.
174 *
175 * @access public
176 * @param string the URL
177 * @param string the link title
178 * @param mixed any attributes
179 * @return string
180 */
Derek Jones0b59f272008-05-13 04:22:33 +0000181if ( ! function_exists('anchor_popup'))
Derek Jones269b9422008-01-28 21:00:20 +0000182{
183 function anchor_popup($uri = '', $title = '', $attributes = FALSE)
Derek Allard42597a12008-10-15 14:10:44 +0000184 {
Derek Jones269b9422008-01-28 21:00:20 +0000185 $title = (string) $title;
Derek Allard42597a12008-10-15 14:10:44 +0000186
Derek Jones0b59f272008-05-13 04:22:33 +0000187 $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
Derek Allard42597a12008-10-15 14:10:44 +0000188
Derek Jones269b9422008-01-28 21:00:20 +0000189 if ($title == '')
190 {
191 $title = $site_url;
192 }
Derek Allard42597a12008-10-15 14:10:44 +0000193
Derek Jones269b9422008-01-28 21:00:20 +0000194 if ($attributes === FALSE)
195 {
196 return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title."</a>";
197 }
Derek Allard42597a12008-10-15 14:10:44 +0000198
Derek Jones0b59f272008-05-13 04:22:33 +0000199 if ( ! is_array($attributes))
Derek Jones269b9422008-01-28 21:00:20 +0000200 {
201 $attributes = array();
202 }
Derek Allard42597a12008-10-15 14:10:44 +0000203
Derek Jones269b9422008-01-28 21:00:20 +0000204 foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val)
205 {
Derek Jones0b59f272008-05-13 04:22:33 +0000206 $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key];
Derek Allard42597a12008-10-15 14:10:44 +0000207 unset($attributes[$key]);
Derek Jones269b9422008-01-28 21:00:20 +0000208 }
Derek Allard5811bf12007-02-20 01:26:08 +0000209
Derek Allard42597a12008-10-15 14:10:44 +0000210 if ($attributes != '')
211 {
212 $attributes = _parse_attributes($attributes);
213 }
214
215 return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\"$attributes>".$title."</a>";
Derek Jones269b9422008-01-28 21:00:20 +0000216 }
Derek Allard5811bf12007-02-20 01:26:08 +0000217}
Derek Allard42597a12008-10-15 14:10:44 +0000218
Derek Allard5811bf12007-02-20 01:26:08 +0000219// ------------------------------------------------------------------------
220
221/**
222 * Mailto Link
223 *
224 * @access public
225 * @param string the email address
226 * @param string the link title
227 * @param mixed any attributes
228 * @return string
229 */
Derek Jones0b59f272008-05-13 04:22:33 +0000230if ( ! function_exists('mailto'))
Derek Allard5811bf12007-02-20 01:26:08 +0000231{
Derek Jones269b9422008-01-28 21:00:20 +0000232 function mailto($email, $title = '', $attributes = '')
Derek Allard5811bf12007-02-20 01:26:08 +0000233 {
Derek Jones269b9422008-01-28 21:00:20 +0000234 $title = (string) $title;
Derek Allard42597a12008-10-15 14:10:44 +0000235
Derek Jones269b9422008-01-28 21:00:20 +0000236 if ($title == "")
237 {
238 $title = $email;
239 }
Derek Allard42597a12008-10-15 14:10:44 +0000240
Derek Jones269b9422008-01-28 21:00:20 +0000241 $attributes = _parse_attributes($attributes);
Derek Allard42597a12008-10-15 14:10:44 +0000242
Derek Jones269b9422008-01-28 21:00:20 +0000243 return '<a href="mailto:'.$email.'"'.$attributes.'>'.$title.'</a>';
Derek Allard5811bf12007-02-20 01:26:08 +0000244 }
Derek Allard5811bf12007-02-20 01:26:08 +0000245}
Derek Allard42597a12008-10-15 14:10:44 +0000246
Derek Allard5811bf12007-02-20 01:26:08 +0000247// ------------------------------------------------------------------------
248
249/**
250 * Encoded Mailto Link
251 *
252 * Create a spam-protected mailto link written in Javascript
253 *
254 * @access public
255 * @param string the email address
256 * @param string the link title
257 * @param mixed any attributes
258 * @return string
259 */
Derek Jones0b59f272008-05-13 04:22:33 +0000260if ( ! function_exists('safe_mailto'))
Derek Allard5811bf12007-02-20 01:26:08 +0000261{
Derek Jones269b9422008-01-28 21:00:20 +0000262 function safe_mailto($email, $title = '', $attributes = '')
Derek Allard5811bf12007-02-20 01:26:08 +0000263 {
Derek Jones269b9422008-01-28 21:00:20 +0000264 $title = (string) $title;
Derek Allard42597a12008-10-15 14:10:44 +0000265
Derek Jones269b9422008-01-28 21:00:20 +0000266 if ($title == "")
267 {
268 $title = $email;
269 }
Derek Allard42597a12008-10-15 14:10:44 +0000270
Derek Jones269b9422008-01-28 21:00:20 +0000271 for ($i = 0; $i < 16; $i++)
Derek Allard5811bf12007-02-20 01:26:08 +0000272 {
Derek Jones269b9422008-01-28 21:00:20 +0000273 $x[] = substr('<a href="mailto:', $i, 1);
274 }
Derek Allard42597a12008-10-15 14:10:44 +0000275
Derek Jones269b9422008-01-28 21:00:20 +0000276 for ($i = 0; $i < strlen($email); $i++)
277 {
278 $x[] = "|".ord(substr($email, $i, 1));
279 }
280
281 $x[] = '"';
282
283 if ($attributes != '')
284 {
285 if (is_array($attributes))
Derek Allard5811bf12007-02-20 01:26:08 +0000286 {
Derek Jones269b9422008-01-28 21:00:20 +0000287 foreach ($attributes as $key => $val)
Derek Allard5811bf12007-02-20 01:26:08 +0000288 {
Derek Jones269b9422008-01-28 21:00:20 +0000289 $x[] = ' '.$key.'="';
290 for ($i = 0; $i < strlen($val); $i++)
291 {
292 $x[] = "|".ord(substr($val, $i, 1));
293 }
294 $x[] = '"';
Derek Allard5811bf12007-02-20 01:26:08 +0000295 }
Derek Allard5811bf12007-02-20 01:26:08 +0000296 }
Derek Jones269b9422008-01-28 21:00:20 +0000297 else
Derek Allard42597a12008-10-15 14:10:44 +0000298 {
Derek Jones269b9422008-01-28 21:00:20 +0000299 for ($i = 0; $i < strlen($attributes); $i++)
300 {
301 $x[] = substr($attributes, $i, 1);
302 }
Derek Allard5811bf12007-02-20 01:26:08 +0000303 }
Derek Allard42597a12008-10-15 14:10:44 +0000304 }
305
Derek Jones269b9422008-01-28 21:00:20 +0000306 $x[] = '>';
Derek Allard42597a12008-10-15 14:10:44 +0000307
Derek Jones269b9422008-01-28 21:00:20 +0000308 $temp = array();
309 for ($i = 0; $i < strlen($title); $i++)
Derek Allard5811bf12007-02-20 01:26:08 +0000310 {
Derek Jones269b9422008-01-28 21:00:20 +0000311 $ordinal = ord($title[$i]);
Derek Allard42597a12008-10-15 14:10:44 +0000312
Derek Jones269b9422008-01-28 21:00:20 +0000313 if ($ordinal < 128)
Derek Allard5811bf12007-02-20 01:26:08 +0000314 {
Derek Jones269b9422008-01-28 21:00:20 +0000315 $x[] = "|".$ordinal;
Derek Allard5811bf12007-02-20 01:26:08 +0000316 }
Derek Jones269b9422008-01-28 21:00:20 +0000317 else
318 {
319 if (count($temp) == 0)
320 {
321 $count = ($ordinal < 224) ? 2 : 3;
322 }
Derek Allard42597a12008-10-15 14:10:44 +0000323
Derek Jones269b9422008-01-28 21:00:20 +0000324 $temp[] = $ordinal;
325 if (count($temp) == $count)
326 {
327 $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64);
328 $x[] = "|".$number;
329 $count = 1;
330 $temp = array();
331 }
Derek Allard5811bf12007-02-20 01:26:08 +0000332 }
333 }
Derek Allard42597a12008-10-15 14:10:44 +0000334
Derek Jones269b9422008-01-28 21:00:20 +0000335 $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>';
Derek Allard42597a12008-10-15 14:10:44 +0000336
Derek Jones269b9422008-01-28 21:00:20 +0000337 $x = array_reverse($x);
338 ob_start();
Derek Allard42597a12008-10-15 14:10:44 +0000339
Derek Jones269b9422008-01-28 21:00:20 +0000340 ?><script type="text/javascript">
341 //<![CDATA[
342 var l=new Array();
343 <?php
344 $i = 0;
345 foreach ($x as $val){ ?>l[<?php echo $i++; ?>]='<?php echo $val; ?>';<?php } ?>
346
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;
Derek Allard5811bf12007-02-20 01:26:08 +0000356 }
Derek Allard5811bf12007-02-20 01:26:08 +0000357}
Derek Allard42597a12008-10-15 14:10:44 +0000358
Derek Allard5811bf12007-02-20 01:26:08 +0000359// ------------------------------------------------------------------------
360
361/**
362 * Auto-linker
363 *
364 * Automatically links URL and Email addresses.
365 * Note: There's a bit of extra code here to deal with
366 * URLs or emails that end in a period. We'll strip these
367 * off and add them after the link.
368 *
369 * @access public
370 * @param string the string
371 * @param string the type: email, url, or both
372 * @param bool whether to create pop-up links
373 * @return string
374 */
Derek Jones0b59f272008-05-13 04:22:33 +0000375if ( ! function_exists('auto_link'))
Derek Allard5811bf12007-02-20 01:26:08 +0000376{
Derek Jones269b9422008-01-28 21:00:20 +0000377 function auto_link($str, $type = 'both', $popup = FALSE)
378 {
379 if ($type != 'email')
Derek Allard42597a12008-10-15 14:10:44 +0000380 {
Derek Jones269b9422008-01-28 21:00:20 +0000381 if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches))
Derek Allard5811bf12007-02-20 01:26:08 +0000382 {
Derek Jones269b9422008-01-28 21:00:20 +0000383 $pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
Derek Allard42597a12008-10-15 14:10:44 +0000384
Derek Jones269b9422008-01-28 21:00:20 +0000385 for ($i = 0; $i < sizeof($matches['0']); $i++)
Derek Allard5811bf12007-02-20 01:26:08 +0000386 {
Derek Jones269b9422008-01-28 21:00:20 +0000387 $period = '';
388 if (preg_match("|\.$|", $matches['6'][$i]))
389 {
390 $period = '.';
391 $matches['6'][$i] = substr($matches['6'][$i], 0, -1);
392 }
Derek Allard42597a12008-10-15 14:10:44 +0000393
Derek Jones269b9422008-01-28 21:00:20 +0000394 $str = str_replace($matches['0'][$i],
395 $matches['1'][$i].'<a href="http'.
396 $matches['4'][$i].'://'.
397 $matches['5'][$i].
398 $matches['6'][$i].'"'.$pop.'>http'.
399 $matches['4'][$i].'://'.
400 $matches['5'][$i].
401 $matches['6'][$i].'</a>'.
402 $period, $str);
403 }
Derek Allard5811bf12007-02-20 01:26:08 +0000404 }
405 }
Derek Allard5811bf12007-02-20 01:26:08 +0000406
Derek Jones269b9422008-01-28 21:00:20 +0000407 if ($type != 'url')
Derek Allard42597a12008-10-15 14:10:44 +0000408 {
Derek Allarddbc9e152008-10-06 14:41:47 +0000409 if (preg_match_all("/([a-zA-Z0-9_\.\-\+Ã…]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches))
Derek Allard5811bf12007-02-20 01:26:08 +0000410 {
Derek Jones269b9422008-01-28 21:00:20 +0000411 for ($i = 0; $i < sizeof($matches['0']); $i++)
Derek Allard5811bf12007-02-20 01:26:08 +0000412 {
Derek Jones269b9422008-01-28 21:00:20 +0000413 $period = '';
414 if (preg_match("|\.$|", $matches['3'][$i]))
415 {
416 $period = '.';
417 $matches['3'][$i] = substr($matches['3'][$i], 0, -1);
418 }
Derek Allard42597a12008-10-15 14:10:44 +0000419
Derek Jones269b9422008-01-28 21:00:20 +0000420 $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str);
421 }
Derek Jones269b9422008-01-28 21:00:20 +0000422 }
Derek Allard5811bf12007-02-20 01:26:08 +0000423 }
Derek Allard42597a12008-10-15 14:10:44 +0000424
Derek Jones269b9422008-01-28 21:00:20 +0000425 return $str;
Derek Allard5811bf12007-02-20 01:26:08 +0000426 }
Derek Allard5811bf12007-02-20 01:26:08 +0000427}
Derek Allard42597a12008-10-15 14:10:44 +0000428
Derek Allard5811bf12007-02-20 01:26:08 +0000429// ------------------------------------------------------------------------
430
431/**
432 * Prep URL
433 *
434 * Simply adds the http:// part if missing
435 *
436 * @access public
437 * @param string the URL
438 * @return string
439 */
Derek Jones0b59f272008-05-13 04:22:33 +0000440if ( ! function_exists('prep_url'))
Derek Allard5811bf12007-02-20 01:26:08 +0000441{
Derek Jones269b9422008-01-28 21:00:20 +0000442 function prep_url($str = '')
Derek Allard5811bf12007-02-20 01:26:08 +0000443 {
Derek Jones269b9422008-01-28 21:00:20 +0000444 if ($str == 'http://' OR $str == '')
445 {
446 return '';
447 }
Derek Allard42597a12008-10-15 14:10:44 +0000448
Derek Jones269b9422008-01-28 21:00:20 +0000449 if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://')
450 {
451 $str = 'http://'.$str;
452 }
Derek Allard42597a12008-10-15 14:10:44 +0000453
Derek Jones269b9422008-01-28 21:00:20 +0000454 return $str;
455 }
Derek Allard5811bf12007-02-20 01:26:08 +0000456}
Derek Allard42597a12008-10-15 14:10:44 +0000457
Derek Allard5811bf12007-02-20 01:26:08 +0000458// ------------------------------------------------------------------------
459
460/**
461 * Create URL Title
462 *
463 * Takes a "title" string as input and creates a
464 * human-friendly URL string with either a dash
465 * or an underscore as the word separator.
466 *
467 * @access public
468 * @param string the string
469 * @param string the separator: dash, or underscore
470 * @return string
471 */
Derek Jones0b59f272008-05-13 04:22:33 +0000472if ( ! function_exists('url_title'))
Derek Allard5811bf12007-02-20 01:26:08 +0000473{
Derek Jones269b9422008-01-28 21:00:20 +0000474 function url_title($str, $separator = 'dash')
Derek Allard5811bf12007-02-20 01:26:08 +0000475 {
Derek Jones269b9422008-01-28 21:00:20 +0000476 if ($separator == 'dash')
477 {
478 $search = '_';
479 $replace = '-';
480 }
481 else
482 {
483 $search = '-';
484 $replace = '_';
485 }
Derek Allard42597a12008-10-15 14:10:44 +0000486
Derek Jones269b9422008-01-28 21:00:20 +0000487 $trans = array(
Derek Jonesfd275702008-10-10 22:37:06 +0000488 '&\#\d+?;' => '',
489 '&\S+?;' => '',
490 '\s+' => $replace,
491 '[^a-z0-9\-\._]' => '',
492 $replace.'+' => $replace,
493 $replace.'$' => $replace,
494 '^'.$replace => $replace
495 );
Derek Allard5811bf12007-02-20 01:26:08 +0000496
Derek Jonesfd275702008-10-10 22:37:06 +0000497 $str = strip_tags($str);
Derek Allard42597a12008-10-15 14:10:44 +0000498
Derek Jones269b9422008-01-28 21:00:20 +0000499 foreach ($trans as $key => $val)
500 {
Derek Jonesfd275702008-10-10 22:37:06 +0000501 $str = preg_replace("#".$key."#i", $val, $str);
Derek Jones269b9422008-01-28 21:00:20 +0000502 }
Derek Allard42597a12008-10-15 14:10:44 +0000503
Derek Jones269b9422008-01-28 21:00:20 +0000504 return trim(stripslashes($str));
Derek Allard5811bf12007-02-20 01:26:08 +0000505 }
Derek Allard5811bf12007-02-20 01:26:08 +0000506}
Derek Allard42597a12008-10-15 14:10:44 +0000507
Derek Allard5811bf12007-02-20 01:26:08 +0000508// ------------------------------------------------------------------------
509
510/**
511 * Header Redirect
512 *
513 * Header redirect in two flavors
Derek Allard05f830c2008-04-27 13:35:20 +0000514 * For very fine grained control over headers, you could use the Output
515 * Library's set_header() function.
Derek Allard5811bf12007-02-20 01:26:08 +0000516 *
517 * @access public
518 * @param string the URL
519 * @param string the method: location or redirect
520 * @return string
521 */
Derek Jones0b59f272008-05-13 04:22:33 +0000522if ( ! function_exists('redirect'))
Derek Allard5811bf12007-02-20 01:26:08 +0000523{
Derek Allard05f830c2008-04-27 13:35:20 +0000524 function redirect($uri = '', $method = 'location', $http_response_code = 302)
Derek Allard5811bf12007-02-20 01:26:08 +0000525 {
Derek Jones269b9422008-01-28 21:00:20 +0000526 switch($method)
527 {
528 case 'refresh' : header("Refresh:0;url=".site_url($uri));
529 break;
Derek Allard05f830c2008-04-27 13:35:20 +0000530 default : header("Location: ".site_url($uri), TRUE, $http_response_code);
Derek Jones269b9422008-01-28 21:00:20 +0000531 break;
532 }
533 exit;
Derek Allard5811bf12007-02-20 01:26:08 +0000534 }
Derek Allard5811bf12007-02-20 01:26:08 +0000535}
Derek Allard42597a12008-10-15 14:10:44 +0000536
Derek Allard5811bf12007-02-20 01:26:08 +0000537// ------------------------------------------------------------------------
538
539/**
540 * Parse out the attributes
541 *
542 * Some of the functions use this
543 *
544 * @access private
545 * @param array
546 * @param bool
547 * @return string
548 */
Derek Jones0b59f272008-05-13 04:22:33 +0000549if ( ! function_exists('_parse_attributes'))
Derek Allard5811bf12007-02-20 01:26:08 +0000550{
Derek Jones269b9422008-01-28 21:00:20 +0000551 function _parse_attributes($attributes, $javascript = FALSE)
Derek Allard5811bf12007-02-20 01:26:08 +0000552 {
Derek Jones269b9422008-01-28 21:00:20 +0000553 if (is_string($attributes))
554 {
555 return ($attributes != '') ? ' '.$attributes : '';
556 }
Derek Allard5811bf12007-02-20 01:26:08 +0000557
Derek Jones269b9422008-01-28 21:00:20 +0000558 $att = '';
559 foreach ($attributes as $key => $val)
Derek Allard5811bf12007-02-20 01:26:08 +0000560 {
Derek Jones269b9422008-01-28 21:00:20 +0000561 if ($javascript == TRUE)
562 {
563 $att .= $key . '=' . $val . ',';
564 }
565 else
566 {
567 $att .= ' ' . $key . '="' . $val . '"';
568 }
Derek Allard5811bf12007-02-20 01:26:08 +0000569 }
Derek Allard42597a12008-10-15 14:10:44 +0000570
Derek Jones269b9422008-01-28 21:00:20 +0000571 if ($javascript == TRUE AND $att != '')
Derek Allard5811bf12007-02-20 01:26:08 +0000572 {
Derek Jones269b9422008-01-28 21:00:20 +0000573 $att = substr($att, 0, -1);
Derek Allard5811bf12007-02-20 01:26:08 +0000574 }
Derek Allard42597a12008-10-15 14:10:44 +0000575
Derek Jones269b9422008-01-28 21:00:20 +0000576 return $att;
Derek Allard5811bf12007-02-20 01:26:08 +0000577 }
Derek Allard5811bf12007-02-20 01:26:08 +0000578}
579
Derek Jones0b59f272008-05-13 04:22:33 +0000580
581/* End of file url_helper.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000582/* Location: ./system/helpers/url_helper.php */