Skip to content

Commit

Permalink
Joomla 5 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mavrosxristoforos committed Jan 23, 2024
1 parent 2420ff7 commit 577a6be
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
uses: actions/checkout@v1
- name: Build Joomla Package
id: jxbuild
uses: mavrosxristoforos/[email protected]
uses: mavrosxristoforos/[email protected].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'
Expand Down
43 changes: 25 additions & 18 deletions popfeed/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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).')');
Expand All @@ -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)) );
}
Expand All @@ -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();
}
Expand All @@ -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;
}
Expand All @@ -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']);
Expand All @@ -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');
}
}

Expand All @@ -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;
}
Expand All @@ -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) {
Expand Down
27 changes: 17 additions & 10 deletions popfeed/popfeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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.
}
Expand Down
2 changes: 1 addition & 1 deletion popfeed/popfeed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<license>GNU General Public License</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>https://mavrosxristoforos.com/</authorUrl>
<version>1.6.68</version>
<version>1.6.71</version>
<description><![CDATA[PopFeed - Complete Article Feedback Functionality, popping out of your site!<br/>Usage in content: <strong>{popfeed}Your link text{/popfeed}</strong>]]></description>
<files>
<filename plugin="popfeed">popfeed.php</filename>
Expand Down
6 changes: 4 additions & 2 deletions popfeed/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') : '';
}

?>
Expand Down
2 changes: 1 addition & 1 deletion popfeed/tmpl/email_body.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-------------------------------------------------------------------------*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
\defined( '_JEXEC' ) or die( 'Restricted access' );

?>
You received a message from <?php print $helper->posted_values['name']; ?> (<?php print $helper->posted_values['email']; ?>)
Expand Down
6 changes: 4 additions & 2 deletions popfeed/tmpl/scripts_and_styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down

0 comments on commit 577a6be

Please sign in to comment.