<commit_before><?php
include '_include.php';

setContentTypeHTML();
setIsBlog();

if (defined('STDIN')) {
	$_GET[$argv[1]] = $argv[2];
}

if (isset($_GET[getBlogPostIdParam()])) {
	
	setBlogPostId($_GET[getBlogPostIdParam()]);
	
	if (!existsBlogPost()) {
		redirect(getBlogLink());
	}
	
	setIsBlogPost();
	
	readBlogPostConfig();
	readBlogPostContent();
	
	includeThemeFile('page-prefix.php');
	includeThemeFile('blog-post-full.php');
	includeThemeFile('page-suffix.php');
}

else if (isset($_GET[getBlogSearchParam()])) {
	
	setBlogSearchQuery($_GET[getBlogSearchParam()]);
	setIsBlogSearch();
	
	$words = preg_split('/\s+/', trim(getBlogSearchQuery()));
	
	includeThemeFile('page-prefix.php');
	includeThemeFile('blog-search-prefix.php');
	
	foreach (getBlogPostFolders() as $blogPostFolder) {
		setBlogPostId(basename($blogPostFolder));
		readBlogPostConfig();
		readBlogPostContent();
		
		foreach ($words as $word) {
			
			$isFound = false;
			$blogPostContentStripTags = null;
			
			//
			// first check in title
			
			if (stripos(getBlogPostTitle(), $word) !== false) {
				$isFound = true;
			}
			
			//
			// then in keywords
			
			else if (stripos(implode('', getBlogPostKeywords()), $word) !== false) {
				$isFound = true;
			}
			
			//
			// then in description
			
			else if (stripos(getBlogPostDescription(), $word) !== false) {
				$isFound = true;
			}
			
			//
			// then in content
			
			else {
				
				$blogPostContentStripTags = strip_tags(getBlogPostContent());
				$blogPostContentStripTags = preg_replace('/\s+/', ' ',$blogPostContentStripTags);
				
				$wordPos = strpos($blogPostContentStripTags, $word);
				
				if ($wordPos !== false) {
					$isFound = true;
				}
			}
			
			//
			// if found
			// - create the search result
			// - include the theme file
			// - and break the cycle through search words
			
			if ($isFound) {
				
				if (is_null($blogPostContentStripTags)) {
					$blogPostContentStripTags = strip_tags(getBlogPostContent());
					$blogPostContentStripTags = preg_replace('/\s+/', ' ',$blogPostContentStripTags);
				}
				
				$blogPostContentStripTags = trim($blogPostContentStripTags);
				$blogPostContentStripTags = strtolower($blogPostContentStripTags);
				
				$blogSearchResult = 'Keywords: ' . implode(', ', getBlogPostKeywords()) . '<br>Content: ';
				
				$blogSearchResult .= substr($blogPostContentStripTags, 0, 100);
				$blogSearchResult .= ' ... ';
				$blogSearchResult .= substr($blogPostContentStripTags, max(0, $wordPos - 200), 400);
				$blogSearchResult .= ' ... ';
				
				$blogSearchResult = str_ireplace($word, '<span class="blog-search-result-word">' . $word . '</span>', $blogSearchResult);
				
				setBlogSearchResult($blogSearchResult);
				
				includeThemeFile('blog-search-result.php');
				break;
			}
		}
	}
	
	includeThemeFile('blog-search-suffix.php');
	includeThemeFile('page-suffix.php');
}

else {
	
	includeThemeFile('page-prefix.php');
	
	foreach (getBlogPostFolders() as $blogPostFolder) {
		setBlogPostId(basename($blogPostFolder));
		readBlogPostConfig();
		
		includeThemeFile('blog-post-description.php');
	}
	
	includeThemeFile('page-suffix.php');
}

?><commit_msg>search - blog post contains all words<commit_after><?php
include '_include.php';

setContentTypeHTML();
setIsBlog();

if (defined('STDIN')) {
	$_GET[$argv[1]] = $argv[2];
}

if (isset($_GET[getBlogPostIdParam()])) {
	
	setBlogPostId($_GET[getBlogPostIdParam()]);
	
	if (!existsBlogPost()) {
		redirect(getBlogLink());
	}
	
	setIsBlogPost();
	
	readBlogPostConfig();
	readBlogPostContent();
	
	includeThemeFile('page-prefix.php');
	includeThemeFile('blog-post-full.php');
	includeThemeFile('page-suffix.php');
}

else if (isset($_GET[getBlogSearchParam()])) {
	
	setBlogSearchQuery($_GET[getBlogSearchParam()]);
	setIsBlogSearch();
	
	$words = preg_split('/\s+/', trim(getBlogSearchQuery()));
	
	includeThemeFile('page-prefix.php');
	includeThemeFile('blog-search-prefix.php');
	
	foreach (getBlogPostFolders() as $blogPostFolder) {
		setBlogPostId(basename($blogPostFolder));
		readBlogPostConfig();
		readBlogPostContent();
		
		$blogPostContentStripTags = strip_tags(getBlogPostContent());
		$blogPostContentStripTags = preg_replace('/\s+/', ' ',$blogPostContentStripTags);
		
		$blogPostContainsAllWords = true;
		
		foreach ($words as $word) {
			
			$isFound = false;
			
			//
			// first check in title
			
			if (stripos(getBlogPostTitle(), $word) !== false) {
				$isFound = true;
			}
			
			//
			// then in keywords
			
			else if (stripos(implode('', getBlogPostKeywords()), $word) !== false) {
				$isFound = true;
			}
			
			//
			// then in description
			
			else if (stripos(getBlogPostDescription(), $word) !== false) {
				$isFound = true;
			}
			
			//
			// then in content
			
			else {
				
				$wordPos = strpos($blogPostContentStripTags, $word);
				
				if ($wordPos !== false) {
					$isFound = true;
				}
			}
			
			//
			// if word not found
			// - reset the "contains all words" flag
			// - and break the cycle through search words
			
			if (!$isFound) {
				$blogPostContainsAllWords = false;
				break;
			}
		}
		
		//
		// if blog post contains all words
		// - create the search result
		// - include the theme file
		
		if ($blogPostContainsAllWords) {
			
			$blogPostContentStripTags = trim($blogPostContentStripTags);
			$blogPostContentStripTags = strtolower($blogPostContentStripTags);
			
			$blogSearchResult = 'Keywords: ' . implode(', ', getBlogPostKeywords()) . '<br>Content: ';
			
			$blogSearchResult .= substr($blogPostContentStripTags, 0, 100);
			$blogSearchResult .= ' ... ';
			$blogSearchResult .= substr($blogPostContentStripTags, max(0, $wordPos - 200), 400);
			$blogSearchResult .= ' ... ';
			
			foreach ($words as $word) {
				$blogSearchResult = str_ireplace($word, '<span class="blog-search-result-word">' . $word . '</span>', $blogSearchResult);
			}
			
			setBlogSearchResult($blogSearchResult);
			
			includeThemeFile('blog-search-result.php');
		}
	}
	
	includeThemeFile('blog-search-suffix.php');
	includeThemeFile('page-suffix.php');
}

else {
	
	includeThemeFile('page-prefix.php');
	
	foreach (getBlogPostFolders() as $blogPostFolder) {
		setBlogPostId(basename($blogPostFolder));
		readBlogPostConfig();
		
		includeThemeFile('blog-post-description.php');
	}
	
	includeThemeFile('page-suffix.php');
}

?>
{'fraction_non_alphanumeric': 0.16006911718504555, 'fraction_numerical': 0.004084197298146403, 'mean_word_length': 3.6204644412191582, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '964471', 'n_tokens_mistral': 2573, 'n_tokens_neox': 2048, 'n_words': 346}