Skip to content

Commit

Permalink
1.2.6
Browse files Browse the repository at this point in the history
Don't display Menu_Item_Root in menus list
Inline help in filter subform
WebP Directory : adjust delete images button size
Add more description to plugin's parameters
Debug : add extension/excluded/menu/error values to [new] line
  • Loading branch information
conseilgouz committed Aug 8, 2024
1 parent 02bb180 commit aeaccd9
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 37 deletions.
28 changes: 12 additions & 16 deletions cgwebp.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<extension type="plugin" version="4.0" group="system" method="upgrade">
<name>System - CG Webp</name>
<creationDate>2024-08-07</creationDate>
<creationDate>2024-08-08</creationDate>
<author>ConseilGouz</author>
<copyright>Copyright (C) 2024 ConseilGouz. All rights reserved.</copyright>
<license>GNU/GPL</license>
<authorEmail>pascal.leconte@conseilgouz.com</authorEmail>
<authorUrl>https://www.conseilgouz.com</authorUrl>
<version>1.2.5</version>
<version>1.2.6</version>
<description>PLG_SYSTEM_CGWEBP_DESCRIPTION</description>
<namespace path="src">Conseilgouz\Plugin\System\Cgwebp</namespace>
<scriptfile>script.cgwebp.php</scriptfile>
Expand All @@ -31,34 +31,30 @@
<fields name="params">
<fieldset name="basic" addfieldprefix="Conseilgouz\Plugin\System\Cgwebp\Field">
<field name="version" type="version" margintop="-3em" extension="cgwebp" />
<field
name="filters" type="subform" icon="list"
label="PLG_SYSTEM_CGWEBP_FILTERS" multiple="true"
default=""
<field name="filters" type="subform" icon="list"
label="PLG_SYSTEM_CGWEBP_FILTERS"
multiple="true" default=""
formsource="plugins/system/cgwebp/filters.xml"
/>
<field
name="excludedMenus"
type="cgmenuitems"
label="PLG_SYSTEM_CGWEBP_EXCLUDED_MENUS"
multiple="true"
layout="joomla.form.field.list-fancy-select"
filter="intarray"
<field name="excludedMenus" type="cgmenuitems"
label="PLG_SYSTEM_CGWEBP_EXCLUDED_MENUS" description="PLG_SYSTEM_CGWEBP_EXCLUDED_MENUS_DESC"
multiple="true" layout="joomla.form.field.list-fancy-select" filter="intarray"
/>
<field name="webp_support" type="webpsupport"/>
<field name="storage" type="radio" default="same"
label="PLG_SYSTEM_CGWEBP_STORAGE" description="PLG_SYSTEM_CGWEBP_STORAGE_DESC"
class="btn-group btn-group-yesno half left">
class="btn-group btn-group-yesno sixty left">
<option value="same">PLG_SYSTEM_CGWEBP_STORAGE_SAME</option>
<option value="media">PLG_SYSTEM_CGWEBP_STORAGE_MEDIA</option>
</field>
<field name="webp_destroy" type="webpdestroy"/>
<field name="debug" type="radio" default="0" label="PLG_SYSTEM_CGWEBP_DEBUG"
<field name="debug" type="radio" default="0"
label="PLG_SYSTEM_CGWEBP_DEBUG" description="PLG_SYSTEM_CGWEBP_DEBUG_DESC"
class="btn-group btn-group-yesno clear">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="mode" type="hidden" default="" label="PLG_SYSTEM_CGWEBP_MODE">
<field name="mode" type="hidden" default="" label="PLG_SYSTEM_CGWEBP_MODE" >
</field>
</fieldset>
</fields>
Expand Down
15 changes: 9 additions & 6 deletions filters.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<config>
<inlinehelp button="show"/>
</config>
<field name="directory"
label="PLG_SYSTEM_CGWEBP_DIRECTORY"
type="text" required="required"/>
label="PLG_SYSTEM_CGWEBP_DIRECTORY" description="PLG_SYSTEM_CGWEBP_DIRECTORY_DESC"
type="text" required="required" />
<field name="extensions" label="PLG_SYSTEM_CGWEBP_EXTENSIONS" type="checkboxes" required="required">
<option value="jpg|jpeg|JPG|JPEG">JPG/JPEG</option>
<option value="png|PNG">PNG</option>
</field>
<field name="quality" type="integer" label="PLG_SYSTEM_CGWEBP_QUALITY" first="1" last="100"
default="100" step="1" required="required" />
<field name="quality" type="integer"
label="PLG_SYSTEM_CGWEBP_QUALITY" description="PLG_SYSTEM_CGWEBP_QUALITY_DESC"
first="1" last="100" default="60" step="1" required="required" />
<field name="stored_time" type="hidden" label="PLG_SYSTEM_CGWEBP_STORED_TIME"
description="PLG_SYSTEM_CGWEBP_STORED_TIME_DESC" default="0"
step="1"/>
description="PLG_SYSTEM_CGWEBP_STORED_TIME_DESC" />
<field name="excluded" type="textarea" default="" label="PLG_SYSTEM_CGWEBP_EXCLUDES"
description="PLG_SYSTEM_CGWEBP_EXCLUDES_DESC" rows="3" cols="20" filter="raw"/>
</form>
7 changes: 6 additions & 1 deletion language/en-GB/plg_system_cgwebp.sys.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ PLG_SYSTEM_CGWEBP="CG WebP - convert images to WEBP"
PLG_SYSTEM_CGWEBP_DESCRIPTION="<script src='../media/plg_system_cgwebp/js/cgwebp.js'></script>CG WebP plugin helps you optimize your page load by displaying WebP images instead of your images.<br>When a page is displayed, all images from defined formats are converted to WEBP format and stored either in original images directory or in media/plg_system_cgwebp/_cache directory.<br>Storing webp images in media directory is recommended, all WebP images being at the same place will be easier to remove.<br><b>Important</b> : if media option, generated webp images will be removed when de-installing this plugin.<br>Check CG Webp plugin parameters and, if in use, disable DJ WebP plugin."
PLG_SYSTEM_CGWEBP_FILTERS="Filters"
PLG_SYSTEM_CGWEBP_DIRECTORY="Directory"
PLG_SYSTEM_CGWEBP_DIRECTORY_DESC="Enter images directory to convert to WebP format (default value = images)."

PLG_SYSTEM_CGWEBP_EXTENSIONS="Images type"
PLG_SYSTEM_CGWEBP_QUALITY="Quality"
PLG_SYSTEM_CGWEBP_QUALITY_DESC="Define converted images quality in percentage. The higher quality is (maxi : 100), the bigger image size will be (default = 60)."
PLG_SYSTEM_CGWEBP_DEBUG="Debug"
PLG_SYSTEM_CGWEBP_DEBUG_DESC="Activate or not plugin's debug mode.<br>This shows images conversion result, it also show why some images were not converted (already done, parameter, error...)"

PLG_SYSTEM_CGWEBP_MENU_ITEMS_PLACEHOLDER="Select excluded menu items"
PLG_SYSTEM_CGWEBP_MENU_ITEM_PLACEHOLDER="Select excluded menu item"
PLG_SYSTEM_CGWEBP_EXCLUDED_MENUS="Excludes menus"
PLG_SYSTEM_CGWEBP_EXCLUDED_MENUS_DESC="WebP conversion process may be disabled for some menus. Select those menus from the list."
PLG_SYSTEM_CGWEBP_MENU_ITEMS_PLEASE_SELECT="Please select menu items"
PLG_SYSTEM_CGWEBP_MENU_ITEMS_NONE="None"
PLG_SYSTEM_CGWEBP_EXCLUDES="Excluded files/directory"
PLG_SYSTEM_CGWEBP_EXCLUDES_DESC="List of elements which should be excluded from webp compression. Separated by ;"
PLG_SYSTEM_CGWEBP_EXCLUDES_DESC="List of elements which should be excluded from webp format conversion. Elements must be semilcolon separated (;)."

PLG_SYSTEM_CGWEBP_SUPPORT_TABLE="Check WebP support"
PLG_SYSTEM_CGWEBP_SUPPORT_ENDPOINT="Endpoint"
Expand Down
9 changes: 7 additions & 2 deletions language/fr-FR/plg_system_cgwebp.sys.ini
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
PLG_SYSTEM_CGWEBP="CG WebP - conversion des images en WEBP"
PLG_SYSTEM_CGWEBP_DESCRIPTION="<script src='../media/plg_system_cgwebp/js/cgwebp.js'></script>Le plugin CG WebP optimise le chargement de vos pages en affichant des images WebP à la place de vos images jpg/png.<br>Quand une page est affichée, toutes les images jpg/png sont convertis en WEBP et stockées soit dans le même répertoire que l'image original, soit dans le répertoire media/plg_system_cgwebp/_cache.<br>L'utilisation du répertoire media est recommandée, les images WebP générées devenant faciles à retrouver.<br><br><b>Important</b> : si l'option media est utilisée, les images webp générées par ce plugin seront supprimées lors de la désintallation du plugin.<br><br>N'oubliez pas de vérifier les paramètres du plugin CG Webp et, si vous utilisiez le plugin DJ Webp, n'oubliez pas de le désactiver."
PLG_SYSTEM_CGWEBP_DESCRIPTION="<script src='../media/plg_system_cgwebp/js/cgwebp.js'></script>Le plugin CG WebP optimise le chargement de vos pages en affichant des images WebP à la place de vos images jpg/png.<br>Quand une page est affichée, toutes les images jpg/png sont convertis en WEBP et stockées soit dans le même répertoire que l'image original, soit dans le répertoire media/plg_system_cgwebp/_cache.<br>L'utilisation du répertoire media est recommandée, les images WebP générées devenant faciles à retrouver.<br><br><b>Important</b> : si l'option media est utilisée, les images webp générées par ce plugin seront supprimées lors de la désinstallation du plugin.<br><br>N'oubliez pas de vérifier les paramètres du plugin CG Webp et, si vous utilisiez le plugin DJ Webp, n'oubliez pas de le désactiver."
PLG_SYSTEM_CGWEBP_FILTERS="Filtres"
PLG_SYSTEM_CGWEBP_DIRECTORY="Répertoire"
PLG_SYSTEM_CGWEBP_DIRECTORY_DESC="Répertoire des images à convertir au format WebP (par défaut = images)."

PLG_SYSTEM_CGWEBP_EXTENSIONS="Types image"
PLG_SYSTEM_CGWEBP_QUALITY="Qualité"
PLG_SYSTEM_CGWEBP_QUALITY_DESC="Définir la qualité de l'image après conversion, en pourcentage. Plus la qualité est haute (maxi : 100), plus la taille de l'image est importante (défaut = 60)."
PLG_SYSTEM_CGWEBP_DEBUG="Debug"
PLG_SYSTEM_CGWEBP_DEBUG_DESC="Activer ou non le mode debug du plugin.<br>Ce mode permet de suivre la conversion des images, ainsi que d'avoir la raison de non conversion d'images (déjà converti, paramétrage, erreur...)"

PLG_SYSTEM_CGWEBP_MENU_ITEMS_PLACEHOLDER="Selection des menus à exclure"
PLG_SYSTEM_CGWEBP_MENU_ITEM_PLACEHOLDER="Selection du menu exclu"
PLG_SYSTEM_CGWEBP_EXCLUDED_MENUS="Menus exclus"
PLG_SYSTEM_CGWEBP_EXCLUDED_MENUS_DESC="La conversion d'images au format WebP peut être désactivée pour certains menus. Sélectionner ces menus dans la liste des menus disponibles."
PLG_SYSTEM_CGWEBP_MENU_ITEMS_PLEASE_SELECT="Selectionnez un/des menu(s)"
PLG_SYSTEM_CGWEBP_MENU_ITEMS_NONE="Aucun"
PLG_SYSTEM_CGWEBP_EXCLUDES="Fichiers/répertoire à exclure"
PLG_SYSTEM_CGWEBP_EXCLUDES_DESC="Liste des éléments à exclure de la compression WebP, séparés par ;"
PLG_SYSTEM_CGWEBP_EXCLUDES_DESC="Liste des éléments à exclure de la conversion au format WebP. Les éléments doivent être séparés par un point-virgule (;)."

PLG_SYSTEM_CGWEBP_SUPPORT_TABLE="Check WebP support"
PLG_SYSTEM_CGWEBP_SUPPORT_ENDPOINT="Endpoint"
Expand Down
2 changes: 1 addition & 1 deletion layouts/webp_destroy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Joomla\CMS\Language\Text;

?>
<button class="btn btn-primary" type="button" id="webpdestroy" >
<button class="btn btn-primary" type="button" id="webpdestroy" style="float:right;width:40%">
<?php echo Text::_('PLG_SYSTEM_CGWEBP_DESTROY'); ?>
</button>
<div id="destroy_message" aria-live="polite"></div>
6 changes: 5 additions & 1 deletion media/js/cgwebp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* @version 1.1.2
* @package CGWebp system plugin
* @author ConseilGouz
* @copyright Copyright (C) 2024 ConseilGouz. All rights reserved.
Expand Down Expand Up @@ -31,6 +30,11 @@ document.addEventListener("DOMContentLoaded", function(){
let half = halfs[i];
group = half.parentNode.parentNode.parentNode.style.width = "50%";
}
halfs = document.querySelectorAll('.view-plugin .sixty');
for(var i=0; i< halfs.length; i++) {
let half = halfs[i];
group = half.parentNode.parentNode.parentNode.style.width = "60%";
}

// show/hide button depending on Storage value
storageMedia = document.querySelector('#jform_params_storage1');
Expand Down
18 changes: 18 additions & 0 deletions plg_system_cgwebp_changelog.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<changelogs>
<changelog>
<element>plg_system_cgwebp</element>
<type>plugin</type>
<group>system</group>
<version>1.2.6</version>
<note>
<item>Update : 08/08/2024</item>
</note>
<fix>
<item>Don't display Menu_Item_Root in menus list</item>
<item>Inline help in filter subform</item>
<item>WebP Directory : adjust delete images button size</item>
</fix>
<addition>
<item>Add more description to plugin's parameters</item>
<item>Debug : add extension/excluded/menu/error values to [new] line</item>
</addition>
</changelog>
<changelog>
<element>plg_system_cgwebp</element>
<type>plugin</type>
Expand Down
20 changes: 12 additions & 8 deletions src/Extension/Cgwebp.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
/**
* @version 1.2.5
* @package CGWebp system plugin
* @author ConseilGouz
* @copyright Copyright (C) 2024 ConseilGouz. All rights reserved.
Expand Down Expand Up @@ -107,12 +106,17 @@ private function gowebp($sHtml, $onefilter)
'/' . $regexPath . '\/.*?(' . implode('|', $extensions) . ')(?=[\'"?#])|#joomlaImage.*?(' . implode('|', $extensions) . ').+?(?=\")\b/',
function ($match) use ($quality, $stored_time, $excludedArr, &$debugTarget, $regexPath) {
$img = $match[0];
$newImg = $this->imgToWebp($img, $quality, $excludedArr, $stored_time, $regexPath, $match,$debugTarget);
$newImg = $this->imgToWebp($img, $quality, $excludedArr, $stored_time, $regexPath, $match, $debugTarget);
$new = 'false';
if (in_array($newImg,['extension','excluded','ignored','error'])) {
$new = $newImg;
$newImg = false;
}
if (!$newImg) { // no conversion
$debugTarget[] = array(
'source' => $image,
'source' => $img,
'target' => $newImg,
'new' => 'false'
'new' => $new
);
}
return $newImg ? $newImg : $img;
Expand Down Expand Up @@ -158,16 +162,16 @@ private function imgToWebp($image, $quality = 100, $excluded = array(), $stored_
$bNew = 'false';

if(!isset($imgInfo['extension']) || !$imgInfo['extension']) {
return;
return 'extension';
}

if(count($excluded)) {
if(in_array($image, $excluded) || $this->isExcludedDirectory($image, $excluded)) {
return;
return 'excluded';
}
}
if (str_starts_with($image, '#')) { // media manager image part : ignore it
return;
return 'ignored';
}
if(is_file($imgPath)) {
if (!isset($this->_webps[$imgHash])) {
Expand Down Expand Up @@ -206,7 +210,7 @@ private function imgToWebp($image, $quality = 100, $excluded = array(), $stored_
imagewebp($img, $newImage, $quality);
$bNew = 'true';
} catch (\Throwable $throwable) {
return false; // conversion error :ignore image
return 'error'; // conversion error :ignore image
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Field/CgmenuitemsField.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
/**
* @version 1.2.0
* @package CGWebp system plugin
* @author ConseilGouz
* @copyright Copyright (C) 2024 ConseilGouz. All rights reserved.
Expand Down Expand Up @@ -64,7 +63,8 @@ protected function getOptions()
->select('m.id AS value, m.title AS text')
->from($db->quoteName('#__menu', 'm'))
->where('m.menutype <> ' . $db->quote('main'))
->where('m.published = 1');
->where('m.published = 1')
->where('m.id > 1');

$db->setQuery($query);
static::$options = $db->loadObjectList();
Expand Down

0 comments on commit aeaccd9

Please sign in to comment.