Migrate function file to PHP7. Code Cleanup.
This commit is contained in:
parent
28b8874110
commit
6e5b8ec72e
|
@ -8,14 +8,14 @@
|
|||
/**
|
||||
* Browsersprache ermitteln
|
||||
*
|
||||
* @param array $allowed_languages Array of allowed languages
|
||||
* @param string $default_language Language code of the default language
|
||||
* @param string $lang_variable Already set language variable
|
||||
* @param bool $strict_mode Whether to demand de (false) or de-de
|
||||
* @param array $allowed_languages Array of allowed languages.
|
||||
* @param string $default_language Language code of the default language.
|
||||
* @param string|null $lang_variable Already set language variable.
|
||||
* @param boolean $strict_mode Whether to demand de (false) or de-de.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function lang_getfrombrowser($allowed_languages, $default_language, $lang_variable = null, $strict_mode = true) {
|
||||
function lang_getfrombrowser(array $allowed_languages, string $default_language, $lang_variable = null, bool $strict_mode = true) {
|
||||
// $_SERVER['HTTP_ACCEPT_LANGUAGE'] verwenden, wenn keine Sprachvariable mitgegeben wurde
|
||||
if ($lang_variable === null) {
|
||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) $lang_variable = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
|
||||
|
@ -37,8 +37,7 @@ function lang_getfrombrowser($allowed_languages, $default_language, $lang_variab
|
|||
// Nun alle mitgegebenen Sprachen abarbeiten
|
||||
foreach ($accepted_languages as $accepted_language) {
|
||||
// Alle Infos über diese Sprache rausholen
|
||||
$res = preg_match('/^([a-z]{1,8}(?:-[a-z]{1,8})*)'.
|
||||
'(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i', $accepted_language, $matches
|
||||
$res = preg_match('/^([a-z]{1,8}(?:-[a-z]{1,8})*)' . '(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i', $accepted_language, $matches
|
||||
);
|
||||
|
||||
// war die Syntax gültig?
|
||||
|
@ -93,7 +92,7 @@ function lang_getfrombrowser($allowed_languages, $default_language, $lang_variab
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function ensureDir($filepath) {
|
||||
function ensureDir(string $filepath) {
|
||||
if (!is_dir($filepath)) mkdir($filepath);
|
||||
}
|
||||
|
||||
|
@ -104,7 +103,7 @@ function ensureDir($filepath) {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function ensureJson($filepath) {
|
||||
function ensureJson(string $filepath) {
|
||||
|
||||
if (!file_exists($filepath) or filesize($filepath) < 2) {
|
||||
file_put_contents($filepath, "[]");
|
||||
|
@ -134,21 +133,21 @@ function ensureEnvironment() {
|
|||
/**
|
||||
* Function transform escapes a string for printing in TeX
|
||||
*
|
||||
* @param string $transform String to transform
|
||||
* @param string $transform String to transform.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function transform($transform) {
|
||||
function transform(string $transform):string {
|
||||
|
||||
$transform = preg_replace('#<br>#', ' ', $transform);
|
||||
$transform = preg_replace('#</br>#', ' ', $transform);
|
||||
$transform = preg_replace('#<br />#', ' ', $transform);
|
||||
$transform = preg_replace('#’#', '\'', $transform);
|
||||
$transform = preg_replace('#'.chr(11).'#', ' ', $transform);
|
||||
$transform = preg_replace('#' . chr(11) . '#', ' ', $transform);
|
||||
$transform = preg_replace('#"#', '"', $transform);
|
||||
$transform = preg_replace('#&#', '&', $transform);
|
||||
$transform = preg_replace('#•#', '•', $transform);
|
||||
$transform = preg_replace('#'.chr(9).'#', '', $transform);
|
||||
$transform = preg_replace('#' . chr(9) . '#', '', $transform);
|
||||
$transform = str_replace('&', '\\&', $transform);
|
||||
$transform = str_replace('{', '\\{', $transform);
|
||||
$transform = str_replace('}', '\\}', $transform);
|
||||
|
@ -179,7 +178,7 @@ function transform($transform) {
|
|||
$transform = preg_replace('#è#', 'è', $transform);
|
||||
|
||||
foreach (array("[", "]") as $toescape)
|
||||
$transform = str_replace ($toescape, "$".$toescape."$", $transform);
|
||||
$transform = str_replace ($toescape, "$" . $toescape . "$", $transform);
|
||||
|
||||
$transform = html_entity_decode($transform, ENT_QUOTES, "utf-8" );
|
||||
return $transform;
|
||||
|
@ -192,7 +191,7 @@ function transform($transform) {
|
|||
*
|
||||
* @return string[]
|
||||
*/
|
||||
function scanDirConts($folder) {
|
||||
function scanDirConts(string $folder) {
|
||||
return array_values(array_diff(scandir($folder), [".", "..", ".git"]));
|
||||
}
|
||||
|
||||
|
@ -206,8 +205,8 @@ function scanDirConts($folder) {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function copyFolder($from, $to) {
|
||||
mkdir ($to);
|
||||
function copyFolder(string $from, string $to) {
|
||||
mkdir($to);
|
||||
foreach (array_diff(scandir("$from"), [".", ".."]) as $file) {
|
||||
copy("$from/$file", "$to/$file");
|
||||
}
|
||||
|
@ -220,7 +219,7 @@ function copyFolder($from, $to) {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function removeFolder($folder) {
|
||||
function removeFolder(string $folder) {
|
||||
foreach (array_diff(scandir("$folder"), [".", ".."]) as $file) {
|
||||
if (is_dir("$folder/$file")) removeFolder("$folder/$file");
|
||||
else unlink("$folder/$file");
|
||||
|
@ -237,7 +236,7 @@ function removeFolder($folder) {
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function removeFolderGently($folder, $exclude) {
|
||||
function removeFolderGently(string $folder, string $exclude) {
|
||||
foreach (array_diff(scandir("$folder"), [".", ".."]) as $file) {
|
||||
if (time() - filemtime("$folder/$file") < 10 and $file != $exclude) continue;
|
||||
if (is_dir("$folder/$file")) $output = removeFolder("$folder/$file");
|
||||
|
@ -254,13 +253,13 @@ function removeFolderGently($folder, $exclude) {
|
|||
* @param string $folder Determines the folder (say, template) to use for PDF generation.
|
||||
* @param string $texFilename Name of the TeX file. Used without its ending.
|
||||
* @param string $filename Filename as it should be shown to the user.
|
||||
* @param boolean $pdfSettings Additional parameters to use \def for.
|
||||
* @param boolean $lang Language. Optional.
|
||||
* @param array $pdfSettings Additional parameters to use \def for.
|
||||
* @param string $lang Language. Optional.
|
||||
* @param boolean $debug Enables/disables debug mode. Optional.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function runPDF($folder, $texFilename, $filename, $pdfSettings, $lang = "de", $debug = false) {
|
||||
function runPDF(string $folder, string $texFilename, string $filename, array $pdfSettings, string $lang = "de", bool $debug = false) {
|
||||
|
||||
if (!is_dir("./tmp")) mkdir("./tmp");
|
||||
|
||||
|
@ -316,14 +315,14 @@ function runPDF($folder, $texFilename, $filename, $pdfSettings, $lang = "de", $d
|
|||
*
|
||||
* @param string $title Title of the page.
|
||||
* @param string $contents Page contents.
|
||||
* @param string $lang Language. Optional
|
||||
* @param string $lang Language. Optional.
|
||||
* @param array $availableLangs Page description. Optional.
|
||||
* @param string $descriptions Page description. Optional.
|
||||
* @param string $pdfLink Link to brochure. Optional.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function printHTMLPage(string $title, string $contents, string $lang = "en", array $availableLangs = ["en"], string $descriptions = "", $pdfLink = "brochure") {
|
||||
function printHTMLPage(string $title, string $contents, string $lang = "en", array $availableLangs = ["en"], string $descriptions = "", string $pdfLink = "brochure"):string {
|
||||
|
||||
$output = '<!DOCTYPE html>
|
||||
<html lang="' . $lang . '" id="' . str_replace(":", "", str_replace(" ", "", $title)) . '">
|
||||
|
@ -336,9 +335,9 @@ function printHTMLPage(string $title, string $contents, string $lang = "en", arr
|
|||
<link rel="shortcut icon" sizes="16x16 32x32" href="./media/mdlogo-32px.png" />
|
||||
<link rel="shortcut icon" sizes="64x64" href="./media/mdlogo-64px.png" /><link rel="stylesheet" type="text/css" href="css/main.css">
|
||||
|
||||
<meta name="twitter:title" content="' . $title. '" />
|
||||
<meta property="og:title" content="' . $title. '" />
|
||||
<title>' . $title. '</title>
|
||||
<meta name="twitter:title" content="' . $title . '" />
|
||||
<meta property="og:title" content="' . $title . '" />
|
||||
<title>' . $title . '</title>
|
||||
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta name="twitter:site" content="@museumdigital" />
|
||||
|
|
Reference in New Issue
Block a user