Jump to content

Custom Upload Names


adrian

Recommended Posts

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
Link to comment
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
Link to comment
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
Link to comment
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.

Link to comment
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

Link to comment
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.

Link to comment
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,

Link to comment
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?

 

Link to comment
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));

 

Link to comment
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.

Link to comment
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"));

 

Link to comment
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

Link to comment
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).

Link to comment
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

Link to comment
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
×
×
  • Create New...