Exemplo n.º 1
0
 /**
  * Get a preview of a news letter before its sent on to the masses
  *  - Uses prepareMailingForPreview to create the actual preview
  */
 public function action_newsletterpreview()
 {
     global $context, $txt;
     // needed to create the preview
     require_once SUBSDIR . '/Mail.subs.php';
     loadLanguage('Errors');
     $context['post_error']['errors'] = array();
     $context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0;
     $context['send_html'] = !empty($_POST['send_html']) ? 1 : 0;
     // Let them know about any mistakes
     if (empty($_POST['subject'])) {
         $context['post_error']['errors'][] = $txt['error_no_subject'];
     }
     if (empty($_POST['message'])) {
         $context['post_error']['errors'][] = $txt['error_no_message'];
     }
     prepareMailingForPreview();
     $context['sub_template'] = 'generic_preview';
 }
Exemplo n.º 2
0
 /**
  * Shows a form to edit a forum mailing and its recipients.
  *
  * What it does:
  * - Called by ?action=admin;area=news;sa=mailingcompose.
  * - Requires the send_mail permission.
  * - Form is submitted to ?action=admin;area=news;sa=mailingsend.
  *
  * @uses ManageNews template, email_members_compose sub-template.
  */
 public function action_mailingcompose()
 {
     global $txt, $context;
     // Setup the template!
     $context['page_title'] = $txt['admin_newsletters'];
     $context['sub_template'] = 'email_members_compose';
     $context['subject'] = !empty($_POST['subject']) ? $_POST['subject'] : $context['forum_name'] . ': ' . htmlspecialchars($txt['subject'], ENT_COMPAT, 'UTF-8');
     $context['message'] = !empty($_POST['message']) ? $_POST['message'] : htmlspecialchars($txt['message'] . "\n\n" . replaceBasicActionUrl($txt['regards_team']) . "\n\n" . '{$board_url}', ENT_COMPAT, 'UTF-8');
     // Needed for the WYSIWYG editor.
     require_once SUBSDIR . '/Editor.subs.php';
     // Now create the editor.
     $editorOptions = array('id' => 'message', 'value' => $context['message'], 'height' => '250px', 'width' => '100%', 'labels' => array('post_button' => $txt['sendtopic_send']), 'preview_type' => 2);
     create_control_richedit($editorOptions);
     if (isset($context['preview'])) {
         require_once SUBSDIR . '/Mail.subs.php';
         $context['recipients']['members'] = !empty($_POST['members']) ? explode(',', $_POST['members']) : array();
         $context['recipients']['exclude_members'] = !empty($_POST['exclude_members']) ? explode(',', $_POST['exclude_members']) : array();
         $context['recipients']['groups'] = !empty($_POST['groups']) ? explode(',', $_POST['groups']) : array();
         $context['recipients']['exclude_groups'] = !empty($_POST['exclude_groups']) ? explode(',', $_POST['exclude_groups']) : array();
         $context['recipients']['emails'] = !empty($_POST['emails']) ? explode(';', $_POST['emails']) : array();
         $context['email_force'] = !empty($_POST['email_force']) ? 1 : 0;
         $context['total_emails'] = !empty($_POST['total_emails']) ? (int) $_POST['total_emails'] : 0;
         $context['max_id_member'] = !empty($_POST['max_id_member']) ? (int) $_POST['max_id_member'] : 0;
         $context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0;
         $context['send_html'] = !empty($_POST['send_html']) ? '1' : '0';
         return prepareMailingForPreview();
     }
     // Start by finding any members!
     $toClean = array();
     if (!empty($_POST['members'])) {
         $toClean[] = 'members';
     }
     if (!empty($_POST['exclude_members'])) {
         $toClean[] = 'exclude_members';
     }
     if (!empty($toClean)) {
         require_once SUBSDIR . '/Auth.subs.php';
         foreach ($toClean as $type) {
             // Remove the quotes.
             $_POST[$type] = strtr((string) $_POST[$type], array('\\"' => '"'));
             preg_match_all('~"([^"]+)"~', $_POST[$type], $matches);
             $_POST[$type] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST[$type]))));
             foreach ($_POST[$type] as $index => $member) {
                 if (strlen(trim($member)) > 0) {
                     $_POST[$type][$index] = Util::htmlspecialchars(Util::strtolower(trim($member)));
                 } else {
                     unset($_POST[$type][$index]);
                 }
             }
             // Find the members
             $_POST[$type] = implode(',', array_keys(findMembers($_POST[$type])));
         }
     }
     if (isset($_POST['member_list']) && is_array($_POST['member_list'])) {
         $members = array();
         foreach ($_POST['member_list'] as $member_id) {
             $members[] = (int) $member_id;
         }
         $_POST['members'] = implode(',', $members);
     }
     if (isset($_POST['exclude_member_list']) && is_array($_POST['exclude_member_list'])) {
         $members = array();
         foreach ($_POST['exclude_member_list'] as $member_id) {
             $members[] = (int) $member_id;
         }
         $_POST['exclude_members'] = implode(',', $members);
     }
     // Clean the other vars.
     $this->action_mailingsend(true);
     // We need a couple strings from the email template file
     loadLanguage('EmailTemplates');
     require_once SUBSDIR . '/News.subs.php';
     // Get a list of all full banned users.  Use their Username and email to find them.
     // Only get the ones that can't login to turn off notification.
     $context['recipients']['exclude_members'] = excludeBannedMembers();
     // Did they select moderators - if so add them as specific members...
     if (!empty($context['recipients']['groups']) && in_array(3, $context['recipients']['groups']) || !empty($context['recipients']['exclude_groups']) && in_array(3, $context['recipients']['exclude_groups'])) {
         $mods = getModerators();
         foreach ($mods as $row) {
             if (in_array(3, $context['recipients'])) {
                 $context['recipients']['exclude_members'][] = $row;
             } else {
                 $context['recipients']['members'][] = $row;
             }
         }
     }
     require_once SUBSDIR . '/Members.subs.php';
     // For progress bar!
     $context['total_emails'] = count($context['recipients']['emails']);
     $context['max_id_member'] = maxMemberID();
     // Clean up the arrays.
     $context['recipients']['members'] = array_unique($context['recipients']['members']);
     $context['recipients']['exclude_members'] = array_unique($context['recipients']['exclude_members']);
 }
Exemplo n.º 3
0
function newsletterpreview()
{
    global $context, $sourcedir, $smcFunc, $txt;
    require_once $sourcedir . '/Subs-Post.php';
    require_once $sourcedir . '/ManageNews.php';
    loadLanguage('Errors');
    $context['post_error']['messages'] = array();
    $context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0;
    $context['send_html'] = !empty($_POST['send_html']) ? 1 : 0;
    if (empty($_POST['subject'])) {
        $context['post_error']['messages'][] = $txt['error_no_subject'];
    }
    if (empty($_POST['message'])) {
        $context['post_error']['messages'][] = $txt['error_no_message'];
    }
    prepareMailingForPreview();
    $context['sub_template'] = 'pm';
}
Exemplo n.º 4
0
/**
 * Shows a form to edit a forum mailing and its recipients.
 * Called by ?action=admin;area=news;sa=mailingcompose.
 * Requires the send_mail permission.
 * Form is submitted to ?action=admin;area=news;sa=mailingsend.
 *
 * @uses ManageNews template, email_members_compose sub-template.
 */
function ComposeMailing()
{
    global $txt, $sourcedir, $context, $smcFunc, $scripturl, $modSettings;
    // Setup the template!
    $context['page_title'] = $txt['admin_newsletters'];
    $context['sub_template'] = 'email_members_compose';
    $context['subject'] = !empty($_POST['subject']) ? $_POST['subject'] : htmlspecialchars($context['forum_name'] . ': ' . $txt['subject']);
    $context['message'] = !empty($_POST['message']) ? $_POST['message'] : htmlspecialchars($txt['message'] . "\n\n" . $txt['regards_team'] . "\n\n" . '{$board_url}');
    // Needed for the WYSIWYG editor.
    require_once $sourcedir . '/Subs-Editor.php';
    // Now create the editor.
    $editorOptions = array('id' => 'message', 'value' => $context['message'], 'height' => '175px', 'width' => '100%', 'labels' => array('post_button' => $txt['sendtopic_send']), 'preview_type' => 2);
    create_control_richedit($editorOptions);
    // Store the ID for old compatibility.
    $context['post_box_name'] = $editorOptions['id'];
    if (isset($context['preview'])) {
        require_once $sourcedir . '/Subs-Post.php';
        $context['recipients']['members'] = !empty($_POST['members']) ? explode(',', $_POST['members']) : array();
        $context['recipients']['exclude_members'] = !empty($_POST['exclude_members']) ? explode(',', $_POST['exclude_members']) : array();
        $context['recipients']['groups'] = !empty($_POST['groups']) ? explode(',', $_POST['groups']) : array();
        $context['recipients']['exclude_groups'] = !empty($_POST['exclude_groups']) ? explode(',', $_POST['exclude_groups']) : array();
        $context['recipients']['emails'] = !empty($_POST['emails']) ? explode(';', $_POST['emails']) : array();
        $context['email_force'] = !empty($_POST['email_force']) ? 1 : 0;
        $context['total_emails'] = !empty($_POST['total_emails']) ? (int) $_POST['total_emails'] : 0;
        $context['max_id_member'] = !empty($_POST['max_id_member']) ? (int) $_POST['max_id_member'] : 0;
        $context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0;
        $context['send_html'] = !empty($_POST['send_html']) ? '1' : '0';
        return prepareMailingForPreview();
    }
    // Start by finding any members!
    $toClean = array();
    if (!empty($_POST['members'])) {
        $toClean[] = 'members';
    }
    if (!empty($_POST['exclude_members'])) {
        $toClean[] = 'exclude_members';
    }
    if (!empty($toClean)) {
        require_once $sourcedir . '/Subs-Auth.php';
        foreach ($toClean as $type) {
            // Remove the quotes.
            $_POST[$type] = strtr($_POST[$type], array('\\"' => '"'));
            preg_match_all('~"([^"]+)"~', $_POST[$type], $matches);
            $_POST[$type] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST[$type]))));
            foreach ($_POST[$type] as $index => $member) {
                if (strlen(trim($member)) > 0) {
                    $_POST[$type][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($member)));
                } else {
                    unset($_POST[$type][$index]);
                }
            }
            // Find the members
            $_POST[$type] = implode(',', array_keys(findMembers($_POST[$type])));
        }
    }
    if (isset($_POST['member_list']) && is_array($_POST['member_list'])) {
        $members = array();
        foreach ($_POST['member_list'] as $member_id) {
            $members[] = (int) $member_id;
        }
        $_POST['members'] = implode(',', $members);
    }
    if (isset($_POST['exclude_member_list']) && is_array($_POST['exclude_member_list'])) {
        $members = array();
        foreach ($_POST['exclude_member_list'] as $member_id) {
            $members[] = (int) $member_id;
        }
        $_POST['exclude_members'] = implode(',', $members);
    }
    // Clean the other vars.
    SendMailing(true);
    // We need a couple strings from the email template file
    loadLanguage('EmailTemplates');
    // Get a list of all full banned users.  Use their Username and email to find them.  Only get the ones that can't login to turn off notification.
    $request = $smcFunc['db_query']('', '
		SELECT DISTINCT mem.id_member
		FROM {db_prefix}ban_groups AS bg
			INNER JOIN {db_prefix}ban_items AS bi ON (bg.id_ban_group = bi.id_ban_group)
			INNER JOIN {db_prefix}members AS mem ON (bi.id_member = mem.id_member)
		WHERE (bg.cannot_access = {int:cannot_access} OR bg.cannot_login = {int:cannot_login})
			AND (bg.expire_time IS NULL OR bg.expire_time > {int:current_time})', array('cannot_access' => 1, 'cannot_login' => 1, 'current_time' => time()));
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $context['recipients']['exclude_members'][] = $row['id_member'];
    }
    $smcFunc['db_free_result']($request);
    $request = $smcFunc['db_query']('', '
		SELECT DISTINCT bi.email_address
		FROM {db_prefix}ban_items AS bi
			INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group)
		WHERE (bg.cannot_access = {int:cannot_access} OR bg.cannot_login = {int:cannot_login})
			AND (COALESCE(bg.expire_time, 1=1) OR bg.expire_time > {int:current_time})
			AND bi.email_address != {string:blank_string}', array('cannot_access' => 1, 'cannot_login' => 1, 'current_time' => time(), 'blank_string' => ''));
    $condition_array = array();
    $condition_array_params = array();
    $count = 0;
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $condition_array[] = '{string:email_' . $count . '}';
        $condition_array_params['email_' . $count++] = $row['email_address'];
    }
    $smcFunc['db_free_result']($request);
    if (!empty($condition_array)) {
        $request = $smcFunc['db_query']('', '
			SELECT id_member
			FROM {db_prefix}members
			WHERE email_address IN(' . implode(', ', $condition_array) . ')', $condition_array_params);
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $context['recipients']['exclude_members'][] = $row['id_member'];
        }
        $smcFunc['db_free_result']($request);
    }
    // Did they select moderators - if so add them as specific members...
    if (!empty($context['recipients']['groups']) && in_array(3, $context['recipients']['groups']) || !empty($context['recipients']['exclude_groups']) && in_array(3, $context['recipients']['exclude_groups'])) {
        $request = $smcFunc['db_query']('', '
			SELECT DISTINCT mem.id_member AS identifier
			FROM {db_prefix}members AS mem
				INNER JOIN {db_prefix}moderators AS mods ON (mods.id_member = mem.id_member)
			WHERE mem.is_activated = {int:is_activated}', array('is_activated' => 1));
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            if (in_array(3, $context['recipients'])) {
                $context['recipients']['exclude_members'][] = $row['identifier'];
            } else {
                $context['recipients']['members'][] = $row['identifier'];
            }
        }
        $smcFunc['db_free_result']($request);
    }
    // For progress bar!
    $context['total_emails'] = count($context['recipients']['emails']);
    $request = $smcFunc['db_query']('', '
		SELECT MAX(id_member)
		FROM {db_prefix}members', array());
    list($context['max_id_member']) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
    // Clean up the arrays.
    $context['recipients']['members'] = array_unique($context['recipients']['members']);
    $context['recipients']['exclude_members'] = array_unique($context['recipients']['exclude_members']);
}