You need to be logged in to post in the forum - Log In

An active JCE Pro Subscription is required to post in the forum - Buy a Subscription

Support is currently Offline

Official support hours
Monday to Friday
09:00 - 17:00 Europe/London (BST)

Please create a new Ticket and we will get back to you as soon as we can.

#116032 image manager extended: folder creation with custom prefix

Posted in ‘Suggestions & Feature Requests’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Latest post by gotyou on Wednesday, 07 February 2024 08:30 GMT

gotyou
Hello Ryan!
We have many users on many different sites, but all struggle with the same problem (not the "best users" you may think. correct! 😃 ) Maybe a new feature / setting could help out?

Using the image manager extended over the months many image folders are created (and many images are uploaded). We educate our users to use a specific prefix to keep order and be able to find folders quickly: YYMMDD_nameofthearticlethefolderisfor. This way everyone can easily understand what data belongs to what content item. Plus everything is stored chronologically and the sorting works "out of the box".

Guess what, that works only for a short time and after that very short time everyone has forgotten about it. The obvious result are crammed folders with almost no logical order.

It would be great if the image manager extended could add that prefix automatically. So the user would only enter the folder name like nameofthearticlethefolderisfor, but would get a correct YYMMDD_nameofthearticlethefolderisfor

Even better if this setting would be flexible to add the prefix using only specific profiles and / or if a subfolder is created inside a defined folder.
Like: add the prefix automatically inside images/data/imgs but not inside images/data/vids.
On top: maybe it could be implemented that the general JCE file manager works the same way.

Well, ideas, ideas....

Thanks for your attention, and
Best regards!
Chris

Ryan
It would be great if the image manager extended could add that prefix automatically. So the user would only enter the folder name like nameofthearticlethefolderisfor, but would get a correct YYMMDD_nameofthearticlethefolderisfor


This is an interesting idea and I will look into it. Could be applied to uploaded images too.

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

Ryan
It would be great if the image manager extended could add that prefix automatically. So the user would only enter the folder name like nameofthearticlethefolderisfor, but would get a correct YYMMDD_nameofthearticlethefolderisfor Even better if this setting would be flexible to add the prefix using only specific profiles and / or if a subfolder is created inside a defined folder. Like: add the prefix automatically inside images/data/imgs but not inside images/data/vids. On top: maybe it could be implemented that the general JCE file manager works the same way.
If you don't mind getting your hands dirty with a bit of PHP you can use the JCE Filesystem Events to rename the folder after it has been created, based on your conditions. Download and install this Joomla System Plugin - https://github.com/widgetfactory/wf_filesystem_events Then edit the plugins/system/wf_filesystem_events/wf_filesystem_events.php file to add your code in the appropriate event. In your case for example:

public function onWfFileSystemCreateFolder($path, $state)
{
    // Validate the state parameter to ensure the folder creation was successful
    if ($state !== true) {
        return;
    }

    $parent = dirname($path);
    $targetDirectory = JPATH_SITE . '/images/data/imgs';

    // Proceed only if the folder is a direct child of the target directory
    if ($parent === $targetDirectory) {
        $name = basename($path);
        $date = date('Y-m-d'); // Get the current date
        $newName = $date . '_' . $name; // Append the date to the folder name

        // Attempt to rename the folder
       Joomla\CMS\Filesystem\Folder::move($path, $parent . '/' . $newName);
    }
}

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

gotyou
Thanks a lot for providing this example. It'll take some time until I'll have a detailed look on this. Just two things to mention / ask: [list] [*]We change the basic folder each year, like

$targetDirectory = JPATH_SITE . '/images/data/imgs/2024';
So only changing the file each year would just get us a new setting. Right? [*]Second question is of course related: do I have to care about JCE updates changing things? [/list] Thanks a lot [Edit:] Thinking about my notes / questions I realized they're unnecessary. The answers are YES and NO..