<?php
/**
	Plugin Name: Download Magnet
	Plugin URI: https://peachysoftware.com/downloadmagnet
	Description: Provide a download window to capture email addresses
	Version: 3.0.1
	Author: Peachy Software LLC
	Author URI: https://peachysoftware.com
	License: GPLV2

	Copyright 2024 Peachy Software LLC (email : support@peachysoftware.com)
 *
 * @category Plugins
 * @package  WordPress
 * @author   Peachy Sofware LLC
 **/

defined( 'ABSPATH' ) || die( 'Invalid Path' );
	// DO NOT REMOVE THIS IF, IT IS ESSENTIAL FOR THE `function_exists` CALL ABOVE TO PROPERLY WORK.

if ( ! function_exists( 'psdm_fs' ) ) {
	// Create a helper function for easy SDK access.
	function psdm_fs() {
		global $psdm_fs;

		if ( ! isset( $psdm_fs ) ) {
			// Include Freemius SDK.
			require_once __DIR__ . '/vendor/freemius/start.php';

			$psdm_fs = fs_dynamic_init(
				array(
					'id'             => '4373',
					'slug'           => 'downloadmagnet',
					'type'           => 'plugin',
					'public_key'     => 'pk_77d239cca1611be8d4cbbedf9b49e',
					'is_premium'     => false,
					'has_addons'     => true,
					'has_paid_plans' => false,
					'menu'           => array(
						'slug'    => 'edit.php?post_type=psdmcontent',
						'account' => false,
						'contact' => false,
						'support' => false,
					),
				)
			);
		}

		return $psdm_fs;
	}

	// Init Freemius.
	psdm_fs();
	// Signal that SDK was initiated.
	do_action( 'psdm_fs_loaded' );
}


	require_once plugin_dir_path( __FILE__ ) . 'includes/class-psdm-downloadmagnet.php';

	register_activation_hook( __FILE__, 'psdm_create_table' );
	/**
	 * Create table.
	 */
function psdm_create_table() {
	global $wpdb;
	$charset_collate = $wpdb->get_charset_collate();
	$table_name      = $wpdb->prefix . 'psdm_downloads';
	$sql             = "CREATE TABLE $table_name (
						id mediumint(9) NOT NULL AUTO_INCREMENT,
						time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
						download_id mediumint(9),
						download_name varchar(128),
						name varchar(128),
						email_address varchar(128),
						permission_granted tinyint(1),
						ip_address varchar(48),
						comments text,
						UNIQUE KEY id (id)
                   ) {$charset_collate};";
	include_once ABSPATH . 'wp-admin/includes/upgrade.php';
	dbDelta( $sql );
	update_site_option( 'psdm_db_version', 1.0 );
}

	$download = new PSDM_DownloadMagnet();
