Firefox PHP

Dictionary Plug-in

Posted by Rob 
Rob
Dictionary Plug-in
May 03, 2001 02:39PM
I wanted an easy way to give my user access to definitions of certain words. It checks the body of the message for any words that exist in it's dictionary table. If it finds them it replaces the work with a link that displays a little popup window on mouseover with the definition.

example:
[www.liquidcode.net]

It works really well, but does cause a little slow down on long posts, as you can see in the message below the above one.

I've tested this plugin with Phorum v3.2.11 and MySQL v3.22.27 but it should work with any version of MySQL. Currently it only works with MySQL.

Since I can only attach text, let me know if you want the code fo this plugin.

Please let me know what you think, if you have any problems with it, or if you think it needs anything.
Re: Dictionary Plug-in
May 05, 2001 03:47PM
i would love to use it. All support you need is here
Re: Dictionary Plug-in
May 07, 2001 09:32PM
I'd be interested in seeing how you did this. Do you
use a flat text (or DB..whichever you prefer) to query
the post prior to insert, then attach appropriate javascript?

Nice idea. Could be developed exceedingly well. If you don't
mind, I'd like to look at the source as well. kyndig@kyndig.com

Kind Regards,
Kyndig
[www.kyndig.com]
Phorum Hacker As Time Permits
Great
May 08, 2001 08:32AM
i would love to use it. Not only in phorum, but also in my articles
Rob
Re: Dictionary Plug-in
May 08, 2001 01:35PM
I'm gald you liked it. I've put up a temporary download area on my server so you can get it.

www.liquidcode.net/dictionary/

All the source is there for you to play with. Let me know if you come up with anything that I could use.

The way it works currently is: Phorum calls the plugin with the body of any messages, this text is then parsed looking for any "dictionary" words (the dictionary is kept in the database), if the words are found then the word is converted into a link and the Overlib javascript call is added. I didn't write the Overlib javascript I just wrote the code to use it with Phorum. The dictionary.php script can be used outside of phorum you just need to modify the way the database works and it'll run fine. I originally built it to run on the rest of my site which is going to be a slashdot clone.

I still have a lot of code clean up to do, and I need to work on speeding up the parsing and replacing of the text since it's slow on large messages, and will be slow on a non-threaded message board.
Idea
May 08, 2001 02:19PM
here is idea:
What if we count number of chars in $body and found out that it's too big, then we will use new window jscript. I dont' thinks its' too hard, but it could fix parsing of big messages.
Rob
Re: Idea
May 08, 2001 02:30PM
That would speed things up but leave long messages without there dictionary words converted. This would make the site look strange. Especially if the users got used to seeing certain words in different colors and in some messages they aren't. I think there is a better solution, I just need to look for it.

I think I can get some speed increase by optomizing my code. I'm looking at it now and I see a function that I call 3 times for each word in the text and I should just call that once on the entire text block.
Re: Dictionary Plug-in
May 08, 2001 07:24PM
Great job! Well documented class workin. Going to modify it abit and place it in the public forums, but as to the time to parse the message, I see no help for this. Other than changing the loop process you have (abit heavy, but I can follow your login behind grabbing each word in order to compare these to your database)

Best bet I'd see if your greatly concerned about a quick memory hike and abit of drag in submission process is store your dictionary in a simple associative array. Since you will be maintaining full control over your dictionary, an associative array will allow for comparison call on the fly during your loop. This keeps you from the overhead of another heavy query and comparison. Drawback: It isn't in the database and thus is hard coded. You could go with phorums style of configuration file handling by parsing the config file itself, just changing your pointers arround through a form or what not.

Theres my ten cents. Thankyou most kindly Rob for a great class
mod! ( and the commenting is just an added bonus ;)

Kyndig
Re: Idea
May 08, 2001 07:55PM
no, there still be link on new page instead of layer.
Jules
Re: Idea
May 09, 2001 03:49AM
hmm...i took a look at this feature...its pretty neat...i was thinking maybe using it to show info on the authors and maybe set up a form for them to fill out with their personal info they may want to make public. could workout...the ideas are many =)

Jules
Rob
Re: Idea
May 09, 2001 01:23PM
It'd be very easy to convert to that usage. Let me know if you want any help.
Rob
Re: Idea
May 09, 2001 01:27PM
True, I guess I missunderstood you. Actually before I found the Overlib javascript library that was how I was building it to work. It's just a matter of changing the $this->link_options, and $this->link_start in the dictionary.php class.
Rob
Re: Dictionary Plug-in
May 09, 2001 01:31PM
I thought about making the database an include, but since there is only 1 query done when the class in initialized, and I have the class initialized only once I didn't think that the database would be a problem. Unless someone creates a hugh dictionary.

Let me know what you do to the code, or if there is anything I can help you with.
Rob
Re: Dictionary Plug-in
May 21, 2001 02:58PM
If you downloaded a copy of this plugin you might want to update it. I was informed of a bug where the javascript broke on flat view pages. The bug has been fixed and you can get the updated code at: [www.liquidcode.net]
Re: Dictionary Plug-in
January 13, 2002 12:19PM
Is this code still available? I'm getting a 404 trying to hit the page?
Mike
Rob
Re: Dictionary Plug-in
January 14, 2002 01:09PM
Sorry about that, my server crashed and I haven't gotten everything back up yet. Hopefully by this weekend. Maybe someone who has already downloaded it can send you a copy.
Re: Dictionary Plug-in
January 21, 2002 12:01PM
Please someone give me a copy this dictionary.
Send me via email, please.
Thank you.
Rob
Re: Dictionary Plug-in
January 23, 2002 12:51PM
Ok, I haven't gotten my server completely back up, but I did get the plugin download page back. So if you want it you can get it at:

www.liquidcode.net/dictionary/
Re: Dictionary Plug-in
February 20, 2002 08:21PM
I am running 3.3.2a, i have added a inf.php file to the directory so that the plugin can be picked up (this is instead of adding the line in plugins.php , actually i copied the one from the repace plugin and edited it.
I followed the rest of the instructions and it seem sok apart from the java script doesnt seem to be executing on mouse over. i had a look at the code for the page, the code for my higlited entr looks like this:

<SCRIPT LANGUAGE="JavaScript" SRC="./plugin/dictionary/overlib.js"></SCRIPT>
I am thinking about reveneering the dash on my <a href="javascript:void(0)" class="def-text" onMouseOver="return overlib('a real rare breed', CAPTION, 'Definition: Stag', NOCLOSE, AUTOSTATUS, AUTOSTATUSCAP, FGCOLOR, '#C0C0C0', BGCOLOR, '#000080', TEXTCOLOR, '#000000', CAPCOLOR, '#FFFFFF', CLOSECOLOR, '#FFFFFF', TEXTFONT, 'Arial,Helvetica;', CAPTIONFONT, 'Arial,Helvetica;', CLOSEFONT, 'Arial,Helvetica;', TEXTSIZE, '2', CAPTIONSIZE, '3', CLOSESIZE, '2', WIDTH, '40', HEIGHT, '40', CENTER, BORDER, '3', CAPICON, '/icons/script.gif', OFFSETX, '10', OFFSETY, '10')" onMouseOut="nd();"><span class="def-text">Stag</span></a>


any ideas whats wrong.

Thanks

Dave
Re: Dictionary Plug-in
April 15, 2002 11:23AM
I have also come across this problem. It seems to only happen on the newest versions of IE6 with internet security set to medium or higher. I don't know how to fix it yet and am trying to figure one out.
Sorry, you do not have permission to post/reply in this forum.