Changeset 3046250
- Timestamp:
- 03/06/2024 10:53:01 AM (2 years ago)
- Location:
- eh-gms-feed
- Files:
-
- 10 edited
-
tags/3.10/css/gms-default.css (modified) (2 diffs)
-
tags/3.10/eh-gms-feed.php (modified) (1 diff)
-
tags/3.10/includes/main-class.php (modified) (11 diffs)
-
tags/3.10/js/eh-gms-feed.js (modified) (6 diffs)
-
tags/3.10/readme.txt (modified) (2 diffs)
-
trunk/css/gms-default.css (modified) (2 diffs)
-
trunk/eh-gms-feed.php (modified) (1 diff)
-
trunk/includes/main-class.php (modified) (11 diffs)
-
trunk/js/eh-gms-feed.js (modified) (6 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
eh-gms-feed/tags/3.10/css/gms-default.css
r2981152 r3046250 8 8 .gms-filter fieldset { width: fit-content } 9 9 .gms-filter legend { padding: 0px } 10 .gms-detaillink { cursor: pointer } 11 .gms-detaillink:hover { background-color: yellow } 10 12 11 13 /* This styling sets alignment for specific tables */ … … 26 28 @media screen and (max-width: 767px) { .gms-table { overflow-x: auto; display: block; white-space: nowrap } .gms-nomobile { display: none } } 27 29 28 /* Styling for fixtures and results displayed as list */30 /* Styling for fixtures and results displayed as list and fixture details */ 29 31 .gms-list > * + * { margin-top: 1.5rem; margin-bottom: 1.5rem } 32 .gms-list + .gms-footnote { margin-top: 1rem } 30 33 .gms-card { text-align: center; padding: 3px 3px; border-radius: 0.5rem } 31 .gms-card, .gms-cardtime { border: 1px solid; border-color: silver } 32 .gms-cardfixture { display: flex; gap: 0.5rem; align-items: center } 34 .gms-card, .gms-cardtime, .gms-cardnoscore, .gms-fixturedetails > div { border: 1px solid; border-color: silver } 35 .gms-cardtitle { font-weight: 700; font-size:larger } 36 .gms-cardfixture, .gms-cardscorers { display: flex; gap: 0.5rem; align-items: center } 33 37 .gms-cardhome { flex: 1 1 0%; text-align: right } 34 38 .gms-carddivide { padding: 0.25rem 0.5rem } 35 .gms-cardtime { font-weight: 700; border-radius: 0.375rem; background-color: white }39 .gms-cardtime, .gms-cardnoscore { font-weight: 700; border-radius: 0.375rem; background-color: white } 36 40 .gms-cardaway { flex: 1 1 0%; text-align: left } 37 .gms-list + .gms-footnote { margin-top: 1rem } 41 .gms-cardscorers { font-size: smaller } 42 .gms-cardstatus { background-color: black; color: white; margin: 0.25rem auto; width:fit-content; padding: 0.25rem 0.5rem } 43 .gms-fixture .gms-card > * { margin-top: 0.5rem; margin-bottom: 0.5rem } 44 .gms-fixturedetails { display: flex; flex-wrap: wrap; gap: 1rem } 45 .gms-fixturedetails > div { flex-grow: 1; padding: 0.5rem 0.5rem; border-radius: 0.5rem } 46 .gms-fixturedetails img { display: inline; width: 1.5rem; height: 1.5rem; vertical-align: middle; margin-right: 0.25rem } 47 .gms-fixturedetails ul { list-style-type: none; padding: 0; margin: 0 } 48 .gms-players li { display: flex; align-items: center } 49 .gms-players svg { width: 1rem; height: 1rem } 38 50 39 51 /* Creates a loader image for the AJAX wait */ -
eh-gms-feed/tags/3.10/eh-gms-feed.php
r3042119 r3046250 4 4 * Plugin URI: https://wordpress.org/plugins/eh-gms-feed/ 5 5 * Description: Show fixtures, results and tables from England Hockey GMS 6 * Version: 3. 96 * Version: 3.10 7 7 * Author: Matthew Treherne 8 8 * Author URI: https://profiles.wordpress.org/mtreherne -
eh-gms-feed/tags/3.10/includes/main-class.php
r3042119 r3046250 10 10 class EH_GMS_Feed { 11 11 12 private $basename, $settings, $atts_show, $not_valid, $filter_match, $table_name, $fixture_data, $display_name, $show_gender, $show_list, $show_cal, $cal_summary ;12 private $basename, $settings, $atts_show, $not_valid, $filter_match, $table_name, $fixture_data, $display_name, $show_gender, $show_list, $show_cal, $cal_summary, $id, $show_detail; 13 13 private $club_link, $team_link, $comp_link, $team_comps, $comp_name; 14 14 private $args = ['method','show','team','comp_id','club_id','whatson','link','sort_by','options']; … … 22 22 'compsinfixtures' => ['suffix' => 'fixturesandresults', 'transient' => 'TEAM', 'keys' => ['teams'], 'error_bag' => 'competition', 'expiry' => 'default'], 23 23 'competition' => ['suffix' => '', 'transient' => 'COMPETITION SUMMARY', 'keys' => ['competitions'], 'error_bag' => null, 'expiry' => 'default'], 24 'fixture' => ['suffix' => '', 'transient' => 'FIXTURE', 'keys' => ['fixtures'], 'error_bag' => null, 'expiry' => 'default'], 24 25 ]; 25 26 … … 176 177 } 177 178 179 private function show_goals ($events) { 180 $goals = []; 181 foreach ($events as $event) if (in_array($event->eventType,['FG','PC','PS'])) $goals[$event->memberId][] = $event; 182 $showGoals = []; 183 foreach ($goals as $goalsById) { 184 $playerName = ''; 185 $playerGoals = []; 186 foreach ($goalsById as $goal) { 187 if (!$playerName) $playerName = $goal->displayName; 188 $playerGoals[] = ($goal->minute ? $goal->minute . '′ ' : '') . $goal->eventType; 189 } 190 $showGoals[] = $playerName . ' (' . implode(', ',$playerGoals) . ')'; 191 } 192 return implode(', ', $showGoals); 193 } 194 195 private function show_players($players) { 196 $showPlayers = ''; 197 $withheld = 0; 198 foreach ($players as $player) { 199 if (!($player->consent || isset($player->shirtNumber))) { $withheld += 1; continue; } 200 $playerEvents = []; 201 foreach ($player->playerEvents as $event) { 202 switch ($event->eventType) { 203 case 'GC': $showType = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M1.892 20.5 12 3.959 22.109 20.5z" fill="#0FBD00" stroke="#0DA300"/></svg>'; break; 204 case 'YC': $showType = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="3.5" y=".5" width="17" height="23" rx="1.5" fill="#FFE500" stroke="#DBCA39"/></svg>'; break; 205 case 'RC': $showType = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10.5" fill="#E0251B" stroke="#E0251B"/></svg>'; break; 206 default : $showType = '<b>'.$event->eventType.'</b>'; 207 } 208 $playerEvents[] = ($event->minute ? '<b>'.$event->minute . '′ </b>' : '') . $showType; 209 } 210 switch ($player->otherRoleDescription) { 211 case 'Goalkeeper' : $role = ' (GK)'; break; 212 case 'Captain' : $role = ' (C)'; break; 213 default : $role = ''; 214 } 215 $showPlayers .= '<li>'.($player->shirtNumber ?? '') . ' ' . $player->displayName . $role . (!empty($playerEvents) ? (' ' . implode(', ',$playerEvents)) : '') . '</li>'; 216 } 217 if ($withheld) $showPlayers .= ($withheld > 1) ? '<li>Names Withheld (×'.$withheld.')</li>' : '<li>Name Withheld</li>'; 218 return $showPlayers; 219 } 220 221 private function show_officials($officials) { 222 $showOfficials = ''; 223 foreach ($officials as $official) { 224 if ($official->displayName != 'Name Withheld') $showOfficials .= '<li>' . $official->role . ': ' . $official->displayName . '</li>'; 225 } 226 return $showOfficials; 227 } 228 229 private function fixture_summary ($fixture, $valid_date, $show_detail=false) { 230 $html = ''; 231 $fixture_card = [ 232 'Date' => $valid_date->format('d M Y'), 233 'Time' => $fixture->fixtureTime == '00:00' ? '' : $fixture->fixtureTime, 234 'Home Team' => $fixture->homeTeam->teamName, 235 'Score' => '', 236 'Away Team' => $fixture->awayTeam->teamName, 237 'Venue' => !empty($fixture->venue) ? ($this->show_detail ? esc_html($fixture->venue) : '<a href="https://www.google.com/maps/search/?api=1&query='.urlencode($fixture->venue).'" target="_blank">'.esc_html($fixture->venue).'</a>') : '', 238 ]; 239 if ($show_detail) { 240 $home_goals = $this->show_goals($fixture->homeTeamEvents); 241 $away_goals = $this->show_goals($fixture->awayTeamEvents); 242 $address = !empty($fixture->venueDetails->address) ? $fixture->venueDetails->address . (!empty($fixture->venueDetails->postCode) ? ','.$fixture->venueDetails->postCode : '') : ''; 243 } 244 $score_class = ''; 245 $home_attr = $away_attr = $home_class = $away_class = []; 246 if ($fixture->isResult && !$fixture->isBye) { 247 $fixture_card['Score'] = $fixture->homeTeamScore . ' : ' . $fixture->awayTeamScore; 248 if ($fixture->status == 'Postponed' || ($fixture->homeTeamScore == 'P' && $fixture->awayTeamScore == 'P')); 249 elseif ($fixture->status == 'Cancelled' || ($fixture->homeTeamScore == 'C' && $fixture->awayTeamScore == 'C')); 250 elseif ($fixture->homeTeamScore == $fixture->awayTeamScore) $score_class = 'gms-draw'; 251 elseif (($fixture->homeTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->homeTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore > $fixture->awayTeamScore) $score_class = 'gms-win'; 252 elseif (($fixture->awayTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->awayTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore < $fixture->awayTeamScore) $score_class = 'gms-win'; 253 else $score_class = 'gms-loss'; 254 } 255 if ($this->is_clubteam($fixture->homeTeam) && $this->is_clubwide()) { 256 $home_class[] = 'gms-clubteam'; 257 $home_attr[] = 'data-team="'.($fixture->homeTeam->id).'"'; 258 if ($this->show_gender) $fixture_card['Home Team'] .= ' ('.$fixture->homeTeam->gender.')'; 259 } 260 if ($this->is_clubteam($fixture->awayTeam) && $this->is_clubwide()) { 261 $away_class[] = 'gms-clubteam'; 262 $away_attr[] = 'data-team="'.($fixture->awayTeam->id).'"'; 263 if ($this->show_gender) $fixture_card['Away Team'] .= ' ('.$fixture->awayTeam->gender.')'; 264 } 265 if ($this->show_list) { 266 $statusDisplay = !in_array($fixture->status, ['Active','Result','Bye']) ? $fixture->status : ''; 267 if ($fixture->isResult && ($fixture->homeTeamShootoutScore > 0 || $fixture->awayTeamShootoutScore > 0)) $statusDisplay = 'Shootout '.$fixture->homeTeamShootoutScore.' - '. $fixture->awayTeamShootoutScore; 268 $home_attr[] = 'class="'.implode(' ',$home_class).'"'; 269 $away_attr[] = 'class="'.implode(' ',$away_class).'"'; 270 if ($fixture->isBye) { 271 $divide = '- : -'; 272 $divide_attr = ' class="gms-carddivide gms-cardnoscore"'; 273 } 274 elseif ($fixture->isResult) { 275 $divide = $fixture_card['Score']; 276 $divide_attr = ' class="gms-carddivide '.($score_class ?: 'gms-cardnoscore').'"'; 277 } 278 else { 279 $divide = $fixture_card['Time'] ?: 'TBC'; 280 $divide_attr = ' class="gms-carddivide gms-cardtime"'; 281 } 282 $html .= '<div class="gms-card'.($this->show_detail ? ' gms-detaillink' : '').'"'.($this->show_detail ? ' data-fixture="'.$fixture->id.'"': '').'>' 283 .($show_detail ? '<div class="gms-cardtitle">Fixture Details</div>': '') 284 .'<div class="gms-carddate">'.$fixture_card['Date'].'</div>' 285 .'<div class="gms-cardfixture"><div class="gms-cardhome"><div '.implode(' ',$home_attr).'>'.$fixture_card['Home Team'].'</div></div><div'.$divide_attr.'>'.$divide.'</div><div class="gms-cardaway"><div '.implode(' ',$away_attr).'>'.$fixture_card['Away Team'].'</div></div></div>' 286 .(($show_detail && ($home_goals || $away_goals)) ? '<div class="gms-cardscorers"><div class="gms-cardhome"><div>'.$home_goals.'</div></div><div class="gms-carddivide"></div><div class="gms-cardaway"><div>'.$away_goals.'</div></div></div>' : '') 287 .($statusDisplay ? '<div class="gms-cardstatus">'.$statusDisplay.'</div>' : '') 288 .'<div class="gms-cardvenue">'.($fixture_card['Venue'] ?: 'Venue TBC').'</div>' 289 .($show_detail && $address ? '<div>'.$address.'</div>' : '') 290 .'</div>'; 291 if ($show_detail) { 292 $participant_details = false; 293 $html .= '<div class="gms-fixturedetails">'; 294 foreach (['home','away'] as $team) { 295 $showPlayers = $this->show_players($fixture->{$team . 'Players'}); 296 $showOfficials = $this->show_officials($fixture->{$team. 'TeamOfficials'}); 297 if ($showPlayers || $showOfficials) { 298 $club_logo = $fixture->{$team . 'Team'}->clubLogoUrl ?? null; 299 $participant_details = true; 300 $html .= '<div>'; 301 if ($showPlayers) $html .= '<div class="gms-players">'.($club_logo ? '<img src="'.$club_logo.'" onerror="this.style.display=\'none\'"></img>' : '').'<b>'.$fixture->{$team.'Team'}->teamName.'</b><ul>'.$showPlayers.'</ul></div>'; 302 if ($showOfficials) $html .= '<div class="gms-officials">'.($showPlayers ? '<br/>' : '').'<b>Coaching Roles</b><ul>'.$showOfficials.'</ul></div>'; 303 $html .= '</div>'; 304 } 305 } 306 $showOfficials = $this->show_officials($fixture->officials); 307 if ($showOfficials) { 308 $participant_details = true; 309 $html .= '<div class="gms-officials"><b>Match Officials</b><ul>'.$showOfficials.'</ul></div>'; 310 } 311 if (!$participant_details) $html .= '<div><b>No more details available</b></div>'; 312 $html .= '</div>'; 313 } 314 } 315 else { 316 $home_attr[] = 'class="'.implode(' ',$home_class).'"'; 317 $away_attr[] = 'class="'.implode(' ',$away_class).'"'; 318 $html .= $this->show_detail ? '<tr class="gms-detaillink" data-fixture="'.$fixture->id.'">': '<tr>'; 319 foreach ($this->fixture_data as $column_title => $field_name) { 320 $value = $fixture_card[$column_title]; 321 switch ($column_title) { 322 case 'Home Team' : $attr = implode(' ',$home_attr); break; 323 case 'Away Team' : $attr = implode(' ',$away_attr); break; 324 case 'Score' : $attr = 'class="'.$score_class.'"'; break; 325 default : $attr = ''; 326 } 327 $html .= '<td '.$attr.'>'.($column_title != 'Venue' ? esc_html($value) : $value).'</td>'; 328 } 329 $html .= '</tr>'; 330 } 331 return $html; 332 } 333 178 334 private function process_matches ($fixtures) { 179 335 $html = ''; … … 189 345 if ($this->filter_whatson($valid_date)) continue; 190 346 $this->filter_match = true; 191 $fixture_card = [ 192 'Date' => $valid_date->format('d M Y'), 193 'Time' => $fixture->fixtureTime == '00:00' ? '' : $fixture->fixtureTime, 194 'Home Team' => $fixture->homeTeam->teamName, 195 'Score' => '', 196 'Away Team' => $fixture->awayTeam->teamName, 197 'Venue' => !empty($fixture->venue) ? '<a href="https://www.google.com/maps/search/?api=1&query='.urlencode($fixture->venue).'" target="_blank">'.esc_html($fixture->venue).'</a>' : '' 198 ]; 199 $score_class = ''; 200 $home_attr = $away_attr = $home_class = $away_class = []; 201 if ($fixture->isResult && !$fixture->isBye) { 202 $fixture_card['Score'] = $fixture->homeTeamScore . ' : ' . $fixture->awayTeamScore; 203 if ($fixture->status == 'Postponed' || ($fixture->homeTeamScore == 'P' && $fixture->awayTeamScore == 'P')); 204 elseif ($fixture->homeTeamScore == $fixture->awayTeamScore) $score_class = 'gms-draw'; 205 elseif (($fixture->homeTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->homeTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore > $fixture->awayTeamScore) $score_class = 'gms-win'; 206 elseif (($fixture->awayTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->awayTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore < $fixture->awayTeamScore) $score_class = 'gms-win'; 207 else $score_class = 'gms-loss'; 208 } 209 if ($this->is_clubteam($fixture->homeTeam) && $this->is_clubwide()) { 210 $home_class[] = 'gms-clubteam'; 211 $home_attr[] = 'data-team="'.($fixture->homeTeam->id).'"'; 212 if ($this->show_gender) $fixture_card['Home Team'] .= ' ('.$fixture->homeTeam->gender.')'; 213 } 214 if ($this->is_clubteam($fixture->awayTeam) && $this->is_clubwide()) { 215 $away_class[] = 'gms-clubteam'; 216 $away_attr[] = 'data-team="'.($fixture->awayTeam->id).'"'; 217 if ($this->show_gender) $fixture_card['Away Team'] .= ' ('.$fixture->awayTeam->gender.')'; 218 } 219 if ($this->show_list) { 220 $home_class[] = 'gms-cardhome'; 221 $away_class[] = 'gms-cardaway'; 222 $home_attr[] = 'class="'.implode(' ',$home_class).'"'; 223 $away_attr[] = 'class="'.implode(' ',$away_class).'"'; 224 if ($fixture->isResult && !$fixture->isBye) { 225 $divide = $fixture_card['Score']; 226 $divide_attr = ' class="gms-carddivide '.$score_class.'"'; 227 } 228 else { 229 $divide = $fixture_card['Time'] ?: 'TBC'; 230 $divide_attr = ' class="gms-carddivide gms-cardtime"'; 231 } 232 $html .= '<div class="gms-card"><div class="gms-carddate">'.$fixture_card['Date'].'</div><div class="gms-cardfixture"><div '.implode(' ',$home_attr).'>'.$fixture_card['Home Team'].'</div><div'.$divide_attr.'>'.$divide.'</div><div '.implode(' ',$away_attr).'>'.$fixture_card['Away Team'].'</div></div><div class="gms-cardvenue">'.($fixture_card['Venue'] ?: 'Venue TBC').'</div></div>'; 233 } 234 else { 235 $home_attr[] = 'class="'.implode(' ',$home_class).'"'; 236 $away_attr[] = 'class="'.implode(' ',$away_class).'"'; 237 $html .= '<tr>'; 238 foreach ($this->fixture_data as $column_title => $field_name) { 239 $value = $fixture_card[$column_title]; 240 switch ($column_title) { 241 case 'Home Team' : $attr = implode(' ',$home_attr); break; 242 case 'Away Team' : $attr = implode(' ',$away_attr); break; 243 case 'Score' : $attr = 'class="'.$score_class.'"'; break; 244 default : $attr = ''; 245 } 246 $html .= '<td '.$attr.'>'.($column_title != 'Venue' ? esc_html($value) : $value).'</td>'; 247 } 248 $html .= '</tr>'; 249 } 347 $html .= $this->fixture_summary($fixture, $valid_date); 250 348 } 251 349 return $html; … … 380 478 } 381 479 480 private function process_fixture($data) { 481 $html = '<div class="gms-list">'; 482 $html .= $this->fixture_summary($data, new \DateTime($data->fixtureDate), true); 483 $html .= '</div>'; 484 $html .= '<div class="gms-footnote">'.sprintf(esc_html__( '[Fixture %2$s also found at%3$s %1$s]', 'eh-gms-feed'), '<a href="'.$this->get_link('fixture', $this->id).'" target="_blank">England Hockey Link</a>', '<span class="gms-nomobile">', '</span>').'</div>'; 485 return $html; 486 } 487 382 488 private function get_table() { 383 489 $html = ''; 384 490 $tables = []; 491 if (str_contains($this->atts_show['show'], 'fixture')) $tables[] = 'fixture'; 385 492 if (str_contains($this->atts_show['show'], 'league')) $tables[] = 'league'; 386 493 if (str_contains($this->atts_show['show'], 'results')) { … … 395 502 if ($table_name == 'fixtures') unset($this->fixture_data['Score']); 396 503 if ($table_name == 'league' && $this->is_competition()) { 397 if ($this->atts_show['link']) $this->comp_link = $this->atts_show['link'];504 if ($this->atts_show['link']) $this->comp_link = $this->atts_show['link']; 398 505 $html .= $this->get_json('competition', $this->atts_show['comp_id']); 399 506 } … … 407 514 } 408 515 elseif ($table_name == 'teams' && $this->is_clubwide()) { 409 if ($this->atts_show['link'])$this->club_link = $this->atts_show['link'];516 if ($this->atts_show['link']) $this->club_link = $this->atts_show['link']; 410 517 $html .= $this->get_json('teamslist', $this->atts_show['club_id']); 518 } 519 elseif ($table_name == 'fixture' && $this->id) { 520 $this->show_list = true; 521 $html .= $this->get_json('fixture', $this->id); 411 522 } 412 523 } … … 483 594 $this->atts_show['options'] = sanitize_text_field( $this->atts_show['options'] ); 484 595 if ($this->atts_show['method'] == 'api' || $this->atts_show['method'] == 'api-dynamic') { 485 if (empty($this->atts_show['club_id']) && ((!$this->is_competition() && !$this->is_team() ) || $this->atts_show['method'] == 'api-dynamic')) {596 if (empty($this->atts_show['club_id']) && ((!$this->is_competition() && !$this->is_team() && !$this->atts_show['show'] == 'fixture') || $this->atts_show['method'] == 'api-dynamic')) { 486 597 $message = esc_html__( 'Please enter a Club ID with the shortcode e.g. [gms club_id="19fd1b0c-e11c-46f9-9114-45c2262a1e90"], or set a default Club ID in the plugin settings.', 'eh-gms-feed' ); 487 598 $this->not_valid .= '<p>'.$message.'</p>'; … … 495 606 } 496 607 foreach (explode('+',$this->atts_show['show']) as $show) { 497 if (!in_array($show,['fixtures','results','league','teams' ])) {608 if (!in_array($show,['fixtures','results','league','teams','fixture'])) { 498 609 $message = sprintf(esc_html__( 'Please enter a "show" parameter (%s) equal to "fixtures", "results", "league" or "teams".', 'eh-gms-feed' ), $show ?: 'empty'); 499 610 $this->not_valid .= '<p>'.$message.'</p>'; … … 520 631 foreach ($options as $option) { 521 632 $option_split = array_map('trim', explode(':', $option)); 522 if ($option_split[0] == 'showgender' && ($option_split[1] ?? '') == 'yes') $this->show_gender = true; 523 if ($option_split[0] == 'showlist' && ($option_split[1] ?? '') == 'yes') $this->show_list = true; 524 if ($option_split[0] == 'showcal' && ($option_split[1] ?? '') == 'yes') $this->show_cal = true; 525 if ($option_split[0] == 'calsummary') $this->cal_summary = $option_split[1] ?? ''; 633 switch ($option_split[0]) { 634 case 'showgender' : if (($option_split[1] ?? '') == 'yes') $this->show_gender = true; break; 635 case 'showlist' : if (($option_split[1] ?? '') == 'yes') $this->show_list = true; break; 636 case 'showcal' : if (($option_split[1] ?? '') == 'yes') $this->show_cal = true; break; 637 case 'calsummary' : $this->cal_summary = $option_split[1] ?? ''; break; 638 case 'id' : $this->id = $option_split[1] ?? ''; break; 639 case 'showdetail' : if (($option_split[1] ?? '') == 'yes') $this->show_detail = true; break; 640 } 526 641 } 527 642 } … … 540 655 541 656 public function enqueue_scripts () { 542 wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3. 9', true);657 wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.10', true); 543 658 wp_localize_script('EH_GMS_Feed', 'eh_gms_feed_ajax_obj', ['ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce('get_gms_table')]); 544 wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3. 8');659 wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3.10'); 545 660 if ($this->settings->default_css == 'yes') wp_enqueue_style('EH_GMS_Feed'); 546 661 } -
eh-gms-feed/tags/3.10/js/eh-gms-feed.js
r3042119 r3046250 7 7 var refresh_message = 'The tables selected will be shown when you click on the <b>REFRESH</b> button.'; 8 8 9 function club_team (message, filter, wrapper) { 10 wrapper.find('.gms-clubteam[data-team]').css('cursor','pointer').on('click', function(e) { 9 function club_team (message, filter, wrapper, detail) { 10 var ele = detail ? detail : wrapper; 11 ele.find('.gms-clubteam[data-team]').css('cursor','pointer').prop('title', 'Select to filter by team').on('click', function(e) { 12 if (detail) { 13 detail.hide(); 14 filter.show(); 15 wrapper.show(); 16 } 11 17 var team = e.currentTarget.dataset.team; 12 18 filter.find('select[name="team"]').val(team); 13 19 team_change(message, filter, wrapper, team, function() { 14 20 filter.find('select[name="whatson"]').val(''); 15 if (filter.find('select[name="comp_id"]').val() != ' - All Competitions -' && filter.find('input[type="checkbox"][name="show"][value="results"]').prop('checked')) {21 if (filter.find('select[name="comp_id"]').val() != '' && filter.find('input[type="checkbox"][name="show"][value="results"]').prop('checked')) { 16 22 filter.find('input[type="checkbox"][name="show"][value="league"]').prop('checked',true); 17 23 } … … 63 69 } 64 70 71 function fixture_detail (message, filter, loader, wrapper) { 72 var detail = wrapper.next(); 73 wrapper.find('.gms-detaillink[data-fixture]').each(function() { 74 jQuery(this).on('click', function(e) { 75 var fixturelink = e.currentTarget; 76 var fixture = fixturelink.dataset.fixture; 77 message.text('Retrieving Fixture Details'); 78 if (filter) filter.hide(); 79 wrapper.hide(); 80 message.show(); 81 loader.show(); 82 message[0].scrollIntoView(); 83 var team = filter ? filter.find('select[name="team"]').val() : null; 84 var club_id = (wrapper.data('club_id') && !team) ? wrapper.data('club_id') : null; 85 jQuery.post(eh_gms_feed_ajax_obj.ajax_url, { _ajax_nonce: eh_gms_feed_ajax_obj.nonce, action: "get_gms_table", method: 'api', show: 'fixture', club_id: club_id, options: 'id:' + fixture }) 86 .always(function() { 87 loader.hide(); 88 }) 89 .done(function(data) { 90 message.hide(); 91 detail.html(data); 92 detail.show(); 93 detail[0].scrollIntoView(); 94 if (filter && !team) club_team(message, filter, wrapper, detail); 95 var goback = jQuery('<button type="button" class="gms-button">Go Back</button>').appendTo(detail); 96 goback.on('click', function(e) { 97 detail.hide(); 98 if (filter) filter.show(); 99 wrapper.show(); 100 fixturelink.scrollIntoView({ behavior: 'smooth', block: 'center' }); 101 }); 102 }) 103 .fail(function(response) { 104 detail.html(''); 105 message.text(error_message); 106 if (filter) filter.show(); 107 wrapper.show(); 108 }); 109 }); 110 }); 111 } 112 65 113 jQuery('div.gms-ajax').each(function() { 66 114 … … 69 117 if (ele.attr('data-request') != 'true') { 70 118 ele.attr('data-request','true'); 71 var message = jQuery('<p style="text-align: center; display: none "></p>').insertBefore(ele);119 var message = jQuery('<p style="text-align: center; display: none; scroll-margin-top: 1rem"></p>').insertBefore(ele); 72 120 var loader = jQuery('<div class="gms-loader" style="display: none"></div>').insertBefore(ele); 73 121 message.text('Retrieving GMS Table'); … … 81 129 .done(function(data) { 82 130 message.hide(); 131 var filter; 83 132 if (method=='api-dynamic') { 84 133 ele.html(data.html); 85 134 message.before(data.filter); 86 varfilter = message.prev();135 filter = message.prev(); 87 136 filter.find('select[name="team"]').on('change', function(e) { 88 137 team_change(message, filter, ele, e.target.value); … … 111 160 message.hide(); 112 161 ele.html(data); 113 club_team(message, filter, ele); 162 if (options && options.includes('showDetail:yes')) fixture_detail(message, filter, loader, ele); 163 else club_team(message, filter, ele); 114 164 }) 115 165 .fail(function(response) { … … 122 172 ele.html(refresh_message); 123 173 }); 124 club_team(message, filter, ele);174 if (!(options && options.includes('showDetail:yes'))) club_team(message, filter, ele); 125 175 } 126 176 else ele.html(data); 127 if (options && options.includes('showCal:yes')) ele.on('click', '.gms-copy', function(event) { 128 var text = event.target.dataset.copy_text; 129 var ele = document.getElementById(event.target.dataset.copy_id); 130 if (text) ele.textContent = text; 131 var range = document.createRange(); 132 var selection = window.getSelection(); 133 range.selectNodeContents(ele); 134 selection.removeAllRanges(); 135 selection.addRange(range); 136 document.execCommand('copy'); 137 }); 177 if (options) { 178 if (options.includes('showDetail:yes')) { 179 jQuery('<div class="gms-fixture" style="scroll-margin-top: 1rem"></div>').insertAfter(ele); 180 fixture_detail(message, filter, loader, ele); 181 } 182 if (options.includes('showCal:yes')) ele.on('click', '.gms-copy', function(event) { 183 var text = event.target.dataset.copy_text; 184 var ele = document.getElementById(event.target.dataset.copy_id); 185 if (text) ele.textContent = text; 186 var range = document.createRange(); 187 var selection = window.getSelection(); 188 range.selectNodeContents(ele); 189 selection.removeAllRanges(); 190 selection.addRange(range); 191 document.execCommand('copy'); 192 }); 193 } 138 194 }) 139 195 .fail(function(response) { -
eh-gms-feed/tags/3.10/readme.txt
r3042119 r3046250 3 3 Tags: hockey, GMS 4 4 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&[email protected]¤cy_code=GBP&item_name=Donation+for+EH+GMS+Feed 5 Tested up to: 6. 25 Tested up to: 6.3 6 6 Requires PHP: 5.3 7 Stable tag: 3. 97 Stable tag: 3.10 8 8 License: GPLv2 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 63 63 == Changelog == 64 64 65 = 3.10 = 66 * Added option to click through to fixture details 67 * Added status to fixture card e.g. for walkover and shootout result 68 * Change to default CSS for fixture details 69 * Fix to filter when selecting club team in multiple competitions 70 65 71 = 3.9 = 66 72 * Added option to provide link to WebCal with club teams list -
eh-gms-feed/trunk/css/gms-default.css
r2981152 r3046250 8 8 .gms-filter fieldset { width: fit-content } 9 9 .gms-filter legend { padding: 0px } 10 .gms-detaillink { cursor: pointer } 11 .gms-detaillink:hover { background-color: yellow } 10 12 11 13 /* This styling sets alignment for specific tables */ … … 26 28 @media screen and (max-width: 767px) { .gms-table { overflow-x: auto; display: block; white-space: nowrap } .gms-nomobile { display: none } } 27 29 28 /* Styling for fixtures and results displayed as list */30 /* Styling for fixtures and results displayed as list and fixture details */ 29 31 .gms-list > * + * { margin-top: 1.5rem; margin-bottom: 1.5rem } 32 .gms-list + .gms-footnote { margin-top: 1rem } 30 33 .gms-card { text-align: center; padding: 3px 3px; border-radius: 0.5rem } 31 .gms-card, .gms-cardtime { border: 1px solid; border-color: silver } 32 .gms-cardfixture { display: flex; gap: 0.5rem; align-items: center } 34 .gms-card, .gms-cardtime, .gms-cardnoscore, .gms-fixturedetails > div { border: 1px solid; border-color: silver } 35 .gms-cardtitle { font-weight: 700; font-size:larger } 36 .gms-cardfixture, .gms-cardscorers { display: flex; gap: 0.5rem; align-items: center } 33 37 .gms-cardhome { flex: 1 1 0%; text-align: right } 34 38 .gms-carddivide { padding: 0.25rem 0.5rem } 35 .gms-cardtime { font-weight: 700; border-radius: 0.375rem; background-color: white }39 .gms-cardtime, .gms-cardnoscore { font-weight: 700; border-radius: 0.375rem; background-color: white } 36 40 .gms-cardaway { flex: 1 1 0%; text-align: left } 37 .gms-list + .gms-footnote { margin-top: 1rem } 41 .gms-cardscorers { font-size: smaller } 42 .gms-cardstatus { background-color: black; color: white; margin: 0.25rem auto; width:fit-content; padding: 0.25rem 0.5rem } 43 .gms-fixture .gms-card > * { margin-top: 0.5rem; margin-bottom: 0.5rem } 44 .gms-fixturedetails { display: flex; flex-wrap: wrap; gap: 1rem } 45 .gms-fixturedetails > div { flex-grow: 1; padding: 0.5rem 0.5rem; border-radius: 0.5rem } 46 .gms-fixturedetails img { display: inline; width: 1.5rem; height: 1.5rem; vertical-align: middle; margin-right: 0.25rem } 47 .gms-fixturedetails ul { list-style-type: none; padding: 0; margin: 0 } 48 .gms-players li { display: flex; align-items: center } 49 .gms-players svg { width: 1rem; height: 1rem } 38 50 39 51 /* Creates a loader image for the AJAX wait */ -
eh-gms-feed/trunk/eh-gms-feed.php
r3042119 r3046250 4 4 * Plugin URI: https://wordpress.org/plugins/eh-gms-feed/ 5 5 * Description: Show fixtures, results and tables from England Hockey GMS 6 * Version: 3. 96 * Version: 3.10 7 7 * Author: Matthew Treherne 8 8 * Author URI: https://profiles.wordpress.org/mtreherne -
eh-gms-feed/trunk/includes/main-class.php
r3042119 r3046250 10 10 class EH_GMS_Feed { 11 11 12 private $basename, $settings, $atts_show, $not_valid, $filter_match, $table_name, $fixture_data, $display_name, $show_gender, $show_list, $show_cal, $cal_summary ;12 private $basename, $settings, $atts_show, $not_valid, $filter_match, $table_name, $fixture_data, $display_name, $show_gender, $show_list, $show_cal, $cal_summary, $id, $show_detail; 13 13 private $club_link, $team_link, $comp_link, $team_comps, $comp_name; 14 14 private $args = ['method','show','team','comp_id','club_id','whatson','link','sort_by','options']; … … 22 22 'compsinfixtures' => ['suffix' => 'fixturesandresults', 'transient' => 'TEAM', 'keys' => ['teams'], 'error_bag' => 'competition', 'expiry' => 'default'], 23 23 'competition' => ['suffix' => '', 'transient' => 'COMPETITION SUMMARY', 'keys' => ['competitions'], 'error_bag' => null, 'expiry' => 'default'], 24 'fixture' => ['suffix' => '', 'transient' => 'FIXTURE', 'keys' => ['fixtures'], 'error_bag' => null, 'expiry' => 'default'], 24 25 ]; 25 26 … … 176 177 } 177 178 179 private function show_goals ($events) { 180 $goals = []; 181 foreach ($events as $event) if (in_array($event->eventType,['FG','PC','PS'])) $goals[$event->memberId][] = $event; 182 $showGoals = []; 183 foreach ($goals as $goalsById) { 184 $playerName = ''; 185 $playerGoals = []; 186 foreach ($goalsById as $goal) { 187 if (!$playerName) $playerName = $goal->displayName; 188 $playerGoals[] = ($goal->minute ? $goal->minute . '′ ' : '') . $goal->eventType; 189 } 190 $showGoals[] = $playerName . ' (' . implode(', ',$playerGoals) . ')'; 191 } 192 return implode(', ', $showGoals); 193 } 194 195 private function show_players($players) { 196 $showPlayers = ''; 197 $withheld = 0; 198 foreach ($players as $player) { 199 if (!($player->consent || isset($player->shirtNumber))) { $withheld += 1; continue; } 200 $playerEvents = []; 201 foreach ($player->playerEvents as $event) { 202 switch ($event->eventType) { 203 case 'GC': $showType = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M1.892 20.5 12 3.959 22.109 20.5z" fill="#0FBD00" stroke="#0DA300"/></svg>'; break; 204 case 'YC': $showType = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="3.5" y=".5" width="17" height="23" rx="1.5" fill="#FFE500" stroke="#DBCA39"/></svg>'; break; 205 case 'RC': $showType = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10.5" fill="#E0251B" stroke="#E0251B"/></svg>'; break; 206 default : $showType = '<b>'.$event->eventType.'</b>'; 207 } 208 $playerEvents[] = ($event->minute ? '<b>'.$event->minute . '′ </b>' : '') . $showType; 209 } 210 switch ($player->otherRoleDescription) { 211 case 'Goalkeeper' : $role = ' (GK)'; break; 212 case 'Captain' : $role = ' (C)'; break; 213 default : $role = ''; 214 } 215 $showPlayers .= '<li>'.($player->shirtNumber ?? '') . ' ' . $player->displayName . $role . (!empty($playerEvents) ? (' ' . implode(', ',$playerEvents)) : '') . '</li>'; 216 } 217 if ($withheld) $showPlayers .= ($withheld > 1) ? '<li>Names Withheld (×'.$withheld.')</li>' : '<li>Name Withheld</li>'; 218 return $showPlayers; 219 } 220 221 private function show_officials($officials) { 222 $showOfficials = ''; 223 foreach ($officials as $official) { 224 if ($official->displayName != 'Name Withheld') $showOfficials .= '<li>' . $official->role . ': ' . $official->displayName . '</li>'; 225 } 226 return $showOfficials; 227 } 228 229 private function fixture_summary ($fixture, $valid_date, $show_detail=false) { 230 $html = ''; 231 $fixture_card = [ 232 'Date' => $valid_date->format('d M Y'), 233 'Time' => $fixture->fixtureTime == '00:00' ? '' : $fixture->fixtureTime, 234 'Home Team' => $fixture->homeTeam->teamName, 235 'Score' => '', 236 'Away Team' => $fixture->awayTeam->teamName, 237 'Venue' => !empty($fixture->venue) ? ($this->show_detail ? esc_html($fixture->venue) : '<a href="https://www.google.com/maps/search/?api=1&query='.urlencode($fixture->venue).'" target="_blank">'.esc_html($fixture->venue).'</a>') : '', 238 ]; 239 if ($show_detail) { 240 $home_goals = $this->show_goals($fixture->homeTeamEvents); 241 $away_goals = $this->show_goals($fixture->awayTeamEvents); 242 $address = !empty($fixture->venueDetails->address) ? $fixture->venueDetails->address . (!empty($fixture->venueDetails->postCode) ? ','.$fixture->venueDetails->postCode : '') : ''; 243 } 244 $score_class = ''; 245 $home_attr = $away_attr = $home_class = $away_class = []; 246 if ($fixture->isResult && !$fixture->isBye) { 247 $fixture_card['Score'] = $fixture->homeTeamScore . ' : ' . $fixture->awayTeamScore; 248 if ($fixture->status == 'Postponed' || ($fixture->homeTeamScore == 'P' && $fixture->awayTeamScore == 'P')); 249 elseif ($fixture->status == 'Cancelled' || ($fixture->homeTeamScore == 'C' && $fixture->awayTeamScore == 'C')); 250 elseif ($fixture->homeTeamScore == $fixture->awayTeamScore) $score_class = 'gms-draw'; 251 elseif (($fixture->homeTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->homeTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore > $fixture->awayTeamScore) $score_class = 'gms-win'; 252 elseif (($fixture->awayTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->awayTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore < $fixture->awayTeamScore) $score_class = 'gms-win'; 253 else $score_class = 'gms-loss'; 254 } 255 if ($this->is_clubteam($fixture->homeTeam) && $this->is_clubwide()) { 256 $home_class[] = 'gms-clubteam'; 257 $home_attr[] = 'data-team="'.($fixture->homeTeam->id).'"'; 258 if ($this->show_gender) $fixture_card['Home Team'] .= ' ('.$fixture->homeTeam->gender.')'; 259 } 260 if ($this->is_clubteam($fixture->awayTeam) && $this->is_clubwide()) { 261 $away_class[] = 'gms-clubteam'; 262 $away_attr[] = 'data-team="'.($fixture->awayTeam->id).'"'; 263 if ($this->show_gender) $fixture_card['Away Team'] .= ' ('.$fixture->awayTeam->gender.')'; 264 } 265 if ($this->show_list) { 266 $statusDisplay = !in_array($fixture->status, ['Active','Result','Bye']) ? $fixture->status : ''; 267 if ($fixture->isResult && ($fixture->homeTeamShootoutScore > 0 || $fixture->awayTeamShootoutScore > 0)) $statusDisplay = 'Shootout '.$fixture->homeTeamShootoutScore.' - '. $fixture->awayTeamShootoutScore; 268 $home_attr[] = 'class="'.implode(' ',$home_class).'"'; 269 $away_attr[] = 'class="'.implode(' ',$away_class).'"'; 270 if ($fixture->isBye) { 271 $divide = '- : -'; 272 $divide_attr = ' class="gms-carddivide gms-cardnoscore"'; 273 } 274 elseif ($fixture->isResult) { 275 $divide = $fixture_card['Score']; 276 $divide_attr = ' class="gms-carddivide '.($score_class ?: 'gms-cardnoscore').'"'; 277 } 278 else { 279 $divide = $fixture_card['Time'] ?: 'TBC'; 280 $divide_attr = ' class="gms-carddivide gms-cardtime"'; 281 } 282 $html .= '<div class="gms-card'.($this->show_detail ? ' gms-detaillink' : '').'"'.($this->show_detail ? ' data-fixture="'.$fixture->id.'"': '').'>' 283 .($show_detail ? '<div class="gms-cardtitle">Fixture Details</div>': '') 284 .'<div class="gms-carddate">'.$fixture_card['Date'].'</div>' 285 .'<div class="gms-cardfixture"><div class="gms-cardhome"><div '.implode(' ',$home_attr).'>'.$fixture_card['Home Team'].'</div></div><div'.$divide_attr.'>'.$divide.'</div><div class="gms-cardaway"><div '.implode(' ',$away_attr).'>'.$fixture_card['Away Team'].'</div></div></div>' 286 .(($show_detail && ($home_goals || $away_goals)) ? '<div class="gms-cardscorers"><div class="gms-cardhome"><div>'.$home_goals.'</div></div><div class="gms-carddivide"></div><div class="gms-cardaway"><div>'.$away_goals.'</div></div></div>' : '') 287 .($statusDisplay ? '<div class="gms-cardstatus">'.$statusDisplay.'</div>' : '') 288 .'<div class="gms-cardvenue">'.($fixture_card['Venue'] ?: 'Venue TBC').'</div>' 289 .($show_detail && $address ? '<div>'.$address.'</div>' : '') 290 .'</div>'; 291 if ($show_detail) { 292 $participant_details = false; 293 $html .= '<div class="gms-fixturedetails">'; 294 foreach (['home','away'] as $team) { 295 $showPlayers = $this->show_players($fixture->{$team . 'Players'}); 296 $showOfficials = $this->show_officials($fixture->{$team. 'TeamOfficials'}); 297 if ($showPlayers || $showOfficials) { 298 $club_logo = $fixture->{$team . 'Team'}->clubLogoUrl ?? null; 299 $participant_details = true; 300 $html .= '<div>'; 301 if ($showPlayers) $html .= '<div class="gms-players">'.($club_logo ? '<img src="'.$club_logo.'" onerror="this.style.display=\'none\'"></img>' : '').'<b>'.$fixture->{$team.'Team'}->teamName.'</b><ul>'.$showPlayers.'</ul></div>'; 302 if ($showOfficials) $html .= '<div class="gms-officials">'.($showPlayers ? '<br/>' : '').'<b>Coaching Roles</b><ul>'.$showOfficials.'</ul></div>'; 303 $html .= '</div>'; 304 } 305 } 306 $showOfficials = $this->show_officials($fixture->officials); 307 if ($showOfficials) { 308 $participant_details = true; 309 $html .= '<div class="gms-officials"><b>Match Officials</b><ul>'.$showOfficials.'</ul></div>'; 310 } 311 if (!$participant_details) $html .= '<div><b>No more details available</b></div>'; 312 $html .= '</div>'; 313 } 314 } 315 else { 316 $home_attr[] = 'class="'.implode(' ',$home_class).'"'; 317 $away_attr[] = 'class="'.implode(' ',$away_class).'"'; 318 $html .= $this->show_detail ? '<tr class="gms-detaillink" data-fixture="'.$fixture->id.'">': '<tr>'; 319 foreach ($this->fixture_data as $column_title => $field_name) { 320 $value = $fixture_card[$column_title]; 321 switch ($column_title) { 322 case 'Home Team' : $attr = implode(' ',$home_attr); break; 323 case 'Away Team' : $attr = implode(' ',$away_attr); break; 324 case 'Score' : $attr = 'class="'.$score_class.'"'; break; 325 default : $attr = ''; 326 } 327 $html .= '<td '.$attr.'>'.($column_title != 'Venue' ? esc_html($value) : $value).'</td>'; 328 } 329 $html .= '</tr>'; 330 } 331 return $html; 332 } 333 178 334 private function process_matches ($fixtures) { 179 335 $html = ''; … … 189 345 if ($this->filter_whatson($valid_date)) continue; 190 346 $this->filter_match = true; 191 $fixture_card = [ 192 'Date' => $valid_date->format('d M Y'), 193 'Time' => $fixture->fixtureTime == '00:00' ? '' : $fixture->fixtureTime, 194 'Home Team' => $fixture->homeTeam->teamName, 195 'Score' => '', 196 'Away Team' => $fixture->awayTeam->teamName, 197 'Venue' => !empty($fixture->venue) ? '<a href="https://www.google.com/maps/search/?api=1&query='.urlencode($fixture->venue).'" target="_blank">'.esc_html($fixture->venue).'</a>' : '' 198 ]; 199 $score_class = ''; 200 $home_attr = $away_attr = $home_class = $away_class = []; 201 if ($fixture->isResult && !$fixture->isBye) { 202 $fixture_card['Score'] = $fixture->homeTeamScore . ' : ' . $fixture->awayTeamScore; 203 if ($fixture->status == 'Postponed' || ($fixture->homeTeamScore == 'P' && $fixture->awayTeamScore == 'P')); 204 elseif ($fixture->homeTeamScore == $fixture->awayTeamScore) $score_class = 'gms-draw'; 205 elseif (($fixture->homeTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->homeTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore > $fixture->awayTeamScore) $score_class = 'gms-win'; 206 elseif (($fixture->awayTeam->id == $this->atts_show['team'] || ($this->is_clubwide() && $fixture->awayTeam->clubId == $this->atts_show['club_id'])) && $fixture->homeTeamScore < $fixture->awayTeamScore) $score_class = 'gms-win'; 207 else $score_class = 'gms-loss'; 208 } 209 if ($this->is_clubteam($fixture->homeTeam) && $this->is_clubwide()) { 210 $home_class[] = 'gms-clubteam'; 211 $home_attr[] = 'data-team="'.($fixture->homeTeam->id).'"'; 212 if ($this->show_gender) $fixture_card['Home Team'] .= ' ('.$fixture->homeTeam->gender.')'; 213 } 214 if ($this->is_clubteam($fixture->awayTeam) && $this->is_clubwide()) { 215 $away_class[] = 'gms-clubteam'; 216 $away_attr[] = 'data-team="'.($fixture->awayTeam->id).'"'; 217 if ($this->show_gender) $fixture_card['Away Team'] .= ' ('.$fixture->awayTeam->gender.')'; 218 } 219 if ($this->show_list) { 220 $home_class[] = 'gms-cardhome'; 221 $away_class[] = 'gms-cardaway'; 222 $home_attr[] = 'class="'.implode(' ',$home_class).'"'; 223 $away_attr[] = 'class="'.implode(' ',$away_class).'"'; 224 if ($fixture->isResult && !$fixture->isBye) { 225 $divide = $fixture_card['Score']; 226 $divide_attr = ' class="gms-carddivide '.$score_class.'"'; 227 } 228 else { 229 $divide = $fixture_card['Time'] ?: 'TBC'; 230 $divide_attr = ' class="gms-carddivide gms-cardtime"'; 231 } 232 $html .= '<div class="gms-card"><div class="gms-carddate">'.$fixture_card['Date'].'</div><div class="gms-cardfixture"><div '.implode(' ',$home_attr).'>'.$fixture_card['Home Team'].'</div><div'.$divide_attr.'>'.$divide.'</div><div '.implode(' ',$away_attr).'>'.$fixture_card['Away Team'].'</div></div><div class="gms-cardvenue">'.($fixture_card['Venue'] ?: 'Venue TBC').'</div></div>'; 233 } 234 else { 235 $home_attr[] = 'class="'.implode(' ',$home_class).'"'; 236 $away_attr[] = 'class="'.implode(' ',$away_class).'"'; 237 $html .= '<tr>'; 238 foreach ($this->fixture_data as $column_title => $field_name) { 239 $value = $fixture_card[$column_title]; 240 switch ($column_title) { 241 case 'Home Team' : $attr = implode(' ',$home_attr); break; 242 case 'Away Team' : $attr = implode(' ',$away_attr); break; 243 case 'Score' : $attr = 'class="'.$score_class.'"'; break; 244 default : $attr = ''; 245 } 246 $html .= '<td '.$attr.'>'.($column_title != 'Venue' ? esc_html($value) : $value).'</td>'; 247 } 248 $html .= '</tr>'; 249 } 347 $html .= $this->fixture_summary($fixture, $valid_date); 250 348 } 251 349 return $html; … … 380 478 } 381 479 480 private function process_fixture($data) { 481 $html = '<div class="gms-list">'; 482 $html .= $this->fixture_summary($data, new \DateTime($data->fixtureDate), true); 483 $html .= '</div>'; 484 $html .= '<div class="gms-footnote">'.sprintf(esc_html__( '[Fixture %2$s also found at%3$s %1$s]', 'eh-gms-feed'), '<a href="'.$this->get_link('fixture', $this->id).'" target="_blank">England Hockey Link</a>', '<span class="gms-nomobile">', '</span>').'</div>'; 485 return $html; 486 } 487 382 488 private function get_table() { 383 489 $html = ''; 384 490 $tables = []; 491 if (str_contains($this->atts_show['show'], 'fixture')) $tables[] = 'fixture'; 385 492 if (str_contains($this->atts_show['show'], 'league')) $tables[] = 'league'; 386 493 if (str_contains($this->atts_show['show'], 'results')) { … … 395 502 if ($table_name == 'fixtures') unset($this->fixture_data['Score']); 396 503 if ($table_name == 'league' && $this->is_competition()) { 397 if ($this->atts_show['link']) $this->comp_link = $this->atts_show['link'];504 if ($this->atts_show['link']) $this->comp_link = $this->atts_show['link']; 398 505 $html .= $this->get_json('competition', $this->atts_show['comp_id']); 399 506 } … … 407 514 } 408 515 elseif ($table_name == 'teams' && $this->is_clubwide()) { 409 if ($this->atts_show['link'])$this->club_link = $this->atts_show['link'];516 if ($this->atts_show['link']) $this->club_link = $this->atts_show['link']; 410 517 $html .= $this->get_json('teamslist', $this->atts_show['club_id']); 518 } 519 elseif ($table_name == 'fixture' && $this->id) { 520 $this->show_list = true; 521 $html .= $this->get_json('fixture', $this->id); 411 522 } 412 523 } … … 483 594 $this->atts_show['options'] = sanitize_text_field( $this->atts_show['options'] ); 484 595 if ($this->atts_show['method'] == 'api' || $this->atts_show['method'] == 'api-dynamic') { 485 if (empty($this->atts_show['club_id']) && ((!$this->is_competition() && !$this->is_team() ) || $this->atts_show['method'] == 'api-dynamic')) {596 if (empty($this->atts_show['club_id']) && ((!$this->is_competition() && !$this->is_team() && !$this->atts_show['show'] == 'fixture') || $this->atts_show['method'] == 'api-dynamic')) { 486 597 $message = esc_html__( 'Please enter a Club ID with the shortcode e.g. [gms club_id="19fd1b0c-e11c-46f9-9114-45c2262a1e90"], or set a default Club ID in the plugin settings.', 'eh-gms-feed' ); 487 598 $this->not_valid .= '<p>'.$message.'</p>'; … … 495 606 } 496 607 foreach (explode('+',$this->atts_show['show']) as $show) { 497 if (!in_array($show,['fixtures','results','league','teams' ])) {608 if (!in_array($show,['fixtures','results','league','teams','fixture'])) { 498 609 $message = sprintf(esc_html__( 'Please enter a "show" parameter (%s) equal to "fixtures", "results", "league" or "teams".', 'eh-gms-feed' ), $show ?: 'empty'); 499 610 $this->not_valid .= '<p>'.$message.'</p>'; … … 520 631 foreach ($options as $option) { 521 632 $option_split = array_map('trim', explode(':', $option)); 522 if ($option_split[0] == 'showgender' && ($option_split[1] ?? '') == 'yes') $this->show_gender = true; 523 if ($option_split[0] == 'showlist' && ($option_split[1] ?? '') == 'yes') $this->show_list = true; 524 if ($option_split[0] == 'showcal' && ($option_split[1] ?? '') == 'yes') $this->show_cal = true; 525 if ($option_split[0] == 'calsummary') $this->cal_summary = $option_split[1] ?? ''; 633 switch ($option_split[0]) { 634 case 'showgender' : if (($option_split[1] ?? '') == 'yes') $this->show_gender = true; break; 635 case 'showlist' : if (($option_split[1] ?? '') == 'yes') $this->show_list = true; break; 636 case 'showcal' : if (($option_split[1] ?? '') == 'yes') $this->show_cal = true; break; 637 case 'calsummary' : $this->cal_summary = $option_split[1] ?? ''; break; 638 case 'id' : $this->id = $option_split[1] ?? ''; break; 639 case 'showdetail' : if (($option_split[1] ?? '') == 'yes') $this->show_detail = true; break; 640 } 526 641 } 527 642 } … … 540 655 541 656 public function enqueue_scripts () { 542 wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3. 9', true);657 wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.10', true); 543 658 wp_localize_script('EH_GMS_Feed', 'eh_gms_feed_ajax_obj', ['ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce('get_gms_table')]); 544 wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3. 8');659 wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3.10'); 545 660 if ($this->settings->default_css == 'yes') wp_enqueue_style('EH_GMS_Feed'); 546 661 } -
eh-gms-feed/trunk/js/eh-gms-feed.js
r3042119 r3046250 7 7 var refresh_message = 'The tables selected will be shown when you click on the <b>REFRESH</b> button.'; 8 8 9 function club_team (message, filter, wrapper) { 10 wrapper.find('.gms-clubteam[data-team]').css('cursor','pointer').on('click', function(e) { 9 function club_team (message, filter, wrapper, detail) { 10 var ele = detail ? detail : wrapper; 11 ele.find('.gms-clubteam[data-team]').css('cursor','pointer').prop('title', 'Select to filter by team').on('click', function(e) { 12 if (detail) { 13 detail.hide(); 14 filter.show(); 15 wrapper.show(); 16 } 11 17 var team = e.currentTarget.dataset.team; 12 18 filter.find('select[name="team"]').val(team); 13 19 team_change(message, filter, wrapper, team, function() { 14 20 filter.find('select[name="whatson"]').val(''); 15 if (filter.find('select[name="comp_id"]').val() != ' - All Competitions -' && filter.find('input[type="checkbox"][name="show"][value="results"]').prop('checked')) {21 if (filter.find('select[name="comp_id"]').val() != '' && filter.find('input[type="checkbox"][name="show"][value="results"]').prop('checked')) { 16 22 filter.find('input[type="checkbox"][name="show"][value="league"]').prop('checked',true); 17 23 } … … 63 69 } 64 70 71 function fixture_detail (message, filter, loader, wrapper) { 72 var detail = wrapper.next(); 73 wrapper.find('.gms-detaillink[data-fixture]').each(function() { 74 jQuery(this).on('click', function(e) { 75 var fixturelink = e.currentTarget; 76 var fixture = fixturelink.dataset.fixture; 77 message.text('Retrieving Fixture Details'); 78 if (filter) filter.hide(); 79 wrapper.hide(); 80 message.show(); 81 loader.show(); 82 message[0].scrollIntoView(); 83 var team = filter ? filter.find('select[name="team"]').val() : null; 84 var club_id = (wrapper.data('club_id') && !team) ? wrapper.data('club_id') : null; 85 jQuery.post(eh_gms_feed_ajax_obj.ajax_url, { _ajax_nonce: eh_gms_feed_ajax_obj.nonce, action: "get_gms_table", method: 'api', show: 'fixture', club_id: club_id, options: 'id:' + fixture }) 86 .always(function() { 87 loader.hide(); 88 }) 89 .done(function(data) { 90 message.hide(); 91 detail.html(data); 92 detail.show(); 93 detail[0].scrollIntoView(); 94 if (filter && !team) club_team(message, filter, wrapper, detail); 95 var goback = jQuery('<button type="button" class="gms-button">Go Back</button>').appendTo(detail); 96 goback.on('click', function(e) { 97 detail.hide(); 98 if (filter) filter.show(); 99 wrapper.show(); 100 fixturelink.scrollIntoView({ behavior: 'smooth', block: 'center' }); 101 }); 102 }) 103 .fail(function(response) { 104 detail.html(''); 105 message.text(error_message); 106 if (filter) filter.show(); 107 wrapper.show(); 108 }); 109 }); 110 }); 111 } 112 65 113 jQuery('div.gms-ajax').each(function() { 66 114 … … 69 117 if (ele.attr('data-request') != 'true') { 70 118 ele.attr('data-request','true'); 71 var message = jQuery('<p style="text-align: center; display: none "></p>').insertBefore(ele);119 var message = jQuery('<p style="text-align: center; display: none; scroll-margin-top: 1rem"></p>').insertBefore(ele); 72 120 var loader = jQuery('<div class="gms-loader" style="display: none"></div>').insertBefore(ele); 73 121 message.text('Retrieving GMS Table'); … … 81 129 .done(function(data) { 82 130 message.hide(); 131 var filter; 83 132 if (method=='api-dynamic') { 84 133 ele.html(data.html); 85 134 message.before(data.filter); 86 varfilter = message.prev();135 filter = message.prev(); 87 136 filter.find('select[name="team"]').on('change', function(e) { 88 137 team_change(message, filter, ele, e.target.value); … … 111 160 message.hide(); 112 161 ele.html(data); 113 club_team(message, filter, ele); 162 if (options && options.includes('showDetail:yes')) fixture_detail(message, filter, loader, ele); 163 else club_team(message, filter, ele); 114 164 }) 115 165 .fail(function(response) { … … 122 172 ele.html(refresh_message); 123 173 }); 124 club_team(message, filter, ele);174 if (!(options && options.includes('showDetail:yes'))) club_team(message, filter, ele); 125 175 } 126 176 else ele.html(data); 127 if (options && options.includes('showCal:yes')) ele.on('click', '.gms-copy', function(event) { 128 var text = event.target.dataset.copy_text; 129 var ele = document.getElementById(event.target.dataset.copy_id); 130 if (text) ele.textContent = text; 131 var range = document.createRange(); 132 var selection = window.getSelection(); 133 range.selectNodeContents(ele); 134 selection.removeAllRanges(); 135 selection.addRange(range); 136 document.execCommand('copy'); 137 }); 177 if (options) { 178 if (options.includes('showDetail:yes')) { 179 jQuery('<div class="gms-fixture" style="scroll-margin-top: 1rem"></div>').insertAfter(ele); 180 fixture_detail(message, filter, loader, ele); 181 } 182 if (options.includes('showCal:yes')) ele.on('click', '.gms-copy', function(event) { 183 var text = event.target.dataset.copy_text; 184 var ele = document.getElementById(event.target.dataset.copy_id); 185 if (text) ele.textContent = text; 186 var range = document.createRange(); 187 var selection = window.getSelection(); 188 range.selectNodeContents(ele); 189 selection.removeAllRanges(); 190 selection.addRange(range); 191 document.execCommand('copy'); 192 }); 193 } 138 194 }) 139 195 .fail(function(response) { -
eh-gms-feed/trunk/readme.txt
r3042119 r3046250 3 3 Tags: hockey, GMS 4 4 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&[email protected]¤cy_code=GBP&item_name=Donation+for+EH+GMS+Feed 5 Tested up to: 6. 25 Tested up to: 6.3 6 6 Requires PHP: 5.3 7 Stable tag: 3. 97 Stable tag: 3.10 8 8 License: GPLv2 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 63 63 == Changelog == 64 64 65 = 3.10 = 66 * Added option to click through to fixture details 67 * Added status to fixture card e.g. for walkover and shootout result 68 * Change to default CSS for fixture details 69 * Fix to filter when selecting club team in multiple competitions 70 65 71 = 3.9 = 66 72 * Added option to provide link to WebCal with club teams list
Note: See TracChangeset
for help on using the changeset viewer.