function tin_newsletter_weekly_event() { if (ot_get_option('newsletter') == 'on') { global $wpdb; date_default_timezone_set('Asia/Shanghai'); $newsletter_posts = $wpdb->get_results("SELECT DISTINCT {$wpdb->posts}.ID FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' AND post_date > date_sub( NOW(), INTERVAL 1 WEEK ) ORDER BY post_date DESC"); $arr = array(); if (!empty($newsletter_posts)) { foreach ($newsletter_posts as $post) { $the_post_id_array[] = $post->ID; $arr = $the_post_id_array; } $str = implode('|', $arr); $issue_meta = get_tin_meta('issue'); $issue_meta_arr = explode(',', $issue_meta); if (in_array($str, $issue_meta_arr)) { return; } if (!empty($issue_meta)) { $issue_meta .= ',' . $str; } else { $issue_meta = $str; } update_tin_meta('issue', $issue_meta); $issue_meta = get_tin_meta('issue'); $issue_meta_array = explode(',', $issue_meta); $issue_num = count($issue_meta_array); //获取newsletter $html = newsletter_posts_issue($issue_num, 1); //获取订阅用户 $subscribers = get_tin_meta('tin_dl_users'); $subscribers2 = get_tin_meta('tin_subscribers'); if (!empty($subscribers)) { $subscribers .= ',' . $subscribers2; } else { $subscribers = $subscribers2; } $subscribers_array = explode(',', $subscribers); //循环发送 if (!empty($subscribers_array)) { $wp_email = 'no-reply@' . preg_replace('#^www\\.#', '', strtolower($_SERVER['SERVER_NAME'])); $from = "From: \"" . $name . "\" <{$wp_email}>"; $headers = "{$from}\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n"; $title = get_bloginfo('name') . '邮件周刊(第' . $issue_num . '期)'; foreach ($subscribers_array as $subscriber) { wp_mail($subscriber, $title, $html, $headers); } } else { return; } } else { return; } } else { return; } }
update_tin_meta('tin_dlusers', $tin_dlusers); $tin_subscribers = get_tin_meta('tin_subscribers'); $tin_subscribers = tin_delete_string_specific_value(',', $tin_subscribers, $_GET['email']); update_tin_meta('tin_subscribers', $tin_subscribers); $content = '<div style="min-height:300px;">' . __('退订成功!', 'tinection') . '</div>'; } else { $content = '<div style="min-height:300px;">' . __('退订失败,你可能已经退订,或请重新再试!', 'tinection') . '</div>'; } } elseif (isset($_GET['action']) && $_GET['action'] == 'subscribe') { $title = __('邮件订阅', 'tinection'); $content = newsletter_subscribe_template(); } else { $issue = $length; $title = __('邮件周刊(No.', 'tinection') . $issue . ')'; $content = tin_past_issues_selection(); $content .= newsletter_posts_issue($issue); } ?> <html> <title><?php echo $title; ?> - <?php bloginfo('name'); ?> </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!-- Main Wrap --> <div id="main-wrap" style="padding-top:20px;padding-bottom:20px;"> <?php echo $content;