<?php
// Prevent direct access.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
/**
 * Plugin Name: MDJM Extension - Google Calendar Sync
 * Description: Synchronise your events to your Google Calendar.
 * Version:     2.3.8.1
 * Date:        January 2026
 * Author: MDJM
 * Author URI:  https://www.mdjm.co.uk
 * Text Domain: mdjm-gcal-integration
 * Domain Path: /languages
 * Copyright   Copyright (c) 2022 Dan Porter, Jack Mawhinney
 */

// Set MDJM Google Calendar Integration Version
if ( ! defined( 'MDJM_GCAL_VERSION' ) ) {
	define( 'MDJM_GCAL_VERSION', '2.3.8.1' );
}

// Set minimum MDJM version required
if ( ! defined( 'MDJM_REQUIRED' ) ) {
	define( 'MDJM_REQUIRED', '1.7.6' );
}

// Set minimum required PHP version
if ( ! defined( 'MDJM_PHP_MIN' ) ) {
	define( 'MDJM_PHP_MIN', '8.2' );
}
// Set minimum required WP version
if ( ! defined( 'MDJM_WP_MIN' ) ) {
	define( 'MDJM_WP_MIN', '6.9' );
}

// Define path to MDJM Google Calendar Integration Plugin
if ( ! defined( 'MDJM_GCAL_PATH' ) ) {
	define( 'MDJM_GCAL_PATH', untrailingslashit( __DIR__ ) );
}
// Define URL to MDJM Google Calendar Integration Plugin
if ( ! defined( 'MDJM_GCAL_URL' ) ) {
	define( 'MDJM_GCAL_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
}
// Define MDJM Google Calendar Integration Plugin Basename
if ( ! defined( 'MDJM_GCAL_BASENAME' ) ) {
	define( 'MDJM_GCAL_BASENAME', plugin_basename( __FILE__ ) );
}
// Define MDJM Google Calendar Integration Plugin FILENAME
if ( ! defined( 'MDJM_GCAL_FILE' ) ) {
	define( 'MDJM_GCAL_FILE', __FILE__ );
}


class MDJM_GCal_Sync {

	private static $instance;

	/**
	 * Add the Manage Contact Forms link
	 *
	 * @since   2.0
	 */
	public static function action_links( $links ) {
		$action_links['settings'] = '<a href="' . get_site_url( 'settings', 'mdjm-google-cal-sync' ) . '/wp-admin/edit.php?post_type=mdjm-event&page=mdjm-settings&tab=extensions&section=gcal_sync"' . esc_attr( __( 'Settings', 'mdjm-google-cal-sync' ) ) . '</a>';

		return array_merge( $action_links, $links );
	} // action_links


	public static function instance() {

		if ( ! self::$instance ) {
			self::$instance           = new MDJM_GCal_Sync();
			self::$instance->google   = new MDJM_GCal_Init();
		}

		return self::$instance;
	} // __construct
}

// Load Plugin Files
require MDJM_GCAL_PATH . '/includes/mdjm-gcal-init.php';
require_once MDJM_GCAL_PATH . '/includes/class-mdjm-ics-feed.php';

// Start Plugin
function MDJM_GCal() {
	return MDJM_GCal_Sync::instance();
} // MDJM_Gcal

add_action( 'plugins_loaded', 'MDJM_GCal' );

function mdjm_gcal_activate() {

	if ( ! class_exists( 'Mobile_DJ_Manager', false ) ) {
		return;
	}

	$current_version = get_option( 'mdjm_gcal_version' );
	if ( $current_version ) {
		return;
	}

	update_option( 'mdjm_gcal_version', MDJM_GCAL_VERSION );
} // mdjm_mc_activate
register_activation_hook( __FILE__, 'mdjm_gcal_activate' );
