PluginProbe
Property Hive / 1.4.53
Property Hive v1.4.53
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.53, at includes/admin/ph-meta-box-functions.php

422 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 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
310
311 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['name'] ) . '" class="' . esc_attr( $field['class'] ) . '">';
312
313 foreach ( $field['options'] as $key => $value ) {
314
315 echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
316
317 }
318
319 echo '</select> ';
320
321 if ( ! empty( $field['description'] ) ) {
322
323 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
324 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" />';
325 } else {
326 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
327 }
328
329 }
330 echo '</p>';
331 }
332
333 /**
334 * Output a select input box with optgroups.
335 *
336 * @access public
337 * @param array $field
338 * @return void
339 */
340 function propertyhive_wp_select_optgroups( $field ) {
341 global $thepostid, $post, $propertyhive;
342
343 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
344 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
345 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
346 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
347
348 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'] ) . '">';
349
350 echo '<option value="" ' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . '></option>';
351
352 foreach ( $field['options'] as $optgroup => $options ) {
353
354 echo '<optgroup label="' . esc_html( $optgroup ) . '">';
355
356 foreach ( $options as $key => $value ) {
357
358 echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
359
360 }
361
362 echo '</optgroup>';
363
364 }
365
366 echo '</select> ';
367
368 if ( ! empty( $field['description'] ) ) {
369
370 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
371 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" />';
372 } else {
373 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
374 }
375
376 }
377 echo '</p>';
378 }
379
380 /**
381 * Output a radio input box.
382 *
383 * @access public
384 * @param array $field
385 * @return void
386 */
387 function propertyhive_wp_radio( $field ) {
388 global $thepostid, $post, $propertyhive;
389
390 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
391 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
392 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
393 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
394 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
395
396 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">';
397
398 foreach ( $field['options'] as $key => $value ) {
399
400 echo '<li><label><input
401 name="' . esc_attr( $field['name'] ) . '"
402 value="' . esc_attr( $key ) . '"
403 type="radio"
404 class="' . esc_attr( $field['class'] ) . '"
405 ' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '
406 /> ' . esc_html( $value ) . '</label>
407 </li>';
408 }
409 echo '</ul>';
410
411 if ( ! empty( $field['description'] ) ) {
412
413 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
414 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" />';
415 } else {
416 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
417 }
418
419 }
420
421 echo '</fieldset>';
422 }