1 | #!/usr/bin/perl -w
|
---|
2 |
|
---|
3 | use CGI qw(:standard);
|
---|
4 |
|
---|
5 | my $image_generation_code_directory = "/research/mdewsnip/greenstone/image-generation";
|
---|
6 | my $images_directory = "/home/mdewsnip/public_html/greenstone/temp-images";
|
---|
7 | my $images_directory_url = "http://www.cs.waikato.ac.nz/~mdewsnip/greenstone/temp-images";
|
---|
8 |
|
---|
9 | print "Content-Type: text/html; charset=utf-8\n\n";
|
---|
10 | print start_html("Greenstone classifier image generation");
|
---|
11 | print "<h2>Greenstone classifier image generation</h2>";
|
---|
12 | print hr();
|
---|
13 |
|
---|
14 | # Language code and macrofile name
|
---|
15 | my $language = param("l") || "en.english";
|
---|
16 |
|
---|
17 | # Macro name (ASCII characters only)
|
---|
18 | my $macro_name = param("macro");
|
---|
19 | $macro_name =~ tr/a-zA-Z0-9//cd;
|
---|
20 |
|
---|
21 | # Image filename (ASCII characters only)
|
---|
22 | my $image_name = param("image");
|
---|
23 | $image_name =~ tr/a-zA-Z0-9//cd;
|
---|
24 |
|
---|
25 | my $text_unicode = param("text");
|
---|
26 | if (defined $macro_name && $macro_name ne "" && defined $image_name && $image_name ne "" && defined $text_unicode && $text_unicode ne "") {
|
---|
27 | my $language_code = (split(/\./, $language))[0];
|
---|
28 | my $macrofile_name = (split(/\./, $language))[1];
|
---|
29 |
|
---|
30 | my $language_modifier = "";
|
---|
31 | my $language_modifier_one = "";
|
---|
32 | my $image_directory = "";
|
---|
33 | my $translate_this = "";
|
---|
34 | unless ($language_code eq "en") {
|
---|
35 | $language_modifier = "[l=$language_code]";
|
---|
36 | $language_modifier_one = "l=$language_code,";
|
---|
37 | $image_directory = "$language_code/";
|
---|
38 | $translate_this = "# <b>Translate this!</b>";
|
---|
39 | }
|
---|
40 |
|
---|
41 | # Write a temporary macrofile containing the text for the images
|
---|
42 | $text_unicode_raw = $text_unicode; # May contain "\n" to split the green_title text
|
---|
43 | $text_unicode =~ s/\\n/ /g; # Replace any "\n" with " " for standard use
|
---|
44 | open(MACROFILE, ">$image_generation_code_directory/web-images.dm") || (print "Error: Could not open web-images.dm for writing.", end_html() && die);
|
---|
45 | print MACROFILE "\#\# \"" . $text_unicode . "\" \#\# nav_bar_button \#\# t$image_name \#\#\n\n";
|
---|
46 | print MACROFILE "\#\# \"" . $text_unicode_raw . "\" \#\# green_title \#\# h_$image_name \#\#\n\n";
|
---|
47 | close(MACROFILE);
|
---|
48 |
|
---|
49 | # Use ImageMagick via image generation scripts to make the images
|
---|
50 | `cd ..; source setup.bash; cd $image_generation_code_directory; make-images.pl -language_symbol $language_code -image_dir $images_directory web-images.dm; rm web-images.*`;
|
---|
51 |
|
---|
52 | # Get width of nav_bar_buttons
|
---|
53 | my $nav_bar_button_width = 87;
|
---|
54 | my $nav_bar_button_identification = `identify $images_directory/t${image_name}on.gif 2>&1`;
|
---|
55 | if ($nav_bar_button_identification =~ /t${image_name}on.gif \w+ (\d+)x(\d+)/) {
|
---|
56 | $nav_bar_button_width = $1;
|
---|
57 | }
|
---|
58 |
|
---|
59 | # Get width of green_titles
|
---|
60 | my $green_title_width = 200;
|
---|
61 | my $green_title_identification = `identify $images_directory/h_$image_name.gif 2>&1`;
|
---|
62 | if ($green_title_identification =~ /h_$image_name.gif \w+ (\d+)x(\d+)/) {
|
---|
63 | $green_title_width = $1;
|
---|
64 | }
|
---|
65 |
|
---|
66 | # Output result HTML
|
---|
67 | print "<p>Greenstone classifier images with text \"" . $text_unicode_raw . "\":";
|
---|
68 | print "<p><a href=\"$images_directory_url/t${image_name}on.gif\"><img src=\"$images_directory_url/t${image_name}on.gif\" border=\"0\" width=\"$nav_bar_button_width\" height=\"17\"></a>";
|
---|
69 | print "<p><a href=\"$images_directory_url/t${image_name}of.gif\"><img src=\"$images_directory_url/t${image_name}of.gif\" border=\"0\" width=\"$nav_bar_button_width\" height=\"17\"></a>";
|
---|
70 | print "<p><a href=\"$images_directory_url/t${image_name}gr.gif\"><img src=\"$images_directory_url/t${image_name}gr.gif\" border=\"0\" width=\"$nav_bar_button_width\" height=\"17\"></a>";
|
---|
71 | print "<p><a href=\"$images_directory_url/h_$image_name.gif\" style=\"color: #000000\"><img src=\"$images_directory_url/h_$image_name.gif\" border=\"1\" width=\"$green_title_width\" height=\"57\"></a>";
|
---|
72 | print "<p>\n";
|
---|
73 | print "These images should be put in the images/$image_directory folder of your Greenstone installation.\n";
|
---|
74 | print "<p>\n";
|
---|
75 | print "To get Greenstone to use the new images, some macros must be defined. Copy all the following text and paste it into the extra.dm file in Greenstone's \"macros\" directory:\n";
|
---|
76 | print "<p>\n";
|
---|
77 | print "<tt>\n";
|
---|
78 |
|
---|
79 | # base.dm macros
|
---|
80 | print "# <i>The following macros usually live in base.dm</i>\n";
|
---|
81 | print "<br>package Global\n";
|
---|
82 | print "<br>\n";
|
---|
83 | print "<br>_" . $macro_name . "width_ $language_modifier {_widtht" . $image_name . "x_ }\n";
|
---|
84 | print "<br>_image" . $macro_name . "_ $language_modifier {_gsimage_(_httpbrowse" . $macro_name . "_,_httpicont" . $image_name . "of_,_httpicont" . $image_name . "on_,$text_unicode,_textimage" . $macro_name . "_)}\n";
|
---|
85 | print "<br>_icontab" . $macro_name . "green_ $language_modifier {<img src=\"_httpicont" . $image_name . "gr_\" width=_widtht" . $image_name . "x_ border=0>}\n";
|
---|
86 | print "<br>_icontab" . $macro_name . "green_ [$language_modifier_one" . "v=1] {_texticontab" . $macro_name . "green_ }\n";
|
---|
87 | print "<p>\n";
|
---|
88 |
|
---|
89 | # document.dm macros
|
---|
90 | print "# <i>The following macros usually live in document.dm</i>\n";
|
---|
91 | print "<br>package document\n";
|
---|
92 | print "<br>\n";
|
---|
93 | print "<br>_text" . $macro_name . "page_ $language_modifier {_texticonh" . $image_name . "_}\n";
|
---|
94 | print "<br>_icon" . $macro_name . "page_ $language_modifier {<img src=\"_httpiconh" . $image_name . "_\" width=\"_widthh" . $image_name . "_\" height=\"_heighth" . $image_name . "_\">}\n";
|
---|
95 | print "<br>_icon" . $macro_name . "page_ [$language_modifier_one" . "v=1] {<h2>_texticonh" . $image_name . "_</h2>}\n";
|
---|
96 | print "<p>\n";
|
---|
97 |
|
---|
98 | # <language>.dm macros
|
---|
99 | print "# <i>The following macros usually live in $macrofile_name.dm</i>\n";
|
---|
100 | print "<br>package Global\n";
|
---|
101 | print "<br>\n";
|
---|
102 | print "<br>_textimage" . $macro_name . "_ $language_modifier {Browse by " . $text_unicode . "} $translate_this\n";
|
---|
103 | print "<br>_texticontab" . $macro_name . "green_ $language_modifier {\u$text_unicode}\n";
|
---|
104 | print "<br>\n";
|
---|
105 | print "<br>## \"$text_unicode\" ## nav_bar_button ## t" . $image_name . " ##\n";
|
---|
106 | print "<br>_httpicont" . $image_name . "gr_ $language_modifier {_httpimg_/$image_directory" . "t" . $image_name . "gr.gif}\n";
|
---|
107 | print "<br>_httpicont" . $image_name . "of_ $language_modifier {_httpimg_/$image_directory" . "t" . $image_name . "of.gif}\n";
|
---|
108 | print "<br>_httpicont" . $image_name . "on_ $language_modifier {_httpimg_/$image_directory" . "t" . $image_name . "on.gif}\n";
|
---|
109 | print "<br>_widtht" . $image_name . "x_ $language_modifier {$nav_bar_button_width}\n";
|
---|
110 |
|
---|
111 | print "<br>\n";
|
---|
112 | print "<br>package document\n";
|
---|
113 | print "<br>\n";
|
---|
114 | print "<br>_texticonh" . $image_name . "_ $language_modifier {\u$text_unicode}\n";
|
---|
115 | print "<br>\n";
|
---|
116 | print "<br>## \"$text_unicode\" ## green_title ## h_" . $image_name . " ##\n";
|
---|
117 | print "<br>_httpiconh" . $image_name . "_ $language_modifier {_httpimg_/$image_directory" . "h_" . $image_name . ".gif}\n";
|
---|
118 | print "<br>_widthh" . $image_name . "_ $language_modifier {$green_title_width}\n";
|
---|
119 | print "<br>_heighth" . $image_name . "_ $language_modifier {57}\n";
|
---|
120 |
|
---|
121 | print "<br>\n";
|
---|
122 | print "<br>package help\n";
|
---|
123 | print "<br>\n";
|
---|
124 | print "<br>_text" . $macro_name . "short_ $language_modifier {access publications by $text_unicode} $translate_this\n";
|
---|
125 | print "<br>_text" . $macro_name . "long_ $language_modifier {<p>You can <i>access publications by $text_unicode</i> by pressing the <i>" . $text_unicode . "</i> button. This brings up a list of " . $text_unicode . ". } $translate_this\n";
|
---|
126 | print "<br>\n";
|
---|
127 |
|
---|
128 | print "</tt>\n";
|
---|
129 | }
|
---|
130 | else {
|
---|
131 | print "<p>Error: parameter not defined.";
|
---|
132 | }
|
---|
133 |
|
---|
134 | print end_html();
|
---|