[greenstone-users] Images as internal links.

From ak19@cs.waikato.ac.nz
DateWed Apr 16 18:42:37 2008
Subject [greenstone-users] Images as internal links.
In-Reply-To (001101c895ad$86a1a340$d7226481-fims-uwo-ca)
Hello Michael,

I think I was able to reproduce your problem by creating a demo collection
containing two html files. Each html page contains an image that links to
the other html page rather than direct us to the source image. And just as
you had said, the images in the Greenstone generated pages link to the
image sources instead of intended the html pages.

I have therefore made some changes to the perl source code file
"HTMLPlug.pm" which does the work of GLI's HTMLPlug. I am attaching the
updated HTMLPlug.pm as well as the two html files and two images used in
my demo collection for you to test things with.
(For greenstone-users mailing list: There are no attachments. Instead, the
changes made to HTMLPlug.pm are explained at the bottom).

What I would like you to try is the following:

1. First I'd advise you to make a back-up copy of the version of
HTMLPlug.pm which you already have, so that you can return to it in case
the updated file does something unexpected or has unwanted side-effects.
HTMLPlug.pm is located in the $GSDLHOME/perllib/plugins/ folder, where
$GSDLHOME is your Greenstone 3 installation folder.

2. Now place the HTMLPlug.pm I have attached into that same folder

3. Since it's perl code, you don't need to recompile anything. This simply
means you don't need to do anything special to tell GLI that the
underlying code has changed. It will automatically work with the changes.

4. Start GLI--the Greenstone Librarian Interface-- and create a demo
collection with the 4 other files that I am attaching:
page1.html, page2.html, ImageIcon.bmp, Apollo.png.

5. Before building, you will need to tell GLI that your images should not
be made into links to source images. This can be done as follows:
- click on the Design tab in GLI and
- in the right-hand pane select HTMLPlug.
- at the bottom, press the button Configure Plugin.
- in the dialog that opens, make sure the option "assoc_files" is ticked
and can you append "|bmp" to its field so that it now looks like:
This step is necessary to make sure that any bitmap (*.bmp) images
embedded in html pages (such as the ImageIcon.bmp in my attachment and now
in the demo collection) will display in the generated Greenstone pages.
- IMPORTANT: also tick the option "no_image_links" which in the updated
HTMLPLug.pm file will prevent images from being turned into links to the
source images. This is hopefully what you wanted.
- Press the OK button at the bottom of the Configure HTMLPlugin dialog

6. Click on GLI's Create tab and press the Build Collection at the bottom
to build the current collection.

7. Preview it in the browser. Browse by titles or filenames and view
page1.html and page2.html. Click on the images. If all went well, the
images should link to the pages and not the open the source image.

Did this work for you?

The no_image_links option you ticked in the Configure HTMLPlugin dialog
has the effect of not allowing any images (even where these are not links
to other pages) to link to their source versions.

If you are alright with this and are game to try out the solution on your
actual collection, then close the demo collection and rebuild your real
collection by following Step 5 and onwards. Remember, if something goes
wrong, you can replace the attached HTMLPlug.pm with the original's
back-up copy (from step 1).


For Greenstone-users mailing list (no attachments). The changes made to
$GSDLHOME/perllib/plugins/HTMLPlug.pm follow. They have not yet been
committed to Greenstone's main source repository, as I am not sure whether
the intention of HTMLPlug's no_image_links option is exactly as I have
understood it. If I get confirmation for it, I will commit the changes.

The changes (to HTMLPlug.pm) being discussed are:
1. In sub routine "process_section", it previously contained:
# trap images
$$textref =~
$self->replace_images ($1, $2, $3, $base_dir, $file, $doc_obj,
I replaced the above with:
my $no_image_links = 0;
$no_image_links = 1;
# Seting this flag to make sure the images have the /gsdl/collect/gsarch/index/assoc/20080415.dir in their
# attribute so that they don't appear broken. It's for those cases where
# are links to other html pages rather than links to the source imgs

# trap images either way: whether there are going to be no_image_links
or whether
# any embedded images are going to be turned into links to the source
# In the no_image_links case, the following substitution will ensure
that the
# image's src attribute references the correct greenstone location for
the image,
# so that the image displays.
$$textref =~
$self->replace_images ($1, $2, $3, $base_dir, $file, $doc_obj,
$cursection, $no_image_links)/isge;

2. Subroutine "replace_images", contained two lines of code that have been
my ($front, $link, $back, $base_dir,
$file, $doc_obj, $section) = @_;
my $anchor_link = "<a href="$img_file" >".$image_link."</a>";

The above two bits of code have been replaced with the following two
my ($front, $link, $back, $base_dir,
$file, $doc_obj, $section, $no_image_links) = @_;

my $anchor_link = $image_link;

if(!defined $no_image_links || !$no_image_links) {
# We don't do the following if the no_image_links option is set:
# Turn the <img> tag into a link to the image (image opens when clicked on).
# By surrounding the <img> tag with a link to the image as follows:
# <a href="image"><img src="image"></a>
$anchor_link = "<a href="$img_file" >".$image_link."</a>";
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HTMLPlug.pm
Type: application/x-perl
Size: 47955 bytes
Desc: not available
Url : https://list.scms.waikato.ac.nz/mailman/private/greenstone-users/attachments/20080407/a0793e85/HTMLPlug-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ImageIcon.bmp
Type: image/bmp
Size: 1062 bytes
Desc: not available
Url : https://list.scms.waikato.ac.nz/mailman/private/greenstone-users/attachments/20080407/a0793e85/ImageIcon-0001.bmp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://list.scms.waikato.ac.nz/mailman/private/greenstone-users/attachments/20080407/a0793e85/page1-0001.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://list.scms.waikato.ac.nz/mailman/private/greenstone-users/attachments/20080407/a0793e85/page2-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Apollo.png
Type: image/png
Size: 47117 bytes
Desc: not available
Url : https://list.scms.waikato.ac.nz/mailman/private/greenstone-users/attachments/20080407/a0793e85/Apollo-0001.png