API: Page
Filename:
fwpPage_client.ctyp
Released With:
5.1.0
Current Version:
1.0.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
Contains instance variables which identify the current client preferences regarding language, etc. Can also be used to access built-in Lasso client values.
$fw_pageModes->setSomething; if: $fw_pageModes->'Something';
... do something ...
/if;
Instance Variables:
->'ip' = looks for X-Forwarded-For in the page headers and returns that value if present, else returns the normal client_ip value. In a load-balanced muli-server setup, client_ip is usually going to return the IP address of the load balancing machine that forwarded the request.
The X-Forwarded-For value is often added to headers to reflect the original client IP address (just like you'd normally expect from client_ip). You should use $fw_client->'ip' (with or without quotes in this case, as it is also trapped as a tag) everywhere that would normally use client_ip to make your applications ready for load-balanced installations.
->'language' (string) : the client's preferred language code for multi-view strings.
->'media' (string) : the client's preferred media code for multi-view strings.
->'variant' (string) : the client's preferred variant code for multi-view strings.
->'thousandsChar' (string) : the client's preferred character for separating thousands in numeric strings.
->'decimalChar' (string) : the client's preferred character for separating whole and decimal components of numeric strings.
Member Tags:
->setLanguage = sets ->'language' to a specified value.
->setMedia = sets ->'media' to a specified value.
->setVariant = sets ->'variant' to a specified value.
->setThousandsChar = sets ->'thousandsChar' to a specified value.
->setDecimalChar = sets ->'decimalChar' to a specified value.
For consistency in interface it is also possible to use $fw_client-> with a member tag the same as any of Lasso's internal client_ tags. For example: $fw_client->browser can be used in place of client_browser.
<?lassoscript
//............................................................................
//
// pageblocks: (c) 2002-2007 http://www.pageblocks.org/
//
//............................................................................
/*
{fileName= fwpPage_client.ctyp }
{rsrcType= type }
{rsrcName= fwp_client }
{rsrcHTTP= www.pageblocks.org/refc/fwp_client }
{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= provides client date & numerics formatting preferencse
and a gateway to Lasso client tag values }
{maintvsrn= 1.1 }
{maintrelease= 5.2.0 }
{maintdate= 2007-06-15 }
{maintauthor= Greg Willits }
{maintnotes= added intercept for client_ip to return
forwarded-for if available }
{maintvsrn= 1.0 }
{maintrelease= 5.1.0 }
{maintdate= 2006-08-01 }
{maintauthor= Greg Willits }
{maintnotes= initial release }
*/
//............................................................................
define_type:'fwp_client';
local:
'decimalChar' = string,
'thousandsChar' = string,
'language' = string,
'media' = string,
'variant' = string,
'forwardedFor' = string,
'forwardedHost' = string,
'ip' = string;
//============================================================================
//
// ->onCreate
//
//............................................................................
define_tag:'onCreate';
(self->'forwardedFor') = (string_findRegExp: client_headers, -find='X-Forwarded-For:\\s?(.*)', -ignorecase)->last;
(self->'forwardedFor')
? (self->'forwardedFor')->trim;
(self->'forwardedHost') = (string_findRegExp: client_headers, -find='X-Forwarded-For:\\s?(.*)', -ignorecase)->last;
(self->'forwardedHost')
? (self->'forwardedHost')->trim;
(self->'forwardedFor')
? (self->'ip') = (self->'forwardedFor')
| (self->'ip') = client_ip;
/define_tag;
//============================================================================
// ->unknownTag
//
// provides an interface to all the Lasso built-in client_ tags
// just to unify the API into the client if preferred
//
//............................................................................
define_tag:'_unknowntag';
// ::HACK::
// this is a bandaid to correct the behavior of Lasso
// calling _unknownTag before checking for an instance var
// when the ivar is called unquoted
if: self->properties->first->contains:tag_name;
return: self->properties->first->find:tag_name;
/if;
if: tag_name == 'IP';
(self->'forwardedFor')
? return: (self->'forwardedFor')
| return: client_ip;
/if;
// enables this ctype to act as an interface to built-in client_ tags
if: lasso_tagExists:('client_' + tag_name);
return: (\('client_' + tag_name))->run;
/if;
/define_tag;
//============================================================================
define_tag:'setDecimalChar',
-required = 'newValue', -type = string;
(self->'decimalChar') = #newValue;
/define_tag;
//============================================================================
define_tag:'setThousandsChar',
-required = 'newValue', -type = string;
(self->'thousandsChar') = #newValue;
/define_tag;
//============================================================================
define_tag:'setLanguage',
-required = 'newValue', -type = string;
(self->'language') = #newValue;
/define_tag;
//============================================================================
define_tag:'setMedia',
-required = 'newValue', -type = string;
(self->'media') = #newValue;
/define_tag;
//============================================================================
define_tag:'setVariant',
-required = 'newValue', -type = string;
(self->'variant') = #newValue;
/define_tag;
/define_type;
?>
© 2002-2012, pageblocks.org