Module z_context

Request context for Zotonic request evaluation.

Copyright 2009-2014 Marc Worrell

Authors: Marc Worrell (marc@worrell.nl).

Description

Request context for Zotonic request evaluation.

Function Index

abs_url/2Make the url an absolute url by prepending the hostname.
add_script_page/1Add the script from the context to the page in the user agent.
add_script_page/2Add a script to the page in the user agent.
add_script_session/1Add the script from the context to all pages of the session.
add_script_session/2Add a script to the all pages of the session.
clean_scripts/1Remove all scripts from the context.
combine_results/2Merge the scripts and the rendered content of two contexts into Context1.
continue_all/1
continue_session/1Continue an existing session, if the session id is in the request.
cookie_domain/1Fetch the cookie domain, defaults to 'undefined' which will equal the domain to the domain of the current request.
copy_scripts/2Overwrite the scripts in Context with the scripts in From.
db_driver/1Fetch the database driver module for this site.
db_pool/1Fetch the pid of the database worker pool for this site.
depickle/1Depickle a context for restoring from a database.
document_domain/1The document domain used for cross domain iframe javascripts.
ensure_all/1Ensure session and page session.
ensure_qs/1Ensure that we have parsed the query string, fetch body if necessary.
ensure_session/1Ensure that we have a session, start a new session process when needed.
get/2Fetch the value of the context variable Key, return undefined when Key is not found.
get/3Fetch the value of the context variable Key, return Default when Key is not found.
get_all/1Return a proplist with all context variables.
get_controller_module/1Get the resource module handling the request.
get_cookie/2Read a cookie value from the current request.
get_cookies/2
get_page/2Fetch the value of the page variable Key.
get_persistent/2Fetch the value of the visitor variable Key.
get_q/2Get a request parameter, either from the query string or the post body.
get_q/3Get a request parameter, either from the query string or the post body.
get_q_all/1Get all parameters.
get_q_all/2Get the all the parameters with the same name, returns the empty list when non found.
get_q_all_noz/1Get all query/post args, filter the zotonic internal args.
get_q_validated/2Fetch a query parameter and perform the validation connected to the parameter.
get_req_header/2Get a request header.
get_req_path/1Return the request path.
get_reqdata/1Return the webmachine request data of the context.
get_resp_header/2Get a response header.
get_session/2Fetch the value of the session variable Key.
get_session/3Fetch the value of the session variable Key, falling back to default.
get_value/2Find a key in the context, page, session or persistent state.
has_session/1Check if the current context has a session attached.
has_session_page/1Check if the current context has a session page attached.
has_websockethost/1Return true iff this site has a separately configured websockethost.
hostname/1Return the preferred hostname from the site configuration.
hostname_port/1Return the preferred hostname, including port, from the site configuration.
incr/3Increment the context variable Key.
incr_page/3Increment the page variable Key.
incr_session/3Increment the session variable Key.
is_request/1Check if the current context is a request context.
lager_md/1
lager_md/2
language/1Return the selected language of the Context.
merge_scripts/2Merge the scripts from context C into the context accumulator, used when collecting all scripts in an output stream.
new/1Return a new empty context, no request is initialized.
new/2Create a new context record for a host with a certain language.
new_tests/0Create a new context used when testing parts of zotonic.
output/2Replace the contexts in the output with their rendered content and collect all scripts.
persistent_id/1Ensure that we have an id for the visitor.
pickle/1Pickle a context for storing in the database.
prune_for_async/1Make the context safe to use in a async message.
prune_for_database/1Cleanup a context so that it can be used exclusively for database connections.
prune_for_scomp/1Cleanup a context for cacheable scomp handling.
prune_for_scomp/2
prune_for_spawn/1Minimal prune, for ensuring that the context can safely used in two processes.
prune_for_template/1Cleanup a context for the output stream.
set/2Set the value of the context variables to all {Key, Value} properties.
set/3Set the value of the context variable Key to Value.
set_controller_module/2
set_cookie/3Set a cookie value with default options.
set_cookie/4Set a cookie value with cookie options.
set_language/2Set the language of the context.
set_nocache_headers/1Some user agents have too aggressive client side caching.
set_noindex_header/1Set the noindex header if the config is set, or the webmachine resource opt is set.
set_noindex_header/2Set the noindex header if the config is set, the webmachine resource opt is set or Force is set.
set_page/3Set the value of the page variable Key to Value.
set_persistent/3Set the value of the visitor variable Key to Value.
set_q/3Set the value of a request parameter argument.
set_reqdata/2Set the webmachine request data of the context.
set_resp_header/3Set a response header for the request in the context.
set_session/3Set the value of the session variable Key to Value.
set_tz/2Set the timezone of the context.
site/1Maps the host in the request to a site in the sites folder.
site_protocol/1Fetch the protocol for absolute urls referring to the site (defaults to http).
spawn_link_page/4Spawn a new process, link it to the page process.
spawn_link_session/4Spawn a new process, link it to the session process.
streamhost/1Fetch the domain and port for stream (comet/websocket) connections.
tz/1Return the selected timezone of the Context; defaults to the site's timezone.
tz_config/1Return the site's configured timezone.
websockethost/1Fetch the domain and port for websocket connections.

Function Details

abs_url/2

abs_url(Url::iolist(), Context) -> binary()

Make the url an absolute url by prepending the hostname.

add_script_page/1

add_script_page(Context) -> any()

Add the script from the context to the page in the user agent.

add_script_page/2

add_script_page(Script, Context) -> any()

Add a script to the page in the user agent. Used for comet feeds.

add_script_session/1

add_script_session(Context) -> any()

Add the script from the context to all pages of the session.

add_script_session/2

add_script_session(Script, Context) -> any()

Add a script to the all pages of the session. Used for comet feeds.

clean_scripts/1

clean_scripts(C::Context) -> Context

Remove all scripts from the context

combine_results/2

combine_results(C1::Context1, C2::Context2) -> Context

Merge the scripts and the rendered content of two contexts into Context1

continue_all/1

continue_all(Context) -> any()

continue_session/1

continue_session(Context) -> any()

Continue an existing session, if the session id is in the request.

cookie_domain/1

cookie_domain(Context) -> list() | undefined

Fetch the cookie domain, defaults to 'undefined' which will equal the domain to the domain of the current request.

copy_scripts/2

copy_scripts(From, Context) -> Context

Overwrite the scripts in Context with the scripts in From

db_driver/1

db_driver(Context) -> any()

Fetch the database driver module for this site

db_pool/1

db_pool(Context) -> any()

Fetch the pid of the database worker pool for this site

depickle/1

depickle(X1) -> any()

Depickle a context for restoring from a database

document_domain/1

document_domain(Context) -> any()

The document domain used for cross domain iframe javascripts

ensure_all/1

ensure_all(Context) -> any()

Ensure session and page session. Fetches and parses the query string.

ensure_qs/1

ensure_qs(Context) -> any()

Ensure that we have parsed the query string, fetch body if necessary

ensure_session/1

ensure_session(Context) -> any()

Ensure that we have a session, start a new session process when needed

get/2

get(Key, Context) -> Value | undefined

Fetch the value of the context variable Key, return undefined when Key is not found.

get/3

get(Key, Context, Default) -> Value | Default

Fetch the value of the context variable Key, return Default when Key is not found.

get_all/1

get_all(Context) -> PropList

Return a proplist with all context variables.

get_controller_module/1

get_controller_module(Context) -> term()

Get the resource module handling the request.

get_cookie/2

get_cookie(Key, Context) -> any()

Read a cookie value from the current request.

get_cookies/2

get_cookies(Key, Context) -> any()

get_page/2

get_page(Key, Context) -> Value

Fetch the value of the page variable Key

get_persistent/2

get_persistent(Key, Context) -> Value

Fetch the value of the visitor variable Key

get_q/2

get_q(Key::string(), Context) -> Value::string() | undefined

Get a request parameter, either from the query string or the post body. Post body has precedence over the query string.

get_q/3

get_q(Key::string(), Context, Default) -> Value::string()

Get a request parameter, either from the query string or the post body. Post body has precedence over the query string.

get_q_all/1

get_q_all(Context) -> [{Key::string(), [Values]}]

Get all parameters.

get_q_all/2

get_q_all(Key::string(), Context) -> [Values]

Get the all the parameters with the same name, returns the empty list when non found.

get_q_all_noz/1

get_q_all_noz(Context) -> [{Key::string(), [Values]}]

Get all query/post args, filter the zotonic internal args.

get_q_validated/2

get_q_validated(Keys::Key, Context) -> Value

Fetch a query parameter and perform the validation connected to the parameter. An exception {not_validated, Key} is thrown when there was no validator, when the validator is invalid or when the validation failed.

get_req_header/2

get_req_header(Header, Context) -> Value

Get a request header. The header MUST be in lower case.

get_req_path/1

get_req_path(Context) -> list()

Return the request path

get_reqdata/1

get_reqdata(Context) -> #wm_reqdata{}

Return the webmachine request data of the context

get_resp_header/2

get_resp_header(Header, Context) -> Value

Get a response header

get_session/2

get_session(Key, Context) -> Value

Fetch the value of the session variable Key

get_session/3

get_session(Key, Context, DefaultValue) -> Value

Fetch the value of the session variable Key, falling back to default.

get_value/2

get_value(Key::string(), Context) -> Value | undefined

Find a key in the context, page, session or persistent state.

has_session/1

has_session(Context) -> any()

Check if the current context has a session attached

has_session_page/1

has_session_page(Context) -> any()

Check if the current context has a session page attached

has_websockethost/1

has_websockethost(Context) -> bool()

Return true iff this site has a separately configured websockethost

hostname/1

hostname(Context) -> string()

Return the preferred hostname from the site configuration

hostname_port/1

hostname_port(Context) -> string()

Return the preferred hostname, including port, from the site configuration

incr/3

incr(Key, Value::Increment, Context) -> {NewValue, NewContext}

Increment the context variable Key

incr_page/3

incr_page(Key, Value::Increment, Context) -> {NewValue, NewContext}

Increment the page variable Key

incr_session/3

incr_session(Key, Value::Increment, Context) -> {NewValue, NewContext}

Increment the session variable Key

is_request/1

is_request(Context) -> any()

Check if the current context is a request context

lager_md/1

lager_md(ContextOrReqData) -> any()

lager_md/2

lager_md(MD, Context) -> any()

language/1

language(Context::#context{}) -> atom()

Return the selected language of the Context

merge_scripts/2

merge_scripts(C::Context, Acc::ContextAcc) -> Context

Merge the scripts from context C into the context accumulator, used when collecting all scripts in an output stream

new/1

new(Context::HostDescr) -> Context2

Return a new empty context, no request is initialized.

new/2

new(Host, Lang) -> any()

Create a new context record for a host with a certain language.

new_tests/0

new_tests() -> any()

Create a new context used when testing parts of zotonic

output/2

output(B::list(), Context) -> {io_list(), Context}

Replace the contexts in the output with their rendered content and collect all scripts

persistent_id/1

persistent_id(Context) -> any()

Ensure that we have an id for the visitor

pickle/1

pickle(Context) -> tuple()

Pickle a context for storing in the database

prune_for_async/1

prune_for_async(Context) -> any()

Make the context safe to use in a async message. This removes buffers and the db transaction.

prune_for_database/1

prune_for_database(Context) -> any()

Cleanup a context so that it can be used exclusively for database connections

prune_for_scomp/1

prune_for_scomp(Context) -> any()

Cleanup a context for cacheable scomp handling. Resets most of the accumulators to prevent duplicating between different (cached) renderings.

prune_for_scomp/2

prune_for_scomp(VisibleFor, Context) -> any()

prune_for_spawn/1

prune_for_spawn(Context) -> any()

Minimal prune, for ensuring that the context can safely used in two processes

prune_for_template/1

prune_for_template(Context) -> any()

Cleanup a context for the output stream

set/2

set(PropList, Context) -> Context

Set the value of the context variables to all {Key, Value} properties.

set/3

set(Key, Value, Context) -> Context

Set the value of the context variable Key to Value

set_controller_module/2

set_controller_module(Module::atom(), Context) -> NewContext

set_cookie/3

set_cookie(Key, Value, Context) -> any()

Set a cookie value with default options.

set_cookie/4

set_cookie(Key, Value, Options, Context) -> any()

Set a cookie value with cookie options.

set_language/2

set_language(Lang::atom() | binary() | string(), Context::#context{}) -> #context{}

Set the language of the context.

set_nocache_headers/1

set_nocache_headers(Context::#context{}) -> #context{}

Some user agents have too aggressive client side caching. These headers prevent the caching of content on the user agent iff the content generated has a session. You can prevent addition of these headers by not calling z_context:ensure_session/1, or z_context:ensure_all/1.

set_noindex_header/1

set_noindex_header(Context::#context{}) -> #context{}

Set the noindex header if the config is set, or the webmachine resource opt is set.

set_noindex_header/2

set_noindex_header(Force::term(), Context::#context{}) -> #context{}

Set the noindex header if the config is set, the webmachine resource opt is set or Force is set.

set_page/3

set_page(Key, Value, Context) -> Context

Set the value of the page variable Key to Value

set_persistent/3

set_persistent(Key, Value, Context) -> Context

Set the value of the visitor variable Key to Value

set_q/3

set_q(Key::string(), Value::any(), Context::#context{}) -> #context{}

Set the value of a request parameter argument

set_reqdata/2

set_reqdata(ReqData, Context) -> #wm_reqdata{}

Set the webmachine request data of the context

set_resp_header/3

set_resp_header(Header, Value, Context) -> NewContext

Set a response header for the request in the context.

set_session/3

set_session(Key, Value, Context) -> Context

Set the value of the session variable Key to Value

set_tz/2

set_tz(Tz::string() | binary(), Context::#context{}) -> #context{}

Set the timezone of the context.

site/1

site(Context::wm_reqdata) -> atom()

Maps the host in the request to a site in the sites folder.

site_protocol/1

site_protocol(Context) -> any()

Fetch the protocol for absolute urls referring to the site (defaults to http). Useful when the site is behind a https proxy.

spawn_link_page/4

spawn_link_page(Module, Func, Args, Context) -> any()

Spawn a new process, link it to the page process. Used for comet feeds.

spawn_link_session/4

spawn_link_session(Module, Func, Args, Context) -> any()

Spawn a new process, link it to the session process.

streamhost/1

streamhost(Context) -> list()

Fetch the domain and port for stream (comet/websocket) connections

tz/1

tz(Context::#context{}) -> binary()

Return the selected timezone of the Context; defaults to the site's timezone

tz_config/1

tz_config(Context::#context{}) -> binary()

Return the site's configured timezone.

websockethost/1

websockethost(Context) -> list()

Fetch the domain and port for websocket connections


Generated by EDoc, Nov 20 2014, 13:26:28.