PluginProbe
Property Hive / 1.4.5
Property Hive v1.4.5
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.5, at includes/admin/class-ph-admin-settings.php

787 lines 27.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">
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">
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">
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 // Select boxes
359 case 'select' :
360 case 'multiselect' :
361
362 $option_value = self::get_option( $value['id'], $value['default'] );
363
364 ?><tr valign="top">
365 <th scope="row" class="titledesc">
366 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
367 <?php echo $tip; ?>
368 </th>
369 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
370 <select
371 name="<?php echo esc_attr( $value['id'] ); ?><?php if ( $value['type'] == 'multiselect' ) echo '[]'; ?>"
372 id="<?php echo esc_attr( $value['id'] ); ?>"
373 style="<?php echo esc_attr( $value['css'] ); ?>"
374 class="<?php echo esc_attr( $value['class'] ); ?>"
375 <?php echo implode( ' ', $custom_attributes ); ?>
376 <?php if ( $value['type'] == 'multiselect' ) echo 'multiple="multiple"'; ?>
377 >
378 <?php
379 foreach ( $value['options'] as $key => $val ) {
380 ?>
381 <option value="<?php echo esc_attr( $key ); ?>" <?php
382
383 if ( is_array( $option_value ) )
384 selected( in_array( $key, $option_value ), true );
385 else
386 selected( $option_value, $key );
387
388 ?>><?php echo $val ?></option>
389 <?php
390 }
391 ?>
392 </select> <?php echo $description; ?>
393 </td>
394 </tr><?php
395 break;
396
397 // Radio inputs
398 case 'radio' :
399
400 $option_value = self::get_option( $value['id'], $value['default'] );
401
402 ?><tr valign="top">
403 <th scope="row" class="titledesc">
404 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
405 <?php echo $tip; ?>
406 </th>
407 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
408 <fieldset>
409 <?php echo $description; ?>
410 <ul>
411 <?php
412 foreach ( $value['options'] as $key => $val ) {
413 ?>
414 <li>
415 <label><input
416 name="<?php echo esc_attr( $value['id'] ); ?>"
417 value="<?php echo $key; ?>"
418 type="radio"
419 style="<?php echo esc_attr( $value['css'] ); ?>"
420 class="<?php echo esc_attr( $value['class'] ); ?>"
421 <?php echo implode( ' ', $custom_attributes ); ?>
422 <?php checked( $key, $option_value ); ?>
423 /> <?php echo $val ?></label>
424 </li>
425 <?php
426 }
427 ?>
428 </ul>
429 </fieldset>
430 </td>
431 </tr><?php
432 break;
433
434 // Checkbox input
435 case 'checkbox' :
436
437 $option_value = self::get_option( $value['id'], $value['default'] );
438 $visbility_class = array();
439
440 if ( ! isset( $value['hide_if_checked'] ) ) {
441 $value['hide_if_checked'] = false;
442 }
443 if ( ! isset( $value['show_if_checked'] ) ) {
444 $value['show_if_checked'] = false;
445 }
446 if ( $value['hide_if_checked'] == 'yes' || $value['show_if_checked'] == 'yes' ) {
447 $visbility_class[] = 'hidden_option';
448 }
449 if ( $value['hide_if_checked'] == 'option' ) {
450 $visbility_class[] = 'hide_options_if_checked';
451 }
452 if ( $value['show_if_checked'] == 'option' ) {
453 $visbility_class[] = 'show_options_if_checked';
454 }
455
456 if ( ! isset( $value['checkboxgroup'] ) || 'start' == $value['checkboxgroup'] ) {
457 ?>
458 <tr valign="top" class="<?php echo esc_attr( implode( ' ', $visbility_class ) ); ?>">
459 <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?></th>
460 <td class="forminp forminp-checkbox">
461 <fieldset>
462 <?php
463 } else {
464 ?>
465 <fieldset class="<?php echo esc_attr( implode( ' ', $visbility_class ) ); ?>">
466 <?php
467 }
468
469 if ( ! empty( $value['title'] ) ) {
470 ?>
471 <legend class="screen-reader-text"><span><?php echo esc_html( $value['title'] ) ?></span></legend>
472 <?php
473 }
474
475 ?>
476 <label for="<?php echo $value['id'] ?>">
477 <input
478 name="<?php echo esc_attr( $value['id'] ); ?>"
479 id="<?php echo esc_attr( $value['id'] ); ?>"
480 type="checkbox"
481 value="1"
482 <?php checked( $option_value, 'yes'); ?>
483 <?php echo implode( ' ', $custom_attributes ); ?>
484 /> <?php echo $description ?>
485 </label> <?php echo $tip; ?>
486 <?php
487
488 if ( ! isset( $value['checkboxgroup'] ) || 'end' == $value['checkboxgroup'] ) {
489 ?>
490 </fieldset>
491 </td>
492 </tr>
493 <?php
494 } else {
495 ?>
496 </fieldset>
497 <?php
498 }
499 break;
500
501 // Image width settings
502 case 'image_width' :
503
504 $width = self::get_option( $value['id'] . '[width]', $value['default']['width'] );
505 $height = self::get_option( $value['id'] . '[height]', $value['default']['height'] );
506 $crop = checked( 1, self::get_option( $value['id'] . '[crop]', $value['default']['crop'] ), false );
507
508 ?><tr valign="top">
509 <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?> <?php echo $tip; ?></th>
510 <td class="forminp image_width_settings">
511
512 <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
513
514 <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>
515
516 </td>
517 </tr><?php
518 break;
519
520 // Single page selects
521 case 'single_select_page' :
522
523 $args = array( 'name' => $value['id'],
524 'id' => $value['id'],
525 'sort_column' => 'menu_order',
526 'sort_order' => 'ASC',
527 'show_option_none' => ' ',
528 'class' => $value['class'],
529 'echo' => false,
530 'selected' => absint( self::get_option( $value['id'] ) )
531 );
532
533 if( isset( $value['args'] ) )
534 $args = wp_parse_args( $value['args'], $args );
535
536 ?><tr valign="top" class="single_select_page">
537 <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?> <?php echo $tip; ?></th>
538 <td class="forminp">
539 <?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; ?>
540 </td>
541 </tr><?php
542 break;
543
544 // Single country selects
545 case 'single_select_country' :
546 $country_setting = (string) self::get_option( $value['id'] );
547 $countries = PH()->countries->countries;
548
549 if ( strstr( $country_setting, ':' ) ) {
550 $country_setting = explode( ':', $country_setting );
551 $country = current( $country_setting );
552 } else {
553 $country = $country_setting;
554 }
555 ?><tr valign="top">
556 <th scope="row" class="titledesc">
557 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
558 <?php echo $tip; ?>
559 </th>
560 <td class="forminp">
561 <select name="<?php echo esc_attr( $value['id'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>">
562 <?php PH()->countries->country_dropdown_options( $country ); ?>
563 </select>
564 <?php echo $description; ?>
565 </td>
566 </tr><?php
567 break;
568
569 // Country multiselects
570 case 'multi_select_countries' :
571
572 $selections = (array) self::get_option( $value['id'] );
573
574 if ( ! empty( $value['options'] ) )
575 $countries = $value['options'];
576 else
577 $countries = PH()->countries->countries;
578
579 asort( $countries );
580 ?><tr valign="top">
581 <th scope="row" class="titledesc">
582 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
583 <?php echo $tip; ?>
584 </th>
585 <td class="forminp">
586 <select multiple="multiple" name="<?php echo esc_attr( $value['id'] ); ?>[]" style="<?php echo esc_attr( $value['css'] ); ?>">
587 <?php
588 if ( $countries )
589 foreach ( $countries as $key => $val )
590 echo '<option value="' . esc_attr( $key ) . '" ' . selected( in_array( $key, $selections ), true, false ).'>' . $val['name'] . '</option>';
591 ?>
592 </select> <?php if ( $description ) echo $description; ?>
593 </td>
594 </tr><?php
595 break;
596
597 // Default: run an action
598 default:
599 do_action( 'propertyhive_admin_field_' . $value['type'], $value );
600 break;
601 }
602 }
603 }
604
605 /**
606 * Save admin fields.
607 *
608 * Loops though the propertyhive options array and outputs each field.
609 *
610 * @access public
611 * @param array $options Opens array to output
612 * @return bool
613 */
614 public static function save_fields( $options ) {
615 if ( empty( $_POST ) )
616 return false;
617
618 // Options to update will be stored here
619 $update_options = array();
620
621 // Loop options and get values to save
622 foreach ( $options as $value ) {
623
624 if ( ! isset( $value['id'] ) )
625 continue;
626
627 $type = isset( $value['type'] ) ? sanitize_title( $value['type'] ) : '';
628
629 // Get the option name
630 $option_value = null;
631
632 switch ( $type ) {
633
634 // Standard types
635 case "checkbox" :
636
637 if ( isset( $_POST[ $value['id'] ] ) ) {
638 $option_value = 'yes';
639 } else {
640 $option_value = 'no';
641 }
642
643 break;
644
645 case "textarea" :
646
647 if ( isset( $_POST[$value['id']] ) ) {
648 $option_value = wp_kses_post( trim( stripslashes( $_POST[ $value['id'] ] ) ) );
649 } else {
650 $option_value = '';
651 }
652
653 break;
654
655 case "text" :
656 case 'email':
657 case 'number':
658 case "select" :
659 case "color" :
660 case 'password' :
661 case "single_select_page" :
662 case "single_select_country" :
663 case 'radio' :
664
665 if ( isset( $_POST[$value['id']] ) ) {
666 $option_value = sanitize_text_field( stripslashes( $_POST[ $value['id'] ] ) );
667 } else {
668 $option_value = '';
669 }
670
671 break;
672
673 // Special types
674 case "multiselect" :
675 case "multi_select_countries" :
676
677 // Get countries array
678 if ( isset( $_POST[ $value['id'] ] ) )
679 $selected_countries = array_map( 'ph_clean', array_map( 'stripslashes', (array) $_POST[ $value['id'] ] ) );
680 else
681 $selected_countries = array();
682
683 $option_value = $selected_countries;
684
685 break;
686
687 case "image_width" :
688
689 if ( isset( $_POST[$value['id'] ]['width'] ) ) {
690
691 $update_options[ $value['id'] ]['width'] = ph_clean( stripslashes( $_POST[ $value['id'] ]['width'] ) );
692 $update_options[ $value['id'] ]['height'] = ph_clean( stripslashes( $_POST[ $value['id'] ]['height'] ) );
693
694 if ( isset( $_POST[ $value['id'] ]['crop'] ) )
695 $update_options[ $value['id'] ]['crop'] = 1;
696 else
697 $update_options[ $value['id'] ]['crop'] = 0;
698
699 } else {
700 $update_options[ $value['id'] ]['width'] = $value['default']['width'];
701 $update_options[ $value['id'] ]['height'] = $value['default']['height'];
702 $update_options[ $value['id'] ]['crop'] = $value['default']['crop'];
703 }
704
705 break;
706
707 // Custom handling
708 default :
709
710 do_action( 'propertyhive_update_option_' . $type, $value );
711
712 break;
713
714 }
715
716 if ( ! is_null( $option_value ) ) {
717 // Check if option is an array
718 if ( strstr( $value['id'], '[' ) ) {
719
720 parse_str( $value['id'], $option_array );
721
722 // Option name is first key
723 $option_name = current( array_keys( $option_array ) );
724
725 // Get old option value
726 if ( ! isset( $update_options[ $option_name ] ) )
727 $update_options[ $option_name ] = get_option( $option_name, array() );
728
729 if ( ! is_array( $update_options[ $option_name ] ) )
730 $update_options[ $option_name ] = array();
731
732 // Set keys and value
733 $key = key( $option_array[ $option_name ] );
734
735 $update_options[ $option_name ][ $key ] = $option_value;
736
737 // Single value
738 } else {
739 $update_options[ $value['id'] ] = $option_value;
740 }
741 }
742
743 // Custom handling
744 do_action( 'propertyhive_update_option', $value );
745 }
746
747 // Now save the options
748 foreach( $update_options as $name => $value )
749 update_option( $name, $value );
750
751 return true;
752 }
753
754 /**
755 * Checks which method we're using to serve downloads
756 *
757 * If using force or x-sendfile, this ensures the .htaccess is in place
758 *
759 * @access public
760 * @return void
761 */
762 /*public static function check_download_folder_protection() {
763 $upload_dir = wp_upload_dir();
764 $downloads_url = $upload_dir['basedir'] . '/propertyhive_uploads';
765 $download_method = get_option('propertyhive_file_download_method');
766
767 if ( $download_method == 'redirect' ) {
768
769 // Redirect method - don't protect
770 if ( file_exists( $downloads_url . '/.htaccess' ) )
771 unlink( $downloads_url . '/.htaccess' );
772
773 } else {
774
775 // Force method - protect, add rules to the htaccess file
776 if ( ! file_exists( $downloads_url . '/.htaccess' ) ) {
777 if ( $file_handle = @fopen( $downloads_url . '/.htaccess', 'w' ) ) {
778 fwrite( $file_handle, 'deny from all' );
779 fclose( $file_handle );
780 }
781 }
782 }
783 }*/
784 }
785
786 endif;
787