PluginProbe
WP-EMail / 2.62
WP-EMail v2.62
3.0.0 trunk 1.00 2.00b 2.01 2.02 2.03 2.04 2.04a 2.05 2.06 2.07 2.10 2.11 2.20 2.30 2.31 2.40 2.50 2.51 2.52 2.61 2.62 2.63 2.64 All 42 releases
wp-email / wp-email.php

wp-email.php in WP-EMail 2.62, at wp-email.php

1,503 lines 63.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP-EMail
4 Plugin URI: http://lesterchan.net/portfolio/programming/php/
5 Description: Allows people to recommand/send your WordPress blog's post/page to a friend.
6 Version: 2.62
7 Author: Lester 'GaMerZ' Chan
8 Author URI: http://lesterchan.net
9 Text Domain: wp-email
10 */
11
12 /*
13 Copyright 2013 Lester Chan (email : lesterchan@gmail.com)
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 */
29
30 /**
31 * @todo flush permalinks when needed so the user doesn't have to
32 * @todo Make EMAIL_SHOW_REMARKS a setting and remove the readme.txt's FAQs
33 * @todo Make loading of CSS file completely optional
34 * @todo Consider making donotemail shortcode not affect wp-print without optional parameter?
35 */
36
37 ### Define: Show Email Remarks In Logs?
38 define('EMAIL_SHOW_REMARKS', true);
39
40
41 ### Create Text Domain For Translations
42 add_action( 'plugins_loaded', 'email_textdomain' );
43 function email_textdomain() {
44 load_plugin_textdomain( 'wp-email', false, dirname( plugin_basename( __FILE__ ) ) );
45 }
46
47
48 ### E-Mail Table Name
49 global $wpdb;
50 $wpdb->email = $wpdb->prefix.'email';
51
52
53 ### Function: E-Mail Administration Menu
54 add_action('admin_menu', 'email_menu');
55 function email_menu() {
56 add_menu_page(__('E-Mail', 'wp-email'), __('E-Mail', 'wp-email'), 'manage_email', 'wp-email/email-manager.php', '', 'dashicons-email-alt');
57 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');
58 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');
59 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');
60 }
61
62
63 ### Function: E-Mail htaccess ReWrite Rules
64 add_filter('generate_rewrite_rules', 'email_rewrite');
65 function email_rewrite($wp_rewrite) {
66 $email_link = get_permalink();
67 $page_uris = $wp_rewrite->page_uri_index();
68 $uris = $page_uris[0];
69 if(substr($email_link, -1, 1) != '/' && substr($wp_rewrite->permalink_structure, -1, 1) != '/') {
70 $email_link_text = '/email';
71 $email_popup_text = '/emailpopup';
72 } else {
73 $email_link_text = 'email';
74 $email_popup_text = 'emailpopup';
75 }
76 // WP-EMail Standalone Post Rules
77 $rewrite_rules = $wp_rewrite->generate_rewrite_rule($wp_rewrite->permalink_structure.$email_link_text, EP_PERMALINK);
78 $rewrite_rules = array_slice($rewrite_rules, 5, 1);
79 $r_rule = array_keys($rewrite_rules);
80 $r_rule = array_shift($r_rule);
81 $r_rule = str_replace('/trackback', '', $r_rule);
82 $r_link = array_values($rewrite_rules);
83 $r_link = array_shift($r_link);
84 $r_link = str_replace('tb=1', 'email=1', $r_link);
85 $wp_rewrite->rules = array_merge(array($r_rule => $r_link), $wp_rewrite->rules);
86 // WP-Email Standalone Page Rules
87 if(is_array($uris)) {
88 $email_page_rules = array();
89 foreach ($uris as $uri => $pagename) {
90 $wp_rewrite->add_rewrite_tag('%pagename%', "($uri)", 'pagename=');
91 $rewrite_rules = $wp_rewrite->generate_rewrite_rules($wp_rewrite->get_page_permastruct().'/emailpage', EP_PAGES);
92 $rewrite_rules = array_slice($rewrite_rules, 5, 1);
93 $r_rule = array_keys($rewrite_rules);
94 $r_rule = array_shift($r_rule);
95 $r_rule = str_replace('/trackback', '', $r_rule);
96 $r_link = array_values($rewrite_rules);
97 $r_link = array_shift($r_link);
98 $r_link = str_replace('tb=1', 'email=1', $r_link);
99 $email_page_rules = array_merge($email_page_rules, array($r_rule => $r_link));
100 }
101 $wp_rewrite->rules = array_merge($email_page_rules, $wp_rewrite->rules);
102 }
103
104 // WP-EMail Popup Post Rules
105 $rewrite_rules = $wp_rewrite->generate_rewrite_rule($wp_rewrite->permalink_structure.$email_popup_text, EP_PERMALINK);
106 $rewrite_rules = array_slice($rewrite_rules, 5, 1);
107 $r_rule = array_keys($rewrite_rules);
108 $r_rule = array_shift($r_rule);
109 $r_rule = str_replace('/trackback', '', $r_rule);
110 $r_link = array_values($rewrite_rules);
111 $r_link = array_shift($r_link);
112 $r_link = str_replace('tb=1', 'emailpopup=1', $r_link);
113 $wp_rewrite->rules = array_merge(array($r_rule => $r_link), $wp_rewrite->rules);
114 if(is_array($uris)) {
115 $email_page_rules = array();
116 foreach ($uris as $uri => $pagename) {
117 $wp_rewrite->add_rewrite_tag('%pagename%', "($uri)", 'pagename=');
118 $rewrite_rules = $wp_rewrite->generate_rewrite_rules($wp_rewrite->get_page_permastruct().'/emailpopuppage', EP_PAGES);
119 $rewrite_rules = array_slice($rewrite_rules, 5, 1);
120 $r_rule = array_keys($rewrite_rules);
121 $r_rule = array_shift($r_rule);
122 $r_rule = str_replace('/trackback', '', $r_rule);
123 $r_link = array_values($rewrite_rules);
124 $r_link = array_shift($r_link);
125 $r_link = str_replace('tb=1', 'emailpopup=1', $r_link);
126 $email_page_rules = array_merge($email_page_rules, array($r_rule => $r_link));
127 }
128 $wp_rewrite->rules = array_merge($email_page_rules, $wp_rewrite->rules);
129 }
130 }
131
132
133 ### Function: E-Mail Public Variables
134 add_filter('query_vars', 'email_variables');
135 function email_variables($public_query_vars) {
136 $public_query_vars[] = 'email';
137 $public_query_vars[] = 'emailpopup';
138 return $public_query_vars;
139 }
140
141
142 ### Function: Print Out jQuery Script At The Top
143 add_action('wp_head', 'email_javascripts_header');
144 function email_javascripts_header() {
145 wp_print_scripts('jquery');
146 }
147
148
149 ### Function: Enqueue E-Mail Javascripts/CSS
150 add_action('wp_enqueue_scripts', 'email_scripts');
151 function email_scripts() {
152 global $text_direction;
153 if(@file_exists(TEMPLATEPATH.'/email-css.css')) {
154 wp_enqueue_style('wp-email', get_stylesheet_directory_uri().'/email-css.css', false, '2.60', 'all');
155 } else {
156 wp_enqueue_style('wp-email', plugins_url('wp-email/email-css.css'), false, '2.60', 'all');
157 }
158 if('rtl' == $text_direction) {
159 if(@file_exists(TEMPLATEPATH.'/email-css-rtl.css')) {
160 wp_enqueue_style('wp-email-rtl', get_stylesheet_directory_uri().'/email-css-rtl.css', false, '2.60', 'all');
161 } else {
162 wp_enqueue_style('wp-email-rtl', plugins_url('wp-email/email-css-rtl.css'), false, '2.60', 'all');
163 }
164 }
165 $email_max = intval(get_option('email_multiple'));
166 wp_enqueue_script('wp-email', plugins_url('wp-email/email-js.js'), array('jquery'), '2.60', true);
167 wp_localize_script('wp-email', 'emailL10n', array(
168 'ajax_url' => admin_url('admin-ajax.php', (is_ssl() ? 'https' : 'http')),
169 'max_allowed' => $email_max,
170 'text_error' => __('The Following Error Occurs:', 'wp-email'),
171 'text_name_invalid' => __('- Your Name is empty/invalid', 'wp-email'),
172 'text_email_invalid' => __('- Your Email is empty/invalid', 'wp-email'),
173 'text_remarks_invalid' => __('- Your Remarks is invalid', 'wp-email'),
174 'text_friend_names_empty' => __('- Friend Name(s) is empty', 'wp-email'),
175 'text_friend_name_invalid' => __('- Friend Name is empty/invalid: ', 'wp-email'),
176 'text_max_friend_names_allowed' => sprintf(_n('- Maximum %s Friend Name allowed', '- Maximum %s Friend Names allowed', $email_max, 'wp-email'), number_format_i18n($email_max)),
177 'text_friend_emails_empty' => __('- Friend Email(s) is empty', 'wp-email'),
178 'text_friend_email_invalid' => __('- Friend Email is invalid: ', 'wp-email'),
179 'text_max_friend_emails_allowed' => sprintf(_n('- Maximum %s Friend Email allowed', '- Maximum %s Friend Emails allowed', $email_max, 'wp-email'), number_format_i18n($email_max)),
180 'text_friends_tally' => __('- Friend Name(s) count does not tally with Friend Email(s) count', 'wp-email'),
181 'text_image_verify_empty' => __('- Image Verification is empty', 'wp-email')
182 ));
183 }
184
185
186 ### Function: Display E-Mail Link
187 function email_link($email_post_text = '', $email_page_text = '', $echo = true) {
188 global $id;
189 $output = '';
190 $using_permalink = get_option('permalink_structure');
191 $email_options = get_option('email_options');
192 $email_style = intval($email_options['email_style']);
193 $email_type = intval($email_options['email_type']);
194 if(empty($email_post_text)) {
195 $email_text = stripslashes($email_options['post_text']);
196 } else {
197 $email_text = $email_post_text;
198 }
199 $email_icon = plugins_url('wp-email/images/'.$email_options['email_icon']);
200 $email_link = get_permalink();
201 $email_html = stripslashes($email_options['email_html']);
202 $onclick = '';
203 // Fix For Static Page
204 if(get_option('show_on_front') == 'page' && is_page()) {
205 if(intval(get_option('page_on_front')) > 0) {
206 $email_link = _get_page_link();
207 }
208 }
209 switch($email_type) {
210 // E-Mail Standalone Page
211 case 1:
212 if(!empty($using_permalink)) {
213 if(substr($email_link, -1, 1) != '/') {
214 $email_link= $email_link.'/';
215 }
216 if(is_page()) {
217 if(empty($email_page_text)) {
218 $email_text = stripslashes($email_options['page_text']);
219 } else {
220 $email_text = $email_page_text;
221 }
222 $email_link = $email_link.'emailpage/';
223 } else {
224 $email_link = $email_link.'email/';
225 }
226 } else {
227 if(is_page()) {
228 if(empty($email_page_text)) {
229 $email_text = stripslashes($email_options['page_text']);
230 } else {
231 $email_text = $email_page_text;
232 }
233 }
234 $email_link = $email_link.'&amp;email=1';
235 }
236 break;
237 // E-Mail Popup
238 case 2:
239 if(!empty($using_permalink)) {
240 if(substr($email_link, -1, 1) != '/') {
241 $email_link= $email_link.'/';
242 }
243 if(is_page()) {
244 if(empty($email_page_text)) {
245 $email_text = stripslashes($email_options['page_text']);
246 } else {
247 $email_text = $email_page_text;
248 }
249 $email_link = $email_link.'emailpopuppage/';
250 } else {
251 $email_link = $email_link.'emailpopup/';
252 }
253 } else {
254 if(is_page()) {
255 if(empty($email_page_text)) {
256 $email_text = stripslashes($email_options['page_text']);
257 } else {
258 $email_text = $email_page_text;
259 }
260 }
261 $email_link = $email_link.'&amp;emailpopup=1';
262 }
263 $onclick = ' onclick="email_popup(this.href); return false;" ';
264 break;
265 }
266 unset($email_options);
267 switch($email_style) {
268 // Icon + Text Link
269 case 1:
270 $output = '<a href="'.$email_link.'"'.$onclick.' title="'.$email_text.'" rel="nofollow"><img class="WP-EmailIcon" src="'.$email_icon.'" alt="'.$email_text.'" title="'.$email_text.'" style="border: 0px;" /></a>&nbsp;<a href="'.$email_link.'"'.$onclick.' title="'.$email_text.'" rel="nofollow">'.$email_text.'</a>';
271 break;
272 // Icon Only
273 case 2:
274 $output = '<a href="'.$email_link.'"'.$onclick.' title="'.$email_text.'" rel="nofollow"><img class="WP-EmailIcon" src="'.$email_icon.'" alt="'.$email_text.'" title="'.$email_text.'" style="border: 0px;" /></a>';
275 break;
276 // Text Link Only
277 case 3:
278 $output = '<a href="'.$email_link.'"'.$onclick.' title="'.$email_text.'" rel="nofollow">'.$email_text.'</a>';
279 break;
280 case 4:
281 $email_html = str_replace("%EMAIL_URL%", $email_link, $email_html);
282 $email_html = str_replace("%EMAIL_POPUP%", $onclick, $email_html);
283 $email_html = str_replace("%EMAIL_TEXT%", $email_text, $email_html);
284 $email_html = str_replace("%EMAIL_ICON_URL%", $email_icon, $email_html);
285 $output = $email_html;
286 break;
287 }
288 if($echo) {
289 echo $output."\n";
290 } else {
291 return $output;
292 }
293 }
294
295
296 ### Function: Short Code For Inserting Email Links Into Posts/Pages
297 add_shortcode('email_link', 'email_link_shortcode');
298 function email_link_shortcode($atts) {
299 if(!is_feed()) {
300 return email_link('', '', false);
301 } else {
302 return __('Note: There is an email link embedded within this post, please visit this post to email it.', 'wp-email');
303 }
304 }
305 function email_link_shortcode2($atts) {
306 return;
307 }
308
309
310 ### Function: Short Code For DO NOT EMAIL Content
311 add_shortcode('donotemail', 'email_donotemail_shortcode');
312 function email_donotemail_shortcode($atts, $content = null) {
313 return do_shortcode($content);
314 }
315 function email_donotemail_shortcode2($atts, $content = null) {
316 return;
317 }
318
319
320 ### Function: Snippet Words
321 if(!function_exists('snippet_words')) {
322 function snippet_words($text, $length = 0) {
323 $words = split(' ', $text);
324 return join(" ",array_slice($words, 0, $length)).'...';
325 }
326 }
327
328
329 ### Function: Snippet Text
330 if(!function_exists('snippet_text')) {
331 function snippet_text($text, $length = 0) {
332 if (defined('MB_OVERLOAD_STRING')) {
333 $text = @html_entity_decode($text, ENT_QUOTES, get_option('blog_charset'));
334 if (mb_strlen($text) > $length) {
335 return htmlentities(mb_substr($text,0,$length), ENT_COMPAT, get_option('blog_charset')).'...';
336 } else {
337 return htmlentities($text, ENT_COMPAT, get_option('blog_charset'));
338 }
339 } else {
340 $text = @html_entity_decode($text, ENT_QUOTES, get_option('blog_charset'));
341 if (strlen($text) > $length) {
342 return htmlentities(substr($text,0,$length), ENT_COMPAT, get_option('blog_charset')).'...';
343 } else {
344 return htmlentities($text, ENT_COMPAT, get_option('blog_charset'));
345 }
346 }
347 }
348 }
349
350
351 ### Function: Add E-Mail Filters
352 function email_addfilters() {
353 global $emailfilters_count;
354 if(get_option('k2version') === false) {
355 $loop_count = 0;
356 } else {
357 $loop_count = 1;
358 }
359 if(intval($emailfilters_count) == $loop_count) {
360 add_filter('the_title', 'email_title');
361 add_filter('the_content', 'email_form', 10, 5);
362 }
363 $emailfilters_count++;
364 }
365
366
367 ### Function: Remove E-Mail Filters
368 function email_removefilters() {
369 remove_filter('the_title', 'email_title');
370 remove_filter('the_content', 'email_form', 10, 5);
371 }
372
373
374 ### Function: E-Mail Page Title
375 function email_pagetitle($page_title) {
376 $page_title .= ' &raquo; '.__('E-Mail', 'wp-email');
377 return $page_title;
378 }
379
380
381 ### Function: E-Mail Post ID
382 if(!function_exists('get_the_id')) {
383 function get_the_id() {
384 global $id;
385 return $id;
386 }
387 }
388
389
390 ### Function: Get E-Mail Remark
391 function email_get_remark() {
392 global $post;
393 return get_post_meta($post->ID, 'wp-email-remark', true);
394 }
395
396
397 ### Function: Get E-Mail Title
398 function email_get_title() {
399 global $post;
400 $post_title = get_post_meta($post->ID, 'wp-email-title', true);
401 if( empty($post_title) ) {
402 $post_title = $post->post_title;
403 }
404 if(!empty($post->post_password)) {
405 $post_title = sprintf(__('Protected: %s', 'wp-email'), $post_title);
406 } elseif($post->post_status == 'private') {
407 $post_title = sprintf(__('Private: %s', 'wp-email'), $post_title);
408 }
409 return $post_title;
410 }
411
412
413 ### Function: E-Mail Title
414 function email_title($page_title) {
415 if(in_the_loop()) {
416 $post_title = email_get_title();
417 $post_author = the_author('', false);
418 $post_date = get_the_time(get_option('date_format').' ('.get_option('time_format').')', '', '', false);
419 $post_category = email_category(__(',', 'wp-email').' ');
420 $post_category_alt = strip_tags($post_category);
421 $template_title = stripslashes(get_option('email_template_title'));
422 $template_title = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_title);
423 $template_title = str_replace("%EMAIL_POST_AUTHOR%", $post_author, $template_title);
424 $template_title = str_replace("%EMAIL_POST_DATE%", $post_date, $template_title);
425 $template_title = str_replace("%EMAIL_POST_CATEGORY%", $post_category, $template_title);
426 $template_title = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_title);
427 $template_title = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_title);
428 $template_title = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_title);
429 return $template_title;
430 } else {
431 return $page_title;
432 }
433 }
434
435
436 ### Function: E-Mail Category
437 function email_category($separator = ', ', $parents='') {
438 return get_the_category_list($separator, $parents);
439 }
440
441
442 ### Function: E-Mail Content
443 function email_content() {
444 $content = get_email_content();
445 $email_snippet = intval(get_option('email_snippet'));
446 if($email_snippet > 0) {
447 return snippet_words($content , $email_snippet);
448 } else {
449 return $content;
450 }
451 }
452
453
454 ### Function: E-Mail Alternate Content
455 function email_content_alt() {
456 remove_filter('the_content', 'wptexturize');
457 $content = get_email_content();
458 $content = clean_pre($content);
459 $content = strip_tags($content);
460 $email_snippet = intval(get_option('email_snippet'));
461 if($email_snippet > 0) {
462 return snippet_words($content , $email_snippet);
463 } else {
464 return $content;
465 }
466 }
467
468
469 ### Function: E-Mail Get The Content
470 function get_email_content() {
471 global $pages, $multipage, $numpages, $post;
472 if(post_password_required()) {
473 return __('Password Protected Post', 'wp-email');
474 }
475 if($multipage) {
476 for($page = 0; $page < $numpages; $page++) {
477 $content .= $pages[$page];
478 }
479 } else {
480 $content = $pages[0];
481 }
482 $content = html_entity_decode($content);
483 $content = htmlspecialchars_decode($content);
484 if(function_exists('print_rewrite')) {
485 remove_shortcode('donotprint');
486 add_shortcode('donotprint', 'print_donotprint_shortcode2');
487 }
488 remove_shortcode('donotemail');
489 add_shortcode('donotemail', 'email_donotemail_shortcode2');
490 remove_shortcode('email_link');
491 add_shortcode('email_link', 'email_link_shortcode2');
492 $content = apply_filters('the_content', $content);
493 return $content;
494 }
495
496
497 ### Function: Get IP Address
498 function get_email_ipaddress() {
499 if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
500 $ip_address = $_SERVER["REMOTE_ADDR"];
501 } else {
502 $ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"];
503 }
504 if(strpos($ip_address, ',') !== false) {
505 $ip_address = explode(',', $ip_address);
506 $ip_address = $ip_address[0];
507 }
508 return esc_attr($ip_address);
509 }
510
511 ### Function: There Are Still Many PHP 4.x Users
512 if(!function_exists('htmlspecialchars_decode')) {
513 function htmlspecialchars_decode($string, $style = ENT_COMPAT) {
514 $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS,$style));
515 if($style === ENT_QUOTES) {
516 $translation['&#039;'] = '\'';
517 }
518 return strtr($string, $translation);
519 }
520 }
521
522
523 ### Function: Check Vaild Name (AlphaNumeric With Spaces Allowed Only)
524 if(!function_exists('is_valid_name')) {
525 function is_valid_name($name) {
526 $regex = '/[(\*\(\)\[\]\+\,\/\?\:\;\'\"\`\~\\#\$\%\^\&\<\>)+]/';
527 return !(preg_match($regex, $name));
528 }
529 }
530
531
532 ### Function: Check Valid E-Mail Address
533 if(!function_exists('is_valid_email')) {
534 function is_valid_email($email) {
535 $regex = '/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/';
536 return (preg_match($regex, $email));
537 }
538 }
539
540
541 ### Function: Check Valid Remarks (Ensure No E-Mail Injections)
542 if(!function_exists('is_valid_remarks')) {
543 function is_valid_remarks($content) {
544 $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');
545 foreach ($injection_strings as $spam) {
546 $check = strpos(strtolower($content), $spam);
547 if ($check !== false) {
548 return false;
549 }
550 }
551 return true;
552 }
553 }
554
555
556 ### Function: Check For E-Mail Spamming
557 function not_spamming() {
558 global $wpdb;
559 $current_time = current_time('timestamp');
560 $email_ip = get_email_ipaddress();
561 $email_host = esc_attr(@gethostbyaddr($email_ip));
562 $email_status = __('Success', 'wp-email');
563 $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");
564 $email_allow_interval = intval(get_option('email_interval'))*60;
565 if(($current_time-$last_emailed) < $email_allow_interval) {
566 return false;
567 } else {
568 return true;
569 }
570 }
571
572
573 ### Function: E-Mail Flood Interval
574 function email_flood_interval($echo = true) {
575 $email_allow_interval_min = intval(get_option('email_interval'));
576 if($echo) {
577 echo $email_allow_interval_min;
578 } else {
579 return $email_allow_interval_min;
580 }
581 }
582
583
584 ### Function: Fill In Email Fills If Logged In (By Aaron Campbell)
585 add_filter('email_form-fieldvalues', 'email_fill_fields');
586 function email_fill_fields($email_fields) {
587 global $current_user;
588 if ($current_user->ID > 0) {
589 $email_fields['yourname'] = trim(esc_attr($current_user->first_name.' '.$current_user->last_name));
590 $email_fields['youremail'] = esc_attr($current_user->user_email);
591 }
592 return $email_fields;
593 }
594
595
596 ### Function: E-Mail Form Header
597 function email_form_header($echo = true, $temp_id) {
598 global $id;
599 if(intval($temp_id) > 0) {
600 $id = $temp_id;
601 }
602 $using_permalink = get_option('permalink_structure');
603 $permalink = get_permalink();
604 // Fix For Static Page
605 if(get_option('show_on_front') == 'page' && is_page()) {
606 if(intval(get_option('page_on_front')) > 0) {
607 $permalink = _get_page_link();
608 }
609 }
610 $output = '';
611 if(!empty($using_permalink)) {
612 if(is_page()) {
613 $output .= '<form action="'.$permalink.'emailpage/" method="post">'."\n";
614 $output .= '<p style="display: none;"><input type="hidden" id="page_id" name="page_id" value="'.$id.'" /></p>'."\n";
615 } else {
616 $output = '<form action="'.$permalink.'email/" method="post">'."\n";
617 $output .= '<p style="display: none;"><input type="hidden" id="p" name="p" value="'.$id.'" /></p>'."\n";
618 }
619 } else {
620 if(is_page()) {
621 $output .= '<form action="'.$permalink.'&amp;email=1" method="post">'."\n";
622 $output .= '<p style="display: none;"><input type="hidden" id="page_id" name="page_id" value="'.$id.'" /></p>'."\n";
623 } else {
624 $output .= '<form action="'.$permalink.'&amp;email=1" method="post">'."\n";
625 $output .= '<p style="display: none;"><input type="hidden" id="p" name="p" value="'.$id.'" /></p>'."\n";
626 }
627 }
628 $output .= '<p style="display: none;"><input type="hidden" id="wp-email_nonce" name="wp-email_nonce" value="'.wp_create_nonce('wp-email-nonce').'" /></p>'."\n";
629 if($echo) {
630 echo $output;
631 } else {
632 return $output;
633 }
634 }
635
636
637 ### Function: E-Mail Form Header For Popup
638 function email_popup_form_header($echo = true, $temp_id) {
639 global $post;
640 $id = intval($post->ID);
641 if(intval($temp_id) > 0) {
642 $id = $temp_id;
643 }
644 $using_permalink = get_option('permalink_structure');
645 $permalink = get_permalink();
646 // Fix For Static Page
647 if(get_option('show_on_front') == 'page' && is_page()) {
648 if(intval(get_option('page_on_front')) > 0) {
649 $permalink = _get_page_link();
650 }
651 }
652 $output = '';
653 if(!empty($using_permalink)) {
654 if(is_page()) {
655 $output .= '<form action="'.$permalink.'emailpopuppage/" method="post">'."\n";
656 $output .= '<p style="display: none;"><input type="hidden" id="page_id" name="page_id" value="'.$id.'" /></p>'."\n";
657 } else {
658 $output = '<form action="'.$permalink.'emailpopup/" method="post">'."\n";
659 $output .= '<p style="display: none;"><input type="hidden" id="p" name="p" value="'.$id.'" /></p>'."\n";
660 }
661 } else {
662 if(is_page()) {
663 $output .= '<form action="'.$permalink.'&amp;emailpopup=1" method="post">'."\n";
664 $output .= '<p style="display: none;"><input type="hidden" id="page_id" name="page_id" value="'.$id.'" /></p>'."\n";
665 } else {
666 $output .= '<form action="'.$permalink.'&amp;emailpopup=1" method="post">'."\n";
667 $output .= '<p style="display: none;"><input type="hidden" id="p" name="p" value="'.$id.'" /></p>'."\n";
668 }
669 }
670 $output .= '<p style="display: none;"><input type="hidden" id="wp-email_nonce" name="wp-email_nonce" value="'.wp_create_nonce('wp-email-nonce').'" /></p>'."\n";
671 if($echo) {
672 echo $output;
673 } else {
674 return $output;
675 }
676 }
677
678
679 ### Function: Multiple E-Mails
680 function email_multiple($echo = true) {
681 $email_multiple = intval(get_option('email_multiple'));
682 if($email_multiple > 1) {
683 $output = '<br /><em>'.sprintf(_n('Separate multiple entries with a comma. Maximum %s entry.', 'Separate multiple entries with a comma. Maximum %s entries.', $email_multiple, 'wp-email'), number_format_i18n($email_multiple)).'</em>';
684 if($echo) {
685 echo $outut;
686 } else {
687 return $output;
688 }
689 }
690 }
691
692
693 ### Function: Get EMail Total Sent
694 if(!function_exists('get_emails')) {
695 function get_emails($echo = true) {
696 global $wpdb;
697 $totalemails = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email");
698 if($echo) {
699 echo number_format_i18n($totalemails);
700 } else {
701 return number_format_i18n($totalemails);
702 }
703 }
704 }
705
706
707 ### Function: Get EMail Total Sent Success
708 if(!function_exists('get_emails_success')) {
709 function get_emails_success($echo = true) {
710 global $wpdb;
711 $totalemails_success = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = '".__('Success', 'wp-email')."'");
712 if($echo) {
713 echo number_format_i18n($totalemails_success);
714 } else {
715 return number_format_i18n($totalemails_success);
716 }
717 }
718 }
719
720
721 ### Function: Get EMail Total Sent Failed
722 if(!function_exists('get_emails_failed')) {
723 function get_emails_failed($echo = true) {
724 global $wpdb;
725 $totalemails_failed = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = '".__('Failed', 'wp-email')."'");
726 if($echo) {
727 echo number_format_i18n($totalemails_failed);
728 } else {
729 return number_format_i18n($totalemails_failed);
730 }
731 }
732 }
733
734
735 ### Function: Get EMail Sent For Post
736 if(!function_exists('get_email_count')) {
737 function get_email_count($post_id = 0, $echo = true) {
738 global $wpdb;
739 if($post_id == 0) {
740 global $post;
741 $post_id = $post->ID;
742 }
743 $post_id = intval($post_id);
744 $totalemails = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email WHERE email_postid = $post_id");
745 if($echo) {
746 echo number_format_i18n($totalemails);
747 } else {
748 return number_format_i18n($totalemails);
749 }
750 }
751 }
752
753
754 ### Function: Get Most E-Mailed
755 if(!function_exists('get_mostemailed')) {
756 function get_mostemailed($mode = '', $limit = 10, $chars = 0, $echo = true) {
757 global $wpdb, $post;
758 $temp_post = $post;
759 $where = '';
760 $temp = '';
761 if(!empty($mode) && $mode != 'both') {
762 $where = "post_type = '$mode'";
763 } else {
764 $where = '1=1';
765 }
766 $mostemailed= $wpdb->get_results("SELECT $wpdb->posts.*, COUNT($wpdb->email.email_postid) AS email_total FROM $wpdb->email LEFT JOIN $wpdb->posts ON $wpdb->email.email_postid = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND $where AND post_password = '' AND post_status = 'publish' GROUP BY $wpdb->email.email_postid ORDER BY email_total DESC LIMIT $limit");
767 if($mostemailed) {
768 if($chars > 0) {
769 foreach ($mostemailed as $post) {
770 $post_title = get_the_title();
771 $email_total = intval($post->email_total);
772 $temp .= "<li><a href=\"".get_permalink()."\">".snippet_text($post_title, $chars)."</a> - ".sprintf(_n('%s email', '%s emails', $email_total, 'wp-email'), number_format_i18n($email_total))."</li>\n";
773 }
774 } else {
775 foreach ($mostemailed as $post) {
776 $post_title = get_the_title();
777 $email_total = intval($post->email_total);
778 $temp .= "<li><a href=\"".get_permalink()."\">$post_title</a> - ".sprintf(_n('%s email', '%s emails', $email_total, 'wp-email'), number_format_i18n($email_total))."</li>\n";
779 }
780 }
781 } else {
782 $temp = '<li>'.__('N/A', 'wp-email').'</li>'."\n";
783 }
784 $post = $temp_post;
785 if($echo) {
786 echo $temp;
787 } else {
788 return $temp;
789 }
790 }
791 }
792
793
794 ### Function: Load WP-EMail
795 add_action('template_redirect', 'wp_email', 5);
796 function wp_email() {
797 if(intval(get_query_var('email')) == 1) {
798 include(WP_PLUGIN_DIR.'/wp-email/email-standalone.php');
799 exit();
800 } elseif(intval(get_query_var('emailpopup')) == 1) {
801 include(WP_PLUGIN_DIR.'/wp-email/email-popup.php');
802 exit();
803 }
804 }
805
806
807 ### Function: Process E-Mail Form
808 add_action('wp_ajax_email', 'process_email_form');
809 add_action('wp_ajax_nopriv_email', 'process_email_form');
810 function process_email_form() {
811 global $wpdb, $post, $text_direction;
812 // If User Click On Mail
813 if(isset($_POST['action']) && $_POST['action'] == 'email') {
814
815 // Verify Referer
816 if(!check_ajax_referer('wp-email-nonce', 'wp-email_nonce', false))
817 {
818 _e('Failed To Verify Referrer', 'wp-email');
819 exit();
820 }
821
822 @session_start();
823 email_textdomain();
824 header('Content-Type: text/html; charset='.get_option('blog_charset').'');
825 // POST Variables
826 $yourname = (!empty($_POST['yourname']) ? strip_tags(stripslashes(trim($_POST['yourname']))) : '');
827 $youremail = (!empty($_POST['youremail']) ? strip_tags(stripslashes(trim($_POST['youremail']))) : '');
828 $yourremarks = (!empty($_POST['yourremarks'])? strip_tags(stripslashes(trim($_POST['yourremarks']))) : '');
829 $friendname = (!empty($_POST['friendname']) ? strip_tags(stripslashes(trim($_POST['friendname']))) : '');
830 $friendemail = (!empty($_POST['friendemail'])? strip_tags(stripslashes(trim($_POST['friendemail']))) : '');
831 $imageverify = (!empty($_POST['imageverify'])? $_POST['imageverify'] : '');
832 $p = (!empty($_POST['p']) ? intval($_POST['p']) : 0);
833 $page_id = (!empty($_POST['page_id']) ? intval($_POST['page_id']) : 0);
834 // Get Post Information
835 if($p > 0) {
836 $post_type = get_post_type($p);
837 $query_post = 'p='. $p . '&post_type=' . $post_type;
838 $id = $p;
839 } else {
840 $query_post = 'page_id='.$page_id;
841 $id = $page_id;
842 }
843 query_posts($query_post);
844 if(have_posts()) {
845 while(have_posts()) {
846 the_post();
847 $post_title = email_get_title();
848 $post_author = get_the_author();
849 $post_date = get_the_time(get_option('date_format').' ('.get_option('time_format').')', '', '', false);
850 $post_category = email_category(__(',', 'wp-email').' ');
851 $post_category_alt = strip_tags($post_category);
852 $post_excerpt = get_the_excerpt();
853 $post_content = email_content();
854 $post_content_alt = email_content_alt();
855 }
856 }
857 // Error
858 $error = '';
859 $error_field = array('yourname' => $yourname, 'youremail' => $youremail, 'yourremarks' => $yourremarks, 'friendname' => $friendname, 'friendemail' => $friendemail, 'id' => $id);
860 // Get Options
861 $email_fields = get_option('email_fields');
862 $email_image_verify = intval(get_option('email_imageverify'));
863 $email_smtp = get_option('email_smtp');
864 // Multiple Names/Emails
865 $friends = array();
866 $friendname_count = 0;
867 $friendemail_count = 0;
868 $multiple_names = explode(',', $friendname);
869 $multiple_emails = explode(',', $friendemail);
870 $multiple_max = intval(get_option('email_multiple'));
871 if($multiple_max == 0) { $multiple_max = 1; }
872 // Checking Your Name Field For Errors
873 if(intval($email_fields['yourname']) == 1) {
874 if(empty($yourname)) {
875 $error .= '<br /><strong>&raquo;</strong> '.__('Your Name is empty', 'wp-email');
876 }
877 if(!is_valid_name($yourname)) {
878 $error .= '<br /><strong>&raquo;</strong> '.__('Your Name is invalid', 'wp-email');
879 }
880 }
881 // Checking Your E-Mail Field For Errors
882 if(intval($email_fields['youremail']) == 1) {
883 if(empty($youremail)) {
884 $error .= '<br /><strong>&raquo;</strong> '.__('Your Email is empty', 'wp-email');
885 }
886 if(!is_valid_email($youremail)) {
887 $error .= '<br /><strong>&raquo;</strong> '.__('Your Email is invalid', 'wp-email');
888 }
889 }
890 // Checking Your Remarks Field For Errors
891 if(intval($email_fields['yourremarks']) == 1) {
892 if(!is_valid_remarks($yourremarks)) {
893 $error .= '<br /><strong>&raquo;</strong> '.__('Your Remarks is invalid', 'wp-email');
894 }
895 }
896 // Checking Friend's Name Field For Errors
897 if(intval($email_fields['friendname']) == 1) {
898 if(empty($friendname)) {
899 $error .= '<br /><strong>&raquo;</strong> '.__('Friend Name(s) is empty', 'wp-email');
900 } else {
901 if($multiple_names) {
902 foreach($multiple_names as $multiple_name) {
903 $multiple_name = trim($multiple_name);
904 if(empty($multiple_name)) {
905 $error .= '<br /><strong>&raquo;</strong> '.sprintf(__('Friend Name is empty: %s', 'wp-email'), $multiple_name);
906 } elseif(!is_valid_name($multiple_name)) {
907 $error .= '<br /><strong>&raquo;</strong> '.sprintf(__('Friend Name is invalid: %s', 'wp-email'), $multiple_name);
908 } else {
909 $friends[$friendname_count]['name'] = $multiple_name;
910 $friendname_count++;
911 }
912 if($friendname_count > $multiple_max) {
913 break;
914 }
915 }
916 }
917 }
918 }
919 // Checking Friend's E-Mail Field For Errors
920 if(empty($friendemail)) {
921 $error .= '<br /><strong>&raquo;</strong> '.__('Friend Email(s) is empty', 'wp-email');
922 } else {
923 if($multiple_emails) {
924 foreach($multiple_emails as $multiple_email) {
925 $multiple_email = trim($multiple_email);
926 if(empty($multiple_email)) {
927 $error .= '<br /><strong>&raquo;</strong> '.sprintf(__('Friend Email is empty: %s', 'wp-email'), $multiple_email);
928 } elseif(!is_valid_email($multiple_email)) {
929 $error .= '<br /><strong>&raquo;</strong> '.sprintf(__('Friend Email is invalid: %s', 'wp-email'), $multiple_email);
930 } else {
931 $friends[$friendemail_count]['email'] = $multiple_email;
932 $friendemail_count++;
933 }
934 if($friendemail_count > $multiple_max) {
935 break;
936 }
937 }
938 }
939 }
940 // Checking If The Fields Exceed The Size Of Maximum Entries Allowed
941 if(sizeof($friends) > $multiple_max) {
942 $error .= '<br /><strong>&raquo;</strong> '.sprintf(_n('Maximum %s Friend allowed', 'Maximum %s Friend(s) allowed', $multiple_max, 'wp-email'), number_format_i18n($multiple_max));
943 }
944 if(intval($email_fields['friendname']) == 1) {
945 if($friendname_count != $friendemail_count) {
946 $error .= '<br /><strong>&raquo;</strong> '.__('Friend Name(s) count does not tally with Friend Email(s) count', 'wp-email');
947 }
948 }
949 // Check Whether We Enable Image Verification
950 if($email_image_verify) {
951 $imageverify = strtoupper($imageverify);
952 if(empty($imageverify)) {
953 $error .= '<br /><strong>&raquo;</strong> '.__('Image Verification is empty', 'wp-email');
954 } else {
955 if($_SESSION['email_verify'] != md5($imageverify)) {
956 $error .= '<br /><strong>&raquo;</strong> '.__('Image Verification failed', 'wp-email');
957 }
958 }
959 }
960 // If There Is No Error, We Process The E-Mail
961 if(empty($error) && not_spamming()) {
962 // If Remarks Is Empty, Assign N/A
963 if(empty($yourremarks)) { $yourremarks = __('N/A', 'wp-email'); }
964 // Template For E-Mail Subject
965 $template_email_subject = stripslashes(get_option('email_template_subject'));
966 $template_email_subject = str_replace("%EMAIL_YOUR_NAME%", $yourname, $template_email_subject);
967 $template_email_subject = str_replace("%EMAIL_YOUR_EMAIL%", $youremail, $template_email_subject);
968 $template_email_subject = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_subject);
969 $template_email_subject = str_replace("%EMAIL_POST_AUTHOR%", $post_author, $template_email_subject);
970 $template_email_subject = str_replace("%EMAIL_POST_DATE%", $post_date, $template_email_subject);
971 $template_email_subject = str_replace("%EMAIL_POST_CATEGORY%", $post_category_alt, $template_email_subject);
972 $template_email_subject = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_subject);
973 $template_email_subject = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_subject);
974 $template_email_subject = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_subject);
975 // Template For E-Mail Body
976 $template_email_body = stripslashes(get_option('email_template_body'));
977 $template_email_body = str_replace("%EMAIL_YOUR_NAME%", $yourname, $template_email_body);
978 $template_email_body = str_replace("%EMAIL_YOUR_EMAIL%", $youremail, $template_email_body);
979 $template_email_body = str_replace("%EMAIL_YOUR_REMARKS%", $yourremarks, $template_email_body);
980 $template_email_body = str_replace("%EMAIL_FRIEND_NAME%", $friendname, $template_email_body);
981 $template_email_body = str_replace("%EMAIL_FRIEND_EMAIL%", $friendemail, $template_email_body);
982 $template_email_body = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_body);
983 $template_email_body = str_replace("%EMAIL_POST_AUTHOR%", $post_author, $template_email_body);
984 $template_email_body = str_replace("%EMAIL_POST_DATE%", $post_date, $template_email_body);
985 $template_email_body = str_replace("%EMAIL_POST_CATEGORY%", $post_category, $template_email_body);
986 $template_email_body = str_replace("%EMAIL_POST_EXCERPT%", $post_excerpt, $template_email_body);
987 $template_email_body = str_replace("%EMAIL_POST_CONTENT%", $post_content, $template_email_body);
988 $template_email_body = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_body);
989 $template_email_body = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_body);
990 $template_email_body = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_body);
991 if('rtl' == $text_direction) {
992 $template_email_body = "<div style=\"direction: rtl;\">$template_email_body</div>";
993 }
994 // Template For E-Mail Alternate Body
995 $template_email_bodyalt = stripslashes(get_option('email_template_bodyalt'));
996 $template_email_bodyalt = str_replace("%EMAIL_YOUR_NAME%", $yourname, $template_email_bodyalt);
997 $template_email_bodyalt = str_replace("%EMAIL_YOUR_EMAIL%", $youremail, $template_email_bodyalt);
998 $template_email_bodyalt = str_replace("%EMAIL_YOUR_REMARKS%", $yourremarks, $template_email_bodyalt);
999 $template_email_bodyalt = str_replace("%EMAIL_FRIEND_NAME%", $friendname, $template_email_bodyalt);
1000 $template_email_bodyalt = str_replace("%EMAIL_FRIEND_EMAIL%", $friendemail, $template_email_bodyalt);
1001 $template_email_bodyalt = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_bodyalt);
1002 $template_email_bodyalt = str_replace("%EMAIL_POST_AUTHOR%", $post_author, $template_email_bodyalt);
1003 $template_email_bodyalt = str_replace("%EMAIL_POST_DATE%", $post_date, $template_email_bodyalt);
1004 $template_email_bodyalt = str_replace("%EMAIL_POST_CATEGORY%", $post_category_alt, $template_email_bodyalt);
1005 $template_email_bodyalt = str_replace("%EMAIL_POST_EXCERPT%", $post_excerpt, $template_email_bodyalt);
1006 $template_email_bodyalt = str_replace("%EMAIL_POST_CONTENT%", $post_content_alt, $template_email_bodyalt);
1007 $template_email_bodyalt = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_bodyalt);
1008 $template_email_bodyalt = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_bodyalt);
1009 $template_email_bodyalt = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_bodyalt);
1010 // PHP Mailer Variables
1011 if (!class_exists("phpmailer")) {
1012 require_once(ABSPATH.WPINC.'/class-phpmailer.php');
1013 }
1014 $mail = new PHPMailer();
1015 $mail->From = $youremail;
1016 $mail->FromName = $yourname;
1017 foreach($friends as $friend) {
1018 $mail->AddAddress($friend['email'], $friend['name']);
1019 }
1020 $mail->CharSet = strtolower(get_bloginfo('charset'));
1021 $mail->Username = $email_smtp['username'];
1022 $mail->Password = $email_smtp['password'];
1023 $mail->Host = $email_smtp['server'];
1024 $mail->Mailer = get_option('email_mailer');
1025 if($mail->Mailer == 'smtp') {
1026 $mail->SMTPAuth = true;
1027 }
1028 $mail->ContentType = get_option('email_contenttype');
1029 $mail->Subject = $template_email_subject;
1030 if(get_option('email_contenttype') == 'text/plain') {
1031 $mail->Body = $template_email_bodyalt;
1032 } else {
1033 $mail->Body = $template_email_body;
1034 $mail->AltBody = $template_email_bodyalt;
1035 }
1036 // Send The Mail if($mail->Send()) {
1037 if($mail->Send()) {
1038 $email_status = __('Success', 'wp-email');
1039 // Template For Sent Successfully
1040 $template_email_sentsuccess = stripslashes(get_option('email_template_sentsuccess'));
1041 $template_email_sentsuccess = str_replace("%EMAIL_FRIEND_NAME%", $friendname, $template_email_sentsuccess);
1042 $template_email_sentsuccess = str_replace("%EMAIL_FRIEND_EMAIL%", $friendemail, $template_email_sentsuccess);
1043 $template_email_sentsuccess = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_sentsuccess);
1044 $template_email_sentsuccess = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_sentsuccess);
1045 $template_email_sentsuccess = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_sentsuccess);
1046 $template_email_sentsuccess = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_sentsuccess);
1047 // If There Is Error Sending
1048 } else {
1049 if($yourremarks == __('N/A', 'wp-email')) { $yourremarks = ''; }
1050 $email_status = __('Failed', 'wp-email');
1051 // Template For Sent Failed
1052 $template_email_sentfailed = stripslashes(get_option('email_template_sentfailed'));
1053 $template_email_sentfailed = str_replace("%EMAIL_FRIEND_NAME%", $friendname, $template_email_sentfailed);
1054 $template_email_sentfailed = str_replace("%EMAIL_FRIEND_EMAIL%", $friendemail, $template_email_sentfailed);
1055 $template_email_sentfailed = str_replace("%EMAIL_ERROR_MSG%", $mail->ErrorInfo, $template_email_sentfailed);
1056 $template_email_sentfailed = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_sentfailed);
1057 $template_email_sentfailed = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_sentfailed);
1058 $template_email_sentfailed = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_sentfailed);
1059 $template_email_sentfailed = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_sentfailed);
1060 }
1061 // Logging
1062 $email_yourname = addslashes($yourname);
1063 $email_youremail = addslashes($youremail);
1064 $email_yourremarks = addslashes($yourremarks);
1065 $email_postid = intval(get_the_id());
1066 $email_posttitle = addslashes($post_title);
1067 $email_timestamp = current_time('timestamp');
1068 $email_ip = get_email_ipaddress();
1069 $email_host = esc_attr(@gethostbyaddr($email_ip));
1070 foreach($friends as $friend) {
1071 $email_friendname = addslashes($friend['name']);
1072 $email_friendemail = addslashes($friend['email']);
1073 $wpdb->query("INSERT INTO $wpdb->email VALUES (0, '$email_yourname', '$email_youremail', '$email_yourremarks', '$email_friendname', '$email_friendemail', $email_postid, '$email_posttitle', '$email_timestamp', '$email_ip', '$email_host', '$email_status')");
1074 }
1075 if($email_status == __('Success', 'wp-email')) {
1076 $output = $template_email_sentsuccess;
1077 } else {
1078 $output = $template_email_sentfailed;
1079 }
1080 echo $output;
1081 exit();
1082 // If There Are Errors
1083 } else {
1084 $error = substr($error, 21);
1085 $template_email_error = stripslashes(get_option('email_template_error'));
1086 $template_email_error = str_replace("%EMAIL_ERROR_MSG%", $error, $template_email_error);
1087 $template_email_error = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_error);
1088 $template_email_error = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_error);
1089 $template_email_error = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_error);
1090 $output = $template_email_error;
1091 $output .= email_form('', false, false, false, $error_field);
1092 echo $output;
1093 exit();
1094 } // End if(empty($error))
1095 } // End if(!empty($_POST['wp-email']))
1096 }
1097
1098
1099 ### Function: E-Mail Form
1100 function email_form($content, $echo = true, $subtitle = true, $div = true, $error_field = '') {
1101 global $wpdb, $multipage;
1102 // Variables
1103 $multipage = false;
1104 $post_title = email_get_title();
1105 $post_author = the_author('', false);
1106 $post_date = get_the_time(get_option('date_format').' ('.get_option('time_format').')', '', '', false);
1107 $post_category = email_category(__(',', 'wp-email').' ');
1108 $post_category_alt = strip_tags($post_category);
1109 $email_fields = get_option('email_fields');
1110 $email_image_verify = intval(get_option('email_imageverify'));
1111 $email_options = get_option('email_options');
1112 $email_type = intval($email_options['email_type']);
1113 $error_field = apply_filters('email_form-fieldvalues', $error_field);
1114 $output = '';
1115 // Template - Subtitle
1116 if($subtitle) {
1117 $template_subtitle = stripslashes(get_option('email_template_subtitle'));
1118 $template_subtitle = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_subtitle);
1119 $template_subtitle = str_replace("%EMAIL_POST_AUTHOR%", $post_author, $template_subtitle);
1120 $template_subtitle = str_replace("%EMAIL_POST_DATE%", $post_date, $template_subtitle);
1121 $template_subtitle = str_replace("%EMAIL_POST_CATEGORY%", $post_category, $template_subtitle);
1122 $template_subtitle = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_subtitle);
1123 $template_subtitle = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_subtitle);
1124 $template_subtitle = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_subtitle);
1125 $output .= $template_subtitle;
1126 }
1127 // Display WP-EMail Form
1128 if($div) {
1129 $output .= '<div id="wp-email-content" class="wp-email">'."\n";
1130 }
1131 if (not_spamming()) {
1132 if(!post_password_required()) {
1133 if($email_type == 2){
1134 $output .= email_popup_form_header(false, (!empty($error_field['id']) ? $error_field['id'] : 0));
1135 } else {
1136 $output .= email_form_header(false, (!empty($error_field['id']) ? $error_field['id'] : 0));
1137 }
1138 $output .= '<p id="wp-email-required">'.__('* Required Field', 'wp-email').'</p>'."\n";
1139 if(intval($email_fields['yourname']) == 1) {
1140 $output .= '<p>'."\n";
1141 $output .= '<label for="yourname">'.__('Your Name: *', 'wp-email').'</label><br />'."\n";
1142 $output .= '<input type="text" size="50" id="yourname" name="yourname" class="TextField" value="'.(!empty($error_field['yourname']) ? $error_field['yourname'] : '').'" />'."\n";
1143 $output .= '</p>'."\n";
1144 }
1145 if(intval($email_fields['youremail']) == 1) {
1146 $output .= '<p>'."\n";
1147 $output .= '<label for="youremail">'.__('Your E-Mail: *', 'wp-email').'</label><br />'."\n";
1148 $output .= '<input type="text" size="50" id="youremail" name="youremail" class="TextField" value="'.(!empty($error_field['youremail']) ? $error_field['youremail'] : '').'" dir="ltr" />'."\n";
1149 $output .= '</p>'."\n";
1150 }
1151 if(intval($email_fields['yourremarks']) == 1) {
1152 $output .= '<p>'."\n";
1153 $output .= ' <label for="yourremarks">'.__('Your Remark:', 'wp-email').'</label><br />'."\n";
1154 $output .= ' <textarea cols="49" rows="8" id="yourremarks" name="yourremarks" class="Forms">';
1155 $val = email_get_remark();
1156 if ( !empty($error_field['yourremarks']) ) {
1157 $val = $error_field['yourremarks'];
1158 }
1159 if ( !empty($val) ) {
1160 $output .= esc_html($val);
1161 }
1162 $output .= '</textarea>'."\n";
1163 $output .= '</p>'."\n";
1164 }
1165 if(intval($email_fields['friendname']) == 1) {
1166 $output .= '<p>'."\n";
1167 $output .= '<label for="friendname">'.__('Friend\'s Name: *', 'wp-email').'</label><br />'."\n";
1168 $output .= '<input type="text" size="50" id="friendname" name="friendname" class="TextField" value="'.(!empty($error_field['friendname']) ? $error_field['friendname'] : '').'" />'.email_multiple(false)."\n";
1169 $output .= '</p>'."\n";
1170 }
1171 $output .= '<p>'."\n";
1172 $output .= '<label for="friendemail">'.__('Friend\'s E-Mail: *', 'wp-email').'</label><br />'."\n";
1173 $output .= '<input type="text" size="50" id="friendemail" name="friendemail" class="TextField" value="'.(!empty($error_field['friendemail']) ? $error_field['friendemail'] : '').'" dir="ltr" />'.email_multiple(false)."\n";
1174 $output .= '</p>'."\n";
1175 if($email_image_verify) {
1176 $output .= '<p>'."\n";
1177 $output .= '<label for="imageverify">'.__('Image Verification: *', 'wp-email').'</label><br />'."\n";
1178 $output .= '<img src="'.plugins_url('wp-email/email-image-verify.php').'" width="55" height="15" alt="'.__('E-Mail Image Verification', 'wp-email').'" /><input type="text" size="5" maxlength="5" id="imageverify" name="imageverify" class="TextField" />'."\n";
1179 $output .= '</p>'."\n";
1180 }
1181 $output .= '<p id="wp-email-button"><input type="button" value="'.__(' Mail It! ', 'wp-email').'" id="wp-email-submit" class="Button" onclick="email_form();" onkeypress="email_form();" /></p>'."\n";
1182 $output .= '</form>'."\n";
1183 } else {
1184 $output .= get_the_password_form();
1185 } // End if(!post_password_required())
1186 } else {
1187 $output .= '<p>'.sprintf(_n('Please wait for <strong>%s Minute</strong> before sending the next article.', 'Please wait for <strong>%s Minutes</strong> before sending the next article.', email_flood_interval(false), 'wp-email'), email_flood_interval(false)).'</p>'."\n";
1188 } // End if (not_spamming())
1189 $output .= '<div id="wp-email-loading" class="wp-email-loading"><img src="'.plugins_url('wp-email/images/loading.gif').'" width="16" height="16" alt="'.__('Loading', 'wp-email').' ..." title="'.__('Loading', 'wp-email').' ..." class="wp-email-image" />&nbsp;'.__('Loading', 'wp-email').' ...</div>'."\n";
1190 if($div) {
1191 $output .= '</div>'."\n";
1192 }
1193 email_removefilters();
1194 if($echo) {
1195 echo $output;
1196 } else {
1197 return $output;
1198 }
1199 }
1200
1201
1202 ### Function: Modify Default WordPress Listing To Make It Sorted By Most E-Mailed
1203 function email_fields($content) {
1204 global $wpdb;
1205 $content .= ", COUNT($wpdb->email.email_postid) AS email_total";
1206 return $content;
1207 }
1208 function email_join($content) {
1209 global $wpdb;
1210 $content .= " LEFT JOIN $wpdb->email ON $wpdb->email.email_postid = $wpdb->posts.ID";
1211 return $content;
1212 }
1213 function email_groupby($content) {
1214 global $wpdb;
1215 $content .= " $wpdb->email.email_postid";
1216 return $content;
1217 }
1218 function email_orderby($content) {
1219 $orderby = trim(addslashes($_GET['orderby']));
1220 if(empty($orderby) || ($orderby != 'asc' && $orderby != 'desc')) {
1221 $orderby = 'desc';
1222 }
1223 $content = " email_total $orderby";
1224 return $content;
1225 }
1226
1227
1228 ### Process The Sorting
1229 /*
1230 if($_GET['sortby'] == 'email') {
1231 add_filter('posts_fields', 'email_fields');
1232 add_filter('posts_join', 'email_join');
1233 add_filter('posts_groupby', 'email_groupby');
1234 add_filter('posts_orderby', 'email_orderby');
1235 }
1236 */
1237
1238
1239 ### Function: Plug Into WP-Stats
1240 add_action('wp','email_wp_stats');
1241 function email_wp_stats() {
1242 if(function_exists('stats_page')) {
1243 if(strpos(get_option('stats_url'), $_SERVER['REQUEST_URI']) || strpos($_SERVER['REQUEST_URI'], 'stats-options.php') || strpos($_SERVER['REQUEST_URI'], 'wp-stats/wp-stats.php')) {
1244 add_filter('wp_stats_page_admin_plugins', 'email_page_admin_general_stats');
1245 add_filter('wp_stats_page_admin_most', 'email_page_admin_most_stats');
1246 add_filter('wp_stats_page_plugins', 'email_page_general_stats');
1247 add_filter('wp_stats_page_most', 'email_page_most_stats');
1248 }
1249 }
1250 }
1251
1252
1253 ### Function: Add WP-EMail General Stats To WP-Stats Page Options
1254 function email_page_admin_general_stats($content) {
1255 $stats_display = get_option('stats_display');
1256 if($stats_display['email'] == 1) {
1257 $content .= '<input type="checkbox" name="stats_display[]" id="wpstats_email" value="email" checked="checked" />&nbsp;&nbsp;<label for="wpstats_email">'.__('WP-EMail', 'wp-email').'</label><br />'."\n";
1258 } else {
1259 $content .= '<input type="checkbox" name="stats_display[]" id="wpstats_email" value="email" />&nbsp;&nbsp;<label for="wpstats_email">'.__('WP-EMail', 'wp-email').'</label><br />'."\n";
1260 }
1261 return $content;
1262 }
1263
1264
1265 ### Function: Add WP-EMail Top Most/Highest Stats To WP-Stats Page Options
1266 function email_page_admin_most_stats($content) {
1267 $stats_display = get_option('stats_display');
1268 $stats_mostlimit = intval(get_option('stats_mostlimit'));
1269 if($stats_display['emailed_most_post'] == 1) {
1270 $content .= '<input type="checkbox" name="stats_display[]" id="wpstats_emailed_most_post" value="emailed_most_post" checked="checked" />&nbsp;&nbsp;<label for="wpstats_emailed_most_post">'.sprintf(_n('%s Most Emailed Post', '%s Most Emailed Posts', $stats_mostlimit, 'wp-email'), number_format_i18n($stats_mostlimit)).'</label><br />'."\n";
1271 } else {
1272 $content .= '<input type="checkbox" name="stats_display[]" id="wpstats_emailed_most_post" value="emailed_most_post" />&nbsp;&nbsp;<label for="wpstats_emailed_most_post">'.sprintf(_n('%s Most Emailed Post', '%s Most Emailed Posts', $stats_mostlimit, 'wp-email'), number_format_i18n($stats_mostlimit)).'</label><br />'."\n";
1273 }
1274 if($stats_display['emailed_most_page'] == 1) {
1275 $content .= '<input type="checkbox" name="stats_display[]" id="wpstats_emailed_most_page" value="emailed_most_page" checked="checked" />&nbsp;&nbsp;<label for="wpstats_emailed_most_page">'.sprintf(_n('%s Most Emailed Page', '%s Most Emailed Pages', $stats_mostlimit, 'wp-email'), number_format_i18n($stats_mostlimit)).'</label><br />'."\n";
1276 } else {
1277 $content .= '<input type="checkbox" name="stats_display[]" id="wpstats_emailed_most_page" value="emailed_most_page" />&nbsp;&nbsp;<label for="wpstats_emailed_most_page">'.sprintf(_n('%s Most Emailed Page', '%s Most Emailed Pages', $stats_mostlimit, 'wp-email'), number_format_i18n($stats_mostlimit)).'</label><br />'."\n";
1278 }
1279 return $content;
1280 }
1281
1282
1283 ### Function: Add WP-EMail General Stats To WP-Stats Page
1284 function email_page_general_stats($content) {
1285 global $wpdb;
1286 $stats_display = get_option('stats_display');
1287 if($stats_display['email'] == 1) {
1288 $email_stats = $wpdb->get_results("SELECT email_status, COUNT(email_id) AS email_total FROM $wpdb->email GROUP BY email_status");
1289 if($email_stats) {
1290 $email_stats_array = array();
1291 $email_stats_array['total'] = 0;
1292 foreach($email_stats as $email_stat) {
1293 $email_stats_array[$email_stat->email_status] = intval($email_stat->email_total);
1294 $email_stats_array['total'] += intval($email_stat->email_total);
1295 }
1296 }
1297 $content .= '<p><strong>'.__('WP-EMail', 'wp-email').'</strong></p>'."\n";
1298 $content .= '<ul>'."\n";
1299 $content .= '<li>'.sprintf(_n('<strong>%s</strong> email was sent.', '<strong>%s</strong> emails were sent.', $email_stats_array['total'], 'wp-email'), number_format_i18n($email_stats_array['total'])).'</li>'."\n";
1300 $content .= '<li>'.sprintf(_n('<strong>%s</strong> email was sent successfully.', '<strong>%s</strong> emails were sent successfully.', $email_stats_array[__('Success', 'wp-email')], 'wp-email'), number_format_i18n($email_stats_array[__('Success', 'wp-email')])).'</li>'."\n";
1301 $content .= '<li>'.sprintf(_n('<strong>%s</strong> email failed to send.', '<strong>%s</strong> emails failed to send.', $email_stats_array[__('Failed', 'wp-email')], 'wp-email'), number_format_i18n($email_stats_array[__('Failed', 'wp-email')])).'</li>'."\n";
1302 $content .= '</ul>'."\n";
1303 }
1304 return $content;
1305 }
1306
1307
1308 ### Function: Add WP-EMail Top Most/Highest Stats To WP-Stats Page
1309 function email_page_most_stats($content) {
1310 $stats_display = get_option('stats_display');
1311 $stats_mostlimit = intval(get_option('stats_mostlimit'));
1312 if($stats_display['emailed_most_post'] == 1) {
1313 $content .= '<p><strong>'.sprintf(_n('%s Most Emailed Post', '%s Most Emailed Posts', $stats_mostlimit, 'wp-email'), number_format_i18n($stats_mostlimit)).'</strong></p>'."\n";
1314 $content .= '<ul>'."\n";
1315 $content .= get_mostemailed('post', $stats_mostlimit, 0, false);
1316 $content .= '</ul>'."\n";
1317 }
1318 if($stats_display['emailed_most_page'] == 1) {
1319 $content .= '<p><strong>'.sprintf(_n('%s Most Emailed Page', '%s Most Emailed Pages', $stats_mostlimit, 'wp-email'), number_format_i18n($stats_mostlimit)).'</strong></p>'."\n";
1320 $content .= '<ul>'."\n";
1321 $content .= get_mostemailed('page', $stats_mostlimit, 0, false);
1322 $content .= '</ul>'."\n";
1323 }
1324 return $content;
1325 }
1326
1327
1328 ### Class: WP-EMail Widget
1329 class WP_Widget_Email extends WP_Widget {
1330 // Constructor
1331 function WP_Widget_Email() {
1332 $widget_ops = array('description' => __('WP-EMail emails statistics', 'wp-email'));
1333 $this->WP_Widget('email', __('Email', 'wp-email'), $widget_ops);
1334 }
1335
1336 // Display Widget
1337 function widget($args, $instance) {
1338 extract($args);
1339 $title = apply_filters('widget_title', esc_attr($instance['title']));
1340 $type = esc_attr($instance['type']);
1341 $mode = esc_attr($instance['mode']);
1342 $limit = intval($instance['limit']);
1343 $chars = intval($instance['chars']);
1344 //$cat_ids = explode(',', esc_attr($instance['cat_ids']));
1345 echo $before_widget.$before_title.$title.$after_title;
1346 echo '<ul>'."\n";
1347 switch($type) {
1348 case 'most_emailed':
1349 get_mostemailed($mode, $limit, $chars);
1350 break;
1351 }
1352 echo '</ul>'."\n";
1353 echo $after_widget;
1354 }
1355
1356 // When Widget Control Form Is Posted
1357 function update($new_instance, $old_instance) {
1358 if (!isset($new_instance['submit'])) {
1359 return false;
1360 }
1361 $instance = $old_instance;
1362 $instance['title'] = strip_tags($new_instance['title']);
1363 $instance['type'] = strip_tags($new_instance['type']);
1364 $instance['mode'] = strip_tags($new_instance['mode']);
1365 $instance['limit'] = intval($new_instance['limit']);
1366 $instance['chars'] = intval($new_instance['chars']);
1367 //$instance['cat_ids'] = strip_tags($new_instance['cat_ids']);
1368 return $instance;
1369 }
1370
1371 // DIsplay Widget Control Form
1372 function form($instance) {
1373 global $wpdb;
1374 $instance = wp_parse_args((array) $instance, array('title' => __('EMail', 'wp-email'), 'type' => 'most_emailed', 'mode' => 'both', 'limit' => 10, 'chars' => 200));
1375 $title = esc_attr($instance['title']);
1376 $type = esc_attr($instance['type']);
1377 $mode = esc_attr($instance['mode']);
1378 $limit = intval($instance['limit']);
1379 $chars = intval($instance['chars']);
1380 //$cat_ids = esc_attr($instance['cat_ids']);
1381 ?>
1382 <p>
1383 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'wp-email'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label>
1384 </p>
1385 <p>
1386 <label for="<?php echo $this->get_field_id('type'); ?>"><?php _e('Statistics Type:', 'wp-email'); ?>
1387 <select name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>" class="widefat">
1388 <option value="most_emailed"<?php selected('most_emailed', $type); ?>><?php _e('Most Emailed', 'wp-email'); ?></option>
1389 </select>
1390 </label>
1391 </p>
1392 <p>
1393 <label for="<?php echo $this->get_field_id('mode'); ?>"><?php _e('Include Views From:', 'wp-email'); ?>
1394 <select name="<?php echo $this->get_field_name('mode'); ?>" id="<?php echo $this->get_field_id('mode'); ?>" class="widefat">
1395 <option value="both"<?php selected('both', $mode); ?>><?php _e('Posts &amp; Pages', 'wp-email'); ?></option>
1396 <option value="post"<?php selected('post', $mode); ?>><?php _e('Posts Only', 'wp-email'); ?></option>
1397 <option value="page"<?php selected('page', $mode); ?>><?php _e('Pages Only', 'wp-email'); ?></option>
1398 </select>
1399 </label>
1400 </p>
1401 <p>
1402 <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e('No. Of Records To Show:', 'wp-email'); ?> <input class="widefat" id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit; ?>" /></label>
1403 </p>
1404 <p>
1405 <label for="<?php echo $this->get_field_id('chars'); ?>"><?php _e('Maximum Post Title Length (Characters):', 'wp-email'); ?> <input class="widefat" id="<?php echo $this->get_field_id('chars'); ?>" name="<?php echo $this->get_field_name('chars'); ?>" type="text" value="<?php echo $chars; ?>" /></label><br />
1406 <small><?php _e('<strong>0</strong> to disable.', 'wp-email'); ?></small>
1407 </p>
1408 <input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />
1409 <?php
1410 }
1411 }
1412
1413
1414 ### Function: Init WP-EMail Widget
1415 add_action('widgets_init', 'widget_email_init');
1416 function widget_email_init() {
1417 email_textdomain();
1418 register_widget('WP_Widget_Email');
1419 }
1420
1421
1422 ### Function: Create E-Mail Table
1423 add_action('activate_wp-email/wp-email.php', 'create_email_table');
1424 function create_email_table() {
1425 global $wpdb;
1426 email_textdomain();
1427 if(@is_file(ABSPATH.'/wp-admin/upgrade-functions.php')) {
1428 include_once(ABSPATH.'/wp-admin/upgrade-functions.php');
1429 } elseif(@is_file(ABSPATH.'/wp-admin/includes/upgrade.php')) {
1430 include_once(ABSPATH.'/wp-admin/includes/upgrade.php');
1431 } else {
1432 die('We have problem finding your \'/wp-admin/upgrade-functions.php\' and \'/wp-admin/includes/upgrade.php\'');
1433 }
1434 $charset_collate = '';
1435 if($wpdb->supports_collation()) {
1436 if(!empty($wpdb->charset)) {
1437 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
1438 }
1439 if(!empty($wpdb->collate)) {
1440 $charset_collate .= " COLLATE $wpdb->collate";
1441 }
1442 }
1443 // Create E-Mail Table
1444 $create_table = "CREATE TABLE $wpdb->email (".
1445 "email_id int(10) NOT NULL auto_increment,".
1446 "email_yourname varchar(200) NOT NULL default '',".
1447 "email_youremail varchar(200) NOT NULL default '',".
1448 "email_yourremarks text NOT NULL,".
1449 "email_friendname varchar(200) NOT NULL default '',".
1450 "email_friendemail varchar(200) NOT NULL default '',".
1451 "email_postid int(10) NOT NULL default '0',".
1452 "email_posttitle text NOT NULL,".
1453 "email_timestamp varchar(20) NOT NULL default '',".
1454 "email_ip varchar(100) NOT NULL default '',".
1455 "email_host varchar(200) NOT NULL default '',".
1456 "email_status varchar(20) NOT NULL default '',".
1457 "PRIMARY KEY (email_id)) $charset_collate;";
1458 maybe_create_table($wpdb->email, $create_table);
1459 // Add In Options (12 Records)
1460 add_option('email_smtp', array('username' => '', 'password' => '', 'server' => ''), 'Your SMTP Name, Password, Server');
1461 add_option('email_contenttype', 'text/html', 'Your E-Mail Type');
1462 add_option('email_mailer', 'php', 'Your Mailer Type');
1463 add_option('email_template_subject', __('Recommended Article By %EMAIL_YOUR_NAME%: %EMAIL_POST_TITLE%', 'wp-email'), 'Template For E-Mail Subject');
1464 add_option('email_template_body', __('<p>Hi <strong>%EMAIL_FRIEND_NAME%</strong>,<br />Your friend, <strong>%EMAIL_YOUR_NAME%</strong>, has recommended this article entitled \'<strong>%EMAIL_POST_TITLE%</strong>\' to you.</p><p><strong>Here is his/her remark:</strong><br />%EMAIL_YOUR_REMARKS%</p><p><strong>%EMAIL_POST_TITLE%</strong><br />Posted By %EMAIL_POST_AUTHOR% On %EMAIL_POST_DATE% In %EMAIL_POST_CATEGORY%</p>%EMAIL_POST_CONTENT%<p>Article taken from %EMAIL_BLOG_NAME% - <a href="%EMAIL_BLOG_URL%">%EMAIL_BLOG_URL%</a><br />URL to article: <a href="%EMAIL_PERMALINK%">%EMAIL_PERMALINK%</a></p>', 'wp-email'), 'Template For E-Mail Body');
1465 add_option('email_template_bodyalt', __('Hi %EMAIL_FRIEND_NAME%,'."\n".
1466 'Your friend, %EMAIL_YOUR_NAME%, has recommended this article entitled \'%EMAIL_POST_TITLE%\' to you.'."\n\n".
1467 'Here is his/her remarks:'."\n".
1468 '%EMAIL_YOUR_REMARKS%'."\n\n".
1469 '%EMAIL_POST_TITLE%'."\n".
1470 'Posted By %EMAIL_POST_AUTHOR% On %EMAIL_POST_DATE% In %EMAIL_POST_CATEGORY%'."\n".
1471 '%EMAIL_POST_CONTENT%'."\n".
1472 'Article taken from %EMAIL_BLOG_NAME% - %EMAIL_BLOG_URL%'."\n".
1473 'URL to article: %EMAIL_PERMALINK%', 'wp-email'), 'Template For E-Mail Alternate Body');
1474 add_option('email_template_sentsuccess', '<p>'.__('Article: <strong>%EMAIL_POST_TITLE%</strong> has been sent to <strong>%EMAIL_FRIEND_NAME% (%EMAIL_FRIEND_EMAIL%)</strong></p><p>&laquo; <a href="%EMAIL_PERMALINK%">'.__('Back to %EMAIL_POST_TITLE%', 'wp-email').'</a></p>', 'wp-email'), 'Template For E-Mail That Is Sent Successfully');
1475 add_option('email_template_sentfailed', '<p>'.__('An error has occurred when trying to send this email: ', 'wp-email').'<br /><strong>&raquo;</strong> %EMAIL_ERROR_MSG%</p>', 'Template For E-Mail That Failed To Sent');
1476 add_option('email_template_error', '<p>'.__('An error has occurred: ', 'wp-email').'<br /><strong>&raquo;</strong> %EMAIL_ERROR_MSG%</p>', 'Template For E-Mail That Has An Error');
1477 add_option('email_interval', 10, 'The Number Of Minutes Before The User Can E-Mail The Next Article');
1478 add_option('email_snippet', 0, 'Enable Snippet Feature For Your E-Mail?');
1479 add_option('email_multiple', 5, 'Maximum Number Of Multiple E-Mails');
1480 // Version 2.05 Options
1481 add_option('email_imageverify', 1, 'Enable Image Verification?');
1482 // Version 2.10 Options
1483 $email_options = array('post_text' => __('Email This Post', 'wp-email'), 'page_text' => __('Email This Page', 'wp-email'), 'email_icon' => 'email_famfamfam.png', 'email_type' => 1, 'email_style' => 1, 'email_html' => '<a href="%EMAIL_URL%" rel="nofollow" title="%EMAIL_TEXT%">%EMAIL_TEXT%</a>');
1484 $email_fields = array('yourname' => 1, 'youremail' => 1, 'yourremarks' => 1, 'friendname' => 1, 'friendemail' => 1);
1485 add_option('email_options', $email_options, 'Email Options');
1486 add_option('email_fields', $email_fields, 'Email Fields');
1487 // Version 2.11 Options
1488 add_option('email_template_title', __('E-Mail \'%EMAIL_POST_TITLE%\' To A Friend', 'wp-email'), 'Template For E-Mail Page Title');
1489 add_option('email_template_subtitle', '<p style="text-align: center;">'.__('Email a copy of <strong>\'%EMAIL_POST_TITLE%\'</strong> to a friend', 'wp-email').'</p>', 'Template For E-Mail Page SubTitle');
1490 // Version 2.20 Upgrade
1491 $email_mailer = get_option('email_mailer');
1492 if($email_mailer == 'php') {
1493 update_option('email_mailer', 'mail');
1494 }
1495 // Version 2.60 Upgrade
1496 delete_option('widget_email_most_emailed');
1497 // Set 'manage_email' Capabilities To Administrator
1498 $role = get_role('administrator');
1499 if(!$role->has_cap('manage_email')) {
1500 $role->add_cap('manage_email');
1501 }
1502 }
1503