adrian

Custom Upload Names

Recommended Posts

I test it on a new page and getting the same problem. Having "Rename on Save" unchecked everything seems to be ok.

Are you sure that it's working for you with multiple repeater items and with "Rename on Save" checked?

  • Like 2

Share this post


Link to post
Share on other sites
1 hour ago, PWaddict said:

Are you sure that it's working for you with multiple repeater items

That seems to be the issue - it seems one of my recent attempts to clean things up broke this part. I'll try to get it fixed soon. 

Thanks for all your testing of this module - it hasn't had any love for a long time and I have never actually used it with repeaters so it certainly needs it 🙂

  • Like 1

Share this post


Link to post
Share on other sites

Just a note here to say that repeater support is now fixed. A big thanks to @PWaddict for help testing these changes.

  • Like 3

Share this post


Link to post
Share on other sites

Can you completely remove the HTML entities? For example if on the text field I write: "Test" then the file will be renamed to: quot-test-quot.jpg instead of test.jpg.

  • Like 1

Share this post


Link to post
Share on other sites
36 minutes ago, PWaddict said:

Can you completely remove the HTML entities? For example if on the text field I write: "Test" then the file will be renamed to: quot-test-quot.jpg instead of test.jpg.

Yep, good catch - please try the latest version.

  • Thanks 1

Share this post


Link to post
Share on other sites

@PWaddict - I just committed another update which makes use of PW's core cleanBasename method for generating the final filename. I think this should be an improvement in certain situations. Please let me know if you have any problems with it.

Share this post


Link to post
Share on other sites
2 hours ago, adrian said:

@PWaddict - I just committed another update which makes use of PW's core cleanBasename method for generating the final filename. I think this should be an improvement in certain situations. Please let me know if you have any problems with it.

It ignores the "Character replacements" from the InputfieldPageName module and on repeaters it replaces "Character replacements" and HTML entities with underscores. Please remove that update. The 1.2.2 version does the job perfect.

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, PWaddict said:

It ignores the "Character replacements" from the InputfieldPageName module and on repeaters it replaces "Character replacements" and HTML entities with underscores. Please remove that update. The 1.2.2 version does the job perfect.

Thanks for noticing that - I have reverted that change and bumped the version number to 1.2.4 to make sure anyone who upgraded to 1.2.3 sees that there has been an update.

Share this post


Link to post
Share on other sites

Actually, I messed up that reversal, but I decided to investigate the issue you're having with 1.2.3 and I can't reproduce. This is what happens for me in a repeater - note that the ä is replaced with an "a" as expected. I don't think it should matter, but what version of PW are you running?

image.png.9acb3dc815cb30f0d95ba61685e05207.png

Share this post


Link to post
Share on other sites

@PWaddict - I know you'd like me to just revert to that previous version but I would like to figure out why it seems to be working ok for me and not you. Can you please post your settings for the rename rule and an example of a field value that is causing htmlentities to be replaced with underscores.

Share this post


Link to post
Share on other sites
1 hour ago, adrian said:

@PWaddict - I know you'd like me to just revert to that previous version but I would like to figure out why it seems to be working ok for me and not you. Can you please post your settings for the rename rule and an example of a field value that is causing htmlentities to be replaced with underscores.

On the regular field I'm using {$page->title}_{$file->mtime} + "Rename on Save".
On the repeater field I'm using {$filePage->my_text_field}_{$file->mtime} + "Rename on Save".

On the field value I tested with various combinations like: "Test щ" or "Test ä" but doesn't matter cause none of them are working,

Share this post


Link to post
Share on other sites
32 minutes ago, PWaddict said:

On the regular field I'm using {$page->title}_{$file->mtime} + "Rename on Save".
On the repeater field I'm using {$filePage->my_text_field}_{$file->mtime} + "Rename on Save".

On the field value I tested with various combinations like: "Test щ" or "Test ä" but doesn't matter cause none of them are working,

Weird, that filename format patter for me returns: test_a_1545255464.jpg which should be exactly what we expect - correct?

 

Share this post


Link to post
Share on other sites
21 minutes ago, adrian said:

Weird, that filename format patter for me returns: test_a_1545255464.jpg which should be exactly what we expect - correct?

yep

Share this post


Link to post
Share on other sites

This is interesting:

image.png.b757dacd27cbe0f32933444800b2ac05.png

Are you seeing the first, rather than the second result?

See the last commit where those booleans are passed to the cleanBasename() method: https://github.com/adrianbj/CustomUploadNames/commit/9428a18c4cf67a40c7ef6bd6b63ae600a28086e3

Could you please check that the version you are using has those lines and also please test that code in the Tracy console:

$pageFiles = new Pagefiles($page);

d($pageFiles->cleanBasename('"Test ä".png'));
d($pageFiles->cleanBasename('"Test ä".png', false, true, true));

 

Share this post


Link to post
Share on other sites
14 minutes ago, adrian said:

Could you please check that the version you are using has those lines

Yep I have the 1.2.4 and it has those lines.

 

15 minutes ago, adrian said:

please test that code in the Tracy console

Here are the results:

tracy.jpg.59645d49f289bab8aae44b060c5128c7.jpg

Share this post


Link to post
Share on other sites

@PWaddict - thanks for checking that code in the Console, but it looks the same as what I am seeing, so I can't figure out why you're getting a different result returned from the module. 

Not sure where to go from here other than asking you to test on another PW install.

Share this post


Link to post
Share on other sites
2 minutes ago, adrian said:

it looks the same as what I am seeing

It's not the same. On the 2nd command the result for you is test_a.png and for me test.png.

  • Like 1

Share this post


Link to post
Share on other sites
10 minutes ago, PWaddict said:

It's not the same. On the 2nd command the result for you is test_a.png and for me test.png.

Sorry I didn't catch that 🙂

So for some reason your install is behaving differently. I think I have narrowed it down to multibyte support or iconv. Could you please run these in the console and let me know what you get:

d(function_exists("mb_internal_encoding"));
d(function_exists("\\iconv"));

 

Share this post


Link to post
Share on other sites

Thanks, although not what I was hoping for 🙂

I don't know how to debug this without being able to access your system. I am pretty sure it's in $sanitizer->nameFilter() which is called by many other methods. Have you manually edited the PageName character replacements? It seems that if I remove the needed ones from that and I disable iconv, then I can get the same result you are getting. 

Would you be up for trying to dig into that nameFilter method and see where it's failing for you? I think it's somewhere in this block: https://github.com/processwire/processwire/blob/a0570bb2a0919ddc38487f1adbb190f9f9ab90f2/wire/core/Sanitizer.php#L171-L186

Share this post


Link to post
Share on other sites
2 hours ago, adrian said:

 


$pageFiles = new Pagefiles($page);

d($pageFiles->cleanBasename('"Test ä".png'));
d($pageFiles->cleanBasename('"Test ä".png', false, true, true));

I've installed TracyDebugger on live server and the results from the above code are the same as yours. The problem is happening only on localhost (XAMPP).

Share this post


Link to post
Share on other sites
27 minutes ago, adrian said:

Have you manually edited the PageName character replacements?

No.

 

27 minutes ago, adrian said:

Would you be up for trying to dig into that nameFilter method and see where it's failing for you?

I'm not sure how to test it.

Share this post


Link to post
Share on other sites

Could be the problem caused by Windows? I have the same installation on localhost (Windows) and on live server (Linux). Have you tried on localhost (Windows)?

Share this post


Link to post
Share on other sites
11 minutes ago, PWaddict said:

Have you tried on localhost (Windows)?

I don't have access to a Windows machine dev environment at the moment. It might be related I suppose. I would have thought this issue would have come up before though because the cleanBasename method is what PW uses when uploading images, which is the reason I'd like to stay with this approach if I can, rather than the old pageName I was using before. 

In terms of how you could debug this, in that block of code I linked to, I'd want to know that mb_strpos, mb_eregi_replace and iconv calls are returning the same values on the Windows box that they are on linux. 

I would try this:

        if($beautify && $needsWork) {
            if($beautify === self::translate && $this->multibyteSupport) {
                $value = mb_strtolower($value);

                if(empty($replacements)) {
                    $configData = $this->wire('modules')->getModuleConfigData('InputfieldPageName');
                    $replacements = empty($configData['replacements']) ? InputfieldPageName::$defaultReplacements : $configData['replacements'];
                }

                foreach($replacements as $from => $to) {
                    if(mb_strpos($value, $from) !== false) {
                        bd($from .' => ' . $to, $value);
                        $value = mb_eregi_replace($from, $to, $value);
                        bd($value);
                    }
                }
            }

            if(function_exists("\\iconv")) {
                $v = iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", $value);
                if($v) {
                    bd($value, 'ICONV');
                    $value = $v;
                }
            }
            $needsWork = strlen(str_replace($allowed, '', $value));
        }

which should result in something like this which shows the replacement ä => a that is being made and with the final filename and whether the iconv call changes it further or not.

image.png.e67c79e3ac49e14ded885b4d55a57da4.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Anssi
      A simple module to enable easy navigation between the public and the admin side of the site. After installation a green bar will appear to the upper side of the screen, containing a few navigation elements and displaying the PW version number.
      Heavily inspired by @apeisa's great AdminBar (Thanks!). I needed a bit simpler tool for my projects and as a result, this was made. Available on GitHub .

    • By Sebi
      I've created a small module which lets you define a timestamp after which a page should be accessible. In addition you can define a timestamp when the release should end and the page should not be accessable any more.
      Github: https://github.com/Sebiworld/PageAccessReleasetime
      Usage
      PageAccessReleasetime can be installed like every other module in ProcessWire. Check the following guide for detailed information: How-To Install or Uninstall Modules
      After that, you will find checkboxes for activating the releasetime-fields at the settings-tab of each page. You don't need to add the fields to your templates manually.
      Check e.g. the checkbox "Activate Releasetime from?" and fill in a date in the future. The page will not be accessable for your users until the given date is reached.
      If you have $config->pagefileSecure = true, the module will protect files of unreleased pages as well.
      How it works
      This module hooks into Page::viewable to prevent users to access unreleased pages:
      public function hookPageViewable($event) { $page = $event->object; $viewable = $event->return; if($viewable){ // If the page would be viewable, additionally check Releasetime and User-Permission $viewable = $this->canUserSee($page); } $event->return = $viewable; } To prevent access to the files of unreleased pages, we hook into Page::isPublic and ProcessPageView::sendFile.
      public function hookPageIsPublic($e) { $page = $e->object; if($e->return && $this->isReleaseTimeSet($page)) { $e->return = false; } } The site/assets/files/ directory of pages, which isPublic() returns false, will get a '-' as prefix. This indicates ProcessWire (with activated $config->pagefileSecure) to check the file's permissions via PHP before delivering it to the client.
      The check wether a not-public file should be accessable happens in ProcessPageView::sendFile. We throw an 404 Exception if the current user must not see the file.
      public function hookProcessPageViewSendFile($e) { $page = $e->arguments[0]; if(!$this->canUserSee($page)) { throw new Wire404Exception('File not found'); } } Additionally we hook into ProcessPageEdit::buildForm to add the PageAccessReleasetime fields to each page and move them to the settings tab.
      Limitations
      In the current version, releasetime-protected pages will appear in wire('pages')->find() queries. If you want to display a list of pages, where pages could be releasetime-protected, you should double-check with $page->viewable() wether the page can be accessed. $page->viewable() returns false, if the page is not released yet.
      If you have an idea how unreleased pages can be filtered out of ProcessWire selector queries, feel free to write an issue, comment or make a pull request!
    • By David Karich
      Thanks to the great Pro module "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use this module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      With this proof of concept I have created a module which adds the feature to copy a repeater item to the clipboard so that you can paste this item to another page with the same repeater field. The module has been developed very rudimentarily so far. It is currently not possible to copy nested items. There is also no check of Min/Max. You can also only copy items that have the same field on different pages. And surely you can solve all this more elegantly with AJAX. But personally I lack the deeper understanding of the repeaters. Also missing on the Javascript side are event triggers for the repeaters, which would make it easier. Like e.g. RepeaterItemInitReady or similar.
      it would be great if @ryan would implement this functionality in the core of RepeaterMatrix. I think he has better ways to implement this. Or what do you think, Ryan?
      Everybody is welcome to work on this module and improve it, if it should not be integrated into the matrix core. Therefore I put it for testing and as download on GitHub: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDublicate
      You can best see the functionality in the screencast: 
       
    • By anderson
      Hi,
      Please take a look at this:
      https://templatemag.com/demo/Good/
      The upper nav bar, including dropdowns like "pages" and "portfolios", what do you call this whole thing? At first I guess it's called "dropdown nav bar", but seems not.
      AND of course, what's the simplest way/module to achieve this in PW?
      Thanks in advance.
    • By Sebi2020
      Hey, I'm new and I created a simple module for tagging pages because I didn't found a module for it (sadly this is not a core feature). This module is licensed under the GPL3 and cames with absolutly no warranty at all. You should test the module before using it in production environments. Currently it's an alpha release. if you like the module or have ideas for improvements feel free to post a comment. Currently this fieldtype is only compatible with the Inputfield I've created to because I haven't found  an Inputfield yet, that returns arrays from a single html input.
      Greetings Sebi2020
      FieldtypeTags.zip.asc
      InputfieldTagify.zip
      InputfieldTagify.zip.asc
      FieldtypeTags.zip