--- footermap.module 2008-07-22 11:22:06.000000000 +1000 +++ footermap.module.patched 2009-09-11 13:30:35.000000000 +1000 @@ -1,238 +1,239 @@ -' . t('Displays a sitemap at the bottom of the page.'); - break; - } - } // function footermap_help - - - /* - * Set settings path - * @return array an array of menu items - */ - function footermap_menu() - { - $items = array(); - - $items['admin/settings/footermap'] = array( - 'title' => 'footermap', - 'description' => t('Configure menu visibility for footermap'), - 'page callback' => 'drupal_get_form', - 'page arguments' => array('footermap_settings'), - 'access arguments' => array('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 menus - primary, secondary, and navigation menus'), - ); - - $primary_menus = footermap_get_primary_menus(); - - $form['avail_menus'] = array( - '#type' => 'checkboxes', - '#title' => t('Enabled Menus'), - '#default_value' => variable_get('avail_menus', array('primary-links','secondary-links','navigation')), - '#options' => $primary_menus, - '#description' => t('Select the menus you want visible.'), - ); - - $form['footer_cache'] = array( - '#type' => 'radios', - '#title' => t('Enable Caching:'), - '#default_value' => variable_get('footer_cache',0), - '#options' => array(t('Yes'),t('No')), - '#required' => '1', - '#description' => t('Enable caching of footermap (Recommended).'), - ); - - return system_settings_form($form); - } // function footermap_settings - - /* - * menu_link_alter hook -- clear the footer cache - * @param item item unused - * @param menu menu unused - */ - function footermap_menu_link_alter(&$item, $menu) - { - if (variable_get('footer_cache',0) == 0) - return; - $footercache = cache_get('footermap','cache'); - - $mlidregex = '/'.$item['mlid'].'/'; - - if ( preg_match($mlidregex,$footercache->data) == 0 ) - return; - // okay let's clear cache - - cache_clear_all('footermap','cache'); - - } // function footermap_menu_link_alter - - - /* - * 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? */ - - $mapref = array(); - $avail_menus = array(); - - - if (variable_get('footer_cache',0) == 0) - { - $vartime = cache_get('variables','cache')->created; - $o = cache_get('footermap','cache'); - } - if ( (isset($o->data)) && ($o->created >= $vartime) ) - return $o->data; - - unset($o); - - $tmp_menus = variable_get('avail_menus',array('primary-menu','secondary-menu','navigation')); - - foreach ($tmp_menus as $key=>$val) - if (! is_numeric($val)) - $avail_menus[$val] = $val; - - footermap_get_menu(variable_get('top_menu',variable_get('menu_primary_menu', 0)),1,variable_get('recurse_limit',0),$mapref,0,$avail_menus); - - foreach ( $mapref as $block ) - $o.= theme('links', $block, array('class' => 'links footermap-item')); - $o = "
\n".$o."\n
\n"; - - if (variable_get('footer_cache',0) == 0) - cache_set('footermap',$o,'cache',CACHE_TEMPORARY); - - return $o; - - } - - - /* - * Retrieve menu recursively - * @param mid menu_id - * @param level what level we are in the tree - * @param limit recurse limiter - * @param mapref array pointer - * @param arrcnt block counter. - * @param avail_menus visible menus. - */ - - function footermap_get_menu($mlid,$level,$limit,&$mapref,$arrcnt,$avail_menus) - { - if( ($limit != 0 ) && ($level > $limit) ) - return; - - if( $paths ) - $r = db_query("SELECT ml.*, coalesce(n.status,1) as nstatus, (SELECT ul.dst FROM {url_alias} ul WHERE src = ml.link_path) AS alias FROM {menu_links} ml LEFT OUTER JOIN {node} n ON substr(ml.link_path,6) = n.nid WHERE ml.plid = %d AND ml.module <> 'system' AND ml.hidden <> -1 ORDER BY ml.plid,ml.weight",$mlid) - or die(db_error()); - else - $r = db_query("SELECT ml.*, coalesce(n.status,1) as nstatus FROM {menu_links} ml LEFT OUTER JOIN {node} n ON substr(ml.link_path,6) = n.nid WHERE ml.plid = %d AND ml.module <> 'system' AND ml.hidden <> -1 ORDER BY ml.plid,ml.weight", $mlid) - or die(db_error()); - - while( $h = db_fetch_object($r) ) - { - $g = 0; - foreach ($avail_menus as $key=>$mn) - { - if ($mn == $h->menu_name) - { - $g = 1; - end; - } - } - - if ($g == 1) - { - if ($h->nstatus == 1) - { - $cur = 'menu-' . $h->mlid; - if( $h->alias ) - $mapref[$arrcnt][$cur][href] = $h->alias; - else - $mapref[$arrcnt][$cur][href] = $h->link_path; - - if( $h->link_path == "/" ) - $mapref[$arrcnt][$cur][href] = $base_url; - - $mapref[$arrcnt][$cur][title] = $h->link_title; - unset($cur); // let's unset $cur just in case. - } - - if( $h->has_children == 1 ) - { - footermap_get_menu($h->mlid, $level+1, $limit, $mapref, $arrcnt,array($h->menu_name => $h->menu_name)); - if( $level == 1 ) - $arrcnt++; - } - } - } - - } // function footermap_get_menu() - - - function footermap_get_primary_menus($topmenu = 0) - { - $ret = array(); - - if ( ! is_numeric($topmenu) ) // let's be careful - $topmenu = 0; - - $res = db_query("select distinct menu_name from {menu_links} where plid = %d and module <> 'system' and hidden <> -1", $topmenu); - - while ( $menu = db_fetch_object($res) ) - $ret[$menu->menu_name] = t($menu->menu_name); - - return($ret); - } // function footermap_get_primary_menus - +' . t('Displays a sitemap at the bottom of the page.'); + break; + } + } // function footermap_help + + + /* + * Set settings path + * @return array an array of menu items + */ + function footermap_menu() + { + $items = array(); + + $items['admin/settings/footermap'] = array( + 'title' => 'footermap', + 'description' => t('Configure menu visibility for footermap'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('footermap_settings'), + 'access arguments' => array('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 menus - primary, secondary, and navigation menus'), + ); + + $primary_menus = footermap_get_primary_menus(); + + $form['avail_menus'] = array( + '#type' => 'checkboxes', + '#title' => t('Enabled Menus'), + '#default_value' => variable_get('avail_menus', array('primary-links','secondary-links','navigation')), + '#options' => $primary_menus, + '#description' => t('Select the menus you want visible.'), + ); + + $form['footer_cache'] = array( + '#type' => 'radios', + '#title' => t('Enable Caching:'), + '#default_value' => variable_get('footer_cache',0), + '#options' => array(t('Yes'),t('No')), + '#required' => '1', + '#description' => t('Enable caching of footermap (Recommended).'), + ); + + return system_settings_form($form); + } // function footermap_settings + + /* + * menu_link_alter hook -- clear the footer cache + * @param item item unused + * @param menu menu unused + */ + function footermap_menu_link_alter(&$item, $menu) + { + if (variable_get('footer_cache',0) == 0) + return; + $footercache = cache_get('footermap','cache'); + + $mlidregex = '/'.$item['mlid'].'/'; + + if ( preg_match($mlidregex,$footercache->data) == 0 ) + return; + // okay let's clear cache + + cache_clear_all('footermap','cache'); + + } // function footermap_menu_link_alter + + + /* + * 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? */ + + $mapref = array(); + $avail_menus = array(); + + + if (variable_get('footer_cache',0) == 0) + { + $vartime = cache_get('variables','cache')->created; + $o = cache_get('footermap','cache'); + } + if ( (isset($o->data)) && ($o->created >= $vartime) ) + return $o->data; + + unset($o); + + $tmp_menus = variable_get('avail_menus',array('primary-menu','secondary-menu','navigation')); + + foreach ($tmp_menus as $key=>$val) + if (! is_numeric($val)) + $avail_menus[$val] = $val; + + footermap_get_menu(variable_get('top_menu',variable_get('menu_primary_menu', 0)),1,variable_get('recurse_limit',0),$mapref,0,$avail_menus); + + foreach ( $mapref as $block ) + $o.= theme('links', $block, array('class' => 'links footermap-item')); + $o = "
\n".$o."\n
\n"; + + if (variable_get('footer_cache',0) == 0) + cache_set('footermap',$o,'cache',CACHE_TEMPORARY); + + return $o; + + } + + + /* + * Retrieve menu recursively + * @param mid menu_id + * @param level what level we are in the tree + * @param limit recurse limiter + * @param mapref array pointer + * @param arrcnt block counter. + * @param avail_menus visible menus. + */ + + function footermap_get_menu($mlid,$level,$limit,&$mapref,$arrcnt,$avail_menus) + { + if( ($limit != 0 ) && ($level > $limit) ) + return; + + if( $paths ) + $r = db_query("SELECT ml.*, coalesce(n.status,1) as nstatus, (SELECT ul.dst FROM {url_alias} ul WHERE src = ml.link_path) AS alias FROM {menu_links} ml LEFT OUTER JOIN {node} n ON substr(ml.link_path,6) = n.nid WHERE ml.plid = %d AND ml.module <> 'system' AND ml.hidden <> -1 ORDER BY ml.plid,ml.weight",$mlid) + or die(db_error()); + else + $r = db_query("SELECT ml.*, coalesce(n.status,1) as nstatus FROM {menu_links} ml LEFT OUTER JOIN {node} n ON substr(ml.link_path,6) = n.nid WHERE ml.plid = %d AND ml.module <> 'system' AND ml.hidden <> -1 ORDER BY ml.plid,ml.weight", $mlid) + or die(db_error()); + + while( $h = db_fetch_object($r) ) + { + $g = 0; + foreach ($avail_menus as $key=>$mn) + { + if ($mn == $h->menu_name) + { + $g = 1; + end; + } + } + + if ($g == 1) + { + if ($h->nstatus == 1) + { + $cur = 'menu-' . $h->mlid; + if( $h->alias ) + $mapref[$arrcnt][$cur][href] = $h->alias; + else + $mapref[$arrcnt][$cur][href] = $h->link_path; + + if( $h->link_path == "/" ) + $mapref[$arrcnt][$cur][href] = $base_url; + + $mapref[$arrcnt][$cur][title] = $h->link_title; + unset($cur); // let's unset $cur just in case. + } + + if( $h->has_children == 1 ) + { + footermap_get_menu($h->mlid, $level+1, $limit, $mapref, $arrcnt,array($h->menu_name => $h->menu_name)); + } + if( $level == 1 ) + $arrcnt++; + + } + } + + } // function footermap_get_menu() + + + function footermap_get_primary_menus($topmenu = 0) + { + $ret = array(); + + if ( ! is_numeric($topmenu) ) // let's be careful + $topmenu = 0; + + $res = db_query("select distinct menu_name from {menu_links} where plid = %d and module <> 'system' and hidden <> -1", $topmenu); + + while ( $menu = db_fetch_object($res) ) + $ret[$menu->menu_name] = t($menu->menu_name); + + return($ret); + } // function footermap_get_primary_menus +