diff --git a/administrator/components/com_admin/sql/updates/mysql/6.0.0-2025-03-25.sql b/administrator/components/com_admin/sql/updates/mysql/6.0.0-2025-03-25.sql new file mode 100644 index 0000000000000..88870f1196465 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/6.0.0-2025-03-25.sql @@ -0,0 +1,2 @@ +INSERT INTO `#__mail_templates` (`template_id`, `extension`, `language`, `subject`, `body`, `htmlbody`, `attachments`, `params`) VALUES +('plg_content_joomla.newarticle', 'plg_content_joomla', '', 'PLG_CONTENT_JOOMLA_NEW_ARTICLE_SUBJECT', 'PLG_CONTENT_JOOMLA_NEW_ARTICLE_BODY', '', '', '{"tags":["sitename","name","email","title","url"]}'); diff --git a/administrator/components/com_admin/sql/updates/postgresql/6.0.0-2025-03-25.sql b/administrator/components/com_admin/sql/updates/postgresql/6.0.0-2025-03-25.sql new file mode 100644 index 0000000000000..0fcab19b08774 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/postgresql/6.0.0-2025-03-25.sql @@ -0,0 +1,2 @@ +INSERT INTO "#__mail_templates" ("template_id", "extension", "language", "subject", "body", "htmlbody", "attachments", "params") VALUES +('plg_content_joomla.newarticle', 'plg_content_joomla', '', 'PLG_CONTENT_JOOMLA_NEW_ARTICLE_SUBJECT', 'PLG_CONTENT_JOOMLA_NEW_ARTICLE_BODY', '', '', '{"tags":["sitename","name","email","title","url"]}'); diff --git a/administrator/language/en-GB/plg_content_joomla.ini b/administrator/language/en-GB/plg_content_joomla.ini index 5b818a07e48e6..6ef078e4cc78c 100644 --- a/administrator/language/en-GB/plg_content_joomla.ini +++ b/administrator/language/en-GB/plg_content_joomla.ini @@ -8,6 +8,10 @@ PLG_CONTENT_JOOMLA_FIELD_CHECK_CATEGORIES_DESC="Check that categories are fully PLG_CONTENT_JOOMLA_FIELD_CHECK_CATEGORIES_LABEL="Check Category Deletion" PLG_CONTENT_JOOMLA_FIELD_EMAIL_NEW_FE_DESC="Email users if 'Send email' is on when there is a new article submitted via the Frontend." PLG_CONTENT_JOOMLA_FIELD_EMAIL_NEW_FE_LABEL="Email on New Site Article" +PLG_CONTENT_JOOMLA_MAIL_NEWARTICLE_DESC="Sent when a new article is submitted via frontend." +PLG_CONTENT_JOOMLA_MAIL_NEWARTICLE_TITLE="Content: New Article Submitted" +PLG_CONTENT_JOOMLA_NEW_ARTICLE_BODY="A new Article has been submitted by {NAME} entitled {TITLE}." +PLG_CONTENT_JOOMLA_NEW_ARTICLE_SUBJECT="[{SITENAME}] - New Article Submitted" PLG_CONTENT_JOOMLA_SCHEMA_CONTACT_DESC="When active, generate contact rich snippets from the default data" PLG_CONTENT_JOOMLA_SCHEMA_CONTACT_LABEL="Contact Schema" PLG_CONTENT_JOOMLA_SCHEMA_CONTENT_DESC="When active, generate content rich snippets from the default data" diff --git a/installation/sql/mysql/supports.sql b/installation/sql/mysql/supports.sql index bf0a661b0ba37..c5078df0f63fa 100644 --- a/installation/sql/mysql/supports.sql +++ b/installation/sql/mysql/supports.sql @@ -437,4 +437,5 @@ INSERT INTO `#__mail_templates` (`template_id`, `extension`, `language`, `subjec ('plg_system_tasknotification.fatal_recovery_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_FATAL_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_FATAL_MAIL_BODY', '', '', '{"tags": ["task_id", "task_title"]}'), ('plg_system_tasknotification.orphan_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_ORPHAN_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_ORPHAN_MAIL_BODY', '', '', '{"tags": ["task_id", "task_title"]}'), ('plg_system_tasknotification.success_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_SUCCESS_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_SUCCESS_MAIL_BODY', '', '', '{"tags":["task_id", "task_title", "exec_data_time", "task_output"]}'), -('plg_multifactorauth_email.mail', 'plg_multifactorauth_email', '', 'PLG_MULTIFACTORAUTH_EMAIL_EMAIL_SUBJECT', 'PLG_MULTIFACTORAUTH_EMAIL_EMAIL_BODY', '', '', '{"tags":["code","sitename","siteurl","username","email","fullname"]}'); +('plg_multifactorauth_email.mail', 'plg_multifactorauth_email', '', 'PLG_MULTIFACTORAUTH_EMAIL_EMAIL_SUBJECT', 'PLG_MULTIFACTORAUTH_EMAIL_EMAIL_BODY', '', '', '{"tags":["code","sitename","siteurl","username","email","fullname"]}'), +('plg_content_joomla.newarticle', 'plg_content_joomla', '', 'PLG_CONTENT_JOOMLA_NEW_ARTICLE_SUBJECT', 'PLG_CONTENT_JOOMLA_NEW_ARTICLE_BODY', '', '', '{"tags":["sitename","name","email","title","url"]}'); diff --git a/installation/sql/postgresql/supports.sql b/installation/sql/postgresql/supports.sql index 1478ef3ce2575..7c64e3f868e5b 100644 --- a/installation/sql/postgresql/supports.sql +++ b/installation/sql/postgresql/supports.sql @@ -448,4 +448,5 @@ INSERT INTO "#__mail_templates" ("template_id", "extension", "language", "subjec ('plg_system_tasknotification.fatal_recovery_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_FATAL_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_FATAL_MAIL_BODY', '', '', '{"tags": ["task_id", "task_title"]}'), ('plg_system_tasknotification.orphan_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_ORPHAN_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_ORPHAN_MAIL_BODY', '', '', '{"tags": ["task_id", "task_title"]}'), ('plg_system_tasknotification.success_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_SUCCESS_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_SUCCESS_MAIL_BODY', '', '', '{"tags":["task_id", "task_title", "exec_data_time", "task_output"]}'), -('plg_multifactorauth_email.mail', 'plg_multifactorauth_email', '', 'PLG_MULTIFACTORAUTH_EMAIL_EMAIL_SUBJECT', 'PLG_MULTIFACTORAUTH_EMAIL_EMAIL_BODY', '', '', '{"tags":["code","sitename","siteurl","username","email","fullname"]}'); +('plg_multifactorauth_email.mail', 'plg_multifactorauth_email', '', 'PLG_MULTIFACTORAUTH_EMAIL_EMAIL_SUBJECT', 'PLG_MULTIFACTORAUTH_EMAIL_EMAIL_BODY', '', '', '{"tags":["code","sitename","siteurl","username","email","fullname"]}'), +('plg_content_joomla.newarticle', 'plg_content_joomla', '', 'PLG_CONTENT_JOOMLA_NEW_ARTICLE_SUBJECT', 'PLG_CONTENT_JOOMLA_NEW_ARTICLE_BODY', '', '', '{"tags":["sitename","name","email","title","url"]}'); diff --git a/language/en-GB/com_content.ini b/language/en-GB/com_content.ini index 981736b228fad..ee2d46aaad012 100644 --- a/language/en-GB/com_content.ini +++ b/language/en-GB/com_content.ini @@ -67,6 +67,7 @@ COM_CONTENT_MORE_ARTICLES="More Articles …" COM_CONTENT_NEW_ARTICLE="New Article" COM_CONTENT_NO_ARTICLES="There are no articles in this category. If subcategories display on this page, they may have articles." COM_CONTENT_NUM_ITEMS="Article Count:" +;Deprecated, will be removed in 7.0 COM_CONTENT_ON_NEW_CONTENT="A new Article has been submitted by '%1$s' entitled '%2$s'." COM_CONTENT_ORDERING="Ordering:
New articles default to the first position in the Category. The ordering can be changed in Backend." COM_CONTENT_PAGEBREAK_DOC_TITLE="Page Break" diff --git a/plugins/content/joomla/src/Extension/Joomla.php b/plugins/content/joomla/src/Extension/Joomla.php index cf07a50490b78..3590804504fd6 100644 --- a/plugins/content/joomla/src/Extension/Joomla.php +++ b/plugins/content/joomla/src/Extension/Joomla.php @@ -11,7 +11,6 @@ namespace Joomla\Plugin\Content\Joomla\Extension; use Joomla\CMS\Cache\CacheControllerFactory; -use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Event\Model\AfterChangeStateEvent; use Joomla\CMS\Event\Model\AfterSaveEvent; use Joomla\CMS\Event\Model\BeforeChangeStateEvent; @@ -20,9 +19,13 @@ use Joomla\CMS\Event\Plugin\System\Schemaorg\BeforeCompileHeadEvent; use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; -use Joomla\CMS\Language\Language; use Joomla\CMS\Language\Text; +use Joomla\CMS\Log\Log; +use Joomla\CMS\Mail\Exception\MailDisabledException; +use Joomla\CMS\Mail\MailTemplate; use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\CMS\Router\Route; +use Joomla\CMS\String\PunycodeHelper; use Joomla\CMS\Table\CoreContent; use Joomla\CMS\Uri\Uri; use Joomla\CMS\User\UserFactoryAwareTrait; @@ -34,6 +37,7 @@ use Joomla\Event\SubscriberInterface; use Joomla\Registry\Registry; use Joomla\Utilities\ArrayHelper; +use PHPMailer\PHPMailer\Exception as phpMailerException; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -163,26 +167,35 @@ public function onContentAfterSave(AfterSaveEvent $event): void } $user = $this->getApplication()->getIdentity(); + $this->loadLanguage(); - // Messaging for new items - - $default_language = ComponentHelper::getParams('com_languages')->get('administrator'); - $debug = $this->getApplication()->get('debug_lang'); - + // Emailing for new items foreach ($users as $user_id) { if ($user_id != $user->id) { - // Load language for messaging - $receiver = $this->getUserFactory()->loadUserById($user_id); - $lang = Language::getInstance($receiver->getParam('admin_language', $default_language), $debug); - $lang->load('com_content'); - $message = [ - 'user_id_to' => $user_id, - 'subject' => $lang->_('COM_CONTENT_NEW_ARTICLE'), - 'message' => \sprintf($lang->_('COM_CONTENT_ON_NEW_CONTENT'), $user->name, $article->title), + $receiver = $this->getUserFactory()->loadUserById($user_id); + $linkMode = $this->getApplication()->get('force_ssl', 0) == 2 ? Route::TLS_FORCE : Route::TLS_IGNORE; + $templateData = [ + 'sitename' => $this->getApplication()->get('sitename'), + 'name' => $user->name, + 'email' => PunycodeHelper::emailToPunycode($user->email), + 'title' => $article->title, + 'url' => Route::link('administrator', 'index.php?option=com_content&view=articles&filter[search]=id:' . $article->id, false, $linkMode, true), ]; - $model_message = $this->getApplication()->bootComponent('com_messages')->getMVCFactory() - ->createModel('Message', 'Administrator'); - $model_message->save($message); + + // Send email + try { + $mailer = new MailTemplate('plg_content_joomla.newarticle', $receiver->getParam('admin_language', $this->getLanguage()->getTag())); + $mailer->addTemplateData($templateData); + $mailer->addRecipient($receiver->email, $receiver->name); + + $mailer->send(); + } catch (MailDisabledException | phpMailerException $exception) { + try { + Log::add(Text::_($exception->getMessage()), Log::WARNING, 'jerror'); + } catch (\RuntimeException $exception) { + $this->getApplication()->enqueueMessage(Text::_($exception->errorMessage()), 'warning'); + } + } } } }