Phase 6: WebP image conversion - Converter for Media plugin with Nginx rewrite rules

This commit is contained in:
Hanson.xyz Dev
2025-11-28 17:16:24 -06:00
parent 91de533da4
commit 78a744ef06
260 changed files with 21138 additions and 5 deletions
@@ -0,0 +1,104 @@
<?php
namespace WebpConverterVendor\MattPlugins\DeactivationModal\Model;
/**
* Stores information about the selectable reason of the plugin deactivation.
*/
class FormOption
{
/**
* @var string Key of the deactivation reason.
*/
private $key;
/**
* @var int Order priority (ascending).
*/
private $priority;
/**
* @var string Label of the reason option.
*/
private $label;
/**
* @var callable|null A function that returns a message visible after selecting the reason (may contain HTML).
*/
private $message;
/**
* @var string|null Label of additional question (visible after selecting the reason in the form).
*/
private $question;
/**
* @param string $key Key of the deactivation reason.
* @param int $priority Order priority (ascending).
* @param string $label Label of the reason option.
* @param callable|null $message A function that returns a message visible after selecting the reason (may contain
* HTML).
* @param string|null $question Label of additional question (visible after selecting the reason in the form).
*/
public function __construct(string $key, int $priority, string $label, ?callable $message = null, ?string $question = null)
{
$this->key = $key;
$this->priority = $priority;
$this->label = $label;
$this->message = $message;
$this->question = $question;
}
public function get_key() : string
{
return $this->key;
}
public function get_priority() : int
{
return $this->priority;
}
/**
* @param int $priority Order priority (ascending).
*/
public function set_priority(int $priority) : self
{
$this->priority = $priority;
return $this;
}
public function get_label() : string
{
return $this->label;
}
/**
* @param string $label Label of the reason option.
*/
public function set_label(string $label) : self
{
$this->label = $label;
return $this;
}
/**
* @return callable|null
*/
public function get_message()
{
return $this->message;
}
/**
* @param string|null $message Message visible after selecting the reason in the form (may contain HTML).
*/
public function set_message(?string $message = null) : self
{
$this->message = $message;
return $this;
}
/**
* @return string|null
*/
public function get_question()
{
return $this->question;
}
/**
* @param string|null $question Label of additional question (visible after selecting the reason in the form).
*/
public function set_question(?string $question = null) : self
{
$this->question = $question;
return $this;
}
}
@@ -0,0 +1,73 @@
<?php
namespace WebpConverterVendor\MattPlugins\DeactivationModal\Model;
use WebpConverterVendor\MattPlugins\DeactivationModal\Exception\DuplicatedFormOptionKeyException;
use WebpConverterVendor\MattPlugins\DeactivationModal\Exception\UnknownFormOptionKeyException;
/**
* Manages the list of deactivation reason in the form.
*/
class FormOptions
{
/**
* @var FormOption[]
*/
private $options = [];
/**
* @param FormOption $new_option .
*
* @throws DuplicatedFormOptionKeyException
*/
public function set_option(FormOption $new_option) : self
{
foreach ($this->options as $option) {
if ($option->get_key() === $new_option->get_key()) {
throw new DuplicatedFormOptionKeyException($new_option->get_key());
}
}
$this->options[] = $new_option;
return $this;
}
/**
* @param string $option_key .
*
* @throws UnknownFormOptionKeyException
*/
public function delete_option(string $option_key) : self
{
foreach ($this->options as $option_index => $option) {
if ($option->get_key() === $option_key) {
unset($this->options[$option_index]);
return $this;
}
}
throw new UnknownFormOptionKeyException($option_key);
}
/**
* @param string $option_key .
* @param callable $update_callback Example: "function ( FormOption $option ) { }".
*
* @throws UnknownFormOptionKeyException
*/
public function update_option(string $option_key, callable $update_callback) : self
{
foreach ($this->options as $option) {
if ($option->get_key() === $option_key) {
\call_user_func($update_callback, $option);
return $this;
}
}
throw new UnknownFormOptionKeyException($option_key);
}
/**
* @return FormOption[]
*/
public function get_options() : array
{
$options = $this->options;
\usort($options, function (FormOption $option_a, FormOption $option_b) {
return $option_a->get_priority() <=> $option_b->get_priority();
});
return $options;
}
}
@@ -0,0 +1,86 @@
<?php
namespace WebpConverterVendor\MattPlugins\DeactivationModal\Model;
/**
* Stores information about the deactivation modal template.
*/
class FormTemplate
{
/**
* @var string
*/
private $api_url;
/**
* @var string
*/
private $form_title;
/**
* @var string
*/
private $form_desc;
/**
* @var string
*/
private $button_submit_label;
/**
* @var string
*/
private $button_skip_label;
/**
* @var string|null
*/
private $notice_message;
/**
* @var string
*/
private $field_name_reason = 'request_reason';
/**
* @var string
*/
private $field_name_comment = 'request_comment_%s';
public function __construct(string $api_url, string $form_title, string $form_desc, string $button_submit_label, string $button_skip_label, ?string $notice_message = null)
{
$this->api_url = $api_url;
$this->form_title = $form_title;
$this->form_desc = $form_desc;
$this->button_submit_label = $button_submit_label;
$this->button_skip_label = $button_skip_label;
$this->notice_message = $notice_message;
}
public function get_api_url() : string
{
return $this->api_url;
}
public function get_form_title() : string
{
return $this->form_title;
}
public function get_form_desc() : string
{
return $this->form_desc;
}
public function get_button_submit_label() : string
{
return $this->button_submit_label;
}
public function get_button_skip_label() : string
{
return $this->button_skip_label;
}
/**
* @return string|null
*/
public function get_notice_message()
{
return $this->notice_message;
}
public function get_field_name_reason() : string
{
return $this->field_name_reason;
}
public function get_field_name_comment() : string
{
return $this->field_name_comment;
}
}
@@ -0,0 +1,35 @@
<?php
namespace WebpConverterVendor\MattPlugins\DeactivationModal\Model;
/**
* Stores information about the additional value sent in the request reporting plugin deactivation.
*/
class FormValue
{
/**
* @var string Key of the additional value.
*/
private $key;
/**
* @var callable A function that returns a text value.
*/
private $value_callback;
/**
* @param string $key Key of the additional value.
* @param callable $value_callback A function that returns a text value.
*/
public function __construct(string $key, callable $value_callback)
{
$this->key = $key;
$this->value_callback = $value_callback;
}
public function get_key() : string
{
return $this->key;
}
public function get_value_callback() : callable
{
return $this->value_callback;
}
}
@@ -0,0 +1,37 @@
<?php
namespace WebpConverterVendor\MattPlugins\DeactivationModal\Model;
use WebpConverterVendor\MattPlugins\DeactivationModal\Exception\DuplicatedFormValueKeyException;
/**
* It manages the list of additional information sent in the request reporting plugin deactivation.
*/
class FormValues
{
/**
* @var FormValue[]
*/
private $values = [];
/**
* @param FormValue $new_value .
*
* @throws DuplicatedFormValueKeyException
*/
public function set_value(FormValue $new_value) : self
{
foreach ($this->values as $value) {
if ($value->get_key() === $new_value->get_key()) {
throw new DuplicatedFormValueKeyException($new_value->get_key());
}
}
$this->values[] = $new_value;
return $this;
}
/**
* @return FormValue[]
*/
public function get_values() : array
{
return $this->values;
}
}
@@ -0,0 +1,75 @@
<?php
namespace WebpConverterVendor\MattPlugins\DeactivationModal\Model;
/**
* Stores information containing request data reporting plugin deactivation.
*/
class RequestData
{
/**
* @var string
*/
private $plugin_slug;
/**
* @var string|null
*/
private $reason_key = null;
/**
* @var string|null
*/
private $additional_info = null;
/**
* @var array
*/
private $additional_data = [];
/**
* @param string $plugin_slug .
*/
public function __construct(string $plugin_slug)
{
$this->plugin_slug = $plugin_slug;
}
public function get_plugin_slug() : string
{
return $this->plugin_slug;
}
public function set_reason_key(?string $reason_key = null) : self
{
$this->reason_key = $reason_key;
return $this;
}
/**
* @return string|null
*/
public function get_reason_key()
{
return $this->reason_key;
}
public function set_additional_info(?string $additional_info = null) : self
{
$this->additional_info = $additional_info;
return $this;
}
/**
* @return string|null
*/
public function get_additional_info()
{
return $this->additional_info;
}
public function set_additional_data(array $additional_data) : self
{
$this->additional_data = $additional_data;
return $this;
}
public function set_additional_data_item(string $data_key, string $data_value) : self
{
$this->additional_data[$data_key] = $data_value;
return $this;
}
public function get_additional_data() : array
{
return $this->additional_data;
}
}