LS_Twig_Extension

Extends\Twig_Extension

This extension is needed to add complex functions to twig, needing specific process (like accessing config datas).

Most of the calls to internal functions don't need to be set here, but can be directly added to the internal config file. For example, the calls to encode, gT and eT don't need any extra parameters or process, so they are added as filters in the congif/internal.php:

'filters' => array( 'jencode' => 'CJSON::encode', 't' => 'eT', 'gT' => 'gT', ),

So you only add functions here when they need a specific process while called via Twig. To add an advanced function to twig:

  1. Add it here as a static public function eg: static public function foo($bar) { return procces($bar); }

  2. Add it in config/internal.php as a function, and as an allowed function in the sandbox eg: twigRenderer' => array( ... 'functions' => array( ... 'foo' => 'LS_Twig_Extension::foo', ...), ... 'sandboxConfig' => array( ... 'functions' => array('include', ..., 'foo') ),

Now you access this function in any twig file via: {{ foo($bar) }}, it will show the result of process($bar). If LS_Twig_Extension::foo() returns some HTML, by default the HTML will be escaped and shows as text. To get the pure HTML, just do: {{ foo($bar) | raw }}

package

Default

Methods

assetPublish

assetPublish(string $sRessource)
static

Arguments

$sRessource

string

Checks for a permission on render

checkPermission(String $permission,String $permissionGrade,Integer|NULL $iSurveyId = null): Boolean
static

Arguments

$permission

String

$permissionGrade

String

$iSurveyId

Integer|NULL

(default null)

Response

Boolean

createAbsoluteUrl

createAbsoluteUrl( $url, $params = array())
static

Arguments

$url

$params

createUrl

createUrl( $url, $params = array())
static

Arguments

$url

$params

darkencss

darkencss( $cssColor, $grade = 10, $alpha = 1)
static

Arguments

$cssColor

$grade

$alpha

get flat and ellipsize string

ellipsizeString(string $string,integer $maxlength,float $position = 1,string $ellipsis = '…'): string
static

Arguments

$string

string

to ellipsize

$maxlength

integer

of the final string

$position

float

of the ellipsis in string (between 0 and 1)

$ellipsis

string

string to shown in place of removed part

Response

string

flat and ellipsize text, for template compatibility

flatEllipsizeText(string $sString,boolean $bFlat = true,integer $iAbbreviated,string $sEllipsis = '...',integer $fPosition = 1): string
static
deprecated

(4.0)

Arguments

$sString

string

:the string

$bFlat

boolean

: flattenText or not : completely flat (not like flattenText from common_helper)

$iAbbreviated

integer

: max string text (if true : always flat), 0 or false : don't abbreviated

$sEllipsis

string

if abbreviated : the char to put at end (or middle)

$fPosition

integer

if abbreviated position to split (in % : 0 to 1)

Response

string

Get html text and remove whole not clean string

flatString(string $string,boolean $encode = false): string
static

Arguments

$string

string

to flatten

$encode

boolean

html entities

Response

string

Retrieve the question classes for a given question id Use in survey template question.twig file.

getAllQuestionClasses(integer $iQid): string
static

TODO: we'd rather provide a oQuestion object to the twig view with a method getAllQuestion(). But for now, this public static function respect the old way of doing

deprecated

must be removed when allow to broke template. Since it was in 3.0 , it was in API (and question.twig are surely be updated).

Arguments

$iQid

integer

the question id

Response

string

the classes

Retrieve all the previous answers from a given token To use it: {% set aResponses = getAllTokenAnswers(aSurveyInfo.sid) %} {{ dump(aResponses) }}

getAllTokenAnswers( $iSurveyID)
static

Of course, the survey must use token. If you want to show it after completion, the you must turn on public statistics

Arguments

$iSurveyID

getConfig

getConfig( $item)
static

Arguments

$item

Get the parsed output of the expression manger for a specific string

getExpressionManagerOutput(String $sInString): String
static

Arguments

$sInString

String

Response

String

Returns a list of filters to add to the existing list.

getFilters(): array<mixed,\Twig\TwigFilter>
inherited

Response

array<mixed,\Twig\TwigFilter>

Returns a list of functions to add to the existing list.

getFunctions(): array<mixed,\Twig\TwigFunction>
inherited

Response

array<mixed,\Twig\TwigFunction>

Returns a list of global variables to add to the existing list.

getGlobals(): array
inherited
deprecated

since 1.23 (to be removed in 2.0), implement \Twig_Extension_GlobalsInterface instead

Response

array

An array of global variables

Returns the "tracking url" for Google Analytics when style is "Survey-SID/GROUP"

getGoogleAnalyticsTrackingUrl(integer $surveyId,string $trackUrlPageName = ''): string
static

Arguments

$surveyId

integer

$trackUrlPageName

string

Specific page name to include in the tracking url. If it's empty, we will try to infer it from the context.

Response

string

The tracking URL as "-[]/[<page name|group seq>]-"

Returns true if the language uses RTL writing system.

getLanguageRTL( $sLanguageCode)
static

Arguments

$sLanguageCode

Returns the name of the extension.

getName(): string
inherited
deprecated

since 1.26 (to be removed in 2.0), not used anymore internally

Response

string

The extension name

Returns the node visitor instances to add to the existing list.

getNodeVisitors(): array<mixed,\Twig\NodeVisitor\NodeVisitorInterface>
inherited

Returns a list of operators to add to the existing list.

getOperators(): \Twig\Extension\array<array>
inherited

Response

\Twig\Extension\array

First array of unary operators, second array of binary operators

getParam

getParam( $sName, $sDefaultValue = null)
static

Arguments

$sName

$sDefaultValue

getPosition

getPosition( $position): string
static

Arguments

$position

Response

string

getPost

getPost( $sName, $sDefaultValue = null)
static

Arguments

$sName

$sDefaultValue

getQuery

getQuery( $sName, $sDefaultValue = null)
static

Arguments

$sName

$sDefaultValue

getTemplateForRessource

getTemplateForRessource(string $sRessource)
static

Arguments

$sRessource

string

Returns a list of tests to add to the existing list.

getTests(): array<mixed,\Twig\TwigTest>
inherited

Response

array<mixed,\Twig\TwigTest>

Get the textcontrol widget output for a specific string

getTextDisplayWidget(String $sInString, $name): String
static

Arguments

$sInString

String

$name

Response

String

Returns the token parser instances to add to the existing list.

getTokenParsers(): array<mixed,\Twig\TokenParser\TokenParserInterface>
inherited

image

image( $sImagePath, $alt = '', $htmlOptions = array()): string
static
var

string the image path relative to the template root

string the alternative text display

array additional HTML attribute

Arguments

$sImagePath

$alt

$htmlOptions

Response

string

imageSrc

imageSrc( $sImagePath, $default = false): string|false
static
var

string the image path relative to the template root

string|false an alternative image if the provided one cant be found

Arguments

$sImagePath

$default

Response

string|false

Check if a needle is in a multidimensional array

in_multiarray(mixed $needle,array $haystack,boolean $strict = false)

Arguments

$needle

mixed

The searched value.

$haystack

array

The array.

$strict

boolean

If the third parameter strict is set to TRUE then the in_array() function will also check the types of the needle in the haystack.

Initializes the runtime environment.

initRuntime(\Twig\Environment $environment)
inherited

This is where you can load some file that contains filter functions for instance.

deprecated

since 1.23 (to be removed in 2.0), implement \Twig_Extension_InitRuntimeInterface instead

Arguments

$environment

\Twig\Environment

Convert a json object to a PHP array (so no troubles with object method in sandbox)

json_decode(string $json,boolean $assoc = true): array
static

Arguments

$json

string

$assoc

boolean

return sub object as array too

Response

array

lightencss

lightencss( $cssColor, $grade = 10, $alpha = 1)
static

Arguments

$cssColor

$grade

$alpha

listCoreScripts

listCoreScripts()
static

listScriptFiles

listScriptFiles()
static

Process any string with current page

processString( $string,boolean $static = false,integer $numRecursionLevels = 3,array $aReplacement = array()): string
static

Arguments

$string

$static

boolean

return static string (or not)

$numRecursionLevels

integer

recursion (max) level to do

$aReplacement

array

replacement out of EM

Response

string

registerCssFile

registerCssFile( $path)
static

Arguments

$path

Publish a script file from general script directory, using or not the asset manager (depending on configuration) In any twig file, you can register a general script file doing: {{ registerGeneralScript($sGeneralScriptFileName) }}

registerGeneralScript(string $sGeneralScriptFileName,string $position = null,array $htmlOptions = array())
static

Arguments

$sGeneralScriptFileName

string

name of the script file to publish in general script directory (it should contains the subdirectories)

$position

string

$htmlOptions

array

registerPackage

registerPackage( $name)
static

Arguments

$name

Publish a css file from public style directory, using or not the asset manager (depending on configuration) In any twig file, you can register a public css file doing: {{ registerPublicCssFile($sPublicCssFileName) }}

registerPublicCssFile(string $sPublicCssFileName)
static

Arguments

$sPublicCssFileName

string

name of the CSS file to publish in public style directory

Publish a script In any twig file, you can register a script doing: {{ registerScript($sId, $sScript) }}

registerScript( $id, $script, $position = null,array $htmlOptions = array())
static

NOTE: this function is not recursive, so don't use it to register a script located inside a theme folder, or inherited themes will be broken. NOTE! to register a script located inside a theme folder, registerTemplateScript()

Arguments

$id

$script

$position

$htmlOptions

array

registerScriptFile

registerScriptFile( $path, $position = null)
static

Arguments

$path

$position

Publish a css file from template directory, using or not the asset manager (depending on configuration) In any twig file, you can register a template css file doing: {{ registerTemplateCssFile($sTemplateCssFileName) }}

registerTemplateCssFile(string $sTemplateCssFileName)
static

Arguments

$sTemplateCssFileName

string

name of the CSS file to publish in template directory (it should contains the subdirectories)

Publish a script file from template directory, using or not the asset manager (depending on configuration) In any twig file, you can register a template script file doing: {{ registerTemplateScript($sTemplateScriptFileName) }}

registerTemplateScript(string $sTemplateScriptFileName,string $position = null,array $htmlOptions = array())
static

Arguments

$sTemplateScriptFileName

string

name of the script file to publish in general script directory (it should contains the subdirectories)

$position

string

$htmlOptions

array

renderCaptcha

renderCaptcha()
static

since count with a noncountable element is throwing a warning in latest php versions we have to be sure not to kill rendering by a wrong variable

safecount(mixed $element): void
static

Arguments

$element

mixed

templateResourceUrl

templateResourceUrl( $resourcePath, $default = false): string|false
static
var

string : the needed resource

string : the default resource if needed resssource didn't exist

Arguments

$resourcePath

$default

Response

string|false

unregisterPackage

unregisterPackage(string $name)
static

Arguments

$name

string

unregisterScriptFile

unregisterScriptFile(string $name)
static

Arguments

$name

string

Unregister all packages/script files for AJAX rendering

unregisterScriptForAjax()
static