Topic: Star rating not working in short story

Hi! I'm trying to install the AJAX-star-rater from an old website I had (the original code isn't on the forum anymore) but it doesn't work anymore and I don't get why:

I can rate when I'm in the full story, but in the short story, it seems that cutenews can't get the ID of the article, it shows with those two problems:

- If I rate any article, the modified line stays always the last of the file (so the first article of the website)
- I created a code named {voters} wich shows the number of voters and again, it works only in the fullstory, but the short story shows every voters without any space one after the other.

The final aim of this is to have a heart, or any button on wich I clik and increase by 1 the number of voters on the article. That should be really simple but since the rater had a problem from the beginning without even modifying it, I can't go further in the changes.

Here is the first part of the code in the full-story part:


//#############################################################
//#############################################################
// Star-Rating-Code

            //###########################
            // Firstcall-Block

            $firstcall_db = "$cutepath/data/ratings.txt";    // Define DB for Ratings
            $news_database = "$cutepath/data/news.txt";    // Tell it where the Main-DB is
             
            if (!file_exists($firstcall_db)) {    // If Ratings-DB is non-existant            
                $news_data = file("$news_database");    // Then get the Main-DB
                foreach($news_data as $news_data_line) {    // Divided into lines
                    $news_data_line_arr = explode("|",$news_data_line);    // and explode each line at the Pipe-Character to get the ID 
                    $id_sum .= $news_data_line_arr[0]."|0|0\n";    // And write all IDs into the Rating-DB in the manner we need 
                }
                
                $firstcall = fopen($firstcall_db, "w");    // Now go and create that Ratings-DB
                fwrite($firstcall, $id_sum);    // And paste the data we took above into it
                fclose($firstcall);    // Close the DB
                chmod ("$cutepath/data/ratings.txt", 0777);    // And change file-permissions
            }
            
            // End of Firstcall-Block
            //###########################
                        
                        $ratings_file = "$cutepath/data/ratings.txt"; 

            $ratings_db = file("$ratings_file");
            $new_ratings = fopen("$ratings_file","r");
            foreach($ratings_db as $rate_line) {

                $rate_line_arr = explode("|",$rate_line);
                $rate_line_id = $rate_line_arr[0];
                $rate_line_id = rtrim($rate_line_id);

                if($rate_line_id == $id) {    // We have just identified the correct line in the db to work with
                    $line_rating = $rate_line_arr[1];
                    $line_rating = rtrim($line_rating);
                    $line_voters = $rate_line_arr[2];
                    $line_voters = rtrim($line_voters);
                    if($line_voters == 0) {    // To prevent division by zero
                        $rating = 0;
                        $percentage = 0;
                    } else {
                        $rating = $line_rating / $line_voters;    // Divide Rating by Voters
                        $rounded_rating = round($rating);    // Round the decimal number to a single natural number
                        switch ($rounded_rating) {
                        case 0:
                            $percentage = 0;
                            break;
                        case 1:
                            $percentage = 100;
                            break;
                        }
                    }
                }
            }

                        // Code for Star-Ratings with possibility to vote
                        $rating_code = '<ul class="star-rating" id="ratingID';
                        $rating_code .= $id;    // ID which needs to be given so we can distinguish different rating-bars in one site
                        $rating_code .= '">';
                        $rating_code .= '<li class="current-rating" style="width:';
            $rating_code .= $percentage;    // actual value so that already given stars are shown correctly
            $rating_code .= '%;">';
            $rating_code .= $rating.'/1';    // Give the value in a break too so that even without images the rater is still understandable
            $rating_code .= '</li>
                     * <span title="" class="one-star" id="one-star-';
            $rating_code .= $id;
            $rating_code .= '" onclick="rateIt(this.id,this.parentNode.parentNode.id)"></span>
';
            $rating_code .= '</ul><span class="rating_confirm" id="rating_confirm';
            $rating_code .= $id;    // ID which needs to be given so we can distinguish different rating-bar-confirm-boxes in one site
            $rating_code .= '"> </span>';

            $voters_num .= $line_voters;
 
            fclose($new_ratings);

// End of Star-Rating-Code                    
//#############################################################
//#############################################################



And here is the seconde part for the active news:


//#############################################################
//#############################################################
// Star-Rating-Code

            //###########################
            // Firstcall-Block

            $firstcall_db = "$cutepath/data/ratings.txt";    // Define DB for Ratings
            $news_database = "$cutepath/data/news.txt";    // Tell it where the Main-DB is
             
            if (!file_exists($firstcall_db)) {    // If Ratings-DB is non-existant            
                $news_data = file("$news_database");    // Then get the Main-DB
                foreach($news_data as $news_data_line) {    // Divided into lines
                    $news_data_line_arr = explode("|",$news_data_line);    // and explode each line at the Pipe-Character to get the ID 
                    $id_sum .= $news_data_line_arr[0]."|0|0\n";    // And write all IDs into the Rating-DB in the manner we need 
                }
                
                $firstcall = fopen($firstcall_db, "w");    // Now go and create that Ratings-DB
                fwrite($firstcall, $id_sum);    // And paste the data we took above into it
                fclose($firstcall);    // Close the DB
                chmod ("$cutepath/data/ratings.txt", 0777);    // And change file-permissions
            }
            
            // End of Firstcall-Block
            //###########################
                        
                        $ratings_file = "$cutepath/data/ratings.txt"; 

            $ratings_db = file("$ratings_file");
            $new_ratings = fopen("$ratings_file","r");
            foreach($ratings_db as $rate_line) {

                $rate_line_arr = explode("|",$rate_line);
                $rate_line_id = $rate_line_arr[0];
                $rate_line_id = rtrim($rate_line_id);

        $id = $news_arr[0];     // Important for short-story-code - We need to clarify what the ID is

                if($rate_line_id == $id) {    // We have just identified the correct line in the db to work with
                    $line_rating = $rate_line_arr[1];
                    $line_rating = rtrim($line_rating);
                    $line_voters = $rate_line_arr[2];
                    $line_voters = rtrim($line_voters);
                    if($line_voters == 0) {    // To prevent division by zero
                        $rating = 0;
                        $percentage = 0;
                    } else {
                        $rating = $line_rating / $line_voters;    // Divide Rating by Voters
                        $rounded_rating = round($rating);    // Round the decimal number to a single natural number
                        switch ($rounded_rating) {
                        case 0:
                            $percentage = 0;
                            break;
                        case 1:
                            $percentage = 100;
                            break;
                        }
                    }
                }
            }

                        // Code for Star-Ratings with possibility to vote
                        $rating_code = '<ul class="star-rating" id="ratingID';
                        $rating_code .= $id;    // ID which needs to be given so we can distinguish different rating-bars in one site
                        $rating_code .= '">';
                        $rating_code .= '<li class="current-rating" style="width:';
            $rating_code .= $percentage;    // actual value so that already given stars are shown correctly
            $rating_code .= '%;">';
            $rating_code .= $rating.'/1';    // Give the value in a break too so that even without images the rater is still understandable
            $rating_code .= '</li>
                     * <span title="" class="one-star" id="one-star-';
            $rating_code .= $id;
            $rating_code .= '" onclick="rateIt(this.id,this.parentNode.parentNode.id)"></span>
';
            $rating_code .= '</ul><span class="rating_confirm" id="rating_confirm';
            $rating_code .= $id;    // ID which needs to be given so we can distinguish different rating-bar-confirm-boxes in one site
            $rating_code .= '"> </span>';
                    
            // Code for Star-Ratings without possibility to vote - Only show the rating
                        $rating_code_showonly = '<ul class="star-rating-showonly"><li class="current-rating" style="width:';
            $rating_code_showonly .= $percentage;    // actual value so that already given stars are shown correctly
            $rating_code_showonly .= '%;">';
            $rating_code_showonly .= $rating.'/1';    // Give the value in a break too so that even without images the rater is still understandable
            $rating_code_showonly .= '</li>
                     * <span title="1/1"></span>

                    </ul>';

            $voters_num .= $line_voters;
  
            fclose($new_ratings);

// End of Star-Rating-Code                    
//#############################################################
//#############################################################


Thank you for your help !