Forum Replies Created

Viewing 13 replies - 76 through 88 (of 88 total)
  • Tobias, I had Firefox but I have the same problem with Google Chrome so it is not probably the browser case.

    Tobias,

    Well, I see it in the console like tremblayly. If You don’t see it, it means it is probably end-user dependent or network issue… such issues are the worst, hard to reproduce.

    Regards,
    Darek

    Tobias,

    I have the same problem, so You can see my website as well:
    coaching.dariusz-licznerski.pl

    Probably it comes from google button, I am not sure if I had it with WP-Table Reloaded plugin before or not.

    Regards,
    Darek

    Okoth1,

    I’ve changed the “kksr_ajax” function in “index.php” file in the “kk-star-ratings” directory.

    Little description of changes:
    I just copied the body of the function “kksr_ajax” and add extra “if” and “for” loop when the ID is minus (e.g. id=-80). If the id is minus I know that js file sends to the php array with all IDs and want back ratings for all of them. Simply if the id is plus (e.g. id=500), I know that this is single call for ID, so the else from if is unchanged part.

    So this is all the rocket science ??

    I am not 100% sure if it solve your problem and will be ok in your case (posts). Test it carefully somewhere before. Probably it can be done much better. I posted the changed fragment below so see it before and make your own changes based on this.

    public function kksr_ajax()
    		{
    			header('Content-type: application/json; charset=utf-8');
    			check_ajax_referer($this->id);
    
    			$Response = array();
    
    			$total_stars = is_numeric(parent::get_options('kksr_stars')) ? parent::get_options('kksr_stars') : 5;
    
    			$pid = $_POST['id'];
    			$stars = $_POST['stars'];
    			$ip = $_SERVER['REMOTE_ADDR'];
    
    			if ($pid<0)
    			{
    				$pid=-$pid;
    				$ID_all = explode("-",$_POST['all']);
    
    				for ($i=1;$i<=$pid;$i++)
    				{
    					$Response[$i] = array();
    
    					$ratings = get_post_meta($ID_all[$i-1], '_kksr_ratings', true) ? get_post_meta($ID_all[$i-1], '_kksr_ratings', true) : 0;
    					$casts = get_post_meta($ID_all[$i-1], '_kksr_casts', true) ? get_post_meta($ID_all[$i-1], '_kksr_casts', true) : 0;
    
    					if($stars==0 && $ratings==0)
    					{
    						$Response[$i]['legend'] = parent::get_options('kksr_init_msg');
    						$Response[$i]['disable'] = 'false';
    						$Response[$i]['fuel'] = '0';
    						do_action('kksr_init', $ID_all[$i-1], false, false);
    					}
    					else
    					{
    						$nratings = $ratings + ($stars/($total_stars/5));
    						$ncasts = $casts + ($stars>0);
    						$avg = $nratings ? round($nratings/$ncasts,1) : 0;
    						$per = $nratings ? round((($nratings/$ncasts)/5)*100) : 0;
    						$Response[$i]['disable'] = 'false';
    						if($stars)
    						{
    							$Ips = get_post_meta($ID_all[$i-1], '_kksr_ips', true) ? unserialize(base64_decode(get_post_meta($ID_all[$i-1], '_kksr_ips', true))) : array();
    							if(!in_array($ip, $Ips))
    							{
    								$Ips[] = $ip;
    							}
    							$ips = base64_encode(serialize($Ips));
    							update_post_meta($ID_all[$i-1], '_kksr_ratings', $nratings);
    							update_post_meta($ID_all[$i-1], '_kksr_casts', $ncasts);
    							update_post_meta($ID_all[$i-1], '_kksr_ips', $ips);
    							update_post_meta($ID_all[$i-1], '_kksr_avg', $avg);
    							$Response[$i]['disable'] = parent::get_options('kksr_unique') ? 'true' : 'false';
    							do_action('kksr_rate', $ID_all[$i-1], $stars, $ip);
    						}
    						else
    						{
    							do_action('kksr_init', $ID_all[$i-1], ($avg*($total_stars/5)).'/'.$total_stars, $ncasts);
    						}
    						$legend = parent::get_options('kksr_legend');
    						$legend = str_replace('[total]', $ncasts, $legend);
    						$legend = str_replace('[avg]', ($avg*($total_stars/5)).'/'.$total_stars, $legend);
    						$legend = str_replace('[s]', $ncasts==1?'':'s', $legend);
    						$Response[$i]['legend'] = str_replace('[per]',$per.'%', $legend);
    						$Response[$i]['fuel'] = $per;
    					}
    				$Response[$i]['success'] = 'true';
    				}
    			}
    			else {
    				$ratings = get_post_meta($pid, '_kksr_ratings', true) ? get_post_meta($pid, '_kksr_ratings', true) : 0;
    				$casts = get_post_meta($pid, '_kksr_casts', true) ? get_post_meta($pid, '_kksr_casts', true) : 0;
    
    				if($stars==0 && $ratings==0)
    				{
    					$Response['legend'] = parent::get_options('kksr_init_msg');
    					$Response['disable'] = 'false';
    					$Response['fuel'] = '0';
    					do_action('kksr_init', $pid, false, false);
    				}
    				else
    				{
    					$nratings = $ratings + ($stars/($total_stars/5));
    					$ncasts = $casts + ($stars>0);
    					$avg = $nratings ? round($nratings/$ncasts,1) : 0;
    					$per = $nratings ? round((($nratings/$ncasts)/5)*100) : 0;
    					$Response['disable'] = 'false';
    					if($stars)
    					{
    						$Ips = get_post_meta($pid, '_kksr_ips', true) ? unserialize(base64_decode(get_post_meta($pid, '_kksr_ips', true))) : array();
    						if(!in_array($ip, $Ips))
    						{
    							$Ips[] = $ip;
    						}
    						$ips = base64_encode(serialize($Ips));
    						update_post_meta($pid, '_kksr_ratings', $nratings);
    						update_post_meta($pid, '_kksr_casts', $ncasts);
    						update_post_meta($pid, '_kksr_ips', $ips);
    						update_post_meta($pid, '_kksr_avg', $avg);
    						$Response['disable'] = parent::get_options('kksr_unique') ? 'true' : 'false';
    						do_action('kksr_rate', $pid, $stars, $ip);
    					}
    					else
    					{
    						do_action('kksr_init', $pid, ($avg*($total_stars/5)).'/'.$total_stars, $ncasts);
    					}
    					$legend = parent::get_options('kksr_legend');
    					$legend = str_replace('[total]', $ncasts, $legend);
    					$legend = str_replace('[avg]', ($avg*($total_stars/5)).'/'.$total_stars, $legend);
    					$legend = str_replace('[s]', $ncasts==1?'':'s', $legend);
    					$Response['legend'] = str_replace('[per]',$per.'%', $legend);
    					$Response['fuel'] = $per;
    				}
    			$Response['success'] = 'true';
    			}
    			echo json_encode($Response);
    			die();
    		}

    Regards,
    Darek

    Probably you have to change it into:

    .tablepress-id-N thead th {
    	color: #000000 !important;
    }

    TablePress needs !important to force the custom CSS from file.

    Thread Starter Darek L

    (@darekl)

    Thanks Tobias to find the source of the problem. I will keep the hardcode as long as there the tabs exist in this case.

    Okoth1,

    Websites are open source code, so you can view it at any time. The kk star ratings js file you can see here: js.js. Also you need to change the php file on the other side (not so much changes there, just get the array and ask database for ratings).

    Steps:
    1. The js file counts how many IDs you have on the page.
    2. Then the js file sends to the php file the number of IDs and also all IDs numbers (so they don’t have to be from 1 to eg. 80, you can have e.g. 1,2,3 space and from 10 other IDs).
    3. The php file gets the number of IDs and all IDs numbers.
    4. Then the php file checks ratings for all IDs in the database.
    5. The php file packs the IDs and ratings to array and sends it to the js file.
    6. Then the js file gets ratings from array and calls modified function kksr_fetch which I copied and changed into kksr_fetch_all.

    Hope it helps. Not so pretty coding style, rather quick fix. Probably official patch should be more advanced, I guess.

    Regards,
    Darek

    SashaSolo,

    You have only 6 ratings per page (per one load) so it is not so slow in your case. I had about 80 ratings per page (per one load), so it took years to load all ratings at once…

    You have 6 admin-ajax.php calls right now, not so much, but if you want to speed up your page you have to call admin-ajax.php only once.

    Regards,
    Darek

    Thread Starter Darek L

    (@darekl)

    It can be fixed with CSS code like that:

    /* fix 1st column width */
    #tablepress-1 .column-1,
    #tablepress-1 .column-3,
    #tablepress-1 .column-4,
    #tablepress-1 .column-5,
    #tablepress-1 .column-6 {
    	width: 14% !important;
    }
    #tablepress-1 .column-2 {
    	width: 30% !important;
    }
    #tablepress-2 .column-1 {
    	width: 14% !important;
    }
    #tablepress-2 .column-4,
    #tablepress-2 .column-5 {
    	width: 5% !important;
    }
    #tablepress-2 .column-2 {
    	width: 40% !important;
    }
    #tablepress-2 .column-3 {
    	width: 41% !important;
    }

    …but it is hardcoded…

    Thread Starter Darek L

    (@darekl)

    Yes, when I put aaSorting code into js file it popup window with second table initialisation… yes but everything is fine now, resolved, thanks.

    Thread Starter Darek L

    (@darekl)

    Thanks Tobias for quick help.

    I found fnSort and use it in order to avoid error related to the second table initialisation.

    Finally I get it to work with such code:

    // Default sort
    var oTable;
    oTable = jQuery('#tablepress-1').dataTable();
    oTable.fnSort( [ [0,'desc'] ] );
    oTable = jQuery('#tablepress-2').dataTable();
    oTable.fnSort( [ [0,'desc'] ] );

    Looks like it is what l was looking for…

    I did it coaching.dariusz-licznerski.pl

    …but with kk Star Ratings plugin. The plugin kk Star Ratings has problem with slow loading if you have so many IDs in the table… so I had to fix it too.

    Currently the sort works with TablePress plugin but if I turn on the Wp-Table Reloaded it works with it as well.

    I fix it: coaching.dariusz-licznerski.pl

    p.s. This problem is because admin-ajax.php is called for each ID. It takes time for many IDs…

Viewing 13 replies - 76 through 88 (of 88 total)