c3336c36b1a6da2cfaf996c3879008a615baa7d3
[phorkie.git] / src / phorkie / HtmlHelper.php
1 <?php
2 namespace phorkie;
3
4 class HtmlHelper
5 {
6     public function getIconUrl($email, $size = 32)
7     {
8         if ($email == 'anonymous@phorkie') {
9             return 'phorkie/anonymous.png';
10         }
11
12         $s = new \Services_Libravatar();
13         return $s->url(
14             $email,
15             array(
16                 'size'    => $size,
17                 'default' => Tools::fullUrl('phorkie/anonymous.png')
18             )
19         );
20     }
21
22     public function getLanguageOptions(File $file = null)
23     {
24         $html = '<option value="_auto_">* automatic *</option>';
25         $fileExt = null;
26         if ($file !== null) {
27             $fileExt = $file->getExt();
28         }
29         foreach ($GLOBALS['phorkie']['languages'] as $ext => $arLang) {
30             if (isset($arLang['show']) && !$arLang['show']) {
31                 continue;
32             }
33             $html .= sprintf(
34                 '<option value="%s"%s>%s</option>',
35                 $ext,
36                 $fileExt == $ext ? ' selected="selected"' : '',
37                 $arLang['title']
38             ) . "\n";
39         }
40         return $html;
41     }
42
43     public function getDomain($url)
44     {
45         return parse_url($url, PHP_URL_HOST);
46     }
47
48     public function fullUrl($path = '')
49     {
50         return Tools::fullUrl($path);
51     }
52
53     public function mayWriteLocally()
54     {
55         if ($GLOBALS['phorkie']['auth']['securityLevel'] == 0) {
56             //everyone may do everything
57             return true;
58         }
59
60         $logged_in = false;
61         if (!isset($_SESSION['identity'])) {
62             //not logged in
63         } else if ($GLOBALS['phorkie']['auth']['listedUsersOnly']) {
64             if (in_array($_SESSION['identity'], $GLOBALS['phorkie']['auth']['users'])) {
65                 $logged_in = true;
66             }
67         } else {
68             //session identity exists, no special checks required
69             $logged_in = true;
70         }
71
72         return $logged_in;
73     }
74 }
75
76 ?>