517 | | $this->enqueue_schedule_shortcode_dependencies(); |
| 513 | $attr = shortcode_atts( array( |
| 514 | 'date' => null, |
| 515 | 'tracks' => 'all', |
| 516 | 'speaker_link' => 'anchor', // anchor|wporg|permalink|none |
| 517 | 'session_link' => 'permalink', // permalink|anchor|none |
| 518 | ), $attr ); |
| 519 | |
| 520 | foreach ( array( 'tracks', 'speaker_link', 'session_link' ) as $key_for_case_sensitive_value ) { |
| 521 | $attr[ $key_for_case_sensitive_value ] = strtolower( $attr[ $key_for_case_sensitive_value ] ); |
| 522 | } |
| 523 | |
| 524 | if ( ! in_array( $attr['speaker_link'], array( 'anchor', 'wporg', 'permalink', 'none' ) ) ) |
| 525 | $attr['speaker_link'] = 'anchor'; |
| 526 | |
| 527 | if ( ! in_array( $attr['session_link'], array( 'permalink', 'anchor', 'none' ) ) ) |
| 528 | $attr['session_link'] = 'permalink'; |
| 529 | |
| 530 | $columns = array(); |
| 531 | $tracks = array(); |
| 532 | |
| 533 | $query_args = array( |
| 534 | 'post_type' => 'wcb_session', |
| 535 | 'posts_per_page' => -1, |
| 536 | 'meta_query' => array( |
| 537 | 'relation' => 'AND', |
| 538 | array( |
| 539 | 'key' => '_wcpt_session_time', |
| 540 | 'compare' => 'EXISTS', |
| 541 | ), |
| 542 | ), |
| 543 | ); |
| 544 | |
| 545 | if ( 'all' == $attr['tracks'] ) { |
| 546 | // Include all tracks. |
| 547 | $tracks = get_terms( 'wcb_track' ); |
| 548 | } else { |
| 549 | // Loop through given tracks and look for terms. |
| 550 | $terms = array_map( 'trim', explode( ',', $attr['tracks'] ) ); |
| 551 | foreach ( $terms as $term_slug ) { |
| 552 | $term = get_term_by( 'slug', $term_slug, 'wcb_track' ); |
| 553 | if ( $term ) |
| 554 | $tracks[ $term->term_id ] = $term; |
| 555 | } |
| 556 | |
| 557 | // If tracks were provided, restrict the lookup in WP_Query. |
| 558 | if ( ! empty( $tracks ) ) { |
| 559 | $query_args['tax_query'][] = array( |
| 560 | 'taxonomy' => 'wcb_track', |
| 561 | 'field' => 'id', |
| 562 | 'terms' => array_values( wp_list_pluck( $tracks, 'term_id' ) ), |
| 563 | ); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | if ( $attr['date'] && strtotime( $attr['date'] ) ) { |
| 568 | $query_args['meta_query'][] = array( |
| 569 | 'key' => '_wcpt_session_time', |
| 570 | 'value' => array( |
| 571 | strtotime( $attr['date'] ), |
| 572 | strtotime( $attr['date'] . ' +1 day' ), |
| 573 | ), |
| 574 | 'compare' => 'BETWEEN', |
| 575 | 'type' => 'NUMERIC', |
| 576 | ); |
| 577 | } |
| 578 | |
| 579 | // Use tracks to form the columns. |
| 580 | if ( $tracks ) { |
| 581 | foreach ( $tracks as $track ) |
| 582 | $columns[ $track->term_id ] = $track->term_id; |
| 583 | } else { |
| 584 | $columns[ 0 ] = 0; |
| 585 | } |
| 586 | |
| 587 | unset( $tracks ); |
| 588 | |
| 589 | // Loop through all sessions and assign them into the formatted |
| 590 | // $sessions array: $sessions[ $time ][ $track ] = $session_id |
| 591 | // Use 0 as the track ID if no tracks exist |
519 | | $attr = preprocess_schedule_attributes( $attr ); |
520 | | $tracks = get_schedule_tracks( $attr['tracks'] ); |
521 | | $tracks_explicitly_specified = 'all' !== $attr['tracks']; |
522 | | $sessions = get_schedule_sessions( $attr['date'], $tracks_explicitly_specified, $tracks ); |
523 | | $columns = get_schedule_columns( $tracks, $sessions, $tracks_explicitly_specified ); |
| 593 | $sessions = array(); |
| 594 | $sessions_query = new WP_Query( $query_args ); |
| 595 | foreach ( $sessions_query->posts as $session ) { |
| 596 | $time = absint( get_post_meta( $session->ID, '_wcpt_session_time', true ) ); |
| 597 | $tracks = get_the_terms( $session->ID, 'wcb_track' ); |
525 | | $html = '<table class="wcpt-schedule" border="0">'; |
| 599 | if ( ! isset( $sessions[ $time ] ) ) |
| 600 | $sessions[ $time ] = array(); |
| 601 | |
| 602 | if ( empty( $tracks ) ) { |
| 603 | $sessions[ $time ][ 0 ] = $session->ID; |
| 604 | } else { |
| 605 | foreach ( $tracks as $track ) |
| 606 | $sessions[ $time ][ $track->term_id ] = $session->ID; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | // Sort all sessions by their key (timestamp). |
| 611 | ksort( $sessions ); |
| 612 | |
| 613 | // Remove empty columns unless tracks have been explicitly specified |
| 614 | if ( 'all' == $attr['tracks'] ) { |
| 615 | $used_terms = array(); |
| 616 | |
| 617 | foreach ( $sessions as $time => $entry ) |
| 618 | if ( is_array( $entry ) ) |
| 619 | foreach ( $entry as $term_id => $session_id ) |
| 620 | $used_terms[ $term_id ] = $term_id; |
| 621 | |
| 622 | $columns = array_intersect( $columns, $used_terms ); |
| 623 | unset( $used_terms ); |
| 624 | } |
| 625 | |
| 626 | $html = '<table class="wcpt-schedule" border="0">'; |
691 | | * Enqueue style and scripts needed for [schedule] shortcode. |
692 | | */ |
693 | | function enqueue_schedule_shortcode_dependencies() { |
694 | | wp_enqueue_style( 'dashicons' ); |
695 | | |
696 | | wp_enqueue_script( |
697 | | 'favourite-sessions', |
698 | | plugin_dir_url( __FILE__ ) . 'js/favourite-sessions.js', |
699 | | array( 'jquery' ), |
700 | | filemtime( plugin_dir_path( __FILE__ ) . 'js/favourite-sessions.js' ), |
701 | | true |
702 | | ); |
703 | | |
704 | | wp_localize_script( |
705 | | 'favourite-sessions', |
706 | | 'favSessionsPhpObject', |
707 | | array( |
708 | | 'root' => esc_url_raw( rest_url() ), |
709 | | 'i18n' => array( |
710 | | 'reqTimeOut' => esc_html__( 'Sorry, the email request timed out.', 'wordcamporg' ), |
711 | | 'otherError' => esc_html__( 'Sorry, the email request failed.', 'wordcamporg' ), |
712 | | ), |
713 | | ) |
714 | | ); |
715 | | } |
716 | | |
717 | | /** |
718 | | * Return HTML code for email form used to send/share favourite sessions over email. |
719 | | * |
720 | | * Both form and button/link to show/hide the form can be styled using classes email-form |
721 | | * and show-email-form, respectively. |
722 | | * |
723 | | * @return string HTML code that represents the form to send emails and a link to show and hide it. |
724 | | */ |
725 | | function fav_session_email_form() { |
726 | | static $email_form_count = 0; |
727 | | |
728 | | // Skip email form if it is disabled or it was already added to document. |
729 | | if ( email_fav_sessions_disabled() || $email_form_count !== 0 ) { |
730 | | return ''; |
731 | | } |
732 | | |
733 | | ob_start(); |
734 | | ?> |
735 | | |
736 | | <div class="email-form fav-session-email-form-hide"> |
737 | | <div id="fav-session-email-form"> |
738 | | <?php esc_html_e( 'Send me my favorite sessions:', 'wordcamporg' ); ?> |
739 | | |
740 | | <form id="fav-sessions-form"> |
741 | | <input type="text" name="email_address" id="fav-sessions-email-address" placeholder="my@email.com" /> |
742 | | <input type="submit" value="<?php esc_attr_e( 'Send', 'wordcamporg' ); ?>" /> |
743 | | </form> |
744 | | </div> |
745 | | <div class="fav-session-email-wait-spinner"></div> |
746 | | <div class="fav-session-email-result"></div> |
747 | | </div> |
748 | | |
749 | | <a class="show-email-form" href="javascript:"> |
750 | | <span class="dashicons dashicons-star-filled"></span> |
751 | | <span class="dashicons dashicons-email-alt"></span> |
752 | | </a> |
753 | | |
754 | | <?php |
755 | | $email_form = ob_get_clean(); |
756 | | |
757 | | $email_form_count++; |
758 | | |
759 | | return $email_form; |
760 | | } |
761 | | |
762 | | /** |
1289 | | if ( ! $speakers->have_posts() ) { |
1290 | | return $content; |
1291 | | } |
1292 | | |
1293 | | $speakers_html = sprintf( |
1294 | | '<h2 class="session-speakers">%s</h2>', |
1295 | | _n( |
1296 | | __( 'Speaker', 'wordcamporg' ), |
1297 | | __( 'Speakers', 'wordcamporg' ), |
1298 | | $speakers->post_count |
1299 | | ) |
| 1303 | $speaker_text = _n( |
| 1304 | __( 'Speaker', 'wordcamporg' ), |
| 1305 | __( 'Speakers', 'wordcamporg' ), |
| 1306 | $speakers->post_count, |
| 1307 | 'wordcamporg' |
1311 | | return $content . $speakers_html; |
1312 | | } |
1313 | | |
1314 | | /** |
1315 | | * Add Slides link to Session posts |
1316 | | * |
1317 | | * We don't enable it for sites that were created before it was committed, because some will have already |
1318 | | * crafted the session to include this content, so duplicating it would look wrong, but we still allow older |
1319 | | * sites to opt-in. |
1320 | | * |
1321 | | * @param string $content |
1322 | | * |
1323 | | * @return string |
1324 | | */ |
1325 | | function add_slides_info_to_session_posts( $content ) { |
1326 | | global $post; |
1327 | | $enabled_site_ids = apply_filters( 'wcpt_session_post_slides_info_enabled_site_ids', array( |
1328 | | 206, // testing.wordcamp.org |
1329 | | 648, // 2016.asheville |
1330 | | 651, // 2016.kansascity |
1331 | | 623, // 2016.tampa |
1332 | | ) ); |
1333 | | |
1334 | | if ( ! $this->is_single_cpt_post( 'wcb_session' ) ) { |
1335 | | return $content; |
| 1318 | $speakers_list = join( ', ', $speakers_array ); |
| 1319 | if( $speakers_list ) { |
| 1320 | $speaker_text .= ': ' . $speakers_list; |
| 1321 | } else { |
| 1322 | $speaker_text = ''; |
1338 | | $site_id = get_current_blog_id(); |
1339 | | if ( $site_id <= apply_filters( 'wcpt_session_post_slides_info_min_site_id', 699 ) && ! in_array( $site_id, $enabled_site_ids ) ) { |
1340 | | return $content; |
1341 | | } |
| 1325 | // Get the time and date of the session |
| 1326 | $time = absint( get_post_meta( $post->ID, '_wcpt_session_time', true ) ); |
| 1327 | $time_text = ''; |
| 1328 | if( $time ) { |
| 1329 | $time_format = get_option( 'time_format', 'g:i a' ); |
| 1330 | $date_format = get_option( 'date_format', 'F j, Y' ); |
1356 | | /** |
1357 | | * Add Video link to Session posts |
1358 | | * |
1359 | | * We don't enable it for sites that were created before it was committed, because some will have already |
1360 | | * crafted the session to include this content, so duplicating it would look wrong, but we still allow older |
1361 | | * sites to opt-in. |
1362 | | * |
1363 | | * @param string $content |
1364 | | * |
1365 | | * @return string |
1366 | | */ |
1367 | | function add_video_info_to_session_posts( $content ) { |
1368 | | global $post; |
1369 | | $enabled_site_ids = apply_filters( 'wcpt_session_post_video_info_enabled_site_ids', array( |
1370 | | 206, // testing.wordcamp.org |
1371 | | 648, // 2016.asheville |
1372 | | 623, // 2016.tampa |
1373 | | ) ); |
| 1349 | $tracks_text = _n( |
| 1350 | __( 'Track', 'wordcamporg' ), |
| 1351 | __( 'Tracks', 'wordcamporg' ), |
| 1352 | $num_tracks, |
| 1353 | 'wordcamporg' |
| 1354 | ); |
1390 | | $session_video_html = '<div class="session-video">'; |
1391 | | $session_video_html .= sprintf( __( '<a href="%s" target="_blank">View Session Video</a>', 'wordcamporg' ), esc_url( $session_video ) ); |
1392 | | $session_video_html .= '</div>'; |
1393 | | |
1394 | | return $content . $session_video_html; |
1395 | | } |
1396 | | |
1397 | | /** |
1398 | | * Append a session's categories to its post content. |
1399 | | * |
1400 | | * @param string $content |
1401 | | * |
1402 | | * @return string |
1403 | | */ |
1404 | | function add_session_categories_to_session_posts( $content ) { |
1405 | | global $post; |
1406 | | |
1407 | | if ( ! $this->is_single_cpt_post( 'wcb_session' ) ) { |
1408 | | return $content; |
| 1374 | // Get the list of session categories |
| 1375 | $categories_list = get_the_term_list( $post->ID, 'wcb_session_category', '', _x( ', ', 'Used between list items, there is a space after the comma.', 'wordcamporg' ) ); |
| 1376 | $categories_text = ''; |
| 1377 | if ( $categories_list ) { |
| 1378 | $num_categories = count( explode( ', ', $categories_list ) ); |
| 1379 | $categories_text = _n( |
| 1380 | __( 'Category', 'wordcamporg' ), |
| 1381 | __( 'Categories', 'wordcamporg' ), |
| 1382 | $num_categories, |
| 1383 | 'wordcamporg' |
| 1384 | ); |
| 1385 | $categories_text .= ': ' . $categories_list; |
1411 | | $session_categories_html = ''; |
1412 | | |
1413 | | $session_categories_list = get_the_term_list( $post->ID, 'wcb_session_category', '', _x( ', ', 'Used between list items, there is a space after the comma.', 'wordcamporg' ) ); |
1414 | | if ( $session_categories_list ) { |
1415 | | $session_categories_html = sprintf( |
1416 | | '<span class="session-categories-links"><span class="screen-reader-text">%1$s</span> %2$s</span>', |
1417 | | esc_html_x( 'Categories', 'Used before session category names.', 'wordcamporg' ), |
1418 | | wp_kses_post( $session_categories_list ) |
1419 | | ); |
| 1388 | // Generate meta list for display |
| 1389 | $meta_html = ''; |
| 1390 | if( $speaker_text || $time_text || $tracks_text || $slides_text || $video_text || $categories_text ) { |
| 1391 | ob_start(); |
| 1392 | require_once( __DIR__ . '/views/common/session-meta-data-list.php' ); |
| 1393 | $meta_html = ob_get_clean(); |