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.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / gravatar-hovercards.php
jetpack / modules Last commit date
canonical-urls 2 months ago carousel 4 days ago comment-likes 6 months ago comments 1 week ago custom-post-types 3 months ago external-media 6 months ago google-fonts 4 months ago gravatar 5 years ago infinite-scroll 1 week ago likes 1 week ago markdown 1 week ago memberships 1 week ago photon-cdn 1 month ago plugin-search 1 month ago post-by-email 6 months ago related-posts 4 days ago scan 2 months ago seo-tools 1 week ago sharedaddy 1 week ago shortcodes 1 week ago shortlinks 1 week ago simple-payments 6 months ago site-icon 6 months ago sitemaps 1 week ago stats 5 months ago subscriptions 4 days ago theme-tools 2 weeks ago tiled-gallery 1 week ago verification-tools 2 weeks ago videopress 1 week ago widget-visibility 1 week ago widgets 4 days ago woocommerce-analytics 1 month ago wordads 1 month ago wpcom-tos 5 months ago account-protection.php 1 month ago blaze.php 6 months ago blocks.php 6 months ago canonical-urls.php 3 months ago carousel.php 6 months ago comment-likes.php 6 months ago comments.php 2 months ago contact-form.php 6 months ago copy-post.php 2 weeks ago custom-content-types.php 1 month ago google-fonts.php 1 month ago gravatar-hovercards.php 1 week ago infinite-scroll.php 6 months ago json-api.php 6 months ago latex.php 1 week ago likes.php 1 month ago markdown.php 6 months ago module-extras.php 6 months ago module-headings.php 1 week ago module-info.php 3 months ago monitor.php 4 days ago notes.php 5 months ago photon-cdn.php 6 months ago photon.php 6 months ago plugin-search.php 1 month ago post-by-email.php 1 month ago post-list.php 6 months ago protect.php 1 month ago publicize.php 6 months ago related-posts.php 2 weeks ago search.php 6 months ago seo-tools.php 6 months ago sharedaddy.php 3 months ago shortcodes.php 6 months ago shortlinks.php 2 weeks ago simple-payments.php 6 months ago sitemaps.php 6 months ago sso.php 6 months ago stats.php 1 week ago subscriptions.php 1 week ago theme-tools.php 6 months ago tiled-gallery.php 6 months ago vaultpress.php 6 months ago verification-tools.php 1 month ago videopress.php 6 months ago waf.php 6 months ago widget-visibility.php 6 months ago widgets.php 6 months ago woocommerce-analytics.php 6 months ago wordads.php 6 months ago wpcom-reader.php 3 months ago wpgroho.js 1 year ago
gravatar-hovercards.php
409 lines
1 <?php
2 /**
3 * Module Name: Gravatar Hovercards
4 * Module Description: Show a user’s Gravatar profile when visitors hover over their name or image.
5 * Sort Order: 11
6 * Recommendation Order: 13
7 * First Introduced: 1.1
8 * Requires Connection: No
9 * Auto Activate: No
10 * Module Tags: Social, Appearance
11 * Feature: Appearance
12 * Additional Search Queries: gravatar, hovercards
13 *
14 * @package automattic/jetpack
15 */
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit( 0 );
19 }
20
21 define( 'GROFILES__CACHE_BUSTER', gmdate( 'YW' ) );
22
23 /**
24 * Actions that are run on init.
25 */
26 function grofiles_hovercards_init() {
27 add_filter( 'get_avatar', 'grofiles_get_avatar', 10, 2 );
28 add_action( 'wp_enqueue_scripts', 'grofiles_attach_cards' );
29 add_action( 'wp_footer', 'grofiles_extra_data' );
30 add_action( 'admin_init', 'grofiles_add_settings' );
31
32 add_action( 'load-index.php', 'grofiles_admin_cards' );
33 add_action( 'load-users.php', 'grofiles_admin_cards' );
34 add_action( 'load-edit-comments.php', 'grofiles_admin_cards' );
35 add_action( 'load-options-discussion.php', 'grofiles_admin_cards_forced' );
36
37 add_filter( 'jetpack_module_configuration_url_gravatar-hovercards', 'gravatar_hovercards_configuration_url' );
38
39 add_filter( 'get_comment_author_url', 'grofiles_amp_comment_author_url', 10, 2 );
40 }
41
42 /**
43 * Set configuration page URL.
44 */
45 function gravatar_hovercards_configuration_url() {
46 return admin_url( 'options-discussion.php#show_avatars' );
47 }
48
49 add_action( 'jetpack_modules_loaded', 'grofiles_hovercards_init' );
50
51 /* Hovercard Settings */
52
53 /**
54 * Adds Gravatar Hovercard setting
55 *
56 * @todo - always print HTML, hide via CSS/JS if !show_avatars
57 */
58 function grofiles_add_settings() {
59 if ( ! get_option( 'show_avatars' ) ) {
60 return;
61 }
62
63 add_settings_field( 'gravatar_disable_hovercards', __( 'Gravatar Hovercards', 'jetpack' ), 'grofiles_setting_callback', 'discussion', 'avatars' );
64 register_setting( 'discussion', 'gravatar_disable_hovercards', 'grofiles_hovercard_option_sanitize' );
65 }
66
67 /**
68 * HTML for Gravatar Hovercard setting
69 */
70 function grofiles_setting_callback() {
71 global $current_user;
72
73 $option = get_option( 'gravatar_disable_hovercards' );
74 printf(
75 "<label id='gravatar-hovercard-options'><input %s name='gravatar_disable_hovercards' id='gravatar_disable_hovercards' type='checkbox' value='enabled' class='code'/>%s</label>",
76 checked( $option, 'enabled', false ),
77 esc_html__( 'View people\'s profiles when you mouse over their Gravatars', 'jetpack' )
78 );
79
80 ?>
81 <style type="text/css">
82 #grav-profile-example img {
83 float: left;
84 }
85 #grav-profile-example span {
86 padding: 0 1em;
87 }
88 </style>
89 <script type="text/javascript">
90 // <![CDATA[
91 jQuery( function($) {
92 var tr = $( '#gravatar_disable_hovercards' ).change( function() {
93 if ( $( this ).is( ':checked' ) ) {
94 $( '#grav-profile-example' ).slideDown( 'fast' );
95 } else {
96 $( '#grav-profile-example' ).slideUp( 'fast' );
97 }
98 } ).parents( 'tr' );
99 var ftr = tr.parents( 'table' ).find( 'tr:first' );
100 if ( ftr.length && !ftr.find( '#gravatar_disable_hovercards' ).length ) {
101 ftr.after( tr );
102 }
103 } );
104 // ]]>
105 </script>
106 <p id="grav-profile-example" class="hide-if-no-js"
107 <?php
108 if ( 'disabled' === $option ) {
109 echo ' style="display:none"';}
110 ?>
111 >
112 <?php echo get_avatar( $current_user->ID, 64 ); ?> <span><?php esc_html_e( 'Put your mouse over your Gravatar to check out your profile.', 'jetpack' ); ?> <br class="clear" /></span></p>
113 <?php
114 }
115
116 /**
117 * Sanitation filter for Gravatar Hovercard setting
118 *
119 * @param string $val Disabled or enabled.
120 */
121 function grofiles_hovercard_option_sanitize( $val ) {
122 if ( 'disabled' === $val ) {
123 return $val;
124 }
125
126 return $val ? 'enabled' : 'disabled';
127 }
128
129 /* Hovercard Display */
130
131 /**
132 * Stores the gravatars' users that need extra profile data attached.
133 *
134 * Getter/Setter
135 *
136 * @param int|string|null $author Setter: User ID or email address. Getter: null.
137 *
138 * @return mixed Setter: void. Getter: array of user IDs and email addresses.
139 */
140 function grofiles_gravatars_to_append( $author = null ) {
141 static $authors = array();
142
143 // Get.
144 if ( $author === null ) {
145 return array_keys( $authors );
146 }
147
148 // Set.
149
150 if ( is_numeric( $author ) ) {
151 $author = (int) $author;
152 }
153
154 $authors[ $author ] = true;
155 }
156
157 /**
158 * In AMP, override the comment URL to allow for interactivity without
159 * navigating to a new page
160 *
161 * @param string $url The comment author's URL.
162 * @param int $id The comment ID.
163 *
164 * @return string The adjusted URL
165 */
166 function grofiles_amp_comment_author_url( $url, $id ) {
167 if ( 'comment' === get_comment_type( $id ) && class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
168 // @todo Disabling the comment author link in this way is not ideal since clicking the link does not cause the lightbox to open in the same way as clicking the gravatar. Likely get_comment_author_url_link should be used instead so that the href attribute can be replaced with an `on` attribute that activates the gallery.
169 return '#!';
170 }
171
172 return $url;
173 }
174
175 /**
176 * Stores the user ID or email address for each gravatar generated.
177 *
178 * Attached to the 'get_avatar' filter.
179 *
180 * @param string $avatar The <img/> element of the avatar.
181 * @param mixed $author User ID, email address, user login, comment object, user object, post object.
182 *
183 * @return string The <img/> element of the avatar.
184 */
185 function grofiles_get_avatar( $avatar, $author ) {
186 $is_amp = class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request();
187
188 if ( is_numeric( $author ) ) {
189 grofiles_gravatars_to_append( $author );
190 } elseif ( is_string( $author ) ) {
191 if ( str_contains( $author, '@' ) ) {
192 grofiles_gravatars_to_append( $author );
193 } else {
194 $user = get_user_by( 'slug', $author );
195 if ( $user ) {
196 grofiles_gravatars_to_append( $user->ID );
197 }
198 }
199 } elseif ( isset( $author->comment_type ) ) {
200 if ( $is_amp ) {
201 if ( 1 === preg_match( '/avatar\/([a-zA-Z0-9]+)\?/', $avatar, $email_hash ) ) {
202 $email_hash = $email_hash[1];
203 $cache_group = 'gravatar_profiles_';
204 $cache_key = 'gravatar_profile_' . $email_hash;
205
206 $response_body = wp_cache_get( $cache_key, $cache_group );
207 if ( false === $response_body ) {
208 $response = wp_remote_get( esc_url_raw( 'https://gravatar.com/' . $email_hash . '.json' ) );
209 if ( is_array( $response ) && ! is_wp_error( $response ) ) {
210 $response_body = json_decode( $response['body'] );
211 wp_cache_set( $cache_key, $response_body, $cache_group, 60 * MINUTE_IN_SECONDS );
212 }
213 }
214
215 $profile = $response_body->entry[0] ?? null;
216 $display_name = $profile->displayName ?? ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
217 $location = $profile->currentLocation ?? ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
218 $description = $profile->aboutMe ?? ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
219
220 $avatar = '
221 <figure data-amp-lightbox="true">
222 ' . $avatar . '
223 <figcaption>
224 ' . esc_html( $display_name ) . ( ! empty( $location ) ? '' . esc_html( $location ) : '' ) . ( ! empty( $description ) ? '' . esc_html( $description ) : '' ) . '
225 </figcaption>
226 </figure>
227 ';
228 }
229
230 return $avatar;
231 }
232
233 if ( '' !== $author->comment_type && 'comment' !== $author->comment_type ) {
234 return $avatar;
235 }
236 if ( $author->user_id ) {
237 grofiles_gravatars_to_append( $author->user_id );
238 } else {
239 grofiles_gravatars_to_append( $author->comment_author_email );
240 }
241 } elseif ( isset( $author->user_login ) ) {
242 grofiles_gravatars_to_append( $author->ID );
243 } elseif ( isset( $author->post_author ) ) {
244 grofiles_gravatars_to_append( $author->post_author );
245 }
246
247 return $avatar;
248 }
249
250 /**
251 * Loads Gravatar Hovercard script.
252 */
253 function grofiles_attach_cards() {
254
255 // Is the display of Avatars disabled?
256 if ( ! get_option( 'show_avatars' ) ) {
257 return;
258 }
259
260 // Is the display of Gravatar Hovercards disabled?
261 if ( 'disabled' === Jetpack_Options::get_option_and_ensure_autoload( 'gravatar_disable_hovercards', '0' ) ) {
262 return;
263 }
264
265 // Hovercards are only relevant on pages that render avatars.
266 if ( ! is_singular() && ! is_home() && ! is_front_page() && ! is_archive() && ! is_search() ) {
267 return;
268 }
269
270 if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
271 wp_enqueue_style( 'gravatar-hovercard-style', plugins_url( '/gravatar/gravatar-hovercards-amp.css', __FILE__ ), array(), JETPACK__VERSION );
272 } else {
273 wp_enqueue_script( 'grofiles-cards', 'https://secure.gravatar.com/js/gprofiles.js', array(), GROFILES__CACHE_BUSTER, true );
274 wp_enqueue_script( 'wpgroho', plugins_url( 'wpgroho.js', __FILE__ ), array( 'grofiles-cards' ), JETPACK__VERSION, true );
275 if ( is_user_logged_in() ) {
276 $cu = wp_get_current_user();
277 $my_hash = md5( $cu->user_email );
278 } elseif ( ! empty( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) {
279 $my_hash = md5( filter_var( wp_unslash( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) );
280 } else {
281 $my_hash = '';
282 }
283 wp_localize_script( 'wpgroho', 'WPGroHo', compact( 'my_hash' ) );
284 }
285 }
286 /**
287 * Add hovercards on Discussion settings panel.
288 */
289 function grofiles_attach_cards_forced() {
290 add_filter( 'pre_option_gravatar_disable_hovercards', 'grofiles_force_gravatar_enable_hovercards' );
291 grofiles_attach_cards();
292 }
293 /**
294 * Set hovercards as enabled on Discussion settings panel.
295 */
296 function grofiles_force_gravatar_enable_hovercards() {
297 return 'enabled';
298 }
299 /**
300 * Add script to admin footer on Discussion settings panel.
301 */
302 function grofiles_admin_cards_forced() {
303 add_action( 'admin_footer', 'grofiles_attach_cards_forced' );
304 }
305 /**
306 * Add script to admin footer.
307 */
308 function grofiles_admin_cards() {
309 add_action( 'admin_footer', 'grofiles_attach_cards' );
310 }
311 /**
312 * Dequeue the FE assets when there are no gravatars on the page to be displayed.
313 */
314 function grofiles_extra_data() {
315 $authors = grofiles_gravatars_to_append();
316
317 if ( ! $authors ) {
318 wp_dequeue_script( 'grofiles-cards' );
319 wp_dequeue_script( 'wpgroho' );
320 } else {
321 ?>
322 <div style="display:none">
323 <?php
324 foreach ( $authors as $author ) {
325 grofiles_hovercards_data_html( $author );
326 }
327 ?>
328 </div>
329 <?php
330 }
331 }
332
333 /**
334 * Echoes the data from grofiles_hovercards_data() as HTML elements.
335 *
336 * @since 5.5.0 Add support for a passed WP_User object
337 *
338 * @param int|string|WP_User $author User ID, email address, or a WP_User object.
339 */
340 function grofiles_hovercards_data_html( $author ) {
341 $data = grofiles_hovercards_data( $author );
342 $hash = '';
343 if ( is_numeric( $author ) ) {
344 $user = get_userdata( $author );
345 if ( $user ) {
346 $hash = md5( $user->user_email );
347 }
348 } elseif ( is_email( $author ) ) {
349 $hash = md5( $author );
350 } elseif ( is_a( $author, 'WP_User' ) ) {
351 $hash = md5( $author->user_email );
352 }
353
354 if ( ! $hash ) {
355 return;
356 }
357 ?>
358 <div class="grofile-hash-map-<?php echo esc_attr( $hash ); ?>">
359 <?php foreach ( $data as $key => $value ) : ?>
360 <span class="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value ); ?></span>
361 <?php endforeach; ?>
362 </div>
363 <?php
364 }
365
366 /* API */
367
368 /**
369 * Returns the PHP callbacks for data sources.
370 *
371 * 'grofiles_hovercards_data_callbacks' filter
372 *
373 * @return array<string,callable> ( data_key => data_callback, ... )
374 */
375 function grofiles_hovercards_data_callbacks() {
376 /**
377 * Filter the Gravatar Hovercard PHP callbacks.
378 *
379 * @module gravatar-hovercards
380 *
381 * @since 1.1.0
382 *
383 * @param array $args Array of data callbacks.
384 */
385 return apply_filters( 'grofiles_hovercards_data_callbacks', array() );
386 }
387
388 /**
389 * Keyed JSON object containing all profile data provided by registered callbacks
390 *
391 * @param int|string $author User ID or email address.
392 *
393 * @return array<string,mixed> ( data_key => data, ... )
394 */
395 function grofiles_hovercards_data( $author ) {
396 $r = array();
397 foreach ( grofiles_hovercards_data_callbacks() as $key => $callback ) {
398 if ( ! is_callable( $callback ) ) {
399 continue;
400 }
401 $data = call_user_func( $callback, $author, $key );
402 if ( $data !== null ) {
403 $r[ $key ] = $data;
404 }
405 }
406
407 return $r;
408 }
409