Clean up outdated scripts

See #16
This commit is contained in:
2022-11-07 00:31:57 +01:00
parent 82f01a0961
commit 85ea427242
13 changed files with 52 additions and 1165 deletions

View File

@ -9,11 +9,11 @@
declare(strict_types = 1);
// Set autoloader
# \error_reporting(E_ALL);
# \ini_set('display_errors', "1");
\error_reporting(E_ALL);
\ini_set('display_errors', "1");
\spl_autoload_register("mdCsvxmlAutoloader");
\set_exception_handler("mdExceptionHandler");
\set_error_handler("mdErrorHandler", E_ALL);
# \set_exception_handler("mdExceptionHandler");
# \set_error_handler("mdErrorHandler", E_ALL);
require_once __DIR__ . '/../inc/constants.php';
require_once __DIR__ . '/../vendor/autoload.php';
@ -177,165 +177,3 @@ function mdExceptionHandler(Throwable $exception):void {
}
}
/**
* Function for generating the HTML head.
*
* @param string $injected Additional code to inject into the head, e.g. a
* reference to JS files.
*
* @return string
*/
function printHTMLHead(string $injected = ""):string {
$output = '<!DOCTYPE HTML>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta name="description" content="Validate import CSV files for museum-digital" />
<link rel="stylesheet" type="text/css" href="assets/css/csvxml.min.css" />
<meta name="theme-color" content="#aa4400" />
<link rel="shortcut icon" sizes="128x128" href="assets/img/mdlogo-csvxml.svg" />
<script src="assets/js/csvxml-overview.min.js" type="text/javascript" defer></script>
<meta name="robots" content="noindex" />
<title>CSVXML :: museum-digital</title>
<meta name="keywords" content="Imports, museum-digital" />
';
$output .= $injected;
$output .= '
</head>
<body>
<h1>
<img src="assets/img/mdlogo-csvxml.svg" alt="" />
<span>museum-digital:csvxml</span>
</h1>
';
return $output;
}
/**
* Function generateHelpTooltip returns a tooltip for hovering over using the common settings.
*
* @param string $identifier ID attribute of the tooltip.
* @param string $title Title of the tooltip.
* @param string $explica More in-depth explanation: body of the tooltip.
* @param boolean $setParagraph If set to true (default), the content of the tooltip will be put into a <p> element. Optional.
*
* @return array
*/
function generateHelpTooltip(string $identifier, string $title, string $explica, bool $setParagraph = true):array {
$outputTag = '<a class="newToolTipTag icons iconsHelp" data-for="' . $identifier . '" title="Help"></a>';
$output = '<span class="newToolTip" id="tooltip_' . $identifier . '" data-title="' . $title . '">';
if ($setParagraph) $output .= '<p class="toolTipCont">';
$output .= $explica;
if ($setParagraph) $output .= '</p>';
$output .= '</span>';
return [$output, $outputTag];
}
/**
* Outputs a DOMDocument with correct header and then aborts.
* Used mainly for debugging.
*
* @param DOMDocument $xmlDoc XML object.
*
* @return string
*/
function printDOMDocToXML(DOMDocument $xmlDoc):string {
return '<?xml version="1.0" encoding="UTF-8"?>' . $xmlDoc->saveXML($xmlDoc->documentElement);
}
/**
* Function for creating a DOMElement with a text node inside.
*
* @param DOMDocument $xmlDoc XML document.
* @param string $tag Tag.
* @param string $content Text content.
*
* @return DOMElement
*/
function createTextDomElement(DOMDocument $xmlDoc, string $tag, string $content):DOMElement {
try {
$element = $xmlDoc->createElement($tag);
}
catch (DOMException $e) {
echo "Error at " . __FILE__ . ", line #" . __LINE__ . PHP_EOL . "<br/>";
echo "Cannot create DOM element for $tag / $content";
exit;
}
$element->appendChild($xmlDoc->createTextNode($content));
return $element;
}
/**
* Function for creating a DOMDocument record channel.
*
* @return array
*/
function getBlankRecordChannel():array {
$xmlDoc = new DOMDocument("1.0", "UTF-8");
$xmlMainElem = $xmlDoc->createElement("record");
$record_node = $xmlDoc->appendChild($xmlMainElem); //add RSS element to XML node
return [$xmlDoc, $record_node];
}
/**
* Function for removing a directory with all its contents.
*
* @param string $dir File path of the directory to remove.
*
* @return void
*/
function rrmdir(string $dir):void {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir . "/" . $object) == "dir") rrmdir($dir . "/" . $object);
else unlink($dir . "/" . $object);
}
}
reset($objects);
rmdir($dir);
}
}
/**
* Function for checking if two arrays have identical values / contents.
*
* @param array $arrayA First array to compare.
* @param array $arrayB Second array to compare.
*
* @return boolean
*/
function identical_values(array $arrayA, array $arrayB):bool {
sort($arrayA);
sort($arrayB);
return $arrayA == $arrayB;
}