source: extensions/Comments_on_Albums/include/coa_admin_comments.php @ 9766

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

[plugins] Comments on Albums

  • compatible with BBCode Bar and/or Smilies Support
  • better css integration
File size: 4.1 KB
Line 
1<?php
2/* Code adapted from admin/comments.php */
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5load_language('plugin.lang', COA_PATH);
6
7// +-----------------------------------------------------------------------+
8//                              Tabsheet
9// +-----------------------------------------------------------------------+
10include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
11
12$tabs = array(
13        array(
14                'code' => 'pictures',
15                'label' => l10n('COA_comments_photos'),
16        ),
17        array(
18                'code' => 'albums',
19                'label' => l10n('COA_comments_albums'),
20        ),
21);
22
23$tab_codes = array_map(create_function('$a', 'return $a["code"];'), $tabs);
24
25if (isset($_GET['section']) and in_array($_GET['section'], $tab_codes)) {
26        $page['tab'] = $_GET['section'];
27} else {
28        $page['tab'] = $tabs[0]['code'];
29}
30
31$tabsheet = new tabsheet();
32foreach ($tabs as $tab) {
33        $tabsheet->add(
34                $tab['code'],
35                $tab['label'],
36                get_root_url().'admin.php?page=comments&amp;section='.$tab['code']
37        );
38}
39$tabsheet->select($page['tab']);
40$tabsheet->assign();
41
42
43if ($page['tab'] == 'albums') {
44        $template->clear_assign(array('ADMIN_CONTENT', 'comments', 'LIST', 'F_ACTION'));
45
46        // +-----------------------------------------------------------------------+
47        //                              Actions
48        // +-----------------------------------------------------------------------+
49        if (!empty($_POST)) {
50                if (!empty($_POST['comments'])) {
51                        check_input_parameter('comments', $_POST, true, PATTERN_ID);
52
53                        if (isset($_POST['validate_albums'])) {
54                                $query = 'UPDATE '.COA_TABLE.' SET
55                                                validated = \'true\',
56                                                validation_date = NOW()
57                                        WHERE id IN ('.implode(',', $_POST['comments']).')
58                                ;';
59                                pwg_query($query);
60
61                                array_push($page['infos'], l10n_dec(
62                                        '%d user comment validated', '%d user comments validated',
63                                        count($_POST['comments'])
64                                ));
65                        }
66
67                        if (isset($_POST['reject_albums'])) {
68                                $query = 'DELETE FROM '.COA_TABLE.'
69                                        WHERE id IN ('.implode(',', $_POST['comments']).')
70                                ;';
71                                pwg_query($query);
72
73                                array_push($page['infos'], l10n_dec(
74                                        '%d user comment rejected', '%d user comments rejected',
75                                        count($_POST['comments'])
76                                ));
77                        }
78                }
79        }
80
81        // +-----------------------------------------------------------------------+
82        //                              Infos (re-assignation needed)
83        // +-----------------------------------------------------------------------+
84        if (count($page['infos']) != 0) {
85                $template->assign('infos', $page['infos']);
86        }
87
88        // +-----------------------------------------------------------------------+
89        //                              Comments display
90        // +-----------------------------------------------------------------------+
91        $list = array();
92
93        $query = 'SELECT
94                        com.id,
95                        com.category_id,
96                        com.date,
97                        com.author,
98                        '.$conf['user_fields']['username'].' AS username,
99                        com.content,
100                        cat.name
101                FROM '.COA_TABLE.' AS com
102                INNER JOIN '.CATEGORIES_TABLE.' AS cat
103                ON cat.id = com.category_id
104                LEFT JOIN '.USERS_TABLE.' AS u
105                ON u.'.$conf['user_fields']['id'].' = com.author_id
106                WHERE validated = \'false\'
107                ORDER BY com.date DESC
108        ;';
109        $result = pwg_query($query);
110
111        while ($row = pwg_db_fetch_assoc($result)) {
112                // author
113                if (empty($row['author_id'])) {
114                        $author_name = $row['author'];
115                } else {
116                        $author_name = stripslashes($row['username']);
117                }
118               
119                // comment content
120                $template->append('comments', array(
121                        'CAT_URL' => PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='.$row['category_id'],
122                        'CAT_NAME' => $row['name'],
123                        'ID' => $row['id'],
124                        'AUTHOR' => trigger_event('render_comment_author', $author_name),
125                        'DATE' => format_date($row['date'], true),
126                        'CONTENT' => trigger_event('render_comment_content',$row['content']),
127                ));
128
129                array_push($list, $row['id']);
130        }
131
132        // template
133        $template->set_filename('comments', dirname(__FILE__) .'/../template/coa_admin_comments.tpl');
134        $template->assign(array(
135                'F_ACTION' => get_root_url().'admin.php?page=comments&amp;section=albums',
136                'LIST' => implode(',', $list),
137        ));
138        $template->assign_var_from_handle('ADMIN_CONTENT', 'comments');
139}
140
141?>
Note: See TracBrowser for help on using the repository browser.