312c5e54a35ba4790c15842ca349504f241468ac
[phinde.git] / src / phinde / Helper.php
1 <?php
2 namespace phinde;
3
4 class Helper
5 {
6     public static function isUrlAllowed($url)
7     {
8         $urlDomain = parse_url($url, PHP_URL_HOST);
9         if (!in_array($urlDomain, $GLOBALS['phinde']['domains'])) {
10             return false;
11         }
12         return true;
13     }
14
15     public static function noSchema($url)
16     {
17         return str_replace(
18             array('http://', 'https://'),
19             '',
20             $url
21         );
22     }
23
24     public static function addSchema($url)
25     {
26         if (substr($url, 0, 7) == 'http://'
27             || substr($url, 0, 8) == 'https://'
28         ) {
29             return $url;
30         }
31         return 'http://' . $url;
32     }
33
34     public static function sanitizeTitle($str)
35     {
36         return trim(
37             str_replace(
38                 array("\r", "\n", '  ', '  '),
39                 array('', ' ', ' ', ' '),
40                 $str
41             )
42         );
43     }
44 }
45 ?>