diff --git a/inc/mdEmbeds.php b/inc/mdEmbeds.php
index 2695bdd..9276845 100644
--- a/inc/mdEmbeds.php
+++ b/inc/mdEmbeds.php
@@ -362,4 +362,61 @@ function embedEventCalendar(array $arguments):string {
return $output;
}
+/**
+ * Function for embedding search results from MD.
+ *
+ * @param array $arguments Arguments / GET parameters for urls to query.
+ * @param array $settings Settings variable.
+ *
+ * @return string
+ */
+function searchMDObjects(array $arguments, array $settings):string {
+
+ $toIgnore = ["t=", "output=", "mod="];
+ $srcArgs = "done=yes";
+ foreach ($arguments as $arg) {
+ if (startsWithAny($arg, $toIgnore)) continue;
+ $srcArgs .= "&" . $arg;
+ }
+ $srcArgs .= "&output=json&mod=complete";
+
+ $contents = json_decode(queryCachePage($settings['mdVersion'] . "?$srcArgs", "search", $settings), true);
+
+ $output = '
+
+ ';
+
+ foreach ($contents as $object) {
+ $output .= '
+
+ ';
+
+ if (isset($object['image']) > 0) {
+ $output .= '
+
';
+ }
+
+ $output .= '
+
+
+
' . $object['objekt_name'] . '
+
+
+
+
+
+
+ ';
+ }
+
+ $output .= '
+
+ ';
+
+ return $output;
+}
+
?>
diff --git a/inc/search.php b/inc/search.php
index 261ced4..9b679c9 100644
--- a/inc/search.php
+++ b/inc/search.php
@@ -14,7 +14,7 @@
*
* @return array
*/
-function searchInPages(string $searchTerm) {
+function searchInPages(string $searchTerm):array {
$files = scanDirConts(__DIR__ . "/../data/static");
@@ -34,19 +34,55 @@ function searchInPages(string $searchTerm) {
$curResults['title'] = $contents['title'];
// Sanitize content for snippets.
- $snippet = preg_replace('/[\[{\(].*[\]}\)]/U' , '', strip_tags($contents['content']));
+ $snippet = preg_replace('/[\[{\(].*[\]}\)]/U', '', strip_tags($contents['content']));
$curResults['snippet'] = createTextSnippet($snippet, 180);
$results[$file] = $curResults;
}
usort($results, function($a, $b) {
- if ($a == $b) return 0;
- return ($a > $b) ? -1 : 1;
+ if ($a['priority'] == $b['priority']) return 0;
+ return ($a['priority'] > $b['priority']) ? -1 : 1;
});
return $results;
}
+/**
+ * Function for generating and listing search results.
+ *
+ * @param string $searchTerm Search term.
+ *
+ * @return string
+ */
+function displaySearchResults(string $searchTerm):string {
+
+ $searchResults = searchInPages($searchTerm);
+ $output = '
+ ';
+
+ foreach ($searchResults as $file => $item) {
+ $output .= '
+ -
+
+
' . $item['title'] . '
+ ' . (string)($item['snippet']) . '
+
+
+ - ' . (string)($item['inTitle'] + $item['inDescription']) . '
+
+
+
+ ';
+ }
+
+ $output .= "
+
";
+
+ return $output;
+
+}
+
+
?>
diff --git a/js/main.js b/js/main.js
index 1f6b5f7..521a038 100644
--- a/js/main.js
+++ b/js/main.js
@@ -29,6 +29,8 @@ document.addEventListener("DOMContentLoaded", function() {
"Times" : "Times",
"Search" : "Search",
"SearchingFor" : "Searching for",
+ "Hits" : "Hits:",
+ "ResultsInPages" : "Results in texts",
"... who" : "... who",
"... where" : "... where",
"... when" : "... when",
@@ -50,6 +52,8 @@ document.addEventListener("DOMContentLoaded", function() {
"Times" : "Zeiten",
"Search" : "Suche",
"SearchingFor" : "Suche nach",
+ "Hits" : "Treffer:",
+ "ResultsInPages" : "Treffer in Texten",
"... who" : "... wer",
"... where" : "... wo",
"... when" : "... wann",
diff --git a/search.php b/search.php
index 88907d7..b26e111 100644
--- a/search.php
+++ b/search.php
@@ -51,9 +51,19 @@ if (!isset($_GET['q'])) {
}
else {
- echo ' "' . $_GET['q'] . '"
';
- $resultsInPages = searchInPages($_GET['q']);
- print_r($resultsInPages);
+ echo '
+ "' . $_GET['q'] . '"
+
+
+
+ ' . displaySearchResults($_GET['q']) . '
+
+
+
+
+ ' . searchMDObjects(["sv=" . $_GET['q']], $settings) . '
+
+ ';
}
diff --git a/themes/default/default.css b/themes/default/default.css
index 1c5ab52..d26209e 100644
--- a/themes/default/default.css
+++ b/themes/default/default.css
@@ -24,7 +24,8 @@
*/
html { margin: 0; padding: 0; }
-body { margin: 0; padding: 0; font-family: sourceSansPro; font-size: 1.15em; line-height: 1.5; }
+body { margin: 0; padding: 0; font-family: sourceSansPro;
+ font-size: 1.15em; line-height: 1.5; }
* { box-sizing: border-box; z-index: 1; }
a { color: inherit; text-decoration: none; }
@@ -35,8 +36,10 @@ a.buttonLike,
select,
button,
textarea,
-input { padding: .6em .8em; background: #FAFAFA; border: 1px solid #CFD8DC; font-family: roboto; font-size: inherit;
- border-radius: .3em; transition: background .1s, box-shadow .1s; box-sizing: border-box; }
+input { padding: .6em .8em; background: #FAFAFA; border: 1px solid #CFD8DC;
+ font-family: roboto; font-size: inherit;
+ border-radius: .3em; box-sizing: border-box;
+ transition: background .1s, box-shadow .1s; }
button { padding: .6em; }
select { padding: .3em .8em; }
textarea { line-height: 1.4em; }
@@ -135,6 +138,10 @@ main { padding: .5em 5em 3em 0; text-align: justify; }
body > footer { margin: 1em 5vw 2em 5vw; padding: 1em 0; background: #FFF; color: #666;
border-top: 1px solid #AAA; }
+/****************************
+ * Specialized pages.
+ */
+
/************
* Editing Static Pages
*/
@@ -152,6 +159,21 @@ body > footer { margin: 1em 5vw 2em 5vw; padding: 1em 0; background: #FFF; color
#pageTools > * { padding: 0 1rem; }
+/************
+ * Search pages
+ */
+
+#pagesSearchList,
+#pagesSearchList li { margin: 0; padding: 0; list-style: none; }
+#pagesSearchList li { margin: .5em 0; padding: .5em 0;
+ border-bottom: 1px solid #D6D6D6; transition: border-bottom .4s; }
+#pagesSearchList li:hover { border-bottom-color: #666; }
+
+#pagesSearchList h4 { margin: 0; padding: 0; }
+#pagesSearchList dl { color: #666; font-size: .9em; }
+#pagesSearchList dt,
+#pagesSearchList dd { display: inline-block; margin: 0; padding: 0; }
+
/************
* Login Page
*/
@@ -175,6 +197,7 @@ body > footer { margin: 1em 5vw 2em 5vw; padding: 1em 0; background: #FFF; color
/************
* Larger screens.
*/
+
@media screen and (min-width: 95em) {
#mainHeader,
body > nav,
diff --git a/themes/default/mdEmbeds.css b/themes/default/mdEmbeds.css
index 664979e..6473fe5 100644
--- a/themes/default/mdEmbeds.css
+++ b/themes/default/mdEmbeds.css
@@ -3,6 +3,14 @@
* Styles for data embedded from museum-digital.
*/
+/**********
+ * Objects in search results.
+ */
+
+.searchGrid { }
+.searchGrid .objTile { margin-bottom: 1em; vertical-align: top; }
+.searchGrid .objTile img { max-height: 180px; }
+
/**********
* Simple tiles for displaying an object.
*/