name = 'speedbooster';
$this->tab = 'front_office_features';
$this->version = '1.98';
$this->author = 'DMR-Electronics';
$this->need_instance = 0;
$this->ps_versions_compliancy = ['min' => '1.6.0.4', 'max' => '1.6.1.24'];
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Speed Booster');
$this->description = $this->l('Optimaliseer de snelheid, lazy loading, responsive afbeeldingen en schone WebP conversie.');
$this->confirmUninstall = $this->l('Weet u zeker dat u de module wilt deïnstalleren? Dit kan de prestaties beïnvloeden.');
}
public function install()
{
if (!parent::install() ||
!$this->registerHook('header') ||
!Configuration::updateValue('SPEEDBOOSTER_LAZY_LOADING', 0) ||
!Configuration::updateValue('SPEEDBOOSTER_WEBP_CONVERSION', 0) ||
!Configuration::updateValue('SPEEDBOOSTER_WEBP_QUALITY', 80) ||
!Configuration::updateValue('SPEEDBOOSTER_RESPONSIVE_IMAGES', 0)
) {
return false;
}
$cache_dir = $this->getLocalPath() . 'cache/';
if (!is_dir($cache_dir)) {
mkdir($cache_dir, 0775, true);
}
return true;
}
public function uninstall()
{
if (!parent::uninstall() ||
!Configuration::deleteByName('SPEEDBOOSTER_LAZY_LOADING') ||
!Configuration::deleteByName('SPEEDBOOSTER_WEBP_CONVERSION') ||
!Configuration::deleteByName('SPEEDBOOSTER_WEBP_QUALITY') ||
!Configuration::deleteByName('SPEEDBOOSTER_RESPONSIVE_IMAGES')
) {
return false;
}
return true;
}
public function getContent()
{
$output = '';
if (Tools::isSubmit('submitSpeedBoosterSettings')) {
Configuration::updateValue('SPEEDBOOSTER_LAZY_LOADING', (int)Tools::getValue('SPEEDBOOSTER_LAZY_LOADING'));
Configuration::updateValue('SPEEDBOOSTER_WEBP_CONVERSION', (int)Tools::getValue('SPEEDBOOSTER_WEBP_CONVERSION'));
Configuration::updateValue('SPEEDBOOSTER_WEBP_QUALITY', (int)Tools::getValue('SPEEDBOOSTER_WEBP_QUALITY'));
Configuration::updateValue('SPEEDBOOSTER_RESPONSIVE_IMAGES', (int)Tools::getValue('SPEEDBOOSTER_RESPONSIVE_IMAGES'));
$output .= $this->displayConfirmation($this->l('Instellingen bijgewerkt'));
}
$redirects_result = '';
if (Tools::isSubmit('submitRedirectsCheck')) {
$url = Tools::getValue('url_to_check');
if (!empty($url) && Validate::isUrl($url)) {
$redirects_result = $this->_checkRedirects($url);
} else {
$output .= $this->displayError($this->l('Ongeldige URL.'));
}
}
$bulk_conversion_result = '';
if (Tools::isSubmit('submitBulkConvert')) {
$bulk_conversion_result = $this->_bulkConvertImages();
$output .= $this->displayConfirmation($bulk_conversion_result);
}
return $output
. $this->displayForm()
. $this->displayRedirectsForm($redirects_result)
. $this->displayBulkConverterForm();
}
public function displayForm()
{
$fields_form = [
'form' => [
'legend' => [
'title' => $this->l('Instellingen'),
'icon' => 'icon-cogs'
],
'input' => [
[
'type' => 'switch',
'label' => $this->l('Lazy Loading inschakelen'),
'name' => 'SPEEDBOOSTER_LAZY_LOADING',
'is_bool' => true,
'values' => [
['id' => 'lazy_on', 'value' => 1, 'label' => $this->l('Ja')],
['id' => 'lazy_off', 'value' => 0, 'label' => $this->l('Nee')]
],
'hint' => $this->l('Afbeeldingen worden pas geladen als ze in zicht komen.'),
],
[
'type' => 'switch',
'label' => $this->l('WebP conversie inschakelen'),
'name' => 'SPEEDBOOSTER_WEBP_CONVERSION',
'is_bool' => true,
'values' => [
['id' => 'webp_on', 'value' => 1, 'label' => $this->l('Ja')],
['id' => 'webp_off', 'value' => 0, 'label' => $this->l('Nee')]
],
'hint' => $this->l('Converteert afbeeldingen naar WebP met schone extensies.'),
],
[
'type' => 'text',
'label' => $this->l('WebP Kwaliteit'),
'name' => 'SPEEDBOOSTER_WEBP_QUALITY',
'class' => 'fixed-width-sm',
'hint' => $this->l('Kwaliteit voor WebP (0-100).'),
],
[
'type' => 'switch',
'label' => $this->l('Responsive afbeeldingen inschakelen'),
'name' => 'SPEEDBOOSTER_RESPONSIVE_IMAGES',
'is_bool' => true,
'values' => [
['id' => 'responsive_on', 'value' => 1, 'label' => $this->l('Ja')],
['id' => 'responsive_off', 'value' => 0, 'label' => $this->l('Nee')]
],
'hint' => $this->l('Afbeeldingen automatisch schaalbaar maken met srcset en CSS.'),
],
],
'submit' => [
'title' => $this->l('Opslaan'),
'class' => 'btn btn-default pull-right'
]
],
];
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitSpeedBoosterSettings';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
.'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = [
'fields_value' => $this->getConfigFormValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
];
return $helper->generateForm([$fields_form]);
}
public function getConfigFormValues()
{
return [
'SPEEDBOOSTER_LAZY_LOADING' => Configuration::get('SPEEDBOOSTER_LAZY_LOADING'),
'SPEEDBOOSTER_WEBP_CONVERSION' => Configuration::get('SPEEDBOOSTER_WEBP_CONVERSION'),
'SPEEDBOOSTER_WEBP_QUALITY' => Configuration::get('SPEEDBOOSTER_WEBP_QUALITY'),
'SPEEDBOOSTER_RESPONSIVE_IMAGES' => Configuration::get('SPEEDBOOSTER_RESPONSIVE_IMAGES'),
];
}
public function displayRedirectsForm($result = '')
{
$token = Tools::getAdminTokenLite('AdminModules');
$html = '
' . $this->l('Redirects controleren') . '
';
if (!empty($result)) {
$html .= '
' . $this->l('Resultaat:') . ' ' . nl2br(htmlspecialchars($result)) . ' ';
}
$html .= '
';
return $html;
}
public function displayBulkConverterForm()
{
$token = Tools::getAdminTokenLite('AdminModules');
$html = '
' . $this->l('Bulk WebP Conversie (Schone Extensies)') . '
';
return $html;
}
protected function _checkRedirects($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$header = curl_exec($ch);
$info = curl_getinfo($ch);
if (curl_errno($ch)) return $this->l('Fout tijdens cURL-verzoek: ') . curl_error($ch);
curl_close($ch);
$redirect_chain = "Start URL: $url\nEind URL: ".$info['url']."\nHTTP Code: ".$info['http_code']."\nTotaal aantal omleidingen: ".$info['redirect_count']."\n\n";
$headers = explode("\n", str_replace("\r", "", $header));
foreach ($headers as $line) {
if (preg_match('/^Location: (.*)$/i', $line, $matches)) {
$redirect_chain .= "Omleiding gevonden: ".trim($matches[1])."\n";
}
}
return $redirect_chain;
}
protected function _bulkConvertImages()
{
if (!function_exists('imagewebp')) return $this->l('PHP GD-bibliotheek met WebP-ondersteuning is niet geïnstalleerd.');
$paths = [_PS_IMG_DIR_.'p/', _PS_IMG_DIR_.'c/', _PS_IMG_DIR_.'cms/'];
$success_count = 0; $fail_count = 0;
foreach ($paths as $path) {
if (!is_dir($path)) continue;
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
foreach ($files as $file) {
if ($file->getFilename() === '.' || $file->getFilename() === '..') continue;
$ext = strtolower(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
if (in_array($ext, ['jpg','jpeg','png'])) {
$source = $file->getRealPath();
// Schone conversie: vervang .jpg/.png door .webp
$webp = preg_replace('/\.(jpe?g|png)$/i', '.webp', $source);
if (!file_exists($webp)) {
if ($this->_createWebp($source, $webp)) {
$success_count++;
} else {
$fail_count++;
}
}
}
}
}
return $this->l('Conversie voltooid. Succes: ').$success_count.$this->l(', Mislukt: ').$fail_count;
}
protected function _createWebp($source, $destination)
{
if (!function_exists('imagewebp')) return false;
$quality = max(0, min(100, (int)Configuration::get('SPEEDBOOSTER_WEBP_QUALITY')));
$info = @getimagesize($source);
if ($info === false) return false;
$image = null;
switch($info['mime']){
case 'image/jpeg':
if (function_exists('imagecreatefromjpeg')) {
$image = @imagecreatefromjpeg($source);
}
break;
case 'image/png':
if (function_exists('imagecreatefrompng')) {
$image = @imagecreatefrompng($source);
if ($image) {
imagealphablending($image, false);
imagesavealpha($image, true);
}
}
break;
default: return false;
}
if (!$image) return false;
$result = imagewebp($image, $destination, $quality);
imagedestroy($image);
return $result;
}
public function _processHtml($buffer)
{
// 1. WebP conversie van image URLs in de HTML (schone .webp extensie)
if ((bool)Configuration::get('SPEEDBOOSTER_WEBP_CONVERSION')) {
$buffer = preg_replace_callback('/ ]+)src=["\']([^"\']+\.(jpe?g|png))["\']([^>]*)>/i', function($matches) {
$before = $matches[1];
$src = $matches[2];
$after = $matches[4];
$webpSrc = preg_replace('/\.(jpe?g|png)$/i', '.webp', $src);
return ' ';
}, $buffer);
}
// 2. Lazy Loading
if ((bool)Configuration::get('SPEEDBOOSTER_LAZY_LOADING')) {
$buffer = preg_replace_callback('/ ]+)>/i', function($matches){
$img = $matches[0];
$isBigPic = (strpos($img, 'id="bigpic"') !== false || strpos($img, "id='bigpic'") !== false);
if ($isBigPic) {
$img = preg_replace('/loading=["\']lazy["\']/i', '', $img);
if (strpos($img, 'fetchpriority=') === false) {
return str_replace(' ]+)src="([^"]+)"([^>]*)>/i', function($matches){
$before = $matches[1];
$src = $matches[2];
$after = $matches[3];
if (strpos($before.$after, 'srcset=') !== false) {
return $matches[0];
}
$srcset = $src.' 1x, '.$src.' 2x';
$sizes = '(max-width: 768px) 100vw, 768px';
return ' ';
}, $buffer);
}
return $buffer;
}
public function hookHeader()
{
if (isset($this->context->controller->controller_type) && $this->context->controller->controller_type == 'admin') {
return '';
}
if (Tools::isSubmit('ajax') ||
(isset($this->context->controller->ajax) && $this->context->controller->ajax) ||
(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
) {
return '';
}
// Voorkom activering op kassa- en inlogpagina's
if (isset($this->context->controller->php_self) &&
in_array($this->context->controller->php_self, ['order', 'order-opc', 'authentication', 'cart'])
) {
return '';
}
$output = '';
// Automatische LCP preload toevoegen voor categorie achtergrondafbeeldingen
if (isset($this->context->controller->php_self) && $this->context->controller->php_self == 'category') {
$id_category = (int)Tools::getValue('id_category');
if ($id_category) {
$category = new Category($id_category, (int)$this->context->language->id);
if (Validate::isLoadedObject($category) && $category->id_image) {
$categoryImg = $this->context->link->getCatImageLink($category->link_rewrite, $category->id_image, 'category_default');
if ($categoryImg) {
$output .= ' ' . "\n";
}
}
}
}
if ((bool)Configuration::get('SPEEDBOOSTER_LAZY_LOADING') || (bool)Configuration::get('SPEEDBOOSTER_RESPONSIVE_IMAGES') || (bool)Configuration::get('SPEEDBOOSTER_WEBP_CONVERSION')) {
ob_start([$this, '_processHtml']);
}
if ((bool)Configuration::get('SPEEDBOOSTER_RESPONSIVE_IMAGES')) {
$this->context->controller->addCSS($this->_path.'views/css/speedbooster.css');
}
if ((bool)Configuration::get('SPEEDBOOSTER_LAZY_LOADING')) {
$this->context->controller$this->context->controller->addJS($this->_path.'views/js/speedbooster-lazy.js');
}
return $output;
}
}
Connettore BNC-maschio RG 58 - 10 pezzi in offerta
Connettore a saldare BNC-maschio. Morsetto RG 58 (10 pezzi)
Visualizza ingrandito
Connettore a saldare BNC-maschio. Morsetto RG 58 (Prezzo per 10 pezzi)
30 altri prodotti nella categoria - Connettori Coassiali
Informazioni sul prodotto
Connettore a saldare BNC-maschio. Morsetto RG 58 (Prezzo per 10 pezzi)