diff --git a/application/modules/opac/controllers/WidgetController.php b/application/modules/opac/controllers/WidgetController.php new file mode 100644 index 0000000000000000000000000000000000000000..43bc563d57a615f3b57655a294d2bd6233860587 --- /dev/null +++ b/application/modules/opac/controllers/WidgetController.php @@ -0,0 +1,43 @@ +<?php +/** + * Copyright (c) 2012-2018, 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 + */ + + +class WidgetController extends ZendAfi_Controller_Action { + public function renderAction() { + session_write_close(); + $this->getHelper('ViewRenderer')->setNoRender(); + + if (!$id = $this->_getParam('widget_id')) + return $this->_response->setHttpResponseCode(404); + + if (!$profile_id = $this->_getParam('profile_id')) + return $this->_response->setHttpResponseCode(404); + + if (!$widget = ((new Class_Systeme_Widget_Widget) + ->setId($id) + ->setProfileId($profile_id) + ->load())) + return $this->_response->setHttpResponseCode(404); + xdebug_break(); + Class_Template::setCurrentFrom($profile_id); + $this->_response->setBody(Class_Template::current()->renderWidget($widget, $this->view)); + } +} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/DefineURLs.php b/library/ZendAfi/Controller/Plugin/DefineURLs.php index 91f282e3221db9b4b30a2e5e63e9424c0007276f..382042c028415fb4b48e794c5b5a0697c75ecb6c 100644 --- a/library/ZendAfi/Controller/Plugin/DefineURLs.php +++ b/library/ZendAfi/Controller/Plugin/DefineURLs.php @@ -70,7 +70,7 @@ class ZendAfi_Controller_Plugin_DefineURLs extends Zend_Controller_Plugin_Abstra Class_Profil::setCurrentProfil($detector->detectFrom($request)); $profil = Class_Profil::getCurrentProfil(); - Class_Template::setCurrentFrom($request->getParam('id_profil', $profil->getId())); + Class_Template::setCurrentFrom($request->getParam('id_profil', $request->getParam('profile_id', $profil->getId()))); if (static::ADMIN == $request->getModuleName()) return $this->adminRequest(); diff --git a/library/templates/Intonation/Assets/css/intonation.css b/library/templates/Intonation/Assets/css/intonation.css index 42204524c88422bb93bc6db7c3df8d8b17513cc3..13262e1274cbbe76612fd2a1463703adb6edff03 100644 --- a/library/templates/Intonation/Assets/css/intonation.css +++ b/library/templates/Intonation/Assets/css/intonation.css @@ -116,4 +116,19 @@ p > i { .multiple_carousel .img_as_background { height: 100%; +} + +pre:hover { + cursor: text; +} + +button[onclick]:hover { + cursor: pointer; +} + +pre { + padding: 1rem 1em; + border-left: 5px solid; + margin: 0 1em; + border-right: 5px solid; } \ No newline at end of file diff --git a/library/templates/Intonation/Library/Settings.php b/library/templates/Intonation/Library/Settings.php index 7e04a081de4f4794b057e68f946737510cb6afac..1ee6cb4ad308e749727a8369e02d815356db9d8b 100644 --- a/library/templates/Intonation/Library/Settings.php +++ b/library/templates/Intonation/Library/Settings.php @@ -94,7 +94,10 @@ class Intonation_Library_Settings extends Intonation_System_Abstract { 'icons_map_utils' => ['image_place_holder' => '/library/templates/Intonation/Assets/images/image_place_holder.png', 'previous' => 'class fas fa-chevron-left', - 'next' => 'class fas fa-chevron-right'] + 'next' => 'class fas fa-chevron-right', + 'rss' => 'class fas fa-rss', + 'embed' => 'class fas fa-code' + ] ]; diff --git a/library/templates/Intonation/Library/Widget/Carousel/Record/Definition.php b/library/templates/Intonation/Library/Widget/Carousel/Record/Definition.php index b1d9ec9eab6f0c2c2e28b03f2627cf3f8292658b..4e01f28a80958c47a947b2aa701165ad859d2ca9 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Record/Definition.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Record/Definition.php @@ -42,7 +42,7 @@ class Intonation_Library_Widget_Carousel_Record_Definition extends Class_Systeme 'display_mode' => static::WALL, 'rss_avis' => false, 'embeded_code' => false, - 'title_as_link' => true, + 'link_to_all' => true, 'order' => Class_CriteresRecherche::SORT_RANDOM, 'nb_notices' => 9]; } diff --git a/library/templates/Intonation/Library/Widget/Carousel/Record/Form.php b/library/templates/Intonation/Library/Widget/Carousel/Record/Form.php index 9e6854e324d423b24ca53af5af6a9fb376c32175..235523a94e207600d2d556aca556d2fa7611c1f5 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Record/Form.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Record/Form.php @@ -50,14 +50,14 @@ class Intonation_Library_Widget_Carousel_Record_Form extends ZendAfi_Form_Config 'display_mode']) ->addElement('checkbox', - 'title_as_link', - ['label' => $this->_('Le titre de la boite est un lien vers la recherche')]) + 'link_to_all', + ['label' => $this->_('Proposer le lien vers tous les résultats')]) ->addElement('checkbox', 'embeded_code', ['label' => $this->_('Proposer le code "embeded"')]) - ->addToShareGroup(['title_as_link', + ->addToShareGroup(['link_to_all', 'embeded_code']); $this->removeElement('tri'); diff --git a/library/templates/Intonation/Library/Widget/Carousel/Record/View.php b/library/templates/Intonation/Library/Widget/Carousel/Record/View.php index 5e5977560fb745bf18c64811587fa611aa65996e..90e6144b549b4df4806fdeeff8021ad3958b1ace 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Record/View.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Record/View.php @@ -25,10 +25,78 @@ class Intonation_Library_Widget_Carousel_Record_View extends Zendafi_View_Helper public function getHtml() { $this->titre = $this->_settings->getTitre(); $this->contenu = $this->_getHTML(); + return $this->getHtmlArray(); } + public function getFooter() { + $rss = $this->_settings->getRssAvis() + ? $this->_getTagRss() + : ''; + + $embeded = $this->_settings->getEmbededCode() + ? $this->_getTagEmbededCode() + : ''; + + $link_to_all = $this->_settings->getLinkToAll() + ? $this->_getTagLinkToAll() + : ''; + + $html = array_filter([$rss, + $embeded, + $link_to_all]); + + if (empty($html)) + return; + + return $this->_tag('div', + implode($html), + ['class' => 'btn-group', + 'role' => 'group']); + } + + + protected function _getTagRss() { + return $this->view->button(new Class_Entity(['Text' => Class_Template::current() + ->getIco($this->view, + 'rss', + 'utils'), + 'Url' => $this->_getUrlFor('rss', 'kiosque'), + 'Attribs' => ['title' => $this->_('Flux RSS de la boite "%s"', $this->titre)]])); + } + + + protected function _getTagEmbededCode() { + $id = 'dropdown_embed_' . $this->getId(); + return $this->_tag('div', + $this->_tag('button', + Class_Template::current()->getIco($this->view, 'embed', 'utils'), + ['class' => 'dropdown-toggle', + 'title' => $this->_('Code IFRAME à copier coller'), + 'id' => $id, + 'data-toggle' => 'dropdown', + 'aria-haspopup' => 'true', + 'aria-expanded' => 'false']) + . $this->_tag('div', + $this->view->tagPre($this->_tag('iframe', + '', + ['src' => $this->view->absoluteUrl([ + 'module' => 'opac', + 'controller' => 'widget', + 'action' => 'render', + 'widget_id' => $this->getId(), + 'profile_id' => Class_Profil::getCurrentProfil()->getId()], + null, + true)]), + ['class' => 'embeded_code']), + ['class' => 'dropdown-menu', + 'aria-labelledby' => $id]), + ['class' => 'btn-group', + 'role' => 'group']); + } + + protected function _getHTML() { $order = $this->_settings->getOrder(); $selection_id = $this->_settings->getIdPanier(); diff --git a/library/templates/Intonation/Template.php b/library/templates/Intonation/Template.php index 17dd56c2ed2b011c6e3e4f92ef0e600d885e39bd..502f058b892dad2e2080b80208aa54a745dcfd78 100644 --- a/library/templates/Intonation/Template.php +++ b/library/templates/Intonation/Template.php @@ -55,6 +55,15 @@ class Intonation_Template extends Class_Template { } + public function renderWidget($widget, $view) { + $widget->setSection(new Class_Entity); + $content = $this->renderWidgetOn((new Intonation_System_Widget)->setSettings($widget), $view); + $iframe = (new Intonation_View_Iframe($this, $view)) + ->setBody($content); + return $iframe->render(); + } + + public function handleFooter() { return true; } diff --git a/library/templates/Intonation/View/Iframe.php b/library/templates/Intonation/View/Iframe.php new file mode 100644 index 0000000000000000000000000000000000000000..dc37a76c5abeac4adc42c532536d471d98deb941 --- /dev/null +++ b/library/templates/Intonation/View/Iframe.php @@ -0,0 +1,166 @@ +<?php +/** + * Copyright (c) 2012-2018, 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 + */ + + +class Intonation_View_Iframe extends ZendAfi_View_Helper_BaseHelper { + + protected + $_body, + $_profile, + $_template; + + + public function __construct($template, $view) { + $this->view = $view; + $this->_template = $template; + $this->_profile = $template->getProfile(); + } + + + public function setBody($content) { + $this->_body = $content; + return $this; + } + + + public function render() { + $head = $this->_tag('head', + $this->_headContent()); + + return $this->_tag('html', + $head . $this->_body, + ['lang' => $this->_translate()->getLocale()]); + } + + + protected function _headContent() { + xdebug_break(); + $script_loader = Class_ScriptLoader::getInstance(); + $head_scripts = Class_ScriptLoader::newInstance() + ->addInlineScript(sprintf('var baseUrl="%s"; var imagesUrl="%s"; var cssUrl="%s"; var userFilesUrl="%s"', + BASE_URL, + URL_ADMIN_IMG, + URL_ADMIN_CSS, + USERFILESURL)); + + if($this->_template->getIntonationJquery()) + $head_scripts->loadJQuery(); + + if($this->_template->getIntonationJqueryUi()) + $head_scripts->loadJQueryUI(); + + $this->_addFontAwesome($head_scripts); + $this->_addBootstrap4($head_scripts); + + if($this->_template->getIntonationCoreJs()) { + $head_scripts->addOPACScript('subModal') + ->addAdminScripts(['onload_utils', 'global']) + ->showNotifications(); + $script_loader->addJQueryReady('initializePopups();'); + } + + if($this->_template->getIntonationCoreCss()) + $head_scripts->addOPACStyleSheet('core'); + + + if($this->_template->getIntonationIntonationCss()) + $head_scripts->addStyleSheets([Class_Url::absolute('/library/templates/Intonation/Assets/css/intonation.css')]); + + if($custom_css_urls = $this->_template->getCustomCssUrl()) + $head_scripts->addStyleSheets($custom_css_urls); + + if($custom_js_urls = $this->_template->getCustomJsUrl()) + $head_scripts->addScripts($custom_js_urls); + + $content = [$this->_tag('meta', null, ['http-equiv' => 'Content-Type', + 'content' => 'text/html;charset=UTF-8']), + + $this->_tag('meta', null, ['name' => 'viewport', + 'content' => 'width=device-width, initial-scale=1, shrink-to-fit=no']), + + $this->_tag('meta', null, ['name' => 'description', + 'content' => $this->_profile->getCommentaire()]), + + $this->_tag('meta', null, ['name' => 'keywords', + 'content' => $this->_profile->getRefTags()]), + + $this->_tag('meta', null, ['name' => 'robots', + 'content' => 'all']), + + $this->_tag('meta', null, ['name' => 'revisit-after', + 'content' => '10 days']), + + $this->_tag('title', $this->view->getTitre()), + + $head_scripts->styleSheetsHTML(), + $script_loader->styleSheetsHTML(), + $head_scripts->javaScriptsHTML(), + $script_loader->javaScriptsHTML(), + $this->view->heartbeat(), + $this->view->headScript(), + $this->view->headLink()]; + + return implode($content); + } + + + protected function _addFontAwesome($script_loader) { + if (!$this->_template->getIntonationFontAwesomeCss()) + return $this; + + $script_loader + ->cssAddLine($this->_tag('link', + null, + ['rel' => 'stylesheet', + 'href' => 'https://use.fontawesome.com/releases/v5.5.0/css/all.css', + 'integrity' => 'sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU', + 'crossorigin' => 'anonymous'])); + return $this; + } + + + protected function _addBootstrap4($script_loader) { + if($this->_template->getIntonationBootstrapCss()) + $script_loader->cssAddLine( + $this->_tag('link', + null, + ['rel' => 'stylesheet', + 'href' => 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css', + 'integrity' => 'sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M', + 'crossorigin' => 'anonymous'])); + + if($this->_template->getIntonationBootstrapDependencyPopper()) + $script_loader->scriptsAddLine($this->view->tag('script', + '', + ['src' => 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js', + 'integrity' => 'sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4', + 'crossorigin' => 'anonymous'])); + + if($this->_template->getIntonationBootstrapJs()) + $script_loader->scriptsAddLine($this->view->tag('script', + '', + ['src' => 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js', + 'integrity' => 'sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1', + 'crossorigin' => 'anonymous'])); + + return $this; + } +} \ No newline at end of file diff --git a/library/templates/Intonation/View/RenderMultipleCarousel.php b/library/templates/Intonation/View/RenderMultipleCarousel.php index f5f46012c0b25189d23b9459392f7fd7e6c18fdb..739257588775a058961ad4a9b01c0d15995c83f9 100644 --- a/library/templates/Intonation/View/RenderMultipleCarousel.php +++ b/library/templates/Intonation/View/RenderMultipleCarousel.php @@ -21,6 +21,7 @@ class Intonation_View_RenderMultipleCarousel extends ZendAfi_View_Helper_BaseHelper { + public function renderMultipleCarousel($collection) { $id = 'carousel_' . md5(rand(1000, 9999)); diff --git a/tests/scenarios/Templates/TemplatesTest.php b/tests/scenarios/Templates/TemplatesTest.php index f1658f4104874a358d2ac970110967763efb9f70..acbecc1fa42cbd6fc3d66feb8d42a17f7ee26fdb 100644 --- a/tests/scenarios/Templates/TemplatesTest.php +++ b/tests/scenarios/Templates/TemplatesTest.php @@ -1531,6 +1531,10 @@ class TemplatesRecordsWidgetTest extends TemplatesIntonationTestCase { ->load()); $widget ->setNewDatas(['order' => 'alpha_titre ASC', + 'rss_avis' => 1, + 'link_to_all' => 1, + 'embeded_code'=> 1, + 'IntonationShowFooter' => 1, 'display_mode' => 'multiple_carousel']) ->updateProfile(); @@ -1551,4 +1555,15 @@ class TemplateLoadingImageTest extends TemplatesIntonationTestCase { $this->dispatch('/opac/index/picture/id_profil/72/url/' . urlencode('https://mon-bokeh.org/belle-image.jpeg')); $this->assertNotNull($this->_response->getBody()); } +} + + + +class TemplateRenderWidgetTest extends TemplatesIntonationTestCase { + /** @test */ + public function dispatchWidgetRenderShouldDisplayContent() { + ZendAfi_Auth::getInstance()->clearIdentity(); + $this->dispatch('/opac/widget/render/widget_id/17/profile_id/72/', true); + $this->assertXPathContentContains('//div', 'Boite kiosque de notices'); + } } \ No newline at end of file