1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* phpBB Forum Mapper. A helper class for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @author Dark❶, https://dark1.tech |
7
|
|
|
* @version 1.0.0 |
8
|
|
|
* @source https://github.com/dark-1/phpbbForumMap |
9
|
|
|
* @copyright (c) 2020, Dark❶, https://dark1.tech |
10
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
11
|
|
|
* |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace dark1\reducesearchindex\core; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @ignore |
18
|
|
|
*/ |
19
|
|
|
use phpbb\db\driver\driver_interface as db_driver; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* phpBB Forum Mapper. |
23
|
|
|
*/ |
24
|
|
|
abstract class forum_map |
25
|
|
|
{ |
26
|
|
|
/** @var \phpbb\db\driver\driver_interface */ |
27
|
|
|
protected $db; |
28
|
|
|
|
29
|
|
|
/** @var int Latest Right ID*/ |
30
|
|
|
private $right; |
31
|
|
|
|
32
|
|
|
/** @var string Padding */ |
33
|
|
|
private $padding; |
34
|
|
|
|
35
|
|
|
/** @var string Padding Spacer */ |
36
|
|
|
private $padding_spacer; |
37
|
|
|
|
38
|
|
|
/** @var string Padding Symbol */ |
39
|
|
|
private $padding_symbol; |
40
|
|
|
|
41
|
|
|
/** @var array Forum Template Row */ |
42
|
|
|
private $forum_tpl_row; |
43
|
|
|
|
44
|
|
|
/** @var array All Forum Data */ |
45
|
|
|
private $forums; |
46
|
|
|
|
47
|
|
|
/** @var array Forum SQL Column */ |
48
|
|
|
private $sql_col; |
49
|
|
|
|
50
|
|
|
/** @var array Store Padding for each Forum */ |
51
|
|
|
private $padding_store; |
52
|
|
|
|
53
|
|
|
/** @var string Default Padding Spacer */ |
54
|
|
|
const PADDING_SPACER = ' '; |
55
|
|
|
|
56
|
|
|
/** @var string Default Padding Symbol */ |
57
|
|
|
const PADDING_SYMBOL = ' ↳ '; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Constructor. |
61
|
|
|
* |
62
|
|
|
* @param \phpbb\db\driver\driver_interface $db Database object |
63
|
|
|
*/ |
64
|
|
|
public function __construct(db_driver $db) |
65
|
|
|
{ |
66
|
|
|
$this->db = $db; |
67
|
|
|
$this->right = 0; |
68
|
|
|
$this->padding = ''; |
69
|
|
|
$this->padding_spacer = ''; |
70
|
|
|
$this->padding_symbol = ''; |
71
|
|
|
$this->forum_tpl_row = []; |
72
|
|
|
$this->forums = []; |
73
|
|
|
$this->sql_col = []; |
74
|
|
|
$this->padding_store = ['0' => '']; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Display the Forum options. |
79
|
|
|
* |
80
|
|
|
* @param string $padding_spacer Padding Spacer |
81
|
|
|
* @param string $padding_symbol Padding Symbol |
82
|
|
|
* |
83
|
|
|
* @return array |
84
|
|
|
* @access public |
85
|
|
|
*/ |
86
|
|
|
public function main($padding_spacer = '', $padding_symbol = '') |
87
|
|
|
{ |
88
|
|
|
$this->padding_spacer = !empty($padding_spacer) ? $padding_spacer : self::PADDING_SPACER; |
89
|
|
|
$this->padding_symbol = !empty($padding_symbol) ? $padding_symbol : self::PADDING_SYMBOL; |
90
|
|
|
$this->sql_col = $this->get_forums_cust_sql_col(); |
91
|
|
|
|
92
|
|
|
$this->get_forums(); |
93
|
|
|
$this->parse_forums(); |
94
|
|
|
|
95
|
|
|
return $this->forum_tpl_row; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get forums. |
100
|
|
|
* |
101
|
|
|
* @return void |
102
|
|
|
* @access private |
103
|
|
|
*/ |
104
|
|
|
private function get_forums() |
105
|
|
|
{ |
106
|
|
|
$sql = 'SELECT forum_id, forum_type, forum_name, parent_id, left_id, right_id' . (!empty($this->sql_col) ? ', ' . implode(', ', $this->sql_col) : '') . ' FROM ' . FORUMS_TABLE . ' ORDER BY left_id ASC'; |
107
|
|
|
$result = $this->db->sql_query($sql); |
108
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
109
|
|
|
{ |
110
|
|
|
$this->forums[] = $row; |
111
|
|
|
} |
112
|
|
|
$this->db->sql_freeresult($result); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Parse forums. |
117
|
|
|
* |
118
|
|
|
* @return void |
119
|
|
|
* @access private |
120
|
|
|
*/ |
121
|
|
|
private function parse_forums() |
122
|
|
|
{ |
123
|
|
|
foreach ($this->forums as $row) |
124
|
|
|
{ |
125
|
|
|
$this->get_forum_padding($row['parent_id'], $row['left_id'], $row['right_id']); |
126
|
|
|
$tpl_row = $this->get_forum_tpl_row($row) + $this->get_forum_cust_tpl_row($row); |
127
|
|
|
|
128
|
|
|
if (!empty($tpl_row)) |
129
|
|
|
{ |
130
|
|
|
$this->forum_tpl_row[] = $tpl_row; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Get forum padding. |
137
|
|
|
* |
138
|
|
|
* @param int $parent_id Forum parent ID |
139
|
|
|
* @param int $left_id Forum left ID |
140
|
|
|
* @param int $right_id Forum right ID |
141
|
|
|
* |
142
|
|
|
* @return void |
143
|
|
|
* @access private |
144
|
|
|
*/ |
145
|
|
|
private function get_forum_padding($parent_id, $left_id, $right_id) |
146
|
|
|
{ |
147
|
|
|
if ($left_id < $this->right) |
148
|
|
|
{ |
149
|
|
|
$this->padding .= $this->padding_spacer; |
150
|
|
|
$this->padding_store[$parent_id] = $this->padding; |
151
|
|
|
} |
152
|
|
|
else if ($left_id > $this->right + 1) |
153
|
|
|
{ |
154
|
|
|
$this->padding = (isset($this->padding_store[$parent_id])) ? $this->padding_store[$parent_id] : ''; |
155
|
|
|
} |
156
|
|
|
$this->right = $right_id; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Get forum template row. |
161
|
|
|
* |
162
|
|
|
* @param array $row Forum row |
163
|
|
|
* |
164
|
|
|
* @return array |
165
|
|
|
* @access private |
166
|
|
|
*/ |
167
|
|
|
private function get_forum_tpl_row($row) |
168
|
|
|
{ |
169
|
|
|
$tpl_row = []; |
170
|
|
|
// Normal forums have configuration setting |
171
|
|
|
if ($row['forum_type'] == FORUM_POST) |
172
|
|
|
{ |
173
|
|
|
// The labels for all the inputs are supposed to be constructed based on the forum IDs to make it easy to know which |
174
|
|
|
$tpl_row = [ |
175
|
|
|
'S_IS_CAT' => false, |
176
|
|
|
'FORUM_PAD' => $this->padding . $this->padding_symbol, |
177
|
|
|
'FORUM_NAME' => $row['forum_name'], |
178
|
|
|
'FORUM_ID' => $row['forum_id'], |
179
|
|
|
]; |
180
|
|
|
} |
181
|
|
|
// Category forums are displayed for organizational purposes, but have no configuration setting |
182
|
|
|
else if ($row['forum_type'] == FORUM_CAT) |
183
|
|
|
{ |
184
|
|
|
$tpl_row = [ |
185
|
|
|
'S_IS_CAT' => true, |
186
|
|
|
'FORUM_PAD' => $this->padding . $this->padding_symbol, |
187
|
|
|
'FORUM_NAME' => $row['forum_name'], |
188
|
|
|
]; |
189
|
|
|
} |
190
|
|
|
// Other forum types (Example: links) are ignored |
191
|
|
|
return $tpl_row; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Get forum custom SQL Column. |
196
|
|
|
* |
197
|
|
|
* @return array |
198
|
|
|
* @access protected |
199
|
|
|
*/ |
200
|
|
|
abstract protected function get_forums_cust_sql_col(); |
201
|
|
|
/** @example : |
202
|
|
|
{ |
203
|
|
|
// For one forum table coloumn |
204
|
|
|
return ['dark1_ext_enable']; |
205
|
|
|
// OR |
206
|
|
|
// For two or more forum table coloumn |
207
|
|
|
return ['dark1_ext_enable', 'dark1_ext_value']; |
208
|
|
|
} |
209
|
|
|
*/ |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Get forum custom template row. |
213
|
|
|
* |
214
|
|
|
* @param array $row Forum row |
215
|
|
|
* |
216
|
|
|
* @return array |
217
|
|
|
* @access protected |
218
|
|
|
*/ |
219
|
|
|
abstract protected function get_forum_cust_tpl_row($row); |
220
|
|
|
/** @example : |
221
|
|
|
{ |
222
|
|
|
$tpl_row = []; |
223
|
|
|
if ($row['forum_type'] == FORUM_POST) |
224
|
|
|
{ |
225
|
|
|
// Array to be joined with original $tpl_row |
226
|
|
|
$tpl_row = [ |
227
|
|
|
'ENABLE' => $row['dark1_ext_enable'], |
228
|
|
|
// If more than one |
229
|
|
|
'VALUE' => $row['dark1_ext_value'], |
230
|
|
|
]; |
231
|
|
|
} |
232
|
|
|
return $tpl_row; |
233
|
|
|
} |
234
|
|
|
*/ |
235
|
|
|
} |
236
|
|
|
|