Plugin Directory

Changeset 3066677


Ignore:
Timestamp:
04/08/2024 08:27:42 AM (23 months ago)
Author:
mtreherne
Message:

Release of Version 3.14

Location:
eh-gms-feed
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • eh-gms-feed/tags/3.14/css/gms-default.css

    r3064521 r3066677  
    44.gms-table th, .gms-table td { border: 1px solid; padding: 3px 10px; border-color: silver }
    55.gms-footnote, .gms-filter { margin: 0 0 2rem }
    6 .gms-clubteam { font-weight: 700 }
     6.gms-clubteam:not(.gms-button) { font-weight: 700 }
    77.gms-filter > div { margin: 0 0 1rem }
    88.gms-filter fieldset { width: fit-content }
  • eh-gms-feed/tags/3.14/eh-gms-feed.php

    r3065987 r3066677  
    44 * Plugin URI: https://wordpress.org/plugins/eh-gms-feed/
    55 * Description: Show fixtures, results and tables from England Hockey GMS
    6  * Version: 3.13
     6 * Version: 3.14
    77 * Author: Matthew Treherne
    88 * Author URI: https://profiles.wordpress.org/mtreherne
  • eh-gms-feed/tags/3.14/includes/coreAPI.php

    r3065987 r3066677  
    44class coreAPI {
    55
    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;
    77
    88    protected $settings;
     
    1818        'fixturesandresults' => ['transient' => 'TEAM', 'keys' => ['teams'], 'error_bag' => null, 'expiry' => 'default'],
    1919        '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'],
    2121        'teamsinclub' => ['suffix' => 'teams', 'transient' => 'CLUB TEAMS', 'keys' => ['clubs'], 'error_bag' => 'teamselected', 'expiry' => 'static'],
    2222        'teamslist' => ['suffix' => 'teams', 'transient' => 'CLUB TEAMS', 'keys' => ['clubs'], 'error_bag' => null, 'expiry' => 'static'],
     
    2424        'competition' => ['suffix' => '', 'transient' => 'COMPETITION SUMMARY', 'keys' => ['competitions'], 'error_bag' => null, 'expiry' => 'default'],
    2525        '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'],
    2727    ];
    2828
    2929    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';
    3134        $this->settings->static_transient_expiry = '86400';
     35        $this->settings->daily_transient_expiry = '86400';
     36        $this->settings->weekly_transient_expiry = '604800';
    3237    }
    3338
     
    4651
    4752  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;
    4954        list($transient_name, $gms_api_url, $headers) = $this->parse_keys($key, $keys);
    5055        $body = get_transient($transient_name);
     
    5661                if (strlen($transient_name) <= 172) {
    5762                    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;
    6167                    }
    6268                    $cache_response = true;
     
    103109            }
    104110        }
    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;
    106113        return $result;
    107114  }
     
    294301            if (!($fixture->isResult || $this->is_beforetoday($valid_date))) $this->directions = ['venue' => $fixture->venue ?? '', 'll' => null, 'address' => $address, 'postcode' => $fixture->venueDetails->postCode ?? null];
    295302            $address .= !empty($address) ? (!empty($fixture->venueDetails->postCode) ? ', '.$fixture->venueDetails->postCode : '') : '';
     303            $this->set_expiry($valid_date, 'fixturedetail');
    296304        }
    297305        $score_class = '';
     
    310318            $home_attr[] = 'data-team="'.($fixture->homeTeam->id).'"';
    311319            if ($this->show_gender) $fixture_card['Home Team'] .= ' ('.$fixture->homeTeam->gender.')';
     320            if ($show_detail) $this->detailClubTeam = $fixture->homeTeam->id;
    312321        }
    313322        if ($this->is_clubteam($fixture->awayTeam) && $this->is_clubwide()) {
     
    315324            $away_attr[] = 'data-team="'.($fixture->awayTeam->id).'"';
    316325            if ($this->show_gender) $fixture_card['Away Team'] .= ' ('.$fixture->awayTeam->gender.')';
     326            if ($show_detail) $this->detailClubTeam = $fixture->awayTeam->id;
    317327        }
    318328        if ($this->show_list) {
     
    571581        $gp = $gw = $gd = $gl = $gf = $ga = 0;
    572582        $form = [];
     583        $missing_result = false;
    573584        foreach ($data as $competition) {
    574585            foreach ($competition->fixtures as $fixture) {
     
    592603                    }
    593604                }
    594                 elseif ($this->is_beforetoday($valid_date)) continue;
     605                elseif ($this->is_beforetoday($valid_date)) { $missing_result = true; continue; }
    595606                elseif (!$next_fixture_date || $valid_date < $next_fixture_date) $next_fixture_date = $valid_date;
    596607            }
    597608        }
     609        if (!$missing_result) $this->set_expiry($next_fixture_date, 'nextfixture');
    598610        if ($teamname) {
    599611            $points = $gw * 3 + $gd;
     
    618630    private function multiple_teams() {
    619631        $html = '';
    620         $json_data = $required_data = $league_data = $guzzle_data = $team_keys = [];
     632        $json_data = $required_data = $league_data = $guzzle_data = $guzzle_required = [];
    621633        $no_data = 0;
    622634        $haveTeams = false;
     
    624636        foreach ($this->multiple_teams as $teamID) {
    625637            $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);
    628639            $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            }
    630650            else $json_data[$teamID] = $body;
    631651        }
    632652        // Guzzle required data if possible
    633653        if (method_exists($this,'guzzle_teams')) {
    634             $guzzle_data = $this->guzzle_teams($required_data);
     654            $guzzle_data = $this->guzzle_teams($guzzle_required);
    635655            $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) {
    639659            $this->customteam = $teamID;
    640660            $team_data = $this->get_json('customteam', $teamID);
     
    650670                }
    651671                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);
    653673            }
    654674        }
     
    668688    }
    669689
     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
    670708}
  • eh-gms-feed/tags/3.14/includes/main-class.php

    r3065987 r3066677  
    3333        elseif ($this->validate_atts($atts)) {
    3434            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] : [])]);
    3636                else echo $this->get_table();
    3737            }
     
    6969        $this->atts_show['options'] = sanitize_text_field( $this->atts_show['options'] );
    7070        $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'])) {
    7272            if (empty($this->atts_show['club_id']) && ((!$this->is_competition() && !$this->is_team() && !$this->atts_show['show'] == 'fixture') || $this->atts_show['method'] == 'api-dynamic')) {
    7373                $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' );
     
    128128    public function gms_shortcode ( $atts = [] ) {
    129129        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';
    131132                wp_enqueue_script('EH_GMS_Feed');
    132133                $html_atts = '';
     
    143144
    144145    public function enqueue_scripts () {
    145         wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.13', true);
     146        wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.14', true);
    146147        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.12');
     148        wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3.14');
    148149        if ($this->settings->default_css == 'yes') wp_enqueue_style('EH_GMS_Feed');
    149150    }
  • eh-gms-feed/tags/3.14/includes/settings.php

    r2981152 r3066677  
    1111
    1212    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;
    1614    public $default_css = 'yes';
    17     public $default_ajax = 'no';
     15    public $default_ajax = 'yes';
    1816    public $default_club_id;
    1917    private $settings;
     
    117115            <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>
    118116        </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>
    120118      <?php
    121119    }
  • eh-gms-feed/tags/3.14/js/eh-gms-feed.js

    r3065987 r3066677  
    99    function club_team (message, filter, wrapper, detail) {
    1010        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) {
    1212            if (detail) {
    1313                detail.hide();
     
    9393                        detail.show();
    9494                        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                        }
    96101                        var fixture_card = detail[0].querySelector('.gms-card');
    97102                        if (fixture_card) {
  • eh-gms-feed/tags/3.14/readme.txt

    r3065987 r3066677  
    55Tested up to: 6.5
    66Requires PHP: 5.3
    7 Stable tag: 3.13
     7Stable tag: 3.14
    88License: GPLv2
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6262
    6363== 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
    6472
    6573= 3.13 =
  • eh-gms-feed/trunk/css/gms-default.css

    r3064521 r3066677  
    44.gms-table th, .gms-table td { border: 1px solid; padding: 3px 10px; border-color: silver }
    55.gms-footnote, .gms-filter { margin: 0 0 2rem }
    6 .gms-clubteam { font-weight: 700 }
     6.gms-clubteam:not(.gms-button) { font-weight: 700 }
    77.gms-filter > div { margin: 0 0 1rem }
    88.gms-filter fieldset { width: fit-content }
  • eh-gms-feed/trunk/eh-gms-feed.php

    r3065987 r3066677  
    44 * Plugin URI: https://wordpress.org/plugins/eh-gms-feed/
    55 * Description: Show fixtures, results and tables from England Hockey GMS
    6  * Version: 3.13
     6 * Version: 3.14
    77 * Author: Matthew Treherne
    88 * Author URI: https://profiles.wordpress.org/mtreherne
  • eh-gms-feed/trunk/includes/coreAPI.php

    r3065987 r3066677  
    44class coreAPI {
    55
    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;
    77
    88    protected $settings;
     
    1818        'fixturesandresults' => ['transient' => 'TEAM', 'keys' => ['teams'], 'error_bag' => null, 'expiry' => 'default'],
    1919        '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'],
    2121        'teamsinclub' => ['suffix' => 'teams', 'transient' => 'CLUB TEAMS', 'keys' => ['clubs'], 'error_bag' => 'teamselected', 'expiry' => 'static'],
    2222        'teamslist' => ['suffix' => 'teams', 'transient' => 'CLUB TEAMS', 'keys' => ['clubs'], 'error_bag' => null, 'expiry' => 'static'],
     
    2424        'competition' => ['suffix' => '', 'transient' => 'COMPETITION SUMMARY', 'keys' => ['competitions'], 'error_bag' => null, 'expiry' => 'default'],
    2525        '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'],
    2727    ];
    2828
    2929    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';
    3134        $this->settings->static_transient_expiry = '86400';
     35        $this->settings->daily_transient_expiry = '86400';
     36        $this->settings->weekly_transient_expiry = '604800';
    3237    }
    3338
     
    4651
    4752  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;
    4954        list($transient_name, $gms_api_url, $headers) = $this->parse_keys($key, $keys);
    5055        $body = get_transient($transient_name);
     
    5661                if (strlen($transient_name) <= 172) {
    5762                    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;
    6167                    }
    6268                    $cache_response = true;
     
    103109            }
    104110        }
    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;
    106113        return $result;
    107114  }
     
    294301            if (!($fixture->isResult || $this->is_beforetoday($valid_date))) $this->directions = ['venue' => $fixture->venue ?? '', 'll' => null, 'address' => $address, 'postcode' => $fixture->venueDetails->postCode ?? null];
    295302            $address .= !empty($address) ? (!empty($fixture->venueDetails->postCode) ? ', '.$fixture->venueDetails->postCode : '') : '';
     303            $this->set_expiry($valid_date, 'fixturedetail');
    296304        }
    297305        $score_class = '';
     
    310318            $home_attr[] = 'data-team="'.($fixture->homeTeam->id).'"';
    311319            if ($this->show_gender) $fixture_card['Home Team'] .= ' ('.$fixture->homeTeam->gender.')';
     320            if ($show_detail) $this->detailClubTeam = $fixture->homeTeam->id;
    312321        }
    313322        if ($this->is_clubteam($fixture->awayTeam) && $this->is_clubwide()) {
     
    315324            $away_attr[] = 'data-team="'.($fixture->awayTeam->id).'"';
    316325            if ($this->show_gender) $fixture_card['Away Team'] .= ' ('.$fixture->awayTeam->gender.')';
     326            if ($show_detail) $this->detailClubTeam = $fixture->awayTeam->id;
    317327        }
    318328        if ($this->show_list) {
     
    571581        $gp = $gw = $gd = $gl = $gf = $ga = 0;
    572582        $form = [];
     583        $missing_result = false;
    573584        foreach ($data as $competition) {
    574585            foreach ($competition->fixtures as $fixture) {
     
    592603                    }
    593604                }
    594                 elseif ($this->is_beforetoday($valid_date)) continue;
     605                elseif ($this->is_beforetoday($valid_date)) { $missing_result = true; continue; }
    595606                elseif (!$next_fixture_date || $valid_date < $next_fixture_date) $next_fixture_date = $valid_date;
    596607            }
    597608        }
     609        if (!$missing_result) $this->set_expiry($next_fixture_date, 'nextfixture');
    598610        if ($teamname) {
    599611            $points = $gw * 3 + $gd;
     
    618630    private function multiple_teams() {
    619631        $html = '';
    620         $json_data = $required_data = $league_data = $guzzle_data = $team_keys = [];
     632        $json_data = $required_data = $league_data = $guzzle_data = $guzzle_required = [];
    621633        $no_data = 0;
    622634        $haveTeams = false;
     
    624636        foreach ($this->multiple_teams as $teamID) {
    625637            $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);
    628639            $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            }
    630650            else $json_data[$teamID] = $body;
    631651        }
    632652        // Guzzle required data if possible
    633653        if (method_exists($this,'guzzle_teams')) {
    634             $guzzle_data = $this->guzzle_teams($required_data);
     654            $guzzle_data = $this->guzzle_teams($guzzle_required);
    635655            $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) {
    639659            $this->customteam = $teamID;
    640660            $team_data = $this->get_json('customteam', $teamID);
     
    650670                }
    651671                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);
    653673            }
    654674        }
     
    668688    }
    669689
     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
    670708}
  • eh-gms-feed/trunk/includes/main-class.php

    r3065987 r3066677  
    3333        elseif ($this->validate_atts($atts)) {
    3434            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] : [])]);
    3636                else echo $this->get_table();
    3737            }
     
    6969        $this->atts_show['options'] = sanitize_text_field( $this->atts_show['options'] );
    7070        $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'])) {
    7272            if (empty($this->atts_show['club_id']) && ((!$this->is_competition() && !$this->is_team() && !$this->atts_show['show'] == 'fixture') || $this->atts_show['method'] == 'api-dynamic')) {
    7373                $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' );
     
    128128    public function gms_shortcode ( $atts = [] ) {
    129129        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';
    131132                wp_enqueue_script('EH_GMS_Feed');
    132133                $html_atts = '';
     
    143144
    144145    public function enqueue_scripts () {
    145         wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.13', true);
     146        wp_register_script('EH_GMS_Feed', plugin_dir_url(__DIR__).'js/eh-gms-feed.js', ['jquery'], '3.14', true);
    146147        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.12');
     148        wp_register_style('EH_GMS_Feed', plugin_dir_url(__DIR__).'css/gms-default.css',[],'3.14');
    148149        if ($this->settings->default_css == 'yes') wp_enqueue_style('EH_GMS_Feed');
    149150    }
  • eh-gms-feed/trunk/includes/settings.php

    r2981152 r3066677  
    1111
    1212    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;
    1614    public $default_css = 'yes';
    17     public $default_ajax = 'no';
     15    public $default_ajax = 'yes';
    1816    public $default_club_id;
    1917    private $settings;
     
    117115            <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>
    118116        </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>
    120118      <?php
    121119    }
  • eh-gms-feed/trunk/js/eh-gms-feed.js

    r3065987 r3066677  
    99    function club_team (message, filter, wrapper, detail) {
    1010        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) {
    1212            if (detail) {
    1313                detail.hide();
     
    9393                        detail.show();
    9494                        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                        }
    96101                        var fixture_card = detail[0].querySelector('.gms-card');
    97102                        if (fixture_card) {
  • eh-gms-feed/trunk/readme.txt

    r3065987 r3066677  
    55Tested up to: 6.5
    66Requires PHP: 5.3
    7 Stable tag: 3.13
     7Stable tag: 3.14
    88License: GPLv2
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6262
    6363== 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
    6472
    6573= 3.13 =
Note: See TracChangeset for help on using the changeset viewer.