コード例 #1
0
/** \brief send the email notifications dealing with wiki page  changes to
 * admin notification addresses + watching users addresses (except editor is configured)
 * \$event: 'wiki_page_created'|'wiki_page_changed'
 */
function sendWikiEmailNotification($event, $pageName, $edit_user, $edit_comment, $oldver, $edit_data, $machine, $diff = '', $minor = false)
{
    global $tikilib, $notificationlib, $feature_user_watches, $smarty, $userlib, $wiki_watch_editor;
    $nots = array();
    $defaultLanguage = $tikilib->get_preference("language", "en");
    // Users watching this forum or this post
    if ($feature_user_watches == 'y' && $event == 'wiki_page_changed') {
        $nots = $tikilib->get_event_watches($event, $pageName);
        if ($wiki_watch_editor != "y") {
            for ($i = count($nots) - 1; $i >= 0; --$i) {
                if ($nots[$i]['user'] == $edit_user) {
                    unset($nots[$i]);
                    break;
                }
            }
        }
        foreach (array_keys($nots) as $i) {
            $nots[$i]['language'] = $tikilib->get_user_preference($nots[$i]['user'], "language", $defaultLanguage);
        }
    }
    // admin notifications
    if ($notificationlib) {
        // If it's a minor change, get only the minor change watches.
        if ($minor) {
            $emails = $notificationlib->get_mail_events('wiki_page_changes_incl_minor', 'wikipage' . $pageName);
            // look for pageName and any page
            // else if it's not minor change, get both watch types.
        } else {
            $emails1 = $notificationlib->get_mail_events('wiki_page_changes', 'wikipage' . $pageName);
            // look for pageName and any page
            $emails2 = $notificationlib->get_mail_events('wiki_page_changes_incl_minor', 'wikipage' . $pageName);
            // look for pageName and any page
            $emails = array_merge($emails1, $emails2);
        }
        foreach ($emails as $email) {
            if ($wiki_watch_editor != "y" && $email == $edit_user) {
                continue;
            }
            if (!testEmailInList($nots, $email)) {
                $not = array('email' => $email);
                if ($not['user'] = $userlib->get_user_by_email($email)) {
                    $not['language'] = $tikilib->get_user_preference($not['user'], "language", $defaultLanguage);
                } else {
                    $not['language'] = $defaultLanguage;
                }
                $nots[] = $not;
            }
        }
    }
    if ($edit_user == '') {
        $edit_user = tra('Anonymous');
    }
    if (count($nots)) {
        if (function_exists("html_entity_decode")) {
            $edit_data = html_entity_decode($edit_data);
        }
        include_once 'lib/webmail/tikimaillib.php';
        $mail = new TikiMail();
        $smarty->assign('mail_site', $_SERVER["SERVER_NAME"]);
        $smarty->assign('mail_page', $pageName);
        $smarty->assign('mail_date', date("U"));
        $smarty->assign('mail_user', $edit_user);
        $smarty->assign('mail_comment', $edit_comment);
        $newver = $oldver + 1;
        $smarty->assign('mail_oldver', $oldver);
        $smarty->assign('mail_newver', $newver);
        $smarty->assign('mail_data', $edit_data);
        $foo = parse_url($_SERVER["REQUEST_URI"]);
        $machine = $tikilib->httpPrefix() . dirname($foo["path"]);
        $smarty->assign('mail_machine', $machine);
        $parts = explode('/', $foo['path']);
        if (count($parts) > 1) {
            unset($parts[count($parts) - 1]);
        }
        $smarty->assign('mail_machine_raw', $tikilib->httpPrefix() . implode('/', $parts));
        $smarty->assign_by_ref('mail_pagedata', $edit_data);
        $smarty->assign_by_ref('mail_diffdata', $diff);
        if ($event == 'wiki_page_created') {
            $smarty->assign('new_page', 'y');
        }
        foreach ($nots as $not) {
            if (isset($not['hash'])) {
                $smarty->assign('mail_hash', $not['hash']);
            }
            $mail->setUser($not['user']);
            $mail_data = $smarty->fetchLang($not['language'], "mail/user_watch_wiki_page_changed_subject.tpl");
            $mail->setSubject(sprintf($mail_data, $pageName));
            $mail_data = $smarty->fetchLang($not['language'], "mail/user_watch_wiki_page_changed.tpl");
            $mail->setText($mail_data);
            $mail->buildMessage();
            $mail->send(array($not['email']));
        }
    }
}
コード例 #2
0
/**
 *\brief send the email notifications dealing with wiki page  changes to
 * admin notification addresses + watching users addresses (except editor is configured)
 * \$event: 'wiki_page_created'|'wiki_page_changed'|wiki_page_deleted |wiki_file_attached
 *
 */
function sendWikiEmailNotification($wikiEvent, $pageName, $edit_user, $edit_comment, $oldver, $edit_data, $machine = '', $diff = '', $minor = false, $contributions = '', $structure_parent_id = 0, $attId = 0, $lang = '')
{
    global $tikilib, $prefs, $smarty, $userlib;
    global $notificationlib;
    include_once 'lib/notifications/notificationlib.php';
    $nots = array();
    $defaultLanguage = $prefs['site_language'];
    if ($wikiEvent == 'wiki_file_attached') {
        $event = 'wiki_page_changed';
    } else {
        $event = $wikiEvent;
    }
    if ($prefs['feature_user_watches'] == 'y') {
        $nots = $tikilib->get_event_watches($event, $pageName);
    }
    if ($prefs['feature_user_watches'] == 'y' && $event == 'wiki_page_changed') {
        global $structlib;
        include_once 'lib/structures/structlib.php';
        $nots2 = $structlib->get_watches($pageName);
        if (!empty($nots2)) {
            $nots = array_merge($nots, $nots2);
        }
        if ($prefs['wiki_watch_editor'] != "y" || $prefs['user_wiki_watch_editor'] != "y") {
            for ($i = count($nots) - 1; $i >= 0; --$i) {
                if ($nots[$i]['user'] == $edit_user) {
                    unset($nots[$i]);
                    break;
                }
            }
        }
        foreach (array_keys($nots) as $i) {
            $nots[$i]['language'] = $tikilib->get_user_preference($nots[$i]['user'], "language", $defaultLanguage);
        }
    }
    if ($prefs['feature_user_watches'] == 'y' && $event == 'wiki_page_created' && $structure_parent_id) {
        global $structlib;
        include_once 'lib/structures/structlib.php';
        $nots = array_merge($nots, $structlib->get_watches('', $structure_parent_id));
    }
    // admin notifications
    // If it's a minor change, get only the minor change watches.
    if ($minor) {
        $emails = $notificationlib->get_mail_events('wiki_page_changes_incl_minor', $pageName);
        // look for pageName and any page
    } else {
        // else if it's not minor change, get both watch types.
        $emails1 = $notificationlib->get_mail_events('wiki_page_changes', $pageName);
        // look for pageName and any page
        $emails2 = $notificationlib->get_mail_events('wiki_page_changes_incl_minor', $pageName);
        // look for pageName and any page
        $emails = array_merge($emails1, $emails2);
    }
    foreach ($emails as $email) {
        if (($prefs['wiki_watch_editor'] != "y" || $prefs['user_wiki_watch_editor'] != "y") && $email == $edit_user) {
            continue;
        }
        if (!testEmailInList($nots, $email)) {
            $not = array('email' => $email);
            if ($not['user'] = $userlib->get_user_by_email($email)) {
                $not['language'] = $tikilib->get_user_preference($not['user'], "language", $defaultLanguage);
            } else {
                $not['language'] = $defaultLanguage;
            }
            $nots[] = $not;
        }
    }
    if ($edit_user == '') {
        $edit_user = tra('Anonymous');
    }
    if ($prefs['feature_user_watches'] == 'y' && $prefs['feature_daily_report_watches'] == 'y') {
        if ($wikiEvent == 'wiki_file_attached') {
            $reportsManager = Reports_Factory::build('Reports_Manager');
            $reportsManager->addToCache($nots, array("event" => $wikiEvent, "pageName" => $pageName, 'attId' => $attId, "editUser" => $edit_user, "editComment" => $edit_comment, 'filename' => $edit_data));
        } else {
            $reportsManager = Reports_Factory::build('Reports_Manager');
            $reportsManager->addToCache($nots, array("event" => $wikiEvent, "pageName" => $pageName, "object" => $pageName, "editUser" => $edit_user, "editComment" => $edit_comment, "oldVer" => $oldver));
        }
    }
    if (count($nots)) {
        $edit_data = TikiLib::htmldecode($edit_data);
        include_once 'lib/mail/maillib.php';
        $smarty->assign('mail_site', $_SERVER["SERVER_NAME"]);
        $smarty->assign('mail_page', $pageName);
        $smarty->assign('mail_date', $tikilib->now);
        $smarty->assign('mail_user', $edit_user);
        $smarty->assign('mail_comment', $edit_comment);
        $newver = $oldver + 1;
        $smarty->assign('mail_oldver', $oldver);
        $smarty->assign('mail_newver', $newver);
        $smarty->assign('mail_data', $edit_data);
        $smarty->assign('mail_attId', $attId);
        $foo = parse_url($_SERVER["REQUEST_URI"]);
        $machine = $tikilib->httpPrefix(true) . dirname($foo["path"]);
        $smarty->assign('mail_machine', $machine);
        if ($prefs['feature_contribution'] == 'y' && !empty($contributions)) {
            global $contributionlib;
            include_once 'lib/contribution/contributionlib.php';
            $smarty->assign('mail_contributions', $contributionlib->print_contributions($contributions));
        }
        $parts = explode('/', $foo['path']);
        if (count($parts) > 1) {
            unset($parts[count($parts) - 1]);
        }
        $smarty->assign('mail_machine_raw', $tikilib->httpPrefix(true) . implode('/', $parts));
        $smarty->assign_by_ref('mail_pagedata', $edit_data);
        $smarty->assign_by_ref('mail_diffdata', $diff);
        if ($event == 'wiki_page_created') {
            $smarty->assign('mail_action', 'new');
        } elseif ($event == 'wiki_page_deleted') {
            $smarty->assign('mail_action', 'delete');
        } elseif ($wikiEvent == 'wiki_file_attached') {
            $smarty->assign('mail_action', 'attach');
        } else {
            $smarty->assign('mail_action', 'edit');
        }
        include_once 'lib/webmail/tikimaillib.php';
        foreach ($nots as $not) {
            if (empty($not['email'])) {
                continue;
            }
            $smarty->assign('watchId', $not['watchId']);
            $mail_subject = $smarty->fetchLang($not['language'], "mail/user_watch_wiki_page_changed_subject.tpl");
            $mail_data = $smarty->fetchLang($not['language'], "mail/user_watch_wiki_page_changed.tpl");
            $mail = new TikiMail($not['user']);
            $mail->setSubject(sprintf($mail_subject, $pageName));
            $mail->setText($mail_data);
            $mail->send(array($not['email']));
        }
    }
}