Added basic support of search for objects.
This commit is contained in:
parent
80485a98ab
commit
5c4f0eb5d9
|
@ -362,4 +362,61 @@ function embedEventCalendar(array $arguments):string {
|
||||||
return $output;
|
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 = '
|
||||||
|
<div class="searchGrid">
|
||||||
|
';
|
||||||
|
|
||||||
|
foreach ($contents as $object) {
|
||||||
|
$output .= '
|
||||||
|
<div class="objTile">
|
||||||
|
';
|
||||||
|
|
||||||
|
if (isset($object['image']) > 0) {
|
||||||
|
$output .= '
|
||||||
|
<img src="' . $settings['mdVersion'] . $object['image'] . '" />';
|
||||||
|
}
|
||||||
|
|
||||||
|
$output .= '
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<h4>' . $object['objekt_name'] . '</h4>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<a href="./object.php?id=' . $object['objekt_id'] . '" class="toTranslate" data-content="More"></a>
|
||||||
|
<a href="' . $settings['mdVersion'] . '?t=objekt&oges=' . $object['objekt_id'] . '" class="toTranslate" data-content="MoreAtMuseumDigital">' . $object['objekt_name'] . '</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
}
|
||||||
|
|
||||||
|
$output .= '
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function searchInPages(string $searchTerm) {
|
function searchInPages(string $searchTerm):array {
|
||||||
|
|
||||||
$files = scanDirConts(__DIR__ . "/../data/static");
|
$files = scanDirConts(__DIR__ . "/../data/static");
|
||||||
|
|
||||||
|
@ -41,12 +41,48 @@ function searchInPages(string $searchTerm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
usort($results, function($a, $b) {
|
usort($results, function($a, $b) {
|
||||||
if ($a == $b) return 0;
|
if ($a['priority'] == $b['priority']) return 0;
|
||||||
return ($a > $b) ? -1 : 1;
|
return ($a['priority'] > $b['priority']) ? -1 : 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
return $results;
|
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 = '
|
||||||
|
<ul id="pagesSearchList">';
|
||||||
|
|
||||||
|
foreach ($searchResults as $file => $item) {
|
||||||
|
$output .= '
|
||||||
|
<li>
|
||||||
|
|
||||||
|
<a href="./?id=' . str_replace(".json", "", $file) . '"><h4>' . $item['title'] . '</h4></a>
|
||||||
|
<p>' . (string)($item['snippet']) . '</p>
|
||||||
|
<dl class="searchMetadataLine">
|
||||||
|
<dt class="toTranslate" data-content="Hits"></dt>
|
||||||
|
<dd>' . (string)($item['inTitle'] + $item['inDescription']) . '</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
';
|
||||||
|
}
|
||||||
|
|
||||||
|
$output .= "
|
||||||
|
</ul>";
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -29,6 +29,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
"Times" : "Times",
|
"Times" : "Times",
|
||||||
"Search" : "Search",
|
"Search" : "Search",
|
||||||
"SearchingFor" : "Searching for",
|
"SearchingFor" : "Searching for",
|
||||||
|
"Hits" : "Hits:",
|
||||||
|
"ResultsInPages" : "Results in texts",
|
||||||
"... who" : "... who",
|
"... who" : "... who",
|
||||||
"... where" : "... where",
|
"... where" : "... where",
|
||||||
"... when" : "... when",
|
"... when" : "... when",
|
||||||
|
@ -50,6 +52,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
"Times" : "Zeiten",
|
"Times" : "Zeiten",
|
||||||
"Search" : "Suche",
|
"Search" : "Suche",
|
||||||
"SearchingFor" : "Suche nach",
|
"SearchingFor" : "Suche nach",
|
||||||
|
"Hits" : "Treffer:",
|
||||||
|
"ResultsInPages" : "Treffer in Texten",
|
||||||
"... who" : "... wer",
|
"... who" : "... wer",
|
||||||
"... where" : "... wo",
|
"... where" : "... wo",
|
||||||
"... when" : "... wann",
|
"... when" : "... wann",
|
||||||
|
|
16
search.php
16
search.php
|
@ -51,9 +51,19 @@ if (!isset($_GET['q'])) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
echo '<h1><span class="toTranslate" data-content="SearchingFor"></span> "' . $_GET['q'] . '"</h1>';
|
echo '
|
||||||
$resultsInPages = searchInPages($_GET['q']);
|
<h1><span class="toTranslate" data-content="SearchingFor"></span> "' . $_GET['q'] . '"</h1>
|
||||||
print_r($resultsInPages);
|
|
||||||
|
<section>
|
||||||
|
<h2><span class="toTranslate" data-content="ResultsInPages"></span></h2>
|
||||||
|
' . displaySearchResults($_GET['q']) . '
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="mdSearchObjs">
|
||||||
|
<h2><span class="toTranslate" data-content="ResultsInObjects"></span></h2>
|
||||||
|
' . searchMDObjects(["sv=" . $_GET['q']], $settings) . '
|
||||||
|
</section>
|
||||||
|
';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
html { margin: 0; padding: 0; }
|
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; }
|
* { box-sizing: border-box; z-index: 1; }
|
||||||
a { color: inherit; text-decoration: none; }
|
a { color: inherit; text-decoration: none; }
|
||||||
|
@ -35,8 +36,10 @@ a.buttonLike,
|
||||||
select,
|
select,
|
||||||
button,
|
button,
|
||||||
textarea,
|
textarea,
|
||||||
input { padding: .6em .8em; background: #FAFAFA; border: 1px solid #CFD8DC; font-family: roboto; font-size: inherit;
|
input { padding: .6em .8em; background: #FAFAFA; border: 1px solid #CFD8DC;
|
||||||
border-radius: .3em; transition: background .1s, box-shadow .1s; box-sizing: border-box; }
|
font-family: roboto; font-size: inherit;
|
||||||
|
border-radius: .3em; box-sizing: border-box;
|
||||||
|
transition: background .1s, box-shadow .1s; }
|
||||||
button { padding: .6em; }
|
button { padding: .6em; }
|
||||||
select { padding: .3em .8em; }
|
select { padding: .3em .8em; }
|
||||||
textarea { line-height: 1.4em; }
|
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;
|
body > footer { margin: 1em 5vw 2em 5vw; padding: 1em 0; background: #FFF; color: #666;
|
||||||
border-top: 1px solid #AAA; }
|
border-top: 1px solid #AAA; }
|
||||||
|
|
||||||
|
/****************************
|
||||||
|
* Specialized pages.
|
||||||
|
*/
|
||||||
|
|
||||||
/************
|
/************
|
||||||
* Editing Static 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; }
|
#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
|
* Login Page
|
||||||
*/
|
*/
|
||||||
|
@ -175,6 +197,7 @@ body > footer { margin: 1em 5vw 2em 5vw; padding: 1em 0; background: #FFF; color
|
||||||
/************
|
/************
|
||||||
* Larger screens.
|
* Larger screens.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@media screen and (min-width: 95em) {
|
@media screen and (min-width: 95em) {
|
||||||
#mainHeader,
|
#mainHeader,
|
||||||
body > nav,
|
body > nav,
|
||||||
|
|
|
@ -3,6 +3,14 @@
|
||||||
* Styles for data embedded from museum-digital.
|
* 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.
|
* Simple tiles for displaying an object.
|
||||||
*/
|
*/
|
||||||
|
|
Reference in New Issue
Block a user