Resource icon

Post Content Find / Replace 2.0.1

No permission to download
How do I replace triple line breaks, with double line breaks? Replace:
HTML:
<br />
<br />
<br />
(may include whitespace inbetween)
With:
HTML:
<br />
<br />
 
To clarify, are you looking to take XF originating content that contains three line breaks and convert them to only two?

We don't actually store <br /> in our post content so trying to find <br /> and replace it won't have any effect.

I strongly suspect also that even if you matched the new line character \n that you may struggle to actually replace it with anything. We don't have any special handling for that so if you tried to replace \n\n\n with \n\n I think it will literally insert the string \n\n into the post rather than two line breaks.

On the whole, not sure it's something I'd recommend doing. At least not with this add-on.
 
Yes, I am looking to replace XF post content that contains 3 line breaks with 3.
I was hoping that something similar to this would work:
Code:
/\n\s*\n/g, '\n'
Thank you for the advice. It seems like a bad idea.
 
Not a bad idea necessarily. It just wouldn't really work with this add-on.

As a side note, you might be able to do this natively with MySQL 8.0+.

SQL:
UPDATE xf_post SET message = REGEXP_REPLACE(message, "\n{3}", "\n\n") WHERE message REGEXP "\n{3}";

This worked for me in quite literally the singular case I tested. This is, by far, to be considered untested and unrecommended without considerably more thought and testing. There may be edge cases where this doesn't work as expected or otherwise is undesirable.

As noted in that SO link there may be considerations also with whitespace surrounding the new line characters. My example above only takes care of \n\n\n rather than \n \n \n and other combinations.

Might be worth doing some testing with, on a test database obviously.
 
Thanks! I would greatly appreciate the answers to these questions:
  1. I have found that my sites post table has many tags URLs that are incorrect. The trailing slash is missing. i.e.
    mysite.com/tags/my-tag
    which should be:
    mysite.com/tags/my-tag/
    What RegEx can I use to add the trailing slash to those links that miss this?
  2. Some tags still have old vbulletin syntax with a plus sign between words. i.e.
    mysite.com/tags/my+tag/
    which should be:
    mysite.com/tags/my-tag/
    What RegEx can I use to change the plus sign to a minus?
  3. How can I replace the following urls from:
    mysite.com/threads/627311/#postcount=43
    to:
    mysite.com/threads/627311/
  4. And from:
    mysite.com/threads/105576/#highlight=bla
    to:
    mysite.com/threads/105576/
 
I'm guessing if you get a Forbidden error when trying to add a replacement string, it's an issue with the server?

1618241976974.webp
 
Looks to me like a server permissions issue. Probably need to do a chmod to get the right read/write access to it.
 
Any other ideas? I really would like to use this add-on to fix some links posted in the forums for an external domain that is no longer online. I'm planning to replace it with a link to the web archive.
 
Hey @Chris D - any suggestions on the Forbidden error? I tried uploading files manually via FTP and confirmed that ownership is the same as all the other XF core files, directory and file permissions are set correctly.
 
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?
 
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.
 
Back
Top Bottom