/
api.php
102 lines (77 loc) · 2.13 KB
/
api.php
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
<?php
//see http://php.net/manual/en/function.call-user-func-array.php how to use extensively
// if(isset($_GET['runFunction']) && function_exists($_GET['runFunction']))
// call_user_func($_GET['runFunction']);
// else
// echo "Function not found or wrong input";
$person = $_POST["message"] . "\n";
$messages = explode(" ", $person);
// Write the contents to the file,
// using the FILE_APPEND flag to append the content to the end of the file
// and the LOCK_EX flag to prevent anyone else writing to the file at the same time
// function test()
// {
// echo("test");
// }
//
// function submitMessage()
// {
// }
$harassmentMultiplier;
$bad_words_mild = array();
$bad_words_medium = array();
$bad_words_harsh = array();
$filename = 'badWordsMild.txt';
$myfile = fopen($filename, "r");
while(!feof($myfile)) {
// echo fgets($myfile) . "<br>";
$bad_words_mild[] = fgets($myfile);
}
fclose($myfile);
$filename = 'badWordsMedium.txt';
$myfile = fopen($filename, "r");
while(!feof($myfile)) {
// echo fgets($myfile) . "<br>";
$bad_words_medium[] = fgets($myfile);
}
fclose($myfile);
$filename = 'badWordsHarsh.txt';
$myfile = fopen($filename, "r");
while(!feof($myfile)) {
// echo fgets($myfile) . "<br>";
$bad_words_harsh[] = fgets($myfile);
}
fclose($myfile);
foreach ($messages as $word) {
if(isset($word) && $word !== '') {
foreach ($bad_words_mild as $badWord) {
if (trim($word) === trim($badWord)) {
$harassmentMultiplier = $harassmentMultiplier + 3;
}
}
}
}
foreach ($messages as $word) {
if(isset($word) && $word !== '') {
foreach ($bad_words_medium as $badWord) {
if (trim($word) === trim($badWord)) {
$harassmentMultiplier = $harassmentMultiplier + 6;
}
}
}
}
foreach ($messages as $word) {
if(isset($word) && $word !== '') {
foreach ($bad_words_harsh as $badWord) {
if (trim($word) === trim($badWord)) {
$harassmentMultiplier = $harassmentMultiplier + 9;
}
}
}
}
echo $harassmentMultiplier * 3;
if ($harassmentMultiplier < 8) {
$filename = 'sub.txt';
file_put_contents($filename, $person, FILE_APPEND | LOCK_EX);
}
?>