|
From: Chris W. <la...@us...> - 2001-10-24 20:55:40
|
Update of /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Handler
In directory usw-pr-cvs1:/tmp/cvs-serv22637/OpenInteract/Handler
Modified Files:
Page.pm
Log Message:
latest updates
Index: Page.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Handler/Page.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Page.pm 2001/10/22 02:00:29 1.2
--- Page.pm 2001/10/24 20:55:37 1.3
***************
*** 19,38 ****
);
- use constant MAIN_SCRIPT => '/Page';
-
- # Use this to signal that we shouldn't send the content through TT --
- # this is useful for documentation :-)
-
- use constant NO_PARSE_STATUS => 'no_parse';
-
# 52 weeks -- default expiration for page
-
- use constant DEFAULT_EXPIRE => 60 * 60 * 24 * 7 * 52;
-
- # 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 -->';
# Use this to check whether the file retrieved is displayable in the
--- 19,25 ----
);
# 52 weeks -- default expiration for page
! use constant DEFAULT_EXPIRE => '365D';
# Use this to check whether the file retrieved is displayable in the
***************
*** 51,61 ****
sub MY_OBJECT_CLASS { return OpenInteract::Request->instance->page }
sub MY_SEARCH_FIELDS { return () }
- sub MY_OBJECT_FORM_TITLE { return 'Edit Page' }
- sub MY_OBJECT_FORM_TEMPLATE { return '' }
sub MY_EDIT_RETURN_URL { return '/' }
sub MY_EDIT_DISPLAY_TASK { return 'show' }
sub MY_EDIT_FIELDS { return qw( location title author keywords
boxes main_template notes ) }
! sub MY_EDIT_FIELDS_TOGGLED { return qw( is_active is_file ) }
sub MY_EDIT_FIELDS_DATE { return qw( active_on expires_on ) }
sub MY_ALLOW_SEARCH_FORM { return 1 }
--- 38,46 ----
sub MY_OBJECT_CLASS { return OpenInteract::Request->instance->page }
sub MY_SEARCH_FIELDS { return () }
sub MY_EDIT_RETURN_URL { return '/' }
sub MY_EDIT_DISPLAY_TASK { return 'show' }
sub MY_EDIT_FIELDS { return qw( location title author keywords
boxes main_template notes ) }
! sub MY_EDIT_FIELDS_TOGGLED { return qw( is_active is_file template_parse ) }
sub MY_EDIT_FIELDS_DATE { return qw( active_on expires_on ) }
sub MY_ALLOW_SEARCH_FORM { return 1 }
***************
*** 63,66 ****
--- 48,52 ----
sub MY_ALLOW_EDIT { return 1 }
sub MY_ALLOW_REMOVE { return 1 }
+ sub MY_ALLOW_NOTIFY { return 1 }
sub MY_ALLOW_WIZARD { return undef }
***************
*** 80,87 ****
# Retrieve all directories, expanding the one we were asked to (if at
# all). Note that these are just the objects in the database, although
! # hopefully there's one of these corresponding to every file in the
! # filesystem.
! sub listing {
my ( $class, $p ) = @_;
my $R = OpenInteract::Request->instance;
--- 66,73 ----
# Retrieve all directories, expanding the one we were asked to (if at
# all). Note that these are just the objects in the database, although
! # there should be a corresponding content entry for every one of these
! # in the filesystem or database.
! sub directory_list {
my ( $class, $p ) = @_;
my $R = OpenInteract::Request->instance;
***************
*** 89,93 ****
my $selected_dir = $R->apache->param( 'selected_dir' );
my $params = { selected_dir => $selected_dir,
! error_msg => $p->{error_msg} };
$params->{dir_list} = eval { $R->page->list_directories };
--- 75,80 ----
my $selected_dir = $R->apache->param( 'selected_dir' );
my $params = { selected_dir => $selected_dir,
! error_msg => $p->{error_msg},
! status_msg => $p->{status_msg} };
$params->{dir_list} = eval { $R->page->list_directories };
***************
*** 95,98 ****
--- 82,86 ----
OpenIntereact::Error->set( SPOPS::Error->get );
$R->throw({ code => 403 });
+ $params->{error_msg} .= "\nCannot retrieve directories: $@";
$params->{dir_list} = [];
}
***************
*** 102,111 ****
if ( $selected_dir ) {
! $params->{children_files} = $R->static_page->fetch_iterator({
where => 'directory = ?',
value => [ $selected_dir ] });
}
! $R->{page}{title} = 'Listing of Documents';
return $R->template->handler( {}, $params,
{ name => 'page::page_directory_list' } );
--- 90,99 ----
if ( $selected_dir ) {
! $params->{children_files} = $R->page->fetch_iterator({
where => 'directory = ?',
value => [ $selected_dir ] });
}
! $R->{page}{title} = 'Document Listing';
return $R->template->handler( {}, $params,
{ name => 'page::page_directory_list' } );
***************
*** 113,121 ****
sub show {
my ( $class, $p ) = @_;
my $R = OpenInteract::Request->instance;
! my $params = { main_script => MAIN_SCRIPT,
! error_msg => $p->{error_msg},
status_msg => $p->{status_msg} };
--- 101,136 ----
+ # Yes, this is out of the normal order. It's just that show() is so
+ # big and includes so much stuff...
+
+ sub _edit_customize {
+ my ( $class, $page, $old_data ) = @_;
+ my %opts = ();
+
+ # If the user changed the location, then we need to set the ID so
+ # the UPDATE works properly.
+
+ if ( $page->{location} ne $old_data->{location} ) {
+ $opts{use_id} = $old_data->{location};
+ }
+
+ # Default the expires_on field
+
+ unless ( $page->{expires_on} ) {
+ my $expire_date = Class::Date->now + DEFAULT_EXPIRE;
+ $page->{expires_on} = $expire_date->strftime( '%Y-%m-%d' );;
+ }
+ return ( OK, \%opts );
+ }
+
+
+
+ # Why do we set the content-type when returning errors? See note on
+ # error content-type forcing in POD...
+
sub show {
my ( $class, $p ) = @_;
my $R = OpenInteract::Request->instance;
! my $params = { error_msg => $p->{error_msg},
status_msg => $p->{status_msg} };
***************
*** 123,178 ****
# directly, specified in a parameter or taken from the URL.
! my $location = $class->_clean_location( $class->_find_location( $p ) );
# Try and find a page object (just the metadata) matching with our
# location. Note that _find_page_object() will also treat
# $location as a directory request, where appropriate
-
- my $page = eval { $p->{page} || $class->_find_page_object( $location ) };
- my $error_type = $@;
- my $do_edit = ( $R->apache->param( 'edit' ) and
- $p->{level} >= SEC_LEVEL_WRITE );
-
- unless ( $page or $do_edit ) {
- $R->DEBUG && $R->scrib( 1, "",
- "Error type: ($error_type)" );
! # We have to force the content-type here because the user
! # might have requested a file that actually exists in the
! # filesystem and which Apache has already mapped a
! # content-type. You'll know when this happens because you'll
! # be prompted to d/l the file or a plugin (like Acrobat
! # Reader) will try to display it, but the *actual* content
! # will be plain old HTML...
!
$R->{page}{content_type} = 'text/html';
!
! if ( $error_type =~ /^security/ ) {
my $admin_email = $R->CONFIG->{mail}{admin_email};
! return <<FORBID;
! <h2>Access Forbidden</h2>
! <p>You do not have access rights to view this page. Please e-mail the
! administrator at <a href="mailto:$admin_email">$admin_email</a> if you
! feel you have received this message in error.</p>
! FORBID
}
! elsif ( $error_type =~ /^access/ ) {
return "<h2>Cannot Access</h2><p>Failure accessing page.</p>";
}
- return <<NOTFOUND;
- <h2>Page Not Found</h2>
- <p>Could not find page with location you requested
- (<tt>$location</tt>). Did you mistype the address?</p>
- NOTFOUND
}
# If we specified that we're going to send a separate file to the
# user (usually not HTML, text, etc.) then set the information and
# quit processing
! unless ( $class->_is_page_displayable( $page ) ) {
$R->{page}{send_file} = $page->{location};
! $R->DEBUG && $R->scrib( 1, "File being retrieved is not displayable.",
! "Set 'send_file' to $page->{location}" );
return undef;
}
--- 138,175 ----
# directly, specified in a parameter or taken from the URL.
! my $location = $class->_clean_location( $class->_find_location( $p ) );
# Try and find a page object (just the metadata) matching with our
# location. Note that _find_page_object() will also treat
# $location as a directory request, where appropriate
! my $page = $p->{page} || eval { $class->_find_page_object( $location ) };
! if ( $@ ) {
$R->{page}{content_type} = 'text/html';
! $R->DEBUG && $R->scrib( 1, "Could not retrieve page. Error ($@)" );
! if ( $@ =~ /^security/ ) {
my $admin_email = $R->CONFIG->{mail}{admin_email};
! return $class->_forbiden_message( $admin_email )
}
! elsif ( $@ =~ /^access/ ) {
return "<h2>Cannot Access</h2><p>Failure accessing page.</p>";
}
}
+ my $do_edit = $p->{edit} || $R->apache->param( 'edit' );
+ unless ( $page or $do_edit ) {
+ $R->{page}{content_type} = 'text/html';
+ return $class->_notfound_message( $location );
+ }
+
+
# If we specified that we're going to send a separate file to the
# user (usually not HTML, text, etc.) then set the information and
# quit processing
! unless ( $class->_is_displayable( $page ) ) {
$R->{page}{send_file} = $page->{location};
! $R->DEBUG && $R->scrib( 1, "File being retrieved is not directly displayable.",
! "Set 'send_file' to ($page->{location})" );
return undef;
}
***************
*** 180,184 ****
# We have a page and we can display it, so grab the content
! $page->load_content;
# Now figure out if we're editing or not
--- 177,181 ----
# We have a page and we can display it, so grab the content
! $page->content;
# Now figure out if we're editing or not
***************
*** 192,220 ****
if ( $do_edit ) {
$page ||= $R->page->new;
$params->{page} = $page;
$text_params = { name => 'page::page_form' };
$R->{page}{title} = 'Edit a Document';
- my $update_items = ( $page->is_saved ) ? eval { $page->fetch_updates( 5 ) } : [];
- foreach my $update_info ( @{ $update_items } ) {
- my $user = eval { $R->user->fetch( $update_info->[0] ) };
- my $username = ( $user ) ? $user->{login_name} : 'administrator';
- push @{ $params->{update_list} }, { login_name => $username, date => $update_info->[1] };
- }
}
else {
-
- # Ensure the page is viewable right now
-
unless ( $class->_is_active( $page ) ) {
$R->DEBUG && $R->scrib( 1, "Page is not currently active; return error" );
! $R->{page}{title} = 'Page not yet active';
! return '<h2 align="center">Not Active</h2><p>Sorry, this page is not currentlyactive.</p>';
}
! $R->{page}{title} = $page->{title};
# Allows the page to define the main template it will use; if
# the page doesn't define one then the main UI module will use
! # the default
$R->{page}{_template_name_} = $page->{main_template};
--- 189,209 ----
if ( $do_edit ) {
$page ||= $R->page->new;
+ $page->{is_file} ||= 'yes' if ( $page->CONFIG->{default_storage} eq 'file' );
$params->{page} = $page;
$text_params = { name => 'page::page_form' };
$R->{page}{title} = 'Edit a Document';
}
else {
unless ( $class->_is_active( $page ) ) {
$R->DEBUG && $R->scrib( 1, "Page is not currently active; return error" );
! $R->{page}{title} = 'Page not active';
! return '<h2 align="center">Not Active</h2><p>Sorry, this page is not active.</p>';
}
! $R->{page}{title} = $page->{title};
# Allows the page to define the main template it will use; if
# the page doesn't define one then the main UI module will use
! # the default for the current theme
$R->{page}{_template_name_} = $page->{main_template};
***************
*** 230,236 ****
# its content.
! if ( $page->{_template_status} eq NO_PARSE_STATUS ) {
! return $page->{content};
! }
return $R->template->handler( {}, $params, $text_params );
--- 219,223 ----
# its content.
! return $page->{content} if ( $page->{template_parse} eq 'no' );
return $R->template->handler( {}, $params, $text_params );
***************
*** 349,355 ****
$this_page .= <<PCOUNT;
<p align="right"><font size="-1">
! [% OI.comp( 'page_count', total_pages = $total_pages,
! url = '$page->{location}',
! current_pagenum = $current_pagenum ) %]
</font></p>
PCOUNT
--- 336,342 ----
$this_page .= <<PCOUNT;
<p align="right"><font size="-1">
! [%- PROCESS page_count( total_pages = $total_pages,
! url = '$page->{location}',
! current_pagenum = $current_pagenum ) -%]
</font></p>
PCOUNT
***************
*** 366,398 ****
my $box_string = $page->{boxes};
! # If this page has specified any boxes, push them onto the stack
! # unless they start with a '-', in which case set that name aside
! # so we can go through all of the boxes and remove it.
- my %box_remove = ();
if ( $box_string ) {
my @boxes = split /\s+/, $box_string;
foreach my $box_name ( @boxes ) {
next if ( $box_name =~ /^\s*$/ );
$R->DEBUG && $R->scrib( 1, "Adding box name ($box_name) from page definition" );
if ( $box_name =~ s/^\-// ) {
! $box_remove{ $box_name }++;
! }
! else {
! push @{ $R->{boxes} }, $box_name;
}
}
-
- # Go through ALL the boxes and do a removal if necessary
-
- # TODO: we should move this processing to base_box)
-
- my @box_keep = ();
- foreach my $box_info ( @{ $R->{boxes} } ) {
- next if ( ref $box_info and $box_remove{ $box_info->{name} } );
- next if ( ! ref $box_info and $box_remove{ $box_info } );
- push @box_keep, $box_info;
- }
- $R->{boxes} = \@box_keep;
}
--- 353,372 ----
my $box_string = $page->{boxes};
! # Add boxes as necessary -- names beginning with a '-' should be
! # tagged for removal
if ( $box_string ) {
+ $box_string =~ s/^\s+//;
my @boxes = split /\s+/, $box_string;
foreach my $box_name ( @boxes ) {
next if ( $box_name =~ /^\s*$/ );
$R->DEBUG && $R->scrib( 1, "Adding box name ($box_name) from page definition" );
+ my $box_params = { name => $box_name };
if ( $box_name =~ s/^\-// ) {
! $box_params->{name} = $box_name;
! $box_params->{remove} = 'yes';
}
+ push @{ $R->{boxes} }, $box_params
}
}
***************
*** 414,434 ****
return 1 unless ( $page->{active_on} );
! my $active = Class::Date::date([ split '-', $page->{active_on} ]);
my $now = Class::Date->now;
! my $expires = Class::Date::date([ split '-', $page->{expires_on} ]);
my $R = OpenInteract::Request->instance;
$R->DEBUG && $R->scrib( 1, "Active on: $active; Expires on: $expires" );
! return undef if ( $now < $active );
! return undef if ( $now > $expires );
! return 1;
}
! sub _edit_customize {
}
1;
--- 388,464 ----
return 1 unless ( $page->{active_on} );
! my $active = Class::Date::date([ split /\D/, $page->{active_on} ]);
my $now = Class::Date->now;
! my $expires = Class::Date::date([ split /\D/, $page->{expires_on} ]);
my $R = OpenInteract::Request->instance;
$R->DEBUG && $R->scrib( 1, "Active on: $active; Expires on: $expires" );
! return ( $active <= $now and $now <= $expires );
!
}
! sub _forbidden_message {
! my ( $class, $mail ) = @_;
! return <<FORBID;
! <h2>Access Forbidden</h2>
! <p>You do not have access rights to view this page. Please e-mail the
! administrator at <a href="mailto:$mail">$mail</a> if you feel you have
! received this message in error.</p>
! FORBID
}
+ sub _notfound_message {
+ my ( $class, $location ) = @_;
+ return <<NOTFOUND;
+ <h2>Page Not Found</h2>
+ <p>Could not find page with location you requested
+ (<tt>$location</tt>). Did you mistype the address?</p>
+ NOTFOUND
+ }
1;
+
+ =pod
+
+ =head1 NAME
+
+ =head1 SYNOPSIS
+
+ =head1 DESCRIPTION
+
+ =head2 Error Content-Type Forcing
+
+ We have to force the content-type when returning an error in C<show()>
+ because the user might have requested a file that actually exists in
+ the filesystem and which Apache has already mapped a content-type. You
+ will know when this happens because you will be prompted to d/l the
+ file or a plugin (like Acrobat Reader) will try to display it, but the
+ *actual* content will be plain old HTML...
+
+ =head1 METHODS
+
+ =head1 BUGS
+
+ None known.
+
+ =head1 TO DO
+
+ Nothing known.
+
+ =head1 SEE ALSO
+
+ =head1 COPYRIGHT
+
+ Copyright (c) 2001 intes.net, inc.. All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the same terms as Perl itself.
+
+ =head1 AUTHORS
+
+ Chris Winters <ch...@cw...>
+
+ =cut
|