Ticket #5500: date_field_patch#1_abweb.patch
| File date_field_patch#1_abweb.patch, 30.1 KB (added by , 11 years ago) |
|---|
-
wp-content/plugins/buddypress/bp-xprofile/bp-xprofile-admin.php
From 6fec22f53012e6dda8247087ba10f7cc0752b9f9 Mon Sep 17 00:00:00 2001 From: ialert <info@ialert.name> Date: Tue, 5 Apr 2016 10:36:46 +0300 Subject: [PATCH 1/2] Date xprofile field enhancement: dateSelector field type formed by 3 dropdowns && limit registration access by age e.g. --- .../buddypress/bp-xprofile/bp-xprofile-admin.php | 40 +++ .../bp-xprofile/bp-xprofile-functions.php | 2 +- .../buddypress/bp-xprofile/bp-xprofile-screens.php | 7 +- .../class-bp-xprofile-field-type-datebox.php | 359 ++++++++++++++++++--- .../classes/class-bp-xprofile-field.php | 36 +++ 5 files changed, 395 insertions(+), 49 deletions(-) diff --git a/wp-content/plugins/buddypress/bp-xprofile/bp-xprofile-admin.php b/wp-content/plugins/buddypress/bp-xprofile/bp-xprofile-admin.php index 47cf274..09c7876 100644
a b function xprofile_admin_delete_group( $group_id ) { 331 331 xprofile_admin( $message, $type ); 332 332 } 333 333 334 function xprofile_admin_manage_datebox_option($message) 335 { 336 if(empty($_POST['datebox_option'])) return; 337 338 $_POST['datebox_option'][0] = isset($_POST['datebox_option'][0]) ? 'yes' : 'no'; 339 $_POST['datebox_option'][1] = isset($_POST['datebox_option'][1]) ? 'yes' : 'no'; 340 341 $_POST['datebox_option'][2] = (isset($_POST['datebox_option'][2]) && $_POST['datebox_option'][2] == 'year') ? 'year' : 'ago'; 342 343 $message .= ($_POST['datebox_option'][3] == '') ? __( 'Field "Max years ago" - required! ', 'buddypress' ) : ''; 344 $_POST['datebox_option'][3] = 345 isset($_POST['datebox_option'][3]) ? mb_substr(abs(intval($_POST['datebox_option'][3])), 0, 4, 'UTF-8') : 100; 346 347 $message .= ($_POST['datebox_option'][4] == '') ? __( 'Field "Min years ago" - required! ', 'buddypress' ) : ''; 348 $_POST['datebox_option'][4] = 349 isset($_POST['datebox_option'][4]) ? mb_substr(intval($_POST['datebox_option'][4]), 0, 5, 'UTF-8') : 18; 350 351 $message .= ($_POST['datebox_option'][3] < $_POST['datebox_option'][4]) ? __( 'Wrong year range! ', 'buddypress' ) : ''; 352 353 $message .= ($_POST['datebox_option'][5] == '') ? __( 'Field "Erliest" - required! ', 'buddypress' ) : ''; 354 $_POST['datebox_option'][5] = (isset($_POST['datebox_option'][5])) 355 ? mb_substr(intval($_POST['datebox_option'][5]), 0, 5, 'UTF-8') : date("Y") - 100; 356 357 $message .= ($_POST['datebox_option'][5] == '') ? __( 'Field "Latest" - required! ', 'buddypress' ) : ''; 358 $_POST['datebox_option'][6] = (isset($_POST['datebox_option'][6])) 359 ? mb_substr(abs(intval($_POST['datebox_option'][6])), 0, 4, 'UTF-8') : date("Y") - 18; 360 361 $message .= ($_POST['datebox_option'][5] > $_POST['datebox_option'][6]) ? __( 'Wrong Erliest/Latest range! ', 'buddypress' ) : ''; 362 363 ksort($_POST['datebox_option'], SORT_NUMERIC); 364 reset($_POST['datebox_option']); 365 366 if(!empty($message)){ 367 $GLOBALS['message'] = $message; 368 } 369 } 370 334 371 /** 335 372 * Handles the adding or editing of profile field data for a user. 336 373 * … … function xprofile_admin_manage_field( $group_id, $field_id = null ) { 351 388 $field->group_id = $group_id; 352 389 353 390 if ( isset( $_POST['saveField'] ) ) { 391 392 xprofile_admin_manage_datebox_option($message); 393 354 394 if ( BP_XProfile_Field::admin_validate() ) { 355 395 $field->is_required = $_POST['required']; 356 396 $field->type = $_POST['fieldtype']; -
wp-content/plugins/buddypress/bp-xprofile/bp-xprofile-functions.php
diff --git a/wp-content/plugins/buddypress/bp-xprofile/bp-xprofile-functions.php b/wp-content/plugins/buddypress/bp-xprofile/bp-xprofile-functions.php index 0996257..1b059f7 100644
a b function xprofile_set_field_data( $field, $user_id, $value, $is_required = false 434 434 } 435 435 436 436 // For certain fields, only certain parameters are acceptable, so add them to the whitelist. 437 if ( $field_type_obj->supports_options ) {437 if ( $field_type_obj->supports_options && $field_type_obj->name != 'Date Selector' ) { 438 438 $field_type_obj->set_whitelist_values( wp_list_pluck( $field->get_children(), 'name' ) ); 439 439 } 440 440 -
wp-content/plugins/buddypress/bp-xprofile/bp-xprofile-screens.php
diff --git a/wp-content/plugins/buddypress/bp-xprofile/bp-xprofile-screens.php b/wp-content/plugins/buddypress/bp-xprofile/bp-xprofile-screens.php index 103e24e..91bcd93 100644
a b function xprofile_screen_edit_profile() { 91 91 92 92 if ( !empty( $_POST['field_' . $field_id . '_day'] ) && !empty( $_POST['field_' . $field_id . '_month'] ) && !empty( $_POST['field_' . $field_id . '_year'] ) ) { 93 93 // Concatenate the values. 94 $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year']; 94 $eng_months = array( 1=>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ); 95 $_POST['field_' . $field_id . '_month'] = array_search($_POST['field_' . $field_id . '_month'], $eng_months); 96 $date_value = $_POST['field_' . $field_id . '_year'] . '-' . $_POST['field_' . $field_id . '_month'] . '-' . $_POST['field_' . $field_id . '_day']; 95 97 96 98 // Turn the concatenated value into a timestamp. 97 $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) ); 99 $date = new DateTime($date_value); 100 $_POST['field_' . $field_id] = $date->format('Y-m-d H:i:s'); 98 101 } 99 102 100 103 } -
wp-content/plugins/buddypress/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php
diff --git a/wp-content/plugins/buddypress/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php b/wp-content/plugins/buddypress/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php index 5869f26..1b3c049 100644
a b class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 28 28 $this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' ); 29 29 $this->name = _x( 'Date Selector', 'xprofile field type', 'buddypress' ); 30 30 31 $this->supports_options = true; # This parameter - added 32 31 33 $this->set_format( '/^\d{4}-\d{1,2}-\d{1,2} 00:00:00$/', 'replace' ); // "Y-m-d 00:00:00" 32 34 33 35 /** … … class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 97 99 * 98 100 * @since 1.8.0 99 101 */ 100 do_action( bp_get_the_profile_field_errors_action() ); ?> 101 102 <label for="<?php bp_the_profile_field_input_name(); ?>_day" class="bp-screen-reader-text"><?php esc_html_e( 'Select day', 'buddypress' ); ?></label> 103 <select <?php echo $this->get_edit_field_html_elements( $day_r ); ?>> 104 <?php bp_the_profile_field_options( array( 105 'type' => 'day', 106 'user_id' => $user_id 107 ) ); ?> 108 </select> 109 110 <label for="<?php bp_the_profile_field_input_name(); ?>_month" class="bp-screen-reader-text"><?php esc_html_e( 'Select month', 'buddypress' ); ?></label> 111 <select <?php echo $this->get_edit_field_html_elements( $month_r ); ?>> 112 <?php bp_the_profile_field_options( array( 113 'type' => 'month', 114 'user_id' => $user_id 115 ) ); ?> 116 </select> 117 118 <label for="<?php bp_the_profile_field_input_name(); ?>_year" class="bp-screen-reader-text"><?php esc_html_e( 'Select year', 'buddypress' ); ?></label> 119 <select <?php echo $this->get_edit_field_html_elements( $year_r ); ?>> 120 <?php bp_the_profile_field_options( array( 121 'type' => 'year', 122 'user_id' => $user_id 123 ) ); ?> 124 </select> 102 do_action( bp_get_the_profile_field_errors_action() ); 103 104 ob_start(); 105 ?> 106 <select <?php echo $this->get_edit_field_html_elements($day_r); ?>> 107 <?php bp_the_profile_field_options(array( 108 'type' => 'day', 109 'user_id' => $user_id, 110 ));?> 111 </select> 112 <?php 125 113 114 $selectDay = ob_get_contents(); 115 ob_end_clean(); 116 117 ob_start(); 118 ?> 119 <select <?php echo $this->get_edit_field_html_elements($month_r); ?>> 120 <?php bp_the_profile_field_options(array( 121 'type' => 'month', 122 'user_id' => $user_id, 123 ));?> 124 </select> 125 <?php 126 127 $selectMonth = ob_get_contents(); 128 ob_end_clean(); 129 130 ob_start(); 131 ?> 132 <select <?php echo $this->get_edit_field_html_elements($year_r); ?>> 133 <?php bp_the_profile_field_options(array( 134 'type' => 'year', 135 'user_id' => $user_id, 136 ));?> 137 138 </select> 139 <?php 140 $selectYear = ob_get_contents(); 141 ob_end_clean(); 142 143 // Change the location of selects, depending on the "date_format" 144 $format = get_option('date_format', 'd/m/Y'); 145 146 switch ($format) { 147 case 'm/d/Y'; #m/d/Y 148 case 'm-d-Y'; 149 case 'm.d.Y'; 150 echo $selectMonth; 151 echo $selectDay; 152 echo $selectYear; 153 break; 154 155 case 'd/m/Y'; #d/m/Y 156 case 'd-m-Y'; 157 case 'd.m.Y'; 158 echo $selectDay; 159 echo $selectMonth; 160 echo $selectYear; 161 break; 162 163 default; #Y-m-d 164 echo $selectYear; 165 echo $selectMonth; 166 echo $selectDay; 167 break; 168 } 169 170 ?> 126 171 </div> 127 172 <?php 128 173 } … … class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 162 207 163 208 // If MySQL timestamp. 164 209 } else { 165 $day = mysql2date( 'j', $date ); 166 $month = mysql2date( 'F', $date, false ); // Not localized, so that selected() works below. 167 $year = mysql2date( 'Y', $date ); 210 $DT = new DateTime($date); // problem 2038 year http://php.net/manual/en/class.datetime.php 211 $day = $DT->format('j'); 212 $month = $DT->format('F'); 213 $year = $DT->format('Y'); 168 214 } 169 215 } 170 216 … … class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 226 272 case 'year': 227 273 $html = sprintf( '<option value="" %1$s>%2$s</option>', selected( $year, 0, false ), /* translators: no option picked in select box */ __( '----', 'buddypress' ) ); 228 274 229 for ( $i = 2037; $i > 1901; $i-- ) { 230 $html .= sprintf( '<option value="%1$s" %2$s>%3$s</option>', (int) $i, selected( $year, $i, false ), (int) $i ); 275 276 $ord = get_option('BPOptRegData'); 277 $ord = unserialize($ord); 278 $opt = $this->field_obj->get_children(); 279 280 281 if(isset($opt[2]->name)){ 282 $ord['range-curr'] = ($opt[2]->name == 'year') ? 'year' : 'ago'; 283 } else { 284 $ord['range-curr'] = 'ago'; 285 } 286 287 if(isset($opt[3]->name)) { 288 $ord['range-year']['ago']['max'] = $opt[3]->name; 231 289 } 290 291 if(isset($opt[4]->name)){ 292 $ord['range-year']['ago']['min'] = $opt[4]->name; 293 } 294 295 if(isset($opt[5]->name)){ 296 $ord['range-year']['year']['earliest'] = $opt[5]->name; 297 } 298 299 if(isset($opt[6]->name)){ 300 $ord['range-year']['year']['latest'] = $opt[6]->name; 301 } 302 303 if($ord['range-curr'] == 'ago'){ 304 $ord['range-year']['year']['latest'] = date("Y") - $ord['range-year']['ago']['min']; 305 $ord['range-year']['year']['earliest'] = date("Y") - $ord['range-year']['ago']['max']; 306 } 307 308 for ( $i = $ord['range-year']['year']['latest']; $i > ($ord['range-year']['year']['earliest']-1); $i-- ) { 309 $html .= sprintf( '<option value="%1$s" %2$s>%3$s</option>', (int) $i, selected( $year, $i, false ), (int) $i ); 310 } 232 311 break; 233 312 } 234 313 … … class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 272 351 $year_r = bp_parse_args( $raw_properties, array( 273 352 'id' => bp_get_the_profile_field_input_name() . '_year', 274 353 'name' => bp_get_the_profile_field_input_name() . '_year' 275 ) ); ?> 276 277 <label for="<?php bp_the_profile_field_input_name(); ?>_day" class="screen-reader-text"><?php esc_html_e( 'Select day', 'buddypress' ); ?></label> 278 <select <?php echo $this->get_edit_field_html_elements( $day_r ); ?>> 279 <?php bp_the_profile_field_options( array( 'type' => 'day' ) ); ?> 280 </select> 354 ) ); 355 356 // Change the location of selects, depending on the "date_format" 357 358 ob_start(); 359 ?> 360 <select <?php echo $this->get_edit_field_html_elements( $day_r ); ?>> 361 <?php bp_the_profile_field_options( array( 'type' => 'day' ) ); ?> 362 </select> 363 <?php 364 $selectDay = ob_get_contents(); 365 ob_end_clean(); 366 367 ob_start(); 368 ?> 369 <select <?php echo $this->get_edit_field_html_elements( $month_r ); ?>> 370 <?php bp_the_profile_field_options( array( 'type' => 'month' ) ); ?> 371 </select> 372 <?php 373 $selectMonth = ob_get_contents(); 374 ob_end_clean(); 375 376 ob_start(); 377 ?> 378 <select <?php echo $this->get_edit_field_html_elements( $year_r ); ?>> 379 <?php bp_the_profile_field_options( array( 'type' => 'year' ) ); ?> 380 </select> 381 <?php 382 $selectYear = ob_get_contents(); 383 ob_end_clean(); 384 385 // Change the location of selects, depending on the "date_format" 386 387 $format = get_option('date_format', 'd/m/Y'); 388 389 switch($format) 390 { 391 case 'm/d/Y';#m/d/Y 392 case 'm-d-Y'; 393 case 'm.d.Y'; 394 echo $selectMonth; 395 echo $selectDay; 396 echo $selectYear; 397 break; 398 399 case 'd/m/Y'; #d/m/Y 400 case 'd-m-Y'; 401 case 'd.m.Y'; 402 echo $selectDay; 403 echo $selectMonth; 404 echo $selectYear; 405 break; 406 407 default; #Y-m-d 408 echo $selectYear; 409 echo $selectMonth; 410 echo $selectDay; 411 break; 412 } 281 413 282 <label for="<?php bp_the_profile_field_input_name(); ?>_month" class="screen-reader-text"><?php esc_html_e( 'Select month', 'buddypress' ); ?></label> 283 <select <?php echo $this->get_edit_field_html_elements( $month_r ); ?>> 284 <?php bp_the_profile_field_options( array( 'type' => 'month' ) ); ?> 285 </select> 414 ?> 286 415 287 <label for="<?php bp_the_profile_field_input_name(); ?>_year" class="screen-reader-text"><?php esc_html_e( 'Select year', 'buddypress' ); ?></label>288 <select <?php echo $this->get_edit_field_html_elements( $year_r ); ?>>289 <?php bp_the_profile_field_options( array( 'type' => 'year' ) ); ?>290 </select>291 416 292 417 <?php 293 418 } … … class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 302 427 * @param string $control_type Optional. HTML input type used to render the current 303 428 * field's child options. 304 429 */ 305 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} 430 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) { 431 //parent::admin_new_field_html( $current_field, 'checkbox' ); 432 $type = array_search( get_class( $this ), bp_xprofile_get_field_types() ); 433 434 if ( false === $type ) { 435 return; 436 } 437 438 $class = $current_field->type != $type ? 'display: none;' : ''; 439 $current_type_obj = bp_xprofile_create_field_type( $type ); 440 $SET = $current_field->BPOptRegData; 441 $SET = unserialize($SET); 442 $OPT = $current_field->get_children( true ); 443 444 ?> 445 446 <div id="<?php echo esc_attr( $type ); ?>" class="postbox bp-options-box" style="<?php echo esc_attr( $class ); ?> margin-top: 15px;"> 447 <h3><?php esc_html_e( 'Please enter options for this Field:', 'buddypress' ); ?></h3> 448 449 <div class="inside"> 450 451 <div id="datebox_div1" class="bp-option sortable"> 452 453 <?php /*input type="text" name="datebox_option[0]" id="datebox_option1" value="value"/*/ ?> 454 455 <label> 456 <input type="checkbox" name="datebox_option[0]" 457 <?= ($OPT[0]->name == 'yes') ? ' checked="checked" ' : 458 ($SET['show-year'] == 'yes' && empty($OPT) ? ' checked="checked" ' : ''); ?> value="yes"/> 459 Show year (if unchecked then profile will show only date and month) 460 </label> 461 462 <br /> 463 <label> 464 <input type="checkbox" name="datebox_option[1]" 465 <?= ($SET['show-time'] == 'yes' OR $OPT[1]->name == 'yes') ? ' checked="checked" ' : ''; ?> value="yes"/> 466 Show time lapsed instead of date , e.g. show age (overrides show year) 467 </label> 468 469 <br /> 470 <table> 471 <tr> 472 <td>Year range</td> 473 <td><input type="radio" name="datebox_option[2]" value="ago" 474 <?= ($SET['range-curr'] == 'ago' OR $OPT[2]->name == 'ago') ? ' checked="checked" ' : ''; ?> /></td> 475 <td> 476 Max <input type="text" name="datebox_option[3]" size="3" maxlength="4" 477 value="<?= isset($OPT[3]->name) ? $OPT[3]->name : $SET['range-year']['ago']['max']; ?>" /> years ago, 478 </td> 479 <td> 480 Min <input type="text" name="datebox_option[4]" size="3" maxlength="5" 481 value="<?= isset($OPT[4]->name) ? $OPT[4]->name : $SET['range-year']['ago']['min']; ?>" /> years ago 482 </td> 483 </tr> 484 <tr> 485 <td></td> 486 <td><input type="radio" name="datebox_option[2]" value="year" 487 <?= ($SET['range-curr'] == 'year' OR $OPT[2]->name == 'year') ? ' checked="checked" ' : ''; ?> /></td> 488 <td> 489 Earliest <input type="text" name="datebox_option[5]" size="3" maxlength="5" 490 value="<?= isset($OPT[5]->name) ? $OPT[5]->name : $SET['range-year']['year']['earliest']; ?>" /> 491 </td> 492 <td> 493 Latest <input type="text" name="datebox_option[6]" size="3" maxlength="4" 494 value="<?= isset($OPT[6]->name) ? $OPT[6]->name : $SET['range-year']['year']['latest']; ?>" /> 495 </td> 496 </tr> 497 <tr> 498 <td></td> 499 <td colspan="3"><b>Note</b>: Year range is allowed between 1902 and 2037 years only.</td> 500 </tr> 501 </table> 502 503 </div> 504 505 <input type="hidden" name="datebox_option_number" id="datebox_option_number" value="7"/> 506 <input type="hidden" name="sort_order_datebox" id="sort_order_datebox" value="custom"/> 507 508 <?php /*div id="datebox_more"></div> 509 <p><a href="javascript:add_option('datebox')">Add Another Option</a></p*/ ?> 510 </div> 511 </div> 512 513 <?php 514 } 306 515 307 516 /** 308 517 * Format Date values for display. … … class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 322 531 $field_value = strtotime( $field_value ); 323 532 } 324 533 325 return bp_format_time( $field_value, true, false ); 534 global $wpdb, $bp; 535 $option = unserialize(get_option( 'BPOptRegData')); 536 //$uid = bp_displayed_user_id(); 537 $parent_id = isset($GLOBALS['field']->id) ? $GLOBALS['field']->id : false; 538 $group_id = isset($GLOBALS['field']->group_id) ? $GLOBALS['field']->group_id : false; 539 $sort_sql = 'ORDER BY option_order ASC'; 540 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE parent_id = %d AND group_id = %d $sort_sql", $parent_id, $group_id ); 541 $opt = $wpdb->get_results( $sql ); 542 543 if(isset($opt[0]) && isset($opt[1])){ 544 $option['show-year'] = $opt[0]->name; 545 $option['show-time'] = $opt[1]->name; 546 } 547 548 549 if($option['show-time'] == 'yes'){ 550 $field_value = self::formatDateByBPOptRegData($field_value, true, true); 551 552 }elseif($option['show-year'] == 'no'){ 553 $field_value = self::formatDateByBPOptRegData($field_value, true, false); 554 555 }else{// 556 $field_value = bp_format_time( $field_value, true, false ); 557 } 558 559 return $field_value; 326 560 } 561 562 private function formatDateByBPOptRegData( $time, $localize_time = true, $show) { 563 564 if ( ! isset( $time ) || ! is_numeric( $time ) ) { 565 return false; 566 } 567 568 if ( ! empty( $localize_time ) ) { 569 $root_blog_offset = get_blog_option( bp_get_root_blog_id(), 'gmt_offset' ); 570 }else{ 571 $root_blog_offset = false; 572 } 573 574 $time_offset = $time + ( $root_blog_offset * 3600 ); 575 $format = get_option( 'date_format' ); 576 577 if($show === false){ 578 $format = str_replace( 579 array( '/Y', 'Y/', '/y', 'y/', ' Y', 'Y ', ' y', 'y ', '.Y', 'Y.', '.y', 'y.', '-Y', 'Y-', '-y', 'y-', 'Y', 'y'), '', $format 580 ); 581 582 $date = date_i18n($format, $time_offset ); 583 584 }else{ // Here we calculate the number of years 585 586 $time_curr = time(); 587 $def = $time_curr - $time_offset; 588 $date = floor($def / (60*60*24*365)); 589 $date = ' ' . $date . __(' years', 'buddypress'); 590 } 591 592 return $date; 593 } 327 594 } -
wp-content/plugins/buddypress/bp-xprofile/classes/class-bp-xprofile-field.php
diff --git a/wp-content/plugins/buddypress/bp-xprofile/classes/class-bp-xprofile-field.php b/wp-content/plugins/buddypress/bp-xprofile/classes/class-bp-xprofile-field.php index c24db3f..a1336dd 100644
a b class BP_XProfile_Field { 162 162 */ 163 163 protected $member_types; 164 164 165 166 167 public $BPOptRegData = array(); 168 165 169 /** 166 170 * Initialize and/or populate profile field. 167 171 * … … class BP_XProfile_Field { 181 185 $this->type_obj = bp_xprofile_create_field_type( 'textbox' ); 182 186 $this->type_obj->field_obj = $this; 183 187 } 188 189 $this->BPOptRegData = $this->runCheckBPOptRegDate(); 190 } 191 192 193 public function runCheckBPOptRegDate() 194 { 195 196 197 $BPOptRegData = get_option('BPOptRegData'); 198 199 if($BPOptRegData === false){ 200 201 $serialize = serialize( 202 array( 203 'show-year' => 'yes', 204 'show-time' => 'no', 205 'range-curr' => 'ago', 206 'range-year' => array( 207 'ago' => array('min' => 18, 'max' => 100), 208 'year' => array('earliest' => (date("Y")-101), 'latest' => (date("Y")-18)) 209 ) 210 ) 211 ); 212 213 add_option('BPOptRegData', $serialize, '', 'no'); 214 215 return $serialize; 216 217 } else { 218 return $BPOptRegData; 219 } 184 220 } 185 221 186 222 /** -
wp-content/plugins/buddypress/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php
-- 1.9.1 From 8263e16340f25aa17cca19d206a52f951b1e5235 Mon Sep 17 00:00:00 2001 From: ialert <info@ialert.name> Date: Wed, 6 Apr 2016 13:16:43 +0300 Subject: [PATCH 2/2] patch update: add format date choose options on add/edit screen --- .../class-bp-xprofile-field-type-datebox.php | 92 +++++++++++++++------- .../classes/class-bp-xprofile-field.php | 3 +- 2 files changed, 67 insertions(+), 28 deletions(-) diff --git a/wp-content/plugins/buddypress/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php b/wp-content/plugins/buddypress/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php index 1b3c049..5bca409 100644
a b class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 452 452 453 453 <?php /*input type="text" name="datebox_option[0]" id="datebox_option1" value="value"/*/ ?> 454 454 455 <label> 456 <input type="checkbox" name="datebox_option[0]" 457 <?= ($OPT[0]->name == 'yes') ? ' checked="checked" ' : 458 ($SET['show-year'] == 'yes' && empty($OPT) ? ' checked="checked" ' : ''); ?> value="yes"/> 459 Show year (if unchecked then profile will show only date and month) 460 </label> 455 456 <h3>Date format</h3> 457 458 <?php 461 459 462 <br /> 460 $date_formats = array_unique( apply_filters( 'date_formats', array( __( 'F j, Y' ), 'Y-m-d', 'm/d/Y', 'd/m/Y' ) ) ); 461 ?> 462 <?php if(!empty($date_formats)): ?> 463 <?php $custom_format = true; ?> 464 <?php foreach ( $date_formats as $format ): ?> 465 <?php 466 $checked = ''; 467 468 if($OPT[7]->name == $format) { 469 $checked = 'checked'; 470 $custom_format = false; 471 } 472 473 ?> 474 <label title='<?=esc_attr($format); ?>'><input <?=$checked; ?> type='radio' name='datebox_option[7]' value='<?= esc_attr($format); ?>' /><?=date_i18n( $format );?></label><br /> 475 <?php endforeach;?> 476 <? endif; ?> 477 478 <label> 479 <input type="radio" <?=($custom_format)? 'checked': ''; ?> value="custom" id="date_format_custom_radio" name="datebox_option[7]"> Custom:<span class="screen-reader-text" style="cursor: move;"> enter a custom date format in the following field</span> 480 </label> 481 <input type="text" style="width: 80px;" class="small-text" value='<?= esc_attr($OPT[7]->name); ?>' id="date_format_custom" name="date_format_custom"> 482 <span class="screen-reader-text"><? _e( 'example:' ) ;?> </span><span class="example"><?=date_i18n( $OPT[7]->name );?></span> <span class='spinner'></span> 483 <br /><br /> 463 484 <label> 464 485 <input type="checkbox" name="datebox_option[1]" 465 486 <?= ($SET['show-time'] == 'yes' OR $OPT[1]->name == 'yes') ? ' checked="checked" ' : ''; ?> value="yes"/> 466 487 Show time lapsed instead of date , e.g. show age (overrides show year) 467 </label> 468 469 <br /> 470 <table> 488 </label> 489 <table> 471 490 <tr> 472 491 <td>Year range</td> 473 492 <td><input type="radio" name="datebox_option[2]" value="ago" … … class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 502 521 503 522 </div> 504 523 505 <input type="hidden" name="datebox_option_number" id="datebox_option_number" value=" 7"/>524 <input type="hidden" name="datebox_option_number" id="datebox_option_number" value="8"/> 506 525 <input type="hidden" name="sort_order_datebox" id="sort_order_datebox" value="custom"/> 507 526 508 527 <?php /*div id="datebox_more"></div> 509 528 <p><a href="javascript:add_option('datebox')">Add Another Option</a></p*/ ?> 510 529 </div> 511 530 </div> 531 <script> 532 jQuery(document).ready(function($) { 533 $("input[name='date_format']").click(function(){ 534 if ( "date_format_custom_radio" != $(this).attr("id") ) 535 $( "input[name='date_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).text() ); 536 }); 537 538 $("input[name='date_format_custom']").focus(function(){ 539 $( '#date_format_custom_radio' ).prop( 'checked', true ); 540 }); 541 542 $("input[name='date_format_custom'], input[name='time_format_custom']").change( function() { 543 var format = $(this); 544 $('#date_format_custom_radio' ).val(format.val()); 545 format.siblings( '.spinner' ).addClass( 'is-active' ); 546 $.post(ajaxurl, { 547 action: 'date_format_custom' == format.attr('name') ? 'date_format' : 'time_format', 548 date : format.val() 549 }, function(d) { 550 format.siblings( '.spinner' ).removeClass( 'is-active' ); format.siblings('.example').text(d); 551 552 } ); 553 }); 554 }); 555 </script> 512 556 513 557 <?php 514 558 } … … class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 534 578 global $wpdb, $bp; 535 579 $option = unserialize(get_option( 'BPOptRegData')); 536 580 //$uid = bp_displayed_user_id(); 537 $parent_id = isset($GLOBALS['field']->id) ? $GLOBALS['field']->id : false; 538 $group_id = isset($GLOBALS['field']->group_id) ? $GLOBALS['field']->group_id : false; 581 $parent_id = isset($GLOBALS['field']->id) ? $GLOBALS['field']->id : $field_id; 539 582 $sort_sql = 'ORDER BY option_order ASC'; 540 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE parent_id = %d AND group_id = %d $sort_sql", $parent_id, $group_id);583 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE parent_id = %d $sort_sql", $parent_id); 541 584 $opt = $wpdb->get_results( $sql ); 542 585 586 $option['date-format'] = $opt[7]->name; 587 543 588 if(isset($opt[0]) && isset($opt[1])){ 544 589 $option['show-year'] = $opt[0]->name; 545 590 $option['show-time'] = $opt[1]->name; … … class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 547 592 548 593 549 594 if($option['show-time'] == 'yes'){ 550 $field_value = self::formatDateByBPOptRegData($field_value, true, true);595 $field_value = self::formatDateByBPOptRegData($field_value,$option, true, true); 551 596 552 }elseif($option['show-year'] == 'no'){ 553 $field_value = self::formatDateByBPOptRegData($field_value, true, false); 554 555 }else{// 556 $field_value = bp_format_time( $field_value, true, false ); 597 }else { 598 $field_value = self::formatDateByBPOptRegData($field_value,$option, true, false); 557 599 } 558 600 559 601 return $field_value; 560 602 } 561 603 562 private function formatDateByBPOptRegData( $time, $ localize_time = true, $show) {604 private function formatDateByBPOptRegData( $time, $option,$localize_time = true, $show) { 563 605 564 606 if ( ! isset( $time ) || ! is_numeric( $time ) ) { 565 607 return false; … … class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 572 614 } 573 615 574 616 $time_offset = $time + ( $root_blog_offset * 3600 ); 575 $format = get_option( 'date_format' );576 617 577 618 if($show === false){ 578 $format = str_replace(579 array( '/Y', 'Y/', '/y', 'y/', ' Y', 'Y ', ' y', 'y ', '.Y', 'Y.', '.y', 'y.', '-Y', 'Y-', '-y', 'y-', 'Y', 'y'), '', $format580 );581 619 582 $date = date_i18n($ format, $time_offset );620 $date = date_i18n($option['date-format'], $time_offset ); 583 621 584 622 }else{ // Here we calculate the number of years 585 623 -
wp-content/plugins/buddypress/bp-xprofile/classes/class-bp-xprofile-field.php
diff --git a/wp-content/plugins/buddypress/bp-xprofile/classes/class-bp-xprofile-field.php b/wp-content/plugins/buddypress/bp-xprofile/classes/class-bp-xprofile-field.php index a1336dd..502030f 100644
a b class BP_XProfile_Field { 206 206 'range-year' => array( 207 207 'ago' => array('min' => 18, 'max' => 100), 208 208 'year' => array('earliest' => (date("Y")-101), 'latest' => (date("Y")-18)) 209 ) 209 ), 210 'date-format' => "Y-m-d", 210 211 ) 211 212 ); 212 213
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)