Пример #1
0
/** \brief send the email notifications dealing with the forum changes to
 * \brief outbound address + admin notification addresses / forum admin email + watching users addresses
 * \param $event = 'forum_post_topic' or 'forum_post_thread'
 * \param $object = forumId watch if forum_post_topic or topicId watch if forum_post_thread
 * \param $threadId = topicId if forum_post_thread
 * \param $title of the message
 * \param $topicName name of the parent topic
 */
function sendForumEmailNotification($event, $object, $forum_info, $title, $data, $author, $topicName, $messageId = '', $inReplyTo = '', $threadId, $parentId = '')
{
    global $tikilib, $feature_user_watches, $smarty, $userlib, $sender_email;
    // Per-forum From address overrides global default.
    if ($forum_info['outbound_from']) {
        $my_sender = '"' . "{$author}" . '" <' . $forum_info['outbound_from'] . '>';
    } else {
        $my_sender = $sender_email;
    }
    //outbound email ->  will be sent in utf8 - from sender_email
    if ($forum_info['outbound_address']) {
        include_once 'lib/webmail/tikimaillib.php';
        $mail = new TikiMail();
        $mail->setSubject($title);
        $foo = parse_url($_SERVER["REQUEST_URI"]);
        $machine = $tikilib->httpPrefix() . dirname($foo["path"]);
        $reply_link = "\n\n----\n\nReply Link: <" . $machine . "tiki-view_forum_thread.php?forumId=" . $forum_info['forumId'] . "&comments_reply_threadId={$object}&comments_parentId={$threadId}&post_reply=1#form>\n";
        if (array_key_exists('outbound_mails_reply_link', $forum_info) && $forum_info['outbound_mails_reply_link']) {
            $mail->setText($title . "\n" . $data . $reply_link);
        } else {
            $mail->setText($title . "\n" . $data);
        }
        $mail->setHeader("Reply-To", $my_sender);
        $mail->setHeader("From", $my_sender);
        $mail->setSubject($topicName);
        if ($inReplyTo) {
            $mail->setHeader("In-Reply-To", "<" . $inReplyTo . ">");
        }
        global $commentslib;
        $attachments = $commentslib->get_thread_attachments($object, 0);
        if (count($attachments) > 0) {
            foreach ($attachments as $att) {
                $att_data = $commentslib->get_thread_attachment($att['attId']);
                $file = $mail->getFile($att_data['dir'] . $att_data['path']);
                $mail->addAttachment($file, $att_data['filename'], $att_data['filetype']);
            }
        }
        $mail->buildMessage();
        // Message-ID is set below buildMessage because otherwise lib/webmail/htmlMimeMail.php will over-write it.
        $mail->setHeader("Message-ID", "<" . $messageId . ">");
        $mail->send(array($forum_info['outbound_address']));
    }
    $nots = array();
    $defaultLanguage = $tikilib->get_preference("language", "en");
    // Users watching this forum or this post
    if ($feature_user_watches == 'y') {
        $nots = $tikilib->get_event_watches($event, $object);
        for ($i = count($nots) - 1; $i >= 0; --$i) {
            $nots[$i]['language'] = $tikilib->get_user_preference($nots[$i]['user'], "language", $defaultLanguage);
        }
    }
    // Special forward address
    //TODO: merge or use the admin notification feature
    if ($forum_info["useMail"] == 'y') {
        $not['email'] = $forum_info['mail'];
        if ($not['user'] = $userlib->get_user_by_email($forum_info['mail'])) {
            $not['language'] = $tikilib->get_user_preference($not['user'], "language", $defaultLanguage);
        } else {
            $not['language'] = $defaultLanguage;
        }
        $nots[] = $not;
    }
    if (count($nots)) {
        include_once 'lib/webmail/tikimaillib.php';
        $mail = new TikiMail();
        $smarty->assign('mail_forum', $forum_info["name"]);
        $smarty->assign('mail_title', $title);
        $smarty->assign('mail_date', date("U"));
        $smarty->assign('mail_message', $data);
        $smarty->assign('mail_author', $author);
        $foo = parse_url($_SERVER["REQUEST_URI"]);
        $machine = $tikilib->httpPrefix() . dirname($foo["path"]);
        $machine = preg_replace("!/\$!", "", $machine);
        // just incase
        $smarty->assign('mail_machine', $machine);
        $smarty->assign('forumId', $forum_info["forumId"]);
        if ($event == "forum_post_topic") {
            $smarty->assign('new_topic', 'y');
            $smarty->assign('topicId', $threadId);
        } else {
            $smarty->assign('topicId', $object);
        }
        $smarty->assign('mail_topic', $topicName);
        foreach ($nots as $not) {
            $mail->setUser($not['user']);
            $mail_data = $smarty->fetchLang($not['language'], "mail/notification_subject.tpl");
            $mail->setSubject($mail_data);
            $mail_data = $smarty->fetchLang($not['language'], "mail/forum_post_notification.tpl");
            $mail->setText($mail_data);
            $mail->buildMessage();
            $mail->send(array($not['email']));
        }
    }
}
Пример #2
0
 $smarty->assign('sent', 'n');
 $smarty->assign('attaching', 'n');
 if (isset($_REQUEST["send"])) {
     $mail = new TikiMail($user);
     $email = $userlib->get_user_email($user);
     $mail->setFrom($email);
     if (!empty($_REQUEST["cc"])) {
         $mail->setCc($_REQUEST["cc"]);
     }
     if (!empty($_REQUEST["bcc"])) {
         $mail->setBcc($_REQUEST["bcc"]);
     }
     $mail->setSubject($_REQUEST["subject"]);
     if ($_REQUEST["attach1"]) {
         check_ticket('webmail');
         $a1 = $mail->getFile('temp/mail_attachs/' . $_REQUEST["attach1file"]);
         $mail->addAttachment($a1, $_REQUEST["attach1"], $_REQUEST["attach1type"]);
         @unlink('temp/mail_attachs/' . $_REQUEST["attach1file"]);
     }
     if ($_REQUEST["attach2"]) {
         check_ticket('webmail');
         $a2 = $mail->getFile('temp/mail_attachs/' . $_REQUEST["attach2file"]);
         $mail->addAttachment($a2, $_REQUEST["attach2"], $_REQUEST["attach2type"]);
         @unlink('temp/mail_attachs/' . $_REQUEST["attach2file"]);
     }
     if ($_REQUEST["attach3"]) {
         check_ticket('webmail');
         $a3 = $mail->getFile('temp/mail_attachs/' . $_REQUEST["attach3file"]);
         $mail->addAttachment($a3, $_REQUEST["attach3"], $_REQUEST["attach3type"]);
         @unlink('temp/mail_attachs/' . $_REQUEST["attach3file"]);
     }
Пример #3
0
/** \brief send the email notifications dealing with the forum changes to
 * \brief outbound address + admin notification addresses / forum admin email + watching users addresses
 * \param $event = 'forum_post_topic' or 'forum_post_thread'
 * \param $object = forumId watch if forum_post_topic or topicId watch if forum_post_thread
 * \param $threadId = topicId if forum_post_thread
 * \param $title of the message
 * \param $topicName name of the parent topic
 */
function sendForumEmailNotification($event, $object, $forum_info, $title, $data, $author, $topicName, $messageId = '', $inReplyTo = '', $threadId, $parentId, $contributions = '', $postId = '')
{
    global $tikilib, $prefs, $smarty, $userlib;
    // Per-forum From address overrides global default.
    if ($forum_info['outbound_from']) {
        $author = $userlib->clean_user($author);
        $my_sender = '"' . "{$author}" . '" <' . $forum_info['outbound_from'] . '>';
    } else {
        $my_sender = $prefs['sender_email'];
    }
    //outbound email ->  will be sent in utf8 - from sender_email
    if ($forum_info['outbound_address']) {
        include_once 'lib/webmail/tikimaillib.php';
        $mail = new TikiMail();
        $mail->setSubject($title);
        if (!empty($forum_info['outbound_mails_reply_link']) && $forum_info['outbound_mails_reply_link'] == 'y') {
            $foo = parse_url($_SERVER["REQUEST_URI"]);
            $machine = $tikilib->httpPrefix(true) . dirname($foo["path"]);
            if ($event == 'forum_post_topic') {
                $reply_link = "{$machine}/tiki-view_forum_thread.php?forumId=" . $forum_info['forumId'] . "&comments_parentId={$threadId}#form";
            } else {
                $reply_link = "{$machine}/tiki-view_forum_thread.php?forumId=" . $forum_info['forumId'] . "&comments_reply_threadId={$object}&comments_parentId={$threadId}&post_reply=1#form";
            }
        } else {
            $reply_link = '';
        }
        $smarty->assign('title', $title);
        $smarty->assign('data', $data);
        $smarty->assign('reply_link', $reply_link);
        $smarty->assign('author', $author);
        $mail_data = $smarty->fetch("mail/forum_outbound.tpl");
        $mail->setText($mail_data);
        $mail->setReplyTo($my_sender);
        $mail->setFrom($my_sender);
        $mail->setSubject($topicName);
        if ($inReplyTo) {
            $mail->setHeader("In-Reply-To", "<" . $inReplyTo . ">");
        }
        global $commentslib;
        $attachments = $commentslib->get_thread_attachments($event == 'forum_post_topic' ? $threadId : $object, 0);
        if (count($attachments) > 0) {
            foreach ($attachments as $att) {
                $att_data = $commentslib->get_thread_attachment($att['attId']);
                if ($att_data['dir'] . $att_data['path'] == "") {
                    // no path to file on disk
                    $file = $att_data['data'];
                    // read file from database
                } else {
                    $file = $mail->getFile($att_data['dir'] . $att_data['path']);
                    // read file from disk
                }
                $mail->addAttachment($file, $att_data['filename'], $att_data['filetype']);
            }
        }
        // Message-ID is set below buildMessage because otherwise lib/webmail/htmlMimeMail.php will over-write it.
        $mail->setHeader("Message-ID", "<" . $messageId . ">");
        $mail->send(array($forum_info['outbound_address']));
    }
    $nots = array();
    $defaultLanguage = $prefs['site_language'];
    // Users watching this forum or this post
    if ($prefs['feature_user_watches'] == 'y' || $prefs['feature_group_watches'] == 'y') {
        $nots_raw = $tikilib->get_event_watches($event, $event == 'forum_post_topic' ? $forum_info['forumId'] : $threadId, $forum_info);
        $nots = array();
        $users = array();
        foreach ($nots_raw as $n) {
            if ($n['user'] != $author && !in_array($n['user'], $users)) {
                // make sure user receive only one notification even if he is monitoring both the topic and thread
                $n['language'] = $tikilib->get_user_preference($n['user'], "language", $defaultLanguage);
                $nots[] = $n;
                $users[] = $n['user'];
            }
        }
    }
    // Special forward address
    //TODO: merge or use the admin notification feature
    if ($forum_info["useMail"] == 'y') {
        $not['email'] = $forum_info['mail'];
        if ($not['user'] = $userlib->get_user_by_email($forum_info['mail'])) {
            $not['language'] = $tikilib->get_user_preference($not['user'], "language", $defaultLanguage);
        } else {
            $not['language'] = $defaultLanguage;
        }
        $nots[] = $not;
    }
    if ($prefs['feature_user_watches'] == 'y' && $prefs['feature_daily_report_watches'] == 'y') {
        $reportsManager = Reports_Factory::build('Reports_Manager');
        $reportsManager->addToCache($nots, array("event" => $event, "forumId" => $forum_info['forumId'], "forumName" => $forum_info['name'], "topicId" => $threadId, "threadId" => $postId, "threadName" => $topicName, "user" => $author));
    }
    if (count($nots)) {
        include_once 'lib/webmail/tikimaillib.php';
        $smarty->assign('mail_forum', $forum_info["name"]);
        $smarty->assign('mail_title', $title);
        $smarty->assign('mail_date', $tikilib->now);
        $smarty->assign('mail_message', $data);
        $smarty->assign('mail_author', $author);
        if ($prefs['feature_contribution'] == 'y' && !empty($contributions)) {
            global $contributionlib;
            include_once 'lib/contribution/contributionlib.php';
            $smarty->assign('mail_contributions', $contributionlib->print_contributions($contributions));
        }
        $foo = parse_url($_SERVER["REQUEST_URI"]);
        $machine = $tikilib->httpPrefix(true) . dirname($foo["path"]);
        $machine = preg_replace("!/\$!", "", $machine);
        // just incase
        $smarty->assign('mail_machine', $machine);
        $smarty->assign('forumId', $forum_info["forumId"]);
        if ($event == "forum_post_topic") {
            $smarty->assign('new_topic', 'y');
        } else {
            $smarty->assign('threadId', $object);
        }
        $smarty->assign('topicId', $threadId);
        $smarty->assign('mail_topic', $topicName);
        foreach ($nots as $not) {
            $mail = new TikiMail();
            $mail->setUser($not['user']);
            $mail_data = $smarty->fetchLang($not['language'], "mail/user_watch_forum_subject.tpl");
            $mail->setSubject($mail_data);
            $mail_data = $smarty->fetchLang($not['language'], "mail/forum_post_notification.tpl");
            $mail->setText($mail_data);
            $mail->send(array($not['email']));
        }
    }
}