Resource icon

Post Content Find / Replace 2.0.1

No permission to download
I've had to change the URL of my forum so was attempting to use this add-on to fix some broken links. The add-on is left half installed and I am getting server errors completing the installation:

Code:
ErrorException: Fatal Error: Illegal length modifier specified 'f' in s[np]printf call src/XF/Util/File.php:305

Stack trace
#0 [internal function]: XF::handleFatalError()
#1 {main}

Request state
array(4) {
  ["url"] => string(31) "/forums/admin.php?tools/run-job"
  ["referrer"] => string(56) "https://www.topklasse.org/forums/admin.php?tools/run-job"
  ["_GET"] => array(1) {
    ["tools/run-job"] => string(0) ""
  }
  ["_POST"] => array(3) {
    ["_xfRedirect"] => string(17) "/forums/admin.php"
    ["_xfToken"] => string(8) "********"
    ["only_ids"] => string(0) ""
  }
}

when i run it, it shows up as a 500 error but this error is generated too.

I was able to fix it myself - I found this error from the first time Installed it:

Code:
ErrorException: Fatal Error: Illegal length modifier specified 'f' in s[np]printf call src/vendor/league/flysystem/src/Adapter/Local.php:199
Generated by: c107 Apr 23, 2021 at 12:18 AM
Stack trace
#0 [internal function]: XF::handleFatalError()
#1 {main}
Request state
array(4) {
  ["url"] => string(31) "/forums/admin.php?tools/run-job"
  ["referrer"] => string(56) "https://www.topklasse.org/forums/admin.php?tools/run-job"
  ["_GET"] => array(1) {
    ["tools/run-job"] => string(0) ""
  }
  ["_POST"] => array(3) {
    ["_xfRedirect"] => string(122) "https://www.topklasse.org/forums/admin.php?add-ons/XFPR/finalize&t=1619101120%2C3b3eb07ef5e8ef5a3829096e4da04e27&a=install"
    ["_xfToken"] => string(8) "********"
    ["only_ids"] => string(4) "8502"
  }
}

I then ran the url manually in the post command and that fixed it.
 
Got it to run, got this error:
Code:
ErrorException: [E_WARNING] preg_match_all(): Empty regular expression in src/addons/XFPR/Admin/Controller/PostReplace.php at line 41
[LIST=1]
[*]XF::handlePhpError()
[*]preg_match_all() in src/addons/XFPR/Admin/Controller/PostReplace.php at line 41
[*]XFPR\Admin\Controller\PostReplace->actionReplace() in src/XF/Mvc/Dispatcher.php at line 350
[*]XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 261
[*]XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 113
[*]XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 55
[*]XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2326
[*]XF\App->run() in src/XF.php at line 488
[*]XF::runApp() in admin.php at line 13
[/LIST]
I entered the URL I want to replace in the Quick Find field. I entered the new URL in the Replacement String field. I checked the Save Changes box. I clicked Proceed and got the error above. I didn't enter anything in the Regular Expression field. What did I do wrong?
Looking back at the old XF1 instructions I see I need to add the URL I'm trying to replace into the Reg Ex field, and use part of it in the Quick Find field. And then enter the URL I want to replace it with in the Replacement String field. Would anyone be able to help me structure the Reg Ex for the URL I'm trying to replace? Here's what I'm trying to do:

Quick Find: dmtalon.v8eaters
Reg Ex (URL I'm trying to replace): http://dmtalon.v8eaters.com/ISC.html
Replace it with: http://web.archive.org/web/20100815101158/http://dmtalon.v8eaters.com/ISC.html
 
Hello,

I found a little bug maybe:

Missing (not viewing) explain text from existing phrase:
Code:
xfpr_save_changes_explain
under the "Change Save" checkbox.

1628334727408.webp
 
Anyone please advice how to clear all orphaned BBCODE from an old addon?
Post content format:
Rich (BB code):
[CQ=*random*][/CQ]
 
If random is only alphanumeric then like this:

Fast search:
Code:
[CQ=
fast search contains the part that never change at your seach, so the search and replace tool can find very fast these posts that contain the fast search string.

RegEx search:
Code:
#(\[CQ\=)([a-zA-Z0-9]+)(\]\[\/CQ\])#siU
At this sample your random can contain a-z, A-Z and/or 0-9 but nothing others.

replace:
Leave in this case blank to remove all found blocks/groups from your posts.


If random is more as only alphanumeric, then you have to change the regex block/group at the middle like this eg:
Code:
#(\[CQ\=)([0-9a-zA-Z.:,&/]+)(\]\[\/CQ\])#siU
... you can add the things you want to search for at the middle block/group in this case.

If your random can also contain whitespace(s) eg, add a \s in the middle block/group. For backslash(es) use \\ eg.
Sample:
Code:
#(\[CQ\=)([0-9a-zA-Z.:,&/\s\\]+)(\]\[\/CQ\]\s)#siU
Here I also added a \s at the 3. block/group end to find also the whitespace at the end of our search and remove them later to so you dont have after removing a sensless double whitespace in your posts.

Make a test run bevore you hit save and: make a backup just bevore. ;)



Try to test your search and play a litle around at a regex tester like this one to see and understand what you do:
1628587685892.png

1628588396607.png

I use likly this one good an simple: https://www.regextester.com/

You see the 3 blocks/groups we serach for and found and you can test it risk less at many test strings as you want with this regex tester. :)
 
Last edited:
I would greatly appreciate some regex help using this tool! :)

I migrated from a solution that left the youtube links as text only with no bbcode. And some have url/URL bbcode.

So for example they look like this in the post and database:

Code:
https://www.youtube.com/watch?v=xxxxxxxxxxx

https://youtu.be/xxxxxxxxxxx

[URL]https://youtu.be/xxxxxxxxxxx[/URL]

[url]https://www.youtube.com/watch?v=xxxxxxxxxxx[/url]

PLUS some ancient ones with http not https.
Some with www, some not.

Thanks for any help! Trying to get the embedded with MEDIA=youtube][/MEDIA]
 
I think best will be to do this job in two steps. I can post you some hints what you can do with regex later today...
 
OK, I have a solution to made it in one step. :D ;)
But make a backup and try a test-run just before - its your own risk. ;) I made it for your samples above. If you have more samples we can take a second look to test it with more samples at https://www.regextester.com/

Fast search:
Code:
youtu

Regex Code: (both runs)
Code:
#(\shttps?|\s\[url\]https?|\s\[URL\]https?)(:\/\/www\.youtube\.com\/watch\?v=|:\/\/youtu\.be\/)([a-zA-Z0-9-_]+)(\s|\[\/url\]\s|\[\/URL\]\s)#siU

Replacement:
Code:
[MEDIA=youtube]$3[/MEDIA]

Tested in/with Regex Tester (https://www.regextester.com/)
1628694751721.png

What the Regex search and replace above will do:

1. The fast search and find ALL posts with the string "youtu" inside to reduce the posts who our regex code should run in next step.

2. after that the Regex code will run to find matches for the 4 Regex groups Groups ar beginning with a "(" and ending with closing ")".
Betwen the groups there is a logical AND. Like group one AND group2 eg.
Inner the groups stand the "|" for a OR (this|that = this OR that).

group #1
Code:
(\shttps?|\s\[url\]https?|\s\[URL\]https?)
- find " http" OR " https" OR " http" OR " [url]https" OR " [URL]http" OR " [URL]https"
wow, thats a many or, but it work ... but I think that can also be made a little bit shorter - next time :D ;) Take a look at the whitespaces "\s".

group #2
Code:
(:\/\/www\.youtube\.com\/watch\?v=|:\/\/youtu\.be\/)
- AND find "://www.youtube.com/watch?v=" OR "://youtu.be/"

group #3
Code:
([a-zA-Z0-9-_]+)
- AND find the "Video-ID" we need
Here we open a character class with "[" and search for a alpha numeric character that CAN be lower or upper case or a  number or a  "_" or a "-".
The "+" after "]" to closing this little class says that we will search for one or more characters matching our class.

group #4
Code:
(\s|\[\/url\]\s|\[\/URL\]\s)
- AND find a " " (one withespace) OR "[/url] " OR "[/URL] "
to match and mark the end of our regex search.

3. Replace
When we have found ALL 4 groups we pickup us group #3 with the needed video-ID and put them ($3 as placeholder to insert string from group #3) in our new string we wish to insert as replacement for the old ones:
- made a string from a opening ""


Oh, the "#" at beginning and "#siU" at the end is some kind of magic we need to run our regex code. :D ;)

Thats all - when you do it step for step its not so complicated as it looks like. :)
 
Last edited:
Awesome! It did some of them not all. These are the ones it skips:

https://youtu.be/xxxxxxxxxxx
This is how it looks in the post and datbase, there is no bbcode at all, not url, media, none, and it is not a link. It's just text. It did not change this.

https://www.youtube.com/watch?v=xxxxxxxxxxx
I suppose it left this one due to the "watch" code. Also this one is just text, no bbcode.

[media] https://www.youtube.com/watch?v=xxxxxxxxxxx [/media]
So there's a bunch like this, a space after the opening and before the closing bbcode AND lowercase media tags.

[URL="https://www.youtube.com/watch?t=195&v=xxxxxxxxxxx"]https://www.youtube.com/watch?t=195&v=xxxxxxxxxxx[/URL]
Some left like this.

[URL="https://youtu.be/xxxxxxxxxxx"]https://youtu.be/xxxxxxxxxxx[/URL]
And that.

Of course if the links have to stay as links, at least they work! But better embedded if possible.

Thanks for taking the time on these! They can be a real pain!
 
I used a simpler version of the regex before on 5 vB4 migrations.

This one got the cases missed by the simpler one. :)
 
Awesome! It did some of them not all. These are the ones it skips:

https://youtu.be/xxxxxxxxxxx
This is how it looks in the post and datbase, there is no bbcode at all, not url, media, none, and it is not a link. It's just text. It did not change this.

I suppose it left this one due to the "watch" code. Also this one is just text, no bbcode.
sure?
Exakt these strings my regex match at my last screenshot from regex tester above. :unsure:
But no problem I will made some more tests later today at home.
https://www.youtube.com/watch?v=xxxxxxxxxxx

[media] https://www.youtube.com/watch?v=xxxxxxxxxxx [/media]
So there's a bunch like this, a space after the opening and before the closing bbcode AND lowercase media tags.
OK, this version of a youtube inline code you dont have telled me in your first question - to match this, we have to extend the regex, thats clear.

[URL="https://www.youtube.com/watch?t=195&v=xxxxxxxxxxx"]https://www.youtube.com/watch?t=195&v=xxxxxxxxxxx[/URL]
Some left like this.

[URL="https://youtu.be/xxxxxxxxxxx"]https://youtu.be/xxxxxxxxxxx[/URL]
And that.
Same as bevore - youtube link versions you dont tell me I cant made a matching regex for. ;)
But its no problem to extend the regex code or made a extra regex code for. I will take a look later today.

I forgot to mention your code indenting the media code so its own line there is a space before it.
Any screenshots from please? The replacement code doesnt made a new line ... or I dontkknow what you mean at this point. Both possible. :D ;)


We now talk from:
the first one:
Code:
https://www.youtube.com/watch?v=xxxxxxxxxxx
[url]https://www.youtube.com/watch?v=xxxxxxxxxxx[/url]
[URL]https://www.youtube.com/watch?v=xxxxxxxxxxx[/URL]
https://youtu.be/xxxxxxxxxxx
[url]https://youtu.be/xxxxxxxxxxx[/url]
[URL]https://youtu.be/xxxxxxxxxxx[/URL]
And the new ones:
Code:
[URL="https://youtu.be/xxxxxxxxxxx"]https://youtu.be/xxxxxxxxxxx[/URL]
[URL="https://www.youtube.com/watch?t=195&v=xxxxxxxxxxx"]https://www.youtube.com/watch?t=195&v=xxxxxxxxxxx[/URL]
[media] https://www.youtube.com/watch?v=xxxxxxxxxxx [/media]
Are these now all Youtube link variants that we have to find and match with regex? Is this now correct?
 
Last edited:
@Chris D @Mike @Kier
A small suggestion: would be nice if you can add regex as language for the code bbcode hier in the editor so we have highlighted regex code. That make it easier to explain and understand the code. :)
 
As you can see at my first answer above - I search only for matches with a (one) whitespace at beginning and also one whitespace at the end. At my replace there is no extra whitespaces ... or linebrakes. :unsure:

I will make a new test run now with the other links you have posted after I made the first one and then let us see what happens.
 
OK - I only found a code for a three step solution for you.
Its important to run it step by step in exactly the direction!

Step 1 "the longer ones #1"
fast search: youtu

regex search
Code:
#(\[URL\=\"https?|\[url\=\"https?)(:\/\/www\.youtube\.com\/watch\?t=[0-9]+\&v=|:\/\/youtu\.be\/)([0-9a-zA-Z_-]+)(\"\]https?\:\/\/)(www\.youtube\.com\/watch\?t=[0-9]+\&v=|youtu\.be\/)([0-9a-zA-Z_-]+)(\[\/URL\]|\[\/url\])#siU

Match test step 1
1628837134829.png
Replacing test step 1
Code:
[media=youtube]$3[/media]
1628837157539.png

Working for me... next step.


Step 2 "the longer ones #2"
fast search: youtu

Regex search
Code:
#(\[media\]|\[MEDIA\])(\shttps?:\/\/)(www\.youtube\.com\/watch\?v=|youto\.be\/)([0-9a-zA-Z_-]+)(\s\[\/media\]|\s\[\/MEDIA\])#siU

Match test step 2:
1628837715735.png

Replacing test step 2:
Code:
[media=youtube]$4[/media]
1628837785705.png

Working for me ... up to last step #3.

Step 3 "the shorter ones"
fast search: youtu

regex search
Code:
#(https?|\[url\]https?|\[URL\]https?)(:\/\/www\.youtube\.com\/watch\?v=|:\/\/youtu\.be\/)([a-zA-Z0-9-_]+)(\[\/url\]|\[\/URL\]|)#siU

Match test step 3:
1628839962937.png

Replacing test step 3:
Code:
[media=youtube]$3[/media]
1628839999663.png

For me - step one to three AND in exactly this direction (!!) works, no extra linebrakes as I can see here at Regex-Tester tool.

Again:
Use regextester.com to verify my code above with your strings, make a backup and run a test run with search&replace tool bevore you save it at your database!
 
Last edited:
fast search: youto
This should be youtu ;)
OK - I only found a code for a three step solution for you.
Its important to run it step by step in exactly the direction!

Step 1 "the longer ones #1"
fast search: youto

regex search
Code:
#(\[URL\=\"https?|\[url\=\"https?)(:\/\/www\.youtube\.com\/watch\?t=[0-9]+\&v=|:\/\/youtu\.be\/)([0-9a-zA-Z_-]+)(\"\]https?\:\/\/)(www\.youtube\.com\/watch\?t=[0-9]+\&v=|youtu\.be\/)([0-9a-zA-Z_-]+)(\[\/URL\]|\[\/url\])#siU

Match test step 1
View attachment 255967
Replacing test step 1
Code:
[media=youtube]$3[/media]
View attachment 255968

Working for me... next step.


Step 2 "the longer ones #2"
fast search: youto

Regex search
Code:
#(\[media\]|\[MEDIA\])(\shttps?:\/\/)(www\.youtube\.com\/watch\?v=|youto\.be\/)([0-9a-zA-Z_-]+)(\s\[\/media\]|\s\[\/MEDIA\])#siU

Match test step 2:
View attachment 255970

Replacing test step 2:
Code:
[media=youtube]$4[/media]
View attachment 255971

Working for me ... up to last step #3.

Step 3 "the shorter ones"
fast search: youtu

regex search
Code:
#(https?|\[url\]https?|\[URL\]https?)(:\/\/www\.youtube\.com\/watch\?v=|:\/\/youtu\.be\/)([a-zA-Z0-9-_]+)(\[\/url\]|\[\/URL\]|)#siU

Match test step 3:
View attachment 255978

Replacing test step 3:
Code:
[media=youtube]$3[/media]
View attachment 255979

For me - step one to three AND in exactly this direction (!!) works, no extra linebrakes as I can see here at Regex-Tester tool.

Again:
Use regextester.com to verify my code above with your strings, make a backup and run a test run with search&replace tool bevore you save it at your database!

Thanks!

Step 1 and 2 are working.

Something is wrong with step 3. It is returning results with one letter like this:
[MEDIA=youtube]Q[/MEDIA]

Also on the "longer" ones I still have these left:

Code:
https://www.youtube.com/watch?v=xxxxxxxxxxx

Though, I didn't "save" task #3 because the preview had the one letter result.
 
Last edited:
Back
Top Bottom