',
''
);
$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 <<
B
i
u
List
Item
IMG
URL
EDITOR;
}
// Function to check for errors and display them as needed.
function displayErrors($leErrors, $errorArray) {
$Errors = array(
"You forgot to put in a username!",
"Sorry, but you can't have special characters in your username.",
"That username already exists; you have to pick a new one.",
"Your username is longer than 24 characters!",
"You didn't give an email address!",
"The email you gave wasn't valid! Double-check it.",
"That email is already registered! Did you forget your password?",
"You DO need to make a password, ya know.",
"You need to confirm your password here!",
"The passwords you gave didn't match. Time to double-check.",
"It seems that username doesn't exist. Want to register?",
"That password doesn't match the username. Reset your password?",
"<1-- 13 -->Whoops! You need to give both your username and your password!"
);
$leErrors = array_intersect($leErrors, $errorArray);
foreach($leErrors as $error) {
$error = $error - 1;
echo "" . $Errors[$error] . "";
}
}
// Retrieve template from the source.
function GetTemplate($templatename) {
$filename = $_SERVER['DOCUMENT_ROOT'] . "/Resources/Templates/" . $templatename . ".php";
include("$filename");
return $template;
}
// Parse all proper content into the template.
function ParseTemplate($template, $array) {
foreach($array as $a => $b) {
$template = str_replace("{{{" . $a . "}}}", $b, $template);
}
return $template;
}
/**
* Return the path to the given template.
*/
function template(string $name): string
{
return "../app/templates/$name.php";
}
/**
* Render a template. Pass data to it - uses an output buffer to have PHP process the template instead of using
* a template engine. If you're including partials in the page, call render('partial', $data), as $data will still
* be available.
*/
function render(string $baseView, array $data = []): string
{
ob_start();
extract($data);
include template($baseView);
return ob_get_clean();
}
?>