|
From: <ix...@us...> - 2002-01-04 00:27:04
|
ixjonez 02/01/03 16:27:03
Modified: lib/LiveFrame Tag: ÷ `¶@@Ò @Ò X à¶ 8È ¸ h¹ h¹
¶@¶@¶@¶@¶@¶@ ¶@ ¶@z z
°¶@°¶@¸¶@¸¶@À¶@À¶@ȶ@ȶ@ж@ж@ظ ظ
à¶@à¶@è¶@è¶@ð¶@ð¶@ø¶@ø¶@
/tmp/cvs-serv11191/lib/LiveFrame/Site.pm No tag
Site.pm
Log:
allow the site to not exist and don't attempt to load galleries if it does
not exist. implement directory and file creation. implement inserting a
gallery (altho without order.conf rewriting for now).
Revision Changes Path
No revision
No revision
No revision
No revision
No revision
No revision
No revision
No revision
No revision
No revision
No revision
No revision
No revision
No revision
No revision
1.3 +106 -9 commons/lib/LiveFrame/Site.pm
Index: /tmp/cvs-serv11191/lib/LiveFrame/Site.pm
===================================================================
RCS file: /cvsroot/liveframe/commons/lib/LiveFrame/Site.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /tmp/cvs-serv11191/lib/LiveFrame/Site.pm 2001/12/19 05:29:21 1.2
+++ /tmp/cvs-serv11191/lib/LiveFrame/Site.pm 2002/01/04 00:27:03 1.3
@@ -2,6 +2,7 @@
package LiveFrame::Site;
+use Fcntl ();
use File::Basename ();
use LiveFrame::Gallery ();
use Tie::IxHash ();
@@ -16,6 +17,7 @@
my $self = bless
{
+ exists => undef,
path => $path,
galleries => undef,
}, $class;
@@ -34,17 +36,20 @@
sub galleries {
my ($self, $include_hidden) = @_;
+ my @g;
unless ($self->{galleries}) {
- $self->{galleries} = Tie::IxHash->new(),
+ $self->{galleries} = Tie::IxHash->new();
- $self->load_galleries($self->order_file());
- $self->load_visibility($self->hidden_file);
+ if ($self->exists()) {
+ $self->load_galleries($self->order_file());
+ $self->load_visibility($self->hidden_file);
+ }
+
+ @g = $include_hidden ?
+ $self->{galleries}->Values() :
+ grep { $_->shown() } $self->{galleries}->Values();
}
- my @g = $include_hidden ?
- $self->{galleries}->Values() :
- grep { $_->shown() } $self->{galleries}->Values();
-
return wantarray ? @g : \@g;
}
@@ -55,9 +60,39 @@
}
## public methods
+
+sub insert_gallery {
+ my ($self, $gallery, $pos) = @_;
+ return undef unless $gallery;
+
+ $self->galleries();
+ my $num_galleries = $self->num_galleries();
+
+ # if no position was indicated, push the gallery on the end of the list
+ $pos = $num_galleries unless defined $pos;
+
+ if ($pos == $num_galleries) {
+ # we can simply add the new gallery to the end
+ $self->{galleries}->Push($gallery->basename() => $gallery);
+ }
+ else {
+ # create a new galleries structure
+ my $new = Tie::IxHash->new();
+
+ # pop each gallery off the old structure and push it on the
+ # new one, inserting the specified gallery in the specified
+ # position
+ for (my $ix = 0; $ix < $num_galleries; $ix++) {
+ if ($ix == $pos) {
+ $new->Push($gallery->basename() => $gallery);
+ }
+
+ my ($name, $gallery) = $self->{galleries}->Shift();
+ $new->Push($name => $gallery);
+ }
-sub add_gallery {
- my ($self, $pos) = @_;
+ $self->{galleries} = $new;
+ }
return 1;
}
@@ -67,9 +102,71 @@
return File::Basename::basename($self->path());
}
+sub create {
+ my ($self, $perms) = @_;
+ $perms ||= 0755;
+
+ if ($self->exists()) {
+ die "can't create: site previously exists\n";
+ }
+
+ my $old_umask = umask;
+ umask 0000;
+
+ my $path = $self->path();
+ warn "mkpath $path\n";
+ File::Path::mkpath($path, undef, $perms) or
+ die "can't mkdir $path: $!\n";
+
+ my $order_file = $self->order_file();
+ sysopen ORDER, $order_file, Fcntl::O_WRONLY|Fcntl::O_CREAT, 0644 or
+ die "can't write $order_file: $!\n";
+ binmode ORDER;
+ print ORDER <<EOT;
+#
+# to specify the order of LiveFrame galleries manually, set the manual
+# gallery ordering variable in your liveframe script to "yes" and enter
+# the name of each gallery directory, each on it's own line, below.
+#
+
+EOT
+ close ORDER;
+
+ my $hidden_file = $self->hidden_file();
+ sysopen HIDDEN, $hidden_file, Fcntl::O_WRONLY|Fcntl::O_CREAT, 0644 or
+ die "can't write $hidden_file: $!\n";
+ binmode HIDDEN;
+ print HIDDEN <<EOT;
+#
+# to prevent LiveFrame galleries from being displayed in the gallery
+# index or in the previous/next gallery interface on the start page,
+# enter their names, each on it's own line, below.
+#
+# e.g.; to hide the gallery "sample" from the index, uncomment the
+# following line:
+#
+
+EOT
+ close HIDDEN;
+
+ umask $old_umask;
+
+ $self->{exists} = 1;
+
+ return 1;
+}
+
sub dirname {
my ($self) = @_;
return File::Basename::dirname($self->path());
+}
+
+sub exists {
+ my ($self) = @_;
+ unless (defined $self->{exists}) {
+ $self->{exists} = -f $self->hidden_file() ? 1 : 0;
+ }
+ return $self->{exists};
}
sub num_galleries {
No revision
No revision
1.3 +106 -9 commons/lib/LiveFrame/Site.pm
Index: Site.pm
===================================================================
RCS file: /cvsroot/liveframe/commons/lib/LiveFrame/Site.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Site.pm 2001/12/19 05:29:21 1.2
+++ Site.pm 2002/01/04 00:27:03 1.3
@@ -2,6 +2,7 @@
package LiveFrame::Site;
+use Fcntl ();
use File::Basename ();
use LiveFrame::Gallery ();
use Tie::IxHash ();
@@ -16,6 +17,7 @@
my $self = bless
{
+ exists => undef,
path => $path,
galleries => undef,
}, $class;
@@ -34,17 +36,20 @@
sub galleries {
my ($self, $include_hidden) = @_;
+ my @g;
unless ($self->{galleries}) {
- $self->{galleries} = Tie::IxHash->new(),
+ $self->{galleries} = Tie::IxHash->new();
- $self->load_galleries($self->order_file());
- $self->load_visibility($self->hidden_file);
+ if ($self->exists()) {
+ $self->load_galleries($self->order_file());
+ $self->load_visibility($self->hidden_file);
+ }
+
+ @g = $include_hidden ?
+ $self->{galleries}->Values() :
+ grep { $_->shown() } $self->{galleries}->Values();
}
- my @g = $include_hidden ?
- $self->{galleries}->Values() :
- grep { $_->shown() } $self->{galleries}->Values();
-
return wantarray ? @g : \@g;
}
@@ -55,9 +60,39 @@
}
## public methods
+
+sub insert_gallery {
+ my ($self, $gallery, $pos) = @_;
+ return undef unless $gallery;
+
+ $self->galleries();
+ my $num_galleries = $self->num_galleries();
+
+ # if no position was indicated, push the gallery on the end of the list
+ $pos = $num_galleries unless defined $pos;
+
+ if ($pos == $num_galleries) {
+ # we can simply add the new gallery to the end
+ $self->{galleries}->Push($gallery->basename() => $gallery);
+ }
+ else {
+ # create a new galleries structure
+ my $new = Tie::IxHash->new();
+
+ # pop each gallery off the old structure and push it on the
+ # new one, inserting the specified gallery in the specified
+ # position
+ for (my $ix = 0; $ix < $num_galleries; $ix++) {
+ if ($ix == $pos) {
+ $new->Push($gallery->basename() => $gallery);
+ }
+
+ my ($name, $gallery) = $self->{galleries}->Shift();
+ $new->Push($name => $gallery);
+ }
-sub add_gallery {
- my ($self, $pos) = @_;
+ $self->{galleries} = $new;
+ }
return 1;
}
@@ -67,9 +102,71 @@
return File::Basename::basename($self->path());
}
+sub create {
+ my ($self, $perms) = @_;
+ $perms ||= 0755;
+
+ if ($self->exists()) {
+ die "can't create: site previously exists\n";
+ }
+
+ my $old_umask = umask;
+ umask 0000;
+
+ my $path = $self->path();
+ warn "mkpath $path\n";
+ File::Path::mkpath($path, undef, $perms) or
+ die "can't mkdir $path: $!\n";
+
+ my $order_file = $self->order_file();
+ sysopen ORDER, $order_file, Fcntl::O_WRONLY|Fcntl::O_CREAT, 0644 or
+ die "can't write $order_file: $!\n";
+ binmode ORDER;
+ print ORDER <<EOT;
+#
+# to specify the order of LiveFrame galleries manually, set the manual
+# gallery ordering variable in your liveframe script to "yes" and enter
+# the name of each gallery directory, each on it's own line, below.
+#
+
+EOT
+ close ORDER;
+
+ my $hidden_file = $self->hidden_file();
+ sysopen HIDDEN, $hidden_file, Fcntl::O_WRONLY|Fcntl::O_CREAT, 0644 or
+ die "can't write $hidden_file: $!\n";
+ binmode HIDDEN;
+ print HIDDEN <<EOT;
+#
+# to prevent LiveFrame galleries from being displayed in the gallery
+# index or in the previous/next gallery interface on the start page,
+# enter their names, each on it's own line, below.
+#
+# e.g.; to hide the gallery "sample" from the index, uncomment the
+# following line:
+#
+
+EOT
+ close HIDDEN;
+
+ umask $old_umask;
+
+ $self->{exists} = 1;
+
+ return 1;
+}
+
sub dirname {
my ($self) = @_;
return File::Basename::dirname($self->path());
+}
+
+sub exists {
+ my ($self) = @_;
+ unless (defined $self->{exists}) {
+ $self->{exists} = -f $self->hidden_file() ? 1 : 0;
+ }
+ return $self->{exists};
}
sub num_galleries {
|