View Full Version : Is This Possible? Change Keywords Into Links automatically [Variable Tool won't work]
remotay
09-12-2009, 08:47 AM
I've tried searching the forums with no luck. I want it so on every forum post, if someone says the word, lets say Meepo, it will link to meepo.com
The variable replace manager is a good tool, but it replaces EVERYTHING. I just need this done in the posts area.
If this isn't built into Vbulletin I would gladly pay someone to set it up for me. I would enter all the keywords and links manually.
Lynne
09-12-2009, 02:40 PM
I've posted this quite a few times and there is a version of it in the modifications area:
hook location - postbit_display_complete
$word = array(
'word 1',
'word 2',
);
$link = array(
'<a href="link1.php">Link 1</a>',
'<a href="link2.php">Link 2</a>',
);
$this->post['message'] = str_replace($word, $link, $this->post['message']);
(I use str_ireplace, but that's your choice - google the differences.)
remotay
09-13-2009, 01:16 AM
Lynne, thanks so much for the quick reply. To be fair I did a considerable amount of searching before posting this. I guess I was searching the wrong keywords.
Your code works perfectly and I figured out how to implement it, but one small issue. How can I make it so it's not case sensitive?
Ex: Whether users type out Meepo, meepo or mEEpo it should still link to the same location? Using the code above it needs to be case sensitive for it to link correctly.
Lynne
09-13-2009, 02:49 AM
Lynne, thanks so much for the quick reply. To be fair I did a considerable amount of searching before posting this. I guess I was searching the wrong keywords.
Your code works perfectly and I figured out how to implement it, but one small issue. How can I make it so it's not case sensitive?
Ex: Whether users type out Meepo, meepo or mEEpo it should still link to the same location? Using the code above it needs to be case sensitive for it to link correctly.
That is why I suggested googling str_ireplace and perhaps using it instead. :)
remotay
09-13-2009, 10:59 AM
Lynne, you've been extremely helpful, but I have ONE last question, I promise :). I'll certainly return the favor to someone else on the forums who needs help one day.
Works like a charm, but I tried to make it so it only replaces each occurrence of the keyword ONCE rather than every single time it's mentioned in the post.
Some googling led me to find this piece of code 'function str_replace_once' but I need it as istr_replace_once which apparently doesn't exist :[. Even if it did work though I'm not sure if it would work the way I need it to work?
I have 100 keywords that are set to be replaced with that keyword as a URL - So if a post mentions 5 of those keywords, they should all be converted, but if the same posts mentions the same keyword twice, only one should be converted?
Also, Lynne I would certainly donate something like $5 for your time :P, especially now that this got a tad bit more complicated.
AfterWorldForum
09-13-2009, 02:40 PM
...
Some googling led me to find this piece of code 'function str_replace_once' but I need it as istr_replace_once which apparently doesn't exist :[. Even if it did work though I'm not sure if it would work the way I need it to work?
...
Also, Lynne I would certainly donate something like $5 for your time :P, especially now that this got a tad bit more complicated.
Try putting MEEPO in your $word array, and within the str_replace_once, wrap a strtoupper function around the $word parameter.
This way, regardless of case in the post, it will always evaluate to the fully capitalized word stored in your array.
HTH.
Peter
Lynne
09-13-2009, 02:55 PM
^^ What he said is a very good solution and something I would not have thought of, so thank you EntropiaPlanets for posting that!
remotay
09-13-2009, 09:18 PM
Will ucwords() work as well? If I use ucwords() will I need to make all of the words in the array lower case for this one to work?
Because first character of each word uppercase looks cleaner than all caps :)
AfterWorldForum
09-14-2009, 03:51 PM
Will ucwords() work as well? If I use ucwords() will I need to make all of the words in the array lower case for this one to work?
Because first character of each word uppercase looks cleaner than all caps :)
The only place it will be "seen" is in the code, and even there, no real person is looking at it (well, you and perhaps some other coders).
What goes on in the kitchen might not be pretty to look at, but as long as the clientele never finds out, they don't care :D
And Lynne, your most welcome :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.