Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| delete_cookies | |
0.00% |
0 / 33 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| handle | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
42 | |||
| 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 | namespace phpbb\ucp\controller; |
| 15 | |
| 16 | use phpbb\config\config; |
| 17 | use phpbb\controller\helper; |
| 18 | use phpbb\event\dispatcher_interface; |
| 19 | use phpbb\language\language; |
| 20 | use phpbb\request\request_interface; |
| 21 | use phpbb\user; |
| 22 | |
| 23 | class delete_cookies |
| 24 | { |
| 25 | /** @var config */ |
| 26 | private $config; |
| 27 | |
| 28 | /** @var dispatcher_interface */ |
| 29 | private $dispatcher; |
| 30 | |
| 31 | /** @var helper */ |
| 32 | private $helper; |
| 33 | |
| 34 | /** @var language */ |
| 35 | private $language; |
| 36 | |
| 37 | /** @var request_interface */ |
| 38 | private $request; |
| 39 | |
| 40 | /** @var user */ |
| 41 | private $user; |
| 42 | |
| 43 | /** @var string phpBB root path */ |
| 44 | private $phpbb_root_path; |
| 45 | |
| 46 | /** @var string PHP extension */ |
| 47 | private $php_ext; |
| 48 | |
| 49 | /** |
| 50 | * Constructor for delete_cookies controller |
| 51 | * |
| 52 | * @param config $config |
| 53 | * @param dispatcher_interface $dispatcher |
| 54 | * @param helper $helper |
| 55 | * @param language $language |
| 56 | * @param request_interface $request |
| 57 | * @param user $user |
| 58 | * @param string $phpbb_root_path |
| 59 | * @param string $php_ext |
| 60 | */ |
| 61 | public function __construct(config $config, dispatcher_interface $dispatcher, helper $helper, language $language, request_interface $request, user $user, string $phpbb_root_path, string $php_ext) |
| 62 | { |
| 63 | $this->config = $config; |
| 64 | $this->dispatcher = $dispatcher; |
| 65 | $this->helper = $helper; |
| 66 | $this->language = $language; |
| 67 | $this->request = $request; |
| 68 | $this->user = $user; |
| 69 | $this->phpbb_root_path = $phpbb_root_path; |
| 70 | $this->php_ext = $php_ext; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Handle delete cookies requests |
| 75 | * |
| 76 | * @return void |
| 77 | */ |
| 78 | public function handle() |
| 79 | { |
| 80 | $this->language->add_lang(['ucp']); |
| 81 | |
| 82 | // Delete Cookies with dynamic names (do NOT delete poll cookies) |
| 83 | if (confirm_box(true)) |
| 84 | { |
| 85 | $set_time = time() - 31536000; |
| 86 | |
| 87 | foreach ($this->request->variable_names(request_interface::COOKIE) as $cookie_name) |
| 88 | { |
| 89 | // Only delete board cookies |
| 90 | if (strpos($cookie_name, $this->config['cookie_name'] . '_') !== 0) |
| 91 | { |
| 92 | continue; |
| 93 | } |
| 94 | |
| 95 | $cookie_name = str_replace($this->config['cookie_name'] . '_', '', $cookie_name); |
| 96 | |
| 97 | /** |
| 98 | * Event to save custom cookies from deletion |
| 99 | * |
| 100 | * @event core.ucp_delete_cookies |
| 101 | * @var string cookie_name Cookie name to checking |
| 102 | * @var bool retain_cookie Do we retain our cookie or not, true if retain |
| 103 | * @since 3.1.3-RC1 |
| 104 | * @changed 3.3.13-RC1 Moved to new delete_cookies controller |
| 105 | */ |
| 106 | $retain_cookie = false; |
| 107 | $vars = ['cookie_name', 'retain_cookie']; |
| 108 | extract($this->dispatcher->trigger_event('core.ucp_delete_cookies', compact($vars))); |
| 109 | if ($retain_cookie) |
| 110 | { |
| 111 | continue; |
| 112 | } |
| 113 | |
| 114 | // Polls are stored as {cookie_name}_poll_{topic_id}, cookie_name_ got removed, therefore checking for poll_ |
| 115 | if (strpos($cookie_name, 'poll_') !== 0) |
| 116 | { |
| 117 | $this->user->set_cookie($cookie_name, '', $set_time); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | $this->user->set_cookie('track', '', $set_time); |
| 122 | $this->user->set_cookie('u', '', $set_time); |
| 123 | $this->user->set_cookie('k', '', $set_time); |
| 124 | $this->user->set_cookie('sid', '', $set_time); |
| 125 | |
| 126 | // We destroy the session here, the user will be logged out nevertheless |
| 127 | $this->user->session_kill(); |
| 128 | $this->user->session_begin(); |
| 129 | |
| 130 | meta_refresh(3, $this->helper->route('phpbb_index_controller')); |
| 131 | |
| 132 | $message = $this->language->lang('COOKIES_DELETED') . '<br><br>' . $this->language->lang('RETURN_INDEX', '<a href="' . $this->helper->route('phpbb_index_controller') . '">', '</a>'); |
| 133 | trigger_error($message); |
| 134 | } |
| 135 | else |
| 136 | { |
| 137 | confirm_box(false, 'DELETE_COOKIES', ''); |
| 138 | } |
| 139 | |
| 140 | redirect($this->helper->route('phpbb_index_controller')); |
| 141 | } |
| 142 | } |