Campustream 1.0
A social network MQP for WPI
|
00001 <? 00002 include_once $GLOBALS['APPROOT'] . 'application/lib/postmark/Adapter_Interface.php'; 00003 include_once $GLOBALS['APPROOT'] . 'application/lib/postmark/Postmark.php'; 00004 00008 class email { 00009 00015 public static function send_confirmation(User_Model $user) { 00016 if (!$user->is_loaded()) { return; } 00017 00018 $subject = "Welcome to Campustream! Please confirm your email."; 00019 $body = " 00020 <h1>Welcome to Campustream!</h1> 00021 <p>Before you can use the site, you need to confirm your email address. Please visit this link:</p> 00022 <p><a href=\"http://campustream.com/confirm/do?code={$user->confirm_code}\">http://campustream.com/confirm/do?code={$user->confirm_code}</a></p> 00023 <p>Thanks! — the Campustream team</p> 00024 "; 00025 00026 self::enqueue($user, $subject, $body); 00027 } 00028 00036 public static function send_notification(User_Model $to_user, $msg, $link) { 00037 if (!$to_user->email_enabled) { 00038 return; 00039 } 00040 00041 $msg = sess::getUser()->name . " " . $msg; 00042 $msg .= "<br />"; 00043 $msg .= "You can view the notification <a href=\"http://campustream.com{$link}\">here</a>."; 00044 $msg .= "<br /><br />"; 00045 $msg .= "Thanks!<br />"; 00046 $msg .= "The Campustream Team"; 00047 00048 $msg .= "<br /><br />"; 00049 $msg .= "Note: if you do not wish to receive notification emails, you may quickly disable them <a href=\"http://dev.campustream.com/settings/profile\">here</a>."; 00050 00051 self::enqueue($to_user, "Campustream Notification", $msg); 00052 } 00053 00057 private static function enqueue($user, $subject, $body) { 00058 $r = RedisManager::connection(); 00059 00060 $data = array( 00061 'to' => $user, 00062 'subject' => $subject, 00063 'body' => $body 00064 ); 00065 00066 Logger::debug("Enqueuing email to {$user->username}"); 00067 00068 $r->rpush('queue:email', serialize($data)); 00069 } 00070 00075 public static function send(User_Model $to, $subject, $body) { 00076 00077 $message = " 00078 <html> 00079 <head><title>Campustream</title></head> 00080 <body> 00081 $body 00082 </body> 00083 </html> 00084 "; 00085 00086 Logger::email('Sent', "{$to->name} <{$to->email}> - $subject"); 00087 00088 try { 00089 Mail_Postmark::compose() 00090 ->addTo($to->email, $to->name) 00091 ->subject($subject) 00092 ->messageHtml($message) 00093 ->send(); 00094 } catch (Exception $e) { 00095 Logger::email('Error', $e->getMessage()); 00096 } 00097 } 00098 } 00099 00103 class Mail_Postmark_Adapter implements Mail_Postmark_Adapter_Interface { 00104 public static $latestLogEntry; 00105 00106 public static function getApiKey() { 00107 return "400edfd8-5598-4a39-b513-a4f31543bf8e"; 00108 } 00109 00110 public static function setupDefaults(Mail_Postmark &$mail) { 00111 $mail->from('noreply@campustream.com', 'Campustream'); 00112 } 00113 00114 public static function log($logData) { 00115 self::$latestLogEntry = $logData; 00116 } 00117 }