<commit_before>$ID = q$Id: DocumentTemplate.pm,v 1.12 2005-12-04 17:40:20 diddledan Exp $;
&printdebug('Module DocumentTemplate',
			'',
			'Authors: The CRIMP Team',
			"Version: $ID",
			'http://crimp.sourceforge.net/'
			);
			
&printdebug('',$status,"Started With: $crimp->{DocumentTemplate}");

my $blankTemplate = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>'.$Config->{_}->{SiteTitle}.'</title>
</head>
<body>
<!--PAGE_CONTENT-->
</body></html>';

#only parse the template if this is an html or xhtml page
if (($crimp->{ContentType} eq 'text/html') || ($crimp->{ContentType} eq 'text/xhtml+xml')) {
	# This should also be set within the query string '?DocumentTemplate=[none|off]'
	if (($crimp->{DocumentTemplate} eq 'none') || ($crimp->{DocumentTemplate} eq 'off')) {
		&printdebug('','pass','A blank template is being used');
		&insertContent($blankTemplate);
	} else {
		@HttpRequest = split(/\//,$crimp->{HttpRequest});
		foreach $HttpRequest (@HttpRequest){
			#print "$crimp->{HttpRequest} :: $HttpRequest :: $crimp->{UserConfig}<br>";
			if ($crimp->{UserConfig} ne "/$HttpRequest"){$path = "$path/$HttpRequest";}
		}
	
		sysopen (FILE,$crimp->{DocumentTemplate}, O_RDONLY) or &printdebug('','Warn',"Template $crimp->{DocumentTemplate} not found");
		@template_content=<FILE>;
		#$SIZE=@LINES;
		$status = 'pass';
		close(FILE);
		if (@template_content) {
			my $new_content = '';
				foreach $template_line(@template_content) {
		  		$new_content = join '', $new_content, $template_line;
			}
		
			#printdebug ("Putting Page into Template");
			
			&insertContent($new_content);
		} else {
			&printdebug('','warn','Template file does not contain any content, using default blank template.');
			&insertContent($blankTemplate);
		}
	}
} else {
	&printdebug('', 'pass', "Skipped module for ContentType: $crimp->{ContentType}");
}

sub insertContent {
	my $template = shift;

	#remove xml header if present
	$crimp->{DisplayHtml} =~ s|<\?xml.*?\?>||i;
	#remove doctype if present
	$crimp->{DisplayHtml} =~ s|<!DOCTYPE.*?>||i;
	#remove headers storing the title of the page
	$crimp->{DisplayHtml} =~ s|<title>(.*?)</title>||si;
	
	$crimp->{PageTitle} ||= $1;
	
	#strip from <html> down to the opening <body> tag
	$crimp->{DisplayHtml} =~ s|<html.*?>.*?<body>||si;
	#remove the closing </body> tag and any cruft after - alas, that's nothing to do with the dogshow
	$crimp->{DisplayHtml} =~ s|</body>.*||si;
	
	if ($crimp->{PageTitle} eq '') {
		&printdebug('','warn','The Page has no title');
	} else {
		&printdebug('','pass',"PageTitle: $crimp->{PageTitle}");
		$crimp->{PageTitle} = join '', ' - ', $crimp->{PageTitle};
		$template =~ s|(</title>)|$crimp->{PageTitle}\1|i;;
	}
	
	$template =~ s/<!--PAGE_CONTENT-->/$crimp->{DisplayHtml}/gi;
	
	$crimp->{DisplayHtml} = $template;
}

1;<commit_msg>Corrected title... now gives current html title without template and gives 'TemplateTitle - ContentTitle' with a template<commit_after>$ID = q$Id: DocumentTemplate.pm,v 1.13 2005-12-17 23:51:33 deadpan110 Exp $;
&printdebug('Module DocumentTemplate',
			'',
			'Authors: The CRIMP Team',
			"Version: $ID",
			'http://crimp.sourceforge.net/'
			);
			
&printdebug('',$status,"Started With: $crimp->{DocumentTemplate}");

my $blankTemplate = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>'.$Config->{_}->{SiteTitle}.'</title>
</head>
<body>
<!--PAGE_CONTENT-->
</body></html>';

#only parse the template if this is an html or xhtml page
if (($crimp->{ContentType} eq 'text/html') || ($crimp->{ContentType} eq 'text/xhtml+xml')) {
	# This should also be set within the query string '?DocumentTemplate=[none|off]'
	if (($crimp->{DocumentTemplate} eq 'none') || ($crimp->{DocumentTemplate} eq 'off')) {
		&printdebug('','pass','A blank template is being used');
		&insertContent($blankTemplate);
	} else {
		@HttpRequest = split(/\//,$crimp->{HttpRequest});
		foreach $HttpRequest (@HttpRequest){
			#print "$crimp->{HttpRequest} :: $HttpRequest :: $crimp->{UserConfig}<br>";
			if ($crimp->{UserConfig} ne "/$HttpRequest"){$path = "$path/$HttpRequest";}
		}
	
		sysopen (FILE,$crimp->{DocumentTemplate}, O_RDONLY) or &printdebug('','Warn',"Template $crimp->{DocumentTemplate} not found");
		@template_content=<FILE>;
		#$SIZE=@LINES;
		$status = 'pass';
		close(FILE);
		if (@template_content) {
			my $new_content = '';
				foreach $template_line(@template_content) {
		  		$new_content = join '', $new_content, $template_line;
			}
		
			#printdebug ("Putting Page into Template");
			
			&insertContent($new_content);
		} else {
			&printdebug('','warn','Template file does not contain any content, using default blank template.');
			&insertContent($blankTemplate);
		}
	}
} else {
	&printdebug('', 'pass', "Skipped module for ContentType: $crimp->{ContentType}");
}

sub insertContent {
	my $template = shift;

	#remove xml header if present
	$crimp->{DisplayHtml} =~ s|<\?xml.*?\?>||i;
	#remove doctype if present
	$crimp->{DisplayHtml} =~ s|<!DOCTYPE.*?>||i;
	#remove headers storing the title of the page
	$crimp->{DisplayHtml} =~ s|<title>(.*?)</title>||si;
	#if we insert content then this is important
	$crimp->{PageTitle} = $1;
	
	#strip from <html> down to the opening <body> tag
	$crimp->{DisplayHtml} =~ s|<html.*?>.*?<body>||si;
	#remove the closing </body> tag and any cruft after - alas, that's nothing to do with the dogshow
	$crimp->{DisplayHtml} =~ s|</body>.*||si;
	
	if ($crimp->{PageTitle} eq '') {
		&printdebug('','warn','The Page has no title');
	} else {
		&printdebug('','pass',"PageTitle: $crimp->{PageTitle}");
		$crimp->{PageTitle} = join '', ' - ', $crimp->{PageTitle};
		$template =~ s|(</title>)|$crimp->{PageTitle}\1|i;;
	}
	
	$template =~ s/<!--PAGE_CONTENT-->/$crimp->{DisplayHtml}/gi;
	
	$crimp->{DisplayHtml} = $template;
}

1;
{'fraction_non_alphanumeric': 0.21160006744225257, 'fraction_numerical': 0.010284943517113471, 'mean_word_length': 4.725868725868726, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '951537', 'n_tokens_mistral': 2275, 'n_tokens_neox': 2060, 'n_words': 474}