fix_hr_tags_RTE.diff

Administrator Admin, 2009-11-09 19:40

Download (16.3 KB)

View differences:

tests/typo3/sysext/cms/tslib/tslib_content_testcase.php (Arbeitskopie)
124 124

  
125 125
		return $imageResource;
126 126
	}
127

  
128
	/**
129
	 * Tests whether method "encapsLines" works properly
130
	 * 
131
	 * @test
132
	 */
133
	public function check_encaps_lineSplit() {
134
		$testValues = array(
135
					// A single wrapped line should stay the same
136
			1 => array(
137
				'before' => '<p>Some text</p>',
138
				'after' => array(
139
					'conf1' => '<p>Some text</p>',
140
					'conf2' => '<p>Some text</p>',
141
				),
142
			),
143
					// Multiple properly wrapped lines should stay the same
144
			2 => array(
145
				'before' => '<p>Some text</p>'.chr(10).'<p>Another Text</p>',
146
				'after' => array(
147
					'conf1' => '<p>Some text</p>'.chr(10).'<p>Another Text</p>',
148
					'conf2' => '<p>Some text</p>'.chr(10).'<p>Another Text</p>',
149
				),
150
			),
151
					// Check if single unwrapped line gets wrapped
152
			3 => array(
153
				'before' => 'Some text',
154
				'after' => array(
155
					'conf1' => '<P>Some text</P>',
156
					'conf2' => '<p>Some text</p>',
157
				)
158
			),
159
				// Check if multiple unwrapped lines gets wrapped
160
			4 => array(
161
				'before' => 'Some text'.chr(10).'Another Text',
162
				'after' => array(
163
					'conf1' => '<P>Some text</P>'.chr(10).'<P>Another Text</P>',
164
					'conf2' => '<p>Some text</p>'.chr(10).'<p>Another Text</p>',
165
				),
166
			),
167
				// Check if empty lines get wrapped properly
168
			5 => array(
169
				'before' => '<p>Some text</p>'.chr(10).chr(10).'<p>Another Text</p>',
170
				'after' => array(
171
					'conf1' => '<p>Some text</p>'.chr(10).'<P></P>'.chr(10).'<p>Another Text</p>',
172
					'conf2' => '<p>Some text</p>'.chr(10).'<p></p>'.chr(10).'<p>Another Text</p>',
173
				),
174
			),
175
				// Check if empty lines and non wrapped lines get wrapped properly
176
			6 => array(
177
				'before' => 'Some text'.chr(10).chr(10).'Another Text',
178
				'after' => array(
179
					'conf1' => '<P>Some text</P>'.chr(10).'<P></P>'.chr(10).'<P>Another Text</P>',
180
					'conf2' => '<p>Some text</p>'.chr(10).'<p></p>'.chr(10).'<p>Another Text</p>',
181
				),
182
			),
183
				// Check if empty lines and non wrapped lines get wrapped properly
184
			7 => array(
185
				'before' => '<p>Some text</p>'.chr(10).chr(10).'Another Text',
186
				'after' => array(
187
					'conf1' => '<p>Some text</p>'.chr(10).'<P></P>'.chr(10).'<P>Another Text</P>',
188
					'conf2' => '<p>Some text</p>'.chr(10).'<p></p>'.chr(10).'<p>Another Text</p>',
189
				),
190
			),
191
				// Check if <div> gets changed to <p>
192
			8 => array(
193
				'before' => '<div>Some text</div>'.chr(10).chr(10).'Another Text',
194
				'after' => array(
195
					'conf1' => '<p>Some text</p>'.chr(10).'<P></P>'.chr(10).'<P>Another Text</P>',
196
					'conf2' => '<p>Some text</p>'.chr(10).'<p></p>'.chr(10).'<p>Another Text</p>',
197
				),
198
			),
199

  
200
				// Check if single-tag is handled correct
201
			20 => array(
202
				'before' => '<hr />',
203
				'after' => array(
204
					'conf1' => '<hr />',
205
					'conf2' => '<hr class="changed" />',
206
				),
207
				'singleTag' => true,
208
			),
209
				// Check if single-tag is handled correct
210
			21 => array(
211
				'before' => '<hr/>',
212
				'after' => array(
213
					'conf1' => '<hr />',
214
					'conf2' => '<hr class="changed" />',
215
				),
216
				'singleTag' => true,
217
			),
218
				// Check if single-tag is handled correct
219
			22 => array(
220
				'before' => '<hr   />',
221
				'after' => array(
222
					'conf1' => '<hr />',
223
					'conf2' => '<hr class="changed" />',
224
				),
225
				'singleTag' => true,
226
			),
227
				// Check if single-tag is handled correct
228
			23 => array(
229
				'before' => '<hr class="test" />',
230
				'after' => array(
231
					'conf1' => '<hr class="test" />',
232
					'conf2' => '<hr class="changed" />',
233
				),
234
				'singleTag' => true,
235
			),
236
				// Check if multiple unwrapped lines gets wrapped / Single-Tag
237
			24 => array(
238
				'before' => 'Some text'.chr(10).'<hr />'.chr(10).'Another Text',
239
				'after' => array(
240
					'conf1' => '<P>Some text</P>'.chr(10).'<hr />'.chr(10).'<P>Another Text</P>',
241
					'conf2' => '<p>Some text</p>'.chr(10).'<hr class="changed" />'.chr(10).'<p>Another Text</p>',
242
				),
243
				'singleTag' => true,
244
			),
245
					// A single wrapped line should stay the same / Single-Tag
246
			25 => array(
247
				'before' => '<p><hr /></p>',
248
				'after' => array(
249
					'conf1' => '<p><hr /></p>',
250
					'conf2' => '<p><hr /></p>',
251
				),
252
			),
253
		);
254

  
255
			// Configurations for testing encaps_lineSplit
256
		$conf = array(
257
			'conf1' => array(
258
				'encapsTagList' => 'div, p, hr',
259
				'remapTag.' => array(
260
					'DIV' => 'P',
261
				),
262
				'wrapNonWrappedLines' => '<P>|</P>',
263
			),
264
			'conf2' => array(
265
				'encapsTagList' => 'div, p, hr',
266
				'remapTag.' => array(
267
					'DIV' => 'P',
268
				),
269
				'addAttributes.' => array(
270
					'HR.' => array(
271
						'class' => 'changed',
272
					),
273
				),
274
				'nonWrappedTag' => 'P',
275
			),
276
		);
277

  
278
			// Running defined test-values using above configuration
279
		foreach ($testValues as $key => $test) {
280
			foreach ($conf as $confKey => $confArr) {
281
					// Test new method
282
				$result = $this->cObj->encaps_lineSplit($test['before'], $confArr);
283
					// Test original method
284
				$result_orig = $this->encaps_lineSplit($test['before'], $confArr);
285

  
286
					// Check if new method delivers expected result
287
				$this->assertEquals($result, $test['after'][$confKey], 'Error #1 for test #'.$key.' using conf "'.$confKey.'" !');
288

  
289
					// If this is a "singleTag" testcase old and new implementation have to differ
290
				if ($test['singleTag']) {
291
					$this->assertNotEquals($result, $result_orig, 'Error #2 for test #'.$key.' using conf "'.$confKey.'"');
292
				} else {
293
					$this->assertEquals($result, $result_orig, 'Error #3 for test #'.$key.' using conf "'.$confKey.'"');
294
				}
295
			}
296
		}
297

  
298
	}
299

  
300

  
301
	/**
302
	 * Original encaps_lineSplit method prior to "singleTag" patch. Remove in TYPO3 4.5
303
	 *
304
	 * @param	string		The input value
305
	 * @param	array		TypoScript options
306
	 * @return	string		The processed input value being returned; Splitted lines imploded by chr(10) again.
307
	 * @access private
308
	 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=323&cHash=a19312be78
309
	 */
310
	function encaps_lineSplit($theValue, $conf)	{
311
		$lParts = explode(chr(10),$theValue);
312

  
313
		$encapTags = t3lib_div::trimExplode(',',strtolower($conf['encapsTagList']),1);
314
		$nonWrappedTag = $conf['nonWrappedTag'];
315
		$defaultAlign=trim($this->cObj->stdWrap($conf['defaultAlign'],$conf['defaultAlign.']));
316

  
317
		if (!strcmp('',$theValue))	return '';
318

  
319
		foreach ($lParts as $k => $l) {
320
			$sameBeginEnd=0;
321
			$l=trim($l);
322
			$attrib=array();
323
			$nWrapped=0;
324
			$byPass=0;
325
			if (substr($l,0,1)=='<' && substr($l,-1)=='>')	{
326
				$fwParts = explode('>',substr($l,1),2);
327
				$backParts = t3lib_div::revExplode('<', substr($fwParts[1],0,-1), 2);
328
				$attrib = t3lib_div::get_tag_attributes('<'.$fwParts[0].'>');
329
				list($tagName) = explode(' ',$fwParts[0]);
330
				$str_content = $backParts[0];
331
				$sameBeginEnd = (substr(strtolower($backParts[1]),1,strlen($tagName))==strtolower($tagName));
332
			}
333

  
334
			if ($sameBeginEnd && in_array(strtolower($tagName),$encapTags))	{
335
				$uTagName = strtoupper($tagName);
336
				$uTagName = strtoupper($conf['remapTag.'][$uTagName]?$conf['remapTag.'][$uTagName]:$uTagName);
337
			} else {
338
				$uTagName = strtoupper($nonWrappedTag);
339
				$str_content = $lParts[$k];
340
				$nWrapped=1;
341
				$attrib=array();
342
			}
343

  
344
				// Wrapping all inner-content:
345
			if (is_array($conf['innerStdWrap_all.']))	{$str_content = $this->cObj->stdWrap($str_content,$conf['innerStdWrap_all.']);}
346

  
347
			if ($uTagName)	{
348
					// Setting common attributes
349
				if (is_array($conf['addAttributes.'][$uTagName.'.']))	{
350
					foreach ($conf['addAttributes.'][$uTagName.'.'] as $kk => $vv) {
351
						if (!is_array($vv))	{
352
							if ((string)$conf['addAttributes.'][$uTagName.'.'][$kk.'.']['setOnly']=='blank')	{
353
								if (!strcmp($attrib[$kk],''))	$attrib[$kk]=$vv;
354
							} elseif ((string)$conf['addAttributes.'][$uTagName.'.'][$kk.'.']['setOnly']=='exists')	{
355
								if (!isset($attrib[$kk]))	$attrib[$kk]=$vv;
356
							} else {
357
								$attrib[$kk]=$vv;
358
							}
359
						}
360
					}
361
				}
362
					// Wrapping all inner-content:
363
				if (is_array($conf['encapsLinesStdWrap.'][$uTagName.'.']))	{$str_content = $this->cObj->stdWrap($str_content,$conf['encapsLinesStdWrap.'][$uTagName.'.']);}
364
					// Default align
365
				if (!$attrib['align'] && $defaultAlign)	$attrib['align']=$defaultAlign;
366

  
367
				$params = t3lib_div::implodeAttributes($attrib,1);
368
				if ($conf['removeWrapping'])	{
369
					$str_content=$str_content;
370
				} else {
371
					$str_content='<'.strtolower($uTagName).(trim($params)?' '.trim($params):'').'>'.$str_content.'</'.strtolower($uTagName).'>';
372
				}
373
			}
374

  
375
			if ($nWrapped && $conf['wrapNonWrappedLines'])	{$str_content = $this->cObj->wrap($str_content,$conf['wrapNonWrappedLines']);}
376
			$lParts[$k] = $str_content;
377
		}
378

  
379
		return implode(chr(10),$lParts);
380
	}
381

  
127 382
}
128 383
?>
t3lib/class.t3lib_parsehtml.php (Arbeitskopie)
762 762
					$tagContent = substr($tok,$endTag,$tagEnd-$endTag);
763 763
					$tagParts = preg_split('/\s+/s',$tagContent,2);
764 764
					$tagName = strtolower($tagParts[0]);
765
					$singleTag = 0;
765 766
					if (isset($tags[$tagName]))	{
766 767
						if (is_array($tags[$tagName]))	{	// If there is processing to do for the tag:
767 768

  
769
							if (substr($tagParts[1], -1) == '/') {
770
								$singleTag = 1;
771
							}
768 772
							if (!$endTag)	{	// If NOT an endtag, do attribute processing (added dec. 2003)
769 773
									// Override attributes
770 774
								if (strcmp($tags[$tagName]['overrideAttribs'],''))	{
......
900 904

  
901 905
								if ($setTag)	{
902 906
										// Setting the tag
903
									$newContent[$c++]=$this->processTag($lt.($endTag?'/':'').trim($tagParts[0].' '.$tagParts[1]).$gt,$addConfig,$endTag,$lt=='&lt;');
907
									$newContent[$c++]=$this->processTag($lt.($endTag?'/':'').trim($tagParts[0].' '.$tagParts[1]).($singleTag?' /':'').$gt,$addConfig,$endTag,$lt=='&lt;');
904 908
								}
905 909
							}
906 910
						} else {
907
							$newContent[$c++]=$this->processTag('<'.($endTag?'/':'').$tagContent.'>',$addConfig,$endTag);
911
							$newContent[$c++]=$this->processTag($x = '<'.($endTag?'/':'').$tagContent.'>',$addConfig,$endTag);
908 912
						}
909 913
					} elseif ($keepAll) {	// This is if the tag was not defined in the array for processing:
910 914
						if (!strcmp($keepAll,'protect'))	{
t3lib/class.t3lib_parsehtml_proc.php (Arbeitskopie)
102 102
class t3lib_parsehtml_proc extends t3lib_parsehtml {
103 103

  
104 104
		// Static:
105
	var $blockElementList = 'PRE,UL,OL,H1,H2,H3,H4,H5,H6,HR,ADDRESS,DL,DD';	// List of tags for these elements
105
	var $blockElementList = 'PRE,UL,OL,H1,H2,H3,H4,H5,H6,ADDRESS,DL,DD';	// List of tags for these elements
106
	var $singleTagPatterns = '/(<hr\s*\/>)/i';	// List of single-tag patterns which should not get wrapped for _rte transformation
106 107

  
107 108
		// Internal, static:
108 109
	var $recPid = 0;				// Set this to the pid of the record manipulated by the class.
......
1357 1358

  
1358 1359
				// Wrapping the line in <$dT> is not already wrapped:
1359 1360
			$testStr = strtolower(trim($parts[$k]));
1360
			if (substr($testStr,0,4)!='<div' || substr($testStr,-6)!='</div>')	{
1361
				if (substr($testStr,0,2)!='<p' || substr($testStr,-4)!='</p>')	{
1362
						// Only set p-tags if there is not already div or p tags:
1363
					$parts[$k]='<'.$dT.'>'.$parts[$k].'</'.$dT.'>';
1361
				// Do not wrap single-tags like <hr/> with <div> or <p> tags
1362
			if (!preg_match($this->singleTagPatterns, $testStr)) {
1363
				if (substr($testStr,0,4)!='<div' || substr($testStr,-6)!='</div>')	{
1364
					if (substr($testStr,0,2)!='<p' || substr($testStr,-4)!='</p>')	{
1365
							// Only set p-tags if there is not already div or p tags:
1366
						$parts[$k]='<'.$dT.'>'.$parts[$k].'</'.$dT.'>';
1367
					}
1364 1368
				}
1365 1369
			}
1366 1370
		}
1367

  
1368 1371
			// Implode result:
1369 1372
		return implode(chr(10),$parts);
1370 1373
	}
typo3/sysext/cms/tslib/class.tslib_content.php (Arbeitskopie)
5119 5119

  
5120 5120
		foreach ($lParts as $k => $l) {
5121 5121
			$sameBeginEnd=0;
5122
			$singleTag = 0;
5122 5123
			$l=trim($l);
5123 5124
			$attrib=array();
5124 5125
			$nWrapped=0;
5125
			$byPass=0;
5126 5126
			if (substr($l,0,1)=='<' && substr($l,-1)=='>')	{
5127 5127
				$fwParts = explode('>',substr($l,1),2);
5128
				$backParts = t3lib_div::revExplode('<', substr($fwParts[1],0,-1), 2);
5129
				$attrib = t3lib_div::get_tag_attributes('<'.$fwParts[0].'>');
5130
				list($tagName) = explode(' ',$fwParts[0]);
5131
				$str_content = $backParts[0];
5132
				$sameBeginEnd = (substr(strtolower($backParts[1]),1,strlen($tagName))==strtolower($tagName));
5128
				list($tagName, $tagParams) = explode(' ',$fwParts[0], 2);
5129
				if (!$fwParts[1]) {
5130
					if (substr($tagName, -1) == '/') {
5131
						$tagName = substr($tagName, 0, -1);
5132
					}
5133
					if (substr($fwParts[0], -1) == '/') {
5134
						$sameBeginEnd = 1;
5135
						$singleTag = 1;
5136
						$attrib = t3lib_div::get_tag_attributes('<'.substr($fwParts[0], 0, -1).'>');
5137
					}
5138
				} else {
5139
					$backParts = t3lib_div::revExplode('<', substr($fwParts[1],0,-1), 2);
5140
					$attrib = t3lib_div::get_tag_attributes('<'.$fwParts[0].'>');
5141
					$str_content = $backParts[0];
5142
					$sameBeginEnd = (substr(strtolower($backParts[1]),1,strlen($tagName))==strtolower($tagName));
5143
				}
5133 5144
			}
5134 5145

  
5135
			if ($sameBeginEnd && in_array(strtolower($tagName),$encapTags))	{
5146
			if ($sameBeginEnd && in_array(strtolower($tagName), $encapTags))	{
5136 5147
				$uTagName = strtoupper($tagName);
5137 5148
				$uTagName = strtoupper($conf['remapTag.'][$uTagName]?$conf['remapTag.'][$uTagName]:$uTagName);
5138 5149
			} else {
......
5143 5154
			}
5144 5155

  
5145 5156
				// Wrapping all inner-content:
5146
			if (is_array($conf['innerStdWrap_all.']))	{$str_content = $this->stdWrap($str_content,$conf['innerStdWrap_all.']);}
5157
			if (is_array($conf['innerStdWrap_all.']))	{$str_content = $this->stdWrap($str_content, $conf['innerStdWrap_all.']);}
5147 5158

  
5148 5159
			if ($uTagName)	{
5149 5160
					// Setting common attributes
......
5151 5162
					foreach ($conf['addAttributes.'][$uTagName.'.'] as $kk => $vv) {
5152 5163
						if (!is_array($vv))	{
5153 5164
							if ((string)$conf['addAttributes.'][$uTagName.'.'][$kk.'.']['setOnly']=='blank')	{
5154
								if (!strcmp($attrib[$kk],''))	$attrib[$kk]=$vv;
5165
								if (!strcmp($attrib[$kk],'')) {
5166
									$attrib[$kk]=$vv;
5167
								}
5155 5168
							} elseif ((string)$conf['addAttributes.'][$uTagName.'.'][$kk.'.']['setOnly']=='exists')	{
5156
								if (!isset($attrib[$kk]))	$attrib[$kk]=$vv;
5169
								if (!isset($attrib[$kk])) {
5170
									$attrib[$kk]=$vv;
5171
								}
5157 5172
							} else {
5158 5173
								$attrib[$kk]=$vv;
5159 5174
							}
......
5161 5176
					}
5162 5177
				}
5163 5178
					// Wrapping all inner-content:
5164
				if (is_array($conf['encapsLinesStdWrap.'][$uTagName.'.']))	{$str_content = $this->stdWrap($str_content,$conf['encapsLinesStdWrap.'][$uTagName.'.']);}
5179
				if (is_array($conf['encapsLinesStdWrap.'][$uTagName.'.'])) {
5180
					$str_content = $this->stdWrap($str_content,$conf['encapsLinesStdWrap.'][$uTagName.'.']);
5181
				}
5165 5182
					// Default align
5166
				if (!$attrib['align'] && $defaultAlign)	$attrib['align']=$defaultAlign;
5183
				if (!$attrib['align'] && $defaultAlign) {
5184
					$attrib['align']=$defaultAlign;
5185
				}
5167 5186

  
5168 5187
				$params = t3lib_div::implodeAttributes($attrib,1);
5169
				if ($conf['removeWrapping'])	{
5188
				if ($conf['removeWrapping'] && !($singleTag && $conf['removeWrapping.']['keepSingleTag'])) {
5170 5189
					$str_content=$str_content;
5171 5190
				} else {
5172
					$str_content='<'.strtolower($uTagName).(trim($params)?' '.trim($params):'').'>'.$str_content.'</'.strtolower($uTagName).'>';
5191
					if ($singleTag) {
5192
						$str_content='<'.strtolower($uTagName).(trim($params)?' '.trim($params):'').' />';
5193
					} else {
5194
						$str_content='<'.strtolower($uTagName).(trim($params)?' '.trim($params):'').'>'.$str_content.'</'.strtolower($uTagName).'>';
5195
					}
5173 5196
				}
5174 5197
			}
5175 5198

  
5176
			if ($nWrapped && $conf['wrapNonWrappedLines'])	{$str_content = $this->wrap($str_content,$conf['wrapNonWrappedLines']);}
5199
			if ($nWrapped && $conf['wrapNonWrappedLines']) {
5200
				$str_content = $this->wrap($str_content,$conf['wrapNonWrappedLines']);
5201
			}
5177 5202
			$lParts[$k] = $str_content;
5178 5203
		}
5179 5204