false, "title"=>"", "width"=>400, "height"=>400); $DID_VOTE = false; if(isset($_SERVER['QUERY_STRING']) && (false===isset($_GET['id']))){ $_GET['id'] = $_SERVER['QUERY_STRING']; // makes the "id=" part of url optional } if(isset($_GET['id'])){ $id = $_GET['id']; $loadedData['id'] = $id; // Log the view of the item. if(false === mysql_query("UPDATE $mediaType SET numViews=numViews+1 WHERE id=$id")){ $singular = getSingular($mediaType); logEvent("Couldn't increment the number of views for $singular with id $id.

".mysql_error()); } // Pre-load the media info $queryString = "SELECT * FROM $mediaType WHERE id=$id"; if($result = mysql_query($queryString,$db)){ if(($numRows = mysql_num_rows($result)) && ($numRows > 0)){ $cnt = 0; $loadedData['url'] = mysql_result($result,$cnt, "url_orig"); $loadedData['title'] = stripslashes(mysql_result($result,$cnt, "title")); $loadedData['caption'] = stripslashes(mysql_result($result,$cnt, "caption")); $loadedData['tags'] = getTags($mediaType, $id); //$loadedData['categories'] = stripslashes(mysql_result($result, $cnt, "categories")); $loadedData['score'] = mysql_result($result,$cnt, "score"); $loadedData['numVotes'] = mysql_result($result,$cnt, "numVotes"); $loadedData['numViews'] = mysql_result($result, $cnt, "numViews"); $loadedData['lowestAge'] = mysql_result($result, $cnt, "lowestAge"); if($mediaType == "movies"){ $loadedData['width'] = mysql_result($result,$cnt, "width"); $loadedData['height'] = mysql_result($result,$cnt, "height"); } else if(($mediaType == "pictures") || ($mediaType == "games") || ($mediaType == "flash")){ $size = getimagesize($loadedData['url']); $loadedData['width'] = $size[0]; $loadedData['height'] = $size[1]; } $loadedData['MEDIA_FOUND'] = true; } } } $loadedData['DID_VOTE'] = $DID_VOTE; return $loadedData; } // end preprocessMedia(...) //// // Displays a rating given the score and number of votes. //// function dispRating($score, $numVotes, $numViews){ print "
\n"; print "\n"; print "
Statistics
\n"; print "
\n"; print ratingContent($score, $numVotes, $numViews); print "
\n"; print "
\n"; } // end dispRating(...) //// // RETURNS the content inside of the ratings div (does not print it). //// function ratingContent($score, $numVotes, $numViews){ $retVal = ""; $retVal .= "Viewed $numViews times
"; if($numVotes == 0){ $retVal .= "[No one has rated this yet]
"; } else { $rating = round(($score / $numVotes), 1); for($stars=1; $stars<5; $stars++){ if($rating >= $stars){ $img = "starOn.png"; } else if($rating > ($stars-1)){ $img = "starHalf.png"; } else { $img = "starOff.png"; } $retVal .= ""; } $retVal .= "
Ave Rating of $rating from $numVotes vote".(($numVotes==1)?"":"s"); } return $retVal; } // end ratingContent(...) //// // Displays a form for rating the current media item. //// function dispRatingForm($mediaType){ $PHP_SELF = $_SERVER['PHP_SELF']; $singular = getSingular($mediaType); $id=""; if(isset($_GET['id'])){ $id = $_GET['id']; } // Prevents multiple voting from simply refreshing the page. $randToken = mt_rand(1,10000); $_SESSION['randToken'] = $randToken; $voteKey = mt_rand(1,10000); $voteVal = createAuth($voteKey, $id); GLOBAL $DID_VOTE; if($DID_VOTE){ dispSuccess("Your rating has been processed. Thank you!"); } else { // TODO: Later on, if desired, the filenames of the on/off/half stars can be loaded into short-named variables to make less overall code (good for bandwidth & load-time). // TODO: Later on, if desired, the filenames of the on/off/half stars can be loaded into short-named variables to make less overall code (good for bandwidth & load-time). // TODO: Also, move this into an outside file (the same one with the ajax for voting) so that it can be cached. // TODO: Also, move this into an outside file (the same one with the ajax for voting) so that it can be cached. ?>
To rate this , click on the stars below
"; print "2"; print "3"; print "4"; ?>

"; print "
$title
"; print "
$caption

\n"; if($caption == ""){print "
\n";} $id = $loadedData['id']; $url = $loadedData['url']; $width = $loadedData['width']; $height = $loadedData['height']; $dimString = makeDimString($width,$height); $extension = strrchr($url, '.'); if(substr($url, 0, 1) == "."){ $absUrl = substr($url, 1); // chops initial '.' if it exists } else { $absUrl = $url; } $absUrl = "http://".$_SERVER['HTTP_HOST'].$absUrl; if($mediaType == "movies"){ if($dimString == ""){ $dimString = "width='400' height='300'"; } //// TODO: SWAP FOR DEBUG //print "\n"; print ""; //// TODO: SWAP FOR DEBUG print "
"; print "Latest versions of Windows Media Player and QuickTime."; print "
(click here to download this movie)"; print "

"; } else if($mediaType == "pictures"){ //print "\n"; scaleMedia($width, $height); $dimString = makeDimString($width,$height); if($extension == ".gif"){ print "\n"; } else { print "\n"; } } else if(($mediaType == "games") || ($mediaType == "flash")){ if(file_exists($url)){ $size = getimagesize($url); $loadedData['width'] = $size[0]; $loadedData['height'] = $size[1]; $width = $loadedData['width']; $height = $loadedData['height']; scaleMedia($width, $height); $dimString = makeDimString($width,$height); print ""; } else { dispError("This content is missing... what's going on!?

We've logged this problem and will look into it."); logEvent($url." appears to be missing"); } } dispTags($loadedData['tags']); dispRating($loadedData['score'], $loadedData['numVotes'], $loadedData['numViews']); dispRatingForm($mediaType); } else { print "
Unable to locate a film with that id. Please check the "; print "$mediaType page for available clips.
\n"; // TODO: Fail more gracefully than a link... display some random media of same type (and general) RIGHT HERE // TODO: Fail more gracefully than a link... display some random media of same type (and general) RIGHT HERE } } // end showMedia(...) function makeDimString($width, $height){ $dimString = ""; if($width!=""){ $dimString .= "width='$width'"; } if($height!=""){ $dimString .= (($dimString=="")?"":" "); $dimString .= "height='$height'"; } if(($width == 0) || ($height == 0)){ $dimString = ""; } return $dimString; } // end makeDimString(...) ?>