Trying to fix unsupported glossary plugin
-
I’ve tried a dozen other glossary plugins, and all of them seem to mess up somewhere.
This plugin is called tooltipglossary
It is designed to search for glossary words in the text, and replace them with links to the same word in the glossary.
One problem is, when the keyword is found within another link, it still tries to replace it.
So if I have a glossary term for “co-dominant” and “Dominant” then it replaces them twice. (Depending on which is processed first)
Second, it will change a URL, if the url contains the glossary term.
<a class="glossaryLink" href="https://nwreptiles.com/glossary/codominant/" title="Glossary: Co-Dominant">co-<a class="glossaryLink" href="https://nwreptiles.com/glossary/dominant/" title="Glossary: Dominant">dominant</a></a>
I’ve already made a mod to where it prioritizes the term with the most recent modification date, first, (Ideally it should be the longest terms first) but I really need to tell it not to parse anything within ““, “<img>” or between tags. It would be wise to exclude between <script> tags as well.
Here is partial code from the add-in
foreach($glossary_index as $glossary_item){ $timestamp++; $glossary_title = $glossary_item->post_title; $glossary_search = '/\b'.$glossary_title.'s*?\b(?=([^"]*"[^"]*")*[^"]*$)/i'; $glossary_replace = '<a'.$timestamp.'>$0</a'.$timestamp.'>'; if (get_option('red_glossaryFirstOnly') == 1) { $content_temp = preg_replace($glossary_search, $glossary_replace, $content, 1); } else { $content_temp = preg_replace($glossary_search, $glossary_replace, $content); } $content_temp = rtrim($content_temp); $link_search = '/<a'.$timestamp.'>('.$glossary_item->post_title.'[A-Za-z]*?)<\/a'.$timestamp.'>/i'; if (get_option('red_glossaryTooltip') == 1) { $link_replace = '<a class="glossaryLink" href="' . get_permalink($glossary_item) . '" title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . addslashes($glossary_item->post_content) . '\');" onmouseout="tooltip.hide();">$1</a>'; }else { $link_replace = '<a class="glossaryLink" href="' . get_permalink($glossary_item) . '" title="Glossary: '. $glossary_title . '">$1</a>'; } $content_temp = preg_replace($link_search, $link_replace, $content_temp); $content = $content_temp; }
I am getting a bit lost in this one.
- The topic ‘Trying to fix unsupported glossary plugin’ is closed to new replies.