diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php
index b72520a359..33e0e610e2 100644
--- a/lib/Alchemy/Phrasea/Application.php
+++ b/lib/Alchemy/Phrasea/Application.php
@@ -612,57 +612,31 @@ class Application extends SilexApplication
$twig->addFilter('base_from_coll', new \Twig_Filter_Function('phrasea::baseFromColl'));
$twig->addFilter('AppName', new \Twig_Filter_Function('Alchemy\Phrasea\Controller\Admin\ConnectedUsers::appName'));
$twig->addFilter(new \Twig_SimpleFilter('escapeSimpleQuote', function ($value) {
- $ret = str_replace("'", "\\'", $value);
-
- return $ret;
+ return str_replace("'", "\\'", $value);
}));
- $twig->addFilter(new \Twig_SimpleFilter('highlight', function (\Twig_Environment $twig, $argument) {
- if (is_string($argument)) {
- return str_replace(array('[[em]]', '[[/em]]'), array('', ''), twig_escape_filter($twig, $argument));
- }
- $values = array();
- if (is_array($argument) && isset($argument['values'])) {
- foreach ($argument['values'] as $value) {
- $values[] = str_replace(array('[[em]]', '[[/em]]'), array('', ''), twig_escape_filter($twig, $value['value']));
- }
+ $twig->addFilter(new \Twig_SimpleFilter('highlight', function (\Twig_Environment $twig, $string) {
+ return str_replace(array('[[em]]', '[[/em]]'), array('', ''), $string);
+ }, array('needs_environment' => true,'is_safe' => array('html'))));
- return implode(' ' . $argument['separator'] . ' ', $values);
- }
-
- throw new LogicException('highlight filter must be applied on strings or highlighted fields.');
+ $twig->addFilter(new \Twig_SimpleFilter('linkify', function (\Twig_Environment $twig, $string) {
+ return preg_replace(
+ "(([^']{1})((https?|file):((/{2,4})|(\\{2,4}))[\w:#%/;$()~_?/\-=\\\.&]*)([^']{1}))"
+ , '$1 $2 $7'
+ , $string
+ );
}, array('needs_environment' => true, 'is_safe' => array('html'))));
- $twig->addFilter(new \Twig_SimpleFilter('bounce', function (\Twig_Environment $twig, $argument) {
- if (false === is_array($argument) || !isset($argument['values'])) {
- throw new LogicException('bounce filter must be applied on values that come from highlighted fields.');
- }
- $display = array();
- foreach ($argument['values'] as $value) {
- // value of a caption string
- $toDisplay = $value['value'];
+ $twig->addFilter(new \Twig_SimpleFilter('bounce', function (\Twig_Environment $twig, $fieldValue, $fieldName, $searchRequest, $sbasId) {
// bounce value if it is present in thesaurus as well
- if ($value['from_thesaurus']) {
- $toDisplay = ""
- . twig_escape_filter($twig, $toDisplay)
- . "";
- }
+ return ""
+ . $fieldValue
+ . "";
- // checks for urls in value and wrap them into tags
- $toDisplay = preg_replace(
- "(([^']{1})((https?|file):((/{2,4})|(\\{2,4}))[\w:#%/;$()~_?/\-=\\\.&]*)([^']{1}))"
- , '$1 $2 $7'
- , $toDisplay
- );
-
- $display[] = $toDisplay;
- }
-
- return implode(' ' . $argument['separator'] . ' ', $display);
}, array('needs_environment' => true, 'is_safe' => array('html'))));
$twig->addFilter(new \Twig_SimpleFilter('escapeDoubleQuote', function ($value) {
diff --git a/templates/web/common/caption.html.twig b/templates/web/common/caption.html.twig
index 929230543a..c429a201b6 100644
--- a/templates/web/common/caption.html.twig
+++ b/templates/web/common/caption.html.twig
@@ -1,26 +1,17 @@
-{% import 'common/caption_templates/answer.html.twig' as cap_ans %}
-{% import 'common/caption_templates/basket_element.html.twig' as cap_bas %}
-{% import 'common/caption_templates/internal_publi.html.twig' as cap_pub %}
-{% import 'common/caption_templates/lazaret.html.twig' as cap_laz %}
-{% import 'common/caption_templates/overview.html.twig' as cap_ovr %}
-{% import 'common/caption_templates/preview.html.twig' as cap_prev %}
+{% import 'common/macros.html.twig' as macro %}
-{% if app['authentication'].getUser() %}
- {% set business = app['authentication'].getUser().ACL().has_right_on_base(record.get_base_id(), 'canmodifrecord') %}
-{% else %}
- {% set business = false %}
-{% endif %}
+{% set business = app['authentication'].getUser().ACL().has_right_on_base(record.get_base_id(), 'canmodifrecord')|default(false) %}
{% if view == 'answer' %}
- {{cap_ans.format_caption(record, highlight|default(''), searchEngine|default(null), business)}}
+ {{ macro.format_caption(record, highlight|default(''), searchEngine|default(null), business, false, true) }}
{% elseif view == 'lazaret' %}
- {{cap_laz.format_caption(record, highlight|default(''), searchEngine|default(null), business)}}
+ {{ macro.format_caption(record, highlight|default(''), searchEngine|default(null), business, true, true) }}
{% elseif view == 'preview' %}
- {{cap_prev.format_caption(record, highlight|default(''), searchEngine|default(null), business)}}
+ {{ macro.format_caption(record, highlight|default(''), searchEngine|default(null), business, true, false) }}
{% elseif view == 'basket' %}
- {{cap_bas.format_caption(record, highlight|default(''), searchEngine|default(null), business)}}
+ {{ macro.format_caption(record, highlight|default(''), searchEngine|default(null), business, true, false) }}
{% elseif view == 'overview' %}
- {{cap_ovr.format_caption(record, highlight|default(''), searchEngine|default(null), business)}}
+ {{ macro.format_caption(record, highlight|default(''), searchEngine|default(null), business, false, false) }}
{% elseif view == 'publi' %}
- {{cap_pub.format_caption(record, '', null, business)}}
-{% endif %}
\ No newline at end of file
+ {{ macro.format_caption(record, '', null, business, true, true) }}
+{% endif %}
diff --git a/templates/web/common/caption_templates/answer.html.twig b/templates/web/common/caption_templates/answer.html.twig
deleted file mode 100644
index c653139cb6..0000000000
--- a/templates/web/common/caption_templates/answer.html.twig
+++ /dev/null
@@ -1,9 +0,0 @@
-{% macro format_caption(record, highlight, searchEngine, includeBusiness) %}
- {% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness) %}
-
{{ value.label }} : {{ value | highlight }}
- {% endfor %}
- {% if app['authentication'].getUser().getPrefs('technical_display') == 'group' %}
-
- {% include 'common/technical_datas.html.twig' %}
- {% endif %}
-{% endmacro %}
diff --git a/templates/web/common/caption_templates/basket_element.html.twig b/templates/web/common/caption_templates/basket_element.html.twig
deleted file mode 100644
index ab04398eca..0000000000
--- a/templates/web/common/caption_templates/basket_element.html.twig
+++ /dev/null
@@ -1,5 +0,0 @@
-{% macro format_caption(record, highlight, searchEngine, includeBusiness) %}
- {% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness) %}
- {{ value.label }} : {{ value | bounce | highlight }}
- {% endfor %}
-{% endmacro %}
diff --git a/templates/web/common/caption_templates/internal_publi.html.twig b/templates/web/common/caption_templates/internal_publi.html.twig
deleted file mode 100644
index 1406f432cc..0000000000
--- a/templates/web/common/caption_templates/internal_publi.html.twig
+++ /dev/null
@@ -1,9 +0,0 @@
-{% macro format_caption(record, highlight, searchEngine, includeBusiness) %}
- {% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness) %}
- {{ value.label }} : {{ value | bounce | highlight }}
- {% endfor %}
- {% if app['authentication'].getUser().getPrefs('technical_display') == 'group' %}
-
- {% include 'common/technical_datas.html.twig' %}
- {% endif %}
-{% endmacro %}
diff --git a/templates/web/common/caption_templates/lazaret.html.twig b/templates/web/common/caption_templates/lazaret.html.twig
deleted file mode 100644
index 1406f432cc..0000000000
--- a/templates/web/common/caption_templates/lazaret.html.twig
+++ /dev/null
@@ -1,9 +0,0 @@
-{% macro format_caption(record, highlight, searchEngine, includeBusiness) %}
- {% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness) %}
- {{ value.label }} : {{ value | bounce | highlight }}
- {% endfor %}
- {% if app['authentication'].getUser().getPrefs('technical_display') == 'group' %}
-
- {% include 'common/technical_datas.html.twig' %}
- {% endif %}
-{% endmacro %}
diff --git a/templates/web/common/caption_templates/overview.html.twig b/templates/web/common/caption_templates/overview.html.twig
deleted file mode 100644
index 62182acf7d..0000000000
--- a/templates/web/common/caption_templates/overview.html.twig
+++ /dev/null
@@ -1,5 +0,0 @@
-{% macro format_caption(record, highlight, searchEngine, includeBusiness) %}
- {% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness) %}
- {{ value.label }} : {{ value | highlight }}
- {% endfor %}
-{% endmacro %}
diff --git a/templates/web/common/caption_templates/preview.html.twig b/templates/web/common/caption_templates/preview.html.twig
deleted file mode 100644
index ab04398eca..0000000000
--- a/templates/web/common/caption_templates/preview.html.twig
+++ /dev/null
@@ -1,5 +0,0 @@
-{% macro format_caption(record, highlight, searchEngine, includeBusiness) %}
- {% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness) %}
- {{ value.label }} : {{ value | bounce | highlight }}
- {% endfor %}
-{% endmacro %}
diff --git a/templates/web/common/macros.html.twig b/templates/web/common/macros.html.twig
index aa1a244d83..e4f5faaef3 100644
--- a/templates/web/common/macros.html.twig
+++ b/templates/web/common/macros.html.twig
@@ -29,7 +29,7 @@
|
@@ -39,7 +39,7 @@
@@ -79,3 +79,39 @@
{% endfor %}
{% endfor %}
{% endmacro %}
+
+{% macro caption_value(field, bounceable) %}
+ {% autoescape false %}
+ {% set terms = [] %}
+ {% for data in field.values %}
+ {% if data.from_thesaurus and bounceable %}
+ {% set value = data.value|e|bounce(field.name, data.qjs, field.sbas_id) %}
+ {% else %}
+ {% set value = data.value|e %}
+ {% endif %}
+ {% set terms = [value]|merge(terms) %}
+ {% endfor %}
+ {{ terms|join(' ' ~ field.separator ~ ' ') }}
+ {% endautoescape %}
+{% endmacro %}
+
+{% macro caption_field(field, bounceable, extra_classes) %}
+
+{% endmacro %}
+
+{% macro format_caption(record, highlight, search_engine, include_business, bounceable, technical_data) %}
+ {% for field in record.get_caption().get_highlight_fields(highlight, null, search_engine, include_business) %}
+ {% set extra_classes = ['pair'] %}
+ {% if loop.index is odd %}
+ {% set extra_classes = ['impair'] %}
+ {% endif %}
+ {{ _self.caption_field(field, bounceable|default(true), extra_classes) }}
+ {% endfor %}
+ {% if technical_data|default(true) and app['authentication'].getUser() is not none and app['authentication'].getUser().getPrefs('technical_display') == 'group' %}
+
+ {% include 'common/technical_datas.html.twig' %}
+ {% endif %}
+{% endmacro %}
diff --git a/templates/web/lightbox/IE6/feed.html.twig b/templates/web/lightbox/IE6/feed.html.twig
index 654cdd89f3..94e3064304 100644
--- a/templates/web/lightbox/IE6/feed.html.twig
+++ b/templates/web/lightbox/IE6/feed.html.twig
@@ -1,7 +1,7 @@
{% extends "lightbox/index_layout.html.twig" %}
{% import 'common/thumbnail.html.twig' as thumbnail %}
-{% import 'common/caption_templates/preview.html.twig' as caption %}
+{% import 'common/macros.html.twig' as macro %}
{% block javascript %}
@@ -83,7 +83,7 @@
{% set business = app['authentication'].getUser().ACL().has_right_on_base(first_item.get_record().get_base_id(), 'canmodifrecord') %}
{% if first_item %}
- {{caption.format_caption(first_item.get_record(), '', null, business)}}
+ {{ macro.format_caption(first_item.get_record(), '', null, business, false, false) }}
{% endif %}
diff --git a/templates/web/lightbox/IE6/validate.html.twig b/templates/web/lightbox/IE6/validate.html.twig
index 1e1f77b7e4..17fee1cc69 100644
--- a/templates/web/lightbox/IE6/validate.html.twig
+++ b/templates/web/lightbox/IE6/validate.html.twig
@@ -1,7 +1,7 @@
{% extends "lightbox/index_layout.html.twig" %}
{% import 'common/thumbnail.html.twig' as thumbnail %}
-{% import 'common/caption_templates/preview.html.twig' as caption %}
+{% import 'common/macros.html.twig' as macro %}
{% block javascript %}
@@ -95,7 +95,7 @@
{% if basket_element %}
{% set business = app['authentication'].getUser().ACL().has_right_on_base(basket_element.getRecord(app).get_base_id(), 'canmodifrecord') %}
- {{caption.format_caption(basket_element.getRecord(app), '', null, business)}}
+ {{ macro.format_caption(basket_element.getRecord(app), '', null, business, false, false) }}
{% endif %}
diff --git a/templates/web/lightbox/feed.html.twig b/templates/web/lightbox/feed.html.twig
index b5ea76a30d..5a5c72c9d4 100644
--- a/templates/web/lightbox/feed.html.twig
+++ b/templates/web/lightbox/feed.html.twig
@@ -1,7 +1,7 @@
{% extends "lightbox/index_layout.html.twig" %}
{% import 'common/thumbnail.html.twig' as thumbnail %}
-{% import 'common/caption_templates/preview.html.twig' as caption %}
+{% import 'common/macros.html.twig' as macro %}
{% block javascript %}
@@ -83,7 +83,7 @@
{% set business = app['authentication'].getUser().ACL().has_right_on_base(first_item.get_record().get_base_id(), 'canmodifrecord') %}
{% if first_item %}
- {{caption.format_caption(first_item.get_record(), '', null, business)}}
+ {{ macro.format_caption(first_item.get_record(), '', null, business, false, false) }}
{% endif %}
diff --git a/templates/web/lightbox/validate.html.twig b/templates/web/lightbox/validate.html.twig
index a9e60c5ae2..c59640b9e3 100644
--- a/templates/web/lightbox/validate.html.twig
+++ b/templates/web/lightbox/validate.html.twig
@@ -1,7 +1,7 @@
{% extends "lightbox/index_layout.html.twig" %}
{% import 'common/thumbnail.html.twig' as thumbnail %}
-{% import 'common/caption_templates/preview.html.twig' as caption %}
+{% import 'common/macros.html.twig' as macro %}
{% block javascript %}
@@ -98,7 +98,7 @@
{% if basket_element %}
{% set business = app['authentication'].getUser().ACL().has_right_on_base(basket_element.getRecord(app).get_base_id(), 'canmodifrecord') %}
- {{caption.format_caption(basket_element.getRecord(app), '', null, business)}}
+ {{ macro.format_caption(basket_element.getRecord(app), '', null, business, false, false) }}
{% endif %}
diff --git a/templates/web/prod/preview/caption.html.twig b/templates/web/prod/preview/caption.html.twig
index 5ee2af7d9d..631a76c638 100644
--- a/templates/web/prod/preview/caption.html.twig
+++ b/templates/web/prod/preview/caption.html.twig
@@ -1,4 +1,4 @@
-{% import 'common/caption_templates/preview.html.twig' as caption %}
+{% import 'common/macros.html.twig' as macro %}
{% if app['authentication'].getUser().ACL().has_right_on_base(record.get_base_id, 'canmodifrecord') %}
@@ -13,9 +13,7 @@
{% set business = app['authentication'].getUser().ACL().has_right_on_base(record.get_base_id(), 'canmodifrecord') %}
{% if record.is_from_reg() %}
- {{caption.format_caption(record, '', null, business)}}
+ {{ macro.format_caption(record, '', null, business, false, true) }}
{% else %}
- {{caption.format_caption(record, highlight, searchEngine, business)}}
+ {{ macro.format_caption(record, highlight, searchEngine, business, false, true) }}
{% endif %}
-
- {% include 'common/technical_datas.html.twig' %}
\ No newline at end of file
diff --git a/templates/web/prod/results/answerlist.html.twig b/templates/web/prod/results/answerlist.html.twig
index da356ab3f0..a7d1f67d55 100644
--- a/templates/web/prod/results/answerlist.html.twig
+++ b/templates/web/prod/results/answerlist.html.twig
@@ -1,22 +1,20 @@
-
{% extends "prod/results/answerabstract.html.twig" %}
{% block content %}
-{% import 'common/caption_templates/answer.html.twig' as caption %}
+{% import 'common/macros.html.twig' as macro %}
{% for record in results.getResults() %}
|
- {{record_format.block(record, highlight, searchEngine, 'IMGT', false)}}
+ {{ record_format.block(record, highlight, searchEngine, 'IMGT', false) }}
|
{% set business = app['authentication'].getUser().ACL().has_right_on_base(record.get_base_id(), 'canmodifrecord') %}
- {{caption.format_caption(record, highlight, searchEngine, business)}}
- {% if app['authentication'].getUser().getPrefs('technical_display') == 'group' %} {{record.get_technical_infos|raw}}{% endif %}
+ {{ macro.format_caption(record, highlight, searchEngine, business, true, true) }}
|