-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommentdb.php
More file actions
242 lines (192 loc) · 7.81 KB
/
commentdb.php
File metadata and controls
242 lines (192 loc) · 7.81 KB
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of commentdb
*
* @author Yasha
*/
session_start();
include '../db/dbConnector.php';
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
class usefultools{
static function checkquery($result)
{
if($result)
{
echo "else";
}
else
{
header("HTTP/1.0 404 Not Found");
header('HTTP', true, 500);
die("Error");
}
}
}
class commentdb {
protected $dbcach;
protected $articleid;
protected $username;
function __construct($articleid, $username)
{
$this->articleid=$articleid;
$this->username=$username;
$this->dbcach=new DbConnector();
}
}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
class commentinsert extends commentdb
{
protected $content;
function __construct($articleid, $username, $content)
{
parent::__construct($articleid, $username);
$this->content=$content;
}
public function insertanalysis()
{
$m=$this->dbcach->query("insert into analysis(analysis_content, article_id, username, date_added) values('$this->content',$this->articleid,'$this->username',now())");
trigger::action("users","score=score+0.25, analysispost=analysispost+1","username=".$this->username );
}
public function insertcomment()
{
$m=$this->dbcach->query("insert into comments(Comment_content, article_id, username, date_added) values('$this->content',$this->articleid,'$this->username',now())");
}
}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
class commentreplyinsert extends commentinsert
{
private $commentid;
function __construct($articleid, $username, $content, $commentid)
{
parent::__construct($articleid, $username, $content);
$this->commentid=$commentid;
}
//insert comment reply
public function insertcommentreply()
{
$m= $this->dbcach->query("insert into comments(Comment_content, article_id, username, date_added, reply) values('$this->content',$this->articleid,'$this->username',now(),$this->commentid)");
// $m= $this->dbcach->query("insert into replyto(comment_id, response_id) values('$this->content',$this->articleid,'$this->username',now(),$this->commentid)");
}
}
//////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
class feedbackanalysis extends commentdb
{
private $comment_id;
function __construct($articleid, $username, $comment_id) {
parent::__construct($articleid, $username);
$this->comment_id=$comment_id;
}
public function voteups()
{
$m= $this->dbcach->query("insert into analysisvoteups(analysis_id, username) values ($this->comment_id,'$this->username') ");
if($m){$this->dbcach->query("update analysis set voteups=voteups+1 where analysis_id= $this->comment_id ");
}else {
usefultools::checkquery($m);
}
}}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
class feedbackcomment extends commentdb
{
private $comment_id;
function __construct($articleid, $username, $comment_id) {
parent::__construct($articleid, $username);
$this->comment_id=$comment_id;
}
public function thumbedup()
{
$m= $this->dbcach->query("insert into comment_votes(comment_id, username, votetype) values ($this->comment_id,'$this->username',1) ");
if($m) $this->dbcach->query("update comments set feedbacksum=feedbacksum+1 where comment_id= $this->comment_id ");
else{
usefultools::checkquery($m);
}
}
public function thumbeddown()
{
$m= $this->dbcach->query("insert into comment_votes(comment_id, username, votetype) values ($this->comment_id,'$this->username',2) ");
if($m)$this->dbcach->query("update comments set feedbacksum=feedbacksum-1 where comment_id= $this->comment_id ");
else {
usefultools::checkquery($m);
}
}
}
class admincomment{
private $commentid;
private $dbcach;
public function __construct($commentid) {
$this->commentid=$commentid;
$this->dbcach=new DbConnector();
}
public function update($content)
{
$m=$this->dbcach->query(" update comments set comment_content='$content' where comment_id=$this->commentid");
}
public function report($reason,$username)
{
$m= $this->dbcach->query(" insert into complain (complain_category, reasons, complained_content_id, username,date_added) values('comments','$reason',$this->commentid,' $username',now())");
usefultools::checkquery($m);
}
function delete()
{
$this->dbcach->query(" delete from comments where comment_id=$this->commentid");
}}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
$id=$_POST['id'];
$contentcomment=$_POST['content'];
$commentid=$_POST['commentid'];
$command=$_POST['command'];
$username=$_SESSION['username'];
//$cdb=new commentdb($id, $user);
//
//$cdb->insertcomment();
//switch($command)
//{
//
// case "thumbsup":feedbackcomment($id, $user, $commentid)->thumbedup(); break;
// case "thumbsdown":feedbackcomment($id, $user, $commentid)->thumbeddown();break;
// case "insertcomment":commentinsert($id, $user, $contentcomment)->insertcomment();break;
// case "insertanalysis":commentinsert($id, $user, $contentcomment)->insertcomment();break;
// case "analysis voteups":commentinsert($id, $user, $contentcomment)->insertcomment();break;
// case "insercommentreply":commentreplyinsert($id, $user, $contentcomment,$commentid)->insertcomment();break;
//
//}
//
$m;
if($command=="thumbsup"){
$c=new feedbackcomment($id,$username,$commentid);
$c->thumbedup();}
else if($command=="thumbsdown"){
$c=new feedbackcomment($id,$username,$commentid);
$c->thumbeddown();}
else if($command=="insertcomment"){
$c=new commentinsert($id,$username, $contentcomment);
$c->insertcomment();}
else if($command=="voteups"){
$c=new feedbackanalysis($id, $username, $commentid);
$c->voteups(); }
else if($command=="insertcommentreply"){
$c=new commentreplyinsert($id,$username, $contentcomment,$commentid);
$c->insertcommentreply();}
else if($command=="report"){
$c=new admincomment($commentid);
$m=$c->report($contentcomment,$username);}
else if($command=="deletecomment"){
$c=new admincomment($commentid);
$m=$c->delete();}
else if($command=="insertanalysis"){
$c=new commentinsert($id,$username, $contentcomment);
$m=$c->insertanalysis();}
else if($command=="updatecomment"){
$c=new admincomment($commentid);
$m=$c->update($contentcomment);}
//$cdb->thumbedup();
?>