Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Feat: Introduce Mail Template Layout #43829

Merged
merged 27 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5c5853b
[5.2] [WIP] Feat: Add mail template layout as wrapper for mails
LadySolveig Jul 22, 2024
67ca7f9
cs
LadySolveig Jul 23, 2024
110f5c8
fix cs
LadySolveig Jul 23, 2024
65284e5
cs
LadySolveig Jul 23, 2024
c7a9bf0
Fix order in xml field
LadySolveig Jul 23, 2024
641d6aa
Update layouts/joomla/mail/mailtemplate.php
LadySolveig Jul 23, 2024
cd3e5af
Update administrator/language/en-GB/com_config.ini
LadySolveig Jul 23, 2024
16d272e
Update administrator/language/en-GB/com_config.ini
LadySolveig Jul 23, 2024
9697528
Update administrator/language/en-GB/com_mails.ini
LadySolveig Jul 23, 2024
e0dbe30
Update administrator/language/en-GB/com_mails.ini
LadySolveig Jul 23, 2024
cc4d8fc
Remove modification in layout that was replacing the scheme with 'ww…
LadySolveig Jul 23, 2024
1f53da6
Update layouts/joomla/mail/mailtemplate.php
LadySolveig Jul 23, 2024
abe2893
Merge branch '5.2-dev' into 5.2/feat/mailtemplate
Hackwar Jul 23, 2024
5d2ab24
Merge remote-tracking branch 'origin/5.2-dev' into 5.2/feat/mailtemplate
LadySolveig Jul 25, 2024
6ebad04
various improvements, fixes and additional option `disable logofile`
LadySolveig Jul 25, 2024
277f842
phpcs-fixer + suggestions from review
LadySolveig Jul 25, 2024
f3ff895
ISO 2 Letter Language Code dynamic in layout
LadySolveig Jul 25, 2024
69fec91
Fixed cid 'site-logo' for attached logo image
LadySolveig Jul 25, 2024
2f5ed0d
Allow image files with whitespace and rename variable name
LadySolveig Jul 25, 2024
14b94af
Merge remote-tracking branch 'myjoomla/5.2/feat/mailtemplate' into 5.…
LadySolveig Jul 25, 2024
44d956e
dynamic lang code part 2
LadySolveig Jul 25, 2024
83724a0
cs and remove second lang definition from layout
LadySolveig Jul 25, 2024
1e2cb33
Fix no tatic HtmlHelper
LadySolveig Jul 25, 2024
334c6d9
Fix db->quote missing
LadySolveig Jul 26, 2024
c2499df
remove empty space
LadySolveig Jul 26, 2024
ca816ae
improve query
LadySolveig Jul 26, 2024
10ef318
Merge branch '5.2-dev' into 5.2/feat/mailtemplate
Hackwar Jul 26, 2024
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
34 changes: 33 additions & 1 deletion administrator/components/com_mails/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<inlinehelp button="show"/>
<fieldset
name="mails_options"
label="COM_MAILS_CONFIG_MAIL_OPTIONS" >
label="COM_MAILS_CONFIG_MAIL_OPTIONS"
addfieldprefix="Joomla\Component\Mails\Administrator\Field" >
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved

<field
name="mail_style"
Expand Down Expand Up @@ -49,6 +50,37 @@
exclude="administrator|api|cache|cli|components|includes|language|layouts|libraries|modules|plugins|templates|tmp"
/>

<field
name="disable_htmllayout"
type="radio"
label="COM_CONFIG_FIELD_MAILTEMPLATE_LAYOUT_OFF_LABEL"
layout="joomla.form.field.radio.switcher"
default="1"
showon="mail_style:html[OR]mail_style:both"
>
<option value="0">JDISABLED</option>
<option value="1">JENABLED</option>
</field>

<field
name="mail_htmllayout"
type="mailtemplateLayout"
label="COM_CONFIG_FIELD_MAILTEMPLATE_LAYOUT_LABEL"
class="form-select"
showon="mail_style:html[OR]mail_style:both[AND]disable_htmllayout:1"
/>

<field
name="mail_logoFile"
type="media"
schemes="http,https,ftp,ftps,data,file"
validate="url"
relative="true"
default=""
label="COM_CONFIG_FIELD_MAILTEMPLATE_LOGOFILE_LABEL"
showon="mail_style:html[OR]mail_style:both[AND]disable_htmllayout:1"
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
/>

</fieldset>

<fieldset
Expand Down
22 changes: 21 additions & 1 deletion administrator/components/com_mails/forms/template.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<form addfieldprefix="Joomla\Component\Mails\Administrator\Field">
<fieldset>
<field
name="template_id"
Expand Down Expand Up @@ -205,6 +205,26 @@
default=""
filter="string"
/>

<field
name="disable_htmllayout"
type="radio"
label="COM_MAILS_FIELD_HTML_LAYOUT_OFF_LABEL"
layout="joomla.form.field.radio.switcher"
default="1"
>
<option value="0">JDISABLED</option>
<option value="1">JENABLED</option>
</field>

<field
name="htmllayout"
type="mailtemplateLayout"
label="COM_MAILS_FIELD_HTML_LAYOUT_LABEL"
class="form-select"
showon="disable_htmllayout:1"
/>

</fieldset>
</fields>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage com_mails
*
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Mails\Administrator\Field;

use Joomla\CMS\Form\FormField;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\Filesystem\Folder;
use Joomla\Filesystem\Path;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Form Field to display a list of the layouts for a field from
* the extension or template overrides.
*
* @since __DEPLOY_VERSION__
*/
class MailtemplateLayoutField extends FormField
{
/**
* The form field type.
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected $type = 'MailtemplateLayout';

/**
* Method to get the field input for a field layout field.
*
* @return string The field input.
*
* @since __DEPLOY_VERSION__
*/
protected function getInput()
{
// $extension = explode('.', $this->form->getValue('context'));
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
// $extension = $extension[0];

// Get the database object and a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);

// Build the query.
$query->select('element, name')
->from('#__extensions')
->where('client_id = 0')
->where('type = ' . $db->quote('template'))
->where('enabled = 1');
HLeithner marked this conversation as resolved.
Show resolved Hide resolved

// Set the query and load the templates.
$db->setQuery($query);
$templates = $db->loadObjectList('element');

// Prepare the grouped list
$groups = [];

// Add "Use Default"
$groups[]['items'][] = HTMLHelper::_('select.option', '', Text::_('JOPTION_USE_DEFAULT'));

// Loop on all templates
if ($templates) {
foreach ($templates as $template) {
$files = [];
$template_paths = [
Path::clean(JPATH_SITE . '/templates/' . $template->element . '/html/layouts/joomla/mail'),
Path::clean(JPATH_SITE . '/templates/' . $template->element . '/html/layouts/com_mails/joomla/mail'),
];

// Add the layout options from the template paths.
foreach ($template_paths as $template_path) {
if (is_dir($template_path)) {
$files = array_merge($files, Folder::files($template_path, '^[^_]*\.php$', false, true));
}
}

if (\count($files)) {
// Create the group for the template
$groups[$template->name] = [];
$groups[$template->name]['id'] = $this->id . '_' . $template->element;
$groups[$template->name]['text'] = Text::sprintf('JOPTION_FROM_TEMPLATE', $template->name);
$groups[$template->name]['items'] = [];

foreach ($files as $file) {
// Add an option to the template group
$value = basename($file, '.php');
$groups[$template->name]['items'][] = HTMLHelper::_('select.option', $value, $value);
}
}
}
}

// Compute attributes for the grouped list
$attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';

// Prepare HTML code
$html = [];

// Compute the current selected values
$selected = [$this->value];

// Add a grouped list
$html[] = HTMLHelper::_(
'select.groupedlist',
$groups,
$this->name,
['id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected]
);

return implode($html);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public function getForm($data = [], $loadData = true)

if ($params->get('mail_style', 'plaintext') == 'plaintext') {
$form->removeField('htmlbody');
$form->removeField('disable_htmllayout', 'params');
$form->removeField('htmllayout', 'params');
}

if ($params->get('mail_style', 'plaintext') == 'html') {
Expand Down
3 changes: 3 additions & 0 deletions administrator/language/en-GB/com_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ COM_CONFIG_FIELD_MAIL_SMTP_PASSWORD_LABEL="SMTP Password"
COM_CONFIG_FIELD_MAIL_SMTP_PORT_LABEL="SMTP Port"
COM_CONFIG_FIELD_MAIL_SMTP_SECURE_LABEL="SMTP Security"
COM_CONFIG_FIELD_MAIL_SMTP_USERNAME_LABEL="SMTP Username"
COM_CONFIG_FIELD_MAILTEMPLATE_LAYOUT_LABEL="Mail Template Layout"
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
COM_CONFIG_FIELD_MAILTEMPLATE_LAYOUT_OFF_LABEL="Disable Mail Template Layout"
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
COM_CONFIG_FIELD_MAILTEMPLATE_LOGOFILE_LABEL="Logo File"
COM_CONFIG_FIELD_MEMCACHE_COMPRESSION_LABEL="Memcache(d) Compression"
COM_CONFIG_FIELD_MEMCACHE_HOST_LABEL="Memcache(d) Server Host"
COM_CONFIG_FIELD_MEMCACHE_PERSISTENT_LABEL="Persistent Memcache(d)"
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/com_mails.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ COM_MAILS_FIELD_BODY_LABEL="Body"
COM_MAILS_FIELD_FILE_LABEL="File"
COM_MAILS_FIELD_FILENAME_LABEL="File Name"
COM_MAILS_FIELD_HTMLBODY_LABEL="HTML Body"
COM_MAILS_FIELD_HTML_LAYOUT_LABEL="Mail Template Layout"
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
COM_MAILS_FIELD_HTML_LAYOUT_OFF_LABEL="Disable Mail Template Layout"
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
COM_MAILS_FIELD_LANGUAGE_CODE_INVALID="Invalid Language Code"
COM_MAILS_FIELD_MAIL_COPY_MAIL_LABEL="Send Copy To Email"
COM_MAILS_FIELD_MAIL_FROM_EMAIL_LABEL="From Email"
Expand Down
113 changes: 113 additions & 0 deletions layouts/joomla/mail/mailtemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

/**
* @package Joomla.Site
* @subpackage com_mails
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
*
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

use Joomla\CMS\Uri\Uri;

defined('_JEXEC') or die;

// Check if we have all the data
if (!array_key_exists('mail', $displayData)) {
return;
}

// Setting up for display
$mailBody = $displayData['mail'];

if (!$mailBody) {
return;
}

$extraData = [];

if (array_key_exists('extra', $displayData)) {
$extraData = $displayData['extra'];
}

$siteUrl = Uri::root(false);

?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="x-apple-disable-message-reformatting">
<!--[if !mso]><!-->
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<!--<![endif]-->
<title></title>
<!--[if mso]>
<style>
table {border-collapse:collapse;border-spacing:0;border:none;margin:0;}
div, td {padding:0;}
div {margin:0 !important;}
</style>
<noscript>
<xml>
<o:OfficeDocumentSettings>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
</noscript>
<![endif]-->
<style>
html {height: 100%;}
table, td, div, h1, p { font-family: Arial, sans-serif; }
</style>
</head>
<body style="margin:0;padding:0;word-spacing:normal;background-color:#00000008;height:100%;">
<div role="article" aria-roledescription="email" lang="en" style="text-size-adjust:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;background-color:#00000008;height:100%;">
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
<table role="presentation" style="width:100%;border:none;border-spacing:0;height:100%;">
<tr>
<td align="center" style="vertical-align:baseline; padding:30px 0">
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
<!--[if mso]>
<table role="presentation" align="center" style="width:630px;">
<tr>
<td>
<![endif]-->
<table role="presentation" style="width:94%;max-width:630px;border:none;border-spacing:0;text-align:left;font-family:Arial,sans-serif;font-size:16px;line-height:22px;color:#363636;">
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
<tr>
<td style="padding:40px 30px 0 30px;text-align:center;font-size:24px;font-weight:bold;background-color:#ffffff;">
<?php if (isset($extraData['logo']) || isset($extraData['siteName'])) : ?>
<?php if (isset($extraData['logo'])) : ?>
<img src="cid:<?php echo htmlspecialchars($extraData['logo'], ENT_QUOTES);?>" alt="<?php echo (isset($extraData['siteName']) ? $extraData['siteName'] : 'Logo');?>" style="max-width:80%;height:auto;border:none;text-decoration:none;color:#ffffff;">
<?php else : ?>
<h1 style="margin-top:0;margin-bottom:0;font-size:26px;line-height:32px;font-weight:bold;letter-spacing:-0.02em;color:#112855;">
<?php echo $extraData['siteName']; ?>
</h1>
<?php endif; ?>
<div style="padding: 30px 0 0;"></div>
<div style="padding:.75px;background-color:#0000000f;"></div>
</td>
</tr>
<tr>
<td style="padding:30px;background-color:#ffffff;">
<?php endif; ?>
<?php echo $mailBody; ?>
</td>
</tr>
<tr>
<td style="padding:30px;text-align:center;font-size:12px;background-color:#112855;color:#cccccc;">
<p style="margin:0;font-size:14px;line-height:20px;">&reg; <?php echo isset($extraData['siteName']) ? $extraData['siteName'] . ' ' : ''; ?><?php echo date("Y"); ?>
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
<br><a title="<?php echo $siteUrl;?>" href="<?php echo $siteUrl; ?>" style="color:#cccccc;text-decoration:underline;"><?php echo substr_replace($siteUrl, 'www.', 0, strlen(Uri::getInstance()->toString(['scheme'])));?></a>
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
</td>
</tr>
</table>
<!--[if mso]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
</table>
</div>
</body>
</html>
Loading