API Docs for: WebTemplate API v2.0
Show:

WebTemplate Class

The WebTemplate class

Methods

authenticate

(
  • username
  • password
  • passwordIsHash
  • $rememberUser
)
Boolean

Sets the current user

Parameters:

  • username String
  • password String
  • passwordIsHash Boolean

    is the password an md5 hash?

  • $rememberUser Boolean

    should the login be stored in a cookie

Returns:

Boolean: true if successful, false otherwise

contactIsAdministrator

() Boolean

Return true if the current contact is an administrator

Returns:

Boolean: Returns true if the current user is an administrator

contactIsGlobalAdministrator

() Boolean

Return true if the current contact is the global administrator

Returns:

Boolean: Returns true if the current user is the global administrator

copyNode

(
  • srcGuid
  • dstGuid
)
private

Copy a node's properties (used for linking nodes)

Parameters:

  • srcGuid Int

    The guid of the source node

  • dstGuid Int

    The guid of the destination node

copyNodeChildren

(
  • from
  • to
  • [ignore]
)

Copy a node's children to another node

Parameters:

  • from String

    The guid or path of the node to copy the children from

  • to String

    The guid or path of the node to copy the children to

  • [ignore] Int optional

    The guid of the type to ignore when copying the children

debugMessage

(
  • message
)

Write a debug message to the files/debug.txt file inside the current site's directory

Parameters:

  • message String

    The debug message

decrypt

(
  • value
)
String

Decrypt a string

Parameters:

  • value String

    The string to decrypt

Returns:

String: The decrypted string

encrypt

(
  • value
)
String

Encrypt a string

Parameters:

  • value String

    The string to encrypt

Returns:

String: The encrypted string

getAuthChallenge

()

Get an authorisation challenge for logging in

Returns:

The authorisation challenge to be used the in the login form

getCurrentPage

() Object

Return the object for the current page

Returns:

Object: The object for the current page

getCurrentUser

() Object

Get the Object for the current user

Returns:

Object: The object for the current user

getGuid

(
  • path
)
Int

Get the guid for a path

Parameters:

  • path String

Returns:

Int: the guid for a path

getMode

()

Get the mode of WebTemplate

Returns:

Returns "view", "edit", "moderate" or "index"

getModerationEnabled

() Boolean

Return true if moderation is enabled

Returns:

Boolean: Returns true if moderation is enabled

getNode

(
  • path
)
Object

Return the object for a node given its guid or path

Parameters:

  • path String

    The path or the guid of the node

Returns:

Object: The object of the node, NULL if the node does not exist

getOptionID

(
  • options
  • value
)
Int

Get the id of an option, given its string value

Parameters:

  • options String

    The path to the options, or the name of some built in options (eg "wtCountries")

  • value String

    The string value of the option

Returns:

Int: The ID of the option

getOptionsFromString

(
  • optionString
)
Array

Get the options defined in a string

Parameters:

  • optionString String

Returns:

Array: The options as an array

getOptionValue

(
  • options
  • id
)
String

Given an id, get the related option as a String

Parameters:

  • options String

    The path to the options, or the name of some built in options (eg "wtCountries")

  • id Int

    The ID of the option

Returns:

String: The String name of the option

getPostValue

(
  • name
  • [default=""]
)
String

Get a POST value, or return a default value if it doesn't exist

Parameters:

  • name String

    The name of the post variable

  • [default=""] String optional

    The default value if the post variable doesn't exist

Returns:

String: The POST value

getRequestValue

(
  • name
  • [default=""]
)
String

Get a REQUEST value, or return a default value if it doesn't exist

Parameters:

  • name String

    The name of the request variable

  • [default=""] String optional

    The default value if the request variable doesn't exist

Returns:

String: The REQUEST value

getTextTranslation

(
  • text
  • languageID
)

Get the translation of some text

Parameters:

  • text String
  • languageID Int

    The ID of the language to get the translation for

Returns:

The translation of the text, or the original text if no translation exists

getTranslationNode

(
  • guid
  • languageID
)

Get the the translation node for a node, return NULL if the node does not exist

Parameters:

  • guid Int

    The guid of the node to get the translation for

  • languageID Int

    The guid of the language to get the translation node

getUserLocation

(
  • [ipAddress=""]
)
Array

Return the country the current user is in

Parameters:

  • [ipAddress=""] Object optional

    An optional IP address to use instead of the current user's ip address

Returns:

Array: an associative array containing "country" and "countryCode"

getWTValue

(
  • path
)
String

Get a wt value, eg getWTValue("wt.page.uri")

Parameters:

  • path String

    The path to get

Returns:

String: The value for the path

linkNodes

(
  • parent
  • child
)

Link two nodes

Parameters:

  • parent String

    The guid or path of the parent node

  • child String

    The guid or path of the child node

loginAs

(
  • username
)

If the user is an administrator, allow them to login as a different user

Parameters:

  • username String

    The user to log in as

logout

()

Log out the current user

nodesAreLinked

(
  • parent
  • child
)
Boolean

Test if two nodes are linked

Parameters:

  • parent String

    The guid or path to the parent node

  • child String

    The guid or path to the child node

Returns:

Boolean: Returns true if the two nodes are linked

optionsPath

(
  • optionsPath
  • [optionQuery=Array()]
)

Get options as an array

Parameters:

  • optionsPath String

    The path to the parent of the options, or the name of built in options (eg "wtCountries")

  • [optionQuery=Array()] Array optional

    A WT query specifying which nodes to use as the options

pathExists

(
  • path
  • create
)
Boolean

Check if a path exists in the WebTemplate tree and optionally create the path if it does not exist

Parameters:

  • path String

    the path to check

  • create Boolean

    should the path be created with wtNodes if it does not exist?

Returns:

Boolean: true if the path exists, false otherwise

query

(
  • args
  • callback
  • noresultscallback
)
String

Perform a query on the WebTemplate Database

Examples:

The following example will print all contacts whose name starts with 'a' $q = Array(); $q["Node Type"] = "wtContact"; $q["Path"] = "/Contacts/*"; $q["Criteria"] = "First Name LIKE 'a%'" $q["Order By"] = "First Name"; $q["Template Source"] = "[wt:First Name] [wt:Last Name]"; print $GLOBALS["WT"]->query($q);

The following example will call a callback for each result

function callbackFunction($data, $args) { print 'name = ' . $data["First Name"]; }

$q = Array() $q["Node Type"] = "wtContact"; $GLOBALS["WT"]->query($q, "callbackFunction");

Parameters:

  • args Array

    the specification of the query

  • callback String

    a function to be called for each result of the query, the callback will task 2 arguments, the first an array of results, the second information about the results

  • noresultscallback String

    a function to be called if there are no results

Returns:

String: the results from the query

registerNodeTypeClass

(
  • typeName
  • className
)

Register a class to a node type, once registered, getNode will return objects of this class for this type of node

Parameters:

  • typeName String
  • className String

registerPageNotFoundHandler

(
  • function
)

Register a function to be called when a page is not found

Parameters:

  • function Function

    The function to call on page not found

registerURIHandler

(
  • uri
  • function
)

Register a function to process a URI

Parameters:

  • uri String

    The uri to handle

  • function Function

    The function to call for the url

requestValueExists

(
  • name
)

Test if a Request value exists

Parameters:

  • name String

    The name of the request value

setMode

(
  • mode
)

Set the mode of Webtemplate

Parameters:

  • mode String

    "view", "edit", "moderate", "index"

setModerationEnabled

(
  • enabled
)

Turn moderation on or off

Parameters:

  • enabled Boolean

    Set to true to turn on moderation

setTextTranslation

(
  • text
  • languageID
  • translation
)

Set the translation for some text

Parameters:

  • text String

    The text to set the translation for

  • languageID Int

    The id of the language the translation is being provided for

  • translation String

    The text of the translation

setURIParameter

(
  • uri
  • param
  • value
  • [encodeValue=true]
)
String

Set or add a parameter in the query part of a URI

Parameters:

  • uri String

    The uri to set the parameter for

  • param String

    The name of the parameter

  • value String

    The value of the parameter

  • [encodeValue=true] Boolean optional

    If true, then url encode the value

Returns:

String: The url with the parameter set in the query section

setUser

(
  • The
)

Set the current user

Parameters:

  • The String

    username of the user to set

switchToSecure

(
  • [uri=""]
  • [secureURL=""]
)

Switch to secure mode

Parameters:

  • [uri=""] String optional

    If set, redirect to this uri in secure mode

  • [secureURL=""] String optional

    If set, use this secure URL instead of the one in settings

unlinkNodes

(
  • parent
  • child
)

Unlink two nodes

Parameters:

  • parent String

    The guid or path to the parent node

  • child String

    The guid or path to the child node

unloginAs

()

If loginAs has been called, swich back to the previous user