Glossary

Started by slinouille, December 24, 2008, 10:33:47 AM

Previous topic - Next topic

DaKrampus

#420
Quote from: nixlike on May 20, 2012, 02:53:56 PM
Is anyone able to fix this for current SMF 2.0.2? Installing it with some manual edits is not a problem, but the usage seems to be broken, especially here:

'<span class=\"glossary\" title=\"".addslashes($definition)."\">$1</span>'",

It shows up with ">theglossarywordIputin which can also be fixed somehow by manual editing but then again it fails again when the definition is multilined (not just one single line) and shows up in the post with line2, line3">theglossarywordIputin in the post message and I don't seem to be able to fix this on my own :( I am so much looking forward to use this mod, but it needs some optimization.

Thanks to anyone (mod creator - are you still active?) who is able to fix this :)

That one is only usefull if you want to add glossary bbcode.. when editing. I dont use that.

But I am rewriting the parsing part for a medical page, and got it working by changing big parts of  the parsing function.
As I am out of the country, I dont have my pc here, but I will be back in about 2 weeks time.
basically what i did is in subs.php
I replaced parse_glossary function with this one:
function parse_glossary($message)
{
global $context, $modSettings, $smcFunc, $db_prefix;
// Check if mod is enabled
if(empty($modSettings['enable_glossary_mod']) || $modSettings['enable_glossary_mod'] == false)
return $message;

//Build full glossary list
if ( empty($context['glossary_list']) ){
$context['glossary_list'] = array();
$data_glossary = $smcFunc['db_query']('', '
SELECT *
FROM {db_prefix}glossary
WHERE valid = {int:valid} AND show_in_message = {int:show_in_message}
ORDER BY word ASC',
array(
'valid' => 1,
'show_in_message' => 1,
)
);   
while ($res = $smcFunc['db_fetch_assoc']($data_glossary) ){
$context['glossary_list'][trim($res['word'])] = trim($res['definition']);
//if synonyms exit then add them in the list
if ( !empty($res['synonyms']) ){
$synonyms = explode(',',$res['synonyms']);
foreach ( $synonyms as $synonym )
{
$context['glossary_list'][trim($synonym)] = trim($res['definition']);

}
}
}
$smcFunc['db_free_result']($data_glossary);
}
$words = $context['glossary_list'] ;
$restricted_symbols = array('{','}','?',',','+','*','|','/','\\','$','^','.','[',']');
foreach($words as $word => $definition)
{
/*if you are in UTF-8 Fix the international characters in the keyword. */

$word = (isset($context['utf8']) && !empty($context['utf8'])) ? un_htmlspecialchars($word) : $word;
// we strip out any regex breaking symbols
$word = str_replace($restricted_symbols, '', $word);


//This is the new regex
$regex = '/\b(?!<.*?)('.trim($word).')(?![^<>]*?>)\b/siU'; 
//does the def really need addslashes??? i dunno but i tried without using ' " and <> and it works without. so i dont use it
$newstring = '<span class="glossary" title="'.$definition.'">'."$1".'</span>';
// now we do the preg_replace
$message = preg_replace($regex, $newstring, $message,(isset($modSettings['glossary_unique_word']) && $modSettings['glossary_unique_word']==1) ? 1 : -1); 
}
//followin has to disappear, because a) I dont want urls in tooltipps b) you cannot click them anyway.
// TODO: keep all bbcode as is, and parse with javascript.

if ( !empty($modSettings['enable_bbc_tooltip_glossary']) ) {
$message = preg_replace('#\[ url=([^\]]*) \] (.*?) \[ /url \]#smx','$2',$message); //Suppress URL bbcode from tooltip
return parse_bbc($message,true,'',array('b','i','u','url'));
}
else return $message;
}


it takes much less memory on very large glossaries, because the part where in the original you have to prefix all glossary words to avoid them parsing themselves is gone. So those huge array manipulations are also gone.
The original regex does not permit to parse in urls, but we are in a span tag, this regex does not permit to parse between any < > tags. so there is no self parsing any more. Advantage: you can parse a word that is <a>tags.. seems to work. reslut parsing test: <a href="#">testword</a> will give <a href="#"><span class=glossary>test</span>word</a>

And, you ran into major probs, if some of your keywords contained regular expression elements. like []*.? In that case it was broken.
here it would also be the case.
But they are stripped out now, so word wont match anyway. (it would not break, if you slashed the chars out in the word... but that would be too complex as usually you dont slash out a * or a dot .)

Just dont use those chars in your key words (in description it does not matter)

I hope it works for you, because I modified much more, as there were/are glitches in the javascript part. I wrote my own, that only makes tooltips and parses the bold, underline, italic and line breaks on the client side.
It will be finished next month when I am back. But i think I will not be able to post it here, as the dev is somehow gone and I heard you are not allowed to package and post modified mods of an existing mod.

Da.

Kindred

the rule is:

you can not post modified mods unless a mod author has
a) released the mod with a specific, Open Source, distributable license.
b) given permission in email or in the thread for individuals (or anyone) to release modified copies

If you have sufficiently re-written the code so that it is no longer the same mod (I think the rule of thumb is less than 10% original code?) then you can submit it to the mod site as your own, new mod. :)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

DaKrampus

Yeah, well I think there is more than 10% left. Cause you have to count all the parts that you cant really change, like the arrays to integrate into the admin etc...
and the loops populating the template, i dont really see what you can do differently.
The changes are in the core part: db (3 extra fields), the parsing of the post. And rewritten a new javascript. for the mouseover tooltip. But still I kept the var names.

Anyway I wouldnt have the time to give support.
So i wont post it.

the function up there is the key part anyway. and it is much faster than the original (at least if you have ~ 500 keywords.
the javascript is only needed if you want to change functionality. like parsing the bbcode clientside with jquery instead of doing it in the function. uses less ressources, because as it is it parses every message twice...

but to make a long story short. I'll just keep posting little functions to change for speeding it up.

Da

nixlike

Is there a working update for SMF 2.0.2 meanwhile or does anyone else have a solution to seriously come up with? If so - please do so!

Kindred

hmmm?  This seems to work just fine on 2.0.2. I have it installed and working on two sites.

DaKrampus has a nice update to the mod listed just above...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

nixlike

See my quote from above, thats the issue I'm running in. and of course its most probably because of some other mod installed but instead of dealing with other installed mods to get past that issue I'd rather lay down that glossary mod for good. I'll give it another try with the update from Krampus above, thank you Kindred :)

loplo

#426
Hey guys, just installed the mod but the "Add a new key word" is disappearing after half of second.
Is there a workaround?

LE
I've found out that when I'm clicking on the "Add a new keyword" with the middle mouse button, a new tab is being opened (normal) BUT the popup window is not disappearing anymore. Temporary workaround.

dimspace

#427
Well installed, made a couple of corrections, changed the database table details manually, all working, well, not working.

darned jquery conflicts, add glossary item popup dissapears after about 2 seconds, and the admin popup menu appears or doesnt appear depending on which browser you are using.

And then, doh, reading back through the pages, found my problem. Pretty Urls! :S (works with simplesef)

loplo

Good point, changed the SEF and now it works.
Now I have to check for any errors in case of incompatibility.

dimspace

sef works fine but needs all traces of pretty urls removed, which is proving a nightmare.

Kindred

sef is silly anyway
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

dimspace

Agree to an extent, although it makes things a bit tidier when tweeting links etc. i had to get rid of pretty urls at some point anyway, its a monolithic mess and slowdown, the database tables for it end up being extreme. This was a good excuse.

Only problem im now getting is when trying to create new entries
Duplicate entry '0' for key 'PRIMARY'

thats an easy fix though. :D

loplo

Is there a way to avoid the capitalization in the tooltip?

dimspace

Ok, working beautifully, but now i have a request that I need help with.

I run a cycling forum and as you can imagine we will be creating a huge glossary of terms, from race category descriptions, rider nicknames, cycling terms and a whole host of other things. For guests, and people new to cycling the tooltips will be a big feature, helping them understand the sport, however, for members who are experienced the tooltips could just be a pain and they would like the ability to turn them off.

Now in theory this is a simple process

1) add a column to the user database denoting tooltips on or off with a relevant settings entry to check a checkbox
2) tell the mod to look at the user reference for on/off rather than the global setting

Sounds simple, but although im learning php and my way around smf im not confident enough with it to approach such a task, but i imagine for someone with experience its a relatively easy coding change.

but that brings me onto the status of the mod,, and what is permissible as far as improvements or additions goes on existing mods. im not sure if we are allowed to add extra code to add extra functionality without the user permission, so I will ask for clarification on that before I go any further with that request. :D

Kindred

you can do just about anything you want to the code on your own server.
You can even share what you did with other users - so long as it is provided as "modify the package this way" so long as you are not distributing a fully modified package on your own.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

loplo

I've managed to fix for the time the capitalization in the tooltip, using text-transform:uppercase. Now the whole text is shown with capitals.
But I'm still looking for the piece of code that changes parts of the text.
Anyone?!

dimspace

Quote from: Kindred on February 05, 2013, 02:30:20 PM
you can do just about anything you want to the code on your own server.
You can even share what you did with other users - so long as it is provided as "modify the package this way" so long as you are not distributing a fully modified package on your own.

cool, i wanted to check.

im going to try and work it out myself (this could be amusing). If I cant then i may wave some $ around

dimspace

Well that was easier than I though.

I tested this and it appeared to work, but i am by no stretch of the imagination a competent coder, so it may be badly done, not work, delete all information from your hard drive, or lead to the complete and utter destruction of the world as we know it,  so dont take my word for it. ta. disclaimer ends

Add additional radio button to profiles (I added it to look and layout)

with the following details:
name: Glossary Tooltips
description: Select if you want to see mouseover tooltips on glossary words.
checkbox
default state checked

and then made the following edits;

in load.php

find
if ( !empty($modSettings['enable_tooltips']) )

replace with
if ( !empty($options['cust_glossa']) )

in display.php

find
//Run Glossary analyzer on the message
if ( $modSettings['enable_tooltips'] )


replace with
//Run Glossary analyzer on the message
if ( $options['cust_glossa'] )




tested, and user selection of wether to display tooltips works.

Now i just need to sort out the fact that enabling glossary has stopped my lightbox working :D

dimspace

Quote from: loplo on February 05, 2013, 02:46:59 PM
I've managed to fix for the time the capitalization in the tooltip, using text-transform:uppercase. Now the whole text is shown with capitals.
But I'm still looking for the piece of code that changes parts of the text.
Anyone?!

erm, text transform lowercase? maybe :S im not sure what you are trying to achieve

loplo

Let-s say you have in the glossary ARM and somewhere a definition containing the word army.
In the tooltip, the word army will appear as ARMy.

Advertisement: