content::init (public)
content::init [ -resolve_index resolve_index ] [ -revision revision ] \ urlvar rootvar [ content_root ] [ template_root ] [ context ] \ [ rev_id ] [ content_type ]
Defined in packages/acs-content-repository/tcl/filter-procs.tcl
Initialize the namespace variables for the ::content procs and figures out which template to use and set up the template for the required content type etc.
- Switches:
- -resolve_index (optional, defaults to
"f"
)- -revision (optional, defaults to
"live"
)- Parameters:
- urlvar (required)
- rootvar (required)
- content_root (optional)
- template_root (optional)
- context (optional, defaults to
"public"
)- rev_id (optional)
- content_type (optional)
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: upvar $urlvar url $rootvar root_path variable root_folder_id variable item_id variable revision_id set root_folder_id $content_root # if a .tcl file exists at this url, then don't do any queries if { [file exists [ns_url2file "$url.tcl"]] } { return 0 } # cache this query persistently for 1 hour set item_info(item_id) [::content::item::get_id -item_path $url -root_folder_id $content_root -resolve_index $resolve_index] set item_info(content_type) [::content::item::get_content_type -item_id $item_info(item_id)] # No item found, so do not handle this request if {$item_info(item_id) eq ""} { set item_info(item_id) [::content::item::get_id -item_path $url -root_folder_id $content_root -resolve_index $resolve_index] set item_info(content_type) [::content::item::get_content_type -item_id $item_info(item_id)] if {$item_info(item_id) eq ""} { ns_log notice "content::init: no content found for url $url" return 0 } } variable item_url set item_url $url set item_id $item_info(item_id) if { $content_type eq "" } { set content_type $item_info(content_type) } # TODO accept latest revision as well. DaveB # Make sure that a live revision exists if { $rev_id eq "" } { if {"best" eq $revision} { # latest_revision unless live_revision is set, then live_revision set revision_id [::content::item::get_best_revision -item_id $item_id] } else { # default live_revision set revision_id [::content::item::get_live_revision -item_id $item_id] } if {$revision_id eq ""} { ns_log notice "content::init: no live revision found for content item $item_id" return 0 } } else { set revision_id $rev_id } variable template_path # Get the template set template_found_p [db_0or1row get_template_url "" -column_array info] if { !$template_found_p || $info(template_url) eq {} } { ns_log notice "content::init: No template found to render content item $item_id in context '$context'" return 0 } set url $info(template_url) set root_path [get_template_root] # 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}.adp if { ![file exists $file] } { 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 if { \"text/html\" ne \$content(mime_type) && !\[ad_html_text_convertible_p -from \$content(mime_type) -to text/html\] } { \# don't render its content cr_write_content -revision_id \$content(revision_id) ad_script_abort } \# Ordinary text/* mime type. foreach {key value} [array get content] { set $key $value } set text \[cr_write_content -string -revision_id \$revision_id\] if { !\[string equal \"text/html\" \$content(mime_type)\] } { set text \[ad_html_text_convert -from \$content(mime_type) -to text/html -- \$text\] } set context \[list \$title\] ad_return_template " template::util::write_file $file $text } return 1Generic XQL file: packages/acs-content-repository/tcl/filter-procs.xql
PostgreSQL XQL file: <fullquery name="content::init.get_template_url"> <querytext> select content_item__get_live_revision(content_item__get_template(:item_id, :context)) as template_id, content_template__get_path(content_item__get_template(:item_id, :context),:template_root) as template_url from dual </querytext> </fullquery>packages/acs-content-repository/tcl/filter-procs-postgresql.xql
Oracle XQL file: <fullquery name="content::init.get_template_url"> <querytext> select content_item.get_live_revision(content_item.get_template(:item_id, :context)) as template_id, content_template.get_path(content_item.get_template(:item_id, :context), :template_root) as template_url from dual </querytext> </fullquery>packages/acs-content-repository/tcl/filter-procs-oracle.xql