%%[[if edit]]%%
Variable Guide
RatingStack uses a powerful system of PHP to get ratings from your data file and perform
various calculations. You are welcome to reuse any of the following variables in your text or labels, within
RatingStack. A variable always starts with a dollar sign (
$
). For example, the variable
$average
gets replaced with the average rating. This replacement happens when the page is viewed.
- Totals and sums
- $total_count The total number of ratings received.
- $sum_of_ratings The sum of all the ratings added together.
- Averages
- $average The calculated average of the ratings, with no rounding.
- $average_zero The calculated average of the ratings, rounded to zero decimal places.
- $average_one The calculated average of the ratings, rounded to one decimal place.
- $average_two The calculated average of the ratings, rounded to two decimal places.
- $average_three The calculated average of the ratings, rounded to three decimal places.
- Counts
- $is_one The total number of 1-star ratings.
- $is_two The total number of 2-star ratings.
- $is_three The total number of 3-star ratings.
- $is_four The total number of 4-star ratings.
- $is_five The total number of 5-star ratings.
- $lt_one The total number of ratings equal or less-than 1-star.
- $lt_two The total number of ratings equal or less-than 2-star.
- $lt_three The total number of ratings equal or less-than 3-star.
- $lt_four The total number of ratings equal or less-than 4-star.
- $lt_five The total number of ratings equal or less-than 5-star.
- $gt_one The total number of ratings equal or greater-than 1-star.
- $gt_two The total number of ratings equal or greater-than 2-star.
- $gt_three The total number of ratings equal or greater-than 3-star.
- $gt_four The total number of ratings equal or greater-than 4-star.
- $gt_five The total number of ratings equal or greater-than 5-star.
- Percentages
- $pc_one The percentage of 1-star ratings.
- $pc_two The percentage of 2-star ratings.
- $pc_three The percentage of 3-star ratings.
- $pc_four The percentage of 4-star ratings.
- $pc_five The percentage of 5-star ratings.
- $pc_sum_one The combined percentage value of 1-star ratings.
- $pc_sum_two The combined percentage value of 1-star and 2-star ratings.
- $pc_sum_three The combined percentage value of 1-star, 2-star and 3-star ratings.
- $pc_sum_four The combined percentage value of 1-star, 2-star, 3-star and 4-star ratings.
- $pc_lt_one The percentage sum of ratings equal or less than 1-star.
- $pc_lt_two The percentage sum of ratings equal or less than 2-star.
- $pc_lt_three The percentage sum of ratings equal or less than 3-star.
- $pc_lt_four The percentage sum of ratings equal or less than 4-star.
- $pc_lt_five The percentage sum of ratings equal or less than 5-star.
- $pc_gt_one The percentage sum of ratings equal or more than 1-star.
- $pc_gt_two The percentage sum of ratings equal or more than 2-star.
- $pc_gt_three The percentage sum of ratings equal or more than 3-star.
- $pc_gt_four The percentage sum of ratings equal or more than 4-star.
- $pc_gt_five The percentage sum of ratings equal or more than 5-star.
%%[[endif]]%%
%%[[if preview]]%%
0) {
$array = explode("\n", fread($fp, filesize($filename)));
$average = array_sum($array) / count($array);
// Basics
$total_count = count($array);
$sum_of_ratings = array_sum($array);
// Counts
$is_one = 0;
$is_two = 0;
$is_three = 0;
$is_four = 0;
$is_five = 0;
$lt_one = 0;
$lt_two = 0;
$lt_three = 0;
$lt_four = 0;
$lt_five = 0;
$gt_one = 0;
$gt_two = 0;
$gt_three = 0;
$gt_four = 0;
$gt_five = 0;
foreach ($array as $item) {
if ($item == 1) {
$is_one++;
}
if ($item == 2) {
$is_two++;
}
if ($item == 3) {
$is_three++;
}
if ($item == 4) {
$is_four++;
}
if ($item == 5) {
$is_five++;
}
if ($item <= 1) {
$lt_one++;
}
if ($item <= 2) {
$lt_two++;
}
if ($item <= 3) {
$lt_three++;
}
if ($item <= 4) {
$lt_four++;
}
if ($item <= 5) {
$lt_five++;
}
if ($item >= 1) {
$gt_one++;
}
if ($item >= 2) {
$gt_two++;
}
if ($item >= 3) {
$gt_three++;
}
if ($item >= 4) {
$gt_four++;
}
if ($item >= 5) {
$gt_five++;
}
}
// Calculate the average ratings
$average_zero = number_format((float)$average, 0, '.', '');
$average_one = number_format((float)$average, 1, '.', '');
$average_two = number_format((float)$average, 2, '.', '');
$average_three = number_format((float)$average, 3, '.', '');
// Calculate percentages
$pc_one = number_format((float)($is_one / $total_count * 100), 0, '.', '');
$pc_two = number_format((float)($is_two / $total_count * 100), 0, '.', '');
$pc_three = number_format((float)($is_three / $total_count * 100), 0, '.', '');
$pc_four = number_format((float)($is_four / $total_count * 100), 0, '.', '');
$pc_five = number_format((float)($is_five / $total_count * 100), 0, '.', '');
$pc_sum_one = ($pc_one);
$pc_sum_two = ($pc_one + $pc_two);
$pc_sum_three = ($pc_one + $pc_two + $pc_three);
$pc_sum_four = ($pc_one + $pc_two + $pc_three + $pc_four);
$pc_sum_five = ($pc_one + $pc_two + $pc_three + $pc_four + $pc_five);
$pc_lt_one = ($pc_one);
$pc_lt_two = ($pc_one + $pc_two);
$pc_lt_three = ($pc_one + $pc_two + $pc_three);
$pc_lt_four = ($pc_one + $pc_two + $pc_three + $pc_four);
$pc_lt_five = ($pc_one + $pc_two + $pc_three + $pc_four + $pc_five);
$pc_gt_one = ($pc_one + $pc_two + $pc_three + $pc_four + $pc_five);
$pc_gt_two = ($pc_two + $pc_three + $pc_four + $pc_five);
$pc_gt_three = ($pc_three + $pc_four + $pc_five);
$pc_gt_four = ($pc_four + $pc_five);
$pc_gt_five = ($pc_five);
%[if %("%id=config%" == "stars")% ]%
echo "";
if ($average_three === 5) {
echo '%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=solid_star%';
}
if ($average_three > 4 && $average_three < 5) {
echo '%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=half_star%';
}
elseif ($average_three == 4) {
echo '%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=empty_star%';
}
elseif ($average_three > 3 && $average_three < 4) {
echo '%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=half_star%
%id=empty_star%';
}
elseif ($average_three == 3) {
echo '%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=empty_star%
%id=empty_star%';
}
elseif ($average_three > 2 && $average_three < 3) {
echo '%id=solid_star%
%id=solid_star%
%id=half_star%
%id=empty_star%
%id=empty_star%';
}
elseif ($average_three == 2) {
echo '%id=solid_star%
%id=solid_star%
%id=empty_star%
%id=empty_star%
%id=empty_star%';
}
elseif ($average_three > 1 && $average_three < 2) {
echo '%id=solid_star%
%id=half_star%
%id=empty_star%
%id=empty_star%
%id=empty_star%';
}
elseif ($average_three == 1) {
echo '%id=solid_star%
%id=empty_star%
%id=empty_star%
%id=empty_star%
%id=empty_star%';
}
else {
echo '%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=solid_star%';
}
if ($total_count == 0) {
echo "%id=no_reviews%";
}
elseif ($total_count == 1) {
echo "%id=summary_2%";
}
else {
echo "%id=summary_2%";
}
echo "
";
%[endif]%
%[if %("%id=config%" == "bars")% ]%
echo "5 %id=bar_prefix%$pc_five%$is_five ";
echo "4 %id=bar_prefix%$pc_four%$is_four ";
echo "3 %id=bar_prefix%$pc_three%$is_three ";
echo "2 %id=bar_prefix%$pc_two%$is_two ";
echo "1 %id=bar_prefix%$pc_one%$is_one ";
%[endif]%
%[if %("%id=config%" == "text")% ]%
echo "%id=text_output%";
%[endif]%
%[if %("%id=config%" == "custom")% ]%
%id=custom_code%
%[endif]%
}
?>
%%[[endif]]%%
%%[[if publish]]%%
0) {
$array = explode("\n", fread($fp, filesize($filename)));
$average = array_sum($array) / count($array);
// Basics
$total_count = count($array);
$sum_of_ratings = array_sum($array);
// Counts
$is_one = 0;
$is_two = 0;
$is_three = 0;
$is_four = 0;
$is_five = 0;
$lt_one = 0;
$lt_two = 0;
$lt_three = 0;
$lt_four = 0;
$lt_five = 0;
$gt_one = 0;
$gt_two = 0;
$gt_three = 0;
$gt_four = 0;
$gt_five = 0;
foreach ($array as $item) {
if ($item == 1) {
$is_one++;
}
if ($item == 2) {
$is_two++;
}
if ($item == 3) {
$is_three++;
}
if ($item == 4) {
$is_four++;
}
if ($item == 5) {
$is_five++;
}
if ($item <= 1) {
$lt_one++;
}
if ($item <= 2) {
$lt_two++;
}
if ($item <= 3) {
$lt_three++;
}
if ($item <= 4) {
$lt_four++;
}
if ($item <= 5) {
$lt_five++;
}
if ($item >= 1) {
$gt_one++;
}
if ($item >= 2) {
$gt_two++;
}
if ($item >= 3) {
$gt_three++;
}
if ($item >= 4) {
$gt_four++;
}
if ($item >= 5) {
$gt_five++;
}
}
// Calculate the average ratings
$average_zero = number_format((float)$average, 0, '.', '');
$average_one = number_format((float)$average, 1, '.', '');
$average_two = number_format((float)$average, 2, '.', '');
$average_three = number_format((float)$average, 3, '.', '');
// Calculate percentages
$pc_one = number_format((float)($is_one / $total_count * 100), 0, '.', '');
$pc_two = number_format((float)($is_two / $total_count * 100), 0, '.', '');
$pc_three = number_format((float)($is_three / $total_count * 100), 0, '.', '');
$pc_four = number_format((float)($is_four / $total_count * 100), 0, '.', '');
$pc_five = number_format((float)($is_five / $total_count * 100), 0, '.', '');
$pc_sum_one = ($pc_one);
$pc_sum_two = ($pc_one + $pc_two);
$pc_sum_three = ($pc_one + $pc_two + $pc_three);
$pc_sum_four = ($pc_one + $pc_two + $pc_three + $pc_four);
$pc_sum_five = ($pc_one + $pc_two + $pc_three + $pc_four + $pc_five);
$pc_lt_one = ($pc_one);
$pc_lt_two = ($pc_one + $pc_two);
$pc_lt_three = ($pc_one + $pc_two + $pc_three);
$pc_lt_four = ($pc_one + $pc_two + $pc_three + $pc_four);
$pc_lt_five = ($pc_one + $pc_two + $pc_three + $pc_four + $pc_five);
$pc_gt_one = ($pc_one + $pc_two + $pc_three + $pc_four + $pc_five);
$pc_gt_two = ($pc_two + $pc_three + $pc_four + $pc_five);
$pc_gt_three = ($pc_three + $pc_four + $pc_five);
$pc_gt_four = ($pc_four + $pc_five);
$pc_gt_five = ($pc_five);
%[if %("%id=config%" == "stars")% ]%
echo "";
if ($average_three === 5) {
echo '%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=solid_star%';
}
if ($average_three > 4 && $average_three < 5) {
echo '%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=half_star%';
}
elseif ($average_three == 4) {
echo '%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=empty_star%';
}
elseif ($average_three > 3 && $average_three < 4) {
echo '%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=half_star%
%id=empty_star%';
}
elseif ($average_three == 3) {
echo '%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=empty_star%
%id=empty_star%';
}
elseif ($average_three > 2 && $average_three < 3) {
echo '%id=solid_star%
%id=solid_star%
%id=half_star%
%id=empty_star%
%id=empty_star%';
}
elseif ($average_three == 2) {
echo '%id=solid_star%
%id=solid_star%
%id=empty_star%
%id=empty_star%
%id=empty_star%';
}
elseif ($average_three > 1 && $average_three < 2) {
echo '%id=solid_star%
%id=half_star%
%id=empty_star%
%id=empty_star%
%id=empty_star%';
}
elseif ($average_three == 1) {
echo '%id=solid_star%
%id=empty_star%
%id=empty_star%
%id=empty_star%
%id=empty_star%';
}
else {
echo '%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=solid_star%
%id=solid_star%';
}
if ($total_count == 0) {
echo "%id=no_reviews%";
}
elseif ($total_count == 1) {
echo "%id=summary_2%";
}
else {
echo "%id=summary_2%";
}
echo "
";
%[endif]%
%[if %("%id=config%" == "bars")% ]%
echo "5 %id=bar_prefix%$pc_five%$is_five ";
echo "4 %id=bar_prefix%$pc_four%$is_four ";
echo "3 %id=bar_prefix%$pc_three%$is_three ";
echo "2 %id=bar_prefix%$pc_two%$is_two ";
echo "1 %id=bar_prefix%$pc_one%$is_one ";
%[endif]%
%[if %("%id=config%" == "text")% ]%
echo "%id=text_output%";
%[endif]%
%[if %("%id=config%" == "custom")% ]%
%id=custom_code%
%[endif]%
}
?>
%%[[endif]]%%