MeeranerBlatt durchsuchen
0) {
$words = preg_split(‚/[^a-z0-9äöüß]+/i‘, $search, -1, PREG_SPLIT_NO_EMPTY);
$words = array_filter($words, function($w) {
return strlen(trim($w)) > 1;
});
		/** @var Page[] $pages */
		$pages = MySQL::getObjectsBySQL(‚Page‘, ‚SELECT ID,IDX,AUTHOR_ID,DOMAIN_ID,LANDING_PAGE,TITLE,CUSTOM_PATH,PATH,CONTENT,NULL as PRINT_VERSION,THEME_SETTINGS,GENERATION_DATE,LAST_CHANGE_DATE,PUBLICATION_STATE,PUBLICATION_DATE,PUBLICATION_LINK FROM PAGES WHERE PRINT_VERSION is not NULL ORDER BY IDX DESC‘);
		$page_matches = 0;
		$findAndB = function($pattern, $subject) use (&$page_matches) {
			$regex = ‚|‘ . preg_quote($pattern, ‚|‘) . ‚|i‘;
			$matches = array();
			$match = preg_match($regex, $subject, $matches, PREG_OFFSET_CAPTURE);
			if($match !== 1) {
				$pos = strlen($subject) >= 250 ? strpos($subject, ‚. ‚, 250) + 1 : strlen($subject);
				return $subject; // substr($subject, 0, $pos);
			}
			$page_matches += strlen($pattern);
			$pos = $matches[0][1];
			$matched = preg_match_all(‚/[.?!][^a-z0-9äöüß]/i‘, $subject, $matches, PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER);
			if($pos < 250 || $matched === FALSE || $matched === 0) {
				$pos = 0;
			} else
				foreach($matches[0] as $match) {
					if($match[1] > $pos – 250) {
						$pos = $match[1] < $pos ? $match[1] + 2 : $pos;
						break;
					}
				}
			
			if(preg_match('/[.?!][^a-z0-9äöüß]/i', $subject, $matches, PREG_OFFSET_CAPTURE, $pos + 250) !== 1) {
				$length = strlen($subject);
			} else
				$length = $matches[0][1] - $pos + 1;
			
			$result = substr($subject, $pos, $length);
			$result = preg_replace_callback(
				$regex,
				function($matched) {
					return '‚ . $matched[0] . ‚‚;
				},
				$result
			);
			return trim($result);
		};
		$results = array();
		foreach($pages as $p) {
			$page_matches = 0;
			$title = $findAndB($search, Utils::antiHTMLInjection($p->getTitle()));
			$path = $findAndB($search, Utils::antiHTMLInjection($p->getPath()));
			$content = $findAndB($search, strip_tags($p->getContent(), ‚
‚));
$page_matches *= 2;
			foreach($words as $keyword) {
				$title = $findAndB($keyword, $title);
				$path = $findAndB($keyword, $path);
				$content = $findAndB($keyword, $content);
			}
			if($page_matches === 0)
				continue;
			$title = $title;
			$path = $path;
$anchor = „getPath()) . „#search=“ . Utils::antiHTMLInjection($search) . „\“ class=\“search-result\“>
“ . ($content ? „
“ : „“) . „„;
			array_push($results, (object) array(
				‚matches‘ => $page_matches,
				‚html‘ => $anchor
			));
		}
		usort($results, function($a, $b) {
			return $b->matches – $a->matches;
		});
		foreach($results as $r)
			echo $r->html;
		if(count($results) === 0)
			echo ‚
Es wurden keine passenden Ergebnisse gefunden.
Beachten Sie, dass Ihre Suchwörter aus mindestens 2 Buchstaben bestehen müssen.
‚;
	} else
		echo ‚
Ihre Suchwörter müssen aus mindestens 2 Buchstaben bestehen.
‚;
	?>
