2 /*------------------------------------------------------------
3 * CarbonPHP framework (C) Tom Bell
4 * http://tombell.org.uk
5 *------------------------------------------------------------*/
7 if (!defined('CARBON_PATH'))
9 exit('Direct script access is not allowed.');
12 if (!function_exists('site_url'))
14 function site_url($uri = '')
16 $carbon =& get_instance();
17 return $carbon->config
->get_site_url($uri);
21 if (!function_exists('base_url'))
25 $carbon =& get_instance();
26 return $carbon->config
->slash_item('base_url');
30 if (!function_exists('index_page'))
34 $carbon =& get_instance();
35 return $carbon->config
->get_item_value('index_page');
39 if (!function_exists('anchor'))
41 function anchor($uri = '', $title = '', $attributes = '')
43 $title = (string) $title;
47 $site_url = (!preg_match('!^\w+://!i', $uri)) ?
site_url($uri) : $uri;
51 $site_url = site_url($uri);
59 if ($attributes == '')
61 $attributes = ' title="' . $title . '"';
65 $attributes = parse_attributes($attributes);
68 return '<a href="' . $site_url . '"' . $attributes . '>' . $title . '</a>';
72 if (!function_exists('anchor_popup'))
74 function anchor_popup($uri = '', $title = '', $attributes = false)
76 $title = (string) $title;
77 $site_url = (!preg_match('!^\w+://!i', $uri)) ?
site_url($uri) : $uri;
84 if ($attributes === false)
86 return "<a href='javascript:void(0);' onclick=\"window.open('" . $site_url . "', '_blank');\">" . $title . "</a>";
89 if (!is_array($attributes))
91 $attributes = array();
97 'scrollbars' => 'yes',
104 foreach ($default as $key => $val)
106 $attr[$key] = (!isset($attributes[$key])) ?
$val : $attributes[$key];
109 return "<a href='javascript(0);' onclick=\"window.open('" . $site_url . "', '_blank', '" . parse_attributes($attr, true) . "');\">" . $title . "</a>";
113 if (!function_exists('mailto'))
115 function mailto($email, $title = '', $attributes = '')
117 $title = (string) $title;
124 $attributes = parse_attributes($attributes);
126 return '<a href="mailto:' . $email . '"' . $attributes . '>' . $title . '</a>';
130 if (!function_exists('safe_mailto'))
132 function safe_mailto($email, $title = '', $attributes = '')
134 $title = (string) $title;
141 for ($i = 0; $i < 16; $i++
)
143 $x[] = substr('<a href="mailto:', $i, 1);
146 for ($i = 0; $i < strlen($email); $i++
)
148 $x[] = '|' . ord(substr($email, $i, 1));
153 if ($attributes != '')
155 if (is_array($attributes))
157 foreach ($attributes as $key => $val)
159 $x[] = ' ' . $key . '="';
161 for ($i = 0; $i < strlen($val); $i++
)
163 $x[] = '|' . ord(substr($val, $i, 1));
171 for ($i = 0; $i < strlen($attributes); $i++
)
173 $x[] = substr($attributes, $i, 1);
182 for ($i = 0; $i < strlen($title); $i++
)
184 $ordinal = ord($title[$i]);
188 $x[] = '|' . $ordinal;
192 if (count($temp) == 0)
194 $count = ($ordinal < 224) ?
2 : 3;
199 if (count($temp) == $count)
201 $number = ($count == 3) ?
(($temp['0'] %
16) * 4096) +
(($temp['1'] %
64) * 64) +
($temp['2'] %
64) : (($temp['0'] %
32) * 64) +
($temp['1'] %
64);
202 $x[] = '|' . $number;
214 $x = array_reverse($x);
219 <script type
="text/javascript">
228 l
[<?php
echo $i++
;?
>] = '<?php echo $val;?>';
233 for (var i
= l
.length
- 1; i
>= 0; i
= i
- 1)
235 if (l
[i
].substring(0, 1) == '|')
237 document
.write("&#" +
unescape(l
[i
].substring(1)) +
";");
241 document
.write(unescape(l
[i
]));
248 $buffer = ob_get_contents();
254 if (!function_exists('auto_link'))
256 function auto_link($string, $type = 'both', $popup = false)
258 if ($type != 'email')
260 if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $string, $matches))
262 $pop = ($popup == true) ?
' target="_blank" ' : '';
264 for ($i = 0; $i < sizeof($matches['0']); $i++
)
268 if (preg_match("|\.$|", $matches['6'][$i]))
271 $matches['6'][$i] = substr($matches['6'][$i], 0, -1);
274 $string = str_replace($matches['0'][$i],
275 $matches['1'][$i] . '<a href="http' .
276 $matches['4'][$i] . '://' .
278 $matches['6'][$i] . '"' . $pop . '>http' .
279 $matches['4'][$i] . '://' .
281 $matches['6'][$i] . '</a>' .
289 if (preg_match_all("/([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $string, $matches))
291 for ($i = 0; $i < sizeof($matches['0']); $i++
)
294 $matches['3'][$i] = substr($matches['3'][$i], 0, -1);
297 $string = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i] . '@' . $matches['2'][$i] . '.' . $matches['3'][$i]) . $period, $string);
305 if (!function_exists('prep_url'))
307 function prep_url($string = '')
309 if ($string == 'http://' ||
$string == '')
314 if (substr($string, 0, 7) != 'http://' && substr($string, 0, 8) != 'https://')
316 $string = 'http://' . $string;
323 if (!function_exists('url_title'))
325 function url_title($string, $separator = 'dash')
327 if ($separator == 'dash')
341 "[^a-z0-9]" . $replace . "]" => '',
342 $replace . "+" => $replace,
343 $replace . "$" => '',
347 $string = strip_tags(strtolower($string));
349 foreach ($trans as $key => $val)
351 $string = preg_replace("#" . $key . "#", $val, $string);
354 return trim(stripslashes($string));
358 if (!function_exists('redirect'))
360 function redirect($uri = '', $method = 'location')
365 header('Refresh:0; url= ' . site_url($uri));
369 header('Location: ' . site_url($uri));
377 if (!function_exists('parse_attributes'))
379 function parse_attributes($attributes, $javascript = false)
381 if (is_string($attributes))
383 return ($attributes != '') ?
' ' . $attributes : '';
388 foreach ($attributes as $key => $val)
390 if ($javascript == true)
392 $attr .= $key . '=' . $val . ',';
396 $attr .= ' ' . $key . '="' . $val . '"';
400 if ($javascript == true && $attr != '')
402 $attr = substr($attr, 0, -1);