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 231 2003-11-03 22:39:53Z z0rglub $ |
---|
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( './admin/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 = $array_cat_directories[$subrow['cat_id']]; |
---|
64 | $src.= 'thumbnail/'.$conf['prefix_thumbnail']; |
---|
65 | $src.= $file.'.'.$subrow['tn_ext']; |
---|
66 | $vtp->setVar( $sub, 'picture.thumb_src', $src ); |
---|
67 | // link to the full size picture |
---|
68 | $url = './picture.php?cat='.$subrow['cat_id']; |
---|
69 | $url.= '&image_id='.$row['image_id']; |
---|
70 | $vtp->setVar( $sub, 'picture.thumb_url', add_session_id( $url ) ); |
---|
71 | // 3. for each picture, retrieving all comments |
---|
72 | $query = 'SELECT id,date,author,content'; |
---|
73 | $query.= ' FROM '.PREFIX_TABLE.'comments'; |
---|
74 | $query.= ' WHERE image_id = '.$row['image_id']; |
---|
75 | $query.= ' AND date > '.$maxtime; |
---|
76 | if ( $validation_box ) $query.= " AND validated = 'false'"; |
---|
77 | $query.= ' ORDER BY date DESC'; |
---|
78 | $query.= ';'; |
---|
79 | $subresult = mysql_query( $query ); |
---|
80 | while ( $subrow = mysql_fetch_array( $subresult ) ) |
---|
81 | { |
---|
82 | $vtp->addSession( $sub, 'comment' ); |
---|
83 | $author = $subrow['author']; |
---|
84 | if ( $subrow['author'] == '' ) $author = $lang['guest']; |
---|
85 | $vtp->setVar( $sub, 'comment.author', $author ); |
---|
86 | $displayed_date = format_date( $subrow['date'], 'unix', true ); |
---|
87 | $vtp->setVar( $sub, 'comment.date', $displayed_date ); |
---|
88 | |
---|
89 | $content = nl2br( $subrow['content'] ); |
---|
90 | |
---|
91 | // replace _word_ by an underlined word |
---|
92 | $pattern = '/_([^\s]*)_/'; |
---|
93 | $replacement = '<span style="text-decoration:underline;">\1</span>'; |
---|
94 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
95 | |
---|
96 | // replace *word* by a bolded word |
---|
97 | $pattern = '/\*([^\s]*)\*/'; |
---|
98 | $replacement = '<span style="font-weight:bold;">\1</span>'; |
---|
99 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
100 | |
---|
101 | // replace /word/ by an italic word |
---|
102 | $pattern = '/\/([^\s]*)\//'; |
---|
103 | $replacement = '<span style="font-style:italic;">\1</span>'; |
---|
104 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
105 | |
---|
106 | $vtp->setVar( $sub, 'comment.content', $content ); |
---|
107 | |
---|
108 | $vtp->addSession( $sub, 'delete' ); |
---|
109 | $url = './admin.php?page=comments'; |
---|
110 | if ( isset( $_GET['last_days'] ) ) $url.= '&last_days='.MAX_DAYS; |
---|
111 | if ( isset( $_GET['show_unvalidated'] ) ) |
---|
112 | $url.= '&show_unvalidated=true'; |
---|
113 | $url.= '&del='.$subrow['id']; |
---|
114 | $vtp->setVar( $sub, 'delete.link', add_session_id( $url ) ); |
---|
115 | $vtp->closeSession( $sub, 'delete' ); |
---|
116 | // if the comment has to be validated, we display a checkbox |
---|
117 | if ( $validation_box ) |
---|
118 | { |
---|
119 | $vtp->addSession( $sub, 'validation' ); |
---|
120 | $vtp->setVar( $sub, 'validation.id', $subrow['id'] ); |
---|
121 | $vtp->closeSession( $sub, 'validation' ); |
---|
122 | } |
---|
123 | $vtp->closeSession( $sub, 'comment' ); |
---|
124 | } |
---|
125 | $vtp->closeSession( $sub, 'picture' ); |
---|
126 | } |
---|
127 | } |
---|
128 | //------------------------------------------------------------ comment deletion |
---|
129 | if ( isset( $_GET['del'] ) and is_numeric( $_GET['del'] ) ) |
---|
130 | { |
---|
131 | $query = 'DELETE FROM '.PREFIX_TABLE.'comments'; |
---|
132 | $query.= ' WHERE id = '.$_GET['del']; |
---|
133 | $query.= ';'; |
---|
134 | mysql_query( $query ); |
---|
135 | } |
---|
136 | //--------------------------------------------------------- comments validation |
---|
137 | if ( isset( $_POST['submit'] ) ) |
---|
138 | { |
---|
139 | $query = 'SELECT id'; |
---|
140 | $query.= ' FROM '.PREFIX_TABLE.'comments'; |
---|
141 | $query.= " WHERE validated = 'false'"; |
---|
142 | $query.= ';'; |
---|
143 | $result = mysql_query( $query ); |
---|
144 | while ( $row = mysql_fetch_array( $result ) ) |
---|
145 | { |
---|
146 | if ( $_POST['validate-'.$row['id']] == 'true' ) |
---|
147 | { |
---|
148 | $query = 'UPDATE '.PREFIX_TABLE.'comments'; |
---|
149 | $query.= " SET validated = 'true'"; |
---|
150 | $query.= ' WHERE id = '.$row['id']; |
---|
151 | $query.= ';'; |
---|
152 | mysql_query( $query ); |
---|
153 | } |
---|
154 | } |
---|
155 | } |
---|
156 | //----------------------------------------------------- template initialization |
---|
157 | $sub = $vtp->Open( './template/'.$user['template'].'/admin/comments.vtp' ); |
---|
158 | $tpl = array( 'stats_last_days','delete','close','submit','open' ); |
---|
159 | templatize_array( $tpl, 'lang', $sub ); |
---|
160 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
161 | //--------------------------------------------------- number of days to display |
---|
162 | if ( isset( $_GET['last_days'] ) ) define( "MAX_DAYS", $_GET['last_days'] ); |
---|
163 | else define( "MAX_DAYS", 0 ); |
---|
164 | //----------------------------------------- non specific section initialization |
---|
165 | $array_cat_directories = array(); |
---|
166 | $array_cat_names = array(); |
---|
167 | $array_cat_site_id = array(); |
---|
168 | //------------------------------------------------------- last comments display |
---|
169 | $vtp->addSession( $sub, 'section' ); |
---|
170 | $vtp->setVar( $sub, 'section.title', $lang['comments_last_title'] ); |
---|
171 | $vtp->addSession( $sub, 'last_days' ); |
---|
172 | foreach ( $conf['last_days'] as $option ) { |
---|
173 | $vtp->addSession( $sub, 'last_day_option' ); |
---|
174 | $vtp->setVar( $sub, 'last_day_option.option', $option ); |
---|
175 | $url = './admin.php?page=comments'; |
---|
176 | $url.= '&last_days='.($option - 1); |
---|
177 | $vtp->setVar( $sub, 'last_day_option.link', add_session_id( $url ) ); |
---|
178 | if ( $option == MAX_DAYS + 1 ) |
---|
179 | { |
---|
180 | $vtp->setVar( $sub, 'last_day_option.style', 'font-weight:bold;'); |
---|
181 | } |
---|
182 | $vtp->closeSession( $sub, 'last_day_option' ); |
---|
183 | } |
---|
184 | $vtp->closeSession( $sub, 'last_days' ); |
---|
185 | if ( isset( $_GET['last_days'] ) ) |
---|
186 | { |
---|
187 | $vtp->addSession( $sub, 'close' ); |
---|
188 | $url = './admin.php?page=comments'; |
---|
189 | if ( isset( $_GET['show_unvalidated'] ) ) |
---|
190 | { |
---|
191 | $url.= '&show_unvalidated='.$_GET['show_unvalidated']; |
---|
192 | } |
---|
193 | $vtp->setVar( $sub, 'close.url', add_session_id( $url ) ); |
---|
194 | $vtp->closeSession( $sub, 'close' ); |
---|
195 | // 1. retrieving picture ids which have comments recently added |
---|
196 | $date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) ); |
---|
197 | list($year,$month,$day) = explode( '-', $date); |
---|
198 | $maxtime = mktime( 0,0,0,$month,$day,$year ); |
---|
199 | $query = 'SELECT DISTINCT(image_id) as image_id'; |
---|
200 | $query.= ' FROM '.PREFIX_TABLE.'comments'; |
---|
201 | $query.= ', '.PREFIX_TABLE.'images as images'; |
---|
202 | $query.= ' WHERE image_id = images.id'; |
---|
203 | $query.= ' AND date > '.$maxtime; |
---|
204 | $query.= ' ORDER BY date_available DESC'; |
---|
205 | $query.= ';'; |
---|
206 | $result = mysql_query( $query ); |
---|
207 | display_pictures( $result, $maxtime ); |
---|
208 | } |
---|
209 | $vtp->closeSession( $sub, 'section' ); |
---|
210 | //---------------------------------------------- non validated comments display |
---|
211 | $vtp->addSession( $sub, 'section' ); |
---|
212 | $vtp->setVar( $sub, 'section.title', $lang['comments_non_validated_title'] ); |
---|
213 | if ( isset( $_GET['show_unvalidated'] ) ) |
---|
214 | { |
---|
215 | // form starts |
---|
216 | $vtp->addSession( $sub, 'start_form' ); |
---|
217 | $action = './admin.php?page=comments'; |
---|
218 | if ( isset( $_GET['last_days'] ) ) |
---|
219 | { |
---|
220 | $action.= '&last_days='.$_GET['last_days']; |
---|
221 | } |
---|
222 | $action.= '&show_unvalidated=true'; |
---|
223 | $vtp->setVar( $sub, 'start_form.action', add_session_id( $action ) ); |
---|
224 | $vtp->closeSession( $sub, 'start_form' ); |
---|
225 | // close this section ? |
---|
226 | $vtp->addSession( $sub, 'close' ); |
---|
227 | $url = './admin.php?page=comments'; |
---|
228 | if ( isset( $_GET['last_days'] ) ) |
---|
229 | { |
---|
230 | $url.= '&last_days='.$_GET['last_days']; |
---|
231 | } |
---|
232 | $vtp->setVar( $sub, 'close.url', add_session_id( $url ) ); |
---|
233 | $vtp->closeSession( $sub, 'close' ); |
---|
234 | // retrieving all picture ids which have unvalidated comments |
---|
235 | $query = 'SELECT DISTINCT(image_id) as image_id'; |
---|
236 | $query.= ' FROM '.PREFIX_TABLE.'comments as comments'; |
---|
237 | $query.= ', '.PREFIX_TABLE.'images as images'; |
---|
238 | $query.= ' WHERE image_id = images.id'; |
---|
239 | $query.= " AND comments.validated = 'false'"; |
---|
240 | $query.= ' ORDER BY date_available DESC'; |
---|
241 | $query.= ';'; |
---|
242 | $result = mysql_query( $query ); |
---|
243 | display_pictures( $result, 0, true ); |
---|
244 | $vtp->addSession( $sub, 'submit' ); |
---|
245 | $vtp->closeSession( $sub, 'submit' ); |
---|
246 | // form ends |
---|
247 | $vtp->addSession( $sub, 'end_form' ); |
---|
248 | $vtp->closeSession( $sub, 'end_form' ); |
---|
249 | } |
---|
250 | else |
---|
251 | { |
---|
252 | $vtp->addSession( $sub, 'open' ); |
---|
253 | $url = './admin.php?page=comments'; |
---|
254 | if ( isset( $_GET['last_days'] ) ) |
---|
255 | { |
---|
256 | $url.= '&last_days='.$_GET['last_days']; |
---|
257 | } |
---|
258 | $url.= '&show_unvalidated=true'; |
---|
259 | $vtp->setVar( $sub, 'open.url', add_session_id( $url ) ); |
---|
260 | $vtp->closeSession( $sub, 'open' ); |
---|
261 | } |
---|
262 | $vtp->closeSession( $sub, 'section' ); |
---|
263 | //----------------------------------------------------------- sending html code |
---|
264 | $vtp->Parse( $handle, 'sub', $sub ); |
---|
265 | ?> |
---|