Index: openacs-4/packages/static-pages/www/page-visit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/static-pages/www/page-visit.tcl,v
diff -u -N -r1.4 -r1.4.2.1
--- openacs-4/packages/static-pages/www/page-visit.tcl 18 Sep 2002 12:03:33 -0000 1.4
+++ openacs-4/packages/static-pages/www/page-visit.tcl 12 Dec 2002 22:40:48 -0000 1.4.2.1
@@ -25,5 +25,64 @@
#}
-ad_returnredirect $filename
+#ad_returnredirect $filename
+
+ad_proc -private sp_package_url {package_key} {
+
Given a package key, return a URL of a mounted
+ package instance. If there is more than one instance
+ of the package mounted, the one with the lowest
+ package_id
will be returned. If the
+ package is not instantiated or not mounted anywhere,
+ an error is raised. The proc is meant to be memoized.
+
+} {
+ set proc_name {sp_package_url}
+
+ set found_p [db_0or1row get_any_package_instance {
+ select min(package_id) as package_id
+ from apm_packages
+ where package_key = :package_key
+ }]
+
+ if { !$found_p } {
+ error "$proc_name: the '$package_key' package is not instantiated."
+ }
+
+ set found_p [db_0or1row get_mount_point {
+ select site_node.url(min(node_id)) as url
+ from site_nodes
+ where object_id = :package_id
+ }]
+
+ if { !$found_p } {
+ error "$proc_name: the '$package_key' package is not mounted."
+ }
+
+ return $url
+}
+
+
+# There are two possiblities: Either the static page is beneath the
+# site global www/ directory (and the filename starts "/www/"), or it
+# is beneath one of the package www directories (and the filename
+# starts "/packages/":
+
+if { [string first "/www/" $filename] == 0 } {
+ set redirect_to [string range $filename [string length "/www/"] end]
+} elseif { [regexp "^/packages/(\[^/\]+)" $filename match package_dir] } {
+ # TODO: We are assuming that the package directory name $package_dir
+ # is in fact always the package key. Is this really true?
+
+ if { ! [regexp "^/packages/$package_dir/www/(.+)" $filename match url_part] } {
+ ad_return_error "Error in filename" "This page has an invalid filename: '$filename'."
+ }
+
+ set redirect_to "[sp_package_url $package_dir]$url_part"
+} else {
+ ad_return_error "Error in filename" "This page has an invalid filename: '$filename'."
+ return
+}
+
+ns_log Notice "atp: redirect_to: '$redirect_to' filename: '$redirect_to'"
+ad_returnredirect $redirect_to