Links need an access check
mstrelan - October 15, 2009 - 02:29
| Project: | footermap: a footer site map |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | mradcliffe |
| Status: | fixed |
Jump to:
Description
Users who cannot access links should not see them in the footermap. I don't particularly want to node_load each link though and that also won't work if there are links that are not to nodes.

#1
For some reason I can't patch against your file so here's the code to allow this.
(difference is global $user and node_access)
function footermap_get_menu($mlid,$level,$limit,&$mapref,$arrcnt,$avail_menus)
{
global $db_type;
global $user;
if( ($limit != 0 ) && ($level > $limit) )
return;
if (variable_get('sys_menus',0) == 0)
$add = " AND ml.module <> 'system' ";
else
$add = ' ';
if( module_exists('path') )
$r = db_query("SELECT ml.*, (SELECT ul.dst FROM {url_alias} ul WHERE src = ml.link_path) AS alias FROM {menu_links} ml WHERE ml.plid = %d AND ml.hidden <> -1".$add."ORDER BY ml.plid,ml.weight",$mlid)
or die(db_error());
else
$r = db_query("SELECT ml.* FROM {menu_links} ml WHERE ml.plid = %d AND ml.hidden <> -1".$add."ORDER BY ml.plid,ml.weight", $mlid)
or die(db_error());
while( $h = db_fetch_object($r) )
{
if (preg_match("/node\/(\d+)/",$h->link_path,$matches) == 1) {
$node = node_load($matches[1]);
if (!node_access('view', $node, $user)) {
continue;
}
}
$g = 0;
foreach ($avail_menus as $key=>$mn)
{
if ($mn == $h->menu_name)
{
$g = 1;
end;
}
}
if ($g == 1)
{
if ($node->status == 1 || !isset($node))
{
$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()
#2
I've done this in a slightly different way. I think that footermap should be based off of anonymous user rather than an authenticated user. Although I guess this breaks for extranet and intranet sites. It might look nicer if it was the same for all users rather than different dependent on the user.
Looks like another setting :(
#3
I've tested my implementation, and it works fine. However, there are some caveats.
1. Manually created menu items of course don't have any access requirements by default. So they'll always show up. This shouldn't be a problem as that can be controlled via block access (hopefully).
2. Manually created menu items to nodes. It looks a bit odd via the above issue because it works properly in footermap, but of course since primary links doesn't care, it's still in primary links or wherever that menu item exists. This is more of a core drupal quirk.
#4