1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | comments.php | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | application : PhpWebGallery <http://phpwebgallery.net> | |
---|
6 | // | branch : BSF (Best So Far) | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2004-10-23 17:56:46 +0000 (Sat, 23 Oct 2004) $ |
---|
10 | // | last modifier : $Author: z0rglub $ |
---|
11 | // | revision : $Revision: 579 $ |
---|
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 | // | initialization | |
---|
30 | // +-----------------------------------------------------------------------+ |
---|
31 | if (!defined('IN_ADMIN')) |
---|
32 | { |
---|
33 | define('PHPWG_ROOT_PATH','./'); |
---|
34 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
35 | } |
---|
36 | |
---|
37 | if (isset($_GET['last_days'])) |
---|
38 | { |
---|
39 | define('MAX_DAYS', $_GET['last_days']); |
---|
40 | } |
---|
41 | else |
---|
42 | { |
---|
43 | define('MAX_DAYS', 0); |
---|
44 | } |
---|
45 | $array_cat_names = array(); |
---|
46 | // +-----------------------------------------------------------------------+ |
---|
47 | // | comments management | |
---|
48 | // +-----------------------------------------------------------------------+ |
---|
49 | // comments deletion |
---|
50 | if (isset($_POST['delete']) and count($_POST['comment_id']) > 0) |
---|
51 | { |
---|
52 | $query = ' |
---|
53 | DELETE FROM '.COMMENTS_TABLE.' |
---|
54 | WHERE id IN ('.implode(',', $_POST['comment_id']).') |
---|
55 | ;'; |
---|
56 | mysql_query($query); |
---|
57 | } |
---|
58 | // comments validation |
---|
59 | if (isset($_POST['validate']) and count($_POST['comment_id']) > 0) |
---|
60 | { |
---|
61 | $query = ' |
---|
62 | UPDATE '.COMMENTS_TABLE.' |
---|
63 | SET validated = \'true\' |
---|
64 | WHERE id IN ('.implode(',', $_POST['comment_id']).') |
---|
65 | ;'; |
---|
66 | mysql_query($query); |
---|
67 | } |
---|
68 | // +-----------------------------------------------------------------------+ |
---|
69 | // | page header and options | |
---|
70 | // +-----------------------------------------------------------------------+ |
---|
71 | if (!defined('IN_ADMIN')) |
---|
72 | { |
---|
73 | $title= $lang['title_comments']; |
---|
74 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
75 | } |
---|
76 | |
---|
77 | $template->set_filenames(array('comments'=>'comments.tpl')); |
---|
78 | $template->assign_vars( |
---|
79 | array( |
---|
80 | 'L_COMMENT_TITLE' => $title, |
---|
81 | 'L_COMMENT_STATS' => $lang['stats_last_days'], |
---|
82 | 'L_COMMENT_RETURN' => $lang['return_main_page'], |
---|
83 | 'L_DELETE' =>$lang['delete'], |
---|
84 | 'L_VALIDATE'=>$lang['submit'], |
---|
85 | |
---|
86 | 'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php') |
---|
87 | ) |
---|
88 | ); |
---|
89 | |
---|
90 | foreach ($conf['last_days'] as $option) |
---|
91 | { |
---|
92 | $url = $_SERVER['PHP_SELF'].'?last_days='.($option - 1); |
---|
93 | if (defined('IN_ADMIN')) |
---|
94 | { |
---|
95 | $url.= '&page=comments'; |
---|
96 | } |
---|
97 | $template->assign_block_vars( |
---|
98 | 'last_day_option', |
---|
99 | array( |
---|
100 | 'OPTION'=>$option, |
---|
101 | 'T_STYLE'=>(($option == MAX_DAYS + 1)?'text-decoration:underline;':''), |
---|
102 | 'U_OPTION'=>add_session_id($url) |
---|
103 | ) |
---|
104 | ); |
---|
105 | } |
---|
106 | // +-----------------------------------------------------------------------+ |
---|
107 | // | last comments display | |
---|
108 | // +-----------------------------------------------------------------------+ |
---|
109 | // 1. retrieving picture ids which have comments recently added |
---|
110 | $maxdate = date('Y-m-d', strtotime('-'.MAX_DAYS.' day')); |
---|
111 | |
---|
112 | $query = ' |
---|
113 | SELECT DISTINCT(ic.image_id) AS image_id,(ic.category_id) AS category_id |
---|
114 | FROM '.COMMENTS_TABLE.' AS c, '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
115 | WHERE c.image_id = ic.image_id |
---|
116 | AND date >= \''.$maxdate.'\''; |
---|
117 | if ($user['status'] != 'admin') |
---|
118 | { |
---|
119 | $query.= " |
---|
120 | AND validated = 'true'"; |
---|
121 | // we must not show pictures of a forbidden category |
---|
122 | if ($user['forbidden_categories'] != '') |
---|
123 | { |
---|
124 | $query.= ' |
---|
125 | AND category_id NOT IN ('.$user['forbidden_categories'].')'; |
---|
126 | } |
---|
127 | } |
---|
128 | $query.= ' |
---|
129 | ORDER BY ic.image_id DESC |
---|
130 | ;'; |
---|
131 | $result = mysql_query($query); |
---|
132 | if ($user['status'] == 'admin') |
---|
133 | { |
---|
134 | $template->assign_block_vars('validation', array()); |
---|
135 | } |
---|
136 | while ($row = mysql_fetch_array($result)) |
---|
137 | { |
---|
138 | $category_id = $row['category_id']; |
---|
139 | |
---|
140 | // for each picture, getting informations for displaying thumbnail and |
---|
141 | // link to the full size picture |
---|
142 | $query = ' |
---|
143 | SELECT name,file,storage_category_id as cat_id,tn_ext |
---|
144 | FROM '.IMAGES_TABLE.' |
---|
145 | WHERE id = '.$row['image_id'].' |
---|
146 | ;'; |
---|
147 | $subresult = mysql_query($query); |
---|
148 | $subrow = mysql_fetch_array($subresult); |
---|
149 | |
---|
150 | if (!isset($array_cat_names[$subrow['cat_id']])) |
---|
151 | { |
---|
152 | $cat_result = get_cat_info($subrow['cat_id']); |
---|
153 | $array_cat_names[$subrow['cat_id']] = |
---|
154 | get_cat_display_name($cat_result['name'], ' > ', ''); |
---|
155 | } |
---|
156 | |
---|
157 | // name of the picture |
---|
158 | $name = $array_cat_names[$category_id].' > '; |
---|
159 | if (!empty($subrow['name'])) |
---|
160 | { |
---|
161 | $name.= $subrow['name']; |
---|
162 | } |
---|
163 | else |
---|
164 | { |
---|
165 | $name.= str_replace('_',' ',get_filename_wo_extension($subrow['file'])); |
---|
166 | } |
---|
167 | $name.= ' [ '.$subrow['file'].' ]'; |
---|
168 | // source of the thumbnail picture |
---|
169 | $thumbnail_src = get_thumbnail_src($subrow['file'], |
---|
170 | $subrow['cat_id'], |
---|
171 | @$subrow['tn_ext']); |
---|
172 | // link to the full size picture |
---|
173 | $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id; |
---|
174 | $url.= '&image_id='.$row['image_id']; |
---|
175 | |
---|
176 | $template->assign_block_vars( |
---|
177 | 'picture', |
---|
178 | array( |
---|
179 | 'TITLE_IMG'=>$name, |
---|
180 | 'I_THUMB'=>$thumbnail_src, |
---|
181 | 'U_THUMB'=>add_session_id($url) |
---|
182 | )); |
---|
183 | |
---|
184 | // for each picture, retrieving all comments |
---|
185 | $query = ' |
---|
186 | SELECT * |
---|
187 | FROM '.COMMENTS_TABLE.' |
---|
188 | WHERE image_id = '.$row['image_id'].' |
---|
189 | AND date >= \''.$maxdate.'\''; |
---|
190 | if ($user['status'] != 'admin') |
---|
191 | { |
---|
192 | $query.= ' |
---|
193 | AND validated = \'true\''; |
---|
194 | } |
---|
195 | $query.= ' |
---|
196 | ORDER BY date DESC |
---|
197 | ;'; |
---|
198 | $handleresult = mysql_query($query); |
---|
199 | while ($subrow = mysql_fetch_array($handleresult)) |
---|
200 | { |
---|
201 | $author = $subrow['author']; |
---|
202 | if (empty($subrow['author'])) |
---|
203 | { |
---|
204 | $author = $lang['guest']; |
---|
205 | } |
---|
206 | |
---|
207 | $template->assign_block_vars( |
---|
208 | 'picture.comment', |
---|
209 | array( |
---|
210 | 'COMMENT_AUTHOR'=>$author, |
---|
211 | 'COMMENT_DATE'=>format_date($subrow['date'],'mysql_datetime',true), |
---|
212 | 'COMMENT'=>parse_comment_content($subrow['content']), |
---|
213 | )); |
---|
214 | |
---|
215 | if ($user['status'] == 'admin') |
---|
216 | { |
---|
217 | $template->assign_block_vars( |
---|
218 | 'picture.comment.validation', |
---|
219 | array( |
---|
220 | 'ID'=> $subrow['id'], |
---|
221 | 'CHECKED'=>($subrow['validated']=='false')?'checked="checked"': '' |
---|
222 | )); |
---|
223 | } |
---|
224 | } |
---|
225 | } |
---|
226 | // +-----------------------------------------------------------------------+ |
---|
227 | // | html code display | |
---|
228 | // +-----------------------------------------------------------------------+ |
---|
229 | if (defined('IN_ADMIN')) |
---|
230 | { |
---|
231 | $template->assign_var_from_handle('ADMIN_CONTENT', 'comments'); |
---|
232 | } |
---|
233 | else |
---|
234 | { |
---|
235 | $template->assign_block_vars('title',array()); |
---|
236 | $template->pparse('comments'); |
---|
237 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
238 | } |
---|
239 | ?> |
---|