Index: openacs-4/packages/acs-content-repository/tcl/publish-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/publish-procs.tcl,v
diff -u -N -r1.16 -r1.17
--- openacs-4/packages/acs-content-repository/tcl/publish-procs.tcl 1 May 2018 08:31:43 -0000 1.16
+++ openacs-4/packages/acs-content-repository/tcl/publish-procs.tcl 8 May 2018 22:37:18 -0000 1.17
@@ -1,37 +1,37 @@
namespace eval publish {
- variable item_id_stack
+ variable item_id_stack
variable revision_html
namespace eval handle {}
}
ad_proc -public publish::get_page_root {} {
- Get the page root. All items will be published to the
+ Get the page root. All items will be published to the
filesystem with their URLs relative to this root.
The page root is controlled by the PageRoot parameter in CMS.
A relative path is relative to $::acs::pageroot
The default is $::acs::pageroot
-
+
@return The page root
-
+
@see publish::get_template_root
@see publish::get_publish_roots
} {
# LARS TODO: This parameter doesn't exist, it's a remnant from the CMS package
set root_path [parameter::get \
-package_id [ad_conn package_id] \
-parameter PageRoot]
-
+
if { [string index $root_path 0] ne "/" } {
# Relative path, prepend server_root
set root_path "$::acs::pageroot/$root_path"
}
-
+
return [ns_normalizepath $root_path]
-
+
}
@@ -41,22 +41,22 @@
which should be a space-separated list of all the roots. Relative paths
are relative to publish::get_page_root.
The default is [list [publish::get_page_root]]
-
+
@return A list of all the publish roots
-
+
@see publish::get_template_root
@see publish::get_page_root
-
+
} {
# LARS TODO: This parameter doesn't exist, it's a remnant from the CMS package
set root_paths [parameter::get \
-package_id [ad_conn package_id] \
-parameter PublishRoots]
-
+
if { [llength $root_paths] == 0 } {
set root_paths [list [get_page_root]]
}
-
+
# Resolve relative paths
set page_root [publish::get_page_root]
set absolute_paths [list]
@@ -67,19 +67,19 @@
lappend absolute_paths $path
}
}
-
+
return $absolute_paths
}
ad_proc -public publish::mkdirs { path } {
Create all the directories necessary to save the specified file
-
+
@param path The path to the file that is about to be saved
} {
set index [string last "/" $path]
if { $index != -1 } {
file mkdir [string range $path 0 $index-1]
- }
+ }
}
###############################################
@@ -90,25 +90,25 @@
ad_proc -private publish::push_id { item_id {revision_id ""}} {
@private push_id
-
+
Push an item id on top of stack. This proc is used
to store state between child, relation
and content tags.
-
- @param item_id
+
+ @param item_id
The id to be put on stack
-
- @param revision_id {default ""}
+
+ @param revision_id {default ""}
The id of the revision to use. If missing, live
revision will most likely be used
-
- @see publish::pop_id
+
+ @see publish::pop_id
@see publish::get_main_item_id
@see publish::get_main_revision_id
} {
- variable item_id_stack
- variable revision_html
+ variable item_id_stack
+ variable revision_html
if { [template::util::is_nil item_id] } {
error "Null id pushed on stack in publish::push_id"
@@ -121,7 +121,7 @@
if { [info exists ::content::item_id] } {
set old_item_id $::content::item_id
}
-
+
if { [info exists ::content::revision_id] } {
set old_revision_id $::content::revision_id
}
@@ -151,34 +151,33 @@
ad_proc -private publish::pop_id {} {
@private pop_id
-
+
Pop the item_id and the revision_id off the top of the stack.
Clear the temporary item cache if the stack becomes empty.
-
+
@return The popped item id, or the empty string if the string is
already empty
-
- @see publish::push_id
+
+ @see publish::push_id
@see publish::get_main_item_id
@see publish::get_main_revision_id
} {
- variable item_id_stack
+ variable item_id_stack
set pair [lindex $item_id_stack 0]
if { [template::util::is_nil pair] } {
#error "Item id stack is empty in publish::pop_id"
}
-
+
set item_id_stack [lrange $item_id_stack 1 end]
# If the stack is now empty, clear the cache
if { [template::util::is_nil item_id_stack] } {
array unset revision_html
}
- set ::content::item_id [lindex $pair 0]
- set ::content::revision_id [lindex $pair 1]
+ lassign $pair ::content::item_id ::content::revision_id
return $::content::item_id
}
@@ -187,14 +186,14 @@
ad_proc -public publish::proc_exists { namespace_name proc_name } {
@public proc_exists
-
+
Determine if a procedure exists in the given namespace
-
+
@param namespace_name The fully qualified namespace name,
such as "template::util"
-
+
@param proc_name The proc name, such as "is_nil"
-
+
@return 1 if the proc exists in the given namespace, 0 otherwise
} {
@@ -208,61 +207,61 @@
#
-ad_proc -public publish::handle_binary_file {
- item_id revision_id_ref url_ref error_ref args
+ad_proc -public publish::handle_binary_file {
+ item_id revision_id_ref url_ref error_ref args
} {
@public handle_binary_file
-
+
Helper procedure for writing handlers for binary files.
It will write the blob of the item to the filesystem,
but only if -embed is specified. Then, it will attempt to
merge the image with its template.
This proc accepts exactly the same options a typical handler.
-
- @param item_id
+
+ @param item_id
The id of the item to handle
-
- @param revision_id_ref {required}
+
+ @param revision_id_ref {required}
The name of the variable in the calling frame that will
receive the revision_id whose content blob was written
- to the filesystem.
-
- @param url_ref
+ to the filesystem.
+
+ @param url_ref
The name of the variable in the calling frame that will
receive the relative URL of the file in the file system
which contains the content blob
-
- @param error_ref
+
+ @param error_ref
The name of the variable in the calling frame that will
receive an error message. If no error has occurred, this
variable will be set to the empty string ""
-
- @option embed
+
+ @option embed
Signifies that the content should be embedded directly in
- the parent item. -embed is required for this
+ the parent item. -embed is required for this
proc, since it makes no sense to handle the binary file
in any other way.
-
+
@option revision_id {default The live revision for the item}
The revision whose content is to be used
-
- @option no_merge
+
+ @option no_merge
If present, do NOT merge with the template, in order to
- prevent infinite recursion in the <content> tag. In
+ prevent infinite recursion in the <content> tag. In
this case, the proc will return the empty string ""
-
- @return The HTML resulting from merging the item with its
+
+ @return The HTML resulting from merging the item with its
template, or "" if no template exists or the -no_merge
flag was specified
-
- @see publish::handle::image
+ @see publish::handle::image
+
} {
template::util::get_opts $args
- upvar $error_ref error_msg
+ upvar $error_ref error_msg
upvar $url_ref file_url
upvar $revision_id_ref revision_id
set error_msg ""
@@ -272,14 +271,14 @@
} else {
set revision_id $opts(revision_id)
}
-
+
# If the embed tag is true, return the html. Otherwise,
# just write the image to the filesystem
if { [info exists opts(embed)] } {
set file_url [publish::write_content $revision_id \
-item_id $item_id -root_path [publish::get_publish_roots]]
-
+
# If write_content aborted, give up
if { [template::util::is_nil file_url] } {
set error_msg "No URL found for revision $revision_id, item $item_id"
@@ -293,8 +292,8 @@
return $html
}
- return ""
-
+ return ""
+
} else {
set error_msg "No embed specified for handle_binary_file, aborting"
return ""
@@ -305,14 +304,14 @@
ad_proc -private publish::html_args { argv } {
@private html_args
-
+
Concatenate a list of name-value pairs as returned by
set_to_pairs into a list of "name=value" pairs
-
+
@param argv The list of name-value pairs
-
+
@return An HTML string in format "name=value name=value ..."
-
+
@see publish::set_to_pairs
} {
@@ -321,7 +320,7 @@
foreach { name value } $argv {
append extra_html "$name=\"$value\" "
}
- }
+ }
return $extra_html
}
@@ -330,21 +329,21 @@
ad_proc -public publish::item_include_tag { item_id {extra_args {}} } {
@public item_include_tag
-
+
Create an include tag to include an item, in the form
- include src=/foo/bar/baz item_id=item_id + include src=/foo/bar/baz item_id=item_id param=value param=value ...- + @param item_id The item id - + @param extra_args {} A list of extra parameters to be passed to the include tag, in form {name value name value ...} - + @return The HTML for the include tag - + @see content::item::get_virtual_path @see publish::html_args @@ -361,12 +360,12 @@ The basic image handler. Writes the image blob to the filesystem, then either merges with the template or provides a default - tag. Uses the title for alt text if no alt text is specified + tag. Uses the title for alt text if no alt text is specified externally. } { template::util::get_opts $args - + # LARS TODO: Added -no_merge, verify how this is supposed to work set html [publish::handle_binary_file \ $item_id revision_id url error_msg {*}$args -no_merge] @@ -405,36 +404,36 @@ } append html " $extra_html" - + # Append the alt text if needed if { !$have_alt } { append html " alt=\"$image_alt\"" } - + append html ">" return $html } -ad_proc -private publish::merge_with_template { item_id args } { +ad_proc -private publish::merge_with_template { item_id args } { @private merge_with_template - + Merge the item with its template and return the resulting HTML. This proc is similar to content::init - + @param item_id The item id - - @option revision_id {default The live revision} + + @option revision_id {default The live revision} The revision which is to be used when rendering the item - + @option html Extra HTML parameters to be passed to the ADP parser, in format {name value name value ...} - + @return The rendered HTML, or the empty string on failure - + @see publish::handle_item } { @@ -450,12 +449,12 @@ set revision_id [::content::item::get_live_revision -item_id $item_id] } - # Get the template + # Get the template set ::content::template_url [::content::item::get_template -item_id $item_id -use_context public] - if {$::content::template_url eq {}} { + if {$::content::template_url eq {}} { ns_log Warning "publish::merge_with_template: no template for item $item_id" - return "" + return "" } ns_log debug "publish::merge_with_template: template for item $item_id is $::content::template_url" @@ -479,9 +478,9 @@ return $html } - + ad_proc -public publish::handle::text { item_id args } { Return the text body of the item @@ -494,7 +493,7 @@ set revision_id [::content::item::get_live_revision -item_id $item_id] } else { set revision_id $opts(revision_id) - } + } if { [info exists opts(embed)] } { # Render the child item and embed it in the code @@ -508,7 +507,7 @@ # Query for values from a previous revision set html [db_string get_previous_content ""] } - } + } } else { # Just create an include tag @@ -519,9 +518,9 @@ } else { set extra_args "" } - + set html [publish::item_include_tag $item_id $extra_args] - } + } return $html } @@ -530,37 +529,36 @@ ad_proc -public publish::get_mime_handler { mime_type } { @public get_mime_handler - + Return the name of a proc that should be used to render items with the given mime-type. The mime type handlers should all follow the naming convention - +
proc publish::handle::mime_prefix::mime_suffix- + If the specific mime handler could not be found, get_mime_handler looks for a generic procedure with the name - +
proc publish::handle::mime_prefix- - If the generic mime handler does not exist either, + + If the generic mime handler does not exist either, get_mime_handler returns "" - - @param mime_type + + @param mime_type The full mime type, such as "text/html" or "image/jpg" - + @return The name of the proc which should be used to handle the mime-type, or an empty string on failure. - + @see publish::handle_item } { set mime_pair [split $mime_type "/"] - set mime_prefix [lindex $mime_pair 0] - set mime_suffix [lindex $mime_pair 1] + lassign $mime_pair mime_prefix mime_suffix # Look for the specific handler if { [proc_exists "::publish::handle::${mime_prefix}" $mime_suffix] } { @@ -580,13 +578,13 @@ ad_proc -private publish::get_main_item_id {} { @private get_main_item_id - + Get the main item id from the top of the stack - + @return the main item id - - @see publish::pop_id - @see publish::push_id + + @see publish::pop_id + @see publish::push_id @see publish::get_main_revision_id } { @@ -604,13 +602,13 @@ ad_proc -private publish::get_main_revision_id {} { @private get_main_revision_id - + Get the main item revision from the top of the stack - + @return the main item id - - @see publish::pop_id - @see publish::push_id + + @see publish::pop_id + @see publish::push_id @see publish::get_main_item_id } { @@ -630,27 +628,27 @@ @private handle_item Render an item either by looking it up in the temporary cache, - or by using the appropriate mime handler. Once the item is rendered, it + or by using the appropriate mime handler. Once the item is rendered, it is stored in the temporary cache under a key which combines the item_id, any extra HTML parameters, and a flag which specifies whether the item was merged with its template.