コード例 #1
0
ファイル: notify_class.php プロジェクト: armpit/e107
 /**
  * Send an email notification following an event.
  *
  * The email is sent via a common interface, which will send immediately for small numbers of recipients, and queue for larger.
  * 
  * @param string $id - identifies event actions
  * @param string $subject - subject for email
  * @param string $message - email message body
  * @return void
  *
  *	@todo handle 'everyone except' clauses (email address filter done)
  *	@todo set up pref to not notify originator of event which caused notify (see $blockOriginator)
  */
 function send($id, $subject, $message, $media = array())
 {
     $tp = e107::getParser();
     $sql = e107::getDb();
     $subject = $tp->toEmail($subject);
     $message = $tp->replaceConstants($message, "full");
     //	$message = $tp->toEmail($message);
     $emailFilter = '';
     $notifyTarget = $this->notify_prefs['event'][$id]['class'];
     if ($notifyTarget == '-email') {
         $emailFilter = $this->notify_prefs['event'][$id]['email'];
     }
     $blockOriginator = FALSE;
     // TODO: set this using a pref
     $recipients = array();
     if ($notifyTarget == 'email') {
         if (!$blockOriginator || $this->notify_prefs['event'][$id]['email'] != USEREMAIL) {
             $recipients[] = array('mail_recipient_email' => $this->notify_prefs['event'][$id]['email'], 'mail_target_info' => array('SUBJECT' => $subject, 'DATE_SHORT' => $tp->toDate(time(), 'short'), 'DATE_LONG' => $tp->toDate(time(), 'long')));
         }
     } elseif (is_numeric($notifyTarget)) {
         switch ($notifyTarget) {
             case e_UC_MAINADMIN:
                 $qry = "`user_admin` = 1 AND `user_perms` = '0' AND `user_ban` = 0";
                 break;
             case e_UC_ADMIN:
                 $qry = "`user_admin` = 1 AND `user_ban` = 0";
                 break;
             case e_UC_MEMBER:
                 $qry = "`user_ban` = 0";
                 break;
             default:
                 $qry = "user_ban = 0 AND user_class REGEXP '(^|,)(" . $notifyTarget . ")(,|\$)'";
                 break;
         }
         $qry = 'SELECT user_id,user_name,user_email,user_join,user_lastvisit FROM `#user` WHERE ' . $qry;
         if ($blockOriginator) {
             $qry .= ' AND `user_id` != ' . USERID;
         }
         if (false !== ($count = $sql->gen($qry))) {
             // Now add email addresses to the list
             while ($row = $sql->fetch(MYSQL_ASSOC)) {
                 if ($row['user_email'] != $emailFilter) {
                     $unsubscribe = array('date' => $row['user_join'], 'email' => $row['user_email'], 'id' => $row['user_id'], 'plugin' => 'user', 'userclass' => $notifyTarget);
                     $urlQuery = http_build_query($unsubscribe, null, '&');
                     $exclude = array(e_UC_MEMBER, e_UC_ADMIN, e_UC_MAINADMIN);
                     // no unsubscribing from these classes.
                     $unsubUrl = SITEURL . "unsubscribe.php?id=" . base64_encode($urlQuery);
                     $unsubMessage = "This message was sent to " . $row['user_email'] . ". If you don't want to receive these emails in the future, please <a href='" . $unsubUrl . "'>unsubscribe</a>.";
                     $recipients[] = array('mail_recipient_id' => $row['user_id'], 'mail_recipient_name' => $row['user_name'], 'mail_recipient_email' => $row['user_email'], 'mail_target_info' => array('USERID' => $row['user_id'], 'DISPLAYNAME' => $row['user_name'], 'SUBJECT' => $subject, 'USERNAME' => $row['user_name'], 'USERLASTVISIT' => $row['user_lastvisit'], 'UNSUBSCRIBE' => !in_array($notifyTarget, $exclude) ? $unsubUrl : '', 'UNSUBSCRIBE_MESSAGE' => !in_array($notifyTarget, $exclude) ? $unsubMessage : '', 'USERCLASS' => $notifyTarget, 'DATE_SHORT' => $tp->toDate(time(), 'short'), 'DATE_LONG' => $tp->toDate(time(), 'long')));
                 }
             }
         }
     }
     if (E107_DEBUG_LEVEL > 0) {
         $data = array('id' => $id, 'subject' => $subject, 'recipients' => $recipients, 'prefs' => $this->notify_prefs['event'][$id], 'message' => $message);
         e107::getMessage()->addDebug("<b>Mailing is simulated only while in DEBUG mode.</b>");
         e107::getMessage()->addDebug(print_a($data, true));
         e107::getLog()->add('Notify Debug', $data, E_LOG_INFORMATIVE, "NOTIFY_DBG");
         return;
     }
     $siteadminemail = e107::getPref('siteadminemail');
     $siteadmin = e107::getPref('siteadmin');
     if (count($recipients)) {
         require_once e_HANDLER . 'mail_manager_class.php';
         $mailer = new e107MailManager();
         // Create the mail body
         $mailData = array('mail_total_count' => count($recipients), 'mail_content_status' => MAIL_STATUS_TEMP, 'mail_create_app' => 'core', 'mail_title' => 'NOTIFY', 'mail_subject' => $subject, 'mail_sender_email' => e107::getPref('replyto_email', $siteadminemail), 'mail_sender_name' => e107::getPref('replyto_name', $siteadmin), 'mail_notify_complete' => 0, 'mail_body' => $message, 'template' => 'notify', 'mail_send_style' => 'notify');
         if (!empty($media) && is_array($media)) {
             foreach ($media as $k => $v) {
                 $mailData['mail_media'][$k] = array('path' => $v);
             }
         }
         $result = $mailer->sendEmails('notify', $mailData, $recipients);
         e107::getLog()->e_log_event(10, -1, 'NOTIFY', $subject, $message, FALSE, LOG_TO_ROLLING);
     } else {
         $data = array('qry' => $qry, 'error' => 'No recipients');
         e107::getLog()->add('Notify Debug', $data, E_LOG_WARNING_, "NOTIFY_DBG");
     }
 }
コード例 #2
0
ファイル: forum_class.php プロジェクト: KonzolozZ/e107
 /**
  * Send an email to users who are tracking the topic/thread.
  * @param $post
  * @return bool
  */
 function trackEmail($post)
 {
     $sql = e107::getDb();
     $tp = e107::getParser();
     $trackingPref = $this->prefs->get('track');
     if (empty($trackingPref)) {
         return false;
     }
     $data = $sql->retrieve('SELECT t.*, u.user_id, u.user_name, u.user_email, u.user_lastvisit FROM `#forum_track` AS t LEFT JOIN `#user` AS u ON t.track_userid = u.user_id WHERE t.track_thread=' . intval($post['post_thread']), true);
     if (empty($data)) {
         return false;
     }
     $threadData = $this->threadGet($post['post_thread']);
     $recipients = array();
     $thread_name = $tp->toText($threadData['thread_name']);
     //	$thread_name = str_replace('&quot;', '"', $thread_name);		// This not picked up by toText();
     $datestamp = $tp->toDate($post['post_datestamp']);
     $email_post = $tp->toHTML($post['post_entry'], true);
     //	$mail_link = "<a href='".SITEURL.$PLUGINS_DIRECTORY."forum/forum_viewtopic.php?".$thread_parent.".last'>".SITEURL.$PLUGINS_DIRECTORY."forum/forum_viewtopic.php?".$thread_parent.".last</a>";
     $query = array('last' => 1);
     $mail_link = e107::url('forum', 'topic', $threadData, array('mode' => 'full', 'query' => $query));
     $subject = $this->prefs->get('eprefix') . " " . $thread_name;
     foreach ($data as $row) {
         $recipients[] = array('mail_recipient_id' => $row['user_id'], 'mail_recipient_name' => $row['user_name'], 'mail_recipient_email' => $row['user_email'], 'mail_target_info' => array('USERID' => $row['user_id'], 'DISPLAYNAME' => $row['user_name'], 'SUBJECT' => $subject, 'USERNAME' => $row['user_name'], 'USERLASTVISIT' => $row['user_lastvisit'], 'DATE_SHORT' => $tp->toDate(time(), 'short'), 'DATE_LONG' => $tp->toDate(time(), 'long')));
     }
     require_once e_HANDLER . 'mail_manager_class.php';
     $mailer = new e107MailManager();
     $vars = array('x' => USERNAME, 'y' => $thread_name, 'z' => $datestamp);
     $message = "[html]" . $tp->lanVars(LAN_FORUM_8001, $vars, true) . "<br /><br /><blockquote>" . $tp->toEmail($email_post, false) . "</blockquote><br />" . LAN_FORUM_8002 . "<br /><a href='" . $mail_link . "'>" . $mail_link . "</a>[/html]";
     // Create the mail body
     $mailData = array('mail_total_count' => count($recipients), 'mail_content_status' => MAIL_STATUS_TEMP, 'mail_create_app' => 'forum', 'mail_title' => 'FORUM TRACKING', 'mail_subject' => $subject, 'mail_sender_email' => e107::getPref('replyto_email', SITEADMINEMAIL), 'mail_sender_name' => e107::getPref('replyto_name', SITEADMIN), 'mail_notify_complete' => 0, 'mail_body' => $message, 'template' => 'default', 'mail_send_style' => 'default');
     /*	if(!empty($media) && is_array($media))
     			{
     				foreach($media as $k=>$v)
     				{
     					$mailData['mail_media'][$k] = array('path'=>$v);
     				}
     			}*/
     $opts = array();
     // array('mail_force_queue'=>1);
     $mailer->sendEmails('default', $mailData, $recipients, $opts);
 }