| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Sharedaddy |
| 4 |
Description: The most super duper sharing tool on the interwebs. |
| 5 |
Version: 0.3.1 |
| 6 |
Author: Automattic, Inc. |
| 7 |
Author URI: http://automattic.com/ |
| 8 |
Plugin URI: http://en.blog.wordpress.com/2010/08/24/more-ways-to-share/ |
| 9 |
*/ |
| 10 |
|
| 11 |
require_once plugin_dir_path( __FILE__ ).'sharing.php'; |
| 12 |
|
| 13 |
function sharing_email_send_post( $data ) { |
| 14 |
$content = sprintf( __( '%1$s (%2$s) thinks you may be interested in the following post:'."\n\n", 'jetpack' ), $data['name'], $data['source'] ); |
| 15 |
$content .= $data['post']->post_title."\n"; |
| 16 |
$content .= get_permalink( $data['post']->ID )."\n"; |
| 17 |
|
| 18 |
wp_mail( $data['target'], '['.__( 'Shared Post', 'jetpack' ).'] '.$data['post']->post_title, $content ); |
| 19 |
} |
| 20 |
|
| 21 |
function sharing_add_meta_box() { |
| 22 |
$post_types = get_post_types( array( 'public' => true ) ); |
| 23 |
$title = apply_filters( 'sharing_meta_box_title', __( 'Sharing', 'jetpack' ) ); |
| 24 |
foreach( $post_types as $post_type ) { |
| 25 |
add_meta_box( 'sharing_meta', $title, 'sharing_meta_box_content', $post_type, 'advanced', 'high' ); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
function sharing_meta_box_content( $post ) { |
| 30 |
do_action( 'start_sharing_meta_box_content', $post ); |
| 31 |
|
| 32 |
$disabled = get_post_meta( $post->ID, 'sharing_disabled', true ); ?> |
| 33 |
|
| 34 |
<p> |
| 35 |
<label for="enable_post_sharing"> |
| 36 |
<input type="checkbox" name="enable_post_sharing" id="enable_post_sharing" value="1" <?php checked( !$disabled ); ?>> |
| 37 |
<?php _e( 'Show sharing buttons.' , 'jetpack'); ?> |
| 38 |
</label> |
| 39 |
<input type="hidden" name="sharing_status_hidden" value="1" /> |
| 40 |
</p> |
| 41 |
|
| 42 |
<?php |
| 43 |
do_action( 'end_sharing_meta_box_content', $post ); |
| 44 |
} |
| 45 |
|
| 46 |
function sharing_meta_box_save( $post_id ) { |
| 47 |
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) |
| 48 |
return $post_id; |
| 49 |
|
| 50 |
// Record sharing disable |
| 51 |
if ( isset( $_POST['post_type'] ) && ( 'post' == $_POST['post_type'] || 'page' == $_POST['post_type'] ) ) { |
| 52 |
if ( current_user_can( 'edit_post', $post_id ) ) { |
| 53 |
if ( isset( $_POST['sharing_status_hidden'] ) ) { |
| 54 |
if ( !isset( $_POST['enable_post_sharing'] ) ) { |
| 55 |
update_post_meta( $post_id, 'sharing_disabled', 1 ); |
| 56 |
} else { |
| 57 |
delete_post_meta( $post_id, 'sharing_disabled' ); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
return $post_id; |
| 64 |
} |
| 65 |
|
| 66 |
function sharing_meta_box_protected( $protected, $meta_key, $meta_type ) { |
| 67 |
if ( 'sharing_disabled' == $meta_key ) |
| 68 |
$protected = true; |
| 69 |
|
| 70 |
return $protected; |
| 71 |
} |
| 72 |
|
| 73 |
add_filter( 'is_protected_meta', 'sharing_meta_box_protected', 10, 3 ); |
| 74 |
|
| 75 |
function sharing_plugin_settings( $links ) { |
| 76 |
$settings_link = '<a href="options-general.php?page=sharing.php">'.__( 'Settings', 'jetpack' ).'</a>'; |
| 77 |
array_unshift( $links, $settings_link ); |
| 78 |
return $links; |
| 79 |
} |
| 80 |
|
| 81 |
function sharing_add_plugin_settings($links, $file) { |
| 82 |
if ( $file == basename( dirname( __FILE__ ) ).'/'.basename( __FILE__ ) ) { |
| 83 |
$links[] = '<a href="options-general.php?page=sharing.php">' . __( 'Settings', 'jetpack' ) . '</a>'; |
| 84 |
$links[] = '<a href="http://support.wordpress.com/sharing/">' . __( 'Support', 'jetpack' ) . '</a>'; |
| 85 |
} |
| 86 |
|
| 87 |
return $links; |
| 88 |
} |
| 89 |
|
| 90 |
function sharing_restrict_to_single( $services ) { |
| 91 |
// This removes Press This from non-multisite blogs - doesnt make much sense |
| 92 |
if ( is_multisite() === false ) { |
| 93 |
unset( $services['press-this'] ); |
| 94 |
} |
| 95 |
|
| 96 |
return $services; |
| 97 |
} |
| 98 |
|
| 99 |
function sharing_init() { |
| 100 |
if ( get_option( 'sharedaddy_disable_resources' ) ) { |
| 101 |
add_filter( 'sharing_js', 'sharing_disable_js' ); |
| 102 |
remove_action( 'wp_head', 'sharing_add_header', 1 ); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
function sharing_disable_js() { |
| 107 |
return false; |
| 108 |
} |
| 109 |
|
| 110 |
function sharing_global_resources() { |
| 111 |
$disable = get_option( 'sharedaddy_disable_resources' ); |
| 112 |
?> |
| 113 |
<tr valign="top"> |
| 114 |
<th scope="row"><label for="disable_css"><?php _e( 'Disable CSS and JS', 'jetpack' ); ?></label></th> |
| 115 |
<td> |
| 116 |
<input id="disable_css" type="checkbox" name="disable_resources" <?php if ( $disable == 1 ) echo ' checked="checked"'; ?>/> <small><em><?php _e( 'Advanced. If this option is checked, you must include these files in your theme manually for the sharing links to work.', 'jetpack' ); ?></em></small> |
| 117 |
</td> |
| 118 |
</tr> |
| 119 |
<?php |
| 120 |
} |
| 121 |
|
| 122 |
function sharing_global_resources_save() { |
| 123 |
update_option( 'sharedaddy_disable_resources', isset( $_POST['disable_resources'] ) ? 1 : 0 ); |
| 124 |
} |
| 125 |
|
| 126 |
function sharing_email_dialog() { |
| 127 |
echo '<div class="recaptcha" id="sharing_recaptcha"></div><input type="hidden" name="recaptcha_public_key" id="recaptcha_public_key" value="'.(defined( 'RECAPTCHA_PUBLIC_KEY' ) ? esc_attr( RECAPTCHA_PUBLIC_KEY ) : '').'" />'; |
| 128 |
} |
| 129 |
|
| 130 |
function sharing_email_check( $true, $post, $data ) { |
| 131 |
require_once plugin_dir_path( __FILE__ ).'recaptchalib.php'; |
| 132 |
|
| 133 |
$recaptcha_result = recaptcha_check_answer( RECAPTCHA_PRIVATE_KEY, $_SERVER["REMOTE_ADDR"], $data["recaptcha_challenge_field"], $data["recaptcha_response_field"] ); |
| 134 |
|
| 135 |
return $recaptcha_result->is_valid; |
| 136 |
} |
| 137 |
|
| 138 |
add_action( 'init', 'sharing_init' ); |
| 139 |
add_action( 'admin_init', 'sharing_add_meta_box' ); |
| 140 |
add_action( 'save_post', 'sharing_meta_box_save' ); |
| 141 |
add_action( 'sharing_email_send_post', 'sharing_email_send_post' ); |
| 142 |
add_action( 'sharing_global_options', 'sharing_global_resources', 30 ); |
| 143 |
add_action( 'sharing_admin_update', 'sharing_global_resources_save' ); |
| 144 |
add_filter( 'sharing_services', 'sharing_restrict_to_single' ); |
| 145 |
add_action( 'plugin_action_links_'.basename( dirname( __FILE__ ) ).'/'.basename( __FILE__ ), 'sharing_plugin_settings', 10, 4 ); |
| 146 |
add_filter( 'plugin_row_meta', 'sharing_add_plugin_settings', 10, 2 ); |
| 147 |
|
| 148 |
if ( defined( 'RECAPTCHA_PRIVATE_KEY' ) ) { |
| 149 |
add_action( 'sharing_email_dialog', 'sharing_email_dialog' ); |
| 150 |
add_filter( 'sharing_email_check', 'sharing_email_check', 10, 3 ); |
| 151 |
} |