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