SetGlobalVariables(); NewTemplater::SetGlobalVariable("logout-key", $_SESSION['logout_key']); } NewTemplater::RegisterVariableHook("errors", "get_errors"); NewTemplater::RegisterVariableHook("notices", "get_notices"); function get_errors($fetch) { if(isset($_SESSION['errors'])) { $errors = $_SESSION['errors']; if($fetch === true) { /* We only want to clear out errors if a call to * actually retrieve the errors was made, not just * something like an isempty. */ $_SESSION['errors'] = array(); } return $errors; } else { return array(); } } function get_notices($fetch) { if(isset($_SESSION['notices'])) { $notices = $_SESSION['notices']; if($fetch === true) { $_SESSION['notices'] = array(); } return $notices; } else { return array(); } } function flash_error($message) { $_SESSION['errors'][] = $message; } function flash_notice($message) { $_SESSION['notices'][] = $message; } if($cphp_config->debugmode === false) { $smtp = Swift_SmtpTransport::newInstance($cphp_config->smtp->host, $cphp_config->smtp->port) ->setUsername($cphp_config->smtp->username)->setPassword($cphp_config->smtp->password); $mail_transport = Swift_Mailer::newInstance($smtp); } function send_mail($to, $subject, $text, $html) { global $mail_transport, $cphp_config; $sMessage = Swift_Message::newInstance(); $sMessage->setSubject($subject); $sMessage->setTo($to); $from = array(); $from[$cphp_config->smtp->from] = $cphp_config->smtp->from_name; $sMessage->setFrom($from); $sMessage->setBody($text); $sMessage->addPart($html, "text/html"); if($cphp_config->debugmode) { echo("
From: {$cphp_config->smtp->from}
To: {$to}
Subject: {$subject}

{$text}

{$html}
"); } else { $mail_transport->send($sMessage); } } function generate_urlname($input, $iteration) { $uUrlName = preg_replace("/[ =_+]/", "-", $input); $sUrlName = preg_replace("/[^a-zA-Z0-9-]/", "", $uUrlName); $sUrlName = strtolower($sUrlName); if($iteration > 0) { $sUrlName .= "-" . $iteration; } return $sUrlName; }