Hi Rodolfo,
I'd like to duplicate the ?random capability with a minor change. It should redirect not to /image/XX but /image123/XX. ?random should still redirect to /image/XX. I just want ?random123 to redirect to /image123/XX. Thanks in advance.
---------------------------------------------------------------------------------------
case 'random':
if(!CHV\getSetting('website_random')) {
break;
}
$tables = CHV\DB::getTables();
$db = CHV\DB::getInstance();
$db->query('SELECT MIN(image_id) as min, MAX(image_id) as max FROM '.$tables['images']);
$limit = $db->fetchSingle();
// Try to get the right image
$random_ids = G\random_values($limit['min'], $limit['max'], 10);
if(is_null($random_ids)) {
G\redirect();
} else {
if(count($random_ids) == 1) {
$random_ids[] = $random_ids[0];
}
}
if($limit['min'] !== $limit['max']) {
// Do NOT show the last viewed image
$last_viewed_image = CHV\decodeID($_SESSION['last_viewed_image']);
if(($key = array_search($last_viewed_image, $random_ids)) !== false) {
unset($random_ids[$key]);
}
}
$query = 'SELECT image_id FROM '.$tables['images'].' LEFT JOIN '.$tables['albums'].' ON '.$tables['images'].'.image_album_id = '.$tables['albums'].'.album_id WHERE image_id IN ('.join(',', $random_ids).") AND (album_privacy = 'public' OR album_privacy IS NULL) ";
// Don't show NSFW in random mode
if(!CHV\getSetting('show_nsfw_in_random_mode')) {
if($logged_user) {
$query .= 'AND ('.$tables['images'].'.image_nsfw = 0 OR '.$tables['images'].'.image_user_id = '.$logged_user['id'].') ';
} else {
$query .= 'AND '.$tables['images'].'.image_nsfw = 0 ';
}
}
if($handler::getCond('forced_private_mode')) {
$query .= 'AND '.$tables['images'].'.image_user_id = '.$logged_user['id'].' ';
}
$query .= 'ORDER BY RAND() LIMIT 1';
$db->query($query);
$imageID = $db->fetchSingle()['image_id'];
$image = CHV\Image::getSingle($imageID, false, true);;
// Does exists in the disk?
if($image['file_resource']['chain']['image'] == NULL) $image = false;
if(!$image) {
if($_SESSION['random_failure'] > 3) {
G\redirect();
} else {
$_SESSION['random_failure'] += 1;
}
} else {
unset($_SESSION['random_failure']);
}
G\redirect($image ? CHV\Image::getUrlViewer(CHV\encodeID($imageID)) : '?random');
break;
I'd like to duplicate the ?random capability with a minor change. It should redirect not to /image/XX but /image123/XX. ?random should still redirect to /image/XX. I just want ?random123 to redirect to /image123/XX. Thanks in advance.
---------------------------------------------------------------------------------------
case 'random':
if(!CHV\getSetting('website_random')) {
break;
}
$tables = CHV\DB::getTables();
$db = CHV\DB::getInstance();
$db->query('SELECT MIN(image_id) as min, MAX(image_id) as max FROM '.$tables['images']);
$limit = $db->fetchSingle();
// Try to get the right image
$random_ids = G\random_values($limit['min'], $limit['max'], 10);
if(is_null($random_ids)) {
G\redirect();
} else {
if(count($random_ids) == 1) {
$random_ids[] = $random_ids[0];
}
}
if($limit['min'] !== $limit['max']) {
// Do NOT show the last viewed image
$last_viewed_image = CHV\decodeID($_SESSION['last_viewed_image']);
if(($key = array_search($last_viewed_image, $random_ids)) !== false) {
unset($random_ids[$key]);
}
}
$query = 'SELECT image_id FROM '.$tables['images'].' LEFT JOIN '.$tables['albums'].' ON '.$tables['images'].'.image_album_id = '.$tables['albums'].'.album_id WHERE image_id IN ('.join(',', $random_ids).") AND (album_privacy = 'public' OR album_privacy IS NULL) ";
// Don't show NSFW in random mode
if(!CHV\getSetting('show_nsfw_in_random_mode')) {
if($logged_user) {
$query .= 'AND ('.$tables['images'].'.image_nsfw = 0 OR '.$tables['images'].'.image_user_id = '.$logged_user['id'].') ';
} else {
$query .= 'AND '.$tables['images'].'.image_nsfw = 0 ';
}
}
if($handler::getCond('forced_private_mode')) {
$query .= 'AND '.$tables['images'].'.image_user_id = '.$logged_user['id'].' ';
}
$query .= 'ORDER BY RAND() LIMIT 1';
$db->query($query);
$imageID = $db->fetchSingle()['image_id'];
$image = CHV\Image::getSingle($imageID, false, true);;
// Does exists in the disk?
if($image['file_resource']['chain']['image'] == NULL) $image = false;
if(!$image) {
if($_SESSION['random_failure'] > 3) {
G\redirect();
} else {
$_SESSION['random_failure'] += 1;
}
} else {
unset($_SESSION['random_failure']);
}
G\redirect($image ? CHV\Image::getUrlViewer(CHV\encodeID($imageID)) : '?random');
break;