diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f98a6a0..bec1f8e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,12 +15,12 @@ jobs: uses: actions/checkout@v1 - name: Build Joomla Package id: jxbuild - uses: mavrosxristoforos/jxb@1.0 + uses: mavrosxristoforos/jxb@1.0.1 with: build-file: 'build_popfeed.jxb' - name: Get XML id: getxml - uses: mavrosxristoforos/get-xml-info@1.0 + uses: mavrosxristoforos/get-xml-info@1.1.1 with: xml-file: 'popfeed/popfeed.xml' xpath: '//version' diff --git a/popfeed/helper.php b/popfeed/helper.php index 16fdc92..67ee9af 100644 --- a/popfeed/helper.php +++ b/popfeed/helper.php @@ -10,7 +10,13 @@ -------------------------------------------------------------------------*/ // no direct access -defined( '_JEXEC' ) or die( 'Restricted access' ); +\defined( '_JEXEC' ) or die( 'Restricted access' ); + +use \Joomla\CMS\Factory; +use \Joomla\CMS\Language\Text; +use \Joomla\CMS\Uri\Uri; +use \Joomla\CMS\HTML\HTMLHelper; +//use \Joomla\CMS\Plugin\PluginHelper; class PlgPopFeedHelper { @@ -24,6 +30,7 @@ class PlgPopFeedHelper { public $mailer; public $posted_values; private $context; + public $popfeed_text; public function initialize($plg_popfeed, $params, $row, $context) { $this->params = $params; @@ -85,7 +92,7 @@ public function initializeRecipient() { if ($this->params->get('auto_recipient', false)) { // Auto Recipient from article author. if ($this->hasRow && ($this->context != 'mod_custom.content')) { - $user_tmp = JFactory::getUser($this->article->created_by); + $user_tmp = Factory::getUser($this->article->created_by); $this->recipient = $user_tmp->email; } } @@ -111,7 +118,7 @@ public function isNotExcluded() { $catids = explode(',', $catids); } if (count($catids) > 0) { - $db = JFactory::getDBO(); + $db = Factory::getDBO(); $db->setQuery('SELECT COUNT(*) FROM `#__content` '. ' WHERE `id` = "'.$this->article->id.'" '. ' AND `catid` IN ('.implode(',', $catids).')'); @@ -135,7 +142,7 @@ public function isValidComponentView() { $view_array[] = 'category'; } - $input = JFactory::getApplication()->input; + $input = Factory::getApplication()->input; return ( (in_array($input->get('option', '', 'cmd'), $component_array)) && (in_array($input->get('view', '', 'cmd'), $view_array)) ); } @@ -145,9 +152,9 @@ public function addMessage($key, $def, $msg_type) { } public function hasCaptcha() { - return (JFactory::getConfig()->get('captcha') != '0'); + return (Factory::getConfig()->get('captcha') != '0'); /*if ($this->params->get('use_captcha', '1')) { - $db = JFactory::getDBO(); + $db = Factory::getDBO(); $db->setQuery('SELECT COUNT(`extension_id`) FROM `#__extensions` WHERE `type`="plugin" AND `folder`="captcha" AND `enabled`=1'); return $db->loadResult(); } @@ -164,13 +171,13 @@ public function prepareEmail() { if (isset($_POST[$form_id.'_post'])) { $isValidPost = true; if ($this->hasCaptcha()) { - $captcha = JCaptcha::getInstance(JFactory::getConfig()->get('captcha')); - /*JPluginHelper::importPlugin('captcha'); + $captcha = JCaptcha::getInstance(Factory::getConfig()->get('captcha')); + /*PluginHelper::importPlugin('captcha'); $d = JEventDispatcher::getInstance(); $res = $d->trigger('onCheckAnswer', 'not_used'); if( (!isset($res[0])) || (!$res[0]) ) {*/ try { - if (!$captcha->checkAnswer(JFactory::getApplication()->input->get('popfeed_recaptcha_'.$form_id, null, 'string'))) { + if (!$captcha->checkAnswer(Factory::getApplication()->input->get('popfeed_recaptcha_'.$form_id, null, 'string'))) { $this->addMessage('INVALID_CAPTCHA', 'Invalid Captcha', 'error'); $isValidPost = false; } @@ -193,9 +200,9 @@ public function prepareEmail() { $this->addMessage('INVALID_EMAIL', 'Submitted email is invalid. Please try again.', 'error'); } else { - $this->mailer = JFactory::getMailer(); + $this->mailer = Factory::getMailer(); $this->mailer->addRecipient($this->recipient); // One recipient is allowed when initializing. - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $this->mailer->setSender(array($app->getCfg('mailfrom'),$this->posted_values['name'])); if(version_compare(JVERSION, '3.5', 'ge')) { $this->mailer->addReplyTo($this->posted_values['email'], $this->posted_values['name']); @@ -213,18 +220,18 @@ public function prepareEmail() { } public function loadAssets() { - $document = JFactory::getDocument(); + $document = Factory::getDocument(); if ($this->params->get('include_css', true)) { - $document->addStyleSheet(JURI::base().'plugins/content/popfeed/assets/popfeed.css'); + $document->addStyleSheet(Uri::base().'plugins/content/popfeed/assets/popfeed.css'); } if (in_array($this->include_external_libraries, array(0,1))) { // Load jQuery - JHtml::_('jquery.framework'); + HTMLHelper::_('jquery.framework'); } if (in_array($this->include_external_libraries, array(0,2))) { // Load ColorBox - $document->addStyleSheet(JURI::base().'plugins/content/popfeed/assets/colorbox.css'); - $document->addScript(JURI::base().'plugins/content/popfeed/assets/jquery.colorbox-min.js'); + $document->addStyleSheet(Uri::base().'plugins/content/popfeed/assets/colorbox.css'); + $document->addScript(Uri::base().'plugins/content/popfeed/assets/jquery.colorbox-min.js'); } } @@ -251,7 +258,7 @@ public function determinePopFeedText() { public function i18nParam($param, $default) { $value = $this->params->get($param, $default); if ($value != $default) { - $translated_value = JText::_($value, $default); + $translated_value = Text::_($value, $default); if ($translated_value != $default) { $value = $translated_value; } @@ -260,7 +267,7 @@ public function i18nParam($param, $default) { } public function i18n($key, $default) { - return (JText::_($key) == $key) ? $default : JText::_($key); + return (Text::_($key) == $key) ? $default : Text::_($key); } function str_between($p1, $p2, $text) { diff --git a/popfeed/popfeed.php b/popfeed/popfeed.php index 766fc79..ea31df7 100644 --- a/popfeed/popfeed.php +++ b/popfeed/popfeed.php @@ -10,16 +10,17 @@ -------------------------------------------------------------------------*/ // no direct access -defined( '_JEXEC' ) or die( 'Restricted access' ); +\defined( '_JEXEC' ) or die( 'Restricted access' ); -jimport( 'joomla.plugin.plugin' ); +use \Joomla\CMS\Plugin\CMSPlugin; +use \Joomla\CMS\Plugin\PluginHelper; -class plgContentPopFeed extends JPlugin { +class plgContentPopFeed extends CMSPlugin { private function doBeforeDisplay($helper) { $helper->loadAssets(); $form_id = 'popfeed_form_'.$helper->article->id; - include JPluginHelper::getLayoutPath('content', 'popfeed', 'scripts_and_styles'); + include PluginHelper::getLayoutPath('content', 'popfeed', 'scripts_and_styles'); } public function onContentBeforeDisplay($context, &$row, &$params, $page = 0) { @@ -55,15 +56,21 @@ public function onContentPrepare($context, &$row, &$params, $page = 0) { // Comes here only if email should be sent. // Prepare email body. ob_start(); - include JPluginHelper::getLayoutPath('content', 'popfeed', 'email_body'); + include PluginHelper::getLayoutPath('content', 'popfeed', 'email_body'); $email_body = ob_get_clean(); $helper->mailer->setBody($email_body); - if ($helper->mailer->Send() !== true) { - $helper->addMessage('YOUR_FEEDBACK_COULD_NOT_BE_SUBMITTED', 'Your feedback could not be submitted. Please try again.', 'error'); + try { + if ($helper->mailer->Send() !== true) { + $helper->addMessage('YOUR_FEEDBACK_COULD_NOT_BE_SUBMITTED', 'Your feedback could not be submitted. Please try again.', 'error'); + } + else { + $helper->addMessage('THANK_YOU_FOR_YOUR_FEEDBACK', 'Thank you for your feedback.', 'message'); + } } - else { - $helper->addMessage('THANK_YOU_FOR_YOUR_FEEDBACK', 'Thank you for your feedback.', 'message'); + catch(\Throwable $e) { + $helper->addMessage('YOUR_FEEDBACK_COULD_NOT_BE_SUBMITTED', 'Your feedback could not be submitted. Please try again.', 'error'); + $helper->addMessage('POPFEED_ERROR_MESSAGE_KEY', $e->getMessage(), 'error'); // this key intentionally does not exist } } @@ -72,7 +79,7 @@ public function onContentPrepare($context, &$row, &$params, $page = 0) { // Show Form. ob_start(); - include JPluginHelper::getLayoutPath('content', 'popfeed'); + include PluginHelper::getLayoutPath('content', 'popfeed'); $form = ob_get_clean(); $helper->replacePopFeedTag($form, true); // True means to include any messages from the post process. } diff --git a/popfeed/popfeed.xml b/popfeed/popfeed.xml index ea36bf0..727c997 100644 --- a/popfeed/popfeed.xml +++ b/popfeed/popfeed.xml @@ -7,7 +7,7 @@ GNU General Public License mavrosxristoforos@gmail.com https://mavrosxristoforos.com/ -1.6.68 +1.6.71 Usage in content: {popfeed}Your link text{/popfeed}]]> popfeed.php diff --git a/popfeed/tmpl/default.php b/popfeed/tmpl/default.php index 2220dae..ac2c8b6 100644 --- a/popfeed/tmpl/default.php +++ b/popfeed/tmpl/default.php @@ -10,14 +10,16 @@ -------------------------------------------------------------------------*/ // no direct access -defined( '_JEXEC' ) or die( 'Restricted access' ); +\defined( '_JEXEC' ) or die( 'Restricted access' ); + +use \Joomla\CMS\Factory; $form_id = 'popfeed_form_'.$helper->article->id; $a_href = ($helper->popfeed_appearance == '0') ? '#'.$form_id : 'javascript:void(0);'; if ($helper->hasCaptcha()) { // Initialize Captcha - $captcha_field = (JFactory::getConfig()->get('captcha') != '0') ? JCaptcha::getInstance(JFactory::getConfig()->get('captcha'))->display('popfeed_recaptcha_'.$form_id, 'popfeed_recaptcha_'.$form_id, 'g-recaptcha') : ''; + $captcha_field = (Factory::getConfig()->get('captcha') != '0') ? JCaptcha::getInstance(Factory::getConfig()->get('captcha'))->display('popfeed_recaptcha_'.$form_id, 'popfeed_recaptcha_'.$form_id, 'g-recaptcha') : ''; } ?> diff --git a/popfeed/tmpl/email_body.php b/popfeed/tmpl/email_body.php index 03a6e53..8527818 100644 --- a/popfeed/tmpl/email_body.php +++ b/popfeed/tmpl/email_body.php @@ -10,7 +10,7 @@ -------------------------------------------------------------------------*/ // no direct access -defined( '_JEXEC' ) or die( 'Restricted access' ); +\defined( '_JEXEC' ) or die( 'Restricted access' ); ?> You received a message from posted_values['name']; ?> (posted_values['email']; ?>) diff --git a/popfeed/tmpl/scripts_and_styles.php b/popfeed/tmpl/scripts_and_styles.php index ab53ce7..1dfa234 100644 --- a/popfeed/tmpl/scripts_and_styles.php +++ b/popfeed/tmpl/scripts_and_styles.php @@ -10,9 +10,11 @@ -------------------------------------------------------------------------*/ // no direct access -defined( '_JEXEC' ) or die( 'Restricted access' ); +\defined( '_JEXEC' ) or die( 'Restricted access' ); -$document = JFactory::getDocument(); +use \Joomla\CMS\Factory; + +$document = Factory::getDocument(); // Initialize Form Scripts & Styles $style = '';