View source
<?php
function theme_og_subgroups_menu_tree($group) {
og_subgroups_include('tree');
if (!($tree = og_subgroups_get_group_tree($group))) {
return NULL;
}
$treeview = variable_get('og_subgroups_block_use_treeview', 1);
$controls = variable_get('og_subgroups_block_use_treeview_controls', 1);
$ajax = variable_get('og_subgroups_block_use_treeview_ajax', 0);
if ($treeview) {
$path = drupal_get_path('module', 'og_subgroups');
drupal_add_css($path . '/theme/og_subgroups.css');
drupal_add_css($path . '/theme/jquery.treeview.css');
drupal_add_js($path . '/scripts/jquery.treeview.min.js');
$js_settings = array();
if ($controls) {
$js_settings[] = "control: '#og-subgroups-tree-controls-{$group->nid}'";
}
if ($ajax) {
$js_settings[] = "url: Drupal.settings.basePath + 'subgroups/tree/{$group->nid}'";
drupal_add_js($path . '/scripts/jquery.treeview.async.js');
}
drupal_add_js("\n \$(document).ready(function() {\n \$('ul.og-subgroups-menu-tree').treeview({ \n collapsed: true,\n animated: 'fast',\n " . (!empty($js_settings) ? implode(",\n\t", $js_settings) : '') . "\n });\n });\n ", 'inline');
}
$content .= "<div id=\"og-subgroups-tree-{$group->nid}\" class=\"og-subgroups-tree\">";
if ($treeview && $controls) {
$content .= "<div id=\"og-subgroups-tree-controls-{$group->nid}\" class=\"og-subgroups-tree-controls\">";
$content .= '<a title="' . t('Collapse the entire tree below') . '" href="#">' . t('Collapse') . '</a> | ';
$content .= '<a title="' . t('Expand the entire tree below') . '" href="#">' . t('Expand') . '</a>';
$content .= '</div>';
}
$parents = og_subgroups_get_group_parents($group);
$content .= "<ul id=\"og-subgroups-menu-tree-{$group->nid}\" class=\"og-subgroups-menu-tree\">";
if (!($treeview && $ajax)) {
foreach ($tree as $branch) {
if (empty($branch->children)) {
return NULL;
}
$content .= '<li class="open og-subgroups-tree-active-trail">';
$content .= theme('og_subgroups_menu_tree_link', $group, $branch);
if (!empty($branch->children)) {
$content .= '<ul>' . theme('og_subgroups_menu_tree_branch', $group, $branch->children, $parents) . '</ul>';
}
$content .= '</li>';
}
}
$content .= '</ul>';
$content .= '</div>';
return $content;
}
function theme_og_subgroups_menu_tree_branch($group, $branch, $parents) {
$content = '';
foreach ($branch as $stem) {
$class = array();
if ($group->nid == $stem->nid) {
$class[] = 'og-subgroups-tree-active-trail';
}
if (in_array($stem->nid, array_keys($parents))) {
$class[] = 'open';
$class[] = 'og-subgroups-tree-active-trail';
}
$content .= '<li' . (!empty($class) ? ' class="' . implode(" ", $class) . '"' : '') . '>' . theme('og_subgroups_menu_tree_link', $group, $stem);
if (!empty($stem->children)) {
$content .= '<ul>' . theme('og_subgroups_menu_tree_branch', $group, $stem->children, $parents) . '</ul>';
}
$content .= '</li>';
}
return $content;
}
function theme_og_subgroups_menu_tree_link($current, $group, $access = TRUE) {
if ($access) {
if (og_subgroups_mask_group($group)) {
return $group->title;
}
}
$link = array(
'title' => $group->title,
'href' => "node/{$group->nid}",
'options' => array(),
);
if ($current->nid == $group->nid) {
$link['options']['attributes']['class'] = 'og-subgroups-tree-active';
}
return l($link['title'], $link['href'], $link['options']);
}