Advertisement:

Turning certain words into links automatically

Aloittaja Sciamano, maaliskuu 28, 2013, 06:36:12 AP

« edellinen - seuraava »

Sciamano

Hello!
I'm running a travel blog, and I'd need to turn certain words like 'Expedia' or 'Priceline' for example into the respective affiliate links, so that every time someone writes the word 'Expedia', my Expedia affiliate link automatically comes out.
In other words I need to automatically turn certain words/expression into links.

I've searched the boards over and over, and the usual solution suggested is to use the Censored Words tool.

The problem is this works only if someone does not try to edit a post where a word/expression has already been turned into a link.
For example, if I place this in the Censored Words setup:

Google --> [url=http://www.google.com]Google[/url]

it works only if no one edits a post where this transformation has already been done.
Infact, if I edit a post with the linked Google word, this is what I see:


I tried searching this in [url=http://www.google.com]Google[/url]

[/code]

And as soon as I hit the 'Post' button, both google words (the one inside www.google.com [nofollow] link and the 'Google' word itself) get transformed again (and it loops every time one edits the post), therefore the result is this:


I tried searching this in [url=http://www.[url=http://www.google.com]Google[/url].com]Google[/url]


Which, as you can imagine, is a huge mess (and gets worse every time one edits, as I already said before).

I've also tried preventing the 'loop' transformation putting this in the Censored Words tool:


Expedia ---> [url=http://clk.tradedoubler.com/click?p=XXXX&a=YYYY&g=ZZZZZ]Expedia[/url]

and

[url=http://clk.tradedoubler.com/click?p=XXXX&a=YYYY&g=ZZZZZ][url=http://clk.tradedoubler.com/click?p=XXXX&a=YYYY&g=ZZZZZ]Expedia[/url][/url]
--->
[url=http://clk.tradedoubler.com/click?p=XXXX&a=YYYY&g=ZZZZZ]Expedia[/url]


But it does not work. Every time I edit a post, the url tag gets multiplied.

Please help, this is making me crazy, and unfortunately I'm no programmer so I can't solve this by myself.
Thanks a lot.

kat

How about using Word Censoring?

There, you can censor "Google", replacing it with "http://www.google.com".

Sciamano

That's what I'm using...  my whole post talks about this :)

kat

Doh! I missed that line! :P

I think that what you have, there, is a bug with the ol' WYSIWYG editor.

If you disable that, does it work OK?

Sciamano

#4
I tried disabling it (Admin panel -> Post and Topics -> Post Settings) but no matter what I do, I keep getting the WYSIWYG editor!!
What am I doing wrong??

EDIT: wait a second... I think I never had a WYSIWYG editor active. All I get is the usual editor with buttons on top, which write BBCode tags in the text area when selected.

EDIT/2: what's even more strange is that with my Priceline affiliate link, it actually works!! But it does not with other links.
The Priceline link looks like this:

[url=http://www.kqzyfj.com/click-123456-12345678]Priceline[/url]

And using this in the Words Censorer works:


Priceline --> [url=http://www.kqzyfj.com/click-123456-12345678]Priceline[/url]

[url=http://www.kqzyfj.com/click-123456-12345678][url=http://www.kqzyfj.com/click-123456-12345678]Priceline[/url][/url]
-->
[url=http://www.kqzyfj.com/click-123456-12345678]Priceline[/url]


(If I edit the post, it still remains one working link, no links inside links)

But with other links, like the Expedia one, it doesn't.
I guess there's something in the affiliate link syntax that prevents the Words Censorer from working correctly.
The Expedia link looks like this:

Expedia ---> [url=http://clk.tradedoubler.com/click?p=XXXX&a=YYYY&g=ZZZZZ]Expedia[/url]

I've already tried editing out the question mark but it looks like the problem does not lay there.

The problem really lays here, because using a tinyurl link instead of the full affiliate link actually works (which is a nice workaround but not really a solution)

Any insights??

MrPhil

Does Word Censor get applied during rendering of the post, as opposed to during entry/edit? I thought it was, but I can't look at the code until I get home tonight. That would mean the plain word "Expedia" should be in the post entry in the database, and none of the replacement markup, regardless of which editor you use.

Since the Word Censor presumably stores its lists in the database, could it be you're running into a maximum length issue? To actually censor (replace) a word normally wouldn't take all that much more text than the original word, but WC wasn't really built to do general replacement like this, and maybe it doesn't allow enough space for some replacements? I'd check the database to see if there is an unreasonably short replacement string allowed, and consider increasing the field size. If you do that, you may have to change other settings or hard coded variables that check field lengths.

SMF really could use a variant of WC that would replace only the first occurrence on a page (as well as first after #new), or the first in each post, and possibly within titles (subject lines). It could also be used to mark known trademarks (tm) and (r). This has been discussed before.

Sciamano

Lainaus käyttäjältä: MrPhil - maaliskuu 28, 2013, 09:44:26 AP
Does Word Censor get applied during rendering of the post, as opposed to during entry/edit?

I have no idea

Lainaus käyttäjältä: MrPhil - maaliskuu 28, 2013, 09:44:26 APSince the Word Censor presumably stores its lists in the database, could it be you're running into a maximum length issue?

I think this might be the problem since, as I stated in the previous message, using shortened urls makes everything work...


Sciamano

Lainaus käyttäjältä: K@ - maaliskuu 28, 2013, 10:20:10 AP
Why not use tinyurl?

http://tinyurl.com [nofollow]

That's what I've done:

Lainaausing a tinyurl link instead of the full affiliate link actually works (which is a nice workaround but not really a solution)

Still think it's not a true solution, although it works :)


Arantor

To answer MrPhil: word censoring is applied before the post is viewed, or before it goes to the editing page, if it is forced on, or it is not forced on but the user has it on. (It is possible to allow users to turn it off)

Sounds to me like the Glossary mod might be a better fit.
Holder of controversial views, all of which my own.


Sciamano

Lainaus käyttäjältä: Arantor - maaliskuu 28, 2013, 11:20:30 APSounds to me like the Glossary mod might be a better fit.
I've already looked at it, but it does not make links out of words, only tooltips. :(

SlyBaldGuy

Another problem with using the Censored portion of the site is that it also converts the text in the titles of the posts.

I'd be willing to contribute money to someone to develop a mod that converted keywords to other text/links just in the body.

MrPhil

Rather than modifying the censorText() function, I would write a new function (in Load.php) that behaves in a similar way. Let's call it moreText(). Find all the places where censorText() is called for something that looks like the body of a message, and after that call moreText() with the same argument. censorText() seems to both modify its input and return the value, but in most (if not all) cases the code discards whatever is returned. So, it would probably be easier to just call another function than to try to wrap something around censorText() calls, or to add a new parameter to censorText() (it already has an optional argument, so you'd have to modify every single call to censorText()). You might not necessarily want to call moreText() for every single place the message "body" is censored, but it's a start.

Within moreText(), you could use censorText()'s code as a starting point. To do it really right, you would want an admin interface to maintain the list of words and their replacement addresses ("vulgar" and "proper" terms in censorText()). As a very quick and dirty, you could have a hard coded list in the function, but as a mod it should store the terms in the database somewhere. You would only need to store the address (href term), and could build the rest of the link on the fly. One thing that should differ from word censoring is that only one instance of a word (say, "Expedia") should be "linkified" per post, and possibly per page. You could either hit the first one, or randomly select one from among multiple occurrences in a message body. To do it only once per page would be a much harder task, as you would either have to have all the message bodies at once, or just do the first and set a flag somewhere that term has been handled.

johnpaul2k2

Lainaus käyttäjältä: SlyBaldGuy - kesäkuu 23, 2013, 11:24:44 IP
Another problem with using the Censored portion of the site is that it also converts the text in the titles of the posts.

I'd be willing to contribute money to someone to develop a mod that converted keywords to other text/links just in the body.

i have been waiting and will still wait ;)

allweb

Any update on this, I have tried censored words but have the same problem with titles being affected too, if some one could come up with a simple bit of code to restrict censored words from titles then this method would work. I will see if I can find the code and do it and will report back however if some one finds a way to do this before hand please let us all know.

Thanks

handy1

Lainaus käyttäjältä: SlyBaldGuy - kesäkuu 23, 2013, 11:24:44 IP
Another problem with using the Censored portion of the site is that it also converts the text in the titles of the posts.

I'd be willing to contribute money to someone to develop a mod that converted keywords to other text/links just in the body.

I am also ready to pay someone if he/she can do this. Replace word by links, but just in body.

emanuele

Dunno if that is what you were looking for, but should be quite close.

It is just a variation of the censoring, but it affects only stuff that passes through parse_bbc (that means message' bodies, but not subjects, PM bodies, the news and it may affect also custom fields if set up to use bbc code).
I understand is less than optimal, but I think it's the safest way, otherwise you'd have to manually apply the code to many places and/or not apply it to many others, kind of a mess. This way I'm sure any place worth a "replacement" is replaced.

Well, if you want to donate something let me know by PM.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

johnpaul2k2

Lainaus käyttäjältä: emanuele - huhtikuu 27, 2014, 09:52:00 AP
Dunno if that is what you were looking for, but should be quite close.

It is just a variation of the censoring, but it affects only stuff that passes through parse_bbc (that means message' bodies, but not subjects, PM bodies, the news and it may affect also custom fields if set up to use bbc code).
I understand is less than optimal, but I think it's the safest way, otherwise you'd have to manually apply the code to many places and/or not apply it to many others, kind of a mess. This way I'm sure any place worth a "replacement" is replaced.

Well, if you want to donate something let me know by PM.

thanks emanuele

i am thinking of replacing with affiliate link 8)

hope it will work?

emanuele

I suppose so. :P

Oh, another different from the normal censoring is that users cannot disable it.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Advertisement: