Share_Email

The Jetpack by WordPress.com Share Email class.

Defined (1)

The class is defined in the following location(s).

/modules/sharedaddy/sharing-sources.php  
  1. class Share_Email extends Sharing_Source { 
  2. public $shortname = 'email'; 
  3. public $genericon = '\f410'; 
  4. public function __construct( $id, array $settings ) { 
  5. parent::__construct( $id, $settings ); 
  6.  
  7. if ( 'official' == $this->button_style ) 
  8. $this->smart = true; 
  9. else 
  10. $this->smart = false; 
  11.  
  12. public function get_name() { 
  13. return _x( 'Email', 'as sharing source', 'jetpack' ); 
  14.  
  15. // Default does nothing 
  16. public function process_request( $post, array $post_data ) { 
  17. $ajax = false; 
  18. if ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) 
  19. $ajax = true; 
  20.  
  21. $source_email = $target_email = $source_name = false; 
  22.  
  23. if ( isset( $post_data['source_email'] ) && is_email( $post_data['source_email'] ) ) 
  24. $source_email = $post_data['source_email']; 
  25.  
  26. if ( isset( $post_data['target_email'] ) && is_email( $post_data['target_email'] ) ) 
  27. $target_email = $post_data['target_email']; 
  28.  
  29. if ( isset( $post_data['source_name'] ) && strlen( $post_data['source_name'] ) < 200 ) { 
  30. $source_name = $post_data['source_name']; 
  31. } elseif ( isset( $post_data['source_name'] ) ) { 
  32. $source_name = substr( $post_data['source_name'], 0, 200 ); 
  33. } else { 
  34. $source_name = ''; 
  35.  
  36. // Test email 
  37. $error = 1; // Failure in data 
  38. if ( empty( $post_data['source_f_name'] ) && $source_email && $target_email && $source_name ) { 
  39. /** 
  40. * Allow plugins to stop the email sharing button from running the shared message through Akismet. 
  41. * @module sharedaddy 
  42. * @since 1.1.0 
  43. * @param bool true Should we check if the message isn't spam? 
  44. * @param object $post Post information. 
  45. * @param array $post_data Information about the shared message. 
  46. */ 
  47. if ( apply_filters( 'sharing_email_check', true, $post, $post_data ) ) { 
  48. $data = array( 
  49. 'post' => $post,  
  50. 'source' => $source_email,  
  51. 'target' => $target_email,  
  52. 'name' => $source_name 
  53. ); 
  54. // todo: implement an error message when email doesn't get sent. 
  55. /** 
  56. * Filter whether an email can be sent from the Email sharing button. 
  57. * @module sharedaddy 
  58. * @since 1.1.0 
  59. * @param array $data Array of information about the shared message. 
  60. */ 
  61. if ( ( $data = apply_filters( 'sharing_email_can_send', $data ) ) !== false ) { 
  62. // Record stats 
  63. parent::process_request( $data['post'], $post_data ); 
  64.  
  65. /** 
  66. * Fires when an email is sent via the Email sharing button. 
  67. * @module sharedaddy 
  68. * @since 1.1.0 
  69. * @param array $data Array of information about the shared message. 
  70. */ 
  71. do_action( 'sharing_email_send_post', $data ); 
  72.  
  73. // Return a positive regardless of whether the user is subscribed or not 
  74. if ( $ajax ) { 
  75. ?> 
  76. <div class="response"> 
  77. <div class="response-title"><?php _e( 'This post has been shared!', 'jetpack' ); ?></div> 
  78. <div class="response-sub"><?php printf( __( 'You have shared this post with %s', 'jetpack' ), esc_html( $target_email ) ); ?></div> 
  79. <div class="response-close"><a href="#" class="sharing_cancel"><?php _e( 'Close', 'jetpack' ); ?></a></div> 
  80. </div> 
  81. <?php 
  82. else 
  83. wp_safe_redirect( get_permalink( $post->ID ).'?shared=email' ); 
  84.  
  85. die(); 
  86. else 
  87. $error = 2; // Email check failed 
  88.  
  89. if ( $ajax ) 
  90. echo $error; 
  91. else 
  92. wp_safe_redirect( get_permalink( $post->ID ).'?shared=email&msg=fail' ); 
  93.  
  94. die(); 
  95.  
  96. public function get_display( $post ) { 
  97. return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Email', 'share to', 'jetpack' ), __( 'Click to email this to a friend', 'jetpack' ), 'share=email' ); 
  98.  
  99. /** 
  100. * Outputs the hidden email dialog 
  101. */ 
  102. public function display_footer() { 
  103. global $current_user; 
  104.  
  105. $visible = $status = false; 
  106. ?> 
  107. <div id="sharing_email" style="display: none;"> 
  108. <form action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" method="post"> 
  109. <label for="target_email"><?php _e( 'Send to Email Address', 'jetpack' ) ?></label> 
  110. <input type="email" name="target_email" id="target_email" value="" /> 
  111.  
  112. <?php if ( is_user_logged_in() ) : ?> 
  113. <input type="hidden" name="source_name" value="<?php echo esc_attr( $current_user->display_name ); ?>" /> 
  114. <input type="hidden" name="source_email" value="<?php echo esc_attr( $current_user->user_email ); ?>" /> 
  115. <?php else : ?> 
  116.  
  117. <label for="source_name"><?php _e( 'Your Name', 'jetpack' ) ?></label> 
  118. <input type="text" name="source_name" id="source_name" value="" /> 
  119.  
  120. <label for="source_email"><?php _e( 'Your Email Address', 'jetpack' ) ?></label> 
  121. <input type="email" name="source_email" id="source_email" value="" /> 
  122.  
  123. <?php endif; ?> 
  124. <input type="text" id="jetpack-source_f_name" name="source_f_name" class="input" value="" size="25" autocomplete="off" /> 
  125. <script> document.getElementById('jetpack-source_f_name').value = ''; </script> 
  126. <?php 
  127. /** 
  128. * Fires when the Email sharing dialog is loaded. 
  129. * @module sharedaddy 
  130. * @since 1.1.0 
  131. * @param string jetpack Eail sharing source. 
  132. */ 
  133. do_action( 'sharing_email_dialog', 'jetpack' ); 
  134. ?> 
  135.  
  136. <img style="float: right; display: none" class="loading" src="<?php 
  137. /** This filter is documented in modules/shortcodes/audio.php */ 
  138. echo apply_filters( 'jetpack_static_url', plugin_dir_url( __FILE__ ) . 'images/loading.gif' ); ?>" alt="loading" width="16" height="16" /> 
  139. <input type="submit" value="<?php esc_attr_e( 'Send Email', 'jetpack' ); ?>" class="sharing_send" /> 
  140. <a rel="nofollow" href="#cancel" class="sharing_cancel"><?php _e( 'Cancel', 'jetpack' ); ?></a> 
  141.  
  142. <div class="errors errors-1" style="display: none;"> 
  143. <?php _e( 'Post was not sent - check your email addresses!', 'jetpack' ); ?> 
  144. </div> 
  145.  
  146. <div class="errors errors-2" style="display: none;"> 
  147. <?php _e( 'Email check failed, please try again', 'jetpack' ); ?> 
  148. </div> 
  149.  
  150. <div class="errors errors-3" style="display: none;"> 
  151. <?php _e( 'Sorry, your blog cannot share posts by email.', 'jetpack' ); ?> 
  152. </div> 
  153. </form> 
  154. </div> 
  155. <?php