summaryrefslogtreecommitdiff
path: root/src/emote.php
blob: ea9e52cf4636d82fea17a23aa2300460e9e9ace6 (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
<?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;

    function __construct($id, $code, $ext, $created_at, $uploaded_by, $is_in_user_set, $rating, $visibility)
    {
        $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;
    }

    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 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
        ;
    }
}