00001 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 if ( ! function_exists('site_url'))
00041 {
00042 function site_url($uri = '')
00043 {
00044 $CI =& get_instance();
00045 return $CI->config->site_url($uri);
00046 }
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 if ( ! function_exists('base_url'))
00060 {
00061 function base_url()
00062 {
00063 $CI =& get_instance();
00064 return $CI->config->slash_item('base_url');
00065 }
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 if ( ! function_exists('index_page'))
00079 {
00080 function index_page()
00081 {
00082 $CI =& get_instance();
00083 return $CI->config->item('index_page');
00084 }
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 if ( ! function_exists('anchor'))
00101 {
00102 function anchor($uri = '', $title = '', $attributes = '')
00103 {
00104 $title = (string) $title;
00105
00106 if ( ! is_array($uri))
00107 {
00108 $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
00109 }
00110 else
00111 {
00112 $site_url = site_url($uri);
00113 }
00114
00115 if ($title == '')
00116 {
00117 $title = $site_url;
00118 }
00119
00120 if ($attributes != '')
00121 {
00122 $attributes = _parse_attributes($attributes);
00123 }
00124
00125 return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
00126 }
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 if ( ! function_exists('anchor_popup'))
00144 {
00145 function anchor_popup($uri = '', $title = '', $attributes = FALSE)
00146 {
00147 $title = (string) $title;
00148
00149 $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
00150
00151 if ($title == '')
00152 {
00153 $title = $site_url;
00154 }
00155
00156 if ($attributes === FALSE)
00157 {
00158 return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title."</a>";
00159 }
00160
00161 if ( ! is_array($attributes))
00162 {
00163 $attributes = array();
00164 }
00165
00166 foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val)
00167 {
00168 $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key];
00169 }
00170
00171 return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\">".$title."</a>";
00172 }
00173 }
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 if ( ! function_exists('mailto'))
00187 {
00188 function mailto($email, $title = '', $attributes = '')
00189 {
00190 $title = (string) $title;
00191
00192 if ($title == "")
00193 {
00194 $title = $email;
00195 }
00196
00197 $attributes = _parse_attributes($attributes);
00198
00199 return '<a href="mailto:'.$email.'"'.$attributes.'>'.$title.'</a>';
00200 }
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 if ( ! function_exists('safe_mailto'))
00217 {
00218 function safe_mailto($email, $title = '', $attributes = '')
00219 {
00220 $title = (string) $title;
00221
00222 if ($title == "")
00223 {
00224 $title = $email;
00225 }
00226
00227 for ($i = 0; $i < 16; $i++)
00228 {
00229 $x[] = substr('<a href="mailto:', $i, 1);
00230 }
00231
00232 for ($i = 0; $i < strlen($email); $i++)
00233 {
00234 $x[] = "|".ord(substr($email, $i, 1));
00235 }
00236
00237 $x[] = '"';
00238
00239 if ($attributes != '')
00240 {
00241 if (is_array($attributes))
00242 {
00243 foreach ($attributes as $key => $val)
00244 {
00245 $x[] = ' '.$key.'="';
00246 for ($i = 0; $i < strlen($val); $i++)
00247 {
00248 $x[] = "|".ord(substr($val, $i, 1));
00249 }
00250 $x[] = '"';
00251 }
00252 }
00253 else
00254 {
00255 for ($i = 0; $i < strlen($attributes); $i++)
00256 {
00257 $x[] = substr($attributes, $i, 1);
00258 }
00259 }
00260 }
00261
00262 $x[] = '>';
00263
00264 $temp = array();
00265 for ($i = 0; $i < strlen($title); $i++)
00266 {
00267 $ordinal = ord($title[$i]);
00268
00269 if ($ordinal < 128)
00270 {
00271 $x[] = "|".$ordinal;
00272 }
00273 else
00274 {
00275 if (count($temp) == 0)
00276 {
00277 $count = ($ordinal < 224) ? 2 : 3;
00278 }
00279
00280 $temp[] = $ordinal;
00281 if (count($temp) == $count)
00282 {
00283 $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64);
00284 $x[] = "|".$number;
00285 $count = 1;
00286 $temp = array();
00287 }
00288 }
00289 }
00290
00291 $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>';
00292
00293 $x = array_reverse($x);
00294 ob_start();
00295
00296 ?><script type="text/javascript">
00297
00298 var l=new Array();
00299 <?php
00300 $i = 0;
00301 foreach ($x as $val){ ?>l[<?php echo $i++; ?>]='<?php echo $val; ?>';<?php } ?>
00302
00303 for (var i = l.length-1; i >= 0; i=i-1){
00304 if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";");
00305 else document.write(unescape(l[i]));}
00306
00307 </script><?php
00308
00309 $buffer = ob_get_contents();
00310 ob_end_clean();
00311 return $buffer;
00312 }
00313 }
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331 if ( ! function_exists('auto_link'))
00332 {
00333 function auto_link($str, $type = 'both', $popup = FALSE)
00334 {
00335 if ($type != 'email')
00336 {
00337 if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)<]+)#i", $str, $matches))
00338 {
00339 $pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
00340
00341 for ($i = 0; $i < sizeof($matches['0']); $i++)
00342 {
00343 $period = '';
00344 if (preg_match("|\.$|", $matches['6'][$i]))
00345 {
00346 $period = '.';
00347 $matches['6'][$i] = substr($matches['6'][$i], 0, -1);
00348 }
00349
00350 $str = str_replace($matches['0'][$i],
00351 $matches['1'][$i].'<a href="http'.
00352 $matches['4'][$i].'://'.
00353 $matches['5'][$i].
00354 $matches['6'][$i].'"'.$pop.'>http'.
00355 $matches['4'][$i].'://'.
00356 $matches['5'][$i].
00357 $matches['6'][$i].'</a>'.
00358 $period, $str);
00359 }
00360 }
00361 }
00362
00363 if ($type != 'url')
00364 {
00365 if (preg_match_all("/([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches))
00366 {
00367 for ($i = 0; $i < sizeof($matches['0']); $i++)
00368 {
00369 $period = '';
00370 if (preg_match("|\.$|", $matches['3'][$i]))
00371 {
00372 $period = '.';
00373 $matches['3'][$i] = substr($matches['3'][$i], 0, -1);
00374 }
00375
00376 $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str);
00377 }
00378
00379 }
00380 }
00381 return $str;
00382 }
00383 }
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396 if ( ! function_exists('prep_url'))
00397 {
00398 function prep_url($str = '')
00399 {
00400 if ($str == 'http://' OR $str == '')
00401 {
00402 return '';
00403 }
00404
00405 if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://')
00406 {
00407 $str = 'http://'.$str;
00408 }
00409
00410 return $str;
00411 }
00412 }
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428 if ( ! function_exists('url_title'))
00429 {
00430 function url_title($str, $separator = 'dash')
00431 {
00432 if ($separator == 'dash')
00433 {
00434 $search = '_';
00435 $replace = '-';
00436 }
00437 else
00438 {
00439 $search = '-';
00440 $replace = '_';
00441 }
00442
00443 $trans = array(
00444 $search => $replace,
00445 "\s+" => $replace,
00446 "[^a-z0-9".$replace."]" => '',
00447 $replace."+" => $replace,
00448 $replace."$" => '',
00449 "^".$replace => ''
00450 );
00451
00452 $str = strip_tags(strtolower($str));
00453
00454 foreach ($trans as $key => $val)
00455 {
00456 $str = preg_replace("#".$key."#", $val, $str);
00457 }
00458
00459 return trim(stripslashes($str));
00460 }
00461 }
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477 if ( ! function_exists('redirect'))
00478 {
00479 function redirect($uri = '', $method = 'location', $http_response_code = 302)
00480 {
00481 switch($method)
00482 {
00483 case 'refresh' : header("Refresh:0;url=".site_url($uri));
00484 break;
00485 default : header("Location: ".site_url($uri), TRUE, $http_response_code);
00486 break;
00487 }
00488 exit;
00489 }
00490 }
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504 if ( ! function_exists('_parse_attributes'))
00505 {
00506 function _parse_attributes($attributes, $javascript = FALSE)
00507 {
00508 if (is_string($attributes))
00509 {
00510 return ($attributes != '') ? ' '.$attributes : '';
00511 }
00512
00513 $att = '';
00514 foreach ($attributes as $key => $val)
00515 {
00516 if ($javascript == TRUE)
00517 {
00518 $att .= $key . '=' . $val . ',';
00519 }
00520 else
00521 {
00522 $att .= ' ' . $key . '="' . $val . '"';
00523 }
00524 }
00525
00526 if ($javascript == TRUE AND $att != '')
00527 {
00528 $att = substr($att, 0, -1);
00529 }
00530
00531 return $att;
00532 }
00533 }
00534
00535
00536
00537