File manager - Edit - /home/monara/public_html/test.athavaneng.com/Traits.tar
Back
GlobalDefaultMessages.php 0000644 00000013374 15073226722 0011470 0 ustar 00 <?php namespace FluentForm\App\Helpers\Traits; use FluentForm\Framework\Helpers\ArrayHelper as Arr; trait GlobalDefaultMessages { private static $globalDefaultMessages = []; public static function getGlobalDefaultMessage($key) { if (isset(static::$globalDefaultMessages[$key])) { return static::$globalDefaultMessages[$key]; } $globalSettings = get_option('_fluentform_global_form_settings'); if (!$globalSettings || !Arr::get($globalSettings, 'default_messages')) { static::setGlobalDefaultMessages(); } else if ($message = Arr::get($globalSettings, 'default_messages.' . $key, '')) { static::$globalDefaultMessages[$key] = $message; } return apply_filters('fluentform/global_default_message', Arr::get(static::$globalDefaultMessages, $key , ''), $key); } public static function getAllGlobalDefaultMessages() { static::setGlobalDefaultMessages(); return static::$globalDefaultMessages; } private static function setGlobalDefaultMessages() { $default_messages = []; foreach (static::globalDefaultMessageSettingFields() as $key => $field) { $default_messages[$key] = $field['value']; } $globalSettings = get_option('_fluentform_global_form_settings'); if ($globalSettings && $messages = Arr::get($globalSettings, 'default_messages', [])) { $default_messages = array_merge($default_messages, $messages); } static::$globalDefaultMessages = apply_filters('fluentform/global_default_messages', $default_messages); } public static function globalDefaultMessageSettingFields() { $default_message_setting_fields = [ 'required' => [ 'label' => __('Required Field', 'fluentform'), 'value' => __('This field is required', 'fluentform'), 'help_text' => __("This message will be shown if validation fails for required field.", 'fluentform'), ], 'email' => [ 'label' => __('Email', 'fluentform'), 'value' => __('This field must contain a valid email', 'fluentform'), 'help_text' => __("This message will be shown if validation fails for email.", 'fluentform'), ], 'numeric' => [ 'label' => __('Numeric', 'fluentform'), 'value' => __('This field must contain numeric value', 'fluentform'), 'help_text' => __("This message will be shown if validation fails for numeric value.", 'fluentform'), ], 'min' => [ 'label' => __('Minimum', 'fluentform'), 'value' => __('Validation fails for minimum value', 'fluentform'), 'help_text' => __("This message will be shown if validation fails for minimum value.", 'fluentform'), ], 'max' => [ 'label' => __('Maximum', 'fluentform'), 'value' => __('Validation fails for maximum value', 'fluentform'), 'help_text' => __("This message will be shown if validation fails for maximum value.", 'fluentform'), ], 'digits' => [ 'label' => __('Digits', 'fluentform'), 'value' => __('Validation fails for limited digits', 'fluentform'), 'help_text' => __("This message will be shown if validation fails for digits value.", 'fluentform'), ], 'url' => [ 'label' => __('Url', 'fluentform'), 'value' => __('This field must contain a valid url', 'fluentform'), 'help_text' => __("This message will be shown if validation fails for validate URL.", 'fluentform'), ], 'allowed_image_types' => [ 'label' => __('Allowed Image Types', 'fluentform'), 'value' => __('Allowed image types does not match', 'fluentform'), 'help_text' => __("This message will be shown if validation fails for image types.", 'fluentform'), ], 'allowed_file_types' => [ 'label' => __('Allowed File Types', 'fluentform'), 'value' => __('Invalid file type', 'fluentform'), 'help_text' => __("This message will be shown if validation fails for allowed file type.", 'fluentform'), ], 'max_file_size' => [ 'label' => __('Maximum File Size', 'fluentform'), 'value' => __('Validation fails for maximum file size', 'fluentform'), 'help_text' => __("This message will be shown if validation fails for maximum file size.", 'fluentform'), ], 'max_file_count' => [ 'label' => __('Maximum File Count', 'fluentform'), 'value' => __('Validation fails for maximum file count', 'fluentform'), 'help_text' => __("This message will be shown if validation fails for maximum file count.", 'fluentform'), ], ]; if (defined('FLUENTFORMPRO')) { $default_message_setting_fields['valid_phone_number'] = [ 'label' => __('Valid Phone Number', 'fluentformpro'), 'value' => __('Phone number is not valid', 'fluentformpro'), 'help_text' => __("This message will be shown if validation fails for validate phone number.", 'fluentform'), ]; } return apply_filters('fluentform/global_default_message_setting_fields', $default_message_setting_fields); } } OrderAttributionMeta.php 0000644 00000025704 15073235625 0011404 0 ustar 00 <?php declare( strict_types=1 ); namespace Automattic\WooCommerce\Internal\Traits; use Automattic\WooCommerce\Vendor\Detection\MobileDetect; use Automattic\WooCommerce\Admin\API\Reports\Controller as ReportsController; use Exception; use WC_Meta_Data; use WC_Order; use WP_Post; /** * Trait OrderAttributionMeta * * @since 8.5.0 * * phpcs:disable Generic.Commenting.DocComment.MissingShort */ trait OrderAttributionMeta { /** @var string[] */ private $default_fields = array( // main fields. 'type', 'url', // utm fields. 'utm_campaign', 'utm_source', 'utm_medium', 'utm_content', 'utm_id', 'utm_term', // additional fields. 'session_entry', 'session_start_time', 'session_pages', 'session_count', 'user_agent', ); /** @var array */ private $fields = array(); /** @var string */ private $field_prefix = ''; /** * Get the device type based on the other meta fields. * * @param array $values The meta values. * * @return string The device type. */ protected function get_device_type( array $values ): string { $detector = new MobileDetect( array(), $values['user_agent'] ); if ( $detector->isMobile() ) { return 'Mobile'; } elseif ( $detector->isTablet() ) { return 'Tablet'; } else { return 'Desktop'; } } /** * Set the meta fields and the field prefix. * * @return void */ private function set_fields_and_prefix() { /** * Filter the fields to show in the source data metabox. * * @since 8.5.0 * * @param string[] $fields The fields to show. */ $this->fields = (array) apply_filters( 'wc_order_attribution_tracking_fields', $this->default_fields ); $this->set_field_prefix(); } /** * Set the meta prefix for our fields. * * @return void */ private function set_field_prefix(): void { /** * Filter the prefix for the meta fields. * * @since 8.5.0 * * @param string $prefix The prefix for the meta fields. */ $prefix = (string) apply_filters( 'wc_order_attribution_tracking_field_prefix', 'wc_order_attribution_' ); // Remove leading and trailing underscores. $prefix = trim( $prefix, '_' ); // Ensure the prefix ends with _, and set the prefix. $this->field_prefix = "{$prefix}_"; } /** * Filter an order's meta data to only the keys that we care about. * * Sets the origin value based on the source type. * * @param WC_Meta_Data[] $meta The meta data. * * @return array */ private function filter_meta_data( array $meta ): array { $return = array(); $prefix = $this->get_meta_prefixed_field( '' ); foreach ( $meta as $item ) { if ( str_starts_with( $item->key, $prefix ) ) { $return[ $this->unprefix_meta_field( $item->key ) ] = $item->value; } } // Determine the device type from the user agent. if ( ! array_key_exists( 'device_type', $return ) && array_key_exists( 'user_agent', $return ) ) { $return['device_type'] = $this->get_device_type( $return ); } // Determine the origin based on source type and referrer. $source_type = $return['type'] ?? ''; $source = $return['utm_source'] ?? ''; $return['origin'] = $this->get_origin_label( $source_type, $source, true ); return $return; } /** * Get the field name with the appropriate prefix. * * @param string $field Field name. * * @return string The prefixed field name. */ private function get_prefixed_field( $field ): string { return "{$this->field_prefix}{$field}"; } /** * Get the field name with the meta prefix. * * @param string $field The field name. * * @return string The prefixed field name. */ private function get_meta_prefixed_field( string $field ): string { // Map some of the fields to the correct meta name. if ( 'type' === $field ) { $field = 'source_type'; } elseif ( 'url' === $field ) { $field = 'referrer'; } return "_{$this->get_prefixed_field( $field )}"; } /** * Remove the meta prefix from the field name. * * @param string $field The prefixed field. * * @return string */ private function unprefix_meta_field( string $field ): string { $return = str_replace( "_{$this->field_prefix}", '', $field ); // Map some of the fields to the correct meta name. if ( 'source_type' === $return ) { $return = 'type'; } elseif ( 'referrer' === $return ) { $return = 'url'; } return $return; } /** * Get the order object with HPOS compatibility. * * @param WC_Order|WP_Post|int $post_or_order The post ID or object. * * @return WC_Order The order object * @throws Exception When the order isn't found. */ private function get_hpos_order_object( $post_or_order ) { // If we've already got an order object, just return it. if ( $post_or_order instanceof WC_Order ) { return $post_or_order; } // If we have a post ID, get the post object. if ( is_numeric( $post_or_order ) ) { $post_or_order = wc_get_order( $post_or_order ); } // Throw an exception if we don't have an order object. if ( ! $post_or_order instanceof WC_Order ) { throw new Exception( __( 'Order not found.', 'woocommerce' ) ); } return $post_or_order; } /** * Map posted, prefixed values to fields. * Used for the classic forms. * * @param array $raw_values The raw values from the POST form. * * @return array */ private function get_unprefixed_fields( array $raw_values = array() ): array { $values = array(); // Look through each field in POST data. foreach ( $this->fields as $field ) { $values[ $field ] = $raw_values[ $this->get_prefixed_field( $field ) ] ?? '(none)'; } return $values; } /** * Map submitted values to meta values. * * @param array $raw_values The raw (unprefixed) values from the submitted data. * * @return array */ private function get_source_values( array $raw_values = array() ): array { $values = array(); // Look through each field in given data. foreach ( $this->fields as $field ) { $value = sanitize_text_field( wp_unslash( $raw_values[ $field ] ) ); if ( '(none)' === $value ) { continue; } $values[ $field ] = $value; } // Set the device type if possible using the user agent. if ( array_key_exists( 'user_agent', $values ) && ! empty( $values['user_agent'] ) ) { $values['device_type'] = $this->get_device_type( $values ); } return $values; } /** * Get the label for the Order origin with placeholder where appropriate. Can be * translated (for DB / display) or untranslated (for Tracks). * * @param string $source_type The source type. * @param string $source The source. * @param bool $translated Whether the label should be translated. * * @return string */ private function get_origin_label( string $source_type, string $source, bool $translated = true ): string { // Set up the label based on the source type. switch ( $source_type ) { case 'utm': $label = $translated ? /* translators: %s is the source value */ __( 'Source: %s', 'woocommerce' ) : 'Source: %s'; break; case 'organic': $label = $translated ? /* translators: %s is the source value */ __( 'Organic: %s', 'woocommerce' ) : 'Organic: %s'; break; case 'referral': $label = $translated ? /* translators: %s is the source value */ __( 'Referral: %s', 'woocommerce' ) : 'Referral: %s'; break; case 'typein': $label = ''; $source = $translated ? __( 'Direct', 'woocommerce' ) : 'Direct'; break; case 'admin': $label = ''; $source = $translated ? __( 'Web admin', 'woocommerce' ) : 'Web admin'; break; default: $label = ''; $source = __( 'Unknown', 'woocommerce' ); break; } /** * Filter the formatted source for the order origin. * * @since 8.5.0 * * @param string $formatted_source The formatted source. * @param string $source The source. */ $formatted_source = apply_filters( 'wc_order_attribution_origin_formatted_source', ucfirst( trim( $source, '()' ) ), $source ); /** * Filter the label for the order origin. * * This label should have a %s placeholder for the formatted source to be inserted * via sprintf(). * * @since 8.5.0 * * @param string $label The label for the order origin. * @param string $source_type The source type. * @param string $source The source. * @param string $formatted_source The formatted source. */ $label = (string) apply_filters( 'wc_order_attribution_origin_label', $label, $source_type, $source, $formatted_source ); if ( false === strpos( $label, '%' ) ) { return $formatted_source; } return sprintf( $label, $formatted_source ); } /** * Get the description for the order attribution field. * * @param string $field The field name. * * @return string */ private function get_field_description( string $field ): string { /* translators: %s is the field name */ $description = sprintf( __( 'Order attribution field: %s', 'woocommerce' ), $field ); /** * Filter the description for the order attribution field. * * @since 8.5.0 * * @param string $description The description for the order attribution field. * @param string $field The field name. */ return (string) apply_filters( 'wc_order_attribution_field_description', $description, $field ); } /** * Get the order history for the customer (data matches Customers report). * * @param mixed $customer_identifier The customer ID or billing email. * * @return array Order count, total spend, and average spend per order. */ private function get_customer_history( $customer_identifier ): array { /* * Exclude the statuses that aren't valid for the Customers report. * 'checkout-draft' is the checkout block's draft order status. `any` is added by V2 Orders REST. * @see /Automattic/WooCommerce/Admin/API/Report/DataStore::get_excluded_report_order_statuses() */ $all_order_statuses = ReportsController::get_order_statuses(); $excluded_statuses = array( 'pending', 'failed', 'cancelled', 'auto-draft', 'trash', 'checkout-draft', 'any' ); // Get the valid customer orders. $args = array( 'limit' => - 1, 'return' => 'objects', 'status' => array_diff( $all_order_statuses, $excluded_statuses ), 'type' => 'shop_order', ); // If the customer_identifier is a valid ID, use it. Otherwise, use the billing email. if ( is_numeric( $customer_identifier ) && $customer_identifier > 0 ) { $args['customer_id'] = $customer_identifier; } else { $args['billing_email'] = $customer_identifier; $args['customer_id'] = 0; } $orders = wc_get_orders( $args ); // Populate the order_count and total_spent variables with the valid orders. $order_count = count( $orders ); $total_spent = 0; foreach ( $orders as $order ) { $total_spent += $order->get_total() - $order->get_total_refunded(); } return array( 'order_count' => $order_count, 'total_spent' => $total_spent, 'average_spent' => $order_count ? $total_spent / $order_count : 0, ); } } AccessiblePrivateMethods.php 0000644 00000017745 15073235625 0012217 0 ustar 00 <?php namespace Automattic\WooCommerce\Internal\Traits; use Automattic\WooCommerce\Utilities\ArrayUtil; /** * This trait allows making private methods of a class accessible from outside. * This is useful to define hook handlers with the [$this, 'method'] or [__CLASS__, 'method'] syntax * without having to make the method public (and thus having to keep it forever for backwards compatibility). * * Example: * * class Foobar { * use AccessiblePrivateMethods; * * public function __construct() { * self::add_action('some_action', [$this, 'handle_some_action']); * } * * public static function init() { * self::add_filter('some_filter', [__CLASS__, 'handle_some_filter']); * } * * private function handle_some_action() { * } * * private static function handle_some_filter() { * } * } * * For this to work the callback must be an array and the first element of the array must be either '$this', '__CLASS__', * or another instance of the same class; otherwise the method won't be marked as accessible * (but the corresponding WordPress 'add_action' and 'add_filter' functions will still be called). * * No special procedure is needed to remove hooks set up with these methods, the regular 'remove_action' * and 'remove_filter' functions provided by WordPress can be used as usual. */ trait AccessiblePrivateMethods { //phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore /** * List of instance methods marked as externally accessible. * * @var array */ private $_accessible_private_methods = array(); /** * List of static methods marked as externally accessible. * * @var array */ private static $_accessible_static_private_methods = array(); //phpcs:enable PSR2.Classes.PropertyDeclaration.Underscore /** * Register a WordPress action. * If the callback refers to a private or protected instance method in this class, the method is marked as externally accessible. * * $callback can be a standard callable, or a string representing the name of a method in this class. * * @param string $hook_name The name of the action to add the callback to. * @param callable|string $callback The callback to be run when the action is called. * @param int $priority Optional. Used to specify the order in which the functions * associated with a particular action are executed. * Lower numbers correspond with earlier execution, * and functions with the same priority are executed * in the order in which they were added to the action. Default 10. * @param int $accepted_args Optional. The number of arguments the function accepts. Default 1. */ protected static function add_action( string $hook_name, $callback, int $priority = 10, int $accepted_args = 1 ): void { self::process_callback_before_hooking( $callback ); add_action( $hook_name, $callback, $priority, $accepted_args ); } /** * Register a WordPress filter. * If the callback refers to a private or protected instance method in this class, the method is marked as externally accessible. * * $callback can be a standard callable, or a string representing the name of a method in this class. * * @param string $hook_name The name of the filter to add the callback to. * @param callable|string $callback The callback to be run when the filter is called. * @param int $priority Optional. Used to specify the order in which the functions * associated with a particular filter are executed. * Lower numbers correspond with earlier execution, * and functions with the same priority are executed * in the order in which they were added to the filter. Default 10. * @param int $accepted_args Optional. The number of arguments the function accepts. Default 1. */ protected static function add_filter( string $hook_name, $callback, int $priority = 10, int $accepted_args = 1 ): void { self::process_callback_before_hooking( $callback ); add_filter( $hook_name, $callback, $priority, $accepted_args ); } /** * Do the required processing to a callback before invoking the WordPress 'add_action' or 'add_filter' function. * * @param callable $callback The callback to process. * @return void */ protected static function process_callback_before_hooking( $callback ): void { if ( ! is_array( $callback ) || count( $callback ) < 2 ) { return; } $first_item = $callback[0]; if ( __CLASS__ === $first_item ) { static::mark_static_method_as_accessible( $callback[1] ); } elseif ( is_object( $first_item ) && get_class( $first_item ) === __CLASS__ ) { $first_item->mark_method_as_accessible( $callback[1] ); } } /** * Register a private or protected instance method of this class as externally accessible. * * @param string $method_name Method name. * @return bool True if the method has been marked as externally accessible, false if the method doesn't exist. */ protected function mark_method_as_accessible( string $method_name ): bool { // Note that an "is_callable" check would be useless here: // "is_callable" always returns true if the class implements __call. if ( method_exists( $this, $method_name ) ) { $this->_accessible_private_methods[ $method_name ] = $method_name; return true; } return false; } /** * Register a private or protected static method of this class as externally accessible. * * @param string $method_name Method name. * @return bool True if the method has been marked as externally accessible, false if the method doesn't exist. */ protected static function mark_static_method_as_accessible( string $method_name ): bool { if ( method_exists( __CLASS__, $method_name ) ) { static::$_accessible_static_private_methods[ $method_name ] = $method_name; return true; } return false; } /** * Undefined/inaccessible instance method call handler. * * @param string $name Called method name. * @param array $arguments Called method arguments. * @return mixed * @throws \Error The called instance method doesn't exist or is private/protected and not marked as externally accessible. */ public function __call( $name, $arguments ) { if ( isset( $this->_accessible_private_methods[ $name ] ) ) { return call_user_func_array( array( $this, $name ), $arguments ); } elseif ( is_callable( array( 'parent', '__call' ) ) ) { return parent::__call( $name, $arguments ); } elseif ( method_exists( $this, $name ) ) { throw new \Error( 'Call to private method ' . get_class( $this ) . '::' . $name ); } else { throw new \Error( 'Call to undefined method ' . get_class( $this ) . '::' . $name ); } } /** * Undefined/inaccessible static method call handler. * * @param string $name Called method name. * @param array $arguments Called method arguments. * @return mixed * @throws \Error The called static method doesn't exist or is private/protected and not marked as externally accessible. */ public static function __callStatic( $name, $arguments ) { if ( isset( static::$_accessible_static_private_methods[ $name ] ) ) { return call_user_func_array( array( __CLASS__, $name ), $arguments ); } elseif ( is_callable( array( 'parent', '__callStatic' ) ) ) { return parent::__callStatic( $name, $arguments ); } elseif ( 'add_action' === $name || 'add_filter' === $name ) { $proper_method_name = 'add_static_' . substr( $name, 4 ); throw new \Error( __CLASS__ . '::' . $name . " can't be called statically, did you mean '$proper_method_name'?" ); } elseif ( method_exists( __CLASS__, $name ) ) { throw new \Error( 'Call to private method ' . __CLASS__ . '::' . $name ); } else { throw new \Error( 'Call to undefined method ' . __CLASS__ . '::' . $name ); } } } ScriptDebug.php 0000644 00000001072 15073235625 0007500 0 ustar 00 <?php declare( strict_types=1 ); namespace Automattic\WooCommerce\Internal\Traits; use Automattic\Jetpack\Constants; /** * Trait ScriptDebug * * @since 8.5.0 */ trait ScriptDebug { /** * Get the script suffix based on the SCRIPT_DEBUG constant. * * @return string */ protected function get_script_suffix(): string { return $this->is_script_debug_enabled() ? '' : '.min'; } /** * Check if SCRIPT_DEBUG is enabled. * * @return bool */ protected function is_script_debug_enabled(): bool { return Constants::is_true( 'SCRIPT_DEBUG' ); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings