0) {
return true;
} else {
return false;
}
}
// ---------------------------------------------------------------------------- //
// ---------------------------------------------------------------------------- //
/// Pretty functions - used to makes things cleaner and look nicer.
// Change the MySQL date format (YYYY-MM-DD) into something friendlier.
function betterDate($uglyDate) {
try {
$date = new DateTime($uglyDate);
return $date->format("jS M Y, g:i A");
} catch(PDOException $ex) {
echo $ex->getMessage();
}
}
function nicerDate($uglyDate) {
try {
$date = new DateTime($uglyDate);
return $date->format("jS M Y - g:i A");
} catch(PDOException $ex) {
echo $ex->getMessage();
}
}
function getAge($date) {
$birthDay = new DateTime($date);
$today = new DateTime();
$age = $today->diff($birthDay);
return $age->y;
}
// ---------------------------------------------------------------------------- //
// ---------------------------------------------------------------------------- //
/// Aegis functions - cleans data and parses it, as well as hashes and checks other stuff for protection.
// This function serves to prevent tags within HTML getting into things. It's basically a symbol cleaner.
// Kudos to Atli from Dream.In.Code for showing me htmlentities()!
function magicClean($text) {
return htmlentities($text, ENT_QUOTES, "UTF-8");
}
// Hash a password thousands of times using a random salt.
function hashPass($password, $salt, $username = "failure") {
for($round = 0; $round < 124363; $round++) {
$HashedPass = hash("sha512", $username . $salt . $password);
}
return $HashedPass;
}
function generateSalt(int $length = 15): string
{
return bin2hex(random_bytes($length));
}
// Validate the email address inputted!
function checkEmail($email): bool
{
return filter_var($email, FILTER_VALIDATE_EMAIL) ? true : false;
}
// Simple BBCode parse function.
function BBCode($data) {
$input = array(
'/(\r?\n)/',
'/(\r?\n){2,}/',
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[img (.*?)\](.*?)\[\/img\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[url\=(.*?)\](.*?)\[\/url\]/is',
'/\[list\]/is',
'/\[\/list\]/is',
'/\[item\](.*?)\[\/item\]/is',
'/ \:\)/is',
'/ \-\.\-/is',
'/ \:bomb\:/is',
'/ \:D/is',
'/ \:C/is',
'/ \-\_\-/is',
'/ o\_\-/is',
'/ \-\_\o/is',
'/ o\.\-/is',
'/ D\:/is',
'/\[code\](.*?)\[\/code\]/is',
'/ \:P/is'
);
$output = array(
'
',
'
',
'$1',
'$1',
'$1',
'',
'$1',
'$2',
'
CODE', '' ); $rtrn = preg_replace($input, $output, $data); return $rtrn; } // ---------------------------------------------------------------------------- // // ---------------------------------------------------------------------------- // /// Email functions - used to send emails for various reasons // Send an email to the specified recipient. function sendMail($mailSubject, $mailContent, $mailDestinee, $templatename) { $mailHeaders = 'MIME-Version: 1.0' . "\r\n"; $mailHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $mailHeaders .= 'From: theguys@localhost:8888' . "\r\n"; $filename = $_SERVER['DOCUMENT_ROOT'] . "/Resources/Templates/emails/" . $templatename . ".php"; include("$filename"); foreach($mailContent as $a => $b) { $template = str_replace("{{{" . $a . "}}}", $b, $template); } mail($mailDestinee, $mailSubject, $template, $mailHeaders); } // ---------------------------------------------------------------------------- // // ---------------------------------------------------------------------------- // /// Generator functions - used to create things that would take too many lines to constantly repeat // Create the new and improved text editor. function textEditor($Width, $Height, $Name, $Default) { echo <<$1