123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- /**
- * dolphin. Collection of useful PHP skeletons.
- * Copyright (C) 2016 Johannes 'Banana' Keßler
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
- *
- * You should have received a copy of the
- * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
- * along with this program. If not, see http://www.sun.com/cddl/cddl.html
- */
- mb_http_output('UTF-8');
- mb_internal_encoding('UTF-8');
- ini_set('error_reporting',-1); // E_ALL & E_STRICT
- if(ini_get("magic_quotes_gpc") == 1) {
- die('Magic quotes is set to "on", and system is not able to change it. Please update Your php.ini file');
- }
- ## check request
- $_urlToParse = filter_var($_SERVER['QUERY_STRING'],FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
- if(!empty($_urlToParse)) {
- # see http://de2.php.net/manual/en/regexp.reference.unicode.php
- if(preg_match('/[\p{C}\p{M}\p{Sc}\p{Sk}\p{So}\p{Zl}\p{Zp}]/u',$_urlToParse) === 1) {
- die('Malformed request. Make sure you know what you are doing.');
- }
- }
- # time settings
- date_default_timezone_set('Europe/Berlin');
- define('DEBUG',false);
- ## set the error reporting
- ini_set('log_errors',true);
- ini_set('error_log','error.log');
- if(DEBUG === true) {
- ini_set('display_errors',true);
- }
- else {
- ini_set('display_errors',false);
- }
- $requestString = false;
- $searchStr = false;
- $searchResult = false;
- $searchCount = 0;
- $tagLink = false;
- $catLink = false;
- if(isset($_POST['query'])) {
- $searchStr = trim($_POST['query']);
- $searchStr = strtolower($searchStr);
- $searchStr = preg_replace("/[^\p{L}\p{N}\p{Zs}]/u","",$searchStr);
- # kinda full txt search
- if(!empty($searchStr)) {
- $files = glob('20*/*/*/*.html');
- $limit = 0;
- if(!empty($files)) {
- foreach($files as $file) {
-
- if($limit > 30) break;
- $stream = new SplFileObject($file);
- $grepped = new RegexIterator($stream, '/'.$searchStr.'/i');
- foreach($grepped as $found) {
- $_text = $file;
- # this search for a headline tag and the result will be used as
- # the result text in the search results
- $headlines = new RegexIterator($stream,"/<h2>([^<]+)<\/h2>/");
- foreach($headlines as $headline) {
- $_text = trim($headline);
- $_text = strip_tags($_text);
- break;
- }
-
-
- $searchResult[] = array(
- 'href' => 'https://url.to/'.$file,
- 'text' => $_text
- );
- $limit++;
-
- #var_dump($found);
- #var_dump($file);
- #var_dump($searchResult);
- #exit();
- unset($headlines);
- unset($_text);
- break;
- }
- unset($stream);
- unset($grepped);
- }
- $searchCount = count($searchResult);
- }
- }
- # is it a tag?
- $tagDir = 'tags/'.$searchStr;
- if(file_exists($tagDir)) {
- $tagLink = $searchStr;
- }
- # is it a category?
- $topicsDir = 'topics/'.$searchStr;
- if(file_exists($topicsDir)) {
- $catLink = $searchStr;
- }
- }
- header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
- header("Cache-Control: post-check=0, pre-check=0", false);
- header("Pragma: no-cache");
- ?>
- <!DOCTYPE HTML>
- <html>
- <head>
- <title>Suche nach: <?php echo $searchStr; ?></title>
- <meta charset="utf-8" />
- <meta name="robots" content="noindex,nofollow" />
- <meta name="viewport" content="width=device-width, initial-scale=1" />
- </head>
- <body>
- <div >
- <article >
- <header>
- <h2>Suche</h2>
- <p>Gesucht: <?php echo $searchStr; ?> | Gefunden: <?php echo $searchCount; ?></p>
- </header>
- <?php if(!empty($tagLink)) { ?>
- <p>Tag: <a href="https://www.url.to/tags/<?php echo $tagLink; ?>"><?php echo $tagLink; ?></a></p>
- <?php } ?>
- <?php if(!empty($catLink)) { ?>
- <p>Kategorie: <a href="https://www.url.to/topics/<?php echo $catLink; ?>"><?php echo $catLink; ?></a></p>
- <?php } ?>
-
- <?php if(!empty($searchResult)) { ?>
- <ul>
- <?php
- foreach($searchResult as $result) {
- echo "<li><a href='".$result['href']."'>".$result['text']."</a></li>\n";
- }
- ?>
- </ul>
- <?php } else { ?>
- <div>
- <p>Leider nichts gefunden.</p>
- </div>
- <?php } ?>
-
- </article>
- </div>
- </body>
- </html>
|