-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_comment_backup.php
104 lines (84 loc) · 2.64 KB
/
add_comment_backup.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
103
104
<?php
//add_comment.php
$connect = new PDO('mysql:host=localhost;dbname=discnet', 'root', '');
$error = '';
$comment_name = '';
$comment_content = '';
$badwords=['aaa','idiot','shit'];
if(empty($_POST["comment_name"]))
{
$error .= '<p class="text-danger">Name is required</p>';
}
else
{
$comment_name = $_POST["comment_name"];
}
if(empty($_POST["comment_content"]))
{
$error .= '<p class="text-danger">Comment is required</p>';
}
else
{
$comment_content = $_POST["comment_content"];
$string_to_array= explode(" ", $comment_content);
// echo '<pre>' . print_r($string_to_array, TRUE) . '</pre>';
foreach ($string_to_array as $word)
{
// $sql="SELECT * FROM `badwords` WHERE `words` LIKE '$word'";
// $result=mysqli_query($conn,$sql);
// $query = mysqli_query("SELECT * FROM `badwords` WHERE `words` LIKE '$word'");
// while($row = mysqli_fetch_array($result))
// {
$arr=array();
foreach ($badwords as $i)
{
if ($i==$word)
{
array_push($arr,$i);
}
}
foreach ($arr as $w)
{
$word_found = $w;
$new_word = preg_replace('/(?!^.?).(?!.{0}$)/', '*', $word_found);
$key = array_search($word_found,$string_to_array);
$length = strlen($word_found)-1;
$replace = array($key => $new_word);
$string_to_array = array_replace($string_to_array,$replace);
}
// }
}
$new_string = implode(" ", $string_to_array);
$comment_content= $new_string;
}
if($error == '')
{
$query = "INSERT INTO tbl_comment (parent_comment_id, comment, comment_sender_name, post_id) VALUES (:parent_comment_id, :comment, :comment_sender_name,:post_id)
";
$statement = $connect->prepare($query);
$statement->execute(
array(
':parent_comment_id' => $_POST["comment_id"],
':comment' => $comment_content,
':comment_sender_name' => $comment_name,
':post_id' => $_POST['post_id']
)
);
$error = '
<script>
window.scrollTo(0, 0);
function timeRefresh(timeoutPeriod) {
setTimeout("location.reload(true);", timeoutPeriod);
}
timeRefresh(5000);
</script>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>'.$comment_content.'</strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
$data = array(
'error' => $error
);
echo json_encode($data);
?>