class Metadata

Provides site-level metadata that can be overriden by a particular page.

Metadata is a subset of the preference values. Eventually it would be best to split them.

Traits

Provides methods for validating UTF-8 character encoding and string composition.

Properties

$siteName
$title
$description
$author
$copyright
$seo
$robots
$canonicalUrl
$language

Methods

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.

__construct(Preference $preference)

Constructor.

setSiteName(string $value)

Sets the site title property.

setTitle(string $value)

Sets the page meta title property.

setDescription(string $value)

Sets the meta description property.

setAuthor(string $value)

Sets the page meta author property.

setCopyright(string $value)

Sets the page meta copyright property.

setSeo(string $value)

Sets the SEO-friendly URL string for this page.

setRobots(string $value)

Sets the meta robots directive for this page.

setCanonicalUrl(string $value)

Set query string parameters for the canonical URL tag in theme.html files.

setLanguage(string $language)

Set the language meta tag for this page.

update(array $override)

Update metadata properties to page-specific values.

Details

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.

at line 58
__construct(Preference $preference)

Constructor.

Parameters

Preference $preference Instance of Preference, holding site preferences.

at line 75
setSiteName(string $value)

Sets the site title property.

Parameters

string $value Site name.

at line 85
setTitle(string $value)

Sets the page meta title property.

Parameters

string $value Page title.

at line 95
setDescription(string $value)

Sets the meta description property.

Parameters

string $value Page description.

at line 105
setAuthor(string $value)

Sets the page meta author property.

Parameters

string $value Page author.

at line 115
setCopyright(string $value)

Sets the page meta copyright property.

Parameters

string $value Page copyright.

at line 125
setSeo(string $value)

Sets the SEO-friendly URL string for this page.

Parameters

string $value SEO string.

at line 135
setRobots(string $value)

Sets the meta robots directive for this page.

Parameters

string $value Robots directive.

at line 147
setCanonicalUrl(string $value)

Set query string parameters for the canonical URL tag in theme.html files.

Do not pass in the base URL (domain) of the site, only the query string.

Parameters

string $value Query string parameters for canonical URL of relevant page.

at line 157
setLanguage(string $language)

Set the language meta tag for this page.

Parameters

string $language 2-letter ISO language code.

at line 167
update(array $override)

Update metadata properties to page-specific values.

Parameters

array $override Array of key-value pairs of properties that should be updated.