Changeset 8952
- Timestamp:
- 06/14/2019 05:59:45 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-meeting-posttype/wporg-meeting-posttype.php
r8922 r8952 220 220 ), 221 221 ); 222 222 register_post_type( 'meeting', $args ); 223 223 } 224 224 … … 428 428 public function meeting_time_shortcode( $attr, $content = '' ) { 429 429 430 $attr = shortcode_atts( array( 431 'team' => null, 432 'limit' => 1, 433 'before' => __( 'Next meeting: ', 'wporg' ), 434 'titletag' => 'strong', 435 'more' => true, 436 ), $attr ); 437 430 438 if ( empty( $attr['team'] ) ) { 431 439 return ''; … … 435 443 $attr['team'] = 'Docs'; 436 444 } 445 446 if ( ! has_action( 'wp_footer', array( $this, 'time_conversion_script' ) ) ) { 447 add_action( 'wp_footer', array( $this, 'time_conversion_script' ), 999 ); 448 } 449 437 450 438 451 // meta query to eliminate expired meetings from query … … 441 454 } ); 442 455 456 switch_to_blog( get_main_site_id() ); 457 443 458 $query = new WP_Query( 444 459 array( 445 460 'post_type' => 'meeting', 446 ' nopaging' => true,461 'posts_per_page' => $attr['limit'], 447 462 'meta_query' => array( 448 463 'relation' => 'AND', … … 457 472 ); 458 473 459 if ( count( $query->posts ) > 0 ) { 460 461 $post = $query->posts[0]; 474 $out = ''; 475 foreach ( $query->posts as $post ) { 462 476 $next_meeting_datestring = $post->next_date; 463 477 $utc_time = strftime( '%H:%M:%S', strtotime( $post->time ) ); 464 478 $next_meeting_iso = $next_meeting_datestring . 'T' . $utc_time . '+00:00'; 465 $next_meeeting_timestamp = strtotime( $next_meeting_datestring . $utc_time ); 479 $next_meeting_timestamp = strtotime( $next_meeting_datestring . ' '. $utc_time ); 480 $next_meeting_display = strftime( '%c %Z', $next_meeting_timestamp ); 481 482 $slack_channel = null; 483 if ( $post->location && preg_match( '/^#([-\w]+)$/', trim( $post->location ), $match ) ) { 484 $slack_channel = sanitize_title( $match[1] ); 485 } 466 486 467 $out = '<p>'; 468 $out .= 'Next meeting: ' . __( $post->post_title ); 487 $out .= '<p>'; 488 $out .= esc_html( $attr['before'] ); 489 $out .= '<strong class="meeting-title">' . esc_html( $post->post_title ) . '</strong>'; 469 490 $display_count = count( $query->posts ) - 1; 470 $out .= $display_count === 0 ? '' : ' <a title="Click to view all meetings for this team" href="/meetings#' . esc_attr( $attr['team'] ) . '">' . sprintf( __( '(+%s more)'), $display_count ) . '</a>'; 491 if ( $attr['more'] ) { 492 $out .= $display_count === 0 ? '' : ' <a title="Click to view all meetings for this team" href="/meetings#' . esc_attr( $attr['team'] ) . '">' . sprintf( __( '(+%s more)'), $display_count ) . '</a>'; 493 } 471 494 $out .= '</br>'; 472 $out .= '<time class="date" date-time="' . esc_attr( $next_meeting_iso ) . '" title="' . esc_attr( $next_meeting_iso ) . '">' . $next_meeting_iso . '</time> '; 473 $out .= sprintf( __( '(%s from now)' ), human_time_diff( $next_meeeting_timestamp, current_time('timestamp') ) ); 474 $out .= empty( $post->location ) ? '' : ' ' . sprintf( __('at %s on Slack'), $post->location ); 495 $out .= '<time class="date" date-time="' . esc_attr( $next_meeting_iso ) . '" title="' . esc_attr( $next_meeting_iso ) . '">' . $next_meeting_display . '</time> '; 496 $out .= sprintf( esc_html__( '(%s from now)' ), human_time_diff( $next_meeting_timestamp, current_time('timestamp') ) ); 497 if ( $post->location && $slack_channel ) { 498 $out .= ' ' . sprintf( wp_kses( __('at <a href="%s">%s</a> on Slack'), array( 'a' => array( 'href' => array() ) ) ), 'https://wordpress.slack.com/messages/' . $slack_channel, $post->location ); 499 } 475 500 $out .= '</p>'; 476 501 } 477 502 503 restore_current_blog(); 478 504 479 505 return $out; … … 521 547 ), 522 548 ); 549 550 public function time_conversion_script() { 551 echo <<<EOF 552 <script type="text/javascript"> 553 554 var parse_date = function (text) { 555 var m = /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})\+00:00$/.exec(text); 556 var d = new Date(); 557 d.setUTCFullYear(+m[1]); 558 d.setUTCDate(+m[3]); 559 d.setUTCMonth(+m[2]-1); 560 d.setUTCHours(+m[4]); 561 d.setUTCMinutes(+m[5]); 562 d.setUTCSeconds(+m[6]); 563 return d; 564 } 565 var format_time = function (d) { 566 return d.toLocaleTimeString(navigator.language, {weekday: 'long', hour: '2-digit', minute: '2-digit', timeZoneName: 'short'}); 567 } 568 569 var nodes = document.getElementsByTagName('time'); 570 for (var i=0; i<nodes.length; ++i) { 571 var node = nodes[i]; 572 if (node.className === 'date') { 573 var d = parse_date(node.getAttribute('date-time')); 574 if (d) { 575 node.textContent = format_time(d); 576 } 577 } 578 } 579 </script> 580 EOF; 581 } 523 582 } 524 583
Note: See TracChangeset
for help on using the changeset viewer.