=== DigiExpert8 Forms File Uploader for OneDrive ===
Contributors: digiexpert8
Tags: onedrive, microsoft graph, gravity forms, wpforms, contact form 7
Requires at least: 6.2
Tested up to: 6.9
Requires PHP: 7.4
Stable tag: 1.1.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Uploads Gravity Forms, WPForms, and Contact Form 7 files to Microsoft OneDrive with secure OAuth and configurable filtering.

== Description ==

DigiExpert8 Forms File Uploader for OneDrive is an independent plugin and is not affiliated with, endorsed by, or sponsored by Microsoft.

The plugin provides:

* Microsoft OAuth2 connection flow for OneDrive.
* Gravity Forms, WPForms, and Contact Form 7 file upload support.
* Form ID and Field ID filtering per provider.
* Folder templates always control the OneDrive folder path and support placeholders: `{form_title}`, `{provider}`, `{form_id}`, `{entry_id}`, `{date}`, `{submission_folder}`.
* Field placeholders are supported, including Gravity Forms and WPForms values like `{field_3}`, Gravity sub-inputs like `{field_1_3}`, and name-based placeholders like `{passport_number}`, `{full_name}`, or `{applicant_name}`.
* Optional Gravity Forms entry PDF summary upload.
* Optional local file deletion after successful upload.
* Encrypted storage for client secret and tokens.

== Installation ==

1. Copy `digiexpert8-forms-file-uploader-for-onedrive` into `/wp-content/plugins/`.
2. Activate the plugin in WordPress admin.
3. Open `DigiExpert8 Forms File Uploader for OneDrive` in the WordPress admin menu.
4. Follow the detailed setup steps below.

== External Services ==

This plugin connects to Microsoft OneDrive through Microsoft Graph.

It sends data to Microsoft only when:
* an administrator clicks `Connect OneDrive` and completes OAuth authorization
* a configured form submission triggers a file upload to OneDrive
* optional Gravity Forms PDF summary upload is enabled and a PDF summary is uploaded

Data sent to Microsoft may include:
* OAuth authorization data required to obtain access and refresh tokens
* uploaded file contents
* remote folder and file names built from plugin settings and form submission context

Folder template examples:
* `{form_title}_{field_3}_{field_48}_{entry_id}`
* `IDLV_Alex Smith_A1234567_987`
* `{form_title}_{full_name}_{passport_number}_{entry_id}`
* `{provider}/{form_id}/{field_3}/{entry_id}`
* `{provider}/{form_id}/{field_1_3}-{field_1_6}/{entry_id}`
* `{provider}/{form_id}/{submission_folder}`

Service provider:
* Microsoft OneDrive / Microsoft Graph

Service documentation and terms:
* Microsoft Graph: https://learn.microsoft.com/graph/overview
* Microsoft Terms of Use: https://www.microsoft.com/servicesagreement
* Microsoft Privacy Statement: https://privacy.microsoft.com/privacystatement

== Changelog ==

= 1.1.4 =
* Preserved existing refresh tokens when Microsoft token refresh responses do not include a replacement refresh token.
* Improved local upload URL resolution for protocol/domain aliases, encoded filenames, and query strings.
* Fixed fallback URL downloads being rejected before upload when a form plugin returns a URL that cannot be mapped directly to the uploads directory.
* Improved WPForms and Contact Form 7 uploaded file detection for newer/nested file payloads.

= 1.1.3 =
* Made the configured Folder Template authoritative for OneDrive folder paths across providers.
* Added form title and field placeholder support for folder templates, including Gravity Forms, WPForms, and Contact Form 7 field values.
* Changed the default folder template to `{form_title}_{field_3}_{field_48}_{entry_id}` with updated admin examples.
* Removed automatic duplicate-folder suffixing so deterministic templates stay unchanged.

= 1.1.2 =
* Added WordPress.org submission polish for external service disclosure and public metadata.

= 1.1.1 =
* Added WordPress.com Marketplace-friendly metadata headers.
* Added Plugins screen Settings link.
* Added non-breaking extension hooks for upload context and Gravity Forms folder/file customization.
* Updated debug logging to prefer WooCommerce logger when available.

= 1.1.0 =
* Added optional Gravity Forms entry PDF summary upload to the same OneDrive submission folder.
* Added admin setting to enable or disable Gravity Forms PDF summary upload.
* Kept existing file-upload behavior unchanged by default.

= 1.0.0 =
* Initial production release.

== Troubleshooting ==

* `AADSTS50011` redirect mismatch:
  * The Redirect URI in Entra must exactly match the plugin value, including protocol (`https://`), domain, path, and trailing slash behavior.
* `OneDrive connection failed` after clicking Connect:
  * Save settings first and confirm Tenant ID, Client ID, and Client Secret are not empty.
  * If secret is regenerated in Entra, paste new secret Value in plugin and save again.
* Permission errors from Graph:
  * Confirm `Files.ReadWrite` is delegated permission (not application permission).
  * Confirm consent was granted in the same tenant/account you sign in with.
* Upload size issues:
  * Current upload call uses Microsoft Graph simple upload (`PUT .../content`), which supports up to 250 MB per file.
  * Resumable/chunked upload sessions are not implemented in this plugin version.

== Security Notes ==

* Only users with `manage_options` can configure or connect OneDrive.
* OAuth state is validated to prevent CSRF.
* Settings forms and actions use WordPress nonces.
* Secrets and tokens are encrypted at rest using site salts.
* Upload path building sanitizes all path segments.
* Local path resolution is restricted to the WordPress uploads directory.

== Known Limits ==

* This version uploads immediately on form completion.
* Large/resumable upload sessions are not yet implemented.
* Upload retries/queue management are not yet implemented.
