You are here

footermap.module in footermap: a footer site map 5

File

footermap.module
View source
<?php

/* $Id */

/*
 * @file
 * This module queries the menu for pages and makes a dynamic
 * sitemap at the bottom of the page.
 *
 * copyright Matthew Radcliffe, Kosada Inc.
 *
 */

/*
 * Display help and module information
 * @param section which sectino of the site we're displaying
 * @return help text for section
 */
function footermap_help($section = '') {
  $output = '';
  switch ($section) {
    case "admin/modules#description":
      $output = t("Displays a sitemap at the bottom of the page");
      break;
  }
  return $output;
}

// function footermap_help

/*
 * Valid permissions for this module
 * @return array An array of valid permissions for this module
 */
function footermap_perm() {
  return array(
    'access content',
  );
}

// function footermap_perm

/*
 * Set settings path
 * @return array an array of menu items
 */
function footermap_menu() {
  $items = array();
  $items[] = array(
    'path' => 'admin/settings/footermap',
    'title' => t('Footermap'),
    'description' => t('Change recurse limit or specify top menu id'),
    'callback' => 'drupal_get_form',
    'callback arguments' => array(
      'footermap_settings',
    ),
    'access' => user_access('administer site configuration'),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

// function footermap_menu

/* 
 * Setup settings form for footermap
 * @return array an array of forms
 */
function footermap_settings() {
  $form['recurse_limit'] = array(
    '#type' => 'textfield',
    '#title' => t('Recurse Limit'),
    '#default_value' => variable_get('recurse_limit', 0),
    '#size' => 3,
    '#maxlength' => 3,
    '#description' => t('Set the # of times to recurse through a particular menu.  Default is 0, unlimited.'),
  );
  $form['top_menu'] = array(
    '#type' => 'textfield',
    '#title' => t('Top Menu'),
    '#default_value' => variable_get('top_menu', variable_get('menu_primary_menu', 0)),
    '#size' => 3,
    '#maxlength' => 3,
    '#description' => t('Set the menu id to use as the top level.  Default is to start at 0 i.e. primary links.'),
  );
  $form['menu_headers'] = array(
    '#type' => 'radios',
    '#title' => t('Menu Headers'),
    '#default_value' => variable_get('menu_headers', 0),
    '#options' => array(
      t('Yes'),
      t('No'),
    ),
    '#required' => '1',
    '#description' => t('Display menu block headers in the footer site map.'),
  );
  return system_settings_form($form);
}

// function footermap_settings

/*
 * Declare footer hook
 * @return string A string containing HTML to be inserted
 */
function footermap_footer($main = 0) {

  /* base mid changed to '0' in 5.x? */

  /* is there a way of getting this dynamically in 4.x and 5.x consistently? */
  $o = "";
  $o .= "<div class=\"footermap\">\n";
  $x = footermap_get_menu(variable_get('top_menu', variable_get('menu_primary_menu', 0)), 1, 0, $o, variable_get('recurse_limit', 0));
  $o = preg_replace("/&#xb7; (\\S+)\$/", "\$1", $o);

  /* get rid of trailing shit :v */
  $o .= "</div>\n";
  return $o;
}

/*
 * Retrieve menu recursively
 * @param mid menu_id
 * @param level what level we are in the tree
 * @param hastree has sub menus
 * @param temp reference to a string to output
 * @return boolean a boolean to tell whether or not to carraige return
 */
function footermap_get_menu($mid, $level, $hastree, &$temp, $limit) {
  if ($limit != 0 && $level > $limit) {
    return 0;
  }

  /* if( $level > 1 ) { $tab = $level * 5; }
     else { $tab = 1; } */

  /* left over from some tabbing experiment i did.  leaving it alone for now */
  $a = 0;
  if ($paths) {
    $r = db_query("SELECT menu.*, (SELECT dst FROM url_alias WHERE src = menu.path) AS alias FROM menu WHERE pid = {$mid} ORDER BY pid,weight") or die(db_error());
  }
  else {
    $r = db_query("SELECT * FROM menu WHERE pid = {$mid} ORDER BY pid,weight") or die(db_error());
  }
  while ($h = db_fetch_object($r)) {
    if ($level == 2) {
      $a = 1;
    }
    if ($h->alias) {
      $h->path = $h->alias;
    }
    if ($h->path == "/") {
      $h->path = $base_url;
    }
    else {
      if (preg_match("/^http|www|gopher|https|mailto|ftp|file|news/", $h->path) == 0 && $h->path != "") {

        /* we need not match external links */
        $h->path = base_path() . $h->path;
      }
      else {
      }
    }
    if ($level > 1 && $h->path != "" && dechex($h->type) % 10 != 0) {
      $temp .= "\t<span class=\"footermap-item\"><a href=\"{$h->path}\">{$h->title}</a> &#xb7; </span>";
    }
    else {
      if ($h->path != "" && dechex($h->type) % 10 != 0) {
        $temp .= "<span class=\"footermap-submenu\"><a href=\"{$h->path}\">{$h->title}</a> &#xb7; </span>";
      }
      else {
        if (variable_get('menu_headers', 0) == 0 && dechex($h->type) % 10 != 0) {
          $temp .= "<span>{$h->title} &#xb7;</span>";
        }
      }
    }
    $i = footermap_get_menu($h->mid, $level + 1, $a, $temp, $limit);
    if ($i > 0) {

      /* let's make this consistant with drupal-4-7, is it ok? */
      $temp .= "<br>\n";
      $temp = preg_replace("/&#xb7; (\\S+)\$/", "\$1", $temp);
    }
  }
  return $a;
}

// function footermap_get_menu()