1 | <?php |
||
22 | class bbcodes_display |
||
23 | { |
||
24 | /** @var config */ |
||
25 | protected $config; |
||
26 | |||
27 | /** @var driver_interface */ |
||
28 | protected $db; |
||
29 | |||
30 | /** @var manager */ |
||
31 | protected $extension_manager; |
||
32 | |||
33 | /** @var user */ |
||
34 | protected $user; |
||
35 | |||
36 | /** @var string */ |
||
37 | protected $root_path; |
||
38 | |||
39 | /** @var array */ |
||
40 | protected $memberships; |
||
41 | |||
42 | /** |
||
43 | * Constructor |
||
44 | * |
||
45 | * @param config $config Config object |
||
46 | * @param driver_interface $db Database connection |
||
47 | 13 | * @param manager $extension_manager Extension manager object |
|
48 | * @param user $user User object |
||
49 | 13 | * @param string $root_path Path to phpBB root |
|
50 | 13 | * @access public |
|
51 | 13 | */ |
|
52 | 13 | public function __construct(config $config, driver_interface $db, manager $extension_manager, user $user, $root_path) |
|
53 | 13 | { |
|
54 | $this->config = $config; |
||
55 | $this->db = $db; |
||
56 | $this->extension_manager = $extension_manager; |
||
57 | $this->user = $user; |
||
58 | $this->root_path = $root_path; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Display allowed custom BBCodes with icons |
||
63 | * |
||
64 | * Uses GIF images named exactly the same as the bbcode_tag |
||
65 | 1 | * |
|
66 | * @param array $custom_tags Template data of the bbcode |
||
67 | 1 | * @param array $row The data of the bbcode |
|
68 | * @return array Update template data of the bbcode |
||
69 | 1 | * @access public |
|
70 | 1 | */ |
|
71 | 1 | public function display_custom_bbcodes($custom_tags, $row) |
|
72 | 1 | { |
|
73 | $icons = $this->get_icons(); |
||
74 | 1 | ||
75 | 1 | $icon_tag = strtolower(rtrim($row['bbcode_tag'], '=')); |
|
76 | |||
77 | 1 | $custom_tags['BBCODE_IMG'] = isset($icons[$icon_tag]) ? $icons[$icon_tag] : ''; |
|
78 | 1 | $custom_tags['S_CUSTOM_BBCODE_ALLOWED'] = !empty($row['bbcode_group']) ? $this->user_in_bbcode_group($row['bbcode_group']) : true; |
|
79 | |||
80 | 1 | return $custom_tags; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * Disable BBCodes not allowed by a user's group(s). |
||
85 | * |
||
86 | * @param parser $service Object from the text_formatter.parser service |
||
87 | * @return void |
||
88 | * @access public |
||
89 | */ |
||
90 | 3 | public function allow_custom_bbcodes(parser $service) |
|
102 | |||
103 | /** |
||
104 | * Determine if a user is in a group allowed to use a custom BBCode |
||
105 | * |
||
106 | * @param string|array $group_ids Allowed group IDs, comma separated string or array |
||
107 | * @return bool Return true if allowed to use BBCode |
||
108 | * @access public |
||
109 | */ |
||
110 | 13 | public function user_in_bbcode_group($group_ids = '') |
|
129 | |||
130 | /** |
||
131 | * Get paths/names to ABBC3's BBCode icons. |
||
132 | * Search in ABBC3's icons dir and also the core's images dir. |
||
133 | * |
||
134 | * @return array Array of icon paths: ['foo' => './ext/vse/abbc3/images/icons/foo.png'] |
||
135 | * @access public |
||
136 | 1 | */ |
|
137 | public function get_icons() |
||
161 | 9 | ||
162 | 9 | /** |
|
163 | 9 | * Load this user's group memberships if it's not cached already |
|
164 | 9 | * |
|
165 | * @access protected |
||
166 | 9 | */ |
|
167 | 9 | protected function load_memberships() |
|
186 | } |
||
187 |