Admin
2 weeks ago
Builder
2 weeks ago
Helpers
2 weeks ago
Integrations
2 weeks ago
CFF_Autolink.php
2 weeks ago
CFF_Blocks.php
2 weeks ago
CFF_Cache.php
2 weeks ago
CFF_Education.php
2 weeks ago
CFF_Elementor_Base.php
2 weeks ago
CFF_Elementor_Widget.php
2 weeks ago
CFF_Error_Reporter.php
2 weeks ago
CFF_FB_Settings.php
2 weeks ago
CFF_Feed_Elementor_Control.php
2 weeks ago
CFF_Feed_Locator.php
2 weeks ago
CFF_Feed_Pro.php
2 weeks ago
CFF_GDPR_Integrations.php
2 weeks ago
CFF_Group_Posts.php
2 weeks ago
CFF_HTTP_Request.php
2 weeks ago
CFF_Oembed.php
2 weeks ago
CFF_Parse.php
2 weeks ago
CFF_Resizer.php
2 weeks ago
CFF_Response.php
2 weeks ago
CFF_Shortcode.php
2 weeks ago
CFF_Shortcode_Display.php
2 weeks ago
CFF_SiteHealth.php
2 weeks ago
CFF_Utils.php
2 weeks ago
CFF_View.php
2 weeks ago
Custom_Facebook_Feed.php
2 weeks ago
Email_Notification.php
2 weeks ago
Platform_Data.php
2 weeks ago
SB_Facebook_Data_Encryption.php
2 weeks ago
SB_Facebook_Data_Manager.php
2 weeks ago
index.php
2 weeks ago
Custom_Facebook_Feed.php
1102 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 FacebookFeed\Vendor\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::register(); |
| 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 | $recommended_blocks = new \FacebookFeed\Vendor\Smashballoon\Framework\Packages\Blocks\RecommendedBlocks(); |
| 421 | $recommended_blocks->setup(); |
| 422 | |
| 423 | self::$instance->cff_support_tool = new CFF_Support_Tool(); |
| 424 | self::$instance->cff_divi_handler = new CFF_Divi_Handler(); |
| 425 | |
| 426 | if (is_admin()) { |
| 427 | $this->cff_tooltip_wizard = new Builder\CFF_Tooltip_Wizard(); |
| 428 | if (version_compare(PHP_VERSION, '5.3.0') >= 0 && version_compare(get_bloginfo('version'), '4.6', '>')) { |
| 429 | $this->cff_notifications = new CFF_Notifications(); |
| 430 | $this->cff_notifications->init(); |
| 431 | |
| 432 | $this->cff_newuser = new CFF_New_User(); |
| 433 | $this->cff_newuser->init(); |
| 434 | |
| 435 | require_once trailingslashit(CFF_PLUGIN_DIR) . 'admin/addon-functions.php'; |
| 436 | $this->cff_sitehealth = new CFF_SiteHealth(); |
| 437 | if ($this->cff_sitehealth->allow_load()) { |
| 438 | $this->cff_sitehealth->load(); |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | $this->platform_data_manager = new Platform_Data(); |
| 444 | $this->platform_data_manager->register_hooks(); |
| 445 | |
| 446 | |
| 447 | $this->cff_callout = new CFF_Callout(); |
| 448 | |
| 449 | self::$instance->cff_sb_analytics = new SB_Analytics(); |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * Launch the Group Posts Cache Process |
| 454 | * |
| 455 | * @return void |
| 456 | * @access public |
| 457 | */ |
| 458 | public function group_posts_process() |
| 459 | { |
| 460 | $cff_cron_schedule = 'hourly'; |
| 461 | $cff_cache_time = get_option('cff_cache_time'); |
| 462 | $cff_cache_time_unit = get_option('cff_cache_time_unit'); |
| 463 | if ($cff_cache_time_unit == 'hours' && $cff_cache_time > 5) { |
| 464 | $cff_cron_schedule = 'twicedaily'; |
| 465 | } |
| 466 | if ($cff_cache_time_unit == 'days') { |
| 467 | $cff_cron_schedule = 'daily'; |
| 468 | } |
| 469 | CFF_Group_Posts::group_schedule_event(time(), $cff_cron_schedule); |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Register Assets |
| 474 | * |
| 475 | * @since 2.19 |
| 476 | */ |
| 477 | public function register_assets() |
| 478 | { |
| 479 | add_action('wp_enqueue_scripts', array( $this, 'enqueue_styles_assets' )); |
| 480 | add_action('wp_enqueue_scripts', array( $this, 'enqueue_scripts_assets' )); |
| 481 | } |
| 482 | |
| 483 | |
| 484 | /** |
| 485 | * Enqueue & Register Styles |
| 486 | * |
| 487 | * @since 2.19 |
| 488 | */ |
| 489 | public function enqueue_styles_assets() |
| 490 | { |
| 491 | $options = get_option('cff_style_settings'); |
| 492 | |
| 493 | // Handles the minification of the plugin stylesheets |
| 494 | $cff_min = isset($_GET['sb_debug']) ? '' : '.min'; |
| 495 | |
| 496 | // Respects SSL, Style.css is relative to the current file |
| 497 | wp_register_style( |
| 498 | 'cff', |
| 499 | CFF_PLUGIN_URL . 'assets/css/cff-style' . $cff_min . '.css', |
| 500 | array(), |
| 501 | CFFVER |
| 502 | ); |
| 503 | |
| 504 | $options['cff_enqueue_with_shortcode'] = isset($options['cff_enqueue_with_shortcode']) ? $options['cff_enqueue_with_shortcode'] : false; |
| 505 | if (isset($options['cff_enqueue_with_shortcode']) && !$options['cff_enqueue_with_shortcode']) { |
| 506 | wp_enqueue_style('cff'); |
| 507 | } |
| 508 | |
| 509 | $options = get_option('cff_style_settings'); |
| 510 | |
| 511 | if (CFF_GDPR_Integrations::doing_gdpr($options)) { |
| 512 | $options[ 'cff_font_source' ] = 'local'; |
| 513 | } |
| 514 | if (!isset($options[ 'cff_font_source' ])) { |
| 515 | wp_enqueue_style('sb-font-awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'); |
| 516 | } else { |
| 517 | if ($options[ 'cff_font_source' ] == 'none') { |
| 518 | // Do nothing |
| 519 | } elseif ($options[ 'cff_font_source' ] == 'local') { |
| 520 | wp_enqueue_style( |
| 521 | 'sb-font-awesome', |
| 522 | CFF_PLUGIN_URL . 'assets/css/font-awesome.min.css', |
| 523 | array(), |
| 524 | '4.7.0' |
| 525 | ); |
| 526 | } else { |
| 527 | wp_enqueue_style('sb-font-awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'); |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | |
| 533 | /** |
| 534 | * Enqueue & Register Scripts |
| 535 | * |
| 536 | * @since 2.19 |
| 537 | * @access public |
| 538 | */ |
| 539 | public function enqueue_scripts_assets() |
| 540 | { |
| 541 | $options = get_option('cff_style_settings'); |
| 542 | |
| 543 | // Handles the minification of the plugin scripts |
| 544 | $cff_min = isset($_GET['sb_debug']) ? '' : '.min'; |
| 545 | |
| 546 | // Register the script to make it available |
| 547 | wp_register_script( |
| 548 | 'cffscripts', |
| 549 | CFF_PLUGIN_URL . 'assets/js/cff-scripts' . $cff_min . '.js', |
| 550 | array('jquery'), |
| 551 | CFFVER, |
| 552 | true |
| 553 | ); |
| 554 | $options['cff_enqueue_with_shortcode'] = isset($options['cff_enqueue_with_shortcode']) ? $options['cff_enqueue_with_shortcode'] : false; |
| 555 | if (isset($options['cff_enqueue_with_shortcode']) && !$options['cff_enqueue_with_shortcode']) { |
| 556 | wp_enqueue_script('cffscripts'); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | |
| 561 | /** |
| 562 | * DB Update Checker. |
| 563 | * |
| 564 | * Check for the db updates |
| 565 | * |
| 566 | * @since 2.19 |
| 567 | * @access public |
| 568 | */ |
| 569 | public function cff_check_for_db_updates() |
| 570 | { |
| 571 | $db_ver = get_option('cff_db_version', 0); |
| 572 | if ((float) $db_ver < 1.0) { |
| 573 | global $wp_roles; |
| 574 | $wp_roles->add_cap('administrator', 'manage_custom_facebook_feed_options'); |
| 575 | $cff_statuses_option = get_option('cff_statuses', array()); |
| 576 | if (! isset($cff_statuses_option['first_install'])) { |
| 577 | $options_set = get_option('cff_page_id', false); |
| 578 | if ($options_set) { |
| 579 | $cff_statuses_option['first_install'] = 'from_update'; |
| 580 | } else { |
| 581 | $cff_statuses_option['first_install'] = time(); |
| 582 | } |
| 583 | $cff_rating_notice_option = get_option('cff_rating_notice', false); |
| 584 | if ($cff_rating_notice_option === 'dismissed') { |
| 585 | $cff_statuses_option['rating_notice_dismissed'] = time(); |
| 586 | } |
| 587 | $cff_rating_notice_waiting = get_transient('custom_facebook_rating_notice_waiting'); |
| 588 | if ( |
| 589 | $cff_rating_notice_waiting === false |
| 590 | && $cff_rating_notice_option === false |
| 591 | ) { |
| 592 | $time = 2 * WEEK_IN_SECONDS; |
| 593 | set_transient('custom_facebook_rating_notice_waiting', 'waiting', $time); |
| 594 | update_option('cff_rating_notice', 'pending', false); |
| 595 | } |
| 596 | update_option('cff_statuses', $cff_statuses_option, false); |
| 597 | } |
| 598 | update_option('cff_db_version', CFF_DBVERSION); |
| 599 | } |
| 600 | if ((float) $db_ver < 1.1) { |
| 601 | if (! wp_next_scheduled('cff_feed_issue_email')) { |
| 602 | $timestamp = strtotime('next monday'); |
| 603 | $timestamp = $timestamp + (3600 * 24 * 7); |
| 604 | $six_am_local = $timestamp + CFF_Utils::cff_get_utc_offset() + (6 * 60 * 60); |
| 605 | wp_schedule_event($six_am_local, 'cffweekly', 'cff_feed_issue_email'); |
| 606 | } |
| 607 | update_option('cff_db_version', CFF_DBVERSION); |
| 608 | } |
| 609 | if ((float) $db_ver < 1.2) { |
| 610 | if (! wp_next_scheduled('cff_notification_update')) { |
| 611 | $timestamp = strtotime('next monday'); |
| 612 | $timestamp = $timestamp + (3600 * 24 * 7); |
| 613 | $six_am_local = $timestamp + CFF_Utils::cff_get_utc_offset() + (6 * 60 * 60); |
| 614 | |
| 615 | wp_schedule_event($six_am_local, 'cffweekly', 'cff_notification_update'); |
| 616 | } |
| 617 | update_option('cff_db_version', CFF_DBVERSION); |
| 618 | } |
| 619 | |
| 620 | if ((float) $db_ver < 1.3) { |
| 621 | CFF_Feed_Locator::create_table(); |
| 622 | update_option('cff_db_version', CFF_DBVERSION); |
| 623 | } |
| 624 | |
| 625 | if ((float) $db_ver < 1.4) { |
| 626 | Builder\CFF_Db::create_tables(); |
| 627 | update_option('cff_db_version', CFF_DBVERSION); |
| 628 | } |
| 629 | |
| 630 | // \CustomFacebookFeed\Builder\CFF_Db::reset_tables();\CustomFacebookFeed\Builder\CFF_Db::reset_db_update();die(); |
| 631 | |
| 632 | /** |
| 633 | * for 4.0 update |
| 634 | */ |
| 635 | if ((float) $db_ver < 2.1) { |
| 636 | $options = get_option('cff_style_settings', array()); |
| 637 | $legacy_at = get_option('cff_access_token'); |
| 638 | $options_support_legacy = false; // in case the locator table doesn't have any feeds in it but someone might be using legacy feeds |
| 639 | if (! empty($legacy_at)) { |
| 640 | $options_support_legacy = true; |
| 641 | \CustomFacebookFeed\Builder\CFF_Feed_Saver::set_legacy_feed_settings(); |
| 642 | } |
| 643 | |
| 644 | \CustomFacebookFeed\Builder\CFF_Db::create_tables(); |
| 645 | update_option('cff_db_version', CFF_DBVERSION); |
| 646 | |
| 647 | // are there existing feeds to toggle legacy onboarding? |
| 648 | $cff_statuses_option = get_option('cff_statuses', array()); |
| 649 | $cff_statuses_option['legacy_onboarding'] = array( |
| 650 | 'active' => false, |
| 651 | 'type' => 'single' |
| 652 | ); |
| 653 | |
| 654 | \CustomFacebookFeed\Builder\CFF_Source::set_legacy_source_queue(); |
| 655 | if (\CustomFacebookFeed\Builder\CFF_Source::should_do_source_updates()) { |
| 656 | \CustomFacebookFeed\Builder\CFF_Source::batch_process_legacy_source_queue(); |
| 657 | } |
| 658 | |
| 659 | \CustomFacebookFeed\Builder\CFF_Source::update_source_from_legacy_settings(); |
| 660 | |
| 661 | // how many legacy feeds? |
| 662 | $args = array( |
| 663 | 'html_location' => array( 'header', 'footer', 'sidebar', 'content', 'unknown' ), |
| 664 | 'group_by' => 'shortcode_atts', |
| 665 | 'page' => 1 |
| 666 | ); |
| 667 | $feeds_data = \CustomFacebookFeed\CFF_Feed_Locator::legacy_facebook_feed_locator_query($args); |
| 668 | $num_legacy = count($feeds_data); |
| 669 | |
| 670 | $cff_statuses_option['support_legacy_shortcode'] = false; |
| 671 | |
| 672 | if ($num_legacy > 0) { |
| 673 | if ($num_legacy > 1) { |
| 674 | $cff_statuses_option['legacy_onboarding'] = array( |
| 675 | 'active' => true, |
| 676 | 'type' => 'multiple' |
| 677 | ); |
| 678 | $cff_statuses_option['support_legacy_shortcode'] = true; |
| 679 | } else { |
| 680 | $cff_statuses_option['legacy_onboarding'] = array( |
| 681 | 'active' => true, |
| 682 | 'type' => 'single' |
| 683 | ); |
| 684 | |
| 685 | $shortcode_atts = $feeds_data[0]['shortcode_atts'] != '[""]' ? json_decode($feeds_data[0]['shortcode_atts'], true) : []; |
| 686 | $shortcode_atts = is_array($shortcode_atts) ? $shortcode_atts : array(); |
| 687 | |
| 688 | $cff_statuses_option['support_legacy_shortcode'] = $shortcode_atts; |
| 689 | |
| 690 | $settings_data = \CustomFacebookFeed\Builder\CFF_Post_Set::legacy_to_builder_convert($shortcode_atts); |
| 691 | |
| 692 | if (isset($settings_data['id'])) { |
| 693 | $source_ids = explode(',', str_replace(' ', '', $settings_data['id'])); |
| 694 | } else { |
| 695 | $source_ids = (array)get_option('cff_page_id', array()); |
| 696 | } |
| 697 | |
| 698 | $source_list = \CustomFacebookFeed\Builder\CFF_Feed_Builder::get_source_list(); |
| 699 | |
| 700 | $supported_sources = array(); |
| 701 | $feed_name = 'Existing Feed'; |
| 702 | foreach ($source_list as $source) { |
| 703 | if (in_array($source['account_id'], $source_ids, true)) { |
| 704 | $supported_sources[] = $source['account_id']; |
| 705 | $feed_name = $source['username']; |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | $feed_saver = new \CustomFacebookFeed\Builder\CFF_Feed_Saver(false); |
| 710 | $feed_saver->set_data($settings_data); |
| 711 | |
| 712 | $feed_saver->set_feed_name($feed_name); |
| 713 | |
| 714 | $new_feed_id = $feed_saver->update_or_insert(); |
| 715 | |
| 716 | $args = array( |
| 717 | 'new_feed_id' => $new_feed_id, |
| 718 | 'legacy_feed_id' => $feeds_data[0]['feed_id'], |
| 719 | ); |
| 720 | |
| 721 | CFF_Feed_Locator::update_legacy_to_builder($args); |
| 722 | } |
| 723 | } elseif ($num_legacy === 0 && $options_support_legacy) { |
| 724 | $cff_statuses_option['support_legacy_shortcode'] = true; |
| 725 | } |
| 726 | |
| 727 | update_option('cff_statuses', $cff_statuses_option); |
| 728 | } |
| 729 | |
| 730 | if ((float) $db_ver < 2.2) { |
| 731 | $manager = new SB_Facebook_Data_Manager(); |
| 732 | $manager->update_db_for_dpa(); |
| 733 | update_option('cff_db_version', CFF_DBVERSION); |
| 734 | } |
| 735 | |
| 736 | if (version_compare($db_ver, '2.4', '<')) { |
| 737 | update_option('cff_db_version', CFF_DBVERSION); |
| 738 | |
| 739 | $groups = \CustomFacebookFeed\Builder\CFF_Db::source_query(array( 'type' => 'group' )); |
| 740 | |
| 741 | $cff_statuses_option = get_option('cff_statuses', array()); |
| 742 | $cff_statuses_option['groups_need_update'] = false; |
| 743 | |
| 744 | if (empty($groups)) { |
| 745 | update_option('cff_statuses', $cff_statuses_option, false); |
| 746 | } else { |
| 747 | $encryption = new \CustomFacebookFeed\SB_Facebook_Data_Encryption(); |
| 748 | $groups_need_update = false; |
| 749 | foreach ($groups as $source) { |
| 750 | $info = ! empty($source['info']) ? json_decode($encryption->decrypt($source['info'])) : array(); |
| 751 | if (\CustomFacebookFeed\Builder\CFF_Source::needs_update($source, $info)) { |
| 752 | $groups_need_update = true; |
| 753 | } |
| 754 | } |
| 755 | $cff_statuses_option['groups_need_update'] = $groups_need_update; |
| 756 | update_option('cff_statuses', $cff_statuses_option, false); |
| 757 | } |
| 758 | |
| 759 | $cff_statuses_option['wizard_dismissed'] = false; |
| 760 | update_option('cff_statuses', $cff_statuses_option); |
| 761 | } |
| 762 | |
| 763 | if (version_compare($db_ver, '2.5', '<')) { |
| 764 | $cff_statuses_option = get_option('cff_statuses', array()); |
| 765 | if (!isset($cff_statuses_option['wizard_dismissed'])) { |
| 766 | $cff_statuses_option['wizard_dismissed'] = true; |
| 767 | update_option('cff_statuses', $cff_statuses_option); |
| 768 | } |
| 769 | update_option('cff_db_version', CFF_DBVERSION); |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | |
| 774 | /** |
| 775 | * Activate |
| 776 | * |
| 777 | * CFF activation action. |
| 778 | * |
| 779 | * @since 2.19 |
| 780 | * @access public |
| 781 | */ |
| 782 | public function cff_activate() |
| 783 | { |
| 784 | $options = get_option('cff_style_settings', array()); |
| 785 | |
| 786 | // Run cron twice daily when plugin is first activated for new users |
| 787 | if (! wp_next_scheduled('cff_cron_job')) { |
| 788 | wp_schedule_event(time(), 'twicedaily', 'cff_cron_job'); |
| 789 | } |
| 790 | if (! wp_next_scheduled('cff_feed_issue_email')) { |
| 791 | CFF_Utils::cff_schedule_report_email(); |
| 792 | } |
| 793 | // set usage tracking to false if fresh install. |
| 794 | $usage_tracking = get_option('cff_usage_tracking', false); |
| 795 | |
| 796 | if (! is_array($usage_tracking)) { |
| 797 | $usage_tracking = array( |
| 798 | 'enabled' => false, |
| 799 | 'last_send' => 0 |
| 800 | ); |
| 801 | update_option('cff_usage_tracking', $usage_tracking, false); |
| 802 | } |
| 803 | |
| 804 | if (! wp_next_scheduled('cff_notification_update')) { |
| 805 | $timestamp = strtotime('next monday'); |
| 806 | $timestamp = $timestamp + (3600 * 24 * 7); |
| 807 | $six_am_local = $timestamp + CFF_Utils::cff_get_utc_offset() + (6 * 60 * 60); |
| 808 | wp_schedule_event($six_am_local, 'cffweekly', 'cff_notification_update'); |
| 809 | } |
| 810 | |
| 811 | $cff_statuses_option = get_option('cff_statuses', array()); |
| 812 | if (!isset($cff_statuses_option['wizard_dismissed']) || $cff_statuses_option['wizard_dismissed'] === false) { |
| 813 | add_option('cff_plugin_do_activation_redirect', true); |
| 814 | } |
| 815 | |
| 816 | if (! empty($options)) { |
| 817 | return; |
| 818 | } |
| 819 | |
| 820 | // Show all post types |
| 821 | $options[ 'cff_show_links_type' ] = true; |
| 822 | $options[ 'cff_show_event_type' ] = true; |
| 823 | $options[ 'cff_show_video_type' ] = true; |
| 824 | $options[ 'cff_show_photos_type' ] = true; |
| 825 | $options[ 'cff_show_status_type' ] = true; |
| 826 | $options[ 'cff_show_albums_type' ] = true; |
| 827 | $options[ 'cff_show_author' ] = true; |
| 828 | $options[ 'cff_show_text' ] = true; |
| 829 | $options[ 'cff_show_desc' ] = true; |
| 830 | $options[ 'cff_show_shared_links' ] = true; |
| 831 | $options[ 'cff_show_date' ] = true; |
| 832 | $options[ 'cff_show_media' ] = true; |
| 833 | $options[ 'cff_show_media_link' ] = true; |
| 834 | $options[ 'cff_show_event_title' ] = true; |
| 835 | $options[ 'cff_show_event_details' ] = true; |
| 836 | $options[ 'cff_show_meta' ] = true; |
| 837 | $options[ 'cff_show_link' ] = true; |
| 838 | $options[ 'cff_show_like_box' ] = true; |
| 839 | $options[ 'cff_show_facebook_link' ] = true; |
| 840 | $options[ 'cff_show_facebook_share' ] = true; |
| 841 | $options[ 'cff_event_title_link' ] = true; |
| 842 | |
| 843 | update_option('cff_style_settings', $options); |
| 844 | |
| 845 | get_option('cff_show_access_token'); |
| 846 | update_option('cff_show_access_token', true); |
| 847 | } |
| 848 | |
| 849 | public function cff_activation_plugin_redirect() |
| 850 | { |
| 851 | $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options'; |
| 852 | if (!current_user_can($cap)) { |
| 853 | return false; |
| 854 | } |
| 855 | |
| 856 | if (get_option('cff_plugin_do_activation_redirect', false)) { |
| 857 | delete_option('cff_plugin_do_activation_redirect'); |
| 858 | wp_safe_redirect(admin_url('/admin.php?page=cff-setup')); |
| 859 | exit(); |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | |
| 864 | /** |
| 865 | * Deactivate |
| 866 | * |
| 867 | * CFF deactivation action. |
| 868 | * |
| 869 | * @since 2.19 |
| 870 | * @access public |
| 871 | */ |
| 872 | public function cff_deactivate() |
| 873 | { |
| 874 | wp_clear_scheduled_hook('cff_cron_job'); |
| 875 | wp_clear_scheduled_hook('cff_notification_update'); |
| 876 | wp_clear_scheduled_hook('cff_feed_issue_email'); |
| 877 | wp_clear_scheduled_hook('cff_usage_tracking_cron'); |
| 878 | } |
| 879 | |
| 880 | |
| 881 | /** |
| 882 | * Uninstall |
| 883 | * |
| 884 | * CFF uninstallation action. |
| 885 | * |
| 886 | * @since 2.19 |
| 887 | * @access public |
| 888 | */ |
| 889 | public static function cff_uninstall() |
| 890 | { |
| 891 | if (! current_user_can('activate_plugins')) { |
| 892 | return; |
| 893 | } |
| 894 | // If the user is preserving the settings then don't delete them |
| 895 | $cff_preserve_settings = get_option('cff_preserve_settings'); |
| 896 | if (! empty($cff_preserve_settings)) { |
| 897 | return; |
| 898 | } |
| 899 | |
| 900 | // Settings |
| 901 | delete_option('cff_show_access_token'); |
| 902 | delete_option('cff_access_token'); |
| 903 | delete_option('cff_page_id'); |
| 904 | delete_option('cff_num_show'); |
| 905 | delete_option('cff_post_limit'); |
| 906 | delete_option('cff_show_others'); |
| 907 | delete_option('cff_cache_time'); |
| 908 | delete_option('cff_cache_time_unit'); |
| 909 | delete_option('cff_locale'); |
| 910 | delete_option('cff_ajax'); |
| 911 | delete_option('cff_preserve_settings'); |
| 912 | // Style & Layout |
| 913 | delete_option('cff_title_length'); |
| 914 | delete_option('cff_body_length'); |
| 915 | delete_option('cff_style_settings'); |
| 916 | |
| 917 | delete_option('cff_usage_tracking_config'); |
| 918 | delete_option('cff_usage_tracking'); |
| 919 | |
| 920 | delete_option('cff_statuses'); |
| 921 | delete_option('cff_rating_notice'); |
| 922 | delete_option('cff_review_consent'); |
| 923 | delete_option('cff_db_version'); |
| 924 | delete_option('cff_newuser_notifications'); |
| 925 | delete_option('cff_notifications'); |
| 926 | |
| 927 | delete_option('cff_legacy_feed_settings'); |
| 928 | delete_option('cff_theme_styles'); |
| 929 | delete_option('cff_caching_type'); |
| 930 | delete_option('cff_oembed_token'); |
| 931 | |
| 932 | global $wp_roles; |
| 933 | $wp_roles->remove_cap('administrator', 'manage_custom_facebook_feed_options'); |
| 934 | |
| 935 | global $wpdb; |
| 936 | $locator_table_name = $wpdb->prefix . CFF_FEED_LOCATOR; |
| 937 | $wpdb->query("DROP TABLE IF EXISTS $locator_table_name"); |
| 938 | |
| 939 | $feeds_table_name = $wpdb->prefix . 'cff_feeds'; |
| 940 | $wpdb->query("DROP TABLE IF EXISTS $feeds_table_name"); |
| 941 | |
| 942 | $feed_caches_table_name = $wpdb->prefix . 'cff_feed_caches'; |
| 943 | $wpdb->query("DROP TABLE IF EXISTS $feed_caches_table_name"); |
| 944 | |
| 945 | $sources_table_name = $wpdb->prefix . 'cff_sources'; |
| 946 | $wpdb->query("DROP TABLE IF EXISTS $sources_table_name"); |
| 947 | |
| 948 | $table_name = esc_sql($wpdb->prefix . "postmeta"); |
| 949 | $result = $wpdb->query(" |
| 950 | DELETE |
| 951 | FROM $table_name |
| 952 | WHERE meta_key = '_cff_oembed_done_checking';"); |
| 953 | |
| 954 | $usermeta_table_name = $wpdb->prefix . "usermeta"; |
| 955 | $result = $wpdb->query(" |
| 956 | DELETE |
| 957 | FROM $usermeta_table_name |
| 958 | WHERE meta_key LIKE ('cff\_%') |
| 959 | "); |
| 960 | } |
| 961 | |
| 962 | |
| 963 | |
| 964 | /** |
| 965 | * Custom CSS |
| 966 | * |
| 967 | * Adding custom CSS |
| 968 | * |
| 969 | * @since 2.19 |
| 970 | * @access public |
| 971 | * @deprecated |
| 972 | */ |
| 973 | public function cff_custom_css() |
| 974 | { |
| 975 | } |
| 976 | |
| 977 | |
| 978 | /** |
| 979 | * Custom JS |
| 980 | * |
| 981 | * Adding custom JS |
| 982 | * |
| 983 | * @since 2.19 |
| 984 | * @access public |
| 985 | */ |
| 986 | public function cff_js() |
| 987 | { |
| 988 | $options = get_option('cff_style_settings'); |
| 989 | |
| 990 | // Link hashtags? |
| 991 | isset($options[ 'cff_link_hashtags' ]) ? $cff_link_hashtags = $options[ 'cff_link_hashtags' ] : $cff_link_hashtags = 'true'; |
| 992 | ($cff_link_hashtags == 'true' || $cff_link_hashtags == 'on') ? $cff_link_hashtags = 'true' : $cff_link_hashtags = 'false'; |
| 993 | |
| 994 | // If linking the post text then don't link the hashtags |
| 995 | isset($options[ 'cff_title_link' ]) ? $cff_title_link = $options[ 'cff_title_link' ] : $cff_title_link = false; |
| 996 | ($cff_title_link == 'true' || $cff_title_link == 'on') ? $cff_title_link = true : $cff_title_link = false; |
| 997 | if ($cff_title_link) { |
| 998 | $cff_link_hashtags = 'false'; |
| 999 | } |
| 1000 | |
| 1001 | echo '<!-- Custom Facebook Feed JS -->'; |
| 1002 | echo "\r\n"; |
| 1003 | echo '<script type="text/javascript">'; |
| 1004 | echo 'var cffajaxurl = "' . admin_url('admin-ajax.php') . '";'; |
| 1005 | echo "\r\n"; |
| 1006 | echo 'var cfflinkhashtags = "' . $cff_link_hashtags . '";'; |
| 1007 | echo "\r\n"; |
| 1008 | echo '</script>'; |
| 1009 | echo "\r\n"; |
| 1010 | } |
| 1011 | |
| 1012 | |
| 1013 | /** |
| 1014 | * Cron Custom Interval |
| 1015 | * |
| 1016 | * Cron Job Custom Interval |
| 1017 | * |
| 1018 | * @since 2.19 |
| 1019 | * @access public |
| 1020 | */ |
| 1021 | public function cff_cron_custom_interval($schedules) |
| 1022 | { |
| 1023 | $schedules['cffweekly'] = array( |
| 1024 | 'interval' => 3600 * 24 * 7, |
| 1025 | 'display' => __('Weekly') |
| 1026 | ); |
| 1027 | return $schedules; |
| 1028 | } |
| 1029 | |
| 1030 | /** |
| 1031 | * Feed Locator Ajax Call |
| 1032 | * |
| 1033 | * @since 2.19 |
| 1034 | * @access public |
| 1035 | */ |
| 1036 | public function cff_feed_locator() |
| 1037 | { |
| 1038 | |
| 1039 | $feed_locator_data_array = isset($_POST['feedLocatorData']) && !empty($_POST['feedLocatorData']) && is_array($_POST['feedLocatorData']) ? $_POST['feedLocatorData'] : false; |
| 1040 | if ($feed_locator_data_array != false) : |
| 1041 | foreach ($feed_locator_data_array as $single_feed_locator) { |
| 1042 | $can_do_background_tasks = false; |
| 1043 | |
| 1044 | $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options'; |
| 1045 | $cap = apply_filters('cff_settings_pages_capability', $cap); |
| 1046 | if (current_user_can($cap)) { |
| 1047 | $can_do_background_tasks = true; |
| 1048 | } else { |
| 1049 | $nonce = isset($_POST['locator_nonce']) ? sanitize_text_field(wp_unslash($_POST['locator_nonce'])) : ''; |
| 1050 | if (isset($single_feed_locator['postID']) && wp_verify_nonce($nonce, esc_attr('cff-locator-nonce-' . $single_feed_locator['postID']))) { |
| 1051 | $can_do_background_tasks = true; |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | if ($can_do_background_tasks) { |
| 1056 | $feed_details = array( |
| 1057 | 'feed_id' => $single_feed_locator['feedID'], |
| 1058 | 'atts' => $single_feed_locator['shortCodeAtts'], |
| 1059 | 'location' => array( |
| 1060 | 'post_id' => $single_feed_locator['postID'], |
| 1061 | 'html' => $single_feed_locator['location'] |
| 1062 | ) |
| 1063 | ); |
| 1064 | $locator = new CFF_Feed_Locator($feed_details); |
| 1065 | $locator->add_or_update_entry(); |
| 1066 | } |
| 1067 | } |
| 1068 | endif; |
| 1069 | die(); |
| 1070 | } |
| 1071 | |
| 1072 | /** |
| 1073 | * Detect Custom CSS Code |
| 1074 | * |
| 1075 | * @since ?? |
| 1076 | * @access public |
| 1077 | */ |
| 1078 | public function detect_custom_code() |
| 1079 | { |
| 1080 | // $cff_options = get_option( 'cff_style_settings' ); |
| 1081 | // if( !empty( $cff_options[ 'cff_custom_css' ]) ){ |
| 1082 | // $core_custom_css = wp_get_custom_css(); |
| 1083 | // \WP_Customize_Custom_CSS_Setting |
| 1084 | // } |
| 1085 | } |
| 1086 | |
| 1087 | /** |
| 1088 | * Summary of print_callout |
| 1089 | * |
| 1090 | * @return void |
| 1091 | */ |
| 1092 | public function cff_print_callout() |
| 1093 | { |
| 1094 | if (is_user_logged_in()) { |
| 1095 | $current_user = wp_get_current_user(); |
| 1096 | if (user_can($current_user, 'administrator')) { |
| 1097 | CFF_Callout::print_callout(); |
| 1098 | } |
| 1099 | } |
| 1100 | } |
| 1101 | } |
| 1102 |