Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 243
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
mcp_front_view
0.00% covered (danger)
0.00%
0 / 241
0.00% covered (danger)
0.00%
0 / 1
1560
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14/**
15* @ignore
16*/
17if (!defined('IN_PHPBB'))
18{
19    exit;
20}
21
22/**
23* MCP Front Panel
24*/
25function mcp_front_view($id, $mode, $action)
26{
27    global $phpEx, $phpbb_root_path;
28    global $template, $db, $user, $auth, $module;
29    global $phpbb_dispatcher, $request;
30
31    // Latest 5 unapproved
32    if ($module->loaded('queue'))
33    {
34        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_approve')));
35        $post_list = array();
36        $forum_names = array();
37
38        $forum_id = $request->variable('f', 0);
39
40        $template->assign_var('S_SHOW_UNAPPROVED', (!empty($forum_list)) ? true : false);
41
42        if (!empty($forum_list))
43        {
44            $sql_ary = array(
45                'SELECT' => 'COUNT(post_id) AS total',
46                'FROM' => array(
47                        POSTS_TABLE => 'p',
48                    ),
49                'WHERE' => $db->sql_in_set('p.forum_id', $forum_list) . '
50                    AND ' . $db->sql_in_set('p.post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE))
51            );
52
53            /**
54            * Allow altering the query to get the number of unapproved posts
55            *
56            * @event core.mcp_front_queue_unapproved_total_before
57            * @var    array    sql_ary            Query array to get the total number of unapproved posts
58            * @var    array    forum_list        List of forums to look for unapproved posts
59            * @since 3.1.5-RC1
60            */
61            $vars = array('sql_ary', 'forum_list');
62            extract($phpbb_dispatcher->trigger_event('core.mcp_front_queue_unapproved_total_before', compact($vars)));
63
64            $sql = $db->sql_build_query('SELECT', $sql_ary);
65            $result = $db->sql_query($sql);
66            $total = (int) $db->sql_fetchfield('total');
67            $db->sql_freeresult($result);
68
69            if ($total)
70            {
71                $sql = 'SELECT forum_id, forum_name
72                    FROM ' . FORUMS_TABLE . '
73                    WHERE ' . $db->sql_in_set('forum_id', $forum_list);
74                $result = $db->sql_query($sql);
75
76                while ($row = $db->sql_fetchrow($result))
77                {
78                    $forum_names[$row['forum_id']] = $row['forum_name'];
79                }
80                $db->sql_freeresult($result);
81
82                $sql = 'SELECT post_id
83                    FROM ' . POSTS_TABLE . '
84                    WHERE ' . $db->sql_in_set('forum_id', $forum_list) . '
85                        AND ' . $db->sql_in_set('post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE)) . '
86                    ORDER BY post_time DESC, post_id DESC';
87                $result = $db->sql_query_limit($sql, 5);
88
89                while ($row = $db->sql_fetchrow($result))
90                {
91                    $post_list[] = $row['post_id'];
92                }
93                $db->sql_freeresult($result);
94
95                if (empty($post_list))
96                {
97                    $total = 0;
98                }
99            }
100
101            /**
102            * Alter list of posts and total as required
103            *
104            * @event core.mcp_front_view_queue_postid_list_after
105            * @var    int        total                        Number of unapproved posts
106            * @var    array    post_list                    List of unapproved posts
107            * @var    array    forum_list                    List of forums that contain the posts
108            * @var    array    forum_names                    Associative array with forum_id as key and its corresponding forum_name as value
109            * @since 3.1.0-RC3
110            */
111            $vars = array('total', 'post_list', 'forum_list', 'forum_names');
112            extract($phpbb_dispatcher->trigger_event('core.mcp_front_view_queue_postid_list_after', compact($vars)));
113
114            if ($total)
115            {
116                $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.post_attachment, p.poster_id, p.post_username, u.username, u.username_clean, u.user_colour, t.topic_id, t.topic_title, t.topic_first_post_id, p.forum_id
117                    FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
118                    WHERE ' . $db->sql_in_set('p.post_id', $post_list) . '
119                        AND t.topic_id = p.topic_id
120                        AND p.poster_id = u.user_id
121                    ORDER BY p.post_time DESC, p.post_id DESC';
122
123                /**
124                 * Alter posts data SQL query
125                 *
126                 * @event core.mcp_front_view_modify_posts_data_sql
127                 * @var    array    forum_list        List of forums that contain the posts
128                 * @var    array    forum_names        Associative array with forum_id as key and its corresponding forum_name as value
129                 * @var    array    post_list        List of unapproved posts
130                 * @var    string    sql                String with the SQL query to be executed
131                 * @var    int        total            Number of unapproved posts
132                 * @since 3.3.5-RC1
133                 */
134                $vars = [
135                    'forum_list',
136                    'forum_names',
137                    'post_list',
138                    'sql',
139                    'total',
140                ];
141                extract($phpbb_dispatcher->trigger_event('core.mcp_front_view_modify_posts_data_sql', compact($vars)));
142
143                $result = $db->sql_query($sql);
144
145                while ($row = $db->sql_fetchrow($result))
146                {
147                    $unapproved_post_row = [
148                        'U_POST_DETAILS'    => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;p=' . $row['post_id']),
149                        'U_MCP_FORUM'        => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=forum_view&amp;f=' . $row['forum_id']),
150                        'U_MCP_TOPIC'        => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=topic_view&amp;t=' . $row['topic_id']),
151                        'U_FORUM'            => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']),
152                        'U_TOPIC'            => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $row['topic_id']),
153
154                        'AUTHOR_FULL'        => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour']),
155                        'AUTHOR'            => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour']),
156                        'AUTHOR_COLOUR'        => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour']),
157                        'U_AUTHOR'            => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour']),
158
159                        'FORUM_NAME'    => $forum_names[$row['forum_id']],
160                        'POST_ID'        => $row['post_id'],
161                        'TOPIC_TITLE'    => $row['topic_title'],
162                        'SUBJECT'        => ($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
163                        'POST_TIME'        => $user->format_date($row['post_time']),
164                        'ATTACH_ICON_IMG'    => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
165                    ];
166
167                    /**
168                     * Alter unapproved posts template block for MCP front page
169                     *
170                     * @event core.mcp_front_view_modify_unapproved_post_row
171                     * @var    array    forum_names                Array containing forum names
172                     * @var    string    mode                    MCP front view mode
173                     * @var    array    row                        Array with unapproved post data
174                     * @var    array    unapproved_post_row        Template block array of the unapproved post
175                     * @since 3.3.5-RC1
176                     */
177                    $vars = [
178                        'forum_names',
179                        'mode',
180                        'row',
181                        'unapproved_post_row',
182                    ];
183                    extract($phpbb_dispatcher->trigger_event('core.mcp_front_view_modify_unapproved_post_row', compact($vars)));
184
185                    $template->assign_block_vars('unapproved', $unapproved_post_row);
186                }
187                $db->sql_freeresult($result);
188            }
189
190            $s_hidden_fields = build_hidden_fields(array(
191                'redirect'        => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main' . (($forum_id) ? '&amp;f=' . $forum_id : ''))
192            ));
193
194            $template->assign_vars(array(
195                'S_HIDDEN_FIELDS'        => $s_hidden_fields,
196                'S_MCP_QUEUE_ACTION'    => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue"),
197                'L_UNAPPROVED_TOTAL'    => $user->lang('UNAPPROVED_POSTS_TOTAL', (int) $total),
198                'S_HAS_UNAPPROVED_POSTS'=> ($total != 0),
199            ));
200        }
201    }
202
203    // Latest 5 reported
204    if ($module->loaded('reports'))
205    {
206        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_report')));
207
208        $template->assign_var('S_SHOW_REPORTS', (!empty($forum_list)) ? true : false);
209
210        if (!empty($forum_list))
211        {
212            $sql = 'SELECT COUNT(r.report_id) AS total
213                FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p
214                WHERE r.post_id = p.post_id
215                    AND r.pm_id = 0
216                    AND r.report_closed = 0
217                    AND ' . $db->sql_in_set('p.forum_id', $forum_list);
218
219            /**
220            * Alter sql query to count the number of reported posts
221            *
222            * @event core.mcp_front_reports_count_query_before
223            * @var    string    sql                The query string used to get the number of reports that exist
224            * @var    array    forum_list        List of forums that contain the posts
225            * @since 3.1.5-RC1
226            */
227            $vars = array('sql', 'forum_list');
228            extract($phpbb_dispatcher->trigger_event('core.mcp_front_reports_count_query_before', compact($vars)));
229
230            $result = $db->sql_query($sql);
231            $total = (int) $db->sql_fetchfield('total');
232            $db->sql_freeresult($result);
233
234            if ($total)
235            {
236                $sql_ary = array(
237                    'SELECT'    => 'r.report_time, p.post_id, p.post_subject, p.post_time, p.post_attachment, u.username, u.username_clean, u.user_colour, u.user_id, u2.username as author_name, u2.username_clean as author_name_clean, u2.user_colour as author_colour, u2.user_id as author_id, t.topic_id, t.topic_title, f.forum_id, f.forum_name',
238
239                    'FROM'        => array(
240                        REPORTS_TABLE            => 'r',
241                        REPORTS_REASONS_TABLE    => 'rr',
242                        TOPICS_TABLE            => 't',
243                        USERS_TABLE                => array('u', 'u2'),
244                        POSTS_TABLE                => 'p',
245                    ),
246
247                    'LEFT_JOIN'    => array(
248                        array(
249                            'FROM'    => array(FORUMS_TABLE => 'f'),
250                            'ON'    => 'f.forum_id = p.forum_id',
251                        ),
252                    ),
253
254                    'WHERE'        => 'r.post_id = p.post_id
255                        AND r.pm_id = 0
256                        AND r.report_closed = 0
257                        AND r.reason_id = rr.reason_id
258                        AND p.topic_id = t.topic_id
259                        AND r.user_id = u.user_id
260                        AND p.poster_id = u2.user_id
261                        AND ' . $db->sql_in_set('p.forum_id', $forum_list),
262
263                    'ORDER_BY'    => 'p.post_time DESC, p.post_id DESC',
264                );
265
266                /**
267                * Alter sql query to get latest reported posts
268                *
269                * @event core.mcp_front_reports_listing_query_before
270                * @var    array    sql_ary            Associative array with the query to be executed
271                * @var    array    forum_list        List of forums that contain the posts
272                * @since 3.1.0-RC3
273                */
274                $vars = array('sql_ary', 'forum_list');
275                extract($phpbb_dispatcher->trigger_event('core.mcp_front_reports_listing_query_before', compact($vars)));
276
277                $sql = $db->sql_build_query('SELECT', $sql_ary);
278                $result = $db->sql_query_limit($sql, 5);
279
280                while ($row = $db->sql_fetchrow($result))
281                {
282                    $reported_post_row = [
283                        'U_POST_DETAILS'    => append_sid("{$phpbb_root_path}mcp.$phpEx", 'p=' . $row['post_id'] . "&amp;i=reports&amp;mode=report_details"),
284                        'U_MCP_FORUM'        => append_sid("{$phpbb_root_path}mcp.$phpEx", 'f=' . $row['forum_id'] . "&amp;i=$id&amp;mode=forum_view"),
285                        'U_MCP_TOPIC'        => append_sid("{$phpbb_root_path}mcp.$phpEx", 't=' . $row['topic_id'] . "&amp;i=$id&amp;mode=topic_view"),
286                        'U_FORUM'            => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']),
287                        'U_TOPIC'            => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $row['topic_id']),
288
289                        'REPORTER_FULL'        => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
290                        'REPORTER'            => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
291                        'REPORTER_COLOUR'    => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
292                        'U_REPORTER'        => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
293
294                        'AUTHOR_FULL'        => get_username_string('full', $row['author_id'], $row['author_name'], $row['author_colour']),
295                        'AUTHOR'            => get_username_string('username', $row['author_id'], $row['author_name'], $row['author_colour']),
296                        'AUTHOR_COLOUR'        => get_username_string('colour', $row['author_id'], $row['author_name'], $row['author_colour']),
297                        'U_AUTHOR'            => get_username_string('profile', $row['author_id'], $row['author_name'], $row['author_colour']),
298
299                        'FORUM_NAME'    => $row['forum_name'],
300                        'TOPIC_TITLE'    => $row['topic_title'],
301                        'SUBJECT'        => ($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
302                        'REPORT_TIME'    => $user->format_date($row['report_time']),
303                        'POST_TIME'        => $user->format_date($row['post_time']),
304                        'ATTACH_ICON_IMG'    => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
305                    ];
306
307                    /**
308                     * Alter reported posts template block for MCP front page
309                     *
310                     * @event core.mcp_front_view_modify_reported_post_row
311                     * @var    array    forum_list            List of forums that contain the posts
312                     * @var    string    mode                MCP front view mode
313                     * @var    array    reported_post_row    Template block array of the reported post
314                     * @var    array    row                    Array with reported post data
315                     * @since 3.3.5-RC1
316                     */
317                    $vars = [
318                        'forum_list',
319                        'mode',
320                        'reported_post_row',
321                        'row',
322                    ];
323                    extract($phpbb_dispatcher->trigger_event('core.mcp_front_view_modify_reported_post_row', compact($vars)));
324
325                    $template->assign_block_vars('report', $reported_post_row);
326                }
327                $db->sql_freeresult($result);
328            }
329
330            $template->assign_vars(array(
331                'L_REPORTS_TOTAL'    => $user->lang('REPORTS_TOTAL', (int) $total),
332                'S_HAS_REPORTS'        => ($total != 0),
333            ));
334        }
335    }
336
337    // Latest 5 reported PMs
338    if ($module->loaded('pm_reports') && $auth->acl_get('m_pm_report'))
339    {
340        $template->assign_var('S_SHOW_PM_REPORTS', true);
341        $user->add_lang(array('ucp'));
342
343        $sql = 'SELECT COUNT(r.report_id) AS total
344            FROM ' . REPORTS_TABLE . ' r, ' . PRIVMSGS_TABLE . ' p
345            WHERE r.post_id = 0
346                AND r.pm_id = p.msg_id
347                AND r.report_closed = 0';
348        $result = $db->sql_query($sql);
349        $total = (int) $db->sql_fetchfield('total');
350        $db->sql_freeresult($result);
351
352        if ($total)
353        {
354            if (!function_exists('get_recipient_strings'))
355            {
356                include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
357            }
358
359            $sql_ary = array(
360                'SELECT'    => 'r.report_id, r.report_time, p.msg_id, p.message_subject, p.message_time, p.to_address, p.bcc_address, p.message_attachment, u.username, u.username_clean, u.user_colour, u.user_id, u2.username as author_name, u2.username_clean as author_name_clean, u2.user_colour as author_colour, u2.user_id as author_id',
361
362                'FROM'        => array(
363                    REPORTS_TABLE            => 'r',
364                    REPORTS_REASONS_TABLE    => 'rr',
365                    USERS_TABLE                => array('u', 'u2'),
366                    PRIVMSGS_TABLE                => 'p',
367                ),
368
369                'WHERE'        => 'r.pm_id = p.msg_id
370                    AND r.post_id = 0
371                    AND r.report_closed = 0
372                    AND r.reason_id = rr.reason_id
373                    AND r.user_id = u.user_id
374                    AND p.author_id = u2.user_id',
375
376                'ORDER_BY'    => 'p.message_time DESC',
377            );
378            $sql = $db->sql_build_query('SELECT', $sql_ary);
379            $result = $db->sql_query_limit($sql, 5);
380
381            $pm_by_id = $pm_list = array();
382            while ($row = $db->sql_fetchrow($result))
383            {
384                $pm_by_id[(int) $row['msg_id']] = $row;
385                $pm_list[] = (int) $row['msg_id'];
386            }
387            $db->sql_freeresult($result);
388
389            $address_list = get_recipient_strings($pm_by_id);
390
391            foreach ($pm_list as $message_id)
392            {
393                $row = $pm_by_id[$message_id];
394
395                $template->assign_block_vars('pm_report', array(
396                    'U_PM_DETAILS'    => append_sid("{$phpbb_root_path}mcp.$phpEx", 'r=' . $row['report_id'] . "&amp;i=pm_reports&amp;mode=pm_report_details"),
397
398                    'REPORTER_FULL'        => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
399                    'REPORTER'            => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
400                    'REPORTER_COLOUR'    => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
401                    'U_REPORTER'        => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
402
403                    'PM_AUTHOR_FULL'        => get_username_string('full', $row['author_id'], $row['author_name'], $row['author_colour']),
404                    'PM_AUTHOR'            => get_username_string('username', $row['author_id'], $row['author_name'], $row['author_colour']),
405                    'PM_AUTHOR_COLOUR'        => get_username_string('colour', $row['author_id'], $row['author_name'], $row['author_colour']),
406                    'U_PM_AUTHOR'            => get_username_string('profile', $row['author_id'], $row['author_name'], $row['author_colour']),
407
408                    'PM_SUBJECT'        => $row['message_subject'],
409                    'REPORT_TIME'        => $user->format_date($row['report_time']),
410                    'PM_TIME'            => $user->format_date($row['message_time']),
411                    'RECIPIENTS'        => implode(', ', $address_list[$row['msg_id']]),
412                    'ATTACH_ICON_IMG'    => ($auth->acl_get('u_download') && $row['message_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
413                ));
414            }
415        }
416
417        $template->assign_vars(array(
418            'L_PM_REPORTS_TOTAL'    => $user->lang('PM_REPORTS_TOTAL', (int) $total),
419            'S_HAS_PM_REPORTS'        => ($total != 0),
420        ));
421    }
422
423    // Latest 5 logs
424    if ($module->loaded('logs'))
425    {
426        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_')));
427
428        if (!empty($forum_list))
429        {
430            $log_count = false;
431            $log = array();
432            view_log('mod', $log, $log_count, 5, 0, $forum_list);
433
434            foreach ($log as $row)
435            {
436                $template->assign_block_vars('log', array(
437                    'USERNAME'        => $row['username_full'],
438                    'IP'            => $row['ip'],
439                    'TIME'            => $user->format_date($row['time']),
440                    'ACTION'        => $row['action'],
441                    'U_VIEW_TOPIC'    => (!empty($row['viewtopic'])) ? $row['viewtopic'] : '',
442                    'U_VIEWLOGS'    => (!empty($row['viewlogs'])) ? $row['viewlogs'] : '')
443                );
444            }
445        }
446
447        $template->assign_vars(array(
448            'S_SHOW_LOGS'    => (!empty($forum_list)) ? true : false,
449            'S_HAS_LOGS'    => (!empty($log)) ? true : false)
450        );
451    }
452
453    $template->assign_var('S_MCP_ACTION', append_sid("{$phpbb_root_path}mcp.$phpEx"));
454    make_jumpbox(append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=forum_view'), 0, false, 'm_', true);
455}