Changeset 2878118
- Timestamp:
- 03/10/2023 07:51:00 PM (2 years ago)
- Location:
- wc-pre-order
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
wc-pre-order/trunk/includes/Admin/Settings.php
r2550859 r2878118 7 7 * 8 8 * Class Settings 9 * 9 10 * @package SpringDevs\PreOrder\Admin 10 11 */ 11 class Settings 12 { 13 /** 14 * Settings constructor. 15 */ 16 public function __construct() 17 { 18 add_action("admin_menu", [$this, "create_admin_menu"]); 19 add_action('admin_init', [$this, 'register_settings']); 20 } 12 class Settings { 21 13 22 public function create_admin_menu() 23 { 24 $parent_slug = "edit.php?post_type=sdevs_preorder"; 25 $hook = add_submenu_page($parent_slug, __('Settings >> Pre-Order', 'sdevs_preorder'), __('Settings', 'sdevs_preorder'), 'manage_options', 'sdevs-preorder-settings', [$this, 'settings_content']); 14 /** 15 * Settings constructor. 16 */ 17 public function __construct() { 18 add_action( 'admin_menu', array( $this, 'create_admin_menu' ) ); 19 add_action( 'admin_init', array( $this, 'register_settings' ) ); 20 } 26 21 27 add_action('load-' . $hook, [$this, 'init_hooks']); 28 } 22 /** 23 * Admin menu setup. 24 */ 25 public function create_admin_menu() { 26 $parent_slug = 'edit.php?post_type=sdevs_preorder'; 27 $hook = add_submenu_page( $parent_slug, __( 'Settings ‹ Pre-Order', 'sdevs_preorder' ), __( 'Settings', 'sdevs_preorder' ), 'manage_options', 'sdevs-preorder-settings', array( $this, 'settings_content' ) ); 29 28 30 /** 31 * Initialize our hooks for the settings page 32 * 33 * @return void 34 */ 35 public function init_hooks() 36 { 37 add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']); 38 } 29 add_action( 'load-' . $hook, array( $this, 'init_hooks' ) ); 30 } 39 31 40 /** 41 * Load scripts and styles for the app 42 * 43 * @return void 44 */ 45 public function enqueue_scripts() 46 { 47 wp_enqueue_style('wp-color-picker'); 48 wp_enqueue_script('sdevs-preorder-adminjs'); 49 } 32 /** 33 * Initialize our hooks for the settings page 34 * 35 * @return void 36 */ 37 public function init_hooks() { 38 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 39 } 50 40 51 /** 52 * register settings options 53 **/ 54 public function register_settings() 55 { 56 register_setting('preorder_settings', 'preorder_default_add_to_cart_txt'); 57 register_setting('preorder_settings', 'preorder_no_date_label_color'); 58 register_setting('preorder_settings', 'preorder_rels_date_label_color'); 59 register_setting('preorder_settings', 'preorder_order_item_marker_txt'); 60 do_action('sdevs_preorder_register_settings', 'preorder_settings'); 61 } 41 /** 42 * Load scripts and styles for the app 43 * 44 * @return void 45 */ 46 public function enqueue_scripts() { 47 wp_enqueue_style( 'wp-color-picker' ); 48 wp_enqueue_script( 'sdevs-preorder-adminjs' ); 49 } 62 50 63 public function settings_content() 64 { 65 include 'views/settings.php'; 66 } 51 /** 52 * Register settings options 53 **/ 54 public function register_settings() { 55 register_setting( 'preorder_settings', 'preorder_label_position' ); 56 register_setting( 'preorder_settings', 'preorder_default_add_to_cart_txt' ); 57 register_setting( 'preorder_settings', 'preorder_no_date_label_color' ); 58 register_setting( 'preorder_settings', 'preorder_rels_date_label_color' ); 59 register_setting( 'preorder_settings', 'preorder_order_item_marker_txt' ); 60 do_action( 'sdevs_preorder_register_settings', 'preorder_settings' ); 61 } 62 63 /** 64 * HTML content settings. 65 */ 66 public function settings_content() { 67 include 'views/settings.php'; 68 } 67 69 } -
wc-pre-order/trunk/includes/Admin/views/settings.php
r2550859 r2878118 1 <?php 2 // phpcs:ignoreFile 3 ?> 1 4 <div class="wrap"> 2 <?php settings_errors(); ?> 3 <h1><?php _e('Pre-Order Settings', 'sdevs_preorder'); ?></h1> 4 <p><?php _e('Customize pre-order options', 'sdevs_preorder'); ?></p> 5 <form method="post" action="options.php"> 6 <?php settings_fields('preorder_settings'); ?> 7 <?php do_settings_sections('preorder_settings'); ?> 8 <table class="form-table"> 9 <tbody> 10 <tr> 11 <th scope="row"> 12 <label for="preorder_default_add_to_cart_txt"> 13 <?php esc_html_e('Default Add to Cart text', 'sdevs_preorder'); ?> 14 </label> 15 </th> 16 <td> 17 <input type="text" id="preorder_default_add_to_cart_txt" name="preorder_default_add_to_cart_txt" value="<?php echo esc_html(get_option('preorder_default_add_to_cart_txt', 'Pre-order Now')); ?>" /> 18 <p class="description"><?php _e("This text will be replaced on 'Add to Cart' button. By leaving it blank.", 'sdevs_preorder'); ?></p> 19 </td> 20 </tr> 21 <tr> 22 <th scope="row"> 23 <label for="preorder_no_date_label_color"> 24 <?php esc_html_e('No Date Label Color', 'sdevs_preorder'); ?> 25 </label> 26 </th> 27 <td> 28 <input id="preorder_no_date_label_color" class="sdevs-color-field" type="text" value="<?php echo get_option('preorder_no_date_label_color', '#47aeea'); ?>" name="preorder_no_date_label_color" data-default-color="#47aeea" /> 29 <p class="description"><?php echo sprintf(__('Text color for No Date Label. Default %s.', 'sdevs_preorder'), '<code>#47aeea</code>'); ?></p> 30 </td> 31 </tr> 32 <tr> 33 <th scope="row"> 34 <label for="preorder_rels_date_label_color"> 35 <?php esc_html_e('Release Date Label Color', 'sdevs_preorder'); ?> 36 </label> 37 </th> 38 <td> 39 <input id="preorder_rels_date_label_color" class="sdevs-color-field" type="text" value="<?php echo get_option('preorder_rels_date_label_color', '#000000'); ?>" name="preorder_rels_date_label_color" data-default-color="#000000" /> 40 <p class="description"><?php echo sprintf(__('Text color for Release Date Label Color. Default %s.', 'sdevs_preorder'), '<code>#000000</code>'); ?></p> 41 </td> 42 </tr> 5 <?php settings_errors(); ?> 6 <h1><?php _e( 'Pre-Order Settings', 'sdevs_preorder' ); ?></h1> 7 <p><?php _e( 'Customize pre-order options', 'sdevs_preorder' ); ?></p> 8 <form method="post" action="options.php"> 9 <?php settings_fields( 'preorder_settings' ); ?> 10 <?php do_settings_sections( 'preorder_settings' ); ?> 11 <?php 12 $button_positions = array( 13 'default' => __( 'Default', 'sdevs_preorder' ), 14 'after_product_image' => __( 'After Product Image', 'sdevs_preorder' ), 15 'after_product_title' => __( 'After Product Title', 'sdevs_preorder' ), 16 'before_product_title' => __( 'Before Product Title', 'sdevs_preorder' ), 17 'after_add_to_cart_button' => __( 'After Add To Cart Button', 'sdevs_preorder' ), 18 'inside_description' => __( 'Inside Description', 'sdevs_preorder' ), 19 ); 20 ?> 21 <table class="form-table"> 22 <tbody> 23 <tr> 24 <th scope="row"> 25 <label for="preorder_label_position"> 26 <?php esc_html_e( 'Label position', 'sdevs_preorder' ); ?> 27 </label> 28 </th> 29 <td> 30 <select name="preorder_label_position" id="preorder_label_position" style="width: 100%;"> 31 <?php foreach ( $button_positions as $button_position_key => $button_position_value ) : ?> 32 <option value="<?php echo $button_position_key; ?>" <?php if ( get_option( 'preorder_label_position', 'default' ) === $button_position_key ) { echo 'selected';}?>> 33 <?php echo $button_position_value; ?> 34 </option> 35 <?php endforeach; ?> 36 </select> 37 <p class="description"><?php esc_html_e( 'No Date & Release Date label position', 'sdevs_preorder' ); ?></p> 38 </td> 39 </tr> 40 <tr> 41 <th scope="row"> 42 <label for="preorder_default_add_to_cart_txt"> 43 <?php esc_html_e( 'Default Add to Cart text', 'sdevs_preorder' ); ?> 44 </label> 45 </th> 46 <td> 47 <input type="text" id="preorder_default_add_to_cart_txt" name="preorder_default_add_to_cart_txt" value="<?php echo esc_html( get_option( 'preorder_default_add_to_cart_txt', 'Pre-order Now' ) ); ?>" /> 48 <p class="description"><?php _e( "This text will be replaced on 'Add to Cart' button. By leaving it blank.", 'sdevs_preorder' ); ?></p> 49 </td> 50 </tr> 51 <tr> 52 <th scope="row"> 53 <label for="preorder_no_date_label_color"> 54 <?php esc_html_e( 'No Date Label Color', 'sdevs_preorder' ); ?> 55 </label> 56 </th> 57 <td> 58 <input id="preorder_no_date_label_color" class="sdevs-color-field" type="text" value="<?php echo get_option( 'preorder_no_date_label_color', '#47aeea' ); ?>" name="preorder_no_date_label_color" data-default-color="#47aeea" /> 59 <p class="description"><?php echo sprintf( __( 'Text color for No Date Label. Default %s.', 'sdevs_preorder' ), '<code>#47aeea</code>' ); ?></p> 60 </td> 61 </tr> 62 <tr> 63 <th scope="row"> 64 <label for="preorder_rels_date_label_color"> 65 <?php esc_html_e( 'Release Date Label Color', 'sdevs_preorder' ); ?> 66 </label> 67 </th> 68 <td> 69 <input id="preorder_rels_date_label_color" class="sdevs-color-field" type="text" value="<?php echo get_option( 'preorder_rels_date_label_color', '#000000' ); ?>" name="preorder_rels_date_label_color" data-default-color="#000000" /> 70 <p class="description"><?php echo sprintf( __( 'Text color for Release Date Label Color. Default %s.', 'sdevs_preorder' ), '<code>#000000</code>' ); ?></p> 71 </td> 72 </tr> 43 73 44 45 46 47 <?php esc_html_e('Order item marker Text', 'sdevs_preorder'); ?>48 49 50 51 <input type="text" id="preorder_order_item_marker_txt" name="preorder_order_item_marker_txt" value="<?php echo esc_html(get_option('preorder_order_item_marker_txt', 'Pre-Order product')); ?>" />52 53 74 <tr> 75 <th scope="row"> 76 <label for="preorder_order_item_marker_txt"> 77 <?php esc_html_e( 'Order item marker Text', 'sdevs_preorder' ); ?> 78 </label> 79 </th> 80 <td> 81 <input type="text" id="preorder_order_item_marker_txt" name="preorder_order_item_marker_txt" value="<?php echo esc_html( get_option( 'preorder_order_item_marker_txt', 'Pre-Order product' ) ); ?>" /> 82 </td> 83 </tr> 54 84 55 <?php do_action("sdevs_preorder_setting_fields"); ?>56 57 85 <?php do_action( 'sdevs_preorder_setting_fields' ); ?> 86 </tbody> 87 </table> 58 88 59 89 <?php submit_button(); ?> 60 90 61 91 </form> 62 92 </div> -
wc-pre-order/trunk/includes/Frontend/Product.php
r2550859 r2878118 7 7 /** 8 8 * Class Product 9 * 9 10 * @package SpringDevs\PreOrder\Frontend 10 11 */ 11 class Product 12 { 12 class Product { 13 13 14 public function __construct()15 {16 add_filter('woocommerce_product_single_add_to_cart_text', array($this, 'change_add_to_cart_text'));17 add_filter('woocommerce_product_add_to_cart_text', array($this, 'change_add_to_cart_text'));18 add_action('woocommerce_single_product_summary', [$this, 'put_product_txt'], 20);19 add_filter('woocommerce_add_to_cart_validation', [$this, 'filter_add_to_cart_validation'], 20, 4);20 }21 14 22 public function change_add_to_cart_text($text) 23 { 24 global $product; 25 if (!$product) return $text; 26 $has_preorder = $product->get_meta("_has_preorder", true); 27 if ($has_preorder) { 28 $labels = $product->get_meta("_product_preorder_labels", true); 29 $cart_text = $labels['add_to_cart_label']; 30 if ($cart_text || $cart_text != '') { 31 return $cart_text; 32 } 33 return get_option("preorder_default_add_to_cart_txt", "Pre-order Now"); 34 } 35 return $text; 36 } 15 public function __construct() { 16 add_filter( 'woocommerce_product_single_add_to_cart_text', array( $this, 'change_add_to_cart_text' ) ); 17 add_filter( 'woocommerce_product_add_to_cart_text', array( $this, 'change_add_to_cart_text' ) ); 18 add_filter( 'woocommerce_add_to_cart_validation', array( $this, 'filter_add_to_cart_validation' ), 20, 4 ); 37 19 38 public function put_product_txt() 39 { 40 global $product; 41 $has_preorder = Helper::has_preorder($product->get_id()); 42 if ($has_preorder) { 43 $this->display_txt($product); 44 } 45 } 20 $position = get_option( 'preorder_label_position', 'default' ); 21 if ( 'default' === $position ) { 22 add_action( 'woocommerce_single_product_summary', array( $this, 'put_product_txt' ), 20 ); 23 } elseif ( 'after_product_image' === $position ) { 24 add_action( 'woocommerce_product_thumbnails', array( $this, 'put_product_txt' ) ); 25 } elseif ( 'after_product_title' === $position ) { 26 add_action( 'woocommerce_single_product_summary', array( $this, 'put_product_txt' ), 7 ); 27 } elseif ( 'before_product_title' === $position ) { 28 add_action( 'woocommerce_single_product_summary', array( $this, 'put_product_txt' ), 1 ); 29 } elseif ( 'after_add_to_cart_button' === $position ) { 30 add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'put_product_txt' ) ); 31 } elseif ( 'inside_description' === $position ) { 32 add_action( 'woocommerce_after_single_product_summary', array( $this, 'put_product_txt' ) ); 33 } 34 } 46 35 47 public function filter_add_to_cart_validation($passed, $product_id, $quantity, $variation_id = 0) 48 { 49 $has_preorder = Helper::has_preorder($product_id); 50 if ($has_preorder) { 51 $cartProducts = WC()->cart->get_cart(); 52 foreach ($cartProducts as $key => $values) { 53 $cart_product = $values['data']; 54 $has_cart_preorder = Helper::has_preorder($cart_product->get_id()); 55 if (!$has_cart_preorder) { 56 wc_add_notice(__("Currently You have Non-Preorder product on cart !!", "sdevs_preorder"), 'error'); 57 return false; 58 } 59 } 60 } else { 61 $cartProducts = WC()->cart->get_cart(); 62 foreach ($cartProducts as $key => $values) { 63 $cart_product = $values['data']; 64 $has_cart_preorder = Helper::has_preorder($cart_product->get_id()); 65 if ($has_cart_preorder) { 66 wc_add_notice(__("Currently You have Preorder product on cart !!", "sdevs_preorder"), 'error'); 67 return false; 68 } 69 } 70 } 71 return $passed; 72 } 36 public function change_add_to_cart_text( $text ) { 37 global $product; 38 if ( ! $product ) { 39 return $text; 40 } 41 $has_preorder = $product->get_meta( '_has_preorder', true ); 42 if ( $has_preorder ) { 43 $labels = $product->get_meta( '_product_preorder_labels', true ); 44 $cart_text = $labels['add_to_cart_label']; 45 if ( $cart_text || $cart_text != '' ) { 46 return $cart_text; 47 } 48 return get_option( 'preorder_default_add_to_cart_txt', 'Pre-order Now' ); 49 } 50 return $text; 51 } 73 52 74 public function display_txt($product, $echo = true) 75 { 76 $labels = $product->get_meta("_product_preorder_labels", true); 77 $rels_date = $product->get_meta("_preorder_product_release_date", true); 78 $summery_text = null; 79 $attr = null; 80 if ($rels_date) { 81 $rels_txt = $labels['rels_date_label']; 82 $rels_txt = nl2br($rels_txt); 83 preg_match_all("/\[([^\]]*)\]/", $rels_txt, $matches); 84 $matches = $matches[1]; 85 foreach ($matches as $meta_key) { 86 if ('_release_date' === $meta_key) { 87 $replaced_txt = date('F d, Y', strtotime($rels_date)); 88 $rels_txt = str_replace('[' . $meta_key . ']', $replaced_txt, $rels_txt); 89 } 90 } 91 $summery_text = $rels_txt; 92 $attr = 'style="color: ' . get_option('preorder_rels_date_label_color', '#000000') . '"'; 93 } else { 94 $summery_text = $labels['no_date_label']; 95 $attr = 'style="color: ' . get_option('preorder_no_date_label_color', '#47aeea') . '"'; 96 } 97 if ($echo) : 98 ?> 99 <p> 100 <strong <?php echo $attr; ?>><?php _e($summery_text, 'sdevs_preorder'); ?></strong> 101 </p> 102 <?php 103 else : 104 return $summery_text; 105 endif; 106 } 53 public function put_product_txt() { 54 global $product; 55 $has_preorder = Helper::has_preorder( $product->get_id() ); 56 if ( $has_preorder ) { 57 $this->display_txt( $product ); 58 } 59 } 60 61 public function filter_add_to_cart_validation( $passed, $product_id, $quantity, $variation_id = 0 ) { 62 $has_preorder = Helper::has_preorder( $product_id ); 63 if ( $has_preorder ) { 64 $cartProducts = WC()->cart->get_cart(); 65 foreach ( $cartProducts as $key => $values ) { 66 $cart_product = $values['data']; 67 $has_cart_preorder = Helper::has_preorder( $cart_product->get_id() ); 68 if ( ! $has_cart_preorder ) { 69 wc_add_notice( __( 'Currently You have Non-Preorder product on cart !!', 'sdevs_preorder' ), 'error' ); 70 return false; 71 } 72 } 73 } else { 74 $cartProducts = WC()->cart->get_cart(); 75 foreach ( $cartProducts as $key => $values ) { 76 $cart_product = $values['data']; 77 $has_cart_preorder = Helper::has_preorder( $cart_product->get_id() ); 78 if ( $has_cart_preorder ) { 79 wc_add_notice( __( 'Currently You have Preorder product on cart !!', 'sdevs_preorder' ), 'error' ); 80 return false; 81 } 82 } 83 } 84 return $passed; 85 } 86 87 public function display_txt( $product, $echo = true ) { 88 $labels = $product->get_meta( '_product_preorder_labels', true ); 89 $rels_date = $product->get_meta( '_preorder_product_release_date', true ); 90 $summery_text = null; 91 $attr = null; 92 if ( $rels_date ) { 93 $rels_txt = $labels['rels_date_label']; 94 $rels_txt = nl2br( $rels_txt ); 95 preg_match_all( '/\[([^\]]*)\]/', $rels_txt, $matches ); 96 $matches = $matches[1]; 97 foreach ( $matches as $meta_key ) { 98 if ( '_release_date' === $meta_key ) { 99 $replaced_txt = date( 'F d, Y', strtotime( $rels_date ) ); 100 $rels_txt = str_replace( '[' . $meta_key . ']', $replaced_txt, $rels_txt ); 101 } 102 } 103 $summery_text = $rels_txt; 104 $attr = 'style="color: ' . get_option( 'preorder_rels_date_label_color', '#000000' ) . '"'; 105 } else { 106 $summery_text = $labels['no_date_label']; 107 $attr = 'style="color: ' . get_option( 'preorder_no_date_label_color', '#47aeea' ) . '"'; 108 } 109 if ( $echo ) : 110 ?> 111 <p> 112 <strong <?php echo $attr; ?>><?php _e( $summery_text, 'sdevs_preorder' ); ?></strong> 113 </p> 114 <?php 115 else : 116 return $summery_text; 117 endif; 118 } 107 119 } -
wc-pre-order/trunk/index.php
r2550859 r2878118 1 1 <?php 2 // silence is golden2 // silence is golden -
wc-pre-order/trunk/pre-order.php
r2622108 r2878118 4 4 Plugin URI: https://wordpress.org/plugins/sdevs-wc-preorder 5 5 Description: Allow customers to pre-order from your store. 6 Version: 1.0. 36 Version: 1.0.4 7 7 Author: SpringDevs 8 8 Author URI: https://springdevs.com/ … … 40 40 41 41 // don't call the file directly 42 if ( !defined('ABSPATH')) {43 42 if ( ! defined( 'ABSPATH' ) ) { 43 exit; 44 44 } 45 45 … … 51 51 * @class Sdevs_preorder The class that holds the entire Sdevs_preorder plugin 52 52 */ 53 final class Sdevs_preorder 54 { 55 /** 56 * Plugin version 57 * 58 * @var string 59 */ 60 const version = '1.0.3'; 61 62 /** 63 * Holds various class instances 64 * 65 * @var array 66 */ 67 private $container = []; 68 69 /** 70 * Constructor for the Sdevs_preorder class 71 * 72 * Sets up all the appropriate hooks and actions 73 * within our plugin. 74 */ 75 private function __construct() 76 { 77 $this->define_constants(); 78 79 register_activation_hook(__FILE__, [$this, 'activate']); 80 register_deactivation_hook(__FILE__, [$this, 'deactivate']); 81 82 add_action('plugins_loaded', [$this, 'init_plugin']); 83 } 84 85 /** 86 * Initializes the Sdevs_preorder() class 87 * 88 * Checks for an existing Sdevs_preorder() instance 89 * and if it doesn't find one, creates it. 90 * 91 * @return Sdevs_preorder|bool 92 */ 93 public static function init() 94 { 95 static $instance = false; 96 97 if (!$instance) { 98 $instance = new Sdevs_preorder(); 99 } 100 101 return $instance; 102 } 103 104 /** 105 * Magic getter to bypass referencing plugin. 106 * 107 * @param $prop 108 * 109 * @return mixed 110 */ 111 public function __get($prop) 112 { 113 if (array_key_exists($prop, $this->container)) { 114 return $this->container[$prop]; 115 } 116 117 return $this->{$prop}; 118 } 119 120 /** 121 * Magic isset to bypass referencing plugin. 122 * 123 * @param $prop 124 * 125 * @return mixed 126 */ 127 public function __isset($prop) 128 { 129 return isset($this->{$prop}) || isset($this->container[$prop]); 130 } 131 132 /** 133 * Define the constants 134 * 135 * @return void 136 */ 137 public function define_constants() 138 { 139 define('SDEVS_PREORDER_VERSION', self::version); 140 define('SDEVS_PREORDER_FILE', __FILE__); 141 define('SDEVS_PREORDER_PATH', dirname(SDEVS_PREORDER_FILE)); 142 define('SDEVS_PREORDER_INCLUDES', SDEVS_PREORDER_PATH . '/includes'); 143 define('SDEVS_PREORDER_TEMPLATES', SDEVS_PREORDER_PATH . '/templates/'); 144 define('SDEVS_PREORDER_URL', plugins_url('', SDEVS_PREORDER_FILE)); 145 define('SDEVS_PREORDER_ASSETS', SDEVS_PREORDER_URL . '/assets'); 146 } 147 148 /** 149 * Load the plugin after all plugis are loaded 150 * 151 * @return void 152 */ 153 public function init_plugin() 154 { 155 if (!class_exists('WooCommerce')) { 156 add_action('admin_notices', function () { 157 include 'includes/Admin/views/plugin-notice.php'; 158 }); 159 return; 160 } 161 $this->includes(); 162 $this->init_hooks(); 163 } 164 165 /** 166 * Placeholder for activation function 167 * 168 * Nothing being called here yet. 169 */ 170 public function activate() 171 { 172 $installer = new SpringDevs\PreOrder\Installer(); 173 $installer->run(); 174 } 175 176 /** 177 * Placeholder for deactivation function 178 * 179 * Nothing being called here yet. 180 */ 181 public function deactivate() 182 { 183 } 184 185 /** 186 * Include the required files 187 * 188 * @return void 189 */ 190 public function includes() 191 { 192 if ($this->is_request('admin')) { 193 $this->container['admin'] = new SpringDevs\PreOrder\Admin(); 194 } 195 196 if ($this->is_request('frontend')) { 197 $this->container['frontend'] = new SpringDevs\PreOrder\Frontend(); 198 } 199 200 if ($this->is_request('ajax')) { 201 // require_once SDEVS_PREORDER_INCLUDES . '/class-ajax.php'; 202 } 203 } 204 205 /** 206 * Initialize the hooks 207 * 208 * @return void 209 */ 210 public function init_hooks() 211 { 212 add_action('init', [$this, 'init_classes']); 213 214 // Localize our plugin 215 add_action('init', [$this, 'localization_setup']); 216 } 217 218 /** 219 * Instantiate the required classes 220 * 221 * @return void 222 */ 223 public function init_classes() 224 { 225 if ($this->is_request('ajax')) { 226 // $this->container['ajax'] = new SpringDevs\PreOrder\Ajax(); 227 } 228 229 $this->container['api'] = new SpringDevs\PreOrder\Api(); 230 $this->container['assets'] = new SpringDevs\PreOrder\Assets(); 231 } 232 233 /** 234 * Initialize plugin for localization 235 * 236 * @uses load_plugin_textdomain() 237 */ 238 public function localization_setup() 239 { 240 load_plugin_textdomain('sdevs_preorder', false, dirname(plugin_basename(__FILE__)) . '/languages/'); 241 } 242 243 /** 244 * What type of request is this? 245 * 246 * @param string $type admin, ajax, cron or frontend. 247 * 248 * @return bool 249 */ 250 private function is_request($type) 251 { 252 switch ($type) { 253 case 'admin': 254 return is_admin(); 255 256 case 'ajax': 257 return defined('DOING_AJAX'); 258 259 case 'rest': 260 return defined('REST_REQUEST'); 261 262 case 'cron': 263 return defined('DOING_CRON'); 264 265 case 'frontend': 266 return (!is_admin() || defined('DOING_AJAX')) && !defined('DOING_CRON'); 267 } 268 } 53 final class Sdevs_preorder { 54 55 /** 56 * Plugin version 57 * 58 * @var string 59 */ 60 const version = '1.0.4'; 61 62 /** 63 * Holds various class instances 64 * 65 * @var array 66 */ 67 private $container = array(); 68 69 /** 70 * Constructor for the Sdevs_preorder class 71 * 72 * Sets up all the appropriate hooks and actions 73 * within our plugin. 74 */ 75 private function __construct() { 76 $this->define_constants(); 77 78 register_activation_hook( __FILE__, array( $this, 'activate' ) ); 79 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); 80 81 add_action( 'plugins_loaded', array( $this, 'init_plugin' ) ); 82 } 83 84 /** 85 * Initializes the Sdevs_preorder() class 86 * 87 * Checks for an existing Sdevs_preorder() instance 88 * and if it doesn't find one, creates it. 89 * 90 * @return Sdevs_preorder|bool 91 */ 92 public static function init() { 93 static $instance = false; 94 95 if ( ! $instance ) { 96 $instance = new Sdevs_preorder(); 97 } 98 99 return $instance; 100 } 101 102 /** 103 * Magic getter to bypass referencing plugin. 104 * 105 * @param $prop 106 * 107 * @return mixed 108 */ 109 public function __get( $prop ) { 110 if ( array_key_exists( $prop, $this->container ) ) { 111 return $this->container[ $prop ]; 112 } 113 114 return $this->{$prop}; 115 } 116 117 /** 118 * Magic isset to bypass referencing plugin. 119 * 120 * @param $prop 121 * 122 * @return mixed 123 */ 124 public function __isset( $prop ) { 125 return isset( $this->{$prop} ) || isset( $this->container[ $prop ] ); 126 } 127 128 /** 129 * Define the constants 130 * 131 * @return void 132 */ 133 public function define_constants() { 134 define( 'SDEVS_PREORDER_VERSION', self::version ); 135 define( 'SDEVS_PREORDER_FILE', __FILE__ ); 136 define( 'SDEVS_PREORDER_PATH', dirname( SDEVS_PREORDER_FILE ) ); 137 define( 'SDEVS_PREORDER_INCLUDES', SDEVS_PREORDER_PATH . '/includes' ); 138 define( 'SDEVS_PREORDER_TEMPLATES', SDEVS_PREORDER_PATH . '/templates/' ); 139 define( 'SDEVS_PREORDER_URL', plugins_url( '', SDEVS_PREORDER_FILE ) ); 140 define( 'SDEVS_PREORDER_ASSETS', SDEVS_PREORDER_URL . '/assets' ); 141 } 142 143 /** 144 * Load the plugin after all plugis are loaded 145 * 146 * @return void 147 */ 148 public function init_plugin() { 149 if ( ! class_exists( 'WooCommerce' ) ) { 150 add_action( 151 'admin_notices', 152 function () { 153 include 'includes/Admin/views/plugin-notice.php'; 154 } 155 ); 156 return; 157 } 158 $this->includes(); 159 $this->init_hooks(); 160 } 161 162 /** 163 * Placeholder for activation function 164 * 165 * Nothing being called here yet. 166 */ 167 public function activate() { 168 $installer = new SpringDevs\PreOrder\Installer(); 169 $installer->run(); 170 } 171 172 /** 173 * Placeholder for deactivation function 174 * 175 * Nothing being called here yet. 176 */ 177 public function deactivate() { 178 } 179 180 /** 181 * Include the required files 182 * 183 * @return void 184 */ 185 public function includes() { 186 if ( $this->is_request( 'admin' ) ) { 187 $this->container['admin'] = new SpringDevs\PreOrder\Admin(); 188 } 189 190 if ( $this->is_request( 'frontend' ) ) { 191 $this->container['frontend'] = new SpringDevs\PreOrder\Frontend(); 192 } 193 194 if ( $this->is_request( 'ajax' ) ) { 195 // require_once SDEVS_PREORDER_INCLUDES . '/class-ajax.php'; 196 } 197 } 198 199 /** 200 * Initialize the hooks 201 * 202 * @return void 203 */ 204 public function init_hooks() { 205 add_action( 'init', array( $this, 'init_classes' ) ); 206 207 // Localize our plugin 208 add_action( 'init', array( $this, 'localization_setup' ) ); 209 } 210 211 /** 212 * Instantiate the required classes 213 * 214 * @return void 215 */ 216 public function init_classes() { 217 if ( $this->is_request( 'ajax' ) ) { 218 // $this->container['ajax'] = new SpringDevs\PreOrder\Ajax(); 219 } 220 221 $this->container['api'] = new SpringDevs\PreOrder\Api(); 222 $this->container['assets'] = new SpringDevs\PreOrder\Assets(); 223 } 224 225 /** 226 * Initialize plugin for localization 227 * 228 * @uses load_plugin_textdomain() 229 */ 230 public function localization_setup() { 231 load_plugin_textdomain( 'sdevs_preorder', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 232 } 233 234 /** 235 * What type of request is this? 236 * 237 * @param string $type admin, ajax, cron or frontend. 238 * 239 * @return bool 240 */ 241 private function is_request( $type ) { 242 switch ( $type ) { 243 case 'admin': 244 return is_admin(); 245 246 case 'ajax': 247 return defined( 'DOING_AJAX' ); 248 249 case 'rest': 250 return defined( 'REST_REQUEST' ); 251 252 case 'cron': 253 return defined( 'DOING_CRON' ); 254 255 case 'frontend': 256 return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ); 257 } 258 } 269 259 } // Sdevs_preorder 270 260 … … 274 264 * @return \Sdevs_preorder|bool 275 265 */ 276 function sdevs_preorder() 277 { 278 return Sdevs_preorder::init(); 266 function sdevs_preorder() { 267 return Sdevs_preorder::init(); 279 268 } 280 269 -
wc-pre-order/trunk/readme.txt
r2741734 r2878118 1 1 === Pre Order Addon for WooCommerce - Advance Order/Backorder Plugin === 2 Contributors: springdevs, naminbd, ok9xnirab2 Contributors: springdevs, naminbd, istiaqnirab 3 3 Donate link: https://springdevs.com/ 4 4 Tags: WooCommerce, preorder, pre order, pre-order, woocommerce-preorder 5 5 Requires at least: 4.0 6 Tested up to: 6.07 Stable tag: 1.0. 36 Tested up to: 5.8 7 Stable tag: 1.0.4 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later … … 50 50 == Changelog == 51 51 52 = 1.0.4 - March 11, 2023 = 53 * Label placement setting added 54 52 55 = 1.0.2 - October 30, 2021 = 53 56 * Tested up to wordpress v5.8 -
wc-pre-order/trunk/templates/myaccount/preorders.php
r2550859 r2878118 5 5 * 6 6 * This template can be overridden by copying it to yourtheme/preorder/myaccount/preorders.php 7 *8 7 */ 9 8 … … 44 43 foreach ($order->get_items() as $order_item) { 45 44 if ($order_item['product_id'] == $product_id) { 46 $price = wc_price($order_item->get_subtotal(), [ 45 $price = wc_price( 46 $order_item->get_subtotal(), [ 47 47 'currency' => $order->get_currency() 48 ]); 48 ] 49 ); 49 50 $item_rels_date = $order_item->get_meta('_relase_date', true); 50 51 if ($item_rels_date) { … … 53 54 } 54 55 } 55 ?>56 ?> 56 57 <tr> 57 58 <td> … … 68 69 </td> 69 70 </tr> 70 <?php71 <?php 71 72 endwhile; 72 73 endif; -
wc-pre-order/trunk/vendor/autoload.php
r2550859 r2878118 3 3 // autoload.php @generated by Composer 4 4 5 if (PHP_VERSION_ID < 50600) { 6 if (!headers_sent()) { 7 header('HTTP/1.1 500 Internal Server Error'); 8 } 9 $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; 10 if (!ini_get('display_errors')) { 11 if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { 12 fwrite(STDERR, $err); 13 } elseif (!headers_sent()) { 14 echo $err; 15 } 16 } 17 trigger_error( 18 $err, 19 E_USER_ERROR 20 ); 21 } 22 5 23 require_once __DIR__ . '/composer/autoload_real.php'; 6 24 -
wc-pre-order/trunk/vendor/composer/ClassLoader.php
r2550859 r2878118 43 43 class ClassLoader 44 44 { 45 /** @var \Closure(string):void */ 46 private static $includeFile; 47 48 /** @var ?string */ 49 private $vendorDir; 50 45 51 // PSR-4 52 /** 53 * @var array[] 54 * @psalm-var array<string, array<string, int>> 55 */ 46 56 private $prefixLengthsPsr4 = array(); 57 /** 58 * @var array[] 59 * @psalm-var array<string, array<int, string>> 60 */ 47 61 private $prefixDirsPsr4 = array(); 62 /** 63 * @var array[] 64 * @psalm-var array<string, string> 65 */ 48 66 private $fallbackDirsPsr4 = array(); 49 67 50 68 // PSR-0 69 /** 70 * @var array[] 71 * @psalm-var array<string, array<string, string[]>> 72 */ 51 73 private $prefixesPsr0 = array(); 74 /** 75 * @var array[] 76 * @psalm-var array<string, string> 77 */ 52 78 private $fallbackDirsPsr0 = array(); 53 79 80 /** @var bool */ 54 81 private $useIncludePath = false; 82 83 /** 84 * @var string[] 85 * @psalm-var array<string, string> 86 */ 55 87 private $classMap = array(); 88 89 /** @var bool */ 56 90 private $classMapAuthoritative = false; 91 92 /** 93 * @var bool[] 94 * @psalm-var array<string, bool> 95 */ 57 96 private $missingClasses = array(); 97 98 /** @var ?string */ 58 99 private $apcuPrefix; 59 100 101 /** 102 * @var self[] 103 */ 104 private static $registeredLoaders = array(); 105 106 /** 107 * @param ?string $vendorDir 108 */ 109 public function __construct($vendorDir = null) 110 { 111 $this->vendorDir = $vendorDir; 112 self::initializeIncludeClosure(); 113 } 114 115 /** 116 * @return string[] 117 */ 60 118 public function getPrefixes() 61 119 { … … 67 125 } 68 126 127 /** 128 * @return array[] 129 * @psalm-return array<string, array<int, string>> 130 */ 69 131 public function getPrefixesPsr4() 70 132 { … … 72 134 } 73 135 136 /** 137 * @return array[] 138 * @psalm-return array<string, string> 139 */ 74 140 public function getFallbackDirs() 75 141 { … … 77 143 } 78 144 145 /** 146 * @return array[] 147 * @psalm-return array<string, string> 148 */ 79 149 public function getFallbackDirsPsr4() 80 150 { … … 82 152 } 83 153 154 /** 155 * @return string[] Array of classname => path 156 * @psalm-return array<string, string> 157 */ 84 158 public function getClassMap() 85 159 { … … 88 162 89 163 /** 90 * @param array $classMap Class to filename map 164 * @param string[] $classMap Class to filename map 165 * @psalm-param array<string, string> $classMap 166 * 167 * @return void 91 168 */ 92 169 public function addClassMap(array $classMap) … … 103 180 * appending or prepending to the ones previously set for this prefix. 104 181 * 105 * @param string $prefix The prefix 106 * @param array|string $paths The PSR-0 root directories 107 * @param bool $prepend Whether to prepend the directories 182 * @param string $prefix The prefix 183 * @param string[]|string $paths The PSR-0 root directories 184 * @param bool $prepend Whether to prepend the directories 185 * 186 * @return void 108 187 */ 109 188 public function add($prefix, $paths, $prepend = false) … … 148 227 * appending or prepending to the ones previously set for this namespace. 149 228 * 150 * @param string $prefix The prefix/namespace, with trailing '\\'151 * @param array|string $paths The PSR-4 base directories152 * @param bool $prepend Whether to prepend the directories229 * @param string $prefix The prefix/namespace, with trailing '\\' 230 * @param string[]|string $paths The PSR-4 base directories 231 * @param bool $prepend Whether to prepend the directories 153 232 * 154 233 * @throws \InvalidArgumentException 234 * 235 * @return void 155 236 */ 156 237 public function addPsr4($prefix, $paths, $prepend = false) … … 196 277 * replacing any others previously set for this prefix. 197 278 * 198 * @param string $prefix The prefix 199 * @param array|string $paths The PSR-0 base directories 279 * @param string $prefix The prefix 280 * @param string[]|string $paths The PSR-0 base directories 281 * 282 * @return void 200 283 */ 201 284 public function set($prefix, $paths) … … 212 295 * replacing any others previously set for this namespace. 213 296 * 214 * @param string $prefix The prefix/namespace, with trailing '\\'215 * @param array|string $paths The PSR-4 base directories297 * @param string $prefix The prefix/namespace, with trailing '\\' 298 * @param string[]|string $paths The PSR-4 base directories 216 299 * 217 300 * @throws \InvalidArgumentException 301 * 302 * @return void 218 303 */ 219 304 public function setPsr4($prefix, $paths) … … 235 320 * 236 321 * @param bool $useIncludePath 322 * 323 * @return void 237 324 */ 238 325 public function setUseIncludePath($useIncludePath) … … 257 344 * 258 345 * @param bool $classMapAuthoritative 346 * 347 * @return void 259 348 */ 260 349 public function setClassMapAuthoritative($classMapAuthoritative) … … 277 366 * 278 367 * @param string|null $apcuPrefix 368 * 369 * @return void 279 370 */ 280 371 public function setApcuPrefix($apcuPrefix) … … 297 388 * 298 389 * @param bool $prepend Whether to prepend the autoloader or not 390 * 391 * @return void 299 392 */ 300 393 public function register($prepend = false) 301 394 { 302 395 spl_autoload_register(array($this, 'loadClass'), true, $prepend); 396 397 if (null === $this->vendorDir) { 398 return; 399 } 400 401 if ($prepend) { 402 self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders; 403 } else { 404 unset(self::$registeredLoaders[$this->vendorDir]); 405 self::$registeredLoaders[$this->vendorDir] = $this; 406 } 303 407 } 304 408 305 409 /** 306 410 * Unregisters this instance as an autoloader. 411 * 412 * @return void 307 413 */ 308 414 public function unregister() 309 415 { 310 416 spl_autoload_unregister(array($this, 'loadClass')); 417 418 if (null !== $this->vendorDir) { 419 unset(self::$registeredLoaders[$this->vendorDir]); 420 } 311 421 } 312 422 … … 315 425 * 316 426 * @param string $class The name of the class 317 * @return bool|null True if loaded, null otherwise427 * @return true|null True if loaded, null otherwise 318 428 */ 319 429 public function loadClass($class) 320 430 { 321 431 if ($file = $this->findFile($class)) { 322 includeFile($file); 432 $includeFile = self::$includeFile; 433 $includeFile($file); 323 434 324 435 return true; 325 436 } 437 438 return null; 326 439 } 327 440 … … 368 481 } 369 482 483 /** 484 * Returns the currently registered loaders indexed by their corresponding vendor directories. 485 * 486 * @return self[] 487 */ 488 public static function getRegisteredLoaders() 489 { 490 return self::$registeredLoaders; 491 } 492 493 /** 494 * @param string $class 495 * @param string $ext 496 * @return string|false 497 */ 370 498 private function findFileWithExtension($class, $ext) 371 499 { … … 433 561 return false; 434 562 } 563 564 /** 565 * @return void 566 */ 567 private static function initializeIncludeClosure() 568 { 569 if (self::$includeFile !== null) { 570 return; 571 } 572 573 /** 574 * Scope isolated include. 575 * 576 * Prevents access to $this/self from included files. 577 * 578 * @param string $file 579 * @return void 580 */ 581 self::$includeFile = \Closure::bind(static function($file) { 582 include $file; 583 }, null, null); 584 } 435 585 } 436 437 /**438 * Scope isolated include.439 *440 * Prevents access to $this/self from included files.441 */442 function includeFile($file)443 {444 include $file;445 } -
wc-pre-order/trunk/vendor/composer/InstalledVersions.php
r2550859 r2878118 1 1 <?php 2 2 3 4 5 6 7 8 9 10 11 3 /* 4 * This file is part of Composer. 5 * 6 * (c) Nils Adermann <[email protected]> 7 * Jordi Boggiano <[email protected]> 8 * 9 * For the full copyright and license information, please view the LICENSE 10 * file that was distributed with this source code. 11 */ 12 12 13 13 namespace Composer; 14 14 15 use Composer\Autoload\ClassLoader; 15 16 use Composer\Semver\VersionParser; 16 17 17 18 19 20 21 18 /** 19 * This class is copied in every Composer installed project and available to all 20 * 21 * See also https://getcomposer.org/doc/07-runtime.md#installed-versions 22 * 23 * To require its presence, you can require `composer-runtime-api ^2.0` 24 */ 22 25 class InstalledVersions 23 26 { 24 private static $installed = array ( 25 'root' => 26 array ( 27 'pretty_version' => '1.0.0+no-version-set', 28 'version' => '1.0.0.0', 29 'aliases' => 30 array ( 31 ), 32 'reference' => NULL, 33 'name' => 'springdevs/pre-order', 34 ), 35 'versions' => 36 array ( 37 'springdevs/pre-order' => 38 array ( 39 'pretty_version' => '1.0.0+no-version-set', 40 'version' => '1.0.0.0', 41 'aliases' => 42 array ( 43 ), 44 'reference' => NULL, 45 ), 46 ), 47 ); 48 49 50 51 52 53 54 55 public static function getInstalledPackages() 56 { 57 return array_keys(self::$installed['versions']); 27 /** 28 * @var mixed[]|null 29 * @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}|array{}|null 30 */ 31 private static $installed; 32 33 /** 34 * @var bool|null 35 */ 36 private static $canGetVendors; 37 38 /** 39 * @var array[] 40 * @psalm-var array<string, array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}> 41 */ 42 private static $installedByVendor = array(); 43 44 /** 45 * Returns a list of all package names which are present, either by being installed, replaced or provided 46 * 47 * @return string[] 48 * @psalm-return list<string> 49 */ 50 public static function getInstalledPackages() 51 { 52 $packages = array(); 53 foreach (self::getInstalled() as $installed) { 54 $packages[] = array_keys($installed['versions']); 55 } 56 57 if (1 === \count($packages)) { 58 return $packages[0]; 59 } 60 61 return array_keys(array_flip(\call_user_func_array('array_merge', $packages))); 62 } 63 64 /** 65 * Returns a list of all package names with a specific type e.g. 'library' 66 * 67 * @param string $type 68 * @return string[] 69 * @psalm-return list<string> 70 */ 71 public static function getInstalledPackagesByType($type) 72 { 73 $packagesByType = array(); 74 75 foreach (self::getInstalled() as $installed) { 76 foreach ($installed['versions'] as $name => $package) { 77 if (isset($package['type']) && $package['type'] === $type) { 78 $packagesByType[] = $name; 79 } 80 } 81 } 82 83 return $packagesByType; 84 } 85 86 /** 87 * Checks whether the given package is installed 88 * 89 * This also returns true if the package name is provided or replaced by another package 90 * 91 * @param string $packageName 92 * @param bool $includeDevRequirements 93 * @return bool 94 */ 95 public static function isInstalled($packageName, $includeDevRequirements = true) 96 { 97 foreach (self::getInstalled() as $installed) { 98 if (isset($installed['versions'][$packageName])) { 99 return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']); 100 } 101 } 102 103 return false; 104 } 105 106 /** 107 * Checks whether the given package satisfies a version constraint 108 * 109 * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call: 110 * 111 * Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3') 112 * 113 * @param VersionParser $parser Install composer/semver to have access to this class and functionality 114 * @param string $packageName 115 * @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package 116 * @return bool 117 */ 118 public static function satisfies(VersionParser $parser, $packageName, $constraint) 119 { 120 $constraint = $parser->parseConstraints($constraint); 121 $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); 122 123 return $provided->matches($constraint); 124 } 125 126 /** 127 * Returns a version constraint representing all the range(s) which are installed for a given package 128 * 129 * It is easier to use this via isInstalled() with the $constraint argument if you need to check 130 * whether a given version of a package is installed, and not just whether it exists 131 * 132 * @param string $packageName 133 * @return string Version constraint usable with composer/semver 134 */ 135 public static function getVersionRanges($packageName) 136 { 137 foreach (self::getInstalled() as $installed) { 138 if (!isset($installed['versions'][$packageName])) { 139 continue; 140 } 141 142 $ranges = array(); 143 if (isset($installed['versions'][$packageName]['pretty_version'])) { 144 $ranges[] = $installed['versions'][$packageName]['pretty_version']; 145 } 146 if (array_key_exists('aliases', $installed['versions'][$packageName])) { 147 $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']); 148 } 149 if (array_key_exists('replaced', $installed['versions'][$packageName])) { 150 $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']); 151 } 152 if (array_key_exists('provided', $installed['versions'][$packageName])) { 153 $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']); 154 } 155 156 return implode(' || ', $ranges); 157 } 158 159 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 160 } 161 162 /** 163 * @param string $packageName 164 * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present 165 */ 166 public static function getVersion($packageName) 167 { 168 foreach (self::getInstalled() as $installed) { 169 if (!isset($installed['versions'][$packageName])) { 170 continue; 171 } 172 173 if (!isset($installed['versions'][$packageName]['version'])) { 174 return null; 175 } 176 177 return $installed['versions'][$packageName]['version']; 178 } 179 180 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 181 } 182 183 /** 184 * @param string $packageName 185 * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present 186 */ 187 public static function getPrettyVersion($packageName) 188 { 189 foreach (self::getInstalled() as $installed) { 190 if (!isset($installed['versions'][$packageName])) { 191 continue; 192 } 193 194 if (!isset($installed['versions'][$packageName]['pretty_version'])) { 195 return null; 196 } 197 198 return $installed['versions'][$packageName]['pretty_version']; 199 } 200 201 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 202 } 203 204 /** 205 * @param string $packageName 206 * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference 207 */ 208 public static function getReference($packageName) 209 { 210 foreach (self::getInstalled() as $installed) { 211 if (!isset($installed['versions'][$packageName])) { 212 continue; 213 } 214 215 if (!isset($installed['versions'][$packageName]['reference'])) { 216 return null; 217 } 218 219 return $installed['versions'][$packageName]['reference']; 220 } 221 222 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 223 } 224 225 /** 226 * @param string $packageName 227 * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path. 228 */ 229 public static function getInstallPath($packageName) 230 { 231 foreach (self::getInstalled() as $installed) { 232 if (!isset($installed['versions'][$packageName])) { 233 continue; 234 } 235 236 return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null; 237 } 238 239 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); 240 } 241 242 /** 243 * @return array 244 * @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string} 245 */ 246 public static function getRootPackage() 247 { 248 $installed = self::getInstalled(); 249 250 return $installed[0]['root']; 251 } 252 253 /** 254 * Returns the raw installed.php data for custom implementations 255 * 256 * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect. 257 * @return array[] 258 * @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} 259 */ 260 public static function getRawData() 261 { 262 @trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED); 263 264 if (null === self::$installed) { 265 // only require the installed.php file if this file is loaded from its dumped location, 266 // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 267 if (substr(__DIR__, -8, 1) !== 'C') { 268 self::$installed = include __DIR__ . '/installed.php'; 269 } else { 270 self::$installed = array(); 271 } 272 } 273 274 return self::$installed; 275 } 276 277 /** 278 * Returns the raw data of all installed.php which are currently loaded for custom implementations 279 * 280 * @return array[] 281 * @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}> 282 */ 283 public static function getAllRawData() 284 { 285 return self::getInstalled(); 286 } 287 288 /** 289 * Lets you reload the static array from another file 290 * 291 * This is only useful for complex integrations in which a project needs to use 292 * this class but then also needs to execute another project's autoloader in process, 293 * and wants to ensure both projects have access to their version of installed.php. 294 * 295 * A typical case would be PHPUnit, where it would need to make sure it reads all 296 * the data it needs from this class, then call reload() with 297 * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure 298 * the project in which it runs can then also use this class safely, without 299 * interference between PHPUnit's dependencies and the project's dependencies. 300 * 301 * @param array[] $data A vendor/composer/installed.php data set 302 * @return void 303 * 304 * @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} $data 305 */ 306 public static function reload($data) 307 { 308 self::$installed = $data; 309 self::$installedByVendor = array(); 310 } 311 312 /** 313 * @return array[] 314 * @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}> 315 */ 316 private static function getInstalled() 317 { 318 if (null === self::$canGetVendors) { 319 self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders'); 320 } 321 322 $installed = array(); 323 324 if (self::$canGetVendors) { 325 foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { 326 if (isset(self::$installedByVendor[$vendorDir])) { 327 $installed[] = self::$installedByVendor[$vendorDir]; 328 } elseif (is_file($vendorDir.'/composer/installed.php')) { 329 $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php'; 330 if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { 331 self::$installed = $installed[count($installed) - 1]; 332 } 333 } 334 } 335 } 336 337 if (null === self::$installed) { 338 // only require the installed.php file if this file is loaded from its dumped location, 339 // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 340 if (substr(__DIR__, -8, 1) !== 'C') { 341 self::$installed = require __DIR__ . '/installed.php'; 342 } else { 343 self::$installed = array(); 344 } 345 } 346 $installed[] = self::$installed; 347 348 return $installed; 349 } 58 350 } 59 60 61 62 63 64 65 66 67 68 public static function isInstalled($packageName)69 {70 return isset(self::$installed['versions'][$packageName]);71 }72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 public static function satisfies(VersionParser $parser, $packageName, $constraint)87 {88 $constraint = $parser->parseConstraints($constraint);89 $provided = $parser->parseConstraints(self::getVersionRanges($packageName));90 91 return $provided->matches($constraint);92 }93 94 95 96 97 98 99 100 101 102 103 public static function getVersionRanges($packageName)104 {105 if (!isset(self::$installed['versions'][$packageName])) {106 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');107 }108 109 $ranges = array();110 if (isset(self::$installed['versions'][$packageName]['pretty_version'])) {111 $ranges[] = self::$installed['versions'][$packageName]['pretty_version'];112 }113 if (array_key_exists('aliases', self::$installed['versions'][$packageName])) {114 $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['aliases']);115 }116 if (array_key_exists('replaced', self::$installed['versions'][$packageName])) {117 $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['replaced']);118 }119 if (array_key_exists('provided', self::$installed['versions'][$packageName])) {120 $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['provided']);121 }122 123 return implode(' || ', $ranges);124 }125 126 127 128 129 130 public static function getVersion($packageName)131 {132 if (!isset(self::$installed['versions'][$packageName])) {133 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');134 }135 136 if (!isset(self::$installed['versions'][$packageName]['version'])) {137 return null;138 }139 140 return self::$installed['versions'][$packageName]['version'];141 }142 143 144 145 146 147 public static function getPrettyVersion($packageName)148 {149 if (!isset(self::$installed['versions'][$packageName])) {150 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');151 }152 153 if (!isset(self::$installed['versions'][$packageName]['pretty_version'])) {154 return null;155 }156 157 return self::$installed['versions'][$packageName]['pretty_version'];158 }159 160 161 162 163 164 public static function getReference($packageName)165 {166 if (!isset(self::$installed['versions'][$packageName])) {167 throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');168 }169 170 if (!isset(self::$installed['versions'][$packageName]['reference'])) {171 return null;172 }173 174 return self::$installed['versions'][$packageName]['reference'];175 }176 177 178 179 180 181 public static function getRootPackage()182 {183 return self::$installed['root'];184 }185 186 187 188 189 190 191 192 public static function getRawData()193 {194 return self::$installed;195 }196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 public static function reload($data)216 {217 self::$installed = $data;218 }219 } -
wc-pre-order/trunk/vendor/composer/autoload_classmap.php
r2550859 r2878118 3 3 // autoload_classmap.php @generated by Composer 4 4 5 $vendorDir = dirname( dirname(__FILE__));5 $vendorDir = dirname(__DIR__); 6 6 $baseDir = dirname($vendorDir); 7 7 -
wc-pre-order/trunk/vendor/composer/autoload_files.php
r2550859 r2878118 3 3 // autoload_files.php @generated by Composer 4 4 5 $vendorDir = dirname( dirname(__FILE__));5 $vendorDir = dirname(__DIR__); 6 6 $baseDir = dirname($vendorDir); 7 7 -
wc-pre-order/trunk/vendor/composer/autoload_namespaces.php
r2550859 r2878118 3 3 // autoload_namespaces.php @generated by Composer 4 4 5 $vendorDir = dirname( dirname(__FILE__));5 $vendorDir = dirname(__DIR__); 6 6 $baseDir = dirname($vendorDir); 7 7 -
wc-pre-order/trunk/vendor/composer/autoload_psr4.php
r2550859 r2878118 3 3 // autoload_psr4.php @generated by Composer 4 4 5 $vendorDir = dirname( dirname(__FILE__));5 $vendorDir = dirname(__DIR__); 6 6 $baseDir = dirname($vendorDir); 7 7 -
wc-pre-order/trunk/vendor/composer/autoload_real.php
r2550859 r2878118 24 24 25 25 spl_autoload_register(array('ComposerAutoloaderInit8b057caf3cd808091e292aea40097efa', 'loadClassLoader'), true, true); 26 self::$loader = $loader = new \Composer\Autoload\ClassLoader( );26 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); 27 27 spl_autoload_unregister(array('ComposerAutoloaderInit8b057caf3cd808091e292aea40097efa', 'loadClassLoader')); 28 28 29 $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); 30 if ($useStaticLoader) { 31 require __DIR__ . '/autoload_static.php'; 32 33 call_user_func(\Composer\Autoload\ComposerStaticInit8b057caf3cd808091e292aea40097efa::getInitializer($loader)); 34 } else { 35 $map = require __DIR__ . '/autoload_namespaces.php'; 36 foreach ($map as $namespace => $path) { 37 $loader->set($namespace, $path); 38 } 39 40 $map = require __DIR__ . '/autoload_psr4.php'; 41 foreach ($map as $namespace => $path) { 42 $loader->setPsr4($namespace, $path); 43 } 44 45 $classMap = require __DIR__ . '/autoload_classmap.php'; 46 if ($classMap) { 47 $loader->addClassMap($classMap); 48 } 49 } 29 require __DIR__ . '/autoload_static.php'; 30 call_user_func(\Composer\Autoload\ComposerStaticInit8b057caf3cd808091e292aea40097efa::getInitializer($loader)); 50 31 51 32 $loader->register(true); 52 33 53 if ($useStaticLoader) { 54 $includeFiles = Composer\Autoload\ComposerStaticInit8b057caf3cd808091e292aea40097efa::$files; 55 } else { 56 $includeFiles = require __DIR__ . '/autoload_files.php'; 57 } 58 foreach ($includeFiles as $fileIdentifier => $file) { 59 composerRequire8b057caf3cd808091e292aea40097efa($fileIdentifier, $file); 34 $filesToLoad = \Composer\Autoload\ComposerStaticInit8b057caf3cd808091e292aea40097efa::$files; 35 $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { 36 if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { 37 $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; 38 39 require $file; 40 } 41 }, null, null); 42 foreach ($filesToLoad as $fileIdentifier => $file) { 43 $requireFile($fileIdentifier, $file); 60 44 } 61 45 … … 63 47 } 64 48 } 65 66 function composerRequire8b057caf3cd808091e292aea40097efa($fileIdentifier, $file)67 {68 if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {69 require $file;70 71 $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;72 }73 } -
wc-pre-order/trunk/vendor/composer/installed.php
r2550859 r2878118 1 <?php return array ( 2 'root' => 3 array ( 4 'pretty_version' => '1.0.0+no-version-set', 5 'version' => '1.0.0.0', 6 'aliases' => 7 array ( 1 <?php return array( 2 'root' => array( 3 'pretty_version' => 'dev-stable', 4 'version' => 'dev-stable', 5 'type' => 'wordpress-plugin', 6 'install_path' => __DIR__ . '/../../', 7 'aliases' => array(), 8 'reference' => '434d19b20b4937e43fda3cc30df84c238d4cc525', 9 'name' => 'springdevs/pre-order', 10 'dev' => true, 8 11 ), 9 'reference' => NULL, 10 'name' => 'springdevs/pre-order', 11 ), 12 'versions' => 13 array ( 14 'springdevs/pre-order' => 15 array ( 16 'pretty_version' => '1.0.0+no-version-set', 17 'version' => '1.0.0.0', 18 'aliases' => 19 array ( 20 ), 21 'reference' => NULL, 12 'versions' => array( 13 'springdevs/pre-order' => array( 14 'pretty_version' => 'dev-stable', 15 'version' => 'dev-stable', 16 'type' => 'wordpress-plugin', 17 'install_path' => __DIR__ . '/../../', 18 'aliases' => array(), 19 'reference' => '434d19b20b4937e43fda3cc30df84c238d4cc525', 20 'dev_requirement' => false, 21 ), 22 22 ), 23 ),24 23 );
Note: See TracChangeset
for help on using the changeset viewer.