mirror of
https://github.com/Combodo/iTop.git
synced 2026-03-03 16:14:13 +01:00
Refactor "sanitize_identifier" and "sanitize_variable_name"custom TWIG functions to "sanitize(FOO)"
Note: FOO is one of \utils::ENUM_SANITIZATION_FILTER_XXX
This commit is contained in:
@@ -86,19 +86,18 @@ class Extension
|
||||
})
|
||||
);
|
||||
|
||||
// Filter to sanitize an XML / HTML identifier
|
||||
// Usage in twig: {{ 'identifier:to-sanitize'|sanitize_identifier }}
|
||||
$oTwigEnv->addFilter(new Twig_SimpleFilter('sanitize_identifier', function ($sString) {
|
||||
return utils::Sanitize($sString, '', utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER);
|
||||
/**
|
||||
* Filter to sanitize a text
|
||||
* Usage in twig: {{ 'variable_name:to-sanitize'|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) }}
|
||||
*
|
||||
* @uses \utils::Sanitize()
|
||||
* @since 3.0.0
|
||||
*/
|
||||
$oTwigEnv->addFilter(new Twig_SimpleFilter('sanitize', function (string $sString, string $sFilter) {
|
||||
return utils::Sanitize($sString, '', $sFilter);
|
||||
})
|
||||
);
|
||||
|
||||
// Filter to sanitize a variable name
|
||||
// Usage in twig: {{ 'variable_name:to-sanitize'|sanitize_variable_name }}
|
||||
$oTwigEnv->addFilter(new Twig_SimpleFilter('sanitize_variable_name', function ($sString) {
|
||||
return utils::Sanitize($sString, '', utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME);
|
||||
})
|
||||
);
|
||||
// Filter to add a parameter at the end of the URL to force cache invalidation after an upgrade.
|
||||
// Previously we put the iTop version but now it's the last setup/toolkit timestamp to avoid cache issues when building several times the same version during tests
|
||||
//
|
||||
@@ -106,9 +105,7 @@ class Extension
|
||||
$oTwigEnv->addFilter(new Twig_SimpleFilter('add_itop_version', function ($sUrl) {
|
||||
if (strpos($sUrl, '?') === false) {
|
||||
$sUrl = $sUrl."?t=".utils::GetCacheBusterTimestamp();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$sUrl = $sUrl."&t=".utils::GetCacheBusterTimestamp();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,20 +9,23 @@
|
||||
{% for oTab in oUIBlock.GetSubBlocks() %}
|
||||
{% block iboTabContainerTab %}
|
||||
{% if oTab.GetType() == constant('TabManager::ENUM_TAB_TYPE_AJAX') %}
|
||||
<li class="ibo-tab-container--tab-header" data-role="ibo-tab-container--tab-header"
|
||||
data-tab-id="tab_{{ oTab.GetId()|sanitize_identifier }}" data-tab-type="{{ oTab.GetType() }}"
|
||||
data-cache="{{ oTab.GetCache() }}">
|
||||
<a href="{{ oTab.GetUrl() }}" class="ibo-tab-container--tab-toggler"
|
||||
data-role="ibo-tab-container--tab-toggler"><span>{{ oTab.GetTitle() }}</span></a>
|
||||
</li>
|
||||
{% elseif oTab.GetType() == constant('TabManager::ENUM_TAB_TYPE_HTML') %}
|
||||
<li class="ibo-tab-container--tab-header" data-role="ibo-tab-container--tab-header"
|
||||
data-tab-id="tab_{{ oTab.GetId()|sanitize_identifier }}" data-tab-type="{{ oTab.GetType() }}">
|
||||
<a href="#tab_{{ oTab.GetId()|sanitize_identifier }}" class="ibo-tab-container--tab-toggler" data-role="ibo-tab-container--tab-toggler">
|
||||
<span>{{ oTab.GetTitle() }}</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="ibo-tab-container--tab-header" data-role="ibo-tab-container--tab-header"
|
||||
data-tab-id="tab_{{ oTab.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER')) }}"
|
||||
data-tab-type="{{ oTab.GetType() }}"
|
||||
data-cache="{{ oTab.GetCache() }}">
|
||||
<a href="{{ oTab.GetUrl() }}" class="ibo-tab-container--tab-toggler"
|
||||
data-role="ibo-tab-container--tab-toggler"><span>{{ oTab.GetTitle() }}</span></a>
|
||||
</li>
|
||||
{% elseif oTab.GetType() == constant('TabManager::ENUM_TAB_TYPE_HTML') %}
|
||||
<li class="ibo-tab-container--tab-header" data-role="ibo-tab-container--tab-header"
|
||||
data-tab-id="tab_{{ oTab.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER')) }}"
|
||||
data-tab-type="{{ oTab.GetType() }}">
|
||||
<a href="#tab_{{ oTab.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER')) }}"
|
||||
class="ibo-tab-container--tab-toggler" data-role="ibo-tab-container--tab-toggler">
|
||||
<span>{{ oTab.GetTitle() }}</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% endfor %}
|
||||
<li class="ibo-tab-container--extra-tabs-container ibo-tab-container--tab-header" data-role="ibo-tab-container--extra-tabs-container">
|
||||
@@ -30,11 +33,12 @@
|
||||
<span class="fas fa-ellipsis-v"></span>
|
||||
</a>
|
||||
<div class="ibo-tab-container--extra-tabs-list ibo-is-hidden" data-role="ibo-tab-container--extra-tabs-list">
|
||||
{% for oTab in oUIBlock.GetSubBlocks() %}
|
||||
<a href="#tab_{{ oTab.GetId()|sanitize_identifier }}" class="ibo-tab-container--extra-tab-toggler" data-role="ibo-tab-container--extra-tab-toggler">
|
||||
<span>{{ oTab.GetTitle() }}</span>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% for oTab in oUIBlock.GetSubBlocks() %}
|
||||
<a href="#tab_{{ oTab.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER')) }}"
|
||||
class="ibo-tab-container--extra-tab-toggler" data-role="ibo-tab-container--extra-tab-toggler">
|
||||
<span>{{ oTab.GetTitle() }}</span>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</li>
|
||||
{% endblock %}
|
||||
@@ -45,30 +49,32 @@
|
||||
{% if not aPage.isPrintable %}
|
||||
<div id="{{ oUIBlock.GetId() }}--tab-container-list" class="ibo-tab-container--tab-container-list" data-role="ibo-tab-container--tab-container-list">
|
||||
{% for oTab in oUIBlock.GetSubBlocks() %}
|
||||
{% if oTab.GetType() == constant('TabManager::ENUM_TAB_TYPE_HTML') %}
|
||||
<div id="tab_{{ oTab.GetId()|sanitize_identifier }}" class="ibo-tab-container--tab-container">
|
||||
{% if oUIBlock.GetIsScrollable() %}
|
||||
<div class="ibo-tab-container--tab-container--label"><span>{{ oTab.GetTitle() }}</span></div>
|
||||
{% endif %}
|
||||
{{ render_block(oTab, {aPage: aPage}) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if oTab.GetType() == constant('TabManager::ENUM_TAB_TYPE_HTML') %}
|
||||
<div id="tab_{{ oTab.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER')) }}"
|
||||
class="ibo-tab-container--tab-container">
|
||||
{% if oUIBlock.GetIsScrollable() %}
|
||||
<div class="ibo-tab-container--tab-container--label"><span>{{ oTab.GetTitle() }}</span></div>
|
||||
{% endif %}
|
||||
{{ render_block(oTab, {aPage: aPage}) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
|
||||
{% for oTab in oUIBlock.GetSubBlocks() %}
|
||||
<div id="tab_{{ oTab.GetId()|sanitize_identifier }}" class="ibo-tab-container--tab-container">
|
||||
<div class="ibo-title--text title">
|
||||
{{ oTab.GetTitle() }}
|
||||
</div>
|
||||
{% if oTab.GetType() == constant('TabManager::ENUM_TAB_TYPE_HTML') %}
|
||||
{{ render_block(oTab, {aPage: aPage}) }}
|
||||
{% else %}
|
||||
<div class="printable-tab-content"></div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% for oTab in oUIBlock.GetSubBlocks() %}
|
||||
<div id="tab_{{ oTab.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER')) }}"
|
||||
class="ibo-tab-container--tab-container">
|
||||
<div class="ibo-title--text title">
|
||||
{{ oTab.GetTitle() }}
|
||||
</div>
|
||||
{% if oTab.GetType() == constant('TabManager::ENUM_TAB_TYPE_HTML') %}
|
||||
{{ render_block(oTab, {aPage: aPage}) }}
|
||||
{% else %}
|
||||
<div class="printable-tab-content"></div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
$('#{{ oUIBlock.GetId() }}').tab_container();
|
||||
{% else %}
|
||||
{% for oTab in oUIBlock.GetSubBlocks() %}
|
||||
oHiddeableChapters['tab_{{ oTab.GetId()|sanitize_identifier }}'] = '{{ oTab.GetTitle()|escape('js') }}';
|
||||
{% if oTab.GetType() == constant('TabManager::ENUM_TAB_TYPE_AJAX') %}
|
||||
$.post('{{ oTab.GetUrl()|raw}}', {printable: '1'}, function(data){
|
||||
$('#tab_{{ oTab.GetId()|sanitize_identifier }} > .printable-tab-content').append(data);
|
||||
});
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
oHiddeableChapters['tab_{{ oTab.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER')) }}'] = '{{ oTab.GetTitle()|escape('js') }}';
|
||||
{% if oTab.GetType() == constant('TabManager::ENUM_TAB_TYPE_AJAX') %}
|
||||
$.post('{{ oTab.GetUrl()|raw }}', {printable: '1'}, function (data)
|
||||
{
|
||||
$('#tab_{{ oTab.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER')) }} > .printable-tab-content').append(data);
|
||||
});
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
{% endblock %}
|
||||
|
||||
{% if aPage.aJsFiles is not empty %}
|
||||
{% set sId = oUIBlock.GetId() | sanitize_variable_name %}
|
||||
{% set sId = oUIBlock.GetId() | sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) %}
|
||||
{% block iboPageJsFiles %}
|
||||
<script type="text/javascript">
|
||||
var aFilesToLoad{{ sId }} = [];
|
||||
|
||||
Reference in New Issue
Block a user