1 | <?php |
---|
2 | /* Code adapted from admin/comments.php */ |
---|
3 | defined('COA_ID') or die('Hacking attempt!'); |
---|
4 | |
---|
5 | $page['active_menu'] = get_active_menu('comments'); |
---|
6 | |
---|
7 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
8 | |
---|
9 | if (isset($_GET['start']) and is_numeric($_GET['start'])) |
---|
10 | { |
---|
11 | $page['start'] = $_GET['start']; |
---|
12 | } |
---|
13 | else |
---|
14 | { |
---|
15 | $page['start'] = 0; |
---|
16 | } |
---|
17 | |
---|
18 | // +-----------------------------------------------------------------------+ |
---|
19 | // | Check Access and exit when user status is not ok | |
---|
20 | // +-----------------------------------------------------------------------+ |
---|
21 | |
---|
22 | check_status(ACCESS_ADMINISTRATOR); |
---|
23 | |
---|
24 | // +-----------------------------------------------------------------------+ |
---|
25 | // | actions | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | if (!empty($_POST)) |
---|
28 | { |
---|
29 | if (empty($_POST['comments'])) |
---|
30 | { |
---|
31 | $page['errors'][] = l10n('Select at least one comment'); |
---|
32 | } |
---|
33 | else |
---|
34 | { |
---|
35 | include_once(COA_PATH.'include/functions_comment.inc.php'); |
---|
36 | check_input_parameter('comments', $_POST, true, PATTERN_ID); |
---|
37 | |
---|
38 | if (isset($_POST['validate'])) |
---|
39 | { |
---|
40 | validate_user_comment_albums($_POST['comments']); |
---|
41 | |
---|
42 | $page['infos'][] = l10n_dec( |
---|
43 | '%d user comment validated', '%d user comments validated', |
---|
44 | count($_POST['comments']) |
---|
45 | ); |
---|
46 | } |
---|
47 | |
---|
48 | if (isset($_POST['reject'])) |
---|
49 | { |
---|
50 | delete_user_comment_albums($_POST['comments']); |
---|
51 | |
---|
52 | $page['infos'][] = l10n_dec( |
---|
53 | '%d user comment rejected', '%d user comments rejected', |
---|
54 | count($_POST['comments']) |
---|
55 | ); |
---|
56 | } |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | // +-----------------------------------------------------------------------+ |
---|
61 | // | template init | |
---|
62 | // +-----------------------------------------------------------------------+ |
---|
63 | |
---|
64 | $template->set_filename('comments', 'comments.tpl'); |
---|
65 | $template->set_prefilter('comments', 'coa_admin_add_category_name'); |
---|
66 | |
---|
67 | $template->assign('F_ACTION', COA_ADMIN); |
---|
68 | |
---|
69 | // +-----------------------------------------------------------------------+ |
---|
70 | // | Tabs | |
---|
71 | // +-----------------------------------------------------------------------+ |
---|
72 | |
---|
73 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
74 | |
---|
75 | $tabsheet = new tabsheet(); |
---|
76 | $tabsheet->set_id('comments'); |
---|
77 | $tabsheet->select('albums'); |
---|
78 | $tabsheet->assign(); |
---|
79 | |
---|
80 | // +-----------------------------------------------------------------------+ |
---|
81 | // | comments display | |
---|
82 | // +-----------------------------------------------------------------------+ |
---|
83 | |
---|
84 | $nb_total = 0; |
---|
85 | $nb_pending = 0; |
---|
86 | |
---|
87 | $query = ' |
---|
88 | SELECT |
---|
89 | COUNT(*) AS counter, |
---|
90 | validated |
---|
91 | FROM '.COA_TABLE.' |
---|
92 | GROUP BY validated |
---|
93 | ;'; |
---|
94 | $result = pwg_query($query); |
---|
95 | while ($row = pwg_db_fetch_assoc($result)) |
---|
96 | { |
---|
97 | $nb_total+= $row['counter']; |
---|
98 | |
---|
99 | if ('false' == $row['validated']) |
---|
100 | { |
---|
101 | $nb_pending = $row['counter']; |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | if (!isset($_GET['filter']) and $nb_pending > 0) |
---|
106 | { |
---|
107 | $page['filter'] = 'pending'; |
---|
108 | } |
---|
109 | else |
---|
110 | { |
---|
111 | $page['filter'] = 'all'; |
---|
112 | } |
---|
113 | |
---|
114 | if (isset($_GET['filter']) and 'pending' == $_GET['filter']) |
---|
115 | { |
---|
116 | $page['filter'] = 'pending'; |
---|
117 | } |
---|
118 | |
---|
119 | $template->assign( |
---|
120 | array( |
---|
121 | 'nb_total' => $nb_total, |
---|
122 | 'nb_pending' => $nb_pending, |
---|
123 | 'filter' => $page['filter'], |
---|
124 | ) |
---|
125 | ); |
---|
126 | |
---|
127 | $where_clauses = array('1=1'); |
---|
128 | |
---|
129 | if ('pending' == $page['filter']) |
---|
130 | { |
---|
131 | $where_clauses[] = 'validated=\'false\''; |
---|
132 | } |
---|
133 | |
---|
134 | $query = ' |
---|
135 | SELECT |
---|
136 | com.id, |
---|
137 | com.category_id, |
---|
138 | com.date, |
---|
139 | com.author, |
---|
140 | u.'.$conf['user_fields']['username'].' AS username, |
---|
141 | com.content, |
---|
142 | cat.name, |
---|
143 | img.id AS image_id, |
---|
144 | img.path, |
---|
145 | com.validated |
---|
146 | FROM '.COA_TABLE.' AS com |
---|
147 | LEFT JOIN '.CATEGORIES_TABLE.' AS cat |
---|
148 | ON cat.id = com.category_id |
---|
149 | LEFT JOIN '.USERS_TABLE.' AS u |
---|
150 | ON u.'.$conf['user_fields']['id'].' = com.author_id |
---|
151 | LEFT JOIN '.USER_CACHE_CATEGORIES_TABLE.' AS ucc |
---|
152 | ON ucc.cat_id = com.category_id AND ucc.user_id = '.$user['id'].' |
---|
153 | LEFT JOIN '.IMAGES_TABLE.' AS img |
---|
154 | ON img.id = ucc.user_representative_picture_id |
---|
155 | WHERE '.implode(' AND ', $where_clauses).' |
---|
156 | ORDER BY com.date DESC |
---|
157 | LIMIT '.$page['start'].', '.$conf['comments_page_nb_comments'].' |
---|
158 | ;'; |
---|
159 | $result = pwg_query($query); |
---|
160 | |
---|
161 | while ($row = pwg_db_fetch_assoc($result)) |
---|
162 | { |
---|
163 | $thumb = DerivativeImage::thumb_url( |
---|
164 | array( |
---|
165 | 'id'=>$row['image_id'], |
---|
166 | 'path'=>$row['path'], |
---|
167 | ) |
---|
168 | ); |
---|
169 | |
---|
170 | if (empty($row['author_id'])) |
---|
171 | { |
---|
172 | $author_name = $row['author']; |
---|
173 | } |
---|
174 | else |
---|
175 | { |
---|
176 | $author_name = stripslashes($row['username']); |
---|
177 | } |
---|
178 | |
---|
179 | $template->append( |
---|
180 | 'comments', |
---|
181 | array( |
---|
182 | 'ID' => $row['id'], |
---|
183 | 'U_PICTURE' => get_root_url().'admin.php?page=album-'.$row['category_id'], |
---|
184 | 'CATEGORY_NAME' => trigger_event('render_category_name', $row['name']), |
---|
185 | 'TN_SRC' => $thumb, |
---|
186 | 'AUTHOR' => trigger_event('render_comment_author', $author_name), |
---|
187 | 'DATE' => format_date($row['date'], true), |
---|
188 | 'CONTENT' => trigger_event('render_comment_content', $row['content'], 'album'), |
---|
189 | 'IS_PENDING' => ('false' == $row['validated']), |
---|
190 | ) |
---|
191 | ); |
---|
192 | } |
---|
193 | |
---|
194 | // +-----------------------------------------------------------------------+ |
---|
195 | // | navigation bar | |
---|
196 | // +-----------------------------------------------------------------------+ |
---|
197 | |
---|
198 | $navbar = create_navigation_bar( |
---|
199 | get_root_url().'admin.php'.get_query_string_diff(array('start')), |
---|
200 | ('pending' == $page['filter'] ? $nb_pending : $nb_total), |
---|
201 | $page['start'], |
---|
202 | $conf['comments_page_nb_comments'] |
---|
203 | ); |
---|
204 | |
---|
205 | $template->assign('navbar', $navbar); |
---|
206 | |
---|
207 | // +-----------------------------------------------------------------------+ |
---|
208 | // | sending html code | |
---|
209 | // +-----------------------------------------------------------------------+ |
---|
210 | |
---|
211 | $template->assign_var_from_handle('ADMIN_CONTENT', 'comments'); |
---|
212 | |
---|
213 | |
---|
214 | function coa_admin_add_category_name($content) |
---|
215 | { |
---|
216 | $search = '<img src="{$comment.TN_SRC}">'; |
---|
217 | $add = '<br>{$comment.CATEGORY_NAME}'; |
---|
218 | return str_replace($search, $search.$add, $content); |
---|
219 | } |
---|