Completed
Push — develop ( b5cd4d...6f9401 )
by David
04:39
created
src/admin/WL_Metabox/WL_Metabox_Field_date.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -18,69 +18,69 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class WL_Metabox_Field_date extends WL_Metabox_Field {
20 20
 
21
-	/**
22
-	 * Attribute to distinguish between date formats, inferred from the schema property export type
23
-	 *
24
-	 * @since  3.2.0
25
-	 * @access private
26
-	 * @var string $date_format The date format.
27
-	 */
28
-	private $date_format;
29
-
30
-	/**
31
-	 * Boolean flag to decide if the calendar should include time or not
32
-	 *
33
-	 * @since  3.2.0
34
-	 * @access private
35
-	 * @var boolean $timepicker A boolean flag.
36
-	 */
37
-	private $timepicker;
38
-
39
-	/**
40
-	 * {@inheritdoc}
41
-	 */
42
-	public function __construct( $args ) {
43
-		parent::__construct( $args );
44
-
45
-		// Distinguish between date and datetime
46
-		if ( isset( $this->raw_custom_field['export_type'] ) && 'xsd:datetime' === $this->raw_custom_field['export_type'] ) {
47
-			$this->date_format = 'Y/m/d H:i';
48
-			$this->timepicker  = true;
49
-		} else {
50
-			$this->date_format = 'Y/m/d';
51
-			$this->timepicker  = false;
52
-		}
53
-
54
-	}
55
-
56
-	/**
57
-	 * @param mixed $date
58
-	 *
59
-	 * @return string
60
-	 */
61
-	public function html_input( $date ) {
62
-
63
-		$picker_date = ( empty( $date ) ? '' : esc_attr( date( $this->date_format, strtotime( $date ) ) ) );
64
-
65
-		return <<<EOF
21
+    /**
22
+     * Attribute to distinguish between date formats, inferred from the schema property export type
23
+     *
24
+     * @since  3.2.0
25
+     * @access private
26
+     * @var string $date_format The date format.
27
+     */
28
+    private $date_format;
29
+
30
+    /**
31
+     * Boolean flag to decide if the calendar should include time or not
32
+     *
33
+     * @since  3.2.0
34
+     * @access private
35
+     * @var boolean $timepicker A boolean flag.
36
+     */
37
+    private $timepicker;
38
+
39
+    /**
40
+     * {@inheritdoc}
41
+     */
42
+    public function __construct( $args ) {
43
+        parent::__construct( $args );
44
+
45
+        // Distinguish between date and datetime
46
+        if ( isset( $this->raw_custom_field['export_type'] ) && 'xsd:datetime' === $this->raw_custom_field['export_type'] ) {
47
+            $this->date_format = 'Y/m/d H:i';
48
+            $this->timepicker  = true;
49
+        } else {
50
+            $this->date_format = 'Y/m/d';
51
+            $this->timepicker  = false;
52
+        }
53
+
54
+    }
55
+
56
+    /**
57
+     * @param mixed $date
58
+     *
59
+     * @return string
60
+     */
61
+    public function html_input( $date ) {
62
+
63
+        $picker_date = ( empty( $date ) ? '' : esc_attr( date( $this->date_format, strtotime( $date ) ) ) );
64
+
65
+        return <<<EOF
66 66
 			<div class="wl-input-wrapper">
67 67
 				<input type="text" class="$this->meta_name" value="$picker_date" style="width:88%" />
68 68
 				<input type="hidden" class="$this->meta_name" name="wl_metaboxes[$this->meta_name][]" value="$date" />
69 69
 				<button class="button wl-remove-input wl-button" type="button" style="width:10%">Remove</button>
70 70
 			</div>
71 71
 EOF;
72
-	}
72
+    }
73 73
 
74
-	public function html_wrapper_close() {
74
+    public function html_wrapper_close() {
75 75
 
76
-		// Should the widget include time picker?
77
-		$timepicker = json_encode( $this->timepicker );
76
+        // Should the widget include time picker?
77
+        $timepicker = json_encode( $this->timepicker );
78 78
 
79
-		// Set up the datetimepicker.
80
-		//
81
-		// See https://github.com/trentrichardson/jQuery-Timepicker-Addon
82
-		// See in http://trentrichardson.com/examples/timepicker.
83
-		$html = <<<EOF
79
+        // Set up the datetimepicker.
80
+        //
81
+        // See https://github.com/trentrichardson/jQuery-Timepicker-Addon
82
+        // See in http://trentrichardson.com/examples/timepicker.
83
+        $html = <<<EOF
84 84
 			<script type='text/javascript'>
85 85
 				( function( $ ) {
86 86
 
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 			</script>
112 112
 EOF;
113 113
 
114
-		$html .= parent::html_wrapper_close();
114
+        $html .= parent::html_wrapper_close();
115 115
 
116
-		return $html;
117
-	}
116
+        return $html;
117
+    }
118 118
 
119 119
 }
Please login to merge, or discard this patch.
src/admin/WL_Metabox/WL_Metabox.php 2 patches
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -14,274 +14,274 @@
 block discarded – undo
14 14
  */
15 15
 class WL_Metabox {
16 16
 
17
-	public $fields;
18
-
19
-	/**
20
-	 * WL_Metabox constructor.
21
-	 *
22
-	 * @since 3.1.0
23
-	 */
24
-	public function __construct() {
25
-
26
-		// Add hooks to print metaboxes and save submitted data.
27
-		add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
28
-		add_action( 'wl_linked_data_save_post', array(
29
-			&$this,
30
-			'save_form_data',
31
-		) );
32
-
33
-		// Enqueue js and css.
34
-		$this->enqueue_scripts_and_styles();
35
-
36
-	}
37
-
38
-	/**
39
-	 * Add a callback to print the metabox in page.
40
-	 * Wordpress will fire the $this->html() callback at the right time.
41
-	 */
42
-	public function add_main_metabox() {
43
-
44
-		// Add main metabox (will print also the inner fields).
45
-		$id    = uniqid( 'wl-metabox-' );
46
-		$title = get_the_title() . ' ' . __( 'properties', 'wordlift' );
47
-		add_meta_box( $id, $title, array(
48
-			$this,
49
-			'html',
50
-		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
51
-
52
-		// Add filter to change the metabox CSS class.
53
-		add_filter( "postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class' );
54
-	}
55
-
56
-	/**
57
-	 * Called from WP to print the metabox content in page.
58
-	 *
59
-	 * @since 3.1.0
60
-	 *
61
-	 * @param WP_Post $post The post.
62
-	 */
63
-	public function html( $post ) {
64
-
65
-		// Build the fields we need to print.
66
-		$this->instantiate_fields( $post->ID );
67
-
68
-		// Loop over the fields.
69
-		foreach ( $this->fields as $field ) {
70
-
71
-			// load data from DB (values will be available in $field->data).
72
-			$field->get_data();
73
-
74
-			// print field HTML (nonce included).
75
-			echo $field->html();
76
-		}
77
-
78
-	}
79
-
80
-	/**
81
-	 * Read the WL <-> Schema mapping and build the Fields for the entity being edited.
82
-	 *
83
-	 * Note: the first function that calls this method will instantiate the fields.
84
-	 * Why it isn't called from the constructor? Because we need to hook this process as late as possible.
85
-	 *
86
-	 * @since 3.1.0
87
-	 *
88
-	 * @param int $post_id The post id.
89
-	 */
90
-	public function instantiate_fields( $post_id ) {
91
-
92
-		// This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering.
93
-		if ( isset( $this->fields ) ) {
94
-			return;
95
-		}
96
-
97
-		$entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
98
-
99
-		if ( isset( $entity_type ) ) {
100
-
101
-			/**
102
-			 * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
103
-			 * We must divide fields in two groups:
104
-			 * - simple: accept values for one property
105
-			 * - grouped: accept values for more properties, or for one property that needs a specific metabox.
106
-			 */
107
-			$metaboxes         = $this->group_properties_by_input_field( $entity_type );
108
-			$simple_metaboxes  = $metaboxes[0];
109
-			$grouped_metaboxes = $metaboxes[1];
17
+    public $fields;
18
+
19
+    /**
20
+     * WL_Metabox constructor.
21
+     *
22
+     * @since 3.1.0
23
+     */
24
+    public function __construct() {
25
+
26
+        // Add hooks to print metaboxes and save submitted data.
27
+        add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
28
+        add_action( 'wl_linked_data_save_post', array(
29
+            &$this,
30
+            'save_form_data',
31
+        ) );
32
+
33
+        // Enqueue js and css.
34
+        $this->enqueue_scripts_and_styles();
35
+
36
+    }
37
+
38
+    /**
39
+     * Add a callback to print the metabox in page.
40
+     * Wordpress will fire the $this->html() callback at the right time.
41
+     */
42
+    public function add_main_metabox() {
43
+
44
+        // Add main metabox (will print also the inner fields).
45
+        $id    = uniqid( 'wl-metabox-' );
46
+        $title = get_the_title() . ' ' . __( 'properties', 'wordlift' );
47
+        add_meta_box( $id, $title, array(
48
+            $this,
49
+            'html',
50
+        ), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
51
+
52
+        // Add filter to change the metabox CSS class.
53
+        add_filter( "postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class' );
54
+    }
55
+
56
+    /**
57
+     * Called from WP to print the metabox content in page.
58
+     *
59
+     * @since 3.1.0
60
+     *
61
+     * @param WP_Post $post The post.
62
+     */
63
+    public function html( $post ) {
64
+
65
+        // Build the fields we need to print.
66
+        $this->instantiate_fields( $post->ID );
67
+
68
+        // Loop over the fields.
69
+        foreach ( $this->fields as $field ) {
70
+
71
+            // load data from DB (values will be available in $field->data).
72
+            $field->get_data();
73
+
74
+            // print field HTML (nonce included).
75
+            echo $field->html();
76
+        }
77
+
78
+    }
79
+
80
+    /**
81
+     * Read the WL <-> Schema mapping and build the Fields for the entity being edited.
82
+     *
83
+     * Note: the first function that calls this method will instantiate the fields.
84
+     * Why it isn't called from the constructor? Because we need to hook this process as late as possible.
85
+     *
86
+     * @since 3.1.0
87
+     *
88
+     * @param int $post_id The post id.
89
+     */
90
+    public function instantiate_fields( $post_id ) {
91
+
92
+        // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering.
93
+        if ( isset( $this->fields ) ) {
94
+            return;
95
+        }
96
+
97
+        $entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
98
+
99
+        if ( isset( $entity_type ) ) {
100
+
101
+            /**
102
+             * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
103
+             * We must divide fields in two groups:
104
+             * - simple: accept values for one property
105
+             * - grouped: accept values for more properties, or for one property that needs a specific metabox.
106
+             */
107
+            $metaboxes         = $this->group_properties_by_input_field( $entity_type );
108
+            $simple_metaboxes  = $metaboxes[0];
109
+            $grouped_metaboxes = $metaboxes[1];
110 110
 
111
-			// Loop over simple entity properties.
112
-			foreach ( $simple_metaboxes as $key => $property ) {
111
+            // Loop over simple entity properties.
112
+            foreach ( $simple_metaboxes as $key => $property ) {
113 113
 
114
-				// Info passed to the metabox.
115
-				$info         = array();
116
-				$info[ $key ] = $property;
114
+                // Info passed to the metabox.
115
+                $info         = array();
116
+                $info[ $key ] = $property;
117 117
 
118
-				// Build the requested field as WL_Metabox_Field_ object.
119
-				$this->add_field( $info );
120
-			}
118
+                // Build the requested field as WL_Metabox_Field_ object.
119
+                $this->add_field( $info );
120
+            }
121 121
 
122
-			// Loop over grouped properties.
123
-			foreach ( $grouped_metaboxes as $key => $property ) {
122
+            // Loop over grouped properties.
123
+            foreach ( $grouped_metaboxes as $key => $property ) {
124 124
 
125
-				// Info passed to the metabox.
126
-				$info         = array();
127
-				$info[ $key ] = $property;
125
+                // Info passed to the metabox.
126
+                $info         = array();
127
+                $info[ $key ] = $property;
128 128
 
129
-				// Build the requested field group as WL_Metabox_Field_ object.
130
-				$this->add_field( $info, true );
131
-			}
129
+                // Build the requested field group as WL_Metabox_Field_ object.
130
+                $this->add_field( $info, true );
131
+            }
132 132
 
133
-		}
134
-	}
133
+        }
134
+    }
135 135
 
136
-	/**
137
-	 * Separes metaboxes in simple and grouped.
138
-	 *
139
-	 * @param array $custom_fields Information on the entity type.
140
-	 */
141
-	public function group_properties_by_input_field( $custom_fields ) {
136
+    /**
137
+     * Separes metaboxes in simple and grouped.
138
+     *
139
+     * @param array $custom_fields Information on the entity type.
140
+     */
141
+    public function group_properties_by_input_field( $custom_fields ) {
142 142
 
143
-		$simple_properties  = array();
144
-		$grouped_properties = array();
143
+        $simple_properties  = array();
144
+        $grouped_properties = array();
145 145
 
146
-		// Loop over possible entity properties.
147
-		foreach ( $custom_fields as $key => $property ) {
146
+        // Loop over possible entity properties.
147
+        foreach ( $custom_fields as $key => $property ) {
148 148
 
149
-			// Check presence of predicate and type.
150
-			if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
149
+            // Check presence of predicate and type.
150
+            if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
151 151
 
152
-				// Check if input_field is defined.
153
-				if ( isset( $property['input_field'] ) && $property['input_field'] !== '' ) {
152
+                // Check if input_field is defined.
153
+                if ( isset( $property['input_field'] ) && $property['input_field'] !== '' ) {
154 154
 
155
-					$grouped_key = $property['input_field'];
155
+                    $grouped_key = $property['input_field'];
156 156
 
157
-					// Update list of grouped properties.
158
-					$grouped_properties[ $grouped_key ][ $key ] = $property;
157
+                    // Update list of grouped properties.
158
+                    $grouped_properties[ $grouped_key ][ $key ] = $property;
159 159
 
160
-				} else {
160
+                } else {
161 161
 
162
-					// input_field not defined, add simple metabox.
163
-					$simple_properties[ $key ] = $property;
164
-				}
165
-			}
166
-		}
162
+                    // input_field not defined, add simple metabox.
163
+                    $simple_properties[ $key ] = $property;
164
+                }
165
+            }
166
+        }
167 167
 
168
-		return array( $simple_properties, $grouped_properties );
169
-	}
168
+        return array( $simple_properties, $grouped_properties );
169
+    }
170 170
 
171
-	/**
172
-	 * Add a Field to the current Metabox, based on the description of the Field.
173
-	 * This method is a rude factory for Field objects.
174
-	 *
175
-	 * @param array $args
176
-	 * @param bool  $grouped Flag to distinguish between simple and grouped Fields
177
-	 */
178
-	public function add_field( $args, $grouped = false ) {
171
+    /**
172
+     * Add a Field to the current Metabox, based on the description of the Field.
173
+     * This method is a rude factory for Field objects.
174
+     *
175
+     * @param array $args
176
+     * @param bool  $grouped Flag to distinguish between simple and grouped Fields
177
+     */
178
+    public function add_field( $args, $grouped = false ) {
179 179
 
180
-		if ( $grouped ) {
181
-			// Special fields (sameas, coordinates, etc.).
180
+        if ( $grouped ) {
181
+            // Special fields (sameas, coordinates, etc.).
182 182
 
183
-			// Build Field with a custom class (e.g. WL_Metabox_Field_date).
184
-			$field_class = 'WL_Metabox_Field_' . key( $args );
183
+            // Build Field with a custom class (e.g. WL_Metabox_Field_date).
184
+            $field_class = 'WL_Metabox_Field_' . key( $args );
185 185
 
186
-		} else {
187
-			// Simple fields (string, uri, boolean, etc.).
186
+        } else {
187
+            // Simple fields (string, uri, boolean, etc.).
188 188
 
189
-			// Which field? We want to use the class that is specific for the field.
190
-			$meta      = key( $args );
191
-			$this_meta = $args[ $meta ];
189
+            // Which field? We want to use the class that is specific for the field.
190
+            $meta      = key( $args );
191
+            $this_meta = $args[ $meta ];
192 192
 
193
-			// If the field declares what metabox it wants, use that one.
194
-			if ( isset( $this_meta['metabox']['class'] ) ) {
193
+            // If the field declares what metabox it wants, use that one.
194
+            if ( isset( $this_meta['metabox']['class'] ) ) {
195 195
 
196
-				$field_class = $this_meta['metabox']['class'];
196
+                $field_class = $this_meta['metabox']['class'];
197 197
 
198
-			} elseif ( ! isset( $this_meta['type'] ) || ( $this_meta['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING ) ) {
198
+            } elseif ( ! isset( $this_meta['type'] ) || ( $this_meta['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING ) ) {
199 199
 
200
-				// TODO: all fields should explicitly declare the required WL_Metabox.
201
-				// When they will remove this.
200
+                // TODO: all fields should explicitly declare the required WL_Metabox.
201
+                // When they will remove this.
202 202
 
203
-				// Use default WL_Metabox_Field (manages strings).
204
-				$field_class = 'WL_Metabox_Field';
203
+                // Use default WL_Metabox_Field (manages strings).
204
+                $field_class = 'WL_Metabox_Field';
205 205
 
206
-			} else {
206
+            } else {
207 207
 
208
-				// TODO: all fields should explicitly declare the required WL_Metabox.
209
-				// When they will remove this.
208
+                // TODO: all fields should explicitly declare the required WL_Metabox.
209
+                // When they will remove this.
210 210
 
211
-				// Build Field with a custom class (e.g. WL_Metabox_Field_date).
212
-				$field_class = 'WL_Metabox_Field_' . $this_meta['type'];
211
+                // Build Field with a custom class (e.g. WL_Metabox_Field_date).
212
+                $field_class = 'WL_Metabox_Field_' . $this_meta['type'];
213 213
 
214
-			}
215
-		}
214
+            }
215
+        }
216 216
 
217
-		// Call apropriate constructor (e.g. WL_Metabox_Field_... ).
218
-		$this->fields[] = new $field_class( $args );
219
-	}
217
+        // Call apropriate constructor (e.g. WL_Metabox_Field_... ).
218
+        $this->fields[] = new $field_class( $args );
219
+    }
220 220
 
221
-	public function save_form_data( $entity_id ) {
221
+    public function save_form_data( $entity_id ) {
222 222
 
223
-		// Build Field objects.
224
-		$this->instantiate_fields( $entity_id );
223
+        // Build Field objects.
224
+        $this->instantiate_fields( $entity_id );
225 225
 
226
-		// Check if WL metabox form was posted.
227
-		if ( ! isset( $_POST['wl_metaboxes'] ) ) {
228
-			return;
229
-		}
226
+        // Check if WL metabox form was posted.
227
+        if ( ! isset( $_POST['wl_metaboxes'] ) ) {
228
+            return;
229
+        }
230 230
 
231
-		foreach ( $this->fields as $field ) {
231
+        foreach ( $this->fields as $field ) {
232 232
 
233
-			// Verify nonce.
234
-			$valid_nonce = $field->verify_nonce();
235
-			if ( $valid_nonce ) {
233
+            // Verify nonce.
234
+            $valid_nonce = $field->verify_nonce();
235
+            if ( $valid_nonce ) {
236 236
 
237
-				$posted_data = $_POST['wl_metaboxes'];
238
-				$field_name  = $field->meta_name;
237
+                $posted_data = $_POST['wl_metaboxes'];
238
+                $field_name  = $field->meta_name;
239 239
 
240
-				// Each Filed only deals with its values.
241
-				if ( isset( $posted_data[ $field_name ] ) ) {
240
+                // Each Filed only deals with its values.
241
+                if ( isset( $posted_data[ $field_name ] ) ) {
242 242
 
243
-					$values = $posted_data[ $field_name ];
244
-					if ( ! is_array( $values ) ) {
245
-						$values = array( $values );
246
-					}
243
+                    $values = $posted_data[ $field_name ];
244
+                    if ( ! is_array( $values ) ) {
245
+                        $values = array( $values );
246
+                    }
247 247
 
248
-					// Save data permanently
249
-					$field->save_data( $values );
250
-				}
251
-			}
252
-		}
248
+                    // Save data permanently
249
+                    $field->save_data( $values );
250
+                }
251
+            }
252
+        }
253 253
 
254
-		wl_linked_data_push_to_redlink( $entity_id );
255
-	}
254
+        wl_linked_data_push_to_redlink( $entity_id );
255
+    }
256 256
 
257
-	/**
258
-	 * Enqueue scripts and styles.
259
-	 *
260
-	 * @since 3.0.0
261
-	 */
262
-	public function enqueue_scripts_and_styles() {
257
+    /**
258
+     * Enqueue scripts and styles.
259
+     *
260
+     * @since 3.0.0
261
+     */
262
+    public function enqueue_scripts_and_styles() {
263 263
 
264
-		// Load the jquery-ui-timepicker-addon library.
265
-		wp_enqueue_style( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css' );
266
-		wp_enqueue_script( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js', array( 'jquery-ui-datepicker' ), '1.6.3', true );
264
+        // Load the jquery-ui-timepicker-addon library.
265
+        wp_enqueue_style( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css' );
266
+        wp_enqueue_script( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js', array( 'jquery-ui-datepicker' ), '1.6.3', true );
267 267
 
268
-		wp_enqueue_script( 'jquery-ui-timepicker-no-conflict', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.no-conflict.js', array(
269
-			'jquery-ui-datepicker',
270
-			'jquery-ui-timepicker-addon',
271
-		) );
268
+        wp_enqueue_script( 'jquery-ui-timepicker-no-conflict', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.no-conflict.js', array(
269
+            'jquery-ui-datepicker',
270
+            'jquery-ui-timepicker-addon',
271
+        ) );
272 272
 
273
-		// Leaflet.
274
-		wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
275
-		wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
273
+        // Leaflet.
274
+        wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
275
+        wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
276 276
 
277
-		// Add AJAX autocomplete to facilitate metabox editing.
278
-		wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
279
-		wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
280
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
281
-				'action'   => 'entity_by_title',
282
-			)
283
-		);
277
+        // Add AJAX autocomplete to facilitate metabox editing.
278
+        wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
279
+        wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
280
+                'ajax_url' => admin_url( 'admin-ajax.php' ),
281
+                'action'   => 'entity_by_title',
282
+            )
283
+        );
284 284
 
285
-	}
285
+    }
286 286
 
287 287
 }
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once( 'WL_Metabox_Field.php' );
4
-require_once( 'WL_Metabox_Field_date.php' );
5
-require_once( 'WL_Metabox_Field_uri.php' );
6
-require_once( 'WL_Metabox_Field_coordinates.php' );
7
-require_once( 'WL_Metabox_Field_sameas.php' );
8
-require_once( 'WL_Metabox_Field_address.php' );
3
+require_once('WL_Metabox_Field.php');
4
+require_once('WL_Metabox_Field_date.php');
5
+require_once('WL_Metabox_Field_uri.php');
6
+require_once('WL_Metabox_Field_coordinates.php');
7
+require_once('WL_Metabox_Field_sameas.php');
8
+require_once('WL_Metabox_Field_address.php');
9 9
 
10 10
 /**
11 11
  * Class WL_Metabox
@@ -24,11 +24,11 @@  discard block
 block discarded – undo
24 24
 	public function __construct() {
25 25
 
26 26
 		// Add hooks to print metaboxes and save submitted data.
27
-		add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
28
-		add_action( 'wl_linked_data_save_post', array(
27
+		add_action('add_meta_boxes', array(&$this, 'add_main_metabox'));
28
+		add_action('wl_linked_data_save_post', array(
29 29
 			&$this,
30 30
 			'save_form_data',
31
-		) );
31
+		));
32 32
 
33 33
 		// Enqueue js and css.
34 34
 		$this->enqueue_scripts_and_styles();
@@ -42,15 +42,15 @@  discard block
 block discarded – undo
42 42
 	public function add_main_metabox() {
43 43
 
44 44
 		// Add main metabox (will print also the inner fields).
45
-		$id    = uniqid( 'wl-metabox-' );
46
-		$title = get_the_title() . ' ' . __( 'properties', 'wordlift' );
47
-		add_meta_box( $id, $title, array(
45
+		$id    = uniqid('wl-metabox-');
46
+		$title = get_the_title().' '.__('properties', 'wordlift');
47
+		add_meta_box($id, $title, array(
48 48
 			$this,
49 49
 			'html',
50
-		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
50
+		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high');
51 51
 
52 52
 		// Add filter to change the metabox CSS class.
53
-		add_filter( "postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class' );
53
+		add_filter("postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class');
54 54
 	}
55 55
 
56 56
 	/**
@@ -60,13 +60,13 @@  discard block
 block discarded – undo
60 60
 	 *
61 61
 	 * @param WP_Post $post The post.
62 62
 	 */
63
-	public function html( $post ) {
63
+	public function html($post) {
64 64
 
65 65
 		// Build the fields we need to print.
66
-		$this->instantiate_fields( $post->ID );
66
+		$this->instantiate_fields($post->ID);
67 67
 
68 68
 		// Loop over the fields.
69
-		foreach ( $this->fields as $field ) {
69
+		foreach ($this->fields as $field) {
70 70
 
71 71
 			// load data from DB (values will be available in $field->data).
72 72
 			$field->get_data();
@@ -87,16 +87,16 @@  discard block
 block discarded – undo
87 87
 	 *
88 88
 	 * @param int $post_id The post id.
89 89
 	 */
90
-	public function instantiate_fields( $post_id ) {
90
+	public function instantiate_fields($post_id) {
91 91
 
92 92
 		// This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering.
93
-		if ( isset( $this->fields ) ) {
93
+		if (isset($this->fields)) {
94 94
 			return;
95 95
 		}
96 96
 
97
-		$entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
97
+		$entity_type = wl_entity_taxonomy_get_custom_fields($post_id);
98 98
 
99
-		if ( isset( $entity_type ) ) {
99
+		if (isset($entity_type)) {
100 100
 
101 101
 			/**
102 102
 			 * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
@@ -104,30 +104,30 @@  discard block
 block discarded – undo
104 104
 			 * - simple: accept values for one property
105 105
 			 * - grouped: accept values for more properties, or for one property that needs a specific metabox.
106 106
 			 */
107
-			$metaboxes         = $this->group_properties_by_input_field( $entity_type );
107
+			$metaboxes         = $this->group_properties_by_input_field($entity_type);
108 108
 			$simple_metaboxes  = $metaboxes[0];
109 109
 			$grouped_metaboxes = $metaboxes[1];
110 110
 
111 111
 			// Loop over simple entity properties.
112
-			foreach ( $simple_metaboxes as $key => $property ) {
112
+			foreach ($simple_metaboxes as $key => $property) {
113 113
 
114 114
 				// Info passed to the metabox.
115 115
 				$info         = array();
116
-				$info[ $key ] = $property;
116
+				$info[$key] = $property;
117 117
 
118 118
 				// Build the requested field as WL_Metabox_Field_ object.
119
-				$this->add_field( $info );
119
+				$this->add_field($info);
120 120
 			}
121 121
 
122 122
 			// Loop over grouped properties.
123
-			foreach ( $grouped_metaboxes as $key => $property ) {
123
+			foreach ($grouped_metaboxes as $key => $property) {
124 124
 
125 125
 				// Info passed to the metabox.
126 126
 				$info         = array();
127
-				$info[ $key ] = $property;
127
+				$info[$key] = $property;
128 128
 
129 129
 				// Build the requested field group as WL_Metabox_Field_ object.
130
-				$this->add_field( $info, true );
130
+				$this->add_field($info, true);
131 131
 			}
132 132
 
133 133
 		}
@@ -138,34 +138,34 @@  discard block
 block discarded – undo
138 138
 	 *
139 139
 	 * @param array $custom_fields Information on the entity type.
140 140
 	 */
141
-	public function group_properties_by_input_field( $custom_fields ) {
141
+	public function group_properties_by_input_field($custom_fields) {
142 142
 
143 143
 		$simple_properties  = array();
144 144
 		$grouped_properties = array();
145 145
 
146 146
 		// Loop over possible entity properties.
147
-		foreach ( $custom_fields as $key => $property ) {
147
+		foreach ($custom_fields as $key => $property) {
148 148
 
149 149
 			// Check presence of predicate and type.
150
-			if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
150
+			if (isset($property['predicate']) && isset($property['type'])) {
151 151
 
152 152
 				// Check if input_field is defined.
153
-				if ( isset( $property['input_field'] ) && $property['input_field'] !== '' ) {
153
+				if (isset($property['input_field']) && $property['input_field'] !== '') {
154 154
 
155 155
 					$grouped_key = $property['input_field'];
156 156
 
157 157
 					// Update list of grouped properties.
158
-					$grouped_properties[ $grouped_key ][ $key ] = $property;
158
+					$grouped_properties[$grouped_key][$key] = $property;
159 159
 
160 160
 				} else {
161 161
 
162 162
 					// input_field not defined, add simple metabox.
163
-					$simple_properties[ $key ] = $property;
163
+					$simple_properties[$key] = $property;
164 164
 				}
165 165
 			}
166 166
 		}
167 167
 
168
-		return array( $simple_properties, $grouped_properties );
168
+		return array($simple_properties, $grouped_properties);
169 169
 	}
170 170
 
171 171
 	/**
@@ -175,27 +175,27 @@  discard block
 block discarded – undo
175 175
 	 * @param array $args
176 176
 	 * @param bool  $grouped Flag to distinguish between simple and grouped Fields
177 177
 	 */
178
-	public function add_field( $args, $grouped = false ) {
178
+	public function add_field($args, $grouped = false) {
179 179
 
180
-		if ( $grouped ) {
180
+		if ($grouped) {
181 181
 			// Special fields (sameas, coordinates, etc.).
182 182
 
183 183
 			// Build Field with a custom class (e.g. WL_Metabox_Field_date).
184
-			$field_class = 'WL_Metabox_Field_' . key( $args );
184
+			$field_class = 'WL_Metabox_Field_'.key($args);
185 185
 
186 186
 		} else {
187 187
 			// Simple fields (string, uri, boolean, etc.).
188 188
 
189 189
 			// Which field? We want to use the class that is specific for the field.
190
-			$meta      = key( $args );
191
-			$this_meta = $args[ $meta ];
190
+			$meta      = key($args);
191
+			$this_meta = $args[$meta];
192 192
 
193 193
 			// If the field declares what metabox it wants, use that one.
194
-			if ( isset( $this_meta['metabox']['class'] ) ) {
194
+			if (isset($this_meta['metabox']['class'])) {
195 195
 
196 196
 				$field_class = $this_meta['metabox']['class'];
197 197
 
198
-			} elseif ( ! isset( $this_meta['type'] ) || ( $this_meta['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING ) ) {
198
+			} elseif ( ! isset($this_meta['type']) || ($this_meta['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING)) {
199 199
 
200 200
 				// TODO: all fields should explicitly declare the required WL_Metabox.
201 201
 				// When they will remove this.
@@ -209,49 +209,49 @@  discard block
 block discarded – undo
209 209
 				// When they will remove this.
210 210
 
211 211
 				// Build Field with a custom class (e.g. WL_Metabox_Field_date).
212
-				$field_class = 'WL_Metabox_Field_' . $this_meta['type'];
212
+				$field_class = 'WL_Metabox_Field_'.$this_meta['type'];
213 213
 
214 214
 			}
215 215
 		}
216 216
 
217 217
 		// Call apropriate constructor (e.g. WL_Metabox_Field_... ).
218
-		$this->fields[] = new $field_class( $args );
218
+		$this->fields[] = new $field_class($args);
219 219
 	}
220 220
 
221
-	public function save_form_data( $entity_id ) {
221
+	public function save_form_data($entity_id) {
222 222
 
223 223
 		// Build Field objects.
224
-		$this->instantiate_fields( $entity_id );
224
+		$this->instantiate_fields($entity_id);
225 225
 
226 226
 		// Check if WL metabox form was posted.
227
-		if ( ! isset( $_POST['wl_metaboxes'] ) ) {
227
+		if ( ! isset($_POST['wl_metaboxes'])) {
228 228
 			return;
229 229
 		}
230 230
 
231
-		foreach ( $this->fields as $field ) {
231
+		foreach ($this->fields as $field) {
232 232
 
233 233
 			// Verify nonce.
234 234
 			$valid_nonce = $field->verify_nonce();
235
-			if ( $valid_nonce ) {
235
+			if ($valid_nonce) {
236 236
 
237 237
 				$posted_data = $_POST['wl_metaboxes'];
238 238
 				$field_name  = $field->meta_name;
239 239
 
240 240
 				// Each Filed only deals with its values.
241
-				if ( isset( $posted_data[ $field_name ] ) ) {
241
+				if (isset($posted_data[$field_name])) {
242 242
 
243
-					$values = $posted_data[ $field_name ];
244
-					if ( ! is_array( $values ) ) {
245
-						$values = array( $values );
243
+					$values = $posted_data[$field_name];
244
+					if ( ! is_array($values)) {
245
+						$values = array($values);
246 246
 					}
247 247
 
248 248
 					// Save data permanently
249
-					$field->save_data( $values );
249
+					$field->save_data($values);
250 250
 				}
251 251
 			}
252 252
 		}
253 253
 
254
-		wl_linked_data_push_to_redlink( $entity_id );
254
+		wl_linked_data_push_to_redlink($entity_id);
255 255
 	}
256 256
 
257 257
 	/**
@@ -262,22 +262,22 @@  discard block
 block discarded – undo
262 262
 	public function enqueue_scripts_and_styles() {
263 263
 
264 264
 		// Load the jquery-ui-timepicker-addon library.
265
-		wp_enqueue_style( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css' );
266
-		wp_enqueue_script( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js', array( 'jquery-ui-datepicker' ), '1.6.3', true );
265
+		wp_enqueue_style('jquery-ui-timepicker-addon', dirname(plugin_dir_url(__FILE__)).'/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css');
266
+		wp_enqueue_script('jquery-ui-timepicker-addon', dirname(plugin_dir_url(__FILE__)).'/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js', array('jquery-ui-datepicker'), '1.6.3', true);
267 267
 
268
-		wp_enqueue_script( 'jquery-ui-timepicker-no-conflict', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.no-conflict.js', array(
268
+		wp_enqueue_script('jquery-ui-timepicker-no-conflict', dirname(plugin_dir_url(__FILE__)).'/js/jquery.datetimepicker.no-conflict.js', array(
269 269
 			'jquery-ui-datepicker',
270 270
 			'jquery-ui-timepicker-addon',
271
-		) );
271
+		));
272 272
 
273 273
 		// Leaflet.
274
-		wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
275
-		wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
274
+		wp_enqueue_style('leaflet', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.css');
275
+		wp_enqueue_script('leaflet', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.js', __FILE__);
276 276
 
277 277
 		// Add AJAX autocomplete to facilitate metabox editing.
278
-		wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
279
-		wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
280
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
278
+		wp_enqueue_script('wl-entity-metabox-utility', dirname(plugin_dir_url(__FILE__)).'/js/wl_entity_metabox_utilities.js');
279
+		wp_localize_script('wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
280
+				'ajax_url' => admin_url('admin-ajax.php'),
281 281
 				'action'   => 'entity_by_title',
282 282
 			)
283 283
 		);
Please login to merge, or discard this patch.