function glossify_nodeapi in Glossify 5
Same name and namespace in other branches
- 6.3 glossify.module \glossify_nodeapi()
- 6 glossify.module \glossify_nodeapi()
File
- ./
glossify.module, line 62
Code
function glossify_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if (in_array($node->type, variable_get('glossify_content_types_to_search', node_get_types()))) {
// rendering the right type of node
drupal_add_css(drupal_get_path('module', 'glossify') . '/glossify.css');
$types = variable_get('glossify_glossary_content_type', NULL);
if (isset($types)) {
$glossify_style = variable_get('glossify_style', 'links');
foreach ($types as $type) {
// build WHERE clause
$clauseparts[] = 'type = "' . $type . '"';
}
$whereclause = implode(' OR ', $clauseparts);
$result = db_query('SELECT title, nid FROM {node} n WHERE ' . $whereclause);
while ($term = db_fetch_object($result)) {
//load the $glossary_term array
$glossary_term[$term->title] = $term->nid;
}
// endwhile looping through terms
switch ($op) {
case 'alter':
foreach (array_keys($glossary_term) as $term) {
$pattern = '/\\b(?<!\\"|\\/)' . $term . '\\b/';
switch ($glossify_style) {
case 'links':
$replacement = l($term, 'node/' . $glossary_term[$term], array(
'class' => 'glossify_term',
));
break;
case 'reference':
$replacement = '<span class="glossify_term">' . $term . '</span>';
break;
case 'hovertip':
default:
$replacement = '<span class="glossify_term hovertip_target" hovertip="' . $term . '">' . $term . '</span>';
break;
}
// endswitch glossify style
if (variable_get('glossify_teaser', TRUE)) {
$node->teaser = preg_replace($pattern, $replacement, $node->teaser, variable_get('glossify_link_first_only', true) ? 1 : -1);
}
if ($node->nid != $glossary_term[$term]) {
// don't link to myself
$node->body = preg_replace($pattern, $replacement, $node->body, variable_get('glossify_link_first_only', true) ? 1 : -1);
}
}
// endforeach looping through terms
break;
// done with $op = 'alter'
case 'view':
foreach (array_keys($glossary_term) as $term) {
if (preg_match('/' . $term . '/', $node->body)) {
// got one
switch ($glossify_style) {
case 'links':
break;
case 'reference':
$term_definition_list .= theme('glossify_term', $glossary_term[$term], $glossify_style);
case 'hovertip':
default:
$node->content['glossify'][$term] = array(
'#value' => theme('glossify_term', $glossary_term[$term], $glossify_style),
'#weight' => 10,
);
$node->content['glossify']['#weight'] = 10;
break;
}
// endswitch glossify style
}
// endif found a term to glossify
}
// endforeach looping through terms
if ($glossify_style == 'reference') {
// make reference section under the node
$node->content['glossify'] = array(
'#weight' => '10',
'#value' => theme('glossify_reference_section', $term_definition_list),
);
}
}
// endswitch $op
}
// endif there is a glossary type to search for
}
// if we're viewing an appropriate node
}