Beispiel #1
0
function river_activity_3C_bday_mailer($hook, $entity_type, $returnvalue, $params)
{
    $bday = elgg_get_plugin_setting('birth_day', 'river_activity_3C');
    elgg_set_ignore_access(true);
    $siteurl = elgg_get_site_entity()->url;
    $sitename = elgg_get_site_entity()->name;
    $siteemail = elgg_get_site_entity()->email;
    $from = $sitename . ' <' . $siteemail . '>';
    $month = date('m', strtotime("now"));
    $options = array('metadata_names' => 'BD_month', 'metadata_values' => $month, 'types' => 'user', 'limit' => false, 'full_view' => false, 'pagination' => false);
    $bd_users = new ElggBatch('elgg_get_entities_from_metadata', $options);
    $bd_today = date('j, F', strtotime('now'));
    foreach ($bd_users as $bd_user) {
        $bd_name = $bd_user->name;
        $bd_email = $bd_user->email;
        $bd_day = date('j, F', strtotime($bd_user->{$bday}));
        if ($bd_day == $bd_today) {
            if ($bd_email) {
                $message = elgg_echo('river_activity_3C:bday_message', array($bd_name, $bd_day, $sitename, $siteurl));
                elgg_send_email($from, $bd_email, elgg_echo('river_activity_3C:bday_message:subject'), $message);
                $result = elgg_echo("river_activity_3C:bday_mailer_cron_true");
            } else {
                $result = elgg_echo("river_activity_3C:bday_mailer_cron_false");
            }
        }
    }
    elgg_set_ignore_access(false);
    return $returnvalue . $result;
}
Beispiel #2
0
 function testElggSendEmailBypass()
 {
     _elgg_services()->hooks->registerHandler('email', 'system', [$this, 'handleEmailHookTrue']);
     $this->assertTrue(elgg_send_email("*****@*****.**", "*****@*****.**", "Hello", "World", ['foo' => 1]));
     _elgg_services()->hooks->unregisterHandler('email', 'system', [$this, 'handleEmailHookTrue']);
     $this->assertNull($this->mailer->getLastMessage());
 }
Beispiel #3
0
function elgg_update_services_notify_admin($message)
{
    $site = elgg_get_site_entity();
    if ($site && isset($site->email)) {
        $mailfrom = $site->email;
    } else {
        $mailfrom = 'noreply@' . $site->getDomain();
    }
    $mailto = elgg_get_plugin_setting("notify_mail_address", 'elgg_update_services');
    if ($mailto) {
        elgg_send_email($mailfrom, $mailto, elgg_echo('elgg_update_services:subject'), $message);
    }
}
Beispiel #4
0
function spam_login_filter_notify_admin($blockedEmail, $blockedIp, $reason)
{
    if (elgg_get_plugin_setting('notify_by_mail', 'spam_login_filter') == "yes") {
        //Notify spam tentative to administrator
        $site = elgg_get_site_entity();
        if ($site && isset($site->email)) {
            $from = $site->email;
        } else {
            $from = 'noreply@' . get_site_domain($site->guid);
        }
        $message = sprintf(elgg_echo('spam_login_filter:notify_message'), $blockedEmail, $blockedIp, $reason);
        $to = elgg_get_plugin_setting('notify_mail_address', 'spam_login_filter');
        if (!is_email_address($to)) {
            return;
        }
        elgg_send_email($from, $to, elgg_echo('spam_login_filter:notify_subject'), $message);
    }
}
Beispiel #5
0
/**
 * Request user validation email.
 * Send email out to the address and request a confirmation.
 *
 * @param int  $user_guid       The user's GUID
 * @param bool $admin_requested Was it requested by admin
 * @return mixed
 */
function uservalidationbyadmin_request_validation($user_guid, $admin_requested = FALSE)
{
    $site = elgg_get_site_entity();
    if ($site && $site->email) {
        $from = $site->email;
    } else {
        $from = 'noreply@' . get_site_domain($site->guid);
    }
    $user_guid = (int) $user_guid;
    $user = get_entity($user_guid);
    //notify admins
    if ($user && $user instanceof ElggUser) {
        // Work out validate link
        $code = uservalidationbyadmin_generate_code($user_guid, $user->email);
        $link = "{$site->url}uservalidationbyadmin/confirm?u={$user_guid}&c={$code}";
        // IP detection
        $ip_address = $_SERVER['REMOTE_ADDR'];
        /*$geoloc = "https://secure.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress=".$ip_address;
        		$geotags = get_meta_tags($geoloc);
        		$geocountry = $geotags['country'];
        		$georegion = $geotags['region'];
        		$geocity = $geotags['city'];
        		$geocertainty = $geotags['certainty'];*/
        $geostring = $ip_address;
        //." ; ".$geocountry." ; ".$georegion." ; ".$geocity." ; ".$geocertainty;
        // Send validation email
        $subject = elgg_echo('email:validate:subject', array($user->name, $site->name));
        $body = elgg_echo('email:validate:body', array($user->name, $user->email, $ip_address, $geostring, $link, $site->name, $site->url));
        $emails = elgg_get_plugin_setting('emails', 'uservalidationbyadmin');
        $admin_mails = explode(",", $emails);
        $sent_total = 0;
        foreach ($admin_mails as $mail) {
            if (elgg_send_email($from, $mail, $subject, $body)) {
                $sent_total++;
            }
        }
        // Atleast 1 mail sent
        if ($sent_total > 0 && !$admin_requested) {
            system_message(elgg_echo('uservalidationbyadmin:registerok'));
        }
        return $result;
    }
    return FALSE;
}
Beispiel #6
0
/**
 * Send password for new user who is registered using facebook connect
 *
 * @param $email
 * @param $name
 * @param $username
 * @param $password
 */
function send_user_password_mail($email, $name, $username, $password)
{
    $site = elgg_get_site_entity();
    $email = trim($email);
    // send out other email addresses
    if (!is_email_address($email)) {
        return false;
    }
    $message = elgg_echo('facebook_connect:email:body', array($name, $site->name, $site->url, $username, $email, $password, $site->name, $site->url));
    $subject = elgg_echo('facebook_connect:email:subject', array($name));
    // create the from address
    $site = get_entity($site->guid);
    if ($site && isset($site->email)) {
        $from = $site->email;
    } else {
        $from = 'noreply@' . get_site_domain($site->guid);
    }
    elgg_send_email($from, $email, $subject, $message);
}
Beispiel #7
0
function group_tools_invite_email(ElggGroup $group, $email, $text = "", $resend = false)
{
    $result = false;
    if (!empty($group) && $group instanceof ElggGroup && !empty($email) && is_email_address($email) && ($loggedin_user = elgg_get_logged_in_user_entity())) {
        // get site secret
        $site_secret = get_site_secret();
        // generate invite code
        $invite_code = md5($site_secret . $email . $group->getGUID());
        if (!group_tools_check_group_email_invitation($invite_code, $group->getGUID()) || $resend) {
            // make site email
            $site = elgg_get_site_entity();
            if (!empty($site->email)) {
                if (!empty($site->name)) {
                    $site_from = $site->name . " <" . $site->email . ">";
                } else {
                    $site_from = $site->email;
                }
            } else {
                // no site email, so make one up
                if (!empty($site->name)) {
                    $site_from = $site->name . " <noreply@" . get_site_domain($site->getGUID()) . ">";
                } else {
                    $site_from = "noreply@" . get_site_domain($site->getGUID());
                }
            }
            if (!$resend) {
                // register invite with group
                $group->annotate("email_invitation", $invite_code, ACCESS_LOGGED_IN, $group->getGUID());
            }
            // make subject
            $subject = elgg_echo("group_tools:groups:invite:email:subject", array($group->name));
            // make body
            $body = elgg_echo("group_tools:groups:invite:email:body", array($loggedin_user->name, $group->name, $site->name, $text, $site->name, elgg_get_site_url() . "register", elgg_get_site_url() . "groups/invitations/?invitecode=" . $invite_code, $invite_code));
            $result = elgg_send_email($site_from, $email, $subject, $body);
        } else {
            $result = null;
        }
    }
    return $result;
}
Beispiel #8
0
         continue;
     }
     if ($user->guid == elgg_get_logged_in_user_guid()) {
         $error++;
         continue;
     }
     if ($user->isBanned()) {
         $banned++;
     } else {
         if ($user->ban(get_input('approval_message', 'admin decision'))) {
             create_annotation($user->guid, 'ban', get_input('approval_message', true), '', elgg_get_logged_in_user_guid(), ACCESS_PUBLIC);
             $subject = elgg_echo("db_explorer:ban:email:subject");
             if (get_input('notify_users', false)) {
                 $body = elgg_view('framework/db_explorer/notifications/ban', array('entity' => $user, 'setter' => elgg_get_logged_in_user_entity(), 'note' => get_input('notify_users_message')));
                 try {
                     elgg_send_email(elgg_get_site_entity()->email, $user->email, $subject, $body);
                 } catch (Exception $e) {
                     register_error($e->getMessage());
                 }
             }
             $success++;
         } else {
             $error++;
         }
     }
 }
 $msg[] = elgg_echo('db_explorer:success:ban', array((int) $success, $count));
 if ($banned > 0) {
     $msg[] = elgg_echo('db_explorer:error:already_banned', array($banned));
 }
 if ($error_nouser > 0) {
Beispiel #9
0
<?php

/**
 * Send verification email to user
 *
*/
$guids = get_input('user_guids');
//$guid = $guid[0];
//get the unvalidated user
access_show_hidden_entities(TRUE);
foreach ($guids as $guid) {
    $user = get_entity($guid);
    if ($user) {
        $code = uservalidationbyadmin_generate_code($user->guid, $user->email);
        $validate = elgg_view('output/confirmlink', array('confirm' => elgg_echo('uservalidationbyadmin:confirm_validate_user', array($user->username)), 'href' => "uservalidationbyadmin/validate?user_guids[]={$user->guid}&code={$code}", 'text' => elgg_echo('uservalidationbyadmin:admin:validate')));
        $validateLink = array_pop(explode('href=', $validate));
        $index = strpos($validateLink, 'rel=') - 3;
        $validateLink = substr($validateLink, 1, $index);
        //build validation email
        $subject = elgg_echo('uservalidationbyadmin:email:validate:header');
        $body = elgg_echo('uservalidationbyadmin:email:validate:body');
        $body .= "\r\n" . $validateLink;
        $options = array("to" => $to, "subject" => $subject, "html_message" => $body, "plaintext_message" => $body);
        if (elgg_send_email('*****@*****.**', $user->email, $subject, $body)) {
            system_message(elgg_echo('uservalidationbyadmin:email:validate:sent'));
        } else {
            register_error(elgg_echo('uservalidationbyadmin:email:validate:error'));
        }
    }
}
 public function sendEmail($action, $email, $guid)
 {
     switch ($action) {
         case 'activate':
             $email = sanitise_string($email);
             $user = get_entity($guid);
             if (!$user) {
                 register_error(elgg_echo('email:activate:userNotFound'));
                 return false;
             }
             if (!$user->deactivated) {
                 register_error(elgg_echo('email:activate:userActivated'));
                 return false;
             }
             if (!$this->validateEmail($email)) {
                 register_error(elgg_echo('email:activate:invalidEmail'));
                 return false;
             }
             //construct the email
             $from = "*****@*****.**";
             $to = $email;
             $subject = elgg_echo('activate:heading');
             $code = $this->generateCode($user->guid, $email, date('Ymd'));
             $link = "{$this->site->url}usermgmt/activation?u={$user->guid}&c={$code}";
             $message = elgg_echo('email:activate:body', array($user->name, $link, $this->site->name, $this->{$site}->url));
             if (elgg_send_email($from, $to, $subject, $message)) {
                 return true;
             }
             register_error(elgg_echo('email:activate:error'));
             return false;
             break;
     }
 }
Beispiel #11
0
    register_error(elgg_echo('registration:notemail'));
    forward(REFERER);
}
// try to find a registration
$registrations = elgg_get_entities_from_metadata(['type' => 'object', 'subtype' => EventRegistration::SUBTYPE, 'owner_guid' => $entity->getGUID(), 'limit' => 1, 'metadata_name_value_pairs' => ['name' => 'email', 'value' => $email, 'case_sensitive' => false]]);
if (empty($registrations)) {
    register_error(elgg_echo('event_manager:action:unsubscribe:error:no_registration'));
    forward(REFERER);
}
$registration = $registrations[0];
// generate unsubscribe code
$unsubscribe_code = event_manager_create_unsubscribe_code($registration, $entity);
$unsubscribe_link = elgg_normalize_url("events/unsubscribe/confirm/{$registration->getGUID()}/" . $unsubscribe_code);
// make a message with further instructions
$subject = elgg_echo('event_manager:unsubscribe:confirm:subject', [$entity->title]);
$message = elgg_echo('event_manager:unsubscribe:confirm:message', [$registration->name, $entity->title, $entity->getURL(), $unsubscribe_link]);
// nice e-mail addresses
$site = elgg_get_site_entity();
if ($site->email) {
    $from = $site->name . " <{$site->email}>";
} else {
    $from = $site->name . " <noreply@{$site->getDomain()}>";
}
$to = $registration->name . " <{$registration->email}>";
if (!elgg_send_email($from, $to, $subject, $message)) {
    register_error(elgg_echo('event_manager:action:unsubscribe:error:mail'));
    forward(REFERER);
}
elgg_clear_sticky_form('event_unsubscribe');
system_message(elgg_echo('event_manager:action:unsubscribe:success'));
forward($entity->getURL());
Beispiel #12
0
/**
 * Send registration validation email
 * 
 * @param Event      $event  event
 * @param ElggEntity $entity object or user to send mail to
 * 
 * @return void
 */
function event_manager_send_registration_validation_email(Event $event, ElggEntity $entity)
{
    $subject = elgg_echo("event_manager:registration:confirm:subject", array($event->title));
    $message = elgg_echo("event_manager:registration:confirm:message", array($entity->name, $event->title, event_manager_get_registration_validation_url($event->getGUID(), $entity->getGUID())));
    $site = elgg_get_site_entity();
    // send confirmation mail
    if (elgg_instanceof($entity, "user")) {
        notify_user($entity->getGUID(), $event->getOwnerGUID(), $subject, $message, null, "email");
    } else {
        $from = $site->email;
        if (empty($from)) {
            $from = "noreply@" . $site->getDomain();
        }
        if (!empty($site->name)) {
            $site_name = $site->name;
            if (strstr($site_name, ',')) {
                $site_name = '"' . $site_name . '"';
                // Protect the name with quotations if it contains a comma
            }
            $site_name = '=?UTF-8?B?' . base64_encode($site_name) . '?=';
            // Encode the name. If may content nos ASCII chars.
            $from = $site_name . " <" . $from . ">";
        }
        elgg_send_email($from, $entity->email, $subject, $message);
    }
}
Beispiel #13
0
 /**
  * Notifies an user of the RSVP
  *
  * @param string $type type of the RSVP
  * @param string $to   guid of the user
  *
  * @return void
  */
 public function notifyOnRsvp($type, $to = null)
 {
     $ia = elgg_set_ignore_access(true);
     if ($to === null) {
         $to = elgg_get_logged_in_user_guid();
     }
     $to_entity = get_entity($to);
     if (empty($to_entity)) {
         elgg_set_ignore_access($ia);
         return;
     }
     // can we make nice links in the emails
     $html_email_handler_enabled = elgg_is_active_plugin("html_email_handler");
     // do we have a registration link
     $registrationLink = "";
     $unsubscribeLink = "";
     if ($type == EVENT_MANAGER_RELATION_ATTENDING) {
         if ($this->registration_needed) {
             $link = elgg_get_site_url() . 'events/registration/view/?guid=' . $this->getGUID() . '&u_g=' . $to . '&k=' . md5($this->time_created . get_site_secret() . $to);
             $registrationLink = PHP_EOL . PHP_EOL;
             $registrationLink .= elgg_echo('event_manager:event:registration:notification:program:linktext');
             $registrationLink .= PHP_EOL . PHP_EOL;
             if ($html_email_handler_enabled) {
                 $registrationLink .= elgg_view("output/url", array("text" => $link, "href" => $link));
             } else {
                 $registrationLink .= $link;
             }
         }
         if ($this->register_nologin) {
             $link = elgg_get_site_url() . "events/unsubscribe/" . $this->getGUID() . "/" . elgg_get_friendly_title($this->title) . "?e=" . $to_entity->email;
             $unsubscribeLink = PHP_EOL . PHP_EOL;
             $unsubscribeLink .= elgg_echo('event_manager:event:registration:notification:unsubscribe:linktext');
             $unsubscribeLink .= PHP_EOL . PHP_EOL;
             if ($html_email_handler_enabled) {
                 $unsubscribeLink .= elgg_view("output/url", array("text" => $link, "href" => $link));
             } else {
                 $unsubscribeLink .= $link;
             }
         }
     }
     // make the event title for in the e-mail
     if ($html_email_handler_enabled) {
         $event_title_link = elgg_view("output/url", array("text" => $this->title, "href" => $this->getURL()));
     } else {
         $event_title_link = $this->title;
     }
     // notify the owner of the event
     $this->notifyOwnerOnRSVP($type, $to_entity, $event_title_link, $registrationLink);
     // notify the attending user
     $user_subject = elgg_echo('event_manager:event:registration:notification:user:subject');
     $user_message = elgg_echo('event_manager:event:registration:notification:user:text:' . $type, array($to_entity->name, $event_title_link));
     $user_message .= $registrationLink;
     $user_message .= $unsubscribeLink;
     if ($to_entity instanceof ElggUser) {
         // use notification system for real users
         notify_user($to, $this->getOwnerGUID(), $user_subject, $user_message);
     } else {
         // send e-mail for non users
         $to_email = $to_entity->name . "<" . $to_entity->email . ">";
         $site = elgg_get_site_entity($this->site_guid);
         if ($site->email) {
             if ($site->name) {
                 $site_from = $site->name . " <" . $site->email . ">";
             } else {
                 $site_from = $site->email;
             }
         } else {
             // no site email, so make one up
             if ($site->name) {
                 $site_from = $site->name . " <noreply@" . $site->getDomain() . ">";
             } else {
                 $site_from = "noreply@" . $site->getDomain();
             }
         }
         elgg_send_email($site_from, $to_email, $user_subject, $user_message);
     }
     elgg_set_ignore_access($ia);
 }
Beispiel #14
0
 public function send_($from, $to, $subject, $body)
 {
     return \elgg_send_email($from, $to, $subject, $body);
 }
Beispiel #15
0
/**
 * Invite a new user by email to a group
 *
 * @param ElggGroup $group  the group to be invited for
 * @param string    $email  the email address to be invited
 * @param string    $text   (optional) extra text in the invitation
 * @param boolean   $resend should existing invitations be resend
 *
 * @return boolean|NULL true is invited, false on failure, null when already send
 */
function group_tools_invite_email(ElggGroup $group, $email, $text = "", $resend = false)
{
    $result = false;
    $loggedin_user = elgg_get_logged_in_user_entity();
    if (!empty($group) && $group instanceof ElggGroup && !empty($email) && is_email_address($email) && !empty($loggedin_user)) {
        // generate invite code
        $invite_code = group_tools_generate_email_invite_code($group->getGUID(), $email);
        if (!empty($invite_code)) {
            $found_group = group_tools_check_group_email_invitation($invite_code, $group->getGUID());
            if (empty($found_group) || $resend) {
                // make site email
                $site = elgg_get_site_entity();
                if (!empty($site->email)) {
                    if (!empty($site->name)) {
                        $site_from = $site->name . " <" . $site->email . ">";
                    } else {
                        $site_from = $site->email;
                    }
                } else {
                    // no site email, so make one up
                    if (!empty($site->name)) {
                        $site_from = $site->name . " <noreply@" . get_site_domain($site->getGUID()) . ">";
                    } else {
                        $site_from = "noreply@" . get_site_domain($site->getGUID());
                    }
                }
                if (empty($found_group)) {
                    // register invite with group
                    $group->annotate("email_invitation", $invite_code . "|" . $email, ACCESS_LOGGED_IN, $group->getGUID());
                }
                // make subject
                $subject = elgg_echo("group_tools:groups:invite:email:subject", array($group->name));
                // make body
                $body = elgg_echo("group_tools:groups:invite:email:body", array($loggedin_user->name, $group->name, $site->name, $text, $site->name, elgg_get_site_url() . "register?group_invitecode=" . $invite_code, elgg_get_site_url() . "groups/invitations/?invitecode=" . $invite_code, $invite_code));
                $params = array("group" => $group, "inviter" => $loggedin_user, "invitee" => $email);
                $body = elgg_trigger_plugin_hook("invite_notification", "group_tools", $params, $body);
                $result = elgg_send_email($site_from, $email, $subject, $body);
            } else {
                $result = null;
            }
        }
    }
    return $result;
}
Beispiel #16
0
function subsite_manager_subsite_invite_email($email, $message = "")
{
    $result = false;
    if (subsite_manager_on_subsite() && !empty($email) && ($user = elgg_get_logged_in_user_entity()) && $user->isAdmin()) {
        $site = elgg_get_site_entity();
        $parent_site = $site->getOwnerEntity();
        $registration_link = $site->url . "register";
        if (get_config("disable_registration") === true) {
            $registration_link = $parent_site->url . "register";
        }
        // make mail
        $subject = elgg_echo("subsite_manager:subsite_admin:invite:new_user:subject", array($site->name));
        $body = elgg_echo("subsite_manager:subsite_admin:invite:new_user:message", array($user->name, $site->name, $parent_site->name, $message, $registration_link));
        // make site email
        if (!empty($site->email)) {
            if (!empty($site->name)) {
                $site_from = $site->name . " <" . $site->email . ">";
            } else {
                $site_from = $site->email;
            }
        } else {
            // no site email, so make one up
            if (!empty($site->name)) {
                $site_from = $site->name . " <noreply@" . get_site_domain($site->getGUID()) . ">";
            } else {
                $site_from = "noreply@" . get_site_domain($site->getGUID());
            }
        }
        $result = elgg_send_email($site_from, $email, $subject, $body);
    }
    return $result;
}
Beispiel #17
0
/**
 * Send a workflow notification for a question to the phase owner
 * 
 * @param ElggQuestion $question the question the notification is about
 * @param QuesionsWorkflowPhase $phase the phase of the workflow
 *
 * @return bool
 */
function questions_send_workflow_notification(ElggQuestion $question, QuestionsWorkflowPhase $phase)
{
    return elgg_send_email(questions_get_site_email(), $phase->email, elgg_echo("questions:workflow:email:subject", array($question->title)), elgg_echo("questions:workflow:email:body", array($question->getWorkflowURL())));
}
Beispiel #18
0
/**
 * Send registration validation email
 *
 * @param Event      $event  event
 * @param ElggEntity $entity object or user to send mail to
 *
 * @return void
 */
function event_manager_send_registration_validation_email(Event $event, ElggEntity $entity)
{
    $subject = elgg_echo('event_manager:registration:confirm:subject', [$event->title]);
    $message = elgg_echo('event_manager:registration:confirm:message', [$entity->name, $event->title, event_manager_get_registration_validation_url($event->getGUID(), $entity->getGUID())]);
    $site = elgg_get_site_entity();
    // send confirmation mail
    if (elgg_instanceof($entity, 'user')) {
        notify_user($entity->getGUID(), $event->getOwnerGUID(), $subject, $message, null, 'email');
    } else {
        $from = $site->email;
        if (empty($from)) {
            $from = 'noreply@' . $site->getDomain();
        }
        if (!empty($site->name)) {
            $site_name = $site->name;
            if (strstr($site_name, ',')) {
                $site_name = '"' . $site_name . '"';
                // Protect the name with quotations if it contains a comma
            }
            $from = $site_name . " <" . $from . ">";
        }
        elgg_send_email($from, $entity->email, $subject, $message);
    }
}
Beispiel #19
0
$message = preg_replace("/(\r\n|\r)/", "\n", $message);
// Convert to unix line endings in body
$message = wordwrap($message);
$subject = get_input('subject');
$offset = (int) get_input('offset', 0);
$limit = 9999;
if (empty($subject) || empty($message)) {
    register_error(elgg_echo("webgalli_mails:requiredfieldsempty"));
    forward($_SERVER['HTTP_REFERER']);
} else {
    $users = get_entities('user', '', 0, '', $limit, $offset);
    if ($users) {
        // create the from address
        $site = get_entity($CONFIG->site_guid);
        if ($site && isset($site->email)) {
            $from = $site->email;
        } else {
            $from = 'noreply@' . get_site_domain($CONFIG->site_guid);
        }
        foreach ($users as $u) {
            $to = $u->email;
            $action = elgg_send_email($from, $to, $subject, $message);
        }
        if ($action) {
            system_message(elgg_echo('webgalli_mails:mailssent'));
        } else {
            register_error(elgg_echo("webgalli_mails:mailfailure"));
        }
    }
}
forward($_SERVER['HTTP_REFERER']);
Beispiel #20
0
/**
 * Send an email notification
 *
 * @param string $hook   Hook name
 * @param string $type   Hook type
 * @param bool   $result Has anyone sent a message yet?
 * @param array  $params Hook parameters
 * @return bool
 * @access private
 */
function _elgg_send_email_notification($hook, $type, $result, $params)
{
    if ($result === true) {
        // assume someone else already sent the message
        return;
    }
    /* @var \Elgg\Notifications\Notification $message */
    $message = $params['notification'];
    $sender = $message->getSender();
    $recipient = $message->getRecipient();
    if (!$sender) {
        return false;
    }
    if (!$recipient || !$recipient->email) {
        return false;
    }
    $to = $recipient->email;
    $site = elgg_get_site_entity();
    // If there's an email address, use it - but only if it's not from a user.
    if (!$sender instanceof \ElggUser && $sender->email) {
        $from = $sender->email;
    } else {
        if ($site->email) {
            $from = $site->email;
        } else {
            // If all else fails, use the domain of the site.
            $from = 'noreply@' . $site->getDomain();
        }
    }
    return elgg_send_email($from, $to, $message->subject, $message->body, $params);
}
    if (!$group_invite) {
        $new = true;
        $group_invite = groups_invite_create_group_invite($email);
    }
    if (!$new && !$resend) {
        $skipped++;
        continue;
    }
    add_entity_relationship($group_invite->guid, 'invited_by', $inviter->guid);
    add_entity_relationship($group_invite->guid, 'invited_to', $group->guid);
    $link = elgg_trigger_plugin_hook('registration_link', 'site', ['email' => $email, 'friend_guid' => $inviter->guid], elgg_normalize_url('register'));
    $site = elgg_get_site_entity();
    $notification_params = array('inviter' => $inviter->getDisplayName(), 'group' => $group->getDisplayName(), 'site' => $site->getDisplayName(), 'message' => $message ? elgg_echo('groups:invite:notify:message', array($message)) : '', 'link' => $link);
    $subject = elgg_echo('groups:invite:notify:subject', array($group->getDisplayName()));
    $body = elgg_echo('groups:invite:notify:body', $notification_params);
    $sent = elgg_send_email($site->email, $email, $subject, $body);
    if ($sent) {
        $invited++;
    } else {
        $error++;
    }
}
foreach ($invitee_guids as $invitee_guid) {
    if (!$invitee_guid) {
        continue;
    }
    $invitee = get_entity($invitee_guid);
    if (!$invitee) {
        $error++;
        continue;
    }
Beispiel #22
0
/**
 * Process the newsletter for a given guid
 *
 * @param int $entity_guid guid of the newsletter
 *
 * @return void
 */
function newsletter_process($entity_guid)
{
    $entity_guid = sanitise_int($entity_guid, false);
    if (empty($entity_guid)) {
        return;
    }
    // ignore access
    $ia = elgg_set_ignore_access(true);
    $entity = get_entity($entity_guid);
    // is this a Newsletter
    if (!elgg_instanceof($entity, 'object', Newsletter::SUBTYPE)) {
        elgg_set_ignore_access($ia);
        return;
    }
    $logging = ['start_time' => time()];
    $site = elgg_get_site_entity();
    $container = $entity->getContainerEntity();
    $dbprefix = elgg_get_config('dbprefix');
    // set newsletter status to sending
    $entity->status = 'sending';
    $entity->start_time = $logging['start_time'];
    // get the recipients
    // basic set of user selection options
    $basic_user_options = ['type' => 'user', 'limit' => false, 'selects' => ['ue.email'], 'joins' => ['JOIN ' . $dbprefix . 'users_entity ue ON e.guid = ue.guid'], 'callback' => 'newsletter_user_row_to_subscriber_info'];
    // include users without settings
    if (newsletter_include_existing_users()) {
        // yes, so exclude blocked
        $basic_user_options['wheres'] = ["(e.guid NOT IN (SELECT guid_one\n\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\tWHERE relationship = '" . NewsletterSubscription::GENERAL_BLACKLIST . "'\n\t\t\t\tAND guid_two = " . $site->getGUID() . ")\n\t\t\t)", "(e.guid NOT IN (SELECT guid_one\n\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\tWHERE relationship = '" . NewsletterSubscription::BLACKLIST . "'\n\t\t\t\tAND guid_two = " . $container->getGUID() . ")\n\t\t\t)"];
    } else {
        // no, so subscription is required
        $basic_user_options['wheres'] = ["(e.guid IN (SELECT guid_one\n\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\tWHERE relationship = '" . NewsletterSubscription::SUBSCRIPTION . "'\n\t\t\t\tAND guid_two = " . $container->getGUID() . ")\n\t\t\t)"];
    }
    $filtered_recipients = ['users' => [], 'emails' => []];
    $recipients = $entity->getRecipients();
    if (empty($recipients)) {
        // no recipients so report error
        $entity->status = 'sent';
        return false;
    }
    // recipients is an array consisting of:
    // - user_guids: 	individual users
    // - group_guids:	groups to send the content to
    // - emails:		individual email addresses
    // - subscribers:	(int) whether or not to add the subscribers of the container
    // - members:		(int) whether or not to aad the member of the container
    $user_guids = elgg_extract('user_guids', $recipients);
    if (!empty($user_guids)) {
        if (!is_array($user_guids)) {
            $user_guids = [$user_guids];
        }
        // convert to a format we can use
        $options = $basic_user_options;
        $options['wheres'][] = '(e.guid IN (' . implode(',', $user_guids) . '))';
        $users = elgg_get_entities($options);
        if (!empty($users)) {
            $new_users = [];
            foreach ($users as $user) {
                $new_users[$user['guid']] = $user['email'];
            }
            $filtered_recipients['users'] += $new_users;
        }
    }
    $group_guids = elgg_extract('group_guids', $recipients);
    if (!empty($group_guids)) {
        if (!is_array($group_guids)) {
            $group_guids = [$group_guids];
        }
        $options = $basic_user_options;
        $options['joins'][] = 'JOIN ' . $dbprefix . 'entity_relationships r ON e.guid = r.guid_one';
        $options['wheres'][] = '(r.guid_two IN (' . implode(',', $group_guids) . ') AND r.relationship = "member")';
        $users = elgg_get_entities($options);
        if (!empty($users)) {
            $new_users = [];
            foreach ($users as $user) {
                $new_users[$user['guid']] = $user['email'];
            }
            $filtered_recipients['users'] += $new_users;
        }
    }
    $subscribers = elgg_extract('subscribers', $recipients);
    if (!empty($subscribers)) {
        $subscribers = newsletter_get_subscribers($container);
        $filtered_recipients['users'] += $subscribers['users'];
        $filtered_recipients['emails'] = array_merge($filtered_recipients['emails'], $subscribers['emails']);
    }
    $members = elgg_extract('members', $recipients);
    if (!empty($members)) {
        $relationship = 'member';
        if (elgg_instanceof($container, 'site')) {
            $relationship = 'member_of_site';
        }
        $options = $basic_user_options;
        $options['relationship'] = $relationship;
        $options['relationship_guid'] = $container->getGUID();
        $options['inverse_relationship'] = true;
        $users = elgg_get_entities_from_relationship($options);
        if (!empty($users)) {
            $new_users = [];
            foreach ($users as $user) {
                $new_users[$user['guid']] = $user['email'];
            }
            $filtered_recipients['users'] += $new_users;
        }
    }
    $emails = elgg_extract('emails', $recipients);
    if (!empty($emails)) {
        if (!is_array($emails)) {
            $emails = [$emails];
        }
        // get blocked users
        $options = ['type' => 'user', 'limit' => false, 'selects' => ['ue.email'], 'joins' => ['JOIN ' . $dbprefix . 'users_entity ue ON e.guid = ue.guid'], 'wheres' => ["(ue.email IN ('" . implode("','", $emails) . "'))", "(e.guid IN (SELECT guid_one\n\t\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\t\tWHERE relationship = '" . NewsletterSubscription::GENERAL_BLACKLIST . "'\n\t\t\t\t\tAND guid_two = " . $site->getGUID() . ")\n\t\t\t\tOR\n\t\t\t\te.guid IN (SELECT guid_one\n\t\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\t\tWHERE relationship = '" . NewsletterSubscription::BLACKLIST . "'\n\t\t\t\t\tAND guid_two = " . $container->getGUID() . ")\n\t\t\t\t)"], 'callback' => 'newsletter_user_row_to_subscriber_info'];
        $users = elgg_get_entities($options);
        if (!empty($users)) {
            $blocked_emails = [];
            foreach ($users as $user) {
                $blocked_emails[] = $user['email'];
            }
            $emails = array_diff($emails, $blocked_emails);
        }
        if (!empty($emails)) {
            // get blocked emails
            $options = ['type' => 'object', 'subtype' => NewsletterSubscription::SUBTYPE, 'limit' => false, 'selects' => ['oe.title AS email'], 'joins' => ['JOIN ' . $dbprefix . 'objects_entity oe ON e.guid = oe.guid'], 'wheres' => ["(oe.title IN ('" . implode("','", $emails) . "'))", "(e.guid IN (SELECT guid_one\n\t\t\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\t\t\tWHERE relationship = '" . NewsletterSubscription::GENERAL_BLACKLIST . "'\n\t\t\t\t\t\tAND guid_two = " . $site->getGUID() . ")\n\t\t\t\t\tOR\n\t\t\t\t\te.guid IN (SELECT guid_one\n\t\t\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\t\t\tWHERE relationship = '" . NewsletterSubscription::BLACKLIST . "'\n\t\t\t\t\t\tAND guid_two = " . $container->getGUID() . ")\n\t\t\t\t\t)"], 'callback' => 'newsletter_user_row_to_subscriber_info'];
            $subscriptions = elgg_get_entities($options);
            if (!empty($subscriptions)) {
                $blocked_emails = [];
                foreach ($subscriptions as $subscription) {
                    $blocked_emails[] = $subscription['email'];
                }
                $emails = array_diff($emails, $blocked_emails);
            }
            if (!empty($emails)) {
                $filtered_recipients['emails'] = array_merge($filtered_recipients['emails'], $emails);
            }
        }
    }
    // get newsletter content
    if ($entity->subject) {
        $message_subject = $entity->subject;
    } else {
        $message_subject = elgg_echo('newsletter:subject', [$container->name, $entity->title]);
    }
    $message_plaintext_content = elgg_echo('newsletter:plain_message', [elgg_normalize_url($entity->getURL())]);
    $message_html_content = elgg_view_layout('newsletter', ['entity' => $entity]);
    // convert to inline CSS for email clients
    $message_html_content = html_email_handler_css_inliner($message_html_content);
    // proccess all recipients
    if (newsletter_custom_from_enabled() && !empty($entity->from)) {
        // from is validated to a valid email address in the newsletter save action
        $from = $entity->from;
    } else {
        // default to the container email address
        $from = html_email_handler_make_rfc822_address($container);
    }
    // set default send options
    $send_options = ['from' => $from, 'subject' => $message_subject, 'plaintext_message' => $message_plaintext_content];
    foreach ($filtered_recipients as $type => $recipients) {
        if (empty($recipients)) {
            continue;
        }
        foreach ($recipients as $id => $recipient) {
            $recipient_log = ['type' => $type, 'email' => $recipient, 'time' => date(DATE_RFC1123), 'timestamp' => time(), 'status' => false];
            // create individual footer for unsubscribe link
            if ($type == 'users') {
                $recipient_log['guid'] = $id;
                $unsubscribe_link = newsletter_generate_unsubscribe_link($container, $id);
            } else {
                $unsubscribe_link = newsletter_generate_unsubscribe_link($container, $recipient);
            }
            // place the unsubscribe link in the message
            $unsubscribe_link = elgg_normalize_url($unsubscribe_link);
            $message_html_content_user = str_ireplace(urlencode("{unsublink}"), $unsubscribe_link, $message_html_content);
            // replace the online link for logged out users to add an emailadres
            if ($type !== 'users') {
                $online_link = $entity->getURL();
                $new_online_link = $online_link . '?e=' . $recipient;
                $message_html_content_user = str_ireplace($online_link, $new_online_link, $message_html_content_user);
            }
            // add URL postfix to all internal links
            $message_html_content_user = newsletter_apply_url_postfix($message_html_content_user, $entity);
            // send mail
            $send_options['to'] = $recipient;
            $send_options['html_message'] = $message_html_content_user;
            $recipient_log['status'] = html_email_handler_send_email($send_options);
            if ($recipient_log['status'] && !empty($recipient_log['guid'])) {
                $entity->addRelationship($recipient_log['guid'], Newsletter::SEND_TO);
            }
            // add to logging
            $logging['recipients'][] = $recipient_log;
            $entity->saveLogging($logging);
        }
    }
    $logging['end_time'] = time();
    $entity->saveLogging($logging);
    // set newsletter status to done
    $entity->status = 'sent';
    // send status notification
    if (newsletter_is_email_address($entity->status_notification)) {
        $from = html_email_handler_make_rfc822_address($site);
        $subject = elgg_echo('newsletter:status_notification:subject');
        $message = elgg_echo('newsletter:status_notification:message', [$entity->title, $entity->getURL()]);
        elgg_send_email($from, $entity->status_notification, $subject, $message);
    }
    // restore access
    elgg_set_ignore_access($ia);
}
Beispiel #23
0
/**
 * Invite a new user by email to a group
 *
 * @param ElggGroup $group  the group to be invited for
 * @param string    $email  the email address to be invited
 * @param string    $text   (optional) extra text in the invitation
 * @param bool      $resend should existing invitations be resend
 *
 * @return bool|NULL true is invited, false on failure, null when already send
 */
function group_tools_invite_email(ElggGroup $group, $email, $text = "", $resend = false)
{
    $loggedin_user = elgg_get_logged_in_user_entity();
    $resend = (bool) $resend;
    if (!$group instanceof ElggGroup || empty($email) || !is_email_address($email) || empty($loggedin_user)) {
        return false;
    }
    // generate invite code
    $invite_code = group_tools_generate_email_invite_code($group->getGUID(), $email);
    if (empty($invite_code)) {
        return false;
    }
    $found_group = group_tools_check_group_email_invitation($invite_code, $group->getGUID());
    if (!empty($found_group) && empty($resend)) {
        return null;
    }
    // make site email
    $site = elgg_get_site_entity();
    if (!empty($site->email)) {
        if (!empty($site->name)) {
            $site_from = "{$site->name} <{$site->email}>";
        } else {
            $site_from = $site->email;
        }
    } else {
        // no site email, so make one up
        if (!empty($site->name)) {
            $site_from = "{$site->name} <noreply@{$site->getDomain()}>";
        } else {
            $site_from = "noreply@{$site->getDomain()}";
        }
    }
    if (empty($found_group)) {
        // register invite with group
        $group->annotate('email_invitation', "{$invite_code}|{$email}", ACCESS_LOGGED_IN, $group->getGUID());
    }
    // make subject
    $subject = elgg_echo('group_tools:groups:invite:email:subject', [$group->name]);
    // make body
    $body = elgg_echo('group_tools:groups:invite:email:body', [$loggedin_user->name, $group->name, $site->name, $text, $site->name, elgg_normalize_url("register?group_invitecode={$invite_code}"), elgg_normalize_url("groups/invitations/?invitecode={$invite_code}"), $invite_code]);
    $params = ['group' => $group, 'inviter' => $loggedin_user, 'invitee' => $email];
    $body = elgg_trigger_plugin_hook('invite_notification', 'group_tools', $params, $body);
    return elgg_send_email($site_from, $email, $subject, $body);
}
Beispiel #24
0
    }
    if (get_user_by_email($email)) {
        $error = TRUE;
        $already_members[] = $email;
        continue;
    }
    $link = elgg_get_site_url() . 'register?friend_guid=' . $current_user->guid . '&invitecode=' . generate_invite_code($current_user->username);
    $message = elgg_echo('invitefriends:email', array($site->name, $current_user->name, $emailmessage, $link));
    $subject = elgg_echo('invitefriends:subject', array($site->name));
    // create the from address
    $site = get_entity($site->guid);
    if ($site && isset($site->email)) {
        $from = $site->email;
    } else {
        $from = 'noreply@' . get_site_domain($site->guid);
    }
    elgg_send_email($from, $email, $subject, $message);
    $sent_total++;
}
if ($error) {
    register_error(elgg_echo('invitefriends:invitations_sent', array($sent_total)));
    if (count($bad_emails) > 0) {
        register_error(elgg_echo('invitefriends:email_error', array(implode(', ', $bad_emails))));
    }
    if (count($already_members) > 0) {
        register_error(elgg_echo('invitefriends:already_members', array(implode(', ', $already_members))));
    }
} else {
    system_message(elgg_echo('invitefriends:success'));
}
forward(REFERER);
Beispiel #25
0
$required_fields = array("name", "email", "message");
foreach ($required_fields as $required_name) {
    if (!get_input($required_name)) {
        $error = true;
        register_error(elgg_echo("error:missing_data"));
    } elseif ($required_name == "email" && !is_email_address($email)) {
        $error = true;
        register_error(elgg_echo("registration:notemail"));
    }
}
// errors found?
if (empty($error)) {
    if (($contact_recipient = elgg_get_plugin_setting("recipient", "contact")) && is_email_address($contact_recipient)) {
        $mailmessage = elgg_echo("contact:mail:message:prepend") . PHP_EOL . PHP_EOL . elgg_echo("contact:form:name:label") . ": " . $name . PHP_EOL . elgg_echo("contact:form:mail:label") . ": " . $email . PHP_EOL . elgg_echo("contact:form:message:label") . ": " . $message;
        $params = array();
        if (!empty($cc)) {
            $params["cc"] = array($email);
        }
        elgg_send_email($email, $contact_recipient, $subject, $mailmessage, $params);
        elgg_clear_sticky_form("contact_form");
        system_message(elgg_echo("contact:message:success"));
        if (elgg_get_plugin_setting("thankyou_text", "contact")) {
            $forward_url = "contact/thankyou";
        } else {
            $forward_url = "";
        }
    } else {
        register_error(elgg_echo("contact:message:invalid_recipient_address"));
    }
}
forward($forward_url);
/**
 * Send a notification via email.
 *
 * @param ElggEntity $from    The from user/site/object
 * @param ElggUser   $to      To which user?
 * @param string     $subject The subject of the message.
 * @param string     $message The message body
 * @param array      $params  Optional parameters (none taken in this instance)
 *
 * @return bool
 * @access private
 */
function email_notify_handler(ElggEntity $from, ElggUser $to, $subject, $message, array $params = NULL)
{
    global $CONFIG;
    if (!$from) {
        $msg = elgg_echo('NotificationException:MissingParameter', array('from'));
        throw new NotificationException($msg);
    }
    if (!$to) {
        $msg = elgg_echo('NotificationException:MissingParameter', array('to'));
        throw new NotificationException($msg);
    }
    if ($to->email == "") {
        $msg = elgg_echo('NotificationException:NoEmailAddress', array($to->guid));
        throw new NotificationException($msg);
    }
    // To
    $to = $to->email;
    // From
    $site = get_entity($CONFIG->site_guid);
    // If there's an email address, use it - but only if its not from a user.
    if (!$from instanceof ElggUser && $from->email) {
        $from = $from->email;
    } else {
        if ($site && $site->email) {
            // Use email address of current site if we cannot use sender's email
            $from = $site->email;
        } else {
            // If all else fails, use the domain of the site.
            $from = 'noreply@' . get_site_domain($CONFIG->site_guid);
        }
    }
    return elgg_send_email($from, $to, $subject, $message);
}
Beispiel #27
0
 /**
  * Notifies an user of the RSVP
  *
  * @param string $type type of the RSVP
  * @param string $to   guid of the user
  *
  * @return void
  */
 protected function notifyOnRsvp($type, $to = null)
 {
     if ($type == EVENT_MANAGER_RELATION_ATTENDING_PENDING) {
         return;
     }
     $ia = elgg_set_ignore_access(true);
     if ($to === null) {
         $to = elgg_get_logged_in_user_guid();
     }
     $to_entity = get_entity($to);
     if (empty($to_entity)) {
         elgg_set_ignore_access($ia);
         return;
     }
     // can we make nice links in the emails
     $html_email_handler_enabled = elgg_is_active_plugin("html_email_handler");
     // do we have a registration link
     $registrationLink = "";
     $unsubscribeLink = "";
     if ($type == EVENT_MANAGER_RELATION_ATTENDING) {
         if ($this->registration_needed) {
             $link = elgg_get_site_url() . 'events/registration/view/' . $this->getGUID() . '?u_g=' . $to . '&k=' . elgg_build_hmac([$this->time_created, $to])->getToken();
             $registrationLink = PHP_EOL . PHP_EOL;
             $registrationLink .= elgg_echo('event_manager:event:registration:notification:program:linktext');
             $registrationLink .= PHP_EOL . PHP_EOL;
             if ($html_email_handler_enabled) {
                 $registrationLink .= elgg_view("output/url", array("text" => $link, "href" => $link));
             } else {
                 $registrationLink .= $link;
             }
         }
         if ($this->register_nologin) {
             $link = elgg_get_site_url() . "events/unsubscribe/" . $this->getGUID() . "/" . elgg_get_friendly_title($this->title) . "?e=" . $to_entity->email;
             $unsubscribeLink = PHP_EOL . PHP_EOL;
             $unsubscribeLink .= elgg_echo('event_manager:event:registration:notification:unsubscribe:linktext');
             $unsubscribeLink .= PHP_EOL . PHP_EOL;
             if ($html_email_handler_enabled) {
                 $unsubscribeLink .= elgg_view("output/url", array("text" => $link, "href" => $link));
             } else {
                 $unsubscribeLink .= $link;
             }
         }
         if ($html_email_handler_enabled) {
             // add addthisevent banners in footer
             $registrationLink .= elgg_view('event_manager/email/addevent', ['entity' => $this]);
         }
     }
     // make the event title for in the e-mail
     if ($html_email_handler_enabled) {
         $event_title_link = elgg_view("output/url", array("text" => $this->title, "href" => $this->getURL()));
     } else {
         $event_title_link = $this->title;
     }
     // notify the owner of the event
     $this->notifyOwnerOnRSVP($type, $to_entity, $event_title_link, $registrationLink);
     // notify the attending user
     $user_subject = elgg_echo('event_manager:event:registration:notification:user:subject');
     $user_message = elgg_echo('event_manager:event:registration:notification:user:text:' . $type, [$to_entity->name, $event_title_link]);
     $completed_text = elgg_strip_tags($this->registration_completed, '<a>');
     if (!empty($completed_text)) {
         $completed_text = str_ireplace('[NAME]', $to_entity->name, $completed_text);
         $completed_text = str_ireplace('[EVENT]', $this->title, $completed_text);
         $user_message .= PHP_EOL . $completed_text;
     }
     $user_message .= $registrationLink . $unsubscribeLink;
     if ($to_entity instanceof ElggUser) {
         // use notification system for real users
         $summary = elgg_echo('event_manager:event:registration:notification:user:summary:' . $type, [$this->title]);
         // set params for site notifications
         $params = ['summary' => $summary, 'object' => $this, 'action' => 'rsvp'];
         notify_user($to, $this->getOwnerGUID(), $user_subject, $user_message, $params);
     } else {
         // send e-mail for non users
         $to_email = $to_entity->name . "<" . $to_entity->email . ">";
         $site = elgg_get_site_entity($this->site_guid);
         $site_from = $this->getSiteEmailAddress($site);
         elgg_send_email($site_from, $to_email, $user_subject, $user_message);
     }
     elgg_set_ignore_access($ia);
 }
Beispiel #28
0
/**
 * Process the newsletter for a given guid
 *
 * @param int $entity_guid guid of the newsletter
 *
 * @return void
 */
function newsletter_process($entity_guid)
{
    $entity_guid = sanitise_int($entity_guid, false);
    if (!empty($entity_guid)) {
        // ignore access
        $ia = elgg_set_ignore_access(true);
        $entity = get_entity($entity_guid);
        // is this a Newsletter
        if (!empty($entity) && elgg_instanceof($entity, "object", Newsletter::SUBTYPE)) {
            $logging = array("start_time" => time());
            $site = elgg_get_site_entity();
            $container = $entity->getContainerEntity();
            $dbprefix = elgg_get_config("dbprefix");
            // ================================
            // set newsletter status to sending
            // ================================
            $entity->status = "sending";
            $entity->start_time = $logging["start_time"];
            // ==================
            // get the recipients
            // ==================
            // basic set of user selection options
            $basic_user_options = array("type" => "user", "limit" => false, "selects" => array("ue.email"), "joins" => array("JOIN " . $dbprefix . "users_entity ue ON e.guid = ue.guid"), "callback" => "newsletter_user_row_to_subscriber_info");
            // include users without settings
            if (newsletter_include_existing_users()) {
                // yes, so exclude blocked
                $basic_user_options["wheres"] = array("(e.guid NOT IN (SELECT guid_one\n\t\t\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\t\t\tWHERE relationship = '" . NewsletterSubscription::GENERAL_BLACKLIST . "'\n\t\t\t\t\t\tAND guid_two = " . $site->getGUID() . ")\n\t\t\t\t\t)", "(e.guid NOT IN (SELECT guid_one\n\t\t\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\t\t\tWHERE relationship = '" . NewsletterSubscription::BLACKLIST . "'\n\t\t\t\t\t\tAND guid_two = " . $container->getGUID() . ")\n\t\t\t\t\t)");
            } else {
                // no, so subscription is required
                $basic_user_options["wheres"] = array("(e.guid IN (SELECT guid_one\n\t\t\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\t\t\tWHERE relationship = '" . NewsletterSubscription::SUBSCRIPTION . "'\n\t\t\t\t\t\tAND guid_two = " . $container->getGUID() . ")\n\t\t\t\t\t)");
            }
            $filtered_recipients = array("users" => array(), "emails" => array());
            $recipients = $entity->getRecipients();
            if (empty($recipients)) {
                // no recipients so report error
                $entity->status = "sent";
                return false;
            }
            // recipients is an array consisting of:
            // - user_guids: 	individual users
            // - group_guids:	groups to send the content to
            // - emails:		individual email addresses
            // - subscribers:	(int) whether or not to add the subscribers of the container
            // - members:		(int) whether or not to aad the member of the container
            $user_guids = elgg_extract("user_guids", $recipients);
            if (!empty($user_guids)) {
                if (!is_array($user_guids)) {
                    $user_guids = array($user_guids);
                }
                // convert to a format we can use
                $options = $basic_user_options;
                $options["wheres"][] = "(e.guid IN (" . implode(",", $user_guids) . "))";
                $users = elgg_get_entities($options);
                if (!empty($users)) {
                    $new_users = array();
                    foreach ($users as $user) {
                        $new_users[$user["guid"]] = $user["email"];
                    }
                    $filtered_recipients["users"] += $new_users;
                }
            }
            $group_guids = elgg_extract("group_guids", $recipients);
            if (!empty($group_guids)) {
                if (!is_array($group_guids)) {
                    $group_guids = array($group_guids);
                }
                $options = $basic_user_options;
                $options["joins"][] = "JOIN " . $dbprefix . "entity_relationships r ON e.guid = r.guid_one";
                $options["wheres"][] = "(r.guid_two IN (" . implode(",", $group_guids) . ") AND r.relationship = 'member')";
                $users = elgg_get_entities($options);
                if (!empty($users)) {
                    $new_users = array();
                    foreach ($users as $user) {
                        $new_users[$user["guid"]] = $user["email"];
                    }
                    $filtered_recipients["users"] += $new_users;
                }
            }
            $subscribers = elgg_extract("subscribers", $recipients);
            if (!empty($subscribers)) {
                $subscribers = newsletter_get_subscribers($container);
                $filtered_recipients["users"] += $subscribers["users"];
                $filtered_recipients["emails"] = array_merge($filtered_recipients["emails"], $subscribers["emails"]);
            }
            $members = elgg_extract("members", $recipients);
            if (!empty($members)) {
                $relationship = "member";
                if (elgg_instanceof($container, "site")) {
                    $relationship = "member_of_site";
                }
                $options = $basic_user_options;
                $options["relationship"] = $relationship;
                $options["relationship_guid"] = $container->getGUID();
                $options["inverse_relationship"] = true;
                $users = elgg_get_entities_from_relationship($options);
                if (!empty($users)) {
                    $new_users = array();
                    foreach ($users as $user) {
                        $new_users[$user["guid"]] = $user["email"];
                    }
                    $filtered_recipients["users"] += $new_users;
                }
            }
            $emails = elgg_extract("emails", $recipients);
            if (!empty($emails)) {
                if (!is_array($emails)) {
                    $emails = array($emails);
                }
                // get blocked users
                $options = array("type" => "user", "limit" => false, "selects" => array("ue.email"), "joins" => array("JOIN " . $dbprefix . "users_entity ue ON e.guid = ue.guid"), "wheres" => array("(ue.email IN ('" . implode("','", $emails) . "'))", "(e.guid IN (SELECT guid_one\n\t\t\t\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\t\t\t\tWHERE relationship = '" . NewsletterSubscription::GENERAL_BLACKLIST . "'\n\t\t\t\t\t\t\tAND guid_two = " . $site->getGUID() . ")\n\t\t\t\t\t\tOR\n\t\t\t\t\t\te.guid IN (SELECT guid_one\n\t\t\t\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\t\t\t\tWHERE relationship = '" . NewsletterSubscription::BLACKLIST . "'\n\t\t\t\t\t\t\tAND guid_two = " . $container->getGUID() . ")\n\t\t\t\t\t\t)"), "callback" => "newsletter_user_row_to_subscriber_info");
                $users = elgg_get_entities($options);
                if (!empty($users)) {
                    $blocked_emails = array();
                    foreach ($users as $user) {
                        $blocked_emails[] = $user["email"];
                    }
                    $emails = array_diff($emails, $blocked_emails);
                }
                if (!empty($emails)) {
                    // get blocked emails
                    $options = array("type" => "object", "subtype" => NewsletterSubscription::SUBTYPE, "limit" => false, "selects" => array("oe.title AS email"), "joins" => array("JOIN " . $dbprefix . "objects_entity oe ON e.guid = oe.guid"), "wheres" => array("(oe.title IN ('" . implode("','", $emails) . "'))", "(e.guid IN (SELECT guid_one\n\t\t\t\t\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\t\t\t\t\tWHERE relationship = '" . NewsletterSubscription::GENERAL_BLACKLIST . "'\n\t\t\t\t\t\t\t\tAND guid_two = " . $site->getGUID() . ")\n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\te.guid IN (SELECT guid_one\n\t\t\t\t\t\t\t\tFROM " . $dbprefix . "entity_relationships\n\t\t\t\t\t\t\t\tWHERE relationship = '" . NewsletterSubscription::BLACKLIST . "'\n\t\t\t\t\t\t\t\tAND guid_two = " . $container->getGUID() . ")\n\t\t\t\t\t\t\t)"), "callback" => "newsletter_user_row_to_subscriber_info");
                    $subscriptions = elgg_get_entities($options);
                    if (!empty($subscriptions)) {
                        $blocked_emails = array();
                        foreach ($subscriptions as $subscription) {
                            $blocked_emails[] = $subscription["email"];
                        }
                        $emails = array_diff($emails, $blocked_emails);
                    }
                    if (!empty($emails)) {
                        $filtered_recipients["emails"] = array_merge($filtered_recipients["emails"], $emails);
                    }
                }
            }
            // ======================
            // get newsletter content
            // ======================
            if ($entity->subject) {
                $message_subject = $entity->subject;
            } else {
                $message_subject = elgg_echo("newsletter:subject", array($container->name, $entity->title));
            }
            $message_plaintext_content = elgg_echo("newsletter:plain_message", array(elgg_normalize_url($entity->getURL())));
            $message_html_content = elgg_view_layout("newsletter", array("entity" => $entity));
            // convert to inline CSS for email clients
            $message_html_content = html_email_handler_css_inliner($message_html_content);
            // =======================
            // proccess all recipients
            // =======================
            $send_options = array("from" => html_email_handler_make_rfc822_address($container), "subject" => $message_subject, "plaintext_message" => $message_plaintext_content);
            foreach ($filtered_recipients as $type => $recipients) {
                if (!empty($recipients)) {
                    foreach ($recipients as $id => $recipient) {
                        $recipient_log = array("type" => $type, "email" => $recipient, "time" => date(DATE_RFC1123), "timestamp" => time(), "status" => false);
                        // =============================================
                        // create individual footer for unsubscribe link
                        // =============================================
                        if ($type == "users") {
                            $recipient_log["guid"] = $id;
                            $unsubscribe_link = newsletter_generate_unsubscribe_link($container, $id);
                        } else {
                            $unsubscribe_link = newsletter_generate_unsubscribe_link($container, $recipient);
                        }
                        // place the unsubscribe link in the message
                        $unsubscribe_link = elgg_normalize_url($unsubscribe_link);
                        $message_html_content_user = str_ireplace(urlencode("{unsublink}"), $unsubscribe_link, $message_html_content);
                        // replace the online link for logged out users to add an emailadres
                        if ($type !== "users") {
                            $online_link = $entity->getURL();
                            $new_online_link = $online_link . "?e=" . $recipient;
                            $message_html_content_user = str_ireplace($online_link, $new_online_link, $message_html_content_user);
                        }
                        // add URL postfix to all internal links
                        $message_html_content_user = newsletter_apply_url_postfix($message_html_content_user);
                        // =========
                        // send mail
                        // =========
                        $send_options["to"] = $recipient;
                        $send_options["html_message"] = $message_html_content_user;
                        $recipient_log["status"] = html_email_handler_send_email($send_options);
                        if ($recipient_log["status"] && !empty($recipient_log["guid"])) {
                            $entity->addRelationship($recipient_log["guid"], Newsletter::SEND_TO);
                        }
                        // ==============
                        // add to logging
                        // ==============
                        $logging["recipients"][] = $recipient_log;
                        $entity->saveLogging($logging);
                    }
                }
            }
            $logging["end_time"] = time();
            $entity->saveLogging($logging);
            // =============================
            // set newsletter status to done
            // =============================
            $entity->status = "sent";
            // ========================
            // send status notification
            // ========================
            if (!empty($entity->status_notification) && newsletter_is_email_address($entity->status_notification)) {
                $from = html_email_handler_make_rfc822_address($site);
                $subject = elgg_echo("newsletter:status_notification:subject");
                $message = elgg_echo("newsletter:status_notification:message", array($entity->title, $entity->getURL()));
                elgg_send_email($from, $entity->status_notification, $subject, $message);
            }
        }
        // restore access
        elgg_set_ignore_access($ia);
    }
}
Beispiel #29
0
function zhgroups_send_email($from_name, $to_email, $subject, $message, $end = '')
{
    $site = elgg_get_site_entity();
    if ($site->email) {
        $site_from = $from_name . " <" . $site->email . ">";
    } else {
        // no site email, so make one up
        $site_from = $from_name . " <noreply@" . get_site_domain($site->getGUID()) . ">";
    }
    if (empty($end)) {
        $body = zhaohuEmailHead() . $message . zhaohuEmailEnd();
    } else {
        $body = zhaohuEmailHead() . $message . $end;
    }
    return elgg_send_email($site_from, $to_email, $subject, $body);
}