• Publicity: Public Only All

filter-procs.tcl


Procedures in this file

Detailed information

content::deploy (public, deprecated)

 content::deploy url_stub
Deprecated. Invoking this procedure generates a warning.

render the template and write it to the filesystem with template::util::write_file DEPRECATED: since its birth ~2003 this proc refers to a nonexistent variable and is therefore broken.

Parameters:
url_stub
See Also:
  • modern ways to produce templated content e.g. theme packages or xowiki pages

Partial Call Graph (max 5 caller/called nodes):
%3 ad_log_deprecated ad_log_deprecated (public) content::init content::init (public) template::adp_parse template::adp_parse (public) template::util::write_file template::util::write_file (public) content::deploy content::deploy content::deploy->ad_log_deprecated content::deploy->content::init content::deploy->template::adp_parse content::deploy->template::util::write_file

Testcases:
No testcase defined.

content::get_content (public)

 content::get_content [ content_type ]

sets the content in the array "content" in the callers scope assumes item_id or revision_id is set in the ::content namespace.

Parameters:
content_type (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 acs_object_type::get_table_name acs_object_type::get_table_name (public) db_0or1row db_0or1row (public) db_map db_map (public) db_string db_string (public) template::util::is_nil template::util::is_nil (public) content::get_content content::get_content content::get_content->acs_object_type::get_table_name content::get_content->db_0or1row content::get_content->db_map content::get_content->db_string content::get_content->template::util::is_nil

Testcases:
No testcase defined.

content::get_content_value (public)

 content::get_content_value revision_id
Parameters:
revision_id
Returns:
content element corresponding to the provided revision_id

Partial Call Graph (max 5 caller/called nodes):
%3 content::init content::init (public) content::get_content_value content::get_content_value content::init->content::get_content_value db_exec_plsql db_exec_plsql (public) content::get_content_value->db_exec_plsql db_string db_string (public) content::get_content_value->db_string db_transaction db_transaction (public) content::get_content_value->db_transaction

Testcases:
No testcase defined.

content::get_item_id (public)

 content::get_item_id
Returns:
current value of ::content::item_id

Partial Call Graph (max 5 caller/called nodes):
%3

Testcases:
No testcase defined.

content::get_template_root (public)

 content::get_template_root

Find the directory in the filesystem 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: (1) the TemplateRoot parameter of the package for which the request is made, i.e., [ad_conn package_id] (2) the TemplateRoot parameter of the acs-content-repository If it is not found in any of these places, it defaults to $::acs::rootdir/templates If the value resulting from the search does not start with a '/' it is taken to be relative to $::acs::rootdir

Returns:
the template root (full path from /)

Partial Call Graph (max 5 caller/called nodes):
%3 content::init content::init (public) content::get_template_root content::get_template_root content::init->content::get_template_root publish::merge_with_template publish::merge_with_template (private) publish::merge_with_template->content::get_template_root ad_conn ad_conn (public) content::get_template_root->ad_conn apm_package_id_from_key apm_package_id_from_key (public) content::get_template_root->apm_package_id_from_key parameter::get parameter::get (public) content::get_template_root->parameter::get

Testcases:
No testcase defined.

content::get_template_url (public)

 content::get_template_url
Returns:
current value of ::content::template_url

Partial Call Graph (max 5 caller/called nodes):
%3

Testcases:
No testcase defined.

content::has_content (public)

 content::has_content

return true if the request has content associated with it

Returns:
1 if ::content::item_id is defined

Partial Call Graph (max 5 caller/called nodes):
%3

Testcases:
No testcase defined.

content::init (public)

 content::init [ -resolve_index resolve_index ] [ -revision revision ] \
    urlvar rootvar [ content_root ] [ template_root ] [ context ] \
    [ rev_id ] [ content_type ]

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
(defaults to "f") (optional)
-revision
(defaults to "live") (optional)
Parameters:
urlvar
rootvar
content_root (optional)
template_root (optional)
context (defaults to "public")
rev_id (optional)
content_type (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 content::deploy content::deploy (public, deprecated) content::init content::init content::deploy->content::init content::get_content_value content::get_content_value (public) content::init->content::get_content_value content::get_template_root content::get_template_root (public) content::init->content::get_template_root content::item::get_best_revision content::item::get_best_revision (public) content::init->content::item::get_best_revision content::item::get_content_type content::item::get_content_type (public) content::init->content::item::get_content_type content::item::get_id content::item::get_id (public) content::init->content::item::get_id

Testcases:
No testcase defined.
[ hide source ] | [ make this the default ]

Content File Source

###########
# Register the filter to automatically look up paths to content
# items and retrieve the appropriate item id
###########

namespace eval content {

    variable item_id
    variable item_url
    variable template_url
    variable revision_id
}




ad_proc -public content::get_template_root {} {
    Find the directory in the filesystem 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:
    (1) the TemplateRoot parameter of the package for which the request is
        made, i.e., [ad_conn package_id]
    (2) the TemplateRoot parameter of the acs-content-repository

    If it is not found in any of these places, it defaults to

    $::acs::rootdir/templates

    If the value resulting from the search does not start with a '/'
    it is taken to be relative to $::acs::rootdir

    @return the template root (full path from /)
} {
    # Look for package-defined root
    set package_id [ad_conn package_id]
    set template_root \
        [parameter::get -package_id $package_id -parameter TemplateRoot -default ""]

    if { $template_root eq "" } {
        # Look for template root defined in the CR
        set package_id [apm_package_id_from_key "acs-content-repository"]

        set template_root [parameter::get -package_id $package_id \
                               -parameter TemplateRoot -default "templates"]
    }

    if { [string index $template_root 0] ne "/" } {
        # Relative path, prepend server_root
        set template_root "$::acs::rootdir/$template_root"
    }

    return [ns_normalizepath $template_root]

}


ad_proc -public content::has_content {} {
    return true if the request has content associated with it

    @return 1 if ::content::item_id is defined
} { 
    variable item_id

    return [info exists item_id]
}

ad_proc -public content::get_item_id {} {
    @return current value of ::content::item_id
} {

    variable item_id

    return $item_id
}

ad_proc -public content::get_content { { content_type {} } } {
    sets the content in the array "content" in the callers scope
    assumes item_id or revision_id is set in the ::content namespace.

    @param content_type 
} {
    variable item_id
    variable revision_id

    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] } {
    # Try to get the live revision
    ns_log notice "content::get_content: trying to get live revision"
    set revision_id [db_string get_revision ""]
    if { [template::util::is_nil revision_id] } {
        ns_log notice "content::get_content: No live revision for item $item_id"
        return
    }
    }

    # 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 { [string equal -length 4 "text" $mime_type] } {
        set text_sql [db_map content_as_text]
    } else {
        set text_sql ""
    }

    # Get the content type
    if { $content_type eq "" } {
        set content_type [db_string get_content_type ""]
    }

    # Get the table name
    set table_name [acs_object_type::get_table_name \
                        -object_type $content_type]

    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 content::get_template_url {} {
    @return current value of ::content::template_url
} {
    variable template_url

    return $template_url
}



ad_proc -public content::get_content_value { revision_id } {
    @return content element corresponding to the provided revision_id
} { 
    db_transaction {
        db_exec_plsql gcv_get_revision_id {}

        # Query for values from a previous revision
        set content [db_string gcv_get_previous_content ""]

    }

    return $content
}


d_proc -public content::init {
    {-resolve_index "f"}
    {-revision "live"}
    urlvar
    rootvar
    {content_root ""}
    {template_root ""}
    {context "public"}
    {rev_id ""}
    {content_type ""}
} {
    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.
} {
    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 1
}



ad_proc -deprecated content::deploy { url_stub } {
    render the template and write it to the filesystem
    with template::util::write_file

    DEPRECATED: since its birth ~2003 this proc refers to a
    nonexistent variable and is therefore broken.

    @see modern ways to produce templated content e.g. theme packages or
         xowiki pages
} {
    set output_path $::acs::pageroot$url_stub

    init url_stub root_path

    set output [template::adp_parse $file_stub]

    template::util::write_file $output_path $output
}

# Local variables:
#    mode: tcl
#    tcl-indent-level: 4
#    indent-tabs-mode: nil
# End: