Completed
Pull Request — master (#2)
by Jimmy
1003:35 queued 970:52
created
includes/modules/wps_installer/model/wps_installer_model.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@
 block discarded – undo
81 81
 	 * Save the current state of installation process
82 82
 	 *
83 83
 	 * @param string $setted_state A parameter setted for saving the state of installation ( in progress, completed, ignored )
84
-	 * @param array $current_db_version The current value for database version option
84
+	 * @param string $current_db_version The current value for database version option
85 85
 	 */
86 86
 	function installer_state_saver( $setted_state, $current_db_version ) {
87 87
 		$current_db_version['installation_state'] = $setted_state;
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
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
  *
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 /**
3 3
  * Module controller class definition file
4 4
  *
@@ -28,34 +28,34 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @param integer $the_step_to_save The current step to save
30 30
 	 */
31
-	function save_step( $the_step_to_save ) {
31
+	function save_step($the_step_to_save) {
32 32
 
33
-		switch ( $the_step_to_save ) {
33
+		switch ($the_step_to_save) {
34 34
 			case 1:
35 35
 				/**	Save company informations	*/
36
-				$wpshop_company_info = !empty( $_POST['wpshop_company_info'] ) ? sanitize_text_field( $_POST['wpshop_company_info'] ) : '';
37
-				if ( !empty( $wpshop_company_info ) ) {
38
-					update_option( 'wpshop_company_info', $wpshop_company_info );
36
+				$wpshop_company_info = !empty($_POST['wpshop_company_info']) ? sanitize_text_field($_POST['wpshop_company_info']) : '';
37
+				if (!empty($wpshop_company_info)) {
38
+					update_option('wpshop_company_info', $wpshop_company_info);
39 39
 				}
40 40
 
41 41
 				/**	Save the company logo in case a file is sended	*/
42
-				$shop_logo = !empty( $_POST['wpshop_logo'] ) ? sanitize_text_field( $_POST['wpshop_logo'] ) : '';
43
-				if ( !empty( $shop_logo ) ) {
44
-					update_option( 'wpshop_logo', $shop_logo );
42
+				$shop_logo = !empty($_POST['wpshop_logo']) ? sanitize_text_field($_POST['wpshop_logo']) : '';
43
+				if (!empty($shop_logo)) {
44
+					update_option('wpshop_logo', $shop_logo);
45 45
 				}
46 46
 				break;
47 47
 
48 48
 			case 2:
49 49
 				/**	Save shop type	*/
50
-				$wpshop_shop_type = !empty( $_POST['wpshop_shop_type'] ) ? sanitize_text_field( $_POST[ 'wpshop_shop_type' ] ) : '';
51
-				if ( !empty( $wpshop_shop_type ) ) {
52
-					update_option( 'wpshop_shop_type', $wpshop_shop_type );
50
+				$wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : '';
51
+				if (!empty($wpshop_shop_type)) {
52
+					update_option('wpshop_shop_type', $wpshop_shop_type);
53 53
 				}
54 54
 
55 55
 				/**	Save shop price piloting	*/
56
-				$wpshop_shop_price_piloting = !empty( $_POST[ 'wpshop_shop_price_piloting' ] ) ? sanitize_text_field( $_POST[ 'wpshop_shop_price_piloting' ] ) : '';
57
-				if ( !empty( $wpshop_shop_price_piloting ) ) {
58
-					update_option( 'wpshop_shop_price_piloting', $wpshop_shop_price_piloting );
56
+				$wpshop_shop_price_piloting = !empty($_POST['wpshop_shop_price_piloting']) ? sanitize_text_field($_POST['wpshop_shop_price_piloting']) : '';
57
+				if (!empty($wpshop_shop_price_piloting)) {
58
+					update_option('wpshop_shop_price_piloting', $wpshop_shop_price_piloting);
59 59
 				}
60 60
 
61 61
 				/**	Insert default pages	*/
@@ -63,21 +63,21 @@  discard block
 block discarded – undo
63 63
 				//add_action( 'init', array( 'wps_message_ctr', 'create_default_message' ) );
64 64
 
65 65
 				/**	In case the user want to insert default datas	*/
66
-				$wps_installer_data_insertion = !empty( $_POST[ 'wps-installer-data-insertion' ] ) ? sanitize_text_field( $_POST[ 'wps-installer-data-insertion' ] ) : '';
67
-				if ( !empty( $wps_installer_data_insertion ) && ( 'yes' == $wps_installer_data_insertion ) ) {
66
+				$wps_installer_data_insertion = !empty($_POST['wps-installer-data-insertion']) ? sanitize_text_field($_POST['wps-installer-data-insertion']) : '';
67
+				if (!empty($wps_installer_data_insertion) && ('yes' == $wps_installer_data_insertion)) {
68 68
 					/**	Insert sample datas */
69
-					add_action( 'init', array( 'wpshop_install', 'import_sample_datas' ) );
69
+					add_action('init', array('wpshop_install', 'import_sample_datas'));
70 70
 				}
71 71
 
72
-				$wps_current_db_version = get_option( 'wpshop_db_options', 0 );
73
-				$wps_current_db_version[ 'installation_state' ] = 'completed';
74
-				$wps_current_db_version[ 'installation_date' ] = current_time( 'mysql', 0 );
75
-				update_option( 'wpshop_db_options', $wps_current_db_version );
72
+				$wps_current_db_version = get_option('wpshop_db_options', 0);
73
+				$wps_current_db_version['installation_state'] = 'completed';
74
+				$wps_current_db_version['installation_date'] = current_time('mysql', 0);
75
+				update_option('wpshop_db_options', $wps_current_db_version);
76 76
 				break;
77 77
 		}
78 78
 
79
-		if ( !empty( $the_step_to_save ) ) {
80
-			update_option( 'wps-installation-current-step', ( WPSINSTALLER_STEPS_COUNT != $the_step_to_save ? $the_step_to_save + 1 : WPSINSTALLER_STEPS_COUNT ) );
79
+		if (!empty($the_step_to_save)) {
80
+			update_option('wps-installation-current-step', (WPSINSTALLER_STEPS_COUNT != $the_step_to_save ? $the_step_to_save + 1 : WPSINSTALLER_STEPS_COUNT));
81 81
 		}
82 82
 	}
83 83
 
@@ -87,16 +87,16 @@  discard block
 block discarded – undo
87 87
 	 * @param string $setted_state A parameter setted for saving the state of installation ( in progress, completed, ignored )
88 88
 	 * @param array $current_db_version The current value for database version option
89 89
 	 */
90
-	function installer_state_saver( $setted_state, $current_db_version ) {
90
+	function installer_state_saver($setted_state, $current_db_version) {
91 91
 		$current_db_version['installation_state'] = $setted_state;
92
-		$current_db_version[ 'installation_date' ] = current_time( 'mysql', 0 );
92
+		$current_db_version['installation_date'] = current_time('mysql', 0);
93 93
 		update_option('wpshop_db_options', $current_db_version);
94 94
 
95
-		if ( "ignored" == $current_db_version['installation_state'] ) {
95
+		if ("ignored" == $current_db_version['installation_state']) {
96 96
 			/**	Create the different pages	*/
97
-			if ( 2 >= get_option( 'wps-installation-current-step' ) ) {
98
-				update_option( 'wpshop_shop_price_piloting', 'TTC' );
99
-				update_option( 'wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE );
97
+			if (2 >= get_option('wps-installation-current-step')) {
98
+				update_option('wpshop_shop_price_piloting', 'TTC');
99
+				update_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
100 100
 
101 101
 				/**	Insert default pages	*/
102 102
 				//add_action( 'init', array( 'wpshop_install', 'wpshop_insert_default_pages' ) );
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 			}
106 106
 
107 107
 			/**	Save the crrent step to 4 in order to consider that installation is done	*/
108
-			update_option( 'wps-installation-current-step', WPSINSTALLER_STEPS_COUNT );
108
+			update_option('wps-installation-current-step', WPSINSTALLER_STEPS_COUNT);
109 109
 		}
110 110
 
111 111
 		return $current_db_version;
Please login to merge, or discard this patch.
modules/wps_media_manager/controller/wps_media_manager_frontend_ctr.php 3 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	/**
71 71
 	 * Get product Complete Sheet
72 72
 	 * @param integer $pid
73
-	 * @return Ambigous <string, string>
73
+	 * @return string <string, string>
74 74
 	 */
75 75
 	public static function get_product_complete_sheet_galery( $pid ) {
76 76
 		$output = '';
@@ -157,6 +157,9 @@  discard block
 block discarded – undo
157 157
 		return $output;
158 158
 	}
159 159
 
160
+	/**
161
+	 * @param integer $product_id
162
+	 */
160 163
 	public static function get_product_complete_sheet_attachments( $product_id ) {
161 164
 		$output = '';
162 165
 
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 class wps_media_manager_frontend_ctr {
3 3
 
4
-	public static function get_attachments( $pid, $type = 'gallery' ) {
4
+	public static function get_attachments($pid, $type = 'gallery') {
5 5
 		$attachments = array();
6
-		$media_id_data = get_post_meta( $pid, '_wps_product_media', true );
7
-		if( !empty($media_id_data) ) {
8
-			$media_id = explode( ',', $media_id_data );
9
-			foreach($media_id as $id) {
10
-				if( ( ( wp_attachment_is_image( $id ) && $type == 'gallery' ) || ( !empty( $id ) && !wp_attachment_is_image( $id ) && $type == 'attachments' ) ) ) {
11
-					$attachment_data = get_post( $id );
12
-					if( !empty( $attachment_data ) && !empty($attachment_data->ID) ) {
6
+		$media_id_data = get_post_meta($pid, '_wps_product_media', true);
7
+		if (!empty($media_id_data)) {
8
+			$media_id = explode(',', $media_id_data);
9
+			foreach ($media_id as $id) {
10
+				if (((wp_attachment_is_image($id) && $type == 'gallery') || (!empty($id) && !wp_attachment_is_image($id) && $type == 'attachments'))) {
11
+					$attachment_data = get_post($id);
12
+					if (!empty($attachment_data) && !empty($attachment_data->ID)) {
13 13
 						$attachments[] = $attachment_data;
14 14
 					}
15 15
 				}
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @return string The attachement gallery output
28 28
 	 */
29
-	public static function display_attachment_gallery( $attachement_type, $content ) {
29
+	public static function display_attachment_gallery($attachement_type, $content) {
30 30
 		$galery_output = '';
31 31
 
32 32
 		/*
33 33
 		 * Get the template part for given galery type
34 34
 		 */
35
-		switch ( $attachement_type ) {
35
+		switch ($attachement_type) {
36 36
 			case 'picture':
37 37
 					$template_part = 'product_attachment_picture_galery';
38 38
 				break;
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 		 * Build template
53 53
 		 */
54 54
 		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
55
-		if ( $tpl_way_to_take[0] && !empty($tpl_way_to_take[1]) ) {
55
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
56 56
 			/*	Include the old way template part	*/
57 57
 			ob_start();
58 58
 			require(wpshop_display::get_template_file($tpl_way_to_take[1]));
@@ -72,81 +72,81 @@  discard block
 block discarded – undo
72 72
 	 * @param integer $pid
73 73
 	 * @return Ambigous <string, string>
74 74
 	 */
75
-	public static function get_product_complete_sheet_galery( $pid ) {
75
+	public static function get_product_complete_sheet_galery($pid) {
76 76
 		$output = '';
77
-		if( !empty($pid) ) {
77
+		if (!empty($pid)) {
78 78
 			$tpl_component = $sub_tpl_component = array();
79 79
 			$attachments = array();
80 80
 			$tpl_component['THUMBNAILS'] = '';
81 81
 			$tpl_component['SLIDER_CONTENT'] = '';
82 82
 
83 83
 			/**	Check and get the product thumbnail	*/
84
-			$principal_thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true);
85
-			if( !empty($principal_thumbnail_id) ) {
86
-				$attachments[0] = get_post( $principal_thumbnail_id );
84
+			$principal_thumbnail_id = get_post_meta($pid, '_thumbnail_id', true);
85
+			if (!empty($principal_thumbnail_id)) {
86
+				$attachments[0] = get_post($principal_thumbnail_id);
87 87
 			}
88 88
 			else {
89 89
 				$sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL'] = '';
90
-				$sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
91
-				$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
90
+				$sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
91
+				$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
92 92
 				$sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL_ID'] = '';
93 93
 
94
-				$tpl_component[ 'SLIDER_CONTENT' ] .= wpshop_display::display_template_element( 'wps_product_complete_sheet_gallery_slider_element', $sub_tpl_component );
95
-				$tpl_component[ 'THUMBNAILS' ] = '';
94
+				$tpl_component['SLIDER_CONTENT'] .= wpshop_display::display_template_element('wps_product_complete_sheet_gallery_slider_element', $sub_tpl_component);
95
+				$tpl_component['THUMBNAILS'] = '';
96 96
 			}
97 97
 
98 98
 			/**	Get product associated pictures	*/
99 99
 			$allowed_mime_type = get_allowed_mime_types();
100 100
 
101
-			$attachments = array_merge( $attachments, (array)self::get_attachments( $pid ) );
101
+			$attachments = array_merge($attachments, (array)self::get_attachments($pid));
102 102
 
103 103
 			/**	In case there are picture read and display them into product sheet	*/
104
-			if ( !empty($attachments) ) {
105
-				foreach( $attachments as $attachment) {
106
-					if( !empty($attachment) && !empty($attachment->post_mime_type) && in_array( $attachment->post_mime_type, $allowed_mime_type ) ) {
104
+			if (!empty($attachments)) {
105
+				foreach ($attachments as $attachment) {
106
+					if (!empty($attachment) && !empty($attachment->post_mime_type) && in_array($attachment->post_mime_type, $allowed_mime_type)) {
107 107
 						//IMAGE SLIDER
108
-						$image_attributes = wp_get_attachment_metadata( $attachment->ID );
108
+						$image_attributes = wp_get_attachment_metadata($attachment->ID);
109 109
 						$sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL'] = '';
110 110
 						$sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL_ID'] = $attachment->ID;
111
-						if ( !empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes']) ) {
112
-							foreach ( $image_attributes['sizes'] as $size_name => $size_def) {
113
-								$p = wp_get_attachment_image( $attachment->ID, $size_name);
114
-								$src = wp_get_attachment_image_src( $attachment->ID, $size_name );
111
+						if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
112
+							foreach ($image_attributes['sizes'] as $size_name => $size_def) {
113
+								$p = wp_get_attachment_image($attachment->ID, $size_name);
114
+								$src = wp_get_attachment_image_src($attachment->ID, $size_name);
115 115
 								$sub_tpl_component['THUMBNAIL_GALLERY_' . strtoupper($size_name)] = '';
116 116
 								$sub_tpl_component['IMAGE_SLIDER_' . strtoupper($size_name)] = '';
117
-								if( !empty($p) ) {
118
-									$sub_tpl_component['SRC_IMAGE_SLIDER_' . strtoupper($size_name)] = ( !empty($src) ) ? $src[0] : '';
119
-									$sub_tpl_component['IMAGE_SLIDER_' . strtoupper($size_name)] = ( !empty( $p ) ) ? $p : '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
120
-									$sub_tpl_component['THUMBNAIL_GALLERY_' . strtoupper($size_name)] = ( !empty( $p ) ) ? $p : '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
117
+								if (!empty($p)) {
118
+									$sub_tpl_component['SRC_IMAGE_SLIDER_' . strtoupper($size_name)] = (!empty($src)) ? $src[0] : '';
119
+									$sub_tpl_component['IMAGE_SLIDER_' . strtoupper($size_name)] = (!empty($p)) ? $p : '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
120
+									$sub_tpl_component['THUMBNAIL_GALLERY_' . strtoupper($size_name)] = (!empty($p)) ? $p : '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
121 121
 								}
122 122
 							}
123
-							$p = wp_get_attachment_image( $attachment->ID, 'full');
124
-							$src = wp_get_attachment_image_src( $attachment->ID, 'full' );
125
-							if( !empty($p) ) {
126
-								$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = ( !empty($src) ) ? $src[0] : '';
127
-								$sub_tpl_component['IMAGE_SLIDER_FULL'] = ( !empty($p) ) ? $p : '';
128
-								$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = ( !empty($p) ) ? $p : '';
123
+							$p = wp_get_attachment_image($attachment->ID, 'full');
124
+							$src = wp_get_attachment_image_src($attachment->ID, 'full');
125
+							if (!empty($p)) {
126
+								$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = (!empty($src)) ? $src[0] : '';
127
+								$sub_tpl_component['IMAGE_SLIDER_FULL'] = (!empty($p)) ? $p : '';
128
+								$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = (!empty($p)) ? $p : '';
129 129
 							}
130 130
 						}
131 131
 						else {
132
-							$p = wp_get_attachment_image( $attachment->ID, 'full' );
133
-							$src = wp_get_attachment_image_src( $attachment->ID, 'full' );
134
-							$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = ( !empty($src) ) ? $src[0] : '';
135
-							$sub_tpl_component['IMAGE_SLIDER_FULL'] = ( !empty( $p ) ) ? $p : '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
136
-							$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = ( !empty( $p ) ) ? $p : '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
132
+							$p = wp_get_attachment_image($attachment->ID, 'full');
133
+							$src = wp_get_attachment_image_src($attachment->ID, 'full');
134
+							$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = (!empty($src)) ? $src[0] : '';
135
+							$sub_tpl_component['IMAGE_SLIDER_FULL'] = (!empty($p)) ? $p : '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
136
+							$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = (!empty($p)) ? $p : '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
137 137
 						}
138
-						if ( !empty( $sub_tpl_component['IMAGE_SLIDER_FULL'] ) ) {
139
-							$tpl_component[ 'SLIDER_CONTENT' ] .= wpshop_display::display_template_element( 'wps_product_complete_sheet_gallery_slider_element', $sub_tpl_component );
140
-							if ( ( 1 < count( $attachments ) ) || ( ( 1 == count( $attachments ) ) && empty( $principal_thumbnail_id ) ) ) {
141
-								$tpl_component[ 'THUMBNAILS' ] .= wpshop_display::display_template_element( 'wps_product_complete_sheet_gallery_thumbnail_element', $sub_tpl_component );
138
+						if (!empty($sub_tpl_component['IMAGE_SLIDER_FULL'])) {
139
+							$tpl_component['SLIDER_CONTENT'] .= wpshop_display::display_template_element('wps_product_complete_sheet_gallery_slider_element', $sub_tpl_component);
140
+							if ((1 < count($attachments)) || ((1 == count($attachments)) && empty($principal_thumbnail_id))) {
141
+								$tpl_component['THUMBNAILS'] .= wpshop_display::display_template_element('wps_product_complete_sheet_gallery_thumbnail_element', $sub_tpl_component);
142 142
 							}
143 143
 						}
144
-						unset( $sub_tpl_component );
144
+						unset($sub_tpl_component);
145 145
 					}
146 146
 					else {
147 147
 						$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = '';
148
-						$sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
149
-						$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
148
+						$sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
149
+						$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />';
150 150
 					}
151 151
 				}
152 152
 			}
@@ -157,35 +157,35 @@  discard block
 block discarded – undo
157 157
 		return $output;
158 158
 	}
159 159
 
160
-	public static function get_product_complete_sheet_attachments( $product_id ) {
160
+	public static function get_product_complete_sheet_attachments($product_id) {
161 161
 		$output = '';
162 162
 
163 163
 		/**	Get attachement file for the current product	*/
164 164
 		$product_picture_galery_content = $product_document_galery_content = '';
165 165
 		$picture_number = $document_number = $index_li = 0;
166 166
 
167
-		$attachments = self::get_attachments( $product_id, 'attachments' );
167
+		$attachments = self::get_attachments($product_id, 'attachments');
168 168
 
169
-		if ( is_array($attachments) && (count($attachments) > 0) ) {
169
+		if (is_array($attachments) && (count($attachments) > 0)) {
170 170
 			$picture_increment = $document_increment = 1;
171 171
 			foreach ($attachments as $attachment) {
172 172
 				$tpl_component = array();
173
-				$attachment_url = wp_get_attachment_url( $attachment->ID );
173
+				$attachment_url = wp_get_attachment_url($attachment->ID);
174 174
 				$attachment_extension = explode('.', $attachment_url);
175 175
 				$attachment_extension = $attachment_extension[1];
176 176
 				$tpl_component['ATTACHMENT_ITEM_GUID'] = $attachment_url;
177 177
 				$tpl_component['ATTACHMENT_ITEM_TITLE'] = $attachment->post_title;
178 178
 				$tpl_component['ATTACHMENT_ITEM_EXTENSION'] = $attachment_extension;
179
-				if(is_int(strpos($attachment->post_mime_type, 'application/')) || is_int(strpos($attachment->post_mime_type, 'text/'))) {
179
+				if (is_int(strpos($attachment->post_mime_type, 'application/')) || is_int(strpos($attachment->post_mime_type, 'text/'))) {
180 180
 					$tpl_component['ATTACHMENT_ITEM_TYPE'] = 'document';
181
-					$tpl_component['ATTACHMENT_ITEM_SPECIFIC_CLASS'] = (!($document_increment%WPSHOP_DISPLAY_GALLERY_ELEMENT_NUMBER_PER_LINE)) ? 'wpshop_gallery_document_last' : '';
181
+					$tpl_component['ATTACHMENT_ITEM_SPECIFIC_CLASS'] = (!($document_increment % WPSHOP_DISPLAY_GALLERY_ELEMENT_NUMBER_PER_LINE)) ? 'wpshop_gallery_document_last' : '';
182 182
 					/** Template parameters	*/
183 183
 					$template_part = 'product_attachment_item_document';
184 184
 					$tpl_component['PRODUCT_ID'] = $product_id;
185 185
 
186 186
 					/** Build template	*/
187 187
 					$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
188
-					if ( $tpl_way_to_take[0] && !empty($tpl_way_to_take[1]) ) {
188
+					if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
189 189
 						/*	Include the old way template part	*/
190 190
 
191 191
 						ob_start();
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 			}
205 205
 
206 206
 			ob_start();
207
-			require( wpshop_tools::get_template_part( WPS_MEDIA_MANAGER_DIR, WPS_MEDIA_MANAGER_TEMPLATE_DIR, 'frontend', 'associated', 'document' ) );
207
+			require(wpshop_tools::get_template_part(WPS_MEDIA_MANAGER_DIR, WPS_MEDIA_MANAGER_TEMPLATE_DIR, 'frontend', 'associated', 'document'));
208 208
 			$output = ob_get_contents();
209 209
 			ob_end_clean();
210 210
 		}
Please login to merge, or discard this patch.
Braces   +8 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 class wps_media_manager_frontend_ctr {
3 5
 
4 6
 	public static function get_attachments( $pid, $type = 'gallery' ) {
@@ -58,8 +60,7 @@  discard block
 block discarded – undo
58 60
 			require(wpshop_display::get_template_file($tpl_way_to_take[1]));
59 61
 			$galery_output = ob_get_contents();
60 62
 			ob_end_clean();
61
-		}
62
-		else {
63
+		} else {
63 64
 			$galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
64 65
 		}
65 66
 		unset($tpl_component);
@@ -84,8 +85,7 @@  discard block
 block discarded – undo
84 85
 			$principal_thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true);
85 86
 			if( !empty($principal_thumbnail_id) ) {
86 87
 				$attachments[0] = get_post( $principal_thumbnail_id );
87
-			}
88
-			else {
88
+			} else {
89 89
 				$sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL'] = '';
90 90
 				$sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
91 91
 				$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
@@ -127,8 +127,7 @@  discard block
 block discarded – undo
127 127
 								$sub_tpl_component['IMAGE_SLIDER_FULL'] = ( !empty($p) ) ? $p : '';
128 128
 								$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = ( !empty($p) ) ? $p : '';
129 129
 							}
130
-						}
131
-						else {
130
+						} else {
132 131
 							$p = wp_get_attachment_image( $attachment->ID, 'full' );
133 132
 							$src = wp_get_attachment_image_src( $attachment->ID, 'full' );
134 133
 							$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = ( !empty($src) ) ? $src[0] : '';
@@ -142,8 +141,7 @@  discard block
 block discarded – undo
142 141
 							}
143 142
 						}
144 143
 						unset( $sub_tpl_component );
145
-					}
146
-					else {
144
+					} else {
147 145
 						$sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = '';
148 146
 						$sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
149 147
 						$sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />';
@@ -192,8 +190,7 @@  discard block
 block discarded – undo
192 190
 						require(wpshop_display::get_template_file($tpl_way_to_take[1]));
193 191
 						$product_document_galery_content .= ob_get_contents();
194 192
 						ob_end_clean();
195
-					}
196
-					else {
193
+					} else {
197 194
 						$product_document_galery_content .= wpshop_display::display_template_element($template_part, $tpl_component);
198 195
 					}
199 196
 
Please login to merge, or discard this patch.
includes/modules/wps_message/controller/wps_message_ctr.php 3 patches
Doc Comments   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -299,7 +299,11 @@
 block discarded – undo
299 299
 	}
300 300
 
301 301
 	/** Store a new message
302
-	 * @return boolean
302
+	 * @param string $email
303
+	 * @param string $title
304
+	 * @param string $message
305
+	 * @param integer $model_id
306
+	 * @return boolean|null
303 307
 	 */
304 308
 	function add_message($recipient_id=0, $email, $title, $message, $model_id, $object, $date = null) {
305 309
 		$date = empty($date) ? current_time('mysql', 0) : $date;
Please login to merge, or discard this patch.
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 class wps_message_ctr {
3 3
 	/** Define the main directory containing the template for the current plugin
4 4
 	 * @var string
@@ -20,14 +20,14 @@  discard block
 block discarded – undo
20 20
 		$this->template_dir = WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . "/templates/";
21 21
 
22 22
 		// WP General actions
23
-		add_action( 'admin_init', array( $this, 'wps_messages_init_actions') );
24
-		add_action('add_meta_boxes', array( $this, 'add_meta_boxes') );
25
-		add_action('manage_'.WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE.'_posts_custom_column',  array( $this, 'messages_custom_columns'));
26
-		add_filter('manage_edit-'.WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE.'_columns', array( $this, 'messages_edit_columns'));
23
+		add_action('admin_init', array($this, 'wps_messages_init_actions'));
24
+		add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
25
+		add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_posts_custom_column', array($this, 'messages_custom_columns'));
26
+		add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '_columns', array($this, 'messages_edit_columns'));
27 27
 
28 28
 		// Shortcodes
29
-		add_shortcode( 'wps_message_histo', array( $this, 'display_message_histo_per_customer') );
30
-		add_shortcode( 'order_customer_personnal_informations', array( $this, 'order_personnal_informations') );
29
+		add_shortcode('wps_message_histo', array($this, 'display_message_histo_per_customer'));
30
+		add_shortcode('order_customer_personnal_informations', array($this, 'order_personnal_informations'));
31 31
 
32 32
 		/** Ajax */
33 33
 		add_action('wp_ajax_get_content_message', array($this, 'get_content_message'));
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 	public function enqueue_scripts() {
40 40
 		/** Css */
41 41
 		add_thickbox();
42
-		wp_register_style( 'wpeo-message-css', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/css/frontend.css', '', WPS_MESSAGE_VERSION );
43
-		wp_enqueue_style( 'wpeo-message-css' );
42
+		wp_register_style('wpeo-message-css', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/css/frontend.css', '', WPS_MESSAGE_VERSION);
43
+		wp_enqueue_style('wpeo-message-css');
44 44
 
45 45
 		/** My js */
46
-		wp_enqueue_script( 'wps-message-js', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/js/frontend.js', array("jquery", 'thickbox'), WPS_MESSAGE_VERSION);
46
+		wp_enqueue_script('wps-message-js', WPS_MESSAGE_URL . WPS_MESSAGE_DIR . '/assets/js/frontend.js', array("jquery", 'thickbox'), WPS_MESSAGE_VERSION);
47 47
 	}
48 48
 
49 49
 	/**
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 				'show_in_nav_menus' 		=> false,
85 85
 				'rewrite' 					=> false,
86 86
 				'query_var' 				=> true,
87
-				'supports' 					=> array('title','editor'),
87
+				'supports' 					=> array('title', 'editor'),
88 88
 				'has_archive' 				=> false
89 89
 		));
90 90
 	}
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		add_meta_box(
98 98
 		'wpshop_message_histo',
99 99
 		__('Message historic', 'wpshop'),
100
-		array( $this, 'message_histo_box'),
100
+		array($this, 'message_histo_box'),
101 101
 		WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, 'normal', 'high'
102 102
 		);
103 103
 	}
@@ -119,15 +119,15 @@  discard block
 block discarded – undo
119 119
 	 * @param  integer $message_type_id : Message type ID
120 120
 	 * @return string
121 121
 	 */
122
-	function get_historic_message_by_type( $message_type_id ) {
122
+	function get_historic_message_by_type($message_type_id) {
123 123
 		global $wpdb;
124 124
 		$output = '';
125
-		if ( !empty($message_type_id) ) {
125
+		if (!empty($message_type_id)) {
126 126
 			// Recover all sended messages
127 127
 			$wps_message_mdl = new wps_message_mdl();
128
-			$messages = $wps_message_mdl->get_messages_histo( $message_type_id );
128
+			$messages = $wps_message_mdl->get_messages_histo($message_type_id);
129 129
 			ob_start();
130
-			require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "backend", "message_historic") );
130
+			require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, "backend", "message_historic"));
131 131
 			$output .= ob_get_contents();
132 132
 			ob_end_clean();
133 133
 		}
@@ -139,13 +139,13 @@  discard block
 block discarded – undo
139 139
 	 */
140 140
 	public static function create_default_message() {
141 141
 		// Get default messages defined into xml files
142
-		$xml_default_emails = file_get_contents( WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml' );
143
-		$default_emails = new SimpleXMLElement( $xml_default_emails );
142
+		$xml_default_emails = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml');
143
+		$default_emails = new SimpleXMLElement($xml_default_emails);
144 144
 
145 145
 		//Read default emails for options creation
146
-		foreach ( $default_emails->xpath( '//emails/email' ) as $email ) {
147
-			if (  ( WPSHOP_DEFINED_SHOP_TYPE == (string)$email->attributes()->shop_type ) || ( 'sale' == WPSHOP_DEFINED_SHOP_TYPE ) ) {
148
-				self::createMessage( (string)$email->attributes()->code, (string)$email->subject, (string)$email->content );
146
+		foreach ($default_emails->xpath('//emails/email') as $email) {
147
+			if ((WPSHOP_DEFINED_SHOP_TYPE == (string)$email->attributes()->shop_type) || ('sale' == WPSHOP_DEFINED_SHOP_TYPE)) {
148
+				self::createMessage((string)$email->attributes()->code, (string)$email->subject, (string)$email->content);
149 149
 			}
150 150
 		}
151 151
 	}
@@ -157,24 +157,24 @@  discard block
 block discarded – undo
157 157
 	 * @param string $message : Message content
158 158
 	 * @return integer message ID
159 159
 	 */
160
-	public static function createMessage( $code, $object = "", $message = "" ) {
160
+	public static function createMessage($code, $object = "", $message = "") {
161 161
 		$id = 0;
162 162
 
163
-		$object = empty( $object ) ? constant( $code . '_OBJECT' ) : $object;
164
-		$message = empty( $message ) ? constant( $code ) : $message;
165
-		$message_option = get_option( $code, null );
163
+		$object = empty($object) ? constant($code . '_OBJECT') : $object;
164
+		$message = empty($message) ? constant($code) : $message;
165
+		$message_option = get_option($code, null);
166 166
 
167
-		if ( empty( $message_option ) && !empty( $object ) && !empty( $message ) ) {
167
+		if (empty($message_option) && !empty($object) && !empty($message)) {
168 168
 			$new_message = array(
169
-				'post_title' 	=> __( $object , 'wpshop'),
170
-				'post_content' 	=> self::customize_message( __( $message, 'wpshop' ) ),
169
+				'post_title' 	=> __($object, 'wpshop'),
170
+				'post_content' 	=> self::customize_message(__($message, 'wpshop')),
171 171
 				'post_status' 	=> 'publish',
172 172
 				'post_author' 	=> 1,
173 173
 				'post_type' 	=> WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE
174 174
 			);
175
-			$id = wp_insert_post( $new_message );
175
+			$id = wp_insert_post($new_message);
176 176
 
177
-			update_option( $code, $id );
177
+			update_option($code, $id);
178 178
 		}
179 179
 		else {
180 180
 			$id = $message_option;
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
 	function messages_custom_columns($column) {
191 191
 		global $post;
192 192
 		$metadata = get_post_custom();
193
-		switch($column){
193
+		switch ($column) {
194 194
 			case "extract":
195 195
 				echo wp_trim_words($post->post_content, 55);
196 196
 			break;
197 197
 			case "last_dispatch_date":
198
-				if(!empty($metadata['wpshop_message_last_dispatch_date'][0]))
199
-					echo mysql2date('d F Y, H:i:s',$metadata['wpshop_message_last_dispatch_date'][0], true);
198
+				if (!empty($metadata['wpshop_message_last_dispatch_date'][0]))
199
+					echo mysql2date('d F Y, H:i:s', $metadata['wpshop_message_last_dispatch_date'][0], true);
200 200
 				else
201 201
 					echo '-';
202 202
 			break;
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
 		$columns = array(
212 212
 				'cb' => '<input type="checkbox" />',
213 213
 				'title' => __('Name', 'wpshop'),
214
-				'extract' =>__('Extract from the message','wpshop'),
215
-				'date' => __('Creation date','wpshop'),
216
-				'last_dispatch_date' => __('Last dispatch date','wpshop')
214
+				'extract' =>__('Extract from the message', 'wpshop'),
215
+				'date' => __('Creation date', 'wpshop'),
216
+				'last_dispatch_date' => __('Last dispatch date', 'wpshop')
217 217
 		);
218 218
 
219 219
 		return $columns;
@@ -229,12 +229,12 @@  discard block
 block discarded – undo
229 229
 				'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE,
230 230
 				'posts_per_page' => '-1',
231 231
 		));
232
-		$options='';
232
+		$options = '';
233 233
 		if (!empty($posts)) {
234
-			$options = '<option value="0">' .__('Select values from list', 'wpshop'). '</option>';
234
+			$options = '<option value="0">' . __('Select values from list', 'wpshop') . '</option>';
235 235
 			foreach ($posts as $p) {
236
-				$selected = $p->ID==$current ? ' selected="selected"': '';
237
-				$options .= '<option value="'.$p->ID.'"'.$selected.'>'.$p->post_title.'</option>';
236
+				$selected = $p->ID == $current ? ' selected="selected"' : '';
237
+				$options .= '<option value="' . $p->ID . '"' . $selected . '>' . $p->post_title . '</option>';
238 238
 			}
239 239
 		}
240 240
 		wp_reset_query();
@@ -247,13 +247,13 @@  discard block
 block discarded – undo
247 247
 	 * @param integer $customer_id : ID to identifiate the customer
248 248
 	 * @return string
249 249
 	 */
250
-	function display_message_histo_per_customer( $args, $customer_id = '' ) {
251
-		$customer_id = ( !empty($customer_id) ) ? $customer_id : get_current_user_id();
252
-		$message_id = ( !empty($args) && !empty($args['message_id']) ) ? $args['message_id'] : '';
250
+	function display_message_histo_per_customer($args, $customer_id = '') {
251
+		$customer_id = (!empty($customer_id)) ? $customer_id : get_current_user_id();
252
+		$message_id = (!empty($args) && !empty($args['message_id'])) ? $args['message_id'] : '';
253 253
 		$message_elements = '';
254 254
 
255 255
 		$wps_message_mdl = new wps_message_mdl();
256
-		$messages_data = $wps_message_mdl->get_messages_histo( $message_id, $customer_id );
256
+		$messages_data = $wps_message_mdl->get_messages_histo($message_id, $customer_id);
257 257
 
258 258
 // 		ob_start();
259 259
 // 		require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "frontend", "messages") );
@@ -262,21 +262,21 @@  discard block
 block discarded – undo
262 262
 
263 263
 		/**	Order emails	*/
264 264
 		$messages_histo = array();
265
-		foreach( $messages_data as $meta_id => $messages ) :
265
+		foreach ($messages_data as $meta_id => $messages) :
266 266
 			$i = 0;
267
-			foreach ( $messages as $message ) :
268
-				$messages_histo[ $message[ 'mess_dispatch_date' ][ 0 ] ][ $i ][ 'title' ] = $message[ 'mess_title' ];
269
-				$messages_histo[ $message[ 'mess_dispatch_date' ][ 0 ] ][ $i ][ 'message' ] = $message[ 'mess_message' ];
270
-				$messages_histo[ $message[ 'mess_dispatch_date' ][ 0 ] ][ $i ][ 'dates' ] = $message[ 'mess_dispatch_date' ];
271
-				if ( !empty( $message[ 'mess_object_id' ] ) ) {
272
-					$messages_histo[ $message[ 'mess_dispatch_date' ][ 0 ] ][ $i ][ 'object' ] = $message[ 'mess_object_id' ];
267
+			foreach ($messages as $message) :
268
+				$messages_histo[$message['mess_dispatch_date'][0]][$i]['title'] = $message['mess_title'];
269
+				$messages_histo[$message['mess_dispatch_date'][0]][$i]['message'] = $message['mess_message'];
270
+				$messages_histo[$message['mess_dispatch_date'][0]][$i]['dates'] = $message['mess_dispatch_date'];
271
+				if (!empty($message['mess_object_id'])) {
272
+					$messages_histo[$message['mess_dispatch_date'][0]][$i]['object'] = $message['mess_object_id'];
273 273
 				}
274 274
 				$i++;
275 275
 			endforeach;
276 276
 		endforeach;
277
-		ksort( $messages_histo );
277
+		ksort($messages_histo);
278 278
 		ob_start();
279
-		require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "frontend", "customer", "messages") );
279
+		require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, "frontend", "customer", "messages"));
280 280
 		$output = ob_get_contents();
281 281
 		ob_end_clean();
282 282
 
@@ -288,10 +288,10 @@  discard block
 block discarded – undo
288 288
 	 * @param string $message : message content
289 289
 	 * @return string
290 290
 	 */
291
-	public static function customize_message( $message ) {
292
-		if( !empty($message) ) {
291
+	public static function customize_message($message) {
292
+		if (!empty($message)) {
293 293
 			ob_start();
294
-			require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . '/templates/', "backend", "message_html_structure") );
294
+			require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, WPS_MESSAGE_PATH . WPS_MESSAGE_DIR . '/templates/', "backend", "message_html_structure"));
295 295
 			$message = ob_get_contents();
296 296
 			ob_end_clean();
297 297
 		}
@@ -301,12 +301,12 @@  discard block
 block discarded – undo
301 301
 	/** Store a new message
302 302
 	 * @return boolean
303 303
 	 */
304
-	function add_message($recipient_id=0, $email, $title, $message, $model_id, $object, $date = null) {
304
+	function add_message($recipient_id = 0, $email, $title, $message, $model_id, $object, $date = null) {
305 305
 		$date = empty($date) ? current_time('mysql', 0) : $date;
306
-		$object_empty = array('object_type'=>'','object_id'=>0);
306
+		$object_empty = array('object_type'=>'', 'object_id'=>0);
307 307
 		$object = array_merge($object_empty, $object);
308 308
 
309
-		$historic = get_post_meta($recipient_id, '_wpshop_messages_histo_' .$model_id. '_' .substr($date, 0, 7), true);
309
+		$historic = get_post_meta($recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr($date, 0, 7), true);
310 310
 		$data_to_insert = array(
311 311
 				'mess_user_id' => $recipient_id,
312 312
 				'mess_user_email' => $email,
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 		);
319 319
 		$historic[] = $data_to_insert;
320 320
 
321
-		update_post_meta($recipient_id, '_wpshop_messages_histo_' .$model_id. '_' .substr($date, 0, 7), $historic);
321
+		update_post_meta($recipient_id, '_wpshop_messages_histo_' . $model_id . '_' . substr($date, 0, 7), $historic);
322 322
 	}
323 323
 
324 324
 	/**
@@ -329,37 +329,37 @@  discard block
 block discarded – undo
329 329
 	 * @param boolean $duplicate_message : Duplicate a light message for historic storage
330 330
 	 * @return string
331 331
 	 */
332
-	function customMessage($string, $data, $model_name='', $duplicate_message=false) {
332
+	function customMessage($string, $data, $model_name = '', $duplicate_message = false) {
333 333
 		$avant = array();
334 334
 		$apres = array();
335 335
 
336
-		$logo_option = get_option( 'wpshop_logo' );
336
+		$logo_option = get_option('wpshop_logo');
337 337
 
338
-		$data['your_shop_logo'] = ( !empty($logo_option) ) ? '<img src="'.$logo_option.'" alt="' .get_bloginfo('name'). '" />' : '';
338
+		$data['your_shop_logo'] = (!empty($logo_option)) ? '<img src="' . $logo_option . '" alt="' . get_bloginfo('name') . '" />' : '';
339 339
 
340
-		foreach($data as $key => $value) {
341
-			$avant[] = '['.$key.']';
340
+		foreach ($data as $key => $value) {
341
+			$avant[] = '[' . $key . ']';
342 342
 			switch ($key) {
343 343
 				case 'order_content' :
344
-					$apres[] = ( $duplicate_message ) ? '[order_content]' : $this->order_content_template_for_mail ( $data['order_id'] );
344
+					$apres[] = ($duplicate_message) ? '[order_content]' : $this->order_content_template_for_mail($data['order_id']);
345 345
 					break;
346 346
 				case 'order_addresses' :
347
-					$apres[] = ( $duplicate_message ) ? '[order_addresses]' : $this->order_addresses_template_for_mail ( $data['order_id'] );
347
+					$apres[] = ($duplicate_message) ? '[order_addresses]' : $this->order_addresses_template_for_mail($data['order_id']);
348 348
 					break;
349 349
 
350 350
 				case 'order_billing_address' :
351
-					$apres[] = ( $duplicate_message ) ? '[order_billing_address]' : $this->order_addresses_template_for_mail ( $data['order_id'], 'billing' );
351
+					$apres[] = ($duplicate_message) ? '[order_billing_address]' : $this->order_addresses_template_for_mail($data['order_id'], 'billing');
352 352
 					break;
353 353
 
354 354
 				case 'order_shipping_address' :
355
-					$apres[] = ( $duplicate_message ) ? '[order_shipping_address]' : $this->order_addresses_template_for_mail ( $data['order_id'], 'shipping' );
355
+					$apres[] = ($duplicate_message) ? '[order_shipping_address]' : $this->order_addresses_template_for_mail($data['order_id'], 'shipping');
356 356
 					break;
357 357
 
358 358
 				case 'order_customer_comments' :
359
-					$apres[] = ( $duplicate_message ) ? '[order_customer_comments]' : $this->order_customer_comment_template_for_mail ( $data['order_id'] );
359
+					$apres[] = ($duplicate_message) ? '[order_customer_comments]' : $this->order_customer_comment_template_for_mail($data['order_id']);
360 360
 					break;
361 361
 				case 'order_personnal_informations' :
362
-					$apres[] = ( $duplicate_message ) ? '[order_personnal_informations]' : $this->order_personnal_informations();
362
+					$apres[] = ($duplicate_message) ? '[order_personnal_informations]' : $this->order_personnal_informations();
363 363
 					break;
364 364
 				default :
365 365
 					$apres[] = $value;
@@ -368,9 +368,9 @@  discard block
 block discarded – undo
368 368
 		}
369 369
 		$string = str_replace($avant, $apres, $string);
370 370
 
371
-		$string = apply_filters( 'wps_more_customized_message', $string, $data, $duplicate_message );
371
+		$string = apply_filters('wps_more_customized_message', $string, $data, $duplicate_message);
372 372
 
373
-		if ( ($model_name != 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE') ) {
373
+		if (($model_name != 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE')) {
374 374
 			$string = preg_replace("/\[(.*)\]/Usi", '', $string);
375 375
 		}
376 376
 
@@ -385,21 +385,21 @@  discard block
 block discarded – undo
385 385
 	 * @param string $object : message object
386 386
 	 * @param file $attached_file : File to attached to e-mail
387 387
 	 */
388
-	function wpshop_prepared_email($email, $model_name, $data=array(), $object=array(), $attached_file = '') {
388
+	function wpshop_prepared_email($email, $model_name, $data = array(), $object = array(), $attached_file = '') {
389 389
 		global $wpdb;
390
-		$data = apply_filters( 'wps_extra_data_to_send_in_email', $data );
390
+		$data = apply_filters('wps_extra_data_to_send_in_email', $data);
391 391
 		$model_id = get_option($model_name, 0);
392
-		$query = $wpdb->prepare( 'SELECT * FROM ' .$wpdb->posts. ' WHERE ID = %s', $model_id);
393
-		$post_message = $wpdb->get_row( $query );
392
+		$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE ID = %s', $model_id);
393
+		$post_message = $wpdb->get_row($query);
394 394
 		$duplicate_message = '';
395
-		if ( !empty($post_message) ) {
395
+		if (!empty($post_message)) {
396 396
 			$title = $this->customMessage($post_message->post_title, $data, $model_name);
397 397
 			$message = $this->customMessage($post_message->post_content, $data, $model_name);
398 398
 			/* On envoie le mail */
399
-			if ( array_key_exists('order_content', $data) || array_key_exists('order_addresses', $data) || array_key_exists('order_customer_comments', $data) ) {
399
+			if (array_key_exists('order_content', $data) || array_key_exists('order_addresses', $data) || array_key_exists('order_customer_comments', $data)) {
400 400
 				$duplicate_message = $this->customMessage($post_message->post_content, $data, $model_name, true);
401 401
 			}
402
-			if ( !empty($email) ) {
402
+			if (!empty($email)) {
403 403
 				$this->wpshop_email($email, $title, $message, true, $model_id, $object, $attached_file, $duplicate_message);
404 404
 			}
405 405
 		}
@@ -419,17 +419,17 @@  discard block
 block discarded – undo
419 419
 	function wpshop_email($email, $title, $message, $save = true, $model_id, $object = array(), $attachments = '', $duplicate_message = '') {
420 420
 		global $wpdb;
421 421
 		// Sauvegarde
422
-		if($save) {
423
-			$user = $wpdb->get_row('SELECT ID FROM '.$wpdb->users.' WHERE user_email="'.$email.'";');
422
+		if ($save) {
423
+			$user = $wpdb->get_row('SELECT ID FROM ' . $wpdb->users . ' WHERE user_email="' . $email . '";');
424 424
 			$user_id = $user ? $user->ID : get_current_user_id();
425
-			$query = $wpdb->prepare('SELECT ID FROM ' .$wpdb->posts. ' WHERE post_author = %d AND post_type = %s ', $user_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
426
-			$user_post_id = $wpdb->get_var( $query );
425
+			$query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s ', $user_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
426
+			$user_post_id = $wpdb->get_var($query);
427 427
 
428
-			if ( !empty($duplicate_message) ) {
429
-				$this->add_message( $user_post_id, $email, $title, $duplicate_message, $model_id, $object );
428
+			if (!empty($duplicate_message)) {
429
+				$this->add_message($user_post_id, $email, $title, $duplicate_message, $model_id, $object);
430 430
 			}
431 431
 			else {
432
-				$this->add_message( $user_post_id, $email, $title, $message, $model_id, $object );
432
+				$this->add_message($user_post_id, $email, $title, $message, $model_id, $object);
433 433
 			}
434 434
 
435 435
 		}
@@ -437,19 +437,19 @@  discard block
 block discarded – undo
437 437
 		$emails = get_option('wpshop_emails', array());
438 438
 		$noreply_email = $emails['noreply_email'];
439 439
 		// Split the email to get the name
440
-		$vers_nom = substr($email, 0, strpos($email,'@'));
440
+		$vers_nom = substr($email, 0, strpos($email, '@'));
441 441
 
442 442
 		// Headers du mail
443 443
 		$headers = "MIME-Version: 1.0\r\n";
444 444
 		$headers .= "Content-type: text/html; charset=UTF-8\r\n";
445
-		$headers .= 'From: '.get_bloginfo('name').' <'.$noreply_email.'>' . "\r\n";
445
+		$headers .= 'From: ' . get_bloginfo('name') . ' <' . $noreply_email . '>' . "\r\n";
446 446
 
447 447
 		// Mail en HTML
448 448
 		@wp_mail($email, $title, $message, $headers, $attachments);
449 449
 
450 450
 
451
-		if ( !empty($attachments) ) {
452
-			unlink( $attachments );
451
+		if (!empty($attachments)) {
452
+			unlink($attachments);
453 453
 		}
454 454
 	}
455 455
 
@@ -458,13 +458,13 @@  discard block
 block discarded – undo
458 458
 	 * @param integer $order_id : Order ID
459 459
 	 * @return string
460 460
 	 */
461
-	function order_content_template_for_mail ( $order_id ) {
461
+	function order_content_template_for_mail($order_id) {
462 462
 		$message = '';
463
-		if ( !empty($order_id) ) {
463
+		if (!empty($order_id)) {
464 464
 			$currency_code = wpshop_tools::wpshop_get_currency(false);
465 465
 			$orders_infos = get_post_meta($order_id, '_order_postmeta', true);
466 466
 			ob_start();
467
-			require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_content_mail_template" ) );
467
+			require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_content_mail_template"));
468 468
 			$message .= ob_get_contents();
469 469
 			ob_end_clean();
470 470
 		}
@@ -477,44 +477,44 @@  discard block
 block discarded – undo
477 477
 	 * @param integer $address_type : Address type ID
478 478
 	 * @return string
479 479
 	 */
480
-	function order_addresses_template_for_mail ( $order_id, $address_type = '' ) {
480
+	function order_addresses_template_for_mail($order_id, $address_type = '') {
481 481
 		global $wpdb;
482
-		$shipping_option = get_option( 'wpshop_shipping_address_choice' );
483
-		$display_shipping = ( !empty($shipping_option) && !empty($shipping_option['activate']) ) ? true : false;
482
+		$shipping_option = get_option('wpshop_shipping_address_choice');
483
+		$display_shipping = (!empty($shipping_option) && !empty($shipping_option['activate'])) ? true : false;
484 484
 		$message = '';
485
-		if ( !empty($order_id) ) {
485
+		if (!empty($order_id)) {
486 486
 			$order_addresses = get_post_meta($order_id, '_order_info', true);
487
-			if ( !empty($order_addresses) ) {
488
-				foreach ( $order_addresses as $key=>$order_address ) {
489
-					if ( !empty($order_address) && ( empty($address_type) || $address_type == $key ) ) {
487
+			if (!empty($order_addresses)) {
488
+				foreach ($order_addresses as $key=>$order_address) {
489
+					if (!empty($order_address) && (empty($address_type) || $address_type == $key)) {
490 490
 
491
-						if( $key != 'shipping' || ($key == 'shipping' && $display_shipping) ) {
492
-							$address_type_title = ( !empty($key) && $key == 'billing' ) ? __('Billing address', 'wpshop') : __('Shipping address', 'wpshop');
491
+						if ($key != 'shipping' || ($key == 'shipping' && $display_shipping)) {
492
+							$address_type_title = (!empty($key) && $key == 'billing') ? __('Billing address', 'wpshop') : __('Shipping address', 'wpshop');
493 493
 							$civility = '';
494
-							if ( !empty($order_address['address']['civility']) ) {
495
-								$query = $wpdb->prepare('SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $order_address['address']['civility']);
496
-								$civility = $wpdb->get_var( $query );
494
+							if (!empty($order_address['address']['civility'])) {
495
+								$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $order_address['address']['civility']);
496
+								$civility = $wpdb->get_var($query);
497 497
 							}
498 498
 
499 499
 							// Address informations
500
-							$customer_last_name = (!empty($order_address['address']['address_last_name']) ) ? $order_address['address']['address_last_name'] : '';
501
-							$customer_firtsname = (!empty($order_address['address']['address_first_name']) ) ? $order_address['address']['address_first_name'] : '';
502
-							$customer_company = (!empty($order_address['address']['company']) ) ? $order_address['address']['company'] : '';
503
-							$customer_address = (!empty($order_address['address']['address']) ) ? $order_address['address']['address'] : '';
504
-							$customer_zip_code = (!empty($order_address['address']['postcode']) ) ? $order_address['address']['postcode'] : '';
505
-							$customer_city = (!empty($order_address['address']['city']) ) ? $order_address['address']['city'] : '';
506
-							$customer_state = (!empty($order_address['address']['state']) ) ? $order_address['address']['state'] : '';
507
-							$customer_phone = (!empty($order_address['address']['phone']) ) ? ' Tel. : '.$order_address['address']['phone'] : '';
500
+							$customer_last_name = (!empty($order_address['address']['address_last_name'])) ? $order_address['address']['address_last_name'] : '';
501
+							$customer_firtsname = (!empty($order_address['address']['address_first_name'])) ? $order_address['address']['address_first_name'] : '';
502
+							$customer_company = (!empty($order_address['address']['company'])) ? $order_address['address']['company'] : '';
503
+							$customer_address = (!empty($order_address['address']['address'])) ? $order_address['address']['address'] : '';
504
+							$customer_zip_code = (!empty($order_address['address']['postcode'])) ? $order_address['address']['postcode'] : '';
505
+							$customer_city = (!empty($order_address['address']['city'])) ? $order_address['address']['city'] : '';
506
+							$customer_state = (!empty($order_address['address']['state'])) ? $order_address['address']['state'] : '';
507
+							$customer_phone = (!empty($order_address['address']['phone'])) ? ' Tel. : ' . $order_address['address']['phone'] : '';
508 508
 							$country = '';
509
-							foreach ( unserialize(WPSHOP_COUNTRY_LIST) as $key => $value ) {
510
-								if ( !empty($order_address['address']['country']) && $key ==  $order_address['address']['country']) {
509
+							foreach (unserialize(WPSHOP_COUNTRY_LIST) as $key => $value) {
510
+								if (!empty($order_address['address']['country']) && $key == $order_address['address']['country']) {
511 511
 									$country = $value;
512 512
 								}
513 513
 							}
514 514
 							$customer_country = $country;
515 515
 
516 516
 							ob_start();
517
-							require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_addresses_template_for_mail") );
517
+							require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_addresses_template_for_mail"));
518 518
 							$message .= ob_get_contents();
519 519
 							ob_end_clean();
520 520
 						}
@@ -530,21 +530,21 @@  discard block
 block discarded – undo
530 530
 	 * @param integer $order_id : Order ID
531 531
 	 * @return string
532 532
 	 */
533
-	function order_customer_comment_template_for_mail ( $order_id ) {
533
+	function order_customer_comment_template_for_mail($order_id) {
534 534
 		global $wpdb;
535 535
 		$message = '';
536
-		if ( !empty($order_id) ) {
537
-			$query = $wpdb->prepare('SELECT post_excerpt FROM ' .$wpdb->posts. ' WHERE ID = %d', $order_id);
538
-			$comment = $wpdb->get_var( $query );
536
+		if (!empty($order_id)) {
537
+			$query = $wpdb->prepare('SELECT post_excerpt FROM ' . $wpdb->posts . ' WHERE ID = %d', $order_id);
538
+			$comment = $wpdb->get_var($query);
539 539
 			$order_infos = get_post_meta($order_id, '_order_postmeta', true);
540
-			if ( !empty($order_infos['order_key']) ) {
541
-				$comment_title =  __('Comments about the order', 'wpshop');
540
+			if (!empty($order_infos['order_key'])) {
541
+				$comment_title = __('Comments about the order', 'wpshop');
542 542
 			}
543 543
 			else {
544
-				$comment_title =  __('Comments about the quotation', 'wpshop');
544
+				$comment_title = __('Comments about the quotation', 'wpshop');
545 545
 			}
546 546
 			ob_start();
547
-			require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_email_customer_comments") );
547
+			require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_email_customer_comments"));
548 548
 			$message .= ob_get_contents();
549 549
 			ob_end_clean();
550 550
 		}
@@ -559,15 +559,15 @@  discard block
 block discarded – undo
559 559
 		global $wpdb;
560 560
 		$user_id = get_current_user_id();
561 561
 		$message = '';
562
-		$customer_entity = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS );
563
-		if( !empty($customer_entity) ) {
562
+		$customer_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
563
+		if (!empty($customer_entity)) {
564 564
 
565
-			$query = $wpdb->prepare( 'SELECT * FROM '.WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE entity_id = %d AND status = %s', $customer_entity, 'valid' );
566
-			$attributes_sets = $wpdb->get_results( $query );
565
+			$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s', $customer_entity, 'valid');
566
+			$attributes_sets = $wpdb->get_results($query);
567 567
 
568
-			if( !empty($attributes_sets) ) {
568
+			if (!empty($attributes_sets)) {
569 569
 				ob_start();
570
-				require( wpshop_tools::get_template_part( WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_personnal_informations_template_for_mail") );
570
+				require(wpshop_tools::get_template_part(WPS_MESSAGE_DIR, $this->template_dir, "backend/mails", "order_personnal_informations_template_for_mail"));
571 571
 				$message .= ob_get_contents();
572 572
 				ob_end_clean();
573 573
 			}
@@ -578,15 +578,15 @@  discard block
 block discarded – undo
578 578
 	/**
579 579
 	 * Support historic messages
580 580
 	 */
581
-	function wpshop_messages_historic_correction () {
581
+	function wpshop_messages_historic_correction() {
582 582
 		global $wpdb;
583
-		$query = $wpdb->prepare('SELECT * FROM ' .$wpdb->postmeta. ' WHERE meta_key LIKE %s', '_wpshop_messages_histo_%');
584
-		$messages_histo = $wpdb->get_results( $query );
583
+		$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s', '_wpshop_messages_histo_%');
584
+		$messages_histo = $wpdb->get_results($query);
585 585
 
586
-		foreach ( $messages_histo as $message ) {
587
-			$query_user = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_author = %d AND post_type = %s',  $message->post_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
588
-			$user_post_id = $wpdb->get_var( $query_user );
589
-			$wpdb->update($wpdb->postmeta, array('post_id' => $user_post_id ), array('meta_id' => $message->meta_id ) );
586
+		foreach ($messages_histo as $message) {
587
+			$query_user = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_author = %d AND post_type = %s', $message->post_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
588
+			$user_post_id = $wpdb->get_var($query_user);
589
+			$wpdb->update($wpdb->postmeta, array('post_id' => $user_post_id), array('meta_id' => $message->meta_id));
590 590
 		}
591 591
 	}
592 592
 
@@ -595,9 +595,9 @@  discard block
 block discarded – undo
595 595
 	 * Récupères le contenu du message
596 596
 	 */
597 597
 	public function get_content_message() {
598
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
598
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
599 599
 
600
-		if ( !wp_verify_nonce( $_wpnonce, 'get_content_message' ) )
600
+		if (!wp_verify_nonce($_wpnonce, 'get_content_message'))
601 601
 			wp_die();
602 602
 
603 603
 		global $wpdb;
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 		$result = unserialize($result[0]->meta_value);
608 608
 		$result = $result[0]['mess_message'];
609 609
 
610
-		wp_die( $result );
610
+		wp_die($result);
611 611
 	}
612 612
 
613 613
 }
Please login to merge, or discard this patch.
Braces   +14 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 class wps_message_ctr {
3 5
 	/** Define the main directory containing the template for the current plugin
4 6
 	 * @var string
@@ -175,8 +177,7 @@  discard block
 block discarded – undo
175 177
 			$id = wp_insert_post( $new_message );
176 178
 
177 179
 			update_option( $code, $id );
178
-		}
179
-		else {
180
+		} else {
180 181
 			$id = $message_option;
181 182
 		}
182 183
 
@@ -195,10 +196,11 @@  discard block
 block discarded – undo
195 196
 				echo wp_trim_words($post->post_content, 55);
196 197
 			break;
197 198
 			case "last_dispatch_date":
198
-				if(!empty($metadata['wpshop_message_last_dispatch_date'][0]))
199
-					echo mysql2date('d F Y, H:i:s',$metadata['wpshop_message_last_dispatch_date'][0], true);
200
-				else
201
-					echo '-';
199
+				if(!empty($metadata['wpshop_message_last_dispatch_date'][0])) {
200
+									echo mysql2date('d F Y, H:i:s',$metadata['wpshop_message_last_dispatch_date'][0], true);
201
+				} else {
202
+									echo '-';
203
+				}
202 204
 			break;
203 205
 		}
204 206
 	}
@@ -427,8 +429,7 @@  discard block
 block discarded – undo
427 429
 
428 430
 			if ( !empty($duplicate_message) ) {
429 431
 				$this->add_message( $user_post_id, $email, $title, $duplicate_message, $model_id, $object );
430
-			}
431
-			else {
432
+			} else {
432 433
 				$this->add_message( $user_post_id, $email, $title, $message, $model_id, $object );
433 434
 			}
434 435
 
@@ -539,8 +540,7 @@  discard block
 block discarded – undo
539 540
 			$order_infos = get_post_meta($order_id, '_order_postmeta', true);
540 541
 			if ( !empty($order_infos['order_key']) ) {
541 542
 				$comment_title =  __('Comments about the order', 'wpshop');
542
-			}
543
-			else {
543
+			} else {
544 544
 				$comment_title =  __('Comments about the quotation', 'wpshop');
545 545
 			}
546 546
 			ob_start();
@@ -597,8 +597,9 @@  discard block
 block discarded – undo
597 597
 	public function get_content_message() {
598 598
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
599 599
 
600
-		if ( !wp_verify_nonce( $_wpnonce, 'get_content_message' ) )
601
-			wp_die();
600
+		if ( !wp_verify_nonce( $_wpnonce, 'get_content_message' ) ) {
601
+					wp_die();
602
+		}
602 603
 
603 604
 		global $wpdb;
604 605
 		$meta_id = (int)$_GET['meta_id'];
Please login to merge, or discard this patch.
includes/modules/wps_orders/controller/wps_orders_ctr.php 3 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		/**
130 130
 		 *	Build an array with the different items to add to an order
131 131
 		 *
132
-		 *	@param array $products The item list to add to the order
132
+		 *	@param array $product The item list to add to the order
133 133
 		 *
134 134
 		 *	@return array $item_list The item to add to order
135 135
 		 */
@@ -321,6 +321,9 @@  discard block
 block discarded – undo
321 321
 			wp_die();
322 322
 		}
323 323
 
324
+		/**
325
+		 * @param integer $order_id
326
+		 */
324 327
 		function pay_quotation( $order_id ) {
325 328
 			$status = true;
326 329
 			$order_meta = get_post_meta( $order_id, '_order_postmeta', true );
Please login to merge, or discard this patch.
Spacing   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 class wps_orders_ctr {
3 3
 	/** Define the main directory containing the template for the current plugin
4 4
 	 * @var string
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
 			/** Template Load **/
18 18
 // 			add_filter( 'wpshop_custom_template', array( &$this, 'custom_template_load' ) );
19 19
 
20
-			add_shortcode( 'order_customer_informations', array( &$this, 'display_order_customer_informations' ) );
21
-			add_shortcode( 'wps_orders_in_customer_account', array($this, 'display_orders_in_account') );
20
+			add_shortcode('order_customer_informations', array(&$this, 'display_order_customer_informations'));
21
+			add_shortcode('wps_orders_in_customer_account', array($this, 'display_orders_in_account'));
22 22
 
23
-			add_action( 'wp_enqueue_scripts', array( $this, 'wps_orders_scripts') );
23
+			add_action('wp_enqueue_scripts', array($this, 'wps_orders_scripts'));
24 24
 			/**	Include the different javascript	*/
25
-			add_action( 'admin_init', array(&$this, 'admin_js') );
25
+			add_action('admin_init', array(&$this, 'admin_js'));
26 26
 
27 27
 
28 28
 			/** Ajax Actions **/
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
 // 			add_action( 'wap_ajax_wps_orders_load_variations_container', array( &$this, 'wps_orders_load_variations_container') );
33 33
 // 			add_action( 'wap_ajax_wps_order_refresh_in_admin', array( &$this, 'wps_order_refresh_in_admin') );
34 34
 
35
-			add_action( 'wp_ajax_wps_orders_load_details', array( $this, 'wps_orders_load_details') );
35
+			add_action('wp_ajax_wps_orders_load_details', array($this, 'wps_orders_load_details'));
36 36
 
37 37
 			// Add a product sale historic in administration product panel
38
-			add_action( 'wp_ajax_wps_order_choose_customer', array( $this, 'wps_order_choose_customer' ) );
38
+			add_action('wp_ajax_wps_order_choose_customer', array($this, 'wps_order_choose_customer'));
39 39
 
40 40
 			/** For delete order */
41
-			add_action( 'wp_ajax_wps_delete_order', array( $this, 'wps_delete_order' ) );
41
+			add_action('wp_ajax_wps_delete_order', array($this, 'wps_delete_order'));
42 42
 
43 43
 			/** For pay billing */
44
-			add_action( 'wp_ajax_wps_checkout_quotation', array( $this, 'wps_checkout_quotation' ) );
45
-			add_action( 'wp_ajax_nopriv_wps_checkout_quotation', array( $this, 'wps_checkout_quotation_no_login' ) );
44
+			add_action('wp_ajax_wps_checkout_quotation', array($this, 'wps_checkout_quotation'));
45
+			add_action('wp_ajax_nopriv_wps_checkout_quotation', array($this, 'wps_checkout_quotation_no_login'));
46 46
 
47 47
 		}
48 48
 
@@ -58,24 +58,24 @@  discard block
 block discarded – undo
58 58
 		 * Add scripts
59 59
 		 */
60 60
 		function wps_orders_scripts() {
61
-			wp_enqueue_script( 'wps_orders_fronend', WPS_ORDERS_URL.WPS_ORDERS_DIR.'/assets/frontend/js/wps_orders.js' );
61
+			wp_enqueue_script('wps_orders_fronend', WPS_ORDERS_URL . WPS_ORDERS_DIR . '/assets/frontend/js/wps_orders.js');
62 62
 		}
63 63
 
64 64
 		function display_order_customer_informations() {
65 65
 			global $post_id; global $wpdb;
66 66
 			$output = '';
67
-			if ( !empty($post_id) ) {
68
-				$order_postmeta = get_post_meta( $post_id, '_order_postmeta', true );
69
-				$order_info = get_post_meta( $post_id, '_order_info', true );
67
+			if (!empty($post_id)) {
68
+				$order_postmeta = get_post_meta($post_id, '_order_postmeta', true);
69
+				$order_info = get_post_meta($post_id, '_order_info', true);
70 70
 
71 71
 				/** Check the order status **/
72
-				if ( !empty($order_postmeta) ) {
73
-					if ( !empty($order_postmeta['order_status'])  && $order_postmeta['order_status'] != 'awaiting_payment' ) {
74
-						$output = wps_address::display_an_address( $order_info['billing']['address'] );
75
-						$output .= wps_address::display_an_address( $order_info['shipping']['address'] );
72
+				if (!empty($order_postmeta)) {
73
+					if (!empty($order_postmeta['order_status']) && $order_postmeta['order_status'] != 'awaiting_payment') {
74
+						$output = wps_address::display_an_address($order_info['billing']['address']);
75
+						$output .= wps_address::display_an_address($order_info['shipping']['address']);
76 76
 					}
77 77
 					else {
78
-						$output = wps_address::display_an_address( $order_info['billing']['address'] );
78
+						$output = wps_address::display_an_address($order_info['billing']['address']);
79 79
 					}
80 80
 				}
81 81
 			}
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 							'blog_id'                 => $GLOBALS['blog_id'],
100 100
 							'who'                     => null // string
101 101
 						);
102
-				$tpl_component['CUSTOMERS_LIST'] = wp_dropdown_users( $args );
102
+				$tpl_component['CUSTOMERS_LIST'] = wp_dropdown_users($args);
103 103
 				$output = wpshop_display::display_template_element('wps_orders_choose_customer_interface', $tpl_component, array(), 'admin');
104 104
 			}
105 105
 			return $output;
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
110 110
 		 * @param integer $customer_id
111 111
 		 * @return string
112 112
 		 */
113
-		function display_orders_in_account( $customer_id = '' ) {
113
+		function display_orders_in_account($customer_id = '') {
114 114
 			$output = '';
115
-			$customer_id = ( !empty($customer_id) ) ? $customer_id : get_current_user_id();
116
-			$from_admin = ( !empty($customer_id) ) ? true : false;
115
+			$customer_id = (!empty($customer_id)) ? $customer_id : get_current_user_id();
116
+			$from_admin = (!empty($customer_id)) ? true : false;
117 117
 			$wps_orders_mdl = new wps_orders_mdl();
118
-			$orders = $wps_orders_mdl->get_customer_orders( $customer_id );
118
+			$orders = $wps_orders_mdl->get_customer_orders($customer_id);
119 119
 
120 120
 			// Display orders
121 121
 			ob_start();
122
-			require_once( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "frontend", "orders_list_in_account") );
122
+			require_once(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "frontend", "orders_list_in_account"));
123 123
 			$output = ob_get_contents();
124 124
 			ob_end_clean();
125 125
 
@@ -133,26 +133,26 @@  discard block
 block discarded – undo
133 133
 		 *
134 134
 		 *	@return array $item_list The item to add to order
135 135
 		 */
136
-		function add_product_to_order( $product ) {
136
+		function add_product_to_order($product) {
137 137
 			global $wpdb;
138 138
 
139
-			if( !empty($product) && empty($product['price_ttc_before_discount']) && empty($product['price_ht_before_discount']) ) {
140
-				$price_infos = wpshop_prices::check_product_price( $product, true );
141
-				$product['price_ht'] = ( !empty($price_infos['discount']) &&  !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ?  $price_infos['discount']['discount_et_price'] : $price_infos['et'];
142
-				$product['product_price'] = ( !empty($price_infos['discount']) &&  !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati'];
143
-				$product['tva'] = ( !empty($price_infos['discount']) &&  !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva'];
139
+			if (!empty($product) && empty($product['price_ttc_before_discount']) && empty($product['price_ht_before_discount'])) {
140
+				$price_infos = wpshop_prices::check_product_price($product, true);
141
+				$product['price_ht'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_et_price'] : $price_infos['et'];
142
+				$product['product_price'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati'];
143
+				$product['tva'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva'];
144 144
 			}
145 145
 
146
-			$price_piloting = get_option( 'wpshop_shop_price_piloting' );
146
+			$price_piloting = get_option('wpshop_shop_price_piloting');
147 147
 
148
-			if ( !empty($price_piloting) && $price_piloting == 'HT') {
148
+			if (!empty($price_piloting) && $price_piloting == 'HT') {
149 149
 				$total_ht = $product['price_ht'] * $product['product_qty'];
150
-				$tva_total_amount = $total_ht * ( $product['tx_tva'] / 100 );
150
+				$tva_total_amount = $total_ht * ($product['tx_tva'] / 100);
151 151
 				$total_ttc = $total_ht + $tva_total_amount;
152 152
 			}
153 153
 			else {
154 154
 				$total_ttc = $product['product_price'] * $product['product_qty'];
155
-				$total_ht  = $total_ttc / ( 1 + ( $product['tx_tva'] / 100 ) );
155
+				$total_ht  = $total_ttc / (1 + ($product['tx_tva'] / 100));
156 156
 				$tva_total_amount = $total_ttc - $total_ht;
157 157
 			}
158 158
 
@@ -160,21 +160,21 @@  discard block
 block discarded – undo
160 160
 
161 161
 			$item_discount_type = $item_discount_value = $item_discount_amount = 0;
162 162
 
163
-			$d_amount = !empty( $product ) && !empty( $product[ 'discount_amount' ] ) ? wpshop_tools::formate_number( $product['discount_amount'] ) : null;
164
-			$d_rate = !empty( $product ) && !empty( $product[ 'discount_rate' ] ) ? wpshop_tools::formate_number( $product['discount_rate'] ) : null;
165
-			$d_special = !empty( $product ) && !empty( $product[ 'special_price' ] ) ? wpshop_tools::formate_number( $product['special_price'] ) : null;
163
+			$d_amount = !empty($product) && !empty($product['discount_amount']) ? wpshop_tools::formate_number($product['discount_amount']) : null;
164
+			$d_rate = !empty($product) && !empty($product['discount_rate']) ? wpshop_tools::formate_number($product['discount_rate']) : null;
165
+			$d_special = !empty($product) && !empty($product['special_price']) ? wpshop_tools::formate_number($product['special_price']) : null;
166 166
 
167
-			if( !empty($d_amount) ) {
167
+			if (!empty($d_amount)) {
168 168
 				$item_discount_type = 'discount_amount';
169 169
 				$item_discount_amount = $product['discount_amount'];
170 170
 				$item_discount_value = $product['discount_amount'];
171 171
 			}
172
-			elseif(!empty($d_rate)) {
172
+			elseif (!empty($d_rate)) {
173 173
 				$item_discount_type = 'discount_rate';
174 174
 				$item_discount_amount = $product['discount_rate'];
175 175
 				$item_discount_value = $product['discount_rate'];
176 176
 			}
177
-			elseif(!empty($d_special)) {
177
+			elseif (!empty($d_special)) {
178 178
 				$item_discount_type = 'special_price';
179 179
 				$item_discount_amount = $product['special_price'];
180 180
 				$item_discount_value = $product['special_price'];
@@ -201,31 +201,31 @@  discard block
 block discarded – undo
201 201
 					'item_meta' => !empty($product['item_meta']) ? $product['item_meta'] : array()
202 202
 			);
203 203
 
204
-			$array_not_to_do = array(WPSHOP_PRODUCT_PRICE_HT,WPSHOP_PRODUCT_PRICE_TTC,WPSHOP_PRODUCT_PRICE_TAX_AMOUNT,'product_qty',WPSHOP_PRODUCT_PRICE_TAX,'product_id','product_reference','product_name','variations');
204
+			$array_not_to_do = array(WPSHOP_PRODUCT_PRICE_HT, WPSHOP_PRODUCT_PRICE_TTC, WPSHOP_PRODUCT_PRICE_TAX_AMOUNT, 'product_qty', WPSHOP_PRODUCT_PRICE_TAX, 'product_id', 'product_reference', 'product_name', 'variations');
205 205
 
206
-			if(!empty($product['item_meta'])) {
207
-				foreach($product['item_meta'] as $key=>$value) {
208
-					if( !isset($item['item_'.$key]) && !in_array($key, $array_not_to_do) && !empty($product[$key]) ) {
209
-						$item['item_'.$key] = $product[$key];
206
+			if (!empty($product['item_meta'])) {
207
+				foreach ($product['item_meta'] as $key=>$value) {
208
+					if (!isset($item['item_' . $key]) && !in_array($key, $array_not_to_do) && !empty($product[$key])) {
209
+						$item['item_' . $key] = $product[$key];
210 210
 					}
211 211
 				}
212 212
 			}
213 213
 
214 214
 			/** Check if it's a variation product **/
215
-			if ( !empty($product) && !empty( $product['item_meta']) && !empty($product['item_meta']['variations']) ) {
216
-				foreach( $product['item_meta']['variations'] as $k => $variation ) {
217
-					$product_variation_def = get_post_meta( $k, '_wpshop_variations_attribute_def', true);
218
-					if ( !empty($product_variation_def) ) {
219
-						foreach( $product_variation_def as $attribute_code => $variation_id ) {
220
-							$variation_attribute_def = wpshop_attributes::getElement( $attribute_code, '"valid"', 'code' );
221
-							if ( !empty($variation_attribute_def) ) {
215
+			if (!empty($product) && !empty($product['item_meta']) && !empty($product['item_meta']['variations'])) {
216
+				foreach ($product['item_meta']['variations'] as $k => $variation) {
217
+					$product_variation_def = get_post_meta($k, '_wpshop_variations_attribute_def', true);
218
+					if (!empty($product_variation_def)) {
219
+						foreach ($product_variation_def as $attribute_code => $variation_id) {
220
+							$variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code');
221
+							if (!empty($variation_attribute_def)) {
222 222
 								$item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label;
223
-								if ( $variation_attribute_def->data_type_to_use == 'custom' ) {
224
-									$query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id=%d', $variation_id);
225
-									$variation_name = $wpdb->get_var( $query );
223
+								if ($variation_attribute_def->data_type_to_use == 'custom') {
224
+									$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id);
225
+									$variation_name = $wpdb->get_var($query);
226 226
 								}
227 227
 								else {
228
-									$variation_post = get_post( $variation_id );
228
+									$variation_post = get_post($variation_id);
229 229
 									$variation_name = $variation_post->post_title;
230 230
 								}
231 231
 								$item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name;
@@ -237,19 +237,19 @@  discard block
 block discarded – undo
237 237
 			}
238 238
 			else {
239 239
 				/** Check if it's product with one variation **/
240
-				$product_variation_def = get_post_meta( $product['product_id'], '_wpshop_variations_attribute_def', true);
240
+				$product_variation_def = get_post_meta($product['product_id'], '_wpshop_variations_attribute_def', true);
241 241
 
242
-				if ( !empty($product_variation_def) ) {
243
-					foreach( $product_variation_def as $attribute_code => $variation_id ) {
244
-						$variation_attribute_def = wpshop_attributes::getElement( $attribute_code, '"valid"', 'code' );
245
-						if ( !empty($variation_attribute_def) ) {
242
+				if (!empty($product_variation_def)) {
243
+					foreach ($product_variation_def as $attribute_code => $variation_id) {
244
+						$variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code');
245
+						if (!empty($variation_attribute_def)) {
246 246
 							$item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label;
247
-							if ( $variation_attribute_def->data_type_to_use == 'custom' ) {
248
-								$query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id=%d', $variation_id);
249
-								$variation_name = $wpdb->get_var( $query );
247
+							if ($variation_attribute_def->data_type_to_use == 'custom') {
248
+								$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id);
249
+								$variation_name = $wpdb->get_var($query);
250 250
 							}
251 251
 							else {
252
-								$variation_post = get_post( $variation_id );
252
+								$variation_post = get_post($variation_id);
253 253
 								$variation_name = $variation_post->post_title;
254 254
 							}
255 255
 							$item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name;
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 			}
261 261
 
262 262
 			/**	On ajoute la possibilité d'étendre les données produits ajoutées dans le panier / Add possibility to extends product data saved into cart	*/
263
-			$item = apply_filters( 'wpshop-add-product-to-order', $item, $product );
263
+			$item = apply_filters('wpshop-add-product-to-order', $item, $product);
264 264
 
265 265
 			return $item;
266 266
 		}
@@ -270,24 +270,24 @@  discard block
 block discarded – undo
270 270
 		 * AJAX - Load order details in customer account
271 271
 		 */
272 272
 		function wps_orders_load_details() {
273
-			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
273
+			$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
274 274
 
275
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_orders_load_details' ) )
275
+			if (!wp_verify_nonce($_wpnonce, 'wps_orders_load_details'))
276 276
 				wp_die();
277 277
 
278
-			$order_id = ( !empty($_POST['order_id']) ) ? wpshop_tools::varSanitizer( $_POST['order_id'] ) : '';
278
+			$order_id = (!empty($_POST['order_id'])) ? wpshop_tools::varSanitizer($_POST['order_id']) : '';
279 279
 			$user_id = get_current_user_id();
280 280
 			$status = false; $result = '';
281
-			if( !empty($order_id) ) {
282
-				$order = get_post( $order_id );
283
-				$order_infos = get_post_meta( $order_id, '_order_postmeta', true );
284
-				$order_key = ( !empty($order_infos['order_key']) ) ? $order_infos['order_key'] : '-';
285
-				if( !empty($order) && !empty($user_id) && $order->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER && $order->post_author == $user_id ) {
286
-					$result = do_shortcode( '[wps_cart cart_type="summary" oid="' .$order_id. '"]' );
281
+			if (!empty($order_id)) {
282
+				$order = get_post($order_id);
283
+				$order_infos = get_post_meta($order_id, '_order_postmeta', true);
284
+				$order_key = (!empty($order_infos['order_key'])) ? $order_infos['order_key'] : '-';
285
+				if (!empty($order) && !empty($user_id) && $order->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER && $order->post_author == $user_id) {
286
+					$result = do_shortcode('[wps_cart cart_type="summary" oid="' . $order_id . '"]');
287 287
 					$status = true;
288 288
 				}
289 289
 			}
290
-			echo json_encode( array( 'status' => $status, 'title' => sprintf( __( 'Order n° %s details', 'wpshop' ), $order_key ), 'content' => $result ) );
290
+			echo json_encode(array('status' => $status, 'title' => sprintf(__('Order n° %s details', 'wpshop'), $order_key), 'content' => $result));
291 291
 			wp_die();
292 292
 		}
293 293
 
@@ -295,83 +295,83 @@  discard block
 block discarded – undo
295 295
 		 * AJAX - Choose customer to create order
296 296
 		 */
297 297
 		function wps_order_choose_customer() {
298
-			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
298
+			$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
299 299
 
300
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_order_choose_customer' ) )
300
+			if (!wp_verify_nonce($_wpnonce, 'wps_order_choose_customer'))
301 301
 				wp_die();
302 302
 
303 303
 			$status = false; $billing_data = $shipping_data = '';
304
-			$customer_id = ( !empty($_POST['customer_id']) ) ? intval( $_POST['customer_id'] ): null;
305
-			if( !empty($customer_id) ) {
304
+			$customer_id = (!empty($_POST['customer_id'])) ? intval($_POST['customer_id']) : null;
305
+			if (!empty($customer_id)) {
306 306
 				$wps_address = new wps_address();
307
-				$billing_option = get_option( 'wpshop_billing_address' );
308
-				$shipping_option = get_option( 'wpshop_shipping_address_choice' );
307
+				$billing_option = get_option('wpshop_billing_address');
308
+				$shipping_option = get_option('wpshop_shipping_address_choice');
309 309
 				$billing_option = $billing_option['choice'];
310
-				$customer_addresses_list = wps_address::get_addresses_list( $customer_id );
310
+				$customer_addresses_list = wps_address::get_addresses_list($customer_id);
311 311
 				$status = true;
312
-				$billing_data = '<div class="wps-alert-info">' .sprintf( __( 'No Billing address created, <a href="%s" title="' .__( 'Create a new billing address', 'wpshop' ). '" class="thickbox">create one</a>', 'wpshop' ),admin_url( 'admin-ajax.php' ). '?action=wps-add-an-address-in-admin&address_type='.$billing_option.'&customer_id='.$customer_id.'&height=600' ). '</div>';
312
+				$billing_data = '<div class="wps-alert-info">' . sprintf(__('No Billing address created, <a href="%s" title="' . __('Create a new billing address', 'wpshop') . '" class="thickbox">create one</a>', 'wpshop'), admin_url('admin-ajax.php') . '?action=wps-add-an-address-in-admin&address_type=' . $billing_option . '&customer_id=' . $customer_id . '&height=600') . '</div>';
313 313
 
314
-				if( !empty($shipping_option) && !empty($shipping_option['activate']) ) {
314
+				if (!empty($shipping_option) && !empty($shipping_option['activate'])) {
315 315
 					$shipping_option = $shipping_option['choice'];
316
-					$shipping_data = '<div class="wps-alert-info">' .sprintf( __( 'No shipping address created, <a href="%s" title="' .__( 'Create a new shipping address', 'wpshop' ). '" class="thickbox">create one</a>', 'wpshop' ),admin_url( 'admin-ajax.php' ). '?action=wps-add-an-address-in-admin&address_type='.$shipping_option.'&customer_id='.$customer_id.'&height=600' ). '</div>';
316
+					$shipping_data = '<div class="wps-alert-info">' . sprintf(__('No shipping address created, <a href="%s" title="' . __('Create a new shipping address', 'wpshop') . '" class="thickbox">create one</a>', 'wpshop'), admin_url('admin-ajax.php') . '?action=wps-add-an-address-in-admin&address_type=' . $shipping_option . '&customer_id=' . $customer_id . '&height=600') . '</div>';
317 317
 				}
318 318
 
319
-				if( !empty($customer_addresses_list) ) {
320
-					foreach( $customer_addresses_list as $address_type => $customer_addresses ) {
321
-						if( $billing_option == $address_type ) {
322
-							$billing_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type );
319
+				if (!empty($customer_addresses_list)) {
320
+					foreach ($customer_addresses_list as $address_type => $customer_addresses) {
321
+						if ($billing_option == $address_type) {
322
+							$billing_data = $wps_address->display_address_in_administration($customer_addresses, $address_type);
323 323
 						}
324 324
 						else {
325
-							$shipping_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type );
325
+							$shipping_data = $wps_address->display_address_in_administration($customer_addresses, $address_type);
326 326
 						}
327 327
 					}
328 328
 				}
329 329
 			}
330
-			echo json_encode( array( 'status' => $status, 'billing_data' => $billing_data, 'shipping_data' => $shipping_data) );
330
+			echo json_encode(array('status' => $status, 'billing_data' => $billing_data, 'shipping_data' => $shipping_data));
331 331
 			wp_die();
332 332
 		}
333 333
 
334
-		function pay_quotation( $order_id ) {
334
+		function pay_quotation($order_id) {
335 335
 			$status = true;
336
-			$order_meta = get_post_meta( $order_id, '_order_postmeta', true );
337
-			$order_info = get_post_meta( $order_id, '_order_info', true );
336
+			$order_meta = get_post_meta($order_id, '_order_postmeta', true);
337
+			$order_info = get_post_meta($order_id, '_order_info', true);
338 338
 			$_SESSION['shipping_method'] = $order_meta['order_payment']['shipping_method'];
339
-			isset( $order_info['billing']['address_id'] ) ? $_SESSION['billing_address'] = $order_info['billing']['address_id'] : $status = false;
340
-			isset( $order_info['shipping']['address_id'] ) ? $_SESSION['shipping_address'] = $order_info['shipping']['address_id'] : false;
339
+			isset($order_info['billing']['address_id']) ? $_SESSION['billing_address'] = $order_info['billing']['address_id'] : $status = false;
340
+			isset($order_info['shipping']['address_id']) ? $_SESSION['shipping_address'] = $order_info['shipping']['address_id'] : false;
341 341
 			$_SESSION['cart'] = array();
342
-			$_SESSION['cart']['order_id'] = wpshop_tools::varSanitizer( $order_id );
342
+			$_SESSION['cart']['order_id'] = wpshop_tools::varSanitizer($order_id);
343 343
 			$_SESSION['cart']['cart_type'] = 'normal';
344 344
 			$_SESSION['cart']['order_amount_to_pay_now'] = $order_meta['order_amount_to_pay_now'];
345 345
 			$_SESSION['cart']['order_items'] = $order_meta['order_items'];
346
-			return array( 'status' => $status, 'permalink' => get_permalink( get_option('wpshop_cart_page_id') ) . '?order_step=5' );
346
+			return array('status' => $status, 'permalink' => get_permalink(get_option('wpshop_cart_page_id')) . '?order_step=5');
347 347
 		}
348 348
 		/**
349 349
 		 * AJAX - Delete order by order_id
350 350
 		 */
351 351
 		public function wps_delete_order() {
352
-			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
352
+			$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
353 353
 
354
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_delete_order' ) )
354
+			if (!wp_verify_nonce($_wpnonce, 'wps_delete_order'))
355 355
 				wp_die();
356 356
 
357 357
 			$status = false;
358 358
 			$output = '';
359
-			$order_id = !empty( $_POST['order_id'] ) ? (int) $_POST['order_id'] : 0;
360
-			if( $order_id ) {
361
-				$order_meta = get_post_meta( $order_id, '_order_postmeta', true );
359
+			$order_id = !empty($_POST['order_id']) ? (int)$_POST['order_id'] : 0;
360
+			if ($order_id) {
361
+				$order_meta = get_post_meta($order_id, '_order_postmeta', true);
362 362
 				$wps_credit = new wps_credit();
363
-				$wps_credit->create_an_credit( $order_id );
363
+				$wps_credit->create_an_credit($order_id);
364 364
 				$order_meta['order_status'] = 'canceled';
365
-				$order_meta['order_payment']['refunded_action']['refunded_date'] = current_time('mysql', 0 );
365
+				$order_meta['order_payment']['refunded_action']['refunded_date'] = current_time('mysql', 0);
366 366
 				$order_meta['order_payment']['refunded_action']['author'] = get_current_user_id();
367
-				update_post_meta( $order_id, '_order_postmeta', $order_meta );
367
+				update_post_meta($order_id, '_order_postmeta', $order_meta);
368 368
 				ob_start();
369
-				require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, "frontend", "order_row_in_account") );
369
+				require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, "frontend", "order_row_in_account"));
370 370
 				$output = ob_get_contents();
371 371
 				ob_end_clean();
372 372
 				$status = true;
373 373
 			}
374
-			echo json_encode( array( 'status' => $status, 'row' => $output ) );
374
+			echo json_encode(array('status' => $status, 'row' => $output));
375 375
 			wp_die();
376 376
 		}
377 377
 
@@ -379,37 +379,37 @@  discard block
 block discarded – undo
379 379
 		 * AJAX - Pay billing
380 380
 		 */
381 381
 		public function wps_checkout_quotation() {
382
-			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
382
+			$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
383 383
 
384
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_quotation' ) )
384
+			if (!wp_verify_nonce($_wpnonce, 'wps_checkout_quotation'))
385 385
 				wp_die();
386 386
 
387 387
 			$status = true;
388
-			$order_id = !empty( $_REQUEST['order_id'] ) ? (int) $_REQUEST['order_id'] : 0;
388
+			$order_id = !empty($_REQUEST['order_id']) ? (int)$_REQUEST['order_id'] : 0;
389 389
 
390
-			if( !empty( $order_id ) ) {
391
-				$pay_quotation = self::pay_quotation( $order_id );
390
+			if (!empty($order_id)) {
391
+				$pay_quotation = self::pay_quotation($order_id);
392 392
 				$status = $pay_quotation['status'];
393 393
 			}
394 394
 
395
-			$is_link = !empty( $_REQUEST['is_link'] ) ? sanitize_text_field( $_REQUEST['is_link'] ) : '';
395
+			$is_link = !empty($_REQUEST['is_link']) ? sanitize_text_field($_REQUEST['is_link']) : '';
396 396
 
397
-			if( !empty( $is_link ) ) {
398
-				wp_redirect( $pay_quotation['permalink'] );
397
+			if (!empty($is_link)) {
398
+				wp_redirect($pay_quotation['permalink']);
399 399
 				exit();
400 400
 			} else {
401
-				echo json_encode( array( 'status' => $status, '301' => $pay_quotation['permalink'] ) );
401
+				echo json_encode(array('status' => $status, '301' => $pay_quotation['permalink']));
402 402
 				wp_die();
403 403
 			}
404 404
 		}
405 405
 		public function wps_checkout_quotation_no_login() {
406
-			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
406
+			$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
407 407
 
408
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_quotation' ) )
408
+			if (!wp_verify_nonce($_wpnonce, 'wps_checkout_quotation'))
409 409
 				wp_die();
410 410
 
411
-			$order_id = !empty( $_REQUEST['order_id'] ) ? (int) $_REQUEST['order_id'] : 0;
412
-			wp_redirect( home_url('/wp-login.php') . '?redirect_to=' . urlencode( admin_url() . 'admin-ajax.php?action=wps_checkout_quotation&order_id=' . $order_id . '&is_link=link' ) );
411
+			$order_id = !empty($_REQUEST['order_id']) ? (int)$_REQUEST['order_id'] : 0;
412
+			wp_redirect(home_url('/wp-login.php') . '?redirect_to=' . urlencode(admin_url() . 'admin-ajax.php?action=wps_checkout_quotation&order_id=' . $order_id . '&is_link=link'));
413 413
 			exit();
414 414
 		}
415 415
 }
Please login to merge, or discard this patch.
Braces   +27 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 class wps_orders_ctr {
3 5
 	/** Define the main directory containing the template for the current plugin
4 6
 	 * @var string
@@ -73,13 +75,11 @@  discard block
 block discarded – undo
73 75
 					if ( !empty($order_postmeta['order_status'])  && $order_postmeta['order_status'] != 'awaiting_payment' ) {
74 76
 						$output = wps_address::display_an_address( $order_info['billing']['address'] );
75 77
 						$output .= wps_address::display_an_address( $order_info['shipping']['address'] );
76
-					}
77
-					else {
78
+					} else {
78 79
 						$output = wps_address::display_an_address( $order_info['billing']['address'] );
79 80
 					}
80 81
 				}
81
-			}
82
-			else {
82
+			} else {
83 83
 				/** Display  "Choose customer or create one" Interface **/
84 84
 				$tpl_component = array();
85 85
 				$args = array(
@@ -149,8 +149,7 @@  discard block
 block discarded – undo
149 149
 				$total_ht = $product['price_ht'] * $product['product_qty'];
150 150
 				$tva_total_amount = $total_ht * ( $product['tx_tva'] / 100 );
151 151
 				$total_ttc = $total_ht + $tva_total_amount;
152
-			}
153
-			else {
152
+			} else {
154 153
 				$total_ttc = $product['product_price'] * $product['product_qty'];
155 154
 				$total_ht  = $total_ttc / ( 1 + ( $product['tx_tva'] / 100 ) );
156 155
 				$tva_total_amount = $total_ttc - $total_ht;
@@ -168,13 +167,11 @@  discard block
 block discarded – undo
168 167
 				$item_discount_type = 'discount_amount';
169 168
 				$item_discount_amount = $product['discount_amount'];
170 169
 				$item_discount_value = $product['discount_amount'];
171
-			}
172
-			elseif(!empty($d_rate)) {
170
+			} elseif(!empty($d_rate)) {
173 171
 				$item_discount_type = 'discount_rate';
174 172
 				$item_discount_amount = $product['discount_rate'];
175 173
 				$item_discount_value = $product['discount_rate'];
176
-			}
177
-			elseif(!empty($d_special)) {
174
+			} elseif(!empty($d_special)) {
178 175
 				$item_discount_type = 'special_price';
179 176
 				$item_discount_amount = $product['special_price'];
180 177
 				$item_discount_value = $product['special_price'];
@@ -223,8 +220,7 @@  discard block
 block discarded – undo
223 220
 								if ( $variation_attribute_def->data_type_to_use == 'custom' ) {
224 221
 									$query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id=%d', $variation_id);
225 222
 									$variation_name = $wpdb->get_var( $query );
226
-								}
227
-								else {
223
+								} else {
228 224
 									$variation_post = get_post( $variation_id );
229 225
 									$variation_name = $variation_post->post_title;
230 226
 								}
@@ -234,8 +230,7 @@  discard block
 block discarded – undo
234 230
 						}
235 231
 					}
236 232
 				}
237
-			}
238
-			else {
233
+			} else {
239 234
 				/** Check if it's product with one variation **/
240 235
 				$product_variation_def = get_post_meta( $product['product_id'], '_wpshop_variations_attribute_def', true);
241 236
 
@@ -247,8 +242,7 @@  discard block
 block discarded – undo
247 242
 							if ( $variation_attribute_def->data_type_to_use == 'custom' ) {
248 243
 								$query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id=%d', $variation_id);
249 244
 								$variation_name = $wpdb->get_var( $query );
250
-							}
251
-							else {
245
+							} else {
252 246
 								$variation_post = get_post( $variation_id );
253 247
 								$variation_name = $variation_post->post_title;
254 248
 							}
@@ -272,8 +266,9 @@  discard block
 block discarded – undo
272 266
 		function wps_orders_load_details() {
273 267
 			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
274 268
 
275
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_orders_load_details' ) )
276
-				wp_die();
269
+			if ( !wp_verify_nonce( $_wpnonce, 'wps_orders_load_details' ) ) {
270
+							wp_die();
271
+			}
277 272
 
278 273
 			$order_id = ( !empty($_POST['order_id']) ) ? wpshop_tools::varSanitizer( $_POST['order_id'] ) : '';
279 274
 			$user_id = get_current_user_id();
@@ -297,8 +292,9 @@  discard block
 block discarded – undo
297 292
 		function wps_order_choose_customer() {
298 293
 			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
299 294
 
300
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_order_choose_customer' ) )
301
-				wp_die();
295
+			if ( !wp_verify_nonce( $_wpnonce, 'wps_order_choose_customer' ) ) {
296
+							wp_die();
297
+			}
302 298
 
303 299
 			$status = false; $billing_data = $shipping_data = '';
304 300
 			$customer_id = ( !empty($_POST['customer_id']) ) ? intval( $_POST['customer_id'] ): null;
@@ -320,8 +316,7 @@  discard block
 block discarded – undo
320 316
 					foreach( $customer_addresses_list as $address_type => $customer_addresses ) {
321 317
 						if( $billing_option == $address_type ) {
322 318
 							$billing_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type );
323
-						}
324
-						else {
319
+						} else {
325 320
 							$shipping_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type );
326 321
 						}
327 322
 					}
@@ -351,8 +346,9 @@  discard block
 block discarded – undo
351 346
 		public function wps_delete_order() {
352 347
 			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
353 348
 
354
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_delete_order' ) )
355
-				wp_die();
349
+			if ( !wp_verify_nonce( $_wpnonce, 'wps_delete_order' ) ) {
350
+							wp_die();
351
+			}
356 352
 
357 353
 			$status = false;
358 354
 			$output = '';
@@ -381,8 +377,9 @@  discard block
 block discarded – undo
381 377
 		public function wps_checkout_quotation() {
382 378
 			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
383 379
 
384
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_quotation' ) )
385
-				wp_die();
380
+			if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_quotation' ) ) {
381
+							wp_die();
382
+			}
386 383
 
387 384
 			$status = true;
388 385
 			$order_id = !empty( $_REQUEST['order_id'] ) ? (int) $_REQUEST['order_id'] : 0;
@@ -405,8 +402,9 @@  discard block
 block discarded – undo
405 402
 		public function wps_checkout_quotation_no_login() {
406 403
 			$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
407 404
 
408
-			if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_quotation' ) )
409
-				wp_die();
405
+			if ( !wp_verify_nonce( $_wpnonce, 'wps_checkout_quotation' ) ) {
406
+							wp_die();
407
+			}
410 408
 
411 409
 			$order_id = !empty( $_REQUEST['order_id'] ) ? (int) $_REQUEST['order_id'] : 0;
412 410
 			wp_redirect( home_url('/wp-login.php') . '?redirect_to=' . urlencode( admin_url() . 'admin-ajax.php?action=wps_checkout_quotation&order_id=' . $order_id . '&is_link=link' ) );
Please login to merge, or discard this patch.
includes/modules/wps_product/controller/wps_product_ajax_ctr.01.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,6 @@
 block discarded – undo
30 30
 	 * of the number of corrected product and the template of the method : ajax_checking_products_values if inconsistent product
31 31
 	 * already present.
32 32
 	 *
33
-	 * @param array $_POST['product_price'] List of the new price for the product like array( $id_product => $new_price )
34 33
 	 * @return JSON Response
35 34
 	 */
36 35
 	public function ajax_save_product_price() {
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 class wps_product_ajax_ctr_01 {
3 3
 	public function __construct() {
4
-		add_action( 'wp_ajax_checking_products_values', array( &$this, 'ajax_render_inconsistent_product_price' ) );
5
-		add_action( 'wp_ajax_save_products_prices', array( &$this, 'ajax_save_product_price' ) );
4
+		add_action('wp_ajax_checking_products_values', array(&$this, 'ajax_render_inconsistent_product_price'));
5
+		add_action('wp_ajax_save_products_prices', array(&$this, 'ajax_save_product_price'));
6 6
 	}
7 7
 
8 8
 	/**
@@ -12,16 +12,16 @@  discard block
 block discarded – undo
12 12
 	 * list. Then display the template product_check_data
13 13
 	 */
14 14
 	public function ajax_render_inconsistent_product_price() {
15
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
15
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
16 16
 
17
-		if ( !wp_verify_nonce( $_wpnonce, 'ajax_render_inconsistent_product_price' ) )
17
+		if (!wp_verify_nonce($_wpnonce, 'ajax_render_inconsistent_product_price'))
18 18
 			wp_die();
19 19
 
20 20
 		$list_product = wps_product_ctr::get_inconsistent_product();
21 21
 
22 22
 		$inconsistent_product_number = count($list_product);
23 23
 
24
-		require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "backend", "product_check_data") );
24
+		require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "backend", "product_check_data"));
25 25
 		wp_die();
26 26
 	}
27 27
 
@@ -39,39 +39,39 @@  discard block
 block discarded – undo
39 39
 	 * @return JSON Response
40 40
 	 */
41 41
 	public function ajax_save_product_price() {
42
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
42
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
43 43
 
44
-		if ( !wp_verify_nonce( $_wpnonce, 'ajax_save_product_price' ) )
44
+		if (!wp_verify_nonce($_wpnonce, 'ajax_save_product_price'))
45 45
 			wp_die();
46 46
 
47
-		header( 'Content-Type: application/json' );
47
+		header('Content-Type: application/json');
48 48
 		$response = array();
49 49
 
50
-		$price_piloting_option = get_option( 'wpshop_shop_price_piloting' );
50
+		$price_piloting_option = get_option('wpshop_shop_price_piloting');
51 51
 
52
-		$inconsistent_product_number 	= !empty( $_POST['product_price'] ) ? (int) count( $_POST['product_price'] ) : 0;
53
-		$consistent_product_number 		= 0;
52
+		$inconsistent_product_number = !empty($_POST['product_price']) ? (int)count($_POST['product_price']) : 0;
53
+		$consistent_product_number = 0;
54 54
 
55
-		$entity_type_id	= wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
56
-		$language 		= WPSHOP_CURRENT_LOCALE;
57
-		$icl_language = !empty( $_REQUEST['icl_post_language'] ) ? sanitize_text_field( $_REQUEST['icl_post_language'] ) : '';
55
+		$entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
56
+		$language = WPSHOP_CURRENT_LOCALE;
57
+		$icl_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
58 58
 
59
-		if ( !empty($icl_language) ) {
60
-			$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_language );
59
+		if (!empty($icl_language)) {
60
+			$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_language);
61 61
 			$language = $wpdb->get_var($query);
62 62
 		}
63 63
 
64
-		$product_price = !empty( $_POST['product_price'] ) ? (array) $_POST['product_price'] : array();
64
+		$product_price = !empty($_POST['product_price']) ? (array)$_POST['product_price'] : array();
65 65
 
66
-		if( !empty( $product_price ) ) {
67
-			foreach( $product_price as $product_id => $price ) {
66
+		if (!empty($product_price)) {
67
+			foreach ($product_price as $product_id => $price) {
68 68
 				try {
69
-					if( $price_piloting_option == 'TTC' )
70
-						wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'product_price' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_products' );
69
+					if ($price_piloting_option == 'TTC')
70
+						wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => sanitize_text_field($price))), $entity_type_id, (int)$product_id, $language, 'wpshop_products');
71 71
 					else
72
-						wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'price_ht' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_product' );
72
+						wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => sanitize_text_field($price))), $entity_type_id, (int)$product_id, $language, 'wpshop_product');
73 73
 
74
-					wpshop_products::calculate_price( $product_id );
74
+					wpshop_products::calculate_price($product_id);
75 75
 					$consistent_product_number++;
76 76
 
77 77
 				} catch (Exception $e) {
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
 			}
80 80
 		}
81 81
 
82
-		$response['template_number'] = __( sprintf( 'Number of processed product : %d/%d', $consistent_product_number, $inconsistent_product_number ), 'wps-product' );
82
+		$response['template_number'] = __(sprintf('Number of processed product : %d/%d', $consistent_product_number, $inconsistent_product_number), 'wps-product');
83 83
 
84 84
 		$list_product = wps_product_ctr::get_inconsistent_product();
85 85
 		ob_start();
86
-		require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "backend", "product_check_data") );
86
+		require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "backend", "product_check_data"));
87 87
 		$response['template'] = ob_get_clean();
88 88
 
89
-		wp_die( json_encode( $response ) );
89
+		wp_die(json_encode($response));
90 90
 	}
91 91
 }
92 92
 
Please login to merge, or discard this patch.
Braces   +14 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 class wps_product_ajax_ctr_01 {
3 5
 	public function __construct() {
4 6
 		add_action( 'wp_ajax_checking_products_values', array( &$this, 'ajax_render_inconsistent_product_price' ) );
@@ -14,8 +16,9 @@  discard block
 block discarded – undo
14 16
 	public function ajax_render_inconsistent_product_price() {
15 17
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
16 18
 
17
-		if ( !wp_verify_nonce( $_wpnonce, 'ajax_render_inconsistent_product_price' ) )
18
-			wp_die();
19
+		if ( !wp_verify_nonce( $_wpnonce, 'ajax_render_inconsistent_product_price' ) ) {
20
+					wp_die();
21
+		}
19 22
 
20 23
 		$list_product = wps_product_ctr::get_inconsistent_product();
21 24
 
@@ -41,8 +44,9 @@  discard block
 block discarded – undo
41 44
 	public function ajax_save_product_price() {
42 45
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
43 46
 
44
-		if ( !wp_verify_nonce( $_wpnonce, 'ajax_save_product_price' ) )
45
-			wp_die();
47
+		if ( !wp_verify_nonce( $_wpnonce, 'ajax_save_product_price' ) ) {
48
+					wp_die();
49
+		}
46 50
 
47 51
 		header( 'Content-Type: application/json' );
48 52
 		$response = array();
@@ -66,10 +70,11 @@  discard block
 block discarded – undo
66 70
 		if( !empty( $product_price ) ) {
67 71
 			foreach( $product_price as $product_id => $price ) {
68 72
 				try {
69
-					if( $price_piloting_option == 'TTC' )
70
-						wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'product_price' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_products' );
71
-					else
72
-						wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'price_ht' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_product' );
73
+					if( $price_piloting_option == 'TTC' ) {
74
+											wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'product_price' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_products' );
75
+					} else {
76
+											wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'price_ht' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_product' );
77
+					}
73 78
 
74 79
 					wpshop_products::calculate_price( $product_id );
75 80
 					$consistent_product_number++;
Please login to merge, or discard this patch.
includes/modules/wps_product/controller/wps_product_ctr.php 3 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -257,8 +257,6 @@
 block discarded – undo
257 257
 	 *
258 258
 	 * @param int $product_id L'id du produit
259 259
 	 * @param string $type Peut être varchar, integer, text, options, decimal, datetime
260
-	 * @param string $attribute_name Le code d'un attribut
261
-	 * @param string $attribute_value La valeur à mêttre à jour
262 260
 	 */
263 261
 	public function update_the_attribute_for_product($product_id, $type, $name_attribute, $value_attribute) {
264 262
 		global $wpdb;
Please login to merge, or discard this patch.
Spacing   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 class wps_product_ctr {
3 3
 
4 4
 	/**
@@ -8,16 +8,16 @@  discard block
 block discarded – undo
8 8
 	 * @return void
9 9
 	 */
10 10
 	function __construct() {
11
-		add_action( 'admin_enqueue_scripts', array( &$this, 'callback_admin_enqueue_scripts' ) );
11
+		add_action('admin_enqueue_scripts', array(&$this, 'callback_admin_enqueue_scripts'));
12 12
 
13
-		add_shortcode( 'wps_product_caracteristics', array( $this, 'display_product_caracteristics_tab' ) );
14
-		add_shortcode( 'wpshop_product_caracteristics', array( $this, 'display_product_caracteristics_tab' ) );
15
-		add_shortcode( 'wps_product_discount_chip', array( $this, 'display_discount_chip' ) );
16
-		add_shortcode( 'wpshop_product_discount_chip', array( $this, 'display_discount_chip' ) );
13
+		add_shortcode('wps_product_caracteristics', array($this, 'display_product_caracteristics_tab'));
14
+		add_shortcode('wpshop_product_caracteristics', array($this, 'display_product_caracteristics_tab'));
15
+		add_shortcode('wps_product_discount_chip', array($this, 'display_discount_chip'));
16
+		add_shortcode('wpshop_product_discount_chip', array($this, 'display_discount_chip'));
17 17
 
18
-		add_shortcode( 'wpshop_product_title', array( $this, 'wpshop_product_title' ) );
19
-		add_shortcode( 'wpshop_product_content', array( $this, 'wpshop_product_content' ) );
20
-		add_shortcode( 'wpshop_product_thumbnail', array( $this, 'wpshop_product_thumbnail' ) );
18
+		add_shortcode('wpshop_product_title', array($this, 'wpshop_product_title'));
19
+		add_shortcode('wpshop_product_content', array($this, 'wpshop_product_content'));
20
+		add_shortcode('wpshop_product_thumbnail', array($this, 'wpshop_product_thumbnail'));
21 21
 	}
22 22
 
23 23
 	/**
@@ -28,14 +28,14 @@  discard block
 block discarded – undo
28 28
 		$module_folder = WPS_PRODUCT_PATH . '/modules/';
29 29
 
30 30
 		/**	Check if the defined directory exists for reading and including the different modules	*/
31
-		if( is_dir( $module_folder ) ) {
32
-			$parent_folder_content = scandir( $module_folder );
33
-			foreach ( $parent_folder_content as $folder ) {
34
-				if ( $folder && substr( $folder, 0, 1) != '.' && is_dir( $folder ) ) {
35
-					$child_folder_content = scandir( $module_folder . $folder );
36
-					if ( file_exists( $module_folder . $folder . '/' . $folder . '.php') ) {
37
-						$f =  $module_folder . $folder . '/' . $folder . '.php';
38
-						include( $f );
31
+		if (is_dir($module_folder)) {
32
+			$parent_folder_content = scandir($module_folder);
33
+			foreach ($parent_folder_content as $folder) {
34
+				if ($folder && substr($folder, 0, 1) != '.' && is_dir($folder)) {
35
+					$child_folder_content = scandir($module_folder . $folder);
36
+					if (file_exists($module_folder . $folder . '/' . $folder . '.php')) {
37
+						$f = $module_folder . $folder . '/' . $folder . '.php';
38
+						include($f);
39 39
 					}
40 40
 				}
41 41
 			}
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	}
44 44
 
45 45
 	public function callback_admin_enqueue_scripts() {
46
-		wp_enqueue_script( 'wps_product_js', WPS_PRODUCT_URL . '/asset/js/backend.js', array( "jquery", "jquery-form" ), WPS_PRODUCT_VERSION );
46
+		wp_enqueue_script('wps_product_js', WPS_PRODUCT_URL . '/asset/js/backend.js', array("jquery", "jquery-form"), WPS_PRODUCT_VERSION);
47 47
 	}
48 48
 
49 49
 	/**
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
 	 * @param array $args
52 52
 	 * @return string
53 53
 	 */
54
-	function display_product_caracteristics_tab( $args ) {
54
+	function display_product_caracteristics_tab($args) {
55 55
 		$output = '';
56
-		if( !empty($args) && !empty($args['pid']) ) {
56
+		if (!empty($args) && !empty($args['pid'])) {
57 57
 			$wps_product_mdl = new wps_product_mdl();
58
-			$product_atts_def = $wps_product_mdl->get_product_atts_def( $args['pid'] );
59
-			if( !empty($product_atts_def) ) {
58
+			$product_atts_def = $wps_product_mdl->get_product_atts_def($args['pid']);
59
+			if (!empty($product_atts_def)) {
60 60
 				ob_start();
61
-				require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_caracteristics_tab") );
61
+				require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_caracteristics_tab"));
62 62
 				$output = ob_get_contents();
63 63
 				ob_end_clean();
64 64
 			}
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
 	 * @param array $args
72 72
 	 * @return string
73 73
 	 */
74
-	function display_discount_chip( $args ) {
74
+	function display_discount_chip($args) {
75 75
 		$output = '';
76
-		if( !empty($args) && !empty($args['pid']) ) {
76
+		if (!empty($args) && !empty($args['pid'])) {
77 77
 			$wps_price = new wpshop_prices();
78
-			$discount_data = wpshop_prices::check_discount_for_product( $args['pid'] );
79
-			if( !empty($discount_data) ) {
78
+			$discount_data = wpshop_prices::check_discount_for_product($args['pid']);
79
+			if (!empty($discount_data)) {
80 80
 				ob_start();
81
-				require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_discount_chip") );
81
+				require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_discount_chip"));
82 82
 				$output = ob_get_contents();
83 83
 				ob_end_clean();
84 84
 			}
@@ -96,36 +96,36 @@  discard block
 block discarded – undo
96 96
 	 */
97 97
 	function check_stock($product_id, $cart_asked_quantity, $combined_variation_id = '') {
98 98
 		// Checking if combined variation ID exist and it is a simple option
99
-		if( !empty($combined_variation_id) && ( strpos($combined_variation_id, '__') !== false ) ) {
100
-			$var_id = explode( '__', $combined_variation_id);
99
+		if (!empty($combined_variation_id) && (strpos($combined_variation_id, '__') !== false)) {
100
+			$var_id = explode('__', $combined_variation_id);
101 101
 			$combined_variation_id = $var_id[1];
102 102
 		}
103 103
 
104 104
 
105
-		if ( !empty($combined_variation_id) ) {
105
+		if (!empty($combined_variation_id)) {
106 106
 
107
-			$variation_metadata = get_post_meta( $combined_variation_id, '_wpshop_product_metadata', true );
108
-			if ( isset($variation_metadata['product_stock']) ) {
107
+			$variation_metadata = get_post_meta($combined_variation_id, '_wpshop_product_metadata', true);
108
+			if (isset($variation_metadata['product_stock'])) {
109 109
 				$product_id = $combined_variation_id;
110 110
 			}
111 111
 		}
112 112
 		$product_data = wpshop_products::get_product_data($product_id, false, '"publish"');
113 113
 
114
-		if(!empty($product_data)) {
114
+		if (!empty($product_data)) {
115 115
 			$manage_stock = !empty($product_data['manage_stock']) ? $product_data['manage_stock'] : '';
116 116
 
117
-			$product_post_type = get_post_type( $product_id );
117
+			$product_post_type = get_post_type($product_id);
118 118
 
119
-			if ( $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
120
-				$parent_def = wpshop_products::get_parent_variation( $product_id );
121
-				if ( !empty($parent_def) && !empty($parent_def['parent_post']) ) {
119
+			if ($product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
120
+				$parent_def = wpshop_products::get_parent_variation($product_id);
121
+				if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
122 122
 					$parent_post = $parent_def['parent_post'];
123 123
 					$parent_product_data = wpshop_products::get_product_data($parent_post->ID);
124
-					$manage_stock = empty( $manage_stock ) ? $parent_product_data['manage_stock'] : $manage_stock;
124
+					$manage_stock = empty($manage_stock) ? $parent_product_data['manage_stock'] : $manage_stock;
125 125
 				}
126 126
 			}
127
-			$manage_stock_is_activated = (!empty($manage_stock) && ( strtolower(__($manage_stock, 'wpshop')) == strtolower(__('Yes', 'wpshop')) )) ? true : false;
128
-			$the_qty_is_in_stock = ( !empty($product_data['product_stock']) && $product_data['product_stock'] >= $cart_asked_quantity ) ? true : false ;
127
+			$manage_stock_is_activated = (!empty($manage_stock) && (strtolower(__($manage_stock, 'wpshop')) == strtolower(__('Yes', 'wpshop')))) ? true : false;
128
+			$the_qty_is_in_stock = (!empty($product_data['product_stock']) && $product_data['product_stock'] >= $cart_asked_quantity) ? true : false;
129 129
 
130 130
 			if (($manage_stock_is_activated && $the_qty_is_in_stock) OR !$manage_stock_is_activated) {
131 131
 				return true;
@@ -138,18 +138,18 @@  discard block
 block discarded – undo
138 138
 	}
139 139
 
140 140
 	public static function get_inconsistent_product() {
141
-		$price_piloting_option = get_option( 'wpshop_shop_price_piloting' );
141
+		$price_piloting_option = get_option('wpshop_shop_price_piloting');
142 142
 
143
-		$entity_id 		= wpshop_entities::get_entity_identifier_from_code( 'wpshop_product' );
143
+		$entity_id = wpshop_entities::get_entity_identifier_from_code('wpshop_product');
144 144
 
145
-		$attribute_def	= wpshop_attributes::getElement( ( $price_piloting_option == 'TTC' ) ? 'product_price' : 'price_ht', "'valid'", 'code' );
146
-		$attribute_id	= $attribute_def->id;
145
+		$attribute_def = wpshop_attributes::getElement(($price_piloting_option == 'TTC') ? 'product_price' : 'price_ht', "'valid'", 'code');
146
+		$attribute_id = $attribute_def->id;
147 147
 
148 148
 		global $wpdb;
149 149
 
150 150
 		$wpdb->query('SET SESSION group_concat_max_len = 10000');
151 151
 
152
-		$query			= "
152
+		$query = "
153 153
 		SELECT 		post.ID, post.post_title, attr_val_dec.value as price_attribute, GROUP_CONCAT(postmeta.meta_key, '&sep&', postmeta.meta_value, '&&' ORDER BY postmeta.meta_key) as price
154 154
 			FROM 		$wpdb->posts as post
155 155
 		JOIN		$wpdb->postmeta as postmeta
@@ -162,15 +162,15 @@  discard block
 block discarded – undo
162 162
 			AND			postmeta.meta_key IN( '_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata' )
163 163
 		GROUP BY	post.ID";
164 164
 
165
-		$list_product	= $wpdb->get_results( $wpdb->prepare( $query, array( $entity_id, $attribute_id ) ) );
165
+		$list_product = $wpdb->get_results($wpdb->prepare($query, array($entity_id, $attribute_id)));
166 166
 
167
-		if( !empty( $list_product ) ) {
168
-			foreach( $list_product as $key_product => &$product ) {
167
+		if (!empty($list_product)) {
168
+			foreach ($list_product as $key_product => &$product) {
169 169
 				$product->price = explode('&&,', $product->price);
170
-				if(!empty($product->price) && is_array($product->price)) {
170
+				if (!empty($product->price) && is_array($product->price)) {
171 171
 					$array_price = array();
172
-					foreach($product->price as &$price) {
173
-						if(strpos( $price, '&&' ))
172
+					foreach ($product->price as &$price) {
173
+						if (strpos($price, '&&'))
174 174
 							$price = substr($price, 0, -2);
175 175
 
176 176
 						$tmp_price = explode('&sep&', $price);
@@ -178,35 +178,35 @@  discard block
 block discarded – undo
178 178
 						$price = maybe_unserialize($tmp_price[1]);
179 179
 
180 180
 						/** _wpshop_product_metadata */
181
-						if( $key == '_wpshop_product_metadata' ) {
182
-							$array_price[$key] =  ( $price_piloting_option == 'TTC' ) ? $price['product_price'] : $price['price_ht'];
181
+						if ($key == '_wpshop_product_metadata') {
182
+							$array_price[$key] = ($price_piloting_option == 'TTC') ? $price['product_price'] : $price['price_ht'];
183 183
 						}
184 184
 
185 185
 						/** _wps_price_infos */
186
-						if( $key == '_wps_price_infos' ) {
187
-							$array_price[$key] = !empty( $price['PRODUCT_PRICE'] ) ? $price['PRODUCT_PRICE'] : '-';
186
+						if ($key == '_wps_price_infos') {
187
+							$array_price[$key] = !empty($price['PRODUCT_PRICE']) ? $price['PRODUCT_PRICE'] : '-';
188 188
 						}
189 189
 
190
-						if( $key == '_product_price' ) {
191
-							$array_price[$key] = ( $price_piloting_option == 'TTC' ) ? $price : '-';
190
+						if ($key == '_product_price') {
191
+							$array_price[$key] = ($price_piloting_option == 'TTC') ? $price : '-';
192 192
 						}
193 193
 
194
-						if ( $key == '_wpshop_displayed_price' ) {
194
+						if ($key == '_wpshop_displayed_price') {
195 195
 							$array_price[$key] = $price;
196 196
 						}
197 197
 						unset($price);
198 198
 					}
199 199
 
200
-					$array_meta_list = array( '_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata', );
200
+					$array_meta_list = array('_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata',);
201 201
 
202
-					foreach( $array_meta_list as $meta_list ) {
203
-						if( !array_key_exists( $meta_list, $array_price ) ) {
202
+					foreach ($array_meta_list as $meta_list) {
203
+						if (!array_key_exists($meta_list, $array_price)) {
204 204
 							$array_price[$meta_list] = 0;
205 205
 						}
206 206
 					}
207 207
 
208 208
 					$product->price = $array_price;
209
-					if( $product->price_attribute === $product->price['_wpshop_product_metadata'] ) {
209
+					if ($product->price_attribute === $product->price['_wpshop_product_metadata']) {
210 210
 						unset($list_product[$key_product]);
211 211
 					}
212 212
 
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
 	 * @param int $pid L'id du produit
225 225
 	 * @return WP_Post
226 226
 	 */
227
-	public function get_thumbnail ( $pid ) {
228
-		if( empty( $pid ) )
227
+	public function get_thumbnail($pid) {
228
+		if (empty($pid))
229 229
 			return null;
230 230
 
231
-		$thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true );
231
+		$thumbnail_id = get_post_meta($pid, '_thumbnail_id', true);
232 232
 
233
-		if( empty( $thumbnail_id ) )
233
+		if (empty($thumbnail_id))
234 234
 			return null;
235 235
 
236 236
 		return $thumbnail_id;
@@ -243,9 +243,9 @@  discard block
 block discarded – undo
243 243
 	 * @param array $array_data The array data [integer][barcode] = 0111100001
244 244
 	 */
245 245
 	public function update_attributes_for_product($product_id, $array_data) {
246
-		if(!empty($array_data)) {
247
-			foreach($array_data as $type => $array) {
248
-				foreach($array as $name_attribute => $value_attribute) {
246
+		if (!empty($array_data)) {
247
+			foreach ($array_data as $type => $array) {
248
+				foreach ($array as $name_attribute => $value_attribute) {
249 249
 					$this->update_the_attribute_for_product($product_id, $type, $name_attribute, $value_attribute);
250 250
 				}
251 251
 			}
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 		$attribute_id = $wpdb->get_var($wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code="%s"', array($name_attribute)));
270 270
 
271 271
 		/** On vérifie s'il existe si c'est le cas, on update sinon on insert */
272
-		if(count($wpdb->get_row($wpdb->prepare('SELECT value_id FROM ' . WPSHOP_DBT_ATTRIBUTE . '_value_' . $type . ' WHERE entity_id=%d AND attribute_id IN(SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code="%s")', array($product_id, $name_attribute)))) > 0) {
272
+		if (count($wpdb->get_row($wpdb->prepare('SELECT value_id FROM ' . WPSHOP_DBT_ATTRIBUTE . '_value_' . $type . ' WHERE entity_id=%d AND attribute_id IN(SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code="%s")', array($product_id, $name_attribute)))) > 0) {
273 273
 			$wpdb->query(
274 274
 				$wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . '_value_' . $type . ' SET value="%s" WHERE entity_id=%d AND attribute_id=%d',
275 275
 					array($value_attribute, $product_id, $attribute_id)
@@ -295,13 +295,13 @@  discard block
 block discarded – undo
295 295
 	 * @param array $args [ 'id' ] L'id du produit
296 296
 	 * @return string
297 297
 	 */
298
-	public function wpshop_product_title( $args ) {
299
-		$output = __( 'No product has been found.', 'wpshop' );
298
+	public function wpshop_product_title($args) {
299
+		$output = __('No product has been found.', 'wpshop');
300 300
 
301
-		if ( !empty( $args ) && !empty( $args['pid'] ) ) {
301
+		if (!empty($args) && !empty($args['pid'])) {
302 302
 			global $wpdb;
303 303
 			$query = "SELECT post_title FROM {$wpdb->posts} WHERE ID = %d";
304
-			$output = $wpdb->get_var( $wpdb->prepare( $query, $args['pid'] ) );
304
+			$output = $wpdb->get_var($wpdb->prepare($query, $args['pid']));
305 305
 		}
306 306
 
307 307
 		return $output;
@@ -312,16 +312,16 @@  discard block
 block discarded – undo
312 312
 	 * @param array $args [ 'id' ] L'id du produit
313 313
 	 * @return string
314 314
 	 */
315
-	public function wpshop_product_content( $args ) {
316
-		$output = __( 'No product has been found.', 'wpshop' );
315
+	public function wpshop_product_content($args) {
316
+		$output = __('No product has been found.', 'wpshop');
317 317
 
318
-		if ( !empty( $args ) && !empty( $args['pid'] ) ) {
318
+		if (!empty($args) && !empty($args['pid'])) {
319 319
 			global $wpdb;
320 320
 			$query = "SELECT post_content FROM {$wpdb->posts} WHERE ID = %d";
321
-			$output = $wpdb->get_var( $wpdb->prepare( $query, $args['pid'] ) );
321
+			$output = $wpdb->get_var($wpdb->prepare($query, $args['pid']));
322 322
 		}
323 323
 
324
-		return nl2br( $output );
324
+		return nl2br($output);
325 325
 	}
326 326
 
327 327
 	/**
@@ -331,12 +331,12 @@  discard block
 block discarded – undo
331 331
 	 * 						[ size ] La taille de l'image. Peut être défini comme : small, medium ou full
332 332
 	 * @return string
333 333
 	 */
334
-	public function wpshop_product_thumbnail( $args ) {
334
+	public function wpshop_product_thumbnail($args) {
335 335
 		$url_thumbnail = WPSHOP_DEFAULT_PRODUCT_PICTURE;
336 336
 		$size = '20%';
337 337
 
338
-		if ( !empty( $args ) && !empty( $args['size'] ) ) {
339
-			switch ( $args['size'] ) {
338
+		if (!empty($args) && !empty($args['size'])) {
339
+			switch ($args['size']) {
340 340
 				case 'small':
341 341
 					$size = '20%';
342 342
 					break;
@@ -351,20 +351,20 @@  discard block
 block discarded – undo
351 351
 			}
352 352
 		}
353 353
 
354
-		if ( !empty( $args ) && !empty( $args['pid'] ) ) {
355
-			$thumbnail_id = $this->get_thumbnail( $args['pid'] );
354
+		if (!empty($args) && !empty($args['pid'])) {
355
+			$thumbnail_id = $this->get_thumbnail($args['pid']);
356 356
 
357
-			if( !empty( $thumbnail_id ) ) {
358
-				$attachment = get_post( $thumbnail_id );
357
+			if (!empty($thumbnail_id)) {
358
+				$attachment = get_post($thumbnail_id);
359 359
 
360
-				if( !empty( $attachment ) && !empty( $attachment->guid ) ) {
360
+				if (!empty($attachment) && !empty($attachment->guid)) {
361 361
 					$url_thumbnail = $attachment->guid;
362 362
 				}
363 363
 			}
364 364
 		}
365 365
 
366 366
 		ob_start();
367
-		require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_thumbnail" ) );
367
+		require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_thumbnail"));
368 368
 		$output = ob_get_clean();
369 369
 
370 370
 		return $output;
Please login to merge, or discard this patch.
Braces   +14 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 class wps_product_ctr {
3 5
 
4 6
 	/**
@@ -129,8 +131,7 @@  discard block
 block discarded – undo
129 131
 
130 132
 			if (($manage_stock_is_activated && $the_qty_is_in_stock) OR !$manage_stock_is_activated) {
131 133
 				return true;
132
-			}
133
-			else {
134
+			} else {
134 135
 				return __('You cannot add that amount to the cart since there is not enough stock.', 'wpshop');
135 136
 			}
136 137
 		}
@@ -170,8 +171,9 @@  discard block
 block discarded – undo
170 171
 				if(!empty($product->price) && is_array($product->price)) {
171 172
 					$array_price = array();
172 173
 					foreach($product->price as &$price) {
173
-						if(strpos( $price, '&&' ))
174
-							$price = substr($price, 0, -2);
174
+						if(strpos( $price, '&&' )) {
175
+													$price = substr($price, 0, -2);
176
+						}
175 177
 
176 178
 						$tmp_price = explode('&sep&', $price);
177 179
 						$key = $tmp_price[0];
@@ -225,13 +227,15 @@  discard block
 block discarded – undo
225 227
 	 * @return WP_Post
226 228
 	 */
227 229
 	public function get_thumbnail ( $pid ) {
228
-		if( empty( $pid ) )
229
-			return null;
230
+		if( empty( $pid ) ) {
231
+					return null;
232
+		}
230 233
 
231 234
 		$thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true );
232 235
 
233
-		if( empty( $thumbnail_id ) )
234
-			return null;
236
+		if( empty( $thumbnail_id ) ) {
237
+					return null;
238
+		}
235 239
 
236 240
 		return $thumbnail_id;
237 241
 	}
@@ -275,8 +279,7 @@  discard block
 block discarded – undo
275 279
 					array($value_attribute, $product_id, $attribute_id)
276 280
 				)
277 281
 			);
278
-		}
279
-		else {
282
+		} else {
280 283
 			/** Insert avec toutes les informations requise */
281 284
 			$wpdb->insert(WPSHOP_DBT_ATTRIBUTE . '_value_' . $type, array(
282 285
 					'attribute_id' 			=> $attribute_id,
Please login to merge, or discard this patch.
wps_product_mass_interface/controller/wps_product_mass_interface_ctr.php 4 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -158,6 +158,7 @@  discard block
 block discarded – undo
158 158
 	/**
159 159
 	 * Display pagination
160 160
 	 *
161
+	 * @param integer $current_page
161 162
 	 * @return string
162 163
 	 */
163 164
 	function get_products_pagination( $current_page, $attribute_set_id = 1 ) {
@@ -201,6 +202,9 @@  discard block
 block discarded – undo
201 202
 			return $output;
202 203
 			}
203 204
 
205
+	/**
206
+	 * @param integer $product_id
207
+	 */
204 208
 	function wps_product_attached_files( $product_id ) {
205 209
 		global $wpdb;
206 210
 		$output = '';
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -352,8 +352,8 @@  discard block
 block discarded – undo
352 352
 	}
353 353
 
354 354
 	/**
355
-	* Delete product list
356
-	**/
355
+	 * Delete product list
356
+	 **/
357 357
 	function wps_mass_delete_file() {
358 358
 		$status = false;
359 359
 		$file_id = (!empty($_POST['file_id']) ) ? intval($_POST['file_id']) : null;
@@ -366,8 +366,8 @@  discard block
 block discarded – undo
366 366
 	}
367 367
 
368 368
 	/**
369
-	* Update product files list
370
-	*/
369
+	 * Update product files list
370
+	 */
371 371
 	function wps_mass_edit_update_files_list() {
372 372
 		$status = false; $response = '';
373 373
 		$product_id = ( !empty($_POST['product_id']) ) ? intval($_POST['product_id']) : null;
Please login to merge, or discard this patch.
Spacing   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 /**
3 3
  * Main controller file for product mass modification module
4 4
  *
@@ -19,47 +19,47 @@  discard block
 block discarded – undo
19 19
 	 */
20 20
 	function __construct() {
21 21
 		// Add submenu
22
-		add_action('admin_menu', array( $this, 'register_mass_products_edit_submenu' ), 350 );
22
+		add_action('admin_menu', array($this, 'register_mass_products_edit_submenu'), 350);
23 23
 
24 24
 		// Declare Styles and JS Files
25
-		add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_scripts') );
26
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_css' ) );
27
-		add_action( 'admin_print_scripts', array( $this, 'admin_print_scripts' ) );
25
+		add_action('admin_enqueue_scripts', array($this, 'add_admin_scripts'));
26
+		add_action('admin_enqueue_scripts', array($this, 'admin_css'));
27
+		add_action('admin_print_scripts', array($this, 'admin_print_scripts'));
28 28
 
29 29
 		// Trigger ajax action
30
-		add_action( 'wp_ajax_wps_mass_edit_change_page', array( $this, 'wps_mass_edit_change_page') );
31
-		add_action( 'wp_ajax_wps_mass_edit_product_save_action', array( $this, 'wps_save_product_quick_interface') );
32
-		add_action( 'wp_ajax_wps_mass_interface_new_product_creation', array( $this, 'wps_mass_interface_new_product_creation' ) );
33
-		add_action( 'wp_ajax_wps_mass_delete_file', array( $this, 'wps_mass_delete_file' ) );
34
-		add_action( 'wp_ajax_wps_mass_edit_update_files_list', array( $this, 'wps_mass_edit_update_files_list' ) );
30
+		add_action('wp_ajax_wps_mass_edit_change_page', array($this, 'wps_mass_edit_change_page'));
31
+		add_action('wp_ajax_wps_mass_edit_product_save_action', array($this, 'wps_save_product_quick_interface'));
32
+		add_action('wp_ajax_wps_mass_interface_new_product_creation', array($this, 'wps_mass_interface_new_product_creation'));
33
+		add_action('wp_ajax_wps_mass_delete_file', array($this, 'wps_mass_delete_file'));
34
+		add_action('wp_ajax_wps_mass_edit_update_files_list', array($this, 'wps_mass_edit_update_files_list'));
35 35
 		// add_action( 'wap_ajax_wps_mass_delete_post', array( $this, 'wps_mass_delete_post' ) );
36 36
 	}
37 37
 
38 38
 	function register_mass_products_edit_submenu() {
39
-		add_submenu_page( 'edit.php?post_type=wpshop_product', __('Mass product edit', 'wpshop' ), __('Mass product edit', 'wpshop'), 'manage_options', 'mass_edit_interface', array($this, 'wps_display_mass_edit_interface'));
39
+		add_submenu_page('edit.php?post_type=wpshop_product', __('Mass product edit', 'wpshop'), __('Mass product edit', 'wpshop'), 'manage_options', 'mass_edit_interface', array($this, 'wps_display_mass_edit_interface'));
40 40
 	}
41 41
 
42 42
 	/**
43 43
 	 * Define the aministration pat styles
44 44
 	 */
45 45
 	function admin_css() {
46
-		wp_enqueue_style( 'wps-mass-product-update', WPS_PDCT_MASS_URL.'/assets/css/backend.css', '', WPS_PDCT_MASS_VERSION);
46
+		wp_enqueue_style('wps-mass-product-update', WPS_PDCT_MASS_URL . '/assets/css/backend.css', '', WPS_PDCT_MASS_VERSION);
47 47
 	}
48 48
 
49 49
 	/**
50 50
 	 * Add javascript to administration
51 51
 	 */
52 52
 	function add_admin_scripts() {
53
-		wp_enqueue_script( 'admin_product_js', WPS_PDCT_MASS_URL.'/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true);
53
+		wp_enqueue_script('admin_product_js', WPS_PDCT_MASS_URL . '/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true);
54 54
 		wp_enqueue_media();
55 55
 	}
56 56
 
57 57
 	function admin_print_scripts() {
58 58
 		$output = '<script type="text/javascript">';
59
-		$output .= 'var WPS_MASS_ERROR_INIT = "' .__( 'An error has occured, the page cannot be initialized', 'wpshop' ). '";';
60
-		$output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' .__( 'An error was occured, the new product cannot be created', 'wpshop' ). '";';
61
-		$output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' .__( 'You must select product to save', 'wpshop' ). '";';
62
-		$output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' .__( 'You will save selected products, are you sure to continue ?', 'wpshop' ). '";';
59
+		$output .= 'var WPS_MASS_ERROR_INIT = "' . __('An error has occured, the page cannot be initialized', 'wpshop') . '";';
60
+		$output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' . __('An error was occured, the new product cannot be created', 'wpshop') . '";';
61
+		$output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' . __('You must select product to save', 'wpshop') . '";';
62
+		$output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' . __('You will save selected products, are you sure to continue ?', 'wpshop') . '";';
63 63
 		$output .= '</script>';
64 64
 		echo $output;
65 65
 	}
@@ -71,15 +71,15 @@  discard block
 block discarded – undo
71 71
 	 *
72 72
 	 * @return array
73 73
 	 */
74
-	function check_attribute_to_display_for_quick_add( $attribute_list, $quick_add_form_attributes = array() ) {
75
-
76
-		if ( !empty( $attribute_list ) ) {
77
-			foreach( $attribute_list as $attributes_group ) {
78
-				foreach( $attributes_group as $attributes_sections ) {
79
-					if( !empty($attributes_sections) && !empty($attributes_sections['attributes']) ) {
80
-						foreach( $attributes_sections['attributes'] as $attribute_id => $att_def ) {
81
-							if( !empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes' ) {
82
-								$quick_add_form_attributes[ $attribute_id ] = $att_def;
74
+	function check_attribute_to_display_for_quick_add($attribute_list, $quick_add_form_attributes = array()) {
75
+
76
+		if (!empty($attribute_list)) {
77
+			foreach ($attribute_list as $attributes_group) {
78
+				foreach ($attributes_group as $attributes_sections) {
79
+					if (!empty($attributes_sections) && !empty($attributes_sections['attributes'])) {
80
+						foreach ($attributes_sections['attributes'] as $attribute_id => $att_def) {
81
+							if (!empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes') {
82
+								$quick_add_form_attributes[$attribute_id] = $att_def;
83 83
 							}
84 84
 						}
85 85
 					}
@@ -96,29 +96,29 @@  discard block
 block discarded – undo
96 96
 	 * @param integer $page
97 97
 	 * @return string
98 98
 	 */
99
-	function display_products_list( $default = 1, $page = 0  ) {
99
+	function display_products_list($default = 1, $page = 0) {
100 100
 		global $wpdb;
101 101
 		// Product entity
102
-		$product_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT );
102
+		$product_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
103 103
 
104 104
 		$user_id = get_current_user_id();
105 105
 		// Check product limit
106
-		$product_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true );
107
-		$product_limit = ( !empty($product_limit) ) ? $product_limit : 20;
106
+		$product_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true);
107
+		$product_limit = (!empty($product_limit)) ? $product_limit : 20;
108 108
 
109 109
 		// Get products for the current page
110 110
 		$wps_product_mass_interface_mdl = new wps_product_mass_interface_mdl();
111
-		$products = $wps_product_mass_interface_mdl->get_quick_interface_products( $default, $page, $product_limit );
111
+		$products = $wps_product_mass_interface_mdl->get_quick_interface_products($default, $page, $product_limit);
112 112
 
113 113
 		// Construct Table Head Data
114 114
 		$quick_add_form_attributes = array();
115 115
 		$get_attributes_quick_add_form = $wps_product_mass_interface_mdl->get_attributes_quick_add_form();
116
-		foreach( $get_attributes_quick_add_form as $quick_add_form_attribute ) {
116
+		foreach ($get_attributes_quick_add_form as $quick_add_form_attribute) {
117 117
 			$quick_add_form_attributes[$quick_add_form_attribute['id']] = $quick_add_form_attribute;
118 118
 		}
119 119
 
120 120
 		ob_start();
121
-		require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list" ) );
121
+		require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list"));
122 122
 		$output = ob_get_contents();
123 123
 		ob_end_clean();
124 124
 		return $output;
@@ -134,25 +134,25 @@  discard block
 block discarded – undo
134 134
 		$products_attributes_groups = $wps_product_mass_interface_mdl->get_product_attributes_sets();
135 135
 
136 136
 		$default = '';
137
-		if( !empty($products_attributes_groups) ) {
138
-			foreach( $products_attributes_groups as $key => $products_attributes_group ) {
139
-				if( $products_attributes_group->slug == 'free_product' ) {
140
-					unset( $products_attributes_groups[$key] );
137
+		if (!empty($products_attributes_groups)) {
138
+			foreach ($products_attributes_groups as $key => $products_attributes_group) {
139
+				if ($products_attributes_group->slug == 'free_product') {
140
+					unset($products_attributes_groups[$key]);
141 141
 				}
142
-				if( !empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes' ) {
142
+				if (!empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes') {
143 143
 					$default = $products_attributes_group->id;
144 144
 				}
145 145
 			}
146 146
 		}
147 147
 		// Check page
148
-		$page = ( !empty( $_GET[ 'page' ] ) && is_int( (int)$_GET[ 'page' ] ) && $_GET[ 'page' ] > 0 ) ? (int)($_GET[ 'page' ] - 1) : 0;
148
+		$page = (!empty($_GET['page']) && is_int((int)$_GET['page']) && $_GET['page'] > 0) ? (int)($_GET['page'] - 1) : 0;
149 149
 		// Display product tab
150
-		$product_list_interface = $this->display_products_list( $default, $page );
150
+		$product_list_interface = $this->display_products_list($default, $page);
151 151
 
152 152
 		// Get pagination
153
-		$pagination = $this->get_products_pagination( $page, $default );
153
+		$pagination = $this->get_products_pagination($page, $default);
154 154
 
155
-		require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface" ) );
155
+		require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface"));
156 156
 	}
157 157
 
158 158
 	/**
@@ -160,13 +160,13 @@  discard block
 block discarded – undo
160 160
 	 *
161 161
 	 * @return string
162 162
 	 */
163
-	function get_products_pagination( $current_page, $attribute_set_id = 1 ) {
163
+	function get_products_pagination($current_page, $attribute_set_id = 1) {
164 164
 		global $wpdb;
165 165
 		$user_id = get_current_user_id();
166 166
 		$output = '';
167 167
 		/**	Define the element number per page. If the user change the default value, take this value	*/
168
-		$one_page_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true );
169
-		$one_page_limit = ( !empty($one_page_limit) ) ? $one_page_limit : 20;
168
+		$one_page_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true);
169
+		$one_page_limit = (!empty($one_page_limit)) ? $one_page_limit : 20;
170 170
 
171 171
 		/**	Count the number of product existing in the shop	*/
172 172
 		$query = $wpdb->prepare(
@@ -178,37 +178,37 @@  discard block
 block discarded – undo
178 178
 				AND meta_value = %s
179 179
 				AND post_status IN ( 'publish', 'draft' )",
180 180
 				WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, '_wpshop_product_attribute_set_id', $attribute_set_id);
181
-		$products = $wpdb->get_var( $query );
181
+		$products = $wpdb->get_var($query);
182 182
 
183
-			if( !empty($products) ) {
183
+			if (!empty($products)) {
184 184
 			$args = array(
185 185
 			'base' => '%_%',
186
-			'format' => admin_url( 'admin-ajax.php?action=wps_add_quick_interface&page=%#%' ),
187
-					'current' => ( $current_page + 1 ),
188
-					'total' => ceil( $products / $one_page_limit ),
186
+			'format' => admin_url('admin-ajax.php?action=wps_add_quick_interface&page=%#%'),
187
+					'current' => ($current_page + 1),
188
+					'total' => ceil($products / $one_page_limit),
189 189
 						'type' => 'array',
190 190
 						'prev_next' => false,
191 191
 						'show_all' => true,
192 192
 			);
193
-			$paginate = paginate_links( $args );
193
+			$paginate = paginate_links($args);
194 194
 
195 195
 				$wps_product_ctr = new wps_product_ctr();
196 196
 				ob_start();
197
-				require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination" ) );
197
+				require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination"));
198 198
 				$output = ob_get_contents();
199 199
 			ob_end_clean();
200 200
 			}
201 201
 			return $output;
202 202
 			}
203 203
 
204
-	function wps_product_attached_files( $product_id ) {
204
+	function wps_product_attached_files($product_id) {
205 205
 		global $wpdb;
206 206
 		$output = '';
207
-		$query = $wpdb->prepare( 'SELECT * FROM ' .$wpdb->posts. ' WHERE post_parent = %d AND post_type = %s AND post_mime_type LIKE %s', $product_id, 'attachment', 'application%' );
208
-		$files = $wpdb->get_results( $query );
209
-		if( !empty($files) ) {
207
+		$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_parent = %d AND post_type = %s AND post_mime_type LIKE %s', $product_id, 'attachment', 'application%');
208
+		$files = $wpdb->get_results($query);
209
+		if (!empty($files)) {
210 210
 			ob_start();
211
-			require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list" ) );
211
+			require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list"));
212 212
 			$output = ob_get_contents();
213 213
 			ob_end_clean();
214 214
 		}
@@ -220,23 +220,23 @@  discard block
 block discarded – undo
220 220
 	 * AJAX - Change page action on mass edit product interface
221 221
 	 */
222 222
 	function wps_mass_edit_change_page() {
223
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
223
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
224 224
 
225
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) )
225
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_change_page'))
226 226
 			wp_die();
227 227
 
228 228
 		$status = false; $response = '';
229
-		$page = ( !empty($_POST['page_id']) ) ? intval( $_POST['page_id'] ) - 1 : 0;
230
-		$attribute_set_id = ( !empty($_POST['att_set_id']) ) ? intval( $_POST['att_set_id'] ) : 1;
231
-		if( !empty($attribute_set_id) ) {
229
+		$page = (!empty($_POST['page_id'])) ? intval($_POST['page_id']) - 1 : 0;
230
+		$attribute_set_id = (!empty($_POST['att_set_id'])) ? intval($_POST['att_set_id']) : 1;
231
+		if (!empty($attribute_set_id)) {
232 232
 			// Get tab
233
-			$response = $this->display_products_list( $attribute_set_id, $page );
234
-			$pagination = $this->get_products_pagination( $page, $attribute_set_id );
235
-			if( !empty($response) ) {
233
+			$response = $this->display_products_list($attribute_set_id, $page);
234
+			$pagination = $this->get_products_pagination($page, $attribute_set_id);
235
+			if (!empty($response)) {
236 236
 				$status = true;
237 237
 			}
238 238
 		}
239
-		echo json_encode( array( 'status' => $status, 'response' => $response, 'pagination' => $pagination ) );
239
+		echo json_encode(array('status' => $status, 'response' => $response, 'pagination' => $pagination));
240 240
 		wp_die();
241 241
 	}
242 242
 
@@ -244,30 +244,30 @@  discard block
 block discarded – undo
244 244
 	 * AJAX - Create a draft product and display the line allowing to edit informations for this product
245 245
 	 */
246 246
 	function wps_mass_interface_new_product_creation() {
247
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
247
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
248 248
 
249
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) )
249
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_interface_new_product_creation'))
250 250
 			wp_die();
251 251
 
252 252
 		global $wpdb;
253 253
 		$output = $pagination = '';
254 254
 		$status = false;
255 255
 
256
-		$new_product_id = wp_insert_post( array(
256
+		$new_product_id = wp_insert_post(array(
257 257
 				'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
258 258
 				'post_status' => 'publish',
259
-				'post_title' => __( 'New product', 'wpshop' ),
260
-		) );
259
+				'post_title' => __('New product', 'wpshop'),
260
+		));
261 261
 
262
-		if( !is_object($new_product_id) ) {
262
+		if (!is_object($new_product_id)) {
263 263
 			$status = true;
264 264
 		}
265
-		if ( !empty( $new_product_id ) ) {
266
-			$product_attribute_set_id = ( !empty($_POST['attributes_set']) ) ? intval( $_POST['attributes_set'] ) : 1;
267
-			update_post_meta( $new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id );
265
+		if (!empty($new_product_id)) {
266
+			$product_attribute_set_id = (!empty($_POST['attributes_set'])) ? intval($_POST['attributes_set']) : 1;
267
+			update_post_meta($new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id);
268 268
 		}
269 269
 
270
-		echo json_encode( array( 'status' => $status, 'response' => $output, 'pagination' => $pagination ) );
270
+		echo json_encode(array('status' => $status, 'response' => $output, 'pagination' => $pagination));
271 271
 		wp_die();
272 272
 	}
273 273
 
@@ -275,59 +275,59 @@  discard block
 block discarded – undo
275 275
 	 * AJAX - Save datas
276 276
 	 */
277 277
 	function wps_save_product_quick_interface() {
278
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
278
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
279 279
 
280
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) )
280
+		if (!wp_verify_nonce($_wpnonce, 'wps_save_product_quick_interface'))
281 281
 			wp_die();
282 282
 
283 283
 		global $wpdb;
284 284
 		$response = ''; $status = false;
285 285
 		$count_products_to_update = 0; $total_updated_products = 0;
286 286
 
287
-		$wps_product_quick_save = !empty( $_REQUEST['wps_product_quick_save'] ) ? (array) $_REQUEST['wps_product_quick_save'] : array();
288
-		$wps_mass_interface = !empty( $_REQUEST['wps_mass_interface'] ) ? (array) $_REQUEST['wps_mass_interface'] : array();
289
-		$wpshop_product_attribute = !empty( $_REQUEST['wpshop_product_attribute'] ) ? (array) $_REQUEST['wpshop_product_attribute'] : array();
287
+		$wps_product_quick_save = !empty($_REQUEST['wps_product_quick_save']) ? (array)$_REQUEST['wps_product_quick_save'] : array();
288
+		$wps_mass_interface = !empty($_REQUEST['wps_mass_interface']) ? (array)$_REQUEST['wps_mass_interface'] : array();
289
+		$wpshop_product_attribute = !empty($_REQUEST['wpshop_product_attribute']) ? (array)$_REQUEST['wpshop_product_attribute'] : array();
290 290
 
291
-		if( !empty($wps_product_quick_save) ) {
292
-			$count_products_to_update = count( $wps_product_quick_save );
293
-			foreach( $wps_product_quick_save as $product_to_save ) {
291
+		if (!empty($wps_product_quick_save)) {
292
+			$count_products_to_update = count($wps_product_quick_save);
293
+			foreach ($wps_product_quick_save as $product_to_save) {
294 294
 				$data_to_save = array();
295 295
 				// Update post
296
-				$updated_post = wp_update_post( array( 'ID' => $product_to_save,
297
-						'post_title' => sanitize_text_field( $wps_mass_interface[$product_to_save]['post_title'] ),
298
-						'post_content' => sanitize_text_field( $wps_mass_interface[$product_to_save]['post_content'] ),
296
+				$updated_post = wp_update_post(array('ID' => $product_to_save,
297
+						'post_title' => sanitize_text_field($wps_mass_interface[$product_to_save]['post_title']),
298
+						'post_content' => sanitize_text_field($wps_mass_interface[$product_to_save]['post_content']),
299 299
 						)
300 300
 				);
301 301
 				// Update attributes
302
-				if( !empty($updated_post) ) {
302
+				if (!empty($updated_post)) {
303 303
 					// Update Featured picture
304
-					if( !empty($wps_mass_interface[$product_to_save]['picture']) ) {
305
-						$thumbnail_exist = get_post_meta( $updated_post, '_thumbnail_id', true );
306
-						if($wps_mass_interface[$product_to_save]['picture'] != 'deleted') {
307
-							wp_update_post( array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post) );
308
-							update_post_meta( $updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture'] );
304
+					if (!empty($wps_mass_interface[$product_to_save]['picture'])) {
305
+						$thumbnail_exist = get_post_meta($updated_post, '_thumbnail_id', true);
306
+						if ($wps_mass_interface[$product_to_save]['picture'] != 'deleted') {
307
+							wp_update_post(array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post));
308
+							update_post_meta($updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture']);
309 309
 						}
310
-						elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) {
311
-							delete_post_meta( $updated_post, '_thumbnail_id' );
310
+						elseif ($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) {
311
+							delete_post_meta($updated_post, '_thumbnail_id');
312 312
 						}
313 313
 					}
314 314
 
315 315
 					// Update files datas
316
-					if( !empty($wps_mass_interface[$product_to_save]['files']) ) {
317
-						$files_data = explode( ',', sanitize_text_field( $_REQUEST['wps_mass_interface'][$product_to_save]['files'] ) );
318
-						if( !empty($files_data) && is_array($files_data) ) {
319
-							foreach( $files_data as $file_id ) {
320
-								if( !empty($file_id) ) {
321
-									wp_update_post( array('ID' => $file_id, 'post_parent' => $updated_post) );
316
+					if (!empty($wps_mass_interface[$product_to_save]['files'])) {
317
+						$files_data = explode(',', sanitize_text_field($_REQUEST['wps_mass_interface'][$product_to_save]['files']));
318
+						if (!empty($files_data) && is_array($files_data)) {
319
+							foreach ($files_data as $file_id) {
320
+								if (!empty($file_id)) {
321
+									wp_update_post(array('ID' => $file_id, 'post_parent' => $updated_post));
322 322
 								}
323 323
 							}
324 324
 						}
325 325
 					}
326 326
 
327
-					$data_to_save['post_ID'] = $data_to_save['product_id'] = intval( $product_to_save );
328
-					$data_to_save['wpshop_product_attribute'] = ( !empty($wpshop_product_attribute[ $product_to_save ]) ) ? $wpshop_product_attribute[ $product_to_save ] : array();
327
+					$data_to_save['post_ID'] = $data_to_save['product_id'] = intval($product_to_save);
328
+					$data_to_save['wpshop_product_attribute'] = (!empty($wpshop_product_attribute[$product_to_save])) ? $wpshop_product_attribute[$product_to_save] : array();
329 329
 
330
-					if(empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) {
330
+					if (empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) {
331 331
 						// Get current barcode
332 332
 						$wps_product_mdl = new wps_product_mdl();
333 333
 						$attid = wpshop_attributes::getElement('barcode', "'valid'", 'code')->id;
@@ -338,34 +338,34 @@  discard block
 block discarded – undo
338 338
 					$data_to_save['user_ID'] = get_current_user_id();
339 339
 					$data_to_save['action'] = 'editpost';
340 340
 
341
-					if( !empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true" ) {
342
-						wp_trash_post( $product_to_save );
341
+					if (!empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true") {
342
+						wp_trash_post($product_to_save);
343 343
 					}
344 344
 
345
-					if( !empty($product_to_save) && !empty( $data_to_save['user_ID'] ) ) {
345
+					if (!empty($product_to_save) && !empty($data_to_save['user_ID'])) {
346 346
 						$product_class = new wpshop_products();
347
-						$product_class->save_product_custom_informations( $product_to_save, $data_to_save );
347
+						$product_class->save_product_custom_informations($product_to_save, $data_to_save);
348 348
 						$total_updated_products++;
349 349
 					}
350 350
 				}
351 351
 			}
352 352
 		}
353 353
 		// Checking status
354
-		$status = ( $total_updated_products == $count_products_to_update ) ? true : false;
354
+		$status = ($total_updated_products == $count_products_to_update) ? true : false;
355 355
 
356
-		if( $status ) {
357
-			$response = sprintf( __( '%d products have been successfully updated', 'wpshop'), $total_updated_products );
356
+		if ($status) {
357
+			$response = sprintf(__('%d products have been successfully updated', 'wpshop'), $total_updated_products);
358 358
 		}
359 359
 		else {
360
-			if( !empty($total_updated_products) ) {
361
-				$response = sprintf( __( 'All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update );
360
+			if (!empty($total_updated_products)) {
361
+				$response = sprintf(__('All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update);
362 362
 			}
363 363
 			else {
364
-				$response = __( 'No product have been updated', 'wpshop');
364
+				$response = __('No product have been updated', 'wpshop');
365 365
 			}
366 366
 		}
367 367
 
368
-		echo json_encode( array('status' => $status, 'response' => $response ) );
368
+		echo json_encode(array('status' => $status, 'response' => $response));
369 369
 		wp_die();
370 370
 	}
371 371
 
@@ -373,18 +373,18 @@  discard block
 block discarded – undo
373 373
 	* Delete product list
374 374
 	**/
375 375
 	function wps_mass_delete_file() {
376
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
376
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
377 377
 
378
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) )
378
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_delete_file'))
379 379
 			wp_die();
380 380
 
381 381
 		$status = false;
382
-		$file_id = (!empty($_POST['file_id']) ) ? intval($_POST['file_id']) : null;
383
-		if( !empty($file_id) ) {
384
-			wp_update_post( array('ID' => $file_id, 'post_parent' => 0) );
382
+		$file_id = (!empty($_POST['file_id'])) ? intval($_POST['file_id']) : null;
383
+		if (!empty($file_id)) {
384
+			wp_update_post(array('ID' => $file_id, 'post_parent' => 0));
385 385
 			$status = true;
386 386
 		}
387
-		echo json_encode( array( 'status' => $status ) );
387
+		echo json_encode(array('status' => $status));
388 388
 		wp_die();
389 389
 	}
390 390
 
@@ -392,32 +392,32 @@  discard block
 block discarded – undo
392 392
 	* Update product files list
393 393
 	*/
394 394
 	function wps_mass_edit_update_files_list() {
395
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
395
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
396 396
 
397
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) )
397
+		if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_update_files_list'))
398 398
 			wp_die();
399 399
 
400 400
 		$status = false; $response = '';
401
-		$product_id = ( !empty($_POST['product_id']) ) ? intval($_POST['product_id']) : null;
402
-		$files = ( !empty($_POST['files']) ) ? intval($_POST['files']) : null;
403
-		if( !empty($product_id ) ) {
401
+		$product_id = (!empty($_POST['product_id'])) ? intval($_POST['product_id']) : null;
402
+		$files = (!empty($_POST['files'])) ? intval($_POST['files']) : null;
403
+		if (!empty($product_id)) {
404 404
 			// Update files datas
405
-			if( !empty($files) ) {
406
-				$files_data = explode( ',', $files );
407
-				if( !empty($files_data) && is_array($files_data) ) {
408
-					foreach( $files_data as $file_id ) {
409
-						if( !empty($file_id) ) {
410
-							wp_update_post( array('ID' => $file_id, 'post_parent' => $product_id) );
405
+			if (!empty($files)) {
406
+				$files_data = explode(',', $files);
407
+				if (!empty($files_data) && is_array($files_data)) {
408
+					foreach ($files_data as $file_id) {
409
+						if (!empty($file_id)) {
410
+							wp_update_post(array('ID' => $file_id, 'post_parent' => $product_id));
411 411
 						}
412 412
 					}
413 413
 				}
414 414
 			}
415 415
 
416 416
 
417
-			$response = $this->wps_product_attached_files( $product_id );
417
+			$response = $this->wps_product_attached_files($product_id);
418 418
 			$status = true;
419 419
 		}
420
-		echo json_encode( array( 'status' => $status, 'response' => $response ) );
420
+		echo json_encode(array('status' => $status, 'response' => $response));
421 421
 		wp_die();
422 422
 	}
423 423
 
Please login to merge, or discard this patch.
Braces   +21 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 /**
3 5
  * Main controller file for product mass modification module
4 6
  *
@@ -222,8 +224,9 @@  discard block
 block discarded – undo
222 224
 	function wps_mass_edit_change_page() {
223 225
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
224 226
 
225
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) )
226
-			wp_die();
227
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) ) {
228
+					wp_die();
229
+		}
227 230
 
228 231
 		$status = false; $response = '';
229 232
 		$page = ( !empty($_POST['page_id']) ) ? intval( $_POST['page_id'] ) - 1 : 0;
@@ -246,8 +249,9 @@  discard block
 block discarded – undo
246 249
 	function wps_mass_interface_new_product_creation() {
247 250
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
248 251
 
249
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) )
250
-			wp_die();
252
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) ) {
253
+					wp_die();
254
+		}
251 255
 
252 256
 		global $wpdb;
253 257
 		$output = $pagination = '';
@@ -277,8 +281,9 @@  discard block
 block discarded – undo
277 281
 	function wps_save_product_quick_interface() {
278 282
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
279 283
 
280
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) )
281
-			wp_die();
284
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) ) {
285
+					wp_die();
286
+		}
282 287
 
283 288
 		global $wpdb;
284 289
 		$response = ''; $status = false;
@@ -306,8 +311,7 @@  discard block
 block discarded – undo
306 311
 						if($wps_mass_interface[$product_to_save]['picture'] != 'deleted') {
307 312
 							wp_update_post( array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post) );
308 313
 							update_post_meta( $updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture'] );
309
-						}
310
-						elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) {
314
+						} elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) {
311 315
 							delete_post_meta( $updated_post, '_thumbnail_id' );
312 316
 						}
313 317
 					}
@@ -355,12 +359,10 @@  discard block
 block discarded – undo
355 359
 
356 360
 		if( $status ) {
357 361
 			$response = sprintf( __( '%d products have been successfully updated', 'wpshop'), $total_updated_products );
358
-		}
359
-		else {
362
+		} else {
360 363
 			if( !empty($total_updated_products) ) {
361 364
 				$response = sprintf( __( 'All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update );
362
-			}
363
-			else {
365
+			} else {
364 366
 				$response = __( 'No product have been updated', 'wpshop');
365 367
 			}
366 368
 		}
@@ -375,8 +377,9 @@  discard block
 block discarded – undo
375 377
 	function wps_mass_delete_file() {
376 378
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
377 379
 
378
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) )
379
-			wp_die();
380
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) ) {
381
+					wp_die();
382
+		}
380 383
 
381 384
 		$status = false;
382 385
 		$file_id = (!empty($_POST['file_id']) ) ? intval($_POST['file_id']) : null;
@@ -394,8 +397,9 @@  discard block
 block discarded – undo
394 397
 	function wps_mass_edit_update_files_list() {
395 398
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
396 399
 
397
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) )
398
-			wp_die();
400
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) ) {
401
+					wp_die();
402
+		}
399 403
 
400 404
 		$status = false; $response = '';
401 405
 		$product_id = ( !empty($_POST['product_id']) ) ? intval($_POST['product_id']) : null;
Please login to merge, or discard this patch.
modules/wps_product_mass_interface/model/wps_product_mass_interface_mdl.php 3 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,8 +16,7 @@
 block discarded – undo
16 16
 
17 17
 	/**
18 18
 	 * Returns Products with post data and its attributes configuration
19
-	 * @param integer $limit
20
-	 * @param integer $count_products
19
+	 * @param integer $attribute_set_id
21 20
 	 * @return array
22 21
 	 */
23 22
 	function get_quick_interface_products( $attribute_set_id, $start_limit = 0, $nb_product_per_page = 20 ) {
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 /**
3 3
  * Model file for product mass modification module
4 4
  *
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 * @param integer $count_products
21 21
 	 * @return array
22 22
 	 */
23
-	function get_quick_interface_products( $attribute_set_id, $start_limit = 0, $nb_product_per_page = 20 ) {
23
+	function get_quick_interface_products($attribute_set_id, $start_limit = 0, $nb_product_per_page = 20) {
24 24
 		global $wpdb;
25 25
 
26 26
 		$products_data = array();
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
 				AND meta_key = %s
35 35
 				AND meta_value = %s
36 36
 			ORDER BY ID DESC
37
-			LIMIT " . $start_limit * $nb_product_per_page . ", " .$nb_product_per_page .""
37
+			LIMIT " . $start_limit * $nb_product_per_page . ", " . $nb_product_per_page . ""
38 38
 			, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, '_wpshop_product_attribute_set_id', $attribute_set_id );
39
-		$products = $wpdb->get_results( $query );
39
+		$products = $wpdb->get_results($query);
40 40
 
41
-		if( !empty($products) ) {
42
-			foreach( $products as $product ) {
41
+		if (!empty($products)) {
42
+			foreach ($products as $product) {
43 43
 				// For each product stock Post Datas and attributes definition
44 44
 				$tmp = array();
45 45
 				$tmp['post_datas'] = $product;
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
 
55 55
 	function get_product_attributes_sets() {
56 56
 		global $wpdb;
57
-		$product_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT );
58
-		$query = $wpdb->prepare( 'SELECT * FROM '. WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s', $product_entity_id, 'valid' );
59
-		$attributes_groups = $wpdb->get_results( $query );
57
+		$product_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
58
+		$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s', $product_entity_id, 'valid');
59
+		$attributes_groups = $wpdb->get_results($query);
60 60
 
61 61
 		return $attributes_groups;
62 62
 	}
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 
65 65
 	function get_attributes_quick_add_form() {
66 66
 		global $wpdb;
67
-		$product_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT );
68
-		$query = $wpdb->prepare( 'SELECT * FROM '. WPSHOP_DBT_ATTRIBUTE . ' WHERE entity_id = %d AND is_used_in_quick_add_form = %s AND status = %s', $product_entity_id, 'yes', 'valid' );
69
-		$attributes = $wpdb->get_results( $query, ARRAY_A );
67
+		$product_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
68
+		$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE entity_id = %d AND is_used_in_quick_add_form = %s AND status = %s', $product_entity_id, 'yes', 'valid');
69
+		$attributes = $wpdb->get_results($query, ARRAY_A);
70 70
 	
71 71
 		return $attributes;
72 72
 	}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
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
  *
Please login to merge, or discard this patch.
includes/modules/wps_rewrites/wps_rewrites.php 3 patches
Doc Comments   +20 added lines patch added patch discarded remove patch
@@ -78,6 +78,11 @@  discard block
 block discarded – undo
78 78
 			}
79 79
 		}
80 80
 	}
81
+
82
+	/**
83
+	 * @param string $slug
84
+	 * @param string $separator
85
+	 */
81 86
 	private function rewrite_term_hierarchy( $parent, &$rewrite, $slug, $separator ) {
82 87
 		$childs = get_terms( $this->taxonomy, array( 'parent' => $parent->term_id, 'hide_empty' => false ) );
83 88
 		foreach( $childs as $child ) {
@@ -115,6 +120,11 @@  discard block
 block discarded – undo
115 120
 		}
116 121
 		return $permalink;
117 122
 	}
123
+
124
+	/**
125
+	 * @param string $permalink
126
+	 * @param string $separator
127
+	 */
118 128
 	private function permalink_term_hierarchy( $term, &$permalink, $taxonomy, $separator ) {
119 129
 		if( $term->parent == 0 ) {
120 130
 			$permalink = $term->slug . $separator . $permalink;
@@ -220,6 +230,11 @@  discard block
 block discarded – undo
220 230
 			}
221 231
 		}
222 232
 	}
233
+
234
+	/**
235
+	 * @param string $slug
236
+	 * @param string $separator
237
+	 */
223 238
 	private function rewrite_term_hierarchy( $parent, &$rewrite, $slug, $separator ) {
224 239
 		$rewrite[] = $slug . $parent->slug . $separator;
225 240
 		$childs = get_terms( $this->taxonomy, array( 'parent' => $parent->term_id, 'hide_empty' => false ) );
@@ -281,6 +296,11 @@  discard block
 block discarded – undo
281 296
 		}
282 297
 		return $permalink;
283 298
 	}
299
+
300
+	/**
301
+	 * @param string $permalink
302
+	 * @param string $separator
303
+	 */
284 304
 	private function permalink_term_hierarchy( $term, &$permalink, $taxonomy, $separator ) {
285 305
 		if( $term->parent == 0 ) {
286 306
 			$permalink = $term->slug . $separator . $permalink;
Please login to merge, or discard this patch.
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 // Rewrite wpshop_categories
4
-$options = get_option( 'wpshop_catalog_categories_option', null );
4
+$options = get_option('wpshop_catalog_categories_option', null);
5 5
 $slug = !empty($options['wpshop_catalog_categories_slug']) ? $options['wpshop_catalog_categories_slug'] : WPSHOP_CATALOG_PRODUCT_NO_CATEGORY;
6
-( empty( $options['wpshop_catalog_categories_slug'] ) || $options['wpshop_catalog_categories_slug'] == '/' ) ? new Custom_Taxonomy_Rewrite( WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $slug, false ) : false;
6
+(empty($options['wpshop_catalog_categories_slug']) || $options['wpshop_catalog_categories_slug'] == '/') ? new Custom_Taxonomy_Rewrite(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $slug, false) : false;
7 7
 
8 8
 // Rewrite wpshop_products
9
-$options = get_option( 'wpshop_catalog_product_option', null );
10
-$slug = !empty( $options['wpshop_catalog_product_slug'] ) ? $options['wpshop_catalog_product_slug'] : '/';
11
-$categories = !empty( $options['wpshop_catalog_product_slug_with_category'] );
12
-( empty( $options['wpshop_catalog_product_slug'] ) || $options['wpshop_catalog_product_slug'] == '/' ) ? new Custom_Post_Type_Rewrite( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, $slug, $categories ) : false;
9
+$options = get_option('wpshop_catalog_product_option', null);
10
+$slug = !empty($options['wpshop_catalog_product_slug']) ? $options['wpshop_catalog_product_slug'] : '/';
11
+$categories = !empty($options['wpshop_catalog_product_slug_with_category']);
12
+(empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') ? new Custom_Post_Type_Rewrite(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, $slug, $categories) : false;
13 13
 
14 14
 class Custom_Taxonomy_Rewrite {
15 15
 	private $post_type;
@@ -17,95 +17,95 @@  discard block
 block discarded – undo
17 17
 	private $enable_rewrites;
18 18
 	private $use_slug;
19 19
 	private $use_hierarchy_cat_slug;
20
-	public function __construct( $taxonomy, $post_type, $slug = '/', $hierarchy = false ) {
20
+	public function __construct($taxonomy, $post_type, $slug = '/', $hierarchy = false) {
21 21
 		$this->post_type = $post_type;
22 22
 		$this->taxonomy = $taxonomy;
23 23
 		$this->use_slug = $slug;
24 24
 		$this->use_hierarchy_cat_slug = $hierarchy;
25
-		add_action( 'init', array( $this, 'rewrite' ), 11 );
26
-		add_action( 'created_' . $this->taxonomy, array( $this, 'flush_rewrite' ) );
27
-		add_action( 'edited_' . $this->taxonomy, array( $this, 'flush_rewrite' ) );
28
-		add_action( 'delete_' . $this->taxonomy, array( $this, 'flush_rewrite' ) );
29
-		add_filter( 'term_link', array( $this, 'permalink' ), 10, 3 );
25
+		add_action('init', array($this, 'rewrite'), 11);
26
+		add_action('created_' . $this->taxonomy, array($this, 'flush_rewrite'));
27
+		add_action('edited_' . $this->taxonomy, array($this, 'flush_rewrite'));
28
+		add_action('delete_' . $this->taxonomy, array($this, 'flush_rewrite'));
29
+		add_filter('term_link', array($this, 'permalink'), 10, 3);
30 30
 	}
31 31
 	public function rewrite() {
32 32
 		global $wp_rewrite;
33 33
 		$this->enable_rewrites = $wp_rewrite->use_trailing_slashes;
34
-		if( $this->enable_rewrites ) {
35
-			if( empty( $this->use_slug ) || $this->use_slug == '/' ) {
36
-				if( $this->use_hierarchy_cat_slug ) {
34
+		if ($this->enable_rewrites) {
35
+			if (empty($this->use_slug) || $this->use_slug == '/') {
36
+				if ($this->use_hierarchy_cat_slug) {
37 37
 					$slug = '';
38 38
 					$rewrite = array();
39
-					$terms = get_terms( $this->taxonomy, array( 'parent' => 0, 'hide_empty' => false ) );
40
-					foreach( $terms as $term ) {
41
-						$this->rewrite_term_hierarchy( $term, $rewrite, $slug, '/' );
39
+					$terms = get_terms($this->taxonomy, array('parent' => 0, 'hide_empty' => false));
40
+					foreach ($terms as $term) {
41
+						$this->rewrite_term_hierarchy($term, $rewrite, $slug, '/');
42 42
 					}
43
-					foreach( $rewrite as $way ) {
44
-						add_rewrite_rule( $way . 'feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
45
-						add_rewrite_rule( $way . '(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
46
-						add_rewrite_rule( $way . 'page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top' );
47
-						add_rewrite_rule( $way . '?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top' );
43
+					foreach ($rewrite as $way) {
44
+						add_rewrite_rule($way . 'feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
45
+						add_rewrite_rule($way . '(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
46
+						add_rewrite_rule($way . 'page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top');
47
+						add_rewrite_rule($way . '?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top');
48 48
 					}
49 49
 				} else {
50
-					$terms = get_terms( $this->taxonomy, array( 'fields' => 'id=>slug', 'hide_empty' => false ) );
51
-					foreach( $terms as $term ) {
52
-						add_rewrite_rule( '(' . $term . ')/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
53
-						add_rewrite_rule( '(' . $term . ')/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
54
-						add_rewrite_rule( '(' . $term . ')/page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top' );
55
-						add_rewrite_rule( '(' . $term . ')/?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top' );
50
+					$terms = get_terms($this->taxonomy, array('fields' => 'id=>slug', 'hide_empty' => false));
51
+					foreach ($terms as $term) {
52
+						add_rewrite_rule('(' . $term . ')/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
53
+						add_rewrite_rule('(' . $term . ')/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
54
+						add_rewrite_rule('(' . $term . ')/page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top');
55
+						add_rewrite_rule('(' . $term . ')/?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top');
56 56
 					}
57 57
 				}
58 58
 			} else {
59
-				if( $this->use_hierarchy_cat_slug ) {
59
+				if ($this->use_hierarchy_cat_slug) {
60 60
 					$slug = '/';
61 61
 					$rewrite = array();
62
-					$terms = get_terms( $this->taxonomy, array( 'parent' => 0, 'hide_empty' => false ) );
63
-					foreach( $terms as $term ) {
64
-						$this->rewrite_term_hierarchy( $term, $rewrite, $slug, '/' );
62
+					$terms = get_terms($this->taxonomy, array('parent' => 0, 'hide_empty' => false));
63
+					foreach ($terms as $term) {
64
+						$this->rewrite_term_hierarchy($term, $rewrite, $slug, '/');
65 65
 					}
66
-					foreach( $rewrite as $way ) {
67
-						add_rewrite_rule( $this->use_slug . $way . 'feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
68
-						add_rewrite_rule( $this->use_slug . $way . '(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
69
-						add_rewrite_rule( $this->use_slug . $way . 'page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top' );
70
-						add_rewrite_rule( $this->use_slug . $way . '?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top' );
66
+					foreach ($rewrite as $way) {
67
+						add_rewrite_rule($this->use_slug . $way . 'feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
68
+						add_rewrite_rule($this->use_slug . $way . '(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
69
+						add_rewrite_rule($this->use_slug . $way . 'page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top');
70
+						add_rewrite_rule($this->use_slug . $way . '?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top');
71 71
 					}
72 72
 				} else {
73
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
74
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' );
75
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top' );
76
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top' );
73
+					add_rewrite_rule($this->use_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
74
+					add_rewrite_rule($this->use_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top');
75
+					add_rewrite_rule($this->use_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top');
76
+					add_rewrite_rule($this->use_slug . '/([^/]+)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top');
77 77
 				}
78 78
 			}
79 79
 		}
80 80
 	}
81
-	private function rewrite_term_hierarchy( $parent, &$rewrite, $slug, $separator ) {
82
-		$childs = get_terms( $this->taxonomy, array( 'parent' => $parent->term_id, 'hide_empty' => false ) );
83
-		foreach( $childs as $child ) {
84
-			$this->rewrite_term_hierarchy( $child, $rewrite, $slug . $parent->slug . $separator, $separator );
81
+	private function rewrite_term_hierarchy($parent, &$rewrite, $slug, $separator) {
82
+		$childs = get_terms($this->taxonomy, array('parent' => $parent->term_id, 'hide_empty' => false));
83
+		foreach ($childs as $child) {
84
+			$this->rewrite_term_hierarchy($child, $rewrite, $slug . $parent->slug . $separator, $separator);
85 85
 		}
86 86
 		$rewrite[] = $slug . '(' . $parent->slug . ')' . $separator;
87 87
 	}
88 88
 	public function flush_rewrite() {
89
-		if( $this->enable_rewrites ) {
89
+		if ($this->enable_rewrites) {
90 90
 			$this->rewrite();
91 91
 			flush_rewrite_rules();
92 92
 		}
93 93
 	}
94
-	public function permalink( $permalink, $term, $taxonomy ) {
95
-		if( $this->enable_rewrites ) {
96
-			if( $taxonomy === $this->taxonomy ) {
97
-				if( empty( $this->use_slug ) || $this->use_slug == '/' ) {
98
-					if( $this->use_hierarchy_cat_slug ) {
94
+	public function permalink($permalink, $term, $taxonomy) {
95
+		if ($this->enable_rewrites) {
96
+			if ($taxonomy === $this->taxonomy) {
97
+				if (empty($this->use_slug) || $this->use_slug == '/') {
98
+					if ($this->use_hierarchy_cat_slug) {
99 99
 						$term_permalink = '';
100
-						$this->permalink_term_hierarchy( $term, $term_permalink, $taxonomy, '/' );
100
+						$this->permalink_term_hierarchy($term, $term_permalink, $taxonomy, '/');
101 101
 						$permalink = get_site_url() . '/' . $term_permalink;
102 102
 					} else {
103 103
 						$permalink = get_site_url() . '/' . $term->slug;
104 104
 					}
105 105
 				} else {
106
-					if( $this->use_hierarchy_cat_slug ) {
106
+					if ($this->use_hierarchy_cat_slug) {
107 107
 						$term_permalink = '';
108
-						$this->permalink_term_hierarchy( $term, $term_permalink, $taxonomy, '/' );
108
+						$this->permalink_term_hierarchy($term, $term_permalink, $taxonomy, '/');
109 109
 						$permalink = get_site_url() . '/' . $this->use_slug . '/' . $term_permalink;
110 110
 					} else {
111 111
 						$permalink = get_site_url() . '/' . $this->use_slug . '/' . $term->slug;
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
 		}
116 116
 		return $permalink;
117 117
 	}
118
-	private function permalink_term_hierarchy( $term, &$permalink, $taxonomy, $separator ) {
119
-		if( $term->parent == 0 ) {
118
+	private function permalink_term_hierarchy($term, &$permalink, $taxonomy, $separator) {
119
+		if ($term->parent == 0) {
120 120
 			$permalink = $term->slug . $separator . $permalink;
121 121
 		} else {
122 122
 			$permalink = $term->slug . $separator . $permalink;
123
-			$term_parent = get_term( $term->parent, $taxonomy );
124
-			$this->permalink_term_hierarchy( $term_parent, $permalink, $taxonomy, $separator );
123
+			$term_parent = get_term($term->parent, $taxonomy);
124
+			$this->permalink_term_hierarchy($term_parent, $permalink, $taxonomy, $separator);
125 125
 		}
126 126
 	}
127 127
 }
@@ -133,122 +133,122 @@  discard block
 block discarded – undo
133 133
 	private $use_slug;
134 134
 	private $use_cat_slug;
135 135
 	private $use_hierarchy_cat_slug;
136
-	public function __construct( $post_type, $taxonomy, $slug = '/', $categories = false ) {
136
+	public function __construct($post_type, $taxonomy, $slug = '/', $categories = false) {
137 137
 		$this->post_type = $post_type;
138 138
 		$this->taxonomy = $taxonomy;
139 139
 		$this->use_slug = $slug;
140
-		if( is_bool( $categories ) ) {
140
+		if (is_bool($categories)) {
141 141
 			$this->use_cat_slug = $categories;
142 142
 			$this->use_hierarchy_cat_slug = false;
143
-		} elseif( $categories == 'hierarchy' ) {
143
+		} elseif ($categories == 'hierarchy') {
144 144
 			$this->use_cat_slug = true;
145 145
 			$this->use_hierarchy_cat_slug = true;
146 146
 		}
147
-		add_action( 'init', array( $this, 'rewrite' ), 11 );
148
-		add_action( 'created_' . $this->taxonomy, array( $this, 'flush_rewrite' ) );
149
-		add_action( 'edited_' . $this->taxonomy, array( $this, 'flush_rewrite' ) );
150
-		add_action( 'delete_' . $this->taxonomy, array( $this, 'flush_rewrite' ) );
151
-		add_filter( 'post_type_link', array( $this, 'permalink' ), 10, 3 );
152
-		add_action( 'pre_get_posts', array( $this, 'query' ) );
147
+		add_action('init', array($this, 'rewrite'), 11);
148
+		add_action('created_' . $this->taxonomy, array($this, 'flush_rewrite'));
149
+		add_action('edited_' . $this->taxonomy, array($this, 'flush_rewrite'));
150
+		add_action('delete_' . $this->taxonomy, array($this, 'flush_rewrite'));
151
+		add_filter('post_type_link', array($this, 'permalink'), 10, 3);
152
+		add_action('pre_get_posts', array($this, 'query'));
153 153
 	}
154 154
 	public function rewrite() {
155 155
 		global $wp_rewrite;
156 156
 		$this->enable_rewrites = $wp_rewrite->use_trailing_slashes;
157
-		if( $this->enable_rewrites ) {
158
-			if( empty( $this->use_slug ) || $this->use_slug == '/' ) {
159
-				if( $this->use_cat_slug ) {
160
-					if( $this->use_hierarchy_cat_slug ) {
157
+		if ($this->enable_rewrites) {
158
+			if (empty($this->use_slug) || $this->use_slug == '/') {
159
+				if ($this->use_cat_slug) {
160
+					if ($this->use_hierarchy_cat_slug) {
161 161
 						add_rewrite_tag('%taxonomies%', '(.*)');
162 162
 						$slug = '(';
163 163
 						$rewrite = array();
164
-						$terms = get_terms( $this->taxonomy, array( 'parent' => 0, 'hide_empty' => false ) );
165
-						foreach( $terms as $term ) {
166
-							$this->rewrite_term_hierarchy( $term, $rewrite, $slug, '/' );
164
+						$terms = get_terms($this->taxonomy, array('parent' => 0, 'hide_empty' => false));
165
+						foreach ($terms as $term) {
166
+							$this->rewrite_term_hierarchy($term, $rewrite, $slug, '/');
167 167
 						}
168
-						foreach( array_reverse( $rewrite ) as $way ) {
169
-							add_rewrite_rule( $way . ')([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
170
-							add_rewrite_rule( $way . ')([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
171
-							add_rewrite_rule( $way . ')([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top' );
172
-							add_rewrite_rule( $way . ')([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top' );
168
+						foreach (array_reverse($rewrite) as $way) {
169
+							add_rewrite_rule($way . ')([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
170
+							add_rewrite_rule($way . ')([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
171
+							add_rewrite_rule($way . ')([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top');
172
+							add_rewrite_rule($way . ')([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top');
173 173
 						}
174 174
 					} else {
175 175
 						add_rewrite_tag('%taxonomies%', '(.*)');
176
-						$terms = get_terms( $this->taxonomy, array( 'fields' => 'id=>slug', 'hide_empty' => false ) );
177
-						foreach( $terms as $term ) {
178
-							add_rewrite_rule( '(' . $term . ')/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
179
-							add_rewrite_rule( '(' . $term . ')/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
180
-							add_rewrite_rule( '(' . $term . ')/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top' );
181
-							add_rewrite_rule( '(' . $term . ')/([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top' );
176
+						$terms = get_terms($this->taxonomy, array('fields' => 'id=>slug', 'hide_empty' => false));
177
+						foreach ($terms as $term) {
178
+							add_rewrite_rule('(' . $term . ')/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
179
+							add_rewrite_rule('(' . $term . ')/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
180
+							add_rewrite_rule('(' . $term . ')/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top');
181
+							add_rewrite_rule('(' . $term . ')/([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top');
182 182
 						}
183 183
 					}
184 184
 				} /*else {
185 185
 					Only in the query func
186 186
 				} */
187 187
 			} else {
188
-				if( $this->use_cat_slug ) {
189
-					if( $this->use_hierarchy_cat_slug ) {
188
+				if ($this->use_cat_slug) {
189
+					if ($this->use_hierarchy_cat_slug) {
190 190
 						add_rewrite_tag('%taxonomies%', '(.*)');
191 191
 						$slug = '/(';
192 192
 						$rewrite = array();
193
-						$terms = get_terms( $this->taxonomy, array( 'parent' => 0, 'hide_empty' => false ) );
194
-						foreach( $terms as $term ) {
195
-							$this->rewrite_term_hierarchy( $term, $rewrite, $slug, '/' );
193
+						$terms = get_terms($this->taxonomy, array('parent' => 0, 'hide_empty' => false));
194
+						foreach ($terms as $term) {
195
+							$this->rewrite_term_hierarchy($term, $rewrite, $slug, '/');
196 196
 						}
197
-						foreach( array_reverse( $rewrite ) as $way ) {
198
-							add_rewrite_rule( $this->use_slug . $way . ')([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
199
-							add_rewrite_rule( $this->use_slug . $way . ')([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
200
-							add_rewrite_rule( $this->use_slug . $way . ')([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top' );
201
-							add_rewrite_rule( $this->use_slug . $way . ')([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top' );
197
+						foreach (array_reverse($rewrite) as $way) {
198
+							add_rewrite_rule($this->use_slug . $way . ')([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
199
+							add_rewrite_rule($this->use_slug . $way . ')([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
200
+							add_rewrite_rule($this->use_slug . $way . ')([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top');
201
+							add_rewrite_rule($this->use_slug . $way . ')([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top');
202 202
 						}
203 203
 					} else {
204 204
 						add_rewrite_tag('%taxonomies%', '(.*)');
205
-						$terms = get_terms( $this->taxonomy, array( 'fields' => 'id=>slug', 'hide_empty' => false ) );
206
-						foreach( $terms as $term ) {
207
-							add_rewrite_rule( $this->use_slug . '/(' . $term . ')/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
208
-							add_rewrite_rule( $this->use_slug . '/(' . $term . ')/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' );
209
-							add_rewrite_rule( $this->use_slug . '/(' . $term . ')/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top' );
210
-							add_rewrite_rule( $this->use_slug . '/(' . $term . ')/([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top' );
205
+						$terms = get_terms($this->taxonomy, array('fields' => 'id=>slug', 'hide_empty' => false));
206
+						foreach ($terms as $term) {
207
+							add_rewrite_rule($this->use_slug . '/(' . $term . ')/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
208
+							add_rewrite_rule($this->use_slug . '/(' . $term . ')/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top');
209
+							add_rewrite_rule($this->use_slug . '/(' . $term . ')/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top');
210
+							add_rewrite_rule($this->use_slug . '/(' . $term . ')/([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top');
211 211
 						}
212 212
 					}
213 213
 				} else {
214
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->post_type . '=$matches[1]&feed=$matches[2]', 'top' );
215
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->post_type . '=$matches[1]&feed=$matches[2]', 'top' );
216
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?' . $this->post_type . '=$matches[1]&paged=$matches[2]', 'top' );
217
-					add_rewrite_rule( $this->use_slug . '/([^/]+)/?$', 'index.php?' . $this->post_type . '=$matches[1]', 'top' );
214
+					add_rewrite_rule($this->use_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->post_type . '=$matches[1]&feed=$matches[2]', 'top');
215
+					add_rewrite_rule($this->use_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->post_type . '=$matches[1]&feed=$matches[2]', 'top');
216
+					add_rewrite_rule($this->use_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?' . $this->post_type . '=$matches[1]&paged=$matches[2]', 'top');
217
+					add_rewrite_rule($this->use_slug . '/([^/]+)/?$', 'index.php?' . $this->post_type . '=$matches[1]', 'top');
218 218
 					//'rewrite' => array( 'slug' => $this->post_type ) || true
219 219
 				}
220 220
 			}
221 221
 		}
222 222
 	}
223
-	private function rewrite_term_hierarchy( $parent, &$rewrite, $slug, $separator ) {
223
+	private function rewrite_term_hierarchy($parent, &$rewrite, $slug, $separator) {
224 224
 		$rewrite[] = $slug . $parent->slug . $separator;
225
-		$childs = get_terms( $this->taxonomy, array( 'parent' => $parent->term_id, 'hide_empty' => false ) );
226
-		foreach( $childs as $child ) {
227
-			$this->rewrite_term_hierarchy( $child, $rewrite, $slug . $parent->slug . $separator, $separator );
225
+		$childs = get_terms($this->taxonomy, array('parent' => $parent->term_id, 'hide_empty' => false));
226
+		foreach ($childs as $child) {
227
+			$this->rewrite_term_hierarchy($child, $rewrite, $slug . $parent->slug . $separator, $separator);
228 228
 		}
229 229
 	}
230 230
 	public function flush_rewrite() {
231
-		if( $this->enable_rewrites ) {
231
+		if ($this->enable_rewrites) {
232 232
 			$this->rewrite();
233 233
 			flush_rewrite_rules();
234 234
 		}
235 235
 	}
236
-	public function permalink( $permalink, $post, $leavename ) {
237
-		if( $this->enable_rewrites ) {
238
-			if( $post->post_type == $this->post_type ) {
239
-				if( empty( $this->use_slug ) || $this->use_slug == '/' ) {
240
-					if( $this->use_cat_slug ) {
241
-						if( $this->use_hierarchy_cat_slug ) {
242
-							$terms = get_the_terms( $post->ID, $this->taxonomy );
243
-							if( !empty( $terms ) ) {
236
+	public function permalink($permalink, $post, $leavename) {
237
+		if ($this->enable_rewrites) {
238
+			if ($post->post_type == $this->post_type) {
239
+				if (empty($this->use_slug) || $this->use_slug == '/') {
240
+					if ($this->use_cat_slug) {
241
+						if ($this->use_hierarchy_cat_slug) {
242
+							$terms = get_the_terms($post->ID, $this->taxonomy);
243
+							if (!empty($terms)) {
244 244
 								$term = $terms[0];
245 245
 								$post_permalink = '';
246
-								$this->permalink_term_hierarchy( $term, $post_permalink, $this->taxonomy, '/' );
246
+								$this->permalink_term_hierarchy($term, $post_permalink, $this->taxonomy, '/');
247 247
 								$permalink = get_site_url() . '/' . $post_permalink . $post->post_name . '/';
248 248
 							}
249 249
 						} else {
250
-							$terms = get_the_terms( $post->ID, $this->taxonomy );
251
-							if( !empty( $terms ) ) {
250
+							$terms = get_the_terms($post->ID, $this->taxonomy);
251
+							if (!empty($terms)) {
252 252
 								$term = $terms[0];
253 253
 								$permalink = get_site_url() . '/' . $term->slug . '/' . $post->post_name . '/';
254 254
 							}
@@ -257,18 +257,18 @@  discard block
 block discarded – undo
257 257
 						$permalink = get_site_url() . '/' . $post->post_name . '/';
258 258
 					}
259 259
 				} else {
260
-					if( $this->use_cat_slug ) {
261
-						if( $this->use_hierarchy_cat_slug ) {
262
-							$terms = get_the_terms( $post->ID, $this->taxonomy );
263
-							if( !empty( $terms ) ) {
260
+					if ($this->use_cat_slug) {
261
+						if ($this->use_hierarchy_cat_slug) {
262
+							$terms = get_the_terms($post->ID, $this->taxonomy);
263
+							if (!empty($terms)) {
264 264
 								$term = $terms[0];
265 265
 								$post_permalink = '';
266
-								$this->permalink_term_hierarchy( $term, $post_permalink, $this->taxonomy, '/' );
266
+								$this->permalink_term_hierarchy($term, $post_permalink, $this->taxonomy, '/');
267 267
 								$permalink = get_site_url() . '/' . $this->use_slug . '/' . $post_permalink . $post->post_name . '/';
268 268
 							}
269 269
 						} else {
270
-							$terms = get_the_terms( $post->ID, $this->taxonomy );
271
-							if( !empty( $terms ) ) {
270
+							$terms = get_the_terms($post->ID, $this->taxonomy);
271
+							if (!empty($terms)) {
272 272
 								$term = $terms[0];
273 273
 								$permalink = get_site_url() . '/' . $this->use_slug . '/' . $term->slug . '/' . $post->post_name . '/';
274 274
 							}
@@ -281,20 +281,20 @@  discard block
 block discarded – undo
281 281
 		}
282 282
 		return $permalink;
283 283
 	}
284
-	private function permalink_term_hierarchy( $term, &$permalink, $taxonomy, $separator ) {
285
-		if( $term->parent == 0 ) {
284
+	private function permalink_term_hierarchy($term, &$permalink, $taxonomy, $separator) {
285
+		if ($term->parent == 0) {
286 286
 			$permalink = $term->slug . $separator . $permalink;
287 287
 		} else {
288 288
 			$permalink = $term->slug . $separator . $permalink;
289
-			$term_parent = get_term( $term->parent, $taxonomy );
290
-			$this->permalink_term_hierarchy( $term_parent, $permalink, $taxonomy, $separator );
289
+			$term_parent = get_term($term->parent, $taxonomy);
290
+			$this->permalink_term_hierarchy($term_parent, $permalink, $taxonomy, $separator);
291 291
 		}
292 292
 	}
293
-	public function query( $query ) {
294
-		if( $this->enable_rewrites ) {
295
-			if ( empty( $this->use_slug ) || $this->use_slug == '/' && !$this->use_cat_slug ) {
296
-				if ( !is_admin() && $query->is_main_query() && !isset( $query->page ) && count( $query->query ) == 2 ) {
297
-					$query->set('post_type', array( 'page', 'post', $this->post_type ) );
293
+	public function query($query) {
294
+		if ($this->enable_rewrites) {
295
+			if (empty($this->use_slug) || $this->use_slug == '/' && !$this->use_cat_slug) {
296
+				if (!is_admin() && $query->is_main_query() && !isset($query->page) && count($query->query) == 2) {
297
+					$query->set('post_type', array('page', 'post', $this->post_type));
298 298
 				}
299 299
 			}
300 300
 		}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
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
  *
Please login to merge, or discard this patch.