/usr/share/bibledit-gtk/menus.pl is in bibledit-gtk-data 4.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | # Copyright (©) 2011 Peter von Kaehne.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use XML::LibXML;
use File::Path qw(make_path remove_tree);
use File::Copy;
use HTML::Tidy;
$file = `cat site.xml`;
my $tidy = HTML::Tidy->new(
{
output_xhtml => 1,
tidy_mark => 0,
indent => 1,
}
);
$parser = XML::LibXML->new();
$content = $parser->parse_string($file);
@pages = $content->getElementsByTagName("url");
my %menu = ();
# Creating and cleaning a list of all pages under a common path
## first create hashed list - this could be done better with a hash of anonymous arrays, but I do not understand them well enough
foreach (@pages) {
$menu{ ( $_->getElementsByTagName("dir") )[0]->textContent() } .=
( ( $_->getElementsByTagName("html") )[0]->getElementsByTagName("h1") )
[0]->textContent() . "AAAA"
. ( $_->getElementsByTagName("name") )[0]->textContent()."ZZZZ";
}
## then clean each list up
foreach $key ( keys %menu ) {
@value = split( "ZZZZ", $menu{$key} );
@value = sort (@value);
foreach (@value) {
@item = split( "AAAA", $_ );
$_ = "<li><a href=\"$item[1]\">$item[0]</a></li>";
}
$menu{$key} = join( "", @value );
$menu{$key} =~ s/href=\"[^"].*?\/([0-9,a-z,A-Z,-]+\.html)\"/href=\"$1\"/g;
}
# Build the page:
foreach (@pages) {
my $dir = ( $_->getElementsByTagName("dir") )[0]->textContent();
my $name = ( $_->getElementsByTagName("name") )[0]->textContent();
my $title = ( $_->getElementsByTagName("h1") )[0]->textContent();
my $index;
my $depth;
## calculating the page's depth
{ my $temp = $dir;
$temp =~ s/[^\/]//g;
$depth = '../' x length($temp);
}
## creating a path to the index page (home.html)
$index = "<li><a href=\"".$depth."home.html\">1 Bibledit</a></li>";
## identfiying and creating a link to the parent
my $parent;
if ( $dir eq "site" ) {
$parent = "";
}
else {
$parent = $dir;
$parent =~ s/.*?\/([a-z,A-Z,0-9,\-]+?)$/$1/;
$parent =
"<li><a href=\"../"
. $parent
. ".html\">"
. ucfirst($parent)
. "</a></li>";
}
## link to self
my $home = $name;
$home =~ s/[^\/]*\///g;
# list of children pages
$children = $name;
$children =~ s/\.html//;
if ( $menu{$children} ) {
$children = "<ul>" . $menu{$children} . "</ul>";
$children =~ s/href=\"/href=\"$home\//g;
$children =~ s/\.html\//\//g;
}
else {
$children = "";
}
# list of sibling pages
my $siblings =
$menu{ ( $_->getElementsByTagName("dir") )[0]->textContent() };
$siblings =~ s/$dir\///g;
$siblings =~ s/<a[^>]*?>$title<\/a>/$title.$children/e;
# creating a unified menu and appending it in the right place
my $menu = $index . $parent . "<hr/>" . $siblings;
if ($menu) {
( $_->getElementsByTagName("div") )[0]->appendWellBalancedChunk($menu);
}
# fix internal links
{ my @links = $_->getElementsByTagName("a");
foreach (@links) {
my $ref = $_->getAttribute("href");
$ref =~ s/SELFREFERENCE/$depth/;
$_->setAttribute("href",$ref);
}
}
# adding the license and a link to the stylesheet
( $_->getElementsByTagName("head") )[0]->appendWellBalancedChunk("<link href=\"".$depth."bibledit.css\" rel=\"stylesheet\" type=\"text/css\"\/>");
$license = `cat license`;
( $_->getElementsByTagName("head") )[0]->appendWellBalancedChunk($license);
}
# creating and writing the finalised page
foreach (@pages) {
my $dir = ( $_->getElementsByTagName("dir") )[0];
my $name = ( $_->getElementsByTagName("name") )[0];
my $html = ( $_->getElementsByTagName("html") )[0];
make_path( $dir->textContent() );
open FILE, ">", $name->textContent();
print FILE $tidy->clean( $html->toString() );
close FILE;
}
# putting the style sheet in the correct place
copy ("bibledit.css","site/bibledit.css");
|