Added interpreter for pseudocode for displaying exhibitions, events.
Added basic search. Added object pages.
This commit is contained in:
@ -69,13 +69,15 @@ function ensureEnvironment() {
|
||||
|
||||
$settings = array_merge(
|
||||
[
|
||||
"startPage" => "1",
|
||||
"pageTitle" => "md:cms",
|
||||
"logo" => "",
|
||||
"url" => "",
|
||||
"mdVersion" => "https://www.museum-digital.de/nat/",
|
||||
"maxFileSize" => 300000,
|
||||
"defaultLang" => "en"
|
||||
"startPage" => "1",
|
||||
"pageTitle" => "md:cms",
|
||||
"logo" => "",
|
||||
"url" => "",
|
||||
"cacheRefreshInterval" => 0,
|
||||
"mdVersion" => "https://rlp.museum-digital.de/",
|
||||
"mdImgFolder" => "https://rlp.museum-digital.de/data/rlp/",
|
||||
"maxFileSize" => 300000,
|
||||
"defaultLang" => "en"
|
||||
],
|
||||
json_decode(file_get_contents(__DIR__ . "/../data/settings.json"), true)
|
||||
);
|
||||
@ -109,6 +111,42 @@ function loadPublicPages() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Query or cache pages.
|
||||
*
|
||||
* @param string $url URL to query.
|
||||
* @param string $area The type of the queried page. If caching is enabled, renew cache every X seconds.
|
||||
* @param array $settings Settings variable.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function queryCachePage(string $url, string $area = "", array $settings = ['cacheRefreshInterval' => 0]) {
|
||||
|
||||
// Ignore caching if cacheRefreshInterval equals zero.
|
||||
if ($settings['cacheRefreshInterval'] == 0) {
|
||||
return file_get_contents($url);
|
||||
}
|
||||
|
||||
$fileDir = __DIR__ . "/../data/caches/$area";
|
||||
ensureDir($fileDir);
|
||||
|
||||
$fileName = md5($url);
|
||||
$filePath = "$fileDir/$fileName.json";
|
||||
|
||||
// Load from cache.
|
||||
if (file_exists($filePath) && time() - filemtime($filePath) < $settings['cacheRefreshInterval']) {
|
||||
return file_get_contents($filePath);
|
||||
}
|
||||
|
||||
// Refresh cache.
|
||||
|
||||
$contents = file_get_contents($url);
|
||||
file_put_contents($filePath, $contents, LOCK_EX);
|
||||
|
||||
return $contents;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function scanDirConts is a wrapper around scandir(), which removes [".", ".."].
|
||||
*
|
||||
@ -320,4 +358,78 @@ function checkPreviewAccess($sessionStarted = false) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function checking if a string starts with another.
|
||||
*
|
||||
* @param string $haystack String to check.
|
||||
* @param string $needle Potential start of $haystack.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function startswith(string $haystack, string $needle):bool {
|
||||
if (substr($haystack, 0, strlen($needle)) == $needle) return (true);
|
||||
else return (false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function checking if a string starts with any input from the input array.
|
||||
*
|
||||
* @param string $haystack String to check.
|
||||
* @param string[] $needles Array containing potential start values of $haystack.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function startswithAny(string $haystack, array $needles):bool {
|
||||
$output = false;
|
||||
foreach ($needles as $needle) {
|
||||
$output = startswith($haystack, $needle);
|
||||
if ($output == true) return $output;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Curling web pages.
|
||||
* Function to check errors.
|
||||
*
|
||||
* @param string $url URL to query.
|
||||
* @param string $host Authentication data. Optional.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function runCurl(string $url, string $host = ""):string {
|
||||
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
// curl_setopt($curl, CURLOPT_RESOLVE, ["www.example.com:443:172.16.1.1"]);
|
||||
curl_setopt($curl, CURLOPT_ENCODING, '');
|
||||
if ($host) curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $host"));
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$result = curl_exec($curl);
|
||||
|
||||
curl_close($curl);
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function cuts down a string and adds a period in case it's longer than length to create a snippet.
|
||||
*
|
||||
* @param string $string Input text to cut down
|
||||
* @param int $length Length of the snippet to create
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function createTextSnippet($string, $length) {
|
||||
|
||||
if (strlen($string) > $length) {
|
||||
$string = substr($string, 0, $length);
|
||||
$string = substr($string, 0, strrpos($string, ' '));
|
||||
$string .= ' ...';
|
||||
}
|
||||
return $string;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user