WordPress.org

Ready to get started?Download WordPress

Forums

WordPress File Monitor Plus
[resolved] Ignore File Patterns (21 posts)

  1. mistaecko
    Member
    Posted 2 years ago #

    I don't think it is currently possible to ignore/exclude file patterns. It would be really nice though!
    E.g. look at the latest timthumb version. It uses .txt files for cached files. I would like to ignore those but still be able to see changes to any other file in the cache directory.

    Personally, I'd be thrilled to see an additional filter that uses regex and works on the full path of the file. This would allow for maximum flexibility while not generating any problems for backwards compatibility!

    Another option is to allow for simple wildcard patterns, e.g.

    path/to/directory/*.txt
    themes/*/cache/*.txt

    (Internally I would still translate this to regular expressions though).

    :)

    mistaecko

    http://wordpress.org/extend/plugins/wordpress-file-monitor-plus/

  2. Scott Cariss
    Member
    Plugin Author

    Posted 2 years ago #

    Hi mistaecko,

    I've been looking into this in the past but what has stopped me doing this that regular expressions in programming is my weak spot. I really struggle to understand them so it's always put me off attempting this feature.

    What I'm thinking though as a half way point is an input box that lets you enter your own regular expressions. So to use it you would have to be a bit of an expert. Not as easy using wildcards unfortunately.

  3. mistaecko
    Member
    Posted 2 years ago #

    Yeah, I totally understand. Regular Expressions are a beast! ;)

    I am not so sure that there would be a lot of people using this feature anyway.

    What would really be nice is the wildcard support I guess.

    I wonder whether it would make sense to enable simple wildcard support (*) on the individual fields. This could be done by using regex internally.

    You don't really need to understand the detailed syntax of regular expressions to use them to implement wildcard support.
    The concept is as follows:
    1. Take the user input and run it through preg_quote - this will put a backslash in front of every character that is part of the regex syntax
    $input = preg_quote($input);

    2. Then use str_replace to turn all wildcards into the correct regex syntax - the wildcard * should match any character, which in regex syntax is .* (dot means any character, and asterix means 0 or more times). We have to consider that in step 1. all asterix wildcards have been prefixed with a backslash
    $input = str_replace("\\*", ".*", $input);

    3. Then add a ^ at the beginning and a $ at the end. These are the regex markers for line beginning and line ending.

    I am still reflecting on whether there are better solutions. I had a look around (google) to see if there are any PHP projects or libs out there which have implemented something similar. Sometimes it's better not to reinvent the wheel. But haven't found anything convincing yet.

    mistaecko

  4. mistaecko
    Member
    Posted 2 years ago #

    And, of course, you would then have to match your string (filename, dir name, absolute dir or file path) against each pattern with
    if (preg_match("/$pattern/i", $nameOrPath))
    The slashes are part of the regex definition, the i is a 'switch' that makes the pattern case insensitive. preg_match will return the number of matches or 0 in case of no match. Since we added line beginning and line ending markers there can only be 1 match or none at all, but all int values greater than 0 will evaluate to TRUE anyway.

  5. Scott Cariss
    Member
    Plugin Author

    Posted 2 years ago #

    I'm thinking using http://uk3.php.net/fnmatch would be better to match when using wildcards *

    What do you think?

  6. mistaecko
    Member
    Posted 2 years ago #

    You are probably right!

    Starting from PHP 5.3 this should work on Windows as well.

    I didn't really get the meaning of the parameters by reading the PHP docs. Found a better explanation of FNM_PATHNAME here.

    If the FNM_ PATHNAME flag is set in the Flags parameter, a / (slash) in the String parameter is explicitly matched by a / in the Pattern parameter. It is not matched by either the * (asterisk) or ? (question-mark) special characters, nor by a bracket expression. If the FNM_PATHNAME flag is not set, the / is treated as an ordinary character.

    If I understand correctly, the difference is this:

    FNM_PATHNAME=1  /abc/def/file.txt does *not* match /abc/*.txt
    FNM_PATHNAME=0 /abc/def/file.txt *does* match /abc/*.txt

    I would rather expect FNM_PATHNAME=1 behavior. However, the turning it off (=0) could be more powerful. One could do something like /blbla/cache/*.txt and this would ignore all text files in all subdirs of the /blbla/cache directory.

    Or maybe even */cache/*.txt

    What do you think?

  7. Scott Cariss
    Member
    Plugin Author

    Posted 2 years ago #

    Well if you follow the comments on the PHP page you can see people have provided alternatives for windows support that fall back to preg_match().

    I havent looked into fnmatch much yet as I'm very busy at work atm. Not going to be free really till the new year to try this out. Might get a go on xmas day when there is nothing on the television.

  8. Scott Cariss
    Member
    Plugin Author

    Posted 2 years ago #

    Now supported in version 1.4

  9. o6asan
    Member
    Posted 2 years ago #

    Hi Scott,

    I upgraded to v.1.4.

    But the feature doesn't work.
    When I upgraded, my setting automatically changed the new format.
    For example,
    Exact Dirs To Ignore E:\WWWROOT\wp-content\blogs.dir\3\files
    ====>> Dirs/Files To Ignore E:\WWWROOT\wp-content\blogs.dir\3\files\*

    But the plugin does not ignore the directory.
    What's wrong? Do I need something else?

  10. Scott Cariss
    Member
    Plugin Author

    Posted 2 years ago #

    Hi o6asan,

    Please try version 1.4.1

  11. o6asan
    Member
    Posted 2 years ago #

    Hi Scott,

    Now I update to version 1.4.1 and it works very well.

    Thanks so much for your quick job.

    By the way, I'll send a new language zip.

  12. Scott Cariss
    Member
    Plugin Author

    Posted 2 years ago #

    Good stuff.

  13. Jpsy
    Member
    Posted 2 years ago #

    Hi Scott,

    ignoring one folder is working fine for me. But I cannot get multiple folders to work. I tried separating them by lines and by lines plus colons.
    Could you give a hint how to do it right?

    MANY THANKS for a great plugin that really adds to WP security!

    Cheers, Jörg.

  14. Scott Cariss
    Member
    Plugin Author

    Posted 2 years ago #

    Simply putting entries on a new line should work.

    What are your exact ignore settings. Maybe from that I can tell you where you are going wrong.

  15. Jpsy
    Member
    Posted 2 years ago #

    Hi Scott,

    I tried several approaches:

    Multiple lines

    /my/absolute/vhost/path/wp-content/themes/mytheme/cache/*
    /my/absolute/vhost/path/backwpup-abc12/*

    Multiple lines, comma separated

    /my/absolute/vhost/path/wp-content/themes/mytheme/cache/*,
    /my/absolute/vhost/path/backwpup-abc12/*

    Single line, comma separated

    /my/absolute/vhost/path/wp-content/themes/mytheme/cache/*,/my/absolute/vhost/path/backwpup-abc12/*

    ... and all of the comma versions with semicolon instead of comma.

  16. Scott Cariss
    Member
    Plugin Author

    Posted 2 years ago #

    /my/absolute/vhost/path/wp-content/themes/mytheme/cache/*
    /my/absolute/vhost/path/_backwpup-abc12/*

    ^^ that one should work fine....

  17. Scott Cariss
    Member
    Plugin Author

    Posted 2 years ago #

    Can you possibly try:

    /my/absolute/vhost/path/wp-content/themes/mytheme/cache*
    /my/absolute/vhost/path/_backwpup-abc12*
  18. Jpsy
    Member
    Posted 2 years ago #

    Yepp, will try both versions.

  19. Jpsy
    Member
    Posted 2 years ago #

    Hi Scott,
    damn, it looks like they are working both flawlessly now. No idea what I did wrong the first time. I could swear that I tried the first of your two versions (lines ending in /*, no separation characters) even multiple times with no luck.
    Anyway, thanks for your help!
    Cheers, Jörg.

  20. Scott Cariss
    Member
    Plugin Author

    Posted 2 years ago #

    No Worries.

    Possibly a rouge space at the start or end of the line perhaps?

  21. Jpsy
    Member
    Posted 2 years ago #

    Very well possible.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic