LimeSurvey API - Master branch

SurveyThemeHelper
in package

General helper class for survey themes

Table of Contents

Methods

checkConfigFiles()  : void
Checks and updates the given configuration file if necessary.
getFileCategories()  : array<string|int, ThemeFileCategory>
Returns a list of file categories for the theme.
getNestedThemeConfigPath()  : mixed
getRealThemeFilePath()  : string|null
Returns the real absolute 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.
checkDomDocument()  : DOMDocument|null
Processes a DOMDocument object to check and potentially modify its structure.

Methods

checkConfigFiles()

Checks and updates the given configuration file if necessary.

public static checkConfigFiles(string $configFile) : void

This function loads the specified XML configuration file into a DOMDocument object, checks for its validity, and if applicable, updates it by calling checkDomDocument. If the file is invalid or an exception occurs, a warning is logged with details about the issue.

Parameters
$configFile : string

Path to the configuration file to be checked and potentially updated.

Tags
throws
Exception

Propagates any exceptions thrown by checkDomDocument.

Return values
void

This function does not return a value. It may either update the configuration file or log a warning if the file is invalid or cannot be processed.

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>

getNestedThemeConfigPath()

public static getNestedThemeConfigPath(mixed $templateName) : mixed
Parameters
$templateName : mixed

getRealThemeFilePath()

Returns the real absolute 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 directory 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

checkDomDocument()

Processes a DOMDocument object to check and potentially modify its structure.

private static checkDomDocument(DOMDocument $domDocument) : DOMDocument|null

This method specifically looks for 'cssframework' nodes within the given DOMDocument. If found, it examines child nodes for a default option and 'dropdownoptions'. It ensures that all 'option' nodes are wrapped within an 'optgroup' element. If any modifications are made, the DOMDocument is marked as changed.

Parameters
$domDocument : DOMDocument

The DOMDocument object to be checked and potentially modified.

Tags
throws
Exception

If an invalid node is found within 'dropdownoptions' or if no 'dropdownoptions' nodes are found when expected.

Return values
DOMDocument|null

Returns the modified DOMDocument if changes were made, otherwise null. Changes include ensuring 'option' nodes within 'cssframework' are properly grouped under an 'optgroup' and setting a default option if not present.


        
On this page

Search results