Issues (46)

1
<?php require($_SERVER['DOCUMENT_ROOT'] . "/static/config.inc.php"); ?>
2
<?php require($_SERVER['DOCUMENT_ROOT'] . "/static/conn.php"); ?>
3
<?php require($_SERVER['DOCUMENT_ROOT'] . "/lib/profile.php"); ?>
4
<!DOCTYPE html>
5
<html>
6
<head>
7
    <link href="/static/css/required.css" rel="stylesheet">
8
    <title>Witter: What are you doing?</title>
9
    <script src='https://www.google.com/recaptcha/api.js' async defer></script>
10
    <?php $user = getUserFromName($_SESSION['siteusername'], $conn); ?>
11
    <script>function onLogin(token){ document.getElementById('submitform').submit(); }</script>
12
    <script src="/js/i-have-no-idea-what-to-name-this-file-and-it-doesnt-really-matter.js"></script>
13
</head>
14
<body id="front">
15
<div id="container">
16
    <?php require($_SERVER['DOCUMENT_ROOT'] . "/static/header.php");
17
    $stmt = $conn->prepare("SELECT banstatus FROM users WHERE username = ?");
18
    $stmt->bind_param("s", $username);
19
    $stmt->execute();
20
    $result = $stmt->get_result();
21
    $row = $result->fetch_assoc();
22
    if($_SERVER['REQUEST_METHOD'] == 'POST') {
23
        if($row['banstatus'] == 'suspended'){ $error = "you're suspended"; goto skipcomment; }
24
        if(!isset($_SESSION['siteusername'])){ $error = "you are not logged in"; goto skipcomment; }
25
        if(!$_POST['comment']){ $error = "your comment cannot be blank"; goto skipcomment; }
26
        if(strlen($_POST['comment']) > 500){ $error = "your comment must be shorter than 500 characters"; goto skipcomment; }
27
        if(!isset($_POST['g-recaptcha-response'])){ $error = "captcha validation failed"; goto skipcomment; }
28
        if(!validateCaptcha($config['recaptcha_secret'], $_POST['g-recaptcha-response'])) { $error = "captcha validation failed"; goto skipcomment; }
29
30
        $stmt = $conn->prepare("INSERT INTO `weets` (realid, author, contents) VALUES (?, ?, ?)");
31
        $stmt->bind_param("sss", $uniqid, $_SESSION['siteusername'], $text);
32
        $uniqid = time() . uniqid();
33
        $text = htmlspecialchars($_POST['comment']);
34
        $stmt->execute();
35
        $stmt->close();
36
        skipcomment:
37
    }
38
    ?>
39
    <div id="content">
40
        <?php if(!isset($_SESSION['siteusername'])) { ?>
41
            <div style="background-color: lightyellow;" class="wrapper">
42
                <big><big><big>Hey there! You arent logged in!</big></big></big><br>
43
                <img style="float: left; margin-right: 5px;" src="/static/girl.gif">Witter is a free service that lets you keep in touch with people through the exchange of quick, frequent answers to one simple question: What are you doing? Log in or register to post.
44
            </div><br><br><br><br><br><br>
45
        <?php } ?>
46
        <div class="wrapper">
47
            <?php if(isset($_SESSION['siteusername'])) { ?>
48
                <div class="customtopRight">
49
                    <img id="pfp" style="vertical-align: middle;" src="/dynamic/pfp/<?php echo $user['pfp']; ?>"> <b><big><big><?php echo $_SESSION['siteusername']; ?></big></big></b><br>
50
                    <table id="cols">
51
                        <tr>
52
                            <th style="width: 33%;">&nbsp;</th>
53
                            <th style="width: 33%;">&nbsp;</th>
54
                            <th style="width: 33%;">&nbsp;</th>
55
                        </tr>
56
                        <tr>
57
                            <td><big><big><big><b><?php echo getFollowing($_SESSION['siteusername'], $conn); ?></b></big></big></big><br><span id="blue">following</span></td>
58
                            <td><big><big><big><b><?php echo getFollowers($_SESSION['siteusername'], $conn); ?></b></big></big></big><br><span id="blue">followers</span></td>
59
                            <td><big><big><big><b><?php echo getWeets(rhandleTag($_SESSION['siteusername']), $conn); ?></b></big></big></big><br><span id="blue">weets</span></td>
60
                        </tr>
61
                    </table><br>
62
                    <?php require($_SERVER['DOCUMENT_ROOT'] . "/static/followRequire.php"); ?>
63
                    <div class="altbg">
64
                        <a href="/home.php">Home</a><br>
65
                        <a href="/pms.php">Private Messages [200]</a>
66
                    </div><br>
67
                    <div class="altbg">
68
                        <center><a href="https://discord.gg/J5ZDsak">Join the Discord server</a></center>
69
                    </div><br>
70
                </div>
71
            <?php } ?>
72
            <div class="customtopLeft">
73
                <big><big><big>What are you doing? </big></big></big> <?php if(isset($error)) { echo "<small style='color: red;'>" . $error . "</small>"; } ?> <span id="textlimit">0/500</span>
74
                <?php if($user['banstatus'] != "suspended" || isset($_SESSION['siteusername'])) { ?>
75
                    <form method="post" enctype="multipart/form-data" id="submitform">
76
                        <textarea cols="32" style="width: 534px;" id="upltx" name="comment"><?php if(isset($_GET['text'])) { echo $_GET['text']; } ?></textarea><br>
77
                        <script src="/js/commd.js"></script>
78
                        <input style="float: right; font-size: 1.2em; margin-top: 5px; margin-right: -6px;" type="submit" value="update" class="g-recaptcha" data-sitekey="<?php echo $config['recaptcha_sitekey']; ?>" data-callback="onLogin">
79
                    </form>
80
                <?php } else { ?>
81
                    <div style='padding: 5px; border: 5px solid green;'>
82
                        <h4 id='noMargin'>
83
                            You have been suspended or you are not logged in.
84
                        </h4>
85
                    </div>
86
                <?php } ?>
87
                <script src='/js/limit.js'></script><br>
88
                <?php if(!isset($_GET['page'])) { ?>
89
                    <table id="cols">
90
                        <tr>
91
                            <th style="width: 33%;">&nbsp;</th>
92
                            <th style="width: 33%;">&nbsp;</th>
93
                            <th style="width: 33%;">&nbsp;</th>
94
                        </tr>
95
                        <tr style="vertical-align: top;">
96
                            <td id="cBorder" <?php if(!isset($_GET['t'])) { ?> style="background-color: #F8F8F8; border-bottom: 1px dashed #333;" <?php } ?>><b><a id="blacklink" href="?t=latest">Latest</a></b></td>
97
                            <td id="cBorder" <?php if(isset($_GET['t']) && $_GET['t'] == "popular") { ?> style="background-color: #F8F8F8; border-bottom: 1px dashed #333;" <?php } ?>><b><a id="blacklink" href="?t=popular">Most Popular</a></b></td>
98
                            <td id="cBorder" <?php if(isset($_GET['t']) && $_GET['t'] == "oldest") { ?> style="background-color: #F8F8F8; border-bottom: 1px dashed #333;" <?php } ?>><b><a id="blacklink" href="?t=oldest">Oldest</a></b></td>
99
                        </tr>
100
                    </table><br>
101
                <?php } ?>
102
                <table id="feed">
103
                    <tr>
104
                        <th style="width: 48px;">&nbsp;</th>
105
                        <th>&nbsp;</th>
106
                    </tr>
107
                    <?php
108
                    $total_pages = $conn->query('SELECT COUNT(*) FROM weets')->fetch_row()[0];
109
                    $page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1;
110
                    $num_results_on_page = 16;
111
112
                    $stmt = $conn->prepare("SELECT * FROM weets ORDER BY id DESC LIMIT ?,?");
113
                    $calc_page = ($page - 1) * $num_results_on_page;
114
                    $stmt->bind_param('ii', $calc_page, $num_results_on_page);
115
                    $stmt->execute();
116
                    $result = $stmt->get_result();
117
118
                    while($row = $result->fetch_assoc()) { ?>
119
                        <tr>
120
                            <big><big><big>
121
                                        <td>
122
                                            <img id="pfp" src="/dynamic/pfp/<?php echo getPFPFromUser($row['author'], $conn); ?>">
123
                                        </td>
124
                                        <td><a id="tag" href="/u.php?n=<?php echo handleTag($row['author']); ?>"><?php echo($row['author']); ?></a>
125
                                            <?php if(returnVerifiedFromUsername($row['author'], $conn) != "") { ?> <span style="border-radius: 10px; background-color: deepskyblue; color: white; padding: 3px;"><?php echo(returnVerifiedFromUsername($row['author'], $conn)); ?></span> <?php } ?>
126
                                            <div id="floatRight" class="dropdown">
127
                                                <span><img style="vertical-align: middle;" src="/static/witter-dotdotdot.png"></span>
128
                                                <div class="dropdown-content">
129
                                                    <a href="#<?php //echo report.php?r=$row['realid']; ?>"><img style="vertical-align: middle;" src="/static/witter-report.png"></a><br>
130
                                                    <?php if(isset($_SESSION['siteusername']) && $row['author'] == $_SESSION['siteusername']) { ?>
131
                                                        <a href="/delete.php?rid=<?php echo $row['realid']; ?>"><img style="vertical-align: middle;" src="/static/witter-trash.png"></a><br>
132
                                                        <a href="/edit.php?rid=<?php echo $row['realid']; ?>"><img style="vertical-align: middle;" src="/static/witter-edit.png"></a><br>
133
                                                    <?php } ?>
134
                                                </div>
135
                                            </div>
136
                                            <span id="floatRight">
137
                                            <?php if(ifLiked($_SESSION['siteusername'], $row['id'], $conn) == true) { ?>
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
138
                                                <a href="#" onclick="unlike(<?=$row['id']?>)" id="like-toggle-<?=$row['id']?>"><img style="vertical-align: middle;" src="/static/witter-liked.png"></a>
139
                                            <?php } else { ?>
140
                                                <a href="#" onclick="like(<?=$row['id']?>)" id="like-toggle-<?=$row['id']?>"><img style="vertical-align: middle;" src="/static/witter-like.png"></a>
141
                                            <?php } ?>
142
                                        </span>
143
                                            <div id="feedtext"><?php echo parseText($row['contents']); ?> </div>
144
                                            <small id="grey">about <?php echo time_elapsed_string($row['date']); ?> from web
145
                                                <span id="floatRight">
146
                                                <?php echo getComments($row['realid'], $conn); ?><img style="vertical-align: middle;" src="/static/witter-replies.png"> &bull; <a href="/v.php?rid=<?php echo $row['realid']; ?>">Reply</a> &bull; <a href="/home.php?text=https://witter.spacemy.xyz/embed/?i=<?php echo $row['realid']; ?>">Reweet</a>
147
                                            </span>
148
                                            </small><br>
149
                                            <?php
150
                                            $likes = getLikesReal($row['id'], $conn);
151
                                            while($row = $likes->fetch_assoc()) {
152
                                                ?>
153
                                                <a href="/u.php?n=<?php echo handleTag($row['fromu']); ?>"><img style="width: 30px; height: 30px; margin-left: 2px;" id="pfp" src="/dynamic/pfp/<?php echo getPFPFromUser($row['fromu'], $conn); ?>"></a>&nbsp;
154
                                            <?php } ?>
155
                                        </td>
156
                                    </big></big></big>
157
                        </tr>
158
                        <?php
159
                    }
160
                    ?>
161
                </table>
162
                <center>
163
                    <?php if (ceil($total_pages / $num_results_on_page) > 0): ?>
164
                        <?php if ($page > 1): ?>
165
                            <a href="?page=<?php echo $page-1 ?>">Prev</a>
166
                        <?php endif; ?>
167
168
                        <?php if ($page > 3): ?>
169
                            <a href="?page=1">1</a>
170
                            ...
171
                        <?php endif; ?>
172
173
                        <?php if ($page-2 > 0): ?><a href="?page=<?php echo $page-2 ?>"><?php echo $page-2 ?></a><?php endif; ?>
174
                        <?php if ($page-1 > 0): ?><a href="?page=<?php echo $page-1 ?>"><?php echo $page-1 ?></a><?php endif; ?>
175
176
                        <a href="?page=<?php echo $page ?>"><?php echo $page ?></a>
177
178
                        <?php if ($page+1 < ceil($total_pages / $num_results_on_page)+1): ?><a href="?page=<?php echo $page+1 ?>"><?php echo $page+1 ?></a></li><?php endif; ?>
179
                        <?php if ($page+2 < ceil($total_pages / $num_results_on_page)+1): ?><a href="?page=<?php echo $page+2 ?>"><?php echo $page+2 ?></a></li><?php endif; ?>
180
181
                        <?php if ($page < ceil($total_pages / $num_results_on_page)-2): ?>
182
                            ...
183
                            <a href="?page=<?php echo ceil($total_pages / $num_results_on_page) ?>"><?php echo ceil($total_pages / $num_results_on_page) ?></a>
184
                        <?php endif; ?>
185
186
                        <?php if ($page < ceil($total_pages / $num_results_on_page)): ?>
187
                            <a href="?page=<?php echo $page+1 ?>">Next</a>
188
                        <?php endif; ?>
189
                    <?php endif; ?>
190
            </div>
191
            </center>
192
            <?php require($_SERVER['DOCUMENT_ROOT'] . "/static/footer.php"); ?>
193
        </div>
194
    </div>
195
</div>
196
</body>
197
</html>
198