email = $table_prefix . 'email';
### Function: E-Mail Administration Menu
add_action('admin_menu', 'email_menu');
function email_menu() {
if (function_exists('add_menu_page')) {
add_menu_page(__('E-Mail', 'wp-email'), __('E-Mail', 'wp-email'), 'manage_email', 'email/email-manager.php');
}
if (function_exists('add_submenu_page')) {
add_submenu_page('email/email-manager.php', __('Manage E-Mail', 'wp-email'), __('Manage E-Mail', 'wp-email'), 'manage_email', 'email/email-manager.php');
add_submenu_page('email/email-manager.php', __('E-Mail Options', 'wp-email'), __('E-Mail Options', 'wp-email'), 'manage_email', 'email/email-options.php');
}
}
### Function: E-Mail htaccess ReWrite Rules
add_filter('generate_rewrite_rules', 'email_rewrite');
function email_rewrite($wp_rewrite) {
// WP-EMail Rules
$rewrite_rules2 = $wp_rewrite->generate_rewrite_rule($wp_rewrite->permalink_structure.'email');
array_splice($rewrite_rules2, 1);
$r_rule = array_keys($rewrite_rules2);
$r_rule = array_shift($r_rule);
$r_rule = str_replace('/trackback', '', $r_rule);
$r_link = array_values($rewrite_rules2);
$r_link = array_shift($r_link);
$r_link = str_replace('tb=1', 'email=1', $r_link);
$email_rules = array($r_rule => $r_link, '(.+)/emailpage/?$' => 'index.php?pagename='.$wp_rewrite->preg_index(1).'&email=1');
$wp_rewrite->rules = $email_rules + $wp_rewrite->rules;
// WP-EMail PopUp Rules
$rewrite_rules3 = $wp_rewrite->generate_rewrite_rule($wp_rewrite->permalink_structure.'emailpopup');
array_splice($rewrite_rules3, 1);
$r_rule2 = array_keys($rewrite_rules3);
$r_rule2 = array_shift($r_rule2);
$r_rule2 = str_replace('/trackback', '', $r_rule2);
$r_link2 = array_values($rewrite_rules3);
$r_link2 = array_shift($r_link2);
$r_link2 = str_replace('tb=1', 'emailpopup=1', $r_link2);
$emailpopup_rules = array($r_rule2 => $r_link2, '(.+)/emailpopuppage/?$' => 'index.php?pagename='.$wp_rewrite->preg_index(1).'&emailpopup=1');
$wp_rewrite->rules = $emailpopup_rules + $wp_rewrite->rules;
}
### Function: E-Mail Public Variables
add_filter('query_vars', 'email_variables');
function email_variables($public_query_vars) {
$public_query_vars[] = 'email';
$public_query_vars[] = 'emailpopup';
return $public_query_vars;
}
### Function: E-Mail Javascript
add_action('wp_head', 'email_js');
function email_js() {
echo "\n".''."\n";
echo ''."\n";
echo ''."\n";
echo ''."\n";
}
### Function: Display E-Mail Link
function email_link($deprecated = '', $deprecated2 ='', $echo = true) {
global $id;
$output = '';
$using_permalink = get_option('permalink_structure');
$email_options = get_option('email_options');
$email_style = intval($email_options['email_style']);
$email_type = intval($email_options['email_type']);
$email_text = stripslashes($email_options['post_text']);
$email_icon = get_option('siteurl').'/wp-content/plugins/email/images/'.$email_options['email_icon'];
$email_link = get_permalink();
$email_html = stripslashes($email_options['email_html']);
$onclick = '';
// Fix For Static Page
if(get_option('show_on_front') == 'page' && is_page()) {
if(intval(get_option('page_on_front')) > 0) {
$email_link = _get_page_link();
}
}
switch($email_type) {
// E-Mail Standalone Page
case 1:
if(!empty($using_permalink)) {
if(is_page()) {
if(substr($email_link, -1, 1) != '/') {
$email_link= $email_link.'/';
}
$email_text = stripslashes($email_options['page_text']);
$email_link = $email_link.'emailpage/';
} else {
$email_link = $email_link.'email/';
}
} else {
if(is_page()) {
$email_text = stripslashes($email_options['page_text']);
}
$email_link = $email_link.'&email=1';
}
break;
// E-Mail Popup
case 2:
if(!empty($using_permalink)) {
if(is_page()) {
if(substr($email_link, -1, 1) != '/') {
$email_link= $email_link.'/';
}
$email_text = stripslashes($email_options['page_text']);
$email_link = $email_link.'emailpopuppage/';
} else {
$email_link = $email_link.'emailpopup/';
}
} else {
if(is_page()) {
$email_text = stripslashes($email_options['page_text']);
}
$email_link = $email_link.'&emailpopup=1';
}
$onclick = ' onclick="email_popup(this.href); return false;" ';
break;
}
unset($email_options);
switch($email_style) {
// Icon + Text Link
case 1:
$output = ' '.$email_text.'';
break;
// Icon Only
case 2:
$output = '
';
break;
// Text Link Only
case 3:
$output = ''.$email_text.'';
break;
case 4:
$email_html = str_replace("%EMAIL_URL%", $email_link, $email_html);
$email_html = str_replace("%EMAIL_POPUP%", $onclick, $email_html);
$email_html = str_replace("%EMAIL_TEXT%", $email_text, $email_html);
$email_html = str_replace("%EMAIL_ICON_URL%", $email_icon, $email_html);
$output = $email_html;
break;
}
if($echo) {
echo $output."\n";
} else {
return $output;
}
}
### Function: Deprecated Functions
function email_link_image() { email_link(); }
function email_popup($deprecated = '', $deprecated2 ='') { email_link(); }
function email_popup_image() { email_link(); }
### Function: Place E-Mail Link
add_filter('the_content', 'place_emaillink', 7);
function place_emaillink($content){
if(!is_feed()) {
$content = str_replace("[email_link]", email_link('', '', false), $content);
} else {
$content = str_replace("[email_link]", __('Note: You can email this post by visiting the site.', 'wp-email'), $content);
}
return $content;
}
### Function: Snippet Text
if(!function_exists('snippet_chars')) {
function snippet_chars($text, $length = 0) {
$text = htmlspecialchars_decode($text);
if (strlen($text) > $length){
return htmlspecialchars(substr($text,0,$length)).'...';
} else {
return htmlspecialchars($text);
}
}
}
### Function: HTML Special Chars Decode
if (!function_exists('htmlspecialchars_decode')) {
function htmlspecialchars_decode($text) {
return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
}
}
### Function: Add E-Mail Filters
function email_addfilters() {
global $added_emailfilters;
if(!$added_emailfilters) {
add_filter('the_title', 'email_title');
add_filter('the_content', 'email_form', '', false, false);
$added_emailfilters = true;
}
}
### Function: Remove E-Mail Filters
function email_removefilters() {
remove_filter('the_title', 'email_title');
remove_filter('the_content', 'email_form');
}
### Function: E-Mail Page Title
function email_pagetitle($page_title) {
$page_title = '» '.__('E-Mail', 'wp-email').$page_title;
return $page_title;
}
### Function: E-Mail Post ID
if(!function_exists('get_the_id')) {
function get_the_id() {
global $id;
return $id;
}
}
### Function: E-Mail Title
function email_title($page_title) {
global $email_title_once;
if(in_the_loop()) {
$post_title = get_the_title();
$post_author = the_author('', false);
$post_date = get_the_time(get_option('date_format').' ('.get_option('time_format').')', '', '', false);
$post_category = email_category();
$post_category_alt = strip_tags($post_category);
$template_title = stripslashes(get_option('email_template_title'));
$template_title = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_title);
$template_title = str_replace("%EMAIL_POST_AUTHOR%", $post_author, $template_title);
$template_title = str_replace("%EMAIL_POST_DATE%", $post_date, $template_title);
$template_title = str_replace("%EMAIL_POST_CATEGORY%", $post_category, $template_title);
$template_title = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_title);
$template_title = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_title);
$template_title = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_title);
return $template_title;
} else {
return $page_title;
}
}
### Function: E-Mail Category
function email_category($separator = ', ', $parents='') {
return get_the_category_list($separator, $parents);
}
### Function: E-Mail Content
function email_content() {
$content = get_email_content();
$content = str_replace(']]>', ']]>', $content);
$email_snippet = intval(get_option('email_snippet'));
if($email_snippet > 0) {
return snippet_chars($content , $email_snippet);
} else {
return $content;
}
}
### Function: E-Mail Alternate Content
function email_content_alt() {
remove_filter('the_content', 'wptexturize');
$content = get_email_content();
$content = clean_pre($content);
$content = strip_tags($content);
$email_snippet = intval(get_option('email_snippet'));
if($email_snippet > 0) {
return snippet_chars($content , $email_snippet);
} else {
return $content;
}
}
### Function: E-Mail Get The Content
function get_email_content() {
global $pages, $multipage, $numpages, $post;
if (!empty($post->post_password)) {
if (stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) {
return __('Password Protected Post', 'wp-email');
}
}
if($multipage) {
for($page = 0; $page < $numpages; $page++) {
$content .= $pages[$page];
}
} else {
$content = $pages[0];
}
$content = apply_filters('the_content', $content);
return $content;
}
### Function: Get IP Address
function get_email_ipaddress() {
if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$ip_address = $_SERVER["REMOTE_ADDR"];
} else {
$ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
if(strpos($ip_address, ',') !== false) {
$ip_address = explode(',', $ip_address);
$ip_address = $ip_address[0];
}
return $ip_address;
}
### Function: Check For Password Protected Post
function not_password_protected() {
global $post;
if (!empty($post->post_password)) {
if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) {
return false;
}
}
return true;
}
### Function: Check Vaild Name (AlphaNumeric With Spaces Allowed Only)
if(!function_exists('is_valid_name')) {
function is_valid_name($name) {
if(ereg('[^[:space:]a-zA-Z0-9]', $name)) {
return false;
} else {
return true;
}
}
}
### Function: Check Valid E-Mail Address
if(!function_exists('is_valid_email')) {
function is_valid_email($email) {
$regex = '/^[A-z0-9][\w.-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}$/';
return (preg_match($regex, $email));
}
}
### Function: Check Valid Remarks (Ensure No E-Mail Injections)
if(!function_exists('is_valid_remarks')) {
function is_valid_remarks($content) {
$injection_strings = array('apparently-to', 'cc', 'bcc', 'boundary', 'charset', 'content-disposition', 'content-type', 'content-transfer-encoding', 'errors-to', 'in-reply-to', 'message-id', 'mime-version', 'multipart/mixed', 'multipart/alternative', 'multipart/related', 'reply-to', 'x-mailer', 'x-sender', 'x-uidl');
foreach ($injection_strings as $spam) {
$check = strpos(strtolower($content), $spam);
if ($check !== false) {
return false;
}
}
return true;
}
}
### Function: Check For E-Mail Spamming
function not_spamming() {
global $wpdb;
$current_time = current_time('timestamp');
$email_ip = get_email_ipaddress();
$email_host = @gethostbyaddr($email_ip);
$email_status = __('Success', 'wp-email');
$last_emailed = $wpdb->get_var("SELECT email_timestamp FROM $wpdb->email WHERE email_ip = '$email_ip' AND email_host = '$email_host' AND email_status = '$email_status' ORDER BY email_timestamp DESC LIMIT 1");
$email_allow_interval = intval(get_option('email_interval'))*60;
if(($current_time-$last_emailed) < $email_allow_interval) {
return false;
} else {
return true;
}
}
### Function: E-Mail Flood Interval
function email_flood_interval($echo = true) {
$email_allow_interval_min = intval(get_option('email_interval'));
if($echo) {
echo $email_allow_interval_min;
} else {
return $email_allow_interval_min;
}
}
### Function: E-Mail Form Header
function email_form_header($echo = true) {
global $id;
$using_permalink = get_option('permalink_structure');
$permalink = get_permalink();
// Fix For Static Page
if(get_option('show_on_front') == 'page' && is_page()) {
if(intval(get_option('page_on_front')) > 0) {
$permalink = _get_page_link();
}
}
$output = '';
if(!empty($using_permalink)) {
if(is_page()) {
$output .= '