|
From: Chris W. <la...@us...> - 2001-10-25 14:58:52
|
Update of /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Handler
In directory usw-pr-cvs1:/tmp/cvs-serv22007/OpenInteract/Handler
Modified Files:
Page.pm
Log Message:
deal with uploaded files
Index: Page.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Handler/Page.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Page.pm 2001/10/24 23:04:14 1.4
--- Page.pm 2001/10/25 14:58:50 1.5
***************
*** 46,49 ****
--- 46,52 ----
sub MY_ALLOW_SEARCH_FORM { return 1 }
sub MY_ALLOW_SEARCH { return 1 }
+ sub MY_ALLOW_CREATE { return 1 }
+ sub MY_OBJECT_CREATE_SECURITY { return SEC_LEVEL_WRITE }
+ sub MY_ALLOW_SHOW { return 1 }
sub MY_ALLOW_EDIT { return 1 }
sub MY_ALLOW_REMOVE { return 1 }
***************
*** 106,109 ****
--- 109,114 ----
sub _edit_customize {
my ( $class, $page, $old_data ) = @_;
+ my $R = OpenInteract::Request->instance;
+
my %opts = ();
***************
*** 121,124 ****
--- 126,153 ----
$page->{expires_on} = $expire_date->strftime( '%Y-%m-%d' );;
}
+
+ # See if the upload should be there
+
+ # TODO: Modify the save() methods in OI::Page::Blah to take a
+ # filehandle in 'content' as well as plain old text.
+
+ my $has_upload = $class->_read_field_toggled( $R->apache, 'use_upload' );
+ if ( $has_upload eq 'yes' ) {
+ $R->DEBUG && $R->scrib( 1, "User is requesting content from uploaded file..." );
+ my $upload = $R->apache->upload( 'content_upload' );
+ unless ( $upload ) {
+ my $error_msg = 'You checked off that you wanted to upload a ' .
+ 'file but did not upload one. Why are you teasing me?';
+ my %error_opts = ( method => 'show', error_msg => $error_msg, edit => 1 );
+ return ( ERROR, \%error_opts );
+ }
+ $R->DEBUG && $R->scrib( 1, "Upload seems to be retrieved ok. Here is some info:\n",
+ "Filename: (", $upload->filename, ") Size: (",
+ $upload->size, ") Type: (", $upload->type, ")" );
+ $page->{content} = $upload->fh;
+ }
+
+ $page->{mime_type} ||= 'text/html';
+
return ( OK, \%opts );
}
***************
*** 161,166 ****
$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
--- 190,196 ----
$R->{page}{content_type} = 'text/html';
return $class->_notfound_message( $location );
! }
+ $page ||= $R->page->new;
# If we specified that we're going to send a separate file to the
***************
*** 185,229 ****
# user can do so.
- my $text_params = {};
-
if ( $do_edit ) {
$page ||= $R->page->new;
$page->{is_file} ||= 'yes' if ( $page->CONFIG->{default_storage} eq 'file' );
$params->{page} = $page;
- $text_params = { name => 'base_page::page_form' };
$R->{page}{title} = 'Edit a Document';
}
- else {
- $R->DEBUG && $R->scrib( 1, "Display ($page->{location}) as normal HTML" );
- 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};
! # You can split your page into multiple viewable pages -- see
! # _split_pages() for more info
! $text_params = { text => $class->_split_pages( $page ) };
! $class->_add_object_boxes( $page, $p );
! }
! # If the page has told us not to run it through TT, just return
! # its content.
! return $page->{content} if ( $page->{template_parse} eq 'no' );
! return $R->template->handler( {}, $params, $text_params );
}
sub _is_displayable {
my ( $class, $page ) = @_;
--- 215,260 ----
# user can do so.
if ( $do_edit ) {
+ $R->DEBUG && $R->scrib( 1, "This page should be in an editable form" );
$page ||= $R->page->new;
$page->{is_file} ||= 'yes' if ( $page->CONFIG->{default_storage} eq 'file' );
$params->{page} = $page;
$R->{page}{title} = 'Edit a Document';
+ return $R->template->handler( {}, $params, { name => 'base_page::page_form' } );
}
! # Otherwise, ensure the page is active, set metadata and send it
! # off to be displayed
! $R->DEBUG && $R->scrib( 1, "Display ($page->{location}) as normal HTML" );
! 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};
! $class->_add_object_boxes( $page, $p );
! # You can split your page into multiple viewable pages -- see
! # _split_pages() for more info
! my $display_content = $class->_split_pages( $page );
!
! return $display_content if ( $page->{template_parse} eq 'no' );
! return $R->template->handler( {}, $params, { text => \$display_content } );
}
+ # True means page is displayable in browser, false means it's not. We
+ # treat an empty mime_type as an HTML page. (Might change)
+
sub _is_displayable {
my ( $class, $page ) = @_;
***************
*** 234,238 ****
! # Find the location from whatever paramters, information we need
sub _find_location {
--- 265,270 ----
! # Find the location from whatever is available -- passed parameters,
! # GET/POST parameters, or the original path
sub _find_location {
***************
*** 313,316 ****
--- 345,351 ----
}
}
+
+ # Returning undef means there were no errors, we just didn't find the page
+
return undef unless ( $error_type );
die $error_type;
***************
*** 318,321 ****
--- 353,358 ----
+ # Lop off the query string from $text
+
sub _remove_query_string {
my ( $class, $text ) = @_;
***************
*** 325,328 ****
--- 362,369 ----
+ # A page can have one or more tags that declare it wants itself split
+ # into multiple pieces for display. This routine does the
+ # splitting. This is still under development...
+
sub _split_pages {
my ( $class, $page ) = @_;
***************
*** 345,351 ****
</font></p>
PCOUNT
! return \$this_page;
}
! return \$page->{content};
}
--- 386,392 ----
</font></p>
PCOUNT
! return $this_page;
}
! return $page->{content};
}
***************
*** 426,437 ****
--- 467,487 ----
1;
+ __END__
+
=pod
=head1 NAME
+ OpenInteract::Handler::Page - Display HTML pages and other documents from the database and/or filesystem
+
=head1 SYNOPSIS
=head1 DESCRIPTION
+ Displays a 'static' page from information in the database. The URL to
+ the page looks like a normal page rather than a database call or other
+ GET request, although it B<can> look like a GET request if you want it
+ to.
+
=head2 Error Content-Type Forcing
***************
*** 445,448 ****
--- 495,520 ----
=head1 METHODS
+ We use L<OpenInteract::CommonHandler|OpenInteract::CommonHandler> but
+ override the C<show()> method for our special needs.
+
+ B<directory_list>: implemented in this class
+
+ B<search_form>: implemented in
+ L<OpenInteract::CommonHandler|OpenInteract::CommonHandler>
+
+ B<search>: implemented in
+ L<OpenInteract::CommonHandler|OpenInteract::CommonHandler>
+
+ B<show>: implemented in this class
+
+ B<edit>: implemented in
+ L<OpenInteract::CommonHandler|OpenInteract::CommonHandler>
+
+ B<remove>: implemented in
+ L<OpenInteract::CommonHandler|OpenInteract::CommonHandler>
+
+ B<notify>: implemented in
+ L<OpenInteract::CommonHandler|OpenInteract::CommonHandler>
+
=head1 BUGS
***************
*** 454,457 ****
--- 526,531 ----
=head1 SEE ALSO
+
+ L<OpenInteract::CommonHandler|OpenInteract::CommonHandler>
=head1 COPYRIGHT
|