*/
/**
* 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",
"exhibitionCalendar",
"eventCalendar"
];
foreach ($embedOptions as $option) {
if (strpos($text, $option) === false) continue;
$position = strpos($text, $option) - 1;
$nextTag = $nextWhitespace = strlen($text);
if (strpos($text, "<", $position) !== false) $nextTag = strpos($text, "<", $position);
if (strpos($text, " ", $position) !== false) $nextWhitespace = strpos($text, " ", $position);
$end = min($nextTag, $nextWhitespace);
$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 "exhibitionCalendar":
$text = str_replace($pseudocode, embedExhibitionCalendar($arguments), $text);
break;
case "eventCalendar":
$text = str_replace($pseudocode, embedEventCalendar($arguments), $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'] . '
';
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 .= '
';
}
$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 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 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 = '
';
foreach ($contents as $object) {
$output .= '
';
if (isset($object['image']) > 0) {
$output .= '
';
}
$output .= '
' . $object['objekt_name'] . '
';
}
$output .= '
';
return $output;
}
?>