PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.7.5
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.7.5
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 4 months ago Builder 4 months ago Helpers 4 months ago Integrations 4 months ago CFF_Autolink.php 4 months ago CFF_Blocks.php 4 months ago CFF_Cache.php 4 months ago CFF_Education.php 4 months ago CFF_Elementor_Base.php 4 months ago CFF_Elementor_Widget.php 4 months ago CFF_Error_Reporter.php 4 months ago CFF_FB_Settings.php 4 months ago CFF_Feed_Elementor_Control.php 4 months ago CFF_Feed_Locator.php 4 months ago CFF_Feed_Pro.php 4 months ago CFF_GDPR_Integrations.php 4 months ago CFF_Group_Posts.php 4 months ago CFF_HTTP_Request.php 4 months ago CFF_Oembed.php 4 months ago CFF_Parse.php 4 months ago CFF_Resizer.php 4 months ago CFF_Response.php 4 months ago CFF_Shortcode.php 4 months ago CFF_Shortcode_Display.php 4 months ago CFF_SiteHealth.php 4 months ago CFF_Utils.php 4 months ago CFF_View.php 4 months ago Custom_Facebook_Feed.php 4 months ago Email_Notification.php 4 months ago Platform_Data.php 4 months ago SB_Facebook_Data_Encryption.php 4 months ago SB_Facebook_Data_Manager.php 4 months ago index.php 4 months ago
Custom_Facebook_Feed.php
1099 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\Admin\CFF_Tracking;
22 use CustomFacebookFeed\Builder\CFF_Feed_Builder;
23 use CustomFacebookFeed\Admin\CFF_Global_Settings;
24 use CustomFacebookFeed\Admin\CFF_oEmbeds;
25 use CustomFacebookFeed\Admin\CFF_Extensions;
26 use CustomFacebookFeed\Admin\CFF_About_Us;
27 use CustomFacebookFeed\Admin\CFF_Support;
28 use CustomFacebookFeed\Admin\CFF_Support_Tool;
29 use CustomFacebookFeed\Platform_Data;
30 use CustomFacebookFeed\Integrations\Divi\CFF_Divi_Handler;
31 use Smashballoon\Framework\Packages\Notification\Notices\SBNotices;
32
33 if (! defined('ABSPATH')) {
34 exit; // Exit if accessed directly
35 }
36
37
38
39 final class Custom_Facebook_Feed
40 {
41 /**
42 * Instance
43 *
44 * @since 2.19
45 * @access private
46 * @static
47 * @var Custom_Facebook_Feed
48 */
49 private static $instance;
50
51
52 /**
53 * CFF_Admin.
54 *
55 * Admin admin panel.
56 *
57 * @since 2.19
58 * @access public
59 *
60 * @var CFF_Admin
61 */
62 public $cff_admin;
63
64
65 /**
66 * CFF_Error_Reporter.
67 *
68 * Error Reporter panel.
69 *
70 * @since 2.19
71 * @access public
72 *
73 * @var CFF_Error_Reporter
74 */
75 public $cff_error_reporter;
76
77 /**
78 * CFF_Support_Tool.
79 *
80 * @since 2.19
81 * @access public
82 *
83 * @var CFF_Error_Reporter
84 */
85 public $cff_support_tool;
86
87 /**
88 * cff_blocks.
89 *
90 * Blocks.
91 *
92 * @since 2.19
93 * @access public
94 *
95 * @var cff_blocks
96 */
97 public $cff_blocks;
98
99 /**
100 * CFF_Notifications.
101 *
102 * Notifications System.
103 *
104 * @since 2.19
105 * @access public
106 *
107 * @var CFF_Notifications
108 */
109 public $cff_notifications;
110
111 /**
112 * CFF_New_User.
113 *
114 * New User.
115 *
116 * @since 2.19
117 * @access public
118 *
119 * @var CFF_New_User
120 */
121 public $cff_newuser;
122
123 /**
124 * CFF_Oembed.
125 *
126 * Oembed Element.
127 *
128 * @since 2.19
129 * @access public
130 *
131 * @var CFF_Oembed
132 */
133 public $cff_oembed;
134
135 /**
136 * CFF_Tracking.
137 *
138 * Tracking System.
139 *
140 * @since 2.19
141 * @access public
142 *
143 * @var CFF_Tracking
144 */
145 public $cff_tracking;
146
147 /**
148 * CFF_Shortcode.
149 *
150 * Shortcode Class.
151 *
152 * @since 2.19
153 * @access public
154 *
155 * @var CFF_Shortcode
156 */
157 public $cff_shortcode;
158
159 /**
160 * CFF_SiteHealth.
161 *
162 * @since 2.19
163 * @access public
164 *
165 * @var CFF_SiteHealth
166 */
167 public $cff_sitehealth;
168
169
170 /**
171 * CFF_Feed_Builder.
172 *
173 * Feed Builder.
174 *
175 * @since 4.0
176 * @access public
177 *
178 * @var CFF_Feed_Builder
179 */
180 public $cff_feed_builder;
181
182 /**
183 * CFF_Global_Settings.
184 *
185 * Global Settings.
186 *
187 * @since 4.0
188 * @access public
189 *
190 * @var CFF_Global_Settings
191 */
192 public $cff_global_settings;
193
194 /**
195 * CFF_oEmbeds.
196 *
197 * oEmbeds Page.
198 *
199 * @since 4.0
200 * @access public
201 *
202 * @var CFF_oEmbeds
203 */
204 public $cff_oembeds;
205
206 /**
207 * CFF_About_Us.
208 *
209 * About Us Page.
210 *
211 * @since 4.0
212 * @access public
213 * @var CFF_About_Us
214 */
215 public $cff_about_us;
216
217 /**
218 * CFF_Support.
219 *
220 * Support Page.
221 *
222 * @since 4.0
223 * @access public
224 *
225 * @var CFF_Support
226 */
227 public $cff_support;
228
229 /**
230 * CFF_Tooltip_Wizard.
231 *
232 * GB Blocks Pages.
233 *
234 * @since 4.0
235 * @access public
236 *
237 * @var CFF_Tooltip_Wizard
238 */
239 public $cff_tooltip_wizard;
240
241 /**
242 * CFF_Elementor_Base.
243 *
244 * Elementor Base.
245 *
246 * @since 4.0
247 * @access public
248 *
249 * @var CFF_Elementor_Base
250 */
251 public $cff_elementor_base;
252
253 /**
254 * CFF_Onboarding_Wizard.
255 *
256 * Onboarding Wizard.
257 *
258 * @since 4.0
259 * @access public
260 *
261 * @var CFF_Onboarding_Wizard
262 */
263 public $cff_onboarding_wizard;
264
265
266 /**
267 * Platform_Data
268 *
269 * @since 4.4
270 * @access public
271 *
272 * @var Platform_Data
273 */
274 public $platform_data_manager;
275
276 /**
277 * Admin Notices
278 *
279 * @since 4.4
280 * @access public
281 *
282 * @var CFF_Admin_Notices
283 */
284 public $cff_admin_notices;
285
286 /**
287 * Analytics Plugin Integration
288 *
289 * @since 4.4
290 * @access public
291 *
292 * @var SB_Analytics
293 */
294 public $cff_sb_analytics;
295
296
297 /**
298 * Callout
299 *
300 * @since
301 * @access public
302 *
303 * @var CFF_Callout
304 */
305
306 public $cff_callout;
307
308 /**
309 * CFF_Divi_Handler
310 *
311 * Divi Module Handler.
312 *
313 * @since 4.3
314 * @access public
315 *
316 * @var \CustomFacebookFeed\Integrations\Divi\CFF_Divi_Handler
317 */
318 public $cff_divi_handler;
319 /**
320 * Custom_Facebook_Feed Instance.
321 *
322 * Just one instance of the Custom_Facebook_Feed class
323 *
324 * @since 2.19
325 * @access public
326 * @static
327 *
328 * @return Custom_Facebook_Feed
329 */
330 public static function instance()
331 {
332 if (null === self::$instance) {
333 self::$instance = new self();
334
335 if (!class_exists('CFF_Utils')) {
336 include_once CFF_PLUGIN_DIR . 'inc/CFF_Utils.php';
337 }
338
339 require_once CFF_PLUGIN_DIR . 'vendor/autoload.php';
340
341
342 add_action('init', [ self::$instance, 'load_textdomain' ], 10);
343 add_action('plugins_loaded', [ self::$instance, 'init' ], 0);
344
345
346
347 add_action('wp_loaded', [ self::$instance, 'cff_check_for_db_updates' ]);
348
349 add_action('wp_footer', [ self::$instance, 'cff_js' ]);
350
351 add_filter('cron_schedules', [ self::$instance, 'cff_cron_custom_interval' ]);
352 add_filter('widget_text', 'do_shortcode');
353
354 add_action('wp_ajax_feed_locator', [self::$instance, 'cff_feed_locator']);
355 add_action('wp_ajax_nopriv_feed_locator', [self::$instance, 'cff_feed_locator']);
356
357 register_activation_hook(CFF_FILE, [ self::$instance, 'cff_activate' ]);
358 register_deactivation_hook(CFF_FILE, [ self::$instance, 'cff_deactivate' ]);
359 register_uninstall_hook(CFF_FILE, array('CustomFacebookFeed\Custom_Facebook_Feed','cff_uninstall'));
360
361 add_action('admin_init', [ self::$instance, 'cff_activation_plugin_redirect' ]);
362 add_action('wp_footer', [ self::$instance, 'cff_print_callout' ]);
363 }
364 return self::$instance;
365 }
366
367 /**
368 * Load Custom_Facebook_Feed textdomain.
369 *
370 * @since 2.19
371 *
372 * @return void
373 * @access public
374 */
375 public function load_textdomain()
376 {
377 load_plugin_textdomain('custom-facebook-feed', false, CFF_PLUGIN_DIR_FILE_BASE . '/languages');
378 }
379
380
381 /**
382 * Init.
383 *
384 * Initialize Custom_Facebook_Feed plugin.
385 *
386 * @since 2.19
387 * @access public
388 */
389 public function init()
390 {
391 // Load Composer Autoload
392 $this->cff_tracking = new CFF_Tracking();
393 $this->cff_oembed = new CFF_Oembed();
394 $this->cff_error_reporter = new CFF_Error_Reporter();
395 $this->cff_admin = new CFF_Admin();
396 $this->cff_blocks = new CFF_Blocks();
397 $this->cff_shortcode = new CFF_Shortcode();
398 $this->cff_feed_builder = new CFF_Feed_Builder();
399 $this->cff_global_settings = new CFF_Global_Settings();
400 $this->cff_oembeds = new CFF_oEmbeds();
401 $this->cff_about_us = new CFF_About_Us();
402 $this->cff_support = new CFF_Support();
403 $this->cff_elementor_base = CFF_Elementor_Base::instance();
404 $this->cff_onboarding_wizard = new CFF_Onboarding_Wizard();
405
406 self::$instance->cff_admin_notices = new CFF_Admin_Notices();
407
408 global $cff_notices;
409 $cff_notices = SBNotices::instance('custom-facebook-feed');
410
411 $this->register_assets();
412 $this->group_posts_process();
413
414 $this->detect_custom_code();
415
416 if ($this->cff_blocks->allow_load()) {
417 $this->cff_blocks->load();
418 }
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.
791 $usage_tracking = get_option('cff_usage_tracking', false);
792
793 if (! is_array($usage_tracking)) {
794 $usage_tracking = array(
795 'enabled' => false,
796 'last_send' => 0
797 );
798 update_option('cff_usage_tracking', $usage_tracking, false);
799 }
800
801 if (! wp_next_scheduled('cff_notification_update')) {
802 $timestamp = strtotime('next monday');
803 $timestamp = $timestamp + (3600 * 24 * 7);
804 $six_am_local = $timestamp + CFF_Utils::cff_get_utc_offset() + (6 * 60 * 60);
805 wp_schedule_event($six_am_local, 'cffweekly', 'cff_notification_update');
806 }
807
808 $cff_statuses_option = get_option('cff_statuses', array());
809 if (!isset($cff_statuses_option['wizard_dismissed']) || $cff_statuses_option['wizard_dismissed'] === false) {
810 add_option('cff_plugin_do_activation_redirect', true);
811 }
812
813 if (! empty($options)) {
814 return;
815 }
816
817 // Show all post types
818 $options[ 'cff_show_links_type' ] = true;
819 $options[ 'cff_show_event_type' ] = true;
820 $options[ 'cff_show_video_type' ] = true;
821 $options[ 'cff_show_photos_type' ] = true;
822 $options[ 'cff_show_status_type' ] = true;
823 $options[ 'cff_show_albums_type' ] = true;
824 $options[ 'cff_show_author' ] = true;
825 $options[ 'cff_show_text' ] = true;
826 $options[ 'cff_show_desc' ] = true;
827 $options[ 'cff_show_shared_links' ] = true;
828 $options[ 'cff_show_date' ] = true;
829 $options[ 'cff_show_media' ] = true;
830 $options[ 'cff_show_media_link' ] = true;
831 $options[ 'cff_show_event_title' ] = true;
832 $options[ 'cff_show_event_details' ] = true;
833 $options[ 'cff_show_meta' ] = true;
834 $options[ 'cff_show_link' ] = true;
835 $options[ 'cff_show_like_box' ] = true;
836 $options[ 'cff_show_facebook_link' ] = true;
837 $options[ 'cff_show_facebook_share' ] = true;
838 $options[ 'cff_event_title_link' ] = true;
839
840 update_option('cff_style_settings', $options);
841
842 get_option('cff_show_access_token');
843 update_option('cff_show_access_token', true);
844 }
845
846 public function cff_activation_plugin_redirect()
847 {
848 $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options';
849 if (!current_user_can($cap)) {
850 return false;
851 }
852
853 if (get_option('cff_plugin_do_activation_redirect', false)) {
854 delete_option('cff_plugin_do_activation_redirect');
855 wp_safe_redirect(admin_url('/admin.php?page=cff-setup'));
856 exit();
857 }
858 }
859
860
861 /**
862 * Deactivate
863 *
864 * CFF deactivation action.
865 *
866 * @since 2.19
867 * @access public
868 */
869 public function cff_deactivate()
870 {
871 wp_clear_scheduled_hook('cff_cron_job');
872 wp_clear_scheduled_hook('cff_notification_update');
873 wp_clear_scheduled_hook('cff_feed_issue_email');
874 wp_clear_scheduled_hook('cff_usage_tracking_cron');
875 }
876
877
878 /**
879 * Uninstall
880 *
881 * CFF uninstallation action.
882 *
883 * @since 2.19
884 * @access public
885 */
886 public static function cff_uninstall()
887 {
888 if (! current_user_can('activate_plugins')) {
889 return;
890 }
891 // If the user is preserving the settings then don't delete them
892 $cff_preserve_settings = get_option('cff_preserve_settings');
893 if (! empty($cff_preserve_settings)) {
894 return;
895 }
896
897 // Settings
898 delete_option('cff_show_access_token');
899 delete_option('cff_access_token');
900 delete_option('cff_page_id');
901 delete_option('cff_num_show');
902 delete_option('cff_post_limit');
903 delete_option('cff_show_others');
904 delete_option('cff_cache_time');
905 delete_option('cff_cache_time_unit');
906 delete_option('cff_locale');
907 delete_option('cff_ajax');
908 delete_option('cff_preserve_settings');
909 // Style & Layout
910 delete_option('cff_title_length');
911 delete_option('cff_body_length');
912 delete_option('cff_style_settings');
913
914 delete_option('cff_usage_tracking_config');
915 delete_option('cff_usage_tracking');
916
917 delete_option('cff_statuses');
918 delete_option('cff_rating_notice');
919 delete_option('cff_review_consent');
920 delete_option('cff_db_version');
921 delete_option('cff_newuser_notifications');
922 delete_option('cff_notifications');
923
924 delete_option('cff_legacy_feed_settings');
925 delete_option('cff_theme_styles');
926 delete_option('cff_caching_type');
927 delete_option('cff_oembed_token');
928
929 global $wp_roles;
930 $wp_roles->remove_cap('administrator', 'manage_custom_facebook_feed_options');
931
932 global $wpdb;
933 $locator_table_name = $wpdb->prefix . CFF_FEED_LOCATOR;
934 $wpdb->query("DROP TABLE IF EXISTS $locator_table_name");
935
936 $feeds_table_name = $wpdb->prefix . 'cff_feeds';
937 $wpdb->query("DROP TABLE IF EXISTS $feeds_table_name");
938
939 $feed_caches_table_name = $wpdb->prefix . 'cff_feed_caches';
940 $wpdb->query("DROP TABLE IF EXISTS $feed_caches_table_name");
941
942 $sources_table_name = $wpdb->prefix . 'cff_sources';
943 $wpdb->query("DROP TABLE IF EXISTS $sources_table_name");
944
945 $table_name = esc_sql($wpdb->prefix . "postmeta");
946 $result = $wpdb->query("
947 DELETE
948 FROM $table_name
949 WHERE meta_key = '_cff_oembed_done_checking';");
950
951 $usermeta_table_name = $wpdb->prefix . "usermeta";
952 $result = $wpdb->query("
953 DELETE
954 FROM $usermeta_table_name
955 WHERE meta_key LIKE ('cff\_%')
956 ");
957 }
958
959
960
961 /**
962 * Custom CSS
963 *
964 * Adding custom CSS
965 *
966 * @since 2.19
967 * @access public
968 * @deprecated
969 */
970 public function cff_custom_css()
971 {
972 }
973
974
975 /**
976 * Custom JS
977 *
978 * Adding custom JS
979 *
980 * @since 2.19
981 * @access public
982 */
983 public function cff_js()
984 {
985 $options = get_option('cff_style_settings');
986
987 // Link hashtags?
988 isset($options[ 'cff_link_hashtags' ]) ? $cff_link_hashtags = $options[ 'cff_link_hashtags' ] : $cff_link_hashtags = 'true';
989 ($cff_link_hashtags == 'true' || $cff_link_hashtags == 'on') ? $cff_link_hashtags = 'true' : $cff_link_hashtags = 'false';
990
991 // If linking the post text then don't link the hashtags
992 isset($options[ 'cff_title_link' ]) ? $cff_title_link = $options[ 'cff_title_link' ] : $cff_title_link = false;
993 ($cff_title_link == 'true' || $cff_title_link == 'on') ? $cff_title_link = true : $cff_title_link = false;
994 if ($cff_title_link) {
995 $cff_link_hashtags = 'false';
996 }
997
998 echo '<!-- Custom Facebook Feed JS -->';
999 echo "\r\n";
1000 echo '<script type="text/javascript">';
1001 echo 'var cffajaxurl = "' . admin_url('admin-ajax.php') . '";';
1002 echo "\r\n";
1003 echo 'var cfflinkhashtags = "' . $cff_link_hashtags . '";';
1004 echo "\r\n";
1005 echo '</script>';
1006 echo "\r\n";
1007 }
1008
1009
1010 /**
1011 * Cron Custom Interval
1012 *
1013 * Cron Job Custom Interval
1014 *
1015 * @since 2.19
1016 * @access public
1017 */
1018 public function cff_cron_custom_interval($schedules)
1019 {
1020 $schedules['cffweekly'] = array(
1021 'interval' => 3600 * 24 * 7,
1022 'display' => __('Weekly')
1023 );
1024 return $schedules;
1025 }
1026
1027 /**
1028 * Feed Locator Ajax Call
1029 *
1030 * @since 2.19
1031 * @access public
1032 */
1033 public function cff_feed_locator()
1034 {
1035
1036 $feed_locator_data_array = isset($_POST['feedLocatorData']) && !empty($_POST['feedLocatorData']) && is_array($_POST['feedLocatorData']) ? $_POST['feedLocatorData'] : false;
1037 if ($feed_locator_data_array != false) :
1038 foreach ($feed_locator_data_array as $single_feed_locator) {
1039 $can_do_background_tasks = false;
1040
1041 $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options';
1042 $cap = apply_filters('cff_settings_pages_capability', $cap);
1043 if (current_user_can($cap)) {
1044 $can_do_background_tasks = true;
1045 } else {
1046 $nonce = isset($_POST['locator_nonce']) ? sanitize_text_field(wp_unslash($_POST['locator_nonce'])) : '';
1047 if (isset($single_feed_locator['postID']) && wp_verify_nonce($nonce, esc_attr('cff-locator-nonce-' . $single_feed_locator['postID']))) {
1048 $can_do_background_tasks = true;
1049 }
1050 }
1051
1052 if ($can_do_background_tasks) {
1053 $feed_details = array(
1054 'feed_id' => $single_feed_locator['feedID'],
1055 'atts' => $single_feed_locator['shortCodeAtts'],
1056 'location' => array(
1057 'post_id' => $single_feed_locator['postID'],
1058 'html' => $single_feed_locator['location']
1059 )
1060 );
1061 $locator = new CFF_Feed_Locator($feed_details);
1062 $locator->add_or_update_entry();
1063 }
1064 }
1065 endif;
1066 die();
1067 }
1068
1069 /**
1070 * Detect Custom CSS Code
1071 *
1072 * @since ??
1073 * @access public
1074 */
1075 public function detect_custom_code()
1076 {
1077 // $cff_options = get_option( 'cff_style_settings' );
1078 // if( !empty( $cff_options[ 'cff_custom_css' ]) ){
1079 // $core_custom_css = wp_get_custom_css();
1080 // \WP_Customize_Custom_CSS_Setting
1081 // }
1082 }
1083
1084 /**
1085 * Summary of print_callout
1086 *
1087 * @return void
1088 */
1089 public function cff_print_callout()
1090 {
1091 if (is_user_logged_in()) {
1092 $current_user = wp_get_current_user();
1093 if (user_can($current_user, 'administrator')) {
1094 CFF_Callout::print_callout();
1095 }
1096 }
1097 }
1098 }
1099