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

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