source: extensions/Comments_on_Albums/include/coa_comments_page.php @ 9634

Last change on this file since 9634 was 9634, checked in by mistic100, 13 years ago

[plugins] Comments on Albums

  • corrections
  • public list available
File size: 7.5 KB
Line 
1<?php 
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4$template->assign(array(
5        'COA_PATH' => COA_PATH,
6        'ICON_COLOR' => 'ff3363',
7        'ICON_COLOR_OVER' => 'ff7700',
8));
9
10// ajout d'un bouton sur la page principale
11if (!isset($_GET['display_mode'])) {   
12       
13        $template->set_prefilter('comments', 'coa_add_button');
14
15        function coa_add_button($content, &$smarty) {
16                $search = '#<ul class="categoryActions">#';
17
18                $replacement = '
19                {html_head}
20                        <style type="text/css">
21                                .pwg-icon-comments-albums {ldelim}
22                                        background-image: url({$COA_PATH}template/s26/outline_{$ICON_COLOR}.png);
23                                        background-position: -26px 0;
24                                }
25                                a:hover .pwg-icon-comments-albums {ldelim}
26                                        background-image: url({$COA_PATH}template/s26/outline_{$ICON_COLOR_OVER}.png);
27                                        background-position: -26px 0;
28                                }
29                        </style>
30                {/html_head}
31
32                <ul class="categoryActions">
33                        <li><a href="comments.php?display_mode=albums" title="Commentaires albums" class="pwg-state-default pwg-button">
34                                <span class="pwg-icon pwg-icon-comments-albums">&nbsp;</span><span class="pwg-button-text">Commentaires albums</span>
35                        </a></li>';
36
37                return preg_replace($search, $replacement, $content);
38        }
39       
40// page modifiée pour les commentaires albums
41} else if ($_GET['display_mode'] == 'albums') {
42        $template->clear_assign(array('comments', 'navbar', 'sort_by_options'));
43       
44// sort_by : database fields proposed for sorting comments list
45$sort_by = array(
46        'date' => l10n('comment date'),
47        'category_id' => l10n('album')
48);
49$template->assign('sort_by_options', $sort_by);
50
51// +-----------------------------------------------------------------------+
52// |                         comments management                           |
53// +-----------------------------------------------------------------------+
54
55$comment_id = null;
56$action = null;
57
58$actions = array('delete_albums', 'validate_albums', 'edit_albums');
59foreach ($actions as $loop_action) {
60        if (isset($_GET[$loop_action])) {
61                $action = $loop_action;
62                check_input_parameter($action, $_GET, false, PATTERN_ID);
63                $comment_id = $_GET[$action];
64                break;
65        }
66}
67
68if (isset($action)) {
69        include_once(COA_PATH.'include/functions_comment.inc.php');
70        check_pwg_token();
71        $comment_author_id = get_comment_author_id_albums($comment_id);
72        $true_action = str_replace('_albums', null, $action);
73
74        if (can_manage_comment($true_action, $comment_author_id)) {
75                $perform_redirect = false;
76
77                if ('delete_albums' == $action) {
78                        delete_user_comment_albums($comment_id);
79                        $perform_redirect = true;
80                }
81
82                if ('validate_albums' == $action) {
83                        validate_user_comment_albums($comment_id);
84                        $perform_redirect = true;
85                }
86
87                if ('edit_albums' == $action) {
88                        if (!empty($_POST['content'])) {
89                                update_user_comment_albums(array(
90                                        'comment_id' => $_GET['edit_albums'],
91                                        'image_id' => $_POST['image_id'],
92                                        'content' => $_POST['content']
93                                        ), $_POST['key']
94                                );
95                                $perform_redirect = true;
96                        } else {
97                                $edit_comment = $_GET['edit_albums'];
98                        }
99                }
100
101                if ($perform_redirect) {
102                        $redirect_url = PHPWG_ROOT_PATH.'comments.php'.get_query_string_diff(array('delete_albums','validate_albums','edit_albums','pwg_token'));
103                        redirect($redirect_url);
104                }
105        }
106}
107
108// +-----------------------------------------------------------------------+
109// |                            navigation bar                             |
110// +-----------------------------------------------------------------------+
111
112if (isset($_GET['start']) and is_numeric($_GET['start'])) {
113        $start = $_GET['start'];
114} else {
115        $start = 0;
116}
117
118$query = 'SELECT COUNT(DISTINCT(com.id))
119        FROM '.COA_TABLE.' AS com
120        LEFT JOIN '.USERS_TABLE.' As u
121        ON u.'.$conf['user_fields']['id'].' = com.author_id
122        WHERE '.implode('
123        AND ', $page['where_clauses']).'
124;';
125
126list($counter) = pwg_db_fetch_row(pwg_query($query));
127
128$url = PHPWG_ROOT_PATH . 'comments.php' . get_query_string_diff(array('start','delete','validate','pwg_token'));
129$navbar = create_navigation_bar($url, $counter, $start, $page['items_number'], '');
130$template->assign('navbar', $navbar);
131
132// +-----------------------------------------------------------------------+
133// |                        last comments display                          |
134// +-----------------------------------------------------------------------+
135
136$comments = array();
137$element_ids = array();
138$category_ids = array();
139
140$query = 'SELECT
141                com.id AS comment_id,
142                com.category_id,
143                com.author,
144                com.author_id,
145                com.date,
146                com.content,
147                com.validated
148        FROM '.COA_TABLE.' AS com
149        LEFT JOIN '.USERS_TABLE.' As u
150        ON u.'.$conf['user_fields']['id'].' = com.author_id
151        WHERE '.implode('
152        AND ', $page['where_clauses']).'
153        GROUP BY
154                comment_id,
155                com.category_id,
156                com.author,
157                com.author_id,
158                com.date,
159                com.content,
160                com.validated
161        ORDER BY '.$page['sort_by'].' '.$page['sort_order'];
162        if ('all' != $page['items_number']) {
163                $query.= '
164                LIMIT '.$page['items_number'].' OFFSET '.$start;
165        }
166        $query.= '
167;';
168$result = pwg_query($query);
169
170while ($row = pwg_db_fetch_assoc($result)) {
171        array_push($comments, $row);
172        array_push($element_ids, $row['category_id']);
173}
174
175if (count($comments) > 0) {
176        // retrieving category informations
177        $query = 'SELECT
178                        cat.id,
179                        cat.name,
180                        cat.permalink,
181                        cat.uppercats,
182                        com.id as comment_id
183                FROM '.CATEGORIES_TABLE.' AS cat
184                LEFT JOIN '.COA_TABLE.' AS com
185                ON cat.id=com.category_id
186                '.get_sql_condition_FandF(array(
187                        'forbidden_categories' => 'cat.id',
188                        'visible_categories' => 'cat.id'
189                ), 'WHERE').'
190                AND cat.id IN ('.implode(',', $element_ids).')
191        ;';
192        $categories = hash_from_query($query, 'comment_id');
193
194        foreach ($comments as $comment) {
195                $name = $categories[$comment['comment_id']]['name'];
196
197                $url = duplicate_index_url(array(
198                        'category' => array(
199                                'id' => $categories[$comment['comment_id']]['id'], 
200                                'name' => $categories[$comment['comment_id']]['name'], 
201                                'permalink' => $categories[$comment['comment_id']]['permalink'],
202                        ),array('start')
203                ));
204
205                $tpl_comment = array(
206                        'U_PICTURE' => $url,
207                        'TN_SRC' => $url,
208                        'ALT' => $name,
209                        'AUTHOR' => trigger_event('render_comment_author', $comment['author']),
210                        'DATE' => format_date($comment['date'], true),
211                        'CONTENT' => trigger_event('render_comment_content',$comment['content']),
212                );
213
214                if (can_manage_comment('delete', $comment['author_id'])) {
215                        $url = get_root_url().'comments.php'.get_query_string_diff(array('delete','validate','edit', 'pwg_token'));
216
217                        $tpl_comment['U_DELETE'] = add_url_params($url, array(
218                                'delete_albums' => $comment['comment_id'],
219                                'pwg_token' => get_pwg_token(),
220                        ));
221                }
222                if (can_manage_comment('edit', $comment['author_id'])) {
223                        $url = get_root_url().'comments.php'.get_query_string_diff(array('edit', 'delete','validate', 'pwg_token'));
224
225                        $tpl_comment['U_EDIT'] = add_url_params($url, array(
226                                'edit_albums' => $comment['comment_id'],
227                                'pwg_token' => get_pwg_token(),
228                        ));
229
230                        if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment)) {
231                                $key = get_ephemeral_key(2, $comment['category_id']);
232                                $tpl_comment['IN_EDIT'] = true;
233                                $tpl_comment['KEY'] = $key;
234                                $tpl_comment['IMAGE_ID'] = $comment['category_id'];
235                                $tpl_comment['CONTENT'] = $comment['content'];
236                        }
237                }
238                if (can_manage_comment('validate', $comment['author_id'])) {
239                        if ('true' != $comment['validated']) {
240                                $tpl_comment['U_VALIDATE'] = add_url_params($url, array(
241                                        'validate_albums'=> $comment['comment_id'],
242                                        'pwg_token' => get_pwg_token(),
243                                ));
244                        }
245                }
246               
247                $template->append('comments', $tpl_comment);
248        }
249}
250
251       
252        $template->set_filenames(array('comments'=> dirname(__FILE__).'/../template/coa_comments_page.tpl'));
253}
254
255?>
Note: See TracBrowser for help on using the repository browser.