Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 2 | /**
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 3 | * CodeIgniter
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 8 | * @author ExpressionEngine Dev Team
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 12 | * @since Version 1.0
|
| 13 | * @filesource
|
| 14 | */
|
| 15 |
|
| 16 | // ------------------------------------------------------------------------
|
| 17 |
|
| 18 | /**
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 19 | * CodeIgniter URL Helpers
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 20 | *
|
| 21 | * @package CodeIgniter
|
| 22 | * @subpackage Helpers
|
| 23 | * @category Helpers
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 24 | * @author ExpressionEngine Dev Team
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 25 | * @link http://codeigniter.com/user_guide/helpers/url_helper.html
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 26 | */
|
| 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
|
| 39 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 40 | if ( ! function_exists('site_url'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 41 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 42 | function site_url($uri = '')
|
| 43 | {
|
| 44 | $CI =& get_instance();
|
| 45 | return $CI->config->site_url($uri);
|
| 46 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 47 | }
|
Rick Ellis | 9e2c04c | 2008-08-19 22:12:26 +0000 | [diff] [blame] | 48 |
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 49 | // ------------------------------------------------------------------------
|
| 50 |
|
| 51 | /**
|
| 52 | * Base URL
|
| 53 | *
|
| 54 | * Returns the "base_url" item from your config file
|
| 55 | *
|
| 56 | * @access public
|
| 57 | * @return string
|
| 58 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 59 | if ( ! function_exists('base_url'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 60 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 61 | function base_url()
|
| 62 | {
|
| 63 | $CI =& get_instance();
|
| 64 | return $CI->config->slash_item('base_url');
|
| 65 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 66 | }
|
Rick Ellis | 9e2c04c | 2008-08-19 22:12:26 +0000 | [diff] [blame] | 67 |
|
| 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
|
| 78 | */
|
| 79 | if ( ! 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 | *
|
| 92 | * Returns the URI segments.
|
| 93 | *
|
| 94 | * @access public
|
| 95 | * @return string
|
| 96 | */
|
| 97 | if ( ! function_exists('uri_string'))
|
| 98 | {
|
| 99 | function uri_string()
|
| 100 | {
|
| 101 | $CI =& get_instance();
|
| 102 | return $CI->uri->uri_string();
|
| 103 | }
|
| 104 | }
|
| 105 |
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 106 | // ------------------------------------------------------------------------
|
| 107 |
|
| 108 | /**
|
| 109 | * Index page
|
| 110 | *
|
| 111 | * Returns the "index_page" from your config file
|
| 112 | *
|
| 113 | * @access public
|
| 114 | * @return string
|
| 115 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 116 | if ( ! function_exists('index_page'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 117 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 118 | function index_page()
|
| 119 | {
|
| 120 | $CI =& get_instance();
|
| 121 | return $CI->config->item('index_page');
|
| 122 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 123 | }
|
| 124 |
|
| 125 | // ------------------------------------------------------------------------
|
| 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
|
| 137 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 138 | if ( ! function_exists('anchor'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 139 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 140 | function anchor($uri = '', $title = '', $attributes = '')
|
| 141 | {
|
| 142 | $title = (string) $title;
|
Derek Jones | 1f2fd2d | 2007-07-11 21:59:12 +0000 | [diff] [blame] | 143 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 144 | if ( ! is_array($uri))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 145 | {
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 146 | $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 147 | }
|
| 148 | else
|
| 149 | {
|
| 150 | $site_url = site_url($uri);
|
| 151 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 152 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 153 | if ($title == '')
|
| 154 | {
|
| 155 | $title = $site_url;
|
| 156 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 157 |
|
Derek Jones | cd6f9cd | 2008-05-07 17:31:03 +0000 | [diff] [blame] | 158 | if ($attributes != '')
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 159 | {
|
| 160 | $attributes = _parse_attributes($attributes);
|
| 161 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 162 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 163 | return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
|
| 164 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 165 | }
|
| 166 |
|
| 167 | // ------------------------------------------------------------------------
|
| 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 Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 181 | if ( ! function_exists('anchor_popup'))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 182 | {
|
| 183 | function anchor_popup($uri = '', $title = '', $attributes = FALSE)
|
| 184 | {
|
| 185 | $title = (string) $title;
|
Derek Jones | 1f2fd2d | 2007-07-11 21:59:12 +0000 | [diff] [blame] | 186 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 187 | $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 188 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 189 | if ($title == '')
|
| 190 | {
|
| 191 | $title = $site_url;
|
| 192 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 193 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 194 | if ($attributes === FALSE)
|
| 195 | {
|
| 196 | return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title."</a>";
|
| 197 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 198 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 199 | if ( ! is_array($attributes))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 200 | {
|
| 201 | $attributes = array();
|
| 202 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 203 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 204 | foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val)
|
| 205 | {
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 206 | $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key];
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 207 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 208 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 209 | return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\">".$title."</a>";
|
| 210 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 211 | }
|
| 212 |
|
| 213 | // ------------------------------------------------------------------------
|
| 214 |
|
| 215 | /**
|
| 216 | * Mailto Link
|
| 217 | *
|
| 218 | * @access public
|
| 219 | * @param string the email address
|
| 220 | * @param string the link title
|
| 221 | * @param mixed any attributes
|
| 222 | * @return string
|
| 223 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 224 | if ( ! function_exists('mailto'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 225 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 226 | function mailto($email, $title = '', $attributes = '')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 227 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 228 | $title = (string) $title;
|
| 229 |
|
| 230 | if ($title == "")
|
| 231 | {
|
| 232 | $title = $email;
|
| 233 | }
|
| 234 |
|
| 235 | $attributes = _parse_attributes($attributes);
|
| 236 |
|
| 237 | return '<a href="mailto:'.$email.'"'.$attributes.'>'.$title.'</a>';
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 238 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 239 | }
|
| 240 |
|
| 241 | // ------------------------------------------------------------------------
|
| 242 |
|
| 243 | /**
|
| 244 | * Encoded Mailto Link
|
| 245 | *
|
| 246 | * Create a spam-protected mailto link written in Javascript
|
| 247 | *
|
| 248 | * @access public
|
| 249 | * @param string the email address
|
| 250 | * @param string the link title
|
| 251 | * @param mixed any attributes
|
| 252 | * @return string
|
| 253 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 254 | if ( ! function_exists('safe_mailto'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 255 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 256 | function safe_mailto($email, $title = '', $attributes = '')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 257 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 258 | $title = (string) $title;
|
| 259 |
|
| 260 | if ($title == "")
|
| 261 | {
|
| 262 | $title = $email;
|
| 263 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 264 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 265 | for ($i = 0; $i < 16; $i++)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 266 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 267 | $x[] = substr('<a href="mailto:', $i, 1);
|
| 268 | }
|
| 269 |
|
| 270 | for ($i = 0; $i < strlen($email); $i++)
|
| 271 | {
|
| 272 | $x[] = "|".ord(substr($email, $i, 1));
|
| 273 | }
|
| 274 |
|
| 275 | $x[] = '"';
|
| 276 |
|
| 277 | if ($attributes != '')
|
| 278 | {
|
| 279 | if (is_array($attributes))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 280 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 281 | foreach ($attributes as $key => $val)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 282 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 283 | $x[] = ' '.$key.'="';
|
| 284 | for ($i = 0; $i < strlen($val); $i++)
|
| 285 | {
|
| 286 | $x[] = "|".ord(substr($val, $i, 1));
|
| 287 | }
|
| 288 | $x[] = '"';
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 289 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 290 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 291 | else
|
| 292 | {
|
| 293 | for ($i = 0; $i < strlen($attributes); $i++)
|
| 294 | {
|
| 295 | $x[] = substr($attributes, $i, 1);
|
| 296 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 297 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 298 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 299 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 300 | $x[] = '>';
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 301 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 302 | $temp = array();
|
| 303 | for ($i = 0; $i < strlen($title); $i++)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 304 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 305 | $ordinal = ord($title[$i]);
|
| 306 |
|
| 307 | if ($ordinal < 128)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 308 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 309 | $x[] = "|".$ordinal;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 310 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 311 | else
|
| 312 | {
|
| 313 | if (count($temp) == 0)
|
| 314 | {
|
| 315 | $count = ($ordinal < 224) ? 2 : 3;
|
| 316 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 317 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 318 | $temp[] = $ordinal;
|
| 319 | if (count($temp) == $count)
|
| 320 | {
|
| 321 | $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64);
|
| 322 | $x[] = "|".$number;
|
| 323 | $count = 1;
|
| 324 | $temp = array();
|
| 325 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 326 | }
|
| 327 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 328 |
|
| 329 | $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>';
|
| 330 |
|
| 331 | $x = array_reverse($x);
|
| 332 | ob_start();
|
| 333 |
|
| 334 | ?><script type="text/javascript">
|
| 335 | //<![CDATA[
|
| 336 | var l=new Array();
|
| 337 | <?php
|
| 338 | $i = 0;
|
| 339 | foreach ($x as $val){ ?>l[<?php echo $i++; ?>]='<?php echo $val; ?>';<?php } ?>
|
| 340 |
|
| 341 | for (var i = l.length-1; i >= 0; i=i-1){
|
| 342 | if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";");
|
| 343 | else document.write(unescape(l[i]));}
|
| 344 | //]]>
|
| 345 | </script><?php
|
| 346 |
|
| 347 | $buffer = ob_get_contents();
|
| 348 | ob_end_clean();
|
| 349 | return $buffer;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 350 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 351 | }
|
| 352 |
|
| 353 | // ------------------------------------------------------------------------
|
| 354 |
|
| 355 | /**
|
| 356 | * Auto-linker
|
| 357 | *
|
| 358 | * Automatically links URL and Email addresses.
|
| 359 | * Note: There's a bit of extra code here to deal with
|
| 360 | * URLs or emails that end in a period. We'll strip these
|
| 361 | * off and add them after the link.
|
| 362 | *
|
| 363 | * @access public
|
| 364 | * @param string the string
|
| 365 | * @param string the type: email, url, or both
|
| 366 | * @param bool whether to create pop-up links
|
| 367 | * @return string
|
| 368 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 369 | if ( ! function_exists('auto_link'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 370 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 371 | function auto_link($str, $type = 'both', $popup = FALSE)
|
| 372 | {
|
| 373 | if ($type != 'email')
|
| 374 | {
|
| 375 | if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 376 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 377 | $pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
|
| 378 |
|
| 379 | for ($i = 0; $i < sizeof($matches['0']); $i++)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 380 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 381 | $period = '';
|
| 382 | if (preg_match("|\.$|", $matches['6'][$i]))
|
| 383 | {
|
| 384 | $period = '.';
|
| 385 | $matches['6'][$i] = substr($matches['6'][$i], 0, -1);
|
| 386 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 387 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 388 | $str = str_replace($matches['0'][$i],
|
| 389 | $matches['1'][$i].'<a href="http'.
|
| 390 | $matches['4'][$i].'://'.
|
| 391 | $matches['5'][$i].
|
| 392 | $matches['6'][$i].'"'.$pop.'>http'.
|
| 393 | $matches['4'][$i].'://'.
|
| 394 | $matches['5'][$i].
|
| 395 | $matches['6'][$i].'</a>'.
|
| 396 | $period, $str);
|
| 397 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 398 | }
|
| 399 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 400 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 401 | if ($type != 'url')
|
| 402 | {
|
| 403 | if (preg_match_all("/([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 404 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 405 | for ($i = 0; $i < sizeof($matches['0']); $i++)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 406 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 407 | $period = '';
|
| 408 | if (preg_match("|\.$|", $matches['3'][$i]))
|
| 409 | {
|
| 410 | $period = '.';
|
| 411 | $matches['3'][$i] = substr($matches['3'][$i], 0, -1);
|
| 412 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 413 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 414 | $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str);
|
| 415 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 416 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 417 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 418 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 419 | return $str;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 420 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 421 | }
|
| 422 |
|
| 423 | // ------------------------------------------------------------------------
|
| 424 |
|
| 425 | /**
|
| 426 | * Prep URL
|
| 427 | *
|
| 428 | * Simply adds the http:// part if missing
|
| 429 | *
|
| 430 | * @access public
|
| 431 | * @param string the URL
|
| 432 | * @return string
|
| 433 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 434 | if ( ! function_exists('prep_url'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 435 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 436 | function prep_url($str = '')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 437 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 438 | if ($str == 'http://' OR $str == '')
|
| 439 | {
|
| 440 | return '';
|
| 441 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 442 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 443 | if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://')
|
| 444 | {
|
| 445 | $str = 'http://'.$str;
|
| 446 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 447 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 448 | return $str;
|
| 449 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 450 | }
|
| 451 |
|
| 452 | // ------------------------------------------------------------------------
|
| 453 |
|
| 454 | /**
|
| 455 | * Create URL Title
|
| 456 | *
|
| 457 | * Takes a "title" string as input and creates a
|
| 458 | * human-friendly URL string with either a dash
|
| 459 | * or an underscore as the word separator.
|
| 460 | *
|
| 461 | * @access public
|
| 462 | * @param string the string
|
| 463 | * @param string the separator: dash, or underscore
|
| 464 | * @return string
|
| 465 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 466 | if ( ! function_exists('url_title'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 467 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 468 | function url_title($str, $separator = 'dash')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 469 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 470 | if ($separator == 'dash')
|
| 471 | {
|
| 472 | $search = '_';
|
| 473 | $replace = '-';
|
| 474 | }
|
| 475 | else
|
| 476 | {
|
| 477 | $search = '-';
|
| 478 | $replace = '_';
|
| 479 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 480 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 481 | $trans = array(
|
| 482 | $search => $replace,
|
| 483 | "\s+" => $replace,
|
| 484 | "[^a-z0-9".$replace."]" => '',
|
| 485 | $replace."+" => $replace,
|
| 486 | $replace."$" => '',
|
| 487 | "^".$replace => ''
|
| 488 | );
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 489 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 490 | $str = strip_tags(strtolower($str));
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 491 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 492 | foreach ($trans as $key => $val)
|
| 493 | {
|
| 494 | $str = preg_replace("#".$key."#", $val, $str);
|
| 495 | }
|
| 496 |
|
| 497 | return trim(stripslashes($str));
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 498 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 499 | }
|
| 500 |
|
| 501 | // ------------------------------------------------------------------------
|
| 502 |
|
| 503 | /**
|
| 504 | * Header Redirect
|
| 505 | *
|
| 506 | * Header redirect in two flavors
|
Derek Allard | 05f830c | 2008-04-27 13:35:20 +0000 | [diff] [blame] | 507 | * For very fine grained control over headers, you could use the Output
|
| 508 | * Library's set_header() function.
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 509 | *
|
| 510 | * @access public
|
| 511 | * @param string the URL
|
| 512 | * @param string the method: location or redirect
|
| 513 | * @return string
|
| 514 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 515 | if ( ! function_exists('redirect'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 516 | {
|
Derek Allard | 05f830c | 2008-04-27 13:35:20 +0000 | [diff] [blame] | 517 | function redirect($uri = '', $method = 'location', $http_response_code = 302)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 518 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 519 | switch($method)
|
| 520 | {
|
| 521 | case 'refresh' : header("Refresh:0;url=".site_url($uri));
|
| 522 | break;
|
Derek Allard | 05f830c | 2008-04-27 13:35:20 +0000 | [diff] [blame] | 523 | default : header("Location: ".site_url($uri), TRUE, $http_response_code);
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 524 | break;
|
| 525 | }
|
| 526 | exit;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 527 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 528 | }
|
| 529 |
|
| 530 | // ------------------------------------------------------------------------
|
| 531 |
|
| 532 | /**
|
| 533 | * Parse out the attributes
|
| 534 | *
|
| 535 | * Some of the functions use this
|
| 536 | *
|
| 537 | * @access private
|
| 538 | * @param array
|
| 539 | * @param bool
|
| 540 | * @return string
|
| 541 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 542 | if ( ! function_exists('_parse_attributes'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 543 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 544 | function _parse_attributes($attributes, $javascript = FALSE)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 545 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 546 | if (is_string($attributes))
|
| 547 | {
|
| 548 | return ($attributes != '') ? ' '.$attributes : '';
|
| 549 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 550 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 551 | $att = '';
|
| 552 | foreach ($attributes as $key => $val)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 553 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 554 | if ($javascript == TRUE)
|
| 555 | {
|
| 556 | $att .= $key . '=' . $val . ',';
|
| 557 | }
|
| 558 | else
|
| 559 | {
|
| 560 | $att .= ' ' . $key . '="' . $val . '"';
|
| 561 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 562 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 563 |
|
| 564 | if ($javascript == TRUE AND $att != '')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 565 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 566 | $att = substr($att, 0, -1);
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 567 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 568 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 569 | return $att;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 570 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 571 | }
|
| 572 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 573 |
|
| 574 | /* End of file url_helper.php */
|
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 575 | /* Location: ./system/helpers/url_helper.php */ |