Completed
Pull Request — master (#2)
by Jimmy
1216:52 queued 1185:43
created
includes/modules/wps_opinion/controller/wps_opinion_ctr.php 3 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -158,13 +158,13 @@
 block discarded – undo
158 158
 					$rate = get_comment_meta( $send_opinion->comment_ID, '_wps_customer_rate', true );
159 159
 					$data = array( 'id' => $send_opinion->comment_ID,
160 160
 								   'opinion_post_ID' => $send_opinion->comment_post_ID,
161
-							       'author_IP' => $send_opinion->comment_author_IP,
162
-							       'author' => $send_opinion->comment_author,
163
-							       'author_email' => $send_opinion->comment_author_email,
164
-							       'opinion_content' => $send_opinion->comment_content,
165
-							       'opinion_date' => $send_opinion->comment_date,
166
-							       'author_id' => $send_opinion->user_id,
167
-							       'opinion_approved' => $send_opinion->comment_approved,
161
+								   'author_IP' => $send_opinion->comment_author_IP,
162
+								   'author' => $send_opinion->comment_author,
163
+								   'author_email' => $send_opinion->comment_author_email,
164
+								   'opinion_content' => $send_opinion->comment_content,
165
+								   'opinion_date' => $send_opinion->comment_date,
166
+								   'author_id' => $send_opinion->user_id,
167
+								   'opinion_approved' => $send_opinion->comment_approved,
168 168
 								   'opinion_rate' => $rate
169 169
 							);
170 170
 				 	$posted_opinions[] = new wps_opinion_model( $data );
Please login to merge, or discard this patch.
Spacing   +105 added lines, -105 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_opinion_ctr {
3 3
 
4 4
 	/** Define the main directory containing the template for the current plugin
@@ -13,36 +13,36 @@  discard block
 block discarded – undo
13 13
 
14 14
 	function __construct() {
15 15
 		$this->template_dir = WPS_OPINION_PATH . WPS_OPINION_DIR . "/templates/";
16
-		add_action( 'admin_init', array( $this, 'declare_options' ) );
17
-		add_shortcode( 'wps_opinion', array( $this, 'display_opinion_customer_interface') );
18
-		add_shortcode( 'wps_star_rate_product', array( $this, 'display_star_rate_in_product') );
19
-		add_shortcode( 'wps_opinion_product', array( $this, 'display_opinion_in_product') );
20
-		add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ) );
16
+		add_action('admin_init', array($this, 'declare_options'));
17
+		add_shortcode('wps_opinion', array($this, 'display_opinion_customer_interface'));
18
+		add_shortcode('wps_star_rate_product', array($this, 'display_star_rate_in_product'));
19
+		add_shortcode('wps_opinion_product', array($this, 'display_opinion_in_product'));
20
+		add_action('wp_enqueue_scripts', array($this, 'add_scripts'));
21 21
 
22 22
 		/** Ajax actions **/
23
-		add_action( 'wp_ajax_wps-opinion-save-form', array( $this, 'wps_opinion_save_form') );
24
-		add_action( 'wp_ajax_nopriv_wps-opinion-save-form', array( $this, 'wps_opinion_save_form') );
25
-		add_action( 'wp_ajax_wps-update-opinion-star-rate', array( $this, 'wps_update_opinion_star_rate') );
26
-		add_action( 'wp_ajax_wps-refresh-add-opinion-list', array( $this, 'wps_refresh_add_opinion_list') );
27
-		add_action( 'wp_ajax_wps_fill_opinion_modal', array( $this, 'wps_fill_opinion_modal') );
23
+		add_action('wp_ajax_wps-opinion-save-form', array($this, 'wps_opinion_save_form'));
24
+		add_action('wp_ajax_nopriv_wps-opinion-save-form', array($this, 'wps_opinion_save_form'));
25
+		add_action('wp_ajax_wps-update-opinion-star-rate', array($this, 'wps_update_opinion_star_rate'));
26
+		add_action('wp_ajax_wps-refresh-add-opinion-list', array($this, 'wps_refresh_add_opinion_list'));
27
+		add_action('wp_ajax_wps_fill_opinion_modal', array($this, 'wps_fill_opinion_modal'));
28 28
 	}
29 29
 
30 30
 	/**
31 31
 	 * Add JS Files
32 32
 	 */
33 33
 	function add_scripts() {
34
-		wp_enqueue_script( 'jquery' );
35
-		wp_enqueue_script( 'jquery-form' );
36
-		wp_enqueue_script( 'wps-opinion-js', WPS_OPINION_URL . WPS_OPINION_DIR .'/assets/js/wps_opinion.js', false );
34
+		wp_enqueue_script('jquery');
35
+		wp_enqueue_script('jquery-form');
36
+		wp_enqueue_script('wps-opinion-js', WPS_OPINION_URL . WPS_OPINION_DIR . '/assets/js/wps_opinion.js', false);
37 37
 	}
38 38
 
39 39
 	/**
40 40
 	 * OPTIONS - Declare add-on configuration panel
41 41
 	 */
42
-	function declare_options(){
43
-		add_settings_section('wpshop_addons_opinions_options', '<span class="dashicons dashicons-format-chat"></span>'.__('Customer opinions', 'wpshop'), '', 'wpshop_addons_options');
44
-		register_setting('wpshop_options', 'wps_opinion', array( $this, 'validate_options'));
45
-		add_settings_field('wpshop_opinions_field', __( 'Activate possibility to add opinions on products', 'wpshop'), array( $this, 'addons_definition_fields'), 'wpshop_addons_options', 'wpshop_addons_opinions_options');
42
+	function declare_options() {
43
+		add_settings_section('wpshop_addons_opinions_options', '<span class="dashicons dashicons-format-chat"></span>' . __('Customer opinions', 'wpshop'), '', 'wpshop_addons_options');
44
+		register_setting('wpshop_options', 'wps_opinion', array($this, 'validate_options'));
45
+		add_settings_field('wpshop_opinions_field', __('Activate possibility to add opinions on products', 'wpshop'), array($this, 'addons_definition_fields'), 'wpshop_addons_options', 'wpshop_addons_opinions_options');
46 46
 	}
47 47
 
48 48
 	/**
@@ -50,26 +50,26 @@  discard block
 block discarded – undo
50 50
 	 * @param array $input
51 51
 	 * @return unknown
52 52
 	 */
53
-	function validate_options( $input ) {
53
+	function validate_options($input) {
54 54
 		return $input;
55 55
 	}
56 56
 
57 57
 	function addons_definition_fields() {
58
-		$opinion_option = get_option( 'wps_opinion' );
59
-		echo '<input type="checkbox" name="wps_opinion[active]" ' . ( ( !empty($opinion_option) && !empty($opinion_option['active']) ) ? 'checked="ckecked"' : '' ) . '/>';
58
+		$opinion_option = get_option('wps_opinion');
59
+		echo '<input type="checkbox" name="wps_opinion[active]" ' . ((!empty($opinion_option) && !empty($opinion_option['active'])) ? 'checked="ckecked"' : '') . '/>';
60 60
 	}
61 61
 
62 62
 	/**
63 63
 	 * Display opinions for an element
64 64
 	 * @param integer $element_id
65 65
 	 */
66
-	function display_opinions( $element_id ) {
67
-		if( !empty($element_id) ) {
66
+	function display_opinions($element_id) {
67
+		if (!empty($element_id)) {
68 68
 			$wps_opinion_mdl = new wps_opinion_model();
69
-			$opinions = $wps_opinion_mdl->get_opinions( $element_id );
70
-			if( !empty($opinions) ) {
69
+			$opinions = $wps_opinion_mdl->get_opinions($element_id);
70
+			if (!empty($opinions)) {
71 71
 				ob_start();
72
-				require( wpshop_tools::get_template_part( WPS_OPINION_DIR, $this->template_dir, "frontend", "opinions") );
72
+				require(wpshop_tools::get_template_part(WPS_OPINION_DIR, $this->template_dir, "frontend", "opinions"));
73 73
 				$output = ob_get_contents();
74 74
 				ob_end_clean();
75 75
 			}
@@ -81,18 +81,18 @@  discard block
 block discarded – undo
81 81
 	 * @param decimal $rate
82 82
 	 * @return string
83 83
 	 */
84
-	function display_stars( $rate ) {
84
+	function display_stars($rate) {
85 85
 		$output = '';
86
-		$opinion_option = get_option( 'wps_opinion' );
87
-		if( !empty($opinion_option) && !empty($opinion_option['active']) ) {
88
-			if( isset($rate) ) {
89
-				$exploded_rate = explode( '.', $rate );
90
-				for( $i = 1; $i <= 5; $i++ ) {
91
-					if ( $i <= $exploded_rate[0] ) {
86
+		$opinion_option = get_option('wps_opinion');
87
+		if (!empty($opinion_option) && !empty($opinion_option['active'])) {
88
+			if (isset($rate)) {
89
+				$exploded_rate = explode('.', $rate);
90
+				for ($i = 1; $i <= 5; $i++) {
91
+					if ($i <= $exploded_rate[0]) {
92 92
 						$output .= '<div class="dashicons dashicons-star-filled"></div>';
93 93
 					}
94 94
 					else {
95
-						if( ($i == intval( $exploded_rate[0] ) + 1) && !empty($exploded_rate[1]) && intval($exploded_rate[1]) > 0) {
95
+						if (($i == intval($exploded_rate[0]) + 1) && !empty($exploded_rate[1]) && intval($exploded_rate[1]) > 0) {
96 96
 							$output .= '<div class="dashicons dashicons-star-half"></div>';
97 97
 						}
98 98
 						else {
@@ -115,24 +115,24 @@  discard block
 block discarded – undo
115 115
 	function display_opinion_customer_interface() {
116 116
 		$output = '';
117 117
 		$customer_id = get_current_user_id();
118
-		$opinion_option = get_option( 'wps_opinion' );
119
-		if( !empty($opinion_option) && !empty($opinion_option['active']) ) {
120
-			if( !empty($customer_id) ) {
118
+		$opinion_option = get_option('wps_opinion');
119
+		if (!empty($opinion_option) && !empty($opinion_option['active'])) {
120
+			if (!empty($customer_id)) {
121 121
 				/** Products which wait opinion **/
122 122
 				//Get all ordered products with no opinion of this customer
123 123
 				$wps_opinion_mdl = new wps_opinion_model();
124
-				$ordered_products = $wps_opinion_mdl->get_ordered_products( $customer_id, false);
125
-				if( !empty($ordered_products) ) {
124
+				$ordered_products = $wps_opinion_mdl->get_ordered_products($customer_id, false);
125
+				if (!empty($ordered_products)) {
126 126
 					ob_start();
127
-					require( wpshop_tools::get_template_part( WPS_OPINION_DIR, $this->template_dir, "frontend", "waited_opinions") );
127
+					require(wpshop_tools::get_template_part(WPS_OPINION_DIR, $this->template_dir, "frontend", "waited_opinions"));
128 128
 					$output .= ob_get_contents();
129 129
 					ob_end_clean();
130 130
 				}
131 131
 
132 132
 				/** Posted opinions **/
133
-				$posted_opinions = $this->wps_customer_posted_opinions( $customer_id );
133
+				$posted_opinions = $this->wps_customer_posted_opinions($customer_id);
134 134
 				ob_start();
135
-				require( wpshop_tools::get_template_part( WPS_OPINION_DIR, $this->template_dir, "frontend", "posted_opinions") );
135
+				require(wpshop_tools::get_template_part(WPS_OPINION_DIR, $this->template_dir, "frontend", "posted_opinions"));
136 136
 				$output .= ob_get_contents();
137 137
 				ob_end_clean();
138 138
 			}
@@ -145,18 +145,18 @@  discard block
 block discarded – undo
145 145
 	 * @param int $customer_id
146 146
 	 * @return array wps_opinion_model
147 147
 	 */
148
-	function wps_customer_posted_opinions( $customer_id ) {
148
+	function wps_customer_posted_opinions($customer_id) {
149 149
 		$posted_opinions = array();
150
-		$opinion_option = get_option( 'wps_opinion' );
151
-		if( !empty($opinion_option) && !empty($opinion_option['active']) ) {
152
-			if( !empty($customer_id) ) {
150
+		$opinion_option = get_option('wps_opinion');
151
+		if (!empty($opinion_option) && !empty($opinion_option['active'])) {
152
+			if (!empty($customer_id)) {
153 153
 				$wps_opinion_mdl = new wps_opinion_model();
154 154
 				/** Customer opinions **/
155
-				$send_opinions = $wps_opinion_mdl->get_customer_opinions( $customer_id );
155
+				$send_opinions = $wps_opinion_mdl->get_customer_opinions($customer_id);
156 156
 
157
-				foreach( $send_opinions as $send_opinion ) {
158
-					$rate = get_comment_meta( $send_opinion->comment_ID, '_wps_customer_rate', true );
159
-					$data = array( 'id' => $send_opinion->comment_ID,
157
+				foreach ($send_opinions as $send_opinion) {
158
+					$rate = get_comment_meta($send_opinion->comment_ID, '_wps_customer_rate', true);
159
+					$data = array('id' => $send_opinion->comment_ID,
160 160
 								   'opinion_post_ID' => $send_opinion->comment_post_ID,
161 161
 							       'author_IP' => $send_opinion->comment_author_IP,
162 162
 							       'author' => $send_opinion->comment_author,
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 							       'opinion_approved' => $send_opinion->comment_approved,
168 168
 								   'opinion_rate' => $rate
169 169
 							);
170
-				 	$posted_opinions[] = new wps_opinion_model( $data );
170
+				 	$posted_opinions[] = new wps_opinion_model($data);
171 171
 				}
172 172
 			}
173 173
 		}
@@ -179,16 +179,16 @@  discard block
 block discarded – undo
179 179
 	 * @param array $args
180 180
 	 * @return string
181 181
 	 */
182
-	function display_star_rate_in_product( $args ) {
182
+	function display_star_rate_in_product($args) {
183 183
 		$output = '';
184
-		$opinion_option = get_option( 'wps_opinion' );
185
-		if( !empty($opinion_option) && !empty($opinion_option['active']) ) {
186
-			if( !empty($args) && !empty($args['pid']) ) {
184
+		$opinion_option = get_option('wps_opinion');
185
+		if (!empty($opinion_option) && !empty($opinion_option['active'])) {
186
+			if (!empty($args) && !empty($args['pid'])) {
187 187
 				$wps_opinion_mdl = new wps_opinion_model();
188
-				$comments_for_products = $wps_opinion_mdl->get_opinions_for_product( $args['pid'], 'approve' );
189
-				if( !empty($comments_for_products) ) {
190
-					$rate = $this->calcul_rate_average( $comments_for_products );
191
-					$output = $this->display_stars( $rate );
188
+				$comments_for_products = $wps_opinion_mdl->get_opinions_for_product($args['pid'], 'approve');
189
+				if (!empty($comments_for_products)) {
190
+					$rate = $this->calcul_rate_average($comments_for_products);
191
+					$output = $this->display_stars($rate);
192 192
 				}
193 193
 			}
194 194
 		}
@@ -200,37 +200,37 @@  discard block
 block discarded – undo
200 200
 	 * @param array $comments_for_product
201 201
 	 * @return decimal
202 202
 	 */
203
-	function calcul_rate_average( $comments_for_product ) {
203
+	function calcul_rate_average($comments_for_product) {
204 204
 		$rate_average = $r = $i = 0;
205
-		if( !empty($comments_for_product) ) {
206
-			foreach( $comments_for_product as $comment_for_product ) {
207
-				if( $comment_for_product->opinion_approved == 1 ) {
205
+		if (!empty($comments_for_product)) {
206
+			foreach ($comments_for_product as $comment_for_product) {
207
+				if ($comment_for_product->opinion_approved == 1) {
208 208
 					$r += $comment_for_product->opinion_rate;
209 209
 					$i++;
210 210
 				}
211 211
 			}
212 212
 
213
-			$rate_average = ( !empty($i) ) ? number_format( ( $r / $i ), 1, '.', '' ) : 0;
213
+			$rate_average = (!empty($i)) ? number_format(($r / $i), 1, '.', '') : 0;
214 214
 		}
215 215
 		return $rate_average;
216 216
 	}
217 217
 
218
-	function display_opinion_in_product( $args ) {
218
+	function display_opinion_in_product($args) {
219 219
 		$output = '';
220
-		$opinion_option = get_option( 'wps_opinion' );
221
-		if( !empty($opinion_option) && !empty($opinion_option['active']) ) {
222
-			if( !empty($args) && !empty($args['pid']) ) {
220
+		$opinion_option = get_option('wps_opinion');
221
+		if (!empty($opinion_option) && !empty($opinion_option['active'])) {
222
+			if (!empty($args) && !empty($args['pid'])) {
223 223
 				$wps_opinion_mdl = new wps_opinion_model();
224
-				$comments_for_product = $wps_opinion_mdl->get_opinions_for_product( $args['pid'], 'approve' );
224
+				$comments_for_product = $wps_opinion_mdl->get_opinions_for_product($args['pid'], 'approve');
225 225
 
226
-				if( !empty($comments_for_product) ) {
226
+				if (!empty($comments_for_product)) {
227 227
 					ob_start();
228
-					require( wpshop_tools::get_template_part( WPS_OPINION_DIR, $this->template_dir, "frontend", "opinion_in_product") );
228
+					require(wpshop_tools::get_template_part(WPS_OPINION_DIR, $this->template_dir, "frontend", "opinion_in_product"));
229 229
 					$output .= ob_get_contents();
230 230
 					ob_end_clean();
231 231
 				}
232 232
 				else {
233
-					$output = '<div class="wps-alert-info">' .__( 'No opinion has been posted on this product', 'wps_opinion'). '</div>';
233
+					$output = '<div class="wps-alert-info">' . __('No opinion has been posted on this product', 'wps_opinion') . '</div>';
234 234
 				}
235 235
 			}
236 236
 		}
@@ -238,20 +238,20 @@  discard block
 block discarded – undo
238 238
 	}
239 239
 
240 240
 	function wps_update_opinion_star_rate() {
241
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
241
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
242 242
 
243
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_update_opinion_star_rate' ) )
243
+		if (!wp_verify_nonce($_wpnonce, 'wps_update_opinion_star_rate'))
244 244
 			wp_die();
245 245
 
246 246
 		$status = false;
247 247
 		$output = '';
248
-		$rate = !empty( $_POST['rate'] ) ? (int) $_POST['rate'] : 0;
248
+		$rate = !empty($_POST['rate']) ? (int)$_POST['rate'] : 0;
249 249
 
250
-		if( isset( $rate ) ) {
251
-			$output = $this->display_stars( $rate );
250
+		if (isset($rate)) {
251
+			$output = $this->display_stars($rate);
252 252
 			$status = true;
253 253
 		}
254
-		echo json_encode( array( 'status' => $status, 'response' => $output) );
254
+		echo json_encode(array('status' => $status, 'response' => $output));
255 255
 		wp_die();
256 256
 	}
257 257
 
@@ -259,45 +259,45 @@  discard block
 block discarded – undo
259 259
 	 * AJAX - Save opinions
260 260
 	 */
261 261
 	function wps_opinion_save_form() {
262
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
262
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
263 263
 
264
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_opinion_save_form' ) )
264
+		if (!wp_verify_nonce($_wpnonce, 'wps_opinion_save_form'))
265 265
 			wp_die();
266 266
 
267 267
 		$status = false; $response = '';
268 268
 		$wps_opinion_mdl = new wps_opinion_model();
269 269
 		$user_id = get_current_user_id();
270 270
 		// Check if opinion for this product has been posted
271
-		$checking_opinions = $wps_opinion_mdl->get_opinions_for_product( intval($_POST['wps-opinion-product-id']) );
271
+		$checking_opinions = $wps_opinion_mdl->get_opinions_for_product(intval($_POST['wps-opinion-product-id']));
272 272
 		$comment_exist = false;
273
-		if( !empty($checking_opinions) ) {
274
-			foreach( $checking_opinions as $o ) {
275
-				if( $o->user_id == $user_id ) {
273
+		if (!empty($checking_opinions)) {
274
+			foreach ($checking_opinions as $o) {
275
+				if ($o->user_id == $user_id) {
276 276
 					$comment_exist = true;
277 277
 				}
278 278
 			}
279 279
 		}
280
-		if( !empty($user_id) && !$comment_exist ) {
281
-			$user_data = get_userdata( $user_id );
282
-			$data = array( 'opinion_post_ID' => intval($_POST['wps-opinion-product-id']),
280
+		if (!empty($user_id) && !$comment_exist) {
281
+			$user_data = get_userdata($user_id);
282
+			$data = array('opinion_post_ID' => intval($_POST['wps-opinion-product-id']),
283 283
 						   'author_IP' => $_SERVER['REMOTE_ADDR'],
284
-						   'author' => get_user_meta( $user_id, 'first_name', true ).' '.get_user_meta( $user_id, 'last_name', true),
285
-						   'author_email' => ( !empty( $user_data->user_email) ) ? $user_data->user_email : '',
286
-						   'opinion_content' => strip_tags( sanitize_text_field ( $_POST['wps-opinion-comment'] ) ),
287
-						   'opinion_date' => current_time( 'mysql', 0 ),
284
+						   'author' => get_user_meta($user_id, 'first_name', true) . ' ' . get_user_meta($user_id, 'last_name', true),
285
+						   'author_email' => (!empty($user_data->user_email)) ? $user_data->user_email : '',
286
+						   'opinion_content' => strip_tags(sanitize_text_field($_POST['wps-opinion-comment'])),
287
+						   'opinion_date' => current_time('mysql', 0),
288 288
 						   'author_id' => $user_id,
289
-						   'opinion_rate' => intval( $_POST['wps-opinion-rate'] )
289
+						   'opinion_rate' => intval($_POST['wps-opinion-rate'])
290 290
 					);
291 291
 
292
-			$wps_opinion_mdl->Create( $data );
292
+			$wps_opinion_mdl->Create($data);
293 293
 			$wps_opinion_mdl->Save();
294 294
 			$status = true;
295
-			$response = __( 'Comment has been send and must be approved by an administrator before publishing', 'wpshop' );
295
+			$response = __('Comment has been send and must be approved by an administrator before publishing', 'wpshop');
296 296
 		}
297 297
 		else {
298
-			$response = __( 'You have already post a comment for this product', 'wpshop' );
298
+			$response = __('You have already post a comment for this product', 'wpshop');
299 299
 		}
300
-		echo json_encode( array( 'status' => $status, 'response' => $response) );
300
+		echo json_encode(array('status' => $status, 'response' => $response));
301 301
 		wp_die();
302 302
 	}
303 303
 
@@ -305,14 +305,14 @@  discard block
 block discarded – undo
305 305
 	 * AJAX - Refresh Opinion list
306 306
 	 */
307 307
 	function wps_refresh_add_opinion_list() {
308
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
308
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
309 309
 
310
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_refresh_add_opinion_list' ) )
310
+		if (!wp_verify_nonce($_wpnonce, 'wps_refresh_add_opinion_list'))
311 311
 			wp_die();
312 312
 
313 313
 		$status = true; $response = '';
314 314
 		$response = $this->display_opinion_customer_interface();
315
-		echo json_encode( array('status' => $status, 'response' => $response ) );
315
+		echo json_encode(array('status' => $status, 'response' => $response));
316 316
 		wp_die();
317 317
 	}
318 318
 
@@ -320,19 +320,19 @@  discard block
 block discarded – undo
320 320
 	 * AJAX - Fill the opinion modal
321 321
 	 */
322 322
 	function wps_fill_opinion_modal() {
323
-		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
323
+		$_wponce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
324 324
 
325
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_fill_opinion_modal' ) )
325
+		if (!wp_verify_nonce($_wpnonce, 'wps_fill_opinion_modal'))
326 326
 			wp_die();
327 327
 
328 328
 		$status = true; $title = ''; $content = '';
329
-		$title = __( 'Add your opinion', 'wps_opinion');
329
+		$title = __('Add your opinion', 'wps_opinion');
330 330
 		ob_start();
331
-		$pid = ( !empty($_POST['pid']) ) ? intval( $_POST['pid'] ) : null;
332
-		require( wpshop_tools::get_template_part( WPS_OPINION_DIR, $this->template_dir, "frontend", "wps-modal-opinion") );
331
+		$pid = (!empty($_POST['pid'])) ? intval($_POST['pid']) : null;
332
+		require(wpshop_tools::get_template_part(WPS_OPINION_DIR, $this->template_dir, "frontend", "wps-modal-opinion"));
333 333
 		$content = ob_get_contents();
334 334
 		ob_end_clean();
335
-		echo json_encode( array( 'status' => $status, 'title' => $title, 'content' => $content ) );
335
+		echo json_encode(array('status' => $status, 'title' => $title, 'content' => $content));
336 336
 		wp_die();
337 337
 	}
338 338
 
Please login to merge, or discard this patch.
Braces   +20 added lines, -19 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_opinion_ctr {
3 5
 
4 6
 	/** Define the main directory containing the template for the current plugin
@@ -90,18 +92,15 @@  discard block
 block discarded – undo
90 92
 				for( $i = 1; $i <= 5; $i++ ) {
91 93
 					if ( $i <= $exploded_rate[0] ) {
92 94
 						$output .= '<div class="dashicons dashicons-star-filled"></div>';
93
-					}
94
-					else {
95
+					} else {
95 96
 						if( ($i == intval( $exploded_rate[0] ) + 1) && !empty($exploded_rate[1]) && intval($exploded_rate[1]) > 0) {
96 97
 							$output .= '<div class="dashicons dashicons-star-half"></div>';
97
-						}
98
-						else {
98
+						} else {
99 99
 							$output .= '<div class="dashicons dashicons-star-empty"></div>';
100 100
 						}
101 101
 					}
102 102
 				}
103
-			}
104
-			else {
103
+			} else {
105 104
 				$output = '-';
106 105
 			}
107 106
 		}
@@ -228,8 +227,7 @@  discard block
 block discarded – undo
228 227
 					require( wpshop_tools::get_template_part( WPS_OPINION_DIR, $this->template_dir, "frontend", "opinion_in_product") );
229 228
 					$output .= ob_get_contents();
230 229
 					ob_end_clean();
231
-				}
232
-				else {
230
+				} else {
233 231
 					$output = '<div class="wps-alert-info">' .__( 'No opinion has been posted on this product', 'wps_opinion'). '</div>';
234 232
 				}
235 233
 			}
@@ -240,8 +238,9 @@  discard block
 block discarded – undo
240 238
 	function wps_update_opinion_star_rate() {
241 239
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
242 240
 
243
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_update_opinion_star_rate' ) )
244
-			wp_die();
241
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_update_opinion_star_rate' ) ) {
242
+					wp_die();
243
+		}
245 244
 
246 245
 		$status = false;
247 246
 		$output = '';
@@ -261,8 +260,9 @@  discard block
 block discarded – undo
261 260
 	function wps_opinion_save_form() {
262 261
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
263 262
 
264
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_opinion_save_form' ) )
265
-			wp_die();
263
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_opinion_save_form' ) ) {
264
+					wp_die();
265
+		}
266 266
 
267 267
 		$status = false; $response = '';
268 268
 		$wps_opinion_mdl = new wps_opinion_model();
@@ -293,8 +293,7 @@  discard block
 block discarded – undo
293 293
 			$wps_opinion_mdl->Save();
294 294
 			$status = true;
295 295
 			$response = __( 'Comment has been send and must be approved by an administrator before publishing', 'wpshop' );
296
-		}
297
-		else {
296
+		} else {
298 297
 			$response = __( 'You have already post a comment for this product', 'wpshop' );
299 298
 		}
300 299
 		echo json_encode( array( 'status' => $status, 'response' => $response) );
@@ -307,8 +306,9 @@  discard block
 block discarded – undo
307 306
 	function wps_refresh_add_opinion_list() {
308 307
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
309 308
 
310
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_refresh_add_opinion_list' ) )
311
-			wp_die();
309
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_refresh_add_opinion_list' ) ) {
310
+					wp_die();
311
+		}
312 312
 
313 313
 		$status = true; $response = '';
314 314
 		$response = $this->display_opinion_customer_interface();
@@ -322,8 +322,9 @@  discard block
 block discarded – undo
322 322
 	function wps_fill_opinion_modal() {
323 323
 		$_wponce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
324 324
 
325
-		if ( !wp_verify_nonce( $_wpnonce, 'wps_fill_opinion_modal' ) )
326
-			wp_die();
325
+		if ( !wp_verify_nonce( $_wpnonce, 'wps_fill_opinion_modal' ) ) {
326
+					wp_die();
327
+		}
327 328
 
328 329
 		$status = true; $title = ''; $content = '';
329 330
 		$title = __( 'Add your opinion', 'wps_opinion');
Please login to merge, or discard this patch.
includes/modules/wps_opinion/templates/frontend/posted_opinion.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 ?>
3 3
 <div class="wps-table-content wps-table-row">
4
-		<div class="wps-table-cell"><?php echo mysql2date( get_option('date_format'), $posted_opinion->opinion_date, true ); ?></div>
4
+		<div class="wps-table-cell"><?php echo mysql2date(get_option('date_format'), $posted_opinion->opinion_date, true); ?></div>
5 5
 		<div class="wps-table-cell">
6 6
 			<?php 
7
-			$product = get_post( $posted_opinion->opinion_post_ID );
8
-			if( !empty($product) && !empty($product->post_type) ) : 
9
-				if( $product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) : 
10
-					$product = get_post( $product->post_parent );
7
+			$product = get_post($posted_opinion->opinion_post_ID);
8
+			if (!empty($product) && !empty($product->post_type)) : 
9
+				if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) : 
10
+					$product = get_post($product->post_parent);
11 11
 				endif;
12 12
 			endif;
13 13
 			echo $product->post_title;
14 14
 			?>
15 15
 		</div>
16 16
 		<div class="wps-table-cell"><?php echo $posted_opinion->opinion_content; ?></div>
17
-		<div class="wps-table-cell"><?php echo wps_opinion_ctr::display_stars( $posted_opinion->opinion_rate ); ?></div>
17
+		<div class="wps-table-cell"><?php echo wps_opinion_ctr::display_stars($posted_opinion->opinion_rate); ?></div>
18 18
 </div>
19 19
\ No newline at end of file
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_opinion/templates/frontend/opinion_in_product.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 ?>
3 3
 <div class="wps-table">
4 4
 <?php
5
-foreach( $comments_for_product as $comment_for_product ) : 
6
-	if( $comment_for_product->opinion_approved == 1 ) : 
5
+foreach ($comments_for_product as $comment_for_product) : 
6
+	if ($comment_for_product->opinion_approved == 1) : 
7 7
 ?>
8 8
 	<div class="wps-table-content wps-table-row">
9 9
 		<div class="wps-table-cell"><?php echo $comment_for_product->author; ?></div>
10
-		<div class="wps-table-cell"><?php echo mysql2date( get_option('date_format'), $comment_for_product->opinion_date, true ); ?></div>
10
+		<div class="wps-table-cell"><?php echo mysql2date(get_option('date_format'), $comment_for_product->opinion_date, true); ?></div>
11 11
 		<div class="wps-table-cell"><?php echo $comment_for_product->opinion_content; ?></div>
12
-		<div class="wps-table-cell"><?php echo wps_opinion_ctr::display_stars( $comment_for_product->opinion_rate ); ?></div>
12
+		<div class="wps-table-cell"><?php echo wps_opinion_ctr::display_stars($comment_for_product->opinion_rate); ?></div>
13 13
 	</div>
14 14
 <?php 
15 15
 	endif;
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_opinion/templates/frontend/posted_opinions.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
2
- if( !empty($posted_opinions) ) : ?>
3
-<span class="wps-h5"><?php _e( 'My opinions', 'wpshop'); ?></span>
1
+<?php if (!defined('ABSPATH')) exit;
2
+ if (!empty($posted_opinions)) : ?>
3
+<span class="wps-h5"><?php _e('My opinions', 'wpshop'); ?></span>
4 4
 <div class="wps-table">
5 5
 	<div class="wps-table-header wps-table-row">
6
-		<div class="wps-table-cell"><?php _e( 'Date', 'wps_opinion'); ?></div>
7
-		<div class="wps-table-cell"><?php _e( 'Product', 'wps_opinion'); ?></div>
8
-		<div class="wps-table-cell"><?php _e( 'Opinion', 'wps_opinion'); ?></div>
9
-		<div class="wps-table-cell"><?php _e( 'Rate', 'wps_opinion'); ?></div>
6
+		<div class="wps-table-cell"><?php _e('Date', 'wps_opinion'); ?></div>
7
+		<div class="wps-table-cell"><?php _e('Product', 'wps_opinion'); ?></div>
8
+		<div class="wps-table-cell"><?php _e('Opinion', 'wps_opinion'); ?></div>
9
+		<div class="wps-table-cell"><?php _e('Rate', 'wps_opinion'); ?></div>
10 10
 	</div>
11 11
 
12 12
 	<?php 
13
-	if( !empty($posted_opinions) ) : 
14
-		foreach( $posted_opinions as $posted_opinion ) : 
15
-			require( wpshop_tools::get_template_part( WPS_OPINION_DIR, $this->template_dir,"frontend", "posted_opinion") );
13
+	if (!empty($posted_opinions)) : 
14
+		foreach ($posted_opinions as $posted_opinion) : 
15
+			require(wpshop_tools::get_template_part(WPS_OPINION_DIR, $this->template_dir, "frontend", "posted_opinion"));
16 16
 		endforeach;
17 17
 	endif; 
18 18
 	?>
19 19
 </div>
20 20
 <?php else : ?>
21
-<div class="wps-alert-info"><?php _e( 'You never posted an opinion on a product', 'wpshop'); ?></div>
21
+<div class="wps-alert-info"><?php _e('You never posted an opinion on a product', 'wpshop'); ?></div>
22 22
 <?php endif; ?>
Please login to merge, or discard this patch.
Braces   +8 added lines, -3 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
  if( !empty($posted_opinions) ) : ?>
3 5
 <span class="wps-h5"><?php _e( 'My opinions', 'wpshop'); ?></span>
4 6
 <div class="wps-table">
@@ -17,6 +19,9 @@  discard block
 block discarded – undo
17 19
 	endif; 
18 20
 	?>
19 21
 </div>
20
-<?php else : ?>
21
-<div class="wps-alert-info"><?php _e( 'You never posted an opinion on a product', 'wpshop'); ?></div>
22
+<?php else {
23
+	: ?>
24
+<div class="wps-alert-info"><?php _e( 'You never posted an opinion on a product', 'wpshop');
25
+}
26
+?></div>
22 27
 <?php endif; ?>
Please login to merge, or discard this patch.
includes/modules/wps_opinion/templates/frontend/waited_opinions.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,17 +1,17 @@
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 ?>
3
-<div><span class="wps-h3"><?php _e( 'This products wait your opinion', 'wps_opinion'); ?></span></div>
3
+<div><span class="wps-h3"><?php _e('This products wait your opinion', 'wps_opinion'); ?></span></div>
4 4
 <div class="wps-table">
5 5
 	<div class="wps-table-header wps-table-row">
6
-		<div class="wps-table-cell"><?php _e( 'Picture', 'wps_opinion'); ?></div>
7
-		<div class="wps-table-cell"><?php _e( 'Product', 'wps_opinion'); ?></div>
6
+		<div class="wps-table-cell"><?php _e('Picture', 'wps_opinion'); ?></div>
7
+		<div class="wps-table-cell"><?php _e('Product', 'wps_opinion'); ?></div>
8 8
 		<div class="wps-table-cell"></div>
9 9
 	</div>
10
-	<?php if( !empty($ordered_products) ) : ?>
11
-	<?php foreach( $ordered_products as $ordered_product ) : ?>
12
-	<?php require( wpshop_tools::get_template_part( WPS_OPINION_DIR, $this->template_dir, "frontend", "waited_opinion") ); ?>
10
+	<?php if (!empty($ordered_products)) : ?>
11
+	<?php foreach ($ordered_products as $ordered_product) : ?>
12
+	<?php require(wpshop_tools::get_template_part(WPS_OPINION_DIR, $this->template_dir, "frontend", "waited_opinion")); ?>
13 13
 	<?php endforeach; ?>
14 14
 	<?php else : ?>
15
-	<?php _e( 'No products wait your opinion !', 'wps_opinion'); ?>
15
+	<?php _e('No products wait your opinion !', 'wps_opinion'); ?>
16 16
 	<?php endif; ?>
17 17
 </div>
Please login to merge, or discard this patch.
Braces   +8 added lines, -3 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
 <div><span class="wps-h3"><?php _e( 'This products wait your opinion', 'wps_opinion'); ?></span></div>
4 6
 <div class="wps-table">
@@ -11,7 +13,10 @@  discard block
 block discarded – undo
11 13
 	<?php foreach( $ordered_products as $ordered_product ) : ?>
12 14
 	<?php require( wpshop_tools::get_template_part( WPS_OPINION_DIR, $this->template_dir, "frontend", "waited_opinion") ); ?>
13 15
 	<?php endforeach; ?>
14
-	<?php else : ?>
15
-	<?php _e( 'No products wait your opinion !', 'wps_opinion'); ?>
16
+	<?php else {
17
+	: ?>
18
+	<?php _e( 'No products wait your opinion !', 'wps_opinion');
19
+}
20
+?>
16 21
 	<?php endif; ?>
17 22
 </div>
Please login to merge, or discard this patch.
includes/modules/wps_opinion/templates/frontend/opinion.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 ?>
3 3
 <div class="wps-table-content wps-table-row">
4
-		<div class="wps-table-cell"><?php echo mysql2date( get_option('date_format'), $opinion->opinion_date, true ); ?></div>
4
+		<div class="wps-table-cell"><?php echo mysql2date(get_option('date_format'), $opinion->opinion_date, true); ?></div>
5 5
 		<div class="wps-table-cell"><?php echo $order_meta['order_key']; ?></div>
6 6
 		<div class="wps-table-cell"><?php echo $opinion->opinion_content; ?></div>
7 7
 		<div class="wps-table-cell"></div>
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_opinion/templates/frontend/opinions.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 ?>
3
-<div><span class="wps-h3"><?php _e( 'My opinions', 'wps_opinion'); ?></span></div>
3
+<div><span class="wps-h3"><?php _e('My opinions', 'wps_opinion'); ?></span></div>
4 4
 <div class="wps-table">
5 5
 	<div class="wps-table-header wps-table-row">
6
-		<div class="wps-table-cell"><?php _e( 'Date', 'wps_opinion'); ?></div>
7
-		<div class="wps-table-cell"><?php _e( 'Product', 'wps_opinion'); ?></div>
8
-		<div class="wps-table-cell"><?php _e( 'Opinion', 'wps_opinion'); ?></div>
9
-		<div class="wps-table-cell"><?php _e( 'Rate', 'wps_opinion'); ?></div>
6
+		<div class="wps-table-cell"><?php _e('Date', 'wps_opinion'); ?></div>
7
+		<div class="wps-table-cell"><?php _e('Product', 'wps_opinion'); ?></div>
8
+		<div class="wps-table-cell"><?php _e('Opinion', 'wps_opinion'); ?></div>
9
+		<div class="wps-table-cell"><?php _e('Rate', 'wps_opinion'); ?></div>
10 10
 	</div>
11 11
 
12 12
 	<?php
13
-	 if( !empty($opinions) ) : 
14
-		foreach( $opinions as $opinion ): 
15
-			require( wpshop_tools::get_template_part( WPS_OPINION_DIR, $this->template_dir, "frontend", "opinion") );
13
+	 if (!empty($opinions)) : 
14
+		foreach ($opinions as $opinion): 
15
+			require(wpshop_tools::get_template_part(WPS_OPINION_DIR, $this->template_dir, "frontend", "opinion"));
16 16
 		endforeach; 
17 17
 	else : 
18
-		echo '<div class="wps-alert-info">' .__( 'You have never post opinion', 'wps_opinion'). '</div>';
18
+		echo '<div class="wps-alert-info">' . __('You have never post opinion', 'wps_opinion') . '</div>';
19 19
 	endif;  
20 20
 	 ?>
21 21
 </div>
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 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
 <div><span class="wps-h3"><?php _e( 'My opinions', 'wps_opinion'); ?></span></div>
4 6
 <div class="wps-table">
@@ -14,8 +16,10 @@  discard block
 block discarded – undo
14 16
 		foreach( $opinions as $opinion ): 
15 17
 			require( wpshop_tools::get_template_part( WPS_OPINION_DIR, $this->template_dir, "frontend", "opinion") );
16 18
 		endforeach; 
17
-	else : 
19
+	else {
20
+		: 
18 21
 		echo '<div class="wps-alert-info">' .__( 'You have never post opinion', 'wps_opinion'). '</div>';
22
+	}
19 23
 	endif;  
20 24
 	 ?>
21 25
 </div>
Please login to merge, or discard this patch.
includes/modules/wps_opinion/model/wps_opinion_model.php 2 patches
Spacing   +60 added lines, -60 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_opinion_model {
3 3
 	
4 4
 	var $id; 
@@ -12,19 +12,19 @@  discard block
 block discarded – undo
12 12
 	var $opinion_approved;
13 13
 	var $opinion_rate;
14 14
 	
15
-	function __construct( $data= array() ) {
16
-		if( !empty($data) ) {
17
-			$this->id = ( !empty($data['id']) ) ? $data['id'] : ''; 
18
-			$this->opinion_post_ID = ( !empty($data['opinion_post_ID']) ) ? $data['opinion_post_ID'] : '';
19
-			$this->author_IP = ( !empty($data['author_IP']) ) ? $data['author_IP'] : '';
20
-			$this->author = ( !empty($data['author']) ) ? $data['author'] : '';
21
-			$this->author_name = ( !empty($data['author_name']) ) ? $data['author_name'] : '';
22
-			$this->author_email = ( !empty($data['author_email']) ) ? $data['author_email'] : '';
23
-			$this->opinion_content = ( !empty($data['opinion_content']) ) ? $data['opinion_content'] : '';
24
-			$this->opinion_date = ( !empty($data['opinion_date']) ) ? $data['opinion_date'] : '';
25
-			$this->author_id = ( !empty($data['author_id']) ) ? $data['author_id'] : '';
26
-			$this->opinion_approved = ( !empty($data['opinion_approved']) ) ? $data['opinion_approved'] : '';
27
-			$this->opinion_rate = ( !empty($data['opinion_rate']) ) ? $data['opinion_rate'] : '';
15
+	function __construct($data = array()) {
16
+		if (!empty($data)) {
17
+			$this->id = (!empty($data['id'])) ? $data['id'] : ''; 
18
+			$this->opinion_post_ID = (!empty($data['opinion_post_ID'])) ? $data['opinion_post_ID'] : '';
19
+			$this->author_IP = (!empty($data['author_IP'])) ? $data['author_IP'] : '';
20
+			$this->author = (!empty($data['author'])) ? $data['author'] : '';
21
+			$this->author_name = (!empty($data['author_name'])) ? $data['author_name'] : '';
22
+			$this->author_email = (!empty($data['author_email'])) ? $data['author_email'] : '';
23
+			$this->opinion_content = (!empty($data['opinion_content'])) ? $data['opinion_content'] : '';
24
+			$this->opinion_date = (!empty($data['opinion_date'])) ? $data['opinion_date'] : '';
25
+			$this->author_id = (!empty($data['author_id'])) ? $data['author_id'] : '';
26
+			$this->opinion_approved = (!empty($data['opinion_approved'])) ? $data['opinion_approved'] : '';
27
+			$this->opinion_rate = (!empty($data['opinion_rate'])) ? $data['opinion_rate'] : '';
28 28
 		}
29 29
 	}
30 30
 	
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
 	 * Create opinion model
33 33
 	 * @param array $data
34 34
 	 */
35
-	function Create( $data ) {
36
-		$this->id = ( !empty($data['id']) ) ? $data['id'] : '';
37
-		$this->opinion_post_ID = ( !empty($data['opinion_post_ID']) ) ? $data['opinion_post_ID'] : '';
38
-		$this->author_IP = ( !empty($data['author_IP']) ) ? $data['author_IP'] : '';
39
-		$this->author = ( !empty($data['author']) ) ? $data['author'] : '';
40
-		$this->author_email = ( !empty($data['author_email']) ) ? $data['author_email'] : '';
41
-		$this->opinion_content = ( !empty($data['opinion_content']) ) ? $data['opinion_content'] : '';
42
-		$this->opinion_date = ( !empty($data['opinion_date']) ) ? $data['opinion_date'] : '';
43
-		$this->author_id = ( !empty($data['author_id']) ) ? $data['author_id'] : '';
44
-		$this->opinion_approved = ( !empty($data['opinion_approved']) ) ? $data['opinion_approved'] : 0;
45
-		$this->opinion_rate = ( !empty($data['opinion_rate']) ) ? $data['opinion_rate'] : 0;
35
+	function Create($data) {
36
+		$this->id = (!empty($data['id'])) ? $data['id'] : '';
37
+		$this->opinion_post_ID = (!empty($data['opinion_post_ID'])) ? $data['opinion_post_ID'] : '';
38
+		$this->author_IP = (!empty($data['author_IP'])) ? $data['author_IP'] : '';
39
+		$this->author = (!empty($data['author'])) ? $data['author'] : '';
40
+		$this->author_email = (!empty($data['author_email'])) ? $data['author_email'] : '';
41
+		$this->opinion_content = (!empty($data['opinion_content'])) ? $data['opinion_content'] : '';
42
+		$this->opinion_date = (!empty($data['opinion_date'])) ? $data['opinion_date'] : '';
43
+		$this->author_id = (!empty($data['author_id'])) ? $data['author_id'] : '';
44
+		$this->opinion_approved = (!empty($data['opinion_approved'])) ? $data['opinion_approved'] : 0;
45
+		$this->opinion_rate = (!empty($data['opinion_rate'])) ? $data['opinion_rate'] : 0;
46 46
 	}
47 47
 
48 48
 	/**
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 	 * @return bool $status
51 51
 	 */
52 52
 	function Save() {
53
-		if( !empty($this->opinion_post_ID) && !empty($this->author_id) && !empty($this->opinion_content) ) {
54
-			$post_type = get_post_type( $this->opinion_post_ID );
53
+		if (!empty($this->opinion_post_ID) && !empty($this->author_id) && !empty($this->opinion_content)) {
54
+			$post_type = get_post_type($this->opinion_post_ID);
55 55
 			// If element is a product or a product variation, we accept to save opinion
56
-			if( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT || $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
56
+			if ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT || $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
57 57
 				/** Insert comment **/
58 58
 				$data = array(
59 59
 						'comment_post_ID' => $this->opinion_post_ID,
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
 				);
69 69
 				$this->id = wp_insert_comment($data);
70 70
 				
71
-				if( !empty($this->id) ) {
72
-					$status = update_comment_meta( $this->id, '_wps_customer_rate', $this->opinion_rate );
71
+				if (!empty($this->id)) {
72
+					$status = update_comment_meta($this->id, '_wps_customer_rate', $this->opinion_rate);
73 73
 				}
74 74
 			}
75 75
 		}
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
 	 * @param integer $user_id
83 83
 	 * @return array
84 84
 	 */
85
-	function check_opinion_exists( $pid, $user_id ) {
85
+	function check_opinion_exists($pid, $user_id) {
86 86
 		$opinions = array();
87
-		if( !empty($pid) && !empty($user_id) ) {
88
-			$opinions = get_comments( array( 'post_id' => $pid, 'user_id' => $user_id) );
87
+		if (!empty($pid) && !empty($user_id)) {
88
+			$opinions = get_comments(array('post_id' => $pid, 'user_id' => $user_id));
89 89
 		}
90 90
 		return $opinions;
91 91
 	}
@@ -96,31 +96,31 @@  discard block
 block discarded – undo
96 96
 	 * @param bool $send_opinion
97 97
 	 * @return array
98 98
 	 */
99
-	function get_ordered_products( $customer_id, $send_opinion = false ) {
99
+	function get_ordered_products($customer_id, $send_opinion = false) {
100 100
 		global $wpdb;
101 101
 		$products = array();
102
-		if( !empty( $customer_id ) ) {
103
-			$query = $wpdb->prepare( 'SELECT * FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_ORDER, $customer_id );
104
-			$orders = $wpdb->get_results( $query );
105
-			if( !empty($orders) ) {
106
-				foreach( $orders as $order ) {
107
-					$order_metadata = get_post_meta( $order->ID, '_order_postmeta', true );
108
-					if( !empty($order_metadata) && !empty($order_metadata['order_items']) ) {
109
-						foreach( $order_metadata['order_items'] as $item_id => $item ) {
102
+		if (!empty($customer_id)) {
103
+			$query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_ORDER, $customer_id);
104
+			$orders = $wpdb->get_results($query);
105
+			if (!empty($orders)) {
106
+				foreach ($orders as $order) {
107
+					$order_metadata = get_post_meta($order->ID, '_order_postmeta', true);
108
+					if (!empty($order_metadata) && !empty($order_metadata['order_items'])) {
109
+						foreach ($order_metadata['order_items'] as $item_id => $item) {
110 110
 							// Check if product is a variation 
111
-							$item_id = ( !empty($item['item_id']) ) ? $item['item_id'] : $item_id;
112
-							if( get_post_type($item_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
113
-								$post_item = get_post( $item_id );
114
-								if( !empty($post_item) ) {
111
+							$item_id = (!empty($item['item_id'])) ? $item['item_id'] : $item_id;
112
+							if (get_post_type($item_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
113
+								$post_item = get_post($item_id);
114
+								if (!empty($post_item)) {
115 115
 									$item_id = $post_item->post_parent;
116 116
 								}
117 117
 							}
118 118
 							// Check if opinion exists
119
-							if( get_post_type($item_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
120
-								$check_opinion = $this->check_opinion_exists( $item_id, $customer_id );
121
-								$opinion_exists = ( !empty( $check_opinion ) ) ? true : false;
122
-								if( (!$opinion_exists && !$send_opinion) || ($opinion_exists && $send_opinion) ) {
123
-									$products[ $item_id ] = $item_id;
119
+							if (get_post_type($item_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
120
+								$check_opinion = $this->check_opinion_exists($item_id, $customer_id);
121
+								$opinion_exists = (!empty($check_opinion)) ? true : false;
122
+								if ((!$opinion_exists && !$send_opinion) || ($opinion_exists && $send_opinion)) {
123
+									$products[$item_id] = $item_id;
124 124
 								}
125 125
 							}
126 126
 						}
@@ -136,10 +136,10 @@  discard block
 block discarded – undo
136 136
 	 * @param integer $customer_id
137 137
 	 * @return array
138 138
 	 */
139
-	function get_customer_opinions( $customer_id ) {
139
+	function get_customer_opinions($customer_id) {
140 140
 		$opinions = array();
141
-		if( !empty($customer_id) ) {
142
-			$opinions = get_comments( array('user_id' => $customer_id, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) );
141
+		if (!empty($customer_id)) {
142
+			$opinions = get_comments(array('user_id' => $customer_id, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
143 143
 		}
144 144
 		return $opinions;
145 145
 	}
@@ -149,12 +149,12 @@  discard block
 block discarded – undo
149 149
 	 * @param integer $product_id
150 150
 	 * @return array
151 151
 	 */
152
-	function get_opinions_for_product( $product_id, $approved = '' ) {
152
+	function get_opinions_for_product($product_id, $approved = '') {
153 153
 		$returned_opinions = array();
154
-		if( !empty($product_id) ) {
155
-			$opinions = get_comments( array('post_id' => $product_id, 'status' => $approved ) );
156
-			if( !empty($opinions) ) {
157
-				foreach( $opinions as $opinion ) {
154
+		if (!empty($product_id)) {
155
+			$opinions = get_comments(array('post_id' => $product_id, 'status' => $approved));
156
+			if (!empty($opinions)) {
157
+				foreach ($opinions as $opinion) {
158 158
 					$comment_def = array(
159 159
 							'id' => $opinion->comment_ID,
160 160
 							'opinion_post_ID' => $opinion->comment_post_ID,
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 							'opinion_date' => $opinion->comment_date,
166 166
 							'author_id' => $opinion->user_id,
167 167
 							'opinion_approved' => $opinion->comment_approved,
168
-							'opinion_rate' => get_comment_meta( $opinion->comment_ID, '_wps_customer_rate', true ),
168
+							'opinion_rate' => get_comment_meta($opinion->comment_ID, '_wps_customer_rate', true),
169 169
 					);
170 170
 					$o = new wps_opinion_model(); 
171 171
 					$o->Create($comment_def);
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_opinion/wps_opinion.php 2 patches
Spacing   +7 added lines, -7 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
 /**
4 4
  * Bootstrap file
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 DEFINE('WPS_OPINION_DIR', basename(dirname(__FILE__)));
10
-DEFINE('WPS_OPINION_PATH', str_replace( "\\", "/", str_replace( WPS_OPINION_DIR, "", dirname( __FILE__ ) ) ) );
11
-DEFINE('WPS_OPINION_URL', str_replace( str_replace( "\\", "/", ABSPATH), site_url() . '/', WPS_OPINION_PATH ) );
12
-load_plugin_textdomain( 'wps_opinion', false, dirname(plugin_basename( __FILE__ )).'/languages/' );
10
+DEFINE('WPS_OPINION_PATH', str_replace("\\", "/", str_replace(WPS_OPINION_DIR, "", dirname(__FILE__))));
11
+DEFINE('WPS_OPINION_URL', str_replace(str_replace("\\", "/", ABSPATH), site_url() . '/', WPS_OPINION_PATH));
12
+load_plugin_textdomain('wps_opinion', false, dirname(plugin_basename(__FILE__)) . '/languages/');
13 13
 
14
-include( plugin_dir_path( __FILE__ ).'/config/config.php' );
15
-include( plugin_dir_path( __FILE__ ).'/controller/wps_opinion_ctr.php' );
16
-include( plugin_dir_path( __FILE__ ).'/model/wps_opinion_model.php' );
14
+include(plugin_dir_path(__FILE__) . '/config/config.php');
15
+include(plugin_dir_path(__FILE__) . '/controller/wps_opinion_ctr.php');
16
+include(plugin_dir_path(__FILE__) . '/model/wps_opinion_model.php');
17 17
 
18 18
 $wps_opinion = new wps_opinion_ctr();
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.