mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 02:13:15 +00:00
wip restore hightlights and multivalue seperator
This commit is contained in:
@@ -130,17 +130,18 @@ class TwigServiceProvider implements ServiceProviderInterface
|
|||||||
$twig->addFilter(new \Twig_SimpleFilter('parseColor', function (\Twig_Environment $twig, $string) use ($app) {
|
$twig->addFilter(new \Twig_SimpleFilter('parseColor', function (\Twig_Environment $twig, $string) use ($app) {
|
||||||
$re = '/^(.*)\[#([0-9a-fA-F]{6})]$/m';
|
$re = '/^(.*)\[#([0-9a-fA-F]{6})]$/m';
|
||||||
$stringArr = explode(';', $string);
|
$stringArr = explode(';', $string);
|
||||||
|
|
||||||
foreach ($stringArr as $key => $value) {
|
foreach ($stringArr as $key => $value) {
|
||||||
preg_match_all($re, trim($value), $matches);
|
preg_match_all($re, trim($value), $matches);
|
||||||
if ($matches && $matches[1] != null && $matches[2] != null) {
|
if ($matches && $matches[1] != null && $matches[2] != null) {
|
||||||
$colorCode = '#' . $matches[2][0];
|
$colorCode = '#' . $matches[2][0];
|
||||||
$colorName = $matches[1][0];
|
$colorName = $matches[1][0];
|
||||||
|
|
||||||
$stringArr[$key] = '<span class="color-dot" style="margin-right: 4px; background-color: ' . $colorCode . '"></span>' . $colorName . '<br />';
|
$stringArr[$key] = '<span style="white-space: nowrap;"><span class="color-dot" style="margin-right: 4px; background-color: ' . $colorCode . '"></span>' . $colorName . '</span>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return implode('', $stringArr);
|
return implode('; ', $stringArr);
|
||||||
}, ['needs_environment' => true, 'is_safe' => ['html']]));
|
}, ['needs_environment' => true, 'is_safe' => ['html']]));
|
||||||
|
|
||||||
$twig->addFilter(new \Twig_SimpleFilter('bounce',
|
$twig->addFilter(new \Twig_SimpleFilter('bounce',
|
||||||
|
|||||||
@@ -47,12 +47,36 @@ class PhraseanetExtension extends \Twig_Extension
|
|||||||
new \Twig_SimpleFunction('record_flags', array($this, 'getRecordFlags')),
|
new \Twig_SimpleFunction('record_flags', array($this, 'getRecordFlags')),
|
||||||
new \Twig_SimpleFunction('border_checker_from_fqcn', array($this, 'getCheckerFromFQCN')),
|
new \Twig_SimpleFunction('border_checker_from_fqcn', array($this, 'getCheckerFromFQCN')),
|
||||||
new \Twig_SimpleFunction('caption_field', array($this, 'getCaptionField')),
|
new \Twig_SimpleFunction('caption_field', array($this, 'getCaptionField')),
|
||||||
|
new \Twig_SimpleFunction('caption_field_label', array($this, 'getCaptionFieldLabel')),
|
||||||
new \Twig_SimpleFunction('caption_field_order', array($this, 'getCaptionFieldOrder')),
|
new \Twig_SimpleFunction('caption_field_order', array($this, 'getCaptionFieldOrder')),
|
||||||
|
|
||||||
new \Twig_SimpleFunction('flag_slugify', array(Flag::class, 'normalizeName')),
|
new \Twig_SimpleFunction('flag_slugify', array(Flag::class, 'normalizeName')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get localized field's label
|
||||||
|
* @param RecordInterface $record
|
||||||
|
* @param $fieldName
|
||||||
|
* @return string - the name label
|
||||||
|
*/
|
||||||
|
public function getCaptionFieldLabel(RecordInterface $record, $fieldName)
|
||||||
|
{
|
||||||
|
if ($record) {
|
||||||
|
/** @var \appbox $appbox */
|
||||||
|
$appbox = $this->app['phraseanet.appbox'];
|
||||||
|
$databox = $appbox->get_databox($record->getDataboxId());
|
||||||
|
foreach ($databox->get_meta_structure() as $meta) {
|
||||||
|
/** @var \databox_field $meta */
|
||||||
|
if ($meta->get_name() === $fieldName) {
|
||||||
|
return $meta->get_label($this->app['locale']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
public function getCaptionField(RecordInterface $record, $field, $value)
|
public function getCaptionField(RecordInterface $record, $field, $value)
|
||||||
{
|
{
|
||||||
if ($record instanceof ElasticsearchRecord) {
|
if ($record instanceof ElasticsearchRecord) {
|
||||||
@@ -99,6 +123,31 @@ class PhraseanetExtension extends \Twig_Extension
|
|||||||
return $orders[$databoxId][$orderKey];
|
return $orders[$databoxId][$orderKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \databox $databox
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function retrieveDataboxFieldOrderings(\databox $databox)
|
||||||
|
{
|
||||||
|
$publicOrder = [];
|
||||||
|
$businessOrder = [];
|
||||||
|
|
||||||
|
foreach ($databox->get_meta_structure() as $field) {
|
||||||
|
$fieldName = $field->get_name();
|
||||||
|
|
||||||
|
if (!$field->isBusiness()) {
|
||||||
|
$publicOrder[] = $fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
$businessOrder[] = $fieldName;
|
||||||
|
};
|
||||||
|
|
||||||
|
return [
|
||||||
|
'public' => $publicOrder,
|
||||||
|
'business' => $businessOrder,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function getRecordFlags(RecordInterface $record)
|
public function getRecordFlags(RecordInterface $record)
|
||||||
{
|
{
|
||||||
$recordStatuses = [];
|
$recordStatuses = [];
|
||||||
@@ -132,24 +181,6 @@ class PhraseanetExtension extends \Twig_Extension
|
|||||||
return $recordStatuses;
|
return $recordStatuses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isGrantedOnDatabox($databoxId, $rights)
|
|
||||||
{
|
|
||||||
if (false === ($this->app->getAuthenticatedUser() instanceof User)) {
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$rights = (array) $rights;
|
|
||||||
foreach ($rights as $right) {
|
|
||||||
if (false === $this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_sbas($databoxId, $right)) {
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns true if user is authenticated and has all the passed rights on the base
|
* returns true if user is authenticated and has all the passed rights on the base
|
||||||
* todo : wtf $rights is an array since it's never called with more than 1 right in it ?
|
* todo : wtf $rights is an array since it's never called with more than 1 right in it ?
|
||||||
@@ -177,6 +208,24 @@ class PhraseanetExtension extends \Twig_Extension
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isGrantedOnDatabox($databoxId, $rights)
|
||||||
|
{
|
||||||
|
if (false === ($this->app->getAuthenticatedUser() instanceof User)) {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rights = (array)$rights;
|
||||||
|
foreach ($rights as $right) {
|
||||||
|
if (false === $this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_sbas($databoxId, $right)) {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function getCollectionLogo($baseId)
|
public function getCollectionLogo($baseId)
|
||||||
{
|
{
|
||||||
if (false === $this->app['filesystem']->exists(sprintf('%s/config/minilogos/%s', $this->app['root.path'], $baseId))) {
|
if (false === $this->app['filesystem']->exists(sprintf('%s/config/minilogos/%s', $this->app['root.path'], $baseId))) {
|
||||||
@@ -242,11 +291,6 @@ class PhraseanetExtension extends \Twig_Extension
|
|||||||
return $this->getSubdefUrl($record, 'thumbnail');
|
return $this->getSubdefUrl($record, 'thumbnail');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getThumbnailGifUrl(RecordInterface $record)
|
|
||||||
{
|
|
||||||
return $this->getSubdefUrl($record, 'thumbnailgif');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSubdefUrl(RecordInterface $record, $subdefName)
|
public function getSubdefUrl(RecordInterface $record, $subdefName)
|
||||||
{
|
{
|
||||||
/** @var StaticMode $staticMode */
|
/** @var StaticMode $staticMode */
|
||||||
@@ -279,6 +323,11 @@ class PhraseanetExtension extends \Twig_Extension
|
|||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getThumbnailGifUrl(RecordInterface $record)
|
||||||
|
{
|
||||||
|
return $this->getSubdefUrl($record, 'thumbnailgif');
|
||||||
|
}
|
||||||
|
|
||||||
public function getSubdefSize(RecordInterface $record, $subdefName)
|
public function getSubdefSize(RecordInterface $record, $subdefName)
|
||||||
{
|
{
|
||||||
$ret = null;
|
$ret = null;
|
||||||
@@ -325,29 +374,4 @@ class PhraseanetExtension extends \Twig_Extension
|
|||||||
{
|
{
|
||||||
return 'phraseanet';
|
return 'phraseanet';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \databox $databox
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function retrieveDataboxFieldOrderings(\databox $databox)
|
|
||||||
{
|
|
||||||
$publicOrder = [];
|
|
||||||
$businessOrder = [];
|
|
||||||
|
|
||||||
foreach ($databox->get_meta_structure() as $field) {
|
|
||||||
$fieldName = $field->get_name();
|
|
||||||
|
|
||||||
if (!$field->isBusiness()) {
|
|
||||||
$publicOrder[] = $fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
$businessOrder[] = $fieldName;
|
|
||||||
};
|
|
||||||
|
|
||||||
return [
|
|
||||||
'public' => $publicOrder,
|
|
||||||
'business' => $businessOrder,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,9 +93,9 @@
|
|||||||
{% set terms = [] %}
|
{% set terms = [] %}
|
||||||
{% for data in field.values %}
|
{% for data in field.values %}
|
||||||
{% if data.from_thesaurus and bounceable %}
|
{% if data.from_thesaurus and bounceable %}
|
||||||
{% set value = data.value|e|bounce(field.name, data.qjs, field.sbas_id) %}
|
{% set value = data.value|e|bounce(field.name, data.qjs, field.sbas_id)|parseColor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set value = data.value|e %}
|
{% set value = data.value|e|parseColor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% set terms = [value]|merge(terms) %}
|
{% set terms = [value]|merge(terms) %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -126,9 +126,9 @@
|
|||||||
|
|
||||||
{% macro caption(record, can_see_business, display_exif, limitedWidth = false) %}
|
{% macro caption(record, can_see_business, display_exif, limitedWidth = false) %}
|
||||||
<dl class="{% if limitedWidth %}{% else %}dl-horizontal{% endif %}">
|
<dl class="{% if limitedWidth %}{% else %}dl-horizontal{% endif %}">
|
||||||
{% for field in record.get_caption().get_highlight_fields(null, can_see_business) %}
|
{% for name, value in record.getCaption(caption_field_order(record, can_see_business)) %}
|
||||||
<dt>{{ field.label_name }}</dt>
|
<dt>{{ caption_field_label(record, name) }}</dt>
|
||||||
<dd>{{ _self.caption_value(field, bounceable|default(true))|highlight|linkify|parseColor }}</dd>
|
<dd>{{ caption_field(record, name, value)|e|highlight|linkify }}</dd>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</dl>
|
</dl>
|
||||||
{% if display_exif|default(true) and app.getAuthenticator().user is not none and user_setting('technical_display') == 'group' %}
|
{% if display_exif|default(true) and app.getAuthenticator().user is not none and user_setting('technical_display') == 'group' %}
|
||||||
|
|||||||
@@ -24,7 +24,8 @@
|
|||||||
{% set can_see_business = granted_on_collection(record.baseId, [constant('\\ACL::CANMODIFRECORD')]) %}
|
{% set can_see_business = granted_on_collection(record.baseId, [constant('\\ACL::CANMODIFRECORD')]) %}
|
||||||
|
|
||||||
<div class="thumb captionTips"
|
<div class="thumb captionTips"
|
||||||
{% if settings.rollover_thumbnail == 'caption' %}tooltipsrc="{{ path('prod_tooltip_caption', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId, 'context' : 'answer', 'number' : record.position|default(0) }) }}"{% endif %}
|
{% if settings.rollover_thumbnail == 'caption' %}title="{{ macro.caption(record, can_see_business, false) | e }}"
|
||||||
|
"{% endif %}
|
||||||
{% if settings.rollover_thumbnail == 'preview' %}tooltipsrc="{{ path('prod_tooltip_preview', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) }}"{% endif %}
|
{% if settings.rollover_thumbnail == 'preview' %}tooltipsrc="{{ path('prod_tooltip_preview', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) }}"{% endif %}
|
||||||
style="height:{{ settings.images_size }}px; z-index:90;">
|
style="height:{{ settings.images_size }}px; z-index:90;">
|
||||||
<div class="doc_infos">
|
<div class="doc_infos">
|
||||||
|
|||||||
Reference in New Issue
Block a user