-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[5.2] Feat: Introduce Mail Template Layout #43829
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
Merged
Merged
Changes from 10 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 67ca7f9
cs
LadySolveig 110f5c8
fix cs
LadySolveig 65284e5
cs
LadySolveig c7a9bf0
Fix order in xml field
LadySolveig 641d6aa
Update layouts/joomla/mail/mailtemplate.php
LadySolveig cd3e5af
Update administrator/language/en-GB/com_config.ini
LadySolveig 16d272e
Update administrator/language/en-GB/com_config.ini
LadySolveig 9697528
Update administrator/language/en-GB/com_mails.ini
LadySolveig e0dbe30
Update administrator/language/en-GB/com_mails.ini
LadySolveig cc4d8fc
Remove modification in layout that was replacing the scheme with 'ww…
LadySolveig 1f53da6
Update layouts/joomla/mail/mailtemplate.php
LadySolveig abe2893
Merge branch '5.2-dev' into 5.2/feat/mailtemplate
Hackwar 5d2ab24
Merge remote-tracking branch 'origin/5.2-dev' into 5.2/feat/mailtemplate
LadySolveig 6ebad04
various improvements, fixes and additional option `disable logofile`
LadySolveig 277f842
phpcs-fixer + suggestions from review
LadySolveig f3ff895
ISO 2 Letter Language Code dynamic in layout
LadySolveig 69fec91
Fixed cid 'site-logo' for attached logo image
LadySolveig 2f5ed0d
Allow image files with whitespace and rename variable name
LadySolveig 14b94af
Merge remote-tracking branch 'myjoomla/5.2/feat/mailtemplate' into 5.…
LadySolveig 44d956e
dynamic lang code part 2
LadySolveig 83724a0
cs and remove second lang definition from layout
LadySolveig 1e2cb33
Fix no tatic HtmlHelper
LadySolveig 334c6d9
Fix db->quote missing
LadySolveig c2499df
remove empty space
LadySolveig ca816ae
improve query
LadySolveig 10ef318
Merge branch '5.2-dev' into 5.2/feat/mailtemplate
Hackwar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
administrator/components/com_mails/src/Field/MailtemplateLayoutField.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Outdated
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.
Outdated
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); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Outdated
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.
Outdated
Show resolved
Hide resolved
LadySolveig marked this conversation as resolved.
Outdated
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;">© <?php echo isset($extraData['siteName']) ? $extraData['siteName'] . ' ' : ''; ?><?php echo date("Y"); ?> | ||
| <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.
Outdated
Show resolved
Hide resolved
|
||
| </td> | ||
| </tr> | ||
| </table> | ||
| <!--[if mso]> | ||
| </td> | ||
| </tr> | ||
| </table> | ||
| <![endif]--> | ||
| </td> | ||
| </tr> | ||
| </table> | ||
| </div> | ||
| </body> | ||
| </html> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.