class ContentEdit implements Viewable

ViewModel for editing content objects.

Traits

Provides an array of time zones.
Provides methods for validating UTF-8 character encoding and string composition.
Provides method for validating cross-site request forgery tokens.
Provides standard implementation for the Viewable interface.

Methods

array
listTimezones()

Provide a list of timezone offsets.

from Timezones
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.

string
pageTitle()

Return title of this page.

from Viewable
setPageTitle(string $pageTitle)

Set the title of this page.

from Viewable
template()

Return the template object required by this page.

from Viewable
setTemplate(string $template)

Set the template used by this page.

from Viewable
string
theme()

Return the theme used by this page.

from Viewable
setTheme(string $theme)

Set (change) the theme.

from Viewable
array
metadata()

Return page-specific metadata overrides.

from Viewable
setMetadata(array $metadata)

Set page-specific overrides of the site metadata.

from Viewable
__construct(object $model)

Constructor.

displayAdd()

Display Add content form.

displayCancel()

Cancel action and redirect to admin page.

displayEdit()

Display edit content form.

displaySave()

Save content object (new or updated).

string
dateFormat()

Returns the date template as per the date() function of PHP.

string
defaultLanguage()

Returns the default language preference.

array
listTags()

Returns a list of options for the tag select box.

array
parentOptions()

Returns a list of options for the parent select box.

string
siteAuthor()

Return the site author preference.

string
action()

Return the action for this page.

string
backUrl()

Return the backUrl.

content()

Return a content object.

setContent(Content $content)

Set content.

int
id()

Return ID.

string
response()

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

Details

in Timezones at line 36
array listTimezones()

Provide a list of timezone offsets.

Return Value

array Array of timezone offsets.

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.

in Viewable at line 39
string pageTitle()

Return title of this page.

Return Value

string

in Viewable at line 49
setPageTitle(string $pageTitle)

Set the title of this page.

Parameters

string $pageTitle Title of this page.

in Viewable at line 59
Template template()

Return the template object required by this page.

Return Value

Template

in Viewable at line 69
setTemplate(string $template)

Set the template used by this page.

Parameters

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

in Viewable at line 86
string theme()

Return the theme used by this page.

Return Value

string

in Viewable at line 98
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 Viewable at line 115
array metadata()

Return page-specific metadata overrides.

Return Value

array

in Viewable at line 125
setMetadata(array $metadata)

Set page-specific overrides of the site metadata.

Parameters

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

at line 59
__construct(object $model)

Constructor.

Parameters

object $model Instance of a model class.

at line 71
displayAdd()

Display Add content form.

at line 85
displayCancel()

Cancel action and redirect to admin page.

at line 94
displayEdit()

Display edit content form.

at line 118
displaySave()

Save content object (new or updated).

at line 158
string dateFormat()

Returns the date template as per the date() function of PHP.

Return Value

string

at line 168
string defaultLanguage()

Returns the default language preference.

Return Value

string Default language as two-letter ISO code.

at line 178
array listTags()

Returns a list of options for the tag select box.

Return Value

array Array of tag IDs and titles as key-value pairs.

at line 188
array parentOptions()

Returns a list of options for the parent select box.

Return Value

array Array of parent (collection) IDs and titles as key-value pairs.

at line 201
string siteAuthor()

Return the site author preference.

Return Value

string

at line 215
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 227
string backUrl()

Return the backUrl.

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

Return Value

string

at line 237
Content content()

Return a content object.

Return Value

Content

at line 247
setContent(Content $content)

Set content.

Parameters

Content $content Content object to be edited.

at line 257
int id()

Return ID.

Return Value

int ID of content object.

at line 267
string response()

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

Return Value

string