Add initial MANIFEST files.
[matthijs/upstream/blosxom-plugins.git] / general / imagegallery
1 # Bloxsom Plugin: ImageGallery
2 # Author: Fletcher T. Penney
3 # Version: 0.6
4
5 package imagegallery;
6
7 # --- Configurable variables ----
8
9 # URL for images directory - will be added to beginning of images for the web browser to find them
10 $images_url = "/images/galleries";
11
12 # Filepath for images directory
13 # This gets added to the gallery to find the files
14 # NOTE: This is a change in behavior from version 0.1
15 $images_path = "$blosxom::datadir/../images/galleries";
16
17
18 # Default thumbnail sub-directory name
19 $thumbdir="thumbnails";
20
21 # Default image sub-directory name
22 $imagesdir="images";
23
24 # Default comments sub-directory name
25 $commentsdir="comments";
26
27 # Default number of columns
28 $columns = 3;
29
30 # HTML Code for gallery pieces
31 $galleryhead = "";
32
33 $galleryrowstart = "";
34
35 $galleryrowend = "";
36
37 $gallerycolstart = qq!<div class="image">\n!;
38
39 $gallerycolend = "</div>\n";
40
41 $galleryfoot = "";
42
43
44 # Message to display in category view
45 $gallerymessage = "<br/>You must click on the individual story to see the images.  Try the \"permanent link\" button.";
46
47 # HTML Code for single image view
48
49 $imagehead = qq!<div class="single-image">\n!;
50
51 $imagefoot = qq!</div>\n!;
52
53
54 # Extensions for valid image types to display
55 $imagetypes = "jpg|gif|png";
56
57 # -------------------------------
58 $path_noflavour = "";
59 $gallery="";
60 $gallerypath="";
61 $comments = "";
62
63 use File::Find;
64 use CGI;
65
66 sub start {
67         $path_noflavour = $blosxom::path_info;
68         if ($path_noflavour !~ s/\.[^\.]*$//) {
69                 $path_noflavour =~ s/\/$//;
70                 $path_noflavour .= "\/index";
71                 $path_noflavour =~ s/^([^\/])/$1/;
72         }
73         $path_noflavour =~ s/^\/*//;
74
75 }
76
77
78 sub story {
79         $gallery="";
80         $comments="";
81         my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
82
83         if ($$body_ref =~ /<!-- imagegallery\s*(\S*)\s*-->/i) {
84                 $gallerypath= $1 . "\/" if $1 ne "";
85
86                 $gallerypath =~ s/\/\//\//g;
87         } else {
88                 return 1;
89         }
90
91         if (($path_noflavour =~ /index$/) || ($path_noflavour =~ /\/$/)) {
92                 $gallery = "<br/> You must view this story individually to <a href=\"$blosxom::url$path/$filename.$blosxom::flavour\">see the images</a>.)";
93                 
94                 if ($blosxom::flavour eq "rss") {
95                         $gallery = "&lt;br&gt; You must view this story individually to &lt;a href=&quot;$blosxom::url$path/$filename.$blosxom::flavour&quot; see the images&lt/a&gt;.)";
96                 }
97                 return 1;
98         }
99
100         $gallery_url = "$images_url/$gallerypath";
101         $gallerypath = "$images_path/$gallerypath";
102
103         # If this is a request for a single photo, display it, and exit
104         if (CGI::param("image")) {
105                 $imagefile = CGI::param("image");
106                 $gallery = $imagehead;
107                 $gallery.= "<img src=\"$gallery_url" . "$imagesdir/$imagefile\" alt=\"Imagegallery - $imagefile\" />";
108                 $gallery .= $imagefoot;
109
110                 # Try and read comments
111                 $imagefile =~ s/($imagetypes)$/txt/i;
112                 open (COMMENT, "<$gallerypath/$commentsdir/$imagefile");
113                 $comments = join '', <COMMENT>;
114                 close COMMENT;
115                 return 1;
116         }
117
118         # Now, find out how many images there are, and where
119         my(@images);
120
121         find(sub {
122                 $File::Find::name =~ /($imagetypes)$/i
123                 and
124                 push (@images, $File::Find::name)
125                 ;}, $gallerypath . $imagesdir);
126         
127         # Sort them.
128                 @images = sort @images;
129
130         # Now fill out gallery
131         if (scalar(@images) > 0) {
132                 $gallery = $galleryhead . $galleryrowstart;
133                 my $count = 0;
134                 foreach $image (@images) {
135                         $count++;
136                         if ($count gt $columns) {
137                                 $count = 1;
138                                 $gallery.= $galleryrowend . $galleryrowstart;
139                         }
140                         $image =~ s/$images_path/$images_url/;
141                         $thumb = $image;
142                         $thumb =~ s/(.*)$imagesdir/$1$thumbdir/;
143
144                         $imagefile = $image;
145                         $imagefile =~ s/.*?([^\/]*)$/$1/;
146
147                         $gallery.= qq!$gallerycolstart
148 <a href="$blosxom::url/$path_noflavour.$blosxom::flavour?image=$imagefile">
149 <img src="$thumb" alt="Thumbnail"/><p>$imagefile</p></a>
150 $gallerycolend!;
151
152                 }
153                 $gallery.= $galleryrowend . $galleryfoot;
154         
155         } else {
156                 $gallery = "No images to display... <br/>";
157         }
158
159
160         1;
161 }
162
163 1;
164
165
166 __END__
167
168
169 Documentation is Pending!!