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