Example #1
0
/**
 * Prints the rating accordingly to option, it's a combined function for image and album rating
 *
 * @param string $option "image" for image rating, "album" for album rating.
 * @see printImageRating() and printAlbumRating()
 *
 */
function printRating($option)
{
    switch ($option) {
        case "image":
            $id = getImageID();
            $value = getImageRating("totalvalue", $id);
            $votes = getImageRating("totalvotes", $id);
            break;
        case "album":
            $id = getAlbumID();
            $value = getAlbumRating("totalvalue", $id);
            $votes = getAlbumRating("totalvotes", $id);
            break;
    }
    if ($votes != 0) {
        $ratingpx = round($value / $votes * 25);
    } else {
        $ratingpx = '';
    }
    $zenpath = WEBPATH . "/" . ZENFOLDER . "/plugins";
    echo "<div id=\"rating\">\n";
    echo "<ul class=\"star-rating\">\n";
    echo "<li class=\"current-rating\" id=\"current-rating\"";
    if (!empty($ratingpx)) {
        echo " style=\"width: " . $ratingpx . "px;\"";
    }
    echo "></li>\n";
    $msg1 = gettext("Rating");
    $msg2 = gettext("Total votes");
    if (!checkForIP(sanitize($_SERVER['REMOTE_ADDR'], 0), $id, $option)) {
        echo "<li><a href=\"javascript:rate(1,{$id},'" . rawurlencode($zenpath) . "','{$option}')\" title=\"" . gettext("1 star out of 5") . "\" class=\"one-star\">2</a></li>\n";
        echo "<li><a href=\"javascript:rate(2,{$id},'" . rawurlencode($zenpath) . "','{$option}')\" title=\"" . gettext("2 stars out of 5") . "\" class=\"two-stars\">2</a></li>\n";
        echo "<li><a href=\"javascript:rate(3,{$id},'" . rawurlencode($zenpath) . "','{$option}')\" title=\"" . gettext("3 stars out of 5") . "\" class=\"three-stars\">2</a></li>\n";
        echo "<li><a href=\"javascript:rate(4,{$id},'" . rawurlencode($zenpath) . "','{$option}')\" title=\"" . gettext("4 stars out of 5") . "\" class=\"four-stars\">2</a></li>\n";
        echo "<li><a href=\"javascript:rate(5,{$id},'" . rawurlencode($zenpath) . "','{$option}')\" title=\"" . gettext("5 stars out of 5") . "\" class=\"five-stars\">2</a></li>\n";
    }
    echo "</ul>\n";
    echo "<div id =\"vote\">\n";
    switch ($option) {
        case "image":
            echo $msg1 . ' ' . getImageRatingCurrent($id) . ' (' . $msg2 . ': ' . $votes . ")";
            break;
        case "album":
            echo $msg1 . ' ' . getAlbumRatingCurrent($id) . ' (' . $msg2 . ': ' . $votes . ")";
            break;
    }
    echo "</div>\n";
    echo "</div>\n";
}
Example #2
0
<?php

/**
 * rating plugin - Updates the rating in the database
 * @author Malte Müller (acrylian) and Stephen Billard (sbillard)
 * @version 1.0.1
 * @package plugins
 */
require '../../template-functions.php';
require_once 'functions-rating.php';
$id = sanitize_numeric($_GET['id']);
$rating = sanitize_numeric($_GET['rating']);
$option = $_GET['option'];
switch ($option) {
    case "image":
        $dbtable = prefix('images');
        break;
    case "album":
        $dbtable = prefix('albums');
        break;
}
if ($rating > 5) {
    $rating = 5;
}
$ip = sanitize($_SERVER['REMOTE_ADDR'], 0);
if (!checkForIP($ip, $id, $option)) {
    $_rating_current_IPlist[] = $ip;
    $insertip = serialize($_rating_current_IPlist);
    query("UPDATE " . $dbtable . " SET total_votes = total_votes + 1, total_value = total_value + " . $rating . ", used_ips='" . $insertip . "' WHERE id = '" . $id . "'");
}