summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Chatzimichos <tampakrap@gentoo.org>2013-10-03 21:53:38 +0200
committerTheo Chatzimichos <tampakrap@gentoo.org>2013-10-03 21:53:38 +0200
commit61f7269ffabd11b7de56507c69191be42d7cfa60 (patch)
tree2ad81bec8d0c124019b23c841d80882c303801bc /plugins/jetpack/modules/subscriptions.php
parentforgot to include new files of jetpack (diff)
downloadblogs-gentoo-61f7269ffabd11b7de56507c69191be42d7cfa60.tar.gz
blogs-gentoo-61f7269ffabd11b7de56507c69191be42d7cfa60.tar.bz2
blogs-gentoo-61f7269ffabd11b7de56507c69191be42d7cfa60.zip
update jetpack
Diffstat (limited to 'plugins/jetpack/modules/subscriptions.php')
-rw-r--r--plugins/jetpack/modules/subscriptions.php144
1 files changed, 86 insertions, 58 deletions
diff --git a/plugins/jetpack/modules/subscriptions.php b/plugins/jetpack/modules/subscriptions.php
index 22366d07..1becb481 100644
--- a/plugins/jetpack/modules/subscriptions.php
+++ b/plugins/jetpack/modules/subscriptions.php
@@ -5,11 +5,13 @@
* Sort Order: 3
* First Introduced: 1.2
* Requires Connection: Yes
+ * Auto Activate: Yes
*/
add_action( 'jetpack_modules_loaded', 'jetpack_subscriptions_load' );
-Jetpack_Sync::sync_options( __FILE__,
+Jetpack_Sync::sync_options(
+ __FILE__,
'home',
'blogname',
'siteurl',
@@ -39,6 +41,8 @@ function jetpack_subscriptions_configuration_load() {
class Jetpack_Subscriptions {
var $jetpack = false;
+ public static $hash;
+
/**
* Singleton
* @static
@@ -56,6 +60,10 @@ class Jetpack_Subscriptions {
function Jetpack_Subscriptions() {
$this->jetpack = Jetpack::init();
+ // Don't use COOKIEHASH as it could be shared across installs && is non-unique in multisite.
+ // @see: https://twitter.com/nacin/status/378246957451333632
+ self::$hash = md5( get_option( 'siteurl' ) );
+
add_filter( 'jetpack_xmlrpc_methods', array( $this, 'xmlrpc_methods' ) );
// @todo remove sync from subscriptions and move elsewhere...
@@ -82,7 +90,9 @@ class Jetpack_Subscriptions {
return false;
}
- return 'publish' === $post->post_status && strlen( (string) $post->post_password ) < 1;
+ if ( 'publish' === $post->post_status && strlen( (string) $post->post_password ) < 1 ) {
+ return apply_filters( 'jetpack_is_post_mailable', true );
+ }
}
/**
@@ -92,9 +102,12 @@ class Jetpack_Subscriptions {
* @param array $methods
*/
function xmlrpc_methods( $methods ) {
- return array_merge( $methods, array(
- 'jetpack.subscriptions.subscribe' => array( $this, 'subscribe' ),
- ) );
+ return array_merge(
+ $methods,
+ array(
+ 'jetpack.subscriptions.subscribe' => array( $this, 'subscribe' ),
+ )
+ );
}
/**
@@ -158,7 +171,7 @@ class Jetpack_Subscriptions {
add_settings_field(
'invitation',
- __( 'Blog follow email text' , 'jetpack' ),
+ __( 'Blog follow email text', 'jetpack' ),
array( $this, 'setting_invitation' ),
'reading',
'email_settings'
@@ -235,25 +248,25 @@ class Jetpack_Subscriptions {
}
public function reading_section() {
- _e( 'These settings change emails sent from your blog to followers.' , 'jetpack');
+ _e( 'These settings change emails sent from your blog to followers.', 'jetpack' );
}
public function setting_invitation() {
$settings = $this->get_settings();
echo '<textarea name="subscription_options[invitation]" class="large-text" cols="50" rows="5">'.$settings['invitation'].'</textarea>';
- echo '<p><span class="description">'.__( 'Introduction text sent when someone follows your blog. (Site and confirmation details will be automatically added for you.)' , 'jetpack').'</span></p>';
+ echo '<p><span class="description">'.__( 'Introduction text sent when someone follows your blog. (Site and confirmation details will be automatically added for you.)', 'jetpack' ).'</span></p>';
}
public function setting_comment_follow() {
$settings = $this->get_settings();
echo '<textarea name="subscription_options[comment_follow]" class="large-text" cols="50" rows="5">'.$settings['comment_follow'].'</textarea>';
- echo '<p><span class="description">'.__( 'Introduction text sent when someone follows a post on your blog. (Site and confirmation details will be automatically added for you.)' , 'jetpack').'</span></p>';
+ echo '<p><span class="description">'.__( 'Introduction text sent when someone follows a post on your blog. (Site and confirmation details will be automatically added for you.)', 'jetpack' ).'</span></p>';
}
function get_default_settings() {
return array(
- 'invitation' => __( "Howdy.\n\nYou recently followed this blog's posts. This means you will receive each new post by email.\n\nTo activate, click confirm below. If you believe this is an error, ignore this message and we'll never bother you again." , 'jetpack'),
- 'comment_follow' => __( "Howdy.\n\nYou recently followed one of my posts. This means you will receive an email when new comments are posted.\n\nTo activate, click confirm below. If you believe this is an error, ignore this message and we'll never bother you again." , 'jetpack')
+ 'invitation' => __( "Howdy.\n\nYou recently followed this blog's posts. This means you will receive each new post by email.\n\nTo activate, click confirm below. If you believe this is an error, ignore this message and we'll never bother you again.", 'jetpack' ),
+ 'comment_follow' => __( "Howdy.\n\nYou recently followed one of my posts. This means you will receive an email when new comments are posted.\n\nTo activate, click confirm below. If you believe this is an error, ignore this message and we'll never bother you again.", 'jetpack' )
);
}
@@ -280,7 +293,7 @@ class Jetpack_Subscriptions {
* unknown : strange error. Jetpack servers at WordPress.com returned something malformed.
* unknown_status : strange error. Jetpack servers at WordPress.com returned something I didn't understand.
*/
- function subscribe( $email, $post_ids = 0, $async = true ) {
+ function subscribe( $email, $post_ids = 0, $async = true, $extra_data = array() ) {
if ( !is_email( $email ) ) {
return new Jetpack_Error( 'invalid_email' );
}
@@ -290,7 +303,7 @@ class Jetpack_Subscriptions {
$xml = new Jetpack_IXR_ClientMulticall();
}
- foreach( (array) $post_ids as $post_id ) {
+ foreach ( (array) $post_ids as $post_id ) {
$post_id = (int) $post_id;
if ( $post_id < 0 ) {
return new Jetpack_Error( 'invalid_post_id' );
@@ -299,9 +312,9 @@ class Jetpack_Subscriptions {
}
if ( $async ) {
- Jetpack::xmlrpc_async_call( 'jetpack.subscribeToSite', $email, $post_id );
+ Jetpack::xmlrpc_async_call( 'jetpack.subscribeToSite', $email, $post_id, serialize( $extra_data ) );
} else {
- $xml->addCall( 'jetpack.subscribeToSite', $email, $post_id );
+ $xml->addCall( 'jetpack.subscribeToSite', $email, $post_id, serialize( $extra_data ) );
}
}
@@ -319,7 +332,7 @@ class Jetpack_Subscriptions {
$responses = $xml->getResponse();
$r = array();
- foreach( (array) $responses as $response ) {
+ foreach ( (array) $responses as $response ) {
if ( isset( $response['faultCode'] ) || isset( $response['faultString'] ) ) {
$r[] = $xml->get_jetpack_error( $response['faultCode'], $response['faultString'] );
continue;
@@ -383,7 +396,17 @@ class Jetpack_Subscriptions {
$redirect_fragment = 'subscribe-blog';
}
- $subscribe = Jetpack_Subscriptions::subscribe( $_REQUEST['email'], 0, false );
+ $subscribe = Jetpack_Subscriptions::subscribe(
+ $_REQUEST['email'],
+ 0,
+ false,
+ array(
+ 'source' => 'widget',
+ 'widget-in-use' => is_active_widget( false, false, 'blog_subscription', true ) ? 'yes' : 'no',
+ 'comment_status' => '',
+ 'server_data' => $_SERVER,
+ )
+ );
if ( is_wp_error( $subscribe ) ) {
$error = $subscribe->get_error_code();
@@ -398,7 +421,7 @@ class Jetpack_Subscriptions {
}
if ( $error ) {
- switch( $error ) {
+ switch ( $error ) {
case 'invalid_email':
$redirect = add_query_arg( 'subscribe', 'invalid_email' );
break;
@@ -422,18 +445,18 @@ class Jetpack_Subscriptions {
*
* Set up and add the comment subscription checkbox to the comment form.
*/
- function comment_subscribe_init() {
- global $post;
+ function comment_subscribe_init() {
+ global $post;
- $comments_checked = '';
- $blog_checked = '';
+ $comments_checked = '';
+ $blog_checked = '';
- // Check for a comment / blog submission and set a cookie to retain the setting and check the boxes.
- if ( isset( $_COOKIE[ 'jetpack_comments_subscribe_' . COOKIEHASH ] ) && $_COOKIE[ 'jetpack_comments_subscribe_' . COOKIEHASH ] == $post->ID )
- $comments_checked = ' checked="checked"';
+ // Check for a comment / blog submission and set a cookie to retain the setting and check the boxes.
+ if ( isset( $_COOKIE[ 'jetpack_comments_subscribe_' . self::$hash ] ) && $_COOKIE[ 'jetpack_comments_subscribe_' . self::$hash ] == $post->ID )
+ $comments_checked = ' checked="checked"';
- if ( isset( $_COOKIE[ 'jetpack_blog_subscribe_' . COOKIEHASH ] ) )
- $blog_checked = ' checked="checked"';
+ if ( isset( $_COOKIE[ 'jetpack_blog_subscribe_' . self::$hash ] ) )
+ $blog_checked = ' checked="checked"';
// Some themes call this function, don't show the checkbox again
remove_action( 'comment_form', 'subscription_comment_form' );
@@ -457,14 +480,14 @@ class Jetpack_Subscriptions {
}
echo apply_filters( 'jetpack_comment_subscription_form', $str );
- }
+ }
/**
* Jetpack_Subscriptions::comment_subscribe_init()
*
* When a user checks the comment subscribe box and submits a comment, subscribe them to the comment thread.
*/
- function comment_subscribe_submit( $comment_id, $approved ) {
+ function comment_subscribe_submit( $comment_id, $approved ) {
if ( 'spam' === $approved ) {
return;
}
@@ -472,10 +495,10 @@ class Jetpack_Subscriptions {
// Set cookies for this post/comment
$this->set_cookies( isset( $_REQUEST['subscribe_comments'] ), isset( $_REQUEST['subscribe_blog'] ) );
- if ( !isset( $_REQUEST['subscribe_comments'] ) && !isset( $_REQUEST['subscribe_blog'] ) )
+ if ( !isset( $_REQUEST['subscribe_comments'] ) && !isset( $_REQUEST['subscribe_blog'] ) )
return;
- $comment = get_comment( $comment_id );
+ $comment = get_comment( $comment_id );
$post_ids = array();
if ( isset( $_REQUEST['subscribe_comments'] ) )
@@ -484,29 +507,41 @@ class Jetpack_Subscriptions {
if ( isset( $_REQUEST['subscribe_blog'] ) )
$post_ids[] = 0;
- Jetpack_Subscriptions::subscribe( $comment->comment_author_email, $post_ids );
- }
+ Jetpack_Subscriptions::subscribe(
+ $comment->comment_author_email,
+ $post_ids,
+ true,
+ array(
+ 'source' => 'comment-form',
+ 'widget-in-use' => is_active_widget( false, false, 'blog_subscription', true ) ? 'yes' : 'no',
+ 'comment_status' => $approved,
+ 'server_data' => $_SERVER,
+ )
+ );
+ }
/**
* Jetpack_Subscriptions::set_cookies()
*
* Set a cookie to save state on the comment and post subscription checkboxes.
*/
- function set_cookies( $comments = true, $posts = true ) {
- global $post;
+ function set_cookies( $comments = true, $posts = true ) {
+ global $post;
- $cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 );
+ $cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 );
+ $cookie_path = apply_filters( 'jetpack_comment_cookie_path', COOKIEPATH );
+ $cookie_domain = apply_filters( 'jetpack_comment_cookie_domain', COOKIE_DOMAIN );
if ( $comments )
- setcookie( 'jetpack_comments_subscribe_' . COOKIEHASH, $post->ID, time() + $cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN );
+ setcookie( 'jetpack_comments_subscribe_' . self::$hash, $post->ID, time() + $cookie_lifetime, $cookie_path, $cookie_domain );
else
- setcookie( 'jetpack_comments_subscribe_' . COOKIEHASH, '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN );
+ setcookie( 'jetpack_comments_subscribe_' . self::$hash, '', time() - 3600, $cookie_path, $cookie_domain );
if ( $posts )
- setcookie( 'jetpack_blog_subscribe_' . COOKIEHASH, 1, time() + $cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN );
+ setcookie( 'jetpack_blog_subscribe_' . self::$hash, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain );
else
- setcookie( 'jetpack_blog_subscribe_' . COOKIEHASH, '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN );
- }
+ setcookie( 'jetpack_blog_subscribe_' . self::$hash, '', time() - 3600, $cookie_path, $cookie_domain );
+ }
}
Jetpack_Subscriptions::init();
@@ -527,17 +562,13 @@ class Jetpack_Subscriptions_Widget extends WP_Widget {
function widget( $args, $instance ) {
global $current_user;
- $source = 'widget';
-
- extract( $args );
-
+ $source = 'widget';
$instance = wp_parse_args( (array) $instance, $this->defaults() );
- $title = isset( $instance['title'] ) ? stripslashes( $instance['title'] ) : '';
$subscribe_text = isset( $instance['subscribe_text'] ) ? stripslashes( $instance['subscribe_text'] ) : '';
$subscribe_button = isset( $instance['subscribe_button'] ) ? stripslashes( $instance['subscribe_button'] ) : '';
- $subscribe_logged_in = isset( $instance['subscribe_logged_in'] ) ? stripslashes( $instance['subscribe_logged_in'] ) : '';
$show_subscribers_total = (bool) $instance['show_subscribers_total'];
$subscribers_total = $this->fetch_subscriber_count();
+ $widget_id = esc_attr( !empty( $args['widget_id'] ) ? esc_attr( $args['widget_id'] ) : mt_rand( 450, 550 ) );
if ( ! is_array( $subscribers_total ) )
$show_subscribers_total = FALSE;
@@ -575,7 +606,7 @@ class Jetpack_Subscriptions_Widget extends WP_Widget {
endif;
// Display a subscribe form ?>
- <form action="" method="post" accept-charset="utf-8" id="subscribe-blog-<?php echo !empty( $args['widget_id'] ) ? esc_attr( $args['widget_id'] ) : mt_rand( 450, 550 ); ?>">
+ <form action="" method="post" accept-charset="utf-8" id="subscribe-blog-<?php echo $widget_id; ?>">
<?php
if ( ! isset ( $_GET['subscribe'] ) ) {
?><p><?php echo $subscribe_text ?></p><?php
@@ -592,7 +623,7 @@ class Jetpack_Subscriptions_Widget extends WP_Widget {
<input type="hidden" name="action" value="subscribe" />
<input type="hidden" name="source" value="<?php echo esc_url( $referer ); ?>" />
<input type="hidden" name="sub-type" value="<?php echo esc_attr( $source ); ?>" />
- <input type="hidden" name="redirect_fragment" value="<?php echo esc_attr( $widget_id ); ?>" />
+ <input type="hidden" name="redirect_fragment" value="<?php echo $widget_id; ?>" />
<?php
if ( is_user_logged_in() ) {
wp_nonce_field( 'blogsub_subscribe_'. get_current_blog_id(), '_wpnonce', false );
@@ -621,9 +652,7 @@ class Jetpack_Subscriptions_Widget extends WP_Widget {
if ( FALSE === $subs_count || 'failed' == $subs_count['status'] ) {
Jetpack:: load_xml_rpc_client();
- $xml = new Jetpack_IXR_Client( array(
- 'user_id' => JETPACK_MASTER_USER,
- ) );
+ $xml = new Jetpack_IXR_Client( array( 'user_id' => JETPACK_MASTER_USER, ) );
$xml->query( 'jetpack.fetchSubscriberCount' );
@@ -650,11 +679,11 @@ class Jetpack_Subscriptions_Widget extends WP_Widget {
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
- $instance['title'] = wp_kses( stripslashes( $new_instance['title'] ), array() );
- $instance['subscribe_text'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_text'] ) );
- $instance['subscribe_logged_in'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_logged_in'] ) );
- $instance['subscribe_button'] = wp_kses( stripslashes( $new_instance['subscribe_button'] ), array() );
- $instance['show_subscribers_total'] = isset( $new_instance['show_subscribers_total'] ) && $new_instance['show_subscribers_total'];
+ $instance['title'] = wp_kses( stripslashes( $new_instance['title'] ), array() );
+ $instance['subscribe_text'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_text'] ) );
+ $instance['subscribe_logged_in'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_logged_in'] ) );
+ $instance['subscribe_button'] = wp_kses( stripslashes( $new_instance['subscribe_button'] ), array() );
+ $instance['show_subscribers_total'] = isset( $new_instance['show_subscribers_total'] ) && $new_instance['show_subscribers_total'];
return $instance;
}
@@ -681,7 +710,6 @@ class Jetpack_Subscriptions_Widget extends WP_Widget {
if ( 'failed' == $subs_fetch['status'] ) {
printf( '<div class="error inline"><p>' . __( '%s: %s', 'jetpack' ) . '</p></div>', esc_html( $subs_fetch['code'] ), esc_html( $subs_fetch['message'] ) );
-
}
$subscribers_total = number_format_i18n( $subs_fetch['value'] );