• 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

Making "embed codes" the default tab

steve31

Chevereto Member
I've searched the whole forum, and found only vague information. I want to make "embed codes" the default tab.

Assume I have very little experience with editing php and js files. I know how to find text and edit it, but I dont understand the source codes.

So please, anyone, just tell me in plain english with simple steps, HOW CAN I MAKE "EMBED CODES" THE DEFAULT TAB THAT USERS FIRST SEE AFTER UPLOADING AN IMAGE.

Please dont give vague information. I've wasted hours here and trying to figure it out myself, and didnt find a clear answer. I'm very surprised this the embed codes are not default to begin with, because its a major feature that would make a person prefer one image hosting site over another. Who wants to do an extra click??
 
in app/themes/Peafowl/image.php

Find
PHP:
        <?php
            global $tabs; // Define it as a global to bind it on the included tab.php
            $tabs = [
                [
                    "label"        => _s('About'),
                    "id"        => "tab-about",
                    "current"    => true,
                ]
            ];
      
            if(CHV\getSetting('theme_show_embed_content')) {
                $tabs[] = [
                    "label"        => _s('Embed codes'),
                    "id"        => "tab-codes",
 
                ];
            }
      
            if(is_admin()) {
                $tabs[] = [
                    "label"        => _s('Full info'),
                    "id"        => "tab-full-info"
                ];
            }
      
            G\Render\include_theme_file("snippets/tabs");
        ?>

Change to

PHP:
        <?php
            global $tabs; // Define it as a global to bind it on the included tab.php
            $tabs = [
                [
                    "label"        => _s('About'),
                    "id"        => "tab-about",
                ]
            ];
      
            if(CHV\getSetting('theme_show_embed_content')) {
                $tabs[] = [
                    "label"        => _s('Embed codes'),
                    "id"        => "tab-codes",
                    "current"    => true,
                ];
            }
      
            if(is_admin()) {
                $tabs[] = [
                    "label"        => _s('Full info'),
                    "id"        => "tab-full-info"
                ];
            }
      
            G\Render\include_theme_file("snippets/tabs");
        ?>
This won't remain after an update unless you clone the page as you should when modifying portions.

I'm very surprised this the embed codes are not default to begin with, because its a major feature that would make a person prefer one image hosting site over another.

Not everyone runs an image uploading site to be hot linked. I run a targeted gallery for artists where hotlinking is a secondary function.

Your use case is not global use case.
 
Last edited:
Thanks but there is no such file at that path. The file I see with that code is \app\routes\route.image.php and I changed it there.

This then changes the default tab, but it shows as WHITE with no links. So then I clcik the "about" tab and back to "embed codes", and then the codes display. So there is a problem somewhere. How can we fix this?
 
Tabs changed some releases ago. The actual tabs code is at app/routes/route.image.php and is easy as change this:

PHP:
        $tabs = [
            [
                "label"        => _s('About'),
                "id"        => "tab-about",
                "current"    => true,
            ]
        ];
        if(CHV\getSetting('theme_show_embed_content')) {
            $tabs[] = [
                "label"        => _s('Embed codes'),
                "id"        => "tab-codes",
            ];
        }

To this:

PHP:
        $tabs = [
            [
                "label"        => _s('About'),
                "id"        => "tab-about",
            ]
        ];
        if(CHV\getSetting('theme_show_embed_content')) {
            $tabs[] = [
                "label"        => _s('Embed codes'),
                "id"        => "tab-codes",
                "current"    => true,
            ];
        }
 
Thanks but there is no such file at that path. The file I see with that code is \app\routes\route.image.php and I changed it there.

This then changes the default tab, but it shows as WHITE with no links. So then I clcik the "about" tab and back to "embed codes", and then the codes display. So there is a problem somewhere. How can we fix this?

I did not properly test, but that IS the right location. I've tested it on my secondary. site and it works perfectly fine. Copy route.image.php and paste it into the overrides in that same folder. This will allow the change to 'stick' during updates.

Name the override route.images.php The follow should be the ENTIRE file as of 1.8.0

PHP:
<?php

/* --------------------------------------------------------------------

  Chevereto
  http://chevereto.com/

  @author    Rodolfo Berrios A. <http://rodolfoberrios.com/>
            <inbox@rodolfoberrios.com>

  Copyright (C) Rodolfo Berrios A. All rights reserved.
 
  BY USING THIS SOFTWARE YOU DECLARE TO ACCEPT THE CHEVERETO EULA
  http://chevereto.com/license

  --------------------------------------------------------------------- */

$route = function($handler) {
    try {
       
        if($handler->isRequestLevel(3)) return $handler->issue404(); // Allow only 2 levels
       
        if(is_null($handler->request[0])) {
            return $handler->issue404();
        }
       
        $logged_user = CHV\Login::getUser();
       
        // User status override redirect
        CHV\User::statusRedirect($logged_user['status']);

        $id = CHV\decodeID($handler->request[0]);
       
        $tables = CHV\DB::getTables();
       
        if($id==0) {
            return $handler->issue404();
        }
       
        // Trail this view
        $_SESSION['last_viewed_image'] = CHV\encodeId($id);
       
        // Session stock viewed images
        if(!$_SESSION['image_view_stock']) {
            $_SESSION['image_view_stock'] = [];
        }
       
        // Get image DB
        $image = CHV\Image::getSingle($id, !in_array($id, $_SESSION['image_view_stock']), TRUE, $logged_user);
       
        // Stock this image view
        $_SESSION['image_view_stock'][] = $id;
       
        // No image or belongs to a banned user if exists?
        if(!$image or (!$logged_user['is_admin'] && !is_null($image['user']['status']) && $image['user']['status'] !== 'valid')) {
            return $handler->issue404();
        }
       
        // Test remote image
        if($image['file_resource']['type'] == 'url') {
            $url = preg_replace('/^https:/i', 'http:', $image['file_resource']['chain']['image']);
            $headers = G\getUrlHeaders($url, [CURLOPT_REFERER => G\get_current_url()]); // Add referrer for some CDN restrictions
            $error_tpl = "Can't fetch file header from external storage server: %url (%e)";
            if($headers['http_code'] == 500) { // Internal (curl) error
                $error_e = $headers['error'];
            } else if($headers['http_code'] !== 200) {
                $error_e = $headers['http_code'];
            }
            if($error_e) {
                error_log(strtr($error_tpl, ['%url' => $url, '%e' => $error_e]));
                if($headers['http_code'] !== 200) {
                    return $handler->issue404();
                }
            }
        } else {
            if(!$image['file_resource']['chain']['image'] || !file_exists($image['file_resource']['chain']['image'])) {
                //CHV\Image::delete($id);
                return $handler->issue404();
            }
            // Update is_animated flag
            if($image['extension'] == 'gif' && !$image['is_animated'] && G\is_animated_image($image['file_resource']['chain']['image'])) {
                CHV\Image::update($id, ['is_animated' => 1]);
                $image['is_animated'] = 1;
            }
        }

        $is_owner = $image['user']['id'] !== NULL ? ($image['user']['id'] == $logged_user['id']) : false;
       
        // Password protected content
        if((!$handler::getCond('admin') || !$is_owner) && $image['album']['privacy'] == 'password' && !CHV\Album::checkSessionPassword($image['album'])) {
            G\redirect($image['album']['url']);
        }
       
        // Private profile
        if($image['user']['is_private'] && !$logged_user['is_admin'] && $image["user"]["id"] !== $logged_user['id']) {
            unset($image['user']);
            $image['user'] = CHV\User::getPrivate();
        }
       
        // Privacy
        if($handler::getCond('forced_private_mode')) {
            $image['album']['privacy'] = CHV\getSetting('website_content_privacy_mode');
        }
        if(!$handler::getCond('admin') and in_array($image['album']['privacy'], array('private', 'custom')) and !$is_owner) {
            return $handler->issue404();
        }
       
        $db = CHV\DB::getInstance();
       
        // User found
        if($image['user']['id'] !== NULL) {
           
            // Get user albums
            $name_array = explode(' ', $image['user']['name']);
            $user_name_short = $name_array[0];
           
            $image['user']['albums'] = [];
           
            // Lets fake the stream as an album
            $image['user']['albums']['stream'] = CHV\User::getStreamAlbum($image['user']);
           
            // Get user album list
            $image['user']['albums'] += CHV\DB::get('albums', ['user_id' => $image['user']['id']], 'AND', ['field' => 'name', 'order' => 'asc']);
           
            foreach($image['user']['albums'] as $k => $v) {
                $image['user']['albums'][$k] = CHV\DB::formatRow($v, 'album');
                CHV\Album::fill($image['user']['albums'][$k]);
            }
           
        }

        // Get the album slice
        if($image['album']['id'] !== NULL) {
            $get_album_slice = CHV\Image::getAlbumSlice($image['id'], $image['album']['id'], 2);
            $image_album_slice_db = $get_album_slice['db'];
            $image_album_slice = array_merge($image['album'], $get_album_slice['formatted']);
        }
       
        $image_safe_html =  G\safe_html($image);
       
        $pre_doctitle = $image_safe_html['title'] ?: ($image_safe_html['name'].'.'.$image_safe_html['extension']) . ' hosted at ' . CHV\getSetting('website_name');
       
        $tabs = [
            [
                "label"        => _s('About'),
                "id"        => "tab-about",

            ]
        ];
        if(CHV\getSetting('theme_show_embed_content')) {
            $tabs[] = [
                "label"        => _s('Embed codes'),
                "id"        => "tab-codes",
                "current"    => true,
            ];
        }
       
        if($handler::getCond('admin')) {
            $tabs[] = [
                "label"        => _s('Full info'),
                "id"        => "tab-full-info"
            ];
           
            // Banned uploader IP?
            $banned_uploader_ip = CHV\Ip_ban::getSingle(['ip' => $image['uploader_ip']]);
           
            // Admin list values
            $image_admin_list_values = [
                [
                    'label'        => _s('Image ID'),
                    'content'    => $image['id'] . ' ('.$image['id_encoded'].')'
                ],
                [
                    'label'        => _s('Uploader IP'),
                    'content'    => sprintf(str_replace('%IP','%1$s', '<a href="'.CHV\getSetting('ip_whois_url').'" target="_blank">%IP</a> 路 <a href="'.G\get_base_url('search/images/?q=ip:%IP').'">'._s('search content').'</a>  路  ' . (!$banned_uploader_ip ? ('<a data-modal="form" data-args="%IP" data-target="modal-add-ip_ban" data-options=\'{"forced": true}\' data-content="ban_uploader_ip">' . _s('Ban IP') . '</a>') : NULL) . '<span class="'. ($banned_uploader_ip ? NULL : 'soft-hidden') .'" data-content="banned_uploader_ip">'._s('IP already banned').'</span>'), $image['uploader_ip'])
                ],
                [
                    'label'     => _s('Upload date'),
                    'content'    => $image['date']
                ],
                [
                    'label'     => '',
                    'content'     => $image['date_gmt'] . ' (GMT)'
                ]
            ];
           
            $handler::setVar('image_admin_list_values', $image_admin_list_values);
            $handler::setCond('banned_uploader_ip', (bool)$banned_uploader_ip);
        }
       
        $handler::setCond('owner', $is_owner);
        $handler::setVar('pre_doctitle', $pre_doctitle);
        $handler::setVar('image_album_slice_db', $image_album_slice_db);
        $handler::setVar('image', $image);
        $handler::setVar('image_safe_html', $image_safe_html);
        $handler::setVar('image_album_slice', G\safe_html($image_album_slice));
        $handler::setVar('tabs', $tabs);
        $handler::setVar('owner', $image['user']);
       
        // Populate image category to meta keywords
        $category = $handler::getVar('categories')[$image['category_id']];
        if($category) {
            $handler::setVar('meta_keywords', _s('%s images', $category['name']) . ', ' . $handler::getVar('meta_keywords'));
        }
       
        // Populate the image meta description
        if($image['description']) {
            $meta_description = $image['description'];
        } else {
            if($image['album']['name']) {
                $meta_description = _s('Image %i in %a album', ['%i' => $image[is_null($image['title']) ? 'filename' : 'title'], '%a' => $image['album']['name']]);
            } else if($image['category']['id']) {
                $meta_description = _s('Image %i in %c category', ['%i' => $image[is_null($image['title']) ? 'filename' : 'title'], '%c' => $image['category']['name']]);
            } else {
                $meta_description = _s('Image %i hosted in %w', ['%i' => $image[is_null($image['title']) ? 'filename' : 'title'], '%w' => CHV\getSetting('website_name')]);
            }
        }
        $handler::setVar('meta_description', htmlspecialchars($meta_description));
       
        if($handler::getCond('admin') or $is_owner) {
            $handler::setVar('user_items_editor', [
                'user_albums'    => $image['user']['albums'],
                'type'            => 'image',
                'album'            => $image['album'],
                'category_id'    => $image['category_id']
            ]);
        }
       
        // Share thing
        $share_element = [
            'referer'        => G\get_base_url(),
            'url'            => $image['url_viewer'],
            'image'            => $image['url'],
            'title'            => $handler::getVar('pre_doctitle')
        ];
        $share_element['HTML'] = '<a href="'.$share_element["url"].'" title="'.$share_element["title"].'"><img src="'.$share_element["image"].'" /></a>';
        $share_links_array = CHV\render\get_share_links($share_element);
        $handler::setVar('share_links_array', $share_links_array);
       
        // Share modal
        $handler::setVar('share_modal', [
            'type'            => 'image',
            'url'            => $image['url_viewer'],
            'links_array'    => $share_links_array,
            'privacy'        => $image['album']['privacy'],
            'privacy_notes'    => $image['album']['privacy_notes'],
        ]);
       
        // Embed codes
        $embed = [];
        $embed['direct-links'] = [
            'label' => _s('Direct links'),
            'entries' => [
                [
                    'label' => _s('Image URL'),
                    'value' => $image['url']
                ],
                [
                    'label' => _s('Image link'),
                    'value' => $image['url_viewer']
                ],
                [
                    'label' => _s('Thumbnail URL'),
                    'value' => $image['thumb']['url']
                ],
            ]
        ];
        if($image['medium']) {
            $embed['direct-links']['entries'][] = [
                'label' => _s('Medium URL'),
                'value' => $image['medium']['url']
            ];
        }
       
        $image_full = [
            'html'        => '<img src="'.$image['url'].'" alt="'.$image['filename'].'" border="0" />',
            'markdown'    => '!['.$image['filename'].']('.$image['url'].')'
        ];
        $image_full['bbcode'] = G\html_to_bbcode($image_full['html']);
       
        $embed['full-image'] = [
            'label' => _s('Full image'),
            'entries' => [
                [
                    'label' => 'HTML',
                    'value' => htmlentities($image_full['html'])
                ],
                [
                    'label' => 'BBCode',
                    'value' => $image_full['bbcode']
                ],
                [
                    'label' => 'Markdown',
                    'value' => $image_full['markdown']
                ],
            ]
        ];
       
        $embed_full_linked['html'] = '<a href="'.$image['url_viewer'].'">'.$image_full['html'].'</a>';
        $embed_full_linked['bbcode'] = G\html_to_bbcode($embed_full_linked['html']);
        $embed_full_linked['markdown'] = '[!['.$image['filename'].']('.$image['url'].')]('.$image['url_viewer'].')';
       
        $embed['full-linked'] = [
            'label' => _s('Full image (linked)'),
            'entries' => [
                [
                    'label' => 'HTML',
                    'value' => htmlentities($embed_full_linked['html'])
                ],
                [
                    'label' => 'BBCode',
                    'value' => $embed_full_linked['bbcode']
                ],
                [
                    'label' => 'Markdown',
                    'value' => $embed_full_linked['markdown']
                ],
            ]
        ];
       
        if($image['medium']) {
            $embed_medium_linked = array(
                "html" => '<a href="'.$image['url_viewer'].'"><img src="'.$image['medium']['url'].'" alt="'.$image['filename'].'" border="0" /></a>'
            );
            $embed_medium_linked['bbcode'] = G\html_to_bbcode($embed_medium_linked['html']);
            $embed_medium_linked['markdown'] = '[!['.$image['medium']['filename'].']('.$image['medium']['url'].')]('.$image['url_viewer'].')';
            $embed['medium-linked'] = [
                'label' => _s('Medium image (linked)'),
                'entries' => [
                    [
                        'label' => 'HTML',
                        'value' => htmlentities($embed_medium_linked['html'])
                    ],
                    [
                        'label' => 'BBCode',
                        'value' => $embed_medium_linked['bbcode']
                    ],
                    [
                        'label' => 'Markdown',
                        'value' => $embed_medium_linked['markdown']
                    ],
                ]
            ];
        }
       
        $embed_thumb_linked = [
            'html' => '<a href="'.$image['url_viewer'].'"><img src="'.$image['thumb']['url'].'" alt="'.$image['filename'].'" border="0" /></a>'
        ];
        $embed_thumb_linked['bbcode'] = G\html_to_bbcode($embed_thumb_linked['html']);
        $embed_thumb_linked['markdown'] = '[!['.$image['thumb']['filename'].']('.$image['thumb']['url'].')]('.$image['url_viewer'].')';
       
        $embed['thumb-linked'] = [
            'label' => _s('Thumbnail image (linked)'),
            'entries' => [
                [
                    'label' => 'HTML',
                    'value' => htmlentities($embed_thumb_linked['html'])
                ],
                [
                    'label' => 'BBCode',
                    'value' => $embed_thumb_linked['bbcode']
                ],
                [
                    'label' => 'Markdown',
                    'value' => $embed_thumb_linked['markdown']
                ],
            ]
        ];
       
        // Insert an embed id for each entry (for the cliboard.js bind)
        $embed_id = 1;
        foreach($embed as &$v) {
            foreach($v['entries'] as &$entry) {
                $entry['id'] = 'embed-code-' . $embed_id;
                $embed_id++;
            }
        }
       
        $handler::setVar('embed', $embed);
       
    } catch(Exception $e) {
        G\exception_to_error($e);
    }
};

This is the ENTIRE contents of that file. If this does not work then there is something else wrong with your install.
 
I cant upload php file but this is in it:

$tabs = [
[
"label" => _s('About'),
"id" => "tab-about",
"current" => true,
]
];
if(CHV\getSetting('theme_show_embed_content')) {
$tabs[] = [
"label" => _s('Embed codes'),
"id" => "tab-codes",
"current" => true,
];
}

if($handler::getCond('admin')) {
$tabs[] = [
"label" => _s('Full info'),
"id" => "tab-full-info"
];
 
Try using this file and remember to flush any server cache that could be catching this file.
 

Attachments

  • route.image.zip
    3.6 KB · Views: 10
Ok i installed the file, and embed codes is automatically selected. But I still need to flick between tabs for the codes to appear. I tried with different browsers and got same result.
 
It seems that it only affects the "current" class but not the content. The system wasn't build for that so I need to update the theme view. I will add it in the next release which should arrive next week.
 
Last edited:
Ok thanks, but when will that be? I dont want to spend money promoting the site until this issue is resolved.
 
Ok thanks, but when will that be? I dont want to spend money promoting the site until this issue is resolved.

Well, you could do it by hand if you can't wait. Open app/themes/Peafowl/views/image.php

Change this:
Code:
<div id="tab-about" class="tabbed-content visible">

To this:
Code:
<div id="tab-about" class="tabbed-content">

Change this:
Code:
<div id="tab-codes" class="tabbed-content">

To this:
Code:
<div id="tab-codes" class="tabbed-content visible">
 
Tabs changed some releases ago. The actual tabs code is at app/routes/route.image.php and is easy as change this:

PHP:
        $tabs = [
            [
                "label"        => _s('About'),
                "id"        => "tab-about",
                "current"    => true,
            ]
        ];
        if(CHV\getSetting('theme_show_embed_content')) {
            $tabs[] = [
                "label"        => _s('Embed codes'),
                "id"        => "tab-codes",
            ];
        }

To this:

PHP:
        $tabs = [
            [
                "label"        => _s('About'),
                "id"        => "tab-about",
            ]
        ];
        if(CHV\getSetting('theme_show_embed_content')) {
            $tabs[] = [
                "label"        => _s('Embed codes'),
                "id"        => "tab-codes",
                "current"    => true,
            ];
        }
Thank you. I also use this function.
 
If there is an option to select the default tab or change the order will be better, modify it every new update is boring.
 
Back
Top