← All changes
|
includes/admin/views/html-viewing-event-meta-box.php
+58
-15
2.2.3
→
2.4.0
View file →
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 4 | 4 | |
| 5 | +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 5 | 6 | $readonly = isset($readonly) ? $readonly : false; |
| 6 | 7 | |
| 7 | 8 | echo '<div class="propertyhive_meta_box">'; |
| 8 | 9 | |
| @@ -9,17 +10,24 @@ | ||
| 9 | 10 | echo '<div class="options_group">'; |
| 10 | 11 | |
| 11 | 12 | wp_nonce_field( 'propertyhive_save_data', 'propertyhive_meta_nonce' ); |
| 12 | 13 | |
| 14 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only calendar prefill; saving has separate nonce and object guards. | |
| 15 | + $propertyhive_calendar_input = wp_unslash( $_GET ); | |
| 16 | + $propertyhive_calendar_start = isset( $propertyhive_calendar_input['start'] ) && is_scalar( $propertyhive_calendar_input['start'] ) ? absint( $propertyhive_calendar_input['start'] ) : null; | |
| 17 | + $propertyhive_calendar_end = isset( $propertyhive_calendar_input['end'] ) && is_scalar( $propertyhive_calendar_input['end'] ) ? absint( $propertyhive_calendar_input['end'] ) : null; | |
| 18 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view. | |
| 13 | 19 | $start_date_time = get_post_meta( $post->ID, '_start_date_time', true ); |
| 14 | 20 | if ( $start_date_time == '' ) |
| 15 | 21 | { |
| 16 | - $start_date_time = date("Y-m-d H:i:s"); | |
| 22 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 23 | + $start_date_time = gmdate("Y-m-d H:i:s"); | |
| 17 | 24 | |
| 18 | - if ( isset($_GET['start']) && $_GET['start'] != '' ) | |
| 25 | + if ( $propertyhive_calendar_start !== null ) | |
| 19 | 26 | { |
| 20 | 27 | // $_GET['start'] should be a unix timestamp |
| 21 | - $start_date_time = date("Y-m-d H:i:s", $_GET['start']); | |
| 28 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 29 | + $start_date_time = gmdate("Y-m-d H:i:s", $propertyhive_calendar_start); | |
| 22 | 30 | } |
| 23 | 31 | } |
| 24 | 32 | |
| 25 | 33 | echo '<p class="form-field event_start_time_field"> |
| @@ -27,25 +35,29 @@ | ||
| 27 | 35 | <label for="_start_date">' . esc_html(__('Viewing Date / Time', 'propertyhive')) . '</label>'; |
| 28 | 36 | |
| 29 | 37 | if ( $readonly ) |
| 30 | 38 | { |
| 31 | - echo esc_html(date("H:i", strtotime($start_date_time)) . ' on ' . date("l jS F Y", strtotime($start_date_time))); | |
| 39 | + echo esc_html(gmdate("H:i", strtotime($start_date_time)) . ' on ' . gmdate("l jS F Y", strtotime($start_date_time))); | |
| 32 | 40 | } |
| 33 | 41 | else |
| 34 | 42 | { |
| 35 | - echo '<input type="date" class="small" name="_start_date" id="_start_date" value="' . esc_attr(date("Y-m-d", strtotime($start_date_time))) . '" placeholder=""> | |
| 43 | + echo '<input type="date" class="small" name="_start_date" id="_start_date" value="' . esc_attr(gmdate("Y-m-d", strtotime($start_date_time))) . '" placeholder=""> | |
| 36 | 44 | <select id="_start_time_hours" name="_start_time_hours" class="select short" style="width:55px">'; |
| 37 | 45 | |
| 38 | 46 | if ( $start_date_time == '' ) |
| 39 | 47 | { |
| 40 | - $value = date("H"); | |
| 48 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 49 | + $value = gmdate("H"); | |
| 41 | 50 | } |
| 42 | 51 | else |
| 43 | 52 | { |
| 44 | - $value = date( "H", strtotime( $start_date_time ) ); | |
| 53 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 54 | + $value = gmdate( "H", strtotime( $start_date_time ) ); | |
| 45 | 55 | } |
| 56 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 46 | 57 | for ( $i = 0; $i < 23; ++$i ) |
| 47 | 58 | { |
| 59 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 48 | 60 | $j = str_pad($i, 2, '0', STR_PAD_LEFT); |
| 49 | 61 | echo '<option value="' . esc_attr($j) . '"'; |
| 50 | 62 | if ($i == $value) { echo ' selected'; } |
| 51 | 63 | echo '>' . esc_html($j) . '</option>'; |
| @@ -56,16 +68,20 @@ | ||
| 56 | 68 | <select id="_start_time_minutes" name="_start_time_minutes" class="select short" style="width:55px">'; |
| 57 | 69 | |
| 58 | 70 | if ( $start_date_time == '' ) |
| 59 | 71 | { |
| 72 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 60 | 73 | $value = ''; |
| 61 | 74 | } |
| 62 | 75 | else |
| 63 | 76 | { |
| 64 | - $value = date( "i", strtotime( $start_date_time ) ); | |
| 77 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 78 | + $value = gmdate( "i", strtotime( $start_date_time ) ); | |
| 65 | 79 | } |
| 80 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 66 | 81 | for ( $i = 0; $i < 60; $i+=5 ) |
| 67 | 82 | { |
| 83 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 68 | 84 | $j = str_pad($i, 2, '0', STR_PAD_LEFT); |
| 69 | 85 | echo '<option value="' . esc_attr($j) . '"'; |
| 70 | 86 | if ($i == $value) { echo ' selected'; } |
| 71 | 87 | echo '>' . esc_html($j) . '</option>'; |
| @@ -74,23 +90,29 @@ | ||
| 74 | 90 | echo '</select>'; |
| 75 | 91 | } |
| 76 | 92 | echo '</p>'; |
| 77 | 93 | |
| 94 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 78 | 95 | $durations = array(15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180); |
| 96 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 79 | 97 | $durations = apply_filters( 'propertyhive_viewing_durations', $durations ); |
| 80 | 98 | |
| 99 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 81 | 100 | $value = get_post_meta( $post->ID, '_duration', true ); |
| 82 | 101 | if ($value == '') |
| 83 | 102 | { |
| 103 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 84 | 104 | $value = apply_filters( 'propertyhive_viewing_default_duration_minutes', 30 ) * 60; // Default is 30 minutes, unless modified by filter |
| 85 | 105 | |
| 86 | - if ( isset($_GET['start']) && $_GET['start'] != '' && isset($_GET['end']) && $_GET['end'] != '' ) | |
| 106 | + if ( $propertyhive_calendar_start !== null && $propertyhive_calendar_end !== null ) | |
| 87 | 107 | { |
| 88 | 108 | // $_GET['start'] and $_GET['end'] should be a unix timestamp |
| 89 | - $duration = ($_GET['end'] - $_GET['start']) / 60; | |
| 109 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 110 | + $duration = ($propertyhive_calendar_end - $propertyhive_calendar_start) / 60; | |
| 90 | 111 | |
| 91 | 112 | if ( in_array($duration, $durations) ) |
| 92 | 113 | { |
| 114 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 93 | 115 | $value = $duration * 60; |
| 94 | 116 | } |
| 95 | 117 | } |
| 96 | 118 | } |
| @@ -102,18 +124,23 @@ | ||
| 102 | 124 | <label for="_duration">' . esc_html(__('Duration', 'propertyhive')) . '</label> |
| 103 | 125 | |
| 104 | 126 | <select id="_duration" name="_duration" class="select short">'; |
| 105 | 127 | |
| 128 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 106 | 129 | foreach ( $durations as $duration ) |
| 107 | 130 | { |
| 108 | 131 | // convert duration to reable format (i.e. 1 hour 15 minutes) |
| 132 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 109 | 133 | $hours = floor($duration / 60); |
| 134 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 110 | 135 | $minutes = $duration % 60; |
| 111 | 136 | echo '<option value="' . esc_attr(($duration * 60)) . '"' . ( $value == ($duration * 60) ? 'selected' : '' ) . '>' . esc_html(( $hours > 0 ? $hours . ' hour' . ( $hours != 1 ? 's' : '' ) : '' ) . ( $minutes != '' ? ' '. $minutes . ' minutes' : '' )) . '</option>'; |
| 112 | 137 | } |
| 113 | 138 | if ( !in_array( $value / 60, $durations)) |
| 114 | 139 | { |
| 140 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 115 | 141 | $hours = floor(($value / 60) / 60); |
| 142 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 116 | 143 | $minutes = ($value / 60) % 60; |
| 117 | 144 | echo '<option value="' . esc_attr($value) . '" selected>' . esc_html(( $hours > 0 ? $hours . ' hour' . ( $hours != 1 ? 's' : '' ) : '' ) . ( $minutes != '' ? ' ' . $minutes . ' minutes' : '' )) . '</option>'; |
| 118 | 145 | } |
| 119 | 146 | |
| @@ -124,8 +151,9 @@ | ||
| 124 | 151 | |
| 125 | 152 | echo ' |
| 126 | 153 | <p class="form-field"><label for="_negotiator_ids">' . esc_html(__( 'Attending Negotiator(s)', 'propertyhive' )) . '</label>'; |
| 127 | 154 | |
| 155 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 128 | 156 | $negotiator_ids = get_post_meta( $post->ID, '_negotiator_id' ); |
| 129 | 157 | if ( $readonly ) |
| 130 | 158 | { |
| 131 | 159 | if ( !empty($negotiator_ids) ) |
| @@ -130,10 +158,12 @@ | ||
| 130 | 158 | { |
| 131 | 159 | if ( !empty($negotiator_ids) ) |
| 132 | 160 | { |
| 133 | 161 | $names = array(); |
| 162 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 134 | 163 | foreach ( $negotiator_ids as $negotiator_id ) |
| 135 | 164 | { |
| 165 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 136 | 166 | $user_info = get_userdata($negotiator_id); |
| 137 | 167 | if ( $user_info !== FALSE ) |
| 138 | 168 | { |
| 139 | 169 | $names[] = $user_info->display_name; |
| @@ -152,23 +182,29 @@ | ||
| 152 | 182 | <select id="_negotiator_ids" name="_negotiator_ids[]" multiple="multiple" data-placeholder="' . esc_attr(__( 'Unaccompanied', 'propertyhive' )) . '" class="multiselect attribute_values">'; |
| 153 | 183 | |
| 154 | 184 | if ( isset($pagenow) && $pagenow == 'post-new.php' ) |
| 155 | 185 | { |
| 186 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 156 | 187 | $negotiator_ids = array( get_current_user_id() ); |
| 157 | 188 | } |
| 158 | 189 | |
| 190 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 159 | 191 | $args = array( |
| 160 | 192 | 'number' => 9999, |
| 161 | 193 | 'orderby' => 'display_name', |
| 194 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Legacy Property Negotiator compatibility filter; existing role filters depend on this exact public hook name. | |
| 162 | 195 | 'role__not_in' => apply_filters( 'property_negotiator_exclude_roles', array('property_hive_contact', 'subscriber') ) |
| 163 | 196 | ); |
| 164 | 197 | |
| 198 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 165 | 199 | $args = apply_filters( 'propertyhive_negotiators_query', $args ); |
| 166 | 200 | |
| 201 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 167 | 202 | $user_query = new WP_User_Query( $args ); |
| 168 | 203 | |
| 169 | 204 | if ( ! empty( $user_query->results ) ) |
| 170 | 205 | { |
| 206 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 171 | 207 | foreach ( $user_query->results as $user ) |
| 172 | 208 | { |
| 173 | 209 | echo '<option value="' . esc_attr($user->ID) . '"'; |
| 174 | 210 | if ( in_array($user->ID, $negotiator_ids) ) |
| @@ -233,25 +269,29 @@ | ||
| 233 | 269 | echo '</div>'; |
| 234 | 270 | |
| 235 | 271 | echo '</div>'; |
| 236 | 272 | |
| 237 | - if ( isset($_GET['viewing_id']) ) | |
| 273 | + $propertyhive_original_viewing_id = isset( $propertyhive_calendar_input['viewing_id'] ) && is_scalar( $propertyhive_calendar_input['viewing_id'] ) ? absint( $propertyhive_calendar_input['viewing_id'] ) : 0; | |
| 274 | + if ( $propertyhive_original_viewing_id > 0 ) | |
| 238 | 275 | { |
| 239 | - echo '<input type="hidden" name="_original_viewing_id" value="' . esc_attr((int)$_GET['viewing_id']) . '">'; | |
| 276 | + echo '<input type="hidden" name="_original_viewing_id" value="' . esc_attr( $propertyhive_original_viewing_id ) . '">'; | |
| 240 | 277 | } |
| 241 | 278 | |
| 242 | 279 | echo '<input type="hidden" name="_num_requiring_confirmation" id="_num_requiring_confirmation" value="">'; |
| 243 | 280 | |
| 281 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 244 | 282 | $previously_selected = array(); |
| 283 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 245 | 284 | $confirmed = get_post_meta( $post->ID, '_confirmed', true ); |
| 246 | 285 | if ( is_array($confirmed) && !empty($confirmed) ) |
| 247 | 286 | { |
| 287 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope. | |
| 248 | 288 | $previously_selected = $confirmed; |
| 249 | 289 | } |
| 250 | 290 | |
| 251 | 291 | echo '<script> |
| 252 | 292 | |
| 253 | - var previously_selected = ' . json_encode($previously_selected) . '; | |
| 293 | + var previously_selected = ' . wp_json_encode( $previously_selected, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ) . '; | |
| 254 | 294 | |
| 255 | 295 | jQuery(document).ready(function() |
| 256 | 296 | { |
| 257 | 297 | generate_confirmation_options(true); |
| @@ -311,9 +351,12 @@ | ||
| 311 | 351 | if ( options.length > 0 ) |
| 312 | 352 | { |
| 313 | 353 | for ( var i in options ) |
| 314 | 354 | { |
| 315 | - jQuery(\'.confirmations .ph-radios\').append(\'<li><label><input type="checkbox" class="checkbox" name="_confirmed[]" value="\' + options[i].id + \'"> \' + options[i].name + \'</label></li>\'); | |
| 355 | + var confirmation_label = jQuery(\'<label>\'); | |
| 356 | + confirmation_label.append(jQuery(\'<input>\', { type: \'checkbox\', class: \'checkbox\', name: \'_confirmed[]\' }).val(options[i].id)); | |
| 357 | + confirmation_label.append(document.createTextNode(\' \' + options[i].name)); | |
| 358 | + jQuery(\'.confirmations .ph-radios\').append(jQuery(\'<li>\').append(confirmation_label)); | |
| 316 | 359 | num_requiring_confirmation = num_requiring_confirmation + 1; |
| 317 | 360 | } |
| 318 | 361 | } |
| 319 | 362 | else |
| @@ -325,9 +368,9 @@ | ||
| 325 | 368 | |
| 326 | 369 | for ( var i in previously_selected ) |
| 327 | 370 | { |
| 328 | 371 | //console.log(previously_selected[i]); |
| 329 | - jQuery("input[name=\'_confirmed[]\'][value=\'" + previously_selected[i] + "\']").prop(\'checked\', true); | |
| 372 | + jQuery("input[name=\'_confirmed[]\']").filter(function() { return this.value == previously_selected[i]; }).prop(\'checked\', true); | |
| 330 | 373 | } |
| 331 | 374 | |
| 332 | 375 | jQuery(\'#_num_requiring_confirmation\').val(num_requiring_confirmation); |
| 333 | 376 | } |