-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment-submit.php
197 lines (143 loc) · 3.48 KB
/
comment-submit.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/*
* Comment submit
* Submit comment progress , submit comment and
* redirect to post
*
* Borno CMS
*
*
*/
/*
* include the function file
*/
require('functions.php');
require_once('include/function/load-plugin.php');
/*
* Check http referer
*/
if(!isset($_SERVER['HTTP_REFERER'])){
borno_die('Why are you trying this? You have invalid refer.'); //die
}
if(!isset($_POST['CSRFToken']) or $_POST['CSRFToken']!=loginuserinfo('active_key')){
borno_die( 'Maybe someone is trying to access this page!');
}
/*
*
* if not isset $_POST[comment,content,post_id] than die()
*
*/
if(!isset($_POST['comment']) or !isset ($_POST['content']) or !isset($_POST['post_id']) or empty($_POST['content'])){
borno_die('You can not submit a blank comment');//die
}
/*
*
*
* if isset invalid post_number than die()
*
*
* @see : http://bd1.php.net/manual/en/function.filter-var.php
*/
$int_options = array("options"=>array("min_range"=>1));//option of min range for that user not insert -1,-2... post number
if(!filter_var($_POST['post_id'], FILTER_VALIDATE_INT, $int_options)){
borno_die('Oh, the system think you have changed the post id.');//die
}
/*
*
*
* check if the content exists in that id
* is_exists_content()
*/
if(!is_exists_content($_POST['post_id'])){
borno_die('No content exists on this id number. Invalid action.');//die
}
/*
*
*
* make sure that comment is open on that post
* get_the_post($post_id,$thefieldthatyouwanttoget)
*/
if(!get_the_post($_POST['post_id'],'comment_permission')=='true'){
borno_die('You can not comment here.');//die
}
/*
*
* user_can(); //check user role
* if user can not add comment than die();
*
*
*
*
*/
if(!user_can('add_comment')){
borno_die('You can not add any comment');//die
}
/*
* Check big ammount comment
*
*/
if(isset($_SESSION['cmntcnt']) and isset($_SESSION['cmnttme'])){
if($_SESSION['cmntcnt']<10){
$_SESSION['cmntcnt'] ++;
}else{
if((time()-$_SESSION['cmnttme'])>60){
unset($_SESSION['cmnttme']);
unset($_SESSION['cmntcnt']);
}else{
borno_die('You can do only ten comment in a minute.');
}
}
}else{
$_SESSION['cmntcnt'] = 1;
$_SESSION['cmnttme'] = time();
}
/*
*
*
* adding comment
* @packge : Borno CMS
* add_comment($user_id,$post_id,$content,$approved)
*/
/*
*
* @variables
*
*/
$approved='publish';//for this time approve is true
$content =htmlspecialchars($_POST['content']);// content
$post_id =$_POST['post_id'];//post id
$user_id =loginuserinfo('id');//user id
/*
* check content is not empty
*
*
*
*/
$c_content = trim($content);
if(empty($c_content)){
borno_die("You can not add a blank comment");//die();
}
/*
//currently disable , if need please enable it
//it stop duplicate comment
$query = borno_query("SELECT * FROM prefix_comment WHERE post_id=$post_id and content = '$content' and status='publish'");
if(mysqli_num_rows($query)!=0){
borno_die('You can not do a duplicate comment');
}
*/
/*
* add comment
* add_comment()
*/
$add_c =add_comment($user_id,$post_id,$content,$approved);//add comment
if($add_c){
$c_id = $add_c;
}
/*
*
*
* Comment notification progress
*
*/
comment_notification($post_id,$user_id,$content);
header("Location:".the_post_link($post_id,false)."#comment-$c_id"); // redirect to post page