*/ /** * Function for checking a text for the existence of pseudocode * for embedding from museum-digital. * * @param string $text Input string. * @param array $settings General settings. * * @return string */ function checkForEmbeds(string $text, array $settings):string { $embedOptions = [ "singleObjectTile", "singleObjectDetails", "singleCollectionTile", "singleCollectionDetails", "singleInstitutionTile", "singleInstitutionDetails", "singleExhibitionDetails", "singleEventDetails", "exhibitionCalendar", "eventCalendar" ]; foreach ($embedOptions as $option) { $i = 0; while (strpos($text, $option) !== false) { $position = strpos($text, $option) - 1; $nextTag = $nextWhitespace = $nextNBSP = strlen($text); if (strpos($text, "<", $position) !== false) $nextTag = strpos($text, "<", $position); if (strpos($text, " ", $position) !== false) $nextWhitespace = strpos($text, " ", $position); if (strpos($text, " ", $position) !== false) $nextNBSP = strpos($text, " ", $position); // The pseudocode ends with a whitespace. No two tiles can be immediately after each other. $end = min($nextTag, $nextWhitespace, $nextNBSP); $pseudocode = substr($text, $position, $end - $position); $command = substr($pseudocode, 1, strpos($pseudocode, "]") - 1); $arguments = []; if (strpos($pseudocode, "{") !== false) $arguments = explode("&", substr($pseudocode, strpos($pseudocode, "{") + 1, -1)); switch ($command) { case "singleObjectTile": $text = str_replace($pseudocode, embedObject($arguments, $settings), $text); break; case "singleObjectDetails": $text = str_replace($pseudocode, embedObject($arguments, $settings, true), $text); break; case "singleCollectionTile": $text = str_replace($pseudocode, embedCollection($arguments, $settings), $text); break; case "singleCollectionDetails": $text = str_replace($pseudocode, embedCollection($arguments, $settings, true), $text); break; case "singleInstitutionTile": $text = str_replace($pseudocode, embedInstitution($arguments, $settings), $text); break; case "singleInstitutionDetails": $text = str_replace($pseudocode, embedInstitution($arguments, $settings, true), $text); break; case "exhibitionCalendar": $text = str_replace($pseudocode, embedExhibitionCalendar($arguments), $text); break; case "singleExhibitionDetails": $text = str_replace($pseudocode, embedExhibition($arguments, $settings, true), $text); break; case "eventCalendar": $text = str_replace($pseudocode, embedEventCalendar($arguments), $text); break; case "singleEventDetails": $text = str_replace($pseudocode, embedEvent($arguments, $settings, true), $text); break; } } } return $text; } /** * Function drawObjectTile creates a tile with just the most basic information on an object. * * @param string[] $contents Input data fetched from the object API at museum-digital. * @param array $settings Settings variable. * * @return string */ function drawObjectTile(array $contents, array $settings):string { $output = '
'; if (count($contents['object_images']) > 0) { foreach ($contents['object_images'] as $image) { if ($image['is_main'] != "j") continue; $output .= ' '; } } $output .= '

' . $contents['object_name'] . '

'; if (!$settings['hideInstitution']) $output .= ' ' . $contents['object_institution']['institution_name'] . ''; $output .= '
' . $contents['object_name'] . '
'; return $output; } /** * Function drawObjectDetails creates a tile with just the most basic information on an object. * * @param string[] $contents Input data fetched from the object API at museum-digital. * @param array $settings Settings variable. * * @return string */ function drawObjectDetails(array $contents, array $settings):string { $output = '

' . $contents['object_name'] . '

'; if (count($contents['object_images']) > 0) { foreach ($contents['object_images'] as $image) { if ($image['is_main'] != "j") continue; $output .= ' '; } } $output .= '
'; $output .= '

' . $contents['object_description'] . '

'; $simpleDefinedConts = [ "object_material_technique", "object_dimensions", ]; $output .= "
"; if (count($contents['object_collection']) > 0) { $output .= '
'; foreach ($contents['object_collection'] as $collection) { $output .= '
' . $collection['collection_name'] . '
'; } } foreach ($simpleDefinedConts as $value) { $output .= "
" . $contents[$value] . "
"; } if (count($contents['object_tags']) > 0) { $output .= '
'; foreach ($contents['object_tags'] as $tag) { $output .= '
' . $tag['tag_name'] . '
'; } } if (count($contents['object_relation_places']) > 0) { $output .= '
'; foreach ($contents['object_relation_places'] as $place) { $output .= '
' . $place['place']['place_name'] . '
'; } } if (count($contents['object_relation_people']) > 0) { $output .= '
'; foreach ($contents['object_relation_people'] as $people) { $output .= '
' . $people['people']['displayname'] . '
'; } } $output .= "
"; if (count($contents['object_events']) > 0) { $output .= "
"; foreach ($contents['object_events'] as $event) { $output .= '
'; if (isset($event['people'])) $output .= ' '; if (isset($event['time'])) $output .= ' '; if (isset($event['place'])) $output .= ' '; $output .= '
' . $event['time']['time_name'] . '
'; } $output .= '
'; } $output .= '

: ' . $contents['object_last_updated'] . ' : ' . $contents['licence']['metadata_rights_status'] . '

'; $output .= '
'; return $output; } /** * Function for displaying objects. * * @param array $arguments Arguments / GET parameters for urls to query. * @param array $settings Settings variable. * @param boolean $showDetails Optional. By default, only a tile with most basic information is displayed. * * @return string */ function embedObject(array $arguments, array $settings, bool $showDetails = false):string { $toIgnore = ["t=", "output="]; $srcArgs = "t=objekt"; foreach ($arguments as $arg) { if (startsWithAny($arg, $toIgnore)) continue; $srcArgs .= "&" . $arg; } $srcArgs .= "&output=json"; $contents = json_decode(queryCachePage($settings['mdVersion'] . "?$srcArgs", "object", $settings), true); if (!$showDetails) return drawObjectTile($contents, $settings); else return drawObjectDetails($contents, $settings); } /** * Function drawInstitutionDetails generates a detail area * containing data fetched from the institution API at museum-digital. * * @param string[] $contents Input data fetched from the institution API at museum-digital. * @param array $settings Settings variable. * * @return string */ function drawInstitutionDetails(array $contents, array $settings):string { $output = '
'; if (isset($contents['institution_image']) and $contents['institution_image']) { $output .= ' '; } $output .= '

' . $contents['institution_name'] . '

' . $contents['institution_description'] . '

'; $output .= '
'; if ($contents['institution_street']) $output .= $contents['institution_street'] . '
'; if ($contents['institution_zipcode']) $output .= $contents['institution_zipcode'] . " " . $contents['institution_place'] . "
"; if ($contents['institution_telnr']) $output .= "" . $contents['institution_telnr'] . "
"; $output .= '
'; if (count($contents['collections']) >= 1) { $output .= '

'; } $output .= '

'; return $output; } /** * Function drawInstitutionTile creates a tile with just the most basic information on an institiution. * * @param string[] $contents Input data fetched from the collection API at museum-digital. * @param array $settings Settings variable. * * @return string */ function drawInstitutionTile(array $contents, array $settings):string { $output = '
'; if (isset($contents['institution_image']) and $contents['institution_image']) { $output .= ' '; } $output .= '

' . $contents['institution_name'] . '

' . $contents['institution_street'] . ' ' . $contents['institution_zipcode'] . " " . $contents['institution_place'] . '

' . $contents['institution_name'] . '
'; return $output; } /** * Function for displaying institution. * * @param array $arguments Arguments / GET parameters for urls to query. * @param array $settings Settings variable. * @param boolean $showDetails Optional. By default, only a tile with most basic information is displayed. * * @return string */ function embedInstitution(array $arguments, array $settings, bool $showDetails = false):string { $toIgnore = ["t=", "output="]; $srcArgs = "t=institution"; foreach ($arguments as $arg) { if (startsWithAny($arg, $toIgnore)) continue; $srcArgs .= "&" . $arg; } $srcArgs .= "&output=json"; $contents = json_decode(queryCachePage($settings['mdVersion'] . "?$srcArgs", "institution", $settings), true); if (!$showDetails) return drawInstitutionTile($contents, $settings); else return drawInstitutionDetails($contents, $settings); } /** * Function drawCollectionDetails generates a detail area. * * @param string[] $contents Input data fetched from the collections API at museum-digital. * @param array $settings Settings variable. * * @return string */ function drawCollectionDetails(array $contents, array $settings):string { $output = '
'; if (isset($contents['collection_image']) and $contents['collection_image']) { $output .= ' '; } $output .= '

' . $contents['collection_name'] . '

' . $contents['collection_description'] . '

'; if (!$settings['hideInstitution']) $output .= ' ' . $contents['collection_institution']['institution_name'] . ' '; $output .= '

'; return $output; } /** * Function drawCollectionTile creates a tile with just the most basic information on a collection. * * @param string[] $contents Input data fetched from the collection API at museum-digital. * @param array $settings Settings variable. * * @return string */ function drawCollectionTile(array $contents, array $settings):string { $output = '
'; if (isset($contents['collection_image']) and $contents['collection_image']) { $output .= ' '; } $output .= '

' . $contents['collection_name'] . '

' . createTextSnippet($contents['collection_description'], 180) . '

'; if (!$settings['hideInstitution']) $output .= ' ' . $contents['collection_institution']['institution_name'] . ''; $output .= '
' . $contents['collection_name'] . '
'; return $output; } /** * Function for displaying collections. * * @param array $arguments Arguments / GET parameters for urls to query. * @param array $settings Settings variable. * @param boolean $showDetails Optional. By default, only a tile with most basic information is displayed. * * @return string */ function embedCollection(array $arguments, array $settings, bool $showDetails = false):string { $toIgnore = ["t=", "output="]; $srcArgs = "t=sammlung"; foreach ($arguments as $arg) { if (startsWithAny($arg, $toIgnore)) continue; $srcArgs .= "&" . $arg; } $srcArgs .= "&output=json"; $contents = json_decode(queryCachePage($settings['mdVersion'] . "?$srcArgs", "collection", $settings), true); if (!$showDetails) return drawCollectionTile($contents, $settings); else return drawCollectionDetails($contents, $settings); } /** * Function drawExhibitionDetails creates a tile with just the most basic information on an exhibition. * * @param string[] $contents Input data fetched from the collection API at museum-digital. * @param array $settings Settings variable. * * @return string */ function drawExhibitionDetails(array $contents, array $settings):string { $output = '
'; if (isset($contents['image']) and $contents['image']) { $output .= ' '; } $output .= '

' . $contents['name'] . '

-

' . $contents['description'] . '

'; $output .= '

' . $contents['institution_name'] . ' (' . $contents['institution_ort'] . ')

'; $output .= '

'; return $output; } /** * Function drawExhibitionTile creates a tile with just the most basic information on an exhibition. * * @param string[] $contents Input data fetched from the collection API at museum-digital. * @param array $settings Settings variable. * * @return string */ function drawExhibitionTile(array $contents, array $settings):string { $output = '
'; if (isset($contents['image']) and $contents['image']) { $output .= ' '; } $output .= '

' . $contents['name'] . '

'; if (!$settings['hideInstitution']) $output .= ' ' . $contents['institution_name'] . ''; $output .= '
' . $contents['name'] . '
'; return $output; } /** * Function for displaying exhibition. * * @param array $arguments Arguments / GET parameters for urls to query. * @param array $settings Settings variable. * @param boolean $showDetails Optional. By default, only a tile with most basic information is displayed. * * @return string */ function embedExhibition(array $arguments, array $settings, bool $showDetails = false):string { $toIgnore = ["t=", "output="]; $srcArgs = "t=exhibition"; foreach ($arguments as $arg) { if (startsWithAny($arg, $toIgnore)) continue; $srcArgs .= "&" . $arg; } $srcArgs .= "&output=json"; $contents = json_decode(queryCachePage($settings['mdVersion'] . "?$srcArgs", "exhibition", $settings), true); if (!$showDetails) return drawExhibitionTile($contents, $settings); else return drawExhibitionDetails($contents, $settings); } /** * Function for embedding event calendar. * * @param array $arguments Arguments / GET parameters for urls to query. * * @return string */ function embedExhibitionCalendar(array $arguments):string { $toIgnore = ["t=", "calendar=", "output="]; $srcArgs = "t=exhibitions_overview&calendar=1"; foreach ($arguments as $arg) { if (startsWithAny($arg, $toIgnore)) continue; $srcArgs .= "&" . $arg; } $srcArgs .= "&output=json"; $srcURL = "apiMirror.php?area=exhibitions&args=" . urlencode($srcArgs); if (isset($_GET['y'])) $y = $_GET['y']; else $y = date("Y"); if (isset($_GET['m'])) $m = $_GET['m']; else $m = date("m"); $prevMonth = strtotime('-1 month', strtotime("$y-$m-01")); $nextMonth = strtotime('+1 month', strtotime("$y-$m-01")); $output = '
'; return $output; } /** * Function drawEventDetails creates a tile with just the most basic information on an event. * * @param string[] $contents Input data fetched from the event API at museum-digital. * @param array $settings Settings variable. * * @return string */ function drawEventDetails(array $contents, array $settings):string { $output = '
'; if (isset($contents['image']) and $contents['image']) { $output .= ' '; } $output .= '

' . $contents['name'] . '

-

' . $contents['description'] . '

'; $output .= '

' . $contents['institution_name'] . ' (' . $contents['institution_ort'] . ')

'; $output .= '

'; return $output; } /** * Function drawEventTile creates a tile with just the most basic information on an event. * * @param string[] $contents Input data fetched from the event API at museum-digital. * @param array $settings Settings variable. * * @return string */ function drawEventTile(array $contents, array $settings):string { $output = '
'; if (isset($contents['image']) and $contents['image']) { $output .= ' '; } $output .= '

' . $contents['name'] . '

'; if (!$settings['hideInstitution']) $output .= ' ' . $contents['institution_name'] . ''; $output .= '
' . $contents['name'] . '
'; return $output; } /** * Function for displaying events. * * @param array $arguments Arguments / GET parameters for urls to query. * @param array $settings Settings variable. * @param boolean $showDetails Optional. By default, only a tile with most basic information is displayed. * * @return string */ function embedEvent(array $arguments, array $settings, bool $showDetails = false):string { $toIgnore = ["t=", "output="]; $srcArgs = "t=event"; foreach ($arguments as $arg) { if (startsWithAny($arg, $toIgnore)) continue; $srcArgs .= "&" . $arg; } $srcArgs .= "&output=json"; $contents = json_decode(queryCachePage($settings['mdVersion'] . "?$srcArgs", "event", $settings), true); if (!$showDetails) return drawEventTile($contents, $settings); else return drawEventDetails($contents, $settings); } /** * Function for embedding event calendar. * * @param array $arguments Arguments / GET parameters for urls to query. * * @return string */ function embedEventCalendar(array $arguments):string { $toIgnore = ["t=", "calendar=", "output="]; $srcArgs = "t=events&calendar=1"; foreach ($arguments as $arg) { if (startsWithAny($arg, $toIgnore)) continue; $srcArgs .= "&" . $arg; } $srcArgs .= "&output=json"; $srcURL = "apiMirror.php?area=events&args=" . urlencode($srcArgs); if (isset($_GET['y'])) $y = $_GET['y']; else $y = date("Y"); if (isset($_GET['m'])) $m = $_GET['m']; else $m = date("m"); $prevMonth = strtotime('-1 month', strtotime("$y-$m-01")); $nextMonth = strtotime('+1 month', strtotime("$y-$m-01")); $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); if (!isset($contents[0])) return ""; $output = '
'; if (isset($_GET['startwert']) and $_GET['startwert'] % 24 === 0) $current = $_GET['startwert']; else $current = 0; $toDisplay = []; for ($i = 0; $i <= 7; $i++) { $toDisplay[] = $current + (-72 + 24 * $i); } $i = 0; $lastToDisplay = end($toDisplay); // Display option to go to start if (!in_array(0, $toDisplay)) $output .= '1'; while ($i < $contents[0]['total']) { if (!in_array($i, $toDisplay)) { $i += 24; continue; } $output .= ' ' . strval(($i / 24) + 1) . ' '; $i += 24; if ($i == $lastToDisplay) break; } // Display option to go to start $last = $contents[0]["total"] - ($contents[0]["total"] % 24); if (!in_array($last, $toDisplay)) $output .= '' . (string)(($last / 24) + 1) . ''; // Generate pagination $output .= '
'; foreach ($contents as $object) { $output .= '
'; if (isset($object['image']) > 0) { $output .= ' '; } $output .= '

' . $object['objekt_name'] . '

' . $object['objekt_name'] . '
'; } $output .= '
'; return $output; } ?>