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
|
Rick Ellis | dd1e323 | 2008-09-12 23:33:20 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2008, 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
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 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
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 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
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 78 | */
|
Rick Ellis | 9e2c04c | 2008-08-19 22:12:26 +0000 | [diff] [blame] | 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 | *
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 92 | * Returns the URI segments.
|
Rick Ellis | 9e2c04c | 2008-08-19 22:12:26 +0000 | [diff] [blame] | 93 | *
|
| 94 | * @access public
|
| 95 | * @return string
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 96 | */
|
Rick Ellis | 9e2c04c | 2008-08-19 22:12:26 +0000 | [diff] [blame] | 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
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 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 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 124 |
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 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
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 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 Allard | 42597a1 | 2008-10-15 14:10:44 +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 | 42597a1 | 2008-10-15 14:10:44 +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 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 166 |
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 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)
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 184 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 185 | $title = (string) $title;
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +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 | 42597a1 | 2008-10-15 14:10:44 +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 | 42597a1 | 2008-10-15 14:10:44 +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 | 42597a1 | 2008-10-15 14:10:44 +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 | 42597a1 | 2008-10-15 14:10:44 +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 Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 207 | unset($attributes[$key]);
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 208 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 209 |
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 210 | if ($attributes != '')
|
| 211 | {
|
| 212 | $attributes = _parse_attributes($attributes);
|
| 213 | }
|
| 214 |
|
| 215 | return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\"$attributes>".$title."</a>";
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 216 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 217 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 218 |
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 219 | // ------------------------------------------------------------------------
|
| 220 |
|
| 221 | /**
|
| 222 | * Mailto Link
|
| 223 | *
|
| 224 | * @access public
|
| 225 | * @param string the email address
|
| 226 | * @param string the link title
|
| 227 | * @param mixed any attributes
|
| 228 | * @return string
|
| 229 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 230 | if ( ! function_exists('mailto'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 231 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 232 | function mailto($email, $title = '', $attributes = '')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 233 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 234 | $title = (string) $title;
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 235 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 236 | if ($title == "")
|
| 237 | {
|
| 238 | $title = $email;
|
| 239 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 240 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 241 | $attributes = _parse_attributes($attributes);
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 242 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 243 | return '<a href="mailto:'.$email.'"'.$attributes.'>'.$title.'</a>';
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 244 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 245 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 246 |
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 247 | // ------------------------------------------------------------------------
|
| 248 |
|
| 249 | /**
|
| 250 | * Encoded Mailto Link
|
| 251 | *
|
| 252 | * Create a spam-protected mailto link written in Javascript
|
| 253 | *
|
| 254 | * @access public
|
| 255 | * @param string the email address
|
| 256 | * @param string the link title
|
| 257 | * @param mixed any attributes
|
| 258 | * @return string
|
| 259 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 260 | if ( ! function_exists('safe_mailto'))
|
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 | function safe_mailto($email, $title = '', $attributes = '')
|
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 | $title = (string) $title;
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 265 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 266 | if ($title == "")
|
| 267 | {
|
| 268 | $title = $email;
|
| 269 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 270 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 271 | for ($i = 0; $i < 16; $i++)
|
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 | $x[] = substr('<a href="mailto:', $i, 1);
|
| 274 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 275 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 276 | for ($i = 0; $i < strlen($email); $i++)
|
| 277 | {
|
| 278 | $x[] = "|".ord(substr($email, $i, 1));
|
| 279 | }
|
| 280 |
|
| 281 | $x[] = '"';
|
| 282 |
|
| 283 | if ($attributes != '')
|
| 284 | {
|
| 285 | if (is_array($attributes))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 286 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 287 | foreach ($attributes as $key => $val)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 288 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 289 | $x[] = ' '.$key.'="';
|
| 290 | for ($i = 0; $i < strlen($val); $i++)
|
| 291 | {
|
| 292 | $x[] = "|".ord(substr($val, $i, 1));
|
| 293 | }
|
| 294 | $x[] = '"';
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 295 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 296 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 297 | else
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 298 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 299 | for ($i = 0; $i < strlen($attributes); $i++)
|
| 300 | {
|
| 301 | $x[] = substr($attributes, $i, 1);
|
| 302 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 303 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 304 | }
|
| 305 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 306 | $x[] = '>';
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 307 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 308 | $temp = array();
|
| 309 | for ($i = 0; $i < strlen($title); $i++)
|
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 | $ordinal = ord($title[$i]);
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 312 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 313 | if ($ordinal < 128)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 314 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 315 | $x[] = "|".$ordinal;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 316 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 317 | else
|
| 318 | {
|
| 319 | if (count($temp) == 0)
|
| 320 | {
|
| 321 | $count = ($ordinal < 224) ? 2 : 3;
|
| 322 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 323 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 324 | $temp[] = $ordinal;
|
| 325 | if (count($temp) == $count)
|
| 326 | {
|
| 327 | $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64);
|
| 328 | $x[] = "|".$number;
|
| 329 | $count = 1;
|
| 330 | $temp = array();
|
| 331 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 332 | }
|
| 333 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 334 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 335 | $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>';
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 336 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 337 | $x = array_reverse($x);
|
| 338 | ob_start();
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 339 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 340 | ?><script type="text/javascript">
|
| 341 | //<![CDATA[
|
| 342 | var l=new Array();
|
| 343 | <?php
|
| 344 | $i = 0;
|
| 345 | foreach ($x as $val){ ?>l[<?php echo $i++; ?>]='<?php echo $val; ?>';<?php } ?>
|
| 346 |
|
| 347 | for (var i = l.length-1; i >= 0; i=i-1){
|
| 348 | if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";");
|
| 349 | else document.write(unescape(l[i]));}
|
| 350 | //]]>
|
| 351 | </script><?php
|
| 352 |
|
| 353 | $buffer = ob_get_contents();
|
| 354 | ob_end_clean();
|
| 355 | return $buffer;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 356 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 357 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 358 |
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 359 | // ------------------------------------------------------------------------
|
| 360 |
|
| 361 | /**
|
| 362 | * Auto-linker
|
| 363 | *
|
| 364 | * Automatically links URL and Email addresses.
|
| 365 | * Note: There's a bit of extra code here to deal with
|
| 366 | * URLs or emails that end in a period. We'll strip these
|
| 367 | * off and add them after the link.
|
| 368 | *
|
| 369 | * @access public
|
| 370 | * @param string the string
|
| 371 | * @param string the type: email, url, or both
|
| 372 | * @param bool whether to create pop-up links
|
| 373 | * @return string
|
| 374 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 375 | if ( ! function_exists('auto_link'))
|
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 | function auto_link($str, $type = 'both', $popup = FALSE)
|
| 378 | {
|
| 379 | if ($type != 'email')
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 380 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 381 | 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] | 382 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 383 | $pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 384 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 385 | for ($i = 0; $i < sizeof($matches['0']); $i++)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 386 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 387 | $period = '';
|
| 388 | if (preg_match("|\.$|", $matches['6'][$i]))
|
| 389 | {
|
| 390 | $period = '.';
|
| 391 | $matches['6'][$i] = substr($matches['6'][$i], 0, -1);
|
| 392 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 393 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 394 | $str = str_replace($matches['0'][$i],
|
| 395 | $matches['1'][$i].'<a href="http'.
|
| 396 | $matches['4'][$i].'://'.
|
| 397 | $matches['5'][$i].
|
| 398 | $matches['6'][$i].'"'.$pop.'>http'.
|
| 399 | $matches['4'][$i].'://'.
|
| 400 | $matches['5'][$i].
|
| 401 | $matches['6'][$i].'</a>'.
|
| 402 | $period, $str);
|
| 403 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 404 | }
|
| 405 | }
|
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 | if ($type != 'url')
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 408 | {
|
Derek Allard | dbc9e15 | 2008-10-06 14:41:47 +0000 | [diff] [blame] | 409 | 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] | 410 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 411 | for ($i = 0; $i < sizeof($matches['0']); $i++)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 412 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 413 | $period = '';
|
| 414 | if (preg_match("|\.$|", $matches['3'][$i]))
|
| 415 | {
|
| 416 | $period = '.';
|
| 417 | $matches['3'][$i] = substr($matches['3'][$i], 0, -1);
|
| 418 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 419 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 420 | $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str);
|
| 421 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 422 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 423 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 424 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 425 | return $str;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 426 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 427 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 428 |
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 429 | // ------------------------------------------------------------------------
|
| 430 |
|
| 431 | /**
|
| 432 | * Prep URL
|
| 433 | *
|
| 434 | * Simply adds the http:// part if missing
|
| 435 | *
|
| 436 | * @access public
|
| 437 | * @param string the URL
|
| 438 | * @return string
|
| 439 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 440 | if ( ! function_exists('prep_url'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 441 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 442 | function prep_url($str = '')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 443 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 444 | if ($str == 'http://' OR $str == '')
|
| 445 | {
|
| 446 | return '';
|
| 447 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 448 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 449 | if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://')
|
| 450 | {
|
| 451 | $str = 'http://'.$str;
|
| 452 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 453 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 454 | return $str;
|
| 455 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 456 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 457 |
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 458 | // ------------------------------------------------------------------------
|
| 459 |
|
| 460 | /**
|
| 461 | * Create URL Title
|
| 462 | *
|
| 463 | * Takes a "title" string as input and creates a
|
| 464 | * human-friendly URL string with either a dash
|
| 465 | * or an underscore as the word separator.
|
| 466 | *
|
| 467 | * @access public
|
| 468 | * @param string the string
|
| 469 | * @param string the separator: dash, or underscore
|
| 470 | * @return string
|
| 471 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 472 | if ( ! function_exists('url_title'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 473 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 474 | function url_title($str, $separator = 'dash')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 475 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 476 | if ($separator == 'dash')
|
| 477 | {
|
| 478 | $search = '_';
|
| 479 | $replace = '-';
|
| 480 | }
|
| 481 | else
|
| 482 | {
|
| 483 | $search = '-';
|
| 484 | $replace = '_';
|
| 485 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 486 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 487 | $trans = array(
|
Derek Jones | fd27570 | 2008-10-10 22:37:06 +0000 | [diff] [blame] | 488 | '&\#\d+?;' => '',
|
| 489 | '&\S+?;' => '',
|
| 490 | '\s+' => $replace,
|
| 491 | '[^a-z0-9\-\._]' => '',
|
| 492 | $replace.'+' => $replace,
|
| 493 | $replace.'$' => $replace,
|
| 494 | '^'.$replace => $replace
|
| 495 | );
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 496 |
|
Derek Jones | fd27570 | 2008-10-10 22:37:06 +0000 | [diff] [blame] | 497 | $str = strip_tags($str);
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 498 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 499 | foreach ($trans as $key => $val)
|
| 500 | {
|
Derek Jones | fd27570 | 2008-10-10 22:37:06 +0000 | [diff] [blame] | 501 | $str = preg_replace("#".$key."#i", $val, $str);
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 502 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 503 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 504 | return trim(stripslashes($str));
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 505 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 506 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 507 |
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 508 | // ------------------------------------------------------------------------
|
| 509 |
|
| 510 | /**
|
| 511 | * Header Redirect
|
| 512 | *
|
| 513 | * Header redirect in two flavors
|
Derek Allard | 05f830c | 2008-04-27 13:35:20 +0000 | [diff] [blame] | 514 | * For very fine grained control over headers, you could use the Output
|
| 515 | * Library's set_header() function.
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 516 | *
|
| 517 | * @access public
|
| 518 | * @param string the URL
|
| 519 | * @param string the method: location or redirect
|
| 520 | * @return string
|
| 521 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 522 | if ( ! function_exists('redirect'))
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 523 | {
|
Derek Allard | 05f830c | 2008-04-27 13:35:20 +0000 | [diff] [blame] | 524 | function redirect($uri = '', $method = 'location', $http_response_code = 302)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 525 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 526 | switch($method)
|
| 527 | {
|
| 528 | case 'refresh' : header("Refresh:0;url=".site_url($uri));
|
| 529 | break;
|
Derek Allard | 05f830c | 2008-04-27 13:35:20 +0000 | [diff] [blame] | 530 | default : header("Location: ".site_url($uri), TRUE, $http_response_code);
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 531 | break;
|
| 532 | }
|
| 533 | exit;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 534 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 535 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 536 |
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 537 | // ------------------------------------------------------------------------
|
| 538 |
|
| 539 | /**
|
| 540 | * Parse out the attributes
|
| 541 | *
|
| 542 | * Some of the functions use this
|
| 543 | *
|
| 544 | * @access private
|
| 545 | * @param array
|
| 546 | * @param bool
|
| 547 | * @return string
|
| 548 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 549 | if ( ! function_exists('_parse_attributes'))
|
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 | function _parse_attributes($attributes, $javascript = FALSE)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 552 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 553 | if (is_string($attributes))
|
| 554 | {
|
| 555 | return ($attributes != '') ? ' '.$attributes : '';
|
| 556 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 557 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 558 | $att = '';
|
| 559 | foreach ($attributes as $key => $val)
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 560 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 561 | if ($javascript == TRUE)
|
| 562 | {
|
| 563 | $att .= $key . '=' . $val . ',';
|
| 564 | }
|
| 565 | else
|
| 566 | {
|
| 567 | $att .= ' ' . $key . '="' . $val . '"';
|
| 568 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 569 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 570 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 571 | if ($javascript == TRUE AND $att != '')
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 572 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 573 | $att = substr($att, 0, -1);
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 574 | }
|
Derek Allard | 42597a1 | 2008-10-15 14:10:44 +0000 | [diff] [blame^] | 575 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 576 | return $att;
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 577 | }
|
Derek Allard | 5811bf1 | 2007-02-20 01:26:08 +0000 | [diff] [blame] | 578 | }
|
| 579 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 580 |
|
| 581 | /* End of file url_helper.php */
|
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 582 | /* Location: ./system/helpers/url_helper.php */ |