1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5
* An open source application development framework for PHP 5.1.6 or newer
8
* @author ExpressionEngine Dev Team
9
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10
* @license http://codeigniter.com/user_guide/license.html
11
* @link http://codeigniter.com
16
// ------------------------------------------------------------------------
19
* CodeIgniter URL Helpers
21
* @package CodeIgniter
24
* @author ExpressionEngine Dev Team
25
* @link http://codeigniter.com/user_guide/helpers/url_helper.html
28
// ------------------------------------------------------------------------
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.
40
if ( ! function_exists('site_url'))
42
function site_url($uri = '')
44
$CI =& get_instance();
45
return $CI->config->site_url($uri);
49
// ------------------------------------------------------------------------
54
* Create a local URL based on your basepath.
55
* Segments can be passed in as a string or an array, same as site_url
56
* or a URL to a file can be passed in, e.g. to an image file.
62
if ( ! function_exists('base_url'))
64
function base_url($uri = '')
66
$CI =& get_instance();
67
return $CI->config->base_url($uri);
71
// ------------------------------------------------------------------------
76
* Returns the full URL (including segments) of the page where this
82
if ( ! function_exists('current_url'))
84
function current_url()
86
$CI =& get_instance();
87
return $CI->config->site_url($CI->uri->uri_string());
91
// ------------------------------------------------------------------------
95
* Returns the URI segments.
100
if ( ! function_exists('uri_string'))
102
function uri_string()
104
$CI =& get_instance();
105
return $CI->uri->uri_string();
109
// ------------------------------------------------------------------------
114
* Returns the "index_page" from your config file
119
if ( ! function_exists('index_page'))
121
function index_page()
123
$CI =& get_instance();
124
return $CI->config->item('index_page');
128
// ------------------------------------------------------------------------
133
* Creates an anchor based on the local URL.
136
* @param string the URL
137
* @param string the link title
138
* @param mixed any attributes
141
if ( ! function_exists('anchor'))
143
function anchor($uri = '', $title = '', $attributes = '')
145
$title = (string) $title;
147
if ( ! is_array($uri))
149
$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
153
$site_url = site_url($uri);
161
if ($attributes != '')
163
$attributes = _parse_attributes($attributes);
166
return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
170
// ------------------------------------------------------------------------
173
* Anchor Link - Pop-up version
175
* Creates an anchor based on the local URL. The link
176
* opens a new window based on the attributes specified.
179
* @param string the URL
180
* @param string the link title
181
* @param mixed any attributes
184
if ( ! function_exists('anchor_popup'))
186
function anchor_popup($uri = '', $title = '', $attributes = FALSE)
188
$title = (string) $title;
190
$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
197
if ($attributes === FALSE)
199
return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title."</a>";
202
if ( ! is_array($attributes))
204
$attributes = array();
207
foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val)
209
$atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key];
210
unset($attributes[$key]);
213
if ($attributes != '')
215
$attributes = _parse_attributes($attributes);
218
return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\"$attributes>".$title."</a>";
222
// ------------------------------------------------------------------------
228
* @param string the email address
229
* @param string the link title
230
* @param mixed any attributes
233
if ( ! function_exists('mailto'))
235
function mailto($email, $title = '', $attributes = '')
237
$title = (string) $title;
244
$attributes = _parse_attributes($attributes);
246
return '<a href="mailto:'.$email.'"'.$attributes.'>'.$title.'</a>';
250
// ------------------------------------------------------------------------
253
* Encoded Mailto Link
255
* Create a spam-protected mailto link written in Javascript
258
* @param string the email address
259
* @param string the link title
260
* @param mixed any attributes
263
if ( ! function_exists('safe_mailto'))
265
function safe_mailto($email, $title = '', $attributes = '')
267
$title = (string) $title;
274
for ($i = 0; $i < 16; $i++)
276
$x[] = substr('<a href="mailto:', $i, 1);
279
for ($i = 0; $i < strlen($email); $i++)
281
$x[] = "|".ord(substr($email, $i, 1));
286
if ($attributes != '')
288
if (is_array($attributes))
290
foreach ($attributes as $key => $val)
292
$x[] = ' '.$key.'="';
293
for ($i = 0; $i < strlen($val); $i++)
295
$x[] = "|".ord(substr($val, $i, 1));
302
for ($i = 0; $i < strlen($attributes); $i++)
304
$x[] = substr($attributes, $i, 1);
312
for ($i = 0; $i < strlen($title); $i++)
314
$ordinal = ord($title[$i]);
322
if (count($temp) == 0)
324
$count = ($ordinal < 224) ? 2 : 3;
328
if (count($temp) == $count)
330
$number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64);
338
$x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>';
340
$x = array_reverse($x);
343
?><script type="text/javascript">
348
foreach ($x as $val){ ?>l[<?php echo $i++; ?>]='<?php echo $val; ?>';<?php } ?>
350
for (var i = l.length-1; i >= 0; i=i-1){
351
if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";");
352
else document.write(unescape(l[i]));}
356
$buffer = ob_get_contents();
362
// ------------------------------------------------------------------------
367
* Automatically links URL and Email addresses.
368
* Note: There's a bit of extra code here to deal with
369
* URLs or emails that end in a period. We'll strip these
370
* off and add them after the link.
373
* @param string the string
374
* @param string the type: email, url, or both
375
* @param bool whether to create pop-up links
378
if ( ! function_exists('auto_link'))
380
function auto_link($str, $type = 'both', $popup = FALSE)
382
if ($type != 'email')
384
if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches))
386
$pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
388
for ($i = 0; $i < count($matches['0']); $i++)
391
if (preg_match("|\.$|", $matches['6'][$i]))
394
$matches['6'][$i] = substr($matches['6'][$i], 0, -1);
397
$str = str_replace($matches['0'][$i],
398
$matches['1'][$i].'<a href="http'.
399
$matches['4'][$i].'://'.
401
$matches['6'][$i].'"'.$pop.'>http'.
402
$matches['4'][$i].'://'.
404
$matches['6'][$i].'</a>'.
412
if (preg_match_all("/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches))
414
for ($i = 0; $i < count($matches['0']); $i++)
417
if (preg_match("|\.$|", $matches['3'][$i]))
420
$matches['3'][$i] = substr($matches['3'][$i], 0, -1);
423
$str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str);
432
// ------------------------------------------------------------------------
437
* Simply adds the http:// part if no scheme is included
440
* @param string the URL
443
if ( ! function_exists('prep_url'))
445
function prep_url($str = '')
447
if ($str == 'http://' OR $str == '')
452
$url = parse_url($str);
454
if ( ! $url OR ! isset($url['scheme']))
456
$str = 'http://'.$str;
463
// ------------------------------------------------------------------------
468
* Takes a "title" string as input and creates a
469
* human-friendly URL string with a "separator" string
470
* as the word separator.
473
* @param string the string
474
* @param string the separator
477
if ( ! function_exists('url_title'))
479
function url_title($str, $separator = '-', $lowercase = FALSE)
481
if ($separator == 'dash')
485
else if ($separator == 'underscore')
490
$q_separator = preg_quote($separator);
494
'[^a-z0-9 _-]' => '',
496
'('.$q_separator.')+' => $separator
499
$str = strip_tags($str);
501
foreach ($trans as $key => $val)
503
$str = preg_replace("#".$key."#i", $val, $str);
506
if ($lowercase === TRUE)
508
$str = strtolower($str);
511
return trim($str, $separator);
515
// ------------------------------------------------------------------------
520
* Header redirect in two flavors
521
* For very fine grained control over headers, you could use the Output
522
* Library's set_header() function.
525
* @param string the URL
526
* @param string the method: location or redirect
529
if ( ! function_exists('redirect'))
531
function redirect($uri = '', $method = 'location', $http_response_code = 302)
533
if ( ! preg_match('#^https?://#i', $uri))
535
$uri = site_url($uri);
540
case 'refresh' : header("Refresh:0;url=".$uri);
542
default : header("Location: ".$uri, TRUE, $http_response_code);
549
// ------------------------------------------------------------------------
552
* Parse out the attributes
554
* Some of the functions use this
561
if ( ! function_exists('_parse_attributes'))
563
function _parse_attributes($attributes, $javascript = FALSE)
565
if (is_string($attributes))
567
return ($attributes != '') ? ' '.$attributes : '';
571
foreach ($attributes as $key => $val)
573
if ($javascript == TRUE)
575
$att .= $key . '=' . $val . ',';
579
$att .= ' ' . $key . '="' . $val . '"';
583
if ($javascript == TRUE AND $att != '')
585
$att = substr($att, 0, -1);
593
/* End of file url_helper.php */
594
/* Location: ./system/helpers/url_helper.php */
b'\\ No newline at end of file'