Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 373 |
|
0.00% |
0 / 15 |
CRAP | n/a |
0 / 0 |
|
| phpbb_module__url | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| phpbb_module_notes_url | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| phpbb_module_warn_url | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| phpbb_module_main_url | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| phpbb_module_logs_url | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| phpbb_module_ban_url | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| phpbb_module_queue_url | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| phpbb_module_reports_url | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| phpbb_extra_url | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
20 | |||
| phpbb_get_topic_data | |
0.00% |
0 / 45 |
|
0.00% |
0 / 1 |
156 | |||
| phpbb_get_post_data | |
0.00% |
0 / 49 |
|
0.00% |
0 / 1 |
72 | |||
| phpbb_get_forum_data | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
72 | |||
| phpbb_get_pm_data | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
12 | |||
| phpbb_mcp_sorting | |
0.00% |
0 / 175 |
|
0.00% |
0 / 1 |
2450 | |||
| phpbb_check_ids | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
342 | |||
| 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 | */ |
| 17 | if (!defined('IN_PHPBB')) |
| 18 | { |
| 19 | exit; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Functions used to generate additional URL paramters |
| 24 | */ |
| 25 | function phpbb_module__url($mode, $module_row) |
| 26 | { |
| 27 | return phpbb_extra_url(); |
| 28 | } |
| 29 | |
| 30 | function phpbb_module_notes_url($mode, $module_row) |
| 31 | { |
| 32 | if ($mode == 'front') |
| 33 | { |
| 34 | return ''; |
| 35 | } |
| 36 | |
| 37 | global $user_id; |
| 38 | return phpbb_extra_url(); |
| 39 | } |
| 40 | |
| 41 | function phpbb_module_warn_url($mode, $module_row) |
| 42 | { |
| 43 | if ($mode == 'front' || $mode == 'list') |
| 44 | { |
| 45 | global $forum_id; |
| 46 | return phpbb_extra_url(); |
| 47 | } |
| 48 | |
| 49 | if ($mode == 'warn_post') |
| 50 | { |
| 51 | global $forum_id, $post_id; |
| 52 | return phpbb_extra_url(); |
| 53 | } |
| 54 | else |
| 55 | { |
| 56 | global $user_id; |
| 57 | return phpbb_extra_url(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | function phpbb_module_main_url($mode, $module_row) |
| 62 | { |
| 63 | return phpbb_extra_url(); |
| 64 | } |
| 65 | |
| 66 | function phpbb_module_logs_url($mode, $module_row) |
| 67 | { |
| 68 | return phpbb_extra_url(); |
| 69 | } |
| 70 | |
| 71 | function phpbb_module_ban_url($mode, $module_row) |
| 72 | { |
| 73 | return phpbb_extra_url(); |
| 74 | } |
| 75 | |
| 76 | function phpbb_module_queue_url($mode, $module_row) |
| 77 | { |
| 78 | return phpbb_extra_url(); |
| 79 | } |
| 80 | |
| 81 | function phpbb_module_reports_url($mode, $module_row) |
| 82 | { |
| 83 | return phpbb_extra_url(); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Generate URL parameters for MCP modules |
| 88 | * |
| 89 | * @param array $additional_parameters Array with additional parameters in format of ['key' => 'parameter_name'] |
| 90 | * |
| 91 | * @return string String with URL parameters (empty string if not any) |
| 92 | */ |
| 93 | function phpbb_extra_url($additional_parameters = []) |
| 94 | { |
| 95 | $url_extra = []; |
| 96 | $url_parameters = array_merge([ |
| 97 | 'f' => 'forum_id', |
| 98 | 't' => 'topic_id', |
| 99 | 'p' => 'post_id', |
| 100 | 'r' => 'report_id', |
| 101 | 'u' => 'user_id', |
| 102 | ], $additional_parameters); |
| 103 | |
| 104 | foreach ($url_parameters as $key => $value) |
| 105 | { |
| 106 | global $$value; |
| 107 | if (isset($$value) && $parameter = $$value) |
| 108 | { |
| 109 | $url_extra[] = "$key=$parameter"; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return implode('&', $url_extra); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Get simple topic data |
| 118 | */ |
| 119 | function phpbb_get_topic_data($topic_ids, $acl_list = false, $read_tracking = false) |
| 120 | { |
| 121 | global $auth, $db, $config, $user; |
| 122 | static $rowset = array(); |
| 123 | |
| 124 | $topics = array(); |
| 125 | |
| 126 | if (!count($topic_ids)) |
| 127 | { |
| 128 | return array(); |
| 129 | } |
| 130 | |
| 131 | // cache might not contain read tracking info, so we can't use it if read |
| 132 | // tracking information is requested |
| 133 | if (!$read_tracking) |
| 134 | { |
| 135 | $cache_topic_ids = array_intersect($topic_ids, array_keys($rowset)); |
| 136 | $topic_ids = array_diff($topic_ids, array_keys($rowset)); |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | $cache_topic_ids = array(); |
| 141 | } |
| 142 | |
| 143 | if (count($topic_ids)) |
| 144 | { |
| 145 | $sql_array = array( |
| 146 | 'SELECT' => 't.*, f.*', |
| 147 | |
| 148 | 'FROM' => array( |
| 149 | TOPICS_TABLE => 't', |
| 150 | ), |
| 151 | |
| 152 | 'LEFT_JOIN' => array( |
| 153 | array( |
| 154 | 'FROM' => array(FORUMS_TABLE => 'f'), |
| 155 | 'ON' => 'f.forum_id = t.forum_id' |
| 156 | ) |
| 157 | ), |
| 158 | |
| 159 | 'WHERE' => $db->sql_in_set('t.topic_id', $topic_ids) |
| 160 | ); |
| 161 | |
| 162 | if ($read_tracking && $config['load_db_lastread']) |
| 163 | { |
| 164 | $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time'; |
| 165 | |
| 166 | $sql_array['LEFT_JOIN'][] = array( |
| 167 | 'FROM' => array(TOPICS_TRACK_TABLE => 'tt'), |
| 168 | 'ON' => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id' |
| 169 | ); |
| 170 | |
| 171 | $sql_array['LEFT_JOIN'][] = array( |
| 172 | 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'), |
| 173 | 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id' |
| 174 | ); |
| 175 | } |
| 176 | |
| 177 | $sql = $db->sql_build_query('SELECT', $sql_array); |
| 178 | $result = $db->sql_query($sql); |
| 179 | |
| 180 | while ($row = $db->sql_fetchrow($result)) |
| 181 | { |
| 182 | $rowset[$row['topic_id']] = $row; |
| 183 | |
| 184 | if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id'])) |
| 185 | { |
| 186 | continue; |
| 187 | } |
| 188 | |
| 189 | $topics[$row['topic_id']] = $row; |
| 190 | } |
| 191 | $db->sql_freeresult($result); |
| 192 | } |
| 193 | |
| 194 | foreach ($cache_topic_ids as $id) |
| 195 | { |
| 196 | if (!$acl_list || $auth->acl_gets($acl_list, $rowset[$id]['forum_id'])) |
| 197 | { |
| 198 | $topics[$id] = $rowset[$id]; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | return $topics; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Get simple post data |
| 207 | */ |
| 208 | function phpbb_get_post_data($post_ids, $acl_list = false, $read_tracking = false) |
| 209 | { |
| 210 | global $db, $auth, $config, $user, $phpbb_dispatcher, $phpbb_container; |
| 211 | |
| 212 | $rowset = array(); |
| 213 | |
| 214 | if (!count($post_ids)) |
| 215 | { |
| 216 | return array(); |
| 217 | } |
| 218 | |
| 219 | $sql_array = array( |
| 220 | 'SELECT' => 'p.*, u.*, t.*, f.*', |
| 221 | |
| 222 | 'FROM' => array( |
| 223 | USERS_TABLE => 'u', |
| 224 | POSTS_TABLE => 'p', |
| 225 | TOPICS_TABLE => 't', |
| 226 | ), |
| 227 | |
| 228 | 'LEFT_JOIN' => array( |
| 229 | array( |
| 230 | 'FROM' => array(FORUMS_TABLE => 'f'), |
| 231 | 'ON' => 'f.forum_id = t.forum_id' |
| 232 | ) |
| 233 | ), |
| 234 | |
| 235 | 'WHERE' => $db->sql_in_set('p.post_id', $post_ids) . ' |
| 236 | AND u.user_id = p.poster_id |
| 237 | AND t.topic_id = p.topic_id', |
| 238 | ); |
| 239 | |
| 240 | if ($read_tracking && $config['load_db_lastread']) |
| 241 | { |
| 242 | $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time'; |
| 243 | |
| 244 | $sql_array['LEFT_JOIN'][] = array( |
| 245 | 'FROM' => array(TOPICS_TRACK_TABLE => 'tt'), |
| 246 | 'ON' => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id' |
| 247 | ); |
| 248 | |
| 249 | $sql_array['LEFT_JOIN'][] = array( |
| 250 | 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'), |
| 251 | 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id' |
| 252 | ); |
| 253 | } |
| 254 | |
| 255 | $sql = $db->sql_build_query('SELECT', $sql_array); |
| 256 | $result = $db->sql_query($sql); |
| 257 | unset($sql_array); |
| 258 | |
| 259 | $phpbb_content_visibility = $phpbb_container->get('content.visibility'); |
| 260 | |
| 261 | while ($row = $db->sql_fetchrow($result)) |
| 262 | { |
| 263 | if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id'])) |
| 264 | { |
| 265 | continue; |
| 266 | } |
| 267 | |
| 268 | if (!$phpbb_content_visibility->is_visible('post', $row['forum_id'], $row)) |
| 269 | { |
| 270 | // Moderators without the permission to approve post should at least not see them. ;) |
| 271 | continue; |
| 272 | } |
| 273 | |
| 274 | $rowset[$row['post_id']] = $row; |
| 275 | } |
| 276 | $db->sql_freeresult($result); |
| 277 | |
| 278 | /** |
| 279 | * This event allows you to modify post data displayed in the MCP |
| 280 | * |
| 281 | * @event core.mcp_get_post_data_after |
| 282 | * @var array post_ids Array with post ids that have been fetched |
| 283 | * @var mixed acl_list Either false or an array with permission strings to check |
| 284 | * @var bool read_tracking Whether or not to take last mark read time into account |
| 285 | * @var array rowset The array of posts to be returned |
| 286 | * @since 3.2.10-RC1 |
| 287 | * @since 3.3.1-RC1 |
| 288 | */ |
| 289 | $vars = [ |
| 290 | 'post_ids', |
| 291 | 'acl_list', |
| 292 | 'read_tracking', |
| 293 | 'rowset', |
| 294 | ]; |
| 295 | extract($phpbb_dispatcher->trigger_event('core.mcp_get_post_data_after', compact($vars))); |
| 296 | |
| 297 | return $rowset; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Get simple forum data |
| 302 | */ |
| 303 | function phpbb_get_forum_data($forum_id, $acl_list = 'f_list', $read_tracking = false) |
| 304 | { |
| 305 | global $auth, $db, $user, $config, $phpbb_container; |
| 306 | |
| 307 | $rowset = array(); |
| 308 | |
| 309 | if (!is_array($forum_id)) |
| 310 | { |
| 311 | $forum_id = array($forum_id); |
| 312 | } |
| 313 | |
| 314 | if (!count($forum_id)) |
| 315 | { |
| 316 | return array(); |
| 317 | } |
| 318 | |
| 319 | if ($read_tracking && $config['load_db_lastread']) |
| 320 | { |
| 321 | $read_tracking_join = ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' |
| 322 | AND ft.forum_id = f.forum_id)'; |
| 323 | $read_tracking_select = ', ft.mark_time'; |
| 324 | } |
| 325 | else |
| 326 | { |
| 327 | $read_tracking_join = $read_tracking_select = ''; |
| 328 | } |
| 329 | |
| 330 | $sql = "SELECT f.* $read_tracking_select |
| 331 | FROM " . FORUMS_TABLE . " f$read_tracking_join |
| 332 | WHERE " . $db->sql_in_set('f.forum_id', $forum_id); |
| 333 | $result = $db->sql_query($sql); |
| 334 | |
| 335 | /* @var $phpbb_content_visibility \phpbb\content_visibility */ |
| 336 | $phpbb_content_visibility = $phpbb_container->get('content.visibility'); |
| 337 | |
| 338 | while ($row = $db->sql_fetchrow($result)) |
| 339 | { |
| 340 | if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id'])) |
| 341 | { |
| 342 | continue; |
| 343 | } |
| 344 | |
| 345 | $row['forum_topics_approved'] = $phpbb_content_visibility->get_count('forum_topics', $row, $row['forum_id']); |
| 346 | |
| 347 | $rowset[$row['forum_id']] = $row; |
| 348 | } |
| 349 | $db->sql_freeresult($result); |
| 350 | |
| 351 | return $rowset; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Get simple pm data |
| 356 | */ |
| 357 | function phpbb_get_pm_data($pm_ids) |
| 358 | { |
| 359 | global $db; |
| 360 | |
| 361 | $rowset = array(); |
| 362 | |
| 363 | if (!count($pm_ids)) |
| 364 | { |
| 365 | return array(); |
| 366 | } |
| 367 | |
| 368 | $sql_array = array( |
| 369 | 'SELECT' => 'p.*, u.*', |
| 370 | |
| 371 | 'FROM' => array( |
| 372 | USERS_TABLE => 'u', |
| 373 | PRIVMSGS_TABLE => 'p', |
| 374 | ), |
| 375 | |
| 376 | 'WHERE' => $db->sql_in_set('p.msg_id', $pm_ids) . ' |
| 377 | AND u.user_id = p.author_id', |
| 378 | ); |
| 379 | |
| 380 | $sql = $db->sql_build_query('SELECT', $sql_array); |
| 381 | $result = $db->sql_query($sql); |
| 382 | unset($sql_array); |
| 383 | |
| 384 | while ($row = $db->sql_fetchrow($result)) |
| 385 | { |
| 386 | $rowset[$row['msg_id']] = $row; |
| 387 | } |
| 388 | $db->sql_freeresult($result); |
| 389 | |
| 390 | return $rowset; |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * sorting in mcp |
| 395 | * |
| 396 | * $where_sql should either be WHERE (default if ommited) or end with AND or OR |
| 397 | * |
| 398 | * $mode reports and reports_closed: the $where parameters uses aliases p for posts table and r for report table |
| 399 | * $mode unapproved_posts: the $where parameters uses aliases p for posts table and t for topic table |
| 400 | */ |
| 401 | function phpbb_mcp_sorting($mode, &$sort_days_val, &$sort_key_val, &$sort_dir_val, &$sort_by_sql_ary, &$sort_order_sql, &$total_val, $forum_id = 0, $topic_id = 0, $where_sql = 'WHERE') |
| 402 | { |
| 403 | global $db, $user, $auth, $template, $request, $phpbb_dispatcher; |
| 404 | |
| 405 | $sort_days_val = $request->variable('st', 0); |
| 406 | $min_time = ($sort_days_val) ? time() - ($sort_days_val * 86400) : 0; |
| 407 | |
| 408 | switch ($mode) |
| 409 | { |
| 410 | case 'viewforum': |
| 411 | $type = 'topics'; |
| 412 | $default_key = 't'; |
| 413 | $default_dir = 'd'; |
| 414 | |
| 415 | $sql = 'SELECT COUNT(topic_id) AS total |
| 416 | FROM ' . TOPICS_TABLE . " |
| 417 | $where_sql forum_id = $forum_id |
| 418 | AND topic_type NOT IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ") |
| 419 | AND topic_last_post_time >= $min_time"; |
| 420 | |
| 421 | if (!$auth->acl_get('m_approve', $forum_id)) |
| 422 | { |
| 423 | $sql .= ' AND topic_visibility = ' . ITEM_APPROVED; |
| 424 | } |
| 425 | break; |
| 426 | |
| 427 | case 'viewtopic': |
| 428 | $type = 'posts'; |
| 429 | $default_key = 't'; |
| 430 | $default_dir = 'a'; |
| 431 | |
| 432 | $sql = 'SELECT COUNT(post_id) AS total |
| 433 | FROM ' . POSTS_TABLE . " |
| 434 | $where_sql topic_id = $topic_id |
| 435 | AND post_time >= $min_time"; |
| 436 | |
| 437 | if (!$auth->acl_get('m_approve', $forum_id)) |
| 438 | { |
| 439 | $sql .= ' AND post_visibility = ' . ITEM_APPROVED; |
| 440 | } |
| 441 | break; |
| 442 | |
| 443 | case 'unapproved_posts': |
| 444 | case 'deleted_posts': |
| 445 | $visibility_const = ($mode == 'unapproved_posts') ? array(ITEM_UNAPPROVED, ITEM_REAPPROVE) : ITEM_DELETED; |
| 446 | $type = 'posts'; |
| 447 | $default_key = 't'; |
| 448 | $default_dir = 'd'; |
| 449 | $where_sql .= ($topic_id) ? ' p.topic_id = ' . $topic_id . ' AND' : ''; |
| 450 | |
| 451 | $sql = 'SELECT COUNT(p.post_id) AS total |
| 452 | FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t |
| 453 | $where_sql " . $db->sql_in_set('p.forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . ' |
| 454 | AND ' . $db->sql_in_set('p.post_visibility', $visibility_const) .' |
| 455 | AND t.topic_id = p.topic_id |
| 456 | AND t.topic_visibility <> p.post_visibility'; |
| 457 | |
| 458 | if ($min_time) |
| 459 | { |
| 460 | $sql .= ' AND post_time >= ' . $min_time; |
| 461 | } |
| 462 | break; |
| 463 | |
| 464 | case 'unapproved_topics': |
| 465 | case 'deleted_topics': |
| 466 | $visibility_const = ($mode == 'unapproved_topics') ? array(ITEM_UNAPPROVED, ITEM_REAPPROVE) : ITEM_DELETED; |
| 467 | $type = 'topics'; |
| 468 | $default_key = 't'; |
| 469 | $default_dir = 'd'; |
| 470 | |
| 471 | $sql = 'SELECT COUNT(topic_id) AS total |
| 472 | FROM ' . TOPICS_TABLE . " |
| 473 | $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . ' |
| 474 | AND ' . $db->sql_in_set('topic_visibility', $visibility_const); |
| 475 | |
| 476 | if ($min_time) |
| 477 | { |
| 478 | $sql .= ' AND topic_time >= ' . $min_time; |
| 479 | } |
| 480 | break; |
| 481 | |
| 482 | case 'pm_reports': |
| 483 | case 'pm_reports_closed': |
| 484 | case 'reports': |
| 485 | case 'reports_closed': |
| 486 | $pm = (strpos($mode, 'pm_') === 0) ? true : false; |
| 487 | |
| 488 | $type = ($pm) ? 'pm_reports' : 'reports'; |
| 489 | $default_key = 't'; |
| 490 | $default_dir = 'd'; |
| 491 | $limit_time_sql = ($min_time) ? "AND r.report_time >= $min_time" : ''; |
| 492 | |
| 493 | if ($topic_id) |
| 494 | { |
| 495 | $where_sql .= ' p.topic_id = ' . $topic_id . ' AND '; |
| 496 | } |
| 497 | else if ($forum_id) |
| 498 | { |
| 499 | $where_sql .= ' p.forum_id = ' . $forum_id . ' AND '; |
| 500 | } |
| 501 | else if (!$pm) |
| 502 | { |
| 503 | $where_sql .= ' ' . $db->sql_in_set('p.forum_id', get_forum_list(array('!f_read', '!m_report')), true, true) . ' AND '; |
| 504 | } |
| 505 | |
| 506 | if ($mode == 'reports' || $mode == 'pm_reports') |
| 507 | { |
| 508 | $where_sql .= ' r.report_closed = 0 AND '; |
| 509 | } |
| 510 | else |
| 511 | { |
| 512 | $where_sql .= ' r.report_closed = 1 AND '; |
| 513 | } |
| 514 | |
| 515 | if ($pm) |
| 516 | { |
| 517 | $sql = 'SELECT COUNT(r.report_id) AS total |
| 518 | FROM ' . REPORTS_TABLE . ' r, ' . PRIVMSGS_TABLE . " p |
| 519 | $where_sql r.post_id = 0 |
| 520 | AND p.msg_id = r.pm_id |
| 521 | $limit_time_sql"; |
| 522 | } |
| 523 | else |
| 524 | { |
| 525 | $sql = 'SELECT COUNT(r.report_id) AS total |
| 526 | FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . " p |
| 527 | $where_sql r.pm_id = 0 |
| 528 | AND p.post_id = r.post_id |
| 529 | $limit_time_sql"; |
| 530 | } |
| 531 | break; |
| 532 | |
| 533 | case 'viewlogs': |
| 534 | $type = 'logs'; |
| 535 | $default_key = 't'; |
| 536 | $default_dir = 'd'; |
| 537 | |
| 538 | $sql = 'SELECT COUNT(log_id) AS total |
| 539 | FROM ' . LOG_TABLE . " |
| 540 | $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_'))) . ' |
| 541 | AND log_time >= ' . $min_time . ' |
| 542 | AND log_type = ' . LOG_MOD; |
| 543 | break; |
| 544 | } |
| 545 | |
| 546 | $sort_key_val = $request->variable('sk', $default_key); |
| 547 | $sort_dir_val = $request->variable('sd', $default_dir); |
| 548 | |
| 549 | switch ($type) |
| 550 | { |
| 551 | case 'topics': |
| 552 | $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); |
| 553 | $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'tt' => $user->lang['TOPIC_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']); |
| 554 | |
| 555 | $sort_by_sql_ary = array('a' => 't.topic_first_poster_name', 't' => array('t.topic_last_post_time', 't.topic_last_post_id'), 'tt' => 't.topic_time', 'r' => (($auth->acl_get('m_approve', $forum_id)) ? 't.topic_posts_approved + t.topic_posts_unapproved + t.topic_posts_softdeleted' : 't.topic_posts_approved'), 's' => 't.topic_title', 'v' => 't.topic_views'); |
| 556 | $limit_time_sql = ($min_time) ? "AND t.topic_last_post_time >= $min_time" : ''; |
| 557 | break; |
| 558 | |
| 559 | case 'posts': |
| 560 | $limit_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); |
| 561 | $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']); |
| 562 | $sort_by_sql_ary = array('a' => 'u.username_clean', 't' => array('p.post_time', 'p.post_id'), 's' => 'p.post_subject'); |
| 563 | $limit_time_sql = ($min_time) ? "AND p.post_time >= $min_time" : ''; |
| 564 | break; |
| 565 | |
| 566 | case 'reports': |
| 567 | $limit_days = array(0 => $user->lang['ALL_REPORTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); |
| 568 | $sort_by_text = array('a' => $user->lang['AUTHOR'], 'r' => $user->lang['REPORTER'], 'p' => $user->lang['POST_TIME'], 't' => $user->lang['REPORT_TIME'], 's' => $user->lang['SUBJECT']); |
| 569 | $sort_by_sql_ary = array('a' => 'u.username_clean', 'r' => 'ru.username', 'p' => array('p.post_time', 'p.post_id'), 't' => 'r.report_time', 's' => 'p.post_subject'); |
| 570 | break; |
| 571 | |
| 572 | case 'pm_reports': |
| 573 | $limit_days = array(0 => $user->lang['ALL_REPORTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); |
| 574 | $sort_by_text = array('a' => $user->lang['AUTHOR'], 'r' => $user->lang['REPORTER'], 'p' => $user->lang['POST_TIME'], 't' => $user->lang['REPORT_TIME'], 's' => $user->lang['SUBJECT']); |
| 575 | $sort_by_sql_ary = array('a' => 'u.username_clean', 'r' => 'ru.username', 'p' => 'p.message_time', 't' => 'r.report_time', 's' => 'p.message_subject'); |
| 576 | break; |
| 577 | |
| 578 | case 'logs': |
| 579 | $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); |
| 580 | $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']); |
| 581 | |
| 582 | $sort_by_sql_ary = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation'); |
| 583 | $limit_time_sql = ($min_time) ? "AND l.log_time >= $min_time" : ''; |
| 584 | break; |
| 585 | } |
| 586 | |
| 587 | // Default total to -1 to allow editing by the event |
| 588 | $total_val = -1; |
| 589 | |
| 590 | $sort_by_sql = $sort_by_sql_ary; |
| 591 | $sort_days = $sort_days_val; |
| 592 | $sort_dir = $sort_dir_val; |
| 593 | $sort_key = $sort_key_val; |
| 594 | $total = $total_val; |
| 595 | /** |
| 596 | * This event allows you to control the SQL query used to get the total number |
| 597 | * of reports the user can access. |
| 598 | * |
| 599 | * This total is used for the pagination and for displaying the total number |
| 600 | * of reports to the user |
| 601 | * |
| 602 | * |
| 603 | * @event core.mcp_sorting_query_before |
| 604 | * @var string sql The current SQL search string |
| 605 | * @var string mode An id related to the module(s) the user is viewing |
| 606 | * @var string type Which kind of information is this being used for displaying. Posts, topics, etc... |
| 607 | * @var int forum_id The forum id of the posts the user is trying to access, if not 0 |
| 608 | * @var int topic_id The topic id of the posts the user is trying to access, if not 0 |
| 609 | * @var int sort_days The max age of the oldest report to be shown, in days |
| 610 | * @var string sort_key The way the user has decided to sort the data. |
| 611 | * The valid values must be in the keys of the sort_by_* variables |
| 612 | * @var string sort_dir Either 'd' for "DESC" or 'a' for 'ASC' in the SQL query |
| 613 | * @var int limit_days The possible max ages of the oldest report for the user to choose, in days. |
| 614 | * @var array sort_by_sql SQL text (values) for the possible names of the ways of sorting data (keys). |
| 615 | * @var array sort_by_text Language text (values) for the possible names of the ways of sorting data (keys). |
| 616 | * @var int min_time Integer with the minimum post time that the user is searching for |
| 617 | * @var int limit_time_sql Time limiting options used in the SQL query. |
| 618 | * @var int total The total number of reports that exist. Only set if you want to override the result |
| 619 | * @var string where_sql Extra information included in the WHERE clause. It must end with "WHERE" or "AND" or "OR". |
| 620 | * Set to "WHERE" and set total above -1 to override the total value |
| 621 | * @since 3.1.4-RC1 |
| 622 | */ |
| 623 | $vars = array( |
| 624 | 'sql', |
| 625 | 'mode', |
| 626 | 'type', |
| 627 | 'forum_id', |
| 628 | 'topic_id', |
| 629 | 'sort_days', |
| 630 | 'sort_key', |
| 631 | 'sort_dir', |
| 632 | 'limit_days', |
| 633 | 'sort_by_sql', |
| 634 | 'sort_by_text', |
| 635 | 'min_time', |
| 636 | 'limit_time_sql', |
| 637 | 'total', |
| 638 | 'where_sql', |
| 639 | ); |
| 640 | extract($phpbb_dispatcher->trigger_event('core.mcp_sorting_query_before', compact($vars))); |
| 641 | $sort_by_sql_ary = $sort_by_sql; |
| 642 | $sort_days_val = $sort_days; |
| 643 | $sort_key_val = $sort_key; |
| 644 | $sort_dir_val = $sort_dir; |
| 645 | $total_val = $total; |
| 646 | unset($sort_by_sql); |
| 647 | unset($sort_days); |
| 648 | unset($sort_key); |
| 649 | unset($sort_dir); |
| 650 | unset($total); |
| 651 | |
| 652 | if (!isset($sort_by_sql_ary[$sort_key_val])) |
| 653 | { |
| 654 | $sort_key_val = $default_key; |
| 655 | } |
| 656 | |
| 657 | $direction = ($sort_dir_val == 'd') ? 'DESC' : 'ASC'; |
| 658 | |
| 659 | if (is_array($sort_by_sql_ary[$sort_key_val])) |
| 660 | { |
| 661 | $sort_order_sql = implode(' ' . $direction . ', ', $sort_by_sql_ary[$sort_key_val]) . ' ' . $direction; |
| 662 | } |
| 663 | else |
| 664 | { |
| 665 | $sort_order_sql = $sort_by_sql_ary[$sort_key_val] . ' ' . $direction; |
| 666 | } |
| 667 | |
| 668 | $s_limit_days = $s_sort_key = $s_sort_dir = $sort_url = ''; |
| 669 | gen_sort_selects($limit_days, $sort_by_text, $sort_days_val, $sort_key_val, $sort_dir_val, $s_limit_days, $s_sort_key, $s_sort_dir, $sort_url); |
| 670 | |
| 671 | $template->assign_vars(array( |
| 672 | 'S_SELECT_SORT_DIR' => $s_sort_dir, |
| 673 | 'S_SELECT_SORT_KEY' => $s_sort_key, |
| 674 | 'S_SELECT_SORT_DAYS' => $s_limit_days) |
| 675 | ); |
| 676 | |
| 677 | if (($sort_days_val && $mode != 'viewlogs') || in_array($mode, array('reports', 'unapproved_topics', 'unapproved_posts', 'deleted_topics', 'deleted_posts')) || $where_sql != 'WHERE') |
| 678 | { |
| 679 | $result = $db->sql_query($sql); |
| 680 | $total_val = (int) $db->sql_fetchfield('total'); |
| 681 | $db->sql_freeresult($result); |
| 682 | } |
| 683 | else if ($total_val < -1) |
| 684 | { |
| 685 | $total_val = -1; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | /** |
| 690 | * Validate ids |
| 691 | * |
| 692 | * @param array &$ids The relevant ids to check |
| 693 | * @param string $table The table to find the ids in |
| 694 | * @param string $sql_id The ids relevant column name |
| 695 | * @param array|false $acl_list A list of permissions the user need to have |
| 696 | * @param mixed $single_forum Limit to one forum id (int) or the first forum found (true) |
| 697 | * |
| 698 | * @return bool|int False if no ids were able to be retrieved, true if at least one id left. |
| 699 | * Additionally, this value can be the forum_id assigned if $single_forum was set. |
| 700 | * Therefore checking the result for with !== false is the best method. |
| 701 | */ |
| 702 | function phpbb_check_ids(&$ids, $table, $sql_id, $acl_list = false, $single_forum = false) |
| 703 | { |
| 704 | global $db, $auth; |
| 705 | |
| 706 | if (!is_array($ids) || empty($ids)) |
| 707 | { |
| 708 | return false; |
| 709 | } |
| 710 | |
| 711 | $sql = "SELECT $sql_id, forum_id FROM $table |
| 712 | WHERE " . $db->sql_in_set($sql_id, $ids); |
| 713 | $result = $db->sql_query($sql); |
| 714 | |
| 715 | $ids = array(); |
| 716 | $forum_id = false; |
| 717 | |
| 718 | while ($row = $db->sql_fetchrow($result)) |
| 719 | { |
| 720 | if ($acl_list && $row['forum_id'] && !$auth->acl_gets($acl_list, $row['forum_id'])) |
| 721 | { |
| 722 | continue; |
| 723 | } |
| 724 | |
| 725 | if ($acl_list && !$row['forum_id'] && !$auth->acl_getf_global($acl_list)) |
| 726 | { |
| 727 | continue; |
| 728 | } |
| 729 | |
| 730 | // Limit forum? If not, just assign the id. |
| 731 | if ($single_forum === false) |
| 732 | { |
| 733 | $ids[] = $row[$sql_id]; |
| 734 | continue; |
| 735 | } |
| 736 | |
| 737 | // Limit forum to a specific forum id? |
| 738 | // This can get really tricky, because we do not want to create a failure on global topics. :) |
| 739 | if ($row['forum_id']) |
| 740 | { |
| 741 | if ($single_forum !== true && $row['forum_id'] == (int) $single_forum) |
| 742 | { |
| 743 | $forum_id = (int) $single_forum; |
| 744 | } |
| 745 | else if ($forum_id === false) |
| 746 | { |
| 747 | $forum_id = $row['forum_id']; |
| 748 | } |
| 749 | |
| 750 | if ($row['forum_id'] == $forum_id) |
| 751 | { |
| 752 | $ids[] = $row[$sql_id]; |
| 753 | } |
| 754 | } |
| 755 | else |
| 756 | { |
| 757 | // Always add a global topic |
| 758 | $ids[] = $row[$sql_id]; |
| 759 | } |
| 760 | } |
| 761 | $db->sql_freeresult($result); |
| 762 | |
| 763 | if (!count($ids)) |
| 764 | { |
| 765 | return false; |
| 766 | } |
| 767 | |
| 768 | // If forum id is false and ids populated we may have only global announcements selected (returning 0 because of (int) $forum_id) |
| 769 | |
| 770 | return ($single_forum === false) ? true : (int) $forum_id; |
| 771 | } |