#!/usr/bin/perl -w use CGI qw(:standard); my $image_generation_code_directory = "/research/mdewsnip/greenstone/image-generation"; my $images_directory = "/home/mdewsnip/public_html/greenstone/temp-images"; my $images_directory_url = "http://www.cs.waikato.ac.nz/~mdewsnip/greenstone/temp-images"; print "Content-Type: text/html; charset=utf-8\n\n"; print start_html("Greenstone classifier image generation"); print "

Greenstone classifier image generation

"; print hr(); # Language code and macrofile name my $language = param("l") || "en.english"; # Macro name (ASCII characters only) my $macro_name = param("macro"); $macro_name =~ tr/a-zA-Z0-9//cd; # Image filename (ASCII characters only) my $image_name = param("image"); $image_name =~ tr/a-zA-Z0-9//cd; my $text_unicode = param("text"); if (defined $macro_name && $macro_name ne "" && defined $image_name && $image_name ne "" && defined $text_unicode && $text_unicode ne "") { my $language_code = (split(/\./, $language))[0]; my $macrofile_name = (split(/\./, $language))[1]; my $language_modifier = ""; my $language_modifier_one = ""; my $image_directory = ""; my $translate_this = ""; unless ($language_code eq "en") { $language_modifier = "[l=$language_code]"; $language_modifier_one = "l=$language_code,"; $image_directory = "$language_code/"; $translate_this = "# Translate this!"; } # Write a temporary macrofile containing the text for the images $text_unicode_raw = $text_unicode; # May contain "\n" to split the green_title text $text_unicode =~ s/\\n/ /g; # Replace any "\n" with " " for standard use open(MACROFILE, ">$image_generation_code_directory/web-images.dm") || (print "Error: Could not open web-images.dm for writing.", end_html() && die); print MACROFILE "\#\# \"" . $text_unicode . "\" \#\# nav_bar_button \#\# t$image_name \#\#\n\n"; print MACROFILE "\#\# \"" . $text_unicode_raw . "\" \#\# green_title \#\# h_$image_name \#\#\n\n"; close(MACROFILE); # Use ImageMagick via image generation scripts to make the images `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.*`; # Get width of nav_bar_buttons my $nav_bar_button_width = 87; my $nav_bar_button_identification = `identify $images_directory/t${image_name}on.gif 2>&1`; if ($nav_bar_button_identification =~ /t${image_name}on.gif \w+ (\d+)x(\d+)/) { $nav_bar_button_width = $1; } # Get width of green_titles my $green_title_width = 200; my $green_title_identification = `identify $images_directory/h_$image_name.gif 2>&1`; if ($green_title_identification =~ /h_$image_name.gif \w+ (\d+)x(\d+)/) { $green_title_width = $1; } # Output result HTML print "

Greenstone classifier images with text \"" . $text_unicode_raw . "\":"; print "

"; print "

"; print "

"; print "

"; print "

\n"; print "These images should be put in the images/$image_directory folder of your Greenstone installation.\n"; print "

\n"; 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"; print "

\n"; print "\n"; # base.dm macros print "# The following macros usually live in base.dm\n"; print "
package Global\n"; print "
\n"; print "
_" . $macro_name . "width_ $language_modifier {_widtht" . $image_name . "x_ }\n"; print "
_image" . $macro_name . "_ $language_modifier {_gsimage_(_httpbrowse" . $macro_name . "_,_httpicont" . $image_name . "of_,_httpicont" . $image_name . "on_,$text_unicode,_textimage" . $macro_name . "_)}\n"; print "
_icontab" . $macro_name . "green_ $language_modifier {<img src=\"_httpicont" . $image_name . "gr_\" width=_widtht" . $image_name . "x_ border=0>}\n"; print "
_icontab" . $macro_name . "green_ [$language_modifier_one" . "v=1] {_texticontab" . $macro_name . "green_ }\n"; print "

\n"; # document.dm macros print "# The following macros usually live in document.dm\n"; print "
package document\n"; print "
\n"; print "
_text" . $macro_name . "page_ $language_modifier {_texticonh" . $image_name . "_}\n"; print "
_icon" . $macro_name . "page_ $language_modifier {<img src=\"_httpiconh" . $image_name . "_\" width=\"_widthh" . $image_name . "_\" height=\"_heighth" . $image_name . "_\">}\n"; print "
_icon" . $macro_name . "page_ [$language_modifier_one" . "v=1] {<h2>_texticonh" . $image_name . "_</h2>}\n"; print "

\n"; # .dm macros print "# The following macros usually live in $macrofile_name.dm\n"; print "
package Global\n"; print "
\n"; print "
_textimage" . $macro_name . "_ $language_modifier {Browse by " . $text_unicode . "} $translate_this\n"; print "
_texticontab" . $macro_name . "green_ $language_modifier {\u$text_unicode}\n"; print "
\n"; print "
## \"$text_unicode\" ## nav_bar_button ## t" . $image_name . " ##\n"; print "
_httpicont" . $image_name . "gr_ $language_modifier {_httpimg_/$image_directory" . "t" . $image_name . "gr.gif}\n"; print "
_httpicont" . $image_name . "of_ $language_modifier {_httpimg_/$image_directory" . "t" . $image_name . "of.gif}\n"; print "
_httpicont" . $image_name . "on_ $language_modifier {_httpimg_/$image_directory" . "t" . $image_name . "on.gif}\n"; print "
_widtht" . $image_name . "x_ $language_modifier {$nav_bar_button_width}\n"; print "
\n"; print "
package document\n"; print "
\n"; print "
_texticonh" . $image_name . "_ $language_modifier {\u$text_unicode}\n"; print "
\n"; print "
## \"$text_unicode\" ## green_title ## h_" . $image_name . " ##\n"; print "
_httpiconh" . $image_name . "_ $language_modifier {_httpimg_/$image_directory" . "h_" . $image_name . ".gif}\n"; print "
_widthh" . $image_name . "_ $language_modifier {$green_title_width}\n"; print "
_heighth" . $image_name . "_ $language_modifier {57}\n"; print "
\n"; print "
package help\n"; print "
\n"; print "
_text" . $macro_name . "short_ $language_modifier {access publications by $text_unicode} $translate_this\n"; print "
_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"; print "
\n"; print "
\n"; } else { print "

Error: parameter not defined."; } print end_html();