News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Automatically link certain words?

Started by MrMike, May 27, 2012, 12:40:51 PM

Previous topic - Next topic

MrMike

Your regex is better, consider it switched. :) I should have been breaking along word boundaries as you did, it's a cleaner, more sensible way to do it.

So, how does one make a mod out of this...is there an online guide or a step-by step tutorial?

Arantor

Well, if you take a look at the 'Important Customization Information' sticky topic in this board, you'll find a bunch of links discussing various aspects of building a mod.

Essentially, though, you could just do what I did: look at existing mods and see how they work, for the very most part it's just a case of find/replace operations.

MrMike

Quote from: Arantor on May 29, 2012, 10:03:26 PMEssentially, though, you could just do what I did: look at existing mods and see how they work, for the very most part it's just a case of find/replace operations.

I think the part I'm most uncertain about is how to create the configuration screens with the options for SMF. I'll look over those topics and see what I can learn.

Arantor

Ah, yes, that's not really that well documented.

There's essentially two parts to it, adding an item to the menu and then doing something when you call that. Take a look around at some mods that do the same (preferably later ones that describe themselves as using hooks, because that solves a *lot* of headaches for 2.0)

MrMike

Quote from: Arantor on May 30, 2012, 10:05:27 AMAh, yes, that's not really that well documented.

Yep, I noticed, lol.

Here's the thing...I've got what seems to be some stable, working code. I could probably figure out all the packaging stuff and configuration screens eventually, but if people want this as a mod package before the turn of the century then someone who's familiar with mods might want to contact me to get the code and package it up...otherwise it may be a looooooooong time before I manage to get into a proper, usable mod package.

I did add some code to eliminate unnecessary queries. The first time the mod is used it does a single query to get the target words, which are then placed in a session var. After that initial query it shouldn't need to hit the database again (as long as the user's session is still alive), it 'll just pull a fresh target list out of the session for each post.

MrPhil

Quote from: MrMike on May 29, 2012, 09:29:30 PM
So, how does one make a mod out of this...is there an online guide or a step-by step tutorial?

@Arantor gave a link earlier to a discussion on the subject. I would read that and then pick apart two or three recent mod packages that do similar things, to get the nitty-gritty practical details. Maybe you could write a post in that discussion with interesting things you found. If you want to bounce any ideas or questions off of me, feel free to PM me. I don't have experience in putting together a mod, but I need to learn how myself as soon as I get some time to do it...

I would suggest that your code only link the first word or phrase on the page, rather than on a per-post basis. I know I get tired of seeing the same terms linked over and over on a page. On the other hand, it might be useful if a reader tends to jump directly to the last or to unread posts. I guess it could be argued either way... Would it be useful to be configurable in member profiles? I wonder if there are any legal issues to marking a trademark only way up top of a page, and someone doesn't see that mark because they came in "late" to the discussion? Perhaps there could be a per-word flag to force the processing of that word in each post?

Arantor

Eh, putting together a mod is pretty straightforward, although using hooks is slightly more exotic.

The main reason why there isn't much of a tutorial is that historically, mods did their work by find/replace on the code itself, and it's kind of hard to provide a tutorial for something that's going to change just about every time.

MrMike

#27
Quote from: MrPhil on May 30, 2012, 11:23:50 AMI would suggest that your code only link the first word or phrase on the page, rather than on a per-post basis. I know I get tired of seeing the same terms linked over and over on a page.

I specifically want the words linked in each post, partly to make certain that people who come into the middle of a thread see it. Once per page is too easily missed (in my opinion).

At this point I'm only looking at one possible change, and that's a 'replacement type' field, where the replacement action could be to either link the word (as it does now) or replace it entirely with the contents of the replace field.

EDIT: I've added the "link or swap" feature above:

       
  • In "link" mode it'll auto-link the word with the URL you provide.
  • In "swap" mode it'll replace the word with whatever you provide (text, HTML, images, etc).
Hopefully it'll give the mod a little flexibility and allow it to be used in other ways, as shown on this demo page:

http://deltabravo.net/forum/index.php?topic=39855.msg318677#msg318677


I figure someone may find it useful to style certain words (bold, italic, etc) or perform some sort of arbitrary replacement (an image, a button, whatever). The added flexibility may let people do other stuff with it as well (ad insertion, dynamic help boxes, etc).

Quote from: MrPhil on May 30, 2012, 11:23:50 AMWould it be useful to be configurable in member profiles?

Not for my intended use, but someone may consider that a useful option.

MrPhil

The "swap this" entries seem need a double click to swap from white on green to black on white, and it only does one word at a time.

Shouldn't the "cake here" be showing and I need to click on it before changing to an image?

MrMike

1) The "swapthis" entries are just static spans, they're just text. Double-clicking is just like clicking on any other text. What you're seeing is normal, expected behavior.

2) The image of the cake should be visible with no interaction (no clicking required). The tag "cake_here" is replaced with an image of a cake when the post is processed. I see the image of the cake in both Firefox and IE...what browser are you using?

Quote from: MrPhil on May 30, 2012, 11:48:02 PM
The "swap this" entries seem need a double click to swap from white on green to black on white, and it only does one word at a time.

Shouldn't the "cake here" be showing and I need to click on it before changing to an image?

MrPhil

Quote from: MrMike on May 31, 2012, 01:06:15 AM
1) The "swapthis" entries are just static spans, they're just text. Double-clicking is just like clicking on any other text. What you're seeing is normal, expected behavior.
If other "censored word" links only take a single click to activate the link, I think that users will find it confusing to have to double click to do anything.

Quote
2) The image of the cake should be visible with no interaction (no clicking required). The tag "cake_here" is replaced with an image of a cake when the post is processed. I see the image of the cake in both Firefox and IE...what browser are you using?
I see the cake too (FF 12) but I want to eat it and have it too! Isn't the whole point of this to have text in your post (highlighted in some way to hint that something can be done with it), that you click on to have something special happen? If you're just going to have a picture of a cake, why not use an [img] tag? You could certainly have the image as a clickable link, and get "cake here" when you click on it, but that seems backwards. The whole idea, as I understand it, is to have a smooth flow of text, with clickable text for a side trip to doing something else.

MrMike

Quote from: MrPhil on May 31, 2012, 10:05:07 AMIf other "censored word" links only take a single click to activate the link, I think that users will find it confusing to have to double click to do anything.

That particular example just shows the tag "swapthis" being swapped with a span containing the words "Replaced Block", and the span is styled with a green background and white text. It's not meant to be clicked on.

Another example shows the tag "button_here" being replaced with a javascript-enabled button. That one can be clicked on.


Quote from: MrPhil on May 31, 2012, 10:05:07 AMIsn't the whole point of this to have text in your post (highlighted in some way to hint that something can be done with it), that you click on to have something special happen?

Yes and no. The point of this mod is to either add predefined links to selected words (link mode), or to replace selected words (tags) with whatever you want (swap mode).


Quote from: MrPhil on May 31, 2012, 10:05:07 AMThe whole idea, as I understand it, is to have a smooth flow of text, with clickable text for a side trip to doing something else.

I think you misunderstand the purpose of the mod. It's just a text replacer. What the text gets replaced with is up to you. In the "link" mode it links the word with a URL you define and (optionally) applies some styling.

In the "swap" mode it replaces the word (perhaps a predefined tag) with whatever you want- another word, a button, an image, a form, a table...whatever you put in the replace string.

To be clear, I developed this mod to auto-link specific words or phrases so that people in the forum would be able to drill down to find related pages for those words or phrases. I added the free-form replacing feature because I thought it might be useful to people in other applications.

I don't plan on using the "swap" feature myself, but it could be used to do a *lot* of tricky stuff in posts.  :)

beanflying

Just what I am looking for, the word censor isn't really doing what I want.

Even if your not going to package this as a full mod any chance you can put the code here or in a PM.

cheers.  :)
Owner of many many shiny toys.

STRONGHOLD

Hi,

Can you please share the codes with us? :)


Sciamano

Did anyone manage to get their hands on this very useful piece of code?

johnpaul2k2

Quote from: MrMike on May 31, 2012, 10:47:19 AM
Quote from: MrPhil on May 31, 2012, 10:05:07 AMIf other "censored word" links only take a single click to activate the link, I think that users will find it confusing to have to double click to do anything.

That particular example just shows the tag "swapthis" being swapped with a span containing the words "Replaced Block", and the span is styled with a green background and white text. It's not meant to be clicked on.

Another example shows the tag "button_here" being replaced with a javascript-enabled button. That one can be clicked on.


Quote from: MrPhil on May 31, 2012, 10:05:07 AMIsn't the whole point of this to have text in your post (highlighted in some way to hint that something can be done with it), that you click on to have something special happen?

Yes and no. The point of this mod is to either add predefined links to selected words (link mode), or to replace selected words (tags) with whatever you want (swap mode).


Quote from: MrPhil on May 31, 2012, 10:05:07 AMThe whole idea, as I understand it, is to have a smooth flow of text, with clickable text for a side trip to doing something else.

I think you misunderstand the purpose of the mod. It's just a text replacer. What the text gets replaced with is up to you. In the "link" mode it links the word with a URL you define and (optionally) applies some styling.

In the "swap" mode it replaces the word (perhaps a predefined tag) with whatever you want- another word, a button, an image, a form, a table...whatever you put in the replace string.

To be clear, I developed this mod to auto-link specific words or phrases so that people in the forum would be able to drill down to find related pages for those words or phrases. I added the free-form replacing feature because I thought it might be useful to people in other applications.

I don't plan on using the "swap" feature myself, but it could be used to do a *lot* of tricky stuff in posts.  :)

Mr Mike...i really need the link mod or code. please help us

Advertisement: