Code Duplication    Length = 28-28 lines in 2 locations

view/SSTemplateParser.php 1 location

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

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