start(); extract($_REQUEST); $perpage = 15; // ########################################################################## if ($movieid && !$quoteid && !$characterid) { $alias = str_replace('.html', '', $movieid); $sort = str_replace('.html', '', $sort); $movie = $connect->query_one("SELECT * FROM mqdb_movies WHERE alias = '$alias'"); $movieid = $movie[movieid]; $letter = strtolower(substr($movie[title], 0, 1)); $movie[title] = move_the($movie[title]); $movie[html_title] = htmlspecialchars($movie[title]); if (!$movie[movieid]) { print_error(); } // ---------------------------------------- switch ($sort) { case 'views': case 'ratings': case 'avgrating': $sqlsort = "q.$sort"; $order = 'DESC'; break; default: $sqlsort = 'q.quote'; $order = 'ASC'; // $sort = 'text'; break; } // ---------------------------------------- if ($page) { $page = str_replace('.html', '', $page); $page = str_replace('page_', '', $page); $limitstart = $perpage * ($page - 1); $pagelimit = "LIMIT $limitstart, $perpage"; } else { $pagelimit = "LIMIT $perpage"; } // ---------------------------------------- $quotes = $connect->query("SELECT q.*, r.ratingid, r.ipaddress, r.rating FROM mqdb_quotes q LEFT JOIN mqdb_ratings r ON (q.quoteid = r.quoteid AND ipaddress = '$_SERVER[REMOTE_ADDR]') WHERE q.movieid = '$movieid' ORDER BY $sqlsort $order $pagelimit"); // ---------------------------------------- $characters = $connect->query("SELECT * FROM mqdb_characters WHERE movieid = '$movie[movieid]' ORDER BY first ASC, last ASC"); $charactertotal = $connect->num_rows($characters); $characterhalf = floor($charactertotal / 2); // ---------------------------------------- while ($character = $connect->fetch_array($characters)) { $character[name] = ($character[last]) ? "$character[first] $character[last]" : $character[first]; $character[moviealias] = $movie[alias]; $charactercount++; $smarty->assign('charactercount', $charactercount); $smarty->assign('charactertotal', $charactertotal); $smarty->assign('characterhalf', $characterhalf); $smarty->assign('character', $character); $characterbits .= $smarty->fetch('movie_characterbit.tpl'); } // ---------------------------------------- while ($quote = $connect->fetch_array($quotes)) { $quote[alias] = $movie[alias]; $quote[quote] = str_replace('', '
', $quote[quote]); $quote[quote] = strip_tags(stripslashes($quote[quote]), '
'); list($quote[plus], $quote[ratingclass], $quote[divclass], $quote[showrate]) = process_rating($quote[rating], $quote[ipaddress]); $smarty->assign('quote', $quote); $quotebits .= $smarty->fetch('quotebit.tpl'); } if (intval($letter)) { $urlletter = 'num'; $breadcrumbletter = '#'; } else { $urlletter = $letter; $breadcrumbletter = strtoupper($letter); } // ---------------------------------------- $totalpages = ceil($movie[quotecount] / $perpage); // ---------------------------------------- $page = (intval($page)) ? $page : 1; $nextpage = $page + 1; $lastpage = $page - 1; $smarty->assign('page', $page); $smarty->assign('totalpages', $totalpages); $smarty->assign('lastpage', $lastpage); $smarty->assign('nextpage', $nextpage); $smarty->assign('movie', $movie); $smarty->assign('sort', $sort); $pagenav = $smarty->fetch('pagenav.tpl'); // ---------------------------------------- $breadcrumb = array("/browse/$urlletter.html" => $breadcrumbletter, '' => $movie[title]); // ---------------------------------------- update_counter($movieid, 'movie'); // ---------------------------------------- $smarty->assign('title', "$movie[title] quotes"); $smarty->assign('breadcrumb', $breadcrumb); $smarty->assign('alphabet', $alphabet); $smarty->assign('sort', $sort); $smarty->assign('movie', $movie); $smarty->assign('char', $char); $smarty->assign('characterbits', $characterbits); $smarty->assign('quotebits', $quotebits); $smarty->assign('pagenav', $pagenav); $smarty->display('movie.tpl'); // ########################################################################## } else if ($quoteid && $movieid && !$characterid) { $quoteid = str_replace('.html', '', $quoteid); $movieid = str_replace('.html', '', $movieid); $quote = $connect->query_one("SELECT q.*, c.* FROM mqdb_quotes q LEFT JOIN mqdb_characters c ON (q.characterid = c.characterid) WHERE quoteid = '$quoteid'"); $movie = $connect->query_one("SELECT * FROM mqdb_movies WHERE alias = '$movieid'"); $ratecheck = $connect->query_one("SELECT * FROM mqdb_ratings WHERE quoteid = '$quote[quoteid]' AND ipaddress = '$_SERVER[REMOTE_ADDR]'"); if (!$movie[movieid] || !$quote[quoteid] || ($movie[movieid] != $quote[movieid])) { print_error(); } // ---------------------------------------- $letter = strtolower(substr($movie[title], 0, 1)); if (intval($letter)) { $urlletter = 'num'; $breadcrumbletter = '#'; } else { $urlletter = $letter; $breadcrumbletter = strtoupper($letter); } // ---------------------------------------- $quote[name] = ($quote[last]) ? "$quote[first] $quote[last]" : $quote[first]; $quote[length] = strlen($quote[quote]); $quote[moviealias] = $movie[alias]; $movie[title] = move_the($movie[title]); $quote[movietitle] = $movie[title]; $quote[quote] = str_replace('', '
', $quote[quote]); $quote[quote] = trim(strip_tags(stripslashes($quote[quote]), '
')); $quote[clipboard] = htmlspecialchars(strip_tags($quote[quote])); if ($ratecheck[ratingid]) { if ($ratecheck[rating] > 0) { $quote[yourrating] = "+$ratecheck[rating]"; } else { $quote[yourrating] = "$ratecheck[rating]"; } } $breadcrumb = array("/browse/$urlletter.html" => $breadcrumbletter, "/movies/$movie[alias].html" => "$movie[title]", '' => 'View Quote'); // ---------------------------------------- update_counter($quote[quoteid], 'quote'); // ---------------------------------------- $smarty->assign('title', "View Quote ... $movie[title]"); $smarty->assign('breadcrumb', $breadcrumb); $smarty->assign('alphabet', $alphabet); $smarty->assign('quote', $quote); $smarty->display('quote.tpl'); // ########################################################################## } else if ($characterid && $movieid && !$quoteid) { $movieid = str_replace('.html', '', $movieid); $characterid = str_replace('.html', '', $characterid); $character = $connect->query_one("SELECT * FROM mqdb_characters WHERE characterid = '$characterid'"); $movie = $connect->query_one("SELECT * FROM mqdb_movies WHERE alias = '$movieid'"); if (!$movie[movieid] || !$character[characterid] || ($movie[movieid] != $character[movieid])) { print_error(); } $quotes = $connect->query("SELECT q.*, r.ratingid, r.ipaddress, r.rating FROM mqdb_quotes q LEFT JOIN mqdb_ratings r ON (q.quoteid = r.quoteid AND ipaddress = '$_SERVER[REMOTE_ADDR]') WHERE q.characterid = '$character[characterid]' ORDER BY q.quoteid ASC"); while ($quote = $connect->fetch_array($quotes)) { $quote[alias] = $movie[alias]; $quote[quote] = str_replace('', '
', $quote[quote]); $quote[quote] = strip_tags(stripslashes($quote[quote]), '
'); list($quote[plus], $quote[ratingclass], $quote[divclass], $quote[showrate]) = process_rating($quote[rating], $quote[ipaddress]); $smarty->assign('quote', $quote); $quotebits .= $smarty->fetch('quotebit.tpl'); } $letter = strtolower(substr($movie[title], 0, 1)); if (intval($letter)) { $urlletter = 'num'; $breadcrumbletter = '#'; } else { $urlletter = $letter; $breadcrumbletter = strtoupper($letter); } $movie[title] = move_the($movie[title]); $character[name] = ($character[last]) ? "$character[first] $character[last]" : $character[first]; // ---------------------------------------- $breadcrumb = array("/browse/$urlletter.html" => $breadcrumbletter, "/movies/$movie[alias].html" => $movie[title], '' => $character[name]); // ---------------------------------------- update_counter($character[characterid], 'character'); // ---------------------------------------- $smarty->assign('title', "$character[name] quotes"); $smarty->assign('breadcrumb', $breadcrumb); $smarty->assign('alphabet', $alphabet); $smarty->assign('moviealias', $movie[alias]); $smarty->assign('movietitle', $movie[title]); $smarty->assign('quotebits', $quotebits); $smarty->display('character.tpl'); // ########################################################################## } else { // SHOW HOME PAGE $movies = $connect->query("SELECT * FROM mqdb_movies WHERE quotecount > 0 ORDER BY RAND() LIMIT 11"); $total = $connect->query_one("SELECT COUNT(quoteid) AS quotes FROM mqdb_quotes"); $movietotal = $connect->query_one("SELECT COUNT(movieid) AS count FROM mqdb_movies"); while ($movie = $connect->fetch_array($movies)) { $moviecount++; $movie[moviecount] = $moviecount; $movie[title] = move_the(stripslashes($movie[title])); $movie[html_title] = htmlspecialchars($movie[title]); $smarty->assign('movie', $movie); if ($movie[image] && !$firstmovie) { $firstmovie = $smarty->fetch('home_firstmovie.tpl'); } else { $moviebits .= $smarty->fetch('home_moviebit.tpl'); } } // ---------------------------------------- list($month, $day, $year) = explode('-', date('m-d-Y', time())); $datestamp = mktime(0, 0, 0, $month, $day + 1, $year); $qotd = $connect->query_one("SELECT q.*, c.*, m.title, m.alias FROM (mqdb_quotes q, mqdb_qotd qd) LEFT JOIN mqdb_characters c ON (q.characterid = c.characterid) LEFT JOIN mqdb_movies m ON (q.movieid = m.movieid) WHERE q.quoteid = qd.quoteid AND qd.date < '$datestamp' ORDER BY date DESC LIMIT 1"); $qotd[name] = ($qotd[last]) ? "$qotd[first] $qotd[last]" : $qotd[first]; $qotd[html_name] = htmlspecialchars($qotd[name]); $qotd[html_title] = htmlspecialchars($qotd[title]); $qotd[length] = strlen($qotd[quote]); // ---------------------------------------- $smarty->assign('title', 'Home Page'); $smarty->assign('alphabet', $alphabet); $smarty->assign('moviebits', $moviebits); $smarty->assign('qotd', $qotd); $smarty->assign('qotd_alias', $qotd[alias]); $smarty->assign('total', $total); $smarty->assign('movietotal', $movietotal); $smarty->assign('firstmovie', $firstmovie); $smarty->display('home.tpl'); } // ############################################################## function process_rating($rating, $ipaddress) { global $_SERVER; if ($rating > 0) { $plus = '+'; $ratingclass = 'green'; } else if ($rating < 0) { $plus = ''; $ratingclass = 'red'; } else { $plus = ''; $ratingclass = 'gray'; } if ($ipaddress == $_SERVER[REMOTE_ADDR]) { $divclass = ($rating == 1) ? 'quote green' : 'quote red'; $showrate = false; } else { $divclass = 'quote'; $showrate = true; } return array($plus, $ratingclass, $divclass, $showrate); } ?>