Page Blocks

Hosting sponsored by:

Point In Space

 

API: Page

Filename:
fwpPage_requestURLElements.ctyp

Released With:
5.1.0

Current Version:
1.2.0

Status: Active

Min Lasso Tested: 8.1.0

Max Lasso Tested: 8.5.3

Related:

Still don't get it?

Check out the talk list archives, or join and ask your questions.

Documentation Error or Request?

Email documentation corrections or comments

API Reference

fwp_requestURLElements (Type)

Description

Provides a breakdown of the original request URL, which depending on whether URL abstraction is being used, may or may not be equal to the internal path of page being served.

If URL abstraction is being used, this ctype is used to specifically get data on the original request URL, whereas fwp_requestpage provides a breakdown of the page that is responding to the request.

Syntax

var:'fw_requestPage'=(fwp_requestPageElements);

Parameters & Member Tags

Instance Vars


No input parameters, but the following instance variables are created:

->'url' = a string of the url less the domain name
->'elements' = an array of each element of the URL (the url is split at / characters)
->'oddElements' = an array of the odd numbered elements of the URL
->'evenElements' = an array of the even numbered elements of the URL
->'subhost' = the current sub domain name
->'subdomain' = synonym for ->'subhost'
->'host' = the current sub and domain name
->'domain' = the current domain name (no subdomain)

Member Tags

{mono->extractOddEvenElements} = divides the elements into the two oddElements and evenElements instance vars. This tag is not called automatically.

{mono->endsWithSlash} = returns a boolean results based on the value of 'url' ending in a slash character

Examples

For a URL of http://www.example.com/catalog/2006/widgets/W100-24c/retail the following instance vars would be populated as shown:

->'url' = '/catalog/2006/widgets/W100-24c/retail'
->'elements' = (array: catalog, 2006, widgets, W100-24c, retail)
->'oddElements' = (array: catalog, widgets, retail)
->'evenElements' = (array: 2006, W100-24c)
->'host' = www.example.com
->'subhost' = www
->'subdomain' = www
->'domain' = example.com

Source Code

View in separate window

<?lassoscript
//............................................................................
//
//    pageblocks: (c) 2002-2007 http://www.pageblocks.org/
//
//............................................................................
/*

    {fileName=        fwpPage_requestURLElements.ctype }
    {rsrcType=        type }
    {rsrcName=        fwp_requestURLElements }
    {rsrcHTTP=        www.pageblocks.org/refc/fwp_requestURLElements }

    {lassoVrsnMin=    8.1.0 }
    {lassoVrsnMax=    8.5.3 }

    {author=        Greg Willits }
    {authorEmail=    subscribe to pbTalk at www.pageblocks.org/talk/ }
    {authorHTTP=    www.pageblocks.org }

    {desc=            Creates instance vars of various URL components. Also 
                    determines if params have been embedded in the URL
                    as created by fwpPage_makeURLparams.ctag and turns them
                    in to vars and rewrite the real `file` name. }

    {maintvsrn=        1.3.0 }
    {maintrelease=    5.3.0 }
    {maintdate=        2007-08-02 }
    {maintauthor=    Greg Willits }
    {maintnotes=    added ->endsWithSlash tag which was supposed to be there
                     all along }

    {maintvsrn=        1.2.0 }
    {maintrelease=    5.1.0 }
    {maintdate=        2006-08-21 }
    {maintauthor=    Greg Willits }
    {maintnotes=    changed name from fwp_URLPaths as part of the all-new
                    url rewriter capabilities, but everything else is 
                    identical }

    {maintvsrn=        1.1.0 }
    {maintrelease=    5.1.0 }
    {maintdate=        2006-08-21 }
    {maintauthor=    Greg Willits }
    {maintnotes=    added ->page as a synonym for file }

    {maintvsrn=        1.0.1 }
    {maintrelease=    5.0.2 }
    {maintdate=        2006-04-11 }
    {maintauthor=    Greg Willits }
    {maintnotes=    changed calculation of #path to fix a bug
                    rearranged some var declarations to make it easier to
                    deprecate older var names }

    {maintvsrn=        1.0 }
    {maintrelease=    5.0.0 }
    {maintdate=        2006-01-16 }
    {maintauthor=    Greg Willits }
    {maintnotes=    initial release }

*/
//.............................................................................

define_type:'fwp_requestURLElements', -prototype;

    local:
        'host'            = string,
        'subhost'        = string,
        'domain'        = string,
        'subdomain'        = string,
        'url'            = string,
        'elements'        = array,
        'oddElements'    = array,
        'evenElements'    = array;

define_tag:'onCreate';

    (self->'url')         = response_filepath;
    
    local:'urlTrimmed' = self->'url';
    #urlTrimmed->removeLeading:'/';
    #urlTrimmed->removeTrailing:'/';

    (self->'elements')    = #urlTrimmed->split:'/';

    (self->'host') = (string_findregexp: client_headers, -find='HOST:\\s?(.*)', -ignorecase)->last;
    (self->'subHost') = (self->'host')->(split:'.')->get:1;
    (self->'host')->trim;
    (self->'subhost')->trim;
    (self->'domain') = (self->'host');
    (self->'domain')->removeleading:((self->'subhost') + '.');
    (self->'subdomain')    = @(self->'subhost');

/define_tag;

//-------------------------------------

define_tag:'extractOddEvenElements';

    local:'thisOne' = string;
    iterate: self->'elements', #thisOne;
        loop_count%2
            ? (self->'evenElements')->insert:#thisOne
            | (self->'oddElements')->insert:#thisOne;
    /iterate;

/define_tag;

//-------------------------------------

define_tag:'endsWithSlash';

    (self->'url')->endsWith:'/'
        ? return: true
        | return: false;

/define_tag;

/define_type;
?>


© 2002-2012, pageblocks.org