<?php require_once PATH::lib() . '/meekrodb.2.3.class.php'; //Even better version of class.DB.php, with OO'd database management. function db_error_handler($params) { $out = 'DB ERROR: '; if (strpos($params['error'], 'Unable to connect to MySQL server!')) { $params['error'] .= " (Did you accidentally upload CONFIG.local.php?)"; } if (isset($params['query'])) { $out .= "QUERY: " . $params['query'] . '<br />'; } if (isset($params['error'])) { $out .= "ERROR: " . $params['error'] . '<br />'; } trigger_error($out, E_USER_ERROR); die; } class DBExt { //A few more features to add to MeekroDB. public static function parseWhereClause($where, $args) { //Better whereclause creation, to be used in placeholding %l. (may not necessarily be a whereclause) //Does not deal with replacement params. if (!is_array($args)) { $args = array(); } if (is_object($where) && get_class($where) == 'WhereClause') { //Well, it's already a WhereClause.
function send_email($bcc_list, $subject, $bb_body, $reply_to = NULL, $prefix = NULL, $footer = NULL, $headers = NULL) { global $EMAIL_ADDRESS, $EMAIL_USERNAME, $EMAIL_PASSWORD, $SMTP_SERVER, $SMTP_SERVER_PORT, $SMTP_SERVER_PROTOCOL, $LMT_EMAIL; require_once PATH::lib() . "/swiftmailer/swift_required.php"; //Instead of using parameter default values, so we can pass NULL. And it's more readable. if (count($bcc_list) == 0) { return true; } if (is_null($reply_to)) { $reply_to = array($EMAIL_ADDRESS => 'LHS Math Club Mailbot'); } if (is_null($prefix)) { $prefix = '[LHS Math Club]'; } if (is_null($footer)) { $footer = "LHS Math Club\n[url]" . get_site_url() . "[/url]\nTo stop receiving LHSMATH emails, contact [email]webmaster@lhsmath.org[/email]."; } if (is_null($headers)) { $headers = array(); } if (is_string($bcc_list)) { $bcc_list = array($bcc_list); } if (!is_array($bcc_list) || !is_string($subject) || !is_string($bb_body) || !is_array($reply_to) && !is_string($reply_to) || !is_string($prefix) || !is_string($footer) || !is_array($headers)) { return 'Invalid email parameters.'; } if (($error_msg = val_email_msg($subject, $bb_body)) !== true) { return $error_msg; } if ($footer != "") { $bb_body .= "\n\n\n---\n{$footer}\n"; } //Attach footer. $html = BBCode($bb_body); //BBCode it. $subject = preg_replace("/[^\\S ]/ui", '', strip_tags($prefix . ' ' . $subject)); //"remove everything that's not [non-whitespace or space]" //preg_replace("/[^[:alnum][:space]]/ui", '', $string);? //Ok everything seems to be working, let's go ahead Swift_Preferences::getInstance()->setCacheType('array'); //Prevents a ton of warnings about SwiftMail's DiskKeyCache, thus actually speeding things up considerably. //Connect to the SMTP server $transport = Swift_SmtpTransport::newInstance($SMTP_SERVER, $SMTP_SERVER_PORT, $SMTP_SERVER_PROTOCOL)->setUsername($EMAIL_USERNAME)->setPassword($EMAIL_PASSWORD); //Make a Mailer that will send through that transport (limiting to 50/send) $mailer = Swift_Mailer::newInstance($transport); //$mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(50, 1));//Max 50 emails per send, 1 sec delay between sends try { //Mush all info into the Mailer $message = Swift_Message::newInstance($subject)->setFrom(array($EMAIL_ADDRESS => 'LHS Math Club Mailbot'))->setBcc($bcc_list)->setContentType("text/html")->setBody($html)->setReplyTo($reply_to); foreach ($headers as $field => $value) { //Add custom headers, such as listserv stuff. $message->getHeaders()->addTextHeader($field, $value); } //Send the message if (!$mailer->send($message)) { LOG::fatal('Error sending email'); } } catch (Exception $e) { LOG::fatal('Email exception: ' . $e->getMessage()); } return true; }
* * 'E': Email verification pending * * '+': Super-Admin (LHSMATH account) * * 'L': Alumnus * * 'X': Logged-out user * * 'T': Temporary user (should not be able to log in) */ require_once PATH::lib() . '/functions.db.php'; DB::$host = $DB_SERVER; //defaults to localhost if omitted DB::$user = $DB_USERNAME; DB::$password = $DB_PASSWORD; DB::$dbName = $DB_DATABASE; DB::$error_handler = 'db_error_handler'; require_once PATH::lib() . '/functions.template.php'; require_once PATH::lib() . '/functions.logs.php'; require_once PATH::lib() . '/recaptchalib-1.11.php'; /* * validate_recaptcha() * Returns true if the recaptcha was entered correctly, else else an error. */ function validate_recaptcha() { global $RECAPTCHA_PRIVATE_KEY; $recaptcha_response = recaptcha_check_answer($RECAPTCHA_PRIVATE_KEY, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']); if (!$recaptcha_response->is_valid) { return 'You entered the reCaptcha incorrectly'; } return true; } /* * recaptcha_get_html_f()
$included_files = get_included_files(); foreach ($included_files as $f) { if (strpos($f, 'meekro')) { $meekro_file = $f; break; } } preg_match('@meekrodb\\.([0-9\\.]+)\\.class.php$@i', $meekro_file, $matches); if (!empty($matches)) { $meekro_version = $matches[1]; } else { $meekro_version = '(ERROR)'; } //--SwiftMail try { require_once PATH::lib() . "/swiftmailer/classes/Swift.php"; $swift_version = Swift::VERSION; } catch (Exception $e) { $swift_version = '(ERROR)'; } //Output ?> <h1>Admin Dashboard</h1> <style>#info-table td{width:33%;table-layout:fixed;word-wrap:break-word;}li{font-size:0.8em;}</style> <table cellspacing="10px" id="info-table"> <tr> <td> <h4>Library/Software Versions</h4> <ul>
<?php /* * .lib/lmt-functions.php * LHS Math Club Website */ // include regular functions and all of its stuff require_once __DIR__ . '/functions.php'; //class LMT_DB extends DB{}; LMT_DB::useDB('lmt'); DB::useDB('lmt'); // except use the LMT db // include scoring require_once PATH::lib() . '/lmt-scoring.php'; // // DEFAULT ACTIONS: // // Replace the custom error handler with this one function lmt_custom_errors($errno, $errstr, $errfile, $errline) { $rh = fopen(PATH::errfile(), 'a+'); fwrite($rh, date(DATE_RFC822) . ' Error [' . $errno . '] on line ' . $errline . ' in ' . $errfile . ': ' . $errstr . "\n"); fclose($rh); global $miniature_page; if (isset($miniature_page)) { $miniature_page = '?Mini'; } if (headers_sent()) { echo '<meta http-equiv="refresh" content="0;url=' . URL::root() . '/LMT/Error' . $miniature_page . '">'; } else { if (isset($_GET['xsrf_token'])) { header('Location: ' . URL::root() . '/LMT/Error' . $miniature_page);