|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* Reduce Search Index [RSI]. An extension for the phpBB Forum Software package. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright (c) 2020-forever, Dark❶, https://dark1.tech |
|
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace dark1\reducesearchindex\controller; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @ignore |
|
15
|
|
|
*/ |
|
16
|
|
|
use dark1\reducesearchindex\core\consts; |
|
17
|
|
|
use phpbb\language\language; |
|
18
|
|
|
use phpbb\log\log; |
|
19
|
|
|
use phpbb\request\request; |
|
20
|
|
|
use phpbb\template\template; |
|
21
|
|
|
use phpbb\user; |
|
22
|
|
|
use phpbb\db\driver\driver_interface as db_driver; |
|
23
|
|
|
use phpbb\cache\driver\driver_interface as cache_driver; |
|
24
|
|
|
use dark1\reducesearchindex\core\forum_map_rsi; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Reduce Search Index [RSI] ACP controller Forum. |
|
28
|
|
|
*/ |
|
29
|
|
|
class acp_forum extends acp_base |
|
30
|
|
|
{ |
|
31
|
|
|
/** @var db_driver */ |
|
32
|
|
|
protected $db; |
|
33
|
|
|
|
|
34
|
|
|
/** @var cache_driver */ |
|
35
|
|
|
protected $cache; |
|
36
|
|
|
|
|
37
|
|
|
/** @var forum_map_rsi */ |
|
38
|
|
|
protected $forum_map_rsi; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Constructor. |
|
42
|
|
|
* |
|
43
|
|
|
* @param language $language Language object |
|
44
|
|
|
* @param log $log Log object |
|
45
|
|
|
* @param request $request Request object |
|
46
|
|
|
* @param template $template Template object |
|
47
|
|
|
* @param user $user User object |
|
48
|
|
|
* @param db_driver $db Database object |
|
49
|
|
|
* @param cache_driver $cache Cache object |
|
50
|
|
|
* @param forum_map_rsi $forum_map_rsi Forum Map RSI |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct(language $language, log $log, request $request, template $template, user $user, db_driver $db, cache_driver $cache, forum_map_rsi $forum_map_rsi) |
|
53
|
|
|
{ |
|
54
|
|
|
parent::__construct($language, $log, $request, $template, $user); |
|
55
|
|
|
|
|
56
|
|
|
$this->db = $db; |
|
57
|
|
|
$this->cache = $cache; |
|
58
|
|
|
$this->forum_map_rsi = $forum_map_rsi; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Display the options a user can configure for Forum Mode. |
|
63
|
|
|
* |
|
64
|
|
|
* @return void |
|
65
|
|
|
* @access public |
|
66
|
|
|
*/ |
|
67
|
|
|
public function handle() |
|
68
|
|
|
{ |
|
69
|
|
|
// Is the form being submitted to us? |
|
70
|
|
|
if ($this->request->is_set_post('submit')) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->check_form_on_submit(); |
|
73
|
|
|
$this->submit_forums(); |
|
74
|
|
|
$this->success_form_on_submit(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
// Set output variables for display in the template |
|
78
|
|
|
$this->print_forums(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Display the Forum options. |
|
83
|
|
|
* |
|
84
|
|
|
* @return void |
|
85
|
|
|
* @access private |
|
86
|
|
|
*/ |
|
87
|
|
|
private function print_forums() |
|
88
|
|
|
{ |
|
89
|
|
|
$forum_tpl_rows = $this->forum_map_rsi->main(); |
|
90
|
|
|
|
|
91
|
|
|
foreach ($forum_tpl_rows as $tpl_row) |
|
92
|
|
|
{ |
|
93
|
|
|
$this->template->assign_block_vars('forumrow', $tpl_row); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Submit the Forum options. |
|
99
|
|
|
* |
|
100
|
|
|
* @return void |
|
101
|
|
|
* @access private |
|
102
|
|
|
*/ |
|
103
|
|
|
private function submit_forums() |
|
104
|
|
|
{ |
|
105
|
|
|
// Set the options the user configured |
|
106
|
|
|
$forum_enable = $this->request->variable('forum_enable', [0 => 0]); |
|
107
|
|
|
$forum_enable = array_chunk($forum_enable, 50, true); |
|
108
|
|
|
foreach ($forum_enable as $forums_chunk) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->db->sql_transaction('begin'); |
|
111
|
|
|
foreach ($forums_chunk as $forum_id => $enable) |
|
112
|
|
|
{ |
|
113
|
|
|
$sql = 'UPDATE ' . FORUMS_TABLE . ' SET dark1_rsi_f_enable = ' . (int) $enable . ' WHERE forum_id = ' . (int) $forum_id; |
|
114
|
|
|
$this->db->sql_query($sql); |
|
115
|
|
|
} |
|
116
|
|
|
$this->db->sql_transaction('commit'); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$this->cache->destroy(consts::CACHE_KEY); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|