<?php

/**
 * Plugin Name: Simple Giveaways
 * Plugin URI:  http://www.wpsimplegiveaways.com
 * Description: Create beautiful giveaways and grow your email list and business.
 * Version:     2.50.0
 * Author:      Igor Benic
 * Author URI:  http://ibenic.com
 * License:     GPL2
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Domain Path: /languages
 * Text Domain: giveasap
 * PHP version 5.6
 *
 * @category Plugin
 * @package  WordPress
 * @author   Igor Benić <i.benic@hotmail.com>
 * @license  GPL2 https://www.gnu.org/licenses/gpl-2.0.html
 * @link     http://ibenic.com
 *
 */
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
if ( function_exists( 'giv_fs' ) ) {
    giv_fs()->set_basename( false, __FILE__ );
    return;
}
if ( !function_exists( 'giv_fs' ) ) {
    // Create a helper function for easy SDK access.
    function giv_fs() {
        global $giv_fs;
        if ( !isset( $giv_fs ) ) {
            // Include Freemius SDK.
            require_once dirname( __FILE__ ) . '/freemius/start.php';
            $fs_config = array(
                'id'                  => '396',
                'slug'                => 'giveasap',
                'type'                => 'plugin',
                'public_key'          => 'pk_c3503a67ed0a3814e2a092853633c',
                'is_premium'          => true,
                'premium_suffix'      => 'Premium',
                'has_premium_version' => true,
                'has_addons'          => false,
                'has_paid_plans'      => true,
                'has_affiliation'     => 'selected',
                'menu'                => array(
                    'slug'        => 'edit.php?post_type=giveasap',
                    'contact'     => false,
                    'support'     => false,
                    'affiliation' => true,
                ),
            );
            if ( defined( 'FS_SECRET_KEY' ) ) {
                $fs_config['secret_key'] = FS_SECRET_KEY;
            }
            $giv_fs = fs_dynamic_init( $fs_config );
        }
        return $giv_fs;
    }

}
// Init Freemius.
giv_fs();
do_action( 'giv_fs_loaded' );
if ( !class_exists( 'GiveASAP' ) ) {
    define( 'GASAP_ROOT', plugin_dir_path( __FILE__ ) );
    define( 'GASAP_URI', plugin_dir_url( __FILE__ ) );
    /**
     * Load plugin textdomain.
     *
     * @return void
     */
    function giveasap_load_textdomain() {
        load_plugin_textdomain( 'giveasap', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
    }

    add_action( 'init', 'giveasap_load_textdomain' );
    /**
     * The constructor Single-ton class that contains every information
     *
     * @category Plugin
     * @package  WordPress
     * @author   Igor Benić <i.benic@hotmail.com>
     * @license  GPL2 https://www.gnu.org/licenses/gpl-2.0.html
     * @link     http://ibenic.com
     */
    class GiveASAP {
        /**
         * Plugin Version
         *
         * @var string
         */
        private $version = '2.50.0';

        /**
         * Instance
         *
         * @var null|GiveASAP
         */
        private static $_instance = null;

        /**
         * Meta object to operate with meta
         *
         * @var null
         */
        public $meta = null;

        /**
         * Settings holder
         *
         * @since  2.4.0
         * @var null
         */
        public $settings = null;

        /**
         * Giveaway Integrations
         *
         * @var array
         */
        public $integrations = array();

        /**
         * Disabling the contructor method
         */
        private function __construct() {
        }

        /**
         * Returns the version of GiveASAP
         *
         * @return string
         */
        public function version() {
            return $this->version;
        }

        /**
         * Getting the instance of this class
         * If there is no instance, it will create one
         *
         * @return GiveASAP
         */
        public static function getInstance() {
            if ( null === static::$_instance ) {
                static::$_instance = new static();
            }
            return static::$_instance;
        }

        /**
         * Return the settings
         *
         * @since  2.4.0
         * @return array
         */
        public function get_settings() {
            if ( !$this->settings ) {
                $this->settings = get_option( 'giveasap_settings', array() );
                if ( !isset( $this->settings['google_site_key'] ) ) {
                    $this->settings['google_site_key'] = false;
                }
                if ( !isset( $this->settings['google_secret_key'] ) ) {
                    $this->settings['google_secret_key'] = false;
                }
            }
            return $this->settings;
        }

        /**
         * Running Admin dependencies we need for this plugin
         *
         * @return void
         */
        public function run_admin_dependencies() {
            include_once GASAP_ROOT . '/admin/class-ga-column.php';
            include_once GASAP_ROOT . '/admin/documentation/screens.php';
            include_once GASAP_ROOT . '/admin/classes/class-ga-users-table.php';
            include_once GASAP_ROOT . '/admin/classes/class-sg-subscriber-entries-table.php';
            include_once GASAP_ROOT . '/admin/ajax.php';
            include_once GASAP_ROOT . '/admin/class-sg-dashboard-widget.php';
            include_once GASAP_ROOT . '/admin/class-sg-permalink-settings.php';
        }

        /**
         * Running all admin functions and including files
         *
         * @return void
         */
        public function run_admin() {
            if ( !is_admin() ) {
                return;
            }
            add_action( 'load-post.php', array($this, 'run_admin_on_post') );
            add_action( 'load-post-new.php', array($this, 'run_admin_on_post') );
            add_action(
                'save_post',
                'giveasap_reset_giveaway_leaderboard_transient_on_save',
                20,
                2
            );
            new \Simple_Giveaways\SG_Dashboard_Widget();
            include_once GASAP_ROOT . '/includes/class-menu.php';
            include_once GASAP_ROOT . '/admin/custom-metabox.php';
            include_once GASAP_ROOT . '/admin/admin-screens.php';
        }

        /**
         * Running Admin files on the GiveASAP CPT
         *
         * @return void
         */
        public function run_admin_on_post() {
            require_once GASAP_ROOT . '/admin/giveasap-cpt-metabox.php';
            require_once GASAP_ROOT . '/admin/giveasap-cpt-schedule.php';
        }

        /**
         * Running all hooks and filters
         *
         * @return void
         */
        public function run_actions() {
            global $wp_version;
            add_action( 'admin_enqueue_scripts', array($this, 'admin_enqueue_scripts') );
            add_filter( 'giveasap_the_content', 'wptexturize' );
            add_filter( 'giveasap_the_content', 'convert_smilies', 20 );
            add_filter( 'giveasap_the_content', 'wpautop' );
            add_filter( 'giveasap_the_content', 'shortcode_unautop' );
            add_filter( 'giveasap_the_content', 'prepend_attachment' );
            if ( version_compare( $wp_version, '5.5.0', '>=' ) ) {
                add_filter( 'giveasap_the_content', 'wp_filter_content_tags' );
            } else {
                add_filter( 'giveasap_the_content', 'wp_make_content_images_responsive' );
            }
            add_filter( 'giveasap_the_content', 'do_shortcode', 11 );
            if ( isset( $GLOBALS['wp_embed'] ) ) {
                add_filter( 'giveasap_the_content', array($GLOBALS['wp_embed'], 'run_shortcode'), 8 );
                add_filter( 'giveasap_the_content', array($GLOBALS['wp_embed'], 'autoembed'), 8 );
            }
            add_filter( 'embed_oembed_html', array($this, 'html_video_wrapper'), 10 );
            add_action( 'widgets_init', array($this, 'register_widgets') );
            add_action( 'init', array($this, 'check_versions') );
            add_action( 'init', 'giveasap_maybe_unsubscribe_from_email' );
            add_action( 'plugins_loaded', array($this, 'load_integrations'), 49 );
            add_filter( 'giveasap_sharing_methods', array($this, 'set_sharing_methods') );
            add_action( 'wp_enqueue_scripts', array($this, 'front_enqueue_scripts') );
            if ( class_exists( '\\Simple_Giveaways\\SG_Categories' ) ) {
                $sg_category = new \Simple_Giveaways\SG_Categories();
                add_action( 'init', array($sg_category, 'register') );
            }
            new \Simple_Giveaways\SG_Blocks();
            new \Simple_Giveaways\SG_Extra_Actions();
            new \Simple_Giveaways\SG_Customizer();
            new \Simple_Giveaways\Prizes();
        }

        /**
         * Loading Integrations
         */
        public function load_integrations() {
            $active_integrations = get_option( 'giveasap_active_integrations', array() );
            $integrations = giveasap_get_integrations();
            foreach ( $active_integrations as $slug => $integration ) {
                if ( !isset( $integrations[$slug] ) ) {
                    continue;
                }
                // Adding Integration class registered through filters priority.
                // In case the database record differentiate from the filtered one.
                if ( class_exists( $integrations[$slug] ) ) {
                    $integration = $integrations[$slug];
                }
                if ( class_exists( $integration ) ) {
                    $this->integrations[$slug] = new $integration();
                }
            }
        }

        /**
         * Checking for version, updating if necessary
         *
         * @return void
         */
        public function check_versions() {
            if ( !defined( 'IFRAME_REQUEST' ) && get_option( 'giveasap_version', '1.4' ) !== $this->version() ) {
                delete_option( 'sg_about_page_was_read' );
                $installer = new \Simple_Giveaways\GA_Installer();
                $installer->install();
                $installer->update( get_option( 'giveasap_version', '1.4' ) );
                do_action( 'giveasap_updated' );
            }
        }

        /**
         * Video Wrapper for embedded content
         *
         * @param  string $html
         *
         * @return string
         */
        public function html_video_wrapper( $html ) {
            $return = '<div class="giveasap-video-container">' . $html . '</div>';
            return $return;
        }

        /**
         * Running only public actions
         *
         * @return void
         */
        public function run_public_actions() {
            if ( is_admin() ) {
                return;
            }
            add_filter( 'template_include', array($this, 'giveasap_template') );
            add_action( 'init', array($this, 'check_for_widget') );
            add_action( 'init', array($this, 'check_for_sg_actions') );
        }

        /**
         * Check and allow for specific SG actions.
         */
        public function check_for_sg_actions() {
            if ( isset( $_POST['sg_action'] ) ) {
                do_action( 'sg_action_' . \Simple_Giveaways\Helpers::unslash_and_clean( $_POST['sg_action'] ) );
            }
        }

        /**
         * Check if the Widget is Active to Enqueue scripts
         *
         * @return void
         */
        public function check_for_widget() {
            if ( is_active_widget( false, false, 'giveasap_widget' ) ) {
                wp_enqueue_style(
                    'sg-shortcode',
                    GASAP_URI . 'assets/dist/css/shortcode.css',
                    array(),
                    $this->version()
                );
                $this->enqueue_scripts();
            }
        }

        /**
         * Load Scripts.
         */
        public function load_scripts( $front = false ) {
            if ( !wp_script_is( 'jquery' ) ) {
                wp_deregister_script( 'jquery' );
                wp_register_script(
                    'jquery',
                    includes_url( '/js/jquery/jquery.js' ),
                    false,
                    null,
                    true
                );
                wp_enqueue_script( 'jquery' );
            }
            $this->enqueue_scripts();
        }

        /**
         * Front Enqueue Scripts
         */
        public function front_enqueue_scripts() {
            global $post;
            $version = $this->version();
            if ( $post && has_shortcode( $post->post_content, 'giveaway_archive' ) ) {
                wp_enqueue_style(
                    'sg-archive',
                    GASAP_URI . 'assets/dist/css/archive.css',
                    array(),
                    $version
                );
                $this->enqueue_scripts();
            }
            $shortcodes = array(
                'giveaway',
                'giveaway_popup',
                'giveaway_winners',
                'giveaway_leaderboard'
            );
            if ( $post ) {
                foreach ( $shortcodes as $shortcode ) {
                    if ( has_shortcode( $post->post_content, $shortcode ) ) {
                        wp_enqueue_style(
                            'sg-shortcode',
                            GASAP_URI . 'assets/dist/css/shortcode.css',
                            array(),
                            $version
                        );
                        $this->enqueue_scripts();
                        break;
                        // 1 is needed.
                    }
                }
                if ( function_exists( 'has_block' ) ) {
                    if ( has_block( 'simple-giveaways/giveaway', $post ) || has_block( 'simple-giveaways/countdown', $post ) ) {
                        wp_enqueue_style(
                            'sg-blocks',
                            GASAP_URI . 'assets/dist/css/gutenberg.css',
                            array(),
                            $version
                        );
                        $this->enqueue_scripts();
                    }
                }
            }
        }

        /**
         * Enqueue the Simple Giveaways Scripts.
         */
        public function enqueue_scripts() {
            // Check if we enqueued it already.
            if ( !wp_script_is( 'sg-js' ) ) {
                $version = $this->version();
                wp_enqueue_script(
                    'sg-jquery',
                    GASAP_URI . 'assets/js/jquery.plugin.min.js',
                    array('jquery'),
                    $version,
                    true
                );
                wp_enqueue_script(
                    'sg-countdown',
                    GASAP_URI . 'assets/js/jquery.countdown.min.js',
                    array('jquery'),
                    $version,
                    true
                );
                $locale = get_locale();
                if ( 'en_US' !== $locale && 'en_EN' !== $locale ) {
                    if ( file_exists( GASAP_ROOT . 'assets/js/l10n/' . $locale . '.js' ) ) {
                        wp_enqueue_script(
                            'giveasap-jquery-lang',
                            GASAP_URI . 'assets/js/l10n/' . $locale . '.js',
                            array('jquery'),
                            $this->version,
                            true
                        );
                    } else {
                        $settings = giveasap_get_settings();
                        if ( isset( $settings['countdown_lang_url'] ) && $settings['countdown_lang_url'] ) {
                            wp_enqueue_script(
                                'sg-locale-' . $locale,
                                $settings['countdown_lang_url'],
                                '',
                                $version,
                                true
                            );
                        }
                    }
                }
                wp_enqueue_script(
                    'sg-js',
                    GASAP_URI . 'assets/dist/js/giveasap.js',
                    array('jquery'),
                    $this->version,
                    true
                );
                wp_localize_script( 'sg-js', 'sg', $this->get_localized_array() );
            }
        }

        /**
         * Get the localized array.
         *
         * @param bool $front
         *
         * @return array
         */
        public function get_localized_array() {
            $array = array(
                'nonce'   => wp_create_nonce( 'giveaway' ),
                'ajaxurl' => admin_url( 'admin-ajax.php' ),
                'text'    => array(
                    'accept_terms' => __( 'Please accept terms and conditions', 'giveasap' ),
                    'countdown'    => array(
                        'labels'        => array(
                            'years'   => _x( 'Years', 'Plural Period in Countdown', 'giveasap' ),
                            'months'  => _x( 'Months', 'Plural Period in Countdown', 'giveasap' ),
                            'weeks'   => _x( 'Weeks', 'Plural Period in Countdown', 'giveasap' ),
                            'days'    => _x( 'Days', 'Plural Period in Countdown', 'giveasap' ),
                            'hours'   => _x( 'Hours', 'Plural Period in Countdown', 'giveasap' ),
                            'minutes' => _x( 'Minutes', 'Plural Period in Countdown', 'giveasap' ),
                            'seconds' => _x( 'Seconds', 'Plural Period in Countdown', 'giveasap' ),
                        ),
                        'labels1'       => array(
                            'year'   => _x( 'Year', 'Singular Period in Countdown', 'giveasap' ),
                            'month'  => _x( 'Month', 'Singular Period in Countdown', 'giveasap' ),
                            'week'   => _x( 'Week', 'Singular Period in Countdown', 'giveasap' ),
                            'day'    => _x( 'Day', 'Singular Period in Countdown', 'giveasap' ),
                            'hour'   => _x( 'Hour', 'Singular Period in Countdown', 'giveasap' ),
                            'minute' => _x( 'Minute', 'Singular Period in Countdown', 'giveasap' ),
                            'second' => _x( 'Second', 'Singular Period in Countdown', 'giveasap' ),
                        ),
                        'compactLabels' => array(
                            'y' => _x( 'y', 'Compact label for Year in Countdown', 'giveasap' ),
                            'm' => _x( 'm', 'Compact label for Month in Countdown', 'giveasap' ),
                            'w' => _x( 'w', 'Compact label for Week in Countdown', 'giveasap' ),
                            'd' => _x( 'd', 'Compact label for Day in Countdown', 'giveasap' ),
                        ),
                    ),
                ),
            );
            return apply_filters( 'sg_localized_array', $array );
        }

        /**
         * Registering Widgets
         *
         * @return void
         */
        public function register_widgets() {
            register_widget( 'GiveASAP_Widget' );
        }

        /**
         * Returning the GiveASAP template
         *
         * @param  string $template Part of a GiveASAP template
         *
         * @return string
         */
        public function giveasap_template( $template ) {
            if ( !is_admin() && is_singular( 'giveasap' ) ) {
                $new_template = $this->locate_template( array('giveasap_template.php') );
                // Filtering the template path to be used in extensions
                $new_template = apply_filters( 'giveasap_template_path', $new_template );
                if ( file_exists( $new_template ) ) {
                    return $new_template;
                }
            }
            return $template;
        }

        /**
         * Template Paths.
         *
         * @return array
         */
        protected function get_theme_template_paths() {
            $file_paths = array(
                1   => trailingslashit( get_stylesheet_directory() ) . 'giveaways',
                10  => trailingslashit( get_template_directory() ) . 'giveaways',
                100 => GASAP_ROOT . '/public/',
            );
            $file_paths = apply_filters( 'sg_template_paths', $file_paths );
            ksort( $file_paths, SORT_NUMERIC );
            return array_map( 'trailingslashit', $file_paths );
        }

        /***
         * @param array $template_names
         * @param bool  $load
         * @param bool  $require_once
         *
         * @return bool|string
         */
        public function locate_template( $template_names, $load = false, $require_once = true ) {
            // No file found yet
            $located = false;
            // Try to find a template file
            foreach ( (array) $template_names as $template_name ) {
                // Continue if template is empty
                if ( empty( $template_name ) ) {
                    continue;
                }
                // Trim off any slashes from the template name
                $template_name = ltrim( $template_name, '/' );
                // try locating this template file by looping through the template paths
                foreach ( $this->get_theme_template_paths() as $template_path ) {
                    if ( file_exists( $template_path . $template_name ) ) {
                        $located = $template_path . $template_name;
                        break;
                    }
                }
                if ( $located ) {
                    break;
                }
            }
            if ( true === $load && !empty( $located ) ) {
                load_template( $located, $require_once );
            }
            return $located;
        }

        /**
         * Enqueuing Scripts on the admin side
         *
         * @param  string $hook_suffix
         *
         * @return void
         */
        public function admin_enqueue_scripts( $hook_suffix ) {
            $hook_scripts = false;
            if ( 'post-new.php' === $hook_suffix && isset( $_GET['post_type'] ) && 'giveasap' === $_GET['post_type'] ) {
                $hook_scripts = true;
            }
            if ( 'post.php' === $hook_suffix && isset( $_GET['post'] ) && get_post_type( $_GET['post'] ) === 'giveasap' ) {
                $hook_scripts = true;
            }
            if ( 'giveasap_page_giveasap_settings' === $hook_suffix || 'giveasap_page_giveasap-users' === $hook_suffix || 'giveasap_page_giveasap-subscriber-entries' === $hook_suffix || 'giveasap_page_giveasap_integrations' === $hook_suffix || 'giveasap_page_giveasap_about_page' === $hook_suffix ) {
                $hook_scripts = true;
            }
            $hook_scripts = apply_filters( 'sg_admin_enqueue_scripts', $hook_scripts, $hook_suffix );
            if ( $hook_scripts ) {
                wp_enqueue_style( 'wp-color-picker' );
                wp_enqueue_script( 'jquery-ui-datepicker' );
                wp_enqueue_script(
                    'sg-reports-select',
                    GASAP_URI . '/assets/js/admin/reports/select2.full.min.js',
                    array('jquery'),
                    '',
                    true
                );
                wp_enqueue_style(
                    'sg-reports-select-css',
                    GASAP_URI . '/assets/css/vendor/select2.min.css',
                    array(),
                    ''
                );
                wp_enqueue_code_editor( array(
                    'type' => 'text/html',
                ) );
                wp_register_script( 'gasap-admin-js', GASAP_URI . 'assets/dist/js/admin.js', array(
                    'jquery',
                    'wp-color-picker',
                    'wp-util',
                    'jquery-ui-sortable'
                ) );
                wp_localize_script( 'gasap-admin-js', 'gasap', array(
                    'ajax_url' => admin_url( 'admin-ajax.php' ),
                    'nonce'    => wp_create_nonce( 'gasap-admin' ),
                    'text'     => array(
                        'saving'            => __( 'Saving', 'giveasap' ),
                        'save'              => __( 'Save', 'giveasap' ),
                        'activate'          => __( 'Activate', 'giveasap' ),
                        'deactivate'        => __( 'Deactivate', 'giveasap' ),
                        'winner_before_end' => __( 'Winner Date & Time is sonner than the End Date. Change it.', 'giveasap' ),
                    ),
                ) );
                wp_enqueue_script( 'gasap-admin-js' );
                wp_enqueue_style(
                    'gasap-admin-css',
                    GASAP_URI . 'assets/dist/css/admin.css',
                    array(),
                    time(),
                    'all'
                );
            }
            if ( 'giveasap_page_sg_reports' === $hook_suffix ) {
                wp_enqueue_style(
                    'gasap-admin-css',
                    GASAP_URI . 'assets/dist/css/admin.css',
                    array(),
                    time(),
                    'all'
                );
                wp_enqueue_script(
                    'sg-reports-chart',
                    GASAP_URI . '/assets/js/admin/reports/chart.bundle.min.js',
                    array('jquery'),
                    '',
                    true
                );
                wp_enqueue_style(
                    'sg-reports-chart-css',
                    GASAP_URI . '/assets/css/admin/chart.min.css',
                    array(),
                    ''
                );
                wp_enqueue_script(
                    'sg-reports-select',
                    GASAP_URI . '/assets/js/admin/reports/select2.full.min.js',
                    array('jquery'),
                    '',
                    true
                );
                wp_enqueue_style(
                    'sg-reports-select-css',
                    GASAP_URI . '/assets/css/vendor/select2.min.css',
                    array(),
                    ''
                );
                wp_enqueue_script(
                    'sg-reports',
                    GASAP_URI . '/assets/js/admin/reports/reports.js',
                    array('jquery'),
                    '',
                    true
                );
            }
        }

        /**
         * Running all dependencies
         *
         * @return void
         */
        public function run_dependencies() {
            global $wpdb;
            include_once GASAP_ROOT . '/includes/abstracts/settings.php';
            include_once GASAP_ROOT . '/includes/abstracts/class-ga-integration.php';
            include_once GASAP_ROOT . '/includes/abstracts/class-sharer.php';
            include_once GASAP_ROOT . '/includes/abstracts/class-sg-giveaway.php';
            include_once GASAP_ROOT . '/includes/giveasap-template-functions.php';
            include_once GASAP_ROOT . '/includes/giveasap-time-functions.php';
            include_once GASAP_ROOT . '/includes/giveasap-functions.php';
            include_once GASAP_ROOT . '/includes/functions-meta.php';
            include_once GASAP_ROOT . '/includes/functions-email.php';
            include_once GASAP_ROOT . '/includes/functions-subscriber.php';
            include_once GASAP_ROOT . '/includes/functions-extra-actions.php';
            include_once GASAP_ROOT . '/includes/giveasap-cpt.php';
            include_once GASAP_ROOT . '/includes/class-status.php';
            include_once GASAP_ROOT . '/includes/class-helpers.php';
            include_once GASAP_ROOT . '/includes/class-schedule.php';
            include_once GASAP_ROOT . '/includes/class-ga-installer.php';
            include_once GASAP_ROOT . '/includes/class-sharing.php';
            include_once GASAP_ROOT . '/includes/class-sharer-facebook.php';
            include_once GASAP_ROOT . '/includes/class-sharer-twitter.php';
            include_once GASAP_ROOT . '/includes/class-sharer-linkedin.php';
            include_once GASAP_ROOT . '/includes/class-sharer-pinterest.php';
            include_once GASAP_ROOT . '/includes/class-sharer-link.php';
            include_once GASAP_ROOT . '/includes/widget.php';
            include_once GASAP_ROOT . '/includes/updates.php';
            include_once GASAP_ROOT . '/includes/shortcode.php';
            include_once GASAP_ROOT . '/includes/giveasap-metabox.php';
            include_once GASAP_ROOT . '/includes/class-giveasap-front.php';
            include_once GASAP_ROOT . '/includes/register-actions.php';
            include_once GASAP_ROOT . '/includes/class-ga-gdpr.php';
            include_once GASAP_ROOT . '/includes/class-sg-blocks.php';
            include_once GASAP_ROOT . '/includes/class-sg-giveaway-factory.php';
            include_once GASAP_ROOT . '/includes/class-sg-giveaway-simple.php';
            include_once GASAP_ROOT . '/includes/class-sg-giveaway-limited.php';
            include_once GASAP_ROOT . '/includes/class-sg-giveaway-logged-in.php';
            include_once GASAP_ROOT . '/includes/class-sg-giveaway-no-subscriber-page.php';
            include_once GASAP_ROOT . '/includes/class-sg-giveaway-evergreen.php';
            include_once GASAP_ROOT . '/includes/class-sg-giveaway-user-picker.php';
            include_once GASAP_ROOT . '/includes/class-sg-subscriber.php';
            include_once GASAP_ROOT . '/includes/class-sg-email.php';
            include_once GASAP_ROOT . '/includes/class-sg-extra-actions.php';
            include_once GASAP_ROOT . '/includes/emails/class-sg-email-subscriber.php';
            include_once GASAP_ROOT . '/includes/emails/class-sg-email-request-link.php';
            include_once GASAP_ROOT . '/includes/emails/class-sg-email-notify-admin.php';
            include_once GASAP_ROOT . '/includes/emails/class-sg-email-referrer.php';
            include_once GASAP_ROOT . '/includes/emails/class-sg-email-reminder.php';
            include_once GASAP_ROOT . '/includes/class-sg-category.php';
            include_once GASAP_ROOT . '/includes/class-sg-customizer.php';
            include_once GASAP_ROOT . '/includes/class-prizes.php';
            include_once GASAP_ROOT . '/includes/compact.php';
            //include_once GASAP_ROOT . '/includes/admin/class-giveasap-form-builder.php';
            include_once GASAP_ROOT . '/includes/admin/class-giveasap-visual-builder.php';
            if ( is_admin() ) {
                $this->run_admin_dependencies();
            }
            include_once GASAP_ROOT . '/includes/integrations/class-sg-automatorwp.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-gamipress.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-facebook.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-twitter.php';
            include_once GASAP_ROOT . '/includes/integrations/class-ga-mailchimp.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-brevo.php';
            include_once GASAP_ROOT . '/includes/integrations/class-ga-aweber.php';
            include_once GASAP_ROOT . '/includes/integrations/class-ga-convertkit.php';
            include_once GASAP_ROOT . '/includes/integrations/class-ga-active-campaign.php';
            include_once GASAP_ROOT . '/includes/integrations/class-ga-mailpoet.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-math-captcha.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-notifications.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-mycred.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-mailster.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-daily-entries.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-buddypress.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-elementor.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-mailerlite.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-drip.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-woocommerce.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-edd.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-fluentcrm.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-wc-follow-up-emails.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-give.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-wpforms.php';
            include_once GASAP_ROOT . '/includes/integrations/class-sg-webhooks.php';
            //include_once GASAP_ROOT . '/includes/integrations/class-sg-tiktok.php';
            // Extending with GiveASAP table
            $wpdb->giveasap_entries = $wpdb->prefix . 'giveasap_entries';
            $wpdb->giveasapmeta = $wpdb->prefix . 'giveasap_meta';
            $wpdb->giveasap_actions = $wpdb->prefix . 'giveasap_actions';
        }

        /**
         * Running filters
         * Used to add other filters
         *
         * @return void
         */
        public function run_filters() {
            do_action( 'giveasap_filters' );
        }

        /**
         * Setting all sharing methods
         *
         * @param array $methods
         */
        public function set_sharing_methods( $methods ) {
            $methods['giveasap_facebook'] = '\\Simple_Giveaways\\GA_Sharer_Facebook';
            $methods['giveasap_twitter'] = '\\Simple_Giveaways\\GA_Sharer_Twitter';
            $methods['giveasap_linkedin'] = '\\Simple_Giveaways\\GA_Sharer_LinkedIN';
            $methods['giveasap_pinterest'] = '\\Simple_Giveaways\\GA_Sharer_Pinterest';
            $methods['giveasap_link'] = '\\Simple_Giveaways\\GA_Sharer_Link';
            return $methods;
        }

    }

    /**
     * Returns the Singleton instance of GiveASAP class
     *
     * @return GiveASAP
     */
    function gasap() {
        return GiveASAP::getInstance();
    }

    /**
     * Run the GiveASAP Plugin by calling all core methods
     *
     * @return void
     */
    function gasap_run() {
        $giveasap = gasap();
        do_action( 'giveasap_init' );
        $giveasap->run_dependencies();
        do_action( 'giveasap_dependencies_loaded' );
        $giveasap->run_admin();
        $giveasap->run_actions();
        $giveasap->run_public_actions();
        $giveasap->run_filters();
        do_action( 'giveasap_init_end' );
    }

    // We will wait until everything is loaded
    add_action( 'plugins_loaded', 'gasap_run', 20 );
    /**
     * Activation Hook
     *
     * @return void
     */
    function giveasap_activate() {
        include_once GASAP_ROOT . '/includes/giveasap-cpt.php';
        include_once GASAP_ROOT . '/includes/class-ga-installer.php';
        giveasap_cpt();
        // Flushing Rewrite Rules
        flush_rewrite_rules();
        $installer = new \Simple_Giveaways\GA_Installer();
        $installer->install();
    }

    register_activation_hook( __FILE__, 'giveasap_activate' );
}