1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Advanced BBCode Box |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2017 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\language\language; |
15
|
|
|
use phpbb\template\template; |
16
|
|
|
use phpbb\user; |
17
|
|
|
use vse\abbc3\ext; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* ABBC3 core BBCodes parser class |
21
|
|
|
*/ |
22
|
|
|
class bbcodes_help |
23
|
|
|
{ |
24
|
|
|
/** @var driver_interface */ |
25
|
|
|
protected $db; |
26
|
|
|
|
27
|
|
|
/** @var language */ |
28
|
|
|
protected $language; |
29
|
|
|
|
30
|
|
|
/** @var template */ |
31
|
|
|
protected $template; |
32
|
|
|
|
33
|
|
|
/** @var user */ |
34
|
|
|
protected $user; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Constructor |
38
|
|
|
* |
39
|
|
|
* @param \phpbb\db\driver\driver_interface $db |
40
|
|
|
* @param language $language |
41
|
|
|
* @param \phpbb\template\template $template |
42
|
|
|
* @param \phpbb\user $user |
43
|
|
|
*/ |
44
|
|
|
public function __construct(driver_interface $db, language $language, template $template, user $user) |
45
|
|
|
{ |
46
|
|
|
$this->db = $db; |
47
|
|
|
$this->language = $language; |
48
|
|
|
$this->template = $template; |
49
|
|
|
$this->user = $user; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Generate BBCode help FAQ for ABBC3's custom BBCodes |
54
|
|
|
*/ |
55
|
|
|
public function faq() |
56
|
|
|
{ |
57
|
|
|
// Set the block template data |
58
|
|
|
$this->template->assign_block_vars('faq_block', [ |
59
|
|
|
'BLOCK_TITLE' => $this->language->lang('ABBC3_FAQ_TITLE'), |
60
|
|
|
'SWITCH_COLUMN' => false, |
61
|
|
|
]); |
62
|
|
|
|
63
|
|
|
$example_text = $this->language->lang('ABBC3_FAQ_SAMPLE_TEXT'); |
64
|
|
|
$abbc3_faq_data = array_intersect_key([ |
65
|
|
|
'ABBC3_FONT_HELPLINE' => "[font=Comic Sans MS]{$example_text}[/font]", |
66
|
|
|
'ABBC3_HIGHLIGHT_HELPLINE' => "[highlight=yellow]{$example_text}[/highlight]", |
67
|
|
|
'ABBC3_ALIGN_HELPLINE' => "[align=center]{$example_text}[/align]", |
68
|
|
|
'ABBC3_FLOAT_HELPLINE' => "[float=right]{$example_text}[/float]", |
69
|
|
|
'ABBC3_STRIKE_HELPLINE' => "[s]{$example_text}[/s]", |
70
|
|
|
'ABBC3_SUB_HELPLINE' => "[sub]{$example_text}[/sub] {$example_text}", |
71
|
|
|
'ABBC3_SUP_HELPLINE' => "[sup]{$example_text}[/sup] {$example_text}", |
72
|
|
|
'ABBC3_GLOW_HELPLINE' => "[glow=red]{$example_text}[/glow]", |
73
|
|
|
'ABBC3_SHADOW_HELPLINE' => "[shadow=blue]{$example_text}[/shadow]", |
74
|
|
|
'ABBC3_DROPSHADOW_HELPLINE' => "[dropshadow=blue]{$example_text}[/dropshadow]", |
75
|
|
|
'ABBC3_BLUR_HELPLINE' => "[blur=blue]{$example_text}[/blur]", |
76
|
|
|
'ABBC3_FADE_HELPLINE' => "[fade]{$example_text}[/fade]", |
77
|
|
|
'ABBC3_PREFORMAT_HELPLINE' => "[pre]{$example_text}\n\t{$example_text}[/pre]", |
78
|
|
|
'ABBC3_DIR_HELPLINE' => "[dir=rtl]{$example_text}[/dir]", |
79
|
|
|
'ABBC3_MARQUEE_HELPLINE' => "[marq=left]{$example_text}[/marq]", |
80
|
|
|
'ABBC3_SPOILER_HELPLINE' => "[spoil]{$example_text}[/spoil]", |
81
|
|
|
'ABBC3_HIDDEN_HELPLINE' => "[hidden]{$example_text}[/hidden]", |
82
|
|
|
'ABBC3_MOD_HELPLINE' => "[mod=\"{$this->language->lang('USERNAME')}\"]{$example_text}[/mod]", |
83
|
|
|
'ABBC3_OFFTOPIC_HELPLINE' => "[offtopic]{$example_text}[/offtopic]", |
84
|
|
|
'ABBC3_NFO_HELPLINE' => '[nfo]༼ つ ◕_◕ ༽つ ʕ•ᴥ•ʔ ¯\_(ツ)_/¯[/nfo]', |
85
|
|
|
'ABBC3_BBVIDEO_HELPLINE' => '[BBvideo=' . ext::BBVIDEO_WIDTH . ',' . ext::BBVIDEO_HEIGHT . ']http://www.youtube.com/watch?v=sP4NMoJcFd4[/BBvideo]', |
86
|
|
|
], $this->allowed_bbcodes()); |
87
|
|
|
|
88
|
|
|
// Process faq data for display as parsed and un-parsed bbcodes |
89
|
|
|
foreach ($abbc3_faq_data as $key => $question) |
90
|
|
|
{ |
91
|
|
|
$uid = $bitfield = $flags = ''; |
92
|
|
|
generate_text_for_storage($question, $uid, $bitfield, $flags, true); |
93
|
|
|
$example = generate_text_for_edit($question, $uid, $flags); |
94
|
|
|
$result = generate_text_for_display($question, $uid, $bitfield, $flags); |
95
|
|
|
$title = explode(':', $this->language->lang($key), 2); |
96
|
|
|
|
97
|
|
|
$this->template->assign_block_vars('faq_block.faq_row', [ |
98
|
|
|
'FAQ_QUESTION' => $title[0], |
99
|
|
|
'FAQ_ANSWER' => $this->language->lang('ABBC3_FAQ_ANSWER', $title[1], $example['text'], $result), |
100
|
|
|
]); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Get custom BBCodes the current user is allowed to use |
106
|
|
|
* |
107
|
|
|
* @return array |
108
|
|
|
*/ |
109
|
|
|
protected function allowed_bbcodes() |
110
|
|
|
{ |
111
|
|
|
$allowed = []; |
112
|
|
|
|
113
|
|
|
$sql = 'SELECT bbcode_helpline |
114
|
|
|
FROM ' . BBCODES_TABLE . ' |
115
|
|
|
WHERE bbcode_helpline ' . $this->db->sql_like_expression('ABBC3_' . $this->db->get_any_char()) . " |
116
|
|
|
AND (bbcode_group = '' |
117
|
|
|
OR bbcode_group IN ( |
118
|
|
|
SELECT group_id |
119
|
|
|
FROM " . USER_GROUP_TABLE . ' |
120
|
|
|
WHERE user_id = ' . (int) $this->user->data['user_id'] . '))'; |
121
|
|
|
|
122
|
|
|
$result = $this->db->sql_query($sql); |
123
|
|
|
|
124
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
125
|
|
|
{ |
126
|
|
|
$allowed[$row['bbcode_helpline']] = true; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$this->db->sql_freeresult($result); |
130
|
|
|
|
131
|
|
|
return $allowed; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|