PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 2.17.1
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v2.17.1
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 / admin / class-cff-tracking.php
custom-facebook-feed / admin Last commit date
PluginSilentUpgrader.php 5 years ago PluginSilentUpgraderSkin.php 6 years ago addon-functions.php 6 years ago class-cff-about.php 6 years ago class-cff-new-user.php 5 years ago class-cff-notifications.php 5 years ago class-cff-tracking.php 5 years ago class-install-skin.php 6 years ago
class-cff-tracking.php
647 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
9 // Exit if accessed directly
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 /**
15 * Usage tracking
16 *
17 * @access public
18 * @since 3.13
19 * @return void
20 */
21 class CFF_Tracking {
22
23 public function __construct() {
24 add_action( 'init', array( $this, 'schedule_send' ) );
25 add_filter( 'cron_schedules', array( $this, 'add_schedules' ) );
26 add_action( 'cff_usage_tracking_cron', array( $this, 'send_checkin' ) );
27 }
28
29 private function normalize_and_format( $key, $value ) {
30 $defaults = array(
31 //Post types
32 'cff_show_links_type' => true,
33 'cff_show_event_type' => true,
34 'cff_show_video_type' => true,
35 'cff_show_photos_type' => true,
36 'cff_show_status_type' => true,
37 'cff_show_albums_type' => true,
38 //Events only
39 'cff_events_source' => 'eventspage',
40 'cff_event_offset' => '6',
41 'cff_event_image_size' => 'full',
42 //Albums only
43 'cff_albums_source' => 'photospage',
44 'cff_show_album_title' => true,
45 'cff_show_album_number' => true,
46 'cff_album_cols' => '4',
47 //Photos only
48 'cff_photos_source' => 'photospage',
49 'cff_photos_cols' => '4',
50 //Videos only
51 'cff_videos_source' => 'videospage',
52 'cff_show_video_name' => true,
53 'cff_show_video_desc' => true,
54 'cff_video_cols' => '4',
55
56 //Lightbox
57 'cff_disable_lightbox' => false,
58 'cff_lightbox_bg_color' => '',
59 'cff_lightbox_text_color' => '',
60 'cff_lightbox_link_color' => '',
61
62 //Filter
63 'cff_filter_string' => '',
64 'cff_exclude_string' => '',
65
66 //Reviews
67 'cff_reviews_rated_5' => true,
68 'cff_reviews_rated_4' => true,
69 'cff_reviews_rated_3' => true,
70 'cff_reviews_rated_2' => true,
71 'cff_reviews_rated_1' => true,
72 'cff_star_size' => '12',
73 'cff_reviews_link_text' => 'View all Reviews',
74 'cff_reviews_no_text' => false,
75 'cff_reviews_method' => 'auto',
76 'cff_reviews_hide_negative' => true,
77
78 //Layout
79 'cff_preset_layout' => 'thumb',
80 'cff_media_position' => 'below',
81 //Include
82 'cff_show_text' => true,
83 'cff_show_desc' => true,
84 'cff_show_shared_links' => true,
85 'cff_show_date' => true,
86 'cff_show_media' => true,
87 'cff_show_event_title' => true,
88 'cff_show_event_details' => true,
89 'cff_show_meta' => true,
90 'cff_show_link' => true,
91 'cff_show_like_box' => true,
92 //Masonry
93 'cff_masonry_enabled' => false,
94 'cff_masonry_desktop_col' => 1,
95 'cff_masonry_mobile_col' => 1,
96
97 //Post Styple
98 'cff_post_style' => '',
99 'cff_post_bg_color' => '',
100 'cff_post_rounded' => '0',
101 'cff_box_shadow' => false,
102 //Typography
103 'cff_title_format' => 'p',
104 'cff_title_size' => 'inherit',
105 'cff_title_weight' => 'inherit',
106 'cff_title_color' => '',
107 'cff_posttext_link_color' => '',
108 'cff_body_size' => '12',
109 'cff_body_weight' => 'inherit',
110 'cff_body_color' => '',
111 'cff_link_title_format' => 'p',
112 'cff_full_link_images' => true,
113 'cff_link_image_size' => 'largesquare',
114 'cff_image_size' => 'large',
115 'cff_link_title_size' => 'inherit',
116 'cff_link_url_size' => '12',
117 'cff_link_desc_size' => 'inherit',
118 'cff_link_desc_color' => '',
119 'cff_link_title_color' => '',
120 'cff_link_url_color' => '',
121 'cff_link_bg_color' => '',
122 'cff_link_border_color' => '',
123 'cff_disable_link_box' => false,
124
125 //Event title
126 'cff_event_title_format' => 'p',
127 'cff_event_title_size' => 'inherit',
128 'cff_event_title_weight' => 'bold',
129 'cff_event_title_color' => '',
130 //Event date
131 'cff_event_date_size' => 'inherit',
132 'cff_event_date_weight' => 'inherit',
133 'cff_event_date_color' => '',
134 'cff_event_date_position' => 'below',
135 'cff_event_date_formatting' => '14',
136 'cff_event_date_custom' => '',
137 //Event details
138 'cff_event_details_size' => 'inherit',
139 'cff_event_details_weight' => 'inherit',
140 'cff_event_details_color' => '',
141 'cff_event_link_color' => '',
142
143 //Date
144 'cff_date_position' => 'author',
145 'cff_date_size' => 'inherit',
146 'cff_date_weight' => 'inherit',
147 'cff_date_color' => '',
148 'cff_date_formatting' => '1',
149 'cff_date_custom' => '',
150 'cff_date_before' => '',
151 'cff_date_after' => '',
152 'cff_timezone' => 'America/Chicago',
153
154 //Link to Facebook
155 'cff_link_size' => 'inherit',
156 'cff_link_weight' => 'inherit',
157 'cff_link_color' => '',
158 'cff_view_link_text' => 'View Link',
159 'cff_link_to_timeline' => false,
160
161 //Load more button
162 // 'cff_load_more' => true,
163 'cff_load_more_bg' => '',
164 'cff_load_more_text_color' => '',
165 'cff_load_more_bg_hover' => '',
166 'cff_load_more_text' => 'Load more',
167 'cff_no_more_posts_text' => 'No more posts',
168
169 //Meta
170 'cff_icon_style' => 'light',
171 'cff_meta_text_color' => '',
172 'cff_meta_link_color' => '',
173 'cff_meta_bg_color' => '',
174 'cff_expand_comments' => false,
175 'cff_comments_num' => '4',
176 'cff_nocomments_text' => 'No comments yet',
177 'cff_hide_comments' => false,
178 'cff_hide_comment_avatars' => false,
179 'cff_lightbox_comments' => true,
180 //Misc
181 'cff_feed_width' => '100%',
182 'cff_feed_width_resp' => false,
183 'cff_feed_height' => '',
184 'cff_feed_padding' => '',
185 'cff_like_box_position' => 'bottom',
186 'cff_like_box_outside' => false,
187 'cff_likebox_width' => '',
188 'cff_likebox_height' => '',
189 'cff_like_box_faces' => false,
190 'cff_like_box_border' => false,
191 'cff_like_box_cover' => true,
192 'cff_like_box_small_header' => false,
193 'cff_like_box_hide_cta' => false,
194
195 //Misc Settings
196 'cff_enable_narrow' => true,
197 'cff_one_image' => false,
198
199 'cff_bg_color' => '',
200 'cff_likebox_bg_color' => '',
201 'cff_like_box_text_color' => 'blue',
202 'cff_video_height' => '',
203 'cff_show_author' => true,
204 'cff_class' => '',
205 'cff_app_id' => '',
206 'cff_show_credit' => '',
207 'cff_format_issue' => false,
208 'cff_disable_svgs' => false,
209 'cff_restricted_page' => false,
210 'cff_hide_supporter_posts' => false,
211 'cff_font_source' => 'cdn',
212 'cff_disable_ajax_cache' => false,
213 'cff_minify' => false,
214 'disable_admin_notice' => false,
215 'cff_request_method' => 'auto',
216 'cff_cron' => 'unset',
217 'cff_timeline_pag' => 'date',
218 'cff_grid_pag' => 'auto',
219
220 //Feed Header
221 'cff_show_header' => '',
222 'cff_header_outside' => false,
223 'cff_header_text' => 'Facebook Posts',
224 'cff_header_bg_color' => '',
225 'cff_header_padding' => '',
226 'cff_header_text_size' => '',
227 'cff_header_text_weight' => '',
228 'cff_header_text_color' => '',
229 'cff_header_icon' => '',
230 'cff_header_icon_color' => '',
231 'cff_header_icon_size' => '28',
232
233 //Author
234 'cff_author_size' => 'inherit',
235 'cff_author_color' => '',
236
237 //New
238 'cff_custom_css' => '',
239 'cff_custom_js' => '',
240 'cff_title_link' => false,
241 'cff_post_tags' => true,
242 'cff_link_hashtags' => true,
243 'cff_event_title_link' => true,
244 'cff_video_action' => 'post',
245 'cff_video_player' => 'facebook',
246 'cff_sep_color' => '',
247 'cff_sep_size' => '1',
248
249 //Translate - general
250 'cff_see_more_text' => 'See More',
251 'cff_see_less_text' => 'See Less',
252 'cff_map_text' => 'Map',
253 'cff_no_events_text' => 'No upcoming events',
254 'cff_facebook_link_text' => 'View on Facebook',
255 'cff_facebook_share_text' => 'Share',
256 'cff_show_facebook_link' => true,
257 'cff_show_facebook_share' => true,
258 'cff_buy_tickets_text' => 'Buy Tickets',
259 'cff_interested_text' => 'interested',
260 'cff_going_text' => 'going',
261
262 //Translate - social
263 'cff_translate_view_previous_comments_text' => 'View more comments',
264 'cff_translate_comment_on_facebook_text' => 'Comment on Facebook',
265 'cff_translate_photos_text' => 'photos',
266 'cff_translate_likes_this_text' => 'likes this',
267 'cff_translate_like_this_text' => 'like this',
268 'cff_translate_reacted_text' => 'reacted to this',
269 'cff_translate_and_text' => 'and',
270 'cff_translate_other_text' => 'other',
271 'cff_translate_others_text' => 'others',
272 'cff_translate_reply_text' => 'Reply',
273 'cff_translate_replies_text' => 'Replies',
274
275 'cff_translate_learn_more_text' => 'Learn More',
276 'cff_translate_shop_now_text' => 'Shop Now',
277 'cff_translate_message_page_text' => 'Message Page',
278 'cff_translate_get_directions_text' => 'Get Directions',
279
280 //Translate - date
281 'cff_translate_second' => 'second',
282 'cff_translate_seconds' => 'seconds',
283 'cff_translate_minute' => 'minute',
284 'cff_translate_minutes' => 'minutes',
285 'cff_translate_hour' => 'hour',
286 'cff_translate_hours' => 'hours',
287 'cff_translate_day' => 'day',
288 'cff_translate_days' => 'days',
289 'cff_translate_week' => 'week',
290 'cff_translate_weeks' => 'weeks',
291 'cff_translate_month' => 'month',
292 'cff_translate_months' => 'months',
293 'cff_translate_year' => 'year',
294 'cff_translate_years' => 'years',
295 'cff_translate_ago' => 'ago',
296
297 // email
298 'enable_email_report' => 'on',
299 'email_notification' => 'monday',
300 'email_notification_addresses' => get_option( 'admin_email' )
301 );
302
303 $normal_bools = array(
304 'cff_show_links_type',
305 'cff_show_event_type',
306 'cff_show_video_type',
307 'cff_show_photos_type',
308 'cff_show_status_type',
309 'cff_show_albums_type',
310 'cff_show_album_title',
311 'cff_show_album_number',
312 'cff_show_video_name',
313 'cff_show_video_desc',
314 'cff_disable_lightbox',
315 'cff_reviews_rated_5',
316 'cff_reviews_rated_4',
317 'cff_reviews_rated_3',
318 'cff_reviews_rated_2',
319 'cff_reviews_rated_1',
320 'cff_reviews_no_text',
321 'cff_reviews_hide_negative',
322 'cff_show_text',
323 'cff_show_desc',
324 'cff_show_shared_links',
325 'cff_show_date',
326 'cff_show_media',
327 'cff_show_event_title',
328 'cff_show_event_details',
329 'cff_show_meta',
330 'cff_show_link',
331 'cff_show_like_box',
332 'cff_masonry_enabled',
333 'cff_box_shadow',
334 'cff_full_link_images',
335 'cff_link_to_timeline',
336 'cff_expand_comments',
337 'cff_hide_comments',
338 'cff_hide_comment_avatars',
339 'cff_lightbox_comments',
340 'cff_disable_link_box',
341 //Misc
342 'cff_feed_width',
343 'cff_feed_width_resp',
344 'cff_like_box_outside',
345 'cff_like_box_faces',
346 'cff_like_box_border',
347 'cff_like_box_cover',
348 'cff_like_box_small_header',
349 'cff_like_box_hide_cta',
350 'cff_disable_styles',
351 'cff_enable_narrow',
352 'cff_one_image',
353 'cff_show_author',
354 'cff_format_issue',
355 'cff_disable_svgs',
356 'cff_restricted_page',
357 'cff_hide_supporter_posts',
358 'cff_disable_ajax_cache',
359 'cff_minify',
360 'disable_admin_notice',
361 'cff_header_outside',
362 'cff_title_link',
363 'cff_post_tags',
364 'cff_link_hashtags',
365 'cff_event_title_link',
366 'cff_show_facebook_link',
367 'cff_show_facebook_share',
368 'enable_email_report'
369 );
370 $custom_text_settings = array(
371 'cff_reviews_link_text',
372 'cff_load_more_text',
373 'cff_no_more_posts_text',
374 'cff_nocomments_text',
375 'cff_header_text',
376 'cff_see_more_text',
377 'cff_see_less_text',
378 'cff_map_text',
379 'cff_no_events_text',
380 'cff_facebook_link_text',
381 'cff_facebook_share_text',
382 'cff_buy_tickets_text',
383 'cff_interested_text',
384 'cff_going_text',
385 'cff_translate_view_previous_comments_text',
386 'cff_translate_comment_on_facebook_text',
387 'cff_translate_photos_text',
388 'cff_translate_likes_this_text',
389 'cff_translate_like_this_text',
390 'cff_translate_reacted_text',
391 'cff_translate_and_text',
392 'cff_translate_other_text',
393 'cff_translate_others_text',
394 'cff_translate_reply_text',
395 'cff_translate_replies_text',
396 'cff_custom_css',
397 'cff_custom_js',
398 'cff_translate_learn_more_text',
399 'cff_translate_shop_now_text',
400 'cff_translate_message_page_text',
401 'cff_translate_get_directions_text',
402 'cff_class',
403 'cff_app_id',
404 'cff_show_credit',
405
406 //Translate - date
407 'cff_translate_second',
408 'cff_translate_seconds',
409 'cff_translate_minute',
410 'cff_translate_minutes',
411 'cff_translate_hour',
412 'cff_translate_hours',
413 'cff_translate_day',
414 'cff_translate_days',
415 'cff_translate_week',
416 'cff_translate_weeks',
417 'cff_translate_month',
418 'cff_translate_months',
419 'cff_translate_year',
420 'cff_translate_years',
421 'cff_translate_ago',
422 'email_notification_addresses'
423 );
424 $comma_separate_counts_settings = array(
425 'cff_filter_string',
426 'cff_exclude_string',
427 );
428
429 if ( is_array( $value ) ) {
430 if ( empty( $value ) ) {
431 return 0;
432 }
433 return count( $value );
434 // 0 for anything that might be false, 1 for everything else
435 } elseif ( in_array( $key, $normal_bools, true ) ) {
436 if ( in_array( $value, array( false, 0, '0', 'false', '' ), true ) ) {
437 return 0;
438 }
439 return 1;
440
441 // if a custom text setting, we just want to know if it's different than the default
442 } elseif ( in_array( $key, $custom_text_settings, true ) ) {
443 if ( $defaults[ $key ] === $value ) {
444 return 0;
445 }
446 return 1;
447 } elseif ( in_array( $key, $comma_separate_counts_settings, true ) ) {
448 if ( str_replace( ' ', '', $value ) === '' ) {
449 return 0;
450 }
451 $split_at_comma = explode( ',', $value );
452 return count( $split_at_comma );
453 }
454
455 return $value;
456
457 }
458
459 private function get_data() {
460 $data = array();
461
462 // Retrieve current theme info
463 $theme_data = wp_get_theme();
464
465 $count_b = 1;
466 if ( is_multisite() ) {
467 if ( function_exists( 'get_blog_count' ) ) {
468 $count_b = get_blog_count();
469 } else {
470 $count_b = 'Not Set';
471 }
472 }
473
474 $php_version = rtrim( ltrim( sanitize_text_field( phpversion() ) ) );
475 $php_version = ! empty( $php_version ) ? substr( $php_version, 0, strpos( $php_version, '.', strpos( $php_version, '.' ) + 1 ) ) : phpversion();
476
477 global $wp_version;
478 $data['this_plugin'] = 'fb';
479 $data['php_version'] = $php_version;
480 $data['mi_version'] = CFFVER;
481 $data['wp_version'] = $wp_version;
482 $data['server'] = isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '';
483 $data['multisite'] = is_multisite();
484 $data['url'] = home_url();
485 $data['themename'] = $theme_data->Name;
486 $data['themeversion'] = $theme_data->Version;
487 $data['settings'] = array();
488 $data['pro'] = cff_is_pro_version() ? '1' : '';
489 $data['sites'] = $count_b;
490 $data['usagetracking'] = get_option( 'cff_usage_tracking_config', false );
491 $num_users = function_exists( 'count_users' ) ? count_users() : 'Not Set';
492 $data['usercount'] = is_array( $num_users ) ? $num_users['total_users'] : 1;
493 $data['timezoneoffset']= date('P');
494
495 $page_id = get_option( 'cff_page_id' );
496 $own_token = get_option( 'cff_show_access_token' );
497 $by_others = get_option( 'cff_show_others' );
498 $number_posts = get_option( 'cff_num_show' );
499 $posts_limit = get_option( 'cff_post_limit' );
500 $page_type = get_option( 'cff_page_type' );
501 $caching_type = get_option( 'cff_caching_type' );
502 $caching_time = get_option( 'cff_cache_time' );
503 $caching_unit = get_option( 'cff_cache_time_unit' );
504 $locale = get_option( 'cff_locale' );
505 $connected_accounts = get_option( 'cff_connected_accounts', '{}' );
506 $connected_accounts = json_decode( stripslashes( $connected_accounts ), true );
507 $settings_to_send = array(
508 'page_id' => $page_id,
509 'own_token' => $own_token,
510 'show_others' => $by_others,
511 'num_posts' => $number_posts,
512 'posts_limit' => $posts_limit,
513 'page_type' => $page_type,
514 'caching_type' => $caching_type,
515 'caching_time' => $caching_time,
516 'caching_unit' => $caching_unit,
517 'locale' => $locale,
518 'num_connected_accounts' => count( $connected_accounts ),
519 );
520 $raw_settings = get_option( 'cff_style_settings', array() );
521 foreach ( $raw_settings as $key => $value ) {
522 $value = $this->normalize_and_format( $key, $value );
523
524 if ( $value !== false ) {
525 $key = str_replace( array( 'sb_instagram_', 'cff_' ), '', $key );
526 $settings_to_send[ $key ] = $value;
527 }
528 }
529
530 $oembed_token = get_option( 'cff_oembed_token', false );
531
532 $settings_to_send['oembed_expiring_token'] = isset( $oembed_token['access_token'] ) ? (int)$oembed_token['access_token'] > 0 : false;
533
534 global $wpdb;
535 $feed_caches = array();
536
537 $results = $wpdb->get_results( "
538 SELECT option_name
539 FROM $wpdb->options
540 WHERE `option_name` LIKE ('%\_transient\_cff\_%')
541 AND `option_name` NOT LIKE ('%\_transient\_cff\_header%');", ARRAY_A );
542
543 if ( isset( $results[0] ) ) {
544 $feed_caches = $results;
545 }
546 $settings_to_send['num_found_feed_caches'] = count( $feed_caches );
547
548 $data['settings'] = $settings_to_send;
549
550 // Retrieve current plugin information
551 if( ! function_exists( 'get_plugins' ) ) {
552 include ABSPATH . '/wp-admin/includes/plugin.php';
553 }
554
555 $plugins = get_plugins();
556 $active_plugins = get_option( 'active_plugins', array() );
557 $plugins_to_send = array();
558
559 foreach ( $plugins as $plugin_path => $plugin ) {
560 // If the plugin isn't active, don't show it.
561 if ( ! in_array( $plugin_path, $active_plugins ) )
562 continue;
563
564 $plugins_to_send[] = $plugin['Name'];
565 }
566
567 $data['active_plugins'] = $plugins_to_send;
568 $data['locale'] = get_locale();
569
570 return $data;
571 }
572
573 public function send_checkin( $override = false, $ignore_last_checkin = false ) {
574 $home_url = trailingslashit( home_url() );
575 if ( strpos( $home_url, 'smashballoon.com' ) !== false ) {
576 return false;
577 }
578
579 if( ! $this->tracking_allowed() && ! $override ) {
580 return false;
581 }
582
583 // Send a maximum of once per week
584 $usage_tracking = get_option( 'cff_usage_tracking', array( 'last_send' => 0, 'enabled' => cff_is_pro_version() ) );
585 if ( is_numeric( $usage_tracking['last_send'] ) && $usage_tracking['last_send'] > strtotime( '-1 week' ) && ! $ignore_last_checkin ) {
586 return false;
587 }
588
589 $request = wp_remote_post( 'https://usage.smashballoon.com/v1/checkin/', array(
590 'method' => 'POST',
591 'timeout' => 5,
592 'redirection' => 5,
593 'httpversion' => '1.1',
594 'blocking' => false,
595 'body' => $this->get_data(),
596 'user-agent' => 'MI/' . CFFVER . '; ' . get_bloginfo( 'url' )
597 ) );
598
599 // If we have completed successfully, recheck in 1 week
600 $usage_tracking = array(
601 'enabled' => true,
602 'last_send' => time(),
603 );
604 update_option( 'cff_usage_tracking', $usage_tracking, false );
605 return true;
606 }
607
608 private function tracking_allowed() {
609 $usage_tracking = get_option( 'cff_usage_tracking', array( 'last_send' => 0, 'enabled' => cff_is_pro_version() ) );
610 $tracking_allowed = isset( $usage_tracking['enabled'] ) ? $usage_tracking['enabled'] : cff_is_pro_version();
611
612 return $tracking_allowed;
613 }
614
615 public function schedule_send() {
616 if ( ! wp_next_scheduled( 'cff_usage_tracking_cron' ) ) {
617 $tracking = array();
618 $tracking['day'] = rand( 0, 6 );
619 $tracking['hour'] = rand( 0, 23 );
620 $tracking['minute'] = rand( 0, 59 );
621 $tracking['second'] = rand( 0, 59 );
622 $tracking['offset'] = ( $tracking['day'] * DAY_IN_SECONDS ) +
623 ( $tracking['hour'] * HOUR_IN_SECONDS ) +
624 ( $tracking['minute'] * MINUTE_IN_SECONDS ) +
625 $tracking['second'];
626 $last_sunday = strtotime("next sunday") - (7 * DAY_IN_SECONDS);
627 if ( ($last_sunday + $tracking['offset']) > time() + 6 * HOUR_IN_SECONDS ) {
628 $tracking['initsend'] = $last_sunday + $tracking['offset'];
629 } else {
630 $tracking['initsend'] = strtotime("next sunday") + $tracking['offset'];
631 }
632
633 wp_schedule_event( $tracking['initsend'], 'weekly', 'cff_usage_tracking_cron' );
634 update_option( 'cff_usage_tracking_config', $tracking );
635 }
636 }
637
638 public function add_schedules( $schedules = array() ) {
639 // Adds once weekly to the existing schedules.
640 $schedules['weekly'] = array(
641 'interval' => 604800,
642 'display' => __( 'Once Weekly', 'custom-facebook-feed' )
643 );
644 return $schedules;
645 }
646 }
647 new CFF_Tracking();