PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.1.2
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.1.2
4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / inc / Admin / CFF_Tracking.php
custom-facebook-feed / inc / Admin Last commit date
Traits 4 years ago CFF_About.php 4 years ago CFF_About_Us.php 4 years ago CFF_Admin.php 4 years ago CFF_Global_Settings.php 4 years ago CFF_Install_Skin.php 4 years ago CFF_New_User.php 4 years ago CFF_Notifications.php 4 years ago CFF_Support.php 4 years ago CFF_Tracking.php 4 years ago CFF_Upgrader.php 4 years ago CFF_oEmbeds.php 4 years ago
CFF_Tracking.php
733 lines
1 <?php
2 /**
3 * Tracking functions for reporting plugin usage to the Smash Balloon site for users that have opted in
4 *
5 * @copyright Copyright (c) 2018, Chris Christoff
6 * @since 3.13
7 */
8 namespace CustomFacebookFeed\Admin;
9 use CustomFacebookFeed\CFF_Utils;
10 // Exit if accessed directly
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Usage tracking
17 *
18 * @access public
19 * @since 3.13
20 * @return void
21 */
22 class CFF_Tracking {
23
24 public function __construct() {
25 add_action( 'init', array( $this, 'schedule_send' ) );
26 add_filter( 'cron_schedules', array( $this, 'add_schedules' ) );
27 add_action( 'cff_usage_tracking_cron', array( $this, 'send_checkin' ) );
28 add_action( 'cff_admin_notices', array( $this, 'usage_opt_in' ) );
29 add_action( 'wp_ajax_cff_usage_opt_in_or_out', array( $this, 'usage_opt_in_or_out' ) );
30 }
31
32 private function normalize_and_format( $key, $value ) {
33 $defaults = array(
34 //Post types
35 'cff_show_links_type' => true,
36 'cff_show_event_type' => true,
37 'cff_show_video_type' => true,
38 'cff_show_photos_type' => true,
39 'cff_show_status_type' => true,
40 'cff_show_albums_type' => true,
41 //Events only
42 'cff_events_source' => 'eventspage',
43 'cff_event_offset' => '6',
44 'cff_event_image_size' => 'full',
45 //Albums only
46 'cff_albums_source' => 'photospage',
47 'cff_show_album_title' => true,
48 'cff_show_album_number' => true,
49 'cff_album_cols' => '4',
50 //Photos only
51 'cff_photos_source' => 'photospage',
52 'cff_photos_cols' => '4',
53 //Videos only
54 'cff_videos_source' => 'videospage',
55 'cff_show_video_name' => true,
56 'cff_show_video_desc' => true,
57 'cff_video_cols' => '4',
58
59 //Lightbox
60 'cff_disable_lightbox' => false,
61 'cff_lightbox_bg_color' => '',
62 'cff_lightbox_text_color' => '',
63 'cff_lightbox_link_color' => '',
64
65 //Filter
66 'cff_filter_string' => '',
67 'cff_exclude_string' => '',
68
69 //Reviews
70 'cff_reviews_rated_5' => true,
71 'cff_reviews_rated_4' => true,
72 'cff_reviews_rated_3' => true,
73 'cff_reviews_rated_2' => true,
74 'cff_reviews_rated_1' => true,
75 'cff_star_size' => '12',
76 'cff_reviews_link_text' => 'View all Reviews',
77 'cff_reviews_no_text' => false,
78 'cff_reviews_method' => 'auto',
79 'cff_reviews_hide_negative' => true,
80
81 //Layout
82 'cff_preset_layout' => 'thumb',
83 'cff_media_position' => 'below',
84 //Include
85 'cff_show_text' => true,
86 'cff_show_desc' => true,
87 'cff_show_shared_links' => true,
88 'cff_show_date' => true,
89 'cff_show_media' => true,
90 'cff_show_event_title' => true,
91 'cff_show_event_details' => true,
92 'cff_show_meta' => true,
93 'cff_show_link' => true,
94 'cff_show_like_box' => true,
95 //Masonry
96 'cff_masonry_enabled' => false,
97 'cff_masonry_desktop_col' => 1,
98 'cff_masonry_mobile_col' => 1,
99
100 //Post Styple
101 'cff_post_style' => '',
102 'cff_post_bg_color' => '',
103 'cff_post_rounded' => '0',
104 'cff_box_shadow' => false,
105 //Typography
106 'cff_title_format' => 'p',
107 'cff_title_size' => 'inherit',
108 'cff_title_weight' => 'inherit',
109 'cff_title_color' => '',
110 'cff_posttext_link_color' => '',
111 'cff_body_size' => '12',
112 'cff_body_weight' => 'inherit',
113 'cff_body_color' => '',
114 'cff_link_title_format' => 'p',
115 'cff_full_link_images' => true,
116 'cff_link_image_size' => 'largesquare',
117 'cff_image_size' => 'large',
118 'cff_link_title_size' => 'inherit',
119 'cff_link_url_size' => '12',
120 'cff_link_desc_size' => 'inherit',
121 'cff_link_desc_color' => '',
122 'cff_link_title_color' => '',
123 'cff_link_url_color' => '',
124 'cff_link_bg_color' => '',
125 'cff_link_border_color' => '',
126 'cff_disable_link_box' => false,
127
128 //Event title
129 'cff_event_title_format' => 'p',
130 'cff_event_title_size' => 'inherit',
131 'cff_event_title_weight' => 'bold',
132 'cff_event_title_color' => '',
133 //Event date
134 'cff_event_date_size' => 'inherit',
135 'cff_event_date_weight' => 'inherit',
136 'cff_event_date_color' => '',
137 'cff_event_date_position' => 'below',
138 'cff_event_date_formatting' => '14',
139 'cff_event_date_custom' => '',
140 //Event details
141 'cff_event_details_size' => 'inherit',
142 'cff_event_details_weight' => 'inherit',
143 'cff_event_details_color' => '',
144 'cff_event_link_color' => '',
145
146 //Date
147 'cff_date_position' => 'author',
148 'cff_date_size' => 'inherit',
149 'cff_date_weight' => 'inherit',
150 'cff_date_color' => '',
151 'cff_date_formatting' => '1',
152 'cff_date_custom' => '',
153 'cff_date_before' => '',
154 'cff_date_after' => '',
155 'cff_timezone' => 'America/Chicago',
156
157 //Link to Facebook
158 'cff_link_size' => 'inherit',
159 'cff_link_weight' => 'inherit',
160 'cff_link_color' => '',
161 'cff_view_link_text' => 'View Link',
162 'cff_link_to_timeline' => false,
163
164 //Load more button
165 // 'cff_load_more' => true,
166 'cff_load_more_bg' => '',
167 'cff_load_more_text_color' => '',
168 'cff_load_more_bg_hover' => '',
169 'cff_load_more_text' => 'Load more',
170 'cff_no_more_posts_text' => 'No more posts',
171
172 //Meta
173 'cff_icon_style' => 'light',
174 'cff_meta_text_color' => '',
175 'cff_meta_link_color' => '',
176 'cff_meta_bg_color' => '',
177 'cff_expand_comments' => false,
178 'cff_comments_num' => '4',
179 'cff_nocomments_text' => 'No comments yet',
180 'cff_hide_comments' => false,
181 'cff_hide_comment_avatars' => false,
182 'cff_lightbox_comments' => true,
183 //Misc
184 'cff_feed_width' => '100%',
185 'cff_feed_width_resp' => false,
186 'cff_feed_height' => '',
187 'cff_feed_padding' => '',
188 'cff_like_box_position' => 'bottom',
189 'cff_like_box_outside' => false,
190 'cff_likebox_width' => '',
191 'cff_likebox_height' => '',
192 'cff_like_box_faces' => false,
193 'cff_like_box_border' => false,
194 'cff_like_box_cover' => true,
195 'cff_like_box_small_header' => false,
196 'cff_like_box_hide_cta' => false,
197
198 //Misc Settings
199 'cff_enable_narrow' => true,
200 'cff_one_image' => false,
201
202 'cff_bg_color' => '',
203 'cff_likebox_bg_color' => '',
204 'cff_like_box_text_color' => 'blue',
205 'cff_video_height' => '',
206 'cff_show_author' => true,
207 'cff_class' => '',
208 'cff_app_id' => '',
209 'cff_show_credit' => '',
210 'cff_format_issue' => false,
211 'cff_disable_svgs' => false,
212 'cff_restricted_page' => false,
213 'cff_hide_supporter_posts' => false,
214 'cff_font_source' => 'cdn',
215 'cff_disable_ajax_cache' => false,
216 'cff_minify' => false,
217 'disable_admin_notice' => false,
218 'cff_request_method' => 'auto',
219 'cff_cron' => 'unset',
220 'cff_timeline_pag' => 'date',
221 'cff_grid_pag' => 'auto',
222
223 //Feed Header
224 'cff_show_header' => '',
225 'cff_header_outside' => false,
226 'cff_header_text' => 'Facebook Posts',
227 'cff_header_bg_color' => '',
228 'cff_header_padding' => '',
229 'cff_header_text_size' => '',
230 'cff_header_text_weight' => '',
231 'cff_header_text_color' => '',
232 'cff_header_icon' => '',
233 'cff_header_icon_color' => '',
234 'cff_header_icon_size' => '28',
235
236 //Author
237 'cff_author_size' => 'inherit',
238 'cff_author_color' => '',
239
240 //New
241 'cff_custom_css' => '',
242 'cff_custom_js' => '',
243 'cff_title_link' => false,
244 'cff_post_tags' => true,
245 'cff_link_hashtags' => true,
246 'cff_event_title_link' => true,
247 'cff_video_action' => 'post',
248 'cff_video_player' => 'facebook',
249 'cff_sep_color' => '',
250 'cff_sep_size' => '1',
251
252 //Translate - general
253 'cff_see_more_text' => 'See More',
254 'cff_see_less_text' => 'See Less',
255 'cff_map_text' => 'Map',
256 'cff_no_events_text' => 'No upcoming events',
257 'cff_facebook_link_text' => 'View on Facebook',
258 'cff_facebook_share_text' => 'Share',
259 'cff_show_facebook_link' => true,
260 'cff_show_facebook_share' => true,
261 'cff_buy_tickets_text' => 'Buy Tickets',
262 'cff_interested_text' => 'interested',
263 'cff_going_text' => 'going',
264
265 //Translate - social
266 'cff_translate_view_previous_comments_text' => 'View more comments',
267 'cff_translate_comment_on_facebook_text' => 'Comment on Facebook',
268 'cff_translate_photos_text' => 'photos',
269 'cff_translate_likes_this_text' => 'likes this',
270 'cff_translate_like_this_text' => 'like this',
271 'cff_translate_reacted_text' => 'reacted to this',
272 'cff_translate_and_text' => 'and',
273 'cff_translate_other_text' => 'other',
274 'cff_translate_others_text' => 'others',
275 'cff_translate_reply_text' => 'Reply',
276 'cff_translate_replies_text' => 'Replies',
277
278 'cff_translate_learn_more_text' => 'Learn More',
279 'cff_translate_shop_now_text' => 'Shop Now',
280 'cff_translate_message_page_text' => 'Message Page',
281 'cff_translate_get_directions_text' => 'Get Directions',
282
283 //Translate - date
284 'cff_translate_second' => 'second',
285 'cff_translate_seconds' => 'seconds',
286 'cff_translate_minute' => 'minute',
287 'cff_translate_minutes' => 'minutes',
288 'cff_translate_hour' => 'hour',
289 'cff_translate_hours' => 'hours',
290 'cff_translate_day' => 'day',
291 'cff_translate_days' => 'days',
292 'cff_translate_week' => 'week',
293 'cff_translate_weeks' => 'weeks',
294 'cff_translate_month' => 'month',
295 'cff_translate_months' => 'months',
296 'cff_translate_year' => 'year',
297 'cff_translate_years' => 'years',
298 'cff_translate_ago' => 'ago',
299
300 // email
301 'enable_email_report' => 'on',
302 'email_notification' => 'monday',
303 'email_notification_addresses' => get_option( 'admin_email' )
304 );
305
306 $normal_bools = array(
307 'cff_show_links_type',
308 'cff_show_event_type',
309 'cff_show_video_type',
310 'cff_show_photos_type',
311 'cff_show_status_type',
312 'cff_show_albums_type',
313 'cff_show_album_title',
314 'cff_show_album_number',
315 'cff_show_video_name',
316 'cff_show_video_desc',
317 'cff_disable_lightbox',
318 'cff_reviews_rated_5',
319 'cff_reviews_rated_4',
320 'cff_reviews_rated_3',
321 'cff_reviews_rated_2',
322 'cff_reviews_rated_1',
323 'cff_reviews_no_text',
324 'cff_reviews_hide_negative',
325 'cff_show_text',
326 'cff_show_desc',
327 'cff_show_shared_links',
328 'cff_show_date',
329 'cff_show_media',
330 'cff_show_event_title',
331 'cff_show_event_details',
332 'cff_show_meta',
333 'cff_show_link',
334 'cff_show_like_box',
335 'cff_masonry_enabled',
336 'cff_box_shadow',
337 'cff_full_link_images',
338 'cff_link_to_timeline',
339 'cff_expand_comments',
340 'cff_hide_comments',
341 'cff_hide_comment_avatars',
342 'cff_lightbox_comments',
343 'cff_disable_link_box',
344 //Misc
345 'cff_feed_width',
346 'cff_feed_width_resp',
347 'cff_like_box_outside',
348 'cff_like_box_faces',
349 'cff_like_box_border',
350 'cff_like_box_cover',
351 'cff_like_box_small_header',
352 'cff_like_box_hide_cta',
353 'cff_disable_styles',
354 'cff_enable_narrow',
355 'cff_one_image',
356 'cff_show_author',
357 'cff_format_issue',
358 'cff_disable_svgs',
359 'cff_restricted_page',
360 'cff_hide_supporter_posts',
361 'cff_disable_ajax_cache',
362 'cff_minify',
363 'disable_admin_notice',
364 'cff_header_outside',
365 'cff_title_link',
366 'cff_post_tags',
367 'cff_link_hashtags',
368 'cff_event_title_link',
369 'cff_show_facebook_link',
370 'cff_show_facebook_share',
371 'enable_email_report'
372 );
373 $custom_text_settings = array(
374 'cff_reviews_link_text',
375 'cff_load_more_text',
376 'cff_no_more_posts_text',
377 'cff_nocomments_text',
378 'cff_header_text',
379 'cff_see_more_text',
380 'cff_see_less_text',
381 'cff_map_text',
382 'cff_no_events_text',
383 'cff_facebook_link_text',
384 'cff_facebook_share_text',
385 'cff_buy_tickets_text',
386 'cff_interested_text',
387 'cff_going_text',
388 'cff_translate_view_previous_comments_text',
389 'cff_translate_comment_on_facebook_text',
390 'cff_translate_photos_text',
391 'cff_translate_likes_this_text',
392 'cff_translate_like_this_text',
393 'cff_translate_reacted_text',
394 'cff_translate_and_text',
395 'cff_translate_other_text',
396 'cff_translate_others_text',
397 'cff_translate_reply_text',
398 'cff_translate_replies_text',
399 'cff_custom_css',
400 'cff_custom_js',
401 'cff_translate_learn_more_text',
402 'cff_translate_shop_now_text',
403 'cff_translate_message_page_text',
404 'cff_translate_get_directions_text',
405 'cff_class',
406 'cff_app_id',
407 'cff_show_credit',
408
409 //Translate - date
410 'cff_translate_second',
411 'cff_translate_seconds',
412 'cff_translate_minute',
413 'cff_translate_minutes',
414 'cff_translate_hour',
415 'cff_translate_hours',
416 'cff_translate_day',
417 'cff_translate_days',
418 'cff_translate_week',
419 'cff_translate_weeks',
420 'cff_translate_month',
421 'cff_translate_months',
422 'cff_translate_year',
423 'cff_translate_years',
424 'cff_translate_ago',
425 'email_notification_addresses'
426 );
427 $comma_separate_counts_settings = array(
428 'cff_filter_string',
429 'cff_exclude_string',
430 );
431
432 if ( is_array( $value ) ) {
433 if ( empty( $value ) ) {
434 return 0;
435 }
436 return count( $value );
437 // 0 for anything that might be false, 1 for everything else
438 } elseif ( in_array( $key, $normal_bools, true ) ) {
439 if ( in_array( $value, array( false, 0, '0', 'false', '' ), true ) ) {
440 return 0;
441 }
442 return 1;
443
444 // if a custom text setting, we just want to know if it's different than the default
445 } elseif ( in_array( $key, $custom_text_settings, true ) ) {
446 if ( $defaults[ $key ] === $value ) {
447 return 0;
448 }
449 return 1;
450 } elseif ( in_array( $key, $comma_separate_counts_settings, true ) ) {
451 if ( str_replace( ' ', '', $value ) === '' ) {
452 return 0;
453 }
454 $split_at_comma = explode( ',', $value );
455 return count( $split_at_comma );
456 }
457
458 return $value;
459
460 }
461
462 private function get_data() {
463 $data = array();
464
465 // Retrieve current theme info
466 $theme_data = wp_get_theme();
467
468 $count_b = 1;
469 if ( is_multisite() ) {
470 if ( function_exists( 'get_blog_count' ) ) {
471 $count_b = get_blog_count();
472 } else {
473 $count_b = 'Not Set';
474 }
475 }
476
477 $php_version = rtrim( ltrim( sanitize_text_field( phpversion() ) ) );
478 $php_version = ! empty( $php_version ) ? substr( $php_version, 0, strpos( $php_version, '.', strpos( $php_version, '.' ) + 1 ) ) : phpversion();
479
480 global $wp_version;
481 $data['this_plugin'] = 'fb';
482 $data['php_version'] = $php_version;
483 $data['mi_version'] = CFFVER;
484 $data['wp_version'] = $wp_version;
485 $data['server'] = isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '';
486 $data['multisite'] = is_multisite();
487 $data['url'] = home_url();
488 $data['themename'] = $theme_data->Name;
489 $data['themeversion'] = $theme_data->Version;
490 $data['settings'] = array();
491 $data['pro'] = CFF_Utils::cff_is_pro_version() ? '1' : '';
492 $data['sites'] = $count_b;
493 $data['usagetracking'] = get_option( 'cff_usage_tracking_config', false );
494 $num_users = function_exists( 'count_users' ) ? count_users() : 'Not Set';
495 $data['usercount'] = is_array( $num_users ) ? $num_users['total_users'] : 1;
496 $data['timezoneoffset']= date('P');
497
498 $page_id = get_option( 'cff_page_id' );
499 $own_token = get_option( 'cff_show_access_token' );
500 $by_others = get_option( 'cff_show_others' );
501 $number_posts = get_option( 'cff_num_show' );
502 $posts_limit = get_option( 'cff_post_limit' );
503 $page_type = get_option( 'cff_page_type' );
504 $caching_type = get_option( 'cff_caching_type' );
505 $caching_time = get_option( 'cff_cache_time' );
506 $caching_unit = get_option( 'cff_cache_time_unit' );
507 $locale = get_option( 'cff_locale' );
508 $connected_accounts = get_option( 'cff_connected_accounts', '{}' );
509 $connected_accounts = json_decode( stripslashes( $connected_accounts ), true );
510 $settings_to_send = array(
511 'page_id' => $page_id,
512 'own_token' => $own_token,
513 'show_others' => $by_others,
514 'num_posts' => $number_posts,
515 'posts_limit' => $posts_limit,
516 'page_type' => $page_type,
517 'caching_type' => $caching_type,
518 'caching_time' => $caching_time,
519 'caching_unit' => $caching_unit,
520 'locale' => $locale,
521 'num_connected_accounts' => count( $connected_accounts ),
522 );
523 $raw_settings = get_option( 'cff_style_settings', array() );
524 foreach ( $raw_settings as $key => $value ) {
525 $value = $this->normalize_and_format( $key, $value );
526
527 if ( $value !== false ) {
528 $key = str_replace( array( 'sb_instagram_', 'cff_' ), '', $key );
529 $settings_to_send[ $key ] = $value;
530 }
531 }
532
533 $oembed_token = get_option( 'cff_oembed_token', false );
534
535 $settings_to_send['oembed_expiring_token'] = isset( $oembed_token['access_token'] ) ? (int)$oembed_token['access_token'] > 0 : false;
536
537 global $wpdb;
538 $feed_caches = array();
539
540 $results = $wpdb->get_results( "
541 SELECT option_name
542 FROM $wpdb->options
543 WHERE `option_name` LIKE ('%\_transient\_cff\_%')
544 AND `option_name` NOT LIKE ('%\_transient\_cff\_header%');", ARRAY_A );
545
546 if ( isset( $results[0] ) ) {
547 $feed_caches = $results;
548 }
549 $settings_to_send['num_found_feed_caches'] = count( $feed_caches );
550
551 $data['settings'] = $settings_to_send;
552
553 // Retrieve current plugin information
554 if( ! function_exists( 'get_plugins' ) ) {
555 include ABSPATH . '/wp-admin/includes/plugin.php';
556 }
557
558 $plugins = get_plugins();
559 $active_plugins = get_option( 'active_plugins', array() );
560 $plugins_to_send = array();
561
562 foreach ( $plugins as $plugin_path => $plugin ) {
563 // If the plugin isn't active, don't show it.
564 if ( ! in_array( $plugin_path, $active_plugins ) )
565 continue;
566
567 $plugins_to_send[] = $plugin['Name'];
568 }
569
570 $data['active_plugins'] = $plugins_to_send;
571 $data['locale'] = get_locale();
572
573 return $data;
574 }
575
576 public function send_checkin( $override = false, $ignore_last_checkin = false ) {
577 $home_url = trailingslashit( home_url() );
578 if ( strpos( $home_url, 'smashballoon.com' ) !== false ) {
579 return false;
580 }
581
582 if( ! $this->tracking_allowed() && ! $override ) {
583 return false;
584 }
585
586 // Send a maximum of once per week
587 $usage_tracking = get_option( 'cff_usage_tracking', array( 'last_send' => 0, 'enabled' => CFF_Utils::cff_is_pro_version() ) );
588 if ( is_numeric( $usage_tracking['last_send'] ) && $usage_tracking['last_send'] > strtotime( '-1 week' ) && ! $ignore_last_checkin ) {
589 return false;
590 }
591
592 $request = wp_remote_post( 'https://usage.smashballoon.com/v1/checkin/', array(
593 'method' => 'POST',
594 'timeout' => 5,
595 'redirection' => 5,
596 'httpversion' => '1.1',
597 'blocking' => false,
598 'body' => $this->get_data(),
599 'user-agent' => 'MI/' . CFFVER . '; ' . get_bloginfo( 'url' )
600 ) );
601
602 // If we have completed successfully, recheck in 1 week
603 $usage_tracking = array(
604 'enabled' => true,
605 'last_send' => time(),
606 );
607 update_option( 'cff_usage_tracking', $usage_tracking, false );
608 return true;
609 }
610
611 private function tracking_allowed() {
612 $usage_tracking = get_option( 'cff_usage_tracking', array( 'last_send' => 0, 'enabled' => CFF_Utils::cff_is_pro_version() ) );
613 $tracking_allowed = isset( $usage_tracking['enabled'] ) ? $usage_tracking['enabled'] : CFF_Utils::cff_is_pro_version();
614
615 return $tracking_allowed;
616 }
617
618 public function schedule_send() {
619 if ( ! wp_next_scheduled( 'cff_usage_tracking_cron' ) ) {
620 $tracking = array();
621 $tracking['day'] = rand( 0, 6 );
622 $tracking['hour'] = rand( 0, 23 );
623 $tracking['minute'] = rand( 0, 59 );
624 $tracking['second'] = rand( 0, 59 );
625 $tracking['offset'] = ( $tracking['day'] * DAY_IN_SECONDS ) +
626 ( $tracking['hour'] * HOUR_IN_SECONDS ) +
627 ( $tracking['minute'] * MINUTE_IN_SECONDS ) +
628 $tracking['second'];
629 $last_sunday = strtotime("next sunday") - (7 * DAY_IN_SECONDS);
630 if ( ($last_sunday + $tracking['offset']) > time() + 6 * HOUR_IN_SECONDS ) {
631 $tracking['initsend'] = $last_sunday + $tracking['offset'];
632 } else {
633 $tracking['initsend'] = strtotime("next sunday") + $tracking['offset'];
634 }
635
636 wp_schedule_event( $tracking['initsend'], 'weekly', 'cff_usage_tracking_cron' );
637 update_option( 'cff_usage_tracking_config', $tracking );
638 }
639 }
640
641 public function add_schedules( $schedules = array() ) {
642 // Adds once weekly to the existing schedules.
643 $schedules['weekly'] = array(
644 'interval' => 604800,
645 'display' => __( 'Once Weekly', 'custom-facebook-feed' )
646 );
647 return $schedules;
648 }
649
650 public function usage_opt_in() {
651 if ( isset( $_GET['trackingdismiss'] ) ) {
652 $usage_tracking = get_option( 'cff_usage_tracking', array( 'last_send' => 0, 'enabled' => false ) );
653
654 $usage_tracking['enabled'] = false;
655
656 update_option( 'cff_usage_tracking', $usage_tracking, false );
657
658 return;
659 }
660
661 $cap = current_user_can( 'manage_custom_facebook_feed_options' ) ? 'manage_custom_facebook_feed_options' : 'manage_options';
662
663 $cap = apply_filters( 'cff_settings_pages_capability', $cap );
664 if ( ! current_user_can( $cap ) ) {
665 return;
666 }
667 $usage_tracking = get_option( 'cff_usage_tracking', false );
668 if ( $usage_tracking || isset( $_GET['feed_id'] ) ) {
669 return;
670 }
671
672 if ( \CustomFacebookFeed\Builder\CFF_Db::feeds_count() < 1
673 && $_GET['page'] === 'cff-feed-builder' ) {
674 return;
675 }
676 wp_enqueue_style(
677 'cff-admin-notifications',
678 CFF_PLUGIN_URL . "admin/assets/css/admin-notifications.css",
679 array(),
680 CFFVER
681 );
682 $img_src = CFF_PLUGIN_URL . 'admin/assets/img/cff-icon.png';
683 ?>
684 <div id="cff-notifications" class="cff_discount_notice cff-usage-tracking-notice">
685 <a
686 class="dismiss cff-no-usage-opt-out"
687 title="<?php echo esc_attr__( 'Dismiss this message', 'custom-facebook-feed' ); ?>"
688 href="<?php echo admin_url('admin.php?page=cff-top&trackingdismiss=1'); ?>"
689 >
690 <svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
691 <path d="M9.66683 1.27325L8.72683 0.333252L5.00016 4.05992L1.2735 0.333252L0.333496 1.27325L4.06016 4.99992L0.333496 8.72659L1.2735 9.66659L5.00016 5.93992L8.72683 9.66659L9.66683 8.72659L5.94016 4.99992L9.66683 1.27325Z" fill="white"/>
692 </svg>
693 </a>
694 <div class="bell"><img src="<?php echo esc_url( $img_src ); ?>" alt="notice"></div>
695 <div class="messages">
696 <div class="message" style="display: block;">
697
698 <h3 class="title">
699 <?php echo esc_html__( 'Help us improve the Custom Facebook Feed plugin', 'custom-facebook-feed') ; ?>
700 </h3>
701
702 <p class="content">
703 <?php echo __( 'Understanding how you are using the plugin allows us to further improve it. Opt-in below to agree to send a weekly report of plugin usage data.', 'custom-facebook-feed' ); ?>
704 <a target="_blank" rel="noopener noreferrer" href="https://smashballoon.com/custom-facebook-feed/docs/usage-tracking/"><?php echo __( 'More information', 'custom-facebook-feed' ); ?></a>
705 </p>
706
707 <div class="buttons">
708 <a href="<?php echo admin_url('admin.php?page=cff-top&trackingdismiss=1') ?>" type="submit" class="cff-opt-in cff-btn cff-btn-blue"><?php echo __( 'Yes, I\'d like to help', 'custom-facebook-feed' ); ?></a>
709 <a href="<?php echo admin_url('admin.php?page=cff-top&trackingdismiss=1') ?>" type="submit" class="cff-no-usage-opt-out cff-btn cff-btn-grey"><?php echo __( 'No, thanks', 'custom-facebook-feed' ); ?></a>
710 </div>
711 </div>
712 </div>
713 </div>
714
715 <?php
716 }
717
718 public function usage_opt_in_or_out() {
719 if ( ! isset( $_POST['opted_in'] ) ) {
720 die ( 'You did not do this the right way!' );
721 }
722
723 $usage_tracking = get_option( 'cff_usage_tracking', array( 'last_send' => 0, 'enabled' => false ) );
724
725 $usage_tracking['enabled'] = isset( $_POST['opted_in'] ) ? $_POST['opted_in'] === 'true' : false;
726
727 update_option( 'cff_usage_tracking', $usage_tracking, false );
728
729 die();
730 }
731 }
732
733 #new CFF_Tracking();