1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2006-03-23 01:49:04 +0000 (Thu, 23 Mar 2006) $ |
---|
10 | // | last modifier : $Author: rvelices $ |
---|
11 | // | revision : $Revision: 1094 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | /** |
---|
29 | * This file is included by the picture page to manage user comments |
---|
30 | * |
---|
31 | */ |
---|
32 | |
---|
33 | if ( isset( $_POST['content'] ) and !empty($_POST['content']) ) |
---|
34 | { |
---|
35 | $register_comment = true; |
---|
36 | $author = !empty($_POST['author'])?$_POST['author']:$lang['guest']; |
---|
37 | // if a guest try to use the name of an already existing user, he must be |
---|
38 | // rejected |
---|
39 | if ( $author != $user['username'] ) |
---|
40 | { |
---|
41 | $query = 'SELECT COUNT(*) AS user_exists'; |
---|
42 | $query.= ' FROM '.USERS_TABLE; |
---|
43 | $query.= ' WHERE '.$conf['user_fields']['username']." = '".$author."'"; |
---|
44 | $query.= ';'; |
---|
45 | $row = mysql_fetch_array( pwg_query( $query ) ); |
---|
46 | if ( $row['user_exists'] == 1 ) |
---|
47 | { |
---|
48 | $template->assign_block_vars( |
---|
49 | 'information', |
---|
50 | array('INFORMATION'=>$lang['comment_user_exists'])); |
---|
51 | $register_comment = false; |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | if ( $register_comment ) |
---|
56 | { |
---|
57 | // anti-flood system |
---|
58 | $reference_date = time() - $conf['anti-flood_time']; |
---|
59 | $query = 'SELECT id FROM '.COMMENTS_TABLE; |
---|
60 | $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')'; |
---|
61 | $query.= " AND author = '".$author."'"; |
---|
62 | $query.= ';'; |
---|
63 | if ( mysql_num_rows( pwg_query( $query ) ) == 0 |
---|
64 | or $conf['anti-flood_time'] == 0 ) |
---|
65 | { |
---|
66 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
67 | |
---|
68 | $data = array(); |
---|
69 | $data{'author'} = $author; |
---|
70 | $data{'date'} = $dbnow; |
---|
71 | $data{'image_id'} = $page['image_id']; |
---|
72 | $data{'content'} = htmlspecialchars( $_POST['content'], ENT_QUOTES); |
---|
73 | |
---|
74 | if (!$conf['comments_validation'] or is_admin()) |
---|
75 | { |
---|
76 | $data{'validated'} = 'true'; |
---|
77 | $data{'validation_date'} = $dbnow; |
---|
78 | } |
---|
79 | else |
---|
80 | { |
---|
81 | $data{'validated'} = 'false'; |
---|
82 | } |
---|
83 | |
---|
84 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
85 | $fields = array('author', 'date', 'image_id', 'content', 'validated', |
---|
86 | 'validation_date'); |
---|
87 | mass_inserts(COMMENTS_TABLE, $fields, array($data)); |
---|
88 | |
---|
89 | // information message |
---|
90 | $message = $lang['comment_added']; |
---|
91 | |
---|
92 | if (!$conf['comments_validation'] or is_admin()) |
---|
93 | |
---|
94 | if ( $conf['comments_validation'] and !is_admin() ) |
---|
95 | { |
---|
96 | $message.= '<br />'.$lang['comment_to_validate']; |
---|
97 | } |
---|
98 | $template->assign_block_vars('information', |
---|
99 | array('INFORMATION'=>$message)); |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | // information message |
---|
104 | $template->assign_block_vars( |
---|
105 | 'information', |
---|
106 | array('INFORMATION'=>$lang['comment_anti-flood'])); |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | // the picture is commentable if it belongs at least to one category which |
---|
112 | // is commentable |
---|
113 | $page['show_comments'] = false; |
---|
114 | foreach ($related_categories as $category) |
---|
115 | { |
---|
116 | if ($category['commentable'] == 'true') |
---|
117 | { |
---|
118 | $page['show_comments'] = true; |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | if ($page['show_comments']) |
---|
123 | { |
---|
124 | // number of comment for this picture |
---|
125 | $query = 'SELECT COUNT(*) AS nb_comments'; |
---|
126 | $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$page['image_id']; |
---|
127 | $query.= " AND validated = 'true'"; |
---|
128 | $query.= ';'; |
---|
129 | $row = mysql_fetch_array( pwg_query( $query ) ); |
---|
130 | |
---|
131 | // navigation bar creation |
---|
132 | if (!isset($page['start'])) |
---|
133 | { |
---|
134 | $page['start'] = 0; |
---|
135 | } |
---|
136 | |
---|
137 | $page['navigation_bar'] = create_navigation_bar( |
---|
138 | duplicate_picture_URL(array(), array('start')), |
---|
139 | $row['nb_comments'], |
---|
140 | $page['start'], |
---|
141 | $conf['nb_comment_page'], |
---|
142 | true // We want a clean URL |
---|
143 | ); |
---|
144 | |
---|
145 | $template->assign_block_vars( |
---|
146 | 'comments', |
---|
147 | array( |
---|
148 | 'NB_COMMENT' => $row['nb_comments'], |
---|
149 | 'NAV_BAR' => $page['navigation_bar'], |
---|
150 | ) |
---|
151 | ); |
---|
152 | |
---|
153 | if ($row['nb_comments'] > 0) |
---|
154 | { |
---|
155 | $query = ' |
---|
156 | SELECT id,author,date,image_id,content |
---|
157 | FROM '.COMMENTS_TABLE.' |
---|
158 | WHERE image_id = '.$page['image_id'].' |
---|
159 | AND validated = \'true\' |
---|
160 | ORDER BY date ASC |
---|
161 | LIMIT '.$page['start'].', '.$conf['nb_comment_page'].' |
---|
162 | ;'; |
---|
163 | $result = pwg_query( $query ); |
---|
164 | |
---|
165 | while ($row = mysql_fetch_array($result)) |
---|
166 | { |
---|
167 | $template->assign_block_vars( |
---|
168 | 'comments.comment', |
---|
169 | array( |
---|
170 | 'COMMENT_AUTHOR' => empty($row['author']) |
---|
171 | ? $lang['guest'] |
---|
172 | : $row['author'], |
---|
173 | |
---|
174 | 'COMMENT_DATE' => format_date( |
---|
175 | $row['date'], |
---|
176 | 'mysql_datetime', |
---|
177 | true), |
---|
178 | |
---|
179 | 'COMMENT' => parse_comment_content($row['content']), |
---|
180 | ) |
---|
181 | ); |
---|
182 | |
---|
183 | if (is_admin()) |
---|
184 | { |
---|
185 | $template->assign_block_vars( |
---|
186 | 'comments.comment.delete', |
---|
187 | array( |
---|
188 | 'U_COMMENT_DELETE' => |
---|
189 | add_url_params( |
---|
190 | $url_self, |
---|
191 | array( |
---|
192 | 'action'=>'delete_comment', |
---|
193 | 'comment_to_delete'=>$row['id'] |
---|
194 | ) |
---|
195 | ) |
---|
196 | ) |
---|
197 | ); |
---|
198 | } |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | if (!$user['is_the_guest'] |
---|
203 | or ($user['is_the_guest'] and $conf['comments_forall'])) |
---|
204 | { |
---|
205 | $template->assign_block_vars('comments.add_comment', array()); |
---|
206 | // display author field if the user is not logged in |
---|
207 | if (!$user['is_the_guest']) |
---|
208 | { |
---|
209 | $template->assign_block_vars( |
---|
210 | 'comments.add_comment.author_known', |
---|
211 | array('KNOWN_AUTHOR'=>$user['username']) |
---|
212 | ); |
---|
213 | } |
---|
214 | else |
---|
215 | { |
---|
216 | $template->assign_block_vars( |
---|
217 | 'comments.add_comment.author_field', array() |
---|
218 | ); |
---|
219 | } |
---|
220 | } |
---|
221 | } |
---|
222 | |
---|
223 | ?> |
---|