43345ba22899c890966c5a659bda068b0daebbe6
[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     /**
46      * Create a full URL with protocol and host name
47      *
48      * @param string $path Path to the file, with leading /
49      *
50      * @return string Full URL
51      */
52     public static function fullUrl($path = '/')
53     {
54         if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) {
55             $prot = 'https';
56         } else {
57             $prot = 'http';
58         }
59         return $prot . '://' . $_SERVER['HTTP_HOST'] . $path;
60     }
61
62 }
63 ?>