summaryrefslogtreecommitdiff
path: root/src/emote.php
blob: ce3b930b63920694e0cb8f314fbe54b6edb71307 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
class Emote
{
    public string $id;
    public string $code;
    public string $ext;
    public mixed $uploaded_by;
    public int $created_at;
    public mixed $rating;
    public bool $is_in_user_set;
    public int $visibility;

    public string|null $source;

    public array $tags;

    function __construct($id, $code, $ext, $created_at, $uploaded_by, $is_in_user_set, $rating, $visibility, $source, $tags)
    {
        $this->id = $id;
        $this->code = $code;
        $this->ext = $ext;
        $this->created_at = $created_at;
        $this->uploaded_by = $uploaded_by;
        $this->is_in_user_set = $is_in_user_set;
        $this->rating = $rating;
        $this->visibility = $visibility;
        $this->source = $source;
        $this->tags = $tags;
    }

    function get_id()
    {
        return $this->id;
    }

    function get_code()
    {
        return $this->code;
    }

    function get_ext()
    {
        return $this->ext;
    }

    function get_created_at()
    {
        return $this->created_at;
    }

    function get_uploaded_by()
    {
        return $this->uploaded_by;
    }

    function is_added_by_user()
    {
        return $this->is_in_user_set;
    }

    function get_rating()
    {
        return $this->rating;
    }

    function get_visibility()
    {
        return $this->visibility;
    }

    function get_source()
    {
        return $this->source;
    }

    function get_tags(): array
    {
        return $this->tags;
    }
}

function html_random_emote(PDO &$db)
{
    $stmt = $db->prepare("SELECT id, code FROM emotes WHERE visibility = 1 ORDER BY RAND() LIMIT 1");
    $stmt->execute();

    if ($row = $stmt->fetch()) {
        echo ''
            ?>
        <section class="box" id="box-random-emote">
            <div class="box navtab">
                <p>Random emote</p>
            </div>
            <div class="box content center">
                <a href="/emotes?id=<?php echo $row["id"] ?>">
                    <img src="/static/userdata/emotes/<?php echo $row["id"] ?>/3x.webp" alt="<?php echo $row["code"] ?>"
                        width="192">
                </a>
            </div>
        </section>
        <?php
        ;
    }
}

function html_featured_emote(PDO &$db)
{
    $stmt = $db->prepare("SELECT e.id, e.code FROM emotes e
    INNER JOIN emote_sets es ON es.is_featured = TRUE
    INNER JOIN emote_set_contents esc ON es.id = esc.emote_set_id
    WHERE e.visibility = 1 AND e.id = esc.emote_id ORDER BY esc.added_at DESC LIMIT 1");
    $stmt->execute();

    if ($row = $stmt->fetch()) {
        echo ''
            ?>
        <section class="box" id="box-featured-emote">
            <div class="box navtab">
                <p>Featured emote</p>
            </div>
            <div class="box content center">
                <a href="/emotes?id=<?php echo $row["id"] ?>">
                    <img src="/static/userdata/emotes/<?php echo $row["id"] ?>/3x.webp" alt="<?php echo $row["code"] ?>"
                        width="192">
                </a>
            </div>
        </section>
        <?php
        ;
    }
}