예제 #1
0
function fn_update_newsletter($newsletter_data, $newsletter_id = 0, $lang_code = CART_LANGUAGE)
{
    if (empty($newsletter_id)) {
        if (empty($newsletter_data['newsletter'])) {
            return false;
        }
        if (empty($newsletter_data['mailing_lists'])) {
            $newsletter_data['mailing_lists'] = array();
        }
        $_data = $newsletter_data;
        $_data['mailing_lists'] = implode(',', $_data['mailing_lists']);
        $newsletter_id = db_query("INSERT INTO ?:newsletters ?e", $_data);
        if (empty($newsletter_id)) {
            return false;
        }
        //
        // Adding news description
        //
        $_data['newsletter_id'] = $newsletter_id;
        foreach ((array) Registry::get('languages') as $_data['lang_code'] => $v) {
            db_query("INSERT INTO ?:newsletter_descriptions ?e", $_data);
        }
    } else {
        // we do not need empty title
        if (empty($newsletter_data['newsletter'])) {
            unset($newsletter_data['newsletter']);
        }
        if (empty($newsletter_data['mailing_lists'])) {
            $newsletter_data['mailing_lists'] = array();
        }
        if (empty($newsletter_data['users'])) {
            $newsletter_data['users'] = '';
        }
        //Override if there is "All" user - 29.01.2015 - MLazarev
        if (in_array("All", explode(',', $newsletter_data['users']))) {
            $user_recipients = db_get_fields("SELECT user_id FROM ?:users ");
            $newsletter_data['users'] = implode(',', $user_recipients);
        }
        $_data = $newsletter_data;
        $_data['mailing_lists'] = implode(',', $_data['mailing_lists']);
        db_query("UPDATE ?:newsletters SET ?u WHERE newsletter_id = ?i", $_data, $newsletter_id);
        // update news descriptions
        db_query("UPDATE ?:newsletter_descriptions SET ?u WHERE newsletter_id=?i AND lang_code=?s", $_data, $newsletter_id, $lang_code);
    }
    if (isset($newsletter_data['campaign_id'])) {
        // for link tracking (to count user clicks on links in our newsletters) we need to rewrite urls in the newsletter.
        fn_rewrite_links($newsletter_data['body_txt'], $newsletter_data['body_html'], $newsletter_id, $newsletter_data['campaign_id']);
    }
    fn_set_hook('update_newsletter', $newsletter_data, $newsletter_id);
    return $newsletter_id;
}
예제 #2
0
function fn_update_newsletter($newsletter_data, $newsletter_id = 0, $lang_code = DESCR_SL)
{
    if (empty($newsletter_data['mailing_lists'])) {
        $newsletter_data['mailing_lists'] = array();
    }
    if (empty($newsletter_id)) {
        if (empty($newsletter_data['newsletter'])) {
            return false;
        }
        $_data = $newsletter_data;
        $_data['mailing_lists'] = implode(',', $_data['mailing_lists']);
        $newsletter_id = db_query("INSERT INTO ?:newsletters ?e", $_data);
        if (empty($newsletter_id)) {
            return false;
        }
        $_data['newsletter_id'] = $newsletter_id;
        foreach (fn_get_translation_languages() as $_data['lang_code'] => $v) {
            db_query("INSERT INTO ?:newsletter_descriptions ?e", $_data);
        }
    } else {
        // we do not need empty title
        if (empty($newsletter_data['newsletter'])) {
            unset($newsletter_data['newsletter']);
        }
        if (empty($newsletter_data['users'])) {
            $newsletter_data['users'] = '';
        }
        $_data = $newsletter_data;
        $_data['mailing_lists'] = implode(',', $_data['mailing_lists']);
        db_query("UPDATE ?:newsletters SET ?u WHERE newsletter_id = ?i", $_data, $newsletter_id);
        db_query("UPDATE ?:newsletter_descriptions SET ?u WHERE newsletter_id=?i AND lang_code=?s", $_data, $newsletter_id, $lang_code);
    }
    if (isset($newsletter_data['campaign_id'])) {
        // for link tracking (to count user clicks on links in our newsletters) we need to rewrite urls in the newsletter.
        fn_rewrite_links($newsletter_data['body_html'], $newsletter_id, $newsletter_data['campaign_id']);
    }
    fn_set_hook('update_newsletter', $newsletter_data, $newsletter_id);
    return $newsletter_id;
}
예제 #3
0
    }
    return array(CONTROLLER_STATUS_OK, "newsletters" . $suffix);
}
if ($mode == 'batch_send' && !empty($_REQUEST['cache_file'])) {
    $data = fn_get_contents(DIR_COMPILED . $_REQUEST['cache_file']);
    if (!empty($data)) {
        $data = @unserialize($data);
    }
    if (is_array($data)) {
        // Ger newsletter data
        $newsletter_data = array();
        foreach ($data['send_ids'] as $newsletter_id) {
            $n = array();
            foreach ((array) Registry::get('languages') as $lang_code => $v) {
                $n[$lang_code] = fn_get_newsletter_data($newsletter_id, $lang_code);
                list($n[$lang_code]['body_txt'], $n[$lang_code]['body_html']) = fn_rewrite_links($n[$lang_code]['body_txt'], $n[$lang_code]['body_html'], $newsletter_id, $n[$lang_code]['campaign_id']);
            }
            $newsletter_data[] = $n;
        }
        foreach (array_splice($data['recipients'], 0, Registry::get('addons.news_and_emails.newsletters_per_pass')) as $subscriber) {
            foreach ($newsletter_data as $newsletter) {
                if ($subscriber['format'] == NEWSLETTER_FORMAT_TXT || empty($newsletter[$subscriber['lang_code']]['body_html']) && !empty($subscriber['users_list']) && $subscriber['users_list'] == 'Y') {
                    $body = fn_render_newsletter($newsletter[$subscriber['lang_code']]['body_txt'], $subscriber);
                    $subscriber['format'] = NEWSLETTER_FORMAT_TXT;
                } else {
                    $body = fn_render_newsletter($newsletter[$subscriber['lang_code']]['body_html'], $subscriber);
                }
                fn_echo(str_replace('[email]', $subscriber['email'], fn_get_lang_var('sending_email_to')) . '<br />');
                fn_override_mailer();
                if (!empty($newsletter[$subscriber['lang_code']]['newsletter_multiple'])) {
                    $subjects = explode("\n", $newsletter[$subscriber['lang_code']]['newsletter_multiple']);