PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 12.3.2
Jetpack – WP Security, Backup, Speed, & Growth v12.3.2
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.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 / widgets / gravatar-profile.php
jetpack / modules / widgets Last commit date
authors 8 years ago contact-info 5 years ago eu-cookie-law 4 years ago facebook-likebox 11 years ago flickr 4 years ago gallery 4 years ago goodreads 5 years ago google-translate 4 years ago image-widget 8 years ago instagram 6 years ago migrate-to-core 3 years ago milestone 3 years ago my-community 8 years ago simple-payments 4 years ago social-icons 4 years ago social-media-icons 5 years ago top-posts 8 years ago wordpress-post-widget 3 years ago authors.php 3 years ago blog-stats.php 3 years ago class-jetpack-eu-cookie-law-widget.php 3 years ago class-jetpack-instagram-widget.php 3 years ago contact-info.php 3 years ago customizer-controls.css 9 years ago customizer-utils.js 6 years ago facebook-likebox.php 3 years ago flickr.php 3 years ago gallery.php 3 years ago goodreads.php 3 years ago google-translate.php 3 years ago gravatar-profile.css 10 years ago gravatar-profile.php 3 years ago image-widget.php 3 years ago internet-defense-league.php 3 years ago mailchimp.php 3 years ago milestone.php 5 years ago my-community.php 3 years ago rsslinks-widget.php 3 years ago simple-payments.php 3 years ago social-icons.php 3 years ago social-media-icons.php 3 years ago top-posts.php 3 years ago twitter-timeline-admin.js 6 years ago twitter-timeline.php 3 years ago upcoming-events.php 3 years ago wordpress-post-widget.php 4 years ago
gravatar-profile.php
500 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
4
5 add_action( 'widgets_init', 'jetpack_gravatar_profile_widget_init' );
6 /**
7 * Register the widget for use in Appearance -> Widgets
8 */
9 function jetpack_gravatar_profile_widget_init() {
10 register_widget( 'Jetpack_Gravatar_Profile_Widget' );
11 }
12
13 /**
14 * Display a widgetized version of your Gravatar Profile
15 * https://blog.gravatar.com/2010/03/26/gravatar-profiles/
16 */
17 class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
18 /**
19 * Jetpack_Gravatar_Profile_Widget constructor.
20 */
21 public function __construct() {
22 parent::__construct(
23 'grofile',
24 /** This filter is documented in modules/widgets/facebook-likebox.php */
25 apply_filters( 'jetpack_widget_name', __( 'Gravatar Profile', 'jetpack' ) ),
26 array(
27 'classname' => 'widget-grofile grofile',
28 'description' => __( 'Display a mini version of your Gravatar Profile', 'jetpack' ),
29 'customize_selective_refresh' => true,
30 )
31 );
32
33 if ( is_admin() ) {
34 add_action( 'admin_footer-widgets.php', array( $this, 'admin_script' ) );
35 }
36
37 if ( is_customize_preview() ) {
38 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
39 }
40 }
41
42 /**
43 * Display the Widget.
44 *
45 * @see WP_Widget::widget()
46 *
47 * @param array $args Display arguments.
48 * @param array $instance The settings for the particular instance of the widget.
49 */
50 public function widget( $args, $instance ) {
51 /**
52 * Fires when an item is displayed on the front end.
53 *
54 * Can be used to track stats about the number of displays for a specific item
55 *
56 * @module widgets, shortcodes
57 *
58 * @since 1.6.0
59 *
60 * @param string widget_view Item type (e.g. widget, or embed).
61 * @param string grofile Item description (e.g. grofile, goodreads).
62 */
63 do_action( 'jetpack_stats_extra', 'widget_view', 'grofile' );
64
65 $instance = wp_parse_args(
66 $instance,
67 array(
68 'title' => '',
69 'email' => '',
70 )
71 );
72
73 /** This filter is documented in core/src/wp-includes/default-widgets.php */
74 $title = apply_filters( 'widget_title', $instance['title'] );
75
76 if ( ! $instance['email'] ) {
77 if ( current_user_can( 'edit_theme_options' ) ) {
78 echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
79 if ( ! empty( $title ) ) {
80 echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
81 }
82 echo '<p>' . wp_kses(
83 sprintf(
84 /* translators: %s is a link to the widget settings page. */
85 __( 'You need to select what to show in this <a href="%s">Gravatar Profile widget</a>.', 'jetpack' ),
86 admin_url( 'widgets.php' )
87 ),
88 array(
89 'a' => array(
90 'href' => true,
91 ),
92 )
93 ) . '</p>';
94 echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
95 }
96 return;
97 }
98
99 echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
100 if ( ! empty( $title ) ) {
101 echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
102 }
103
104 $profile = $this->get_profile( $instance['email'] );
105
106 if ( ! empty( $profile ) ) {
107 $profile = wp_parse_args(
108 $profile,
109 array(
110 'thumbnailUrl' => '',
111 'profileUrl' => '',
112 'displayName' => '',
113 'aboutMe' => '',
114 'urls' => array(),
115 'accounts' => array(),
116 )
117 );
118 $gravatar_url = add_query_arg( 's', 320, $profile['thumbnailUrl'] ); // The default grav returned by grofiles is super small.
119
120 // Enqueue front end assets.
121 $this->enqueue_scripts();
122
123 ?>
124 <img src="<?php echo esc_url( $gravatar_url ); ?>" class="grofile-thumbnail no-grav" alt="<?php echo esc_attr( $profile['displayName'] ); ?>" />
125 <div class="grofile-meta">
126 <h4><a href="<?php echo esc_url( $profile['profileUrl'] ); ?>"><?php echo esc_html( $profile['displayName'] ); ?></a></h4>
127 <p><?php echo wp_kses_post( $profile['aboutMe'] ); ?></p>
128 </div>
129
130 <?php
131
132 if ( $instance['show_personal_links'] ) {
133 $this->display_personal_links( (array) $profile['urls'] );
134 }
135
136 if ( $instance['show_account_links'] ) {
137 $this->display_accounts( (array) $profile['accounts'] );
138 }
139
140 ?>
141
142 <p><a href="<?php echo esc_url( $profile['profileUrl'] ); ?>" class="grofile-full-link">
143 <?php
144 echo esc_html(
145 /**
146 * Filter the Gravatar Profile widget's profile link title.
147 *
148 * @module widgets
149 *
150 * @since 2.8.0
151 *
152 * @param string $str Profile link title.
153 */
154 apply_filters(
155 'jetpack_gravatar_full_profile_title',
156 __( 'View Full Profile &rarr;', 'jetpack' )
157 )
158 );
159 ?>
160 </a></p>
161
162 <?php
163 } elseif ( current_user_can( 'edit_theme_options' ) ) {
164 echo '<p>' . esc_html__( 'Error loading profile', 'jetpack' ) . '</p>';
165 }
166
167 echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
168 }
169
170 /**
171 * Displays the "Personal Links" section.
172 *
173 * @param array $personal_links Array of links.
174 */
175 public function display_personal_links( $personal_links = array() ) {
176 if ( empty( $personal_links ) ) {
177 return;
178 }
179 ?>
180
181 <h4>
182 <?php
183 echo esc_html(
184 apply_filters(
185 /**
186 * Filter the Gravatar Profile widget's "Personal Links" section title.
187 *
188 * @module widgets
189 *
190 * @since 2.8.0
191 *
192 * @param string $str "Personal Links" section title.
193 */
194 'jetpack_gravatar_personal_links_title',
195 __( 'Personal Links', 'jetpack' )
196 )
197 );
198 ?>
199 </h4>
200 <ul class="grofile-urls grofile-links">
201
202 <?php foreach ( $personal_links as $personal_link ) : ?>
203 <li>
204 <a href="<?php echo esc_url( $personal_link['value'] ); ?>">
205 <?php
206 $link_title = ( ! empty( $personal_link['title'] ) ) ? $personal_link['title'] : $personal_link['value'];
207 echo esc_html( $link_title );
208 ?>
209 </a>
210 </li>
211 <?php endforeach; ?>
212 </ul>
213
214 <?php
215 }
216
217 /**
218 * Displays the "Verified Services" accounts.
219 *
220 * @param array $accounts Array of social accounts.
221 */
222 public function display_accounts( $accounts = array() ) {
223 if ( empty( $accounts ) ) {
224 return;
225 }
226 ?>
227
228 <h4>
229 <?php
230 echo esc_html(
231 /**
232 * Filter the Gravatar Profile widget's "Verified Services" section title.
233 *
234 * @module widgets
235 *
236 * @since 2.8.0
237 *
238 * @param string $str "Verified Services" section title.
239 */
240 apply_filters(
241 'jetpack_gravatar_verified_services_title',
242 __( 'Verified Services', 'jetpack' )
243 )
244 );
245 ?>
246 </h4>
247 <ul class="grofile-urls grofile-accounts">
248
249 <?php
250 foreach ( $accounts as $account ) :
251 if ( 'true' !== $account['verified'] ) {
252 continue;
253 }
254
255 $sanitized_service_name = $this->get_sanitized_service_name( $account['shortname'] );
256 $link_title = sprintf(
257 /* translators: %1$s: service username. %2$s: service name ( Facebook, Twitter, etc.) */
258 _x( '%1$s on %2$s', '1: User Name, 2: Service Name (Facebook, Twitter, ...)', 'jetpack' ),
259 esc_html( $account['display'] ),
260 esc_html( $sanitized_service_name )
261 );
262 ?>
263
264 <li>
265 <a href="<?php echo esc_url( $account['url'] ); ?>" title="<?php echo esc_html( $link_title ); ?>">
266 <span class="grofile-accounts-logo grofile-accounts-<?php echo esc_attr( $account['shortname'] ); ?> accounts_<?php echo esc_attr( $account['shortname'] ); ?>"></span>
267 </a>
268 </li>
269
270 <?php endforeach; ?>
271 </ul>
272
273 <?php
274 }
275
276 /**
277 * Enqueue CSS and JavaScript.
278 *
279 * @since 4.0.0
280 */
281 public function enqueue_scripts() {
282 wp_enqueue_style(
283 'gravatar-profile-widget',
284 plugins_url( 'gravatar-profile.css', __FILE__ ),
285 array(),
286 '20120711'
287 );
288
289 wp_enqueue_style(
290 'gravatar-card-services',
291 'https://secure.gravatar.com/css/services.css',
292 array(),
293 defined( 'GROFILES__CACHE_BUSTER' ) ? GROFILES__CACHE_BUSTER : gmdate( 'YW' )
294 );
295 }
296
297 /**
298 * Outputs the widget settings form.
299 *
300 * @param array $instance Current settings.
301 */
302 public function form( $instance ) {
303 $title = isset( $instance['title'] ) ? $instance['title'] : '';
304 $email = isset( $instance['email'] ) ? $instance['email'] : '';
305 $email_user = isset( $instance['email_user'] ) ? $instance['email_user'] : get_current_user_id();
306 $show_personal_links = isset( $instance['show_personal_links'] ) ? (bool) $instance['show_personal_links'] : '';
307 $show_account_links = isset( $instance['show_account_links'] ) ? (bool) $instance['show_account_links'] : '';
308 $profile_url = 'https://gravatar.com/profile/edit';
309
310 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
311 $profile_url = admin_url( 'profile.php' );
312
313 if ( isset( $_REQUEST['calypso'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
314 $profile_url = 'https://wordpress.com/me';
315 }
316 }
317 ?>
318 <p>
319 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
320 <?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 ); ?>" />
321 </label>
322 </p>
323
324 <p>
325 <label for="<?php echo esc_attr( $this->get_field_id( 'email_user' ) ); ?>">
326 <?php esc_html_e( 'Select a user or pick "custom" and enter a custom email address.', 'jetpack' ); ?>
327 <br />
328
329 <?php
330 wp_dropdown_users(
331 array(
332 'show_option_none' => __( 'Custom', 'jetpack' ),
333 'selected' => $email_user,
334 'name' => $this->get_field_name( 'email_user' ),
335 'id' => $this->get_field_id( 'email_user' ),
336 'class' => 'gravatar-profile-user-select',
337 )
338 );
339 ?>
340 </label>
341 </p>
342
343 <p class="gprofile-email-container <?php echo empty( $email_user ) || -1 === (int) $email_user ? '' : 'hidden'; ?>">
344 <label for="<?php echo esc_attr( $this->get_field_id( 'email' ) ); ?>"><?php esc_html_e( 'Custom Email Address', 'jetpack' ); ?>
345 <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 ); ?>" />
346 </label>
347 </p>
348
349 <p>
350 <label for="<?php echo esc_attr( $this->get_field_id( 'show_personal_links' ) ); ?>">
351 <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 ); ?> />
352 <?php esc_html_e( 'Show Personal Links', 'jetpack' ); ?>
353 <br />
354 <small><?php esc_html_e( 'Links to your websites, blogs, or any other sites that help describe who you are.', 'jetpack' ); ?></small>
355 </label>
356 </p>
357
358 <p>
359 <label for="<?php echo esc_attr( $this->get_field_id( 'show_account_links' ) ); ?>">
360 <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 ); ?> />
361 <?php esc_html_e( 'Show Account Links', 'jetpack' ); ?>
362 <br />
363 <small><?php esc_html_e( 'Links to services that you use across the web.', 'jetpack' ); ?></small>
364 </label>
365 </p>
366
367 <p><a href="<?php echo esc_url( $profile_url ); ?>" target="_blank" title="<?php esc_attr_e( 'Opens in new window', 'jetpack' ); ?>"><?php esc_html_e( 'Edit Your Profile', 'jetpack' ); ?></a> | <a href="https://gravatar.com" target="_blank" title="<?php esc_attr_e( 'Opens in new window', 'jetpack' ); ?>"><?php esc_html_e( "What's a Gravatar?", 'jetpack' ); ?></a></p>
368
369 <?php
370 }
371
372 /**
373 * Inline admin script.
374 */
375 public function admin_script() {
376 ?>
377 <script>
378 jQuery( function( $ ) {
379 $( '.wrap' ).on( 'change', '.gravatar-profile-user-select', function() {
380 var $input = $(this).closest('.widget-inside').find('.gprofile-email-container');
381 if ( '-1' === this.value.toLowerCase() ) {
382 $input.show();
383 } else {
384 $input.hide();
385 }
386 });
387 } );
388 </script>
389 <?php
390 }
391
392 /**
393 * Update widget.
394 *
395 * @see WP_Widget::update()
396 *
397 * @param array $new_instance New widget instance data.
398 * @param array $old_instance Old widget instance data.
399 */
400 public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
401 $instance = array();
402
403 $instance['title'] = isset( $new_instance['title'] ) ? wp_kses( $new_instance['title'], array() ) : '';
404 $instance['email'] = isset( $new_instance['email'] ) ? wp_kses( $new_instance['email'], array() ) : '';
405 $instance['email_user'] = isset( $new_instance['email_user'] ) ? (int) $new_instance['email_user'] : -1;
406 $instance['show_personal_links'] = isset( $new_instance['show_personal_links'] ) ? (bool) $new_instance['show_personal_links'] : false;
407 $instance['show_account_links'] = isset( $new_instance['show_account_links'] ) ? (bool) $new_instance['show_account_links'] : false;
408
409 if ( $instance['email_user'] > 0 ) {
410 $user = get_userdata( $instance['email_user'] );
411 $instance['email'] = $user->user_email;
412 }
413
414 $hashed_email = md5( strtolower( trim( $instance['email'] ) ) );
415 $cache_key = 'grofile-' . $hashed_email;
416 delete_transient( $cache_key );
417
418 return $instance;
419 }
420
421 /**
422 * Get the Gravatar profile for a given email address.
423 *
424 * @param string $email Email address.
425 */
426 private function get_profile( $email ) {
427 $hashed_email = md5( strtolower( trim( $email ) ) );
428 $cache_key = 'grofile-' . $hashed_email;
429 $profile = get_transient( $cache_key );
430
431 if ( ! $profile ) {
432 $profile_url = sprintf(
433 'https://secure.gravatar.com/%s.json',
434 $hashed_email
435 );
436
437 $expire = 300;
438 $response = wp_remote_get(
439 esc_url_raw( $profile_url ),
440 array( 'User-Agent' => 'WordPress.com Gravatar Profile Widget' )
441 );
442 $response_code = wp_remote_retrieve_response_code( $response );
443 if ( 200 === $response_code ) {
444 $profile = wp_remote_retrieve_body( $response );
445 $profile = json_decode( $profile, true );
446
447 if ( is_array( $profile ) && ! empty( $profile['entry'] ) && is_array( $profile['entry'] ) ) {
448 $expire = 900; // Cache for 15 minutes.
449 $profile = $profile['entry'][0];
450 } else {
451 // Something strange happened. Cache for 5 minutes.
452 $profile = array();
453 }
454 } else {
455 $expire = 900; // Cache for 15 minutes.
456 $profile = array();
457 }
458
459 set_transient( $cache_key, $profile, $expire );
460 }
461 return $profile;
462 }
463
464 /**
465 * Return properly capitalized service name.
466 *
467 * @param string $shortname The service.
468 *
469 * @return string
470 */
471 private function get_sanitized_service_name( $shortname ) {
472 // Some services have stylized or mixed cap names *cough* WP *cough*.
473 switch ( $shortname ) {
474 case 'friendfeed':
475 return 'FriendFeed';
476 case 'linkedin':
477 return 'LinkedIn';
478 case 'yahoo':
479 return 'Yahoo!';
480 case 'youtube':
481 return 'YouTube';
482 // phpcs:ignore WordPress.WP.CapitalPDangit
483 case 'wordpress':
484 return 'WordPress';
485 case 'tripit':
486 return 'TripIt';
487 case 'myspace':
488 return 'MySpace';
489 case 'foursquare':
490 return 'foursquare';
491 case 'google':
492 return 'Google+';
493 default:
494 // Others don't.
495 $shortname = ucwords( $shortname );
496 }
497 return $shortname;
498 }
499 }
500