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