Example #1
0
    /**
     * Send email notifications to subscribed users:
     *
     * efy-asimo> moderatation and subscription notifications have been separated
     *
     * @param boolean true if send only moderation email, false otherwise
     * @param boolean true if send for everyone else but not for moterators, because a moderation email was sent for them
     * @param integer the user ID who executed the action which will be notified, or NULL if it was executed by an anonymous user
     */
    function send_email_notifications($only_moderators = false, $except_moderators = false, $executed_by_userid = NULL)
    {
        global $DB, $admin_url, $baseurl, $debug, $Debuglog, $htsrv_url;
        global $Settings, $UserSettings;
        if ($only_moderators && $except_moderators) {
            // at least one of them must be false
            return;
        }
        $edited_Item =& $this->get_Item();
        $edited_Blog =& $edited_Item->get_Blog();
        $owner_User = $edited_Blog->get_owner_User();
        $notify_users = array();
        $moderators = array();
        if ($only_moderators || $except_moderators) {
            // we need the list of moderators:
            $sql = 'SELECT DISTINCT user_email, user_ID, uset_value as notify_moderation
						FROM T_users
							LEFT JOIN T_coll_user_perms ON bloguser_user_ID = user_ID
							LEFT JOIN T_coll_group_perms ON bloggroup_group_ID = user_grp_ID
							LEFT JOIN T_users__usersettings ON uset_user_ID = user_ID AND uset_name = "notify_comment_moderation"
							LEFT JOIN T_groups ON grp_ID = user_grp_ID
						WHERE ( ( bloguser_blog_ID = ' . $edited_Blog->ID . ' AND bloguser_perm_edit_cmt IN ( "anon", "lt", "le", "all" ) )
								OR ( bloggroup_blog_ID = ' . $edited_Blog->ID . ' AND bloggroup_perm_edit_cmt IN ( "anon", "lt", "le", "all" ) )
								OR ( grp_perm_blogs = "editall" ) )
							AND LENGTH(TRIM(user_email)) > 0';
            $moderators_to_notify = $DB->get_results($sql);
            foreach ($moderators_to_notify as $moderator) {
                $notify_moderator = is_null($moderator->notify_moderation) ? $Settings->get('def_notify_comment_moderation') : $moderator->notify_moderation;
                if ($notify_moderator) {
                    // add user to notify
                    $moderators[] = $moderator->user_ID;
                }
            }
            if ($UserSettings->get('notify_comment_moderation', $owner_User->ID) && is_email($owner_User->get('email'))) {
                // add blog owner
                $moderators[] = $owner_User->ID;
            }
            // Load all moderators, and check each edit permission on this comment
            $UserCache =& get_UserCache();
            $UserCache->load_list($moderators);
            foreach ($moderators as $index => $moderator_ID) {
                $moderator_User = $UserCache->get_by_ID($moderator_ID, false);
                if (!$moderator_User || !$moderator_User->check_perm('comment!CURSTATUS', 'edit', false, $this)) {
                    // User doesn't exists any more, or has no permission to edit this comment!
                    unset($moderators[$index]);
                } elseif ($only_moderators) {
                    $notify_users[$moderator_ID] = 'moderator';
                }
            }
        }
        if (!$only_moderators) {
            // Not only moderators needs to be notified:
            $except_condition = '';
            if ($except_moderators && !empty($moderators)) {
                // Set except moderators condition. Exclude moderators who already got a notification email.
                $except_condition = ' AND user_ID NOT IN ( "' . implode('", "', $moderators) . '" )';
            }
            // Check if we need to include the item creator user:
            $creator_User =& $edited_Item->get_creator_User();
            if ($UserSettings->get('notify_published_comments', $creator_User->ID) && !empty($creator_User->email) && !in_array($creator_User->ID, $moderators)) {
                // Post creator wants to be notified, and post author is not a moderator...
                $notify_users[$creator_User->ID] = 'creator';
            }
            // Get list of users who want to be notified about the this post comments:
            if ($edited_Blog->get_setting('allow_item_subscriptions')) {
                // item subscriptions is allowed
                $sql = 'SELECT DISTINCT user_ID
									FROM T_items__subscriptions INNER JOIN T_users ON isub_user_ID = user_ID
								 WHERE isub_item_ID = ' . $edited_Item->ID . '
								   AND isub_comments <> 0
								   AND LENGTH(TRIM(user_email)) > 0' . $except_condition;
                $notify_list = $DB->get_results($sql);
                // Preprocess list:
                foreach ($notify_list as $notification) {
                    $notify_users[$notification->user_ID] = 'item_subscription';
                }
            }
            // Get list of users who want to be notfied about this blog comments:
            if ($edited_Blog->get_setting('allow_subscriptions')) {
                // blog subscription is allowed
                $sql = 'SELECT DISTINCT user_ID
								FROM T_subscriptions INNER JOIN T_users ON sub_user_ID = user_ID
							 WHERE sub_coll_ID = ' . $edited_Blog->ID . '
							   AND sub_comments <> 0
							   AND LENGTH(TRIM(user_email)) > 0' . $except_condition;
                $notify_list = $DB->get_results($sql);
                // Preprocess list:
                foreach ($notify_list as $notification) {
                    $notify_users[$notification->user_ID] = 'blog_subscription';
                }
            }
        }
        if ($executed_by_userid != NULL && isset($notify_users[$executed_by_userid])) {
            // don't notify the user who just created/updated this comment
            unset($notify_users[$executed_by_userid]);
        }
        if (!count($notify_users)) {
            // No-one to notify:
            return false;
        }
        /*
         * We have a list of user IDs to notify:
         */
        // TODO: dh> this reveals the comments author's email address to all subscribers!!
        //           $notify_from should get used by default, unless the user has opted in to be the sender!
        // fp>If the subscriber has permission to moderate the comments, he SHOULD receive the email address.
        // Get author email address. It will be visible for moderators/blog/post owners only -- NOT for other subscribers
        if ($this->get_author_User()) {
            // Comment from a registered user:
            $reply_to = $this->author_User->get('email');
            $author_name = $this->author_User->get('login');
            $author_ID = $this->author_User->ID;
        } elseif (!empty($this->author_email)) {
            // non-member, but with email address:
            $reply_to = $this->author_email;
            $author_name = $this->dget('author');
            $author_ID = NULL;
        } else {
            // Fallback (we have no email address):  fp>TODO: or the subscriber is not allowed to view it.
            $reply_to = NULL;
            $author_name = $this->dget('author');
            $author_ID = NULL;
        }
        // Load all users who will be notified, becasuse another way the send_mail_to_User funtion would load them one by one
        $UserCache =& get_UserCache();
        $UserCache->load_list(array_keys($notify_users));
        // Load a list with the blocked emails  in cache
        load_blocked_emails(array_keys($notify_users));
        // Send emails:
        foreach ($notify_users as $notify_user_ID => $notify_type) {
            // get data content
            $notify_User = $UserCache->get_by_ID($notify_user_ID);
            $notify_email = $notify_User->get('email');
            // init notification setting
            locale_temp_switch($notify_User->get('locale'));
            $notify_user_Group = $notify_User->get_Group();
            $notify_full = $notify_type == 'moderator' && $notify_user_Group->check_perm('comment_moderation_notif', 'full') || $notify_user_Group->check_perm('comment_subscription_notif', 'full');
            switch ($this->type) {
                case 'trackback':
                    /* TRANS: Subject of the mail to send on new trackbacks. First %s is the blog's shortname, the second %s is the item's title. */
                    $subject = T_('[%s] New trackback on "%s"');
                    break;
                default:
                    /* TRANS: Subject of the mail to send on new comments. */
                    // In case of full notification the first %s is blog name, the second %s is the item's title.
                    // In case of short notification the first %s is author login, the second %s is the item's title.
                    $subject = $notify_full ? T_('[%s] New comment on "%s"') : T_('%s posted a new comment on "%s"');
                    if ($only_moderators) {
                        if ($this->status == 'draft') {
                            $subject = $notify_full ? T_('[%s] New comment awaiting moderation on "%s"') : T_('New comment awaiting moderation: ') . $subject;
                        } else {
                            $subject = $notify_full ? T_('[%s] New comment may need moderation on "%s"') : T_('New comment may need moderation: ') . $subject;
                        }
                    }
            }
            if ($notify_type == 'moderator') {
                // moderation email
                $user_reply_to = $reply_to;
            } else {
                if ($notify_type == 'blog_subscription') {
                    // blog subscription
                    $user_reply_to = NULL;
                } else {
                    if ($notify_type == 'item_subscription') {
                        // item subscription
                        $user_reply_to = NULL;
                    } else {
                        if ($notify_type == 'creator') {
                            // user is the creator of the post
                            $user_reply_to = $reply_to;
                        } else {
                            debug_die('Unknown user subscription type');
                        }
                    }
                }
            }
            $subject = sprintf($subject, $notify_full ? $edited_Blog->get('shortname') : $author_name, $edited_Item->get('title'));
            $email_template_params = array('notify_full' => $notify_full, 'Comment' => $this, 'Blog' => $edited_Blog, 'Item' => $edited_Item, 'author_name' => $author_name, 'author_ID' => $author_ID, 'notify_type' => $notify_type);
            if ($debug) {
                $notify_message = mail_template('comment_new', 'text', $email_template_params);
                $mail_dump = "Sending notification to {$notify_email}:<pre>Subject: {$subject}\n{$notify_message}</pre>";
                if ($debug >= 2) {
                    // output mail content - NOTE: this will kill sending of headers.
                    echo "<p>{$mail_dump}</p>";
                }
                $Debuglog->add($mail_dump, 'notification');
            }
            // Send the email:
            // Note: Note activated users won't get notification email
            send_mail_to_User($notify_user_ID, $subject, 'comment_new', $email_template_params, false, array('Reply-To' => $user_reply_to));
            blocked_emails_memorize($notify_User->email);
            locale_restore_previous();
        }
        blocked_emails_display();
    }
Example #2
0
 if (empty($forgetful_User->email)) {
     $Messages->add(T_('You have no email address with your profile, therefore we cannot reset your password.') . ' ' . T_('Please try contacting the admin.'), 'error');
 } else {
     $request_id = generate_random_key(22);
     // 22 to make it not too long for URL but unique/safe enough
     // Count how many users match to this login ( It can be more then one in case of email login )
     $user_ids = $UserCache->get_ID_array();
     $user_count = count($user_ids);
     // Set blog param for email link
     $blog_param = '';
     if (!empty($blog)) {
         $blog_param = '&inskin=true&blog=' . $blog;
     }
     $subject = sprintf(T_('Password change request for %s'), $login);
     $email_template_params = array('user_count' => $user_count, 'request_id' => $request_id, 'blog_param' => $blog_param);
     if (!send_mail_to_User($forgetful_User->ID, $subject, 'account_password_reset', $email_template_params, true)) {
         $Messages->add(T_('Sorry, the email with the link to reset your password could not be sent.') . '<br />' . T_('Possible reason: the PHP mail() function may have been disabled on the server.'), 'error');
     } else {
         $Session->set('core.changepwd.request_id', $request_id, 86400 * 2);
         // expires in two days (or when clicked)
         $Session->set('core.changepwd.request_ts_login', $servertimenow . '_' . $login, 360);
         // request timestamp and login/email - expires in six minutes
         $Session->dbsave();
         // save immediately
         $Messages->add(T_('If you correctly entered your login or email address, a link to change your password has been sent to your registered email address.'), 'success');
         syslog_insert('User requested password reset', 'info', 'user', $forgetful_User->ID);
     }
 }
 locale_restore_previous();
 $action = 'req_login';
 break;
                        }
                        if ($allowed) {
                            // User has permission to edit comments with this author level
                            $cmt_count += $count;
                        }
                    }
                }
            }
            if ($cmt_count > 0) {
                // There are comments awaiting moderation on this blog and user has permission to moderate
                $blog_comments[$blog_ID] = $cmt_count;
            }
        }
    }
    if (empty($blog_comments)) {
        // There are no comments awaiting moderation that this user could moderate
        continue;
    }
    $params['blogs'] = array_keys($blog_comments);
    // This can be remvoved if this solution will remain
    $params['comments'] = $blog_comments;
    // Change locale here to localize the email subject and content
    locale_temp_switch($moderator_User->get('locale'));
    if (send_mail_to_User($moderator_ID, T_('Comment moderation reminder'), 'comments_unmoderated_reminder', $params, false)) {
        $mail_sent++;
    }
    locale_restore_previous();
}
$result_message = sprintf(T_('%d moderator have been notified!'), $mail_sent);
return 1;
/*OK*/
Example #4
0
    locale_temp_switch($Blog->locale);
}
// Trigger event: a Plugin could add a $category="error" message here..
$Plugins->trigger_event('MessageFormSent', array('recipient_ID' => $recipient_id, 'item_ID' => $post_id, 'comment_ID' => $comment_id, 'subject' => &$subject, 'message' => &$message, 'Blog' => &$Blog, 'sender_name' => &$sender_name, 'sender_email' => &$sender_address));
$success_message = !$Messages->has_errors();
if ($success_message) {
    // no errors, try to send the message
    $email_template_params = array('sender_name' => $sender_name, 'sender_address' => $sender_address, 'Blog' => $Blog, 'message' => $message, 'comment_id' => $comment_id, 'post_id' => $post_id, 'recipient_User' => $recipient_User, 'Comment' => $Comment);
    if (empty($recipient_User)) {
        // Send mail to visitor
        // Get a message text from template file
        $message = mail_template('contact_message_new', 'text', $email_template_params);
        $success_message = send_mail($recipient_address, $recipient_name, $subject, $message, NULL, NULL, array('Reply-To' => $sender_address));
    } else {
        // Send mail to registered user
        $success_message = send_mail_to_User($recipient_User->ID, $subject, 'contact_message_new', $email_template_params, false, array('Reply-To' => $sender_address));
    }
    // restore the locale to the blog visitor language, before we would display an error message
    locale_restore_previous();
    if ($success_message) {
        // Email has been sent successfully
        if (!is_logged_in()) {
            // We should save a counter (only for anonymous users)
            antispam_increase_counter('contact_email');
        }
    } else {
        // Could not send email
        if ($demo_mode) {
            $Messages->add('Sorry, could not send email. Sending email in demo mode is disabled.', 'error');
        } else {
            $Messages->add(T_('Sorry, could not send email.') . '<br />' . T_('Possible reason: the PHP mail() function may have been disabled on the server.'), 'error');
Example #5
0
/**
 * Send newsletter emails
 */
function newsletter_send()
{
    global $DB, $Session;
    load_class('users/model/_userlist.class.php', 'UserList');
    // Initialize users list from session cache in order to get users IDs for newsletter
    $UserList = new UserList('admin');
    $UserList->memorize = false;
    $UserList->load_from_Request();
    $users_IDs = $UserList->filters['users'];
    // Get all active users which accept newsletter email
    $SQL = get_newsletter_users_sql($users_IDs);
    $users = $DB->get_col($SQL->get());
    echo sprintf(T_('Newsletter is sending for %s users...'), count($users)) . '<br /><br />';
    evo_flush();
    $email_newsletter_params = array('message' => $Session->get('newsletter_message'));
    foreach ($users as $user_ID) {
        $UserCache =& get_UserCache();
        $User = $UserCache->get_by_ID($user_ID);
        echo sprintf(T_('Email is sending for %s (%s)...'), $User->get_identity_link(), $User->get('email')) . ' ';
        // Send a newsletter in user's locale
        locale_temp_switch($User->get('locale'));
        $email_result = send_mail_to_User($user_ID, $Session->get('newsletter_title'), 'newsletter', $email_newsletter_params);
        locale_restore_previous();
        if ($email_result) {
            // Success sending
            echo T_('OK');
        } else {
            // Failed sending
            echo '<span class="red">' . T_('Failed') . '</span>';
        }
        echo '<br />';
        evo_flush();
    }
}
                        }
                        if ($allowed) {
                            // User has permission to edit posts with this author level
                            $post_count += $count;
                        }
                    }
                }
            }
            if ($post_count > 0) {
                // There are posts awaiting moderation on this blog and user has permission to moderate
                $blog_posts[$blog_ID] = $post_count;
            }
        }
    }
    if (empty($blog_posts)) {
        // There are no posts awaiting moderation that this user could moderate
        continue;
    }
    $params['blogs'] = array_keys($blog_posts);
    // This can be remvoved if this solution will remain
    $params['posts'] = $blog_posts;
    // Change locale here to localize the email subject and content
    locale_temp_switch($moderator_User->get('locale'));
    if (send_mail_to_User($moderator_ID, T_('Post moderation reminder'), 'posts_unmoderated_reminder', $params, false)) {
        $mail_sent++;
    }
    locale_restore_previous();
}
$result_message = sprintf('%d moderators have been notified!', $mail_sent);
return 1;
/*OK*/
Example #7
0
    /**
     * Send email notification to recipients on new thread or new message event.
     *
     * @param boolean true if new thread, false if new message in the current thread
     * @param boolean the User who sent the message, in case of current User it may be NULL ( This is not the current User e.g. in case of welcome messages )
     * @return boolean True if all messages could be sent, false otherwise.
     */
    function send_email_notifications($new_thread = true, $from_User = NULL)
    {
        global $DB, $current_User, $admin_url, $baseurl, $app_name;
        global $Settings, $UserSettings, $servertimenow;
        // Select recipients of the current thread:
        $SQL = new SQL();
        $SQL->SELECT('u.user_ID, us.uset_value as notify_messages');
        $SQL->FROM('T_messaging__threadstatus ts
						INNER JOIN T_messaging__contact c
							ON ts.tsta_user_ID = c.mct_to_user_ID AND c.mct_from_user_ID = ' . $this->author_user_ID . ' AND c.mct_blocked = 0
						INNER JOIN T_users u
							ON ts.tsta_user_ID = u.user_ID
						LEFT OUTER JOIN T_users__usersettings us ON u.user_ID = us.uset_user_ID AND us.uset_name = "notify_messages"');
        $SQL->WHERE('ts.tsta_thread_ID = ' . $this->Thread->ID . ' AND ts.tsta_user_ID <> ' . $this->author_user_ID);
        $thrd_recipients = $DB->get_assoc($SQL->get());
        // set message link:
        list($message_link, $prefs_link) = get_messages_link_to($this->thread_ID);
        // Construct message subject and body:
        if ($new_thread) {
            $subject = NT_('%s just sent you a new message!');
        } elseif (count($thrd_recipients) == 1) {
            $subject = NT_('%s just replied to your message!');
        } else {
            $subject = NT_('%s just replied to a conversation you are involved in!');
        }
        // Get other unread threads
        $other_unread_threads = get_users_unread_threads(array_keys($thrd_recipients), $this->thread_ID, 'array', 'html');
        // Load all users who will be notified
        $UserCache =& get_UserCache();
        $UserCache->load_list(array_keys($thrd_recipients));
        // Send email notifications.
        $ret = true;
        $def_notify_messages = $Settings->get('def_notify_messages');
        foreach ($thrd_recipients as $recipient_ID => $notify_messages) {
            // Send mail to recipients who needs to be notified. recipients are already loaded into the UserCache
            if (!($notify_messages || is_null($notify_messages) && $def_notify_messages)) {
                // User should NOT be notified
                continue;
            }
            $email_template_params = array('recipient_ID' => $recipient_ID, 'new_thread' => $new_thread, 'thrd_recipients' => $thrd_recipients, 'Message' => $this, 'message_link' => $message_link, 'other_unread_threads' => $other_unread_threads[$recipient_ID], 'from_User' => $from_User);
            $notify_User = $UserCache->get_by_ID($recipient_ID);
            // Change locale here to localize the email subject and content
            locale_temp_switch($notify_User->get('locale'));
            $sender_login = $from_User === NULL ? $current_User->login : $from_User->login;
            $localized_subject = sprintf(T_($subject), $sender_login);
            // Note: Not activated users won't get notification email
            if (send_mail_to_User($recipient_ID, $localized_subject, 'private_message_new', $email_template_params)) {
                // email sent successful, update las_unread_message_reminder timestamp, because the notification contains all unread messages
                $UserSettings->set('last_unread_messages_reminder', date2mysql($servertimenow), $recipient_ID);
            } else {
                // message was not sent
                $ret = false;
            }
            locale_restore_previous();
        }
        // update reminder timestamp changes
        $UserSettings->dbupdate();
        return $ret;
    }
Example #8
0
 /**
  * Send an email to the user with a link to validate/confirm his email address.
  *
  * If the email could get sent, it saves the used "request_id" into the user's Session.
  *
  * @param string URL, where to redirect the user after he clicked the validation link (gets saved in Session).
  * @return boolean True, if the email could get sent; false if not
  */
 function send_validate_email($redirect_to_after, $blog = NULL, $email_changed = false)
 {
     global $app_name, $Session, $secure_htsrv_url, $baseurl, $servertimenow;
     global $Settings, $UserSettings;
     // Display messages depending on user email status
     display_user_email_status_message($this->ID);
     if ($Settings->get('validation_process') == 'easy') {
         // validation process is set to easy, send and easy activation email
         return send_easy_validate_emails(array($this->ID), false, $email_changed);
     }
     if (mail_is_blocked($this->email)) {
         // prevent trying to send an email to a blocked email address ( Note this is checked in the send_easy_validate_emails too )
         return false;
     }
     if (empty($redirect_to_after)) {
         // redirect to was not set
         $redirect_to_after = param('redirect_to', 'url', '');
         if (empty($redirect_to_after)) {
             if (is_admin_page()) {
                 $redirect_to_after = regenerate_url('action');
             } else {
                 $redirect_to_after = $this->get_userpage_url();
             }
         }
     }
     $request_id = generate_random_key(22);
     $blog_param = empty($blog) ? '' : '&inskin=1&blog=' . $blog;
     // Change locale here to localize the email subject and content
     locale_temp_switch($this->get('locale'));
     $email_template_params = array('status' => $this->status, 'blog_param' => $blog_param, 'request_id' => $request_id);
     $r = send_mail_to_User($this->ID, T_('Activate your account: $login$'), 'account_activate', $email_template_params, true);
     locale_restore_previous();
     if ($r) {
         // save request_id into Session
         $request_ids = $Session->get('core.validatemail.request_ids');
         if (!is_array($request_ids) || $email_changed) {
             // create new request ids array if it doesn't exist yet, or if user email changed ( this way the old request into the old email address won't be valid )
             $request_ids = array();
         }
         $request_ids[] = $request_id;
         $Session->set('core.validatemail.request_ids', $request_ids, 86400 * 2);
         // expires in two days (or when clicked)
         // set a redirect_to session variable because this way after the account will be activated we will know where to redirect
         $Session->set('core.validatemail.redirect_to', $redirect_to_after);
         $Session->dbsave();
         // save immediately
         // update last activation email timestamp
         $UserSettings->set('last_activation_email', date2mysql($servertimenow), $this->ID);
         $UserSettings->dbupdate();
     }
     return $r;
 }
    imap_expunge($mbox);
    pbm_msg(sprintf(T_('Deleted %d processed message(s) from inbox.'), $del_cntr), true);
}
imap_close($mbox);
// Send reports
if ($post_cntr > 0) {
    pbm_msg(sprintf(T_('New posts created: %d'), $post_cntr), true);
    $UserCache =& get_UserCache();
    foreach ($pbm_items as $Items) {
        // Send report to post author
        $to_user_ID = 0;
        foreach ($Items as $Item) {
            if ($to_user_ID == 0) {
                // Get author ID
                $to_user_ID = $Item->Author->ID;
                break;
            }
        }
        $email_template_params = array('Items' => $Items);
        $to_User = $UserCache->get_by_ID($to_user_ID);
        // Change locale here to localize the email subject and content
        locale_temp_switch($to_User->get('locale'));
        send_mail_to_User($to_user_ID, T_('Post by email report'), 'post_by_email_report', $email_template_params);
        locale_restore_previous();
    }
    // sam2kb> TODO: Send detailed report to blog owner
    // global $pbm_messages;
    // send_mail( $blog_owner_email, $blog_owner_name, T_('Post by email detailed report'), implode("\n",$pbm_messages) );
}
return 1;
// success
Example #10
0
    /**
     * Send email notifications to subscribed users
     *
     * @todo fp>> shall we notify suscribers of blog were this is in extra-cat? blueyed>> IMHO yes.
     *
     * @param boolean Display notification messages or not
     * @param array Already notified user ids, or NULL if it is not the case
     */
    function send_email_notifications($display = true, $already_notified = NULL)
    {
        global $DB, $admin_url, $baseurl, $debug, $Debuglog;
        $edited_Blog =& $this->get_Blog();
        if (!$edited_Blog->get_setting('allow_subscriptions')) {
            // Subscriptions not enabled!
            return;
        }
        if ($display) {
            echo "<div class=\"panelinfo\">\n";
            echo '<h3>', T_('Notifying subscribed users...'), "</h3>\n";
        }
        // Create condition to not select already notified modertor users
        $except_users_condition = empty($already_notified) ? '' : ' AND sub_user_ID NOT IN ( ' . implode(',', $already_notified) . ' )';
        // Get list of users who want to be notfied:
        // TODO: also use extra cats/blogs??
        $sql = 'SELECT DISTINCT sub_user_ID
							FROM T_subscriptions
						WHERE sub_coll_ID = ' . $this->get_blog_ID() . '
							AND sub_items <> 0' . $except_users_condition;
        $notify_users = $DB->get_col($sql);
        if (empty($notify_users)) {
            // No-one to notify:
            if ($display) {
                echo '<p>', T_('No-one to notify.'), "</p>\n</div>\n";
            }
            return false;
        }
        // Load all users who will be notified
        $UserCache =& get_UserCache();
        $UserCache->load_list($notify_users);
        /*
         * We have a list of user IDs to notify:
         */
        $this->get_creator_User();
        // Load a list with the blocked emails in cache
        load_blocked_emails($notify_users);
        // Send emails:
        $cache_by_locale = array();
        foreach ($notify_users as $user_ID) {
            $notify_User = $UserCache->get_by_ID($user_ID, false, false);
            if (empty($notify_User)) {
                // skip invalid users
                continue;
            }
            $notify_email = $notify_User->get('email');
            if (empty($notify_email)) {
                // skip users with empty email address
                continue;
            }
            $notify_locale = $notify_User->get('locale');
            $notify_user_Group = $notify_User->get_Group();
            $notify_full = $notify_user_Group->check_perm('post_subscription_notif', 'full');
            if (!isset($cache_by_locale[$notify_locale])) {
                // No message for this locale generated yet:
                locale_temp_switch($notify_locale);
                $cache_by_locale[$notify_locale]['subject']['short'] = sprintf(T_('%s created a new post in blog "%s"'), $this->creator_User->get('login'), $edited_Blog->get('shortname'));
                $cache_by_locale[$notify_locale]['subject']['full'] = sprintf(T_('[%s] New post: "%s"'), $edited_Blog->get('shortname'), $this->get('title'));
                locale_restore_previous();
            }
            $email_template_params = array('locale' => $notify_locale, 'notify_full' => $notify_full, 'Item' => $this, 'recipient_User' => $notify_User, 'notify_type' => 'subscription');
            if ($display) {
                echo T_('Notifying:') . $notify_email . "<br />\n";
            }
            if ($debug >= 2) {
                $message_content = mail_template('post_new', 'txt', $email_template_params);
                echo "<p>Sending notification to {$notify_email}:<pre>{$message_content}</pre>";
            }
            $subject_type = $notify_full ? 'full' : 'short';
            send_mail_to_User($user_ID, $cache_by_locale[$notify_locale]['subject'][$subject_type], 'post_new', $email_template_params);
            blocked_emails_memorize($notify_User->email);
        }
        blocked_emails_display();
        if ($display) {
            echo '<p>', T_('Done.'), "</p>\n</div>\n";
        }
    }
Example #11
0
/**
 * Send account validation email with a permanent validation link
 *
 * @param array user ids to send validation email
 * @param boolean true if this email is an account activation reminder, false if the account status was changed right now
 * @return integer the number of successfully sent emails
 */
function send_easy_validate_emails($user_ids, $is_reminder = true, $email_changed = false)
{
    global $UserSettings, $servertimenow, $secure_htsrv_url;
    $UserCache =& get_UserCache();
    if (isset($GLOBALS['messaging_Module'])) {
        // Get already received messages for each recepient user
        $already_received_messages = get_users_unread_threads($user_ids);
    }
    $cache_by_locale = array();
    $email_sent = 0;
    foreach ($user_ids as $user_ID) {
        // Iterate through user ids and send account activation reminder to all user
        $User = $UserCache->get_by_ID($user_ID, false);
        if (!$User) {
            // user not exists
            continue;
        }
        if (!$User->check_status('can_be_validated')) {
            // User is validated or it is not allowed to be validated
            continue;
        }
        if ($is_reminder && !$UserSettings->get('send_activation_reminder')) {
            // This is an activation reminder, but user wouldn't like to receive this kind of emails
            continue;
        }
        if (mail_is_blocked($User->get('email'))) {
            // prevent trying to send an email to a blocked email address
            continue;
        }
        $notify_locale = $User->get('locale');
        $reminder_key = $UserSettings->get('last_activation_reminder_key', $User->ID);
        if (empty($reminder_key) || $email_changed) {
            // reminder key was not generated yet, or the user email address was changed and we need a new one, to invalidate old requests
            $reminder_key = generate_random_key(32);
            $UserSettings->set('last_activation_reminder_key', $reminder_key, $User->ID);
        }
        if (!isset($cache_by_locale[$notify_locale])) {
            // No subject for this locale generated yet:
            locale_temp_switch($notify_locale);
            $cache_by_locale[$notify_locale]['subject'] = T_('Activate your account: $login$');
            locale_restore_previous();
        }
        $email_template_params = array('locale' => $notify_locale, 'status' => $User->get('status'), 'reminder_key' => $reminder_key, 'is_reminder' => $is_reminder);
        if (!empty($already_received_messages[$User->ID])) {
            // add already received message list to email body
            $email_template_params['already_received_messages'] = $already_received_messages[$User->ID];
        }
        // Update notification sender's info from General settings
        $User->update_sender(true);
        if (send_mail_to_User($User->ID, $cache_by_locale[$notify_locale]['subject'], 'account_activate', $email_template_params, true)) {
            // save corresponding user settings right after the email was sent, to prevent not saving if an eroor occurs
            $email_sent++;
            // Set last remind activation email date and increase sent reminder emails number in UserSettings
            $UserSettings->set('last_activation_email', date2mysql($servertimenow), $User->ID);
            if ($is_reminder) {
                $reminder_sent_to_user = $UserSettings->get('activation_reminder_count', $User->ID);
                $UserSettings->set('activation_reminder_count', $reminder_sent_to_user + 1, $User->ID);
            }
            $UserSettings->dbupdate();
        }
    }
    return $email_sent;
}
if (empty($users_to_remind_ids)) {
    // There is no user to remind after we have filtered out those ussers who haven't logged in since a long time
    $result_message = T_('It was not necessary to send any reminder!');
    return 1;
}
// Set TRUE to use gender settings from back office
global $is_admin_page;
$is_admin_page = true;
// Get all those user threads and their recipients where the corresponding users have unread messages
$unread_threads = get_users_unread_threads($users_to_remind_ids, NULL, 'array', 'html');
// Get unread thread urls
list($threads_link) = get_messages_link_to();
$reminder_sent = 0;
foreach ($users_to_remind_ids as $user_ID) {
    // send reminder email
    $email_template_params = array('unread_threads' => $unread_threads[$user_ID], 'threads_link' => $threads_link);
    $notify_User = $UserCache->get_by_ID($user_ID);
    // Change locale here to localize the email subject and content
    locale_temp_switch($notify_User->get('locale'));
    if (send_mail_to_User($user_ID, T_('You have unread messages!'), 'private_messages_unread_reminder', $email_template_params)) {
        // Update users last unread message reminder timestamp
        $UserSettings->set('last_unread_messages_reminder', date2mysql($servertimenow), $user_ID);
        // save UserSettings after each email, because the cron task mail fail and users won't be updated!
        $UserSettings->dbupdate();
        $reminder_sent++;
    }
    locale_restore_previous();
}
$result_message = sprintf(T_('%d reminder emails were sent!'), $reminder_sent);
return 1;
/* ok */
 /**
  * Send one email
  *
  * @param integer User ID
  * @param string Email address
  * @param string Mode: 'test' - to send test email newsletter
  * @return boolean TRUE on success
  */
 function send_email($user_ID, $email_address = '', $mode = '')
 {
     $newsletter_params = array('include_greeting' => false, 'message_html' => $this->get('email_html'), 'message_text' => $this->get('email_text'));
     if ($mode == 'test') {
         // Send a test newsletter
         global $current_User;
         $newsletter_params['boundary'] = 'b2evo-' . md5(rand());
         $headers = array('Content-Type' => 'multipart/mixed; boundary="' . $newsletter_params['boundary'] . '"');
         $UserCache =& get_UserCache();
         if ($test_User =& $UserCache->get_by_ID($user_ID, false, false)) {
             // Send a test email only when test user exists
             $message = mail_template('newsletter', 'auto', $newsletter_params, $test_User);
             return send_mail($email_address, NULL, $this->get('email_title'), $message, NULL, NULL, $headers);
         } else {
             // No test user found
             return false;
         }
     } else {
         // Send a newsletter to real user
         return send_mail_to_User($user_ID, $this->get('email_title'), 'newsletter', $newsletter_params, false, array(), $email_address);
     }
 }