vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Is This Possible? Change Keywords Into Links automatically [Variable Tool won't work] (https://vborg.vbsupport.ru/showthread.php?t=223014)

remotay 09-12-2009 08:47 AM

Is This Possible? Change Keywords Into Links automatically [Variable Tool won't work]
 
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

PHP Code:

$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

Quote:

Originally Posted by remotay (Post 1883892)
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

Quote:

Originally Posted by remotay (Post 1884048)
...
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

Quote:

Originally Posted by remotay (Post 1884253)
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 :)


All times are GMT. The time now is 03:27 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01833 seconds
  • Memory Usage 1,737KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete