77 lines
2.3 KiB
PHP
77 lines
2.3 KiB
PHP
<?php #lib/main.php
|
|
|
|
/********************************************************************************
|
|
* Content: Most important functions *
|
|
* Author: Nils Otterpohl *
|
|
* Last modification: 24.06.2019 *
|
|
* Version: alpha (incomplete, tested, commented) *
|
|
********************************************************************************/
|
|
|
|
#### INCOMPLETE! TBD: ##############
|
|
# Mehr Datums- und Zeitformate #
|
|
####################################
|
|
|
|
function SS($param)
|
|
{ //Prevents injections from strings
|
|
global $mysqli;
|
|
return $mysqli->escape_string($param);
|
|
}
|
|
|
|
function SI($param)
|
|
{ //Prevents injections from integers
|
|
return intval($param);
|
|
}
|
|
|
|
function myDate($time = 0)
|
|
{ //Formats timestamp to standard date format
|
|
if ($time==0) $time = time();
|
|
return date(FORMATDATE, $time);
|
|
}
|
|
|
|
function myTime($time = 0)
|
|
{ //Formats timestamp to standard time format
|
|
if ($time==0) $time = time();
|
|
return date(FORMATTIME, $time);
|
|
}
|
|
|
|
function myDateTime($time = 0)
|
|
{ //Formats timestamp to standard date and time format
|
|
return myDate($time)." ".myTime($time);
|
|
}
|
|
function fmtTime($format, $time = 0)
|
|
{ //Formats timestamp to a preset value
|
|
global $times;
|
|
return (isset($times[$format]) ? date($times[$format], $time) : myDateTime);
|
|
}
|
|
|
|
function addError($ident, $add)
|
|
{ //Lists an error
|
|
global $err;
|
|
if (isset($err[$ident])) $err["out"][] = $err[$ident].$add;
|
|
else $err["out"][] = $err["unknown"].$ident.$add;
|
|
}
|
|
|
|
function addLibrary($lib, $notify=true)
|
|
{ //Includes a php-library
|
|
global $err;
|
|
if (!(substr($lib,0,4)=="lib/")) $lib = "lib/".$lib;
|
|
if (!(substr($lib,-4,4)==".php")) $lib.= ".php";
|
|
if (file_exists($lib)) include_once($lib);
|
|
elseif ($notify) addError("noLib", $lib);
|
|
}
|
|
|
|
function addStyle($css, $notify=true)
|
|
{ //adds a stylesheet to $output-array
|
|
global $output, $err;
|
|
if (file_exists($css) && ! in_array($css,$output["css"])) $output["css"][] = $css;
|
|
elseif ($notify) addError("noCss", $css);
|
|
}
|
|
|
|
function addJscript($js, $notify=true)
|
|
{ //adds a javascript to $output-array
|
|
global $output, $err;
|
|
if (file_exists($js) && ! in_array($js,$output["js"])) $output["js"][] = $js;
|
|
elseif ($notify) addError("noJs", $js);
|
|
}
|
|
|
|
?>
|