| 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 |
$option_value = self::get_option( $value['id'], $value['default'] ); |
| 463 |
$fieldset_css = isset($value['fieldset_css']) ? ph_clean($value['fieldset_css']) : ''; |
| 464 |
|
| 465 |
$visbility_class = array(); |
| 466 |
|
| 467 |
if ( ! isset( $value['hide_if_checked'] ) ) { |
| 468 |
$value['hide_if_checked'] = false; |
| 469 |
} |
| 470 |
if ( ! isset( $value['show_if_checked'] ) ) { |
| 471 |
$value['show_if_checked'] = false; |
| 472 |
} |
| 473 |
if ( $value['hide_if_checked'] == 'yes' || $value['show_if_checked'] == 'yes' ) { |
| 474 |
$visbility_class[] = 'hidden_option'; |
| 475 |
} |
| 476 |
if ( $value['hide_if_checked'] == 'option' ) { |
| 477 |
$visbility_class[] = 'hide_options_if_checked'; |
| 478 |
} |
| 479 |
if ( $value['show_if_checked'] == 'option' ) { |
| 480 |
$visbility_class[] = 'show_options_if_checked'; |
| 481 |
} |
| 482 |
|
| 483 |
if ( ! isset( $value['checkboxgroup'] ) || 'start' == $value['checkboxgroup'] ) { |
| 484 |
?> |
| 485 |
<tr valign="top" class="<?php echo esc_attr( implode( ' ', $visbility_class ) ); ?>" id="row_<?php echo esc_attr( $value['id'] ); ?>"> |
| 486 |
<th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?></th> |
| 487 |
<td class="forminp forminp-checkbox"> |
| 488 |
<fieldset style="<?php echo $fieldset_css; ?>"> |
| 489 |
<?php |
| 490 |
} else { |
| 491 |
?> |
| 492 |
<fieldset style="<?php echo $fieldset_css; ?>" class="<?php echo esc_attr( implode( ' ', $visbility_class ) ); ?>"> |
| 493 |
<?php |
| 494 |
} |
| 495 |
|
| 496 |
if ( ! empty( $value['title'] ) ) { |
| 497 |
?> |
| 498 |
<legend class="screen-reader-text"><span><?php echo esc_html( $value['title'] ) ?></span></legend> |
| 499 |
<?php |
| 500 |
} |
| 501 |
|
| 502 |
?> |
| 503 |
<label for="<?php echo $value['id'] ?>"> |
| 504 |
<input |
| 505 |
name="<?php echo esc_attr( $value['id'] ); ?>" |
| 506 |
id="<?php echo esc_attr( $value['id'] ); ?>" |
| 507 |
type="checkbox" |
| 508 |
value="1" |
| 509 |
<?php checked( $option_value, 'yes'); ?> |
| 510 |
<?php echo implode( ' ', $custom_attributes ); ?> |
| 511 |
/> <?php echo $description ?> |
| 512 |
</label> <?php echo $tip; ?> |
| 513 |
<?php |
| 514 |
|
| 515 |
if ( ! isset( $value['checkboxgroup'] ) || 'end' == $value['checkboxgroup'] ) { |
| 516 |
?> |
| 517 |
</fieldset> |
| 518 |
</td> |
| 519 |
</tr> |
| 520 |
<?php |
| 521 |
} else { |
| 522 |
?> |
| 523 |
</fieldset> |
| 524 |
<?php |
| 525 |
} |
| 526 |
break; |
| 527 |
|
| 528 |
// Image width settings |
| 529 |
case 'image_width' : |
| 530 |
|
| 531 |
$width = self::get_option( $value['id'] . '[width]', $value['default']['width'] ); |
| 532 |
$height = self::get_option( $value['id'] . '[height]', $value['default']['height'] ); |
| 533 |
$crop = checked( 1, self::get_option( $value['id'] . '[crop]', $value['default']['crop'] ), false ); |
| 534 |
|
| 535 |
?><tr valign="top" id="row_<?php echo esc_attr( $value['id'] ); ?>"> |
| 536 |
<th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?> <?php echo $tip; ?></th> |
| 537 |
<td class="forminp image_width_settings"> |
| 538 |
|
| 539 |
<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; ?>" /> × <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 |
| 540 |
|
| 541 |
<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> |
| 542 |
|
| 543 |
</td> |
| 544 |
</tr><?php |
| 545 |
break; |
| 546 |
|
| 547 |
// Single page selects |
| 548 |
case 'single_select_page' : |
| 549 |
|
| 550 |
$args = array( 'name' => $value['id'], |
| 551 |
'id' => $value['id'], |
| 552 |
'sort_column' => 'menu_order', |
| 553 |
'sort_order' => 'ASC', |
| 554 |
'show_option_none' => ' ', |
| 555 |
'class' => $value['class'], |
| 556 |
'echo' => false, |
| 557 |
'selected' => absint( self::get_option( $value['id'] ) ) |
| 558 |
); |
| 559 |
|
| 560 |
if( isset( $value['args'] ) ) |
| 561 |
$args = wp_parse_args( $value['args'], $args ); |
| 562 |
|
| 563 |
?><tr valign="top" class="single_select_page" id="row_<?php echo esc_attr( $value['id'] ); ?>"> |
| 564 |
<th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?> <?php echo $tip; ?></th> |
| 565 |
<td class="forminp"> |
| 566 |
<?php echo str_replace(' id=', " data-placeholder='" . __( 'Select a page…', 'propertyhive' ) . "' style='" . $value['css'] . "' class='" . $value['class'] . "' id=", wp_dropdown_pages( $args ) ); ?> <?php echo $description; ?> |
| 567 |
</td> |
| 568 |
</tr><?php |
| 569 |
break; |
| 570 |
|
| 571 |
// Single country selects |
| 572 |
case 'single_select_country' : |
| 573 |
$country_setting = (string) self::get_option( $value['id'] ); |
| 574 |
$countries = PH()->countries->countries; |
| 575 |
|
| 576 |
if ( strstr( $country_setting, ':' ) ) { |
| 577 |
$country_setting = explode( ':', $country_setting ); |
| 578 |
$country = current( $country_setting ); |
| 579 |
} else { |
| 580 |
$country = $country_setting; |
| 581 |
} |
| 582 |
?><tr valign="top" id="row_<?php echo esc_attr( $value['id'] ); ?>"> |
| 583 |
<th scope="row" class="titledesc"> |
| 584 |
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label> |
| 585 |
<?php echo $tip; ?> |
| 586 |
</th> |
| 587 |
<td class="forminp"> |
| 588 |
<select name="<?php echo esc_attr( $value['id'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>"> |
| 589 |
<?php PH()->countries->country_dropdown_options( $country ); ?> |
| 590 |
</select> |
| 591 |
<?php echo $description; ?> |
| 592 |
</td> |
| 593 |
</tr><?php |
| 594 |
break; |
| 595 |
|
| 596 |
// Country multiselects |
| 597 |
case 'multi_select_countries' : |
| 598 |
|
| 599 |
$selections = (array) self::get_option( $value['id'] ); |
| 600 |
|
| 601 |
if ( ! empty( $value['options'] ) ) |
| 602 |
$countries = $value['options']; |
| 603 |
else |
| 604 |
$countries = PH()->countries->countries; |
| 605 |
|
| 606 |
asort( $countries ); |
| 607 |
?><tr valign="top" id="row_<?php echo esc_attr( $value['id'] ); ?>"> |
| 608 |
<th scope="row" class="titledesc"> |
| 609 |
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label> |
| 610 |
<?php echo $tip; ?> |
| 611 |
</th> |
| 612 |
<td class="forminp"> |
| 613 |
<select multiple="multiple" name="<?php echo esc_attr( $value['id'] ); ?>[]" style="<?php echo esc_attr( $value['css'] ); ?>"> |
| 614 |
<?php |
| 615 |
if ( $countries ) |
| 616 |
foreach ( $countries as $key => $val ) |
| 617 |
echo '<option value="' . esc_attr( $key ) . '" ' . selected( in_array( $key, $selections ), true, false ).'>' . $val['name'] . '</option>'; |
| 618 |
?> |
| 619 |
</select> <?php if ( $description ) echo $description; ?> |
| 620 |
</td> |
| 621 |
</tr><?php |
| 622 |
break; |
| 623 |
|
| 624 |
// Default: run an action |
| 625 |
default: |
| 626 |
do_action( 'propertyhive_admin_field_' . $value['type'], $value ); |
| 627 |
break; |
| 628 |
} |
| 629 |
} |
| 630 |
} |
| 631 |
|
| 632 |
/** |
| 633 |
* Save admin fields. |
| 634 |
* |
| 635 |
* Loops though the propertyhive options array and outputs each field. |
| 636 |
* |
| 637 |
* @access public |
| 638 |
* @param array $options Opens array to output |
| 639 |
* @return bool |
| 640 |
*/ |
| 641 |
public static function save_fields( $options ) { |
| 642 |
if ( empty( $_POST ) ) |
| 643 |
return false; |
| 644 |
|
| 645 |
// Options to update will be stored here |
| 646 |
$update_options = array(); |
| 647 |
|
| 648 |
// Loop options and get values to save |
| 649 |
foreach ( $options as $value ) { |
| 650 |
|
| 651 |
if ( ! isset( $value['id'] ) ) |
| 652 |
continue; |
| 653 |
|
| 654 |
$type = isset( $value['type'] ) ? sanitize_title( $value['type'] ) : ''; |
| 655 |
|
| 656 |
// Get the option name |
| 657 |
$option_value = null; |
| 658 |
|
| 659 |
switch ( $type ) { |
| 660 |
|
| 661 |
// Standard types |
| 662 |
case "checkbox" : |
| 663 |
|
| 664 |
if ( isset( $_POST[ $value['id'] ] ) ) { |
| 665 |
$option_value = 'yes'; |
| 666 |
} else { |
| 667 |
$option_value = 'no'; |
| 668 |
} |
| 669 |
|
| 670 |
break; |
| 671 |
|
| 672 |
case "textarea" : |
| 673 |
case "wysiwyg" : |
| 674 |
|
| 675 |
if ( isset( $_POST[$value['id']] ) ) { |
| 676 |
$option_value = wp_kses_post( trim( stripslashes( $_POST[ $value['id'] ] ) ) ); |
| 677 |
} else { |
| 678 |
$option_value = ''; |
| 679 |
} |
| 680 |
|
| 681 |
break; |
| 682 |
|
| 683 |
case "text" : |
| 684 |
case 'email': |
| 685 |
case 'number': |
| 686 |
case "select" : |
| 687 |
case "color" : |
| 688 |
case 'password' : |
| 689 |
case "single_select_page" : |
| 690 |
case "single_select_country" : |
| 691 |
case 'radio' : |
| 692 |
|
| 693 |
if ( isset( $_POST[$value['id']] ) ) { |
| 694 |
$option_value = sanitize_text_field( stripslashes( $_POST[ $value['id'] ] ) ); |
| 695 |
} else { |
| 696 |
$option_value = ''; |
| 697 |
} |
| 698 |
|
| 699 |
break; |
| 700 |
|
| 701 |
// Special types |
| 702 |
case "multiselect" : |
| 703 |
case "multi_select_countries" : |
| 704 |
|
| 705 |
// Get countries array |
| 706 |
if ( isset( $_POST[ $value['id'] ] ) ) |
| 707 |
$selected_countries = array_map( 'ph_clean', array_map( 'stripslashes', (array) $_POST[ $value['id'] ] ) ); |
| 708 |
else |
| 709 |
$selected_countries = array(); |
| 710 |
|
| 711 |
$option_value = $selected_countries; |
| 712 |
|
| 713 |
break; |
| 714 |
|
| 715 |
case "image_width" : |
| 716 |
|
| 717 |
if ( isset( $_POST[$value['id'] ]['width'] ) ) { |
| 718 |
|
| 719 |
$update_options[ $value['id'] ]['width'] = ph_clean( stripslashes( $_POST[ $value['id'] ]['width'] ) ); |
| 720 |
$update_options[ $value['id'] ]['height'] = ph_clean( stripslashes( $_POST[ $value['id'] ]['height'] ) ); |
| 721 |
|
| 722 |
if ( isset( $_POST[ $value['id'] ]['crop'] ) ) |
| 723 |
$update_options[ $value['id'] ]['crop'] = 1; |
| 724 |
else |
| 725 |
$update_options[ $value['id'] ]['crop'] = 0; |
| 726 |
|
| 727 |
} else { |
| 728 |
$update_options[ $value['id'] ]['width'] = $value['default']['width']; |
| 729 |
$update_options[ $value['id'] ]['height'] = $value['default']['height']; |
| 730 |
$update_options[ $value['id'] ]['crop'] = $value['default']['crop']; |
| 731 |
} |
| 732 |
|
| 733 |
break; |
| 734 |
|
| 735 |
// Custom handling |
| 736 |
default : |
| 737 |
|
| 738 |
do_action( 'propertyhive_update_option_' . $type, $value ); |
| 739 |
|
| 740 |
break; |
| 741 |
|
| 742 |
} |
| 743 |
|
| 744 |
if ( ! is_null( $option_value ) ) { |
| 745 |
// Check if option is an array |
| 746 |
if ( strstr( $value['id'], '[' ) ) { |
| 747 |
|
| 748 |
parse_str( $value['id'], $option_array ); |
| 749 |
|
| 750 |
// Option name is first key |
| 751 |
$option_name = current( array_keys( $option_array ) ); |
| 752 |
|
| 753 |
// Get old option value |
| 754 |
if ( ! isset( $update_options[ $option_name ] ) ) |
| 755 |
$update_options[ $option_name ] = get_option( $option_name, array() ); |
| 756 |
|
| 757 |
if ( ! is_array( $update_options[ $option_name ] ) ) |
| 758 |
$update_options[ $option_name ] = array(); |
| 759 |
|
| 760 |
// Set keys and value |
| 761 |
$key = key( $option_array[ $option_name ] ); |
| 762 |
|
| 763 |
$update_options[ $option_name ][ $key ] = $option_value; |
| 764 |
|
| 765 |
// Single value |
| 766 |
} else { |
| 767 |
$update_options[ $value['id'] ] = $option_value; |
| 768 |
} |
| 769 |
} |
| 770 |
|
| 771 |
// Custom handling |
| 772 |
do_action( 'propertyhive_update_option', $value ); |
| 773 |
} |
| 774 |
|
| 775 |
// Now save the options |
| 776 |
foreach( $update_options as $name => $value ) |
| 777 |
update_option( $name, $value ); |
| 778 |
|
| 779 |
return true; |
| 780 |
} |
| 781 |
|
| 782 |
/** |
| 783 |
* Checks which method we're using to serve downloads |
| 784 |
* |
| 785 |
* If using force or x-sendfile, this ensures the .htaccess is in place |
| 786 |
* |
| 787 |
* @access public |
| 788 |
* @return void |
| 789 |
*/ |
| 790 |
/*public static function check_download_folder_protection() { |
| 791 |
$upload_dir = wp_upload_dir(); |
| 792 |
$downloads_url = $upload_dir['basedir'] . '/propertyhive_uploads'; |
| 793 |
$download_method = get_option('propertyhive_file_download_method'); |
| 794 |
|
| 795 |
if ( $download_method == 'redirect' ) { |
| 796 |
|
| 797 |
// Redirect method - don't protect |
| 798 |
if ( file_exists( $downloads_url . '/.htaccess' ) ) |
| 799 |
unlink( $downloads_url . '/.htaccess' ); |
| 800 |
|
| 801 |
} else { |
| 802 |
|
| 803 |
// Force method - protect, add rules to the htaccess file |
| 804 |
if ( ! file_exists( $downloads_url . '/.htaccess' ) ) { |
| 805 |
if ( $file_handle = @fopen( $downloads_url . '/.htaccess', 'w' ) ) { |
| 806 |
fwrite( $file_handle, 'deny from all' ); |
| 807 |
fclose( $file_handle ); |
| 808 |
} |
| 809 |
} |
| 810 |
} |
| 811 |
}*/ |
| 812 |
} |
| 813 |
|
| 814 |
endif; |
| 815 |
|