Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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,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"]}');
Original file line number Diff line number Diff line change
@@ -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"]}');
4 changes: 4 additions & 0 deletions administrator/language/en-GB/plg_content_joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion installation/sql/mysql/supports.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}');
3 changes: 2 additions & 1 deletion installation/sql/postgresql/supports.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}');
1 change: 1 addition & 0 deletions language/en-GB/com_content.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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:<br>New articles default to the first position in the Category. The ordering can be changed in Backend."
COM_CONTENT_PAGEBREAK_DOC_TITLE="Page Break"
Expand Down
49 changes: 31 additions & 18 deletions plugins/content/joomla/src/Extension/Joomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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');
}
}
}
}
}
Expand Down