Index: openacs-4/packages/static-pages/static-pages.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/static-pages/static-pages.info,v diff -u -r1.18 -r1.19 --- openacs-4/packages/static-pages/static-pages.info 25 Mar 2004 10:52:47 -0000 1.18 +++ openacs-4/packages/static-pages/static-pages.info 29 Apr 2004 14:25:45 -0000 1.19 @@ -7,7 +7,7 @@ f f - + oracle postgresql @@ -17,67 +17,19 @@ Support searchable and commentable static site content. 2002-12-11 OpenACS - Static Pages loads the static pages of a site into the database so that their contents are available to other packages, such as site-wide-search. It also allows users to make comments on static pages. + Static Pages loads the static content of a site from the filesystem into the database so that their contents are available to other packages, such as search and general-comments, and allows static content to be wrapped by the master template to provide persistent navigation. + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + Index: openacs-4/packages/static-pages/tcl/static-pages-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/static-pages/tcl/static-pages-procs.tcl,v diff -u -r1.14 -r1.15 --- openacs-4/packages/static-pages/tcl/static-pages-procs.tcl 1 Nov 2003 08:45:39 -0000 1.14 +++ openacs-4/packages/static-pages/tcl/static-pages-procs.tcl 29 Apr 2004 14:25:45 -0000 1.15 @@ -750,14 +750,20 @@ # TemplatingEnabledP, need to know the package_id of the # static-pages instance where this page is located, which is # likely NOT the package_id returned by [ad_conn package_id]: - foreach [list page_id package_id] \ [util_memoize [list sp_get_page_id $sp_filename]] { break } + set templating_enabled_p [parameter::get -package_id $package_id -parameter TemplatingEnabledP -default 0] + set comment_p [parameter::get -package_id $package_id -parameter CommentsDisplayedP -default 1] + set file [ad_conn file] ad_conn -set subsite_id [site_node_closest_ancestor_package "acs-subsite"] # If the page is in the db, serve it carefully; otherwise just dump it out. + # We are careful to use ns_returnfile if possible since it is much more + # efficient than reading the whole file into a tcl string and doing ns_return, + # plus it will give 304's if the file is unchanged. + if { $page_id >= 0 } { set page_info [util_memoize [list sp_get_page_info_query $page_id]] @@ -769,58 +775,73 @@ # general_comments_create privilege on the page. Why the_public # rather than the current user? Because we don't want admins to # be seeing "Add a comment" links on non-commentable pages. - # - set comment_link "" - if { [ad_permission_p -user_id [acs_magic_object the_public] $page_id general_comments_create] } { - append comment_link "
[general_comments_create_link -object_name [lindex $page_info 0] $page_id [ad_conn url]]
" + set comment_link "" + if { $comment_p } { + if { [ad_permission_p -user_id [acs_magic_object the_public] $page_id general_comments_create] } { + append comment_link "
[general_comments_create_link -object_name [lindex $page_info 0] $page_id [ad_conn url]]
" + } + append comment_link "[general_comments_get_comments -print_content_p [lindex $page_info 1] $page_id [ad_conn url]]" } - append comment_link "[general_comments_get_comments -print_content_p [lindex $page_info 1] $page_id [ad_conn url]]" - - if { [catch { - set fp [open $filename r] - set file_contents [read $fp] - close $fp - } errmsg] } { - ad_return_error "Error reading file" \ + # Here if comment_link is empty and we are not templating, just ns_returnfile. + if {[empty_string_p $comment_link] + && ! $templating_enabled_p } { + ns_returnfile 200 text/html $filename + return + } else { + if { [catch { + set fp [open $filename r] + set file_contents [read $fp] + close $fp + } errmsg] } { + ad_return_error "Error reading file" \ "This error was encountered while reading $filename: $errmsg" - } + } - # Tcl needs a case-insensitive [string first] function. - # - set body_close [string first "= 0 } { - set body "[string range $file_contents 0 [expr $body_close-1]]${comment_link}[string range $file_contents $body_close end]" - } else { - set body "${file_contents}$comment_link" + + # Tcl needs a case-insensitive [string first] function. + # + set body_close [string first "= 0 } { + set body "[string range $file_contents 0 [expr $body_close-1]]${comment_link}[string range $file_contents $body_close end]" + } else { + set body "${file_contents}$comment_link" + } } } else { - set body [template::util::read_file $file] + if { ! $templating_enabled_p } { + # doing ns_returnfile here means we will get 304's when we can + ns_returnfile 200 text/plain $file + return {} + } else { + set body [template::util::read_file $file] + } } - set templating_enabled [ad_parameter -package_id $package_id TemplatingEnabledP] - if { ![empty_string_p $templating_enabled] && $templating_enabled } { + # If we did not return a file directly above we need to return the body, possibly after + # wrapping it in the master template. + if { $templating_enabled_p } { # Strip out the .. part as page will now be part of a master template set headers "" set sp_scripts "" set title "" if {[regexp -nocase {(.*?)(.*)} $body match headers bodyless]} { set body $bodyless - } + } # Get 0 or 1 ... data to pass up to master template html headers regexp -nocase {(.*?)} $headers match title - + # Get 0 or more tags to pass up to master template html headers while {[regexp -nocase {(.*?)(.*$)} $headers match ascript headers]} { append sp_scripts "\n$ascript" - } - set file_mtime [clock format [file mtime $file]] - set result [template::adp_parse [acs_root_dir]/[ad_parameter -package_id $package_id TemplatePath] [list body $body sp_scripts $sp_scripts title $title file_mtime $file_mtime]] - ns_return 200 text/html $result - } else { - ns_return 200 text/html $body + } + + set file_mtime [clock format [file mtime $file]] + + set body [template::adp_parse [acs_root_dir]/[ad_parameter -package_id $package_id TemplatePath] [list body $body sp_scripts $sp_scripts title $title file_mtime $file_mtime page_id $page_id] ] } + ns_return 200 text/html $body } Index: openacs-4/packages/static-pages/www/templates/static.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/static-pages/www/templates/static.adp,v diff -u -r1.3 -r1.4 --- openacs-4/packages/static-pages/www/templates/static.adp 20 Apr 2004 21:13:55 -0000 1.3 +++ openacs-4/packages/static-pages/www/templates/static.adp 29 Apr 2004 14:25:45 -0000 1.4 @@ -1,5 +1,6 @@ @sp_scripts;noquote@ @title;noquote@ +@page_id@ @body;noquote@
Last modified: @file_mtime@