Customizing SMF > SMF Coding Discussion

Automatically link certain words?

(1/8) > >>

MrMike:
Is there a mod that will automatically link certain words? I've looked through the mods and don't see anything that quite fits that description.

In short, I have a list of keywords and when they appear in a forum post, I'd like to automatically link them to a specified page. The censor feature can do this, but it interferes with the Anti-Spam Links mod.

So, essentially a second censor feature I can use to turn specific words into specific links. Is there a mod like that?

MrPhil:
This has been asked many times (as you're probably aware), and the usual answer is to use word censor. That's not a good solution, even if you're not using Anti-Spam Links, because it will probably end up turning every occurrence of a given word into a link. Preferably, only the first on a page would be linked. There is a question about what text would be so treated -- just post body? signatures? topic subjects? page title?

Anyway, you could probably have a list of words and actions very similar to the censor function. I don't know why word censor and Anti-Spam Links don't play nicely together, so that problem would have to be looked for and addressed. When you read in the list at the top of the page, you would initialize an array of flags for all words in the list. Do the censor-type scan of all applicable text, replacing the found word (if it hasn't already been marked on this page) with whatever the replacement is. Mark the word as already done (for this page). It would be possible to do this globally (only link the first time in a session), but that would involve tracking the list of words seen in a new database table.

Whoever writes this mod might make it more general purpose... not just links, but also trademark signs (tm or P or R) could be handled too (insert symbol, not link). Future actions could be added, such as affiliate linking (there's a mod for that). Maybe the mod should be called FirstTime?

MrMike:
I'll write up a function to do something like this, but I'm not familiar with how to turn it into an official mod package. Perhaps you or someone else would be able to do that if I provided the code?



--- Quote from: MrPhil on May 27, 2012, 02:31:27 PM ---This has been asked many times (as you're probably aware), and the usual answer is to use word censor. That's not a good solution, even if you're not using Anti-Spam Links, because it will probably end up turning every occurrence of a given word into a link. Preferably, only the first on a page would be linked. There is a question about what text would be so treated -- just post body? signatures? topic subjects? page title?

Anyway, you could probably have a list of words and actions very similar to the censor function. I don't know why word censor and Anti-Spam Links don't play nicely together, so that problem would have to be looked for and addressed. When you read in the list at the top of the page, you would initialize an array of flags for all words in the list. Do the censor-type scan of all applicable text, replacing the found word (if it hasn't already been marked on this page) with whatever the replacement is. Mark the word as already done (for this page). It would be possible to do this globally (only link the first time in a session), but that would involve tracking the list of words seen in a new database table.

Whoever writes this mod might make it more general purpose... not just links, but also trademark signs (tm or P or R) could be handled too (insert symbol, not link). Future actions could be added, such as affiliate linking (there's a mod for that). Maybe the mod should be called FirstTime?

--- End quote ---

MrPhil:
Well, I'm a virgin, too  :-[  Is there a good tutorial on turning code edits into real mods?

Arantor:
http://www.simplemachines.org/community/index.php?topic=20319.0

Basically it's just a case of putting together some find/replaces in XML, and just looking through existing mods should cover everything you need to know.

Navigation

[0] Message Index

[#] Next page

Go to full version