diff --git a/VERSIONS_HOTLINE/142688 b/VERSIONS_HOTLINE/142688 new file mode 100644 index 0000000000000000000000000000000000000000..3050a5c287cd854d93b13c9c0ae1bdc2d6951744 --- /dev/null +++ b/VERSIONS_HOTLINE/142688 @@ -0,0 +1 @@ + - correctif #142688 : Champs personnalisés : Les kiosques présents dans les champs de type HTML sont maintenant affichés dans l'interface publique. \ No newline at end of file diff --git a/library/Class/Article.php b/library/Class/Article.php index f0c1b547e889059cf73e2444ddbee27130a2569c..8b449fb3820afdc62d2653b2b60e8550acc69f41 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -29,7 +29,8 @@ class Class_Article extends Storm_Model_Abstract { Trait_TimeSource, Trait_CustomFields, Trait_StaticFileWriter, - Trait_Versionable; + Trait_Versionable, + Trait_CKEditorWidget; const END_TAG='{FIN}'; @@ -628,16 +629,6 @@ class Class_Article extends Storm_Model_Abstract { } - protected function _getCarouselDataFrom(string $preg_function, string $content) : array { - $pattern = '|(?P<allimg><img[^>]+data-code="(?P<code>\w+)"[^>]+data-form="(?P<form>[^"]+)[^>]*>)|'; - $matches = []; - - return $preg_function($pattern, $content, $matches) > 0 - ? $matches - : []; - } - - public function getFirstImageAbsoluteURL() { return $this->withFirstImageDo(function($url) {return Class_Url::absolute($url);}); } diff --git a/library/Class/CustomField.php b/library/Class/CustomField.php index 968a2a97851df19088b03638ff9d1e48867aa664..cd06e2a8afc8aa9aa63e88267b37baa347512def 100644 --- a/library/Class/CustomField.php +++ b/library/Class/CustomField.php @@ -206,4 +206,11 @@ class Class_CustomField extends Storm_Model_Abstract { public function getThesaurusIdOrigine() { return $this->getMeta()->getId(); } + + + public function isCKEditor() : bool { + return $this->hasMeta() + ? $this->getMeta()->isCKEditor() + : false; + } } diff --git a/library/Class/CustomField/Meta.php b/library/Class/CustomField/Meta.php index 3a643e7ec9c2486494fb92e34821010cc73186ed..e6c601efa4f76e03fb149ccd26dd283674bd84d9 100644 --- a/library/Class/CustomField/Meta.php +++ b/library/Class/CustomField/Meta.php @@ -108,6 +108,11 @@ class Class_CustomField_Meta extends Storm_Model_Abstract { return explode(';', $value); return $value; } + + + public function isCKEditor() : bool { + return static::CKEDITOR === $this->getFieldType(); + } } diff --git a/library/Class/CustomField/Value.php b/library/Class/CustomField/Value.php index 43d307dc4da1565542e742a2261435c76a4b450e..c873eddabb00ab7637c1dd766f392fe1dd25c1bf 100644 --- a/library/Class/CustomField/Value.php +++ b/library/Class/CustomField/Value.php @@ -153,4 +153,11 @@ class Class_CustomField_Value extends Storm_Model_Abstract { return false; } + + + public function isCKEditor() : bool { + return $this->hasField() + ? $this->getField()->isCKEditor() + : false; + } } diff --git a/library/Trait/CKEditorWidget.php b/library/Trait/CKEditorWidget.php new file mode 100644 index 0000000000000000000000000000000000000000..55834b9f4a9f95eae7bf86e1f473bad283e00b2e --- /dev/null +++ b/library/Trait/CKEditorWidget.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +trait Trait_CKEditorWidget { + + public static $widget_pattern = '|(?P<allimg><img[^>]+data-code="(?P<code>\w+)"[^>]+data-form="(?P<form>[^"]+)[^>]*>)|'; + + + protected function _getCarouselDataFrom(string $preg_function, + string $content, + ?Closure $callback = null) : array { + + if ( $callback && 'preg_replace_callback' == $preg_function) + return [$preg_function(static::$widget_pattern, + $callback, + $content)]; + + $matches = []; + return $preg_function(static::$widget_pattern, $content, $matches) > 0 + ? $matches + : []; + } +} diff --git a/library/ZendAfi/View/Helper/Article/RenderAbstract.php b/library/ZendAfi/View/Helper/Article/RenderAbstract.php index afae61839bd93cfee96bb9e04643b949ff7f0d05..c2b6f485b3812a4a1a97004b58bc95c8c4aeb346 100644 --- a/library/ZendAfi/View/Helper/Article/RenderAbstract.php +++ b/library/ZendAfi/View/Helper/Article/RenderAbstract.php @@ -97,7 +97,7 @@ abstract class ZendAfi_View_Helper_Article_RenderAbstract $content = ($article->hasSummary()) ? $this->renderSummary($article) : $article->getFullContentWithCookiesConsent(); - return $this->view->article_ReplaceWidgets($content); + return $this->view->renderCKEditorWidgets($content); } diff --git a/library/ZendAfi/View/Helper/Article/RenderFullContent.php b/library/ZendAfi/View/Helper/Article/RenderFullContent.php index 48d281c35523048b421feed4fe1ecb25cbbd91c1..d8fa27b2aac18f7e826cce7f6a492451652015a0 100644 --- a/library/ZendAfi/View/Helper/Article/RenderFullContent.php +++ b/library/ZendAfi/View/Helper/Article/RenderFullContent.php @@ -30,9 +30,7 @@ class ZendAfi_View_Helper_Article_RenderFullContent extends ZendAfi_View_Helper_ public function renderContent($article) { - $content = $article->getFullContentWithCookiesConsent(); - - return $this->view->article_ReplaceWidgets($content); + return $this->view->renderCKEditorWidgets($article->getFullContentWithCookiesConsent()); } diff --git a/library/ZendAfi/View/Helper/Notice/EnteteElement.php b/library/ZendAfi/View/Helper/Notice/EnteteElement.php index 1b6b4a02e99158709358b76ddb1aa217ecf8d883..ecbf80e91d2f6e38d72dbb32634ac90a6d50f656 100644 --- a/library/ZendAfi/View/Helper/Notice/EnteteElement.php +++ b/library/ZendAfi/View/Helper/Notice/EnteteElement.php @@ -40,7 +40,7 @@ class ZendAfi_View_Helper_Notice_EnteteElement extends ZendAfi_View_Helper_BaseH public function getValeursHtml($valeur) { if (!is_array($valeur)) - return $this->view->article_ReplaceWidgets($valeur); + return $this->view->renderCKEditorWidgets($valeur); $html = ''; foreach($valeur as $item) diff --git a/library/ZendAfi/View/Helper/Article/RenderWidget.php b/library/ZendAfi/View/Helper/RenderCKEditorWidget.php similarity index 67% rename from library/ZendAfi/View/Helper/Article/RenderWidget.php rename to library/ZendAfi/View/Helper/RenderCKEditorWidget.php index 21e9006a9f534da66ba45ed614aa87e3b310ecb1..122bd6ba6ae346f4408282bf87b573890851264a 100644 --- a/library/ZendAfi/View/Helper/Article/RenderWidget.php +++ b/library/ZendAfi/View/Helper/RenderCKEditorWidget.php @@ -1,6 +1,6 @@ <?php /** - * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved. * * BOKEH is free software; you can redistribute it and/or modify * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by @@ -20,23 +20,25 @@ */ -class ZendAfi_View_Helper_Article_RenderWidget extends ZendAfi_View_Helper_BaseHelper { - public function article_RenderWidget($code, $form) { +class ZendAfi_View_Helper_RenderCKEditorWidget extends ZendAfi_View_Helper_BaseHelper { + + + public function renderCKEditorWidget(string $code, string $settings) :string { $prefs = []; - parse_str(html_entity_decode($form), $prefs); + parse_str(html_entity_decode($settings), $prefs); - return $this->_getHTMLWith(['type_module'=> $code, - 'preferences' => $prefs]); + return $this->_getHTMLWith(['type_module'=> $code, 'preferences' => $prefs]); } - protected function _getHTMLWith($params) { - $helper = ZendAfi_View_Helper_Accueil_Base::getModuleHelperFromParams(null, - $params, - $this->view); + protected function _getHTMLWith(array $settings) : string { + $helper = + ZendAfi_View_Helper_Accueil_Base::getModuleHelperFromParams(null, + $settings, + $this->view); return $helper ->setFonctionAdminHelper(null) ->getBoite(); } -} \ No newline at end of file +} diff --git a/library/ZendAfi/View/Helper/Article/ReplaceWidgets.php b/library/ZendAfi/View/Helper/RenderCKEditorWidgets.php similarity index 55% rename from library/ZendAfi/View/Helper/Article/ReplaceWidgets.php rename to library/ZendAfi/View/Helper/RenderCKEditorWidgets.php index 437c0765d9e539b68502a329f58a374d6b3a2613..51e01b54f286e8d9d94a160852d8f1dd1d53acf9 100644 --- a/library/ZendAfi/View/Helper/Article/ReplaceWidgets.php +++ b/library/ZendAfi/View/Helper/RenderCKEditorWidgets.php @@ -1,6 +1,6 @@ <?php /** - * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved. * * BOKEH is free software; you can redistribute it and/or modify * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by @@ -20,13 +20,17 @@ */ -class ZendAfi_View_Helper_Article_ReplaceWidgets extends ZendAfi_View_Helper_BaseHelper { - public function article_ReplaceWidgets($content) { - return preg_replace_callback( - '|(?P<allimg><img[^>]+data-code="(?P<code>\w+)"[^>]+data-form="(?P<form>[^"]+)[^>]*>)|', - function ($matches) { - return $this->view->article_RenderWidget($matches['code'], $matches['form']); - }, - $content); +class ZendAfi_View_Helper_RenderCKEditorWidgets extends ZendAfi_View_Helper_BaseHelper { + + use Trait_CKEditorWidget; + + + public function renderCKEditorWidgets(string $content) : string { + return $this->_getCarouselDataFrom('preg_replace_callback', + $content, + (fn($matches) => + ($this->view + ->renderCKEditorWidget($matches['code'], + $matches['form']))))[0]; } -} \ No newline at end of file +} diff --git a/library/requires.php b/library/requires.php index 9018425bfc70d85bf88109e5ed4e14dd85db83c2..c0d149c79755ae952ed199c658f8a82f54b889e3 100644 --- a/library/requires.php +++ b/library/requires.php @@ -149,7 +149,6 @@ require_once(ROOT_PATH.'library/ZendAfi/View/Helper/Admin/FrontNav.php'); require_once(ROOT_PATH.'library/ZendAfi/View/Helper/AdminTools.php'); require_once(ROOT_PATH.'library/ZendAfi/View/Helper/Article/RenderContainer/Empty.php'); require_once(ROOT_PATH.'library/ZendAfi/View/Helper/Article/RenderSummary.php'); -require_once(ROOT_PATH.'library/ZendAfi/View/Helper/Article/ReplaceWidgets.php'); require_once(ROOT_PATH.'library/ZendAfi/View/Helper/Avis.php'); require_once(ROOT_PATH.'library/ZendAfi/View/Helper/BarreNav.php'); require_once(ROOT_PATH.'library/ZendAfi/View/Helper/BoitesDivision.php'); @@ -169,6 +168,8 @@ require_once(ROOT_PATH.'library/ZendAfi/View/Helper/Layout/Opac.php'); require_once(ROOT_PATH.'library/ZendAfi/View/Helper/MenuHorizontal.php'); require_once(ROOT_PATH.'library/ZendAfi/View/Helper/NoteImg.php'); require_once(ROOT_PATH.'library/ZendAfi/View/Helper/Permalink.php'); +require_once(ROOT_PATH.'library/ZendAfi/View/Helper/RenderCKEditorWidget.php'); +require_once(ROOT_PATH.'library/ZendAfi/View/Helper/RenderCKEditorWidgets.php'); require_once(ROOT_PATH.'library/ZendAfi/View/Helper/RenderForm.php'); require_once(ROOT_PATH.'library/ZendAfi/View/Helper/RenderLibrary.php'); require_once(ROOT_PATH.'library/ZendAfi/View/Helper/RenderLibraryOpening.php'); diff --git a/library/templates/Intonation/Library/View/Wrapper/Article.php b/library/templates/Intonation/Library/View/Wrapper/Article.php index 807a4d3c4b947a938105a60e105ef9c300b668d4..e2a68ea2310a11d5bb32ff4533b12948614d580a 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Article.php +++ b/library/templates/Intonation/Library/View/Wrapper/Article.php @@ -265,7 +265,7 @@ class Intonation_Library_View_Wrapper_Article extends Intonation_Library_View_Wr $entity = new Class_Entity($carousel_data); - return $this->_view->article_RenderWidget($entity->getcode(), $entity->getform()); + return $this->_view->renderCKEditorWidget($entity->getcode(), $entity->getform()); } diff --git a/library/templates/Intonation/Library/View/Wrapper/Library/RichContent/Details.php b/library/templates/Intonation/Library/View/Wrapper/Library/RichContent/Details.php index 5f1d3fb84732686b756a4b9392e993c793f0cb56..801c00897291dce342ef9349fe07eef190ea27bb 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Library/RichContent/Details.php +++ b/library/templates/Intonation/Library/View/Wrapper/Library/RichContent/Details.php @@ -109,7 +109,9 @@ class Intonation_Library_View_Wrapper_Library_RichContent_Details extends Intona $options = $field->getSelectedOptionsList(); if (empty($options)) - return $this->_renderInfo($field->getValue(), + return $this->_renderInfo(($field->isCKEditor() + ? $this->_view->renderCKEditorWidgets($field->getValue()) + : $field->getValue()), 'custom'.$count); $content_options = ''; @@ -122,7 +124,7 @@ class Intonation_Library_View_Wrapper_Library_RichContent_Details extends Intona } - protected function _renderInfo($value, $class_name,$display = true) { + protected function _renderInfo($value, $class_name, $display = true) { $style = ($display) ? [] : ['style' => 'display:none;']; $style = array_merge($style, ['class' => $class_name]) ; diff --git a/library/templates/Intonation/Library/Widget/Free/View.php b/library/templates/Intonation/Library/Widget/Free/View.php index 27af3ee0e3a25f6db641ea7886cd0ca20629e984..40f71ff95346b098be8a04e8129cfddd3dee2cf0 100644 --- a/library/templates/Intonation/Library/Widget/Free/View.php +++ b/library/templates/Intonation/Library/Widget/Free/View.php @@ -41,7 +41,7 @@ class Intonation_Library_Widget_Free_View extends Zendafi_View_Helper_Accueil_Ba $edit_link); $content = $this->_article->getFullContentWithCookiesConsent(); - return $this->view->article_ReplaceWidgets($content) + return $this->view->renderCKEditorWidgets($content) . $edit_link; } diff --git a/library/templates/Intonation/View/RenderArticle.php b/library/templates/Intonation/View/RenderArticle.php index 5b34580f17a08def162d00f7a4f820c51457fc90..4c9209cca65fdf1ccf57214515f777e4a91d128b 100644 --- a/library/templates/Intonation/View/RenderArticle.php +++ b/library/templates/Intonation/View/RenderArticle.php @@ -47,7 +47,7 @@ class Intonation_View_RenderArticle extends ZendAfi_View_Helper_BaseHelper { $wrapper->getBadges(), $this->view->tagArticleEvent($article), $this->_tag('p', - $this->view->article_ReplaceWidgets($full_content), + $this->view->renderCKEditorWidgets($full_content), ['class' => 'card-text']), $location_content]; diff --git a/library/templates/Intonation/View/Article/RenderWidget.php b/library/templates/Intonation/View/RenderCKEditorWidget.php similarity index 83% rename from library/templates/Intonation/View/Article/RenderWidget.php rename to library/templates/Intonation/View/RenderCKEditorWidget.php index f3966a429a3d20b73b2319794e0723d44f756a5a..a658833a1966723793eb36ee46eabbfc192fe5dc 100644 --- a/library/templates/Intonation/View/Article/RenderWidget.php +++ b/library/templates/Intonation/View/RenderCKEditorWidget.php @@ -20,11 +20,11 @@ */ -class Intonation_View_Article_RenderWidget extends ZendAfi_View_Helper_Article_RenderWidget { +class Intonation_View_RenderCKEditorWidget extends ZendAfi_View_Helper_RenderCKEditorWidget { - protected function _getHTMLWith($params) { + protected function _getHTMLWith(array $settings) : string { $widget = ((new Class_Systeme_Widget_Widget) - ->loadFromSettings($params)); + ->loadFromSettings($settings)); return Class_Template::current()->renderWidget($widget, $this->view); } diff --git a/tests/scenarios/Templates/TemplatesLibraryTest.php b/tests/scenarios/Templates/TemplatesLibraryTest.php index 82b6940ae8092d084cc0b35520f8d0bf789679be..d9270d424e3db50d46254fb9c81212feb6591130 100644 --- a/tests/scenarios/Templates/TemplatesLibraryTest.php +++ b/tests/scenarios/Templates/TemplatesLibraryTest.php @@ -877,3 +877,48 @@ class TemplatesLibraryWithRewriteUrlLinkTest $this->assertXPath('//a[contains(@class, "badge_tag")][@title="Lire les 2 articles du professionnel"][@href="/bib/articles-pro/pro_id/670/id/1"]'); } } + + + + +class TemplatesLibraryWithCarouselDataInHTMLCustomFieldTest + extends AbstractControllerTestCase { + + + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + + $this->_buildTemplateProfil(['id' => 123123]); + + $library = $this->fixture(Class_Bib::class, + ['id' => 12, + 'libelle' => 'Valleiry']); + + $this->fixture(Class_CustomField::class, + ['id' => 1, + 'priority' => 1, + 'label' => 'Notices', + 'field_type' => Class_CustomField_Meta::CKEDITOR, + 'model' => 'Bib']); + + $library + ->setCustomField('Notices', '<p>Les nouveautés à Valleiry</p><img class="bokeh_kiosk" data-code="KIOSQUE" data-form="titre=&style_liste=mur&aleatoire=1&tri=1&boite=&rss=1&&link_to_all=1&id_panier=123&">') + ->saveWithCustomFields(); + + $this->fixture(Class_Notice::class, + ['id' => 123, + 'titre_principal' => 'Les aventures de Boule et Bill vol.19']); + + $this->dispatch('/bib/en-lire-plus/id/12'); + } + + + /** @test */ + public function masonryWithBouleEtBillRecordTitleShouldBePresent() { + $this->assertXPathContentContains('//div[@class="masonry"]//div[@class="card-title"]', + 'Les aventures de Boule et Bill vol.19'); + } +} \ No newline at end of file