PDA

View Full Version : Hotlinking Forum Names In Posts?


Killerhands
09-12-2010, 04:43 PM
Hi everyone,
I know the basics about vB and have edited a few templates and code here and there, but nothing major. So, I was thinking the other day that if someone posted a thread (or reply) if within the text they reference a Forum, instead of manually having to make a hyperlink linking the text to the forum if somehow vB would auto-detect the name and hotlink it automatically.

Here's a more visual explaination:
original post:

Please go to the FAQ and Clan Knowledge forum if you have any questions or need to find information about the clan.


Auto-detected forum post

Please go to the FAQ and Clan Knowledge (hotlinkedurlheretoforum) forum if you have any questions or need to find information about the clan.


I'm not exactly if this is even possible, but I was wondering if any of you coders out there would have any information about how to approach this. I've looked for mods and I haven't seen anything like this (AME is the closest). I'd imagine it'd just be some sort of simple If-then-else set of statements coming from basic coding experience but I'm not sure on specifics.

Any insight would be greatly appreciated!:)

Thanks,
Killerhands

kh99
09-12-2010, 05:22 PM
Yeah, seems like you could do that without a lot of trouble. The forum names are already in memory (although it may depend on which php file is being executed, I'm not sure). You'd just need to find the right hooks to do a search and replace on the text. Would you want it to be before it's stored or just before it's displayed? I'd think before it's stored so that if a forum is renamed the link would still be there. Some one just asked about that recently, I think I found that the newpost_process hook is called before a post is stored in the database, but that doesn't work on posts being edited (the thread is https://vborg.vbsupport.ru/showthread.php?t=250140).

Maybe another way would be to replace the forum name with some bbcode like 123, then define a bbcode to provide a link (although I guess you couldn't just define a bbcode using the manager, you'd have to write a plugin to be able to insert the forum's name).

Hope some of this make sense.

Killerhands
09-13-2010, 02:23 PM
The bbcode makes the most sense, just I think the hard part for me if figuring out how to extrapolate the forum ID based on the text. I just don't really know where to start. Would I have to make a query to the database asking for all the forum names listed within it and do a search from that?

kh99
09-13-2010, 02:43 PM
A while back I knew a lot about this because I was working on somethng that used the forum info, and now I've forgotten. Maybe the best thing is to look at forumdisplay.php (and also be prepared to look into any included files to see where stuff comes from, like init.php and global.php).

A lot of stuff gets cached to avoid doing a lot of database queries. For instance, the forum info gets used a lot, so once the query's been done the array is serialized and saved as a big string to avoid doing a complex query every time someone vists the home page. There's a $vbulletin->forumcache that's an array by forum id, and one of the fields is 'title', so $vbulletin->forumcache['12']['title'] should be the name of forum with id 12. There's also a variable called $foruminfo, I can't remember what that's for. You'll have to investigate to see under what circumstances these things are filled in (or maybe someone else can help).