Beispiel #1
0
/**
 * Sends the preview newsletter
 *
 * @param Newsletter $entity newsletter to be send
 * @param string     $email  emailaddress of the recipient
 *
 * @return bool if sending is succes or not
 */
function newsletter_send_preview(Newsletter $entity, $email)
{
    $result = false;
    if (!empty($entity) && elgg_instanceof($entity, "object", Newsletter::SUBTYPE) && !empty($email)) {
        $container = $entity->getContainerEntity();
        // build correct subject
        if ($entity->subject) {
            $message_subject = $entity->subject;
        } else {
            $message_subject = elgg_echo("newsletter:subject", array($container->name, $entity->title));
        }
        //  plaintext message
        $message_plaintext_content = elgg_echo("newsletter:plain_message", array($entity->getURL()));
        // html content
        $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);
        // add unsubscribe link
        $unsubscribe_link = newsletter_generate_unsubscribe_link($container, $email);
        $message_html_content = str_ireplace(urlencode("{unsublink}"), $unsubscribe_link, $message_html_content);
        // replace online link
        $online_link = $entity->getURL();
        $new_online_link = $online_link . "?e=" . $email;
        $message_html_content = str_ireplace($online_link, $new_online_link, $message_html_content);
        // start creating sending options
        $send_options = array("from" => html_email_handler_make_rfc822_address($container), "subject" => $message_subject, "plaintext_message" => $message_plaintext_content, "to" => $email, "html_message" => $message_html_content);
        // send preview
        $result = html_email_handler_send_email($send_options);
    }
    return $result;
}
Beispiel #2
0
/**
 * Sends the preview newsletter
 *
 * @param Newsletter $entity newsletter to be send
 * @param string     $email  emailaddress of the recipient
 *
 * @return bool if sending is succes or not
 */
function newsletter_send_preview(Newsletter $entity, $email)
{
    if (!elgg_instanceof($entity, "object", Newsletter::SUBTYPE) || empty($email)) {
        return false;
    }
    $container = $entity->getContainerEntity();
    // build correct subject
    if ($entity->subject) {
        $message_subject = $entity->subject;
    } else {
        $message_subject = elgg_echo('newsletter:subject', [$container->name, $entity->title]);
    }
    //  plaintext message
    $message_plaintext_content = elgg_echo('newsletter:plain_message', [$entity->getURL()]);
    // html content
    $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);
    // add unsubscribe link
    $unsubscribe_link = newsletter_generate_unsubscribe_link($container, $email);
    $message_html_content = str_ireplace(urlencode("{unsublink}"), $unsubscribe_link, $message_html_content);
    // replace online link
    $online_link = $entity->getURL();
    $new_online_link = $online_link . '?e=' . $email;
    $message_html_content = str_ireplace($online_link, $new_online_link, $message_html_content);
    // send preview
    return html_email_handler_send_email(['from' => html_email_handler_make_rfc822_address($container), 'subject' => $message_subject, 'plaintext_message' => $message_plaintext_content, 'to' => $email, 'html_message' => $message_html_content]);
}
Beispiel #3
0
        if (!elgg_view_exists("newsletter/templates/{$template}/body")) {
            // something wrong, reset to default
            $template = 'default';
        }
        $content = elgg_view("newsletter/templates/{$template}/body", $vars);
    }
}
$container_entity = $entity->getContainerEntity();
$container_url = $container_entity->getURL();
if ($container_entity instanceof ElggSite) {
    $container_url = $container_entity->url;
}
$replacements = ['{content}' => $entity->content, '{unsub}' => elgg_echo('newsletter:body:unsub'), '{online}' => elgg_echo('newsletter:body:online'), '{title}' => $entity->title, '{description}' => $entity->description, '{subject}' => $entity->subject, '{newsletter_url}' => elgg_normalize_url($entity->getURL()), '{site_name}' => elgg_get_site_entity()->name, '{site_description}' => elgg_get_site_entity()->description, '{site_url}' => elgg_get_site_url(), '{container_name}' => $entity->getContainerEntity()->name, '{container_url}' => elgg_normalize_url($container_url)];
if (PHP_SAPI !== 'cli') {
    // (pre)viewing online
    if (elgg_is_logged_in()) {
        $replacements['{unsublink}'] = elgg_normalize_url('newsletter/subscriptions/' . elgg_get_logged_in_user_entity()->username);
    } else {
        $email = get_input('e');
        if ($email) {
            $replacements['{newsletter_url}'] = $replacements['{newsletter_url}'] . '?e=' . $email;
            $replacements['{unsublink}'] = newsletter_generate_unsubscribe_link($entity->getContainerEntity(), $email);
        } else {
            $replacements['{unsublink}'] = newsletter_generate_unsubscribe_link($entity->getContainerEntity(), '');
        }
    }
}
foreach ($replacements as $search => $replace) {
    $content = str_ireplace($search, $replace, $content);
}
echo $content;
Beispiel #4
0
        if (!elgg_view_exists("newsletter/templates/" . $template . "/body")) {
            // something wrong, reset to default
            $template = "default";
        }
        $content = elgg_view("newsletter/templates/" . $template . "/body");
    }
}
$container_entity = $entity->getContainerEntity();
$container_url = $container_entity->getURL();
if ($container_entity instanceof ElggSite) {
    $container_url = $container_entity->url;
}
$replacements = array("{content}" => $entity->content, "{unsub}" => elgg_echo("newsletter:body:unsub"), "{online}" => elgg_echo("newsletter:body:online"), "{title}" => $entity->title, "{description}" => $entity->description, "{subject}" => $entity->subject, "{newsletter_url}" => elgg_normalize_url($entity->getURL()), "{site_name}" => elgg_get_site_entity()->name, "{site_description}" => elgg_get_site_entity()->description, "{site_url}" => elgg_get_site_url(), "{container_name}" => $entity->getContainerEntity()->name, "{container_url}" => elgg_normalize_url($container_url));
if (PHP_SAPI !== "cli") {
    // (pre)viewing online
    if (elgg_is_logged_in()) {
        $replacements["{unsublink}"] = elgg_normalize_url("newsletter/subscriptions/" . elgg_get_logged_in_user_entity()->username);
    } else {
        $email = get_input("e");
        if ($email) {
            $replacements["{newsletter_url}"] = $replacements["{newsletter_url}"] . "?e=" . $email;
            $replacements["{unsublink}"] = newsletter_generate_unsubscribe_link($entity->getContainerEntity(), $email);
        } else {
            $replacements["{unsublink}"] = newsletter_generate_unsubscribe_link($entity->getContainerEntity(), "");
        }
    }
}
foreach ($replacements as $search => $replace) {
    $content = str_ireplace($search, $replace, $content);
}
echo $content;