Advertisement
Guest User

Untitled

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