# Stride Club – Garmin stats for you and your friends

A multi-user website (plain PHP + MySQL, no WordPress) built from the
"Garmin Connect Activities" WordPress plugin. People sign up, connect their own
Garmin account with a Garmin *Personal API key*, follow each other, compare
statistics on leaderboards, and add medal pictures, event photos and notes to
their activities. The site comes in Danish and English, with the dark theme from running.gnax.io.

"Stride Club" is a placeholder name. Change `site_name` in `config.php`.

## Requirements

- PHP 8.1 or newer with these extensions: pdo_mysql, openssl, curl, gd, mbstring (exif is optional and keeps phone photos the right way up)
- MySQL 5.7+ or MariaDB 10.3+
- Apache with mod_rewrite (standard on shared hosting), or nginx (see below)
- HTTPS (needed so that logins and Garmin keys are protected in transit)

## Install

1. **Create a database** and a database user in your hosting control panel.
2. **Import `schema.sql`** into it (phpMyAdmin → Import, or `mysql -u USER -p DB < schema.sql`).
3. **Upload the whole folder** to the server.
   - Best: point the domain's/subdomain's *document root* at the `public/` folder.
   - If you can't change the document root, upload everything into the web root.
     The `.htaccess` in the top folder sends every request into `public/`, so
     `config.php`, `src/`, `storage/` etc. can't be downloaded.
4. **Copy `config.sample.php` to `config.php`** and fill in the database details and `site_name`.
5. Open the site once. It shows a freshly generated value for `app_key`.
   Paste that into `config.php`. **Keep it secret and never change it later:**
   it encrypts every user's Garmin key.
6. Make `storage/uploads/` writable by PHP (usually it already is).
7. **Set up automatic sync** (see below). Then create your own account on the site.

### Automatic sync (cron)

In the hosting panel's cron/scheduled tasks, run every 15 minutes:

    php /full/path/to/site/cron/sync.php

Each user is synced at most every `sync_interval_minutes` (default 60).

If your host only offers "call a URL" cron jobs, set a long random
`cron_token` in `config.php` and call
`https://your-site/cron.php?token=YOUR_TOKEN` every 15 minutes.

Users can also press **Sync now** in Settings → Garmin at any time.

### nginx

    root /path/to/site/public;
    location / { try_files $uri /index.php?$query_string; }
    location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/run/php/php-fpm.sock; }

## How privacy works

- Only logged-in users can see anything beyond the front page.
- A user's activities, statistics, medals and photos are visible only to the user
  and to people whose **follow request they have accepted**. Following each other = friends.
- Leaderboards show only you and the people you follow (accepted).
- People search shows names and usernames only, never data.
- Garmin keys and access tokens are encrypted (AES-256-GCM) in the database and only sent to Garmin.
- Only the Garmin fields the dashboard uses are stored. GPS start points, device and owner details are dropped.
- Uploaded images are re-encoded, which strips EXIF data including GPS position. They are stored
  outside the public folder and served only after an access check.
- Passwords are hashed. Failed logins are rate-limited. All forms have CSRF protection.
- Users can disconnect Garmin, delete their imported activities, or delete their whole account.

## Folder overview

    public/           web root: index.php (router), cron.php, assets (CSS, JS)
    src/              application code (App = routes, Stats, Leaderboard, Follows, Media, Garmin, Importer …)
    views/            page templates
    lang/             da.php and en.php: all texts. Add a language by copying one of them
                      and adding it to I18n::LANGUAGES in src/I18n.php
    cron/sync.php     automatic sync
    storage/uploads/  medal and photo files
    schema.sql        database tables

## Good to know

- **Garmin's terms:** Garmin describes the Personal API as being for individuals accessing
  their own data, "not intended for commercial applications serving multiple end users".
  This site has each user use their own key. That fits a private, non-commercial group
  of friends or a club. Anything bigger or commercial should apply for Garmin's business
  Developer Program (OAuth), and `src/Garmin.php` is the one place to change.
- Personal API keys expire after 30 days to one year. Users can enter the expiry date to get a
  reminder in Settings. Garmin also e-mails them.
- Not included yet: "forgot password" e-mails (needs working mail on the host) and the
  route maps from the plugin.
