Add X13 WebP module for image conversion to next-generation formats

- Implemented the main module class with essential properties and methods.
- Added translation support for various user interface strings.
- Created XML configuration file for module versioning.
- Ensured compatibility with different PHP versions and PrestaShop versions.
This commit is contained in:
2025-10-16 21:30:24 +02:00
parent d220e35c31
commit 3b29a79921
235 changed files with 40220 additions and 189 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace WebPConvert\Loggers;
/**
* Base for all logger classes.
*
* WebPConvert can provide insights into the conversion process by means of accepting a logger which
* extends this class.
*
* @package WebPConvert
* @author Bjørn Rosell <it@rosell.dk>
* @since Class available since Release 2.0.0
*/
abstract class BaseLogger
{
/**
* Write a message to the log
*
* @param string $msg message to log
* @param string $style style (null | bold | italic)
* @return void
*/
abstract public function log($msg, $style = '');
/**
* Add new line to the log
* @return void
*/
abstract public function ln();
/**
* Write a line to the log
*
* @param string $msg message to log
* @param string $style style (null | bold | italic)
* @return void
*/
public function logLn($msg, $style = '')
{
$this->log($msg, $style);
$this->ln();
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace WebPConvert\Loggers;
use WebPConvert\Loggers\BaseLogger;
/**
* Collect the logging and retrieve it later in HTML or plain text format.
*
* @package WebPConvert
* @author Bjørn Rosell <it@rosell.dk>
* @since Class available since Release 2.0.0
*/
class BufferLogger extends BaseLogger
{
public $entries = array();
/**
* Write a message to the buffer - all entries can later be retrieved with getText() or getHtlm().
*
* @param string $msg message to log
* @param string $style style (null | bold | italic)
* @return void
*/
public function log($msg, $style = '')
{
$this->entries[] = [$msg, $style];
}
/**
* Write a new line to the buffer.
*
* @return void
*/
public function ln()
{
$this->entries[] = '';
}
/**
* Get everything logged - as HTML.
*
* @return string The log, formatted as HTML.
*/
public function getHtml()
{
$html = '';
foreach ($this->entries as $entry) {
if ($entry == '') {
$html .= '<br>';
} else {
list($msg, $style) = $entry;
$msg = htmlspecialchars($msg);
if ($style == 'bold') {
$html .= '<b>' . $msg . '</b>';
} elseif ($style == 'italic') {
$html .= '<i>' . $msg . '</i>';
} else {
$html .= $msg;
}
}
}
return $html;
}
/**
* Get everything logged - as markdown.
*
* @return string The log, formatted as MarkDown.
*/
public function getMarkDown($newLineChar = "\n\r")
{
$md = '';
foreach ($this->entries as $entry) {
if ($entry == '') {
$md .= $newLineChar;
} else {
list($msg, $style) = $entry;
if ($style == 'bold') {
$md .= '**' . $msg . '** ';
} elseif ($style == 'italic') {
$md .= '*' . $msg . '* ';
} else {
$md .= $msg;
}
}
}
return $md;
}
/**
* Get everything logged - as plain text.
*
* @param string $newLineChar. The character used for new lines.
* @return string The log, formatted as plain text.
*/
public function getText($newLineChar = ' ')
{
$text = '';
foreach ($this->entries as $entry) {
if ($entry == '') { // empty string means new line
if (substr($text, -2) != '.' . $newLineChar) {
$text .= '.' . $newLineChar;
}
} else {
list($msg, $style) = $entry;
$text .= $msg;
}
}
return $text;
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace WebPConvert\Loggers;
/**
* Echo the logs immediately (in HTML)
*
* @package WebPConvert
* @author Bjørn Rosell <it@rosell.dk>
* @since Class available since Release 2.0.0
*/
class EchoLogger extends BaseLogger
{
/**
* Handle log() by echoing the message.
*
* @param string $msg message to log
* @param string $style style (null | bold | italic)
* @return void
*/
public function log($msg, $style = '')
{
$msg = htmlspecialchars($msg);
if ($style == 'bold') {
echo '<b>' . $msg . '</b>';
} elseif ($style == 'italic') {
echo '<i>' . $msg . '</i>';
} else {
echo $msg;
}
}
/**
* Handle ln by echoing a <br> tag.
*
* @return void
*/
public function ln()
{
echo '<br>';
}
}