Advertisement
Guest User

enhanced-tooltipglossary_v1.1_multi-word-terms.patch

a guest
Aug 23rd, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Index: glossary.php
  2. ===================================================================
  3. --- glossary.php (revision 589602)
  4. +++ glossary.php (working copy)
  5. @@ -84,6 +84,16 @@
  6. }
  7. add_action('wp_print_styles', 'red_glossary_css');
  8.  
  9. +// Sort longer titles first, so if there is collision between terms (e.g.,
  10. +// "essential fatty acid" and "fatty acid") the longer one gets created first.
  11. +function sortByWPQueryObjectTitleLength($a, $b) {
  12. + $sortVal = 0;
  13. + if (property_exists($a, 'post_title') && property_exists($b, 'post_title')) {
  14. + $sortVal = strlen($b->post_title) - strlen($a->post_title);
  15. + }
  16. + return $sortVal;
  17. +}
  18. +
  19. function red_glossary_parse($content){
  20.  
  21. //Run the glossary parser
  22. @@ -97,6 +107,9 @@
  23. 'orderby' => 'title'
  24. ));
  25.  
  26. + // Sort by title length (function above)
  27. + uasort($glossary_index, 'sortByWPQueryObjectTitleLength');
  28. +
  29. //the tag:[glossary_exclude]+[/glossary_exclude] can be used to mark text will not be taken into account by the glossary
  30. if ($glossary_index){
  31. $timestamp = time();
  32. @@ -262,6 +275,10 @@
  33. //old code bug-doesn't take into account href='' takes into account only href="")
  34. //$glossary_search = '/\b'.$glossary_title.'s*?\b(?=([^"]*"[^"]*")*[^"]*$)/i';
  35. $glossary_search = '/\b'.$glossary_title.'s*?\b(?=([^"]*"[^"]*")*[^"]*$)(?=([^\']*\'[^\']*\')*[^\']*$)/i';
  36. + // 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)
  37. + if (get_option('red_glossaryProtectedTags') == 1) {
  38. + $glossary_search = '/(?<!glossaryLink">)\b'.$glossary_title.'s*?\b(?=([^"]*"[^"]*")*[^"]*$)(?=([^\']*\'[^\']*\')*[^\']*$)(?!<\/a>)/i';
  39. + }
  40. $glossary_replace = '<a'.$timestamp.'>$0</a'.$timestamp.'>';
  41.  
  42. $origContent = $content;
  43. @@ -298,17 +315,17 @@
  44. }
  45.  
  46. if (get_option('red_glossaryTermLink') == 1) {
  47. - $link_replace = '<span class="glossaryLink" title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . $glossaryItemContent . '\');" onmouseout="tooltip.hide();">$1</span>';
  48. + $link_replace = '<span title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . $glossaryItemContent . '\');" onmouseout="tooltip.hide();" class="glossaryLink">$1</span>';
  49. } else {
  50. - $link_replace = '<a class="glossaryLink" href="' . get_permalink($glossary_item) .'" title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . $glossaryItemContent . '\');" onmouseout="tooltip.hide();">$1</a>';
  51. + $link_replace = '<a href="' . get_permalink($glossary_item) .'" title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . $glossaryItemContent . '\');" onmouseout="tooltip.hide();" class="glossaryLink">$1</a>';
  52. }
  53.  
  54. }
  55. else {
  56. if (get_option('red_glossaryTermLink') == 1) {
  57. - $link_replace = '<span class="glossaryLink" title="Glossary: '. $glossary_title . '">$1</span>';
  58. + $link_replace = '<span title="Glossary: '. $glossary_title . '" class="glossaryLink">$1</span>';
  59. } else {
  60. - $link_replace = '<a class="glossaryLink" href="' . get_permalink($glossary_item) . '" title="Glossary: '. $glossary_title . '">$1</a>';
  61. + $link_replace = '<a href="' . get_permalink($glossary_item) . '" title="Glossary: '. $glossary_title . '" class="glossaryLink">$1</a>';
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement