Skip to content

Commit

Permalink
Version 5.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed Oct 10, 2022
1 parent 9cb27a0 commit 72caa8d
Show file tree
Hide file tree
Showing 45 changed files with 526 additions and 615 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For more information, go to https://www.luigifab.fr/openmage/maillog (IPv6 is re

This repository is a releases mirror. To install the module, please use the composer key available in the documentation.

- Current version: 5.5.0 (08/08/2022)
- Current version: 5.6.0 (10/10/2022)
- Compatibility: OpenMage 19.x / 20.x / 21.x, PHP 7.2 / 7.3 / 7.4 / 8.0 / 8.1
- Client compatibility: Firefox 36+, Chrome 32+, Opera 19+, Edge 16+, Safari 9+
- Translations: English (en), French (fr-FR/fr-CA), German (de), Italian (it), Portuguese (pt-PT/pt-BR), Spanish (es) / Chinese (zh), Czech (cs), Dutch (nl), Greek (el), Hungarian (hu), Japanese (ja), Polish (pl), Romanian (ro), Russian (ru), Slovak (sk), Turkish (tr), Ukrainian (uk)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created S/26/10/2019
* Updated S/19/02/2022
* Updated D/04/09/2022
*
* Copyright 2015-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2015-2016 | Fabrice Creuzot <fabrice.creuzot~label-park~com>
Expand All @@ -25,7 +25,7 @@ class Luigifab_Maillog_Block_Adminhtml_Config_Comment extends Mage_Adminhtml_Blo
protected function _getHeaderCommentHtml($element) {

$comment = $element->getComment();
if (empty($comment))
if (empty($comment) && (stripos($element->getHtmlId(), 'maillog_sync_') !== false))
return '<img src="'.$this->getSkinUrl('images/luigifab/maillog/logo-'.str_replace('maillog_sync_', '', $element->getId()).'.svg').'" alt="" class="maillog logo" />';

if (stripos($element->getHtmlId(), 'sync') !== false)
Expand All @@ -35,6 +35,8 @@ protected function _getHeaderCommentHtml($element) {
'myvar1' => [['numb' => -2, 'text' => 'hello'], ['numb' => 0, 'text' => 'hello'], ['numb' => 2, 'text' => 'hello']],
'myvar2' => ['str1', 'str2'],
];

// debug + exemple en même temps
foreach ($vars['myvar1'] as $i => $n) {
$t = $n['text'];
$n = $n['numb'];
Expand Down Expand Up @@ -66,31 +68,37 @@ protected function _getHeaderCommentHtml($element) {
$vars['myvar1'][$i]['v'] = (mb_stripos($t, '777') === false) ? 'true' : 'false';
$vars['myvar1'][$i]['w'] = (mb_stripos($t, $t) !== false) ? 'true' : 'false';
$vars['myvar1'][$i]['x'] = (mb_stripos($t, $t) === false) ? 'true' : 'false';
$vars['myvar1'][$i]['na'] = (($n > 0) && ($n > -2)) ? 'true' : 'false';
$vars['myvar1'][$i]['nb'] = (($n < 0) && ($n < -2)) ? 'true' : 'false';
$vars['myvar1'][$i]['nc'] = (($n < 0) || ($n < -2)) ? 'true' : 'false';
$vars['myvar1'][$i]['nd'] = (($n > 0) || ($n > -2)) ? 'true' : 'false';
}

return implode("\n", [
'<div class="comment maillog">',
'<p>'.$comment.'</p>',
'<ul lang="en">',
'<li>{{foreach something}} ... {{forelse}} ... {{/foreach}}</li>',
'<li>{{if something gt/gte/gteq/lt/lte/lteq/eq/neq something/empty}} ... {{elseif ...}} ... {{else}} ... {{/if}}</li>',
'<li>{{if something in/nin a,b,c,1,2,3}} ... {{elseif ...}} ... {{else}} ... {{/if}} (in_array)</li>',
'<li>{{if something ct/nct something}} ... {{elseif ...}} ... {{else}} ... {{/if}} (contains)</li>',
'<li>{{ifconfig path="a/b/c"}} ... {{elseconfig}} ... {{/ifconfig}}</li>',
'<li>{{helper action="xx/yy::zz"}} | {{helper action="xx/yy::zz" param="abc" marap=$something ifconfig="a/b/c"}}</li>',
'<li>{{number something}} | {{number path="a/b/c" nodecimal="true" ifconfig="a/b/c"}}</li>',
'<li>{{price something}} | {{price path="a/b/c" nodecimal="true" currency="xyz" store="i" product="i" ifconfig="a/b/c"}}</li>',
'<li>{{currency code="xyz"}} | {{currency path="a/b/c" store="i" ifconfig="a/b/c"}}</li>',
'<li>{{include template="xyz.html"}} | {{include template="xyz.html" ifconfig="a/b/c"}}</li>',
'<li>{{dump something}} | {{dump}}</li>',
'<li>{{picture ...}}</li>',
'<li><code>{{foreach something}} ... {{forelse}} ... {{/foreach}}</code></li>',
'<li><code>{{if something gt/gte/gteq/lt/lte/lteq/eq/neq something/empty}} ... {{elseif ...}} ... {{else}} ... {{/if}}</code></li>',
'<li><code>{{if something in/nin a,b,c,1,2,3}} ... {{elseif ...}} ... {{else}} ... {{/if}} (in_array)</code></li>',
'<li><code>{{if something ct/nct something}} ... {{elseif ...}} ... {{else}} ... {{/if}} (contains)</code></li>',
'<li><code>⭐ {{if something operator something && something operator something ...}} (only " && ")</code></li>',
'<li><code>⭐ {{if something operator something || something operator something ...}} (only " || ")</code></li>',
'<li><code>{{ifconfig path="a/b/c"}} ... {{elseconfig}} ... {{/ifconfig}}</code></li>',
'<li><code>{{helper action="xx/yy::zz"}} | {{helper action="xx/yy::zz" param="abc" marap=$something ifconfig="a/b/c"}}</code></li>',
'<li><code>{{number something}} | {{number path="a/b/c" nodecimal="true" ifconfig="a/b/c"}}</code></li>',
'<li><code>{{price something}} | {{price path="a/b/c" nodecimal="true" currency="xyz" store="i" product="i" ifconfig="a/b/c"}}</code></li>',
'<li><code>{{currency code="xyz"}} | {{currency path="a/b/c" store="i" ifconfig="a/b/c"}}</code></li>',
'<li><code>{{include template="xyz.html"}} | {{include template="xyz.html" ifconfig="a/b/c"}}</code></li>',
'<li><code>{{dump something}} | {{dump}}</code></li>',
'<li><code>{{picture ...}}</code></li>',
'</ul>',
// foreach
'<div class="maillogexamples" onclick="this.innerHTML = this.innerHTML.replace(/\s+true\s+=\s+true/g, \' <b>true</b>\').replace(/\s+false\s+=\s+false/g, \' <b>false</b>\'); this.removeAttribute(\'onclick\');">',
'<pre lang="en">'.trim(str_replace("<span>\n", '<span>', str_replace(['{', '}'], ['{{', '}}'], Mage::getModel('varien/filter_template')->resetVariables($vars)->filter('
<b>foreach</b>
{foreach myvar1 = [["numb" => -2, "text" => "hello"], ["numb" => 0, "text" => "hello"], ["numb" => 2, "text" => "hello"]]}
Z / ... / {if myvar1.numb operator value} true {else} false {/if} (result calculated by _getVariable()) = {var myvar1.z} (result calculated by PHP)
l / ... / {if myvar1.xyz operator value} true {else} false {/if} (result calculated by _getVariable()) = {var myvar1.l} (result calculated by PHP)
{/foreach}
<span>{{foreach myvar1}}<span>
A / {if {{var myvar1.numb}} gt 0} / {{if myvar1.numb gt 0}} true {{else}} false {{/if}} = {{var myvar1.a}}
Expand All @@ -117,7 +125,13 @@ protected function _getHeaderCommentHtml($element) {
V / {if {{var myvar1.text}} nct 777} / {{if myvar1.text nct 777}} true {{else}} false {{/if}} = {{var myvar1.v}}
W / {if {{var myvar1.text}} ct {{var myvar1.text}}} / {{if myvar1.text ct myvar1.text}} true {{else}} false {{/if}} = {{var myvar1.w}}
X / {if {{var myvar1.text}} nct {{var myvar1.text}}} / {{if myvar1.text nct myvar1.text}} true {{else}} false {{/if}} = {{var myvar1.x}}
</span>{{/foreach}}</span>{foreach myvar2 = ["str1", "str2"]} Y / {var myvar2} {/foreach}
NA / {if {{var myvar1.numb}} gt 0 && {{var myvar1.numb}} gt -2} / {{if myvar1.numb gt 0 && myvar1.numb gt -2}} true {{else}} false {{/if}} = {{var myvar1.na}}
NB / {if {{var myvar1.numb}} lt 0 && {{var myvar1.numb}} lt -2} / {{if myvar1.numb lt 0 && myvar1.numb lt -2}} true {{else}} false {{/if}} = {{var myvar1.nb}}
NC / {if {{var myvar1.numb}} lt 0 || {{var myvar1.numb}} lt -2} / {{if myvar1.numb lt 0 || myvar1.numb lt -2}} true {{else}} false {{/if}} = {{var myvar1.nc}}
ND / {if {{var myvar1.numb}} gt 0 || {{var myvar1.numb}} gt -2} / {{if myvar1.numb gt 0 || myvar1.numb gt -2}} true {{else}} false {{/if}} = {{var myvar1.nd}}
</span>{{/foreach}}</span>{foreach myvar2 = ["str1", "str2"]}
Y / {var myvar2}
{/foreach}
<span>{{foreach myvar2}}<span>
Y / {{var myvar2}}
</span>{{/foreach}}</span><!--
Expand Down
17 changes: 5 additions & 12 deletions src/app/code/community/Luigifab/Maillog/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created D/22/03/2015
* Updated V/24/06/2022
* Updated V/02/09/2022
*
* Copyright 2015-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2015-2016 | Fabrice Creuzot <fabrice.creuzot~label-park~com>
Expand Down Expand Up @@ -150,11 +150,8 @@ public function canSend(string ...$emails) {
$ignores = array_filter(preg_split('#\s+#', Mage::getStoreConfig('maillog/filters/ignore')));
foreach ($ignores as $ignore) {
foreach ($emails as $email) {
if (mb_stripos($email, $ignore) !== false) {
$text = sprintf('STOP! Email address (%s) not allowed by keyword: %s', $email, $ignore);
Mage::log($text, Zend_Log::NOTICE, 'maillog.log');
return $text;
}
if (mb_stripos($email, $ignore) !== false)
return sprintf('STOP! Email address (%s) not allowed by keyword: %s', $email, $ignore);
}
}

Expand Down Expand Up @@ -191,10 +188,8 @@ public function canSend(string ...$emails) {
}
}

if ($msg != 'ok-can-send') {
Mage::log($msg, Zend_Log::NOTICE, 'maillog.log');
if ($msg != 'ok-can-send')
return $msg;
}

// toutes les base_url ne doivent pas contenir
$key = 'maillog/filters/notbaseurl';
Expand Down Expand Up @@ -229,10 +224,8 @@ public function canSend(string ...$emails) {
}
}

if ($msg != 'ok-can-send') {
Mage::log($msg, Zend_Log::NOTICE, 'maillog.log');
if ($msg != 'ok-can-send')
return $msg;
}

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/code/community/Luigifab/Maillog/Helper/Picture.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created V/03/01/2020
* Updated M/05/07/2022
* Updated S/27/08/2022
*
* Copyright 2015-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2015-2016 | Fabrice Creuzot <fabrice.creuzot~label-park~com>
Expand Down Expand Up @@ -346,7 +346,7 @@ protected function after(string $html, string $code, array $sizes) {
$size = empty($sizes) ? ['w' => 1, 'h' => 1] : end($sizes);
//$html = str_replace(' src="', ' src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="', $html);
// https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/
$html = str_replace(' src="', ' src="data:image/svg+xml;base64,'.base64_encode('<svg xmlns="http://www.w3.org/2000/svg" width="'.$size['w'].'px" height="'.$size['h'].'"></svg>').'" data-src="', $html);
$html = str_replace(' src="', ' src="data:image/svg+xml;base64,'.base64_encode('<svg xmlns="http://www.w3.org/2000/svg" width="'.$size['w'].'" height="'.$size['h'].'"></svg>').'" data-src="', $html);
$html = str_replace(' srcset="', ' data-srcset="', $html); */

return $html;
Expand Down
31 changes: 23 additions & 8 deletions src/app/code/community/Luigifab/Maillog/Model/Filter.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created D/22/03/2015
* Updated V/24/06/2022
* Updated D/04/09/2022
*
* Copyright 2015-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2015-2016 | Fabrice Creuzot <fabrice.creuzot~label-park~com>
Expand Down Expand Up @@ -63,19 +63,34 @@ public function ifelseDirective(array $match) {
array_shift($match); // $match[0] = tout le groupe = osef
$replace = '';

// $match[1/3/5...] = var cond var => $value
// $match[2/4/6...] = valeur si vrai
// $match[...11=last-1] = {{else}}
// $match[...12=last] = valeur si faux
// $match[1/3/5...] = var cond var => $value
// $match[2/4/6...] = valeur si vrai
// $match[...last-1] = {{else}}
// $match[...last] = valeur si faux
while (count($match) > 0) {
$value = array_shift($match);
if ($value == '{{else}}') {
$replace = array_shift($match);
break;
}
if (!empty($value) && !empty($this->_getVariable($value, ''))) {
$replace = array_shift($match);
break;
if (!empty($value)) {
$result = null;
if (mb_stripos($value, ' && ') !== false) {
$value = explode(' && ', $value);
$result = true;
foreach ($value as $subvalue)
$result = $result && !empty($this->_getVariable($subvalue, ''));
}
else if (mb_stripos($value, ' || ') !== false) {
$value = explode(' || ', $value);
$result = false;
foreach ($value as $subvalue)
$result = $result ?: !empty($this->_getVariable($subvalue, ''));
}
if (($result === true) || (($result === null) && !empty($this->_getVariable($value, '')))) {
$replace = array_shift($match);
break;
}
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/app/code/community/Luigifab/Maillog/Model/Observer.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created S/04/04/2015
* Updated S/30/07/2022
* Updated L/26/09/2022
*
* Copyright 2015-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2015-2016 | Fabrice Creuzot <fabrice.creuzot~label-park~com>
Expand Down Expand Up @@ -121,7 +121,7 @@ public function clearCache(Varien_Event_Observer $observer) {
Mage::app()->cleanCache();
Mage::dispatchEvent('adminhtml_cache_flush_system');

Mage::getSingleton('adminhtml/session')->addSuccess(str_replace('Magento', 'OpenMage', Mage::helper('adminhtml')->__('The Magento cache storage has been flushed.')));
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('The OpenMage cache storage has been flushed.'));
}


Expand Down Expand Up @@ -167,7 +167,7 @@ public function sendEmailReport($cron = null) {
$emails->addFieldToFilter('created_at', [
'datetime' => true,
'from' => $dates['start']->toString(Zend_Date::RFC_3339),
'to' => $dates['end']->toString(Zend_Date::RFC_3339)
'to' => $dates['end']->toString(Zend_Date::RFC_3339),
]);
$emails->setOrder('email_id', 'desc');

Expand Down Expand Up @@ -200,7 +200,7 @@ public function sendEmailReport($cron = null) {
'error_list' => implode('</li><li style="margin:0.8em 0 0.5em;">', $errors),
'import_bounces' => trim(strip_tags($this->getImportStatus('bounces', 'bounces'), '<br> <span>')),
'import_unsubscribers' => trim(strip_tags($this->getImportStatus('unsubscribers', 'unsubscribers'), '<br> <span>')),
'sync' => Mage::getStoreConfigFlag('maillog_sync/general/enabled')
'sync' => Mage::getStoreConfigFlag('maillog_sync/general/enabled'),
];

// chargement des statistiques des emails et des synchronisations
Expand All @@ -215,7 +215,10 @@ public function sendEmailReport($cron = null) {
for ($i = 2; $i <= 14; $i++) {

$dates = $this->getDateRange($isWeek ? 'week' : 'month', $i - 1);
$where = ['from' => $dates['start']->toString(Zend_Date::RFC_3339), 'to' => $dates['end']->toString(Zend_Date::RFC_3339)];
$where = [
'from' => $dates['start']->toString(Zend_Date::DATE_SHORT),
'to' => $dates['end']->toString(Zend_Date::DATE_SHORT),
];

// affiche les dates
if ($isWeek) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created W/11/11/2015
* Updated J/25/11/2021
* Updated S/24/09/2022
*
* Copyright 2015-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2015-2016 | Fabrice Creuzot <fabrice.creuzot~label-park~com>
Expand Down Expand Up @@ -270,7 +270,7 @@ protected function sendRequest(string $type, string $method, $data = null) {
'X-WSSE: UsernameToken '.
'Username="'.Mage::getStoreConfig('maillog_sync/'.$this->_code.'/api_username').'", '.
'PasswordDigest="'.$password.'", Nonce="'.$nonce.'", Created="'.$timestamp.'"',
$override
$override,
]);

$result = curl_exec($ch);
Expand Down
11 changes: 7 additions & 4 deletions src/app/code/community/Luigifab/Maillog/Model/System/Mautic.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created J/23/09/2021
* Updated V/24/06/2022
* Updated J/29/09/2022
*
* Copyright 2015-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2015-2016 | Fabrice Creuzot <fabrice.creuzot~label-park~com>
Expand Down Expand Up @@ -106,12 +106,15 @@ public function mapFields($object, string $group, bool $onlyAttributes = false)
if (in_array($region, $this->_regions[$country])) {
$fields[$system] = $region;
}
else {
else if (!empty($region)) {
$region = transliterator_transliterate('Any-Latin; Latin-ASCII; [^\u001F-\u007f] remove', $region);
if ($object->getData('country_id') == 'RU')
$region = str_replace('skaa', 'skaya', $region);
$fields[$system] = in_array($region, $this->_regions[$country]) ? $region : '';
}
else {
$fields[$system] = '';
}
}
}
else if ($code == 'country_id') {
Expand Down Expand Up @@ -155,7 +158,7 @@ public function mapFields($object, string $group, bool $onlyAttributes = false)
// 2016-02-26T10:31:11+00:00
// 2016-02-26 10:32:28
$fields[$system] = $object->getData($code);
if (preg_match('#^\d{4}.\d{2}.\d{2}.\d{2}.\d{2}.\d{2}#', $fields[$system]) === 1)
if (!empty($fields[$system]) && (preg_match('#^\d{4}.\d{2}.\d{2}.\d{2}.\d{2}.\d{2}#', $fields[$system]) === 1))
$fields[$system] = date('Y-m-d H:i:s', strtotime($fields[$system]));
}
}
Expand Down Expand Up @@ -263,7 +266,7 @@ protected function sendRequest(string $type, string $method, $data = null) {
'Accept: application/json',
'Content-Type: application/json; charset="utf-8"',
'Authorization: Basic '.base64_encode(Mage::getStoreConfig('maillog_sync/'.$this->_code.'/api_username').':'.Mage::helper('core')->decrypt(Mage::getStoreConfig('maillog_sync/'.$this->_code.'/api_password'))),
$override
$override,
]);

$result = curl_exec($ch);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created D/22/03/2015
* Updated S/09/10/2021
* Updated D/28/08/2022
*
* Copyright 2015-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2015-2016 | Fabrice Creuzot <fabrice.creuzot~label-park~com>
Expand Down Expand Up @@ -40,10 +40,12 @@ protected function _isAllowed() {

protected function _redirectBack() {

if ($this->getRequest()->getParam('back') == 'order')
$this->_redirect('*/sales_order/view', ['order_id' => $this->getRequest()->getParam('bid'), 'active_tab' => 'maillog_order_grid']);
else if ($this->getRequest()->getParam('back') == 'customer')
$this->_redirect('*/customer/edit', ['id' => $this->getRequest()->getParam('bid'), 'back' => 'edit', 'tab' => 'customer_info_tabs_maillog_customer_grid']);
$request = $this->getRequest();

if ($request->getParam('back') == 'order')
$this->_redirect('*/sales_order/view', ['order_id' => $request->getParam('bid'), 'active_tab' => 'maillog_order_grid']);
else if ($request->getParam('back') == 'customer')
$this->_redirect('*/customer/edit', ['id' => $request->getParam('bid'), 'back' => 'edit', 'tab' => 'customer_info_tabs_maillog_customer_grid']);
else
$this->_redirect('*/*/index');
}
Expand Down
Loading

0 comments on commit 72caa8d

Please sign in to comment.