Bump. I’m trying to debug this too…
Say we’ve defined the word “TERM”, and we have this in our post:
This term has a busy schedule here's a <a href="wherever" title="Term schedule">link</a>
This will get completely screwed up and try to put a tooltip over the word “Term” in the “title=” tag.
Hi
I’ve made a “big” updateon the code, but I’ve lost some functionalities :
– only the first instance is linked
– any links on H1, H2, H3, H4, H5, H6, links, attributes, etc.
I picked up the code in another plugin and i’ve adapted it.
function red_glossary_parse($content){
//Run the glossary parser
if (((!is_page() && get_option('red_glossaryOnlySingle') == 0) OR
(!is_page() && get_option('red_glossaryOnlySingle') == 1 && is_single()) OR
(is_page() && get_option('red_glossaryOnPages') == 1))){
$glossary_index = get_children(array(
'post_type' => 'glossary',
'post_status' => 'publish',
'order' => 'DESC',
'orderby' => 'title'
));
if ($glossary_index){
$timestamp = time();
foreach($glossary_index as $glossary_item) {
$find = '/'.$glossary_item->post_title.'/i';
$titlefind= $glossary_item->post_title;
$isFind = false;
$matches = array();
preg_match_all($find, $content, $matches, PREG_OFFSET_CAPTURE);
$matchData = $matches[0];
$noChanges = array(
'/<h[1-6][^>]*>[^<]*'.$glossary_item->post_title.'[^<]*<\/h[1-6]>/i',
'/<a[^>]+>[^<]*'.$glossary_item->post_title.'[^<]*<\/a>/i',
'/href=("|\')[^"\']+'.$glossary_item->post_title.'(.*)[^"\']+("|\')/i',
'/src=("|\')[^"\']*'.$glossary_item->post_title.'[^"\']*("|\')/i',
'/alt=("|\')[^"\']*'.$glossary_item->post_title.'[^"\']*("|\')/i',
'/title=("|\')[^"\']*'.$glossary_item->post_title.'[^"\']*("|\')/i',
'/content=("|\')[^"\']*'.$glossary_item->post_title.'[^"\']*("|\')/i',
'/<script[^>]*>[^<]*'.$glossary_item->post_title.'[^<]*<\/script>/i',
'/<embed[^>]+>[^<]*'.$glossary_item->post_title.'[^<]*<\/embed>/i',
'/wmode=("|\')[^"\']*'.$glossary_item->post_title.'[^"\']*("|\')/i'
);
foreach($noChanges as $noChange){
$results = array();
preg_match_all($noChange, $content, $results, PREG_OFFSET_CAPTURE);
$matches = $results[0];
if(!count($matches) == 0) {
foreach($matches as $match){
$start = $match[1];
$end = $match[1] + strlen($match[0]);
foreach($matchData as $index => $data){
if($data[1] >= $start && $data[1] <= $end){
$matchData[$index][2] = true;
}
}
}
}
}
foreach($matchData as $index => $match){
if($match[2] != true){
$isFind = $match;
break;
}
}
if(is_array($isFind)){
$replacement = '<a class="glossaryLink" href="'.get_permalink($glossary_item).'"';
$replacement = $replacement.'title="Glossary : '.$titlefind.'" >'.$isFind[0].'</a>';
$content = substr($content, 0, $isFind[1]) . $replacement . substr($content, $isFind[1] + strlen($isFind[0]));
}
}
}
}
return $content;
}
You have to modify the code to insert the tooltips ehanced version…
With this code, you’ll have never links on :
– links
– alt, title, src, href attribute
– H1 … H6
– script, embed
But you’ll have only ONE link for each term on each page/article, and you will not have ehanced tooltips.
It works on 3.0.5 version of WordPress 🙂
And excuse me for my bad english ^_^