Index: openacs-4/packages/acs-content-repository/tcl/filter-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/filter-procs.tcl,v diff -u -N -r1.16 -r1.17 --- openacs-4/packages/acs-content-repository/tcl/filter-procs.tcl 12 Mar 2004 13:44:55 -0000 1.16 +++ openacs-4/packages/acs-content-repository/tcl/filter-procs.tcl 25 Mar 2004 21:42:19 -0000 1.17 @@ -5,11 +5,13 @@ namespace eval content { -variable item_id -variable item_url -variable template_url -variable revision_id + variable item_id + variable item_url + variable template_url + variable revision_id +} + # Find the directory in the file system where templates are stored. # There are a variety of ways in which this can be set. The proc # looks for that directory in the following places in this order: @@ -22,214 +24,214 @@ # If the value resulting from the search does not start with a '/' # it is taken to be relative to [acs_root_dir] -ad_proc -public get_template_root {} { +ad_proc -public content::get_template_root {} { - # Look for package-defined root - set package_id [ad_conn package_id] - set template_root \ - [ad_parameter -package_id $package_id TemplateRoot dummy ""] + # Look for package-defined root + set package_id [ad_conn package_id] + set template_root \ + [ad_parameter -package_id $package_id TemplateRoot dummy ""] - if { [empty_string_p $template_root] } { - # Look for template root defined in the CR - set package_id [apm_package_id_from_key "acs-content-repository"] + if { [empty_string_p $template_root] } { + # Look for template root defined in the CR + set package_id [apm_package_id_from_key "acs-content-repository"] - set template_root [ad_parameter -package_id $package_id \ - TemplateRoot dummy "templates"] - } + set template_root [ad_parameter -package_id $package_id \ + TemplateRoot dummy "templates"] + } - if { [string index $template_root 0] != "/" } { - # Relative path, prepend server_root - set template_root "[acs_root_dir]/$template_root" - } + if { [string index $template_root 0] != "/" } { + # Relative path, prepend server_root + set template_root "[acs_root_dir]/$template_root" + } - return [ns_normalizepath $template_root] + return [ns_normalizepath $template_root] } # return true if the request has content associated with it -ad_proc -public has_content {} { +ad_proc -public content::has_content {} { - variable item_id + variable item_id - return [info exists item_id] -} + return [info exists item_id] +} -ad_proc -public get_item_id {} { +ad_proc -public content::get_item_id {} { - variable item_id + variable item_id - return $item_id -} + return $item_id +} -ad_proc -public get_content { { content_type {} } } { - - variable item_id - variable revision_id +ad_proc -public content::get_content { { content_type {} } } { - if { [template::util::is_nil item_id] } { - ns_log warning "content::get_content: No active item in content::get_content" - return - } + variable item_id + variable revision_id - # Get the live revision - set revision_id [db_string get_revision ""] + if { [template::util::is_nil item_id] } { + ns_log warning "content::get_content: No active item in content::get_content" + return + } - if { [template::util::is_nil revision_id] } { - ns_log notice "content::get_content: No live revision for item $item_id" - return - } + # Get the live revision + set revision_id [db_string get_revision ""] - # Get the mime type, decide if we want the text - set mime_type [db_string get_mime_type ""] - - if { [template::util::is_nil mime_type] } { - ns_log notice "content::get_content: No such revision: $revision_id" - return - } + if { [template::util::is_nil revision_id] } { + ns_log notice "content::get_content: No live revision for item $item_id" + return + } - if { [string equal -length 4 "text" $mime_type] } { - set text_sql [db_map content_as_text] - } else { - set text_sql "" - } - - # Get the content type - if { [empty_string_p $content_type] } { - set content_type [db_string get_content_type ""] - } + # Get the mime type, decide if we want the text + set mime_type [db_string get_mime_type ""] - # Get the table name - set table_name [db_string get_table_name ""] + if { [template::util::is_nil mime_type] } { + ns_log notice "content::get_content: No such revision: $revision_id" + return + } - upvar content content + if { [string equal -length 4 "text" $mime_type] } { + set text_sql [db_map content_as_text] + } else { + set text_sql "" + } - # Get (all) the content (note this is really dependent on file type) - if {![db_0or1row get_content "" -column_array content]} { - ns_log notice "content::get_content: No data found for item $item_id, revision $revision_id" - return 0 - } + # Get the content type + if { [empty_string_p $content_type] } { + set content_type [db_string get_content_type ""] + } + # Get the table name + set table_name [db_string get_table_name ""] + + upvar content content + + # Get (all) the content (note this is really dependent on file type) + if {![db_0or1row get_content "" -column_array content]} { + ns_log notice "content::get_content: No data found for item $item_id, revision $revision_id" + return 0 + } + } -ad_proc -public get_template_url {} { +ad_proc -public content::get_template_url {} { - variable template_url + variable template_url - return $template_url + return $template_url } # Set a data source in the calling frame with folder URL and label # Useful for generating a context bar -ad_proc -public get_folder_labels { { varname "folders" } } { - - variable item_id +ad_proc -public content::get_folder_labels { { varname "folders" } } { - # this repeats the query used to look up the item in the first place - # but there does not seem to be a clear way around this + variable item_id - # build the folder URL out as we iterate over the query - set query [db_map get_url] - db_multirow -extend {url} $varname ignore_get_url $query { - append url "$name/" - } + # this repeats the query used to look up the item in the first place + # but there does not seem to be a clear way around this + + # build the folder URL out as we iterate over the query + set query [db_map get_url] + db_multirow -extend {url} $varname ignore_get_url $query { + append url "$name/" + } } -ad_proc -public get_content_value { revision_id } { +ad_proc -public content::get_content_value { revision_id } { - db_transaction { - db_exec_plsql gcv_get_revision_id { - begin + db_transaction { + db_exec_plsql gcv_get_revision_id { + begin content_revision.to_temporary_clob(:revision_id); - end; - } + end; + } - # Query for values from a previous revision - set content [db_string gcv_get_previous_content ""] + # Query for values from a previous revision + set content [db_string gcv_get_previous_content ""] - } + } - return $content + return $content } -ad_proc -public init { urlvar rootvar {content_root ""} {template_root ""} {context "public"} {rev_id ""} {content_type ""} } { +ad_proc -public content::init { urlvar rootvar {content_root ""} {template_root ""} {context "public"} {rev_id ""} {content_type ""} } { - upvar $urlvar url $rootvar root_path + upvar $urlvar url $rootvar root_path - variable item_id - variable revision_id - - # if a .tcl file exists at this url, then don't do any queries - if { [file exists [ns_url2file "$url.tcl"]] } { - return 0 - } + variable item_id + variable revision_id - # cache this query persistently for 1 hour - db_0or1row get_item_info "" -column_array item_info + # if a .tcl file exists at this url, then don't do any queries + if { [file exists [ns_url2file "$url.tcl"]] } { + return 0 + } - # No item found, so do not handle this request - if { ![info exists item_info] } { - db_0or1row get_template_info "" -column_array item_info - - if { ![info exists item_info] } { - ns_log notice "content::init: no content found for url $url" - return 0 - } - } + # cache this query persistently for 1 hour + db_0or1row get_item_info "" -column_array item_info - variable item_url - set item_url $url + # No item found, so do not handle this request + if { ![info exists item_info] } { + db_0or1row get_template_info "" -column_array item_info - set item_id $item_info(item_id) - if { [empty_string_p $content_type] } { - set content_type $item_info(content_type) - } + if { ![info exists item_info] } { + ns_log notice "content::init: no content found for url $url" + return 0 + } + } - # Make sure that a live revision exists - if { [empty_string_p $rev_id] } { - set live_revision [db_string get_live_revision ""] + variable item_url + set item_url $url - if { [template::util::is_nil live_revision] } { - ns_log notice "content::init: no live revision found for content item $item_id" - return 0 - } - set revision_id $live_revision - } else { - set revision_id $rev_id - } + set item_id $item_info(item_id) + if { [empty_string_p $content_type] } { + set content_type $item_info(content_type) + } - variable template_path + # Make sure that a live revision exists + if { [empty_string_p $rev_id] } { + set live_revision [db_string get_live_revision ""] - # Get the template - set template_found_p [db_0or1row get_template_url "" -column_array info] + if { [template::util::is_nil live_revision] } { + ns_log notice "content::init: no live revision found for content item $item_id" + return 0 + } + set revision_id $live_revision + } else { + set revision_id $rev_id + } - if { !$template_found_p || [string equal $info(template_url) {}] } { - ns_log notice "content::init: No template found to render content item $item_id in context '$context'" - return 0 - } + variable template_path - set url $info(template_url) - set root_path [get_template_root] + # Get the template + set template_found_p [db_0or1row get_template_url "" -column_array info] - # Added so that published templates are regenerated if they are missing. - # This is useful for default templates. - # (OpenACS - DanW, dcwickstrom@earthlink.net) + if { !$template_found_p || [string equal $info(template_url) {}] } { + ns_log notice "content::init: No template found to render content item $item_id in context '$context'" + return 0 + } - set file ${root_path}/${url}.adp - if { ![file exists $file] } { + set url $info(template_url) + set root_path [get_template_root] - file mkdir [file dirname $file] - set text [content::get_content_value $info(template_id)] - template::util::write_file $file $text - } + # Added so that published templates are regenerated if they are missing. + # This is useful for default templates. + # (OpenACS - DanW, dcwickstrom@earthlink.net) - set file ${root_path}/${url}.tcl - if { ![file exists $file] } { + set file ${root_path}/${url}.adp + if { ![file exists $file] } { - file mkdir [file dirname $file] - set text "\# Put the current revision's attributes in a onerow datasource named \"content\". + file mkdir [file dirname $file] + set text [content::get_content_value $info(template_id)] + template::util::write_file $file $text + } + + set file ${root_path}/${url}.tcl + if { ![file exists $file] } { + + file mkdir [file dirname $file] + set text "\# Put the current revision's attributes in a onerow datasource named \"content\". \# The detected content type is \"$content_type\". content::get_content $content_type @@ -260,17 +262,13 @@ # render the template and write it to the file system -ad_proc -public deploy { url_stub } { - - set output_path [ns_info pageroot]$url_stub +ad_proc -public content::deploy { url_stub } { - init url_stub root_path + set output_path [ns_info pageroot]$url_stub - set output [template::adp_parse $file_stub] + init url_stub root_path - template::util::write_file $output_path $output -} + set output [template::adp_parse $file_stub] -# end of content namespace - + template::util::write_file $output_path $output }