Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
230 lines (165 sloc) 5.4 KB
<?php
/**
* Fivestar Stats module. This is used for determining voting statistics,
* as well as looking for abuse of the voting system.
*
* @author Douglas Muth <http://www.dmuth.org/>
*/
//
// Load our required files.
//
include_once("about.inc.php");
include_once("get_total_stats.inc.php");
include_once("get_ips.inc.php");
include_once("get_user_received_stats.inc.php");
include_once("form.inc.php");
include_once("ip.inc.php");
include_once("menu.inc.php");
include_once("recent/main.inc.php");
include_once("tools.inc.php");
include_once("uid_received.inc.php");
/* Testing/Debugging
$data = fivestarstats_uid_received_summary(2);
$data = fivestarstats_uid_received_summary_html(2, true);
print "<pre>"; print_r($data); print "</pre>";
*/
/**
* Our main function. It returns the various reports.
*
* @return string The content of the page
*/
function fivestarstats_main($arg, $arg2, $arg3, $arg4) {
//fivestarstats_debug("$arg, $arg2, $arg3, $arg4"); // Debugging
$retval = "";
if ($arg == "about") {
$retval .= fivestarstats_about();
} else if ($arg == "recent") {
$retval .= fivestarstats_recent();
} else if ($arg == "tools") {
$retval .= fivestarstats_tools();
} else if ($arg == "stats") {
//
// Default action. Load the main screen.
//
$num = 5;
$data = array();
$data["total"] = fivestarstats_get_total_stats();
$data["ips"] = fivestarstats_get_ips($num);
$data["users"] = fivestarstats_get_user_received_stats($num);
$retval .= drupal_get_form("fivestarstats_form", $data);
//$retval .= "<pre>" . print_r($data, true) . "</pre>"; // Debugging
} else {
//
// Default to recent votes.
//
$retval .= fivestarstats_recent();
}
return($retval);
} // End of fivestarstats_main()
/**
* Main function to print up voting history of a specific IP
*
* @param string $ip The IP address to get voting history of.
*/
function fivestarstats_ip($ip) {
$retval = "";
$data = array();
$data["votes"] = fivestarstats_ip_get_votes($ip);
$data["users"] = fivestarstats_ip_get_users($ip);
$retval .= fivestarstats_ip_get_votes_html($ip, $data["votes"]);
$retval .= "<br/>\n";
$retval .= fivestarstats_ip_get_users_html($data["users"]);
//$retval .= "<pre>" . print_r($data, true) . "</pre>"; // Debugging
return($retval);
} // End of fivestarstats_ip()
/**
* Display all specific votes of a certain rating cast by a specific IP.
*
* @param string $ip The IP address
*
* @param mixed $num_stars The number of stars, or "all" for all votes.
* This can be useful for finding all 1-star votes to pick up abuses.
*
* @return string HTML code.
*/
function fivestarstats_ip_votes($ip, $num_stars) {
//
// Since we're two wildcards deep, build breadcrumbs.
//
$breadcrumb = array();
$breadcrumb[] = l(t("Home"), '<front>');
$breadcrumb[] = l(t("Admin"), "admin");
$breadcrumb[] = l(t("Site Configuration"), "admin/settings");
$breadcrumb[] = l(t("Fivestar Stats"), "admin/settings/fivestarstats");
$breadcrumb[] = l(t("IP: !ip", array("!ip" => $ip)),
"admin/settings/fivestarstats/ip/$ip");
drupal_set_breadcrumb($breadcrumb);
if ($num_stars != "all") {
$retval .= t("<h2>%num-star votes cast by IP %ip:</h2>",
array("%ip" => $ip, "%num" => $num_stars));
} else {
$retval .= t("<h2>All votes cast by IP %ip:</h2>",
array("%ip" => $ip));
}
$data = fivestarstats_ip_get_votes_detail($ip, $num_stars);
$retval .= fivestarstats_ip_get_votes_detail_html($data);
//$retval .= "<pre>" . print_r($data, true) . "</pre>"; // Debugging
return($retval);
} // End of fivestarstats_ip_votes()
/**
* Main function to print up votes received on a specific UID.
*
* @param integer $uid The UID to get info of votes cast on.
*
* @return string HTML code.
*/
function fivestarstats_uid($uid) {
$retval = "";
$user = user_load(array("uid" => $uid));
$retval .= t("<h2>Votes received by user %user</h2>",
array("%user" => $user->name)
);
$data = fivestarstats_uid_received_votes($uid);
$retval .= fivestarstats_uid_received_votes_html($uid, $data);
//$retval .= "<pre>" . print_r($data, true) . "</pre>"; // Debugging
return($retval);
} // End of fivestarstats_uid()
/**
* Get detail on votes cast on a specific user
*
* @param integer $uid The user_id
*
* @param mixed $num_stars The number of stars, or "all"
*
* @return string HTML code.
*/
function fivestarstats_uid_received_votes_detail($uid, $num_stars) {
$retval = "";
$user = user_load(array("uid" => $uid));
//
// Since we're two wildcards deep, build breadcrumbs.
//
$breadcrumb = array();
$breadcrumb[] = l(t("Home"), '<front>');
$breadcrumb[] = l(t("Admin"), "admin");
$breadcrumb[] = l(t("Site Configuration"), "admin/settings");
$breadcrumb[] = l(t("Fivestar Stats"), "admin/settings/fivestarstats");
$breadcrumb[] = l(t("User: !user", array("!user" => $user->name)),
"admin/settings/fivestarstats/uid/$uid");
drupal_set_breadcrumb($breadcrumb);
$data = fivestarstats_uid_received_votes_detail_data($uid, $num_stars);
$retval .= fivestarstats_uid_received_votes_detail_html($uid, $user, $data);
//$retval .= "<pre>" . print_r($data, true) . "</pre>"; // Debugging
return($retval);
} // End of fivestarstats_uid_received_votes_detail()
/**
* Our main debug function.
*
* @param string $message
*/
function fivestarstats_debug($message) {
if (is_array($message)) {
$message = "<pre>" . print_r($message, true) . "</pre>";
}
drupal_set_message("Fivestarstats Debug: " . $message);
} // End of fivestar_stats_debug()
Something went wrong with that request. Please try again.