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