function _lexicon_overview in Lexicon 7
Lexicon overview function that creates all the data end renders the output through the various theme templates.
1 call to _lexicon_overview()
- _lexicon_page in includes/
lexicon.pages.inc - Lexicon page callback function.
File
- includes/
lexicon.pages.inc, line 59 - Page callbacks for the Lexicon module
Code
function _lexicon_overview($vocab, $letter = NULL) {
$dest = drupal_get_destination();
$vid = $vocab->vid;
$path = variable_get('lexicon_path_' . $vid, 'lexicon/' . $vid);
$current_let = '';
$separate = variable_get('lexicon_separate_letters', FALSE);
$page_per_letter = variable_get('lexicon_page_per_letter', FALSE);
$show_description = variable_get('lexicon_show_description', FALSE);
$link_to_term_page = variable_get('lexicon_link_to_term_page', FALSE);
// If the Lexicon is configured to show one big list of terms, but there is a
// letter in the argument, return 404.
if (!$page_per_letter && $letter) {
return MENU_NOT_FOUND;
}
// Set the title if the terms are displayed per letter instead of in one big
// list if the Lexicon is configured to be split into multiple pages and there
// is a letter argument.
if ($page_per_letter && $letter) {
drupal_set_title(t('@title beginning with @let', array(
'@title' => t(variable_get('lexicon_title_' . $vid, $vocab->name)),
'@let' => drupal_strtoupper($letter),
)));
}
// Load the entire vocabulary with entities.
if (module_exists('i18n_taxonomy')) {
global $language;
$tree = i18n_taxonomy_get_tree($vid, $language->language, 0, NULL, TRUE);
}
else {
$tree = taxonomy_get_tree($vid, 0, NULL, TRUE);
}
// If i18n is installed and the vocabulary is localized, localize the terms.
if (function_exists('i18n_taxonomy_localize_terms')) {
$tree = i18n_taxonomy_localize_terms($tree);
}
// Since the tree might not be sorted alphabetically sort it.
uasort($tree, '_lexicon_tree_sort');
$lexicon_alphabar = NULL;
// If the overview is separated in sections per letter or the Lexicon is
// displayed spread over multiple pages per letter create the alphabar.
if ($separate || $page_per_letter) {
$lexicon_alphabar = _lexicon_alphabar($vid, $tree);
}
$lexicon_overview_sections = array();
$lexicon_introduction = NULL;
// Check if the Lexicon is spread over multiple pages per letter and if a
// letter argument is present.
if (!$letter) {
$introduction_text = variable_get('lexicon_introduction_' . $vid, NULL);
// Display the introduction text if it is set in the configuration.
if ($introduction_text['value'] != '') {
$lexicon_introduction = t(check_markup($introduction_text['value'], $introduction_text['format']));
}
}
if (!($page_per_letter && !$letter) || variable_get('lexicon_page_show_all', FALSE)) {
$lexicon_overview_items = '';
$lexicon_section = new stdClass();
if ($tree) {
$not_first = FALSE;
// Build up the list by iterating through all terms within the vocabulary.
foreach ($tree as $term) {
// If terms should not be marked if a term has no description continue
// with the next term.
if (!variable_get('lexicon_allow_no_description', FALSE) && empty($term->description)) {
continue;
}
// If we're looking for a single letter, see if this is it.
$term->let = drupal_strtolower(drupal_substr($term->name, 0, 1));
// If there is no letter argument or the first letter of the term equals
// the letter argument process the term.
if (!$letter || $term->let == $letter) {
// See if it's a new section.
if ($term->let != $current_let) {
if ($not_first) {
if ($separate) {
// Create the section output for the previous section.
$lexicon_overview_sections[] = theme('lexicon_overview_section', array(
'lexicon_section' => $lexicon_section,
'lexicon_overview_items' => $lexicon_overview_items,
));
// Clear the items to fill with the items of the new section.
$lexicon_overview_items = '';
}
}
if ($separate) {
$lexicon_section->letter = $term->let;
// Set the anchor id of the section used by the alphabar and
// linked terms. The anchor is as meaningful as possible
// ("letter"_$letter) for accessibility purposes.
$lexicon_section->id = 'letter_' . $lexicon_section->letter;
}
}
// Create the term output.
$term_output = _lexicon_term_add_info($term);
// Unset the description if it should not be shown.
if (!$show_description) {
unset($term_output->description);
unset($term_output->safe_description);
}
if ($link_to_term_page) {
$term_output->name = l($term_output->name, 'taxonomy/term/' . $term_output->tid);
$term_output->safe_name = $term_output->name;
}
$lexicon_overview_items .= theme('lexicon_overview_item', array(
'term' => $term_output,
));
$current_let = $term->let;
$not_first = TRUE;
}
}
// Create a section without anchor and heading if the Lexicon is not
// separated into sections per letter or if there are no items to display.
if (!$separate || $lexicon_overview_items == '') {
$lexicon_section = NULL;
}
// Create the last section output.
$lexicon_overview_sections[] = theme('lexicon_overview_section', array(
'lexicon_section' => $lexicon_section,
'lexicon_overview_items' => $lexicon_overview_items,
));
}
}
$lexicon_overview = new stdClass();
$lexicon_overview->voc_name = drupal_strtolower(_lexicon_create_valid_id($vocab->name));
$lexicon_overview->description = filter_xss($vocab->description);
$lexicon_overview->introduction = $lexicon_introduction;
if ($separate && variable_get('lexicon_go_to_top_link', FALSE) == TRUE) {
$lexicon_overview->go_to_top_link['name'] = t('Go to top');
$lexicon_overview->go_to_top_link['fragment'] = variable_get('lexicon_go_to_top_link_fragment', 'top');
$lexicon_overview->go_to_top_link['attributes'] = array(
'class' => array(
'lexicon_go_to_top_link',
),
);
}
$output = array(
'admin_links' => array(
'#prefix' => '<div class="lexicon-admin-links">',
'#links' => _lexicon_admin_links($vocab, $dest),
'#theme' => 'links',
'#suffix' => '</div>',
'#attributes' => array(
'class' => array(
'tabs',
),
),
),
'overview' => array(
'#lexicon_overview' => $lexicon_overview,
'#lexicon_alphabar' => $lexicon_alphabar,
'#lexicon_overview_sections' => $lexicon_overview_sections,
'#theme' => 'lexicon_overview',
),
);
return $output;
}