PluginProbe
Property Hive / 1.4.6
Property Hive v1.4.6
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / admin / ph-meta-box-functions.php

ph-meta-box-functions.php in Property Hive 1.4.6, at includes/admin/ph-meta-box-functions.php

421 lines 17.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Meta Box Functions
4 *
5 * @author PropertyHive
6 * @category Core
7 * @package PropertyHive/Admin/Functions
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
13 /**
14 * Output a text input box.
15 *
16 * @access public
17 * @param array $field
18 * @return void
19 */
20 function propertyhive_wp_text_input( $field ) {
21 global $thepostid, $post, $propertyhive;
22
23 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
24 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
25 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
26 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
27 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
28 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
29 $field['type'] = isset( $field['type'] ) ? $field['type'] : 'text';
30 $data_type = empty( $field['data_type'] ) ? '' : $field['data_type'];
31
32 switch ( $data_type ) {
33 case 'price' :
34 $field['class'] .= ' ph_input_price';
35 $field['value'] = ph_format_localized_price( $field['value'] );
36 break;
37 case 'decimal' :
38 $field['class'] .= ' ph_input_decimal';
39 $field['value'] = ph_format_localized_decimal( $field['value'] );
40 break;
41 }
42
43 // Custom attribute handling
44 $custom_attributes = array();
45
46 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) )
47 foreach ( $field['custom_attributes'] as $attribute => $value )
48 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
49
50 echo '
51 <p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '">
52 <label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>
53 <input type="' . esc_attr( $field['type'] ) . '" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . implode( ' ', $custom_attributes ) . ' /> ';
54
55 if ( ! empty( $field['description'] ) ) {
56
57 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
58 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( PH()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
59 } else {
60 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
61 }
62
63 }
64 echo '</p>';
65 }
66
67 /**
68 * Output a file input box.
69 *
70 * @access public
71 * @param array $field
72 * @return void
73 */
74 function propertyhive_wp_photo_upload( $field ) {
75 global $thepostid, $post, $propertyhive;
76
77 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
78 $field['id'] = isset( $field['id'] ) ? $field['id'] : '';
79 $field['button_label'] = isset( $field['button_label'] ) ? $field['button_label'] : __('Select Photo', 'propertyhive');
80 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
81 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
82 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
83 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
84 $data_type = empty( $field['data_type'] ) ? '' : $field['data_type'];
85
86 // Custom attribute handling
87 $custom_attributes = array();
88
89 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) )
90 foreach ( $field['custom_attributes'] as $attribute => $value )
91 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
92
93 propertyhive_wp_hidden_input( $field );
94
95 echo '
96 <p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"';
97 if ( $field['value'] == '' )
98 {
99 echo ' style="display:none;"';
100 }
101 echo '>
102 <label for="' . esc_attr( $field['id'] ) . '">' . __( 'Uploaded', 'propertyhive' ) . ' ' . wp_kses_post( $field['label'] ) . '</label>
103 <span>';
104 if ( $field['value'] != '' )
105 {
106 $image = wp_get_attachment_image_src( $field['value'], 'thumbnail' );
107 if ($image !== FALSE)
108 {
109 echo '<img src="' . $image[0] . '" width="150" alt="">';
110 }
111 else
112 {
113 echo 'Image doesn\'t exist';
114 }
115 }
116 echo '</span>
117 </p>';
118
119 echo '
120 <p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '">
121 <label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>
122 <a href="" class="button button-primary ph_upload_photo_button' . $field['id'] . '">' . $field['button_label'] . '</a>';
123
124 if ( ! empty( $field['description'] ) ) {
125
126 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
127 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( PH()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
128 } else {
129 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
130 }
131
132 }
133 echo '</p>';
134
135 echo '<script>
136
137 var file_frame' . $field['id'] . ';
138
139 jQuery(document).ready(function()
140 {
141 jQuery(\'.ph_upload_photo_button' . $field['id'] . '\').live(\'click\', function( event ){
142
143 event.preventDefault();
144
145 // If the media frame already exists, reopen it.
146 if ( file_frame' . $field['id'] . ' ) {
147 file_frame' . $field['id'] . '.open();
148 return;
149 }
150
151 // Create the media frame.
152 file_frame' . $field['id'] . ' = wp.media.frames.file_frame' . $field['id'] . ' = wp.media({
153 title: jQuery( this ).data( \'uploader_title\' ),
154 button: {
155 text: jQuery( this ).data( \'uploader_button_text\' ),
156 },
157 multiple: false // Set to true to allow multiple files to be selected
158 });
159
160 // When an image is selected, run a callback.
161 file_frame' . $field['id'] . '.on( \'select\', function() {
162 var selection = file_frame' . $field['id'] . '.state().get(\'selection\');
163
164 selection.map( function( attachment ) {
165
166 attachment = attachment.toJSON();
167
168 // Do something with attachment.id and/or attachment.url here
169 console.log(attachment.url);
170
171 // Add selected image to page
172 //add_photo_attachment_to_grid(attachment);
173
174 jQuery(\'.form-field.' . esc_attr( $field['id'] ) . '_field\').show();
175 jQuery(\'.form-field.' . esc_attr( $field['id'] ) . '_field span\').html(\'<img src="\' + attachment.url + \'" width="150" alt="">\');
176 jQuery(\'#' . esc_attr( $field['id'] ) . '\').val(attachment.id);
177 });
178 });
179
180 // Finally, open the modal
181 file_frame' . $field['id'] . '.open();
182 });
183 });
184
185 </script>';
186 }
187
188 /**
189 * Output a hidden input box.
190 *
191 * @access public
192 * @param array $field
193 * @return void
194 */
195 function propertyhive_wp_hidden_input( $field ) {
196 global $thepostid, $post;
197
198 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
199 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
200
201 echo '<input type="hidden" name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" /> ';
202 }
203
204 /**
205 * Output a textarea input box.
206 *
207 * @access public
208 * @param array $field
209 * @return void
210 */
211 function propertyhive_wp_textarea_input( $field ) {
212 global $thepostid, $post, $propertyhive;
213
214 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
215 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
216 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
217 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
218 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
219 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
220
221 // Custom attribute handling
222 $custom_attributes = array();
223
224 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) )
225 foreach ( $field['custom_attributes'] as $attribute => $value )
226 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
227
228 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><textarea class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" rows="2" cols="20" ' . implode( ' ', $custom_attributes ) . '>' . esc_textarea( $field['value'] ) . '</textarea> ';
229
230 if ( ! empty( $field['description'] ) ) {
231
232 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
233 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( PH()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
234 } else {
235 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
236 }
237
238 }
239 echo '</p>';
240 }
241
242 /**
243 * Output a checkbox input box.
244 *
245 * @access public
246 * @param array $field
247 * @return void
248 */
249 function propertyhive_wp_checkbox( $field ) {
250 global $thepostid, $post;
251
252 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
253 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'checkbox';
254 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
255 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
256 $field['cbvalue'] = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'yes';
257 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
258
259 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><input type="checkbox" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['cbvalue'] ) . '" ' . checked( $field['value'], $field['cbvalue'], false ) . ' /> ';
260
261 if ( ! empty( $field['description'] ) ) echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
262
263 echo '</p>';
264 }
265
266 /**
267 * Output a groupd of checkbox input boxes.
268 *
269 * @access public
270 * @param array $field
271 * @return void
272 */
273 function propertyhive_wp_checkboxes( $field ) {
274 global $thepostid, $post;
275
276 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
277 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'checkbox';
278 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
279 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
280 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['name'], true );
281
282 echo '<fieldset class="form-field ' . esc_attr( $field['wrapper_class'] ) . '"><legend>' . wp_kses_post( $field['label'] ) . '</legend><ul class="ph-radios">';
283
284 foreach ( $field['options'] as $key => $value ) {
285 echo '<li><label><input type="checkbox" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '[]" id="' . esc_attr( $field['name'] ) . '_' . $key . '" value="' . esc_attr( $key ) . '" ' . ( ( !empty($field['value']) && in_array( $key, $field['value'] ) ) ? 'checked' : '' ) . ' /> ' . $value . '</label></li>';
286 }
287
288 echo '</ul>';
289
290 if ( ! empty( $field['description'] ) ) echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
291
292 echo '</fieldset>';
293 }
294
295 /**
296 * Output a select input box.
297 *
298 * @access public
299 * @param array $field
300 * @return void
301 */
302 function propertyhive_wp_select( $field ) {
303 global $thepostid, $post, $propertyhive;
304
305 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
306 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
307 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
308 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
309
310 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><select id="' . esc_attr( $field['id'] ) . '" name="' . esc_attr( $field['id'] ) . '" class="' . esc_attr( $field['class'] ) . '">';
311
312 foreach ( $field['options'] as $key => $value ) {
313
314 echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
315
316 }
317
318 echo '</select> ';
319
320 if ( ! empty( $field['description'] ) ) {
321
322 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
323 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( PH()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
324 } else {
325 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
326 }
327
328 }
329 echo '</p>';
330 }
331
332 /**
333 * Output a select input box with optgroups.
334 *
335 * @access public
336 * @param array $field
337 * @return void
338 */
339 function propertyhive_wp_select_optgroups( $field ) {
340 global $thepostid, $post, $propertyhive;
341
342 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
343 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
344 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
345 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
346
347 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><select id="' . esc_attr( $field['id'] ) . '" name="' . esc_attr( $field['id'] ) . '" class="' . esc_attr( $field['class'] ) . '">';
348
349 echo '<option value="" ' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . '></option>';
350
351 foreach ( $field['options'] as $optgroup => $options ) {
352
353 echo '<optgroup label="' . esc_html( $optgroup ) . '">';
354
355 foreach ( $options as $key => $value ) {
356
357 echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
358
359 }
360
361 echo '</optgroup>';
362
363 }
364
365 echo '</select> ';
366
367 if ( ! empty( $field['description'] ) ) {
368
369 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
370 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( PH()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
371 } else {
372 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
373 }
374
375 }
376 echo '</p>';
377 }
378
379 /**
380 * Output a radio input box.
381 *
382 * @access public
383 * @param array $field
384 * @return void
385 */
386 function propertyhive_wp_radio( $field ) {
387 global $thepostid, $post, $propertyhive;
388
389 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
390 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
391 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
392 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
393 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
394
395 echo '<fieldset class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><legend>' . wp_kses_post( $field['label'] ) . '</legend><ul class="ph-radios">';
396
397 foreach ( $field['options'] as $key => $value ) {
398
399 echo '<li><label><input
400 name="' . esc_attr( $field['name'] ) . '"
401 value="' . esc_attr( $key ) . '"
402 type="radio"
403 class="' . esc_attr( $field['class'] ) . '"
404 ' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '
405 /> ' . esc_html( $value ) . '</label>
406 </li>';
407 }
408 echo '</ul>';
409
410 if ( ! empty( $field['description'] ) ) {
411
412 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
413 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( PH()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
414 } else {
415 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
416 }
417
418 }
419
420 echo '</fieldset>';
421 }