class Admin implements Listable

ViewModel for admin interface operations.

Traits

Provides definition of permitted content object types.
Provides standard implementation for common parts of the Listable interface (excepting pagination and setMetadata()).
Provides methods for validating UTF-8 character encoding and string composition.
Provides method for validating cross-site request forgery tokens.

Methods

array
listTemplates()

Returns a list of template names used by specific content types.

array
listTypes()

Returns a whitelist of permitted content object types.

setOrder(string $field)

Sets the primary column to order query results by.

from Listable
setOrderType(string $orderType)

Sets the sort type (ascending or descending) for the primary order column of a result set.

from Listable
setSecondaryOrder(string $field)

Sets the secondary column to order query results by.

from Listable
setSecondaryOrderType(string $orderType)

Sets the sort type (ascending or descending) for the secondary order column of a result set.

from Listable
string
pageTitle()

Return title of this page.

from Listable
setPageTitle(string $pageTitle)

Set the title of this page.

from Listable
template()

Return the template object required by this page.

from Listable
setTemplate(string $template)

Set the template used by this page.

from Listable
string
theme()

Return the theme used by this page.

from Listable
setTheme(string $theme)

Set (change) the theme.

from Listable
array
metadata()

Return page-specific metadata overrides.

from Listable
setMetadata(array $metadata)

Set page-specific overrides of the site metadata.

from Listable
string
encodeEscapeUrl(string $url)

URL-encode and escape a query string for use in a URL.

bool
isAlnum(string $alnum)

Check that a string is comprised solely of alphanumeric characters.

bool
isAlnumUnderscore(string $alnumUnderscore)

Check that a string is comprised solely of alphanumeric characters and underscores.

bool
isAlpha(string $alpha)

Check that a string is comprised solely of alphabetical characters.

bool
isUtf8(string $text)

Check if the character encoding of text is UTF-8.

string
trimString(mixed $text)

Cast to string, check UTF-8 encoding and strip trailing whitespace and control characters.

boolean
validateToken(string $token)

Validate a cross-site request forgery token from a form submission.

__construct(object $model)

Constructor.

displayCancel()

Cancel action and redirect to admin page.

displayConfirmDelete()

Display delete confirmation form.

displayDelete()

Delete content object and display result.

displayTable()

Display the admin summary table.

displayToggle()

Toggle a content object online or offline.

countContent()

Count content objects meeting filter criteria.

string
dateFormat()

Returns the template for formatting the date from preferences.

array
extraParams()

Return extra parameters to be included in pagination control links.

listContent()

Get content objects matching cached filter criteria.

int
limit()

Return admin-side pagination limit.

array
tagOptions(string $zeroOption = TFISH_SELECT_TAGS)

Return options for tag select box control.

array
typeOptions(string $zeroOption = TFISH_SELECT_TYPE)

Return options for type select box control.

array
statusOptions(string $defaultOption = TFISH_SELECT_STATUS)

Return options for tag online status select box control.

string
action()

Return the action for this page.

string
backUrl()

Return the backUrl.

int
contentCount()

Return content count.

array
contentList()

Return content list.

int
id()

Return ID.

setId(int $id)

Set ID.

string
contentTitle()

Return content title.

setContentTitle()

Set title of content object.

int
onlineStatus()

Return online status.

setOnlineStatus(int $onlineStatus)

Set online status.

string
response()

Return the response message (success or failure) for an action.

int
start()

Return start.

setStart(int $start)

Set start ID.

int
tag()

Return ID of tag filter.

setTag(int $tag)

Set tag ID.

string
type()

Return type.

setType(string $type)

Set type.

Details

in ContentTypes at line 36
array listTemplates()

Returns a list of template names used by specific content types.

Return Value

array Array of type-template key values.

in ContentTypes at line 62
array listTypes()

Returns a whitelist of permitted content object types.

Use this whitelist when dynamically instantiating content objects. If you create additional types of content object (which must be descendants of the TfContentObject class) you must add them to the whitelist below. Otherwise their use will be denied in many parts of the Tuskfish system.

Return Value

array Array of whitelisted (permitted) content object types.

in Listable at line 46
setOrder(string $field)

Sets the primary column to order query results by.

Parameters

string $field Name of the primary column to order the query results by.

in Listable at line 56
setOrderType(string $orderType)

Sets the sort type (ascending or descending) for the primary order column of a result set.

Parameters

string $orderType Ascending (ASC) or descending (DESC) order.

in Listable at line 66
setSecondaryOrder(string $field)

Sets the secondary column to order query results by.

Parameters

string $field Name of the secondary column to order the query results by.

in Listable at line 76
setSecondaryOrderType(string $orderType)

Sets the sort type (ascending or descending) for the secondary order column of a result set.

Parameters

string $orderType Ascending (ASC) or descending (DESC) order.

in Listable at line 88
string pageTitle()

Return title of this page.

Return Value

string

in Listable at line 98
setPageTitle(string $pageTitle)

Set the title of this page.

Parameters

string $pageTitle Title of this page.

in Listable at line 108
Template template()

Return the template object required by this page.

Return Value

Template

in Listable at line 118
setTemplate(string $template)

Set the template used by this page.

Parameters

string $template Name of template (alphanumeric and underscore characters only).

in Listable at line 135
string theme()

Return the theme used by this page.

Return Value

string

in Listable at line 147
setTheme(string $theme)

Set (change) the theme.

You must ensure that the new theme directory contains the HTML template files that you need.

Parameters

string $theme Name of theme directory (alphanumeric and underscores only).

in Listable at line 164
array metadata()

Return page-specific metadata overrides.

Return Value

array

in Listable at line 174
setMetadata(array $metadata)

Set page-specific overrides of the site metadata.

Parameters

array $metadata Array of metadata as key => value pairs.

in ValidateString at line 41
string encodeEscapeUrl(string $url)

URL-encode and escape a query string for use in a URL.

Trims, checks for UTF-8 compliance, rawurlencodes and then escapes with htmlspecialchars(). If you wish to use the data on a landing page you must decode it with htmlspecialchars_decode() followed by rawurldecode() in that order. But really, if you are using any characters that need to be encoded in the first place you should probably just stop.

Parameters

string $url Unescaped input URL.

Return Value

string Encoded and escaped URL.

in ValidateString at line 59
bool isAlnum(string $alnum)

Check that a string is comprised solely of alphanumeric characters.

Accented regional characters are rejected. This method is designed to be used to check database identifiers or object property names.

Parameters

string $alnum Input to be tested.

Return Value

bool True if valid alphanumerical string, false otherwise.

in ValidateString at line 77
bool isAlnumUnderscore(string $alnumUnderscore)

Check that a string is comprised solely of alphanumeric characters and underscores.

Accented regional characters are rejected. This method is designed to be used to check database identifiers or object property names.

Parameters

string $alnumUnderscore Input to be tested.

Return Value

bool True if valid alphanumerical or underscore string, false otherwise.

in ValidateString at line 95
bool isAlpha(string $alpha)

Check that a string is comprised solely of alphabetical characters.

Tolerates vanilla ASCII only. Accented regional characters are rejected. This method is designed to be used to check database identifiers or object property names.

Parameters

string $alpha Input to be tested.

Return Value

bool True if valid alphabetical string, false otherwise.

in ValidateString at line 113
bool isUtf8(string $text)

Check if the character encoding of text is UTF-8.

All strings received from external sources must be passed through this function, particularly prior to storage in the database.

Parameters

string $text Input string to check.

Return Value

bool True if string is UTF-8 encoded otherwise false.

in ValidateString at line 131
string trimString(mixed $text)

Cast to string, check UTF-8 encoding and strip trailing whitespace and control characters.

Removes trailing whitespace and control characters (ASCII <= 32 / UTF-8 points 0-32 inclusive), checks for UTF-8 character set and casts input to a string. Note that the data returned by this function still requires escaping at the point of use; it is not database or XSS safe.

As the input is cast to a string do NOT apply this function to non-string types (int, float, bool, object, resource, null, array, etc).

Parameters

mixed $text Input to be trimmed.

Return Value

string Trimmed and UTF-8 validated string.

in ValidateToken at line 40
boolean validateToken(string $token)

Validate a cross-site request forgery token from a form submission.

Forms contain a hidden field with a random token taken from the user's session. This token is used to validate that a form submission did indeed originate from the user, by comparing the value against that stored in the user's session. If they do not match then the request could be a forgery and the form submission should be rejected.

Parameters

string $token A form token to validate against the user's session.

Return Value

boolean True if token is valid.

at line 69
__construct(object $model)

Constructor.

Parameters

object $model Instance of a model class.

at line 85
displayCancel()

Cancel action and redirect to admin page.

at line 94
displayConfirmDelete()

Display delete confirmation form.

at line 105
displayDelete()

Delete content object and display result.

at line 127
displayTable()

Display the admin summary table.

Table a list of content and links to view, edit and delete items.

at line 138
displayToggle()

Toggle a content object online or offline.

at line 149
countContent()

Count content objects meeting filter criteria.

at line 165
string dateFormat()

Returns the template for formatting the date from preferences.

Return Value

string

at line 175
array extraParams()

Return extra parameters to be included in pagination control links.

Return Value

array

at line 192
listContent()

Get content objects matching cached filter criteria.

Result is cached as $contentList property.

at line 216
int limit()

Return admin-side pagination limit.

Return Value

int

at line 227
array tagOptions(string $zeroOption = TFISH_SELECT_TAGS)

Return options for tag select box control.

Parameters

string $zeroOption Text to display as default select box option.

Return Value

array IDs and titles as key-value pairs.

at line 252
array typeOptions(string $zeroOption = TFISH_SELECT_TYPE)

Return options for type select box control.

Parameters

string $zeroOption Text to display as default select box option.

Return Value

array IDs and content types as key-value pairs.

at line 265
array statusOptions(string $defaultOption = TFISH_SELECT_STATUS)

Return options for tag online status select box control.

Parameters

string $defaultOption Text to display as default select box option.

Return Value

array Online (1), offline (0) or both (2).

at line 281
string action()

Return the action for this page.

The action is usually embedded in the form, to control handling on submission (next page load).

Return Value

string

at line 293
string backUrl()

Return the backUrl.

If the cancel button is clicked, the user will be redirected to the backUrl.

Return Value

string

at line 303
int contentCount()

Return content count.

Return Value

int

at line 313
array contentList()

Return content list.

Return Value

array Array of content objects.

at line 323
int id()

Return ID.

Return Value

int ID of content object.

at line 333
setId(int $id)

Set ID.

Parameters

int $id ID of content object.

at line 341
string contentTitle()

Return content title.

Return Value

string

at line 349
setContentTitle()

Set title of content object.

at line 359
int onlineStatus()

Return online status.

Return Value

int Online (1) or offline (0).

at line 369
setOnlineStatus(int $onlineStatus)

Set online status.

Parameters

int $onlineStatus Online (1) or offline (0).

at line 379
string response()

Return the response message (success or failure) for an action.

Return Value

string

at line 389
int start()

Return start.

Return Value

int

at line 401
setStart(int $start)

Set start ID.

First record to return from result set.

Parameters

int $start ID of first object to return in the set of available records.

at line 411
int tag()

Return ID of tag filter.

Return Value

int

at line 421
setTag(int $tag)

Set tag ID.

Parameters

int $tag ID of tag.

at line 431
string type()

Return type.

Return Value

string Type of content object.

at line 443
setType(string $type)

Set type.

Filter list by content type.

Parameters

string $type Type of content object.