Resource icon

Post Content Find / Replace 1.0.0

No permission to download
Thanks for the awesome addon, it helped me alot, but maybe you could help me with one last regex:

I'm converting from burning board via mybb and since burning board uses html for quotes, i have some issues.

The current regex works for 95% of the quotes:
Code:
/\<woltlab-quote data-author=\"(.*)\"\s.*\?postID=(\d*).*\">(.*)<\/woltlab-quote>/sim

The problem howerver is that 'date-author' and 'postId?=' are in a switched position in some cases and that breaks those quotes since the regex matches it directly.

Heres is a working example:
https://regex101.com/r/48RvUQ/1

So sometimes date-author is in the place of data-link and that causes a issue. i'd like to have a regex that does the same thing as the one above, but for both cases....
 
Hi,
I test this addon my regular expression is correct, but I have an error

https://regex101.com/r/Olxz22/1

Code:
ErrorException: [E_WARNING] preg_match_all(): Delimiter must not be alphanumeric or backslash in src/addons/XFPR/Admin/Controller/PostReplace.php at line 41
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 249
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 89
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1879
XF\App->run() in src/XF.php at line 328
XF::runApp() in admin.php at line 13
 
Solved with delimiter : #\[sketchfab\]https*?:\/\/sketchfab.com\/models\/(.*)\[\/sketchfab\]#

But i have new error :

Code:
InvalidArgumentException: Attempted to convert NULL to string/binary [content_title] in src/XF/Mvc/Entity/Entity.php at line 685
XF\Mvc\Entity\Entity->_castValueToType() in src/XF/Mvc/Entity/Entity.php at line 572
XF\Mvc\Entity\Entity->set() in src/XF/Mvc/Entity/Entity.php at line 502
XF\Mvc\Entity\Entity->__set() in src/XF/ModeratorLog/Post.php at line 60
XF\ModeratorLog\Post->setupLogEntityContent() in src/XF/ModeratorLog/AbstractHandler.php at line 67
XF\ModeratorLog\AbstractHandler->log() in src/XF/ModeratorLog/AbstractHandler.php at line 47
XF\ModeratorLog\AbstractHandler->logChange() in src/XF/ModeratorLog/Logger.php at line 62
XF\ModeratorLog\Logger->logChanges() in src/XF/Logger.php at line 47
XF\Logger->logModeratorChanges() in src/XF/Entity/Post.php at line 502
XF\Entity\Post->_postSave() in src/XF/Mvc/Entity/Entity.php at line 1137
XF\Mvc\Entity\Entity->save() in src/XF/Service/Post/Editor.php at line 165
XF\Service\Post\Editor->_save() in src/XF/Service/ValidateAndSavableTrait.php at line 40
XF\Service\Post\Editor->save() in src/addons/XFPR/Admin/Controller/PostReplace.php at line 59
XFPR\Admin\Controller\PostReplace->actionReplace() in src/XF/Mvc/Dispatcher.php at line 249
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 89
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1879
XF\App->run() in src/XF.php at line 328
XF::runApp() in admin.php at line 13
 
Has anyone figured out how to properly replace <br> and <br /> with this? I'm cleaning up old html and this was mentioned as problematic in this thread but no solution posted.
 
For anyone having problems matching strings that span multiple lines, you need to use the s switch on your regex to allow this to work.

For example, a reflex to find the following:

Rich (BB code):
[quote]
[B]Originally posted by Someone[/B]

Would look like this:

Code:
/\[quote\]\s*\[b\]originally posted by (.+)\[/b\]/siU
Note that I’m using a case-insentitive (i), multi-line (s) regex that is also ungreedy (U), so it will stop matching at the first [/b] that it comes across.[/quote]
 
Oh man @Kier that is a huge help, I only wish I knew that when I was performing my DNN > XF conversion so I didnt' have to dump everything to an excel spreadsheet and do it all manually (sort of....used DigDB)

I can still find a use for this though I think, great hint
 
Not quite... instead of a line break I get text "\n" inserted in posts.
Tested on local and it works.

Don't forget to backup the table first for safety reason ;)
Or you may test on test forum installation first.
Code:
UPDATE xf_post
SET message = REPLACE(message, '<br>', '\n');

UPDATE xf_post
SET message = REPLACE(message, '<br/>', '\n');

UPDATE xf_post
SET message = REPLACE(message, '<br />', '\n');
 
Thanks but if possible I'd rather do this via the addon as it's a lot safer since that way I can narrow it down and test beforehand as well. I'm not really comfortable running any such queries without prior testing and I don't have a test install available right now.
 
I've made over 50.000 replacements of pretty much anything you can think of in the last couple of weeks and cleaned up nearly 20 years worth of posts, which had everything from smilies, html to various importing issues and broken tags. Literally the only thing that I've found no way whatsoever to replace with this addon are <br> tags.

Given how incredibly useful this tool is, is there any chance that you could add support for replacing line breaks to it as well, @Kier ? Everyone cleaning up html that XF doesn't allow (=converting it to bbCode) will come across this issue and I've come to rely on PCFR for doing safe replacements, since the quick find field enables me to narrow it down as much as I like, performing test replacements on only a single or a handful of posts before doing a major mass replace. It really is the only relatively safe way to do replacements on a large scale.
 
Back
Top Bottom