Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if the resized file exists; if not resize it #32

Open
github-actions bot opened this issue Dec 4, 2024 · 0 comments
Open

Check if the resized file exists; if not resize it #32

github-actions bot opened this issue Dec 4, 2024 · 0 comments
Labels

Comments

@github-actions
Copy link

github-actions bot commented Dec 4, 2024

// TODO Check if the resized file exists; if not resize it

     */
    public static function addConfigToolbar(Toolbar $bar)
    {
        $bar->linkButton('tickets')->text(Text::_('COM_JED_TITLE_TICKETS'))->url('index.php?option=com_jed&view=tickets')->icon('fa fa-ticket-alt');
        $bar->linkButton('vulnerable')->text('Vulnerable Items')->url('index.php?option=com_jed&view=velvulnerableitems')->icon('fa fa-bug');

        $bar->customHtml('        ');


        $configGroup = $bar->dropdownButton('config-group')->text(Text::_('COM_JED_GENERAL_CONFIG_LABEL'))->toggleSplit(false)->icon('fa fa-cog')->buttonClass('btn btn-action')->listCheck(false);

        $configChild = $configGroup->getChildToolbar();

        $configChild->linkButton('emailtemplates')->text('COM_JED_TITLE_MESSAGETEMPLATES')->icon('fa fa-envelope')->url('index.php?option=com_jed&view=messagetemplates');

        $configChild->linkButton('ticketcategories')->text('COM_JED_TITLE_TICKET_CATEGORIES')->icon('fa fa-folder')->url('index.php?option=com_jed&view=ticketcategories');

        $configChild->linkButton('ticketgroups')->text('COM_JED_TITLE_ALLOCATEDGROUPS')->icon('fa fa-user-friends')->url('index.php?option=com_jed&view=ticketallocatedgroups');

        $configChild->linkButton('ticketlinkeditemtypes')->text('COM_JED_TICKETS_LINKED_ITEM_TYPE_LABELS')->icon('fa fa-link')->url('index.php?option=com_jed&view=ticketlinkeditemtypes');

        $configChild->linkButton('extensionsupplyoptions')->text('COM_JED_EXTENSION_SUPPLY_OPTIONS')->icon('fa fa-link')->url('index.php?option=com_jed&view=extensionsupplyoptions');

        $configChild->linkButton('setupdemomenu')->text('COM_JED_TITLE_SETUP_DEMO_MENU')->icon('fa fa-link')->url('index.php?option=com_jed&view=setupdemo');

        /*
         * Only for finally moving live to test
         */
        $configChild->linkButton('copyjed3data')->text('COM_JED_TITLE_COPY_JED3_DATA')->icon('fa fa-link')->url('index.php?option=com_jed&view=copyjed3data');

        $bar->customHtml('        ');

        $debugGroup = $bar->dropdownButton('debug-group')->text('Debug')->toggleSplit(false)->icon('fa fa-cog')->buttonClass('btn btn-action')->listCheck(false);

        $debugChild = $debugGroup->getChildToolbar();

        $debugChild->linkButton('velabandonedreports')->text('VEL Abandoned Reports')->icon('fa fa-link')->url('index.php?option=com_jed&view=velabandonedreports');

        $debugChild->linkButton('velreports')->text('VEL Reports')->icon('fa fa-link')->url('index.php?option=com_jed&view=velreports');

        $debugChild->linkButton('veldeveloperupdates')->text('VEL Developer Updates')->icon('fa fa-link')->url('index.php?option=com_jed&view=veldeveloperupdates');

        $debugChild->linkButton('velvulnerableitems')->text('VEL Vulnerable Items')->icon('fa fa-link')->url('index.php?option=com_jed&view=velvulnerableitems');
        $debugChild->linkButton('ticketmessages')->text('Ticket Messages')->icon('fa fa-link')->url('index.php?option=com_jed&view=ticketmessages');

        $debugChild->linkButton('ticketinternalnotes')->text('Ticket Internal Notes')->icon('fa fa-link')->url('index.php?option=com_jed&view=ticketinternalnotes');

        $debugChild->linkButton('tickets')->text('JED Tickets')->icon('fa fa-link')->url('index.php?option=com_jed&view=tickets');
        $debugChild->linkButton('extensions')->text('Extensions')->icon('fa fa-link')->url('index.php?option=com_jed&view=extensions');
    }

    /**
     * Function to format JED Extension Images
     *
     * @param   string  $filename  The image filename
     * @param   string  $size      Size of image, small|large
     *
     * @return string  Full image url
     *
     * @since 4.0.0
     */
    public static function formatImage(string $filename, ImageSize $size = ImageSize::SMALL): string
    {
        if (!$filename) {
            return '';
        }

        if (str_starts_with($filename, 'http://') || str_starts_with($filename, 'https://')) {
            return $filename;
        }

        $params = ComponentHelper::getParams('com_jed');
        $cdnUrl = rtrim($params->get('cdn_url', 'https://extensionscdn.joomla.org'), '/');

        $lastDot      = strrpos($filename, '.');
        $partialName  = substr($filename, 0, $lastDot - 1);
        $extension    = substr($filename, $lastDot);
        $bestFilename = match ($size) {
            ImageSize::ORIGINAL => $filename,
            ImageSize::SMALL    => $partialName . '_small' . $extension,
            ImageSize::LARGE    => $partialName . '_large' . $extension,
        };

        // TODO Check if the resized file exists; if not resize it

        // TODO If the file cannot be resized AND I am configured to use a CDN, fall back to the legacy CDN URLs
        if (false && $params->get('use_cdn', 0)) {
            $bestFilename = match ($size) {
                ImageSize::ORIGINAL => $filename,
                ImageSize::SMALL    => $partialName . '_resizeDown400px175px16' . $extension,
                ImageSize::LARGE    => $partialName . '_resizeDown1200px525px16' . $extension,
            };

            return $cdnUrl . '/cache/fab_image/' . $bestFilename;
        }

        // If I am configured to use a CDN, use the https://extensionscdn.joomla.org CDN
        if ($params->get('use_cdn', 0)) {
            return $cdnUrl . '/cache/' . $bestFilename;
        }

        // No CDN (e.g. local development). Where should I get my image from?
        if (File::exists(JPATH_ROOT . '/' . ltrim($bestFilename, '/\\'))) {
            return Uri::root() . ltrim($bestFilename, '/\\');
        }

        if (File::exists(JPATH_ROOT . '/' . ltrim($filename, '/\\'))) {
            return Uri::root() . ltrim($filename, '/\\');
        }

        if (File::exists(JPATH_ROOT . '/media/com_jed/cache/' . ltrim($bestFilename, '/\\'))) {
            return Uri::root() . 'media/com_jed/' . ltrim($bestFilename, '/\\');
        }

        if (File::exists(JPATH_ROOT . '/media/com_jed/cache/' . ltrim($filename, '/\\'))) {
            return Uri::root() . 'media/com_jed/' . ltrim($filename, '/\\');
        }

        return '';
    }

    /**
@github-actions github-actions bot added the todo label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants