LimeSurvey API - Master branch

SurveyThemeHelper
in package

General helper class for survey themes

Table of Contents

Methods

getFileCategories()  : array<string|int, ThemeFileCategory>
Returns a list of file categories for the theme.
getRealThemeFilePath()  : string|null
Returns the real aboslute path of $path If $path is not valid, returns null.
getStandardTemplateList()  : array<string|int, string>
Return the standard template list
getTemplateInFolder()  : array<string, 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.
getTemplateInStandard()  : array<string, string>
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.
getTemplateInUpload()  : array<string, string>
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.
getThemeFileInfo()  : ThemeFileInfo|null
Validates $path and returns its file info Rules: - valid virtual path - real path for an available category
getThemeFileInfoFromAbsolutePath()  : ThemeFileInfo|null|false
Returns a path's ThemeFileInfo if it's an absolute path or relative to the root dir.
getThemeFileInfoFromRelativePath()  : ThemeFileInfo|false
Returns a path's ThemeFileInfo if it's relative to a category.
getThemePath()  : string
Returns the path to the theme specified by $themeName.
getVirtualPathPrefix()  : string|null
Returns the virtual path prefix of $virtualPath.
getVirtualThemeFilePath()  : string|null
Returns the virtual path for $path.
isStandardTemplate()  : bool
isStandardTemplate returns true if a template is a standard template.
isVirtualPath()  : bool
Returns true if $value matches the virtual path format.
sanitizePathInOption()  : string
Sanitizes a theme option value making sure that paths are valid.

Methods

getFileCategories()

Returns a list of file categories for the theme.

public static getFileCategories(string $themeName[, mixed $sid = null ]) : array<string|int, ThemeFileCategory>

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.

Parameters
$themeName : string
$sid : mixed = null
Return values
array<string|int, ThemeFileCategory>

getRealThemeFilePath()

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

public static getRealThemeFilePath(string $path, string $themeName[, mixed $sid = null ]) : string|null
Parameters
$path : string

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

$themeName : string
$sid : mixed = null
Return values
string|null

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

getStandardTemplateList()

Return the standard template list

public static getStandardTemplateList() : array<string|int, string>
Tags
throws
Exception
Return values
array<string|int, string>

getTemplateInFolder()

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.

public static getTemplateInFolder(string $folder) : array<string, string>
Parameters
$folder : string
Return values
array<string, string>

getTemplateInStandard()

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.

public static getTemplateInStandard() : array<string, string>
Return values
array<string, string>

getTemplateInUpload()

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.

public static getTemplateInUpload() : array<string, string>
Return values
array<string, string>

getThemeFileInfo()

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

public static getThemeFileInfo(string|null $path, string $themeName[, mixed $sid = null ]) : ThemeFileInfo|null
Parameters
$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 = null
Return values
ThemeFileInfo|null

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

getThemeFileInfoFromAbsolutePath()

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

public static getThemeFileInfoFromAbsolutePath(string $path, array<string|int, ThemeFileCategory$categoryList) : ThemeFileInfo|null|false

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

Parameters
$path : string
$categoryList : array<string|int, ThemeFileCategory>
Return values
ThemeFileInfo|null|false

getThemeFileInfoFromRelativePath()

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

public static getThemeFileInfoFromRelativePath(string $path, array<string|int, ThemeFileCategory$categoryList) : ThemeFileInfo|false

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

Parameters
$path : string
$categoryList : array<string|int, ThemeFileCategory>
Return values
ThemeFileInfo|false

getThemePath()

Returns the path to the theme specified by $themeName.

public static getThemePath(string $themeName) : string
Parameters
$themeName : string
Return values
string

getVirtualPathPrefix()

Returns the virtual path prefix of $virtualPath.

public static getVirtualPathPrefix(string $virtualPath) : string|null
Parameters
$virtualPath : string
Return values
string|null

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

getVirtualThemeFilePath()

Returns the virtual path for $path.

public static getVirtualThemeFilePath(string $path, string $themeName[, mixed $sid = null ]) : string|null
Parameters
$path : string

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

$themeName : string
$sid : mixed = null
Return values
string|null

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

isStandardTemplate()

isStandardTemplate returns true if a template is a standard template.

public static isStandardTemplate(mixed $themeName) : bool

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

Parameters
$themeName : mixed

template name to look for

Return values
bool

True if standard template, otherwise false

isVirtualPath()

Returns true if $value matches the virtual path format.

public static isVirtualPath(string $value) : bool

It doesn't check the path validity.

Parameters
$value : string
Return values
bool

sanitizePathInOption()

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

public static sanitizePathInOption(string $value, string $themeName[, string $sid = null ]) : string
  • 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).

Parameters
$value : string
$themeName : string
$sid : string = null
Return values
string

        
On this page

Search results