typicalname0 /
4grounds
| 1 | <script type='text/javascript' src='//www.midijs.net/lib/midi.js'></script> |
||
| 2 | <?php |
||
| 3 | require(__DIR__ . "/../vendor/autoload.php"); |
||
| 4 | |||
| 5 | define("DEBUG_MODE", true); |
||
| 6 | session_start(); |
||
| 7 | if(defined("DEBUG_MODE") && DEBUG_MODE) { |
||
| 8 | ini_set('display_errors', 1); |
||
| 9 | ini_set('display_startup_errors', 1); |
||
| 10 | error_reporting(E_ALL); |
||
| 11 | } |
||
| 12 | |||
| 13 | function validateCSS($validate) { |
||
| 14 | $DISALLOWED = array("<?php", "?>", "behavior: url", ".php", "@import", "@\import", "@/import"); |
||
| 15 | |||
| 16 | $validated = str_replace($DISALLOWED, "", $validate); |
||
| 17 | return $validated; |
||
| 18 | } |
||
| 19 | function validateMarkdown($comment, $type = "comment") { |
||
| 20 | $comment = htmlspecialchars($comment); |
||
| 21 | $Parsedown = new Parsedown(); |
||
| 22 | $Parsedown->setSafeMode(true); |
||
| 23 | |||
| 24 | if ($type === "profile") { |
||
| 25 | return $Parsedown->parse($comment); |
||
| 26 | } else { |
||
| 27 | return $Parsedown->line($comment); |
||
| 28 | } |
||
| 29 | } |
||
| 30 | |||
| 31 | |||
| 32 | function validateCaptcha($privatekey, $response) { |
||
| 33 | $responseData = json_decode(file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$privatekey.'&response='.$response)); |
||
| 34 | return $responseData->success; |
||
| 35 | } |
||
| 36 | |||
| 37 | function requireLogin() { |
||
| 38 | if (!isset($_SESSION['user'])) { |
||
| 39 | header("Location: /login.php?r_login"); die(); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | function getGroup($id, $conn) { |
||
| 44 | $stmt = $conn->prepare("SELECT * FROM `groups` WHERE `id` = ?"); |
||
| 45 | $stmt->bind_param("i", $id); |
||
| 46 | $stmt->execute(); |
||
| 47 | $result = $stmt->get_result(); |
||
| 48 | if ($result->num_rows === 0) return 'error'; |
||
| 49 | return $result->fetch_assoc(); |
||
| 50 | } |
||
| 51 | |||
| 52 | function getID($user, $connection) { |
||
| 53 | $stmt = $connection->prepare("SELECT * FROM users WHERE username = ?"); |
||
| 54 | $stmt->bind_param("s", $user); |
||
| 55 | $stmt->execute(); |
||
| 56 | $result = $stmt->get_result(); |
||
| 57 | if($result->num_rows === 0) return 'error'; |
||
| 58 | while($row = $result->fetch_assoc()) { |
||
| 59 | $id = $row['id']; |
||
| 60 | } |
||
| 61 | $stmt->close(); |
||
| 62 | return $id; |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 63 | } |
||
| 64 | |||
| 65 | function getName($id, $connection) { |
||
| 66 | $stmt = $connection->prepare("SELECT * FROM users WHERE id = ?"); |
||
| 67 | $stmt->bind_param("s", $id); |
||
| 68 | $stmt->execute(); |
||
| 69 | $result = $stmt->get_result(); |
||
| 70 | if($result->num_rows === 0) return('error'); |
||
| 71 | while($row = $result->fetch_assoc()) { |
||
| 72 | $name = htmlspecialchars($row['username']); |
||
| 73 | } |
||
| 74 | $stmt->close(); |
||
| 75 | return $name; |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 76 | } |
||
| 77 | |||
| 78 | function getPFP($user, $connection) { |
||
| 79 | $stmt = $connection->prepare("SELECT * FROM users WHERE username = ?"); |
||
| 80 | $stmt->bind_param("s", $user); |
||
| 81 | $stmt->execute(); |
||
| 82 | $result = $stmt->get_result(); |
||
| 83 | if($result->num_rows === 0) return('error'); |
||
| 84 | while($row = $result->fetch_assoc()) { |
||
| 85 | $pfp = htmlspecialchars($row['pfp']); |
||
| 86 | } |
||
| 87 | $stmt->close(); |
||
| 88 | return $pfp; |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 89 | } |
||
| 90 | |||
| 91 | function checkIfFriended($friend1, $friend2, $connection) |
||
| 92 | { |
||
| 93 | $stmt = $connection->prepare("SELECT * FROM `friends` WHERE reciever = ? AND sender = ? OR reciever = ? AND sender = ?"); |
||
| 94 | $stmt->bind_param("ssss", $friend1, $friend2, $friend2, $friend1); |
||
| 95 | $stmt->execute(); |
||
| 96 | $result = $stmt->get_result(); |
||
| 97 | if($result->num_rows === 1){ return true; } |
||
| 98 | return false; |
||
| 99 | } |
||
| 100 | |||
| 101 | function isAdmin($user, $conn) { |
||
| 102 | $stmt = $conn->prepare("SELECT * FROM users WHERE username = ?"); |
||
| 103 | $stmt->bind_param("s", $user); |
||
| 104 | $stmt->execute(); |
||
| 105 | $result = $stmt->get_result(); |
||
| 106 | if($result->num_rows === 0) return false; |
||
| 107 | while($row = $result->fetch_assoc()) { |
||
| 108 | if($row['rank'] == "Admin" || $row['rank'] == "Owner") { |
||
| 109 | return true; |
||
| 110 | } else { |
||
| 111 | return false; |
||
| 112 | } |
||
| 113 | } |
||
| 114 | $stmt->close(); |
||
| 115 | } |
||
| 116 | |||
| 117 | function getUser($id, $connection) { |
||
| 118 | $userResult = array(); |
||
| 119 | $stmt = $connection->prepare("SELECT * FROM users WHERE id = ?"); |
||
| 120 | $stmt->bind_param("i", $id); |
||
| 121 | $stmt->execute(); |
||
| 122 | $result = $stmt->get_result(); |
||
| 123 | if($result->num_rows === 0) echo('That user does not exist.'); |
||
| 124 | while($row = $result->fetch_assoc()) { |
||
| 125 | $userResult['username'] = $row['username']; |
||
| 126 | $userResult['id'] = $row['id']; |
||
| 127 | $userResult['date'] = $row['date']; |
||
| 128 | $userResult['bio'] = $row['bio']; |
||
| 129 | $userResult['css'] = $row['css']; |
||
| 130 | $userResult['pfp'] = $row['pfp']; |
||
| 131 | $userResult['badges'] = explode(';', $row['badges']); |
||
| 132 | $userResult['music'] = $row['music']; |
||
| 133 | $userResult['rank'] = $row['rank']; |
||
| 134 | $userResult['currentgroup'] = $row['currentgroup']; |
||
| 135 | } |
||
| 136 | $stmt->close(); |
||
| 137 | |||
| 138 | $stmt = $connection->prepare("SELECT * FROM gamecomments WHERE author = ?"); |
||
| 139 | $stmt->bind_param("s", $userResult['username']); |
||
| 140 | $stmt->execute(); |
||
| 141 | $result = $stmt->get_result(); |
||
| 142 | |||
| 143 | $userResult['comments'] = 0; |
||
| 144 | while($row = $result->fetch_assoc()) { |
||
|
0 ignored issues
–
show
|
|||
| 145 | $userResult['comments']++; |
||
| 146 | } |
||
| 147 | $stmt->close(); |
||
| 148 | |||
| 149 | $stmt = $connection->prepare("SELECT * FROM comments WHERE author = ?"); |
||
| 150 | $stmt->bind_param("s", $userResult['username']); |
||
| 151 | $stmt->execute(); |
||
| 152 | $result = $stmt->get_result(); |
||
| 153 | |||
| 154 | $userResult['profilecomments'] = 0; |
||
| 155 | while($row = $result->fetch_assoc()) { |
||
| 156 | $userResult['profilecomments']++; |
||
| 157 | } |
||
| 158 | $stmt->close(); |
||
| 159 | |||
| 160 | $stmt = $connection->prepare("SELECT * FROM files WHERE author = ? AND status='y'"); |
||
| 161 | $stmt->bind_param("s", $userResult['username']); |
||
| 162 | $stmt->execute(); |
||
| 163 | $result = $stmt->get_result(); |
||
| 164 | |||
| 165 | $userResult['filesuploaded'] = 0; |
||
| 166 | while($row = $result->fetch_assoc()) { |
||
| 167 | $userResult['filesuploaded']++; |
||
| 168 | } |
||
| 169 | $stmt->close(); |
||
| 170 | return $userResult; |
||
| 171 | } |
||
| 172 | ?> |