Skip to content
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
c5083be
Adding a mail templating system
Hackwar Sep 11, 2018
05d3b14
Further work on the mail templating system
Hackwar Sep 11, 2018
ed2ca3e
Changes from @brianteeman review
Hackwar Sep 12, 2018
3e6d514
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Sep 12, 2018
32c5e2f
Codestyle
Hackwar Sep 12, 2018
114c5a9
Merge branch 'j4mailtemplates' of github.com:Hackwar/joomla-cms into …
Hackwar Sep 12, 2018
92a5552
Further work on mail templates
Hackwar Sep 16, 2018
acde9b6
Further work on Mail Templates
Hackwar Sep 18, 2018
ae73644
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into j…
Hackwar Sep 18, 2018
d6bc7c2
Further work on Mail Templates
Hackwar Sep 18, 2018
3987764
Codestyle
Hackwar Sep 18, 2018
b8b0519
Adding test mail as example for a mail template
Hackwar Sep 18, 2018
4002f73
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Sep 23, 2018
2045ee7
Code cleanup
wilsonge Sep 27, 2018
8b9da11
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Oct 1, 2018
9da9fe1
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Oct 2, 2018
d649824
Merge branch '4.0-dev' into j4mailtemplates
laoneo Oct 3, 2018
a85f9c8
Merge branch '4.0-dev' into j4mailtemplates
laoneo Nov 2, 2018
9557887
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Nov 15, 2018
8ae30c1
Adding filters
Hackwar Nov 15, 2018
ea19a49
Codestyle
Hackwar Nov 15, 2018
d484293
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Nov 28, 2018
eb07c09
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into j…
Hackwar Dec 24, 2018
1b864af
Merge branch 'j4mailtemplates' of github.com:Hackwar/joomla-cms into …
Hackwar Jan 11, 2019
0c1b3c8
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into j…
Hackwar Jan 11, 2019
f83efbd
Adding mail templating system
Hackwar Jan 16, 2019
f52956a
Codestyle and language fix
Hackwar Jan 18, 2019
786421a
EmailTemplateEdit js
Fedik Jan 27, 2019
140b08d
Show/hide tags section. Do not allow to add tag in to disabled input
Fedik Jan 27, 2019
e892aa3
Merge pull request #26 from Fedik/pull22126
Hackwar Jan 27, 2019
d79dc5c
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Mar 15, 2019
c74d621
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Mar 29, 2019
6efe92f
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Apr 10, 2019
0d47f77
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into j…
Hackwar Jun 10, 2019
e43d7d8
Merge branch 'j4mailtemplates' of github.com:Hackwar/joomla-cms into …
Hackwar Jun 10, 2019
9c773a7
JS Codestyle
Hackwar Jun 11, 2019
7eaf6c3
JS Codestyle
Hackwar Jun 11, 2019
0a83161
Fixing SQL install files
Hackwar Jun 11, 2019
2515708
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into j…
Hackwar Jun 11, 2019
f083f96
Fixing SQL
Hackwar Jun 12, 2019
8e556d6
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Jul 13, 2019
9f66708
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Jul 14, 2019
df7c6cd
Codestyle and cleanup of com_mails
Hackwar Jul 14, 2019
882b5e3
Merge branch '4.0-dev' into j4mailtemplates
wilsonge Jul 27, 2019
380e20d
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into j…
Hackwar Jul 28, 2019
b65709e
Fixing merge conflicts
Hackwar Jul 28, 2019
f42b052
Merge branch 'j4mailtemplates' of github.com:Hackwar/joomla-cms into …
Hackwar Jul 28, 2019
cfbeaeb
Fix javascript to remove switcher references
wilsonge Jul 28, 2019
5f322e4
Remove console log
wilsonge Jul 28, 2019
c28abf6
Fix javascript to remove switcher references (#30)
Hackwar Jul 28, 2019
927a6c2
Fixing readonly for textarea
Hackwar Jul 28, 2019
cf2d1a7
Several fixes
Hackwar Jul 29, 2019
b75f060
Removing accidental label
Hackwar Jul 30, 2019
8c4088e
Adding labels, fixing docblocks
Hackwar Jul 31, 2019
2cff8b4
Merge branch 'j4mailtemplates' of github.com:Hackwar/joomla-cms into …
Hackwar Jul 31, 2019
3767972
Clarifying language strings used
Hackwar Aug 1, 2019
99561a2
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Aug 1, 2019
8e2e954
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into j…
Hackwar Aug 15, 2019
077eee3
Merge branch '4.0-dev' into j4mailtemplates
wilsonge Aug 31, 2019
aa4a9ae
Update administrator/components/com_admin/sql/updates/postgresql/4.0.…
Hackwar Sep 2, 2019
a3efef9
Remove obsolete columns from SQL statements
roland-d Sep 3, 2019
30e5d67
Merge pull request #33 from roland-d/code-fixes-j4
Hackwar Sep 3, 2019
e398dcb
Removing false static
Hackwar Sep 4, 2019
28924d2
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Sep 4, 2019
fb29369
Fix tags not showing in html mode
wilsonge Sep 22, 2019
45176dc
Cleanup template model doc block
wilsonge Sep 22, 2019
0c4b3bb
Start work on disabled function
wilsonge Sep 22, 2019
e2f353a
If textarea has readonly attribute start tinymce in readonly mode
wilsonge Sep 25, 2019
1f2b62c
Add function to codemirro
wilsonge Sep 26, 2019
ac21fe6
Simplify editor none
wilsonge Sep 26, 2019
e5cd50a
Editor disabled (#35)
Hackwar Sep 27, 2019
4c11029
Merge branch '4.0-dev' into j4mailtemplates
Hackwar Sep 27, 2019
7cb22eb
Merge branch '4.0-dev' into j4mailtemplates
wilsonge Sep 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE TABLE IF NOT EXISTS `#__mail_templates` (
`mail_id` VARCHAR(127) NOT NULL DEFAULT '',
`language` char(7) NOT NULL DEFAULT '',
`subject` VARCHAR(255) NOT NULL DEFAULT '',
`body` TEXT NOT NULL,
`htmlbody` TEXT NOT NULL,
`attachments` TEXT NOT NULL,
`params` TEXT NOT NULL,
PRIMARY KEY (`mail_id`, `language`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

INSERT INTO `#__mail_templates` (`mail_id`, `language`, `subject`, `body`, `htmlbody`, `attachments`, `params`) VALUES ('com_config.test_mail', '', 'COM_CONFIG_SENDMAIL_SUBJECT', 'COM_CONFIG_SENDMAIL_BODY', '', '', '{"tags":["sitename","method"]}');
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
INSERT INTO `#__extensions` (`extension_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES
(37, 'com_mails', 'component', 'com_mails', '', 1, 1, 1, 1, '{"name":"com_mails","type":"component","creationDate":"January 2019","author":"Joomla! Project","copyright":"(C) 2005 - 2018 Open Source Matters. All rights reserved.","authorEmail":"[email protected]","authorUrl":"www.joomla.org","version":"4.0.0","description":"COM_MAILS_XML_DESCRIPTION","group":""}', '{}', '', '', 0, '0000-00-00 00:00:00', 0, 0);

CREATE TABLE IF NOT EXISTS `#__mail_templates` (
`template_id` VARCHAR(127) NOT NULL DEFAULT '',
`language` char(7) NOT NULL DEFAULT '',
`subject` VARCHAR(255) NOT NULL DEFAULT '',
`body` TEXT NOT NULL,
`htmlbody` TEXT NOT NULL,
`attachments` TEXT NOT NULL,
`params` TEXT NOT NULL,
PRIMARY KEY (`template_id`, `language`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

INSERT INTO `#__mail_templates` (`template_id`, `language`, `subject`, `body`, `htmlbody`, `attachments`, `params`) VALUES ('com_config.test_mail', '', 'COM_CONFIG_SENDMAIL_SUBJECT', 'COM_CONFIG_SENDMAIL_BODY', '', '', '{"tags":["sitename","method"]}');
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE TABLE IF NOT EXISTS "#__mail_templates" (
"mail_id" varchar(127) NOT NULL DEFAULT '',
"language" char(7) NOT NULL DEFAULT '',
"subject" varchar(255) NOT NULL DEFAULT '',
"body" TEXT NOT NULL,
"htmlbody" TEXT NOT NULL,
"attachments" TEXT NOT NULL,
"params" TEXT NOT NULL,
CONSTRAINT "#__mail_templates_idx_mail_id_language" UNIQUE ("mail_id", "language"),
);
CREATE INDEX "#__mail_templates_idx_mail_id" ON "#__mail_templates" ("mail_id");
CREATE INDEX "#__mail_templates_idx_language" ON "#__mail_templates" ("language");

INSERT INTO "#__mail_templates" ("mail_id", "language", "subject", "body", "htmlbody", "attachments", "params") VALUES ('com_config.test_mail', '', 'COM_CONFIG_SENDMAIL_SUBJECT', 'COM_CONFIG_SENDMAIL_BODY', '', '', '{"tags":["sitename","method"]}');
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
INSERT INTO "#__extensions" ("extension_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "custom_data", "system_data", "checked_out", "checked_out_time", "ordering", "state") VALUES
(37, 'com_mails', 'component', 'com_mails', '', 1, 1, 1, 1, '{"name":"com_mails","type":"component","creationDate":"January 2019","author":"Joomla! Project","copyright":"(C) 2005 - 2018 Open Source Matters. All rights reserved.","authorEmail":"[email protected]","authorUrl":"www.joomla.org","version":"4.0.0","description":"COM_MAILS_XML_DESCRIPTION","group":""}', '{}', '', '', 0, '0000-00-00 00:00:00', 0, 0);

CREATE TABLE IF NOT EXISTS "#__mail_templates" (
"template_id" varchar(127) NOT NULL DEFAULT '',
"language" char(7) NOT NULL DEFAULT '',
"subject" varchar(255) NOT NULL DEFAULT '',
"body" TEXT NOT NULL,
"htmlbody" TEXT NOT NULL,
"attachments" TEXT NOT NULL,
"params" TEXT NOT NULL,
CONSTRAINT "#__mail_templates_idx_template_id_language" UNIQUE ("template_id", "language"),
);
CREATE INDEX "#__mail_templates_idx_template_id" ON "#__mail_templates" ("template_id");
CREATE INDEX "#__mail_templates_idx_language" ON "#__mail_templates" ("language");

INSERT INTO "#__mail_templates" ("template_id", "language", "subject", "body", "htmlbody", "attachments", "params") VALUES ('com_config.test_mail', '', 'COM_CONFIG_SENDMAIL_SUBJECT', 'COM_CONFIG_SENDMAIL_BODY', '', '', '{"tags":["sitename","method"]}');
315 changes: 315 additions & 0 deletions administrator/components/com_config/Controller/MailController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_config
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Config\Administrator\Controller;

defined('_JEXEC') or die;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;

/**
* The mail controller
*
* @since __DEPLOY_VERSION__
*/
class MailController extends FormController
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'default_task', 'model_path', and
* 'view_path' (this list is not meant to be comprehensive).
* @param MVCFactoryInterface $factory The factory.
* @param CMSApplication $app The JApplication for the dispatcher
* @param \JInput $input Input
*
* @since __DEPLOY_VERSION__
* @throws \Exception
*/
public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null)
{
parent::__construct($config, $factory, $app, $input);

$this->view_item = 'mail';
$this->view_list = 'mails';
}

/**
* Method to check if you can add a new record.
*
* @param array $data An array of input data.
*
* @return boolean
*
* @since __DEPLOY_VERSION__
*/
protected function allowAdd($data = [])
{
return false;
}

/**
* Method to check if you can edit a record.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
*
* @since __DEPLOY_VERSION__
*/
protected function allowEdit($data = array(), $key = 'id')
{
return true;
}

/**
* Method to edit an existing record.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key
* (sometimes required to avoid router collisions).
*
* @return boolean True if access level check and checkout passes, false otherwise.
*
* @since __DEPLOY_VERSION__
*/
public function edit($key = null, $urlVar = null)
{
// Do not cache the response to this, its a redirect, and mod_expires and google chrome browser bugs cache it forever!
$this->app->allowCache(false);

$context = "$this->option.edit.$this->context";

// Get the previous record id (if any) and the current record id.
$mail_id = $this->input->getCmd('mail_id');
$language = $this->input->getCmd('language');

// Access check.
if (!$this->allowEdit(array('mail_id' => $mail_id, 'language' => $language), $mail_id))
{
$this->setMessage(Text::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'), 'error');

$this->setRedirect(
Route::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToListAppend(), false
)
);

return false;
}

// Check-out succeeded, push the new record id into the session.
$this->holdEditId($context, $mail_id . '.' . $language);
$this->app->setUserState($context . '.data', null);

$this->setRedirect(
Route::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend(array($mail_id, $language), 'mail_id'), false
)
);

return true;
}

/**
* Gets the URL arguments to append to an item redirect.
*
* @param string[] $recordId The primary key id for the item in the first element and the language of the
* mail template in the second key.
* @param string $urlVar The name of the URL variable for the id.
*
* @return string The arguments to append to the redirect URL.
*
* @since __DEPLOY_VERSION__
*/
protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id')
{
$language = array_pop($recordId);
$return = parent::getRedirectToItemAppend(array_pop($recordId), $urlVar);
$return .= '&language=' . $language;

return $return;
}

/**
* Method to save a record.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
*
* @return boolean True if successful, false otherwise.
*
* @since __DEPLOY_VERSION__
*/
public function save($key = null, $urlVar = null)
{
// Check for request forgeries.
$this->checkToken();

/** @var \Joomla\CMS\MVC\Model\AdminModel $model */
$model = $this->getModel();
$data = $this->input->post->get('jform', array(), 'array');
$context = "$this->option.edit.$this->context";
$task = $this->getTask();

$recordId = $this->input->getCmd('mail_id');
$language = $this->input->getCmd('language');

// Populate the row id from the session.
$data['mail_id'] = $recordId;
$data['language'] = $language;

// Access check.
if (!$this->allowSave($data, 'mail_id'))
{
$this->setMessage(Text::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'), 'error');

$this->setRedirect(
Route::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToListAppend(), false
)
);

return false;
}

// Validate the posted data.
// Sometimes the form needs some posted data, such as for plugins and modules.
$form = $model->getForm($data, false);

if (!$form)
{
$this->app->enqueueMessage($model->getError(), 'error');

return false;
}

// Send an object which can be modified through the plugin event
$objData = (object) $data;
$this->app->triggerEvent(
'onContentNormaliseRequestData',
array($this->option . '.' . $this->context, $objData, $form)
);
$data = (array) $objData;

// Test whether the data is valid.
$validData = $model->validate($form, $data);

// Check for validation errors.
if ($validData === false)
{
// Get the validation messages.
$errors = $model->getErrors();

// Push up to three validation messages out to the user.
for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
{
if ($errors[$i] instanceof \Exception)
{
$this->app->enqueueMessage($errors[$i]->getMessage(), 'warning');
}
else
{
$this->app->enqueueMessage($errors[$i], 'warning');
}
}

// Save the data in the session.
$this->app->setUserState($context . '.data', $data);

// Redirect back to the edit screen.
$this->setRedirect(
Route::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend(array($recordId, $language), 'mail_id'), false
)
);

return false;
}

// Attempt to save the data.
if (!$model->save($validData))
{
// Save the data in the session.
$this->app->setUserState($context . '.data', $validData);

// Redirect back to the edit screen.
$this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()), 'error');

$this->setRedirect(
Route::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend(array($recordId, $language), 'mail_id'), false
)
);

return false;
}

$langKey = $this->text_prefix . ($recordId === 0 && $this->app->isClient('site') ? '_SUBMIT' : '') . '_SAVE_SUCCESS';
$prefix = Factory::getLanguage()->hasKey($langKey) ? $this->text_prefix : 'JLIB_APPLICATION';

$this->setMessage(Text::_($prefix . ($recordId === 0 && $this->app->isClient('site') ? '_SUBMIT' : '') . '_SAVE_SUCCESS'));

// Redirect the user and adjust session state based on the chosen task.
switch ($task)
{
case 'apply':
// Set the record data in the session.
$this->holdEditId($context, $recordId);
$this->app->setUserState($context . '.data', null);

// Redirect back to the edit screen.
$this->setRedirect(
Route::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend(array($recordId, $language), 'mail_id'), false
)
);
break;

default:
// Clear the record id and data from the session.
$this->releaseEditId($context, $recordId);
$this->app->setUserState($context . '.data', null);

$url = 'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToListAppend();

// Check if there is a return value
$return = $this->input->get('return', null, 'base64');

if (!is_null($return) && Uri::isInternal(base64_decode($return)))
{
$url = base64_decode($return);
}

// Redirect to the list screen.
$this->setRedirect(Route::_($url, false));
break;
}

// Invoke the postSave method to allow for the child class to access the model.
$this->postSaveHook($model, $validData);

return true;
}
}
Loading