Skip to content

Commit

Permalink
Update escaping of facet values so that translatable facet values can…
Browse files Browse the repository at this point in the history
… be translated in translation mode
  • Loading branch information
mdnoble73 committed May 23, 2024
1 parent 3f33929 commit c47199b
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 38 deletions.
19 changes: 10 additions & 9 deletions code/web/interface/plugins/function.translate.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
function smarty_function_translate($params, Smarty_Internal_Template &$smarty) {
function smarty_function_translate($params, Smarty_Internal_Template &$smarty) : string {
global $translator;

// If no translator exists yet, create one -- this may be necessary if we
Expand All @@ -15,20 +15,21 @@ function smarty_function_translate($params, Smarty_Internal_Template &$smarty) {
$translator = new Translator('lang', $code);
}
if (is_array($params)) {
$defaultText = isset($params['defaultText']) ? $params['defaultText'] : null;
$inAttribute = isset($params['inAttribute']) ? $params['inAttribute'] : false;
$isPublicFacing = isset($params['isPublicFacing']) ? $params['isPublicFacing'] : false;
$isAdminFacing = isset($params['isAdminFacing']) ? $params['isAdminFacing'] : false;
$isMetadata = isset($params['isMetadata']) ? $params['isMetadata'] : false;
$isAdminEnteredData = isset($params['isAdminEnteredData']) ? $params['isAdminEnteredData'] : false;
$translateParameters = isset($params['translateParameters']) ? $params['translateParameters'] : false;
$defaultText = $params['defaultText'] ?? null;
$inAttribute = $params['inAttribute'] ?? false;
$isPublicFacing = $params['isPublicFacing'] ?? false;
$isAdminFacing = $params['isAdminFacing'] ?? false;
$isMetadata = $params['isMetadata'] ?? false;
$isAdminEnteredData = $params['isAdminEnteredData'] ?? false;
$translateParameters = $params['translateParameters'] ?? false;
$escape = $params['escape'] ?? false;
$replacementValues = [];
foreach ($params as $index => $param) {
if (is_numeric($index)) {
$replacementValues[$index] = $param;
}
}
return $translator->translate($params['text'], $defaultText, $replacementValues, $inAttribute, $isPublicFacing, $isAdminFacing, $isMetadata, $isAdminEnteredData, $translateParameters);
return $translator->translate($params['text'], $defaultText, $replacementValues, $inAttribute, $isPublicFacing, $isAdminFacing, $isMetadata, $isAdminEnteredData, $translateParameters, $escape);
} else {
return $translator->translate($params, null, [], false);
}
Expand Down
4 changes: 2 additions & 2 deletions code/web/interface/themes/responsive/Admin/propertiesList.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@
{/if}
{if !empty($canExportToCSV) && !empty($dataList)}
<div class="btn-group">
<input type='submit' name='exportToCSV' value="{translate text='Export Selected to CSV' isAdminFacing=true}" class="btn btn-default" onclick="$('#objectAction').val('exportSelectedToCSV');" />
<input type='submit' name='exportToCSV' value="{translate text='Export to CSV' isAdminFacing=true}" class="btn btn-default" onclick="$('#objectAction').val('exportToCSV');" />
<input type='submit' name='exportToCSV' value="{translate text='Export Selected to CSV' isAdminFacing=true inAttribute=true}" class="btn btn-default" onclick="$('#objectAction').val('exportSelectedToCSV');" />
<input type='submit' name='exportToCSV' value="{translate text='Export to CSV' isAdminFacing=true inAttribute=true}" class="btn btn-default" onclick="$('#objectAction').val('exportToCSV');" />
</div>
{/if}
{if !empty($canAddNew)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<img src="{img filename=$thisFacet.imageNameSelected}" alt="{translate text=$thisFacet.value|escape inAttribute=true isPublicFacing=true}">
</div>
<div class="col-xs-6 formatCategoryLabel">
{translate text=$thisFacet.display|escape isPublicFacing=true}
{translate text=$thisFacet.display isPublicFacing=true}
<br>({translate text=Remove isPublicFacing=true})
</div>
</div>
Expand All @@ -29,7 +29,7 @@
<img src="{img filename=$thisFacet.imageName}" alt="{translate text='Filter Format by %1%' 1=$thisFacet.value translateParameters=true isPublicFacing=true inAttribute=true}">
</div>
<div class="col-xs-6 formatCategoryLabel">
{translate text=$thisFacet.display|escape isPublicFacing=true}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}<br>({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format:0:".":","}){/if}
{translate text=$thisFacet.display isPublicFacing=true}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}<br>({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format:0:".":","}){/if}
</div>
</div>
</a>
Expand All @@ -45,9 +45,9 @@
<div id="availabilityControl" class="btn-group" data-toggle="buttons-radio" style="display: flex;align-items: center;justify-content: center;">
{foreach from=$cluster.list item=thisFacet name="narrowLoop"}
{if !empty($thisFacet.isApplied)}
<button aria-pressed="true" type="button" id="{$thisFacet.value|escape|regex_replace:'/[()\s]/':''}" class="btn btn-primary btn-wrap" name="availabilityControls">{translate text=$thisFacet.display|escape isPublicFacing=true}{if $thisFacet.count > 0}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))} ({$thisFacet.count|number_format:0:".":","}){/if}{/if}</button>
<button aria-pressed="true" type="button" id="{$thisFacet.value|escape|regex_replace:'/[()\s]/':''}" class="btn btn-primary btn-wrap" name="availabilityControls">{translate text=$thisFacet.display isPublicFacing=true}{if $thisFacet.count > 0}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))} ({$thisFacet.count|number_format:0:".":","}){/if}{/if}</button>
{else}
<button aria-pressed="false" type="button" id="{$thisFacet.value|escape|regex_replace:'/[()\s]/':''}" class="btn btn-default btn-wrap" name="availabilityControls" data-url="{$thisFacet.url|escape}" onclick="window.location = $(this).data('url')" >{translate text=$thisFacet.display|escape isPublicFacing=true}{if $thisFacet.count > 0}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))} ({$thisFacet.count|number_format:0:".":","}){/if}{/if}</button>
<button aria-pressed="false" type="button" id="{$thisFacet.value|escape|regex_replace:'/[()\s]/':''}" class="btn btn-default btn-wrap" name="availabilityControls" data-url="{$thisFacet.url|escape}" onclick="window.location = $(this).data('url')" >{translate text=$thisFacet.display isPublicFacing=true}{if $thisFacet.count > 0}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))} ({$thisFacet.count|number_format:0:".":","}){/if}{/if}</button>
{/if}
{/foreach}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<option {if empty($cluster.hasSelectedOption)}selected="selected"{/if}>{$cluster.defaultValue}</option>
{/if}
{foreach from=$cluster.list item=thisFacet name="narrowLoop"}
<option data-destination="{$thisFacet.url}" data-label="{$thisFacet.display|escape}" {if !empty($thisFacet.isApplied)}selected{/if}>{$thisFacet.display|escape}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if $thisFacet.count != ''}&nbsp;({$thisFacet.count}){/if}{/if}</option>
<option data-destination="{$thisFacet.url}" data-label="{$thisFacet.display|escape}" {if !empty($thisFacet.isApplied)}selected{/if}>{$thisFacet.display}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if $thisFacet.count != ''}&nbsp;({$thisFacet.count}){/if}{/if}</option>
{/foreach}
</select>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="facetValue">
<label for="{$title}_{$thisFacet.value|escapeCSS}">
<input type="checkbox" {if !empty($thisFacet.isApplied)}checked{/if} name="{$title}_{$thisFacet.value|escapeCSS}" id="{$title}_{$thisFacet.value|escapeCSS}" onclick="document.location = '{if !empty($thisFacet.isApplied)}{$thisFacet.removalUrl|escape}{else}{$thisFacet.url|escape}{/if}';" onkeypress="document.location = '{if !empty($thisFacet.isApplied)}{$thisFacet.removalUrl|escape}{else}{$thisFacet.url|escape}{/if}';">
{$thisFacet.display|escape}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if !empty($thisFacet.count)}&nbsp;({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format}){/if}{/if}
{$thisFacet.display}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if !empty($thisFacet.count)}&nbsp;({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format}){/if}{/if}
</label>
</div>
{/foreach}
Expand All @@ -38,7 +38,7 @@
<label>
<input type="checkbox" {if !empty($thisFacet.isApplied)}checked{/if} name="filter[]" value='{$cluster.field_name}:{if empty($thisFacet.value)}(""){else}"{$thisFacet.value|escape:url}"{/if}'>
&nbsp;
{$thisFacet.display|escape}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if !empty($thisFacet.count)}&nbsp;({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format}){/if}{/if}
{$thisFacet.display}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if !empty($thisFacet.count)}&nbsp;({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format}){/if}{/if}
</label>
</div>
{/strip}
Expand All @@ -60,7 +60,7 @@
<div class="facetValue">
<label for="{$title}_{$thisFacet.value|escapeCSS}">
<input type="checkbox" {if !empty($thisFacet.isApplied)}checked{/if} name="{$title}_{$thisFacet.value|escapeCSS}" id="{$title}_{$thisFacet.value|escapeCSS}" onclick="document.location = '{if !empty($thisFacet.isApplied)}{$thisFacet.removalUrl|escape}{else}{$thisFacet.url|escape}{/if}';" onkeypress="document.location = '{if !empty($thisFacet.isApplied)}{$thisFacet.removalUrl|escape}{else}{$thisFacet.url|escape}{/if}';">
{$thisFacet.display|escape}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if !empty($thisFacet.count)}&nbsp;({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format}){/if}{/if}
{$thisFacet.display}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if !empty($thisFacet.count)}&nbsp;({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format}){/if}{/if}
</label>
</div>
{/foreach}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<div class="narrowGroupHidden" id="narrowGroupHidden_{$title}" style="display:none">
{/if}
{if !empty($thisFacet.isApplied)}
<div class="facetValue"><i class="fas fa-check-circle fa-lg text-success" style="vertical-align: middle"></i> {$thisFacet.display|escape} <a href="{$thisFacet.removalUrl|escape}" class="removeFacetLink">({translate text='remove' isPublicFacing=true})</a></div>
<div class="facetValue"><i class="fas fa-check-circle fa-lg text-success" style="vertical-align: middle"></i> {$thisFacet.display} <a href="{$thisFacet.removalUrl|escape}" class="removeFacetLink">({translate text='remove' isPublicFacing=true})</a></div>
{else}
<div class="facetValue">{if $thisFacet.url !=null}<a href="{$thisFacet.url|escape}">{/if}{$thisFacet.display|escape}{if $thisFacet.url !=null}</a>{/if}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if $thisFacet.count != ''}&nbsp;({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format}){/if}{/if}</div>
<div class="facetValue">{if $thisFacet.url !=null}<a href="{$thisFacet.url|escape}">{/if}{$thisFacet.display}{if $thisFacet.url !=null}</a>{/if}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if $thisFacet.count != ''}&nbsp;({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format}){/if}{/if}</div>
{/if}
{/foreach}
{if $smarty.foreach.narrowLoop.total > $cluster.valuesToShow}
Expand All @@ -30,7 +30,7 @@
<div class="container-12">
<div class="row moreFacetPopup">
{foreach from=$cluster.sortedList item=thisFacet name="narrowLoop"}
<div class="col-tn-12 standardFacet">{if $thisFacet.url !=null}<a href="{$thisFacet.url|escape}">{/if}{$thisFacet.display|escape}{if $thisFacet.url !=null}</a>{/if}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if $thisFacet.count != ''}&nbsp;({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format}){/if}{/if}</div>
<div class="col-tn-12 standardFacet">{if $thisFacet.url !=null}<a href="{$thisFacet.url|escape}">{/if}{$thisFacet.display}{if $thisFacet.url !=null}</a>{/if}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if $thisFacet.count != ''}&nbsp;({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format}){/if}{/if}</div>
{/foreach}
</div>
</div>
Expand All @@ -45,9 +45,9 @@
<div class="narrowGroupHidden" id="narrowGroupHidden_{$title}" style="display:none">
{/if}
{if !empty($thisFacet.isApplied)}
<div class="facetValue"><i class="fas fa-check-circle fa-lg text-success" style="vertical-align: middle"></i> {$thisFacet.display|escape} <a href="{$thisFacet.removalUrl|escape}" class="removeFacetLink">({translate text='remove' isPublicFacing=true})</a></div>
<div class="facetValue"><i class="fas fa-check-circle fa-lg text-success" style="vertical-align: middle"></i> {$thisFacet.display} <a href="{$thisFacet.removalUrl|escape}" class="removeFacetLink">({translate text='remove' isPublicFacing=true})</a></div>
{else}
<div class="facetValue">{if $thisFacet.url !=null}<a href="{$thisFacet.url|escape}">{/if}{$thisFacet.display|escape}{if $thisFacet.url !=null}</a>{/if}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if $thisFacet.count != ''}&nbsp;({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format}){/if}{/if}</div>
<div class="facetValue">{if $thisFacet.url !=null}<a href="{$thisFacet.url|escape}">{/if}{$thisFacet.display}{if $thisFacet.url !=null}</a>{/if}{if $facetCountsToShow == 1 || ($facetCountsToShow == 2 && empty($thisFacet.countIsApproximate))}{if $thisFacet.count != ''}&nbsp;({if !empty($thisFacet.countIsApproximate)}{/if}{$thisFacet.count|number_format}){/if}{/if}</div>
{/if}
{/foreach}
{if $smarty.foreach.narrowLoop.total > $cluster.valuesToShow}
Expand Down
4 changes: 4 additions & 0 deletions code/web/release_notes/24.06.00.MD
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@

</div>

### Other Updates
- Update escaping of facet values so that translatable facet values can be translated in translation mode. (Tickets 130428, 130798) (*MDN*)
- Fix translation mode for Export to CSV buttons in the Admin interface.

//kirstien
### Accessibility Updates
- Libby lending period options are now select elements to make them keyboard accessible and easily indicate selected values. (*KK*)
Expand Down
2 changes: 2 additions & 0 deletions code/web/sys/SearchObject/BaseSearcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ public function getFilterList() {
$display = $translate ? translate([
'text' => $value,
'isPublicFacing' => true,
'escape' => true,
]) : $value;
}

Expand Down Expand Up @@ -1327,6 +1328,7 @@ public function getLimitList() {
'display' => $limit,
'value' => $limit,
'isApplied' => ($limit == $this->limit),
'escape' => true,
];
}
}
Expand Down
29 changes: 23 additions & 6 deletions code/web/sys/SearchObject/GroupedWorkSearcher2.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,9 @@ public function getFacetList($filter = null) {
$currentSettings['display'] = $translate ? translate([
'text' => $facetValue,
'isPublicFacing' => true,
'isMetadata' => true
]) : $facetValue;
'isMetadata' => true,
'escape' => true,
]) : htmlentities($facetValue);
$currentSettings['count'] = $facet[1];
$currentSettings['isApplied'] = false;
$currentSettings['url'] = $this->renderLinkWithFilter($field, $facetValue);
Expand Down Expand Up @@ -879,17 +880,33 @@ public function getFacetList($filter = null) {

if (!$foundInstitution && $doInstitutionProcessing) {
$list[$field]['list']['1' . $currentLibrary->facetLabel] = [
'value' => $currentLibrary->facetLabel,
'display' => $currentLibrary->facetLabel,
'value' => $translate ? translate([
'text' => $currentLibrary->facetLabel,
'isPublicFacing' => true,
'escape' => true
]) : htmlentities($currentLibrary->facetLabel),
'display' => $translate ? translate([
'text' => $currentLibrary->facetLabel,
'isPublicFacing' => true,
'escape' => true
]) : htmlentities($currentLibrary->facetLabel),
'count' => 0,
'isApplied' => false,
'url' => null,
];
}
if (!$foundBranch && $doBranchProcessing && !empty($activeLocationFacet)) {
$list[$field]['list']['1' . $activeLocationFacet] = [
'value' => $activeLocationFacet,
'display' => $activeLocationFacet,
'value' => $translate ? translate([
'text' => $activeLocationFacet,
'isPublicFacing' => true,
'escape' => true
]) : htmlentities($activeLocationFacet),
'display' => $translate ? translate([
'text' => $activeLocationFacet,
'isPublicFacing' => true,
'escape' => true
]) : htmlentities($activeLocationFacet),
'count' => 0,
'isApplied' => false,
'url' => null,
Expand Down
Loading

0 comments on commit c47199b

Please sign in to comment.