=== Chess Podium ===

Contributors: marcobelemmi
Tags: chess, tournament, swiss, pairing, standings
Requires at least: 5.8
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.9.3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Manage chess tournaments from WordPress: players, Swiss pairings, results, standings, and exports. Free plan: up to 10 players per tournament.

== Description ==

Chess Podium helps chess clubs organize tournaments directly from WordPress. Create tournaments, add players, generate Swiss pairings, enter results, and publish standings—all without spreadsheets.

**Free plan includes:**
* Up to 10 players per tournament
* Swiss pairing
* Round Robin and Double Round Robin
* Results and standings
* Public tournament page
* CSV export
* FIDE ID import

**Upgrade to Pro** for unlimited players, advanced exports, PGN pages, and more. [Get Chess Podium Pro →](https://chesspodium.com/pricing/)

== Installation ==

1. Install the plugin through the 'Plugins' menu in WordPress, or upload the `chess-podium` folder to `/wp-content/plugins/`
2. Activate the plugin through the 'Plugins' menu
3. Go to **Settings → Permalinks** and save changes (required for the tournament page)
4. Open **Chess Podium** in the admin menu to create your first tournament

== Frequently Asked Questions ==

= What is the free player limit? =

The free plan allows up to 10 players per tournament. Upgrade to Chess Podium Pro for unlimited players.

= How do I display the tournament on my site? =

Use the shortcode `[chess_podium_tournament]` on any page, or visit `/torneo/` (or `/currenttournament/`) for the live tournament view.

= Can I import players from FIDE? =

Yes. Enter a FIDE ID to auto-import name, rating, and nationality from the official FIDE database.

== Terms of Service and Privacy Policy ==

This plugin may link to the plugin website's legal pages. Ensure these URLs are valid and publicly accessible:
* Terms of Service: https://chesspodium.com/terms-of-service/
* Privacy Policy: https://chesspodium.com/privacy-policy/

If your site uses different paths, create the corresponding pages and update the links where the plugin references them.

== External services ==

This plugin relies on the following third-party services to provide core functionality:

1. **Chess Podium Pairing API (http://89.167.56.28)**: Used to calculate tournament pairings (Swiss System and Round Robin). The plugin sends tournament data (player names, ratings, and results) to this server to generate the next round's pairings.
   * Service provided by: Chess Podium.
   * Data sent: Tournament IDs, player names, and scores.

2. **FIDE Ratings (https://ratings.fide.com)**: Used to fetch and update player Elo ratings and titles based on their FIDE ID.
   * Service provided by: International Chess Federation (FIDE).
   * Data sent: FIDE ID (public identifier).

3. **Stripe (https://api.stripe.com)**: Used to process payments for the Pro license.
   * Service provided by: Stripe, Inc.
   * Terms of Service: https://stripe.com/legal
   * Privacy Policy: https://stripe.com/privacy

4. **PayPal (https://api-m.paypal.com, https://api-m.sandbox.paypal.com)**: Used to process payments for the Pro license.
   * Service provided by: PayPal Holdings, Inc.
   * Terms of Service: https://www.paypal.com/webapps/mpp/ua/useragreement-full
   * Privacy Policy: https://www.paypal.com/webapps/mpp/ua/privacy-full

Additional services (optional, depending on configuration):

* **Chess Podium License API** (chesspodium.com): Validates Pro licenses. Sends: license key, site URL. Ensure Terms and Privacy pages exist on your site (e.g. /terms-of-service/, /privacy-policy/) or use your own policy URLs.
* **Lichess** (lichess.org): PGN live feed for broadcast games. Fetched server-side; no user data sent.
* **Wikimedia** (Wikipedia REST API, Wikidata SPARQL — wikipedia.org, wikidata.org): Optional. Used only to resolve **player profile thumbnail images** when FIDE does not return a usable photo. Sends: player name and/or FIDE ID (public). No account data.

**Note on shortcode names:** This plugin uses the prefix `chess_podium_` for all new shortcodes (e.g. `[chess_podium_tournament]`, `[chess_podium_manager_tornei]`). Legacy shortcodes `checkmate_manager_tornei`, `storico_tornei`, and `regina_torneo` are kept only for backward compatibility; prefer the `chess_podium_*` equivalents for new installations.

== Third-party software ==

For third‑party software licenses and external services used by this plugin, see `THIRD-PARTY.txt` in the plugin root.

== Screenshots ==

1. Tournament management dashboard
2. Add players and generate pairings
3. Public standings page

== Changelog ==

= 1.9.3 =
**WordPress 7.0**
* Declared **ready for WordPress 7.0** (`Tested up to: 7.0`). Gutenberg blocks use **block API version 3** (`chess-podium/tournament`, `chess-podium/tournament-archive-card`) for compatibility with the iframed post editor rollout.

**Tournament archive card**
* New Gutenberg block **`chess-podium/tournament-archive-card`** and shortcode **`[chess_podium_tournament_archive id="X"]`**: cover image (gallery, venue photo, or logo), compact **standings preview**, and link to the **live tournament page** or **published HTML export** (`rows`, `show_image`, `link="auto|live|archive"`).
* Admin **Add to page** screen: full shortcode documentation with examples, parameters, and Gutenberg notes (translated IT/FR/DE/ES).

**Internationalization**
* New and updated strings for the archive card block, shortcode, and admin documentation.

= 1.9.2 =
**Public events calendar**
* New shortcode `[chess_podium_events]`: month grid plus optional list of tournaments with dates (tournament row, brochure fields, or round dates).
* Shows **past**, **current**, and **upcoming** events; attributes include `include_past`, `include_ongoing`, `thumbnails`, `show_list`, `month`.
* List **thumbnails** follow the same preview rules as tournament cards (first gallery image, else brochure logo, else default).
* Admin **Overview** and **brochure/Content** fields for event dates and calendar visibility; brochure save keeps dates aligned with the tournament row; `calendar_visible` stored on the tournament.

**Calendar presentation**
* Day cells use **text-only** links (no thumbnails in the grid); **past** events use **muted** styling; tournament names are **bold**, slightly larger, and **wrap** in uniform cells.

**Player profile shortcode**
* `[chess_podium_player_profile]`: **photo** (directory avatar or roster/FIDE cache), **country flag**, and a **clickable name** (and image when linked) to the **unified** `/player/{slug}/` profile when the player exists in the directory.

**Internationalization**
* New and updated strings for the calendar and profile shortcode across supported locales.

= 1.9.1 =
**Unified player directory & public profiles**
* Directory profile URL pattern: `/player/{slug}/` with avatar, bio, external links (FIDE, Lichess, etc.), **tournament history**, and **career statistics**.
* **Tournament context** via `?cp_tournament={id}`: “From this tournament” block with standings-style stats, round-by-round table, opponent names resolved from detailed pairings (with roster fallback), and **game links only when** archived round PGN exists or the pairing has non-empty live PGN (avoids empty boards).
* **Routing resilience**: if WordPress handles `/player/{slug}/` as a normal page, the plugin falls back to parsing the request URI so unified profiles still render.
* **FIDE ratings profile** links use the official `https://ratings.fide.com/profile/{id}` endpoint; the FIDE ID in the header links there.

**Career overview & charts**
* Aggregate **W / D / L** share, **rating vs performance** sparkline (SVG), and **per-tournament Elo change** bars built from detailed pairing data where available.

**Exports (published tournament folder)**
* Player links target the **unified WordPress profile** and append `cp_tournament` when a directory player is mapped, keeping context from exports.

**Admin**
* **Players** (directory): upload and remove **profile avatar** image.

**Internationalization**
* Cleaned duplicate `msgid` entries in translation files (e.g. “Players”, “— Select —”, “Tournament history”) for reliable Poedit merges.

= 1.9.0 =
**Partner hotels (Budget tab)**  
* Add partner hotels (name/city/stars) with a tournament share rate (€/presence/day).
* Assign each player to a partner hotel, with family members, days, hotel total and tournament share (auto-calculated: rate × (player+family) × days).
* New exports for hotel data: **CSV** and **PDF** (with HTML fallback when PDF engine is unavailable).
* Summary table: tournament income by hotel.

= 1.8.7 =
**Players (admin)**
* Fixed bulk save in Players tab (“Save all players”) when multiple actions were present (invalid nested forms prevented submissions in some browsers).
* Added **manual player photo** (global per player): select from **Media Library** or **upload from computer**; manual photo takes priority over FIDE/Wikipedia/generic avatar.

**Published tournaments (HTML export)**
* Export now uses **SEO-friendly player profile URLs** (e.g. `name-surname.html`). Legacy `player-<id>.html` files are still generated and redirect to the new URL.
* Exported player profiles now support the manual player photo override.

= 1.8.6 =
**Published tournaments (HTML export)**  
* Fixed player name click in exported pages (links now open `player-<id>.html` reliably; no “click does nothing”).  
* Improved export photo resolution: fetch and cache FIDE photos during export when available; safe fallback to generic avatars when FIDE has no real photo (avoids blank/placeholder images).

**Printable material**  
* New **Board cards (PDF)**: board number cards with tournament logo and name, optimized for cutting (**6 per page**).

= 1.8.5 =
**Team tournaments (Swiss + standings + TRF16)**  
* New **team tournament mode**: create teams, assign players to teams and boards, manage team matches per round.  
* Team standings with **Match Points (MP)** and **Board Points (BP)** plus team tie-breaks: **Buchholz MP/BP**, **EDE**, **ESB**.  
* TRF16 export: team count in `012` and new team section **`013`** (Annex 2).  
* Swiss-style **auto pairing for teams** (avoids repeats when possible) with official **BYE** handling for odd team counts.

**Live tournament performance**  
* Heavy PGN fetch work moved out of the request path (reduces live page timeouts on large events).

**Stockfish analysis (public game page)**  
* Engine PV lines shown in **SAN** (user-friendly) instead of raw UCI.

**Build**  
* `CHESS_PODIUM_VERSION` **1.8.5**, `build-zip.ps1` → `chess-podium-1.8.5.zip`; marketing theme **1.8.5**; `dev/chess-podium-svn` mirror aligned.

= 1.8.4 =
**Tournament communications (Pro, GDPR-oriented)**  
* Player records: optional **email** and **opt-in for technical emails** (pairings, notices) during registration and from the admin players UI.  
* **Communications** tab: compose **HTML** messages with placeholders (`{player_name}`, `{tournament_name}`, `{pairing_url}`, `{table_number}`, `{round_number}`, `{site_url}`) and send via WordPress (`wp_mail`). Only players with a valid address who opted in receive bulk mail.  
* **Background delivery**: queued recipients are sent in small batches with scheduled cron (avoids admin timeouts on long lists).  
* **Recent sends** log per tournament (date, subject, recipient count).  
* **Test email** to any address before bulk send: single preview with sample placeholder values, subject prefixed `[TEST]`, does not enqueue bulk mail or add a log row.  
* **Rounds** tab: **Notify players (email)** shortcut opens Communications with a pre-filled pairings message for the current round.

**Translations**  
* New and updated strings for communications, registration opt-in, and admin notices in **IT / DE / FR / ES**.

= 1.8.3 =
**Performance & scalability (large tournaments)**  
* Added **versioned caching** (object cache + per-request memoization) for heavy reads: players, pairings (all/round/detailed), standings.  
* Cache invalidates automatically via a per-tournament **cache version bump** when results/pairings/rounds change (save results, save pairings, generate/rollback round, swap colors, delete player, Lichess import).  
* Public tournament page: **standings load asynchronously** (AJAX + pagination + nonce) for large tournaments to keep pages responsive.

**Routing & multilingual robustness**  
* Fixed “No content” on multilingual sites when `?lang=...` is present by parsing pretty URLs directly (player profile, game SEO URL, round URL) even if rewrite rules were flushed under a different locale.

**Published tournaments grid** (`[chess_podium_tornei]`)  
* Preview image priority restored: **gallery photo → event logo → default**.

**Translations**  
* Completed missing UI strings (Lichess import, pairing settings labels/options) across IT/DE/FR/ES.  
* Standardized **“Anti-cheating”** to remain in English everywhere (avoid non-standard local translations like “antitrucchi”).

**Refactor (codebase maintainability)**  
* Split bootstrap wiring into dedicated classes: `ChessPodium_Admin`, `ChessPodium_Frontend`, `ChessPodium_FrontendAjax` (keeps behavior, reduces `chess-podium.php` responsibilities).

= 1.8.2 =
**Public tournament & player profile**  
* SEO-friendly URLs for tournament, rounds, games, and **player profile** (pretty permalinks + rewrite rules; optional slug per tournament/player).  
* **Current round pairings**: white and black names are **clickable** and open the in-tournament player profile.  
* **Player profile photo**: FIDE page parsing improved (rejects generic og:image); **Wikipedia / Wikidata fallback** — Wikidata **P1440** (FIDE ID) → article title, **full-text search** on Wikipedia when the stored name does not match the article title, multiple wiki languages; filter `chess_podium_player_photo_url` for overrides.  
* External services note: optional requests to **Wikimedia** (Wikipedia API, Wikidata SPARQL) for profile thumbnails when FIDE does not expose a usable image.

**Build**  
* `CHESS_PODIUM_VERSION` **1.8.2**, `build-zip.ps1` → `chess-podium-1.8.2.zip`; marketing theme **1.8.2**; `dev/chess-podium-svn` mirror aligned.

= 1.8.1 =
**Live single game replay: Chessground + engine analysis (client-side)**  
* New single game page UI with Chessground board (mobile-friendly) and robust live polling without resetting to start position.  
* Analysis mode: replay previous moves without live overriding; make your own legal moves as a “variation” from any position.  
* Client-side Stockfish (Web Worker) analysis with evaluation bar, best-move arrow and MultiPV lines; explicit Start/Stop evaluation toggle.  
* Exported photo galleries: lightbox restored (clicking an image opens it again).  
* Live tournament UI: pairings table now scrolls horizontally on mobile instead of overflowing the page.

= 1.8 =
**FIDE profile import (ratings.fide.com)**  
* Parsing updated for the current public profile HTML: federation from the flag image under `.profile-info-country` (e.g. `/images/flags/us.svg` → ISO-2), FIDE title from `.profile-info-title` (e.g. “Grandmaster” → GM). Legacy fallbacks kept.  
* `sanitize_fide_title()` now maps full English title names (Grandmaster, International Master, Woman Grandmaster, etc.) to standard abbreviations.

**Tournament types & rounds**  
* New system type: **Double round robin** (second cycle repeats Berger pairings with colours reversed). Suitable for events such as the FIDE Candidates (8 players, 14 rounds).  
* **Tournament type** can be changed after creation from **Chess Podium → tournament → Settings** (Swiss / Round Robin / Double Round Robin).  
* Maximum **rounds** increased to **99** (create form, wizard, settings, Excel import); wizard client validation updated.

**Players**  
* **Manual add player**: optional **FIDE ID** field (unique per tournament), same validation as FIDE import.

**Public & live UI**  
* **Live tournament dashboard** (`/torneo/livetournament/`): shows **tournament logo** from brochure settings when set.  
* **Published tournaments grid** (`[chess_podium_tornei]`): card image prefers **brochure logo**, then first gallery photo, then default.

**Exports**  
* TRF header tournament type: `round_robin` and `double_round_robin` both emit **RR** (two-letter field).

**Marketing theme (chess-podium-template)**  
* Homepage **“See it in action”**: second example card links to the **FIDE Candidates 2026** tournament run on Chess Podium: `https://www.chesspodium.com/tournament/?tournament_id=27` (standings, rounds, pairings, live boards), alongside the Cattolica archive and DGT demo.  
* Theme version **1.8**; download/SEO strings and EN/IT/DE/FR/ES translations for the new block.

**Build**  
* `CHESS_PODIUM_VERSION` **1.8.1**, `build-zip.ps1` → `chess-podium-1.8.1.zip`; `dev/chess-podium-svn` mirror aligned.

= 1.7.9 =
* Fair play & anti-cheating: per-tournament checklist and text (FIDE Handbook §09 themes), optional fair play officer and complaints URL; shown on live page and static HTML export when enabled (Settings tab).

= 1.7.8 =
* Emergency hotfix: include missing `includes/class-pdf-badges.php` file in release package to prevent fatal errors on some installations.
* Hardening: badge module include is now guarded with `file_exists()` to prevent full plugin crash if file is unavailable.

= 1.7.7 =
* Tie-break engine aligned with Swiss-Manager/FIDE 2023 rules for unplayed rounds (BYE/withdrawn) in Buchholz, Buchholz Cut 1, and Sonneborn-Berger.
* Direct Encounter (DE) ranking logic fixed with correct mini-league handling inside tied groups.
* New print-ready exports: Badges and Placecards PDF/HTML with robust pagination (no card split across pages).
* Placecards layout optimized for green printing (4 per page).
* FIDE real-time sync: per-player and bulk "Sync with FIDE" action from Players tab.
* Public tournament player profile page (`?cp_player=`) with tournament stats and optional FIDE profile photo.
* Badges improved: tournament name on card, nationality flag, per-player QR code linking to live tournament player profile.
* New/updated translations (IT/DE/FR/ES) for the new UI and print features.

= 1.7.6 =
* Setup wizard after activation (guided first tournament, optional published page with shortcode)
* Gutenberg block `chess-podium/tournament` and Classic Editor shortcode inserter
* Customizer: colors for public tournament tables and chessboard squares
* FIDE norms: omit redundant GM/IM norm badges when the player already holds that title or higher
* Minor copy and translation string updates

= 1.7.5 =
* WordPress.org review compliance: All JS/CSS included via wp_enqueue_script, wp_enqueue_style, wp_add_inline_script, wp_add_inline_style (no raw script/style tags on WordPress pages)
* No remote assets: jQuery, chess.js, chessboard bundled in plugin; export uses only local paths (js/jquery.min.js, js/chess.min.js, etc.)
* Paths: plugin_dir_path() and plugins_url() used throughout; removed ABSPATH/WPINC for export (jQuery copied from plugin only)
* Game page: inline CSS/JS moved to wp_register_style + wp_add_inline_style and wp_register_script + wp_add_inline_script
* PDF certificate: comment added clarifying inline style is for dompdf output only

= 1.7.4 =
* WordPress.org review compliance: Terms/Privacy URLs updated to /terms-of-service/ and /privacy-policy/ (ensure these pages exist on your site)
* External services: full readme section (Pairing API, FIDE, Stripe, PayPal) with data sent and policy links
* Export: copy_export_vendor_assets uses plugin path only; jQuery fallback to WordPress wp-includes/js/jquery when not in plugin (chessboard always works in static export)
* Scripts: admin tab and config modal moved to wp_enqueue_script (admin-tabs.js, admin-config-modal.js) with wp_localize_script for strings
* Sanitization: HTTP_ACCEPT_LANGUAGE and all file upload type/size use sanitize_text_field and wp_check_filetype (do not trust $_FILES['type'])
* Escaping: all echoed variables use esc_attr, esc_html, wp_kses_post; class-grand-prix.php render_player_with_flag output wrapped in wp_kses_post; wrap_html export title escaped
* Transient: cp_pgn_fetch_ renamed to chess_podium_pgn_fetch_ for consistent prefixing

= 1.7.2 =
* Plugin header format aligned to WordPress Plugin Handbook (DocBlock, colon alignment)

= 1.7.1 =
* Plugin header format fix for WordPress.org Plugin Check (Description, Version, License)

= 1.7.0 =
* WordPress.org compliance: replaced inline scripts/styles with wp_enqueue_script, wp_enqueue_style, wp_add_inline_script, wp_add_inline_style
* Local assets: chess.js, chessboard-js, chess piece images, and country flags bundled in plugin (no CDN)
* External services documented in readme (License API, PayPal, bbpPairings, Lichess)
* Plugin paths use plugin_dir_path() and plugin_dir_url() consistently
* Sanitization: $_FILES filenames with sanitize_file_name(), wp_json_encode for JSON output
* Escaping: all echoed variables use esc_attr(), esc_html() where appropriate
* Shortcodes: added chess_podium_manager_tornei, chess_podium_storico_tornei; renamed cpSponsorsAdmin to chessPodiumSponsorsAdmin. Legacy shortcodes (regina_torneo, checkmate_manager_tornei, storico_tornei) kept only for backward compatibility with existing beta/external installs; all new elements use chess_podium_ prefix.
* Static export: vendor JS/CSS and flags copied locally; no remote dependencies
* Live dashboard: local flag images, escaped output (XSS prevention)

= 1.6.0 =
* Grand Prix: create series of linked tournaments with points per position, participation points, social ELO, aggregated standings
* Admin: Chess Podium → Grand Prix to create and manage Grand Prix
* Shortcode: [chess_podium_grand_prix id="X"] to display Grand Prix standings
* Tournament settings: link tournaments to one or more Grand Prix

= 1.5.0 =
* chess-results Excel import: create tournament, import players, bulk import round results
* Same pairing engine as Swiss Manager (JaVaFo) and chess-results compatibility
* Improved Excel format support for player list and pairing exports

= 0.3.0 =
* Free and Pro tiers: 10 players free, unlimited with Pro license
* License management page
* FIDE player import
* CSV bulk import
* External tournaments support
* PGN upload and display
* Photo gallery
* Export to folder

= 0.2.0 =
* Swiss pairing
* Standings and tiebreakers
* Public tournament page

= 0.1.0 =
* Initial release

== Upgrade Notice ==

= 1.9.3 =
WordPress 7.0 ready. New tournament archive card block and shortcode for blog posts with standings preview and cover image.

= 1.9.2 =
Public events calendar shortcode, clearer calendar styling for past events, and richer player profile shortcode.

= 1.9.1 =
Unified directory player profiles with tournament context, career charts, smarter export links, directory avatars, and translation catalog cleanup.

= 1.9.0 =
Partner hotels tracking in Budget tab, with per-player stays and CSV/PDF reports.

= 1.8.6 =
Export HTML: player profile pages + more reliable FIDE photos. New printable Board cards PDF (6 per page).

= 1.8.5 =
Team tournaments (teams, Swiss pairings, standings, TRF16 team export) + live page performance improvements + Stockfish PV lines in SAN.

= 1.8.2 =
Pretty URLs for player profiles, clickable pairings, and improved profile photos (FIDE + Wikipedia/Wikidata).

= 1.8.1 =
Live replay/analysis improvements and mobile UI fixes.

= 1.8 =
Version alignment and marketing site update (Candidates tournament link on homepage). Same plugin behavior as 1.7.9.
= 1.7.9 =
Fair play / anti-cheating section for players (FIDE-aligned themes), live page and export.
= 1.7.8 =
Emergency hotfix for a fatal error introduced in 1.7.7. Update immediately.
= 1.7.7 =
Major standings/tie-break fixes (FIDE 2023 compliant), new badge/placecard printing, real-time FIDE sync, and QR-linked player profiles.
= 1.7.6 =
Setup wizard, Gutenberg tournament block, Customizer table/board colors, smarter FIDE norm display.
= 1.7.5 =
WordPress.org compliance: wp_enqueue for all assets, no remote CDN (jQuery bundled), plugin_dir_path/plugins_url only, game page uses wp_add_inline_script/style.
= 1.7.4 =
WordPress.org compliance: Terms/Privacy URLs, enqueue scripts, sanitization, escaping, external services docs, transient prefix.
= 1.7.2 =
Plugin header format aligned to WordPress Plugin Handbook.
= 1.7.1 =
Plugin header format fix for WordPress.org Plugin Check.
= 1.7.0 =
WordPress.org compliance: local assets, proper enqueue, sanitization, escaping. Backward-compatible shortcodes preserved.
= 1.6.0 =
Grand Prix: series of linked tournaments with points, social ELO, and aggregated standings. New admin section and shortcode.
= 1.5.0 =
chess-results Excel import: import tournament data, player list, and round results from chess-results exports.
= 0.3.0 =
Free plan: up to 10 players per tournament. Upgrade to Pro for unlimited players.
= 0.2.0 =
* Swiss pairing and standings
= 0.1.0 =
* Initial release
