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 | }
|
| 48 |
|
| 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 | }
|
| 67 |
|
| 68 | // ------------------------------------------------------------------------
|
| 69 |
|
| 70 | /**
|
| 71 | * Index page
|
| 72 | *
|
| 73 | * Returns the "index_page" from your config file
|
| 74 | *
|
| 75 | * @access public
|
| 76 | * @return string
|
| 77 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 78 | if ( ! function_exists('index_page'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 79 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 80 | function index_page()
|
| 81 | {
|
| 82 | $CI =& get_instance();
|
| 83 | return $CI->config->item('index_page');
|
| 84 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 85 | }
|
| 86 |
|
| 87 | // ------------------------------------------------------------------------
|
| 88 |
|
| 89 | /**
|
| 90 | * Anchor Link
|
| 91 | *
|
| 92 | * Creates an anchor based on the local URL.
|
| 93 | *
|
| 94 | * @access public
|
| 95 | * @param string the URL
|
| 96 | * @param string the link title
|
| 97 | * @param mixed any attributes
|
| 98 | * @return string
|
| 99 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 100 | if ( ! function_exists('anchor'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 101 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 102 | function anchor($uri = '', $title = '', $attributes = '')
|
| 103 | {
|
| 104 | $title = (string) $title;
|
Derek Jones | 1f2fd2d | 2007-07-11 21:59:12 +0000 | [diff] [blame] | 105 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 106 | if ( ! is_array($uri))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 107 | {
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 108 | $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 109 | }
|
| 110 | else
|
| 111 | {
|
| 112 | $site_url = site_url($uri);
|
| 113 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 114 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 115 | if ($title == '')
|
| 116 | {
|
| 117 | $title = $site_url;
|
| 118 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 119 |
|
Derek Jones | cd6f9cd | 2008-05-07 17:31:03 +0000 | [diff] [blame] | 120 | if ($attributes != '')
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 121 | {
|
| 122 | $attributes = _parse_attributes($attributes);
|
| 123 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 124 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 125 | return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
|
| 126 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 127 | }
|
| 128 |
|
| 129 | // ------------------------------------------------------------------------
|
| 130 |
|
| 131 | /**
|
| 132 | * Anchor Link - Pop-up version
|
| 133 | *
|
| 134 | * Creates an anchor based on the local URL. The link
|
| 135 | * opens a new window based on the attributes specified.
|
| 136 | *
|
| 137 | * @access public
|
| 138 | * @param string the URL
|
| 139 | * @param string the link title
|
| 140 | * @param mixed any attributes
|
| 141 | * @return string
|
| 142 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 143 | if ( ! function_exists('anchor_popup'))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 144 | {
|
| 145 | function anchor_popup($uri = '', $title = '', $attributes = FALSE)
|
| 146 | {
|
| 147 | $title = (string) $title;
|
Derek Jones | 1f2fd2d | 2007-07-11 21:59:12 +0000 | [diff] [blame] | 148 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 149 | $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 150 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 151 | if ($title == '')
|
| 152 | {
|
| 153 | $title = $site_url;
|
| 154 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 155 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 156 | if ($attributes === FALSE)
|
| 157 | {
|
| 158 | return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title."</a>";
|
| 159 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 160 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 161 | if ( ! is_array($attributes))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 162 | {
|
| 163 | $attributes = array();
|
| 164 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 165 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 166 | foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val)
|
| 167 | {
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 168 | $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key];
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 169 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 170 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 171 | return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\">".$title."</a>";
|
| 172 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 173 | }
|
| 174 |
|
| 175 | // ------------------------------------------------------------------------
|
| 176 |
|
| 177 | /**
|
| 178 | * Mailto Link
|
| 179 | *
|
| 180 | * @access public
|
| 181 | * @param string the email address
|
| 182 | * @param string the link title
|
| 183 | * @param mixed any attributes
|
| 184 | * @return string
|
| 185 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 186 | if ( ! function_exists('mailto'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 187 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 188 | function mailto($email, $title = '', $attributes = '')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 189 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 190 | $title = (string) $title;
|
| 191 |
|
| 192 | if ($title == "")
|
| 193 | {
|
| 194 | $title = $email;
|
| 195 | }
|
| 196 |
|
| 197 | $attributes = _parse_attributes($attributes);
|
| 198 |
|
| 199 | return '<a href="mailto:'.$email.'"'.$attributes.'>'.$title.'</a>';
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 200 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 201 | }
|
| 202 |
|
| 203 | // ------------------------------------------------------------------------
|
| 204 |
|
| 205 | /**
|
| 206 | * Encoded Mailto Link
|
| 207 | *
|
| 208 | * Create a spam-protected mailto link written in Javascript
|
| 209 | *
|
| 210 | * @access public
|
| 211 | * @param string the email address
|
| 212 | * @param string the link title
|
| 213 | * @param mixed any attributes
|
| 214 | * @return string
|
| 215 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 216 | if ( ! function_exists('safe_mailto'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 217 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 218 | function safe_mailto($email, $title = '', $attributes = '')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 219 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 220 | $title = (string) $title;
|
| 221 |
|
| 222 | if ($title == "")
|
| 223 | {
|
| 224 | $title = $email;
|
| 225 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 226 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 227 | for ($i = 0; $i < 16; $i++)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 228 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 229 | $x[] = substr('<a href="mailto:', $i, 1);
|
| 230 | }
|
| 231 |
|
| 232 | for ($i = 0; $i < strlen($email); $i++)
|
| 233 | {
|
| 234 | $x[] = "|".ord(substr($email, $i, 1));
|
| 235 | }
|
| 236 |
|
| 237 | $x[] = '"';
|
| 238 |
|
| 239 | if ($attributes != '')
|
| 240 | {
|
| 241 | if (is_array($attributes))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 242 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 243 | foreach ($attributes as $key => $val)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 244 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 245 | $x[] = ' '.$key.'="';
|
| 246 | for ($i = 0; $i < strlen($val); $i++)
|
| 247 | {
|
| 248 | $x[] = "|".ord(substr($val, $i, 1));
|
| 249 | }
|
| 250 | $x[] = '"';
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 251 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 252 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 253 | else
|
| 254 | {
|
| 255 | for ($i = 0; $i < strlen($attributes); $i++)
|
| 256 | {
|
| 257 | $x[] = substr($attributes, $i, 1);
|
| 258 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 259 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 260 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 261 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 262 | $x[] = '>';
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 263 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 264 | $temp = array();
|
| 265 | for ($i = 0; $i < strlen($title); $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 | $ordinal = ord($title[$i]);
|
| 268 |
|
| 269 | if ($ordinal < 128)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 270 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 271 | $x[] = "|".$ordinal;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 272 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 273 | else
|
| 274 | {
|
| 275 | if (count($temp) == 0)
|
| 276 | {
|
| 277 | $count = ($ordinal < 224) ? 2 : 3;
|
| 278 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 279 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 280 | $temp[] = $ordinal;
|
| 281 | if (count($temp) == $count)
|
| 282 | {
|
| 283 | $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64);
|
| 284 | $x[] = "|".$number;
|
| 285 | $count = 1;
|
| 286 | $temp = array();
|
| 287 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 288 | }
|
| 289 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 290 |
|
| 291 | $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>';
|
| 292 |
|
| 293 | $x = array_reverse($x);
|
| 294 | ob_start();
|
| 295 |
|
| 296 | ?><script type="text/javascript">
|
| 297 | //<![CDATA[
|
| 298 | var l=new Array();
|
| 299 | <?php
|
| 300 | $i = 0;
|
| 301 | foreach ($x as $val){ ?>l[<?php echo $i++; ?>]='<?php echo $val; ?>';<?php } ?>
|
| 302 |
|
| 303 | for (var i = l.length-1; i >= 0; i=i-1){
|
| 304 | if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";");
|
| 305 | else document.write(unescape(l[i]));}
|
| 306 | //]]>
|
| 307 | </script><?php
|
| 308 |
|
| 309 | $buffer = ob_get_contents();
|
| 310 | ob_end_clean();
|
| 311 | return $buffer;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 312 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 313 | }
|
| 314 |
|
| 315 | // ------------------------------------------------------------------------
|
| 316 |
|
| 317 | /**
|
| 318 | * Auto-linker
|
| 319 | *
|
| 320 | * Automatically links URL and Email addresses.
|
| 321 | * Note: There's a bit of extra code here to deal with
|
| 322 | * URLs or emails that end in a period. We'll strip these
|
| 323 | * off and add them after the link.
|
| 324 | *
|
| 325 | * @access public
|
| 326 | * @param string the string
|
| 327 | * @param string the type: email, url, or both
|
| 328 | * @param bool whether to create pop-up links
|
| 329 | * @return string
|
| 330 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 331 | if ( ! function_exists('auto_link'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 332 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 333 | function auto_link($str, $type = 'both', $popup = FALSE)
|
| 334 | {
|
| 335 | if ($type != 'email')
|
| 336 | {
|
| 337 | 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] | 338 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 339 | $pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
|
| 340 |
|
| 341 | for ($i = 0; $i < sizeof($matches['0']); $i++)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 342 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 343 | $period = '';
|
| 344 | if (preg_match("|\.$|", $matches['6'][$i]))
|
| 345 | {
|
| 346 | $period = '.';
|
| 347 | $matches['6'][$i] = substr($matches['6'][$i], 0, -1);
|
| 348 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 349 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 350 | $str = str_replace($matches['0'][$i],
|
| 351 | $matches['1'][$i].'<a href="http'.
|
| 352 | $matches['4'][$i].'://'.
|
| 353 | $matches['5'][$i].
|
| 354 | $matches['6'][$i].'"'.$pop.'>http'.
|
| 355 | $matches['4'][$i].'://'.
|
| 356 | $matches['5'][$i].
|
| 357 | $matches['6'][$i].'</a>'.
|
| 358 | $period, $str);
|
| 359 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 360 | }
|
| 361 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 362 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 363 | if ($type != 'url')
|
| 364 | {
|
| 365 | 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] | 366 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 367 | for ($i = 0; $i < sizeof($matches['0']); $i++)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 368 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 369 | $period = '';
|
| 370 | if (preg_match("|\.$|", $matches['3'][$i]))
|
| 371 | {
|
| 372 | $period = '.';
|
| 373 | $matches['3'][$i] = substr($matches['3'][$i], 0, -1);
|
| 374 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 375 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 376 | $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str);
|
| 377 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 378 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 379 | }
|
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 | return $str;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 382 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 383 | }
|
| 384 |
|
| 385 | // ------------------------------------------------------------------------
|
| 386 |
|
| 387 | /**
|
| 388 | * Prep URL
|
| 389 | *
|
| 390 | * Simply adds the http:// part if missing
|
| 391 | *
|
| 392 | * @access public
|
| 393 | * @param string the URL
|
| 394 | * @return string
|
| 395 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 396 | if ( ! function_exists('prep_url'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 397 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 398 | function prep_url($str = '')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 399 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 400 | if ($str == 'http://' OR $str == '')
|
| 401 | {
|
| 402 | return '';
|
| 403 | }
|
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 | if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://')
|
| 406 | {
|
| 407 | $str = 'http://'.$str;
|
| 408 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 409 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 410 | return $str;
|
| 411 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 412 | }
|
| 413 |
|
| 414 | // ------------------------------------------------------------------------
|
| 415 |
|
| 416 | /**
|
| 417 | * Create URL Title
|
| 418 | *
|
| 419 | * Takes a "title" string as input and creates a
|
| 420 | * human-friendly URL string with either a dash
|
| 421 | * or an underscore as the word separator.
|
| 422 | *
|
| 423 | * @access public
|
| 424 | * @param string the string
|
| 425 | * @param string the separator: dash, or underscore
|
| 426 | * @return string
|
| 427 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 428 | if ( ! function_exists('url_title'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 429 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 430 | function url_title($str, $separator = 'dash')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 431 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 432 | if ($separator == 'dash')
|
| 433 | {
|
| 434 | $search = '_';
|
| 435 | $replace = '-';
|
| 436 | }
|
| 437 | else
|
| 438 | {
|
| 439 | $search = '-';
|
| 440 | $replace = '_';
|
| 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 | $trans = array(
|
| 444 | $search => $replace,
|
| 445 | "\s+" => $replace,
|
| 446 | "[^a-z0-9".$replace."]" => '',
|
| 447 | $replace."+" => $replace,
|
| 448 | $replace."$" => '',
|
| 449 | "^".$replace => ''
|
| 450 | );
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 451 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 452 | $str = strip_tags(strtolower($str));
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 453 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 454 | foreach ($trans as $key => $val)
|
| 455 | {
|
| 456 | $str = preg_replace("#".$key."#", $val, $str);
|
| 457 | }
|
| 458 |
|
| 459 | return trim(stripslashes($str));
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 460 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 461 | }
|
| 462 |
|
| 463 | // ------------------------------------------------------------------------
|
| 464 |
|
| 465 | /**
|
| 466 | * Header Redirect
|
| 467 | *
|
| 468 | * Header redirect in two flavors
|
Derek Allard | 05f830c | 2008-04-27 13:35:20 +0000 | [diff] [blame] | 469 | * For very fine grained control over headers, you could use the Output
|
| 470 | * Library's set_header() function.
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 471 | *
|
| 472 | * @access public
|
| 473 | * @param string the URL
|
| 474 | * @param string the method: location or redirect
|
| 475 | * @return string
|
| 476 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 477 | if ( ! function_exists('redirect'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 478 | {
|
Derek Allard | 05f830c | 2008-04-27 13:35:20 +0000 | [diff] [blame] | 479 | function redirect($uri = '', $method = 'location', $http_response_code = 302)
|
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 | switch($method)
|
| 482 | {
|
| 483 | case 'refresh' : header("Refresh:0;url=".site_url($uri));
|
| 484 | break;
|
Derek Allard | 05f830c | 2008-04-27 13:35:20 +0000 | [diff] [blame] | 485 | default : header("Location: ".site_url($uri), TRUE, $http_response_code);
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 486 | break;
|
| 487 | }
|
| 488 | exit;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 489 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 490 | }
|
| 491 |
|
| 492 | // ------------------------------------------------------------------------
|
| 493 |
|
| 494 | /**
|
| 495 | * Parse out the attributes
|
| 496 | *
|
| 497 | * Some of the functions use this
|
| 498 | *
|
| 499 | * @access private
|
| 500 | * @param array
|
| 501 | * @param bool
|
| 502 | * @return string
|
| 503 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 504 | if ( ! function_exists('_parse_attributes'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 505 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 506 | function _parse_attributes($attributes, $javascript = FALSE)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 507 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 508 | if (is_string($attributes))
|
| 509 | {
|
| 510 | return ($attributes != '') ? ' '.$attributes : '';
|
| 511 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 512 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 513 | $att = '';
|
| 514 | foreach ($attributes as $key => $val)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 515 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 516 | if ($javascript == TRUE)
|
| 517 | {
|
| 518 | $att .= $key . '=' . $val . ',';
|
| 519 | }
|
| 520 | else
|
| 521 | {
|
| 522 | $att .= ' ' . $key . '="' . $val . '"';
|
| 523 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 524 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 525 |
|
| 526 | if ($javascript == TRUE AND $att != '')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 527 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 528 | $att = substr($att, 0, -1);
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 529 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 530 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 531 | return $att;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 532 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 533 | }
|
| 534 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 535 |
|
| 536 | /* End of file url_helper.php */
|
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 537 | /* Location: ./system/helpers/url_helper.php */ |