Example #1
0
/**
 * Get a mail message text by template name
 *
 * @param string Template name
 * @param string Email format ( auto | html | text )
 * @param array Params
 * @param object User
 * @return string Mail message
 */
function mail_template($template_name, $format = 'auto', $params = array(), $User = NULL)
{
    global $current_charset, $is_admin_page;
    if (!empty($params['locale'])) {
        // Switch to locale for current email template
        locale_temp_switch($params['locale']);
    }
    $value_is_admin_page = $is_admin_page;
    // Set TRUE to use gender settings from back office
    $is_admin_page = true;
    // Set extension of template
    $template_exts = array();
    switch ($format) {
        case 'auto':
            // $template_exts['non-mime'] = '.txt.php'; // The area that is ignored by MIME-compliant clients
            $template_exts['text'] = '.txt.php';
            $template_exts['html'] = '.html.php';
            $boundary = $params['boundary'];
            $boundary_alt = 'b2evo-alt-' . md5(rand());
            $template_headers = array('text' => 'Content-Type: text/plain; charset=' . $current_charset, 'html' => 'Content-Type: text/html; charset=' . $current_charset);
            break;
        case 'html':
            $template_exts['html'] = '.html.php';
            break;
        case 'text':
            $template_exts['text'] = '.txt.php';
            break;
    }
    $template_message = '';
    if (isset($boundary, $boundary_alt)) {
        // Start new boundary content
        $template_message .= "\n" . '--' . $boundary . "\n";
        $template_message .= 'Content-Type: multipart/alternative; boundary="' . $boundary_alt . '"' . "\n\n";
    }
    foreach ($template_exts as $format => $ext) {
        if (isset($boundary, $boundary_alt) && $format != 'non-mime') {
            // Start new boundary alt content
            $template_message .= "\n" . '--' . $boundary_alt . "\n";
        }
        if (isset($template_headers[$format])) {
            // Header data for each content
            $template_message .= $template_headers[$format] . "\n\n";
        }
        // Get mail template
        ob_start();
        emailskin_include($template_name . $ext, $params);
        $template_message .= ob_get_clean();
        if (!empty($User)) {
            // Replace $login$ with gender colored link + icon in HTML format,
            //   and with simple login text in PLAIN TEXT format
            $user_login = $format == 'html' ? $User->get_colored_login(array('mask' => '$avatar$ $login$')) : $User->login;
            $template_message = str_replace('$login$', $user_login, $template_message);
        }
    }
    if (isset($boundary, $boundary_alt)) {
        // End all boundary contents
        $template_message .= "\n" . '--' . $boundary_alt . '--' . "\n";
        $template_message .= "\n" . '--' . $boundary . '--' . "\n";
    }
    // Return back the value
    $is_admin_page = $value_is_admin_page;
    if (!empty($params['locale'])) {
        // Restore previous locale
        locale_restore_previous();
    }
    return $template_message;
}
        $duplicated_files_message = $new_File->get_duplicated_files_message(array('message' => '<p' . emailskin_style('.p') . '><b' . emailskin_style('.important') . '>' . T_('WARNING: the same profile picture is used by these other users: %s.') . '</b></p>' . "\n", 'use_style' => true));
    }
    if ($params['avatar_changed']) {
        // If profile pictre has been changed
        echo '<p' . emailskin_style('.p') . '>' . T_('The main profile picture was changed to:') . '</p>' . "\n";
        echo '<p' . emailskin_style('.p') . '>' . $User->get_avatar_File()->get_tag('', '', '', '', 'fit-320x320', 'original', '', '', '', '', '', '#', '', 1, 'none') . '</p>' . "\n";
    } elseif ($params['new_avatar_upload']) {
        // Display the newly uploaded file only if it was not set as main profile picture
        echo '<p' . emailskin_style('.p') . '>' . T_('A new profile picture file was uploaded:') . '</p>' . "\n";
        echo '<p' . emailskin_style('.p') . '>' . $new_File->get_tag('', '', '', '', 'fit-320x320', 'original', '', '', '', '', '', '#', '', 1, 'none') . '</p>' . "\n";
    }
    // Display warning message about duplicated files
    echo $duplicated_files_message;
    // User's pictures:
    echo '<p' . emailskin_style('.p') . '>' . T_('The current profile pictures for this account are:') . '</p>' . "\n";
    $user_pictures = '';
    $user_avatars = $User->get_avatar_Links(false);
    foreach ($user_avatars as $user_Link) {
        $user_pictures .= $user_Link->get_tag(array('before_image' => '', 'before_image_legend' => '', 'after_image_legend' => '', 'after_image' => ' ', 'image_size' => 'crop-top-160x160'));
    }
    echo empty($user_pictures) ? '<p' . emailskin_style('.p') . '><b>' . T_('No pictures.') . '</b></p>' : $user_pictures;
}
// Buttons:
echo '<div' . emailskin_style('div.buttons') . '>' . "\n";
echo get_link_tag($admin_url . '?ctrl=user&user_tab=profile&user_ID=' . $params['user_ID'], T_('Edit User'), 'div.buttons a+a.button_yellow') . "\n";
echo "</div>\n";
// Footer vars:
$params['unsubscribe_text'] = T_('If you don\'t want to receive any more notifications about user changes, click here:') . ' <a href="' . $htsrv_url . 'quick_unsubscribe.php?type=account_changed&user_ID=$user_ID$&key=$unsubscribe_key$"' . emailskin_style('.a') . '>' . T_('instant unsubscribe') . '</a>.';
// ---------------------------- EMAIL FOOTER INCLUDED HERE ----------------------------
emailskin_include('_email_footer.inc.html.php', $params);
// ------------------------------- END OF EMAIL FOOTER --------------------------------
Example #3
0
/**
 * Get a mail message text by template name
 *
 * @param string Template name
 * @param string Email format ( auto | html | text )
 * @param array Params
 * @param object User
 * @return string|array Mail message OR Array of the email contents when message is multipart content
 */
function mail_template($template_name, $format = 'auto', $params = array(), $User = NULL)
{
    global $current_charset;
    if (!empty($params['locale'])) {
        // Switch to locale for current email template
        locale_temp_switch($params['locale']);
    }
    // Set extension of template
    $template_exts = array();
    switch ($format) {
        case 'auto':
            // $template_exts['non-mime'] = '.txt.php'; // The area that is ignored by MIME-compliant clients
            $template_exts['text'] = '.txt.php';
            $template_exts['html'] = '.html.php';
            $boundary = $params['boundary'];
            $boundary_alt = 'b2evo-alt-' . md5(rand());
            $template_headers = array('text' => 'Content-Type: text/plain; charset=' . $current_charset, 'html' => 'Content-Type: text/html; charset=' . $current_charset);
            // Store all contents in this array for multipart message
            $template_contents = array('charset' => $current_charset, 'full' => '', 'html' => '', 'text' => '');
            break;
        case 'html':
            $template_exts['html'] = '.html.php';
            break;
        case 'text':
            $template_exts['text'] = '.txt.php';
            break;
    }
    $template_message = '';
    if (isset($boundary, $boundary_alt)) {
        // Start new boundary content
        $template_message .= "\n" . '--' . $boundary . "\n";
        $template_message .= 'Content-Type: multipart/alternative; boundary="' . $boundary_alt . '"' . "\n\n";
    }
    foreach ($template_exts as $format => $ext) {
        $formated_message = '';
        if (isset($boundary, $boundary_alt) && $format != 'non-mime') {
            // Start new boundary alt content
            $template_message .= "\n" . '--' . $boundary_alt . "\n";
        }
        if (isset($template_headers[$format])) {
            // Header data for each content
            $template_message .= $template_headers[$format] . "\n\n";
        }
        // Get mail template
        ob_start();
        emailskin_include($template_name . $ext, $params);
        $formated_message .= ob_get_clean();
        if (!empty($User)) {
            // Replace $login$ with gender colored link + icon in HTML format,
            //   and with simple login text in PLAIN TEXT format
            $user_login = $format == 'html' ? $User->get_colored_login(array('mask' => '$avatar$ $login$', 'use_style' => true)) : $User->login;
            $formated_message = str_replace('$login$', $user_login, $formated_message);
        }
        if ($format == 'html') {
            // Use "http://" for protocol-relative urls because email browsers cannot load such urls:
            $formated_message = preg_replace('~(src|href)="//~', '$1="http://', $formated_message);
        }
        $template_message .= $formated_message;
        if (isset($template_contents)) {
            // Multipart content
            $template_contents[$format] = $formated_message;
        }
    }
    if (isset($boundary, $boundary_alt)) {
        // End all boundary contents
        $template_message .= "\n" . '--' . $boundary_alt . '--' . "\n";
        $template_message .= "\n" . '--' . $boundary . '--' . "\n";
    }
    if (!empty($params['locale'])) {
        // Restore previous locale
        locale_restore_previous();
    }
    if (isset($template_contents)) {
        // Return array for multipart content
        $template_contents['full'] = $template_message;
        return $template_contents;
    } else {
        // Return string if email message contains one content (html or text)
        return $template_message;
    }
}