Completed
Pull Request — master (#2)
by Jimmy
1003:35 queued 970:52
created
core/wpeo_model/controller/comment_ctr.01.php 2 patches
Spacing   +33 added lines, -33 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
  * CRUD Functions pour les comments
@@ -8,80 +8,80 @@  discard block
 block discarded – undo
8 8
 class comment_ctr_01 {
9 9
 	protected $model_name = 'comment_mdl_01';
10 10
 	protected $meta_key = '_comment';
11
-	protected $comment_type	= '';
11
+	protected $comment_type = '';
12 12
 
13 13
 	protected $base = 'comment';
14 14
 	protected $version = '0.1';
15 15
 
16 16
 	public function __construct() {
17 17
 		/**	Ajout des routes personnalisées pour les éléments de type "commentaires" / Add specific routes for "comments" elements' type	*/
18
-		add_filter( 'json_endpoints', array( &$this, 'callback_register_route' ) );
18
+		add_filter('json_endpoints', array(&$this, 'callback_register_route'));
19 19
 	}
20 20
 
21
-	public function update( $data ) {
21
+	public function update($data) {
22 22
 		$object = $data;
23 23
 
24
-		if( is_array( $data ) ) {
25
-			$object = new $this->model_name( $data, $this->meta_key, false );
24
+		if (is_array($data)) {
25
+			$object = new $this->model_name($data, $this->meta_key, false);
26 26
 		}
27
-		wp_update_comment( $object->do_wp_object() );
27
+		wp_update_comment($object->do_wp_object());
28 28
 
29 29
 		/** On insert ou on met à jour les meta */
30
-		if( !empty( $object->option ) ) {
31
-			$object->save_meta_data( $object, 'update_comment_meta', $this->meta_key );
30
+		if (!empty($object->option)) {
31
+			$object->save_meta_data($object, 'update_comment_meta', $this->meta_key);
32 32
 		}
33 33
 
34 34
 		return $object;
35 35
 	}
36 36
 
37
-	public function create( $data ) {
37
+	public function create($data) {
38 38
 
39 39
 		$object = $data;
40 40
 
41
-		if( is_array( $data ) ) {
42
-			$object = new $this->model_name( $data, $this->meta_key );
41
+		if (is_array($data)) {
42
+			$object = new $this->model_name($data, $this->meta_key);
43 43
 			$object->type = $this->comment_type;
44 44
 		}
45 45
 
46
-		$object->id = wp_insert_comment( $object->do_wp_object() );
46
+		$object->id = wp_insert_comment($object->do_wp_object());
47 47
 
48 48
 		/** On insert ou on met à jour les meta */
49
-		if( !empty( $object->option ) ) {
50
-			$object->save_meta_data( $object, 'update_comment_meta', $this->meta_key  );
49
+		if (!empty($object->option)) {
50
+			$object->save_meta_data($object, 'update_comment_meta', $this->meta_key);
51 51
 		}
52 52
 
53 53
 		return $object;
54 54
 	}
55 55
 
56
-	public function delete( $id ) {
57
-		wp_delete_comment( $id );
56
+	public function delete($id) {
57
+		wp_delete_comment($id);
58 58
 	}
59 59
 
60
-	public function show( $id, $cropped = false ) {
61
-		$comment = get_comment( $id );
60
+	public function show($id, $cropped = false) {
61
+		$comment = get_comment($id);
62 62
 
63
-		if( !empty( $comment ) )
64
-			$comment = new $this->model_name( $comment, $this->meta_key, $cropped );
63
+		if (!empty($comment))
64
+			$comment = new $this->model_name($comment, $this->meta_key, $cropped);
65 65
 
66 66
 		return $comment;
67 67
 	}
68 68
 
69
-	public function index( $post_id = 0, $args_where = array( 'parent' => 0, 'status' => -34070, ), $cropped = false ) {
69
+	public function index($post_id = 0, $args_where = array('parent' => 0, 'status' => -34070,), $cropped = false) {
70 70
 		$array_model = array();
71 71
 
72 72
 		$args = array(
73 73
 			'post_id' 	=> $post_id,
74 74
 		);
75 75
 
76
-		if ( !empty( $this->comment_type ) )
76
+		if (!empty($this->comment_type))
77 77
 			$args['type'] = $this->comment_type;
78 78
 
79 79
 		$args = array_merge($args, $args_where);
80
-		$array_comment = get_comments( $args );
80
+		$array_comment = get_comments($args);
81 81
 
82
-		if( !empty( $array_comment ) ) {
83
-			foreach( $array_comment as $comment ) {
84
-				$array_model[] = new $this->model_name( $comment, $this->meta_key, $cropped );
82
+		if (!empty($array_comment)) {
83
+			foreach ($array_comment as $comment) {
84
+				$array_model[] = new $this->model_name($comment, $this->meta_key, $cropped);
85 85
 			}
86 86
 		}
87 87
 
@@ -95,25 +95,25 @@  discard block
 block discarded – undo
95 95
 	 *
96 96
 	 * @return array La liste des routes personnalisées ajoutées aux routes existantes / The personnalized routes added to existing
97 97
 	 */
98
-	public function callback_register_route( $array_route ) {
98
+	public function callback_register_route($array_route) {
99 99
 		/** Récupération de la liste complète des éléments / Get all existing elements */
100
-		$array_route['/' . $this->version . '/get/' . $this->base ] = array(
101
-				array( array( $this, 'index' ), WP_JSON_Server::READABLE | WP_JSON_Server::ACCEPT_JSON )
100
+		$array_route['/' . $this->version . '/get/' . $this->base] = array(
101
+				array(array($this, 'index'), WP_JSON_Server::READABLE | WP_JSON_Server::ACCEPT_JSON)
102 102
 		);
103 103
 
104 104
 		/** Récupération d'un élément donné / Get a given element */
105 105
 		$array_route['/' . $this->version . '/get/' . $this->base . '/(?P<id>\d+)'] = array(
106
-				array( array( $this, 'show' ), WP_JSON_Server::READABLE |  WP_JSON_Server::ACCEPT_JSON )
106
+				array(array($this, 'show'), WP_JSON_Server::READABLE | WP_JSON_Server::ACCEPT_JSON)
107 107
 		);
108 108
 
109 109
 		/** Mise à jour d'un élément / Update an element */
110 110
 		$array_route['/' . $this->version . '/post/' . $this->base . ''] = array(
111
-				array( array( $this, 'update' ), WP_JSON_Server::CREATABLE | WP_JSON_Server::ACCEPT_JSON ),
111
+				array(array($this, 'update'), WP_JSON_Server::CREATABLE | WP_JSON_Server::ACCEPT_JSON),
112 112
 		);
113 113
 
114 114
 		/** Suppression d'un élément / Delete an element */
115 115
 		$array_route['/' . $this->version . '/delete/' . $this->base . '/(?P<id>\d+)'] = array(
116
-				array( array( $this, 'delete' ), WP_JSON_Server::DELETABLE | WP_JSON_Server::ACCEPT_JSON ),
116
+				array(array($this, 'delete'), WP_JSON_Server::DELETABLE | WP_JSON_Server::ACCEPT_JSON),
117 117
 		);
118 118
 
119 119
 		return $array_route;
Please login to merge, or discard this patch.
Braces   +9 added lines, -5 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
 /**
4 6
  * CRUD Functions pour les comments
@@ -60,8 +62,9 @@  discard block
 block discarded – undo
60 62
 	public function show( $id, $cropped = false ) {
61 63
 		$comment = get_comment( $id );
62 64
 
63
-		if( !empty( $comment ) )
64
-			$comment = new $this->model_name( $comment, $this->meta_key, $cropped );
65
+		if( !empty( $comment ) ) {
66
+					$comment = new $this->model_name( $comment, $this->meta_key, $cropped );
67
+		}
65 68
 
66 69
 		return $comment;
67 70
 	}
@@ -73,8 +76,9 @@  discard block
 block discarded – undo
73 76
 			'post_id' 	=> $post_id,
74 77
 		);
75 78
 
76
-		if ( !empty( $this->comment_type ) )
77
-			$args['type'] = $this->comment_type;
79
+		if ( !empty( $this->comment_type ) ) {
80
+					$args['type'] = $this->comment_type;
81
+		}
78 82
 
79 83
 		$args = array_merge($args, $args_where);
80 84
 		$array_comment = get_comments( $args );
Please login to merge, or discard this patch.
core/wpeo_model/controller/user_ctr.01.php 2 patches
Spacing   +33 added lines, -33 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
 /**
@@ -19,75 +19,75 @@  discard block
 block discarded – undo
19 19
 	 */
20 20
 	public function __construct() {
21 21
 		/**	Ajout des routes personnalisées pour les éléments de type "user" / Add specific routes for "user" elements' type	*/
22
-		add_filter( 'json_endpoints', array( &$this, 'callback_register_route' ) );
22
+		add_filter('json_endpoints', array(&$this, 'callback_register_route'));
23 23
 	}
24 24
 
25
-	public function update( $data ) {
25
+	public function update($data) {
26 26
 		$object = $data;
27 27
 
28
-		if( is_array( $data ) ) {
29
-			$object = new $this->model_name( $data, $this->meta_key );
28
+		if (is_array($data)) {
29
+			$object = new $this->model_name($data, $this->meta_key);
30 30
 		}
31 31
 
32
-		wp_update_user( $object->do_wp_object() );
32
+		wp_update_user($object->do_wp_object());
33 33
 
34 34
 		/** On insert ou on met à jour les meta */
35
-		if( !empty( $object->option ) ) {
35
+		if (!empty($object->option)) {
36 36
 
37
-			$object->save_meta_data( $object, 'update_user_meta', $this->meta_key );
37
+			$object->save_meta_data($object, 'update_user_meta', $this->meta_key);
38 38
 		}
39 39
 
40 40
 		return $object;
41 41
 	}
42 42
 
43
-	public function create( $data ) {
43
+	public function create($data) {
44 44
 		$object = $data;
45 45
 
46
-		if( is_array( $data ) ) {
47
-			$object = new $this->model_name( $data, $this->meta_key );
46
+		if (is_array($data)) {
47
+			$object = new $this->model_name($data, $this->meta_key);
48 48
 		}
49 49
 
50 50
 		$array_object = $object->do_wp_object();
51 51
 
52
-		if ( empty( $array_object['user_pass'] ) ) {
52
+		if (empty($array_object['user_pass'])) {
53 53
 			$array_object['user_pass'] = wp_generate_password();
54 54
 		}
55 55
 
56 56
 
57
-		$object->id = wp_insert_user( $array_object );
57
+		$object->id = wp_insert_user($array_object);
58 58
 
59
-		$object->option['user_info']['initial'] = $object->build_user_initial( $object );
60
-		$object->option[ 'user_info' ][ 'avatar_color' ] = $object->avatar_color[ array_rand( $object->avatar_color, 1 ) ];
59
+		$object->option['user_info']['initial'] = $object->build_user_initial($object);
60
+		$object->option['user_info']['avatar_color'] = $object->avatar_color[array_rand($object->avatar_color, 1)];
61 61
 
62 62
 		/** On insert ou on met à jour les meta */
63
-		if( !empty( $object->option ) ) {
63
+		if (!empty($object->option)) {
64 64
 
65
-			$object->save_meta_data( $object, 'update_user_meta', $this->meta_key );
65
+			$object->save_meta_data($object, 'update_user_meta', $this->meta_key);
66 66
 		}
67 67
 
68 68
 
69 69
 		return $object;
70 70
 	}
71 71
 
72
-	public function delete( $id ) {
73
-		wp_delete_user( $id );
72
+	public function delete($id) {
73
+		wp_delete_user($id);
74 74
 	}
75 75
 
76
-	public function show( $id, $cropped = false ) {
77
- 		$user = get_user_by( 'id', $id );
78
-		$user = new $this->model_name( $user, $this->meta_key, $cropped );
76
+	public function show($id, $cropped = false) {
77
+ 		$user = get_user_by('id', $id);
78
+		$user = new $this->model_name($user, $this->meta_key, $cropped);
79 79
 
80 80
 		return $user;
81 81
 	}
82 82
 
83
-	public function index( $args_where = array( ), $cropped = false ) {
83
+	public function index($args_where = array( ), $cropped = false) {
84 84
 		$array_model = array();
85 85
 
86
-		$array_user = get_users( $args_where );
86
+		$array_user = get_users($args_where);
87 87
 
88
-		if( !empty( $array_user ) ) {
89
-			foreach( $array_user as $key => $user ) {
90
-				$array_model[$key] = new $this->model_name( $user, $this->meta_key, $cropped );
88
+		if (!empty($array_user)) {
89
+			foreach ($array_user as $key => $user) {
90
+				$array_model[$key] = new $this->model_name($user, $this->meta_key, $cropped);
91 91
 			}
92 92
 		}
93 93
 
@@ -101,25 +101,25 @@  discard block
 block discarded – undo
101 101
 	 *
102 102
 	 * @return array La liste des routes personnalisées ajoutées aux routes existantes / The personnalized routes added to existing
103 103
 	 */
104
-	public function callback_register_route( $array_route ) {
104
+	public function callback_register_route($array_route) {
105 105
 		/** Récupération de la liste complète des éléments / Get all existing elements */
106
-		$array_route['/' . $this->version . '/get/' . $this->base ] = array(
107
-				array( array( $this, 'index' ), WP_JSON_Server::READABLE | WP_JSON_Server::ACCEPT_JSON )
106
+		$array_route['/' . $this->version . '/get/' . $this->base] = array(
107
+				array(array($this, 'index'), WP_JSON_Server::READABLE | WP_JSON_Server::ACCEPT_JSON)
108 108
 		);
109 109
 
110 110
 		/** Récupération d'un élément donné / Get a given element */
111 111
 		$array_route['/' . $this->version . '/get/' . $this->base . '/(?P<id>\d+)'] = array(
112
-				array( array( $this, 'show' ), WP_JSON_Server::READABLE |  WP_JSON_Server::ACCEPT_JSON )
112
+				array(array($this, 'show'), WP_JSON_Server::READABLE | WP_JSON_Server::ACCEPT_JSON)
113 113
 		);
114 114
 
115 115
 		/** Mise à jour d'un élément / Update an element */
116 116
 		$array_route['/' . $this->version . '/post/' . $this->base . ''] = array(
117
-				array( array( $this, 'update' ), WP_JSON_Server::CREATABLE | WP_JSON_Server::ACCEPT_JSON ),
117
+				array(array($this, 'update'), WP_JSON_Server::CREATABLE | WP_JSON_Server::ACCEPT_JSON),
118 118
 		);
119 119
 
120 120
 		/** Suppression d'un élément / Delete an element */
121 121
 		$array_route['/' . $this->version . '/delete/' . $this->base . '/(?P<id>\d+)'] = array(
122
-				array( array( $this, 'delete' ), WP_JSON_Server::DELETABLE | WP_JSON_Server::ACCEPT_JSON ),
122
+				array(array($this, 'delete'), WP_JSON_Server::DELETABLE | WP_JSON_Server::ACCEPT_JSON),
123 123
 		);
124 124
 
125 125
 		return $array_route;
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.
core/wpeo_model/controller/constructor_model_ctr.01.php 3 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -234,16 +234,16 @@
 block discarded – undo
234 234
 		$encoded_object = json_encode( $object->option );
235 235
 
236 236
 		$encoded_object = preg_replace_callback(
237
-		    '/\\\\u([0-9a-f]{4})/i',
238
-		    function ($matches) {
239
-		        $sym = mb_convert_encoding(
240
-		                pack('H*', $matches[1]),
241
-		                'UTF-8',
242
-		                'UTF-16'
243
-		                );
244
-			    return $sym;
245
-		    },
246
-		    $encoded_object
237
+			'/\\\\u([0-9a-f]{4})/i',
238
+			function ($matches) {
239
+				$sym = mb_convert_encoding(
240
+						pack('H*', $matches[1]),
241
+						'UTF-8',
242
+						'UTF-16'
243
+						);
244
+				return $sym;
245
+			},
246
+			$encoded_object
247 247
 		);
248 248
 
249 249
 		call_user_func( $function, $object->id, $meta_key, $encoded_object );
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 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
  * Fichier du controlleur principal pour les catégories de dangers dans Digirisk / Controller file for danger categories for Digirisk
4 4
  *
@@ -20,52 +20,52 @@  discard block
 block discarded – undo
20 20
 	 * @param Array or StdClass $object
21 21
 	 * @return void
22 22
 	 */
23
-	public function __construct( $object ) {
23
+	public function __construct($object) {
24 24
 		$action = 'create';
25 25
 
26
-		if( ( is_array( $object ) && isset( $object['id'] ) ) || ( is_object( $object ) && get_class( $object ) != 'WP_User' && isset( $object->id ) ) ) {
26
+		if ((is_array($object) && isset($object['id'])) || (is_object($object) && get_class($object) != 'WP_User' && isset($object->id))) {
27 27
 			$action = 'update';
28 28
 		}
29 29
 
30
-		foreach( $this->model as $field_name => $field_def ) {
31
-			if( ( 'create' === $action ) || ( 'update' === $action && ( ( is_object( $object ) && isset( $object->$field_name ) ) || ( is_array( $object ) && isset( $object[$field_name] ) ) ) ) ) {
32
-				if( !isset( $field_def['type'] ) || is_array( $field_def['type'] ) ) {
30
+		foreach ($this->model as $field_name => $field_def) {
31
+			if (('create' === $action) || ('update' === $action && ((is_object($object) && isset($object->$field_name)) || (is_array($object) && isset($object[$field_name]))))) {
32
+				if (!isset($field_def['type']) || is_array($field_def['type'])) {
33 33
 
34
-					foreach( $field_def as $sub_file_name => $sub_field_def ) {
35
-						if( !empty( $sub_field_def['function'] ) ) {
36
-							$this->$field_name = call_user_func( $sub_field_def['function'], $this );
34
+					foreach ($field_def as $sub_file_name => $sub_field_def) {
35
+						if (!empty($sub_field_def['function'])) {
36
+							$this->$field_name = call_user_func($sub_field_def['function'], $this);
37 37
 						}
38 38
 					}
39 39
 				}
40 40
 				else {
41 41
 					// On lui affècte la valeur par défaut
42
-					$this->$field_name = isset( $field_def['default'] ) ? $field_def[ 'default' ] : null;
42
+					$this->$field_name = isset($field_def['default']) ? $field_def['default'] : null;
43 43
 
44 44
 					// Il faut tester si c'est une fonction WordPress ou pas
45 45
 					// 				if( function_exists( $field_def['function'] ) && !empty( $this->id ) )
46 46
 					// 					$this->$field_name = call_user_func( $field_def['function'], $this->id );
47 47
 
48 48
 					// Si c'est un objet
49
-					if ( is_object( $object ) ) {
49
+					if (is_object($object)) {
50 50
 						// Si la valeur est trouvé dans le modèle et dans l'objet
51
-						if ( version_compare( phpversion(), '7.0.0' ) >= 0 ) {
52
-							if( !empty( $object->{$field_def['field']} ) ) {
51
+						if (version_compare(phpversion(), '7.0.0') >= 0) {
52
+							if (!empty($object->{$field_def['field']} )) {
53 53
 								$this->$field_name = $object->{$field_def['field']};
54
-								settype( $this->$field_name, $field_def['type'] );
54
+								settype($this->$field_name, $field_def['type']);
55 55
 							}
56 56
 							else {
57
-								if( $field_def['required'] ) {
57
+								if ($field_def['required']) {
58 58
 									$this->$field_name = "Is required !";
59 59
 								}
60 60
 							}
61 61
 						}
62 62
 						else {
63
-							if( !empty( $object->$field_def['field'] ) ) {
63
+							if (!empty($object->$field_def['field'])) {
64 64
 								$this->$field_name = $object->$field_def['field'];
65
-								settype( $this->$field_name, $field_def['type'] );
65
+								settype($this->$field_name, $field_def['type']);
66 66
 							}
67 67
 							else {
68
-								if( $field_def['required'] ) {
68
+								if ($field_def['required']) {
69 69
 									$this->$field_name = "Is required !";
70 70
 								}
71 71
 							}
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 					}
74 74
 					else {
75 75
 						// Si la valeur est trouvé dans le modèle et dans l'objet
76
-						if( is_array( $object ) && array_key_exists( $field_name, $object ) ) {
76
+						if (is_array($object) && array_key_exists($field_name, $object)) {
77 77
 							$this->$field_name = $object[$field_name];
78
-							settype( $this->$field_name, $field_def['type'] );
78
+							settype($this->$field_name, $field_def['type']);
79 79
 						}
80 80
 						else {
81
-							if( $field_def['required'] ) {
81
+							if ($field_def['required']) {
82 82
 								$this->$field_name = "Is required !";
83 83
 							}
84 84
 						}
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
 	public function do_wp_object() {
97 97
 		$object = array();
98 98
 
99
-		foreach( $this->model as $field_name => $field_def ) {
100
-			if( !empty( $field_def['field'] ) && isset( $this->$field_name ) )
101
-				$object[ $field_def[ 'field' ] ] = $this->$field_name;
99
+		foreach ($this->model as $field_name => $field_def) {
100
+			if (!empty($field_def['field']) && isset($this->$field_name))
101
+				$object[$field_def['field']] = $this->$field_name;
102 102
 		}
103 103
 
104 104
 		return $object;
@@ -115,60 +115,60 @@  discard block
 block discarded – undo
115 115
 	 *
116 116
 	 * @return mixed La valeur du champs / The field value
117 117
 	 */
118
-	function fill_value( $object, $full_meta, $field_name, $field_def, $internal_meta ) {
118
+	function fill_value($object, $full_meta, $field_name, $field_def, $internal_meta) {
119 119
 		$value = null;
120 120
 
121 121
 		$object_option = $object;
122 122
 		/**	On ne récupère que les options de l'objet courant / Only get current object's options */
123
-		if ( is_array( $object ) && isset( $object[ 'option' ] ) && is_array( $object[ 'option' ] ) ) {
124
-			$object_option = $object[ 'option' ];
123
+		if (is_array($object) && isset($object['option']) && is_array($object['option'])) {
124
+			$object_option = $object['option'];
125 125
 		}
126
-		else if ( isset( $object->option ) ) {
126
+		else if (isset($object->option)) {
127 127
 			$object_option = $object->option;
128 128
 		}
129 129
 
130
-		if( !isset( $field_def[ 'type' ] ) || is_array( $field_def[ 'type' ] ) ) {
131
-			$sub_internal_meta = isset( $internal_meta[ $field_name ] ) ? $internal_meta[ $field_name ] : null;
132
-			foreach( $field_def as $sub_field_name => $sub_field ) {
133
-				$object_to_use = is_array( $object_option ) && !empty( $object_option[ $field_name ] ) ? $object_option[ $field_name ] : $object_option;
134
-				$value[ $sub_field_name ] = $this->fill_value( $object_to_use, $full_meta, $sub_field_name, $sub_field, $sub_internal_meta);
130
+		if (!isset($field_def['type']) || is_array($field_def['type'])) {
131
+			$sub_internal_meta = isset($internal_meta[$field_name]) ? $internal_meta[$field_name] : null;
132
+			foreach ($field_def as $sub_field_name => $sub_field) {
133
+				$object_to_use = is_array($object_option) && !empty($object_option[$field_name]) ? $object_option[$field_name] : $object_option;
134
+				$value[$sub_field_name] = $this->fill_value($object_to_use, $full_meta, $sub_field_name, $sub_field, $sub_internal_meta);
135 135
 			}
136 136
 		}
137 137
 		else {
138 138
 			/**	Remplissage avec la valeur par défaut / Fill with the default value */
139
-			$value = isset( $field_def['default'] ) ? $field_def['default'] : null;
139
+			$value = isset($field_def['default']) ? $field_def['default'] : null;
140 140
 
141 141
 			/** Si la valeur existe dans la meta propre sous forme json on remplit avec cette valeur / If the value exists into json meta fill with this value  */
142
-			$value = isset( $internal_meta[ $field_name ] ) ? $internal_meta[ $field_name ] : $value;
142
+			$value = isset($internal_meta[$field_name]) ? $internal_meta[$field_name] : $value;
143 143
 
144 144
 			/**	Si la valeur est stockée dans une meta seule / If the value if stored into a single meta	*/
145
-			if ( isset( $field_def[ 'field_type' ] ) && ( 'meta' == $field_def[ 'field_type' ] ) ) {
145
+			if (isset($field_def['field_type']) && ('meta' == $field_def['field_type'])) {
146 146
 				$meta_to_use = null;
147
-				if ( is_object( $full_meta ) && isset( $full_meta->$field_def[ 'field' ] ) ) {
148
-					$meta_to_use = $full_meta->$field_def[ 'field' ];
147
+				if (is_object($full_meta) && isset($full_meta->$field_def['field'])) {
148
+					$meta_to_use = $full_meta->$field_def['field'];
149 149
 				}
150
-				else if ( is_array( $full_meta ) && isset( $full_meta[ $field_def[ 'field' ] ] ) ) {
151
-					$meta_to_use = $full_meta[ $field_def[ 'field' ] ];
150
+				else if (is_array($full_meta) && isset($full_meta[$field_def['field']])) {
151
+					$meta_to_use = $full_meta[$field_def['field']];
152 152
 				}
153 153
 
154
-				if ( isset( $meta_to_use ) ) {
155
-					if ( is_array( $meta_to_use ) && ( 1 == count( $meta_to_use ) ) && isset( $meta_to_use[ 0 ] ) ) {
156
-						$value = $meta_to_use[ 0 ];
154
+				if (isset($meta_to_use)) {
155
+					if (is_array($meta_to_use) && (1 == count($meta_to_use)) && isset($meta_to_use[0])) {
156
+						$value = $meta_to_use[0];
157 157
 					}
158 158
 					else {
159 159
 						$value = $meta_to_use;
160 160
 					}
161 161
 				}
162 162
 			}
163
-			else if ( isset( $field_def[ 'field_type' ] ) && ( 'computed' == $field_def[ 'field_type' ] ) && !empty( $field_def[ 'function' ] ) ) {
164
-				$value = call_user_func( $field_def[ 'function' ], $object);
163
+			else if (isset($field_def['field_type']) && ('computed' == $field_def['field_type']) && !empty($field_def['function'])) {
164
+				$value = call_user_func($field_def['function'], $object);
165 165
 			}
166 166
 
167 167
 			/** Si on a définit une valeur (dans le cas de la création ou de la mise à jour) / If we defined the value (in creation case or in update case ) */
168
-			$value = is_array( $object_option ) && isset( $object_option[ $field_name ] ) ? $object_option[ $field_name ] : $value;
168
+			$value = is_array($object_option) && isset($object_option[$field_name]) ? $object_option[$field_name] : $value;
169 169
 
170 170
 			/**	Forçage du type pour la valeur / Force the value type	*/
171
-			settype( $value, $field_def[ 'type' ] );
171
+			settype($value, $field_def['type']);
172 172
 		}
173 173
 
174 174
 		return $value;
@@ -199,43 +199,43 @@  discard block
 block discarded – undo
199 199
 	 * @param string $function Le nom de la fonction à appeler / The name of function to call
200 200
 	 * @param string $meta_key La meta clé à mêttre à jour / The meta key to update
201 201
 	 */
202
-	public function save_meta_data( $object, $function, $meta_key ) {
202
+	public function save_meta_data($object, $function, $meta_key) {
203 203
 		/** Read the object model option */
204 204
 		$array_option = $object->get_array_option();
205 205
 
206
-		foreach ( $object->option as $field_name => $field ) {
207
-			if( !isset( $array_option[ $field_name ]['type'] ) || is_array( $array_option[ $field_name ]['type'] ) ) {
208
-				foreach( $field as $sub_field_name => $sub_field ) {
206
+		foreach ($object->option as $field_name => $field) {
207
+			if (!isset($array_option[$field_name]['type']) || is_array($array_option[$field_name]['type'])) {
208
+				foreach ($field as $sub_field_name => $sub_field) {
209 209
 
210
-					if ( isset( $array_option[ $field_name ][ $sub_field_name ][ 'field_type' ] ) ) {
211
-						if ( 'meta' == $array_option[ $field_name ][ $sub_field_name ][ 'field_type' ] ) {
210
+					if (isset($array_option[$field_name][$sub_field_name]['field_type'])) {
211
+						if ('meta' == $array_option[$field_name][$sub_field_name]['field_type']) {
212 212
 							/** Update a single meta for specific field */
213
-							call_user_func( $function, $object->id, $array_option[ $field_name ][ $sub_field_name ][ 'field' ] , $object->option[ $field_name ][ $sub_field_name ] );
213
+							call_user_func($function, $object->id, $array_option[$field_name][$sub_field_name]['field'], $object->option[$field_name][$sub_field_name]);
214 214
 // 							unset( $object->option[ $field_name ][ $sub_field_name ] );
215 215
 						}
216
-						else if ( 'computed' == $array_option[ $field_name ][ $sub_field_name ][ 'field_type' ] ) {
217
-							unset( $object->option[ $field_name ][ $sub_field_name ] );
216
+						else if ('computed' == $array_option[$field_name][$sub_field_name]['field_type']) {
217
+							unset($object->option[$field_name][$sub_field_name]);
218 218
 						}
219 219
 					}
220 220
 				}
221 221
 			}
222
-			else if ( isset( $array_option[ $field_name ][ 'field_type' ] ) ) {
223
-				if ( 'meta' == $array_option[ $field_name ][ 'field_type' ] ) {
222
+			else if (isset($array_option[$field_name]['field_type'])) {
223
+				if ('meta' == $array_option[$field_name]['field_type']) {
224 224
 					/** Update a single meta for specific field */
225
-					call_user_func( $function, $object->id, $array_option[ $field_name ][ 'field' ], $object->option[ $field_name ] );
226
-					unset( $object->option[ $field_name ] );
225
+					call_user_func($function, $object->id, $array_option[$field_name]['field'], $object->option[$field_name]);
226
+					unset($object->option[$field_name]);
227 227
 				}
228
-				else if ( 'computed' == $array_option[ $field_name ][ 'field_type' ] ) {
229
-					unset( $object->option[ $field_name ] );
228
+				else if ('computed' == $array_option[$field_name]['field_type']) {
229
+					unset($object->option[$field_name]);
230 230
 				}
231 231
 			}
232 232
 		}
233 233
 
234
-		$encoded_object = json_encode( $object->option );
234
+		$encoded_object = json_encode($object->option);
235 235
 
236 236
 		$encoded_object = preg_replace_callback(
237 237
 		    '/\\\\u([0-9a-f]{4})/i',
238
-		    function ($matches) {
238
+		    function($matches) {
239 239
 		        $sym = mb_convert_encoding(
240 240
 		                pack('H*', $matches[1]),
241 241
 		                'UTF-8',
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 		    $encoded_object
247 247
 		);
248 248
 
249
-		call_user_func( $function, $object->id, $meta_key, $encoded_object );
249
+		call_user_func($function, $object->id, $meta_key, $encoded_object);
250 250
 	}
251 251
 
252 252
 }
Please login to merge, or discard this patch.
Braces   +20 added lines, -31 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
  * Fichier du controlleur principal pour les catégories de dangers dans Digirisk / Controller file for danger categories for Digirisk
4 6
  *
@@ -36,8 +38,7 @@  discard block
 block discarded – undo
36 38
 							$this->$field_name = call_user_func( $sub_field_def['function'], $this );
37 39
 						}
38 40
 					}
39
-				}
40
-				else {
41
+				} else {
41 42
 					// On lui affècte la valeur par défaut
42 43
 					$this->$field_name = isset( $field_def['default'] ) ? $field_def[ 'default' ] : null;
43 44
 
@@ -52,32 +53,27 @@  discard block
 block discarded – undo
52 53
 							if( !empty( $object->{$field_def['field']} ) ) {
53 54
 								$this->$field_name = $object->{$field_def['field']};
54 55
 								settype( $this->$field_name, $field_def['type'] );
55
-							}
56
-							else {
56
+							} else {
57 57
 								if( $field_def['required'] ) {
58 58
 									$this->$field_name = "Is required !";
59 59
 								}
60 60
 							}
61
-						}
62
-						else {
61
+						} else {
63 62
 							if( !empty( $object->$field_def['field'] ) ) {
64 63
 								$this->$field_name = $object->$field_def['field'];
65 64
 								settype( $this->$field_name, $field_def['type'] );
66
-							}
67
-							else {
65
+							} else {
68 66
 								if( $field_def['required'] ) {
69 67
 									$this->$field_name = "Is required !";
70 68
 								}
71 69
 							}
72 70
 						}
73
-					}
74
-					else {
71
+					} else {
75 72
 						// Si la valeur est trouvé dans le modèle et dans l'objet
76 73
 						if( is_array( $object ) && array_key_exists( $field_name, $object ) ) {
77 74
 							$this->$field_name = $object[$field_name];
78 75
 							settype( $this->$field_name, $field_def['type'] );
79
-						}
80
-						else {
76
+						} else {
81 77
 							if( $field_def['required'] ) {
82 78
 								$this->$field_name = "Is required !";
83 79
 							}
@@ -97,8 +93,9 @@  discard block
 block discarded – undo
97 93
 		$object = array();
98 94
 
99 95
 		foreach( $this->model as $field_name => $field_def ) {
100
-			if( !empty( $field_def['field'] ) && isset( $this->$field_name ) )
101
-				$object[ $field_def[ 'field' ] ] = $this->$field_name;
96
+			if( !empty( $field_def['field'] ) && isset( $this->$field_name ) ) {
97
+							$object[ $field_def[ 'field' ] ] = $this->$field_name;
98
+			}
102 99
 		}
103 100
 
104 101
 		return $object;
@@ -122,8 +119,7 @@  discard block
 block discarded – undo
122 119
 		/**	On ne récupère que les options de l'objet courant / Only get current object's options */
123 120
 		if ( is_array( $object ) && isset( $object[ 'option' ] ) && is_array( $object[ 'option' ] ) ) {
124 121
 			$object_option = $object[ 'option' ];
125
-		}
126
-		else if ( isset( $object->option ) ) {
122
+		} else if ( isset( $object->option ) ) {
127 123
 			$object_option = $object->option;
128 124
 		}
129 125
 
@@ -133,8 +129,7 @@  discard block
 block discarded – undo
133 129
 				$object_to_use = is_array( $object_option ) && !empty( $object_option[ $field_name ] ) ? $object_option[ $field_name ] : $object_option;
134 130
 				$value[ $sub_field_name ] = $this->fill_value( $object_to_use, $full_meta, $sub_field_name, $sub_field, $sub_internal_meta);
135 131
 			}
136
-		}
137
-		else {
132
+		} else {
138 133
 			/**	Remplissage avec la valeur par défaut / Fill with the default value */
139 134
 			$value = isset( $field_def['default'] ) ? $field_def['default'] : null;
140 135
 
@@ -146,21 +141,18 @@  discard block
 block discarded – undo
146 141
 				$meta_to_use = null;
147 142
 				if ( is_object( $full_meta ) && isset( $full_meta->$field_def[ 'field' ] ) ) {
148 143
 					$meta_to_use = $full_meta->$field_def[ 'field' ];
149
-				}
150
-				else if ( is_array( $full_meta ) && isset( $full_meta[ $field_def[ 'field' ] ] ) ) {
144
+				} else if ( is_array( $full_meta ) && isset( $full_meta[ $field_def[ 'field' ] ] ) ) {
151 145
 					$meta_to_use = $full_meta[ $field_def[ 'field' ] ];
152 146
 				}
153 147
 
154 148
 				if ( isset( $meta_to_use ) ) {
155 149
 					if ( is_array( $meta_to_use ) && ( 1 == count( $meta_to_use ) ) && isset( $meta_to_use[ 0 ] ) ) {
156 150
 						$value = $meta_to_use[ 0 ];
157
-					}
158
-					else {
151
+					} else {
159 152
 						$value = $meta_to_use;
160 153
 					}
161 154
 				}
162
-			}
163
-			else if ( isset( $field_def[ 'field_type' ] ) && ( 'computed' == $field_def[ 'field_type' ] ) && !empty( $field_def[ 'function' ] ) ) {
155
+			} else if ( isset( $field_def[ 'field_type' ] ) && ( 'computed' == $field_def[ 'field_type' ] ) && !empty( $field_def[ 'function' ] ) ) {
164 156
 				$value = call_user_func( $field_def[ 'function' ], $object);
165 157
 			}
166 158
 
@@ -212,20 +204,17 @@  discard block
 block discarded – undo
212 204
 							/** Update a single meta for specific field */
213 205
 							call_user_func( $function, $object->id, $array_option[ $field_name ][ $sub_field_name ][ 'field' ] , $object->option[ $field_name ][ $sub_field_name ] );
214 206
 // 							unset( $object->option[ $field_name ][ $sub_field_name ] );
215
-						}
216
-						else if ( 'computed' == $array_option[ $field_name ][ $sub_field_name ][ 'field_type' ] ) {
207
+						} else if ( 'computed' == $array_option[ $field_name ][ $sub_field_name ][ 'field_type' ] ) {
217 208
 							unset( $object->option[ $field_name ][ $sub_field_name ] );
218 209
 						}
219 210
 					}
220 211
 				}
221
-			}
222
-			else if ( isset( $array_option[ $field_name ][ 'field_type' ] ) ) {
212
+			} else if ( isset( $array_option[ $field_name ][ 'field_type' ] ) ) {
223 213
 				if ( 'meta' == $array_option[ $field_name ][ 'field_type' ] ) {
224 214
 					/** Update a single meta for specific field */
225 215
 					call_user_func( $function, $object->id, $array_option[ $field_name ][ 'field' ], $object->option[ $field_name ] );
226 216
 					unset( $object->option[ $field_name ] );
227
-				}
228
-				else if ( 'computed' == $array_option[ $field_name ][ 'field_type' ] ) {
217
+				} else if ( 'computed' == $array_option[ $field_name ][ 'field_type' ] ) {
229 218
 					unset( $object->option[ $field_name ] );
230 219
 				}
231 220
 			}
Please login to merge, or discard this patch.
core/wpeo_model/controller/post_ctr.01.php 2 patches
Spacing   +59 added lines, -59 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
 /**
@@ -18,31 +18,31 @@  discard block
 block discarded – undo
18 18
 	 */
19 19
 	public function __construct() {
20 20
 		/**	Ajout des routes personnalisées pour les éléments de type "post" / Add specific routes for "post" elements' type	*/
21
-		add_filter( 'json_endpoints', array( &$this, 'callback_register_route' ) );
21
+		add_filter('json_endpoints', array(&$this, 'callback_register_route'));
22 22
 	}
23 23
 
24
-	public function update( $data ) {
24
+	public function update($data) {
25 25
 		$object = $data;
26 26
 
27
-		if( is_array( $data ) ) {
28
-			$object = new $this->model_name( $data, $this->meta_key );
27
+		if (is_array($data)) {
28
+			$object = new $this->model_name($data, $this->meta_key);
29 29
 		}
30 30
 
31
-		wp_update_post( $object->do_wp_object() );
31
+		wp_update_post($object->do_wp_object());
32 32
 
33 33
 		/** On insert ou on met à jour les meta */
34
-		if( !empty( $object->option ) ) {
35
-			$object->save_meta_data( $object, 'update_post_meta', $this->meta_key );
34
+		if (!empty($object->option)) {
35
+			$object->save_meta_data($object, 'update_post_meta', $this->meta_key);
36 36
 		}
37 37
 
38 38
 		/** On insert les terms */
39
-		if ( !empty( $object->taxonomy ) ) {
40
-			foreach( $object->taxonomy as $taxonomy => $array_value ) {
41
-				if( !empty( $taxonomy ) && !empty( $array_value ) ) {
42
-					wp_set_object_terms( $object->id, $array_value, $taxonomy );
39
+		if (!empty($object->taxonomy)) {
40
+			foreach ($object->taxonomy as $taxonomy => $array_value) {
41
+				if (!empty($taxonomy) && !empty($array_value)) {
42
+					wp_set_object_terms($object->id, $array_value, $taxonomy);
43 43
 				}
44
-				else if( !empty( $taxonomy ) && empty( $array_value ) ) {
45
-					wp_set_object_terms( $object->id, '', $taxonomy );
44
+				else if (!empty($taxonomy) && empty($array_value)) {
45
+					wp_set_object_terms($object->id, '', $taxonomy);
46 46
 				}
47 47
 			}
48 48
 		}
@@ -50,24 +50,24 @@  discard block
 block discarded – undo
50 50
 		return $object;
51 51
 	}
52 52
 
53
-	public function create( $data ) {
53
+	public function create($data) {
54 54
 		$object = $data;
55 55
 
56
-		if( is_array( $data ) ) {
57
-			$object = new $this->model_name( $data, $this->meta_key );
56
+		if (is_array($data)) {
57
+			$object = new $this->model_name($data, $this->meta_key);
58 58
 			$object->type = $this->post_type;
59 59
 		}
60
-		$object->id = wp_insert_post( $object->do_wp_object() );
60
+		$object->id = wp_insert_post($object->do_wp_object());
61 61
 		/** On insert ou on met à jour les meta */
62
-		if( !empty( $object->option ) ) {
63
-			$object->save_meta_data( $object, 'update_post_meta', $this->meta_key );
62
+		if (!empty($object->option)) {
63
+			$object->save_meta_data($object, 'update_post_meta', $this->meta_key);
64 64
 		}
65 65
 
66 66
 		/** On insert les terms */
67
-		if ( !empty( $object->taxonomy ) ) {
68
-			foreach( $object->taxonomy as $taxonomy => $array_value ) {
69
-				if( !empty( $taxonomy ) && !empty( $array_value ) ) {
70
-					wp_set_object_terms( $object->id, $array_value, $taxonomy );
67
+		if (!empty($object->taxonomy)) {
68
+			foreach ($object->taxonomy as $taxonomy => $array_value) {
69
+				if (!empty($taxonomy) && !empty($array_value)) {
70
+					wp_set_object_terms($object->id, $array_value, $taxonomy);
71 71
 				}
72 72
 			}
73 73
 		}
@@ -90,15 +90,15 @@  discard block
 block discarded – undo
90 90
 	 *
91 91
 	 * @return Object L'objet construit selon le modèle définit / Builded object by model structure
92 92
 	 */
93
-	public function show( $id, $cropped = false ) {
93
+	public function show($id, $cropped = false) {
94 94
 
95
- 		$post = get_post( $id );
96
-		$post = new $this->model_name( $post, $this->meta_key, $cropped );
95
+ 		$post = get_post($id);
96
+		$post = new $this->model_name($post, $this->meta_key, $cropped);
97 97
 
98 98
 		return $post;
99 99
 	}
100 100
 
101
-	public function index( $args_where = array( 'post_parent' => 0 ), $cropped = false ) {
101
+	public function index($args_where = array('post_parent' => 0), $cropped = false) {
102 102
 		$array_model = array();
103 103
 
104 104
 		$args = array(
@@ -107,32 +107,32 @@  discard block
 block discarded – undo
107 107
 			'posts_per_page' 	=> -1,
108 108
 		);
109 109
 
110
-		$args = array_merge( $args, $args_where );
111
-		$array_post = get_posts( $args );
110
+		$args = array_merge($args, $args_where);
111
+		$array_post = get_posts($args);
112 112
 
113
-		if( !empty( $array_post ) ) {
114
-			foreach( $array_post as $key => $post ) {
115
-				$array_model[$key] = new $this->model_name( $post, $this->meta_key, $cropped );
113
+		if (!empty($array_post)) {
114
+			foreach ($array_post as $key => $post) {
115
+				$array_model[$key] = new $this->model_name($post, $this->meta_key, $cropped);
116 116
 			}
117 117
 		}
118 118
 
119 119
 		return $array_model;
120 120
 	}
121 121
 
122
-	public function search( $search, $array ) {
122
+	public function search($search, $array) {
123 123
 			global $wpdb;
124 124
 
125
-			if( empty( $array ) || !is_array( $array ) )
125
+			if (empty($array) || !is_array($array))
126 126
 				return array();
127 127
 
128 128
 			$where = ' AND ( ';
129 129
 
130
-			if ( !empty( $array ) ) {
131
-			  foreach ( $array as $key => $element ) {
132
-					if( is_array( $element ) ) {
133
-						foreach( $element as $sub_element ) {
130
+			if (!empty($array)) {
131
+			  foreach ($array as $key => $element) {
132
+					if (is_array($element)) {
133
+						foreach ($element as $sub_element) {
134 134
 							$where .= $where == ' AND ( ' ? '' : ' OR ';
135
-							$where .= ' (PM.meta_key="' . $sub_element . '" AND PM.meta_value LIKE "%'. $search . '%") ';
135
+							$where .= ' (PM.meta_key="' . $sub_element . '" AND PM.meta_value LIKE "%' . $search . '%") ';
136 136
 						}
137 137
 					}
138 138
 					else {
@@ -145,13 +145,13 @@  discard block
 block discarded – undo
145 145
 			$where .= ' ) ';
146 146
 
147 147
 
148
-			$list_group = $wpdb->get_results( "SELECT DISTINCT P.ID FROM {$wpdb->posts} as P JOIN {$wpdb->postmeta} AS PM ON PM.post_id=P.ID WHERE P.post_type='".$this->get_post_type()."'" . $where );
148
+			$list_group = $wpdb->get_results("SELECT DISTINCT P.ID FROM {$wpdb->posts} as P JOIN {$wpdb->postmeta} AS PM ON PM.post_id=P.ID WHERE P.post_type='" . $this->get_post_type() . "'" . $where);
149 149
 
150 150
 			$list_model = array();
151 151
 
152
-			if ( !empty( $list_group ) ) {
153
-			  foreach ( $list_group as $element ) {
154
-					$list_model[] = $this->show( $element->ID );
152
+			if (!empty($list_group)) {
153
+			  foreach ($list_group as $element) {
154
+					$list_model[] = $this->show($element->ID);
155 155
 			  }
156 156
 			}
157 157
 
@@ -164,13 +164,13 @@  discard block
 block discarded – undo
164 164
 	 * @param mixed $object
165 165
 	 * @return array|WP_Error Array of term_id
166 166
 	 */
167
-	public static function eo_get_object_terms( $object ) {
168
-		$list_term 		= array();
169
-		$array_model 	= $object->get_model();
167
+	public static function eo_get_object_terms($object) {
168
+		$list_term = array();
169
+		$array_model = $object->get_model();
170 170
 
171
-		if( !empty( $array_model ) && !empty( $array_model['taxonomy'] ) ) {
172
-			foreach( $array_model['taxonomy'] as $key => $value ) {
173
-				$list_term[$key] = wp_get_object_terms( $object->id, $key, array( 'fields' => 'ids' ) );
171
+		if (!empty($array_model) && !empty($array_model['taxonomy'])) {
172
+			foreach ($array_model['taxonomy'] as $key => $value) {
173
+				$list_term[$key] = wp_get_object_terms($object->id, $key, array('fields' => 'ids'));
174 174
 			}
175 175
 		}
176 176
 
@@ -193,25 +193,25 @@  discard block
 block discarded – undo
193 193
 	 *
194 194
 	 * @return array La liste des routes personnalisées ajoutées aux routes existantes / The personnalized routes added to existing
195 195
 	 */
196
-	public function callback_register_route( $array_route ) {
196
+	public function callback_register_route($array_route) {
197 197
 		/** Récupération de la liste complète des éléments / Get all existing elements */
198
-		$array_route['/' . $this->version . '/get/' . $this->base ] = array(
199
-				array( array( $this, 'index' ), WP_JSON_Server::READABLE | WP_JSON_Server::ACCEPT_JSON )
198
+		$array_route['/' . $this->version . '/get/' . $this->base] = array(
199
+				array(array($this, 'index'), WP_JSON_Server::READABLE | WP_JSON_Server::ACCEPT_JSON)
200 200
 		);
201 201
 
202 202
 		/** Récupération d'un élément donné / Get a given element */
203 203
 		$array_route['/' . $this->version . '/get/' . $this->base . '/(?P<id>\d+)'] = array(
204
-				array( array( $this, 'show' ), WP_JSON_Server::READABLE |  WP_JSON_Server::ACCEPT_JSON )
204
+				array(array($this, 'show'), WP_JSON_Server::READABLE | WP_JSON_Server::ACCEPT_JSON)
205 205
 		);
206 206
 
207 207
 		/** Mise à jour d'un élément / Update an element */
208 208
 		$array_route['/' . $this->version . '/post/' . $this->base . ''] = array(
209
-				array( array( $this, 'update' ), WP_JSON_Server::CREATABLE | WP_JSON_Server::ACCEPT_JSON ),
209
+				array(array($this, 'update'), WP_JSON_Server::CREATABLE | WP_JSON_Server::ACCEPT_JSON),
210 210
 		);
211 211
 
212 212
 		/** Suppression d'un élément / Delete an element */
213 213
 		$array_route['/' . $this->version . '/delete/' . $this->base . '/(?P<id>\d+)'] = array(
214
-				array( array( $this, 'delete' ), WP_JSON_Server::DELETABLE | WP_JSON_Server::ACCEPT_JSON ),
214
+				array(array($this, 'delete'), WP_JSON_Server::DELETABLE | WP_JSON_Server::ACCEPT_JSON),
215 215
 		);
216 216
 
217 217
 		return $array_route;
@@ -224,11 +224,11 @@  discard block
 block discarded – undo
224 224
 	 *
225 225
 	 * @return boolean|string Le titre du post si il est trouvé, false dans le cas contraire / The post title in case it is founded, false in other case
226 226
 	 */
227
-	public function get_title_by_id( $post_id ) {
228
-		if (  true !== is_int( ( int )$post_id ) )
227
+	public function get_title_by_id($post_id) {
228
+		if (true !== is_int((int)$post_id))
229 229
 			return false;
230 230
 
231
-		$post_title = get_post_field( 'post_title', $post_id );
231
+		$post_title = get_post_field('post_title', $post_id);
232 232
 
233 233
 		return $post_title;
234 234
 	}
Please login to merge, or discard this patch.
Braces   +11 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
 
3 5
 
4 6
 /**
@@ -40,8 +42,7 @@  discard block
 block discarded – undo
40 42
 			foreach( $object->taxonomy as $taxonomy => $array_value ) {
41 43
 				if( !empty( $taxonomy ) && !empty( $array_value ) ) {
42 44
 					wp_set_object_terms( $object->id, $array_value, $taxonomy );
43
-				}
44
-				else if( !empty( $taxonomy ) && empty( $array_value ) ) {
45
+				} else if( !empty( $taxonomy ) && empty( $array_value ) ) {
45 46
 					wp_set_object_terms( $object->id, '', $taxonomy );
46 47
 				}
47 48
 			}
@@ -122,8 +123,9 @@  discard block
 block discarded – undo
122 123
 	public function search( $search, $array ) {
123 124
 			global $wpdb;
124 125
 
125
-			if( empty( $array ) || !is_array( $array ) )
126
-				return array();
126
+			if( empty( $array ) || !is_array( $array ) ) {
127
+							return array();
128
+			}
127 129
 
128 130
 			$where = ' AND ( ';
129 131
 
@@ -134,8 +136,7 @@  discard block
 block discarded – undo
134 136
 							$where .= $where == ' AND ( ' ? '' : ' OR ';
135 137
 							$where .= ' (PM.meta_key="' . $sub_element . '" AND PM.meta_value LIKE "%'. $search . '%") ';
136 138
 						}
137
-					}
138
-					else {
139
+					} else {
139 140
 						$where .= $where == ' AND ( ' ? '' : ' OR ';
140 141
 						$where .= ' P.' . $element . ' LIKE "%' . $search . '%" ';
141 142
 					}
@@ -225,8 +226,9 @@  discard block
 block discarded – undo
225 226
 	 * @return boolean|string Le titre du post si il est trouvé, false dans le cas contraire / The post title in case it is founded, false in other case
226 227
 	 */
227 228
 	public function get_title_by_id( $post_id ) {
228
-		if (  true !== is_int( ( int )$post_id ) )
229
-			return false;
229
+		if (  true !== is_int( ( int )$post_id ) ) {
230
+					return false;
231
+		}
230 232
 
231 233
 		$post_title = get_post_field( 'post_title', $post_id );
232 234
 
Please login to merge, or discard this patch.
core/wpeo_model/model/user_mdl.01.php 2 patches
Spacing   +23 added lines, -23 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
  * Fichier de définition du modèle des utilisateurs / File for user model definition
4 4
  *
@@ -173,24 +173,24 @@  discard block
 block discarded – undo
173 173
 	 * @param string $meta_key Le nom de la "meta" contenant la définition complète de l'object sous forme json / The "meta" name containing the complete definition of object under json format
174 174
 	 * @param boolean $cropped Permet de choisir si on construit le modèle complet ou uniquement les champs principaux / Allows to choose if the entire model have to be build or only main model
175 175
 	 */
176
-	public function __construct( $object, $meta_key, $cropped = false ) {
176
+	public function __construct($object, $meta_key, $cropped = false) {
177 177
 		/**	Instanciation du constructeur de modèle principal / Instanciate the main model constructor	*/
178
-		parent::__construct( $object );
178
+		parent::__construct($object);
179 179
 
180 180
 		/** If cropped don't get meta */
181
-		if ( !$cropped ) {
182
-			$user_meta = get_user_meta( $this->id );
181
+		if (!$cropped) {
182
+			$user_meta = get_user_meta($this->id);
183 183
 
184
-			if ( !empty( $user_meta ) )
185
-				$user_meta = array_merge( $user_meta, get_user_meta( $this->id, $meta_key ) );
184
+			if (!empty($user_meta))
185
+				$user_meta = array_merge($user_meta, get_user_meta($this->id, $meta_key));
186 186
 			else
187
-				$user_meta = get_user_meta( $this->id, $meta_key );
187
+				$user_meta = get_user_meta($this->id, $meta_key);
188 188
 
189
-			$internal_meta = !empty( $user_meta ) && !empty( $user_meta[ $meta_key ] ) && !empty( $user_meta[ $meta_key ][ 0 ] ) ? json_decode( $user_meta[ $meta_key ][ 0 ], true ) : null;
189
+			$internal_meta = !empty($user_meta) && !empty($user_meta[$meta_key]) && !empty($user_meta[$meta_key][0]) ? json_decode($user_meta[$meta_key][0], true) : null;
190 190
 
191
-			if ( !empty( $this->array_option ) ) {
192
-				foreach( $this->array_option as $key => $array ) {
193
-					$this->option[ $key ] = $this->fill_value( $object, $user_meta, $key, $array, $internal_meta );
191
+			if (!empty($this->array_option)) {
192
+				foreach ($this->array_option as $key => $array) {
193
+					$this->option[$key] = $this->fill_value($object, $user_meta, $key, $array, $internal_meta);
194 194
 				}
195 195
 			}
196 196
 		}
@@ -203,19 +203,19 @@  discard block
 block discarded – undo
203 203
 	 *
204 204
 	 * @return string Les initiales de l'utilisateur courant / Current user initial
205 205
 	 */
206
-	public static function build_user_initial( $user ){
206
+	public static function build_user_initial($user) {
207 207
 		$initial = '';
208 208
 
209
-		if ( !empty( $user->option['user_info']['firstname'] ) ) {
210
-			$initial .= substr( $user->option['user_info']['firstname'], 0, 1 );
209
+		if (!empty($user->option['user_info']['firstname'])) {
210
+			$initial .= substr($user->option['user_info']['firstname'], 0, 1);
211 211
 		}
212
-		if ( !empty( $user->option['user_info']['lastname'] ) ) {
213
-			$initial .= substr( $user->option['user_info']['lastname'], 0, 1 );
212
+		if (!empty($user->option['user_info']['lastname'])) {
213
+			$initial .= substr($user->option['user_info']['lastname'], 0, 1);
214 214
 		}
215 215
 
216
-		if ( empty( $initial ) ) {
217
-			if ( !empty( $user->login ) ) {
218
-				$initial .= substr( $user->login, 0, 1 );
216
+		if (empty($initial)) {
217
+			if (!empty($user->login)) {
218
+				$initial .= substr($user->login, 0, 1);
219 219
 			}
220 220
 		}
221 221
 
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
 	 *
233 233
 	 * @return string L'adresse url du gravatar de l'utilisateur / The url address of current user gravatar
234 234
 	 */
235
-	public static function build_user_avatar_url( $user ) {
236
-		if ( empty( $user ) || empty( $user->user_email ) )
235
+	public static function build_user_avatar_url($user) {
236
+		if (empty($user) || empty($user->user_email))
237 237
 			return self::$gravatar_url . '00000000000000000000000000000000?d=blank';
238 238
 
239
-		return self::$gravatar_url . md5( $user->user_email );
239
+		return self::$gravatar_url . md5($user->user_email);
240 240
 	}
241 241
 
242 242
 }
Please login to merge, or discard this patch.
Braces   +11 added lines, -7 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
  * Fichier de définition du modèle des utilisateurs / File for user model definition
4 6
  *
@@ -181,10 +183,11 @@  discard block
 block discarded – undo
181 183
 		if ( !$cropped ) {
182 184
 			$user_meta = get_user_meta( $this->id );
183 185
 
184
-			if ( !empty( $user_meta ) )
185
-				$user_meta = array_merge( $user_meta, get_user_meta( $this->id, $meta_key ) );
186
-			else
187
-				$user_meta = get_user_meta( $this->id, $meta_key );
186
+			if ( !empty( $user_meta ) ) {
187
+							$user_meta = array_merge( $user_meta, get_user_meta( $this->id, $meta_key ) );
188
+			} else {
189
+							$user_meta = get_user_meta( $this->id, $meta_key );
190
+			}
188 191
 
189 192
 			$internal_meta = !empty( $user_meta ) && !empty( $user_meta[ $meta_key ] ) && !empty( $user_meta[ $meta_key ][ 0 ] ) ? json_decode( $user_meta[ $meta_key ][ 0 ], true ) : null;
190 193
 
@@ -233,8 +236,9 @@  discard block
 block discarded – undo
233 236
 	 * @return string L'adresse url du gravatar de l'utilisateur / The url address of current user gravatar
234 237
 	 */
235 238
 	public static function build_user_avatar_url( $user ) {
236
-		if ( empty( $user ) || empty( $user->user_email ) )
237
-			return self::$gravatar_url . '00000000000000000000000000000000?d=blank';
239
+		if ( empty( $user ) || empty( $user->user_email ) ) {
240
+					return self::$gravatar_url . '00000000000000000000000000000000?d=blank';
241
+		}
238 242
 
239 243
 		return self::$gravatar_url . md5( $user->user_email );
240 244
 	}
Please login to merge, or discard this patch.
core/wpeo_model/model/comment_mdl.01.php 2 patches
Spacing   +9 added lines, -9 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
  * Fichier de définition du modèle des commentaires / File for comment model definition
4 4
  *
@@ -109,18 +109,18 @@  discard block
 block discarded – undo
109 109
 	 * @param string $meta_key Le nom de la "meta" contenant la définition complète de l'object sous forme json / The "meta" name containing the complete definition of object under json format
110 110
 	 * @param boolean $cropped Permet de choisir si on construit le modèle complet ou uniquement les champs principaux / Allows to choose if the entire model have to be build or only main model
111 111
 	 */
112
-	public function __construct( $object, $meta_key, $cropped ) {
113
-		parent::__construct( $object );
112
+	public function __construct($object, $meta_key, $cropped) {
113
+		parent::__construct($object);
114 114
 
115 115
 		/** If cropped, don't get meta */
116
-		if(!$cropped) {
116
+		if (!$cropped) {
117 117
 			/** Meta */
118
-			$comment_meta = get_comment_meta( $this->id );
119
-			$internal_meta = !empty( $comment_meta ) && !empty( $comment_meta[ $meta_key ] ) && !empty( $comment_meta[ $meta_key ][ 0 ] ) ? json_decode( $comment_meta[ $meta_key ][ 0 ], true ) : null;
118
+			$comment_meta = get_comment_meta($this->id);
119
+			$internal_meta = !empty($comment_meta) && !empty($comment_meta[$meta_key]) && !empty($comment_meta[$meta_key][0]) ? json_decode($comment_meta[$meta_key][0], true) : null;
120 120
 
121
-			if( !empty( $this->array_option ) ) {
122
-				foreach( $this->array_option as $key => $array ) {
123
-					$this->option[ $key ] = $this->fill_value( $object, $comment_meta, $key, $array, $internal_meta );
121
+			if (!empty($this->array_option)) {
122
+				foreach ($this->array_option as $key => $array) {
123
+					$this->option[$key] = $this->fill_value($object, $comment_meta, $key, $array, $internal_meta);
124 124
 				}
125 125
 			}
126 126
 		}
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.
core/wpeo_model/model/post_mdl.01.php 2 patches
Spacing   +9 added lines, -9 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
  * Fichier de définition du modèle des éléments "custom post type" / File for "custom post types" element model definition
4 4
  *
@@ -127,19 +127,19 @@  discard block
 block discarded – undo
127 127
 	 * @param string $meta_key Le nom de la "meta" contenant la définition complète de l'object sous forme json / The "meta" name containing the complete definition of object under json format
128 128
 	 * @param boolean $cropped Permet de choisir si on construit le modèle complet ou uniquement les champs principaux / Allows to choose if the entire model have to be build or only main model
129 129
 	 */
130
-	public function __construct( $object, $meta_key, $cropped ) {
130
+	public function __construct($object, $meta_key, $cropped) {
131 131
 		/**	Instanciation du constructeur de modèle principal / Instanciate the main model constructor	*/
132
-		parent::__construct( $object );
132
+		parent::__construct($object);
133 133
 
134 134
 		/** If cropped don't get meta */
135
-		if(!$cropped) {
135
+		if (!$cropped) {
136 136
 
137 137
 			/** Meta */
138
-			$post_meta = get_post_meta( $this->id );
139
-			$internal_meta = !empty( $post_meta ) && !empty( $post_meta[ $meta_key ] ) && !empty( $post_meta[ $meta_key ][ 0 ] ) ? json_decode( $post_meta[ $meta_key ][ 0 ], true ) : null;
140
-			if( !empty( $this->array_option ) ) {
141
-				foreach( $this->array_option as $key => $array ) {
142
-					$this->option[ $key ] = $this->fill_value( $object, $post_meta, $key, $array, $internal_meta );
138
+			$post_meta = get_post_meta($this->id);
139
+			$internal_meta = !empty($post_meta) && !empty($post_meta[$meta_key]) && !empty($post_meta[$meta_key][0]) ? json_decode($post_meta[$meta_key][0], true) : null;
140
+			if (!empty($this->array_option)) {
141
+				foreach ($this->array_option as $key => $array) {
142
+					$this->option[$key] = $this->fill_value($object, $post_meta, $key, $array, $internal_meta);
143 143
 				}
144 144
 			}
145 145
 
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.
core/wpeo_model/model/term_mdl.01.php 2 patches
Spacing   +9 added lines, -9 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
  * Fichier de définition du modèle des taxinomies / File for term model definition
4 4
  *
@@ -103,19 +103,19 @@  discard block
 block discarded – undo
103 103
 	 * @param string $meta_key Le nom de la "meta" contenant la définition complète de l'object sous forme json / The "meta" name containing the complete definition of object under json format
104 104
 	 * @param boolean $cropped Permet de choisir si on construit le modèle complet ou uniquement les champs principaux / Allows to choose if the entire model have to be build or only main model
105 105
 	 */
106
-	public function __construct( $object, $meta_key, $cropped ) {
106
+	public function __construct($object, $meta_key, $cropped) {
107 107
 		/**	Instanciation du constructeur de modèle principal / Instanciate the main model constructor	*/
108
-		parent::__construct( $object );
108
+		parent::__construct($object);
109 109
 
110 110
 		/** If cropped don't get meta */
111
-		if( !$cropped ) {
111
+		if (!$cropped) {
112 112
 			/** Lecture des "metas" pour la taxinomie / Read taxonomy "meta" */
113
-			$meta = get_term_meta( $this->id );
114
-			$internal_meta = !empty( $meta ) && !empty( $meta[ $meta_key ] ) && !empty( $meta[ $meta_key ][ 0 ] ) ? json_decode( $meta[ $meta_key ][ 0 ], true ) : null;
113
+			$meta = get_term_meta($this->id);
114
+			$internal_meta = !empty($meta) && !empty($meta[$meta_key]) && !empty($meta[$meta_key][0]) ? json_decode($meta[$meta_key][0], true) : null;
115 115
 
116
-			if( !empty( $this->array_option ) ) {
117
-				foreach( $this->array_option as $key => $array ) {
118
-					$this->option[ $key ] = $this->fill_value( $object, $meta, $key, $array, $internal_meta );
116
+			if (!empty($this->array_option)) {
117
+				foreach ($this->array_option as $key => $array) {
118
+					$this->option[$key] = $this->fill_value($object, $meta, $key, $array, $internal_meta);
119 119
 				}
120 120
 			}
121 121
 		}
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_barcode/controller/wps_barcode_ajax.ctr.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -248,7 +248,7 @@
 block discarded – undo
248 248
 
249 249
 	/**
250 250
 	 * Generate barcode image
251
-	 * @param object $barcode Instance of wps_barcodegen
251
+	 * @param wps_barcodegen $barcode Instance of wps_barcodegen
252 252
 	 * @param string $meta Numerical code of barcode
253 253
 	 * @param string $type Texte for complete message
254 254
 	 * @param string $price Price of product
Please login to merge, or discard this patch.
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 class wps_barcode_ajax {
4 4
 	public function __construct() {
5
-		add_action( 'wp_ajax_barcode_img_product', array($this, 'imgProduct') );
6
-		add_action( 'wp_ajax_barcode_img_coupons', array($this, 'imgCoupons') );
5
+		add_action('wp_ajax_barcode_img_product', array($this, 'imgProduct'));
6
+		add_action('wp_ajax_barcode_img_coupons', array($this, 'imgCoupons'));
7 7
 	}
8 8
 
9 9
 	// @TODO : NONCE
10 10
 	public function imgProduct() {
11
-		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
11
+		$_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : '';
12 12
 
13
-		if ( !wp_verify_nonce( $_wpnonce, 'imgProduct' ) )
13
+		if (!wp_verify_nonce($_wpnonce, 'imgProduct'))
14 14
 			wp_die();
15 15
 
16 16
 		global $meta, $barcode, $post_ID, $wpdb, $table_prefix, $gg;
@@ -24,17 +24,17 @@  discard block
 block discarded – undo
24 24
 
25 25
 		/*Select value of barcode*/
26 26
 		$result = $wpdb->get_results(
27
-				'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR.
28
-				' WHERE attribute_id=(SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE.
29
-				' WHERE code = "barcode") AND entity_id="'.$post_ID.'"', ARRAY_A);
27
+				'SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR .
28
+				' WHERE attribute_id=(SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE .
29
+				' WHERE code = "barcode") AND entity_id="' . $post_ID . '"', ARRAY_A);
30 30
 		$meta = !empty($result) ? $result[0]['value'] : '';
31 31
 
32 32
 		/*Get price of product*/
33
-		$result = $wpdb->get_results('SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL.
34
-				' WHERE attribute_id=(SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE.
35
-				' WHERE code="'.WPSHOP_PRODUCT_PRICE_TTC.'") AND entity_id='.$post_ID, ARRAY_A);
33
+		$result = $wpdb->get_results('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL .
34
+				' WHERE attribute_id=(SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE .
35
+				' WHERE code="' . WPSHOP_PRODUCT_PRICE_TTC . '") AND entity_id=' . $post_ID, ARRAY_A);
36 36
 
37
-		if ( !empty($result) && $result[0]['value'] >= 0) {
37
+		if (!empty($result) && $result[0]['value'] >= 0) {
38 38
 			$price = $result[0]['value'];
39 39
 
40 40
 			$post = get_post($post_ID, ARRAY_A);
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 	}
49 49
 
50 50
 	public function imgCoupons() {
51
-		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
51
+		$_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : '';
52 52
 
53
-		if ( !wp_verify_nonce( $_wpnonce, 'imgProduct' ) )
53
+		if (!wp_verify_nonce($_wpnonce, 'imgProduct'))
54 54
 			wp_die();
55 55
 
56 56
 		global $meta, $barcode, $post_ID, $wpdb, $table_prefix;
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
 		$country = '000';
67 67
 		$result = get_post_meta($post_ID);
68 68
 
69
-		if ( !empty($result) ) {
70
-			if ( empty($result['wpshop_coupon_barcode']) ) {
69
+		if (!empty($result)) {
70
+			if (empty($result['wpshop_coupon_barcode'])) {
71 71
 				$conf = get_option('wps_barcode');
72 72
 				if ($conf['type'] === 'internal') {
73 73
 					$type = $conf['internal_coupons'];
74 74
 
75
-					$query = $wpdb->get_results('SELECT post_date FROM '.
76
-							$table_prefix.'posts WHERE ID='.$post_ID, ARRAY_A);
75
+					$query = $wpdb->get_results('SELECT post_date FROM ' .
76
+							$table_prefix . 'posts WHERE ID=' . $post_ID, ARRAY_A);
77 77
 
78 78
 					$pDate = new DateTime($query[0]['post_date']);
79 79
 					$date = $pDate->format('my');
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 
82 82
 				$len = strlen($post_ID);
83 83
 				$ref = '';
84
-				if ( $len < 5 ) {
85
-					for ($i=0; $i <= $len; $i++) {
84
+				if ($len < 5) {
85
+					for ($i = 0; $i <= $len; $i++) {
86 86
 						$ref .= '0';
87 87
 					}
88 88
 				}
89
-				$id = $ref.$post_ID;
90
-				$code = $type.$date.$id;
89
+				$id = $ref . $post_ID;
90
+				$code = $type . $date . $id;
91 91
 				$meta = $barcode->checksum($code);
92 92
 				add_post_meta($post_ID, 'wpshop_coupon_barcode', $meta);
93 93
 			}
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
 				$meta = $result['wpshop_coupon_barcode'][0];
96 96
 			}
97 97
 
98
-			$query = $wpdb->get_results('SELECT post_title FROM '.
99
-					$table_prefix.'posts WHERE ID='.$post_ID, ARRAY_A);
98
+			$query = $wpdb->get_results('SELECT post_title FROM ' .
99
+					$table_prefix . 'posts WHERE ID=' . $post_ID, ARRAY_A);
100 100
 
101 101
 			$post = get_post($post_ID, ARRAY_A);
102 102
 
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 			wp_die();
108 108
 		}
109 109
 		else {
110
-			echo '<p>'.__('None bardcode generated as coupon has not created.',
111
-					'wps_barcode').'</p>';
110
+			echo '<p>' . __('None bardcode generated as coupon has not created.',
111
+					'wps_barcode') . '</p>';
112 112
 			wp_die();
113 113
 		}
114 114
 	}
@@ -122,41 +122,41 @@  discard block
 block discarded – undo
122 122
 	 * @param string $title Title of product
123 123
 	 */
124 124
 	public function generate_image(&$barcode, $meta, $type, $price, $title, $post_ID = 0) {
125
-		if ( !empty($meta) ) {
125
+		if (!empty($meta)) {
126 126
 			$barcode->setGenerateCode($meta);
127 127
 			$binCode = $barcode->getBinCode();
128 128
 
129 129
 			$px = 3.779528;
130
-			$x = round(66*$px); //249.449 px
131
-			$y = round(50*$px); //188.976 px
132
-			$bar_size = round(63.393/72); //0.880 px
130
+			$x = round(66 * $px); //249.449 px
131
+			$y = round(50 * $px); //188.976 px
132
+			$bar_size = round(63.393 / 72); //0.880 px
133 133
 
134 134
 			$len = 0;
135 135
 			$test = '';
136 136
 
137
-			while ($len !== strlen($binCode) ) {
138
-				$test .= substr($binCode, $len, 7).' ';
139
-				$len = $len+7;
137
+			while ($len !== strlen($binCode)) {
138
+				$test .= substr($binCode, $len, 7) . ' ';
139
+				$len = $len + 7;
140 140
 			}
141 141
 
142 142
 			$im = imagecreate($x, $y);
143 143
 			$background_color = imagecolorallocate($im, 255, 255, 255);
144
-			$start = round(5.79*$px); //21.883
144
+			$start = round(5.79 * $px); //21.883
145 145
 
146 146
 			/*Write First left guard*/
147
-			$this->imgNormalGuard($im, $start, $start+$bar_size,
147
+			$this->imgNormalGuard($im, $start, $start + $bar_size,
148 148
 					imagecolorallocate($im, 0, 0, 0));
149
-			$this->imgNormalGuard($im, $start+($bar_size*2),
150
-					$start+($bar_size*3), imagecolorallocate($im, 255, 255, 255));
151
-			$this->imgNormalGuard($im, $start+($bar_size*4),
152
-					$start+($bar_size*5), imagecolorallocate($im, 0, 0, 0));
149
+			$this->imgNormalGuard($im, $start + ($bar_size * 2),
150
+					$start + ($bar_size * 3), imagecolorallocate($im, 255, 255, 255));
151
+			$this->imgNormalGuard($im, $start + ($bar_size * 4),
152
+					$start + ($bar_size * 5), imagecolorallocate($im, 0, 0, 0));
153 153
 
154
-			$pos = $start+($bar_size*7);
155
-			$newPos = $pos+$bar_size;
154
+			$pos = $start + ($bar_size * 7);
155
+			$newPos = $pos + $bar_size;
156 156
 
157 157
 			/*Write left barcode*/
158
-			for ($i=0; $i<42 ; $i++) {
159
-				if( substr($binCode, $i, 1) === '0' ) {
158
+			for ($i = 0; $i < 42; $i++) {
159
+				if (substr($binCode, $i, 1) === '0') {
160 160
 					$color = imagecolorallocate($im, 255, 255, 255);
161 161
 				}
162 162
 				else {
@@ -164,108 +164,108 @@  discard block
 block discarded – undo
164 164
 				}
165 165
 
166 166
 				$this->imgSymbole($im, $pos, $newPos, $color);
167
-				$newPos = $pos+$bar_size;
168
-				$pos = $newPos+$bar_size;
167
+				$newPos = $pos + $bar_size;
168
+				$pos = $newPos + $bar_size;
169 169
 			}
170 170
 
171 171
 			/*Writer center guard*/
172 172
 			$pos = $newPos;
173
-			$this->imgNormalGuard($im, $pos, $newPos+$bar_size,
173
+			$this->imgNormalGuard($im, $pos, $newPos + $bar_size,
174 174
 					imagecolorallocate($im, 255, 255, 255));
175
-			$this->imgNormalGuard($im, $pos+($bar_size*2),
176
-					$newPos+($bar_size*3), imagecolorallocate($im, 0, 0, 0));
177
-			$this->imgNormalGuard($im, $pos+($bar_size*4),
178
-					$newPos+($bar_size*5), imagecolorallocate($im, 255, 255, 255));
179
-			$this->imgNormalGuard($im, $pos+($bar_size*6),
180
-					$newPos+($bar_size*7), imagecolorallocate($im, 0, 0, 0));
181
-			$this->imgNormalGuard($im, $pos+($bar_size*8),
182
-					$newPos+($bar_size*9), imagecolorallocate($im, 255, 255, 255));
175
+			$this->imgNormalGuard($im, $pos + ($bar_size * 2),
176
+					$newPos + ($bar_size * 3), imagecolorallocate($im, 0, 0, 0));
177
+			$this->imgNormalGuard($im, $pos + ($bar_size * 4),
178
+					$newPos + ($bar_size * 5), imagecolorallocate($im, 255, 255, 255));
179
+			$this->imgNormalGuard($im, $pos + ($bar_size * 6),
180
+					$newPos + ($bar_size * 7), imagecolorallocate($im, 0, 0, 0));
181
+			$this->imgNormalGuard($im, $pos + ($bar_size * 8),
182
+					$newPos + ($bar_size * 9), imagecolorallocate($im, 255, 255, 255));
183 183
 
184
-			$pos = $newPos+($bar_size*10);
184
+			$pos = $newPos + ($bar_size * 10);
185 185
 
186 186
 			/*Write right barcode*/
187
-			for ($i=42; $i<84 ; $i++) {
188
-				if( substr($binCode, $i, 1) === '0' ) {
187
+			for ($i = 42; $i < 84; $i++) {
188
+				if (substr($binCode, $i, 1) === '0') {
189 189
 					$color = imagecolorallocate($im, 255, 255, 255);
190 190
 				}
191 191
 				else {
192 192
 					$color = imagecolorallocate($im, 0, 0, 0);
193 193
 				}
194 194
 
195
-				$newPos = $pos+$bar_size;
195
+				$newPos = $pos + $bar_size;
196 196
 
197 197
 				$this->imgSymbole($im, $pos, $newPos, $color);
198
-				$pos = $newPos+$bar_size;
198
+				$pos = $newPos + $bar_size;
199 199
 			}
200 200
 
201 201
 			/*Write right guard*/
202
-			$pos = $newPos+$bar_size;
203
-			$this->imgNormalGuard($im, $pos, $pos+$bar_size,
202
+			$pos = $newPos + $bar_size;
203
+			$this->imgNormalGuard($im, $pos, $pos + $bar_size,
204 204
 					imagecolorallocate($im, 0, 0, 0));
205
-			$this->imgNormalGuard($im, $pos+($bar_size*2),
206
-					$pos+($bar_size*3), imagecolorallocate($im, 255, 255, 255));
207
-			$this->imgNormalGuard($im, $pos+($bar_size*4),
208
-					$pos+($bar_size*5), imagecolorallocate($im, 0, 0, 0));
205
+			$this->imgNormalGuard($im, $pos + ($bar_size * 2),
206
+					$pos + ($bar_size * 3), imagecolorallocate($im, 255, 255, 255));
207
+			$this->imgNormalGuard($im, $pos + ($bar_size * 4),
208
+					$pos + ($bar_size * 5), imagecolorallocate($im, 0, 0, 0));
209 209
 
210 210
 			$textSize = 16;
211
-			$font = WPS_BARCODE_FONTS.'/arialbd.ttf';
212
-			imagettftext($im, $textSize, 0, 8, $y-$start-5,
211
+			$font = WPS_BARCODE_FONTS . '/arialbd.ttf';
212
+			imagettftext($im, $textSize, 0, 8, $y - $start - 5,
213 213
 			imagecolorallocate($im, 0, 0, 0), $font, substr($meta, 0, 1));
214 214
 
215 215
 			$continue = true;
216 216
 			$i = 28; $j = 0;
217 217
 
218 218
 			/*Write left number code*/
219
-			while ($j<5) {
220
-				$j=$j+1;
221
-				imagettftext($im, $textSize, 0, $i, $y-$start-5,
219
+			while ($j < 5) {
220
+				$j = $j + 1;
221
+				imagettftext($im, $textSize, 0, $i, $y - $start - 5,
222 222
 				imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j, 1));
223
-				$i = $i+14;
223
+				$i = $i + 14;
224 224
 			}
225 225
 
226 226
 			/*Write right number code*/
227
-			while ($j<11) {
228
-				$j=$j+1;
229
-				imagettftext($im, $textSize, 0, $i+6, $y-$start-5,
227
+			while ($j < 11) {
228
+				$j = $j + 1;
229
+				imagettftext($im, $textSize, 0, $i + 6, $y - $start - 5,
230 230
 					imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j, 1));
231
-				$i = $i+15;
231
+				$i = $i + 15;
232 232
 			}
233
-			imagettftext($im, $textSize, 0, $i+4, $y-$start-5,
234
-				imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j+1, 1));
233
+			imagettftext($im, $textSize, 0, $i + 4, $y - $start - 5,
234
+				imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j + 1, 1));
235 235
 
236 236
 			/*Write ref product and price*/
237 237
 			$textSize = 12;
238 238
 			$currency = (wpshop_tools::wpshop_get_currency() === '&euro;') ? "€" : wpshop_tools::wpshop_get_currency();
239 239
 
240
-			if ( $type === __('coupon', 'wps_barcode') ) {
240
+			if ($type === __('coupon', 'wps_barcode')) {
241 241
 				$coupon_postmeta = get_post_meta($post_ID, 'wpshop_coupon_discount_type');
242
-				if ( $coupon_postmeta[0] === 'percent' ) {
243
-					$price = $price.' %';
242
+				if ($coupon_postmeta[0] === 'percent') {
243
+					$price = $price . ' %';
244 244
 				}
245 245
 				else {
246
-					$price = sprintf( number_format( $price, 2 ). ' '.$currency);
246
+					$price = sprintf(number_format($price, 2) . ' ' . $currency);
247 247
 				}
248 248
 			}
249 249
 			else {
250
-				$price = sprintf( number_format( $price, 2 ). ' '.$currency);
250
+				$price = sprintf(number_format($price, 2) . ' ' . $currency);
251 251
 			}
252 252
 
253
-			imagettftext($im, $textSize, 0, 20, round(6*$px),
253
+			imagettftext($im, $textSize, 0, 20, round(6 * $px),
254 254
 				imagecolorallocate($im, 0, 0, 0), $font, $title);
255
-			imagettftext($im, $textSize, 0, ($x/2)+40, round(6*$px),
255
+			imagettftext($im, $textSize, 0, ($x / 2) + 40, round(6 * $px),
256 256
 				imagecolorallocate($im, 0, 0, 0), $font, $price);
257 257
 
258 258
 			ob_start();
259 259
 			imagepng($im);
260 260
 			$img = ob_get_clean();
261 261
 
262
-			return '<p><img src="data:image/png;base64,'.base64_encode($img).
263
-			'" id="barcode" width="160" height="90" /></p>'.
262
+			return '<p><img src="data:image/png;base64,' . base64_encode($img) .
263
+			'" id="barcode" width="160" height="90" /></p>' .
264 264
 
265
-			'<p style="text-align: right"><button class="button '.
266
-					'button-primary button-large" type="button"'.
267
-					'id="print_barcode">'.
268
-					__('Print', 'wps_barcode').'</button></p>';
265
+			'<p style="text-align: right"><button class="button ' .
266
+					'button-primary button-large" type="button"' .
267
+					'id="print_barcode">' .
268
+					__('Print', 'wps_barcode') . '</button></p>';
269 269
 
270 270
 					/*wp_mkdir_p( WPS_BARCODE_UPLOAD );
271 271
 
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 					}*/
285 285
 		}
286 286
 		else {
287
-			return '<p>'.sprintf( __('None bardcode generated as you did create %s.',
288
-					'wps_barcode'), $type).'</p>';
287
+			return '<p>' . sprintf(__('None bardcode generated as you did create %s.',
288
+					'wps_barcode'), $type) . '</p>';
289 289
 		}
290 290
 	}
291 291
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 	 * @param integer $color Color of rectangle
298 298
 	 */
299 299
 	private function imgNormalGuard(&$image, $pos, $size, $color) {
300
-		imagefilledrectangle($image, $pos, 180*0.25,$size, 180-10, $color );
300
+		imagefilledrectangle($image, $pos, 180 * 0.25, $size, 180 - 10, $color);
301 301
 	}
302 302
 
303 303
 	/**
@@ -308,6 +308,6 @@  discard block
 block discarded – undo
308 308
 	 * @param integer $color Color of rectangle
309 309
 	 */
310 310
 	private function imgSymbole(&$image, $pos, $size, $color) {
311
-		imagefilledrectangle($image, $pos, 180*0.25,$size, 180-40, $color );
311
+		imagefilledrectangle($image, $pos, 180 * 0.25, $size, 180 - 40, $color);
312 312
 	}
313 313
 }
Please login to merge, or discard this patch.
Braces   +16 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
 
3 5
 class wps_barcode_ajax {
4 6
 	public function __construct() {
@@ -10,8 +12,9 @@  discard block
 block discarded – undo
10 12
 	public function imgProduct() {
11 13
 		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
12 14
 
13
-		if ( !wp_verify_nonce( $_wpnonce, 'imgProduct' ) )
14
-			wp_die();
15
+		if ( !wp_verify_nonce( $_wpnonce, 'imgProduct' ) ) {
16
+					wp_die();
17
+		}
15 18
 
16 19
 		global $meta, $barcode, $post_ID, $wpdb, $table_prefix, $gg;
17 20
 		require_once('wps_barcodegen.ctr.php');
@@ -50,8 +53,9 @@  discard block
 block discarded – undo
50 53
 	public function imgCoupons() {
51 54
 		$_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
52 55
 
53
-		if ( !wp_verify_nonce( $_wpnonce, 'imgProduct' ) )
54
-			wp_die();
56
+		if ( !wp_verify_nonce( $_wpnonce, 'imgProduct' ) ) {
57
+					wp_die();
58
+		}
55 59
 
56 60
 		global $meta, $barcode, $post_ID, $wpdb, $table_prefix;
57 61
 
@@ -90,8 +94,7 @@  discard block
 block discarded – undo
90 94
 				$code = $type.$date.$id;
91 95
 				$meta = $barcode->checksum($code);
92 96
 				add_post_meta($post_ID, 'wpshop_coupon_barcode', $meta);
93
-			}
94
-			else {
97
+			} else {
95 98
 				$meta = $result['wpshop_coupon_barcode'][0];
96 99
 			}
97 100
 
@@ -105,8 +108,7 @@  discard block
 block discarded – undo
105 108
 			$array = array('img' => $barcode);
106 109
 			echo json_encode($array);
107 110
 			wp_die();
108
-		}
109
-		else {
111
+		} else {
110 112
 			echo '<p>'.__('None bardcode generated as coupon has not created.',
111 113
 					'wps_barcode').'</p>';
112 114
 			wp_die();
@@ -158,8 +160,7 @@  discard block
 block discarded – undo
158 160
 			for ($i=0; $i<42 ; $i++) {
159 161
 				if( substr($binCode, $i, 1) === '0' ) {
160 162
 					$color = imagecolorallocate($im, 255, 255, 255);
161
-				}
162
-				else {
163
+				} else {
163 164
 					$color = imagecolorallocate($im, 0, 0, 0);
164 165
 				}
165 166
 
@@ -187,8 +188,7 @@  discard block
 block discarded – undo
187 188
 			for ($i=42; $i<84 ; $i++) {
188 189
 				if( substr($binCode, $i, 1) === '0' ) {
189 190
 					$color = imagecolorallocate($im, 255, 255, 255);
190
-				}
191
-				else {
191
+				} else {
192 192
 					$color = imagecolorallocate($im, 0, 0, 0);
193 193
 				}
194 194
 
@@ -241,12 +241,10 @@  discard block
 block discarded – undo
241 241
 				$coupon_postmeta = get_post_meta($post_ID, 'wpshop_coupon_discount_type');
242 242
 				if ( $coupon_postmeta[0] === 'percent' ) {
243 243
 					$price = $price.' %';
244
-				}
245
-				else {
244
+				} else {
246 245
 					$price = sprintf( number_format( $price, 2 ). ' '.$currency);
247 246
 				}
248
-			}
249
-			else {
247
+			} else {
250 248
 				$price = sprintf( number_format( $price, 2 ). ' '.$currency);
251 249
 			}
252 250
 
@@ -282,8 +280,7 @@  discard block
 block discarded – undo
282 280
 					} catch (Exception $e) {
283 281
 						echo __('Generation problem', 'wps_barcode');
284 282
 					}*/
285
-		}
286
-		else {
283
+		} else {
287 284
 			return '<p>'.sprintf( __('None bardcode generated as you did create %s.',
288 285
 					'wps_barcode'), $type).'</p>';
289 286
 		}
Please login to merge, or discard this patch.