menu refactored

This commit is contained in:
bluesaxman 2019-05-03 11:54:39 -06:00
parent 61077644cc
commit 69cf1b3a8b

View File

@ -87,7 +87,7 @@ sub html_tag {
sub soft_die {
print http_status(500,"text/html; charset=utf-8");
print "<!DOCTYPE html>\n";
print html_tag("html",html_tag("body",$site500));
print html_tag("html",html_tag("body",$site500.shift));
exit;
}
@ -181,17 +181,6 @@ sub get_page {
}
}
############## Menu needs refactoring ###################
sub getmenu {
open(MENUFILE, "<", $data_dir."menucont") or return "There is no menu yet";
while(my $item = <MENUFILE>) {
push(@_,$item);
}
close(MENUFILE);
chomp @_;
@_;
}
sub menu_item {
my $name = $_[0];
if ($_[0] =~ m/\//){$name = (split("/",$_[0]))[1]}
@ -215,32 +204,55 @@ sub render_menu {
return $menu_content;
}
sub submenu {
my $page = (split("/",shift(@_)))[1];
$page =~ s/_dir$//g;
my @list = [];
opendir(DIR,$pages_dir.$page."_dir/") or return "";
while (my $file = readdir(DIR)) {
sub menu {
my $current_page = (split("/",shift))[1] ? (split("/",shift))[1] : "";
$current_page =~ s/_dir$//g;
my %menus = ();
# Handle main menu
if (-e $data_dir."menucont") {
open(MENUFILE, "<", $data_dir."menucont") or return "Problem accessing menu file:".$!;
while(my $item = <MENUFILE>) {
push(@{$menus{"main"}},$item);
}
close(MENUFILE);
chomp @{$menus{"main"}};
} else {
opendir(my $dir,$pages_dir) or return "Problem parsing the pages directory:".$!;
while (my $file = readdir($dir)) {
next if ($file =~ m/^\./);
push(@list,$page."_dir/".$file);
next if ($file =~ m/_dir$/);
push (@{$menus{"main"}}, $file);
}
closedir(DIR);
shift(@list);
return render_menu("sub",@list);
close($dir);
}
# Get any additional menus. currently supports 1 sub menu, eventually recursive
if (-d $pages_dir.$current_page."_dir") {
$menus{$current_page} = ();
opendir(my $dir,$pages_dir.$current_page."_dir") or return "Problem parsing the ".$current_page."_dir directory:".$!;
while (my $file = readdir($dir)) {
next if ($file =~ m/^\./);
next if ($file =~ m/_dir$/);
push (@{$menus{$current_page}}, $file);
}
close($dir);
}
my $buffer = "";
# main needs to be output first then the rest of the menus can be looped through
$buffer .= render_menu("main",@{$menus{"main"}});
delete($menus{"main"});
for my $menu_name (sort keys %menus) {
$buffer .= render_menu($menu_name,@{$menus{$menu_name}});
}
return $buffer;
}
######################### /menu ###########################
sub page_template {
my $content = join("\n",@_);
my $page_content = html_tag(
'div',
$content
# For the main sites command prompt
# .html_tag('span'," ", {attribute=>'id', value=>"prompt"})
# .html_tag('span',"&#9608", {attribute=>'class', value=>"cursor"})
,{attribute=>'id', value=>'screen'});
$page_content .= render_menu("menu",getmenu()); #will need to me changed after menu refactor
# $page_content .= submenu(clean_input($request[4])); #comment this out if the site doesn't have submenus.
$page_content .= menu(clean_input($request[4]));
$page_content .= html_tag('div',"Murkfall.net",{attribute=>'id',value=>"footer"});
return $page_content;
}
@ -255,9 +267,8 @@ sub build_page {
render_logo($site_symbol).
page_template(@content).
include(@footer_includes),
#for the main site
# {attribute=>'onkeydown',value=>"HandleStroke(event)"}
));
)
);
}
build_page(clean_input($request[4]));