Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: glossary.php
- ===================================================================
- --- glossary.php (revision 589602)
- +++ glossary.php (working copy)
- @@ -84,6 +84,16 @@
- }
- add_action('wp_print_styles', 'red_glossary_css');
- +// Sort longer titles first, so if there is collision between terms (e.g.,
- +// "essential fatty acid" and "fatty acid") the longer one gets created first.
- +function sortByWPQueryObjectTitleLength($a, $b) {
- + $sortVal = 0;
- + if (property_exists($a, 'post_title') && property_exists($b, 'post_title')) {
- + $sortVal = strlen($b->post_title) - strlen($a->post_title);
- + }
- + return $sortVal;
- +}
- +
- function red_glossary_parse($content){
- //Run the glossary parser
- @@ -97,6 +107,9 @@
- 'orderby' => 'title'
- ));
- + // Sort by title length (function above)
- + uasort($glossary_index, 'sortByWPQueryObjectTitleLength');
- +
- //the tag:[glossary_exclude]+[/glossary_exclude] can be used to mark text will not be taken into account by the glossary
- if ($glossary_index){
- $timestamp = time();
- @@ -262,6 +275,10 @@
- //old code bug-doesn't take into account href='' takes into account only href="")
- //$glossary_search = '/\b'.$glossary_title.'s*?\b(?=([^"]*"[^"]*")*[^"]*$)/i';
- $glossary_search = '/\b'.$glossary_title.'s*?\b(?=([^"]*"[^"]*")*[^"]*$)(?=([^\']*\'[^\']*\')*[^\']*$)/i';
- + // If protected tags option is turned on, make sure we're not replacing terms that are already in anchor tags (esp. anchor tags generated by another glossary term)
- + if (get_option('red_glossaryProtectedTags') == 1) {
- + $glossary_search = '/(?<!glossaryLink">)\b'.$glossary_title.'s*?\b(?=([^"]*"[^"]*")*[^"]*$)(?=([^\']*\'[^\']*\')*[^\']*$)(?!<\/a>)/i'; // PAR
- + }
- $glossary_replace = '<a'.$timestamp.'>$0</a'.$timestamp.'>';
- $origContent = $content;
- @@ -298,17 +315,17 @@
- }
- if (get_option('red_glossaryTermLink') == 1) {
- - $link_replace = '<span class="glossaryLink" title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . $glossaryItemContent . '\');" onmouseout="tooltip.hide();">$1</span>';
- + $link_replace = '<span title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . $glossaryItemContent . '\');" onmouseout="tooltip.hide();" class="glossaryLink">$1</span>';
- } else {
- - $link_replace = '<a class="glossaryLink" href="' . get_permalink($glossary_item) .'" title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . $glossaryItemContent . '\');" onmouseout="tooltip.hide();">$1</a>';
- + $link_replace = '<a href="' . get_permalink($glossary_item) .'" title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . $glossaryItemContent . '\');" onmouseout="tooltip.hide();" class="glossaryLink">$1</a>';
- }
- }
- else {
- if (get_option('red_glossaryTermLink') == 1) {
- - $link_replace = '<span class="glossaryLink" title="Glossary: '. $glossary_title . '">$1</span>';
- + $link_replace = '<span title="Glossary: '. $glossary_title . '" class="glossaryLink">$1</span>';
- } else {
- - $link_replace = '<a class="glossaryLink" href="' . get_permalink($glossary_item) . '" title="Glossary: '. $glossary_title . '">$1</a>';
- + $link_replace = '<a href="' . get_permalink($glossary_item) . '" title="Glossary: '. $glossary_title . '" class="glossaryLink">$1</a>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement