Skip to content

Commit

Permalink
Merge pull request #39 from mailjet/DE-1335-make-fixes-according-to-c…
Browse files Browse the repository at this point in the history
…ollected-errors-manual-testing

Prepare plugin for Joomla 5
  • Loading branch information
oleksandr-mykhailenko authored Nov 7, 2024
2 parents 227be2d + 5efea09 commit efd4e6a
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 180 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

Tags: email, marketing, signup, newsletter, widget, smtp, mailjet
Requires at least: 3.0.0
Tested up to: 4.4.8
Stable tag: 4.0
Tested up to: 5.2.0
Stable tag: 4.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -81,6 +81,9 @@ Once your Mailjet plugin is installed, click on "Extensions" in the top menu and

## Changelog

= 4.1 =
* Make plugin compatible with Joomla 5.

= 4.0 =
* Make plugin compatible with Joomla 4.

Expand Down
Binary file modified packages/com_mailjet.zip
Binary file not shown.
44 changes: 44 additions & 0 deletions packages/com_mailjet/admin/com_mailjet.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="4.1">
<name>Mailjet</name>
<author>Mailjet SAS</author>
<authorUrl>http://www.mailjet.com</authorUrl>
<authorEmail>[email protected]</authorEmail>
<creationDate>June 2014</creationDate>
<url>http://www.mailjet.com/</url>
<version>4.1</version>
<copyright>Copyright (C) 2014 Mailjet SAS.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE</license>
<description>Mailjet Email component.</description>

<scriptfile>installer.php</scriptfile>
<files folder="front">
<filename>mailjet.php</filename>
<filename>controller.php</filename>
<filename>styles.css</filename>
<folder>models</folder>
<folder>views</folder>
</files>

<administration>
<menu img="../administrator/components/com_mailjet/images/logo-16x16.png">COM_MAILJET_MENU</menu>
<submenu>
<menu view="mailjet" img="../administrator/components/com_mailjet/images/logo-16x16.png">COM_MAILJET_SETTINGS</menu>
<menu view="contacts" img="../administrator/components/com_mailjet/images/logo-16x16.png">COM_MAILJET_CONTACTS</menu>
<menu view="campaigns" img="../administrator/components/com_mailjet/images/logo-16x16.png">COM_MAILJET_CAMPAIGNS</menu>
<menu view="statistics" img="../administrator/components/com_mailjet/images/logo-16x16.png">COM_MAILJET_STATS</menu>
</submenu>
<files folder="admin">
<filename>mailjet.php</filename>
<filename>controller.php</filename>
<filename>config.php</filename>
<filename>styles.css</filename>
<folder>views</folder>
<folder>models</folder>
<folder>language</folder>
<folder>images</folder>
<folder>lib</folder>
<folder>helpers</folder>
</files>
</administration>
</extension>
68 changes: 34 additions & 34 deletions packages/com_mailjet/admin/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class_alias('JController', 'JControllerLegacy');
class MailjetController extends JControllerLegacy
{
/**
* @param bool $cachable
* @param bool $urlparams
* @param bool $cachable
* @param bool $urlparams
*
* @return void
* @throws Exception
Expand All @@ -50,9 +50,9 @@ public function save(): void
{
Session::checkToken() or jexit('Invalid Token');

$error = false;
$error = false;
$mailjetConfig = sPrintF('%s/components/%s/config.php', JPATH_ADMINISTRATOR, 'com_mailjet');
$fileConfig = JPATH_ROOT . '/configuration.php';
$fileConfig = JPATH_ROOT . '/configuration.php';

require_once($mailjetConfig);

Expand All @@ -61,22 +61,22 @@ public function save(): void
$prev = new JConfig();
$prev = ArrayHelper::fromObject($prev);

$fields['bak_mailer'] = $prev['mailer'];
$fields['bak_smtpauth'] = $prev['smtpauth'];
$fields['bak_smtpuser'] = $prev['smtpuser'];
$fields['bak_smtppass'] = $prev['smtppass'];
$fields['bak_smtphost'] = $prev['smtphost'];
$fields['bak_mailer'] = $prev['mailer'];
$fields['bak_smtpauth'] = $prev['smtpauth'];
$fields['bak_smtpuser'] = $prev['smtpuser'];
$fields['bak_smtppass'] = $prev['smtppass'];
$fields['bak_smtphost'] = $prev['smtphost'];
$fields['bak_smtpsecure'] = $prev['smtpsecure'];
$fields['bak_smtpport'] = $prev['smtpport'];
$fields['bak_smtpport'] = $prev['smtpport'];

$data = Factory::getApplication()->input->post->getArray();

$fields['enable'] = isset($data['enable']) && $data['enable'] === 'on';
$fields['test'] = isset($data['test']);
$fields['enable'] = isset($data['enable']) && $data['enable'] === 'on';
$fields['test'] = isset($data['test']);
$fields['test_address'] = $data['test_address'];
$fields['username'] = $data['username'];
$fields['password'] = $data['password'];
$fields['host'] = $host;
$fields['username'] = $data['username'];
$fields['password'] = $data['password'];
$fields['host'] = $host;

$configs = [['ssl://', 465],
['tls://', 587],
Expand Down Expand Up @@ -111,8 +111,8 @@ public function save(): void
Factory::getApplication()->enqueueMessage(
json_encode([
'message' => \Joomla\CMS\Language\Text::_('COM_MAILJET_CONTACT_SUPPORT_ERROR'),
'error' => $errno,
'str' => $errstr
'error' => $errno,
'str' => $errstr
]),
\Joomla\CMS\Application\CMSApplication::MSG_WARNING
);
Expand All @@ -124,7 +124,7 @@ public function save(): void
Factory::getApplication()->enqueueMessage(
json_encode([
'message' => \Joomla\CMS\Language\Text::_('COM_MAILJET_RECIPIENT_INVALID'),
'error' => $fields['test_address'],
'error' => $fields['test_address'],
]),
\Joomla\CMS\Application\CMSApplication::MSG_WARNING
);
Expand Down Expand Up @@ -156,11 +156,11 @@ public function save(): void
}

$mailjetData = sPrintF('%s/components/%s/lib/db/data', JPATH_ADMINISTRATOR, 'com_mailjet');
$JSONString = json_encode([
'apiKey' => $fields['username'],
'apiSecret' => $fields['password'],
$JSONString = json_encode([
'apiKey' => $fields['username'],
'apiSecret' => $fields['password'],
'test_address' => $fields['test_address'],
'enable' => $fields['enable'],
'enable' => $fields['enable'],
]);

if(!\Joomla\Filesystem\File::write($mailjetData, $JSONString)) {
Expand All @@ -171,21 +171,21 @@ public function save(): void
}

if($fields['enable']) {
$prev['mailer'] = 'smtp';
$prev['smtpauth'] = '1';
$prev['smtpuser'] = $fields['username'];
$prev['smtppass'] = $fields['password'];
$prev['smtphost'] = $fields['host'];
$prev['mailer'] = 'smtp';
$prev['smtpauth'] = '1';
$prev['smtpuser'] = $fields['username'];
$prev['smtppass'] = $fields['password'];
$prev['smtphost'] = $fields['host'];
$prev['smtpsecure'] = $fields['secure'];
$prev['smtpport'] = $fields['port'];
$prev['smtpport'] = $fields['port'];
} else {
$prev['mailer'] = $fields['bak_mailer'];
$prev['smtpauth'] = $fields['bak_smtpauth'];
$prev['smtpuser'] = $fields['bak_smtpuser'];
$prev['smtppass'] = $fields['bak_smtppass'];
$prev['smtphost'] = $fields['bak_smtphost'];
$prev['mailer'] = $fields['bak_mailer'];
$prev['smtpauth'] = $fields['bak_smtpauth'];
$prev['smtpuser'] = $fields['bak_smtpuser'];
$prev['smtppass'] = $fields['bak_smtppass'];
$prev['smtphost'] = $fields['bak_smtphost'];
$prev['smtpsecure'] = $fields['bak_smtpsecure'];
$prev['smtpport'] = $fields['bak_smtpport'];
$prev['smtpport'] = $fields['bak_smtpport'];
}

$config = new \Joomla\Registry\Registry('config');
Expand Down
135 changes: 1 addition & 134 deletions packages/com_mailjet/admin/models/mailjet.php
Original file line number Diff line number Diff line change
@@ -1,134 +1 @@
<?php

/**
* @author Mailjet SAS
*
* @copyright Copyright (C) 2014 Mailjet SAS.
* @license GNU General Public License version 2 or later; see LICENSE
*/

// No direct access

use Joomla\CMS\Factory;
use Joomla\CMS\Version;
use Joomla\Utilities\ArrayHelper;

defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.model');

if (!class_exists('JModelLegacy')) {
class_alias('JModel', 'JModelLegacy');
}

class MailjetModelMailjet extends JModelLegacy
{
/**
* @return array
* @throws Exception
* @since 4.0
*/
public function getAsPost()
{
$jInput = Factory::getApplication()->input;
$post = $jInput->post->getArray();

$data ['enable'] = isset($post['enable']) && $post['enable'] === 'on';
$data ['test'] = isset($post['test']);
$data ['test_address'] = $post ['test_address'];
$data ['username'] = $post ['username'];
$data ['password'] = $post ['password'];
$data ['api_token'] = serialize(false);

return $data;
}


/**
* @return array
* @since 4.0
*/
public function getAsRecord(): array
{
$mailjetConfig = sPrintF('%s/config.php', JPATH_COMPONENT);

require_once($mailjetConfig);

$conf = new JMailjetConfig();
$host = $conf->host;
$prev = new JConfig();
$prev = ArrayHelper::fromObject($prev);

$fields['bak_mailer'] = $prev['mailer'];
$fields['bak_smtpauth'] = $prev['smtpauth'];
$fields['bak_smtpuser'] = $prev['smtpuser'];
$fields['bak_smtppass'] = $prev['smtppass'];
$fields['bak_smtphost'] = $prev['smtphost'];
$fields['bak_smtpsecure'] = $prev['smtpsecure'];
$fields['bak_smtpport'] = $prev['smtpport'];

$data['enable'] = $conf->enable && 'smtp' == $prev ['mailer'] && $conf->host == $prev ['smtphost'];
$data['test'] = $conf->test;
$data['test_address'] = $conf->test_address;
$data['username'] = $conf->username;
$data['password'] = $conf->password;
$data['host'] = $host;

if (isset($data['api_token']) && $data['api_token']) {
$data['api_token'] = unserialize($conf->api_token);
}

return $data;
}


/**
* @param $key
* @param $value
*
* @return void
* @throws Exception
* @since 4.0
*/
public function saveRecord($key, $value)
{
jimport('joomla.filesystem.path');
jimport('joomla.filesystem.file');

$mailjetConfig = sPrintF('%s/components/%s/config.php', JPATH_ADMINISTRATOR, 'com_mailjet');

require_once($mailjetConfig);

$config = new JRegistry('config');
$config->loadArray($this->getAsRecord());

$jversion = new Version();

if (version_compare($jversion->getShortVersion(), '2.5.6', 'lt')) {
$config->setValue($key, $value);
} else {
$config->set($key, $value);
}

$configString = $config->toString('PHP', ['class' => 'JMailjetConfig', 'closingtag' => false]);

if (!\Joomla\Filesystem\File::write($mailjetConfig, $configString)) {
Factory::getApplication()->enqueueMessage(
\Joomla\CMS\Language\Text::_('Unable to write configuration file for Mailjet\'s settings.'),
\Joomla\CMS\Application\CMSApplication::MSG_WARNING
);
}

$mailjetData = sPrintF('%s/components/%s/lib/db/data', JPATH_ADMINISTRATOR, 'com_mailjet');

$JSONString = '{"apiKey":"' . $post['username'] . '","apiSecret":"' . $post['password'] . '","token":null}';

if (!\Joomla\Filesystem\File::write($mailjetData, $JSONString)) {
Factory::getApplication()->enqueueMessage(
\Joomla\CMS\Language\Text::_('Unable to write data file for Mailjet\'s settings.'),
\Joomla\CMS\Application\CMSApplication::MSG_WARNING
);
}
}
}

<?php/** * @author Mailjet SAS * * @copyright Copyright (C) 2014 Mailjet SAS. * @license GNU General Public License version 2 or later; see LICENSE */// No direct accessuse Joomla\CMS\Factory;use Joomla\CMS\Version;use Joomla\Utilities\ArrayHelper;defined('_JEXEC') or die('Restricted access');jimport('joomla.application.component.model');if (!class_exists('JModelLegacy')) { class_alias('JModel', 'JModelLegacy');}class MailjetModelMailjet extends JModelLegacy{ /** * @return array * @throws Exception * @since 4.0 */ public function getAsPost(): array { $jInput = Factory::getApplication()->input; $post = $jInput->post->getArray(); $data ['enable'] = isset($post['enable']) && $post['enable'] === 'on'; $data ['test'] = isset($post['test']); $data ['test_address'] = $post ['test_address']; $data ['username'] = $post ['username']; $data ['password'] = $post ['password']; $data ['api_token'] = serialize(false); return $data; } /** * @return array * @since 4.0 */ public function getAsRecord(): array { $mailjetConfig = sPrintF('%s/config.php', JPATH_COMPONENT); require_once($mailjetConfig); $conf = new JMailjetConfig(); $host = $conf->host; $prev = new JConfig(); $prev = ArrayHelper::fromObject($prev); $fields['bak_mailer'] = $prev['mailer']; $fields['bak_smtpauth'] = $prev['smtpauth']; $fields['bak_smtpuser'] = $prev['smtpuser']; $fields['bak_smtppass'] = $prev['smtppass']; $fields['bak_smtphost'] = $prev['smtphost']; $fields['bak_smtpsecure'] = $prev['smtpsecure']; $fields['bak_smtpport'] = $prev['smtpport']; $data['enable'] = $conf->enable && 'smtp' == $prev ['mailer'] && $conf->host == $prev ['smtphost']; $data['test'] = $conf->test; $data['test_address'] = $conf->test_address; $data['username'] = $conf->username; $data['password'] = $conf->password; $data['host'] = $host; if (isset($data['api_token']) && $data['api_token']) { $data['api_token'] = unserialize($conf->api_token); } return $data; } /** * @param $key * @param $value * * @return void * @throws Exception * @since 4.0 */ public function saveRecord($key, $value) { jimport('joomla.filesystem.path'); jimport('joomla.filesystem.file'); $mailjetConfig = sPrintF('%s/components/%s/config.php', JPATH_ADMINISTRATOR, 'com_mailjet'); require_once($mailjetConfig); $config = new JRegistry('config'); $config->loadArray($this->getAsRecord()); $jversion = new Version(); if (version_compare($jversion->getShortVersion(), '2.5.6', 'lt')) { $config->setValue($key, $value); } else { $config->set($key, $value); } $configString = $config->toString('PHP', ['class' => 'JMailjetConfig', 'closingtag' => false]); if (!\Joomla\Filesystem\File::write($mailjetConfig, $configString)) { Factory::getApplication()->enqueueMessage( \Joomla\CMS\Language\Text::_('Unable to write configuration file for Mailjet\'s settings.'), \Joomla\CMS\Application\CMSApplication::MSG_WARNING ); } $mailjetData = sPrintF('%s/components/%s/lib/db/data', JPATH_ADMINISTRATOR, 'com_mailjet'); $JSONString = '{"apiKey":"' . $post['username'] . '","apiSecret":"' . $post['password'] . '","token":null}'; if (!\Joomla\Filesystem\File::write($mailjetData, $JSONString)) { Factory::getApplication()->enqueueMessage( \Joomla\CMS\Language\Text::_('Unable to write data file for Mailjet\'s settings.'), \Joomla\CMS\Application\CMSApplication::MSG_WARNING ); } }}
Expand Down
2 changes: 1 addition & 1 deletion packages/com_mailjet/admin/views/campaigns/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class MailjetViewCampaigns extends JViewLegacy
/**
* @since 4.0
* @return void
* @throws Exception
*/
public function display($tpl = null)
{
\Joomla\CMS\Toolbar\ToolbarHelper::title(\Joomla\CMS\Language\Text::_("COM_MAILJET_CAMPAIGNS"), 'logo.png');
//JToolBarHelper::save ();

$this->sidebar = \Joomla\CMS\HTML\Helpers\Sidebar::render();

Expand Down
4 changes: 3 additions & 1 deletion packages/com_mailjet/admin/views/contacts/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ class MailjetViewContacts extends JViewLegacy
/**
* @since 4.0
* @return void
* @throws Exception
*/
public function display($tpl = null)
{
\Joomla\CMS\Toolbar\ToolbarHelper::title(\Joomla\CMS\Language\Text::_("COM_MAILJET_CONTACTS"), 'logo.png');
\Joomla\CMS\Toolbar\ToolbarHelper::title(\Joomla\CMS\Language\Text::_("COM_MAILJET_CONTACTS"), 'logo.png' );

$this->sidebar = \Joomla\CMS\HTML\Helpers\Sidebar::render();

parent::display($tpl);
Expand Down
2 changes: 1 addition & 1 deletion packages/com_mailjet/admin/views/mailjet/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class_alias('JView', 'JViewLegacy');
class MailjetViewMailjet extends JViewLegacy
{
/**
* @param null $tpl
* @param null $tpl
* @return void
* @throws Exception
* @since 4.0
Expand Down
2 changes: 1 addition & 1 deletion packages/com_mailjet/admin/views/statistics/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MailjetViewStatistics extends JViewLegacy
public function display($tpl = null)
{
\Joomla\CMS\Toolbar\ToolbarHelper::title(\Joomla\CMS\Language\Text::_("COM_MAILJET_STATS"), 'logo.png');

$this->sidebar = \Joomla\CMS\HTML\Helpers\Sidebar::render();

parent::display($tpl);
Expand Down
1 change: 1 addition & 0 deletions packages/com_mailjet/front/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class_alias('JController', 'JControllerLegacy');

class MailjetController extends JControllerLegacy
{

public function save()
{
global $result;
Expand Down
Loading

0 comments on commit efd4e6a

Please sign in to comment.