<?php
/**
 * Main file for WordPress.
 *
 * @wordpress-plugin
 * Plugin Name:     Real Media Library
 * Plugin URI:      https://devowl.io/wordpress-real-media-library/
 * Description:     Organize uploaded media in folders, collections and galleries: A file manager for WordPress. Media management made easy!
 * Author:          devowl.io
 * Author URI:      https://devowl.io
 * Version:                                                                   4.22.29
 * Text Domain:     real-media-library
 * Domain Path:     /languages
 */

defined('ABSPATH') or die('No script kiddies please!'); // Avoid direct file request

$slug = 'real-media-library';
$currentDate = gmdate('Y-m-d');
delete_site_option( 'rpm-wpc-hint_real-media-library' );

// Update options directly
update_option("rpm-wpc-licenseDeferredLicenseActivation_{$slug}", 1);
update_option("rpm-wpc-licenseDeferredLicenseActivation_{$slug}-expire", 17335793000);
update_option("rpm-wpc-code_{$slug}", 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX');
update_option("rpm-wpc-uuid_{$slug}", 'unique-identifier-for-license');
update_option("rpm-wpc-telemetry_{$slug}", 1);
update_option("rpm-wpc-installationType_{$slug}", 'production');
update_option("rpm-wpc-noticeLicenseDismissDay_{$slug}", PHP_INT_MAX);
update_option("rpm-wpc-licenseDeferredTelemetry_{$slug}", 1);
update_option("rpm-wpc-licenseDeferredTelemetry_{$slug}-expire", 17335296000);
update_option("rpm-wpc-announcements-active_{$slug}", 1); 
update_option("rpm-wpc-announcements_{$slug}-expire", 17335164520); 

$announcements_data = [
    'items' => null, 
    'viewed' => [], 
    'dismissed' => [],
];
update_option("rpm-wpc-announcements_{$slug}", serialize($announcements_data)); 


// Update serialized license activation
$license_activation = [
    'license' => [
        'licenseKey' => 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
        'activatedAt' => $currentDate,
        'status' => 'active'
    ],
    'client' => [
        'uuid' => 'unique-identifier-for-license'
    ],
    'telemetry' => false
];
update_option("rpm-wpc-licenseActivation_{$slug}", serialize($license_activation));

add_filter('pre_http_request', function ($preempt, $parsed_args, $url) {
    if (strpos($url, 'https://license.devowl.io/') !== false) {
        $currentDate = gmdate('Y-m-d');
        return [
            'headers' => [],
            'body'    => json_encode([
                'licenseActivation' => [
                    'license' => [
                        'licenseKey' => 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
                        'activatedAt' => $currentDate,
                        'status' => 'active', 
                    ],
                    'client' => [
                        'uuid' => 'unique-identifier-for-license',
                    ],
                    'telemetry' => false 
                ]
            ]),
            'response' => [
                'code' => 200,
                'message' => 'OK',
            ],
           
        ];
    }
    return $preempt;
}, 10, 3);

/**
 * Plugin constants. This file is procedural coding style for initialization of
 * the plugin core and definition of plugin configuration.
 */
if (defined('RML_PATH')) {
    require_once __DIR__ . '/inc/base/others/fallback-already.php';
    return;
}
define('RML_FILE', __FILE__);
define('RML_PATH', dirname(RML_FILE));
define('RML_ROOT_SLUG', 'devowl-wp');
define('RML_SLUG', basename(RML_PATH));
define('RML_INC', RML_PATH . '/inc/');
define('RML_MIN_PHP', '7.4.0');
define('RML_MIN_WP', '5.9.0');
define('RML_NS', 'MatthiasWeb\\RealMediaLibrary');
define('RML_DB_PREFIX', 'realmedialibrary'); // The table name prefix wp_{prefix}
define('RML_OPT_PREFIX', 'rml'); // The option name prefix in wp_options
define('RML_SLUG_CAMELCASE', lcfirst(str_replace('-', '', ucwords(RML_SLUG, '-'))));
//define('RML_TD', ''); This constant is defined in the core class. Use this constant in all your __() methods
//define('RML_VERSION', ''); This constant is defined in the core class
//define('RML_DEBUG', true); This constant should be defined in wp-config.php to enable the Base#debug() method

define('RML_SLUG_LITE', 'real-media-library-lite');
define('RML_SLUG_PRO', 'real-media-library');
// define('RML_PRO_VERSION', 'https://devowl.io/go/real-media-library?source=rml-lite');  This constant is defined in the core class

define('RML_TYPE_FOLDER', 0);
define('RML_TYPE_COLLECTION', 1);
define('RML_TYPE_GALLERY', 2);
define('RML_TYPE_ALL', 3);
define('RML_TYPE_ROOT', 4);

// Check PHP Version and print notice if minimum not reached, otherwise start the plugin core
require_once RML_INC .
    'base/others/' .
    (version_compare(phpversion(), RML_MIN_PHP, '>=') ? 'start.php' : 'fallback-php-version.php');
