21 Commits

Author SHA1 Message Date
5badaa18fd Merge branch 'main' of 192.168.1.206:roberto/siti-ai-product-content-generator
All checks were successful
Build & Release Plugin / release (push) Successful in 8s
2026-02-06 19:25:12 +00:00
9776c2a8fa chore: fix PHP opening tag formatting in groq-ai-product-text.php 2026-02-06 19:25:08 +00:00
actions-bot
e02d29c49e chore: update manifest.json 2026-02-06 18:47:29 +00:00
5ed94f79d3 chore: bump version to 1.10.0 and enhance model selection functionality
Some checks failed
Build & Release Plugin / release (push) Failing after 10s
2026-02-06 18:47:21 +00:00
actions-bot
ee1873568d chore: update manifest.json 2026-02-01 15:44:21 +00:00
cf0269f421 chore: bump version to 1.9.9
All checks were successful
Build & Release Plugin / release (push) Successful in 10s
2026-02-01 15:44:14 +00:00
a352c53139 chore: add release workflow for plugin build and deployment 2026-02-01 15:43:42 +00:00
github-actions[bot]
b33d92a80e chore: update manifest.json 2026-02-01 04:46:37 +00:00
2a36fa7e31 chore: bump version to 1.9.8
All checks were successful
Build & Release Plugin / release (push) Successful in 14s
2026-02-01 04:46:27 +00:00
github-actions[bot]
4b05d67a82 chore: update manifest.json 2026-02-01 04:37:32 +00:00
71424567bf chore: bump version to 1.9.7
All checks were successful
Build & Release Plugin / release (push) Successful in 15s
2026-02-01 04:36:30 +00:00
82da1180da fix: include owner and repository in license verification request
All checks were successful
Build & Release Plugin / release (push) Successful in 6s
2026-02-01 04:36:06 +00:00
2c749eebd5 fix: enhance license validation logic in SitiWebUpdater2
All checks were successful
Build & Release Plugin / release (push) Successful in 5s
2026-02-01 04:10:01 +00:00
github-actions[bot]
04a0c8be37 chore: update manifest.json 2026-02-01 04:02:03 +00:00
03727b9828 chore: bump version to 1.9.6
All checks were successful
Build & Release Plugin / release (push) Successful in 16s
2026-02-01 04:01:54 +00:00
github-actions[bot]
987139bca7 chore: update manifest.json 2026-02-01 03:59:23 +00:00
773db7407c chore: bump version to 1.9.5
Some checks failed
Build & Release Plugin / release (push) Failing after 9s
2026-02-01 03:59:14 +00:00
github-actions[bot]
a4da6e3e00 chore: update manifest.json 2026-02-01 03:55:48 +00:00
ec08c79aab feat: update version to 1.9.4 and enhance license validation handling
All checks were successful
Build & Release Plugin / release (push) Successful in 20s
2026-02-01 03:55:36 +00:00
4a789363c5 feat: enhance SitiWebUpdater2 with global license management and automatic updates
All checks were successful
Build & Release Plugin / release (push) Successful in 12s
2026-02-01 03:46:14 +00:00
github-actions[bot]
c279ea7247 chore: update manifest.json 2026-02-01 03:05:10 +00:00
8 changed files with 521 additions and 412 deletions

View File

@@ -0,0 +1,25 @@
name: Build & Release Plugin
on:
workflow_dispatch:
inputs:
release_notes:
description: "Optionele release-opmerkingen"
required: false
push:
branches: [ main ]
paths:
- 'groq-ai-product-text.php'
- 'includes/**'
- 'assets/**'
- 'languages/**'
jobs:
release:
uses: roberto/ci-workflows/.gitea/workflows/wp-plugin-release.yml@c6393ed47258d6f040ceeed3994b17b7faa3ef23
with:
main_file: groq-ai-product-text.php
slug: siti-ai-product-content-generator
release_body: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.release_notes || '' }}
secrets:
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}

View File

@@ -1,199 +0,0 @@
name: Build & Release Plugin
on:
workflow_dispatch:
inputs:
release_notes:
description: 'Optionele release-opmerkingen'
required: false
push:
branches:
- main
paths:
- 'groq-ai-product-text.php'
- 'includes/**'
- 'assets/**'
- 'README.md'
- '.github/workflows/release.yml'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Determine plugin version
id: meta
run: |
VERSION=$(grep -E "^\s*\*\s*Version:" -m 1 groq-ai-product-text.php | sed -E 's/.*Version:\s*//')
VERSION=$(echo "$VERSION" | tr -d '\r')
if [ -z "$VERSION" ]; then
echo "::error::Kon pluginversie niet bepalen."
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Genereer manifest.json uit plugin header
run: |
python3 - <<'PY'
import json
import re
with open('groq-ai-product-text.php', 'r', encoding='utf-8') as handle:
content = handle.read()
header_match = re.search(r'/\*\*(.*?)\*/', content, re.S)
header = header_match.group(1) if header_match else ''
def read_field(label: str) -> str:
match = re.search(r'^\s*\*\s*' + re.escape(label) + r'\s*:\s*(.+)$', header, re.M)
return match.group(1).strip() if match else ''
manifest = {
'plugin_name': read_field('Plugin Name'),
'description': read_field('Description'),
'version': read_field('Version'),
'author': read_field('Author'),
'author_url': read_field('Author URI'),
}
with open('manifest.json', 'w', encoding='utf-8') as handle:
json.dump(manifest, handle, ensure_ascii=False, indent=2)
print('manifest.json aangemaakt/bijgewerkt')
PY
- name: Commit & push manifest.json
run: |
if git diff --quiet -- manifest.json; then
echo "manifest.json ongewijzigd; geen commit nodig."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add manifest.json
git commit -m "chore: update manifest.json"
git push
- name: Check if tag exists
id: tagcheck
run: |
TAG="v${{ steps.meta.outputs.version }}"
if git ls-remote --tags origin "refs/tags/$TAG" | grep -q "refs/tags/$TAG$"; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Tag bestaat al workflow afronden
if: steps.tagcheck.outputs.exists == 'true'
run: |
echo "Tag v${{ steps.meta.outputs.version }} bestaat al. Release wordt overgeslagen."
- name: Build distributie-zip
if: steps.tagcheck.outputs.exists == 'false'
id: package
run: |
if ! command -v zip >/dev/null 2>&1; then
apt-get update -y
apt-get install -y zip
fi
VERSION="${{ steps.meta.outputs.version }}"
SLUG="siti-ai-product-content-generator"
BUILD_ROOT="$RUNNER_TEMP/build"
DEST_DIR="$BUILD_ROOT/$SLUG"
mkdir -p "$DEST_DIR"
tar -cf - \
--exclude='.git' \
--exclude='.github' \
--exclude='docker' \
--exclude='docs' \
--exclude='dist' \
--exclude='docker-compose.yml' \
--exclude='PLAN.md' \
. | tar -xf - -C "$DEST_DIR"
mkdir -p dist
ZIP_PATH="dist/${SLUG}-${VERSION}.zip"
(cd "$BUILD_ROOT" && zip -r "$GITHUB_WORKSPACE/$ZIP_PATH" "$SLUG")
echo "asset_path=$ZIP_PATH" >> "$GITHUB_OUTPUT"
echo "asset_name=${SLUG}-${VERSION}.zip" >> "$GITHUB_OUTPUT"
- name: Maak Gitea release
if: steps.tagcheck.outputs.exists == 'false'
env:
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
RELEASE_SERVER_URL: ${{ vars.RELEASE_SERVER_URL }}
RELEASE_REPOSITORY: ${{ vars.RELEASE_REPOSITORY }}
run: |
VERSION="${{ steps.meta.outputs.version }}"
TAG="v$VERSION"
ASSET_PATH="${{ steps.package.outputs.asset_path }}"
ASSET_NAME="${{ steps.package.outputs.asset_name }}"
if [ -z "$RELEASE_TOKEN" ]; then
echo "::error::RELEASE_TOKEN ontbreekt. Voeg deze secret toe om releases te kunnen maken."
exit 1
fi
SERVER_URL="${RELEASE_SERVER_URL:-${GITHUB_SERVER_URL}}"
REPO="${RELEASE_REPOSITORY:-${GITHUB_REPOSITORY}}"
if [ -z "$SERVER_URL" ] || [ -z "$REPO" ]; then
echo "::error::Kan server of repository niet bepalen. Stel RELEASE_SERVER_URL en RELEASE_REPOSITORY in."
exit 1
fi
API_URL="${SERVER_URL%/}/api/v1"
export TAG
python3 - <<'PY'
import json
import os
payload = {
"tag_name": os.environ["TAG"],
"name": f"Siti AI Product Teksten {os.environ['TAG']}",
"body": f"Automatische release op basis van versie {os.environ['TAG'][1:]}",
"target_commitish": os.environ.get("GITHUB_SHA") or os.environ.get("GITEA_SHA", ""),
}
with open("release.json", "w", encoding="utf-8") as handle:
json.dump(payload, handle, ensure_ascii=False)
PY
curl -sS -X POST "$API_URL/repos/$REPO/releases" \
-H "Authorization: token $RELEASE_TOKEN" \
-H "Content-Type: application/json" \
-d @release.json \
-o release-response.json
RELEASE_ID=$(python3 - <<'PY'
import json
with open('release-response.json', 'r', encoding='utf-8') as handle:
data = json.load(handle)
print(data.get('id', ''))
PY
)
if [ -z "$RELEASE_ID" ]; then
echo "::error::Kon release-ID niet bepalen. Response: $(cat release-response.json)"
exit 1
fi
curl -sS -X POST "$API_URL/repos/$REPO/releases/$RELEASE_ID/assets?name=$ASSET_NAME" \
-H "Authorization: token $RELEASE_TOKEN" \
-H "Content-Type: application/zip" \
--data-binary "@$ASSET_PATH"

View File

@@ -1,85 +1,49 @@
# Nieuwe License Validator en Updater # SitiWebUpdater2 - Globale Plugin Updater
Deze plugin gebruikt nu een eigen licentie- en updatesysteem via plugins.robert.ooo in plaats van GitHub. Deze class gebruikt een globale registry zodat alle plugins die deze updater gebruiken hun licenties op één centrale pagina beheren.
## Gebruik ## Gebruik
### License Validator ### Basis setup (per plugin)
```php ```php
require_once __DIR__ . '/includes/SitiLicenseValidator.php'; require_once 'path/to/SitiWebUpdater2.php';
// Initialiseer validator
$validator = new SitiLicenseValidator();
// Stel licentie in (van settings)
$validator->set_license_key( get_option( 'siti_license_key' ) );
// Verificeer
$result = $validator->verify();
if ( is_wp_error( $result ) ) {
// Toon fout
echo $result->get_error_message();
} else {
// Licentie geldig
$version = $result['license']['pluginVersion'];
}
```
### SitiWebUpdater2
```php
require_once __DIR__ . '/includes/SitiWebUpdater2.php';
// Initialiseer updater
$updater = new SitiWebUpdater2( __FILE__ ); $updater = new SitiWebUpdater2( __FILE__ );
$updater->set_owner( 'jouw-github-username' );
// Stel owner/repo in (bijv. van manifest.json) $updater->set_repository( 'jouw-plugin-repo' );
$updater->set_owner( 'siti-ai-product-content-generator' ); $updater->initialize();
$updater->set_repository( 'siti-ai-product-content-generator' );
// Stel licentie in voor downloads
$updater->set_license_key( get_option( 'siti_license_key' ) );
// API URL (optioneel, default is plugins.robert.ooo)
$updater->set_api_base_url( 'https://plugins.robert.ooo' );
``` ```
## Instellingen ### Automatische features
Voeg in je admin settings pagina velden toe voor: De updater doet alles automatisch:
- Licentiecode 1. **Globale license pagina**: Voegt één instellingen pagina toe onder Instellingen > Plugin Licenties
- API URL (optioneel) 2. **Admin notices**: Toont rood bericht per plugin als licentie ongeldig is
3. **Dagelijkse checks**: Controleert dagelijks alle licenties
4. **Auto-updates**: Controleert op updates voor alle plugins
Sla op in wp_options: ### Centrale licentie pagina
```php Alle plugins die SitiWebUpdater2 gebruiken verschijnen automatisch op de centrale pagina `Instellingen > Plugin Licenties`, waar je alle licentiecodes in één keer kunt beheren.
update_option( 'siti_license_key', sanitize_text_field( $_POST['license_key'] ) );
update_option( 'siti_api_url', esc_url_raw( $_POST['api_url'] ) ?: 'https://plugins.robert.ooo' );
```
## Cron Job voor Licentie Checks ## Configuratie
```php - **Owner/Repo**: Stel in via `set_owner()` en `set_repository()`
add_action( 'siti_daily_license_check', function() { - **API URL**: Standaard `https://plugins.robert.ooo`, aanpasbaar met `set_api_base_url()`
$validator = new SitiLicenseValidator(); - **License key**: Wordt opgeslagen in eigen option key per plugin
$result = $validator->verify();
// Log of handel af
} );
if ( ! wp_next_scheduled( 'siti_daily_license_check' ) ) { ## Option Keys (per plugin)
wp_schedule_event( time(), 'daily', 'siti_daily_license_check' );
}
```
## Admin Notices - `siti_updater_{plugin_slug}_license_key`: De licentiecode
- `siti_updater_{plugin_slug}_license_data`: Gecachte licentie data
- `siti_updater_{plugin_slug}_last_check`: Timestamp laatste check
```php ## Cron Jobs (per plugin)
add_action( 'admin_notices', function() {
$validator = new SitiLicenseValidator(); - `siti_updater_daily_check_siti_updater_{plugin_slug}_`: Dagelijkse licentie verificatie
if ( ! $validator->is_valid() ) {
echo '<div class="notice notice-error"><p>Licentie ongeldig. Controleer je instellingen.</p></div>'; ## Herbruikbaarheid
}
} ); Deze class is volledig herbruikbaar in meerdere plugins. Elke plugin registreert zichzelf automatisch in de globale registry en verschijnt op de centrale licentie pagina.
```

View File

@@ -2,7 +2,7 @@
/** /**
* Plugin Name: SitiAI Product Teksten * Plugin Name: SitiAI Product Teksten
* Description: Genereer productteksten met diverse AI-aanbieders rechtstreeks vanuit WooCommerce. * Description: Genereer productteksten met diverse AI-aanbieders rechtstreeks vanuit WooCommerce.
* Version: 1.9.3 * Version: 1.10.0
* Author: Roberto Guagliardo | SitiWeb * Author: Roberto Guagliardo | SitiWeb
* Author URI: https://sitiweb.nl/ * Author URI: https://sitiweb.nl/
* Text Domain: siti-ai-product-content-generator * Text Domain: siti-ai-product-content-generator

View File

@@ -181,6 +181,7 @@ class Groq_AI_Product_Text_Settings_Page extends Groq_AI_Admin_Base {
'attributes' => [ 'attributes' => [
'id' => 'groq-ai-model-select', 'id' => 'groq-ai-model-select',
], ],
'current_provider' => isset( $settings['provider'] ) ? $settings['provider'] : '',
] ]
); );
@@ -569,15 +570,50 @@ class Groq_AI_Product_Text_Settings_Page extends Groq_AI_Admin_Base {
<?php <?php
} }
private function render_model_select_field( $field_args ) { public function render_model_select_field( $field_args ) {
$name = isset( $field_args['name'] ) ? $field_args['name'] : ''; $name = isset( $field_args['name'] ) ? $field_args['name'] : '';
$id = isset( $field_args['id'] ) && '' !== $field_args['id'] ? $field_args['id'] : 'groq-ai-model-select'; $id = isset( $field_args['id'] ) && '' !== $field_args['id'] ? $field_args['id'] : 'groq-ai-model-select';
$current = isset( $field_args['value'] ) ? (string) $field_args['value'] : ''; $current = isset( $field_args['value'] ) ? (string) $field_args['value'] : '';
$placeholder = __( 'Selecteer eerst een aanbieder', GROQ_AI_PRODUCT_TEXT_DOMAIN ); $placeholder = __( 'Selecteer eerst een aanbieder', GROQ_AI_PRODUCT_TEXT_DOMAIN );
$current_provider = isset( $field_args['current_provider'] ) ? sanitize_key( (string) $field_args['current_provider'] ) : '';
$provider = '' !== $current_provider ? $this->provider_manager->get_provider( $current_provider ) : null;
$models = [];
if ( $provider ) {
$models = $this->prepare_models_list_for_provider( $current_provider, $this->plugin->get_cached_models_for_provider( $current_provider ) );
if ( empty( $models ) ) {
$models = $this->prepare_models_list_for_provider( $current_provider, $provider->get_available_models() );
}
$placeholder = __( 'Selecteer een model', GROQ_AI_PRODUCT_TEXT_DOMAIN );
} elseif ( '' !== $current_provider ) {
$placeholder = __( 'Geen modellen gevonden. Gebruik "Live modellen ophalen".', GROQ_AI_PRODUCT_TEXT_DOMAIN );
}
?> ?>
<div class="groq-ai-model-field"> <div class="groq-ai-model-field">
<select id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" data-current-model="<?php echo esc_attr( $current ); ?>"> <select id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" data-current-model="<?php echo esc_attr( $current ); ?>">
<option value="" selected="selected"><?php echo esc_html( $placeholder ); ?></option> <option value=""><?php echo esc_html( $placeholder ); ?></option>
<?php
if ( ! empty( $models ) ) :
$has_current = in_array( $current, $models, true );
foreach ( $models as $model ) :
?>
<option value="<?php echo esc_attr( $model ); ?>" <?php selected( $current, $model ); ?>><?php echo esc_html( $model ); ?></option>
<?php
endforeach;
if ( $current && ! $has_current ) :
?>
<option value="<?php echo esc_attr( $current ); ?>" selected="selected"><?php echo esc_html( $current ); ?></option>
<?php
endif;
elseif ( $current ) :
?>
<option value="<?php echo esc_attr( $current ); ?>" selected="selected"><?php echo esc_html( $current ); ?></option>
<?php
endif;
?>
</select> </select>
</div> </div>
<button type="button" class="button" id="groq-ai-refresh-models"><?php esc_html_e( 'Live modellen ophalen', GROQ_AI_PRODUCT_TEXT_DOMAIN ); ?></button> <button type="button" class="button" id="groq-ai-refresh-models"><?php esc_html_e( 'Live modellen ophalen', GROQ_AI_PRODUCT_TEXT_DOMAIN ); ?></button>
@@ -865,8 +901,11 @@ class Groq_AI_Product_Text_Settings_Page extends Groq_AI_Admin_Base {
foreach ( $this->provider_manager->get_providers() as $provider ) { foreach ( $this->provider_manager->get_providers() as $provider ) {
$provider_key = $provider->get_key(); $provider_key = $provider->get_key();
$cached_models = $this->plugin->get_cached_models_for_provider( $provider_key ); $cached_models = $this->prepare_models_list_for_provider( $provider_key, $this->plugin->get_cached_models_for_provider( $provider_key ) );
$cached_models = Groq_AI_Model_Exclusions::filter_models( $provider_key, $cached_models );
if ( empty( $cached_models ) ) {
$cached_models = $this->prepare_models_list_for_provider( $provider_key, $provider->get_available_models() );
}
$data['providers'][ $provider_key ] = [ $data['providers'][ $provider_key ] = [
'default_label' => sprintf( __( 'Gebruik standaardmodel (%s)', GROQ_AI_PRODUCT_TEXT_DOMAIN ), $provider->get_default_model() ), 'default_label' => sprintf( __( 'Gebruik standaardmodel (%s)', GROQ_AI_PRODUCT_TEXT_DOMAIN ), $provider->get_default_model() ),
'models' => $cached_models, 'models' => $cached_models,
@@ -878,6 +917,18 @@ class Groq_AI_Product_Text_Settings_Page extends Groq_AI_Admin_Base {
wp_localize_script( 'groq-ai-settings', 'GroqAISettingsData', $data ); wp_localize_script( 'groq-ai-settings', 'GroqAISettingsData', $data );
} }
private function prepare_models_list_for_provider( $provider_key, $models ) {
$list = Groq_AI_Model_Exclusions::filter_models( $provider_key, $models );
if ( empty( $list ) ) {
return [];
}
sort( $list, SORT_NATURAL | SORT_FLAG_CASE );
return $list;
}
public function handle_google_oauth_start() { public function handle_google_oauth_start() {
if ( ! current_user_can( 'manage_options' ) ) { if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'Je hebt geen toestemming om deze actie uit te voeren.', GROQ_AI_PRODUCT_TEXT_DOMAIN ), '', [ 'response' => 403 ] ); wp_die( esc_html__( 'Je hebt geen toestemming om deze actie uit te voeren.', GROQ_AI_PRODUCT_TEXT_DOMAIN ), '', [ 'response' => 403 ] );

View File

@@ -10,10 +10,12 @@ class SitiLicenseValidator {
private $api_base_url = 'https://plugins.robert.ooo'; private $api_base_url = 'https://plugins.robert.ooo';
private $license_key; private $license_key;
private $hostname; private $hostname;
private $plugin_version;
public function __construct( $license_key = null, $hostname = null ) { public function __construct( $license_key = null, $hostname = null, $plugin_version = null ) {
$this->license_key = $license_key ?: get_option( 'siti_license_key' ); $this->license_key = $license_key ?: get_option( 'siti_license_key' );
$this->hostname = $hostname ?: parse_url( home_url(), PHP_URL_HOST ); $this->hostname = $hostname ?: parse_url( home_url(), PHP_URL_HOST );
$this->plugin_version = $plugin_version;
} }
/** /**
@@ -37,6 +39,13 @@ class SitiLicenseValidator {
$this->hostname = $hostname; $this->hostname = $hostname;
} }
/**
* Set the plugin version for reporting purposes
*/
public function set_plugin_version( $version ) {
$this->plugin_version = $version;
}
/** /**
* Verify the license * Verify the license
* *
@@ -58,6 +67,7 @@ class SitiLicenseValidator {
'body' => wp_json_encode( array( 'body' => wp_json_encode( array(
'key' => $this->license_key, 'key' => $this->license_key,
'hostname' => $this->hostname, 'hostname' => $this->hostname,
'currentVersion' => $this->plugin_version,
) ), ) ),
'timeout' => 15, 'timeout' => 15,
) ); ) );
@@ -69,22 +79,30 @@ class SitiLicenseValidator {
$code = wp_remote_retrieve_response_code( $response ); $code = wp_remote_retrieve_response_code( $response );
$body = json_decode( wp_remote_retrieve_body( $response ), true ); $body = json_decode( wp_remote_retrieve_body( $response ), true );
if ( ! is_array( $body ) ) {
return new WP_Error( 'verification_failed', 'Onverwacht antwoord van licentieserver.' );
}
$has_payload = isset( $body['license'] ) || isset( $body['pluginVersion'] ) || isset( $body['version'] );
if ( 200 !== $code ) { if ( 200 !== $code ) {
if ( $has_payload ) {
$this->store_license_payload( $body );
}
$error_message = isset( $body['error'] ) ? $body['error'] : 'Licentie verificatie mislukt.'; $error_message = isset( $body['error'] ) ? $body['error'] : 'Licentie verificatie mislukt.';
return new WP_Error( 'verification_failed', $error_message ); return new WP_Error( 'verification_failed', $error_message );
} }
if ( empty( $body['valid'] ) ) { if ( empty( $body['valid'] ) ) {
if ( $has_payload ) {
$this->store_license_payload( $body );
}
return new WP_Error( 'invalid_license', 'Licentie is ongeldig.' ); return new WP_Error( 'invalid_license', 'Licentie is ongeldig.' );
} }
// Update last check time $this->store_license_payload( $body );
update_option( 'siti_license_last_check', current_time( 'mysql' ) );
// Store license data
if ( isset( $body['license'] ) ) {
update_option( 'siti_license_data', $body['license'] );
}
return $body; return $body;
} }
@@ -127,4 +145,37 @@ class SitiLicenseValidator {
// In practice, you might want to proxy this through WordPress // In practice, you might want to proxy this through WordPress
return $this->api_base_url . '/api/licenses/download?key=' . urlencode( $this->license_key ) . '&hostname=' . urlencode( $this->hostname ) . '&version=' . urlencode( $version ); return $this->api_base_url . '/api/licenses/download?key=' . urlencode( $this->license_key ) . '&hostname=' . urlencode( $this->hostname ) . '&version=' . urlencode( $version );
} }
/**
* Persist payload data locally for UI purposes
*/
private function store_license_payload( $body ) {
$license_data = array();
if ( isset( $body['license'] ) && is_array( $body['license'] ) ) {
$license_data = $body['license'];
}
if ( empty( $license_data['key'] ) ) {
$license_data['key'] = $this->license_key;
}
$version = null;
if ( ! empty( $body['pluginVersion'] ) ) {
$version = $body['pluginVersion'];
} elseif ( ! empty( $body['version'] ) ) {
$version = $body['version'];
}
if ( $version ) {
$license_data['pluginVersion'] = $version;
}
if ( empty( $license_data ) ) {
return;
}
update_option( 'siti_license_data', $license_data );
update_option( 'siti_license_last_check', current_time( 'mysql' ) );
}
} }

View File

@@ -6,7 +6,11 @@
* Updates plugins via the Siti Plugin Repo API instead of GitHub * Updates plugins via the Siti Plugin Repo API instead of GitHub
* Fully self-contained with built-in license management * Fully self-contained with built-in license management
*/ */
class SitiWebUpdater2 { class SitiWebUpdater2
{
private static $instances = array();
private static $global_settings_registered = false;
private $file; private $file;
private $plugin; private $plugin;
@@ -19,11 +23,15 @@ class SitiWebUpdater2 {
private $plugin_response; private $plugin_response;
private $option_prefix; private $option_prefix;
public function __construct( $file ) { public function __construct($file)
{
$this->file = $file; $this->file = $file;
$this->option_prefix = 'siti_updater_' . sanitize_key(dirname(plugin_basename($this->file))) . '_'; $this->option_prefix = 'siti_updater_' . sanitize_key(dirname(plugin_basename($this->file))) . '_';
$this->set_plugin_properties(); $this->set_plugin_properties();
// Register this instance globally
self::$instances[$this->option_prefix] = $this;
add_action('admin_init', array($this, 'set_plugin_properties')); add_action('admin_init', array($this, 'set_plugin_properties'));
add_action('admin_notices', array($this, 'admin_notices')); add_action('admin_notices', array($this, 'admin_notices'));
add_action('siti_updater_daily_check_' . $this->option_prefix, array($this, 'daily_license_check')); add_action('siti_updater_daily_check_' . $this->option_prefix, array($this, 'daily_license_check'));
@@ -35,13 +43,20 @@ class SitiWebUpdater2 {
return $this; return $this;
} }
public function initialize() { public function initialize()
{
add_filter('pre_set_site_transient_update_plugins', array($this, 'check_for_updates')); add_filter('pre_set_site_transient_update_plugins', array($this, 'check_for_updates'));
add_filter('plugins_api', array($this, 'plugin_info'), 10, 3); add_filter('plugins_api', array($this, 'plugin_info'), 10, 3);
add_action( 'admin_menu', array( $this, 'add_settings_page' ) );
// Register global settings page only once
if (!self::$global_settings_registered) {
add_action('admin_menu', array($this, 'add_global_settings_page'));
self::$global_settings_registered = true;
}
} }
public function set_plugin_properties() { public function set_plugin_properties()
{
if (!function_exists('get_plugin_data')) { if (!function_exists('get_plugin_data')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php'; require_once ABSPATH . 'wp-admin/includes/plugin.php';
} }
@@ -51,31 +66,125 @@ class SitiWebUpdater2 {
$this->active = is_plugin_active($this->basename); $this->active = is_plugin_active($this->basename);
} }
public function set_owner( $owner ) { public static function get_instances()
{
return self::$instances;
}
public function get_plugin_data()
{
return $this->plugin;
}
public function set_owner($owner)
{
$this->owner = $owner; $this->owner = $owner;
} }
public function set_repository( $repository ) { public function set_repository($repository)
{
$this->repository = $repository; $this->repository = $repository;
} }
public function set_license_key( $key ) { public function set_license_key($key)
$this->license_key = $key; {
update_option( $this->option_prefix . 'license_key', $key ); $sanitized_key = sanitize_text_field((string) $key);
$stored_key = get_option($this->option_prefix . 'license_key', '');
if ($stored_key !== $sanitized_key) {
$this->clear_cached_license_data();
} }
public function get_license_key() { $this->license_key = $sanitized_key;
update_option($this->option_prefix . 'license_key', $sanitized_key);
}
public function get_license_key()
{
if (null === $this->license_key) { if (null === $this->license_key) {
$this->license_key = get_option($this->option_prefix . 'license_key', ''); $this->license_key = get_option($this->option_prefix . 'license_key', '');
} }
return $this->license_key; return $this->license_key;
} }
public function set_api_base_url( $api_base_url ) { public function get_license_data()
{
return $this->get_stored_license_data();
}
public function set_api_base_url($api_base_url)
{
$this->api_base_url = rtrim((string) $api_base_url, '/'); $this->api_base_url = rtrim((string) $api_base_url, '/');
} }
private function get_plugin_info() { private function normalize_version($version)
{
if (!is_string($version)) {
return $version;
}
$version = trim($version);
if ('' === $version) {
return $version;
}
if (0 === stripos($version, 'v')) {
$version = ltrim($version, 'vV');
}
return $version;
}
private function get_stored_license_data()
{
$data = get_option($this->option_prefix . 'license_data', array());
return is_array($data) ? $data : array();
}
private function clear_cached_license_data()
{
delete_option($this->option_prefix . 'license_data');
delete_option($this->option_prefix . 'last_check');
}
private function store_license_data($body)
{
if (!is_array($body)) {
$body = array();
}
$license_data = array();
if (isset($body['license']) && is_array($body['license'])) {
$license_data = $body['license'];
}
if (empty($license_data['key'])) {
$license_data['key'] = $this->get_license_key();
}
$license_data['licenseValid'] = !empty($body['valid']);
$version = null;
if (isset($body['pluginVersion']) && $body['pluginVersion']) {
$version = $body['pluginVersion'];
} elseif (isset($body['version']) && $body['version']) {
$version = $body['version'];
} elseif (isset($license_data['pluginVersion']) && $license_data['pluginVersion']) {
$version = $license_data['pluginVersion'];
}
if ($version) {
$license_data['pluginVersion'] = $this->normalize_version($version);
}
update_option($this->option_prefix . 'license_data', $license_data);
update_option($this->option_prefix . 'last_check', current_time('mysql'));
}
private function get_plugin_info()
{
if (is_null($this->plugin_response)) { if (is_null($this->plugin_response)) {
$request_uri = sprintf('%s/api/plugins/%s/%s', $this->api_base_url, $this->owner, $this->repository); $request_uri = sprintf('%s/api/plugins/%s/%s', $this->api_base_url, $this->owner, $this->repository);
@@ -93,11 +202,15 @@ class SitiWebUpdater2 {
} }
$body = json_decode(wp_remote_retrieve_body($response), true); $body = json_decode(wp_remote_retrieve_body($response), true);
if (is_array($body) && isset($body['version'])) {
$body['version'] = $this->normalize_version($body['version']);
}
$this->plugin_response = $body; $this->plugin_response = $body;
} }
} }
public function check_for_updates( $transient ) { public function check_for_updates($transient)
{
if (empty($transient->checked)) { if (empty($transient->checked)) {
return $transient; return $transient;
} }
@@ -108,10 +221,10 @@ class SitiWebUpdater2 {
return $transient; return $transient;
} }
$remote_version = $this->plugin_response['version']; $remote_version = $this->normalize_version($this->plugin_response['version']);
$current_version = $this->plugin['Version']; $current_version = $this->normalize_version($this->plugin['Version']);
if ( version_compare( $remote_version, $current_version, '>' ) ) { if ($remote_version && version_compare($remote_version, $current_version, '>')) {
$download_url = $this->get_download_url('latest'); $download_url = $this->get_download_url('latest');
if (!is_wp_error($download_url)) { if (!is_wp_error($download_url)) {
@@ -128,7 +241,8 @@ class SitiWebUpdater2 {
return $transient; return $transient;
} }
public function plugin_info( $result, $action, $args ) { public function plugin_info($result, $action, $args)
{
if ('plugin_information' !== $action || $args->slug !== dirname($this->basename)) { if ('plugin_information' !== $action || $args->slug !== dirname($this->basename)) {
return $result; return $result;
} }
@@ -142,7 +256,7 @@ class SitiWebUpdater2 {
return (object) array( return (object) array(
'name' => $this->plugin_response['name'] ?? $this->plugin['Name'], 'name' => $this->plugin_response['name'] ?? $this->plugin['Name'],
'slug' => $args->slug, 'slug' => $args->slug,
'version' => $this->plugin_response['version'], 'version' => $this->normalize_version($this->plugin_response['version'] ?? $this->plugin['Version']),
'author' => $this->plugin_response['author'] ?? $this->plugin['Author'], 'author' => $this->plugin_response['author'] ?? $this->plugin['Author'],
'author_profile' => $this->plugin_response['author_url'] ?? $this->plugin['AuthorURI'], 'author_profile' => $this->plugin_response['author_url'] ?? $this->plugin['AuthorURI'],
'homepage' => $this->plugin_response['homepage'] ?? '', 'homepage' => $this->plugin_response['homepage'] ?? '',
@@ -158,7 +272,8 @@ class SitiWebUpdater2 {
); );
} }
private function get_download_url( $version = 'latest' ) { private function get_download_url($version = 'latest')
{
$license_key = $this->get_license_key(); $license_key = $this->get_license_key();
if (empty($license_key)) { if (empty($license_key)) {
return new WP_Error('no_license', 'Geen licentie ingesteld'); return new WP_Error('no_license', 'Geen licentie ingesteld');
@@ -168,13 +283,15 @@ class SitiWebUpdater2 {
return $this->api_base_url . '/api/licenses/download?key=' . urlencode($license_key) . '&hostname=' . urlencode($hostname) . '&version=' . urlencode($version); return $this->api_base_url . '/api/licenses/download?key=' . urlencode($license_key) . '&hostname=' . urlencode($hostname) . '&version=' . urlencode($version);
} }
public function verify_license() { public function verify_license()
{
$license_key = $this->get_license_key(); $license_key = $this->get_license_key();
if (empty($license_key)) { if (empty($license_key)) {
return new WP_Error('missing_license', 'Geen licentiecode ingesteld.'); return new WP_Error('missing_license', 'Geen licentiecode ingesteld.');
} }
$hostname = parse_url(home_url(), PHP_URL_HOST); $hostname = parse_url(home_url(), PHP_URL_HOST);
$current_version = isset($this->plugin['Version']) ? $this->plugin['Version'] : null;
$response = wp_remote_post($this->api_base_url . '/api/licenses/verify', array( $response = wp_remote_post($this->api_base_url . '/api/licenses/verify', array(
'headers' => array( 'headers' => array(
'Content-Type' => 'application/json', 'Content-Type' => 'application/json',
@@ -182,6 +299,9 @@ class SitiWebUpdater2 {
'body' => wp_json_encode(array( 'body' => wp_json_encode(array(
'key' => $license_key, 'key' => $license_key,
'hostname' => $hostname, 'hostname' => $hostname,
'currentVersion' => $current_version,
'owner' => $this->owner,
'repository' => $this->repository,
)), )),
'timeout' => 15, 'timeout' => 15,
)); ));
@@ -193,98 +313,195 @@ class SitiWebUpdater2 {
$code = wp_remote_retrieve_response_code($response); $code = wp_remote_retrieve_response_code($response);
$body = json_decode(wp_remote_retrieve_body($response), true); $body = json_decode(wp_remote_retrieve_body($response), true);
if (!is_array($body)) {
$this->clear_cached_license_data();
return new WP_Error('verification_failed', 'Onverwacht antwoord van licentieserver.');
}
$has_license_payload = isset($body['license']) || isset($body['pluginVersion']) || isset($body['version']);
if (200 !== $code) { if (200 !== $code) {
if ($has_license_payload) {
$this->store_license_data($body);
} else {
$this->clear_cached_license_data();
}
$error_message = isset($body['error']) ? $body['error'] : 'Licentie verificatie mislukt.'; $error_message = isset($body['error']) ? $body['error'] : 'Licentie verificatie mislukt.';
return new WP_Error('verification_failed', $error_message); return new WP_Error('verification_failed', $error_message);
} }
if (empty($body['valid'])) { if (empty($body['valid'])) {
if ($has_license_payload) {
$this->store_license_data($body);
} else {
$this->clear_cached_license_data();
}
return new WP_Error('invalid_license', 'Licentie is ongeldig.'); return new WP_Error('invalid_license', 'Licentie is ongeldig.');
} }
// Store license data $this->store_license_data($body);
update_option( $this->option_prefix . 'license_data', $body['license'] );
update_option( $this->option_prefix . 'last_check', current_time( 'mysql' ) );
return $body; return $body;
} }
public function is_license_valid() { public function is_license_valid()
$data = get_option( $this->option_prefix . 'license_data', array() ); {
return ! empty( $data ) && isset( $data['key'] ); $data = $this->get_license_data();
if (empty($data) || empty($data['key'])) {
return false;
} }
public function admin_notices() { if (isset($data['licenseValid'])) {
return (bool) $data['licenseValid'];
}
return true;
}
public function get_latest_known_version()
{
$this->get_plugin_info();
if (!empty($this->plugin_response['version'])) {
return $this->normalize_version($this->plugin_response['version']);
}
$license_data = $this->get_license_data();
if (isset($license_data['pluginVersion']) && $license_data['pluginVersion']) {
return $this->normalize_version($license_data['pluginVersion']);
}
return null;
}
public function admin_notices()
{
if (!current_user_can('manage_options')) { if (!current_user_can('manage_options')) {
return; return;
} }
if (!$this->is_license_valid()) { if (!$this->is_license_valid()) {
$settings_url = admin_url( 'options-general.php?page=siti-updater-' . sanitize_title( $this->plugin['Name'] ) ); $settings_url = admin_url('options-general.php?page=siti-plugin-licenses');
echo '<div class="notice notice-error"><p>'; echo '<div class="notice notice-error"><p>';
printf( printf(
esc_html__('%s: Licentie ongeldig of niet ingesteld. Ga naar %s om je licentie in te voeren.', 'siti-updater'), esc_html__('%s: Licentie ongeldig of niet ingesteld. Ga naar %s om je licentie in te voeren.', 'siti-updater'),
esc_html($this->plugin['Name']), esc_html($this->plugin['Name']),
'<a href="' . esc_url( $settings_url ) . '">' . esc_html__( 'instellingen', 'siti-updater' ) . '</a>' '<a href="' . esc_url($settings_url) . '">' . esc_html__('plugin licenties', 'siti-updater') . '</a>'
); );
echo '</p></div>'; echo '</p></div>';
} }
} }
public function daily_license_check() { public function daily_license_check()
{
$result = $this->verify_license(); $result = $this->verify_license();
if (is_wp_error($result)) { if (is_wp_error($result)) {
error_log($this->plugin['Name'] . ' License check failed: ' . $result->get_error_message()); error_log($this->plugin['Name'] . ' License check failed: ' . $result->get_error_message());
} }
} }
public function add_settings_page() { public function add_global_settings_page()
{
add_options_page( add_options_page(
sprintf( __( '%s Licentie', 'siti-updater' ), $this->plugin['Name'] ), __('Plugin Licenties', 'siti-updater'),
sprintf( __( '%s Licentie', 'siti-updater' ), $this->plugin['Name'] ), __('Plugin Licenties', 'siti-updater'),
'manage_options', 'manage_options',
'siti-updater-' . sanitize_title( $this->plugin['Name'] ), 'siti-plugin-licenses',
array( $this, 'render_settings_page' ) array($this, 'render_global_settings_page')
); );
} }
public function render_settings_page() { public function render_global_settings_page()
{
if (!current_user_can('manage_options')) { if (!current_user_can('manage_options')) {
return; return;
} }
if ( isset( $_POST['siti_updater_license_key'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'siti_updater_save' ) ) { if (isset($_POST['siti_updater_save']) && wp_verify_nonce($_POST['_wpnonce'], 'siti_updater_save')) {
$this->set_license_key( sanitize_text_field( $_POST['siti_updater_license_key'] ) ); foreach (self::$instances as $prefix => $instance) {
$result = $this->verify_license(); $key = $prefix . 'license_key';
if (isset($_POST[$key])) {
$instance->set_license_key(sanitize_text_field($_POST[$key]));
$result = $instance->verify_license();
if (is_wp_error($result)) { if (is_wp_error($result)) {
add_settings_error( 'siti_updater', 'license_error', $result->get_error_message() ); $plugin_data = $instance->get_plugin_data();
add_settings_error('siti_updater', 'license_error_' . $prefix, $plugin_data['Name'] . ': ' . $result->get_error_message());
} else { } else {
add_settings_error( 'siti_updater', 'license_success', __( 'Licentie succesvol opgeslagen en geverifieerd.', 'siti-updater' ), 'updated' ); $plugin_data = $instance->get_plugin_data();
add_settings_error('siti_updater', 'license_success_' . $prefix, $plugin_data['Name'] . ': ' . __('Licentie succesvol opgeslagen en geverifieerd.', 'siti-updater'), 'updated');
}
}
} }
} }
?> ?>
<div class="wrap"> <div class="wrap">
<h1><?php printf( esc_html__( '%s Licentie Instellingen', 'siti-updater' ), $this->plugin['Name'] ); ?></h1> <h1><?php esc_html_e('Plugin Licenties', 'siti-updater'); ?></h1>
<p class="description"> <p class="description">
<?php printf( esc_html__( 'Voer je licentiecode in voor %s om updates te ontvangen.', 'siti-updater' ), $this->plugin['Name'] ); ?> <?php esc_html_e('Beheer licentiecodes voor al je plugins die het Siti update systeem gebruiken.', 'siti-updater'); ?>
</p> </p>
<?php settings_errors('siti_updater'); ?> <?php settings_errors('siti_updater'); ?>
<form method="post" action=""> <form method="post" action="">
<?php wp_nonce_field('siti_updater_save'); ?> <?php wp_nonce_field('siti_updater_save'); ?>
<table class="form-table"> <table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th><?php esc_html_e('Plugin', 'siti-updater'); ?></th>
<th><?php esc_html_e('Licentiecode', 'siti-updater'); ?></th>
<th><?php esc_html_e('Geldig', 'siti-updater'); ?></th>
<th><?php esc_html_e('Huidige versie', 'siti-updater'); ?></th>
<th><?php esc_html_e('Nieuwste versie', 'siti-updater'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach (self::$instances as $prefix => $instance):
$license_data = $instance->get_license_data();
$is_valid = $instance->is_license_valid();
$plugin_data = $instance->get_plugin_data();
$current_version = $plugin_data['Version'];
$latest_known = $instance->get_latest_known_version();
$latest_version = $latest_known ? $latest_known : (isset($license_data['pluginVersion']) ? $license_data['pluginVersion'] : '-');
?>
<tr> <tr>
<th scope="row"><?php esc_html_e( 'Licentiecode', 'siti-updater' ); ?></th>
<td> <td>
<input type="text" name="siti_updater_license_key" value="<?php echo esc_attr( $this->get_license_key() ); ?>" class="regular-text" /> <strong><?php echo esc_html($plugin_data['Name']); ?></strong>
<p class="description"><?php esc_html_e( 'Verkrijg je licentiecode van plugins.robert.ooo', 'siti-updater' ); ?></p> <br>
<small><?php echo esc_html($plugin_data['Description']); ?></small>
</td>
<td>
<input type="text" name="<?php echo esc_attr($prefix . 'license_key'); ?>"
value="<?php echo esc_attr($instance->get_license_key()); ?>" class="regular-text"
placeholder="<?php esc_attr_e('Voer licentiecode in...', 'siti-updater'); ?>" />
<p class="description">
<?php printf(esc_html__('Licentie voor %s. Verkrijg je code van plugins.robert.ooo', 'siti-updater'), $plugin_data['Name']); ?>
</p>
</td>
<td>
<span class="license-status <?php echo $is_valid ? 'valid' : 'invalid'; ?>">
<?php echo $is_valid ? '<span style="color: green;">✓ ' . esc_html__('Ja', 'siti-updater') . '</span>' : '<span style="color: red;">✗ ' . esc_html__('Nee', 'siti-updater') . '</span>'; ?>
</span>
</td>
<td>
<?php echo esc_html($current_version); ?>
</td>
<td>
<?php echo esc_html($latest_version); ?>
<?php if ($latest_version && '-' !== $latest_version && version_compare($latest_version, $current_version, '>')): ?>
<br><small
style="color: orange;"><?php esc_html_e('Update beschikbaar!', 'siti-updater'); ?></small>
<?php endif; ?>
</td> </td>
</tr> </tr>
<?php endforeach; ?>
</tbody>
</table> </table>
<p class="submit"> <p class="submit">
<input type="submit" name="submit" class="button button-primary" value="<?php esc_attr_e( 'Licentie opslaan', 'siti-updater' ); ?>" /> <input type="submit" name="siti_updater_save" class="button button-primary"
value="<?php esc_attr_e('Licenties opslaan', 'siti-updater'); ?>" />
</p> </p>
</form> </form>
</div> </div>

View File

@@ -1,7 +1,7 @@
{ {
"plugin_name": "SitiAI Product Teksten", "plugin_name": "SitiAI Product Teksten",
"description": "Genereer productteksten met diverse AI-aanbieders rechtstreeks vanuit WooCommerce.", "description": "Genereer productteksten met diverse AI-aanbieders rechtstreeks vanuit WooCommerce.",
"version": "1.9.2", "version": "1.10.0",
"author": "Roberto Guagliardo | SitiWeb", "author": "Roberto Guagliardo | SitiWeb",
"author_url": "https://sitiweb.nl/" "author_url": "https://sitiweb.nl/"
} }