SOHKat Posted October 5, 2009 Share Posted October 5, 2009 I downloaded http://www.dbscripts.net/ratings/ I have it working on my site HERE but I do not like the way it displays. All I need help with is rearranging the different lines. I want Current Rating, The Images and the (% out of #) all on the same line Total # of Votes on the same line as "Rate This Script" The developer offers no support apparently. Anyhow, there are really only two files that have anything to do with how it displays - besides the Style CSS. Here they are: config.php (I thought to rearrange the list in here, but that did not work.) <?php /**************************************************************************** * DRBRatings * http://www.dbscripts.net/ratings/ * * Copyright © 2007 Don Barnes ****************************************************************************/ // Modify this string to reflect the URL where DRBRatings is installed. // A trailing slash must be included. This URL will be used in the generated // HTML for the image tags, and in the URL for the form submission. $RATINGS_URL = 'http://www.campblood.net/rate/'; // Names of the form input elements in the ratings form. // You probably won't need to change these unless the names conflict with some // other element on your pages. $RATING_ID_PARAM_NAME = "ratingid"; $RATING_PARAM_NAME = "rating"; // Precision to use when displaying the average rating $RATINGS_PRECISION = 2; // These are the file names for the star graphics. These graphics // files must be located immediately beneath the RATINGS_URL defined above. // Feel free to customize these graphics. $IMAGE_STAR_EMPTY = 'empty.gif'; $IMAGE_STAR_HALF = 'half.gif'; $IMAGE_STAR_FILLED = 'filled.gif'; // These are the strings that are displayed in the rating control // and the result page. // Modify these to customize what is displayed to the user. $CURRENT_RATING_STRING = 'Current Rating:'; $RATING_STRING = '(%s out of %s)'; $RATE_THIS_STRING = 'Rate This Movie:'; $SUBMIT_BUTTON_STRING = 'Submit'; $RATING_LIST_DEFAULT_LABEL = 'Please Select'; $DUPLICATE_RATE_ERROR_MSG = 'You have already rated!'; $NO_RATING_SELECTED_ERROR_MSG = 'You forgot to select a rating!'; $NUMBER_OF_RATINGS_STRING = '%s Total Votes'; // The maximum number of stars per rating // Change this to customize the maximum number of stars. $MAX_STARS = 5; // List of valid rating IDs. All rating requests are checked against this list // to ensure that malicious users do not submit invalid rating IDs through a // cross-site request forgery. Add or modify values in this array to // customize the available rating IDs for new ratings forms. // All values in this array must be strings. In addition, they must // only use alphanumeric characters (A-Z, a-z, and 0-9). $VALID_RATING_IDS = array("1", "2"); // Array containing labels for each rating value // If no labels are desired, simply leave the array blank. $RATING_LABELS = array( 1 => "Awful", 3 => "Average", 5 => "Excellent" ); ?> ratings.php <?php /**************************************************************************** * DRBRatings * http://www.dbscripts.net/ratings/ * * Copyright © 2007 Don Barnes ****************************************************************************/ include_once(dirname(__FILE__) . '/config.php'); $CHECK_FOR_DUPLICATE_RATINGS = TRUE; function show_ratings_control($id) { global $MAX_STARS; global $RATING_STRING; global $NUMBER_OF_RATINGS_STRING; global $CURRENT_RATING_STRING; // Validate parameters if(!is_valid_id($id)) { die('ERROR: An invalid rating ID was submitted.'); } // Get the current rating and rating count $summarylist = rating_summary_list($id); $ratingCount = get_rating_count($summarylist); $rating = get_current_rating($summarylist); // Initialize the display messages for the rating control $ratingString = sprintf($RATING_STRING, $rating, $MAX_STARS); $numberOfRatingsString = sprintf($NUMBER_OF_RATINGS_STRING, $ratingCount); // Output rating control echo("<div class=\"ratingsContainer\">\r\n"); echo("\t<div class=\"currentRating\">" . htmlspecialchars($CURRENT_RATING_STRING) . "</div>\r\n"); echo("\t<div class=\"rating\">\r\n"); show_stars($rating); echo("\t\t" . htmlspecialchars($ratingString) . "\r\n\t</div>\r\n"); echo("\t<div class=\"numberOfRatings\">" . htmlspecialchars($numberOfRatingsString) . "</div>\r\n"); show_rate_form($id); echo("</div>\r\n"); } function show_rate_form($id) { global $RATE_THIS_STRING; global $MAX_STARS; global $SUBMIT_BUTTON_STRING; global $RATING_LABELS; global $RATING_LIST_DEFAULT_LABEL; global $RATINGS_URL; global $RATING_ID_PARAM_NAME; global $RATING_PARAM_NAME; echo("\t<form class=\"rateIt\" method=\"post\" action=\"" . $RATINGS_URL . "rate.php\">\r\n"); echo("\t\t" . htmlspecialchars($RATE_THIS_STRING) . "\r\n"); echo("\t\t<select name=\"" . htmlspecialchars($RATING_PARAM_NAME) . "\">\r\n"); echo("\t\t\t<option value=\"\">" . htmlspecialchars($RATING_LIST_DEFAULT_LABEL) . "</option>\r\n"); for($i = 1; $i <= $MAX_STARS; $i++) { echo("\t\t\t<option value=\"" . $i . "\">" . $i); if(!empty($RATING_LABELS) && isset($RATING_LABELS[$i])) { echo(" - " . htmlspecialchars($RATING_LABELS[$i])); } echo("</option>\r\n"); } echo("\t\t</select>\r\n"); echo("\t\t<input type=\"hidden\" name=\"" . htmlspecialchars($RATING_ID_PARAM_NAME) . "\" value=\"" . htmlspecialchars($id) . "\" />\r\n"); echo("\t\t<input type=\"submit\" value=\"" . htmlspecialchars($SUBMIT_BUTTON_STRING) . "\" class=\"submit\" />\r\n"); echo("\t</form>\r\n"); } function show_stars($rating) { global $IMAGE_STAR_EMPTY; global $IMAGE_STAR_HALF; global $IMAGE_STAR_FILLED; global $MAX_STARS; // Iterate through the stars, and show the correct type of star image // based on the rating. for($i = 1; $i <= $MAX_STARS; $i++) { if($rating > $i - .5) { show_ratings_image($IMAGE_STAR_FILLED, "*"); } else if($rating > $i - 1) { show_ratings_image($IMAGE_STAR_HALF, "1/2"); } else { show_ratings_image($IMAGE_STAR_EMPTY, ""); } } } function show_ratings_image($filename, $alt) { global $RATINGS_URL; echo("\t\t<img src=\"" . $RATINGS_URL . urlencode($filename) . "\" alt=\"" . $alt . "\" />\r\n"); } function smarter_is_int($val) { return (is_numeric($val)?intval($val)==$val:FALSE); } function is_valid_id($id) { global $VALID_RATING_IDS; return (!empty($id) && preg_match('/^[a-zA-Z0-9]+$/D', $id) === 1 && in_array($id, $VALID_RATING_IDS, TRUE)); } function is_valid_rating($rating) { global $MAX_STARS; return (!empty($rating) && preg_match('/^[1-9][0-9]*$/D', $rating) === 1 && smarter_is_int($rating) && $rating >= 1 && $rating <= $MAX_STARS); } function get_rating_count($summarylist) { // Get rating count from summary if($summarylist === FALSE || count($summarylist) < 1) { return 0; } else { return $summarylist[0]; } } function get_current_rating($summarylist) { global $MAX_STARS; // Get total count $totalCount = get_rating_count($summarylist); if($totalCount == 0) return 0; // Prevent divide by zero // Calculate total ratings $totalRatings = 0; if($summarylist !== FALSE) { for($i = 1; $i <= $MAX_STARS; $i++) { if($i < count($summarylist)) { $totalRatings += $summarylist[$i] * $i; } } } // Return average global $RATINGS_PRECISION; return round($totalRatings / $totalCount, $RATINGS_PRECISION); } function add_new_rating($id, $rating) { global $rating_error_message; // Make sure rating wasn't left blank if(empty($rating)) { global $NO_RATING_SELECTED_ERROR_MSG; $rating_error_message = $NO_RATING_SELECTED_ERROR_MSG; return FALSE; } // Validate parameters if(!is_valid_id($id)) { die('ERROR: An invalid rating ID was submitted.'); } if(!is_valid_rating($rating) ) { die('ERROR: An invalid rating was submitted.'); } // Convert to integer value $rating = intval($rating); // Check for duplicate rating attempt global $CHECK_FOR_DUPLICATE_RATINGS; if($CHECK_FOR_DUPLICATE_RATINGS === TRUE) { $ipaddress = $_SERVER['REMOTE_ADDR']; if(has_rated($id, $ipaddress)) { global $DUPLICATE_RATE_ERROR_MSG; $rating_error_message = $DUPLICATE_RATE_ERROR_MSG; return FALSE; } } // Add rating rating_history_add($id, $ipaddress, $rating); rating_summary_add($id, $rating); return TRUE; } function rating_summary_file_path($id) { return dirname(__FILE__) . '/data/summary_' . $id . '.dat'; } function rating_history_file_path($id) { return dirname(__FILE__) . '/data/history_' . $id . '.dat'; } function rating_summary_list($id) { // Load existing $summarylist = @file(rating_summary_file_path($id)); if($summarylist !== FALSE) { $summarylist = array_map("trim", $summarylist); } return $summarylist; } function rating_summary_add($id, $rating) { // Get existing ratings $summarylist = rating_summary_list($id); // Open/create summary file $summary_fp = @fopen(rating_summary_file_path($id), "w"); if($summary_fp === FALSE) { die("Unable to open summary file for writing"); } @flock($summary_fp, LOCK_EX); // Update total rating count if($summarylist === FALSE || count($summarylist) < 1) { $count = 1; } else { $count = $summarylist[0] + 1; } fputs($summary_fp, $count . "\n"); // Add rating to history global $MAX_STARS; for($i = 1; $i <= $MAX_STARS; $i++) { if($summarylist === FALSE || $i > count($summarylist) + 1) { // This is the first rating for this number if($i == $rating) { $out = 1; } else { $out = 0; } } else { // Add to existing rating count for this number if($i == $rating) { $out = ($summarylist[$i] + 1); } else { $out = $summarylist[$i]; } } // Write out new rating count for this number fputs($summary_fp, $out . "\n"); } fclose($summary_fp); } function rating_history_add($id, $ipaddress, $rating) { // Open/create history file $history_fp = @fopen(rating_history_file_path($id), "a"); if($history_fp === FALSE) { die("Unable to open history file for writing"); } // Add IP address and rating to history @flock($history_fp, LOCK_EX); fputs($history_fp, $ipaddress . "|" . $rating . "\n"); fclose($history_fp); } function explode_history($line) { return array_map("trim", explode("|", $line)); } function rating_history_list($id) { // Load existing rating history $summarylist = @file(rating_history_file_path($id)); if($summarylist !== FALSE) { $summarylist = array_map("explode_history", $summarylist); } return $summarylist; } function has_rated($id, $ipaddress) { // Find rating history $rating_history_list = rating_history_list($id); if($rating_history_list !== FALSE) { return( find_rating_history(trim($ipaddress), $rating_history_list) !== FALSE ); } else { return FALSE; } } function find_rating_history($ipaddress, $list) { // Search rating history for this IP address if(!empty($list)) { for($i = 0; $i < count($list); $i++) { if($list[$i][0] == $ipaddress) return $list[$i]; } } return FALSE; } function the_credits() { echo("<div class=\"credit\">Powered by DRBRatings, a <a href=\"http://www.dbscripts.net/ratings/\">free PHP ratings script</a></div>\n"); } ?> I assume this is a really easy and quick fix. The solution is much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/176576-simple-rating-script-little-edit-need-help-with/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.