{% trans_default_domain 'security' %}
<h3>
    <span class="fas fa-wrench"></span>
    {% trans %}HTMLPurifier settings{% endtrans %}
    {{ pageSetVar('title', 'HTMLPurifier settings'|trans) }}
</h3>

<p class="alert alert-info">{% trans %}HTMLPurifier filtering occurs when a template string or variable is modified with the 'safehtml' modifier, or when a module asks for similar processing from within its functions.{% endtrans %}</p>

<div class="alert alert-warning">
    <h4>{% trans %}Warning{% endtrans %}</h4>
    <p>{% trans %}Setting HTMLPurifier configuration directives incorrectly can render your system unstable and inacessible. No validity checking is performed on any user-supplied settings. Ensure you fully understand each directive and its effects on your system. Ensure that all prerequisites are met and that any additional software or libraries required by each directive are properly installed and available to HTMLPurifier.{% endtrans %}</p>
    <p><a href="{{ path('zikulasecuritycentermodule_config_allowedhtml') }}" title="{% trans %}Allowed HTML settings{% endtrans %}">{% trans %}Allowed HTML settings{% endtrans %}</a> {% trans %}will be applied after HTMLPurifier processing is completed.{% endtrans %}</p>
</div>

<form action="{{ path('zikulasecuritycentermodule_config_purifierconfig') }}" method="post" enctype="application/x-www-form-urlencoded" role="form">
    {% for directiveNamespace, directives in purifierAllowed %}
    <fieldset>
        {% set namespaceFrag = directiveNamespace|e('url') %}
        {% set namespaceLink = '<a href="http://htmlpurifier.org/live/configdoc/plain.html#' ~ namespaceFrag ~ '" class="external">' ~ directiveNamespace ~ '</a>' %}
        <legend>{% trans with {'%s': namespaceLink|raw } %}HTMLPurifier %s configuration directives{% endtrans %}</legend>
        {% for directiveName, directive in directives|filter(d => d.supported) %}
            {% set idVal = 'purifierConfig_' ~ directive.key %}
            {% set nameVal = 'purifierConfig[' ~ directive.key ~ ']' %}

            {% if directive.allowNull %}
            <div class="form-group row">
                <label class="col-md-3 col-form-label" for="purifierConfig_div_{{ directive.key }}">
                    {{ directiveName }} <a href="http://htmlpurifier.org/live/configdoc/plain.html#{{ directive.key|e('url') }}" class="external">(?)</a>
                </label>
                <div class="col-md-9">
                    <div id="purifierConfig_div_{{ directive.key }}">
                        <input id="purifierConfig_Null_{{ directive.key }}" name="purifierConfig[Null_{{ directive.key }}]" type="checkbox" value="1"{% if directive.value is null %} checked="checked"{% endif %} onclick="{% if directive.type != purifierTypes.bool %}toggleWriteability('{{ idVal }}', checked);{% else %}toggleWriteability('{{ idVal }}_Yes', checked); toggleWriteability('{{ idVal }}_No', checked);{% endif %}" />
                        <label for="purifierConfig_Null_{{ directive.key }}">{% trans %}Use default value (if checked) or override value{% endtrans %}</label>
                    </div>
                </div>
            </div>
            <div class="form-group row">
                <label class="col-md-3 col-form-label" for="{{ idVal }}">&nbsp;</label>
            {% else %}
            <div class="form-group row">
                <label class="col-md-3 col-form-label" for="{{ idVal }}">{{ directiveName }} <a href="http://htmlpurifier.org/live/configdoc/plain.html#{{ directive.key|e('url') }}">(?)</a></label>
            {% endif %}

            {% set disabledVal = directive.value is null ? ' disabled="disabled"' : '' %}

            {% if directive.allowedValues is defined %}
                <div class="col-md-9">
                    <select id="{{ idVal }}" class="form-control" name="{{ nameVal }}"{{ disabledVal }} style="min-width: 5em">
                        {% for allowedVal in directive.allowedValues %}
                            <option value="{{ allowedVal }}"{% if directive.value == allowedVal %} selected="selected"{% endif %}>{{ allowedVal }}</option>
                        {% endfor %}
                    </select>
                </div>
            {% elseif directive.type in [purifierTypes.text, purifierTypes.itext, purifierTypes.list, purifierTypes.hash, purifierTypes.lookup] %}
                <div class="col-md-9">
                    <textarea id="{{ idVal }}" class="form-control" name="{{ nameVal }}" cols="50" rows="5"{{ disabledVal }}>{{ directive.value }}</textarea>
                    {% if directive.type in [purifierTypes.list, purifierTypes.lookup] %}
                        <em class="help-block sub">{% trans %}(Place each value on a separate line.){% endtrans %}</em>
                    {% elseif directive.type == purifierTypes.hash %}
                        <em class="help-block sub">{% trans %}(Separate each key-value pair with a colon (e.g., key:value). Place each key-value pair on a separate line.){% endtrans %}</em>
                    {% endif %}
                </div>
            {% elseif directive.type in [purifierTypes.string, purifierTypes.istring, purifierTypes.int, purifierTypes.float] %}
                <div class="col-md-9">
                    <input id="{{ idVal }}" name="{{ nameVal }}" class="form-control" type="text" value="{{ directive.value }}"{{ disabledVal }} />
                </div>
            {% elseif directive.type == purifierTypes.bool %}
                <div id="{{ idVal }}" class="col-md-9">
                    <input id="{{ idVal }}_Yes" name="{{ nameVal }}" type="radio" value="1"{% if directive.value == true %} checked="checked"{% endif %}{{ disabledVal }} />
                    <label for="{{ idVal }}_Yes">{% trans %}Yes{% endtrans %}</label>
                    <input id="{{ idVal }}_No" name="{{ nameVal }}" type="radio" value="0"{% if directive.value != true %} checked="checked"{% endif %}{{ disabledVal }} />
                    <label for="{{ idVal }}_No">{% trans %}No{% endtrans %}</label>
                </div>
            {% else %}
                <div class="col-md-9">
                    <em class="help-block sub">{% trans %}(Modification not supported.){% endtrans %} {% trans %}Value:{% endtrans %} {# directive.value|serialize #}{{ directive.value }}</em>
                </div>
            {% endif %}
            </div>
        {% endfor %}
        </fieldset>
    {% endfor %}

    <div class="form-group row">
        <div class="col-md-9 offset-md-3">
            <button class="btn btn-success" title="{% trans %}Save{% endtrans %}"><i class="fas fa-check"></i> {% trans %}Save{% endtrans %}</button>
            <a class="btn btn-secondary" href="{{ path('zikulasecuritycentermodule_config_config') }}" title="{% trans %}Cancel{% endtrans %}"><i class="fas fa-times"></i> {% trans %}Cancel{% endtrans %}</a>
            <a class="btn btn-secondary" href="{{ path('zikulasecuritycentermodule_config_purifierconfig', {reset: 'default'}) }}" title="{% trans %}Reset to default values{% endtrans %}"><i class="fas fa-sync"></i> {% trans %}Reset to default values{% endtrans %}</a>
        </div>
    </div>
</form>
{{ pageAddAsset('javascript', zasset('@ZikulaSecurityCenterModule:js/ZikulaSecurityCenterModule.Admin.PurifierConfig.js')) }}
