Advertisement
Guest User

event-list.php

a guest
Aug 2nd, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.58 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Event List
  4.  *
  5.  * @author      ThemeBoy
  6.  * @package     SportsPress/Templates
  7.  * @version     2.2
  8.  * @change      De Belser Arne - 28 Juni 2017 - Line 193
  9.  */
  10.  
  11. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  12.  
  13. $defaults = array(
  14.     'id' => null,
  15.     'title' => false,
  16.     'status' => 'default',
  17.     'date' => 'default',
  18.     'date_from' => 'default',
  19.     'date_to' => 'default',
  20.     'day' => 'default',
  21.     'league' => null,
  22.     'season' => null,
  23.     'venue' => null,
  24.     'team' => null,
  25.     'player' => null,
  26.     'number' => -1,
  27.     'show_team_logo' => get_option( 'sportspress_event_list_show_logos', 'no' ) == 'yes' ? true : false,
  28.     'link_events' => get_option( 'sportspress_link_events', 'yes' ) == 'yes' ? true : false,
  29.     'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
  30.     'link_venues' => get_option( 'sportspress_link_venues', 'yes' ) == 'yes' ? true : false,
  31.     'abbreviate_teams' => get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false,
  32.     'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false,
  33.     'scrollable' => get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false,
  34.     'paginated' => get_option( 'sportspress_event_list_paginated', 'yes' ) == 'yes' ? true : false,
  35.     'rows' => get_option( 'sportspress_event_list_rows', 10 ),
  36.     'order' => 'default',
  37.     'columns' => null,
  38.     'show_all_events_link' => false,
  39.     'show_title' => get_option( 'sportspress_event_list_show_title', 'yes' ) == 'yes' ? true : false,
  40.     'title_format' => get_option( 'sportspress_event_list_title_format', 'title' ),
  41.     'time_format' => get_option( 'sportspress_event_list_time_format', 'combined' ),
  42. );
  43.  
  44. extract( $defaults, EXTR_SKIP );
  45.  
  46. $calendar = new SP_Calendar( $id );
  47. if ( $status != 'default' )
  48.     $calendar->status = $status;
  49. if ( $date != 'default' )
  50.     $calendar->date = $date;
  51. if ( $date_from != 'default' )
  52.     $calendar->from = $date_from;
  53. if ( $date_to != 'default' )
  54.     $calendar->to = $date_to;
  55. if ( $league )
  56.     $calendar->league = $league;
  57. if ( $season )
  58.     $calendar->season = $season;
  59. if ( $venue )
  60.     $calendar->venue = $venue;
  61. if ( $team )
  62.     $calendar->team = $team;
  63. if ( $player )
  64.     $calendar->player = $player;
  65. if ( $order != 'default' )
  66.     $calendar->order = $order;
  67. if ( $day != 'default' )
  68.     $calendar->day = $day;
  69. $data = $calendar->data();
  70. $usecolumns = $calendar->columns;
  71.  
  72. if ( isset( $columns ) ):
  73.     if ( is_array( $columns ) )
  74.         $usecolumns = $columns;
  75.     else
  76.         $usecolumns = explode( ',', $columns );
  77. endif;
  78.  
  79. if ( $show_title && false === $title && $id ):
  80.     $caption = $calendar->caption;
  81.     if ( $caption )
  82.         $title = $caption;
  83.     else
  84.         $title = get_the_title( $id );
  85. endif;
  86. ?>
  87. <div class="sp-template sp-template-event-list">
  88.     <?php if ( $title ) { ?>
  89.         <h4 class="sp-table-caption"><?php echo $title; ?></h4>
  90.     <?php } ?>
  91.     <div class="sp-table-wrapper">
  92.         <table class="sp-event-list sp-event-list-format-<?php echo $title_format; ?> sp-data-table<?php if ( $paginated ) { ?> sp-paginated-table<?php } if ( $sortable ) { ?> sp-sortable-table<?php } if ( $scrollable ) { ?> sp-scrollable-table<?php } ?>" data-sp-rows="<?php echo $rows; ?>">
  93.             <thead>
  94.                 <tr>
  95.                     <?php
  96.                     echo '<th class="data-date">' . __( 'Date', 'sportspress' ) . '</th>';
  97.  
  98.                     switch ( $title_format ) {
  99.                         case 'homeaway':
  100.                             if ( sp_column_active( $usecolumns, 'event' ) ) {
  101.                                 echo '<th class="data-home">' . __( 'Home', 'sportspress' ) . '</th>';
  102.                             }
  103.  
  104.                             if ( 'combined' == $time_format && sp_column_active( $usecolumns, 'time' ) ) {
  105.                                 echo '<th class="data-time">' . __( 'Time/Results', 'sportspress' ) . '</th>';
  106.                             } elseif ( in_array( $time_format, array( 'separate', 'results' ) ) && sp_column_active( $usecolumns, 'results' ) ) {
  107.                                 echo '<th class="data-results">' . __( 'Results', 'sportspress' ) . '</th>';
  108.                             }
  109.  
  110.                             if ( sp_column_active( $usecolumns, 'event' ) ) {
  111.                                 echo '<th class="data-away">' . __( 'Away', 'sportspress' ) . '</th>';
  112.                             }
  113.  
  114.                             if ( in_array( $time_format, array( 'separate', 'time' ) ) && sp_column_active( $usecolumns, 'time' ) ) {
  115.                                 echo '<th class="data-time">' . __( 'Time', 'sportspress' ) . '</th>';
  116.                             }
  117.                             break;
  118.                         default:
  119.                             if ( sp_column_active( $usecolumns, 'event' ) ) {
  120.                                 if ( $title_format == 'teams' )
  121.                                     echo '<th class="data-teams">' . __( 'Teams', 'sportspress' ) . '</th>';
  122.                                 else
  123.                                     echo '<th class="data-event">' . __( 'Event', 'sportspress' ) . '</th>';
  124.                             }
  125.  
  126.                             switch ( $time_format ) {
  127.                                 case 'separate':
  128.                                     if ( sp_column_active( $usecolumns, 'time' ) )
  129.                                         echo '<th class="data-time">' . __( 'Time', 'sportspress' ) . '</th>';
  130.                                     if ( sp_column_active( $usecolumns, 'results' ) )
  131.                                         echo '<th class="data-results">' . __( 'Results', 'sportspress' ) . '</th>';
  132.                                     break;
  133.                                 case 'time':
  134.                                     if ( sp_column_active( $usecolumns, 'time' ) )
  135.                                         echo '<th class="data-time">' . __( 'Time', 'sportspress' ) . '</th>';
  136.                                     break;
  137.                                 case 'results':
  138.                                     if ( sp_column_active( $usecolumns, 'results' ) )
  139.                                         echo '<th class="data-results">' . __( 'Results', 'sportspress' ) . '</th>';
  140.                                     break;
  141.                                 default:
  142.                                     if ( sp_column_active( $usecolumns, 'time' ) )
  143.                                         echo '<th class="data-time">' . __( 'Time/Results', 'sportspress' ) . '</th>';
  144.                             }
  145.                     }
  146.  
  147.                     if ( sp_column_active( $usecolumns, 'league' ) )
  148.                         echo '<th class="data-league">' . __( 'Competition', 'sportspress' ) . '</th>';
  149.  
  150.                     if ( sp_column_active( $usecolumns, 'season' ) )
  151.                         echo '<th class="data-season">' . __( 'Season', 'sportspress' ) . '</th>';
  152.  
  153.                     if ( sp_column_active( $usecolumns, 'venue' ) )
  154.                         echo '<th class="data-venue">' . __( 'Venue', 'sportspress' ) . '</th>';
  155.  
  156.                     if ( sp_column_active( $usecolumns, 'article' ) )
  157.                         echo '<th class="data-article">' . __( 'Article', 'sportspress' ) . '</th>';
  158.  
  159.                     if ( sp_column_active( $usecolumns, 'day' ) )
  160.                         echo '<th class="data-day">' . __( 'Match Day', 'sportspress' ) . '</th>';
  161.                     ?>
  162.                 </tr>
  163.             </thead>
  164.             <tbody>
  165.                 <?php
  166.                 $i = 0;
  167.  
  168.                 if ( is_numeric( $number ) && $number > 0 )
  169.                     $limit = $number;
  170.  
  171.                 foreach ( $data as $event ):
  172.                     if ( isset( $limit ) && $i >= $limit ) continue;
  173.  
  174.                     $teams = get_post_meta( $event->ID, 'sp_team' );
  175.                     $video = get_post_meta( $event->ID, 'sp_video', true );
  176.  
  177.                     $main_results = apply_filters( 'sportspress_event_list_main_results', sp_get_main_results( $event ), $event->ID );
  178.  
  179.                     $teams_output = '';
  180.                     $team_class = '';
  181.                     $teams_array = array();
  182.                     $team_logos = array();
  183.  
  184.                     if ( $teams ):
  185.                         foreach ( $teams as $t => $team ):
  186.                             $name = sp_get_team_name( $team, $abbreviate_teams );
  187.                             if ( $name ):
  188.  
  189.                                 if ( $show_team_logo ):
  190.                                     if ( has_post_thumbnail( $team ) ):
  191.                                         $logo = '<span class="team-logo">' . sp_get_logo( $team, 'mini' ) . '</span>';
  192.                                         $team_logos[] = $logo;
  193.                                         $team_class .= ' has-logo';
  194.  
  195.                                         // Begin nieuwe code
  196.                                             if ( $t ):
  197.                                             $name = '<span class="pc-list-logo">' . $name . ' ' . $logo . '</span>' . '<span class="mobile-list-logo">' . $logo . ' ' . $name . '</span>';
  198.                                             else:
  199.                                             $name = $logo . ' ' . $name;
  200.                                             endif;
  201.                                         // Einde nieuwe code
  202.  
  203.                                         // if ( $t ): // Logo's anders ordenen - De Belser Arne - 1 Juni 2017
  204.                                             // $name = '<span style="text-align: right !important; display: block;">' . $logo . '<br>' . $name . '</span>';
  205.                                             // else:
  206.                                             // $name = '<span style="text-align: left !important; display: block;">' . $logo . '<br>' . $name . '</span>';
  207.                                             // endif;
  208.                                         // Einde custom code
  209.  
  210.                                         // Begin originele code
  211.                                             // if ( $t ):
  212.                                             // $name = $logo . ' ' . $name;
  213.                                             // else:
  214.                                             // $name .= ' ' . $logo;
  215.                                             // endif;
  216.                                         // Einde originele code
  217.  
  218.                                     endif;
  219.                                 endif;
  220.  
  221.                                 if ( $link_teams ):
  222.                                     $team_output = '<a href="' . get_post_permalink( $team ) . '">' . $name . '</a>';
  223.                                 else:
  224.                                     $team_output = $name;
  225.                                 endif;
  226.  
  227.                                 $team_result = sp_array_value( $main_results, $team, null );
  228.  
  229.                                 if ( $team_result != null ):
  230.                                     if ( $usecolumns != null && ! in_array( 'time', $usecolumns ) ):
  231.                                         $team_output .= ' (' . $team_result . ')';
  232.                                     endif;
  233.                                 endif;
  234.  
  235.                                 $teams_array[] = $team_output;
  236.  
  237.                                 $teams_output .= $team_output . '<br>';
  238.                             endif;
  239.                         endforeach;
  240.                     else:
  241.                         $teams_output .= '&mdash;';
  242.                     endif;
  243.  
  244.                     echo '<tr class="sp-row sp-post' . ( $i % 2 == 0 ? ' alternate' : '' ) . ' sp-row-no-' . $i . '">';
  245.  
  246.                         $date_html = '<date>' . get_post_time( 'Y-m-d H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_date', get_post_time( get_option( 'date_format' ), false, $event, true ), $event->ID );
  247.  
  248.                         if ( $link_events ) $date_html = '<a href="' . get_post_permalink( $event->ID, false, true ) . '">' . $date_html . '</a>';
  249.  
  250.                         echo '<td class="data-date">' . $date_html . '</td>';
  251.  
  252.                         switch ( $title_format ) {
  253.                             case 'homeaway':
  254.  
  255.                                     if ( sp_column_active( $usecolumns, 'event' ) ) {
  256.                                         $team = array_shift( $teams_array );
  257.                                         echo '<td class="data-home' . $team_class . '">' . $team . '</td>';
  258.                                     }
  259.  
  260.                                     if ( 'combined' == $time_format && sp_column_active( $usecolumns, 'time' ) ) {
  261.                                         echo '<td class="data-time">';
  262.                                         if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '">';
  263.                                         if ( ! empty( $main_results ) ):
  264.                                             echo implode( ' - ', $main_results );
  265.                                         else:
  266.                                             echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', sp_get_time( $event ), $event->ID );
  267.                                         endif;
  268.                                         if ( $link_events ) echo '</a>';
  269.                                         echo '</td>';
  270.                                     } elseif ( in_array( $time_format, array( 'separate', 'results' ) ) && sp_column_active( $usecolumns, 'results' ) ) {
  271.                                         echo '<td class="data-results">';
  272.                                         if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '">';
  273.                                         if ( ! empty( $main_results ) ):
  274.                                             echo implode( ' - ', $main_results );
  275.                                         else:
  276.                                             echo '-';
  277.                                         endif;
  278.                                         if ( $link_events ) echo '</a>';
  279.                                         echo '</td>';
  280.                                     }
  281.  
  282.                                     if ( sp_column_active( $usecolumns, 'event' ) ) {
  283.                                         $team = array_shift( $teams_array );
  284.                                         echo '<td class="data-away' . $team_class . '">' . $team . '</td>';
  285.                                     }
  286.  
  287.                                     if ( in_array( $time_format, array( 'separate', 'time' ) ) && sp_column_active( $usecolumns, 'time' ) ) {
  288.                                         echo '<td class="data-time">';
  289.                                         if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '">';
  290.                                         echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', sp_get_time( $event ), $event->ID );
  291.                                         if ( $link_events ) echo '</a>';
  292.                                         echo '</td>';
  293.                                     }
  294.                                     break;
  295.  
  296.                             default:
  297.                                 if ( sp_column_active( $usecolumns, 'event' ) ) {
  298.                                     if ( $title_format == 'teams' ) {
  299.                                         echo '<td class="data-event data-teams">' . $teams_output . '</td>';
  300.                                     } else {
  301.                                         $title_html = implode( ' ', $team_logos ) . ' ' . $event->post_title;
  302.                                         if ( $link_events ) $title_html = '<a href="' . get_post_permalink( $event->ID, false, true ) . '">' . $title_html . '</a>';
  303.                                         echo '<td class="data-event">' . $title_html . '</td>';
  304.                                     }
  305.                                 }
  306.  
  307.                                 switch ( $time_format ) {
  308.                                     case 'separate':
  309.                                         if ( sp_column_active( $usecolumns, 'time' ) ) {
  310.                                             echo '<td class="data-time">';
  311.                                             if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '">';
  312.                                             echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', sp_get_time( $event ), $event->ID );
  313.                                             if ( $link_events ) echo '</a>';
  314.                                             echo '</td>';
  315.                                         }
  316.                                         if ( sp_column_active( $usecolumns, 'results' ) ) {
  317.                                             echo '<td class="data-results">';
  318.                                             if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '">';
  319.                                             if ( ! empty( $main_results ) ):
  320.                                                 echo implode( ' - ', $main_results );
  321.                                             else:
  322.                                                 echo '-';
  323.                                             endif;
  324.                                             if ( $link_events ) echo '</a>';
  325.                                             echo '</td>';
  326.                                         }
  327.                                         break;
  328.                                     case 'time':
  329.                                         if ( sp_column_active( $usecolumns, 'time' ) ) {
  330.                                             echo '<td class="data-time">';
  331.                                             if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '">';
  332.                                             echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', sp_get_time( $event ), $event->ID );
  333.                                             if ( $link_events ) echo '</a>';
  334.                                             echo '</td>';
  335.                                         }
  336.                                         break;
  337.                                     case 'results':
  338.                                         if ( sp_column_active( $usecolumns, 'results' ) ) {
  339.                                             echo '<td class="data-results">';
  340.                                             if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '">';
  341.                                             if ( ! empty( $main_results ) ):
  342.                                                 echo implode( ' - ', $main_results );
  343.                                             else:
  344.                                                 echo '-';
  345.                                             endif;
  346.                                             if ( $link_events ) echo '</a>';
  347.                                             echo '</td>';
  348.                                         }
  349.                                         break;
  350.                                     default:
  351.                                         if ( sp_column_active( $usecolumns, 'time' ) ) {
  352.                                             echo '<td class="data-time">';
  353.                                             if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '">';
  354.                                             if ( ! empty( $main_results ) ):
  355.                                                 echo implode( ' - ', $main_results );
  356.                                             else:
  357.                                                 echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', sp_get_time( $event ), $event->ID );
  358.                                             endif;
  359.                                             if ( $link_events ) echo '</a>';
  360.                                             echo '</td>';
  361.                                         }
  362.                                 }
  363.                         }
  364.  
  365.                         if ( sp_column_active( $usecolumns, 'league' ) ):
  366.                             echo '<td class="data-league">';
  367.                             $leagues = get_the_terms( $event->ID, 'sp_league' );
  368.                             if ( $leagues ): foreach ( $leagues as $league ):
  369.                                 echo $league->name;
  370.                             endforeach; endif;
  371.                             echo '</td>';
  372.                         endif;
  373.  
  374.                         if ( sp_column_active( $usecolumns, 'season' ) ):
  375.                             echo '<td class="data-season">';
  376.                             $seasons = get_the_terms( $event->ID, 'sp_season' );
  377.                             if ( $seasons ): foreach ( $seasons as $season ):
  378.                                 echo $season->name;
  379.                             endforeach; endif;
  380.                             echo '</td>';
  381.                         endif;
  382.  
  383.                         if ( sp_column_active( $usecolumns, 'venue' ) ):
  384.                             echo '<td class="data-venue">';
  385.                             if ( $link_venues ):
  386.                                 the_terms( $event->ID, 'sp_venue' );
  387.                             else:
  388.                                 $venues = get_the_terms( $event->ID, 'sp_venue' );
  389.                                 if ( $venues ): foreach ( $venues as $venue ):
  390.                                     echo $venue->name;
  391.                                 endforeach; endif;
  392.                             endif;
  393.                             echo '</td>';
  394.                         endif;
  395.  
  396.                         if ( sp_column_active( $usecolumns, 'article' ) ):
  397.                             echo '<td class="data-article">';
  398.                                 if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '">';
  399.  
  400.                                 if ( $video ):
  401.                                     echo '<div class="dashicons dashicons-video-alt"></div>';
  402.                                 elseif ( has_post_thumbnail( $event->ID ) ):
  403.                                     echo '<div class="dashicons dashicons-camera"></div>';
  404.                                 endif;
  405.                                 if ( $event->post_content !== null ):
  406.                                     if ( $event->post_status == 'publish' ):
  407.                                         _e( 'Recap', 'sportspress' );
  408.                                     else:
  409.                                         _e( 'Preview', 'sportspress' );
  410.                                     endif;
  411.                                 endif;
  412.  
  413.                                 if ( $link_events ) echo '</a>';
  414.                             echo '</td>';
  415.                         endif;
  416.  
  417.                         if ( sp_column_active( $usecolumns, 'day' ) ):
  418.                             echo '<td class="data-day">';
  419.                             $day = get_post_meta( $event->ID, 'sp_day', true );
  420.                             if ( '' == $day ) {
  421.                                 echo '-';
  422.                             } else {
  423.                                 echo $day;
  424.                             }
  425.                             echo '</td>';
  426.                         endif;
  427.  
  428.                     echo '</tr>';
  429.  
  430.                     $i++;
  431.                 endforeach;
  432.                 ?>
  433.             </tbody>
  434.         </table>
  435.     </div>
  436.     <?php
  437.     if ( $id && $show_all_events_link )
  438.         echo '<div class="sp-calendar-link sp-view-all-link"><a href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a></div>';
  439.     ?>
  440. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement