PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.10.0
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.10.0
4.12.0 4.10.0 4.9.0 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 / Custom_Facebook_Feed.php
custom-facebook-feed / inc Last commit date
Admin 3 weeks ago Builder 3 weeks ago Helpers 3 weeks ago Integrations 3 weeks ago UsageTracking 3 weeks ago CFF_Autolink.php 3 weeks ago CFF_Blocks.php 3 weeks ago CFF_Cache.php 3 weeks ago CFF_Education.php 3 weeks ago CFF_Elementor_Base.php 3 weeks ago CFF_Elementor_Widget.php 3 weeks ago CFF_Error_Reporter.php 3 weeks ago CFF_FB_Settings.php 3 weeks ago CFF_Feed_Elementor_Control.php 3 weeks ago CFF_Feed_Locator.php 3 weeks ago CFF_Feed_Pro.php 3 weeks ago CFF_GDPR_Integrations.php 3 weeks ago CFF_Group_Posts.php 3 weeks ago CFF_HTTP_Request.php 3 weeks ago CFF_Oembed.php 3 weeks ago CFF_Parse.php 3 weeks ago CFF_Resizer.php 3 weeks ago CFF_Response.php 3 weeks ago CFF_Shortcode.php 3 weeks ago CFF_Shortcode_Display.php 3 weeks ago CFF_SiteHealth.php 3 weeks ago CFF_Utils.php 3 weeks ago CFF_View.php 3 weeks ago Custom_Facebook_Feed.php 3 weeks ago Email_Notification.php 3 weeks ago Platform_Data.php 3 weeks ago SB_Facebook_Data_Encryption.php 3 weeks ago SB_Facebook_Data_Manager.php 3 weeks ago index.php 3 weeks ago
Custom_Facebook_Feed.php
1119 lines
1 <?php
2
3 /**
4 * CustomFacebookFeed plugin.
5 *
6 * The main Custom_Facebook_Feed class that runs the plugins & registers all the ressources.
7 *
8 * @since 2.19
9 */
10
11 namespace CustomFacebookFeed;
12
13 use CustomFacebookFeed\Admin\CFF_Admin_Notices;
14 use CustomFacebookFeed\Admin\CFF_Callout;
15 use CustomFacebookFeed\Admin\CFF_Onboarding_Wizard;
16 use CustomFacebookFeed\Integrations\Analytics\SB_Analytics;
17 use CustomFacebookFeed\SB_Facebook_Data_Manager;
18 use CustomFacebookFeed\Admin\CFF_Admin;
19 use CustomFacebookFeed\Admin\CFF_New_User;
20 use CustomFacebookFeed\Admin\CFF_Notifications;
21 use CustomFacebookFeed\Builder\CFF_Feed_Builder;
22 use CustomFacebookFeed\Admin\CFF_Global_Settings;
23 use CustomFacebookFeed\Admin\CFF_oEmbeds;
24 use CustomFacebookFeed\Admin\CFF_Extensions;
25 use CustomFacebookFeed\Admin\CFF_About_Us;
26 use CustomFacebookFeed\Admin\CFF_Support;
27 use CustomFacebookFeed\Admin\CFF_Support_Tool;
28 use CustomFacebookFeed\Platform_Data;
29 use CustomFacebookFeed\Integrations\Divi\CFF_Divi_Handler;
30 use FacebookFeed\Vendor\Smashballoon\Framework\Packages\Notification\Notices\SBNotices;
31
32 if (! defined('ABSPATH')) {
33 exit; // Exit if accessed directly
34 }
35
36
37
38 final class Custom_Facebook_Feed
39 {
40 /**
41 * Instance
42 *
43 * @since 2.19
44 * @access private
45 * @static
46 * @var Custom_Facebook_Feed
47 */
48 private static $instance;
49
50
51 /**
52 * CFF_Admin.
53 *
54 * Admin admin panel.
55 *
56 * @since 2.19
57 * @access public
58 *
59 * @var CFF_Admin
60 */
61 public $cff_admin;
62
63
64 /**
65 * CFF_Error_Reporter.
66 *
67 * Error Reporter panel.
68 *
69 * @since 2.19
70 * @access public
71 *
72 * @var CFF_Error_Reporter
73 */
74 public $cff_error_reporter;
75
76 /**
77 * CFF_Support_Tool.
78 *
79 * @since 2.19
80 * @access public
81 *
82 * @var CFF_Error_Reporter
83 */
84 public $cff_support_tool;
85
86 /**
87 * cff_blocks.
88 *
89 * Blocks.
90 *
91 * @since 2.19
92 * @access public
93 *
94 * @var cff_blocks
95 */
96 public $cff_blocks;
97
98 /**
99 * CFF_Notifications.
100 *
101 * Notifications System.
102 *
103 * @since 2.19
104 * @access public
105 *
106 * @var CFF_Notifications
107 */
108 public $cff_notifications;
109
110 /**
111 * CFF_New_User.
112 *
113 * New User.
114 *
115 * @since 2.19
116 * @access public
117 *
118 * @var CFF_New_User
119 */
120 public $cff_newuser;
121
122 /**
123 * CFF_Oembed.
124 *
125 * Oembed Element.
126 *
127 * @since 2.19
128 * @access public
129 *
130 * @var CFF_Oembed
131 */
132 public $cff_oembed;
133
134 /**
135 * CFF_Shortcode.
136 *
137 * Shortcode Class.
138 *
139 * @since 2.19
140 * @access public
141 *
142 * @var CFF_Shortcode
143 */
144 public $cff_shortcode;
145
146 /**
147 * CFF_SiteHealth.
148 *
149 * @since 2.19
150 * @access public
151 *
152 * @var CFF_SiteHealth
153 */
154 public $cff_sitehealth;
155
156
157 /**
158 * CFF_Feed_Builder.
159 *
160 * Feed Builder.
161 *
162 * @since 4.0
163 * @access public
164 *
165 * @var CFF_Feed_Builder
166 */
167 public $cff_feed_builder;
168
169 /**
170 * CFF_Global_Settings.
171 *
172 * Global Settings.
173 *
174 * @since 4.0
175 * @access public
176 *
177 * @var CFF_Global_Settings
178 */
179 public $cff_global_settings;
180
181 /**
182 * CFF_oEmbeds.
183 *
184 * oEmbeds Page.
185 *
186 * @since 4.0
187 * @access public
188 *
189 * @var CFF_oEmbeds
190 */
191 public $cff_oembeds;
192
193 /**
194 * CFF_About_Us.
195 *
196 * About Us Page.
197 *
198 * @since 4.0
199 * @access public
200 * @var CFF_About_Us
201 */
202 public $cff_about_us;
203
204 /**
205 * CFF_Support.
206 *
207 * Support Page.
208 *
209 * @since 4.0
210 * @access public
211 *
212 * @var CFF_Support
213 */
214 public $cff_support;
215
216 /**
217 * CFF_Tooltip_Wizard.
218 *
219 * GB Blocks Pages.
220 *
221 * @since 4.0
222 * @access public
223 *
224 * @var CFF_Tooltip_Wizard
225 */
226 public $cff_tooltip_wizard;
227
228 /**
229 * CFF_Elementor_Base.
230 *
231 * Elementor Base.
232 *
233 * @since 4.0
234 * @access public
235 *
236 * @var CFF_Elementor_Base
237 */
238 public $cff_elementor_base;
239
240 /**
241 * CFF_Onboarding_Wizard.
242 *
243 * Onboarding Wizard.
244 *
245 * @since 4.0
246 * @access public
247 *
248 * @var CFF_Onboarding_Wizard
249 */
250 public $cff_onboarding_wizard;
251
252
253 /**
254 * Platform_Data
255 *
256 * @since 4.4
257 * @access public
258 *
259 * @var Platform_Data
260 */
261 public $platform_data_manager;
262
263 /**
264 * Admin Notices
265 *
266 * @since 4.4
267 * @access public
268 *
269 * @var CFF_Admin_Notices
270 */
271 public $cff_admin_notices;
272
273 /**
274 * Analytics Plugin Integration
275 *
276 * @since 4.4
277 * @access public
278 *
279 * @var SB_Analytics
280 */
281 public $cff_sb_analytics;
282
283
284 /**
285 * Callout
286 *
287 * @since
288 * @access public
289 *
290 * @var CFF_Callout
291 */
292
293 public $cff_callout;
294
295 /**
296 * CFF_Divi_Handler
297 *
298 * Divi Module Handler.
299 *
300 * @since 4.3
301 * @access public
302 *
303 * @var \CustomFacebookFeed\Integrations\Divi\CFF_Divi_Handler
304 */
305 public $cff_divi_handler;
306
307 /**
308 * Smash Usage Tracking (extended).
309 *
310 * @since 4.8.1
311 * @access public
312 *
313 * @var \CustomFacebookFeed\UsageTracking\SmashUsageTracking
314 */
315 public $smash_usage_tracking;
316 /**
317 * Custom_Facebook_Feed Instance.
318 *
319 * Just one instance of the Custom_Facebook_Feed class
320 *
321 * @since 2.19
322 * @access public
323 * @static
324 *
325 * @return Custom_Facebook_Feed
326 */
327 public static function instance()
328 {
329 if (null === self::$instance) {
330 self::$instance = new self();
331
332 if (!class_exists('CFF_Utils')) {
333 include_once CFF_PLUGIN_DIR . 'inc/CFF_Utils.php';
334 }
335
336 require_once CFF_PLUGIN_DIR . 'vendor/autoload.php';
337
338
339 add_action('init', [ self::$instance, 'load_textdomain' ], 10);
340 add_action('plugins_loaded', [ self::$instance, 'init' ], 0);
341
342
343
344 add_action('wp_loaded', [ self::$instance, 'cff_check_for_db_updates' ]);
345
346 add_action('wp_footer', [ self::$instance, 'cff_js' ]);
347
348 add_filter('cron_schedules', [ self::$instance, 'cff_cron_custom_interval' ]);
349 add_filter('widget_text', 'do_shortcode');
350
351 add_action('wp_ajax_feed_locator', [self::$instance, 'cff_feed_locator']);
352 add_action('wp_ajax_nopriv_feed_locator', [self::$instance, 'cff_feed_locator']);
353
354 register_activation_hook(CFF_FILE, [ self::$instance, 'cff_activate' ]);
355 register_deactivation_hook(CFF_FILE, [ self::$instance, 'cff_deactivate' ]);
356 register_uninstall_hook(CFF_FILE, array('CustomFacebookFeed\Custom_Facebook_Feed','cff_uninstall'));
357
358 add_action('admin_init', [ self::$instance, 'cff_activation_plugin_redirect' ]);
359 add_action('wp_footer', [ self::$instance, 'cff_print_callout' ]);
360 }
361 return self::$instance;
362 }
363
364 /**
365 * Load Custom_Facebook_Feed textdomain.
366 *
367 * @since 2.19
368 *
369 * @return void
370 * @access public
371 */
372 public function load_textdomain()
373 {
374 load_plugin_textdomain('custom-facebook-feed', false, CFF_PLUGIN_DIR_FILE_BASE . '/languages');
375 }
376
377
378 /**
379 * Init.
380 *
381 * Initialize Custom_Facebook_Feed plugin.
382 *
383 * @since 2.19
384 * @access public
385 */
386 public function init()
387 {
388 // Load Composer Autoload
389 $this->smash_usage_tracking = new \CustomFacebookFeed\UsageTracking\SmashUsageTracking();
390 $this->cff_oembed = new CFF_Oembed();
391 $this->cff_error_reporter = new CFF_Error_Reporter();
392 $this->cff_admin = new CFF_Admin();
393 $this->cff_blocks = new CFF_Blocks();
394 $this->cff_shortcode = new CFF_Shortcode();
395 $this->cff_feed_builder = new CFF_Feed_Builder();
396 $this->cff_global_settings = new CFF_Global_Settings();
397 $this->cff_oembeds = new CFF_oEmbeds();
398 $this->cff_about_us = new CFF_About_Us();
399 $this->cff_support = new CFF_Support();
400 $this->cff_elementor_base = CFF_Elementor_Base::register();
401 $this->cff_onboarding_wizard = new CFF_Onboarding_Wizard();
402
403 self::$instance->cff_admin_notices = new CFF_Admin_Notices();
404
405 global $cff_notices;
406 $cff_notices = SBNotices::instance('custom-facebook-feed');
407
408 $this->register_assets();
409 $this->group_posts_process();
410
411 $this->detect_custom_code();
412
413 if ($this->cff_blocks->allow_load()) {
414 $this->cff_blocks->load();
415 }
416
417 $recommended_blocks = new \FacebookFeed\Vendor\Smashballoon\Framework\Packages\Blocks\RecommendedBlocks();
418 $recommended_blocks->setup();
419
420 self::$instance->cff_support_tool = new CFF_Support_Tool();
421 self::$instance->cff_divi_handler = new CFF_Divi_Handler();
422
423 if (is_admin()) {
424 $this->cff_tooltip_wizard = new Builder\CFF_Tooltip_Wizard();
425 if (version_compare(PHP_VERSION, '5.3.0') >= 0 && version_compare(get_bloginfo('version'), '4.6', '>')) {
426 $this->cff_notifications = new CFF_Notifications();
427 $this->cff_notifications->init();
428
429 $this->cff_newuser = new CFF_New_User();
430 $this->cff_newuser->init();
431
432 require_once trailingslashit(CFF_PLUGIN_DIR) . 'admin/addon-functions.php';
433 $this->cff_sitehealth = new CFF_SiteHealth();
434 if ($this->cff_sitehealth->allow_load()) {
435 $this->cff_sitehealth->load();
436 }
437 }
438 }
439
440 $this->platform_data_manager = new Platform_Data();
441 $this->platform_data_manager->register_hooks();
442
443
444 $this->cff_callout = new CFF_Callout();
445
446 self::$instance->cff_sb_analytics = new SB_Analytics();
447 }
448
449 /**
450 * Launch the Group Posts Cache Process
451 *
452 * @return void
453 * @access public
454 */
455 public function group_posts_process()
456 {
457 $cff_cron_schedule = 'hourly';
458 $cff_cache_time = get_option('cff_cache_time');
459 $cff_cache_time_unit = get_option('cff_cache_time_unit');
460 if ($cff_cache_time_unit == 'hours' && $cff_cache_time > 5) {
461 $cff_cron_schedule = 'twicedaily';
462 }
463 if ($cff_cache_time_unit == 'days') {
464 $cff_cron_schedule = 'daily';
465 }
466 CFF_Group_Posts::group_schedule_event(time(), $cff_cron_schedule);
467 }
468
469 /**
470 * Register Assets
471 *
472 * @since 2.19
473 */
474 public function register_assets()
475 {
476 add_action('wp_enqueue_scripts', array( $this, 'enqueue_styles_assets' ));
477 add_action('wp_enqueue_scripts', array( $this, 'enqueue_scripts_assets' ));
478 }
479
480
481 /**
482 * Enqueue & Register Styles
483 *
484 * @since 2.19
485 */
486 public function enqueue_styles_assets()
487 {
488 $options = get_option('cff_style_settings');
489
490 // Handles the minification of the plugin stylesheets
491 $cff_min = isset($_GET['sb_debug']) ? '' : '.min';
492
493 // Respects SSL, Style.css is relative to the current file
494 wp_register_style(
495 'cff',
496 CFF_PLUGIN_URL . 'assets/css/cff-style' . $cff_min . '.css',
497 array(),
498 CFFVER
499 );
500
501 $options['cff_enqueue_with_shortcode'] = isset($options['cff_enqueue_with_shortcode']) ? $options['cff_enqueue_with_shortcode'] : false;
502 if (isset($options['cff_enqueue_with_shortcode']) && !$options['cff_enqueue_with_shortcode']) {
503 wp_enqueue_style('cff');
504 }
505
506 $options = get_option('cff_style_settings');
507
508 if (CFF_GDPR_Integrations::doing_gdpr($options)) {
509 $options[ 'cff_font_source' ] = 'local';
510 }
511 if (!isset($options[ 'cff_font_source' ])) {
512 wp_enqueue_style('sb-font-awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
513 } else {
514 if ($options[ 'cff_font_source' ] == 'none') {
515 // Do nothing
516 } elseif ($options[ 'cff_font_source' ] == 'local') {
517 wp_enqueue_style(
518 'sb-font-awesome',
519 CFF_PLUGIN_URL . 'assets/css/font-awesome.min.css',
520 array(),
521 '4.7.0'
522 );
523 } else {
524 wp_enqueue_style('sb-font-awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
525 }
526 }
527 }
528
529
530 /**
531 * Enqueue & Register Scripts
532 *
533 * @since 2.19
534 * @access public
535 */
536 public function enqueue_scripts_assets()
537 {
538 $options = get_option('cff_style_settings');
539
540 // Handles the minification of the plugin scripts
541 $cff_min = isset($_GET['sb_debug']) ? '' : '.min';
542
543 // Register the script to make it available
544 wp_register_script(
545 'cffscripts',
546 CFF_PLUGIN_URL . 'assets/js/cff-scripts' . $cff_min . '.js',
547 array('jquery'),
548 CFFVER,
549 true
550 );
551 $options['cff_enqueue_with_shortcode'] = isset($options['cff_enqueue_with_shortcode']) ? $options['cff_enqueue_with_shortcode'] : false;
552 if (isset($options['cff_enqueue_with_shortcode']) && !$options['cff_enqueue_with_shortcode']) {
553 wp_enqueue_script('cffscripts');
554 }
555 }
556
557
558 /**
559 * DB Update Checker.
560 *
561 * Check for the db updates
562 *
563 * @since 2.19
564 * @access public
565 */
566 public function cff_check_for_db_updates()
567 {
568 $db_ver = get_option('cff_db_version', 0);
569 if ((float) $db_ver < 1.0) {
570 global $wp_roles;
571 $wp_roles->add_cap('administrator', 'manage_custom_facebook_feed_options');
572 $cff_statuses_option = get_option('cff_statuses', array());
573 if (! isset($cff_statuses_option['first_install'])) {
574 $options_set = get_option('cff_page_id', false);
575 if ($options_set) {
576 $cff_statuses_option['first_install'] = 'from_update';
577 } else {
578 $cff_statuses_option['first_install'] = time();
579 }
580 $cff_rating_notice_option = get_option('cff_rating_notice', false);
581 if ($cff_rating_notice_option === 'dismissed') {
582 $cff_statuses_option['rating_notice_dismissed'] = time();
583 }
584 $cff_rating_notice_waiting = get_transient('custom_facebook_rating_notice_waiting');
585 if (
586 $cff_rating_notice_waiting === false
587 && $cff_rating_notice_option === false
588 ) {
589 $time = 2 * WEEK_IN_SECONDS;
590 set_transient('custom_facebook_rating_notice_waiting', 'waiting', $time);
591 update_option('cff_rating_notice', 'pending', false);
592 }
593 update_option('cff_statuses', $cff_statuses_option, false);
594 }
595 update_option('cff_db_version', CFF_DBVERSION);
596 }
597 if ((float) $db_ver < 1.1) {
598 if (! wp_next_scheduled('cff_feed_issue_email')) {
599 $timestamp = strtotime('next monday');
600 $timestamp = $timestamp + (3600 * 24 * 7);
601 $six_am_local = $timestamp + CFF_Utils::cff_get_utc_offset() + (6 * 60 * 60);
602 wp_schedule_event($six_am_local, 'cffweekly', 'cff_feed_issue_email');
603 }
604 update_option('cff_db_version', CFF_DBVERSION);
605 }
606 if ((float) $db_ver < 1.2) {
607 if (! wp_next_scheduled('cff_notification_update')) {
608 $timestamp = strtotime('next monday');
609 $timestamp = $timestamp + (3600 * 24 * 7);
610 $six_am_local = $timestamp + CFF_Utils::cff_get_utc_offset() + (6 * 60 * 60);
611
612 wp_schedule_event($six_am_local, 'cffweekly', 'cff_notification_update');
613 }
614 update_option('cff_db_version', CFF_DBVERSION);
615 }
616
617 if ((float) $db_ver < 1.3) {
618 CFF_Feed_Locator::create_table();
619 update_option('cff_db_version', CFF_DBVERSION);
620 }
621
622 if ((float) $db_ver < 1.4) {
623 Builder\CFF_Db::create_tables();
624 update_option('cff_db_version', CFF_DBVERSION);
625 }
626
627 // \CustomFacebookFeed\Builder\CFF_Db::reset_tables();\CustomFacebookFeed\Builder\CFF_Db::reset_db_update();die();
628
629 /**
630 * for 4.0 update
631 */
632 if ((float) $db_ver < 2.1) {
633 $options = get_option('cff_style_settings', array());
634 $legacy_at = get_option('cff_access_token');
635 $options_support_legacy = false; // in case the locator table doesn't have any feeds in it but someone might be using legacy feeds
636 if (! empty($legacy_at)) {
637 $options_support_legacy = true;
638 \CustomFacebookFeed\Builder\CFF_Feed_Saver::set_legacy_feed_settings();
639 }
640
641 \CustomFacebookFeed\Builder\CFF_Db::create_tables();
642 update_option('cff_db_version', CFF_DBVERSION);
643
644 // are there existing feeds to toggle legacy onboarding?
645 $cff_statuses_option = get_option('cff_statuses', array());
646 $cff_statuses_option['legacy_onboarding'] = array(
647 'active' => false,
648 'type' => 'single'
649 );
650
651 \CustomFacebookFeed\Builder\CFF_Source::set_legacy_source_queue();
652 if (\CustomFacebookFeed\Builder\CFF_Source::should_do_source_updates()) {
653 \CustomFacebookFeed\Builder\CFF_Source::batch_process_legacy_source_queue();
654 }
655
656 \CustomFacebookFeed\Builder\CFF_Source::update_source_from_legacy_settings();
657
658 // how many legacy feeds?
659 $args = array(
660 'html_location' => array( 'header', 'footer', 'sidebar', 'content', 'unknown' ),
661 'group_by' => 'shortcode_atts',
662 'page' => 1
663 );
664 $feeds_data = \CustomFacebookFeed\CFF_Feed_Locator::legacy_facebook_feed_locator_query($args);
665 $num_legacy = count($feeds_data);
666
667 $cff_statuses_option['support_legacy_shortcode'] = false;
668
669 if ($num_legacy > 0) {
670 if ($num_legacy > 1) {
671 $cff_statuses_option['legacy_onboarding'] = array(
672 'active' => true,
673 'type' => 'multiple'
674 );
675 $cff_statuses_option['support_legacy_shortcode'] = true;
676 } else {
677 $cff_statuses_option['legacy_onboarding'] = array(
678 'active' => true,
679 'type' => 'single'
680 );
681
682 $shortcode_atts = $feeds_data[0]['shortcode_atts'] != '[""]' ? json_decode($feeds_data[0]['shortcode_atts'], true) : [];
683 $shortcode_atts = is_array($shortcode_atts) ? $shortcode_atts : array();
684
685 $cff_statuses_option['support_legacy_shortcode'] = $shortcode_atts;
686
687 $settings_data = \CustomFacebookFeed\Builder\CFF_Post_Set::legacy_to_builder_convert($shortcode_atts);
688
689 if (isset($settings_data['id'])) {
690 $source_ids = explode(',', str_replace(' ', '', $settings_data['id']));
691 } else {
692 $source_ids = (array)get_option('cff_page_id', array());
693 }
694
695 $source_list = \CustomFacebookFeed\Builder\CFF_Feed_Builder::get_source_list();
696
697 $supported_sources = array();
698 $feed_name = 'Existing Feed';
699 foreach ($source_list as $source) {
700 if (in_array($source['account_id'], $source_ids, true)) {
701 $supported_sources[] = $source['account_id'];
702 $feed_name = $source['username'];
703 }
704 }
705
706 $feed_saver = new \CustomFacebookFeed\Builder\CFF_Feed_Saver(false);
707 $feed_saver->set_data($settings_data);
708
709 $feed_saver->set_feed_name($feed_name);
710
711 $new_feed_id = $feed_saver->update_or_insert();
712
713 $args = array(
714 'new_feed_id' => $new_feed_id,
715 'legacy_feed_id' => $feeds_data[0]['feed_id'],
716 );
717
718 CFF_Feed_Locator::update_legacy_to_builder($args);
719 }
720 } elseif ($num_legacy === 0 && $options_support_legacy) {
721 $cff_statuses_option['support_legacy_shortcode'] = true;
722 }
723
724 update_option('cff_statuses', $cff_statuses_option);
725 }
726
727 if ((float) $db_ver < 2.2) {
728 $manager = new SB_Facebook_Data_Manager();
729 $manager->update_db_for_dpa();
730 update_option('cff_db_version', CFF_DBVERSION);
731 }
732
733 if (version_compare($db_ver, '2.4', '<')) {
734 update_option('cff_db_version', CFF_DBVERSION);
735
736 $groups = \CustomFacebookFeed\Builder\CFF_Db::source_query(array( 'type' => 'group' ));
737
738 $cff_statuses_option = get_option('cff_statuses', array());
739 $cff_statuses_option['groups_need_update'] = false;
740
741 if (empty($groups)) {
742 update_option('cff_statuses', $cff_statuses_option, false);
743 } else {
744 $encryption = new \CustomFacebookFeed\SB_Facebook_Data_Encryption();
745 $groups_need_update = false;
746 foreach ($groups as $source) {
747 $info = ! empty($source['info']) ? json_decode($encryption->decrypt($source['info'])) : array();
748 if (\CustomFacebookFeed\Builder\CFF_Source::needs_update($source, $info)) {
749 $groups_need_update = true;
750 }
751 }
752 $cff_statuses_option['groups_need_update'] = $groups_need_update;
753 update_option('cff_statuses', $cff_statuses_option, false);
754 }
755
756 $cff_statuses_option['wizard_dismissed'] = false;
757 update_option('cff_statuses', $cff_statuses_option);
758 }
759
760 if (version_compare($db_ver, '2.5', '<')) {
761 $cff_statuses_option = get_option('cff_statuses', array());
762 if (!isset($cff_statuses_option['wizard_dismissed'])) {
763 $cff_statuses_option['wizard_dismissed'] = true;
764 update_option('cff_statuses', $cff_statuses_option);
765 }
766 update_option('cff_db_version', CFF_DBVERSION);
767 }
768 }
769
770
771 /**
772 * Activate
773 *
774 * CFF activation action.
775 *
776 * @since 2.19
777 * @access public
778 */
779 public function cff_activate()
780 {
781 $options = get_option('cff_style_settings', array());
782
783 // Run cron twice daily when plugin is first activated for new users
784 if (! wp_next_scheduled('cff_cron_job')) {
785 wp_schedule_event(time(), 'twicedaily', 'cff_cron_job');
786 }
787 if (! wp_next_scheduled('cff_feed_issue_email')) {
788 CFF_Utils::cff_schedule_report_email();
789 }
790 // set usage tracking to false if fresh install. Skip when the Pro plugin is active: it shares
791 // this option and defaults tracking on, so seeding a disabled record here would silently turn it off.
792 $usage_tracking = get_option('cff_usage_tracking', false);
793 $cff_network_active = is_multisite() ? (array) get_site_option( 'active_sitewide_plugins', array() ) : array();
794 $cff_pro_active = in_array( 'custom-facebook-feed-pro/custom-facebook-feed.php', (array) get_option( 'active_plugins', array() ), true )
795 || isset( $cff_network_active['custom-facebook-feed-pro/custom-facebook-feed.php'] );
796
797 if ( ! is_array( $usage_tracking ) && ! $cff_pro_active ) {
798 $usage_tracking = array(
799 'enabled' => false,
800 'last_send' => 0
801 );
802 update_option('cff_usage_tracking', $usage_tracking, false);
803 }
804
805 if (! wp_next_scheduled('cff_notification_update')) {
806 $timestamp = strtotime('next monday');
807 $timestamp = $timestamp + (3600 * 24 * 7);
808 $six_am_local = $timestamp + CFF_Utils::cff_get_utc_offset() + (6 * 60 * 60);
809 wp_schedule_event($six_am_local, 'cffweekly', 'cff_notification_update');
810 }
811
812 $cff_statuses_option = get_option('cff_statuses', array());
813 if (!isset($cff_statuses_option['wizard_dismissed']) || $cff_statuses_option['wizard_dismissed'] === false) {
814 add_option('cff_plugin_do_activation_redirect', true);
815 }
816
817 if (! empty($options)) {
818 return;
819 }
820
821 // Show all post types
822 $options[ 'cff_show_links_type' ] = true;
823 $options[ 'cff_show_event_type' ] = true;
824 $options[ 'cff_show_video_type' ] = true;
825 $options[ 'cff_show_photos_type' ] = true;
826 $options[ 'cff_show_status_type' ] = true;
827 $options[ 'cff_show_albums_type' ] = true;
828 $options[ 'cff_show_author' ] = true;
829 $options[ 'cff_show_text' ] = true;
830 $options[ 'cff_show_desc' ] = true;
831 $options[ 'cff_show_shared_links' ] = true;
832 $options[ 'cff_show_date' ] = true;
833 $options[ 'cff_show_media' ] = true;
834 $options[ 'cff_show_media_link' ] = true;
835 $options[ 'cff_show_event_title' ] = true;
836 $options[ 'cff_show_event_details' ] = true;
837 $options[ 'cff_show_meta' ] = true;
838 $options[ 'cff_show_link' ] = true;
839 $options[ 'cff_show_like_box' ] = true;
840 $options[ 'cff_show_facebook_link' ] = true;
841 $options[ 'cff_show_facebook_share' ] = true;
842 $options[ 'cff_event_title_link' ] = true;
843
844 update_option('cff_style_settings', $options);
845
846 get_option('cff_show_access_token');
847 update_option('cff_show_access_token', true);
848 }
849
850 public function cff_activation_plugin_redirect()
851 {
852 $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options';
853 if (!current_user_can($cap)) {
854 return false;
855 }
856
857 if (get_option('cff_plugin_do_activation_redirect', false)) {
858 delete_option('cff_plugin_do_activation_redirect');
859 wp_safe_redirect(admin_url('/admin.php?page=cff-setup'));
860 exit();
861 }
862 }
863
864
865 /**
866 * Deactivate
867 *
868 * CFF deactivation action.
869 *
870 * @since 2.19
871 * @access public
872 */
873 public function cff_deactivate()
874 {
875 wp_clear_scheduled_hook('cff_cron_job');
876 wp_clear_scheduled_hook('cff_notification_update');
877 wp_clear_scheduled_hook('cff_feed_issue_email');
878 wp_clear_scheduled_hook('cff_usage_tracking_cron');
879 wp_clear_scheduled_hook( \CustomFacebookFeed\UsageTracking\Config::CRON_HOOK );
880 }
881
882
883 /**
884 * Uninstall
885 *
886 * CFF uninstallation action.
887 *
888 * @since 2.19
889 * @access public
890 */
891 public static function cff_uninstall()
892 {
893 if (! current_user_can('activate_plugins')) {
894 return;
895 }
896 // If the user is preserving the settings then don't delete them
897 $cff_preserve_settings = get_option('cff_preserve_settings');
898 if (! empty($cff_preserve_settings)) {
899 return;
900 }
901
902 // Settings
903 delete_option('cff_show_access_token');
904 delete_option('cff_access_token');
905 delete_option('cff_page_id');
906 delete_option('cff_num_show');
907 delete_option('cff_post_limit');
908 delete_option('cff_show_others');
909 delete_option('cff_cache_time');
910 delete_option('cff_cache_time_unit');
911 delete_option('cff_locale');
912 delete_option('cff_ajax');
913 delete_option('cff_preserve_settings');
914 // Style & Layout
915 delete_option('cff_title_length');
916 delete_option('cff_body_length');
917 delete_option('cff_style_settings');
918
919 delete_option('cff_usage_tracking_config');
920 // Usage-tracking consent, site token and telemetry are shared with the Pro plugin. Only remove
921 // them when Pro is not active, otherwise deleting the free plugin would reset Pro's consent.
922 $cff_network_active = is_multisite() ? (array) get_site_option( 'active_sitewide_plugins', array() ) : array();
923 $cff_pro_active = in_array( 'custom-facebook-feed-pro/custom-facebook-feed.php', (array) get_option( 'active_plugins', array() ), true )
924 || isset( $cff_network_active['custom-facebook-feed-pro/custom-facebook-feed.php'] );
925 if ( ! $cff_pro_active ) {
926 delete_option( 'cff_usage_tracking' );
927 delete_option( 'cff_smash_usage_tracking' );
928 delete_option( 'cff_smash_usage_tracking_site_token' );
929 delete_option( 'cff_smash_usage_tracking_schedule' );
930 delete_option( 'cff_smash_usage_events' );
931 delete_option( 'cff_smash_usage_active_dates' );
932 delete_option( 'cff_smash_usage_session_durations' );
933 }
934 wp_clear_scheduled_hook( 'cff_usage_tracking_cron' );
935 wp_clear_scheduled_hook( \CustomFacebookFeed\UsageTracking\Config::CRON_HOOK );
936
937 delete_option('cff_statuses');
938 delete_option('cff_rating_notice');
939 delete_option('cff_review_consent');
940 delete_option('cff_db_version');
941 delete_option('cff_newuser_notifications');
942 delete_option('cff_notifications');
943
944 delete_option('cff_legacy_feed_settings');
945 delete_option('cff_theme_styles');
946 delete_option('cff_caching_type');
947 delete_option('cff_oembed_token');
948
949 global $wp_roles;
950 $wp_roles->remove_cap('administrator', 'manage_custom_facebook_feed_options');
951
952 global $wpdb;
953 $locator_table_name = $wpdb->prefix . CFF_FEED_LOCATOR;
954 $wpdb->query("DROP TABLE IF EXISTS $locator_table_name");
955
956 $feeds_table_name = $wpdb->prefix . 'cff_feeds';
957 $wpdb->query("DROP TABLE IF EXISTS $feeds_table_name");
958
959 $feed_caches_table_name = $wpdb->prefix . 'cff_feed_caches';
960 $wpdb->query("DROP TABLE IF EXISTS $feed_caches_table_name");
961
962 $sources_table_name = $wpdb->prefix . 'cff_sources';
963 $wpdb->query("DROP TABLE IF EXISTS $sources_table_name");
964
965 $table_name = esc_sql($wpdb->prefix . "postmeta");
966 $result = $wpdb->query("
967 DELETE
968 FROM $table_name
969 WHERE meta_key = '_cff_oembed_done_checking';");
970
971 $usermeta_table_name = $wpdb->prefix . "usermeta";
972 $result = $wpdb->query("
973 DELETE
974 FROM $usermeta_table_name
975 WHERE meta_key LIKE ('cff\_%')
976 ");
977 }
978
979
980
981 /**
982 * Custom CSS
983 *
984 * Adding custom CSS
985 *
986 * @since 2.19
987 * @access public
988 * @deprecated
989 */
990 public function cff_custom_css()
991 {
992 }
993
994
995 /**
996 * Custom JS
997 *
998 * Adding custom JS
999 *
1000 * @since 2.19
1001 * @access public
1002 */
1003 public function cff_js()
1004 {
1005 $options = get_option('cff_style_settings');
1006
1007 // Link hashtags?
1008 isset($options[ 'cff_link_hashtags' ]) ? $cff_link_hashtags = $options[ 'cff_link_hashtags' ] : $cff_link_hashtags = 'true';
1009 ($cff_link_hashtags == 'true' || $cff_link_hashtags == 'on') ? $cff_link_hashtags = 'true' : $cff_link_hashtags = 'false';
1010
1011 // If linking the post text then don't link the hashtags
1012 isset($options[ 'cff_title_link' ]) ? $cff_title_link = $options[ 'cff_title_link' ] : $cff_title_link = false;
1013 ($cff_title_link == 'true' || $cff_title_link == 'on') ? $cff_title_link = true : $cff_title_link = false;
1014 if ($cff_title_link) {
1015 $cff_link_hashtags = 'false';
1016 }
1017
1018 echo '<!-- Custom Facebook Feed JS -->';
1019 echo "\r\n";
1020 echo '<script type="text/javascript">';
1021 echo 'var cffajaxurl = "' . admin_url('admin-ajax.php') . '";';
1022 echo "\r\n";
1023 echo 'var cfflinkhashtags = "' . $cff_link_hashtags . '";';
1024 echo "\r\n";
1025 echo '</script>';
1026 echo "\r\n";
1027 }
1028
1029
1030 /**
1031 * Cron Custom Interval
1032 *
1033 * Cron Job Custom Interval
1034 *
1035 * @since 2.19
1036 * @access public
1037 */
1038 public function cff_cron_custom_interval($schedules)
1039 {
1040 $schedules['cffweekly'] = array(
1041 'interval' => 3600 * 24 * 7,
1042 'display' => __('Weekly')
1043 );
1044 return $schedules;
1045 }
1046
1047 /**
1048 * Feed Locator Ajax Call
1049 *
1050 * @since 2.19
1051 * @access public
1052 */
1053 public function cff_feed_locator()
1054 {
1055
1056 $feed_locator_data_array = isset($_POST['feedLocatorData']) && !empty($_POST['feedLocatorData']) && is_array($_POST['feedLocatorData']) ? $_POST['feedLocatorData'] : false;
1057 if ($feed_locator_data_array != false) :
1058 foreach ($feed_locator_data_array as $single_feed_locator) {
1059 $can_do_background_tasks = false;
1060
1061 $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options';
1062 $cap = apply_filters('cff_settings_pages_capability', $cap);
1063 if (current_user_can($cap)) {
1064 $can_do_background_tasks = true;
1065 } else {
1066 $nonce = isset($_POST['locator_nonce']) ? sanitize_text_field(wp_unslash($_POST['locator_nonce'])) : '';
1067 if (isset($single_feed_locator['postID']) && wp_verify_nonce($nonce, esc_attr('cff-locator-nonce-' . $single_feed_locator['postID']))) {
1068 $can_do_background_tasks = true;
1069 }
1070 }
1071
1072 if ($can_do_background_tasks) {
1073 $feed_details = array(
1074 'feed_id' => $single_feed_locator['feedID'],
1075 'atts' => $single_feed_locator['shortCodeAtts'],
1076 'location' => array(
1077 'post_id' => $single_feed_locator['postID'],
1078 'html' => $single_feed_locator['location']
1079 )
1080 );
1081 $locator = new CFF_Feed_Locator($feed_details);
1082 $locator->add_or_update_entry();
1083 }
1084 }
1085 endif;
1086 die();
1087 }
1088
1089 /**
1090 * Detect Custom CSS Code
1091 *
1092 * @since ??
1093 * @access public
1094 */
1095 public function detect_custom_code()
1096 {
1097 // $cff_options = get_option( 'cff_style_settings' );
1098 // if( !empty( $cff_options[ 'cff_custom_css' ]) ){
1099 // $core_custom_css = wp_get_custom_css();
1100 // \WP_Customize_Custom_CSS_Setting
1101 // }
1102 }
1103
1104 /**
1105 * Summary of print_callout
1106 *
1107 * @return void
1108 */
1109 public function cff_print_callout()
1110 {
1111 if (is_user_logged_in()) {
1112 $current_user = wp_get_current_user();
1113 if (user_can($current_user, 'administrator')) {
1114 CFF_Callout::print_callout();
1115 }
1116 }
1117 }
1118 }
1119