|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* Advanced BBCode Box |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright (c) 2013 Matt Friedman |
|
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace vse\abbc3\core; |
|
12
|
|
|
|
|
13
|
|
|
use phpbb\db\driver\driver_interface; |
|
14
|
|
|
use phpbb\extension\manager; |
|
15
|
|
|
use phpbb\user; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* ABBC3 core BBCodes display class |
|
19
|
|
|
*/ |
|
20
|
|
|
class bbcodes_display |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var driver_interface */ |
|
23
|
|
|
protected $db; |
|
24
|
|
|
|
|
25
|
|
|
/** @var manager */ |
|
26
|
|
|
protected $extension_manager; |
|
27
|
|
|
|
|
28
|
|
|
/** @var user */ |
|
29
|
|
|
protected $user; |
|
30
|
|
|
|
|
31
|
|
|
/** @var string */ |
|
32
|
|
|
protected $ext_root_path; |
|
33
|
|
|
|
|
34
|
|
|
/** @var array */ |
|
35
|
|
|
protected $memberships; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Constructor |
|
39
|
|
|
* |
|
40
|
|
|
* @param driver_interface $db Database connection |
|
41
|
|
|
* @param manager $extension_manager Extension manager object |
|
42
|
|
|
* @param user $user User object |
|
43
|
|
|
* @param string $ext_root_path Path to abbc3 extension root |
|
44
|
|
|
* @access public |
|
45
|
|
|
*/ |
|
46
|
11 |
|
public function __construct(driver_interface $db, manager $extension_manager, user $user, $ext_root_path) |
|
47
|
|
|
{ |
|
48
|
11 |
|
$this->db = $db; |
|
49
|
11 |
|
$this->extension_manager = $extension_manager; |
|
50
|
11 |
|
$this->user = $user; |
|
51
|
11 |
|
$this->ext_root_path = $ext_root_path; |
|
52
|
11 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Display allowed custom BBCodes with icons |
|
56
|
|
|
* |
|
57
|
|
|
* Uses GIF images named exactly the same as the bbcode_tag |
|
58
|
|
|
* |
|
59
|
|
|
* @param array $custom_tags Template data of the bbcode |
|
60
|
|
|
* @param array $row The data of the bbcode |
|
61
|
|
|
* @return array Update template data of the bbcode |
|
62
|
|
|
* @access public |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function display_custom_bbcodes($custom_tags, $row) |
|
65
|
|
|
{ |
|
66
|
1 |
|
static $images = array(); |
|
67
|
|
|
|
|
68
|
1 |
|
if (empty($images)) |
|
69
|
1 |
|
{ |
|
70
|
1 |
|
$images = $this->get_images(); |
|
71
|
1 |
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
$bbcode_img = 'abbc3/images/icons/' . strtolower(rtrim($row['bbcode_tag'], '=')) . '.gif'; |
|
74
|
|
|
|
|
75
|
1 |
|
$custom_tags['BBCODE_IMG'] = (isset($images['ext/' . $bbcode_img])) ? 'ext/vse/' . $bbcode_img : ''; |
|
76
|
1 |
|
$custom_tags['S_CUSTOM_BBCODE_ALLOWED'] = (!empty($row['bbcode_group'])) ? $this->user_in_bbcode_group($row['bbcode_group']) : true; |
|
77
|
|
|
|
|
78
|
1 |
|
return $custom_tags; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Set custom BBCodes to 'disabled' if they are not allowed to be used |
|
83
|
|
|
* |
|
84
|
|
|
* @param array $bbcodes Array of bbcode data for use in parsing |
|
85
|
|
|
* @param array $rowset Array of bbcode data from the database |
|
86
|
|
|
* @return array The bbcodes data array |
|
87
|
|
|
* @access public |
|
88
|
|
|
* |
|
89
|
|
|
* @deprecated 3.2.0. Provides bc for phpBB 3.1.x. |
|
90
|
|
|
*/ |
|
91
|
|
|
public function allow_custom_bbcodes($bbcodes, $rowset) |
|
92
|
|
|
{ |
|
93
|
|
|
foreach ($rowset as $row) |
|
94
|
|
|
{ |
|
95
|
|
|
if (!$this->user_in_bbcode_group($row['bbcode_group'])) |
|
96
|
|
|
{ |
|
97
|
|
|
$bbcodes[$row['bbcode_tag']]['disabled'] = true; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $bbcodes; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Determine if a user is in a group allowed to use a custom BBCode |
|
106
|
|
|
* |
|
107
|
|
|
* @param string $group_ids Allowed group IDs, comma separated |
|
108
|
|
|
* @return bool Return true if allowed to use BBCode |
|
109
|
|
|
* @access public |
|
110
|
|
|
*/ |
|
111
|
11 |
|
public function user_in_bbcode_group($group_ids = '') |
|
112
|
|
|
{ |
|
113
|
|
|
if ($group_ids) |
|
114
|
11 |
|
{ |
|
115
|
|
|
// Convert string to an array |
|
116
|
7 |
|
if (!is_array($group_ids)) |
|
117
|
7 |
|
{ |
|
118
|
5 |
|
$group_ids = explode(',', $group_ids); |
|
119
|
5 |
|
} |
|
120
|
|
|
|
|
121
|
|
|
// Load the user's group memberships |
|
122
|
7 |
|
$this->load_memberships(); |
|
123
|
|
|
|
|
124
|
7 |
|
return (bool) sizeof(array_intersect($this->memberships, $group_ids)); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
// If we get here, there were no group restrictions so everyone can use this BBCode |
|
128
|
4 |
|
return true; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Get image paths/names from ABBC3's icons folder |
|
133
|
|
|
* |
|
134
|
|
|
* @return array File data from ./ext/vse/abbc3/images/icons |
|
135
|
|
|
* @access protected |
|
136
|
|
|
*/ |
|
137
|
1 |
|
protected function get_images() |
|
138
|
|
|
{ |
|
139
|
1 |
|
$finder = $this->extension_manager->get_finder(); |
|
140
|
|
|
|
|
141
|
|
|
return $finder |
|
142
|
1 |
|
->extension_suffix('.gif') |
|
143
|
1 |
|
->extension_directory('/images/icons') |
|
144
|
1 |
|
->find_from_extension('abbc3', $this->ext_root_path); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Load this user's group memberships if it's not cached already |
|
149
|
|
|
* |
|
150
|
|
|
* @return null |
|
151
|
|
|
* @access protected |
|
152
|
|
|
*/ |
|
153
|
7 |
|
protected function load_memberships() |
|
154
|
|
|
{ |
|
155
|
7 |
|
if (isset($this->memberships)) |
|
156
|
7 |
|
{ |
|
157
|
1 |
|
return; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
7 |
|
$this->memberships = array(); |
|
161
|
|
|
$sql = 'SELECT group_id |
|
162
|
7 |
|
FROM ' . USER_GROUP_TABLE . ' |
|
163
|
7 |
|
WHERE user_id = ' . (int) $this->user->data['user_id'] . ' |
|
164
|
7 |
|
AND user_pending = 0'; |
|
165
|
7 |
|
$result = $this->db->sql_query($sql); |
|
166
|
7 |
|
while ($row = $this->db->sql_fetchrow($result)) |
|
167
|
|
|
{ |
|
168
|
7 |
|
$this->memberships[] = $row['group_id']; |
|
169
|
7 |
|
} |
|
170
|
7 |
|
$this->db->sql_freeresult($result); |
|
171
|
7 |
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|