[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CVS Update: gleipnir
- To: cvs@lists.cleannorth.org
- Subject: CVS Update: gleipnir
- From: Dan Brosemer <odin@cleannorth.org>
- Date: Tue, 12 Aug 2008 20:34:48 -0401 (EDT)
- List-help: <mailto:cvs-request@lists.cleannorth.org?subject=help>
- List-post: <mailto:cvs@lists.cleannorth.org>
- List-subscribe: <mailto:cvs-request@lists.cleannorth.org?subject=subscribe>
- List-unsubscribe: <mailto:cvs-request@lists.cleannorth.org?subject=unsubscribe>
- Resent-date: Tue, 12 Aug 2008 20:34:56 -0401 (EDT)
- Resent-from: cvs@lists.cleannorth.org
- Resent-message-id: <zANEEB.A.gYD.GxioIB@skroob.cleannorth.org>
- Resent-sender: cvs-request@lists.cleannorth.org
Log Message:
-----------
Check in Josh's gallery stuff after renaming it and giving it a directory of
its own. I highly doubt it'll work after I renamed it, but it needed to be
done and fixing it can now commence.
Added Files:
-----------
gleipnir/public_html/gallery:
index.pl
picture.pl
upload.pl
Revision Data
-------------
--- /dev/null
+++ public_html/gallery/index.pl
@@ -0,0 +1,175 @@
+#!/usr/bin/perl -w
+###############################################################################
+# $Id: index.pl,v 1.1 2008/08/13 00:35:11 odin Exp $
+# gallery.pl - view and upload pictures in categories
+#
+# Copyright (C) 2000-2003 Dan Brosemer <odin@cleannorth.org>
+# Copyright (C) 2006 Jim Dew <jdew@yggdrasil.ca>
+# Copyright (C) 2006-2007 Josh Hayes-Sheen <grevian@gmail.com>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+###############################################################################
+
+use strict;
+use Gleipnir;
+
+my $gleipnir = new Gleipnir;
+my $cgi = $gleipnir->cgi;
+
+$gleipnir->sidebar('gallery');
+
+do { print $gleipnir->output; exit } if $gleipnir->done;
+
+
+if ( $gleipnir->access('galleryupload') && defined($cgi->param('action')) )
+ {
+ my $action = $cgi->param('action');
+ if ( $action eq 'upload' )
+ {
+ $gleipnir = ShowUpload( -gleipnir => $gleipnir );
+ }
+ elsif( $action eq 'edit' )
+ {
+ $gleipnir = ShowEdit( -gleipnir => $gleipnir );
+ }
+ else
+ {
+ $gleipnir = ShowPage( -gleipnir => $gleipnir );
+ }
+ }
+elsif ( defined($cgi->param('gallery')) )
+ {
+ $gleipnir = ShowCategory( -gleipnir => $gleipnir );
+ }
+else
+ {
+ $gleipnir = ShowPage( -gleipnir => $gleipnir );
+ }
+
+print $gleipnir->output;
+exit;
+
+sub ShowPage
+ {
+ my %options = @_;
+ my $gleipnir = $options{-gleipnir};
+ my $cgi = $gleipnir->cgi;
+ my $dbh = $gleipnir->dbh;
+
+ # Either get the groups the user belongs to, or if they belong to nothing show story's accessable to 'everyone'
+ my $ingroups = ();
+ if ( defined( $gleipnir->groups ) )
+ {
+ $ingroups = join( ",", ( $gleipnir->groups ) );
+ $ingroups = "or gid in ($ingroups)" if ($ingroups);
+ }
+
+ $ingroups = " gid is null " . $ingroups;
+
+ my $SQL = <<EOT;
+select identifier, galleryid from gallery where $ingroups
+EOT
+
+ my $cursor = $dbh->prepare($SQL);
+ $cursor->execute();
+
+ my $template = $gleipnir->template('gallery/index');
+
+ my @categories = ();
+ while ( my $ref = $cursor->fetchrow_hashref )
+ {
+ push @categories, { identifier => $ref->{identifier}, id => $ref->{galleryid} };
+ }
+ $template->param('categories' => \@categories );
+
+ return $gleipnir->body( $template->output );
+ }
+
+sub ShowCategory
+{
+ my %options = @_;
+ my $gleipnir = $options{-gleipnir};
+ my $cgi = $gleipnir->cgi;
+ my $dbh = $gleipnir->dbh;
+
+ return ShowPage( -gleipnir => $gleipnir ) unless defined( $cgi->param('gallery') );
+ my $galleryid = int( $cgi->param('gallery') );
+ my $template = $gleipnir->template('gallery/category');
+
+ my $ingroups = ();
+ if ( defined( $gleipnir->groups ) )
+ {
+ $ingroups = join( ",", ( $gleipnir->groups ) );
+ $ingroups = "or g.gid in ($ingroups)" if ($ingroups);
+ }
+
+ $ingroups = " g.gid is null " . $ingroups;
+
+ my $GSQL = <<EOT;
+select identifier, description from gallery where galleryid = ?
+EOT
+
+ my $gcursor = $dbh->prepare($GSQL);
+ $gcursor->execute($galleryid);
+
+ my $gallery_desc = $gcursor->fetchrow_hashref;
+ $template->param( 'gallery_title' => $gallery_desc->{identifier},
+ 'gallery_description' => $gallery_desc->{description}
+ );
+
+ my $CSQL = <<EOT;
+select count(pictureid) from gallery_picture where gallery = ?
+EOT
+
+ my $ccursor = $dbh->prepare($CSQL);
+ $ccursor->execute($galleryid);
+
+ my $countref = $ccursor->fetchrow_hashref;
+ my $count = $countref->{count};
+
+ my ( $block, $offset, $limit ) = $gleipnir->paginate( -items => $count, -perpage => $cgi->param('perpage')||6 );
+ $template->param('pagination' => $block);
+
+ my $SQL = <<EOT;
+select gp.pictureid, gp.caption, gp.thumb_path from gallery_picture gp left join gallery g on g.galleryid = gp.gallery
+where $ingroups and gp.gallery = ? limit $limit offset $offset
+EOT
+
+ my $cursor = $dbh->prepare($SQL);
+ $cursor->execute($galleryid);
+
+ my @pictures = ();
+ my $flip = 1;
+ while ( my $ref = $cursor->fetchrow_hashref )
+ {
+ push @pictures, {
+ caption => $ref->{caption},
+ thumb_path => $ref->{thumb_path},
+ pictureid =>$ref->{pictureid},
+ flip => $flip
+ };
+ $flip = !$flip; # Flip the picture sides
+ }
+ $template->param( 'pictures' => \@pictures );
+ return $gleipnir->body( $template->output );
+}
+
--- /dev/null
+++ public_html/gallery/picture.pl
@@ -0,0 +1,92 @@
+#!/usr/bin/perl -w
+###############################################################################
+# $Id: picture.pl,v 1.1 2008/08/13 00:35:11 odin Exp $
+# gallery_picture.pl - view large sized pictures with comment threads and tags
+#
+# Copyright (C) 2000-2003 Dan Brosemer <odin@cleannorth.org>
+# Copyright (C) 2006 Jim Dew <jdew@yggdrasil.ca>
+# Copyright (C) 2006-2007 Josh Hayes-Sheen <grevian@gmail.com>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+###############################################################################
+
+use strict;
+use Gleipnir;
+
+my $gleipnir = new Gleipnir;
+my $cgi = $gleipnir->cgi;
+
+$gleipnir->sidebar('gallery');
+
+do { print $gleipnir->output; exit } if $gleipnir->done;
+
+$gleipnir = ShowPage( -gleipnir => $gleipnir );
+
+print $gleipnir->output;
+exit;
+
+sub ShowPage
+ {
+ my %options = @_;
+ my $gleipnir = $options{-gleipnir};
+ my $cgi = $gleipnir->cgi;
+ my $dbh = $gleipnir->dbh;
+
+ my $pictureid = $cgi->param('id');
+
+ # build a where clause that will filter out pictures this user does not have access to
+ my $ingroups = ();
+ if ( defined( $gleipnir->groups ) )
+ {
+ $ingroups = join( ",", ( $gleipnir->groups ) );
+ $ingroups = "or g.gid in ($ingroups)" if ($ingroups);
+ }
+
+ $ingroups = " gid is null " . $ingroups;
+
+ my $SQL = <<EOT;
+select gp.pictureid, gp.gallery, gp.image_path, gp.title, gp.caption, gp.exif, gp.uploader, gp.uploaded, g.identifier, g.description
+from gallery_picture gp left join gallery g on g.galleryid = gp.gallery where gp.pictureid = ? and $ingroups
+EOT
+
+ my $cursor = $dbh->prepare($SQL);
+ $cursor->execute( $pictureid );
+
+ my $template = $gleipnir->template('gallery/picture');
+
+ my $ref = $cursor->fetchrow_hashref;
+
+ $template->param(
+ title => $ref->{title},
+ pictureid => $ref->{pictureid},
+ galleryid => $ref->{gallery},
+ image_path => $ref->{image_path},
+ caption => $ref->{caption},
+ uploader => $ref->{uploader},
+ upload_date => $ref->{uploaded},
+ gallery_name => $ref->{identifier},
+ gallery_desc => $ref->{description}
+ );
+
+ return $gleipnir->body( $template->output );
+ }
+
--- /dev/null
+++ public_html/gallery/upload.pl
@@ -0,0 +1,214 @@
+#!/usr/bin/perl -w
+
+use Gleipnir;
+use strict;
+use GD;
+use POSIX qw(ceil floor);
+use Digest::SHA1 qw(sha1 sha1_hex sha1_base64);
+
+my $gleipnir = new Gleipnir;
+do { print $gleipnir->output; exit } if ($gleipnir->done);
+
+my $cgi = $gleipnir->cgi;
+
+my $action = $cgi->param('action') || 'none';
+
+if ( $action eq 'upload')
+{
+ $gleipnir = UploadPictures(-gleipnir => $gleipnir);
+}
+else
+{
+ $gleipnir = ShowPage( -gleipnir => $gleipnir );
+}
+
+print $gleipnir->output;
+exit;
+
+sub ShowPage
+{
+ my %options=@_;
+ my $gleipnir = $options{-gleipnir};
+ my $cgi = $gleipnir->cgi;
+ my $dbh = $gleipnir->dbh;
+ my $template = $gleipnir->template('gallery/upload');
+
+ # Even if they have galleryupload access, they can still only upload to
+ # galleries they have view access to.
+
+ my $ingroups = ();
+ if ( defined( $gleipnir->groups ) )
+ {
+ $ingroups = join( ",", ( $gleipnir->groups ) );
+ $ingroups = "or gid in ($ingroups)" if ($ingroups);
+ }
+
+ $ingroups = " gid is null " . $ingroups;
+
+ my $SQL =<<EOT;
+select identifier, galleryid from gallery where $ingroups
+EOT
+
+ my $cursor = $dbh->prepare($SQL);
+ $cursor->execute();
+
+ my @galleries = ();
+
+ while ( my $ref = $cursor->fetchrow_hashref() )
+ {
+ push @galleries, { title => $ref->{identifier}, id => $ref->{galleryid} };
+ }
+
+ # Assemble a username, I could have sworn we had an easier way to do this,
+ my $sql = <<EOT;
+select username, fname, lname from cnuser where uid = ?
+EOT
+ my $ucursor = $dbh->prepare($sql);
+ $ucursor->execute($gleipnir->uid);
+ my ($username, $fname, $lname) = $ucursor->fetchrow;
+ my $uname = $fname . ' ' . $lname . ' (' . $username . ')';
+
+ $template->param( galleries => \@galleries, uname => $uname );
+ return $gleipnir->body($template->output);
+}
+
+sub UploadPictures
+{
+ my %options=@_;
+ my $gleipnir = $options{-gleipnir};
+ my $cgi = $gleipnir->cgi;
+ my $dbh = $gleipnir->dbh;
+ my $template = $gleipnir->template('gallery/completed');
+ my $title = $cgi->param('title');
+ my $caption = $cgi->param('caption');
+ my $galleryid = $cgi->param('gallery');
+
+ # start off with some basic info
+ my $uploader_id = $gleipnir->uid;
+ my $fail = 0;
+ my $message = " ";
+ my $xtn = "jpg";
+
+ my $originaldir = $gleipnir->cfetch(dirs => 'docroot') .$gleipnir->cfetch( dirs => 'originals' );
+ my $storagedir = $gleipnir->cfetch(dirs => 'docroot') . $gleipnir->cfetch( dirs => 'imagedir' );
+ my $thumbdir = $gleipnir->cfetch(dirs => 'docroot') . $gleipnir->cfetch( dirs => 'thumbdir' );
+
+ # Get an ID for this picture and create it's filename
+ my $iSQL =<<EOT;
+select nextval('gallery_picture_pictureid_seq')
+EOT
+ my $icursor = $dbh->prepare($iSQL);
+ $icursor->execute();
+ my $id = $icursor->fetchrow;
+
+ # Get our filename and file handle
+ my $fh = $cgi->upload( 'imagefile' );
+ my $filename = $cgi->param( 'imagefile' );
+ # Strip off slashes
+ $filename =~ s/.*[\/\\](.*)/$1/;
+
+ #Set the xtn to the last value, which we can assume is the file extension, this is pretty fug, there's probably a better way to do it.
+ my @filesp = split('.', $filename);
+ foreach my $cur (@filesp) { $xtn = $cur; }
+
+ # Copy our original image to somewhere safeish
+ open ( ORIGIMAGE, ">$originaldir/$id.$xtn" ) or $fail = 1;
+ if ( $fail > 0 )
+ {
+ $message = " Could not open Image File to write: $! at $originaldir/$id.png";
+ $template->param(message => $message, failed => $fail );
+ return $gleipnir->body($template->output);
+ }
+ binmode ORIGIMAGE;
+ while (<$fh>) {
+ print ORIGIMAGE;
+ }
+ close(ORIGIMAGE);
+
+ # Load the image into GD so we can work with it
+ GD::Image->trueColor(1);
+ my $image = GD::Image->new( "$originaldir/$id.$xtn" );
+ if ( !defined($image) )
+ {
+ $fail = 1;
+ $message .= " Could not create image from file $originaldir/$id.$xtn, $! <br>";
+ $template->param(message => $message, failed => $fail );
+ return $gleipnir->body($template->output);
+ }
+
+ # Grab the image in png form.
+ my $image_png = $image->png();
+
+ # Grab a SHA1 hash for later
+ my $hash = sha1( $image_png );
+
+ # Convert the image to a png and write it out to a file
+ open( MYIMAGE, ">$storagedir/$id.png" ) or $fail = 1;
+ if ( $fail > 0 )
+ {
+ $message = " Could not write Image file: $! at $storagedir/$id.png";
+ $template->param(message => $message, failed => $fail );
+ return $gleipnir->body($template->output);
+ }
+ binmode MYIMAGE;
+ print MYIMAGE $image_png;
+ close MYIMAGE;
+
+ # Find the appropriate dimensions for the thumbnail
+ # Calculate aspect ratio
+ my $thumbmaxsize = $gleipnir->cfetch('images' => 'thumbsize');
+ my $width = $image->width();
+ my $height = $image->height();
+ my $wRatio = $thumbmaxsize / $width;
+ my $hRatio = $thumbmaxsize / $height;
+ my $thumbwidth = undef;
+ my $thumbheight = undef;
+
+ # Calculate a proportional width and height no larger than the max size.
+ if ( ($wRatio * $height) < $thumbmaxsize )
+ {
+ # Image is horizontal
+ $thumbheight = ceil($wRatio * $height);
+ $thumbwidth = $thumbmaxsize;
+ }
+ else
+ {
+ # Image is vertical
+ $thumbwidth = ceil($hRatio * $width);
+ $thumbheight = $thumbmaxsize;
+ }
+
+ # Create a thumbnail of an appropriate size
+ my $thumb = new GD::Image($thumbwidth, $thumbheight);
+ if ( !defined( $thumb ) )
+ {
+ $fail = 1;
+ $message .= "Could not create thumbnail for image $filename <br>";
+ $template->param(message => $message, failed => $fail );
+ return $gleipnir->body($template->output);
+ }
+ $thumb->copyResampled( $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $image->width(), $image->height() );
+
+ # Write the thumbnail out to a file
+ open (MYTHUMBNAIL, ">$thumbdir/$id.png" );
+ binmode MYTHUMBNAIL;
+ print MYTHUMBNAIL $thumb->png();
+ close MYTHUMBNAIL;
+
+ my $aSQL =<<EOT;
+insert into gallery_picture (pictureid, original_hash, uploader, gallery, thumb_path, original_path, image_path, caption, title ) values (?,?,?,?,?,?,?,?,?)
+EOT
+
+ my $acursor = $dbh->prepare($aSQL);
+
+ # Upload the picture info to our database
+ $acursor->execute( $id, $hash, $gleipnir->uid, $galleryid,
+ $gleipnir->cfetch( dirs => 'thumbdir' )."/$id.png",
+ $gleipnir->cfetch( dirs => 'originals' )."/$id.$xtn",
+ $gleipnir->cfetch( dirs => 'imagedir' )."/$id.png", $caption, $title );
+
+ $template->param(message => $message, failed => $fail );
+ return $gleipnir->body($template->output);
+}
+
+
- Prev by Date: CVS Update: gleipnir
- Next by Date: CVS Update: gleipnir
- Previous by thread: CVS Update: gleipnir
- Next by thread: CVS Update: gleipnir
- Index(es):