PluginProbe
WP-EMail / 2.61
WP-EMail v2.61
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.61, at wp-email.php

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