Resource icon

Post Content Find / Replace 2.0.1

No permission to download
This add-on is not compatible with XF 2.1.

It worked fine for me on the release version of 2.1.

Did a great job converting old AME BB Codes from vBulletin to media bb codes for XenForo.

I got many of the regex's and instructions to use from this old thread. Do note you need to run them once with http and again with https as you may have a mix of URLs used on your forum. At first I edited the regex to do both http and https at the same time but it proved too much memory for my server. As it was I had to increase my PHP memory limit temporarily by adding this line to the top of the /src/config.php file:

PHP:
ini_set('memory_limit','1024M');

Still have more to convert but it's working, Made the conversion much better!
 
Is there any way to replace quoted posts with username mention?

Just as a simple example:

quoted-post.webp

To:

mentioned.webp

I haven't tried it yet, were there any methods in particular?
 
his looks pretty easy - I want to turn Youtube URLs in posts (from smf upgrade) into embedded Youtube links.

Example;

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

Obviously you just need to extract media id and place in media tags.

I found this regex online which works perfectly in https://regex101.com with my test URLs

Code:
^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*

However PCSR barfs on it:

ErrorException: [E_WARNING] preg_match_all(): Unknown modifier '#' in src/addons/XFPR/Admin/Controller/PostReplace.php at line 41
  1. XF::handlePhpError()
  2. preg_match_all() in src/addons/XFPR/Admin/Controller/PostReplace.php at line 41
  3. XFPR\Admin\Controller\PostReplace->actionReplace() in src/XF/Mvc/Dispatcher.php at line 321
  4. XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 248
  5. XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 100
  6. XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 50
  7. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2177
  8. XF\App->run() in src/XF.php at line 390
  9. XF::runApp() in admin.php at line 13
Any ideas? Might need to run multiple regex with simpler syntax?
 
@Overscan hi, I think this will solve your problem.

Quick Find:
[url=http://www.youtube.com

Regular Expression:
/\[url=http:\/\/(?:www\.)*+youtube\.com\/watch\?v=([\w\-]+)\].+\[\/url\]/siU

Replacement string:
[media=youtube]\1[/media]

@Chris D — #1184317
 
Thanks - that did some.

Most of the URLs are like
Code:
https:://youtube.com/watch?v=_J4IbHZhhh4
without the URL bbcode. I had an SMF plugin which turned these to embedded videos automatically.

I tried modifying the regex to remove the
Code:
[URL=  ] [/URL]
parts without success so far.

Edit - success!

Code:
/https:\/\/(?:www\.)*+youtube\.com\/watch\?v=(.*$)/siU

Oh - I spoke too soon - that works on many posts, but some have stuff after the URL. I need to stop the capture group at first space after the URL I think.
 
Last edited:
Brute force worked:

PHP:
https:\/\/(?:www\.)*+youtube\.com\/watch\?v=(...........)

Assuming media id is always 11 characters....
 
@Overscan well try this;

Quick Find:
https://www.youtube.com

And non-www of the URL...

https://youtube.com

HTTP;

http://www.youtube.com

And non-www of the URL...

http://youtube.com

Regular Expression:
#\[url="([^\]]+)"\](.*)\[/url\]#siU

Replacement string:
[URL="\1"]\1[/URL]

Please note that do not change. Let's just try it and see what happens.
 
I'm trying to replace:

Code:
[MEDIA=amazon]B005DT9U3Q[/MEDIA]

with

Code:
https://www.amazon.com/dp/B005DT9U3Q/

i've been trying:

Code:
#\[MEDIA=amazon"([^\]]+)"\](.*)\[/MEDIA\]#siU

Code:
https://www.amazon.com/dp/\1

but when i put 'amazon' in the quick find, it never finds anything. if i leave it blank (or put something simple like 'a') it takes forever and times out with a 500 error.

can someone help me with this?
 
@electrogypsy hi,

Add the following lines to your config.php

Code:
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 0);

Quick find:
[media

Regular expression:
#\[MEDIA=amazon"([^\]]+)"\](.*)\[/MEDIA\]#siU

Replacement string:
https://www.amazon.com/dp/\1

And yet despite this, do not change. Let's just try it and see what happens.
 
Last edited:
@electrogypsy Sorry it was config.php file inside /src folder. Anyways, I edited my post after you replied.

Quick find:
amazon

Regular expression:
#\[(amazon)=[0-9]{10}]\[/\1]#siu

Replacement string:
https://www.amazon.com/dp/\1
 
@electrogypsy Sorry it was config.php file inside /src folder. Anyways, I edited my post after you replied.

Quick find:
amazon

Regular expression:
#\[(amazon)=[0-9]{10}]\[/\1]#siu

Replacement string:
https://www.amazon.com/dp/\1

thank you for that, but it still doesn't do anything. i'm starting to think maybe this addon just isn't working for me?
 
Hi there.

I want to replace
Code:
https://www.youtube.com/watch?v=12345678
with
Code:
[media=youtube]\1[/media]

What do I have to search for, I mean, what do I have to type in?

Almost forgot: There are also a few
Code:
https://youtu.be/12345678

that need to be changed.
 
Last edited:
I'm getting a PHP memory error when trying to run this on our test forum.

204279

Memory limit 240M, post max size is 50M, PCRE is enabled.
 
I'm getting a PHP memory error when trying to run this on our test forum.

View attachment 204279

Memory limit 240M, post max size is 50M, PCRE is enabled.
config.php ini_set..
 
I got the following error when doing a test run:

ErrorException: [E_WARNING] preg_match_all(): Delimiter must not be alphanumeric or backslash in src/addons/XFPR/Admin/Controller/PostReplace.php at line 41
  1. XF::handlePhpError()
  2. preg_match_all() in src/addons/XFPR/Admin/Controller/PostReplace.php at line 41
  3. XFPR\Admin\Controller\PostReplace->actionReplace() in src/XF/Mvc/Dispatcher.php at line 321
  4. XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 248
  5. XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 100
  6. XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 50
  7. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2177
  8. XF\App->run() in src/XF.php at line 390
  9. XF::runApp() in admin.php at line 13
 
I have removed all attachments from my forum posts as I am planning to use a gallery for pictures. But the attachment tags are still there. I still have thousands of attach tags in my posts similar to this one:
Code:
[ATTACH=full]11529[/ATTACH]
Is there a way to remove them all?
 
I have removed all attachments from my forum posts as I am planning to use a gallery for pictures. But the attachment tags are still there. I still have thousands of attach tags in my posts similar to this one:
Code:
[ATTACH=full]11529[/ATTACH]
Is there a way to remove them all?
I didn't make this addon work, I ended up with writing a php script to do it, It's very easy.
 
Top Bottom