| 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 ); |
| | 232 | |
| | 233 | $ord = get_option('BPOptRegData'); |
| | 234 | $ord = unserialize($ord); |
| | 235 | $opt = $this->field_obj->get_children(); |
| | 236 | |
| | 237 | |
| | 238 | if(isset($opt[2]->name)){ |
| | 239 | $ord['range-curr'] = ($opt[2]->name == 'year') ? 'year' : 'ago'; |
| | 240 | } else { |
| | 241 | $ord['range-curr'] = 'ago'; |
| | 242 | } |
| | 243 | |
| | 244 | if(isset($opt[3]->name)) { |
| | 245 | $ord['range-year']['ago']['max'] = $opt[3]->name; |
| | 246 | } |
| | 247 | |
| | 248 | if(isset($opt[4]->name)){ |
| | 249 | $ord['range-year']['ago']['min'] = $opt[4]->name; |
| | 250 | } |
| | 251 | |
| | 252 | if(isset($opt[5]->name)){ |
| | 253 | $ord['range-year']['year']['earliest'] = $opt[5]->name; |
| | 254 | } |
| | 255 | |
| | 256 | if(isset($opt[6]->name)){ |
| | 257 | $ord['range-year']['year']['latest'] = $opt[6]->name; |
| | 258 | } |
| | 259 | |
| | 260 | if($ord['range-curr'] == 'ago'){ |
| | 261 | $ord['range-year']['year']['latest'] = date("Y") - $ord['range-year']['ago']['min']; |
| | 262 | $ord['range-year']['year']['earliest'] = date("Y") - $ord['range-year']['ago']['max']; |
| 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> |
| | 313 | // Change the location of selects, depending on the "date_format" |
| | 314 | |
| | 315 | ob_start(); |
| | 316 | ?> |
| | 317 | <select <?php echo $this->get_edit_field_html_elements( $day_r ); ?>> |
| | 318 | <?php bp_the_profile_field_options( array( 'type' => 'day' ) ); ?> |
| | 319 | </select> |
| | 320 | <?php |
| | 321 | $selectDay = ob_get_contents(); |
| | 322 | ob_end_clean(); |
| | 323 | |
| | 324 | ob_start(); |
| | 325 | ?> |
| | 326 | <select <?php echo $this->get_edit_field_html_elements( $month_r ); ?>> |
| | 327 | <?php bp_the_profile_field_options( array( 'type' => 'month' ) ); ?> |
| | 328 | </select> |
| | 329 | <?php |
| | 330 | $selectMonth = ob_get_contents(); |
| | 331 | ob_end_clean(); |
| | 332 | |
| | 333 | ob_start(); |
| | 334 | ?> |
| | 335 | <select <?php echo $this->get_edit_field_html_elements( $year_r ); ?>> |
| | 336 | <?php bp_the_profile_field_options( array( 'type' => 'year' ) ); ?> |
| | 337 | </select> |
| | 338 | <?php |
| | 339 | $selectYear = ob_get_contents(); |
| | 340 | ob_end_clean(); |
| | 341 | |
| | 342 | // Change the location of selects, depending on the "date_format" |
| | 343 | |
| | 344 | $format = get_option('date_format', 'd/m/Y'); |
| | 345 | |
| | 346 | switch($format) |
| | 347 | { |
| | 348 | case 'm/d/Y';#m/d/Y |
| | 349 | case 'm-d-Y'; |
| | 350 | case 'm.d.Y'; |
| | 351 | echo $selectMonth; |
| | 352 | echo $selectDay; |
| | 353 | echo $selectYear; |
| | 354 | break; |
| | 355 | |
| | 356 | case 'd/m/Y'; #d/m/Y |
| | 357 | case 'd-m-Y'; |
| | 358 | case 'd.m.Y'; |
| | 359 | echo $selectDay; |
| | 360 | echo $selectMonth; |
| | 361 | echo $selectYear; |
| | 362 | break; |
| | 363 | |
| | 364 | default; #Y-m-d |
| | 365 | echo $selectYear; |
| | 366 | echo $selectMonth; |
| | 367 | echo $selectDay; |
| | 368 | break; |
| | 369 | } |
| 305 | | public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} |
| | 387 | public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) { |
| | 388 | //parent::admin_new_field_html( $current_field, 'checkbox' ); |
| | 389 | $type = array_search( get_class( $this ), bp_xprofile_get_field_types() ); |
| | 390 | |
| | 391 | if ( false === $type ) { |
| | 392 | return; |
| | 393 | } |
| | 394 | |
| | 395 | $class = $current_field->type != $type ? 'display: none;' : ''; |
| | 396 | $current_type_obj = bp_xprofile_create_field_type( $type ); |
| | 397 | $SET = $current_field->BPOptRegData; |
| | 398 | $SET = unserialize($SET); |
| | 399 | $OPT = $current_field->get_children( true ); |
| | 400 | |
| | 401 | ?> |
| | 402 | |
| | 403 | <div id="<?php echo esc_attr( $type ); ?>" class="postbox bp-options-box" style="<?php echo esc_attr( $class ); ?> margin-top: 15px;"> |
| | 404 | <h3><?php esc_html_e( 'Please enter options for this Field:', 'buddypress' ); ?></h3> |
| | 405 | |
| | 406 | <div class="inside"> |
| | 407 | |
| | 408 | <div id="datebox_div1" class="bp-option sortable"> |
| | 409 | |
| | 410 | <?php /*input type="text" name="datebox_option[0]" id="datebox_option1" value="value"/*/ ?> |
| | 411 | |
| | 412 | |
| | 413 | <h3>Date format</h3> |
| | 414 | |
| | 415 | <?php |
| | 416 | |
| | 417 | $date_formats = array_unique( apply_filters( 'date_formats', array( __( 'F j, Y' ), 'Y-m-d', 'm/d/Y', 'd/m/Y' ) ) ); |
| | 418 | ?> |
| | 419 | <?php if(!empty($date_formats)): ?> |
| | 420 | <?php $custom_format = true; ?> |
| | 421 | <?php foreach ( $date_formats as $format ): ?> |
| | 422 | <?php |
| | 423 | $checked = ''; |
| | 424 | |
| | 425 | if($OPT[7]->name == $format) { |
| | 426 | $checked = 'checked'; |
| | 427 | $custom_format = false; |
| | 428 | } |
| | 429 | |
| | 430 | ?> |
| | 431 | <label title='<?=esc_attr($format); ?>'><input <?=$checked; ?> type='radio' name='datebox_option[7]' value='<?= esc_attr($format); ?>' /><?=date_i18n( $format );?></label><br /> |
| | 432 | <?php endforeach;?> |
| | 433 | <?php endif; ?> |
| | 434 | |
| | 435 | <label> |
| | 436 | <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> |
| | 437 | </label> |
| | 438 | <input type="text" style="width: 80px;" class="small-text" value='<?= esc_attr($OPT[7]->name); ?>' id="date_format_custom" name="date_format_custom"> |
| | 439 | <span class="screen-reader-text"><? _e( 'example:' ) ;?> </span><span class="example"><?=date_i18n( $OPT[7]->name );?></span> <span class='spinner'></span> |
| | 440 | <br /><br /> |
| | 441 | <label> |
| | 442 | <input type="checkbox" name="datebox_option[1]" |
| | 443 | <?= ($SET['show-time'] == 'yes' OR $OPT[1]->name == 'yes') ? ' checked="checked" ' : ''; ?> value="yes"/> |
| | 444 | Show time lapsed instead of date , e.g. show age (overrides show year) |
| | 445 | </label> |
| | 446 | <table> |
| | 447 | <tr> |
| | 448 | <td>Year range</td> |
| | 449 | <td><input type="radio" name="datebox_option[2]" value="ago" |
| | 450 | <?= ($SET['range-curr'] == 'ago' OR $OPT[2]->name == 'ago') ? ' checked="checked" ' : ''; ?> /></td> |
| | 451 | <td> |
| | 452 | Max <input type="text" name="datebox_option[3]" size="3" maxlength="4" |
| | 453 | value="<?= isset($OPT[3]->name) ? $OPT[3]->name : $SET['range-year']['ago']['max']; ?>" /> years ago, |
| | 454 | </td> |
| | 455 | <td> |
| | 456 | Min <input type="text" name="datebox_option[4]" size="3" maxlength="5" |
| | 457 | value="<?= isset($OPT[4]->name) ? $OPT[4]->name : $SET['range-year']['ago']['min']; ?>" /> years ago |
| | 458 | </td> |
| | 459 | </tr> |
| | 460 | <tr> |
| | 461 | <td></td> |
| | 462 | <td><input type="radio" name="datebox_option[2]" value="year" |
| | 463 | <?= ($SET['range-curr'] == 'year' OR $OPT[2]->name == 'year') ? ' checked="checked" ' : ''; ?> /></td> |
| | 464 | <td> |
| | 465 | Earliest <input type="text" name="datebox_option[5]" size="3" maxlength="5" |
| | 466 | value="<?= isset($OPT[5]->name) ? $OPT[5]->name : $SET['range-year']['year']['earliest']; ?>" /> |
| | 467 | </td> |
| | 468 | <td> |
| | 469 | Latest <input type="text" name="datebox_option[6]" size="3" maxlength="4" |
| | 470 | value="<?= isset($OPT[6]->name) ? $OPT[6]->name : $SET['range-year']['year']['latest']; ?>" /> |
| | 471 | </td> |
| | 472 | </tr> |
| | 473 | <tr> |
| | 474 | <td></td> |
| | 475 | <td colspan="3"><b>Note</b>: Year range is allowed between 1902 and 2037 years only.</td> |
| | 476 | </tr> |
| | 477 | </table> |
| | 478 | |
| | 479 | </div> |
| | 480 | |
| | 481 | <input type="hidden" name="datebox_option_number" id="datebox_option_number" value="8"/> |
| | 482 | <input type="hidden" name="sort_order_datebox" id="sort_order_datebox" value="custom"/> |
| | 483 | |
| | 484 | <?php /*div id="datebox_more"></div> |
| | 485 | <p><a href="javascript:add_option('datebox')">Add Another Option</a></p*/ ?> |
| | 486 | </div> |
| | 487 | </div> |
| | 488 | <script> |
| | 489 | jQuery(document).ready(function($) { |
| | 490 | $("input[name='date_format']").click(function(){ |
| | 491 | if ( "date_format_custom_radio" != $(this).attr("id") ) |
| | 492 | $( "input[name='date_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).text() ); |
| | 493 | }); |
| | 494 | |
| | 495 | $("input[name='date_format_custom']").focus(function(){ |
| | 496 | $( '#date_format_custom_radio' ).prop( 'checked', true ); |
| | 497 | }); |
| | 498 | |
| | 499 | $("input[name='date_format_custom'], input[name='time_format_custom']").change( function() { |
| | 500 | var format = $(this); |
| | 501 | $('#date_format_custom_radio' ).val(format.val()); |
| | 502 | format.siblings( '.spinner' ).addClass( 'is-active' ); |
| | 503 | $.post(ajaxurl, { |
| | 504 | action: 'date_format_custom' == format.attr('name') ? 'date_format' : 'time_format', |
| | 505 | date : format.val() |
| | 506 | }, function(d) { |
| | 507 | format.siblings( '.spinner' ).removeClass( 'is-active' ); format.siblings('.example').text(d); |
| | 508 | |
| | 509 | } ); |
| | 510 | }); |
| | 511 | }); |
| | 512 | </script> |
| | 513 | |
| | 514 | <?php |
| | 515 | } |
| 325 | | return bp_format_time( $field_value, true, false ); |
| | 535 | global $wpdb, $bp; |
| | 536 | $option = unserialize(get_option( 'BPOptRegData')); |
| | 537 | //$uid = bp_displayed_user_id(); |
| | 538 | $parent_id = isset($GLOBALS['field']->id) ? $GLOBALS['field']->id : $field_id; |
| | 539 | $sort_sql = 'ORDER BY option_order ASC'; |
| | 540 | $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE parent_id = %d $sort_sql", $parent_id); |
| | 541 | $opt = $wpdb->get_results( $sql ); |
| | 542 | |
| | 543 | $option['date-format'] = $opt[7]->name; |
| | 544 | |
| | 545 | if(isset($opt[0]) && isset($opt[1])){ |
| | 546 | $option['show-year'] = $opt[0]->name; |
| | 547 | $option['show-time'] = $opt[1]->name; |
| | 548 | } |
| | 549 | |
| | 550 | |
| | 551 | if($option['show-time'] == 'yes'){ |
| | 552 | $field_value = self::formatDateByBPOptRegData($field_value,$option, true, true); |
| | 553 | |
| | 554 | }else { |
| | 555 | $field_value = self::formatDateByBPOptRegData($field_value,$option, true, false); |
| | 556 | } |
| | 557 | |
| | 558 | return $field_value; |
| | 560 | |
| | 561 | private function formatDateByBPOptRegData( $time, $option,$localize_time = true, $show) { |
| | 562 | |
| | 563 | if ( ! isset( $time ) || ! is_numeric( $time ) ) { |
| | 564 | return false; |
| | 565 | } |
| | 566 | |
| | 567 | if ( ! empty( $localize_time ) ) { |
| | 568 | $root_blog_offset = get_blog_option( bp_get_root_blog_id(), 'gmt_offset' ); |
| | 569 | }else{ |
| | 570 | $root_blog_offset = false; |
| | 571 | } |
| | 572 | |
| | 573 | $time_offset = $time + ( $root_blog_offset * 3600 ); |
| | 574 | |
| | 575 | if($show === false){ |
| | 576 | |
| | 577 | $date = date_i18n($option['date-format'], $time_offset ); |
| | 578 | |
| | 579 | }else{ // Here we calculate the number of years |
| | 580 | |
| | 581 | $time_curr = time(); |
| | 582 | $def = $time_curr - $time_offset; |
| | 583 | $date = floor($def / (60*60*24*365)); |
| | 584 | $date = ' ' . $date . __(' years', 'buddypress'); |
| | 585 | } |
| | 586 | |
| | 587 | return $date; |
| | 588 | } |