SurveyThemeHelper

General helper class for survey themes

package

Default

Methods

Returns a list of file categories for the theme.

getFileCategories(string $themeName,mixed $sid = null): array<mixed,\LimeSurvey\Datavalueobjects\ThemeFileCategory>
static

Each category is related to a directory which holds files for the theme. This files are usually listed to be selected as values for options.

Arguments

$themeName

string

$sid

mixed

Response

array<mixed,\LimeSurvey\Datavalueobjects\ThemeFileCategory>

Returns the real aboslute path of $path If $path is not valid, returns null.

getRealThemeFilePath(string $path,string $themeName,mixed $sid = null): string|null
static

Arguments

$path

string

the path to check. Can be a "virtual" path (eg. 'image::theme::logo.png'), or a normal path.

$themeName

string

$sid

mixed

Response

string|null

the real absolute path if it's valid, of null if it's not.

Return the standard template list

getStandardTemplateList(): array<mixed,string>
static
Throws
\Exception

Response

array<mixed,string>

Returns a list of themes found in the $folder, in the form of an array where the key is the theme name, and value is the theme's path.

getTemplateInFolder(string $folder): \array<string,string>
static

Arguments

$folder

string

Response

\array

Returns a list of standard themes, in the form of an array where the key is the folder name, and value is the theme's path.

getTemplateInStandard(): \array<string,string>
static

Response

\array

Returns a list of user themes, in the form of an array where the key is the folder name, and value is the theme's path.

getTemplateInUpload(): \array<string,string>
static

Response

\array

Validates $path and returns its file info Rules: - valid virtual path - real path for an available category

getThemeFileInfo(string|null $path,string $themeName,mixed $sid = null): \LimeSurvey\Datavalueobjects\ThemeFileInfo|null
static

Arguments

$path

string|null

the path to check. Can be a "virtual" path (eg. 'image::theme::logo.png'), or a normal path.

$themeName

string

$sid

mixed

Response

\LimeSurvey\Datavalueobjects\ThemeFileInfo|null

the file info if it's valid, or null if it's not.

Returns a path's ThemeFileInfo if it's an absolute path or relative to the root dir.

getThemeFileInfoFromAbsolutePath(string $path,array<mixed,\LimeSurvey\Datavalueobjects\ThemeFileCategory> $categoryList): \LimeSurvey\Datavalueobjects\ThemeFileInfo|null|false
static

The function returns false if the path is not found, and null if it's found but doesn't match a category.

Arguments

$path

string

Response

\LimeSurvey\Datavalueobjects\ThemeFileInfo|null|false

Returns a path's ThemeFileInfo if it's relative to a category.

getThemeFileInfoFromRelativePath(string $path,array<mixed,\LimeSurvey\Datavalueobjects\ThemeFileCategory> $categoryList): \LimeSurvey\Datavalueobjects\ThemeFileInfo|false
static

The function returns false if the path is not relative to any category.

Arguments

$path

string

Response

\LimeSurvey\Datavalueobjects\ThemeFileInfo|false

Returns the path to the theme specified by $themeName.

getThemePath(string $themeName): string
static

Arguments

$themeName

string

Response

string

Returns the virtual path prefix of $virtualPath.

getVirtualPathPrefix(string $virtualPath): string|null
static

Arguments

$virtualPath

string

Response

string|null

the virtual path prefix, or null if $virtualPath doesn't match the format

Returns the virtual path for $path.

getVirtualThemeFilePath(string $path,string $themeName,mixed $sid = null): string|null
static

Arguments

$path

string

the path to check. Can be a "virtual" path (eg. 'image::theme::logo.png'), or a normal path.

$themeName

string

$sid

mixed

Response

string|null

the virtual path if it's valid, of null if it's not.

isStandardTemplate returns true if a template is a standard template.

isStandardTemplate(mixed $themeName): boolean
static

This function does not check if a template actually exists. Scans standard themes folder and looks for folder matching the $themeName. Important: here is asumed that theme name = folder name

Arguments

$themeName

mixed

template name to look for

Response

boolean

True if standard template, otherwise false

Returns true if $value matches the virtual path format.

isVirtualPath(string $value): boolean
static

It doesn't check the path validity.

Arguments

$value

string

Response

boolean

Sanitizes a theme option value making sure that paths are valid.

sanitizePathInOption(string $value,string $themeName,string $sid = null): string
static
  • All paths should be relative to the root directoy of the current theme or general files.
  • All paths should be a subdir of the current theme or general files -no path traversal (.. or . ) will be allowed - (example: "../../files/image.png" is not allowed)

Options that match a file will be marked as invalid if the file is not valid, or replaced with the virtual path if the file is valid. The validity of paths depend on the theme configuration (basically the $themeName and the $sid, which could be empty for global options).

Arguments

$value

string

$themeName

string

$sid

string

Response

string