PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.0.2
GiveWP – Donation Plugin and Fundraising Platform v2.0.2
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / class-give-gravatars.php
give / includes Last commit date
admin 8 years ago api 8 years ago deprecated 8 years ago donors 8 years ago emails 8 years ago forms 8 years ago gateways 8 years ago libraries 8 years ago payments 8 years ago actions.php 8 years ago ajax-functions.php 8 years ago class-give-async-process.php 8 years ago class-give-background-updater.php 8 years ago class-give-cache.php 8 years ago class-give-cli-commands.php 8 years ago class-give-cron.php 8 years ago class-give-db-donor-meta.php 8 years ago class-give-db-donors.php 8 years ago class-give-db-form-meta.php 8 years ago class-give-db-logs-meta.php 8 years ago class-give-db-logs.php 8 years ago class-give-db-meta.php 8 years ago class-give-db-payment-meta.php 8 years ago class-give-db.php 8 years ago class-give-donate-form.php 8 years ago class-give-donor.php 8 years ago class-give-email-access.php 8 years ago class-give-gravatars.php 8 years ago class-give-html-elements.php 8 years ago class-give-license-handler.php 8 years ago class-give-logging.php 8 years ago class-give-roles.php 8 years ago class-give-session.php 8 years ago class-give-stats.php 8 years ago class-give-template-loader.php 9 years ago class-give-tooltips.php 8 years ago class-give-translation.php 8 years ago class-notices.php 8 years ago country-functions.php 8 years ago currency-functions.php 8 years ago error-tracking.php 8 years ago filters.php 8 years ago formatting.php 8 years ago import-functions.php 8 years ago install.php 8 years ago login-register.php 8 years ago misc-functions.php 8 years ago plugin-compatibility.php 8 years ago post-types.php 8 years ago price-functions.php 8 years ago process-donation.php 8 years ago scripts.php 8 years ago shortcodes.php 8 years ago template-functions.php 8 years ago user-functions.php 8 years ago
class-give-gravatars.php
543 lines
1 <?php
2 /**
3 * Donors Gravatars
4 *
5 * @package Give
6 * @subpackage Classes/Give_Donors_Gravatars
7 * @copyright Copyright (c) 2016, WordImpress
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Give_Donors_Gravatars Class
19 *
20 * This class handles donors gravatars.
21 *
22 * @since 1.0
23 */
24 class Give_Donors_Gravatars {
25
26 /**
27 * Class Constructor
28 *
29 * Set up the Give Donors Gravatars Class.
30 *
31 * @since 1.0
32 * @access public
33 */
34 public function __construct() {
35 $this->setup_actions();
36 }
37
38 /**
39 * Setup the default hooks and actions
40 *
41 * @since 1.0
42 * @access private
43 *
44 * @return void
45 */
46 private function setup_actions() {
47 // add_action( 'widgets_init', array( $this, 'register_widget' ) );
48 // add_shortcode( 'give_donors_gravatars', array( $this, 'shortcode' ) );
49 // add_filter( 'give_settings_display', array( $this, 'settings' ) );
50 // do_action( 'give_donors_gravatars_setup_actions' );
51 }
52
53 /**
54 * Utility function to check if a gravatar exists for a given email or id
55 *
56 * @see: https://gist.github.com/justinph/5197810
57 *
58 * @since 1.0
59 * @access public
60 *
61 * @param int|string|object $id_or_email A user ID, email address, or comment object
62 *
63 * @return bool If the gravatar exists or not
64 */
65 public function validate_gravatar( $id_or_email ) {
66 //id or email code borrowed from wp-includes/pluggable.php
67 $email = '';
68 if ( is_numeric( $id_or_email ) ) {
69 $id = (int) $id_or_email;
70 $user = get_userdata( $id );
71 if ( $user ) {
72 $email = $user->user_email;
73 }
74 } elseif ( is_object( $id_or_email ) ) {
75 // No avatar for pingbacks or trackbacks
76 $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
77 if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) ) {
78 return false;
79 }
80
81 if ( ! empty( $id_or_email->user_id ) ) {
82 $id = (int) $id_or_email->user_id;
83 $user = get_userdata( $id );
84 if ( $user ) {
85 $email = $user->user_email;
86 }
87 } elseif ( ! empty( $id_or_email->comment_author_email ) ) {
88 $email = $id_or_email->comment_author_email;
89 }
90 } else {
91 $email = $id_or_email;
92 }
93
94 $hashkey = md5( strtolower( trim( $email ) ) );
95 $uri = 'http://www.gravatar.com/avatar/' . $hashkey . '?d=404';
96
97 $data = Give_Cache::get_group( $hashkey );
98
99 if ( is_null( $data ) ) {
100 $response = wp_remote_head( $uri );
101 if ( is_wp_error( $response ) ) {
102 $data = 'not200';
103 } else {
104 $data = $response['response']['code'];
105 }
106 Give_Cache::set_group( $hashkey, $data, $group = '', $expire = 60 * 5 );
107
108 }
109 if ( $data == '200' ) {
110 return true;
111 } else {
112 return false;
113 }
114 }
115
116 /**
117 * Get an array of all the log IDs using the Give Logging Class
118 *
119 * @since 1.0
120 * @access public
121 *
122 * @param int $form_id Donation form id
123 *
124 * @return array IDs if logs, false otherwise
125 */
126 public function get_log_ids( $form_id = '' ) {
127 // get log for this form
128 $logs = Give()->logs->get_logs( $form_id );
129
130 if ( $logs ) {
131 $log_ids = array();
132
133 // make an array with all the donor IDs
134 foreach ( $logs as $log ) {
135 $log_ids[] = $log->ID;
136 }
137
138 return $log_ids;
139 }
140
141 return null;
142
143 }
144
145 /**
146 * Get payment ID
147 *
148 * @since 1.0
149 * @access public
150 *
151 * @param int $form_id Donation form id
152 *
153 * @return mixed
154 */
155 public function get_payment_ids( $form_id = '' ) {
156
157 $give_options = give_get_settings();
158
159 $log_ids = $this->get_log_ids( $form_id );
160
161 if ( $log_ids ) {
162
163 $payment_ids = array();
164
165 foreach ( $log_ids as $id ) {
166 // get the payment ID for each corresponding log ID
167 $payment_ids[] = give_get_meta( $id, '_give_log_payment_id', true );
168 }
169
170 // remove donors who have donated more than once so we can have unique avatars
171 $unique_emails = array();
172
173 foreach ( $payment_ids as $key => $id ) {
174
175 $email = give_get_meta( $id, '_give_payment_donor_email', true );
176
177 if ( isset ( $give_options['give_donors_gravatars_has_gravatar_account'] ) ) {
178 if ( ! $this->validate_gravatar( $email ) ) {
179 continue;
180 }
181 }
182
183 $unique_emails[ $id ] = give_get_meta( $id, '_give_payment_donor_email', true );
184
185 }
186
187 $unique_ids = array();
188
189 // strip duplicate emails
190 $unique_emails = array_unique( $unique_emails );
191
192 // convert the unique IDs back into simple array
193 foreach ( $unique_emails as $id => $email ) {
194 $unique_ids[] = $id;
195 }
196
197 // randomize the payment IDs if enabled
198 if ( isset( $give_options['give_donors_gravatars_random_gravatars'] ) ) {
199 shuffle( $unique_ids );
200 }
201
202 // return our unique IDs
203 return $unique_ids;
204
205 }
206
207 }
208
209 /**
210 * Gravatars
211 *
212 * @since 1.0
213 * @access public
214 *
215 * @param int $form_id Donation form id.
216 * @param string $title Donors gravatars title.
217 *
218 * @return string
219 */
220 public function gravatars( $form_id = false, $title = '' ) {
221
222 // unique $payment_ids
223 $payment_ids = $this->get_payment_ids( $form_id );
224
225 $give_options = give_get_settings();
226
227 // return if no ID
228 if ( ! $form_id ) {
229 return;
230 }
231
232 // minimum amount of donations before showing gravatars
233 // if the number of items in array is not greater or equal to the number specified, then exit
234 if ( isset( $give_options['give_donors_gravatars_min_purchases_required'] ) && '' != $give_options['give_donors_gravatars_min_purchases_required'] ) {
235 if ( ! ( count( $payment_ids ) >= $give_options['give_donors_gravatars_min_purchases_required'] ) ) {
236 return;
237 }
238 }
239
240 ob_start();
241
242 $output = '';
243 echo '<div id="give-purchase-gravatars">';
244
245
246 if ( isset ( $title ) ) {
247
248 if ( $title ) {
249 echo apply_filters( 'give_donors_gravatars_title', '<h3 class="give-gravatars-title">' . esc_attr( $title ) . '</h3>' );
250 } elseif ( isset( $give_options['give_donors_gravatars_heading'] ) ) {
251 echo apply_filters( 'give_donors_gravatars_title', '<h3 class="give-gravatars-title">' . esc_attr( $give_options['give_donors_gravatars_heading'] ) . '</h2>' );
252 }
253
254 }
255 echo '<ul class="give-purchase-gravatars-list">';
256 $i = 0;
257
258 if ( $payment_ids ) {
259 foreach ( $payment_ids as $id ) {
260
261 // Give saves a blank option even when the control is turned off, hence the extra check
262 if ( isset( $give_options['give_donors_gravatars_maximum_number'] ) && '' != $give_options['give_donors_gravatars_maximum_number'] && $i == $give_options['give_donors_gravatars_maximum_number'] ) {
263 continue;
264 }
265
266 // get the payment meta
267 $payment_meta = give_get_meta( $id, '_give_payment_meta', true );
268
269 $user_info = $payment_meta['user_info'];
270
271 // get donor's first name
272 $name = $user_info['first_name'];
273
274 // get donor's email
275 $email = give_get_meta( $id, '_give_payment_donor_email', true );
276
277 // set gravatar size and provide filter
278 $size = isset( $give_options['give_donors_gravatars_gravatar_size'] ) ? apply_filters( 'give_donors_gravatars_gravatar_size', $give_options['give_donors_gravatars_gravatar_size'] ) : '';
279
280 // default image
281 $default_image = apply_filters( 'give_donors_gravatars_gravatar_default_image', false );
282
283 // assemble output
284 $output .= '<li>';
285
286 $output .= get_avatar( $email, $size, $default_image, $name );
287 $output .= '</li>';
288
289 $i ++;
290
291 } // end foreach
292 }
293
294 echo $output;
295 echo '</ul>';
296 echo '</div>';
297
298 return apply_filters( 'give_donors_gravatars', ob_get_clean() );
299 }
300
301 /**
302 * Register widget
303 *
304 * @since 1.0
305 * @access public
306 *
307 * @return void
308 */
309 public function register_widget() {
310 register_widget( 'Give_Donors_Gravatars_Widget' );
311 }
312
313 /**
314 * Shortcode
315 *
316 * @since 1.0
317 * @access public
318 *
319 * @param array $atts Shortcode attribures.
320 * @param string $content Shortcode content.
321 *
322 * @return string
323 */
324 public function shortcode( $atts, $content = null ) {
325
326 $atts = shortcode_atts( array(
327 'id' => '',
328 'title' => ''
329 ), $atts, 'give_donors_gravatars' );
330
331 // if no ID is passed on single give_forms pages, get the correct ID
332 if ( is_singular( 'give_forms' ) ) {
333 $id = get_the_ID();
334 }
335
336 $content = $this->gravatars( $atts['id'], $atts['title'] );
337
338 return $content;
339
340 }
341
342 /**
343 * Settings
344 *
345 * @since 1.0
346 * @access public
347 *
348 * @param array $settings Gravatar settings.
349 *
350 * @return array Gravatar settings.
351 */
352 public function settings( $settings ) {
353
354 $give_gravatar_settings = array(
355 array(
356 'name' => esc_html__( 'Donator Gravatars', 'give' ),
357 'desc' => '<hr>',
358 'id' => 'give_title',
359 'type' => 'give_title'
360 ),
361 array(
362 'name' => esc_html__( 'Heading', 'give' ),
363 'desc' => esc_html__( 'The heading to display above the Gravatars.', 'give' ),
364 'type' => 'text',
365 'id' => 'give_donors_gravatars_heading'
366 ),
367 array(
368 'name' => esc_html__( 'Gravatar Size', 'give' ),
369 'desc' => esc_html__( 'The size of each Gravatar in pixels (512px maximum).', 'give' ),
370 'type' => 'text_small',
371 'id' => 'give_donors_gravatars_gravatar_size',
372 'default' => '64'
373 ),
374 array(
375 'name' => esc_html__( 'Minimum Unique Donations Required', 'give' ),
376 'desc' => esc_html__( 'The minimum number of unique donations a form must have before the Gravatars are shown. Leave blank for no minimum.', 'give' ),
377 'type' => 'text_small',
378 'id' => 'give_donors_gravatars_min_purchases_required',
379 ),
380 array(
381 'name' => esc_html__( 'Maximum Gravatars To Show', 'give' ),
382 'desc' => esc_html__( 'The maximum number of gravatars to show. Leave blank for no limit.', 'give' ),
383 'type' => 'text',
384 'id' => 'give_donors_gravatars_maximum_number',
385 'default' => '20',
386 ),
387 array(
388 'name' => esc_html__( 'Gravatar Visibility', 'give' ),
389 'desc' => esc_html__( 'Show only donors with a Gravatar account.', 'give' ),
390 'id' => 'give_donors_gravatars_has_gravatar_account',
391 'type' => 'checkbox',
392 ),
393 array(
394 'name' => esc_html__( 'Randomize Gravatars', 'give' ),
395 'desc' => esc_html__( 'Randomize the Gravatars.', 'give' ),
396 'id' => 'give_donors_gravatars_random_gravatars',
397 'type' => 'checkbox',
398 ),
399 );
400
401 return array_merge( $settings, $give_gravatar_settings );
402 }
403
404 }
405
406
407 /**
408 * Give_Donors_Gravatars_Widget Class
409 *
410 * This class handles donors gravatars
411 *
412 * @since 1.0
413 */
414 class Give_Donors_Gravatars_Widget extends WP_Widget {
415
416 /**
417 * Widget constructor
418 *
419 * @since 1.0
420 * @access public
421 */
422 public function __construct() {
423
424 // widget settings
425 $widget_ops = array(
426 'classname' => 'give-donors-gravatars',
427 'description' => esc_html__( 'Displays gravatars of people who have donated using your your form. Will only show on the single form page.', 'give' ),
428 );
429
430 // widget control settings
431 $control_ops = array(
432 'width' => 250,
433 'height' => 350,
434 'id_base' => 'give_gravatars_widget'
435 );
436
437 // create the widget
438 parent::__construct(
439 'give_donors_gravatars_widget',
440 esc_html__( 'Give Donors Gravatars', 'give' ),
441 $widget_ops,
442 $control_ops
443 );
444
445 }
446
447 /**
448 * Donors gravatars widget content
449 *
450 * Outputs the content of the widget
451 *
452 * @since 1.0
453 * @access public
454 *
455 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
456 * @param array $instance Settings for the current Links widget instance.
457 *
458 * @return void
459 */
460 public function widget( $args, $instance ) {
461
462 //@TODO: Don't extract it!!!
463 extract( $args );
464
465 if ( ! is_singular( 'give_forms' ) ) {
466 return;
467 }
468
469 // Variables from widget settings
470 $title = apply_filters( 'widget_title', $instance['title'] );
471
472 // Used by themes. Opens the widget
473 echo $before_widget;
474
475 // Display the widget title
476 if ( $title ) {
477 echo $before_title . $title . $after_title;
478 }
479
480 $gravatars = new Give_Donors_Gravatars();
481
482 echo $gravatars->gravatars( get_the_ID(), null ); // remove title
483
484 // Used by themes. Closes the widget
485 echo $after_widget;
486
487 }
488
489 /**
490 * Update donors gravatars
491 *
492 * Processes widget options to be saved.
493 *
494 * @since 1.0
495 * @access public
496 *
497 * @param array $new_instance New settings for this instance as input by the user via WP_Widget::form().
498 * @param array $old_instance Old settings for this instance.
499 *
500 * @return array Updated settings to save.
501 */
502 public function update( $new_instance, $old_instance ) {
503
504 $instance = $old_instance;
505
506 $instance['title'] = strip_tags( $new_instance['title'] );
507
508 return $instance;
509
510 }
511
512 /**
513 * Output donors gravatars
514 *
515 * Displays the actual form on the widget page.
516 *
517 * @since 1.0
518 * @access public
519 *
520 * @param array $instance Current settings.
521 *
522 * @return void
523 */
524 public function form( $instance ) {
525
526 // Set up some default widget settings.
527 $defaults = array(
528 'title' => '',
529 );
530
531 $instance = wp_parse_args( (array) $instance, $defaults ); ?>
532
533 <!-- Title -->
534 <p>
535 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'give' ) ?></label>
536 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $instance['title']; ?>" />
537 </p>
538
539 <?php
540 }
541
542 }
543