Customizing SMF > Modifications and Packages

Glossary

<< < (85/96) > >>

DaKrampus:

--- 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:


--- Code: ---'<span class=\"glossary\" title=\"".addslashes($definition)."\">$1</span>'",
--- End code ---

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 :)

--- End quote ---

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:
--- Code: ---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;
}

--- End code ---

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. :)

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...

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version