Changeset 3066677
- Timestamp:
- 04/08/2024 08:27:42 AM (23 months ago)
- Location:
- eh-gms-feed
- Files:
-
- 14 edited
-
tags/3.14/css/gms-default.css (modified) (1 diff)
-
tags/3.14/eh-gms-feed.php (modified) (1 diff)
-
tags/3.14/includes/coreAPI.php (modified) (15 diffs)
-
tags/3.14/includes/main-class.php (modified) (4 diffs)
-
tags/3.14/includes/settings.php (modified) (2 diffs)
-
tags/3.14/js/eh-gms-feed.js (modified) (2 diffs)
-
tags/3.14/readme.txt (modified) (2 diffs)
-
trunk/css/gms-default.css (modified) (1 diff)
-
trunk/eh-gms-feed.php (modified) (1 diff)
-
trunk/includes/coreAPI.php (modified) (15 diffs)
-
trunk/includes/main-class.php (modified) (4 diffs)
-
trunk/includes/settings.php (modified) (2 diffs)
-
trunk/js/eh-gms-feed.js (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
eh-gms-feed/tags/3.14/css/gms-default.css
r3064521 r3066677 4 4 .gms-table th, .gms-table td { border: 1px solid; padding: 3px 10px; border-color: silver } 5 5 .gms-footnote, .gms-filter { margin: 0 0 2rem } 6 .gms-clubteam { font-weight: 700 }6 .gms-clubteam:not(.gms-button) { font-weight: 700 } 7 7 .gms-filter > div { margin: 0 0 1rem } 8 8 .gms-filter fieldset { width: fit-content } -
eh-gms-feed/tags/3.14/eh-gms-feed.php
r3065987 r3066677 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.1 36 * Version: 3.14 7 7 * Author: Matthew Treherne 8 8 * Author URI: https://profiles.wordpress.org/mtreherne -
eh-gms-feed/tags/3.14/includes/coreAPI.php
r3065987 r3066677 4 4 class coreAPI { 5 5 6 public $error_bag, $api_error = false, $atts_show, $show_gender, $show_list, $show_cal, $cal_summary, $id, $show_detail, $directions, $multiple_teams = [], $teamlimit = 12;6 public $error_bag, $api_error = false, $atts_show, $show_gender, $show_list, $show_cal, $cal_summary, $id, $show_detail, $directions, $multiple_teams = [], $teamlimit = 12, $detailClubTeam; 7 7 8 8 protected $settings; … … 18 18 'fixturesandresults' => ['transient' => 'TEAM', 'keys' => ['teams'], 'error_bag' => null, 'expiry' => 'default'], 19 19 'matchdays' => ['transient' => 'CLUB MATCHDAYS', 'keys' => ['clubs'], 'error_bag' => null, 'expiry' => 'default'], 20 'matchday' => ['suffix' => '', 'transient' => 'CLUB MATCHDAY', 'keys' => ['clubs', 'matchdays'], 'error_bag' => null, 'expiry' => ' static'],20 'matchday' => ['suffix' => '', 'transient' => 'CLUB MATCHDAY', 'keys' => ['clubs', 'matchdays'], 'error_bag' => null, 'expiry' => 'daily'], 21 21 'teamsinclub' => ['suffix' => 'teams', 'transient' => 'CLUB TEAMS', 'keys' => ['clubs'], 'error_bag' => 'teamselected', 'expiry' => 'static'], 22 22 'teamslist' => ['suffix' => 'teams', 'transient' => 'CLUB TEAMS', 'keys' => ['clubs'], 'error_bag' => null, 'expiry' => 'static'], … … 24 24 'competition' => ['suffix' => '', 'transient' => 'COMPETITION SUMMARY', 'keys' => ['competitions'], 'error_bag' => null, 'expiry' => 'default'], 25 25 'fixture' => ['suffix' => '', 'transient' => 'FIXTURE', 'keys' => ['fixtures'], 'error_bag' => null, 'expiry' => 'default'], 26 'customteam' => ['suffix' => 'fixturesandresults', 'transient' => 'TEAM ', 'keys' => ['teams'], 'error_bag' => 'customteam', 'expiry' => 'default'],26 'customteam' => ['suffix' => 'fixturesandresults', 'transient' => 'TEAMRESULTS', 'keys' => ['teams'], 'error_bag' => 'customteam', 'expiry' => 'default'], 27 27 ]; 28 28 29 29 public function __construct () { 30 $this->settings->default_transient_expiry = '3600'; 30 if (!isset($this->settings)) $this->settings = new \stdClass; 31 $this->settings->gms_api_url = 'https://eh-dw-prod.azurewebsites.net/api/'; 32 $this->settings->gms_api_key = '2RRafa42yMEJAUuXlrsXh04nanHcbO/XT81uPQrEMBSVN1LEqpnFvA=='; 33 if (!isset($this->settings->default_transient_expiry)) $this->settings->default_transient_expiry = '3600'; 31 34 $this->settings->static_transient_expiry = '86400'; 35 $this->settings->daily_transient_expiry = '86400'; 36 $this->settings->weekly_transient_expiry = '604800'; 32 37 } 33 38 … … 46 51 47 52 public function get_json($key, $keys=[], $raw=false) { 48 $valid_json = true; $cache_response = false; 53 $valid_json = true; $cache_response = false; $this->expiry = null; 49 54 list($transient_name, $gms_api_url, $headers) = $this->parse_keys($key, $keys); 50 55 $body = get_transient($transient_name); … … 56 61 if (strlen($transient_name) <= 172) { 57 62 switch ($this->api[$key]['expiry']) { 58 case 'static' : $this->expiry = $this->settings->static_transient_expiry; break; 59 case 'weekly' : $this->expiry = '604800'; break; 60 default : $this->expiry = $this->settings->default_transient_expiry; 63 case 'static' : $expiry = $this->settings->static_transient_expiry; break; 64 case 'daily' : $expiry = $this->settings->daily_transient_expiry; break; 65 case 'weekly' : $expiry = $this->settings->weekly_transient_expiry; break; 66 default : $expiry = $this->settings->default_transient_expiry; 61 67 } 62 68 $cache_response = true; … … 103 109 } 104 110 } 105 if ($cache_response) set_transient($transient_name, $body, $this->expiry); 111 if ($cache_response) set_transient($transient_name, $body, $this->expiry ?: $expiry); 112 $this->expiry = null; 106 113 return $result; 107 114 } … … 294 301 if (!($fixture->isResult || $this->is_beforetoday($valid_date))) $this->directions = ['venue' => $fixture->venue ?? '', 'll' => null, 'address' => $address, 'postcode' => $fixture->venueDetails->postCode ?? null]; 295 302 $address .= !empty($address) ? (!empty($fixture->venueDetails->postCode) ? ', '.$fixture->venueDetails->postCode : '') : ''; 303 $this->set_expiry($valid_date, 'fixturedetail'); 296 304 } 297 305 $score_class = ''; … … 310 318 $home_attr[] = 'data-team="'.($fixture->homeTeam->id).'"'; 311 319 if ($this->show_gender) $fixture_card['Home Team'] .= ' ('.$fixture->homeTeam->gender.')'; 320 if ($show_detail) $this->detailClubTeam = $fixture->homeTeam->id; 312 321 } 313 322 if ($this->is_clubteam($fixture->awayTeam) && $this->is_clubwide()) { … … 315 324 $away_attr[] = 'data-team="'.($fixture->awayTeam->id).'"'; 316 325 if ($this->show_gender) $fixture_card['Away Team'] .= ' ('.$fixture->awayTeam->gender.')'; 326 if ($show_detail) $this->detailClubTeam = $fixture->awayTeam->id; 317 327 } 318 328 if ($this->show_list) { … … 571 581 $gp = $gw = $gd = $gl = $gf = $ga = 0; 572 582 $form = []; 583 $missing_result = false; 573 584 foreach ($data as $competition) { 574 585 foreach ($competition->fixtures as $fixture) { … … 592 603 } 593 604 } 594 elseif ($this->is_beforetoday($valid_date)) continue;605 elseif ($this->is_beforetoday($valid_date)) { $missing_result = true; continue; } 595 606 elseif (!$next_fixture_date || $valid_date < $next_fixture_date) $next_fixture_date = $valid_date; 596 607 } 597 608 } 609 if (!$missing_result) $this->set_expiry($next_fixture_date, 'nextfixture'); 598 610 if ($teamname) { 599 611 $points = $gw * 3 + $gd; … … 618 630 private function multiple_teams() { 619 631 $html = ''; 620 $json_data = $required_data = $league_data = $guzzle_data = $ team_keys= [];632 $json_data = $required_data = $league_data = $guzzle_data = $guzzle_required = []; 621 633 $no_data = 0; 622 634 $haveTeams = false; … … 624 636 foreach ($this->multiple_teams as $teamID) { 625 637 $haveTeams = true; 626 list($transient_name, $gms_api_url, $headers) = $this->parse_keys('fixturesandresults', $teamID); 627 $team_keys[$teamID] = ['transient_name' => $transient_name, 'gms_api_url' => $gms_api_url, 'headers' => $headers]; 638 list($transient_name, , ) = $this->parse_keys('fixturesandresults', $teamID); 628 639 $body = get_transient($transient_name); 629 if ($body === false) $required_data[$teamID] = $team_keys[$teamID]; 640 if ($body === false) { 641 // Try the custom data cache second 642 list($transient_name, $gms_api_url, $headers) = $this->parse_keys('customteam', $teamID); 643 $body = get_transient($transient_name); 644 if ($body === false) { 645 $required_data[] = $teamID; 646 $guzzle_required[$teamID]= ['transient_name' => $transient_name, 'gms_api_url' => $gms_api_url, 'headers' => $headers]; 647 } 648 else $json_data[$teamID] = $body; 649 } 630 650 else $json_data[$teamID] = $body; 631 651 } 632 652 // Guzzle required data if possible 633 653 if (method_exists($this,'guzzle_teams')) { 634 $guzzle_data = $this->guzzle_teams($ required_data);654 $guzzle_data = $this->guzzle_teams($guzzle_required); 635 655 $json_data = array_merge($json_data, $guzzle_data); 636 foreach ($guzzle_data as $teamID => $value) unset($required_data[$teamID]);637 } 638 foreach ($required_data as $teamID => $value) {656 foreach ($guzzle_data as $teamID => $value) if (($key = array_search($teamID, $required_data)) !== false) unset($required_data[$key]); 657 } 658 foreach ($required_data as $teamID) { 639 659 $this->customteam = $teamID; 640 660 $team_data = $this->get_json('customteam', $teamID); … … 650 670 } 651 671 else $no_data++; 652 if (isset($guzzle_data[$teamID])) set_transient($ team_keys[$teamID]['transient_name'], $snapshot, $this->expiry);672 if (isset($guzzle_data[$teamID])) set_transient($guzzle_required[$teamID]['transient_name'], $snapshot, $this->expiry); 653 673 } 654 674 } … … 668 688 } 669 689 690 private function set_expiry($valid_date, $rule) { 691 $expiry = 0; 692 if ($valid_date) { 693 $diff = (new \DateTime())->getTimestamp() - $valid_date->getTimestamp(); 694 if ($rule == 'nextfixture') { 695 $diff = -$diff; 696 if ($diff > $this->settings->weekly_transient_expiry) $expiry = $this->settings->weekly_transient_expiry; 697 elseif ($diff > 0) $expiry = $diff; 698 } 699 elseif ($rule == 'fixturedetail') { 700 if ($diff > 2500000) $expiry = $this->settings->weekly_transient_expiry; 701 elseif ($diff > $this->settings->weekly_transient_expiry) $expiry = $this->settings->daily_transient_expiry; 702 } 703 } 704 elseif ($rule == 'nextfixture') $expiry = $this->settings->weekly_transient_expiry; 705 if ($expiry > $this->settings->default_transient_expiry) $this->expiry = $expiry; 706 } 707 670 708 } -
eh-gms-feed/tags/3.14/includes/main-class.php
r3065987 r3066677 33 33 elseif ($this->validate_atts($atts)) { 34 34 if ($this->atts_show['method'] == 'api') { 35 if ($this->atts_show['show'] == 'fixture') wp_send_json(['html' => $this->get_table(), 'details' => $this->directions]);35 if ($this->atts_show['show'] == 'fixture') wp_send_json(['html' => $this->get_table(), 'details' => array_merge($this->directions ?: [], $this->detailClubTeam ? ['ClubTeamID' => $this->detailClubTeam] : [])]); 36 36 else echo $this->get_table(); 37 37 } … … 69 69 $this->atts_show['options'] = sanitize_text_field( $this->atts_show['options'] ); 70 70 $this->multiple_teams = array_unique(array_filter(array_map('trim', explode('+', $this->atts_show['team'])))); 71 if ( $this->atts_show['method'] == 'api' || $this->atts_show['method'] == 'api-dynamic') {71 if (in_array($this->atts_show['method'],['api', 'api-dynamic', 'ajax'])) { 72 72 if (empty($this->atts_show['club_id']) && ((!$this->is_competition() && !$this->is_team() && !$this->atts_show['show'] == 'fixture') || $this->atts_show['method'] == 'api-dynamic')) { 73 73 $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' ); … … 128 128 public function gms_shortcode ( $atts = [] ) { 129 129 if ($this->validate_atts($atts)) { 130 if ($this->settings->default_ajax == 'yes' || $this->atts_show['method'] == 'api-dynamic') { 130 if ($this->settings->default_ajax == 'yes' || $this->atts_show['method'] == 'api-dynamic' || $this->atts_show['method'] == 'ajax') { 131 if ($this->atts_show['method'] == 'ajax') $this->atts_show['method'] = 'api'; 131 132 wp_enqueue_script('EH_GMS_Feed'); 132 133 $html_atts = ''; … … 143 144 144 145 public function enqueue_scripts () { 145 wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.1 3', true);146 wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.14', true); 146 147 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')]); 147 wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3.1 2');148 wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3.14'); 148 149 if ($this->settings->default_css == 'yes') wp_enqueue_style('EH_GMS_Feed'); 149 150 } -
eh-gms-feed/tags/3.14/includes/settings.php
r2981152 r3066677 11 11 12 12 const OPTION_NAME = 'eh_gms_feed_settings'; 13 public $gms_api_url = 'https://eh-dw-prod.azurewebsites.net/api/'; 14 public $gms_api_key = '2RRafa42yMEJAUuXlrsXh04nanHcbO/XT81uPQrEMBSVN1LEqpnFvA=='; 15 public $default_transient_expiry = '3600'; 13 public $default_transient_expiry; 16 14 public $default_css = 'yes'; 17 public $default_ajax = ' no';15 public $default_ajax = 'yes'; 18 16 public $default_club_id; 19 17 private $settings; … … 117 115 <label><input type="radio" name="<?php echo self::OPTION_NAME ?>[default_ajax]" value="no" <?php checked($this->default_ajax, 'no', true); ?>><?php esc_html_e( 'No', 'eh-gms-feed' ); ?></label> 118 116 </fieldset> 119 <p class="description"><?php esc_html_e( ' If your Wordpress setup includes server side page caching, then you may wish to exclude pages (that contain GMS shortcodes for this plugin) from the cache so that data does not become stale, or the page cache must be purged regularly (in line with the transient expiry). Alternatively you may use AJAX by selecting "Yes". Javascript is then used to retrieve GMS data so that fixtures, results and league tables will not be part of the page cache.', 'eh-gms-feed' ); ?></p>117 <p class="description"><?php esc_html_e( 'Default is to use Javascript to retrieve GMS data. This is recommended to avoid problems with site page caching and allow interactive shortcodes to work (e.g. with fixture details and WebCal links). If you select "No" and your setup includes server side page caching, then you may wish to exclude pages (that contain GMS shortcodes) from the cache, or the page cache must be purged regularly (in line with the transient expiry). Individual shortcodes will always use AJAX with method="ajax" or method="api-dynamic".', 'eh-gms-feed' ); ?></p> 120 118 <?php 121 119 } -
eh-gms-feed/tags/3.14/js/eh-gms-feed.js
r3065987 r3066677 9 9 function club_team (message, filter, wrapper, detail) { 10 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) {11 ele.find('.gms-clubteam[data-team]').css('cursor','pointer').prop('title', 'Select to filter by club team').on('click', function(e) { 12 12 if (detail) { 13 13 detail.hide(); … … 93 93 detail.show(); 94 94 detail[0].scrollIntoView(); 95 if (filter && !team) club_team(message, filter, wrapper, detail); 95 if (filter && !team) { 96 if (data.details && data.details.ClubTeamID) { 97 detail[0].insertAdjacentHTML('beforeend', '<button type="button" class="gms-button gms-clubteam" data-team="'+ data.details.ClubTeamID +'">Team Fixtures</button> '); 98 } 99 club_team(message, filter, wrapper, detail); 100 } 96 101 var fixture_card = detail[0].querySelector('.gms-card'); 97 102 if (fixture_card) { -
eh-gms-feed/tags/3.14/readme.txt
r3065987 r3066677 5 5 Tested up to: 6.5 6 6 Requires PHP: 5.3 7 Stable tag: 3.1 37 Stable tag: 3.14 8 8 License: GPLv2 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 62 62 63 63 == Changelog == 64 65 = 3.14 = 66 * Added club team fixtures button to fixture detail 67 * Change to default CSS for club team fixtures button 68 * Optimisation of caching for custom league table and fixture details 69 * Default setting for "Use AJAX (Javascript)" in now "Yes" 70 * When AJAX option is "No" can override on individual shortcode with method="ajax" 71 * Fix to transient expiry when viewing multiple match days for club 64 72 65 73 = 3.13 = -
eh-gms-feed/trunk/css/gms-default.css
r3064521 r3066677 4 4 .gms-table th, .gms-table td { border: 1px solid; padding: 3px 10px; border-color: silver } 5 5 .gms-footnote, .gms-filter { margin: 0 0 2rem } 6 .gms-clubteam { font-weight: 700 }6 .gms-clubteam:not(.gms-button) { font-weight: 700 } 7 7 .gms-filter > div { margin: 0 0 1rem } 8 8 .gms-filter fieldset { width: fit-content } -
eh-gms-feed/trunk/eh-gms-feed.php
r3065987 r3066677 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.1 36 * Version: 3.14 7 7 * Author: Matthew Treherne 8 8 * Author URI: https://profiles.wordpress.org/mtreherne -
eh-gms-feed/trunk/includes/coreAPI.php
r3065987 r3066677 4 4 class coreAPI { 5 5 6 public $error_bag, $api_error = false, $atts_show, $show_gender, $show_list, $show_cal, $cal_summary, $id, $show_detail, $directions, $multiple_teams = [], $teamlimit = 12;6 public $error_bag, $api_error = false, $atts_show, $show_gender, $show_list, $show_cal, $cal_summary, $id, $show_detail, $directions, $multiple_teams = [], $teamlimit = 12, $detailClubTeam; 7 7 8 8 protected $settings; … … 18 18 'fixturesandresults' => ['transient' => 'TEAM', 'keys' => ['teams'], 'error_bag' => null, 'expiry' => 'default'], 19 19 'matchdays' => ['transient' => 'CLUB MATCHDAYS', 'keys' => ['clubs'], 'error_bag' => null, 'expiry' => 'default'], 20 'matchday' => ['suffix' => '', 'transient' => 'CLUB MATCHDAY', 'keys' => ['clubs', 'matchdays'], 'error_bag' => null, 'expiry' => ' static'],20 'matchday' => ['suffix' => '', 'transient' => 'CLUB MATCHDAY', 'keys' => ['clubs', 'matchdays'], 'error_bag' => null, 'expiry' => 'daily'], 21 21 'teamsinclub' => ['suffix' => 'teams', 'transient' => 'CLUB TEAMS', 'keys' => ['clubs'], 'error_bag' => 'teamselected', 'expiry' => 'static'], 22 22 'teamslist' => ['suffix' => 'teams', 'transient' => 'CLUB TEAMS', 'keys' => ['clubs'], 'error_bag' => null, 'expiry' => 'static'], … … 24 24 'competition' => ['suffix' => '', 'transient' => 'COMPETITION SUMMARY', 'keys' => ['competitions'], 'error_bag' => null, 'expiry' => 'default'], 25 25 'fixture' => ['suffix' => '', 'transient' => 'FIXTURE', 'keys' => ['fixtures'], 'error_bag' => null, 'expiry' => 'default'], 26 'customteam' => ['suffix' => 'fixturesandresults', 'transient' => 'TEAM ', 'keys' => ['teams'], 'error_bag' => 'customteam', 'expiry' => 'default'],26 'customteam' => ['suffix' => 'fixturesandresults', 'transient' => 'TEAMRESULTS', 'keys' => ['teams'], 'error_bag' => 'customteam', 'expiry' => 'default'], 27 27 ]; 28 28 29 29 public function __construct () { 30 $this->settings->default_transient_expiry = '3600'; 30 if (!isset($this->settings)) $this->settings = new \stdClass; 31 $this->settings->gms_api_url = 'https://eh-dw-prod.azurewebsites.net/api/'; 32 $this->settings->gms_api_key = '2RRafa42yMEJAUuXlrsXh04nanHcbO/XT81uPQrEMBSVN1LEqpnFvA=='; 33 if (!isset($this->settings->default_transient_expiry)) $this->settings->default_transient_expiry = '3600'; 31 34 $this->settings->static_transient_expiry = '86400'; 35 $this->settings->daily_transient_expiry = '86400'; 36 $this->settings->weekly_transient_expiry = '604800'; 32 37 } 33 38 … … 46 51 47 52 public function get_json($key, $keys=[], $raw=false) { 48 $valid_json = true; $cache_response = false; 53 $valid_json = true; $cache_response = false; $this->expiry = null; 49 54 list($transient_name, $gms_api_url, $headers) = $this->parse_keys($key, $keys); 50 55 $body = get_transient($transient_name); … … 56 61 if (strlen($transient_name) <= 172) { 57 62 switch ($this->api[$key]['expiry']) { 58 case 'static' : $this->expiry = $this->settings->static_transient_expiry; break; 59 case 'weekly' : $this->expiry = '604800'; break; 60 default : $this->expiry = $this->settings->default_transient_expiry; 63 case 'static' : $expiry = $this->settings->static_transient_expiry; break; 64 case 'daily' : $expiry = $this->settings->daily_transient_expiry; break; 65 case 'weekly' : $expiry = $this->settings->weekly_transient_expiry; break; 66 default : $expiry = $this->settings->default_transient_expiry; 61 67 } 62 68 $cache_response = true; … … 103 109 } 104 110 } 105 if ($cache_response) set_transient($transient_name, $body, $this->expiry); 111 if ($cache_response) set_transient($transient_name, $body, $this->expiry ?: $expiry); 112 $this->expiry = null; 106 113 return $result; 107 114 } … … 294 301 if (!($fixture->isResult || $this->is_beforetoday($valid_date))) $this->directions = ['venue' => $fixture->venue ?? '', 'll' => null, 'address' => $address, 'postcode' => $fixture->venueDetails->postCode ?? null]; 295 302 $address .= !empty($address) ? (!empty($fixture->venueDetails->postCode) ? ', '.$fixture->venueDetails->postCode : '') : ''; 303 $this->set_expiry($valid_date, 'fixturedetail'); 296 304 } 297 305 $score_class = ''; … … 310 318 $home_attr[] = 'data-team="'.($fixture->homeTeam->id).'"'; 311 319 if ($this->show_gender) $fixture_card['Home Team'] .= ' ('.$fixture->homeTeam->gender.')'; 320 if ($show_detail) $this->detailClubTeam = $fixture->homeTeam->id; 312 321 } 313 322 if ($this->is_clubteam($fixture->awayTeam) && $this->is_clubwide()) { … … 315 324 $away_attr[] = 'data-team="'.($fixture->awayTeam->id).'"'; 316 325 if ($this->show_gender) $fixture_card['Away Team'] .= ' ('.$fixture->awayTeam->gender.')'; 326 if ($show_detail) $this->detailClubTeam = $fixture->awayTeam->id; 317 327 } 318 328 if ($this->show_list) { … … 571 581 $gp = $gw = $gd = $gl = $gf = $ga = 0; 572 582 $form = []; 583 $missing_result = false; 573 584 foreach ($data as $competition) { 574 585 foreach ($competition->fixtures as $fixture) { … … 592 603 } 593 604 } 594 elseif ($this->is_beforetoday($valid_date)) continue;605 elseif ($this->is_beforetoday($valid_date)) { $missing_result = true; continue; } 595 606 elseif (!$next_fixture_date || $valid_date < $next_fixture_date) $next_fixture_date = $valid_date; 596 607 } 597 608 } 609 if (!$missing_result) $this->set_expiry($next_fixture_date, 'nextfixture'); 598 610 if ($teamname) { 599 611 $points = $gw * 3 + $gd; … … 618 630 private function multiple_teams() { 619 631 $html = ''; 620 $json_data = $required_data = $league_data = $guzzle_data = $ team_keys= [];632 $json_data = $required_data = $league_data = $guzzle_data = $guzzle_required = []; 621 633 $no_data = 0; 622 634 $haveTeams = false; … … 624 636 foreach ($this->multiple_teams as $teamID) { 625 637 $haveTeams = true; 626 list($transient_name, $gms_api_url, $headers) = $this->parse_keys('fixturesandresults', $teamID); 627 $team_keys[$teamID] = ['transient_name' => $transient_name, 'gms_api_url' => $gms_api_url, 'headers' => $headers]; 638 list($transient_name, , ) = $this->parse_keys('fixturesandresults', $teamID); 628 639 $body = get_transient($transient_name); 629 if ($body === false) $required_data[$teamID] = $team_keys[$teamID]; 640 if ($body === false) { 641 // Try the custom data cache second 642 list($transient_name, $gms_api_url, $headers) = $this->parse_keys('customteam', $teamID); 643 $body = get_transient($transient_name); 644 if ($body === false) { 645 $required_data[] = $teamID; 646 $guzzle_required[$teamID]= ['transient_name' => $transient_name, 'gms_api_url' => $gms_api_url, 'headers' => $headers]; 647 } 648 else $json_data[$teamID] = $body; 649 } 630 650 else $json_data[$teamID] = $body; 631 651 } 632 652 // Guzzle required data if possible 633 653 if (method_exists($this,'guzzle_teams')) { 634 $guzzle_data = $this->guzzle_teams($ required_data);654 $guzzle_data = $this->guzzle_teams($guzzle_required); 635 655 $json_data = array_merge($json_data, $guzzle_data); 636 foreach ($guzzle_data as $teamID => $value) unset($required_data[$teamID]);637 } 638 foreach ($required_data as $teamID => $value) {656 foreach ($guzzle_data as $teamID => $value) if (($key = array_search($teamID, $required_data)) !== false) unset($required_data[$key]); 657 } 658 foreach ($required_data as $teamID) { 639 659 $this->customteam = $teamID; 640 660 $team_data = $this->get_json('customteam', $teamID); … … 650 670 } 651 671 else $no_data++; 652 if (isset($guzzle_data[$teamID])) set_transient($ team_keys[$teamID]['transient_name'], $snapshot, $this->expiry);672 if (isset($guzzle_data[$teamID])) set_transient($guzzle_required[$teamID]['transient_name'], $snapshot, $this->expiry); 653 673 } 654 674 } … … 668 688 } 669 689 690 private function set_expiry($valid_date, $rule) { 691 $expiry = 0; 692 if ($valid_date) { 693 $diff = (new \DateTime())->getTimestamp() - $valid_date->getTimestamp(); 694 if ($rule == 'nextfixture') { 695 $diff = -$diff; 696 if ($diff > $this->settings->weekly_transient_expiry) $expiry = $this->settings->weekly_transient_expiry; 697 elseif ($diff > 0) $expiry = $diff; 698 } 699 elseif ($rule == 'fixturedetail') { 700 if ($diff > 2500000) $expiry = $this->settings->weekly_transient_expiry; 701 elseif ($diff > $this->settings->weekly_transient_expiry) $expiry = $this->settings->daily_transient_expiry; 702 } 703 } 704 elseif ($rule == 'nextfixture') $expiry = $this->settings->weekly_transient_expiry; 705 if ($expiry > $this->settings->default_transient_expiry) $this->expiry = $expiry; 706 } 707 670 708 } -
eh-gms-feed/trunk/includes/main-class.php
r3065987 r3066677 33 33 elseif ($this->validate_atts($atts)) { 34 34 if ($this->atts_show['method'] == 'api') { 35 if ($this->atts_show['show'] == 'fixture') wp_send_json(['html' => $this->get_table(), 'details' => $this->directions]);35 if ($this->atts_show['show'] == 'fixture') wp_send_json(['html' => $this->get_table(), 'details' => array_merge($this->directions ?: [], $this->detailClubTeam ? ['ClubTeamID' => $this->detailClubTeam] : [])]); 36 36 else echo $this->get_table(); 37 37 } … … 69 69 $this->atts_show['options'] = sanitize_text_field( $this->atts_show['options'] ); 70 70 $this->multiple_teams = array_unique(array_filter(array_map('trim', explode('+', $this->atts_show['team'])))); 71 if ( $this->atts_show['method'] == 'api' || $this->atts_show['method'] == 'api-dynamic') {71 if (in_array($this->atts_show['method'],['api', 'api-dynamic', 'ajax'])) { 72 72 if (empty($this->atts_show['club_id']) && ((!$this->is_competition() && !$this->is_team() && !$this->atts_show['show'] == 'fixture') || $this->atts_show['method'] == 'api-dynamic')) { 73 73 $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' ); … … 128 128 public function gms_shortcode ( $atts = [] ) { 129 129 if ($this->validate_atts($atts)) { 130 if ($this->settings->default_ajax == 'yes' || $this->atts_show['method'] == 'api-dynamic') { 130 if ($this->settings->default_ajax == 'yes' || $this->atts_show['method'] == 'api-dynamic' || $this->atts_show['method'] == 'ajax') { 131 if ($this->atts_show['method'] == 'ajax') $this->atts_show['method'] = 'api'; 131 132 wp_enqueue_script('EH_GMS_Feed'); 132 133 $html_atts = ''; … … 143 144 144 145 public function enqueue_scripts () { 145 wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.1 3', true);146 wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.14', true); 146 147 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')]); 147 wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3.1 2');148 wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3.14'); 148 149 if ($this->settings->default_css == 'yes') wp_enqueue_style('EH_GMS_Feed'); 149 150 } -
eh-gms-feed/trunk/includes/settings.php
r2981152 r3066677 11 11 12 12 const OPTION_NAME = 'eh_gms_feed_settings'; 13 public $gms_api_url = 'https://eh-dw-prod.azurewebsites.net/api/'; 14 public $gms_api_key = '2RRafa42yMEJAUuXlrsXh04nanHcbO/XT81uPQrEMBSVN1LEqpnFvA=='; 15 public $default_transient_expiry = '3600'; 13 public $default_transient_expiry; 16 14 public $default_css = 'yes'; 17 public $default_ajax = ' no';15 public $default_ajax = 'yes'; 18 16 public $default_club_id; 19 17 private $settings; … … 117 115 <label><input type="radio" name="<?php echo self::OPTION_NAME ?>[default_ajax]" value="no" <?php checked($this->default_ajax, 'no', true); ?>><?php esc_html_e( 'No', 'eh-gms-feed' ); ?></label> 118 116 </fieldset> 119 <p class="description"><?php esc_html_e( ' If your Wordpress setup includes server side page caching, then you may wish to exclude pages (that contain GMS shortcodes for this plugin) from the cache so that data does not become stale, or the page cache must be purged regularly (in line with the transient expiry). Alternatively you may use AJAX by selecting "Yes". Javascript is then used to retrieve GMS data so that fixtures, results and league tables will not be part of the page cache.', 'eh-gms-feed' ); ?></p>117 <p class="description"><?php esc_html_e( 'Default is to use Javascript to retrieve GMS data. This is recommended to avoid problems with site page caching and allow interactive shortcodes to work (e.g. with fixture details and WebCal links). If you select "No" and your setup includes server side page caching, then you may wish to exclude pages (that contain GMS shortcodes) from the cache, or the page cache must be purged regularly (in line with the transient expiry). Individual shortcodes will always use AJAX with method="ajax" or method="api-dynamic".', 'eh-gms-feed' ); ?></p> 120 118 <?php 121 119 } -
eh-gms-feed/trunk/js/eh-gms-feed.js
r3065987 r3066677 9 9 function club_team (message, filter, wrapper, detail) { 10 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) {11 ele.find('.gms-clubteam[data-team]').css('cursor','pointer').prop('title', 'Select to filter by club team').on('click', function(e) { 12 12 if (detail) { 13 13 detail.hide(); … … 93 93 detail.show(); 94 94 detail[0].scrollIntoView(); 95 if (filter && !team) club_team(message, filter, wrapper, detail); 95 if (filter && !team) { 96 if (data.details && data.details.ClubTeamID) { 97 detail[0].insertAdjacentHTML('beforeend', '<button type="button" class="gms-button gms-clubteam" data-team="'+ data.details.ClubTeamID +'">Team Fixtures</button> '); 98 } 99 club_team(message, filter, wrapper, detail); 100 } 96 101 var fixture_card = detail[0].querySelector('.gms-card'); 97 102 if (fixture_card) { -
eh-gms-feed/trunk/readme.txt
r3065987 r3066677 5 5 Tested up to: 6.5 6 6 Requires PHP: 5.3 7 Stable tag: 3.1 37 Stable tag: 3.14 8 8 License: GPLv2 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 62 62 63 63 == Changelog == 64 65 = 3.14 = 66 * Added club team fixtures button to fixture detail 67 * Change to default CSS for club team fixtures button 68 * Optimisation of caching for custom league table and fixture details 69 * Default setting for "Use AJAX (Javascript)" in now "Yes" 70 * When AJAX option is "No" can override on individual shortcode with method="ajax" 71 * Fix to transient expiry when viewing multiple match days for club 64 72 65 73 = 3.13 =
Note: See TracChangeset
for help on using the changeset viewer.