|
From: Chris W. <la...@us...> - 2001-10-24 20:55:40
|
Update of /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Page
In directory usw-pr-cvs1:/tmp/cvs-serv22637/OpenInteract/Page
Modified Files:
Database.pm File.pm
Log Message:
latest updates
Index: Database.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Page/Database.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Database.pm 2001/10/20 15:12:34 1.1
--- Database.pm 2001/10/24 20:55:37 1.2
***************
*** 1,19 ****
package OpenInteract::Page::Database;
! # Read in the page content from a separate table/object
! sub _load {
my ( $self ) = @_;
! my $page_content = $self->page_content;
! $self->{pagetext} = $page_content->{pagetext};
! $self->{script} = $page-content->{script};
}
! sub _save {
}
! sub _remove {
}
--- 1,29 ----
package OpenInteract::Page::Database;
! # $Id$
! use strict;
!
! sub load {
my ( $self ) = @_;
! my $page_content = eval { $self->page_content };
! return $page_content->{content};
}
! sub save {
! my ( $self, $content ) = @_;
! my $R = OpenInteract::Request->instance;
! my $page_content = eval { $self->page_content } || $R->page_content->new;
! $page_content->{location} = $self->{location};
! $page_content->{content} = $content;
! return $page_content->save;
}
! sub remove {
! my ( $self ) = @_;
! my $page_content = eval { $self->page_content };
! return $page_content->remove;
}
Index: File.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Page/File.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** File.pm 2001/10/20 15:12:34 1.1
--- File.pm 2001/10/24 20:55:37 1.2
***************
*** 5,58 ****
use strict;
# Read in the content from a file
! sub load_content {
my ( $self ) = @_;
my $R = OpenInteract::Request->instance;
! my $html_dir = $R->CONFIG->get_dir( 'html' );
! $html_dir =~ s|/$||;
! my $full_location = join( '', $html_dir, $self->{location} );
! next unless ( -f $full_location );
! $R->DEBUG && $R->scrib( 1, "Filesystem location ($full_location) ",
! "exists. Trying to read file." );
! open( STATIC, $full_location ) || die "Cannot access file: no access";
local $/ = undef;
! $self->{pagetext} = <STATIC>;
!
! # Pull out the title, main template, author, extra boxes (if they
! # exist)
! if ( $self->{pagetext} =~ s|<title>(.*)?</title>|| ) {
! $self->{title} ||= $1;
! }
! if ( $self->{pagetext} =~ s|<template>(.*)?</template>|| ) {
! $self->{main_template} ||= $1;
! }
! if ( $self->{pagetext} =~ s|<author>(.*)?</author>|| ) {
! $self->{author} ||= $1;
! }
! if ( $self->{pagetext} =~ s|<boxes>(.*)?</boxes>|| ) {
! $self->{boxes} ||= $1;
! }
# Only use the information between the $BODY_DEMARCATION tags (if
# they exist)
! $self->{pagetext} =~ s/$BODY_DEMARCATION(.*)?$BODY_DEMARCATION/$1/;
# If the page still has <body> tags, only use the information
# between them
! $self->{pagetext} =~ s|<body>(.*)?</body>|$1|i;
}
! sub _save {
}
! sub _remove {
}
--- 5,97 ----
use strict;
+ # Use this to mark the beginning and end of the "good" content in a
+ # page in the filesystem; this allows you to use an HTML editor to
+ # create the content and to save a full html page to the filesystem
+
+ my $BODY_DEMARCATION = '<!-- OI BODY -->';
+
+
# Read in the content from a file
! sub load {
my ( $self ) = @_;
+ my $full_location = $self->_create_file_location;
+ return undef unless ( -f $full_location );
my $R = OpenInteract::Request->instance;
! $R->DEBUG && $R->scrib( 1, "File ($full_location) exists. Trying to read file." );
! open( STATIC, $full_location ) || die "Cannot access file: $!";
local $/ = undef;
! my $content = <STATIC>;
! close( STATIC );
! $R->DEBUG && $R->scrib( 1, "File read ok. Scanning for valid content then returning." );
# Only use the information between the $BODY_DEMARCATION tags (if
# they exist)
! $content =~ s/$BODY_DEMARCATION(.*)?$BODY_DEMARCATION/$1/;
# If the page still has <body> tags, only use the information
# between them
! $content =~ s|<body>(.*)?</body>|$1|i;
!
! return $content;
}
+ # Wrap this sucker in an eval {} -- if there's an error, the old file
+ # is still in place (even if that was nothing); if there's no error,
+ # everything is consistent
! sub save {
! my ( $self, $content ) = @_;
! my $R = OpenInteract::Request->instance;
! my $full_location = $self->_create_file_location;
! $R->DEBUG && $R->scrib( 1, "Trying to save content to ($full_location)" );
!
! my $tmp_location = $full_location;
! if ( -f $full_location ) {
! $R->DEBUG && $R->scrib( 1, "File already exists; writing content to temp file." );
! $tmp_location = "$full_location.tmp";
! if ( -f $tmp_location ) {
! unlink( $tmp_location ) || die "Cannot remove old temp file: $!";
! }
! }
! open( NEW, "> $tmp_location" ) || die "Cannot open temp file for writing: $!";
! print NEW $content;
! close( NEW );
! $R->DEBUG && $R->scrib( 1, "Wrote content to file ok." );
!
! if ( $full_location ne $tmp_location ) {
! $R->DEBUG && $R->scrib( 1, "Trying to delete old content file and rename temp file." );
! unlink( $full_location ) || die "Cannot remove old content file: $!";
! rename( $tmp_location, $full_location ) || die "Cannot rename temp file to content file: $!";
! $R->DEBUG && $R->scrib( 1, "Old file removed, new file renamed ok." );
! }
!
! return $full_location;
}
! sub remove {
! my ( $self ) = @_;
! my $full_location = $self->_create_file_location;
! my $R = OpenInteract::Request->instance;
! $R->DEBUG && $R->scrib( 1, "Trying to delete content file ($full_location)" );
! return 1 unless ( -f $full_location );
! unlink( $full_location ) || die "Cannot remove stale content file: $!";
! $R->DEBUG && $R->scrib( 1, "File deleted ok" );
! return 1;
! }
!
!
! sub _create_file_location {
! my ( $self ) = @_;
! my $R = OpenInteract::Request->instance;
! my $html_dir = $R->CONFIG->get_dir( 'html' );
! $html_dir =~ s|/$||;
! return join( '', $html_dir, $self->{location} );
}
|