Page

The Page class is the core controller and template toolset. This class is automatically instantiated and available in $page, after the init file has been included in your controller. It provides all the base functionality needed to process a request and output your page and templates.

Functions

Page::sharingMetaData

Definition

Name
sharingMetaData
Syntax
String = Page::sharingMetaData( [Item $item] [, Array $_options ] );

Description

Get sharing meta data as string (in OG format), for injection in header.

Parameters

$item
Item Optional item to get data from. Default is the default settings in the config file, using the touch_icon.png as image.
$_options
Array Optional options for Metadata
Options
title
Custom title
description
Custom description
image
Custom image

Return values

String The OG Meta tags with title, description, url and image.

Examples

No example

Dependencies

Janitor
  • Page::pageTitle
  • Page::pageDescription
  • Page::pageImage

Page::pageTitle

Definition

Name
pageTitle
Syntax
String|void = Page::pageTitle( [String $value] );

Description

Getter/setter of page title.

Can be used to set page title from inside your templates. It is typically used to inject the title in your header template. If no title has been set manually, it will use the SITE_NAME constant defined in you config file.

Parameters

String
$value Set the page title. If parameter is omitted, the defined page title will be returned.

Return values

String|void if no $value is passed, it returns the current page title.

Examples

No example

Dependencies

Janitor
  • Nothing

Page::pageDescription

Definition

Name
pageDescription
Syntax
String|void = Page::pageDescription( [String $value] );

Description

Getter/setter of page description.

Can be used to set page description from inside your templates. It is typically used to inject the description in your header template. If no description has been set manually, it will use the DEFAULT_PAGE_DESCRIPTION constant defined in you config file. If DEFAULT_PAGE_DESCRIPTION is not defined, is will return the value from Page::pageTitle.

Parameters

String
$value Set the page description. If parameter is omitted, the defined page description will be returned.

Return values

String|void if no $value is passed, it returns the page description.

Examples

No example

Dependencies

Janitor
  • Page::pageTitle

Page::pageImage

Definition

Name
pageImage
Syntax
String|void = Page::pageImage( [String $value] );

Description

Getter/setter of page image.

Can be used to set page image from inside your templates. It is typically used to inject the image as part of your sharing meta data in your header template. If no image has been set manually, it will use the DEFAULT_PAGE_IMAGE constant defined in you config file. If DEFAULT_PAGE_IMAGE is not defined, is will use /favicon.png.

Parameters

String
$value Set the page image. If parameter is omitted, the defined page image will be returned.

Return values

String|void if no $value is passed, it returns the page image.

Examples

No example

Dependencies

Janitor
  • Nothing

Page::bodyClass

Definition

Name
bodyClass
Syntax
String = Page::bodyClass( [String $value] );

Description

Getter/setter of body class.

Can be used to set body class from inside your templates. It is used to print the body class in your header template.

Parameters

String
$value Set the body class. If parameter is omitted, the defined body class will be returned.

Return values

String|void if no $value is passed, it returns the body class.

Examples

$this->bodyClass("front");

Sets the current body class to front.

Dependencies

Janitor
  • Nothing

Page::contentClass

Definition

Name
contentClass
Syntax
String = Page::contentClass( [String $value] );

Description

Getter/setter of div#content class.

Can be used to set div#content class from inside your templates. It is used to print the div#content class in your header template.

Parameters

String
$value Set the div#content class. If parameter is omitted, the defined div#content class will be returned.

Return values

String|void if no $value is passed, it returns the div#content class.

Examples

$this->contentClass("front");

Set the div#content class to front.

Dependencies

Janitor
  • Nothing

Page::headerIncludes

Definition

Name
headerIncludes
Syntax
String = Page::headerIncludes( [Array $files] );

Description

Getter/setter of header includes.

Can be used to add JavaScript and CSS header includes from inside your templates.

Parameters

Array
$files Add files to the header includes list. If parameter is omitted, the added files will be returned as a string of include statements.

Return values

String|void if no $files are passed, it returns the includes string.

Examples

$this->headerIncludes(array("/js/include_me.js", "/css/include_me.css"));

Add /js/include_me.js and /css/include_me.css to the document head.

Dependencies

Janitor
  • Nothing

Page::template

Definition

Name
template
Syntax
Sting|rendered PHP = Page::template( String $template, [Array $_options] );

Description

This is the secondary method for including templates. Use Page::page for automatic buffering, and header + footer inclusion.

Include a template in your controller. Optional setting for buffered output, to enable setting title, body and content class later.

The path to the template should match a template in either project/src/templates or submodules/janitor/src/templates.

If template is found in neither location the error template will be returned instead.

Parameters

$template
String the path to the wanted template
$_options
Array Optional options for Template inclusion
Options
buffer
Boolean value for buffering - default false
error
Custom error template - default /templates/404.php

Return values

String|rendered PHP If buffer is false, the template will be included and rendered using a PHP include(). If buffer is true, the include will be buffered for printing later.

Examples

No example

Dependencies

Janitor
  • Nothing

Page::page

Definition

Name
page
Syntax
Void = Page::page( Array $_options );

Description

This is the primary method for including templates.

Includes a header, template(s) and a footer in your controller.

The path to the template should match a template in either project/src/templates or submodules/janitor/src/templates.

If template is found in neither location the error template will be returned instead.

Parameters

$_options
Array Optional options for Template inclusion
Options
type
Type of header and footer - default www
templates
Templates to include
body_class
Custom error body class
page_title
Custom page title
page_descriptiton
Custom page description
content_class
Custom content class
error
Custom error template - default /templates/404.php

Return values

Void The header, template(s) and footer will be included and rendered using a PHP include().

Examples

No example

Dependencies

Janitor
  • Page::header
  • Page::footer
  • Page::template

Page::header

Definition

Name
header
Syntax
void = Page::header( [Array $_options] );

Description

Includes a header template. Defaults to templates/www.header.php, but you can specify a backend or development (or any custom) header if you want.

Parameters

$_options
Array Array of options
Options
buffer
Boolean value for buffering - default false
type
The type of header - default www
body_class
Custom error body class
page_title
Custom page title
page_descriptiton
Custom page description
content_class
Custom content class

Return values

String|rendered PHP If buffer is false, the header will be included and rendered using a PHP include(). If buffer is true, the include will be buffered for printing later.

Examples

No example

Dependencies

Janitor
  • Page::bodyClass
  • Page::pageTitle
  • Page::pageDescription
  • Page::contentClass

Page::footer

Definition

Name
footer
Syntax
void = Page::footer( [Array $_options] );

Description

Includes a footer template. Defaults to templates/www.footer.php, but you can specify a backend or development (or any custom) footer if you want.

Parameters

$_options
Array Array of options
Options
buffer
Boolean value for buffering - default false
type
The type of header - default www

Return values

String|rendered PHP If buffer is false, the footer will be included and rendered using a PHP include(). If buffer is true, the include will be buffered for printing later.

Examples

No example

Dependencies

Janitor
  • Nothing

Page::language

Definition

Name
language
Syntax
String|false = Page::language( [String $value] );

Description

Get/set current language. Default should be defined in DEFAULT_LANGUAGE_ISO in config.php

If you attempt to set invalid language, DEFAULT_LANGUAGE_ISO will be used instead of specified value.

Parameters

$value
String ISO language to use for session.

Return values

String | void The language ISO code of the session

Examples

$page->language();

Returns current session language, fx: DA

$page->language("DA");

Sets current session language to DA

Dependencies

Janitor
  • Session
  • Query

Page::languages

Definition

Name
languages
Syntax
Array = Page::languages( [String $id] );

Description

Get all available languages in nested Array structure from cache or DB

Optionally get language details by passing valid language iso value as parameter.

Parameters

$id
String Optional ISO language to get details of.

Return values

Array nested Array of available languages or specified language details

Examples

Get all languages
$page->languages();

Could returns (depending on available languages):

Array( [0] => array( ["id"] => "en", ["name"] => "English" ), [1] => array( ["id"] => "da", ["name"] => "Dansk" ) )
Get details for specific language
$page->languages("DA");

Returns:

Array( ["id"] => "da", ["name"] => "Dansk" )

Dependencies

Janitor
  • Session
  • Query
  • Cache

Page::country

Definition

Name
country
Syntax
String|false = Page::country( [String $value] );

Description

Get/set current country. Default should be defined in DEFAULT_COUNTRY_ISO in config.php

If you attempt to set invalid country, DEFAULT_COUNTRY_ISO will be used instead of specified value.

Parameters

$value
String ISO country to use for session.

Return values

String | void The country ISO code of the session

Examples

$page->country();

Returns current session country, fx: DK

$page->country("DK");

Sets current session country to DK

Dependencies

Janitor
  • Session
  • Query

Page::countries

Definition

Name
countries
Syntax
Array = Page::countries( [String $id] );

Description

Get all available countries in nested Array structure from cache or DB

Optionally get country details by passing valid country iso value as parameter.

Parameters

$id
String Optional ISO country to get details of.

Return values

Array nested Array of available countries or specified country details

Examples

Get all countries
$page->countries();

Could returns (depending on available countries):

Array( [0] => array( ["id"] => "DK", ["name"] => "Danmark", ["phone_countrycode"] => 45, ["phone_format"] => "#### ####", ["language"] => "DA", ["currency"] => "DKK" ), [1] => array( ["id"] => "US", ["name"] => "USA" ["phone_countrycode"] => 1, ["phone_format"] => "### ### ####", ["language"] => "EN", ["currency"] => "USD" ) )
Get details for specific country
$page->countries("DK");

Returns:

Array( ["id"] => "DK", ["name"] => "Danmark", ["phone_countrycode"] => 45, ["phone_format"] => "#### ####", ["language"] => "DA", ["currency"] => "DKK" )

Dependencies

Janitor
  • Session
  • Query
  • Cache

Page::currency

Definition

Name
currency
Syntax
String|void = Page::currency( [String $value] );

Description

Get/set current currency. Default should be defined in DEFAULT_CURRENCY_ISO in config.php

If you attempt to set invalid currency, DEFAULT_CURRENCY_ISO will be used instead of specified value.

Parameters

$value
String ISO currency to use for session.

Return values

String | void The currency ISO code of the session

Examples

$page->currency();

Returns current session currency, fx: DKK

$page->currency("DKK");

Sets current session currency to DKK

Dependencies

Janitor
  • Session
  • Query

Page::currencies

Definition

Name
currencies
Syntax
Array = Page::currencies( [String $id] );

Description

Get all available currencies in nested Array structure from cache or DB

Optionally get currency details by passing valid currency iso value as parameter.

Parameters

$id
String Optional ISO currency to get details of.

Return values

Array nested Array of available currencies or specified currency details

Examples

Get all currencies
$page->currencies();

Could returns (depending on available currencies):

Array( [0] => array( ["id"] => "DKK", ["name"] => "Kroner (Denmark)", ["abbreviation"] => "DKK", ["abbreviation_position"] => "after", ["decimals"] => "2", ["decimal_separator"] => ",", ["grouping_separator"] => "." ), [1] => array( ["id"] => "USD", ["name"] => "US Dollar" ["abbreviation"] => "$", ["abbreviation_position"] => "before", ["decimals"] => "2", ["decimal_separator"] => ".", ["grouping_separator"] => "," ) )
Get details for specific currency
$page->currencies("DKK");

Returns:

Array( ["id"] => "DKK", ["name"] => "Kroner (Denmark)", ["abbreviation"] => "DKK", ["abbreviation_position"] => "after", ["decimals"] => "2", ["decimal_separator"] => ",", ["grouping_separator"] => "." )

Dependencies

Janitor
  • Session
  • Query
  • Cache

Page::vatrates

Definition

Name
vatrates
Syntax
Array = Page::vatrates( [Integer $id] );

Description

Get all available vatrates in nested Array structure from cache or DB

Optionally get vatrate details by passing valid vatrate id as parameter.

Vatrates are used to specify VAT for Item prices.

Parameters

$id
Integer Optional vatrate id to get details of.

Return values

Array nested Array of available vatrates or specified vatrate details

Examples

Get all vatrates
$page->vatrates();

Could returns (depending on available vatrates):

Array( [0] => array( ["id"] => 1, ["name"] => "No VAT", ["vatrate"] => 0, ["country"] => "DK" ), [1] => array( ["id"] => 2, ["name"] => "25%", ["vatrate"] => 0.25, ["country"] => "DK" ) )
Get details for specific vatrate
$page->vatrates(1);

Returns:

Array( ["id"] => 1, ["name"] => "No VAT", ["vatrate"] => 0, ["country"] => "DK" )

Dependencies

Janitor
  • Session
  • Query
  • Cache

Page::subscriptionMethods

Definition

Name
subscriptionMethods
Syntax
Array = Page::subscriptionMethods( [Integer $id] );

Description

Get all available subscription methods in nested Array structure from cache or DB

Optionally get subscription method details by passing valid subscription method id as parameter.

Subscription methods are used to specify subscription renewal setting for item subscriptions.

Parameters

$id
Integer Optional subscription method id to get details of.

Return values

Array nested Array of available subscription methods or specified subscription method details

Examples

Get all subscription methods
$page->subscriptionMethods();

Could returns (depending on available subscription methods):

Array( [0] => array( ["id"] => 1, ["name"] => "Monthly", ["duration"] => "month", ["starts_on"] => NULL ), [1] => array( ["id"] => 1, ["name"] => "Weekly", ["duration"] => "week", ["starts_on"] => NULL ) )
Get details for specific subscription method
$page->subscriptionMethods(1);

Returns:

Array( ["id"] => 1, ["name"] => "Monthly", ["duration"] => "month", ["starts_on"] => NULL )

Dependencies

Janitor
  • Session
  • Query
  • Cache

Page::paymentMethods

Definition

Name
paymentMethods
Syntax
Array = Page::paymentMethods( [Integer $id] );

Description

Get all available payment methods in nested Array structure from cache or DB

Optionally get payment method details by passing valid payment method id as parameter.

Subscription methods are used to specify payment method for subscriptions.

Parameters

$id
Integer Optional payment method id to get details of.

Return values

Array nested Array of available payment methods or specified payment method details

Examples

Get all payment methods
$page->paymentMethods();

Could returns (depending on available payment methods):

Array( [0] => array( ["id"] => 1, ["name"] => "Bank account" ), [1] => array( ["id"] => 1, ["name"] => "Paypal" ) )

Dependencies

Janitor
  • Session
  • Query
  • Cache

Page::segment

Definition

Name
segment
Syntax
String|void = Page::segment( [String $value] );

Description

Get or set segment for current session (desktop, dekstop_ie, dekstop_light, mobile_light, mobile, mobile_touch, tablet, tv). Calls http://detector-v3.dearapi.com for device detection.

Parameters

$value
String Set session segment to $value

Return values

String|void It the $value parameter is omitted, the segment string is returned (desktop, dekstop_ie, dekstop_light, mobile_light, mobile, mobile_touch, tablet, tv)

Examples

No example

Dependencies

Janitor
  • Session

Page::navigation

Definition

Name
navigation
Syntax
Array|Boolean = Page::navigation( String $handle );

Description

Get the nested navigation for handle from cache or DB (if not currently cached)

Parameters

$handle
String Navigation handle

Return values

Array|Boolean The navigation structure in nested array or false.

Examples

No example

Dependencies

Janitor
  • Cache
  • Query
  • Items
  • superNormalize

Page::validatePath

Definition

Name
validatePath
Syntax
Boolean = Page::validatePath( String $path );

Description

Checks if the current user has permission to access the specified path

Parameters

$path
String The path to validate

Return values

Boolean True if current user has access to path, false if not

Examples

No example

Dependencies

Janitor
  • Page::checkPermissions

Page::validPath

Definition

Name
validPath
Syntax
String = Page::validPath( String $path );

Description

Checks if the current user has permission to access the specified path and returns path when user has permission. This is simply a quick way to use validatePath and have the path returned directly.

Parameters

$path
String The path to validate

Return values

String The path is returned if current user has access to path, empty string if not

Examples

No example

Dependencies

Janitor
  • Page::validatePath

Page::actions

Definition

Name
actions
Syntax
Array = Page::actions();

Description

Get Array containing current url fragments, excluding controller path.

Parameters

No parameters

Return values

Array containing current url fragments, excluding controller path

Examples

No example

Dependencies

Janitor
  • Nothing

Page::logIn

Definition

Name
logIn
Syntax
Void|False|Array = Page::logIn();

Description

Log in with username and password from $_POST.

Parameters

No parameters

Return values

Void if login is successful – that is, if credentials are correct, username is verified, and user is activated (status = 1). The user is redirected to the URL specified in $forward_url, which is fetched from either $_POST, $_GET, or session.

Void if ajaxlogin is successful – that is, if credentials are correct, username is verified, user is activated, and "ajaxlogin" => true is posted along with username and password. The function outputs a json-encoded CMS object that contains an updated CSRF token.

Array with the value "status"=>"NOT_VERIFIED" if the posted username exists but is unverified. This happens whether or not the user has a password. It happens whether or not the user is activated.

Array with the value "status"=>"NO_PASSWORD" if login is performed by a user with the following characteristics: 1) User is activated; 2) Username is verified; 3) User does not have a password.

False if login is performed by a user with the following characteristics: 1) User is deactivated; 2) username is verified.

False if the user tries to log in with wrong username and/or wrong password.

Examples

No example

Dependencies

Janitor
  • getPost()
  • getVar()
  • stringOr()
  • mailer()
  • message()
  • Page::addLog
  • Page::validatePath
  • Query
  • Upgrade
  • Session

Page::logOff

Definition

Name
logOff
Syntax
Void = Page::logOff();

Description

Log off the current user, reset session and return user to frontpage.

Parameters

No parameters

Return values

Void

Examples

No example

Dependencies

Janitor
  • Page::addLog
  • Session

Page::throwOff

Definition

Name
throwOff
Syntax
Void = Page::throwOff();

Description

Throw user off the system, send email to ADMIN_EMAIL, reset session and return user to login page.

Parameters

No parameters

Return values

Void

Examples

No example

Dependencies

Janitor
  • Page::addLog
  • Page::mail
  • Session

Page::addLog

Definition

Name
addLog
Syntax
Void = Page::addLog( String $message [, String $collection ] );

Description

Add message to Janitor log. Logging message, timestamp, user_id and IP-address in optional $collection. Defaults to the framework collection

Parameters

$message
String message to log
$collection
String Optional collection to add log to. Defaults to framework

Return values

Void

Examples

logger()->addLog("I think this is interesting");

Dependencies

Janitor
  • FileSystem::makeDirRecursively
  • Session

Page::collectNotification

Definition

Name
collectNotification
Syntax
_returntype_ = Page::collectNotification( String $message [, String $collection ] );

Description

Save message to collection to be emailed to ADMIN_EMAIL when collection limit is reached. Limit is defined in SITE_COLLECT_NOTIFICATIONS in config.php.

Parameters

$message
String message to log
$collection
String Optional collection to add log to. Defaults to framework

Return values

Void

Examples

No example

Dependencies

Janitor
  • FileSystem::makeDirRecursively
  • Session