Skip to content

Commit

Permalink
Code cleanup, composer update
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Mar 20, 2019
1 parent 70467bc commit 574b411
Show file tree
Hide file tree
Showing 121 changed files with 23,322 additions and 376 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v3.0.0-rc.4
## mm/dd/2019

1. [](#new)
* Code cleanup, composer update

# v3.0.0-rc.3
## 02/18/2019

Expand Down
60 changes: 31 additions & 29 deletions classes/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Grav\Common\Grav;
use Grav\Common\Language\Language;
use Grav\Common\Twig\Twig;
use Grav\Framework\Form\Interfaces\FormInterface;
use \Monolog\Logger;
use \Monolog\Handler\StreamHandler;

Expand All @@ -29,7 +30,7 @@ class Email
*/
public static function enabled()
{
return Grav::instance()['config']->get('plugins.email.mailer.engine') != 'none';
return Grav::instance()['config']->get('plugins.email.mailer.engine') !== 'none';
}

/**
Expand Down Expand Up @@ -129,7 +130,7 @@ public function send($message)
* @param array $vars
* @return \Swift_Message
*/
public function buildMessage(array $params, array $vars = array())
public function buildMessage(array $params, array $vars = [])
{
/** @var Twig $twig */
$twig = Grav::instance()['twig'];
Expand All @@ -141,23 +142,23 @@ public function buildMessage(array $params, array $vars = array())
$language = Grav::instance()['language'];

// Extend parameters with defaults.
$params += array(
'bcc' => $config->get('plugins.email.bcc', array()),
$params += [
'bcc' => $config->get('plugins.email.bcc', []),
'body' => $config->get('plugins.email.body', '{% include "forms/data.html.twig" %}'),
'cc' => $config->get('plugins.email.cc', array()),
'cc' => $config->get('plugins.email.cc', []),
'cc_name' => $config->get('plugins.email.cc_name'),
'charset' => $config->get('plugins.email.charset', 'utf-8'),
'from' => $config->get('plugins.email.from'),
'from_name' => $config->get('plugins.email.from_name'),
'content_type' => $config->get('plugins.email.content_type', 'text/html'),
'reply_to' => $config->get('plugins.email.reply_to', array()),
'reply_to' => $config->get('plugins.email.reply_to', []),
'reply_to_name' => $config->get('plugins.email.reply_to_name'),
'subject' => !empty($vars['form']) && $vars['form'] instanceof Form ? $vars['form']->page()->title() : null,
'subject' => !empty($vars['form']) && $vars['form'] instanceof FormInterface ? $vars['form']->page()->title() : null,
'to' => $config->get('plugins.email.to'),
'to_name' => $config->get('plugins.email.to_name'),
'process_markdown' => false,
'template' => false
);
];

// Create message object.
$message = $this->message();
Expand Down Expand Up @@ -192,10 +193,10 @@ public function buildMessage(array $params, array $vars = array())
}
elseif (is_array($value)) {
foreach ($value as $body_part) {
$body_part += array(
$body_part += [
'charset' => $params['charset'],
'content_type' => $params['content_type'],
);
];

$body = !empty($body_part['body']) ? $twig->processString($body_part['body'], $vars) : null;

Expand Down Expand Up @@ -223,10 +224,10 @@ public function buildMessage(array $params, array $vars = array())

case 'to':
if (is_string($value) && !empty($params['to_name'])) {
$value = array(
$value = [
'mail' => $twig->processString($value, $vars),
'name' => $twig->processString($params['to_name'], $vars),
);
];
}

foreach ($this->parseAddressValue($value, $vars) as $address) {
Expand All @@ -236,10 +237,10 @@ public function buildMessage(array $params, array $vars = array())

case 'cc':
if (is_string($value) && !empty($params['cc_name'])) {
$value = array(
$value = [
'mail' => $twig->processString($value, $vars),
'name' => $twig->processString($params['cc_name'], $vars),
);
];
}

foreach ($this->parseAddressValue($value, $vars) as $address) {
Expand All @@ -255,10 +256,10 @@ public function buildMessage(array $params, array $vars = array())

case 'from':
if (is_string($value) && !empty($params['from_name'])) {
$value = array(
$value = [
'mail' => $twig->processString($value, $vars),
'name' => $twig->processString($params['from_name'], $vars),
);
];
}

foreach ($this->parseAddressValue($value, $vars) as $address) {
Expand All @@ -268,10 +269,10 @@ public function buildMessage(array $params, array $vars = array())

case 'reply_to':
if (is_string($value) && !empty($params['reply_to_name'])) {
$value = array(
$value = [
'mail' => $twig->processString($value, $vars),
'name' => $twig->processString($params['reply_to_name'], $vars),
);
];
}

foreach ($this->parseAddressValue($value, $vars) as $address) {
Expand All @@ -288,23 +289,23 @@ public function buildMessage(array $params, array $vars = array())
/**
* Return parsed e-mail address value.
*
* @param $value
* @param string|string[] $value
* @param array $vars
* @return array
*/
public function parseAddressValue($value, array $vars = array())
public function parseAddressValue($value, array $vars = [])
{
$parsed = array();
$parsed = [];

/** @var Twig $twig */
$twig = Grav::instance()['twig'];

// Single e-mail address string
if (is_string($value)) {
$parsed[] = (object) array(
$parsed[] = (object) [
'mail' => $twig->processString($value, $vars),
'name' => null,
);
];
}

else {
Expand All @@ -313,10 +314,10 @@ public function parseAddressValue($value, array $vars = array())

// Single e-mail address array
if (!empty($value['mail'])) {
$parsed[] = (object) array(
$parsed[] = (object) [
'mail' => $twig->processString($value['mail'], $vars),
'name' => !empty($value['name']) ? $twig->processString($value['name'], $vars) : NULL,
);
];
}

// Multiple addresses (either as strings or arrays)
Expand Down Expand Up @@ -441,7 +442,7 @@ public static function clearQueueFailures()
foreach (new \GlobIterator($queue_path . '/*.sending') as $file) {
$final_message = $file->getPathname();

/** @var $message \Swift_Message */
/** @var \Swift_Message $message */
$message = unserialize(file_get_contents($final_message));

echo(sprintf(
Expand Down Expand Up @@ -469,9 +470,10 @@ public static function clearQueueFailures()
/**
* Clean copy a message
*
* @param $message \Swift_Message
* @param \Swift_Message $message
*/
public static function cloneMessage($message) {
public static function cloneMessage($message)
{
$clean = new \Swift_Message();

$clean->setBoundary($message->getBoundary());
Expand Down Expand Up @@ -518,7 +520,7 @@ protected static function getTransport()
if (!empty($options['port'])) {
$transport->setPort($options['port']);
}
if (!empty($options['encryption']) && $options['encryption'] != 'none') {
if (!empty($options['encryption']) && $options['encryption'] !== 'none') {
$transport->setEncryption($options['encryption']);
}
if (!empty($options['user'])) {
Expand Down
2 changes: 1 addition & 1 deletion classes/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Utils
/**
* Quick utility method to send an HTML email.
*
* @param array $params
* @param array<int,mixed> $params
*
* @return bool True if the action was performed.
*/
Expand Down
27 changes: 25 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
{
"name": "getgrav/grav-plugin-email",
"type": "grav-plugin",
"description": "Email plugin for Grav CMS",
"keywords": ["email", "plugin", "sender"],
"homepage": "https://github.com/getgrav/grav-plugin-email",
"license": "MIT",
"authors": [
{
"name": "Team Grav",
"email": "[email protected]",
"homepage": "https://getgrav.org",
"role": "Developer"
}
],
"support": {
"issues": "https://github.com/getgrav/grav-plugin-email/issues",
"irc": "https://chat.getgrav.org",
"forum": "https://getgrav.org/forum",
"docs": "https://github.com/getgrav/grav-plugin-email/blob/master/README.md"
},
"require": {
"php": ">=7.1.3",
"swiftmailer/swiftmailer": "~6.0"
},
"autoload": {
"psr-4": {
"Grav\\Plugin\\Email\\": "classes/"
}
"Grav\\Plugin\\Email\\": "classes/",
"Grav\\Plugin\\Console\\": "cli/"
},
"classmap": ["email.php"]
}
}
Loading

0 comments on commit 574b411

Please sign in to comment.