@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | * Get all addresses for current customer for display |
| 453 | 453 | * |
| 454 | 454 | * @param integer $address_type_id The current identifier of address type -> attribute_set_id |
| 455 | - * @param string $address_type A string allowing to display |
|
| 455 | + * @param string $address_type_title A string allowing to display |
|
| 456 | 456 | * |
| 457 | 457 | * @return string The complete html output for customer addresses |
| 458 | 458 | */ |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | * @param integer $address_type_id |
| 577 | 577 | * @param integer $address_id |
| 578 | 578 | * @param integer $user_id |
| 579 | - * @return string |
|
| 579 | + * @return string[] |
|
| 580 | 580 | */ |
| 581 | 581 | function loading_address_form( $address_type_id, $address_id = '', $user_id = '', $display_in_front = false ) { |
| 582 | 582 | $response = '<div id="wps_address_error_container"></div>'; |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | /** |
| 617 | 617 | * Generate an array with all fields for the address form construction. Classified by address type. |
| 618 | 618 | * @param $typeof |
| 619 | - * @return array |
|
| 619 | + * @return string |
|
| 620 | 620 | */ |
| 621 | 621 | public static function get_addresss_form_fields_by_type ( $typeof, $id ='' ) { |
| 622 | 622 | // Sanitize all $_POST |
@@ -787,7 +787,6 @@ discard block |
||
| 787 | 787 | * @param string $type : Type of address |
| 788 | 788 | * @param string $first : Customer first address ? |
| 789 | 789 | * @param string $referer : Referer website page |
| 790 | - * @param string $admin : Display this form in admin panel |
|
| 791 | 790 | */ |
| 792 | 791 | public static function display_form_fields($type, $id = '', $first = '', $referer = '', $special_values = array(), $options = array(), $display_for_admin = array(), $other_customer = '' ) { |
| 793 | 792 | global $wpshop, $wpshop_form, $wpdb; |
@@ -206,7 +206,7 @@ |
||
| 206 | 206 | */ |
| 207 | 207 | function addresses_custom_query( $query ) { |
| 208 | 208 | if( is_admin() && $query->query['post_type'] == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS && $query->is_main_query() ) { |
| 209 | - add_filter( 'posts_orderby', array( $this, 'addresses_custom_query_order' ) ); |
|
| 209 | + add_filter( 'posts_orderby', array( $this, 'addresses_custom_query_order' ) ); |
|
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | /** |
| 3 | 3 | * File defining class for addresses initialisation |
| 4 | 4 | * |
@@ -8,8 +8,8 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | /** Check if the plugin WPS_LOCALISATION_VERSION is defined. If not defined script will be stopped here */ |
| 11 | -if ( !defined( 'WPS_LOCALISATION_VERSION' ) ) { |
|
| 12 | - die( __("You are not allowed to use this service.", 'wpeo_geoloc') ); |
|
| 11 | +if (!defined('WPS_LOCALISATION_VERSION')) { |
|
| 12 | + die(__("You are not allowed to use this service.", 'wpeo_geoloc')); |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | /** |
@@ -26,50 +26,50 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function __construct() { |
| 28 | 28 | /** Create customer entity type on wordpress initilisation*/ |
| 29 | - add_action( 'init', array( $this, 'create_addresses_entity' ) ); |
|
| 29 | + add_action('init', array($this, 'create_addresses_entity')); |
|
| 30 | 30 | |
| 31 | 31 | /** Add filters for addresses list */ |
| 32 | - add_filter( 'bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, array( $this, 'addresses_list_table_bulk_actions' ) ); |
|
| 33 | - add_filter( 'manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_columns', array( $this, 'list_table_header' ) ); |
|
| 34 | - add_action( 'manage_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_posts_custom_column' , array( $this, 'list_table_column_content' ), 10, 2 ); |
|
| 32 | + add_filter('bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, array($this, 'addresses_list_table_bulk_actions')); |
|
| 33 | + add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_columns', array($this, 'list_table_header')); |
|
| 34 | + add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_posts_custom_column', array($this, 'list_table_column_content'), 10, 2); |
|
| 35 | 35 | |
| 36 | 36 | /** Filter search for customers */ |
| 37 | - add_filter( 'pre_get_posts', array( $this, 'addresses_custom_query' ) ); |
|
| 37 | + add_filter('pre_get_posts', array($this, 'addresses_custom_query')); |
|
| 38 | 38 | |
| 39 | 39 | /** Load */ |
| 40 | - add_filter( 'wpshop_custom_template', array( &$this, 'custom_template_load' ) ); |
|
| 40 | + add_filter('wpshop_custom_template', array(&$this, 'custom_template_load')); |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | 43 | /** Add shortocde listener for addresses */ |
| 44 | - add_shortcode( 'wps_address_list', array( &$this, 'get_addresses') ); |
|
| 45 | - add_shortcode( 'wps_addresses', array( &$this, 'display_addresses_interface') ); |
|
| 46 | - add_shortcode( 'wps_addresses_list', array( &$this, 'shortcode_display_addresses_list' ) ); |
|
| 44 | + add_shortcode('wps_address_list', array(&$this, 'get_addresses')); |
|
| 45 | + add_shortcode('wps_addresses', array(&$this, 'display_addresses_interface')); |
|
| 46 | + add_shortcode('wps_addresses_list', array(&$this, 'shortcode_display_addresses_list')); |
|
| 47 | 47 | |
| 48 | 48 | /** Add listener for ajax actions */ |
| 49 | - add_action( 'wp_ajax_wps_load_address_form', array( &$this, 'wps_load_address_form') ); // DONE |
|
| 50 | - add_action( 'wp_ajax_wps_save_address', array( &$this, 'wps_save_address') ); // DONE |
|
| 51 | - add_action( 'wp_ajax_wps-address-edition-form-load', array( &$this, 'load_address_edition_form' ) ); // DONE |
|
| 52 | - add_action( 'wp_ajax_wps-address-display-an-address', array( &$this, 'display_address' ) ); // DONE |
|
| 49 | + add_action('wp_ajax_wps_load_address_form', array(&$this, 'wps_load_address_form')); // DONE |
|
| 50 | + add_action('wp_ajax_wps_save_address', array(&$this, 'wps_save_address')); // DONE |
|
| 51 | + add_action('wp_ajax_wps-address-edition-form-load', array(&$this, 'load_address_edition_form')); // DONE |
|
| 52 | + add_action('wp_ajax_wps-address-display-an-address', array(&$this, 'display_address')); // DONE |
|
| 53 | 53 | // add_action( 'wap_ajax_wps-address-save-address', array( &$this, 'wps_save_address' ) ); |
| 54 | - add_action( 'wp_ajax_wps-address-display-list', array( &$this, 'display_addresses_list' ) ); // DONE |
|
| 55 | - add_action( 'wp_ajax_wps-address-add-new', array( &$this, 'display_address_adding_form' ) ); // DONE |
|
| 56 | - add_action( 'wp_ajax_wps_delete_an_address', array( &$this, 'wps_delete_an_address' ) ); // DONE |
|
| 57 | - add_action( 'wp_ajax_wps_reload_address_interface', array( &$this, 'wps_reload_address_interface' ) ); |
|
| 54 | + add_action('wp_ajax_wps-address-display-list', array(&$this, 'display_addresses_list')); // DONE |
|
| 55 | + add_action('wp_ajax_wps-address-add-new', array(&$this, 'display_address_adding_form')); // DONE |
|
| 56 | + add_action('wp_ajax_wps_delete_an_address', array(&$this, 'wps_delete_an_address')); // DONE |
|
| 57 | + add_action('wp_ajax_wps_reload_address_interface', array(&$this, 'wps_reload_address_interface')); |
|
| 58 | 58 | // add_action( 'wap_ajax_display_address_form', array( &$this, '') ); |
| 59 | 59 | // add_action( 'wap_ajax_wps-add-an-address-in-admin', array( $this, 'wps_add_an_address_in_admin' ) ); |
| 60 | 60 | |
| 61 | 61 | /* Include the different javascript */ |
| 62 | - add_action( 'wp_enqueue_scripts', array( &$this, 'frontend_js' ) ); |
|
| 63 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_js' ) ); |
|
| 64 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_css' ) ); |
|
| 62 | + add_action('wp_enqueue_scripts', array(&$this, 'frontend_js')); |
|
| 63 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_js')); |
|
| 64 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_css')); |
|
| 65 | 65 | |
| 66 | 66 | /** Add addresses metaboxes to wordpress element */ |
| 67 | - add_action('add_meta_boxes', array( &$this, 'addresses_metaboxes'), 1); |
|
| 67 | + add_action('add_meta_boxes', array(&$this, 'addresses_metaboxes'), 1); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - function shortcode_display_addresses_list( $args ) { |
|
| 71 | - $addresses = $this->get_addresses_list( $args[ 'id' ] ); |
|
| 72 | - require_once( wpshop_tools::get_template_part( WPS_LOCALISATION_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, 'backend', 'addresses') ); |
|
| 70 | + function shortcode_display_addresses_list($args) { |
|
| 71 | + $addresses = $this->get_addresses_list($args['id']); |
|
| 72 | + require_once(wpshop_tools::get_template_part(WPS_LOCALISATION_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, 'backend', 'addresses')); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -77,30 +77,30 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function create_addresses_entity() { |
| 79 | 79 | global $wpdb; |
| 80 | - $query = $wpdb->prepare( "SELECT P.post_title, PM.meta_value FROM {$wpdb->posts} AS P INNER JOIN {$wpdb->postmeta} AS PM ON (PM.post_id = P.ID) WHERE P.post_name = %s AND PM.meta_key = %s", WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, '_wpshop_entity_params' ); |
|
| 81 | - $entity_definition = $wpdb->get_row( $query ); |
|
| 82 | - $entity_params = !empty( $entity_definition ) && !empty( $entity_definition->meta_value ) ? unserialize( $entity_definition->meta_value ) : null; |
|
| 80 | + $query = $wpdb->prepare("SELECT P.post_title, PM.meta_value FROM {$wpdb->posts} AS P INNER JOIN {$wpdb->postmeta} AS PM ON (PM.post_id = P.ID) WHERE P.post_name = %s AND PM.meta_key = %s", WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, '_wpshop_entity_params'); |
|
| 81 | + $entity_definition = $wpdb->get_row($query); |
|
| 82 | + $entity_params = !empty($entity_definition) && !empty($entity_definition->meta_value) ? unserialize($entity_definition->meta_value) : null; |
|
| 83 | 83 | |
| 84 | 84 | $post_type_params = array( |
| 85 | 85 | 'labels' => array( |
| 86 | - 'name' => __( 'Addresses' , 'wpshop' ), |
|
| 87 | - 'singular_name' => __( 'Address', 'wpshop' ), |
|
| 88 | - 'add_new_item' => __( 'New address', 'wpshop' ), |
|
| 89 | - 'add_new' => __( 'New address', 'wpshop' ), |
|
| 90 | - 'edit_item' => __( 'Edit address', 'wpshop' ), |
|
| 91 | - 'new_item' => __( 'New address', 'wpshop' ), |
|
| 92 | - 'view_item' => __( 'View address', 'wpshop' ), |
|
| 93 | - 'search_items' => __( 'Search in addresses', 'wpshop' ), |
|
| 94 | - 'not_found' => __( 'No address found', 'wpshop' ), |
|
| 95 | - 'not_found_in_trash' => __( 'No address founded in trash', 'wpshop' ), |
|
| 86 | + 'name' => __('Addresses', 'wpshop'), |
|
| 87 | + 'singular_name' => __('Address', 'wpshop'), |
|
| 88 | + 'add_new_item' => __('New address', 'wpshop'), |
|
| 89 | + 'add_new' => __('New address', 'wpshop'), |
|
| 90 | + 'edit_item' => __('Edit address', 'wpshop'), |
|
| 91 | + 'new_item' => __('New address', 'wpshop'), |
|
| 92 | + 'view_item' => __('View address', 'wpshop'), |
|
| 93 | + 'search_items' => __('Search in addresses', 'wpshop'), |
|
| 94 | + 'not_found' => __('No address found', 'wpshop'), |
|
| 95 | + 'not_found_in_trash' => __('No address founded in trash', 'wpshop'), |
|
| 96 | 96 | 'parent_item_colon' => '', |
| 97 | 97 | ), |
| 98 | 98 | 'description' => '', |
| 99 | - 'supports' => !empty($entity_params['support']) ? $entity_params['support'] : array( 'title' ), |
|
| 99 | + 'supports' => !empty($entity_params['support']) ? $entity_params['support'] : array('title'), |
|
| 100 | 100 | 'hierarchical' => false, |
| 101 | 101 | 'public' => false, |
| 102 | 102 | 'show_ui' => false, |
| 103 | - 'show_in_menu' => 'edit.php?post_type='.WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, |
|
| 103 | + 'show_in_menu' => 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, |
|
| 104 | 104 | 'show_in_nav_menus' => false, |
| 105 | 105 | 'show_in_admin_bar' => false, |
| 106 | 106 | 'can_export' => false, |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | 'publicly_queryable' => false, |
| 110 | 110 | 'rewrite' => false, |
| 111 | 111 | ); |
| 112 | - register_post_type( WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $post_type_params ); |
|
| 112 | + register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $post_type_params); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | * |
| 120 | 120 | * @return array The new action list to use into customer list table |
| 121 | 121 | */ |
| 122 | - function addresses_list_table_bulk_actions( $actions ){ |
|
| 123 | - unset( $actions[ 'edit' ] ); |
|
| 124 | - unset( $actions[ 'trash' ] ); |
|
| 122 | + function addresses_list_table_bulk_actions($actions) { |
|
| 123 | + unset($actions['edit']); |
|
| 124 | + unset($actions['trash']); |
|
| 125 | 125 | |
| 126 | 126 | return $actions; |
| 127 | 127 | } |
@@ -133,14 +133,14 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | * @return array The new header to display |
| 135 | 135 | */ |
| 136 | - function list_table_header( $current_header ) { |
|
| 137 | - unset( $current_header['title'] ); |
|
| 138 | - unset( $current_header['date'] ); |
|
| 136 | + function list_table_header($current_header) { |
|
| 137 | + unset($current_header['title']); |
|
| 138 | + unset($current_header['date']); |
|
| 139 | 139 | |
| 140 | - $current_header['address_identifier'] = __( 'Address ID', 'wpshop' ); |
|
| 141 | - $current_header['address_element_name'] = __( 'Element', 'wpshop' ); |
|
| 142 | - $current_header['address_type'] = __( 'Address type', 'wpshop' ); |
|
| 143 | - $current_header['address_content'] = __( 'Address', 'wpshop' ); |
|
| 140 | + $current_header['address_identifier'] = __('Address ID', 'wpshop'); |
|
| 141 | + $current_header['address_element_name'] = __('Element', 'wpshop'); |
|
| 142 | + $current_header['address_type'] = __('Address type', 'wpshop'); |
|
| 143 | + $current_header['address_content'] = __('Address', 'wpshop'); |
|
| 144 | 144 | |
| 145 | 145 | return $current_header; |
| 146 | 146 | } |
@@ -151,50 +151,50 @@ discard block |
||
| 151 | 151 | * @param string $column The column identifier to modify output for |
| 152 | 152 | * @param integer $post_id The current post identifier |
| 153 | 153 | */ |
| 154 | - function list_table_column_content( $column, $post_id ) { |
|
| 154 | + function list_table_column_content($column, $post_id) { |
|
| 155 | 155 | global $wpdb; |
| 156 | 156 | |
| 157 | 157 | /** Get wp_users idenfifier from customer id */ |
| 158 | - $query = $wpdb->prepare( "SELECT PA.post_parent AS post_parent, PA.post_author AS post_author, PC.ID AS parent_id, PC.post_title AS post_title, PC.post_type AS post_type FROM {$wpdb->posts} AS PC INNER JOIN {$wpdb->posts} AS PA ON ( PA.post_parent = PC.ID ) WHERE PA.ID = %d", $post_id); |
|
| 159 | - $address_associated_element = $wpdb->get_row( $query ); |
|
| 158 | + $query = $wpdb->prepare("SELECT PA.post_parent AS post_parent, PA.post_author AS post_author, PC.ID AS parent_id, PC.post_title AS post_title, PC.post_type AS post_type FROM {$wpdb->posts} AS PC INNER JOIN {$wpdb->posts} AS PA ON ( PA.post_parent = PC.ID ) WHERE PA.ID = %d", $post_id); |
|
| 159 | + $address_associated_element = $wpdb->get_row($query); |
|
| 160 | 160 | |
| 161 | 161 | /** SCOTCH - Define the associated element type - SCOTCH */ |
| 162 | 162 | $address_associated_element_type = $address_associated_element->post_type; |
| 163 | - if ( $address_associated_element->post_parent == $address_associated_element->post_author ) { |
|
| 163 | + if ($address_associated_element->post_parent == $address_associated_element->post_author) { |
|
| 164 | 164 | $address_associated_element_type = WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** Get the associated element definition */ |
| 168 | - $associated_element_definition = get_post_type_object( $address_associated_element_type ); |
|
| 168 | + $associated_element_definition = get_post_type_object($address_associated_element_type); |
|
| 169 | 169 | |
| 170 | 170 | /** Get address informations */ |
| 171 | - $address_meta = get_post_meta( $post_id ); |
|
| 171 | + $address_meta = get_post_meta($post_id); |
|
| 172 | 172 | |
| 173 | 173 | /** Get user data */ |
| 174 | - switch ( $address_associated_element_type ) { |
|
| 174 | + switch ($address_associated_element_type) { |
|
| 175 | 175 | case WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS: |
| 176 | - $associated_customer = get_userdata( $address_associated_element->post_author ); |
|
| 176 | + $associated_customer = get_userdata($address_associated_element->post_author); |
|
| 177 | 177 | $customer_name_to_display = $associated_customer->display_name; |
| 178 | - if ( !empty( $associated_customer->first_name ) && !empty( $associated_customer->last_name ) ) { |
|
| 179 | - $customer_name_to_display = $associated_customer->last_name . ' ' . $associated_customer->first_name ; |
|
| 178 | + if (!empty($associated_customer->first_name) && !empty($associated_customer->last_name)) { |
|
| 179 | + $customer_name_to_display = $associated_customer->last_name . ' ' . $associated_customer->first_name; |
|
| 180 | 180 | } |
| 181 | - $element_main_infos = ( !empty( $associated_element_definition ) && !empty( $associated_element_definition->labels ) && !empty( $associated_element_definition->labels->singular_name ) ? $associated_element_definition->labels->singular_name . ' - ' : "" ) . $address_associated_element->parent_id . ' - ' . $customer_name_to_display; |
|
| 181 | + $element_main_infos = (!empty($associated_element_definition) && !empty($associated_element_definition->labels) && !empty($associated_element_definition->labels->singular_name) ? $associated_element_definition->labels->singular_name . ' - ' : "") . $address_associated_element->parent_id . ' - ' . $customer_name_to_display; |
|
| 182 | 182 | break; |
| 183 | 183 | |
| 184 | 184 | default: |
| 185 | - $element_main_infos = ( !empty( $associated_element_definition ) && !empty( $associated_element_definition->labels ) && !empty( $associated_element_definition->labels->singular_name ) ? $associated_element_definition->labels->singular_name . ' - ' : "" ) . $address_associated_element->parent_id . ' - ' . $address_associated_element->post_title; |
|
| 185 | + $element_main_infos = (!empty($associated_element_definition) && !empty($associated_element_definition->labels) && !empty($associated_element_definition->labels->singular_name) ? $associated_element_definition->labels->singular_name . ' - ' : "") . $address_associated_element->parent_id . ' - ' . $address_associated_element->post_title; |
|
| 186 | 186 | break; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** Switch current column for custom case */ |
| 190 | 190 | $use_template = true; |
| 191 | - switch ( $column ) { } |
|
| 191 | + switch ($column) { } |
|
| 192 | 192 | |
| 193 | 193 | /** Require the template for displaying the current column */ |
| 194 | - if ( $use_template ) { |
|
| 195 | - $template = wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, 'backend', 'addresses_listtable/' . $column ); |
|
| 196 | - if ( is_file( $template ) ) { |
|
| 197 | - require( $template ); |
|
| 194 | + if ($use_template) { |
|
| 195 | + $template = wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, 'backend', 'addresses_listtable/' . $column); |
|
| 196 | + if (is_file($template)) { |
|
| 197 | + require($template); |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | } |
@@ -204,9 +204,9 @@ discard block |
||
| 204 | 204 | * |
| 205 | 205 | * @param WP_Object $query The current query launched for retrieving addresses |
| 206 | 206 | */ |
| 207 | - function addresses_custom_query( $query ) { |
|
| 208 | - if( is_admin() && $query->query['post_type'] == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS && $query->is_main_query() ) { |
|
| 209 | - add_filter( 'posts_orderby', array( $this, 'addresses_custom_query_order' ) ); |
|
| 207 | + function addresses_custom_query($query) { |
|
| 208 | + if (is_admin() && $query->query['post_type'] == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS && $query->is_main_query()) { |
|
| 209 | + add_filter('posts_orderby', array($this, 'addresses_custom_query_order')); |
|
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | |
@@ -228,15 +228,15 @@ discard block |
||
| 228 | 228 | * |
| 229 | 229 | * @since 1.0 - WPShop 1.3.7.0 |
| 230 | 230 | */ |
| 231 | - function addresses_metaboxes( $post ) { |
|
| 231 | + function addresses_metaboxes($post) { |
|
| 232 | 232 | global $wpdb; |
| 233 | 233 | |
| 234 | - $query = $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s AND post_type = %s", $post, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES ); |
|
| 235 | - $parent = $wpdb->get_var( $query ); |
|
| 236 | - if ( !empty( $parent ) ) { |
|
| 237 | - $address_meta_box_checking = get_post_meta( $parent, '_wpshop_entity_attached_address', true); |
|
| 238 | - if ( !empty($address_meta_box_checking) ) { |
|
| 239 | - add_meta_box( 'wps_attached_addresses', __('Attached addresses', 'wpshop'), array( &$this, 'addresses_metaboxes_content' ), $post, 'normal', 'default' ); |
|
| 234 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s AND post_type = %s", $post, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 235 | + $parent = $wpdb->get_var($query); |
|
| 236 | + if (!empty($parent)) { |
|
| 237 | + $address_meta_box_checking = get_post_meta($parent, '_wpshop_entity_attached_address', true); |
|
| 238 | + if (!empty($address_meta_box_checking)) { |
|
| 239 | + add_meta_box('wps_attached_addresses', __('Attached addresses', 'wpshop'), array(&$this, 'addresses_metaboxes_content'), $post, 'normal', 'default'); |
|
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | } |
@@ -249,9 +249,9 @@ discard block |
||
| 249 | 249 | * |
| 250 | 250 | * @since 1.0 - WPShop 1.3.7.0 |
| 251 | 251 | */ |
| 252 | - function addresses_metaboxes_content( $post, $args ) { |
|
| 253 | - $addresses = self::get_addresses_list( $post->ID ); |
|
| 254 | - require( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "metabox") ); |
|
| 252 | + function addresses_metaboxes_content($post, $args) { |
|
| 253 | + $addresses = self::get_addresses_list($post->ID); |
|
| 254 | + require(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "metabox")); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
@@ -260,17 +260,17 @@ discard block |
||
| 260 | 260 | * @since 1.0 - WPShop 1.3.7.0 |
| 261 | 261 | */ |
| 262 | 262 | function frontend_js() { |
| 263 | - wp_register_style( 'wps_address_frontend_css', WPS_ADDRESS_URL . '/assets/css/frontend.css' ); |
|
| 264 | - wp_enqueue_style( 'wps_address_frontend_css' ); |
|
| 265 | - wp_enqueue_script( 'wps_address_js', WPS_ADDRESS_URL . '/assets/frontend/js/wps_address.js', array( 'jquery', 'jquery-form' ) ); |
|
| 263 | + wp_register_style('wps_address_frontend_css', WPS_ADDRESS_URL . '/assets/css/frontend.css'); |
|
| 264 | + wp_enqueue_style('wps_address_frontend_css'); |
|
| 265 | + wp_enqueue_script('wps_address_js', WPS_ADDRESS_URL . '/assets/frontend/js/wps_address.js', array('jquery', 'jquery-form')); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | function admin_js() { |
| 269 | - wp_enqueue_script( 'wps_address_js', WPS_ADDRESS_URL . '/assets/backend/js/wps_address.js', array( 'jquery', 'jquery-form' ) ); |
|
| 269 | + wp_enqueue_script('wps_address_js', WPS_ADDRESS_URL . '/assets/backend/js/wps_address.js', array('jquery', 'jquery-form')); |
|
| 270 | 270 | } |
| 271 | 271 | function admin_css() { |
| 272 | - wp_register_style( 'wps_address_backend_css', WPS_ADDRESS_URL . '/assets/backend/css/backend.css'/*, array( '' )*/ ); |
|
| 273 | - wp_enqueue_style( 'wps_address_backend_css' ); |
|
| 272 | + wp_register_style('wps_address_backend_css', WPS_ADDRESS_URL . '/assets/backend/css/backend.css'/*, array( '' )*/); |
|
| 273 | + wp_enqueue_style('wps_address_backend_css'); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** Load module/addon automatically to existing template list |
@@ -279,11 +279,11 @@ discard block |
||
| 279 | 279 | * |
| 280 | 280 | * @return array The template with new elements |
| 281 | 281 | */ |
| 282 | - function custom_template_load( $templates ) { |
|
| 283 | - include( WPS_LOCALISATION_TEMPLATES_MAIN_DIR . 'wpshop/main_elements.tpl.php'); |
|
| 282 | + function custom_template_load($templates) { |
|
| 283 | + include(WPS_LOCALISATION_TEMPLATES_MAIN_DIR . 'wpshop/main_elements.tpl.php'); |
|
| 284 | 284 | |
| 285 | 285 | $wpshop_display = new wpshop_display(); |
| 286 | - $templates = $wpshop_display->add_modules_template_to_internal( $tpl_element, $templates ); |
|
| 286 | + $templates = $wpshop_display->add_modules_template_to_internal($tpl_element, $templates); |
|
| 287 | 287 | unset($tpl_element); |
| 288 | 288 | |
| 289 | 289 | return $templates; |
@@ -297,23 +297,23 @@ discard block |
||
| 297 | 297 | * @param Integer $user_id |
| 298 | 298 | * @return Ambigous <multitype:, mixed, string, boolean, unknown, string> |
| 299 | 299 | */ |
| 300 | - public static function get_addresses_list_no_hidden_attributes( $user_id ) { |
|
| 300 | + public static function get_addresses_list_no_hidden_attributes($user_id) { |
|
| 301 | 301 | global $wpdb; |
| 302 | - $query = $wpdb->prepare( 'SELECT ID FROM '. $wpdb->posts . ' WHERE post_type = %s AND post_parent = %s', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $user_id ); |
|
| 303 | - $addresses_ids = $wpdb->get_col( $query ); |
|
| 304 | - $address_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS ); |
|
| 302 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_parent = %s', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $user_id); |
|
| 303 | + $addresses_ids = $wpdb->get_col($query); |
|
| 304 | + $address_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS); |
|
| 305 | 305 | $addresses_result = array(); |
| 306 | - foreach( $addresses_ids as $address_id ) { |
|
| 307 | - $address_post_meta = get_post_meta( $address_id, '_wpshop_address_metadata', true ); |
|
| 308 | - $address_type_id = get_post_meta( $address_id, '_wpshop_address_attribute_set_id', true ); |
|
| 309 | - $query = $wpdb->prepare( 'SELECT attribute_id FROM '.WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND entity_type_id = %d ORDER BY position', $address_type_id, $address_entity_id ); |
|
| 310 | - $attributes_ids = $wpdb->get_col( $query ); |
|
| 311 | - if( !empty( $attributes_ids ) ) { |
|
| 312 | - foreach( $attributes_ids as $attributes_id ) { |
|
| 313 | - $attribute_def = wpshop_attributes::getElement( $attributes_id, '"valid"', 'id' ); |
|
| 314 | - if( !empty( $attribute_def ) && !empty( $address_post_meta[ $attribute_def->code ] ) && $attribute_def->frontend_input != 'hidden' ) { |
|
| 315 | - $addresses_result[ $address_type_id ][ $address_id ][ $attribute_def->code ]['label'] = stripslashes( __( $attribute_def->frontend_label , 'wpshop' ) ); |
|
| 316 | - $addresses_result[ $address_type_id ][ $address_id ][ $attribute_def->code ]['value'] = stripslashes( __( $address_post_meta[ $attribute_def->code ], 'wpshop' ) ); |
|
| 306 | + foreach ($addresses_ids as $address_id) { |
|
| 307 | + $address_post_meta = get_post_meta($address_id, '_wpshop_address_metadata', true); |
|
| 308 | + $address_type_id = get_post_meta($address_id, '_wpshop_address_attribute_set_id', true); |
|
| 309 | + $query = $wpdb->prepare('SELECT attribute_id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND entity_type_id = %d ORDER BY position', $address_type_id, $address_entity_id); |
|
| 310 | + $attributes_ids = $wpdb->get_col($query); |
|
| 311 | + if (!empty($attributes_ids)) { |
|
| 312 | + foreach ($attributes_ids as $attributes_id) { |
|
| 313 | + $attribute_def = wpshop_attributes::getElement($attributes_id, '"valid"', 'id'); |
|
| 314 | + if (!empty($attribute_def) && !empty($address_post_meta[$attribute_def->code]) && $attribute_def->frontend_input != 'hidden') { |
|
| 315 | + $addresses_result[$address_type_id][$address_id][$attribute_def->code]['label'] = stripslashes(__($attribute_def->frontend_label, 'wpshop')); |
|
| 316 | + $addresses_result[$address_type_id][$address_id][$attribute_def->code]['value'] = stripslashes(__($address_post_meta[$attribute_def->code], 'wpshop')); |
|
| 317 | 317 | } |
| 318 | 318 | } |
| 319 | 319 | } |
@@ -326,16 +326,16 @@ discard block |
||
| 326 | 326 | * @param Integer $user_id |
| 327 | 327 | * @return Ambigous <multitype:, mixed, string, boolean, unknown, string> |
| 328 | 328 | */ |
| 329 | - public static function get_addresses_list( $user_id ) { |
|
| 329 | + public static function get_addresses_list($user_id) { |
|
| 330 | 330 | global $wpdb; |
| 331 | 331 | $addresses_list = array(); |
| 332 | - $query = $wpdb->prepare( 'SELECT ID FROM '. $wpdb->posts. ' WHERE post_type = %s AND post_parent = %s', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $user_id ); |
|
| 333 | - $addresses = $wpdb->get_results( $query ); |
|
| 334 | - foreach( $addresses as $address ) { |
|
| 335 | - $address_post_meta = get_post_meta( $address->ID, '_wpshop_address_metadata', true); |
|
| 336 | - $address_type_post_meta = get_post_meta( $address->ID, '_wpshop_address_attribute_set_id', true); |
|
| 332 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_parent = %s', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $user_id); |
|
| 333 | + $addresses = $wpdb->get_results($query); |
|
| 334 | + foreach ($addresses as $address) { |
|
| 335 | + $address_post_meta = get_post_meta($address->ID, '_wpshop_address_metadata', true); |
|
| 336 | + $address_type_post_meta = get_post_meta($address->ID, '_wpshop_address_attribute_set_id', true); |
|
| 337 | 337 | |
| 338 | - if( !empty($address_post_meta) && !empty($address_type_post_meta) ) { |
|
| 338 | + if (!empty($address_post_meta) && !empty($address_type_post_meta)) { |
|
| 339 | 339 | $addresses_list[$address_type_post_meta][$address->ID] = $address_post_meta; |
| 340 | 340 | } |
| 341 | 341 | } |
@@ -343,58 +343,58 @@ discard block |
||
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | /** Display Address**/ |
| 346 | - public static function display_an_address( $address, $address_id = '', $address_type_id = '' ) { |
|
| 346 | + public static function display_an_address($address, $address_id = '', $address_type_id = '') { |
|
| 347 | 347 | global $wpdb; |
| 348 | 348 | $countries = unserialize(WPSHOP_COUNTRY_LIST); |
| 349 | 349 | $output = ''; |
| 350 | - if ( !empty($address) ) { |
|
| 350 | + if (!empty($address)) { |
|
| 351 | 351 | $has_model = false; |
| 352 | 352 | |
| 353 | 353 | /** Check if a model exists**/ |
| 354 | - if ( !empty($address_id) || !empty( $address_type_id ) ) { |
|
| 355 | - $address_type = ( !empty($address_type_id) ) ? $address_type_id : get_post_meta( $address_id, '_wpshop_address_attribute_set_id', true ); |
|
| 356 | - if( !empty($address_type) ) { |
|
| 354 | + if (!empty($address_id) || !empty($address_type_id)) { |
|
| 355 | + $address_type = (!empty($address_type_id)) ? $address_type_id : get_post_meta($address_id, '_wpshop_address_attribute_set_id', true); |
|
| 356 | + if (!empty($address_type)) { |
|
| 357 | 357 | /** Shipping & Billing option **/ |
| 358 | - $shipping_option = get_option( 'wpshop_shipping_address_choice' ); |
|
| 359 | - if ( !empty($shipping_option) && !empty($shipping_option['choice']) && $shipping_option['choice'] == $address_type && !empty($shipping_option['display_model']) ) { |
|
| 360 | - $display_model = $shipping_option['display_model']; |
|
| 358 | + $shipping_option = get_option('wpshop_shipping_address_choice'); |
|
| 359 | + if (!empty($shipping_option) && !empty($shipping_option['choice']) && $shipping_option['choice'] == $address_type && !empty($shipping_option['display_model'])) { |
|
| 360 | + $display_model = $shipping_option['display_model']; |
|
| 361 | 361 | $has_model = true; |
| 362 | 362 | |
| 363 | 363 | } |
| 364 | 364 | else { |
| 365 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
| 366 | - if ( !empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $address_type && !empty($billing_option['display_model']) ) { |
|
| 367 | - $display_model = $billing_option['display_model']; |
|
| 365 | + $billing_option = get_option('wpshop_billing_address'); |
|
| 366 | + if (!empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $address_type && !empty($billing_option['display_model'])) { |
|
| 367 | + $display_model = $billing_option['display_model']; |
|
| 368 | 368 | $has_model = true; |
| 369 | 369 | } |
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | $has_model = false; |
| 374 | - if ( $has_model ) { |
|
| 375 | - foreach( $display_model as $group_id => $group ) { |
|
| 376 | - foreach( $group as $att_id => $att ) { |
|
| 377 | - if ( !empty($att) ) { |
|
| 374 | + if ($has_model) { |
|
| 375 | + foreach ($display_model as $group_id => $group) { |
|
| 376 | + foreach ($group as $att_id => $att) { |
|
| 377 | + if (!empty($att)) { |
|
| 378 | 378 | // Get attribute def |
| 379 | - $attribute_id = str_replace( 'attribute_', '' , $att ); |
|
| 380 | - if( !empty($attribute_id) ) { |
|
| 381 | - $attribute_def = wpshop_attributes::getElement( $attribute_id, '"valid"', 'id' ); |
|
| 382 | - if ( !empty($attribute_def) ) { |
|
| 383 | - if ( $attribute_def->frontend_input == 'select' ) { |
|
| 384 | - $query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d',$address[ $attribute_def->code] ); |
|
| 385 | - $output .= '<strong>'.__( $attribute_def->frontend_label, 'wpshop').' :</strong> '.__( $wpdb->get_var( $query ), 'wpshop' ).' '; |
|
| 379 | + $attribute_id = str_replace('attribute_', '', $att); |
|
| 380 | + if (!empty($attribute_id)) { |
|
| 381 | + $attribute_def = wpshop_attributes::getElement($attribute_id, '"valid"', 'id'); |
|
| 382 | + if (!empty($attribute_def)) { |
|
| 383 | + if ($attribute_def->frontend_input == 'select') { |
|
| 384 | + $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $address[$attribute_def->code]); |
|
| 385 | + $output .= '<strong>' . __($attribute_def->frontend_label, 'wpshop') . ' :</strong> ' . __($wpdb->get_var($query), 'wpshop') . ' '; |
|
| 386 | 386 | } |
| 387 | - elseif( $attribute_def->frontend_verification == 'country' ) { |
|
| 388 | - $output .= ( !empty($countries[ $address[ $attribute_def->code] ]) ) ? '<strong>'.__( $attribute_def->frontend_label, 'wpshop').' :</strong> '.__( $countries[ $address[ $attribute_def->code] ], 'wpshop' ).' ' : ''; |
|
| 387 | + elseif ($attribute_def->frontend_verification == 'country') { |
|
| 388 | + $output .= (!empty($countries[$address[$attribute_def->code]])) ? '<strong>' . __($attribute_def->frontend_label, 'wpshop') . ' :</strong> ' . __($countries[$address[$attribute_def->code]], 'wpshop') . ' ' : ''; |
|
| 389 | 389 | } |
| 390 | 390 | else { |
| 391 | - $output .= ( !empty($address[ $attribute_def->code]) ) ? '<strong>'.__( $attribute_def->frontend_label, 'wpshop').' :</strong> '.$address[ $attribute_def->code].' ' : ' '; |
|
| 391 | + $output .= (!empty($address[$attribute_def->code])) ? '<strong>' . __($attribute_def->frontend_label, 'wpshop') . ' :</strong> ' . $address[$attribute_def->code] . ' ' : ' '; |
|
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | 394 | //End Line |
| 395 | - $next_element = next( $display_model[$group_id] ); |
|
| 396 | - $end_line = strstr( $next_element, '-end-line-', true ); |
|
| 397 | - if ( !empty($end_line) && $end_line == 'wps-attribute' ) { |
|
| 395 | + $next_element = next($display_model[$group_id]); |
|
| 396 | + $end_line = strstr($next_element, '-end-line-', true); |
|
| 397 | + if (!empty($end_line) && $end_line == 'wps-attribute') { |
|
| 398 | 398 | $output .= '<br/>'; |
| 399 | 399 | } |
| 400 | 400 | } |
@@ -403,29 +403,29 @@ discard block |
||
| 403 | 403 | } |
| 404 | 404 | } |
| 405 | 405 | else { |
| 406 | - if( !empty($address_type) ) { |
|
| 406 | + if (!empty($address_type)) { |
|
| 407 | 407 | $tmp_array = array(); |
| 408 | - $address_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS ); |
|
| 409 | - $query = $wpdb->prepare( 'SELECT * FROM '.WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND entity_type_id = %d ORDER BY position', $address_type, $address_entity_id); |
|
| 410 | - $attributes_ids = $wpdb->get_results( $query ); |
|
| 411 | - if( !empty($attributes_ids) ) { |
|
| 412 | - foreach( $attributes_ids as $attributes_id ) { |
|
| 413 | - if ( !empty( $attributes_id->attribute_id ) ) { |
|
| 414 | - $attribute_def = wpshop_attributes::getElement( $attributes_id->attribute_id, '"valid"', 'id' ); |
|
| 415 | - if( $attribute_def->frontend_input != 'hidden') { |
|
| 416 | - if( !empty($attribute_def) && !empty($address[ $attribute_def->code ]) && $attribute_def->frontend_input != 'hidden' ) { |
|
| 417 | - $tmp_array[ $attribute_def->code]['label'] = stripslashes( __( $attribute_def->frontend_label , 'wpshop' ) ); |
|
| 418 | - |
|
| 419 | - if( $attribute_def->frontend_verification == 'country' ) { |
|
| 420 | - $tmp_array[ $attribute_def->code]['value'] = ( !empty($countries[ $address[ $attribute_def->code] ]) ) ? stripslashes( __( $countries[ $address[ $attribute_def->code] ], 'wpshop' ) ) : stripslashes( $address[ $attribute_def->code ] ); |
|
| 408 | + $address_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS); |
|
| 409 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND entity_type_id = %d ORDER BY position', $address_type, $address_entity_id); |
|
| 410 | + $attributes_ids = $wpdb->get_results($query); |
|
| 411 | + if (!empty($attributes_ids)) { |
|
| 412 | + foreach ($attributes_ids as $attributes_id) { |
|
| 413 | + if (!empty($attributes_id->attribute_id)) { |
|
| 414 | + $attribute_def = wpshop_attributes::getElement($attributes_id->attribute_id, '"valid"', 'id'); |
|
| 415 | + if ($attribute_def->frontend_input != 'hidden') { |
|
| 416 | + if (!empty($attribute_def) && !empty($address[$attribute_def->code]) && $attribute_def->frontend_input != 'hidden') { |
|
| 417 | + $tmp_array[$attribute_def->code]['label'] = stripslashes(__($attribute_def->frontend_label, 'wpshop')); |
|
| 418 | + |
|
| 419 | + if ($attribute_def->frontend_verification == 'country') { |
|
| 420 | + $tmp_array[$attribute_def->code]['value'] = (!empty($countries[$address[$attribute_def->code]])) ? stripslashes(__($countries[$address[$attribute_def->code]], 'wpshop')) : stripslashes($address[$attribute_def->code]); |
|
| 421 | 421 | } |
| 422 | - elseif( in_array( $attribute_def->frontend_input, array('select', 'checkbox') ) ) { |
|
| 423 | - $query = $wpdb->prepare( 'SELECT label FROM '. WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $address[ $attribute_def->code] ); |
|
| 424 | - $value = $wpdb->get_var( $query ); |
|
| 425 | - $tmp_array[ $attribute_def->code]['value'] = ( !empty($value) ) ? stripslashes( __( $value, 'wpshop' ) ) : ''; |
|
| 422 | + elseif (in_array($attribute_def->frontend_input, array('select', 'checkbox'))) { |
|
| 423 | + $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $address[$attribute_def->code]); |
|
| 424 | + $value = $wpdb->get_var($query); |
|
| 425 | + $tmp_array[$attribute_def->code]['value'] = (!empty($value)) ? stripslashes(__($value, 'wpshop')) : ''; |
|
| 426 | 426 | } |
| 427 | 427 | else { |
| 428 | - $tmp_array[ $attribute_def->code]['value'] = stripslashes( __( $address[ $attribute_def->code ], 'wpshop' ) ); |
|
| 428 | + $tmp_array[$attribute_def->code]['value'] = stripslashes(__($address[$attribute_def->code], 'wpshop')); |
|
| 429 | 429 | } |
| 430 | 430 | } |
| 431 | 431 | } |
@@ -434,12 +434,12 @@ discard block |
||
| 434 | 434 | $address = $tmp_array; |
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | - foreach( $address as $element_code => $element_value ) { |
|
| 438 | - if( is_array($element_value) ) { |
|
| 439 | - $output .= '<span class="wps-'.$element_code.'"><strong>' .stripslashes( $element_value['label'] ). ' :</strong> ' .stripslashes( $element_value['value'] ). '</span>'; |
|
| 437 | + foreach ($address as $element_code => $element_value) { |
|
| 438 | + if (is_array($element_value)) { |
|
| 439 | + $output .= '<span class="wps-' . $element_code . '"><strong>' . stripslashes($element_value['label']) . ' :</strong> ' . stripslashes($element_value['value']) . '</span>'; |
|
| 440 | 440 | } |
| 441 | 441 | else { |
| 442 | - $output .= '<span class="wps-'.$element_code.'">' .stripslashes( $element_value ). '</span>'; |
|
| 442 | + $output .= '<span class="wps-' . $element_code . '">' . stripslashes($element_value) . '</span>'; |
|
| 443 | 443 | } |
| 444 | 444 | } |
| 445 | 445 | } |
@@ -456,13 +456,13 @@ discard block |
||
| 456 | 456 | * |
| 457 | 457 | * @return string The complete html output for customer addresses |
| 458 | 458 | */ |
| 459 | - function get_addresses_by_type( $address_type_id, $address_type_title, $args = array() ) { |
|
| 459 | + function get_addresses_by_type($address_type_id, $address_type_title, $args = array()) { |
|
| 460 | 460 | global $wpdb; |
| 461 | 461 | /** Get current customer addresses list */ |
| 462 | - if ( is_admin() ) { |
|
| 463 | - $post = !empty( $_GET['post'] ) ? (array) $_GET['post'] : array(); |
|
| 464 | - $post = get_post( $post ); |
|
| 465 | - if ( !empty($post->post_parent) ) { |
|
| 462 | + if (is_admin()) { |
|
| 463 | + $post = !empty($_GET['post']) ? (array)$_GET['post'] : array(); |
|
| 464 | + $post = get_post($post); |
|
| 465 | + if (!empty($post->post_parent)) { |
|
| 466 | 466 | $customer_id = $post->post_parent; |
| 467 | 467 | } |
| 468 | 468 | else { |
@@ -481,85 +481,85 @@ discard block |
||
| 481 | 481 | AND ADDRESSES.post_parent = %d |
| 482 | 482 | AND ADDRESSES_META.meta_key = %s |
| 483 | 483 | AND ADDRESSES_META.meta_value = %d", |
| 484 | - WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $customer_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_attribute_set_id', $address_type_id); |
|
| 484 | + WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $customer_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $address_type_id); |
|
| 485 | 485 | $addresses = $wpdb->get_results($query); |
| 486 | 486 | $addresses_list = ''; |
| 487 | 487 | |
| 488 | 488 | |
| 489 | 489 | /** Initialize */ |
| 490 | 490 | $tpl_component = array(); |
| 491 | - $tpl_component['CUSTOMER_ADDRESS_TYPE_TITLE'] = ( !empty($args) && !empty($args['first']) && $args['first'] ) ? __('Your address', 'wpshop') : $address_type_title; |
|
| 491 | + $tpl_component['CUSTOMER_ADDRESS_TYPE_TITLE'] = (!empty($args) && !empty($args['first']) && $args['first']) ? __('Your address', 'wpshop') : $address_type_title; |
|
| 492 | 492 | $tpl_component['LOADING_ICON'] = WPSHOP_LOADING_ICON; |
| 493 | 493 | $tpl_component['ADDRESS_BUTTONS'] = ''; |
| 494 | - if( count($addresses) > 0 ) { |
|
| 495 | - $tpl_component['ADD_NEW_ADDRESS_LINK'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?')===false ? '?' : '&'). 'action=add_address&type=' .$address_type_id; |
|
| 494 | + if (count($addresses) > 0) { |
|
| 495 | + $tpl_component['ADD_NEW_ADDRESS_LINK'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?') === false ? '?' : '&') . 'action=add_address&type=' . $address_type_id; |
|
| 496 | 496 | } |
| 497 | 497 | else { |
| 498 | - $tpl_component['ADD_NEW_ADDRESS_LINK'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?')===false ? '?' : '&'). 'action=add_address&type=' .$address_type_id .'&first'; |
|
| 498 | + $tpl_component['ADD_NEW_ADDRESS_LINK'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?') === false ? '?' : '&') . 'action=add_address&type=' . $address_type_id . '&first'; |
|
| 499 | 499 | } |
| 500 | - $tpl_component['ADDRESS_TYPE'] = ( !empty($address_type_title) && ($address_type_title == __('Shipping address', 'wpshop'))) ? 'shipping_address' : 'billing_address'; |
|
| 501 | - $tpl_component['ADD_NEW_ADDRESS_TITLE'] = sprintf(__('Add a new %s', 'wpshop'), ( ( !empty($args) && !empty($args['first']) && $args['first'] ) ? __('address', 'wpshop') : $address_type_title )); |
|
| 500 | + $tpl_component['ADDRESS_TYPE'] = (!empty($address_type_title) && ($address_type_title == __('Shipping address', 'wpshop'))) ? 'shipping_address' : 'billing_address'; |
|
| 501 | + $tpl_component['ADD_NEW_ADDRESS_TITLE'] = sprintf(__('Add a new %s', 'wpshop'), ((!empty($args) && !empty($args['first']) && $args['first']) ? __('address', 'wpshop') : $address_type_title)); |
|
| 502 | 502 | |
| 503 | 503 | |
| 504 | 504 | /** Read customer list */ |
| 505 | - if( count($addresses) > 0 ) { |
|
| 505 | + if (count($addresses) > 0) { |
|
| 506 | 506 | /** Get the fields for addresses */ |
| 507 | 507 | $address_fields = wps_address::get_addresss_form_fields_by_type($address_type_id); |
| 508 | 508 | $first = true; |
| 509 | 509 | $tpl_component['ADDRESS_COMBOBOX_OPTION'] = ''; |
| 510 | 510 | $nb_of_addresses = 0; |
| 511 | - foreach ( $addresses as $address ) { |
|
| 511 | + foreach ($addresses as $address) { |
|
| 512 | 512 | // Display the addresses |
| 513 | 513 | /** If there isn't address in SESSION we display the first address of list by default */ |
| 514 | - if ( empty($_SESSION[$tpl_component['ADDRESS_TYPE']]) && $first && !is_admin() ) { |
|
| 514 | + if (empty($_SESSION[$tpl_component['ADDRESS_TYPE']]) && $first && !is_admin()) { |
|
| 515 | 515 | $address_id = $address->ID; |
| 516 | - if ( !is_admin() ) { |
|
| 516 | + if (!is_admin()) { |
|
| 517 | 517 | $_SESSION[$tpl_component['ADDRESS_TYPE']] = $address->ID; |
| 518 | 518 | } |
| 519 | 519 | } |
| 520 | 520 | else { |
| 521 | - $address_id = ( !empty($_SESSION[$tpl_component['ADDRESS_TYPE']]) ) ? $_SESSION[$tpl_component['ADDRESS_TYPE']] : ''; |
|
| 521 | + $address_id = (!empty($_SESSION[$tpl_component['ADDRESS_TYPE']])) ? $_SESSION[$tpl_component['ADDRESS_TYPE']] : ''; |
|
| 522 | 522 | } |
| 523 | - $address_selected_infos = get_post_meta($address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true); |
|
| 524 | - $address_infos = get_post_meta($address->ID, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true); |
|
| 523 | + $address_selected_infos = get_post_meta($address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true); |
|
| 524 | + $address_infos = get_post_meta($address->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true); |
|
| 525 | 525 | |
| 526 | 526 | |
| 527 | - if ( !empty($address_infos) ) { |
|
| 527 | + if (!empty($address_infos)) { |
|
| 528 | 528 | |
| 529 | 529 | $tpl_component['ADDRESS_ID'] = $address->ID; |
| 530 | 530 | /** If no address was selected, we select the first of the list **/ |
| 531 | 531 | $tpl_component['CUSTOMER_ADDRESS_CONTENT'] = self::display_an_address($address_fields, $address_selected_infos, $address_id); |
| 532 | 532 | $tpl_component['ADDRESS_BUTTONS'] = wpshop_display::display_template_element('addresses_box_actions_button_edit', $tpl_component); |
| 533 | - $tpl_component['choosen_address_LINK_EDIT'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?')===false ? '?' : '&') . 'action=editAddress&id='.$address_id; |
|
| 533 | + $tpl_component['choosen_address_LINK_EDIT'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?') === false ? '?' : '&') . 'action=editAddress&id=' . $address_id; |
|
| 534 | 534 | $tpl_component['DEFAULT_ADDRESS_ID'] = $address_id; |
| 535 | 535 | $tpl_component['ADRESS_CONTAINER_CLASS'] = ' wpshop_customer_adress_container_' . $address->ID; |
| 536 | 536 | $tpl_component['CUSTOMER_CHOOSEN_ADDRESS'] = wpshop_display::display_template_element('display_address_container', $tpl_component); |
| 537 | - if ( empty($tpl_component['CUSTOMER_ADDRESS_CONTENT']) ) { |
|
| 538 | - $tpl_component['CUSTOMER_CHOOSEN_ADDRESS'] = '<span style="color:red;">'.__('No data','wpshop').'</span>'; |
|
| 537 | + if (empty($tpl_component['CUSTOMER_ADDRESS_CONTENT'])) { |
|
| 538 | + $tpl_component['CUSTOMER_CHOOSEN_ADDRESS'] = '<span style="color:red;">' . __('No data', 'wpshop') . '</span>'; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | - $tpl_component['ADDRESS_COMBOBOX_OPTION'] .= '<option value="' .$address->ID. '" ' .( ( !empty($_SESSION[$tpl_component['ADDRESS_TYPE']]) && $_SESSION[$tpl_component['ADDRESS_TYPE']] == $address->ID) ? 'selected="selected"' : null). '>' . (!empty($address_infos['address_title']) ? $address_infos['address_title'] : $address_type_title) . '</option>'; |
|
| 541 | + $tpl_component['ADDRESS_COMBOBOX_OPTION'] .= '<option value="' . $address->ID . '" ' . ((!empty($_SESSION[$tpl_component['ADDRESS_TYPE']]) && $_SESSION[$tpl_component['ADDRESS_TYPE']] == $address->ID) ? 'selected="selected"' : null) . '>' . (!empty($address_infos['address_title']) ? $address_infos['address_title'] : $address_type_title) . '</option>'; |
|
| 542 | 542 | $nb_of_addresses++; |
| 543 | 543 | } |
| 544 | 544 | $first = false; |
| 545 | 545 | } |
| 546 | 546 | $tpl_component['ADDRESS_COMBOBOX'] = ''; |
| 547 | - if ( !is_admin() ) { |
|
| 547 | + if (!is_admin()) { |
|
| 548 | 548 | $tpl_component['ADDRESS_COMBOBOX'] = (!empty($tpl_component['ADDRESS_COMBOBOX_OPTION']) && ($nb_of_addresses > 1)) ? wpshop_display::display_template_element('addresses_type_combobox', $tpl_component) : ''; |
| 549 | 549 | } |
| 550 | 550 | } |
| 551 | 551 | else { |
| 552 | - if ( !empty($args) && !empty($args['first']) && $args['first'] ) { |
|
| 552 | + if (!empty($args) && !empty($args['first']) && $args['first']) { |
|
| 553 | 553 | $tpl_component['ADDRESS_TYPE'] = 'first_address'; |
| 554 | 554 | } |
| 555 | 555 | $tpl_component['ADDRESS_ID'] = 0; |
| 556 | 556 | $tpl_component['DEFAULT_ADDRESS_ID'] = 0; |
| 557 | 557 | $tpl_component['ADDRESS_COMBOBOX'] = ''; |
| 558 | - $tpl_component['CUSTOMER_CHOOSEN_ADDRESS'] = sprintf( __('You don\'t have any %s, %splease create a new one%s', 'wpshop'), ( (!empty($args) && !empty($args['first']) && $args['first']) ? __('address', 'wpshop') : strtolower($address_type_title) ) , '<a href="' . $tpl_component['ADD_NEW_ADDRESS_LINK'] . '" >', '</a>' ); |
|
| 558 | + $tpl_component['CUSTOMER_CHOOSEN_ADDRESS'] = sprintf(__('You don\'t have any %s, %splease create a new one%s', 'wpshop'), ((!empty($args) && !empty($args['first']) && $args['first']) ? __('address', 'wpshop') : strtolower($address_type_title)), '<a href="' . $tpl_component['ADD_NEW_ADDRESS_LINK'] . '" >', '</a>'); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | $tpl_component['ADDRESS_BUTTONS'] .= wpshop_display::display_template_element('addresses_box_actions_button_new_address', $tpl_component); |
| 562 | - if ( !empty($args['only_display']) && ($args['only_display'] == 'yes') ) { |
|
| 562 | + if (!empty($args['only_display']) && ($args['only_display'] == 'yes')) { |
|
| 563 | 563 | $tpl_component['ADDRESS_BUTTONS'] = ''; |
| 564 | 564 | } |
| 565 | 565 | |
@@ -579,40 +579,40 @@ discard block |
||
| 579 | 579 | * @param integer $user_id |
| 580 | 580 | * @return string |
| 581 | 581 | */ |
| 582 | - function loading_address_form( $address_type_id, $address_id = '', $user_id = '', $display_in_front = false ) { |
|
| 582 | + function loading_address_form($address_type_id, $address_id = '', $user_id = '', $display_in_front = false) { |
|
| 583 | 583 | $response = '<div id="wps_address_error_container"></div>'; |
| 584 | - $response .= '<form id="wps_address_form_save" action="' .admin_url('admin-ajax.php'). '" method="post">'; |
|
| 584 | + $response .= '<form id="wps_address_form_save" action="' . admin_url('admin-ajax.php') . '" method="post">'; |
|
| 585 | 585 | $response .= '<input type="hidden" name="action" value="wps_save_address" />'; |
| 586 | - $response .= wp_nonce_field( 'wps_save_address' ); |
|
| 586 | + $response .= wp_nonce_field('wps_save_address'); |
|
| 587 | 587 | $first_address_checking = false; |
| 588 | 588 | |
| 589 | - $user_id = ( !empty($user_id) ) ? $user_id : get_current_user_id(); |
|
| 589 | + $user_id = (!empty($user_id)) ? $user_id : get_current_user_id(); |
|
| 590 | 590 | |
| 591 | - if ( !empty($address_id) ) { |
|
| 592 | - $address_type = get_post_meta( $address_id, '_wpshop_address_attribute_set_id', true); |
|
| 591 | + if (!empty($address_id)) { |
|
| 592 | + $address_type = get_post_meta($address_id, '_wpshop_address_attribute_set_id', true); |
|
| 593 | 593 | $response .= self::display_form_fields($address_type, $address_id, '', '', array(), array(), array(), $user_id); |
| 594 | 594 | $title = __('Edit your address', 'wpshop'); |
| 595 | 595 | } |
| 596 | - elseif($address_type_id) { |
|
| 597 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
| 596 | + elseif ($address_type_id) { |
|
| 597 | + $billing_option = get_option('wpshop_billing_address'); |
|
| 598 | 598 | |
| 599 | - $addresses = self::get_addresses_list( $user_id ); |
|
| 600 | - $list_addresses = ( !empty($addresses[ $billing_option['choice'] ]) ) ? $addresses[ $billing_option['choice'] ] : array(); |
|
| 601 | - $first_address_checking = ( empty( $list_addresses ) ) ? true : false; |
|
| 599 | + $addresses = self::get_addresses_list($user_id); |
|
| 600 | + $list_addresses = (!empty($addresses[$billing_option['choice']])) ? $addresses[$billing_option['choice']] : array(); |
|
| 601 | + $first_address_checking = (empty($list_addresses)) ? true : false; |
|
| 602 | 602 | |
| 603 | - $response .= self::display_form_fields($address_type_id, '', '', '', array(), array(), array(), $user_id ); |
|
| 603 | + $response .= self::display_form_fields($address_type_id, '', '', '', array(), array(), array(), $user_id); |
|
| 604 | 604 | $title = __('Add a new address', 'wpshop'); |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** Check if a billing address is already save **/ |
| 608 | - if ( $first_address_checking && $address_type_id != $billing_option['choice'] ) { |
|
| 609 | - $response .= '<div class="wps-form"><input name="wps-shipping-to-billing" id="wps-shipping-to-billing" checked="checked" type="checkbox" /> <label for="wps-shipping-to-billing">' .__( 'Use the same address for billing', 'wpshop' ). '</label></div>'; |
|
| 608 | + if ($first_address_checking && $address_type_id != $billing_option['choice']) { |
|
| 609 | + $response .= '<div class="wps-form"><input name="wps-shipping-to-billing" id="wps-shipping-to-billing" checked="checked" type="checkbox" /> <label for="wps-shipping-to-billing">' . __('Use the same address for billing', 'wpshop') . '</label></div>'; |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | - $response .= '<button id="wps_submit_address_form" class="wps-bton-first-alignRight-rounded">' .__('Save', 'wpshop'). '</button>'; |
|
| 612 | + $response .= '<button id="wps_submit_address_form" class="wps-bton-first-alignRight-rounded">' . __('Save', 'wpshop') . '</button>'; |
|
| 613 | 613 | |
| 614 | 614 | $response .= '</form>'; |
| 615 | - return array( $response, $title ); |
|
| 615 | + return array($response, $title); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -620,35 +620,35 @@ discard block |
||
| 620 | 620 | * @param $typeof |
| 621 | 621 | * @return array |
| 622 | 622 | */ |
| 623 | - public static function get_addresss_form_fields_by_type ( $typeof, $id ='' ) { |
|
| 623 | + public static function get_addresss_form_fields_by_type($typeof, $id = '') { |
|
| 624 | 624 | // Sanitize all $_POST |
| 625 | 625 | |
| 626 | - $submit_billing_and_shipping_info = !empty( $_POST['submitbillingAndShippingInfo'] ) ? sanitize_key( $_POST['submitbillingAndShippingInfo'] ) : ''; |
|
| 626 | + $submit_billing_and_shipping_info = !empty($_POST['submitbillingAndShippingInfo']) ? sanitize_key($_POST['submitbillingAndShippingInfo']) : ''; |
|
| 627 | 627 | |
| 628 | 628 | $current_item_edited = isset($id) ? (int)wpshop_tools::varSanitizer($id) : null; |
| 629 | 629 | $address = array(); |
| 630 | 630 | $all_addresses = ''; |
| 631 | - $attribute = !empty( $_POST['attribute'] ) ? (array) $_POST['attribute'] : array(); |
|
| 631 | + $attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : array(); |
|
| 632 | 632 | /* Get the attribute set details in order to build the product interface */ |
| 633 | 633 | |
| 634 | 634 | $atribute_set_details = wpshop_attributes_set::getAttributeSetDetails($typeof, "'valid'"); |
| 635 | - if ( !empty($atribute_set_details) ) { |
|
| 635 | + if (!empty($atribute_set_details)) { |
|
| 636 | 636 | foreach ($atribute_set_details as $productAttributeSetDetail) { |
| 637 | 637 | $address = array(); |
| 638 | 638 | $group_name = $productAttributeSetDetail['name']; |
| 639 | 639 | |
| 640 | - if(count($productAttributeSetDetail['attribut']) >= 1){ |
|
| 641 | - foreach($productAttributeSetDetail['attribut'] as $attribute) { |
|
| 642 | - if(!empty($attribute->id)) { |
|
| 643 | - if ( !empty( $submit_billing_and_shipping_info ) ) { |
|
| 640 | + if (count($productAttributeSetDetail['attribut']) >= 1) { |
|
| 641 | + foreach ($productAttributeSetDetail['attribut'] as $attribute) { |
|
| 642 | + if (!empty($attribute->id)) { |
|
| 643 | + if (!empty($submit_billing_and_shipping_info)) { |
|
| 644 | 644 | $value = $attribute[$typeof][$attribute->data_type][$attribute->code]; |
| 645 | 645 | } |
| 646 | 646 | else { |
| 647 | 647 | $value = wpshop_attributes::getAttributeValueForEntityInSet($attribute->data_type, $attribute->id, wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS), $current_item_edited, array('intrinsic' => $attribute->is_intrinsic, 'backend_input' => $attribute->backend_input)); |
| 648 | 648 | } |
| 649 | - $attribute_output_def = wpshop_attributes::get_attribute_field_definition( $attribute, $value, array() ); |
|
| 650 | - $attribute_output_def['id'] = 'address_' . $typeof . '_' .$attribute_output_def['id']; |
|
| 651 | - $address[str_replace( '-', '_', sanitize_title($group_name) ).'_'.$attribute->code] = $attribute_output_def; |
|
| 649 | + $attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute, $value, array()); |
|
| 650 | + $attribute_output_def['id'] = 'address_' . $typeof . '_' . $attribute_output_def['id']; |
|
| 651 | + $address[str_replace('-', '_', sanitize_title($group_name)) . '_' . $attribute->code] = $attribute_output_def; |
|
| 652 | 652 | } |
| 653 | 653 | } |
| 654 | 654 | } |
@@ -668,25 +668,25 @@ discard block |
||
| 668 | 668 | /** Treat the differents fields of form and classified them by form |
| 669 | 669 | * @return boolean |
| 670 | 670 | */ |
| 671 | - public static function save_address_infos( $attribute_set_id ) { |
|
| 671 | + public static function save_address_infos($attribute_set_id) { |
|
| 672 | 672 | global $wpdb; |
| 673 | - $adress_save_the_first = !empty( $_POST['wps-address-save-the-first'] ) ? sanitize_text_field( $_POST['wps-address-save-the-first'] ) : ''; |
|
| 674 | - $attribute = !empty( $_POST['attribute'] ) ? (array)$_POST['attribute'] : ''; |
|
| 675 | - if ( !empty( $attribute[$attribute_set_id] ) ) { |
|
| 676 | - $attribute[$attribute_set_id]['varchar']['address_title'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['address_title'] ); |
|
| 677 | - $attribute[$attribute_set_id]['varchar']['address_last_name'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['address_last_name'] ); |
|
| 678 | - $attribute[$attribute_set_id]['varchar']['address_first_name'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['address_first_name'] ); |
|
| 679 | - $attribute[$attribute_set_id]['varchar']['company'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['company'] ); |
|
| 680 | - $attribute[$attribute_set_id]['varchar']['company'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['company'] ); |
|
| 681 | - $attribute[$attribute_set_id]['varchar']['postcode'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['postcode'] ); |
|
| 682 | - $attribute[$attribute_set_id]['varchar']['city'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['city'] ); |
|
| 683 | - $attribute[$attribute_set_id]['varchar']['country'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['country'] ); |
|
| 684 | - $attribute[$attribute_set_id]['varchar']['state'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['state'] ); |
|
| 685 | - $attribute[$attribute_set_id]['varchar']['longitude'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['longitude'] ); |
|
| 686 | - $attribute[$attribute_set_id]['varchar']['latitude'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['latitude'] ); |
|
| 673 | + $adress_save_the_first = !empty($_POST['wps-address-save-the-first']) ? sanitize_text_field($_POST['wps-address-save-the-first']) : ''; |
|
| 674 | + $attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : ''; |
|
| 675 | + if (!empty($attribute[$attribute_set_id])) { |
|
| 676 | + $attribute[$attribute_set_id]['varchar']['address_title'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['address_title']); |
|
| 677 | + $attribute[$attribute_set_id]['varchar']['address_last_name'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['address_last_name']); |
|
| 678 | + $attribute[$attribute_set_id]['varchar']['address_first_name'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['address_first_name']); |
|
| 679 | + $attribute[$attribute_set_id]['varchar']['company'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['company']); |
|
| 680 | + $attribute[$attribute_set_id]['varchar']['company'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['company']); |
|
| 681 | + $attribute[$attribute_set_id]['varchar']['postcode'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['postcode']); |
|
| 682 | + $attribute[$attribute_set_id]['varchar']['city'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['city']); |
|
| 683 | + $attribute[$attribute_set_id]['varchar']['country'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['country']); |
|
| 684 | + $attribute[$attribute_set_id]['varchar']['state'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['state']); |
|
| 685 | + $attribute[$attribute_set_id]['varchar']['longitude'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['longitude']); |
|
| 686 | + $attribute[$attribute_set_id]['varchar']['latitude'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['latitude']); |
|
| 687 | 687 | $attribute[$attribute_set_id]['integer']['civility'] = (int)$attribute[$attribute_set_id]['integer']['civility']; |
| 688 | 688 | |
| 689 | - if ( !empty( $attribute[$attribute_set_id]['item_id'] ) ) { |
|
| 689 | + if (!empty($attribute[$attribute_set_id]['item_id'])) { |
|
| 690 | 690 | $attribute[$attribute_set_id]['item_id'] = (int)$attribute[$attribute_set_id]['item_id']; |
| 691 | 691 | } |
| 692 | 692 | } |
@@ -694,23 +694,23 @@ discard block |
||
| 694 | 694 | $shipping_address = (int)$_POST['shipping_address']; |
| 695 | 695 | $type_of_form = (int)$_POST['type_of_form']; |
| 696 | 696 | $current_item_edited = !empty($_POST['attribute'][$attribute_set_id]['item_id']) ? (int)wpshop_tools::varSanitizer($_POST['attribute'][$attribute_set_id]['item_id']) : null; |
| 697 | - $current_attribute_set_id = !empty( $_POST['current_attribute_set_id'] ) ? (int)$_POST['current_attribute_set_id'] : ''; |
|
| 698 | - $shipping_to_billing = !empty( $_POST['wps-shipping-to-billing'] ) ? sanitize_text_field( $_POST['wps-shipping-to-billing'] ) : ''; |
|
| 699 | - $shipping_to_billing_id = !empty( $_POST['wps-shipping-to-billing-id'] ) ? (int)$_POST['wps-shipping-to-billing-id'] : ''; |
|
| 697 | + $current_attribute_set_id = !empty($_POST['current_attribute_set_id']) ? (int)$_POST['current_attribute_set_id'] : ''; |
|
| 698 | + $shipping_to_billing = !empty($_POST['wps-shipping-to-billing']) ? sanitize_text_field($_POST['wps-shipping-to-billing']) : ''; |
|
| 699 | + $shipping_to_billing_id = !empty($_POST['wps-shipping-to-billing-id']) ? (int)$_POST['wps-shipping-to-billing-id'] : ''; |
|
| 700 | 700 | |
| 701 | 701 | // Create or update the post address |
| 702 | 702 | |
| 703 | 703 | // @TODO : REQUEST |
| 704 | 704 | $post_parent = ''; |
| 705 | 705 | $post_author = get_current_user_id(); |
| 706 | - $customer_id = !empty( $_REQUEST['user']['customer_id'] ) ? (int) $_REQUEST['user']['customer_id'] : 0; |
|
| 707 | - $post_ID = !empty( $_REQUEST['post_ID'] ) ? (int) $_REQUEST['post_ID'] : 0; |
|
| 706 | + $customer_id = !empty($_REQUEST['user']['customer_id']) ? (int)$_REQUEST['user']['customer_id'] : 0; |
|
| 707 | + $post_ID = !empty($_REQUEST['post_ID']) ? (int)$_REQUEST['post_ID'] : 0; |
|
| 708 | 708 | |
| 709 | - if ( !empty($customer_id) ) { |
|
| 709 | + if (!empty($customer_id)) { |
|
| 710 | 710 | $post_parent = $customer_id; |
| 711 | 711 | $post_author = $customer_id; |
| 712 | 712 | } |
| 713 | - elseif ( !empty( $post_ID ) ) { |
|
| 713 | + elseif (!empty($post_ID)) { |
|
| 714 | 714 | $post_parent = $post_ID; |
| 715 | 715 | } |
| 716 | 716 | else { |
@@ -727,57 +727,57 @@ discard block |
||
| 727 | 727 | |
| 728 | 728 | $edit_other_thing = true; |
| 729 | 729 | |
| 730 | - if ( empty($current_item_edited) && (empty( $current_attribute_set_id ) || $current_attribute_set_id != $attribute_set_id )) { |
|
| 731 | - $current_item_edited = wp_insert_post( $post_address ); |
|
| 732 | - if ( is_admin()) { |
|
| 730 | + if (empty($current_item_edited) && (empty($current_attribute_set_id) || $current_attribute_set_id != $attribute_set_id)) { |
|
| 731 | + $current_item_edited = wp_insert_post($post_address); |
|
| 732 | + if (is_admin()) { |
|
| 733 | 733 | $attribute[$attribute_set_id]['item_id'] = $current_item_edited; |
| 734 | 734 | } |
| 735 | 735 | } |
| 736 | 736 | else { |
| 737 | 737 | $post_address['ID'] = $current_item_edited; |
| 738 | - wp_update_post( $post_address ); |
|
| 738 | + wp_update_post($post_address); |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | /* Shipping to billing save */ |
| 742 | - if( !empty( $shipping_to_billing ) ) { |
|
| 743 | - $wps_shipping_to_billing = array( 'wps-shipping-to-billing' => $shipping_to_billing ); |
|
| 742 | + if (!empty($shipping_to_billing)) { |
|
| 743 | + $wps_shipping_to_billing = array('wps-shipping-to-billing' => $shipping_to_billing); |
|
| 744 | 744 | |
| 745 | - if( !empty( $shipping_to_billing_id ) ) { |
|
| 745 | + if (!empty($shipping_to_billing_id)) { |
|
| 746 | 746 | $wps_shipping_to_billing['wps-shipping-to-billing-id'] = $shipping_to_billing_id; |
| 747 | 747 | } |
| 748 | - update_post_meta($current_item_edited, 'wps-shipping-to-billing', $wps_shipping_to_billing ); |
|
| 748 | + update_post_meta($current_item_edited, 'wps-shipping-to-billing', $wps_shipping_to_billing); |
|
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | //Update the post_meta of address |
| 752 | 752 | update_post_meta($current_item_edited, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, $attribute_set_id); |
| 753 | 753 | |
| 754 | 754 | |
| 755 | - foreach ( $attribute[ $attribute_set_id ] as $type => $type_content) { |
|
| 755 | + foreach ($attribute[$attribute_set_id] as $type => $type_content) { |
|
| 756 | 756 | $attribute_not_to_do = array(); |
| 757 | - if (is_array($type_content) ) { |
|
| 758 | - foreach ( $type_content as $code => $value) { |
|
| 757 | + if (is_array($type_content)) { |
|
| 758 | + foreach ($type_content as $code => $value) { |
|
| 759 | 759 | $attribute_def = wpshop_attributes::getElement($code, "'valid'", 'code'); |
| 760 | - if ( !empty($attribute_def->_need_verification) && $attribute_def->_need_verification == 'yes' ) { |
|
| 761 | - $code_verif = $code.'2'; |
|
| 760 | + if (!empty($attribute_def->_need_verification) && $attribute_def->_need_verification == 'yes') { |
|
| 761 | + $code_verif = $code . '2'; |
|
| 762 | 762 | $attribute_not_to_do[] = $code_verif; |
| 763 | - if ( !empty($attributes[$code_verif] )) { |
|
| 763 | + if (!empty($attributes[$code_verif])) { |
|
| 764 | 764 | unset($attributes[$code_verif]); |
| 765 | 765 | } |
| 766 | 766 | } |
| 767 | - if( !in_array($code, $attribute_not_to_do)) $attributes[$code] = $value; |
|
| 767 | + if (!in_array($code, $attribute_not_to_do)) $attributes[$code] = $value; |
|
| 768 | 768 | } |
| 769 | 769 | } |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | - $attributes = apply_filters( 'wps-address-coordinate-calculation', $attributes ); |
|
| 772 | + $attributes = apply_filters('wps-address-coordinate-calculation', $attributes); |
|
| 773 | 773 | |
| 774 | - $result = wpshop_attributes::setAttributesValuesForItem( $current_item_edited, $attributes, false, '' ); |
|
| 774 | + $result = wpshop_attributes::setAttributesValuesForItem($current_item_edited, $attributes, false, ''); |
|
| 775 | 775 | $result['current_id'] = $current_item_edited; |
| 776 | 776 | |
| 777 | - if( !empty($result['current_id']) ) { |
|
| 777 | + if (!empty($result['current_id'])) { |
|
| 778 | 778 | // Update $_SESSION[address type] |
| 779 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
| 780 | - if( !empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $attribute_set_id ) { |
|
| 779 | + $billing_option = get_option('wpshop_billing_address'); |
|
| 780 | + if (!empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $attribute_set_id) { |
|
| 781 | 781 | $_SESSION['billing_address'] = $result['current_id']; |
| 782 | 782 | } |
| 783 | 783 | else { |
@@ -795,28 +795,28 @@ discard block |
||
| 795 | 795 | * @param string $referer : Referer website page |
| 796 | 796 | * @param string $admin : Display this form in admin panel |
| 797 | 797 | */ |
| 798 | - public static function display_form_fields($type, $id = '', $first = '', $referer = '', $special_values = array(), $options = array(), $display_for_admin = array(), $other_customer = '' ) { |
|
| 798 | + public static function display_form_fields($type, $id = '', $first = '', $referer = '', $special_values = array(), $options = array(), $display_for_admin = array(), $other_customer = '') { |
|
| 799 | 799 | global $wpshop, $wpshop_form, $wpdb; |
| 800 | 800 | |
| 801 | 801 | $choosen_address = get_option('wpshop_billing_address'); |
| 802 | 802 | $shipping_address = get_option('wpshop_shipping_address_choice'); |
| 803 | 803 | $output_form_fields = $form_model = ''; |
| 804 | 804 | |
| 805 | - $user_id = ( !empty($other_customer) ) ? $other_customer : get_current_user_id(); |
|
| 805 | + $user_id = (!empty($other_customer)) ? $other_customer : get_current_user_id(); |
|
| 806 | 806 | |
| 807 | 807 | |
| 808 | - if ( empty($type) ) { |
|
| 808 | + if (empty($type)) { |
|
| 809 | 809 | $type = $choosen_address['choice']; |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | $result = wps_address::get_addresss_form_fields_by_type($type, $id); |
| 813 | 813 | |
| 814 | 814 | /** Check if it's shipping or billing **/ |
| 815 | - if ( $type == $choosen_address['choice'] ) { |
|
| 816 | - $form_model = ( !empty($choosen_address['display_model']) ) ? $choosen_address['display_model'] : null; |
|
| 815 | + if ($type == $choosen_address['choice']) { |
|
| 816 | + $form_model = (!empty($choosen_address['display_model'])) ? $choosen_address['display_model'] : null; |
|
| 817 | 817 | } |
| 818 | - elseif( $type == $shipping_address['choice'] ) { |
|
| 819 | - $form_model = ( !empty($shipping_address['display_model']) ) ? $shipping_address['display_model'] : null; |
|
| 818 | + elseif ($type == $shipping_address['choice']) { |
|
| 819 | + $form_model = (!empty($shipping_address['display_model'])) ? $shipping_address['display_model'] : null; |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | |
@@ -826,17 +826,17 @@ discard block |
||
| 826 | 826 | // take the address informations |
| 827 | 827 | $current_item_edited = !empty($id) ? (int)wpshop_tools::varSanitizer($id) : null; |
| 828 | 828 | |
| 829 | - foreach ( $form as $group_id => $group_fields) { |
|
| 830 | - if ( empty($options) || (!empty($options) && ($options['title']))) $output_form_fields .= '<h2>'.__( $group_fields['name'], 'wpshop' ).'</h2>'; |
|
| 829 | + foreach ($form as $group_id => $group_fields) { |
|
| 830 | + if (empty($options) || (!empty($options) && ($options['title']))) $output_form_fields .= '<h2>' . __($group_fields['name'], 'wpshop') . '</h2>'; |
|
| 831 | 831 | $end_line_indicator = 0; $fields_limit_per_line = -1; |
| 832 | - foreach ( $group_fields['content'] as $key => $field) { |
|
| 833 | - $attribute_def = wpshop_attributes::getElement( $field['name'], $element_status = "'valid'", $field_to_search = 'code' ); |
|
| 832 | + foreach ($group_fields['content'] as $key => $field) { |
|
| 833 | + $attribute_def = wpshop_attributes::getElement($field['name'], $element_status = "'valid'", $field_to_search = 'code'); |
|
| 834 | 834 | /** Grid opening **/ |
| 835 | - if ( !empty($form_model) && !empty($form_model[$group_id]) && in_array('wps-attribute-end-line-'.$end_line_indicator, $form_model[$group_id]) && $fields_limit_per_line == -1 ) { |
|
| 836 | - $current_key = array_search( 'wps-attribute-end-line-'.$end_line_indicator, $form_model[$group_id] ); |
|
| 837 | - $current_attribute_key = array_search( 'attribute_'.$attribute_def->id, $form_model[$group_id] ); |
|
| 835 | + if (!empty($form_model) && !empty($form_model[$group_id]) && in_array('wps-attribute-end-line-' . $end_line_indicator, $form_model[$group_id]) && $fields_limit_per_line == -1) { |
|
| 836 | + $current_key = array_search('wps-attribute-end-line-' . $end_line_indicator, $form_model[$group_id]); |
|
| 837 | + $current_attribute_key = array_search('attribute_' . $attribute_def->id, $form_model[$group_id]); |
|
| 838 | 838 | |
| 839 | - if( $current_attribute_key > $current_key ) { |
|
| 839 | + if ($current_attribute_key > $current_key) { |
|
| 840 | 840 | // /** Define limit **/ |
| 841 | 841 | // if( in_array('wps-attribute-end-line-' . ($end_line_indicator + 1 ) , $form_model[$group_id]) ) { |
| 842 | 842 | // $next_key = array_search( 'wps-attribute-end-line-'.( $end_line_indicator + 1 ), $form_model[$group_id] ); |
@@ -849,121 +849,121 @@ discard block |
||
| 849 | 849 | // $fields_limit_per_line = $end_tab - $current_key - 1; |
| 850 | 850 | // $fields_limit_per_line = ( $fields_limit_per_line > 6 ) ? 6 : $fields_limit_per_line; |
| 851 | 851 | // } |
| 852 | - if ( !empty($fields_limit_per_line) && $fields_limit_per_line != -1 ) { |
|
| 853 | - if ( $fields_limit_per_line == 1 ) { |
|
| 852 | + if (!empty($fields_limit_per_line) && $fields_limit_per_line != -1) { |
|
| 853 | + if ($fields_limit_per_line == 1) { |
|
| 854 | 854 | $output_form_fields .= '<div class="wps-row">'; |
| 855 | 855 | } |
| 856 | 856 | else { |
| 857 | - $output_form_fields .= '<div class="wps-row wps-gridwrapper' .$fields_limit_per_line. '-padded">'; |
|
| 857 | + $output_form_fields .= '<div class="wps-row wps-gridwrapper' . $fields_limit_per_line . '-padded">'; |
|
| 858 | 858 | } |
| 859 | 859 | } |
| 860 | 860 | } |
| 861 | 861 | } |
| 862 | 862 | |
| 863 | - if ( empty($options['field_to_hide']) || !is_array($options['field_to_hide']) || !in_array( $key, $options['field_to_hide'] ) ) { |
|
| 863 | + if (empty($options['field_to_hide']) || !is_array($options['field_to_hide']) || !in_array($key, $options['field_to_hide'])) { |
|
| 864 | 864 | $attributeInputDomain = 'attribute[' . $type . '][' . $field['data_type'] . ']'; |
| 865 | 865 | // Test if there is POST var or if user have already fill his address infos and fill the fields with these infos |
| 866 | - $referer = !empty($_POST['referer']) ? sanitize_text_field( $_POST['referer'] ) : ''; |
|
| 867 | - if( !empty($referer) ) { |
|
| 868 | - $value = !empty( $_POST[$form['id']."_".$field['name']] ) ? sanitize_text_field( $_POST[$form['id']."_".$field['name']] ) : ''; |
|
| 866 | + $referer = !empty($_POST['referer']) ? sanitize_text_field($_POST['referer']) : ''; |
|
| 867 | + if (!empty($referer)) { |
|
| 868 | + $value = !empty($_POST[$form['id'] . "_" . $field['name']]) ? sanitize_text_field($_POST[$form['id'] . "_" . $field['name']]) : ''; |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | |
| 872 | 872 | |
| 873 | 873 | // Fill Automaticly some fields when it's an address creation |
| 874 | - switch ( $field['name']) { |
|
| 874 | + switch ($field['name']) { |
|
| 875 | 875 | case 'address_title' : |
| 876 | - if( empty($field['value']) ) { |
|
| 876 | + if (empty($field['value'])) { |
|
| 877 | 877 | /** Count Billing and shipping address **/ |
| 878 | 878 | $billing_address_count = $shipping_address_count = 1; |
| 879 | - if ( get_current_user_id() != 0 ) { |
|
| 880 | - $addresses = get_posts( array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_parent' => get_current_user_id(), 'post_status' => 'draft') ); |
|
| 881 | - if ( !empty($addresses) ) { |
|
| 882 | - foreach( $addresses as $address ) { |
|
| 883 | - $address_type = get_post_meta( $address->ID, '_wpshop_address_attribute_set_id', true); |
|
| 884 | - if ( !empty($address_type) ){ |
|
| 885 | - if ( !empty( $shipping_address_choice['choice'] ) && $address_type == $shipping_address_choice['choice'] ) { |
|
| 879 | + if (get_current_user_id() != 0) { |
|
| 880 | + $addresses = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_parent' => get_current_user_id(), 'post_status' => 'draft')); |
|
| 881 | + if (!empty($addresses)) { |
|
| 882 | + foreach ($addresses as $address) { |
|
| 883 | + $address_type = get_post_meta($address->ID, '_wpshop_address_attribute_set_id', true); |
|
| 884 | + if (!empty($address_type)) { |
|
| 885 | + if (!empty($shipping_address_choice['choice']) && $address_type == $shipping_address_choice['choice']) { |
|
| 886 | 886 | $shipping_address_count++; |
| 887 | 887 | } |
| 888 | - else{ |
|
| 888 | + else { |
|
| 889 | 889 | $billing_address_count++; |
| 890 | 890 | } |
| 891 | 891 | } |
| 892 | 892 | } |
| 893 | 893 | } |
| 894 | 894 | } |
| 895 | - $field['value'] = ( $type == $choosen_address['choice'] ) ? __('Billing address', 'wpshop').( ($billing_address_count > 1) ? ' '.$billing_address_count : '' ) : __('Shipping address', 'wpshop').( ($shipping_address_count > 1) ? ' '.$shipping_address_count : ''); |
|
| 895 | + $field['value'] = ($type == $choosen_address['choice']) ? __('Billing address', 'wpshop') . (($billing_address_count > 1) ? ' ' . $billing_address_count : '') : __('Shipping address', 'wpshop') . (($shipping_address_count > 1) ? ' ' . $shipping_address_count : ''); |
|
| 896 | 896 | |
| 897 | 897 | } |
| 898 | 898 | break; |
| 899 | 899 | case 'address_last_name' : |
| 900 | - if( empty($field['value']) ) { |
|
| 901 | - $usermeta_last_name = get_user_meta( $user_id, 'last_name', true); |
|
| 902 | - $field['value'] = ( !empty($usermeta_last_name) ) ? $usermeta_last_name : ''; |
|
| 900 | + if (empty($field['value'])) { |
|
| 901 | + $usermeta_last_name = get_user_meta($user_id, 'last_name', true); |
|
| 902 | + $field['value'] = (!empty($usermeta_last_name)) ? $usermeta_last_name : ''; |
|
| 903 | 903 | } |
| 904 | 904 | break; |
| 905 | 905 | case 'address_first_name' : |
| 906 | - if( empty($field['value']) ) { |
|
| 907 | - $usermeta_first_name = get_user_meta( $user_id, 'first_name', true); |
|
| 908 | - $field['value'] = ( !empty($usermeta_first_name) ) ? $usermeta_first_name : ''; |
|
| 906 | + if (empty($field['value'])) { |
|
| 907 | + $usermeta_first_name = get_user_meta($user_id, 'first_name', true); |
|
| 908 | + $field['value'] = (!empty($usermeta_first_name)) ? $usermeta_first_name : ''; |
|
| 909 | 909 | } |
| 910 | 910 | break; |
| 911 | 911 | case 'address_user_email' : |
| 912 | - if( empty($field['value']) ) { |
|
| 913 | - $user_infos = get_userdata( $user_id ); |
|
| 914 | - $field['value'] = ( !empty($user_infos) && !empty($user_infos->user_email) ) ? $user_infos->user_email : ''; |
|
| 912 | + if (empty($field['value'])) { |
|
| 913 | + $user_infos = get_userdata($user_id); |
|
| 914 | + $field['value'] = (!empty($user_infos) && !empty($user_infos->user_email)) ? $user_infos->user_email : ''; |
|
| 915 | 915 | } |
| 916 | 916 | break; |
| 917 | 917 | default : |
| 918 | - $field['value'] = ( !empty($field['value']) ) ? $field['value'] : ''; |
|
| 918 | + $field['value'] = (!empty($field['value'])) ? $field['value'] : ''; |
|
| 919 | 919 | break; |
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | |
| 923 | 923 | |
| 924 | 924 | /** Fill fields if $_POST exist **/ |
| 925 | - if ( !empty( $attribute[$type][$field['data_type']][$field['name']] ) ) { |
|
| 926 | - $field['value'] = sanitize_text_field( $_POST['attribute'][$type][$field['data_type']][$field['name']] ); |
|
| 925 | + if (!empty($attribute[$type][$field['data_type']][$field['name']])) { |
|
| 926 | + $field['value'] = sanitize_text_field($_POST['attribute'][$type][$field['data_type']][$field['name']]); |
|
| 927 | 927 | } |
| 928 | 928 | |
| 929 | 929 | |
| 930 | - if( $field['name'] == 'address_title' && !empty($first) && $type == __('Billing address', 'wpshop') ) { |
|
| 930 | + if ($field['name'] == 'address_title' && !empty($first) && $type == __('Billing address', 'wpshop')) { |
|
| 931 | 931 | $value = __('Billing address', 'wpshop'); |
| 932 | 932 | } |
| 933 | - elseif( $field['name'] == 'address_title' && !empty($first) && $type == __('Shipping address', 'wpshop') ) { |
|
| 933 | + elseif ($field['name'] == 'address_title' && !empty($first) && $type == __('Shipping address', 'wpshop')) { |
|
| 934 | 934 | $value = __('Shipping address', 'wpshop'); |
| 935 | 935 | } |
| 936 | 936 | |
| 937 | - if ( !empty($special_values[$field['name']]) ) { |
|
| 937 | + if (!empty($special_values[$field['name']])) { |
|
| 938 | 938 | $field['value'] = $special_values[$field['name']]; |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | $template = 'wpshop_account_form_input'; |
| 942 | - if ( $field['type'] == 'hidden' ) { |
|
| 942 | + if ($field['type'] == 'hidden') { |
|
| 943 | 943 | $template = 'wpshop_account_form_hidden_input'; |
| 944 | 944 | } |
| 945 | 945 | |
| 946 | - if ( $field['frontend_verification'] == 'country' ) { |
|
| 946 | + if ($field['frontend_verification'] == 'country') { |
|
| 947 | 947 | $field['type'] = 'select'; |
| 948 | 948 | /** display a country list **/ |
| 949 | 949 | $countries_list = unserialize(WPSHOP_COUNTRY_LIST); |
| 950 | 950 | $possible_values = array_merge(array('' => __('Choose a country')), $countries_list); |
| 951 | 951 | |
| 952 | - $limit_countries_list = get_option( 'wpshop_limit_country_list' ); |
|
| 953 | - $default_country_choice = get_option( 'wpshop_country_default_choice' ); |
|
| 954 | - if ( !empty($limit_countries_list) ) { |
|
| 952 | + $limit_countries_list = get_option('wpshop_limit_country_list'); |
|
| 953 | + $default_country_choice = get_option('wpshop_country_default_choice'); |
|
| 954 | + if (!empty($limit_countries_list)) { |
|
| 955 | 955 | $possible_values = array(); |
| 956 | - if ( count($limit_countries_list) > 1 ) { |
|
| 956 | + if (count($limit_countries_list) > 1) { |
|
| 957 | 957 | $possible_values[''] = __('Choose a country'); |
| 958 | 958 | } |
| 959 | - foreach( $limit_countries_list as $country_code) { |
|
| 960 | - if ( !empty($countries_list) && !empty($countries_list[$country_code]) ) { |
|
| 959 | + foreach ($limit_countries_list as $country_code) { |
|
| 960 | + if (!empty($countries_list) && !empty($countries_list[$country_code])) { |
|
| 961 | 961 | $possible_values[$country_code] = $countries_list[$country_code]; |
| 962 | 962 | } |
| 963 | 963 | } |
| 964 | 964 | } |
| 965 | 965 | |
| 966 | - $field['value'] = ( !empty($default_country_choice) && array_key_exists($default_country_choice, $possible_values ) ) ? $default_country_choice : ''; |
|
| 966 | + $field['value'] = (!empty($default_country_choice) && array_key_exists($default_country_choice, $possible_values)) ? $default_country_choice : ''; |
|
| 967 | 967 | $field['possible_value'] = $possible_values; |
| 968 | 968 | $field['valueToPut'] = 'index'; |
| 969 | 969 | |
@@ -975,7 +975,7 @@ discard block |
||
| 975 | 975 | $input_tpl_component = array(); |
| 976 | 976 | |
| 977 | 977 | //$input_tpl_component['CUSTOMER_FORM_INPUT_MAIN_CONTAINER_CLASS'] = ' wsphop_customer_account_form_container wsphop_customer_account_form_container_' . $field['name'] . $element_simple_class; |
| 978 | - $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = ( $field['type'] != 'hidden' ) ? stripslashes( __( $field['label'], 'wpshop' ) ) . ( ( $field['required'] == 'yes' ) ? ' <em>*</em>' : '') : ''; |
|
| 978 | + $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = ($field['type'] != 'hidden') ? stripslashes(__($field['label'], 'wpshop')) . (($field['required'] == 'yes') ? ' <em>*</em>' : '') : ''; |
|
| 979 | 979 | $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL_OPTIONS'] = ' for="' . $field['id'] . '"'; |
| 980 | 980 | $input_tpl_component['CUSTOMER_FORM_INPUT_FIELD'] = wpshop_form::check_input_type($field, $attributeInputDomain); |
| 981 | 981 | //$output_form_fields .= wpshop_display::display_template_element($template, $input_tpl_component); |
@@ -986,15 +986,15 @@ discard block |
||
| 986 | 986 | |
| 987 | 987 | unset($input_tpl_component); |
| 988 | 988 | |
| 989 | - if ( $field['_need_verification'] == 'yes' ) { |
|
| 989 | + if ($field['_need_verification'] == 'yes') { |
|
| 990 | 990 | $field['name'] = $field['name'] . '2'; |
| 991 | 991 | $field['id'] = $field['id'] . '2'; |
| 992 | 992 | $element_simple_class = str_replace('"', '', str_replace('class="', '', str_replace('wpshop_input_datetime', '', $field['option']))); |
| 993 | 993 | $input_tpl_component = array(); |
| 994 | - $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = __( $field['label'], 'wpshop' ) . ( ( ($field['required'] == 'yes' && !is_admin()) || ($field['name'] == 'address_user_email' && is_admin()) ) ? ' <span class="required">*</span>' : ''); |
|
| 994 | + $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = __($field['label'], 'wpshop') . ((($field['required'] == 'yes' && !is_admin()) || ($field['name'] == 'address_user_email' && is_admin())) ? ' <span class="required">*</span>' : ''); |
|
| 995 | 995 | $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL_OPTIONS'] = ' for="' . $field['id'] . '"'; |
| 996 | 996 | $input_tpl_component['CUSTOMER_FORM_INPUT_MAIN_CONTAINER_CLASS'] = ' wsphop_customer_account_form_container wsphop_customer_account_form_container_' . $field['name'] . $element_simple_class; |
| 997 | - $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = sprintf( __('Confirm %s', 'wpshop'), strtolower( __( $field['label'], 'wpshop' ) ) ). ( ($field['required'] == 'yes') && !is_admin() ? ' <span class="required">*</span>' : ''); |
|
| 997 | + $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = sprintf(__('Confirm %s', 'wpshop'), strtolower(__($field['label'], 'wpshop'))) . (($field['required'] == 'yes') && !is_admin() ? ' <span class="required">*</span>' : ''); |
|
| 998 | 998 | $input_tpl_component['CUSTOMER_FORM_INPUT_FIELD'] = wpshop_form::check_input_type($field, $attributeInputDomain) . $field['options']; |
| 999 | 999 | //$output_form_fields .= wpshop_display::display_template_element($template, $input_tpl_component); |
| 1000 | 1000 | $output_form_fields .= wpshop_display::display_template_element('wps_address_field', $input_tpl_component, array(), 'wpshop'); |
@@ -1003,9 +1003,9 @@ discard block |
||
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | /** Grid closing **/ |
| 1006 | - if( $fields_limit_per_line != -1 && !empty($fields_limit_per_line) ) { |
|
| 1006 | + if ($fields_limit_per_line != -1 && !empty($fields_limit_per_line)) { |
|
| 1007 | 1007 | $fields_limit_per_line--; |
| 1008 | - if( $fields_limit_per_line == 0 ) { |
|
| 1008 | + if ($fields_limit_per_line == 0) { |
|
| 1009 | 1009 | $output_form_fields .= '</div>'; |
| 1010 | 1010 | $fields_limit_per_line = -1; |
| 1011 | 1011 | $end_line_indicator++; |
@@ -1014,18 +1014,18 @@ discard block |
||
| 1014 | 1014 | } |
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | - if ( $type == $choosen_address['choice'] ) { |
|
| 1018 | - $output_form_fields .= '<input type="hidden" name="billing_address" value="'.$choosen_address['choice'].'" />'; |
|
| 1017 | + if ($type == $choosen_address['choice']) { |
|
| 1018 | + $output_form_fields .= '<input type="hidden" name="billing_address" value="' . $choosen_address['choice'] . '" />'; |
|
| 1019 | 1019 | } |
| 1020 | 1020 | $shipping_address_options = get_option('wpshop_shipping_address_choice'); |
| 1021 | - if ( $type == $shipping_address_options['choice'] ) { |
|
| 1022 | - $output_form_fields .= '<input type="hidden" name="shipping_address" value="' .$shipping_address_options['choice']. '" />'; |
|
| 1021 | + if ($type == $shipping_address_options['choice']) { |
|
| 1022 | + $output_form_fields .= '<input type="hidden" name="shipping_address" value="' . $shipping_address_options['choice'] . '" />'; |
|
| 1023 | 1023 | } |
| 1024 | - $output_form_fields .= '<input type="hidden" name="type_of_form" value="' .$type. '" /><input type="hidden" name="attribute[' .$type. '][item_id]" value="' .$current_item_edited. '" />'; |
|
| 1024 | + $output_form_fields .= '<input type="hidden" name="type_of_form" value="' . $type . '" /><input type="hidden" name="attribute[' . $type . '][item_id]" value="' . $current_item_edited . '" />'; |
|
| 1025 | 1025 | |
| 1026 | - $output_form_fields .= ( $user_id != get_current_user_id() ) ? '<input type="hidden" name="user[customer_id]" value="' .$user_id. '" />' : ''; |
|
| 1026 | + $output_form_fields .= ($user_id != get_current_user_id()) ? '<input type="hidden" name="user[customer_id]" value="' . $user_id . '" />' : ''; |
|
| 1027 | 1027 | |
| 1028 | - if ( empty($first) ) $output_form_fields = wpshop_display::display_template_element('wpshop_customer_addresses_form', array('CUSTOMER_ADDRESSES_FORM_CONTENT' => $output_form_fields, 'CUSTOMER_ADDRESSES_FORM_BUTTONS' => '')); |
|
| 1028 | + if (empty($first)) $output_form_fields = wpshop_display::display_template_element('wpshop_customer_addresses_form', array('CUSTOMER_ADDRESSES_FORM_CONTENT' => $output_form_fields, 'CUSTOMER_ADDRESSES_FORM_BUTTONS' => '')); |
|
| 1029 | 1029 | |
| 1030 | 1030 | return $output_form_fields; |
| 1031 | 1031 | } |
@@ -1079,22 +1079,22 @@ discard block |
||
| 1079 | 1079 | * @param integer $shipping_address_type_id |
| 1080 | 1080 | * @param integer $billing_address_type_id |
| 1081 | 1081 | */ |
| 1082 | - function shipping_to_billing( $shipping_address_type_id, $billing_address_type_id ) { |
|
| 1082 | + function shipping_to_billing($shipping_address_type_id, $billing_address_type_id) { |
|
| 1083 | 1083 | global $wpdb; |
| 1084 | 1084 | $tmp_array = array(); |
| 1085 | - $tmp_array = !empty( $_REQUEST ) ? (array)$_REQUEST : array(); |
|
| 1085 | + $tmp_array = !empty($_REQUEST) ? (array)$_REQUEST : array(); |
|
| 1086 | 1086 | |
| 1087 | 1087 | $billing_fields = array(); |
| 1088 | - if( !empty($tmp_array) && !empty($tmp_array['attribute']) && !empty($tmp_array['attribute'][$shipping_address_type_id]) ) { |
|
| 1089 | - foreach ($tmp_array['attribute'][$shipping_address_type_id] as $key => $attribute_group ) { |
|
| 1090 | - if ( is_array($attribute_group) ) { |
|
| 1091 | - foreach( $attribute_group as $field_name => $value ) { |
|
| 1092 | - $attribute_def = wpshop_attributes::getElement( sanitize_text_field( $field_name ), "'valid'", 'code' ); |
|
| 1093 | - if( !empty($attribute_def) ) { |
|
| 1094 | - $query = $wpdb->prepare( 'SELECT * FROM '. WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE status = %s AND attribute_id = %d AND attribute_set_id = %s', 'valid', (int)$attribute_def->id, sanitize_text_field( $billing_address_type_id ) ); |
|
| 1095 | - $attribute_exist = $wpdb->get_var( $query ); |
|
| 1096 | - if ( !empty($attribute_exist) ) { |
|
| 1097 | - $tmp_array['attribute'][$billing_address_type_id][$attribute_def->data_type][$field_name] = sanitize_text_field( $value ); |
|
| 1088 | + if (!empty($tmp_array) && !empty($tmp_array['attribute']) && !empty($tmp_array['attribute'][$shipping_address_type_id])) { |
|
| 1089 | + foreach ($tmp_array['attribute'][$shipping_address_type_id] as $key => $attribute_group) { |
|
| 1090 | + if (is_array($attribute_group)) { |
|
| 1091 | + foreach ($attribute_group as $field_name => $value) { |
|
| 1092 | + $attribute_def = wpshop_attributes::getElement(sanitize_text_field($field_name), "'valid'", 'code'); |
|
| 1093 | + if (!empty($attribute_def)) { |
|
| 1094 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE status = %s AND attribute_id = %d AND attribute_set_id = %s', 'valid', (int)$attribute_def->id, sanitize_text_field($billing_address_type_id)); |
|
| 1095 | + $attribute_exist = $wpdb->get_var($query); |
|
| 1096 | + if (!empty($attribute_exist)) { |
|
| 1097 | + $tmp_array['attribute'][$billing_address_type_id][$attribute_def->data_type][$field_name] = sanitize_text_field($value); |
|
| 1098 | 1098 | } |
| 1099 | 1099 | } |
| 1100 | 1100 | } |
@@ -1114,29 +1114,29 @@ discard block |
||
| 1114 | 1114 | * @param integer $order_id |
| 1115 | 1115 | * @return string |
| 1116 | 1116 | */ |
| 1117 | - function display_addresses_interface( $customer_id = '', $admin_display = false, $order_id = '' ) { |
|
| 1117 | + function display_addresses_interface($customer_id = '', $admin_display = false, $order_id = '') { |
|
| 1118 | 1118 | $output = $extra_class = $billing_address_display = $shipping_address_display = $first_address_checking = ''; |
| 1119 | - $is_from_admin = ( !empty($customer_id) ) ? true : false; |
|
| 1120 | - $user_id = ( !empty($customer_id) ) ? $customer_id : get_current_user_id(); |
|
| 1121 | - if ( $user_id != 0 ) { |
|
| 1119 | + $is_from_admin = (!empty($customer_id)) ? true : false; |
|
| 1120 | + $user_id = (!empty($customer_id)) ? $customer_id : get_current_user_id(); |
|
| 1121 | + if ($user_id != 0) { |
|
| 1122 | 1122 | |
| 1123 | - $shipping_option = get_option( 'wpshop_shipping_address_choice' ); |
|
| 1124 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
| 1123 | + $shipping_option = get_option('wpshop_shipping_address_choice'); |
|
| 1124 | + $billing_option = get_option('wpshop_billing_address'); |
|
| 1125 | 1125 | |
| 1126 | 1126 | /** Shipping address **/ |
| 1127 | 1127 | // Check if is only downloadable else display address |
| 1128 | 1128 | $cart_is_downloadable = false; |
| 1129 | - if ( !empty( $_SESSION['cart'] ) && !empty( $_SESSION['cart']['order_items'] ) ) { |
|
| 1130 | - foreach( $_SESSION['cart']['order_items'] as $c ) { |
|
| 1131 | - $product = wpshop_products::get_product_data( $c['item_id'] ); |
|
| 1129 | + if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 1130 | + foreach ($_SESSION['cart']['order_items'] as $c) { |
|
| 1131 | + $product = wpshop_products::get_product_data($c['item_id']); |
|
| 1132 | 1132 | /** Check if it's a variation and check the parent product **/ |
| 1133 | - if ( get_post_type( $c['item_id'] ) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 1134 | - $parent_def = wpshop_products::get_parent_variation( $c['item_id'] ); |
|
| 1135 | - if ( !empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['is_downloadable_']) ) { |
|
| 1133 | + if (get_post_type($c['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1134 | + $parent_def = wpshop_products::get_parent_variation($c['item_id']); |
|
| 1135 | + if (!empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['is_downloadable_'])) { |
|
| 1136 | 1136 | $product['is_downloadable_'] = $parent_def['parent_post_meta']['is_downloadable_']; |
| 1137 | 1137 | } |
| 1138 | 1138 | } |
| 1139 | - if( !empty($product['is_downloadable_']) && ( __( $product['is_downloadable_'], 'wpshop' ) == __('Yes', 'wpshop') || __( $product['is_downloadable_'], 'wpshop') == __('yes', 'wpshop') ) ) { |
|
| 1139 | + if (!empty($product['is_downloadable_']) && (__($product['is_downloadable_'], 'wpshop') == __('Yes', 'wpshop') || __($product['is_downloadable_'], 'wpshop') == __('yes', 'wpshop'))) { |
|
| 1140 | 1140 | $cart_is_downloadable = true; |
| 1141 | 1141 | } else { |
| 1142 | 1142 | $cart_is_downloadable = false; |
@@ -1146,33 +1146,33 @@ discard block |
||
| 1146 | 1146 | } |
| 1147 | 1147 | |
| 1148 | 1148 | $checkout_address_type = array( |
| 1149 | - 'shipping' => __( 'Shipping address', 'wpshop' ), |
|
| 1150 | - 'billing' => __( 'Billing address', 'wpshop' ), |
|
| 1149 | + 'shipping' => __('Shipping address', 'wpshop'), |
|
| 1150 | + 'billing' => __('Billing address', 'wpshop'), |
|
| 1151 | 1151 | ); |
| 1152 | 1152 | $shipping_is_avalaible = true; |
| 1153 | - foreach ( $checkout_address_type as $address_type => $address_title ) { |
|
| 1153 | + foreach ($checkout_address_type as $address_type => $address_title) { |
|
| 1154 | 1154 | $display_address_of_type = true; |
| 1155 | - switch ( $address_type ) { |
|
| 1155 | + switch ($address_type) { |
|
| 1156 | 1156 | case 'shipping': |
| 1157 | - if ( empty( $shipping_option ) || empty( $shipping_option[ 'activate' ] ) || $cart_is_downloadable ) { |
|
| 1157 | + if (empty($shipping_option) || empty($shipping_option['activate']) || $cart_is_downloadable) { |
|
| 1158 | 1158 | $display_address_of_type = false; |
| 1159 | 1159 | $shipping_is_avalaible = false; |
| 1160 | 1160 | } |
| 1161 | 1161 | else { |
| 1162 | - $address_type_id = $shipping_option[ 'choice' ]; |
|
| 1162 | + $address_type_id = $shipping_option['choice']; |
|
| 1163 | 1163 | } |
| 1164 | 1164 | break; |
| 1165 | 1165 | case 'billing': |
| 1166 | - $address_type_id = $billing_option[ 'choice' ]; |
|
| 1166 | + $address_type_id = $billing_option['choice']; |
|
| 1167 | 1167 | break; |
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | - if ( $display_address_of_type ) { |
|
| 1171 | - $box_content = !$admin_display ? self::display_address_interface_content( $address_type_id, $address_title, '', $address_type, $user_id ) : ''; |
|
| 1172 | - $first_address_checking = ( empty( $box_content ) && ( 'shipping' == $address_type ) ) ? true : false; |
|
| 1170 | + if ($display_address_of_type) { |
|
| 1171 | + $box_content = !$admin_display ? self::display_address_interface_content($address_type_id, $address_title, '', $address_type, $user_id) : ''; |
|
| 1172 | + $first_address_checking = (empty($box_content) && ('shipping' == $address_type)) ? true : false; |
|
| 1173 | 1173 | |
| 1174 | 1174 | ob_start(); |
| 1175 | - require( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, ( $admin_display ? 'backend' : 'frontend' ), 'address', 'container' ) ); |
|
| 1175 | + require(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, ($admin_display ? 'backend' : 'frontend'), 'address', 'container')); |
|
| 1176 | 1176 | $output .= ob_get_contents(); |
| 1177 | 1177 | ob_end_clean(); |
| 1178 | 1178 | } |
@@ -1183,20 +1183,20 @@ discard block |
||
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | /** Display address interface content **/ |
| 1186 | - public static function display_address_interface_content( $address_type_id, $address_title, $selected_address = null, $type, $customer_id = '', $admin_display = false, $order_id = '' ) { |
|
| 1187 | - $user_id = ( !empty($customer_id) ) ? $customer_id : get_current_user_id(); |
|
| 1188 | - $is_from_admin = ( !empty($customer_id) ) ? true : false; |
|
| 1189 | - $select_id = ( !empty($type) && $type == 'shipping') ? 'shipping_address_address_list' : 'billing_address_address_list'; |
|
| 1186 | + public static function display_address_interface_content($address_type_id, $address_title, $selected_address = null, $type, $customer_id = '', $admin_display = false, $order_id = '') { |
|
| 1187 | + $user_id = (!empty($customer_id)) ? $customer_id : get_current_user_id(); |
|
| 1188 | + $is_from_admin = (!empty($customer_id)) ? true : false; |
|
| 1189 | + $select_id = (!empty($type) && $type == 'shipping') ? 'shipping_address_address_list' : 'billing_address_address_list'; |
|
| 1190 | 1190 | $output = ''; |
| 1191 | - if( !empty($address_type_id) ) { |
|
| 1192 | - $addresses = self::get_addresses_list( $user_id ); |
|
| 1193 | - $list_addresses = ( !empty($addresses[ $address_type_id ]) ) ? $addresses[ $address_type_id ] : array(); |
|
| 1194 | - if ( empty($list_addresses) ) { |
|
| 1191 | + if (!empty($address_type_id)) { |
|
| 1192 | + $addresses = self::get_addresses_list($user_id); |
|
| 1193 | + $list_addresses = (!empty($addresses[$address_type_id])) ? $addresses[$address_type_id] : array(); |
|
| 1194 | + if (empty($list_addresses)) { |
|
| 1195 | 1195 | $form = self::display_form_fields($address_type_id); |
| 1196 | 1196 | } |
| 1197 | 1197 | $output = ''; |
| 1198 | 1198 | ob_start(); |
| 1199 | - require( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, ( ($admin_display) ? 'backend' : 'frontend' ), "address", "content") ); |
|
| 1199 | + require(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, (($admin_display) ? 'backend' : 'frontend'), "address", "content")); |
|
| 1200 | 1200 | $output .= ob_get_contents(); |
| 1201 | 1201 | ob_end_clean(); |
| 1202 | 1202 | } |
@@ -1210,14 +1210,14 @@ discard block |
||
| 1210 | 1210 | * @since 1.0 - WPShop 1.3.7.0 |
| 1211 | 1211 | */ |
| 1212 | 1212 | function display_addresses_list() { |
| 1213 | - $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 1213 | + $_wpnonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 1214 | 1214 | |
| 1215 | - if ( !wp_verify_nonce( $_wpnonce, 'display_addresses_list' ) ) |
|
| 1215 | + if (!wp_verify_nonce($_wpnonce, 'display_addresses_list')) |
|
| 1216 | 1216 | die(); |
| 1217 | 1217 | |
| 1218 | - $post_id = (int) $_POST['post_id']; |
|
| 1219 | - $addresses = $this->get_addresses_list( $post_id ); |
|
| 1220 | - require_once( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "addresses" ) ); |
|
| 1218 | + $post_id = (int)$_POST['post_id']; |
|
| 1219 | + $addresses = $this->get_addresses_list($post_id); |
|
| 1220 | + require_once(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "addresses")); |
|
| 1221 | 1221 | die(); |
| 1222 | 1222 | } |
| 1223 | 1223 | |
@@ -1227,21 +1227,21 @@ discard block |
||
| 1227 | 1227 | * @since 1.0 - WPShop 1.3.7.0 |
| 1228 | 1228 | */ |
| 1229 | 1229 | function display_address() { |
| 1230 | - $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 1230 | + $_wpnonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 1231 | 1231 | |
| 1232 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_address_display_an_address' ) ) |
|
| 1232 | + if (!wp_verify_nonce($_wpnonce, 'wps_address_display_an_address')) |
|
| 1233 | 1233 | die(); |
| 1234 | 1234 | |
| 1235 | - $adress_id = (int) $_POST['address_id']; |
|
| 1236 | - $address_post_meta = get_post_meta( $adress_id, '_wpshop_address_metadata', true); |
|
| 1237 | - $address_type_post_meta = get_post_meta( $adress_id, '_wpshop_address_attribute_set_id', true); |
|
| 1238 | - if( !empty($address_post_meta) && !empty($address_type_post_meta) ) { |
|
| 1239 | - $addresses_list[$address_type_post_meta][ $adress_id ] = $address_post_meta; |
|
| 1235 | + $adress_id = (int)$_POST['address_id']; |
|
| 1236 | + $address_post_meta = get_post_meta($adress_id, '_wpshop_address_metadata', true); |
|
| 1237 | + $address_type_post_meta = get_post_meta($adress_id, '_wpshop_address_attribute_set_id', true); |
|
| 1238 | + if (!empty($address_post_meta) && !empty($address_type_post_meta)) { |
|
| 1239 | + $addresses_list[$address_type_post_meta][$adress_id] = $address_post_meta; |
|
| 1240 | 1240 | } |
| 1241 | 1241 | $address_open = true; |
| 1242 | - foreach ( $addresses_list as $address_type => $addresses_list_by_type ) : |
|
| 1243 | - foreach ( $addresses_list_by_type as $address_id => $address ) : |
|
| 1244 | - require( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address" ) ); |
|
| 1242 | + foreach ($addresses_list as $address_type => $addresses_list_by_type) : |
|
| 1243 | + foreach ($addresses_list_by_type as $address_id => $address) : |
|
| 1244 | + require(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address")); |
|
| 1245 | 1245 | endforeach; |
| 1246 | 1246 | endforeach; |
| 1247 | 1247 | |
@@ -1256,29 +1256,29 @@ discard block |
||
| 1256 | 1256 | function display_address_adding_form() { |
| 1257 | 1257 | global $wpdb; |
| 1258 | 1258 | |
| 1259 | - $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 1259 | + $_wpnonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 1260 | 1260 | |
| 1261 | - if ( !wp_verify_nonce( $_wpnonce, 'display_address_adding_form' ) ) |
|
| 1261 | + if (!wp_verify_nonce($_wpnonce, 'display_address_adding_form')) |
|
| 1262 | 1262 | die(); |
| 1263 | 1263 | |
| 1264 | 1264 | $address_id = 0; |
| 1265 | - $post_ID = (int)$_POST[ 'post_id' ]; |
|
| 1266 | - $element = get_post( $post_ID ); |
|
| 1267 | - $query = $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s ", $element->post_type); |
|
| 1268 | - $element_cpt = $wpdb->get_var( $query ); |
|
| 1269 | - $attached_addresses = get_post_meta( $element_cpt, '_wpshop_entity_attached_address', true ); |
|
| 1270 | - |
|
| 1271 | - if ( !empty( $attached_addresses ) ) { |
|
| 1272 | - if ( count( $attached_addresses ) == 1 ) { |
|
| 1273 | - $address_type_id = $attached_addresses[ 0 ]; |
|
| 1274 | - require_once( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "form" ) ); |
|
| 1265 | + $post_ID = (int)$_POST['post_id']; |
|
| 1266 | + $element = get_post($post_ID); |
|
| 1267 | + $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_name = %s ", $element->post_type); |
|
| 1268 | + $element_cpt = $wpdb->get_var($query); |
|
| 1269 | + $attached_addresses = get_post_meta($element_cpt, '_wpshop_entity_attached_address', true); |
|
| 1270 | + |
|
| 1271 | + if (!empty($attached_addresses)) { |
|
| 1272 | + if (count($attached_addresses) == 1) { |
|
| 1273 | + $address_type_id = $attached_addresses[0]; |
|
| 1274 | + require_once(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "form")); |
|
| 1275 | 1275 | } |
| 1276 | 1276 | else { |
| 1277 | - require_once( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "addresses", "types" ) ); |
|
| 1277 | + require_once(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "addresses", "types")); |
|
| 1278 | 1278 | } |
| 1279 | 1279 | } |
| 1280 | 1280 | else { |
| 1281 | - printf( __( 'No addresses are attached to this element type %s', 'wpeo_geoloc' ), $element->post_type); |
|
| 1281 | + printf(__('No addresses are attached to this element type %s', 'wpeo_geoloc'), $element->post_type); |
|
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | 1284 | die(); |
@@ -1290,20 +1290,20 @@ discard block |
||
| 1290 | 1290 | * @since 1.0 - WPShop 1.3.7.0 |
| 1291 | 1291 | */ |
| 1292 | 1292 | function load_address_edition_form() { |
| 1293 | - $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 1293 | + $_wpnonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 1294 | 1294 | |
| 1295 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_address_edition_form_load' ) ) |
|
| 1295 | + if (!wp_verify_nonce($_wpnonce, 'wps_address_edition_form_load')) |
|
| 1296 | 1296 | die(); |
| 1297 | 1297 | |
| 1298 | - $address_id = (int)$_POST[ 'element_id' ]; |
|
| 1299 | - $post_ID = (int)$_POST[ 'post_id' ]; |
|
| 1300 | - $address_type_id = get_post_meta( $address_id, '_wpshop_address_attribute_set_id', true); |
|
| 1301 | - $wpeogeo_adress = !empty( $_POST[ 'wpeogeo-address-type-chosen-for-creation' ] ) ? (int) $_POST[ 'wpeogeo-address-type-chosen-for-creation' ] : 0; |
|
| 1302 | - if ( empty( $address_id ) && empty( $address_type_id ) && !empty( $wpeogeo_adress ) ) { |
|
| 1298 | + $address_id = (int)$_POST['element_id']; |
|
| 1299 | + $post_ID = (int)$_POST['post_id']; |
|
| 1300 | + $address_type_id = get_post_meta($address_id, '_wpshop_address_attribute_set_id', true); |
|
| 1301 | + $wpeogeo_adress = !empty($_POST['wpeogeo-address-type-chosen-for-creation']) ? (int)$_POST['wpeogeo-address-type-chosen-for-creation'] : 0; |
|
| 1302 | + if (empty($address_id) && empty($address_type_id) && !empty($wpeogeo_adress)) { |
|
| 1303 | 1303 | $address_type_id = $wpeogeo_adress; |
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | - require( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "form" ) ); |
|
| 1306 | + require(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "form")); |
|
| 1307 | 1307 | die(); |
| 1308 | 1308 | } |
| 1309 | 1309 | |
@@ -1311,22 +1311,22 @@ discard block |
||
| 1311 | 1311 | * AJAX - Delete an address |
| 1312 | 1312 | */ |
| 1313 | 1313 | function wps_delete_an_address() { |
| 1314 | - $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 1314 | + $_wpnonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 1315 | 1315 | |
| 1316 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_delete_an_address' ) ) |
|
| 1316 | + if (!wp_verify_nonce($_wpnonce, 'wps_delete_an_address')) |
|
| 1317 | 1317 | die(); |
| 1318 | 1318 | |
| 1319 | 1319 | $status = false; $response = ''; |
| 1320 | - $address_id = ( !empty( $_POST['address_id']) ) ? (int) $_POST['address_id'] : null; |
|
| 1321 | - if( !empty($address_id) ) { |
|
| 1320 | + $address_id = (!empty($_POST['address_id'])) ? (int)$_POST['address_id'] : null; |
|
| 1321 | + if (!empty($address_id)) { |
|
| 1322 | 1322 | /** Check if user is author of address **/ |
| 1323 | - $address = get_post( $address_id ); |
|
| 1324 | - if( !empty($address) && !empty($address->post_type) && $address->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS && !empty($address->post_author) && $address->post_author == get_current_user_id() ) { |
|
| 1325 | - wp_delete_post( $address_id, true ); |
|
| 1323 | + $address = get_post($address_id); |
|
| 1324 | + if (!empty($address) && !empty($address->post_type) && $address->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS && !empty($address->post_author) && $address->post_author == get_current_user_id()) { |
|
| 1325 | + wp_delete_post($address_id, true); |
|
| 1326 | 1326 | $status = true; |
| 1327 | 1327 | } |
| 1328 | 1328 | } |
| 1329 | - echo json_encode( array('status' => $status, 'response' => $response) ); |
|
| 1329 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 1330 | 1330 | die(); |
| 1331 | 1331 | } |
| 1332 | 1332 | |
@@ -1334,30 +1334,30 @@ discard block |
||
| 1334 | 1334 | * AJAX - Relad Address Interface in new checkout tunnel |
| 1335 | 1335 | */ |
| 1336 | 1336 | function wps_reload_address_interface() { |
| 1337 | - $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 1337 | + $_wpnonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 1338 | 1338 | |
| 1339 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_address_interface' ) ) |
|
| 1339 | + if (!wp_verify_nonce($_wpnonce, 'wps_reload_address_interface')) |
|
| 1340 | 1340 | die(); |
| 1341 | 1341 | |
| 1342 | 1342 | global $wpdb; |
| 1343 | 1343 | $status = false; $response = ''; |
| 1344 | - $address_type = !empty($_POST['address_type']) ? (int) $_POST['address_type'] : null; |
|
| 1345 | - $selected_address = !empty($_POST['address_id']) ? (int) $_POST['address_id'] : null; |
|
| 1344 | + $address_type = !empty($_POST['address_type']) ? (int)$_POST['address_type'] : null; |
|
| 1345 | + $selected_address = !empty($_POST['address_id']) ? (int)$_POST['address_id'] : null; |
|
| 1346 | 1346 | |
| 1347 | - if ( !empty( $address_type ) ) { |
|
| 1348 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
| 1349 | - if ( !empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $address_type ) { |
|
| 1347 | + if (!empty($address_type)) { |
|
| 1348 | + $billing_option = get_option('wpshop_billing_address'); |
|
| 1349 | + if (!empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $address_type) { |
|
| 1350 | 1350 | $type = 'billing'; |
| 1351 | 1351 | } |
| 1352 | 1352 | else { |
| 1353 | 1353 | $type = 'shipping'; |
| 1354 | 1354 | } |
| 1355 | - $query = $wpdb->prepare( 'SELECT name FROM '.WPSHOP_DBT_ATTRIBUTE_SET .' WHERE id = %d ', $address_type ); |
|
| 1356 | - $address_title = __( $wpdb->get_var( $query ), 'wpshop' ); |
|
| 1357 | - $response = self::display_address_interface_content( $address_type, $address_title, $selected_address, $type ); |
|
| 1355 | + $query = $wpdb->prepare('SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE id = %d ', $address_type); |
|
| 1356 | + $address_title = __($wpdb->get_var($query), 'wpshop'); |
|
| 1357 | + $response = self::display_address_interface_content($address_type, $address_title, $selected_address, $type); |
|
| 1358 | 1358 | $status = true; |
| 1359 | 1359 | } |
| 1360 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
| 1360 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 1361 | 1361 | die(); |
| 1362 | 1362 | } |
| 1363 | 1363 | |
@@ -1366,20 +1366,20 @@ discard block |
||
| 1366 | 1366 | */ |
| 1367 | 1367 | function wps_load_address_form() { |
| 1368 | 1368 | $response = ''; |
| 1369 | - $address_id = ( !empty( $_POST['address_id'] ) ) ? (int) $_POST['address_id'] : ''; |
|
| 1370 | - $address_type_id = ( !empty( $_POST['address_type_id']) ) ? sanitize_text_field( $_POST['address_type_id'] ) : ''; |
|
| 1369 | + $address_id = (!empty($_POST['address_id'])) ? (int)$_POST['address_id'] : ''; |
|
| 1370 | + $address_type_id = (!empty($_POST['address_type_id'])) ? sanitize_text_field($_POST['address_type_id']) : ''; |
|
| 1371 | 1371 | |
| 1372 | - $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 1372 | + $_wpnonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 1373 | 1373 | |
| 1374 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_load_address_form_' . $address_type_id ) ) |
|
| 1374 | + if (!wp_verify_nonce($_wpnonce, 'wps_load_address_form_' . $address_type_id)) |
|
| 1375 | 1375 | wp_die(); |
| 1376 | 1376 | |
| 1377 | 1377 | |
| 1378 | - $form_data = self::loading_address_form( $address_type_id, $address_id, get_current_user_id() ); |
|
| 1378 | + $form_data = self::loading_address_form($address_type_id, $address_id, get_current_user_id()); |
|
| 1379 | 1379 | $response = $form_data[0]; |
| 1380 | 1380 | $title = $form_data[1]; |
| 1381 | 1381 | |
| 1382 | - wp_die( json_encode( array($response, $title) ) ); |
|
| 1382 | + wp_die(json_encode(array($response, $title))); |
|
| 1383 | 1383 | } |
| 1384 | 1384 | |
| 1385 | 1385 | /** |
@@ -1388,28 +1388,28 @@ discard block |
||
| 1388 | 1388 | function wps_save_address() { |
| 1389 | 1389 | global $wpshop, $wpdb; |
| 1390 | 1390 | |
| 1391 | - $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 1391 | + $_wpnonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 1392 | 1392 | |
| 1393 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_address' ) ) |
|
| 1393 | + if (!wp_verify_nonce($_wpnonce, 'wps_save_address')) |
|
| 1394 | 1394 | wp_die(); |
| 1395 | 1395 | |
| 1396 | - $adress_save_the_first = !empty( $_POST['wps-address-save-the-first'] ) ? sanitize_text_field( $_POST['wps-address-save-the-first'] ) : ''; |
|
| 1397 | - $attribute = !empty( $_POST['attribute'] ) ? (array)$_POST['attribute'] : ''; |
|
| 1398 | - if ( !empty( $attribute[$attribute_set_id] ) ) { |
|
| 1399 | - $attribute[$attribute_set_id]['varchar']['address_title'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['address_title'] ); |
|
| 1400 | - $attribute[$attribute_set_id]['varchar']['address_last_name'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['address_last_name'] ); |
|
| 1401 | - $attribute[$attribute_set_id]['varchar']['address_first_name'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['address_first_name'] ); |
|
| 1402 | - $attribute[$attribute_set_id]['varchar']['company'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['company'] ); |
|
| 1403 | - $attribute[$attribute_set_id]['varchar']['company'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['company'] ); |
|
| 1404 | - $attribute[$attribute_set_id]['varchar']['postcode'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['postcode'] ); |
|
| 1405 | - $attribute[$attribute_set_id]['varchar']['city'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['city'] ); |
|
| 1406 | - $attribute[$attribute_set_id]['varchar']['country'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['country'] ); |
|
| 1407 | - $attribute[$attribute_set_id]['varchar']['state'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['state'] ); |
|
| 1408 | - $attribute[$attribute_set_id]['varchar']['longitude'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['longitude'] ); |
|
| 1409 | - $attribute[$attribute_set_id]['varchar']['latitude'] = sanitize_text_field( $attribute[$attribute_set_id]['varchar']['latitude'] ); |
|
| 1396 | + $adress_save_the_first = !empty($_POST['wps-address-save-the-first']) ? sanitize_text_field($_POST['wps-address-save-the-first']) : ''; |
|
| 1397 | + $attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : ''; |
|
| 1398 | + if (!empty($attribute[$attribute_set_id])) { |
|
| 1399 | + $attribute[$attribute_set_id]['varchar']['address_title'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['address_title']); |
|
| 1400 | + $attribute[$attribute_set_id]['varchar']['address_last_name'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['address_last_name']); |
|
| 1401 | + $attribute[$attribute_set_id]['varchar']['address_first_name'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['address_first_name']); |
|
| 1402 | + $attribute[$attribute_set_id]['varchar']['company'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['company']); |
|
| 1403 | + $attribute[$attribute_set_id]['varchar']['company'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['company']); |
|
| 1404 | + $attribute[$attribute_set_id]['varchar']['postcode'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['postcode']); |
|
| 1405 | + $attribute[$attribute_set_id]['varchar']['city'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['city']); |
|
| 1406 | + $attribute[$attribute_set_id]['varchar']['country'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['country']); |
|
| 1407 | + $attribute[$attribute_set_id]['varchar']['state'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['state']); |
|
| 1408 | + $attribute[$attribute_set_id]['varchar']['longitude'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['longitude']); |
|
| 1409 | + $attribute[$attribute_set_id]['varchar']['latitude'] = sanitize_text_field($attribute[$attribute_set_id]['varchar']['latitude']); |
|
| 1410 | 1410 | $attribute[$attribute_set_id]['integer']['civility'] = (int)$attribute[$attribute_set_id]['integer']['civility']; |
| 1411 | 1411 | |
| 1412 | - if ( !empty( $attribute[$attribute_set_id]['item_id'] ) ) { |
|
| 1412 | + if (!empty($attribute[$attribute_set_id]['item_id'])) { |
|
| 1413 | 1413 | $attribute[$attribute_set_id]['item_id'] = (int)$attribute[$attribute_set_id]['item_id']; |
| 1414 | 1414 | } |
| 1415 | 1415 | } |
@@ -1417,46 +1417,46 @@ discard block |
||
| 1417 | 1417 | $shipping_address = (int)$_POST['shipping_address']; |
| 1418 | 1418 | $type_of_form = (int)$_POST['type_of_form']; |
| 1419 | 1419 | $current_item_edited = !empty($_POST['attribute'][$attribute_set_id]['item_id']) ? (int)wpshop_tools::varSanitizer($_POST['attribute'][$attribute_set_id]['item_id']) : null; |
| 1420 | - $current_attribute_set_id = !empty( $_POST['current_attribute_set_id'] ) ? (int)$_POST['current_attribute_set_id'] : ''; |
|
| 1421 | - $shipping_to_billing = !empty( $_POST['wps-shipping-to-billing'] ) ? sanitize_text_field( $_POST['wps-shipping-to-billing'] ) : ''; |
|
| 1422 | - $shipping_to_billing_id = !empty( $_POST['wps-shipping-to-billing-id'] ) ? (int)$_POST['wps-shipping-to-billing-id'] : ''; |
|
| 1420 | + $current_attribute_set_id = !empty($_POST['current_attribute_set_id']) ? (int)$_POST['current_attribute_set_id'] : ''; |
|
| 1421 | + $shipping_to_billing = !empty($_POST['wps-shipping-to-billing']) ? sanitize_text_field($_POST['wps-shipping-to-billing']) : ''; |
|
| 1422 | + $shipping_to_billing_id = !empty($_POST['wps-shipping-to-billing-id']) ? (int)$_POST['wps-shipping-to-billing-id'] : ''; |
|
| 1423 | 1423 | |
| 1424 | 1424 | $status = false; |
| 1425 | 1425 | $result = $address_type = $same_address_type = ''; |
| 1426 | 1426 | |
| 1427 | - foreach ( $attribute as $id_group => $attribute_group ) { |
|
| 1427 | + foreach ($attribute as $id_group => $attribute_group) { |
|
| 1428 | 1428 | $address_type = $id_group; |
| 1429 | - $group = wps_address::get_addresss_form_fields_by_type ($id_group); |
|
| 1430 | - foreach ( $group as $attribute_sets ) { |
|
| 1431 | - foreach ( $attribute_sets as $attribute_set_field ) { |
|
| 1429 | + $group = wps_address::get_addresss_form_fields_by_type($id_group); |
|
| 1430 | + foreach ($group as $attribute_sets) { |
|
| 1431 | + foreach ($attribute_sets as $attribute_set_field) { |
|
| 1432 | 1432 | $validate = $wpshop->validateForm($attribute_set_field['content'], $attribute[$id_group], 'address_edition'); |
| 1433 | 1433 | } |
| 1434 | - if ( $validate ) { |
|
| 1435 | - $shipping_save = self::save_address_infos( $id_group ); |
|
| 1434 | + if ($validate) { |
|
| 1435 | + $shipping_save = self::save_address_infos($id_group); |
|
| 1436 | 1436 | |
| 1437 | - $wps_shipping_to_billing = !empty( $_POST['wps-shipping-to-billing'] ) ? sanitize_text_field( $_POST['wps-shipping-to-billing'] ) : ''; |
|
| 1438 | - if( !empty( $wps_shipping_to_billing ) ) { |
|
| 1437 | + $wps_shipping_to_billing = !empty($_POST['wps-shipping-to-billing']) ? sanitize_text_field($_POST['wps-shipping-to-billing']) : ''; |
|
| 1438 | + if (!empty($wps_shipping_to_billing)) { |
|
| 1439 | 1439 | // @TODO |
| 1440 | 1440 | // $_POST['wps-shipping-to-billing-id'] = $shipping_save['current_id']; |
| 1441 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
| 1442 | - $shipping_option = get_option( 'wpshop_shipping_address_choice' ); |
|
| 1443 | - self::shipping_to_billing( $shipping_option['choice'], $billing_option['choice'] ); |
|
| 1444 | - self::save_address_infos( $billing_option['choice'] ); |
|
| 1441 | + $billing_option = get_option('wpshop_billing_address'); |
|
| 1442 | + $shipping_option = get_option('wpshop_shipping_address_choice'); |
|
| 1443 | + self::shipping_to_billing($shipping_option['choice'], $billing_option['choice']); |
|
| 1444 | + self::save_address_infos($billing_option['choice']); |
|
| 1445 | 1445 | $same_address_type = $billing_option['choice']; |
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | 1448 | $status = true; |
| 1449 | - if ( !empty( $tmp_array ) && !empty( $adress_save_the_first ) ) { |
|
| 1450 | - $query = $wpdb->prepare( 'SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE id = %d ', $address_type ); |
|
| 1451 | - $address_title = __( $wpdb->get_var( $query ), 'wpshop' ); |
|
| 1452 | - $result = self::display_address_interface_content( $address_type, $address_title, $shipping_save[ 'current_id' ], $adress_save_the_first ); |
|
| 1449 | + if (!empty($tmp_array) && !empty($adress_save_the_first)) { |
|
| 1450 | + $query = $wpdb->prepare('SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE id = %d ', $address_type); |
|
| 1451 | + $address_title = __($wpdb->get_var($query), 'wpshop'); |
|
| 1452 | + $result = self::display_address_interface_content($address_type, $address_title, $shipping_save['current_id'], $adress_save_the_first); |
|
| 1453 | 1453 | } |
| 1454 | 1454 | } |
| 1455 | 1455 | else { |
| 1456 | - if ( !empty($wpshop->errors) ){ |
|
| 1457 | - $result = '<div class="wps-alert wps-alert-error">' .__('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
| 1458 | - foreach( $wpshop->errors as $error ){ |
|
| 1459 | - $result .= '<li>' .$error. '</li>'; |
|
| 1456 | + if (!empty($wpshop->errors)) { |
|
| 1457 | + $result = '<div class="wps-alert wps-alert-error">' . __('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
| 1458 | + foreach ($wpshop->errors as $error) { |
|
| 1459 | + $result .= '<li>' . $error . '</li>'; |
|
| 1460 | 1460 | } |
| 1461 | 1461 | $result .= '</ul></div>'; |
| 1462 | 1462 | } |
@@ -1464,7 +1464,7 @@ discard block |
||
| 1464 | 1464 | } |
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | - wp_die( json_encode( array( $status, $result, $address_type, $same_address_type ) ) ); |
|
| 1467 | + wp_die(json_encode(array($status, $result, $address_type, $same_address_type))); |
|
| 1468 | 1468 | } |
| 1469 | 1469 | |
| 1470 | 1470 | } |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * File defining class for addresses initialisation |
| 4 | 6 | * |
@@ -360,8 +362,7 @@ discard block |
||
| 360 | 362 | $display_model = $shipping_option['display_model']; |
| 361 | 363 | $has_model = true; |
| 362 | 364 | |
| 363 | - } |
|
| 364 | - else { |
|
| 365 | + } else { |
|
| 365 | 366 | $billing_option = get_option( 'wpshop_billing_address' ); |
| 366 | 367 | if ( !empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $address_type && !empty($billing_option['display_model']) ) { |
| 367 | 368 | $display_model = $billing_option['display_model']; |
@@ -383,11 +384,9 @@ discard block |
||
| 383 | 384 | if ( $attribute_def->frontend_input == 'select' ) { |
| 384 | 385 | $query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d',$address[ $attribute_def->code] ); |
| 385 | 386 | $output .= '<strong>'.__( $attribute_def->frontend_label, 'wpshop').' :</strong> '.__( $wpdb->get_var( $query ), 'wpshop' ).' '; |
| 386 | - } |
|
| 387 | - elseif( $attribute_def->frontend_verification == 'country' ) { |
|
| 387 | + } elseif( $attribute_def->frontend_verification == 'country' ) { |
|
| 388 | 388 | $output .= ( !empty($countries[ $address[ $attribute_def->code] ]) ) ? '<strong>'.__( $attribute_def->frontend_label, 'wpshop').' :</strong> '.__( $countries[ $address[ $attribute_def->code] ], 'wpshop' ).' ' : ''; |
| 389 | - } |
|
| 390 | - else { |
|
| 389 | + } else { |
|
| 391 | 390 | $output .= ( !empty($address[ $attribute_def->code]) ) ? '<strong>'.__( $attribute_def->frontend_label, 'wpshop').' :</strong> '.$address[ $attribute_def->code].' ' : ' '; |
| 392 | 391 | } |
| 393 | 392 | } |
@@ -401,8 +400,7 @@ discard block |
||
| 401 | 400 | } |
| 402 | 401 | } |
| 403 | 402 | } |
| 404 | - } |
|
| 405 | - else { |
|
| 403 | + } else { |
|
| 406 | 404 | if( !empty($address_type) ) { |
| 407 | 405 | $tmp_array = array(); |
| 408 | 406 | $address_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS ); |
@@ -418,13 +416,11 @@ discard block |
||
| 418 | 416 | |
| 419 | 417 | if( $attribute_def->frontend_verification == 'country' ) { |
| 420 | 418 | $tmp_array[ $attribute_def->code]['value'] = ( !empty($countries[ $address[ $attribute_def->code] ]) ) ? stripslashes( __( $countries[ $address[ $attribute_def->code] ], 'wpshop' ) ) : stripslashes( $address[ $attribute_def->code ] ); |
| 421 | - } |
|
| 422 | - elseif( in_array( $attribute_def->frontend_input, array('select', 'checkbox') ) ) { |
|
| 419 | + } elseif( in_array( $attribute_def->frontend_input, array('select', 'checkbox') ) ) { |
|
| 423 | 420 | $query = $wpdb->prepare( 'SELECT label FROM '. WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $address[ $attribute_def->code] ); |
| 424 | 421 | $value = $wpdb->get_var( $query ); |
| 425 | 422 | $tmp_array[ $attribute_def->code]['value'] = ( !empty($value) ) ? stripslashes( __( $value, 'wpshop' ) ) : ''; |
| 426 | - } |
|
| 427 | - else { |
|
| 423 | + } else { |
|
| 428 | 424 | $tmp_array[ $attribute_def->code]['value'] = stripslashes( __( $address[ $attribute_def->code ], 'wpshop' ) ); |
| 429 | 425 | } |
| 430 | 426 | } |
@@ -437,8 +433,7 @@ discard block |
||
| 437 | 433 | foreach( $address as $element_code => $element_value ) { |
| 438 | 434 | if( is_array($element_value) ) { |
| 439 | 435 | $output .= '<span class="wps-'.$element_code.'"><strong>' .stripslashes( $element_value['label'] ). ' :</strong> ' .stripslashes( $element_value['value'] ). '</span>'; |
| 440 | - } |
|
| 441 | - else { |
|
| 436 | + } else { |
|
| 442 | 437 | $output .= '<span class="wps-'.$element_code.'">' .stripslashes( $element_value ). '</span>'; |
| 443 | 438 | } |
| 444 | 439 | } |
@@ -464,12 +459,10 @@ discard block |
||
| 464 | 459 | $post = get_post( $post ); |
| 465 | 460 | if ( !empty($post->post_parent) ) { |
| 466 | 461 | $customer_id = $post->post_parent; |
| 467 | - } |
|
| 468 | - else { |
|
| 462 | + } else { |
|
| 469 | 463 | $customer_id = $post->post_author; |
| 470 | 464 | } |
| 471 | - } |
|
| 472 | - else { |
|
| 465 | + } else { |
|
| 473 | 466 | $customer_id = get_current_user_id(); |
| 474 | 467 | } |
| 475 | 468 | |
@@ -493,8 +486,7 @@ discard block |
||
| 493 | 486 | $tpl_component['ADDRESS_BUTTONS'] = ''; |
| 494 | 487 | if( count($addresses) > 0 ) { |
| 495 | 488 | $tpl_component['ADD_NEW_ADDRESS_LINK'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?')===false ? '?' : '&'). 'action=add_address&type=' .$address_type_id; |
| 496 | - } |
|
| 497 | - else { |
|
| 489 | + } else { |
|
| 498 | 490 | $tpl_component['ADD_NEW_ADDRESS_LINK'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?')===false ? '?' : '&'). 'action=add_address&type=' .$address_type_id .'&first'; |
| 499 | 491 | } |
| 500 | 492 | $tpl_component['ADDRESS_TYPE'] = ( !empty($address_type_title) && ($address_type_title == __('Shipping address', 'wpshop'))) ? 'shipping_address' : 'billing_address'; |
@@ -516,8 +508,7 @@ discard block |
||
| 516 | 508 | if ( !is_admin() ) { |
| 517 | 509 | $_SESSION[$tpl_component['ADDRESS_TYPE']] = $address->ID; |
| 518 | 510 | } |
| 519 | - } |
|
| 520 | - else { |
|
| 511 | + } else { |
|
| 521 | 512 | $address_id = ( !empty($_SESSION[$tpl_component['ADDRESS_TYPE']]) ) ? $_SESSION[$tpl_component['ADDRESS_TYPE']] : ''; |
| 522 | 513 | } |
| 523 | 514 | $address_selected_infos = get_post_meta($address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true); |
@@ -547,8 +538,7 @@ discard block |
||
| 547 | 538 | if ( !is_admin() ) { |
| 548 | 539 | $tpl_component['ADDRESS_COMBOBOX'] = (!empty($tpl_component['ADDRESS_COMBOBOX_OPTION']) && ($nb_of_addresses > 1)) ? wpshop_display::display_template_element('addresses_type_combobox', $tpl_component) : ''; |
| 549 | 540 | } |
| 550 | - } |
|
| 551 | - else { |
|
| 541 | + } else { |
|
| 552 | 542 | if ( !empty($args) && !empty($args['first']) && $args['first'] ) { |
| 553 | 543 | $tpl_component['ADDRESS_TYPE'] = 'first_address'; |
| 554 | 544 | } |
@@ -592,8 +582,7 @@ discard block |
||
| 592 | 582 | $address_type = get_post_meta( $address_id, '_wpshop_address_attribute_set_id', true); |
| 593 | 583 | $response .= self::display_form_fields($address_type, $address_id, '', '', array(), array(), array(), $user_id); |
| 594 | 584 | $title = __('Edit your address', 'wpshop'); |
| 595 | - } |
|
| 596 | - elseif($address_type_id) { |
|
| 585 | + } elseif($address_type_id) { |
|
| 597 | 586 | $billing_option = get_option( 'wpshop_billing_address' ); |
| 598 | 587 | |
| 599 | 588 | $addresses = self::get_addresses_list( $user_id ); |
@@ -642,8 +631,7 @@ discard block |
||
| 642 | 631 | if(!empty($attribute->id)) { |
| 643 | 632 | if ( !empty( $submit_billing_and_shipping_info ) ) { |
| 644 | 633 | $value = $attribute[$typeof][$attribute->data_type][$attribute->code]; |
| 645 | - } |
|
| 646 | - else { |
|
| 634 | + } else { |
|
| 647 | 635 | $value = wpshop_attributes::getAttributeValueForEntityInSet($attribute->data_type, $attribute->id, wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS), $current_item_edited, array('intrinsic' => $attribute->is_intrinsic, 'backend_input' => $attribute->backend_input)); |
| 648 | 636 | } |
| 649 | 637 | $attribute_output_def = wpshop_attributes::get_attribute_field_definition( $attribute, $value, array() ); |
@@ -709,11 +697,9 @@ discard block |
||
| 709 | 697 | if ( !empty($customer_id) ) { |
| 710 | 698 | $post_parent = $customer_id; |
| 711 | 699 | $post_author = $customer_id; |
| 712 | - } |
|
| 713 | - elseif ( !empty( $post_ID ) ) { |
|
| 700 | + } elseif ( !empty( $post_ID ) ) { |
|
| 714 | 701 | $post_parent = $post_ID; |
| 715 | - } |
|
| 716 | - else { |
|
| 702 | + } else { |
|
| 717 | 703 | $post_parent = get_current_user_id(); |
| 718 | 704 | } |
| 719 | 705 | $post_address = array( |
@@ -732,8 +718,7 @@ discard block |
||
| 732 | 718 | if ( is_admin()) { |
| 733 | 719 | $attribute[$attribute_set_id]['item_id'] = $current_item_edited; |
| 734 | 720 | } |
| 735 | - } |
|
| 736 | - else { |
|
| 721 | + } else { |
|
| 737 | 722 | $post_address['ID'] = $current_item_edited; |
| 738 | 723 | wp_update_post( $post_address ); |
| 739 | 724 | } |
@@ -764,7 +749,9 @@ discard block |
||
| 764 | 749 | unset($attributes[$code_verif]); |
| 765 | 750 | } |
| 766 | 751 | } |
| 767 | - if( !in_array($code, $attribute_not_to_do)) $attributes[$code] = $value; |
|
| 752 | + if( !in_array($code, $attribute_not_to_do)) { |
|
| 753 | + $attributes[$code] = $value; |
|
| 754 | + } |
|
| 768 | 755 | } |
| 769 | 756 | } |
| 770 | 757 | } |
@@ -779,8 +766,7 @@ discard block |
||
| 779 | 766 | $billing_option = get_option( 'wpshop_billing_address' ); |
| 780 | 767 | if( !empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $attribute_set_id ) { |
| 781 | 768 | $_SESSION['billing_address'] = $result['current_id']; |
| 782 | - } |
|
| 783 | - else { |
|
| 769 | + } else { |
|
| 784 | 770 | $_SESSION['shipping_address'] = $result['current_id']; |
| 785 | 771 | } |
| 786 | 772 | } |
@@ -814,8 +800,7 @@ discard block |
||
| 814 | 800 | /** Check if it's shipping or billing **/ |
| 815 | 801 | if ( $type == $choosen_address['choice'] ) { |
| 816 | 802 | $form_model = ( !empty($choosen_address['display_model']) ) ? $choosen_address['display_model'] : null; |
| 817 | - } |
|
| 818 | - elseif( $type == $shipping_address['choice'] ) { |
|
| 803 | + } elseif( $type == $shipping_address['choice'] ) { |
|
| 819 | 804 | $form_model = ( !empty($shipping_address['display_model']) ) ? $shipping_address['display_model'] : null; |
| 820 | 805 | } |
| 821 | 806 | |
@@ -827,7 +812,9 @@ discard block |
||
| 827 | 812 | $current_item_edited = !empty($id) ? (int)wpshop_tools::varSanitizer($id) : null; |
| 828 | 813 | |
| 829 | 814 | foreach ( $form as $group_id => $group_fields) { |
| 830 | - if ( empty($options) || (!empty($options) && ($options['title']))) $output_form_fields .= '<h2>'.__( $group_fields['name'], 'wpshop' ).'</h2>'; |
|
| 815 | + if ( empty($options) || (!empty($options) && ($options['title']))) { |
|
| 816 | + $output_form_fields .= '<h2>'.__( $group_fields['name'], 'wpshop' ).'</h2>'; |
|
| 817 | + } |
|
| 831 | 818 | $end_line_indicator = 0; $fields_limit_per_line = -1; |
| 832 | 819 | foreach ( $group_fields['content'] as $key => $field) { |
| 833 | 820 | $attribute_def = wpshop_attributes::getElement( $field['name'], $element_status = "'valid'", $field_to_search = 'code' ); |
@@ -852,8 +839,7 @@ discard block |
||
| 852 | 839 | if ( !empty($fields_limit_per_line) && $fields_limit_per_line != -1 ) { |
| 853 | 840 | if ( $fields_limit_per_line == 1 ) { |
| 854 | 841 | $output_form_fields .= '<div class="wps-row">'; |
| 855 | - } |
|
| 856 | - else { |
|
| 842 | + } else { |
|
| 857 | 843 | $output_form_fields .= '<div class="wps-row wps-gridwrapper' .$fields_limit_per_line. '-padded">'; |
| 858 | 844 | } |
| 859 | 845 | } |
@@ -884,8 +870,7 @@ discard block |
||
| 884 | 870 | if ( !empty($address_type) ){ |
| 885 | 871 | if ( !empty( $shipping_address_choice['choice'] ) && $address_type == $shipping_address_choice['choice'] ) { |
| 886 | 872 | $shipping_address_count++; |
| 887 | - } |
|
| 888 | - else{ |
|
| 873 | + } else{ |
|
| 889 | 874 | $billing_address_count++; |
| 890 | 875 | } |
| 891 | 876 | } |
@@ -929,8 +914,7 @@ discard block |
||
| 929 | 914 | |
| 930 | 915 | if( $field['name'] == 'address_title' && !empty($first) && $type == __('Billing address', 'wpshop') ) { |
| 931 | 916 | $value = __('Billing address', 'wpshop'); |
| 932 | - } |
|
| 933 | - elseif( $field['name'] == 'address_title' && !empty($first) && $type == __('Shipping address', 'wpshop') ) { |
|
| 917 | + } elseif( $field['name'] == 'address_title' && !empty($first) && $type == __('Shipping address', 'wpshop') ) { |
|
| 934 | 918 | $value = __('Shipping address', 'wpshop'); |
| 935 | 919 | } |
| 936 | 920 | |
@@ -1025,7 +1009,9 @@ discard block |
||
| 1025 | 1009 | |
| 1026 | 1010 | $output_form_fields .= ( $user_id != get_current_user_id() ) ? '<input type="hidden" name="user[customer_id]" value="' .$user_id. '" />' : ''; |
| 1027 | 1011 | |
| 1028 | - if ( empty($first) ) $output_form_fields = wpshop_display::display_template_element('wpshop_customer_addresses_form', array('CUSTOMER_ADDRESSES_FORM_CONTENT' => $output_form_fields, 'CUSTOMER_ADDRESSES_FORM_BUTTONS' => '')); |
|
| 1012 | + if ( empty($first) ) { |
|
| 1013 | + $output_form_fields = wpshop_display::display_template_element('wpshop_customer_addresses_form', array('CUSTOMER_ADDRESSES_FORM_CONTENT' => $output_form_fields, 'CUSTOMER_ADDRESSES_FORM_BUTTONS' => '')); |
|
| 1014 | + } |
|
| 1029 | 1015 | |
| 1030 | 1016 | return $output_form_fields; |
| 1031 | 1017 | } |
@@ -1157,8 +1143,7 @@ discard block |
||
| 1157 | 1143 | if ( empty( $shipping_option ) || empty( $shipping_option[ 'activate' ] ) || $cart_is_downloadable ) { |
| 1158 | 1144 | $display_address_of_type = false; |
| 1159 | 1145 | $shipping_is_avalaible = false; |
| 1160 | - } |
|
| 1161 | - else { |
|
| 1146 | + } else { |
|
| 1162 | 1147 | $address_type_id = $shipping_option[ 'choice' ]; |
| 1163 | 1148 | } |
| 1164 | 1149 | break; |
@@ -1212,8 +1197,9 @@ discard block |
||
| 1212 | 1197 | function display_addresses_list() { |
| 1213 | 1198 | $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 1214 | 1199 | |
| 1215 | - if ( !wp_verify_nonce( $_wpnonce, 'display_addresses_list' ) ) |
|
| 1216 | - die(); |
|
| 1200 | + if ( !wp_verify_nonce( $_wpnonce, 'display_addresses_list' ) ) { |
|
| 1201 | + die(); |
|
| 1202 | + } |
|
| 1217 | 1203 | |
| 1218 | 1204 | $post_id = (int) $_POST['post_id']; |
| 1219 | 1205 | $addresses = $this->get_addresses_list( $post_id ); |
@@ -1229,8 +1215,9 @@ discard block |
||
| 1229 | 1215 | function display_address() { |
| 1230 | 1216 | $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 1231 | 1217 | |
| 1232 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_address_display_an_address' ) ) |
|
| 1233 | - die(); |
|
| 1218 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_address_display_an_address' ) ) { |
|
| 1219 | + die(); |
|
| 1220 | + } |
|
| 1234 | 1221 | |
| 1235 | 1222 | $adress_id = (int) $_POST['address_id']; |
| 1236 | 1223 | $address_post_meta = get_post_meta( $adress_id, '_wpshop_address_metadata', true); |
@@ -1258,8 +1245,9 @@ discard block |
||
| 1258 | 1245 | |
| 1259 | 1246 | $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 1260 | 1247 | |
| 1261 | - if ( !wp_verify_nonce( $_wpnonce, 'display_address_adding_form' ) ) |
|
| 1262 | - die(); |
|
| 1248 | + if ( !wp_verify_nonce( $_wpnonce, 'display_address_adding_form' ) ) { |
|
| 1249 | + die(); |
|
| 1250 | + } |
|
| 1263 | 1251 | |
| 1264 | 1252 | $address_id = 0; |
| 1265 | 1253 | $post_ID = (int)$_POST[ 'post_id' ]; |
@@ -1272,12 +1260,10 @@ discard block |
||
| 1272 | 1260 | if ( count( $attached_addresses ) == 1 ) { |
| 1273 | 1261 | $address_type_id = $attached_addresses[ 0 ]; |
| 1274 | 1262 | require_once( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "form" ) ); |
| 1275 | - } |
|
| 1276 | - else { |
|
| 1263 | + } else { |
|
| 1277 | 1264 | require_once( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "addresses", "types" ) ); |
| 1278 | 1265 | } |
| 1279 | - } |
|
| 1280 | - else { |
|
| 1266 | + } else { |
|
| 1281 | 1267 | printf( __( 'No addresses are attached to this element type %s', 'wpeo_geoloc' ), $element->post_type); |
| 1282 | 1268 | } |
| 1283 | 1269 | |
@@ -1292,8 +1278,9 @@ discard block |
||
| 1292 | 1278 | function load_address_edition_form() { |
| 1293 | 1279 | $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 1294 | 1280 | |
| 1295 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_address_edition_form_load' ) ) |
|
| 1296 | - die(); |
|
| 1281 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_address_edition_form_load' ) ) { |
|
| 1282 | + die(); |
|
| 1283 | + } |
|
| 1297 | 1284 | |
| 1298 | 1285 | $address_id = (int)$_POST[ 'element_id' ]; |
| 1299 | 1286 | $post_ID = (int)$_POST[ 'post_id' ]; |
@@ -1313,8 +1300,9 @@ discard block |
||
| 1313 | 1300 | function wps_delete_an_address() { |
| 1314 | 1301 | $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 1315 | 1302 | |
| 1316 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_delete_an_address' ) ) |
|
| 1317 | - die(); |
|
| 1303 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_delete_an_address' ) ) { |
|
| 1304 | + die(); |
|
| 1305 | + } |
|
| 1318 | 1306 | |
| 1319 | 1307 | $status = false; $response = ''; |
| 1320 | 1308 | $address_id = ( !empty( $_POST['address_id']) ) ? (int) $_POST['address_id'] : null; |
@@ -1336,8 +1324,9 @@ discard block |
||
| 1336 | 1324 | function wps_reload_address_interface() { |
| 1337 | 1325 | $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 1338 | 1326 | |
| 1339 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_address_interface' ) ) |
|
| 1340 | - die(); |
|
| 1327 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_reload_address_interface' ) ) { |
|
| 1328 | + die(); |
|
| 1329 | + } |
|
| 1341 | 1330 | |
| 1342 | 1331 | global $wpdb; |
| 1343 | 1332 | $status = false; $response = ''; |
@@ -1348,8 +1337,7 @@ discard block |
||
| 1348 | 1337 | $billing_option = get_option( 'wpshop_billing_address' ); |
| 1349 | 1338 | if ( !empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $address_type ) { |
| 1350 | 1339 | $type = 'billing'; |
| 1351 | - } |
|
| 1352 | - else { |
|
| 1340 | + } else { |
|
| 1353 | 1341 | $type = 'shipping'; |
| 1354 | 1342 | } |
| 1355 | 1343 | $query = $wpdb->prepare( 'SELECT name FROM '.WPSHOP_DBT_ATTRIBUTE_SET .' WHERE id = %d ', $address_type ); |
@@ -1371,8 +1359,9 @@ discard block |
||
| 1371 | 1359 | |
| 1372 | 1360 | $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 1373 | 1361 | |
| 1374 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_load_address_form_' . $address_type_id ) ) |
|
| 1375 | - wp_die(); |
|
| 1362 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_load_address_form_' . $address_type_id ) ) { |
|
| 1363 | + wp_die(); |
|
| 1364 | + } |
|
| 1376 | 1365 | |
| 1377 | 1366 | |
| 1378 | 1367 | $form_data = self::loading_address_form( $address_type_id, $address_id, get_current_user_id() ); |
@@ -1390,8 +1379,9 @@ discard block |
||
| 1390 | 1379 | |
| 1391 | 1380 | $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 1392 | 1381 | |
| 1393 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_address' ) ) |
|
| 1394 | - wp_die(); |
|
| 1382 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_save_address' ) ) { |
|
| 1383 | + wp_die(); |
|
| 1384 | + } |
|
| 1395 | 1385 | |
| 1396 | 1386 | $adress_save_the_first = !empty( $_POST['wps-address-save-the-first'] ) ? sanitize_text_field( $_POST['wps-address-save-the-first'] ) : ''; |
| 1397 | 1387 | $attribute = !empty( $_POST['attribute'] ) ? (array)$_POST['attribute'] : ''; |
@@ -1451,8 +1441,7 @@ discard block |
||
| 1451 | 1441 | $address_title = __( $wpdb->get_var( $query ), 'wpshop' ); |
| 1452 | 1442 | $result = self::display_address_interface_content( $address_type, $address_title, $shipping_save[ 'current_id' ], $adress_save_the_first ); |
| 1453 | 1443 | } |
| 1454 | - } |
|
| 1455 | - else { |
|
| 1444 | + } else { |
|
| 1456 | 1445 | if ( !empty($wpshop->errors) ){ |
| 1457 | 1446 | $result = '<div class="wps-alert wps-alert-error">' .__('Some errors have been detected', 'wpshop') . ' : <ul>'; |
| 1458 | 1447 | foreach( $wpshop->errors as $error ){ |
@@ -248,7 +248,7 @@ |
||
| 248 | 248 | |
| 249 | 249 | /** |
| 250 | 250 | * Generate barcode image |
| 251 | - * @param object $barcode Instance of wps_barcodegen |
|
| 251 | + * @param wps_barcodegen $barcode Instance of wps_barcodegen |
|
| 252 | 252 | * @param string $meta Numerical code of barcode |
| 253 | 253 | * @param string $type Texte for complete message |
| 254 | 254 | * @param string $price Price of product |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | |
| 3 | 5 | class wps_barcode_metabox { |
| 4 | 6 | public function __construct() { |
@@ -85,15 +87,13 @@ discard block |
||
| 85 | 87 | if ( isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on' ) { |
| 86 | 88 | echo $ajax->generate_image($barcode, $meta, __('product', 'wps_barcode'), |
| 87 | 89 | $price, $ref); |
| 88 | - } |
|
| 89 | - else { |
|
| 90 | + } else { |
|
| 90 | 91 | echo '<p style="text-align: center"><button class="button '. |
| 91 | 92 | 'button-primary button-large" type="button"'. |
| 92 | 93 | 'id="display_barcode">'. |
| 93 | 94 | __('Display', 'wps_barcode').'</button></p>'; |
| 94 | 95 | } |
| 95 | - } |
|
| 96 | - else { |
|
| 96 | + } else { |
|
| 97 | 97 | $conf = get_option('wps_barcode'); |
| 98 | 98 | |
| 99 | 99 | if ( $conf['generate_barcode'] === 'true' ) { |
@@ -134,8 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | if ( empty($order_postmeta['order_invoice_ref']) ) { |
| 136 | 136 | $continue = false; |
| 137 | - } |
|
| 138 | - else { |
|
| 137 | + } else { |
|
| 139 | 138 | $continue = true; |
| 140 | 139 | $id = substr($order_postmeta['order_invoice_ref'], 2); |
| 141 | 140 | } |
@@ -146,8 +145,7 @@ discard block |
||
| 146 | 145 | if ( empty($result['_order_barcode']) ) { |
| 147 | 146 | $meta = $barcode->checksum($code); |
| 148 | 147 | add_post_meta($post_ID, '_order_barcode', $meta); |
| 149 | - } |
|
| 150 | - else { |
|
| 148 | + } else { |
|
| 151 | 149 | $meta = $result['_order_barcode']; |
| 152 | 150 | } |
| 153 | 151 | |
@@ -163,19 +161,16 @@ discard block |
||
| 163 | 161 | $this->generate_image($barcode, $meta[0], __('order client', 'wps_barcode'), |
| 164 | 162 | $price, $title ); |
| 165 | 163 | } |
| 166 | - } |
|
| 167 | - else { |
|
| 164 | + } else { |
|
| 168 | 165 | echo '<p>'.__('None bardcode generated as customer can not get his bill.', |
| 169 | 166 | 'wps_barcode').'</p>'; |
| 170 | 167 | } |
| 171 | 168 | |
| 172 | - } |
|
| 173 | - else { |
|
| 169 | + } else { |
|
| 174 | 170 | echo '<p>'.__('None bardcode generated as customer can not get his bill.', |
| 175 | 171 | 'wps_barcode').'</p>'; |
| 176 | 172 | } |
| 177 | - } |
|
| 178 | - else { |
|
| 173 | + } else { |
|
| 179 | 174 | echo '<p>'.sprintf( __('None bardcode generated as you did create %s.', |
| 180 | 175 | 'wps_barcode'), 'order client').'</p>'; |
| 181 | 176 | } |
@@ -220,8 +215,7 @@ discard block |
||
| 220 | 215 | $code = $type.$date.$id; |
| 221 | 216 | $meta = $barcode->checksum($code); |
| 222 | 217 | add_post_meta($post_ID, 'wpshop_coupon_barcode', $meta); |
| 223 | - } |
|
| 224 | - else { |
|
| 218 | + } else { |
|
| 225 | 219 | $meta = $result['wpshop_coupon_barcode'][0]; |
| 226 | 220 | } |
| 227 | 221 | |
@@ -232,15 +226,13 @@ discard block |
||
| 232 | 226 | if ( isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on' ) { |
| 233 | 227 | $ajax->generate_image($barcode, $meta, __('coupon', 'wps_barcode'), |
| 234 | 228 | $result['wpshop_coupon_discount_value'][0], $query[0]['post_title'], $post_ID); |
| 235 | - } |
|
| 236 | - else { |
|
| 229 | + } else { |
|
| 237 | 230 | echo '<p style="text-align: center"><button class="button '. |
| 238 | 231 | 'button-primary button-large" type="button"'. |
| 239 | 232 | 'id="display_barcode">'. |
| 240 | 233 | __('Display', 'wps_barcode').'</button></p>'; |
| 241 | 234 | } |
| 242 | - } |
|
| 243 | - else { |
|
| 235 | + } else { |
|
| 244 | 236 | echo '<p>'.__('None bardcode generated as coupon has not created.', |
| 245 | 237 | 'wps_barcode').'</p>'; |
| 246 | 238 | } |
@@ -291,8 +283,7 @@ discard block |
||
| 291 | 283 | for ($i=0; $i<42 ; $i++) { |
| 292 | 284 | if( substr($binCode, $i, 1) === '0' ) { |
| 293 | 285 | $color = imagecolorallocate($im, 255, 255, 255); |
| 294 | - } |
|
| 295 | - else { |
|
| 286 | + } else { |
|
| 296 | 287 | $color = imagecolorallocate($im, 0, 0, 0); |
| 297 | 288 | } |
| 298 | 289 | |
@@ -320,8 +311,7 @@ discard block |
||
| 320 | 311 | for ($i=42; $i<84 ; $i++) { |
| 321 | 312 | if( substr($binCode, $i, 1) === '0' ) { |
| 322 | 313 | $color = imagecolorallocate($im, 255, 255, 255); |
| 323 | - } |
|
| 324 | - else { |
|
| 314 | + } else { |
|
| 325 | 315 | $color = imagecolorallocate($im, 0, 0, 0); |
| 326 | 316 | } |
| 327 | 317 | |
@@ -374,12 +364,10 @@ discard block |
||
| 374 | 364 | $coupon_postmeta = get_post_meta($post_ID, 'wpshop_coupon_discount_type'); |
| 375 | 365 | if ( $coupon_postmeta[0] === 'percent' ) { |
| 376 | 366 | $price = $price.' %'; |
| 377 | - } |
|
| 378 | - else { |
|
| 367 | + } else { |
|
| 379 | 368 | $price = sprintf( number_format( $price, 2 ). ' '.$currency); |
| 380 | 369 | } |
| 381 | - } |
|
| 382 | - else { |
|
| 370 | + } else { |
|
| 383 | 371 | $price = sprintf( number_format( $price, 2 ). ' '.$currency); |
| 384 | 372 | } |
| 385 | 373 | |
@@ -415,8 +403,7 @@ discard block |
||
| 415 | 403 | } catch (Exception $e) { |
| 416 | 404 | echo __('Generation problem', 'wps_barcode'); |
| 417 | 405 | } |
| 418 | - } |
|
| 419 | - else { |
|
| 406 | + } else { |
|
| 420 | 407 | echo '<p>'.sprintf( __('None bardcode generated as you did create %s.', |
| 421 | 408 | 'wps_barcode'), $type).'</p>'; |
| 422 | 409 | } |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | |
| 3 | 3 | class wps_barcode_metabox { |
| 4 | 4 | public function __construct() { |
| 5 | - add_action( 'add_meta_boxes', array($this, 'add_meta_box'), 10, 10 ); |
|
| 5 | + add_action('add_meta_boxes', array($this, 'add_meta_box'), 10, 10); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | /** |
@@ -13,9 +13,9 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | $conf = get_option('wps_barcode'); |
| 15 | 15 | |
| 16 | - $post = get_post( get_the_ID() ); |
|
| 17 | - if ( !empty($post) ) { |
|
| 18 | - $query = $wpdb->prepare( " |
|
| 16 | + $post = get_post(get_the_ID()); |
|
| 17 | + if (!empty($post)) { |
|
| 18 | + $query = $wpdb->prepare(" |
|
| 19 | 19 | SELECT * |
| 20 | 20 | FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . " |
| 21 | 21 | WHERE entity_id = %d |
@@ -23,22 +23,22 @@ discard block |
||
| 23 | 23 | SELECT id |
| 24 | 24 | FROM " . WPSHOP_DBT_ATTRIBUTE . " |
| 25 | 25 | WHERE code = %s |
| 26 | - )" , $post->ID, 'barcode' ); |
|
| 27 | - $result = $wpdb->get_results( $query, ARRAY_A ); |
|
| 26 | + )" , $post->ID, 'barcode'); |
|
| 27 | + $result = $wpdb->get_results($query, ARRAY_A); |
|
| 28 | 28 | |
| 29 | - add_meta_box('wps_barcode_product', __('Barcode Manager', 'wps_barcode' ), |
|
| 30 | - array( $this, 'meta_box_product' ), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 31 | - 'side','default'); |
|
| 29 | + add_meta_box('wps_barcode_product', __('Barcode Manager', 'wps_barcode'), |
|
| 30 | + array($this, 'meta_box_product'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 31 | + 'side', 'default'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | if ($conf['type'] === 'internal') { |
| 35 | - add_meta_box('wps_barcode_invoice_client', __('Barcode Manager', 'wps_barcode' ), |
|
| 36 | - array( $this, 'meta_box_invoice_client' ), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, |
|
| 37 | - 'side','default'); |
|
| 35 | + add_meta_box('wps_barcode_invoice_client', __('Barcode Manager', 'wps_barcode'), |
|
| 36 | + array($this, 'meta_box_invoice_client'), WPSHOP_NEWTYPE_IDENTIFIER_ORDER, |
|
| 37 | + 'side', 'default'); |
|
| 38 | 38 | |
| 39 | - add_meta_box('wps_barcode_coupons', __('Barcode Manager', 'wps_barcode' ), |
|
| 40 | - array( $this, 'meta_box_coupons' ), WPSHOP_NEWTYPE_IDENTIFIER_COUPON, |
|
| 41 | - 'side','default'); |
|
| 39 | + add_meta_box('wps_barcode_coupons', __('Barcode Manager', 'wps_barcode'), |
|
| 40 | + array($this, 'meta_box_coupons'), WPSHOP_NEWTYPE_IDENTIFIER_COUPON, |
|
| 41 | + 'side', 'default'); |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
@@ -59,17 +59,17 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | /*Select value of barcode*/ |
| 61 | 61 | $result = $wpdb->get_results( |
| 62 | - 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR. |
|
| 63 | - ' WHERE attribute_id=(SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE. |
|
| 64 | - ' WHERE code = "barcode") AND entity_id="'.$post_ID.'"', ARRAY_A); |
|
| 62 | + 'SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . |
|
| 63 | + ' WHERE attribute_id=(SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . |
|
| 64 | + ' WHERE code = "barcode") AND entity_id="' . $post_ID . '"', ARRAY_A); |
|
| 65 | 65 | $meta = !empty($result) ? $result[0]['value'] : ''; |
| 66 | 66 | |
| 67 | 67 | /*Get price of product*/ |
| 68 | - $result = $wpdb->get_results('SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL. |
|
| 69 | - ' WHERE attribute_id=(SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE. |
|
| 70 | - ' WHERE code="'.WPSHOP_PRODUCT_PRICE_TTC.'") AND entity_id='.$post_ID, ARRAY_A); |
|
| 68 | + $result = $wpdb->get_results('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . |
|
| 69 | + ' WHERE attribute_id=(SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . |
|
| 70 | + ' WHERE code="' . WPSHOP_PRODUCT_PRICE_TTC . '") AND entity_id=' . $post_ID, ARRAY_A); |
|
| 71 | 71 | |
| 72 | - if ( !empty($result) && $result[0]['value'] >= 0) { |
|
| 72 | + if (!empty($result) && $result[0]['value'] >= 0) { |
|
| 73 | 73 | $price = $result[0]['value']; |
| 74 | 74 | |
| 75 | 75 | /*Get title of product*/ |
@@ -77,28 +77,28 @@ discard block |
||
| 77 | 77 | $ref = substr($post['post_title'], 0, 10); |
| 78 | 78 | |
| 79 | 79 | chdir('..'); |
| 80 | - chdir( plugin_dir_path(__FILE__) ); |
|
| 80 | + chdir(plugin_dir_path(__FILE__)); |
|
| 81 | 81 | chdir('..'); |
| 82 | 82 | |
| 83 | 83 | $conf = get_option('wps_barcode'); |
| 84 | 84 | |
| 85 | - if ( isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on' ) { |
|
| 85 | + if (isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on') { |
|
| 86 | 86 | echo $ajax->generate_image($barcode, $meta, __('product', 'wps_barcode'), |
| 87 | 87 | $price, $ref); |
| 88 | 88 | } |
| 89 | 89 | else { |
| 90 | - echo '<p style="text-align: center"><button class="button '. |
|
| 91 | - 'button-primary button-large" type="button"'. |
|
| 92 | - 'id="display_barcode" data-nonce=' . wp_create_nonce( 'imgProduct' ) . '>'. |
|
| 93 | - __('Display', 'wps_barcode').'</button></p>'; |
|
| 90 | + echo '<p style="text-align: center"><button class="button ' . |
|
| 91 | + 'button-primary button-large" type="button"' . |
|
| 92 | + 'id="display_barcode" data-nonce=' . wp_create_nonce('imgProduct') . '>' . |
|
| 93 | + __('Display', 'wps_barcode') . '</button></p>'; |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | else { |
| 97 | 97 | $conf = get_option('wps_barcode'); |
| 98 | 98 | |
| 99 | - if ( $conf['generate_barcode'] === 'true' ) { |
|
| 100 | - echo '<p>'.sprintf( __('None bardcode generated as you did create %s.', |
|
| 101 | - 'wps_barcode'), __('product', 'wps_barcode')).'</p>'; |
|
| 99 | + if ($conf['generate_barcode'] === 'true') { |
|
| 100 | + echo '<p>' . sprintf(__('None bardcode generated as you did create %s.', |
|
| 101 | + 'wps_barcode'), __('product', 'wps_barcode')) . '</p>'; |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -118,21 +118,20 @@ discard block |
||
| 118 | 118 | $country = '000'; |
| 119 | 119 | $result = get_post_meta($post_ID); |
| 120 | 120 | |
| 121 | - if ( !empty($result) ) { |
|
| 121 | + if (!empty($result)) { |
|
| 122 | 122 | $order_postmeta = unserialize($result['_order_postmeta'][0]); |
| 123 | 123 | |
| 124 | - if ( !empty($order_postmeta['order_invoice_date']) ) { |
|
| 124 | + if (!empty($order_postmeta['order_invoice_date'])) { |
|
| 125 | 125 | $conf = get_option('wps_barcode'); |
| 126 | 126 | if ($conf['type'] === 'internal') { |
| 127 | 127 | $type = $conf['internal_invoice_client']; |
| 128 | 128 | |
| 129 | 129 | $order_date = isset($order_postmeta['order_invoice_date']) ? |
| 130 | - $order_postmeta['order_invoice_date'] : |
|
| 131 | - $order_postmeta['order_date']; |
|
| 130 | + $order_postmeta['order_invoice_date'] : $order_postmeta['order_date']; |
|
| 132 | 131 | $pDate = new DateTime($order_date); |
| 133 | 132 | $date = $pDate->format('my'); |
| 134 | 133 | |
| 135 | - if ( empty($order_postmeta['order_invoice_ref']) ) { |
|
| 134 | + if (empty($order_postmeta['order_invoice_ref'])) { |
|
| 136 | 135 | $continue = false; |
| 137 | 136 | } |
| 138 | 137 | else { |
@@ -141,9 +140,9 @@ discard block |
||
| 141 | 140 | } |
| 142 | 141 | } |
| 143 | 142 | if ($continue === true) { |
| 144 | - $code = $type.$date.$id; |
|
| 143 | + $code = $type . $date . $id; |
|
| 145 | 144 | |
| 146 | - if ( empty($result['_order_barcode']) ) { |
|
| 145 | + if (empty($result['_order_barcode'])) { |
|
| 147 | 146 | $meta = $barcode->checksum($code); |
| 148 | 147 | add_post_meta($post_ID, '_order_barcode', $meta); |
| 149 | 148 | } |
@@ -152,32 +151,32 @@ discard block |
||
| 152 | 151 | } |
| 153 | 152 | |
| 154 | 153 | chdir('..'); |
| 155 | - chdir( plugin_dir_path(__FILE__) ); |
|
| 154 | + chdir(plugin_dir_path(__FILE__)); |
|
| 156 | 155 | chdir('..'); |
| 157 | 156 | $order_meta = unserialize($result['_order_postmeta'][0]); |
| 158 | - $title = ( !empty($order_meta['order_invoice_ref']) ) ? $order_meta['order_invoice_ref'] : $order_meta['order_key']; |
|
| 157 | + $title = (!empty($order_meta['order_invoice_ref'])) ? $order_meta['order_invoice_ref'] : $order_meta['order_key']; |
|
| 159 | 158 | $price = $order_meta['order_grand_total']; |
| 160 | 159 | |
| 161 | 160 | |
| 162 | - if ( isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on' ) { |
|
| 161 | + if (isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on') { |
|
| 163 | 162 | $this->generate_image($barcode, $meta[0], __('order client', 'wps_barcode'), |
| 164 | - $price, $title ); |
|
| 163 | + $price, $title); |
|
| 165 | 164 | } |
| 166 | 165 | } |
| 167 | 166 | else { |
| 168 | - echo '<p>'.__('None bardcode generated as customer can not get his bill.', |
|
| 169 | - 'wps_barcode').'</p>'; |
|
| 167 | + echo '<p>' . __('None bardcode generated as customer can not get his bill.', |
|
| 168 | + 'wps_barcode') . '</p>'; |
|
| 170 | 169 | } |
| 171 | 170 | |
| 172 | 171 | } |
| 173 | 172 | else { |
| 174 | - echo '<p>'.__('None bardcode generated as customer can not get his bill.', |
|
| 175 | - 'wps_barcode').'</p>'; |
|
| 173 | + echo '<p>' . __('None bardcode generated as customer can not get his bill.', |
|
| 174 | + 'wps_barcode') . '</p>'; |
|
| 176 | 175 | } |
| 177 | 176 | } |
| 178 | 177 | else { |
| 179 | - echo '<p>'.sprintf( __('None bardcode generated as you did create %s.', |
|
| 180 | - 'wps_barcode'), 'order client').'</p>'; |
|
| 178 | + echo '<p>' . sprintf(__('None bardcode generated as you did create %s.', |
|
| 179 | + 'wps_barcode'), 'order client') . '</p>'; |
|
| 181 | 180 | } |
| 182 | 181 | } |
| 183 | 182 | |
@@ -196,14 +195,14 @@ discard block |
||
| 196 | 195 | $country = '000'; |
| 197 | 196 | $result = get_post_meta($post_ID); |
| 198 | 197 | |
| 199 | - if ( !empty($result) ) { |
|
| 200 | - if ( empty($result['wpshop_coupon_barcode']) ) { |
|
| 198 | + if (!empty($result)) { |
|
| 199 | + if (empty($result['wpshop_coupon_barcode'])) { |
|
| 201 | 200 | $conf = get_option('wps_barcode'); |
| 202 | 201 | if ($conf['type'] === 'internal') { |
| 203 | 202 | $type = $conf['internal_coupons']; |
| 204 | 203 | |
| 205 | - $query = $wpdb->get_results('SELECT post_date FROM '. |
|
| 206 | - $table_prefix.'posts WHERE ID='.$post_ID, ARRAY_A); |
|
| 204 | + $query = $wpdb->get_results('SELECT post_date FROM ' . |
|
| 205 | + $table_prefix . 'posts WHERE ID=' . $post_ID, ARRAY_A); |
|
| 207 | 206 | |
| 208 | 207 | $pDate = new DateTime($query[0]['post_date']); |
| 209 | 208 | $date = $pDate->format('my'); |
@@ -211,13 +210,13 @@ discard block |
||
| 211 | 210 | |
| 212 | 211 | $len = strlen($post_ID); |
| 213 | 212 | $ref = ''; |
| 214 | - if ( $len < 5 ) { |
|
| 215 | - for ($i=0; $i <= $len; $i++) { |
|
| 213 | + if ($len < 5) { |
|
| 214 | + for ($i = 0; $i <= $len; $i++) { |
|
| 216 | 215 | $ref .= '0'; |
| 217 | 216 | } |
| 218 | 217 | } |
| 219 | - $id = $ref.$post_ID; |
|
| 220 | - $code = $type.$date.$id; |
|
| 218 | + $id = $ref . $post_ID; |
|
| 219 | + $code = $type . $date . $id; |
|
| 221 | 220 | $meta = $barcode->checksum($code); |
| 222 | 221 | add_post_meta($post_ID, 'wpshop_coupon_barcode', $meta); |
| 223 | 222 | } |
@@ -225,24 +224,24 @@ discard block |
||
| 225 | 224 | $meta = $result['wpshop_coupon_barcode'][0]; |
| 226 | 225 | } |
| 227 | 226 | |
| 228 | - $query = $wpdb->get_results('SELECT post_title FROM '. |
|
| 229 | - $table_prefix.'posts WHERE ID='.$post_ID, ARRAY_A); |
|
| 227 | + $query = $wpdb->get_results('SELECT post_title FROM ' . |
|
| 228 | + $table_prefix . 'posts WHERE ID=' . $post_ID, ARRAY_A); |
|
| 230 | 229 | |
| 231 | 230 | $post = get_post($post_ID, ARRAY_A); |
| 232 | - if ( isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on' ) { |
|
| 231 | + if (isset($conf['generate_barcode']) && $conf['generate_barcode'] === 'on') { |
|
| 233 | 232 | $ajax->generate_image($barcode, $meta, __('coupon', 'wps_barcode'), |
| 234 | 233 | $result['wpshop_coupon_discount_value'][0], $query[0]['post_title'], $post_ID); |
| 235 | 234 | } |
| 236 | 235 | else { |
| 237 | - echo '<p style="text-align: center"><button class="button '. |
|
| 238 | - 'button-primary button-large" type="button"'. |
|
| 239 | - 'id="display_barcode">'. |
|
| 240 | - __('Display', 'wps_barcode').'</button></p>'; |
|
| 236 | + echo '<p style="text-align: center"><button class="button ' . |
|
| 237 | + 'button-primary button-large" type="button"' . |
|
| 238 | + 'id="display_barcode">' . |
|
| 239 | + __('Display', 'wps_barcode') . '</button></p>'; |
|
| 241 | 240 | } |
| 242 | 241 | } |
| 243 | 242 | else { |
| 244 | - echo '<p>'.__('None bardcode generated as coupon has not created.', |
|
| 245 | - 'wps_barcode').'</p>'; |
|
| 243 | + echo '<p>' . __('None bardcode generated as coupon has not created.', |
|
| 244 | + 'wps_barcode') . '</p>'; |
|
| 246 | 245 | } |
| 247 | 246 | } |
| 248 | 247 | |
@@ -255,41 +254,41 @@ discard block |
||
| 255 | 254 | * @param string $title Title of product |
| 256 | 255 | */ |
| 257 | 256 | public function generate_image(&$barcode, $meta, $type, $price, $title, $post_ID = 0) { |
| 258 | - if ( !empty($meta) ) { |
|
| 257 | + if (!empty($meta)) { |
|
| 259 | 258 | $barcode->setGenerateCode($meta); |
| 260 | 259 | $binCode = $barcode->getBinCode(); |
| 261 | 260 | |
| 262 | 261 | $px = 3.779528; |
| 263 | - $x = round(66*$px); //249.449 px |
|
| 264 | - $y = round(50*$px); //188.976 px |
|
| 265 | - $bar_size = round(63.393/72); //0.880 px |
|
| 262 | + $x = round(66 * $px); //249.449 px |
|
| 263 | + $y = round(50 * $px); //188.976 px |
|
| 264 | + $bar_size = round(63.393 / 72); //0.880 px |
|
| 266 | 265 | |
| 267 | 266 | $len = 0; |
| 268 | 267 | $test = ''; |
| 269 | 268 | |
| 270 | - while ($len !== strlen($binCode) ) { |
|
| 271 | - $test .= substr($binCode, $len, 7).' '; |
|
| 272 | - $len = $len+7; |
|
| 269 | + while ($len !== strlen($binCode)) { |
|
| 270 | + $test .= substr($binCode, $len, 7) . ' '; |
|
| 271 | + $len = $len + 7; |
|
| 273 | 272 | } |
| 274 | 273 | |
| 275 | 274 | $im = imagecreate($x, $y); |
| 276 | 275 | $background_color = imagecolorallocate($im, 255, 255, 255); |
| 277 | - $start = round(5.79*$px); //21.883 |
|
| 276 | + $start = round(5.79 * $px); //21.883 |
|
| 278 | 277 | |
| 279 | 278 | /*Write First left guard*/ |
| 280 | - $this->imgNormalGuard($im, $start, $start+$bar_size, |
|
| 279 | + $this->imgNormalGuard($im, $start, $start + $bar_size, |
|
| 281 | 280 | imagecolorallocate($im, 0, 0, 0)); |
| 282 | - $this->imgNormalGuard($im, $start+($bar_size*2), |
|
| 283 | - $start+($bar_size*3), imagecolorallocate($im, 255, 255, 255)); |
|
| 284 | - $this->imgNormalGuard($im, $start+($bar_size*4), |
|
| 285 | - $start+($bar_size*5), imagecolorallocate($im, 0, 0, 0)); |
|
| 281 | + $this->imgNormalGuard($im, $start + ($bar_size * 2), |
|
| 282 | + $start + ($bar_size * 3), imagecolorallocate($im, 255, 255, 255)); |
|
| 283 | + $this->imgNormalGuard($im, $start + ($bar_size * 4), |
|
| 284 | + $start + ($bar_size * 5), imagecolorallocate($im, 0, 0, 0)); |
|
| 286 | 285 | |
| 287 | - $pos = $start+($bar_size*7); |
|
| 288 | - $newPos = $pos+$bar_size; |
|
| 286 | + $pos = $start + ($bar_size * 7); |
|
| 287 | + $newPos = $pos + $bar_size; |
|
| 289 | 288 | |
| 290 | 289 | /*Write left barcode*/ |
| 291 | - for ($i=0; $i<42 ; $i++) { |
|
| 292 | - if( substr($binCode, $i, 1) === '0' ) { |
|
| 290 | + for ($i = 0; $i < 42; $i++) { |
|
| 291 | + if (substr($binCode, $i, 1) === '0') { |
|
| 293 | 292 | $color = imagecolorallocate($im, 255, 255, 255); |
| 294 | 293 | } |
| 295 | 294 | else { |
@@ -297,128 +296,128 @@ discard block |
||
| 297 | 296 | } |
| 298 | 297 | |
| 299 | 298 | $this->imgSymbole($im, $pos, $newPos, $color); |
| 300 | - $newPos = $pos+$bar_size; |
|
| 301 | - $pos = $newPos+$bar_size; |
|
| 299 | + $newPos = $pos + $bar_size; |
|
| 300 | + $pos = $newPos + $bar_size; |
|
| 302 | 301 | } |
| 303 | 302 | |
| 304 | 303 | /*Writer center guard*/ |
| 305 | 304 | $pos = $newPos; |
| 306 | - $this->imgNormalGuard($im, $pos, $newPos+$bar_size, |
|
| 305 | + $this->imgNormalGuard($im, $pos, $newPos + $bar_size, |
|
| 307 | 306 | imagecolorallocate($im, 255, 255, 255)); |
| 308 | - $this->imgNormalGuard($im, $pos+($bar_size*2), |
|
| 309 | - $newPos+($bar_size*3), imagecolorallocate($im, 0, 0, 0)); |
|
| 310 | - $this->imgNormalGuard($im, $pos+($bar_size*4), |
|
| 311 | - $newPos+($bar_size*5), imagecolorallocate($im, 255, 255, 255)); |
|
| 312 | - $this->imgNormalGuard($im, $pos+($bar_size*6), |
|
| 313 | - $newPos+($bar_size*7), imagecolorallocate($im, 0, 0, 0)); |
|
| 314 | - $this->imgNormalGuard($im, $pos+($bar_size*8), |
|
| 315 | - $newPos+($bar_size*9), imagecolorallocate($im, 255, 255, 255)); |
|
| 307 | + $this->imgNormalGuard($im, $pos + ($bar_size * 2), |
|
| 308 | + $newPos + ($bar_size * 3), imagecolorallocate($im, 0, 0, 0)); |
|
| 309 | + $this->imgNormalGuard($im, $pos + ($bar_size * 4), |
|
| 310 | + $newPos + ($bar_size * 5), imagecolorallocate($im, 255, 255, 255)); |
|
| 311 | + $this->imgNormalGuard($im, $pos + ($bar_size * 6), |
|
| 312 | + $newPos + ($bar_size * 7), imagecolorallocate($im, 0, 0, 0)); |
|
| 313 | + $this->imgNormalGuard($im, $pos + ($bar_size * 8), |
|
| 314 | + $newPos + ($bar_size * 9), imagecolorallocate($im, 255, 255, 255)); |
|
| 316 | 315 | |
| 317 | - $pos = $newPos+($bar_size*10); |
|
| 316 | + $pos = $newPos + ($bar_size * 10); |
|
| 318 | 317 | |
| 319 | 318 | /*Write right barcode*/ |
| 320 | - for ($i=42; $i<84 ; $i++) { |
|
| 321 | - if( substr($binCode, $i, 1) === '0' ) { |
|
| 319 | + for ($i = 42; $i < 84; $i++) { |
|
| 320 | + if (substr($binCode, $i, 1) === '0') { |
|
| 322 | 321 | $color = imagecolorallocate($im, 255, 255, 255); |
| 323 | 322 | } |
| 324 | 323 | else { |
| 325 | 324 | $color = imagecolorallocate($im, 0, 0, 0); |
| 326 | 325 | } |
| 327 | 326 | |
| 328 | - $newPos = $pos+$bar_size; |
|
| 327 | + $newPos = $pos + $bar_size; |
|
| 329 | 328 | |
| 330 | 329 | $this->imgSymbole($im, $pos, $newPos, $color); |
| 331 | - $pos = $newPos+$bar_size; |
|
| 330 | + $pos = $newPos + $bar_size; |
|
| 332 | 331 | } |
| 333 | 332 | |
| 334 | 333 | /*Write right guard*/ |
| 335 | - $pos = $newPos+$bar_size; |
|
| 336 | - $this->imgNormalGuard($im, $pos, $pos+$bar_size, |
|
| 334 | + $pos = $newPos + $bar_size; |
|
| 335 | + $this->imgNormalGuard($im, $pos, $pos + $bar_size, |
|
| 337 | 336 | imagecolorallocate($im, 0, 0, 0)); |
| 338 | - $this->imgNormalGuard($im, $pos+($bar_size*2), |
|
| 339 | - $pos+($bar_size*3), imagecolorallocate($im, 255, 255, 255)); |
|
| 340 | - $this->imgNormalGuard($im, $pos+($bar_size*4), |
|
| 341 | - $pos+($bar_size*5), imagecolorallocate($im, 0, 0, 0)); |
|
| 337 | + $this->imgNormalGuard($im, $pos + ($bar_size * 2), |
|
| 338 | + $pos + ($bar_size * 3), imagecolorallocate($im, 255, 255, 255)); |
|
| 339 | + $this->imgNormalGuard($im, $pos + ($bar_size * 4), |
|
| 340 | + $pos + ($bar_size * 5), imagecolorallocate($im, 0, 0, 0)); |
|
| 342 | 341 | |
| 343 | 342 | $textSize = 16; |
| 344 | 343 | $font = 'assets/fonts/arialbd.ttf'; |
| 345 | - imagettftext($im, $textSize, 0, 8, $y-$start-5, |
|
| 344 | + imagettftext($im, $textSize, 0, 8, $y - $start - 5, |
|
| 346 | 345 | imagecolorallocate($im, 0, 0, 0), $font, substr($meta, 0, 1)); |
| 347 | 346 | |
| 348 | 347 | $continue = true; |
| 349 | 348 | $i = 28; $j = 0; |
| 350 | 349 | |
| 351 | 350 | /*Write left number code*/ |
| 352 | - while ($j<5) { |
|
| 353 | - $j=$j+1; |
|
| 354 | - imagettftext($im, $textSize, 0, $i, $y-$start-5, |
|
| 351 | + while ($j < 5) { |
|
| 352 | + $j = $j + 1; |
|
| 353 | + imagettftext($im, $textSize, 0, $i, $y - $start - 5, |
|
| 355 | 354 | imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j, 1)); |
| 356 | - $i = $i+14; |
|
| 355 | + $i = $i + 14; |
|
| 357 | 356 | } |
| 358 | 357 | |
| 359 | 358 | /*Write right number code*/ |
| 360 | - while ($j<11) { |
|
| 361 | - $j=$j+1; |
|
| 362 | - imagettftext($im, $textSize, 0, $i+6, $y-$start-5, |
|
| 359 | + while ($j < 11) { |
|
| 360 | + $j = $j + 1; |
|
| 361 | + imagettftext($im, $textSize, 0, $i + 6, $y - $start - 5, |
|
| 363 | 362 | imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j, 1)); |
| 364 | - $i = $i+15; |
|
| 363 | + $i = $i + 15; |
|
| 365 | 364 | } |
| 366 | - imagettftext($im, $textSize, 0, $i+4, $y-$start-5, |
|
| 367 | - imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j+1, 1)); |
|
| 365 | + imagettftext($im, $textSize, 0, $i + 4, $y - $start - 5, |
|
| 366 | + imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j + 1, 1)); |
|
| 368 | 367 | |
| 369 | 368 | /*Write ref product and price*/ |
| 370 | 369 | $textSize = 12; |
| 371 | 370 | $currency = (wpshop_tools::wpshop_get_currency() === '€') ? "€" : wpshop_tools::wpshop_get_currency(); |
| 372 | 371 | |
| 373 | - if ( $type === __('coupon', 'wps_barcode') ) { |
|
| 372 | + if ($type === __('coupon', 'wps_barcode')) { |
|
| 374 | 373 | $coupon_postmeta = get_post_meta($post_ID, 'wpshop_coupon_discount_type'); |
| 375 | - if ( $coupon_postmeta[0] === 'percent' ) { |
|
| 376 | - $price = $price.' %'; |
|
| 374 | + if ($coupon_postmeta[0] === 'percent') { |
|
| 375 | + $price = $price . ' %'; |
|
| 377 | 376 | } |
| 378 | 377 | else { |
| 379 | - $price = sprintf( number_format( $price, 2 ). ' '.$currency); |
|
| 378 | + $price = sprintf(number_format($price, 2) . ' ' . $currency); |
|
| 380 | 379 | } |
| 381 | 380 | } |
| 382 | 381 | else { |
| 383 | - $price = sprintf( number_format( $price, 2 ). ' '.$currency); |
|
| 382 | + $price = sprintf(number_format($price, 2) . ' ' . $currency); |
|
| 384 | 383 | } |
| 385 | 384 | |
| 386 | - imagettftext($im, $textSize, 0, 20, round(6*$px), |
|
| 385 | + imagettftext($im, $textSize, 0, 20, round(6 * $px), |
|
| 387 | 386 | imagecolorallocate($im, 0, 0, 0), $font, $title); |
| 388 | - imagettftext($im, $textSize, 0, ($x/2)+40, round(6*$px), |
|
| 387 | + imagettftext($im, $textSize, 0, ($x / 2) + 40, round(6 * $px), |
|
| 389 | 388 | imagecolorallocate($im, 0, 0, 0), $font, $price); |
| 390 | 389 | |
| 391 | 390 | ob_start(); |
| 392 | 391 | imagepng($im); |
| 393 | 392 | $img = ob_get_clean(); |
| 394 | 393 | |
| 395 | - echo '<p><img src="data:image/png;base64,'.base64_encode($img). |
|
| 394 | + echo '<p><img src="data:image/png;base64,' . base64_encode($img) . |
|
| 396 | 395 | '" id="barcode" width="160" height="90" /></p>'; |
| 397 | 396 | |
| 398 | - echo '<p style="text-align: right"><button class="button '. |
|
| 399 | - 'button-primary button-large" type="button"'. |
|
| 400 | - 'id="print_barcode">'. |
|
| 401 | - __('Print', 'wps_barcode').'</button></p>'; |
|
| 397 | + echo '<p style="text-align: right"><button class="button ' . |
|
| 398 | + 'button-primary button-large" type="button"' . |
|
| 399 | + 'id="print_barcode">' . |
|
| 400 | + __('Print', 'wps_barcode') . '</button></p>'; |
|
| 402 | 401 | |
| 403 | - wp_mkdir_p( WPS_BARCODE_UPLOAD ); |
|
| 402 | + wp_mkdir_p(WPS_BARCODE_UPLOAD); |
|
| 404 | 403 | |
| 405 | - file_put_contents(WPS_BARCODE_UPLOAD.$meta.'.png', $img); |
|
| 404 | + file_put_contents(WPS_BARCODE_UPLOAD . $meta . '.png', $img); |
|
| 406 | 405 | |
| 407 | 406 | /*Generate ODT File*/ |
| 408 | 407 | try { |
| 409 | - if( !class_exists('Odf') ) { |
|
| 410 | - require_once(WPS_BARCODE_PATH.'/librairies/odtphp/odf.php'); |
|
| 408 | + if (!class_exists('Odf')) { |
|
| 409 | + require_once(WPS_BARCODE_PATH . '/librairies/odtphp/odf.php'); |
|
| 411 | 410 | } |
| 412 | - $odf = new Odf(WPS_BARCODE_PATH.'assets/medias/avery_a4_991_677.ott'); |
|
| 413 | - $odf->setImage('barcode', WPS_BARCODE_UPLOAD.$meta.'.png'); |
|
| 414 | - $odf->saveToDisk(WPS_BARCODE_UPLOAD.$meta.'.odt'); |
|
| 411 | + $odf = new Odf(WPS_BARCODE_PATH . 'assets/medias/avery_a4_991_677.ott'); |
|
| 412 | + $odf->setImage('barcode', WPS_BARCODE_UPLOAD . $meta . '.png'); |
|
| 413 | + $odf->saveToDisk(WPS_BARCODE_UPLOAD . $meta . '.odt'); |
|
| 415 | 414 | } catch (Exception $e) { |
| 416 | 415 | echo __('Generation problem', 'wps_barcode'); |
| 417 | 416 | } |
| 418 | 417 | } |
| 419 | 418 | else { |
| 420 | - echo '<p>'.sprintf( __('None bardcode generated as you did create %s.', |
|
| 421 | - 'wps_barcode'), $type).'</p>'; |
|
| 419 | + echo '<p>' . sprintf(__('None bardcode generated as you did create %s.', |
|
| 420 | + 'wps_barcode'), $type) . '</p>'; |
|
| 422 | 421 | } |
| 423 | 422 | } |
| 424 | 423 | |
@@ -434,7 +433,7 @@ discard block |
||
| 434 | 433 | * @param integer $color Color of rectangle |
| 435 | 434 | */ |
| 436 | 435 | private function imgNormalGuard(&$image, $pos, $size, $color) { |
| 437 | - imagefilledrectangle($image, $pos, 180*0.25,$size, 180-10, $color ); |
|
| 436 | + imagefilledrectangle($image, $pos, 180 * 0.25, $size, 180 - 10, $color); |
|
| 438 | 437 | } |
| 439 | 438 | |
| 440 | 439 | /** |
@@ -445,7 +444,7 @@ discard block |
||
| 445 | 444 | * @param integer $color Color of rectangle |
| 446 | 445 | */ |
| 447 | 446 | private function imgSymbole(&$image, $pos, $size, $color) { |
| 448 | - imagefilledrectangle($image, $pos, 180*0.25,$size, 180-40, $color ); |
|
| 447 | + imagefilledrectangle($image, $pos, 180 * 0.25, $size, 180 - 40, $color); |
|
| 449 | 448 | } |
| 450 | 449 | |
| 451 | 450 | } |
@@ -147,7 +147,7 @@ |
||
| 147 | 147 | |
| 148 | 148 | /** |
| 149 | 149 | * get binary code of barcode |
| 150 | - * @return binary code |
|
| 150 | + * @return string code |
|
| 151 | 151 | */ |
| 152 | 152 | public function getBinCode() { |
| 153 | 153 | return $this->binCode; |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * Write line of log |
| 54 | 54 | * @param string $string Line writing |
| 55 | - */ |
|
| 55 | + */ |
|
| 56 | 56 | public function writeLog($string) { |
| 57 | 57 | $this->log .= $string; |
| 58 | 58 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | /** |
| 69 | 69 | * Set generate code for barcode has been generate |
| 70 | 70 | * @param string $code Number code of barcode |
| 71 | - */ |
|
| 71 | + */ |
|
| 72 | 72 | public function setGenerateCode($code) { |
| 73 | 73 | $code = $this->checksum( substr($code, 0, 12) ); |
| 74 | 74 | $this->originalCode = $code; |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | /** |
| 157 | 157 | * Read INI configuration for country generate code |
| 158 | - */ |
|
| 158 | + */ |
|
| 159 | 159 | private function readGencodeIni() { |
| 160 | 160 | $ini = parse_ini_file('assets/config/gencode.ini', true); |
| 161 | 161 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | |
| 173 | 173 | /** |
| 174 | 174 | * Read INI general configuration |
| 175 | - */ |
|
| 175 | + */ |
|
| 176 | 176 | private function readConfigIni() { |
| 177 | 177 | $ini = parse_ini_file('assets/config/config.ini', true); |
| 178 | 178 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | * Cut and parse string for generate code |
| 191 | 191 | * @param string $ctry Country number code |
| 192 | 192 | * @return array String exploding with explode PHP function and parsing |
| 193 | - */ |
|
| 193 | + */ |
|
| 194 | 194 | private function explodingString($ctry) { |
| 195 | 195 | global $count, $gen, $leftRnd; |
| 196 | 196 | |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | * @param string $country International country code |
| 270 | 270 | * @param string $code Type for number code generate (country, distributors...) |
| 271 | 271 | * @return string Number code generate |
| 272 | - */ |
|
| 272 | + */ |
|
| 273 | 273 | private function ean13($country, $code, $ref) { |
| 274 | 274 | global $count, $gen, $leftRnd; |
| 275 | 275 | |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | /** |
| 467 | 467 | * Generate bincode |
| 468 | 468 | * @param string $code Number code generated by normalization function |
| 469 | - */ |
|
| 469 | + */ |
|
| 470 | 470 | public function bin($code) { |
| 471 | 471 | if ($this->binCode === '') { |
| 472 | 472 | $binCode = ''; |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | /** |
| 496 | 496 | * Calcul motif for generate barcode |
| 497 | 497 | * @param string $code Number code generate |
| 498 | - */ |
|
| 498 | + */ |
|
| 499 | 499 | private function motifCalc($code) { |
| 500 | 500 | $start = substr($code, 0, 1); |
| 501 | 501 | switch ($start) { |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | 4 | * Generate barcodes with informations |
@@ -30,17 +30,17 @@ discard block |
||
| 30 | 30 | private $config = array(); |
| 31 | 31 | |
| 32 | 32 | public function __construct() { |
| 33 | - $this->setA = array( 0 => '0001101', 1 => '0011001', 2 => '0010011', |
|
| 34 | - 3 => '0111101', 4 => '0100011', 5 => '0110001', 6 => '0101111', |
|
| 35 | - 7 => '0111011', 8 => '0110111', 9 => '0001011' ); |
|
| 33 | + $this->setA = array(0 => '0001101', 1 => '0011001', 2 => '0010011', |
|
| 34 | + 3 => '0111101', 4 => '0100011', 5 => '0110001', 6 => '0101111', |
|
| 35 | + 7 => '0111011', 8 => '0110111', 9 => '0001011'); |
|
| 36 | 36 | |
| 37 | - $this->setB = array( 0 => '0100111', 1 => '0110011', 2 => '0011011', |
|
| 37 | + $this->setB = array(0 => '0100111', 1 => '0110011', 2 => '0011011', |
|
| 38 | 38 | 3 => '0100001', 4 => '0011101', 5 => '0111001', 6 => '0000101', |
| 39 | - 7 => '0010001', 8 => '0001001', 9 => '0010111' ); |
|
| 39 | + 7 => '0010001', 8 => '0001001', 9 => '0010111'); |
|
| 40 | 40 | |
| 41 | - $this->setC = array( 0 => '1110010', 1 => '1100110', 2 => '1101100', |
|
| 41 | + $this->setC = array(0 => '1110010', 1 => '1100110', 2 => '1101100', |
|
| 42 | 42 | 3 => '1000010', 4 => '1011100', 5 => '1001110', 6 => '1010000', |
| 43 | - 7 => '1000100', 8 => '1001000', 9 => '1110100' ); |
|
| 43 | + 7 => '1000100', 8 => '1001000', 9 => '1110100'); |
|
| 44 | 44 | |
| 45 | 45 | //$this->file = fopen(/logs/ean13.log', 'a'); |
| 46 | 46 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @param string $code Number code of barcode |
| 71 | 71 | */ |
| 72 | 72 | public function setGenerateCode($code) { |
| 73 | - $code = $this->checksum( substr($code, 0, 12) ); |
|
| 73 | + $code = $this->checksum(substr($code, 0, 12)); |
|
| 74 | 74 | $this->originalCode = $code; |
| 75 | 75 | $this->motifCalc($code); |
| 76 | 76 | $this->bin(substr($code, 1)); |
@@ -82,15 +82,15 @@ discard block |
||
| 82 | 82 | * @return string Number code with checksum |
| 83 | 83 | */ |
| 84 | 84 | public static function checksum($code) { |
| 85 | - $leftRnd = str_split( substr($code, 0, 7) ); |
|
| 86 | - $rightRnd = str_split( substr($code, 7) ); |
|
| 85 | + $leftRnd = str_split(substr($code, 0, 7)); |
|
| 86 | + $rightRnd = str_split(substr($code, 7)); |
|
| 87 | 87 | |
| 88 | 88 | /*Generate checksum*/ |
| 89 | - $leftSum = ($leftRnd[1]+$leftRnd[3]+$leftRnd[5]+$rightRnd[0]+$rightRnd[2]+$rightRnd[4])*3; |
|
| 90 | - $rightSum = $leftRnd[0]+$leftRnd[2]+$leftRnd[4]+$leftRnd[6]+$rightRnd[1]+$rightRnd[3]; |
|
| 91 | - $sum = $leftSum+$rightSum; |
|
| 89 | + $leftSum = ($leftRnd[1] + $leftRnd[3] + $leftRnd[5] + $rightRnd[0] + $rightRnd[2] + $rightRnd[4]) * 3; |
|
| 90 | + $rightSum = $leftRnd[0] + $leftRnd[2] + $leftRnd[4] + $leftRnd[6] + $rightRnd[1] + $rightRnd[3]; |
|
| 91 | + $sum = $leftSum + $rightSum; |
|
| 92 | 92 | |
| 93 | - $checksum = (ceil($sum/10)*10)-$sum; |
|
| 93 | + $checksum = (ceil($sum / 10) * 10) - $sum; |
|
| 94 | 94 | $rightRnd[5] = strval($checksum); |
| 95 | 95 | $gencode = implode($leftRnd); |
| 96 | 96 | $gencode .= implode($rightRnd); |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | public function setCountry($code) { |
| 115 | 115 | $this->country = $code; |
| 116 | 116 | |
| 117 | - if ( $this->fixed !== '' ) { |
|
| 117 | + if ($this->fixed !== '') { |
|
| 118 | 118 | $this->fixed .= ';country'; |
| 119 | 119 | } |
| 120 | 120 | else { |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | public function setEnterpriseCode($code) { |
| 130 | 130 | $this->enterprise = $code; |
| 131 | 131 | |
| 132 | - if ( $this->fixed !== '' ) { |
|
| 132 | + if ($this->fixed !== '') { |
|
| 133 | 133 | $this->fixed .= ';enterprise'; |
| 134 | 134 | } |
| 135 | 135 | else { |
@@ -159,13 +159,13 @@ discard block |
||
| 159 | 159 | private function readGencodeIni() { |
| 160 | 160 | $ini = parse_ini_file('assets/config/gencode.ini', true); |
| 161 | 161 | |
| 162 | - if ( array_key_exists("EAN13", $ini) ) { |
|
| 163 | - $pos = array_search( "EAN13", array_keys($ini) ); |
|
| 162 | + if (array_key_exists("EAN13", $ini)) { |
|
| 163 | + $pos = array_search("EAN13", array_keys($ini)); |
|
| 164 | 164 | $this->ean13 = array_slice($ini["EAN13"], 0); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - if ( array_key_exists("OTHEREAN13", $ini) ) { |
|
| 168 | - $pos = array_search( "OTHEREAN13" , array_keys($ini) ); |
|
| 167 | + if (array_key_exists("OTHEREAN13", $ini)) { |
|
| 168 | + $pos = array_search("OTHEREAN13", array_keys($ini)); |
|
| 169 | 169 | $this->other_ean13 = array_slice($ini["OTHEREAN13"], 0); |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -176,8 +176,8 @@ discard block |
||
| 176 | 176 | private function readConfigIni() { |
| 177 | 177 | $ini = parse_ini_file('assets/config/config.ini', true); |
| 178 | 178 | |
| 179 | - if ( array_key_exists("general", $ini) ) { |
|
| 180 | - $pos = array_search( "general", array_keys($ini) ); |
|
| 179 | + if (array_key_exists("general", $ini)) { |
|
| 180 | + $pos = array_search("general", array_keys($ini)); |
|
| 181 | 181 | |
| 182 | 182 | $this->enterprise = $ini["general"]["enteprise"]; |
| 183 | 183 | $this->country = $ini["general"]["country"]; |
@@ -199,12 +199,12 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | /*If minimum two informations*/ |
| 201 | 201 | if ($count > 1) { |
| 202 | - for ($i=0; $i<$count ; $i++) { |
|
| 202 | + for ($i = 0; $i < $count; $i++) { |
|
| 203 | 203 | $pos = strpos($exploding[$i], ":"); |
| 204 | 204 | $gen[$i]["start"] = substr($exploding[$i], 0, $pos); |
| 205 | 205 | |
| 206 | - if ( intval( substr($exploding[$i], $pos) ) < 1 ) { |
|
| 207 | - $gen[$i]["end"] = substr($exploding[$i], $pos+1); |
|
| 206 | + if (intval(substr($exploding[$i], $pos)) < 1) { |
|
| 207 | + $gen[$i]["end"] = substr($exploding[$i], $pos + 1); |
|
| 208 | 208 | } |
| 209 | 209 | else { |
| 210 | 210 | $gen[$i]["end"] = substr($exploding[$i], $pos); |
@@ -215,17 +215,17 @@ discard block |
||
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - $select = mt_rand( 0, count($gen)-1 ); |
|
| 218 | + $select = mt_rand(0, count($gen) - 1); |
|
| 219 | 219 | $g1 = strval($gen[$select]["start"]); |
| 220 | 220 | $g2 = strval($gen[$select]["end"]); |
| 221 | 221 | |
| 222 | - $rand = mt_rand( $g1, $g2 ); |
|
| 222 | + $rand = mt_rand($g1, $g2); |
|
| 223 | 223 | |
| 224 | - if ( $rand >= 10 and $rand < 100 ) { |
|
| 225 | - $strNum = '0'.intval($rand); |
|
| 224 | + if ($rand >= 10 and $rand < 100) { |
|
| 225 | + $strNum = '0' . intval($rand); |
|
| 226 | 226 | } |
| 227 | - else if ( $rand < 10 ) { |
|
| 228 | - $strNum = '00'.intval($rand); |
|
| 227 | + else if ($rand < 10) { |
|
| 228 | + $strNum = '00' . intval($rand); |
|
| 229 | 229 | } |
| 230 | 230 | else { |
| 231 | 231 | $strNum = intval($rand); |
@@ -235,21 +235,21 @@ discard block |
||
| 235 | 235 | $pos = strpos($exploding[0], ":"); |
| 236 | 236 | if ($pos > 0) { |
| 237 | 237 | $gen[0]["start"] = substr($exploding[0], 0, $pos); |
| 238 | - $gen[0]["end"] = substr($exploding[0], $pos+1); |
|
| 238 | + $gen[0]["end"] = substr($exploding[0], $pos + 1); |
|
| 239 | 239 | |
| 240 | - $select = mt_rand( intval($gen[0]["start"]), |
|
| 241 | - intval($gen[0]["end"]) ); |
|
| 240 | + $select = mt_rand(intval($gen[0]["start"]), |
|
| 241 | + intval($gen[0]["end"])); |
|
| 242 | 242 | |
| 243 | 243 | $strNum = strval($select); |
| 244 | 244 | $len = strlen($strNum); |
| 245 | - if ( $len < 3 ) { |
|
| 245 | + if ($len < 3) { |
|
| 246 | 246 | switch ($len) { |
| 247 | 247 | case 1: |
| 248 | - $strNum = '00'.$strNum; |
|
| 248 | + $strNum = '00' . $strNum; |
|
| 249 | 249 | break; |
| 250 | 250 | |
| 251 | 251 | case 2: |
| 252 | - $strNum = '0'.$strNum; |
|
| 252 | + $strNum = '0' . $strNum; |
|
| 253 | 253 | break; |
| 254 | 254 | } |
| 255 | 255 | } |
@@ -258,9 +258,9 @@ discard block |
||
| 258 | 258 | $strNum = strval($exploding[0]); |
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | - $leftRnd[0] = substr( $strNum, 0, 1); |
|
| 262 | - $leftRnd[1] = substr( $strNum, 1, 1); |
|
| 263 | - $leftRnd[2] = substr( $strNum, 2, 1); |
|
| 261 | + $leftRnd[0] = substr($strNum, 0, 1); |
|
| 262 | + $leftRnd[1] = substr($strNum, 1, 1); |
|
| 263 | + $leftRnd[2] = substr($strNum, 2, 1); |
|
| 264 | 264 | return $gen; |
| 265 | 265 | } |
| 266 | 266 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | |
| 280 | 280 | $this->readGencodeIni(); |
| 281 | 281 | |
| 282 | - if ( $this->fixed === '' ) { |
|
| 282 | + if ($this->fixed === '') { |
|
| 283 | 283 | $this->readConfigIni(); |
| 284 | 284 | } |
| 285 | 285 | |
@@ -287,28 +287,28 @@ discard block |
||
| 287 | 287 | $explodingConf = explode(";", $this->fixed); |
| 288 | 288 | |
| 289 | 289 | foreach ($explodingConf as $key => $value) { |
| 290 | - if ( strtolower($value) === "country" ) { |
|
| 290 | + if (strtolower($value) === "country") { |
|
| 291 | 291 | $country = $this->country; |
| 292 | 292 | $code = "country"; |
| 293 | 293 | $countryViaConf = true; |
| 294 | 294 | } |
| 295 | - elseif ( strtolower($value) === "enterprise" ) { |
|
| 295 | + elseif (strtolower($value) === "enterprise") { |
|
| 296 | 296 | $enterpriseViaConf = true; |
| 297 | 297 | } |
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - if ( $countryViaConf === true ) { |
|
| 302 | - if ( $this->countryCode !== '' ) |
|
| 301 | + if ($countryViaConf === true) { |
|
| 302 | + if ($this->countryCode !== '') |
|
| 303 | 303 | { |
| 304 | 304 | $strNum = strval($this->countryCode); |
| 305 | - $leftRnd[0] = substr( $strNum, 0, 1); |
|
| 306 | - $leftRnd[1] = substr( $strNum, 1, 1); |
|
| 307 | - $leftRnd[2] = substr( $strNum, 2, 1); |
|
| 305 | + $leftRnd[0] = substr($strNum, 0, 1); |
|
| 306 | + $leftRnd[1] = substr($strNum, 1, 1); |
|
| 307 | + $leftRnd[2] = substr($strNum, 2, 1); |
|
| 308 | 308 | } |
| 309 | 309 | else { |
| 310 | 310 | |
| 311 | - if ( array_key_exists(strtoupper($country), $this->ean13) ) { |
|
| 311 | + if (array_key_exists(strtoupper($country), $this->ean13)) { |
|
| 312 | 312 | $ctry = $this->ean13[strtoupper($country)]; |
| 313 | 313 | } |
| 314 | 314 | |
@@ -339,17 +339,17 @@ discard block |
||
| 339 | 339 | $this->countryGen($country, $code); |
| 340 | 340 | |
| 341 | 341 | /*Generate left section of gencode*/ |
| 342 | - if ( !isset($leftRnd[2]) ) { |
|
| 342 | + if (!isset($leftRnd[2])) { |
|
| 343 | 343 | $leftRnd[2] = mt_rand(0, 9); |
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - if ( $enterpriseViaConf === true ) { |
|
| 347 | + if ($enterpriseViaConf === true) { |
|
| 348 | 348 | $strNum2 = strval($this->enterprise); |
| 349 | - $leftRnd[3] = substr( $strNum2, 0, 1); |
|
| 350 | - $leftRnd[4] = substr( $strNum2, 1, 1); |
|
| 351 | - $leftRnd[5] = substr( $strNum2, 2, 1); |
|
| 352 | - $leftRnd[6] = substr( $strNum2, 3, 1); |
|
| 349 | + $leftRnd[3] = substr($strNum2, 0, 1); |
|
| 350 | + $leftRnd[4] = substr($strNum2, 1, 1); |
|
| 351 | + $leftRnd[5] = substr($strNum2, 2, 1); |
|
| 352 | + $leftRnd[6] = substr($strNum2, 3, 1); |
|
| 353 | 353 | } |
| 354 | 354 | else { |
| 355 | 355 | $leftRnd[3] = mt_rand(0, 9); |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /*Generate right section of gencode*/ |
| 362 | - switch ( strlen($ref) ) { |
|
| 362 | + switch (strlen($ref)) { |
|
| 363 | 363 | case 0: |
| 364 | 364 | $rightRnd[0] = mt_rand(0, 9); |
| 365 | 365 | $rightRnd[1] = mt_rand(0, 9); |
@@ -380,32 +380,32 @@ discard block |
||
| 380 | 380 | $rightRnd[0] = 0; |
| 381 | 381 | $rightRnd[1] = 0; |
| 382 | 382 | $rightRnd[2] = 0; |
| 383 | - $rightRnd[3] = substr( $ref, 0, 1); |
|
| 384 | - $rightRnd[4] = substr( $ref, 1, 1); |
|
| 383 | + $rightRnd[3] = substr($ref, 0, 1); |
|
| 384 | + $rightRnd[4] = substr($ref, 1, 1); |
|
| 385 | 385 | break; |
| 386 | 386 | |
| 387 | 387 | case 3: |
| 388 | 388 | $rightRnd[0] = 0; |
| 389 | 389 | $rightRnd[1] = 0; |
| 390 | - $rightRnd[2] = substr( $ref, 0, 1); |
|
| 391 | - $rightRnd[3] = substr( $ref, 1, 1); |
|
| 392 | - $rightRnd[4] = substr( $ref, 2, 1); |
|
| 390 | + $rightRnd[2] = substr($ref, 0, 1); |
|
| 391 | + $rightRnd[3] = substr($ref, 1, 1); |
|
| 392 | + $rightRnd[4] = substr($ref, 2, 1); |
|
| 393 | 393 | break; |
| 394 | 394 | |
| 395 | 395 | case 4: |
| 396 | 396 | $rightRnd[0] = 0; |
| 397 | - $rightRnd[1] = substr( $ref, 0, 1); |
|
| 398 | - $rightRnd[2] = substr( $ref, 1, 1); |
|
| 399 | - $rightRnd[3] = substr( $ref, 2, 1); |
|
| 400 | - $rightRnd[4] = substr( $ref, 3, 1); |
|
| 397 | + $rightRnd[1] = substr($ref, 0, 1); |
|
| 398 | + $rightRnd[2] = substr($ref, 1, 1); |
|
| 399 | + $rightRnd[3] = substr($ref, 2, 1); |
|
| 400 | + $rightRnd[4] = substr($ref, 3, 1); |
|
| 401 | 401 | break; |
| 402 | 402 | |
| 403 | 403 | case 5: |
| 404 | - $rightRnd[0] = substr( $ref, 0, 1); |
|
| 405 | - $rightRnd[1] = substr( $ref, 1, 1); |
|
| 406 | - $rightRnd[2] = substr( $ref, 2, 1); |
|
| 407 | - $rightRnd[3] = substr( $ref, 3, 1); |
|
| 408 | - $rightRnd[4] = substr( $ref, 4, 1); |
|
| 404 | + $rightRnd[0] = substr($ref, 0, 1); |
|
| 405 | + $rightRnd[1] = substr($ref, 1, 1); |
|
| 406 | + $rightRnd[2] = substr($ref, 2, 1); |
|
| 407 | + $rightRnd[3] = substr($ref, 3, 1); |
|
| 408 | + $rightRnd[4] = substr($ref, 4, 1); |
|
| 409 | 409 | break; |
| 410 | 410 | |
| 411 | 411 | default: |
@@ -443,8 +443,8 @@ discard block |
||
| 443 | 443 | */ |
| 444 | 444 | public function countryGen($country, $code) { |
| 445 | 445 | /*Generation for country selection*/ |
| 446 | - if ( !empty($country) && $code == 'country' ) { |
|
| 447 | - if ( array_key_exists(strtoupper($country), $this->ean13) ) { |
|
| 446 | + if (!empty($country) && $code == 'country') { |
|
| 447 | + if (array_key_exists(strtoupper($country), $this->ean13)) { |
|
| 448 | 448 | $ctry = $this->ean13[strtoupper($country)]; |
| 449 | 449 | $gen = $this->explodingString($ctry); |
| 450 | 450 | } |
@@ -453,8 +453,8 @@ discard block |
||
| 453 | 453 | if ($code == 'distrib' or $code == 'weight' or |
| 454 | 454 | $code == 'interne' or $code == 'coupons' or |
| 455 | 455 | $code == 'issn' or $code == 'isbn') { |
| 456 | - if ( !empty($this->other_ean13) ) { |
|
| 457 | - if ( array_key_exists($code, $this->other_ean13) ) { |
|
| 456 | + if (!empty($this->other_ean13)) { |
|
| 457 | + if (array_key_exists($code, $this->other_ean13)) { |
|
| 458 | 458 | |
| 459 | 459 | $gen = $this->explodingString($this->other_ean13[$code]); |
| 460 | 460 | } |
@@ -471,23 +471,23 @@ discard block |
||
| 471 | 471 | if ($this->binCode === '') { |
| 472 | 472 | $binCode = ''; |
| 473 | 473 | /*Generate left bincode*/ |
| 474 | - for ($i=0; $i<6 ; $i++) { |
|
| 475 | - if( substr($this->motif, $i, 1) === 'A' ) { |
|
| 474 | + for ($i = 0; $i < 6; $i++) { |
|
| 475 | + if (substr($this->motif, $i, 1) === 'A') { |
|
| 476 | 476 | $binCode .= $this->setA[substr($code, $i, 1)]; |
| 477 | 477 | } |
| 478 | - else if ( substr($this->motif, $i, 1) === 'B' ) { |
|
| 478 | + else if (substr($this->motif, $i, 1) === 'B') { |
|
| 479 | 479 | $binCode .= $this->setB[substr($code, $i, 1)]; |
| 480 | 480 | } |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /*Generate right bincode*/ |
| 484 | - for ($i=6; $i<12 ; $i++) { |
|
| 484 | + for ($i = 6; $i < 12; $i++) { |
|
| 485 | 485 | $binCode .= $this->setC[substr($code, $i, 1)]; |
| 486 | 486 | } |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - $this->writeLog( sprintf( __("Bincode generate: %s <br />", 'wps_barcode'), |
|
| 490 | - '<b>'.$binCode.'</b>') ); |
|
| 489 | + $this->writeLog(sprintf(__("Bincode generate: %s <br />", 'wps_barcode'), |
|
| 490 | + '<b>' . $binCode . '</b>')); |
|
| 491 | 491 | |
| 492 | 492 | $this->binCode = $binCode; |
| 493 | 493 | } |
@@ -540,8 +540,8 @@ discard block |
||
| 540 | 540 | break; |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - $this->writeLog( sprintf( __("Motif: %s<br />", 'wps_barcode'), |
|
| 544 | - $this->motif) ); |
|
| 543 | + $this->writeLog(sprintf(__("Motif: %s<br />", 'wps_barcode'), |
|
| 544 | + $this->motif)); |
|
| 545 | 545 | } |
| 546 | 546 | } |
| 547 | 547 | |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | |
| 3 | 5 | /** |
| 4 | 6 | * Generate barcodes with informations |
@@ -116,8 +118,7 @@ discard block |
||
| 116 | 118 | |
| 117 | 119 | if ( $this->fixed !== '' ) { |
| 118 | 120 | $this->fixed .= ';country'; |
| 119 | - } |
|
| 120 | - else { |
|
| 121 | + } else { |
|
| 121 | 122 | $this->fixed .= 'country'; |
| 122 | 123 | } |
| 123 | 124 | } |
@@ -131,8 +132,7 @@ discard block |
||
| 131 | 132 | |
| 132 | 133 | if ( $this->fixed !== '' ) { |
| 133 | 134 | $this->fixed .= ';enterprise'; |
| 134 | - } |
|
| 135 | - else { |
|
| 135 | + } else { |
|
| 136 | 136 | $this->fixed .= 'enterprise'; |
| 137 | 137 | } |
| 138 | 138 | } |
@@ -205,8 +205,7 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | if ( intval( substr($exploding[$i], $pos) ) < 1 ) { |
| 207 | 207 | $gen[$i]["end"] = substr($exploding[$i], $pos+1); |
| 208 | - } |
|
| 209 | - else { |
|
| 208 | + } else { |
|
| 210 | 209 | $gen[$i]["end"] = substr($exploding[$i], $pos); |
| 211 | 210 | } |
| 212 | 211 | |
@@ -223,15 +222,12 @@ discard block |
||
| 223 | 222 | |
| 224 | 223 | if ( $rand >= 10 and $rand < 100 ) { |
| 225 | 224 | $strNum = '0'.intval($rand); |
| 226 | - } |
|
| 227 | - else if ( $rand < 10 ) { |
|
| 225 | + } else if ( $rand < 10 ) { |
|
| 228 | 226 | $strNum = '00'.intval($rand); |
| 229 | - } |
|
| 230 | - else { |
|
| 227 | + } else { |
|
| 231 | 228 | $strNum = intval($rand); |
| 232 | 229 | } |
| 233 | - } |
|
| 234 | - else { |
|
| 230 | + } else { |
|
| 235 | 231 | $pos = strpos($exploding[0], ":"); |
| 236 | 232 | if ($pos > 0) { |
| 237 | 233 | $gen[0]["start"] = substr($exploding[0], 0, $pos); |
@@ -253,8 +249,7 @@ discard block |
||
| 253 | 249 | break; |
| 254 | 250 | } |
| 255 | 251 | } |
| 256 | - } |
|
| 257 | - else { |
|
| 252 | + } else { |
|
| 258 | 253 | $strNum = strval($exploding[0]); |
| 259 | 254 | } |
| 260 | 255 | } |
@@ -291,8 +286,7 @@ discard block |
||
| 291 | 286 | $country = $this->country; |
| 292 | 287 | $code = "country"; |
| 293 | 288 | $countryViaConf = true; |
| 294 | - } |
|
| 295 | - elseif ( strtolower($value) === "enterprise" ) { |
|
| 289 | + } elseif ( strtolower($value) === "enterprise" ) { |
|
| 296 | 290 | $enterpriseViaConf = true; |
| 297 | 291 | } |
| 298 | 292 | } |
@@ -305,8 +299,7 @@ discard block |
||
| 305 | 299 | $leftRnd[0] = substr( $strNum, 0, 1); |
| 306 | 300 | $leftRnd[1] = substr( $strNum, 1, 1); |
| 307 | 301 | $leftRnd[2] = substr( $strNum, 2, 1); |
| 308 | - } |
|
| 309 | - else { |
|
| 302 | + } else { |
|
| 310 | 303 | |
| 311 | 304 | if ( array_key_exists(strtoupper($country), $this->ean13) ) { |
| 312 | 305 | $ctry = $this->ean13[strtoupper($country)]; |
@@ -314,8 +307,7 @@ discard block |
||
| 314 | 307 | |
| 315 | 308 | $gen = $this->explodingString($ctry); |
| 316 | 309 | } |
| 317 | - } |
|
| 318 | - else { |
|
| 310 | + } else { |
|
| 319 | 311 | /*Generation for country selection*/ |
| 320 | 312 | /*if ( !empty($country) && $code == 'country' ) { |
| 321 | 313 | if ( array_key_exists(strtoupper($country), $this->ean13) ) { |
@@ -350,8 +342,7 @@ discard block |
||
| 350 | 342 | $leftRnd[4] = substr( $strNum2, 1, 1); |
| 351 | 343 | $leftRnd[5] = substr( $strNum2, 2, 1); |
| 352 | 344 | $leftRnd[6] = substr( $strNum2, 3, 1); |
| 353 | - } |
|
| 354 | - else { |
|
| 345 | + } else { |
|
| 355 | 346 | $leftRnd[3] = mt_rand(0, 9); |
| 356 | 347 | $leftRnd[4] = mt_rand(0, 9); |
| 357 | 348 | $leftRnd[5] = mt_rand(0, 9); |
@@ -426,8 +417,7 @@ discard block |
||
| 426 | 417 | foreach ($rightRnd as $key => $value) { |
| 427 | 418 | $codeForChecksum .= $value; |
| 428 | 419 | } |
| 429 | - } |
|
| 430 | - else { |
|
| 420 | + } else { |
|
| 431 | 421 | $codeForChecksum = $this->originalCode; |
| 432 | 422 | } |
| 433 | 423 | |
@@ -448,8 +438,7 @@ discard block |
||
| 448 | 438 | $ctry = $this->ean13[strtoupper($country)]; |
| 449 | 439 | $gen = $this->explodingString($ctry); |
| 450 | 440 | } |
| 451 | - } |
|
| 452 | - else { |
|
| 441 | + } else { |
|
| 453 | 442 | if ($code == 'distrib' or $code == 'weight' or |
| 454 | 443 | $code == 'interne' or $code == 'coupons' or |
| 455 | 444 | $code == 'issn' or $code == 'isbn') { |
@@ -474,8 +463,7 @@ discard block |
||
| 474 | 463 | for ($i=0; $i<6 ; $i++) { |
| 475 | 464 | if( substr($this->motif, $i, 1) === 'A' ) { |
| 476 | 465 | $binCode .= $this->setA[substr($code, $i, 1)]; |
| 477 | - } |
|
| 478 | - else if ( substr($this->motif, $i, 1) === 'B' ) { |
|
| 466 | + } else if ( substr($this->motif, $i, 1) === 'B' ) { |
|
| 479 | 467 | $binCode .= $this->setB[substr($code, $i, 1)]; |
| 480 | 468 | } |
| 481 | 469 | } |
@@ -212,6 +212,10 @@ discard block |
||
| 212 | 212 | // Note that no real action is taken, if the archive does not exist it is not |
| 213 | 213 | // created. Use create() for that. |
| 214 | 214 | // -------------------------------------------------------------------------------- |
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * @param string $p_zipname |
|
| 218 | + */ |
|
| 215 | 219 | function PclZip($p_zipname) |
| 216 | 220 | { |
| 217 | 221 | |
@@ -220,6 +224,10 @@ discard block |
||
| 220 | 224 | { |
| 221 | 225 | if (!function_exists('gzopen') |
| 222 | 226 | && function_exists('gzopen64')) { |
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @param string $filename |
|
| 230 | + */ |
|
| 223 | 231 | function gzopen($filename , $mode = 'r', $use_include_path = 0 ) |
| 224 | 232 | { |
| 225 | 233 | return gzopen64($filename , $mode, $use_include_path); |
@@ -457,6 +465,10 @@ discard block |
||
| 457 | 465 | // The list of the added files, with a status of the add action. |
| 458 | 466 | // (see PclZip::listContent() for list entry format) |
| 459 | 467 | // -------------------------------------------------------------------------------- |
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * @param string $p_filelist |
|
| 471 | + */ |
|
| 460 | 472 | function add($p_filelist) |
| 461 | 473 | { |
| 462 | 474 | $v_result=1; |
@@ -2341,6 +2353,10 @@ discard block |
||
| 2341 | 2353 | // Description : |
| 2342 | 2354 | // Parameters : |
| 2343 | 2355 | // -------------------------------------------------------------------------------- |
| 2356 | + |
|
| 2357 | + /** |
|
| 2358 | + * @param string $p_mode |
|
| 2359 | + */ |
|
| 2344 | 2360 | function privOpenFd($p_mode) |
| 2345 | 2361 | { |
| 2346 | 2362 | $v_result=1; |
@@ -4157,6 +4173,10 @@ discard block |
||
| 4157 | 4173 | // Parameters : |
| 4158 | 4174 | // Return Values : |
| 4159 | 4175 | // -------------------------------------------------------------------------------- |
| 4176 | + |
|
| 4177 | + /** |
|
| 4178 | + * @param string $p_string |
|
| 4179 | + */ |
|
| 4160 | 4180 | function privExtractFileAsString(&$p_entry, &$p_string, &$p_options) |
| 4161 | 4181 | { |
| 4162 | 4182 | $v_result=1; |
@@ -5050,6 +5070,10 @@ discard block |
||
| 5050 | 5070 | // Parameters : |
| 5051 | 5071 | // Return Values : |
| 5052 | 5072 | // -------------------------------------------------------------------------------- |
| 5073 | + |
|
| 5074 | + /** |
|
| 5075 | + * @param PclZip $p_archive_to_add |
|
| 5076 | + */ |
|
| 5053 | 5077 | function privMerge(&$p_archive_to_add) |
| 5054 | 5078 | { |
| 5055 | 5079 | $v_result=1; |
@@ -5557,6 +5581,11 @@ discard block |
||
| 5557 | 5581 | // 3 : src & dest gzip |
| 5558 | 5582 | // Return Values : |
| 5559 | 5583 | // -------------------------------------------------------------------------------- |
| 5584 | + |
|
| 5585 | + /** |
|
| 5586 | + * @param integer $p_src |
|
| 5587 | + * @param integer $p_dest |
|
| 5588 | + */ |
|
| 5560 | 5589 | function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) |
| 5561 | 5590 | { |
| 5562 | 5591 | $v_result = 1; |
@@ -5619,6 +5648,11 @@ discard block |
||
| 5619 | 5648 | // Return Values : |
| 5620 | 5649 | // 1 on success, 0 on failure. |
| 5621 | 5650 | // -------------------------------------------------------------------------------- |
| 5651 | + |
|
| 5652 | + /** |
|
| 5653 | + * @param string $p_src |
|
| 5654 | + * @param string $p_dest |
|
| 5655 | + */ |
|
| 5622 | 5656 | function PclZipUtilRename($p_src, $p_dest) |
| 5623 | 5657 | { |
| 5624 | 5658 | $v_result = 1; |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | // ----- Constants |
| 29 | 29 | if (!defined('PCLZIP_READ_BLOCK_SIZE')) { |
| 30 | - define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); |
|
| 30 | + define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | // ----- File list separator |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | //define( 'PCLZIP_SEPARATOR', ' ' ); |
| 42 | 42 | // Recommanded values for smart separation of filenames. |
| 43 | 43 | if (!defined('PCLZIP_SEPARATOR')) { |
| 44 | - define( 'PCLZIP_SEPARATOR', ',' ); |
|
| 44 | + define( 'PCLZIP_SEPARATOR', ',' ); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // ----- Error configuration |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | // you must ensure that you have included PclError library. |
| 51 | 51 | // [2,...] : reserved for futur use |
| 52 | 52 | if (!defined('PCLZIP_ERROR_EXTERNAL')) { |
| 53 | - define( 'PCLZIP_ERROR_EXTERNAL', 0 ); |
|
| 53 | + define( 'PCLZIP_ERROR_EXTERNAL', 0 ); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // ----- Optional static temporary directory |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' ); |
| 64 | 64 | // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' ); |
| 65 | 65 | if (!defined('PCLZIP_TEMPORARY_DIR')) { |
| 66 | - define( 'PCLZIP_TEMPORARY_DIR', '' ); |
|
| 66 | + define( 'PCLZIP_TEMPORARY_DIR', '' ); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | // ----- Optional threshold ratio for use of temporary files |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | // Samples : |
| 76 | 76 | // define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 ); |
| 77 | 77 | if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) { |
| 78 | - define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 ); |
|
| 78 | + define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 ); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // -------------------------------------------------------------------------------- |
@@ -189,20 +189,20 @@ discard block |
||
| 189 | 189 | // -------------------------------------------------------------------------------- |
| 190 | 190 | class PclZip |
| 191 | 191 | { |
| 192 | - // ----- Filename of the zip file |
|
| 193 | - var $zipname = ''; |
|
| 192 | + // ----- Filename of the zip file |
|
| 193 | + var $zipname = ''; |
|
| 194 | 194 | |
| 195 | - // ----- File descriptor of the zip file |
|
| 196 | - var $zip_fd = 0; |
|
| 195 | + // ----- File descriptor of the zip file |
|
| 196 | + var $zip_fd = 0; |
|
| 197 | 197 | |
| 198 | - // ----- Internal error handling |
|
| 199 | - var $error_code = 1; |
|
| 200 | - var $error_string = ''; |
|
| 198 | + // ----- Internal error handling |
|
| 199 | + var $error_code = 1; |
|
| 200 | + var $error_string = ''; |
|
| 201 | 201 | |
| 202 | - // ----- Current status of the magic_quotes_runtime |
|
| 203 | - // This value store the php configuration for magic_quotes |
|
| 204 | - // The class can then disable the magic_quotes and reset it after |
|
| 205 | - var $magic_quotes_status; |
|
| 202 | + // ----- Current status of the magic_quotes_runtime |
|
| 203 | + // This value store the php configuration for magic_quotes |
|
| 204 | + // The class can then disable the magic_quotes and reset it after |
|
| 205 | + var $magic_quotes_status; |
|
| 206 | 206 | |
| 207 | 207 | // -------------------------------------------------------------------------------- |
| 208 | 208 | // Function : PclZip() |
@@ -215,25 +215,25 @@ discard block |
||
| 215 | 215 | function PclZip($p_zipname) |
| 216 | 216 | { |
| 217 | 217 | |
| 218 | - // ----- Tests the zlib |
|
| 219 | - if (!function_exists('gzopen')) |
|
| 220 | - { |
|
| 221 | - if (!function_exists('gzopen') |
|
| 222 | - && function_exists('gzopen64')) { |
|
| 223 | - function gzopen($filename , $mode = 'r', $use_include_path = 0 ) |
|
| 224 | - { |
|
| 225 | - return gzopen64($filename , $mode, $use_include_path); |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - } |
|
| 218 | + // ----- Tests the zlib |
|
| 219 | + if (!function_exists('gzopen')) |
|
| 220 | + { |
|
| 221 | + if (!function_exists('gzopen') |
|
| 222 | + && function_exists('gzopen64')) { |
|
| 223 | + function gzopen($filename , $mode = 'r', $use_include_path = 0 ) |
|
| 224 | + { |
|
| 225 | + return gzopen64($filename , $mode, $use_include_path); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - // ----- Set the attributes |
|
| 231 | - $this->zipname = $p_zipname; |
|
| 232 | - $this->zip_fd = 0; |
|
| 233 | - $this->magic_quotes_status = -1; |
|
| 230 | + // ----- Set the attributes |
|
| 231 | + $this->zipname = $p_zipname; |
|
| 232 | + $this->zip_fd = 0; |
|
| 233 | + $this->magic_quotes_status = -1; |
|
| 234 | 234 | |
| 235 | - // ----- Return |
|
| 236 | - return; |
|
| 235 | + // ----- Return |
|
| 236 | + return; |
|
| 237 | 237 | } |
| 238 | 238 | // -------------------------------------------------------------------------------- |
| 239 | 239 | |
@@ -276,149 +276,149 @@ discard block |
||
| 276 | 276 | // -------------------------------------------------------------------------------- |
| 277 | 277 | function create($p_filelist) |
| 278 | 278 | { |
| 279 | - $v_result=1; |
|
| 280 | - |
|
| 281 | - // ----- Reset the error handler |
|
| 282 | - $this->privErrorReset(); |
|
| 283 | - |
|
| 284 | - // ----- Set default values |
|
| 285 | - $v_options = array(); |
|
| 286 | - $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; |
|
| 287 | - |
|
| 288 | - // ----- Look for variable options arguments |
|
| 289 | - $v_size = func_num_args(); |
|
| 290 | - |
|
| 291 | - // ----- Look for arguments |
|
| 292 | - if ($v_size > 1) { |
|
| 293 | - // ----- Get the arguments |
|
| 294 | - $v_arg_list = func_get_args(); |
|
| 295 | - |
|
| 296 | - // ----- Remove from the options list the first argument |
|
| 297 | - array_shift($v_arg_list); |
|
| 298 | - $v_size--; |
|
| 299 | - |
|
| 300 | - // ----- Look for first arg |
|
| 301 | - if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 302 | - |
|
| 303 | - // ----- Parse the options |
|
| 304 | - $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
|
| 305 | - array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 306 | - PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 307 | - PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 308 | - PCLZIP_CB_PRE_ADD => 'optional', |
|
| 309 | - PCLZIP_CB_POST_ADD => 'optional', |
|
| 310 | - PCLZIP_OPT_NO_COMPRESSION => 'optional', |
|
| 311 | - PCLZIP_OPT_COMMENT => 'optional', |
|
| 312 | - PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 313 | - PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 314 | - PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 315 | - //, PCLZIP_OPT_CRYPT => 'optional' |
|
| 316 | - )); |
|
| 317 | - if ($v_result != 1) { |
|
| 318 | - return 0; |
|
| 319 | - } |
|
| 320 | - } |
|
| 279 | + $v_result=1; |
|
| 280 | + |
|
| 281 | + // ----- Reset the error handler |
|
| 282 | + $this->privErrorReset(); |
|
| 283 | + |
|
| 284 | + // ----- Set default values |
|
| 285 | + $v_options = array(); |
|
| 286 | + $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; |
|
| 287 | + |
|
| 288 | + // ----- Look for variable options arguments |
|
| 289 | + $v_size = func_num_args(); |
|
| 290 | + |
|
| 291 | + // ----- Look for arguments |
|
| 292 | + if ($v_size > 1) { |
|
| 293 | + // ----- Get the arguments |
|
| 294 | + $v_arg_list = func_get_args(); |
|
| 295 | + |
|
| 296 | + // ----- Remove from the options list the first argument |
|
| 297 | + array_shift($v_arg_list); |
|
| 298 | + $v_size--; |
|
| 299 | + |
|
| 300 | + // ----- Look for first arg |
|
| 301 | + if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 302 | + |
|
| 303 | + // ----- Parse the options |
|
| 304 | + $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
|
| 305 | + array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 306 | + PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 307 | + PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 308 | + PCLZIP_CB_PRE_ADD => 'optional', |
|
| 309 | + PCLZIP_CB_POST_ADD => 'optional', |
|
| 310 | + PCLZIP_OPT_NO_COMPRESSION => 'optional', |
|
| 311 | + PCLZIP_OPT_COMMENT => 'optional', |
|
| 312 | + PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 313 | + PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 314 | + PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 315 | + //, PCLZIP_OPT_CRYPT => 'optional' |
|
| 316 | + )); |
|
| 317 | + if ($v_result != 1) { |
|
| 318 | + return 0; |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - // ----- Look for 2 args |
|
| 323 | - // Here we need to support the first historic synopsis of the |
|
| 324 | - // method. |
|
| 325 | - else { |
|
| 326 | - |
|
| 327 | - // ----- Get the first argument |
|
| 328 | - $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0]; |
|
| 329 | - |
|
| 330 | - // ----- Look for the optional second argument |
|
| 331 | - if ($v_size == 2) { |
|
| 332 | - $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
|
| 333 | - } |
|
| 334 | - else if ($v_size > 2) { |
|
| 335 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
|
| 336 | - "Invalid number / type of arguments"); |
|
| 337 | - return 0; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } |
|
| 322 | + // ----- Look for 2 args |
|
| 323 | + // Here we need to support the first historic synopsis of the |
|
| 324 | + // method. |
|
| 325 | + else { |
|
| 326 | + |
|
| 327 | + // ----- Get the first argument |
|
| 328 | + $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0]; |
|
| 329 | + |
|
| 330 | + // ----- Look for the optional second argument |
|
| 331 | + if ($v_size == 2) { |
|
| 332 | + $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
|
| 333 | + } |
|
| 334 | + else if ($v_size > 2) { |
|
| 335 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
|
| 336 | + "Invalid number / type of arguments"); |
|
| 337 | + return 0; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - // ----- Look for default option values |
|
| 343 | - $this->privOptionDefaultThreshold($v_options); |
|
| 344 | - |
|
| 345 | - // ----- Init |
|
| 346 | - $v_string_list = array(); |
|
| 347 | - $v_att_list = array(); |
|
| 348 | - $v_filedescr_list = array(); |
|
| 349 | - $p_result_list = array(); |
|
| 342 | + // ----- Look for default option values |
|
| 343 | + $this->privOptionDefaultThreshold($v_options); |
|
| 344 | + |
|
| 345 | + // ----- Init |
|
| 346 | + $v_string_list = array(); |
|
| 347 | + $v_att_list = array(); |
|
| 348 | + $v_filedescr_list = array(); |
|
| 349 | + $p_result_list = array(); |
|
| 350 | 350 | |
| 351 | - // ----- Look if the $p_filelist is really an array |
|
| 352 | - if (is_array($p_filelist)) { |
|
| 351 | + // ----- Look if the $p_filelist is really an array |
|
| 352 | + if (is_array($p_filelist)) { |
|
| 353 | 353 | |
| 354 | - // ----- Look if the first element is also an array |
|
| 355 | - // This will mean that this is a file description entry |
|
| 356 | - if (isset($p_filelist[0]) && is_array($p_filelist[0])) { |
|
| 357 | - $v_att_list = $p_filelist; |
|
| 358 | - } |
|
| 354 | + // ----- Look if the first element is also an array |
|
| 355 | + // This will mean that this is a file description entry |
|
| 356 | + if (isset($p_filelist[0]) && is_array($p_filelist[0])) { |
|
| 357 | + $v_att_list = $p_filelist; |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | - // ----- The list is a list of string names |
|
| 361 | - else { |
|
| 362 | - $v_string_list = $p_filelist; |
|
| 363 | - } |
|
| 364 | - } |
|
| 360 | + // ----- The list is a list of string names |
|
| 361 | + else { |
|
| 362 | + $v_string_list = $p_filelist; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | - // ----- Look if the $p_filelist is a string |
|
| 367 | - else if (is_string($p_filelist)) { |
|
| 368 | - // ----- Create a list from the string |
|
| 369 | - $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); |
|
| 370 | - } |
|
| 366 | + // ----- Look if the $p_filelist is a string |
|
| 367 | + else if (is_string($p_filelist)) { |
|
| 368 | + // ----- Create a list from the string |
|
| 369 | + $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | - // ----- Invalid variable type for $p_filelist |
|
| 373 | - else { |
|
| 374 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); |
|
| 375 | - return 0; |
|
| 376 | - } |
|
| 372 | + // ----- Invalid variable type for $p_filelist |
|
| 373 | + else { |
|
| 374 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); |
|
| 375 | + return 0; |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | - // ----- Reformat the string list |
|
| 379 | - if (sizeof($v_string_list) != 0) { |
|
| 380 | - foreach ($v_string_list as $v_string) { |
|
| 381 | - if ($v_string != '') { |
|
| 382 | - $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; |
|
| 383 | - } |
|
| 384 | - else { |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - } |
|
| 378 | + // ----- Reformat the string list |
|
| 379 | + if (sizeof($v_string_list) != 0) { |
|
| 380 | + foreach ($v_string_list as $v_string) { |
|
| 381 | + if ($v_string != '') { |
|
| 382 | + $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; |
|
| 383 | + } |
|
| 384 | + else { |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | 388 | |
| 389 | - // ----- For each file in the list check the attributes |
|
| 390 | - $v_supported_attributes |
|
| 391 | - = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' |
|
| 392 | - ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
|
| 393 | - ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
|
| 394 | - ,PCLZIP_ATT_FILE_MTIME => 'optional' |
|
| 395 | - ,PCLZIP_ATT_FILE_CONTENT => 'optional' |
|
| 396 | - ,PCLZIP_ATT_FILE_COMMENT => 'optional' |
|
| 389 | + // ----- For each file in the list check the attributes |
|
| 390 | + $v_supported_attributes |
|
| 391 | + = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' |
|
| 392 | + ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
|
| 393 | + ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
|
| 394 | + ,PCLZIP_ATT_FILE_MTIME => 'optional' |
|
| 395 | + ,PCLZIP_ATT_FILE_CONTENT => 'optional' |
|
| 396 | + ,PCLZIP_ATT_FILE_COMMENT => 'optional' |
|
| 397 | 397 | ); |
| 398 | - foreach ($v_att_list as $v_entry) { |
|
| 399 | - $v_result = $this->privFileDescrParseAtt($v_entry, |
|
| 400 | - $v_filedescr_list[], |
|
| 401 | - $v_options, |
|
| 402 | - $v_supported_attributes); |
|
| 403 | - if ($v_result != 1) { |
|
| 404 | - return 0; |
|
| 405 | - } |
|
| 406 | - } |
|
| 398 | + foreach ($v_att_list as $v_entry) { |
|
| 399 | + $v_result = $this->privFileDescrParseAtt($v_entry, |
|
| 400 | + $v_filedescr_list[], |
|
| 401 | + $v_options, |
|
| 402 | + $v_supported_attributes); |
|
| 403 | + if ($v_result != 1) { |
|
| 404 | + return 0; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | 407 | |
| 408 | - // ----- Expand the filelist (expand directories) |
|
| 409 | - $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); |
|
| 410 | - if ($v_result != 1) { |
|
| 411 | - return 0; |
|
| 412 | - } |
|
| 408 | + // ----- Expand the filelist (expand directories) |
|
| 409 | + $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); |
|
| 410 | + if ($v_result != 1) { |
|
| 411 | + return 0; |
|
| 412 | + } |
|
| 413 | 413 | |
| 414 | - // ----- Call the create fct |
|
| 415 | - $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options); |
|
| 416 | - if ($v_result != 1) { |
|
| 417 | - return 0; |
|
| 418 | - } |
|
| 414 | + // ----- Call the create fct |
|
| 415 | + $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options); |
|
| 416 | + if ($v_result != 1) { |
|
| 417 | + return 0; |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | - // ----- Return |
|
| 421 | - return $p_result_list; |
|
| 420 | + // ----- Return |
|
| 421 | + return $p_result_list; |
|
| 422 | 422 | } |
| 423 | 423 | // -------------------------------------------------------------------------------- |
| 424 | 424 | |
@@ -459,149 +459,149 @@ discard block |
||
| 459 | 459 | // -------------------------------------------------------------------------------- |
| 460 | 460 | function add($p_filelist) |
| 461 | 461 | { |
| 462 | - $v_result=1; |
|
| 463 | - |
|
| 464 | - // ----- Reset the error handler |
|
| 465 | - $this->privErrorReset(); |
|
| 466 | - |
|
| 467 | - // ----- Set default values |
|
| 468 | - $v_options = array(); |
|
| 469 | - $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; |
|
| 470 | - |
|
| 471 | - // ----- Look for variable options arguments |
|
| 472 | - $v_size = func_num_args(); |
|
| 473 | - |
|
| 474 | - // ----- Look for arguments |
|
| 475 | - if ($v_size > 1) { |
|
| 476 | - // ----- Get the arguments |
|
| 477 | - $v_arg_list = func_get_args(); |
|
| 478 | - |
|
| 479 | - // ----- Remove form the options list the first argument |
|
| 480 | - array_shift($v_arg_list); |
|
| 481 | - $v_size--; |
|
| 482 | - |
|
| 483 | - // ----- Look for first arg |
|
| 484 | - if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 485 | - |
|
| 486 | - // ----- Parse the options |
|
| 487 | - $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
|
| 488 | - array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 489 | - PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 490 | - PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 491 | - PCLZIP_CB_PRE_ADD => 'optional', |
|
| 492 | - PCLZIP_CB_POST_ADD => 'optional', |
|
| 493 | - PCLZIP_OPT_NO_COMPRESSION => 'optional', |
|
| 494 | - PCLZIP_OPT_COMMENT => 'optional', |
|
| 495 | - PCLZIP_OPT_ADD_COMMENT => 'optional', |
|
| 496 | - PCLZIP_OPT_PREPEND_COMMENT => 'optional', |
|
| 497 | - PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 498 | - PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 499 | - PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 500 | - //, PCLZIP_OPT_CRYPT => 'optional' |
|
| 462 | + $v_result=1; |
|
| 463 | + |
|
| 464 | + // ----- Reset the error handler |
|
| 465 | + $this->privErrorReset(); |
|
| 466 | + |
|
| 467 | + // ----- Set default values |
|
| 468 | + $v_options = array(); |
|
| 469 | + $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; |
|
| 470 | + |
|
| 471 | + // ----- Look for variable options arguments |
|
| 472 | + $v_size = func_num_args(); |
|
| 473 | + |
|
| 474 | + // ----- Look for arguments |
|
| 475 | + if ($v_size > 1) { |
|
| 476 | + // ----- Get the arguments |
|
| 477 | + $v_arg_list = func_get_args(); |
|
| 478 | + |
|
| 479 | + // ----- Remove form the options list the first argument |
|
| 480 | + array_shift($v_arg_list); |
|
| 481 | + $v_size--; |
|
| 482 | + |
|
| 483 | + // ----- Look for first arg |
|
| 484 | + if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 485 | + |
|
| 486 | + // ----- Parse the options |
|
| 487 | + $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
|
| 488 | + array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 489 | + PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 490 | + PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 491 | + PCLZIP_CB_PRE_ADD => 'optional', |
|
| 492 | + PCLZIP_CB_POST_ADD => 'optional', |
|
| 493 | + PCLZIP_OPT_NO_COMPRESSION => 'optional', |
|
| 494 | + PCLZIP_OPT_COMMENT => 'optional', |
|
| 495 | + PCLZIP_OPT_ADD_COMMENT => 'optional', |
|
| 496 | + PCLZIP_OPT_PREPEND_COMMENT => 'optional', |
|
| 497 | + PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 498 | + PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 499 | + PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 500 | + //, PCLZIP_OPT_CRYPT => 'optional' |
|
| 501 | 501 | )); |
| 502 | - if ($v_result != 1) { |
|
| 503 | - return 0; |
|
| 504 | - } |
|
| 505 | - } |
|
| 502 | + if ($v_result != 1) { |
|
| 503 | + return 0; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | 506 | |
| 507 | - // ----- Look for 2 args |
|
| 508 | - // Here we need to support the first historic synopsis of the |
|
| 509 | - // method. |
|
| 510 | - else { |
|
| 511 | - |
|
| 512 | - // ----- Get the first argument |
|
| 513 | - $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0]; |
|
| 514 | - |
|
| 515 | - // ----- Look for the optional second argument |
|
| 516 | - if ($v_size == 2) { |
|
| 517 | - $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
|
| 518 | - } |
|
| 519 | - else if ($v_size > 2) { |
|
| 520 | - // ----- Error log |
|
| 521 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
|
| 522 | - |
|
| 523 | - // ----- Return |
|
| 524 | - return 0; |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - } |
|
| 507 | + // ----- Look for 2 args |
|
| 508 | + // Here we need to support the first historic synopsis of the |
|
| 509 | + // method. |
|
| 510 | + else { |
|
| 511 | + |
|
| 512 | + // ----- Get the first argument |
|
| 513 | + $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0]; |
|
| 514 | + |
|
| 515 | + // ----- Look for the optional second argument |
|
| 516 | + if ($v_size == 2) { |
|
| 517 | + $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
|
| 518 | + } |
|
| 519 | + else if ($v_size > 2) { |
|
| 520 | + // ----- Error log |
|
| 521 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
|
| 522 | + |
|
| 523 | + // ----- Return |
|
| 524 | + return 0; |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | 528 | |
| 529 | - // ----- Look for default option values |
|
| 530 | - $this->privOptionDefaultThreshold($v_options); |
|
| 529 | + // ----- Look for default option values |
|
| 530 | + $this->privOptionDefaultThreshold($v_options); |
|
| 531 | 531 | |
| 532 | - // ----- Init |
|
| 533 | - $v_string_list = array(); |
|
| 534 | - $v_att_list = array(); |
|
| 535 | - $v_filedescr_list = array(); |
|
| 536 | - $p_result_list = array(); |
|
| 532 | + // ----- Init |
|
| 533 | + $v_string_list = array(); |
|
| 534 | + $v_att_list = array(); |
|
| 535 | + $v_filedescr_list = array(); |
|
| 536 | + $p_result_list = array(); |
|
| 537 | 537 | |
| 538 | - // ----- Look if the $p_filelist is really an array |
|
| 539 | - if (is_array($p_filelist)) { |
|
| 538 | + // ----- Look if the $p_filelist is really an array |
|
| 539 | + if (is_array($p_filelist)) { |
|
| 540 | 540 | |
| 541 | - // ----- Look if the first element is also an array |
|
| 542 | - // This will mean that this is a file description entry |
|
| 543 | - if (isset($p_filelist[0]) && is_array($p_filelist[0])) { |
|
| 544 | - $v_att_list = $p_filelist; |
|
| 545 | - } |
|
| 541 | + // ----- Look if the first element is also an array |
|
| 542 | + // This will mean that this is a file description entry |
|
| 543 | + if (isset($p_filelist[0]) && is_array($p_filelist[0])) { |
|
| 544 | + $v_att_list = $p_filelist; |
|
| 545 | + } |
|
| 546 | 546 | |
| 547 | - // ----- The list is a list of string names |
|
| 548 | - else { |
|
| 549 | - $v_string_list = $p_filelist; |
|
| 550 | - } |
|
| 551 | - } |
|
| 547 | + // ----- The list is a list of string names |
|
| 548 | + else { |
|
| 549 | + $v_string_list = $p_filelist; |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | 552 | |
| 553 | - // ----- Look if the $p_filelist is a string |
|
| 554 | - else if (is_string($p_filelist)) { |
|
| 555 | - // ----- Create a list from the string |
|
| 556 | - $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); |
|
| 557 | - } |
|
| 553 | + // ----- Look if the $p_filelist is a string |
|
| 554 | + else if (is_string($p_filelist)) { |
|
| 555 | + // ----- Create a list from the string |
|
| 556 | + $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); |
|
| 557 | + } |
|
| 558 | 558 | |
| 559 | - // ----- Invalid variable type for $p_filelist |
|
| 560 | - else { |
|
| 561 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); |
|
| 562 | - return 0; |
|
| 563 | - } |
|
| 559 | + // ----- Invalid variable type for $p_filelist |
|
| 560 | + else { |
|
| 561 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); |
|
| 562 | + return 0; |
|
| 563 | + } |
|
| 564 | 564 | |
| 565 | - // ----- Reformat the string list |
|
| 566 | - if (sizeof($v_string_list) != 0) { |
|
| 567 | - foreach ($v_string_list as $v_string) { |
|
| 568 | - $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; |
|
| 569 | - } |
|
| 570 | - } |
|
| 565 | + // ----- Reformat the string list |
|
| 566 | + if (sizeof($v_string_list) != 0) { |
|
| 567 | + foreach ($v_string_list as $v_string) { |
|
| 568 | + $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | 571 | |
| 572 | - // ----- For each file in the list check the attributes |
|
| 573 | - $v_supported_attributes |
|
| 574 | - = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' |
|
| 575 | - ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
|
| 576 | - ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
|
| 577 | - ,PCLZIP_ATT_FILE_MTIME => 'optional' |
|
| 578 | - ,PCLZIP_ATT_FILE_CONTENT => 'optional' |
|
| 579 | - ,PCLZIP_ATT_FILE_COMMENT => 'optional' |
|
| 572 | + // ----- For each file in the list check the attributes |
|
| 573 | + $v_supported_attributes |
|
| 574 | + = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' |
|
| 575 | + ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
|
| 576 | + ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
|
| 577 | + ,PCLZIP_ATT_FILE_MTIME => 'optional' |
|
| 578 | + ,PCLZIP_ATT_FILE_CONTENT => 'optional' |
|
| 579 | + ,PCLZIP_ATT_FILE_COMMENT => 'optional' |
|
| 580 | 580 | ); |
| 581 | - foreach ($v_att_list as $v_entry) { |
|
| 582 | - $v_result = $this->privFileDescrParseAtt($v_entry, |
|
| 583 | - $v_filedescr_list[], |
|
| 584 | - $v_options, |
|
| 585 | - $v_supported_attributes); |
|
| 586 | - if ($v_result != 1) { |
|
| 587 | - return 0; |
|
| 588 | - } |
|
| 589 | - } |
|
| 581 | + foreach ($v_att_list as $v_entry) { |
|
| 582 | + $v_result = $this->privFileDescrParseAtt($v_entry, |
|
| 583 | + $v_filedescr_list[], |
|
| 584 | + $v_options, |
|
| 585 | + $v_supported_attributes); |
|
| 586 | + if ($v_result != 1) { |
|
| 587 | + return 0; |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | 590 | |
| 591 | - // ----- Expand the filelist (expand directories) |
|
| 592 | - $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); |
|
| 593 | - if ($v_result != 1) { |
|
| 594 | - return 0; |
|
| 595 | - } |
|
| 591 | + // ----- Expand the filelist (expand directories) |
|
| 592 | + $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); |
|
| 593 | + if ($v_result != 1) { |
|
| 594 | + return 0; |
|
| 595 | + } |
|
| 596 | 596 | |
| 597 | - // ----- Call the create fct |
|
| 598 | - $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options); |
|
| 599 | - if ($v_result != 1) { |
|
| 600 | - return 0; |
|
| 601 | - } |
|
| 597 | + // ----- Call the create fct |
|
| 598 | + $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options); |
|
| 599 | + if ($v_result != 1) { |
|
| 600 | + return 0; |
|
| 601 | + } |
|
| 602 | 602 | |
| 603 | - // ----- Return |
|
| 604 | - return $p_result_list; |
|
| 603 | + // ----- Return |
|
| 604 | + return $p_result_list; |
|
| 605 | 605 | } |
| 606 | 606 | // -------------------------------------------------------------------------------- |
| 607 | 607 | |
@@ -648,26 +648,26 @@ discard block |
||
| 648 | 648 | // -------------------------------------------------------------------------------- |
| 649 | 649 | function listContent() |
| 650 | 650 | { |
| 651 | - $v_result=1; |
|
| 651 | + $v_result=1; |
|
| 652 | 652 | |
| 653 | - // ----- Reset the error handler |
|
| 654 | - $this->privErrorReset(); |
|
| 653 | + // ----- Reset the error handler |
|
| 654 | + $this->privErrorReset(); |
|
| 655 | 655 | |
| 656 | - // ----- Check archive |
|
| 657 | - if (!$this->privCheckFormat()) { |
|
| 658 | - return(0); |
|
| 659 | - } |
|
| 656 | + // ----- Check archive |
|
| 657 | + if (!$this->privCheckFormat()) { |
|
| 658 | + return(0); |
|
| 659 | + } |
|
| 660 | 660 | |
| 661 | - // ----- Call the extracting fct |
|
| 662 | - $p_list = array(); |
|
| 663 | - if (($v_result = $this->privList($p_list)) != 1) |
|
| 664 | - { |
|
| 665 | - unset($p_list); |
|
| 666 | - return(0); |
|
| 667 | - } |
|
| 661 | + // ----- Call the extracting fct |
|
| 662 | + $p_list = array(); |
|
| 663 | + if (($v_result = $this->privList($p_list)) != 1) |
|
| 664 | + { |
|
| 665 | + unset($p_list); |
|
| 666 | + return(0); |
|
| 667 | + } |
|
| 668 | 668 | |
| 669 | - // ----- Return |
|
| 670 | - return $p_list; |
|
| 669 | + // ----- Return |
|
| 670 | + return $p_list; |
|
| 671 | 671 | } |
| 672 | 672 | // -------------------------------------------------------------------------------- |
| 673 | 673 | |
@@ -705,120 +705,120 @@ discard block |
||
| 705 | 705 | // -------------------------------------------------------------------------------- |
| 706 | 706 | function extract() |
| 707 | 707 | { |
| 708 | - $v_result=1; |
|
| 708 | + $v_result=1; |
|
| 709 | 709 | |
| 710 | - // ----- Reset the error handler |
|
| 711 | - $this->privErrorReset(); |
|
| 710 | + // ----- Reset the error handler |
|
| 711 | + $this->privErrorReset(); |
|
| 712 | 712 | |
| 713 | - // ----- Check archive |
|
| 714 | - if (!$this->privCheckFormat()) { |
|
| 715 | - return(0); |
|
| 716 | - } |
|
| 713 | + // ----- Check archive |
|
| 714 | + if (!$this->privCheckFormat()) { |
|
| 715 | + return(0); |
|
| 716 | + } |
|
| 717 | 717 | |
| 718 | - // ----- Set default values |
|
| 719 | - $v_options = array(); |
|
| 718 | + // ----- Set default values |
|
| 719 | + $v_options = array(); |
|
| 720 | 720 | // $v_path = "./"; |
| 721 | - $v_path = ''; |
|
| 722 | - $v_remove_path = ""; |
|
| 723 | - $v_remove_all_path = false; |
|
| 724 | - |
|
| 725 | - // ----- Look for variable options arguments |
|
| 726 | - $v_size = func_num_args(); |
|
| 727 | - |
|
| 728 | - // ----- Default values for option |
|
| 729 | - $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
|
| 730 | - |
|
| 731 | - // ----- Look for arguments |
|
| 732 | - if ($v_size > 0) { |
|
| 733 | - // ----- Get the arguments |
|
| 734 | - $v_arg_list = func_get_args(); |
|
| 735 | - |
|
| 736 | - // ----- Look for first arg |
|
| 737 | - if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 738 | - |
|
| 739 | - // ----- Parse the options |
|
| 740 | - $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
|
| 741 | - array (PCLZIP_OPT_PATH => 'optional', |
|
| 742 | - PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 743 | - PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 744 | - PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 745 | - PCLZIP_CB_PRE_EXTRACT => 'optional', |
|
| 746 | - PCLZIP_CB_POST_EXTRACT => 'optional', |
|
| 747 | - PCLZIP_OPT_SET_CHMOD => 'optional', |
|
| 748 | - PCLZIP_OPT_BY_NAME => 'optional', |
|
| 749 | - PCLZIP_OPT_BY_EREG => 'optional', |
|
| 750 | - PCLZIP_OPT_BY_PREG => 'optional', |
|
| 751 | - PCLZIP_OPT_BY_INDEX => 'optional', |
|
| 752 | - PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', |
|
| 753 | - PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional', |
|
| 754 | - PCLZIP_OPT_REPLACE_NEWER => 'optional' |
|
| 755 | - ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' |
|
| 756 | - ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', |
|
| 757 | - PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 758 | - PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 759 | - PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 760 | - )); |
|
| 761 | - if ($v_result != 1) { |
|
| 762 | - return 0; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - // ----- Set the arguments |
|
| 766 | - if (isset($v_options[PCLZIP_OPT_PATH])) { |
|
| 767 | - $v_path = $v_options[PCLZIP_OPT_PATH]; |
|
| 768 | - } |
|
| 769 | - if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { |
|
| 770 | - $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; |
|
| 771 | - } |
|
| 772 | - if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 773 | - $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
|
| 774 | - } |
|
| 775 | - if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { |
|
| 776 | - // ----- Check for '/' in last path char |
|
| 777 | - if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { |
|
| 778 | - $v_path .= '/'; |
|
| 779 | - } |
|
| 780 | - $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; |
|
| 781 | - } |
|
| 782 | - } |
|
| 721 | + $v_path = ''; |
|
| 722 | + $v_remove_path = ""; |
|
| 723 | + $v_remove_all_path = false; |
|
| 724 | + |
|
| 725 | + // ----- Look for variable options arguments |
|
| 726 | + $v_size = func_num_args(); |
|
| 727 | + |
|
| 728 | + // ----- Default values for option |
|
| 729 | + $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
|
| 730 | + |
|
| 731 | + // ----- Look for arguments |
|
| 732 | + if ($v_size > 0) { |
|
| 733 | + // ----- Get the arguments |
|
| 734 | + $v_arg_list = func_get_args(); |
|
| 735 | + |
|
| 736 | + // ----- Look for first arg |
|
| 737 | + if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 738 | + |
|
| 739 | + // ----- Parse the options |
|
| 740 | + $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
|
| 741 | + array (PCLZIP_OPT_PATH => 'optional', |
|
| 742 | + PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 743 | + PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 744 | + PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 745 | + PCLZIP_CB_PRE_EXTRACT => 'optional', |
|
| 746 | + PCLZIP_CB_POST_EXTRACT => 'optional', |
|
| 747 | + PCLZIP_OPT_SET_CHMOD => 'optional', |
|
| 748 | + PCLZIP_OPT_BY_NAME => 'optional', |
|
| 749 | + PCLZIP_OPT_BY_EREG => 'optional', |
|
| 750 | + PCLZIP_OPT_BY_PREG => 'optional', |
|
| 751 | + PCLZIP_OPT_BY_INDEX => 'optional', |
|
| 752 | + PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', |
|
| 753 | + PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional', |
|
| 754 | + PCLZIP_OPT_REPLACE_NEWER => 'optional' |
|
| 755 | + ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' |
|
| 756 | + ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', |
|
| 757 | + PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 758 | + PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 759 | + PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 760 | + )); |
|
| 761 | + if ($v_result != 1) { |
|
| 762 | + return 0; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + // ----- Set the arguments |
|
| 766 | + if (isset($v_options[PCLZIP_OPT_PATH])) { |
|
| 767 | + $v_path = $v_options[PCLZIP_OPT_PATH]; |
|
| 768 | + } |
|
| 769 | + if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { |
|
| 770 | + $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; |
|
| 771 | + } |
|
| 772 | + if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 773 | + $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
|
| 774 | + } |
|
| 775 | + if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { |
|
| 776 | + // ----- Check for '/' in last path char |
|
| 777 | + if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { |
|
| 778 | + $v_path .= '/'; |
|
| 779 | + } |
|
| 780 | + $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; |
|
| 781 | + } |
|
| 782 | + } |
|
| 783 | 783 | |
| 784 | - // ----- Look for 2 args |
|
| 785 | - // Here we need to support the first historic synopsis of the |
|
| 786 | - // method. |
|
| 787 | - else { |
|
| 788 | - |
|
| 789 | - // ----- Get the first argument |
|
| 790 | - $v_path = $v_arg_list[0]; |
|
| 791 | - |
|
| 792 | - // ----- Look for the optional second argument |
|
| 793 | - if ($v_size == 2) { |
|
| 794 | - $v_remove_path = $v_arg_list[1]; |
|
| 795 | - } |
|
| 796 | - else if ($v_size > 2) { |
|
| 797 | - // ----- Error log |
|
| 798 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
|
| 799 | - |
|
| 800 | - // ----- Return |
|
| 801 | - return 0; |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - } |
|
| 784 | + // ----- Look for 2 args |
|
| 785 | + // Here we need to support the first historic synopsis of the |
|
| 786 | + // method. |
|
| 787 | + else { |
|
| 788 | + |
|
| 789 | + // ----- Get the first argument |
|
| 790 | + $v_path = $v_arg_list[0]; |
|
| 791 | + |
|
| 792 | + // ----- Look for the optional second argument |
|
| 793 | + if ($v_size == 2) { |
|
| 794 | + $v_remove_path = $v_arg_list[1]; |
|
| 795 | + } |
|
| 796 | + else if ($v_size > 2) { |
|
| 797 | + // ----- Error log |
|
| 798 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
|
| 799 | + |
|
| 800 | + // ----- Return |
|
| 801 | + return 0; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | 805 | |
| 806 | - // ----- Look for default option values |
|
| 807 | - $this->privOptionDefaultThreshold($v_options); |
|
| 806 | + // ----- Look for default option values |
|
| 807 | + $this->privOptionDefaultThreshold($v_options); |
|
| 808 | 808 | |
| 809 | - // ----- Trace |
|
| 809 | + // ----- Trace |
|
| 810 | 810 | |
| 811 | - // ----- Call the extracting fct |
|
| 812 | - $p_list = array(); |
|
| 813 | - $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, |
|
| 814 | - $v_remove_all_path, $v_options); |
|
| 815 | - if ($v_result < 1) { |
|
| 816 | - unset($p_list); |
|
| 817 | - return(0); |
|
| 818 | - } |
|
| 811 | + // ----- Call the extracting fct |
|
| 812 | + $p_list = array(); |
|
| 813 | + $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, |
|
| 814 | + $v_remove_all_path, $v_options); |
|
| 815 | + if ($v_result < 1) { |
|
| 816 | + unset($p_list); |
|
| 817 | + return(0); |
|
| 818 | + } |
|
| 819 | 819 | |
| 820 | - // ----- Return |
|
| 821 | - return $p_list; |
|
| 820 | + // ----- Return |
|
| 821 | + return $p_list; |
|
| 822 | 822 | } |
| 823 | 823 | // -------------------------------------------------------------------------------- |
| 824 | 824 | |
@@ -862,132 +862,132 @@ discard block |
||
| 862 | 862 | //function extractByIndex($p_index, options...) |
| 863 | 863 | function extractByIndex($p_index) |
| 864 | 864 | { |
| 865 | - $v_result=1; |
|
| 865 | + $v_result=1; |
|
| 866 | 866 | |
| 867 | - // ----- Reset the error handler |
|
| 868 | - $this->privErrorReset(); |
|
| 867 | + // ----- Reset the error handler |
|
| 868 | + $this->privErrorReset(); |
|
| 869 | 869 | |
| 870 | - // ----- Check archive |
|
| 871 | - if (!$this->privCheckFormat()) { |
|
| 872 | - return(0); |
|
| 873 | - } |
|
| 870 | + // ----- Check archive |
|
| 871 | + if (!$this->privCheckFormat()) { |
|
| 872 | + return(0); |
|
| 873 | + } |
|
| 874 | 874 | |
| 875 | - // ----- Set default values |
|
| 876 | - $v_options = array(); |
|
| 875 | + // ----- Set default values |
|
| 876 | + $v_options = array(); |
|
| 877 | 877 | // $v_path = "./"; |
| 878 | - $v_path = ''; |
|
| 879 | - $v_remove_path = ""; |
|
| 880 | - $v_remove_all_path = false; |
|
| 881 | - |
|
| 882 | - // ----- Look for variable options arguments |
|
| 883 | - $v_size = func_num_args(); |
|
| 884 | - |
|
| 885 | - // ----- Default values for option |
|
| 886 | - $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
|
| 887 | - |
|
| 888 | - // ----- Look for arguments |
|
| 889 | - if ($v_size > 1) { |
|
| 890 | - // ----- Get the arguments |
|
| 891 | - $v_arg_list = func_get_args(); |
|
| 892 | - |
|
| 893 | - // ----- Remove form the options list the first argument |
|
| 894 | - array_shift($v_arg_list); |
|
| 895 | - $v_size--; |
|
| 896 | - |
|
| 897 | - // ----- Look for first arg |
|
| 898 | - if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 899 | - |
|
| 900 | - // ----- Parse the options |
|
| 901 | - $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
|
| 902 | - array (PCLZIP_OPT_PATH => 'optional', |
|
| 903 | - PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 904 | - PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 905 | - PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', |
|
| 906 | - PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 907 | - PCLZIP_CB_PRE_EXTRACT => 'optional', |
|
| 908 | - PCLZIP_CB_POST_EXTRACT => 'optional', |
|
| 909 | - PCLZIP_OPT_SET_CHMOD => 'optional', |
|
| 910 | - PCLZIP_OPT_REPLACE_NEWER => 'optional' |
|
| 911 | - ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' |
|
| 912 | - ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', |
|
| 913 | - PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 914 | - PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 915 | - PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 878 | + $v_path = ''; |
|
| 879 | + $v_remove_path = ""; |
|
| 880 | + $v_remove_all_path = false; |
|
| 881 | + |
|
| 882 | + // ----- Look for variable options arguments |
|
| 883 | + $v_size = func_num_args(); |
|
| 884 | + |
|
| 885 | + // ----- Default values for option |
|
| 886 | + $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
|
| 887 | + |
|
| 888 | + // ----- Look for arguments |
|
| 889 | + if ($v_size > 1) { |
|
| 890 | + // ----- Get the arguments |
|
| 891 | + $v_arg_list = func_get_args(); |
|
| 892 | + |
|
| 893 | + // ----- Remove form the options list the first argument |
|
| 894 | + array_shift($v_arg_list); |
|
| 895 | + $v_size--; |
|
| 896 | + |
|
| 897 | + // ----- Look for first arg |
|
| 898 | + if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 899 | + |
|
| 900 | + // ----- Parse the options |
|
| 901 | + $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
|
| 902 | + array (PCLZIP_OPT_PATH => 'optional', |
|
| 903 | + PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 904 | + PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 905 | + PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', |
|
| 906 | + PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 907 | + PCLZIP_CB_PRE_EXTRACT => 'optional', |
|
| 908 | + PCLZIP_CB_POST_EXTRACT => 'optional', |
|
| 909 | + PCLZIP_OPT_SET_CHMOD => 'optional', |
|
| 910 | + PCLZIP_OPT_REPLACE_NEWER => 'optional' |
|
| 911 | + ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' |
|
| 912 | + ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', |
|
| 913 | + PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 914 | + PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 915 | + PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 916 | 916 | )); |
| 917 | - if ($v_result != 1) { |
|
| 918 | - return 0; |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - // ----- Set the arguments |
|
| 922 | - if (isset($v_options[PCLZIP_OPT_PATH])) { |
|
| 923 | - $v_path = $v_options[PCLZIP_OPT_PATH]; |
|
| 924 | - } |
|
| 925 | - if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { |
|
| 926 | - $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; |
|
| 927 | - } |
|
| 928 | - if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 929 | - $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
|
| 930 | - } |
|
| 931 | - if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { |
|
| 932 | - // ----- Check for '/' in last path char |
|
| 933 | - if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { |
|
| 934 | - $v_path .= '/'; |
|
| 935 | - } |
|
| 936 | - $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; |
|
| 937 | - } |
|
| 938 | - if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) { |
|
| 939 | - $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
|
| 940 | - } |
|
| 941 | - else { |
|
| 942 | - } |
|
| 943 | - } |
|
| 917 | + if ($v_result != 1) { |
|
| 918 | + return 0; |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + // ----- Set the arguments |
|
| 922 | + if (isset($v_options[PCLZIP_OPT_PATH])) { |
|
| 923 | + $v_path = $v_options[PCLZIP_OPT_PATH]; |
|
| 924 | + } |
|
| 925 | + if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { |
|
| 926 | + $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; |
|
| 927 | + } |
|
| 928 | + if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 929 | + $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
|
| 930 | + } |
|
| 931 | + if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { |
|
| 932 | + // ----- Check for '/' in last path char |
|
| 933 | + if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { |
|
| 934 | + $v_path .= '/'; |
|
| 935 | + } |
|
| 936 | + $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; |
|
| 937 | + } |
|
| 938 | + if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) { |
|
| 939 | + $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
|
| 940 | + } |
|
| 941 | + else { |
|
| 942 | + } |
|
| 943 | + } |
|
| 944 | 944 | |
| 945 | - // ----- Look for 2 args |
|
| 946 | - // Here we need to support the first historic synopsis of the |
|
| 947 | - // method. |
|
| 948 | - else { |
|
| 949 | - |
|
| 950 | - // ----- Get the first argument |
|
| 951 | - $v_path = $v_arg_list[0]; |
|
| 952 | - |
|
| 953 | - // ----- Look for the optional second argument |
|
| 954 | - if ($v_size == 2) { |
|
| 955 | - $v_remove_path = $v_arg_list[1]; |
|
| 956 | - } |
|
| 957 | - else if ($v_size > 2) { |
|
| 958 | - // ----- Error log |
|
| 959 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
|
| 960 | - |
|
| 961 | - // ----- Return |
|
| 962 | - return 0; |
|
| 963 | - } |
|
| 964 | - } |
|
| 965 | - } |
|
| 945 | + // ----- Look for 2 args |
|
| 946 | + // Here we need to support the first historic synopsis of the |
|
| 947 | + // method. |
|
| 948 | + else { |
|
| 949 | + |
|
| 950 | + // ----- Get the first argument |
|
| 951 | + $v_path = $v_arg_list[0]; |
|
| 952 | + |
|
| 953 | + // ----- Look for the optional second argument |
|
| 954 | + if ($v_size == 2) { |
|
| 955 | + $v_remove_path = $v_arg_list[1]; |
|
| 956 | + } |
|
| 957 | + else if ($v_size > 2) { |
|
| 958 | + // ----- Error log |
|
| 959 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
|
| 960 | + |
|
| 961 | + // ----- Return |
|
| 962 | + return 0; |
|
| 963 | + } |
|
| 964 | + } |
|
| 965 | + } |
|
| 966 | 966 | |
| 967 | - // ----- Trace |
|
| 968 | - |
|
| 969 | - // ----- Trick |
|
| 970 | - // Here I want to reuse extractByRule(), so I need to parse the $p_index |
|
| 971 | - // with privParseOptions() |
|
| 972 | - $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index); |
|
| 973 | - $v_options_trick = array(); |
|
| 974 | - $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, |
|
| 975 | - array (PCLZIP_OPT_BY_INDEX => 'optional' )); |
|
| 976 | - if ($v_result != 1) { |
|
| 977 | - return 0; |
|
| 978 | - } |
|
| 979 | - $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX]; |
|
| 967 | + // ----- Trace |
|
| 968 | + |
|
| 969 | + // ----- Trick |
|
| 970 | + // Here I want to reuse extractByRule(), so I need to parse the $p_index |
|
| 971 | + // with privParseOptions() |
|
| 972 | + $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index); |
|
| 973 | + $v_options_trick = array(); |
|
| 974 | + $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, |
|
| 975 | + array (PCLZIP_OPT_BY_INDEX => 'optional' )); |
|
| 976 | + if ($v_result != 1) { |
|
| 977 | + return 0; |
|
| 978 | + } |
|
| 979 | + $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX]; |
|
| 980 | 980 | |
| 981 | - // ----- Look for default option values |
|
| 982 | - $this->privOptionDefaultThreshold($v_options); |
|
| 981 | + // ----- Look for default option values |
|
| 982 | + $this->privOptionDefaultThreshold($v_options); |
|
| 983 | 983 | |
| 984 | - // ----- Call the extracting fct |
|
| 985 | - if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) { |
|
| 986 | - return(0); |
|
| 987 | - } |
|
| 984 | + // ----- Call the extracting fct |
|
| 985 | + if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) { |
|
| 986 | + return(0); |
|
| 987 | + } |
|
| 988 | 988 | |
| 989 | - // ----- Return |
|
| 990 | - return $p_list; |
|
| 989 | + // ----- Return |
|
| 990 | + return $p_list; |
|
| 991 | 991 | } |
| 992 | 992 | // -------------------------------------------------------------------------------- |
| 993 | 993 | |
@@ -1011,54 +1011,54 @@ discard block |
||
| 1011 | 1011 | // -------------------------------------------------------------------------------- |
| 1012 | 1012 | function delete() |
| 1013 | 1013 | { |
| 1014 | - $v_result=1; |
|
| 1014 | + $v_result=1; |
|
| 1015 | 1015 | |
| 1016 | - // ----- Reset the error handler |
|
| 1017 | - $this->privErrorReset(); |
|
| 1016 | + // ----- Reset the error handler |
|
| 1017 | + $this->privErrorReset(); |
|
| 1018 | 1018 | |
| 1019 | - // ----- Check archive |
|
| 1020 | - if (!$this->privCheckFormat()) { |
|
| 1021 | - return(0); |
|
| 1022 | - } |
|
| 1019 | + // ----- Check archive |
|
| 1020 | + if (!$this->privCheckFormat()) { |
|
| 1021 | + return(0); |
|
| 1022 | + } |
|
| 1023 | 1023 | |
| 1024 | - // ----- Set default values |
|
| 1025 | - $v_options = array(); |
|
| 1026 | - |
|
| 1027 | - // ----- Look for variable options arguments |
|
| 1028 | - $v_size = func_num_args(); |
|
| 1029 | - |
|
| 1030 | - // ----- Look for arguments |
|
| 1031 | - if ($v_size > 0) { |
|
| 1032 | - // ----- Get the arguments |
|
| 1033 | - $v_arg_list = func_get_args(); |
|
| 1034 | - |
|
| 1035 | - // ----- Parse the options |
|
| 1036 | - $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
|
| 1037 | - array (PCLZIP_OPT_BY_NAME => 'optional', |
|
| 1038 | - PCLZIP_OPT_BY_EREG => 'optional', |
|
| 1039 | - PCLZIP_OPT_BY_PREG => 'optional', |
|
| 1040 | - PCLZIP_OPT_BY_INDEX => 'optional' )); |
|
| 1041 | - if ($v_result != 1) { |
|
| 1042 | - return 0; |
|
| 1043 | - } |
|
| 1044 | - } |
|
| 1024 | + // ----- Set default values |
|
| 1025 | + $v_options = array(); |
|
| 1026 | + |
|
| 1027 | + // ----- Look for variable options arguments |
|
| 1028 | + $v_size = func_num_args(); |
|
| 1029 | + |
|
| 1030 | + // ----- Look for arguments |
|
| 1031 | + if ($v_size > 0) { |
|
| 1032 | + // ----- Get the arguments |
|
| 1033 | + $v_arg_list = func_get_args(); |
|
| 1034 | + |
|
| 1035 | + // ----- Parse the options |
|
| 1036 | + $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
|
| 1037 | + array (PCLZIP_OPT_BY_NAME => 'optional', |
|
| 1038 | + PCLZIP_OPT_BY_EREG => 'optional', |
|
| 1039 | + PCLZIP_OPT_BY_PREG => 'optional', |
|
| 1040 | + PCLZIP_OPT_BY_INDEX => 'optional' )); |
|
| 1041 | + if ($v_result != 1) { |
|
| 1042 | + return 0; |
|
| 1043 | + } |
|
| 1044 | + } |
|
| 1045 | 1045 | |
| 1046 | - // ----- Magic quotes trick |
|
| 1047 | - $this->privDisableMagicQuotes(); |
|
| 1046 | + // ----- Magic quotes trick |
|
| 1047 | + $this->privDisableMagicQuotes(); |
|
| 1048 | 1048 | |
| 1049 | - // ----- Call the delete fct |
|
| 1050 | - $v_list = array(); |
|
| 1051 | - if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) { |
|
| 1052 | - $this->privSwapBackMagicQuotes(); |
|
| 1053 | - unset($v_list); |
|
| 1054 | - return(0); |
|
| 1055 | - } |
|
| 1049 | + // ----- Call the delete fct |
|
| 1050 | + $v_list = array(); |
|
| 1051 | + if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) { |
|
| 1052 | + $this->privSwapBackMagicQuotes(); |
|
| 1053 | + unset($v_list); |
|
| 1054 | + return(0); |
|
| 1055 | + } |
|
| 1056 | 1056 | |
| 1057 | - // ----- Magic quotes trick |
|
| 1058 | - $this->privSwapBackMagicQuotes(); |
|
| 1057 | + // ----- Magic quotes trick |
|
| 1058 | + $this->privSwapBackMagicQuotes(); |
|
| 1059 | 1059 | |
| 1060 | - // ----- Return |
|
| 1061 | - return $v_list; |
|
| 1060 | + // ----- Return |
|
| 1061 | + return $v_list; |
|
| 1062 | 1062 | } |
| 1063 | 1063 | // -------------------------------------------------------------------------------- |
| 1064 | 1064 | |
@@ -1071,10 +1071,10 @@ discard block |
||
| 1071 | 1071 | function deleteByIndex($p_index) |
| 1072 | 1072 | { |
| 1073 | 1073 | |
| 1074 | - $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); |
|
| 1074 | + $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); |
|
| 1075 | 1075 | |
| 1076 | - // ----- Return |
|
| 1077 | - return $p_list; |
|
| 1076 | + // ----- Return |
|
| 1077 | + return $p_list; |
|
| 1078 | 1078 | } |
| 1079 | 1079 | // -------------------------------------------------------------------------------- |
| 1080 | 1080 | |
@@ -1095,61 +1095,61 @@ discard block |
||
| 1095 | 1095 | function properties() |
| 1096 | 1096 | { |
| 1097 | 1097 | |
| 1098 | - // ----- Reset the error handler |
|
| 1099 | - $this->privErrorReset(); |
|
| 1098 | + // ----- Reset the error handler |
|
| 1099 | + $this->privErrorReset(); |
|
| 1100 | 1100 | |
| 1101 | - // ----- Magic quotes trick |
|
| 1102 | - $this->privDisableMagicQuotes(); |
|
| 1101 | + // ----- Magic quotes trick |
|
| 1102 | + $this->privDisableMagicQuotes(); |
|
| 1103 | 1103 | |
| 1104 | - // ----- Check archive |
|
| 1105 | - if (!$this->privCheckFormat()) { |
|
| 1106 | - $this->privSwapBackMagicQuotes(); |
|
| 1107 | - return(0); |
|
| 1108 | - } |
|
| 1104 | + // ----- Check archive |
|
| 1105 | + if (!$this->privCheckFormat()) { |
|
| 1106 | + $this->privSwapBackMagicQuotes(); |
|
| 1107 | + return(0); |
|
| 1108 | + } |
|
| 1109 | 1109 | |
| 1110 | - // ----- Default properties |
|
| 1111 | - $v_prop = array(); |
|
| 1112 | - $v_prop['comment'] = ''; |
|
| 1113 | - $v_prop['nb'] = 0; |
|
| 1114 | - $v_prop['status'] = 'not_exist'; |
|
| 1115 | - |
|
| 1116 | - // ----- Look if file exists |
|
| 1117 | - if (@is_file($this->zipname)) |
|
| 1118 | - { |
|
| 1119 | - // ----- Open the zip file |
|
| 1120 | - if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) |
|
| 1121 | - { |
|
| 1122 | - $this->privSwapBackMagicQuotes(); |
|
| 1110 | + // ----- Default properties |
|
| 1111 | + $v_prop = array(); |
|
| 1112 | + $v_prop['comment'] = ''; |
|
| 1113 | + $v_prop['nb'] = 0; |
|
| 1114 | + $v_prop['status'] = 'not_exist'; |
|
| 1115 | + |
|
| 1116 | + // ----- Look if file exists |
|
| 1117 | + if (@is_file($this->zipname)) |
|
| 1118 | + { |
|
| 1119 | + // ----- Open the zip file |
|
| 1120 | + if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) |
|
| 1121 | + { |
|
| 1122 | + $this->privSwapBackMagicQuotes(); |
|
| 1123 | 1123 | |
| 1124 | - // ----- Error log |
|
| 1125 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); |
|
| 1124 | + // ----- Error log |
|
| 1125 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); |
|
| 1126 | 1126 | |
| 1127 | - // ----- Return |
|
| 1128 | - return 0; |
|
| 1129 | - } |
|
| 1127 | + // ----- Return |
|
| 1128 | + return 0; |
|
| 1129 | + } |
|
| 1130 | 1130 | |
| 1131 | - // ----- Read the central directory informations |
|
| 1132 | - $v_central_dir = array(); |
|
| 1133 | - if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 1134 | - { |
|
| 1135 | - $this->privSwapBackMagicQuotes(); |
|
| 1136 | - return 0; |
|
| 1137 | - } |
|
| 1131 | + // ----- Read the central directory informations |
|
| 1132 | + $v_central_dir = array(); |
|
| 1133 | + if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 1134 | + { |
|
| 1135 | + $this->privSwapBackMagicQuotes(); |
|
| 1136 | + return 0; |
|
| 1137 | + } |
|
| 1138 | 1138 | |
| 1139 | - // ----- Close the zip file |
|
| 1140 | - $this->privCloseFd(); |
|
| 1139 | + // ----- Close the zip file |
|
| 1140 | + $this->privCloseFd(); |
|
| 1141 | 1141 | |
| 1142 | - // ----- Set the user attributes |
|
| 1143 | - $v_prop['comment'] = $v_central_dir['comment']; |
|
| 1144 | - $v_prop['nb'] = $v_central_dir['entries']; |
|
| 1145 | - $v_prop['status'] = 'ok'; |
|
| 1146 | - } |
|
| 1142 | + // ----- Set the user attributes |
|
| 1143 | + $v_prop['comment'] = $v_central_dir['comment']; |
|
| 1144 | + $v_prop['nb'] = $v_central_dir['entries']; |
|
| 1145 | + $v_prop['status'] = 'ok'; |
|
| 1146 | + } |
|
| 1147 | 1147 | |
| 1148 | - // ----- Magic quotes trick |
|
| 1149 | - $this->privSwapBackMagicQuotes(); |
|
| 1148 | + // ----- Magic quotes trick |
|
| 1149 | + $this->privSwapBackMagicQuotes(); |
|
| 1150 | 1150 | |
| 1151 | - // ----- Return |
|
| 1152 | - return $v_prop; |
|
| 1151 | + // ----- Return |
|
| 1152 | + return $v_prop; |
|
| 1153 | 1153 | } |
| 1154 | 1154 | // -------------------------------------------------------------------------------- |
| 1155 | 1155 | |
@@ -1167,46 +1167,46 @@ discard block |
||
| 1167 | 1167 | // -------------------------------------------------------------------------------- |
| 1168 | 1168 | function duplicate($p_archive) |
| 1169 | 1169 | { |
| 1170 | - $v_result = 1; |
|
| 1170 | + $v_result = 1; |
|
| 1171 | 1171 | |
| 1172 | - // ----- Reset the error handler |
|
| 1173 | - $this->privErrorReset(); |
|
| 1172 | + // ----- Reset the error handler |
|
| 1173 | + $this->privErrorReset(); |
|
| 1174 | 1174 | |
| 1175 | - // ----- Look if the $p_archive is a PclZip object |
|
| 1176 | - if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) |
|
| 1177 | - { |
|
| 1175 | + // ----- Look if the $p_archive is a PclZip object |
|
| 1176 | + if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) |
|
| 1177 | + { |
|
| 1178 | 1178 | |
| 1179 | - // ----- Duplicate the archive |
|
| 1180 | - $v_result = $this->privDuplicate($p_archive->zipname); |
|
| 1181 | - } |
|
| 1179 | + // ----- Duplicate the archive |
|
| 1180 | + $v_result = $this->privDuplicate($p_archive->zipname); |
|
| 1181 | + } |
|
| 1182 | 1182 | |
| 1183 | - // ----- Look if the $p_archive is a string (so a filename) |
|
| 1184 | - else if (is_string($p_archive)) |
|
| 1185 | - { |
|
| 1183 | + // ----- Look if the $p_archive is a string (so a filename) |
|
| 1184 | + else if (is_string($p_archive)) |
|
| 1185 | + { |
|
| 1186 | 1186 | |
| 1187 | - // ----- Check that $p_archive is a valid zip file |
|
| 1188 | - // TBC : Should also check the archive format |
|
| 1189 | - if (!is_file($p_archive)) { |
|
| 1190 | - // ----- Error log |
|
| 1191 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'"); |
|
| 1192 | - $v_result = PCLZIP_ERR_MISSING_FILE; |
|
| 1193 | - } |
|
| 1194 | - else { |
|
| 1195 | - // ----- Duplicate the archive |
|
| 1196 | - $v_result = $this->privDuplicate($p_archive); |
|
| 1197 | - } |
|
| 1198 | - } |
|
| 1187 | + // ----- Check that $p_archive is a valid zip file |
|
| 1188 | + // TBC : Should also check the archive format |
|
| 1189 | + if (!is_file($p_archive)) { |
|
| 1190 | + // ----- Error log |
|
| 1191 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'"); |
|
| 1192 | + $v_result = PCLZIP_ERR_MISSING_FILE; |
|
| 1193 | + } |
|
| 1194 | + else { |
|
| 1195 | + // ----- Duplicate the archive |
|
| 1196 | + $v_result = $this->privDuplicate($p_archive); |
|
| 1197 | + } |
|
| 1198 | + } |
|
| 1199 | 1199 | |
| 1200 | - // ----- Invalid variable |
|
| 1201 | - else |
|
| 1202 | - { |
|
| 1203 | - // ----- Error log |
|
| 1204 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); |
|
| 1205 | - $v_result = PCLZIP_ERR_INVALID_PARAMETER; |
|
| 1206 | - } |
|
| 1200 | + // ----- Invalid variable |
|
| 1201 | + else |
|
| 1202 | + { |
|
| 1203 | + // ----- Error log |
|
| 1204 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); |
|
| 1205 | + $v_result = PCLZIP_ERR_INVALID_PARAMETER; |
|
| 1206 | + } |
|
| 1207 | 1207 | |
| 1208 | - // ----- Return |
|
| 1209 | - return $v_result; |
|
| 1208 | + // ----- Return |
|
| 1209 | + return $v_result; |
|
| 1210 | 1210 | } |
| 1211 | 1211 | // -------------------------------------------------------------------------------- |
| 1212 | 1212 | |
@@ -1226,45 +1226,45 @@ discard block |
||
| 1226 | 1226 | // -------------------------------------------------------------------------------- |
| 1227 | 1227 | function merge($p_archive_to_add) |
| 1228 | 1228 | { |
| 1229 | - $v_result = 1; |
|
| 1229 | + $v_result = 1; |
|
| 1230 | 1230 | |
| 1231 | - // ----- Reset the error handler |
|
| 1232 | - $this->privErrorReset(); |
|
| 1231 | + // ----- Reset the error handler |
|
| 1232 | + $this->privErrorReset(); |
|
| 1233 | 1233 | |
| 1234 | - // ----- Check archive |
|
| 1235 | - if (!$this->privCheckFormat()) { |
|
| 1236 | - return(0); |
|
| 1237 | - } |
|
| 1234 | + // ----- Check archive |
|
| 1235 | + if (!$this->privCheckFormat()) { |
|
| 1236 | + return(0); |
|
| 1237 | + } |
|
| 1238 | 1238 | |
| 1239 | - // ----- Look if the $p_archive_to_add is a PclZip object |
|
| 1240 | - if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) |
|
| 1241 | - { |
|
| 1239 | + // ----- Look if the $p_archive_to_add is a PclZip object |
|
| 1240 | + if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) |
|
| 1241 | + { |
|
| 1242 | 1242 | |
| 1243 | - // ----- Merge the archive |
|
| 1244 | - $v_result = $this->privMerge($p_archive_to_add); |
|
| 1245 | - } |
|
| 1243 | + // ----- Merge the archive |
|
| 1244 | + $v_result = $this->privMerge($p_archive_to_add); |
|
| 1245 | + } |
|
| 1246 | 1246 | |
| 1247 | - // ----- Look if the $p_archive_to_add is a string (so a filename) |
|
| 1248 | - else if (is_string($p_archive_to_add)) |
|
| 1249 | - { |
|
| 1247 | + // ----- Look if the $p_archive_to_add is a string (so a filename) |
|
| 1248 | + else if (is_string($p_archive_to_add)) |
|
| 1249 | + { |
|
| 1250 | 1250 | |
| 1251 | - // ----- Create a temporary archive |
|
| 1252 | - $v_object_archive = new PclZip($p_archive_to_add); |
|
| 1251 | + // ----- Create a temporary archive |
|
| 1252 | + $v_object_archive = new PclZip($p_archive_to_add); |
|
| 1253 | 1253 | |
| 1254 | - // ----- Merge the archive |
|
| 1255 | - $v_result = $this->privMerge($v_object_archive); |
|
| 1256 | - } |
|
| 1254 | + // ----- Merge the archive |
|
| 1255 | + $v_result = $this->privMerge($v_object_archive); |
|
| 1256 | + } |
|
| 1257 | 1257 | |
| 1258 | - // ----- Invalid variable |
|
| 1259 | - else |
|
| 1260 | - { |
|
| 1261 | - // ----- Error log |
|
| 1262 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); |
|
| 1263 | - $v_result = PCLZIP_ERR_INVALID_PARAMETER; |
|
| 1264 | - } |
|
| 1258 | + // ----- Invalid variable |
|
| 1259 | + else |
|
| 1260 | + { |
|
| 1261 | + // ----- Error log |
|
| 1262 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); |
|
| 1263 | + $v_result = PCLZIP_ERR_INVALID_PARAMETER; |
|
| 1264 | + } |
|
| 1265 | 1265 | |
| 1266 | - // ----- Return |
|
| 1267 | - return $v_result; |
|
| 1266 | + // ----- Return |
|
| 1267 | + return $v_result; |
|
| 1268 | 1268 | } |
| 1269 | 1269 | // -------------------------------------------------------------------------------- |
| 1270 | 1270 | |
@@ -1277,12 +1277,12 @@ discard block |
||
| 1277 | 1277 | // -------------------------------------------------------------------------------- |
| 1278 | 1278 | function errorCode() |
| 1279 | 1279 | { |
| 1280 | - if (PCLZIP_ERROR_EXTERNAL == 1) { |
|
| 1281 | - return(PclErrorCode()); |
|
| 1282 | - } |
|
| 1283 | - else { |
|
| 1284 | - return($this->error_code); |
|
| 1285 | - } |
|
| 1280 | + if (PCLZIP_ERROR_EXTERNAL == 1) { |
|
| 1281 | + return(PclErrorCode()); |
|
| 1282 | + } |
|
| 1283 | + else { |
|
| 1284 | + return($this->error_code); |
|
| 1285 | + } |
|
| 1286 | 1286 | } |
| 1287 | 1287 | // -------------------------------------------------------------------------------- |
| 1288 | 1288 | |
@@ -1293,42 +1293,42 @@ discard block |
||
| 1293 | 1293 | // -------------------------------------------------------------------------------- |
| 1294 | 1294 | function errorName($p_with_code=false) |
| 1295 | 1295 | { |
| 1296 | - $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', |
|
| 1297 | - PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL', |
|
| 1298 | - PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL', |
|
| 1299 | - PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER', |
|
| 1300 | - PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE', |
|
| 1301 | - PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG', |
|
| 1302 | - PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP', |
|
| 1303 | - PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE', |
|
| 1304 | - PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL', |
|
| 1305 | - PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION', |
|
| 1306 | - PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT', |
|
| 1307 | - PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL', |
|
| 1308 | - PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL', |
|
| 1309 | - PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM', |
|
| 1310 | - PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', |
|
| 1311 | - PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE', |
|
| 1312 | - PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE', |
|
| 1313 | - PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', |
|
| 1314 | - PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION' |
|
| 1315 | - ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE' |
|
| 1316 | - ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION' |
|
| 1317 | - ); |
|
| 1318 | - |
|
| 1319 | - if (isset($v_name[$this->error_code])) { |
|
| 1320 | - $v_value = $v_name[$this->error_code]; |
|
| 1321 | - } |
|
| 1322 | - else { |
|
| 1323 | - $v_value = 'NoName'; |
|
| 1324 | - } |
|
| 1296 | + $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', |
|
| 1297 | + PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL', |
|
| 1298 | + PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL', |
|
| 1299 | + PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER', |
|
| 1300 | + PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE', |
|
| 1301 | + PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG', |
|
| 1302 | + PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP', |
|
| 1303 | + PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE', |
|
| 1304 | + PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL', |
|
| 1305 | + PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION', |
|
| 1306 | + PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT', |
|
| 1307 | + PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL', |
|
| 1308 | + PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL', |
|
| 1309 | + PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM', |
|
| 1310 | + PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', |
|
| 1311 | + PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE', |
|
| 1312 | + PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE', |
|
| 1313 | + PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', |
|
| 1314 | + PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION' |
|
| 1315 | + ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE' |
|
| 1316 | + ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION' |
|
| 1317 | + ); |
|
| 1318 | + |
|
| 1319 | + if (isset($v_name[$this->error_code])) { |
|
| 1320 | + $v_value = $v_name[$this->error_code]; |
|
| 1321 | + } |
|
| 1322 | + else { |
|
| 1323 | + $v_value = 'NoName'; |
|
| 1324 | + } |
|
| 1325 | 1325 | |
| 1326 | - if ($p_with_code) { |
|
| 1327 | - return($v_value.' ('.$this->error_code.')'); |
|
| 1328 | - } |
|
| 1329 | - else { |
|
| 1330 | - return($v_value); |
|
| 1331 | - } |
|
| 1326 | + if ($p_with_code) { |
|
| 1327 | + return($v_value.' ('.$this->error_code.')'); |
|
| 1328 | + } |
|
| 1329 | + else { |
|
| 1330 | + return($v_value); |
|
| 1331 | + } |
|
| 1332 | 1332 | } |
| 1333 | 1333 | // -------------------------------------------------------------------------------- |
| 1334 | 1334 | |
@@ -1339,17 +1339,17 @@ discard block |
||
| 1339 | 1339 | // -------------------------------------------------------------------------------- |
| 1340 | 1340 | function errorInfo($p_full=false) |
| 1341 | 1341 | { |
| 1342 | - if (PCLZIP_ERROR_EXTERNAL == 1) { |
|
| 1343 | - return(PclErrorString()); |
|
| 1344 | - } |
|
| 1345 | - else { |
|
| 1346 | - if ($p_full) { |
|
| 1347 | - return($this->errorName(true)." : ".$this->error_string); |
|
| 1348 | - } |
|
| 1349 | - else { |
|
| 1350 | - return($this->error_string." [code ".$this->error_code."]"); |
|
| 1351 | - } |
|
| 1352 | - } |
|
| 1342 | + if (PCLZIP_ERROR_EXTERNAL == 1) { |
|
| 1343 | + return(PclErrorString()); |
|
| 1344 | + } |
|
| 1345 | + else { |
|
| 1346 | + if ($p_full) { |
|
| 1347 | + return($this->errorName(true)." : ".$this->error_string); |
|
| 1348 | + } |
|
| 1349 | + else { |
|
| 1350 | + return($this->error_string." [code ".$this->error_code."]"); |
|
| 1351 | + } |
|
| 1352 | + } |
|
| 1353 | 1353 | } |
| 1354 | 1354 | // -------------------------------------------------------------------------------- |
| 1355 | 1355 | |
@@ -1378,39 +1378,39 @@ discard block |
||
| 1378 | 1378 | // -------------------------------------------------------------------------------- |
| 1379 | 1379 | function privCheckFormat($p_level=0) |
| 1380 | 1380 | { |
| 1381 | - $v_result = true; |
|
| 1381 | + $v_result = true; |
|
| 1382 | 1382 | |
| 1383 | 1383 | // ----- Reset the file system cache |
| 1384 | - clearstatcache(); |
|
| 1384 | + clearstatcache(); |
|
| 1385 | 1385 | |
| 1386 | - // ----- Reset the error handler |
|
| 1387 | - $this->privErrorReset(); |
|
| 1386 | + // ----- Reset the error handler |
|
| 1387 | + $this->privErrorReset(); |
|
| 1388 | 1388 | |
| 1389 | - // ----- Look if the file exits |
|
| 1390 | - if (!is_file($this->zipname)) { |
|
| 1391 | - // ----- Error log |
|
| 1392 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); |
|
| 1393 | - return(false); |
|
| 1394 | - } |
|
| 1389 | + // ----- Look if the file exits |
|
| 1390 | + if (!is_file($this->zipname)) { |
|
| 1391 | + // ----- Error log |
|
| 1392 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); |
|
| 1393 | + return(false); |
|
| 1394 | + } |
|
| 1395 | 1395 | |
| 1396 | - // ----- Check that the file is readeable |
|
| 1397 | - if (!is_readable($this->zipname)) { |
|
| 1398 | - // ----- Error log |
|
| 1399 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); |
|
| 1400 | - return(false); |
|
| 1401 | - } |
|
| 1396 | + // ----- Check that the file is readeable |
|
| 1397 | + if (!is_readable($this->zipname)) { |
|
| 1398 | + // ----- Error log |
|
| 1399 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); |
|
| 1400 | + return(false); |
|
| 1401 | + } |
|
| 1402 | 1402 | |
| 1403 | - // ----- Check the magic code |
|
| 1404 | - // TBC |
|
| 1403 | + // ----- Check the magic code |
|
| 1404 | + // TBC |
|
| 1405 | 1405 | |
| 1406 | - // ----- Check the central header |
|
| 1407 | - // TBC |
|
| 1406 | + // ----- Check the central header |
|
| 1407 | + // TBC |
|
| 1408 | 1408 | |
| 1409 | - // ----- Check each file header |
|
| 1410 | - // TBC |
|
| 1409 | + // ----- Check each file header |
|
| 1410 | + // TBC |
|
| 1411 | 1411 | |
| 1412 | - // ----- Return |
|
| 1413 | - return $v_result; |
|
| 1412 | + // ----- Return |
|
| 1413 | + return $v_result; |
|
| 1414 | 1414 | } |
| 1415 | 1415 | // -------------------------------------------------------------------------------- |
| 1416 | 1416 | |
@@ -1431,395 +1431,395 @@ discard block |
||
| 1431 | 1431 | // -------------------------------------------------------------------------------- |
| 1432 | 1432 | function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) |
| 1433 | 1433 | { |
| 1434 | - $v_result=1; |
|
| 1434 | + $v_result=1; |
|
| 1435 | 1435 | |
| 1436 | - // ----- Read the options |
|
| 1437 | - $i=0; |
|
| 1438 | - while ($i<$p_size) { |
|
| 1436 | + // ----- Read the options |
|
| 1437 | + $i=0; |
|
| 1438 | + while ($i<$p_size) { |
|
| 1439 | 1439 | |
| 1440 | - // ----- Check if the option is supported |
|
| 1441 | - if (!isset($v_requested_options[$p_options_list[$i]])) { |
|
| 1442 | - // ----- Error log |
|
| 1443 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); |
|
| 1440 | + // ----- Check if the option is supported |
|
| 1441 | + if (!isset($v_requested_options[$p_options_list[$i]])) { |
|
| 1442 | + // ----- Error log |
|
| 1443 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); |
|
| 1444 | 1444 | |
| 1445 | - // ----- Return |
|
| 1446 | - return PclZip::errorCode(); |
|
| 1447 | - } |
|
| 1445 | + // ----- Return |
|
| 1446 | + return PclZip::errorCode(); |
|
| 1447 | + } |
|
| 1448 | 1448 | |
| 1449 | - // ----- Look for next option |
|
| 1450 | - switch ($p_options_list[$i]) { |
|
| 1451 | - // ----- Look for options that request a path value |
|
| 1452 | - case PCLZIP_OPT_PATH : |
|
| 1453 | - case PCLZIP_OPT_REMOVE_PATH : |
|
| 1454 | - case PCLZIP_OPT_ADD_PATH : |
|
| 1455 | - // ----- Check the number of parameters |
|
| 1456 | - if (($i+1) >= $p_size) { |
|
| 1457 | - // ----- Error log |
|
| 1458 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1459 | - |
|
| 1460 | - // ----- Return |
|
| 1461 | - return PclZip::errorCode(); |
|
| 1462 | - } |
|
| 1449 | + // ----- Look for next option |
|
| 1450 | + switch ($p_options_list[$i]) { |
|
| 1451 | + // ----- Look for options that request a path value |
|
| 1452 | + case PCLZIP_OPT_PATH : |
|
| 1453 | + case PCLZIP_OPT_REMOVE_PATH : |
|
| 1454 | + case PCLZIP_OPT_ADD_PATH : |
|
| 1455 | + // ----- Check the number of parameters |
|
| 1456 | + if (($i+1) >= $p_size) { |
|
| 1457 | + // ----- Error log |
|
| 1458 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1459 | + |
|
| 1460 | + // ----- Return |
|
| 1461 | + return PclZip::errorCode(); |
|
| 1462 | + } |
|
| 1463 | 1463 | |
| 1464 | - // ----- Get the value |
|
| 1465 | - $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
|
| 1466 | - $i++; |
|
| 1467 | - break; |
|
| 1464 | + // ----- Get the value |
|
| 1465 | + $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
|
| 1466 | + $i++; |
|
| 1467 | + break; |
|
| 1468 | 1468 | |
| 1469 | - case PCLZIP_OPT_TEMP_FILE_THRESHOLD : |
|
| 1470 | - // ----- Check the number of parameters |
|
| 1471 | - if (($i+1) >= $p_size) { |
|
| 1472 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1473 | - return PclZip::errorCode(); |
|
| 1474 | - } |
|
| 1469 | + case PCLZIP_OPT_TEMP_FILE_THRESHOLD : |
|
| 1470 | + // ----- Check the number of parameters |
|
| 1471 | + if (($i+1) >= $p_size) { |
|
| 1472 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1473 | + return PclZip::errorCode(); |
|
| 1474 | + } |
|
| 1475 | 1475 | |
| 1476 | - // ----- Check for incompatible options |
|
| 1477 | - if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
|
| 1478 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
|
| 1479 | - return PclZip::errorCode(); |
|
| 1480 | - } |
|
| 1476 | + // ----- Check for incompatible options |
|
| 1477 | + if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
|
| 1478 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
|
| 1479 | + return PclZip::errorCode(); |
|
| 1480 | + } |
|
| 1481 | 1481 | |
| 1482 | - // ----- Check the value |
|
| 1483 | - $v_value = $p_options_list[$i+1]; |
|
| 1484 | - if ((!is_integer($v_value)) || ($v_value<0)) { |
|
| 1485 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1486 | - return PclZip::errorCode(); |
|
| 1487 | - } |
|
| 1482 | + // ----- Check the value |
|
| 1483 | + $v_value = $p_options_list[$i+1]; |
|
| 1484 | + if ((!is_integer($v_value)) || ($v_value<0)) { |
|
| 1485 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1486 | + return PclZip::errorCode(); |
|
| 1487 | + } |
|
| 1488 | 1488 | |
| 1489 | - // ----- Get the value (and convert it in bytes) |
|
| 1490 | - $v_result_list[$p_options_list[$i]] = $v_value*1048576; |
|
| 1491 | - $i++; |
|
| 1492 | - break; |
|
| 1489 | + // ----- Get the value (and convert it in bytes) |
|
| 1490 | + $v_result_list[$p_options_list[$i]] = $v_value*1048576; |
|
| 1491 | + $i++; |
|
| 1492 | + break; |
|
| 1493 | 1493 | |
| 1494 | - case PCLZIP_OPT_TEMP_FILE_ON : |
|
| 1495 | - // ----- Check for incompatible options |
|
| 1496 | - if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
|
| 1497 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
|
| 1498 | - return PclZip::errorCode(); |
|
| 1499 | - } |
|
| 1494 | + case PCLZIP_OPT_TEMP_FILE_ON : |
|
| 1495 | + // ----- Check for incompatible options |
|
| 1496 | + if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
|
| 1497 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
|
| 1498 | + return PclZip::errorCode(); |
|
| 1499 | + } |
|
| 1500 | 1500 | |
| 1501 | - $v_result_list[$p_options_list[$i]] = true; |
|
| 1502 | - break; |
|
| 1503 | - |
|
| 1504 | - case PCLZIP_OPT_TEMP_FILE_OFF : |
|
| 1505 | - // ----- Check for incompatible options |
|
| 1506 | - if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) { |
|
| 1507 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'"); |
|
| 1508 | - return PclZip::errorCode(); |
|
| 1509 | - } |
|
| 1510 | - // ----- Check for incompatible options |
|
| 1511 | - if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { |
|
| 1512 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'"); |
|
| 1513 | - return PclZip::errorCode(); |
|
| 1514 | - } |
|
| 1501 | + $v_result_list[$p_options_list[$i]] = true; |
|
| 1502 | + break; |
|
| 1503 | + |
|
| 1504 | + case PCLZIP_OPT_TEMP_FILE_OFF : |
|
| 1505 | + // ----- Check for incompatible options |
|
| 1506 | + if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) { |
|
| 1507 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'"); |
|
| 1508 | + return PclZip::errorCode(); |
|
| 1509 | + } |
|
| 1510 | + // ----- Check for incompatible options |
|
| 1511 | + if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { |
|
| 1512 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'"); |
|
| 1513 | + return PclZip::errorCode(); |
|
| 1514 | + } |
|
| 1515 | 1515 | |
| 1516 | - $v_result_list[$p_options_list[$i]] = true; |
|
| 1517 | - break; |
|
| 1516 | + $v_result_list[$p_options_list[$i]] = true; |
|
| 1517 | + break; |
|
| 1518 | 1518 | |
| 1519 | - case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : |
|
| 1520 | - // ----- Check the number of parameters |
|
| 1521 | - if (($i+1) >= $p_size) { |
|
| 1522 | - // ----- Error log |
|
| 1523 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1519 | + case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : |
|
| 1520 | + // ----- Check the number of parameters |
|
| 1521 | + if (($i+1) >= $p_size) { |
|
| 1522 | + // ----- Error log |
|
| 1523 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1524 | 1524 | |
| 1525 | - // ----- Return |
|
| 1526 | - return PclZip::errorCode(); |
|
| 1527 | - } |
|
| 1525 | + // ----- Return |
|
| 1526 | + return PclZip::errorCode(); |
|
| 1527 | + } |
|
| 1528 | 1528 | |
| 1529 | - // ----- Get the value |
|
| 1530 | - if ( is_string($p_options_list[$i+1]) |
|
| 1531 | - && ($p_options_list[$i+1] != '')) { |
|
| 1532 | - $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
|
| 1533 | - $i++; |
|
| 1534 | - } |
|
| 1535 | - else { |
|
| 1536 | - } |
|
| 1537 | - break; |
|
| 1529 | + // ----- Get the value |
|
| 1530 | + if ( is_string($p_options_list[$i+1]) |
|
| 1531 | + && ($p_options_list[$i+1] != '')) { |
|
| 1532 | + $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
|
| 1533 | + $i++; |
|
| 1534 | + } |
|
| 1535 | + else { |
|
| 1536 | + } |
|
| 1537 | + break; |
|
| 1538 | 1538 | |
| 1539 | - // ----- Look for options that request an array of string for value |
|
| 1540 | - case PCLZIP_OPT_BY_NAME : |
|
| 1541 | - // ----- Check the number of parameters |
|
| 1542 | - if (($i+1) >= $p_size) { |
|
| 1543 | - // ----- Error log |
|
| 1544 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1539 | + // ----- Look for options that request an array of string for value |
|
| 1540 | + case PCLZIP_OPT_BY_NAME : |
|
| 1541 | + // ----- Check the number of parameters |
|
| 1542 | + if (($i+1) >= $p_size) { |
|
| 1543 | + // ----- Error log |
|
| 1544 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1545 | 1545 | |
| 1546 | - // ----- Return |
|
| 1547 | - return PclZip::errorCode(); |
|
| 1548 | - } |
|
| 1546 | + // ----- Return |
|
| 1547 | + return PclZip::errorCode(); |
|
| 1548 | + } |
|
| 1549 | 1549 | |
| 1550 | - // ----- Get the value |
|
| 1551 | - if (is_string($p_options_list[$i+1])) { |
|
| 1552 | - $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; |
|
| 1553 | - } |
|
| 1554 | - else if (is_array($p_options_list[$i+1])) { |
|
| 1555 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1556 | - } |
|
| 1557 | - else { |
|
| 1558 | - // ----- Error log |
|
| 1559 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1550 | + // ----- Get the value |
|
| 1551 | + if (is_string($p_options_list[$i+1])) { |
|
| 1552 | + $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; |
|
| 1553 | + } |
|
| 1554 | + else if (is_array($p_options_list[$i+1])) { |
|
| 1555 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1556 | + } |
|
| 1557 | + else { |
|
| 1558 | + // ----- Error log |
|
| 1559 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1560 | 1560 | |
| 1561 | - // ----- Return |
|
| 1562 | - return PclZip::errorCode(); |
|
| 1563 | - } |
|
| 1564 | - $i++; |
|
| 1565 | - break; |
|
| 1566 | - |
|
| 1567 | - // ----- Look for options that request an EREG or PREG expression |
|
| 1568 | - case PCLZIP_OPT_BY_EREG : |
|
| 1569 | - // ereg() is deprecated starting with PHP 5.3. Move PCLZIP_OPT_BY_EREG |
|
| 1570 | - // to PCLZIP_OPT_BY_PREG |
|
| 1571 | - $p_options_list[$i] = PCLZIP_OPT_BY_PREG; |
|
| 1572 | - case PCLZIP_OPT_BY_PREG : |
|
| 1573 | - //case PCLZIP_OPT_CRYPT : |
|
| 1574 | - // ----- Check the number of parameters |
|
| 1575 | - if (($i+1) >= $p_size) { |
|
| 1576 | - // ----- Error log |
|
| 1577 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1578 | - |
|
| 1579 | - // ----- Return |
|
| 1580 | - return PclZip::errorCode(); |
|
| 1581 | - } |
|
| 1561 | + // ----- Return |
|
| 1562 | + return PclZip::errorCode(); |
|
| 1563 | + } |
|
| 1564 | + $i++; |
|
| 1565 | + break; |
|
| 1566 | + |
|
| 1567 | + // ----- Look for options that request an EREG or PREG expression |
|
| 1568 | + case PCLZIP_OPT_BY_EREG : |
|
| 1569 | + // ereg() is deprecated starting with PHP 5.3. Move PCLZIP_OPT_BY_EREG |
|
| 1570 | + // to PCLZIP_OPT_BY_PREG |
|
| 1571 | + $p_options_list[$i] = PCLZIP_OPT_BY_PREG; |
|
| 1572 | + case PCLZIP_OPT_BY_PREG : |
|
| 1573 | + //case PCLZIP_OPT_CRYPT : |
|
| 1574 | + // ----- Check the number of parameters |
|
| 1575 | + if (($i+1) >= $p_size) { |
|
| 1576 | + // ----- Error log |
|
| 1577 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1578 | + |
|
| 1579 | + // ----- Return |
|
| 1580 | + return PclZip::errorCode(); |
|
| 1581 | + } |
|
| 1582 | 1582 | |
| 1583 | - // ----- Get the value |
|
| 1584 | - if (is_string($p_options_list[$i+1])) { |
|
| 1585 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1586 | - } |
|
| 1587 | - else { |
|
| 1588 | - // ----- Error log |
|
| 1589 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1583 | + // ----- Get the value |
|
| 1584 | + if (is_string($p_options_list[$i+1])) { |
|
| 1585 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1586 | + } |
|
| 1587 | + else { |
|
| 1588 | + // ----- Error log |
|
| 1589 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1590 | 1590 | |
| 1591 | - // ----- Return |
|
| 1592 | - return PclZip::errorCode(); |
|
| 1593 | - } |
|
| 1594 | - $i++; |
|
| 1595 | - break; |
|
| 1596 | - |
|
| 1597 | - // ----- Look for options that takes a string |
|
| 1598 | - case PCLZIP_OPT_COMMENT : |
|
| 1599 | - case PCLZIP_OPT_ADD_COMMENT : |
|
| 1600 | - case PCLZIP_OPT_PREPEND_COMMENT : |
|
| 1601 | - // ----- Check the number of parameters |
|
| 1602 | - if (($i+1) >= $p_size) { |
|
| 1603 | - // ----- Error log |
|
| 1604 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, |
|
| 1605 | - "Missing parameter value for option '" |
|
| 1591 | + // ----- Return |
|
| 1592 | + return PclZip::errorCode(); |
|
| 1593 | + } |
|
| 1594 | + $i++; |
|
| 1595 | + break; |
|
| 1596 | + |
|
| 1597 | + // ----- Look for options that takes a string |
|
| 1598 | + case PCLZIP_OPT_COMMENT : |
|
| 1599 | + case PCLZIP_OPT_ADD_COMMENT : |
|
| 1600 | + case PCLZIP_OPT_PREPEND_COMMENT : |
|
| 1601 | + // ----- Check the number of parameters |
|
| 1602 | + if (($i+1) >= $p_size) { |
|
| 1603 | + // ----- Error log |
|
| 1604 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, |
|
| 1605 | + "Missing parameter value for option '" |
|
| 1606 | 1606 | .PclZipUtilOptionText($p_options_list[$i]) |
| 1607 | 1607 | ."'"); |
| 1608 | 1608 | |
| 1609 | - // ----- Return |
|
| 1610 | - return PclZip::errorCode(); |
|
| 1611 | - } |
|
| 1609 | + // ----- Return |
|
| 1610 | + return PclZip::errorCode(); |
|
| 1611 | + } |
|
| 1612 | 1612 | |
| 1613 | - // ----- Get the value |
|
| 1614 | - if (is_string($p_options_list[$i+1])) { |
|
| 1615 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1616 | - } |
|
| 1617 | - else { |
|
| 1618 | - // ----- Error log |
|
| 1619 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, |
|
| 1620 | - "Wrong parameter value for option '" |
|
| 1613 | + // ----- Get the value |
|
| 1614 | + if (is_string($p_options_list[$i+1])) { |
|
| 1615 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1616 | + } |
|
| 1617 | + else { |
|
| 1618 | + // ----- Error log |
|
| 1619 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, |
|
| 1620 | + "Wrong parameter value for option '" |
|
| 1621 | 1621 | .PclZipUtilOptionText($p_options_list[$i]) |
| 1622 | 1622 | ."'"); |
| 1623 | 1623 | |
| 1624 | - // ----- Return |
|
| 1625 | - return PclZip::errorCode(); |
|
| 1626 | - } |
|
| 1627 | - $i++; |
|
| 1628 | - break; |
|
| 1629 | - |
|
| 1630 | - // ----- Look for options that request an array of index |
|
| 1631 | - case PCLZIP_OPT_BY_INDEX : |
|
| 1632 | - // ----- Check the number of parameters |
|
| 1633 | - if (($i+1) >= $p_size) { |
|
| 1634 | - // ----- Error log |
|
| 1635 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1636 | - |
|
| 1637 | - // ----- Return |
|
| 1638 | - return PclZip::errorCode(); |
|
| 1639 | - } |
|
| 1624 | + // ----- Return |
|
| 1625 | + return PclZip::errorCode(); |
|
| 1626 | + } |
|
| 1627 | + $i++; |
|
| 1628 | + break; |
|
| 1629 | + |
|
| 1630 | + // ----- Look for options that request an array of index |
|
| 1631 | + case PCLZIP_OPT_BY_INDEX : |
|
| 1632 | + // ----- Check the number of parameters |
|
| 1633 | + if (($i+1) >= $p_size) { |
|
| 1634 | + // ----- Error log |
|
| 1635 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1636 | + |
|
| 1637 | + // ----- Return |
|
| 1638 | + return PclZip::errorCode(); |
|
| 1639 | + } |
|
| 1640 | 1640 | |
| 1641 | - // ----- Get the value |
|
| 1642 | - $v_work_list = array(); |
|
| 1643 | - if (is_string($p_options_list[$i+1])) { |
|
| 1641 | + // ----- Get the value |
|
| 1642 | + $v_work_list = array(); |
|
| 1643 | + if (is_string($p_options_list[$i+1])) { |
|
| 1644 | 1644 | |
| 1645 | - // ----- Remove spaces |
|
| 1646 | - $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); |
|
| 1645 | + // ----- Remove spaces |
|
| 1646 | + $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); |
|
| 1647 | 1647 | |
| 1648 | - // ----- Parse items |
|
| 1649 | - $v_work_list = explode(",", $p_options_list[$i+1]); |
|
| 1650 | - } |
|
| 1651 | - else if (is_integer($p_options_list[$i+1])) { |
|
| 1652 | - $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; |
|
| 1653 | - } |
|
| 1654 | - else if (is_array($p_options_list[$i+1])) { |
|
| 1655 | - $v_work_list = $p_options_list[$i+1]; |
|
| 1656 | - } |
|
| 1657 | - else { |
|
| 1658 | - // ----- Error log |
|
| 1659 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1648 | + // ----- Parse items |
|
| 1649 | + $v_work_list = explode(",", $p_options_list[$i+1]); |
|
| 1650 | + } |
|
| 1651 | + else if (is_integer($p_options_list[$i+1])) { |
|
| 1652 | + $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; |
|
| 1653 | + } |
|
| 1654 | + else if (is_array($p_options_list[$i+1])) { |
|
| 1655 | + $v_work_list = $p_options_list[$i+1]; |
|
| 1656 | + } |
|
| 1657 | + else { |
|
| 1658 | + // ----- Error log |
|
| 1659 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1660 | 1660 | |
| 1661 | - // ----- Return |
|
| 1662 | - return PclZip::errorCode(); |
|
| 1663 | - } |
|
| 1661 | + // ----- Return |
|
| 1662 | + return PclZip::errorCode(); |
|
| 1663 | + } |
|
| 1664 | 1664 | |
| 1665 | - // ----- Reduce the index list |
|
| 1666 | - // each index item in the list must be a couple with a start and |
|
| 1667 | - // an end value : [0,3], [5-5], [8-10], ... |
|
| 1668 | - // ----- Check the format of each item |
|
| 1669 | - $v_sort_flag=false; |
|
| 1670 | - $v_sort_value=0; |
|
| 1671 | - for ($j=0; $j<sizeof($v_work_list); $j++) { |
|
| 1672 | - // ----- Explode the item |
|
| 1673 | - $v_item_list = explode("-", $v_work_list[$j]); |
|
| 1674 | - $v_size_item_list = sizeof($v_item_list); |
|
| 1665 | + // ----- Reduce the index list |
|
| 1666 | + // each index item in the list must be a couple with a start and |
|
| 1667 | + // an end value : [0,3], [5-5], [8-10], ... |
|
| 1668 | + // ----- Check the format of each item |
|
| 1669 | + $v_sort_flag=false; |
|
| 1670 | + $v_sort_value=0; |
|
| 1671 | + for ($j=0; $j<sizeof($v_work_list); $j++) { |
|
| 1672 | + // ----- Explode the item |
|
| 1673 | + $v_item_list = explode("-", $v_work_list[$j]); |
|
| 1674 | + $v_size_item_list = sizeof($v_item_list); |
|
| 1675 | 1675 | |
| 1676 | - // ----- TBC : Here we might check that each item is a |
|
| 1677 | - // real integer ... |
|
| 1676 | + // ----- TBC : Here we might check that each item is a |
|
| 1677 | + // real integer ... |
|
| 1678 | 1678 | |
| 1679 | - // ----- Look for single value |
|
| 1680 | - if ($v_size_item_list == 1) { |
|
| 1681 | - // ----- Set the option value |
|
| 1682 | - $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
|
| 1683 | - $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; |
|
| 1684 | - } |
|
| 1685 | - elseif ($v_size_item_list == 2) { |
|
| 1686 | - // ----- Set the option value |
|
| 1687 | - $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
|
| 1688 | - $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1]; |
|
| 1689 | - } |
|
| 1690 | - else { |
|
| 1691 | - // ----- Error log |
|
| 1692 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1693 | - |
|
| 1694 | - // ----- Return |
|
| 1695 | - return PclZip::errorCode(); |
|
| 1696 | - } |
|
| 1697 | - |
|
| 1698 | - |
|
| 1699 | - // ----- Look for list sort |
|
| 1700 | - if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { |
|
| 1701 | - $v_sort_flag=true; |
|
| 1702 | - |
|
| 1703 | - // ----- TBC : An automatic sort should be writen ... |
|
| 1704 | - // ----- Error log |
|
| 1705 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1706 | - |
|
| 1707 | - // ----- Return |
|
| 1708 | - return PclZip::errorCode(); |
|
| 1709 | - } |
|
| 1710 | - $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; |
|
| 1711 | - } |
|
| 1679 | + // ----- Look for single value |
|
| 1680 | + if ($v_size_item_list == 1) { |
|
| 1681 | + // ----- Set the option value |
|
| 1682 | + $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
|
| 1683 | + $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; |
|
| 1684 | + } |
|
| 1685 | + elseif ($v_size_item_list == 2) { |
|
| 1686 | + // ----- Set the option value |
|
| 1687 | + $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
|
| 1688 | + $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1]; |
|
| 1689 | + } |
|
| 1690 | + else { |
|
| 1691 | + // ----- Error log |
|
| 1692 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1693 | + |
|
| 1694 | + // ----- Return |
|
| 1695 | + return PclZip::errorCode(); |
|
| 1696 | + } |
|
| 1697 | + |
|
| 1698 | + |
|
| 1699 | + // ----- Look for list sort |
|
| 1700 | + if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { |
|
| 1701 | + $v_sort_flag=true; |
|
| 1702 | + |
|
| 1703 | + // ----- TBC : An automatic sort should be writen ... |
|
| 1704 | + // ----- Error log |
|
| 1705 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1706 | + |
|
| 1707 | + // ----- Return |
|
| 1708 | + return PclZip::errorCode(); |
|
| 1709 | + } |
|
| 1710 | + $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; |
|
| 1711 | + } |
|
| 1712 | 1712 | |
| 1713 | - // ----- Sort the items |
|
| 1714 | - if ($v_sort_flag) { |
|
| 1715 | - // TBC : To Be Completed |
|
| 1716 | - } |
|
| 1713 | + // ----- Sort the items |
|
| 1714 | + if ($v_sort_flag) { |
|
| 1715 | + // TBC : To Be Completed |
|
| 1716 | + } |
|
| 1717 | 1717 | |
| 1718 | - // ----- Next option |
|
| 1719 | - $i++; |
|
| 1720 | - break; |
|
| 1721 | - |
|
| 1722 | - // ----- Look for options that request no value |
|
| 1723 | - case PCLZIP_OPT_REMOVE_ALL_PATH : |
|
| 1724 | - case PCLZIP_OPT_EXTRACT_AS_STRING : |
|
| 1725 | - case PCLZIP_OPT_NO_COMPRESSION : |
|
| 1726 | - case PCLZIP_OPT_EXTRACT_IN_OUTPUT : |
|
| 1727 | - case PCLZIP_OPT_REPLACE_NEWER : |
|
| 1728 | - case PCLZIP_OPT_STOP_ON_ERROR : |
|
| 1729 | - $v_result_list[$p_options_list[$i]] = true; |
|
| 1730 | - break; |
|
| 1731 | - |
|
| 1732 | - // ----- Look for options that request an octal value |
|
| 1733 | - case PCLZIP_OPT_SET_CHMOD : |
|
| 1734 | - // ----- Check the number of parameters |
|
| 1735 | - if (($i+1) >= $p_size) { |
|
| 1736 | - // ----- Error log |
|
| 1737 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1738 | - |
|
| 1739 | - // ----- Return |
|
| 1740 | - return PclZip::errorCode(); |
|
| 1741 | - } |
|
| 1718 | + // ----- Next option |
|
| 1719 | + $i++; |
|
| 1720 | + break; |
|
| 1721 | + |
|
| 1722 | + // ----- Look for options that request no value |
|
| 1723 | + case PCLZIP_OPT_REMOVE_ALL_PATH : |
|
| 1724 | + case PCLZIP_OPT_EXTRACT_AS_STRING : |
|
| 1725 | + case PCLZIP_OPT_NO_COMPRESSION : |
|
| 1726 | + case PCLZIP_OPT_EXTRACT_IN_OUTPUT : |
|
| 1727 | + case PCLZIP_OPT_REPLACE_NEWER : |
|
| 1728 | + case PCLZIP_OPT_STOP_ON_ERROR : |
|
| 1729 | + $v_result_list[$p_options_list[$i]] = true; |
|
| 1730 | + break; |
|
| 1731 | + |
|
| 1732 | + // ----- Look for options that request an octal value |
|
| 1733 | + case PCLZIP_OPT_SET_CHMOD : |
|
| 1734 | + // ----- Check the number of parameters |
|
| 1735 | + if (($i+1) >= $p_size) { |
|
| 1736 | + // ----- Error log |
|
| 1737 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1738 | + |
|
| 1739 | + // ----- Return |
|
| 1740 | + return PclZip::errorCode(); |
|
| 1741 | + } |
|
| 1742 | 1742 | |
| 1743 | - // ----- Get the value |
|
| 1744 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1745 | - $i++; |
|
| 1746 | - break; |
|
| 1747 | - |
|
| 1748 | - // ----- Look for options that request a call-back |
|
| 1749 | - case PCLZIP_CB_PRE_EXTRACT : |
|
| 1750 | - case PCLZIP_CB_POST_EXTRACT : |
|
| 1751 | - case PCLZIP_CB_PRE_ADD : |
|
| 1752 | - case PCLZIP_CB_POST_ADD : |
|
| 1753 | - /* for futur use |
|
| 1743 | + // ----- Get the value |
|
| 1744 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1745 | + $i++; |
|
| 1746 | + break; |
|
| 1747 | + |
|
| 1748 | + // ----- Look for options that request a call-back |
|
| 1749 | + case PCLZIP_CB_PRE_EXTRACT : |
|
| 1750 | + case PCLZIP_CB_POST_EXTRACT : |
|
| 1751 | + case PCLZIP_CB_PRE_ADD : |
|
| 1752 | + case PCLZIP_CB_POST_ADD : |
|
| 1753 | + /* for futur use |
|
| 1754 | 1754 | case PCLZIP_CB_PRE_DELETE : |
| 1755 | 1755 | case PCLZIP_CB_POST_DELETE : |
| 1756 | 1756 | case PCLZIP_CB_PRE_LIST : |
| 1757 | 1757 | case PCLZIP_CB_POST_LIST : |
| 1758 | 1758 | */ |
| 1759 | - // ----- Check the number of parameters |
|
| 1760 | - if (($i+1) >= $p_size) { |
|
| 1761 | - // ----- Error log |
|
| 1762 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1759 | + // ----- Check the number of parameters |
|
| 1760 | + if (($i+1) >= $p_size) { |
|
| 1761 | + // ----- Error log |
|
| 1762 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1763 | 1763 | |
| 1764 | - // ----- Return |
|
| 1765 | - return PclZip::errorCode(); |
|
| 1766 | - } |
|
| 1764 | + // ----- Return |
|
| 1765 | + return PclZip::errorCode(); |
|
| 1766 | + } |
|
| 1767 | 1767 | |
| 1768 | - // ----- Get the value |
|
| 1769 | - $v_function_name = $p_options_list[$i+1]; |
|
| 1768 | + // ----- Get the value |
|
| 1769 | + $v_function_name = $p_options_list[$i+1]; |
|
| 1770 | 1770 | |
| 1771 | - // ----- Check that the value is a valid existing function |
|
| 1772 | - if (!function_exists($v_function_name)) { |
|
| 1773 | - // ----- Error log |
|
| 1774 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1771 | + // ----- Check that the value is a valid existing function |
|
| 1772 | + if (!function_exists($v_function_name)) { |
|
| 1773 | + // ----- Error log |
|
| 1774 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1775 | 1775 | |
| 1776 | - // ----- Return |
|
| 1777 | - return PclZip::errorCode(); |
|
| 1778 | - } |
|
| 1776 | + // ----- Return |
|
| 1777 | + return PclZip::errorCode(); |
|
| 1778 | + } |
|
| 1779 | 1779 | |
| 1780 | - // ----- Set the attribute |
|
| 1781 | - $v_result_list[$p_options_list[$i]] = $v_function_name; |
|
| 1782 | - $i++; |
|
| 1783 | - break; |
|
| 1780 | + // ----- Set the attribute |
|
| 1781 | + $v_result_list[$p_options_list[$i]] = $v_function_name; |
|
| 1782 | + $i++; |
|
| 1783 | + break; |
|
| 1784 | 1784 | |
| 1785 | - default : |
|
| 1786 | - // ----- Error log |
|
| 1787 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
|
| 1788 | - "Unknown parameter '" |
|
| 1785 | + default : |
|
| 1786 | + // ----- Error log |
|
| 1787 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
|
| 1788 | + "Unknown parameter '" |
|
| 1789 | 1789 | .$p_options_list[$i]."'"); |
| 1790 | 1790 | |
| 1791 | - // ----- Return |
|
| 1792 | - return PclZip::errorCode(); |
|
| 1793 | - } |
|
| 1791 | + // ----- Return |
|
| 1792 | + return PclZip::errorCode(); |
|
| 1793 | + } |
|
| 1794 | 1794 | |
| 1795 | - // ----- Next options |
|
| 1796 | - $i++; |
|
| 1797 | - } |
|
| 1795 | + // ----- Next options |
|
| 1796 | + $i++; |
|
| 1797 | + } |
|
| 1798 | 1798 | |
| 1799 | - // ----- Look for mandatory options |
|
| 1800 | - if ($v_requested_options !== false) { |
|
| 1801 | - for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
|
| 1802 | - // ----- Look for mandatory option |
|
| 1803 | - if ($v_requested_options[$key] == 'mandatory') { |
|
| 1804 | - // ----- Look if present |
|
| 1805 | - if (!isset($v_result_list[$key])) { |
|
| 1806 | - // ----- Error log |
|
| 1807 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
|
| 1808 | - |
|
| 1809 | - // ----- Return |
|
| 1810 | - return PclZip::errorCode(); |
|
| 1811 | - } |
|
| 1812 | - } |
|
| 1813 | - } |
|
| 1814 | - } |
|
| 1799 | + // ----- Look for mandatory options |
|
| 1800 | + if ($v_requested_options !== false) { |
|
| 1801 | + for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
|
| 1802 | + // ----- Look for mandatory option |
|
| 1803 | + if ($v_requested_options[$key] == 'mandatory') { |
|
| 1804 | + // ----- Look if present |
|
| 1805 | + if (!isset($v_result_list[$key])) { |
|
| 1806 | + // ----- Error log |
|
| 1807 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
|
| 1808 | + |
|
| 1809 | + // ----- Return |
|
| 1810 | + return PclZip::errorCode(); |
|
| 1811 | + } |
|
| 1812 | + } |
|
| 1813 | + } |
|
| 1814 | + } |
|
| 1815 | 1815 | |
| 1816 | - // ----- Look for default values |
|
| 1817 | - if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { |
|
| 1816 | + // ----- Look for default values |
|
| 1817 | + if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { |
|
| 1818 | 1818 | |
| 1819 | - } |
|
| 1819 | + } |
|
| 1820 | 1820 | |
| 1821 | - // ----- Return |
|
| 1822 | - return $v_result; |
|
| 1821 | + // ----- Return |
|
| 1822 | + return $v_result; |
|
| 1823 | 1823 | } |
| 1824 | 1824 | // -------------------------------------------------------------------------------- |
| 1825 | 1825 | |
@@ -1831,37 +1831,37 @@ discard block |
||
| 1831 | 1831 | // -------------------------------------------------------------------------------- |
| 1832 | 1832 | function privOptionDefaultThreshold(&$p_options) |
| 1833 | 1833 | { |
| 1834 | - $v_result=1; |
|
| 1834 | + $v_result=1; |
|
| 1835 | 1835 | |
| 1836 | - if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
|
| 1837 | - || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) { |
|
| 1838 | - return $v_result; |
|
| 1839 | - } |
|
| 1836 | + if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
|
| 1837 | + || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) { |
|
| 1838 | + return $v_result; |
|
| 1839 | + } |
|
| 1840 | 1840 | |
| 1841 | - // ----- Get 'memory_limit' configuration value |
|
| 1842 | - $v_memory_limit = ini_get('memory_limit'); |
|
| 1843 | - $v_memory_limit = trim($v_memory_limit); |
|
| 1844 | - $last = strtolower(substr($v_memory_limit, -1)); |
|
| 1841 | + // ----- Get 'memory_limit' configuration value |
|
| 1842 | + $v_memory_limit = ini_get('memory_limit'); |
|
| 1843 | + $v_memory_limit = trim($v_memory_limit); |
|
| 1844 | + $last = strtolower(substr($v_memory_limit, -1)); |
|
| 1845 | 1845 | |
| 1846 | - if($last == 'g') |
|
| 1847 | - //$v_memory_limit = $v_memory_limit*1024*1024*1024; |
|
| 1848 | - $v_memory_limit = $v_memory_limit*1073741824; |
|
| 1849 | - if($last == 'm') |
|
| 1850 | - //$v_memory_limit = $v_memory_limit*1024*1024; |
|
| 1851 | - $v_memory_limit = $v_memory_limit*1048576; |
|
| 1852 | - if($last == 'k') |
|
| 1853 | - $v_memory_limit = $v_memory_limit*1024; |
|
| 1846 | + if($last == 'g') |
|
| 1847 | + //$v_memory_limit = $v_memory_limit*1024*1024*1024; |
|
| 1848 | + $v_memory_limit = $v_memory_limit*1073741824; |
|
| 1849 | + if($last == 'm') |
|
| 1850 | + //$v_memory_limit = $v_memory_limit*1024*1024; |
|
| 1851 | + $v_memory_limit = $v_memory_limit*1048576; |
|
| 1852 | + if($last == 'k') |
|
| 1853 | + $v_memory_limit = $v_memory_limit*1024; |
|
| 1854 | 1854 | |
| 1855 | - $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO); |
|
| 1855 | + $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO); |
|
| 1856 | 1856 | |
| 1857 | 1857 | |
| 1858 | - // ----- Sanity check : No threshold if value lower than 1M |
|
| 1859 | - if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) { |
|
| 1860 | - unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]); |
|
| 1861 | - } |
|
| 1858 | + // ----- Sanity check : No threshold if value lower than 1M |
|
| 1859 | + if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) { |
|
| 1860 | + unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]); |
|
| 1861 | + } |
|
| 1862 | 1862 | |
| 1863 | - // ----- Return |
|
| 1864 | - return $v_result; |
|
| 1863 | + // ----- Return |
|
| 1864 | + return $v_result; |
|
| 1865 | 1865 | } |
| 1866 | 1866 | // -------------------------------------------------------------------------------- |
| 1867 | 1867 | |
@@ -1875,116 +1875,116 @@ discard block |
||
| 1875 | 1875 | // -------------------------------------------------------------------------------- |
| 1876 | 1876 | function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) |
| 1877 | 1877 | { |
| 1878 | - $v_result=1; |
|
| 1878 | + $v_result=1; |
|
| 1879 | 1879 | |
| 1880 | - // ----- For each file in the list check the attributes |
|
| 1881 | - foreach ($p_file_list as $v_key => $v_value) { |
|
| 1880 | + // ----- For each file in the list check the attributes |
|
| 1881 | + foreach ($p_file_list as $v_key => $v_value) { |
|
| 1882 | 1882 | |
| 1883 | - // ----- Check if the option is supported |
|
| 1884 | - if (!isset($v_requested_options[$v_key])) { |
|
| 1885 | - // ----- Error log |
|
| 1886 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); |
|
| 1883 | + // ----- Check if the option is supported |
|
| 1884 | + if (!isset($v_requested_options[$v_key])) { |
|
| 1885 | + // ----- Error log |
|
| 1886 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); |
|
| 1887 | 1887 | |
| 1888 | - // ----- Return |
|
| 1889 | - return PclZip::errorCode(); |
|
| 1890 | - } |
|
| 1888 | + // ----- Return |
|
| 1889 | + return PclZip::errorCode(); |
|
| 1890 | + } |
|
| 1891 | 1891 | |
| 1892 | - // ----- Look for attribute |
|
| 1893 | - switch ($v_key) { |
|
| 1894 | - case PCLZIP_ATT_FILE_NAME : |
|
| 1895 | - if (!is_string($v_value)) { |
|
| 1896 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1897 | - return PclZip::errorCode(); |
|
| 1898 | - } |
|
| 1892 | + // ----- Look for attribute |
|
| 1893 | + switch ($v_key) { |
|
| 1894 | + case PCLZIP_ATT_FILE_NAME : |
|
| 1895 | + if (!is_string($v_value)) { |
|
| 1896 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1897 | + return PclZip::errorCode(); |
|
| 1898 | + } |
|
| 1899 | 1899 | |
| 1900 | - $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); |
|
| 1900 | + $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); |
|
| 1901 | 1901 | |
| 1902 | - if ($p_filedescr['filename'] == '') { |
|
| 1903 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1904 | - return PclZip::errorCode(); |
|
| 1905 | - } |
|
| 1902 | + if ($p_filedescr['filename'] == '') { |
|
| 1903 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1904 | + return PclZip::errorCode(); |
|
| 1905 | + } |
|
| 1906 | 1906 | |
| 1907 | - break; |
|
| 1907 | + break; |
|
| 1908 | 1908 | |
| 1909 | - case PCLZIP_ATT_FILE_NEW_SHORT_NAME : |
|
| 1910 | - if (!is_string($v_value)) { |
|
| 1911 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1912 | - return PclZip::errorCode(); |
|
| 1913 | - } |
|
| 1909 | + case PCLZIP_ATT_FILE_NEW_SHORT_NAME : |
|
| 1910 | + if (!is_string($v_value)) { |
|
| 1911 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1912 | + return PclZip::errorCode(); |
|
| 1913 | + } |
|
| 1914 | 1914 | |
| 1915 | - $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); |
|
| 1915 | + $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); |
|
| 1916 | 1916 | |
| 1917 | - if ($p_filedescr['new_short_name'] == '') { |
|
| 1918 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1919 | - return PclZip::errorCode(); |
|
| 1920 | - } |
|
| 1921 | - break; |
|
| 1917 | + if ($p_filedescr['new_short_name'] == '') { |
|
| 1918 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1919 | + return PclZip::errorCode(); |
|
| 1920 | + } |
|
| 1921 | + break; |
|
| 1922 | 1922 | |
| 1923 | - case PCLZIP_ATT_FILE_NEW_FULL_NAME : |
|
| 1924 | - if (!is_string($v_value)) { |
|
| 1925 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1926 | - return PclZip::errorCode(); |
|
| 1927 | - } |
|
| 1923 | + case PCLZIP_ATT_FILE_NEW_FULL_NAME : |
|
| 1924 | + if (!is_string($v_value)) { |
|
| 1925 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1926 | + return PclZip::errorCode(); |
|
| 1927 | + } |
|
| 1928 | 1928 | |
| 1929 | - $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); |
|
| 1929 | + $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); |
|
| 1930 | 1930 | |
| 1931 | - if ($p_filedescr['new_full_name'] == '') { |
|
| 1932 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1933 | - return PclZip::errorCode(); |
|
| 1934 | - } |
|
| 1935 | - break; |
|
| 1931 | + if ($p_filedescr['new_full_name'] == '') { |
|
| 1932 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1933 | + return PclZip::errorCode(); |
|
| 1934 | + } |
|
| 1935 | + break; |
|
| 1936 | 1936 | |
| 1937 | - // ----- Look for options that takes a string |
|
| 1938 | - case PCLZIP_ATT_FILE_COMMENT : |
|
| 1939 | - if (!is_string($v_value)) { |
|
| 1940 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1941 | - return PclZip::errorCode(); |
|
| 1942 | - } |
|
| 1937 | + // ----- Look for options that takes a string |
|
| 1938 | + case PCLZIP_ATT_FILE_COMMENT : |
|
| 1939 | + if (!is_string($v_value)) { |
|
| 1940 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1941 | + return PclZip::errorCode(); |
|
| 1942 | + } |
|
| 1943 | 1943 | |
| 1944 | - $p_filedescr['comment'] = $v_value; |
|
| 1945 | - break; |
|
| 1944 | + $p_filedescr['comment'] = $v_value; |
|
| 1945 | + break; |
|
| 1946 | 1946 | |
| 1947 | - case PCLZIP_ATT_FILE_MTIME : |
|
| 1948 | - if (!is_integer($v_value)) { |
|
| 1949 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1950 | - return PclZip::errorCode(); |
|
| 1951 | - } |
|
| 1947 | + case PCLZIP_ATT_FILE_MTIME : |
|
| 1948 | + if (!is_integer($v_value)) { |
|
| 1949 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1950 | + return PclZip::errorCode(); |
|
| 1951 | + } |
|
| 1952 | 1952 | |
| 1953 | - $p_filedescr['mtime'] = $v_value; |
|
| 1954 | - break; |
|
| 1953 | + $p_filedescr['mtime'] = $v_value; |
|
| 1954 | + break; |
|
| 1955 | 1955 | |
| 1956 | - case PCLZIP_ATT_FILE_CONTENT : |
|
| 1957 | - $p_filedescr['content'] = $v_value; |
|
| 1958 | - break; |
|
| 1956 | + case PCLZIP_ATT_FILE_CONTENT : |
|
| 1957 | + $p_filedescr['content'] = $v_value; |
|
| 1958 | + break; |
|
| 1959 | 1959 | |
| 1960 | - default : |
|
| 1961 | - // ----- Error log |
|
| 1962 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
|
| 1963 | - "Unknown parameter '".$v_key."'"); |
|
| 1960 | + default : |
|
| 1961 | + // ----- Error log |
|
| 1962 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
|
| 1963 | + "Unknown parameter '".$v_key."'"); |
|
| 1964 | 1964 | |
| 1965 | - // ----- Return |
|
| 1966 | - return PclZip::errorCode(); |
|
| 1967 | - } |
|
| 1965 | + // ----- Return |
|
| 1966 | + return PclZip::errorCode(); |
|
| 1967 | + } |
|
| 1968 | 1968 | |
| 1969 | - // ----- Look for mandatory options |
|
| 1970 | - if ($v_requested_options !== false) { |
|
| 1971 | - for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
|
| 1972 | - // ----- Look for mandatory option |
|
| 1973 | - if ($v_requested_options[$key] == 'mandatory') { |
|
| 1974 | - // ----- Look if present |
|
| 1975 | - if (!isset($p_file_list[$key])) { |
|
| 1976 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
|
| 1977 | - return PclZip::errorCode(); |
|
| 1978 | - } |
|
| 1979 | - } |
|
| 1980 | - } |
|
| 1981 | - } |
|
| 1969 | + // ----- Look for mandatory options |
|
| 1970 | + if ($v_requested_options !== false) { |
|
| 1971 | + for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
|
| 1972 | + // ----- Look for mandatory option |
|
| 1973 | + if ($v_requested_options[$key] == 'mandatory') { |
|
| 1974 | + // ----- Look if present |
|
| 1975 | + if (!isset($p_file_list[$key])) { |
|
| 1976 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
|
| 1977 | + return PclZip::errorCode(); |
|
| 1978 | + } |
|
| 1979 | + } |
|
| 1980 | + } |
|
| 1981 | + } |
|
| 1982 | 1982 | |
| 1983 | - // end foreach |
|
| 1984 | - } |
|
| 1983 | + // end foreach |
|
| 1984 | + } |
|
| 1985 | 1985 | |
| 1986 | - // ----- Return |
|
| 1987 | - return $v_result; |
|
| 1986 | + // ----- Return |
|
| 1987 | + return $v_result; |
|
| 1988 | 1988 | } |
| 1989 | 1989 | // -------------------------------------------------------------------------------- |
| 1990 | 1990 | |
@@ -2004,120 +2004,120 @@ discard block |
||
| 2004 | 2004 | // -------------------------------------------------------------------------------- |
| 2005 | 2005 | function privFileDescrExpand(&$p_filedescr_list, &$p_options) |
| 2006 | 2006 | { |
| 2007 | - $v_result=1; |
|
| 2007 | + $v_result=1; |
|
| 2008 | 2008 | |
| 2009 | - // ----- Create a result list |
|
| 2010 | - $v_result_list = array(); |
|
| 2009 | + // ----- Create a result list |
|
| 2010 | + $v_result_list = array(); |
|
| 2011 | 2011 | |
| 2012 | - // ----- Look each entry |
|
| 2013 | - for ($i=0; $i<sizeof($p_filedescr_list); $i++) { |
|
| 2012 | + // ----- Look each entry |
|
| 2013 | + for ($i=0; $i<sizeof($p_filedescr_list); $i++) { |
|
| 2014 | 2014 | |
| 2015 | - // ----- Get filedescr |
|
| 2016 | - $v_descr = $p_filedescr_list[$i]; |
|
| 2015 | + // ----- Get filedescr |
|
| 2016 | + $v_descr = $p_filedescr_list[$i]; |
|
| 2017 | 2017 | |
| 2018 | - // ----- Reduce the filename |
|
| 2019 | - $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false); |
|
| 2020 | - $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); |
|
| 2018 | + // ----- Reduce the filename |
|
| 2019 | + $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false); |
|
| 2020 | + $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); |
|
| 2021 | 2021 | |
| 2022 | - // ----- Look for real file or folder |
|
| 2023 | - if (file_exists($v_descr['filename'])) { |
|
| 2024 | - if (@is_file($v_descr['filename'])) { |
|
| 2025 | - $v_descr['type'] = 'file'; |
|
| 2026 | - } |
|
| 2027 | - else if (@is_dir($v_descr['filename'])) { |
|
| 2028 | - $v_descr['type'] = 'folder'; |
|
| 2029 | - } |
|
| 2030 | - else if (@is_link($v_descr['filename'])) { |
|
| 2031 | - // skip |
|
| 2032 | - continue; |
|
| 2033 | - } |
|
| 2034 | - else { |
|
| 2035 | - // skip |
|
| 2036 | - continue; |
|
| 2037 | - } |
|
| 2038 | - } |
|
| 2022 | + // ----- Look for real file or folder |
|
| 2023 | + if (file_exists($v_descr['filename'])) { |
|
| 2024 | + if (@is_file($v_descr['filename'])) { |
|
| 2025 | + $v_descr['type'] = 'file'; |
|
| 2026 | + } |
|
| 2027 | + else if (@is_dir($v_descr['filename'])) { |
|
| 2028 | + $v_descr['type'] = 'folder'; |
|
| 2029 | + } |
|
| 2030 | + else if (@is_link($v_descr['filename'])) { |
|
| 2031 | + // skip |
|
| 2032 | + continue; |
|
| 2033 | + } |
|
| 2034 | + else { |
|
| 2035 | + // skip |
|
| 2036 | + continue; |
|
| 2037 | + } |
|
| 2038 | + } |
|
| 2039 | 2039 | |
| 2040 | - // ----- Look for string added as file |
|
| 2041 | - else if (isset($v_descr['content'])) { |
|
| 2042 | - $v_descr['type'] = 'virtual_file'; |
|
| 2043 | - } |
|
| 2040 | + // ----- Look for string added as file |
|
| 2041 | + else if (isset($v_descr['content'])) { |
|
| 2042 | + $v_descr['type'] = 'virtual_file'; |
|
| 2043 | + } |
|
| 2044 | 2044 | |
| 2045 | - // ----- Missing file |
|
| 2046 | - else { |
|
| 2047 | - // ----- Error log |
|
| 2048 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist"); |
|
| 2045 | + // ----- Missing file |
|
| 2046 | + else { |
|
| 2047 | + // ----- Error log |
|
| 2048 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist"); |
|
| 2049 | 2049 | |
| 2050 | - // ----- Return |
|
| 2051 | - return PclZip::errorCode(); |
|
| 2052 | - } |
|
| 2050 | + // ----- Return |
|
| 2051 | + return PclZip::errorCode(); |
|
| 2052 | + } |
|
| 2053 | 2053 | |
| 2054 | - // ----- Calculate the stored filename |
|
| 2055 | - $this->privCalculateStoredFilename($v_descr, $p_options); |
|
| 2054 | + // ----- Calculate the stored filename |
|
| 2055 | + $this->privCalculateStoredFilename($v_descr, $p_options); |
|
| 2056 | 2056 | |
| 2057 | - // ----- Add the descriptor in result list |
|
| 2058 | - $v_result_list[sizeof($v_result_list)] = $v_descr; |
|
| 2057 | + // ----- Add the descriptor in result list |
|
| 2058 | + $v_result_list[sizeof($v_result_list)] = $v_descr; |
|
| 2059 | 2059 | |
| 2060 | - // ----- Look for folder |
|
| 2061 | - if ($v_descr['type'] == 'folder') { |
|
| 2062 | - // ----- List of items in folder |
|
| 2063 | - $v_dirlist_descr = array(); |
|
| 2064 | - $v_dirlist_nb = 0; |
|
| 2065 | - if ($v_folder_handler = @opendir($v_descr['filename'])) { |
|
| 2066 | - while (($v_item_handler = @readdir($v_folder_handler)) !== false) { |
|
| 2067 | - |
|
| 2068 | - // ----- Skip '.' and '..' |
|
| 2069 | - if (($v_item_handler == '.') || ($v_item_handler == '..')) { |
|
| 2070 | - continue; |
|
| 2071 | - } |
|
| 2060 | + // ----- Look for folder |
|
| 2061 | + if ($v_descr['type'] == 'folder') { |
|
| 2062 | + // ----- List of items in folder |
|
| 2063 | + $v_dirlist_descr = array(); |
|
| 2064 | + $v_dirlist_nb = 0; |
|
| 2065 | + if ($v_folder_handler = @opendir($v_descr['filename'])) { |
|
| 2066 | + while (($v_item_handler = @readdir($v_folder_handler)) !== false) { |
|
| 2067 | + |
|
| 2068 | + // ----- Skip '.' and '..' |
|
| 2069 | + if (($v_item_handler == '.') || ($v_item_handler == '..')) { |
|
| 2070 | + continue; |
|
| 2071 | + } |
|
| 2072 | 2072 | |
| 2073 | - // ----- Compose the full filename |
|
| 2074 | - $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; |
|
| 2073 | + // ----- Compose the full filename |
|
| 2074 | + $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; |
|
| 2075 | 2075 | |
| 2076 | - // ----- Look for different stored filename |
|
| 2077 | - // Because the name of the folder was changed, the name of the |
|
| 2078 | - // files/sub-folders also change |
|
| 2079 | - if (($v_descr['stored_filename'] != $v_descr['filename']) |
|
| 2080 | - && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) { |
|
| 2081 | - if ($v_descr['stored_filename'] != '') { |
|
| 2082 | - $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; |
|
| 2083 | - } |
|
| 2084 | - else { |
|
| 2085 | - $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; |
|
| 2086 | - } |
|
| 2087 | - } |
|
| 2076 | + // ----- Look for different stored filename |
|
| 2077 | + // Because the name of the folder was changed, the name of the |
|
| 2078 | + // files/sub-folders also change |
|
| 2079 | + if (($v_descr['stored_filename'] != $v_descr['filename']) |
|
| 2080 | + && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) { |
|
| 2081 | + if ($v_descr['stored_filename'] != '') { |
|
| 2082 | + $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; |
|
| 2083 | + } |
|
| 2084 | + else { |
|
| 2085 | + $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; |
|
| 2086 | + } |
|
| 2087 | + } |
|
| 2088 | 2088 | |
| 2089 | - $v_dirlist_nb++; |
|
| 2090 | - } |
|
| 2089 | + $v_dirlist_nb++; |
|
| 2090 | + } |
|
| 2091 | 2091 | |
| 2092 | - @closedir($v_folder_handler); |
|
| 2093 | - } |
|
| 2094 | - else { |
|
| 2095 | - // TBC : unable to open folder in read mode |
|
| 2096 | - } |
|
| 2092 | + @closedir($v_folder_handler); |
|
| 2093 | + } |
|
| 2094 | + else { |
|
| 2095 | + // TBC : unable to open folder in read mode |
|
| 2096 | + } |
|
| 2097 | 2097 | |
| 2098 | - // ----- Expand each element of the list |
|
| 2099 | - if ($v_dirlist_nb != 0) { |
|
| 2100 | - // ----- Expand |
|
| 2101 | - if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { |
|
| 2102 | - return $v_result; |
|
| 2103 | - } |
|
| 2098 | + // ----- Expand each element of the list |
|
| 2099 | + if ($v_dirlist_nb != 0) { |
|
| 2100 | + // ----- Expand |
|
| 2101 | + if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { |
|
| 2102 | + return $v_result; |
|
| 2103 | + } |
|
| 2104 | 2104 | |
| 2105 | - // ----- Concat the resulting list |
|
| 2106 | - $v_result_list = array_merge($v_result_list, $v_dirlist_descr); |
|
| 2107 | - } |
|
| 2108 | - else { |
|
| 2109 | - } |
|
| 2105 | + // ----- Concat the resulting list |
|
| 2106 | + $v_result_list = array_merge($v_result_list, $v_dirlist_descr); |
|
| 2107 | + } |
|
| 2108 | + else { |
|
| 2109 | + } |
|
| 2110 | 2110 | |
| 2111 | - // ----- Free local array |
|
| 2112 | - unset($v_dirlist_descr); |
|
| 2113 | - } |
|
| 2114 | - } |
|
| 2111 | + // ----- Free local array |
|
| 2112 | + unset($v_dirlist_descr); |
|
| 2113 | + } |
|
| 2114 | + } |
|
| 2115 | 2115 | |
| 2116 | - // ----- Get the result list |
|
| 2117 | - $p_filedescr_list = $v_result_list; |
|
| 2116 | + // ----- Get the result list |
|
| 2117 | + $p_filedescr_list = $v_result_list; |
|
| 2118 | 2118 | |
| 2119 | - // ----- Return |
|
| 2120 | - return $v_result; |
|
| 2119 | + // ----- Return |
|
| 2120 | + return $v_result; |
|
| 2121 | 2121 | } |
| 2122 | 2122 | // -------------------------------------------------------------------------------- |
| 2123 | 2123 | |
@@ -2129,30 +2129,30 @@ discard block |
||
| 2129 | 2129 | // -------------------------------------------------------------------------------- |
| 2130 | 2130 | function privCreate($p_filedescr_list, &$p_result_list, &$p_options) |
| 2131 | 2131 | { |
| 2132 | - $v_result=1; |
|
| 2133 | - $v_list_detail = array(); |
|
| 2132 | + $v_result=1; |
|
| 2133 | + $v_list_detail = array(); |
|
| 2134 | 2134 | |
| 2135 | - // ----- Magic quotes trick |
|
| 2136 | - $this->privDisableMagicQuotes(); |
|
| 2137 | - |
|
| 2138 | - // ----- Open the file in write mode |
|
| 2139 | - if (($v_result = $this->privOpenFd('wb')) != 1) |
|
| 2140 | - { |
|
| 2141 | - // ----- Return |
|
| 2142 | - return $v_result; |
|
| 2143 | - } |
|
| 2135 | + // ----- Magic quotes trick |
|
| 2136 | + $this->privDisableMagicQuotes(); |
|
| 2137 | + |
|
| 2138 | + // ----- Open the file in write mode |
|
| 2139 | + if (($v_result = $this->privOpenFd('wb')) != 1) |
|
| 2140 | + { |
|
| 2141 | + // ----- Return |
|
| 2142 | + return $v_result; |
|
| 2143 | + } |
|
| 2144 | 2144 | |
| 2145 | - // ----- Add the list of files |
|
| 2146 | - $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options); |
|
| 2145 | + // ----- Add the list of files |
|
| 2146 | + $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options); |
|
| 2147 | 2147 | |
| 2148 | - // ----- Close |
|
| 2149 | - $this->privCloseFd(); |
|
| 2148 | + // ----- Close |
|
| 2149 | + $this->privCloseFd(); |
|
| 2150 | 2150 | |
| 2151 | - // ----- Magic quotes trick |
|
| 2152 | - $this->privSwapBackMagicQuotes(); |
|
| 2151 | + // ----- Magic quotes trick |
|
| 2152 | + $this->privSwapBackMagicQuotes(); |
|
| 2153 | 2153 | |
| 2154 | - // ----- Return |
|
| 2155 | - return $v_result; |
|
| 2154 | + // ----- Return |
|
| 2155 | + return $v_result; |
|
| 2156 | 2156 | } |
| 2157 | 2157 | // -------------------------------------------------------------------------------- |
| 2158 | 2158 | |
@@ -2164,175 +2164,175 @@ discard block |
||
| 2164 | 2164 | // -------------------------------------------------------------------------------- |
| 2165 | 2165 | function privAdd($p_filedescr_list, &$p_result_list, &$p_options) |
| 2166 | 2166 | { |
| 2167 | - $v_result=1; |
|
| 2168 | - $v_list_detail = array(); |
|
| 2167 | + $v_result=1; |
|
| 2168 | + $v_list_detail = array(); |
|
| 2169 | 2169 | |
| 2170 | - // ----- Look if the archive exists or is empty |
|
| 2171 | - if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) |
|
| 2172 | - { |
|
| 2170 | + // ----- Look if the archive exists or is empty |
|
| 2171 | + if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) |
|
| 2172 | + { |
|
| 2173 | 2173 | |
| 2174 | - // ----- Do a create |
|
| 2175 | - $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); |
|
| 2174 | + // ----- Do a create |
|
| 2175 | + $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); |
|
| 2176 | 2176 | |
| 2177 | - // ----- Return |
|
| 2178 | - return $v_result; |
|
| 2179 | - } |
|
| 2180 | - // ----- Magic quotes trick |
|
| 2181 | - $this->privDisableMagicQuotes(); |
|
| 2177 | + // ----- Return |
|
| 2178 | + return $v_result; |
|
| 2179 | + } |
|
| 2180 | + // ----- Magic quotes trick |
|
| 2181 | + $this->privDisableMagicQuotes(); |
|
| 2182 | 2182 | |
| 2183 | - // ----- Open the zip file |
|
| 2184 | - if (($v_result=$this->privOpenFd('rb')) != 1) |
|
| 2185 | - { |
|
| 2186 | - // ----- Magic quotes trick |
|
| 2187 | - $this->privSwapBackMagicQuotes(); |
|
| 2183 | + // ----- Open the zip file |
|
| 2184 | + if (($v_result=$this->privOpenFd('rb')) != 1) |
|
| 2185 | + { |
|
| 2186 | + // ----- Magic quotes trick |
|
| 2187 | + $this->privSwapBackMagicQuotes(); |
|
| 2188 | 2188 | |
| 2189 | - // ----- Return |
|
| 2190 | - return $v_result; |
|
| 2191 | - } |
|
| 2189 | + // ----- Return |
|
| 2190 | + return $v_result; |
|
| 2191 | + } |
|
| 2192 | 2192 | |
| 2193 | - // ----- Read the central directory informations |
|
| 2194 | - $v_central_dir = array(); |
|
| 2195 | - if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 2196 | - { |
|
| 2197 | - $this->privCloseFd(); |
|
| 2198 | - $this->privSwapBackMagicQuotes(); |
|
| 2199 | - return $v_result; |
|
| 2200 | - } |
|
| 2193 | + // ----- Read the central directory informations |
|
| 2194 | + $v_central_dir = array(); |
|
| 2195 | + if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 2196 | + { |
|
| 2197 | + $this->privCloseFd(); |
|
| 2198 | + $this->privSwapBackMagicQuotes(); |
|
| 2199 | + return $v_result; |
|
| 2200 | + } |
|
| 2201 | 2201 | |
| 2202 | - // ----- Go to beginning of File |
|
| 2203 | - @rewind($this->zip_fd); |
|
| 2202 | + // ----- Go to beginning of File |
|
| 2203 | + @rewind($this->zip_fd); |
|
| 2204 | 2204 | |
| 2205 | - // ----- Creates a temporay file |
|
| 2206 | - $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
|
| 2205 | + // ----- Creates a temporay file |
|
| 2206 | + $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
|
| 2207 | 2207 | |
| 2208 | - // ----- Open the temporary file in write mode |
|
| 2209 | - if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
|
| 2210 | - { |
|
| 2211 | - $this->privCloseFd(); |
|
| 2212 | - $this->privSwapBackMagicQuotes(); |
|
| 2208 | + // ----- Open the temporary file in write mode |
|
| 2209 | + if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
|
| 2210 | + { |
|
| 2211 | + $this->privCloseFd(); |
|
| 2212 | + $this->privSwapBackMagicQuotes(); |
|
| 2213 | 2213 | |
| 2214 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
|
| 2214 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
|
| 2215 | 2215 | |
| 2216 | - // ----- Return |
|
| 2217 | - return PclZip::errorCode(); |
|
| 2218 | - } |
|
| 2216 | + // ----- Return |
|
| 2217 | + return PclZip::errorCode(); |
|
| 2218 | + } |
|
| 2219 | 2219 | |
| 2220 | - // ----- Copy the files from the archive to the temporary file |
|
| 2221 | - // TBC : Here I should better append the file and go back to erase the central dir |
|
| 2222 | - $v_size = $v_central_dir['offset']; |
|
| 2223 | - while ($v_size != 0) |
|
| 2224 | - { |
|
| 2225 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2226 | - $v_buffer = fread($this->zip_fd, $v_read_size); |
|
| 2227 | - @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 2228 | - $v_size -= $v_read_size; |
|
| 2229 | - } |
|
| 2220 | + // ----- Copy the files from the archive to the temporary file |
|
| 2221 | + // TBC : Here I should better append the file and go back to erase the central dir |
|
| 2222 | + $v_size = $v_central_dir['offset']; |
|
| 2223 | + while ($v_size != 0) |
|
| 2224 | + { |
|
| 2225 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2226 | + $v_buffer = fread($this->zip_fd, $v_read_size); |
|
| 2227 | + @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 2228 | + $v_size -= $v_read_size; |
|
| 2229 | + } |
|
| 2230 | 2230 | |
| 2231 | - // ----- Swap the file descriptor |
|
| 2232 | - // Here is a trick : I swap the temporary fd with the zip fd, in order to use |
|
| 2233 | - // the following methods on the temporary fil and not the real archive |
|
| 2234 | - $v_swap = $this->zip_fd; |
|
| 2235 | - $this->zip_fd = $v_zip_temp_fd; |
|
| 2236 | - $v_zip_temp_fd = $v_swap; |
|
| 2237 | - |
|
| 2238 | - // ----- Add the files |
|
| 2239 | - $v_header_list = array(); |
|
| 2240 | - if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) |
|
| 2241 | - { |
|
| 2242 | - fclose($v_zip_temp_fd); |
|
| 2243 | - $this->privCloseFd(); |
|
| 2244 | - @unlink($v_zip_temp_name); |
|
| 2245 | - $this->privSwapBackMagicQuotes(); |
|
| 2246 | - |
|
| 2247 | - // ----- Return |
|
| 2248 | - return $v_result; |
|
| 2249 | - } |
|
| 2231 | + // ----- Swap the file descriptor |
|
| 2232 | + // Here is a trick : I swap the temporary fd with the zip fd, in order to use |
|
| 2233 | + // the following methods on the temporary fil and not the real archive |
|
| 2234 | + $v_swap = $this->zip_fd; |
|
| 2235 | + $this->zip_fd = $v_zip_temp_fd; |
|
| 2236 | + $v_zip_temp_fd = $v_swap; |
|
| 2237 | + |
|
| 2238 | + // ----- Add the files |
|
| 2239 | + $v_header_list = array(); |
|
| 2240 | + if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) |
|
| 2241 | + { |
|
| 2242 | + fclose($v_zip_temp_fd); |
|
| 2243 | + $this->privCloseFd(); |
|
| 2244 | + @unlink($v_zip_temp_name); |
|
| 2245 | + $this->privSwapBackMagicQuotes(); |
|
| 2246 | + |
|
| 2247 | + // ----- Return |
|
| 2248 | + return $v_result; |
|
| 2249 | + } |
|
| 2250 | 2250 | |
| 2251 | - // ----- Store the offset of the central dir |
|
| 2252 | - $v_offset = @ftell($this->zip_fd); |
|
| 2253 | - |
|
| 2254 | - // ----- Copy the block of file headers from the old archive |
|
| 2255 | - $v_size = $v_central_dir['size']; |
|
| 2256 | - while ($v_size != 0) |
|
| 2257 | - { |
|
| 2258 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2259 | - $v_buffer = @fread($v_zip_temp_fd, $v_read_size); |
|
| 2260 | - @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
|
| 2261 | - $v_size -= $v_read_size; |
|
| 2262 | - } |
|
| 2251 | + // ----- Store the offset of the central dir |
|
| 2252 | + $v_offset = @ftell($this->zip_fd); |
|
| 2253 | + |
|
| 2254 | + // ----- Copy the block of file headers from the old archive |
|
| 2255 | + $v_size = $v_central_dir['size']; |
|
| 2256 | + while ($v_size != 0) |
|
| 2257 | + { |
|
| 2258 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2259 | + $v_buffer = @fread($v_zip_temp_fd, $v_read_size); |
|
| 2260 | + @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
|
| 2261 | + $v_size -= $v_read_size; |
|
| 2262 | + } |
|
| 2263 | 2263 | |
| 2264 | - // ----- Create the Central Dir files header |
|
| 2265 | - for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++) |
|
| 2266 | - { |
|
| 2267 | - // ----- Create the file header |
|
| 2268 | - if ($v_header_list[$i]['status'] == 'ok') { |
|
| 2269 | - if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
|
| 2270 | - fclose($v_zip_temp_fd); |
|
| 2271 | - $this->privCloseFd(); |
|
| 2272 | - @unlink($v_zip_temp_name); |
|
| 2273 | - $this->privSwapBackMagicQuotes(); |
|
| 2274 | - |
|
| 2275 | - // ----- Return |
|
| 2276 | - return $v_result; |
|
| 2277 | - } |
|
| 2278 | - $v_count++; |
|
| 2279 | - } |
|
| 2264 | + // ----- Create the Central Dir files header |
|
| 2265 | + for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++) |
|
| 2266 | + { |
|
| 2267 | + // ----- Create the file header |
|
| 2268 | + if ($v_header_list[$i]['status'] == 'ok') { |
|
| 2269 | + if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
|
| 2270 | + fclose($v_zip_temp_fd); |
|
| 2271 | + $this->privCloseFd(); |
|
| 2272 | + @unlink($v_zip_temp_name); |
|
| 2273 | + $this->privSwapBackMagicQuotes(); |
|
| 2274 | + |
|
| 2275 | + // ----- Return |
|
| 2276 | + return $v_result; |
|
| 2277 | + } |
|
| 2278 | + $v_count++; |
|
| 2279 | + } |
|
| 2280 | 2280 | |
| 2281 | - // ----- Transform the header to a 'usable' info |
|
| 2282 | - $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
|
| 2283 | - } |
|
| 2281 | + // ----- Transform the header to a 'usable' info |
|
| 2282 | + $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
|
| 2283 | + } |
|
| 2284 | 2284 | |
| 2285 | - // ----- Zip file comment |
|
| 2286 | - $v_comment = $v_central_dir['comment']; |
|
| 2287 | - if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
|
| 2288 | - $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
|
| 2289 | - } |
|
| 2290 | - if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) { |
|
| 2291 | - $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT]; |
|
| 2292 | - } |
|
| 2293 | - if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) { |
|
| 2294 | - $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment; |
|
| 2295 | - } |
|
| 2285 | + // ----- Zip file comment |
|
| 2286 | + $v_comment = $v_central_dir['comment']; |
|
| 2287 | + if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
|
| 2288 | + $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
|
| 2289 | + } |
|
| 2290 | + if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) { |
|
| 2291 | + $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT]; |
|
| 2292 | + } |
|
| 2293 | + if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) { |
|
| 2294 | + $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment; |
|
| 2295 | + } |
|
| 2296 | 2296 | |
| 2297 | - // ----- Calculate the size of the central header |
|
| 2298 | - $v_size = @ftell($this->zip_fd)-$v_offset; |
|
| 2297 | + // ----- Calculate the size of the central header |
|
| 2298 | + $v_size = @ftell($this->zip_fd)-$v_offset; |
|
| 2299 | 2299 | |
| 2300 | - // ----- Create the central dir footer |
|
| 2301 | - if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) |
|
| 2302 | - { |
|
| 2303 | - // ----- Reset the file list |
|
| 2304 | - unset($v_header_list); |
|
| 2305 | - $this->privSwapBackMagicQuotes(); |
|
| 2300 | + // ----- Create the central dir footer |
|
| 2301 | + if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) |
|
| 2302 | + { |
|
| 2303 | + // ----- Reset the file list |
|
| 2304 | + unset($v_header_list); |
|
| 2305 | + $this->privSwapBackMagicQuotes(); |
|
| 2306 | 2306 | |
| 2307 | - // ----- Return |
|
| 2308 | - return $v_result; |
|
| 2309 | - } |
|
| 2307 | + // ----- Return |
|
| 2308 | + return $v_result; |
|
| 2309 | + } |
|
| 2310 | 2310 | |
| 2311 | - // ----- Swap back the file descriptor |
|
| 2312 | - $v_swap = $this->zip_fd; |
|
| 2313 | - $this->zip_fd = $v_zip_temp_fd; |
|
| 2314 | - $v_zip_temp_fd = $v_swap; |
|
| 2311 | + // ----- Swap back the file descriptor |
|
| 2312 | + $v_swap = $this->zip_fd; |
|
| 2313 | + $this->zip_fd = $v_zip_temp_fd; |
|
| 2314 | + $v_zip_temp_fd = $v_swap; |
|
| 2315 | 2315 | |
| 2316 | - // ----- Close |
|
| 2317 | - $this->privCloseFd(); |
|
| 2316 | + // ----- Close |
|
| 2317 | + $this->privCloseFd(); |
|
| 2318 | 2318 | |
| 2319 | - // ----- Close the temporary file |
|
| 2320 | - @fclose($v_zip_temp_fd); |
|
| 2319 | + // ----- Close the temporary file |
|
| 2320 | + @fclose($v_zip_temp_fd); |
|
| 2321 | 2321 | |
| 2322 | - // ----- Magic quotes trick |
|
| 2323 | - $this->privSwapBackMagicQuotes(); |
|
| 2322 | + // ----- Magic quotes trick |
|
| 2323 | + $this->privSwapBackMagicQuotes(); |
|
| 2324 | 2324 | |
| 2325 | - // ----- Delete the zip file |
|
| 2326 | - // TBC : I should test the result ... |
|
| 2327 | - @unlink($this->zipname); |
|
| 2325 | + // ----- Delete the zip file |
|
| 2326 | + // TBC : I should test the result ... |
|
| 2327 | + @unlink($this->zipname); |
|
| 2328 | 2328 | |
| 2329 | - // ----- Rename the temporary file |
|
| 2330 | - // TBC : I should test the result ... |
|
| 2331 | - //@rename($v_zip_temp_name, $this->zipname); |
|
| 2332 | - PclZipUtilRename($v_zip_temp_name, $this->zipname); |
|
| 2329 | + // ----- Rename the temporary file |
|
| 2330 | + // TBC : I should test the result ... |
|
| 2331 | + //@rename($v_zip_temp_name, $this->zipname); |
|
| 2332 | + PclZipUtilRename($v_zip_temp_name, $this->zipname); |
|
| 2333 | 2333 | |
| 2334 | - // ----- Return |
|
| 2335 | - return $v_result; |
|
| 2334 | + // ----- Return |
|
| 2335 | + return $v_result; |
|
| 2336 | 2336 | } |
| 2337 | 2337 | // -------------------------------------------------------------------------------- |
| 2338 | 2338 | |
@@ -2343,30 +2343,30 @@ discard block |
||
| 2343 | 2343 | // -------------------------------------------------------------------------------- |
| 2344 | 2344 | function privOpenFd($p_mode) |
| 2345 | 2345 | { |
| 2346 | - $v_result=1; |
|
| 2346 | + $v_result=1; |
|
| 2347 | 2347 | |
| 2348 | - // ----- Look if already open |
|
| 2349 | - if ($this->zip_fd != 0) |
|
| 2350 | - { |
|
| 2351 | - // ----- Error log |
|
| 2352 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open'); |
|
| 2348 | + // ----- Look if already open |
|
| 2349 | + if ($this->zip_fd != 0) |
|
| 2350 | + { |
|
| 2351 | + // ----- Error log |
|
| 2352 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open'); |
|
| 2353 | 2353 | |
| 2354 | - // ----- Return |
|
| 2355 | - return PclZip::errorCode(); |
|
| 2356 | - } |
|
| 2354 | + // ----- Return |
|
| 2355 | + return PclZip::errorCode(); |
|
| 2356 | + } |
|
| 2357 | 2357 | |
| 2358 | - // ----- Open the zip file |
|
| 2359 | - if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) |
|
| 2360 | - { |
|
| 2361 | - // ----- Error log |
|
| 2362 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode'); |
|
| 2358 | + // ----- Open the zip file |
|
| 2359 | + if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) |
|
| 2360 | + { |
|
| 2361 | + // ----- Error log |
|
| 2362 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode'); |
|
| 2363 | 2363 | |
| 2364 | - // ----- Return |
|
| 2365 | - return PclZip::errorCode(); |
|
| 2366 | - } |
|
| 2364 | + // ----- Return |
|
| 2365 | + return PclZip::errorCode(); |
|
| 2366 | + } |
|
| 2367 | 2367 | |
| 2368 | - // ----- Return |
|
| 2369 | - return $v_result; |
|
| 2368 | + // ----- Return |
|
| 2369 | + return $v_result; |
|
| 2370 | 2370 | } |
| 2371 | 2371 | // -------------------------------------------------------------------------------- |
| 2372 | 2372 | |
@@ -2377,14 +2377,14 @@ discard block |
||
| 2377 | 2377 | // -------------------------------------------------------------------------------- |
| 2378 | 2378 | function privCloseFd() |
| 2379 | 2379 | { |
| 2380 | - $v_result=1; |
|
| 2380 | + $v_result=1; |
|
| 2381 | 2381 | |
| 2382 | - if ($this->zip_fd != 0) |
|
| 2383 | - @fclose($this->zip_fd); |
|
| 2384 | - $this->zip_fd = 0; |
|
| 2382 | + if ($this->zip_fd != 0) |
|
| 2383 | + @fclose($this->zip_fd); |
|
| 2384 | + $this->zip_fd = 0; |
|
| 2385 | 2385 | |
| 2386 | - // ----- Return |
|
| 2387 | - return $v_result; |
|
| 2386 | + // ----- Return |
|
| 2387 | + return $v_result; |
|
| 2388 | 2388 | } |
| 2389 | 2389 | // -------------------------------------------------------------------------------- |
| 2390 | 2390 | |
@@ -2404,56 +2404,56 @@ discard block |
||
| 2404 | 2404 | // function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options) |
| 2405 | 2405 | function privAddList($p_filedescr_list, &$p_result_list, &$p_options) |
| 2406 | 2406 | { |
| 2407 | - $v_result=1; |
|
| 2408 | - |
|
| 2409 | - // ----- Add the files |
|
| 2410 | - $v_header_list = array(); |
|
| 2411 | - if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) |
|
| 2412 | - { |
|
| 2413 | - // ----- Return |
|
| 2414 | - return $v_result; |
|
| 2415 | - } |
|
| 2407 | + $v_result=1; |
|
| 2408 | + |
|
| 2409 | + // ----- Add the files |
|
| 2410 | + $v_header_list = array(); |
|
| 2411 | + if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) |
|
| 2412 | + { |
|
| 2413 | + // ----- Return |
|
| 2414 | + return $v_result; |
|
| 2415 | + } |
|
| 2416 | 2416 | |
| 2417 | - // ----- Store the offset of the central dir |
|
| 2418 | - $v_offset = @ftell($this->zip_fd); |
|
| 2419 | - |
|
| 2420 | - // ----- Create the Central Dir files header |
|
| 2421 | - for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++) |
|
| 2422 | - { |
|
| 2423 | - // ----- Create the file header |
|
| 2424 | - if ($v_header_list[$i]['status'] == 'ok') { |
|
| 2425 | - if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
|
| 2426 | - // ----- Return |
|
| 2427 | - return $v_result; |
|
| 2428 | - } |
|
| 2429 | - $v_count++; |
|
| 2430 | - } |
|
| 2417 | + // ----- Store the offset of the central dir |
|
| 2418 | + $v_offset = @ftell($this->zip_fd); |
|
| 2419 | + |
|
| 2420 | + // ----- Create the Central Dir files header |
|
| 2421 | + for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++) |
|
| 2422 | + { |
|
| 2423 | + // ----- Create the file header |
|
| 2424 | + if ($v_header_list[$i]['status'] == 'ok') { |
|
| 2425 | + if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
|
| 2426 | + // ----- Return |
|
| 2427 | + return $v_result; |
|
| 2428 | + } |
|
| 2429 | + $v_count++; |
|
| 2430 | + } |
|
| 2431 | 2431 | |
| 2432 | - // ----- Transform the header to a 'usable' info |
|
| 2433 | - $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
|
| 2434 | - } |
|
| 2432 | + // ----- Transform the header to a 'usable' info |
|
| 2433 | + $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
|
| 2434 | + } |
|
| 2435 | 2435 | |
| 2436 | - // ----- Zip file comment |
|
| 2437 | - $v_comment = ''; |
|
| 2438 | - if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
|
| 2439 | - $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
|
| 2440 | - } |
|
| 2436 | + // ----- Zip file comment |
|
| 2437 | + $v_comment = ''; |
|
| 2438 | + if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
|
| 2439 | + $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
|
| 2440 | + } |
|
| 2441 | 2441 | |
| 2442 | - // ----- Calculate the size of the central header |
|
| 2443 | - $v_size = @ftell($this->zip_fd)-$v_offset; |
|
| 2442 | + // ----- Calculate the size of the central header |
|
| 2443 | + $v_size = @ftell($this->zip_fd)-$v_offset; |
|
| 2444 | 2444 | |
| 2445 | - // ----- Create the central dir footer |
|
| 2446 | - if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) |
|
| 2447 | - { |
|
| 2448 | - // ----- Reset the file list |
|
| 2449 | - unset($v_header_list); |
|
| 2445 | + // ----- Create the central dir footer |
|
| 2446 | + if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) |
|
| 2447 | + { |
|
| 2448 | + // ----- Reset the file list |
|
| 2449 | + unset($v_header_list); |
|
| 2450 | 2450 | |
| 2451 | - // ----- Return |
|
| 2452 | - return $v_result; |
|
| 2453 | - } |
|
| 2451 | + // ----- Return |
|
| 2452 | + return $v_result; |
|
| 2453 | + } |
|
| 2454 | 2454 | |
| 2455 | - // ----- Return |
|
| 2456 | - return $v_result; |
|
| 2455 | + // ----- Return |
|
| 2456 | + return $v_result; |
|
| 2457 | 2457 | } |
| 2458 | 2458 | // -------------------------------------------------------------------------------- |
| 2459 | 2459 | |
@@ -2468,57 +2468,57 @@ discard block |
||
| 2468 | 2468 | // -------------------------------------------------------------------------------- |
| 2469 | 2469 | function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) |
| 2470 | 2470 | { |
| 2471 | - $v_result=1; |
|
| 2472 | - $v_header = array(); |
|
| 2471 | + $v_result=1; |
|
| 2472 | + $v_header = array(); |
|
| 2473 | 2473 | |
| 2474 | - // ----- Recuperate the current number of elt in list |
|
| 2475 | - $v_nb = sizeof($p_result_list); |
|
| 2474 | + // ----- Recuperate the current number of elt in list |
|
| 2475 | + $v_nb = sizeof($p_result_list); |
|
| 2476 | 2476 | |
| 2477 | - // ----- Loop on the files |
|
| 2478 | - for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { |
|
| 2479 | - // ----- Format the filename |
|
| 2480 | - $p_filedescr_list[$j]['filename'] |
|
| 2481 | - = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); |
|
| 2477 | + // ----- Loop on the files |
|
| 2478 | + for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { |
|
| 2479 | + // ----- Format the filename |
|
| 2480 | + $p_filedescr_list[$j]['filename'] |
|
| 2481 | + = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); |
|
| 2482 | 2482 | |
| 2483 | 2483 | |
| 2484 | - // ----- Skip empty file names |
|
| 2485 | - // TBC : Can this be possible ? not checked in DescrParseAtt ? |
|
| 2486 | - if ($p_filedescr_list[$j]['filename'] == "") { |
|
| 2487 | - continue; |
|
| 2488 | - } |
|
| 2484 | + // ----- Skip empty file names |
|
| 2485 | + // TBC : Can this be possible ? not checked in DescrParseAtt ? |
|
| 2486 | + if ($p_filedescr_list[$j]['filename'] == "") { |
|
| 2487 | + continue; |
|
| 2488 | + } |
|
| 2489 | 2489 | |
| 2490 | - // ----- Check the filename |
|
| 2491 | - if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') |
|
| 2492 | - && (!file_exists($p_filedescr_list[$j]['filename']))) { |
|
| 2493 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); |
|
| 2494 | - return PclZip::errorCode(); |
|
| 2495 | - } |
|
| 2490 | + // ----- Check the filename |
|
| 2491 | + if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') |
|
| 2492 | + && (!file_exists($p_filedescr_list[$j]['filename']))) { |
|
| 2493 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); |
|
| 2494 | + return PclZip::errorCode(); |
|
| 2495 | + } |
|
| 2496 | 2496 | |
| 2497 | - // ----- Look if it is a file or a dir with no all path remove option |
|
| 2498 | - // or a dir with all its path removed |
|
| 2497 | + // ----- Look if it is a file or a dir with no all path remove option |
|
| 2498 | + // or a dir with all its path removed |
|
| 2499 | 2499 | // if ( (is_file($p_filedescr_list[$j]['filename'])) |
| 2500 | 2500 | // || ( is_dir($p_filedescr_list[$j]['filename']) |
| 2501 | - if ( ($p_filedescr_list[$j]['type'] == 'file') |
|
| 2502 | - || ($p_filedescr_list[$j]['type'] == 'virtual_file') |
|
| 2503 | - || ( ($p_filedescr_list[$j]['type'] == 'folder') |
|
| 2504 | - && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) |
|
| 2505 | - || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
| 2506 | - ) { |
|
| 2507 | - |
|
| 2508 | - // ----- Add the file |
|
| 2509 | - $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header, |
|
| 2510 | - $p_options); |
|
| 2511 | - if ($v_result != 1) { |
|
| 2512 | - return $v_result; |
|
| 2513 | - } |
|
| 2514 | - |
|
| 2515 | - // ----- Store the file infos |
|
| 2516 | - $p_result_list[$v_nb++] = $v_header; |
|
| 2517 | - } |
|
| 2518 | - } |
|
| 2501 | + if ( ($p_filedescr_list[$j]['type'] == 'file') |
|
| 2502 | + || ($p_filedescr_list[$j]['type'] == 'virtual_file') |
|
| 2503 | + || ( ($p_filedescr_list[$j]['type'] == 'folder') |
|
| 2504 | + && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) |
|
| 2505 | + || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
| 2506 | + ) { |
|
| 2507 | + |
|
| 2508 | + // ----- Add the file |
|
| 2509 | + $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header, |
|
| 2510 | + $p_options); |
|
| 2511 | + if ($v_result != 1) { |
|
| 2512 | + return $v_result; |
|
| 2513 | + } |
|
| 2514 | + |
|
| 2515 | + // ----- Store the file infos |
|
| 2516 | + $p_result_list[$v_nb++] = $v_header; |
|
| 2517 | + } |
|
| 2518 | + } |
|
| 2519 | 2519 | |
| 2520 | - // ----- Return |
|
| 2521 | - return $v_result; |
|
| 2520 | + // ----- Return |
|
| 2521 | + return $v_result; |
|
| 2522 | 2522 | } |
| 2523 | 2523 | // -------------------------------------------------------------------------------- |
| 2524 | 2524 | |
@@ -2530,22 +2530,22 @@ discard block |
||
| 2530 | 2530 | // -------------------------------------------------------------------------------- |
| 2531 | 2531 | function privAddFile($p_filedescr, &$p_header, &$p_options) |
| 2532 | 2532 | { |
| 2533 | - $v_result=1; |
|
| 2533 | + $v_result=1; |
|
| 2534 | 2534 | |
| 2535 | - // ----- Working variable |
|
| 2536 | - $p_filename = $p_filedescr['filename']; |
|
| 2535 | + // ----- Working variable |
|
| 2536 | + $p_filename = $p_filedescr['filename']; |
|
| 2537 | 2537 | |
| 2538 | - // TBC : Already done in the fileAtt check ... ? |
|
| 2539 | - if ($p_filename == "") { |
|
| 2540 | - // ----- Error log |
|
| 2541 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)"); |
|
| 2538 | + // TBC : Already done in the fileAtt check ... ? |
|
| 2539 | + if ($p_filename == "") { |
|
| 2540 | + // ----- Error log |
|
| 2541 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)"); |
|
| 2542 | 2542 | |
| 2543 | - // ----- Return |
|
| 2544 | - return PclZip::errorCode(); |
|
| 2545 | - } |
|
| 2543 | + // ----- Return |
|
| 2544 | + return PclZip::errorCode(); |
|
| 2545 | + } |
|
| 2546 | 2546 | |
| 2547 | - // ----- Look for a stored different filename |
|
| 2548 | - /* TBC : Removed |
|
| 2547 | + // ----- Look for a stored different filename |
|
| 2548 | + /* TBC : Removed |
|
| 2549 | 2549 | if (isset($p_filedescr['stored_filename'])) { |
| 2550 | 2550 | $v_stored_filename = $p_filedescr['stored_filename']; |
| 2551 | 2551 | } |
@@ -2554,244 +2554,244 @@ discard block |
||
| 2554 | 2554 | } |
| 2555 | 2555 | */ |
| 2556 | 2556 | |
| 2557 | - // ----- Set the file properties |
|
| 2558 | - clearstatcache(); |
|
| 2559 | - $p_header['version'] = 20; |
|
| 2560 | - $p_header['version_extracted'] = 10; |
|
| 2561 | - $p_header['flag'] = 0; |
|
| 2562 | - $p_header['compression'] = 0; |
|
| 2563 | - $p_header['crc'] = 0; |
|
| 2564 | - $p_header['compressed_size'] = 0; |
|
| 2565 | - $p_header['filename_len'] = strlen($p_filename); |
|
| 2566 | - $p_header['extra_len'] = 0; |
|
| 2567 | - $p_header['disk'] = 0; |
|
| 2568 | - $p_header['internal'] = 0; |
|
| 2569 | - $p_header['offset'] = 0; |
|
| 2570 | - $p_header['filename'] = $p_filename; |
|
| 2557 | + // ----- Set the file properties |
|
| 2558 | + clearstatcache(); |
|
| 2559 | + $p_header['version'] = 20; |
|
| 2560 | + $p_header['version_extracted'] = 10; |
|
| 2561 | + $p_header['flag'] = 0; |
|
| 2562 | + $p_header['compression'] = 0; |
|
| 2563 | + $p_header['crc'] = 0; |
|
| 2564 | + $p_header['compressed_size'] = 0; |
|
| 2565 | + $p_header['filename_len'] = strlen($p_filename); |
|
| 2566 | + $p_header['extra_len'] = 0; |
|
| 2567 | + $p_header['disk'] = 0; |
|
| 2568 | + $p_header['internal'] = 0; |
|
| 2569 | + $p_header['offset'] = 0; |
|
| 2570 | + $p_header['filename'] = $p_filename; |
|
| 2571 | 2571 | // TBC : Removed $p_header['stored_filename'] = $v_stored_filename; |
| 2572 | - $p_header['stored_filename'] = $p_filedescr['stored_filename']; |
|
| 2573 | - $p_header['extra'] = ''; |
|
| 2574 | - $p_header['status'] = 'ok'; |
|
| 2575 | - $p_header['index'] = -1; |
|
| 2576 | - |
|
| 2577 | - // ----- Look for regular file |
|
| 2578 | - if ($p_filedescr['type']=='file') { |
|
| 2579 | - $p_header['external'] = 0x00000000; |
|
| 2580 | - $p_header['size'] = filesize($p_filename); |
|
| 2581 | - } |
|
| 2572 | + $p_header['stored_filename'] = $p_filedescr['stored_filename']; |
|
| 2573 | + $p_header['extra'] = ''; |
|
| 2574 | + $p_header['status'] = 'ok'; |
|
| 2575 | + $p_header['index'] = -1; |
|
| 2576 | + |
|
| 2577 | + // ----- Look for regular file |
|
| 2578 | + if ($p_filedescr['type']=='file') { |
|
| 2579 | + $p_header['external'] = 0x00000000; |
|
| 2580 | + $p_header['size'] = filesize($p_filename); |
|
| 2581 | + } |
|
| 2582 | 2582 | |
| 2583 | - // ----- Look for regular folder |
|
| 2584 | - else if ($p_filedescr['type']=='folder') { |
|
| 2585 | - $p_header['external'] = 0x00000010; |
|
| 2586 | - $p_header['mtime'] = filemtime($p_filename); |
|
| 2587 | - $p_header['size'] = filesize($p_filename); |
|
| 2588 | - } |
|
| 2583 | + // ----- Look for regular folder |
|
| 2584 | + else if ($p_filedescr['type']=='folder') { |
|
| 2585 | + $p_header['external'] = 0x00000010; |
|
| 2586 | + $p_header['mtime'] = filemtime($p_filename); |
|
| 2587 | + $p_header['size'] = filesize($p_filename); |
|
| 2588 | + } |
|
| 2589 | 2589 | |
| 2590 | - // ----- Look for virtual file |
|
| 2591 | - else if ($p_filedescr['type'] == 'virtual_file') { |
|
| 2592 | - $p_header['external'] = 0x00000000; |
|
| 2593 | - $p_header['size'] = strlen($p_filedescr['content']); |
|
| 2594 | - } |
|
| 2590 | + // ----- Look for virtual file |
|
| 2591 | + else if ($p_filedescr['type'] == 'virtual_file') { |
|
| 2592 | + $p_header['external'] = 0x00000000; |
|
| 2593 | + $p_header['size'] = strlen($p_filedescr['content']); |
|
| 2594 | + } |
|
| 2595 | 2595 | |
| 2596 | 2596 | |
| 2597 | - // ----- Look for filetime |
|
| 2598 | - if (isset($p_filedescr['mtime'])) { |
|
| 2599 | - $p_header['mtime'] = $p_filedescr['mtime']; |
|
| 2600 | - } |
|
| 2601 | - else if ($p_filedescr['type'] == 'virtual_file') { |
|
| 2602 | - $p_header['mtime'] = time(); |
|
| 2603 | - } |
|
| 2604 | - else { |
|
| 2605 | - $p_header['mtime'] = filemtime($p_filename); |
|
| 2606 | - } |
|
| 2597 | + // ----- Look for filetime |
|
| 2598 | + if (isset($p_filedescr['mtime'])) { |
|
| 2599 | + $p_header['mtime'] = $p_filedescr['mtime']; |
|
| 2600 | + } |
|
| 2601 | + else if ($p_filedescr['type'] == 'virtual_file') { |
|
| 2602 | + $p_header['mtime'] = time(); |
|
| 2603 | + } |
|
| 2604 | + else { |
|
| 2605 | + $p_header['mtime'] = filemtime($p_filename); |
|
| 2606 | + } |
|
| 2607 | 2607 | |
| 2608 | - // ------ Look for file comment |
|
| 2609 | - if (isset($p_filedescr['comment'])) { |
|
| 2610 | - $p_header['comment_len'] = strlen($p_filedescr['comment']); |
|
| 2611 | - $p_header['comment'] = $p_filedescr['comment']; |
|
| 2612 | - } |
|
| 2613 | - else { |
|
| 2614 | - $p_header['comment_len'] = 0; |
|
| 2615 | - $p_header['comment'] = ''; |
|
| 2616 | - } |
|
| 2608 | + // ------ Look for file comment |
|
| 2609 | + if (isset($p_filedescr['comment'])) { |
|
| 2610 | + $p_header['comment_len'] = strlen($p_filedescr['comment']); |
|
| 2611 | + $p_header['comment'] = $p_filedescr['comment']; |
|
| 2612 | + } |
|
| 2613 | + else { |
|
| 2614 | + $p_header['comment_len'] = 0; |
|
| 2615 | + $p_header['comment'] = ''; |
|
| 2616 | + } |
|
| 2617 | 2617 | |
| 2618 | - // ----- Look for pre-add callback |
|
| 2619 | - if (isset($p_options[PCLZIP_CB_PRE_ADD])) { |
|
| 2618 | + // ----- Look for pre-add callback |
|
| 2619 | + if (isset($p_options[PCLZIP_CB_PRE_ADD])) { |
|
| 2620 | 2620 | |
| 2621 | - // ----- Generate a local information |
|
| 2622 | - $v_local_header = array(); |
|
| 2623 | - $this->privConvertHeader2FileInfo($p_header, $v_local_header); |
|
| 2621 | + // ----- Generate a local information |
|
| 2622 | + $v_local_header = array(); |
|
| 2623 | + $this->privConvertHeader2FileInfo($p_header, $v_local_header); |
|
| 2624 | 2624 | |
| 2625 | - // ----- Call the callback |
|
| 2626 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 2627 | - // header. |
|
| 2625 | + // ----- Call the callback |
|
| 2626 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 2627 | + // header. |
|
| 2628 | 2628 | // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);'); |
| 2629 | - $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header); |
|
| 2630 | - if ($v_result == 0) { |
|
| 2631 | - // ----- Change the file status |
|
| 2632 | - $p_header['status'] = "skipped"; |
|
| 2633 | - $v_result = 1; |
|
| 2634 | - } |
|
| 2629 | + $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header); |
|
| 2630 | + if ($v_result == 0) { |
|
| 2631 | + // ----- Change the file status |
|
| 2632 | + $p_header['status'] = "skipped"; |
|
| 2633 | + $v_result = 1; |
|
| 2634 | + } |
|
| 2635 | 2635 | |
| 2636 | - // ----- Update the informations |
|
| 2637 | - // Only some fields can be modified |
|
| 2638 | - if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { |
|
| 2639 | - $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); |
|
| 2640 | - } |
|
| 2641 | - } |
|
| 2636 | + // ----- Update the informations |
|
| 2637 | + // Only some fields can be modified |
|
| 2638 | + if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { |
|
| 2639 | + $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); |
|
| 2640 | + } |
|
| 2641 | + } |
|
| 2642 | 2642 | |
| 2643 | - // ----- Look for empty stored filename |
|
| 2644 | - if ($p_header['stored_filename'] == "") { |
|
| 2645 | - $p_header['status'] = "filtered"; |
|
| 2646 | - } |
|
| 2643 | + // ----- Look for empty stored filename |
|
| 2644 | + if ($p_header['stored_filename'] == "") { |
|
| 2645 | + $p_header['status'] = "filtered"; |
|
| 2646 | + } |
|
| 2647 | 2647 | |
| 2648 | - // ----- Check the path length |
|
| 2649 | - if (strlen($p_header['stored_filename']) > 0xFF) { |
|
| 2650 | - $p_header['status'] = 'filename_too_long'; |
|
| 2651 | - } |
|
| 2648 | + // ----- Check the path length |
|
| 2649 | + if (strlen($p_header['stored_filename']) > 0xFF) { |
|
| 2650 | + $p_header['status'] = 'filename_too_long'; |
|
| 2651 | + } |
|
| 2652 | 2652 | |
| 2653 | - // ----- Look if no error, or file not skipped |
|
| 2654 | - if ($p_header['status'] == 'ok') { |
|
| 2655 | - |
|
| 2656 | - // ----- Look for a file |
|
| 2657 | - if ($p_filedescr['type'] == 'file') { |
|
| 2658 | - // ----- Look for using temporary file to zip |
|
| 2659 | - if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 2660 | - && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
|
| 2661 | - || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
|
| 2662 | - && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) { |
|
| 2663 | - $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); |
|
| 2664 | - if ($v_result < PCLZIP_ERR_NO_ERROR) { |
|
| 2665 | - return $v_result; |
|
| 2666 | - } |
|
| 2667 | - } |
|
| 2653 | + // ----- Look if no error, or file not skipped |
|
| 2654 | + if ($p_header['status'] == 'ok') { |
|
| 2655 | + |
|
| 2656 | + // ----- Look for a file |
|
| 2657 | + if ($p_filedescr['type'] == 'file') { |
|
| 2658 | + // ----- Look for using temporary file to zip |
|
| 2659 | + if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 2660 | + && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
|
| 2661 | + || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
|
| 2662 | + && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) { |
|
| 2663 | + $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); |
|
| 2664 | + if ($v_result < PCLZIP_ERR_NO_ERROR) { |
|
| 2665 | + return $v_result; |
|
| 2666 | + } |
|
| 2667 | + } |
|
| 2668 | 2668 | |
| 2669 | - // ----- Use "in memory" zip algo |
|
| 2670 | - else { |
|
| 2669 | + // ----- Use "in memory" zip algo |
|
| 2670 | + else { |
|
| 2671 | 2671 | |
| 2672 | - // ----- Open the source file |
|
| 2673 | - if (($v_file = @fopen($p_filename, "rb")) == 0) { |
|
| 2674 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); |
|
| 2675 | - return PclZip::errorCode(); |
|
| 2676 | - } |
|
| 2672 | + // ----- Open the source file |
|
| 2673 | + if (($v_file = @fopen($p_filename, "rb")) == 0) { |
|
| 2674 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); |
|
| 2675 | + return PclZip::errorCode(); |
|
| 2676 | + } |
|
| 2677 | 2677 | |
| 2678 | - // ----- Read the file content |
|
| 2679 | - $v_content = @fread($v_file, $p_header['size']); |
|
| 2678 | + // ----- Read the file content |
|
| 2679 | + $v_content = @fread($v_file, $p_header['size']); |
|
| 2680 | 2680 | |
| 2681 | - // ----- Close the file |
|
| 2682 | - @fclose($v_file); |
|
| 2681 | + // ----- Close the file |
|
| 2682 | + @fclose($v_file); |
|
| 2683 | 2683 | |
| 2684 | - // ----- Calculate the CRC |
|
| 2685 | - $p_header['crc'] = @crc32($v_content); |
|
| 2684 | + // ----- Calculate the CRC |
|
| 2685 | + $p_header['crc'] = @crc32($v_content); |
|
| 2686 | 2686 | |
| 2687 | - // ----- Look for no compression |
|
| 2688 | - if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { |
|
| 2689 | - // ----- Set header parameters |
|
| 2690 | - $p_header['compressed_size'] = $p_header['size']; |
|
| 2691 | - $p_header['compression'] = 0; |
|
| 2692 | - } |
|
| 2687 | + // ----- Look for no compression |
|
| 2688 | + if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { |
|
| 2689 | + // ----- Set header parameters |
|
| 2690 | + $p_header['compressed_size'] = $p_header['size']; |
|
| 2691 | + $p_header['compression'] = 0; |
|
| 2692 | + } |
|
| 2693 | 2693 | |
| 2694 | - // ----- Look for normal compression |
|
| 2695 | - else { |
|
| 2696 | - // ----- Compress the content |
|
| 2697 | - $v_content = @gzdeflate($v_content); |
|
| 2698 | - |
|
| 2699 | - // ----- Set header parameters |
|
| 2700 | - $p_header['compressed_size'] = strlen($v_content); |
|
| 2701 | - $p_header['compression'] = 8; |
|
| 2702 | - } |
|
| 2694 | + // ----- Look for normal compression |
|
| 2695 | + else { |
|
| 2696 | + // ----- Compress the content |
|
| 2697 | + $v_content = @gzdeflate($v_content); |
|
| 2698 | + |
|
| 2699 | + // ----- Set header parameters |
|
| 2700 | + $p_header['compressed_size'] = strlen($v_content); |
|
| 2701 | + $p_header['compression'] = 8; |
|
| 2702 | + } |
|
| 2703 | 2703 | |
| 2704 | - // ----- Call the header generation |
|
| 2705 | - if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
|
| 2706 | - @fclose($v_file); |
|
| 2707 | - return $v_result; |
|
| 2708 | - } |
|
| 2704 | + // ----- Call the header generation |
|
| 2705 | + if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
|
| 2706 | + @fclose($v_file); |
|
| 2707 | + return $v_result; |
|
| 2708 | + } |
|
| 2709 | 2709 | |
| 2710 | - // ----- Write the compressed (or not) content |
|
| 2711 | - @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); |
|
| 2710 | + // ----- Write the compressed (or not) content |
|
| 2711 | + @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); |
|
| 2712 | 2712 | |
| 2713 | - } |
|
| 2713 | + } |
|
| 2714 | 2714 | |
| 2715 | - } |
|
| 2715 | + } |
|
| 2716 | 2716 | |
| 2717 | - // ----- Look for a virtual file (a file from string) |
|
| 2718 | - else if ($p_filedescr['type'] == 'virtual_file') { |
|
| 2717 | + // ----- Look for a virtual file (a file from string) |
|
| 2718 | + else if ($p_filedescr['type'] == 'virtual_file') { |
|
| 2719 | 2719 | |
| 2720 | - $v_content = $p_filedescr['content']; |
|
| 2720 | + $v_content = $p_filedescr['content']; |
|
| 2721 | 2721 | |
| 2722 | - // ----- Calculate the CRC |
|
| 2723 | - $p_header['crc'] = @crc32($v_content); |
|
| 2722 | + // ----- Calculate the CRC |
|
| 2723 | + $p_header['crc'] = @crc32($v_content); |
|
| 2724 | 2724 | |
| 2725 | - // ----- Look for no compression |
|
| 2726 | - if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { |
|
| 2727 | - // ----- Set header parameters |
|
| 2728 | - $p_header['compressed_size'] = $p_header['size']; |
|
| 2729 | - $p_header['compression'] = 0; |
|
| 2730 | - } |
|
| 2725 | + // ----- Look for no compression |
|
| 2726 | + if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { |
|
| 2727 | + // ----- Set header parameters |
|
| 2728 | + $p_header['compressed_size'] = $p_header['size']; |
|
| 2729 | + $p_header['compression'] = 0; |
|
| 2730 | + } |
|
| 2731 | 2731 | |
| 2732 | - // ----- Look for normal compression |
|
| 2733 | - else { |
|
| 2734 | - // ----- Compress the content |
|
| 2735 | - $v_content = @gzdeflate($v_content); |
|
| 2736 | - |
|
| 2737 | - // ----- Set header parameters |
|
| 2738 | - $p_header['compressed_size'] = strlen($v_content); |
|
| 2739 | - $p_header['compression'] = 8; |
|
| 2740 | - } |
|
| 2732 | + // ----- Look for normal compression |
|
| 2733 | + else { |
|
| 2734 | + // ----- Compress the content |
|
| 2735 | + $v_content = @gzdeflate($v_content); |
|
| 2736 | + |
|
| 2737 | + // ----- Set header parameters |
|
| 2738 | + $p_header['compressed_size'] = strlen($v_content); |
|
| 2739 | + $p_header['compression'] = 8; |
|
| 2740 | + } |
|
| 2741 | 2741 | |
| 2742 | - // ----- Call the header generation |
|
| 2743 | - if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
|
| 2744 | - @fclose($v_file); |
|
| 2745 | - return $v_result; |
|
| 2746 | - } |
|
| 2747 | - |
|
| 2748 | - // ----- Write the compressed (or not) content |
|
| 2749 | - @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); |
|
| 2750 | - } |
|
| 2742 | + // ----- Call the header generation |
|
| 2743 | + if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
|
| 2744 | + @fclose($v_file); |
|
| 2745 | + return $v_result; |
|
| 2746 | + } |
|
| 2747 | + |
|
| 2748 | + // ----- Write the compressed (or not) content |
|
| 2749 | + @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); |
|
| 2750 | + } |
|
| 2751 | 2751 | |
| 2752 | - // ----- Look for a directory |
|
| 2753 | - else if ($p_filedescr['type'] == 'folder') { |
|
| 2754 | - // ----- Look for directory last '/' |
|
| 2755 | - if (@substr($p_header['stored_filename'], -1) != '/') { |
|
| 2756 | - $p_header['stored_filename'] .= '/'; |
|
| 2757 | - } |
|
| 2758 | - |
|
| 2759 | - // ----- Set the file properties |
|
| 2760 | - $p_header['size'] = 0; |
|
| 2761 | - //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked |
|
| 2762 | - $p_header['external'] = 0x00000010; // Value for a folder : to be checked |
|
| 2763 | - |
|
| 2764 | - // ----- Call the header generation |
|
| 2765 | - if (($v_result = $this->privWriteFileHeader($p_header)) != 1) |
|
| 2766 | - { |
|
| 2767 | - return $v_result; |
|
| 2768 | - } |
|
| 2769 | - } |
|
| 2770 | - } |
|
| 2752 | + // ----- Look for a directory |
|
| 2753 | + else if ($p_filedescr['type'] == 'folder') { |
|
| 2754 | + // ----- Look for directory last '/' |
|
| 2755 | + if (@substr($p_header['stored_filename'], -1) != '/') { |
|
| 2756 | + $p_header['stored_filename'] .= '/'; |
|
| 2757 | + } |
|
| 2758 | + |
|
| 2759 | + // ----- Set the file properties |
|
| 2760 | + $p_header['size'] = 0; |
|
| 2761 | + //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked |
|
| 2762 | + $p_header['external'] = 0x00000010; // Value for a folder : to be checked |
|
| 2763 | + |
|
| 2764 | + // ----- Call the header generation |
|
| 2765 | + if (($v_result = $this->privWriteFileHeader($p_header)) != 1) |
|
| 2766 | + { |
|
| 2767 | + return $v_result; |
|
| 2768 | + } |
|
| 2769 | + } |
|
| 2770 | + } |
|
| 2771 | 2771 | |
| 2772 | - // ----- Look for post-add callback |
|
| 2773 | - if (isset($p_options[PCLZIP_CB_POST_ADD])) { |
|
| 2772 | + // ----- Look for post-add callback |
|
| 2773 | + if (isset($p_options[PCLZIP_CB_POST_ADD])) { |
|
| 2774 | 2774 | |
| 2775 | - // ----- Generate a local information |
|
| 2776 | - $v_local_header = array(); |
|
| 2777 | - $this->privConvertHeader2FileInfo($p_header, $v_local_header); |
|
| 2775 | + // ----- Generate a local information |
|
| 2776 | + $v_local_header = array(); |
|
| 2777 | + $this->privConvertHeader2FileInfo($p_header, $v_local_header); |
|
| 2778 | 2778 | |
| 2779 | - // ----- Call the callback |
|
| 2780 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 2781 | - // header. |
|
| 2779 | + // ----- Call the callback |
|
| 2780 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 2781 | + // header. |
|
| 2782 | 2782 | // eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);'); |
| 2783 | - $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header); |
|
| 2784 | - if ($v_result == 0) { |
|
| 2785 | - // ----- Ignored |
|
| 2786 | - $v_result = 1; |
|
| 2787 | - } |
|
| 2783 | + $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header); |
|
| 2784 | + if ($v_result == 0) { |
|
| 2785 | + // ----- Ignored |
|
| 2786 | + $v_result = 1; |
|
| 2787 | + } |
|
| 2788 | 2788 | |
| 2789 | - // ----- Update the informations |
|
| 2790 | - // Nothing can be modified |
|
| 2791 | - } |
|
| 2789 | + // ----- Update the informations |
|
| 2790 | + // Nothing can be modified |
|
| 2791 | + } |
|
| 2792 | 2792 | |
| 2793 | - // ----- Return |
|
| 2794 | - return $v_result; |
|
| 2793 | + // ----- Return |
|
| 2794 | + return $v_result; |
|
| 2795 | 2795 | } |
| 2796 | 2796 | // -------------------------------------------------------------------------------- |
| 2797 | 2797 | |
@@ -2803,105 +2803,105 @@ discard block |
||
| 2803 | 2803 | // -------------------------------------------------------------------------------- |
| 2804 | 2804 | function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) |
| 2805 | 2805 | { |
| 2806 | - $v_result=PCLZIP_ERR_NO_ERROR; |
|
| 2806 | + $v_result=PCLZIP_ERR_NO_ERROR; |
|
| 2807 | 2807 | |
| 2808 | - // ----- Working variable |
|
| 2809 | - $p_filename = $p_filedescr['filename']; |
|
| 2808 | + // ----- Working variable |
|
| 2809 | + $p_filename = $p_filedescr['filename']; |
|
| 2810 | 2810 | |
| 2811 | 2811 | |
| 2812 | - // ----- Open the source file |
|
| 2813 | - if (($v_file = @fopen($p_filename, "rb")) == 0) { |
|
| 2814 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); |
|
| 2815 | - return PclZip::errorCode(); |
|
| 2816 | - } |
|
| 2812 | + // ----- Open the source file |
|
| 2813 | + if (($v_file = @fopen($p_filename, "rb")) == 0) { |
|
| 2814 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); |
|
| 2815 | + return PclZip::errorCode(); |
|
| 2816 | + } |
|
| 2817 | 2817 | |
| 2818 | - // ----- Creates a compressed temporary file |
|
| 2819 | - $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; |
|
| 2820 | - if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) { |
|
| 2821 | - fclose($v_file); |
|
| 2822 | - PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
|
| 2823 | - return PclZip::errorCode(); |
|
| 2824 | - } |
|
| 2818 | + // ----- Creates a compressed temporary file |
|
| 2819 | + $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; |
|
| 2820 | + if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) { |
|
| 2821 | + fclose($v_file); |
|
| 2822 | + PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
|
| 2823 | + return PclZip::errorCode(); |
|
| 2824 | + } |
|
| 2825 | 2825 | |
| 2826 | - // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
|
| 2827 | - $v_size = filesize($p_filename); |
|
| 2828 | - while ($v_size != 0) { |
|
| 2829 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2830 | - $v_buffer = @fread($v_file, $v_read_size); |
|
| 2831 | - //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 2832 | - @gzputs($v_file_compressed, $v_buffer, $v_read_size); |
|
| 2833 | - $v_size -= $v_read_size; |
|
| 2834 | - } |
|
| 2826 | + // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
|
| 2827 | + $v_size = filesize($p_filename); |
|
| 2828 | + while ($v_size != 0) { |
|
| 2829 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2830 | + $v_buffer = @fread($v_file, $v_read_size); |
|
| 2831 | + //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 2832 | + @gzputs($v_file_compressed, $v_buffer, $v_read_size); |
|
| 2833 | + $v_size -= $v_read_size; |
|
| 2834 | + } |
|
| 2835 | 2835 | |
| 2836 | - // ----- Close the file |
|
| 2837 | - @fclose($v_file); |
|
| 2838 | - @gzclose($v_file_compressed); |
|
| 2836 | + // ----- Close the file |
|
| 2837 | + @fclose($v_file); |
|
| 2838 | + @gzclose($v_file_compressed); |
|
| 2839 | 2839 | |
| 2840 | - // ----- Check the minimum file size |
|
| 2841 | - if (filesize($v_gzip_temp_name) < 18) { |
|
| 2842 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes'); |
|
| 2843 | - return PclZip::errorCode(); |
|
| 2844 | - } |
|
| 2840 | + // ----- Check the minimum file size |
|
| 2841 | + if (filesize($v_gzip_temp_name) < 18) { |
|
| 2842 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes'); |
|
| 2843 | + return PclZip::errorCode(); |
|
| 2844 | + } |
|
| 2845 | 2845 | |
| 2846 | - // ----- Extract the compressed attributes |
|
| 2847 | - if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { |
|
| 2848 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 2849 | - return PclZip::errorCode(); |
|
| 2850 | - } |
|
| 2846 | + // ----- Extract the compressed attributes |
|
| 2847 | + if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { |
|
| 2848 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 2849 | + return PclZip::errorCode(); |
|
| 2850 | + } |
|
| 2851 | 2851 | |
| 2852 | - // ----- Read the gzip file header |
|
| 2853 | - $v_binary_data = @fread($v_file_compressed, 10); |
|
| 2854 | - $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data); |
|
| 2852 | + // ----- Read the gzip file header |
|
| 2853 | + $v_binary_data = @fread($v_file_compressed, 10); |
|
| 2854 | + $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data); |
|
| 2855 | 2855 | |
| 2856 | - // ----- Check some parameters |
|
| 2857 | - $v_data_header['os'] = bin2hex($v_data_header['os']); |
|
| 2856 | + // ----- Check some parameters |
|
| 2857 | + $v_data_header['os'] = bin2hex($v_data_header['os']); |
|
| 2858 | 2858 | |
| 2859 | - // ----- Read the gzip file footer |
|
| 2860 | - @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8); |
|
| 2861 | - $v_binary_data = @fread($v_file_compressed, 8); |
|
| 2862 | - $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data); |
|
| 2859 | + // ----- Read the gzip file footer |
|
| 2860 | + @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8); |
|
| 2861 | + $v_binary_data = @fread($v_file_compressed, 8); |
|
| 2862 | + $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data); |
|
| 2863 | 2863 | |
| 2864 | - // ----- Set the attributes |
|
| 2865 | - $p_header['compression'] = ord($v_data_header['cm']); |
|
| 2866 | - //$p_header['mtime'] = $v_data_header['mtime']; |
|
| 2867 | - $p_header['crc'] = $v_data_footer['crc']; |
|
| 2868 | - $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18; |
|
| 2864 | + // ----- Set the attributes |
|
| 2865 | + $p_header['compression'] = ord($v_data_header['cm']); |
|
| 2866 | + //$p_header['mtime'] = $v_data_header['mtime']; |
|
| 2867 | + $p_header['crc'] = $v_data_footer['crc']; |
|
| 2868 | + $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18; |
|
| 2869 | 2869 | |
| 2870 | - // ----- Close the file |
|
| 2871 | - @fclose($v_file_compressed); |
|
| 2870 | + // ----- Close the file |
|
| 2871 | + @fclose($v_file_compressed); |
|
| 2872 | 2872 | |
| 2873 | - // ----- Call the header generation |
|
| 2874 | - if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
|
| 2875 | - return $v_result; |
|
| 2876 | - } |
|
| 2873 | + // ----- Call the header generation |
|
| 2874 | + if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
|
| 2875 | + return $v_result; |
|
| 2876 | + } |
|
| 2877 | 2877 | |
| 2878 | - // ----- Add the compressed data |
|
| 2879 | - if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) |
|
| 2880 | - { |
|
| 2881 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 2882 | - return PclZip::errorCode(); |
|
| 2883 | - } |
|
| 2878 | + // ----- Add the compressed data |
|
| 2879 | + if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) |
|
| 2880 | + { |
|
| 2881 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 2882 | + return PclZip::errorCode(); |
|
| 2883 | + } |
|
| 2884 | 2884 | |
| 2885 | - // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
|
| 2886 | - fseek($v_file_compressed, 10); |
|
| 2887 | - $v_size = $p_header['compressed_size']; |
|
| 2888 | - while ($v_size != 0) |
|
| 2889 | - { |
|
| 2890 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2891 | - $v_buffer = @fread($v_file_compressed, $v_read_size); |
|
| 2892 | - //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 2893 | - @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
|
| 2894 | - $v_size -= $v_read_size; |
|
| 2895 | - } |
|
| 2885 | + // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
|
| 2886 | + fseek($v_file_compressed, 10); |
|
| 2887 | + $v_size = $p_header['compressed_size']; |
|
| 2888 | + while ($v_size != 0) |
|
| 2889 | + { |
|
| 2890 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2891 | + $v_buffer = @fread($v_file_compressed, $v_read_size); |
|
| 2892 | + //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 2893 | + @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
|
| 2894 | + $v_size -= $v_read_size; |
|
| 2895 | + } |
|
| 2896 | 2896 | |
| 2897 | - // ----- Close the file |
|
| 2898 | - @fclose($v_file_compressed); |
|
| 2897 | + // ----- Close the file |
|
| 2898 | + @fclose($v_file_compressed); |
|
| 2899 | 2899 | |
| 2900 | - // ----- Unlink the temporary file |
|
| 2901 | - @unlink($v_gzip_temp_name); |
|
| 2900 | + // ----- Unlink the temporary file |
|
| 2901 | + @unlink($v_gzip_temp_name); |
|
| 2902 | 2902 | |
| 2903 | - // ----- Return |
|
| 2904 | - return $v_result; |
|
| 2903 | + // ----- Return |
|
| 2904 | + return $v_result; |
|
| 2905 | 2905 | } |
| 2906 | 2906 | // -------------------------------------------------------------------------------- |
| 2907 | 2907 | |
@@ -2915,107 +2915,107 @@ discard block |
||
| 2915 | 2915 | // -------------------------------------------------------------------------------- |
| 2916 | 2916 | function privCalculateStoredFilename(&$p_filedescr, &$p_options) |
| 2917 | 2917 | { |
| 2918 | - $v_result=1; |
|
| 2918 | + $v_result=1; |
|
| 2919 | 2919 | |
| 2920 | - // ----- Working variables |
|
| 2921 | - $p_filename = $p_filedescr['filename']; |
|
| 2922 | - if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { |
|
| 2923 | - $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; |
|
| 2924 | - } |
|
| 2925 | - else { |
|
| 2926 | - $p_add_dir = ''; |
|
| 2927 | - } |
|
| 2928 | - if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) { |
|
| 2929 | - $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; |
|
| 2930 | - } |
|
| 2931 | - else { |
|
| 2932 | - $p_remove_dir = ''; |
|
| 2933 | - } |
|
| 2934 | - if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 2935 | - $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
|
| 2936 | - } |
|
| 2937 | - else { |
|
| 2938 | - $p_remove_all_dir = 0; |
|
| 2939 | - } |
|
| 2920 | + // ----- Working variables |
|
| 2921 | + $p_filename = $p_filedescr['filename']; |
|
| 2922 | + if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { |
|
| 2923 | + $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; |
|
| 2924 | + } |
|
| 2925 | + else { |
|
| 2926 | + $p_add_dir = ''; |
|
| 2927 | + } |
|
| 2928 | + if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) { |
|
| 2929 | + $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; |
|
| 2930 | + } |
|
| 2931 | + else { |
|
| 2932 | + $p_remove_dir = ''; |
|
| 2933 | + } |
|
| 2934 | + if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 2935 | + $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
|
| 2936 | + } |
|
| 2937 | + else { |
|
| 2938 | + $p_remove_all_dir = 0; |
|
| 2939 | + } |
|
| 2940 | 2940 | |
| 2941 | 2941 | |
| 2942 | - // ----- Look for full name change |
|
| 2943 | - if (isset($p_filedescr['new_full_name'])) { |
|
| 2944 | - // ----- Remove drive letter if any |
|
| 2945 | - $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']); |
|
| 2946 | - } |
|
| 2942 | + // ----- Look for full name change |
|
| 2943 | + if (isset($p_filedescr['new_full_name'])) { |
|
| 2944 | + // ----- Remove drive letter if any |
|
| 2945 | + $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']); |
|
| 2946 | + } |
|
| 2947 | 2947 | |
| 2948 | - // ----- Look for path and/or short name change |
|
| 2949 | - else { |
|
| 2950 | - |
|
| 2951 | - // ----- Look for short name change |
|
| 2952 | - // Its when we cahnge just the filename but not the path |
|
| 2953 | - if (isset($p_filedescr['new_short_name'])) { |
|
| 2954 | - $v_path_info = pathinfo($p_filename); |
|
| 2955 | - $v_dir = ''; |
|
| 2956 | - if ($v_path_info['dirname'] != '') { |
|
| 2957 | - $v_dir = $v_path_info['dirname'].'/'; |
|
| 2958 | - } |
|
| 2959 | - $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; |
|
| 2960 | - } |
|
| 2961 | - else { |
|
| 2962 | - // ----- Calculate the stored filename |
|
| 2963 | - $v_stored_filename = $p_filename; |
|
| 2964 | - } |
|
| 2948 | + // ----- Look for path and/or short name change |
|
| 2949 | + else { |
|
| 2950 | + |
|
| 2951 | + // ----- Look for short name change |
|
| 2952 | + // Its when we cahnge just the filename but not the path |
|
| 2953 | + if (isset($p_filedescr['new_short_name'])) { |
|
| 2954 | + $v_path_info = pathinfo($p_filename); |
|
| 2955 | + $v_dir = ''; |
|
| 2956 | + if ($v_path_info['dirname'] != '') { |
|
| 2957 | + $v_dir = $v_path_info['dirname'].'/'; |
|
| 2958 | + } |
|
| 2959 | + $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; |
|
| 2960 | + } |
|
| 2961 | + else { |
|
| 2962 | + // ----- Calculate the stored filename |
|
| 2963 | + $v_stored_filename = $p_filename; |
|
| 2964 | + } |
|
| 2965 | 2965 | |
| 2966 | - // ----- Look for all path to remove |
|
| 2967 | - if ($p_remove_all_dir) { |
|
| 2968 | - $v_stored_filename = basename($p_filename); |
|
| 2969 | - } |
|
| 2970 | - // ----- Look for partial path remove |
|
| 2971 | - else if ($p_remove_dir != "") { |
|
| 2972 | - if (substr($p_remove_dir, -1) != '/') |
|
| 2973 | - $p_remove_dir .= "/"; |
|
| 2966 | + // ----- Look for all path to remove |
|
| 2967 | + if ($p_remove_all_dir) { |
|
| 2968 | + $v_stored_filename = basename($p_filename); |
|
| 2969 | + } |
|
| 2970 | + // ----- Look for partial path remove |
|
| 2971 | + else if ($p_remove_dir != "") { |
|
| 2972 | + if (substr($p_remove_dir, -1) != '/') |
|
| 2973 | + $p_remove_dir .= "/"; |
|
| 2974 | 2974 | |
| 2975 | - if ( (substr($p_filename, 0, 2) == "./") |
|
| 2976 | - || (substr($p_remove_dir, 0, 2) == "./")) { |
|
| 2975 | + if ( (substr($p_filename, 0, 2) == "./") |
|
| 2976 | + || (substr($p_remove_dir, 0, 2) == "./")) { |
|
| 2977 | 2977 | |
| 2978 | - if ( (substr($p_filename, 0, 2) == "./") |
|
| 2979 | - && (substr($p_remove_dir, 0, 2) != "./")) { |
|
| 2980 | - $p_remove_dir = "./".$p_remove_dir; |
|
| 2981 | - } |
|
| 2982 | - if ( (substr($p_filename, 0, 2) != "./") |
|
| 2983 | - && (substr($p_remove_dir, 0, 2) == "./")) { |
|
| 2984 | - $p_remove_dir = substr($p_remove_dir, 2); |
|
| 2985 | - } |
|
| 2986 | - } |
|
| 2978 | + if ( (substr($p_filename, 0, 2) == "./") |
|
| 2979 | + && (substr($p_remove_dir, 0, 2) != "./")) { |
|
| 2980 | + $p_remove_dir = "./".$p_remove_dir; |
|
| 2981 | + } |
|
| 2982 | + if ( (substr($p_filename, 0, 2) != "./") |
|
| 2983 | + && (substr($p_remove_dir, 0, 2) == "./")) { |
|
| 2984 | + $p_remove_dir = substr($p_remove_dir, 2); |
|
| 2985 | + } |
|
| 2986 | + } |
|
| 2987 | 2987 | |
| 2988 | - $v_compare = PclZipUtilPathInclusion($p_remove_dir, |
|
| 2989 | - $v_stored_filename); |
|
| 2990 | - if ($v_compare > 0) { |
|
| 2991 | - if ($v_compare == 2) { |
|
| 2992 | - $v_stored_filename = ""; |
|
| 2993 | - } |
|
| 2994 | - else { |
|
| 2995 | - $v_stored_filename = substr($v_stored_filename, |
|
| 2996 | - strlen($p_remove_dir)); |
|
| 2997 | - } |
|
| 2998 | - } |
|
| 2999 | - } |
|
| 2988 | + $v_compare = PclZipUtilPathInclusion($p_remove_dir, |
|
| 2989 | + $v_stored_filename); |
|
| 2990 | + if ($v_compare > 0) { |
|
| 2991 | + if ($v_compare == 2) { |
|
| 2992 | + $v_stored_filename = ""; |
|
| 2993 | + } |
|
| 2994 | + else { |
|
| 2995 | + $v_stored_filename = substr($v_stored_filename, |
|
| 2996 | + strlen($p_remove_dir)); |
|
| 2997 | + } |
|
| 2998 | + } |
|
| 2999 | + } |
|
| 3000 | 3000 | |
| 3001 | - // ----- Remove drive letter if any |
|
| 3002 | - $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename); |
|
| 3001 | + // ----- Remove drive letter if any |
|
| 3002 | + $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename); |
|
| 3003 | 3003 | |
| 3004 | - // ----- Look for path to add |
|
| 3005 | - if ($p_add_dir != "") { |
|
| 3006 | - if (substr($p_add_dir, -1) == "/") |
|
| 3007 | - $v_stored_filename = $p_add_dir.$v_stored_filename; |
|
| 3008 | - else |
|
| 3009 | - $v_stored_filename = $p_add_dir."/".$v_stored_filename; |
|
| 3010 | - } |
|
| 3011 | - } |
|
| 3004 | + // ----- Look for path to add |
|
| 3005 | + if ($p_add_dir != "") { |
|
| 3006 | + if (substr($p_add_dir, -1) == "/") |
|
| 3007 | + $v_stored_filename = $p_add_dir.$v_stored_filename; |
|
| 3008 | + else |
|
| 3009 | + $v_stored_filename = $p_add_dir."/".$v_stored_filename; |
|
| 3010 | + } |
|
| 3011 | + } |
|
| 3012 | 3012 | |
| 3013 | - // ----- Filename (reduce the path of stored name) |
|
| 3014 | - $v_stored_filename = PclZipUtilPathReduction($v_stored_filename); |
|
| 3015 | - $p_filedescr['stored_filename'] = $v_stored_filename; |
|
| 3013 | + // ----- Filename (reduce the path of stored name) |
|
| 3014 | + $v_stored_filename = PclZipUtilPathReduction($v_stored_filename); |
|
| 3015 | + $p_filedescr['stored_filename'] = $v_stored_filename; |
|
| 3016 | 3016 | |
| 3017 | - // ----- Return |
|
| 3018 | - return $v_result; |
|
| 3017 | + // ----- Return |
|
| 3018 | + return $v_result; |
|
| 3019 | 3019 | } |
| 3020 | 3020 | // -------------------------------------------------------------------------------- |
| 3021 | 3021 | |
@@ -3027,40 +3027,40 @@ discard block |
||
| 3027 | 3027 | // -------------------------------------------------------------------------------- |
| 3028 | 3028 | function privWriteFileHeader(&$p_header) |
| 3029 | 3029 | { |
| 3030 | - $v_result=1; |
|
| 3030 | + $v_result=1; |
|
| 3031 | 3031 | |
| 3032 | - // ----- Store the offset position of the file |
|
| 3033 | - $p_header['offset'] = ftell($this->zip_fd); |
|
| 3032 | + // ----- Store the offset position of the file |
|
| 3033 | + $p_header['offset'] = ftell($this->zip_fd); |
|
| 3034 | 3034 | |
| 3035 | - // ----- Transform UNIX mtime to DOS format mdate/mtime |
|
| 3036 | - $v_date = getdate($p_header['mtime']); |
|
| 3037 | - $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; |
|
| 3038 | - $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; |
|
| 3035 | + // ----- Transform UNIX mtime to DOS format mdate/mtime |
|
| 3036 | + $v_date = getdate($p_header['mtime']); |
|
| 3037 | + $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; |
|
| 3038 | + $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; |
|
| 3039 | 3039 | |
| 3040 | - // ----- Packed data |
|
| 3041 | - $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, |
|
| 3042 | - $p_header['version_extracted'], $p_header['flag'], |
|
| 3043 | - $p_header['compression'], $v_mtime, $v_mdate, |
|
| 3044 | - $p_header['crc'], $p_header['compressed_size'], |
|
| 3040 | + // ----- Packed data |
|
| 3041 | + $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, |
|
| 3042 | + $p_header['version_extracted'], $p_header['flag'], |
|
| 3043 | + $p_header['compression'], $v_mtime, $v_mdate, |
|
| 3044 | + $p_header['crc'], $p_header['compressed_size'], |
|
| 3045 | 3045 | $p_header['size'], |
| 3046 | - strlen($p_header['stored_filename']), |
|
| 3046 | + strlen($p_header['stored_filename']), |
|
| 3047 | 3047 | $p_header['extra_len']); |
| 3048 | 3048 | |
| 3049 | - // ----- Write the first 148 bytes of the header in the archive |
|
| 3050 | - fputs($this->zip_fd, $v_binary_data, 30); |
|
| 3049 | + // ----- Write the first 148 bytes of the header in the archive |
|
| 3050 | + fputs($this->zip_fd, $v_binary_data, 30); |
|
| 3051 | 3051 | |
| 3052 | - // ----- Write the variable fields |
|
| 3053 | - if (strlen($p_header['stored_filename']) != 0) |
|
| 3054 | - { |
|
| 3055 | - fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); |
|
| 3056 | - } |
|
| 3057 | - if ($p_header['extra_len'] != 0) |
|
| 3058 | - { |
|
| 3059 | - fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); |
|
| 3060 | - } |
|
| 3052 | + // ----- Write the variable fields |
|
| 3053 | + if (strlen($p_header['stored_filename']) != 0) |
|
| 3054 | + { |
|
| 3055 | + fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); |
|
| 3056 | + } |
|
| 3057 | + if ($p_header['extra_len'] != 0) |
|
| 3058 | + { |
|
| 3059 | + fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); |
|
| 3060 | + } |
|
| 3061 | 3061 | |
| 3062 | - // ----- Return |
|
| 3063 | - return $v_result; |
|
| 3062 | + // ----- Return |
|
| 3063 | + return $v_result; |
|
| 3064 | 3064 | } |
| 3065 | 3065 | // -------------------------------------------------------------------------------- |
| 3066 | 3066 | |
@@ -3072,48 +3072,48 @@ discard block |
||
| 3072 | 3072 | // -------------------------------------------------------------------------------- |
| 3073 | 3073 | function privWriteCentralFileHeader(&$p_header) |
| 3074 | 3074 | { |
| 3075 | - $v_result=1; |
|
| 3075 | + $v_result=1; |
|
| 3076 | 3076 | |
| 3077 | - // TBC |
|
| 3078 | - //for(reset($p_header); $key = key($p_header); next($p_header)) { |
|
| 3079 | - //} |
|
| 3077 | + // TBC |
|
| 3078 | + //for(reset($p_header); $key = key($p_header); next($p_header)) { |
|
| 3079 | + //} |
|
| 3080 | 3080 | |
| 3081 | - // ----- Transform UNIX mtime to DOS format mdate/mtime |
|
| 3082 | - $v_date = getdate($p_header['mtime']); |
|
| 3083 | - $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; |
|
| 3084 | - $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; |
|
| 3081 | + // ----- Transform UNIX mtime to DOS format mdate/mtime |
|
| 3082 | + $v_date = getdate($p_header['mtime']); |
|
| 3083 | + $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; |
|
| 3084 | + $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; |
|
| 3085 | 3085 | |
| 3086 | 3086 | |
| 3087 | - // ----- Packed data |
|
| 3088 | - $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, |
|
| 3089 | - $p_header['version'], $p_header['version_extracted'], |
|
| 3090 | - $p_header['flag'], $p_header['compression'], |
|
| 3087 | + // ----- Packed data |
|
| 3088 | + $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, |
|
| 3089 | + $p_header['version'], $p_header['version_extracted'], |
|
| 3090 | + $p_header['flag'], $p_header['compression'], |
|
| 3091 | 3091 | $v_mtime, $v_mdate, $p_header['crc'], |
| 3092 | - $p_header['compressed_size'], $p_header['size'], |
|
| 3093 | - strlen($p_header['stored_filename']), |
|
| 3092 | + $p_header['compressed_size'], $p_header['size'], |
|
| 3093 | + strlen($p_header['stored_filename']), |
|
| 3094 | 3094 | $p_header['extra_len'], $p_header['comment_len'], |
| 3095 | - $p_header['disk'], $p_header['internal'], |
|
| 3095 | + $p_header['disk'], $p_header['internal'], |
|
| 3096 | 3096 | $p_header['external'], $p_header['offset']); |
| 3097 | 3097 | |
| 3098 | - // ----- Write the 42 bytes of the header in the zip file |
|
| 3099 | - fputs($this->zip_fd, $v_binary_data, 46); |
|
| 3098 | + // ----- Write the 42 bytes of the header in the zip file |
|
| 3099 | + fputs($this->zip_fd, $v_binary_data, 46); |
|
| 3100 | 3100 | |
| 3101 | - // ----- Write the variable fields |
|
| 3102 | - if (strlen($p_header['stored_filename']) != 0) |
|
| 3103 | - { |
|
| 3104 | - fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); |
|
| 3105 | - } |
|
| 3106 | - if ($p_header['extra_len'] != 0) |
|
| 3107 | - { |
|
| 3108 | - fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); |
|
| 3109 | - } |
|
| 3110 | - if ($p_header['comment_len'] != 0) |
|
| 3111 | - { |
|
| 3112 | - fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']); |
|
| 3113 | - } |
|
| 3101 | + // ----- Write the variable fields |
|
| 3102 | + if (strlen($p_header['stored_filename']) != 0) |
|
| 3103 | + { |
|
| 3104 | + fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); |
|
| 3105 | + } |
|
| 3106 | + if ($p_header['extra_len'] != 0) |
|
| 3107 | + { |
|
| 3108 | + fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); |
|
| 3109 | + } |
|
| 3110 | + if ($p_header['comment_len'] != 0) |
|
| 3111 | + { |
|
| 3112 | + fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']); |
|
| 3113 | + } |
|
| 3114 | 3114 | |
| 3115 | - // ----- Return |
|
| 3116 | - return $v_result; |
|
| 3115 | + // ----- Return |
|
| 3116 | + return $v_result; |
|
| 3117 | 3117 | } |
| 3118 | 3118 | // -------------------------------------------------------------------------------- |
| 3119 | 3119 | |
@@ -3125,24 +3125,24 @@ discard block |
||
| 3125 | 3125 | // -------------------------------------------------------------------------------- |
| 3126 | 3126 | function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment) |
| 3127 | 3127 | { |
| 3128 | - $v_result=1; |
|
| 3128 | + $v_result=1; |
|
| 3129 | 3129 | |
| 3130 | - // ----- Packed data |
|
| 3131 | - $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, |
|
| 3132 | - $p_nb_entries, $p_size, |
|
| 3130 | + // ----- Packed data |
|
| 3131 | + $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, |
|
| 3132 | + $p_nb_entries, $p_size, |
|
| 3133 | 3133 | $p_offset, strlen($p_comment)); |
| 3134 | 3134 | |
| 3135 | - // ----- Write the 22 bytes of the header in the zip file |
|
| 3136 | - fputs($this->zip_fd, $v_binary_data, 22); |
|
| 3135 | + // ----- Write the 22 bytes of the header in the zip file |
|
| 3136 | + fputs($this->zip_fd, $v_binary_data, 22); |
|
| 3137 | 3137 | |
| 3138 | - // ----- Write the variable fields |
|
| 3139 | - if (strlen($p_comment) != 0) |
|
| 3140 | - { |
|
| 3141 | - fputs($this->zip_fd, $p_comment, strlen($p_comment)); |
|
| 3142 | - } |
|
| 3138 | + // ----- Write the variable fields |
|
| 3139 | + if (strlen($p_comment) != 0) |
|
| 3140 | + { |
|
| 3141 | + fputs($this->zip_fd, $p_comment, strlen($p_comment)); |
|
| 3142 | + } |
|
| 3143 | 3143 | |
| 3144 | - // ----- Return |
|
| 3145 | - return $v_result; |
|
| 3144 | + // ----- Return |
|
| 3145 | + return $v_result; |
|
| 3146 | 3146 | } |
| 3147 | 3147 | // -------------------------------------------------------------------------------- |
| 3148 | 3148 | |
@@ -3154,69 +3154,69 @@ discard block |
||
| 3154 | 3154 | // -------------------------------------------------------------------------------- |
| 3155 | 3155 | function privList(&$p_list) |
| 3156 | 3156 | { |
| 3157 | - $v_result=1; |
|
| 3157 | + $v_result=1; |
|
| 3158 | 3158 | |
| 3159 | - // ----- Magic quotes trick |
|
| 3160 | - $this->privDisableMagicQuotes(); |
|
| 3159 | + // ----- Magic quotes trick |
|
| 3160 | + $this->privDisableMagicQuotes(); |
|
| 3161 | 3161 | |
| 3162 | - // ----- Open the zip file |
|
| 3163 | - if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) |
|
| 3164 | - { |
|
| 3165 | - // ----- Magic quotes trick |
|
| 3166 | - $this->privSwapBackMagicQuotes(); |
|
| 3162 | + // ----- Open the zip file |
|
| 3163 | + if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) |
|
| 3164 | + { |
|
| 3165 | + // ----- Magic quotes trick |
|
| 3166 | + $this->privSwapBackMagicQuotes(); |
|
| 3167 | 3167 | |
| 3168 | - // ----- Error log |
|
| 3169 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); |
|
| 3168 | + // ----- Error log |
|
| 3169 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); |
|
| 3170 | 3170 | |
| 3171 | - // ----- Return |
|
| 3172 | - return PclZip::errorCode(); |
|
| 3173 | - } |
|
| 3171 | + // ----- Return |
|
| 3172 | + return PclZip::errorCode(); |
|
| 3173 | + } |
|
| 3174 | 3174 | |
| 3175 | - // ----- Read the central directory informations |
|
| 3176 | - $v_central_dir = array(); |
|
| 3177 | - if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 3178 | - { |
|
| 3179 | - $this->privSwapBackMagicQuotes(); |
|
| 3180 | - return $v_result; |
|
| 3181 | - } |
|
| 3175 | + // ----- Read the central directory informations |
|
| 3176 | + $v_central_dir = array(); |
|
| 3177 | + if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 3178 | + { |
|
| 3179 | + $this->privSwapBackMagicQuotes(); |
|
| 3180 | + return $v_result; |
|
| 3181 | + } |
|
| 3182 | 3182 | |
| 3183 | - // ----- Go to beginning of Central Dir |
|
| 3184 | - @rewind($this->zip_fd); |
|
| 3185 | - if (@fseek($this->zip_fd, $v_central_dir['offset'])) |
|
| 3186 | - { |
|
| 3187 | - $this->privSwapBackMagicQuotes(); |
|
| 3183 | + // ----- Go to beginning of Central Dir |
|
| 3184 | + @rewind($this->zip_fd); |
|
| 3185 | + if (@fseek($this->zip_fd, $v_central_dir['offset'])) |
|
| 3186 | + { |
|
| 3187 | + $this->privSwapBackMagicQuotes(); |
|
| 3188 | 3188 | |
| 3189 | - // ----- Error log |
|
| 3190 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 3189 | + // ----- Error log |
|
| 3190 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 3191 | 3191 | |
| 3192 | - // ----- Return |
|
| 3193 | - return PclZip::errorCode(); |
|
| 3194 | - } |
|
| 3192 | + // ----- Return |
|
| 3193 | + return PclZip::errorCode(); |
|
| 3194 | + } |
|
| 3195 | 3195 | |
| 3196 | - // ----- Read each entry |
|
| 3197 | - for ($i=0; $i<$v_central_dir['entries']; $i++) |
|
| 3198 | - { |
|
| 3199 | - // ----- Read the file header |
|
| 3200 | - if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
|
| 3201 | - { |
|
| 3202 | - $this->privSwapBackMagicQuotes(); |
|
| 3203 | - return $v_result; |
|
| 3204 | - } |
|
| 3205 | - $v_header['index'] = $i; |
|
| 3196 | + // ----- Read each entry |
|
| 3197 | + for ($i=0; $i<$v_central_dir['entries']; $i++) |
|
| 3198 | + { |
|
| 3199 | + // ----- Read the file header |
|
| 3200 | + if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
|
| 3201 | + { |
|
| 3202 | + $this->privSwapBackMagicQuotes(); |
|
| 3203 | + return $v_result; |
|
| 3204 | + } |
|
| 3205 | + $v_header['index'] = $i; |
|
| 3206 | 3206 | |
| 3207 | - // ----- Get the only interesting attributes |
|
| 3208 | - $this->privConvertHeader2FileInfo($v_header, $p_list[$i]); |
|
| 3209 | - unset($v_header); |
|
| 3210 | - } |
|
| 3207 | + // ----- Get the only interesting attributes |
|
| 3208 | + $this->privConvertHeader2FileInfo($v_header, $p_list[$i]); |
|
| 3209 | + unset($v_header); |
|
| 3210 | + } |
|
| 3211 | 3211 | |
| 3212 | - // ----- Close the zip file |
|
| 3213 | - $this->privCloseFd(); |
|
| 3212 | + // ----- Close the zip file |
|
| 3213 | + $this->privCloseFd(); |
|
| 3214 | 3214 | |
| 3215 | - // ----- Magic quotes trick |
|
| 3216 | - $this->privSwapBackMagicQuotes(); |
|
| 3215 | + // ----- Magic quotes trick |
|
| 3216 | + $this->privSwapBackMagicQuotes(); |
|
| 3217 | 3217 | |
| 3218 | - // ----- Return |
|
| 3219 | - return $v_result; |
|
| 3218 | + // ----- Return |
|
| 3219 | + return $v_result; |
|
| 3220 | 3220 | } |
| 3221 | 3221 | // -------------------------------------------------------------------------------- |
| 3222 | 3222 | |
@@ -3241,24 +3241,24 @@ discard block |
||
| 3241 | 3241 | // -------------------------------------------------------------------------------- |
| 3242 | 3242 | function privConvertHeader2FileInfo($p_header, &$p_info) |
| 3243 | 3243 | { |
| 3244 | - $v_result=1; |
|
| 3245 | - |
|
| 3246 | - // ----- Get the interesting attributes |
|
| 3247 | - $v_temp_path = PclZipUtilPathReduction($p_header['filename']); |
|
| 3248 | - $p_info['filename'] = $v_temp_path; |
|
| 3249 | - $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']); |
|
| 3250 | - $p_info['stored_filename'] = $v_temp_path; |
|
| 3251 | - $p_info['size'] = $p_header['size']; |
|
| 3252 | - $p_info['compressed_size'] = $p_header['compressed_size']; |
|
| 3253 | - $p_info['mtime'] = $p_header['mtime']; |
|
| 3254 | - $p_info['comment'] = $p_header['comment']; |
|
| 3255 | - $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); |
|
| 3256 | - $p_info['index'] = $p_header['index']; |
|
| 3257 | - $p_info['status'] = $p_header['status']; |
|
| 3258 | - $p_info['crc'] = $p_header['crc']; |
|
| 3259 | - |
|
| 3260 | - // ----- Return |
|
| 3261 | - return $v_result; |
|
| 3244 | + $v_result=1; |
|
| 3245 | + |
|
| 3246 | + // ----- Get the interesting attributes |
|
| 3247 | + $v_temp_path = PclZipUtilPathReduction($p_header['filename']); |
|
| 3248 | + $p_info['filename'] = $v_temp_path; |
|
| 3249 | + $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']); |
|
| 3250 | + $p_info['stored_filename'] = $v_temp_path; |
|
| 3251 | + $p_info['size'] = $p_header['size']; |
|
| 3252 | + $p_info['compressed_size'] = $p_header['compressed_size']; |
|
| 3253 | + $p_info['mtime'] = $p_header['mtime']; |
|
| 3254 | + $p_info['comment'] = $p_header['comment']; |
|
| 3255 | + $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); |
|
| 3256 | + $p_info['index'] = $p_header['index']; |
|
| 3257 | + $p_info['status'] = $p_header['status']; |
|
| 3258 | + $p_info['crc'] = $p_header['crc']; |
|
| 3259 | + |
|
| 3260 | + // ----- Return |
|
| 3261 | + return $v_result; |
|
| 3262 | 3262 | } |
| 3263 | 3263 | // -------------------------------------------------------------------------------- |
| 3264 | 3264 | |
@@ -3280,122 +3280,122 @@ discard block |
||
| 3280 | 3280 | // -------------------------------------------------------------------------------- |
| 3281 | 3281 | function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
| 3282 | 3282 | { |
| 3283 | - $v_result=1; |
|
| 3283 | + $v_result=1; |
|
| 3284 | 3284 | |
| 3285 | - // ----- Magic quotes trick |
|
| 3286 | - $this->privDisableMagicQuotes(); |
|
| 3285 | + // ----- Magic quotes trick |
|
| 3286 | + $this->privDisableMagicQuotes(); |
|
| 3287 | 3287 | |
| 3288 | - // ----- Check the path |
|
| 3289 | - if ( ($p_path == "") |
|
| 3290 | - || ( (substr($p_path, 0, 1) != "/") |
|
| 3291 | - && (substr($p_path, 0, 3) != "../") |
|
| 3288 | + // ----- Check the path |
|
| 3289 | + if ( ($p_path == "") |
|
| 3290 | + || ( (substr($p_path, 0, 1) != "/") |
|
| 3291 | + && (substr($p_path, 0, 3) != "../") |
|
| 3292 | 3292 | && (substr($p_path,1,2)!=":/"))) |
| 3293 | - $p_path = "./".$p_path; |
|
| 3294 | - |
|
| 3295 | - // ----- Reduce the path last (and duplicated) '/' |
|
| 3296 | - if (($p_path != "./") && ($p_path != "/")) |
|
| 3297 | - { |
|
| 3298 | - // ----- Look for the path end '/' |
|
| 3299 | - while (substr($p_path, -1) == "/") |
|
| 3300 | - { |
|
| 3301 | - $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
| 3302 | - } |
|
| 3303 | - } |
|
| 3293 | + $p_path = "./".$p_path; |
|
| 3294 | + |
|
| 3295 | + // ----- Reduce the path last (and duplicated) '/' |
|
| 3296 | + if (($p_path != "./") && ($p_path != "/")) |
|
| 3297 | + { |
|
| 3298 | + // ----- Look for the path end '/' |
|
| 3299 | + while (substr($p_path, -1) == "/") |
|
| 3300 | + { |
|
| 3301 | + $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
| 3302 | + } |
|
| 3303 | + } |
|
| 3304 | 3304 | |
| 3305 | - // ----- Look for path to remove format (should end by /) |
|
| 3306 | - if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/')) |
|
| 3307 | - { |
|
| 3308 | - $p_remove_path .= '/'; |
|
| 3309 | - } |
|
| 3310 | - $p_remove_path_size = strlen($p_remove_path); |
|
| 3305 | + // ----- Look for path to remove format (should end by /) |
|
| 3306 | + if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/')) |
|
| 3307 | + { |
|
| 3308 | + $p_remove_path .= '/'; |
|
| 3309 | + } |
|
| 3310 | + $p_remove_path_size = strlen($p_remove_path); |
|
| 3311 | 3311 | |
| 3312 | - // ----- Open the zip file |
|
| 3313 | - if (($v_result = $this->privOpenFd('rb')) != 1) |
|
| 3314 | - { |
|
| 3315 | - $this->privSwapBackMagicQuotes(); |
|
| 3316 | - return $v_result; |
|
| 3317 | - } |
|
| 3312 | + // ----- Open the zip file |
|
| 3313 | + if (($v_result = $this->privOpenFd('rb')) != 1) |
|
| 3314 | + { |
|
| 3315 | + $this->privSwapBackMagicQuotes(); |
|
| 3316 | + return $v_result; |
|
| 3317 | + } |
|
| 3318 | 3318 | |
| 3319 | - // ----- Read the central directory informations |
|
| 3320 | - $v_central_dir = array(); |
|
| 3321 | - if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 3322 | - { |
|
| 3323 | - // ----- Close the zip file |
|
| 3324 | - $this->privCloseFd(); |
|
| 3325 | - $this->privSwapBackMagicQuotes(); |
|
| 3319 | + // ----- Read the central directory informations |
|
| 3320 | + $v_central_dir = array(); |
|
| 3321 | + if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 3322 | + { |
|
| 3323 | + // ----- Close the zip file |
|
| 3324 | + $this->privCloseFd(); |
|
| 3325 | + $this->privSwapBackMagicQuotes(); |
|
| 3326 | 3326 | |
| 3327 | - return $v_result; |
|
| 3328 | - } |
|
| 3327 | + return $v_result; |
|
| 3328 | + } |
|
| 3329 | 3329 | |
| 3330 | - // ----- Start at beginning of Central Dir |
|
| 3331 | - $v_pos_entry = $v_central_dir['offset']; |
|
| 3330 | + // ----- Start at beginning of Central Dir |
|
| 3331 | + $v_pos_entry = $v_central_dir['offset']; |
|
| 3332 | 3332 | |
| 3333 | - // ----- Read each entry |
|
| 3334 | - $j_start = 0; |
|
| 3335 | - for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
|
| 3336 | - { |
|
| 3333 | + // ----- Read each entry |
|
| 3334 | + $j_start = 0; |
|
| 3335 | + for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
|
| 3336 | + { |
|
| 3337 | 3337 | |
| 3338 | - // ----- Read next Central dir entry |
|
| 3339 | - @rewind($this->zip_fd); |
|
| 3340 | - if (@fseek($this->zip_fd, $v_pos_entry)) |
|
| 3341 | - { |
|
| 3342 | - // ----- Close the zip file |
|
| 3343 | - $this->privCloseFd(); |
|
| 3344 | - $this->privSwapBackMagicQuotes(); |
|
| 3338 | + // ----- Read next Central dir entry |
|
| 3339 | + @rewind($this->zip_fd); |
|
| 3340 | + if (@fseek($this->zip_fd, $v_pos_entry)) |
|
| 3341 | + { |
|
| 3342 | + // ----- Close the zip file |
|
| 3343 | + $this->privCloseFd(); |
|
| 3344 | + $this->privSwapBackMagicQuotes(); |
|
| 3345 | 3345 | |
| 3346 | - // ----- Error log |
|
| 3347 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 3346 | + // ----- Error log |
|
| 3347 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 3348 | 3348 | |
| 3349 | - // ----- Return |
|
| 3350 | - return PclZip::errorCode(); |
|
| 3351 | - } |
|
| 3349 | + // ----- Return |
|
| 3350 | + return PclZip::errorCode(); |
|
| 3351 | + } |
|
| 3352 | 3352 | |
| 3353 | - // ----- Read the file header |
|
| 3354 | - $v_header = array(); |
|
| 3355 | - if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
|
| 3356 | - { |
|
| 3357 | - // ----- Close the zip file |
|
| 3358 | - $this->privCloseFd(); |
|
| 3359 | - $this->privSwapBackMagicQuotes(); |
|
| 3353 | + // ----- Read the file header |
|
| 3354 | + $v_header = array(); |
|
| 3355 | + if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
|
| 3356 | + { |
|
| 3357 | + // ----- Close the zip file |
|
| 3358 | + $this->privCloseFd(); |
|
| 3359 | + $this->privSwapBackMagicQuotes(); |
|
| 3360 | 3360 | |
| 3361 | - return $v_result; |
|
| 3362 | - } |
|
| 3361 | + return $v_result; |
|
| 3362 | + } |
|
| 3363 | 3363 | |
| 3364 | - // ----- Store the index |
|
| 3365 | - $v_header['index'] = $i; |
|
| 3364 | + // ----- Store the index |
|
| 3365 | + $v_header['index'] = $i; |
|
| 3366 | 3366 | |
| 3367 | - // ----- Store the file position |
|
| 3368 | - $v_pos_entry = ftell($this->zip_fd); |
|
| 3367 | + // ----- Store the file position |
|
| 3368 | + $v_pos_entry = ftell($this->zip_fd); |
|
| 3369 | 3369 | |
| 3370 | - // ----- Look for the specific extract rules |
|
| 3371 | - $v_extract = false; |
|
| 3370 | + // ----- Look for the specific extract rules |
|
| 3371 | + $v_extract = false; |
|
| 3372 | 3372 | |
| 3373 | - // ----- Look for extract by name rule |
|
| 3374 | - if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 3375 | - && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
|
| 3373 | + // ----- Look for extract by name rule |
|
| 3374 | + if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 3375 | + && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
|
| 3376 | 3376 | |
| 3377 | - // ----- Look if the filename is in the list |
|
| 3378 | - for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { |
|
| 3377 | + // ----- Look if the filename is in the list |
|
| 3378 | + for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { |
|
| 3379 | 3379 | |
| 3380 | - // ----- Look for a directory |
|
| 3381 | - if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
|
| 3380 | + // ----- Look for a directory |
|
| 3381 | + if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
|
| 3382 | 3382 | |
| 3383 | - // ----- Look if the directory is in the filename path |
|
| 3384 | - if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 3385 | - && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
|
| 3386 | - $v_extract = true; |
|
| 3387 | - } |
|
| 3388 | - } |
|
| 3389 | - // ----- Look for a filename |
|
| 3390 | - elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
|
| 3391 | - $v_extract = true; |
|
| 3392 | - } |
|
| 3393 | - } |
|
| 3394 | - } |
|
| 3383 | + // ----- Look if the directory is in the filename path |
|
| 3384 | + if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 3385 | + && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
|
| 3386 | + $v_extract = true; |
|
| 3387 | + } |
|
| 3388 | + } |
|
| 3389 | + // ----- Look for a filename |
|
| 3390 | + elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
|
| 3391 | + $v_extract = true; |
|
| 3392 | + } |
|
| 3393 | + } |
|
| 3394 | + } |
|
| 3395 | 3395 | |
| 3396 | - // ----- Look for extract by ereg rule |
|
| 3397 | - // ereg() is deprecated with PHP 5.3 |
|
| 3398 | - /* |
|
| 3396 | + // ----- Look for extract by ereg rule |
|
| 3397 | + // ereg() is deprecated with PHP 5.3 |
|
| 3398 | + /* |
|
| 3399 | 3399 | else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) |
| 3400 | 3400 | && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { |
| 3401 | 3401 | |
@@ -3405,207 +3405,207 @@ discard block |
||
| 3405 | 3405 | } |
| 3406 | 3406 | */ |
| 3407 | 3407 | |
| 3408 | - // ----- Look for extract by preg rule |
|
| 3409 | - else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 3410 | - && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
|
| 3408 | + // ----- Look for extract by preg rule |
|
| 3409 | + else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 3410 | + && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
|
| 3411 | 3411 | |
| 3412 | - if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { |
|
| 3413 | - $v_extract = true; |
|
| 3414 | - } |
|
| 3415 | - } |
|
| 3412 | + if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { |
|
| 3413 | + $v_extract = true; |
|
| 3414 | + } |
|
| 3415 | + } |
|
| 3416 | 3416 | |
| 3417 | - // ----- Look for extract by index rule |
|
| 3418 | - else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 3419 | - && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
|
| 3417 | + // ----- Look for extract by index rule |
|
| 3418 | + else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 3419 | + && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
|
| 3420 | 3420 | |
| 3421 | - // ----- Look if the index is in the list |
|
| 3422 | - for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { |
|
| 3423 | - |
|
| 3424 | - if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 3425 | - $v_extract = true; |
|
| 3426 | - } |
|
| 3427 | - if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 3428 | - $j_start = $j+1; |
|
| 3429 | - } |
|
| 3430 | - |
|
| 3431 | - if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
|
| 3432 | - break; |
|
| 3433 | - } |
|
| 3434 | - } |
|
| 3435 | - } |
|
| 3421 | + // ----- Look if the index is in the list |
|
| 3422 | + for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { |
|
| 3423 | + |
|
| 3424 | + if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 3425 | + $v_extract = true; |
|
| 3426 | + } |
|
| 3427 | + if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 3428 | + $j_start = $j+1; |
|
| 3429 | + } |
|
| 3430 | + |
|
| 3431 | + if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
|
| 3432 | + break; |
|
| 3433 | + } |
|
| 3434 | + } |
|
| 3435 | + } |
|
| 3436 | 3436 | |
| 3437 | - // ----- Look for no rule, which means extract all the archive |
|
| 3438 | - else { |
|
| 3439 | - $v_extract = true; |
|
| 3440 | - } |
|
| 3437 | + // ----- Look for no rule, which means extract all the archive |
|
| 3438 | + else { |
|
| 3439 | + $v_extract = true; |
|
| 3440 | + } |
|
| 3441 | 3441 | |
| 3442 | 3442 | // ----- Check compression method |
| 3443 | 3443 | if ( ($v_extract) |
| 3444 | - && ( ($v_header['compression'] != 8) |
|
| 3445 | - && ($v_header['compression'] != 0))) { |
|
| 3446 | - $v_header['status'] = 'unsupported_compression'; |
|
| 3444 | + && ( ($v_header['compression'] != 8) |
|
| 3445 | + && ($v_header['compression'] != 0))) { |
|
| 3446 | + $v_header['status'] = 'unsupported_compression'; |
|
| 3447 | 3447 | |
| 3448 | - // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3449 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3450 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3448 | + // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3449 | + if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3450 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3451 | 3451 | |
| 3452 | - $this->privSwapBackMagicQuotes(); |
|
| 3452 | + $this->privSwapBackMagicQuotes(); |
|
| 3453 | 3453 | |
| 3454 | - PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, |
|
| 3455 | - "Filename '".$v_header['stored_filename']."' is " |
|
| 3456 | - ."compressed by an unsupported compression " |
|
| 3457 | - ."method (".$v_header['compression'].") "); |
|
| 3454 | + PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, |
|
| 3455 | + "Filename '".$v_header['stored_filename']."' is " |
|
| 3456 | + ."compressed by an unsupported compression " |
|
| 3457 | + ."method (".$v_header['compression'].") "); |
|
| 3458 | 3458 | |
| 3459 | - return PclZip::errorCode(); |
|
| 3459 | + return PclZip::errorCode(); |
|
| 3460 | 3460 | } |
| 3461 | 3461 | } |
| 3462 | 3462 | |
| 3463 | 3463 | // ----- Check encrypted files |
| 3464 | 3464 | if (($v_extract) && (($v_header['flag'] & 1) == 1)) { |
| 3465 | - $v_header['status'] = 'unsupported_encryption'; |
|
| 3465 | + $v_header['status'] = 'unsupported_encryption'; |
|
| 3466 | 3466 | |
| 3467 | - // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3468 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3469 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3467 | + // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3468 | + if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3469 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3470 | 3470 | |
| 3471 | - $this->privSwapBackMagicQuotes(); |
|
| 3471 | + $this->privSwapBackMagicQuotes(); |
|
| 3472 | 3472 | |
| 3473 | - PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, |
|
| 3474 | - "Unsupported encryption for " |
|
| 3475 | - ." filename '".$v_header['stored_filename'] |
|
| 3473 | + PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, |
|
| 3474 | + "Unsupported encryption for " |
|
| 3475 | + ." filename '".$v_header['stored_filename'] |
|
| 3476 | 3476 | ."'"); |
| 3477 | 3477 | |
| 3478 | - return PclZip::errorCode(); |
|
| 3478 | + return PclZip::errorCode(); |
|
| 3479 | 3479 | } |
| 3480 | - } |
|
| 3480 | + } |
|
| 3481 | 3481 | |
| 3482 | - // ----- Look for real extraction |
|
| 3483 | - if (($v_extract) && ($v_header['status'] != 'ok')) { |
|
| 3484 | - $v_result = $this->privConvertHeader2FileInfo($v_header, |
|
| 3485 | - $p_file_list[$v_nb_extracted++]); |
|
| 3486 | - if ($v_result != 1) { |
|
| 3487 | - $this->privCloseFd(); |
|
| 3488 | - $this->privSwapBackMagicQuotes(); |
|
| 3489 | - return $v_result; |
|
| 3490 | - } |
|
| 3482 | + // ----- Look for real extraction |
|
| 3483 | + if (($v_extract) && ($v_header['status'] != 'ok')) { |
|
| 3484 | + $v_result = $this->privConvertHeader2FileInfo($v_header, |
|
| 3485 | + $p_file_list[$v_nb_extracted++]); |
|
| 3486 | + if ($v_result != 1) { |
|
| 3487 | + $this->privCloseFd(); |
|
| 3488 | + $this->privSwapBackMagicQuotes(); |
|
| 3489 | + return $v_result; |
|
| 3490 | + } |
|
| 3491 | 3491 | |
| 3492 | - $v_extract = false; |
|
| 3493 | - } |
|
| 3492 | + $v_extract = false; |
|
| 3493 | + } |
|
| 3494 | 3494 | |
| 3495 | - // ----- Look for real extraction |
|
| 3496 | - if ($v_extract) |
|
| 3497 | - { |
|
| 3495 | + // ----- Look for real extraction |
|
| 3496 | + if ($v_extract) |
|
| 3497 | + { |
|
| 3498 | 3498 | |
| 3499 | - // ----- Go to the file position |
|
| 3500 | - @rewind($this->zip_fd); |
|
| 3501 | - if (@fseek($this->zip_fd, $v_header['offset'])) |
|
| 3502 | - { |
|
| 3503 | - // ----- Close the zip file |
|
| 3504 | - $this->privCloseFd(); |
|
| 3499 | + // ----- Go to the file position |
|
| 3500 | + @rewind($this->zip_fd); |
|
| 3501 | + if (@fseek($this->zip_fd, $v_header['offset'])) |
|
| 3502 | + { |
|
| 3503 | + // ----- Close the zip file |
|
| 3504 | + $this->privCloseFd(); |
|
| 3505 | 3505 | |
| 3506 | - $this->privSwapBackMagicQuotes(); |
|
| 3506 | + $this->privSwapBackMagicQuotes(); |
|
| 3507 | 3507 | |
| 3508 | - // ----- Error log |
|
| 3509 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 3508 | + // ----- Error log |
|
| 3509 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 3510 | 3510 | |
| 3511 | - // ----- Return |
|
| 3512 | - return PclZip::errorCode(); |
|
| 3513 | - } |
|
| 3511 | + // ----- Return |
|
| 3512 | + return PclZip::errorCode(); |
|
| 3513 | + } |
|
| 3514 | 3514 | |
| 3515 | - // ----- Look for extraction as string |
|
| 3516 | - if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) { |
|
| 3515 | + // ----- Look for extraction as string |
|
| 3516 | + if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) { |
|
| 3517 | 3517 | |
| 3518 | - $v_string = ''; |
|
| 3518 | + $v_string = ''; |
|
| 3519 | 3519 | |
| 3520 | - // ----- Extracting the file |
|
| 3521 | - $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options); |
|
| 3522 | - if ($v_result1 < 1) { |
|
| 3523 | - $this->privCloseFd(); |
|
| 3524 | - $this->privSwapBackMagicQuotes(); |
|
| 3525 | - return $v_result1; |
|
| 3526 | - } |
|
| 3520 | + // ----- Extracting the file |
|
| 3521 | + $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options); |
|
| 3522 | + if ($v_result1 < 1) { |
|
| 3523 | + $this->privCloseFd(); |
|
| 3524 | + $this->privSwapBackMagicQuotes(); |
|
| 3525 | + return $v_result1; |
|
| 3526 | + } |
|
| 3527 | 3527 | |
| 3528 | - // ----- Get the only interesting attributes |
|
| 3529 | - if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1) |
|
| 3530 | - { |
|
| 3531 | - // ----- Close the zip file |
|
| 3532 | - $this->privCloseFd(); |
|
| 3533 | - $this->privSwapBackMagicQuotes(); |
|
| 3528 | + // ----- Get the only interesting attributes |
|
| 3529 | + if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1) |
|
| 3530 | + { |
|
| 3531 | + // ----- Close the zip file |
|
| 3532 | + $this->privCloseFd(); |
|
| 3533 | + $this->privSwapBackMagicQuotes(); |
|
| 3534 | 3534 | |
| 3535 | - return $v_result; |
|
| 3536 | - } |
|
| 3535 | + return $v_result; |
|
| 3536 | + } |
|
| 3537 | 3537 | |
| 3538 | - // ----- Set the file content |
|
| 3539 | - $p_file_list[$v_nb_extracted]['content'] = $v_string; |
|
| 3538 | + // ----- Set the file content |
|
| 3539 | + $p_file_list[$v_nb_extracted]['content'] = $v_string; |
|
| 3540 | 3540 | |
| 3541 | - // ----- Next extracted file |
|
| 3542 | - $v_nb_extracted++; |
|
| 3541 | + // ----- Next extracted file |
|
| 3542 | + $v_nb_extracted++; |
|
| 3543 | 3543 | |
| 3544 | - // ----- Look for user callback abort |
|
| 3545 | - if ($v_result1 == 2) { |
|
| 3546 | - break; |
|
| 3547 | - } |
|
| 3548 | - } |
|
| 3549 | - // ----- Look for extraction in standard output |
|
| 3550 | - elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) |
|
| 3551 | - && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { |
|
| 3552 | - // ----- Extracting the file in standard output |
|
| 3553 | - $v_result1 = $this->privExtractFileInOutput($v_header, $p_options); |
|
| 3554 | - if ($v_result1 < 1) { |
|
| 3555 | - $this->privCloseFd(); |
|
| 3556 | - $this->privSwapBackMagicQuotes(); |
|
| 3557 | - return $v_result1; |
|
| 3558 | - } |
|
| 3544 | + // ----- Look for user callback abort |
|
| 3545 | + if ($v_result1 == 2) { |
|
| 3546 | + break; |
|
| 3547 | + } |
|
| 3548 | + } |
|
| 3549 | + // ----- Look for extraction in standard output |
|
| 3550 | + elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) |
|
| 3551 | + && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { |
|
| 3552 | + // ----- Extracting the file in standard output |
|
| 3553 | + $v_result1 = $this->privExtractFileInOutput($v_header, $p_options); |
|
| 3554 | + if ($v_result1 < 1) { |
|
| 3555 | + $this->privCloseFd(); |
|
| 3556 | + $this->privSwapBackMagicQuotes(); |
|
| 3557 | + return $v_result1; |
|
| 3558 | + } |
|
| 3559 | 3559 | |
| 3560 | - // ----- Get the only interesting attributes |
|
| 3561 | - if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { |
|
| 3562 | - $this->privCloseFd(); |
|
| 3563 | - $this->privSwapBackMagicQuotes(); |
|
| 3564 | - return $v_result; |
|
| 3565 | - } |
|
| 3560 | + // ----- Get the only interesting attributes |
|
| 3561 | + if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { |
|
| 3562 | + $this->privCloseFd(); |
|
| 3563 | + $this->privSwapBackMagicQuotes(); |
|
| 3564 | + return $v_result; |
|
| 3565 | + } |
|
| 3566 | 3566 | |
| 3567 | - // ----- Look for user callback abort |
|
| 3568 | - if ($v_result1 == 2) { |
|
| 3569 | - break; |
|
| 3570 | - } |
|
| 3571 | - } |
|
| 3572 | - // ----- Look for normal extraction |
|
| 3573 | - else { |
|
| 3574 | - // ----- Extracting the file |
|
| 3575 | - $v_result1 = $this->privExtractFile($v_header, |
|
| 3576 | - $p_path, $p_remove_path, |
|
| 3567 | + // ----- Look for user callback abort |
|
| 3568 | + if ($v_result1 == 2) { |
|
| 3569 | + break; |
|
| 3570 | + } |
|
| 3571 | + } |
|
| 3572 | + // ----- Look for normal extraction |
|
| 3573 | + else { |
|
| 3574 | + // ----- Extracting the file |
|
| 3575 | + $v_result1 = $this->privExtractFile($v_header, |
|
| 3576 | + $p_path, $p_remove_path, |
|
| 3577 | 3577 | $p_remove_all_path, |
| 3578 | 3578 | $p_options); |
| 3579 | - if ($v_result1 < 1) { |
|
| 3580 | - $this->privCloseFd(); |
|
| 3581 | - $this->privSwapBackMagicQuotes(); |
|
| 3582 | - return $v_result1; |
|
| 3583 | - } |
|
| 3579 | + if ($v_result1 < 1) { |
|
| 3580 | + $this->privCloseFd(); |
|
| 3581 | + $this->privSwapBackMagicQuotes(); |
|
| 3582 | + return $v_result1; |
|
| 3583 | + } |
|
| 3584 | 3584 | |
| 3585 | - // ----- Get the only interesting attributes |
|
| 3586 | - if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) |
|
| 3587 | - { |
|
| 3588 | - // ----- Close the zip file |
|
| 3589 | - $this->privCloseFd(); |
|
| 3590 | - $this->privSwapBackMagicQuotes(); |
|
| 3585 | + // ----- Get the only interesting attributes |
|
| 3586 | + if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) |
|
| 3587 | + { |
|
| 3588 | + // ----- Close the zip file |
|
| 3589 | + $this->privCloseFd(); |
|
| 3590 | + $this->privSwapBackMagicQuotes(); |
|
| 3591 | 3591 | |
| 3592 | - return $v_result; |
|
| 3593 | - } |
|
| 3592 | + return $v_result; |
|
| 3593 | + } |
|
| 3594 | 3594 | |
| 3595 | - // ----- Look for user callback abort |
|
| 3596 | - if ($v_result1 == 2) { |
|
| 3597 | - break; |
|
| 3598 | - } |
|
| 3599 | - } |
|
| 3600 | - } |
|
| 3601 | - } |
|
| 3595 | + // ----- Look for user callback abort |
|
| 3596 | + if ($v_result1 == 2) { |
|
| 3597 | + break; |
|
| 3598 | + } |
|
| 3599 | + } |
|
| 3600 | + } |
|
| 3601 | + } |
|
| 3602 | 3602 | |
| 3603 | - // ----- Close the zip file |
|
| 3604 | - $this->privCloseFd(); |
|
| 3605 | - $this->privSwapBackMagicQuotes(); |
|
| 3603 | + // ----- Close the zip file |
|
| 3604 | + $this->privCloseFd(); |
|
| 3605 | + $this->privSwapBackMagicQuotes(); |
|
| 3606 | 3606 | |
| 3607 | - // ----- Return |
|
| 3608 | - return $v_result; |
|
| 3607 | + // ----- Return |
|
| 3608 | + return $v_result; |
|
| 3609 | 3609 | } |
| 3610 | 3610 | // -------------------------------------------------------------------------------- |
| 3611 | 3611 | |
@@ -3620,346 +3620,346 @@ discard block |
||
| 3620 | 3620 | // -------------------------------------------------------------------------------- |
| 3621 | 3621 | function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
| 3622 | 3622 | { |
| 3623 | - $v_result=1; |
|
| 3623 | + $v_result=1; |
|
| 3624 | 3624 | |
| 3625 | - // ----- Read the file header |
|
| 3626 | - if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
|
| 3627 | - { |
|
| 3628 | - // ----- Return |
|
| 3629 | - return $v_result; |
|
| 3630 | - } |
|
| 3625 | + // ----- Read the file header |
|
| 3626 | + if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
|
| 3627 | + { |
|
| 3628 | + // ----- Return |
|
| 3629 | + return $v_result; |
|
| 3630 | + } |
|
| 3631 | 3631 | |
| 3632 | 3632 | |
| 3633 | - // ----- Check that the file header is coherent with $p_entry info |
|
| 3634 | - if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
|
| 3635 | - // TBC |
|
| 3636 | - } |
|
| 3633 | + // ----- Check that the file header is coherent with $p_entry info |
|
| 3634 | + if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
|
| 3635 | + // TBC |
|
| 3636 | + } |
|
| 3637 | 3637 | |
| 3638 | - // ----- Look for all path to remove |
|
| 3639 | - if ($p_remove_all_path == true) { |
|
| 3640 | - // ----- Look for folder entry that not need to be extracted |
|
| 3641 | - if (($p_entry['external']&0x00000010)==0x00000010) { |
|
| 3638 | + // ----- Look for all path to remove |
|
| 3639 | + if ($p_remove_all_path == true) { |
|
| 3640 | + // ----- Look for folder entry that not need to be extracted |
|
| 3641 | + if (($p_entry['external']&0x00000010)==0x00000010) { |
|
| 3642 | 3642 | |
| 3643 | - $p_entry['status'] = "filtered"; |
|
| 3643 | + $p_entry['status'] = "filtered"; |
|
| 3644 | 3644 | |
| 3645 | - return $v_result; |
|
| 3646 | - } |
|
| 3645 | + return $v_result; |
|
| 3646 | + } |
|
| 3647 | 3647 | |
| 3648 | - // ----- Get the basename of the path |
|
| 3649 | - $p_entry['filename'] = basename($p_entry['filename']); |
|
| 3650 | - } |
|
| 3648 | + // ----- Get the basename of the path |
|
| 3649 | + $p_entry['filename'] = basename($p_entry['filename']); |
|
| 3650 | + } |
|
| 3651 | 3651 | |
| 3652 | - // ----- Look for path to remove |
|
| 3653 | - else if ($p_remove_path != "") |
|
| 3654 | - { |
|
| 3655 | - if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) |
|
| 3656 | - { |
|
| 3652 | + // ----- Look for path to remove |
|
| 3653 | + else if ($p_remove_path != "") |
|
| 3654 | + { |
|
| 3655 | + if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) |
|
| 3656 | + { |
|
| 3657 | 3657 | |
| 3658 | - // ----- Change the file status |
|
| 3659 | - $p_entry['status'] = "filtered"; |
|
| 3658 | + // ----- Change the file status |
|
| 3659 | + $p_entry['status'] = "filtered"; |
|
| 3660 | 3660 | |
| 3661 | - // ----- Return |
|
| 3662 | - return $v_result; |
|
| 3663 | - } |
|
| 3661 | + // ----- Return |
|
| 3662 | + return $v_result; |
|
| 3663 | + } |
|
| 3664 | 3664 | |
| 3665 | - $p_remove_path_size = strlen($p_remove_path); |
|
| 3666 | - if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) |
|
| 3667 | - { |
|
| 3665 | + $p_remove_path_size = strlen($p_remove_path); |
|
| 3666 | + if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) |
|
| 3667 | + { |
|
| 3668 | 3668 | |
| 3669 | - // ----- Remove the path |
|
| 3670 | - $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size); |
|
| 3669 | + // ----- Remove the path |
|
| 3670 | + $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size); |
|
| 3671 | 3671 | |
| 3672 | - } |
|
| 3673 | - } |
|
| 3672 | + } |
|
| 3673 | + } |
|
| 3674 | 3674 | |
| 3675 | - // ----- Add the path |
|
| 3676 | - if ($p_path != '') { |
|
| 3677 | - $p_entry['filename'] = $p_path."/".$p_entry['filename']; |
|
| 3678 | - } |
|
| 3675 | + // ----- Add the path |
|
| 3676 | + if ($p_path != '') { |
|
| 3677 | + $p_entry['filename'] = $p_path."/".$p_entry['filename']; |
|
| 3678 | + } |
|
| 3679 | 3679 | |
| 3680 | - // ----- Check a base_dir_restriction |
|
| 3681 | - if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { |
|
| 3682 | - $v_inclusion |
|
| 3683 | - = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], |
|
| 3684 | - $p_entry['filename']); |
|
| 3685 | - if ($v_inclusion == 0) { |
|
| 3686 | - |
|
| 3687 | - PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, |
|
| 3688 | - "Filename '".$p_entry['filename']."' is " |
|
| 3680 | + // ----- Check a base_dir_restriction |
|
| 3681 | + if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { |
|
| 3682 | + $v_inclusion |
|
| 3683 | + = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], |
|
| 3684 | + $p_entry['filename']); |
|
| 3685 | + if ($v_inclusion == 0) { |
|
| 3686 | + |
|
| 3687 | + PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, |
|
| 3688 | + "Filename '".$p_entry['filename']."' is " |
|
| 3689 | 3689 | ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); |
| 3690 | 3690 | |
| 3691 | - return PclZip::errorCode(); |
|
| 3692 | - } |
|
| 3693 | - } |
|
| 3691 | + return PclZip::errorCode(); |
|
| 3692 | + } |
|
| 3693 | + } |
|
| 3694 | 3694 | |
| 3695 | - // ----- Look for pre-extract callback |
|
| 3696 | - if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
|
| 3695 | + // ----- Look for pre-extract callback |
|
| 3696 | + if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
|
| 3697 | 3697 | |
| 3698 | - // ----- Generate a local information |
|
| 3699 | - $v_local_header = array(); |
|
| 3700 | - $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 3698 | + // ----- Generate a local information |
|
| 3699 | + $v_local_header = array(); |
|
| 3700 | + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 3701 | 3701 | |
| 3702 | - // ----- Call the callback |
|
| 3703 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 3704 | - // header. |
|
| 3702 | + // ----- Call the callback |
|
| 3703 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 3704 | + // header. |
|
| 3705 | 3705 | // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); |
| 3706 | - $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
|
| 3707 | - if ($v_result == 0) { |
|
| 3708 | - // ----- Change the file status |
|
| 3709 | - $p_entry['status'] = "skipped"; |
|
| 3710 | - $v_result = 1; |
|
| 3711 | - } |
|
| 3706 | + $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
|
| 3707 | + if ($v_result == 0) { |
|
| 3708 | + // ----- Change the file status |
|
| 3709 | + $p_entry['status'] = "skipped"; |
|
| 3710 | + $v_result = 1; |
|
| 3711 | + } |
|
| 3712 | 3712 | |
| 3713 | - // ----- Look for abort result |
|
| 3714 | - if ($v_result == 2) { |
|
| 3715 | - // ----- This status is internal and will be changed in 'skipped' |
|
| 3716 | - $p_entry['status'] = "aborted"; |
|
| 3717 | - $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 3718 | - } |
|
| 3713 | + // ----- Look for abort result |
|
| 3714 | + if ($v_result == 2) { |
|
| 3715 | + // ----- This status is internal and will be changed in 'skipped' |
|
| 3716 | + $p_entry['status'] = "aborted"; |
|
| 3717 | + $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 3718 | + } |
|
| 3719 | 3719 | |
| 3720 | - // ----- Update the informations |
|
| 3721 | - // Only some fields can be modified |
|
| 3722 | - $p_entry['filename'] = $v_local_header['filename']; |
|
| 3723 | - } |
|
| 3720 | + // ----- Update the informations |
|
| 3721 | + // Only some fields can be modified |
|
| 3722 | + $p_entry['filename'] = $v_local_header['filename']; |
|
| 3723 | + } |
|
| 3724 | 3724 | |
| 3725 | 3725 | |
| 3726 | - // ----- Look if extraction should be done |
|
| 3727 | - if ($p_entry['status'] == 'ok') { |
|
| 3726 | + // ----- Look if extraction should be done |
|
| 3727 | + if ($p_entry['status'] == 'ok') { |
|
| 3728 | 3728 | |
| 3729 | - // ----- Look for specific actions while the file exist |
|
| 3730 | - if (file_exists($p_entry['filename'])) |
|
| 3731 | - { |
|
| 3729 | + // ----- Look for specific actions while the file exist |
|
| 3730 | + if (file_exists($p_entry['filename'])) |
|
| 3731 | + { |
|
| 3732 | 3732 | |
| 3733 | - // ----- Look if file is a directory |
|
| 3734 | - if (is_dir($p_entry['filename'])) |
|
| 3735 | - { |
|
| 3733 | + // ----- Look if file is a directory |
|
| 3734 | + if (is_dir($p_entry['filename'])) |
|
| 3735 | + { |
|
| 3736 | 3736 | |
| 3737 | - // ----- Change the file status |
|
| 3738 | - $p_entry['status'] = "already_a_directory"; |
|
| 3737 | + // ----- Change the file status |
|
| 3738 | + $p_entry['status'] = "already_a_directory"; |
|
| 3739 | 3739 | |
| 3740 | - // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3741 | - // For historical reason first PclZip implementation does not stop |
|
| 3742 | - // when this kind of error occurs. |
|
| 3743 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3744 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3745 | - |
|
| 3746 | - PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, |
|
| 3747 | - "Filename '".$p_entry['filename']."' is " |
|
| 3740 | + // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3741 | + // For historical reason first PclZip implementation does not stop |
|
| 3742 | + // when this kind of error occurs. |
|
| 3743 | + if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3744 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3745 | + |
|
| 3746 | + PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, |
|
| 3747 | + "Filename '".$p_entry['filename']."' is " |
|
| 3748 | 3748 | ."already used by an existing directory"); |
| 3749 | 3749 | |
| 3750 | - return PclZip::errorCode(); |
|
| 3751 | - } |
|
| 3752 | - } |
|
| 3753 | - // ----- Look if file is write protected |
|
| 3754 | - else if (!is_writeable($p_entry['filename'])) |
|
| 3755 | - { |
|
| 3750 | + return PclZip::errorCode(); |
|
| 3751 | + } |
|
| 3752 | + } |
|
| 3753 | + // ----- Look if file is write protected |
|
| 3754 | + else if (!is_writeable($p_entry['filename'])) |
|
| 3755 | + { |
|
| 3756 | 3756 | |
| 3757 | - // ----- Change the file status |
|
| 3758 | - $p_entry['status'] = "write_protected"; |
|
| 3757 | + // ----- Change the file status |
|
| 3758 | + $p_entry['status'] = "write_protected"; |
|
| 3759 | 3759 | |
| 3760 | - // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3761 | - // For historical reason first PclZip implementation does not stop |
|
| 3762 | - // when this kind of error occurs. |
|
| 3763 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3764 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3760 | + // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3761 | + // For historical reason first PclZip implementation does not stop |
|
| 3762 | + // when this kind of error occurs. |
|
| 3763 | + if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3764 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3765 | 3765 | |
| 3766 | - PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
|
| 3767 | - "Filename '".$p_entry['filename']."' exists " |
|
| 3766 | + PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
|
| 3767 | + "Filename '".$p_entry['filename']."' exists " |
|
| 3768 | 3768 | ."and is write protected"); |
| 3769 | 3769 | |
| 3770 | - return PclZip::errorCode(); |
|
| 3771 | - } |
|
| 3772 | - } |
|
| 3770 | + return PclZip::errorCode(); |
|
| 3771 | + } |
|
| 3772 | + } |
|
| 3773 | 3773 | |
| 3774 | - // ----- Look if the extracted file is older |
|
| 3775 | - else if (filemtime($p_entry['filename']) > $p_entry['mtime']) |
|
| 3776 | - { |
|
| 3777 | - // ----- Change the file status |
|
| 3778 | - if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) |
|
| 3779 | - && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { |
|
| 3774 | + // ----- Look if the extracted file is older |
|
| 3775 | + else if (filemtime($p_entry['filename']) > $p_entry['mtime']) |
|
| 3776 | + { |
|
| 3777 | + // ----- Change the file status |
|
| 3778 | + if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) |
|
| 3779 | + && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { |
|
| 3780 | 3780 | } |
| 3781 | - else { |
|
| 3782 | - $p_entry['status'] = "newer_exist"; |
|
| 3783 | - |
|
| 3784 | - // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3785 | - // For historical reason first PclZip implementation does not stop |
|
| 3786 | - // when this kind of error occurs. |
|
| 3787 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3788 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3789 | - |
|
| 3790 | - PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
|
| 3791 | - "Newer version of '".$p_entry['filename']."' exists " |
|
| 3792 | - ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); |
|
| 3793 | - |
|
| 3794 | - return PclZip::errorCode(); |
|
| 3795 | - } |
|
| 3796 | - } |
|
| 3797 | - } |
|
| 3798 | - else { |
|
| 3799 | - } |
|
| 3800 | - } |
|
| 3781 | + else { |
|
| 3782 | + $p_entry['status'] = "newer_exist"; |
|
| 3783 | + |
|
| 3784 | + // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3785 | + // For historical reason first PclZip implementation does not stop |
|
| 3786 | + // when this kind of error occurs. |
|
| 3787 | + if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3788 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3789 | + |
|
| 3790 | + PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
|
| 3791 | + "Newer version of '".$p_entry['filename']."' exists " |
|
| 3792 | + ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); |
|
| 3793 | + |
|
| 3794 | + return PclZip::errorCode(); |
|
| 3795 | + } |
|
| 3796 | + } |
|
| 3797 | + } |
|
| 3798 | + else { |
|
| 3799 | + } |
|
| 3800 | + } |
|
| 3801 | 3801 | |
| 3802 | - // ----- Check the directory availability and create it if necessary |
|
| 3803 | - else { |
|
| 3804 | - if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) |
|
| 3805 | - $v_dir_to_check = $p_entry['filename']; |
|
| 3806 | - else if (!strstr($p_entry['filename'], "/")) |
|
| 3807 | - $v_dir_to_check = ""; |
|
| 3808 | - else |
|
| 3809 | - $v_dir_to_check = dirname($p_entry['filename']); |
|
| 3810 | - |
|
| 3811 | - if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { |
|
| 3812 | - |
|
| 3813 | - // ----- Change the file status |
|
| 3814 | - $p_entry['status'] = "path_creation_fail"; |
|
| 3802 | + // ----- Check the directory availability and create it if necessary |
|
| 3803 | + else { |
|
| 3804 | + if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) |
|
| 3805 | + $v_dir_to_check = $p_entry['filename']; |
|
| 3806 | + else if (!strstr($p_entry['filename'], "/")) |
|
| 3807 | + $v_dir_to_check = ""; |
|
| 3808 | + else |
|
| 3809 | + $v_dir_to_check = dirname($p_entry['filename']); |
|
| 3810 | + |
|
| 3811 | + if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { |
|
| 3815 | 3812 | |
| 3816 | - // ----- Return |
|
| 3817 | - //return $v_result; |
|
| 3818 | - $v_result = 1; |
|
| 3819 | - } |
|
| 3820 | - } |
|
| 3821 | - } |
|
| 3813 | + // ----- Change the file status |
|
| 3814 | + $p_entry['status'] = "path_creation_fail"; |
|
| 3815 | + |
|
| 3816 | + // ----- Return |
|
| 3817 | + //return $v_result; |
|
| 3818 | + $v_result = 1; |
|
| 3819 | + } |
|
| 3820 | + } |
|
| 3821 | + } |
|
| 3822 | 3822 | |
| 3823 | - // ----- Look if extraction should be done |
|
| 3824 | - if ($p_entry['status'] == 'ok') { |
|
| 3823 | + // ----- Look if extraction should be done |
|
| 3824 | + if ($p_entry['status'] == 'ok') { |
|
| 3825 | 3825 | |
| 3826 | - // ----- Do the extraction (if not a folder) |
|
| 3827 | - if (!(($p_entry['external']&0x00000010)==0x00000010)) |
|
| 3828 | - { |
|
| 3829 | - // ----- Look for not compressed file |
|
| 3830 | - if ($p_entry['compression'] == 0) { |
|
| 3826 | + // ----- Do the extraction (if not a folder) |
|
| 3827 | + if (!(($p_entry['external']&0x00000010)==0x00000010)) |
|
| 3828 | + { |
|
| 3829 | + // ----- Look for not compressed file |
|
| 3830 | + if ($p_entry['compression'] == 0) { |
|
| 3831 | 3831 | |
| 3832 | - // ----- Opening destination file |
|
| 3833 | - if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) |
|
| 3834 | - { |
|
| 3832 | + // ----- Opening destination file |
|
| 3833 | + if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) |
|
| 3834 | + { |
|
| 3835 | 3835 | |
| 3836 | - // ----- Change the file status |
|
| 3837 | - $p_entry['status'] = "write_error"; |
|
| 3836 | + // ----- Change the file status |
|
| 3837 | + $p_entry['status'] = "write_error"; |
|
| 3838 | 3838 | |
| 3839 | - // ----- Return |
|
| 3840 | - return $v_result; |
|
| 3841 | - } |
|
| 3839 | + // ----- Return |
|
| 3840 | + return $v_result; |
|
| 3841 | + } |
|
| 3842 | 3842 | |
| 3843 | 3843 | |
| 3844 | - // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
|
| 3845 | - $v_size = $p_entry['compressed_size']; |
|
| 3846 | - while ($v_size != 0) |
|
| 3847 | - { |
|
| 3848 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 3849 | - $v_buffer = @fread($this->zip_fd, $v_read_size); |
|
| 3850 | - /* Try to speed up the code |
|
| 3844 | + // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
|
| 3845 | + $v_size = $p_entry['compressed_size']; |
|
| 3846 | + while ($v_size != 0) |
|
| 3847 | + { |
|
| 3848 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 3849 | + $v_buffer = @fread($this->zip_fd, $v_read_size); |
|
| 3850 | + /* Try to speed up the code |
|
| 3851 | 3851 | $v_binary_data = pack('a'.$v_read_size, $v_buffer); |
| 3852 | 3852 | @fwrite($v_dest_file, $v_binary_data, $v_read_size); |
| 3853 | 3853 | */ |
| 3854 | - @fwrite($v_dest_file, $v_buffer, $v_read_size); |
|
| 3855 | - $v_size -= $v_read_size; |
|
| 3856 | - } |
|
| 3854 | + @fwrite($v_dest_file, $v_buffer, $v_read_size); |
|
| 3855 | + $v_size -= $v_read_size; |
|
| 3856 | + } |
|
| 3857 | 3857 | |
| 3858 | - // ----- Closing the destination file |
|
| 3859 | - fclose($v_dest_file); |
|
| 3858 | + // ----- Closing the destination file |
|
| 3859 | + fclose($v_dest_file); |
|
| 3860 | 3860 | |
| 3861 | - // ----- Change the file mtime |
|
| 3862 | - touch($p_entry['filename'], $p_entry['mtime']); |
|
| 3861 | + // ----- Change the file mtime |
|
| 3862 | + touch($p_entry['filename'], $p_entry['mtime']); |
|
| 3863 | 3863 | |
| 3864 | 3864 | |
| 3865 | - } |
|
| 3866 | - else { |
|
| 3867 | - // ----- TBC |
|
| 3868 | - // Need to be finished |
|
| 3869 | - if (($p_entry['flag'] & 1) == 1) { |
|
| 3870 | - PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.'); |
|
| 3871 | - return PclZip::errorCode(); |
|
| 3872 | - } |
|
| 3865 | + } |
|
| 3866 | + else { |
|
| 3867 | + // ----- TBC |
|
| 3868 | + // Need to be finished |
|
| 3869 | + if (($p_entry['flag'] & 1) == 1) { |
|
| 3870 | + PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.'); |
|
| 3871 | + return PclZip::errorCode(); |
|
| 3872 | + } |
|
| 3873 | 3873 | |
| 3874 | 3874 | |
| 3875 | - // ----- Look for using temporary file to unzip |
|
| 3876 | - if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 3877 | - && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
|
| 3878 | - || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
|
| 3879 | - && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) { |
|
| 3880 | - $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options); |
|
| 3881 | - if ($v_result < PCLZIP_ERR_NO_ERROR) { |
|
| 3882 | - return $v_result; |
|
| 3883 | - } |
|
| 3884 | - } |
|
| 3875 | + // ----- Look for using temporary file to unzip |
|
| 3876 | + if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 3877 | + && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
|
| 3878 | + || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
|
| 3879 | + && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) { |
|
| 3880 | + $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options); |
|
| 3881 | + if ($v_result < PCLZIP_ERR_NO_ERROR) { |
|
| 3882 | + return $v_result; |
|
| 3883 | + } |
|
| 3884 | + } |
|
| 3885 | 3885 | |
| 3886 | - // ----- Look for extract in memory |
|
| 3887 | - else { |
|
| 3886 | + // ----- Look for extract in memory |
|
| 3887 | + else { |
|
| 3888 | 3888 | |
| 3889 | 3889 | |
| 3890 | - // ----- Read the compressed file in a buffer (one shot) |
|
| 3891 | - $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 3890 | + // ----- Read the compressed file in a buffer (one shot) |
|
| 3891 | + $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 3892 | 3892 | |
| 3893 | - // ----- Decompress the file |
|
| 3894 | - $v_file_content = @gzinflate($v_buffer); |
|
| 3895 | - unset($v_buffer); |
|
| 3896 | - if ($v_file_content === FALSE) { |
|
| 3893 | + // ----- Decompress the file |
|
| 3894 | + $v_file_content = @gzinflate($v_buffer); |
|
| 3895 | + unset($v_buffer); |
|
| 3896 | + if ($v_file_content === FALSE) { |
|
| 3897 | 3897 | |
| 3898 | - // ----- Change the file status |
|
| 3899 | - // TBC |
|
| 3900 | - $p_entry['status'] = "error"; |
|
| 3898 | + // ----- Change the file status |
|
| 3899 | + // TBC |
|
| 3900 | + $p_entry['status'] = "error"; |
|
| 3901 | 3901 | |
| 3902 | - return $v_result; |
|
| 3903 | - } |
|
| 3902 | + return $v_result; |
|
| 3903 | + } |
|
| 3904 | 3904 | |
| 3905 | - // ----- Opening destination file |
|
| 3906 | - if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { |
|
| 3905 | + // ----- Opening destination file |
|
| 3906 | + if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { |
|
| 3907 | 3907 | |
| 3908 | - // ----- Change the file status |
|
| 3909 | - $p_entry['status'] = "write_error"; |
|
| 3908 | + // ----- Change the file status |
|
| 3909 | + $p_entry['status'] = "write_error"; |
|
| 3910 | 3910 | |
| 3911 | - return $v_result; |
|
| 3912 | - } |
|
| 3911 | + return $v_result; |
|
| 3912 | + } |
|
| 3913 | 3913 | |
| 3914 | - // ----- Write the uncompressed data |
|
| 3915 | - @fwrite($v_dest_file, $v_file_content, $p_entry['size']); |
|
| 3916 | - unset($v_file_content); |
|
| 3914 | + // ----- Write the uncompressed data |
|
| 3915 | + @fwrite($v_dest_file, $v_file_content, $p_entry['size']); |
|
| 3916 | + unset($v_file_content); |
|
| 3917 | 3917 | |
| 3918 | - // ----- Closing the destination file |
|
| 3919 | - @fclose($v_dest_file); |
|
| 3918 | + // ----- Closing the destination file |
|
| 3919 | + @fclose($v_dest_file); |
|
| 3920 | 3920 | |
| 3921 | - } |
|
| 3921 | + } |
|
| 3922 | 3922 | |
| 3923 | - // ----- Change the file mtime |
|
| 3924 | - @touch($p_entry['filename'], $p_entry['mtime']); |
|
| 3925 | - } |
|
| 3923 | + // ----- Change the file mtime |
|
| 3924 | + @touch($p_entry['filename'], $p_entry['mtime']); |
|
| 3925 | + } |
|
| 3926 | 3926 | |
| 3927 | - // ----- Look for chmod option |
|
| 3928 | - if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { |
|
| 3927 | + // ----- Look for chmod option |
|
| 3928 | + if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { |
|
| 3929 | 3929 | |
| 3930 | - // ----- Change the mode of the file |
|
| 3931 | - @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); |
|
| 3932 | - } |
|
| 3930 | + // ----- Change the mode of the file |
|
| 3931 | + @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); |
|
| 3932 | + } |
|
| 3933 | 3933 | |
| 3934 | - } |
|
| 3935 | - } |
|
| 3934 | + } |
|
| 3935 | + } |
|
| 3936 | 3936 | |
| 3937 | 3937 | // ----- Change abort status |
| 3938 | 3938 | if ($p_entry['status'] == "aborted") { |
| 3939 | - $p_entry['status'] = "skipped"; |
|
| 3939 | + $p_entry['status'] = "skipped"; |
|
| 3940 | 3940 | } |
| 3941 | 3941 | |
| 3942 | - // ----- Look for post-extract callback |
|
| 3943 | - elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
|
| 3942 | + // ----- Look for post-extract callback |
|
| 3943 | + elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
|
| 3944 | 3944 | |
| 3945 | - // ----- Generate a local information |
|
| 3946 | - $v_local_header = array(); |
|
| 3947 | - $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 3945 | + // ----- Generate a local information |
|
| 3946 | + $v_local_header = array(); |
|
| 3947 | + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 3948 | 3948 | |
| 3949 | - // ----- Call the callback |
|
| 3950 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 3951 | - // header. |
|
| 3949 | + // ----- Call the callback |
|
| 3950 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 3951 | + // header. |
|
| 3952 | 3952 | // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); |
| 3953 | - $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
|
| 3953 | + $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
|
| 3954 | 3954 | |
| 3955 | - // ----- Look for abort result |
|
| 3956 | - if ($v_result == 2) { |
|
| 3957 | - $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 3958 | - } |
|
| 3959 | - } |
|
| 3955 | + // ----- Look for abort result |
|
| 3956 | + if ($v_result == 2) { |
|
| 3957 | + $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 3958 | + } |
|
| 3959 | + } |
|
| 3960 | 3960 | |
| 3961 | - // ----- Return |
|
| 3962 | - return $v_result; |
|
| 3961 | + // ----- Return |
|
| 3962 | + return $v_result; |
|
| 3963 | 3963 | } |
| 3964 | 3964 | // -------------------------------------------------------------------------------- |
| 3965 | 3965 | |
@@ -3971,71 +3971,71 @@ discard block |
||
| 3971 | 3971 | // -------------------------------------------------------------------------------- |
| 3972 | 3972 | function privExtractFileUsingTempFile(&$p_entry, &$p_options) |
| 3973 | 3973 | { |
| 3974 | - $v_result=1; |
|
| 3974 | + $v_result=1; |
|
| 3975 | 3975 | |
| 3976 | - // ----- Creates a temporary file |
|
| 3977 | - $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; |
|
| 3978 | - if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) { |
|
| 3979 | - fclose($v_file); |
|
| 3980 | - PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
|
| 3981 | - return PclZip::errorCode(); |
|
| 3982 | - } |
|
| 3976 | + // ----- Creates a temporary file |
|
| 3977 | + $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; |
|
| 3978 | + if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) { |
|
| 3979 | + fclose($v_file); |
|
| 3980 | + PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
|
| 3981 | + return PclZip::errorCode(); |
|
| 3982 | + } |
|
| 3983 | 3983 | |
| 3984 | 3984 | |
| 3985 | - // ----- Write gz file format header |
|
| 3986 | - $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3)); |
|
| 3987 | - @fwrite($v_dest_file, $v_binary_data, 10); |
|
| 3985 | + // ----- Write gz file format header |
|
| 3986 | + $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3)); |
|
| 3987 | + @fwrite($v_dest_file, $v_binary_data, 10); |
|
| 3988 | 3988 | |
| 3989 | - // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
|
| 3990 | - $v_size = $p_entry['compressed_size']; |
|
| 3991 | - while ($v_size != 0) |
|
| 3992 | - { |
|
| 3993 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 3994 | - $v_buffer = @fread($this->zip_fd, $v_read_size); |
|
| 3995 | - //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 3996 | - @fwrite($v_dest_file, $v_buffer, $v_read_size); |
|
| 3997 | - $v_size -= $v_read_size; |
|
| 3998 | - } |
|
| 3989 | + // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
|
| 3990 | + $v_size = $p_entry['compressed_size']; |
|
| 3991 | + while ($v_size != 0) |
|
| 3992 | + { |
|
| 3993 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 3994 | + $v_buffer = @fread($this->zip_fd, $v_read_size); |
|
| 3995 | + //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 3996 | + @fwrite($v_dest_file, $v_buffer, $v_read_size); |
|
| 3997 | + $v_size -= $v_read_size; |
|
| 3998 | + } |
|
| 3999 | 3999 | |
| 4000 | - // ----- Write gz file format footer |
|
| 4001 | - $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']); |
|
| 4002 | - @fwrite($v_dest_file, $v_binary_data, 8); |
|
| 4000 | + // ----- Write gz file format footer |
|
| 4001 | + $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']); |
|
| 4002 | + @fwrite($v_dest_file, $v_binary_data, 8); |
|
| 4003 | 4003 | |
| 4004 | - // ----- Close the temporary file |
|
| 4005 | - @fclose($v_dest_file); |
|
| 4004 | + // ----- Close the temporary file |
|
| 4005 | + @fclose($v_dest_file); |
|
| 4006 | 4006 | |
| 4007 | - // ----- Opening destination file |
|
| 4008 | - if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { |
|
| 4009 | - $p_entry['status'] = "write_error"; |
|
| 4010 | - return $v_result; |
|
| 4011 | - } |
|
| 4007 | + // ----- Opening destination file |
|
| 4008 | + if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { |
|
| 4009 | + $p_entry['status'] = "write_error"; |
|
| 4010 | + return $v_result; |
|
| 4011 | + } |
|
| 4012 | 4012 | |
| 4013 | - // ----- Open the temporary gz file |
|
| 4014 | - if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) { |
|
| 4015 | - @fclose($v_dest_file); |
|
| 4016 | - $p_entry['status'] = "read_error"; |
|
| 4017 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 4018 | - return PclZip::errorCode(); |
|
| 4019 | - } |
|
| 4013 | + // ----- Open the temporary gz file |
|
| 4014 | + if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) { |
|
| 4015 | + @fclose($v_dest_file); |
|
| 4016 | + $p_entry['status'] = "read_error"; |
|
| 4017 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 4018 | + return PclZip::errorCode(); |
|
| 4019 | + } |
|
| 4020 | 4020 | |
| 4021 | 4021 | |
| 4022 | - // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
|
| 4023 | - $v_size = $p_entry['size']; |
|
| 4024 | - while ($v_size != 0) { |
|
| 4025 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 4026 | - $v_buffer = @gzread($v_src_file, $v_read_size); |
|
| 4027 | - //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 4028 | - @fwrite($v_dest_file, $v_buffer, $v_read_size); |
|
| 4029 | - $v_size -= $v_read_size; |
|
| 4030 | - } |
|
| 4031 | - @fclose($v_dest_file); |
|
| 4032 | - @gzclose($v_src_file); |
|
| 4022 | + // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
|
| 4023 | + $v_size = $p_entry['size']; |
|
| 4024 | + while ($v_size != 0) { |
|
| 4025 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 4026 | + $v_buffer = @gzread($v_src_file, $v_read_size); |
|
| 4027 | + //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 4028 | + @fwrite($v_dest_file, $v_buffer, $v_read_size); |
|
| 4029 | + $v_size -= $v_read_size; |
|
| 4030 | + } |
|
| 4031 | + @fclose($v_dest_file); |
|
| 4032 | + @gzclose($v_src_file); |
|
| 4033 | 4033 | |
| 4034 | - // ----- Delete the temporary file |
|
| 4035 | - @unlink($v_gzip_temp_name); |
|
| 4034 | + // ----- Delete the temporary file |
|
| 4035 | + @unlink($v_gzip_temp_name); |
|
| 4036 | 4036 | |
| 4037 | - // ----- Return |
|
| 4038 | - return $v_result; |
|
| 4037 | + // ----- Return |
|
| 4038 | + return $v_result; |
|
| 4039 | 4039 | } |
| 4040 | 4040 | // -------------------------------------------------------------------------------- |
| 4041 | 4041 | |
@@ -4047,107 +4047,107 @@ discard block |
||
| 4047 | 4047 | // -------------------------------------------------------------------------------- |
| 4048 | 4048 | function privExtractFileInOutput(&$p_entry, &$p_options) |
| 4049 | 4049 | { |
| 4050 | - $v_result=1; |
|
| 4050 | + $v_result=1; |
|
| 4051 | 4051 | |
| 4052 | - // ----- Read the file header |
|
| 4053 | - if (($v_result = $this->privReadFileHeader($v_header)) != 1) { |
|
| 4054 | - return $v_result; |
|
| 4055 | - } |
|
| 4052 | + // ----- Read the file header |
|
| 4053 | + if (($v_result = $this->privReadFileHeader($v_header)) != 1) { |
|
| 4054 | + return $v_result; |
|
| 4055 | + } |
|
| 4056 | 4056 | |
| 4057 | 4057 | |
| 4058 | - // ----- Check that the file header is coherent with $p_entry info |
|
| 4059 | - if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
|
| 4060 | - // TBC |
|
| 4061 | - } |
|
| 4058 | + // ----- Check that the file header is coherent with $p_entry info |
|
| 4059 | + if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
|
| 4060 | + // TBC |
|
| 4061 | + } |
|
| 4062 | 4062 | |
| 4063 | - // ----- Look for pre-extract callback |
|
| 4064 | - if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
|
| 4063 | + // ----- Look for pre-extract callback |
|
| 4064 | + if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
|
| 4065 | 4065 | |
| 4066 | - // ----- Generate a local information |
|
| 4067 | - $v_local_header = array(); |
|
| 4068 | - $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4066 | + // ----- Generate a local information |
|
| 4067 | + $v_local_header = array(); |
|
| 4068 | + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4069 | 4069 | |
| 4070 | - // ----- Call the callback |
|
| 4071 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4072 | - // header. |
|
| 4070 | + // ----- Call the callback |
|
| 4071 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4072 | + // header. |
|
| 4073 | 4073 | // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); |
| 4074 | - $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
|
| 4075 | - if ($v_result == 0) { |
|
| 4076 | - // ----- Change the file status |
|
| 4077 | - $p_entry['status'] = "skipped"; |
|
| 4078 | - $v_result = 1; |
|
| 4079 | - } |
|
| 4074 | + $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
|
| 4075 | + if ($v_result == 0) { |
|
| 4076 | + // ----- Change the file status |
|
| 4077 | + $p_entry['status'] = "skipped"; |
|
| 4078 | + $v_result = 1; |
|
| 4079 | + } |
|
| 4080 | 4080 | |
| 4081 | - // ----- Look for abort result |
|
| 4082 | - if ($v_result == 2) { |
|
| 4083 | - // ----- This status is internal and will be changed in 'skipped' |
|
| 4084 | - $p_entry['status'] = "aborted"; |
|
| 4085 | - $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4086 | - } |
|
| 4081 | + // ----- Look for abort result |
|
| 4082 | + if ($v_result == 2) { |
|
| 4083 | + // ----- This status is internal and will be changed in 'skipped' |
|
| 4084 | + $p_entry['status'] = "aborted"; |
|
| 4085 | + $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4086 | + } |
|
| 4087 | 4087 | |
| 4088 | - // ----- Update the informations |
|
| 4089 | - // Only some fields can be modified |
|
| 4090 | - $p_entry['filename'] = $v_local_header['filename']; |
|
| 4091 | - } |
|
| 4088 | + // ----- Update the informations |
|
| 4089 | + // Only some fields can be modified |
|
| 4090 | + $p_entry['filename'] = $v_local_header['filename']; |
|
| 4091 | + } |
|
| 4092 | 4092 | |
| 4093 | - // ----- Trace |
|
| 4093 | + // ----- Trace |
|
| 4094 | 4094 | |
| 4095 | - // ----- Look if extraction should be done |
|
| 4096 | - if ($p_entry['status'] == 'ok') { |
|
| 4095 | + // ----- Look if extraction should be done |
|
| 4096 | + if ($p_entry['status'] == 'ok') { |
|
| 4097 | 4097 | |
| 4098 | - // ----- Do the extraction (if not a folder) |
|
| 4099 | - if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
|
| 4100 | - // ----- Look for not compressed file |
|
| 4101 | - if ($p_entry['compressed_size'] == $p_entry['size']) { |
|
| 4098 | + // ----- Do the extraction (if not a folder) |
|
| 4099 | + if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
|
| 4100 | + // ----- Look for not compressed file |
|
| 4101 | + if ($p_entry['compressed_size'] == $p_entry['size']) { |
|
| 4102 | 4102 | |
| 4103 | - // ----- Read the file in a buffer (one shot) |
|
| 4104 | - $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4103 | + // ----- Read the file in a buffer (one shot) |
|
| 4104 | + $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4105 | 4105 | |
| 4106 | - // ----- Send the file to the output |
|
| 4107 | - echo $v_buffer; |
|
| 4108 | - unset($v_buffer); |
|
| 4109 | - } |
|
| 4110 | - else { |
|
| 4106 | + // ----- Send the file to the output |
|
| 4107 | + echo $v_buffer; |
|
| 4108 | + unset($v_buffer); |
|
| 4109 | + } |
|
| 4110 | + else { |
|
| 4111 | 4111 | |
| 4112 | - // ----- Read the compressed file in a buffer (one shot) |
|
| 4113 | - $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4112 | + // ----- Read the compressed file in a buffer (one shot) |
|
| 4113 | + $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4114 | 4114 | |
| 4115 | - // ----- Decompress the file |
|
| 4116 | - $v_file_content = gzinflate($v_buffer); |
|
| 4117 | - unset($v_buffer); |
|
| 4118 | - |
|
| 4119 | - // ----- Send the file to the output |
|
| 4120 | - echo $v_file_content; |
|
| 4121 | - unset($v_file_content); |
|
| 4122 | - } |
|
| 4123 | - } |
|
| 4124 | - } |
|
| 4115 | + // ----- Decompress the file |
|
| 4116 | + $v_file_content = gzinflate($v_buffer); |
|
| 4117 | + unset($v_buffer); |
|
| 4118 | + |
|
| 4119 | + // ----- Send the file to the output |
|
| 4120 | + echo $v_file_content; |
|
| 4121 | + unset($v_file_content); |
|
| 4122 | + } |
|
| 4123 | + } |
|
| 4124 | + } |
|
| 4125 | 4125 | |
| 4126 | 4126 | // ----- Change abort status |
| 4127 | 4127 | if ($p_entry['status'] == "aborted") { |
| 4128 | - $p_entry['status'] = "skipped"; |
|
| 4128 | + $p_entry['status'] = "skipped"; |
|
| 4129 | 4129 | } |
| 4130 | 4130 | |
| 4131 | - // ----- Look for post-extract callback |
|
| 4132 | - elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
|
| 4131 | + // ----- Look for post-extract callback |
|
| 4132 | + elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
|
| 4133 | 4133 | |
| 4134 | - // ----- Generate a local information |
|
| 4135 | - $v_local_header = array(); |
|
| 4136 | - $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4134 | + // ----- Generate a local information |
|
| 4135 | + $v_local_header = array(); |
|
| 4136 | + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4137 | 4137 | |
| 4138 | - // ----- Call the callback |
|
| 4139 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4140 | - // header. |
|
| 4138 | + // ----- Call the callback |
|
| 4139 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4140 | + // header. |
|
| 4141 | 4141 | // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); |
| 4142 | - $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
|
| 4142 | + $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
|
| 4143 | 4143 | |
| 4144 | - // ----- Look for abort result |
|
| 4145 | - if ($v_result == 2) { |
|
| 4146 | - $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4147 | - } |
|
| 4148 | - } |
|
| 4144 | + // ----- Look for abort result |
|
| 4145 | + if ($v_result == 2) { |
|
| 4146 | + $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4147 | + } |
|
| 4148 | + } |
|
| 4149 | 4149 | |
| 4150 | - return $v_result; |
|
| 4150 | + return $v_result; |
|
| 4151 | 4151 | } |
| 4152 | 4152 | // -------------------------------------------------------------------------------- |
| 4153 | 4153 | |
@@ -4159,118 +4159,118 @@ discard block |
||
| 4159 | 4159 | // -------------------------------------------------------------------------------- |
| 4160 | 4160 | function privExtractFileAsString(&$p_entry, &$p_string, &$p_options) |
| 4161 | 4161 | { |
| 4162 | - $v_result=1; |
|
| 4163 | - |
|
| 4164 | - // ----- Read the file header |
|
| 4165 | - $v_header = array(); |
|
| 4166 | - if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
|
| 4167 | - { |
|
| 4168 | - // ----- Return |
|
| 4169 | - return $v_result; |
|
| 4170 | - } |
|
| 4162 | + $v_result=1; |
|
| 4163 | + |
|
| 4164 | + // ----- Read the file header |
|
| 4165 | + $v_header = array(); |
|
| 4166 | + if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
|
| 4167 | + { |
|
| 4168 | + // ----- Return |
|
| 4169 | + return $v_result; |
|
| 4170 | + } |
|
| 4171 | 4171 | |
| 4172 | 4172 | |
| 4173 | - // ----- Check that the file header is coherent with $p_entry info |
|
| 4174 | - if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
|
| 4175 | - // TBC |
|
| 4176 | - } |
|
| 4173 | + // ----- Check that the file header is coherent with $p_entry info |
|
| 4174 | + if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
|
| 4175 | + // TBC |
|
| 4176 | + } |
|
| 4177 | 4177 | |
| 4178 | - // ----- Look for pre-extract callback |
|
| 4179 | - if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
|
| 4178 | + // ----- Look for pre-extract callback |
|
| 4179 | + if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
|
| 4180 | 4180 | |
| 4181 | - // ----- Generate a local information |
|
| 4182 | - $v_local_header = array(); |
|
| 4183 | - $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4181 | + // ----- Generate a local information |
|
| 4182 | + $v_local_header = array(); |
|
| 4183 | + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4184 | 4184 | |
| 4185 | - // ----- Call the callback |
|
| 4186 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4187 | - // header. |
|
| 4185 | + // ----- Call the callback |
|
| 4186 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4187 | + // header. |
|
| 4188 | 4188 | // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); |
| 4189 | - $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
|
| 4190 | - if ($v_result == 0) { |
|
| 4191 | - // ----- Change the file status |
|
| 4192 | - $p_entry['status'] = "skipped"; |
|
| 4193 | - $v_result = 1; |
|
| 4194 | - } |
|
| 4189 | + $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
|
| 4190 | + if ($v_result == 0) { |
|
| 4191 | + // ----- Change the file status |
|
| 4192 | + $p_entry['status'] = "skipped"; |
|
| 4193 | + $v_result = 1; |
|
| 4194 | + } |
|
| 4195 | 4195 | |
| 4196 | - // ----- Look for abort result |
|
| 4197 | - if ($v_result == 2) { |
|
| 4198 | - // ----- This status is internal and will be changed in 'skipped' |
|
| 4199 | - $p_entry['status'] = "aborted"; |
|
| 4200 | - $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4201 | - } |
|
| 4196 | + // ----- Look for abort result |
|
| 4197 | + if ($v_result == 2) { |
|
| 4198 | + // ----- This status is internal and will be changed in 'skipped' |
|
| 4199 | + $p_entry['status'] = "aborted"; |
|
| 4200 | + $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4201 | + } |
|
| 4202 | 4202 | |
| 4203 | - // ----- Update the informations |
|
| 4204 | - // Only some fields can be modified |
|
| 4205 | - $p_entry['filename'] = $v_local_header['filename']; |
|
| 4206 | - } |
|
| 4203 | + // ----- Update the informations |
|
| 4204 | + // Only some fields can be modified |
|
| 4205 | + $p_entry['filename'] = $v_local_header['filename']; |
|
| 4206 | + } |
|
| 4207 | 4207 | |
| 4208 | 4208 | |
| 4209 | - // ----- Look if extraction should be done |
|
| 4210 | - if ($p_entry['status'] == 'ok') { |
|
| 4209 | + // ----- Look if extraction should be done |
|
| 4210 | + if ($p_entry['status'] == 'ok') { |
|
| 4211 | 4211 | |
| 4212 | - // ----- Do the extraction (if not a folder) |
|
| 4213 | - if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
|
| 4214 | - // ----- Look for not compressed file |
|
| 4212 | + // ----- Do the extraction (if not a folder) |
|
| 4213 | + if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
|
| 4214 | + // ----- Look for not compressed file |
|
| 4215 | 4215 | // if ($p_entry['compressed_size'] == $p_entry['size']) |
| 4216 | - if ($p_entry['compression'] == 0) { |
|
| 4216 | + if ($p_entry['compression'] == 0) { |
|
| 4217 | 4217 | |
| 4218 | - // ----- Reading the file |
|
| 4219 | - $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4220 | - } |
|
| 4221 | - else { |
|
| 4218 | + // ----- Reading the file |
|
| 4219 | + $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4220 | + } |
|
| 4221 | + else { |
|
| 4222 | 4222 | |
| 4223 | - // ----- Reading the file |
|
| 4224 | - $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4223 | + // ----- Reading the file |
|
| 4224 | + $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4225 | 4225 | |
| 4226 | - // ----- Decompress the file |
|
| 4227 | - if (($p_string = @gzinflate($v_data)) === FALSE) { |
|
| 4228 | - // TBC |
|
| 4229 | - } |
|
| 4230 | - } |
|
| 4226 | + // ----- Decompress the file |
|
| 4227 | + if (($p_string = @gzinflate($v_data)) === FALSE) { |
|
| 4228 | + // TBC |
|
| 4229 | + } |
|
| 4230 | + } |
|
| 4231 | 4231 | |
| 4232 | - // ----- Trace |
|
| 4233 | - } |
|
| 4234 | - else { |
|
| 4235 | - // TBC : error : can not extract a folder in a string |
|
| 4236 | - } |
|
| 4232 | + // ----- Trace |
|
| 4233 | + } |
|
| 4234 | + else { |
|
| 4235 | + // TBC : error : can not extract a folder in a string |
|
| 4236 | + } |
|
| 4237 | 4237 | |
| 4238 | - } |
|
| 4238 | + } |
|
| 4239 | 4239 | |
| 4240 | 4240 | // ----- Change abort status |
| 4241 | 4241 | if ($p_entry['status'] == "aborted") { |
| 4242 | - $p_entry['status'] = "skipped"; |
|
| 4242 | + $p_entry['status'] = "skipped"; |
|
| 4243 | 4243 | } |
| 4244 | 4244 | |
| 4245 | - // ----- Look for post-extract callback |
|
| 4246 | - elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
|
| 4245 | + // ----- Look for post-extract callback |
|
| 4246 | + elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
|
| 4247 | 4247 | |
| 4248 | - // ----- Generate a local information |
|
| 4249 | - $v_local_header = array(); |
|
| 4250 | - $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4248 | + // ----- Generate a local information |
|
| 4249 | + $v_local_header = array(); |
|
| 4250 | + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4251 | 4251 | |
| 4252 | - // ----- Swap the content to header |
|
| 4253 | - $v_local_header['content'] = $p_string; |
|
| 4254 | - $p_string = ''; |
|
| 4252 | + // ----- Swap the content to header |
|
| 4253 | + $v_local_header['content'] = $p_string; |
|
| 4254 | + $p_string = ''; |
|
| 4255 | 4255 | |
| 4256 | - // ----- Call the callback |
|
| 4257 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4258 | - // header. |
|
| 4256 | + // ----- Call the callback |
|
| 4257 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4258 | + // header. |
|
| 4259 | 4259 | // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); |
| 4260 | - $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
|
| 4260 | + $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
|
| 4261 | 4261 | |
| 4262 | - // ----- Swap back the content to header |
|
| 4263 | - $p_string = $v_local_header['content']; |
|
| 4264 | - unset($v_local_header['content']); |
|
| 4262 | + // ----- Swap back the content to header |
|
| 4263 | + $p_string = $v_local_header['content']; |
|
| 4264 | + unset($v_local_header['content']); |
|
| 4265 | 4265 | |
| 4266 | - // ----- Look for abort result |
|
| 4267 | - if ($v_result == 2) { |
|
| 4268 | - $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4269 | - } |
|
| 4270 | - } |
|
| 4266 | + // ----- Look for abort result |
|
| 4267 | + if ($v_result == 2) { |
|
| 4268 | + $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4269 | + } |
|
| 4270 | + } |
|
| 4271 | 4271 | |
| 4272 | - // ----- Return |
|
| 4273 | - return $v_result; |
|
| 4272 | + // ----- Return |
|
| 4273 | + return $v_result; |
|
| 4274 | 4274 | } |
| 4275 | 4275 | // -------------------------------------------------------------------------------- |
| 4276 | 4276 | |
@@ -4282,98 +4282,98 @@ discard block |
||
| 4282 | 4282 | // -------------------------------------------------------------------------------- |
| 4283 | 4283 | function privReadFileHeader(&$p_header) |
| 4284 | 4284 | { |
| 4285 | - $v_result=1; |
|
| 4285 | + $v_result=1; |
|
| 4286 | 4286 | |
| 4287 | - // ----- Read the 4 bytes signature |
|
| 4288 | - $v_binary_data = @fread($this->zip_fd, 4); |
|
| 4289 | - $v_data = unpack('Vid', $v_binary_data); |
|
| 4287 | + // ----- Read the 4 bytes signature |
|
| 4288 | + $v_binary_data = @fread($this->zip_fd, 4); |
|
| 4289 | + $v_data = unpack('Vid', $v_binary_data); |
|
| 4290 | 4290 | |
| 4291 | - // ----- Check signature |
|
| 4292 | - if ($v_data['id'] != 0x04034b50) |
|
| 4293 | - { |
|
| 4291 | + // ----- Check signature |
|
| 4292 | + if ($v_data['id'] != 0x04034b50) |
|
| 4293 | + { |
|
| 4294 | 4294 | |
| 4295 | - // ----- Error log |
|
| 4296 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); |
|
| 4295 | + // ----- Error log |
|
| 4296 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); |
|
| 4297 | 4297 | |
| 4298 | - // ----- Return |
|
| 4299 | - return PclZip::errorCode(); |
|
| 4300 | - } |
|
| 4298 | + // ----- Return |
|
| 4299 | + return PclZip::errorCode(); |
|
| 4300 | + } |
|
| 4301 | 4301 | |
| 4302 | - // ----- Read the first 42 bytes of the header |
|
| 4303 | - $v_binary_data = fread($this->zip_fd, 26); |
|
| 4302 | + // ----- Read the first 42 bytes of the header |
|
| 4303 | + $v_binary_data = fread($this->zip_fd, 26); |
|
| 4304 | 4304 | |
| 4305 | - // ----- Look for invalid block size |
|
| 4306 | - if (strlen($v_binary_data) != 26) |
|
| 4307 | - { |
|
| 4308 | - $p_header['filename'] = ""; |
|
| 4309 | - $p_header['status'] = "invalid_header"; |
|
| 4305 | + // ----- Look for invalid block size |
|
| 4306 | + if (strlen($v_binary_data) != 26) |
|
| 4307 | + { |
|
| 4308 | + $p_header['filename'] = ""; |
|
| 4309 | + $p_header['status'] = "invalid_header"; |
|
| 4310 | 4310 | |
| 4311 | - // ----- Error log |
|
| 4312 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
|
| 4311 | + // ----- Error log |
|
| 4312 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
|
| 4313 | 4313 | |
| 4314 | - // ----- Return |
|
| 4315 | - return PclZip::errorCode(); |
|
| 4316 | - } |
|
| 4314 | + // ----- Return |
|
| 4315 | + return PclZip::errorCode(); |
|
| 4316 | + } |
|
| 4317 | 4317 | |
| 4318 | - // ----- Extract the values |
|
| 4319 | - $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data); |
|
| 4318 | + // ----- Extract the values |
|
| 4319 | + $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data); |
|
| 4320 | 4320 | |
| 4321 | - // ----- Get filename |
|
| 4322 | - $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']); |
|
| 4321 | + // ----- Get filename |
|
| 4322 | + $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']); |
|
| 4323 | 4323 | |
| 4324 | - // ----- Get extra_fields |
|
| 4325 | - if ($v_data['extra_len'] != 0) { |
|
| 4326 | - $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); |
|
| 4327 | - } |
|
| 4328 | - else { |
|
| 4329 | - $p_header['extra'] = ''; |
|
| 4330 | - } |
|
| 4324 | + // ----- Get extra_fields |
|
| 4325 | + if ($v_data['extra_len'] != 0) { |
|
| 4326 | + $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); |
|
| 4327 | + } |
|
| 4328 | + else { |
|
| 4329 | + $p_header['extra'] = ''; |
|
| 4330 | + } |
|
| 4331 | 4331 | |
| 4332 | - // ----- Extract properties |
|
| 4333 | - $p_header['version_extracted'] = $v_data['version']; |
|
| 4334 | - $p_header['compression'] = $v_data['compression']; |
|
| 4335 | - $p_header['size'] = $v_data['size']; |
|
| 4336 | - $p_header['compressed_size'] = $v_data['compressed_size']; |
|
| 4337 | - $p_header['crc'] = $v_data['crc']; |
|
| 4338 | - $p_header['flag'] = $v_data['flag']; |
|
| 4339 | - $p_header['filename_len'] = $v_data['filename_len']; |
|
| 4340 | - |
|
| 4341 | - // ----- Recuperate date in UNIX format |
|
| 4342 | - $p_header['mdate'] = $v_data['mdate']; |
|
| 4343 | - $p_header['mtime'] = $v_data['mtime']; |
|
| 4344 | - if ($p_header['mdate'] && $p_header['mtime']) |
|
| 4345 | - { |
|
| 4346 | - // ----- Extract time |
|
| 4347 | - $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
|
| 4348 | - $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
|
| 4349 | - $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
|
| 4350 | - |
|
| 4351 | - // ----- Extract date |
|
| 4352 | - $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
|
| 4353 | - $v_month = ($p_header['mdate'] & 0x01E0) >> 5; |
|
| 4354 | - $v_day = $p_header['mdate'] & 0x001F; |
|
| 4355 | - |
|
| 4356 | - // ----- Get UNIX date format |
|
| 4357 | - $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
|
| 4332 | + // ----- Extract properties |
|
| 4333 | + $p_header['version_extracted'] = $v_data['version']; |
|
| 4334 | + $p_header['compression'] = $v_data['compression']; |
|
| 4335 | + $p_header['size'] = $v_data['size']; |
|
| 4336 | + $p_header['compressed_size'] = $v_data['compressed_size']; |
|
| 4337 | + $p_header['crc'] = $v_data['crc']; |
|
| 4338 | + $p_header['flag'] = $v_data['flag']; |
|
| 4339 | + $p_header['filename_len'] = $v_data['filename_len']; |
|
| 4340 | + |
|
| 4341 | + // ----- Recuperate date in UNIX format |
|
| 4342 | + $p_header['mdate'] = $v_data['mdate']; |
|
| 4343 | + $p_header['mtime'] = $v_data['mtime']; |
|
| 4344 | + if ($p_header['mdate'] && $p_header['mtime']) |
|
| 4345 | + { |
|
| 4346 | + // ----- Extract time |
|
| 4347 | + $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
|
| 4348 | + $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
|
| 4349 | + $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
|
| 4350 | + |
|
| 4351 | + // ----- Extract date |
|
| 4352 | + $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
|
| 4353 | + $v_month = ($p_header['mdate'] & 0x01E0) >> 5; |
|
| 4354 | + $v_day = $p_header['mdate'] & 0x001F; |
|
| 4355 | + |
|
| 4356 | + // ----- Get UNIX date format |
|
| 4357 | + $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
|
| 4358 | 4358 | |
| 4359 | - } |
|
| 4360 | - else |
|
| 4361 | - { |
|
| 4362 | - $p_header['mtime'] = time(); |
|
| 4363 | - } |
|
| 4359 | + } |
|
| 4360 | + else |
|
| 4361 | + { |
|
| 4362 | + $p_header['mtime'] = time(); |
|
| 4363 | + } |
|
| 4364 | 4364 | |
| 4365 | - // TBC |
|
| 4366 | - //for(reset($v_data); $key = key($v_data); next($v_data)) { |
|
| 4367 | - //} |
|
| 4365 | + // TBC |
|
| 4366 | + //for(reset($v_data); $key = key($v_data); next($v_data)) { |
|
| 4367 | + //} |
|
| 4368 | 4368 | |
| 4369 | - // ----- Set the stored filename |
|
| 4370 | - $p_header['stored_filename'] = $p_header['filename']; |
|
| 4369 | + // ----- Set the stored filename |
|
| 4370 | + $p_header['stored_filename'] = $p_header['filename']; |
|
| 4371 | 4371 | |
| 4372 | - // ----- Set the status field |
|
| 4373 | - $p_header['status'] = "ok"; |
|
| 4372 | + // ----- Set the status field |
|
| 4373 | + $p_header['status'] = "ok"; |
|
| 4374 | 4374 | |
| 4375 | - // ----- Return |
|
| 4376 | - return $v_result; |
|
| 4375 | + // ----- Return |
|
| 4376 | + return $v_result; |
|
| 4377 | 4377 | } |
| 4378 | 4378 | // -------------------------------------------------------------------------------- |
| 4379 | 4379 | |
@@ -4385,101 +4385,101 @@ discard block |
||
| 4385 | 4385 | // -------------------------------------------------------------------------------- |
| 4386 | 4386 | function privReadCentralFileHeader(&$p_header) |
| 4387 | 4387 | { |
| 4388 | - $v_result=1; |
|
| 4388 | + $v_result=1; |
|
| 4389 | 4389 | |
| 4390 | - // ----- Read the 4 bytes signature |
|
| 4391 | - $v_binary_data = @fread($this->zip_fd, 4); |
|
| 4392 | - $v_data = unpack('Vid', $v_binary_data); |
|
| 4390 | + // ----- Read the 4 bytes signature |
|
| 4391 | + $v_binary_data = @fread($this->zip_fd, 4); |
|
| 4392 | + $v_data = unpack('Vid', $v_binary_data); |
|
| 4393 | 4393 | |
| 4394 | - // ----- Check signature |
|
| 4395 | - if ($v_data['id'] != 0x02014b50) |
|
| 4396 | - { |
|
| 4394 | + // ----- Check signature |
|
| 4395 | + if ($v_data['id'] != 0x02014b50) |
|
| 4396 | + { |
|
| 4397 | 4397 | |
| 4398 | - // ----- Error log |
|
| 4399 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); |
|
| 4398 | + // ----- Error log |
|
| 4399 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); |
|
| 4400 | 4400 | |
| 4401 | - // ----- Return |
|
| 4402 | - return PclZip::errorCode(); |
|
| 4403 | - } |
|
| 4401 | + // ----- Return |
|
| 4402 | + return PclZip::errorCode(); |
|
| 4403 | + } |
|
| 4404 | 4404 | |
| 4405 | - // ----- Read the first 42 bytes of the header |
|
| 4406 | - $v_binary_data = fread($this->zip_fd, 42); |
|
| 4405 | + // ----- Read the first 42 bytes of the header |
|
| 4406 | + $v_binary_data = fread($this->zip_fd, 42); |
|
| 4407 | 4407 | |
| 4408 | - // ----- Look for invalid block size |
|
| 4409 | - if (strlen($v_binary_data) != 42) |
|
| 4410 | - { |
|
| 4411 | - $p_header['filename'] = ""; |
|
| 4412 | - $p_header['status'] = "invalid_header"; |
|
| 4408 | + // ----- Look for invalid block size |
|
| 4409 | + if (strlen($v_binary_data) != 42) |
|
| 4410 | + { |
|
| 4411 | + $p_header['filename'] = ""; |
|
| 4412 | + $p_header['status'] = "invalid_header"; |
|
| 4413 | 4413 | |
| 4414 | - // ----- Error log |
|
| 4415 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
|
| 4414 | + // ----- Error log |
|
| 4415 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
|
| 4416 | 4416 | |
| 4417 | - // ----- Return |
|
| 4418 | - return PclZip::errorCode(); |
|
| 4419 | - } |
|
| 4417 | + // ----- Return |
|
| 4418 | + return PclZip::errorCode(); |
|
| 4419 | + } |
|
| 4420 | 4420 | |
| 4421 | - // ----- Extract the values |
|
| 4422 | - $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data); |
|
| 4423 | - |
|
| 4424 | - // ----- Get filename |
|
| 4425 | - if ($p_header['filename_len'] != 0) |
|
| 4426 | - $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); |
|
| 4427 | - else |
|
| 4428 | - $p_header['filename'] = ''; |
|
| 4429 | - |
|
| 4430 | - // ----- Get extra |
|
| 4431 | - if ($p_header['extra_len'] != 0) |
|
| 4432 | - $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); |
|
| 4433 | - else |
|
| 4434 | - $p_header['extra'] = ''; |
|
| 4435 | - |
|
| 4436 | - // ----- Get comment |
|
| 4437 | - if ($p_header['comment_len'] != 0) |
|
| 4438 | - $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); |
|
| 4439 | - else |
|
| 4440 | - $p_header['comment'] = ''; |
|
| 4441 | - |
|
| 4442 | - // ----- Extract properties |
|
| 4443 | - |
|
| 4444 | - // ----- Recuperate date in UNIX format |
|
| 4445 | - //if ($p_header['mdate'] && $p_header['mtime']) |
|
| 4446 | - // TBC : bug : this was ignoring time with 0/0/0 |
|
| 4447 | - if (1) |
|
| 4448 | - { |
|
| 4449 | - // ----- Extract time |
|
| 4450 | - $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
|
| 4451 | - $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
|
| 4452 | - $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
|
| 4453 | - |
|
| 4454 | - // ----- Extract date |
|
| 4455 | - $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
|
| 4456 | - $v_month = ($p_header['mdate'] & 0x01E0) >> 5; |
|
| 4457 | - $v_day = $p_header['mdate'] & 0x001F; |
|
| 4458 | - |
|
| 4459 | - // ----- Get UNIX date format |
|
| 4460 | - $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
|
| 4421 | + // ----- Extract the values |
|
| 4422 | + $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data); |
|
| 4423 | + |
|
| 4424 | + // ----- Get filename |
|
| 4425 | + if ($p_header['filename_len'] != 0) |
|
| 4426 | + $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); |
|
| 4427 | + else |
|
| 4428 | + $p_header['filename'] = ''; |
|
| 4429 | + |
|
| 4430 | + // ----- Get extra |
|
| 4431 | + if ($p_header['extra_len'] != 0) |
|
| 4432 | + $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); |
|
| 4433 | + else |
|
| 4434 | + $p_header['extra'] = ''; |
|
| 4435 | + |
|
| 4436 | + // ----- Get comment |
|
| 4437 | + if ($p_header['comment_len'] != 0) |
|
| 4438 | + $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); |
|
| 4439 | + else |
|
| 4440 | + $p_header['comment'] = ''; |
|
| 4441 | + |
|
| 4442 | + // ----- Extract properties |
|
| 4443 | + |
|
| 4444 | + // ----- Recuperate date in UNIX format |
|
| 4445 | + //if ($p_header['mdate'] && $p_header['mtime']) |
|
| 4446 | + // TBC : bug : this was ignoring time with 0/0/0 |
|
| 4447 | + if (1) |
|
| 4448 | + { |
|
| 4449 | + // ----- Extract time |
|
| 4450 | + $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
|
| 4451 | + $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
|
| 4452 | + $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
|
| 4453 | + |
|
| 4454 | + // ----- Extract date |
|
| 4455 | + $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
|
| 4456 | + $v_month = ($p_header['mdate'] & 0x01E0) >> 5; |
|
| 4457 | + $v_day = $p_header['mdate'] & 0x001F; |
|
| 4458 | + |
|
| 4459 | + // ----- Get UNIX date format |
|
| 4460 | + $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
|
| 4461 | 4461 | |
| 4462 | - } |
|
| 4463 | - else |
|
| 4464 | - { |
|
| 4465 | - $p_header['mtime'] = time(); |
|
| 4466 | - } |
|
| 4462 | + } |
|
| 4463 | + else |
|
| 4464 | + { |
|
| 4465 | + $p_header['mtime'] = time(); |
|
| 4466 | + } |
|
| 4467 | 4467 | |
| 4468 | - // ----- Set the stored filename |
|
| 4469 | - $p_header['stored_filename'] = $p_header['filename']; |
|
| 4468 | + // ----- Set the stored filename |
|
| 4469 | + $p_header['stored_filename'] = $p_header['filename']; |
|
| 4470 | 4470 | |
| 4471 | - // ----- Set default status to ok |
|
| 4472 | - $p_header['status'] = 'ok'; |
|
| 4471 | + // ----- Set default status to ok |
|
| 4472 | + $p_header['status'] = 'ok'; |
|
| 4473 | 4473 | |
| 4474 | - // ----- Look if it is a directory |
|
| 4475 | - if (substr($p_header['filename'], -1) == '/') { |
|
| 4476 | - //$p_header['external'] = 0x41FF0010; |
|
| 4477 | - $p_header['external'] = 0x00000010; |
|
| 4478 | - } |
|
| 4474 | + // ----- Look if it is a directory |
|
| 4475 | + if (substr($p_header['filename'], -1) == '/') { |
|
| 4476 | + //$p_header['external'] = 0x41FF0010; |
|
| 4477 | + $p_header['external'] = 0x00000010; |
|
| 4478 | + } |
|
| 4479 | 4479 | |
| 4480 | 4480 | |
| 4481 | - // ----- Return |
|
| 4482 | - return $v_result; |
|
| 4481 | + // ----- Return |
|
| 4482 | + return $v_result; |
|
| 4483 | 4483 | } |
| 4484 | 4484 | // -------------------------------------------------------------------------------- |
| 4485 | 4485 | |
@@ -4493,7 +4493,7 @@ discard block |
||
| 4493 | 4493 | // -------------------------------------------------------------------------------- |
| 4494 | 4494 | function privCheckFileHeaders(&$p_local_header, &$p_central_header) |
| 4495 | 4495 | { |
| 4496 | - $v_result=1; |
|
| 4496 | + $v_result=1; |
|
| 4497 | 4497 | |
| 4498 | 4498 | // ----- Check the static values |
| 4499 | 4499 | // TBC |
@@ -4512,13 +4512,13 @@ discard block |
||
| 4512 | 4512 | |
| 4513 | 4513 | // ----- Look for flag bit 3 |
| 4514 | 4514 | if (($p_local_header['flag'] & 8) == 8) { |
| 4515 | - $p_local_header['size'] = $p_central_header['size']; |
|
| 4516 | - $p_local_header['compressed_size'] = $p_central_header['compressed_size']; |
|
| 4517 | - $p_local_header['crc'] = $p_central_header['crc']; |
|
| 4515 | + $p_local_header['size'] = $p_central_header['size']; |
|
| 4516 | + $p_local_header['compressed_size'] = $p_central_header['compressed_size']; |
|
| 4517 | + $p_local_header['crc'] = $p_central_header['crc']; |
|
| 4518 | 4518 | } |
| 4519 | 4519 | |
| 4520 | - // ----- Return |
|
| 4521 | - return $v_result; |
|
| 4520 | + // ----- Return |
|
| 4521 | + return $v_result; |
|
| 4522 | 4522 | } |
| 4523 | 4523 | // -------------------------------------------------------------------------------- |
| 4524 | 4524 | |
@@ -4530,152 +4530,152 @@ discard block |
||
| 4530 | 4530 | // -------------------------------------------------------------------------------- |
| 4531 | 4531 | function privReadEndCentralDir(&$p_central_dir) |
| 4532 | 4532 | { |
| 4533 | - $v_result=1; |
|
| 4534 | - |
|
| 4535 | - // ----- Go to the end of the zip file |
|
| 4536 | - $v_size = filesize($this->zipname); |
|
| 4537 | - @fseek($this->zip_fd, $v_size); |
|
| 4538 | - if (@ftell($this->zip_fd) != $v_size) |
|
| 4539 | - { |
|
| 4540 | - // ----- Error log |
|
| 4541 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); |
|
| 4542 | - |
|
| 4543 | - // ----- Return |
|
| 4544 | - return PclZip::errorCode(); |
|
| 4545 | - } |
|
| 4533 | + $v_result=1; |
|
| 4534 | + |
|
| 4535 | + // ----- Go to the end of the zip file |
|
| 4536 | + $v_size = filesize($this->zipname); |
|
| 4537 | + @fseek($this->zip_fd, $v_size); |
|
| 4538 | + if (@ftell($this->zip_fd) != $v_size) |
|
| 4539 | + { |
|
| 4540 | + // ----- Error log |
|
| 4541 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); |
|
| 4542 | + |
|
| 4543 | + // ----- Return |
|
| 4544 | + return PclZip::errorCode(); |
|
| 4545 | + } |
|
| 4546 | 4546 | |
| 4547 | - // ----- First try : look if this is an archive with no commentaries (most of the time) |
|
| 4548 | - // in this case the end of central dir is at 22 bytes of the file end |
|
| 4549 | - $v_found = 0; |
|
| 4550 | - if ($v_size > 26) { |
|
| 4551 | - @fseek($this->zip_fd, $v_size-22); |
|
| 4552 | - if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) |
|
| 4553 | - { |
|
| 4554 | - // ----- Error log |
|
| 4555 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
|
| 4556 | - |
|
| 4557 | - // ----- Return |
|
| 4558 | - return PclZip::errorCode(); |
|
| 4559 | - } |
|
| 4547 | + // ----- First try : look if this is an archive with no commentaries (most of the time) |
|
| 4548 | + // in this case the end of central dir is at 22 bytes of the file end |
|
| 4549 | + $v_found = 0; |
|
| 4550 | + if ($v_size > 26) { |
|
| 4551 | + @fseek($this->zip_fd, $v_size-22); |
|
| 4552 | + if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) |
|
| 4553 | + { |
|
| 4554 | + // ----- Error log |
|
| 4555 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
|
| 4556 | + |
|
| 4557 | + // ----- Return |
|
| 4558 | + return PclZip::errorCode(); |
|
| 4559 | + } |
|
| 4560 | 4560 | |
| 4561 | - // ----- Read for bytes |
|
| 4562 | - $v_binary_data = @fread($this->zip_fd, 4); |
|
| 4563 | - $v_data = @unpack('Vid', $v_binary_data); |
|
| 4561 | + // ----- Read for bytes |
|
| 4562 | + $v_binary_data = @fread($this->zip_fd, 4); |
|
| 4563 | + $v_data = @unpack('Vid', $v_binary_data); |
|
| 4564 | 4564 | |
| 4565 | - // ----- Check signature |
|
| 4566 | - if ($v_data['id'] == 0x06054b50) { |
|
| 4567 | - $v_found = 1; |
|
| 4568 | - } |
|
| 4565 | + // ----- Check signature |
|
| 4566 | + if ($v_data['id'] == 0x06054b50) { |
|
| 4567 | + $v_found = 1; |
|
| 4568 | + } |
|
| 4569 | 4569 | |
| 4570 | - $v_pos = ftell($this->zip_fd); |
|
| 4571 | - } |
|
| 4570 | + $v_pos = ftell($this->zip_fd); |
|
| 4571 | + } |
|
| 4572 | 4572 | |
| 4573 | - // ----- Go back to the maximum possible size of the Central Dir End Record |
|
| 4574 | - if (!$v_found) { |
|
| 4575 | - $v_maximum_size = 65557; // 0xFFFF + 22; |
|
| 4576 | - if ($v_maximum_size > $v_size) |
|
| 4577 | - $v_maximum_size = $v_size; |
|
| 4578 | - @fseek($this->zip_fd, $v_size-$v_maximum_size); |
|
| 4579 | - if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) |
|
| 4580 | - { |
|
| 4581 | - // ----- Error log |
|
| 4582 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
|
| 4583 | - |
|
| 4584 | - // ----- Return |
|
| 4585 | - return PclZip::errorCode(); |
|
| 4586 | - } |
|
| 4573 | + // ----- Go back to the maximum possible size of the Central Dir End Record |
|
| 4574 | + if (!$v_found) { |
|
| 4575 | + $v_maximum_size = 65557; // 0xFFFF + 22; |
|
| 4576 | + if ($v_maximum_size > $v_size) |
|
| 4577 | + $v_maximum_size = $v_size; |
|
| 4578 | + @fseek($this->zip_fd, $v_size-$v_maximum_size); |
|
| 4579 | + if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) |
|
| 4580 | + { |
|
| 4581 | + // ----- Error log |
|
| 4582 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
|
| 4583 | + |
|
| 4584 | + // ----- Return |
|
| 4585 | + return PclZip::errorCode(); |
|
| 4586 | + } |
|
| 4587 | 4587 | |
| 4588 | - // ----- Read byte per byte in order to find the signature |
|
| 4589 | - $v_pos = ftell($this->zip_fd); |
|
| 4590 | - $v_bytes = 0x00000000; |
|
| 4591 | - while ($v_pos < $v_size) |
|
| 4592 | - { |
|
| 4593 | - // ----- Read a byte |
|
| 4594 | - $v_byte = @fread($this->zip_fd, 1); |
|
| 4595 | - |
|
| 4596 | - // ----- Add the byte |
|
| 4597 | - //$v_bytes = ($v_bytes << 8) | Ord($v_byte); |
|
| 4598 | - // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number |
|
| 4599 | - // Otherwise on systems where we have 64bit integers the check below for the magic number will fail. |
|
| 4600 | - $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); |
|
| 4601 | - |
|
| 4602 | - // ----- Compare the bytes |
|
| 4603 | - if ($v_bytes == 0x504b0506) |
|
| 4604 | - { |
|
| 4605 | - $v_pos++; |
|
| 4606 | - break; |
|
| 4607 | - } |
|
| 4608 | - |
|
| 4609 | - $v_pos++; |
|
| 4610 | - } |
|
| 4588 | + // ----- Read byte per byte in order to find the signature |
|
| 4589 | + $v_pos = ftell($this->zip_fd); |
|
| 4590 | + $v_bytes = 0x00000000; |
|
| 4591 | + while ($v_pos < $v_size) |
|
| 4592 | + { |
|
| 4593 | + // ----- Read a byte |
|
| 4594 | + $v_byte = @fread($this->zip_fd, 1); |
|
| 4595 | + |
|
| 4596 | + // ----- Add the byte |
|
| 4597 | + //$v_bytes = ($v_bytes << 8) | Ord($v_byte); |
|
| 4598 | + // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number |
|
| 4599 | + // Otherwise on systems where we have 64bit integers the check below for the magic number will fail. |
|
| 4600 | + $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); |
|
| 4601 | + |
|
| 4602 | + // ----- Compare the bytes |
|
| 4603 | + if ($v_bytes == 0x504b0506) |
|
| 4604 | + { |
|
| 4605 | + $v_pos++; |
|
| 4606 | + break; |
|
| 4607 | + } |
|
| 4608 | + |
|
| 4609 | + $v_pos++; |
|
| 4610 | + } |
|
| 4611 | 4611 | |
| 4612 | - // ----- Look if not found end of central dir |
|
| 4613 | - if ($v_pos == $v_size) |
|
| 4614 | - { |
|
| 4612 | + // ----- Look if not found end of central dir |
|
| 4613 | + if ($v_pos == $v_size) |
|
| 4614 | + { |
|
| 4615 | 4615 | |
| 4616 | - // ----- Error log |
|
| 4617 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); |
|
| 4616 | + // ----- Error log |
|
| 4617 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); |
|
| 4618 | 4618 | |
| 4619 | - // ----- Return |
|
| 4620 | - return PclZip::errorCode(); |
|
| 4621 | - } |
|
| 4622 | - } |
|
| 4619 | + // ----- Return |
|
| 4620 | + return PclZip::errorCode(); |
|
| 4621 | + } |
|
| 4622 | + } |
|
| 4623 | 4623 | |
| 4624 | - // ----- Read the first 18 bytes of the header |
|
| 4625 | - $v_binary_data = fread($this->zip_fd, 18); |
|
| 4624 | + // ----- Read the first 18 bytes of the header |
|
| 4625 | + $v_binary_data = fread($this->zip_fd, 18); |
|
| 4626 | 4626 | |
| 4627 | - // ----- Look for invalid block size |
|
| 4628 | - if (strlen($v_binary_data) != 18) |
|
| 4629 | - { |
|
| 4627 | + // ----- Look for invalid block size |
|
| 4628 | + if (strlen($v_binary_data) != 18) |
|
| 4629 | + { |
|
| 4630 | 4630 | |
| 4631 | - // ----- Error log |
|
| 4632 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); |
|
| 4631 | + // ----- Error log |
|
| 4632 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); |
|
| 4633 | 4633 | |
| 4634 | - // ----- Return |
|
| 4635 | - return PclZip::errorCode(); |
|
| 4636 | - } |
|
| 4634 | + // ----- Return |
|
| 4635 | + return PclZip::errorCode(); |
|
| 4636 | + } |
|
| 4637 | 4637 | |
| 4638 | - // ----- Extract the values |
|
| 4639 | - $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data); |
|
| 4638 | + // ----- Extract the values |
|
| 4639 | + $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data); |
|
| 4640 | 4640 | |
| 4641 | - // ----- Check the global size |
|
| 4642 | - if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { |
|
| 4641 | + // ----- Check the global size |
|
| 4642 | + if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { |
|
| 4643 | 4643 | |
| 4644 | 4644 | // ----- Removed in release 2.2 see readme file |
| 4645 | 4645 | // The check of the file size is a little too strict. |
| 4646 | 4646 | // Some bugs where found when a zip is encrypted/decrypted with 'crypt'. |
| 4647 | 4647 | // While decrypted, zip has training 0 bytes |
| 4648 | 4648 | if (0) { |
| 4649 | - // ----- Error log |
|
| 4650 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, |
|
| 4651 | - 'The central dir is not at the end of the archive.' |
|
| 4649 | + // ----- Error log |
|
| 4650 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, |
|
| 4651 | + 'The central dir is not at the end of the archive.' |
|
| 4652 | 4652 | .' Some trailing bytes exists after the archive.'); |
| 4653 | 4653 | |
| 4654 | - // ----- Return |
|
| 4655 | - return PclZip::errorCode(); |
|
| 4654 | + // ----- Return |
|
| 4655 | + return PclZip::errorCode(); |
|
| 4656 | 4656 | } |
| 4657 | - } |
|
| 4657 | + } |
|
| 4658 | 4658 | |
| 4659 | - // ----- Get comment |
|
| 4660 | - if ($v_data['comment_size'] != 0) { |
|
| 4661 | - $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); |
|
| 4662 | - } |
|
| 4663 | - else |
|
| 4664 | - $p_central_dir['comment'] = ''; |
|
| 4665 | - |
|
| 4666 | - $p_central_dir['entries'] = $v_data['entries']; |
|
| 4667 | - $p_central_dir['disk_entries'] = $v_data['disk_entries']; |
|
| 4668 | - $p_central_dir['offset'] = $v_data['offset']; |
|
| 4669 | - $p_central_dir['size'] = $v_data['size']; |
|
| 4670 | - $p_central_dir['disk'] = $v_data['disk']; |
|
| 4671 | - $p_central_dir['disk_start'] = $v_data['disk_start']; |
|
| 4672 | - |
|
| 4673 | - // TBC |
|
| 4674 | - //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) { |
|
| 4675 | - //} |
|
| 4676 | - |
|
| 4677 | - // ----- Return |
|
| 4678 | - return $v_result; |
|
| 4659 | + // ----- Get comment |
|
| 4660 | + if ($v_data['comment_size'] != 0) { |
|
| 4661 | + $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); |
|
| 4662 | + } |
|
| 4663 | + else |
|
| 4664 | + $p_central_dir['comment'] = ''; |
|
| 4665 | + |
|
| 4666 | + $p_central_dir['entries'] = $v_data['entries']; |
|
| 4667 | + $p_central_dir['disk_entries'] = $v_data['disk_entries']; |
|
| 4668 | + $p_central_dir['offset'] = $v_data['offset']; |
|
| 4669 | + $p_central_dir['size'] = $v_data['size']; |
|
| 4670 | + $p_central_dir['disk'] = $v_data['disk']; |
|
| 4671 | + $p_central_dir['disk_start'] = $v_data['disk_start']; |
|
| 4672 | + |
|
| 4673 | + // TBC |
|
| 4674 | + //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) { |
|
| 4675 | + //} |
|
| 4676 | + |
|
| 4677 | + // ----- Return |
|
| 4678 | + return $v_result; |
|
| 4679 | 4679 | } |
| 4680 | 4680 | // -------------------------------------------------------------------------------- |
| 4681 | 4681 | |
@@ -4687,96 +4687,96 @@ discard block |
||
| 4687 | 4687 | // -------------------------------------------------------------------------------- |
| 4688 | 4688 | function privDeleteByRule(&$p_result_list, &$p_options) |
| 4689 | 4689 | { |
| 4690 | - $v_result=1; |
|
| 4691 | - $v_list_detail = array(); |
|
| 4692 | - |
|
| 4693 | - // ----- Open the zip file |
|
| 4694 | - if (($v_result=$this->privOpenFd('rb')) != 1) |
|
| 4695 | - { |
|
| 4696 | - // ----- Return |
|
| 4697 | - return $v_result; |
|
| 4698 | - } |
|
| 4690 | + $v_result=1; |
|
| 4691 | + $v_list_detail = array(); |
|
| 4692 | + |
|
| 4693 | + // ----- Open the zip file |
|
| 4694 | + if (($v_result=$this->privOpenFd('rb')) != 1) |
|
| 4695 | + { |
|
| 4696 | + // ----- Return |
|
| 4697 | + return $v_result; |
|
| 4698 | + } |
|
| 4699 | 4699 | |
| 4700 | - // ----- Read the central directory informations |
|
| 4701 | - $v_central_dir = array(); |
|
| 4702 | - if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 4703 | - { |
|
| 4704 | - $this->privCloseFd(); |
|
| 4705 | - return $v_result; |
|
| 4706 | - } |
|
| 4700 | + // ----- Read the central directory informations |
|
| 4701 | + $v_central_dir = array(); |
|
| 4702 | + if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 4703 | + { |
|
| 4704 | + $this->privCloseFd(); |
|
| 4705 | + return $v_result; |
|
| 4706 | + } |
|
| 4707 | 4707 | |
| 4708 | - // ----- Go to beginning of File |
|
| 4709 | - @rewind($this->zip_fd); |
|
| 4708 | + // ----- Go to beginning of File |
|
| 4709 | + @rewind($this->zip_fd); |
|
| 4710 | 4710 | |
| 4711 | - // ----- Scan all the files |
|
| 4712 | - // ----- Start at beginning of Central Dir |
|
| 4713 | - $v_pos_entry = $v_central_dir['offset']; |
|
| 4714 | - @rewind($this->zip_fd); |
|
| 4715 | - if (@fseek($this->zip_fd, $v_pos_entry)) |
|
| 4716 | - { |
|
| 4717 | - // ----- Close the zip file |
|
| 4718 | - $this->privCloseFd(); |
|
| 4711 | + // ----- Scan all the files |
|
| 4712 | + // ----- Start at beginning of Central Dir |
|
| 4713 | + $v_pos_entry = $v_central_dir['offset']; |
|
| 4714 | + @rewind($this->zip_fd); |
|
| 4715 | + if (@fseek($this->zip_fd, $v_pos_entry)) |
|
| 4716 | + { |
|
| 4717 | + // ----- Close the zip file |
|
| 4718 | + $this->privCloseFd(); |
|
| 4719 | 4719 | |
| 4720 | - // ----- Error log |
|
| 4721 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 4720 | + // ----- Error log |
|
| 4721 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 4722 | 4722 | |
| 4723 | - // ----- Return |
|
| 4724 | - return PclZip::errorCode(); |
|
| 4725 | - } |
|
| 4723 | + // ----- Return |
|
| 4724 | + return PclZip::errorCode(); |
|
| 4725 | + } |
|
| 4726 | 4726 | |
| 4727 | - // ----- Read each entry |
|
| 4728 | - $v_header_list = array(); |
|
| 4729 | - $j_start = 0; |
|
| 4730 | - for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
|
| 4731 | - { |
|
| 4727 | + // ----- Read each entry |
|
| 4728 | + $v_header_list = array(); |
|
| 4729 | + $j_start = 0; |
|
| 4730 | + for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
|
| 4731 | + { |
|
| 4732 | 4732 | |
| 4733 | - // ----- Read the file header |
|
| 4734 | - $v_header_list[$v_nb_extracted] = array(); |
|
| 4735 | - if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) |
|
| 4736 | - { |
|
| 4737 | - // ----- Close the zip file |
|
| 4738 | - $this->privCloseFd(); |
|
| 4733 | + // ----- Read the file header |
|
| 4734 | + $v_header_list[$v_nb_extracted] = array(); |
|
| 4735 | + if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) |
|
| 4736 | + { |
|
| 4737 | + // ----- Close the zip file |
|
| 4738 | + $this->privCloseFd(); |
|
| 4739 | 4739 | |
| 4740 | - return $v_result; |
|
| 4741 | - } |
|
| 4740 | + return $v_result; |
|
| 4741 | + } |
|
| 4742 | 4742 | |
| 4743 | 4743 | |
| 4744 | - // ----- Store the index |
|
| 4745 | - $v_header_list[$v_nb_extracted]['index'] = $i; |
|
| 4746 | - |
|
| 4747 | - // ----- Look for the specific extract rules |
|
| 4748 | - $v_found = false; |
|
| 4749 | - |
|
| 4750 | - // ----- Look for extract by name rule |
|
| 4751 | - if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 4752 | - && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
|
| 4753 | - |
|
| 4754 | - // ----- Look if the filename is in the list |
|
| 4755 | - for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { |
|
| 4756 | - |
|
| 4757 | - // ----- Look for a directory |
|
| 4758 | - if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
|
| 4759 | - |
|
| 4760 | - // ----- Look if the directory is in the filename path |
|
| 4761 | - if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 4762 | - && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
|
| 4763 | - $v_found = true; |
|
| 4764 | - } |
|
| 4765 | - elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ |
|
| 4766 | - && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
|
| 4767 | - $v_found = true; |
|
| 4768 | - } |
|
| 4769 | - } |
|
| 4770 | - // ----- Look for a filename |
|
| 4771 | - elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
|
| 4772 | - $v_found = true; |
|
| 4773 | - } |
|
| 4774 | - } |
|
| 4775 | - } |
|
| 4744 | + // ----- Store the index |
|
| 4745 | + $v_header_list[$v_nb_extracted]['index'] = $i; |
|
| 4746 | + |
|
| 4747 | + // ----- Look for the specific extract rules |
|
| 4748 | + $v_found = false; |
|
| 4749 | + |
|
| 4750 | + // ----- Look for extract by name rule |
|
| 4751 | + if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 4752 | + && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
|
| 4753 | + |
|
| 4754 | + // ----- Look if the filename is in the list |
|
| 4755 | + for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { |
|
| 4756 | + |
|
| 4757 | + // ----- Look for a directory |
|
| 4758 | + if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
|
| 4759 | + |
|
| 4760 | + // ----- Look if the directory is in the filename path |
|
| 4761 | + if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 4762 | + && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
|
| 4763 | + $v_found = true; |
|
| 4764 | + } |
|
| 4765 | + elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ |
|
| 4766 | + && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
|
| 4767 | + $v_found = true; |
|
| 4768 | + } |
|
| 4769 | + } |
|
| 4770 | + // ----- Look for a filename |
|
| 4771 | + elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
|
| 4772 | + $v_found = true; |
|
| 4773 | + } |
|
| 4774 | + } |
|
| 4775 | + } |
|
| 4776 | 4776 | |
| 4777 | - // ----- Look for extract by ereg rule |
|
| 4778 | - // ereg() is deprecated with PHP 5.3 |
|
| 4779 | - /* |
|
| 4777 | + // ----- Look for extract by ereg rule |
|
| 4778 | + // ereg() is deprecated with PHP 5.3 |
|
| 4779 | + /* |
|
| 4780 | 4780 | else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) |
| 4781 | 4781 | && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { |
| 4782 | 4782 | |
@@ -4786,201 +4786,201 @@ discard block |
||
| 4786 | 4786 | } |
| 4787 | 4787 | */ |
| 4788 | 4788 | |
| 4789 | - // ----- Look for extract by preg rule |
|
| 4790 | - else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 4791 | - && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
|
| 4789 | + // ----- Look for extract by preg rule |
|
| 4790 | + else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 4791 | + && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
|
| 4792 | 4792 | |
| 4793 | - if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { |
|
| 4794 | - $v_found = true; |
|
| 4795 | - } |
|
| 4796 | - } |
|
| 4793 | + if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { |
|
| 4794 | + $v_found = true; |
|
| 4795 | + } |
|
| 4796 | + } |
|
| 4797 | 4797 | |
| 4798 | - // ----- Look for extract by index rule |
|
| 4799 | - else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 4800 | - && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
|
| 4798 | + // ----- Look for extract by index rule |
|
| 4799 | + else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 4800 | + && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
|
| 4801 | 4801 | |
| 4802 | - // ----- Look if the index is in the list |
|
| 4803 | - for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { |
|
| 4802 | + // ----- Look if the index is in the list |
|
| 4803 | + for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { |
|
| 4804 | 4804 | |
| 4805 | - if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 4806 | - $v_found = true; |
|
| 4807 | - } |
|
| 4808 | - if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 4809 | - $j_start = $j+1; |
|
| 4810 | - } |
|
| 4805 | + if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 4806 | + $v_found = true; |
|
| 4807 | + } |
|
| 4808 | + if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 4809 | + $j_start = $j+1; |
|
| 4810 | + } |
|
| 4811 | 4811 | |
| 4812 | - if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
|
| 4813 | - break; |
|
| 4814 | - } |
|
| 4815 | - } |
|
| 4816 | - } |
|
| 4817 | - else { |
|
| 4818 | - $v_found = true; |
|
| 4819 | - } |
|
| 4812 | + if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
|
| 4813 | + break; |
|
| 4814 | + } |
|
| 4815 | + } |
|
| 4816 | + } |
|
| 4817 | + else { |
|
| 4818 | + $v_found = true; |
|
| 4819 | + } |
|
| 4820 | 4820 | |
| 4821 | - // ----- Look for deletion |
|
| 4822 | - if ($v_found) |
|
| 4823 | - { |
|
| 4824 | - unset($v_header_list[$v_nb_extracted]); |
|
| 4825 | - } |
|
| 4826 | - else |
|
| 4827 | - { |
|
| 4828 | - $v_nb_extracted++; |
|
| 4829 | - } |
|
| 4830 | - } |
|
| 4821 | + // ----- Look for deletion |
|
| 4822 | + if ($v_found) |
|
| 4823 | + { |
|
| 4824 | + unset($v_header_list[$v_nb_extracted]); |
|
| 4825 | + } |
|
| 4826 | + else |
|
| 4827 | + { |
|
| 4828 | + $v_nb_extracted++; |
|
| 4829 | + } |
|
| 4830 | + } |
|
| 4831 | 4831 | |
| 4832 | - // ----- Look if something need to be deleted |
|
| 4833 | - if ($v_nb_extracted > 0) { |
|
| 4832 | + // ----- Look if something need to be deleted |
|
| 4833 | + if ($v_nb_extracted > 0) { |
|
| 4834 | 4834 | |
| 4835 | - // ----- Creates a temporay file |
|
| 4836 | - $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
|
| 4835 | + // ----- Creates a temporay file |
|
| 4836 | + $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
|
| 4837 | 4837 | |
| 4838 | - // ----- Creates a temporary zip archive |
|
| 4839 | - $v_temp_zip = new PclZip($v_zip_temp_name); |
|
| 4838 | + // ----- Creates a temporary zip archive |
|
| 4839 | + $v_temp_zip = new PclZip($v_zip_temp_name); |
|
| 4840 | 4840 | |
| 4841 | - // ----- Open the temporary zip file in write mode |
|
| 4842 | - if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) { |
|
| 4843 | - $this->privCloseFd(); |
|
| 4841 | + // ----- Open the temporary zip file in write mode |
|
| 4842 | + if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) { |
|
| 4843 | + $this->privCloseFd(); |
|
| 4844 | 4844 | |
| 4845 | - // ----- Return |
|
| 4846 | - return $v_result; |
|
| 4847 | - } |
|
| 4845 | + // ----- Return |
|
| 4846 | + return $v_result; |
|
| 4847 | + } |
|
| 4848 | 4848 | |
| 4849 | - // ----- Look which file need to be kept |
|
| 4850 | - for ($i=0; $i<sizeof($v_header_list); $i++) { |
|
| 4849 | + // ----- Look which file need to be kept |
|
| 4850 | + for ($i=0; $i<sizeof($v_header_list); $i++) { |
|
| 4851 | 4851 | |
| 4852 | - // ----- Calculate the position of the header |
|
| 4853 | - @rewind($this->zip_fd); |
|
| 4854 | - if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { |
|
| 4855 | - // ----- Close the zip file |
|
| 4856 | - $this->privCloseFd(); |
|
| 4857 | - $v_temp_zip->privCloseFd(); |
|
| 4858 | - @unlink($v_zip_temp_name); |
|
| 4852 | + // ----- Calculate the position of the header |
|
| 4853 | + @rewind($this->zip_fd); |
|
| 4854 | + if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { |
|
| 4855 | + // ----- Close the zip file |
|
| 4856 | + $this->privCloseFd(); |
|
| 4857 | + $v_temp_zip->privCloseFd(); |
|
| 4858 | + @unlink($v_zip_temp_name); |
|
| 4859 | 4859 | |
| 4860 | - // ----- Error log |
|
| 4861 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 4860 | + // ----- Error log |
|
| 4861 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 4862 | 4862 | |
| 4863 | - // ----- Return |
|
| 4864 | - return PclZip::errorCode(); |
|
| 4865 | - } |
|
| 4863 | + // ----- Return |
|
| 4864 | + return PclZip::errorCode(); |
|
| 4865 | + } |
|
| 4866 | 4866 | |
| 4867 | - // ----- Read the file header |
|
| 4868 | - $v_local_header = array(); |
|
| 4869 | - if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) { |
|
| 4870 | - // ----- Close the zip file |
|
| 4871 | - $this->privCloseFd(); |
|
| 4872 | - $v_temp_zip->privCloseFd(); |
|
| 4873 | - @unlink($v_zip_temp_name); |
|
| 4867 | + // ----- Read the file header |
|
| 4868 | + $v_local_header = array(); |
|
| 4869 | + if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) { |
|
| 4870 | + // ----- Close the zip file |
|
| 4871 | + $this->privCloseFd(); |
|
| 4872 | + $v_temp_zip->privCloseFd(); |
|
| 4873 | + @unlink($v_zip_temp_name); |
|
| 4874 | 4874 | |
| 4875 | - // ----- Return |
|
| 4876 | - return $v_result; |
|
| 4877 | - } |
|
| 4875 | + // ----- Return |
|
| 4876 | + return $v_result; |
|
| 4877 | + } |
|
| 4878 | 4878 | |
| 4879 | - // ----- Check that local file header is same as central file header |
|
| 4880 | - if ($this->privCheckFileHeaders($v_local_header, |
|
| 4881 | - $v_header_list[$i]) != 1) { |
|
| 4882 | - // TBC |
|
| 4883 | - } |
|
| 4884 | - unset($v_local_header); |
|
| 4885 | - |
|
| 4886 | - // ----- Write the file header |
|
| 4887 | - if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) { |
|
| 4888 | - // ----- Close the zip file |
|
| 4889 | - $this->privCloseFd(); |
|
| 4890 | - $v_temp_zip->privCloseFd(); |
|
| 4891 | - @unlink($v_zip_temp_name); |
|
| 4892 | - |
|
| 4893 | - // ----- Return |
|
| 4894 | - return $v_result; |
|
| 4895 | - } |
|
| 4896 | - |
|
| 4897 | - // ----- Read/write the data block |
|
| 4898 | - if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) { |
|
| 4899 | - // ----- Close the zip file |
|
| 4900 | - $this->privCloseFd(); |
|
| 4901 | - $v_temp_zip->privCloseFd(); |
|
| 4902 | - @unlink($v_zip_temp_name); |
|
| 4903 | - |
|
| 4904 | - // ----- Return |
|
| 4905 | - return $v_result; |
|
| 4906 | - } |
|
| 4907 | - } |
|
| 4908 | - |
|
| 4909 | - // ----- Store the offset of the central dir |
|
| 4910 | - $v_offset = @ftell($v_temp_zip->zip_fd); |
|
| 4911 | - |
|
| 4912 | - // ----- Re-Create the Central Dir files header |
|
| 4913 | - for ($i=0; $i<sizeof($v_header_list); $i++) { |
|
| 4914 | - // ----- Create the file header |
|
| 4915 | - if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
|
| 4916 | - $v_temp_zip->privCloseFd(); |
|
| 4917 | - $this->privCloseFd(); |
|
| 4918 | - @unlink($v_zip_temp_name); |
|
| 4919 | - |
|
| 4920 | - // ----- Return |
|
| 4921 | - return $v_result; |
|
| 4922 | - } |
|
| 4923 | - |
|
| 4924 | - // ----- Transform the header to a 'usable' info |
|
| 4925 | - $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
|
| 4926 | - } |
|
| 4927 | - |
|
| 4928 | - |
|
| 4929 | - // ----- Zip file comment |
|
| 4930 | - $v_comment = ''; |
|
| 4931 | - if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
|
| 4932 | - $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
|
| 4933 | - } |
|
| 4934 | - |
|
| 4935 | - // ----- Calculate the size of the central header |
|
| 4936 | - $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset; |
|
| 4937 | - |
|
| 4938 | - // ----- Create the central dir footer |
|
| 4939 | - if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) { |
|
| 4940 | - // ----- Reset the file list |
|
| 4941 | - unset($v_header_list); |
|
| 4942 | - $v_temp_zip->privCloseFd(); |
|
| 4943 | - $this->privCloseFd(); |
|
| 4944 | - @unlink($v_zip_temp_name); |
|
| 4945 | - |
|
| 4946 | - // ----- Return |
|
| 4947 | - return $v_result; |
|
| 4948 | - } |
|
| 4949 | - |
|
| 4950 | - // ----- Close |
|
| 4951 | - $v_temp_zip->privCloseFd(); |
|
| 4952 | - $this->privCloseFd(); |
|
| 4953 | - |
|
| 4954 | - // ----- Delete the zip file |
|
| 4955 | - // TBC : I should test the result ... |
|
| 4956 | - @unlink($this->zipname); |
|
| 4957 | - |
|
| 4958 | - // ----- Rename the temporary file |
|
| 4959 | - // TBC : I should test the result ... |
|
| 4960 | - //@rename($v_zip_temp_name, $this->zipname); |
|
| 4961 | - PclZipUtilRename($v_zip_temp_name, $this->zipname); |
|
| 4879 | + // ----- Check that local file header is same as central file header |
|
| 4880 | + if ($this->privCheckFileHeaders($v_local_header, |
|
| 4881 | + $v_header_list[$i]) != 1) { |
|
| 4882 | + // TBC |
|
| 4883 | + } |
|
| 4884 | + unset($v_local_header); |
|
| 4885 | + |
|
| 4886 | + // ----- Write the file header |
|
| 4887 | + if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) { |
|
| 4888 | + // ----- Close the zip file |
|
| 4889 | + $this->privCloseFd(); |
|
| 4890 | + $v_temp_zip->privCloseFd(); |
|
| 4891 | + @unlink($v_zip_temp_name); |
|
| 4892 | + |
|
| 4893 | + // ----- Return |
|
| 4894 | + return $v_result; |
|
| 4895 | + } |
|
| 4896 | + |
|
| 4897 | + // ----- Read/write the data block |
|
| 4898 | + if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) { |
|
| 4899 | + // ----- Close the zip file |
|
| 4900 | + $this->privCloseFd(); |
|
| 4901 | + $v_temp_zip->privCloseFd(); |
|
| 4902 | + @unlink($v_zip_temp_name); |
|
| 4903 | + |
|
| 4904 | + // ----- Return |
|
| 4905 | + return $v_result; |
|
| 4906 | + } |
|
| 4907 | + } |
|
| 4908 | + |
|
| 4909 | + // ----- Store the offset of the central dir |
|
| 4910 | + $v_offset = @ftell($v_temp_zip->zip_fd); |
|
| 4911 | + |
|
| 4912 | + // ----- Re-Create the Central Dir files header |
|
| 4913 | + for ($i=0; $i<sizeof($v_header_list); $i++) { |
|
| 4914 | + // ----- Create the file header |
|
| 4915 | + if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
|
| 4916 | + $v_temp_zip->privCloseFd(); |
|
| 4917 | + $this->privCloseFd(); |
|
| 4918 | + @unlink($v_zip_temp_name); |
|
| 4919 | + |
|
| 4920 | + // ----- Return |
|
| 4921 | + return $v_result; |
|
| 4922 | + } |
|
| 4923 | + |
|
| 4924 | + // ----- Transform the header to a 'usable' info |
|
| 4925 | + $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
|
| 4926 | + } |
|
| 4927 | + |
|
| 4928 | + |
|
| 4929 | + // ----- Zip file comment |
|
| 4930 | + $v_comment = ''; |
|
| 4931 | + if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
|
| 4932 | + $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
|
| 4933 | + } |
|
| 4934 | + |
|
| 4935 | + // ----- Calculate the size of the central header |
|
| 4936 | + $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset; |
|
| 4937 | + |
|
| 4938 | + // ----- Create the central dir footer |
|
| 4939 | + if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) { |
|
| 4940 | + // ----- Reset the file list |
|
| 4941 | + unset($v_header_list); |
|
| 4942 | + $v_temp_zip->privCloseFd(); |
|
| 4943 | + $this->privCloseFd(); |
|
| 4944 | + @unlink($v_zip_temp_name); |
|
| 4945 | + |
|
| 4946 | + // ----- Return |
|
| 4947 | + return $v_result; |
|
| 4948 | + } |
|
| 4949 | + |
|
| 4950 | + // ----- Close |
|
| 4951 | + $v_temp_zip->privCloseFd(); |
|
| 4952 | + $this->privCloseFd(); |
|
| 4953 | + |
|
| 4954 | + // ----- Delete the zip file |
|
| 4955 | + // TBC : I should test the result ... |
|
| 4956 | + @unlink($this->zipname); |
|
| 4957 | + |
|
| 4958 | + // ----- Rename the temporary file |
|
| 4959 | + // TBC : I should test the result ... |
|
| 4960 | + //@rename($v_zip_temp_name, $this->zipname); |
|
| 4961 | + PclZipUtilRename($v_zip_temp_name, $this->zipname); |
|
| 4962 | 4962 | |
| 4963 | - // ----- Destroy the temporary archive |
|
| 4964 | - unset($v_temp_zip); |
|
| 4965 | - } |
|
| 4963 | + // ----- Destroy the temporary archive |
|
| 4964 | + unset($v_temp_zip); |
|
| 4965 | + } |
|
| 4966 | 4966 | |
| 4967 | - // ----- Remove every files : reset the file |
|
| 4968 | - else if ($v_central_dir['entries'] != 0) { |
|
| 4969 | - $this->privCloseFd(); |
|
| 4967 | + // ----- Remove every files : reset the file |
|
| 4968 | + else if ($v_central_dir['entries'] != 0) { |
|
| 4969 | + $this->privCloseFd(); |
|
| 4970 | 4970 | |
| 4971 | - if (($v_result = $this->privOpenFd('wb')) != 1) { |
|
| 4972 | - return $v_result; |
|
| 4973 | - } |
|
| 4971 | + if (($v_result = $this->privOpenFd('wb')) != 1) { |
|
| 4972 | + return $v_result; |
|
| 4973 | + } |
|
| 4974 | 4974 | |
| 4975 | - if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) { |
|
| 4976 | - return $v_result; |
|
| 4977 | - } |
|
| 4975 | + if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) { |
|
| 4976 | + return $v_result; |
|
| 4977 | + } |
|
| 4978 | 4978 | |
| 4979 | - $this->privCloseFd(); |
|
| 4980 | - } |
|
| 4979 | + $this->privCloseFd(); |
|
| 4980 | + } |
|
| 4981 | 4981 | |
| 4982 | - // ----- Return |
|
| 4983 | - return $v_result; |
|
| 4982 | + // ----- Return |
|
| 4983 | + return $v_result; |
|
| 4984 | 4984 | } |
| 4985 | 4985 | // -------------------------------------------------------------------------------- |
| 4986 | 4986 | |
@@ -4997,49 +4997,49 @@ discard block |
||
| 4997 | 4997 | // -------------------------------------------------------------------------------- |
| 4998 | 4998 | function privDirCheck($p_dir, $p_is_dir=false) |
| 4999 | 4999 | { |
| 5000 | - $v_result = 1; |
|
| 5000 | + $v_result = 1; |
|
| 5001 | 5001 | |
| 5002 | 5002 | |
| 5003 | - // ----- Remove the final '/' |
|
| 5004 | - if (($p_is_dir) && (substr($p_dir, -1)=='/')) |
|
| 5005 | - { |
|
| 5006 | - $p_dir = substr($p_dir, 0, strlen($p_dir)-1); |
|
| 5007 | - } |
|
| 5003 | + // ----- Remove the final '/' |
|
| 5004 | + if (($p_is_dir) && (substr($p_dir, -1)=='/')) |
|
| 5005 | + { |
|
| 5006 | + $p_dir = substr($p_dir, 0, strlen($p_dir)-1); |
|
| 5007 | + } |
|
| 5008 | 5008 | |
| 5009 | - // ----- Check the directory availability |
|
| 5010 | - if ((is_dir($p_dir)) || ($p_dir == "")) |
|
| 5011 | - { |
|
| 5012 | - return 1; |
|
| 5013 | - } |
|
| 5009 | + // ----- Check the directory availability |
|
| 5010 | + if ((is_dir($p_dir)) || ($p_dir == "")) |
|
| 5011 | + { |
|
| 5012 | + return 1; |
|
| 5013 | + } |
|
| 5014 | 5014 | |
| 5015 | - // ----- Extract parent directory |
|
| 5016 | - $p_parent_dir = dirname($p_dir); |
|
| 5017 | - |
|
| 5018 | - // ----- Just a check |
|
| 5019 | - if ($p_parent_dir != $p_dir) |
|
| 5020 | - { |
|
| 5021 | - // ----- Look for parent directory |
|
| 5022 | - if ($p_parent_dir != "") |
|
| 5023 | - { |
|
| 5024 | - if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) |
|
| 5025 | - { |
|
| 5026 | - return $v_result; |
|
| 5027 | - } |
|
| 5028 | - } |
|
| 5029 | - } |
|
| 5015 | + // ----- Extract parent directory |
|
| 5016 | + $p_parent_dir = dirname($p_dir); |
|
| 5017 | + |
|
| 5018 | + // ----- Just a check |
|
| 5019 | + if ($p_parent_dir != $p_dir) |
|
| 5020 | + { |
|
| 5021 | + // ----- Look for parent directory |
|
| 5022 | + if ($p_parent_dir != "") |
|
| 5023 | + { |
|
| 5024 | + if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) |
|
| 5025 | + { |
|
| 5026 | + return $v_result; |
|
| 5027 | + } |
|
| 5028 | + } |
|
| 5029 | + } |
|
| 5030 | 5030 | |
| 5031 | - // ----- Create the directory |
|
| 5032 | - if (!@mkdir($p_dir, 0777)) |
|
| 5033 | - { |
|
| 5034 | - // ----- Error log |
|
| 5035 | - PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); |
|
| 5031 | + // ----- Create the directory |
|
| 5032 | + if (!@mkdir($p_dir, 0777)) |
|
| 5033 | + { |
|
| 5034 | + // ----- Error log |
|
| 5035 | + PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); |
|
| 5036 | 5036 | |
| 5037 | - // ----- Return |
|
| 5038 | - return PclZip::errorCode(); |
|
| 5039 | - } |
|
| 5037 | + // ----- Return |
|
| 5038 | + return PclZip::errorCode(); |
|
| 5039 | + } |
|
| 5040 | 5040 | |
| 5041 | - // ----- Return |
|
| 5042 | - return $v_result; |
|
| 5041 | + // ----- Return |
|
| 5042 | + return $v_result; |
|
| 5043 | 5043 | } |
| 5044 | 5044 | // -------------------------------------------------------------------------------- |
| 5045 | 5045 | |
@@ -5052,180 +5052,180 @@ discard block |
||
| 5052 | 5052 | // -------------------------------------------------------------------------------- |
| 5053 | 5053 | function privMerge(&$p_archive_to_add) |
| 5054 | 5054 | { |
| 5055 | - $v_result=1; |
|
| 5055 | + $v_result=1; |
|
| 5056 | 5056 | |
| 5057 | - // ----- Look if the archive_to_add exists |
|
| 5058 | - if (!is_file($p_archive_to_add->zipname)) |
|
| 5059 | - { |
|
| 5057 | + // ----- Look if the archive_to_add exists |
|
| 5058 | + if (!is_file($p_archive_to_add->zipname)) |
|
| 5059 | + { |
|
| 5060 | 5060 | |
| 5061 | - // ----- Nothing to merge, so merge is a success |
|
| 5062 | - $v_result = 1; |
|
| 5061 | + // ----- Nothing to merge, so merge is a success |
|
| 5062 | + $v_result = 1; |
|
| 5063 | 5063 | |
| 5064 | - // ----- Return |
|
| 5065 | - return $v_result; |
|
| 5066 | - } |
|
| 5064 | + // ----- Return |
|
| 5065 | + return $v_result; |
|
| 5066 | + } |
|
| 5067 | 5067 | |
| 5068 | - // ----- Look if the archive exists |
|
| 5069 | - if (!is_file($this->zipname)) |
|
| 5070 | - { |
|
| 5068 | + // ----- Look if the archive exists |
|
| 5069 | + if (!is_file($this->zipname)) |
|
| 5070 | + { |
|
| 5071 | 5071 | |
| 5072 | - // ----- Do a duplicate |
|
| 5073 | - $v_result = $this->privDuplicate($p_archive_to_add->zipname); |
|
| 5072 | + // ----- Do a duplicate |
|
| 5073 | + $v_result = $this->privDuplicate($p_archive_to_add->zipname); |
|
| 5074 | 5074 | |
| 5075 | - // ----- Return |
|
| 5076 | - return $v_result; |
|
| 5077 | - } |
|
| 5075 | + // ----- Return |
|
| 5076 | + return $v_result; |
|
| 5077 | + } |
|
| 5078 | 5078 | |
| 5079 | - // ----- Open the zip file |
|
| 5080 | - if (($v_result=$this->privOpenFd('rb')) != 1) |
|
| 5081 | - { |
|
| 5082 | - // ----- Return |
|
| 5083 | - return $v_result; |
|
| 5084 | - } |
|
| 5079 | + // ----- Open the zip file |
|
| 5080 | + if (($v_result=$this->privOpenFd('rb')) != 1) |
|
| 5081 | + { |
|
| 5082 | + // ----- Return |
|
| 5083 | + return $v_result; |
|
| 5084 | + } |
|
| 5085 | 5085 | |
| 5086 | - // ----- Read the central directory informations |
|
| 5087 | - $v_central_dir = array(); |
|
| 5088 | - if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 5089 | - { |
|
| 5090 | - $this->privCloseFd(); |
|
| 5091 | - return $v_result; |
|
| 5092 | - } |
|
| 5086 | + // ----- Read the central directory informations |
|
| 5087 | + $v_central_dir = array(); |
|
| 5088 | + if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 5089 | + { |
|
| 5090 | + $this->privCloseFd(); |
|
| 5091 | + return $v_result; |
|
| 5092 | + } |
|
| 5093 | 5093 | |
| 5094 | - // ----- Go to beginning of File |
|
| 5095 | - @rewind($this->zip_fd); |
|
| 5094 | + // ----- Go to beginning of File |
|
| 5095 | + @rewind($this->zip_fd); |
|
| 5096 | 5096 | |
| 5097 | - // ----- Open the archive_to_add file |
|
| 5098 | - if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) |
|
| 5099 | - { |
|
| 5100 | - $this->privCloseFd(); |
|
| 5097 | + // ----- Open the archive_to_add file |
|
| 5098 | + if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) |
|
| 5099 | + { |
|
| 5100 | + $this->privCloseFd(); |
|
| 5101 | 5101 | |
| 5102 | - // ----- Return |
|
| 5103 | - return $v_result; |
|
| 5104 | - } |
|
| 5102 | + // ----- Return |
|
| 5103 | + return $v_result; |
|
| 5104 | + } |
|
| 5105 | 5105 | |
| 5106 | - // ----- Read the central directory informations |
|
| 5107 | - $v_central_dir_to_add = array(); |
|
| 5108 | - if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) |
|
| 5109 | - { |
|
| 5110 | - $this->privCloseFd(); |
|
| 5111 | - $p_archive_to_add->privCloseFd(); |
|
| 5106 | + // ----- Read the central directory informations |
|
| 5107 | + $v_central_dir_to_add = array(); |
|
| 5108 | + if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) |
|
| 5109 | + { |
|
| 5110 | + $this->privCloseFd(); |
|
| 5111 | + $p_archive_to_add->privCloseFd(); |
|
| 5112 | 5112 | |
| 5113 | - return $v_result; |
|
| 5114 | - } |
|
| 5113 | + return $v_result; |
|
| 5114 | + } |
|
| 5115 | 5115 | |
| 5116 | - // ----- Go to beginning of File |
|
| 5117 | - @rewind($p_archive_to_add->zip_fd); |
|
| 5116 | + // ----- Go to beginning of File |
|
| 5117 | + @rewind($p_archive_to_add->zip_fd); |
|
| 5118 | 5118 | |
| 5119 | - // ----- Creates a temporay file |
|
| 5120 | - $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
|
| 5119 | + // ----- Creates a temporay file |
|
| 5120 | + $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
|
| 5121 | 5121 | |
| 5122 | - // ----- Open the temporary file in write mode |
|
| 5123 | - if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
|
| 5124 | - { |
|
| 5125 | - $this->privCloseFd(); |
|
| 5126 | - $p_archive_to_add->privCloseFd(); |
|
| 5122 | + // ----- Open the temporary file in write mode |
|
| 5123 | + if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
|
| 5124 | + { |
|
| 5125 | + $this->privCloseFd(); |
|
| 5126 | + $p_archive_to_add->privCloseFd(); |
|
| 5127 | 5127 | |
| 5128 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
|
| 5128 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
|
| 5129 | 5129 | |
| 5130 | - // ----- Return |
|
| 5131 | - return PclZip::errorCode(); |
|
| 5132 | - } |
|
| 5130 | + // ----- Return |
|
| 5131 | + return PclZip::errorCode(); |
|
| 5132 | + } |
|
| 5133 | 5133 | |
| 5134 | - // ----- Copy the files from the archive to the temporary file |
|
| 5135 | - // TBC : Here I should better append the file and go back to erase the central dir |
|
| 5136 | - $v_size = $v_central_dir['offset']; |
|
| 5137 | - while ($v_size != 0) |
|
| 5138 | - { |
|
| 5139 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5140 | - $v_buffer = fread($this->zip_fd, $v_read_size); |
|
| 5141 | - @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5142 | - $v_size -= $v_read_size; |
|
| 5143 | - } |
|
| 5134 | + // ----- Copy the files from the archive to the temporary file |
|
| 5135 | + // TBC : Here I should better append the file and go back to erase the central dir |
|
| 5136 | + $v_size = $v_central_dir['offset']; |
|
| 5137 | + while ($v_size != 0) |
|
| 5138 | + { |
|
| 5139 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5140 | + $v_buffer = fread($this->zip_fd, $v_read_size); |
|
| 5141 | + @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5142 | + $v_size -= $v_read_size; |
|
| 5143 | + } |
|
| 5144 | 5144 | |
| 5145 | - // ----- Copy the files from the archive_to_add into the temporary file |
|
| 5146 | - $v_size = $v_central_dir_to_add['offset']; |
|
| 5147 | - while ($v_size != 0) |
|
| 5148 | - { |
|
| 5149 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5150 | - $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size); |
|
| 5151 | - @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5152 | - $v_size -= $v_read_size; |
|
| 5153 | - } |
|
| 5145 | + // ----- Copy the files from the archive_to_add into the temporary file |
|
| 5146 | + $v_size = $v_central_dir_to_add['offset']; |
|
| 5147 | + while ($v_size != 0) |
|
| 5148 | + { |
|
| 5149 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5150 | + $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size); |
|
| 5151 | + @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5152 | + $v_size -= $v_read_size; |
|
| 5153 | + } |
|
| 5154 | 5154 | |
| 5155 | - // ----- Store the offset of the central dir |
|
| 5156 | - $v_offset = @ftell($v_zip_temp_fd); |
|
| 5157 | - |
|
| 5158 | - // ----- Copy the block of file headers from the old archive |
|
| 5159 | - $v_size = $v_central_dir['size']; |
|
| 5160 | - while ($v_size != 0) |
|
| 5161 | - { |
|
| 5162 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5163 | - $v_buffer = @fread($this->zip_fd, $v_read_size); |
|
| 5164 | - @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5165 | - $v_size -= $v_read_size; |
|
| 5166 | - } |
|
| 5155 | + // ----- Store the offset of the central dir |
|
| 5156 | + $v_offset = @ftell($v_zip_temp_fd); |
|
| 5157 | + |
|
| 5158 | + // ----- Copy the block of file headers from the old archive |
|
| 5159 | + $v_size = $v_central_dir['size']; |
|
| 5160 | + while ($v_size != 0) |
|
| 5161 | + { |
|
| 5162 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5163 | + $v_buffer = @fread($this->zip_fd, $v_read_size); |
|
| 5164 | + @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5165 | + $v_size -= $v_read_size; |
|
| 5166 | + } |
|
| 5167 | 5167 | |
| 5168 | - // ----- Copy the block of file headers from the archive_to_add |
|
| 5169 | - $v_size = $v_central_dir_to_add['size']; |
|
| 5170 | - while ($v_size != 0) |
|
| 5171 | - { |
|
| 5172 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5173 | - $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size); |
|
| 5174 | - @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5175 | - $v_size -= $v_read_size; |
|
| 5176 | - } |
|
| 5168 | + // ----- Copy the block of file headers from the archive_to_add |
|
| 5169 | + $v_size = $v_central_dir_to_add['size']; |
|
| 5170 | + while ($v_size != 0) |
|
| 5171 | + { |
|
| 5172 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5173 | + $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size); |
|
| 5174 | + @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5175 | + $v_size -= $v_read_size; |
|
| 5176 | + } |
|
| 5177 | 5177 | |
| 5178 | - // ----- Merge the file comments |
|
| 5179 | - $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment']; |
|
| 5178 | + // ----- Merge the file comments |
|
| 5179 | + $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment']; |
|
| 5180 | 5180 | |
| 5181 | - // ----- Calculate the size of the (new) central header |
|
| 5182 | - $v_size = @ftell($v_zip_temp_fd)-$v_offset; |
|
| 5181 | + // ----- Calculate the size of the (new) central header |
|
| 5182 | + $v_size = @ftell($v_zip_temp_fd)-$v_offset; |
|
| 5183 | 5183 | |
| 5184 | - // ----- Swap the file descriptor |
|
| 5185 | - // Here is a trick : I swap the temporary fd with the zip fd, in order to use |
|
| 5186 | - // the following methods on the temporary fil and not the real archive fd |
|
| 5187 | - $v_swap = $this->zip_fd; |
|
| 5188 | - $this->zip_fd = $v_zip_temp_fd; |
|
| 5189 | - $v_zip_temp_fd = $v_swap; |
|
| 5184 | + // ----- Swap the file descriptor |
|
| 5185 | + // Here is a trick : I swap the temporary fd with the zip fd, in order to use |
|
| 5186 | + // the following methods on the temporary fil and not the real archive fd |
|
| 5187 | + $v_swap = $this->zip_fd; |
|
| 5188 | + $this->zip_fd = $v_zip_temp_fd; |
|
| 5189 | + $v_zip_temp_fd = $v_swap; |
|
| 5190 | 5190 | |
| 5191 | - // ----- Create the central dir footer |
|
| 5192 | - if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) |
|
| 5193 | - { |
|
| 5194 | - $this->privCloseFd(); |
|
| 5195 | - $p_archive_to_add->privCloseFd(); |
|
| 5196 | - @fclose($v_zip_temp_fd); |
|
| 5197 | - $this->zip_fd = null; |
|
| 5191 | + // ----- Create the central dir footer |
|
| 5192 | + if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) |
|
| 5193 | + { |
|
| 5194 | + $this->privCloseFd(); |
|
| 5195 | + $p_archive_to_add->privCloseFd(); |
|
| 5196 | + @fclose($v_zip_temp_fd); |
|
| 5197 | + $this->zip_fd = null; |
|
| 5198 | 5198 | |
| 5199 | - // ----- Reset the file list |
|
| 5200 | - unset($v_header_list); |
|
| 5199 | + // ----- Reset the file list |
|
| 5200 | + unset($v_header_list); |
|
| 5201 | 5201 | |
| 5202 | - // ----- Return |
|
| 5203 | - return $v_result; |
|
| 5204 | - } |
|
| 5202 | + // ----- Return |
|
| 5203 | + return $v_result; |
|
| 5204 | + } |
|
| 5205 | 5205 | |
| 5206 | - // ----- Swap back the file descriptor |
|
| 5207 | - $v_swap = $this->zip_fd; |
|
| 5208 | - $this->zip_fd = $v_zip_temp_fd; |
|
| 5209 | - $v_zip_temp_fd = $v_swap; |
|
| 5206 | + // ----- Swap back the file descriptor |
|
| 5207 | + $v_swap = $this->zip_fd; |
|
| 5208 | + $this->zip_fd = $v_zip_temp_fd; |
|
| 5209 | + $v_zip_temp_fd = $v_swap; |
|
| 5210 | 5210 | |
| 5211 | - // ----- Close |
|
| 5212 | - $this->privCloseFd(); |
|
| 5213 | - $p_archive_to_add->privCloseFd(); |
|
| 5211 | + // ----- Close |
|
| 5212 | + $this->privCloseFd(); |
|
| 5213 | + $p_archive_to_add->privCloseFd(); |
|
| 5214 | 5214 | |
| 5215 | - // ----- Close the temporary file |
|
| 5216 | - @fclose($v_zip_temp_fd); |
|
| 5215 | + // ----- Close the temporary file |
|
| 5216 | + @fclose($v_zip_temp_fd); |
|
| 5217 | 5217 | |
| 5218 | - // ----- Delete the zip file |
|
| 5219 | - // TBC : I should test the result ... |
|
| 5220 | - @unlink($this->zipname); |
|
| 5218 | + // ----- Delete the zip file |
|
| 5219 | + // TBC : I should test the result ... |
|
| 5220 | + @unlink($this->zipname); |
|
| 5221 | 5221 | |
| 5222 | - // ----- Rename the temporary file |
|
| 5223 | - // TBC : I should test the result ... |
|
| 5224 | - //@rename($v_zip_temp_name, $this->zipname); |
|
| 5225 | - PclZipUtilRename($v_zip_temp_name, $this->zipname); |
|
| 5222 | + // ----- Rename the temporary file |
|
| 5223 | + // TBC : I should test the result ... |
|
| 5224 | + //@rename($v_zip_temp_name, $this->zipname); |
|
| 5225 | + PclZipUtilRename($v_zip_temp_name, $this->zipname); |
|
| 5226 | 5226 | |
| 5227 | - // ----- Return |
|
| 5228 | - return $v_result; |
|
| 5227 | + // ----- Return |
|
| 5228 | + return $v_result; |
|
| 5229 | 5229 | } |
| 5230 | 5230 | // -------------------------------------------------------------------------------- |
| 5231 | 5231 | |
@@ -5237,56 +5237,56 @@ discard block |
||
| 5237 | 5237 | // -------------------------------------------------------------------------------- |
| 5238 | 5238 | function privDuplicate($p_archive_filename) |
| 5239 | 5239 | { |
| 5240 | - $v_result=1; |
|
| 5240 | + $v_result=1; |
|
| 5241 | 5241 | |
| 5242 | - // ----- Look if the $p_archive_filename exists |
|
| 5243 | - if (!is_file($p_archive_filename)) |
|
| 5244 | - { |
|
| 5242 | + // ----- Look if the $p_archive_filename exists |
|
| 5243 | + if (!is_file($p_archive_filename)) |
|
| 5244 | + { |
|
| 5245 | 5245 | |
| 5246 | - // ----- Nothing to duplicate, so duplicate is a success. |
|
| 5247 | - $v_result = 1; |
|
| 5246 | + // ----- Nothing to duplicate, so duplicate is a success. |
|
| 5247 | + $v_result = 1; |
|
| 5248 | 5248 | |
| 5249 | - // ----- Return |
|
| 5250 | - return $v_result; |
|
| 5251 | - } |
|
| 5249 | + // ----- Return |
|
| 5250 | + return $v_result; |
|
| 5251 | + } |
|
| 5252 | 5252 | |
| 5253 | - // ----- Open the zip file |
|
| 5254 | - if (($v_result=$this->privOpenFd('wb')) != 1) |
|
| 5255 | - { |
|
| 5256 | - // ----- Return |
|
| 5257 | - return $v_result; |
|
| 5258 | - } |
|
| 5253 | + // ----- Open the zip file |
|
| 5254 | + if (($v_result=$this->privOpenFd('wb')) != 1) |
|
| 5255 | + { |
|
| 5256 | + // ----- Return |
|
| 5257 | + return $v_result; |
|
| 5258 | + } |
|
| 5259 | 5259 | |
| 5260 | - // ----- Open the temporary file in write mode |
|
| 5261 | - if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) |
|
| 5262 | - { |
|
| 5263 | - $this->privCloseFd(); |
|
| 5260 | + // ----- Open the temporary file in write mode |
|
| 5261 | + if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) |
|
| 5262 | + { |
|
| 5263 | + $this->privCloseFd(); |
|
| 5264 | 5264 | |
| 5265 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); |
|
| 5265 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); |
|
| 5266 | 5266 | |
| 5267 | - // ----- Return |
|
| 5268 | - return PclZip::errorCode(); |
|
| 5269 | - } |
|
| 5267 | + // ----- Return |
|
| 5268 | + return PclZip::errorCode(); |
|
| 5269 | + } |
|
| 5270 | 5270 | |
| 5271 | - // ----- Copy the files from the archive to the temporary file |
|
| 5272 | - // TBC : Here I should better append the file and go back to erase the central dir |
|
| 5273 | - $v_size = filesize($p_archive_filename); |
|
| 5274 | - while ($v_size != 0) |
|
| 5275 | - { |
|
| 5276 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5277 | - $v_buffer = fread($v_zip_temp_fd, $v_read_size); |
|
| 5278 | - @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
|
| 5279 | - $v_size -= $v_read_size; |
|
| 5280 | - } |
|
| 5271 | + // ----- Copy the files from the archive to the temporary file |
|
| 5272 | + // TBC : Here I should better append the file and go back to erase the central dir |
|
| 5273 | + $v_size = filesize($p_archive_filename); |
|
| 5274 | + while ($v_size != 0) |
|
| 5275 | + { |
|
| 5276 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5277 | + $v_buffer = fread($v_zip_temp_fd, $v_read_size); |
|
| 5278 | + @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
|
| 5279 | + $v_size -= $v_read_size; |
|
| 5280 | + } |
|
| 5281 | 5281 | |
| 5282 | - // ----- Close |
|
| 5283 | - $this->privCloseFd(); |
|
| 5282 | + // ----- Close |
|
| 5283 | + $this->privCloseFd(); |
|
| 5284 | 5284 | |
| 5285 | - // ----- Close the temporary file |
|
| 5286 | - @fclose($v_zip_temp_fd); |
|
| 5285 | + // ----- Close the temporary file |
|
| 5286 | + @fclose($v_zip_temp_fd); |
|
| 5287 | 5287 | |
| 5288 | - // ----- Return |
|
| 5289 | - return $v_result; |
|
| 5288 | + // ----- Return |
|
| 5289 | + return $v_result; |
|
| 5290 | 5290 | } |
| 5291 | 5291 | // -------------------------------------------------------------------------------- |
| 5292 | 5292 | |
@@ -5297,13 +5297,13 @@ discard block |
||
| 5297 | 5297 | // -------------------------------------------------------------------------------- |
| 5298 | 5298 | function privErrorLog($p_error_code=0, $p_error_string='') |
| 5299 | 5299 | { |
| 5300 | - if (PCLZIP_ERROR_EXTERNAL == 1) { |
|
| 5301 | - PclError($p_error_code, $p_error_string); |
|
| 5302 | - } |
|
| 5303 | - else { |
|
| 5304 | - $this->error_code = $p_error_code; |
|
| 5305 | - $this->error_string = $p_error_string; |
|
| 5306 | - } |
|
| 5300 | + if (PCLZIP_ERROR_EXTERNAL == 1) { |
|
| 5301 | + PclError($p_error_code, $p_error_string); |
|
| 5302 | + } |
|
| 5303 | + else { |
|
| 5304 | + $this->error_code = $p_error_code; |
|
| 5305 | + $this->error_string = $p_error_string; |
|
| 5306 | + } |
|
| 5307 | 5307 | } |
| 5308 | 5308 | // -------------------------------------------------------------------------------- |
| 5309 | 5309 | |
@@ -5314,13 +5314,13 @@ discard block |
||
| 5314 | 5314 | // -------------------------------------------------------------------------------- |
| 5315 | 5315 | function privErrorReset() |
| 5316 | 5316 | { |
| 5317 | - if (PCLZIP_ERROR_EXTERNAL == 1) { |
|
| 5318 | - PclErrorReset(); |
|
| 5319 | - } |
|
| 5320 | - else { |
|
| 5321 | - $this->error_code = 0; |
|
| 5322 | - $this->error_string = ''; |
|
| 5323 | - } |
|
| 5317 | + if (PCLZIP_ERROR_EXTERNAL == 1) { |
|
| 5318 | + PclErrorReset(); |
|
| 5319 | + } |
|
| 5320 | + else { |
|
| 5321 | + $this->error_code = 0; |
|
| 5322 | + $this->error_string = ''; |
|
| 5323 | + } |
|
| 5324 | 5324 | } |
| 5325 | 5325 | // -------------------------------------------------------------------------------- |
| 5326 | 5326 | |
@@ -5332,17 +5332,17 @@ discard block |
||
| 5332 | 5332 | // -------------------------------------------------------------------------------- |
| 5333 | 5333 | function privDisableMagicQuotes() |
| 5334 | 5334 | { |
| 5335 | - $v_result=1; |
|
| 5335 | + $v_result=1; |
|
| 5336 | 5336 | |
| 5337 | - // ----- Look if function exists |
|
| 5338 | - if ( (!function_exists("get_magic_quotes_runtime")) |
|
| 5339 | - || (!function_exists("set_magic_quotes_runtime"))) { |
|
| 5340 | - return $v_result; |
|
| 5337 | + // ----- Look if function exists |
|
| 5338 | + if ( (!function_exists("get_magic_quotes_runtime")) |
|
| 5339 | + || (!function_exists("set_magic_quotes_runtime"))) { |
|
| 5340 | + return $v_result; |
|
| 5341 | 5341 | } |
| 5342 | 5342 | |
| 5343 | - // ----- Look if already done |
|
| 5344 | - if ($this->magic_quotes_status != -1) { |
|
| 5345 | - return $v_result; |
|
| 5343 | + // ----- Look if already done |
|
| 5344 | + if ($this->magic_quotes_status != -1) { |
|
| 5345 | + return $v_result; |
|
| 5346 | 5346 | } |
| 5347 | 5347 | |
| 5348 | 5348 | // ----- Get and memorize the magic_quote value |
@@ -5353,8 +5353,8 @@ discard block |
||
| 5353 | 5353 | @set_magic_quotes_runtime(0); |
| 5354 | 5354 | } |
| 5355 | 5355 | |
| 5356 | - // ----- Return |
|
| 5357 | - return $v_result; |
|
| 5356 | + // ----- Return |
|
| 5357 | + return $v_result; |
|
| 5358 | 5358 | } |
| 5359 | 5359 | // -------------------------------------------------------------------------------- |
| 5360 | 5360 | |
@@ -5366,17 +5366,17 @@ discard block |
||
| 5366 | 5366 | // -------------------------------------------------------------------------------- |
| 5367 | 5367 | function privSwapBackMagicQuotes() |
| 5368 | 5368 | { |
| 5369 | - $v_result=1; |
|
| 5369 | + $v_result=1; |
|
| 5370 | 5370 | |
| 5371 | - // ----- Look if function exists |
|
| 5372 | - if ( (!function_exists("get_magic_quotes_runtime")) |
|
| 5373 | - || (!function_exists("set_magic_quotes_runtime"))) { |
|
| 5374 | - return $v_result; |
|
| 5371 | + // ----- Look if function exists |
|
| 5372 | + if ( (!function_exists("get_magic_quotes_runtime")) |
|
| 5373 | + || (!function_exists("set_magic_quotes_runtime"))) { |
|
| 5374 | + return $v_result; |
|
| 5375 | 5375 | } |
| 5376 | 5376 | |
| 5377 | - // ----- Look if something to do |
|
| 5378 | - if ($this->magic_quotes_status != -1) { |
|
| 5379 | - return $v_result; |
|
| 5377 | + // ----- Look if something to do |
|
| 5378 | + if ($this->magic_quotes_status != -1) { |
|
| 5379 | + return $v_result; |
|
| 5380 | 5380 | } |
| 5381 | 5381 | |
| 5382 | 5382 | // ----- Swap back magic_quotes |
@@ -5384,8 +5384,8 @@ discard block |
||
| 5384 | 5384 | @set_magic_quotes_runtime($this->magic_quotes_status); |
| 5385 | 5385 | } |
| 5386 | 5386 | |
| 5387 | - // ----- Return |
|
| 5388 | - return $v_result; |
|
| 5387 | + // ----- Return |
|
| 5388 | + return $v_result; |
|
| 5389 | 5389 | } |
| 5390 | 5390 | // -------------------------------------------------------------------------------- |
| 5391 | 5391 | |
@@ -5401,67 +5401,67 @@ discard block |
||
| 5401 | 5401 | // -------------------------------------------------------------------------------- |
| 5402 | 5402 | function PclZipUtilPathReduction($p_dir) |
| 5403 | 5403 | { |
| 5404 | - $v_result = ""; |
|
| 5405 | - |
|
| 5406 | - // ----- Look for not empty path |
|
| 5407 | - if ($p_dir != "") { |
|
| 5408 | - // ----- Explode path by directory names |
|
| 5409 | - $v_list = explode("/", $p_dir); |
|
| 5410 | - |
|
| 5411 | - // ----- Study directories from last to first |
|
| 5412 | - $v_skip = 0; |
|
| 5413 | - for ($i=sizeof($v_list)-1; $i>=0; $i--) { |
|
| 5414 | - // ----- Look for current path |
|
| 5415 | - if ($v_list[$i] == ".") { |
|
| 5416 | - // ----- Ignore this directory |
|
| 5417 | - // Should be the first $i=0, but no check is done |
|
| 5418 | - } |
|
| 5419 | - else if ($v_list[$i] == "..") { |
|
| 5404 | + $v_result = ""; |
|
| 5405 | + |
|
| 5406 | + // ----- Look for not empty path |
|
| 5407 | + if ($p_dir != "") { |
|
| 5408 | + // ----- Explode path by directory names |
|
| 5409 | + $v_list = explode("/", $p_dir); |
|
| 5410 | + |
|
| 5411 | + // ----- Study directories from last to first |
|
| 5412 | + $v_skip = 0; |
|
| 5413 | + for ($i=sizeof($v_list)-1; $i>=0; $i--) { |
|
| 5414 | + // ----- Look for current path |
|
| 5415 | + if ($v_list[$i] == ".") { |
|
| 5416 | + // ----- Ignore this directory |
|
| 5417 | + // Should be the first $i=0, but no check is done |
|
| 5418 | + } |
|
| 5419 | + else if ($v_list[$i] == "..") { |
|
| 5420 | 5420 | $v_skip++; |
| 5421 | - } |
|
| 5422 | - else if ($v_list[$i] == "") { |
|
| 5421 | + } |
|
| 5422 | + else if ($v_list[$i] == "") { |
|
| 5423 | 5423 | // ----- First '/' i.e. root slash |
| 5424 | 5424 | if ($i == 0) { |
| 5425 | - $v_result = "/".$v_result; |
|
| 5426 | - if ($v_skip > 0) { |
|
| 5427 | - // ----- It is an invalid path, so the path is not modified |
|
| 5428 | - // TBC |
|
| 5429 | - $v_result = $p_dir; |
|
| 5430 | - $v_skip = 0; |
|
| 5431 | - } |
|
| 5425 | + $v_result = "/".$v_result; |
|
| 5426 | + if ($v_skip > 0) { |
|
| 5427 | + // ----- It is an invalid path, so the path is not modified |
|
| 5428 | + // TBC |
|
| 5429 | + $v_result = $p_dir; |
|
| 5430 | + $v_skip = 0; |
|
| 5431 | + } |
|
| 5432 | 5432 | } |
| 5433 | 5433 | // ----- Last '/' i.e. indicates a directory |
| 5434 | 5434 | else if ($i == (sizeof($v_list)-1)) { |
| 5435 | - $v_result = $v_list[$i]; |
|
| 5435 | + $v_result = $v_list[$i]; |
|
| 5436 | 5436 | } |
| 5437 | 5437 | // ----- Double '/' inside the path |
| 5438 | 5438 | else { |
| 5439 | - // ----- Ignore only the double '//' in path, |
|
| 5440 | - // but not the first and last '/' |
|
| 5439 | + // ----- Ignore only the double '//' in path, |
|
| 5440 | + // but not the first and last '/' |
|
| 5441 | 5441 | } |
| 5442 | - } |
|
| 5443 | - else { |
|
| 5442 | + } |
|
| 5443 | + else { |
|
| 5444 | 5444 | // ----- Look for item to skip |
| 5445 | 5445 | if ($v_skip > 0) { |
| 5446 | - $v_skip--; |
|
| 5446 | + $v_skip--; |
|
| 5447 | 5447 | } |
| 5448 | 5448 | else { |
| 5449 | - $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); |
|
| 5449 | + $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); |
|
| 5450 | 5450 | } |
| 5451 | - } |
|
| 5452 | - } |
|
| 5451 | + } |
|
| 5452 | + } |
|
| 5453 | 5453 | |
| 5454 | - // ----- Look for skip |
|
| 5455 | - if ($v_skip > 0) { |
|
| 5456 | - while ($v_skip > 0) { |
|
| 5457 | - $v_result = '../'.$v_result; |
|
| 5458 | - $v_skip--; |
|
| 5459 | - } |
|
| 5460 | - } |
|
| 5461 | - } |
|
| 5454 | + // ----- Look for skip |
|
| 5455 | + if ($v_skip > 0) { |
|
| 5456 | + while ($v_skip > 0) { |
|
| 5457 | + $v_result = '../'.$v_result; |
|
| 5458 | + $v_skip--; |
|
| 5459 | + } |
|
| 5460 | + } |
|
| 5461 | + } |
|
| 5462 | 5462 | |
| 5463 | - // ----- Return |
|
| 5464 | - return $v_result; |
|
| 5463 | + // ----- Return |
|
| 5464 | + return $v_result; |
|
| 5465 | 5465 | } |
| 5466 | 5466 | // -------------------------------------------------------------------------------- |
| 5467 | 5467 | |
@@ -5482,67 +5482,67 @@ discard block |
||
| 5482 | 5482 | // -------------------------------------------------------------------------------- |
| 5483 | 5483 | function PclZipUtilPathInclusion($p_dir, $p_path) |
| 5484 | 5484 | { |
| 5485 | - $v_result = 1; |
|
| 5485 | + $v_result = 1; |
|
| 5486 | 5486 | |
| 5487 | - // ----- Look for path beginning by ./ |
|
| 5488 | - if ( ($p_dir == '.') |
|
| 5489 | - || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { |
|
| 5490 | - $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); |
|
| 5491 | - } |
|
| 5492 | - if ( ($p_path == '.') |
|
| 5493 | - || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) { |
|
| 5494 | - $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); |
|
| 5495 | - } |
|
| 5487 | + // ----- Look for path beginning by ./ |
|
| 5488 | + if ( ($p_dir == '.') |
|
| 5489 | + || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { |
|
| 5490 | + $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); |
|
| 5491 | + } |
|
| 5492 | + if ( ($p_path == '.') |
|
| 5493 | + || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) { |
|
| 5494 | + $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); |
|
| 5495 | + } |
|
| 5496 | 5496 | |
| 5497 | - // ----- Explode dir and path by directory separator |
|
| 5498 | - $v_list_dir = explode("/", $p_dir); |
|
| 5499 | - $v_list_dir_size = sizeof($v_list_dir); |
|
| 5500 | - $v_list_path = explode("/", $p_path); |
|
| 5501 | - $v_list_path_size = sizeof($v_list_path); |
|
| 5502 | - |
|
| 5503 | - // ----- Study directories paths |
|
| 5504 | - $i = 0; |
|
| 5505 | - $j = 0; |
|
| 5506 | - while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) { |
|
| 5507 | - |
|
| 5508 | - // ----- Look for empty dir (path reduction) |
|
| 5509 | - if ($v_list_dir[$i] == '') { |
|
| 5510 | - $i++; |
|
| 5511 | - continue; |
|
| 5512 | - } |
|
| 5513 | - if ($v_list_path[$j] == '') { |
|
| 5514 | - $j++; |
|
| 5515 | - continue; |
|
| 5516 | - } |
|
| 5497 | + // ----- Explode dir and path by directory separator |
|
| 5498 | + $v_list_dir = explode("/", $p_dir); |
|
| 5499 | + $v_list_dir_size = sizeof($v_list_dir); |
|
| 5500 | + $v_list_path = explode("/", $p_path); |
|
| 5501 | + $v_list_path_size = sizeof($v_list_path); |
|
| 5502 | + |
|
| 5503 | + // ----- Study directories paths |
|
| 5504 | + $i = 0; |
|
| 5505 | + $j = 0; |
|
| 5506 | + while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) { |
|
| 5507 | + |
|
| 5508 | + // ----- Look for empty dir (path reduction) |
|
| 5509 | + if ($v_list_dir[$i] == '') { |
|
| 5510 | + $i++; |
|
| 5511 | + continue; |
|
| 5512 | + } |
|
| 5513 | + if ($v_list_path[$j] == '') { |
|
| 5514 | + $j++; |
|
| 5515 | + continue; |
|
| 5516 | + } |
|
| 5517 | 5517 | |
| 5518 | - // ----- Compare the items |
|
| 5519 | - if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { |
|
| 5520 | - $v_result = 0; |
|
| 5521 | - } |
|
| 5518 | + // ----- Compare the items |
|
| 5519 | + if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { |
|
| 5520 | + $v_result = 0; |
|
| 5521 | + } |
|
| 5522 | 5522 | |
| 5523 | - // ----- Next items |
|
| 5524 | - $i++; |
|
| 5525 | - $j++; |
|
| 5526 | - } |
|
| 5523 | + // ----- Next items |
|
| 5524 | + $i++; |
|
| 5525 | + $j++; |
|
| 5526 | + } |
|
| 5527 | 5527 | |
| 5528 | - // ----- Look if everything seems to be the same |
|
| 5529 | - if ($v_result) { |
|
| 5530 | - // ----- Skip all the empty items |
|
| 5531 | - while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; |
|
| 5532 | - while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; |
|
| 5528 | + // ----- Look if everything seems to be the same |
|
| 5529 | + if ($v_result) { |
|
| 5530 | + // ----- Skip all the empty items |
|
| 5531 | + while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; |
|
| 5532 | + while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; |
|
| 5533 | 5533 | |
| 5534 | - if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { |
|
| 5535 | - // ----- There are exactly the same |
|
| 5536 | - $v_result = 2; |
|
| 5537 | - } |
|
| 5538 | - else if ($i < $v_list_dir_size) { |
|
| 5539 | - // ----- The path is shorter than the dir |
|
| 5540 | - $v_result = 0; |
|
| 5541 | - } |
|
| 5542 | - } |
|
| 5534 | + if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { |
|
| 5535 | + // ----- There are exactly the same |
|
| 5536 | + $v_result = 2; |
|
| 5537 | + } |
|
| 5538 | + else if ($i < $v_list_dir_size) { |
|
| 5539 | + // ----- The path is shorter than the dir |
|
| 5540 | + $v_result = 0; |
|
| 5541 | + } |
|
| 5542 | + } |
|
| 5543 | 5543 | |
| 5544 | - // ----- Return |
|
| 5545 | - return $v_result; |
|
| 5544 | + // ----- Return |
|
| 5545 | + return $v_result; |
|
| 5546 | 5546 | } |
| 5547 | 5547 | // -------------------------------------------------------------------------------- |
| 5548 | 5548 | |
@@ -5559,51 +5559,51 @@ discard block |
||
| 5559 | 5559 | // -------------------------------------------------------------------------------- |
| 5560 | 5560 | function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) |
| 5561 | 5561 | { |
| 5562 | - $v_result = 1; |
|
| 5563 | - |
|
| 5564 | - if ($p_mode==0) |
|
| 5565 | - { |
|
| 5566 | - while ($p_size != 0) |
|
| 5567 | - { |
|
| 5568 | - $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5569 | - $v_buffer = @fread($p_src, $v_read_size); |
|
| 5570 | - @fwrite($p_dest, $v_buffer, $v_read_size); |
|
| 5571 | - $p_size -= $v_read_size; |
|
| 5572 | - } |
|
| 5573 | - } |
|
| 5574 | - else if ($p_mode==1) |
|
| 5575 | - { |
|
| 5576 | - while ($p_size != 0) |
|
| 5577 | - { |
|
| 5578 | - $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5579 | - $v_buffer = @gzread($p_src, $v_read_size); |
|
| 5580 | - @fwrite($p_dest, $v_buffer, $v_read_size); |
|
| 5581 | - $p_size -= $v_read_size; |
|
| 5582 | - } |
|
| 5583 | - } |
|
| 5584 | - else if ($p_mode==2) |
|
| 5585 | - { |
|
| 5586 | - while ($p_size != 0) |
|
| 5587 | - { |
|
| 5588 | - $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5589 | - $v_buffer = @fread($p_src, $v_read_size); |
|
| 5590 | - @gzwrite($p_dest, $v_buffer, $v_read_size); |
|
| 5591 | - $p_size -= $v_read_size; |
|
| 5592 | - } |
|
| 5593 | - } |
|
| 5594 | - else if ($p_mode==3) |
|
| 5595 | - { |
|
| 5596 | - while ($p_size != 0) |
|
| 5597 | - { |
|
| 5598 | - $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5599 | - $v_buffer = @gzread($p_src, $v_read_size); |
|
| 5600 | - @gzwrite($p_dest, $v_buffer, $v_read_size); |
|
| 5601 | - $p_size -= $v_read_size; |
|
| 5602 | - } |
|
| 5603 | - } |
|
| 5562 | + $v_result = 1; |
|
| 5563 | + |
|
| 5564 | + if ($p_mode==0) |
|
| 5565 | + { |
|
| 5566 | + while ($p_size != 0) |
|
| 5567 | + { |
|
| 5568 | + $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5569 | + $v_buffer = @fread($p_src, $v_read_size); |
|
| 5570 | + @fwrite($p_dest, $v_buffer, $v_read_size); |
|
| 5571 | + $p_size -= $v_read_size; |
|
| 5572 | + } |
|
| 5573 | + } |
|
| 5574 | + else if ($p_mode==1) |
|
| 5575 | + { |
|
| 5576 | + while ($p_size != 0) |
|
| 5577 | + { |
|
| 5578 | + $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5579 | + $v_buffer = @gzread($p_src, $v_read_size); |
|
| 5580 | + @fwrite($p_dest, $v_buffer, $v_read_size); |
|
| 5581 | + $p_size -= $v_read_size; |
|
| 5582 | + } |
|
| 5583 | + } |
|
| 5584 | + else if ($p_mode==2) |
|
| 5585 | + { |
|
| 5586 | + while ($p_size != 0) |
|
| 5587 | + { |
|
| 5588 | + $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5589 | + $v_buffer = @fread($p_src, $v_read_size); |
|
| 5590 | + @gzwrite($p_dest, $v_buffer, $v_read_size); |
|
| 5591 | + $p_size -= $v_read_size; |
|
| 5592 | + } |
|
| 5593 | + } |
|
| 5594 | + else if ($p_mode==3) |
|
| 5595 | + { |
|
| 5596 | + while ($p_size != 0) |
|
| 5597 | + { |
|
| 5598 | + $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5599 | + $v_buffer = @gzread($p_src, $v_read_size); |
|
| 5600 | + @gzwrite($p_dest, $v_buffer, $v_read_size); |
|
| 5601 | + $p_size -= $v_read_size; |
|
| 5602 | + } |
|
| 5603 | + } |
|
| 5604 | 5604 | |
| 5605 | - // ----- Return |
|
| 5606 | - return $v_result; |
|
| 5605 | + // ----- Return |
|
| 5606 | + return $v_result; |
|
| 5607 | 5607 | } |
| 5608 | 5608 | // -------------------------------------------------------------------------------- |
| 5609 | 5609 | |
@@ -5621,22 +5621,22 @@ discard block |
||
| 5621 | 5621 | // -------------------------------------------------------------------------------- |
| 5622 | 5622 | function PclZipUtilRename($p_src, $p_dest) |
| 5623 | 5623 | { |
| 5624 | - $v_result = 1; |
|
| 5624 | + $v_result = 1; |
|
| 5625 | 5625 | |
| 5626 | - // ----- Try to rename the files |
|
| 5627 | - if (!@rename($p_src, $p_dest)) { |
|
| 5626 | + // ----- Try to rename the files |
|
| 5627 | + if (!@rename($p_src, $p_dest)) { |
|
| 5628 | 5628 | |
| 5629 | - // ----- Try to copy & unlink the src |
|
| 5630 | - if (!@copy($p_src, $p_dest)) { |
|
| 5631 | - $v_result = 0; |
|
| 5632 | - } |
|
| 5633 | - else if (!@unlink($p_src)) { |
|
| 5634 | - $v_result = 0; |
|
| 5635 | - } |
|
| 5636 | - } |
|
| 5629 | + // ----- Try to copy & unlink the src |
|
| 5630 | + if (!@copy($p_src, $p_dest)) { |
|
| 5631 | + $v_result = 0; |
|
| 5632 | + } |
|
| 5633 | + else if (!@unlink($p_src)) { |
|
| 5634 | + $v_result = 0; |
|
| 5635 | + } |
|
| 5636 | + } |
|
| 5637 | 5637 | |
| 5638 | - // ----- Return |
|
| 5639 | - return $v_result; |
|
| 5638 | + // ----- Return |
|
| 5639 | + return $v_result; |
|
| 5640 | 5640 | } |
| 5641 | 5641 | // -------------------------------------------------------------------------------- |
| 5642 | 5642 | |
@@ -5652,20 +5652,20 @@ discard block |
||
| 5652 | 5652 | function PclZipUtilOptionText($p_option) |
| 5653 | 5653 | { |
| 5654 | 5654 | |
| 5655 | - $v_list = get_defined_constants(); |
|
| 5656 | - for (reset($v_list); $v_key = key($v_list); next($v_list)) { |
|
| 5657 | - $v_prefix = substr($v_key, 0, 10); |
|
| 5658 | - if (( ($v_prefix == 'PCLZIP_OPT') |
|
| 5659 | - || ($v_prefix == 'PCLZIP_CB_') |
|
| 5660 | - || ($v_prefix == 'PCLZIP_ATT')) |
|
| 5661 | - && ($v_list[$v_key] == $p_option)) { |
|
| 5662 | - return $v_key; |
|
| 5663 | - } |
|
| 5664 | - } |
|
| 5655 | + $v_list = get_defined_constants(); |
|
| 5656 | + for (reset($v_list); $v_key = key($v_list); next($v_list)) { |
|
| 5657 | + $v_prefix = substr($v_key, 0, 10); |
|
| 5658 | + if (( ($v_prefix == 'PCLZIP_OPT') |
|
| 5659 | + || ($v_prefix == 'PCLZIP_CB_') |
|
| 5660 | + || ($v_prefix == 'PCLZIP_ATT')) |
|
| 5661 | + && ($v_list[$v_key] == $p_option)) { |
|
| 5662 | + return $v_key; |
|
| 5663 | + } |
|
| 5664 | + } |
|
| 5665 | 5665 | |
| 5666 | - $v_result = 'Unknown'; |
|
| 5666 | + $v_result = 'Unknown'; |
|
| 5667 | 5667 | |
| 5668 | - return $v_result; |
|
| 5668 | + return $v_result; |
|
| 5669 | 5669 | } |
| 5670 | 5670 | // -------------------------------------------------------------------------------- |
| 5671 | 5671 | |
@@ -5682,17 +5682,17 @@ discard block |
||
| 5682 | 5682 | // -------------------------------------------------------------------------------- |
| 5683 | 5683 | function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true) |
| 5684 | 5684 | { |
| 5685 | - if (stristr(php_uname(), 'windows')) { |
|
| 5686 | - // ----- Look for potential disk letter |
|
| 5687 | - if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { |
|
| 5688 | - $p_path = substr($p_path, $v_position+1); |
|
| 5689 | - } |
|
| 5690 | - // ----- Change potential windows directory separator |
|
| 5691 | - if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
| 5692 | - $p_path = strtr($p_path, '\\', '/'); |
|
| 5693 | - } |
|
| 5694 | - } |
|
| 5695 | - return $p_path; |
|
| 5685 | + if (stristr(php_uname(), 'windows')) { |
|
| 5686 | + // ----- Look for potential disk letter |
|
| 5687 | + if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { |
|
| 5688 | + $p_path = substr($p_path, $v_position+1); |
|
| 5689 | + } |
|
| 5690 | + // ----- Change potential windows directory separator |
|
| 5691 | + if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
| 5692 | + $p_path = strtr($p_path, '\\', '/'); |
|
| 5693 | + } |
|
| 5694 | + } |
|
| 5695 | + return $p_path; |
|
| 5696 | 5696 | } |
| 5697 | 5697 | // -------------------------------------------------------------------------------- |
| 5698 | 5698 | |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | // -------------------------------------------------------------------------------- |
| 3 | 3 | // PhpConcept Library - Zip Module 2.8.2 |
| 4 | 4 | // -------------------------------------------------------------------------------- |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | // ----- Constants |
| 29 | 29 | if (!defined('PCLZIP_READ_BLOCK_SIZE')) { |
| 30 | - define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); |
|
| 30 | + define('PCLZIP_READ_BLOCK_SIZE', 2048); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | // ----- File list separator |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | //define( 'PCLZIP_SEPARATOR', ' ' ); |
| 42 | 42 | // Recommanded values for smart separation of filenames. |
| 43 | 43 | if (!defined('PCLZIP_SEPARATOR')) { |
| 44 | - define( 'PCLZIP_SEPARATOR', ',' ); |
|
| 44 | + define('PCLZIP_SEPARATOR', ','); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // ----- Error configuration |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | // you must ensure that you have included PclError library. |
| 51 | 51 | // [2,...] : reserved for futur use |
| 52 | 52 | if (!defined('PCLZIP_ERROR_EXTERNAL')) { |
| 53 | - define( 'PCLZIP_ERROR_EXTERNAL', 0 ); |
|
| 53 | + define('PCLZIP_ERROR_EXTERNAL', 0); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // ----- Optional static temporary directory |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' ); |
| 64 | 64 | // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' ); |
| 65 | 65 | if (!defined('PCLZIP_TEMPORARY_DIR')) { |
| 66 | - define( 'PCLZIP_TEMPORARY_DIR', '' ); |
|
| 66 | + define('PCLZIP_TEMPORARY_DIR', ''); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | // ----- Optional threshold ratio for use of temporary files |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | // Samples : |
| 76 | 76 | // define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 ); |
| 77 | 77 | if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) { |
| 78 | - define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 ); |
|
| 78 | + define('PCLZIP_TEMPORARY_FILE_RATIO', 0.47); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // -------------------------------------------------------------------------------- |
@@ -100,72 +100,72 @@ discard block |
||
| 100 | 100 | // -12 : Unable to rename file (rename) |
| 101 | 101 | // -13 : Invalid header checksum |
| 102 | 102 | // -14 : Invalid archive size |
| 103 | - define( 'PCLZIP_ERR_USER_ABORTED', 2 ); |
|
| 104 | - define( 'PCLZIP_ERR_NO_ERROR', 0 ); |
|
| 105 | - define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 ); |
|
| 106 | - define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 ); |
|
| 107 | - define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 ); |
|
| 108 | - define( 'PCLZIP_ERR_MISSING_FILE', -4 ); |
|
| 109 | - define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 ); |
|
| 110 | - define( 'PCLZIP_ERR_INVALID_ZIP', -6 ); |
|
| 111 | - define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 ); |
|
| 112 | - define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 ); |
|
| 113 | - define( 'PCLZIP_ERR_BAD_EXTENSION', -9 ); |
|
| 114 | - define( 'PCLZIP_ERR_BAD_FORMAT', -10 ); |
|
| 115 | - define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 ); |
|
| 116 | - define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 ); |
|
| 117 | - define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 ); |
|
| 118 | - define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 ); |
|
| 119 | - define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 ); |
|
| 120 | - define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 ); |
|
| 121 | - define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 ); |
|
| 122 | - define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 ); |
|
| 123 | - define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 ); |
|
| 124 | - define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 ); |
|
| 125 | - define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 ); |
|
| 103 | + define('PCLZIP_ERR_USER_ABORTED', 2); |
|
| 104 | + define('PCLZIP_ERR_NO_ERROR', 0); |
|
| 105 | + define('PCLZIP_ERR_WRITE_OPEN_FAIL', -1); |
|
| 106 | + define('PCLZIP_ERR_READ_OPEN_FAIL', -2); |
|
| 107 | + define('PCLZIP_ERR_INVALID_PARAMETER', -3); |
|
| 108 | + define('PCLZIP_ERR_MISSING_FILE', -4); |
|
| 109 | + define('PCLZIP_ERR_FILENAME_TOO_LONG', -5); |
|
| 110 | + define('PCLZIP_ERR_INVALID_ZIP', -6); |
|
| 111 | + define('PCLZIP_ERR_BAD_EXTRACTED_FILE', -7); |
|
| 112 | + define('PCLZIP_ERR_DIR_CREATE_FAIL', -8); |
|
| 113 | + define('PCLZIP_ERR_BAD_EXTENSION', -9); |
|
| 114 | + define('PCLZIP_ERR_BAD_FORMAT', -10); |
|
| 115 | + define('PCLZIP_ERR_DELETE_FILE_FAIL', -11); |
|
| 116 | + define('PCLZIP_ERR_RENAME_FILE_FAIL', -12); |
|
| 117 | + define('PCLZIP_ERR_BAD_CHECKSUM', -13); |
|
| 118 | + define('PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14); |
|
| 119 | + define('PCLZIP_ERR_MISSING_OPTION_VALUE', -15); |
|
| 120 | + define('PCLZIP_ERR_INVALID_OPTION_VALUE', -16); |
|
| 121 | + define('PCLZIP_ERR_ALREADY_A_DIRECTORY', -17); |
|
| 122 | + define('PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18); |
|
| 123 | + define('PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19); |
|
| 124 | + define('PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20); |
|
| 125 | + define('PCLZIP_ERR_DIRECTORY_RESTRICTION', -21); |
|
| 126 | 126 | |
| 127 | 127 | // ----- Options values |
| 128 | - define( 'PCLZIP_OPT_PATH', 77001 ); |
|
| 129 | - define( 'PCLZIP_OPT_ADD_PATH', 77002 ); |
|
| 130 | - define( 'PCLZIP_OPT_REMOVE_PATH', 77003 ); |
|
| 131 | - define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 ); |
|
| 132 | - define( 'PCLZIP_OPT_SET_CHMOD', 77005 ); |
|
| 133 | - define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 ); |
|
| 134 | - define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 ); |
|
| 135 | - define( 'PCLZIP_OPT_BY_NAME', 77008 ); |
|
| 136 | - define( 'PCLZIP_OPT_BY_INDEX', 77009 ); |
|
| 137 | - define( 'PCLZIP_OPT_BY_EREG', 77010 ); |
|
| 138 | - define( 'PCLZIP_OPT_BY_PREG', 77011 ); |
|
| 139 | - define( 'PCLZIP_OPT_COMMENT', 77012 ); |
|
| 140 | - define( 'PCLZIP_OPT_ADD_COMMENT', 77013 ); |
|
| 141 | - define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 ); |
|
| 142 | - define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 ); |
|
| 143 | - define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 ); |
|
| 144 | - define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 ); |
|
| 128 | + define('PCLZIP_OPT_PATH', 77001); |
|
| 129 | + define('PCLZIP_OPT_ADD_PATH', 77002); |
|
| 130 | + define('PCLZIP_OPT_REMOVE_PATH', 77003); |
|
| 131 | + define('PCLZIP_OPT_REMOVE_ALL_PATH', 77004); |
|
| 132 | + define('PCLZIP_OPT_SET_CHMOD', 77005); |
|
| 133 | + define('PCLZIP_OPT_EXTRACT_AS_STRING', 77006); |
|
| 134 | + define('PCLZIP_OPT_NO_COMPRESSION', 77007); |
|
| 135 | + define('PCLZIP_OPT_BY_NAME', 77008); |
|
| 136 | + define('PCLZIP_OPT_BY_INDEX', 77009); |
|
| 137 | + define('PCLZIP_OPT_BY_EREG', 77010); |
|
| 138 | + define('PCLZIP_OPT_BY_PREG', 77011); |
|
| 139 | + define('PCLZIP_OPT_COMMENT', 77012); |
|
| 140 | + define('PCLZIP_OPT_ADD_COMMENT', 77013); |
|
| 141 | + define('PCLZIP_OPT_PREPEND_COMMENT', 77014); |
|
| 142 | + define('PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015); |
|
| 143 | + define('PCLZIP_OPT_REPLACE_NEWER', 77016); |
|
| 144 | + define('PCLZIP_OPT_STOP_ON_ERROR', 77017); |
|
| 145 | 145 | // Having big trouble with crypt. Need to multiply 2 long int |
| 146 | 146 | // which is not correctly supported by PHP ... |
| 147 | 147 | //define( 'PCLZIP_OPT_CRYPT', 77018 ); |
| 148 | - define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); |
|
| 149 | - define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 ); |
|
| 150 | - define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias |
|
| 151 | - define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 ); |
|
| 152 | - define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias |
|
| 153 | - define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 ); |
|
| 154 | - define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias |
|
| 148 | + define('PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019); |
|
| 149 | + define('PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020); |
|
| 150 | + define('PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020); // alias |
|
| 151 | + define('PCLZIP_OPT_TEMP_FILE_ON', 77021); |
|
| 152 | + define('PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021); // alias |
|
| 153 | + define('PCLZIP_OPT_TEMP_FILE_OFF', 77022); |
|
| 154 | + define('PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022); // alias |
|
| 155 | 155 | |
| 156 | 156 | // ----- File description attributes |
| 157 | - define( 'PCLZIP_ATT_FILE_NAME', 79001 ); |
|
| 158 | - define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 ); |
|
| 159 | - define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 ); |
|
| 160 | - define( 'PCLZIP_ATT_FILE_MTIME', 79004 ); |
|
| 161 | - define( 'PCLZIP_ATT_FILE_CONTENT', 79005 ); |
|
| 162 | - define( 'PCLZIP_ATT_FILE_COMMENT', 79006 ); |
|
| 157 | + define('PCLZIP_ATT_FILE_NAME', 79001); |
|
| 158 | + define('PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002); |
|
| 159 | + define('PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003); |
|
| 160 | + define('PCLZIP_ATT_FILE_MTIME', 79004); |
|
| 161 | + define('PCLZIP_ATT_FILE_CONTENT', 79005); |
|
| 162 | + define('PCLZIP_ATT_FILE_COMMENT', 79006); |
|
| 163 | 163 | |
| 164 | 164 | // ----- Call backs values |
| 165 | - define( 'PCLZIP_CB_PRE_EXTRACT', 78001 ); |
|
| 166 | - define( 'PCLZIP_CB_POST_EXTRACT', 78002 ); |
|
| 167 | - define( 'PCLZIP_CB_PRE_ADD', 78003 ); |
|
| 168 | - define( 'PCLZIP_CB_POST_ADD', 78004 ); |
|
| 165 | + define('PCLZIP_CB_PRE_EXTRACT', 78001); |
|
| 166 | + define('PCLZIP_CB_POST_EXTRACT', 78002); |
|
| 167 | + define('PCLZIP_CB_PRE_ADD', 78003); |
|
| 168 | + define('PCLZIP_CB_POST_ADD', 78004); |
|
| 169 | 169 | /* For futur use |
| 170 | 170 | define( 'PCLZIP_CB_PRE_LIST', 78005 ); |
| 171 | 171 | define( 'PCLZIP_CB_POST_LIST', 78006 ); |
@@ -220,9 +220,9 @@ discard block |
||
| 220 | 220 | { |
| 221 | 221 | if (!function_exists('gzopen') |
| 222 | 222 | && function_exists('gzopen64')) { |
| 223 | - function gzopen($filename , $mode = 'r', $use_include_path = 0 ) |
|
| 223 | + function gzopen($filename, $mode = 'r', $use_include_path = 0) |
|
| 224 | 224 | { |
| 225 | - return gzopen64($filename , $mode, $use_include_path); |
|
| 225 | + return gzopen64($filename, $mode, $use_include_path); |
|
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | } |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | // -------------------------------------------------------------------------------- |
| 277 | 277 | function create($p_filelist) |
| 278 | 278 | { |
| 279 | - $v_result=1; |
|
| 279 | + $v_result = 1; |
|
| 280 | 280 | |
| 281 | 281 | // ----- Reset the error handler |
| 282 | 282 | $this->privErrorReset(); |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | |
| 303 | 303 | // ----- Parse the options |
| 304 | 304 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 305 | - array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 305 | + array(PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 306 | 306 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
| 307 | 307 | PCLZIP_OPT_ADD_PATH => 'optional', |
| 308 | 308 | PCLZIP_CB_PRE_ADD => 'optional', |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | |
| 389 | 389 | // ----- For each file in the list check the attributes |
| 390 | 390 | $v_supported_attributes |
| 391 | - = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' |
|
| 391 | + = array(PCLZIP_ATT_FILE_NAME => 'mandatory' |
|
| 392 | 392 | ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
| 393 | 393 | ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
| 394 | 394 | ,PCLZIP_ATT_FILE_MTIME => 'optional' |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | // -------------------------------------------------------------------------------- |
| 460 | 460 | function add($p_filelist) |
| 461 | 461 | { |
| 462 | - $v_result=1; |
|
| 462 | + $v_result = 1; |
|
| 463 | 463 | |
| 464 | 464 | // ----- Reset the error handler |
| 465 | 465 | $this->privErrorReset(); |
@@ -485,7 +485,7 @@ discard block |
||
| 485 | 485 | |
| 486 | 486 | // ----- Parse the options |
| 487 | 487 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 488 | - array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 488 | + array(PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 489 | 489 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
| 490 | 490 | PCLZIP_OPT_ADD_PATH => 'optional', |
| 491 | 491 | PCLZIP_CB_PRE_ADD => 'optional', |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | |
| 559 | 559 | // ----- Invalid variable type for $p_filelist |
| 560 | 560 | else { |
| 561 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); |
|
| 561 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '" . gettype($p_filelist) . "' for p_filelist"); |
|
| 562 | 562 | return 0; |
| 563 | 563 | } |
| 564 | 564 | |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | |
| 572 | 572 | // ----- For each file in the list check the attributes |
| 573 | 573 | $v_supported_attributes |
| 574 | - = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' |
|
| 574 | + = array(PCLZIP_ATT_FILE_NAME => 'mandatory' |
|
| 575 | 575 | ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
| 576 | 576 | ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
| 577 | 577 | ,PCLZIP_ATT_FILE_MTIME => 'optional' |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | // -------------------------------------------------------------------------------- |
| 649 | 649 | function listContent() |
| 650 | 650 | { |
| 651 | - $v_result=1; |
|
| 651 | + $v_result = 1; |
|
| 652 | 652 | |
| 653 | 653 | // ----- Reset the error handler |
| 654 | 654 | $this->privErrorReset(); |
@@ -705,7 +705,7 @@ discard block |
||
| 705 | 705 | // -------------------------------------------------------------------------------- |
| 706 | 706 | function extract() |
| 707 | 707 | { |
| 708 | - $v_result=1; |
|
| 708 | + $v_result = 1; |
|
| 709 | 709 | |
| 710 | 710 | // ----- Reset the error handler |
| 711 | 711 | $this->privErrorReset(); |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | |
| 739 | 739 | // ----- Parse the options |
| 740 | 740 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 741 | - array (PCLZIP_OPT_PATH => 'optional', |
|
| 741 | + array(PCLZIP_OPT_PATH => 'optional', |
|
| 742 | 742 | PCLZIP_OPT_REMOVE_PATH => 'optional', |
| 743 | 743 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
| 744 | 744 | PCLZIP_OPT_ADD_PATH => 'optional', |
@@ -862,7 +862,7 @@ discard block |
||
| 862 | 862 | //function extractByIndex($p_index, options...) |
| 863 | 863 | function extractByIndex($p_index) |
| 864 | 864 | { |
| 865 | - $v_result=1; |
|
| 865 | + $v_result = 1; |
|
| 866 | 866 | |
| 867 | 867 | // ----- Reset the error handler |
| 868 | 868 | $this->privErrorReset(); |
@@ -899,7 +899,7 @@ discard block |
||
| 899 | 899 | |
| 900 | 900 | // ----- Parse the options |
| 901 | 901 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 902 | - array (PCLZIP_OPT_PATH => 'optional', |
|
| 902 | + array(PCLZIP_OPT_PATH => 'optional', |
|
| 903 | 903 | PCLZIP_OPT_REMOVE_PATH => 'optional', |
| 904 | 904 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
| 905 | 905 | PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', |
@@ -969,10 +969,10 @@ discard block |
||
| 969 | 969 | // ----- Trick |
| 970 | 970 | // Here I want to reuse extractByRule(), so I need to parse the $p_index |
| 971 | 971 | // with privParseOptions() |
| 972 | - $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index); |
|
| 972 | + $v_arg_trick = array(PCLZIP_OPT_BY_INDEX, $p_index); |
|
| 973 | 973 | $v_options_trick = array(); |
| 974 | 974 | $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, |
| 975 | - array (PCLZIP_OPT_BY_INDEX => 'optional' )); |
|
| 975 | + array(PCLZIP_OPT_BY_INDEX => 'optional')); |
|
| 976 | 976 | if ($v_result != 1) { |
| 977 | 977 | return 0; |
| 978 | 978 | } |
@@ -1011,7 +1011,7 @@ discard block |
||
| 1011 | 1011 | // -------------------------------------------------------------------------------- |
| 1012 | 1012 | function delete() |
| 1013 | 1013 | { |
| 1014 | - $v_result=1; |
|
| 1014 | + $v_result = 1; |
|
| 1015 | 1015 | |
| 1016 | 1016 | // ----- Reset the error handler |
| 1017 | 1017 | $this->privErrorReset(); |
@@ -1034,10 +1034,10 @@ discard block |
||
| 1034 | 1034 | |
| 1035 | 1035 | // ----- Parse the options |
| 1036 | 1036 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 1037 | - array (PCLZIP_OPT_BY_NAME => 'optional', |
|
| 1037 | + array(PCLZIP_OPT_BY_NAME => 'optional', |
|
| 1038 | 1038 | PCLZIP_OPT_BY_EREG => 'optional', |
| 1039 | 1039 | PCLZIP_OPT_BY_PREG => 'optional', |
| 1040 | - PCLZIP_OPT_BY_INDEX => 'optional' )); |
|
| 1040 | + PCLZIP_OPT_BY_INDEX => 'optional')); |
|
| 1041 | 1041 | if ($v_result != 1) { |
| 1042 | 1042 | return 0; |
| 1043 | 1043 | } |
@@ -1122,7 +1122,7 @@ discard block |
||
| 1122 | 1122 | $this->privSwapBackMagicQuotes(); |
| 1123 | 1123 | |
| 1124 | 1124 | // ----- Error log |
| 1125 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); |
|
| 1125 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \'' . $this->zipname . '\' in binary read mode'); |
|
| 1126 | 1126 | |
| 1127 | 1127 | // ----- Return |
| 1128 | 1128 | return 0; |
@@ -1188,7 +1188,7 @@ discard block |
||
| 1188 | 1188 | // TBC : Should also check the archive format |
| 1189 | 1189 | if (!is_file($p_archive)) { |
| 1190 | 1190 | // ----- Error log |
| 1191 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'"); |
|
| 1191 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '" . $p_archive . "'"); |
|
| 1192 | 1192 | $v_result = PCLZIP_ERR_MISSING_FILE; |
| 1193 | 1193 | } |
| 1194 | 1194 | else { |
@@ -1291,9 +1291,9 @@ discard block |
||
| 1291 | 1291 | // Description : |
| 1292 | 1292 | // Parameters : |
| 1293 | 1293 | // -------------------------------------------------------------------------------- |
| 1294 | - function errorName($p_with_code=false) |
|
| 1294 | + function errorName($p_with_code = false) |
|
| 1295 | 1295 | { |
| 1296 | - $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', |
|
| 1296 | + $v_name = array(PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', |
|
| 1297 | 1297 | PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL', |
| 1298 | 1298 | PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL', |
| 1299 | 1299 | PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER', |
@@ -1324,7 +1324,7 @@ discard block |
||
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | if ($p_with_code) { |
| 1327 | - return($v_value.' ('.$this->error_code.')'); |
|
| 1327 | + return($v_value . ' (' . $this->error_code . ')'); |
|
| 1328 | 1328 | } |
| 1329 | 1329 | else { |
| 1330 | 1330 | return($v_value); |
@@ -1337,17 +1337,17 @@ discard block |
||
| 1337 | 1337 | // Description : |
| 1338 | 1338 | // Parameters : |
| 1339 | 1339 | // -------------------------------------------------------------------------------- |
| 1340 | - function errorInfo($p_full=false) |
|
| 1340 | + function errorInfo($p_full = false) |
|
| 1341 | 1341 | { |
| 1342 | 1342 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 1343 | 1343 | return(PclErrorString()); |
| 1344 | 1344 | } |
| 1345 | 1345 | else { |
| 1346 | 1346 | if ($p_full) { |
| 1347 | - return($this->errorName(true)." : ".$this->error_string); |
|
| 1347 | + return($this->errorName(true) . " : " . $this->error_string); |
|
| 1348 | 1348 | } |
| 1349 | 1349 | else { |
| 1350 | - return($this->error_string." [code ".$this->error_code."]"); |
|
| 1350 | + return($this->error_string . " [code " . $this->error_code . "]"); |
|
| 1351 | 1351 | } |
| 1352 | 1352 | } |
| 1353 | 1353 | } |
@@ -1376,7 +1376,7 @@ discard block |
||
| 1376 | 1376 | // true on success, |
| 1377 | 1377 | // false on error, the error code is set. |
| 1378 | 1378 | // -------------------------------------------------------------------------------- |
| 1379 | - function privCheckFormat($p_level=0) |
|
| 1379 | + function privCheckFormat($p_level = 0) |
|
| 1380 | 1380 | { |
| 1381 | 1381 | $v_result = true; |
| 1382 | 1382 | |
@@ -1389,14 +1389,14 @@ discard block |
||
| 1389 | 1389 | // ----- Look if the file exits |
| 1390 | 1390 | if (!is_file($this->zipname)) { |
| 1391 | 1391 | // ----- Error log |
| 1392 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); |
|
| 1392 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '" . $this->zipname . "'"); |
|
| 1393 | 1393 | return(false); |
| 1394 | 1394 | } |
| 1395 | 1395 | |
| 1396 | 1396 | // ----- Check that the file is readeable |
| 1397 | 1397 | if (!is_readable($this->zipname)) { |
| 1398 | 1398 | // ----- Error log |
| 1399 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); |
|
| 1399 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '" . $this->zipname . "'"); |
|
| 1400 | 1400 | return(false); |
| 1401 | 1401 | } |
| 1402 | 1402 | |
@@ -1429,18 +1429,18 @@ discard block |
||
| 1429 | 1429 | // 1 on success. |
| 1430 | 1430 | // 0 on failure. |
| 1431 | 1431 | // -------------------------------------------------------------------------------- |
| 1432 | - function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) |
|
| 1432 | + function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options = false) |
|
| 1433 | 1433 | { |
| 1434 | - $v_result=1; |
|
| 1434 | + $v_result = 1; |
|
| 1435 | 1435 | |
| 1436 | 1436 | // ----- Read the options |
| 1437 | - $i=0; |
|
| 1438 | - while ($i<$p_size) { |
|
| 1437 | + $i = 0; |
|
| 1438 | + while ($i < $p_size) { |
|
| 1439 | 1439 | |
| 1440 | 1440 | // ----- Check if the option is supported |
| 1441 | 1441 | if (!isset($v_requested_options[$p_options_list[$i]])) { |
| 1442 | 1442 | // ----- Error log |
| 1443 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); |
|
| 1443 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '" . $p_options_list[$i] . "' for this method"); |
|
| 1444 | 1444 | |
| 1445 | 1445 | // ----- Return |
| 1446 | 1446 | return PclZip::errorCode(); |
@@ -1453,48 +1453,48 @@ discard block |
||
| 1453 | 1453 | case PCLZIP_OPT_REMOVE_PATH : |
| 1454 | 1454 | case PCLZIP_OPT_ADD_PATH : |
| 1455 | 1455 | // ----- Check the number of parameters |
| 1456 | - if (($i+1) >= $p_size) { |
|
| 1456 | + if (($i + 1) >= $p_size) { |
|
| 1457 | 1457 | // ----- Error log |
| 1458 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1458 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1459 | 1459 | |
| 1460 | 1460 | // ----- Return |
| 1461 | 1461 | return PclZip::errorCode(); |
| 1462 | 1462 | } |
| 1463 | 1463 | |
| 1464 | 1464 | // ----- Get the value |
| 1465 | - $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
|
| 1465 | + $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i + 1], FALSE); |
|
| 1466 | 1466 | $i++; |
| 1467 | 1467 | break; |
| 1468 | 1468 | |
| 1469 | 1469 | case PCLZIP_OPT_TEMP_FILE_THRESHOLD : |
| 1470 | 1470 | // ----- Check the number of parameters |
| 1471 | - if (($i+1) >= $p_size) { |
|
| 1472 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1471 | + if (($i + 1) >= $p_size) { |
|
| 1472 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1473 | 1473 | return PclZip::errorCode(); |
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | 1476 | // ----- Check for incompatible options |
| 1477 | 1477 | if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
| 1478 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
|
| 1478 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '" . PclZipUtilOptionText($p_options_list[$i]) . "' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
|
| 1479 | 1479 | return PclZip::errorCode(); |
| 1480 | 1480 | } |
| 1481 | 1481 | |
| 1482 | 1482 | // ----- Check the value |
| 1483 | - $v_value = $p_options_list[$i+1]; |
|
| 1484 | - if ((!is_integer($v_value)) || ($v_value<0)) { |
|
| 1485 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1483 | + $v_value = $p_options_list[$i + 1]; |
|
| 1484 | + if ((!is_integer($v_value)) || ($v_value < 0)) { |
|
| 1485 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1486 | 1486 | return PclZip::errorCode(); |
| 1487 | 1487 | } |
| 1488 | 1488 | |
| 1489 | 1489 | // ----- Get the value (and convert it in bytes) |
| 1490 | - $v_result_list[$p_options_list[$i]] = $v_value*1048576; |
|
| 1490 | + $v_result_list[$p_options_list[$i]] = $v_value * 1048576; |
|
| 1491 | 1491 | $i++; |
| 1492 | 1492 | break; |
| 1493 | 1493 | |
| 1494 | 1494 | case PCLZIP_OPT_TEMP_FILE_ON : |
| 1495 | 1495 | // ----- Check for incompatible options |
| 1496 | 1496 | if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
| 1497 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
|
| 1497 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '" . PclZipUtilOptionText($p_options_list[$i]) . "' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
|
| 1498 | 1498 | return PclZip::errorCode(); |
| 1499 | 1499 | } |
| 1500 | 1500 | |
@@ -1504,12 +1504,12 @@ discard block |
||
| 1504 | 1504 | case PCLZIP_OPT_TEMP_FILE_OFF : |
| 1505 | 1505 | // ----- Check for incompatible options |
| 1506 | 1506 | if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) { |
| 1507 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'"); |
|
| 1507 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '" . PclZipUtilOptionText($p_options_list[$i]) . "' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'"); |
|
| 1508 | 1508 | return PclZip::errorCode(); |
| 1509 | 1509 | } |
| 1510 | 1510 | // ----- Check for incompatible options |
| 1511 | 1511 | if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { |
| 1512 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'"); |
|
| 1512 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '" . PclZipUtilOptionText($p_options_list[$i]) . "' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'"); |
|
| 1513 | 1513 | return PclZip::errorCode(); |
| 1514 | 1514 | } |
| 1515 | 1515 | |
@@ -1518,18 +1518,18 @@ discard block |
||
| 1518 | 1518 | |
| 1519 | 1519 | case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : |
| 1520 | 1520 | // ----- Check the number of parameters |
| 1521 | - if (($i+1) >= $p_size) { |
|
| 1521 | + if (($i + 1) >= $p_size) { |
|
| 1522 | 1522 | // ----- Error log |
| 1523 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1523 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1524 | 1524 | |
| 1525 | 1525 | // ----- Return |
| 1526 | 1526 | return PclZip::errorCode(); |
| 1527 | 1527 | } |
| 1528 | 1528 | |
| 1529 | 1529 | // ----- Get the value |
| 1530 | - if ( is_string($p_options_list[$i+1]) |
|
| 1531 | - && ($p_options_list[$i+1] != '')) { |
|
| 1532 | - $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
|
| 1530 | + if (is_string($p_options_list[$i + 1]) |
|
| 1531 | + && ($p_options_list[$i + 1] != '')) { |
|
| 1532 | + $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i + 1], FALSE); |
|
| 1533 | 1533 | $i++; |
| 1534 | 1534 | } |
| 1535 | 1535 | else { |
@@ -1539,24 +1539,24 @@ discard block |
||
| 1539 | 1539 | // ----- Look for options that request an array of string for value |
| 1540 | 1540 | case PCLZIP_OPT_BY_NAME : |
| 1541 | 1541 | // ----- Check the number of parameters |
| 1542 | - if (($i+1) >= $p_size) { |
|
| 1542 | + if (($i + 1) >= $p_size) { |
|
| 1543 | 1543 | // ----- Error log |
| 1544 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1544 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1545 | 1545 | |
| 1546 | 1546 | // ----- Return |
| 1547 | 1547 | return PclZip::errorCode(); |
| 1548 | 1548 | } |
| 1549 | 1549 | |
| 1550 | 1550 | // ----- Get the value |
| 1551 | - if (is_string($p_options_list[$i+1])) { |
|
| 1552 | - $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; |
|
| 1551 | + if (is_string($p_options_list[$i + 1])) { |
|
| 1552 | + $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i + 1]; |
|
| 1553 | 1553 | } |
| 1554 | - else if (is_array($p_options_list[$i+1])) { |
|
| 1555 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1554 | + else if (is_array($p_options_list[$i + 1])) { |
|
| 1555 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i + 1]; |
|
| 1556 | 1556 | } |
| 1557 | 1557 | else { |
| 1558 | 1558 | // ----- Error log |
| 1559 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1559 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1560 | 1560 | |
| 1561 | 1561 | // ----- Return |
| 1562 | 1562 | return PclZip::errorCode(); |
@@ -1572,21 +1572,21 @@ discard block |
||
| 1572 | 1572 | case PCLZIP_OPT_BY_PREG : |
| 1573 | 1573 | //case PCLZIP_OPT_CRYPT : |
| 1574 | 1574 | // ----- Check the number of parameters |
| 1575 | - if (($i+1) >= $p_size) { |
|
| 1575 | + if (($i + 1) >= $p_size) { |
|
| 1576 | 1576 | // ----- Error log |
| 1577 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1577 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1578 | 1578 | |
| 1579 | 1579 | // ----- Return |
| 1580 | 1580 | return PclZip::errorCode(); |
| 1581 | 1581 | } |
| 1582 | 1582 | |
| 1583 | 1583 | // ----- Get the value |
| 1584 | - if (is_string($p_options_list[$i+1])) { |
|
| 1585 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1584 | + if (is_string($p_options_list[$i + 1])) { |
|
| 1585 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i + 1]; |
|
| 1586 | 1586 | } |
| 1587 | 1587 | else { |
| 1588 | 1588 | // ----- Error log |
| 1589 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1589 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1590 | 1590 | |
| 1591 | 1591 | // ----- Return |
| 1592 | 1592 | return PclZip::errorCode(); |
@@ -1599,7 +1599,7 @@ discard block |
||
| 1599 | 1599 | case PCLZIP_OPT_ADD_COMMENT : |
| 1600 | 1600 | case PCLZIP_OPT_PREPEND_COMMENT : |
| 1601 | 1601 | // ----- Check the number of parameters |
| 1602 | - if (($i+1) >= $p_size) { |
|
| 1602 | + if (($i + 1) >= $p_size) { |
|
| 1603 | 1603 | // ----- Error log |
| 1604 | 1604 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, |
| 1605 | 1605 | "Missing parameter value for option '" |
@@ -1611,8 +1611,8 @@ discard block |
||
| 1611 | 1611 | } |
| 1612 | 1612 | |
| 1613 | 1613 | // ----- Get the value |
| 1614 | - if (is_string($p_options_list[$i+1])) { |
|
| 1615 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1614 | + if (is_string($p_options_list[$i + 1])) { |
|
| 1615 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i + 1]; |
|
| 1616 | 1616 | } |
| 1617 | 1617 | else { |
| 1618 | 1618 | // ----- Error log |
@@ -1630,9 +1630,9 @@ discard block |
||
| 1630 | 1630 | // ----- Look for options that request an array of index |
| 1631 | 1631 | case PCLZIP_OPT_BY_INDEX : |
| 1632 | 1632 | // ----- Check the number of parameters |
| 1633 | - if (($i+1) >= $p_size) { |
|
| 1633 | + if (($i + 1) >= $p_size) { |
|
| 1634 | 1634 | // ----- Error log |
| 1635 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1635 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1636 | 1636 | |
| 1637 | 1637 | // ----- Return |
| 1638 | 1638 | return PclZip::errorCode(); |
@@ -1640,23 +1640,23 @@ discard block |
||
| 1640 | 1640 | |
| 1641 | 1641 | // ----- Get the value |
| 1642 | 1642 | $v_work_list = array(); |
| 1643 | - if (is_string($p_options_list[$i+1])) { |
|
| 1643 | + if (is_string($p_options_list[$i + 1])) { |
|
| 1644 | 1644 | |
| 1645 | 1645 | // ----- Remove spaces |
| 1646 | - $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); |
|
| 1646 | + $p_options_list[$i + 1] = strtr($p_options_list[$i + 1], ' ', ''); |
|
| 1647 | 1647 | |
| 1648 | 1648 | // ----- Parse items |
| 1649 | - $v_work_list = explode(",", $p_options_list[$i+1]); |
|
| 1649 | + $v_work_list = explode(",", $p_options_list[$i + 1]); |
|
| 1650 | 1650 | } |
| 1651 | - else if (is_integer($p_options_list[$i+1])) { |
|
| 1652 | - $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; |
|
| 1651 | + else if (is_integer($p_options_list[$i + 1])) { |
|
| 1652 | + $v_work_list[0] = $p_options_list[$i + 1] . '-' . $p_options_list[$i + 1]; |
|
| 1653 | 1653 | } |
| 1654 | - else if (is_array($p_options_list[$i+1])) { |
|
| 1655 | - $v_work_list = $p_options_list[$i+1]; |
|
| 1654 | + else if (is_array($p_options_list[$i + 1])) { |
|
| 1655 | + $v_work_list = $p_options_list[$i + 1]; |
|
| 1656 | 1656 | } |
| 1657 | 1657 | else { |
| 1658 | 1658 | // ----- Error log |
| 1659 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1659 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1660 | 1660 | |
| 1661 | 1661 | // ----- Return |
| 1662 | 1662 | return PclZip::errorCode(); |
@@ -1666,9 +1666,9 @@ discard block |
||
| 1666 | 1666 | // each index item in the list must be a couple with a start and |
| 1667 | 1667 | // an end value : [0,3], [5-5], [8-10], ... |
| 1668 | 1668 | // ----- Check the format of each item |
| 1669 | - $v_sort_flag=false; |
|
| 1670 | - $v_sort_value=0; |
|
| 1671 | - for ($j=0; $j<sizeof($v_work_list); $j++) { |
|
| 1669 | + $v_sort_flag = false; |
|
| 1670 | + $v_sort_value = 0; |
|
| 1671 | + for ($j = 0; $j < sizeof($v_work_list); $j++) { |
|
| 1672 | 1672 | // ----- Explode the item |
| 1673 | 1673 | $v_item_list = explode("-", $v_work_list[$j]); |
| 1674 | 1674 | $v_size_item_list = sizeof($v_item_list); |
@@ -1689,7 +1689,7 @@ discard block |
||
| 1689 | 1689 | } |
| 1690 | 1690 | else { |
| 1691 | 1691 | // ----- Error log |
| 1692 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1692 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1693 | 1693 | |
| 1694 | 1694 | // ----- Return |
| 1695 | 1695 | return PclZip::errorCode(); |
@@ -1698,11 +1698,11 @@ discard block |
||
| 1698 | 1698 | |
| 1699 | 1699 | // ----- Look for list sort |
| 1700 | 1700 | if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { |
| 1701 | - $v_sort_flag=true; |
|
| 1701 | + $v_sort_flag = true; |
|
| 1702 | 1702 | |
| 1703 | 1703 | // ----- TBC : An automatic sort should be writen ... |
| 1704 | 1704 | // ----- Error log |
| 1705 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1705 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1706 | 1706 | |
| 1707 | 1707 | // ----- Return |
| 1708 | 1708 | return PclZip::errorCode(); |
@@ -1732,16 +1732,16 @@ discard block |
||
| 1732 | 1732 | // ----- Look for options that request an octal value |
| 1733 | 1733 | case PCLZIP_OPT_SET_CHMOD : |
| 1734 | 1734 | // ----- Check the number of parameters |
| 1735 | - if (($i+1) >= $p_size) { |
|
| 1735 | + if (($i + 1) >= $p_size) { |
|
| 1736 | 1736 | // ----- Error log |
| 1737 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1737 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1738 | 1738 | |
| 1739 | 1739 | // ----- Return |
| 1740 | 1740 | return PclZip::errorCode(); |
| 1741 | 1741 | } |
| 1742 | 1742 | |
| 1743 | 1743 | // ----- Get the value |
| 1744 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1744 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i + 1]; |
|
| 1745 | 1745 | $i++; |
| 1746 | 1746 | break; |
| 1747 | 1747 | |
@@ -1757,21 +1757,21 @@ discard block |
||
| 1757 | 1757 | case PCLZIP_CB_POST_LIST : |
| 1758 | 1758 | */ |
| 1759 | 1759 | // ----- Check the number of parameters |
| 1760 | - if (($i+1) >= $p_size) { |
|
| 1760 | + if (($i + 1) >= $p_size) { |
|
| 1761 | 1761 | // ----- Error log |
| 1762 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1762 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1763 | 1763 | |
| 1764 | 1764 | // ----- Return |
| 1765 | 1765 | return PclZip::errorCode(); |
| 1766 | 1766 | } |
| 1767 | 1767 | |
| 1768 | 1768 | // ----- Get the value |
| 1769 | - $v_function_name = $p_options_list[$i+1]; |
|
| 1769 | + $v_function_name = $p_options_list[$i + 1]; |
|
| 1770 | 1770 | |
| 1771 | 1771 | // ----- Check that the value is a valid existing function |
| 1772 | 1772 | if (!function_exists($v_function_name)) { |
| 1773 | 1773 | // ----- Error log |
| 1774 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1774 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '" . $v_function_name . "()' is not an existing function for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'"); |
|
| 1775 | 1775 | |
| 1776 | 1776 | // ----- Return |
| 1777 | 1777 | return PclZip::errorCode(); |
@@ -1786,7 +1786,7 @@ discard block |
||
| 1786 | 1786 | // ----- Error log |
| 1787 | 1787 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
| 1788 | 1788 | "Unknown parameter '" |
| 1789 | - .$p_options_list[$i]."'"); |
|
| 1789 | + .$p_options_list[$i] . "'"); |
|
| 1790 | 1790 | |
| 1791 | 1791 | // ----- Return |
| 1792 | 1792 | return PclZip::errorCode(); |
@@ -1798,13 +1798,13 @@ discard block |
||
| 1798 | 1798 | |
| 1799 | 1799 | // ----- Look for mandatory options |
| 1800 | 1800 | if ($v_requested_options !== false) { |
| 1801 | - for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
|
| 1801 | + for ($key = reset($v_requested_options); $key = key($v_requested_options); $key = next($v_requested_options)) { |
|
| 1802 | 1802 | // ----- Look for mandatory option |
| 1803 | 1803 | if ($v_requested_options[$key] == 'mandatory') { |
| 1804 | 1804 | // ----- Look if present |
| 1805 | 1805 | if (!isset($v_result_list[$key])) { |
| 1806 | 1806 | // ----- Error log |
| 1807 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
|
| 1807 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter " . PclZipUtilOptionText($key) . "(" . $key . ")"); |
|
| 1808 | 1808 | |
| 1809 | 1809 | // ----- Return |
| 1810 | 1810 | return PclZip::errorCode(); |
@@ -1831,7 +1831,7 @@ discard block |
||
| 1831 | 1831 | // -------------------------------------------------------------------------------- |
| 1832 | 1832 | function privOptionDefaultThreshold(&$p_options) |
| 1833 | 1833 | { |
| 1834 | - $v_result=1; |
|
| 1834 | + $v_result = 1; |
|
| 1835 | 1835 | |
| 1836 | 1836 | if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
| 1837 | 1837 | || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) { |
@@ -1843,16 +1843,16 @@ discard block |
||
| 1843 | 1843 | $v_memory_limit = trim($v_memory_limit); |
| 1844 | 1844 | $last = strtolower(substr($v_memory_limit, -1)); |
| 1845 | 1845 | |
| 1846 | - if($last == 'g') |
|
| 1846 | + if ($last == 'g') |
|
| 1847 | 1847 | //$v_memory_limit = $v_memory_limit*1024*1024*1024; |
| 1848 | - $v_memory_limit = $v_memory_limit*1073741824; |
|
| 1849 | - if($last == 'm') |
|
| 1848 | + $v_memory_limit = $v_memory_limit * 1073741824; |
|
| 1849 | + if ($last == 'm') |
|
| 1850 | 1850 | //$v_memory_limit = $v_memory_limit*1024*1024; |
| 1851 | - $v_memory_limit = $v_memory_limit*1048576; |
|
| 1852 | - if($last == 'k') |
|
| 1853 | - $v_memory_limit = $v_memory_limit*1024; |
|
| 1851 | + $v_memory_limit = $v_memory_limit * 1048576; |
|
| 1852 | + if ($last == 'k') |
|
| 1853 | + $v_memory_limit = $v_memory_limit * 1024; |
|
| 1854 | 1854 | |
| 1855 | - $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO); |
|
| 1855 | + $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit * PCLZIP_TEMPORARY_FILE_RATIO); |
|
| 1856 | 1856 | |
| 1857 | 1857 | |
| 1858 | 1858 | // ----- Sanity check : No threshold if value lower than 1M |
@@ -1873,9 +1873,9 @@ discard block |
||
| 1873 | 1873 | // 1 on success. |
| 1874 | 1874 | // 0 on failure. |
| 1875 | 1875 | // -------------------------------------------------------------------------------- |
| 1876 | - function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) |
|
| 1876 | + function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options = false) |
|
| 1877 | 1877 | { |
| 1878 | - $v_result=1; |
|
| 1878 | + $v_result = 1; |
|
| 1879 | 1879 | |
| 1880 | 1880 | // ----- For each file in the list check the attributes |
| 1881 | 1881 | foreach ($p_file_list as $v_key => $v_value) { |
@@ -1883,7 +1883,7 @@ discard block |
||
| 1883 | 1883 | // ----- Check if the option is supported |
| 1884 | 1884 | if (!isset($v_requested_options[$v_key])) { |
| 1885 | 1885 | // ----- Error log |
| 1886 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); |
|
| 1886 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '" . $v_key . "' for this file"); |
|
| 1887 | 1887 | |
| 1888 | 1888 | // ----- Return |
| 1889 | 1889 | return PclZip::errorCode(); |
@@ -1893,14 +1893,14 @@ discard block |
||
| 1893 | 1893 | switch ($v_key) { |
| 1894 | 1894 | case PCLZIP_ATT_FILE_NAME : |
| 1895 | 1895 | if (!is_string($v_value)) { |
| 1896 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1896 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type " . gettype($v_value) . ". String expected for attribute '" . PclZipUtilOptionText($v_key) . "'"); |
|
| 1897 | 1897 | return PclZip::errorCode(); |
| 1898 | 1898 | } |
| 1899 | 1899 | |
| 1900 | 1900 | $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); |
| 1901 | 1901 | |
| 1902 | 1902 | if ($p_filedescr['filename'] == '') { |
| 1903 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1903 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '" . PclZipUtilOptionText($v_key) . "'"); |
|
| 1904 | 1904 | return PclZip::errorCode(); |
| 1905 | 1905 | } |
| 1906 | 1906 | |
@@ -1908,28 +1908,28 @@ discard block |
||
| 1908 | 1908 | |
| 1909 | 1909 | case PCLZIP_ATT_FILE_NEW_SHORT_NAME : |
| 1910 | 1910 | if (!is_string($v_value)) { |
| 1911 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1911 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type " . gettype($v_value) . ". String expected for attribute '" . PclZipUtilOptionText($v_key) . "'"); |
|
| 1912 | 1912 | return PclZip::errorCode(); |
| 1913 | 1913 | } |
| 1914 | 1914 | |
| 1915 | 1915 | $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); |
| 1916 | 1916 | |
| 1917 | 1917 | if ($p_filedescr['new_short_name'] == '') { |
| 1918 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1918 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '" . PclZipUtilOptionText($v_key) . "'"); |
|
| 1919 | 1919 | return PclZip::errorCode(); |
| 1920 | 1920 | } |
| 1921 | 1921 | break; |
| 1922 | 1922 | |
| 1923 | 1923 | case PCLZIP_ATT_FILE_NEW_FULL_NAME : |
| 1924 | 1924 | if (!is_string($v_value)) { |
| 1925 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1925 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type " . gettype($v_value) . ". String expected for attribute '" . PclZipUtilOptionText($v_key) . "'"); |
|
| 1926 | 1926 | return PclZip::errorCode(); |
| 1927 | 1927 | } |
| 1928 | 1928 | |
| 1929 | 1929 | $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); |
| 1930 | 1930 | |
| 1931 | 1931 | if ($p_filedescr['new_full_name'] == '') { |
| 1932 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1932 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '" . PclZipUtilOptionText($v_key) . "'"); |
|
| 1933 | 1933 | return PclZip::errorCode(); |
| 1934 | 1934 | } |
| 1935 | 1935 | break; |
@@ -1937,7 +1937,7 @@ discard block |
||
| 1937 | 1937 | // ----- Look for options that takes a string |
| 1938 | 1938 | case PCLZIP_ATT_FILE_COMMENT : |
| 1939 | 1939 | if (!is_string($v_value)) { |
| 1940 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1940 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type " . gettype($v_value) . ". String expected for attribute '" . PclZipUtilOptionText($v_key) . "'"); |
|
| 1941 | 1941 | return PclZip::errorCode(); |
| 1942 | 1942 | } |
| 1943 | 1943 | |
@@ -1946,7 +1946,7 @@ discard block |
||
| 1946 | 1946 | |
| 1947 | 1947 | case PCLZIP_ATT_FILE_MTIME : |
| 1948 | 1948 | if (!is_integer($v_value)) { |
| 1949 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
|
| 1949 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type " . gettype($v_value) . ". Integer expected for attribute '" . PclZipUtilOptionText($v_key) . "'"); |
|
| 1950 | 1950 | return PclZip::errorCode(); |
| 1951 | 1951 | } |
| 1952 | 1952 | |
@@ -1960,7 +1960,7 @@ discard block |
||
| 1960 | 1960 | default : |
| 1961 | 1961 | // ----- Error log |
| 1962 | 1962 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
| 1963 | - "Unknown parameter '".$v_key."'"); |
|
| 1963 | + "Unknown parameter '" . $v_key . "'"); |
|
| 1964 | 1964 | |
| 1965 | 1965 | // ----- Return |
| 1966 | 1966 | return PclZip::errorCode(); |
@@ -1968,12 +1968,12 @@ discard block |
||
| 1968 | 1968 | |
| 1969 | 1969 | // ----- Look for mandatory options |
| 1970 | 1970 | if ($v_requested_options !== false) { |
| 1971 | - for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
|
| 1971 | + for ($key = reset($v_requested_options); $key = key($v_requested_options); $key = next($v_requested_options)) { |
|
| 1972 | 1972 | // ----- Look for mandatory option |
| 1973 | 1973 | if ($v_requested_options[$key] == 'mandatory') { |
| 1974 | 1974 | // ----- Look if present |
| 1975 | 1975 | if (!isset($p_file_list[$key])) { |
| 1976 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
|
| 1976 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter " . PclZipUtilOptionText($key) . "(" . $key . ")"); |
|
| 1977 | 1977 | return PclZip::errorCode(); |
| 1978 | 1978 | } |
| 1979 | 1979 | } |
@@ -2004,13 +2004,13 @@ discard block |
||
| 2004 | 2004 | // -------------------------------------------------------------------------------- |
| 2005 | 2005 | function privFileDescrExpand(&$p_filedescr_list, &$p_options) |
| 2006 | 2006 | { |
| 2007 | - $v_result=1; |
|
| 2007 | + $v_result = 1; |
|
| 2008 | 2008 | |
| 2009 | 2009 | // ----- Create a result list |
| 2010 | 2010 | $v_result_list = array(); |
| 2011 | 2011 | |
| 2012 | 2012 | // ----- Look each entry |
| 2013 | - for ($i=0; $i<sizeof($p_filedescr_list); $i++) { |
|
| 2013 | + for ($i = 0; $i < sizeof($p_filedescr_list); $i++) { |
|
| 2014 | 2014 | |
| 2015 | 2015 | // ----- Get filedescr |
| 2016 | 2016 | $v_descr = $p_filedescr_list[$i]; |
@@ -2045,7 +2045,7 @@ discard block |
||
| 2045 | 2045 | // ----- Missing file |
| 2046 | 2046 | else { |
| 2047 | 2047 | // ----- Error log |
| 2048 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist"); |
|
| 2048 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '" . $v_descr['filename'] . "' does not exist"); |
|
| 2049 | 2049 | |
| 2050 | 2050 | // ----- Return |
| 2051 | 2051 | return PclZip::errorCode(); |
@@ -2071,7 +2071,7 @@ discard block |
||
| 2071 | 2071 | } |
| 2072 | 2072 | |
| 2073 | 2073 | // ----- Compose the full filename |
| 2074 | - $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; |
|
| 2074 | + $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'] . '/' . $v_item_handler; |
|
| 2075 | 2075 | |
| 2076 | 2076 | // ----- Look for different stored filename |
| 2077 | 2077 | // Because the name of the folder was changed, the name of the |
@@ -2079,7 +2079,7 @@ discard block |
||
| 2079 | 2079 | if (($v_descr['stored_filename'] != $v_descr['filename']) |
| 2080 | 2080 | && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) { |
| 2081 | 2081 | if ($v_descr['stored_filename'] != '') { |
| 2082 | - $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; |
|
| 2082 | + $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'] . '/' . $v_item_handler; |
|
| 2083 | 2083 | } |
| 2084 | 2084 | else { |
| 2085 | 2085 | $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; |
@@ -2129,7 +2129,7 @@ discard block |
||
| 2129 | 2129 | // -------------------------------------------------------------------------------- |
| 2130 | 2130 | function privCreate($p_filedescr_list, &$p_result_list, &$p_options) |
| 2131 | 2131 | { |
| 2132 | - $v_result=1; |
|
| 2132 | + $v_result = 1; |
|
| 2133 | 2133 | $v_list_detail = array(); |
| 2134 | 2134 | |
| 2135 | 2135 | // ----- Magic quotes trick |
@@ -2164,7 +2164,7 @@ discard block |
||
| 2164 | 2164 | // -------------------------------------------------------------------------------- |
| 2165 | 2165 | function privAdd($p_filedescr_list, &$p_result_list, &$p_options) |
| 2166 | 2166 | { |
| 2167 | - $v_result=1; |
|
| 2167 | + $v_result = 1; |
|
| 2168 | 2168 | $v_list_detail = array(); |
| 2169 | 2169 | |
| 2170 | 2170 | // ----- Look if the archive exists or is empty |
@@ -2181,7 +2181,7 @@ discard block |
||
| 2181 | 2181 | $this->privDisableMagicQuotes(); |
| 2182 | 2182 | |
| 2183 | 2183 | // ----- Open the zip file |
| 2184 | - if (($v_result=$this->privOpenFd('rb')) != 1) |
|
| 2184 | + if (($v_result = $this->privOpenFd('rb')) != 1) |
|
| 2185 | 2185 | { |
| 2186 | 2186 | // ----- Magic quotes trick |
| 2187 | 2187 | $this->privSwapBackMagicQuotes(); |
@@ -2203,7 +2203,7 @@ discard block |
||
| 2203 | 2203 | @rewind($this->zip_fd); |
| 2204 | 2204 | |
| 2205 | 2205 | // ----- Creates a temporay file |
| 2206 | - $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
|
| 2206 | + $v_zip_temp_name = PCLZIP_TEMPORARY_DIR . uniqid('pclzip-') . '.tmp'; |
|
| 2207 | 2207 | |
| 2208 | 2208 | // ----- Open the temporary file in write mode |
| 2209 | 2209 | if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
@@ -2211,7 +2211,7 @@ discard block |
||
| 2211 | 2211 | $this->privCloseFd(); |
| 2212 | 2212 | $this->privSwapBackMagicQuotes(); |
| 2213 | 2213 | |
| 2214 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
|
| 2214 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \'' . $v_zip_temp_name . '\' in binary write mode'); |
|
| 2215 | 2215 | |
| 2216 | 2216 | // ----- Return |
| 2217 | 2217 | return PclZip::errorCode(); |
@@ -2262,7 +2262,7 @@ discard block |
||
| 2262 | 2262 | } |
| 2263 | 2263 | |
| 2264 | 2264 | // ----- Create the Central Dir files header |
| 2265 | - for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++) |
|
| 2265 | + for ($i = 0, $v_count = 0; $i < sizeof($v_header_list); $i++) |
|
| 2266 | 2266 | { |
| 2267 | 2267 | // ----- Create the file header |
| 2268 | 2268 | if ($v_header_list[$i]['status'] == 'ok') { |
@@ -2288,17 +2288,17 @@ discard block |
||
| 2288 | 2288 | $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
| 2289 | 2289 | } |
| 2290 | 2290 | if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) { |
| 2291 | - $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT]; |
|
| 2291 | + $v_comment = $v_comment . $p_options[PCLZIP_OPT_ADD_COMMENT]; |
|
| 2292 | 2292 | } |
| 2293 | 2293 | if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) { |
| 2294 | - $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment; |
|
| 2294 | + $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT] . $v_comment; |
|
| 2295 | 2295 | } |
| 2296 | 2296 | |
| 2297 | 2297 | // ----- Calculate the size of the central header |
| 2298 | - $v_size = @ftell($this->zip_fd)-$v_offset; |
|
| 2298 | + $v_size = @ftell($this->zip_fd) - $v_offset; |
|
| 2299 | 2299 | |
| 2300 | 2300 | // ----- Create the central dir footer |
| 2301 | - if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) |
|
| 2301 | + if (($v_result = $this->privWriteCentralHeader($v_count + $v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) |
|
| 2302 | 2302 | { |
| 2303 | 2303 | // ----- Reset the file list |
| 2304 | 2304 | unset($v_header_list); |
@@ -2343,13 +2343,13 @@ discard block |
||
| 2343 | 2343 | // -------------------------------------------------------------------------------- |
| 2344 | 2344 | function privOpenFd($p_mode) |
| 2345 | 2345 | { |
| 2346 | - $v_result=1; |
|
| 2346 | + $v_result = 1; |
|
| 2347 | 2347 | |
| 2348 | 2348 | // ----- Look if already open |
| 2349 | 2349 | if ($this->zip_fd != 0) |
| 2350 | 2350 | { |
| 2351 | 2351 | // ----- Error log |
| 2352 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open'); |
|
| 2352 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \'' . $this->zipname . '\' already open'); |
|
| 2353 | 2353 | |
| 2354 | 2354 | // ----- Return |
| 2355 | 2355 | return PclZip::errorCode(); |
@@ -2359,7 +2359,7 @@ discard block |
||
| 2359 | 2359 | if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) |
| 2360 | 2360 | { |
| 2361 | 2361 | // ----- Error log |
| 2362 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode'); |
|
| 2362 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \'' . $this->zipname . '\' in ' . $p_mode . ' mode'); |
|
| 2363 | 2363 | |
| 2364 | 2364 | // ----- Return |
| 2365 | 2365 | return PclZip::errorCode(); |
@@ -2377,7 +2377,7 @@ discard block |
||
| 2377 | 2377 | // -------------------------------------------------------------------------------- |
| 2378 | 2378 | function privCloseFd() |
| 2379 | 2379 | { |
| 2380 | - $v_result=1; |
|
| 2380 | + $v_result = 1; |
|
| 2381 | 2381 | |
| 2382 | 2382 | if ($this->zip_fd != 0) |
| 2383 | 2383 | @fclose($this->zip_fd); |
@@ -2404,7 +2404,7 @@ discard block |
||
| 2404 | 2404 | // function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options) |
| 2405 | 2405 | function privAddList($p_filedescr_list, &$p_result_list, &$p_options) |
| 2406 | 2406 | { |
| 2407 | - $v_result=1; |
|
| 2407 | + $v_result = 1; |
|
| 2408 | 2408 | |
| 2409 | 2409 | // ----- Add the files |
| 2410 | 2410 | $v_header_list = array(); |
@@ -2418,7 +2418,7 @@ discard block |
||
| 2418 | 2418 | $v_offset = @ftell($this->zip_fd); |
| 2419 | 2419 | |
| 2420 | 2420 | // ----- Create the Central Dir files header |
| 2421 | - for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++) |
|
| 2421 | + for ($i = 0, $v_count = 0; $i < sizeof($v_header_list); $i++) |
|
| 2422 | 2422 | { |
| 2423 | 2423 | // ----- Create the file header |
| 2424 | 2424 | if ($v_header_list[$i]['status'] == 'ok') { |
@@ -2440,7 +2440,7 @@ discard block |
||
| 2440 | 2440 | } |
| 2441 | 2441 | |
| 2442 | 2442 | // ----- Calculate the size of the central header |
| 2443 | - $v_size = @ftell($this->zip_fd)-$v_offset; |
|
| 2443 | + $v_size = @ftell($this->zip_fd) - $v_offset; |
|
| 2444 | 2444 | |
| 2445 | 2445 | // ----- Create the central dir footer |
| 2446 | 2446 | if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) |
@@ -2468,14 +2468,14 @@ discard block |
||
| 2468 | 2468 | // -------------------------------------------------------------------------------- |
| 2469 | 2469 | function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) |
| 2470 | 2470 | { |
| 2471 | - $v_result=1; |
|
| 2471 | + $v_result = 1; |
|
| 2472 | 2472 | $v_header = array(); |
| 2473 | 2473 | |
| 2474 | 2474 | // ----- Recuperate the current number of elt in list |
| 2475 | 2475 | $v_nb = sizeof($p_result_list); |
| 2476 | 2476 | |
| 2477 | 2477 | // ----- Loop on the files |
| 2478 | - for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { |
|
| 2478 | + for ($j = 0; ($j < sizeof($p_filedescr_list)) && ($v_result == 1); $j++) { |
|
| 2479 | 2479 | // ----- Format the filename |
| 2480 | 2480 | $p_filedescr_list[$j]['filename'] |
| 2481 | 2481 | = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); |
@@ -2488,9 +2488,9 @@ discard block |
||
| 2488 | 2488 | } |
| 2489 | 2489 | |
| 2490 | 2490 | // ----- Check the filename |
| 2491 | - if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') |
|
| 2491 | + if (($p_filedescr_list[$j]['type'] != 'virtual_file') |
|
| 2492 | 2492 | && (!file_exists($p_filedescr_list[$j]['filename']))) { |
| 2493 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); |
|
| 2493 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '" . $p_filedescr_list[$j]['filename'] . "' does not exist"); |
|
| 2494 | 2494 | return PclZip::errorCode(); |
| 2495 | 2495 | } |
| 2496 | 2496 | |
@@ -2498,10 +2498,10 @@ discard block |
||
| 2498 | 2498 | // or a dir with all its path removed |
| 2499 | 2499 | // if ( (is_file($p_filedescr_list[$j]['filename'])) |
| 2500 | 2500 | // || ( is_dir($p_filedescr_list[$j]['filename']) |
| 2501 | - if ( ($p_filedescr_list[$j]['type'] == 'file') |
|
| 2501 | + if (($p_filedescr_list[$j]['type'] == 'file') |
|
| 2502 | 2502 | || ($p_filedescr_list[$j]['type'] == 'virtual_file') |
| 2503 | - || ( ($p_filedescr_list[$j]['type'] == 'folder') |
|
| 2504 | - && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) |
|
| 2503 | + || (($p_filedescr_list[$j]['type'] == 'folder') |
|
| 2504 | + && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) |
|
| 2505 | 2505 | || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
| 2506 | 2506 | ) { |
| 2507 | 2507 | |
@@ -2530,7 +2530,7 @@ discard block |
||
| 2530 | 2530 | // -------------------------------------------------------------------------------- |
| 2531 | 2531 | function privAddFile($p_filedescr, &$p_header, &$p_options) |
| 2532 | 2532 | { |
| 2533 | - $v_result=1; |
|
| 2533 | + $v_result = 1; |
|
| 2534 | 2534 | |
| 2535 | 2535 | // ----- Working variable |
| 2536 | 2536 | $p_filename = $p_filedescr['filename']; |
@@ -2575,13 +2575,13 @@ discard block |
||
| 2575 | 2575 | $p_header['index'] = -1; |
| 2576 | 2576 | |
| 2577 | 2577 | // ----- Look for regular file |
| 2578 | - if ($p_filedescr['type']=='file') { |
|
| 2578 | + if ($p_filedescr['type'] == 'file') { |
|
| 2579 | 2579 | $p_header['external'] = 0x00000000; |
| 2580 | 2580 | $p_header['size'] = filesize($p_filename); |
| 2581 | 2581 | } |
| 2582 | 2582 | |
| 2583 | 2583 | // ----- Look for regular folder |
| 2584 | - else if ($p_filedescr['type']=='folder') { |
|
| 2584 | + else if ($p_filedescr['type'] == 'folder') { |
|
| 2585 | 2585 | $p_header['external'] = 0x00000010; |
| 2586 | 2586 | $p_header['mtime'] = filemtime($p_filename); |
| 2587 | 2587 | $p_header['size'] = filesize($p_filename); |
@@ -2656,10 +2656,10 @@ discard block |
||
| 2656 | 2656 | // ----- Look for a file |
| 2657 | 2657 | if ($p_filedescr['type'] == 'file') { |
| 2658 | 2658 | // ----- Look for using temporary file to zip |
| 2659 | - if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 2659 | + if ((!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 2660 | 2660 | && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
| 2661 | 2661 | || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
| 2662 | - && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) { |
|
| 2662 | + && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])))) { |
|
| 2663 | 2663 | $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); |
| 2664 | 2664 | if ($v_result < PCLZIP_ERR_NO_ERROR) { |
| 2665 | 2665 | return $v_result; |
@@ -2759,7 +2759,7 @@ discard block |
||
| 2759 | 2759 | // ----- Set the file properties |
| 2760 | 2760 | $p_header['size'] = 0; |
| 2761 | 2761 | //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked |
| 2762 | - $p_header['external'] = 0x00000010; // Value for a folder : to be checked |
|
| 2762 | + $p_header['external'] = 0x00000010; // Value for a folder : to be checked |
|
| 2763 | 2763 | |
| 2764 | 2764 | // ----- Call the header generation |
| 2765 | 2765 | if (($v_result = $this->privWriteFileHeader($p_header)) != 1) |
@@ -2803,7 +2803,7 @@ discard block |
||
| 2803 | 2803 | // -------------------------------------------------------------------------------- |
| 2804 | 2804 | function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) |
| 2805 | 2805 | { |
| 2806 | - $v_result=PCLZIP_ERR_NO_ERROR; |
|
| 2806 | + $v_result = PCLZIP_ERR_NO_ERROR; |
|
| 2807 | 2807 | |
| 2808 | 2808 | // ----- Working variable |
| 2809 | 2809 | $p_filename = $p_filedescr['filename']; |
@@ -2816,10 +2816,10 @@ discard block |
||
| 2816 | 2816 | } |
| 2817 | 2817 | |
| 2818 | 2818 | // ----- Creates a compressed temporary file |
| 2819 | - $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; |
|
| 2819 | + $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR . uniqid('pclzip-') . '.gz'; |
|
| 2820 | 2820 | if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) { |
| 2821 | 2821 | fclose($v_file); |
| 2822 | - PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
|
| 2822 | + PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \'' . $v_gzip_temp_name . '\' in binary write mode'); |
|
| 2823 | 2823 | return PclZip::errorCode(); |
| 2824 | 2824 | } |
| 2825 | 2825 | |
@@ -2839,13 +2839,13 @@ discard block |
||
| 2839 | 2839 | |
| 2840 | 2840 | // ----- Check the minimum file size |
| 2841 | 2841 | if (filesize($v_gzip_temp_name) < 18) { |
| 2842 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes'); |
|
| 2842 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \'' . $v_gzip_temp_name . '\' has invalid filesize - should be minimum 18 bytes'); |
|
| 2843 | 2843 | return PclZip::errorCode(); |
| 2844 | 2844 | } |
| 2845 | 2845 | |
| 2846 | 2846 | // ----- Extract the compressed attributes |
| 2847 | 2847 | if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { |
| 2848 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 2848 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \'' . $v_gzip_temp_name . '\' in binary read mode'); |
|
| 2849 | 2849 | return PclZip::errorCode(); |
| 2850 | 2850 | } |
| 2851 | 2851 | |
@@ -2857,7 +2857,7 @@ discard block |
||
| 2857 | 2857 | $v_data_header['os'] = bin2hex($v_data_header['os']); |
| 2858 | 2858 | |
| 2859 | 2859 | // ----- Read the gzip file footer |
| 2860 | - @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8); |
|
| 2860 | + @fseek($v_file_compressed, filesize($v_gzip_temp_name) - 8); |
|
| 2861 | 2861 | $v_binary_data = @fread($v_file_compressed, 8); |
| 2862 | 2862 | $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data); |
| 2863 | 2863 | |
@@ -2865,7 +2865,7 @@ discard block |
||
| 2865 | 2865 | $p_header['compression'] = ord($v_data_header['cm']); |
| 2866 | 2866 | //$p_header['mtime'] = $v_data_header['mtime']; |
| 2867 | 2867 | $p_header['crc'] = $v_data_footer['crc']; |
| 2868 | - $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18; |
|
| 2868 | + $p_header['compressed_size'] = filesize($v_gzip_temp_name) - 18; |
|
| 2869 | 2869 | |
| 2870 | 2870 | // ----- Close the file |
| 2871 | 2871 | @fclose($v_file_compressed); |
@@ -2878,7 +2878,7 @@ discard block |
||
| 2878 | 2878 | // ----- Add the compressed data |
| 2879 | 2879 | if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) |
| 2880 | 2880 | { |
| 2881 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 2881 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \'' . $v_gzip_temp_name . '\' in binary read mode'); |
|
| 2882 | 2882 | return PclZip::errorCode(); |
| 2883 | 2883 | } |
| 2884 | 2884 | |
@@ -2915,7 +2915,7 @@ discard block |
||
| 2915 | 2915 | // -------------------------------------------------------------------------------- |
| 2916 | 2916 | function privCalculateStoredFilename(&$p_filedescr, &$p_options) |
| 2917 | 2917 | { |
| 2918 | - $v_result=1; |
|
| 2918 | + $v_result = 1; |
|
| 2919 | 2919 | |
| 2920 | 2920 | // ----- Working variables |
| 2921 | 2921 | $p_filename = $p_filedescr['filename']; |
@@ -2954,9 +2954,9 @@ discard block |
||
| 2954 | 2954 | $v_path_info = pathinfo($p_filename); |
| 2955 | 2955 | $v_dir = ''; |
| 2956 | 2956 | if ($v_path_info['dirname'] != '') { |
| 2957 | - $v_dir = $v_path_info['dirname'].'/'; |
|
| 2957 | + $v_dir = $v_path_info['dirname'] . '/'; |
|
| 2958 | 2958 | } |
| 2959 | - $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; |
|
| 2959 | + $v_stored_filename = $v_dir . $p_filedescr['new_short_name']; |
|
| 2960 | 2960 | } |
| 2961 | 2961 | else { |
| 2962 | 2962 | // ----- Calculate the stored filename |
@@ -2972,14 +2972,14 @@ discard block |
||
| 2972 | 2972 | if (substr($p_remove_dir, -1) != '/') |
| 2973 | 2973 | $p_remove_dir .= "/"; |
| 2974 | 2974 | |
| 2975 | - if ( (substr($p_filename, 0, 2) == "./") |
|
| 2975 | + if ((substr($p_filename, 0, 2) == "./") |
|
| 2976 | 2976 | || (substr($p_remove_dir, 0, 2) == "./")) { |
| 2977 | 2977 | |
| 2978 | - if ( (substr($p_filename, 0, 2) == "./") |
|
| 2978 | + if ((substr($p_filename, 0, 2) == "./") |
|
| 2979 | 2979 | && (substr($p_remove_dir, 0, 2) != "./")) { |
| 2980 | - $p_remove_dir = "./".$p_remove_dir; |
|
| 2980 | + $p_remove_dir = "./" . $p_remove_dir; |
|
| 2981 | 2981 | } |
| 2982 | - if ( (substr($p_filename, 0, 2) != "./") |
|
| 2982 | + if ((substr($p_filename, 0, 2) != "./") |
|
| 2983 | 2983 | && (substr($p_remove_dir, 0, 2) == "./")) { |
| 2984 | 2984 | $p_remove_dir = substr($p_remove_dir, 2); |
| 2985 | 2985 | } |
@@ -3004,9 +3004,9 @@ discard block |
||
| 3004 | 3004 | // ----- Look for path to add |
| 3005 | 3005 | if ($p_add_dir != "") { |
| 3006 | 3006 | if (substr($p_add_dir, -1) == "/") |
| 3007 | - $v_stored_filename = $p_add_dir.$v_stored_filename; |
|
| 3007 | + $v_stored_filename = $p_add_dir . $v_stored_filename; |
|
| 3008 | 3008 | else |
| 3009 | - $v_stored_filename = $p_add_dir."/".$v_stored_filename; |
|
| 3009 | + $v_stored_filename = $p_add_dir . "/" . $v_stored_filename; |
|
| 3010 | 3010 | } |
| 3011 | 3011 | } |
| 3012 | 3012 | |
@@ -3027,15 +3027,15 @@ discard block |
||
| 3027 | 3027 | // -------------------------------------------------------------------------------- |
| 3028 | 3028 | function privWriteFileHeader(&$p_header) |
| 3029 | 3029 | { |
| 3030 | - $v_result=1; |
|
| 3030 | + $v_result = 1; |
|
| 3031 | 3031 | |
| 3032 | 3032 | // ----- Store the offset position of the file |
| 3033 | 3033 | $p_header['offset'] = ftell($this->zip_fd); |
| 3034 | 3034 | |
| 3035 | 3035 | // ----- Transform UNIX mtime to DOS format mdate/mtime |
| 3036 | 3036 | $v_date = getdate($p_header['mtime']); |
| 3037 | - $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; |
|
| 3038 | - $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; |
|
| 3037 | + $v_mtime = ($v_date['hours'] << 11) + ($v_date['minutes'] << 5) + $v_date['seconds'] / 2; |
|
| 3038 | + $v_mdate = (($v_date['year'] - 1980) << 9) + ($v_date['mon'] << 5) + $v_date['mday']; |
|
| 3039 | 3039 | |
| 3040 | 3040 | // ----- Packed data |
| 3041 | 3041 | $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, |
@@ -3072,7 +3072,7 @@ discard block |
||
| 3072 | 3072 | // -------------------------------------------------------------------------------- |
| 3073 | 3073 | function privWriteCentralFileHeader(&$p_header) |
| 3074 | 3074 | { |
| 3075 | - $v_result=1; |
|
| 3075 | + $v_result = 1; |
|
| 3076 | 3076 | |
| 3077 | 3077 | // TBC |
| 3078 | 3078 | //for(reset($p_header); $key = key($p_header); next($p_header)) { |
@@ -3080,8 +3080,8 @@ discard block |
||
| 3080 | 3080 | |
| 3081 | 3081 | // ----- Transform UNIX mtime to DOS format mdate/mtime |
| 3082 | 3082 | $v_date = getdate($p_header['mtime']); |
| 3083 | - $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; |
|
| 3084 | - $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; |
|
| 3083 | + $v_mtime = ($v_date['hours'] << 11) + ($v_date['minutes'] << 5) + $v_date['seconds'] / 2; |
|
| 3084 | + $v_mdate = (($v_date['year'] - 1980) << 9) + ($v_date['mon'] << 5) + $v_date['mday']; |
|
| 3085 | 3085 | |
| 3086 | 3086 | |
| 3087 | 3087 | // ----- Packed data |
@@ -3125,7 +3125,7 @@ discard block |
||
| 3125 | 3125 | // -------------------------------------------------------------------------------- |
| 3126 | 3126 | function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment) |
| 3127 | 3127 | { |
| 3128 | - $v_result=1; |
|
| 3128 | + $v_result = 1; |
|
| 3129 | 3129 | |
| 3130 | 3130 | // ----- Packed data |
| 3131 | 3131 | $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, |
@@ -3154,7 +3154,7 @@ discard block |
||
| 3154 | 3154 | // -------------------------------------------------------------------------------- |
| 3155 | 3155 | function privList(&$p_list) |
| 3156 | 3156 | { |
| 3157 | - $v_result=1; |
|
| 3157 | + $v_result = 1; |
|
| 3158 | 3158 | |
| 3159 | 3159 | // ----- Magic quotes trick |
| 3160 | 3160 | $this->privDisableMagicQuotes(); |
@@ -3166,7 +3166,7 @@ discard block |
||
| 3166 | 3166 | $this->privSwapBackMagicQuotes(); |
| 3167 | 3167 | |
| 3168 | 3168 | // ----- Error log |
| 3169 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); |
|
| 3169 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \'' . $this->zipname . '\' in binary read mode'); |
|
| 3170 | 3170 | |
| 3171 | 3171 | // ----- Return |
| 3172 | 3172 | return PclZip::errorCode(); |
@@ -3194,7 +3194,7 @@ discard block |
||
| 3194 | 3194 | } |
| 3195 | 3195 | |
| 3196 | 3196 | // ----- Read each entry |
| 3197 | - for ($i=0; $i<$v_central_dir['entries']; $i++) |
|
| 3197 | + for ($i = 0; $i < $v_central_dir['entries']; $i++) |
|
| 3198 | 3198 | { |
| 3199 | 3199 | // ----- Read the file header |
| 3200 | 3200 | if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
@@ -3241,7 +3241,7 @@ discard block |
||
| 3241 | 3241 | // -------------------------------------------------------------------------------- |
| 3242 | 3242 | function privConvertHeader2FileInfo($p_header, &$p_info) |
| 3243 | 3243 | { |
| 3244 | - $v_result=1; |
|
| 3244 | + $v_result = 1; |
|
| 3245 | 3245 | |
| 3246 | 3246 | // ----- Get the interesting attributes |
| 3247 | 3247 | $v_temp_path = PclZipUtilPathReduction($p_header['filename']); |
@@ -3252,7 +3252,7 @@ discard block |
||
| 3252 | 3252 | $p_info['compressed_size'] = $p_header['compressed_size']; |
| 3253 | 3253 | $p_info['mtime'] = $p_header['mtime']; |
| 3254 | 3254 | $p_info['comment'] = $p_header['comment']; |
| 3255 | - $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); |
|
| 3255 | + $p_info['folder'] = (($p_header['external'] & 0x00000010) == 0x00000010); |
|
| 3256 | 3256 | $p_info['index'] = $p_header['index']; |
| 3257 | 3257 | $p_info['status'] = $p_header['status']; |
| 3258 | 3258 | $p_info['crc'] = $p_header['crc']; |
@@ -3280,17 +3280,17 @@ discard block |
||
| 3280 | 3280 | // -------------------------------------------------------------------------------- |
| 3281 | 3281 | function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
| 3282 | 3282 | { |
| 3283 | - $v_result=1; |
|
| 3283 | + $v_result = 1; |
|
| 3284 | 3284 | |
| 3285 | 3285 | // ----- Magic quotes trick |
| 3286 | 3286 | $this->privDisableMagicQuotes(); |
| 3287 | 3287 | |
| 3288 | 3288 | // ----- Check the path |
| 3289 | - if ( ($p_path == "") |
|
| 3290 | - || ( (substr($p_path, 0, 1) != "/") |
|
| 3289 | + if (($p_path == "") |
|
| 3290 | + || ((substr($p_path, 0, 1) != "/") |
|
| 3291 | 3291 | && (substr($p_path, 0, 3) != "../") |
| 3292 | - && (substr($p_path,1,2)!=":/"))) |
|
| 3293 | - $p_path = "./".$p_path; |
|
| 3292 | + && (substr($p_path, 1, 2) != ":/"))) |
|
| 3293 | + $p_path = "./" . $p_path; |
|
| 3294 | 3294 | |
| 3295 | 3295 | // ----- Reduce the path last (and duplicated) '/' |
| 3296 | 3296 | if (($p_path != "./") && ($p_path != "/")) |
@@ -3298,7 +3298,7 @@ discard block |
||
| 3298 | 3298 | // ----- Look for the path end '/' |
| 3299 | 3299 | while (substr($p_path, -1) == "/") |
| 3300 | 3300 | { |
| 3301 | - $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
| 3301 | + $p_path = substr($p_path, 0, strlen($p_path) - 1); |
|
| 3302 | 3302 | } |
| 3303 | 3303 | } |
| 3304 | 3304 | |
@@ -3332,7 +3332,7 @@ discard block |
||
| 3332 | 3332 | |
| 3333 | 3333 | // ----- Read each entry |
| 3334 | 3334 | $j_start = 0; |
| 3335 | - for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
|
| 3335 | + for ($i = 0, $v_nb_extracted = 0; $i < $v_central_dir['entries']; $i++) |
|
| 3336 | 3336 | { |
| 3337 | 3337 | |
| 3338 | 3338 | // ----- Read next Central dir entry |
@@ -3371,17 +3371,17 @@ discard block |
||
| 3371 | 3371 | $v_extract = false; |
| 3372 | 3372 | |
| 3373 | 3373 | // ----- Look for extract by name rule |
| 3374 | - if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 3374 | + if ((isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 3375 | 3375 | && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
| 3376 | 3376 | |
| 3377 | 3377 | // ----- Look if the filename is in the list |
| 3378 | - for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { |
|
| 3378 | + for ($j = 0; ($j < sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { |
|
| 3379 | 3379 | |
| 3380 | 3380 | // ----- Look for a directory |
| 3381 | 3381 | if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
| 3382 | 3382 | |
| 3383 | 3383 | // ----- Look if the directory is in the filename path |
| 3384 | - if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 3384 | + if ((strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 3385 | 3385 | && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
| 3386 | 3386 | $v_extract = true; |
| 3387 | 3387 | } |
@@ -3406,7 +3406,7 @@ discard block |
||
| 3406 | 3406 | */ |
| 3407 | 3407 | |
| 3408 | 3408 | // ----- Look for extract by preg rule |
| 3409 | - else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 3409 | + else if ((isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 3410 | 3410 | && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
| 3411 | 3411 | |
| 3412 | 3412 | if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { |
@@ -3415,20 +3415,20 @@ discard block |
||
| 3415 | 3415 | } |
| 3416 | 3416 | |
| 3417 | 3417 | // ----- Look for extract by index rule |
| 3418 | - else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 3418 | + else if ((isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 3419 | 3419 | && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
| 3420 | 3420 | |
| 3421 | 3421 | // ----- Look if the index is in the list |
| 3422 | - for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { |
|
| 3422 | + for ($j = $j_start; ($j < sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { |
|
| 3423 | 3423 | |
| 3424 | - if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 3424 | + if (($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i <= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 3425 | 3425 | $v_extract = true; |
| 3426 | 3426 | } |
| 3427 | - if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 3428 | - $j_start = $j+1; |
|
| 3427 | + if ($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 3428 | + $j_start = $j + 1; |
|
| 3429 | 3429 | } |
| 3430 | 3430 | |
| 3431 | - if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
|
| 3431 | + if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start'] > $i) { |
|
| 3432 | 3432 | break; |
| 3433 | 3433 | } |
| 3434 | 3434 | } |
@@ -3440,21 +3440,21 @@ discard block |
||
| 3440 | 3440 | } |
| 3441 | 3441 | |
| 3442 | 3442 | // ----- Check compression method |
| 3443 | - if ( ($v_extract) |
|
| 3444 | - && ( ($v_header['compression'] != 8) |
|
| 3443 | + if (($v_extract) |
|
| 3444 | + && (($v_header['compression'] != 8) |
|
| 3445 | 3445 | && ($v_header['compression'] != 0))) { |
| 3446 | 3446 | $v_header['status'] = 'unsupported_compression'; |
| 3447 | 3447 | |
| 3448 | 3448 | // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
| 3449 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3450 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3449 | + if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3450 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) { |
|
| 3451 | 3451 | |
| 3452 | 3452 | $this->privSwapBackMagicQuotes(); |
| 3453 | 3453 | |
| 3454 | 3454 | PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, |
| 3455 | - "Filename '".$v_header['stored_filename']."' is " |
|
| 3455 | + "Filename '" . $v_header['stored_filename'] . "' is " |
|
| 3456 | 3456 | ."compressed by an unsupported compression " |
| 3457 | - ."method (".$v_header['compression'].") "); |
|
| 3457 | + ."method (" . $v_header['compression'] . ") "); |
|
| 3458 | 3458 | |
| 3459 | 3459 | return PclZip::errorCode(); |
| 3460 | 3460 | } |
@@ -3465,14 +3465,14 @@ discard block |
||
| 3465 | 3465 | $v_header['status'] = 'unsupported_encryption'; |
| 3466 | 3466 | |
| 3467 | 3467 | // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
| 3468 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3469 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3468 | + if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3469 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) { |
|
| 3470 | 3470 | |
| 3471 | 3471 | $this->privSwapBackMagicQuotes(); |
| 3472 | 3472 | |
| 3473 | 3473 | PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, |
| 3474 | 3474 | "Unsupported encryption for " |
| 3475 | - ." filename '".$v_header['stored_filename'] |
|
| 3475 | + ." filename '" . $v_header['stored_filename'] |
|
| 3476 | 3476 | ."'"); |
| 3477 | 3477 | |
| 3478 | 3478 | return PclZip::errorCode(); |
@@ -3547,7 +3547,7 @@ discard block |
||
| 3547 | 3547 | } |
| 3548 | 3548 | } |
| 3549 | 3549 | // ----- Look for extraction in standard output |
| 3550 | - elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) |
|
| 3550 | + elseif ((isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) |
|
| 3551 | 3551 | && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { |
| 3552 | 3552 | // ----- Extracting the file in standard output |
| 3553 | 3553 | $v_result1 = $this->privExtractFileInOutput($v_header, $p_options); |
@@ -3620,7 +3620,7 @@ discard block |
||
| 3620 | 3620 | // -------------------------------------------------------------------------------- |
| 3621 | 3621 | function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
| 3622 | 3622 | { |
| 3623 | - $v_result=1; |
|
| 3623 | + $v_result = 1; |
|
| 3624 | 3624 | |
| 3625 | 3625 | // ----- Read the file header |
| 3626 | 3626 | if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
@@ -3638,7 +3638,7 @@ discard block |
||
| 3638 | 3638 | // ----- Look for all path to remove |
| 3639 | 3639 | if ($p_remove_all_path == true) { |
| 3640 | 3640 | // ----- Look for folder entry that not need to be extracted |
| 3641 | - if (($p_entry['external']&0x00000010)==0x00000010) { |
|
| 3641 | + if (($p_entry['external'] & 0x00000010) == 0x00000010) { |
|
| 3642 | 3642 | |
| 3643 | 3643 | $p_entry['status'] = "filtered"; |
| 3644 | 3644 | |
@@ -3674,7 +3674,7 @@ discard block |
||
| 3674 | 3674 | |
| 3675 | 3675 | // ----- Add the path |
| 3676 | 3676 | if ($p_path != '') { |
| 3677 | - $p_entry['filename'] = $p_path."/".$p_entry['filename']; |
|
| 3677 | + $p_entry['filename'] = $p_path . "/" . $p_entry['filename']; |
|
| 3678 | 3678 | } |
| 3679 | 3679 | |
| 3680 | 3680 | // ----- Check a base_dir_restriction |
@@ -3685,7 +3685,7 @@ discard block |
||
| 3685 | 3685 | if ($v_inclusion == 0) { |
| 3686 | 3686 | |
| 3687 | 3687 | PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, |
| 3688 | - "Filename '".$p_entry['filename']."' is " |
|
| 3688 | + "Filename '" . $p_entry['filename'] . "' is " |
|
| 3689 | 3689 | ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); |
| 3690 | 3690 | |
| 3691 | 3691 | return PclZip::errorCode(); |
@@ -3740,11 +3740,11 @@ discard block |
||
| 3740 | 3740 | // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
| 3741 | 3741 | // For historical reason first PclZip implementation does not stop |
| 3742 | 3742 | // when this kind of error occurs. |
| 3743 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3744 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3743 | + if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3744 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) { |
|
| 3745 | 3745 | |
| 3746 | 3746 | PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, |
| 3747 | - "Filename '".$p_entry['filename']."' is " |
|
| 3747 | + "Filename '" . $p_entry['filename'] . "' is " |
|
| 3748 | 3748 | ."already used by an existing directory"); |
| 3749 | 3749 | |
| 3750 | 3750 | return PclZip::errorCode(); |
@@ -3760,11 +3760,11 @@ discard block |
||
| 3760 | 3760 | // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
| 3761 | 3761 | // For historical reason first PclZip implementation does not stop |
| 3762 | 3762 | // when this kind of error occurs. |
| 3763 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3764 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3763 | + if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3764 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) { |
|
| 3765 | 3765 | |
| 3766 | 3766 | PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
| 3767 | - "Filename '".$p_entry['filename']."' exists " |
|
| 3767 | + "Filename '" . $p_entry['filename'] . "' exists " |
|
| 3768 | 3768 | ."and is write protected"); |
| 3769 | 3769 | |
| 3770 | 3770 | return PclZip::errorCode(); |
@@ -3775,8 +3775,8 @@ discard block |
||
| 3775 | 3775 | else if (filemtime($p_entry['filename']) > $p_entry['mtime']) |
| 3776 | 3776 | { |
| 3777 | 3777 | // ----- Change the file status |
| 3778 | - if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) |
|
| 3779 | - && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { |
|
| 3778 | + if ((isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) |
|
| 3779 | + && ($p_options[PCLZIP_OPT_REPLACE_NEWER] === true)) { |
|
| 3780 | 3780 | } |
| 3781 | 3781 | else { |
| 3782 | 3782 | $p_entry['status'] = "newer_exist"; |
@@ -3784,11 +3784,11 @@ discard block |
||
| 3784 | 3784 | // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
| 3785 | 3785 | // For historical reason first PclZip implementation does not stop |
| 3786 | 3786 | // when this kind of error occurs. |
| 3787 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3788 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3787 | + if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3788 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) { |
|
| 3789 | 3789 | |
| 3790 | 3790 | PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
| 3791 | - "Newer version of '".$p_entry['filename']."' exists " |
|
| 3791 | + "Newer version of '" . $p_entry['filename'] . "' exists " |
|
| 3792 | 3792 | ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); |
| 3793 | 3793 | |
| 3794 | 3794 | return PclZip::errorCode(); |
@@ -3801,14 +3801,14 @@ discard block |
||
| 3801 | 3801 | |
| 3802 | 3802 | // ----- Check the directory availability and create it if necessary |
| 3803 | 3803 | else { |
| 3804 | - if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) |
|
| 3804 | + if ((($p_entry['external'] & 0x00000010) == 0x00000010) || (substr($p_entry['filename'], -1) == '/')) |
|
| 3805 | 3805 | $v_dir_to_check = $p_entry['filename']; |
| 3806 | 3806 | else if (!strstr($p_entry['filename'], "/")) |
| 3807 | 3807 | $v_dir_to_check = ""; |
| 3808 | 3808 | else |
| 3809 | 3809 | $v_dir_to_check = dirname($p_entry['filename']); |
| 3810 | 3810 | |
| 3811 | - if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { |
|
| 3811 | + if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external'] & 0x00000010) == 0x00000010))) != 1) { |
|
| 3812 | 3812 | |
| 3813 | 3813 | // ----- Change the file status |
| 3814 | 3814 | $p_entry['status'] = "path_creation_fail"; |
@@ -3824,7 +3824,7 @@ discard block |
||
| 3824 | 3824 | if ($p_entry['status'] == 'ok') { |
| 3825 | 3825 | |
| 3826 | 3826 | // ----- Do the extraction (if not a folder) |
| 3827 | - if (!(($p_entry['external']&0x00000010)==0x00000010)) |
|
| 3827 | + if (!(($p_entry['external'] & 0x00000010) == 0x00000010)) |
|
| 3828 | 3828 | { |
| 3829 | 3829 | // ----- Look for not compressed file |
| 3830 | 3830 | if ($p_entry['compression'] == 0) { |
@@ -3867,16 +3867,16 @@ discard block |
||
| 3867 | 3867 | // ----- TBC |
| 3868 | 3868 | // Need to be finished |
| 3869 | 3869 | if (($p_entry['flag'] & 1) == 1) { |
| 3870 | - PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.'); |
|
| 3870 | + PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \'' . $p_entry['filename'] . '\' is encrypted. Encrypted files are not supported.'); |
|
| 3871 | 3871 | return PclZip::errorCode(); |
| 3872 | 3872 | } |
| 3873 | 3873 | |
| 3874 | 3874 | |
| 3875 | 3875 | // ----- Look for using temporary file to unzip |
| 3876 | - if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 3876 | + if ((!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 3877 | 3877 | && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
| 3878 | 3878 | || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
| 3879 | - && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) { |
|
| 3879 | + && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])))) { |
|
| 3880 | 3880 | $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options); |
| 3881 | 3881 | if ($v_result < PCLZIP_ERR_NO_ERROR) { |
| 3882 | 3882 | return $v_result; |
@@ -3971,13 +3971,13 @@ discard block |
||
| 3971 | 3971 | // -------------------------------------------------------------------------------- |
| 3972 | 3972 | function privExtractFileUsingTempFile(&$p_entry, &$p_options) |
| 3973 | 3973 | { |
| 3974 | - $v_result=1; |
|
| 3974 | + $v_result = 1; |
|
| 3975 | 3975 | |
| 3976 | 3976 | // ----- Creates a temporary file |
| 3977 | - $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; |
|
| 3977 | + $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR . uniqid('pclzip-') . '.gz'; |
|
| 3978 | 3978 | if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) { |
| 3979 | 3979 | fclose($v_file); |
| 3980 | - PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
|
| 3980 | + PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \'' . $v_gzip_temp_name . '\' in binary write mode'); |
|
| 3981 | 3981 | return PclZip::errorCode(); |
| 3982 | 3982 | } |
| 3983 | 3983 | |
@@ -4014,7 +4014,7 @@ discard block |
||
| 4014 | 4014 | if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) { |
| 4015 | 4015 | @fclose($v_dest_file); |
| 4016 | 4016 | $p_entry['status'] = "read_error"; |
| 4017 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 4017 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \'' . $v_gzip_temp_name . '\' in binary read mode'); |
|
| 4018 | 4018 | return PclZip::errorCode(); |
| 4019 | 4019 | } |
| 4020 | 4020 | |
@@ -4047,7 +4047,7 @@ discard block |
||
| 4047 | 4047 | // -------------------------------------------------------------------------------- |
| 4048 | 4048 | function privExtractFileInOutput(&$p_entry, &$p_options) |
| 4049 | 4049 | { |
| 4050 | - $v_result=1; |
|
| 4050 | + $v_result = 1; |
|
| 4051 | 4051 | |
| 4052 | 4052 | // ----- Read the file header |
| 4053 | 4053 | if (($v_result = $this->privReadFileHeader($v_header)) != 1) { |
@@ -4096,7 +4096,7 @@ discard block |
||
| 4096 | 4096 | if ($p_entry['status'] == 'ok') { |
| 4097 | 4097 | |
| 4098 | 4098 | // ----- Do the extraction (if not a folder) |
| 4099 | - if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
|
| 4099 | + if (!(($p_entry['external'] & 0x00000010) == 0x00000010)) { |
|
| 4100 | 4100 | // ----- Look for not compressed file |
| 4101 | 4101 | if ($p_entry['compressed_size'] == $p_entry['size']) { |
| 4102 | 4102 | |
@@ -4159,7 +4159,7 @@ discard block |
||
| 4159 | 4159 | // -------------------------------------------------------------------------------- |
| 4160 | 4160 | function privExtractFileAsString(&$p_entry, &$p_string, &$p_options) |
| 4161 | 4161 | { |
| 4162 | - $v_result=1; |
|
| 4162 | + $v_result = 1; |
|
| 4163 | 4163 | |
| 4164 | 4164 | // ----- Read the file header |
| 4165 | 4165 | $v_header = array(); |
@@ -4210,7 +4210,7 @@ discard block |
||
| 4210 | 4210 | if ($p_entry['status'] == 'ok') { |
| 4211 | 4211 | |
| 4212 | 4212 | // ----- Do the extraction (if not a folder) |
| 4213 | - if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
|
| 4213 | + if (!(($p_entry['external'] & 0x00000010) == 0x00000010)) { |
|
| 4214 | 4214 | // ----- Look for not compressed file |
| 4215 | 4215 | // if ($p_entry['compressed_size'] == $p_entry['size']) |
| 4216 | 4216 | if ($p_entry['compression'] == 0) { |
@@ -4282,7 +4282,7 @@ discard block |
||
| 4282 | 4282 | // -------------------------------------------------------------------------------- |
| 4283 | 4283 | function privReadFileHeader(&$p_header) |
| 4284 | 4284 | { |
| 4285 | - $v_result=1; |
|
| 4285 | + $v_result = 1; |
|
| 4286 | 4286 | |
| 4287 | 4287 | // ----- Read the 4 bytes signature |
| 4288 | 4288 | $v_binary_data = @fread($this->zip_fd, 4); |
@@ -4309,7 +4309,7 @@ discard block |
||
| 4309 | 4309 | $p_header['status'] = "invalid_header"; |
| 4310 | 4310 | |
| 4311 | 4311 | // ----- Error log |
| 4312 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
|
| 4312 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : " . strlen($v_binary_data)); |
|
| 4313 | 4313 | |
| 4314 | 4314 | // ----- Return |
| 4315 | 4315 | return PclZip::errorCode(); |
@@ -4346,7 +4346,7 @@ discard block |
||
| 4346 | 4346 | // ----- Extract time |
| 4347 | 4347 | $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
| 4348 | 4348 | $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
| 4349 | - $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
|
| 4349 | + $v_seconde = ($p_header['mtime'] & 0x001F) * 2; |
|
| 4350 | 4350 | |
| 4351 | 4351 | // ----- Extract date |
| 4352 | 4352 | $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
@@ -4385,7 +4385,7 @@ discard block |
||
| 4385 | 4385 | // -------------------------------------------------------------------------------- |
| 4386 | 4386 | function privReadCentralFileHeader(&$p_header) |
| 4387 | 4387 | { |
| 4388 | - $v_result=1; |
|
| 4388 | + $v_result = 1; |
|
| 4389 | 4389 | |
| 4390 | 4390 | // ----- Read the 4 bytes signature |
| 4391 | 4391 | $v_binary_data = @fread($this->zip_fd, 4); |
@@ -4412,7 +4412,7 @@ discard block |
||
| 4412 | 4412 | $p_header['status'] = "invalid_header"; |
| 4413 | 4413 | |
| 4414 | 4414 | // ----- Error log |
| 4415 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
|
| 4415 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : " . strlen($v_binary_data)); |
|
| 4416 | 4416 | |
| 4417 | 4417 | // ----- Return |
| 4418 | 4418 | return PclZip::errorCode(); |
@@ -4449,7 +4449,7 @@ discard block |
||
| 4449 | 4449 | // ----- Extract time |
| 4450 | 4450 | $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
| 4451 | 4451 | $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
| 4452 | - $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
|
| 4452 | + $v_seconde = ($p_header['mtime'] & 0x001F) * 2; |
|
| 4453 | 4453 | |
| 4454 | 4454 | // ----- Extract date |
| 4455 | 4455 | $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
@@ -4493,7 +4493,7 @@ discard block |
||
| 4493 | 4493 | // -------------------------------------------------------------------------------- |
| 4494 | 4494 | function privCheckFileHeaders(&$p_local_header, &$p_central_header) |
| 4495 | 4495 | { |
| 4496 | - $v_result=1; |
|
| 4496 | + $v_result = 1; |
|
| 4497 | 4497 | |
| 4498 | 4498 | // ----- Check the static values |
| 4499 | 4499 | // TBC |
@@ -4530,7 +4530,7 @@ discard block |
||
| 4530 | 4530 | // -------------------------------------------------------------------------------- |
| 4531 | 4531 | function privReadEndCentralDir(&$p_central_dir) |
| 4532 | 4532 | { |
| 4533 | - $v_result=1; |
|
| 4533 | + $v_result = 1; |
|
| 4534 | 4534 | |
| 4535 | 4535 | // ----- Go to the end of the zip file |
| 4536 | 4536 | $v_size = filesize($this->zipname); |
@@ -4538,7 +4538,7 @@ discard block |
||
| 4538 | 4538 | if (@ftell($this->zip_fd) != $v_size) |
| 4539 | 4539 | { |
| 4540 | 4540 | // ----- Error log |
| 4541 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); |
|
| 4541 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \'' . $this->zipname . '\''); |
|
| 4542 | 4542 | |
| 4543 | 4543 | // ----- Return |
| 4544 | 4544 | return PclZip::errorCode(); |
@@ -4548,11 +4548,11 @@ discard block |
||
| 4548 | 4548 | // in this case the end of central dir is at 22 bytes of the file end |
| 4549 | 4549 | $v_found = 0; |
| 4550 | 4550 | if ($v_size > 26) { |
| 4551 | - @fseek($this->zip_fd, $v_size-22); |
|
| 4552 | - if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) |
|
| 4551 | + @fseek($this->zip_fd, $v_size - 22); |
|
| 4552 | + if (($v_pos = @ftell($this->zip_fd)) != ($v_size - 22)) |
|
| 4553 | 4553 | { |
| 4554 | 4554 | // ----- Error log |
| 4555 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
|
| 4555 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \'' . $this->zipname . '\''); |
|
| 4556 | 4556 | |
| 4557 | 4557 | // ----- Return |
| 4558 | 4558 | return PclZip::errorCode(); |
@@ -4575,11 +4575,11 @@ discard block |
||
| 4575 | 4575 | $v_maximum_size = 65557; // 0xFFFF + 22; |
| 4576 | 4576 | if ($v_maximum_size > $v_size) |
| 4577 | 4577 | $v_maximum_size = $v_size; |
| 4578 | - @fseek($this->zip_fd, $v_size-$v_maximum_size); |
|
| 4579 | - if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) |
|
| 4578 | + @fseek($this->zip_fd, $v_size - $v_maximum_size); |
|
| 4579 | + if (@ftell($this->zip_fd) != ($v_size - $v_maximum_size)) |
|
| 4580 | 4580 | { |
| 4581 | 4581 | // ----- Error log |
| 4582 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
|
| 4582 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \'' . $this->zipname . '\''); |
|
| 4583 | 4583 | |
| 4584 | 4584 | // ----- Return |
| 4585 | 4585 | return PclZip::errorCode(); |
@@ -4597,7 +4597,7 @@ discard block |
||
| 4597 | 4597 | //$v_bytes = ($v_bytes << 8) | Ord($v_byte); |
| 4598 | 4598 | // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number |
| 4599 | 4599 | // Otherwise on systems where we have 64bit integers the check below for the magic number will fail. |
| 4600 | - $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); |
|
| 4600 | + $v_bytes = (($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); |
|
| 4601 | 4601 | |
| 4602 | 4602 | // ----- Compare the bytes |
| 4603 | 4603 | if ($v_bytes == 0x504b0506) |
@@ -4629,7 +4629,7 @@ discard block |
||
| 4629 | 4629 | { |
| 4630 | 4630 | |
| 4631 | 4631 | // ----- Error log |
| 4632 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); |
|
| 4632 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : " . strlen($v_binary_data)); |
|
| 4633 | 4633 | |
| 4634 | 4634 | // ----- Return |
| 4635 | 4635 | return PclZip::errorCode(); |
@@ -4687,11 +4687,11 @@ discard block |
||
| 4687 | 4687 | // -------------------------------------------------------------------------------- |
| 4688 | 4688 | function privDeleteByRule(&$p_result_list, &$p_options) |
| 4689 | 4689 | { |
| 4690 | - $v_result=1; |
|
| 4690 | + $v_result = 1; |
|
| 4691 | 4691 | $v_list_detail = array(); |
| 4692 | 4692 | |
| 4693 | 4693 | // ----- Open the zip file |
| 4694 | - if (($v_result=$this->privOpenFd('rb')) != 1) |
|
| 4694 | + if (($v_result = $this->privOpenFd('rb')) != 1) |
|
| 4695 | 4695 | { |
| 4696 | 4696 | // ----- Return |
| 4697 | 4697 | return $v_result; |
@@ -4727,7 +4727,7 @@ discard block |
||
| 4727 | 4727 | // ----- Read each entry |
| 4728 | 4728 | $v_header_list = array(); |
| 4729 | 4729 | $j_start = 0; |
| 4730 | - for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
|
| 4730 | + for ($i = 0, $v_nb_extracted = 0; $i < $v_central_dir['entries']; $i++) |
|
| 4731 | 4731 | { |
| 4732 | 4732 | |
| 4733 | 4733 | // ----- Read the file header |
@@ -4748,22 +4748,22 @@ discard block |
||
| 4748 | 4748 | $v_found = false; |
| 4749 | 4749 | |
| 4750 | 4750 | // ----- Look for extract by name rule |
| 4751 | - if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 4751 | + if ((isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 4752 | 4752 | && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
| 4753 | 4753 | |
| 4754 | 4754 | // ----- Look if the filename is in the list |
| 4755 | - for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { |
|
| 4755 | + for ($j = 0; ($j < sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { |
|
| 4756 | 4756 | |
| 4757 | 4757 | // ----- Look for a directory |
| 4758 | 4758 | if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
| 4759 | 4759 | |
| 4760 | 4760 | // ----- Look if the directory is in the filename path |
| 4761 | - if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 4761 | + if ((strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 4762 | 4762 | && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
| 4763 | 4763 | $v_found = true; |
| 4764 | 4764 | } |
| 4765 | - elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ |
|
| 4766 | - && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
|
| 4765 | + elseif ((($v_header_list[$v_nb_extracted]['external'] & 0x00000010) == 0x00000010) /* Indicates a folder */ |
|
| 4766 | + && ($v_header_list[$v_nb_extracted]['stored_filename'] . '/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
|
| 4767 | 4767 | $v_found = true; |
| 4768 | 4768 | } |
| 4769 | 4769 | } |
@@ -4787,7 +4787,7 @@ discard block |
||
| 4787 | 4787 | */ |
| 4788 | 4788 | |
| 4789 | 4789 | // ----- Look for extract by preg rule |
| 4790 | - else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 4790 | + else if ((isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 4791 | 4791 | && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
| 4792 | 4792 | |
| 4793 | 4793 | if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { |
@@ -4796,20 +4796,20 @@ discard block |
||
| 4796 | 4796 | } |
| 4797 | 4797 | |
| 4798 | 4798 | // ----- Look for extract by index rule |
| 4799 | - else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 4799 | + else if ((isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 4800 | 4800 | && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
| 4801 | 4801 | |
| 4802 | 4802 | // ----- Look if the index is in the list |
| 4803 | - for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { |
|
| 4803 | + for ($j = $j_start; ($j < sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { |
|
| 4804 | 4804 | |
| 4805 | - if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 4805 | + if (($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i <= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 4806 | 4806 | $v_found = true; |
| 4807 | 4807 | } |
| 4808 | - if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 4809 | - $j_start = $j+1; |
|
| 4808 | + if ($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 4809 | + $j_start = $j + 1; |
|
| 4810 | 4810 | } |
| 4811 | 4811 | |
| 4812 | - if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
|
| 4812 | + if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start'] > $i) { |
|
| 4813 | 4813 | break; |
| 4814 | 4814 | } |
| 4815 | 4815 | } |
@@ -4833,7 +4833,7 @@ discard block |
||
| 4833 | 4833 | if ($v_nb_extracted > 0) { |
| 4834 | 4834 | |
| 4835 | 4835 | // ----- Creates a temporay file |
| 4836 | - $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
|
| 4836 | + $v_zip_temp_name = PCLZIP_TEMPORARY_DIR . uniqid('pclzip-') . '.tmp'; |
|
| 4837 | 4837 | |
| 4838 | 4838 | // ----- Creates a temporary zip archive |
| 4839 | 4839 | $v_temp_zip = new PclZip($v_zip_temp_name); |
@@ -4847,11 +4847,11 @@ discard block |
||
| 4847 | 4847 | } |
| 4848 | 4848 | |
| 4849 | 4849 | // ----- Look which file need to be kept |
| 4850 | - for ($i=0; $i<sizeof($v_header_list); $i++) { |
|
| 4850 | + for ($i = 0; $i < sizeof($v_header_list); $i++) { |
|
| 4851 | 4851 | |
| 4852 | 4852 | // ----- Calculate the position of the header |
| 4853 | 4853 | @rewind($this->zip_fd); |
| 4854 | - if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { |
|
| 4854 | + if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { |
|
| 4855 | 4855 | // ----- Close the zip file |
| 4856 | 4856 | $this->privCloseFd(); |
| 4857 | 4857 | $v_temp_zip->privCloseFd(); |
@@ -4910,7 +4910,7 @@ discard block |
||
| 4910 | 4910 | $v_offset = @ftell($v_temp_zip->zip_fd); |
| 4911 | 4911 | |
| 4912 | 4912 | // ----- Re-Create the Central Dir files header |
| 4913 | - for ($i=0; $i<sizeof($v_header_list); $i++) { |
|
| 4913 | + for ($i = 0; $i < sizeof($v_header_list); $i++) { |
|
| 4914 | 4914 | // ----- Create the file header |
| 4915 | 4915 | if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
| 4916 | 4916 | $v_temp_zip->privCloseFd(); |
@@ -4933,7 +4933,7 @@ discard block |
||
| 4933 | 4933 | } |
| 4934 | 4934 | |
| 4935 | 4935 | // ----- Calculate the size of the central header |
| 4936 | - $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset; |
|
| 4936 | + $v_size = @ftell($v_temp_zip->zip_fd) - $v_offset; |
|
| 4937 | 4937 | |
| 4938 | 4938 | // ----- Create the central dir footer |
| 4939 | 4939 | if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) { |
@@ -4995,15 +4995,15 @@ discard block |
||
| 4995 | 4995 | // 1 : OK |
| 4996 | 4996 | // -1 : Unable to create directory |
| 4997 | 4997 | // -------------------------------------------------------------------------------- |
| 4998 | - function privDirCheck($p_dir, $p_is_dir=false) |
|
| 4998 | + function privDirCheck($p_dir, $p_is_dir = false) |
|
| 4999 | 4999 | { |
| 5000 | 5000 | $v_result = 1; |
| 5001 | 5001 | |
| 5002 | 5002 | |
| 5003 | 5003 | // ----- Remove the final '/' |
| 5004 | - if (($p_is_dir) && (substr($p_dir, -1)=='/')) |
|
| 5004 | + if (($p_is_dir) && (substr($p_dir, -1) == '/')) |
|
| 5005 | 5005 | { |
| 5006 | - $p_dir = substr($p_dir, 0, strlen($p_dir)-1); |
|
| 5006 | + $p_dir = substr($p_dir, 0, strlen($p_dir) - 1); |
|
| 5007 | 5007 | } |
| 5008 | 5008 | |
| 5009 | 5009 | // ----- Check the directory availability |
@@ -5052,7 +5052,7 @@ discard block |
||
| 5052 | 5052 | // -------------------------------------------------------------------------------- |
| 5053 | 5053 | function privMerge(&$p_archive_to_add) |
| 5054 | 5054 | { |
| 5055 | - $v_result=1; |
|
| 5055 | + $v_result = 1; |
|
| 5056 | 5056 | |
| 5057 | 5057 | // ----- Look if the archive_to_add exists |
| 5058 | 5058 | if (!is_file($p_archive_to_add->zipname)) |
@@ -5077,7 +5077,7 @@ discard block |
||
| 5077 | 5077 | } |
| 5078 | 5078 | |
| 5079 | 5079 | // ----- Open the zip file |
| 5080 | - if (($v_result=$this->privOpenFd('rb')) != 1) |
|
| 5080 | + if (($v_result = $this->privOpenFd('rb')) != 1) |
|
| 5081 | 5081 | { |
| 5082 | 5082 | // ----- Return |
| 5083 | 5083 | return $v_result; |
@@ -5095,7 +5095,7 @@ discard block |
||
| 5095 | 5095 | @rewind($this->zip_fd); |
| 5096 | 5096 | |
| 5097 | 5097 | // ----- Open the archive_to_add file |
| 5098 | - if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) |
|
| 5098 | + if (($v_result = $p_archive_to_add->privOpenFd('rb')) != 1) |
|
| 5099 | 5099 | { |
| 5100 | 5100 | $this->privCloseFd(); |
| 5101 | 5101 | |
@@ -5117,7 +5117,7 @@ discard block |
||
| 5117 | 5117 | @rewind($p_archive_to_add->zip_fd); |
| 5118 | 5118 | |
| 5119 | 5119 | // ----- Creates a temporay file |
| 5120 | - $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
|
| 5120 | + $v_zip_temp_name = PCLZIP_TEMPORARY_DIR . uniqid('pclzip-') . '.tmp'; |
|
| 5121 | 5121 | |
| 5122 | 5122 | // ----- Open the temporary file in write mode |
| 5123 | 5123 | if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
@@ -5125,7 +5125,7 @@ discard block |
||
| 5125 | 5125 | $this->privCloseFd(); |
| 5126 | 5126 | $p_archive_to_add->privCloseFd(); |
| 5127 | 5127 | |
| 5128 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
|
| 5128 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \'' . $v_zip_temp_name . '\' in binary write mode'); |
|
| 5129 | 5129 | |
| 5130 | 5130 | // ----- Return |
| 5131 | 5131 | return PclZip::errorCode(); |
@@ -5176,10 +5176,10 @@ discard block |
||
| 5176 | 5176 | } |
| 5177 | 5177 | |
| 5178 | 5178 | // ----- Merge the file comments |
| 5179 | - $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment']; |
|
| 5179 | + $v_comment = $v_central_dir['comment'] . ' ' . $v_central_dir_to_add['comment']; |
|
| 5180 | 5180 | |
| 5181 | 5181 | // ----- Calculate the size of the (new) central header |
| 5182 | - $v_size = @ftell($v_zip_temp_fd)-$v_offset; |
|
| 5182 | + $v_size = @ftell($v_zip_temp_fd) - $v_offset; |
|
| 5183 | 5183 | |
| 5184 | 5184 | // ----- Swap the file descriptor |
| 5185 | 5185 | // Here is a trick : I swap the temporary fd with the zip fd, in order to use |
@@ -5189,7 +5189,7 @@ discard block |
||
| 5189 | 5189 | $v_zip_temp_fd = $v_swap; |
| 5190 | 5190 | |
| 5191 | 5191 | // ----- Create the central dir footer |
| 5192 | - if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) |
|
| 5192 | + if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries'] + $v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) |
|
| 5193 | 5193 | { |
| 5194 | 5194 | $this->privCloseFd(); |
| 5195 | 5195 | $p_archive_to_add->privCloseFd(); |
@@ -5237,7 +5237,7 @@ discard block |
||
| 5237 | 5237 | // -------------------------------------------------------------------------------- |
| 5238 | 5238 | function privDuplicate($p_archive_filename) |
| 5239 | 5239 | { |
| 5240 | - $v_result=1; |
|
| 5240 | + $v_result = 1; |
|
| 5241 | 5241 | |
| 5242 | 5242 | // ----- Look if the $p_archive_filename exists |
| 5243 | 5243 | if (!is_file($p_archive_filename)) |
@@ -5251,7 +5251,7 @@ discard block |
||
| 5251 | 5251 | } |
| 5252 | 5252 | |
| 5253 | 5253 | // ----- Open the zip file |
| 5254 | - if (($v_result=$this->privOpenFd('wb')) != 1) |
|
| 5254 | + if (($v_result = $this->privOpenFd('wb')) != 1) |
|
| 5255 | 5255 | { |
| 5256 | 5256 | // ----- Return |
| 5257 | 5257 | return $v_result; |
@@ -5262,7 +5262,7 @@ discard block |
||
| 5262 | 5262 | { |
| 5263 | 5263 | $this->privCloseFd(); |
| 5264 | 5264 | |
| 5265 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); |
|
| 5265 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \'' . $p_archive_filename . '\' in binary write mode'); |
|
| 5266 | 5266 | |
| 5267 | 5267 | // ----- Return |
| 5268 | 5268 | return PclZip::errorCode(); |
@@ -5295,7 +5295,7 @@ discard block |
||
| 5295 | 5295 | // Description : |
| 5296 | 5296 | // Parameters : |
| 5297 | 5297 | // -------------------------------------------------------------------------------- |
| 5298 | - function privErrorLog($p_error_code=0, $p_error_string='') |
|
| 5298 | + function privErrorLog($p_error_code = 0, $p_error_string = '') |
|
| 5299 | 5299 | { |
| 5300 | 5300 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 5301 | 5301 | PclError($p_error_code, $p_error_string); |
@@ -5332,10 +5332,10 @@ discard block |
||
| 5332 | 5332 | // -------------------------------------------------------------------------------- |
| 5333 | 5333 | function privDisableMagicQuotes() |
| 5334 | 5334 | { |
| 5335 | - $v_result=1; |
|
| 5335 | + $v_result = 1; |
|
| 5336 | 5336 | |
| 5337 | 5337 | // ----- Look if function exists |
| 5338 | - if ( (!function_exists("get_magic_quotes_runtime")) |
|
| 5338 | + if ((!function_exists("get_magic_quotes_runtime")) |
|
| 5339 | 5339 | || (!function_exists("set_magic_quotes_runtime"))) { |
| 5340 | 5340 | return $v_result; |
| 5341 | 5341 | } |
@@ -5366,10 +5366,10 @@ discard block |
||
| 5366 | 5366 | // -------------------------------------------------------------------------------- |
| 5367 | 5367 | function privSwapBackMagicQuotes() |
| 5368 | 5368 | { |
| 5369 | - $v_result=1; |
|
| 5369 | + $v_result = 1; |
|
| 5370 | 5370 | |
| 5371 | 5371 | // ----- Look if function exists |
| 5372 | - if ( (!function_exists("get_magic_quotes_runtime")) |
|
| 5372 | + if ((!function_exists("get_magic_quotes_runtime")) |
|
| 5373 | 5373 | || (!function_exists("set_magic_quotes_runtime"))) { |
| 5374 | 5374 | return $v_result; |
| 5375 | 5375 | } |
@@ -5410,7 +5410,7 @@ discard block |
||
| 5410 | 5410 | |
| 5411 | 5411 | // ----- Study directories from last to first |
| 5412 | 5412 | $v_skip = 0; |
| 5413 | - for ($i=sizeof($v_list)-1; $i>=0; $i--) { |
|
| 5413 | + for ($i = sizeof($v_list) - 1; $i >= 0; $i--) { |
|
| 5414 | 5414 | // ----- Look for current path |
| 5415 | 5415 | if ($v_list[$i] == ".") { |
| 5416 | 5416 | // ----- Ignore this directory |
@@ -5422,7 +5422,7 @@ discard block |
||
| 5422 | 5422 | else if ($v_list[$i] == "") { |
| 5423 | 5423 | // ----- First '/' i.e. root slash |
| 5424 | 5424 | if ($i == 0) { |
| 5425 | - $v_result = "/".$v_result; |
|
| 5425 | + $v_result = "/" . $v_result; |
|
| 5426 | 5426 | if ($v_skip > 0) { |
| 5427 | 5427 | // ----- It is an invalid path, so the path is not modified |
| 5428 | 5428 | // TBC |
@@ -5431,7 +5431,7 @@ discard block |
||
| 5431 | 5431 | } |
| 5432 | 5432 | } |
| 5433 | 5433 | // ----- Last '/' i.e. indicates a directory |
| 5434 | - else if ($i == (sizeof($v_list)-1)) { |
|
| 5434 | + else if ($i == (sizeof($v_list) - 1)) { |
|
| 5435 | 5435 | $v_result = $v_list[$i]; |
| 5436 | 5436 | } |
| 5437 | 5437 | // ----- Double '/' inside the path |
@@ -5446,7 +5446,7 @@ discard block |
||
| 5446 | 5446 | $v_skip--; |
| 5447 | 5447 | } |
| 5448 | 5448 | else { |
| 5449 | - $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); |
|
| 5449 | + $v_result = $v_list[$i] . ($i != (sizeof($v_list) - 1) ? "/" . $v_result : ""); |
|
| 5450 | 5450 | } |
| 5451 | 5451 | } |
| 5452 | 5452 | } |
@@ -5454,7 +5454,7 @@ discard block |
||
| 5454 | 5454 | // ----- Look for skip |
| 5455 | 5455 | if ($v_skip > 0) { |
| 5456 | 5456 | while ($v_skip > 0) { |
| 5457 | - $v_result = '../'.$v_result; |
|
| 5457 | + $v_result = '../' . $v_result; |
|
| 5458 | 5458 | $v_skip--; |
| 5459 | 5459 | } |
| 5460 | 5460 | } |
@@ -5485,13 +5485,13 @@ discard block |
||
| 5485 | 5485 | $v_result = 1; |
| 5486 | 5486 | |
| 5487 | 5487 | // ----- Look for path beginning by ./ |
| 5488 | - if ( ($p_dir == '.') |
|
| 5489 | - || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { |
|
| 5490 | - $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); |
|
| 5488 | + if (($p_dir == '.') |
|
| 5489 | + || ((strlen($p_dir) >= 2) && (substr($p_dir, 0, 2) == './'))) { |
|
| 5490 | + $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE) . '/' . substr($p_dir, 1); |
|
| 5491 | 5491 | } |
| 5492 | - if ( ($p_path == '.') |
|
| 5493 | - || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) { |
|
| 5494 | - $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); |
|
| 5492 | + if (($p_path == '.') |
|
| 5493 | + || ((strlen($p_path) >= 2) && (substr($p_path, 0, 2) == './'))) { |
|
| 5494 | + $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE) . '/' . substr($p_path, 1); |
|
| 5495 | 5495 | } |
| 5496 | 5496 | |
| 5497 | 5497 | // ----- Explode dir and path by directory separator |
@@ -5516,7 +5516,7 @@ discard block |
||
| 5516 | 5516 | } |
| 5517 | 5517 | |
| 5518 | 5518 | // ----- Compare the items |
| 5519 | - if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { |
|
| 5519 | + if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ($v_list_path[$j] != '')) { |
|
| 5520 | 5520 | $v_result = 0; |
| 5521 | 5521 | } |
| 5522 | 5522 | |
@@ -5557,11 +5557,11 @@ discard block |
||
| 5557 | 5557 | // 3 : src & dest gzip |
| 5558 | 5558 | // Return Values : |
| 5559 | 5559 | // -------------------------------------------------------------------------------- |
| 5560 | - function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) |
|
| 5560 | + function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode = 0) |
|
| 5561 | 5561 | { |
| 5562 | 5562 | $v_result = 1; |
| 5563 | 5563 | |
| 5564 | - if ($p_mode==0) |
|
| 5564 | + if ($p_mode == 0) |
|
| 5565 | 5565 | { |
| 5566 | 5566 | while ($p_size != 0) |
| 5567 | 5567 | { |
@@ -5571,7 +5571,7 @@ discard block |
||
| 5571 | 5571 | $p_size -= $v_read_size; |
| 5572 | 5572 | } |
| 5573 | 5573 | } |
| 5574 | - else if ($p_mode==1) |
|
| 5574 | + else if ($p_mode == 1) |
|
| 5575 | 5575 | { |
| 5576 | 5576 | while ($p_size != 0) |
| 5577 | 5577 | { |
@@ -5581,7 +5581,7 @@ discard block |
||
| 5581 | 5581 | $p_size -= $v_read_size; |
| 5582 | 5582 | } |
| 5583 | 5583 | } |
| 5584 | - else if ($p_mode==2) |
|
| 5584 | + else if ($p_mode == 2) |
|
| 5585 | 5585 | { |
| 5586 | 5586 | while ($p_size != 0) |
| 5587 | 5587 | { |
@@ -5591,7 +5591,7 @@ discard block |
||
| 5591 | 5591 | $p_size -= $v_read_size; |
| 5592 | 5592 | } |
| 5593 | 5593 | } |
| 5594 | - else if ($p_mode==3) |
|
| 5594 | + else if ($p_mode == 3) |
|
| 5595 | 5595 | { |
| 5596 | 5596 | while ($p_size != 0) |
| 5597 | 5597 | { |
@@ -5655,7 +5655,7 @@ discard block |
||
| 5655 | 5655 | $v_list = get_defined_constants(); |
| 5656 | 5656 | for (reset($v_list); $v_key = key($v_list); next($v_list)) { |
| 5657 | 5657 | $v_prefix = substr($v_key, 0, 10); |
| 5658 | - if (( ($v_prefix == 'PCLZIP_OPT') |
|
| 5658 | + if ((($v_prefix == 'PCLZIP_OPT') |
|
| 5659 | 5659 | || ($v_prefix == 'PCLZIP_CB_') |
| 5660 | 5660 | || ($v_prefix == 'PCLZIP_ATT')) |
| 5661 | 5661 | && ($v_list[$v_key] == $p_option)) { |
@@ -5680,15 +5680,15 @@ discard block |
||
| 5680 | 5680 | // Return Values : |
| 5681 | 5681 | // The path translated. |
| 5682 | 5682 | // -------------------------------------------------------------------------------- |
| 5683 | - function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true) |
|
| 5683 | + function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter = true) |
|
| 5684 | 5684 | { |
| 5685 | 5685 | if (stristr(php_uname(), 'windows')) { |
| 5686 | 5686 | // ----- Look for potential disk letter |
| 5687 | 5687 | if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { |
| 5688 | - $p_path = substr($p_path, $v_position+1); |
|
| 5688 | + $p_path = substr($p_path, $v_position + 1); |
|
| 5689 | 5689 | } |
| 5690 | 5690 | // ----- Change potential windows directory separator |
| 5691 | - if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
| 5691 | + if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0, 1) == '\\')) { |
|
| 5692 | 5692 | $p_path = strtr($p_path, '\\', '/'); |
| 5693 | 5693 | } |
| 5694 | 5694 | } |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | // -------------------------------------------------------------------------------- |
| 3 | 5 | // PhpConcept Library - Zip Module 2.8.2 |
| 4 | 6 | // -------------------------------------------------------------------------------- |
@@ -330,8 +332,7 @@ discard block |
||
| 330 | 332 | // ----- Look for the optional second argument |
| 331 | 333 | if ($v_size == 2) { |
| 332 | 334 | $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
| 333 | - } |
|
| 334 | - else if ($v_size > 2) { |
|
| 335 | + } else if ($v_size > 2) { |
|
| 335 | 336 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
| 336 | 337 | "Invalid number / type of arguments"); |
| 337 | 338 | return 0; |
@@ -380,8 +381,7 @@ discard block |
||
| 380 | 381 | foreach ($v_string_list as $v_string) { |
| 381 | 382 | if ($v_string != '') { |
| 382 | 383 | $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; |
| 383 | - } |
|
| 384 | - else { |
|
| 384 | + } else { |
|
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | 387 | } |
@@ -515,8 +515,7 @@ discard block |
||
| 515 | 515 | // ----- Look for the optional second argument |
| 516 | 516 | if ($v_size == 2) { |
| 517 | 517 | $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
| 518 | - } |
|
| 519 | - else if ($v_size > 2) { |
|
| 518 | + } else if ($v_size > 2) { |
|
| 520 | 519 | // ----- Error log |
| 521 | 520 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
| 522 | 521 | |
@@ -792,8 +791,7 @@ discard block |
||
| 792 | 791 | // ----- Look for the optional second argument |
| 793 | 792 | if ($v_size == 2) { |
| 794 | 793 | $v_remove_path = $v_arg_list[1]; |
| 795 | - } |
|
| 796 | - else if ($v_size > 2) { |
|
| 794 | + } else if ($v_size > 2) { |
|
| 797 | 795 | // ----- Error log |
| 798 | 796 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
| 799 | 797 | |
@@ -937,8 +935,7 @@ discard block |
||
| 937 | 935 | } |
| 938 | 936 | if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) { |
| 939 | 937 | $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
| 940 | - } |
|
| 941 | - else { |
|
| 938 | + } else { |
|
| 942 | 939 | } |
| 943 | 940 | } |
| 944 | 941 | |
@@ -953,8 +950,7 @@ discard block |
||
| 953 | 950 | // ----- Look for the optional second argument |
| 954 | 951 | if ($v_size == 2) { |
| 955 | 952 | $v_remove_path = $v_arg_list[1]; |
| 956 | - } |
|
| 957 | - else if ($v_size > 2) { |
|
| 953 | + } else if ($v_size > 2) { |
|
| 958 | 954 | // ----- Error log |
| 959 | 955 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
| 960 | 956 | |
@@ -1190,8 +1186,7 @@ discard block |
||
| 1190 | 1186 | // ----- Error log |
| 1191 | 1187 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'"); |
| 1192 | 1188 | $v_result = PCLZIP_ERR_MISSING_FILE; |
| 1193 | - } |
|
| 1194 | - else { |
|
| 1189 | + } else { |
|
| 1195 | 1190 | // ----- Duplicate the archive |
| 1196 | 1191 | $v_result = $this->privDuplicate($p_archive); |
| 1197 | 1192 | } |
@@ -1279,8 +1274,7 @@ discard block |
||
| 1279 | 1274 | { |
| 1280 | 1275 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 1281 | 1276 | return(PclErrorCode()); |
| 1282 | - } |
|
| 1283 | - else { |
|
| 1277 | + } else { |
|
| 1284 | 1278 | return($this->error_code); |
| 1285 | 1279 | } |
| 1286 | 1280 | } |
@@ -1318,15 +1312,13 @@ discard block |
||
| 1318 | 1312 | |
| 1319 | 1313 | if (isset($v_name[$this->error_code])) { |
| 1320 | 1314 | $v_value = $v_name[$this->error_code]; |
| 1321 | - } |
|
| 1322 | - else { |
|
| 1315 | + } else { |
|
| 1323 | 1316 | $v_value = 'NoName'; |
| 1324 | 1317 | } |
| 1325 | 1318 | |
| 1326 | 1319 | if ($p_with_code) { |
| 1327 | 1320 | return($v_value.' ('.$this->error_code.')'); |
| 1328 | - } |
|
| 1329 | - else { |
|
| 1321 | + } else { |
|
| 1330 | 1322 | return($v_value); |
| 1331 | 1323 | } |
| 1332 | 1324 | } |
@@ -1341,12 +1333,10 @@ discard block |
||
| 1341 | 1333 | { |
| 1342 | 1334 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 1343 | 1335 | return(PclErrorString()); |
| 1344 | - } |
|
| 1345 | - else { |
|
| 1336 | + } else { |
|
| 1346 | 1337 | if ($p_full) { |
| 1347 | 1338 | return($this->errorName(true)." : ".$this->error_string); |
| 1348 | - } |
|
| 1349 | - else { |
|
| 1339 | + } else { |
|
| 1350 | 1340 | return($this->error_string." [code ".$this->error_code."]"); |
| 1351 | 1341 | } |
| 1352 | 1342 | } |
@@ -1531,8 +1521,7 @@ discard block |
||
| 1531 | 1521 | && ($p_options_list[$i+1] != '')) { |
| 1532 | 1522 | $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
| 1533 | 1523 | $i++; |
| 1534 | - } |
|
| 1535 | - else { |
|
| 1524 | + } else { |
|
| 1536 | 1525 | } |
| 1537 | 1526 | break; |
| 1538 | 1527 | |
@@ -1550,11 +1539,9 @@ discard block |
||
| 1550 | 1539 | // ----- Get the value |
| 1551 | 1540 | if (is_string($p_options_list[$i+1])) { |
| 1552 | 1541 | $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; |
| 1553 | - } |
|
| 1554 | - else if (is_array($p_options_list[$i+1])) { |
|
| 1542 | + } else if (is_array($p_options_list[$i+1])) { |
|
| 1555 | 1543 | $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
| 1556 | - } |
|
| 1557 | - else { |
|
| 1544 | + } else { |
|
| 1558 | 1545 | // ----- Error log |
| 1559 | 1546 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1560 | 1547 | |
@@ -1583,8 +1570,7 @@ discard block |
||
| 1583 | 1570 | // ----- Get the value |
| 1584 | 1571 | if (is_string($p_options_list[$i+1])) { |
| 1585 | 1572 | $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
| 1586 | - } |
|
| 1587 | - else { |
|
| 1573 | + } else { |
|
| 1588 | 1574 | // ----- Error log |
| 1589 | 1575 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1590 | 1576 | |
@@ -1613,8 +1599,7 @@ discard block |
||
| 1613 | 1599 | // ----- Get the value |
| 1614 | 1600 | if (is_string($p_options_list[$i+1])) { |
| 1615 | 1601 | $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
| 1616 | - } |
|
| 1617 | - else { |
|
| 1602 | + } else { |
|
| 1618 | 1603 | // ----- Error log |
| 1619 | 1604 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, |
| 1620 | 1605 | "Wrong parameter value for option '" |
@@ -1647,14 +1632,11 @@ discard block |
||
| 1647 | 1632 | |
| 1648 | 1633 | // ----- Parse items |
| 1649 | 1634 | $v_work_list = explode(",", $p_options_list[$i+1]); |
| 1650 | - } |
|
| 1651 | - else if (is_integer($p_options_list[$i+1])) { |
|
| 1635 | + } else if (is_integer($p_options_list[$i+1])) { |
|
| 1652 | 1636 | $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; |
| 1653 | - } |
|
| 1654 | - else if (is_array($p_options_list[$i+1])) { |
|
| 1637 | + } else if (is_array($p_options_list[$i+1])) { |
|
| 1655 | 1638 | $v_work_list = $p_options_list[$i+1]; |
| 1656 | - } |
|
| 1657 | - else { |
|
| 1639 | + } else { |
|
| 1658 | 1640 | // ----- Error log |
| 1659 | 1641 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1660 | 1642 | |
@@ -1681,13 +1663,11 @@ discard block |
||
| 1681 | 1663 | // ----- Set the option value |
| 1682 | 1664 | $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
| 1683 | 1665 | $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; |
| 1684 | - } |
|
| 1685 | - elseif ($v_size_item_list == 2) { |
|
| 1666 | + } elseif ($v_size_item_list == 2) { |
|
| 1686 | 1667 | // ----- Set the option value |
| 1687 | 1668 | $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
| 1688 | 1669 | $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1]; |
| 1689 | - } |
|
| 1690 | - else { |
|
| 1670 | + } else { |
|
| 1691 | 1671 | // ----- Error log |
| 1692 | 1672 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1693 | 1673 | |
@@ -1843,14 +1823,17 @@ discard block |
||
| 1843 | 1823 | $v_memory_limit = trim($v_memory_limit); |
| 1844 | 1824 | $last = strtolower(substr($v_memory_limit, -1)); |
| 1845 | 1825 | |
| 1846 | - if($last == 'g') |
|
| 1847 | - //$v_memory_limit = $v_memory_limit*1024*1024*1024; |
|
| 1826 | + if($last == 'g') { |
|
| 1827 | + //$v_memory_limit = $v_memory_limit*1024*1024*1024; |
|
| 1848 | 1828 | $v_memory_limit = $v_memory_limit*1073741824; |
| 1849 | - if($last == 'm') |
|
| 1850 | - //$v_memory_limit = $v_memory_limit*1024*1024; |
|
| 1829 | + } |
|
| 1830 | + if($last == 'm') { |
|
| 1831 | + //$v_memory_limit = $v_memory_limit*1024*1024; |
|
| 1851 | 1832 | $v_memory_limit = $v_memory_limit*1048576; |
| 1852 | - if($last == 'k') |
|
| 1853 | - $v_memory_limit = $v_memory_limit*1024; |
|
| 1833 | + } |
|
| 1834 | + if($last == 'k') { |
|
| 1835 | + $v_memory_limit = $v_memory_limit*1024; |
|
| 1836 | + } |
|
| 1854 | 1837 | |
| 1855 | 1838 | $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO); |
| 1856 | 1839 | |
@@ -2023,15 +2006,12 @@ discard block |
||
| 2023 | 2006 | if (file_exists($v_descr['filename'])) { |
| 2024 | 2007 | if (@is_file($v_descr['filename'])) { |
| 2025 | 2008 | $v_descr['type'] = 'file'; |
| 2026 | - } |
|
| 2027 | - else if (@is_dir($v_descr['filename'])) { |
|
| 2009 | + } else if (@is_dir($v_descr['filename'])) { |
|
| 2028 | 2010 | $v_descr['type'] = 'folder'; |
| 2029 | - } |
|
| 2030 | - else if (@is_link($v_descr['filename'])) { |
|
| 2011 | + } else if (@is_link($v_descr['filename'])) { |
|
| 2031 | 2012 | // skip |
| 2032 | 2013 | continue; |
| 2033 | - } |
|
| 2034 | - else { |
|
| 2014 | + } else { |
|
| 2035 | 2015 | // skip |
| 2036 | 2016 | continue; |
| 2037 | 2017 | } |
@@ -2080,8 +2060,7 @@ discard block |
||
| 2080 | 2060 | && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) { |
| 2081 | 2061 | if ($v_descr['stored_filename'] != '') { |
| 2082 | 2062 | $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; |
| 2083 | - } |
|
| 2084 | - else { |
|
| 2063 | + } else { |
|
| 2085 | 2064 | $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; |
| 2086 | 2065 | } |
| 2087 | 2066 | } |
@@ -2090,8 +2069,7 @@ discard block |
||
| 2090 | 2069 | } |
| 2091 | 2070 | |
| 2092 | 2071 | @closedir($v_folder_handler); |
| 2093 | - } |
|
| 2094 | - else { |
|
| 2072 | + } else { |
|
| 2095 | 2073 | // TBC : unable to open folder in read mode |
| 2096 | 2074 | } |
| 2097 | 2075 | |
@@ -2104,8 +2082,7 @@ discard block |
||
| 2104 | 2082 | |
| 2105 | 2083 | // ----- Concat the resulting list |
| 2106 | 2084 | $v_result_list = array_merge($v_result_list, $v_dirlist_descr); |
| 2107 | - } |
|
| 2108 | - else { |
|
| 2085 | + } else { |
|
| 2109 | 2086 | } |
| 2110 | 2087 | |
| 2111 | 2088 | // ----- Free local array |
@@ -2379,8 +2356,9 @@ discard block |
||
| 2379 | 2356 | { |
| 2380 | 2357 | $v_result=1; |
| 2381 | 2358 | |
| 2382 | - if ($this->zip_fd != 0) |
|
| 2383 | - @fclose($this->zip_fd); |
|
| 2359 | + if ($this->zip_fd != 0) { |
|
| 2360 | + @fclose($this->zip_fd); |
|
| 2361 | + } |
|
| 2384 | 2362 | $this->zip_fd = 0; |
| 2385 | 2363 | |
| 2386 | 2364 | // ----- Return |
@@ -2597,11 +2575,9 @@ discard block |
||
| 2597 | 2575 | // ----- Look for filetime |
| 2598 | 2576 | if (isset($p_filedescr['mtime'])) { |
| 2599 | 2577 | $p_header['mtime'] = $p_filedescr['mtime']; |
| 2600 | - } |
|
| 2601 | - else if ($p_filedescr['type'] == 'virtual_file') { |
|
| 2578 | + } else if ($p_filedescr['type'] == 'virtual_file') { |
|
| 2602 | 2579 | $p_header['mtime'] = time(); |
| 2603 | - } |
|
| 2604 | - else { |
|
| 2580 | + } else { |
|
| 2605 | 2581 | $p_header['mtime'] = filemtime($p_filename); |
| 2606 | 2582 | } |
| 2607 | 2583 | |
@@ -2609,8 +2585,7 @@ discard block |
||
| 2609 | 2585 | if (isset($p_filedescr['comment'])) { |
| 2610 | 2586 | $p_header['comment_len'] = strlen($p_filedescr['comment']); |
| 2611 | 2587 | $p_header['comment'] = $p_filedescr['comment']; |
| 2612 | - } |
|
| 2613 | - else { |
|
| 2588 | + } else { |
|
| 2614 | 2589 | $p_header['comment_len'] = 0; |
| 2615 | 2590 | $p_header['comment'] = ''; |
| 2616 | 2591 | } |
@@ -2921,20 +2896,17 @@ discard block |
||
| 2921 | 2896 | $p_filename = $p_filedescr['filename']; |
| 2922 | 2897 | if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { |
| 2923 | 2898 | $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; |
| 2924 | - } |
|
| 2925 | - else { |
|
| 2899 | + } else { |
|
| 2926 | 2900 | $p_add_dir = ''; |
| 2927 | 2901 | } |
| 2928 | 2902 | if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) { |
| 2929 | 2903 | $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; |
| 2930 | - } |
|
| 2931 | - else { |
|
| 2904 | + } else { |
|
| 2932 | 2905 | $p_remove_dir = ''; |
| 2933 | 2906 | } |
| 2934 | 2907 | if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
| 2935 | 2908 | $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
| 2936 | - } |
|
| 2937 | - else { |
|
| 2909 | + } else { |
|
| 2938 | 2910 | $p_remove_all_dir = 0; |
| 2939 | 2911 | } |
| 2940 | 2912 | |
@@ -2957,8 +2929,7 @@ discard block |
||
| 2957 | 2929 | $v_dir = $v_path_info['dirname'].'/'; |
| 2958 | 2930 | } |
| 2959 | 2931 | $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; |
| 2960 | - } |
|
| 2961 | - else { |
|
| 2932 | + } else { |
|
| 2962 | 2933 | // ----- Calculate the stored filename |
| 2963 | 2934 | $v_stored_filename = $p_filename; |
| 2964 | 2935 | } |
@@ -2969,8 +2940,9 @@ discard block |
||
| 2969 | 2940 | } |
| 2970 | 2941 | // ----- Look for partial path remove |
| 2971 | 2942 | else if ($p_remove_dir != "") { |
| 2972 | - if (substr($p_remove_dir, -1) != '/') |
|
| 2973 | - $p_remove_dir .= "/"; |
|
| 2943 | + if (substr($p_remove_dir, -1) != '/') { |
|
| 2944 | + $p_remove_dir .= "/"; |
|
| 2945 | + } |
|
| 2974 | 2946 | |
| 2975 | 2947 | if ( (substr($p_filename, 0, 2) == "./") |
| 2976 | 2948 | || (substr($p_remove_dir, 0, 2) == "./")) { |
@@ -2990,8 +2962,7 @@ discard block |
||
| 2990 | 2962 | if ($v_compare > 0) { |
| 2991 | 2963 | if ($v_compare == 2) { |
| 2992 | 2964 | $v_stored_filename = ""; |
| 2993 | - } |
|
| 2994 | - else { |
|
| 2965 | + } else { |
|
| 2995 | 2966 | $v_stored_filename = substr($v_stored_filename, |
| 2996 | 2967 | strlen($p_remove_dir)); |
| 2997 | 2968 | } |
@@ -3003,10 +2974,11 @@ discard block |
||
| 3003 | 2974 | |
| 3004 | 2975 | // ----- Look for path to add |
| 3005 | 2976 | if ($p_add_dir != "") { |
| 3006 | - if (substr($p_add_dir, -1) == "/") |
|
| 3007 | - $v_stored_filename = $p_add_dir.$v_stored_filename; |
|
| 3008 | - else |
|
| 3009 | - $v_stored_filename = $p_add_dir."/".$v_stored_filename; |
|
| 2977 | + if (substr($p_add_dir, -1) == "/") { |
|
| 2978 | + $v_stored_filename = $p_add_dir.$v_stored_filename; |
|
| 2979 | + } else { |
|
| 2980 | + $v_stored_filename = $p_add_dir."/".$v_stored_filename; |
|
| 2981 | + } |
|
| 3010 | 2982 | } |
| 3011 | 2983 | } |
| 3012 | 2984 | |
@@ -3289,8 +3261,9 @@ discard block |
||
| 3289 | 3261 | if ( ($p_path == "") |
| 3290 | 3262 | || ( (substr($p_path, 0, 1) != "/") |
| 3291 | 3263 | && (substr($p_path, 0, 3) != "../") |
| 3292 | - && (substr($p_path,1,2)!=":/"))) |
|
| 3293 | - $p_path = "./".$p_path; |
|
| 3264 | + && (substr($p_path,1,2)!=":/"))) { |
|
| 3265 | + $p_path = "./".$p_path; |
|
| 3266 | + } |
|
| 3294 | 3267 | |
| 3295 | 3268 | // ----- Reduce the path last (and duplicated) '/' |
| 3296 | 3269 | if (($p_path != "./") && ($p_path != "/")) |
@@ -3777,8 +3750,7 @@ discard block |
||
| 3777 | 3750 | // ----- Change the file status |
| 3778 | 3751 | if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) |
| 3779 | 3752 | && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { |
| 3780 | - } |
|
| 3781 | - else { |
|
| 3753 | + } else { |
|
| 3782 | 3754 | $p_entry['status'] = "newer_exist"; |
| 3783 | 3755 | |
| 3784 | 3756 | // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
@@ -3794,19 +3766,19 @@ discard block |
||
| 3794 | 3766 | return PclZip::errorCode(); |
| 3795 | 3767 | } |
| 3796 | 3768 | } |
| 3797 | - } |
|
| 3798 | - else { |
|
| 3769 | + } else { |
|
| 3799 | 3770 | } |
| 3800 | 3771 | } |
| 3801 | 3772 | |
| 3802 | 3773 | // ----- Check the directory availability and create it if necessary |
| 3803 | 3774 | else { |
| 3804 | - if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) |
|
| 3805 | - $v_dir_to_check = $p_entry['filename']; |
|
| 3806 | - else if (!strstr($p_entry['filename'], "/")) |
|
| 3807 | - $v_dir_to_check = ""; |
|
| 3808 | - else |
|
| 3809 | - $v_dir_to_check = dirname($p_entry['filename']); |
|
| 3775 | + if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) { |
|
| 3776 | + $v_dir_to_check = $p_entry['filename']; |
|
| 3777 | + } else if (!strstr($p_entry['filename'], "/")) { |
|
| 3778 | + $v_dir_to_check = ""; |
|
| 3779 | + } else { |
|
| 3780 | + $v_dir_to_check = dirname($p_entry['filename']); |
|
| 3781 | + } |
|
| 3810 | 3782 | |
| 3811 | 3783 | if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { |
| 3812 | 3784 | |
@@ -3862,8 +3834,7 @@ discard block |
||
| 3862 | 3834 | touch($p_entry['filename'], $p_entry['mtime']); |
| 3863 | 3835 | |
| 3864 | 3836 | |
| 3865 | - } |
|
| 3866 | - else { |
|
| 3837 | + } else { |
|
| 3867 | 3838 | // ----- TBC |
| 3868 | 3839 | // Need to be finished |
| 3869 | 3840 | if (($p_entry['flag'] & 1) == 1) { |
@@ -4106,8 +4077,7 @@ discard block |
||
| 4106 | 4077 | // ----- Send the file to the output |
| 4107 | 4078 | echo $v_buffer; |
| 4108 | 4079 | unset($v_buffer); |
| 4109 | - } |
|
| 4110 | - else { |
|
| 4080 | + } else { |
|
| 4111 | 4081 | |
| 4112 | 4082 | // ----- Read the compressed file in a buffer (one shot) |
| 4113 | 4083 | $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
@@ -4217,8 +4187,7 @@ discard block |
||
| 4217 | 4187 | |
| 4218 | 4188 | // ----- Reading the file |
| 4219 | 4189 | $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); |
| 4220 | - } |
|
| 4221 | - else { |
|
| 4190 | + } else { |
|
| 4222 | 4191 | |
| 4223 | 4192 | // ----- Reading the file |
| 4224 | 4193 | $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); |
@@ -4230,8 +4199,7 @@ discard block |
||
| 4230 | 4199 | } |
| 4231 | 4200 | |
| 4232 | 4201 | // ----- Trace |
| 4233 | - } |
|
| 4234 | - else { |
|
| 4202 | + } else { |
|
| 4235 | 4203 | // TBC : error : can not extract a folder in a string |
| 4236 | 4204 | } |
| 4237 | 4205 | |
@@ -4324,8 +4292,7 @@ discard block |
||
| 4324 | 4292 | // ----- Get extra_fields |
| 4325 | 4293 | if ($v_data['extra_len'] != 0) { |
| 4326 | 4294 | $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); |
| 4327 | - } |
|
| 4328 | - else { |
|
| 4295 | + } else { |
|
| 4329 | 4296 | $p_header['extra'] = ''; |
| 4330 | 4297 | } |
| 4331 | 4298 | |
@@ -4356,8 +4323,7 @@ discard block |
||
| 4356 | 4323 | // ----- Get UNIX date format |
| 4357 | 4324 | $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
| 4358 | 4325 | |
| 4359 | - } |
|
| 4360 | - else |
|
| 4326 | + } else |
|
| 4361 | 4327 | { |
| 4362 | 4328 | $p_header['mtime'] = time(); |
| 4363 | 4329 | } |
@@ -4422,22 +4388,25 @@ discard block |
||
| 4422 | 4388 | $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data); |
| 4423 | 4389 | |
| 4424 | 4390 | // ----- Get filename |
| 4425 | - if ($p_header['filename_len'] != 0) |
|
| 4426 | - $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); |
|
| 4427 | - else |
|
| 4428 | - $p_header['filename'] = ''; |
|
| 4391 | + if ($p_header['filename_len'] != 0) { |
|
| 4392 | + $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); |
|
| 4393 | + } else { |
|
| 4394 | + $p_header['filename'] = ''; |
|
| 4395 | + } |
|
| 4429 | 4396 | |
| 4430 | 4397 | // ----- Get extra |
| 4431 | - if ($p_header['extra_len'] != 0) |
|
| 4432 | - $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); |
|
| 4433 | - else |
|
| 4434 | - $p_header['extra'] = ''; |
|
| 4398 | + if ($p_header['extra_len'] != 0) { |
|
| 4399 | + $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); |
|
| 4400 | + } else { |
|
| 4401 | + $p_header['extra'] = ''; |
|
| 4402 | + } |
|
| 4435 | 4403 | |
| 4436 | 4404 | // ----- Get comment |
| 4437 | - if ($p_header['comment_len'] != 0) |
|
| 4438 | - $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); |
|
| 4439 | - else |
|
| 4440 | - $p_header['comment'] = ''; |
|
| 4405 | + if ($p_header['comment_len'] != 0) { |
|
| 4406 | + $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); |
|
| 4407 | + } else { |
|
| 4408 | + $p_header['comment'] = ''; |
|
| 4409 | + } |
|
| 4441 | 4410 | |
| 4442 | 4411 | // ----- Extract properties |
| 4443 | 4412 | |
@@ -4459,8 +4428,7 @@ discard block |
||
| 4459 | 4428 | // ----- Get UNIX date format |
| 4460 | 4429 | $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
| 4461 | 4430 | |
| 4462 | - } |
|
| 4463 | - else |
|
| 4431 | + } else |
|
| 4464 | 4432 | { |
| 4465 | 4433 | $p_header['mtime'] = time(); |
| 4466 | 4434 | } |
@@ -4573,8 +4541,9 @@ discard block |
||
| 4573 | 4541 | // ----- Go back to the maximum possible size of the Central Dir End Record |
| 4574 | 4542 | if (!$v_found) { |
| 4575 | 4543 | $v_maximum_size = 65557; // 0xFFFF + 22; |
| 4576 | - if ($v_maximum_size > $v_size) |
|
| 4577 | - $v_maximum_size = $v_size; |
|
| 4544 | + if ($v_maximum_size > $v_size) { |
|
| 4545 | + $v_maximum_size = $v_size; |
|
| 4546 | + } |
|
| 4578 | 4547 | @fseek($this->zip_fd, $v_size-$v_maximum_size); |
| 4579 | 4548 | if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) |
| 4580 | 4549 | { |
@@ -4659,9 +4628,9 @@ discard block |
||
| 4659 | 4628 | // ----- Get comment |
| 4660 | 4629 | if ($v_data['comment_size'] != 0) { |
| 4661 | 4630 | $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); |
| 4631 | + } else { |
|
| 4632 | + $p_central_dir['comment'] = ''; |
|
| 4662 | 4633 | } |
| 4663 | - else |
|
| 4664 | - $p_central_dir['comment'] = ''; |
|
| 4665 | 4634 | |
| 4666 | 4635 | $p_central_dir['entries'] = $v_data['entries']; |
| 4667 | 4636 | $p_central_dir['disk_entries'] = $v_data['disk_entries']; |
@@ -4761,8 +4730,7 @@ discard block |
||
| 4761 | 4730 | if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
| 4762 | 4731 | && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
| 4763 | 4732 | $v_found = true; |
| 4764 | - } |
|
| 4765 | - elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ |
|
| 4733 | + } elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ |
|
| 4766 | 4734 | && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
| 4767 | 4735 | $v_found = true; |
| 4768 | 4736 | } |
@@ -4813,8 +4781,7 @@ discard block |
||
| 4813 | 4781 | break; |
| 4814 | 4782 | } |
| 4815 | 4783 | } |
| 4816 | - } |
|
| 4817 | - else { |
|
| 4784 | + } else { |
|
| 4818 | 4785 | $v_found = true; |
| 4819 | 4786 | } |
| 4820 | 4787 | |
@@ -4822,8 +4789,7 @@ discard block |
||
| 4822 | 4789 | if ($v_found) |
| 4823 | 4790 | { |
| 4824 | 4791 | unset($v_header_list[$v_nb_extracted]); |
| 4825 | - } |
|
| 4826 | - else |
|
| 4792 | + } else |
|
| 4827 | 4793 | { |
| 4828 | 4794 | $v_nb_extracted++; |
| 4829 | 4795 | } |
@@ -5299,8 +5265,7 @@ discard block |
||
| 5299 | 5265 | { |
| 5300 | 5266 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 5301 | 5267 | PclError($p_error_code, $p_error_string); |
| 5302 | - } |
|
| 5303 | - else { |
|
| 5268 | + } else { |
|
| 5304 | 5269 | $this->error_code = $p_error_code; |
| 5305 | 5270 | $this->error_string = $p_error_string; |
| 5306 | 5271 | } |
@@ -5316,8 +5281,7 @@ discard block |
||
| 5316 | 5281 | { |
| 5317 | 5282 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 5318 | 5283 | PclErrorReset(); |
| 5319 | - } |
|
| 5320 | - else { |
|
| 5284 | + } else { |
|
| 5321 | 5285 | $this->error_code = 0; |
| 5322 | 5286 | $this->error_string = ''; |
| 5323 | 5287 | } |
@@ -5415,11 +5379,9 @@ discard block |
||
| 5415 | 5379 | if ($v_list[$i] == ".") { |
| 5416 | 5380 | // ----- Ignore this directory |
| 5417 | 5381 | // Should be the first $i=0, but no check is done |
| 5418 | - } |
|
| 5419 | - else if ($v_list[$i] == "..") { |
|
| 5382 | + } else if ($v_list[$i] == "..") { |
|
| 5420 | 5383 | $v_skip++; |
| 5421 | - } |
|
| 5422 | - else if ($v_list[$i] == "") { |
|
| 5384 | + } else if ($v_list[$i] == "") { |
|
| 5423 | 5385 | // ----- First '/' i.e. root slash |
| 5424 | 5386 | if ($i == 0) { |
| 5425 | 5387 | $v_result = "/".$v_result; |
@@ -5439,13 +5401,11 @@ discard block |
||
| 5439 | 5401 | // ----- Ignore only the double '//' in path, |
| 5440 | 5402 | // but not the first and last '/' |
| 5441 | 5403 | } |
| 5442 | - } |
|
| 5443 | - else { |
|
| 5404 | + } else { |
|
| 5444 | 5405 | // ----- Look for item to skip |
| 5445 | 5406 | if ($v_skip > 0) { |
| 5446 | 5407 | $v_skip--; |
| 5447 | - } |
|
| 5448 | - else { |
|
| 5408 | + } else { |
|
| 5449 | 5409 | $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); |
| 5450 | 5410 | } |
| 5451 | 5411 | } |
@@ -5528,14 +5488,17 @@ discard block |
||
| 5528 | 5488 | // ----- Look if everything seems to be the same |
| 5529 | 5489 | if ($v_result) { |
| 5530 | 5490 | // ----- Skip all the empty items |
| 5531 | - while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; |
|
| 5532 | - while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; |
|
| 5491 | + while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) { |
|
| 5492 | + $j++; |
|
| 5493 | + } |
|
| 5494 | + while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) { |
|
| 5495 | + $i++; |
|
| 5496 | + } |
|
| 5533 | 5497 | |
| 5534 | 5498 | if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { |
| 5535 | 5499 | // ----- There are exactly the same |
| 5536 | 5500 | $v_result = 2; |
| 5537 | - } |
|
| 5538 | - else if ($i < $v_list_dir_size) { |
|
| 5501 | + } else if ($i < $v_list_dir_size) { |
|
| 5539 | 5502 | // ----- The path is shorter than the dir |
| 5540 | 5503 | $v_result = 0; |
| 5541 | 5504 | } |
@@ -5570,8 +5533,7 @@ discard block |
||
| 5570 | 5533 | @fwrite($p_dest, $v_buffer, $v_read_size); |
| 5571 | 5534 | $p_size -= $v_read_size; |
| 5572 | 5535 | } |
| 5573 | - } |
|
| 5574 | - else if ($p_mode==1) |
|
| 5536 | + } else if ($p_mode==1) |
|
| 5575 | 5537 | { |
| 5576 | 5538 | while ($p_size != 0) |
| 5577 | 5539 | { |
@@ -5580,8 +5542,7 @@ discard block |
||
| 5580 | 5542 | @fwrite($p_dest, $v_buffer, $v_read_size); |
| 5581 | 5543 | $p_size -= $v_read_size; |
| 5582 | 5544 | } |
| 5583 | - } |
|
| 5584 | - else if ($p_mode==2) |
|
| 5545 | + } else if ($p_mode==2) |
|
| 5585 | 5546 | { |
| 5586 | 5547 | while ($p_size != 0) |
| 5587 | 5548 | { |
@@ -5590,8 +5551,7 @@ discard block |
||
| 5590 | 5551 | @gzwrite($p_dest, $v_buffer, $v_read_size); |
| 5591 | 5552 | $p_size -= $v_read_size; |
| 5592 | 5553 | } |
| 5593 | - } |
|
| 5594 | - else if ($p_mode==3) |
|
| 5554 | + } else if ($p_mode==3) |
|
| 5595 | 5555 | { |
| 5596 | 5556 | while ($p_size != 0) |
| 5597 | 5557 | { |
@@ -5629,8 +5589,7 @@ discard block |
||
| 5629 | 5589 | // ----- Try to copy & unlink the src |
| 5630 | 5590 | if (!@copy($p_src, $p_dest)) { |
| 5631 | 5591 | $v_result = 0; |
| 5632 | - } |
|
| 5633 | - else if (!@unlink($p_src)) { |
|
| 5592 | + } else if (!@unlink($p_src)) { |
|
| 5634 | 5593 | $v_result = 0; |
| 5635 | 5594 | } |
| 5636 | 5595 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * Open a Zip archive |
| 40 | 40 | * |
| 41 | 41 | * @param string $filename the name of the archive to open |
| 42 | - * @return true if openning has succeeded |
|
| 42 | + * @return boolean if openning has succeeded |
|
| 43 | 43 | */ |
| 44 | 44 | public function open($filename) |
| 45 | 45 | { |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @param string $localname the local path to the file in the archive |
| 80 | 80 | * @param string $contents the content of the file |
| 81 | - * @return true if the file has been successful added |
|
| 81 | + * @return boolean if the file has been successful added |
|
| 82 | 82 | */ |
| 83 | 83 | public function addFromString($localname, $contents) |
| 84 | 84 | { |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @param string $filename the path to the file we want to add |
| 110 | 110 | * @param string $localname the local path to the file in the archive |
| 111 | - * @return true if the file has been successful added |
|
| 111 | + * @return boolean if the file has been successful added |
|
| 112 | 112 | */ |
| 113 | 113 | public function addFile($filename, $localname = null) |
| 114 | 114 | { |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | } |
| 142 | 142 | /** |
| 143 | 143 | * Close the Zip archive |
| 144 | - * @return true |
|
| 144 | + * @return boolean |
|
| 145 | 145 | */ |
| 146 | 146 | public function close() |
| 147 | 147 | { |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | /** |
| 160 | 160 | * Empty the temporary working directory recursively |
| 161 | - * @param $dir the temporary working directory |
|
| 161 | + * @param string $dir the temporary working directory |
|
| 162 | 162 | * @return void |
| 163 | 163 | */ |
| 164 | 164 | private function _rrmdir($dir) |
@@ -23,11 +23,11 @@ |
||
| 23 | 23 | protected $openned = false; |
| 24 | 24 | protected $filename; |
| 25 | 25 | protected $pclzip; |
| 26 | - /** |
|
| 27 | - * Class constructor |
|
| 28 | - * |
|
| 29 | - * @throws PclZipProxyException |
|
| 30 | - */ |
|
| 26 | + /** |
|
| 27 | + * Class constructor |
|
| 28 | + * |
|
| 29 | + * @throws PclZipProxyException |
|
| 30 | + */ |
|
| 31 | 31 | public function __construct() |
| 32 | 32 | { |
| 33 | 33 | if (! class_exists('PclZip')) { |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | require_once 'pclzip/pclzip.lib.php'; |
| 3 | 3 | require_once 'ZipInterface.php'; |
| 4 | 4 | class PclZipProxyException extends Exception |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function __construct() |
| 32 | 32 | { |
| 33 | - if (! class_exists('PclZip')) { |
|
| 33 | + if (!class_exists('PclZip')) { |
|
| 34 | 34 | throw new PclZipProxyException('PclZip class not loaded - PclZip library |
| 35 | 35 | is required for using PclZipProxy'); ; |
| 36 | 36 | } |
@@ -1,4 +1,6 @@ |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Fichier de définition du modèle des taxinomies / File for term model definition |
| 4 | 6 | * |
@@ -481,7 +481,7 @@ |
||
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** SIGN UP - Display the commercial & newsletter form |
| 484 | - * @return void |
|
| 484 | + * @return string |
|
| 485 | 485 | */ |
| 486 | 486 | function display_commercial_newsletter_form() { |
| 487 | 487 | $output = ''; |
@@ -1,8 +1,8 @@ |
||
| 1 | 1 | <?php if ( !defined( 'ABSPATH' ) ) exit; |
| 2 | 2 | class wps_account_ctr { |
| 3 | 3 | /** Define the main directory containing the template for the current plugin |
| 4 | - * @var string |
|
| 5 | - */ |
|
| 4 | + * @var string |
|
| 5 | + */ |
|
| 6 | 6 | private $template_dir; |
| 7 | 7 | /** |
| 8 | 8 | * Define the directory name for the module in order to check into frontend |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_account_ctr { |
| 3 | 3 | /** Define the main directory containing the template for the current plugin |
| 4 | 4 | * @var string |
@@ -19,50 +19,50 @@ discard block |
||
| 19 | 19 | $this->template_dir = WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . "/templates/"; |
| 20 | 20 | /** Shortcodes **/ |
| 21 | 21 | // Sign up Display Shortcode |
| 22 | - add_shortcode( 'wps_signup', array( &$this, 'display_signup' ) ); |
|
| 22 | + add_shortcode('wps_signup', array(&$this, 'display_signup')); |
|
| 23 | 23 | // Log in Form Display Shortcode |
| 24 | - add_shortcode( 'wpshop_login', array( &$this, 'get_login_form')); |
|
| 24 | + add_shortcode('wpshop_login', array(&$this, 'get_login_form')); |
|
| 25 | 25 | //Log in first step |
| 26 | - add_shortcode( 'wps_first_login', array( &$this, 'get_login_first_step')); |
|
| 26 | + add_shortcode('wps_first_login', array(&$this, 'get_login_first_step')); |
|
| 27 | 27 | // Forgot password Form |
| 28 | - add_shortcode( 'wps_forgot_password', array( &$this, 'get_forgot_password_form')); |
|
| 28 | + add_shortcode('wps_forgot_password', array(&$this, 'get_forgot_password_form')); |
|
| 29 | 29 | // Renew password form |
| 30 | - add_shortcode( 'wps_renew_password', array( &$this, 'get_renew_password_form')); |
|
| 30 | + add_shortcode('wps_renew_password', array(&$this, 'get_renew_password_form')); |
|
| 31 | 31 | //Account informations |
| 32 | - add_shortcode( 'wps_account_informations', array($this, 'display_account_informations') ); |
|
| 32 | + add_shortcode('wps_account_informations', array($this, 'display_account_informations')); |
|
| 33 | 33 | //Account form |
| 34 | - add_shortcode( 'wps_account_informations_form', array($this, 'account_informations_form') ); |
|
| 34 | + add_shortcode('wps_account_informations_form', array($this, 'account_informations_form')); |
|
| 35 | 35 | |
| 36 | 36 | /** Ajax Actions **/ |
| 37 | 37 | // add_action('wap_ajax_wps_display_connexion_form', array(&$this, 'wps_ajax_get_login_form_interface') ); |
| 38 | 38 | // add_action('wap_ajax_nopriv_wps_display_connexion_form', array(&$this, 'wps_ajax_get_login_form_interface') ); |
| 39 | 39 | |
| 40 | - add_action('wp_ajax_wps_login_request', array(&$this, 'control_login_form_request') ); |
|
| 41 | - add_action('wp_ajax_nopriv_wps_login_request', array(&$this, 'control_login_form_request') ); |
|
| 40 | + add_action('wp_ajax_wps_login_request', array(&$this, 'control_login_form_request')); |
|
| 41 | + add_action('wp_ajax_nopriv_wps_login_request', array(&$this, 'control_login_form_request')); |
|
| 42 | 42 | |
| 43 | - add_action('wp_ajax_wps_forgot_password_request', array(&$this, 'wps_forgot_password_request') ); |
|
| 44 | - add_action('wp_ajax_nopriv_wps_forgot_password_request', array(&$this, 'wps_forgot_password_request') ); |
|
| 43 | + add_action('wp_ajax_wps_forgot_password_request', array(&$this, 'wps_forgot_password_request')); |
|
| 44 | + add_action('wp_ajax_nopriv_wps_forgot_password_request', array(&$this, 'wps_forgot_password_request')); |
|
| 45 | 45 | |
| 46 | - add_action('wp_ajax_wps_forgot_password_renew', array(&$this, 'wps_forgot_password_renew') ); |
|
| 47 | - add_action('wp_ajax_nopriv_wps_forgot_password_renew', array(&$this, 'wps_forgot_password_renew') ); |
|
| 46 | + add_action('wp_ajax_wps_forgot_password_renew', array(&$this, 'wps_forgot_password_renew')); |
|
| 47 | + add_action('wp_ajax_nopriv_wps_forgot_password_renew', array(&$this, 'wps_forgot_password_renew')); |
|
| 48 | 48 | |
| 49 | - add_action('wp_ajax_wps_signup_request', array(&$this, 'wps_save_signup_form') ); |
|
| 50 | - add_action('wp_ajax_nopriv_wps_signup_request', array(&$this, 'wps_save_signup_form') ); |
|
| 49 | + add_action('wp_ajax_wps_signup_request', array(&$this, 'wps_save_signup_form')); |
|
| 50 | + add_action('wp_ajax_nopriv_wps_signup_request', array(&$this, 'wps_save_signup_form')); |
|
| 51 | 51 | |
| 52 | - add_action('wp_ajax_wps_login_first_request', array(&$this, 'wps_login_first_request') ); |
|
| 53 | - add_action('wp_ajax_nopriv_wps_login_first_request', array(&$this, 'wps_login_first_request') ); |
|
| 52 | + add_action('wp_ajax_wps_login_first_request', array(&$this, 'wps_login_first_request')); |
|
| 53 | + add_action('wp_ajax_nopriv_wps_login_first_request', array(&$this, 'wps_login_first_request')); |
|
| 54 | 54 | |
| 55 | - add_action( 'wp_ajax_wps_save_account_informations', array($this, 'wps_save_account_informations') ); |
|
| 55 | + add_action('wp_ajax_wps_save_account_informations', array($this, 'wps_save_account_informations')); |
|
| 56 | 56 | |
| 57 | - add_action( 'wp_ajax_wps_account_reload_informations', array($this, 'wps_account_reload_informations') ); |
|
| 57 | + add_action('wp_ajax_wps_account_reload_informations', array($this, 'wps_account_reload_informations')); |
|
| 58 | 58 | |
| 59 | - add_action( 'wp_ajax_wps_fill_forgot_password_modal', array($this, 'wps_fill_forgot_password_modal') ); |
|
| 60 | - add_action( 'wp_ajax_nopriv_wps_fill_forgot_password_modal', array($this, 'wps_fill_forgot_password_modal') ); |
|
| 59 | + add_action('wp_ajax_wps_fill_forgot_password_modal', array($this, 'wps_fill_forgot_password_modal')); |
|
| 60 | + add_action('wp_ajax_nopriv_wps_fill_forgot_password_modal', array($this, 'wps_fill_forgot_password_modal')); |
|
| 61 | 61 | |
| 62 | - add_action( 'wp_ajax_wps_fill_account_informations_modal', array($this, 'wps_fill_account_informations_modal') ); |
|
| 63 | - add_action( 'wp_ajax_nopriv_wps_fill_account_informations_modal', array($this, 'wps_fill_account_informations_modal') ); |
|
| 62 | + add_action('wp_ajax_wps_fill_account_informations_modal', array($this, 'wps_fill_account_informations_modal')); |
|
| 63 | + add_action('wp_ajax_nopriv_wps_fill_account_informations_modal', array($this, 'wps_fill_account_informations_modal')); |
|
| 64 | 64 | |
| 65 | - add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts') ); |
|
| 65 | + add_action('wp_enqueue_scripts', array($this, 'add_scripts')); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -70,32 +70,32 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | function add_scripts() { |
| 72 | 72 | wp_enqueue_script('jquery'); |
| 73 | - wp_enqueue_script( 'wps_forgot_password_js', WPS_ACCOUNT_URL.'wps_customer/assets/frontend/js/wps_forgot_password.js' ); |
|
| 74 | - wp_enqueue_script( 'wps_login_js', WPS_ACCOUNT_URL.'wps_customer/assets/frontend/js/wps_login.js' ); |
|
| 75 | - wp_enqueue_script( 'wps_signup_js', WPS_ACCOUNT_URL.'wps_customer/assets/frontend/js/wps_signup.js' ); |
|
| 76 | - wp_enqueue_script( 'wps_account_js', WPS_ACCOUNT_URL.'wps_customer/assets/frontend/js/wps_account.js' ); |
|
| 73 | + wp_enqueue_script('wps_forgot_password_js', WPS_ACCOUNT_URL . 'wps_customer/assets/frontend/js/wps_forgot_password.js'); |
|
| 74 | + wp_enqueue_script('wps_login_js', WPS_ACCOUNT_URL . 'wps_customer/assets/frontend/js/wps_login.js'); |
|
| 75 | + wp_enqueue_script('wps_signup_js', WPS_ACCOUNT_URL . 'wps_customer/assets/frontend/js/wps_signup.js'); |
|
| 76 | + wp_enqueue_script('wps_account_js', WPS_ACCOUNT_URL . 'wps_customer/assets/frontend/js/wps_account.js'); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** LOG IN - Display log in Form **/ |
| 80 | - function get_login_form( $force_login = false ) { |
|
| 80 | + function get_login_form($force_login = false) { |
|
| 81 | 81 | $args = array(); |
| 82 | - if ( get_current_user_id() != 0 ) { |
|
| 83 | - return __( 'You are already logged', 'wpshop'); |
|
| 82 | + if (get_current_user_id() != 0) { |
|
| 83 | + return __('You are already logged', 'wpshop'); |
|
| 84 | 84 | } |
| 85 | 85 | else { |
| 86 | - $action = !empty( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
| 87 | - $key = !empty( $_GET['key'] ) ? sanitize_text_field( $_GET['key'] ) : ''; |
|
| 88 | - $login = !empty( $_GET['login'] ) ? sanitize_text_field( $_GET['login'] ) : 0; |
|
| 89 | - if ( !empty($action) && $action == 'retrieve_password' && !empty($key) && !empty($login) && !$force_login ) { |
|
| 86 | + $action = !empty($_GET['action']) ? sanitize_text_field($_GET['action']) : ''; |
|
| 87 | + $key = !empty($_GET['key']) ? sanitize_text_field($_GET['key']) : ''; |
|
| 88 | + $login = !empty($_GET['login']) ? sanitize_text_field($_GET['login']) : 0; |
|
| 89 | + if (!empty($action) && $action == 'retrieve_password' && !empty($key) && !empty($login) && !$force_login) { |
|
| 90 | 90 | $output = self::get_renew_password_form(); |
| 91 | 91 | } |
| 92 | 92 | else { |
| 93 | 93 | ob_start(); |
| 94 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "login/login-form") ); |
|
| 94 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "login/login-form")); |
|
| 95 | 95 | $output = ob_get_contents(); |
| 96 | 96 | ob_end_clean(); |
| 97 | - if ( !$force_login ) { |
|
| 98 | - $output .= do_shortcode( '[wps_signup]' ); |
|
| 97 | + if (!$force_login) { |
|
| 98 | + $output .= do_shortcode('[wps_signup]'); |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | return $output; |
@@ -105,53 +105,53 @@ discard block |
||
| 105 | 105 | /** LOG IN - AJAX - Action to connect **/ |
| 106 | 106 | function control_login_form_request() { |
| 107 | 107 | |
| 108 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 108 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 109 | 109 | |
| 110 | - if ( !wp_verify_nonce( $_wpnonce, 'control_login_form_request' ) ) |
|
| 110 | + if (!wp_verify_nonce($_wpnonce, 'control_login_form_request')) |
|
| 111 | 111 | wp_die(); |
| 112 | 112 | |
| 113 | 113 | $result = ''; |
| 114 | 114 | $status = false; |
| 115 | - $origin = sanitize_text_field( $_POST['wps-checking-origin'] ); |
|
| 116 | - $wps_login_user_login = !empty( $_POST['wps_login_user_login'] ) ? sanitize_text_field( $_POST['wps_login_user_login' ] ) : ''; |
|
| 117 | - $wps_login_password = !empty( $_POST['wps_login_password'] ) ? sanitize_text_field( $_POST['wps_login_password' ] ) : ''; |
|
| 118 | - $page_account_id = wpshop_tools::get_page_id( get_option( 'wpshop_myaccount_page_id') ); |
|
| 119 | - if ( !empty($wps_login_user_login) && !empty($wps_login_password) ) { |
|
| 115 | + $origin = sanitize_text_field($_POST['wps-checking-origin']); |
|
| 116 | + $wps_login_user_login = !empty($_POST['wps_login_user_login']) ? sanitize_text_field($_POST['wps_login_user_login']) : ''; |
|
| 117 | + $wps_login_password = !empty($_POST['wps_login_password']) ? sanitize_text_field($_POST['wps_login_password']) : ''; |
|
| 118 | + $page_account_id = wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')); |
|
| 119 | + if (!empty($wps_login_user_login) && !empty($wps_login_password)) { |
|
| 120 | 120 | $creds = array(); |
| 121 | 121 | // Test if an user exist with this login |
| 122 | - $user_checking = get_user_by( 'login', $wps_login_user_login ); |
|
| 123 | - if( !empty($user_checking) ) { |
|
| 122 | + $user_checking = get_user_by('login', $wps_login_user_login); |
|
| 123 | + if (!empty($user_checking)) { |
|
| 124 | 124 | $creds['user_login'] = $wps_login_user_login; |
| 125 | 125 | } |
| 126 | 126 | else { |
| 127 | - if ( is_email($wps_login_user_login) ) { |
|
| 128 | - $user_checking = get_user_by( 'email', $wps_login_user_login ); |
|
| 127 | + if (is_email($wps_login_user_login)) { |
|
| 128 | + $user_checking = get_user_by('email', $wps_login_user_login); |
|
| 129 | 129 | $creds['user_login'] = $user_checking->user_login; |
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | - $creds['user_password'] = wpshop_tools::varSanitizer( $_POST['wps_login_password'] ); |
|
| 133 | - $creds['remember'] = !empty( $_POST['wps_login_remember_me'] ) ? (int) $_POST['wps_login_remember_me'] : false; |
|
| 134 | - $user = wp_signon( $creds, false ); |
|
| 135 | - if ( is_wp_error($user) ) { |
|
| 136 | - $result = '<div class="wps-alert-error">' .__('Connexion error', 'wpshop'). '</div>'; |
|
| 132 | + $creds['user_password'] = wpshop_tools::varSanitizer($_POST['wps_login_password']); |
|
| 133 | + $creds['remember'] = !empty($_POST['wps_login_remember_me']) ? (int)$_POST['wps_login_remember_me'] : false; |
|
| 134 | + $user = wp_signon($creds, false); |
|
| 135 | + if (is_wp_error($user)) { |
|
| 136 | + $result = '<div class="wps-alert-error">' . __('Connexion error', 'wpshop') . '</div>'; |
|
| 137 | 137 | } |
| 138 | 138 | else { |
| 139 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 140 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 141 | - if( $origin == $page_account_id ) { |
|
| 142 | - $result = get_permalink( $page_account_id ); |
|
| 139 | + $permalink_option = get_option('permalink_structure'); |
|
| 140 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 141 | + if ($origin == $page_account_id) { |
|
| 142 | + $result = get_permalink($page_account_id); |
|
| 143 | 143 | } |
| 144 | 144 | else { |
| 145 | - $result = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=3'; |
|
| 145 | + $result = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=3'; |
|
| 146 | 146 | } |
| 147 | 147 | $status = true; |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | else { |
| 151 | - $result = '<div class="wps-alert-error">' .__('E-Mail and Password are required', 'wpshop'). '</div>'; |
|
| 151 | + $result = '<div class="wps-alert-error">' . __('E-Mail and Password are required', 'wpshop') . '</div>'; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - echo json_encode( array( $status, $result) ); |
|
| 154 | + echo json_encode(array($status, $result)); |
|
| 155 | 155 | die(); |
| 156 | 156 | } |
| 157 | 157 | |
@@ -159,13 +159,13 @@ discard block |
||
| 159 | 159 | * LOG IN - AJAX - Display log in Form in Ajax |
| 160 | 160 | */ |
| 161 | 161 | function wps_ajax_get_login_form_interface() { |
| 162 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 162 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 163 | 163 | |
| 164 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_ajax_get_login_form_interface' ) ) |
|
| 164 | + if (!wp_verify_nonce($_wpnonce, 'wps_ajax_get_login_form_interface')) |
|
| 165 | 165 | wp_die(); |
| 166 | 166 | |
| 167 | - $response = array( 'status' => true, 'response' => self::get_login_form() ); |
|
| 168 | - echo json_encode( $response ); |
|
| 167 | + $response = array('status' => true, 'response' => self::get_login_form()); |
|
| 168 | + echo json_encode($response); |
|
| 169 | 169 | die(); |
| 170 | 170 | } |
| 171 | 171 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | function get_login_first_step() { |
| 174 | 174 | $output = ''; |
| 175 | 175 | ob_start(); |
| 176 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "login/login-form", "first") ); |
|
| 176 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "login/login-form", "first")); |
|
| 177 | 177 | $output .= ob_get_contents(); |
| 178 | 178 | ob_end_clean(); |
| 179 | 179 | return $output; |
@@ -183,39 +183,39 @@ discard block |
||
| 183 | 183 | * LOG IN - First Step log in request |
| 184 | 184 | */ |
| 185 | 185 | function wps_login_first_request() { |
| 186 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 186 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 187 | 187 | |
| 188 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_login_first_request' ) ) |
|
| 188 | + if (!wp_verify_nonce($_wpnonce, 'wps_login_first_request')) |
|
| 189 | 189 | wp_die(); |
| 190 | 190 | |
| 191 | 191 | $status = false; $login_action = false; $response = ''; |
| 192 | - $user_email = ( !empty($_POST['email_address']) ) ? wpshop_tools::varSanitizer( $_POST['email_address'] ) : null; |
|
| 193 | - if ( !empty($user_email) ) { |
|
| 192 | + $user_email = (!empty($_POST['email_address'])) ? wpshop_tools::varSanitizer($_POST['email_address']) : null; |
|
| 193 | + if (!empty($user_email)) { |
|
| 194 | 194 | $status = true; |
| 195 | 195 | /** Check if a user exist with it's email **/ |
| 196 | - $checking_user = get_user_by( 'login', $user_email); |
|
| 197 | - if ( !empty($checking_user) ) { |
|
| 196 | + $checking_user = get_user_by('login', $user_email); |
|
| 197 | + if (!empty($checking_user)) { |
|
| 198 | 198 | $login_action = true; |
| 199 | - $user_firstname = get_user_meta( $checking_user->ID, 'first_name', true ); |
|
| 199 | + $user_firstname = get_user_meta($checking_user->ID, 'first_name', true); |
|
| 200 | 200 | $response = $user_firstname; |
| 201 | 201 | } |
| 202 | 202 | else { |
| 203 | - $checking_user = get_user_by( 'email', $user_email); |
|
| 204 | - if ( !empty( $checking_user ) ) { |
|
| 203 | + $checking_user = get_user_by('email', $user_email); |
|
| 204 | + if (!empty($checking_user)) { |
|
| 205 | 205 | $login_action = true; |
| 206 | - $user_firstname = get_user_meta( $checking_user->ID, 'first_name', true ); |
|
| 206 | + $user_firstname = get_user_meta($checking_user->ID, 'first_name', true); |
|
| 207 | 207 | $response = $user_firstname; |
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if( !$login_action && is_email($user_email) ) { |
|
| 211 | + if (!$login_action && is_email($user_email)) { |
|
| 212 | 212 | $response = $user_email; |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | else { |
| 216 | - $response = '<div class="wps-alert-error">' .__( 'An e-mail address is required', 'wpshop' ). '</div>'; |
|
| 216 | + $response = '<div class="wps-alert-error">' . __('An e-mail address is required', 'wpshop') . '</div>'; |
|
| 217 | 217 | } |
| 218 | - echo json_encode( array( 'status'=> $status, 'response' => $response, 'login_action' => $login_action) ); |
|
| 218 | + echo json_encode(array('status'=> $status, 'response' => $response, 'login_action' => $login_action)); |
|
| 219 | 219 | die(); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -224,9 +224,9 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | function get_forgot_password_form() { |
| 226 | 226 | $output = ''; |
| 227 | - if ( get_current_user_id() == 0 ) { |
|
| 227 | + if (get_current_user_id() == 0) { |
|
| 228 | 228 | ob_start(); |
| 229 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "forgot-password/forgot-password") ); |
|
| 229 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "forgot-password/forgot-password")); |
|
| 230 | 230 | $output = ob_get_contents(); |
| 231 | 231 | ob_end_clean(); |
| 232 | 232 | } |
@@ -237,16 +237,16 @@ discard block |
||
| 237 | 237 | * FORGOT PASSWORD - AJAX - Fill the forgot password modal |
| 238 | 238 | */ |
| 239 | 239 | function wps_fill_forgot_password_modal() { |
| 240 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 240 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 241 | 241 | |
| 242 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_fill_forgot_password_modal' ) ) |
|
| 242 | + if (!wp_verify_nonce($_wpnonce, 'wps_fill_forgot_password_modal')) |
|
| 243 | 243 | wp_die(); |
| 244 | 244 | |
| 245 | 245 | $status = false; $title = $content = ''; |
| 246 | - $title = __( 'Forgot password', 'wpshop' ); |
|
| 246 | + $title = __('Forgot password', 'wpshop'); |
|
| 247 | 247 | $content = do_shortcode('[wps_forgot_password]'); |
| 248 | 248 | $status = true; |
| 249 | - echo json_encode( array('status' => $status, 'title' => $title, 'content' => $content) ); |
|
| 249 | + echo json_encode(array('status' => $status, 'title' => $title, 'content' => $content)); |
|
| 250 | 250 | wp_die(); |
| 251 | 251 | } |
| 252 | 252 | |
@@ -254,46 +254,46 @@ discard block |
||
| 254 | 254 | * FORGOT PASSWORD- AJAX - Forgot Password Request |
| 255 | 255 | */ |
| 256 | 256 | function wps_forgot_password_request() { |
| 257 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 257 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 258 | 258 | |
| 259 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_forgot_password_request' ) ) |
|
| 259 | + if (!wp_verify_nonce($_wpnonce, 'wps_forgot_password_request')) |
|
| 260 | 260 | wp_die(); |
| 261 | 261 | |
| 262 | 262 | global $wpdb; |
| 263 | 263 | $status = false; $result = ''; |
| 264 | - $user_login = ( !empty( $_POST['wps_user_login']) ) ? wpshop_tools::varSanitizer($_POST['wps_user_login']) : null; |
|
| 265 | - if ( !empty($user_login) ) { |
|
| 264 | + $user_login = (!empty($_POST['wps_user_login'])) ? wpshop_tools::varSanitizer($_POST['wps_user_login']) : null; |
|
| 265 | + if (!empty($user_login)) { |
|
| 266 | 266 | $existing_user = false; |
| 267 | 267 | $exist_user = get_user_by('login', $user_login); |
| 268 | - if( !empty($exist_user) ) { |
|
| 268 | + if (!empty($exist_user)) { |
|
| 269 | 269 | $existing_user = true; |
| 270 | 270 | } |
| 271 | 271 | else { |
| 272 | 272 | $exist_user = get_user_by('email', $user_login); |
| 273 | - if ( !empty($exist_user) ) { |
|
| 273 | + if (!empty($exist_user)) { |
|
| 274 | 274 | $existing_user = true; |
| 275 | 275 | } |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if ( $existing_user ) { |
|
| 278 | + if ($existing_user) { |
|
| 279 | 279 | $key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM $wpdb->users WHERE user_login = %s", $user_login)); |
| 280 | - if ( empty($key) ) { |
|
| 280 | + if (empty($key)) { |
|
| 281 | 281 | $key = wp_generate_password(20, false); |
| 282 | 282 | $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login)); |
| 283 | 283 | } |
| 284 | 284 | $this->send_forgot_password_email($key, $user_login, $exist_user); |
| 285 | - $result = '<div class="wps-alert-info">' .__('An e-mail with an password renew link has been sent to you', 'wpshop'). '</div>'; |
|
| 285 | + $result = '<div class="wps-alert-info">' . __('An e-mail with an password renew link has been sent to you', 'wpshop') . '</div>'; |
|
| 286 | 286 | $status = true; |
| 287 | 287 | } |
| 288 | 288 | else { |
| 289 | - $result = '<div class="wps-alert-error">' .__('No customer account corresponds to this email', 'wpshop'). '</div>'; |
|
| 289 | + $result = '<div class="wps-alert-error">' . __('No customer account corresponds to this email', 'wpshop') . '</div>'; |
|
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | 292 | else { |
| 293 | - $result = '<div class="wps-alert-error">' .__('Please fill the required field', 'wpshop'). '</div>'; |
|
| 293 | + $result = '<div class="wps-alert-error">' . __('Please fill the required field', 'wpshop') . '</div>'; |
|
| 294 | 294 | } |
| 295 | - $response = array( $status, $result ); |
|
| 296 | - echo json_encode( $response ); |
|
| 295 | + $response = array($status, $result); |
|
| 296 | + echo json_encode($response); |
|
| 297 | 297 | die(); |
| 298 | 298 | } |
| 299 | 299 | |
@@ -302,70 +302,70 @@ discard block |
||
| 302 | 302 | * @param string $key |
| 303 | 303 | * @param string $user_login |
| 304 | 304 | */ |
| 305 | - function send_forgot_password_email($key, $user_login, $exist_user){ |
|
| 305 | + function send_forgot_password_email($key, $user_login, $exist_user) { |
|
| 306 | 306 | $user_data = $exist_user->data; |
| 307 | 307 | $email = $user_data->user_email; |
| 308 | 308 | $wps_message = new wps_message_ctr(); |
| 309 | - $first_name = get_user_meta( $user_data->ID, 'first_name', true ); |
|
| 310 | - $last_name = get_user_meta( $user_data->ID, 'last_name', true ); |
|
| 311 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 312 | - $link = '<a href="' .get_permalink( wpshop_tools::get_page_id( get_option('wpshop_checkout_page_id') ) ).( (!empty($permalink_option)) ? '?' : '&').'order_step=2&action=retrieve_password&key=' .$key. '&login=' .rawurlencode($user_login). '">' .get_permalink( wpshop_tools::get_page_id( get_option('wpshop_checkout_page_id') ) ). '&action=retrieve_password&key=' .$key. '&login=' .rawurlencode($user_login). '</a>'; |
|
| 313 | - if( !empty($key) && !empty( $user_login ) ) { |
|
| 309 | + $first_name = get_user_meta($user_data->ID, 'first_name', true); |
|
| 310 | + $last_name = get_user_meta($user_data->ID, 'last_name', true); |
|
| 311 | + $permalink_option = get_option('permalink_structure'); |
|
| 312 | + $link = '<a href="' . get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'))) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=2&action=retrieve_password&key=' . $key . '&login=' . rawurlencode($user_login) . '">' . get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'))) . '&action=retrieve_password&key=' . $key . '&login=' . rawurlencode($user_login) . '</a>'; |
|
| 313 | + if (!empty($key) && !empty($user_login)) { |
|
| 314 | 314 | $wps_message->wpshop_prepared_email($email, |
| 315 | 315 | 'WPSHOP_FORGOT_PASSWORD_MESSAGE', |
| 316 | - array( 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'forgot_password_link' => $link) |
|
| 316 | + array('customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'forgot_password_link' => $link) |
|
| 317 | 317 | ); |
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** FORGOT PASSWORD - AJAX - Make renew password action **/ |
| 322 | 322 | function wps_forgot_password_renew() { |
| 323 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 323 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 324 | 324 | |
| 325 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_forgot_password_renew' ) ) |
|
| 325 | + if (!wp_verify_nonce($_wpnonce, 'wps_forgot_password_renew')) |
|
| 326 | 326 | wp_die(); |
| 327 | 327 | |
| 328 | 328 | global $wpdb; |
| 329 | 329 | $status = false; $result = $form = ''; |
| 330 | - $password = ( !empty( $_POST['pass1']) ) ? wpshop_tools::varSanitizer( $_POST['pass1'] ) : null; |
|
| 331 | - $confirm_password = ( !empty( $_POST['pass2']) ) ? wpshop_tools::varSanitizer( $_POST['pass2'] ) : null; |
|
| 332 | - $activation_key = ( !empty( $_POST['activation_key']) ) ? wpshop_tools::varSanitizer( $_POST['activation_key'] ) : null; |
|
| 333 | - $login = ( !empty( $_POST['user_login']) ) ? wpshop_tools::varSanitizer( $_POST['user_login'] ) : null; |
|
| 334 | - if ( !empty($password) && !empty($confirm_password) && $confirm_password == $password ) { |
|
| 335 | - if ( !empty($activation_key) && !empty($login) ) { |
|
| 330 | + $password = (!empty($_POST['pass1'])) ? wpshop_tools::varSanitizer($_POST['pass1']) : null; |
|
| 331 | + $confirm_password = (!empty($_POST['pass2'])) ? wpshop_tools::varSanitizer($_POST['pass2']) : null; |
|
| 332 | + $activation_key = (!empty($_POST['activation_key'])) ? wpshop_tools::varSanitizer($_POST['activation_key']) : null; |
|
| 333 | + $login = (!empty($_POST['user_login'])) ? wpshop_tools::varSanitizer($_POST['user_login']) : null; |
|
| 334 | + if (!empty($password) && !empty($confirm_password) && $confirm_password == $password) { |
|
| 335 | + if (!empty($activation_key) && !empty($login)) { |
|
| 336 | 336 | $existing_user = false; |
| 337 | - $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $activation_key, $login ) ); |
|
| 338 | - if( empty($user) ) { |
|
| 337 | + $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $activation_key, $login)); |
|
| 338 | + if (empty($user)) { |
|
| 339 | 339 | $existing_user = true; |
| 340 | 340 | } |
| 341 | 341 | else { |
| 342 | - $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_email = %s", $activation_key, $login ) ); |
|
| 343 | - if( !empty($user) ) { |
|
| 342 | + $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_email = %s", $activation_key, $login)); |
|
| 343 | + if (!empty($user)) { |
|
| 344 | 344 | $existing_user = true; |
| 345 | 345 | } |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - if ( $existing_user ){ |
|
| 348 | + if ($existing_user) { |
|
| 349 | 349 | wp_set_password($password, $user->ID); |
| 350 | 350 | wp_password_change_notification($user); |
| 351 | 351 | $status = true; |
| 352 | - $result = '<div class="wps-alert-success">' .__('Your password has been updated', 'wpshop'). '. <a href="#" id="display_connexion_form"> ' .__('Connect you', 'wpshop').' !</a></div>'; |
|
| 353 | - $form = self::get_login_form( true ); |
|
| 352 | + $result = '<div class="wps-alert-success">' . __('Your password has been updated', 'wpshop') . '. <a href="#" id="display_connexion_form"> ' . __('Connect you', 'wpshop') . ' !</a></div>'; |
|
| 353 | + $form = self::get_login_form(true); |
|
| 354 | 354 | } |
| 355 | 355 | else { |
| 356 | - $result = '<div class=" wps-alert-error">' .__('Invalid activation key', 'wpshop'). '</div>'; |
|
| 356 | + $result = '<div class=" wps-alert-error">' . __('Invalid activation key', 'wpshop') . '</div>'; |
|
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | 359 | else { |
| 360 | - $result = '<div class=" wps-alert-error">' .__('Invalid activation key', 'wpshop'). '</div>'; |
|
| 360 | + $result = '<div class=" wps-alert-error">' . __('Invalid activation key', 'wpshop') . '</div>'; |
|
| 361 | 361 | } |
| 362 | 362 | } |
| 363 | 363 | else { |
| 364 | - $result = '<div class="wps-alert-error">' .__('Password and confirmation password are differents', 'wpshop'). '</div>'; |
|
| 364 | + $result = '<div class="wps-alert-error">' . __('Password and confirmation password are differents', 'wpshop') . '</div>'; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - $response = array( $status, $result, $form ); |
|
| 368 | - echo json_encode( $response); |
|
| 367 | + $response = array($status, $result, $form); |
|
| 368 | + echo json_encode($response); |
|
| 369 | 369 | die(); |
| 370 | 370 | } |
| 371 | 371 | |
@@ -374,9 +374,9 @@ discard block |
||
| 374 | 374 | * @return string |
| 375 | 375 | */ |
| 376 | 376 | function get_renew_password_form() { |
| 377 | - if ( get_current_user_id() == 0 ) { |
|
| 377 | + if (get_current_user_id() == 0) { |
|
| 378 | 378 | ob_start(); |
| 379 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "forgot-password/password-renew") ); |
|
| 379 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "forgot-password/password-renew")); |
|
| 380 | 380 | $output = ob_get_contents(); |
| 381 | 381 | ob_end_clean(); |
| 382 | 382 | } |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | |
| 386 | 386 | /** FORGOT PASSWORD - AJAX - Get Forgot Password form **/ |
| 387 | 387 | function wps_ajax_get_forgot_password_form() { |
| 388 | - echo json_encode( array(self::get_forgot_password_form() ) ); |
|
| 388 | + echo json_encode(array(self::get_forgot_password_form())); |
|
| 389 | 389 | die(); |
| 390 | 390 | } |
| 391 | 391 | |
@@ -393,29 +393,29 @@ discard block |
||
| 393 | 393 | * SIGN UP - Display Sign up form |
| 394 | 394 | * @return string |
| 395 | 395 | */ |
| 396 | - function display_signup( $args = array() ) { |
|
| 396 | + function display_signup($args = array()) { |
|
| 397 | 397 | global $wpdb; |
| 398 | 398 | $output = ''; |
| 399 | - if ( get_current_user_id() == 0 || !empty($args) ) { |
|
| 399 | + if (get_current_user_id() == 0 || !empty($args)) { |
|
| 400 | 400 | $fields_to_output = $signup_fields = array(); |
| 401 | 401 | |
| 402 | - $password_attribute = $signup_form_attributes = array(); |
|
| 402 | + $password_attribute = $signup_form_attributes = array(); |
|
| 403 | 403 | |
| 404 | - $entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 404 | + $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 405 | 405 | |
| 406 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_SET.' WHERE entity_id = %d', $entity_id); |
|
| 407 | - $customer_entity_id = $wpdb->get_var( $query ); |
|
| 406 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 407 | + $customer_entity_id = $wpdb->get_var($query); |
|
| 408 | 408 | $attributes_set = wpshop_attributes_set::getElement($customer_entity_id); |
| 409 | - $account_attributes = wpshop_attributes_set::getAttributeSetDetails( ( !empty($attributes_set->id) ) ? $attributes_set->id : '', "'valid'"); |
|
| 410 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_GROUP.' WHERE attribute_set_id = %d AND status = %s', $attributes_set->id, 'valid' ); |
|
| 411 | - $customer_attributes_sections = $wpdb->get_results( $query ); |
|
| 412 | - foreach( $customer_attributes_sections as $k => $customer_attributes_section ) { |
|
| 413 | - foreach( $account_attributes[$customer_attributes_section->id]['attribut'] as $attribute ) { |
|
| 409 | + $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'"); |
|
| 410 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND status = %s', $attributes_set->id, 'valid'); |
|
| 411 | + $customer_attributes_sections = $wpdb->get_results($query); |
|
| 412 | + foreach ($customer_attributes_sections as $k => $customer_attributes_section) { |
|
| 413 | + foreach ($account_attributes[$customer_attributes_section->id]['attribut'] as $attribute) { |
|
| 414 | 414 | $signup_fields[] = $attribute; |
| 415 | 415 | } |
| 416 | 416 | } |
| 417 | 417 | ob_start(); |
| 418 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "signup/signup") ); |
|
| 418 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "signup/signup")); |
|
| 419 | 419 | $output = ob_get_contents(); |
| 420 | 420 | ob_end_clean(); |
| 421 | 421 | } |
@@ -426,92 +426,92 @@ discard block |
||
| 426 | 426 | * SIGN UP - Save sign up form |
| 427 | 427 | */ |
| 428 | 428 | function wps_save_signup_form() { |
| 429 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 429 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 430 | 430 | |
| 431 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_signup_form' ) ) |
|
| 431 | + if (!wp_verify_nonce($_wpnonce, 'wps_save_signup_form')) |
|
| 432 | 432 | wp_die(); |
| 433 | 433 | |
| 434 | 434 | global $wpdb, $wpshop; |
| 435 | - $user_id = ( !empty( $_POST['wps_sign_up_request_from_admin'] ) ) ? (int) $_POST['wps_sign_up_request_from_admin'] : get_current_user_id(); |
|
| 435 | + $user_id = (!empty($_POST['wps_sign_up_request_from_admin'])) ? (int)$_POST['wps_sign_up_request_from_admin'] : get_current_user_id(); |
|
| 436 | 436 | $wps_message = new wps_message_ctr(); |
| 437 | 437 | $status = $account_creation = false; $result = ''; |
| 438 | - $exclude_user_meta = array( 'user_email', 'user_pass' ); |
|
| 439 | - $attribute = !empty( $_POST['attribute'] ) ? (array) $_POST['attribute'] : array(); |
|
| 440 | - $element_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 441 | - if ( !empty( $element_id) ){ |
|
| 442 | - $query = $wpdb->prepare('SELECT id FROM ' .WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE entity_id = %d', $element_id ); |
|
| 443 | - $attribute_set_id = $wpdb->get_var( $query ); |
|
| 444 | - if ( !empty($attribute_set_id) ){ |
|
| 445 | - $group = wps_address::get_addresss_form_fields_by_type( $attribute_set_id ); |
|
| 446 | - foreach ( $group as $attribute_sets ) { |
|
| 447 | - foreach ( $attribute_sets as $attribute_set_field ) { |
|
| 448 | - if( !empty($user_id) ) { |
|
| 449 | - foreach( $attribute_set_field['content'] as $attribute_code => $att_def ) { |
|
| 450 | - if( $attribute_code != 'account_user_email' ) { |
|
| 438 | + $exclude_user_meta = array('user_email', 'user_pass'); |
|
| 439 | + $attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : array(); |
|
| 440 | + $element_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 441 | + if (!empty($element_id)) { |
|
| 442 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id); |
|
| 443 | + $attribute_set_id = $wpdb->get_var($query); |
|
| 444 | + if (!empty($attribute_set_id)) { |
|
| 445 | + $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id); |
|
| 446 | + foreach ($group as $attribute_sets) { |
|
| 447 | + foreach ($attribute_sets as $attribute_set_field) { |
|
| 448 | + if (!empty($user_id)) { |
|
| 449 | + foreach ($attribute_set_field['content'] as $attribute_code => $att_def) { |
|
| 450 | + if ($attribute_code != 'account_user_email') { |
|
| 451 | 451 | $attribute_set_field['content'][$attribute_code]['required'] = 'no'; |
| 452 | 452 | } |
| 453 | 453 | } |
| 454 | 454 | } |
| 455 | - $validate = $wpshop->validateForm($attribute_set_field['content'], $attribute ); |
|
| 455 | + $validate = $wpshop->validateForm($attribute_set_field['content'], $attribute); |
|
| 456 | 456 | } |
| 457 | - if ( empty($wpshop->errors) ) { |
|
| 458 | - $user_name = !empty($attribute['varchar']['user_login']) ? sanitize_text_field( $attribute['varchar']['user_login'] ) : sanitize_email( $attribute['varchar']['user_email'] ); |
|
| 459 | - $user_pass = ( !empty($attribute['varchar']['user_pass']) && !empty($_POST['wps_signup_account_creation']) ) ? sanitize_text_field( $attribute['varchar']['user_pass'] ) : wp_generate_password( 12, false ); |
|
| 457 | + if (empty($wpshop->errors)) { |
|
| 458 | + $user_name = !empty($attribute['varchar']['user_login']) ? sanitize_text_field($attribute['varchar']['user_login']) : sanitize_email($attribute['varchar']['user_email']); |
|
| 459 | + $user_pass = (!empty($attribute['varchar']['user_pass']) && !empty($_POST['wps_signup_account_creation'])) ? sanitize_text_field($attribute['varchar']['user_pass']) : wp_generate_password(12, false); |
|
| 460 | 460 | |
| 461 | - if ( $user_id == 0 ) { |
|
| 462 | - $user_id = wp_create_user($user_name, $user_pass, sanitize_email( $attribute['varchar']['user_email'] ) ); |
|
| 463 | - if ( !is_object( $user_id) ) { |
|
| 461 | + if ($user_id == 0) { |
|
| 462 | + $user_id = wp_create_user($user_name, $user_pass, sanitize_email($attribute['varchar']['user_email'])); |
|
| 463 | + if (!is_object($user_id)) { |
|
| 464 | 464 | $account_creation = true; |
| 465 | 465 | /** Update newsletter user preferences **/ |
| 466 | 466 | $newsletter_preferences = array(); |
| 467 | - $newsletters_site = !empty( $_POST['newsletters_site'] ) ? (int) $_POST['newsletters_site'] : 0; |
|
| 468 | - if( !empty($newsletters_site) ) { |
|
| 467 | + $newsletters_site = !empty($_POST['newsletters_site']) ? (int)$_POST['newsletters_site'] : 0; |
|
| 468 | + if (!empty($newsletters_site)) { |
|
| 469 | 469 | $newsletter_preferences['newsletters_site'] = 1; |
| 470 | 470 | } |
| 471 | - $newsletters_site_partners = !empty( $_POST['newsletters_site_partners'] ) ? (int) $_POST['newsletters_site_partners'] : 0; |
|
| 472 | - if( !empty($newsletters_site_partners) ) { |
|
| 471 | + $newsletters_site_partners = !empty($_POST['newsletters_site_partners']) ? (int)$_POST['newsletters_site_partners'] : 0; |
|
| 472 | + if (!empty($newsletters_site_partners)) { |
|
| 473 | 473 | $newsletter_preferences['newsletters_site_partners'] = 1; |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | - update_user_meta( $user_id, 'user_preferences', $newsletter_preferences); |
|
| 476 | + update_user_meta($user_id, 'user_preferences', $newsletter_preferences); |
|
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | - $customer_entity_request = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id); |
|
| 481 | - $customer_post_ID = $wpdb->get_var( $customer_entity_request ); |
|
| 480 | + $customer_entity_request = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id); |
|
| 481 | + $customer_post_ID = $wpdb->get_var($customer_entity_request); |
|
| 482 | 482 | |
| 483 | - if( !empty( $attribute ) ) { |
|
| 483 | + if (!empty($attribute)) { |
|
| 484 | 484 | $user_info = array(); |
| 485 | - foreach( $attribute as $type => $attributes ) { |
|
| 486 | - foreach( $attributes as $meta => $attribute ) { |
|
| 487 | - $user_info[$meta] = sanitize_text_field( $attribute ); |
|
| 485 | + foreach ($attribute as $type => $attributes) { |
|
| 486 | + foreach ($attributes as $meta => $attribute) { |
|
| 487 | + $user_info[$meta] = sanitize_text_field($attribute); |
|
| 488 | 488 | } |
| 489 | 489 | } |
| 490 | - wps_customer_ctr::save_customer_synchronize( $customer_post_ID, $user_id, $user_info ); |
|
| 490 | + wps_customer_ctr::save_customer_synchronize($customer_post_ID, $user_id, $user_info); |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | - if ( !empty( $_SESSION ) && !empty( $_SESSION[ 'cart' ] ) ) { |
|
| 494 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 495 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' )); |
|
| 496 | - $result = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=3'; |
|
| 493 | + if (!empty($_SESSION) && !empty($_SESSION['cart'])) { |
|
| 494 | + $permalink_option = get_option('permalink_structure'); |
|
| 495 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 496 | + $result = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=3'; |
|
| 497 | 497 | } |
| 498 | 498 | else { |
| 499 | - $account_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_myaccount_page_id' )); |
|
| 500 | - $result = get_permalink( $account_page_id ); |
|
| 499 | + $account_page_id = wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')); |
|
| 500 | + $result = get_permalink($account_page_id); |
|
| 501 | 501 | } |
| 502 | 502 | $status = true; |
| 503 | 503 | |
| 504 | - if ( $account_creation && empty($user_id) ) { |
|
| 504 | + if ($account_creation && empty($user_id)) { |
|
| 505 | 505 | $secure_cookie = is_ssl() ? true : false; |
| 506 | 506 | wp_set_auth_cookie($user_id, true, $secure_cookie); |
| 507 | 507 | } |
| 508 | - $wps_message->wpshop_prepared_email( sanitize_email($attribute['varchar']['user_email']), 'WPSHOP_SIGNUP_MESSAGE', array('customer_first_name' => ( !empty($attribute['varchar']['first_name']) ) ? sanitize_text_field( $attribute['varchar']['first_name'] ) : '', 'customer_last_name' => ( !empty($attribute['varchar']['last_name']) ) ? sanitize_text_field( $attribute['varchar']['last_name'] ) : '', 'customer_user_email' => ( !empty($attribute['varchar']['user_email']) ) ? sanitize_email( $attribute['varchar']['user_email'] ) : '') ); |
|
| 508 | + $wps_message->wpshop_prepared_email(sanitize_email($attribute['varchar']['user_email']), 'WPSHOP_SIGNUP_MESSAGE', array('customer_first_name' => (!empty($attribute['varchar']['first_name'])) ? sanitize_text_field($attribute['varchar']['first_name']) : '', 'customer_last_name' => (!empty($attribute['varchar']['last_name'])) ? sanitize_text_field($attribute['varchar']['last_name']) : '', 'customer_user_email' => (!empty($attribute['varchar']['user_email'])) ? sanitize_email($attribute['varchar']['user_email']) : '')); |
|
| 509 | 509 | |
| 510 | 510 | } |
| 511 | 511 | else { |
| 512 | - $result = '<div class="wps-alert-error">' .__('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
| 513 | - foreach( $wpshop->errors as $error ){ |
|
| 514 | - $result .= '<li>' .$error. '</li>'; |
|
| 512 | + $result = '<div class="wps-alert-error">' . __('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
| 513 | + foreach ($wpshop->errors as $error) { |
|
| 514 | + $result .= '<li>' . $error . '</li>'; |
|
| 515 | 515 | } |
| 516 | 516 | $result .= '</div>'; |
| 517 | 517 | } |
@@ -519,7 +519,7 @@ discard block |
||
| 519 | 519 | |
| 520 | 520 | } |
| 521 | 521 | } |
| 522 | - echo json_encode( array( $status, $result, $user_id) ); |
|
| 522 | + echo json_encode(array($status, $result, $user_id)); |
|
| 523 | 523 | die(); |
| 524 | 524 | } |
| 525 | 525 | |
@@ -528,10 +528,10 @@ discard block |
||
| 528 | 528 | */ |
| 529 | 529 | function display_commercial_newsletter_form() { |
| 530 | 530 | $output = ''; |
| 531 | - $user_preferences = get_user_meta( get_current_user_id(), 'user_preferences', true ); |
|
| 532 | - $wpshop_cart_option = get_option( 'wpshop_cart_option' ); |
|
| 531 | + $user_preferences = get_user_meta(get_current_user_id(), 'user_preferences', true); |
|
| 532 | + $wpshop_cart_option = get_option('wpshop_cart_option'); |
|
| 533 | 533 | ob_start(); |
| 534 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "signup/signup", "newsletter") ); |
|
| 534 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "signup/signup", "newsletter")); |
|
| 535 | 535 | $output = ob_get_contents(); |
| 536 | 536 | ob_end_clean(); |
| 537 | 537 | |
@@ -542,88 +542,88 @@ discard block |
||
| 542 | 542 | * ACCOUNT - Display Account informations |
| 543 | 543 | * @return string |
| 544 | 544 | */ |
| 545 | - function display_account_informations( $customer_id = '' ) { |
|
| 545 | + function display_account_informations($customer_id = '') { |
|
| 546 | 546 | global $wpdb; |
| 547 | 547 | $output = $attributes_sections_tpl = $attribute_details = ''; |
| 548 | - $is_from_admin = ( !empty($customer_id) ) ? true : false; |
|
| 549 | - $customer_id = ( !empty($customer_id) ) ? $customer_id : get_current_user_id(); |
|
| 550 | - if( $customer_id != 0 ) { |
|
| 548 | + $is_from_admin = (!empty($customer_id)) ? true : false; |
|
| 549 | + $customer_id = (!empty($customer_id)) ? $customer_id : get_current_user_id(); |
|
| 550 | + if ($customer_id != 0) { |
|
| 551 | 551 | $screen = get_current_screen(); |
| 552 | - if( is_admin() && isset( $screen ) && is_object( $screen ) && $screen->post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) { |
|
| 553 | - $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 554 | - $query = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $customer_id ); |
|
| 555 | - $cid = $wpdb->get_var( $query ); |
|
| 552 | + if (is_admin() && isset($screen) && is_object($screen) && $screen->post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) { |
|
| 553 | + $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 554 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $customer_id); |
|
| 555 | + $cid = $wpdb->get_var($query); |
|
| 556 | 556 | |
| 557 | 557 | $fields_to_output = $signup_fields = array(); |
| 558 | 558 | |
| 559 | - $password_attribute = $signup_form_attributes = array(); |
|
| 559 | + $password_attribute = $signup_form_attributes = array(); |
|
| 560 | 560 | |
| 561 | - $entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 561 | + $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 562 | 562 | |
| 563 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_SET.' WHERE entity_id = %d', $entity_id); |
|
| 564 | - $customer_entity_id = $wpdb->get_var( $query ); |
|
| 563 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 564 | + $customer_entity_id = $wpdb->get_var($query); |
|
| 565 | 565 | $attributes_set = wpshop_attributes_set::getElement($customer_entity_id); |
| 566 | - $account_attributes = wpshop_attributes_set::getAttributeSetDetails( ( !empty($attributes_set->id) ) ? $attributes_set->id : '', "'valid'"); |
|
| 567 | - $query = $wpdb->prepare('SELECT * FROM '.WPSHOP_DBT_ATTRIBUTE_GROUP.' WHERE attribute_set_id = %d', $attributes_set->id ); |
|
| 568 | - $customer_attributes_sections = $wpdb->get_results( $query ); |
|
| 569 | - foreach( $customer_attributes_sections as $k => $attributes_section ) { |
|
| 566 | + $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'"); |
|
| 567 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d', $attributes_set->id); |
|
| 568 | + $customer_attributes_sections = $wpdb->get_results($query); |
|
| 569 | + foreach ($customer_attributes_sections as $k => $attributes_section) { |
|
| 570 | 570 | $signup_fields[$attributes_section->name] = array(); |
| 571 | - if ( !empty( $account_attributes[$attributes_section->id] ) ) { |
|
| 572 | - foreach( $account_attributes[$attributes_section->id]['attribut'] as $attribute ) { |
|
| 571 | + if (!empty($account_attributes[$attributes_section->id])) { |
|
| 572 | + foreach ($account_attributes[$attributes_section->id]['attribut'] as $attribute) { |
|
| 573 | 573 | $signup_fields[$attributes_section->name][] = $attribute; |
| 574 | 574 | } |
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | 577 | ob_start(); |
| 578 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"backend", "customer-informations/customer_informations_form") ); |
|
| 578 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "backend", "customer-informations/customer_informations_form")); |
|
| 579 | 579 | $output = ob_get_contents(); |
| 580 | 580 | ob_end_clean(); |
| 581 | 581 | } else { |
| 582 | - $customer_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 583 | - $query = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $customer_id ); |
|
| 584 | - $cid = $wpdb->get_var( $query ); |
|
| 585 | - |
|
| 586 | - if( !empty($customer_entity_id) ) { |
|
| 587 | - $query = $wpdb->prepare( 'SELECT * FROM '.WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE entity_id = %d AND status = %s AND default_set = %s', $customer_entity_id, 'valid', 'yes' ); |
|
| 588 | - $attributes_sets = $wpdb->get_results( $query ); |
|
| 589 | - foreach( $attributes_sets as $attributes_set ) { |
|
| 590 | - if( !empty($attributes_set->id) ) { |
|
| 591 | - $query = $wpdb->prepare( 'SELECT * FROM '. WPSHOP_DBT_ATTRIBUTE_GROUP. ' WHERE attribute_set_id = %d AND status = %s', $attributes_set->id, 'valid'); |
|
| 592 | - $attributes_sections = $wpdb->get_results( $query ); |
|
| 593 | - |
|
| 594 | - if( !empty($attributes_sections) ) { |
|
| 595 | - foreach( $attributes_sections as $attributes_section ) { |
|
| 596 | - $query = $wpdb->prepare( 'SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE status = %s AND entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', 'valid', $customer_entity_id, $attributes_set->id, $attributes_section->id); |
|
| 597 | - $attributes_details = $wpdb->get_results( $query ); |
|
| 598 | - |
|
| 599 | - foreach( $attributes_details as $attributes_detail ) { |
|
| 600 | - $query = $wpdb->prepare( 'SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE. ' WHERE id = %d AND status = %s', $attributes_detail->attribute_id, 'valid' ); |
|
| 601 | - $attribute_def = $wpdb->get_row( $query ); |
|
| 602 | - |
|
| 603 | - $query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX.strtolower($attribute_def->data_type). ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d ', $customer_entity_id, $attribute_def->id, $cid ); |
|
| 604 | - $attribute_value = $wpdb->get_var( $query ); |
|
| 582 | + $customer_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 583 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $customer_id); |
|
| 584 | + $cid = $wpdb->get_var($query); |
|
| 585 | + |
|
| 586 | + if (!empty($customer_entity_id)) { |
|
| 587 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s AND default_set = %s', $customer_entity_id, 'valid', 'yes'); |
|
| 588 | + $attributes_sets = $wpdb->get_results($query); |
|
| 589 | + foreach ($attributes_sets as $attributes_set) { |
|
| 590 | + if (!empty($attributes_set->id)) { |
|
| 591 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND status = %s', $attributes_set->id, 'valid'); |
|
| 592 | + $attributes_sections = $wpdb->get_results($query); |
|
| 593 | + |
|
| 594 | + if (!empty($attributes_sections)) { |
|
| 595 | + foreach ($attributes_sections as $attributes_section) { |
|
| 596 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE status = %s AND entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', 'valid', $customer_entity_id, $attributes_set->id, $attributes_section->id); |
|
| 597 | + $attributes_details = $wpdb->get_results($query); |
|
| 598 | + |
|
| 599 | + foreach ($attributes_details as $attributes_detail) { |
|
| 600 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE id = %d AND status = %s', $attributes_detail->attribute_id, 'valid'); |
|
| 601 | + $attribute_def = $wpdb->get_row($query); |
|
| 602 | + |
|
| 603 | + $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type) . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d ', $customer_entity_id, $attribute_def->id, $cid); |
|
| 604 | + $attribute_value = $wpdb->get_var($query); |
|
| 605 | 605 | |
| 606 | 606 | /** Check attribute type for specific type display */ |
| 607 | - if ( "datetime" == $attribute_def->data_type ) { |
|
| 608 | - $attribute_value = mysql2date( get_option( 'date_format' ) . ( ( substr( $attribute_value, -9 ) != ' 00:00:00' ) ? ' ' . get_option( 'time_format' ) : '' ), $attribute_value, true); |
|
| 607 | + if ("datetime" == $attribute_def->data_type) { |
|
| 608 | + $attribute_value = mysql2date(get_option('date_format') . ((substr($attribute_value, -9) != ' 00:00:00') ? ' ' . get_option('time_format') : ''), $attribute_value, true); |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | /** Check attribute input type in order to get specific value */ |
| 612 | - if ( in_array( $attribute_def->backend_input, array( 'multiple-select', 'select', 'radio', 'checkbox' ) ) ) { |
|
| 613 | - if ( $attribute_def->data_type_to_use == 'custom' ) { |
|
| 614 | - $query = $wpdb->prepare("SELECT label FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE attribute_id = %d AND status = 'valid' AND id = %d", $attribute_def->id, $attribute_value ); |
|
| 615 | - $attribute_value = $wpdb->get_var( $query ); |
|
| 612 | + if (in_array($attribute_def->backend_input, array('multiple-select', 'select', 'radio', 'checkbox'))) { |
|
| 613 | + if ($attribute_def->data_type_to_use == 'custom') { |
|
| 614 | + $query = $wpdb->prepare("SELECT label FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE attribute_id = %d AND status = 'valid' AND id = %d", $attribute_def->id, $attribute_value); |
|
| 615 | + $attribute_value = $wpdb->get_var($query); |
|
| 616 | 616 | } |
| 617 | - else if ( $attribute_def->data_type_to_use == 'internal') { |
|
| 618 | - $associated_post = get_post( $atribute_value ); |
|
| 617 | + else if ($attribute_def->data_type_to_use == 'internal') { |
|
| 618 | + $associated_post = get_post($atribute_value); |
|
| 619 | 619 | $attribute_value = $associated_post->post_title; |
| 620 | 620 | } |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - if( !empty( $attribute_def ) ) { |
|
| 624 | - if( $attribute_def->frontend_input != 'password' ) { |
|
| 623 | + if (!empty($attribute_def)) { |
|
| 624 | + if ($attribute_def->frontend_input != 'password') { |
|
| 625 | 625 | ob_start(); |
| 626 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "account/account_informations_element") ); |
|
| 626 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_informations_element")); |
|
| 627 | 627 | $attribute_details .= ob_get_contents(); |
| 628 | 628 | ob_end_clean(); |
| 629 | 629 | } |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | ob_start(); |
| 634 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "account/account_informations_group_element") ); |
|
| 634 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_informations_group_element")); |
|
| 635 | 635 | $attributes_sections_tpl .= ob_get_contents(); |
| 636 | 636 | ob_end_clean(); |
| 637 | 637 | |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | } |
| 643 | 643 | } |
| 644 | 644 | ob_start(); |
| 645 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_informations") ); |
|
| 645 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_informations")); |
|
| 646 | 646 | $output = ob_get_contents(); |
| 647 | 647 | ob_end_clean(); |
| 648 | 648 | } |
@@ -656,85 +656,85 @@ discard block |
||
| 656 | 656 | function account_informations_form() { |
| 657 | 657 | global $wpdb; |
| 658 | 658 | $output = ''; |
| 659 | - if ( get_current_user_id() != 0 ) { |
|
| 659 | + if (get_current_user_id() != 0) { |
|
| 660 | 660 | // Customer ID data |
| 661 | - $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 662 | - $query = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, get_current_user_id() ); |
|
| 663 | - $cid = $wpdb->get_var( $query ); |
|
| 661 | + $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 662 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, get_current_user_id()); |
|
| 663 | + $cid = $wpdb->get_var($query); |
|
| 664 | 664 | |
| 665 | 665 | $fields_to_output = $signup_fields = array(); |
| 666 | 666 | |
| 667 | - $password_attribute = $signup_form_attributes = array(); |
|
| 667 | + $password_attribute = $signup_form_attributes = array(); |
|
| 668 | 668 | |
| 669 | - $entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 669 | + $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 670 | 670 | |
| 671 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_SET.' WHERE entity_id = %d', $entity_id); |
|
| 672 | - $customer_entity_id = $wpdb->get_var( $query ); |
|
| 671 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 672 | + $customer_entity_id = $wpdb->get_var($query); |
|
| 673 | 673 | $attributes_set = wpshop_attributes_set::getElement($customer_entity_id); |
| 674 | - $account_attributes = wpshop_attributes_set::getAttributeSetDetails( ( !empty($attributes_set->id) ) ? $attributes_set->id : '', "'valid'"); |
|
| 675 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_GROUP.' WHERE attribute_set_id = %d', $attributes_set->id ); |
|
| 676 | - $customer_attributes_sections = $wpdb->get_results( $query ); |
|
| 677 | - foreach( $customer_attributes_sections as $k => $customer_attributes_section ) { |
|
| 678 | - if ( !empty( $account_attributes[$customer_attributes_section->id] ) ) { |
|
| 679 | - foreach( $account_attributes[$customer_attributes_section->id]['attribut'] as $attribute ) { |
|
| 674 | + $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'"); |
|
| 675 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d', $attributes_set->id); |
|
| 676 | + $customer_attributes_sections = $wpdb->get_results($query); |
|
| 677 | + foreach ($customer_attributes_sections as $k => $customer_attributes_section) { |
|
| 678 | + if (!empty($account_attributes[$customer_attributes_section->id])) { |
|
| 679 | + foreach ($account_attributes[$customer_attributes_section->id]['attribut'] as $attribute) { |
|
| 680 | 680 | $signup_fields[] = $attribute; |
| 681 | 681 | } |
| 682 | 682 | } |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | ob_start(); |
| 686 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "account/account_form") ); |
|
| 686 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_form")); |
|
| 687 | 687 | $output = ob_get_contents(); |
| 688 | 688 | ob_end_clean(); |
| 689 | 689 | } |
| 690 | 690 | return $output; |
| 691 | 691 | } |
| 692 | 692 | |
| 693 | - function save_account_informations( $cid, $args, $admin = true ) { |
|
| 693 | + function save_account_informations($cid, $args, $admin = true) { |
|
| 694 | 694 | global $wpdb; global $wpshop; |
| 695 | 695 | |
| 696 | - $exclude_user_meta = array( 'user_email', 'user_pass' ); |
|
| 696 | + $exclude_user_meta = array('user_email', 'user_pass'); |
|
| 697 | 697 | $wps_entities = new wpshop_entities(); |
| 698 | - $element_id = $wps_entities->get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 698 | + $element_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 699 | 699 | |
| 700 | - $query = $wpdb->prepare( 'SELECT post_author FROM ' .$wpdb->posts. ' WHERE post_type = %s AND ID = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $cid ); |
|
| 701 | - $user_id = $wpdb->get_var( $query ); |
|
| 700 | + $query = $wpdb->prepare('SELECT post_author FROM ' . $wpdb->posts . ' WHERE post_type = %s AND ID = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $cid); |
|
| 701 | + $user_id = $wpdb->get_var($query); |
|
| 702 | 702 | |
| 703 | 703 | $user_name = !empty($args['attribute']['varchar']['user_login']) ? $args['attribute']['varchar']['user_login'] : $args['attribute']['varchar']['user_email']; |
| 704 | - $user_pass = ( !empty($args['attribute']['varchar']['user_pass']) ) ? $args['attribute']['varchar']['user_pass'] : ''; |
|
| 704 | + $user_pass = (!empty($args['attribute']['varchar']['user_pass'])) ? $args['attribute']['varchar']['user_pass'] : ''; |
|
| 705 | 705 | |
| 706 | - $query = $wpdb->prepare('SELECT id FROM ' .WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE entity_id = %d', $element_id ); |
|
| 707 | - $attribute_set_id = $wpdb->get_var( $query ); |
|
| 708 | - if ( !empty($attribute_set_id) ) { |
|
| 709 | - $group = wps_address::get_addresss_form_fields_by_type( $attribute_set_id ); |
|
| 706 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id); |
|
| 707 | + $attribute_set_id = $wpdb->get_var($query); |
|
| 708 | + if (!empty($attribute_set_id)) { |
|
| 709 | + $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id); |
|
| 710 | 710 | //Save data in attribute tables, ckeck first if exist to know if Insert or Update |
| 711 | - wpshop_attributes::saveAttributeForEntity( $args['attribute'], $element_id, $cid ); |
|
| 712 | - foreach ( $group as $attribute_sets ) { |
|
| 713 | - foreach ( $attribute_sets as $attribute_set_field ) { |
|
| 714 | - if( $admin ) { |
|
| 715 | - $validate = $wpshop->validateForm($attribute_set_field['content'], $args['attribute'] ); |
|
| 711 | + wpshop_attributes::saveAttributeForEntity($args['attribute'], $element_id, $cid); |
|
| 712 | + foreach ($group as $attribute_sets) { |
|
| 713 | + foreach ($attribute_sets as $attribute_set_field) { |
|
| 714 | + if ($admin) { |
|
| 715 | + $validate = $wpshop->validateForm($attribute_set_field['content'], $args['attribute']); |
|
| 716 | 716 | } |
| 717 | - if ( empty($wpshop->errors) || !$admin ) { |
|
| 717 | + if (empty($wpshop->errors) || !$admin) { |
|
| 718 | 718 | $wpshop_attributes = new wpshop_attributes(); |
| 719 | - foreach( $attribute_set_field['content'] as $attribute ) { |
|
| 720 | - $attribute_def = wpshop_attributes::getElement( $attribute['name'], "'valid'", 'code'); |
|
| 721 | - if ( !in_array( $attribute['name'], $exclude_user_meta ) ) { |
|
| 722 | - update_user_meta( $user_id, $attribute['name'], wpshop_tools::varSanitizer( $args['attribute'][$attribute['data_type']][$attribute['name']]) ); |
|
| 719 | + foreach ($attribute_set_field['content'] as $attribute) { |
|
| 720 | + $attribute_def = wpshop_attributes::getElement($attribute['name'], "'valid'", 'code'); |
|
| 721 | + if (!in_array($attribute['name'], $exclude_user_meta)) { |
|
| 722 | + update_user_meta($user_id, $attribute['name'], wpshop_tools::varSanitizer($args['attribute'][$attribute['data_type']][$attribute['name']])); |
|
| 723 | 723 | } |
| 724 | 724 | else { |
| 725 | - wp_update_user( array('ID' => $user_id, $attribute['name'] => wpshop_tools::varSanitizer( $args['attribute'][$attribute['data_type']][$attribute['name']]) ) ); |
|
| 725 | + wp_update_user(array('ID' => $user_id, $attribute['name'] => wpshop_tools::varSanitizer($args['attribute'][$attribute['data_type']][$attribute['name']]))); |
|
| 726 | 726 | } |
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | /** Update newsletter user preferences **/ |
| 730 | 730 | $newsletter_preferences = array(); |
| 731 | - if( !empty($args['newsletters_site']) ) { |
|
| 731 | + if (!empty($args['newsletters_site'])) { |
|
| 732 | 732 | $newsletter_preferences['newsletters_site'] = 1; |
| 733 | 733 | } |
| 734 | - if( !empty($args['newsletters_site_partners']) ) { |
|
| 734 | + if (!empty($args['newsletters_site_partners'])) { |
|
| 735 | 735 | $newsletter_preferences['newsletters_site_partners'] = 1; |
| 736 | 736 | } |
| 737 | - update_user_meta( $user_id, 'user_preferences', $newsletter_preferences); |
|
| 737 | + update_user_meta($user_id, 'user_preferences', $newsletter_preferences); |
|
| 738 | 738 | } else { |
| 739 | 739 | return $wpshop->errors; |
| 740 | 740 | } |
@@ -746,10 +746,10 @@ discard block |
||
| 746 | 746 | /** |
| 747 | 747 | * ACCOUNT - Save account informations |
| 748 | 748 | */ |
| 749 | - function wps_save_account_informations () { |
|
| 750 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 749 | + function wps_save_account_informations() { |
|
| 750 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 751 | 751 | |
| 752 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_account_informations' ) ) |
|
| 752 | + if (!wp_verify_nonce($_wpnonce, 'wps_save_account_informations')) |
|
| 753 | 753 | wp_die(); |
| 754 | 754 | |
| 755 | 755 | global $wpdb; |
@@ -757,24 +757,24 @@ discard block |
||
| 757 | 757 | |
| 758 | 758 | $user_id = get_current_user_id(); |
| 759 | 759 | |
| 760 | - if ( !empty($user_id) ) { |
|
| 761 | - $query = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id ); |
|
| 762 | - $cid = $wpdb->get_var( $query ); |
|
| 760 | + if (!empty($user_id)) { |
|
| 761 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id); |
|
| 762 | + $cid = $wpdb->get_var($query); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | // @TODO |
| 766 | - $errors = $this->save_account_informations( $cid, array() ); |
|
| 766 | + $errors = $this->save_account_informations($cid, array()); |
|
| 767 | 767 | |
| 768 | - if( !empty( $errors ) ) { |
|
| 769 | - $response = '<div class="wps-alert-error">' .__('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
| 770 | - foreach( $errors as $error ){ |
|
| 768 | + if (!empty($errors)) { |
|
| 769 | + $response = '<div class="wps-alert-error">' . __('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
| 770 | + foreach ($errors as $error) { |
|
| 771 | 771 | $response .= '<li>' . $error . '</li>'; |
| 772 | 772 | } |
| 773 | 773 | $response .= '</div>'; |
| 774 | 774 | } else { |
| 775 | 775 | $status = true; |
| 776 | 776 | } |
| 777 | - echo json_encode( array( 'status' => $status, 'response' => $response) ); |
|
| 777 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 778 | 778 | wp_die(); |
| 779 | 779 | } |
| 780 | 780 | |
@@ -782,17 +782,17 @@ discard block |
||
| 782 | 782 | * ACCOUNT - AJAX - Reload account informations data |
| 783 | 783 | */ |
| 784 | 784 | function wps_account_reload_informations() { |
| 785 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 785 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 786 | 786 | |
| 787 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_account_reload_informations' ) ) |
|
| 787 | + if (!wp_verify_nonce($_wpnonce, 'wps_account_reload_informations')) |
|
| 788 | 788 | wp_die(); |
| 789 | 789 | |
| 790 | 790 | $status = false; |
| 791 | 791 | $response = do_shortcode('[wps_account_informations]'); |
| 792 | - if( !empty($response) ) { |
|
| 792 | + if (!empty($response)) { |
|
| 793 | 793 | $status = true; |
| 794 | 794 | } |
| 795 | - echo json_encode( array('status' => $status, 'response' => $response) ); |
|
| 795 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 796 | 796 | wp_die(); |
| 797 | 797 | } |
| 798 | 798 | |
@@ -800,15 +800,15 @@ discard block |
||
| 800 | 800 | * ACCOUNT - AJAX - Fill account informations modal |
| 801 | 801 | */ |
| 802 | 802 | function wps_fill_account_informations_modal() { |
| 803 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 803 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 804 | 804 | |
| 805 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_fill_account_informations_modal' ) ) |
|
| 805 | + if (!wp_verify_nonce($_wpnonce, 'wps_fill_account_informations_modal')) |
|
| 806 | 806 | wp_die(); |
| 807 | 807 | |
| 808 | 808 | $title = $content = ''; |
| 809 | 809 | $title = __('Edit your account informations', 'wpshop'); |
| 810 | - $content = do_shortcode( '[wps_account_informations_form]' ); |
|
| 811 | - echo json_encode( array( 'status' => true, 'title' => $title, 'content' => $content) ); |
|
| 810 | + $content = do_shortcode('[wps_account_informations_form]'); |
|
| 811 | + echo json_encode(array('status' => true, 'title' => $title, 'content' => $content)); |
|
| 812 | 812 | wp_die(); |
| 813 | 813 | } |
| 814 | 814 | |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | class wps_account_ctr { |
| 3 | 5 | /** Define the main directory containing the template for the current plugin |
| 4 | 6 | * @var string |
@@ -81,15 +83,13 @@ discard block |
||
| 81 | 83 | $args = array(); |
| 82 | 84 | if ( get_current_user_id() != 0 ) { |
| 83 | 85 | return __( 'You are already logged', 'wpshop'); |
| 84 | - } |
|
| 85 | - else { |
|
| 86 | + } else { |
|
| 86 | 87 | $action = !empty( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
| 87 | 88 | $key = !empty( $_GET['key'] ) ? sanitize_text_field( $_GET['key'] ) : ''; |
| 88 | 89 | $login = !empty( $_GET['login'] ) ? sanitize_text_field( $_GET['login'] ) : 0; |
| 89 | 90 | if ( !empty($action) && $action == 'retrieve_password' && !empty($key) && !empty($login) && !$force_login ) { |
| 90 | 91 | $output = self::get_renew_password_form(); |
| 91 | - } |
|
| 92 | - else { |
|
| 92 | + } else { |
|
| 93 | 93 | ob_start(); |
| 94 | 94 | require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "login/login-form") ); |
| 95 | 95 | $output = ob_get_contents(); |
@@ -107,8 +107,9 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 109 | 109 | |
| 110 | - if ( !wp_verify_nonce( $_wpnonce, 'control_login_form_request' ) ) |
|
| 111 | - wp_die(); |
|
| 110 | + if ( !wp_verify_nonce( $_wpnonce, 'control_login_form_request' ) ) { |
|
| 111 | + wp_die(); |
|
| 112 | + } |
|
| 112 | 113 | |
| 113 | 114 | $result = ''; |
| 114 | 115 | $status = false; |
@@ -122,8 +123,7 @@ discard block |
||
| 122 | 123 | $user_checking = get_user_by( 'login', $wps_login_user_login ); |
| 123 | 124 | if( !empty($user_checking) ) { |
| 124 | 125 | $creds['user_login'] = $wps_login_user_login; |
| 125 | - } |
|
| 126 | - else { |
|
| 126 | + } else { |
|
| 127 | 127 | if ( is_email($wps_login_user_login) ) { |
| 128 | 128 | $user_checking = get_user_by( 'email', $wps_login_user_login ); |
| 129 | 129 | $creds['user_login'] = $user_checking->user_login; |
@@ -134,20 +134,17 @@ discard block |
||
| 134 | 134 | $user = wp_signon( $creds, false ); |
| 135 | 135 | if ( is_wp_error($user) ) { |
| 136 | 136 | $result = '<div class="wps-alert-error">' .__('Connexion error', 'wpshop'). '</div>'; |
| 137 | - } |
|
| 138 | - else { |
|
| 137 | + } else { |
|
| 139 | 138 | $permalink_option = get_option( 'permalink_structure' ); |
| 140 | 139 | $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
| 141 | 140 | if( $origin == $page_account_id ) { |
| 142 | 141 | $result = get_permalink( $page_account_id ); |
| 143 | - } |
|
| 144 | - else { |
|
| 142 | + } else { |
|
| 145 | 143 | $result = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=3'; |
| 146 | 144 | } |
| 147 | 145 | $status = true; |
| 148 | 146 | } |
| 149 | - } |
|
| 150 | - else { |
|
| 147 | + } else { |
|
| 151 | 148 | $result = '<div class="wps-alert-error">' .__('E-Mail and Password are required', 'wpshop'). '</div>'; |
| 152 | 149 | } |
| 153 | 150 | |
@@ -161,8 +158,9 @@ discard block |
||
| 161 | 158 | function wps_ajax_get_login_form_interface() { |
| 162 | 159 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 163 | 160 | |
| 164 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_ajax_get_login_form_interface' ) ) |
|
| 165 | - wp_die(); |
|
| 161 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_ajax_get_login_form_interface' ) ) { |
|
| 162 | + wp_die(); |
|
| 163 | + } |
|
| 166 | 164 | |
| 167 | 165 | $response = array( 'status' => true, 'response' => self::get_login_form() ); |
| 168 | 166 | echo json_encode( $response ); |
@@ -185,8 +183,9 @@ discard block |
||
| 185 | 183 | function wps_login_first_request() { |
| 186 | 184 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 187 | 185 | |
| 188 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_login_first_request' ) ) |
|
| 189 | - wp_die(); |
|
| 186 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_login_first_request' ) ) { |
|
| 187 | + wp_die(); |
|
| 188 | + } |
|
| 190 | 189 | |
| 191 | 190 | $status = false; $login_action = false; $response = ''; |
| 192 | 191 | $user_email = ( !empty($_POST['email_address']) ) ? wpshop_tools::varSanitizer( $_POST['email_address'] ) : null; |
@@ -198,8 +197,7 @@ discard block |
||
| 198 | 197 | $login_action = true; |
| 199 | 198 | $user_firstname = get_user_meta( $checking_user->ID, 'first_name', true ); |
| 200 | 199 | $response = $user_firstname; |
| 201 | - } |
|
| 202 | - else { |
|
| 200 | + } else { |
|
| 203 | 201 | $checking_user = get_user_by( 'email', $user_email); |
| 204 | 202 | if ( !empty( $checking_user ) ) { |
| 205 | 203 | $login_action = true; |
@@ -211,8 +209,7 @@ discard block |
||
| 211 | 209 | if( !$login_action && is_email($user_email) ) { |
| 212 | 210 | $response = $user_email; |
| 213 | 211 | } |
| 214 | - } |
|
| 215 | - else { |
|
| 212 | + } else { |
|
| 216 | 213 | $response = '<div class="wps-alert-error">' .__( 'An e-mail address is required', 'wpshop' ). '</div>'; |
| 217 | 214 | } |
| 218 | 215 | echo json_encode( array( 'status'=> $status, 'response' => $response, 'login_action' => $login_action) ); |
@@ -239,8 +236,9 @@ discard block |
||
| 239 | 236 | function wps_fill_forgot_password_modal() { |
| 240 | 237 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 241 | 238 | |
| 242 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_fill_forgot_password_modal' ) ) |
|
| 243 | - wp_die(); |
|
| 239 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_fill_forgot_password_modal' ) ) { |
|
| 240 | + wp_die(); |
|
| 241 | + } |
|
| 244 | 242 | |
| 245 | 243 | $status = false; $title = $content = ''; |
| 246 | 244 | $title = __( 'Forgot password', 'wpshop' ); |
@@ -256,8 +254,9 @@ discard block |
||
| 256 | 254 | function wps_forgot_password_request() { |
| 257 | 255 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 258 | 256 | |
| 259 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_forgot_password_request' ) ) |
|
| 260 | - wp_die(); |
|
| 257 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_forgot_password_request' ) ) { |
|
| 258 | + wp_die(); |
|
| 259 | + } |
|
| 261 | 260 | |
| 262 | 261 | global $wpdb; |
| 263 | 262 | $status = false; $result = ''; |
@@ -267,8 +266,7 @@ discard block |
||
| 267 | 266 | $exist_user = get_user_by('login', $user_login); |
| 268 | 267 | if( !empty($exist_user) ) { |
| 269 | 268 | $existing_user = true; |
| 270 | - } |
|
| 271 | - else { |
|
| 269 | + } else { |
|
| 272 | 270 | $exist_user = get_user_by('email', $user_login); |
| 273 | 271 | if ( !empty($exist_user) ) { |
| 274 | 272 | $existing_user = true; |
@@ -284,12 +282,10 @@ discard block |
||
| 284 | 282 | $this->send_forgot_password_email($key, $user_login, $exist_user); |
| 285 | 283 | $result = '<div class="wps-alert-info">' .__('An e-mail with an password renew link has been sent to you', 'wpshop'). '</div>'; |
| 286 | 284 | $status = true; |
| 287 | - } |
|
| 288 | - else { |
|
| 285 | + } else { |
|
| 289 | 286 | $result = '<div class="wps-alert-error">' .__('No customer account corresponds to this email', 'wpshop'). '</div>'; |
| 290 | 287 | } |
| 291 | - } |
|
| 292 | - else { |
|
| 288 | + } else { |
|
| 293 | 289 | $result = '<div class="wps-alert-error">' .__('Please fill the required field', 'wpshop'). '</div>'; |
| 294 | 290 | } |
| 295 | 291 | $response = array( $status, $result ); |
@@ -322,8 +318,9 @@ discard block |
||
| 322 | 318 | function wps_forgot_password_renew() { |
| 323 | 319 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 324 | 320 | |
| 325 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_forgot_password_renew' ) ) |
|
| 326 | - wp_die(); |
|
| 321 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_forgot_password_renew' ) ) { |
|
| 322 | + wp_die(); |
|
| 323 | + } |
|
| 327 | 324 | |
| 328 | 325 | global $wpdb; |
| 329 | 326 | $status = false; $result = $form = ''; |
@@ -337,8 +334,7 @@ discard block |
||
| 337 | 334 | $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $activation_key, $login ) ); |
| 338 | 335 | if( empty($user) ) { |
| 339 | 336 | $existing_user = true; |
| 340 | - } |
|
| 341 | - else { |
|
| 337 | + } else { |
|
| 342 | 338 | $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_email = %s", $activation_key, $login ) ); |
| 343 | 339 | if( !empty($user) ) { |
| 344 | 340 | $existing_user = true; |
@@ -351,16 +347,13 @@ discard block |
||
| 351 | 347 | $status = true; |
| 352 | 348 | $result = '<div class="wps-alert-success">' .__('Your password has been updated', 'wpshop'). '. <a href="#" id="display_connexion_form"> ' .__('Connect you', 'wpshop').' !</a></div>'; |
| 353 | 349 | $form = self::get_login_form( true ); |
| 354 | - } |
|
| 355 | - else { |
|
| 350 | + } else { |
|
| 356 | 351 | $result = '<div class=" wps-alert-error">' .__('Invalid activation key', 'wpshop'). '</div>'; |
| 357 | 352 | } |
| 358 | - } |
|
| 359 | - else { |
|
| 353 | + } else { |
|
| 360 | 354 | $result = '<div class=" wps-alert-error">' .__('Invalid activation key', 'wpshop'). '</div>'; |
| 361 | 355 | } |
| 362 | - } |
|
| 363 | - else { |
|
| 356 | + } else { |
|
| 364 | 357 | $result = '<div class="wps-alert-error">' .__('Password and confirmation password are differents', 'wpshop'). '</div>'; |
| 365 | 358 | } |
| 366 | 359 | |
@@ -428,8 +421,9 @@ discard block |
||
| 428 | 421 | function wps_save_signup_form() { |
| 429 | 422 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 430 | 423 | |
| 431 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_signup_form' ) ) |
|
| 432 | - wp_die(); |
|
| 424 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_save_signup_form' ) ) { |
|
| 425 | + wp_die(); |
|
| 426 | + } |
|
| 433 | 427 | |
| 434 | 428 | global $wpdb, $wpshop; |
| 435 | 429 | $user_id = ( !empty( $_POST['wps_sign_up_request_from_admin'] ) ) ? (int) $_POST['wps_sign_up_request_from_admin'] : get_current_user_id(); |
@@ -494,8 +488,7 @@ discard block |
||
| 494 | 488 | $permalink_option = get_option( 'permalink_structure' ); |
| 495 | 489 | $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' )); |
| 496 | 490 | $result = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=3'; |
| 497 | - } |
|
| 498 | - else { |
|
| 491 | + } else { |
|
| 499 | 492 | $account_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_myaccount_page_id' )); |
| 500 | 493 | $result = get_permalink( $account_page_id ); |
| 501 | 494 | } |
@@ -507,8 +500,7 @@ discard block |
||
| 507 | 500 | } |
| 508 | 501 | $wps_message->wpshop_prepared_email( sanitize_email($attribute['varchar']['user_email']), 'WPSHOP_SIGNUP_MESSAGE', array('customer_first_name' => ( !empty($attribute['varchar']['first_name']) ) ? sanitize_text_field( $attribute['varchar']['first_name'] ) : '', 'customer_last_name' => ( !empty($attribute['varchar']['last_name']) ) ? sanitize_text_field( $attribute['varchar']['last_name'] ) : '', 'customer_user_email' => ( !empty($attribute['varchar']['user_email']) ) ? sanitize_email( $attribute['varchar']['user_email'] ) : '') ); |
| 509 | 502 | |
| 510 | - } |
|
| 511 | - else { |
|
| 503 | + } else { |
|
| 512 | 504 | $result = '<div class="wps-alert-error">' .__('Some errors have been detected', 'wpshop') . ' : <ul>'; |
| 513 | 505 | foreach( $wpshop->errors as $error ){ |
| 514 | 506 | $result .= '<li>' .$error. '</li>'; |
@@ -613,8 +605,7 @@ discard block |
||
| 613 | 605 | if ( $attribute_def->data_type_to_use == 'custom' ) { |
| 614 | 606 | $query = $wpdb->prepare("SELECT label FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE attribute_id = %d AND status = 'valid' AND id = %d", $attribute_def->id, $attribute_value ); |
| 615 | 607 | $attribute_value = $wpdb->get_var( $query ); |
| 616 | - } |
|
| 617 | - else if ( $attribute_def->data_type_to_use == 'internal') { |
|
| 608 | + } else if ( $attribute_def->data_type_to_use == 'internal') { |
|
| 618 | 609 | $associated_post = get_post( $atribute_value ); |
| 619 | 610 | $attribute_value = $associated_post->post_title; |
| 620 | 611 | } |
@@ -720,8 +711,7 @@ discard block |
||
| 720 | 711 | $attribute_def = wpshop_attributes::getElement( $attribute['name'], "'valid'", 'code'); |
| 721 | 712 | if ( !in_array( $attribute['name'], $exclude_user_meta ) ) { |
| 722 | 713 | update_user_meta( $user_id, $attribute['name'], wpshop_tools::varSanitizer( $args['attribute'][$attribute['data_type']][$attribute['name']]) ); |
| 723 | - } |
|
| 724 | - else { |
|
| 714 | + } else { |
|
| 725 | 715 | wp_update_user( array('ID' => $user_id, $attribute['name'] => wpshop_tools::varSanitizer( $args['attribute'][$attribute['data_type']][$attribute['name']]) ) ); |
| 726 | 716 | } |
| 727 | 717 | } |
@@ -749,8 +739,9 @@ discard block |
||
| 749 | 739 | function wps_save_account_informations () { |
| 750 | 740 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 751 | 741 | |
| 752 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_account_informations' ) ) |
|
| 753 | - wp_die(); |
|
| 742 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_save_account_informations' ) ) { |
|
| 743 | + wp_die(); |
|
| 744 | + } |
|
| 754 | 745 | |
| 755 | 746 | global $wpdb; |
| 756 | 747 | $status = false; $response = ''; |
@@ -784,8 +775,9 @@ discard block |
||
| 784 | 775 | function wps_account_reload_informations() { |
| 785 | 776 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 786 | 777 | |
| 787 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_account_reload_informations' ) ) |
|
| 788 | - wp_die(); |
|
| 778 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_account_reload_informations' ) ) { |
|
| 779 | + wp_die(); |
|
| 780 | + } |
|
| 789 | 781 | |
| 790 | 782 | $status = false; |
| 791 | 783 | $response = do_shortcode('[wps_account_informations]'); |
@@ -802,8 +794,9 @@ discard block |
||
| 802 | 794 | function wps_fill_account_informations_modal() { |
| 803 | 795 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 804 | 796 | |
| 805 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_fill_account_informations_modal' ) ) |
|
| 806 | - wp_die(); |
|
| 797 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_fill_account_informations_modal' ) ) { |
|
| 798 | + wp_die(); |
|
| 799 | + } |
|
| 807 | 800 | |
| 808 | 801 | $title = $content = ''; |
| 809 | 802 | $title = __('Edit your account informations', 'wpshop'); |
@@ -276,7 +276,6 @@ |
||
| 276 | 276 | /** |
| 277 | 277 | * Add metas in user when customer is modified |
| 278 | 278 | * |
| 279 | - * @param integer $post_id |
|
| 280 | 279 | * @param WP_Post $post |
| 281 | 280 | */ |
| 282 | 281 | public static function save_entity_customer( $customer_post_ID, $post ) { |
@@ -175,16 +175,16 @@ discard block |
||
| 175 | 175 | 'publicly_queryable' => false, |
| 176 | 176 | 'rewrite' => false, |
| 177 | 177 | 'menu_icon' => 'dashicons-id-alt', |
| 178 | - 'capabilities' => array( |
|
| 179 | - 'create_posts' => 'wpshop_view_dashboard', |
|
| 178 | + 'capabilities' => array( |
|
| 179 | + 'create_posts' => 'wpshop_view_dashboard', |
|
| 180 | 180 | 'edit_post' => 'wpshop_view_dashboard', |
| 181 | - 'edit_posts' => 'wpshop_view_dashboard', |
|
| 182 | - 'edit_others_posts' => 'wpshop_view_dashboard', |
|
| 183 | - 'publish_posts' => 'wpshop_view_dashboard', |
|
| 184 | - 'read_post' => 'wpshop_view_dashboard', |
|
| 185 | - 'read_private_posts' => 'wpshop_view_dashboard', |
|
| 181 | + 'edit_posts' => 'wpshop_view_dashboard', |
|
| 182 | + 'edit_others_posts' => 'wpshop_view_dashboard', |
|
| 183 | + 'publish_posts' => 'wpshop_view_dashboard', |
|
| 184 | + 'read_post' => 'wpshop_view_dashboard', |
|
| 185 | + 'read_private_posts' => 'wpshop_view_dashboard', |
|
| 186 | 186 | 'delete_posts' => 'delete_product' |
| 187 | - ) |
|
| 187 | + ) |
|
| 188 | 188 | ); |
| 189 | 189 | register_post_type( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_type_params ); |
| 190 | 190 | } |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | /* JS to select customer in place of suscriber */ |
| 229 | 229 | public function admin_user_customer_js() { |
| 230 | - echo "<script type='text/javascript'>\n"; |
|
| 231 | - echo "jQuery(document).ready(function($) {"; |
|
| 232 | - echo "\n$('#role').val('customer').change();"; |
|
| 233 | - echo "\n});\n</script>"; |
|
| 234 | - } |
|
| 230 | + echo "<script type='text/javascript'>\n"; |
|
| 231 | + echo "jQuery(document).ready(function($) {"; |
|
| 232 | + echo "\n$('#role').val('customer').change();"; |
|
| 233 | + echo "\n});\n</script>"; |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | 237 | * Create an entity of customer type when a new user is created |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Manage Customer general and front-end functions |
| 4 | 6 | * @author ALLEGRE Jérôme - EOXIA |
@@ -363,8 +365,7 @@ discard block |
||
| 363 | 365 | 'attribute_id' => $attribute_def->id |
| 364 | 366 | ) |
| 365 | 367 | ); |
| 366 | - } |
|
| 367 | - else { |
|
| 368 | + } else { |
|
| 368 | 369 | $wpdb->insert( |
| 369 | 370 | WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower( $attribute_def->data_type ), |
| 370 | 371 | array( |
@@ -470,8 +471,10 @@ discard block |
||
| 470 | 471 | $last_login = get_user_meta( $current_user_id_in_list, 'last_login_time', true ); |
| 471 | 472 | if ( !empty( $last_login ) ) : |
| 472 | 473 | echo mysql2date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) , $last_login, true ); |
| 473 | - else: |
|
| 474 | + else { |
|
| 475 | + : |
|
| 474 | 476 | _e( 'Never logged in', 'wpshop' ); |
| 477 | + } |
|
| 475 | 478 | endif; |
| 476 | 479 | $use_template = false; |
| 477 | 480 | break; |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | /** |
| 3 | 3 | * Manage Customer general and front-end functions |
| 4 | 4 | * @author ALLEGRE Jérôme - EOXIA |
@@ -8,29 +8,29 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | function __construct() { |
| 10 | 10 | /** Create customer entity type on wordpress initilisation*/ |
| 11 | - add_action( 'init', array( $this, 'create_customer_entity' ) ); |
|
| 11 | + add_action('init', array($this, 'create_customer_entity')); |
|
| 12 | 12 | |
| 13 | 13 | /** Call style for administration */ |
| 14 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_css' ) ); |
|
| 14 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_css')); |
|
| 15 | 15 | |
| 16 | - add_action( 'admin_init', array( $this, 'customer_action_on_plugin_init' ) ); |
|
| 17 | - add_action( 'admin_init', array( $this, 'redirect_new_user' ) ); |
|
| 18 | - add_action( 'admin_menu', array( $this, 'customer_action_on_menu' ) ); |
|
| 16 | + add_action('admin_init', array($this, 'customer_action_on_plugin_init')); |
|
| 17 | + add_action('admin_init', array($this, 'redirect_new_user')); |
|
| 18 | + add_action('admin_menu', array($this, 'customer_action_on_menu')); |
|
| 19 | 19 | |
| 20 | 20 | /** When a wordpress user is created, create a customer (post type) */ |
| 21 | - add_action( 'user_register', array( $this, 'create_entity_customer_when_user_is_created') ); |
|
| 22 | - add_action( 'edit_user_profile_update', array( $this, 'update_entity_customer_when_profile_user_is_update' ) ); |
|
| 21 | + add_action('user_register', array($this, 'create_entity_customer_when_user_is_created')); |
|
| 22 | + add_action('edit_user_profile_update', array($this, 'update_entity_customer_when_profile_user_is_update')); |
|
| 23 | 23 | |
| 24 | 24 | /** When save customer update */ |
| 25 | - add_action( 'save_post', array( $this, 'save_entity_customer' ), 10, 2 ); |
|
| 25 | + add_action('save_post', array($this, 'save_entity_customer'), 10, 2); |
|
| 26 | 26 | //add_action( 'admin_notices', array( $this, 'notice_save_post_customer_informations' ) ); |
| 27 | 27 | |
| 28 | 28 | /** Add filters for customer list */ |
| 29 | - add_filter( 'bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, array( $this, 'customer_list_table_bulk_actions' ) ); |
|
| 30 | - add_filter( 'manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_columns', array( $this, 'list_table_header' ) ); |
|
| 31 | - add_action( 'manage_' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_posts_custom_column' , array( $this, 'list_table_column_content' ), 10, 2 ); |
|
| 32 | - add_action( 'restrict_manage_posts', array(&$this, 'list_table_filters') ); |
|
| 33 | - add_filter( 'parse_query', array(&$this, 'list_table_filter_parse_query') ); |
|
| 29 | + add_filter('bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, array($this, 'customer_list_table_bulk_actions')); |
|
| 30 | + add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_columns', array($this, 'list_table_header')); |
|
| 31 | + add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_posts_custom_column', array($this, 'list_table_column_content'), 10, 2); |
|
| 32 | + add_action('restrict_manage_posts', array(&$this, 'list_table_filters')); |
|
| 33 | + add_filter('parse_query', array(&$this, 'list_table_filter_parse_query')); |
|
| 34 | 34 | |
| 35 | 35 | /** Filter search for customers */ |
| 36 | 36 | //add_filter( 'pre_get_posts', array( $this, 'customer_search' ) ); |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | * Customer options for the shop |
| 44 | 44 | */ |
| 45 | 45 | public static function declare_options() { |
| 46 | - if ( WPSHOP_DEFINED_SHOP_TYPE == 'sale' ) { |
|
| 47 | - $wpshop_shop_type = !empty( $_POST['wpshop_shop_type'] ) ? sanitize_text_field( $_POST['wpshop_shop_type'] ) : ''; |
|
| 48 | - $old_wpshop_shop_type = !empty( $_POST['old_wpshop_shop_type'] ) ? sanitize_text_field( $_POST['old_wpshop_shop_type'] ) : ''; |
|
| 46 | + if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 47 | + $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : ''; |
|
| 48 | + $old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : ''; |
|
| 49 | 49 | |
| 50 | - if ( ( $wpshop_shop_type == '' || $wpshop_shop_type != 'presentation' ) |
|
| 51 | - && ( $old_wpshop_shop_type == '' && $old_wpshop_shop_type != 'presentation' ) ) { |
|
| 50 | + if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation') |
|
| 51 | + && ($old_wpshop_shop_type == '' && $old_wpshop_shop_type != 'presentation')) { |
|
| 52 | 52 | /** Add module option to wpshop general options */ |
| 53 | 53 | register_setting('wpshop_options', 'wpshop_cart_option', array('wps_customer_ctr', 'wpshop_options_validate_customers_newsleters')); |
| 54 | 54 | add_settings_field('display_newsletters_subscriptions', __('Display newsletters subscriptions', 'wpshop'), array('wps_customer_ctr', 'display_newsletters_subscriptions'), 'wpshop_cart_info', 'wpshop_cart_info'); |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param unknown_type $input |
| 63 | 63 | * @return unknown |
| 64 | 64 | */ |
| 65 | - public static function wpshop_options_validate_customers_newsleters( $input ) { |
|
| 65 | + public static function wpshop_options_validate_customers_newsleters($input) { |
|
| 66 | 66 | return $input; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | $input_def['valueToPut'] = 'index'; |
| 78 | 78 | $input_def['value'] = !empty($cart_option['display_newsletter']['site_subscription']) ? $cart_option['display_newsletter']['site_subscription'][0] : 'no'; |
| 79 | 79 | $input_def['possible_value'] = 'yes'; |
| 80 | - $output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][site_subscription]') . '<label for="' . $input_def['id'] . '">' . __( 'Newsletters of the site', 'wpshop' ) . '</label>' . '<a href="#" title="'.__('Check this box if you want display newsletter site subscription','wpshop').'" class="wpshop_infobulle_marker">?</a>' . '<br>'; |
|
| 80 | + $output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][site_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the site', 'wpshop') . '</label>' . '<a href="#" title="' . __('Check this box if you want display newsletter site subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . '<br>'; |
|
| 81 | 81 | |
| 82 | 82 | $input_def = array(); |
| 83 | 83 | $input_def['name'] = ''; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $input_def['valueToPut'] = 'index'; |
| 87 | 87 | $input_def['value'] = !empty($cart_option['display_newsletter']['partner_subscription']) ? $cart_option['display_newsletter']['partner_subscription'][0] : 'no'; |
| 88 | 88 | $input_def['possible_value'] = 'yes'; |
| 89 | - $output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][partner_subscription]') . '<label for="' . $input_def['id'] . '">' . __( 'Newsletters of the partners', 'wpshop' ) . '</label>' . '<a href="#" title="'.__('Check this box if you want display newsletter partners subscription','wpshop').'" class="wpshop_infobulle_marker">?</a>' . '<br>'; |
|
| 89 | + $output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][partner_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the partners', 'wpshop') . '</label>' . '<a href="#" title="' . __('Check this box if you want display newsletter partners subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . '<br>'; |
|
| 90 | 90 | |
| 91 | 91 | echo $output; |
| 92 | 92 | } |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | * Include stylesheets |
| 96 | 96 | */ |
| 97 | 97 | function admin_css() { |
| 98 | - wp_register_style( 'wpshop-modules-customer-backend-styles', WPS_ACCOUNT_URL . '/' . WPS_ACCOUNT_DIR . '/assets/backend/css/backend.css', '', WPSHOP_VERSION ); |
|
| 99 | - wp_enqueue_style( 'wpshop-modules-customer-backend-styles' ); |
|
| 98 | + wp_register_style('wpshop-modules-customer-backend-styles', WPS_ACCOUNT_URL . '/' . WPS_ACCOUNT_DIR . '/assets/backend/css/backend.css', '', WPSHOP_VERSION); |
|
| 99 | + wp_enqueue_style('wpshop-modules-customer-backend-styles'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -114,18 +114,18 @@ discard block |
||
| 114 | 114 | $wps_customer_mdl = new wps_customer_mdl(); |
| 115 | 115 | $users = $wps_customer_mdl->getUserList(); |
| 116 | 116 | $select_users = ''; |
| 117 | - if( !empty($users) ) { |
|
| 118 | - foreach($users as $user) { |
|
| 117 | + if (!empty($users)) { |
|
| 118 | + foreach ($users as $user) { |
|
| 119 | 119 | if ($user->ID != 1) { |
| 120 | - $lastname = get_user_meta( $user->ID, 'last_name', true ); |
|
| 121 | - $firstname = get_user_meta( $user->ID, 'first_name', true ); |
|
| 122 | - $select_users .= '<option value="'.$user->ID.'"' . ( ( !$multiple ) && ( $selected_user == $user->ID ) ? ' selected="selected"' : '') . ' >'.$lastname. ' ' .$firstname.' ('.$user->user_email.')</option>'; |
|
| 120 | + $lastname = get_user_meta($user->ID, 'last_name', true); |
|
| 121 | + $firstname = get_user_meta($user->ID, 'first_name', true); |
|
| 122 | + $select_users .= '<option value="' . $user->ID . '"' . ((!$multiple) && ($selected_user == $user->ID) ? ' selected="selected"' : '') . ' >' . $lastname . ' ' . $firstname . ' (' . $user->user_email . ')</option>'; |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | $content_output = ' |
| 126 | - <select name="' . $customer_list_params['name'] . '" id="' . $customer_list_params['id'] . '" data-placeholder="' . __('Choose a customer', 'wpshop') . '" class="chosen_select"' . ( $multiple ? ' multiple="multiple" ' : '') . '' . ( $disabled ? ' disabled="disabled" ' : '') . '> |
|
| 126 | + <select name="' . $customer_list_params['name'] . '" id="' . $customer_list_params['id'] . '" data-placeholder="' . __('Choose a customer', 'wpshop') . '" class="chosen_select"' . ($multiple ? ' multiple="multiple" ' : '') . '' . ($disabled ? ' disabled="disabled" ' : '') . '> |
|
| 127 | 127 | <option value="0" ></option> |
| 128 | - '.$select_users.' |
|
| 128 | + '.$select_users . ' |
|
| 129 | 129 | </select>'; |
| 130 | 130 | } |
| 131 | 131 | return $content_output; |
@@ -143,26 +143,26 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | function create_customer_entity() { |
| 145 | 145 | global $wpdb; |
| 146 | - $query = $wpdb->prepare( "SELECT P.post_title, PM.meta_value FROM {$wpdb->posts} AS P INNER JOIN {$wpdb->postmeta} AS PM ON (PM.post_id = P.ID) WHERE P.post_name = %s AND PM.meta_key = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, '_wpshop_entity_params' ); |
|
| 147 | - $customer_entity_definition = $wpdb->get_row( $query ); |
|
| 148 | - $current_entity_params = !empty( $customer_entity_definition ) && !empty( $customer_entity_definition->meta_value ) ? unserialize( $customer_entity_definition->meta_value ) : null; |
|
| 146 | + $query = $wpdb->prepare("SELECT P.post_title, PM.meta_value FROM {$wpdb->posts} AS P INNER JOIN {$wpdb->postmeta} AS PM ON (PM.post_id = P.ID) WHERE P.post_name = %s AND PM.meta_key = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, '_wpshop_entity_params'); |
|
| 147 | + $customer_entity_definition = $wpdb->get_row($query); |
|
| 148 | + $current_entity_params = !empty($customer_entity_definition) && !empty($customer_entity_definition->meta_value) ? unserialize($customer_entity_definition->meta_value) : null; |
|
| 149 | 149 | |
| 150 | 150 | $post_type_params = array( |
| 151 | 151 | 'labels' => array( |
| 152 | - 'name' => __( 'Customers' , 'wpshop' ), |
|
| 153 | - 'singular_name' => __( 'Customer', 'wpshop' ), |
|
| 154 | - 'add_new_item' => __( 'New customer', 'wpshop' ), |
|
| 155 | - 'add_new' => __( 'New customer', 'wpshop' ), |
|
| 156 | - 'edit_item' => __( 'Edit customer', 'wpshop' ), |
|
| 157 | - 'new_item' => __( 'New customer', 'wpshop' ), |
|
| 158 | - 'view_item' => __( 'View customer', 'wpshop' ), |
|
| 159 | - 'search_items' => __( 'Search in customers', 'wpshop' ), |
|
| 160 | - 'not_found' => __( 'No customer found', 'wpshop' ), |
|
| 161 | - 'not_found_in_trash' => __( 'No customer founded in trash', 'wpshop' ), |
|
| 152 | + 'name' => __('Customers', 'wpshop'), |
|
| 153 | + 'singular_name' => __('Customer', 'wpshop'), |
|
| 154 | + 'add_new_item' => __('New customer', 'wpshop'), |
|
| 155 | + 'add_new' => __('New customer', 'wpshop'), |
|
| 156 | + 'edit_item' => __('Edit customer', 'wpshop'), |
|
| 157 | + 'new_item' => __('New customer', 'wpshop'), |
|
| 158 | + 'view_item' => __('View customer', 'wpshop'), |
|
| 159 | + 'search_items' => __('Search in customers', 'wpshop'), |
|
| 160 | + 'not_found' => __('No customer found', 'wpshop'), |
|
| 161 | + 'not_found_in_trash' => __('No customer founded in trash', 'wpshop'), |
|
| 162 | 162 | 'parent_item_colon' => '', |
| 163 | 163 | ), |
| 164 | 164 | 'description' => '', |
| 165 | - 'supports' => !empty($current_entity_params['support']) ? $current_entity_params['support'] : array( 'title' ), |
|
| 165 | + 'supports' => !empty($current_entity_params['support']) ? $current_entity_params['support'] : array('title'), |
|
| 166 | 166 | 'hierarchical' => false, |
| 167 | 167 | 'public' => false, |
| 168 | 168 | 'show_ui' => true, |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | 'delete_posts' => 'delete_product' |
| 187 | 187 | ) |
| 188 | 188 | ); |
| 189 | - register_post_type( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_type_params ); |
|
| 189 | + register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_type_params); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
@@ -200,30 +200,30 @@ discard block |
||
| 200 | 200 | /** |
| 201 | 201 | * Redirect when create new customer in admin |
| 202 | 202 | */ |
| 203 | - public function redirect_new_user(){ |
|
| 203 | + public function redirect_new_user() { |
|
| 204 | 204 | global $pagenow; |
| 205 | 205 | |
| 206 | 206 | /* Check current admin page. */ |
| 207 | - if( $pagenow != 'user-new.php' && isset( $_SESSION['redirect_to_customer'] ) ) { |
|
| 207 | + if ($pagenow != 'user-new.php' && isset($_SESSION['redirect_to_customer'])) { |
|
| 208 | 208 | $redirect = $_SESSION['redirect_to_customer']; |
| 209 | - unset( $_SESSION['redirect_to_customer'] ); |
|
| 210 | - if( $pagenow == 'users.php' ) { |
|
| 211 | - wp_redirect( admin_url( $redirect, 'http' ) ); |
|
| 209 | + unset($_SESSION['redirect_to_customer']); |
|
| 210 | + if ($pagenow == 'users.php') { |
|
| 211 | + wp_redirect(admin_url($redirect, 'http')); |
|
| 212 | 212 | exit; |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /* Redirect to new user */ |
| 217 | - $post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : ''; |
|
| 218 | - if( $pagenow == 'post-new.php' && isset( $post_type ) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) { |
|
| 217 | + $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
| 218 | + if ($pagenow == 'post-new.php' && isset($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) { |
|
| 219 | 219 | $_SESSION['redirect_to_customer'] = 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS; |
| 220 | - wp_redirect( admin_url('user-new.php', 'http' ), 301 ); |
|
| 220 | + wp_redirect(admin_url('user-new.php', 'http'), 301); |
|
| 221 | 221 | exit; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /* Include JS on new user customer */ |
| 225 | - if( $pagenow == 'user-new.php' && isset( $_SESSION['redirect_to_customer'] ) ) { |
|
| 226 | - add_action( 'admin_print_scripts', array( $this, 'admin_user_customer_js' ), 20 ); |
|
| 225 | + if ($pagenow == 'user-new.php' && isset($_SESSION['redirect_to_customer'])) { |
|
| 226 | + add_action('admin_print_scripts', array($this, 'admin_user_customer_js'), 20); |
|
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | /* JS to select customer in place of suscriber */ |
@@ -239,23 +239,23 @@ discard block |
||
| 239 | 239 | * |
| 240 | 240 | * @param integer $user_id |
| 241 | 241 | */ |
| 242 | - public static function create_entity_customer_when_user_is_created( $user_id ) { |
|
| 243 | - $user_data = get_userdata( $user_id ); |
|
| 244 | - $user_info = array_merge( get_object_vars( $user_data->data ), array_map( 'self::array_map_create_entity_customer_when_user_is_created', get_user_meta( $user_id ) ) ); |
|
| 245 | - $customer_post_ID = wp_insert_post( array( 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'post_author' => $user_id, 'post_title' => $user_data->user_nicename ) ); |
|
| 246 | - self::save_customer_synchronize( $customer_post_ID, $user_id, $user_info ); |
|
| 242 | + public static function create_entity_customer_when_user_is_created($user_id) { |
|
| 243 | + $user_data = get_userdata($user_id); |
|
| 244 | + $user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id))); |
|
| 245 | + $customer_post_ID = wp_insert_post(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'post_author' => $user_id, 'post_title' => $user_data->user_nicename)); |
|
| 246 | + self::save_customer_synchronize($customer_post_ID, $user_id, $user_info); |
|
| 247 | 247 | |
| 248 | 248 | /** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/ |
| 249 | - $usermeta = get_post_meta( $user_id, 'metaboxhidden_nav-menus', true); |
|
| 250 | - if ( !empty($usermeta) && is_array($usermeta) ) { |
|
| 249 | + $usermeta = get_post_meta($user_id, 'metaboxhidden_nav-menus', true); |
|
| 250 | + if (!empty($usermeta) && is_array($usermeta)) { |
|
| 251 | 251 | $data_to_delete = array_search('add-wpshop_product_category', $usermeta); |
| 252 | - if ( $data_to_delete !== false ) { |
|
| 253 | - unset( $usermeta[$data_to_delete] ); |
|
| 252 | + if ($data_to_delete !== false) { |
|
| 253 | + unset($usermeta[$data_to_delete]); |
|
| 254 | 254 | update_user_meta($user_id, 'metaboxhidden_nav-menus', $usermeta); |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | - private static function array_map_create_entity_customer_when_user_is_created( $a ) { |
|
| 258 | + private static function array_map_create_entity_customer_when_user_is_created($a) { |
|
| 259 | 259 | return $a[0]; |
| 260 | 260 | } |
| 261 | 261 | |
@@ -264,13 +264,13 @@ discard block |
||
| 264 | 264 | * |
| 265 | 265 | * @param integer $user_id |
| 266 | 266 | */ |
| 267 | - public static function update_entity_customer_when_profile_user_is_update( $user_id ) { |
|
| 268 | - $user_data = get_userdata( $user_id ); |
|
| 269 | - $user_info = array_merge( get_object_vars( $user_data->data ), array_map( 'self::array_map_create_entity_customer_when_user_is_created', get_user_meta( $user_id ) ) ); |
|
| 270 | - $customer_post_ID = self::get_customer_id_by_author_id( $user_id ); |
|
| 271 | - self::save_customer_synchronize( $customer_post_ID, $user_id, $user_info ); |
|
| 267 | + public static function update_entity_customer_when_profile_user_is_update($user_id) { |
|
| 268 | + $user_data = get_userdata($user_id); |
|
| 269 | + $user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id))); |
|
| 270 | + $customer_post_ID = self::get_customer_id_by_author_id($user_id); |
|
| 271 | + self::save_customer_synchronize($customer_post_ID, $user_id, $user_info); |
|
| 272 | 272 | } |
| 273 | - private static function array_map_update_entity_customer_when_profile_user_is_update( $a ) { |
|
| 273 | + private static function array_map_update_entity_customer_when_profile_user_is_update($a) { |
|
| 274 | 274 | return $a[0]; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -280,53 +280,53 @@ discard block |
||
| 280 | 280 | * @param integer $post_id |
| 281 | 281 | * @param WP_Post $post |
| 282 | 282 | */ |
| 283 | - public static function save_entity_customer( $customer_post_ID, $post ) { |
|
| 284 | - if( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS != $post->post_type || $post->post_status == 'auto-draft' || wp_is_post_revision( $customer_post_ID ) ) { |
|
| 283 | + public static function save_entity_customer($customer_post_ID, $post) { |
|
| 284 | + if (WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS != $post->post_type || $post->post_status == 'auto-draft' || wp_is_post_revision($customer_post_ID)) { |
|
| 285 | 285 | return; |
| 286 | 286 | } |
| 287 | 287 | $user_id = $post->post_author; |
| 288 | 288 | $user_info = array(); |
| 289 | - $attribute = !empty( $_POST['attribute'] ) ? (array)$_POST['attribute'] : array(); |
|
| 290 | - if( !empty( $attribute ) ) { |
|
| 291 | - foreach( $attribute as $type => $attributes ) { |
|
| 292 | - foreach( $attributes as $meta => $attribute ) { |
|
| 293 | - $user_info[$meta] = sanitize_text_field( $attribute ); |
|
| 289 | + $attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : array(); |
|
| 290 | + if (!empty($attribute)) { |
|
| 291 | + foreach ($attribute as $type => $attributes) { |
|
| 292 | + foreach ($attributes as $meta => $attribute) { |
|
| 293 | + $user_info[$meta] = sanitize_text_field($attribute); |
|
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | - self::save_customer_synchronize( $customer_post_ID, $user_id, $user_info ); |
|
| 297 | + self::save_customer_synchronize($customer_post_ID, $user_id, $user_info); |
|
| 298 | 298 | /** Update newsletter user preferences **/ |
| 299 | 299 | $newsletter_preferences = array(); |
| 300 | - $newsletter_site = !empty( $_POST['newsletters_site'] ) ? sanitize_text_field( $_POST['newsletters_site'] ) : ''; |
|
| 301 | - if( !empty($newsletter_site) ) { |
|
| 300 | + $newsletter_site = !empty($_POST['newsletters_site']) ? sanitize_text_field($_POST['newsletters_site']) : ''; |
|
| 301 | + if (!empty($newsletter_site)) { |
|
| 302 | 302 | $newsletter_preferences['newsletters_site'] = 1; |
| 303 | 303 | } |
| 304 | - $newsletters_site_partners = !empty( $_POST['newsletters_site_partners'] ) ? sanitize_text_field( $_POST['newsletters_site_partners'] ) : ''; |
|
| 305 | - if( !empty($newsletters_site_partners) ) { |
|
| 304 | + $newsletters_site_partners = !empty($_POST['newsletters_site_partners']) ? sanitize_text_field($_POST['newsletters_site_partners']) : ''; |
|
| 305 | + if (!empty($newsletters_site_partners)) { |
|
| 306 | 306 | $newsletter_preferences['newsletters_site_partners'] = 1; |
| 307 | 307 | } |
| 308 | - update_user_meta( $user_id, 'user_preferences', $newsletter_preferences); |
|
| 308 | + update_user_meta($user_id, 'user_preferences', $newsletter_preferences); |
|
| 309 | 309 | return; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - public static function save_customer_synchronize( $customer_post_ID, $user_id, $user_info ) { |
|
| 312 | + public static function save_customer_synchronize($customer_post_ID, $user_id, $user_info) { |
|
| 313 | 313 | global $wpdb; |
| 314 | 314 | global $wpshop; |
| 315 | - $exclude_user_meta = array( 'user_login', 'user_nicename', 'user_email', 'user_pass', 'user_url', 'user_registered', 'user_activation_key', 'user_status', 'display_name' ); |
|
| 315 | + $exclude_user_meta = array('user_login', 'user_nicename', 'user_email', 'user_pass', 'user_url', 'user_registered', 'user_activation_key', 'user_status', 'display_name'); |
|
| 316 | 316 | $wps_entities = new wpshop_entities(); |
| 317 | - $element_id = $wps_entities->get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 318 | - $query = $wpdb->prepare( 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id ); |
|
| 319 | - $attribute_set_id = $wpdb->get_var( $query ); |
|
| 317 | + $element_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 318 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id); |
|
| 319 | + $attribute_set_id = $wpdb->get_var($query); |
|
| 320 | 320 | $attributes_default = array(); |
| 321 | - if ( !empty( $attribute_set_id ) ) { |
|
| 322 | - $group = wps_address::get_addresss_form_fields_by_type( $attribute_set_id ); |
|
| 323 | - foreach ( $group as $attribute_sets ) { |
|
| 324 | - foreach ( $attribute_sets as $attribute_set_field ) { |
|
| 325 | - foreach( $attribute_set_field['content'] as $attribute ) { |
|
| 326 | - if( isset( $attribute['value'] ) ) { |
|
| 327 | - if( is_serialized( $attribute['value'] ) ) { |
|
| 328 | - $unserialized_value = unserialize( $attribute['value'] ); |
|
| 329 | - if( isset( $unserialized_value['default_value'] ) ) { |
|
| 321 | + if (!empty($attribute_set_id)) { |
|
| 322 | + $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id); |
|
| 323 | + foreach ($group as $attribute_sets) { |
|
| 324 | + foreach ($attribute_sets as $attribute_set_field) { |
|
| 325 | + foreach ($attribute_set_field['content'] as $attribute) { |
|
| 326 | + if (isset($attribute['value'])) { |
|
| 327 | + if (is_serialized($attribute['value'])) { |
|
| 328 | + $unserialized_value = unserialize($attribute['value']); |
|
| 329 | + if (isset($unserialized_value['default_value'])) { |
|
| 330 | 330 | $attributes_default[$attribute['name']] = $unserialized_value['default_value']; |
| 331 | 331 | } |
| 332 | 332 | } else { |
@@ -337,30 +337,30 @@ discard block |
||
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | 339 | } |
| 340 | - $user_info = array_merge( $attributes_default, $user_info ); |
|
| 341 | - foreach( $user_info as $user_meta => $user_meta_value ) { |
|
| 342 | - $attribute_def = wpshop_attributes::getElement( $user_meta, "'valid'", 'code' ); |
|
| 343 | - if( !empty( $attribute_def ) ){ |
|
| 340 | + $user_info = array_merge($attributes_default, $user_info); |
|
| 341 | + foreach ($user_info as $user_meta => $user_meta_value) { |
|
| 342 | + $attribute_def = wpshop_attributes::getElement($user_meta, "'valid'", 'code'); |
|
| 343 | + if (!empty($attribute_def)) { |
|
| 344 | 344 | //Save data in user meta |
| 345 | - if( in_array( $user_meta, $exclude_user_meta ) ) { |
|
| 346 | - if( $user_meta == 'user_pass' ) { |
|
| 347 | - $new_password = wpshop_tools::varSanitizer( $user_meta_value ); |
|
| 348 | - if( wp_hash_password( $new_password ) == get_user_meta( $user_id, $user_meta, true ) ) { |
|
| 345 | + if (in_array($user_meta, $exclude_user_meta)) { |
|
| 346 | + if ($user_meta == 'user_pass') { |
|
| 347 | + $new_password = wpshop_tools::varSanitizer($user_meta_value); |
|
| 348 | + if (wp_hash_password($new_password) == get_user_meta($user_id, $user_meta, true)) { |
|
| 349 | 349 | continue; |
| 350 | 350 | } |
| 351 | 351 | } |
| 352 | - wp_update_user( array('ID' => $user_id, $user_meta => wpshop_tools::varSanitizer( $user_meta_value ) ) ); |
|
| 352 | + wp_update_user(array('ID' => $user_id, $user_meta => wpshop_tools::varSanitizer($user_meta_value))); |
|
| 353 | 353 | } else { |
| 354 | - update_user_meta( $user_id, $user_meta, wpshop_tools::varSanitizer( $user_meta_value ) ); |
|
| 354 | + update_user_meta($user_id, $user_meta, wpshop_tools::varSanitizer($user_meta_value)); |
|
| 355 | 355 | } |
| 356 | 356 | //Save data in attribute tables, ckeck first if exist to know if Insert or Update |
| 357 | - $query = $wpdb->prepare( 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower( $attribute_def->data_type ) . ' WHERE entity_type_id = %d AND entity_id = %d AND attribute_id = %d', $element_id, $customer_post_ID, $attribute_def->id ); |
|
| 358 | - $checking_attribute_exist = $wpdb->get_results( $query ); |
|
| 359 | - if( !empty( $checking_attribute_exist ) ) { |
|
| 357 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type) . ' WHERE entity_type_id = %d AND entity_id = %d AND attribute_id = %d', $element_id, $customer_post_ID, $attribute_def->id); |
|
| 358 | + $checking_attribute_exist = $wpdb->get_results($query); |
|
| 359 | + if (!empty($checking_attribute_exist)) { |
|
| 360 | 360 | $wpdb->update( |
| 361 | - WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower( $attribute_def->data_type ), |
|
| 361 | + WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type), |
|
| 362 | 362 | array( |
| 363 | - 'value' => wpshop_tools::varSanitizer( $user_meta_value ) ), |
|
| 363 | + 'value' => wpshop_tools::varSanitizer($user_meta_value) ), |
|
| 364 | 364 | array( |
| 365 | 365 | 'entity_type_id' => $element_id, |
| 366 | 366 | 'entity_id' => $customer_post_ID, |
@@ -370,15 +370,15 @@ discard block |
||
| 370 | 370 | } |
| 371 | 371 | else { |
| 372 | 372 | $wpdb->insert( |
| 373 | - WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower( $attribute_def->data_type ), |
|
| 373 | + WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type), |
|
| 374 | 374 | array( |
| 375 | 375 | 'entity_type_id' => $element_id, |
| 376 | 376 | 'attribute_id' => $attribute_def->id, |
| 377 | 377 | 'entity_id' => $customer_post_ID, |
| 378 | 378 | 'user_id' => $user_id, |
| 379 | - 'creation_date_value' => current_time( 'mysql', 0 ), |
|
| 379 | + 'creation_date_value' => current_time('mysql', 0), |
|
| 380 | 380 | 'language' => 'fr_FR', |
| 381 | - 'value' => wpshop_tools::varSanitizer( $user_meta_value ) |
|
| 381 | + 'value' => wpshop_tools::varSanitizer($user_meta_value) |
|
| 382 | 382 | ) |
| 383 | 383 | ); |
| 384 | 384 | } |
@@ -390,14 +390,14 @@ discard block |
||
| 390 | 390 | * Notice for errors on admin |
| 391 | 391 | */ |
| 392 | 392 | function notice_save_post_customer_informations() { |
| 393 | - $errors = isset( $_SESSION['save_post_customer_informations_errors'] ) ? $_SESSION['save_post_customer_informations_errors'] : ''; |
|
| 394 | - if( !empty( $errors ) ) { |
|
| 395 | - foreach( $errors as $error ) { |
|
| 393 | + $errors = isset($_SESSION['save_post_customer_informations_errors']) ? $_SESSION['save_post_customer_informations_errors'] : ''; |
|
| 394 | + if (!empty($errors)) { |
|
| 395 | + foreach ($errors as $error) { |
|
| 396 | 396 | $class = "error"; |
| 397 | 397 | $message = $error; |
| 398 | 398 | echo"<div class=\"$class\"> <p>$message</p></div>"; |
| 399 | 399 | } |
| 400 | - unset( $_SESSION['save_post_customer_informations_errors'] ); |
|
| 400 | + unset($_SESSION['save_post_customer_informations_errors']); |
|
| 401 | 401 | } |
| 402 | 402 | } |
| 403 | 403 | |
@@ -408,16 +408,16 @@ discard block |
||
| 408 | 408 | * |
| 409 | 409 | * @return array The new header to display |
| 410 | 410 | */ |
| 411 | - function list_table_header( $current_header ) { |
|
| 412 | - unset( $current_header['title'] ); |
|
| 413 | - unset( $current_header['date'] ); |
|
| 411 | + function list_table_header($current_header) { |
|
| 412 | + unset($current_header['title']); |
|
| 413 | + unset($current_header['date']); |
|
| 414 | 414 | |
| 415 | - $current_header['customer_identifier'] = __( 'Customer ID', 'wpshop' ); |
|
| 416 | - $current_header['customer_name'] = '<span class="wps-customer-last_name" >' . __( 'Last-name', 'wpshop' ) . '</span><span class="wps-customer-first_name" >' . __( 'First-name', 'wpshop' ) . '</span>'; |
|
| 417 | - $current_header['customer_email'] = __( 'E-mail', 'wpshop' ); |
|
| 418 | - $current_header['customer_orders'] = __( 'Customer\'s orders', 'wpshop' ); |
|
| 419 | - $current_header['customer_date_subscription'] = __( 'Subscription', 'wpshop' ); |
|
| 420 | - $current_header['customer_date_lastlogin'] = __( 'Last login date', 'wpshop' ); |
|
| 415 | + $current_header['customer_identifier'] = __('Customer ID', 'wpshop'); |
|
| 416 | + $current_header['customer_name'] = '<span class="wps-customer-last_name" >' . __('Last-name', 'wpshop') . '</span><span class="wps-customer-first_name" >' . __('First-name', 'wpshop') . '</span>'; |
|
| 417 | + $current_header['customer_email'] = __('E-mail', 'wpshop'); |
|
| 418 | + $current_header['customer_orders'] = __('Customer\'s orders', 'wpshop'); |
|
| 419 | + $current_header['customer_date_subscription'] = __('Subscription', 'wpshop'); |
|
| 420 | + $current_header['customer_date_lastlogin'] = __('Last login date', 'wpshop'); |
|
| 421 | 421 | |
| 422 | 422 | return $current_header; |
| 423 | 423 | } |
@@ -428,45 +428,45 @@ discard block |
||
| 428 | 428 | * @param string $column THe column identifier to modify output for |
| 429 | 429 | * @param integer $post_id The current post identifier |
| 430 | 430 | */ |
| 431 | - function list_table_column_content( $column, $post_id ) { |
|
| 431 | + function list_table_column_content($column, $post_id) { |
|
| 432 | 432 | global $wpdb; |
| 433 | 433 | /** Get wp_users idenfifier from customer id */ |
| 434 | - $query = $wpdb->prepare( "SELECT post_author FROM {$wpdb->posts} WHERE ID = %d", $post_id); |
|
| 435 | - $current_user_id_in_list = $wpdb->get_var( $query ); |
|
| 434 | + $query = $wpdb->prepare("SELECT post_author FROM {$wpdb->posts} WHERE ID = %d", $post_id); |
|
| 435 | + $current_user_id_in_list = $wpdb->get_var($query); |
|
| 436 | 436 | |
| 437 | 437 | /** Get current post informations */ |
| 438 | - $customer_post = get_post( $post_id ); |
|
| 438 | + $customer_post = get_post($post_id); |
|
| 439 | 439 | |
| 440 | 440 | /** Get user data */ |
| 441 | - $current_user_datas = get_userdata( $current_user_id_in_list ); |
|
| 441 | + $current_user_datas = get_userdata($current_user_id_in_list); |
|
| 442 | 442 | |
| 443 | 443 | /** Switch current column for custom case */ |
| 444 | 444 | $use_template = true; |
| 445 | - switch ( $column ) { |
|
| 445 | + switch ($column) { |
|
| 446 | 446 | case 'customer_identifier': |
| 447 | 447 | echo $post_id; |
| 448 | 448 | $use_template = false; |
| 449 | 449 | break; |
| 450 | 450 | case 'customer_date_subscription': |
| 451 | - echo mysql2date( get_option( 'date_format' ), $current_user_datas->user_registered, true ); |
|
| 451 | + echo mysql2date(get_option('date_format'), $current_user_datas->user_registered, true); |
|
| 452 | 452 | $use_template = false; |
| 453 | 453 | break; |
| 454 | 454 | case 'customer_date_lastlogin': |
| 455 | - $last_login = get_user_meta( $current_user_id_in_list, 'last_login_time', true ); |
|
| 456 | - if ( !empty( $last_login ) ) : |
|
| 457 | - echo mysql2date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) , $last_login, true ); |
|
| 455 | + $last_login = get_user_meta($current_user_id_in_list, 'last_login_time', true); |
|
| 456 | + if (!empty($last_login)) : |
|
| 457 | + echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $last_login, true); |
|
| 458 | 458 | else: |
| 459 | - _e( 'Never logged in', 'wpshop' ); |
|
| 459 | + _e('Never logged in', 'wpshop'); |
|
| 460 | 460 | endif; |
| 461 | 461 | $use_template = false; |
| 462 | 462 | break; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | /** Require the template for displaying the current column */ |
| 466 | - if ( $use_template ) { |
|
| 467 | - $template = wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . '/templates/', 'backend', 'customer_listtable/' . $column ); |
|
| 468 | - if ( is_file( $template ) ) { |
|
| 469 | - require( $template ); |
|
| 466 | + if ($use_template) { |
|
| 467 | + $template = wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . '/templates/', 'backend', 'customer_listtable/' . $column); |
|
| 468 | + if (is_file($template)) { |
|
| 469 | + require($template); |
|
| 470 | 470 | } |
| 471 | 471 | } |
| 472 | 472 | } |
@@ -478,33 +478,33 @@ discard block |
||
| 478 | 478 | * |
| 479 | 479 | * @return array The new action list to use into customer list table |
| 480 | 480 | */ |
| 481 | - function customer_list_table_bulk_actions( $actions ){ |
|
| 482 | - unset( $actions[ 'edit' ] ); |
|
| 483 | - unset( $actions[ 'trash' ] ); |
|
| 481 | + function customer_list_table_bulk_actions($actions) { |
|
| 482 | + unset($actions['edit']); |
|
| 483 | + unset($actions['trash']); |
|
| 484 | 484 | |
| 485 | 485 | return $actions; |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | function list_table_filters() { |
| 489 | - $post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : ''; |
|
| 489 | + $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
| 490 | 490 | if (isset($post_type)) { |
| 491 | 491 | if (post_type_exists($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)) { |
| 492 | 492 | $filter_possibilities = array(); |
| 493 | 493 | $filter_possibilities[''] = __('-- Select Filter --', 'wpshop'); |
| 494 | 494 | $filter_possibilities['orders'] = __('List customers with orders', 'wpshop'); |
| 495 | 495 | $filter_possibilities['no_orders'] = __('List customers without orders', 'wpshop'); |
| 496 | - echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, (!empty($_GET['entity_filter']) ? sanitize_text_field( $_GET['entity_filter'] ) : ''), '', 'index'); |
|
| 496 | + echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, (!empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''), '', 'index'); |
|
| 497 | 497 | } |
| 498 | 498 | } |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | function list_table_filter_parse_query($query) { |
| 502 | 502 | global $pagenow, $wpdb; |
| 503 | - $post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : ''; |
|
| 504 | - $entity_filter = !empty( $_GET['entity_filter'] ) ? sanitize_text_field( $_GET['entity_filter'] ) : ''; |
|
| 505 | - if ( is_admin() && ($pagenow == 'edit.php') && !empty( $post_type ) && ( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) && !empty( $entity_filter ) ) { |
|
| 503 | + $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
| 504 | + $entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''; |
|
| 505 | + if (is_admin() && ($pagenow == 'edit.php') && !empty($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) && !empty($entity_filter)) { |
|
| 506 | 506 | $check = null; |
| 507 | - switch ( $entity_filter ) { |
|
| 507 | + switch ($entity_filter) { |
|
| 508 | 508 | case 'orders': |
| 509 | 509 | $sql_query = $wpdb->prepare( |
| 510 | 510 | "SELECT ID |
@@ -541,13 +541,13 @@ discard block |
||
| 541 | 541 | break; |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | - if ( !empty( $check ) ) { |
|
| 544 | + if (!empty($check)) { |
|
| 545 | 545 | $results = $wpdb->get_results($sql_query); |
| 546 | 546 | $user_id_list = array(); |
| 547 | - foreach($results as $item){ |
|
| 547 | + foreach ($results as $item) { |
|
| 548 | 548 | $user_id_list[] = $item->ID; |
| 549 | 549 | } |
| 550 | - if( empty($post_id_list) ) { |
|
| 550 | + if (empty($post_id_list)) { |
|
| 551 | 551 | $post_id_list[] = 'no_result'; |
| 552 | 552 | } |
| 553 | 553 | $query->query_vars[$check] = $user_id_list; |
@@ -562,11 +562,11 @@ discard block |
||
| 562 | 562 | * |
| 563 | 563 | * @return array |
| 564 | 564 | */ |
| 565 | - public static function get_all_customer( $post_status = 'publish' ) { |
|
| 565 | + public static function get_all_customer($post_status = 'publish') { |
|
| 566 | 566 | global $wpdb; |
| 567 | 567 | |
| 568 | - $query = $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_status ); |
|
| 569 | - $list_customer = $wpdb->get_results( $query ); |
|
| 568 | + $query = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_status); |
|
| 569 | + $list_customer = $wpdb->get_results($query); |
|
| 570 | 570 | |
| 571 | 571 | return $list_customer; |
| 572 | 572 | } |
@@ -577,11 +577,11 @@ discard block |
||
| 577 | 577 | * @param int $author_id |
| 578 | 578 | * @return int $customer_id |
| 579 | 579 | */ |
| 580 | - public static function get_customer_id_by_author_id( $author_id ) { |
|
| 580 | + public static function get_customer_id_by_author_id($author_id) { |
|
| 581 | 581 | global $wpdb; |
| 582 | 582 | |
| 583 | - $query = $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type = %s", $author_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 584 | - $customer_id = $wpdb->get_var( $query ); |
|
| 583 | + $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type = %s", $author_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 584 | + $customer_id = $wpdb->get_var($query); |
|
| 585 | 585 | |
| 586 | 586 | return $customer_id; |
| 587 | 587 | } |
@@ -592,30 +592,30 @@ discard block |
||
| 592 | 592 | * @param array $form Passer directement le $_POST pour créer un client. |
| 593 | 593 | * @return array ou int : 1 = Aucun mail, 2 = L'utilisateur existe déjà |
| 594 | 594 | */ |
| 595 | - public static function quick_add_customer( $form ) { |
|
| 595 | + public static function quick_add_customer($form) { |
|
| 596 | 596 | $return = 1; |
| 597 | - if ( !empty( $form ) ) { |
|
| 597 | + if (!empty($form)) { |
|
| 598 | 598 | global $wpdb; |
| 599 | - $customer_type_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 600 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_SET.' WHERE entity_id = %d', $customer_type_id); |
|
| 601 | - $customer_entity_id = $wpdb->get_var( $query ); |
|
| 599 | + $customer_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 600 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $customer_type_id); |
|
| 601 | + $customer_entity_id = $wpdb->get_var($query); |
|
| 602 | 602 | $attributes_set = wpshop_attributes_set::getElement($customer_entity_id); |
| 603 | - $account_attributes = wpshop_attributes_set::getAttributeSetDetails( ( !empty($attributes_set->id) ) ? $attributes_set->id : '', "'valid'"); |
|
| 603 | + $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'"); |
|
| 604 | 604 | |
| 605 | 605 | $customer_attributes_to_save = $customer_attributes_to_save_temp = array(); |
| 606 | 606 | |
| 607 | - foreach ( $form[ 'attribute' ] as $attribute_type => $attributes ) { |
|
| 608 | - foreach ( $attributes as $attribute_code => $attribute_value ) { |
|
| 607 | + foreach ($form['attribute'] as $attribute_type => $attributes) { |
|
| 608 | + foreach ($attributes as $attribute_code => $attribute_value) { |
|
| 609 | 609 | $customer_attributes_compare[$attribute_code] = $attribute_type; |
| 610 | 610 | } |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - foreach( $account_attributes as $account_attribute_group ) { |
|
| 614 | - foreach ( $account_attribute_group[ 'attribut' ] as $attribute ) { |
|
| 615 | - foreach( preg_grep ( '/' . $attribute->code . '/' , array_keys( $customer_attributes_compare ) ) as $codeForm ) { |
|
| 616 | - if( $customer_attributes_compare[$codeForm] == $attribute->data_type ) { |
|
| 617 | - $user[ $attribute->code ] = array( 'attribute_id' => $attribute->id, 'data_type' => $attribute->data_type, 'value' => sanitize_text_field( $_POST[ 'attribute' ][ $attribute->data_type ][ $codeForm ] ) ); |
|
| 618 | - if( $attribute->code == 'user_email' ) { |
|
| 613 | + foreach ($account_attributes as $account_attribute_group) { |
|
| 614 | + foreach ($account_attribute_group['attribut'] as $attribute) { |
|
| 615 | + foreach (preg_grep('/' . $attribute->code . '/', array_keys($customer_attributes_compare)) as $codeForm) { |
|
| 616 | + if ($customer_attributes_compare[$codeForm] == $attribute->data_type) { |
|
| 617 | + $user[$attribute->code] = array('attribute_id' => $attribute->id, 'data_type' => $attribute->data_type, 'value' => sanitize_text_field($_POST['attribute'][$attribute->data_type][$codeForm])); |
|
| 618 | + if ($attribute->code == 'user_email') { |
|
| 619 | 619 | $email_founded = true; |
| 620 | 620 | } |
| 621 | 621 | } |
@@ -623,22 +623,22 @@ discard block |
||
| 623 | 623 | } |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | - if ( $email_founded && is_email( $user['user_email']['value'] ) ) { |
|
| 627 | - $user_id = username_exists( $user['user_email']['value'] ); |
|
| 628 | - if ( empty( $user_id ) ) { |
|
| 629 | - $user_name = isset( $user['user_login']['value'] ) ? $user['user_login']['value'] : $user['user_email']['value']; |
|
| 630 | - $user_pass = isset( $user['user_pass']['value'] ) ? $user['user_pass']['value'] : wp_generate_password( 12, false ); |
|
| 631 | - $user_id = wp_create_user( $user_name, $user_pass, $user['user_email']['value'] ); |
|
| 626 | + if ($email_founded && is_email($user['user_email']['value'])) { |
|
| 627 | + $user_id = username_exists($user['user_email']['value']); |
|
| 628 | + if (empty($user_id)) { |
|
| 629 | + $user_name = isset($user['user_login']['value']) ? $user['user_login']['value'] : $user['user_email']['value']; |
|
| 630 | + $user_pass = isset($user['user_pass']['value']) ? $user['user_pass']['value'] : wp_generate_password(12, false); |
|
| 631 | + $user_id = wp_create_user($user_name, $user_pass, $user['user_email']['value']); |
|
| 632 | 632 | |
| 633 | - if ( !is_wp_error( $user_id ) ) { |
|
| 634 | - $customer_entity_request = $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id); |
|
| 635 | - $customer_entity_id = $wpdb->get_var( $customer_entity_request ); |
|
| 633 | + if (!is_wp_error($user_id)) { |
|
| 634 | + $customer_entity_request = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id); |
|
| 635 | + $customer_entity_id = $wpdb->get_var($customer_entity_request); |
|
| 636 | 636 | $return = array(); |
| 637 | 637 | $return['integer']['ID'] = $user_id; |
| 638 | 638 | |
| 639 | - foreach( $user as $meta_key => $meta_values ) { |
|
| 640 | - update_user_meta( $user_id, $meta_key, $meta_values['value'] ); |
|
| 641 | - $wpdb->insert( WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX.strtolower( $meta_values['data_type'] ), array( 'entity_type_id' => $customer_type_id, 'attribute_id' => $meta_values['attribute_id'], 'entity_id' => $customer_entity_id, 'user_id' => $user_id, 'creation_date_value' => current_time( 'mysql', 0), 'language' => 'fr_FR', 'value' => $meta_values['value'] ) ); |
|
| 639 | + foreach ($user as $meta_key => $meta_values) { |
|
| 640 | + update_user_meta($user_id, $meta_key, $meta_values['value']); |
|
| 641 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($meta_values['data_type']), array('entity_type_id' => $customer_type_id, 'attribute_id' => $meta_values['attribute_id'], 'entity_id' => $customer_entity_id, 'user_id' => $user_id, 'creation_date_value' => current_time('mysql', 0), 'language' => 'fr_FR', 'value' => $meta_values['value'])); |
|
| 642 | 642 | $return[$meta_values['data_type']][$meta_key] = $meta_values['value']; |
| 643 | 643 | } |
| 644 | 644 | } |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | /** |
| 290 | 290 | * Check $_GET in url for the bubble |
| 291 | 291 | * |
| 292 | - * @param array $url The array (paramater, value). |
|
| 292 | + * @param array $urls The array (paramater, value). |
|
| 293 | 293 | * @return boolean true is the bubble is checked in URL or false if not. |
| 294 | 294 | */ |
| 295 | 295 | public function check_url_bubble($urls) { |
@@ -338,7 +338,6 @@ discard block |
||
| 338 | 338 | /** |
| 339 | 339 | * Dismiss the pointer if not already dismissed |
| 340 | 340 | * |
| 341 | - * @param string $_POST['pointer'] The sanitize name of the pointer |
|
| 342 | 341 | */ |
| 343 | 342 | public function dismiss_my_pointer() { |
| 344 | 343 | $pointer = sanitize_key( $_POST['pointer'] ); |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | - * Register post type (Bubbles) |
|
| 37 | - */ |
|
| 36 | + * Register post type (Bubbles) |
|
| 37 | + */ |
|
| 38 | 38 | public function register_post_type() { |
| 39 | 39 | $labels = array( |
| 40 | 40 | 'name' => _x( 'Bubbles', 'post type general name', self::$name_i18n ), |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | - * For add_meta_box (position, actions, conditions, url, advanced) |
|
| 79 | - */ |
|
| 78 | + * For add_meta_box (position, actions, conditions, url, advanced) |
|
| 79 | + */ |
|
| 80 | 80 | public function admin_init() { |
| 81 | 81 | add_meta_box("wpeo-bubble-metabox-position", __("Position", self::$name_i18n), array(&$this, "metabox_position"), $this->post_type, "normal", "low"); |
| 82 | 82 | add_meta_box("wpeo-bubble-metabox-actions", __("Actions", self::$name_i18n), array(&$this, "metabox_actions"), $this->post_type, "normal", "low"); |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | - * Update post meta of post ID, rework the meta URL and save the meta |
|
| 90 | - * |
|
| 91 | - * @param int $post_id The id of the post being saved |
|
| 92 | - */ |
|
| 89 | + * Update post meta of post ID, rework the meta URL and save the meta |
|
| 90 | + * |
|
| 91 | + * @param int $post_id The id of the post being saved |
|
| 92 | + */ |
|
| 93 | 93 | public function save_custom($post_id) { |
| 94 | 94 | /** Eviter l'auto save pour ne pas vider les champs personnalisés */ |
| 95 | 95 | if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) |
@@ -113,10 +113,10 @@ discard block |
||
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | - * Get all pages of the backend, get current meta for this post, and call the template for display the metabox position. |
|
| 117 | - * |
|
| 118 | - * @param WP_Post $post The object for the current post/page. |
|
| 119 | - */ |
|
| 116 | + * Get all pages of the backend, get current meta for this post, and call the template for display the metabox position. |
|
| 117 | + * |
|
| 118 | + * @param WP_Post $post The object for the current post/page. |
|
| 119 | + */ |
|
| 120 | 120 | public function metabox_position($post) { |
| 121 | 121 | global $menu, $_parent_pages; |
| 122 | 122 | $tmp_menu = array(); |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | - * Get current meta for this post, declare the array type next, get all bubble posts and display the template metabox actions. |
|
| 143 | - * |
|
| 144 | - * @param WP_Post $post The object for the current post/page. |
|
| 145 | - */ |
|
| 142 | + * Get current meta for this post, declare the array type next, get all bubble posts and display the template metabox actions. |
|
| 143 | + * |
|
| 144 | + * @param WP_Post $post The object for the current post/page. |
|
| 145 | + */ |
|
| 146 | 146 | public function metabox_actions($post) { |
| 147 | 147 | $meta = get_post_meta($post->ID, $this->post_metakey, true); |
| 148 | 148 | $array_type_next = array("link", "bubble"); |
@@ -155,46 +155,46 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | - * Get current meta for this $post and display the template metabox conditions |
|
| 159 | - * |
|
| 160 | - * @param WP_Post $post The object for the current post/page. |
|
| 161 | - */ |
|
| 158 | + * Get current meta for this $post and display the template metabox conditions |
|
| 159 | + * |
|
| 160 | + * @param WP_Post $post The object for the current post/page. |
|
| 161 | + */ |
|
| 162 | 162 | public function metabox_conditions($post) { |
| 163 | 163 | $meta = get_post_meta($post->ID, $this->post_metakey, true); |
| 164 | 164 | require_once( wpsBubbleTemplate_ctr::get_template_part( WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'metabox', 'conditions')); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | - * Get current meta for this $post and display template metabox url. |
|
| 169 | - * |
|
| 170 | - * @param WP_Post $post The object for the current post/page. |
|
| 171 | - */ |
|
| 168 | + * Get current meta for this $post and display template metabox url. |
|
| 169 | + * |
|
| 170 | + * @param WP_Post $post The object for the current post/page. |
|
| 171 | + */ |
|
| 172 | 172 | public function metabox_url($post) { |
| 173 | 173 | $meta = get_post_meta($post->ID, $this->post_metakey, true); |
| 174 | 174 | require_once( wpsBubbleTemplate_ctr::get_template_part( WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'metabox', 'url')); |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
| 178 | - * Get current meta for this $post and display template metabox advanced. |
|
| 179 | - * |
|
| 180 | - * @param WP_Post $post The object for the current post/page. |
|
| 181 | - */ |
|
| 178 | + * Get current meta for this $post and display template metabox advanced. |
|
| 179 | + * |
|
| 180 | + * @param WP_Post $post The object for the current post/page. |
|
| 181 | + */ |
|
| 182 | 182 | public function metabox_advanced($post) { |
| 183 | 183 | $meta = get_post_meta($post->ID, $this->post_metakey, true); |
| 184 | 184 | require_once( wpsBubbleTemplate_ctr::get_template_part( WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'metabox', 'advanced')); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | - * Register my css and my js bubble, add wp-pointer and add action admin_print_footer_scripts. |
|
| 189 | - */ |
|
| 188 | + * Register my css and my js bubble, add wp-pointer and add action admin_print_footer_scripts. |
|
| 189 | + */ |
|
| 190 | 190 | public function admin_enqueue_scripts() { |
| 191 | 191 | /** Css */ |
| 192 | 192 | wp_register_style( 'wpeo-bubble-css', WPS_GUIDED_URL . '/assets/css/backend.css', '', WPS_GUIDED_VERSION ); |
| 193 | 193 | wp_enqueue_style( 'wpeo-bubble-css' ); |
| 194 | 194 | |
| 195 | 195 | /** For use pointer */ |
| 196 | - wp_enqueue_script( 'wp-pointer' ); |
|
| 197 | - wp_enqueue_style( 'wp-pointer' ); |
|
| 196 | + wp_enqueue_script( 'wp-pointer' ); |
|
| 197 | + wp_enqueue_style( 'wp-pointer' ); |
|
| 198 | 198 | |
| 199 | 199 | /** My js */ |
| 200 | 200 | wp_enqueue_script( 'wpeo-bubble-js', WPS_GUIDED_URL . '/assets/js/backend.js', array("jquery"), WPS_GUIDED_VERSION ); |
@@ -203,9 +203,9 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
| 206 | - * Get all bubble, rework the array bubble for check if the bubble is dismiss, in this page and respects the conditions (url and database) |
|
| 207 | - * and display it. |
|
| 208 | - */ |
|
| 206 | + * Get all bubble, rework the array bubble for check if the bubble is dismiss, in this page and respects the conditions (url and database) |
|
| 207 | + * and display it. |
|
| 208 | + */ |
|
| 209 | 209 | public function custom_admin_pointers_footer() { |
| 210 | 210 | $this->array_bubble = get_posts( |
| 211 | 211 | array( |
@@ -244,11 +244,11 @@ discard block |
||
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
| 247 | - * Check the current page for the bubble |
|
| 248 | - * |
|
| 249 | - * @param array $position (page, anchor_id) |
|
| 250 | - * @return boolean true is the bubble is in page or false if not. |
|
| 251 | - */ |
|
| 247 | + * Check the current page for the bubble |
|
| 248 | + * |
|
| 249 | + * @param array $position (page, anchor_id) |
|
| 250 | + * @return boolean true is the bubble is in page or false if not. |
|
| 251 | + */ |
|
| 252 | 252 | public function check_page_bubble($position) { |
| 253 | 253 | if(empty($position['page'])) |
| 254 | 254 | return true; |
@@ -263,11 +263,11 @@ discard block |
||
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
| 266 | - * Check condition in database for the bubble |
|
| 267 | - * |
|
| 268 | - * @param Array $conditions The array (option_name, data_name, option_value) |
|
| 269 | - * @return boolean true is the bubble respect the condition or false if not. |
|
| 270 | - */ |
|
| 266 | + * Check condition in database for the bubble |
|
| 267 | + * |
|
| 268 | + * @param Array $conditions The array (option_name, data_name, option_value) |
|
| 269 | + * @return boolean true is the bubble respect the condition or false if not. |
|
| 270 | + */ |
|
| 271 | 271 | public function check_condition_bubble($conditions) { |
| 272 | 272 | if(empty($conditions) || empty($conditions['option_name'])) |
| 273 | 273 | return true; |
@@ -287,11 +287,11 @@ discard block |
||
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
| 290 | - * Check $_GET in url for the bubble |
|
| 291 | - * |
|
| 292 | - * @param array $url The array (paramater, value). |
|
| 293 | - * @return boolean true is the bubble is checked in URL or false if not. |
|
| 294 | - */ |
|
| 290 | + * Check $_GET in url for the bubble |
|
| 291 | + * |
|
| 292 | + * @param array $url The array (paramater, value). |
|
| 293 | + * @return boolean true is the bubble is checked in URL or false if not. |
|
| 294 | + */ |
|
| 295 | 295 | public function check_url_bubble($urls) { |
| 296 | 296 | // Il faut que ça respecte au moins 1 $_GET |
| 297 | 297 | if(!empty($urls)) { |
@@ -311,10 +311,10 @@ discard block |
||
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | /** |
| 314 | - * Reset the bubble id for all user |
|
| 315 | - * |
|
| 316 | - * @param int post_ID - The bubble ID |
|
| 317 | - */ |
|
| 314 | + * Reset the bubble id for all user |
|
| 315 | + * |
|
| 316 | + * @param int post_ID - The bubble ID |
|
| 317 | + */ |
|
| 318 | 318 | public function reset_bubble_all_user() { |
| 319 | 319 | $post = get_post((int)$_POST['post_ID']); |
| 320 | 320 | $post_name = $post->post_name; |
@@ -336,10 +336,10 @@ discard block |
||
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /** |
| 339 | - * Dismiss the pointer if not already dismissed |
|
| 340 | - * |
|
| 341 | - * @param string $_POST['pointer'] The sanitize name of the pointer |
|
| 342 | - */ |
|
| 339 | + * Dismiss the pointer if not already dismissed |
|
| 340 | + * |
|
| 341 | + * @param string $_POST['pointer'] The sanitize name of the pointer |
|
| 342 | + */ |
|
| 343 | 343 | public function dismiss_my_pointer() { |
| 344 | 344 | $pointer = sanitize_key( $_POST['pointer'] ); |
| 345 | 345 | if ( $pointer != sanitize_key( $pointer ) ) |
@@ -358,10 +358,10 @@ discard block |
||
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
| 361 | - * Replace quote, simple quote, backline |
|
| 362 | - * |
|
| 363 | - * @param string $string The string |
|
| 364 | - */ |
|
| 361 | + * Replace quote, simple quote, backline |
|
| 362 | + * |
|
| 363 | + * @param string $string The string |
|
| 364 | + */ |
|
| 365 | 365 | private function format_string_php_to_js($string) { |
| 366 | 366 | $string = str_replace(CHR(13).CHR(10),"<br />",$string); |
| 367 | 367 | $string = str_replace("'", "'", $string); |
@@ -385,8 +385,8 @@ discard block |
||
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
| 388 | - * For import the base XML when install or update wpshop |
|
| 389 | - */ |
|
| 388 | + * For import the base XML when install or update wpshop |
|
| 389 | + */ |
|
| 390 | 390 | static public function import_xml() { |
| 391 | 391 | global $wpdb, $wp_rewrite; |
| 392 | 392 | |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | /** |
| 3 | 3 | * Main controller file for bubble module |
| 4 | 4 | * |
@@ -37,20 +37,20 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | public function register_post_type() { |
| 39 | 39 | $labels = array( |
| 40 | - 'name' => _x( 'Bubbles', 'post type general name', self::$name_i18n ), |
|
| 41 | - 'singular_name' => _x( 'Bubble', 'post type singular name', self::$name_i18n ), |
|
| 42 | - 'menu_name' => _x( 'Bubbles', 'admin menu', self::$name_i18n ), |
|
| 43 | - 'name_admin_bar' => _x( 'Bubble', 'add new on admin bar', self::$name_i18n ), |
|
| 44 | - 'add_new' => _x( 'Add New', 'bubble', self::$name_i18n ), |
|
| 45 | - 'add_new_item' => __( 'Add New Bubble', self::$name_i18n ), |
|
| 46 | - 'new_item' => __( 'New Bubble', self::$name_i18n ), |
|
| 47 | - 'edit_item' => __( 'Edit Bubble', self::$name_i18n ), |
|
| 48 | - 'view_item' => __( 'View Bubble', self::$name_i18n ), |
|
| 49 | - 'all_items' => __( 'All Bubbles', self::$name_i18n ), |
|
| 50 | - 'search_items' => __( 'Search Bubbles', self::$name_i18n ), |
|
| 51 | - 'parent_item_colon' => __( 'Parent Bubbles:', self::$name_i18n ), |
|
| 52 | - 'not_found' => __( 'No bubble found.', self::$name_i18n ), |
|
| 53 | - 'not_found_in_trash' => __( 'No bubble found in Trash.', self::$name_i18n ) |
|
| 40 | + 'name' => _x('Bubbles', 'post type general name', self::$name_i18n), |
|
| 41 | + 'singular_name' => _x('Bubble', 'post type singular name', self::$name_i18n), |
|
| 42 | + 'menu_name' => _x('Bubbles', 'admin menu', self::$name_i18n), |
|
| 43 | + 'name_admin_bar' => _x('Bubble', 'add new on admin bar', self::$name_i18n), |
|
| 44 | + 'add_new' => _x('Add New', 'bubble', self::$name_i18n), |
|
| 45 | + 'add_new_item' => __('Add New Bubble', self::$name_i18n), |
|
| 46 | + 'new_item' => __('New Bubble', self::$name_i18n), |
|
| 47 | + 'edit_item' => __('Edit Bubble', self::$name_i18n), |
|
| 48 | + 'view_item' => __('View Bubble', self::$name_i18n), |
|
| 49 | + 'all_items' => __('All Bubbles', self::$name_i18n), |
|
| 50 | + 'search_items' => __('Search Bubbles', self::$name_i18n), |
|
| 51 | + 'parent_item_colon' => __('Parent Bubbles:', self::$name_i18n), |
|
| 52 | + 'not_found' => __('No bubble found.', self::$name_i18n), |
|
| 53 | + 'not_found_in_trash' => __('No bubble found in Trash.', self::$name_i18n) |
|
| 54 | 54 | ); |
| 55 | 55 | |
| 56 | 56 | $args = array( |
@@ -60,18 +60,18 @@ discard block |
||
| 60 | 60 | 'show_ui' => false, |
| 61 | 61 | 'show_in_menu' => false, |
| 62 | 62 | 'query_var' => true, |
| 63 | - 'rewrite' => array( 'slug' => $this->post_type ), |
|
| 63 | + 'rewrite' => array('slug' => $this->post_type), |
|
| 64 | 64 | 'capability_type' => 'post', |
| 65 | 65 | 'exclude_from_search' => true, |
| 66 | 66 | 'has_archive' => true, |
| 67 | 67 | 'hierarchical' => false, |
| 68 | 68 | 'menu_position' => null, |
| 69 | 69 | 'menu_icon' => 'dashicons-format-status', |
| 70 | - 'supports' => array( 'title', 'editor' ) |
|
| 70 | + 'supports' => array('title', 'editor') |
|
| 71 | 71 | |
| 72 | 72 | ); |
| 73 | 73 | |
| 74 | - register_post_type( $this->post_type, $args ); |
|
| 74 | + register_post_type($this->post_type, $args); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -92,19 +92,19 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function save_custom($post_id) { |
| 94 | 94 | /** Eviter l'auto save pour ne pas vider les champs personnalisés */ |
| 95 | - if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) |
|
| 95 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) |
|
| 96 | 96 | return; |
| 97 | 97 | |
| 98 | - $meta = !empty( $_POST['meta'] ) ? (array) $_POST['meta'] : false; |
|
| 99 | - if(!$meta) |
|
| 98 | + $meta = !empty($_POST['meta']) ? (array)$_POST['meta'] : false; |
|
| 99 | + if (!$meta) |
|
| 100 | 100 | return; |
| 101 | 101 | |
| 102 | 102 | // Rework the URL meta |
| 103 | 103 | $tmp_array_urls = array(); |
| 104 | - if(!empty($meta['urls'])) { |
|
| 105 | - for($i = 0; $i < count($meta['urls']['paramater']); $i++) { |
|
| 106 | - $tmp_array_urls[$i]['paramater'] = sanitize_text_field( $meta['urls']['paramater'][$i] ); |
|
| 107 | - $tmp_array_urls[$i]['value'] = (!empty($meta['urls']['value']) && !empty($meta['urls']['value'][$i])) ? sanitize_text_field( $meta['urls']['value'][$i] ) : ""; |
|
| 104 | + if (!empty($meta['urls'])) { |
|
| 105 | + for ($i = 0; $i < count($meta['urls']['paramater']); $i++) { |
|
| 106 | + $tmp_array_urls[$i]['paramater'] = sanitize_text_field($meta['urls']['paramater'][$i]); |
|
| 107 | + $tmp_array_urls[$i]['value'] = (!empty($meta['urls']['value']) && !empty($meta['urls']['value'][$i])) ? sanitize_text_field($meta['urls']['value'][$i]) : ""; |
|
| 108 | 108 | } |
| 109 | 109 | $meta['urls'] = array(); |
| 110 | 110 | $meta['urls'] = $tmp_array_urls; |
@@ -124,20 +124,20 @@ discard block |
||
| 124 | 124 | $tmp_menu = array(); |
| 125 | 125 | $tmp_menu["all"] = __("All pages", self::$name_i18n); |
| 126 | 126 | |
| 127 | - foreach($menu as $array_menu) { |
|
| 128 | - if(!empty($array_menu[0])) |
|
| 127 | + foreach ($menu as $array_menu) { |
|
| 128 | + if (!empty($array_menu[0])) |
|
| 129 | 129 | $tmp_menu[$array_menu[2]] = $array_menu[0]; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $array_pages = array_merge($tmp_menu, $_parent_pages); |
| 133 | 133 | |
| 134 | - foreach($array_pages as $key => $pages) { |
|
| 135 | - if(empty($pages)) |
|
| 134 | + foreach ($array_pages as $key => $pages) { |
|
| 135 | + if (empty($pages)) |
|
| 136 | 136 | $array_pages[$key] = $key; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | $meta = get_post_meta($post->ID, $this->post_metakey, true); |
| 140 | - require_once( wpsBubbleTemplate_ctr::get_template_part( WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'metabox', 'position')); |
|
| 140 | + require_once(wpsBubbleTemplate_ctr::get_template_part(WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'metabox', 'position')); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | 'orderby' => 'title', |
| 154 | 154 | 'post_type' => $this->post_type, |
| 155 | 155 | )); |
| 156 | - require_once( wpsBubbleTemplate_ctr::get_template_part( WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'metabox', 'actions')); |
|
| 156 | + require_once(wpsBubbleTemplate_ctr::get_template_part(WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'metabox', 'actions')); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | public function metabox_conditions($post) { |
| 165 | 165 | $meta = get_post_meta($post->ID, $this->post_metakey, true); |
| 166 | - require_once( wpsBubbleTemplate_ctr::get_template_part( WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'metabox', 'conditions')); |
|
| 166 | + require_once(wpsBubbleTemplate_ctr::get_template_part(WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'metabox', 'conditions')); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | public function metabox_url($post) { |
| 175 | 175 | $meta = get_post_meta($post->ID, $this->post_metakey, true); |
| 176 | - require_once( wpsBubbleTemplate_ctr::get_template_part( WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'metabox', 'url')); |
|
| 176 | + require_once(wpsBubbleTemplate_ctr::get_template_part(WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'metabox', 'url')); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | public function metabox_advanced($post) { |
| 185 | 185 | $meta = get_post_meta($post->ID, $this->post_metakey, true); |
| 186 | - require_once( wpsBubbleTemplate_ctr::get_template_part( WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'metabox', 'advanced')); |
|
| 186 | + require_once(wpsBubbleTemplate_ctr::get_template_part(WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'metabox', 'advanced')); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
@@ -191,17 +191,17 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | public function admin_enqueue_scripts() { |
| 193 | 193 | /** Css */ |
| 194 | - wp_register_style( 'wpeo-bubble-css', WPS_GUIDED_URL . '/assets/css/backend.css', '', WPS_GUIDED_VERSION ); |
|
| 195 | - wp_enqueue_style( 'wpeo-bubble-css' ); |
|
| 194 | + wp_register_style('wpeo-bubble-css', WPS_GUIDED_URL . '/assets/css/backend.css', '', WPS_GUIDED_VERSION); |
|
| 195 | + wp_enqueue_style('wpeo-bubble-css'); |
|
| 196 | 196 | |
| 197 | 197 | /** For use pointer */ |
| 198 | - wp_enqueue_script( 'wp-pointer' ); |
|
| 199 | - wp_enqueue_style( 'wp-pointer' ); |
|
| 198 | + wp_enqueue_script('wp-pointer'); |
|
| 199 | + wp_enqueue_style('wp-pointer'); |
|
| 200 | 200 | |
| 201 | 201 | /** My js */ |
| 202 | - wp_enqueue_script( 'wpeo-bubble-js', WPS_GUIDED_URL . '/assets/js/backend.js', array("jquery"), WPS_GUIDED_VERSION ); |
|
| 202 | + wp_enqueue_script('wpeo-bubble-js', WPS_GUIDED_URL . '/assets/js/backend.js', array("jquery"), WPS_GUIDED_VERSION); |
|
| 203 | 203 | /** Bottom of page */ |
| 204 | - add_action( 'admin_print_footer_scripts', array(&$this, 'custom_admin_pointers_footer'), 50); |
|
| 204 | + add_action('admin_print_footer_scripts', array(&$this, 'custom_admin_pointers_footer'), 50); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -219,30 +219,30 @@ discard block |
||
| 219 | 219 | |
| 220 | 220 | $dismiss_pointer = explode(',', get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true)); |
| 221 | 221 | |
| 222 | - foreach($this->array_bubble as $key => $bubble) { |
|
| 222 | + foreach ($this->array_bubble as $key => $bubble) { |
|
| 223 | 223 | $meta = get_post_meta($bubble->ID, $this->post_metakey, true); |
| 224 | 224 | $this->array_bubble[$key]->post_meta = $meta; |
| 225 | 225 | |
| 226 | 226 | /** On vérifie si la bubble à déjà était fermer ou pas */ |
| 227 | 227 | $slug = "wpeo_bubble_" . $bubble->post_name; |
| 228 | - if(in_array($slug, $dismiss_pointer)) |
|
| 228 | + if (in_array($slug, $dismiss_pointer)) |
|
| 229 | 229 | unset($this->array_bubble[$key]); |
| 230 | 230 | |
| 231 | 231 | /** On vérifie si on est sur la bonne page de la bubble */ |
| 232 | - if(!$this->check_page_bubble((!empty($meta) && !empty($meta['position'])) ? $meta['position'] : array())) |
|
| 232 | + if (!$this->check_page_bubble((!empty($meta) && !empty($meta['position'])) ? $meta['position'] : array())) |
|
| 233 | 233 | unset($this->array_bubble[$key]); |
| 234 | 234 | |
| 235 | 235 | /** On vérifie si y'a pas des conditions */ |
| 236 | - if(!$this->check_condition_bubble((!empty($meta) && !empty($meta['conditions'])) ? $meta['conditions'] : array())) |
|
| 236 | + if (!$this->check_condition_bubble((!empty($meta) && !empty($meta['conditions'])) ? $meta['conditions'] : array())) |
|
| 237 | 237 | unset($this->array_bubble[$key]); |
| 238 | 238 | |
| 239 | 239 | /** On vérifie les $_GET */ |
| 240 | - if(!$this->check_url_bubble((!empty($meta) && !empty($meta['urls'])) ? $meta['urls'] : array())) |
|
| 240 | + if (!$this->check_url_bubble((!empty($meta) && !empty($meta['urls'])) ? $meta['urls'] : array())) |
|
| 241 | 241 | unset($this->array_bubble[$key]); |
| 242 | 242 | } |
| 243 | 243 | sort($this->array_bubble); |
| 244 | 244 | |
| 245 | - require_once( wpsBubbleTemplate_ctr::get_template_part( WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'pointer')); |
|
| 245 | + require_once(wpsBubbleTemplate_ctr::get_template_part(WPS_GUIDED_DIR, WPS_GUIDED_TEMPLATES_MAIN_DIR, 'backend', 'pointer')); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -252,13 +252,13 @@ discard block |
||
| 252 | 252 | * @return boolean true is the bubble is in page or false if not. |
| 253 | 253 | */ |
| 254 | 254 | public function check_page_bubble($position) { |
| 255 | - if(empty($position['page'])) |
|
| 255 | + if (empty($position['page'])) |
|
| 256 | 256 | return true; |
| 257 | 257 | |
| 258 | - if("all" === $position['page']) |
|
| 258 | + if ("all" === $position['page']) |
|
| 259 | 259 | return true; |
| 260 | 260 | |
| 261 | - if(get_current_screen()->parent_file === $position['page']) |
|
| 261 | + if (get_current_screen()->parent_file === $position['page']) |
|
| 262 | 262 | return true; |
| 263 | 263 | |
| 264 | 264 | return false; |
@@ -271,18 +271,18 @@ discard block |
||
| 271 | 271 | * @return boolean true is the bubble respect the condition or false if not. |
| 272 | 272 | */ |
| 273 | 273 | public function check_condition_bubble($conditions) { |
| 274 | - if(empty($conditions) || empty($conditions['option_name'])) |
|
| 274 | + if (empty($conditions) || empty($conditions['option_name'])) |
|
| 275 | 275 | return true; |
| 276 | 276 | |
| 277 | 277 | $option = get_option($conditions['option_name']); |
| 278 | 278 | |
| 279 | - if(empty($option) || $option == "") |
|
| 279 | + if (empty($option) || $option == "") |
|
| 280 | 280 | return true; |
| 281 | 281 | |
| 282 | - if(!is_array($option) && $option == $conditions['option_value']) { |
|
| 282 | + if (!is_array($option) && $option == $conditions['option_value']) { |
|
| 283 | 283 | return true; |
| 284 | 284 | } |
| 285 | - else if(is_array($option) && $conditions['option_value'] == $option[$conditions['data_name']]) { |
|
| 285 | + else if (is_array($option) && $conditions['option_value'] == $option[$conditions['data_name']]) { |
|
| 286 | 286 | return true; |
| 287 | 287 | } |
| 288 | 288 | return false; |
@@ -296,13 +296,13 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | public function check_url_bubble($urls) { |
| 298 | 298 | // Il faut que ça respecte au moins 1 $_GET |
| 299 | - if ( !empty( $urls ) ) { |
|
| 300 | - foreach ($urls as $url ) { |
|
| 301 | - $url = !empty( $_GET[$url['paramater']] ) ? sanitize_text_field( $_GET[$url['paramater']] ) : ''; |
|
| 302 | - if ( !empty( $url ) && $url == $url['value']) { |
|
| 299 | + if (!empty($urls)) { |
|
| 300 | + foreach ($urls as $url) { |
|
| 301 | + $url = !empty($_GET[$url['paramater']]) ? sanitize_text_field($_GET[$url['paramater']]) : ''; |
|
| 302 | + if (!empty($url) && $url == $url['value']) { |
|
| 303 | 303 | return true; |
| 304 | 304 | } |
| 305 | - else if(empty($url['paramater']) && empty($url['value'])) { |
|
| 305 | + else if (empty($url['paramater']) && empty($url['value'])) { |
|
| 306 | 306 | return true; |
| 307 | 307 | } |
| 308 | 308 | } |
@@ -319,17 +319,17 @@ discard block |
||
| 319 | 319 | * @param int post_ID - The bubble ID |
| 320 | 320 | */ |
| 321 | 321 | public function reset_bubble_all_user() { |
| 322 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 322 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 323 | 323 | |
| 324 | - if ( !wp_verify_nonce( $_wpnonce, 'reset_bubble_all_user' ) ) |
|
| 324 | + if (!wp_verify_nonce($_wpnonce, 'reset_bubble_all_user')) |
|
| 325 | 325 | wp_die(); |
| 326 | 326 | |
| 327 | 327 | $post = get_post((int)$_POST['post_ID']); |
| 328 | 328 | $post_name = $post->post_name; |
| 329 | 329 | |
| 330 | 330 | $array_users = get_users(); |
| 331 | - if(!empty($array_users)) { |
|
| 332 | - foreach($array_users as $user) { |
|
| 331 | + if (!empty($array_users)) { |
|
| 332 | + foreach ($array_users as $user) { |
|
| 333 | 333 | // User id $user->data->ID; |
| 334 | 334 | $meta = get_user_meta($user->data->ID, 'dismissed_wp_pointers', true); |
| 335 | 335 | $meta = explode(',', $meta); |
@@ -349,24 +349,24 @@ discard block |
||
| 349 | 349 | * @param string $_POST['pointer'] The sanitize name of the pointer |
| 350 | 350 | */ |
| 351 | 351 | public function dismiss_my_pointer() { |
| 352 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 352 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 353 | 353 | |
| 354 | - if ( !wp_verify_nonce( $_wpnonce, 'dismiss_my_pointer' ) ) |
|
| 354 | + if (!wp_verify_nonce($_wpnonce, 'dismiss_my_pointer')) |
|
| 355 | 355 | wp_die(); |
| 356 | 356 | |
| 357 | - $pointer = sanitize_key( $_POST['pointer'] ); |
|
| 358 | - if ( $pointer != sanitize_key( $pointer ) ) |
|
| 357 | + $pointer = sanitize_key($_POST['pointer']); |
|
| 358 | + if ($pointer != sanitize_key($pointer)) |
|
| 359 | 359 | wp_die(0); |
| 360 | 360 | |
| 361 | - $dismissed = array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) ); |
|
| 361 | + $dismissed = array_filter(explode(',', (string)get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true))); |
|
| 362 | 362 | |
| 363 | - if(in_array($pointer, $dismissed)) |
|
| 363 | + if (in_array($pointer, $dismissed)) |
|
| 364 | 364 | wp_die(0); |
| 365 | 365 | |
| 366 | 366 | $dismissed[] = $pointer; |
| 367 | - $dismissed = implode( ',', $dismissed ); |
|
| 367 | + $dismissed = implode(',', $dismissed); |
|
| 368 | 368 | |
| 369 | - update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed ); |
|
| 369 | + update_user_meta(get_current_user_id(), 'dismissed_wp_pointers', $dismissed); |
|
| 370 | 370 | wp_die(1); |
| 371 | 371 | } |
| 372 | 372 | |
@@ -376,10 +376,10 @@ discard block |
||
| 376 | 376 | * @param string $string The string |
| 377 | 377 | */ |
| 378 | 378 | private function format_string_php_to_js($string) { |
| 379 | - $string = str_replace(CHR(13).CHR(10),"<br />",$string); |
|
| 379 | + $string = str_replace(CHR(13) . CHR(10), "<br />", $string); |
|
| 380 | 380 | $string = str_replace("'", "'", $string); |
| 381 | 381 | $string = nl2br($string); |
| 382 | - $string = preg_replace( "/\r|\n/", "", $string ); |
|
| 382 | + $string = preg_replace("/\r|\n/", "", $string); |
|
| 383 | 383 | return trim($string); |
| 384 | 384 | } |
| 385 | 385 | |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | * @return array |
| 391 | 391 | */ |
| 392 | 392 | static public function xml_2_array($xml_object, $out = array()) { |
| 393 | - foreach((array) $xml_object as $index => $node) { |
|
| 393 | + foreach ((array)$xml_object as $index => $node) { |
|
| 394 | 394 | $out[$index] = (is_object($node)) ? xml_2_array($node) : $node; |
| 395 | 395 | } |
| 396 | 396 | |
@@ -412,34 +412,34 @@ discard block |
||
| 412 | 412 | ); |
| 413 | 413 | |
| 414 | 414 | /** Get the default datas for installation - sample products */ |
| 415 | - $sample_datas = file_get_contents( WPS_GUIDED_PATH . '/assets/data/default-data-guided-tour.xml' ); |
|
| 416 | - $defined_sample_datas = new SimpleXMLElement( $sample_datas, LIBXML_NOCDATA ); |
|
| 415 | + $sample_datas = file_get_contents(WPS_GUIDED_PATH . '/assets/data/default-data-guided-tour.xml'); |
|
| 416 | + $defined_sample_datas = new SimpleXMLElement($sample_datas, LIBXML_NOCDATA); |
|
| 417 | 417 | |
| 418 | 418 | $namespaces = $defined_sample_datas->getDocNamespaces(); |
| 419 | - if ( ! isset( $namespaces['wp'] ) ) |
|
| 419 | + if (!isset($namespaces['wp'])) |
|
| 420 | 420 | $namespaces['wp'] = 'http://wordpress.org/export/1.1/'; |
| 421 | - if ( ! isset( $namespaces['excerpt'] ) ) |
|
| 421 | + if (!isset($namespaces['excerpt'])) |
|
| 422 | 422 | $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/'; |
| 423 | 423 | |
| 424 | - foreach ( $defined_sample_datas->xpath( '//item' ) as $product ) { |
|
| 425 | - $dc = $product->children( 'http://purl.org/dc/elements/1.1/' ); |
|
| 426 | - $content = $product->children( 'http://purl.org/rss/1.0/modules/content/' ); |
|
| 427 | - $excerpt = $product->children( $namespaces['excerpt'] ); |
|
| 428 | - $wp = $product->children( $namespaces['wp'] ); |
|
| 424 | + foreach ($defined_sample_datas->xpath('//item') as $product) { |
|
| 425 | + $dc = $product->children('http://purl.org/dc/elements/1.1/'); |
|
| 426 | + $content = $product->children('http://purl.org/rss/1.0/modules/content/'); |
|
| 427 | + $excerpt = $product->children($namespaces['excerpt']); |
|
| 428 | + $wp = $product->children($namespaces['wp']); |
|
| 429 | 429 | |
| 430 | - $product_args = wp_parse_args( array( |
|
| 430 | + $product_args = wp_parse_args(array( |
|
| 431 | 431 | 'post_title' => __((string)$product->title, self::$name_i18n), |
| 432 | - 'post_name' => (string) $wp->post_name, |
|
| 433 | - 'post_content' => __((string) $content->encoded, self::$name_i18n), |
|
| 434 | - 'post_excerpt' => (string) $excerpt->encoded, |
|
| 435 | - 'post_type' => (string) $wp->post_type, |
|
| 436 | - ), $product_default_args ); |
|
| 437 | - |
|
| 438 | - $product_id = wp_insert_post( $product_args ); |
|
| 439 | - foreach ( $wp->postmeta as $meta ) { |
|
| 432 | + 'post_name' => (string)$wp->post_name, |
|
| 433 | + 'post_content' => __((string)$content->encoded, self::$name_i18n), |
|
| 434 | + 'post_excerpt' => (string)$excerpt->encoded, |
|
| 435 | + 'post_type' => (string)$wp->post_type, |
|
| 436 | + ), $product_default_args); |
|
| 437 | + |
|
| 438 | + $product_id = wp_insert_post($product_args); |
|
| 439 | + foreach ($wp->postmeta as $meta) { |
|
| 440 | 440 | $m = self::xml_2_array($meta->meta_value); |
| 441 | 441 | $m = maybe_unserialize($m[0]); |
| 442 | - update_post_meta( $product_id, (string)$meta->meta_key, $m); |
|
| 442 | + update_post_meta($product_id, (string)$meta->meta_key, $m); |
|
| 443 | 443 | } |
| 444 | 444 | } |
| 445 | 445 | |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Main controller file for bubble module |
| 4 | 6 | * |
@@ -92,12 +94,14 @@ discard block |
||
| 92 | 94 | */ |
| 93 | 95 | public function save_custom($post_id) { |
| 94 | 96 | /** Eviter l'auto save pour ne pas vider les champs personnalisés */ |
| 95 | - if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) |
|
| 96 | - return; |
|
| 97 | + if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
| 98 | + return; |
|
| 99 | + } |
|
| 97 | 100 | |
| 98 | 101 | $meta = !empty( $_POST['meta'] ) ? (array) $_POST['meta'] : false; |
| 99 | - if(!$meta) |
|
| 100 | - return; |
|
| 102 | + if(!$meta) { |
|
| 103 | + return; |
|
| 104 | + } |
|
| 101 | 105 | |
| 102 | 106 | // Rework the URL meta |
| 103 | 107 | $tmp_array_urls = array(); |
@@ -125,15 +129,17 @@ discard block |
||
| 125 | 129 | $tmp_menu["all"] = __("All pages", self::$name_i18n); |
| 126 | 130 | |
| 127 | 131 | foreach($menu as $array_menu) { |
| 128 | - if(!empty($array_menu[0])) |
|
| 129 | - $tmp_menu[$array_menu[2]] = $array_menu[0]; |
|
| 132 | + if(!empty($array_menu[0])) { |
|
| 133 | + $tmp_menu[$array_menu[2]] = $array_menu[0]; |
|
| 134 | + } |
|
| 130 | 135 | } |
| 131 | 136 | |
| 132 | 137 | $array_pages = array_merge($tmp_menu, $_parent_pages); |
| 133 | 138 | |
| 134 | 139 | foreach($array_pages as $key => $pages) { |
| 135 | - if(empty($pages)) |
|
| 136 | - $array_pages[$key] = $key; |
|
| 140 | + if(empty($pages)) { |
|
| 141 | + $array_pages[$key] = $key; |
|
| 142 | + } |
|
| 137 | 143 | } |
| 138 | 144 | |
| 139 | 145 | $meta = get_post_meta($post->ID, $this->post_metakey, true); |
@@ -225,20 +231,24 @@ discard block |
||
| 225 | 231 | |
| 226 | 232 | /** On vérifie si la bubble à déjà était fermer ou pas */ |
| 227 | 233 | $slug = "wpeo_bubble_" . $bubble->post_name; |
| 228 | - if(in_array($slug, $dismiss_pointer)) |
|
| 229 | - unset($this->array_bubble[$key]); |
|
| 234 | + if(in_array($slug, $dismiss_pointer)) { |
|
| 235 | + unset($this->array_bubble[$key]); |
|
| 236 | + } |
|
| 230 | 237 | |
| 231 | 238 | /** On vérifie si on est sur la bonne page de la bubble */ |
| 232 | - if(!$this->check_page_bubble((!empty($meta) && !empty($meta['position'])) ? $meta['position'] : array())) |
|
| 233 | - unset($this->array_bubble[$key]); |
|
| 239 | + if(!$this->check_page_bubble((!empty($meta) && !empty($meta['position'])) ? $meta['position'] : array())) { |
|
| 240 | + unset($this->array_bubble[$key]); |
|
| 241 | + } |
|
| 234 | 242 | |
| 235 | 243 | /** On vérifie si y'a pas des conditions */ |
| 236 | - if(!$this->check_condition_bubble((!empty($meta) && !empty($meta['conditions'])) ? $meta['conditions'] : array())) |
|
| 237 | - unset($this->array_bubble[$key]); |
|
| 244 | + if(!$this->check_condition_bubble((!empty($meta) && !empty($meta['conditions'])) ? $meta['conditions'] : array())) { |
|
| 245 | + unset($this->array_bubble[$key]); |
|
| 246 | + } |
|
| 238 | 247 | |
| 239 | 248 | /** On vérifie les $_GET */ |
| 240 | - if(!$this->check_url_bubble((!empty($meta) && !empty($meta['urls'])) ? $meta['urls'] : array())) |
|
| 241 | - unset($this->array_bubble[$key]); |
|
| 249 | + if(!$this->check_url_bubble((!empty($meta) && !empty($meta['urls'])) ? $meta['urls'] : array())) { |
|
| 250 | + unset($this->array_bubble[$key]); |
|
| 251 | + } |
|
| 242 | 252 | } |
| 243 | 253 | sort($this->array_bubble); |
| 244 | 254 | |
@@ -252,14 +262,17 @@ discard block |
||
| 252 | 262 | * @return boolean true is the bubble is in page or false if not. |
| 253 | 263 | */ |
| 254 | 264 | public function check_page_bubble($position) { |
| 255 | - if(empty($position['page'])) |
|
| 256 | - return true; |
|
| 265 | + if(empty($position['page'])) { |
|
| 266 | + return true; |
|
| 267 | + } |
|
| 257 | 268 | |
| 258 | - if("all" === $position['page']) |
|
| 259 | - return true; |
|
| 269 | + if("all" === $position['page']) { |
|
| 270 | + return true; |
|
| 271 | + } |
|
| 260 | 272 | |
| 261 | - if(get_current_screen()->parent_file === $position['page']) |
|
| 262 | - return true; |
|
| 273 | + if(get_current_screen()->parent_file === $position['page']) { |
|
| 274 | + return true; |
|
| 275 | + } |
|
| 263 | 276 | |
| 264 | 277 | return false; |
| 265 | 278 | } |
@@ -271,18 +284,19 @@ discard block |
||
| 271 | 284 | * @return boolean true is the bubble respect the condition or false if not. |
| 272 | 285 | */ |
| 273 | 286 | public function check_condition_bubble($conditions) { |
| 274 | - if(empty($conditions) || empty($conditions['option_name'])) |
|
| 275 | - return true; |
|
| 287 | + if(empty($conditions) || empty($conditions['option_name'])) { |
|
| 288 | + return true; |
|
| 289 | + } |
|
| 276 | 290 | |
| 277 | 291 | $option = get_option($conditions['option_name']); |
| 278 | 292 | |
| 279 | - if(empty($option) || $option == "") |
|
| 280 | - return true; |
|
| 293 | + if(empty($option) || $option == "") { |
|
| 294 | + return true; |
|
| 295 | + } |
|
| 281 | 296 | |
| 282 | 297 | if(!is_array($option) && $option == $conditions['option_value']) { |
| 283 | 298 | return true; |
| 284 | - } |
|
| 285 | - else if(is_array($option) && $conditions['option_value'] == $option[$conditions['data_name']]) { |
|
| 299 | + } else if(is_array($option) && $conditions['option_value'] == $option[$conditions['data_name']]) { |
|
| 286 | 300 | return true; |
| 287 | 301 | } |
| 288 | 302 | return false; |
@@ -301,14 +315,13 @@ discard block |
||
| 301 | 315 | $url = !empty( $_GET[$url['paramater']] ) ? sanitize_text_field( $_GET[$url['paramater']] ) : ''; |
| 302 | 316 | if ( !empty( $url ) && $url == $url['value']) { |
| 303 | 317 | return true; |
| 304 | - } |
|
| 305 | - else if(empty($url['paramater']) && empty($url['value'])) { |
|
| 318 | + } else if(empty($url['paramater']) && empty($url['value'])) { |
|
| 306 | 319 | return true; |
| 307 | 320 | } |
| 308 | 321 | } |
| 322 | + } else { |
|
| 323 | + return true; |
|
| 309 | 324 | } |
| 310 | - else |
|
| 311 | - return true; |
|
| 312 | 325 | |
| 313 | 326 | return false; |
| 314 | 327 | } |
@@ -321,8 +334,9 @@ discard block |
||
| 321 | 334 | public function reset_bubble_all_user() { |
| 322 | 335 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 323 | 336 | |
| 324 | - if ( !wp_verify_nonce( $_wpnonce, 'reset_bubble_all_user' ) ) |
|
| 325 | - wp_die(); |
|
| 337 | + if ( !wp_verify_nonce( $_wpnonce, 'reset_bubble_all_user' ) ) { |
|
| 338 | + wp_die(); |
|
| 339 | + } |
|
| 326 | 340 | |
| 327 | 341 | $post = get_post((int)$_POST['post_ID']); |
| 328 | 342 | $post_name = $post->post_name; |
@@ -351,17 +365,20 @@ discard block |
||
| 351 | 365 | public function dismiss_my_pointer() { |
| 352 | 366 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 353 | 367 | |
| 354 | - if ( !wp_verify_nonce( $_wpnonce, 'dismiss_my_pointer' ) ) |
|
| 355 | - wp_die(); |
|
| 368 | + if ( !wp_verify_nonce( $_wpnonce, 'dismiss_my_pointer' ) ) { |
|
| 369 | + wp_die(); |
|
| 370 | + } |
|
| 356 | 371 | |
| 357 | 372 | $pointer = sanitize_key( $_POST['pointer'] ); |
| 358 | - if ( $pointer != sanitize_key( $pointer ) ) |
|
| 359 | - wp_die(0); |
|
| 373 | + if ( $pointer != sanitize_key( $pointer ) ) { |
|
| 374 | + wp_die(0); |
|
| 375 | + } |
|
| 360 | 376 | |
| 361 | 377 | $dismissed = array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) ); |
| 362 | 378 | |
| 363 | - if(in_array($pointer, $dismissed)) |
|
| 364 | - wp_die(0); |
|
| 379 | + if(in_array($pointer, $dismissed)) { |
|
| 380 | + wp_die(0); |
|
| 381 | + } |
|
| 365 | 382 | |
| 366 | 383 | $dismissed[] = $pointer; |
| 367 | 384 | $dismissed = implode( ',', $dismissed ); |
@@ -416,10 +433,12 @@ discard block |
||
| 416 | 433 | $defined_sample_datas = new SimpleXMLElement( $sample_datas, LIBXML_NOCDATA ); |
| 417 | 434 | |
| 418 | 435 | $namespaces = $defined_sample_datas->getDocNamespaces(); |
| 419 | - if ( ! isset( $namespaces['wp'] ) ) |
|
| 420 | - $namespaces['wp'] = 'http://wordpress.org/export/1.1/'; |
|
| 421 | - if ( ! isset( $namespaces['excerpt'] ) ) |
|
| 422 | - $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/'; |
|
| 436 | + if ( ! isset( $namespaces['wp'] ) ) { |
|
| 437 | + $namespaces['wp'] = 'http://wordpress.org/export/1.1/'; |
|
| 438 | + } |
|
| 439 | + if ( ! isset( $namespaces['excerpt'] ) ) { |
|
| 440 | + $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/'; |
|
| 441 | + } |
|
| 423 | 442 | |
| 424 | 443 | foreach ( $defined_sample_datas->xpath( '//item' ) as $product ) { |
| 425 | 444 | $dc = $product->children( 'http://purl.org/dc/elements/1.1/' ); |
@@ -77,6 +77,12 @@ |
||
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | + /** |
|
| 81 | + * @param string $page_title |
|
| 82 | + * @param string $menu_title |
|
| 83 | + * @param string $menu_slug |
|
| 84 | + * @param string[] $callback |
|
| 85 | + */ |
|
| 80 | 86 | public function set_submenu_page_help( $page_title, $menu_title, $menu_slug, $callback ) { |
| 81 | 87 | $this->sub_menus[$menu_slug] = array( |
| 82 | 88 | 'page_title' => $page_title |
@@ -20,8 +20,8 @@ |
||
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Appelle le template dans wps_installer backend about / Call the template in wps_installer backend about |
|
| 24 | - */ |
|
| 23 | + * Appelle le template dans wps_installer backend about / Call the template in wps_installer backend about |
|
| 24 | + */ |
|
| 25 | 25 | public function render_menu() { |
| 26 | 26 | require_once( wpshop_tools::get_template_part( WPS_INSTALLER_DIR, WPSINSTALLER_TPL_DIR, "backend", "about" ) ); |
| 27 | 27 | } |
@@ -1,20 +1,20 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_help_menus_ctr { |
| 3 | 3 | public $sub_menus; |
| 4 | 4 | |
| 5 | 5 | public function __construct() { |
| 6 | - $this->set_submenu_page_help( __( 'Shortcodes', 'wpshop' ), __( 'Shortcodes', 'wpshop' ), WPSHOP_URL_SLUG_SHORTCODES, array( 'wpshop_display', 'display_page' ) ); |
|
| 6 | + $this->set_submenu_page_help(__('Shortcodes', 'wpshop'), __('Shortcodes', 'wpshop'), WPSHOP_URL_SLUG_SHORTCODES, array('wpshop_display', 'display_page')); |
|
| 7 | 7 | |
| 8 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
| 9 | - add_action( 'menu_order', array( $this, 'admin_menu_order' ), 12 ); |
|
| 10 | - add_action( 'custom_menu_order', array( $this, 'admin_custom_menu_order' ) ); |
|
| 8 | + add_action('admin_menu', array($this, 'admin_menu')); |
|
| 9 | + add_action('menu_order', array($this, 'admin_menu_order'), 12); |
|
| 10 | + add_action('custom_menu_order', array($this, 'admin_custom_menu_order')); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Ajout du menu pour le logiciel de caisse dans le backend / Create a new administration menu into backend |
| 15 | 15 | */ |
| 16 | 16 | public function admin_menu() { |
| 17 | - add_menu_page( __( 'Help', 'wpshop' ), __( 'Help', 'wpshop' ), 'wpshop_view_dashboard', WPSHOP_URL_SLUG_ABOUT, array($this, 'render_menu'), 'dashicons-editor-help' ); |
|
| 17 | + add_menu_page(__('Help', 'wpshop'), __('Help', 'wpshop'), 'wpshop_view_dashboard', WPSHOP_URL_SLUG_ABOUT, array($this, 'render_menu'), 'dashicons-editor-help'); |
|
| 18 | 18 | |
| 19 | 19 | $this->create_submenu_page_help(); |
| 20 | 20 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * Appelle le template dans wps_installer backend about / Call the template in wps_installer backend about |
| 24 | 24 | */ |
| 25 | 25 | public function render_menu() { |
| 26 | - require_once( wpshop_tools::get_template_part( WPS_INSTALLER_DIR, WPSINSTALLER_TPL_DIR, "backend", "about" ) ); |
|
| 26 | + require_once(wpshop_tools::get_template_part(WPS_INSTALLER_DIR, WPSINSTALLER_TPL_DIR, "backend", "about")); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -33,19 +33,19 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @return array The new admin menu order with the POS addon placed |
| 35 | 35 | */ |
| 36 | - public function admin_menu_order( $current_menu_order ) { |
|
| 36 | + public function admin_menu_order($current_menu_order) { |
|
| 37 | 37 | /** Create a new menu order */ |
| 38 | 38 | $wps_pos_menu_ordered = array(); |
| 39 | 39 | |
| 40 | 40 | /** Read the current existing menu order for rearrange it */ |
| 41 | - foreach ( $current_menu_order as $menu_item ) { |
|
| 42 | - if ( 'edit.php?post_type=wps_highlighting' == $menu_item ) { |
|
| 41 | + foreach ($current_menu_order as $menu_item) { |
|
| 42 | + if ('edit.php?post_type=wps_highlighting' == $menu_item) { |
|
| 43 | 43 | $wps_pos_menu_ordered[] = 'edit.php?post_type=wps_highlighting'; |
| 44 | 44 | $wps_pos_menu_ordered[] = WPSHOP_URL_SLUG_ABOUT; |
| 45 | 45 | |
| 46 | - unset( $current_menu_order[ array_search( WPSHOP_URL_SLUG_ABOUT, $current_menu_order ) ] ); |
|
| 46 | + unset($current_menu_order[array_search(WPSHOP_URL_SLUG_ABOUT, $current_menu_order)]); |
|
| 47 | 47 | } |
| 48 | - else if ( WPSHOP_URL_SLUG_ABOUT != $menu_item ) { |
|
| 48 | + else if (WPSHOP_URL_SLUG_ABOUT != $menu_item) { |
|
| 49 | 49 | $wps_pos_menu_ordered[] = $menu_item; |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | * @return boolean A boolean var defining if we apply admin menu reorder for current user |
| 60 | 60 | */ |
| 61 | 61 | public function admin_custom_menu_order() { |
| 62 | - return current_user_can( 'manage_options' ); |
|
| 62 | + return current_user_can('manage_options'); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | public function create_submenu_page_help() { |
| 66 | - if( is_array( $this->sub_menus ) ) { |
|
| 67 | - foreach ( $this->sub_menus as $slug => $data ) |
|
| 66 | + if (is_array($this->sub_menus)) { |
|
| 67 | + foreach ($this->sub_menus as $slug => $data) |
|
| 68 | 68 | { |
| 69 | 69 | add_submenu_page( |
| 70 | 70 | WPSHOP_URL_SLUG_ABOUT |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public function set_submenu_page_help( $page_title, $menu_title, $menu_slug, $callback ) { |
|
| 80 | + public function set_submenu_page_help($page_title, $menu_title, $menu_slug, $callback) { |
|
| 81 | 81 | $this->sub_menus[$menu_slug] = array( |
| 82 | 82 | 'page_title' => $page_title |
| 83 | 83 | ,'menu_title' => $menu_title |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | class wps_help_menus_ctr { |
| 3 | 5 | public $sub_menus; |
| 4 | 6 | |
@@ -44,8 +46,7 @@ discard block |
||
| 44 | 46 | $wps_pos_menu_ordered[] = WPSHOP_URL_SLUG_ABOUT; |
| 45 | 47 | |
| 46 | 48 | unset( $current_menu_order[ array_search( WPSHOP_URL_SLUG_ABOUT, $current_menu_order ) ] ); |
| 47 | - } |
|
| 48 | - else if ( WPSHOP_URL_SLUG_ABOUT != $menu_item ) { |
|
| 49 | + } else if ( WPSHOP_URL_SLUG_ABOUT != $menu_item ) { |
|
| 49 | 50 | $wps_pos_menu_ordered[] = $menu_item; |
| 50 | 51 | } |
| 51 | 52 | } |