subsite::get_url (public)

 subsite::get_url [ -node_id node_id ] [ -absolute_p absolute_p ] \
    [ -force_host force_host ] [ -strict_p strict_p ] \
    [ -protocol protocol ] [ -port port ]

Defined in packages/acs-subsite/tcl/subsite-procs.tcl

Returns the url stub for the specified subsite. If -absolute is supplied then this function will generate absolute URLs. If the site is currently being accessed via a host node mapping then URLs will omit the corresponding subsite url stub. The hostname will be used for any appropriate subsite when absolute URLs are generated.

Switches:
-node_id
(optional)
the subsite's node_id (defaults to nearest subsite node).
-absolute_p
(defaults to "0") (optional)
whether to include the host in the returned url.
-force_host
(optional)
Use a certain host. In case "any" is specified, and we have a host-node-mapping (e.g. non-connected cases) behave like a virtual server on the first host-node-mapping entry. In connected cases, "any" means: take whatever is provided via vhost.
-strict_p
(defaults to "0") (optional)
-protocol
(optional)
-port
(optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_subsite_api subsite_api (test acs-subsite) subsite::get_url subsite::get_url test_subsite_api->subsite::get_url db_list db_list (public) subsite::get_url->db_list security::configured_driver_info security::configured_driver_info (public) subsite::get_url->security::configured_driver_info site_node::get site_node::get (public) subsite::get_url->site_node::get util::join_location util::join_location (public) subsite::get_url->util::join_location util_driver_info util_driver_info (public) subsite::get_url->util_driver_info ad_conn ad_conn (public) ad_conn->subsite::get_url packages/acs-subsite/lib/login.tcl packages/acs-subsite/ lib/login.tcl packages/acs-subsite/lib/login.tcl->subsite::get_url xowiki::Package instproc www-refresh-login xowiki::Package instproc www-refresh-login (public) xowiki::Package instproc www-refresh-login->subsite::get_url

Testcases:
subsite_api
Source code:
    if {[ns_conn isconnected]} {
        if {$node_id eq ""} {
            set node_id [ad_conn subsite_node_id]
        }

        set subsite_node [site_node::get -node_id $node_id]
        util_driver_info -array driver_info
        set main_host $driver_info(hostname)

        lassign [split [ns_set iget [ns_conn headers] host] :] driver_info(vhost) host_provided_port
        if {$host_provided_port ne "" } {
            set driver_info(port) $host_provided_port
        }

        set request_vhost_p [expr {$main_host ne $driver_info(vhost) }]

    } elseif {$node_id eq ""} {
        error "You must supply node_id when not connected."
    } else {
        set subsite_node [site_node::get -node_id $node_id]
        set request_vhost_p 0
        #
        # Provide fallback values from the first configured driver
        #
        set d [lindex [security::configured_driver_info] 0]
        set driver_info(proto) [dict get $d proto]
        set driver_info(port) [dict get $d port]
        set driver_info(hostname) [dict get $d host]

    }

    #
    # In case we have no vhost, and $force_host is "any", and we have
    # a host-node-mapping (e.g. non-connected cases) behave like a
    # virtual server on the first host-node-mapping entry.
    #
    if {$force_host eq "any" && ![info exists driver_info(vhost)]} {        
        #
        # Get the first entry from the host_node_map, use sorting
        # to get stable answers.
        #
        # TODO: This should be cached
        #
        set force_host [db_list get_vhost {
            select host from host_node_map
            where node_id = :node_id
            order by host
            fetch first 1 row only
        }]
        if {$force_host ne ""} {
            set request_vhost_p 1
            set driver_info(vhost) $force_host
        }
    }

    #
    # If the provided protocol is empty, get it from the driver_info.
    #
    if {$protocol eq ""} {
        set protocol $driver_info(proto)
    }

    #
    # If the provided port is empty, get it from the driver_info.
    #
    if {$port eq ""} {
        set port $driver_info(port)
    }

    #
    # If the provided host is not empty, get it from the host header
    # field (when provided) or from the provided or configured
    # hostname.
    #
    if {$force_host eq "any" && [info exists driver_info(vhost)]} {
        set host $driver_info(vhost)
    } elseif {$force_host ne ""} {
        set host $force_host
    } else {
        set host $driver_info(hostname)
    }

    set result ""
    if { $request_vhost_p } {
        set root_p [expr {[dict get $subsite_node parent_id] eq ""}]
        set search_vhost $host

        # TODO: This should be cached
        set mapped_vhost [db_list get_vhost {
            select host from host_node_map
            where node_id = :node_id
            order by case when host = :search_vhost then 2 else 1 end desc
            fetch first 1 row only
        }]

        if {$root_p && $mapped_vhost eq ""} {
            if {$strict_p} {
                error "$search_vhost is not mapped to this subsite or any of its parents."
            }
            set mapped_vhost $search_vhost
        }

        if {$mapped_vhost eq ""} {
            set result [subsite::get_url  -node_id [dict get $subsite_node parent_id]  -absolute_p $absolute_p  -strict_p $strict_p  -force_host $host]
            append result "[dict get $subsite_node name]/"
        } else {
            #
            # The subsite is host-node mapped and addressed via this
            # URL (as determied via the host header field). In this
            # case, the path leading to the site-node must be removed,
            # according to the documentation.
            #
            set host $mapped_vhost
            dict set subsite_node url /
        }
    }

    if {$result eq ""} {
        if {$absolute_p} {
            set result [util::join_location  -proto $protocol  -hostname $host  -port $port]
        }
        append result [dict get $subsite_node url]
    }

    return $result
XQL Not present:
Generic
PostgreSQL XQL file:
packages/acs-subsite/tcl/subsite-procs-postgresql.xql

Oracle XQL file:
packages/acs-subsite/tcl/subsite-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: