<?php
/**
 * Plugin Name: Drop Print
 * Plugin URI: https://aldenfineprint.com/drop-print/
 * Description: Sell giclee prints with WooCommerce with Drop Print's specialised fine art print-on-demand fulfilment service, built specifically for artists and galleries.
 * Version: 2.0.5
 * Author: Drop Print
 * Author URI: https://aldenfineprint.com
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: drop-print
 * Domain Path: /languages
 * Requires at least: 6.0
 * Tested up to: 7.0
 * Requires PHP: 7.4
 * WC requires at least: 8.6
 * WC tested up to: 10.9.3
 * Requires Plugins: woocommerce
 */
if(!defined('WPINC')){die;}
define('DROP_PRINT_VERSION','2.0.5');
define('DROP_PRINT_PLUGIN_URL',plugin_dir_url(__FILE__));
define('DROP_PRINT_PLUGIN_PATH',plugin_dir_path(__FILE__));
define('DROP_PRINT_PLUGIN_FILE',__FILE__);
define('DROP_PRINT_UPLOAD_BASE_DIR',trailingslashit(wp_upload_dir()['basedir']).'drop-print');
if(!defined('DROP_PRINT_CONTAINER_EXT')){define('DROP_PRINT_CONTAINER_EXT','.drop');}
if(!defined('DROP_PRINT_LEGACY_CONTAINER_EXTS')){define('DROP_PRINT_LEGACY_CONTAINER_EXTS','.afp');}
if(!function_exists('drop_print_container_path')){
function drop_print_container_path(string $base_dir,string $base_name):string{
    $canonical=trailingslashit($base_dir).$base_name.DROP_PRINT_CONTAINER_EXT;
    if(file_exists($canonical)){
        return $canonical;
    }
    foreach(array_filter(array_map('trim',explode(',',DROP_PRINT_LEGACY_CONTAINER_EXTS))) as $legacy_ext){
        $legacy_path=trailingslashit($base_dir).$base_name.$legacy_ext;
        if(file_exists($legacy_path)){
            return $legacy_path;
        }
    }
    return $canonical;
}}
if(!defined('DROP_PRINT_LOCAL_DEV_MODE')){define('DROP_PRINT_LOCAL_DEV_MODE',false);}
if(!defined('DROP_PRINT_DEV_TARGET')){define('DROP_PRINT_DEV_TARGET','sandbox');}
if(!defined('DROP_PRINT_LOCAL_DEV_URL')){define('DROP_PRINT_LOCAL_DEV_URL','');}
if(!function_exists('drop_print_network_base_url')){
function drop_print_network_base_url(string $key):string{
    $production=array(
        'main'    => 'https://aldenfineprint.com/drop-print',
        'api'     => 'https://api.aldenfineprint.com',
        'account' => 'https://account.aldenfineprint.com',
        'editing' => 'https://editing.drop-print.com',
    );
    if(defined('DROP_PRINT_LOCAL_DEV_MODE') && DROP_PRINT_LOCAL_DEV_MODE){
        if('api'===$key && defined('DROP_PRINT_LOCAL_DEV_URL') && is_string(DROP_PRINT_LOCAL_DEV_URL) && DROP_PRINT_LOCAL_DEV_URL!==''){
            return untrailingslashit(DROP_PRINT_LOCAL_DEV_URL);
        }
        $target=defined('DROP_PRINT_DEV_TARGET') ? DROP_PRINT_DEV_TARGET : 'sandbox';
        $sandbox=array(
            'main'    => 'https://aldenfineprint.co.uk',
            'api'     => 'https://api-sandbox.aldenfineprint.co.uk',
            'account' => 'https://api-sandbox.aldenfineprint.co.uk',
            'editing' => 'https://editing-sandbox.aldenfineprint.co.uk',
        );
        $local=array(
            'main'    => 'http://drop-print.localhost',
            'api'     => 'http://api.drop-print.localhost',
            'account' => 'http://api.drop-print.localhost',
            'editing' => 'http://editing.drop-print.localhost',
        );
        $dev = ('local'===$target) ? $local : $sandbox;
        $dev = apply_filters('drop_print_dev_network_hosts',$dev,$target);
        $dev = apply_filters('drop_print_local_network_hosts',$dev);
        if(is_array($dev) && isset($dev[$key]) && is_string($dev[$key]) && $dev[$key]!==''){
            return untrailingslashit($dev[$key]);
        }
    }
    return isset($production[$key]) ? $production[$key] : $production['main'];
}}
if(!defined('DROP_PRINT_API_URI')){define('DROP_PRINT_API_URI',drop_print_network_base_url('api').'/wp-json/print-server/2.0');}
add_action('before_woocommerce_init', function(){
    if(class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)){
        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
    }
});
require_once DROP_PRINT_PLUGIN_PATH.'includes/utils.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/order-line-snapshot.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/drop-print-container-tracker.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/callbacks.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/proof-verdicts.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/plugin-activation.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/admin-settings-page.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/admin-get-client-id.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/class-drop-print-headless-connect.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/production/json-payload-builder.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/production/auto-production.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/production/production-handlers.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/pro-upgrade-session-handlers.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/pro-upsell-notices.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/file-issue-notice.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/production/production-column.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/class-drop-print-live-shipping-method.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/class-drop-print-checkout-packages.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/class-drop-print-checkout-shipping-tiers-assets.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/class-drop-print-shipping-zone-enrollment.php';
require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/class-drop-print-onboarding-wizard.php';
require_once DROP_PRINT_PLUGIN_PATH . 'includes/plugin-update.php';
add_action('admin_init','drop_print_run_update');
register_activation_hook(DROP_PRINT_PLUGIN_FILE,'drop_print_plugin_activation');
require_once DROP_PRINT_PLUGIN_PATH.'includes/plugin-deactivation.php';
register_deactivation_hook(DROP_PRINT_PLUGIN_FILE,'drop_print_plugin_deactivate');
function drop_print_init(){
    load_plugin_textdomain('drop-print',false,dirname(plugin_basename(DROP_PRINT_PLUGIN_FILE)).'/languages');
    require_once DROP_PRINT_PLUGIN_PATH.'includes/enqueues.php';
    if(is_admin()){
        $current_user_id = get_current_user_id();
        if($current_user_id > 0){
            $user_settings = drop_print_get_user_settings($current_user_id);
            if(!empty($user_settings['client_user_connection_id'])){
                require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/product-edit-panel.php';
                require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/dimension-check-handler.php';
                require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/file-upload-handler.php';
                require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/file-delete-handler.php';
                require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/product-variation-handler.php';
                require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/builder-page.php';
                require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/sku-migration-helpers.php';
                require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/class-drop-print-sku-migration-review.php';
                require_once DROP_PRINT_PLUGIN_PATH.'includes/admin/class-drop-print-change-paper-tool.php';
            }
        }
    }
}
add_action('plugins_loaded','drop_print_init');
