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