File: /home/httpd/html/porn.tw/public_html/controllers/control.index_queries.php
<?php
//PLEASE DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
$langSelect = '';
$langJoin = '';
$langWhere = '';
if ($currentLang) {
//$langSelect .= ", `content_languages`.`title` AS `langTitle`, `content_languages`.`description` AS `langDescription`, `content_languages`.`keywords` AS `langKeywords`";
//$langJoin .= " RIGHT JOIN `content_languages` ON `content_languages`.`content` = `content`.`record_num`";
//$langWhere .= " AND `content_languages`.`language` = '$currentLang'";
$langSelect .= ", `content_languages`.`title` AS `langTitle`, `content_languages`.`description` AS `langDescription`, `content_languages`.`keywords` AS `langKeywords`";
$langJoin .= " LEFT JOIN `content_languages` ON `content_languages`.`content` = `content`.`record_num` AND `content_languages`.`language` = '$currentLang'";
$langWhere .= " ";
}
// unset CONTENT FILTER
//if ($_GET['mode'] != 'channel' && !is_numeric($_GET['channel'])) {
// unset($_SESSION['filterContent']);
//}
$page = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 1;
$max_results = $results_per_page;
$from = ($page * $max_results) - $max_results;
$mode = $_REQUEST['mode'];
if ($mode == 'channel' && isset($_GET['type']) && $_GET['type'] !== '') {
if ($_GET['type'] == 'videos') {
$_SESSION['filterContent'] = 'videosOnly';
}
if ($_GET['type'] == 'photos') {
$_SESSION['filterContent'] = 'photosOnly';
}
}
if ($_SESSION['filterContent']) {
if ($_SESSION['filterContent'] == 'photosOnly') {
$filterAnd = "AND `content`.`photos` = 1";
}
if ($_SESSION['filterContent'] == 'videosOnly') {
$filterAnd = "AND `content`.`photos` = 0";
}
}
if ($_GET['durationFrom']) {
$filterAnd .= " AND length > '" . (int) $_GET['durationFrom'] . "' AND photos = 0";
}
if ($_GET['durationTo']) {
$filterAnd .= " AND length < '" . (int) $_GET['durationTo'] . "' AND photos = 0";
}
if (isset($_SESSION["filterType"])) {
$filterAnd .= " AND filter = '" . $_SESSION["filterType"] . "'";
}
if ($_GET['dateRange']) {
if ($_GET['dateRange'] == 'day') {
$dateRange = date('Y-m-d', strtotime('-24 hours'));
} elseif ($_GET['dateRange'] == 'week') {
$dateRange = date('Y-m-d', strtotime('-7 days'));
} elseif ($_GET['dateRange'] == 'month') {
$dateRange = date('Y-m-d', strtotime('-30 days'));
} else {
$dateRange = date('Y-m-d', strtotime('-365 days'));
}
$dateIf = "AND `content`.`encoded_date` >= '$dateRange'";
}
if (!empty($dateIf)) {
$filterAnd .= " " . $dateIf;
}
if (isset($_SESSION['filters']) && $_GET['mode'] !== 'photos' && $_SESSION['filterContent'] !== 'photosOnly') {
if (isset($_SESSION['filters']['hd']) && $_SESSION['filters']['hd'] == '1') {
$filterAnd .= " AND `content`.`movie_height` >= '720'";
}
if (isset($_SESSION['filters']['vr']) && $_SESSION['filters']['vr'] == '1') {
$filterAnd .= " AND `content`.`vr` = '1'";
}
}
if (is_array($topRatedQueryAdditions)) {
$topRatedQueryString = implode(" ", $topRatedQueryAdditions);
}
if (is_array($mostDiscussedQueryAdditions)) {
$mostDiscussedQueryString = implode(" ", $mostDiscussedQueryAdditions);
}
if (is_array($mostViewedQueryAdditions)) {
$mostViewedQueryString = implode(" ", $mostViewedQueryAdditions);
}
if (is_array($longestQueryAdditions)) {
$longestQueryString = implode(" ", $longestQueryAdditions);
}
if (is_array($searchQueryAdditions)) {
$searchQueryString = implode(" ", $searchQueryAdditions);
}
if (is_array($channelQueryAdditions)) {
$channelQueryString = implode(" ", $channelQueryAdditions);
}
if (is_array($paysitesQueryAdditions)) {
$paysitesQueryString = implode(" ", $paysitesQueryAdditions);
}
if (is_array($mostRecentQueryAdditions)) {
$mostRecentQueryString = implode(" ", $mostRecentQueryAdditions);
}
if (is_array($videosQueryAdditions)) {
$videosQueryString = implode(" ", $videosQueryAdditions);
}
if (is_array($randomQueryAdditions)) {
$randomQueryString = implode(" ", $randomQueryAdditions);
}
if (is_array($photosQueryAdditions)) {
$photosQueryString = implode(" ", $photosQueryAdditions);
}
if (is_array($myRentalsQueryAdditions)) {
$myRentalsQueryString = implode(" ", $myRentalsQueryAdditions);
}
if (is_array($defaultQueryAdditions)) {
$defaultQueryString = implode(" ", $defaultQueryAdditions);
}
switch ($mode) {
case 'top-rated':
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 $filterAnd $topRatedQueryString", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile` $langSelect FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num $langJoin WHERE `content`.`enabled` = 1 AND photos = 0 $langWhere $filterAnd $topRatedQueryString ORDER BY `content`.`rating` DESC, views DESC LIMIT $from, $max_results");
break;
case 'most-discussed':
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 $filterAnd $mostDiscussedQueryString", 'count', true);
$results = dbQuery("SELECT `content`.*, (SELECT COUNT(comments.record_num) FROM comments WHERE comments.type = 0 AND comments.content = `content`.`record_num`) AS counter, (SELECT `content_views`.`views` FROM `content_views` WHERE `content_views`.`content` = `content`.`record_num`) AS `views` , (SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`) AS `thumbfile` $langSelect FROM `content` $langJoin WHERE `content`.`enabled` = 1 $langWhere $filterAnd $mostDiscussedQueryString ORDER BY `counter` DESC LIMIT $from,$max_results");
break;
/* User`s favorites will always skip caching results - always get fresh data */
case 'favorites':
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 $filterAnd AND content.record_num IN (SELECT content FROM favorites WHERE user = '$_SESSION[userid]' AND favorites.content = content.record_num)", 'count', true);
$results = dbQuery("SELECT `content`.*, (SELECT `content_views`.`views` FROM `content_views` WHERE `content_views`.`content` = `content`.`record_num`) AS `views`, (SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`) AS `thumbfile`, favorites.record_num as favrecordnum $langSelect FROM content LEFT JOIN favorites ON favorites.content = content.record_num $langJoin WHERE favorites.user = '$_SESSION[userid]' $langWhere AND `content`.`record_num` = `favorites`.`content` AND `content`.`enabled` = 1 $filterAnd GROUP BY `content`.`record_num` ORDER BY `favorites`.`record_num` DESC LIMIT $from,$max_results", false);
$thispage = 'favorites';
break;
case 'most-viewed':
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 AND `content`.`photos` = 0 $filterAnd $mostViewedQueryString", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile` $langSelect FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num $langJoin WHERE `content`.`enabled` = 1 AND photos = 0 $langWhere $filterAnd $mostViewedQueryString ORDER BY `views` DESC LIMIT $from, $max_results");
break;
case 'longest':
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 AND `content`.`photos` = 0 $filterAnd $longestQueryString", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile` $langSelect FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num $langJoin WHERE `content`.`enabled` = 1 AND photos = 0 $langWhere $filterAnd $longestQueryString ORDER BY `length` DESC LIMIT $from, $max_results");
break;
case 'search':
$q = str_replace('-', ' ', mysqli_real_escape_string($dbconn, $_GET['q']));
$type = str_replace('-', ' ', mysqli_real_escape_string($dbconn, $_GET['type']));
if ($_GET['sortby'] == 'views') {
$orderBy = 'ORDER BY `views` DESC';
} elseif ($_GET['sortby'] == 'rating') {
$orderBy = 'ORDER BY `content`.`rating` DESC';
} elseif ($_GET['sortby'] == 'length') {
$orderBy = 'ORDER BY `content`.`length` DESC';
} elseif ($_GET['sortby'] == 'relevancy') {
$orderBy = '';
} elseif ($_GET['sortby'] == 'newest') {
$orderBy = 'ORDER BY `content`.`encoded_date` DESC';
} else {
$orderBy = '';
}
if ($type == "photos") {
$total_results = dbValue("SELECT COUNT(*) AS `count`, MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('$q' IN BOOLEAN MODE) AS `score` FROM `content` JOIN `content_search` ON `content_search`.`content` = `content`.`record_num` WHERE `content`.`enabled` = 1 AND `content`.`photos` = 1 AND MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('$q' IN BOOLEAN MODE) $searchQueryString HAVING `score` > 0", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile`, MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('$q' IN BOOLEAN MODE) AS `score` FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num RIGHT JOIN `content_search` ON `content_search`.`content` = `content`.`record_num` WHERE `content`.`enabled` = 1 AND content.photos = 1 AND MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('$q' IN BOOLEAN MODE) HAVING `score` > 0 $searchQueryString $orderBy LIMIT $from, $max_results");
} else if ($type == "members") {
if ($config['mysql_version'] >= 5.6) {
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `users` WHERE `enabled` = 1 AND MATCH (`username`) AGAINST ('$q' IN BOOLEAN MODE)", 'count', true);
$results = dbQuery("SELECT * FROM `users` WHERE `enabled` = 1 AND MATCH (`username`) AGAINST ('$q' IN BOOLEAN MODE) ORDER BY `username` DESC LIMIT $from, $max_results");
} else {
$total_results = dbValue("SELECT COUNT(*) AS count FROM `users` WHERE `enabled` = 1 AND `username` LIKE '%$q%'", 'count', true);
$results = dbQuery("SELECT * FROM `users` WHERE `enabled` = 1 AND `username` LIKE '%$q%' LIMIT $from, $max_results");
}
} else if ($type == "videos") {
$total_results = dbValue("SELECT COUNT(*) AS `count`, MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('$q' IN BOOLEAN MODE) AS `score` FROM `content` JOIN `content_search` ON `content_search`.`content` = `content`.`record_num` WHERE `content`.`enabled` = 1 AND `content`.`photos` = 0 AND MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('$q' IN BOOLEAN MODE) $searchQueryString HAVING `score` > 0", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('$q' IN BOOLEAN MODE) AS `score` FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num RIGHT JOIN `content_search` ON `content_search`.`content` = `content`.`record_num` WHERE `content`.`enabled` = 1 AND content.photos = 0 AND MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('$q' IN BOOLEAN MODE) HAVING `score` > 0 $searchQueryString $orderBy LIMIT $from, $max_results");
} else {
$total_results = dbValue("SELECT COUNT(*) AS `count`, MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('$q' IN BOOLEAN MODE) AS `score` FROM `content` JOIN `content_search` ON `content_search`.`content` = `content`.`record_num` WHERE `content`.`enabled` = 1 AND MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('$q' IN BOOLEAN MODE) $searchQueryString HAVING `score` > 0", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile`, MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('$q' IN BOOLEAN MODE) AS `score` FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num RIGHT JOIN `content_search` ON `content_search`.`content` = `content`.`record_num` WHERE `content`.`enabled` = 1 AND MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('$q' IN BOOLEAN MODE) HAVING `score` > 0 $searchQueryString $orderBy LIMIT $from, $max_results");
}
/* SELECT `content`.*, content_views.views AS views, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile`, MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('lesbian' IN BOOLEAN MODE) AS `score` FROM `content` RIGHT JOIN `content_search` ON `content_search`.`content` = `content`.`record_num` RIGHT JOIN content_views ON content_views.content = content.record_num WHERE `content`.`enabled` = 1 AND MATCH (`content_search`.`titles`, `content_search`.`keywords`, `content_search`.`descriptions`) AGAINST ('lesbian' IN BOOLEAN MODE) HAVING `score` > 0 ORDER BY score LIMIT 0,30 */
break;
case 'channel':
$chanid = mysqli_real_escape_string($dbconn, $_GET['channel']);
if ($_GET['sortby'] == 'views') {
$orderBy = '`views` DESC';
} elseif ($_GET['sortby'] == 'rating') {
$orderBy = '`content`.`rating` DESC';
} elseif ($_GET['sortby'] == 'length') {
$orderBy = '`content`.`length` DESC';
} elseif ($_GET['sortby'] == 'relevancy') {
$orderBy = '`score` DESC';
} elseif ($_GET['sortby'] == 'newest') {
$orderBy = '`content`.`encoded_date` DESC';
} else {
$orderBy = '`content`.`encoded_date` DESC';
}
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`record_num` IN (SELECT `content` FROM `content_niches` WHERE `niche` = '$chanid') AND `content`.`enabled` = 1 $filterAnd $dateIf $channelQueryString", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile` $langSelect FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num $langJoin WHERE `content`.`enabled` = 1 AND `content`.`record_num` IN (SELECT `content` FROM content_niches WHERE niche = '$chanid') $langWhere $filterAnd $defaultQueryString ORDER BY $orderBy LIMIT $from, $max_results");
break;
case 'my-rentals':
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 $filterAnd $myRentalsQueryString AND content.record_num IN (SELECT content FROM content_purchased WHERE content_purchased.user = '$_SESSION[userid]' AND expires > NOW())", 'count', true);
$results = dbQuery("SELECT `content`.*, (SELECT `content_views`.`views` FROM `content_views` WHERE `content_views`.`content` = `content`.`record_num`) AS `views`, (SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`) AS `thumbfile` $langSelect FROM `content` $langJoin WHERE `content`.`enabled` = 1 $langWhere $filterAnd $dateIf $myRentalsQueryString AND content.record_num IN (SELECT content FROM content_purchased WHERE content_purchased.user = '$_SESSION[userid]' AND expires > NOW()) ORDER BY `encoded_date` DESC LIMIT $from,$max_results");
break;
case 'paysites':
$chanid = mysqli_real_escape_string($dbconn, $_GET['paysite']);
if ($_GET['sortby'] == 'views') {
$orderBy = '`views` DESC';
} elseif ($_GET['sortby'] == 'rating') {
$orderBy = '`content`.`rating` DESC';
} elseif ($_GET['sortby'] == 'length') {
$orderBy = '`content`.`length` DESC';
} elseif ($_GET['sortby'] == 'relevancy') {
$orderBy = '`score` DESC';
} elseif ($_GET['sortby'] == 'newest') {
$orderBy = '`content`.`encoded_date` DESC';
} else {
$orderBy = '`content`.`encoded_date` DESC';
}
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`paysite` = '$chanid' AND `content`.`enabled` = 1 $filterAnd $paysitesQueryString", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile` $langSelect FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num $langJoin WHERE `content`.`enabled` = 1 AND paysite = '$chanid' $langWhere $filterAnd $defaultQueryString GROUP BY `content`.`record_num` ORDER BY $orderBy LIMIT $from, $max_results");
break;
case 'friends':
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `subscriptions`, `users` WHERE `subscriptions`.`user` = '$_SESSION[userid]' AND `subscriptions`.`friend` = `users`.`record_num` AND `users`.`enabled` = 1 GROUP BY `subscriptions`.`friend`", 'count');
$results = dbQuery("SELECT `users`.* FROM `subscriptions`, `users` WHERE `subscriptions`.`user` = '$_SESSION[userid]' AND `subscriptions`.`friend` = `users`.`record_num` AND `users`.`enabled` = 1 GROUP BY `subscriptions`.`friend` ORDER BY `users`.`username` ASC LIMIT $from, $max_results", false);
break;
/* My uploads will always skip caching results - always get fresh data */
case 'my_uploads':
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 $filterAnd AND `content`.`submitter` = '$_SESSION[userid]'", 'count', false);
$results = dbQuery("SELECT `content`.*, (SELECT `content_views`.`views` FROM `content_views` WHERE `content_views`.`content` = `content`.`record_num`) AS `views` , (SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`) AS `thumbfile` $langSelect FROM `content` $langJoin WHERE `content`.`submitter` = '$_SESSION[userid]' AND `content`.`enabled` = 1 $langWhere $filterAnd ORDER BY `content`.`encoded_date` DESC LIMIT $from,$max_results", false);
break;
case 'uploads-by-user':
if (is_numeric($_GET['user'])) {
if ($_GET[photos] == 1) {
$photosAnd = " AND photos = 1";
} else {
$photosAnd = " AND photos = 0";
}
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 $photosAnd $filterAnd AND content.submitter = '$_GET[user]'", 'count');
$results = dbQuery("SELECT `content`.*, (SELECT `content_views`.`views` FROM `content_views` WHERE `content_views`.`content` = `content`.`record_num`) AS `views` , (SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`) AS `thumbfile` $langSelect FROM `content` $langJoin WHERE `content`.`submitter` = '$_GET[user]' $langWhere AND `content`.`enabled` = 1 $photosAnd $filterAnd ORDER BY `content`.`encoded_date` DESC LIMIT $from,$max_results");
}
break;
case 'most-recent':
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 AND `content`.`photos` = 0 $filterAnd $mostRecentQueryString", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile` $langSelect FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num $langJoin WHERE `content`.`enabled` = 1 AND photos = 0 $langWhere $filterAnd $defaultQueryString ORDER BY `encoded_date` DESC LIMIT $from, $max_results");
break;
case 'vr':
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 AND vr = 1 $filterAnd $mostRecentQueryString", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile` $langSelect FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num $langJoin WHERE `content`.`enabled` = 1 AND vr = 1 $langWhere $filterAnd $defaultQueryString ORDER BY `encoded_date` DESC LIMIT $from, $max_results");
break;
case 'videos':
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 AND photos = 0 $filterAnd $videosQueryString", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile` $langSelect FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num $langJoin WHERE `content`.`enabled` = 1 AND photos = 0 $langWhere $filterAnd $defaultQueryString ORDER BY `encoded_date` DESC LIMIT $from, $max_results");
break;
case 'random':
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 $filterAnd $randomQueryString", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile` $langSelect FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num $langJoin WHERE `content`.`enabled` = 1 $langWhere $filterAnd $defaultQueryString ORDER BY RAND() LIMIT $from, $max_results");
break;
case 'photos':
if ($_GET['sortby'] == 'most-viewed') {
$orderBy = '`views` DESC';
} elseif ($_GET['sortby'] == 'top-rated') {
$orderBy = '`content`.`rating` DESC, views DESC';
} elseif ($_GET['sortby'] == 'longest') {
$orderBy = '`content`.`length` DESC';
} elseif ($_GET['sortby'] == 'most-discussed') {
$orderBy = '`numComments` DESC';
} elseif ($_GET['sortby'] == 'most-recent') {
$orderBy = '`content`.`encoded_date` DESC';
} else {
$orderBy = '`content`.`encoded_date` DESC';
}
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 AND photos = 1 $filterAnd $photosQueryString", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, (SELECT COUNT(record_num) FROM comments WHERE content = content.record_num) AS numComments, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile` $langSelect FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num $langJoin WHERE `content`.`enabled` = 1 AND photos = 1 $langWhere $filterAnd $defaultQueryString ORDER BY $orderBy LIMIT $from, $max_results");
break;
default:
$total_results = dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `content`.`enabled` = 1 $filterAnd $defaultQueryString", 'count', true);
$results = dbQuery("SELECT `content`.*, content_views.views AS views, (SELECT IF(content.photos = 1,(SELECT `images`.`filename` FROM `images` WHERE `images`.`record_num` = `content`.`thumbnail`),null)) AS `thumbfile` $langSelect FROM `content` RIGHT JOIN content_views ON content_views.content = content.record_num $langJoin WHERE `content`.`enabled` = 1 $langWhere $filterAnd $defaultQueryString ORDER BY `encoded_date` DESC LIMIT $from, $max_results");
break;
}
$total_pages = ceil($total_results / $max_results);
?>