<?php

/**
 * Plugin Name: Integrate Google Drive (Premium)
 * Plugin URI:  https://softlabbd.com/integrate-google-drive
 * Description: Seamless Google Drive integration for WordPress, allowing you to embed, share, play, and download documents and media files directly from Google Drive to your WordPress site.
 * Version:     1.5.6
 * Update URI: https://api.freemius.com
 * Author:      SoftLab
 * Author URI:  https://softlabbd.com/
 * Text Domain: integrate-google-drive-premium
 * Domain Path: /languages/
 * License:     GPL v2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 */
// don't call the file directly
if ( !defined( 'ABSPATH' ) ) {
    exit( 'You can\'t access this page directly.' );
}

if ( function_exists( 'igd_fs' ) ) {
    igd_fs()->set_basename( true, __FILE__ );
} else {
    // DO NOT REMOVE THIS IF, IT IS ESSENTIAL FOR THE `function_exists` CALL ABOVE TO PROPERLY WORK.
    if ( ! function_exists( 'igd_fs' ) ) {
        // Create a helper function for easy SDK access.
        function igd_fs() {
            global $igd_fs;

            if ( ! isset( $igd_fs ) ) {
                // Include Freemius SDK.
                require_once dirname( __FILE__ ) . '/freemius/start.php';

                class igdFsNull {
                    public function can_use_premium_code__premium_only() {
                        return true;
                    }

                    public function is_premium() {
                        return true;
                    }

                    public function has_any_active_license() {
                        return true;
                    }

                    public function is_paying() {
                        return true;
                    }

                    public function is_paying_or_trials() {
                        return true;
                    }

                    public function get_upgrade_url() {
                        return '';
                    }

                    public function get_trial_url() {
                        return '';
                    }

                    public function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
                        add_filter( $tag, $function_to_add, $priority, $accepted_args );
                    }

                    public function add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
                        add_action( $tag, $function_to_add, $priority, $accepted_args );
                    }

                    // Stub for other possible calls
                    public function __call( $name, $arguments ) {
                        return null;
                    }
                }

                $igd_fs = new igdFsNull();
            }
            return $igd_fs;
        }
        // Signal that SDK was initiated.
        do_action( 'igd_fs_loaded' );
    }
} 

/** define constants */
define( 'IGD_PRO_VERSION', '1.5.5' );
define( 'IGD_PRO_FILE', __FILE__ );
define( 'IGD_PRO_PATH', dirname( IGD_PRO_FILE ) );
define( 'IGD_PRO_INCLUDES', IGD_PRO_PATH . '/includes' );
define( 'IGD_PRO_URL', plugins_url( '', IGD_PRO_FILE ) );
define( 'IGD_PRO_ASSETS', IGD_PRO_URL . '/assets' );
// Activation hook
register_activation_hook( __FILE__, 'igd_pro_activate' );
function igd_pro_activate() {
    if ( !class_exists( 'IGD_PRO\\Install' ) ) {
        include_once IGD_PRO_INCLUDES . '/Install.php';
    }
    IGD_PRO\Install::activate();
}

// Deactivation hook
register_deactivation_hook( __FILE__, 'igd_pro_deactivate' );
function igd_pro_deactivate() {
    if ( !class_exists( 'IGD_PRO\\Install' ) ) {
        include_once IGD_PRO_INCLUDES . '/Install.php';
    }
    IGD_PRO\Install::deactivate();
}

add_action( 'admin_notices', 'igd_pro_missing_plugin_notice' );
function igd_pro_missing_plugin_notice() {
    if ( defined( 'IGD_VERSION' ) ) {
        return;
        // Base plugin is active
    }
    if ( !current_user_can( 'activate_plugins' ) ) {
        return;
    }
    $plugin_slug = 'integrate-google-drive/plugin.php';
    if ( igd_pro_is_base_installed( $plugin_slug ) ) {
        $activation_url = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $plugin_slug . '&amp;plugin_status=all&amp;paged=1&amp;s', 'activate-plugin_' . $plugin_slug );
        $message = '<strong>Integrate Google Drive PRO </strong> requires <strong>Integrate Google Drive</strong> base plugin to be active. Please activate Integrate Google Drive to continue.';
        $button_text = __( 'Activate Integrate Google Drive', 'integrate-google-drive-premium' );
    } else {
        $activation_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=integrate-google-drive' ), 'install-plugin_integrate-google-drive' );
        $message = '<strong>Integrate Google Drive PRO</strong> requires <strong>Integrate Google Drive</strong> base plugin to be installed and activated. Please install Integrate Google Drive to continue.';
        $button_text = __( 'Install Integrate Google Drive', 'integrate-google-drive-premium' );
    }
    $button = '<p><a href="' . esc_url( $activation_url ) . '" class="button-primary">' . esc_html( $button_text ) . '</a></p>';
    printf( '<div class="error"><p>%1$s</p>%2$s</div>', wp_kses( $message, [
        'strong' => [],
        'a'      => [
            'href'  => [],
            'class' => [],
        ],
    ] ), wp_kses( $button, [
        'a' => [
            'href'  => [],
            'class' => [],
        ],
        'p' => [],
    ] ) );
}

function igd_pro_is_base_installed(  $basename  ) {
    if ( !function_exists( 'get_plugins' ) ) {
        include_once ABSPATH . '/wp-admin/includes/plugin.php';
    }
    $installed_plugins = get_plugins();
    return isset( $installed_plugins[$basename] );
}

add_action( 'admin_notices', 'igd_pro_version_upgrade_notice' );
function igd_pro_version_upgrade_notice() {
    if ( !defined( 'IGD_VERSION' ) ) {
        return;
        // Base plugin is active
    }
    if ( version_compare( IGD_VERSION, '1.5.6', '>=' ) ) {
        return;
    }
    if ( !current_user_can( 'update_plugins' ) ) {
        return;
    }
    $message = sprintf(
        esc_html__( '%1$s Integrate Google Drive (PRO) %2$s requires %1$s Integrate Google Drive base plugin %2$s version %1$s %3$s %2$s or newer. Please update Integrate Google Drive to continue.' ),
        '<strong>',
        '</strong>',
        '1.5.6'
    );
    printf( '<div class="error"><p>%s</p></div>', wp_kses( $message, [
        'strong' => [],
    ] ) );
}

add_action( 'igd_loaded', function () {
    igd_fs();
    igd_fs()->add_filter( 'deactivate_on_activation', '__return_false' );
    // Load main plugin class
    if ( version_compare( IGD_VERSION, '1.5.6', '<' ) ) {
        return;
        // Base plugin is outdated
    }
    include_once IGD_PRO_INCLUDES . '/Main.php';
} );