-
Notifications
You must be signed in to change notification settings - Fork 0
/
wcComment.php
executable file
·142 lines (125 loc) · 4.15 KB
/
wcComment.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
<?php
//! Commenting system class
/*!
functions for managing comments
*/
class wcComment
{
//!add a comment
static function add( $idnode, $idfile,$author, $authoremail, $comment, $language)
{
if(filter_var( $authoremail, FILTER_VALIDATE_EMAIL) )
{
$idnode = intval($idnode);
$idfile = intval($idfile);
if ( $idnode>= 0 )
{
if ( $idfile >= 0 )
{
$db = wcCore::getDatabaseHandle();
$temp = sprintf( "%d,%d,'%s','%s','%s','%s'" , $idnode, $idfile , htmlspecialchars ($author, ENT_QUOTES, 'UTF-8'), $authoremail , htmlspecialchars ($comment, ENT_QUOTES, 'UTF-8') , $language);
if ($db->queryInsert('Comments', 'idNode, idFile, author, email, comment, idLanguage', $temp)>0)
{
wcComment::updateNodeCommentsCount($idnode, $idfile);
return 0;
}
}
else
{
return 4;
}
}
else
{
return 3;
}
}
else
{
return 2;
}
return 1;
}
//!approve a comment
static function approve($idcomment)
{
}
//!disable a comment
static function disable($idcomment)
{
}
//!get a list of comments
static function fetch( $language, $idnode, $idfile=0, $page=0, $pageentries=10 )
{
$db = wcCore::getDatabaseHandle();
$idnode = intval($idnode);
$idfile = intval($idfile);
//echo "node: $idnode, $idfile<br />";
$language = filter_var($language, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
// echo "language: $language<br />";
if ( $idnode >= 0 )
{
if ( $idfile >= 0 )
{
$temp = sprintf( "idNode = %d and idFile = %d and idLanguage = '%s'" , $idnode, $idfile , $language );
// echo "$temp<br />";
return $db->querySelect('Comments', $temp);
}
}
return null;
}
//!get a specific comment
static function get($idcomment)
{
}
//!delete a comment
static function remove($idcomment)
{
}
static function updateNodeCommentsCount($idnode, $idfile)
{
$result = 0;
$db = wcCore::getDatabaseHandle();
$idnode = intval($idnode);
$idfile = intval($idfile);
$where = sprintf('idNode = %d and idFile = %d group by idNode,idFile', $idnode, $idfile);
$nodes = $db->querySelect('Comments', $where, 'idNode, idFile, count(idNode) kc','1');
$kn = count($nodes);
if ($kn > 0 ) //only process if the previous query returned something
{
if ($idfile == 0) //update node comment count
{
if ($db->queryUpdate('Nodes','countComment='.$nodes[0]['kc'], 'idNode = '.$nodes[0]['idNode']) > 0)
$result++;
}
else //update a specific file comment count
{
if ($db->queryUpdate('Files','countComment='.$nodes[0]['kc'], 'idNode = '.$nodes[0]['idNode']. ' and idFile='.$nodes[0]['idFile']) > 0)
$result++;
}
}
return $result;
}
static function updateAllCommentsCount()
{
$db = wcCore::getDatabaseHandle();
$nodes = $db->querySelect('Comments', '1 group by idNode,idFile','idNode, idFile, count(idNode) kc');
$kn = count($nodes);
$result = 0;
for ($k=0 ; $k < $kn; $k++)
{
if (intval($nodes[$k]['idFile'])==0)
{
if ($db->queryUpdate('Nodes','countComment='.$nodes[$k]['kc'], 'idNode = '.$nodes[$k]['idNode']) > 0)
$result++;
}
else
{
if ($db->queryUpdate('Files','countComment='.$nodes[$k]['kc'], 'idNode = '.$nodes[$k]['idNode']. ' and idFile='.$nodes[$k]['idFile']) > 0)
$result++;
}
}
return $result;
}
}
?>