Skip to content

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

@github-actions

Description

@github-actions

// 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 '';
    }

    /**

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions