ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Whoops\Util\TemplateHelper Class Reference

Exposes useful tools for working with/in templates. More...

+ Collaboration diagram for Whoops\Util\TemplateHelper:

Public Member Functions

 escape ($raw)
 Escapes a string for output in an HTML document. More...
 
 escapeButPreserveUris ($raw)
 Escapes a string for output in an HTML document, but preserves URIs within it, and converts them to clickable anchor elements. More...
 
 slug ($original)
 Convert a string to a slug version of itself. More...
 
 render ($template, array $additionalVariables=null)
 Given a template path, render it within its own scope. More...
 
 setVariables (array $variables)
 Sets the variables to be passed to all templates rendered by this template helper. More...
 
 setVariable ($variableName, $variableValue)
 Sets a single template variable, by its name: More...
 
 getVariable ($variableName, $defaultValue=null)
 Gets a single template variable, by its name, or $defaultValue if the variable does not exist. More...
 
 delVariable ($variableName)
 Unsets a single template variable, by its name. More...
 
 getVariables ()
 Returns all variables for this helper. More...
 

Private Attributes

 $variables = array()
 

Detailed Description

Exposes useful tools for working with/in templates.

Definition at line 12 of file TemplateHelper.php.

Member Function Documentation

◆ delVariable()

Whoops\Util\TemplateHelper::delVariable (   $variableName)

Unsets a single template variable, by its name.

Parameters
string$variableName

Definition at line 140 of file TemplateHelper.php.

141  {
142  unset($this->variables[$variableName]);
143  }

◆ escape()

Whoops\Util\TemplateHelper::escape (   $raw)

Escapes a string for output in an HTML document.

Parameters
string$raw
Returns
string

Definition at line 26 of file TemplateHelper.php.

Referenced by Whoops\Util\TemplateHelper\escapeButPreserveUris().

27  {
28  $flags = ENT_QUOTES;
29 
30  // HHVM has all constants defined, but only ENT_IGNORE
31  // works at the moment
32  if (defined("ENT_SUBSTITUTE") && !defined("HHVM_VERSION")) {
33  $flags |= ENT_SUBSTITUTE;
34  } else {
35  // This is for 5.3.
36  // The documentation warns of a potential security issue,
37  // but it seems it does not apply in our case, because
38  // we do not blacklist anything anywhere.
39  $flags |= ENT_IGNORE;
40  }
41 
42  return htmlspecialchars($raw, $flags, "UTF-8");
43  }
+ Here is the caller graph for this function:

◆ escapeButPreserveUris()

Whoops\Util\TemplateHelper::escapeButPreserveUris (   $raw)

Escapes a string for output in an HTML document, but preserves URIs within it, and converts them to clickable anchor elements.

Parameters
string$raw
Returns
string

Definition at line 52 of file TemplateHelper.php.

References Whoops\Util\TemplateHelper\escape().

53  {
54  $escaped = $this->escape($raw);
55  return preg_replace(
56  "@([A-z]+?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@",
57  "<a href=\"$1\" target=\"_blank\">$1</a>", $escaped
58  );
59  }
escape($raw)
Escapes a string for output in an HTML document.
+ Here is the call graph for this function:

◆ getVariable()

Whoops\Util\TemplateHelper::getVariable (   $variableName,
  $defaultValue = null 
)

Gets a single template variable, by its name, or $defaultValue if the variable does not exist.

Parameters
string$variableName
mixed$defaultValue
Returns
mixed

Definition at line 129 of file TemplateHelper.php.

130  {
131  return isset($this->variables[$variableName]) ?
132  $this->variables[$variableName] : $defaultValue;
133  }

◆ getVariables()

Whoops\Util\TemplateHelper::getVariables ( )

Returns all variables for this helper.

Returns
array

Definition at line 150 of file TemplateHelper.php.

References Whoops\Util\TemplateHelper\$variables.

Referenced by Whoops\Util\TemplateHelper\render().

151  {
152  return $this->variables;
153  }
+ Here is the caller graph for this function:

◆ render()

Whoops\Util\TemplateHelper::render (   $template,
array  $additionalVariables = null 
)

Given a template path, render it within its own scope.

This method also accepts an array of additional variables to be passed to the template.

Parameters
string$template
array$additionalVariables

Definition at line 82 of file TemplateHelper.php.

References Whoops\Util\TemplateHelper\$variables, and Whoops\Util\TemplateHelper\getVariables().

83  {
84  $variables = $this->getVariables();
85 
86  // Pass the helper to the template:
87  $variables["tpl"] = $this;
88 
89  if ($additionalVariables !== null) {
90  $variables = array_replace($variables, $additionalVariables);
91  }
92 
93  call_user_func(function () {
94  extract(func_get_arg(1));
95  require func_get_arg(0);
96  }, $template, $variables);
97  }
getVariables()
Returns all variables for this helper.
+ Here is the call graph for this function:

◆ setVariable()

Whoops\Util\TemplateHelper::setVariable (   $variableName,
  $variableValue 
)

Sets a single template variable, by its name:

Parameters
string$variableName
mixd$variableValue

Definition at line 116 of file TemplateHelper.php.

117  {
118  $this->variables[$variableName] = $variableValue;
119  }

◆ setVariables()

Whoops\Util\TemplateHelper::setVariables ( array  $variables)

Sets the variables to be passed to all templates rendered by this template helper.

Parameters
array$variables

Definition at line 105 of file TemplateHelper.php.

References Whoops\Util\TemplateHelper\$variables.

106  {
107  $this->variables = $variables;
108  }

◆ slug()

Whoops\Util\TemplateHelper::slug (   $original)

Convert a string to a slug version of itself.

Parameters
string$original
Returns
string

Definition at line 67 of file TemplateHelper.php.

68  {
69  $slug = str_replace(" ", "-", $original);
70  $slug = preg_replace('/[^\w\d\-\_]/i', '', $slug);
71  return strtolower($slug);
72  }

Field Documentation

◆ $variables

Whoops\Util\TemplateHelper::$variables = array()
private

The documentation for this class was generated from the following file: