summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/widgets/gravatar-profile.php')
-rw-r--r--plugins/jetpack/modules/widgets/gravatar-profile.php179
1 files changed, 122 insertions, 57 deletions
diff --git a/plugins/jetpack/modules/widgets/gravatar-profile.php b/plugins/jetpack/modules/widgets/gravatar-profile.php
index d2b13d12..14f8f78a 100644
--- a/plugins/jetpack/modules/widgets/gravatar-profile.php
+++ b/plugins/jetpack/modules/widgets/gravatar-profile.php
@@ -1,10 +1,10 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+
+add_action( 'widgets_init', 'jetpack_gravatar_profile_widget_init' );
/**
* Register the widget for use in Appearance -> Widgets
*/
-add_action( 'widgets_init', 'jetpack_gravatar_profile_widget_init' );
-
function jetpack_gravatar_profile_widget_init() {
register_widget( 'Jetpack_Gravatar_Profile_Widget' );
}
@@ -14,8 +14,10 @@ function jetpack_gravatar_profile_widget_init() {
* https://blog.gravatar.com/2010/03/26/gravatar-profiles/
*/
class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
-
- function __construct() {
+ /**
+ * Jetpack_Gravatar_Profile_Widget constructor.
+ */
+ public function __construct() {
parent::__construct(
'grofile',
/** This filter is documented in modules/widgets/facebook-likebox.php */
@@ -36,7 +38,15 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
}
}
- function widget( $args, $instance ) {
+ /**
+ * Display the Widget.
+ *
+ * @see WP_Widget::widget()
+ *
+ * @param array $args Display arguments.
+ * @param array $instance The settings for the particular instance of the widget.
+ */
+ public function widget( $args, $instance ) {
/**
* Fires when an item is displayed on the front end.
*
@@ -52,7 +62,8 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
do_action( 'jetpack_stats_extra', 'widget_view', 'grofile' );
$instance = wp_parse_args(
- $instance, array(
+ $instance,
+ array(
'title' => '',
'email' => '',
)
@@ -63,26 +74,38 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
if ( ! $instance['email'] ) {
if ( current_user_can( 'edit_theme_options' ) ) {
- echo $args['before_widget'];
+ echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
if ( ! empty( $title ) ) {
echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
- echo '<p>' . sprintf( __( 'You need to select what to show in this <a href="%s">Gravatar Profile widget</a>.', 'jetpack' ), admin_url( 'widgets.php' ) ) . '</p>';
- echo $args['after_widget'];
+ echo '<p>' . wp_kses(
+ sprintf(
+ /* translators: %s is a link to the widget settings page. */
+ __( 'You need to select what to show in this <a href="%s">Gravatar Profile widget</a>.', 'jetpack' ),
+ admin_url( 'widgets.php' )
+ ),
+ array(
+ 'a' => array(
+ 'href' => true,
+ ),
+ )
+ ) . '</p>';
+ echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
return;
}
- echo $args['before_widget'];
+ echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
if ( ! empty( $title ) ) {
- echo $args['before_title'] . $title . $args['after_title'];
+ echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
$profile = $this->get_profile( $instance['email'] );
if ( ! empty( $profile ) ) {
$profile = wp_parse_args(
- $profile, array(
+ $profile,
+ array(
'thumbnailUrl' => '',
'profileUrl' => '',
'displayName' => '',
@@ -91,7 +114,7 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
'accounts' => array(),
)
);
- $gravatar_url = add_query_arg( 's', 320, $profile['thumbnailUrl'] ); // the default grav returned by grofiles is super small
+ $gravatar_url = add_query_arg( 's', 320, $profile['thumbnailUrl'] ); // The default grav returned by grofiles is super small.
// Enqueue front end assets.
$this->enqueue_scripts();
@@ -142,10 +165,15 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
}
}
- echo $args['after_widget'];
+ echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
- function display_personal_links( $personal_links = array() ) {
+ /**
+ * Displays the "Personal Links" section.
+ *
+ * @param array $personal_links Array of links.
+ */
+ public function display_personal_links( $personal_links = array() ) {
if ( empty( $personal_links ) ) {
return;
}
@@ -168,7 +196,7 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
__( 'Personal Links', 'jetpack' )
)
);
- ?>
+ ?>
</h4>
<ul class="grofile-urls grofile-links">
@@ -187,7 +215,12 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
<?php
}
- function display_accounts( $accounts = array() ) {
+ /**
+ * Displays the "Verified Services" accounts.
+ *
+ * @param array $accounts Array of social accounts.
+ */
+ public function display_accounts( $accounts = array() ) {
if ( empty( $accounts ) ) {
return;
}
@@ -197,34 +230,40 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
<?php
echo esc_html(
/**
- * Filter the Gravatar Profile widget's "Verified Services" section title.
- *
- * @module widgets
- *
- * @since 2.8.0
- *
- * @param string $str "Verified Services" section title.
- */
- apply_filters(
- 'jetpack_gravatar_verified_services_title',
- __( 'Verified Services', 'jetpack' )
- )
+ * Filter the Gravatar Profile widget's "Verified Services" section title.
+ *
+ * @module widgets
+ *
+ * @since 2.8.0
+ *
+ * @param string $str "Verified Services" section title.
+ */
+ apply_filters(
+ 'jetpack_gravatar_verified_services_title',
+ __( 'Verified Services', 'jetpack' )
+ )
);
- ?>
+ ?>
</h4>
<ul class="grofile-urls grofile-accounts">
<?php
foreach ( $accounts as $account ) :
- if ( $account['verified'] != 'true' ) {
+ if ( 'true' !== $account['verified'] ) {
continue;
}
$sanitized_service_name = $this->get_sanitized_service_name( $account['shortname'] );
+ $link_title = sprintf(
+ /* translators: %1$s: service username. %2$s: service name ( Facebook, Twitter, etc.) */
+ _x( '%1$s on %2$s', '1: User Name, 2: Service Name (Facebook, Twitter, ...)', 'jetpack' ),
+ esc_html( $account['display'] ),
+ esc_html( $sanitized_service_name )
+ );
?>
<li>
- <a href="<?php echo esc_url( $account['url'] ); ?>" title="<?php echo sprintf( _x( '%1$s on %2$s', '1: User Name, 2: Service Name (Facebook, Twitter, ...)', 'jetpack' ), esc_html( $account['display'] ), esc_html( $sanitized_service_name ) ); ?>">
+ <a href="<?php echo esc_url( $account['url'] ); ?>" title="<?php echo esc_html( $link_title ); ?>">
<span class="grofile-accounts-logo grofile-accounts-<?php echo esc_attr( $account['shortname'] ); ?> accounts_<?php echo esc_attr( $account['shortname'] ); ?>"></span>
</a>
</li>
@@ -240,7 +279,7 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
*
* @since 4.0.0
*/
- function enqueue_scripts() {
+ public function enqueue_scripts() {
wp_enqueue_style(
'gravatar-profile-widget',
plugins_url( 'gravatar-profile.css', __FILE__ ),
@@ -256,7 +295,12 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
);
}
- function form( $instance ) {
+ /**
+ * Outputs the widget settings form.
+ *
+ * @param array $instance Current settings.
+ */
+ public function form( $instance ) {
$title = isset( $instance['title'] ) ? $instance['title'] : '';
$email = isset( $instance['email'] ) ? $instance['email'] : '';
$email_user = isset( $instance['email_user'] ) ? $instance['email_user'] : get_current_user_id();
@@ -267,19 +311,19 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
$profile_url = admin_url( 'profile.php' );
- if ( isset( $_REQUEST['calypso'] ) ) {
+ if ( isset( $_REQUEST['calypso'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$profile_url = 'https://wordpress.com/me';
}
}
?>
<p>
- <label for="<?php echo $this->get_field_id( 'title' ); ?>">
- <?php esc_html_e( 'Title', 'jetpack' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
+ <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
+ <?php esc_html_e( 'Title', 'jetpack' ); ?> <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</label>
</p>
<p>
- <label for="<?php echo $this->get_field_id( 'email_user' ); ?>">
+ <label for="<?php echo esc_attr( $this->get_field_id( 'email_user' ) ); ?>">
<?php esc_html_e( 'Select a user or pick "custom" and enter a custom email address.', 'jetpack' ); ?>
<br />
@@ -297,15 +341,15 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
</label>
</p>
- <p class="gprofile-email-container <?php echo empty( $email_user ) || $email_user == -1 ? '' : 'hidden'; ?>">
- <label for="<?php echo $this->get_field_id( 'email' ); ?>"><?php esc_html_e( 'Custom Email Address', 'jetpack' ); ?>
- <input class="widefat" id="<?php echo $this->get_field_id( 'email' ); ?>" name="<?php echo $this->get_field_name( 'email' ); ?>" type="text" value="<?php echo esc_attr( $email ); ?>" />
+ <p class="gprofile-email-container <?php echo empty( $email_user ) || -1 === (int) $email_user ? '' : 'hidden'; ?>">
+ <label for="<?php echo esc_attr( $this->get_field_id( 'email' ) ); ?>"><?php esc_html_e( 'Custom Email Address', 'jetpack' ); ?>
+ <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'email' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'email' ) ); ?>" type="text" value="<?php echo esc_attr( $email ); ?>" />
</label>
</p>
<p>
- <label for="<?php echo $this->get_field_id( 'show_personal_links' ); ?>">
- <input type="checkbox" name="<?php echo $this->get_field_name( 'show_personal_links' ); ?>" id="<?php echo $this->get_field_id( 'show_personal_links' ); ?>" <?php checked( $show_personal_links ); ?> />
+ <label for="<?php echo esc_attr( $this->get_field_id( 'show_personal_links' ) ); ?>">
+ <input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_personal_links' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'show_personal_links' ) ); ?>" <?php checked( $show_personal_links ); ?> />
<?php esc_html_e( 'Show Personal Links', 'jetpack' ); ?>
<br />
<small><?php esc_html_e( 'Links to your websites, blogs, or any other sites that help describe who you are.', 'jetpack' ); ?></small>
@@ -313,8 +357,8 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
</p>
<p>
- <label for="<?php echo $this->get_field_id( 'show_account_links' ); ?>">
- <input type="checkbox" name="<?php echo $this->get_field_name( 'show_account_links' ); ?>" id="<?php echo $this->get_field_id( 'show_account_links' ); ?>" <?php checked( $show_account_links ); ?> />
+ <label for="<?php echo esc_attr( $this->get_field_id( 'show_account_links' ) ); ?>">
+ <input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_account_links' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'show_account_links' ) ); ?>" <?php checked( $show_account_links ); ?> />
<?php esc_html_e( 'Show Account Links', 'jetpack' ); ?>
<br />
<small><?php esc_html_e( 'Links to services that you use across the web.', 'jetpack' ); ?></small>
@@ -326,7 +370,10 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
<?php
}
- function admin_script() {
+ /**
+ * Inline admin script.
+ */
+ public function admin_script() {
?>
<script>
jQuery( function( $ ) {
@@ -343,8 +390,15 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
<?php
}
- function update( $new_instance, $old_instance ) {
-
+ /**
+ * Update widget.
+ *
+ * @see WP_Widget::update()
+ *
+ * @param array $new_instance New widget instance data.
+ * @param array $old_instance Old widget instance data.
+ */
+ public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$instance = array();
$instance['title'] = isset( $new_instance['title'] ) ? wp_kses( $new_instance['title'], array() ) : '';
@@ -365,11 +419,17 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
return $instance;
}
+ /**
+ * Get the Gravatar profile for a given email address.
+ *
+ * @param string $email Email address.
+ */
private function get_profile( $email ) {
$hashed_email = md5( strtolower( trim( $email ) ) );
$cache_key = 'grofile-' . $hashed_email;
+ $profile = get_transient( $cache_key );
- if ( ! $profile = get_transient( $cache_key ) ) {
+ if ( ! $profile ) {
$profile_url = sprintf(
'https://secure.gravatar.com/%s.json',
$hashed_email
@@ -381,19 +441,19 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
array( 'User-Agent' => 'WordPress.com Gravatar Profile Widget' )
);
$response_code = wp_remote_retrieve_response_code( $response );
- if ( 200 == $response_code ) {
+ if ( 200 === $response_code ) {
$profile = wp_remote_retrieve_body( $response );
$profile = json_decode( $profile, true );
if ( is_array( $profile ) && ! empty( $profile['entry'] ) && is_array( $profile['entry'] ) ) {
- $expire = 900; // cache for 15 minutes
+ $expire = 900; // Cache for 15 minutes.
$profile = $profile['entry'][0];
} else {
// Something strange happened. Cache for 5 minutes.
$profile = array();
}
} else {
- $expire = 900; // cache for 15 minutes
+ $expire = 900; // Cache for 15 minutes.
$profile = array();
}
@@ -402,8 +462,15 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
return $profile;
}
+ /**
+ * Return properly capitalized service name.
+ *
+ * @param string $shortname The service.
+ *
+ * @return string
+ */
private function get_sanitized_service_name( $shortname ) {
- // Some services have stylized or mixed cap names *cough* WP *cough*
+ // Some services have stylized or mixed cap names *cough* WP *cough*.
switch ( $shortname ) {
case 'friendfeed':
return 'FriendFeed';
@@ -425,11 +492,9 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
case 'google':
return 'Google+';
default:
- // Others don't
+ // Others don't.
$shortname = ucwords( $shortname );
}
return $shortname;
}
}
-
-// END