Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: fms-er2020 on January 15, 2021, 11:14:22 AM

Title: how to remove "member" bbcode left from old mentions mod
Post by: fms-er2020 on January 15, 2021, 11:14:22 AM
i replaced my mentions mod with a new one

anyone?

help please
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: Aleksi "Lex" Kilpinen on January 15, 2021, 11:44:57 AM
What format is the bbcode exactly? The cleanest way to go would probably be to clean them from the database side, but with some tags that could be tricky.
Other option would be to add support for the tags, so that SMF still parses them and does something or nothing except hiding them.
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: Kindred on January 15, 2021, 11:45:12 AM
you'd have to do a direct database edit... with a replace


UPDATE smf_messages
SET
    body = REPLACE(body,
        string_to_find,
        string_to_replace)
WHERE
    conditions;
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: GigaWatt on January 15, 2021, 11:56:56 AM
You could also use this script ;).

https://github.com/sbulen/sjrbTools/blob/master/SMF_URLs_Paths.php

It's meant for changing URLs on forums, but I use it in these sorts of cases as well ;). I needed to remove the youtube tag from Yet Another YouTube BBCode Tag mod from my forum ;).
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: Aleksi "Lex" Kilpinen on January 15, 2021, 12:22:26 PM
That's actually a pretty handy tool. If used with care.
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: GigaWatt on January 15, 2021, 12:37:18 PM
Quote from: Aleksi "Lex" Kilpinen on January 15, 2021, 12:22:26 PM
That's actually a pretty handy tool.

Agreed :).

Quote from: Aleksi "Lex" Kilpinen on January 15, 2021, 12:22:26 PM
If used with care.

The default is a dry run (don't change anything, just display posts) ;).
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: fms-er2020 on January 15, 2021, 01:49:10 PM
thanks y'all

but i have no idea how to make use of that script

the bbcode looks like this:

[member=1234]SomeUsername[/member]

if you be so kind to give some steps to follow

:(
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: shawnb61 on January 15, 2021, 01:52:40 PM
That script would not work for this.  It works on fixed strings only.

You need something that operates on a pattern match.  It looks like the user id is part of what needs to be removed.
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: Aleksi "Lex" Kilpinen on January 15, 2021, 01:53:29 PM
That would be in the category of "tricky", because REPLACE() does not have any support for wildcards, patterns, regular expressions, etc. REPLACE() only replaces one constant string for another constant string.
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: fms-er2020 on January 15, 2021, 02:03:45 PM
is there a way to do this :(
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: Aleksi "Lex" Kilpinen on January 15, 2021, 02:13:33 PM
I'm sure there is - Sadly, I'm not really able to come up with it. This would probably need a separate purpose built script to find and handle all of those tags.
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: shawnb61 on January 15, 2021, 04:39:20 PM
I'm thinking...

Mysql honors a REGEXP_REPLACE, but in mysql 8.0.

It honors a REGEXP in earlier versions, but as a SELECT only, not for updates.  Maybe a subquery...  Still thinking...
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: Aleksi "Lex" Kilpinen on January 15, 2021, 05:01:15 PM
Of course, if you shut down the forum for a moment - you could do it offline. Backup, export the table, do the replace with a suitable editor or command line tool to your liking, and then import the edited version?
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: shawnb61 on January 15, 2021, 05:07:44 PM
Yes, as long as your editor had some kind of regexp replacement. 

I know Notepad++ does.
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: fms-er2020 on January 15, 2021, 05:11:44 PM
im on SMF 2.0.17

those suggestions sound scary :(
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: fms-er2020 on January 15, 2021, 05:24:28 PM
i think my php version as per checking cpanel is PHP 7.2 (ea-php72)
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: GigaWatt on January 15, 2021, 06:05:41 PM
The script I posted earlier can be modified ;). The "[/member]" part's easy, no need to modify anything. The "[member=" part would go like this: if you hit "[member=" see if it has a digit after that; if it does, continue reading the data until you hit "]"; if no "]" is encountered after (let's say) 50 digits, drop everything move on; if "]" is hit before 50 digits, delete the value from the DB.
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: shawnb61 on January 15, 2021, 06:12:55 PM
Here is a simplified, modified version here:
https://github.com/sbulen/sjrbTools/blob/master/smf_remove_old_bbc.php

If you have a test environment, run it there first & review the changes.
If you do not have a test environment, back everything up first.  Have your host back the db up, too.  Seriously.  If something bad happens & you can't restore, that's on you.

It will run in an inquiry mode.  When you like the output, change the "doit" flag to "Yes" & rerun.

It's written in a way to be able to be used for other bbc-like substitutions.
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: GigaWatt on January 15, 2021, 06:44:41 PM
I LOVE IT :D <3!
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: fms-er2020 on January 15, 2021, 07:24:25 PM
Quote from: shawnb61 on January 15, 2021, 06:12:55 PM
Here is a simplified, modified version here:
https://github.com/sbulen/sjrbTools/blob/master/smf_remove_old_bbc.php

If you have a test environment, run it there first & review the changes.
If you do not have a test environment, back everything up first.  Have your host back the db up, too.  Seriously.  If something bad happens & you can't restore, that's on you.

It will run in an inquiry mode.  When you like the output, change the "doit" flag to "Yes" & rerun.

It's written in a way to be able to be used for other bbc-like substitutions.

thanks

how safe is it to run this with $doit = "no" ?
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: shawnb61 on January 15, 2021, 07:53:28 PM
Safe.

Do your backups.
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: fms-er2020 on January 15, 2021, 08:07:33 PM
shawn sorrry for being such a noob

is this the only line that i need to edit?

$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix);

i should be able to get the first 4 values from the cpanel but what's a db_prefix?




and assume ill just run the php file in the browser window  after saving it in the public folder?
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: shawnb61 on January 15, 2021, 08:13:57 PM
The only line you need to edit is the doit line.

Don't touch anything else.

Read the instructions at the top a few times!   :)
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: fms-er2020 on January 15, 2021, 08:42:51 PM
@shawnb61

im so broke from buying all the mods i want for my community ...................

how can i repay you?

im so happy

thank you so much shawn

everyone that responded to this thread thank you so much

the open source community is the best
Title: Re: how to remove "member" bbcode left from old mentions mod
Post by: GigaWatt on January 16, 2021, 07:44:18 AM
Shawn's the best when it comes to cleaning up things in the forum's DB ;). He's also got some other good qualities... I guess :P ;D.