ad_html_qualify_links (public)

 ad_html_qualify_links [ -location location ] [ -path path ] html

Defined in packages/acs-tcl/tcl/text-html-procs.tcl

Convert in the HTML text relative URLs into fully qualified URLs including the hostname. It performs the following operations: 1. prepend paths starting with a "/" by the location (protocol and host). 2. prepend paths not starting a "/" by the path, in case it was passed in. Links, which are already fully qualified are not modified.

Switches:
-location (optional)
protocol and host (defaults to [ad_url])
-path (optional)
optional path to be prepended to paths not starting with a "/"
Parameters:
html (required)
HTML text, in which substitutions should be performed.

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_html_qualify_links ad_html_qualify_links (test acs-tcl) ad_html_qualify_links ad_html_qualify_links test_ad_html_qualify_links->ad_html_qualify_links util_current_location util_current_location (public) ad_html_qualify_links->util_current_location notification::email::send notification::email::send (public) notification::email::send->ad_html_qualify_links xowiki::notification::do_notifications xowiki::notification::do_notifications (public) xowiki::notification::do_notifications->ad_html_qualify_links

Testcases:
ad_html_qualify_links
Source code:
    if {![info exists location]} {
        set location [util_current_location]
    }
    #
    # Make sure, location ends with a "/".
    #
    set location "[string trimright $location /]/"

    #
    # Protect all full qualified URLs with special characters (one
    # rule for single quotes, one for double quotes).
    #
    regsub -nocase -all  {(href|src)\s*=\s*'((http|https|ftp|mailto):[^'\"]+)'} $html  "\\1='\u0001\\2\u0002'" html
    regsub -nocase -all  {(href|src)\s*=\s*[\"]((http|https|ftp|mailto):[^'\"]+)[\"]} $html  "\\1=\"\u0001\\2\u0002\"" html

    #
    # If a path is specified, prefix all relative URLs (i.e. not
    # starting with a slash) with the specified path.
    #
    if {[info exists path]} {
        set path "[string trim $path /]/"
        regsub -all -- {(href|src)\s*=\s*['\"]([^/][^\u0001:'\"]+?)['\"]} $html  "\\1='${location}${path}\\2'" html
    }

    #
    # Prefix every URL starting with a slash by the location.
    #
    regsub -nocase -all {(href|src)\s*=\s*['\"]/([^\u0001:'\"]+?)['\"]} $html  "\\1='${location}\\2'" html

    #
    # Remove all protection characters again.
    #
    regsub -nocase -all {((href|src)\s*=\s*['\"]?)\u0001([^\u0002]*)\u0002} $html {\1\3} html

    return $html
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: