aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/bbcode/bbcode_parser.php
blob: 81151a294522126a93ae6a18f70108b144970d91 (plain)
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
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
/**
*
* @package phpBB3
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/**
 * The phpBB version of the BBCode parser
 *
 */
class phpbb_bbcode_parser extends phpbb_bbcode_parser_base
{
	private $list_stack = array();
	protected $tags = array();

	public function __construct()
	{
		$this->tags = array(
			// The exact B BBcode from phpBB
			'b' => array(
				'replace' => '<span style="font-weight: bold">',
				'close' => '</span>',
				'attributes' => array(),
				'children' => array(true, 'quote' => true, 'code' => true, 'list' => true),
				'parents' => array(true),
			),
			// The exact I BBcode from phpBB
			'i' => array(
				'replace' => '<span style="font-style: italic">',
				'close' => '</span>',
				'attributes' => array(),
				'children' => array(true, 'quote' => true, 'code' => true, 'list' => true),
				'parents' => array(true),
			),
			// The exact U BBcode from phpBB
			'u' => array(
				'replace' => '<span style="text-decoration: underline">',
				'close' => '</span>',
				'attributes' => array(),
				'children' => array(true, 'quote' => true, 'code' => true, 'list' => true),
				'parents' => array(true),
			),

			// Quote tag attempt.
			'quote' => array(
				'replace' => '<div class="quotetitle">{_}</div><div class="quotecontent">',
				'close' => '</div>',
				'attributes' => array(
					'_' => array(
						'replace' => '%s wrote:',
					),
				),
				'children' => array(true),
				'parents' => array(true),
			),

			// code tag (without the =php functionality)
			'code' => array(
				'replace' => '<div class="codetitle"><b>Code:</b></div><div class="codecontent">',
				'close' => '</div>',
				'attributes' => array(),
				'children' => array(false),
				'parents' => array(true),
			),

			// list tag
			'list' => array(
				'replace' => '',
				'replace_func' => array($this, 'list_open'),
				'close' => '',
				'close_func' => array($this, 'list_close'),
				'attributes' => array(
					'_' => array(
						'replace' => '',
					),
				),
				'children' => array(false, 'li' => true),
				'parents' => array(true),
			),

			// The exact * tag from phpBB. "*" is not a valid tag name in this parser... introducing li from HTML!
			'li' => array(
				'replace' => '<li>',
				'close' => '</li>',
				'close_shadow' => true,
				'attributes' => array(),
				'children' => array(true, 'li' => true),
				'parents' => array(false, 'list' => true),
			),

			// Almost exact img tag from phpBB...
			'img' => array(
				'replace' => '<img alt="Image" src="',
				'close' => '" />',
				'attributes' => array(
					'__' => array(
						'replace' => '%s',
					),
				),
				'children' => array(false),
				'parents' => array(true),

			),

			'url' => array(
				'replace' => '',
				'replace_func' => array($this, 'url_tag'),
				'close' => '</a>',
				'attributes' => array(
					// The replace value is not important empty because the replace_func handles this.
					'_' => array(
						'replace' => '',
					),
					'__' => array(
						'replace' => '',
					),
				),
				'children' => array(false),
				'parents' => array(true),

			),

			'color' => array(
				'replace' => '<span style="color: {_}">',
				'close' => '</span>',
				'attributes' => array(
					'_' => array(
						'replace' => '%s',
						'required' => true
					),
				),
				'children' => array(true, 'color' => true),
				'parents' => array(true),
			),

			'size' => array(
				'replace' => '<span style="font-size: {_}px; line-height: normal">',
				'close' => '</span>',
				'attributes' => array(
					'_' => array(
						'replace' => '%s',
						'required' => true
					),
				),
				'children' => array(true, 'size' => true),
				'parents' => array(true),
			),


			// FLASH tag implementation attempt.
			'flash' => array(
				'replace' => '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"{w}{h}>
<param name="movie" value="{m}" />
<param name="quality" value="high" />
<embed src="{m}" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"{w}{h}>
</embed>
</object>',
				'close' => false,
				'attributes' => array(
					'm' => array(
						'replace' => '%s',
						'required' => true,
					),
					'w' => array(
						'replace' => ' width="%s"',
						'type_check' => 'ctype_digit',
					),
					'h' => array(
						'replace' => ' height="%s"',
						'type_check' => 'ctype_digit',
					),
				),
				'children' => array(false),
				'parents' => array(true),
			),
			// The spoiler tag from area51.phpbb.com :p
			'spoiler' => array(
				'replace' => '<span class="quotetitle"><b>Spoiler:</b></span><span style="background-color:white;color:white;">',
				'close' => '</span>',
				'attributes' => array(),
				'children' => array(false),
				'parents' => array(true),
			),
			// a noparse tag
			'noparse' => array(
				'replace' => '',
				'close' => '',
				'attributes' => array(),
				'children' => array(false),
				'parents' => array(true),
			),
		);
		$this->smilies = array(
			':)' => '<img src="http://area51.phpbb.com/phpBB/images/smilies/icon_e_smile.gif" />',
			':(' => '<img src="http://area51.phpbb.com/phpBB/images/smilies/icon_e_sad.gif" />',
		);
		
//		$this->text_callback = 'strtoupper';
		parent::__construct();
	}


 	protected function url_tag(array $attributes = array(), array $definition = array())
	{
		if (isset($attributes['_']))
		{
			return '<a href="' . $attributes['_'] . '">';
		}
		return '<a href="' . $attributes['__'] . '">';
	}

 	protected function list_open(array $attributes = array(), array $definition = array())
	{
		if (isset($attributes['_']))
		{
			return '<ol style="list-style-type: ' . $attributes['_'] . '">';
		}
		return '<ul>';
	}

	protected function list_close(array $attributes = array())
	{
		if (isset($attributes['_']))
		{
			return '</ol>';
		}
		return '</ul>';
	}
}