Implement version 0.0.3 features

- Add file attachment support for product versions (Media Library)
- Add version auto-detection from uploaded filenames
- Implement secure customer downloads with hash verification
- Add license key copy-to-clipboard functionality
- Redesign customer licenses page with card-based UI
- Fix product versions meta box visibility for non-licensed types
- Add DownloadController for secure file delivery
- Update CLAUDE.md roadmap and session history

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-21 19:46:50 +01:00
parent 41e5f8d467
commit 78e43b9aea
15 changed files with 1036 additions and 133 deletions

View File

@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.0.3] - 2026-01-21
### Added
- File attachment support for product versions (WordPress Media Library integration)
- Version auto-detection from uploaded filenames (e.g., `plugin-v1.2.3.zip`)
- Customer download page for purchased licenses with secure authenticated downloads
- License key copy-to-clipboard functionality on account page and emails
- New card-based UI for customer licenses page with download section
- DownloadController for secure file delivery with hash-based URL verification
### Changed
- Product versions meta box now hidden for non-licensed product types (dynamic show/hide)
- Redesigned customer licenses page with modern card layout
- Frontend JavaScript and CSS enhancements for better UX
### Technical Details
- New class: DownloadController for secure file downloads
- Database schema updated: `attachment_id` column added to versions table
- ProductVersion model extended with `getEffectiveDownloadUrl()` and `getDownloadFilename()`
- Secure download URLs use hash verification (license_id-version_id-hash format)
## [0.0.2] - 2026-01-21 ## [0.0.2] - 2026-01-21
### Added ### Added
@@ -68,6 +92,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- WordPress REST API integration - WordPress REST API integration
- Custom WooCommerce product type extending WC_Product - Custom WooCommerce product type extending WC_Product
[Unreleased]: https://src.bundespruefstelle.ch/magdev/wc-licensed-product/compare/v0.0.2...HEAD [Unreleased]: https://src.bundespruefstelle.ch/magdev/wc-licensed-product/compare/v0.0.3...HEAD
[0.0.3]: https://src.bundespruefstelle.ch/magdev/wc-licensed-product/compare/v0.0.2...v0.0.3
[0.0.2]: https://src.bundespruefstelle.ch/magdev/wc-licensed-product/compare/v0.0.1...v0.0.2 [0.0.2]: https://src.bundespruefstelle.ch/magdev/wc-licensed-product/compare/v0.0.1...v0.0.2
[0.0.1]: https://src.bundespruefstelle.ch/magdev/wc-licensed-product/releases/tag/v0.0.1 [0.0.1]: https://src.bundespruefstelle.ch/magdev/wc-licensed-product/releases/tag/v0.0.1

View File

@@ -36,12 +36,11 @@ This project is proudly **"vibe-coded"** using Claude.AI - the entire codebase w
_No known bugs at this time._ _No known bugs at this time._
### Version 0.0.3 (Next) ### Version 0.0.4 (Next)
- Add download file attachment support for product versions
- Implement customer download page for purchased licenses
- Add license key copy-to-clipboard functionality in emails and account page
- Consider adding license usage statistics/analytics - Consider adding license usage statistics/analytics
- Consider adding bulk license operations in admin
- Consider adding license renewal/extension functionality
## Technical Stack ## Technical Stack
@@ -289,3 +288,31 @@ Base: `/wp-json/wc-licensed-product/v1/`
- Rate limiting uses WordPress transients - Rate limiting uses WordPress transients
- IP detection supports Cloudflare and proxies - IP detection supports Cloudflare and proxies
- Version management uses AJAX for smooth UX - Version management uses AJAX for smooth UX
### 2026-01-21 - Version 0.0.3 Features
**Implemented:**
- File attachment support for product versions (WordPress Media Library integration)
- Version auto-detection from uploaded filenames (e.g., `plugin-v1.2.3.zip`)
- Customer download page for purchased licenses with secure authenticated downloads
- License key copy-to-clipboard functionality on account page
- New card-based UI for customer licenses page with download section
- Product versions meta box visibility fix (now hidden for non-licensed product types)
**New classes:**
- `DownloadController` - Secure file delivery with hash-based URL verification
**Technical notes:**
- Secure download URLs use hash verification (license_id-version_id-hash format)
- Database schema updated: `attachment_id` column added to versions table
- ProductVersion model extended with `getEffectiveDownloadUrl()` and `getDownloadFilename()`
- Media uploader filters for zip files only
- Clipboard API with fallback for older browsers
- Card-based responsive UI design for licenses page
**Bug fixes:**
- Fixed product versions meta box visibility for non-licensed product types (targets `#wc_licensed_product_versions` container)

View File

@@ -145,3 +145,23 @@
font-style: italic; font-style: italic;
color: #666; color: #666;
} }
/* File Upload UI */
.selected-file-name {
display: inline-block;
margin-right: 10px;
padding: 5px 10px;
background: #e7f3ff;
border-radius: 3px;
font-weight: 500;
}
.selected-file-name:empty {
display: none;
}
#versions-table .dashicons-media-archive {
color: #2271b1;
vertical-align: middle;
margin-left: 5px;
}

View File

@@ -37,7 +37,206 @@
color: #383d41; color: #383d41;
} }
/* License Table */ /* License Cards */
.woocommerce-licenses {
display: flex;
flex-direction: column;
gap: 1.5em;
}
.license-card {
border: 1px solid #e5e5e5;
border-radius: 8px;
overflow: hidden;
background: #fff;
}
.license-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1em 1.5em;
background: #f8f9fa;
border-bottom: 1px solid #e5e5e5;
}
.license-header h3 {
margin: 0;
font-size: 1.1em;
}
.license-header h3 a {
color: inherit;
text-decoration: none;
}
.license-header h3 a:hover {
text-decoration: underline;
}
.license-details {
padding: 1.5em;
}
.license-key-row {
display: flex;
align-items: center;
gap: 0.75em;
margin-bottom: 1em;
flex-wrap: wrap;
}
.license-key-row label {
font-weight: 600;
}
.license-key-row code {
font-family: 'SF Mono', Monaco, Consolas, monospace;
background-color: #f5f5f5;
padding: 0.4em 0.8em;
border-radius: 4px;
font-size: 1em;
letter-spacing: 0.05em;
}
.copy-license-btn {
display: inline-flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
padding: 0;
background: #f0f0f0;
border: 1px solid #ddd;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
}
.copy-license-btn:hover {
background: #e5e5e5;
border-color: #ccc;
}
.copy-license-btn .dashicons {
font-size: 18px;
width: 18px;
height: 18px;
}
.copy-feedback {
display: inline-block;
margin-left: 0.5em;
padding: 0.25em 0.5em;
font-size: 0.85em;
border-radius: 3px;
}
.copy-feedback.success {
background: #d4edda;
color: #155724;
}
.copy-feedback.error {
background: #f8d7da;
color: #721c24;
}
.license-info-row {
display: flex;
gap: 2em;
color: #666;
font-size: 0.95em;
flex-wrap: wrap;
}
/* Download Section */
.license-downloads {
padding: 1em 1.5em;
background: #f8f9fa;
border-top: 1px solid #e5e5e5;
}
.license-downloads h4 {
margin: 0 0 0.75em 0;
font-size: 0.95em;
color: #333;
}
.download-list {
list-style: none;
margin: 0;
padding: 0;
}
.download-list li {
display: flex;
align-items: center;
gap: 1em;
padding: 0.5em 0;
border-bottom: 1px solid #eee;
}
.download-list li:last-child {
border-bottom: none;
}
.download-link {
display: inline-flex;
align-items: center;
gap: 0.5em;
color: #2271b1;
text-decoration: none;
font-weight: 500;
}
.download-link:hover {
text-decoration: underline;
}
.download-link .dashicons {
font-size: 16px;
width: 16px;
height: 16px;
}
.download-version {
background: #e7f3ff;
padding: 0.2em 0.5em;
border-radius: 3px;
font-size: 0.85em;
color: #2271b1;
}
.download-date {
color: #999;
font-size: 0.85em;
margin-left: auto;
}
/* Domain Field */
#licensed-product-domain-field {
margin-top: 2em;
padding: 1.5em;
background-color: #f8f9fa;
border: 1px solid #e5e5e5;
border-radius: 4px;
}
#licensed-product-domain-field h3 {
margin-top: 0;
margin-bottom: 1em;
font-size: 1.1em;
}
#licensed-product-domain-field .description {
display: block;
margin-top: 0.5em;
font-size: 0.9em;
color: #666;
}
/* Legacy License Table (kept for backwards compatibility) */
.woocommerce-licenses-table { .woocommerce-licenses-table {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: collapse;
@@ -64,30 +263,33 @@
font-size: 0.9em; font-size: 0.9em;
} }
/* Domain Field */
#licensed-product-domain-field {
margin-top: 2em;
padding: 1.5em;
background-color: #f8f9fa;
border: 1px solid #e5e5e5;
border-radius: 4px;
}
#licensed-product-domain-field h3 {
margin-top: 0;
margin-bottom: 1em;
font-size: 1.1em;
}
#licensed-product-domain-field .description {
display: block;
margin-top: 0.5em;
font-size: 0.9em;
color: #666;
}
/* Responsive */ /* Responsive */
@media screen and (max-width: 768px) { @media screen and (max-width: 768px) {
.license-header {
flex-direction: column;
align-items: flex-start;
gap: 0.5em;
}
.license-key-row {
flex-direction: column;
align-items: flex-start;
}
.license-info-row {
flex-direction: column;
gap: 0.5em;
}
.download-list li {
flex-wrap: wrap;
}
.download-date {
margin-left: 0;
width: 100%;
}
.woocommerce-licenses-table, .woocommerce-licenses-table,
.woocommerce-licenses-table thead, .woocommerce-licenses-table thead,
.woocommerce-licenses-table tbody, .woocommerce-licenses-table tbody,

90
assets/js/frontend.js Normal file
View File

@@ -0,0 +1,90 @@
/**
* WC Licensed Product - Frontend Scripts
*
* @package Jeremias\WcLicensedProduct
*/
(function($) {
'use strict';
var WCLicensedProductFrontend = {
init: function() {
this.bindEvents();
},
bindEvents: function() {
$(document).on('click', '.copy-license-btn', this.copyLicenseKey);
},
/**
* Copy license key to clipboard
*/
copyLicenseKey: function(e) {
e.preventDefault();
var $btn = $(this);
var licenseKey = $btn.data('license-key');
if (!licenseKey) {
return;
}
// Use modern clipboard API if available
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(licenseKey)
.then(function() {
WCLicensedProductFrontend.showCopyFeedback($btn, true);
})
.catch(function() {
WCLicensedProductFrontend.fallbackCopy(licenseKey, $btn);
});
} else {
WCLicensedProductFrontend.fallbackCopy(licenseKey, $btn);
}
},
/**
* Fallback copy method for older browsers
*/
fallbackCopy: function(text, $btn) {
var $temp = $('<textarea>');
$('body').append($temp);
$temp.val(text).select();
try {
var success = document.execCommand('copy');
WCLicensedProductFrontend.showCopyFeedback($btn, success);
} catch (err) {
WCLicensedProductFrontend.showCopyFeedback($btn, false);
}
$temp.remove();
},
/**
* Show feedback after copy attempt
*/
showCopyFeedback: function($btn, success) {
var message = success
? wcLicensedProduct.strings.copied
: wcLicensedProduct.strings.copyFailed;
var $feedback = $('<span class="copy-feedback"></span>')
.text(message)
.addClass(success ? 'success' : 'error');
$btn.after($feedback);
setTimeout(function() {
$feedback.fadeOut(300, function() {
$(this).remove();
});
}, 1500);
}
};
$(document).ready(function() {
WCLicensedProductFrontend.init();
});
})(jQuery);

View File

@@ -8,6 +8,8 @@
'use strict'; 'use strict';
var WCLicensedProductVersions = { var WCLicensedProductVersions = {
mediaFrame: null,
init: function() { init: function() {
this.bindEvents(); this.bindEvents();
}, },
@@ -16,6 +18,113 @@
$('#add-version-btn').on('click', this.addVersion); $('#add-version-btn').on('click', this.addVersion);
$(document).on('click', '.delete-version-btn', this.deleteVersion); $(document).on('click', '.delete-version-btn', this.deleteVersion);
$(document).on('click', '.toggle-version-btn', this.toggleVersion); $(document).on('click', '.toggle-version-btn', this.toggleVersion);
// Media uploader events
$('#upload-version-file-btn').on('click', this.openMediaUploader.bind(this));
$('#remove-version-file-btn').on('click', this.removeSelectedFile);
// Listen for product type changes
$('#product-type').on('change', this.onProductTypeChange);
// Initial check for product type (handles page load for new products)
this.onProductTypeChange();
},
onProductTypeChange: function() {
var productType = $('#product-type').val();
var $metaBox = $('#wc_licensed_product_versions');
if (productType === 'licensed') {
$metaBox.show();
} else {
$metaBox.hide();
}
},
/**
* Open WordPress media uploader
*/
openMediaUploader: function(e) {
e.preventDefault();
var self = this;
// If frame already exists, open it
if (this.mediaFrame) {
this.mediaFrame.open();
return;
}
// Create media frame
this.mediaFrame = wp.media({
title: wcLicensedProductVersions.strings.selectFile,
button: {
text: wcLicensedProductVersions.strings.useThisFile
},
multiple: false,
library: {
type: ['application/zip', 'application/x-zip-compressed', 'application/octet-stream']
}
});
// When file is selected
this.mediaFrame.on('select', function() {
var attachment = self.mediaFrame.state().get('selection').first().toJSON();
// Set attachment ID
$('#new_attachment_id').val(attachment.id);
// Show filename
$('#selected_file_name').text(attachment.filename);
$('#remove-version-file-btn').show();
// Try to extract version from filename
var extractedVersion = self.extractVersionFromFilename(attachment.filename);
if (extractedVersion && !$('#new_version').val().trim()) {
$('#new_version').val(extractedVersion);
}
// Clear external URL when file is selected
$('#new_download_url').val('');
});
this.mediaFrame.open();
},
/**
* Remove selected file
*/
removeSelectedFile: function(e) {
e.preventDefault();
$('#new_attachment_id').val('');
$('#selected_file_name').text('');
$('#remove-version-file-btn').hide();
},
/**
* Extract version from filename
* Supports patterns like: plugin-v1.2.3.zip, plugin-1.2.3.zip, v1.2.3.zip
*/
extractVersionFromFilename: function(filename) {
// Remove extension
var basename = filename.replace(/\.[^/.]+$/, '');
// Try various patterns
var patterns = [
/[_-]v?(\d+\.\d+\.\d+)$/i, // ends with -v1.2.3 or -1.2.3
/[_-]v?(\d+\.\d+\.\d+)[_-]/i, // contains -v1.2.3- or -1.2.3-
/^v?(\d+\.\d+\.\d+)$/i // just version number
];
for (var i = 0; i < patterns.length; i++) {
var match = basename.match(patterns[i]);
if (match) {
return match[1];
}
}
return null;
}, },
addVersion: function(e) { addVersion: function(e) {
@@ -27,6 +136,7 @@
var version = $('#new_version').val().trim(); var version = $('#new_version').val().trim();
var downloadUrl = $('#new_download_url').val().trim(); var downloadUrl = $('#new_download_url').val().trim();
var releaseNotes = $('#new_release_notes').val().trim(); var releaseNotes = $('#new_release_notes').val().trim();
var attachmentId = $('#new_attachment_id').val();
// Validate version // Validate version
if (!version) { if (!version) {
@@ -51,7 +161,8 @@
product_id: productId, product_id: productId,
version: version, version: version,
download_url: downloadUrl, download_url: downloadUrl,
release_notes: releaseNotes release_notes: releaseNotes,
attachment_id: attachmentId
}, },
success: function(response) { success: function(response) {
if (response.success) { if (response.success) {
@@ -65,6 +176,9 @@
$('#new_version').val(''); $('#new_version').val('');
$('#new_download_url').val(''); $('#new_download_url').val('');
$('#new_release_notes').val(''); $('#new_release_notes').val('');
$('#new_attachment_id').val('');
$('#selected_file_name').text('');
$('#remove-version-file-btn').hide();
} else { } else {
alert(response.data.message || wcLicensedProductVersions.strings.error); alert(response.data.message || wcLicensedProductVersions.strings.error);
} }

View File

@@ -61,12 +61,6 @@ final class VersionAdminController
*/ */
public function renderVersionsMetaBox(\WP_Post $post): void public function renderVersionsMetaBox(\WP_Post $post): void
{ {
$product = wc_get_product($post->ID);
if (!$product || !$product->is_type('licensed')) {
echo '<p>' . esc_html__('This meta box is only available for Licensed Products.', 'wc-licensed-product') . '</p>';
return;
}
$versions = $this->versionManager->getVersionsByProduct($post->ID); $versions = $this->versionManager->getVersionsByProduct($post->ID);
wp_nonce_field('wc_licensed_product_versions', 'wc_licensed_product_versions_nonce'); wp_nonce_field('wc_licensed_product_versions', 'wc_licensed_product_versions_nonce');
?> ?>
@@ -82,10 +76,24 @@ final class VersionAdminController
</td> </td>
</tr> </tr>
<tr> <tr>
<th><label for="new_download_url"><?php esc_html_e('Download URL', 'wc-licensed-product'); ?></label></th> <th><label for="new_attachment_id"><?php esc_html_e('Download File', 'wc-licensed-product'); ?></label></th>
<td>
<input type="hidden" id="new_attachment_id" name="new_attachment_id" value="" />
<span id="selected_file_name" class="selected-file-name"></span>
<button type="button" class="button" id="upload-version-file-btn">
<?php esc_html_e('Select File', 'wc-licensed-product'); ?>
</button>
<button type="button" class="button" id="remove-version-file-btn" style="display: none;">
<?php esc_html_e('Remove', 'wc-licensed-product'); ?>
</button>
<p class="description"><?php esc_html_e('Upload or select a file from the media library. Version will be auto-detected from filename (e.g., plugin-v1.2.3.zip).', 'wc-licensed-product'); ?></p>
</td>
</tr>
<tr>
<th><label for="new_download_url"><?php esc_html_e('Or External URL', 'wc-licensed-product'); ?></label></th>
<td> <td>
<input type="url" id="new_download_url" name="new_download_url" class="large-text" placeholder="https://" /> <input type="url" id="new_download_url" name="new_download_url" class="large-text" placeholder="https://" />
<p class="description"><?php esc_html_e('URL to the downloadable file for this version.', 'wc-licensed-product'); ?></p> <p class="description"><?php esc_html_e('Alternative: Enter an external download URL instead of uploading a file.', 'wc-licensed-product'); ?></p>
</td> </td>
</tr> </tr>
<tr> <tr>
@@ -110,7 +118,7 @@ final class VersionAdminController
<thead> <thead>
<tr> <tr>
<th><?php esc_html_e('Version', 'wc-licensed-product'); ?></th> <th><?php esc_html_e('Version', 'wc-licensed-product'); ?></th>
<th><?php esc_html_e('Download URL', 'wc-licensed-product'); ?></th> <th><?php esc_html_e('Download File', 'wc-licensed-product'); ?></th>
<th><?php esc_html_e('Release Notes', 'wc-licensed-product'); ?></th> <th><?php esc_html_e('Release Notes', 'wc-licensed-product'); ?></th>
<th><?php esc_html_e('Status', 'wc-licensed-product'); ?></th> <th><?php esc_html_e('Status', 'wc-licensed-product'); ?></th>
<th><?php esc_html_e('Released', 'wc-licensed-product'); ?></th> <th><?php esc_html_e('Released', 'wc-licensed-product'); ?></th>
@@ -127,12 +135,19 @@ final class VersionAdminController
<tr data-version-id="<?php echo esc_attr($version->getId()); ?>"> <tr data-version-id="<?php echo esc_attr($version->getId()); ?>">
<td><strong><?php echo esc_html($version->getVersion()); ?></strong></td> <td><strong><?php echo esc_html($version->getVersion()); ?></strong></td>
<td> <td>
<?php if ($version->getDownloadUrl()): ?> <?php
<a href="<?php echo esc_url($version->getDownloadUrl()); ?>" target="_blank"> $effectiveUrl = $version->getEffectiveDownloadUrl();
<?php echo esc_html(wp_basename($version->getDownloadUrl())); ?> $filename = $version->getDownloadFilename();
if ($effectiveUrl):
?>
<a href="<?php echo esc_url($effectiveUrl); ?>" target="_blank">
<?php echo esc_html($filename ?: wp_basename($effectiveUrl)); ?>
</a> </a>
<?php if ($version->getAttachmentId()): ?>
<span class="dashicons dashicons-media-archive" title="<?php esc_attr_e('Uploaded file', 'wc-licensed-product'); ?>"></span>
<?php endif; ?>
<?php else: ?> <?php else: ?>
<em><?php esc_html_e('No download URL', 'wc-licensed-product'); ?></em> <em><?php esc_html_e('No download file', 'wc-licensed-product'); ?></em>
<?php endif; ?> <?php endif; ?>
</td> </td>
<td><?php echo esc_html($version->getReleaseNotes() ? wp_trim_words($version->getReleaseNotes(), 10) : '—'); ?></td> <td><?php echo esc_html($version->getReleaseNotes() ? wp_trim_words($version->getReleaseNotes(), 10) : '—'); ?></td>
@@ -173,6 +188,9 @@ final class VersionAdminController
return; return;
} }
// Enqueue WordPress media uploader
wp_enqueue_media();
wp_enqueue_script( wp_enqueue_script(
'wc-licensed-product-versions', 'wc-licensed-product-versions',
WC_LICENSED_PRODUCT_PLUGIN_URL . 'assets/js/versions.js', WC_LICENSED_PRODUCT_PLUGIN_URL . 'assets/js/versions.js',
@@ -189,6 +207,8 @@ final class VersionAdminController
'versionRequired' => __('Please enter a version number.', 'wc-licensed-product'), 'versionRequired' => __('Please enter a version number.', 'wc-licensed-product'),
'versionInvalid' => __('Please enter a valid version number (e.g., 1.0.0).', 'wc-licensed-product'), 'versionInvalid' => __('Please enter a valid version number (e.g., 1.0.0).', 'wc-licensed-product'),
'error' => __('An error occurred. Please try again.', 'wc-licensed-product'), 'error' => __('An error occurred. Please try again.', 'wc-licensed-product'),
'selectFile' => __('Select Download File', 'wc-licensed-product'),
'useThisFile' => __('Use this file', 'wc-licensed-product'),
], ],
]); ]);
@@ -215,6 +235,7 @@ final class VersionAdminController
$version = sanitize_text_field($_POST['version'] ?? ''); $version = sanitize_text_field($_POST['version'] ?? '');
$downloadUrl = esc_url_raw($_POST['download_url'] ?? ''); $downloadUrl = esc_url_raw($_POST['download_url'] ?? '');
$releaseNotes = sanitize_textarea_field($_POST['release_notes'] ?? ''); $releaseNotes = sanitize_textarea_field($_POST['release_notes'] ?? '');
$attachmentId = absint($_POST['attachment_id'] ?? 0);
if (!$productId || !$version) { if (!$productId || !$version) {
wp_send_json_error(['message' => __('Product ID and version are required.', 'wc-licensed-product')]); wp_send_json_error(['message' => __('Product ID and version are required.', 'wc-licensed-product')]);
@@ -234,7 +255,8 @@ final class VersionAdminController
$productId, $productId,
$version, $version,
$releaseNotes ?: null, $releaseNotes ?: null,
$downloadUrl ?: null $downloadUrl ?: null,
$attachmentId ?: null
); );
if (!$newVersion) { if (!$newVersion) {
@@ -317,12 +339,19 @@ final class VersionAdminController
<tr data-version-id="<?php echo esc_attr($version->getId()); ?>"> <tr data-version-id="<?php echo esc_attr($version->getId()); ?>">
<td><strong><?php echo esc_html($version->getVersion()); ?></strong></td> <td><strong><?php echo esc_html($version->getVersion()); ?></strong></td>
<td> <td>
<?php if ($version->getDownloadUrl()): ?> <?php
<a href="<?php echo esc_url($version->getDownloadUrl()); ?>" target="_blank"> $effectiveUrl = $version->getEffectiveDownloadUrl();
<?php echo esc_html(wp_basename($version->getDownloadUrl())); ?> $filename = $version->getDownloadFilename();
if ($effectiveUrl):
?>
<a href="<?php echo esc_url($effectiveUrl); ?>" target="_blank">
<?php echo esc_html($filename ?: wp_basename($effectiveUrl)); ?>
</a> </a>
<?php if ($version->getAttachmentId()): ?>
<span class="dashicons dashicons-media-archive" title="<?php esc_attr_e('Uploaded file', 'wc-licensed-product'); ?>"></span>
<?php endif; ?>
<?php else: ?> <?php else: ?>
<em><?php esc_html_e('No download URL', 'wc-licensed-product'); ?></em> <em><?php esc_html_e('No download file', 'wc-licensed-product'); ?></em>
<?php endif; ?> <?php endif; ?>
</td> </td>
<td><?php echo esc_html($version->getReleaseNotes() ? wp_trim_words($version->getReleaseNotes(), 10) : '—'); ?></td> <td><?php echo esc_html($version->getReleaseNotes() ? wp_trim_words($version->getReleaseNotes(), 10) : '—'); ?></td>

View File

@@ -10,6 +10,7 @@ declare(strict_types=1);
namespace Jeremias\WcLicensedProduct\Frontend; namespace Jeremias\WcLicensedProduct\Frontend;
use Jeremias\WcLicensedProduct\License\LicenseManager; use Jeremias\WcLicensedProduct\License\LicenseManager;
use Jeremias\WcLicensedProduct\Product\VersionManager;
use Twig\Environment; use Twig\Environment;
/** /**
@@ -19,11 +20,19 @@ final class AccountController
{ {
private Environment $twig; private Environment $twig;
private LicenseManager $licenseManager; private LicenseManager $licenseManager;
private VersionManager $versionManager;
private DownloadController $downloadController;
public function __construct(Environment $twig, LicenseManager $licenseManager) public function __construct(
{ Environment $twig,
LicenseManager $licenseManager,
VersionManager $versionManager,
DownloadController $downloadController
) {
$this->twig = $twig; $this->twig = $twig;
$this->licenseManager = $licenseManager; $this->licenseManager = $licenseManager;
$this->versionManager = $versionManager;
$this->downloadController = $downloadController;
$this->registerHooks(); $this->registerHooks();
} }
@@ -41,8 +50,8 @@ final class AccountController
// Add licenses endpoint content // Add licenses endpoint content
add_action('woocommerce_account_licenses_endpoint', [$this, 'displayLicensesContent']); add_action('woocommerce_account_licenses_endpoint', [$this, 'displayLicensesContent']);
// Enqueue frontend styles // Enqueue frontend styles and scripts
add_action('wp_enqueue_scripts', [$this, 'enqueueStyles']); add_action('wp_enqueue_scripts', [$this, 'enqueueAssets']);
} }
/** /**
@@ -83,18 +92,40 @@ final class AccountController
$licenses = $this->licenseManager->getLicensesByCustomer($customerId); $licenses = $this->licenseManager->getLicensesByCustomer($customerId);
// Enrich licenses with product data // Enrich licenses with product data and downloads
$enrichedLicenses = []; $enrichedLicenses = [];
foreach ($licenses as $license) { foreach ($licenses as $license) {
$product = wc_get_product($license->getProductId()); $product = wc_get_product($license->getProductId());
$order = wc_get_order($license->getOrderId()); $order = wc_get_order($license->getOrderId());
// Get available downloads for this license
$downloads = [];
if ($license->getStatus() === 'active') {
$versions = $this->versionManager->getVersionsByProduct($license->getProductId());
foreach ($versions as $version) {
if ($version->isActive() && ($version->getAttachmentId() || $version->getDownloadUrl())) {
$downloads[] = [
'version' => $version->getVersion(),
'version_id' => $version->getId(),
'filename' => $version->getDownloadFilename(),
'download_url' => $this->downloadController->generateDownloadUrl(
$license->getId(),
$version->getId()
),
'release_notes' => $version->getReleaseNotes(),
'released_at' => $version->getReleasedAt()->format(get_option('date_format')),
];
}
}
}
$enrichedLicenses[] = [ $enrichedLicenses[] = [
'license' => $license, 'license' => $license,
'product_name' => $product ? $product->get_name() : __('Unknown Product', 'wc-licensed-product'), 'product_name' => $product ? $product->get_name() : __('Unknown Product', 'wc-licensed-product'),
'product_url' => $product ? $product->get_permalink() : '', 'product_url' => $product ? $product->get_permalink() : '',
'order_number' => $order ? $order->get_order_number() : '', 'order_number' => $order ? $order->get_order_number() : '',
'order_url' => $order ? $order->get_view_order_url() : '', 'order_url' => $order ? $order->get_view_order_url() : '',
'downloads' => $downloads,
]; ];
} }
@@ -120,23 +151,11 @@ final class AccountController
} }
?> ?>
<table class="woocommerce-licenses-table shop_table shop_table_responsive"> <div class="woocommerce-licenses">
<thead>
<tr>
<th><?php esc_html_e('License Key', 'wc-licensed-product'); ?></th>
<th><?php esc_html_e('Product', 'wc-licensed-product'); ?></th>
<th><?php esc_html_e('Domain', 'wc-licensed-product'); ?></th>
<th><?php esc_html_e('Status', 'wc-licensed-product'); ?></th>
<th><?php esc_html_e('Expires', 'wc-licensed-product'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($enrichedLicenses as $item): ?> <?php foreach ($enrichedLicenses as $item): ?>
<tr> <div class="license-card">
<td data-title="<?php esc_attr_e('License Key', 'wc-licensed-product'); ?>"> <div class="license-header">
<code><?php echo esc_html($item['license']->getLicenseKey()); ?></code> <h3>
</td>
<td data-title="<?php esc_attr_e('Product', 'wc-licensed-product'); ?>">
<?php if ($item['product_url']): ?> <?php if ($item['product_url']): ?>
<a href="<?php echo esc_url($item['product_url']); ?>"> <a href="<?php echo esc_url($item['product_url']); ?>">
<?php echo esc_html($item['product_name']); ?> <?php echo esc_html($item['product_name']); ?>
@@ -144,34 +163,63 @@ final class AccountController
<?php else: ?> <?php else: ?>
<?php echo esc_html($item['product_name']); ?> <?php echo esc_html($item['product_name']); ?>
<?php endif; ?> <?php endif; ?>
</td> </h3>
<td data-title="<?php esc_attr_e('Domain', 'wc-licensed-product'); ?>">
<?php echo esc_html($item['license']->getDomain()); ?>
</td>
<td data-title="<?php esc_attr_e('Status', 'wc-licensed-product'); ?>">
<span class="license-status license-status-<?php echo esc_attr($item['license']->getStatus()); ?>"> <span class="license-status license-status-<?php echo esc_attr($item['license']->getStatus()); ?>">
<?php echo esc_html(ucfirst($item['license']->getStatus())); ?> <?php echo esc_html(ucfirst($item['license']->getStatus())); ?>
</span> </span>
</td> </div>
<td data-title="<?php esc_attr_e('Expires', 'wc-licensed-product'); ?>">
<div class="license-details">
<div class="license-key-row">
<label><?php esc_html_e('License Key:', 'wc-licensed-product'); ?></label>
<code class="license-key" data-license-key="<?php echo esc_attr($item['license']->getLicenseKey()); ?>">
<?php echo esc_html($item['license']->getLicenseKey()); ?>
</code>
<button type="button" class="copy-license-btn" data-license-key="<?php echo esc_attr($item['license']->getLicenseKey()); ?>" title="<?php esc_attr_e('Copy to clipboard', 'wc-licensed-product'); ?>">
<span class="dashicons dashicons-clipboard"></span>
</button>
</div>
<div class="license-info-row">
<span><strong><?php esc_html_e('Domain:', 'wc-licensed-product'); ?></strong> <?php echo esc_html($item['license']->getDomain()); ?></span>
<span><strong><?php esc_html_e('Expires:', 'wc-licensed-product'); ?></strong>
<?php <?php
$expiresAt = $item['license']->getExpiresAt(); $expiresAt = $item['license']->getExpiresAt();
echo $expiresAt echo $expiresAt
? esc_html($expiresAt->format(get_option('date_format'))) ? esc_html($expiresAt->format(get_option('date_format')))
: esc_html__('Never', 'wc-licensed-product'); : esc_html__('Never', 'wc-licensed-product');
?> ?>
</td> </span>
</tr> </div>
</div>
<?php if (!empty($item['downloads'])): ?>
<div class="license-downloads">
<h4><?php esc_html_e('Available Downloads', 'wc-licensed-product'); ?></h4>
<ul class="download-list">
<?php foreach ($item['downloads'] as $download): ?>
<li>
<a href="<?php echo esc_url($download['download_url']); ?>" class="download-link">
<span class="dashicons dashicons-download"></span>
<?php echo esc_html($download['filename'] ?: sprintf(__('Version %s', 'wc-licensed-product'), $download['version'])); ?>
</a>
<span class="download-version">v<?php echo esc_html($download['version']); ?></span>
<span class="download-date"><?php echo esc_html($download['released_at']); ?></span>
</li>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </ul>
</table> </div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php <?php
} }
/** /**
* Enqueue frontend styles * Enqueue frontend styles and scripts
*/ */
public function enqueueStyles(): void public function enqueueAssets(): void
{ {
if (!is_account_page()) { if (!is_account_page()) {
return; return;
@@ -183,5 +231,20 @@ final class AccountController
[], [],
WC_LICENSED_PRODUCT_VERSION WC_LICENSED_PRODUCT_VERSION
); );
wp_enqueue_script(
'wc-licensed-product-frontend',
WC_LICENSED_PRODUCT_PLUGIN_URL . 'assets/js/frontend.js',
['jquery'],
WC_LICENSED_PRODUCT_VERSION,
true
);
wp_localize_script('wc-licensed-product-frontend', 'wcLicensedProduct', [
'strings' => [
'copied' => __('Copied!', 'wc-licensed-product'),
'copyFailed' => __('Copy failed', 'wc-licensed-product'),
],
]);
} }
} }

View File

@@ -0,0 +1,237 @@
<?php
/**
* Download Controller
*
* @package Jeremias\WcLicensedProduct\Frontend
*/
declare(strict_types=1);
namespace Jeremias\WcLicensedProduct\Frontend;
use Jeremias\WcLicensedProduct\License\LicenseManager;
use Jeremias\WcLicensedProduct\Product\VersionManager;
/**
* Handles secure file downloads for licensed customers
*/
final class DownloadController
{
private LicenseManager $licenseManager;
private VersionManager $versionManager;
public function __construct(LicenseManager $licenseManager, VersionManager $versionManager)
{
$this->licenseManager = $licenseManager;
$this->versionManager = $versionManager;
$this->registerHooks();
}
/**
* Register WordPress hooks
*/
private function registerHooks(): void
{
// Add download endpoint
add_action('init', [$this, 'addDownloadEndpoint']);
// Handle download requests
add_action('template_redirect', [$this, 'handleDownloadRequest']);
}
/**
* Add download endpoint
*/
public function addDownloadEndpoint(): void
{
add_rewrite_endpoint('license-download', EP_ROOT | EP_PAGES);
}
/**
* Handle download request
*/
public function handleDownloadRequest(): void
{
global $wp_query;
if (!isset($wp_query->query_vars['license-download'])) {
return;
}
$downloadKey = sanitize_text_field($wp_query->query_vars['license-download']);
if (empty($downloadKey)) {
wp_die(
__('Invalid download link.', 'wc-licensed-product'),
__('Download Error', 'wc-licensed-product'),
['response' => 403]
);
}
// Parse download key: format is "license_id-version_id-hash"
$parts = explode('-', $downloadKey);
if (count($parts) < 3) {
wp_die(
__('Invalid download link format.', 'wc-licensed-product'),
__('Download Error', 'wc-licensed-product'),
['response' => 403]
);
}
$licenseId = absint($parts[0]);
$versionId = absint($parts[1]);
$hash = $parts[2];
// Verify hash
$expectedHash = $this->generateDownloadHash($licenseId, $versionId);
if (!hash_equals($expectedHash, $hash)) {
wp_die(
__('Invalid download link.', 'wc-licensed-product'),
__('Download Error', 'wc-licensed-product'),
['response' => 403]
);
}
// Check user authentication
if (!is_user_logged_in()) {
wp_redirect(wp_login_url(home_url('license-download/' . $downloadKey)));
exit;
}
// Get license
$license = $this->licenseManager->getLicenseById($licenseId);
if (!$license) {
wp_die(
__('License not found.', 'wc-licensed-product'),
__('Download Error', 'wc-licensed-product'),
['response' => 404]
);
}
// Verify user owns the license
$currentUserId = get_current_user_id();
if ($license->getCustomerId() !== $currentUserId) {
wp_die(
__('You do not have permission to download this file.', 'wc-licensed-product'),
__('Download Error', 'wc-licensed-product'),
['response' => 403]
);
}
// Check license status
if ($license->getStatus() !== 'active') {
wp_die(
__('Your license is not active. Please contact support.', 'wc-licensed-product'),
__('Download Error', 'wc-licensed-product'),
['response' => 403]
);
}
// Get version
$version = $this->versionManager->getVersionById($versionId);
if (!$version) {
wp_die(
__('Version not found.', 'wc-licensed-product'),
__('Download Error', 'wc-licensed-product'),
['response' => 404]
);
}
// Verify version belongs to licensed product
if ($version->getProductId() !== $license->getProductId()) {
wp_die(
__('Version does not match your licensed product.', 'wc-licensed-product'),
__('Download Error', 'wc-licensed-product'),
['response' => 403]
);
}
// Check if version is active
if (!$version->isActive()) {
wp_die(
__('This version is no longer available for download.', 'wc-licensed-product'),
__('Download Error', 'wc-licensed-product'),
['response' => 403]
);
}
// Get download file
$attachmentId = $version->getAttachmentId();
$downloadUrl = $version->getDownloadUrl();
if ($attachmentId) {
$this->serveAttachment($attachmentId, $version->getVersion());
} elseif ($downloadUrl) {
// Redirect to external URL
wp_redirect($downloadUrl);
exit;
} else {
wp_die(
__('No download file available for this version.', 'wc-licensed-product'),
__('Download Error', 'wc-licensed-product'),
['response' => 404]
);
}
}
/**
* Serve attachment file for download
*/
private function serveAttachment(int $attachmentId, string $version): void
{
$filePath = get_attached_file($attachmentId);
if (!$filePath || !file_exists($filePath)) {
wp_die(
__('Download file not found.', 'wc-licensed-product'),
__('Download Error', 'wc-licensed-product'),
['response' => 404]
);
}
$filename = wp_basename($filePath);
$mimeType = mime_content_type($filePath) ?: 'application/octet-stream';
$fileSize = filesize($filePath);
// Prevent caching
nocache_headers();
// Set headers for download
header('Content-Type: ' . $mimeType);
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Length: ' . $fileSize);
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
header('Pragma: public');
// Clear output buffer
if (ob_get_level()) {
ob_end_clean();
}
// Read file and output
readfile($filePath);
exit;
}
/**
* Generate download hash for security
*/
public function generateDownloadHash(int $licenseId, int $versionId): string
{
$data = $licenseId . '-' . $versionId . '-' . wp_salt('auth');
return substr(hash('sha256', $data), 0, 16);
}
/**
* Generate download URL for a license and version
*/
public function generateDownloadUrl(int $licenseId, int $versionId): string
{
$hash = $this->generateDownloadHash($licenseId, $versionId);
$downloadKey = $licenseId . '-' . $versionId . '-' . $hash;
return home_url('license-download/' . $downloadKey);
}
}

View File

@@ -92,6 +92,7 @@ final class Installer
patch_version INT UNSIGNED NOT NULL, patch_version INT UNSIGNED NOT NULL,
release_notes TEXT DEFAULT NULL, release_notes TEXT DEFAULT NULL,
download_url VARCHAR(512) DEFAULT NULL, download_url VARCHAR(512) DEFAULT NULL,
attachment_id BIGINT UNSIGNED DEFAULT NULL,
is_active TINYINT(1) NOT NULL DEFAULT 1, is_active TINYINT(1) NOT NULL DEFAULT 1,
released_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, released_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,

View File

@@ -15,6 +15,7 @@ use Jeremias\WcLicensedProduct\Api\RestApiController;
use Jeremias\WcLicensedProduct\Checkout\CheckoutController; use Jeremias\WcLicensedProduct\Checkout\CheckoutController;
use Jeremias\WcLicensedProduct\Email\LicenseEmailController; use Jeremias\WcLicensedProduct\Email\LicenseEmailController;
use Jeremias\WcLicensedProduct\Frontend\AccountController; use Jeremias\WcLicensedProduct\Frontend\AccountController;
use Jeremias\WcLicensedProduct\Frontend\DownloadController;
use Jeremias\WcLicensedProduct\License\LicenseManager; use Jeremias\WcLicensedProduct\License\LicenseManager;
use Jeremias\WcLicensedProduct\Product\LicensedProductType; use Jeremias\WcLicensedProduct\Product\LicensedProductType;
use Jeremias\WcLicensedProduct\Product\VersionManager; use Jeremias\WcLicensedProduct\Product\VersionManager;
@@ -46,6 +47,11 @@ final class Plugin
*/ */
private VersionManager $versionManager; private VersionManager $versionManager;
/**
* Download controller
*/
private DownloadController $downloadController;
/** /**
* Get singleton instance * Get singleton instance
*/ */
@@ -103,7 +109,8 @@ final class Plugin
// Initialize controllers // Initialize controllers
new LicensedProductType(); new LicensedProductType();
new CheckoutController($this->licenseManager); new CheckoutController($this->licenseManager);
new AccountController($this->twig, $this->licenseManager); $this->downloadController = new DownloadController($this->licenseManager, $this->versionManager);
new AccountController($this->twig, $this->licenseManager, $this->versionManager, $this->downloadController);
new RestApiController($this->licenseManager); new RestApiController($this->licenseManager);
new LicenseEmailController($this->licenseManager); new LicenseEmailController($this->licenseManager);

View File

@@ -22,6 +22,7 @@ class ProductVersion
private int $patchVersion; private int $patchVersion;
private ?string $releaseNotes; private ?string $releaseNotes;
private ?string $downloadUrl; private ?string $downloadUrl;
private ?int $attachmentId;
private bool $isActive; private bool $isActive;
private \DateTimeInterface $releasedAt; private \DateTimeInterface $releasedAt;
private \DateTimeInterface $createdAt; private \DateTimeInterface $createdAt;
@@ -40,6 +41,7 @@ class ProductVersion
$version->patchVersion = (int) $data['patch_version']; $version->patchVersion = (int) $data['patch_version'];
$version->releaseNotes = $data['release_notes'] ?: null; $version->releaseNotes = $data['release_notes'] ?: null;
$version->downloadUrl = $data['download_url'] ?: null; $version->downloadUrl = $data['download_url'] ?: null;
$version->attachmentId = !empty($data['attachment_id']) ? (int) $data['attachment_id'] : null;
$version->isActive = (bool) $data['is_active']; $version->isActive = (bool) $data['is_active'];
$version->releasedAt = new \DateTimeImmutable($data['released_at']); $version->releasedAt = new \DateTimeImmutable($data['released_at']);
$version->createdAt = new \DateTimeImmutable($data['created_at']); $version->createdAt = new \DateTimeImmutable($data['created_at']);
@@ -60,6 +62,36 @@ class ProductVersion
]; ];
} }
/**
* Extract version from filename
*
* Supports patterns like:
* - product-name-v1.2.3.zip
* - product-name-1.2.3.zip
* - product_v1.2.3.zip
* - v1.2.3.zip
*/
public static function extractVersionFromFilename(string $filename): ?string
{
// Remove extension
$basename = pathinfo($filename, PATHINFO_FILENAME);
// Try various patterns
$patterns = [
'/[_-]v?(\d+\.\d+\.\d+)$/i', // ends with -v1.2.3 or -1.2.3
'/[_-]v?(\d+\.\d+\.\d+)[_-]/i', // contains -v1.2.3- or -1.2.3-
'/^v?(\d+\.\d+\.\d+)$/i', // just version number
];
foreach ($patterns as $pattern) {
if (preg_match($pattern, $basename, $matches)) {
return $matches[1];
}
}
return null;
}
public function getId(): int public function getId(): int
{ {
return $this->id; return $this->id;
@@ -100,6 +132,36 @@ class ProductVersion
return $this->downloadUrl; return $this->downloadUrl;
} }
public function getAttachmentId(): ?int
{
return $this->attachmentId;
}
/**
* Get the effective download URL (from attachment or direct URL)
*/
public function getEffectiveDownloadUrl(): ?string
{
if ($this->attachmentId) {
return wp_get_attachment_url($this->attachmentId) ?: null;
}
return $this->downloadUrl;
}
/**
* Get the filename for download
*/
public function getDownloadFilename(): ?string
{
if ($this->attachmentId) {
return wp_basename(get_attached_file($this->attachmentId) ?: '');
}
if ($this->downloadUrl) {
return wp_basename($this->downloadUrl);
}
return null;
}
public function isActive(): bool public function isActive(): bool
{ {
return $this->isActive; return $this->isActive;
@@ -129,6 +191,7 @@ class ProductVersion
'patch_version' => $this->patchVersion, 'patch_version' => $this->patchVersion,
'release_notes' => $this->releaseNotes, 'release_notes' => $this->releaseNotes,
'download_url' => $this->downloadUrl, 'download_url' => $this->downloadUrl,
'attachment_id' => $this->attachmentId,
'is_active' => $this->isActive, 'is_active' => $this->isActive,
'released_at' => $this->releasedAt->format('Y-m-d H:i:s'), 'released_at' => $this->releasedAt->format('Y-m-d H:i:s'),
'created_at' => $this->createdAt->format('Y-m-d H:i:s'), 'created_at' => $this->createdAt->format('Y-m-d H:i:s'),

View File

@@ -97,7 +97,8 @@ class VersionManager
int $productId, int $productId,
string $version, string $version,
?string $releaseNotes = null, ?string $releaseNotes = null,
?string $downloadUrl = null ?string $downloadUrl = null,
?int $attachmentId = null
): ?ProductVersion { ): ?ProductVersion {
global $wpdb; global $wpdb;
@@ -114,9 +115,10 @@ class VersionManager
'patch_version' => $parsed['patch'], 'patch_version' => $parsed['patch'],
'release_notes' => $releaseNotes, 'release_notes' => $releaseNotes,
'download_url' => $downloadUrl, 'download_url' => $downloadUrl,
'attachment_id' => $attachmentId,
'is_active' => 1, 'is_active' => 1,
], ],
['%d', '%s', '%d', '%d', '%d', '%s', '%s', '%d'] ['%d', '%s', '%d', '%d', '%d', '%s', '%s', '%d', '%d']
); );
if ($result === false) { if ($result === false) {
@@ -133,7 +135,8 @@ class VersionManager
int $versionId, int $versionId,
?string $releaseNotes = null, ?string $releaseNotes = null,
?string $downloadUrl = null, ?string $downloadUrl = null,
?bool $isActive = null ?bool $isActive = null,
?int $attachmentId = null
): bool { ): bool {
global $wpdb; global $wpdb;
@@ -155,6 +158,11 @@ class VersionManager
$formats[] = '%d'; $formats[] = '%d';
} }
if ($attachmentId !== null) {
$data['attachment_id'] = $attachmentId > 0 ? $attachmentId : null;
$formats[] = $attachmentId > 0 ? '%d' : null;
}
if (empty($data)) { if (empty($data)) {
return true; return true;
} }

View File

@@ -1,46 +1,63 @@
{% if not has_licenses %} {% if not has_licenses %}
<p>{{ __('You have no licenses yet.') }}</p> <p>{{ __('You have no licenses yet.') }}</p>
{% else %} {% else %}
<table class="woocommerce-licenses-table shop_table shop_table_responsive"> <div class="woocommerce-licenses">
<thead>
<tr>
<th>{{ __('License Key') }}</th>
<th>{{ __('Product') }}</th>
<th>{{ __('Domain') }}</th>
<th>{{ __('Status') }}</th>
<th>{{ __('Expires') }}</th>
</tr>
</thead>
<tbody>
{% for item in licenses %} {% for item in licenses %}
<tr> <div class="license-card">
<td data-title="{{ __('License Key') }}"> <div class="license-header">
<code>{{ item.license.licenseKey }}</code> <h3>
</td>
<td data-title="{{ __('Product') }}">
{% if item.product_url %} {% if item.product_url %}
<a href="{{ esc_url(item.product_url) }}">{{ esc_html(item.product_name) }}</a> <a href="{{ esc_url(item.product_url) }}">{{ esc_html(item.product_name) }}</a>
{% else %} {% else %}
{{ esc_html(item.product_name) }} {{ esc_html(item.product_name) }}
{% endif %} {% endif %}
</td> </h3>
<td data-title="{{ __('Domain') }}">
{{ esc_html(item.license.domain) }}
</td>
<td data-title="{{ __('Status') }}">
<span class="license-status license-status-{{ item.license.status }}"> <span class="license-status license-status-{{ item.license.status }}">
{{ item.license.status|capitalize }} {{ item.license.status|capitalize }}
</span> </span>
</td> </div>
<td data-title="{{ __('Expires') }}">
<div class="license-details">
<div class="license-key-row">
<label>{{ __('License Key:') }}</label>
<code class="license-key" data-license-key="{{ esc_attr(item.license.licenseKey) }}">
{{ esc_html(item.license.licenseKey) }}
</code>
<button type="button" class="copy-license-btn" data-license-key="{{ esc_attr(item.license.licenseKey) }}" title="{{ __('Copy to clipboard') }}">
<span class="dashicons dashicons-clipboard"></span>
</button>
</div>
<div class="license-info-row">
<span><strong>{{ __('Domain:') }}</strong> {{ esc_html(item.license.domain) }}</span>
<span><strong>{{ __('Expires:') }}</strong>
{% if item.license.expiresAt %} {% if item.license.expiresAt %}
{{ item.license.expiresAt|date('Y-m-d') }} {{ item.license.expiresAt|date('Y-m-d') }}
{% else %} {% else %}
{{ __('Never') }} {{ __('Never') }}
{% endif %} {% endif %}
</td> </span>
</tr> </div>
</div>
{% if item.downloads is defined and item.downloads is not empty %}
<div class="license-downloads">
<h4>{{ __('Available Downloads') }}</h4>
<ul class="download-list">
{% for download in item.downloads %}
<li>
<a href="{{ esc_url(download.download_url) }}" class="download-link">
<span class="dashicons dashicons-download"></span>
{{ esc_html(download.filename ?: 'Version ' ~ download.version) }}
</a>
<span class="download-version">v{{ esc_html(download.version) }}</span>
<span class="download-date">{{ esc_html(download.released_at) }}</span>
</li>
{% endfor %} {% endfor %}
</tbody> </ul>
</table> </div>
{% endif %}
</div>
{% endfor %}
</div>
{% endif %} {% endif %}

View File

@@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Licensed Product * Plugin Name: WooCommerce Licensed Product
* Plugin URI: https://src.bundespruefstelle.ch/magdev/wc-licensed-product * Plugin URI: https://src.bundespruefstelle.ch/magdev/wc-licensed-product
* Description: WooCommerce plugin to sell software products using license keys with domain-based validation. * Description: WooCommerce plugin to sell software products using license keys with domain-based validation.
* Version: 0.0.2 * Version: 0.0.3
* Author: Marco Graetsch * Author: Marco Graetsch
* Author URI: https://src.bundespruefstelle.ch/magdev * Author URI: https://src.bundespruefstelle.ch/magdev
* License: GPL-2.0-or-later * License: GPL-2.0-or-later
@@ -28,7 +28,7 @@ if (!defined('ABSPATH')) {
} }
// Plugin constants // Plugin constants
define('WC_LICENSED_PRODUCT_VERSION', '0.0.2'); define('WC_LICENSED_PRODUCT_VERSION', '0.0.3');
define('WC_LICENSED_PRODUCT_PLUGIN_FILE', __FILE__); define('WC_LICENSED_PRODUCT_PLUGIN_FILE', __FILE__);
define('WC_LICENSED_PRODUCT_PLUGIN_DIR', plugin_dir_path(__FILE__)); define('WC_LICENSED_PRODUCT_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('WC_LICENSED_PRODUCT_PLUGIN_URL', plugin_dir_url(__FILE__)); define('WC_LICENSED_PRODUCT_PLUGIN_URL', plugin_dir_url(__FILE__));