Added filterable to summary and histogram controllers
[ninja.git] / application / helpers / link.php
blob8031f1104624b8f0f74e0352ddffa876ae4d6aac
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Help class for handling links that could contain
4 * chars that would break Kohanas routing ('/')
5 */
6 class link
8 /**
9 * Encode a string so that it is possible to
10 * use it without risk in Kohana.
11 * The 'all' string has been given a special meaning
12 * and is therefore not encoded.
13 * @param $str
14 * @return str encoded string
16 public function encode($str)
18 $str = trim($str);
19 if (strtolower($str) == 'all') {
20 return $str;
22 return rawurlencode(base64_encode($str));
25 /**
26 * Decode a string that has been encoded
27 * using the encode method.
28 * The 'all' string has been given a special meaning
29 * and is therefore not decoded.
30 * @param $str
31 * @return decoded string
33 public function decode($str)
35 $str = trim($str);
36 if (strtolower($str) == 'all') {
37 return $str;
39 return rawurldecode(base64_decode($str));
42 /**
43 * Primitively 'detect' URI:s in a text and wrap
44 * in a html anchor element.
46 * @param $text string
47 * @return string
49 public static function linkify($text) {
50 return preg_replace('~((ftp|https?)://[^ ]+)~', '<a target="'.config::get('nagdefault.notes_url_target', '*').'" href="$1">$1</a>', $text);