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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\textformatter\s9e;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* s9e\TextFormatter\Renderer adapter
* @package phpBB3
*/
class renderer extends \phpbb\textformatter\renderer
{
/**
* @var s9e\TextFormatter\Renderer
*/
protected $renderer;
/**
* @var bool Status of the viewcensors option
*/
protected $viewcensors = false;
/**
* @var bool Status of the viewflash option
*/
protected $viewflash = false;
/**
* @var bool Status of the viewimg option
*/
protected $viewimg = false;
/**
* @var bool Status of the viewsmilies option
*/
protected $viewsmilies = false;
/**
* Constructor
*
* @param phpbb\cache\driver\driver_interface $cache
* @param string $cache_dir Path to the cache dir
* @param string $key Cache key
* @param ContainerInterface $container
* @return null
*/
public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, ContainerInterface $container)
{
$renderer_data = $cache->get($key);
if ($renderer_data)
{
$class = $renderer_data['class'];
if (!class_exists($class, false))
{
// Try to load the renderer class from its cache file
$cache_file = $cache_dir . $class . '.php';
if (file_exists($cache_file))
{
include($cache_file);
}
}
if (class_exists($class, false))
{
$renderer = unserialize($renderer_data['renderer']);
}
}
if (!isset($renderer))
{
list(, $renderer) = $container->get('text_formatter.s9e.factory')->regenerate();
}
$this->renderer = $renderer;
}
/**
* {@inheritdoc}
*/
public function configure_user(\phpbb\user $user, \phpbb\config\config $config, \phpbb\auth\auth $auth)
{
parent::configure_user($user, $config, $auth);
// Set the stylesheet parameters
foreach (array_keys($this->renderer->getParameters()) as $param_name)
{
if (substr($param_name, 0, 2) === 'L_')
{
// L_FOO is set to $user->lang('FOO')
$this->renderer->setParameter($param_name, $user->lang(substr($param_name, 2)));
}
}
// Set the style id
$this->renderer->setParameter('STYLE_ID', $user->style['style_id']);
}
/**
* {@inheritdoc}
*/
public function get_viewcensors()
{
return $this->viewcensors;
}
/**
* {@inheritdoc}
*/
public function get_viewflash()
{
return $this->viewflash;
}
/**
* {@inheritdoc}
*/
public function get_viewimg()
{
return $this->viewimg;
}
/**
* {@inheritdoc}
*/
public function get_viewsmilies()
{
return $this->viewsmilies;
}
/**
* {@inheritdoc}
*/
public function render($text)
{
$html = $this->renderer->render($text);
/**
* @see bbcode::bbcode_second_pass_code()
*/
$html = preg_replace_callback(
'#(<code>)(.*?)(</code>)#is',
function ($captures)
{
$code = $captures[2];
$code = str_replace("\t", ' ', $code);
$code = str_replace(' ', ' ', $code);
$code = str_replace(' ', ' ', $code);
$code = str_replace("\n ", "\n ", $code);
// keep space at the beginning
if (!empty($code) && $code[0] == ' ')
{
$code = ' ' . substr($code, 1);
}
// remove newline at the beginning
if (!empty($code) && $code[0] == "\n")
{
$code = substr($code, 1);
}
return $captures[1] . $code . $captures[3];
},
$html
);
return $html;
}
/**
* {@inheritdoc}
*/
public function set_smilies_path($path)
{
$this->renderer->setParameter('T_SMILIES_PATH', $path);
}
/**
* {@inheritdoc}
*/
public function set_viewcensors($value)
{
$this->viewcensors = $value;
$this->renderer->setParameter('S_VIEWCENSORS', $value);
}
/**
* {@inheritdoc}
*/
public function set_viewflash($value)
{
$this->viewflash = $value;
$this->renderer->setParameter('S_VIEWFLASH', $value);
}
/**
* {@inheritdoc}
*/
public function set_viewimg($value)
{
$this->viewimg = $value;
$this->renderer->setParameter('S_VIEWIMG', $value);
}
/**
* {@inheritdoc}
*/
public function set_viewsmilies($value)
{
$this->viewsmilies = $value;
$this->renderer->setParameter('S_VIEWSMILIES', $value);
}
}
|