Code Duplication    Length = 28-28 lines in 2 locations

view/SSTemplateParser.php 1 location

@@ 4753-4780 (lines=28) @@
4750
	 * @param string $code
4751
	 * @return string $code
4752
	 */
4753
	protected function includeDebuggingComments($code, $templateName) {
4754
		// If this template contains a doctype, put it right after it,
4755
		// if not, put it after the <html> tag to avoid IE glitches
4756
		if(stripos($code, "<!doctype") !== false) {
4757
			$code = preg_replace('/(<!doctype[^>]*("[^"]")*[^>]*>)/im', "$1\r\n<!-- template $templateName -->", $code);
4758
			$code .= "\r\n" . '$val .= \'<!-- end template ' . $templateName . ' -->\';';
4759
		} elseif(stripos($code, "<html") !== false) {
4760
			$code = preg_replace_callback('/(.*)(<html[^>]*>)(.*)/i', function($matches) use ($templateName) {
4761
				if (stripos($matches[3], '<!--') === false && stripos($matches[3], '-->') !== false) {
4762
					// after this <html> tag there is a comment close but no comment has been opened
4763
					// this most likely means that this <html> tag is inside a comment
4764
					// we should not add a comment inside a comment (invalid html)
4765
					// lets append it at the end of the comment
4766
					// an example case for this is the html5boilerplate: <!--[if IE]><html class="ie"><![endif]-->
4767
					return $matches[0];
4768
				} else {
4769
					// all other cases, add the comment and return it
4770
					return "{$matches[1]}{$matches[2]}<!-- template $templateName -->{$matches[3]}";
4771
				}
4772
			}, $code);
4773
			$code = preg_replace('/(<\/html[^>]*>)/i', "<!-- end template $templateName -->$1", $code);
4774
		} else {
4775
			$code = str_replace('<?php' . PHP_EOL, '<?php' . PHP_EOL . '$val .= \'<!-- template ' . $templateName .
4776
				' -->\';' . "\r\n", $code);
4777
			$code .= "\r\n" . '$val .= \'<!-- end template ' . $templateName . ' -->\';';
4778
		}
4779
		return $code;
4780
	}
4781
	
4782
	/**
4783
	 * Compiles some file that contains template source code, and returns the php code that will execute as per that

view/SSTemplateParser.php.inc 1 location

@@ 1196-1223 (lines=28) @@
1193
	 * @param string $code
1194
	 * @return string $code
1195
	 */
1196
	protected function includeDebuggingComments($code, $templateName) {
1197
		// If this template contains a doctype, put it right after it,
1198
		// if not, put it after the <html> tag to avoid IE glitches
1199
		if(stripos($code, "<!doctype") !== false) {
1200
			$code = preg_replace('/(<!doctype[^>]*("[^"]")*[^>]*>)/im', "$1\r\n<!-- template $templateName -->", $code);
1201
			$code .= "\r\n" . '$val .= \'<!-- end template ' . $templateName . ' -->\';';
1202
		} elseif(stripos($code, "<html") !== false) {
1203
			$code = preg_replace_callback('/(.*)(<html[^>]*>)(.*)/i', function($matches) use ($templateName) {
1204
				if (stripos($matches[3], '<!--') === false && stripos($matches[3], '-->') !== false) {
1205
					// after this <html> tag there is a comment close but no comment has been opened
1206
					// this most likely means that this <html> tag is inside a comment
1207
					// we should not add a comment inside a comment (invalid html)
1208
					// lets append it at the end of the comment
1209
					// an example case for this is the html5boilerplate: <!--[if IE]><html class="ie"><![endif]-->
1210
					return $matches[0];
1211
				} else {
1212
					// all other cases, add the comment and return it
1213
					return "{$matches[1]}{$matches[2]}<!-- template $templateName -->{$matches[3]}";
1214
				}
1215
			}, $code);
1216
			$code = preg_replace('/(<\/html[^>]*>)/i', "<!-- end template $templateName -->$1", $code);
1217
		} else {
1218
			$code = str_replace('<?php' . PHP_EOL, '<?php' . PHP_EOL . '$val .= \'<!-- template ' . $templateName .
1219
				' -->\';' . "\r\n", $code);
1220
			$code .= "\r\n" . '$val .= \'<!-- end template ' . $templateName . ' -->\';';
1221
		}
1222
		return $code;
1223
	}
1224
	
1225
	/**
1226
	 * Compiles some file that contains template source code, and returns the php code that will execute as per that