email = $wpdb->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', 'wp-email/email-manager.php');
}
if (function_exists('add_submenu_page')) {
add_submenu_page('wp-email/email-manager.php', __('Manage E-Mail', 'wp-email'), __('Manage E-Mail', 'wp-email'), 'manage_email', 'wp-email/email-manager.php');
add_submenu_page('wp-email/email-manager.php', __('E-Mail Options', 'wp-email'), __('E-Mail Options', 'wp-email'), 'manage_email', 'wp-email/email-options.php');
add_submenu_page('wp-email/email-manager.php', __('Uninstall WP-EMail', 'wp-email'), __('Uninstall WP-EMail', 'wp-email'), 'manage_email', 'wp-email/email-uninstall.php');
}
}
### Function: E-Mail htaccess ReWrite Rules
add_filter('generate_rewrite_rules', 'email_rewrite');
function email_rewrite($wp_rewrite) {
$email_link = get_permalink();
$page_uris = $wp_rewrite->page_uri_index();
$uris = $page_uris[0];
if(substr($email_link, -1, 1) != '/' && substr($wp_rewrite->permalink_structure, -1, 1) != '/') {
$email_link_text = '/email';
$email_popup_text = '/emailpopup';
} else {
$email_link_text = 'email';
$email_popup_text = 'emailpopup';
}
// WP-EMail Standalone Post Rules
$rewrite_rules = $wp_rewrite->generate_rewrite_rule($wp_rewrite->permalink_structure.$email_link_text, EP_PERMALINK);
$rewrite_rules = array_slice($rewrite_rules, 4, 1);
$r_rule = array_keys($rewrite_rules);
$r_rule = array_shift($r_rule);
$r_rule = str_replace('/trackback', '', $r_rule);
$r_link = array_values($rewrite_rules);
$r_link = array_shift($r_link);
$r_link = str_replace('tb=1', 'email=1', $r_link);
$wp_rewrite->rules = array_merge(array($r_rule => $r_link), $wp_rewrite->rules);
// WP-Email Standalone Page Rules
if(is_array($uris)) {
$email_page_rules = array();
foreach ($uris as $uri => $pagename) {
$wp_rewrite->add_rewrite_tag('%pagename%', "($uri)", 'pagename=');
$rewrite_rules = $wp_rewrite->generate_rewrite_rules($wp_rewrite->get_page_permastruct().'/emailpage', EP_PAGES);
$rewrite_rules = array_slice($rewrite_rules, 4, 1);
$r_rule = array_keys($rewrite_rules);
$r_rule = array_shift($r_rule);
$r_rule = str_replace('/trackback', '', $r_rule);
$r_link = array_values($rewrite_rules);
$r_link = array_shift($r_link);
$r_link = str_replace('tb=1', 'email=1', $r_link);
$email_page_rules = array_merge($email_page_rules, array($r_rule => $r_link));
}
$wp_rewrite->rules = array_merge($email_page_rules, $wp_rewrite->rules);
}
// WP-EMail Popup Post Rules
$rewrite_rules = $wp_rewrite->generate_rewrite_rule($wp_rewrite->permalink_structure.$email_popup_text, EP_PERMALINK);
$rewrite_rules = array_slice($rewrite_rules, 4, 1);
$r_rule = array_keys($rewrite_rules);
$r_rule = array_shift($r_rule);
$r_rule = str_replace('/trackback', '', $r_rule);
$r_link = array_values($rewrite_rules);
$r_link = array_shift($r_link);
$r_link = str_replace('tb=1', 'emailpopup=1', $r_link);
$wp_rewrite->rules = array_merge(array($r_rule => $r_link), $wp_rewrite->rules);
if(is_array($uris)) {
$email_page_rules = array();
foreach ($uris as $uri => $pagename) {
$wp_rewrite->add_rewrite_tag('%pagename%', "($uri)", 'pagename=');
$rewrite_rules = $wp_rewrite->generate_rewrite_rules($wp_rewrite->get_page_permastruct().'/emailpopuppage', EP_PAGES);
$rewrite_rules = array_slice($rewrite_rules, 4, 1);
$r_rule = array_keys($rewrite_rules);
$r_rule = array_shift($r_rule);
$r_rule = str_replace('/trackback', '', $r_rule);
$r_link = array_values($rewrite_rules);
$r_link = array_shift($r_link);
$r_link = str_replace('tb=1', 'emailpopup=1', $r_link);
$email_page_rules = array_merge($email_page_rules, array($r_rule => $r_link));
}
$wp_rewrite->rules = array_merge($email_page_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() {
$email_max = intval(get_option('email_multiple'));
echo "\n".''."\n";
echo ''."\n";
wp_register_script('wp-email', WP_PLUGIN_URL.'/wp-email/email-js-packed.js', false, '2.31');
wp_print_scripts(array('sack', 'wp-email'));
if(@file_exists(TEMPLATEPATH.'/email-css.css')) {
echo ''."\n";
} else {
echo ''."\n";
}
echo ''."\n";
}
### Function: Display E-Mail Link
function email_link($email_post_text = '', $email_page_text = '', $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']);
if(empty($email_post_text)) {
$email_text = stripslashes($email_options['post_text']);
} else {
$email_text = $email_post_text;
}
$email_icon = WP_PLUGIN_URL.'/wp-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(substr($email_link, -1, 1) != '/') {
$email_link= $email_link.'/';
}
if(is_page()) {
if(empty($email_page_text)) {
$email_text = stripslashes($email_options['page_text']);
} else {
$email_text = $email_page_text;
}
$email_link = $email_link.'emailpage/';
} else {
$email_link = $email_link.'email/';
}
} else {
if(is_page()) {
if(empty($email_page_text)) {
$email_text = stripslashes($email_options['page_text']);
} else {
$email_text = $email_page_text;
}
}
$email_link = $email_link.'&email=1';
}
break;
// E-Mail Popup
case 2:
if(!empty($using_permalink)) {
if(substr($email_link, -1, 1) != '/') {
$email_link= $email_link.'/';
}
if(is_page()) {
if(empty($email_page_text)) {
$email_text = stripslashes($email_options['page_text']);
} else {
$email_text = $email_page_text;
}
$email_link = $email_link.'emailpopuppage/';
} else {
$email_link = $email_link.'emailpopup/';
}
} else {
if(is_page()) {
if(empty($email_page_text)) {
$email_text = stripslashes($email_options['page_text']);
} else {
$email_text = $email_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: Short Code For Inserting Email Links Into Posts/Pages
add_shortcode('email_link', 'email_link_shortcode');
function email_link_shortcode($atts) {
if(!is_feed()) {
return email_link('', '', false);
} else {
return __('Note: There is an email link embedded within this post, please visit this post to email it.', 'wp-email');
}
}
### Function: Snippet Words
if(!function_exists('snippet_words')) {
function snippet_words($text, $length = 0) {
$words = split(' ', $text);
return join(" ",array_slice($words, 0, $length)).'...';
}
}
### Function: Snippet Text
if(!function_exists('snippet_text')) {
function snippet_text($text, $length = 0) {
$text = html_entity_decode($text, ENT_QUOTES, get_option('blog_charset'));
if (strlen($text) > $length) {
return htmlentities(substr($text,0,$length), ENT_COMPAT, get_option('blog_charset')).'...';
} else {
return htmlentities($text, ENT_COMPAT, get_option('blog_charset'));
}
}
}
### Function: Add E-Mail Filters
function email_addfilters() {
global $emailfilters_count;
if(get_option('k2version') === false) {
$loop_count = 0;
} else {
$loop_count = 1;
}
if(intval($emailfilters_count) == $loop_count) {
add_filter('the_title', 'email_title');
add_filter('the_content', 'email_form', '', false, false);
}
$emailfilters_count++;
}
### 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: Get E-Mail Title
function email_get_title() {
global $post;
$post_title = $post->post_title;
if(!empty($post->post_password)) {
$post_title = sprintf(__('Protected: %s', 'wp-email'), $post_title);
} elseif($post->post_status == 'private') {
$post_title = sprintf(__('Private: %s', 'wp-email'), $post_title);
}
return $post_title;
}
### Function: E-Mail Title
function email_title($page_title) {
if(in_the_loop()) {
$post_title = email_get_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();
$email_snippet = intval(get_option('email_snippet'));
if($email_snippet > 0) {
return snippet_words($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_words($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 = html_entity_decode($content);
$content = htmlspecialchars_decode($content);
$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: There Are Still Many PHP 4.x Users
if(!function_exists('htmlspecialchars_decode')) {
function htmlspecialchars_decode($string, $style = ENT_COMPAT) {
$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS,$style));
if($style === ENT_QUOTES) {
$translation['''] = '\'';
}
return strtr($string, $translation);
}
}
### Function: Check Vaild Name (AlphaNumeric With Spaces Allowed Only)
if(!function_exists('is_valid_name')) {
function is_valid_name($name) {
$regex = '/[(\*\(\)\[\]\+\,\/\?\:\;\'\"\`\~\\#\$\%\^\&\<\>)+]/';
return !(preg_match($regex, $name));
}
}
### Function: Check Valid E-Mail Address
if(!function_exists('is_valid_email')) {
function is_valid_email($email) {
$regex = '/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/';
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, $temp_id) {
global $id;
if(intval($temp_id) > 0) {
$id = $temp_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 .= '