aboutsummaryrefslogtreecommitdiff
path: root/src/phorkie/HtmlHelper.php
blob: 0a8b926888fca70554bbd56f0d3c2da47957aeca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace phorkie;

class HtmlHelper
{
    public function getIconUrl($email, $size = 32)
    {
        if ($email == 'anonymous@phorkie'
            || !$GLOBALS['phorkie']['cfg']['avatars']
        ) {
            return 'phorkie/anonymous.png';
        }

        $s = new \Services_Libravatar();
        $s->detectHttps();
        return $s->url(
            $email,
            array(
                'size'    => $size,
                'default' => Tools::fullUrl('phorkie/anonymous.png')
            )
        );
    }

    public function getLanguageOptions(File $file = null)
    {
        $html = '<option value="_auto_">* automatic *</option>';
        $fileExt = null;
        if ($file !== null) {
            $fileExt = $file->getExt();
        }
        foreach ($GLOBALS['phorkie']['languages'] as $ext => $arLang) {
            if (isset($arLang['show']) && !$arLang['show']) {
                continue;
            }
            $html .= sprintf(
                '<option value="%s"%s>%s</option>',
                $ext,
                $fileExt == $ext ? ' selected="selected"' : '',
                $arLang['title']
            ) . "\n";
        }
        return $html;
    }

    public function getDomain($url)
    {
        return parse_url($url, PHP_URL_HOST);
    }

    public function fullUrl($path = '')
    {
        return Tools::fullUrl($path);
    }

    public function mayWriteLocally()
    {
        if ($GLOBALS['phorkie']['auth']['securityLevel'] == 0) {
            //everyone may do everything
            return true;
        }

        $logged_in = false;
        if (!isset($_SESSION['identity'])) {
            //not logged in
        } else if ($GLOBALS['phorkie']['auth']['listedUsersOnly']) {
            if (in_array($_SESSION['identity'], $GLOBALS['phorkie']['auth']['users'])) {
                $logged_in = true;
            }
        } else {
            //session identity exists, no special checks required
            $logged_in = true;
        }

        return $logged_in;
    }

    public function getRepositoryEmbedCode(Repository $repo)
    {
        return '<script src="' . $repo->getLink('embed', null, true) . '"'
            . ' id="phork-script-' . $repo->id . '"'
            . ' type="text/javascript"></script>';
    }
}

?>