Jcomments and Kcaptcha

This forum is for general questions about extensions for Joomla! 3.x.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
andy fev
Joomla! Intern
Joomla! Intern
Posts: 51
Joined: Mon Jun 12, 2017 4:09 am

Re: Jcomments and Kcaptcha

Post by andy fev » Wed Aug 15, 2018 4:58 pm

borja wrote:
Tue Jun 19, 2018 1:31 pm
Hello

I use jcomments and kcaptcha on my web. Today it stopped working the captcha. As far as I have read:

I have a problem because the Kcaptch class is deprecated and there were some problems with the captcha.

I change the php twice and it started to work again. the first change was to change the version of php from 7.0.30 to 5.6.36. My web doesn´t work. I went back from 5.6.36 o 7.0.30 and the captcha started to work properly.

what can be wrong?
I use JComments and had the same issue when I upgraded to PHP 7.2 and was able to quickly solve the errors.

JComments is not busted or outdated, the developer used the constructor naming method to serve backward compatibility, many devs did so, but now PHP is strict so it is deprecated.

From php.net
"For backwards compatibility with PHP 3 and 4, if PHP cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class. Effectively, it means that the only case that would have compatibility issues is if the class had a method named __construct() which was used for different semantics."
The Fix
Edit the files that causes the warning and change the function name to the php core keyword __construct.

The files I edited were primarily in the frontend directory components/com_jcomments
  • libraries/kcaptcha/kcaptcha.php Change function KCAPTCHA() to function __construct()
  • classes/acl.php Change function JCommentsACL() to the same construct as above
  • helpers/pagination.php Change function JCommentsPagination()
  • tpl/default/tpl_form.php find if ( (count($customBBCodes)) ) and change to if ($customBBCodes). This is also a new strict rule. When count() is empty, php 7x will complain. The condition is just to determine if bbcodes is enabled
Finally, go to the Joomla plugins directory and edit plugins/content/jcomments/jcomments.php and change function plgContentJComments to function __construct


Now JComments will be functioning fine. No need to worry about an update overwriting the core changes. It's quite likely that the developer is aware of the deprecated methods and any release will include the changes you made.

See more about php constructors at http://php.net/manual/en/language.oop5.decon.php

User avatar
sozzled
Joomla! Champion
Joomla! Champion
Posts: 5503
Joined: Sun Jul 05, 2009 3:30 am
Location: Canberra, Australia
Contact:

Re: Jcomments and Kcaptcha

Post by sozzled » Wed Aug 15, 2018 5:38 pm

@andy fev:
sozzled wrote:
Wed Jun 20, 2018 8:20 am
See solution here (for PHP 7 and reCAPTCHA operability): https://github.com/exstreme/Jcomments-Recaptcha2
All of the PHP 7 requirements (including the PHP 7.2 rule about "not Countable" if an object is not defined) have been incorporated in that place.

I have not yet examined the developer's new release JComments 3.0.7 and I cannot say whether this will resolve the PHP 7 issues we've talked about here. I also do not know if the new release permits the selection of Joomla's Captcha - ReCaptcha plugin, either. There may be differences between the developer's version and the version that can be obtained from GitHub.
Last edited by mandville on Wed Aug 15, 2018 6:33 pm, edited 1 time in total.
Reason: replaced with link to JED as per forum rules
https://www.kuneze.com/blog
Former member of Kunena project team
If you think I’m wrong then say “I think you're wrong.” If you say “You’re wrong!”, how do you know?

Slackervaara
Joomla! Guru
Joomla! Guru
Posts: 901
Joined: Sat Aug 13, 2011 6:27 am

Re: Jcomments and Kcaptcha

Post by Slackervaara » Thu Aug 16, 2018 1:57 pm

3.0.7 is a security fix:

Changelog

* Security fix (processing ajax function calls)
* Security fix (more accurate sanitizing object_group parameter)
+ Added support of IP addresses with '*' wildcards (for blacklist feature).
^ JComments tags (like {jcomments off}) processing optimization
# Guests were able to post comment with admin's names in wrong letter case
^ Updated plugin for Cobalt 8 objects support
# Fixed bug in notifications helper (thanks to mascensao)

annahersh
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 136
Joined: Wed Aug 15, 2018 8:23 pm

Re: Jcomments and Kcaptcha

Post by annahersh » Thu Aug 16, 2018 5:09 pm

The new release still has the deprecated methods. I'd just do the minor edits to replace the functions with the same name as their classes with __construct(), and keep watching for an update. I don't use JComments, but I installed it just now to test and did the edits and it worked fine.

To use an extension of the same name that has been rewritten by someone else could be major head ache later, especially since the original creator is still actively maintaining the script. As seen now, the joomlatune latest is 3.0.7 with bug and security fixes, while the github copy is of the 3.0.5 version.

User avatar
sozzled
Joomla! Champion
Joomla! Champion
Posts: 5503
Joined: Sun Jul 05, 2009 3:30 am
Location: Canberra, Australia
Contact:

Re: Jcomments and Kcaptcha

Post by sozzled » Thu Aug 16, 2018 7:20 pm

The forked version (https://github.com/exstreme/Jcomments-Recaptcha2) has been updated and is referred to as "v3.0.7". I haven't had time to test the new forked version but I suspect it has a regression that produces a warning in PHP 7.2: "count(): Parameter must be an array or an object that implements Countable in /components/com_jcomments/tpl/default/tpl_form.php on line 199". See also viewtopic.php?f=715&t=964646&p=3535929#p3535929

I still need to verify if this happens in PHP 7.2.
https://www.kuneze.com/blog
Former member of Kunena project team
If you think I’m wrong then say “I think you're wrong.” If you say “You’re wrong!”, how do you know?

Slackervaara
Joomla! Guru
Joomla! Guru
Posts: 901
Joined: Sat Aug 13, 2011 6:27 am

Re: Jcomments and Kcaptcha

Post by Slackervaara » Fri Aug 17, 2018 5:04 pm

I can add that the PHP 7 error vanished from com_phocagallery_images.plugin.php, when I used the __construct change suggested earlier here in that file.

Slackervaara
Joomla! Guru
Joomla! Guru
Posts: 901
Joined: Sat Aug 13, 2011 6:27 am

Re: Jcomments and Kcaptcha

Post by Slackervaara » Sat Aug 18, 2018 4:25 pm

3 hours ago I installed the forked version you mentioned, but I added the fix for tpl_form.php, as I have PHP 7.2.8. Everything went smooth, except for configuration of permissions. In order to disable comments posting for public and guests I had to enable the plugin for ReCaptcha.

I have looked in error logs and I have no errors from JComments. The module JComments Latest works OK and also with avatars and the avatar plugin.

annahersh
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 136
Joined: Wed Aug 15, 2018 8:23 pm

Re: Jcomments and Kcaptcha

Post by annahersh » Sat Aug 18, 2018 4:55 pm

Here is a plugin to dynamically fix the JComments files mentioned above. It will check only acl.php to determine if the deprecated files exist and display a toolbar button when in JComments admin area. Once Joomlatune releases a version with the corrections, just uninstall the plugin.

Create a php file and name it fix_jcomments.php

Code: Select all

<?php defined('_JEXEC') or die();


class plgSystemFix_Jcomments extends JPlugin 
{
	
	public function onAfterDispatch() 
	{
		$app	= JFactory::getApplication();
		$toolbar = JToolBar::getInstance('toolbar');
		$sadmin	= JFactory::getUser()->authorise('core.admin');
		
		if( $app->isAdmin() && $sadmin && JFile::exists(JPATH_ROOT.'/components/com_jcomments/jcomments.php') )
		{		
			
			// Jcomments fix
			$plgfile = JPATH_PLUGINS.'/content/jcomments/jcomments.php';
			$aclfile = JPATH_ROOT.'/components/com_jcomments/classes/acl.php';
			$paginfile = JPATH_ROOT.'/components/com_jcomments/helpers/pagination.php';
			$kcapfile = JPATH_ROOT.'/components/com_jcomments/libraries/kcaptcha/kcaptcha.php';
			$tplfile = JPATH_ROOT.'/components/com_jcomments/tpl/default/tpl_form.php';
			$acl = file_get_contents($aclfile);

			if( !is_null($app->input->post->get('fixjcomments')) ) 
			{
				$plg = file_get_contents($plgfile);
				$plg = str_replace('function plgContentJComments', 'function __construct',$plg);
				file_put_contents($plgfile, $plg);
				
				$acl = str_replace('function JCommentsACL', 'function __construct',$acl);
				file_put_contents($aclfile, $acl);
				
				$pagin = file_get_contents($paginfile);
				$pagin = str_replace('function JCommentsPagination', 'function __construct',$pagin);
				file_put_contents($paginfile, $pagin);
				
				$kcap = file_get_contents($kcapfile);
				$kcap = str_replace('function KCAPTCHA', 'function __construct',$kcap);
				file_put_contents($kcapfile, $kcap);
				
				$tpl = file_get_contents($tplfile);
				$tpl = str_replace('if (count($customBBCodes))', 'if ($customBBCodes)',$tpl);
				file_put_contents($tplfile, $tpl);
				
				$app->enqueueMessage(JText::_('Successfully fixed JComments files'));
			}
			
			$jcombtn = '<form action="" method="post" style="margin: 0;">
						<button 
						type="submit" 
						name="fixjcomments" 
						class="btn btn-small hasTooltip" 
						style="background: #ffe3c6;" 
						title="Fix JComments PHP errors">
						Fix JComments PHP
						</button>
						</form>';
			
			if( $app->input->get('option') == 'com_jcomments' &&  strstr($acl, 'function JCommentsACL') !== false ) {
				$toolbar->appendButton('Custom', $jcombtn);
			}
					
		}
	}
}
Manifest fix_jcomments.xml

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.7.0" type="plugin" group="system" method="upgrade">
	<name>System - Fix JComments</name>
	<author>you</author>
	<creationDate>today</creationDate>
	<copyright>All Rights Reserved.</copyright>
	<license></license>
	<authorEmail></authorEmail>
	<authorUrl></authorUrl>
	<version>1.0</version>
	<description>Fix function names in JComments</description>
	
	<files>
		<filename plugin="fix_jcomments">fix_jcomments.php</filename>
	</files>

</extension>
Zip and install then go to plugins manager and enable.

When the deprecate file is detected.
fix-jcomments.jpg
After the fix
after-fix.jpg
You do not have the required permissions to view the files attached to this post.

mbdixon
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Thu Jul 24, 2014 11:52 am

Re: Jcomments and Kcaptcha

Post by mbdixon » Thu Aug 23, 2018 12:02 pm

I used to use JComments but was getting far more junk than genuine comments. I simply installed CComments (https://compojoom.com/joomla-extensions ... d=30f713ae) , imported the comments from JComments after deleting the junk, deleted JComments and since then I've had virtually no junk!

Slackervaara
Joomla! Guru
Joomla! Guru
Posts: 901
Joined: Sat Aug 13, 2011 6:27 am

Re: Jcomments and Kcaptcha

Post by Slackervaara » Fri Aug 24, 2018 1:01 pm

I have just enabled ReCaptcha in JComments 3.07 adapted to PHP 7. ReCaptcha works but I will test now if it blocks spammers.

Slackervaara
Joomla! Guru
Joomla! Guru
Posts: 901
Joined: Sat Aug 13, 2011 6:27 am

Re: Jcomments and Kcaptcha

Post by Slackervaara » Tue Sep 04, 2018 5:35 pm

I have now used JComments ReCaptcha för eleven days and I have not had a single spam. Much better than KCaptcha.

annahersh
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 136
Joined: Wed Aug 15, 2018 8:23 pm

Re: Jcomments and Kcaptcha

Post by annahersh » Tue Sep 04, 2018 7:51 pm

Slackervaara wrote:
Tue Sep 04, 2018 5:35 pm
I have now used JComments ReCaptcha för eleven days and I have not had a single spam. Much better than KCaptcha.
ReCaptcha doesn't stop spammers, it's just a deterrent for the spammers who can't be bothered. As seen with this forum which uses the function yet constantly has spam posts.

User avatar
sozzled
Joomla! Champion
Joomla! Champion
Posts: 5503
Joined: Sun Jul 05, 2009 3:30 am
Location: Canberra, Australia
Contact:

Re: Jcomments and Kcaptcha

Post by sozzled » Tue Sep 04, 2018 8:20 pm

I agree with @annahersh: CAPTCHA does not stop spam; CAPTCHA doesn't stop anything (except when the whole system is broken). It's one thing to write that someone has been using CAPTCHA for a length of time and not "had a single spam"; it's another thing to write that someone has been using an article commenting accessory and not had a single comment for a certain amount of time.

The articles that I write around the internet are read by many people. I would be lucky if I received one comment for every 1000 page hits. The reason that many spam/nonsense comments aren't successfully published is not because of CAPTCHA; there are many reasons: (a) people can't be bothered to comment on articles; (b) comments are not published until they've been approved; (c) people may not even see that they can make comments when they read articles. We cannot conclude that someone has not "had a single spam" purely because of CAPTCHA. We cannot conclude anything.

However, I agree with @Slackervaara in a general sense: Google reCAPTCHA seems to work consistently and "looks" better than other CAPTCHA tools.
https://www.kuneze.com/blog
Former member of Kunena project team
If you think I’m wrong then say “I think you're wrong.” If you say “You’re wrong!”, how do you know?

Slackervaara
Joomla! Guru
Joomla! Guru
Posts: 901
Joined: Sat Aug 13, 2011 6:27 am

Re: Jcomments and Kcaptcha

Post by Slackervaara » Tue Sep 04, 2018 9:02 pm

There are two types of spammers. Human spammers that are not stopped by ReCaptcha, because they are humans and robotics spammers that are stopped by ReCaptcha because they cant choose images. Nothing can stop a human spammer, but they are more expensive and less common.

annahersh
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 136
Joined: Wed Aug 15, 2018 8:23 pm

Re: Jcomments and Kcaptcha

Post by annahersh » Wed Sep 05, 2018 12:48 am

Slackervaara wrote:
Tue Sep 04, 2018 9:02 pm
There are two types of spammers. Human spammers that are not stopped by ReCaptcha, because they are humans and robotics spammers that are stopped by ReCaptcha because they cant choose images. Nothing can stop a human spammer, but they are more expensive and less common.
The key reason why bot spamming is more common with locally applied captcha programs (KCaptcha in this case) is that those scripts are open source and a programmer can write his bot to counter all that is being done by the script since it's in his view. Being that ReCaptcha is remotely served by Google and no one but Google knows how the algorithms work, it's challenging for a coder to counter the methods, but certainly not impossible. See the article about the researchers who bypassed reCaptcha with a bot. https://nakedsecurity.sophos.com/2017/1 ... recaptcha/

The fact is no catpcha method is forever. They need to be constantly changing to stay ahead of counter coding. The free scripts tend to stay dormant so once beaten, without updates they are beaten forever. So yes, the best anti-spam tool is always a third party maintained engine.


Post Reply

Return to “Extensions for Joomla! 3.x”