芝麻web文件管理V1.00
编辑当前文件:/home4/randall/public_html/sl/wp-content/plugins/trx_utils/tools/emailer/emailer.php
subscribers = lorem_ipsum_books_media_store_emailer_group_getlist(); } //----------------------------------------------------------------------------------- // Admin Interface //----------------------------------------------------------------------------------- function admin_menu_item() { if ( current_user_can( 'manage_options' ) ) { // 'theme' - add in the 'Appearance' // 'management' - add in the 'Tools' lorem_ipsum_books_media_store_admin_add_menu_item('theme', array( 'page_title' => esc_html__('Emailer', 'trx_utils'), 'menu_title' => esc_html__('Emailer', 'trx_utils'), 'capability' => 'manage_options', 'menu_slug' => 'trx_emailer', 'callback' => array($this, 'build_page'), ) ); } } //----------------------------------------------------------------------------------- // Load required styles and scripts //----------------------------------------------------------------------------------- function load_scripts() { if (isset($_REQUEST['page']) && $_REQUEST['page']=='trx_emailer') { wp_enqueue_style('trx-emailer-style', trx_utils_get_file_url('tools/emailer/emailer.css'), array(), null); wp_deregister_style('jquery_ui'); wp_deregister_style('date-picker-css'); wp_enqueue_script('jquery-ui-core', false, array('jquery'), null, true); wp_enqueue_script('jquery-ui-tabs', false, array('jquery', 'jquery-ui-core'), null, true); wp_enqueue_script('trx-emailer-script', trx_utils_get_file_url('tools/emailer/emailer.js'), array('jquery'), null, true); wp_localize_script( 'trx-emailer-script', 'LOREM_IPSUM_BOOKS_MEDIA_STORE_EMAILER', array( 'ajax_nonce' => wp_create_nonce(admin_url('admin-ajax.php')), 'ajax_url' => esc_url(admin_url('admin-ajax.php')), 'ajax_error' => esc_html__('Invalid server answer!', 'trx_utils') ) ); } } //----------------------------------------------------------------------------------- // Build the Main Page //----------------------------------------------------------------------------------- function build_page() { $mail = lorem_ipsum_books_media_store_get_theme_option('mail_function'); $subject = $message = $attach = $group = $sender_name = $sender_email = ''; $subscribers_update = $subscribers_delete = $subscribers_clear = false; $subscribers = array(); if ( isset($_POST['emailer_subject']) ) { do { // Check nonce if ( !wp_verify_nonce( lorem_ipsum_books_media_store_get_value_gp('nonce'), admin_url('admin-ajax.php') ) ) { $this->error = esc_html__('Incorrect WP-nonce data! Operation canceled!', 'trx_utils'); break; } // Get post data $subject = lorem_ipsum_books_media_store_get_value_gp('emailer_subject'); if (empty($subject)) { $this->error = esc_html__('Subject can not be empty! Operation canceled!', 'trx_utils'); break; } $message = lorem_ipsum_books_media_store_get_value_gp('emailer_message'); if (empty($message)) { $this->error = esc_html__('Message can not be empty! Operation canceled!', 'trx_utils'); break; } $attach = isset($_FILES['emailer_attachment']['tmp_name']) && file_exists($_FILES['emailer_attachment']['tmp_name']) ? $_FILES['emailer_attachment']['tmp_name'] : ''; $group = lorem_ipsum_books_media_store_get_value_gp('emailer_group'); $subscribers = lorem_ipsum_books_media_store_get_value_gp('emailer_subscribers'); if (!empty($subscribers)) $subscribers = explode("\n", str_replace(array(';', ','), array("\n", "\n"), $subscribers)); else $subscribers = array(); if (count($subscribers)==0) { $this->error = esc_html__('Subscribers lists are empty! Operation canceled!', 'trx_utils'); break; } $sender_name = lorem_ipsum_books_media_store_get_value_gp('emailer_sender_name', get_bloginfo('name')); $sender_email = lorem_ipsum_books_media_store_get_value_gp('emailer_sender_email'); if (empty($sender_email)) $sender_email = lorem_ipsum_books_media_store_get_theme_option('contact_email'); if (empty($sender_email)) $sender_email = get_bloginfo('admin_email'); if (empty($sender_email)) { $this->error = esc_html__('Sender email is empty! Operation canceled!', 'trx_utils'); break; } $headers = 'From: ' . strip_tags($sender_name) . ' <' . trim($sender_email) . '>' . "\r\n" . 'Content-Type: text/html; charset=UTF-8' . "\r\n"; $subscribers_update = isset($_POST['emailer_subscribers_update']); $subscribers_delete = isset($_POST['emailer_subscribers_delete']); $subscribers_clear = isset($_POST['emailer_subscribers_clear']); // Send email $new_list = array(); $list = array(); $cnt = 0; if (is_array($subscribers) && count($subscribers) > 0) { foreach ($subscribers as $email) { $email = trim(chop($email)); if (empty($email)) continue; if (!preg_match('/[\.\-_A-Za-z0-9]+?@[\.\-A-Za-z0-9]+?[\ .A-Za-z0-9]{2,}/', $email)) continue; $list[] = $email; $cnt++; if ($cnt >= $this->max_recipients_in_one_letter) { $rez = $mail == 'mail' ? @mail( join(',', $list), $subject, $message, $headers) : @wp_mail( $list, $subject, $message, $headers, $attach ); if (!$rez) { $err_msg = esc_html__('Error occured when send message!', 'trx_utils'); $cnt = 0; break; } if ($subscribers_update && $group!='none') $new_list = array_merge($new_list, $list); $list = array(); $cnt = 0; } } } $add_msg = $err_msg = ''; if ($cnt > 0) { $rez = $mail == 'mail' ? @mail( join(',', $list), $subject, $message, $headers) : @wp_mail( $list, $subject, $message, $headers, $attach ); if (!$rez) $err_msg = esc_html__('Error occured when send message!', 'trx_utils'); if ($subscribers_update && $group!='none') $new_list = array_merge($new_list, $list); $list = array(); $cnt = 0; } if ($subscribers_update && $group!='none') { $rez = array(); if (is_array($this->subscribers[$group]) && count($this->subscribers[$group]) > 0) { foreach ($this->subscribers[$group] as $k=>$v) { if (!$subscribers_clear && !empty($v)) $rez[$k] = $v; } } if (is_array($new_list) && count($new_list) > 0) { foreach ($new_list as $v) { $rez[$v] = ''; } } $this->subscribers[$group] = $rez; update_option(lorem_ipsum_books_media_store_storage_get('options_prefix') . '_emailer_subscribers', $this->subscribers); $add_msg .= esc_html__('The subscriber list is updated', 'trx_utils'); } else if ($subscribers_delete && $group!='none') { unset($this->subscribers[$group]); update_option(lorem_ipsum_books_media_store_storage_get('options_prefix') . '_emailer_subscribers', $this->subscribers); $add_msg .= esc_html__('The subscriber list is cleared', 'trx_utils'); } if ($err_msg) $this->error = $err_msg; else $this->success = esc_html__('E-Mail was send successfull!', 'trx_utils') . ($add_msg ? ' '.trim($add_msg) : ''); } while (false); } ?>
error)) { ?>
error); ?>
success)) { ?>
success); ?>
false, 'textarea_rows' => 10 )); ?>
>
subscribers) && count($this->subscribers) > 0) { foreach ($this->subscribers as $gr=>$list) { echo '
'.lorem_ipsum_books_media_store_strtoproper($gr).'
'; } } ?>
/>
/>
/>
</textarea>
''); $group = $_REQUEST['group']; $email = $_REQUEST['email']; if (preg_match('/[\.\-_A-Za-z0-9]+?@[\.\-A-Za-z0-9]+?[\ .A-Za-z0-9]{2,}/', $email)) { $subscribers = lorem_ipsum_books_media_store_emailer_group_getlist($group); if (isset($subscribers[$group][$email])) $response['error'] = esc_html__('E-mail address already in the subscribers list!', 'trx_utils'); else { $subscribers[$group][$email] = md5(mt_rand()); update_option(lorem_ipsum_books_media_store_storage_get('options_prefix') . '_emailer_subscribers', $subscribers); $subj = sprintf(esc_html__('Site %s - Subscribe confirmation', 'trx_utils'), get_bloginfo('site_name')); $url = admin_url('admin-ajax.php'); $link = $url . (lorem_ipsum_books_media_store_strpos($url, '?')===false ? '?' : '') . 'action=emailer_confirm&nonce='.urlencode($subscribers[$group][$email]).'&email='.urlencode($email).'&group='.urlencode($group); $msg = wp_kses( sprintf(__("You or someone else added this e-mail address into our subcribtion list.\nPlease, confirm your wish to receive newsletters from our website by clicking on the link below:\n\n
%s
\n\nIf you do not wiish to subscribe to our newsletters, simply ignore this message.", 'trx_utils'), $link, $link) ); $sender_name = get_bloginfo('name'); $sender_email = lorem_ipsum_books_media_store_get_theme_option('contact_email'); if (empty($sender_email)) $sender_email = get_bloginfo('admin_email'); $headers = 'From: ' . strip_tags($sender_name).' <' . trim($sender_email) . '>' . "\r\n" . 'Content-Type: text/html' . "\r\n"; $mail = lorem_ipsum_books_media_store_get_theme_option('mail_function'); $rez = $mail == 'mail' ? @mail( $email, $subj, nl2br($msg), $headers) : @wp_mail( $email, $subj, nl2br($msg), $headers ); if (!$rez) { $response['error'] = esc_html__('Error send message!', 'trx_utils'); } } } else $response['error'] = esc_html__('E-mail address is not valid!', 'trx_utils'); echo json_encode($response); die(); } } // Confirm e-mail in subscribe list if ( !function_exists( 'lorem_ipsum_books_media_store_callback_emailer_confirm' ) ) { function lorem_ipsum_books_media_store_callback_emailer_confirm() { $group = $_REQUEST['group']; $email = $_REQUEST['email']; $nonce = $_REQUEST['nonce']; if (preg_match('/[\.\-_A-Za-z0-9]+?@[\.\-A-Za-z0-9]+?[\ .A-Za-z0-9]{2,}/', $email)) { $subscribers = lorem_ipsum_books_media_store_emailer_group_getlist($group); if (isset($subscribers[$group][$email])) { if ($subscribers[$group][$email] == $nonce) { $subscribers[$group][$email] = ''; update_option(lorem_ipsum_books_media_store_storage_get('options_prefix') . '_emailer_subscribers', $subscribers); lorem_ipsum_books_media_store_set_system_message(esc_html__('Confirmation complete! E-mail address succefully added in the subscribers list!', 'trx_utils'), 'success'); //header('Location: '.home_url('/')); wp_safe_redirect( home_url('/') ); } else if ($subscribers[$group][$email] != '') { lorem_ipsum_books_media_store_set_system_message(esc_html__('Bad confirmation code!', 'trx_utils'), 'error'); //header('Location: '.home_url('/')); wp_safe_redirect( home_url('/') ); } else { lorem_ipsum_books_media_store_set_system_message(esc_html__('E-mail address already exists in the subscribers list!', 'trx_utils'), 'error'); //header('Location: '.home_url('/')); wp_safe_redirect( home_url('/') ); } } } die(); } } // Get subscribers list if group changed if ( !function_exists( 'lorem_ipsum_books_media_store_callback_emailer_group_getlist' ) ) { function lorem_ipsum_books_media_store_callback_emailer_group_getlist() { if ( !wp_verify_nonce( lorem_ipsum_books_media_store_get_value_gp('nonce'), admin_url('admin-ajax.php') ) ) die(); $response = array('error'=>'', 'subscribers' => ''); $group = $_REQUEST['group']; $subscribers = lorem_ipsum_books_media_store_emailer_group_getlist($group); $list = array(); if (isset($subscribers[$group]) && is_array($subscribers[$group]) && count($subscribers[$group]) > 0) { foreach ($subscribers[$group] as $k=>$v) { if (empty($v)) $list[] = $k; } } $response['subscribers'] = join("\n", $list); echo json_encode($response); die(); } } // Get Subscribers list if ( !function_exists( 'lorem_ipsum_books_media_store_emailer_group_getlist' ) ) { function lorem_ipsum_books_media_store_emailer_group_getlist($group='') { $subscribers = get_option(lorem_ipsum_books_media_store_storage_get('options_prefix') . '_emailer_subscribers', array()); if (!is_array($subscribers)) $subscribers = array(); if (!empty($group) && (!isset($subscribers[$group]) || !is_array($subscribers[$group]))) $subscribers[$group] = array(); if (is_array($subscribers) && count($subscribers) > 0) { $need_save = false; foreach ($subscribers as $grp=>$list) { if (isset($list[0])) { // Plain array - old format - convert it $rez = array(); foreach ($list as $v) { $rez[$v] = ''; } $subscribers[$grp] = $rez; $need_save = true; } } if ($need_save) update_option(lorem_ipsum_books_media_store_storage_get('options_prefix') . '_emailer_subscribers', $subscribers); } return $subscribers; } } ?>