PluginProbe
Property Hive / 1.4.62
Property Hive v1.4.62
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 / class-ph-admin-settings.php

class-ph-admin-settings.php in Property Hive 1.4.62, at includes/admin/class-ph-admin-settings.php

816 lines 29.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Admin Settings Class.
4 *
5 * @author PropertyHive
6 * @category Admin
7 * @package PropertyHive/Admin
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
13 if ( ! class_exists( 'PH_Admin_Settings' ) ) :
14
15 /**
16 * PH_Admin_Settings
17 */
18 class PH_Admin_Settings {
19
20 private static $settings = array();
21 private static $errors = array();
22 private static $messages = array();
23
24 /**
25 * Include the settings page classes
26 */
27 public static function get_settings_pages() {
28 if ( empty( self::$settings ) ) {
29 $settings = array();
30
31 include_once( 'settings/class-ph-settings-page.php' );
32
33 $settings[] = include( 'settings/class-ph-settings-general.php' );
34 $settings[] = include( 'settings/class-ph-settings-offices.php' );
35 $settings[] = include( 'settings/class-ph-settings-custom-fields.php' );
36 $settings[] = include( 'settings/class-ph-settings-emails.php' );
37 $settings[] = include( 'settings/class-ph-settings-licenses.php' );
38 $settings[] = include( 'settings/class-ph-settings-add-ons.php' );
39
40 self::$settings = apply_filters( 'propertyhive_get_settings_pages', $settings );
41 }
42 return self::$settings;
43 }
44
45 /**
46 * Save the settings
47 */
48 public static function save() {
49 global $current_section, $current_tab;
50
51 if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'propertyhive-settings' ) )
52 die( __( 'Action failed. Please refresh the page and retry.', 'propertyhive' ) );
53
54 // Trigger actions
55 do_action( 'propertyhive_settings_save_' . $current_tab );
56 do_action( 'propertyhive_update_options_' . $current_tab );
57 do_action( 'propertyhive_update_options' );
58
59 // Clear any unwanted data
60 //ph_delete_property_transients();
61 //delete_transient( 'propertyhive_cache_excluded_uris' );
62
63 self::add_message( __( 'Your settings have been saved.', 'propertyhive' ) );
64 //self::check_download_folder_protection();
65
66 // Re-add endpoints and flush rules
67 //PH()->query->init_query_vars();
68 //PH()->query->add_endpoints();
69 flush_rewrite_rules();
70
71 do_action( 'propertyhive_settings_saved' );
72 }
73
74 /**
75 * Add a message
76 * @param string $text
77 */
78 public static function add_message( $text ) {
79 self::$messages[] = $text;
80 }
81
82 /**
83 * Add an error
84 * @param string $text
85 */
86 public static function add_error( $text ) {
87 self::$errors[] = $text;
88 }
89
90 /**
91 * Output messages + errors
92 */
93 public static function show_messages() {
94 if ( sizeof( self::$errors ) > 0 ) {
95 foreach ( self::$errors as $error )
96 echo '<div id="message" class="error fade"><p><strong>' . $error . '</strong></p></div>';
97 } elseif ( sizeof( self::$messages ) > 0 ) {
98 foreach ( self::$messages as $message )
99 echo '<div id="message" class="updated fade"><p><strong>' . $message . '</strong></p></div>';
100 }
101 }
102
103 /**
104 * Settings page.
105 *
106 * Handles the display of the main propertyhive settings page in admin.
107 *
108 * @access public
109 * @return void
110 */
111 public static function output() {
112 global $current_section, $current_tab;
113
114 do_action( 'propertyhive_settings_start' );
115
116 //wp_enqueue_script( 'propertyhive_settings', PH()->plugin_url() . '/assets/js/admin/settings.min.js', array( 'jquery'/*, 'jquery-ui-datepicker', 'jquery-ui-sortable', 'iris', 'chosen'*/ ), PH()->version, true );
117
118 /*wp_localize_script( 'propertyhive_settings', 'propertyhive_settings_params', array(
119 'i18n_nav_warning' => __( 'The changes you made will be lost if you navigate away from this page.', 'propertyhive' )
120 ) );*/
121
122 // Include settings pages
123 self::get_settings_pages();
124
125 // Get current tab/section
126 $current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( $_GET['tab'] );
127 $current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( $_REQUEST['section'] );
128
129 // Save settings if data has been posted
130 if ( ! empty( $_POST ) )
131 self::save();
132
133 // Add any posted messages
134 if ( ! empty( $_GET['ph_error'] ) )
135 self::add_error( stripslashes( $_GET['ph_error'] ) );
136
137 if ( ! empty( $_GET['ph_message'] ) )
138 self::add_message( stripslashes( $_GET['ph_message'] ) );
139
140 self::show_messages();
141
142 // Get tabs for the settings page
143 $tabs = apply_filters( 'propertyhive_settings_tabs_array', array() );
144
145 include 'views/html-admin-settings.php';
146 }
147
148 /**
149 * Get a setting from the settings API.
150 *
151 * @param mixed $option
152 * @return string
153 */
154 public static function get_option( $option_name, $default = '' ) {
155 // Array value
156 if ( strstr( $option_name, '[' ) ) {
157
158 parse_str( $option_name, $option_array );
159
160 // Option name is first key
161 $option_name = current( array_keys( $option_array ) );
162
163 // Get value
164 $option_values = get_option( $option_name, '' );
165
166 $key = key( $option_array[ $option_name ] );
167
168 if ( isset( $option_values[ $key ] ) )
169 $option_value = $option_values[ $key ];
170 else
171 $option_value = null;
172
173 // Single value
174 } else {
175 $option_value = get_option( $option_name, null );
176 }
177
178 if ( is_array( $option_value ) )
179 $option_value = array_map( 'stripslashes', $option_value );
180 elseif ( ! is_null( $option_value ) )
181 $option_value = stripslashes( $option_value );
182
183 return $option_value === null ? $default : $option_value;
184 }
185
186 /**
187 * Output admin fields.
188 *
189 * Loops though the propertyhive options array and outputs each field.
190 *
191 * @access public
192 * @param array $options Opens array to output
193 */
194 public static function output_fields( $options ) {
195 foreach ( $options as $value ) {
196 if ( ! isset( $value['type'] ) ) continue;
197 if ( ! isset( $value['id'] ) ) $value['id'] = '';
198 if ( ! isset( $value['title'] ) ) $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
199 if ( ! isset( $value['class'] ) ) $value['class'] = '';
200 if ( ! isset( $value['css'] ) ) $value['css'] = '';
201 if ( ! isset( $value['default'] ) ) $value['default'] = '';
202 if ( ! isset( $value['desc'] ) ) $value['desc'] = '';
203 if ( ! isset( $value['desc_tip'] ) ) $value['desc_tip'] = false;
204
205 // Custom attribute handling
206 $custom_attributes = array();
207
208 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) )
209 foreach ( $value['custom_attributes'] as $attribute => $attribute_value )
210 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
211
212 // Description handling
213 if ( $value['desc_tip'] === true ) {
214 $description = '';
215 $tip = $value['desc'];
216 } elseif ( ! empty( $value['desc_tip'] ) ) {
217 $description = $value['desc'];
218 $tip = $value['desc_tip'];
219 } elseif ( ! empty( $value['desc'] ) ) {
220 $description = $value['desc'];
221 $tip = '';
222 } else {
223 $description = $tip = '';
224 }
225
226 if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ) ) ) {
227 $description = '<p style="margin-top:0">' . wp_kses_post( $description ) . '</p>';
228 } elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) {
229 $description = wp_kses_post( $description );
230 } elseif ( $description ) {
231 $description = '<span class="description">' . wp_kses_post( $description ) . '</span>';
232 }
233
234 if ( $tip && in_array( $value['type'], array( 'checkbox' ) ) ) {
235
236 $tip = '<p class="description">' . $tip . '</p>';
237
238 } elseif ( $tip ) {
239
240 $tip = '<img class="help_tip" data-tip="' . esc_attr( $tip ) . '" src="' . PH()->plugin_url() . '/assets/images/help.png" height="16" width="16" />';
241
242 }
243
244 // Switch based on type
245 switch( $value['type'] ) {
246
247 // Section Titles
248 case 'title':
249 if ( ! empty( $value['title'] ) ) {
250 echo '<h3>' . esc_html( $value['title'] ) . '</h3>';
251 }
252 if ( ! empty( $value['desc'] ) ) {
253 echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) );
254 }
255 echo '<table class="form-table">'. "\n\n";
256 if ( ! empty( $value['id'] ) ) {
257 do_action( 'propertyhive_settings_' . sanitize_title( $value['id'] ) );
258 }
259 break;
260
261 // Section Ends
262 case 'sectionend':
263 if ( ! empty( $value['id'] ) ) {
264 do_action( 'propertyhive_settings_' . sanitize_title( $value['id'] ) . '_end' );
265 }
266 echo '</table>';
267 if ( ! empty( $value['id'] ) ) {
268 do_action( 'propertyhive_settings_' . sanitize_title( $value['id'] ) . '_after' );
269 }
270 break;
271
272 case 'html':
273 ?>
274 <tr valign="top" id="row_<?php echo esc_attr( $value['id'] ); ?>">
275 <th scope="row" class="titledesc">
276 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
277 <?php echo $tip; ?>
278 </th>
279 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
280 <?php echo $value['html']; ?>
281 </td>
282 </tr>
283 <?php
284 break;
285
286 // Standard text inputs and subtypes like 'number'
287 case 'text':
288 case 'email':
289 case 'number':
290 case 'color' :
291 case 'password' :
292
293 $type = $value['type'];
294 $class = '';
295 $option_value = self::get_option( $value['id'], $value['default'] );
296
297 if ( $value['type'] == 'color' ) {
298 $type = 'text';
299 $value['class'] .= 'colorpick';
300 $description .= '<div id="colorPickerDiv_' . esc_attr( $value['id'] ) . '" class="colorpickdiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>';
301 }
302
303 ?><tr valign="top" id="row_<?php echo esc_attr( $value['id'] ); ?>">
304 <th scope="row" class="titledesc">
305 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
306 <?php echo $tip; ?>
307 </th>
308 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
309 <input
310 name="<?php echo esc_attr( $value['id'] ); ?>"
311 id="<?php echo esc_attr( $value['id'] ); ?>"
312 type="<?php echo esc_attr( $type ); ?>"
313 style="<?php echo esc_attr( $value['css'] ); ?>"
314 value="<?php echo esc_attr( $option_value ); ?>"
315 class="<?php echo esc_attr( $value['class'] ); ?>"
316 <?php echo implode( ' ', $custom_attributes ); ?>
317 /> <?php echo $description; ?>
318 </td>
319 </tr><?php
320 break;
321
322 // Hidden
323 case 'hidden':
324
325 $option_value = self::get_option( $value['id'], $value['default'] );
326
327 ?><input type="hidden"
328 name="<?php echo esc_attr( $value['id'] ); ?>"
329 value="<?php echo esc_attr( $option_value ); ?>"
330 /><?php
331
332 break;
333
334 // Textarea
335 case 'textarea':
336
337 $option_value = self::get_option( $value['id'], $value['default'] );
338
339 ?><tr valign="top" id="row_<?php echo esc_attr( $value['id'] ); ?>">
340 <th scope="row" class="titledesc">
341 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
342 <?php echo $tip; ?>
343 </th>
344 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
345 <?php echo $description; ?>
346
347 <textarea
348 name="<?php echo esc_attr( $value['id'] ); ?>"
349 id="<?php echo esc_attr( $value['id'] ); ?>"
350 style="<?php echo esc_attr( $value['css'] ); ?>"
351 class="<?php echo esc_attr( $value['class'] ); ?>"
352 <?php echo implode( ' ', $custom_attributes ); ?>
353 ><?php echo esc_textarea( $option_value ); ?></textarea>
354 </td>
355 </tr><?php
356 break;
357
358 // WYSIWYG
359 case 'wysiwyg':
360
361 $option_value = self::get_option( $value['id'], $value['default'] );
362
363 ?><tr valign="top" id="row_<?php echo esc_attr( $value['id'] ); ?>">
364 <th scope="row" class="titledesc">
365 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
366 <?php echo $tip; ?>
367 </th>
368 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
369
370 <?php wp_editor( $option_value, esc_attr( $value['id'] ), array( 'media_buttons' => false, 'textarea_rows' => 3, 'teeny' => true ) ); ?>
371
372 <?php echo '<br>' . $description; ?>
373
374 <?php /*<textarea
375 name="<?php echo esc_attr( $value['id'] ); ?>"
376 id="<?php echo esc_attr( $value['id'] ); ?>"
377 <?php echo implode( ' ', $custom_attributes ); ?>
378 ><?php echo esc_textarea( $option_value ); ?></textarea>*/ ?>
379 </td>
380 </tr><?php
381 break;
382
383 // Select boxes
384 case 'select' :
385 case 'multiselect' :
386
387 $option_value = self::get_option( $value['id'], $value['default'] );
388
389 ?><tr valign="top" id="row_<?php echo esc_attr( $value['id'] ); ?>">
390 <th scope="row" class="titledesc">
391 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
392 <?php echo $tip; ?>
393 </th>
394 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
395 <select
396 name="<?php echo esc_attr( $value['id'] ); ?><?php if ( $value['type'] == 'multiselect' ) echo '[]'; ?>"
397 id="<?php echo esc_attr( $value['id'] ); ?>"
398 style="<?php echo esc_attr( $value['css'] ); ?>"
399 class="<?php echo esc_attr( $value['class'] ); ?>"
400 <?php echo implode( ' ', $custom_attributes ); ?>
401 <?php if ( $value['type'] == 'multiselect' ) echo 'multiple="multiple"'; ?>
402 >
403 <?php
404 foreach ( $value['options'] as $key => $val ) {
405 ?>
406 <option value="<?php echo esc_attr( $key ); ?>" <?php
407
408 if ( is_array( $option_value ) )
409 selected( in_array( $key, $option_value ), true );
410 else
411 selected( $option_value, $key );
412
413 ?>><?php echo $val ?></option>
414 <?php
415 }
416 ?>
417 </select> <?php echo $description; ?>
418 </td>
419 </tr><?php
420 break;
421
422 // Radio inputs
423 case 'radio' :
424
425 $option_value = self::get_option( $value['id'], $value['default'] );
426
427 ?><tr valign="top" id="row_<?php echo esc_attr( $value['id'] ); ?>">
428 <th scope="row" class="titledesc">
429 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
430 <?php echo $tip; ?>
431 </th>
432 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
433 <fieldset>
434 <?php echo $description; ?>
435 <ul>
436 <?php
437 foreach ( $value['options'] as $key => $val ) {
438 ?>
439 <li>
440 <label><input
441 name="<?php echo esc_attr( $value['id'] ); ?>"
442 value="<?php echo $key; ?>"
443 type="radio"
444 style="<?php echo esc_attr( $value['css'] ); ?>"
445 class="<?php echo esc_attr( $value['class'] ); ?>"
446 <?php echo implode( ' ', $custom_attributes ); ?>
447 <?php checked( $key, $option_value ); ?>
448 /> <?php echo $val ?></label>
449 </li>
450 <?php
451 }
452 ?>
453 </ul>
454 </fieldset>
455 </td>
456 </tr><?php
457 break;
458
459 // Checkbox input
460 case 'checkbox' :
461
462 $name = isset($value['name']) && $value['name'] != '' ? ph_clean($value['name']) : $value['id'];
463 $option_value = isset($value['value']) ? ph_clean($value['value']) : self::get_option( $value['id'], $value['default'] );
464 $fieldset_css = isset($value['fieldset_css']) ? ph_clean($value['fieldset_css']) : '';
465
466 $visbility_class = array();
467
468 if ( ! isset( $value['hide_if_checked'] ) ) {
469 $value['hide_if_checked'] = false;
470 }
471 if ( ! isset( $value['show_if_checked'] ) ) {
472 $value['show_if_checked'] = false;
473 }
474 if ( $value['hide_if_checked'] == 'yes' || $value['show_if_checked'] == 'yes' ) {
475 $visbility_class[] = 'hidden_option';
476 }
477 if ( $value['hide_if_checked'] == 'option' ) {
478 $visbility_class[] = 'hide_options_if_checked';
479 }
480 if ( $value['show_if_checked'] == 'option' ) {
481 $visbility_class[] = 'show_options_if_checked';
482 }
483
484 if ( ! isset( $value['checkboxgroup'] ) || 'start' == $value['checkboxgroup'] ) {
485 ?>
486 <tr valign="top" class="<?php echo esc_attr( implode( ' ', $visbility_class ) ); ?>" id="row_<?php echo esc_attr( $value['id'] ); ?>">
487 <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?></th>
488 <td class="forminp forminp-checkbox">
489 <fieldset style="<?php echo $fieldset_css; ?>">
490 <?php
491 } else {
492 ?>
493 <fieldset style="<?php echo $fieldset_css; ?>" class="<?php echo esc_attr( implode( ' ', $visbility_class ) ); ?>">
494 <?php
495 }
496
497 if ( ! empty( $value['title'] ) ) {
498 ?>
499 <legend class="screen-reader-text"><span><?php echo esc_html( $value['title'] ) ?></span></legend>
500 <?php
501 }
502
503 ?>
504 <label for="<?php echo $value['id'] ?>">
505 <input
506 name="<?php echo esc_attr( $name ); ?>"
507 id="<?php echo esc_attr( $value['id'] ); ?>"
508 type="checkbox"
509 value="1"
510 <?php checked( $option_value, 'yes'); ?>
511 <?php echo implode( ' ', $custom_attributes ); ?>
512 /> <?php echo $description ?>
513 </label> <?php echo $tip; ?>
514 <?php
515
516 if ( ! isset( $value['checkboxgroup'] ) || 'end' == $value['checkboxgroup'] ) {
517 ?>
518 </fieldset>
519 </td>
520 </tr>
521 <?php
522 } else {
523 ?>
524 </fieldset>
525 <?php
526 }
527 break;
528
529 // Image width settings
530 case 'image_width' :
531
532 $width = self::get_option( $value['id'] . '[width]', $value['default']['width'] );
533 $height = self::get_option( $value['id'] . '[height]', $value['default']['height'] );
534 $crop = checked( 1, self::get_option( $value['id'] . '[crop]', $value['default']['crop'] ), false );
535
536 ?><tr valign="top" id="row_<?php echo esc_attr( $value['id'] ); ?>">
537 <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?> <?php echo $tip; ?></th>
538 <td class="forminp image_width_settings">
539
540 <input name="<?php echo esc_attr( $value['id'] ); ?>[width]" id="<?php echo esc_attr( $value['id'] ); ?>-width" type="text" size="3" value="<?php echo $width; ?>" /> &times; <input name="<?php echo esc_attr( $value['id'] ); ?>[height]" id="<?php echo esc_attr( $value['id'] ); ?>-height" type="text" size="3" value="<?php echo $height; ?>" />px
541
542 <label><input name="<?php echo esc_attr( $value['id'] ); ?>[crop]" id="<?php echo esc_attr( $value['id'] ); ?>-crop" type="checkbox" <?php echo $crop; ?> /> <?php _e( 'Hard Crop?', 'propertyhive' ); ?></label>
543
544 </td>
545 </tr><?php
546 break;
547
548 // Single page selects
549 case 'single_select_page' :
550
551 $args = array( 'name' => $value['id'],
552 'id' => $value['id'],
553 'sort_column' => 'menu_order',
554 'sort_order' => 'ASC',
555 'show_option_none' => ' ',
556 'class' => $value['class'],
557 'echo' => false,
558 'selected' => absint( self::get_option( $value['id'] ) )
559 );
560
561 if( isset( $value['args'] ) )
562 $args = wp_parse_args( $value['args'], $args );
563
564 ?><tr valign="top" class="single_select_page" id="row_<?php echo esc_attr( $value['id'] ); ?>">
565 <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?> <?php echo $tip; ?></th>
566 <td class="forminp">
567 <?php echo str_replace(' id=', " data-placeholder='" . __( 'Select a page&hellip;', 'propertyhive' ) . "' style='" . $value['css'] . "' class='" . $value['class'] . "' id=", wp_dropdown_pages( $args ) ); ?> <?php echo $description; ?>
568 </td>
569 </tr><?php
570 break;
571
572 // Single country selects
573 case 'single_select_country' :
574 $country_setting = (string) self::get_option( $value['id'] );
575 $countries = PH()->countries->countries;
576
577 if ( strstr( $country_setting, ':' ) ) {
578 $country_setting = explode( ':', $country_setting );
579 $country = current( $country_setting );
580 } else {
581 $country = $country_setting;
582 }
583 ?><tr valign="top" id="row_<?php echo esc_attr( $value['id'] ); ?>">
584 <th scope="row" class="titledesc">
585 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
586 <?php echo $tip; ?>
587 </th>
588 <td class="forminp">
589 <select name="<?php echo esc_attr( $value['id'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>">
590 <?php PH()->countries->country_dropdown_options( $country ); ?>
591 </select>
592 <?php echo $description; ?>
593 </td>
594 </tr><?php
595 break;
596
597 // Country multiselects
598 case 'multi_select_countries' :
599
600 $selections = (array) self::get_option( $value['id'] );
601
602 if ( ! empty( $value['options'] ) )
603 $countries = $value['options'];
604 else
605 $countries = PH()->countries->countries;
606
607 asort( $countries );
608 ?><tr valign="top" id="row_<?php echo esc_attr( $value['id'] ); ?>">
609 <th scope="row" class="titledesc">
610 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
611 <?php echo $tip; ?>
612 </th>
613 <td class="forminp">
614 <select multiple="multiple" name="<?php echo esc_attr( $value['id'] ); ?>[]" style="<?php echo esc_attr( $value['css'] ); ?>">
615 <?php
616 if ( $countries )
617 foreach ( $countries as $key => $val )
618 echo '<option value="' . esc_attr( $key ) . '" ' . selected( in_array( $key, $selections ), true, false ).'>' . $val['name'] . '</option>';
619 ?>
620 </select> <?php if ( $description ) echo $description; ?>
621 </td>
622 </tr><?php
623 break;
624
625 // Default: run an action
626 default:
627 do_action( 'propertyhive_admin_field_' . $value['type'], $value );
628 break;
629 }
630 }
631 }
632
633 /**
634 * Save admin fields.
635 *
636 * Loops though the propertyhive options array and outputs each field.
637 *
638 * @access public
639 * @param array $options Opens array to output
640 * @return bool
641 */
642 public static function save_fields( $options ) {
643 if ( empty( $_POST ) )
644 return false;
645
646 // Options to update will be stored here
647 $update_options = array();
648
649 // Loop options and get values to save
650 foreach ( $options as $value ) {
651
652 if ( ! isset( $value['id'] ) )
653 continue;
654
655 $type = isset( $value['type'] ) ? sanitize_title( $value['type'] ) : '';
656
657 // Get the option name
658 $option_value = null;
659
660 switch ( $type ) {
661
662 // Standard types
663 case "checkbox" :
664
665 if ( isset( $_POST[ $value['id'] ] ) ) {
666 $option_value = 'yes';
667 } else {
668 $option_value = 'no';
669 }
670
671 break;
672
673 case "textarea" :
674 case "wysiwyg" :
675
676 if ( isset( $_POST[$value['id']] ) ) {
677 $option_value = wp_kses_post( trim( stripslashes( $_POST[ $value['id'] ] ) ) );
678 } else {
679 $option_value = '';
680 }
681
682 break;
683
684 case "text" :
685 case 'email':
686 case 'number':
687 case "select" :
688 case "color" :
689 case 'password' :
690 case "single_select_page" :
691 case "single_select_country" :
692 case 'radio' :
693
694 if ( isset( $_POST[$value['id']] ) ) {
695 $option_value = sanitize_text_field( stripslashes( $_POST[ $value['id'] ] ) );
696 } else {
697 $option_value = '';
698 }
699
700 break;
701
702 // Special types
703 case "multiselect" :
704 case "multi_select_countries" :
705
706 // Get countries array
707 if ( isset( $_POST[ $value['id'] ] ) )
708 $selected_countries = array_map( 'ph_clean', array_map( 'stripslashes', (array) $_POST[ $value['id'] ] ) );
709 else
710 $selected_countries = array();
711
712 $option_value = $selected_countries;
713
714 break;
715
716 case "image_width" :
717
718 if ( isset( $_POST[$value['id'] ]['width'] ) ) {
719
720 $update_options[ $value['id'] ]['width'] = ph_clean( stripslashes( $_POST[ $value['id'] ]['width'] ) );
721 $update_options[ $value['id'] ]['height'] = ph_clean( stripslashes( $_POST[ $value['id'] ]['height'] ) );
722
723 if ( isset( $_POST[ $value['id'] ]['crop'] ) )
724 $update_options[ $value['id'] ]['crop'] = 1;
725 else
726 $update_options[ $value['id'] ]['crop'] = 0;
727
728 } else {
729 $update_options[ $value['id'] ]['width'] = $value['default']['width'];
730 $update_options[ $value['id'] ]['height'] = $value['default']['height'];
731 $update_options[ $value['id'] ]['crop'] = $value['default']['crop'];
732 }
733
734 break;
735
736 // Custom handling
737 default :
738
739 do_action( 'propertyhive_update_option_' . $type, $value );
740
741 break;
742
743 }
744
745 if ( ! is_null( $option_value ) ) {
746 // Check if option is an array
747 if ( strstr( $value['id'], '[' ) ) {
748
749 parse_str( $value['id'], $option_array );
750
751 // Option name is first key
752 $option_name = current( array_keys( $option_array ) );
753
754 // Get old option value
755 if ( ! isset( $update_options[ $option_name ] ) )
756 $update_options[ $option_name ] = get_option( $option_name, array() );
757
758 if ( ! is_array( $update_options[ $option_name ] ) )
759 $update_options[ $option_name ] = array();
760
761 // Set keys and value
762 $key = key( $option_array[ $option_name ] );
763
764 $update_options[ $option_name ][ $key ] = $option_value;
765
766 // Single value
767 } else {
768 $update_options[ $value['id'] ] = $option_value;
769 }
770 }
771
772 // Custom handling
773 do_action( 'propertyhive_update_option', $value );
774 }
775
776 // Now save the options
777 foreach( $update_options as $name => $value )
778 update_option( $name, $value );
779
780 return true;
781 }
782
783 /**
784 * Checks which method we're using to serve downloads
785 *
786 * If using force or x-sendfile, this ensures the .htaccess is in place
787 *
788 * @access public
789 * @return void
790 */
791 /*public static function check_download_folder_protection() {
792 $upload_dir = wp_upload_dir();
793 $downloads_url = $upload_dir['basedir'] . '/propertyhive_uploads';
794 $download_method = get_option('propertyhive_file_download_method');
795
796 if ( $download_method == 'redirect' ) {
797
798 // Redirect method - don't protect
799 if ( file_exists( $downloads_url . '/.htaccess' ) )
800 unlink( $downloads_url . '/.htaccess' );
801
802 } else {
803
804 // Force method - protect, add rules to the htaccess file
805 if ( ! file_exists( $downloads_url . '/.htaccess' ) ) {
806 if ( $file_handle = @fopen( $downloads_url . '/.htaccess', 'w' ) ) {
807 fwrite( $file_handle, 'deny from all' );
808 fclose( $file_handle );
809 }
810 }
811 }
812 }*/
813 }
814
815 endif;
816