menu refactored
This commit is contained in:
parent
61077644cc
commit
69cf1b3a8b
75
index.pl
75
index.pl
@ -87,7 +87,7 @@ sub html_tag {
|
|||||||
sub soft_die {
|
sub soft_die {
|
||||||
print http_status(500,"text/html; charset=utf-8");
|
print http_status(500,"text/html; charset=utf-8");
|
||||||
print "<!DOCTYPE html>\n";
|
print "<!DOCTYPE html>\n";
|
||||||
print html_tag("html",html_tag("body",$site500));
|
print html_tag("html",html_tag("body",$site500.shift));
|
||||||
exit;
|
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 {
|
sub menu_item {
|
||||||
my $name = $_[0];
|
my $name = $_[0];
|
||||||
if ($_[0] =~ m/\//){$name = (split("/",$_[0]))[1]}
|
if ($_[0] =~ m/\//){$name = (split("/",$_[0]))[1]}
|
||||||
@ -215,32 +204,55 @@ sub render_menu {
|
|||||||
return $menu_content;
|
return $menu_content;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub submenu {
|
sub menu {
|
||||||
my $page = (split("/",shift(@_)))[1];
|
my $current_page = (split("/",shift))[1] ? (split("/",shift))[1] : "";
|
||||||
$page =~ s/_dir$//g;
|
$current_page =~ s/_dir$//g;
|
||||||
my @list = [];
|
my %menus = ();
|
||||||
opendir(DIR,$pages_dir.$page."_dir/") or return "";
|
# Handle main menu
|
||||||
while (my $file = readdir(DIR)) {
|
if (-e $data_dir."menucont") {
|
||||||
next if ($file =~ m/^\./);
|
open(MENUFILE, "<", $data_dir."menucont") or return "Problem accessing menu file:".$!;
|
||||||
push(@list,$page."_dir/".$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/^\./);
|
||||||
|
next if ($file =~ m/_dir$/);
|
||||||
|
push (@{$menus{"main"}}, $file);
|
||||||
|
}
|
||||||
|
close($dir);
|
||||||
}
|
}
|
||||||
closedir(DIR);
|
# Get any additional menus. currently supports 1 sub menu, eventually recursive
|
||||||
shift(@list);
|
if (-d $pages_dir.$current_page."_dir") {
|
||||||
return render_menu("sub",@list);
|
$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 {
|
sub page_template {
|
||||||
my $content = join("\n",@_);
|
my $content = join("\n",@_);
|
||||||
my $page_content = html_tag(
|
my $page_content = html_tag(
|
||||||
'div',
|
'div',
|
||||||
$content
|
$content
|
||||||
# For the main sites command prompt
|
|
||||||
# .html_tag('span'," ", {attribute=>'id', value=>"prompt"})
|
|
||||||
# .html_tag('span',"█", {attribute=>'class', value=>"cursor"})
|
|
||||||
,{attribute=>'id', value=>'screen'});
|
,{attribute=>'id', value=>'screen'});
|
||||||
$page_content .= render_menu("menu",getmenu()); #will need to me changed after menu refactor
|
$page_content .= menu(clean_input($request[4]));
|
||||||
# $page_content .= submenu(clean_input($request[4])); #comment this out if the site doesn't have submenus.
|
|
||||||
$page_content .= html_tag('div',"Murkfall.net",{attribute=>'id',value=>"footer"});
|
$page_content .= html_tag('div',"Murkfall.net",{attribute=>'id',value=>"footer"});
|
||||||
return $page_content;
|
return $page_content;
|
||||||
}
|
}
|
||||||
@ -255,9 +267,8 @@ sub build_page {
|
|||||||
render_logo($site_symbol).
|
render_logo($site_symbol).
|
||||||
page_template(@content).
|
page_template(@content).
|
||||||
include(@footer_includes),
|
include(@footer_includes),
|
||||||
#for the main site
|
)
|
||||||
# {attribute=>'onkeydown',value=>"HandleStroke(event)"}
|
);
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
build_page(clean_input($request[4]));
|
build_page(clean_input($request[4]));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user