| 1 | package WebEditor::OldFeatures::MakeMenu; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use vars qw($VERSION); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | $VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/); | ||
| 6 | |||
| 7 | 0 | ▶ | use CGI qw(param); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | |||
| 9 | # XXX | ||
| 10 | # This module is untested for a long time. Probably the | ||
| 11 | # get_released_children calls should be rooted in $objdb instead of $root | ||
| 12 | # now. Also there's too much project specific stuff hardcoded to be | ||
| 13 | # useable as a general purpose module. | ||
| 14 | |||
| 15 | ###################################################################### | ||
| 16 | # | ||
| 17 | # create the menu | ||
| 18 | # | ||
| 19 | sub makemenu { | ||
| 20 | my $self = shift; | ||
| 21 | |||
| 22 | my $root = $self->Root; | ||
| 23 | my $objdb = $root->ObjDB; | ||
| 24 | my $c = $self->C; | ||
| 25 | |||
| 26 | require Template; | ||
| 27 | # create a dummy-menu: | ||
| 28 | my @lines; | ||
| 29 | my %menucolors = ("aussen","green", | ||
| 30 | "innen","red", | ||
| 31 | "company","blue"); | ||
| 32 | my $t = Template->new($self->Templateconf); | ||
| 33 | my $templatevars = $self->Templatevars; | ||
| 34 | foreach my $mnu (keys %menucolors) { | ||
| 35 | foreach my $lng (@{ $c->project->sitelanguages }) { | ||
| 36 | my @lines=(); | ||
| 37 | #traversemenu(0,\@lines,$lng); | ||
| 38 | my $outf = $c->paths->pubhtmldir."script/menuconfig_".$mnu."_".$lng.".js"; | ||
| 39 | $templatevars->{'bgcolor'} = $menucolors{$mnu}; | ||
| 40 | #### now the real work | ||
| 41 | my $fldr_id = $objdb->name_to_objid($mnu); | ||
| 42 | my @children = $root->get_released_children($fldr_id); | ||
| 43 | my $mcounter = 0; | ||
| 44 | foreach my $child (@children) { | ||
| 45 | next if (!$child->is_folder); | ||
| 46 | my $mtarget = ""; | ||
| 47 | if (defined $child->IndexDoc) { $mtarget = $child->IndexDoc }; | ||
| 48 | my $mtitle = $child->Title->get($lng); | ||
| 49 | push(@lines,"menu1.list.add('".$mtarget."',' > ".$mtitle."')\n"); | ||
| 50 | my @products = $root->get_released_children($child->Id); | ||
| 51 | #warn $products[0]; | ||
| 52 | if (@products > 0) {push(@lines," tmp = new MenuList(menu1,$mcounter,widchld)\n")} | ||
| 53 | foreach my $product (@products) { | ||
| 54 | next if (!$product->is_folder); | ||
| 55 | my $mtarget = ""; | ||
| 56 | if (defined $product->IndexDoc) { $mtarget = $product->IndexDoc }; | ||
| 57 | my $mtitle = $product->Title->get($lng); | ||
| 58 | push(@lines," tmp.list.add('".$mtarget."',' ".$mtitle."')\n"); | ||
| 59 | } | ||
| 60 | $mcounter++; | ||
| 61 | } | ||
| 62 | ### | ||
| 63 | $templatevars->{'lines'} = \@lines; | ||
| 64 | open (MENU, ">$outf") or error("cant writeopen $outf"); | ||
| 65 | $t->process($c->paths->we_site_templatebase."menuconfig_tpl.js", $self->Templatevars, \*MENU ) or error("Template process failed: ", $t->error, "\n"); | ||
| 66 | close MENU; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | my $outf = $c->paths->pubhtmldir."script/lookup.js"; | ||
| 70 | open (LOOKUP, ">$outf") or error("cant writeopen $outf"); | ||
| 71 | print LOOKUP 'var lookup = {'; | ||
| 72 | $self->traverselookup($objdb->root_object->Id); | ||
| 73 | print LOOKUP " aussen:[\"12\",\"aussen\"], innen:[\"18\",\"innen\"]}"; | ||
| 74 | close LOOKUP; | ||
| 75 | |||
| 76 | #XXX delete: $self->updatekeydb(); | ||
| 77 | ####### | ||
| 78 | # for the real menu: | ||
| 79 | # check each objects "VisibleToMenu", | ||
| 80 | # if an object appears in the menu at all | ||
| 81 | # | ||
| 82 | # check "IndexDoc" of each folder, | ||
| 83 | # which page will be the index.Page of this folder | ||
| 84 | # | ||
| 85 | # then yo'll probably have to create the JS-file | ||
| 86 | # "/html/nav_js/menuitems.js" | ||
| 87 | } | ||
| 88 | |||
| 89 | sub traverselookup { | ||
| 90 | my $self = shift; | ||
| 91 | |||
| 92 | my $root = $self->Root; | ||
| 93 | my $objdb = $self->ObjDB; | ||
| 94 | |||
| 95 | my $realid; | ||
| 96 | my $targetid; | ||
| 97 | my ($objid) = @_; | ||
| 98 | my @children = $objdb->children($objid); | ||
| 99 | #my @children = $root->get_released_children($objid); | ||
| 100 | foreach my $child (@children) { | ||
| 101 | if ($child->is_folder) { | ||
| 102 | if (defined $child->IndexDoc) { | ||
| 103 | $targetid = $child->IndexDoc; | ||
| 104 | } elsif ($root->get_released_children($child->Id)) { | ||
| 105 | my @cs = $root->get_released_children($child->Id); | ||
| 106 | if ($cs[0]) { | ||
| 107 | $targetid = $cs[0]->Version_Parent || "x"; | ||
| 108 | } else { | ||
| 109 | $targetid="x"; | ||
| 110 | } | ||
| 111 | } else { | ||
| 112 | $targetid="x"; | ||
| 113 | } | ||
| 114 | $realid = $child->Id; | ||
| 115 | } | ||
| 116 | my $chobj = $root->get_released_object($child->Id); | ||
| 117 | if ($chobj) { | ||
| 118 | $realid = $chobj->Version_Parent; | ||
| 119 | #my $realid = $child->Id; | ||
| 120 | $targetid = $realid; | ||
| 121 | |||
| 122 | } | ||
| 123 | print LOOKUP $realid.':["'.$targetid.'.html"'; | ||
| 124 | if ($root->can("get_section")) { | ||
| 125 | print LOOKUP ',"' . $root->get_section($child->Id) . '"'; | ||
| 126 | } | ||
| 127 | print LOOKUP '],'."\n"; | ||
| 128 | if ($child->is_folder) { | ||
| 129 | $self->traverselookup($child->Id); | ||
| 130 | } | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | sub traversemenu { | ||
| 135 | my ($self,$objid,$lines,$lang) = @_; | ||
| 136 | my $root = $self->Root; | ||
| 137 | my @children = $root->get_released_children($objid); | ||
| 138 | foreach my $child (@children) { | ||
| 139 | if ($child->is_folder) { | ||
| 140 | $self->traversemenu($child->Id,$lines,$lang); | ||
| 141 | } else { | ||
| 142 | push(@$lines,"<a href='html/$lang/".$child->Id.".html' target='main'>".$child->Id."</a><br>") | ||
| 143 | } | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | 1; | ||