hashover-next icon indicating copy to clipboard operation
hashover-next copied to clipboard

Likes doesnt work at all. + another question

Open vkaotik opened this issue 7 years ago • 11 comments

Hi. I really like this comment system, and I'm looking forward with it. Hashover v1.0 worked perfectly, altrough it was missing one key element - SQL database feature. That's how I've found this branch. I've downloaded this version, and after several attempts, it started working. I've hooked up database to it, and it started to say PDO.php errors: "HashOver PDO.php file could not be included!" which i've fixed it with code fix by @AndreaCatania : From PDO::FETCH_ to \PDO::FETCH_ in lines 76 and 111 in parsesql.php file.

Now at this point I was able to write comments,replies,etc. But when it comes to Like/Dislike function - it simply doesn't work. Now I thought that I did something wrong in coding, because, it was saying like "Error : Something was wrong!" popup after pressing like/dislike button. I've cleaned entire site and put unmodified hashover 2.0, with changed settings file and parsesql.php fix, and the problem still appears. Without PDO fix, hashover simply doesnt work on database mode .Console doesn't output anything, not even clue what's wrong with it. Is it just for me , or is it for all?

Another question might be simpler - Is it possible to make hashover to parse ip addresses from mysql database and show to every single reply? Thanks..

vkaotik avatar May 19 '17 15:05 vkaotik

+1 Good you bring that up! Like/dislike actually does not work for me either. I realised that some time ago and wanted to report it, but then I forgot. I have no clue though what could be the reason nor when it started, as I think it did work at same point.

I suggest you split your comment into two: leave this one for the like/dislike, and open a new one for the 'Most commented pages'. Like this it will be easier to follow up on the individual issues.

prisae avatar May 19 '17 15:05 prisae

Likes also doesn't work at all for me. did you solve this problem? two months ago you reported sql bug and now this bug is bothering me!

paradox70 avatar Aug 29 '17 03:08 paradox70

The cause of this error is 'spl_autoload_register' in like.php fetching the wrong path. When 'spl_autoload_register' gets the classes it also gets the namespace. So from the current directory, it then adds `hashover\statistics.php for example, which is wrong because the classes are inside the scripts folder

To fix the issue and get the like/dislike working go to like.php and swap the current spl_autoload_register with the below code:

spl_autoload_register(function ($class) {
	$get_class = explode('\\', $class);
	$class_name = array_pop($get_class);
	$file_name = __DIR__ . "\\" . strtolower($class_name) . '.php';  // some systems may need to use forward slashes instead

	if(!file_exists($file_name)) {
        echo json_encode (array (
			'error' => $file_name . ' file could not be included!'
		));
		exit;
    }
    include $file_name;
});

leem32 avatar Oct 20 '17 10:10 leem32

@leem32 I replaced spl_autoload_register with your code, but the problem is still there.

paradox70 avatar Oct 20 '17 13:10 paradox70

@paradox70 Weird, this fixes the issue for me on windows localhost using PHP 7.1.1.

Try opening dev tools (f12) then click the like button and in dev tools click the network tab, select like.php and then the response tab. If the path is something like hashover\statistics.php then it's wrong because statistics.php is inside the scripts folder. So the last part of the path should be \hashover\scripts\statistics.php for example.

Basically just play around with the path set by spl_autoload_register( in like.php until you get it right.

leem32 avatar Oct 20 '17 14:10 leem32

@leem32 By the original code I give this error: {"error":"hashover\\statistics.php\" file could not be included!"} After replacing your code I give this error: {"error":"\/var\/www\/example.com\/hashover\/scripts\\hashover.php file could not be included!"}

Basically just play around with the path set by spl_autoload_register( in like.php until you get it right.

Unfortunately I don't know about php! So please help to solve this problem for anyone.

paradox70 avatar Oct 20 '17 14:10 paradox70

Yes , both of those paths are wrong. Try

$file_name = __DIR__ . "\/" . strtolower($class_name) . '.php';

or

$file_name = __DIR__ . "/" . strtolower($class_name) . '.php';

leem32 avatar Oct 20 '17 14:10 leem32

Thank a lot dear @leem32 . Finally replacing spl_autoload_register in like.php with the following code solved the problem:

spl_autoload_register(function ($class) {
    $get_class = explode('\\', $class);
    $class_name = array_pop($get_class);
    $file_name = __DIR__ . "\" . strtolower($class_name) . '.php';

    if(!file_exists($file_name)) {
        echo json_encode (array (
	    	    'error' => $file_name . ' file could not be included!'
	    ));
        	exit;
    }
    include $file_name; // some systems may need to use forward slashes instead
});

paradox70 avatar Oct 20 '17 15:10 paradox70

@paradox70

OK cool :)

leem32 avatar Oct 20 '17 15:10 leem32

It didn't work for me, I had to use the following code:

spl_autoload_register (function ($classname) {
    $classname = strtolower ($classname);
    $get_class = explode('\\', $classname);
    $class_name = array_pop($get_class);

    if (!@include ('./' . $class_name . '.php')) {
        echo json_encode (array (
            'error' => $class_name . '.php" file could not be included!'
        ));

        exit;
    }
});

linuxitux avatar Feb 09 '18 02:02 linuxitux

Hello, sorry for the long delay.

Y'all please try again with the latest code, and if you are still having this problem, let me know and I will try my best to address the issue further.

jacobwb avatar Feb 26 '18 16:02 jacobwb