class Pagination

Generates pagination controls for paging through content.

The number of pagination control slots is set in Tuskfish Preferences. Choose an odd number for best results.

Traits

Validates that a filename or path does NOT contain directory traversals in any form.
Validate that a URL meets the specification.
Provides methods for validating UTF-8 character encoding and string composition.

Methods

bool
hasTraversalorNullByte(string $path)

Check if a file path contains traversals (including encoded traversals) or null bytes.

bool
isUrl(string $url)

Validate URL.

from UrlCheck
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, string $path)

Constructor.

string
renderPaginationControl()

Creates a pagination control designed for use with the Bootstrap framework.

setCount(int $count)

Set the count property, which represents the number of objects matching the page parameters.

boolean
setExtraParams(array $extraParams)

Set extra parameters to be included in pagination control links.

setGallerySideLimit()

Set the pagination limit for gallery views.

setLimit(int $limit)

Sets the limit property, which controls the number of objects to be retrieved in a single page view.

setSearchSideLimit()

Set the pagination limit for search views.

setStart(int $start)

Set the starting position in the set of available object.

setTag(int $tag)

Set the ID of a tag used to filter content.

setUrl(string $path)

Set the base URL for pagination control links.

setUserSideLimit()

Set the pagination limit for user-side views (other than search or gallery).

Details

in TraversalCheck at line 46
bool hasTraversalorNullByte(string $path)

Check if a file path contains traversals (including encoded traversals) or null bytes.

Directory traversals are not permitted in Tuskfish method parameters. If a path is found to contain a traversal it is presumed to be an attack. Encoded traversals are a clear sign of attempted abuse.

In general untrusted data should never be used to construct a file path. This method exists as a second line safety measure.

Parameters

string $path

Return Value

bool True if a traversal or null byte is found, otherwise false.

See also

in UrlCheck at line 40
bool isUrl(string $url)

Validate URL.

Only accepts http:// and https:// protocol and ASCII characters. Other protocols and internationalised domain names will fail validation due to limitation of filter.

Parameters

string $url Input to be tested.

Return Value

bool True if valid URL otherwise false.

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 63
__construct(Preference $preference, string $path)

Constructor.

Parameters

Preference $preference An instance of the Tuskfish site preferences class.
string $path Base URL for constructing pagination links.

at line 87
string renderPaginationControl()

Creates a pagination control designed for use with the Bootstrap framework.

$query is an array of arbitrary query string parameters. Note that these need to be passed in as an array of key => value pairs, and you should build this yourself using known and whitelisted values. Do not pass through random query strings someone gave you on the internetz.

If you want to create pagination controls for other presentation-side libraries add additional methods to this class.

Return Value

string HTML pagination control.

at line 203
setCount(int $count)

Set the count property, which represents the number of objects matching the page parameters.

Parameters

int $count

at line 223
boolean setExtraParams(array $extraParams)

Set extra parameters to be included in pagination control links.

$extraParams is a potential XSS attack vector; only use known and whitelisted keys.

The key => value pairs are i) rawurlencoded and ii) entity escaped. However, in order to avoid messing up the query and avoid unnecessary decoding it is possible to maintain manual control over the operators. (Basically, input requiring encoding or escaping is absolutely not wanted here, it is just being conducted to mitigate XSS attacks). If you actually want to use such input (check your sanity), you will need to decode it prior to use on the landing page.

Parameters

array $extraParams Query string to be appended to the URLs (control script params)

Return Value

boolean Returns false on failure.

at line 248
setGallerySideLimit()

Set the pagination limit for gallery views.

at line 259
setLimit(int $limit)

Sets the limit property, which controls the number of objects to be retrieved in a single page view.

Parameters

int $limit Number of content objects to retrieve in current view.

at line 267
setSearchSideLimit()

Set the pagination limit for search views.

at line 277
setStart(int $start)

Set the starting position in the set of available object.

Parameters

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

at line 287
setTag(int $tag)

Set the ID of a tag used to filter content.

Parameters

int $tag ID of tag used to filter content.

at line 297
setUrl(string $path)

Set the base URL for pagination control links.

Parameters

string $path Base file name for constructing URLs, without the extension.

at line 308
setUserSideLimit()

Set the pagination limit for user-side views (other than search or gallery).