function glossary_block_view in Glossary 7
Implements hook_block_view().
File
- ./
glossary.module, line 1331 - Glossary terms will be automatically marked with links to their descriptions.
Code
function glossary_block_view($delta) {
switch ($delta) {
case 'glossary-search':
$blocks['subject'] = t('Search Glossary');
$content = drupal_get_form('glossary_search_form');
// $blocks['content'] = drupal_get_form('glossary_search_form');
$blocks['content'] = drupal_render($content);
return $blocks;
case 'glossary-random':
$interval = variable_get("glossary_block_{$delta}_interval", 0) * variable_get("glossary_block_{$delta}_step", 0);
$last = variable_get("glossary_block_{$delta}_last", 0);
if ($last + $interval < REQUEST_TIME) {
// Time to get a new selection.
$saved_vids = variable_get("glossary_block_{$delta}_vids", NULL);
if (is_null($saved_vids)) {
$blocks['content'] = t('Glossary block !blk has not been configured.', array(
'!blk' => $delta,
));
return $blocks;
}
$vids = array_filter($saved_vids);
if (count($vids) == 0) {
$vids = _glossary_get_filter_vids();
}
$tid = db_query_range('SELECT tid FROM {taxonomy_term_data} WHERE vid in (:vids) ORDER BY RAND()', 0, 1, array(
':vids' => $vids,
))
->fetchField();
// Set now as the last selection and save that tid.
variable_set("glossary_block_{$delta}_last", REQUEST_TIME);
variable_set("glossary_block_{$delta}_tid", $tid);
}
else {
// Get the current selected tid.
$tid = variable_get("glossary_block_{$delta}_tid", 0);
}
$term = taxonomy_term_load($tid);
$blocks['content'] = theme('glossary_block_term', array(
'0' => $term,
'1' => variable_get("glossary_block_{$delta}_link", TRUE),
));
return $blocks;
}
}