| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- <?php
- /**
- * Plugin Name: QDR - Studiou WC Free Photo Product
- * Plugin URI: https://www.quadarax.com/plugins/studiou-wc-free-photo-product
- * Description: Allows publishing special WooCommerce products with variants and custom raw image upload for photo printing
- * Version: 1.5.8
- * Requires at least: 6.9.4
- * Requires PHP: 8.2
- * Requires Plugins: woocommerce, product-variant-table-for-woocommerce
- * Author: Dalibor Votruba
- * Author URI: https://www.quadarax.com
- * License: GPL v2 or later
- * License URI: https://www.gnu.org/licenses/gpl-2.0.html
- * Text Domain: studiou-wc-free-photo-product
- * Domain Path: /languages
- * WC requires at least: 10.0
- * WC tested up to: 10.6
- * Woo: 12346:a9b8c7d6e5f4a3b2c1d0e9f8a7b6c5d4
- */
- if (!defined('WPINC')) {
- die;
- }
- if (!defined('STUDIOU_WCFPP_VERSION')) define('STUDIOU_WCFPP_VERSION', '1.5.8');
- if (!defined('STUDIOU_WCFPP_PLUGIN_DIR')) define('STUDIOU_WCFPP_PLUGIN_DIR', plugin_dir_path(__FILE__));
- if (!defined('STUDIOU_WCFPP_PLUGIN_URL')) define('STUDIOU_WCFPP_PLUGIN_URL', plugin_dir_url(__FILE__));
- if (!defined('STUDIOU_WCFPP_PLUGIN_BASENAME')) define('STUDIOU_WCFPP_PLUGIN_BASENAME', plugin_basename(__FILE__));
- if (!defined('STUDIOU_WCFPP_CHUNK_SIZE')) define('STUDIOU_WCFPP_CHUNK_SIZE', 1024 * 1024); // 1MB chunks
- class Studiou_WC_Free_Photo_Product {
- /** @var Studiou_WC_FPP_DB */
- private $db;
- /** @var Studiou_WC_FPP_Product */
- private $product;
- /** @var Studiou_WC_FPP_Upload */
- private $upload;
- /** @var Studiou_WC_FPP_Shortcode */
- private $shortcode;
- /** @var Studiou_WC_FPP_Single_Product */
- private $single_product;
- /** @var Studiou_WC_FPP_Cart */
- private $cart;
- /** @var Studiou_WC_FPP_Admin */
- private $admin;
- /** @var Studiou_WC_FPP_Pricing */
- private $pricing;
- public function __construct() {
- $this->load_dependencies();
- add_action('admin_init', array($this, 'check_required_plugins'));
- add_action('admin_menu', array($this, 'add_admin_menu'), 99);
- add_action('admin_enqueue_scripts', array($this, 'register_admin_assets'));
- add_action('wp_enqueue_scripts', array($this, 'register_frontend_assets'));
- $this->init_components();
- add_action('before_woocommerce_init', array($this, 'declare_hpos_compatibility'));
- }
- private function load_dependencies() {
- require_once STUDIOU_WCFPP_PLUGIN_DIR . 'includes/class-studiou-wc-fpp-db.php';
- require_once STUDIOU_WCFPP_PLUGIN_DIR . 'includes/class-studiou-wc-fpp-product.php';
- require_once STUDIOU_WCFPP_PLUGIN_DIR . 'includes/class-studiou-wc-fpp-upload.php';
- require_once STUDIOU_WCFPP_PLUGIN_DIR . 'includes/class-studiou-wc-fpp-shortcode.php';
- require_once STUDIOU_WCFPP_PLUGIN_DIR . 'includes/class-studiou-wc-fpp-single-product.php';
- require_once STUDIOU_WCFPP_PLUGIN_DIR . 'includes/class-studiou-wc-fpp-cart.php';
- require_once STUDIOU_WCFPP_PLUGIN_DIR . 'includes/class-studiou-wc-fpp-admin.php';
- require_once STUDIOU_WCFPP_PLUGIN_DIR . 'includes/class-studiou-wc-fpp-pricing.php';
- }
- private function init_components() {
- $this->db = new Studiou_WC_FPP_DB();
- $this->maybe_upgrade_db();
- $this->product = new Studiou_WC_FPP_Product();
- $this->upload = new Studiou_WC_FPP_Upload($this->db);
- $this->shortcode = new Studiou_WC_FPP_Shortcode();
- $this->single_product = new Studiou_WC_FPP_Single_Product($this->db);
- $this->cart = new Studiou_WC_FPP_Cart($this->db);
- $this->admin = new Studiou_WC_FPP_Admin($this->db);
- $this->pricing = new Studiou_WC_FPP_Pricing();
- }
- /**
- * Run dbDelta when the installed schema is older than the current plugin version.
- * dbDelta handles adding the batch_token column and its KEY on existing installs.
- */
- private function maybe_upgrade_db() {
- $installed = get_option('studiou_wcfpp_db_version', '');
- if (version_compare((string) $installed, STUDIOU_WCFPP_VERSION, '<')) {
- $this->db->create_tables();
- }
- }
- public function check_required_plugins() {
- if (!class_exists('WooCommerce')) {
- add_action('admin_notices', function () {
- echo '<div class="notice notice-error"><p>';
- echo esc_html__('QDR - Studiou WC Free Photo Product requires WooCommerce to be installed and activated.', 'studiou-wc-free-photo-product');
- echo '</p></div>';
- });
- }
- if (!self::is_pvtfw_active()) {
- add_action('admin_notices', function () {
- echo '<div class="notice notice-error"><p>';
- echo esc_html__('QDR - Studiou WC Free Photo Product requires the "Product Variant Table for WooCommerce" plugin to be installed and activated.', 'studiou-wc-free-photo-product');
- echo '</p></div>';
- });
- }
- }
- /**
- * Detects whether the Product Variant Table for WooCommerce (pvtfw) plugin is active,
- * regardless of its main file name, by matching the active-plugins list on the folder slug.
- */
- public static function is_pvtfw_active() {
- $slug = 'product-variant-table-for-woocommerce/';
- $active = (array) get_option('active_plugins', array());
- foreach ($active as $plugin) {
- if (strpos($plugin, $slug) === 0) {
- return true;
- }
- }
- if (is_multisite()) {
- $network = (array) get_site_option('active_sitewide_plugins', array());
- foreach (array_keys($network) as $plugin) {
- if (strpos($plugin, $slug) === 0) {
- return true;
- }
- }
- }
- return false;
- }
- public function declare_hpos_compatibility() {
- if (class_exists('Automattic\WooCommerce\Utilities\FeaturesUtil')) {
- \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility(
- 'custom_order_tables',
- __FILE__,
- true
- );
- }
- }
- public function add_admin_menu() {
- if (class_exists('WooCommerce')) {
- add_submenu_page(
- 'edit.php?post_type=product',
- __('Free Photo Files', 'studiou-wc-free-photo-product'),
- __('Free Photo Files', 'studiou-wc-free-photo-product'),
- 'manage_woocommerce',
- 'studiou-fpp-summary',
- array($this->admin, 'render_summary_page')
- );
- }
- }
- public function register_admin_assets($hook) {
- // Product edit page
- $screen = get_current_screen();
- if ($screen && ($screen->id === 'product' || $screen->post_type === 'product')) {
- wp_enqueue_style(
- 'studiou-wcfpp-admin',
- STUDIOU_WCFPP_PLUGIN_URL . 'assets/css/admin.css',
- array(),
- STUDIOU_WCFPP_VERSION
- );
- wp_enqueue_script(
- 'studiou-wcfpp-admin',
- STUDIOU_WCFPP_PLUGIN_URL . 'assets/js/admin.js',
- array('jquery'),
- STUDIOU_WCFPP_VERSION,
- true
- );
- wp_localize_script('studiou-wcfpp-admin', 'studiouWcfpp', array(
- 'ajaxUrl' => admin_url('admin-ajax.php'),
- 'nonce' => wp_create_nonce('studiou-wcfpp-nonce'),
- 'i18n' => array(
- 'confirmDelete' => __('Are you sure you want to delete the selected files?', 'studiou-wc-free-photo-product'),
- 'confirmDeleteSingle' => __('Are you sure you want to delete this file?', 'studiou-wc-free-photo-product'),
- 'confirmDownloadZip' => __('Download selected files as ZIP archive?', 'studiou-wc-free-photo-product'),
- 'confirmStatusChange' => __('Are you sure you want to change the status of the selected files?', 'studiou-wc-free-photo-product'),
- 'noFilesSelected' => __('No files selected.', 'studiou-wc-free-photo-product'),
- 'statusUpdated' => __('Status updated.', 'studiou-wc-free-photo-product'),
- 'error' => __('An error occurred.', 'studiou-wc-free-photo-product'),
- 'generatingZip' => __('Generating ZIP archive...', 'studiou-wc-free-photo-product'),
- 'generatingCsv' => __('Generating CSV file...', 'studiou-wc-free-photo-product'),
- 'deleting' => __('Deleting...', 'studiou-wc-free-photo-product'),
- ),
- ));
- }
- // Admin summary page
- if ('product_page_studiou-fpp-summary' === $hook) {
- wp_enqueue_style(
- 'studiou-wcfpp-admin',
- STUDIOU_WCFPP_PLUGIN_URL . 'assets/css/admin.css',
- array(),
- STUDIOU_WCFPP_VERSION
- );
- wp_enqueue_script(
- 'studiou-wcfpp-admin',
- STUDIOU_WCFPP_PLUGIN_URL . 'assets/js/admin.js',
- array('jquery'),
- STUDIOU_WCFPP_VERSION,
- true
- );
- wp_localize_script('studiou-wcfpp-admin', 'studiouWcfpp', array(
- 'ajaxUrl' => admin_url('admin-ajax.php'),
- 'nonce' => wp_create_nonce('studiou-wcfpp-nonce'),
- 'i18n' => array(
- 'confirmDelete' => __('Are you sure you want to delete the selected files?', 'studiou-wc-free-photo-product'),
- 'confirmDeleteSingle' => __('Are you sure you want to delete this file?', 'studiou-wc-free-photo-product'),
- 'confirmDownloadZip' => __('Download selected files as ZIP archive?', 'studiou-wc-free-photo-product'),
- 'confirmStatusChange' => __('Are you sure you want to change the status of the selected files?', 'studiou-wc-free-photo-product'),
- 'noFilesSelected' => __('No files selected.', 'studiou-wc-free-photo-product'),
- 'statusUpdated' => __('Status updated.', 'studiou-wc-free-photo-product'),
- 'error' => __('An error occurred.', 'studiou-wc-free-photo-product'),
- 'generatingZip' => __('Generating ZIP archive...', 'studiou-wc-free-photo-product'),
- 'generatingCsv' => __('Generating CSV file...', 'studiou-wc-free-photo-product'),
- 'deleting' => __('Deleting...', 'studiou-wc-free-photo-product'),
- ),
- ));
- }
- }
- public function register_frontend_assets() {
- wp_register_style(
- 'studiou-wcfpp-frontend',
- STUDIOU_WCFPP_PLUGIN_URL . 'assets/css/frontend.css',
- array(),
- STUDIOU_WCFPP_VERSION
- );
- wp_register_script(
- 'studiou-wcfpp-frontend',
- STUDIOU_WCFPP_PLUGIN_URL . 'assets/js/frontend.js',
- array('jquery'),
- STUDIOU_WCFPP_VERSION,
- true
- );
- wp_localize_script('studiou-wcfpp-frontend', 'studiouWcfppFront', array(
- 'ajaxUrl' => admin_url('admin-ajax.php'),
- 'nonce' => wp_create_nonce('studiou-wcfpp-front-nonce'),
- 'chunkSize' => STUDIOU_WCFPP_CHUNK_SIZE,
- 'cartUrl' => wc_get_cart_url(),
- 'currency' => array(
- 'symbol' => function_exists('get_woocommerce_currency_symbol') ? get_woocommerce_currency_symbol() : '',
- 'priceFormat' => function_exists('get_woocommerce_price_format') ? get_woocommerce_price_format() : '%1$s%2$s',
- 'decimalSeparator' => function_exists('wc_get_price_decimal_separator') ? wc_get_price_decimal_separator() : '.',
- 'thousandSeparator' => function_exists('wc_get_price_thousand_separator') ? wc_get_price_thousand_separator() : ',',
- 'decimals' => function_exists('wc_get_price_decimals') ? wc_get_price_decimals() : 2,
- ),
- 'i18n' => array(
- 'uploading' => __('Uploading...', 'studiou-wc-free-photo-product'),
- 'uploadComplete' => __('Upload complete', 'studiou-wc-free-photo-product'),
- 'processing' => __('Processing...', 'studiou-wc-free-photo-product'),
- 'uploadError' => __('Upload failed. Please try again.', 'studiou-wc-free-photo-product'),
- 'fileTooLarge' => __('File is too large. Maximum size: %s MB', 'studiou-wc-free-photo-product'),
- 'selectVariant' => __('Please select a variant.', 'studiou-wc-free-photo-product'),
- 'uploadFile' => __('Please upload a file.', 'studiou-wc-free-photo-product'),
- 'addedToCart' => __('Product added to cart!', 'studiou-wc-free-photo-product'),
- 'addToCartError' => __('Could not add to cart. Please try again.', 'studiou-wc-free-photo-product'),
- 'dragDropText' => __('Drag & drop your file here or click to browse', 'studiou-wc-free-photo-product'),
- 'removeFile' => __('Remove', 'studiou-wc-free-photo-product'),
- 'close' => __('Close', 'studiou-wc-free-photo-product'),
- 'enlarge' => __('Enlarge', 'studiou-wc-free-photo-product'),
- 'addToCart' => __('Add to cart', 'studiou-wc-free-photo-product'),
- 'maxUploadsReached' => __('Maximum number of uploads reached (%d).', 'studiou-wc-free-photo-product'),
- 'outOfStock' => __('out of stock', 'studiou-wc-free-photo-product'),
- 'error' => __('An error occurred.', 'studiou-wc-free-photo-product'),
- 'qtyTiersTitle' => __('Quantity Discount', 'studiou-wc-free-photo-product'),
- 'qtyTiersFromQty' => __('From Qty', 'studiou-wc-free-photo-product'),
- 'qtyTiersDiscount' => __('Discount', 'studiou-wc-free-photo-product'),
- 'qtyTiersUnitPrice' => __('Unit Price', 'studiou-wc-free-photo-product'),
- ),
- ));
- }
- public static function activate() {
- require_once STUDIOU_WCFPP_PLUGIN_DIR . 'includes/class-studiou-wc-fpp-db.php';
- $db = new Studiou_WC_FPP_DB();
- $db->create_tables();
- // Create chunks temp directory
- $upload_dir = wp_upload_dir();
- $chunks_dir = $upload_dir['basedir'] . '/studiou-fpp-chunks';
- if (!file_exists($chunks_dir)) {
- wp_mkdir_p($chunks_dir);
- file_put_contents($chunks_dir . '/.htaccess', 'deny from all');
- file_put_contents($chunks_dir . '/index.php', '<?php // Silence is golden');
- }
- }
- public static function deactivate() {
- // Clean up temp chunks
- $upload_dir = wp_upload_dir();
- $chunks_dir = $upload_dir['basedir'] . '/studiou-fpp-chunks';
- if (is_dir($chunks_dir)) {
- $files = glob($chunks_dir . '/*');
- foreach ($files as $file) {
- if (is_file($file) && basename($file) !== '.htaccess' && basename($file) !== 'index.php') {
- unlink($file);
- }
- }
- }
- }
- }
- // Activation/deactivation hooks
- register_activation_hook(__FILE__, array('Studiou_WC_Free_Photo_Product', 'activate'));
- register_deactivation_hook(__FILE__, array('Studiou_WC_Free_Photo_Product', 'deactivate'));
- function run_studiou_wc_free_photo_product() {
- static $initialized = false;
- if ($initialized) {
- return;
- }
- $initialized = true;
- load_plugin_textdomain(
- 'studiou-wc-free-photo-product',
- false,
- dirname(plugin_basename(__FILE__)) . '/languages/'
- );
- new Studiou_WC_Free_Photo_Product();
- }
- add_action('plugins_loaded', 'run_studiou_wc_free_photo_product');
|