1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * comments.php * |
---|
4 | * ------------------- * |
---|
5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
7 | * * |
---|
8 | * $Id: comments.php 276 2004-01-12 23:41:53Z gweltas $ |
---|
9 | * * |
---|
10 | ***************************************************************************/ |
---|
11 | |
---|
12 | /*************************************************************************** |
---|
13 | * * |
---|
14 | * This program is free software; you can redistribute it and/or modify * |
---|
15 | * it under the terms of the GNU General Public License as published by * |
---|
16 | * the Free Software Foundation; * |
---|
17 | * * |
---|
18 | ***************************************************************************/ |
---|
19 | include_once( './include/isadmin.inc.php' ); |
---|
20 | $page['plain_structure'] = get_plain_structure(); |
---|
21 | //------------------------------------------------------------------- functions |
---|
22 | function display_pictures( $mysql_result, $maxtime, $validation_box = false ) |
---|
23 | { |
---|
24 | global $vtp,$sub,$lang,$conf, |
---|
25 | $array_cat_directories,$array_cat_site_id,$array_cat_names; |
---|
26 | |
---|
27 | while ( $row = mysql_fetch_array( $mysql_result ) ) |
---|
28 | { |
---|
29 | $vtp->addSession( $sub, 'picture' ); |
---|
30 | // 2. for each picture, getting informations for displaying thumbnail and |
---|
31 | // link to the full size picture |
---|
32 | $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext'; |
---|
33 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
34 | $query.= ' WHERE id = '.$row['image_id']; |
---|
35 | $query.= ';'; |
---|
36 | $subresult = mysql_query( $query ); |
---|
37 | $subrow = mysql_fetch_array( $subresult ); |
---|
38 | |
---|
39 | if ( $array_cat_directories[$subrow['cat_id']] == '' ) |
---|
40 | { |
---|
41 | $array_cat_directories[$subrow['cat_id']] = |
---|
42 | get_complete_dir( $subrow['cat_id'] ); |
---|
43 | $cat_result = get_cat_info( $subrow['cat_id'] ); |
---|
44 | $array_cat_site_id[$subrow['cat_id']] = $cat_result['site_id']; |
---|
45 | $array_cat_names[$subrow['cat_id']] = |
---|
46 | get_cat_display_name( $cat_result['name'], ' > ', '' ); |
---|
47 | } |
---|
48 | |
---|
49 | $file = get_filename_wo_extension( $subrow['file'] ); |
---|
50 | // name of the picture |
---|
51 | $name = $array_cat_names[$subrow['cat_id']].' > '; |
---|
52 | if ( $subrow['name'] != '' ) |
---|
53 | { |
---|
54 | $name.= $subrow['name']; |
---|
55 | } |
---|
56 | else |
---|
57 | { |
---|
58 | $name.= str_replace( '_', ' ', $file ); |
---|
59 | } |
---|
60 | $name.= ' [ '.$subrow['file'].' ]'; |
---|
61 | $vtp->setVar( $sub, 'picture.title', $name ); |
---|
62 | // source of the thumbnail picture |
---|
63 | $src = ''; |
---|
64 | if ( $array_cat_site_id[$subrow['cat_id']] == 1 ) |
---|
65 | { |
---|
66 | $src.= '.'; |
---|
67 | } |
---|
68 | $src.= $array_cat_directories[$subrow['cat_id']]; |
---|
69 | $src.= 'thumbnail/'.$conf['prefix_thumbnail']; |
---|
70 | $src.= $file.'.'.$subrow['tn_ext']; |
---|
71 | $vtp->setVar( $sub, 'picture.thumb_src', $src ); |
---|
72 | // link to the full size picture |
---|
73 | $url = '../picture.php?cat='.$subrow['cat_id']; |
---|
74 | $url.= '&image_id='.$row['image_id']; |
---|
75 | $vtp->setVar( $sub, 'picture.thumb_url', add_session_id( $url ) ); |
---|
76 | // 3. for each picture, retrieving all comments |
---|
77 | $query = 'SELECT id,date,author,content'; |
---|
78 | $query.= ' FROM '.PREFIX_TABLE.'comments'; |
---|
79 | $query.= ' WHERE image_id = '.$row['image_id']; |
---|
80 | $query.= ' AND date > '.$maxtime; |
---|
81 | if ( $validation_box ) $query.= " AND validated = 'false'"; |
---|
82 | $query.= ' ORDER BY date DESC'; |
---|
83 | $query.= ';'; |
---|
84 | $subresult = mysql_query( $query ); |
---|
85 | while ( $subrow = mysql_fetch_array( $subresult ) ) |
---|
86 | { |
---|
87 | $vtp->addSession( $sub, 'comment' ); |
---|
88 | $author = $subrow['author']; |
---|
89 | if ( $subrow['author'] == '' ) $author = $lang['guest']; |
---|
90 | $vtp->setVar( $sub, 'comment.author', $author ); |
---|
91 | $displayed_date = format_date( $subrow['date'], 'unix', true ); |
---|
92 | $vtp->setVar( $sub, 'comment.date', $displayed_date ); |
---|
93 | |
---|
94 | $content = nl2br( $subrow['content'] ); |
---|
95 | |
---|
96 | // replace _word_ by an underlined word |
---|
97 | $pattern = '/_([^\s]*)_/'; |
---|
98 | $replacement = '<span style="text-decoration:underline;">\1</span>'; |
---|
99 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
100 | |
---|
101 | // replace *word* by a bolded word |
---|
102 | $pattern = '/\*([^\s]*)\*/'; |
---|
103 | $replacement = '<span style="font-weight:bold;">\1</span>'; |
---|
104 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
105 | |
---|
106 | // replace /word/ by an italic word |
---|
107 | $pattern = '/\/([^\s]*)\//'; |
---|
108 | $replacement = '<span style="font-style:italic;">\1</span>'; |
---|
109 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
110 | |
---|
111 | $vtp->setVar( $sub, 'comment.content', $content ); |
---|
112 | |
---|
113 | $vtp->addSession( $sub, 'delete' ); |
---|
114 | $url = './admin.php?page=comments'; |
---|
115 | if ( isset( $_GET['last_days'] ) ) $url.= '&last_days='.MAX_DAYS; |
---|
116 | if ( isset( $_GET['show_unvalidated'] ) ) |
---|
117 | $url.= '&show_unvalidated=true'; |
---|
118 | $url.= '&del='.$subrow['id']; |
---|
119 | $vtp->setVar( $sub, 'delete.link', add_session_id( $url ) ); |
---|
120 | $vtp->closeSession( $sub, 'delete' ); |
---|
121 | // if the comment has to be validated, we display a checkbox |
---|
122 | if ( $validation_box ) |
---|
123 | { |
---|
124 | $vtp->addSession( $sub, 'validation' ); |
---|
125 | $vtp->setVar( $sub, 'validation.id', $subrow['id'] ); |
---|
126 | $vtp->closeSession( $sub, 'validation' ); |
---|
127 | } |
---|
128 | $vtp->closeSession( $sub, 'comment' ); |
---|
129 | } |
---|
130 | $vtp->closeSession( $sub, 'picture' ); |
---|
131 | } |
---|
132 | } |
---|
133 | //------------------------------------------------------------ comment deletion |
---|
134 | if ( isset( $_GET['del'] ) and is_numeric( $_GET['del'] ) ) |
---|
135 | { |
---|
136 | $query = 'DELETE FROM '.PREFIX_TABLE.'comments'; |
---|
137 | $query.= ' WHERE id = '.$_GET['del']; |
---|
138 | $query.= ';'; |
---|
139 | mysql_query( $query ); |
---|
140 | } |
---|
141 | //--------------------------------------------------------- comments validation |
---|
142 | if ( isset( $_POST['submit'] ) ) |
---|
143 | { |
---|
144 | $query = 'SELECT id'; |
---|
145 | $query.= ' FROM '.PREFIX_TABLE.'comments'; |
---|
146 | $query.= " WHERE validated = 'false'"; |
---|
147 | $query.= ';'; |
---|
148 | $result = mysql_query( $query ); |
---|
149 | while ( $row = mysql_fetch_array( $result ) ) |
---|
150 | { |
---|
151 | if ( $_POST['validate-'.$row['id']] == 'true' ) |
---|
152 | { |
---|
153 | $query = 'UPDATE '.PREFIX_TABLE.'comments'; |
---|
154 | $query.= " SET validated = 'true'"; |
---|
155 | $query.= ' WHERE id = '.$row['id']; |
---|
156 | $query.= ';'; |
---|
157 | mysql_query( $query ); |
---|
158 | } |
---|
159 | } |
---|
160 | } |
---|
161 | //----------------------------------------------------- template initialization |
---|
162 | $sub = $vtp->Open( '../template/'.$user['template'].'/admin/comments.vtp' ); |
---|
163 | $tpl = array( 'stats_last_days','delete','close','submit','open' ); |
---|
164 | templatize_array( $tpl, 'lang', $sub ); |
---|
165 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
166 | //--------------------------------------------------- number of days to display |
---|
167 | if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] ); |
---|
168 | else define( 'MAX_DAYS', 0 ); |
---|
169 | //----------------------------------------- non specific section initialization |
---|
170 | $array_cat_directories = array(); |
---|
171 | $array_cat_names = array(); |
---|
172 | $array_cat_site_id = array(); |
---|
173 | //------------------------------------------------------- last comments display |
---|
174 | $vtp->addSession( $sub, 'section' ); |
---|
175 | $vtp->setVar( $sub, 'section.title', $lang['comments_last_title'] ); |
---|
176 | $vtp->addSession( $sub, 'last_days' ); |
---|
177 | foreach ( $conf['last_days'] as $option ) { |
---|
178 | $vtp->addSession( $sub, 'last_day_option' ); |
---|
179 | $vtp->setVar( $sub, 'last_day_option.option', $option ); |
---|
180 | $url = './admin.php?page=comments'; |
---|
181 | $url.= '&last_days='.($option - 1); |
---|
182 | $vtp->setVar( $sub, 'last_day_option.link', add_session_id( $url ) ); |
---|
183 | if ( $option == MAX_DAYS + 1 ) |
---|
184 | { |
---|
185 | $vtp->setVar( $sub, 'last_day_option.style', 'font-weight:bold;'); |
---|
186 | } |
---|
187 | $vtp->closeSession( $sub, 'last_day_option' ); |
---|
188 | } |
---|
189 | $vtp->closeSession( $sub, 'last_days' ); |
---|
190 | if ( isset( $_GET['last_days'] ) ) |
---|
191 | { |
---|
192 | $vtp->addSession( $sub, 'close' ); |
---|
193 | $url = './admin.php?page=comments'; |
---|
194 | if ( isset( $_GET['show_unvalidated'] ) ) |
---|
195 | { |
---|
196 | $url.= '&show_unvalidated='.$_GET['show_unvalidated']; |
---|
197 | } |
---|
198 | $vtp->setVar( $sub, 'close.url', add_session_id( $url ) ); |
---|
199 | $vtp->closeSession( $sub, 'close' ); |
---|
200 | // 1. retrieving picture ids which have comments recently added |
---|
201 | $date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) ); |
---|
202 | list($year,$month,$day) = explode( '-', $date); |
---|
203 | $maxtime = mktime( 0,0,0,$month,$day,$year ); |
---|
204 | $query = 'SELECT DISTINCT(image_id) as image_id'; |
---|
205 | $query.= ' FROM '.PREFIX_TABLE.'comments'; |
---|
206 | $query.= ', '.PREFIX_TABLE.'images as images'; |
---|
207 | $query.= ' WHERE image_id = images.id'; |
---|
208 | $query.= ' AND date > '.$maxtime; |
---|
209 | $query.= ' ORDER BY date_available DESC'; |
---|
210 | $query.= ';'; |
---|
211 | $result = mysql_query( $query ); |
---|
212 | display_pictures( $result, $maxtime ); |
---|
213 | } |
---|
214 | $vtp->closeSession( $sub, 'section' ); |
---|
215 | //---------------------------------------------- non validated comments display |
---|
216 | $vtp->addSession( $sub, 'section' ); |
---|
217 | $vtp->setVar( $sub, 'section.title', $lang['comments_non_validated_title'] ); |
---|
218 | if ( isset( $_GET['show_unvalidated'] ) ) |
---|
219 | { |
---|
220 | // form starts |
---|
221 | $vtp->addSession( $sub, 'start_form' ); |
---|
222 | $action = './admin.php?page=comments'; |
---|
223 | if ( isset( $_GET['last_days'] ) ) |
---|
224 | { |
---|
225 | $action.= '&last_days='.$_GET['last_days']; |
---|
226 | } |
---|
227 | $action.= '&show_unvalidated=true'; |
---|
228 | $vtp->setVar( $sub, 'start_form.action', add_session_id( $action ) ); |
---|
229 | $vtp->closeSession( $sub, 'start_form' ); |
---|
230 | // close this section ? |
---|
231 | $vtp->addSession( $sub, 'close' ); |
---|
232 | $url = './admin.php?page=comments'; |
---|
233 | if ( isset( $_GET['last_days'] ) ) |
---|
234 | { |
---|
235 | $url.= '&last_days='.$_GET['last_days']; |
---|
236 | } |
---|
237 | $vtp->setVar( $sub, 'close.url', add_session_id( $url ) ); |
---|
238 | $vtp->closeSession( $sub, 'close' ); |
---|
239 | // retrieving all picture ids which have unvalidated comments |
---|
240 | $query = 'SELECT DISTINCT(image_id) as image_id'; |
---|
241 | $query.= ' FROM '.PREFIX_TABLE.'comments as comments'; |
---|
242 | $query.= ', '.PREFIX_TABLE.'images as images'; |
---|
243 | $query.= ' WHERE image_id = images.id'; |
---|
244 | $query.= " AND comments.validated = 'false'"; |
---|
245 | $query.= ' ORDER BY date_available DESC'; |
---|
246 | $query.= ';'; |
---|
247 | $result = mysql_query( $query ); |
---|
248 | display_pictures( $result, 0, true ); |
---|
249 | $vtp->addSession( $sub, 'submit' ); |
---|
250 | $vtp->closeSession( $sub, 'submit' ); |
---|
251 | // form ends |
---|
252 | $vtp->addSession( $sub, 'end_form' ); |
---|
253 | $vtp->closeSession( $sub, 'end_form' ); |
---|
254 | } |
---|
255 | else |
---|
256 | { |
---|
257 | $vtp->addSession( $sub, 'open' ); |
---|
258 | $url = './admin.php?page=comments'; |
---|
259 | if ( isset( $_GET['last_days'] ) ) |
---|
260 | { |
---|
261 | $url.= '&last_days='.$_GET['last_days']; |
---|
262 | } |
---|
263 | $url.= '&show_unvalidated=true'; |
---|
264 | $vtp->setVar( $sub, 'open.url', add_session_id( $url ) ); |
---|
265 | $vtp->closeSession( $sub, 'open' ); |
---|
266 | } |
---|
267 | $vtp->closeSession( $sub, 'section' ); |
---|
268 | //----------------------------------------------------------- sending html code |
---|
269 | $vtp->Parse( $handle, 'sub', $sub ); |
---|
270 | ?> |
---|