Closed (fixed)
Project:
Glossary
Version:
6.x-1.6
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
5 Jan 2009 at 01:05 UTC
Updated:
3 Feb 2009 at 02:00 UTC
One concern I've had with the glossary module has been its propensity to cause term pages to link to themselves. I added a bit of code to have the module check on taxonomy term pages, and exclude the current erm from being included in its checks.
Here are the edits that were required. Towards the top of _glossary_filter_process I added these lines:
$current_term = 0;
if (strcmp(arg(0),'taxonomy') == 0 && strcmp(arg(1),'term') == 0 && arg(2) > 0) {
$current_term = arg(2);
}
A little further down, just inside the foreach loop for the $terms I added:
if ($current_term == $term->tid) continue;
That should do it. FWIW, here's the final function (which includes a check for FCKeditor usage and another display format, mentioned in other posts):
function _glossary_filter_process($format, $text) {
global $user;
if ($user->glossary_disable_indicator && variable_get('glossary_disable_indicator', FALSE)) {
return $text;
}
if (strcmp($_REQUEST['q'], 'fckeditor/xss') == 0) {
return $text;
}
$current_term = 0;
if (strcmp(arg(0),'taxonomy') == 0 && strcmp(arg(1),'term') == 0 && arg(2) > 0) {
$current_term = arg(2);
}
if (variable_get("glossary_vids_$format", 0)) {
$text = ' '. $text .' ';
$replace_mode = variable_get("glossary_replace_$format", 'superscript');
$link_style = variable_get("glossary_link_$format", 'normal');
$absolute_link = ($link_style == 'absolute');
$terms = _glossary_get_terms($format);
$vids = _glossary_get_filter_vids();
$terms_replace = array();
foreach ($terms as $term) {
// $term_title = strip_tags($term->description);
if ($current_term == $term->tid) continue;
$term_title = filter_xss($term->description);
$fragment = NULL;
if ($term->nodes > 0) {
$linkto = taxonomy_term_path($term);
}
elseif (!empty($vids) && (variable_get('glossary_click_option', 0) == 1)) {
if (variable_get('glossary_hide_if_empty', 1) && empty($term_title)) continue;
if (variable_get('glossary_page_per_letter', FALSE)) {
$linkto = 'glossary/'. $term->vid .'/letter'. drupal_strtolower(drupal_substr($term->name, 0, 1));
}
else {
$linkto = 'glossary/'. $term->vid;
}
$fragment = 'term'. $term->tid;
}
else {
$linkto = 'glossary/term/'. $term->tid;
}
$ins_before = $ins_after = NULL;
$term_class = variable_get('glossary_term_class', 'glossary-term');
// Let's try to get Drupal to show non-Latin letters right.
$linkto = decode_entities($linkto);
switch ($replace_mode) {
case 'superscript':
$ins_after = '<sup class="glossary-indicator" title="'. check_plain($term_title) .'">';
if ($link_style == 'none') {
$ins_after .= variable_get("glossary_superscript_$format", 'i');
}
else {
$ins_after .= l(variable_get("glossary_superscript_$format", 'i'), $linkto,
array('attributes' => array('title' => $term_title, 'class' => 'glossary-indicator'),
'fragment' => $fragment, 'absolute' => $absolute_link));
}
$ins_after .= '</sup>';
break;
case 'abbr':
if ($link_style == 'none') {
$ins_before .= '<span class="'. $term_class .'" title="'. $term_title .'"><'. $replace_mode .' title="'. $term_title .'">';
$ins_after .= '</'. $replace_mode .'></span>';
}
else {
$ins_before .= '<'. $replace_mode .' title="'. $term_title .'"><a class="'. $term_class .'" href="'. url($linkto, array('fragment' => $fragment, 'absolute' => $absolute_link)) .'">';
$ins_after .= '</a></'. $replace_mode .'>';
}
break;
// TODO: remove first case after a while.
case 'acronym link':
$replace_mode = 'acronym';
case 'acronym':
case 'cite':
case 'dfn':
if ($link_style == 'none') {
$ins_after .= '</'. $replace_mode .'>';
}
else {
$ins_before .= '<a class="glossary-term" href="'. url($linkto, array('fragment' => $fragment, 'absolute' => $absolute_link)) .'">';
$ins_after .= '</'. $replace_mode .'></a>';
}
$ins_before .= '<'. $replace_mode .' title="'. $term_title .'">';
break;
case 'hovertip':
if ($link_style == 'none') {
$ins_after .= '</span>';
}
else {
$ins_before = '<a class="'. $term_class .'" href="'.
url($linkto, array('fragment' => $fragment, 'absolute' => $absolute_link)) .'">';
$ins_after .= '</span></a>';
}
$ins_before .= '<span>';
$ins_after .= '<span class="hovertip">'. $term->image . $term_title .'</span>';
break;
case 'iconterm':
// Icon format, plus term link.
$img = '<img src="'. base_path() . variable_get("glossary_icon_$format", 'glossary.gif') ."\" />";
if ($link_style == 'none') {
$ins_after .= $img;
}
else {
$ins_before .= '<a class="glossary-term" href="'. url($linkto, array('fragment' => $fragment, 'absolute' => $absolute_link)) .'">';
$ins_after = $img . '</a>';
}
break;
default:
// Icon format.
$img = '<img src="'. base_path() . variable_get("glossary_icon_$format", 'glossary.gif') ."\" />";
if ($link_style == 'none') {
$ins_after .= $img;
}
else {
$ins_after = l($img, $linkto,
array('attributes' => array('title' => $term_title, 'class' => 'glossary-icon'),
'fragment' => $fragment, 'absolute' => $absolute_link, 'html' => TRUE));
}
break;
}
// Replace term and synonyms with the desired new HTML code.
$terms_replace[] = array(
'synonyms' => $term->synonyms,
'ins_before' => decode_entities($ins_before, array('"')),
'ins_after' => decode_entities($ins_after, array('"')),
);
}
return _glossary_insertlink($format, $text, $terms_replace);
}
return $text;
}
Comments
Comment #1
nancydruCommitted on both branches.