* @version $Id: count_actors.php,v 1.4 2007/09/08 09:17:16 andig2 Exp $
*/
// move out of contrib for includes
chdir('..');
require_once './core/functions.php';
?>
List actor counts
if ($submit)
{
// validate form data
$maxcount = (is_numeric($maxcount)) ? (int) $maxcount : 0;
// Build query - ignore duplicate imdbID fields
$query = 'SELECT DISTINCT `imdbID`, `director`, `actors` FROM '.TBL_DATA;
if (empty($wishlist)) $query .= ' WHERE mediatype != '.MEDIA_WISHLIST;
$result = runSQL($query);
$includeDirectors = !empty($director);
$actors = array(); // Actor array
// If we are counting the directors separately than the actors, create the array
if (empty($notseparate) && $includeDirectors) {
$directors = array();
$displayDirectorCount = true;
} else {
// Otherwise, use the actor array for directors as well.
$directors = &$actors;
$displayDirectorCount = false;
}
foreach ($result as $row)
{
$cast = split("\r?\n", $row['actors']);
// Counting actors
foreach ($cast as $actor) {
$actorary = split('::', $actor);
if (!isset($actors[$actorary[0]])) {
// Use actor name as array index so all counts are attributed to the same name
$actors[$actorary[0]] = 0;
}
$actors[$actorary[0]]++;
}
// Director count
if ($includeDirectors) {
if (!isset($directors[$row['director']])) {
$directors[$row['director']] = 0;
}
$directors[$row['director']]++;
}
}
// Sort array by actor appearances in reverse order (high to low)
arsort($actors);
$i = 1;
foreach ($actors as $key=>$val)
{
if ($val > $maxcount)
{
// Build name search url
$url = "../search.php?q=%22" . htmlentities(urlencode($key)) . "%22&isname=Y";
// Text for director counts
$dirText = '';
if ($displayDirectorCount && $directors[$key]) {
$dirText = ", " . $directors[$key] . " director entries";
}
echo "$i - $key: $val actor entries" . $dirText . "
";
$i++;
}
}
} else {
?>
Note: Duplicate movie entries (determined by imdbID) will not be counted.
}
?>