Skip to content

Commit

Permalink
Version 2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronef committed Jul 15, 2024
2 parents 49905c0 + 0dbf2cc commit 8b43e75
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 39 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# (MODX)EvolutionCMS.snippets.ddSendFeedback changelog


## Version 2.9 (2024-07-15)
* \+ SenderEmail → Parameters → `senders->email->to`: Addresses validation has been added. So if you specify only invalid emails, you will receive an error in the CMS log that not all required parameters have been set.
* \+ Sender → Parameters → `senders->{$senderName}->isFailRequiredParamsDisplayedToLog`: The new optional parameter. Allows you do disable a failure message to the CMS log when required parameters are not set.


## Version 2.8 (2024-07-13)

* \* Sender:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG_ru.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# (MODX)EvolutionCMS.snippets.ddSendFeedback changelog


## Версия 2.9 (2024-07-15)
* \+ СендерEmail → Параметры → `senders->email->to`: Добавлена валидация адресов. Таким образом, если вы укажете только недействительные ящики, в логе CMS появится ошибка, что заданы не все необходимые параметры.
* \+ Сендер → Параметры → `senders->{$senderName}->isFailRequiredParamsDisplayedToLog`: Новый необязательный параметр. Позволяет отключить отправку сообщения об ошибке в лог CMS, когда обязательные параметры не заданы.


## Версия 2.8 (2024-07-13)

* \* Сендер:
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ require_once(
#### 1. Elements → Snippets: Create a new snippet with the following data

1. Snippet name: `ddSendFeedback`.
2. Description: `<b>2.8</b> A snippet for sending users' feedback messages to you. It is very useful along with ajax technology.`.
2. Description: `<b>2.9</b> A snippet for sending users' feedback messages to you. It is very useful along with ajax technology.`.
3. Category: `Core`.
4. Parse DocBlock: `no`.
5. Snippet code (php): Insert content of the `ddSendFeedback_snippet.php` file from the archive.
Expand Down Expand Up @@ -156,6 +156,11 @@ require_once(
* Description: Display a failure message to user when sending is failed, or just log it.
* Valid values: `boolean`
* Default value: `true`

* `senders->{$senderName}->isFailRequiredParamsDisplayedToLog`
* Description: Display a failure message to the CMS log when required parameters are not set.
* Valid values: `boolean`
* Default value: `true`


#### Senders → Email
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dd/evolutioncms-snippets-ddsendfeedback",
"type": "modxevo-snippet",
"version": "2.8.0",
"version": "2.9.0",
"description": "A snippet for sending users' feedback messages to a required email, slack and telegram chats or SMS through sms.ru. It is very useful along with ajax technology.",
"keywords": [
"modx",
Expand Down
2 changes: 1 addition & 1 deletion ddSendFeedback_snippet.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* ddSendFeedback
* @version 2.8 (2024-07-13)
* @version 2.9 (2024-07-15)
*
* @see README.md
*
Expand Down
29 changes: 23 additions & 6 deletions src/Sender/Email/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,37 @@ class Sender extends \ddSendFeedback\Sender\Sender {
;

/**
* __construct
* @version 1.0.1 (2019-12-14)
* construct_prepareProps
* @version 1.0 (2024-07-14)
*
* @return {void}
*/
public function __construct($params = []){
//Call base constructor
parent::__construct($params);

protected function construct_prepareProps(){
//Comma separated string support
if (is_string($this->to)){
$this->to = explode(
',',
$this->to
);
}

//Delete invalid emails
foreach(
$this->to
as $itemIndex
=> $itemlValue
){
if (
!filter_var(
$itemlValue,
FILTER_VALIDATE_EMAIL
)
){
unset($this->to[$itemIndex]);
}
}

parent::construct_prepareProps();
}

/**
Expand Down
75 changes: 46 additions & 29 deletions src/Sender/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ abstract class Sender extends \DDTools\Base\Base {
$text = '',
$textMarkupSyntax = 'html',
$isFailDisplayedToUser = true,
$isFailRequiredParamsDisplayedToLog = true,

$requiredProps = ['tpl'],
$canSend = true,
Expand All @@ -34,36 +35,12 @@ abstract class Sender extends \DDTools\Base\Base {

/**
* __construct
* @version 1.7 (2024-07-13)
* @version 1.7.1 (2024-07-14)
*/
public function __construct($params = []){
$this->setExistingProps($params);

$this->requestResultParams = (object) $this->requestResultParams;

if (!\ddTools::isEmpty($this->requestResultParams->checkPropName)){
$this->requestResultParams->isObject = true;
}

//$this->tpl is always required in all senders
array_unshift(
$this->requiredProps,
'tpl'
);

//Check required props
foreach (
$this->requiredProps
as $requiredPropName
){
//If one of required properties is not set
if (\ddTools::isEmpty($this->{$requiredPropName})){
//We can't send
$this->canSend = false;

break;
}
}
$this->construct_prepareProps();

//If all required properties are set
if ($this->canSend){
Expand Down Expand Up @@ -122,6 +99,40 @@ public function __construct($params = []){
}
}

/**
* construct_prepareProps
* @version 1.0 (2024-07-14)
*
* @return {void}
*/
protected function construct_prepareProps(){
$this->requestResultParams = (object) $this->requestResultParams;

if (!\ddTools::isEmpty($this->requestResultParams->checkPropName)){
$this->requestResultParams->isObject = true;
}

//$this->tpl is always required in all senders
array_unshift(
$this->requiredProps,
'tpl'
);

//Check required props
foreach (
$this->requiredProps
as $requiredPropName
){
//If one of required properties is not set
if (\ddTools::isEmpty($this->{$requiredPropName})){
//We can't send
$this->canSend = false;

break;
}
}
}

/**
* initPostPlaceholders
* @version 1.2.1 (2024-07-13)
Expand Down Expand Up @@ -166,7 +177,7 @@ private final function initPostPlaceholders(){

/**
* send
* @version 1.7.5 (2024-07-13)
* @version 1.8 (2024-07-14)
*
* @desc Sends a message.
*
Expand All @@ -177,13 +188,19 @@ public function send(){
$errorData = (object) [
'isError' => true,
//Only 19 signs are allowed here in MODX event log :|
'title' => 'Check required parameters',
'title' => '',
'message' => '',
];

$requestResult = null;

if ($this->canSend){
if (!$this->canSend){
$errorData->title = 'Check required parameters';

if (!$this->isFailRequiredParamsDisplayedToLog){
$errorData->isError = false;
}
}else{
$errorData->title = 'Unexpected API error';

if (!$this->send_auth()){
Expand Down
2 changes: 1 addition & 1 deletion src/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Snippet extends \DDTools\Snippet {
protected
$version = '2.8.0',
$version = '2.9.0',

$params = [
//Defaults
Expand Down

0 comments on commit 8b43e75

Please sign in to comment.