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