Passed
Push — master ( bb183a...de3467 )
by
unknown
01:51
created

validateCaptcha()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<script type='text/javascript' src='//www.midijs.net/lib/midi.js'></script>
2
<?php
3
require(__DIR__ . "/bbcode.php");
4
require(__DIR__ . "/../vendor/autoload.php");
5
6
define("DEBUG_MODE", true);
7
session_start();
8
if(isset(DEBUG_MODE) && DEBUG_MODE) {
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected ')', expecting '[' on line 8 at column 19
Loading history...
9
    ini_set('display_errors', 1);
10
    ini_set('display_startup_errors', 1);
11
    error_reporting(E_ALL);
12
}
13
14
function validateCSS($validate) {
15
	$DISALLOWED = array("<?php", "?>", "behavior: url", ".php", "@import", "@\import", "@/import"); 
16
17
	$validated = str_replace($DISALLOWED, "", $validate);
18
    return $validated;
19
}
20
function validateMarkdown($comment) {
21
	$markdown = new Michelf\Markdown;
22
	$markdown->no_markup = true;
23
	$transformed = $markdown->transform($comment);
24
	return preg_replace(
25
		"/<a href=(?:'|\")javascript:(.*?)(?:'|\")>(.*?)<\/a>/i",
26
		"Attempted XSS: $2 ($1)",
27
		$transformed
28
	);
29
}
30
31
function validateCaptcha($privatekey, $response) {
32
	$responseData = json_decode(file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$privatekey.'&response='.$response));
33
	return $responseData->success;
34
}
35
36
function requireLogin() {
37
	if (!isset($_SESSION['user'])) {
38
		header("Location: /login.php?r_login"); die();
39
	}
40
}
41
42
function getID($user, $connection) {
43
	$stmt = $connection->prepare("SELECT * FROM users WHERE username = ?");
44
	$stmt->bind_param("s", $user);
45
	$stmt->execute();
46
	$result = $stmt->get_result();
47
	if($result->num_rows === 0) return 'error';
48
	while($row = $result->fetch_assoc()) {
49
		$id = $row['id'];
50
	} 
51
	$stmt->close();
52
	return $id;
53
}
54
55
function getName($id, $connection) {
56
	$stmt = $connection->prepare("SELECT * FROM users WHERE id = ?");
57
	$stmt->bind_param("s", $id);
58
	$stmt->execute();
59
	$result = $stmt->get_result();
60
	if($result->num_rows === 0) return('error');
61
	while($row = $result->fetch_assoc()) {
62
		$name = htmlspecialchars($row['username']);
63
	} 
64
	$stmt->close();
65
	return $name;
66
}
67
68
function getPFP($user, $connection) {
69
	$stmt = $connection->prepare("SELECT * FROM users WHERE username = ?");
70
	$stmt->bind_param("s", $user);
71
	$stmt->execute();
72
	$result = $stmt->get_result();
73
	if($result->num_rows === 0) return('error');
74
	while($row = $result->fetch_assoc()) {
75
		$pfp = htmlspecialchars($row['pfp']);
76
	} 
77
	$stmt->close();
78
	return $pfp;
79
}
80
81
function checkIfFriended($friend1, $friend2, $connection)
82
{
83
	$stmt = $connection->prepare("SELECT * FROM `friends` WHERE reciever = ? AND sender = ? OR reciever = ? AND sender = ?");
84
	$stmt->bind_param("ssss", $friend1, $friend2, $friend2, $friend1);
85
	$stmt->execute();
86
	$result = $stmt->get_result();
87
	if($result->num_rows === 1){ return true; }
88
	return false;
89
}
90
91
function getUser($id, $connection) {
92
	$stmt = $connection->prepare("SELECT * FROM users WHERE id = ?");
93
	$stmt->bind_param("i", $id);
94
	$stmt->execute();
95
	$result = $stmt->get_result();
96
	if($result->num_rows === 0) echo('That user does not exist.');
97
	while($row = $result->fetch_assoc()) {
98
		$username = $row['username'];
99
		$id = $row['id'];
100
		$date = $row['date'];
101
		$bio = $row['bio'];
102
		$css = $row['css'];
103
		$pfp = $row['pfp'];
104
		$badges = explode(';', $row['badges']);
105
		$music = $row['music'];
106
	}
107
	$stmt->close();
108
109
	$stmt = $connection->prepare("SELECT * FROM gamecomments WHERE author = ?");
110
	$stmt->bind_param("s", $username);
111
	$stmt->execute();
112
	$result = $stmt->get_result();
113
114
	$comments = 0;
115
	while($row = $result->fetch_assoc()) {
116
		$comments++;
117
	}
118
	$stmt->close();
119
120
	$stmt = $connection->prepare("SELECT * FROM comments WHERE author = ?");
121
	$stmt->bind_param("s", $username);
122
	$stmt->execute();
123
	$result = $stmt->get_result();
124
125
	$profilecomments = 0;
126
	while($row = $result->fetch_assoc()) {
127
		$profilecomments++;
128
	}
129
	$stmt->close();
130
131
	$stmt = $connection->prepare("SELECT * FROM files WHERE author = ? AND status='y'");
132
	$stmt->bind_param("s", $username);
133
	$stmt->execute();
134
	$result = $stmt->get_result();
135
136
	$filesuploaded = 0;
137
	while($row = $result->fetch_assoc()) {
138
		$filesuploaded++;
139
	}
140
	$stmt->close();
141
}
142
?>