Ejemplo n.º 1
0
function send_emails($id_comment)
{
    // disposant de l'email d'un commentaire, on détermine l'article associé, le titre, l’auteur du comm et l’email de l’auteur du com.
    $article = get_entry($GLOBALS['db_handle'], 'commentaires', 'bt_article_id', $id_comment, 'return');
    $article_title = get_entry($GLOBALS['db_handle'], 'articles', 'bt_title', $article, 'return');
    $comm_author = get_entry($GLOBALS['db_handle'], 'commentaires', 'bt_author', $id_comment, 'return');
    $comm_author_email = get_entry($GLOBALS['db_handle'], 'commentaires', 'bt_email', $id_comment, 'return');
    // puis la liste de tous les commentaires de cet article
    $liste_commentaires = array();
    try {
        $query = "SELECT bt_email,bt_subscribe,bt_id FROM commentaires WHERE bt_statut=1 AND bt_article_id=? ORDER BY bt_id";
        $req = $GLOBALS['db_handle']->prepare($query);
        $req->execute(array($article));
        $liste_commentaires = $req->fetchAll(PDO::FETCH_ASSOC);
    } catch (Exception $e) {
        die('Erreur : ' . $e->getMessage());
    }
    // Récupérre la liste (sans doublons) des emails des commentateurs, ainsi que leurs souscription à la notification d'email.
    // si plusieurs comm avec la même email, alors seul le dernier est pris en compte.
    // si l’auteur même du commentaire est souscrit, il ne recoit pas l’email de son propre commentaire.
    $emails = array();
    foreach ($liste_commentaires as $i => $comment) {
        if (!empty($comment['bt_email']) and $comm_author_email != $comment['bt_email']) {
            $emails[$comment['bt_email']] = $comment['bt_subscribe'] . '-' . get_id($comment['bt_id']);
        }
    }
    // ne conserve que la liste des mails dont la souscription est demandée (= 1)
    $to_send_mail = array();
    foreach ($emails as $mail => $is_subscriben) {
        if ($is_subscriben[0] == '1') {
            // $is_subscriben is seen as a array of chars here, first char is 0 or 1 for subscription.
            $to_send_mail[$mail] = substr($is_subscriben, -14);
        }
    }
    $subject = 'New comment on "' . $article_title . '" - ' . $GLOBALS['nom_du_site'];
    $headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset="UTF-8"' . "\r\n";
    $headers .= 'From: no.reply_' . $GLOBALS['email'] . "\r\n" . 'X-Mailer: BlogoText - PHP/' . phpversion();
    // for debug
    //header('Content-type: text/html; charset=UTF-8');
    //die(($to. $subject. $message. $headers));
    //echo '<pre>';print_r($emails);
    //echo '<pre>';print_r($to_send_mail);
    //die();
    // envoi les emails.
    foreach ($to_send_mail as $mail => $is_subscriben) {
        $comment = substr($is_subscriben, -14);
        $unsublink = get_blogpath($article, '') . '&amp;unsub=1&amp;comment=' . $comment . '&amp;mail=' . sha1($mail);
        $message = '<html>';
        $message .= '<head><title>' . $subject . '</title></head>';
        $message .= '<body><p>A new comment by <b>' . $comm_author . '</b> has been posted on <b>' . $article_title . '</b> form ' . $GLOBALS['nom_du_site'] . '.<br/>';
        $message .= 'You can see it by following <a href="' . get_blogpath($article, '') . '#' . article_anchor($id_comment) . '">this link</a>.</p>';
        $message .= '<p>To unsubscribe from the comments on that post, you can follow this link: <a href="' . $unsublink . '">' . $unsublink . '</a>.</p>';
        $message .= '<p>To unsubscribe from the comments on all the posts, follow this link: <a href="' . $unsublink . '&amp;all=1">' . $unsublink . '&amp;all=1</a>.</p>';
        $message .= '<p>Also, do not reply to this email, since it is an automatic generated email.</p><p>Regards.</p></body>';
        $message .= '</html>';
        mail($mail, $subject, $message, $headers);
    }
    return TRUE;
}
Ejemplo n.º 2
0
function init_list_comments($comment)
{
    $comment['auteur_lien'] = !empty($comment['bt_webpage']) ? '<a href="' . $comment['bt_webpage'] . '" class="webpage">' . $comment['bt_author'] . '</a>' : $comment['bt_author'];
    $comment['anchor'] = article_anchor($comment['bt_id']);
    $comment['bt_link'] = get_blogpath($comment['bt_article_id'], '') . '#' . $comment['anchor'];
    $comment = array_merge($comment, decode_id($comment['bt_id']));
    return $comment;
}