• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.
  • Chevereto Support CLST

    Support response

    Support checklist

    • ⚠️ Got a Something went wrong message? Read this guide and provide the actual error. Do not skip this.
    • ✅ Confirm that the server meets the System Requirements
    • 🔥 Check for any available Hotfix - your issue could be already reported/fixed
    • 📚 Read documentation - It will be required to Debug and understand Errors for a faster support response

route.index.php overrride/mod question

Kai

Chevereto Member
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;
 
Hi,

You should change this:
PHP:
case 'random':

To this:
PHP:
case 'random':
case 'random123':

By doing that you will use the same 'random' for 'random123', then in G\redirect you need a conditional to detect if you are in 'random' or in 'random123' and change the redirect target depending on that.
 
I do not grasp the G\redirect conditional. Can you provide an example I can copy paste? Thanks.

I understand having two cases though and have already done this step. :)
 
G\redirect($image ? CHV\Image::getUrlViewer(CHV\encodeID($imageID)) : '?random');

This line needs modification, correct?
 
To be clear, I know what a conditional statement is. I do not know how to form one correctly in this situation.
 
Just wrap a conditional for a new aux variable like $redirect_to and put that in G\redirect, something like this:

PHP:
if(key($querystr)=='random') {
    $redirect_to = $image ? CHV\Image::getUrlViewer(CHV\encodeID($imageID)) : '?random';
} else {
    $redirect_to = $image ? ('image123/' . CHV\encodeID($imageID)) : '?random123';
}
G\redirect($redirect_to);
 
Last edited:
Back
Top