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