diff --git a/VERSIONS_HOTLINE/128866 b/VERSIONS_HOTLINE/128866 new file mode 100644 index 0000000000000000000000000000000000000000..30b79a77b50dc8b3b6e1a742fd86325145510696 --- /dev/null +++ b/VERSIONS_HOTLINE/128866 @@ -0,0 +1 @@ + - ticket #128866 : Serveur de cache : correction d'une erreur en cas de réponse vide ou erronée du serveur d'enrichissement de Bokeh \ No newline at end of file diff --git a/application/modules/opac/controllers/NoticeajaxController.php b/application/modules/opac/controllers/NoticeajaxController.php index 0d81295f70841e7494dfacf1cbff6e22ca06f058..5086a311c9928dfc1239baab3b79595cc500eed8 100644 --- a/application/modules/opac/controllers/NoticeajaxController.php +++ b/application/modules/opac/controllers/NoticeajaxController.php @@ -64,18 +64,17 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { $viewRenderer->setLayoutScript('noticeajax/notice.phtml'); // Stats visualisation - $stat = new Class_StatsNotices(); + $stat = new Class_StatsNotices(); $stat->addStatVisu($this->id_notice); $this->view->preferences = $preferences; } public function tagsAction() { - $tags=$this->notice->getTags($this->id_notice); - $html=$this->notice_html->getTags($tags, $this->id_notice, $this->view); - - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($html); + session_write_close(); + $tags = $this->notice->getTags($this->id_notice); + $html = $this->notice_html->getTags($tags, $this->id_notice, $this->view); + $this->_ajaxResponseWithScript($html); } @@ -89,7 +88,6 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { } $this->renderExemplaires($ids, 0, 'oeuvre'); - } @@ -113,8 +111,7 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { $html = $this->view->Notice_Exemplaires($exemplaires, $nb_notices_oeuvre, $display); - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($html); + $this->_ajaxResponseWithScript($html); } @@ -123,9 +120,8 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { $this->notice = $this->notice->getLinkedSerialRecord(); if (!$this->notice) - return $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript(sprintf('<p>%s</p>', - $this->_('Aucun exemplaire trouvé'))); + return $this->_ajaxResponseWithScript(sprintf('<p>%s</p>', + $this->_('Aucun exemplaire trouvé'))); $nb_notices_oeuvre = Class_Notice::countBy(['clef_oeuvre' => $this->notice->getClefOeuvre(), 'id_notice not' => $this->notice->getId()]); @@ -151,6 +147,7 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { public function localisationAction() { + session_write_close(); $item = Class_Exemplaire::find($this->_request->getParam('id_item', 0)); $this->_helper->json(Class_Localisation::getItemLocalisation($item)); } @@ -166,18 +163,18 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { $xsl = (new Class_Notice_Xsl($notice, Class_Profil::getCurrentProfil())); if ($xsl->isEnabled()) - return $helper->htmlAjaxResponseWithScript($this->view->Notice_Xsl($xsl)); - + return $this->_ajaxResponseWithScript($this->view->Notice_Xsl($xsl)); if ($notice->isPeriodique()) - return $helper->htmlAjaxResponseWithScript($this->view->Notice_ArticlesPeriodiques($notice)); + return $this->_ajaxResponseWithScript($this->view->Notice_ArticlesPeriodiques($notice)); $html = $this->view->notice_Entete($notice, ['entete' => Class_Codification::CHAMPS]); - $helper->htmlAjaxResponseWithScript($html); + $this->_ajaxResponseWithScript($html); } public function recountsAction() { + session_write_close(); $helper = $this->_helper->getHelper('HTMLAjaxResponse'); if (!$notice = Class_Notice::find($this->id_notice)) { @@ -185,25 +182,24 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { return; } - $helper->htmlAjaxResponseWithScript($this->view->Notice_Analytics($notice)); - return; + $this->_ajaxResponseWithScript($this->view->Notice_Analytics($notice)); } - public function similairesAction() { + public function similairesAction() { + session_write_close(); $notices = $this->notice->getNoticesSimilaires(); $html = $this->notice_html->getListeNotices($notices, $this->view); - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($html); + $this->_ajaxResponseWithScript($html); } - public function seriesAction() { + public function seriesAction() { + session_write_close(); $this->notice = Class_Notice::find($this->id_notice); $notices=$this->notice->getNoticesMemeSeries(); $html = $this->notice_html->getListeNotices($notices, $this->view); - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($html); + $this->_ajaxResponseWithScript($html); } @@ -211,8 +207,7 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { session_write_close(); $avis = $this->notice->findAllResumes(); $html = $this->notice_html->getResume($avis); - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($html); + $this->_ajaxResponseWithScript($html); } @@ -220,31 +215,28 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { session_write_close(); if (!$resume = $this->notice->getResume()) $resume = $this->_('Aucun résumé'); - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($resume); + $this->_ajaxResponseWithScript($resume); } public function dispoNoticeAction() { session_write_close(); - $this->_helper->HTMLAjaxResponse($this->notice->hasExemplaireDisponible() ? 'true' : 'false'); + $this->_helper->HTMLAjaxResponse($this->notice->hasExemplaireDisponible() + ? 'true' + : 'false'); } public function biographieAction() { session_write_close(); - $this->_helper - ->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($this->view->biographie($this->notice, + $this->_ajaxResponseWithScript($this->view->biographie($this->notice, $this->notice->getAuteurPrincipal())); } public function bandeannonceAction() { session_write_close(); - $this->_helper - ->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($this->view->trailer($this->notice, + $this->_ajaxResponseWithScript($this->view->trailer($this->notice, $this->_getParam('width', 500))); } @@ -256,9 +248,7 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { : []; $html = (new Class_NoticeHtml($this->notice))->getPhotos($photos); - $this->_helper - ->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($html); + $this->_ajaxResponseWithScript($html); } @@ -271,20 +261,16 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { : []; $html = $this->notice_html->getBibliographie($biblio, $notice["A"]); - $this->_helper - ->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($html); + $this->_ajaxResponseWithScript($html); } public function resnumeriquesAction() { - $helper = $this->_helper->getHelper('HTMLAjaxResponse'); - if ($viewer = (new Class_Notice_Numel($this->notice))->getViewer()) - return $helper->htmlAjaxResponseWithScript($viewer->renderOn($this->view)); + return $this->_ajaxResponseWithScript($viewer->renderOn($this->view)); if ($viewer = (new Class_Notice_Gallica($this->notice))->getViewer()) - return $helper->htmlAjaxResponseWithScript($viewer->renderOn($this->view)); + return $this->_ajaxResponseWithScript($viewer->renderOn($this->view)); $html = $add_album_tag = ''; @@ -308,11 +294,12 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { $html = $add_album_tag . $html; - $helper->htmlAjaxResponseWithScript($html); + $this->_ajaxResponseWithScript($html); } public function morceauxAction() { + session_write_close(); if (!$this->notice->isTypeDocSonore()) return false; @@ -320,13 +307,6 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { $morceaux=$this->notice->getMorceaux(); $source=$morceaux['source']; - // Chez amazon - if (!$morceaux["nb_resultats"]) { - $source = "Amazon"; - $amazon = new Class_WebService_AmazonSonores(); - $morceaux = $amazon->rend_notice_ean($this->notice->getEan()); - } - // Chez LastFm if (!$morceaux["nb_resultats"]) { $source="Last.fm"; @@ -340,97 +320,79 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { $source = ''; $morceaux["auteur"] = $this->notice->getAuteurPrincipal(); $html = $this->notice_html->getMorceaux($morceaux,$source); - $this->_helper - ->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($html); + $this->_ajaxResponseWithScript($html); } public function videomorceauAction() { - if($this->service_afi > "") { - $width = $this->_getParam('width', 500); - $height = (int)($width * 4/5); + if ('' == $this->service_afi) { + $this->_ajaxResponseWithScript($this->notice_html + ->getNonTrouve($this->_("Service non disponible"),true)); + } + + $width = $this->_getParam('width', 500); + $height = (int)($width * 4/5); - $args=["titre" => $this->_getParam('titre'), - "auteur" => $this->_getParam('auteur'), + $args = ['titre' => $this->_getParam('titre'), + 'auteur' => $this->_getParam('auteur'), 'width' => $width, 'height' => $height]; - $data=Class_WebService_AllServices::runServiceAfi(9,$args); - $source=$data["source"]; - $video=$data["video"]; - if(!$video) $html=$this->notice_html->getNonTrouve(); - else $html=$video; - } - else - $html= $html=$this->notice_html->getNonTrouve($this->view->_("Service non disponible"),true); - $this->_helper - ->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($html); - } - - - public function playerlastfmAction() { - $lastfm=new Class_WebService_Lastfm(); - $html = $lastfm->getPlayer($_REQUEST["url"]); - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($html); + $data = Class_WebService_AllServices::runServiceAfiVideo($args); + $this->_ajaxResponseWithScript($data['video'] + ? $data['video'] + : $this->notice_html->getNonTrouve()); } public function videosAction() { - $width = $this->_getParam('width', 500) - 8; //8px du skin de l'INA sur lequel on n'a pas la main - $height = (int)($width * 4/5); - $author = $this->_getParam('author', $this->notice->getAuteurPrincipal()); - $helper = $this->_helper->getHelper('HTMLAjaxResponse'); - - if ($num_video = $this->_getParam("num_video", 0)) { + if ($num_video = $this->_getParam('num_video', 0)) { $num_video = $num_video-1; - $html.=$_SESSION["video_interview"][$num_video]["player"]; - $helper->htmlAjaxResponseWithScript('<style>*{margin:0;padding:0}</style>'.$html); + $html = $_SESSION["video_interview"][$num_video]["player"]; + $this->_ajaxResponseWithScript('<style>*{margin:0;padding:0}</style>'.$html); return; } unset($_SESSION["video_interview"]); - if(!$author) { - $html=$this->notice_html->getNonTrouve($this->view->_("Cette notice n'a pas d'auteur."),true); - $helper->htmlAjaxResponseWithScript($html); + if ('' == $this->service_afi) { + $html = $this->notice_html->getNonTrouve($this->_("Service non disponible"),true); + $this->_ajaxResponseWithScript($html); return; } - - if($this->service_afi > "") { - $args = ['auteur' => $author, - 'width' => $width]; - $data = Class_WebService_AllServices::runServiceAfiInterviews($args); - $source = $data["source"]; - $videos = $data["videos"]; - $_SESSION["video_interview"]=$videos; - $html=$this->notice_html->getInterviews($source, $videos, $width, $height); - $helper->htmlAjaxResponseWithScript($html); + $author = $this->_getParam('author', $this->notice->getAuteurPrincipal()); + if (!$author) { + $html=$this->notice_html->getNonTrouve($this->_("Cette notice n'a pas d'auteur."),true); + $this->_ajaxResponseWithScript($html); return; } - $html = $this->notice_html->getNonTrouve($this->view->_("Service non disponible"),true); - $helper->htmlAjaxResponseWithScript($html); + $width = $this->_getParam('width', 500) - 8; //8px du skin de l'INA sur lequel on n'a pas la main + $height = (int)($width * 4/5); + $args = ['auteur' => $author, + 'width' => $width]; + $data = Class_WebService_AllServices::runServiceAfiInterviews($args); + $source = $data["source"]; + $videos = $data["videos"]; + $_SESSION["video_interview"] = $videos; + $html = $this->notice_html->getInterviews($source, $videos, $width, $height); + $this->_ajaxResponseWithScript($html); } public function avisAction() { session_write_close(); $helper = $this->_helper->getHelper('HTMLAjaxResponse'); - // Lire la notice - if (!$notice = Class_Notice::find($this->id_notice)) { + if (!$this->id_notice) { $helper->direct(''); return; } - $all_avis = $notice->getAllAvisPerSource($this->_getParam("page", 0)); - - $helper->htmlAjaxResponseWithScript($this->view->Notice_Avis($notice, - $all_avis, - $this->_request->getParams())); + $all_avis = $this->notice->getAllAvisPerSource($this->_getParam("page", 0)); + $this->_ajaxResponseWithScript($this->view->Notice_Avis($this->notice, + $all_avis, + $this->_request->getParams())); } @@ -443,7 +405,7 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { public function addTagAction() { - if (!$user = Class_Users::getLoader()->getIdentity()) { + if (!$user = Class_Users::getIdentity()) { $this->_forward('popup-login', 'auth', 'opac', ['redirect' => $this->view->url()]); return; } @@ -453,38 +415,39 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { public function avisAbonneAction() { - session_write_close(); - $notice = Class_Notice::find($this->id_notice); - - $html = $this->view->getHelper('Avis')->getAvisPopup($notice, $notice->getAvisAbonne()); + $this->_renderAvis(function() { return $this->notice->getAvisAbonne(); }); + } - Class_ScriptLoader::getInstance() - ->addOPACStyleSheet('global') - ->addSkinStyleSheet('global'); - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($html); + public function avisBibliothecaireAction() { + $this->_renderAvis(function() { return $this->notice->getAvisBibliothecaire(); }); } - public function avisBibliothecaireAction() { + protected function _renderAvis($callback) { session_write_close(); - $notice = Class_Notice::find($this->id_notice); - $html = $this->view->getHelper('Avis')->getAvisPopup($notice, $notice->getAvisBibliothecaire()); + $helper = $this->_helper->getHelper('HTMLAjaxResponse'); + if (!$this->id_notice) { + $helper->direct(''); + return; + } + + $html = $this->view->getHelper('Avis') + ->getAvisPopup($this->notice, $callback()); Class_ScriptLoader::getInstance() ->addOPACStyleSheet('global') ->addSkinStyleSheet('global'); - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($html); + $this->_ajaxResponseWithScript($html); } public function babelthequeAction() { $helper = $this->_helper->getHelper('HTMLAjaxResponse'); - if (!$script = Class_AdminVar::get('BABELTHEQUE_JS')) { + if (!$this->id_notice + || !($script = Class_AdminVar::get('BABELTHEQUE_JS'))) { $helper->direct(''); return; } @@ -493,24 +456,25 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { $html .= sprintf('<input type="hidden" id="BW_id_isbn" value="%s"\>', $this->notice->getIsbn()); - $blocs = array('notes', 'critiques', 'critiques_pro', 'citations', 'videos', 'etiquettes', 'suggestions'); + $blocs = ['notes', 'critiques', 'critiques_pro', 'citations', + 'videos', 'etiquettes', 'suggestions']; + foreach($blocs as $bloc) $html .= sprintf('<div id="BW_%s"></div>', $bloc); - $helper->htmlAjaxResponseWithScript($html); + $this->_ajaxResponseWithScript($html); } public function frbrAction() { - $id = str_replace('N', '', $this->_getParam('id_notice')); + session_write_close(); $helper = $this->_helper->getHelper('HTMLAjaxResponse'); - - if (!$model = Class_Notice::find((int)$id)) { + if (!$this->id_notice) { $helper->direct(ZendAfi_View_Helper_Frbr::NO_RESULT_MESSAGE); return; } - $helper->htmlAjaxResponseWithScript($this->view->frbr($model)); + $this->_ajaxResponseWithScript($this->view->frbr($this->notice)); } @@ -546,8 +510,9 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { $this->_helper->ajax(function() use ($record) { - return $this->view->RenderRecord_RenderItems($record->getItemsFromSIGB(), - $record->getSameWorkItemsFromSIGB()); + return $this->view + ->RenderRecord_RenderItems($record->getItemsFromSIGB(), + $record->getSameWorkItemsFromSIGB()); }); } @@ -560,7 +525,7 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { 'id' => $this->notice->getId()], null, true), - $this->view->_('Consulter en ligne'), + $this->_('Consulter en ligne'), ['class' => 'btn btn-lg btn-primary m-3']); }; @@ -570,17 +535,18 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { protected function _getLinkOnline($url) { return $this->view->tagAnchor($url, - $this->view->_('Description en ligne'), + $this->_('Description en ligne'), ['class' => 'btn btn-lg btn-primary m-3']); } public function urlResourcesAction() { - $first_item = $this->notice->getExemplaires()[0]; + if (!$items = $this->notice->getExemplaires()) + return $this->_helper->ajax(); + $first_item = $items[0]; $callback = function() use ($first_item) { return $this->_getLinkOnline($first_item->getExternalUrl()); - }; return $this->_helper->ajax($callback); @@ -588,15 +554,17 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { public function bundleResourcesAction() { - $first_item = $this->notice->getExemplaires()[0]; + if (!$items = $this->notice->getExemplaires()) + return $this->_helper->ajax(); + $first_item = $items[0]; $callback = function() use ($first_item) { if ( ! $bundle = $first_item->getBundle()) return $this->_('Lot introuvable'); return $this->view->tagAnchor($this->view->urlNotice($bundle), - $this->view->_('Fait partie du lot %s', - $bundle->getTitrePrincipal()), + $this->_('Fait partie du lot %s', + $bundle->getTitrePrincipal()), ['class' => 'btn btn-lg btn-primary m-3']); }; @@ -617,25 +585,22 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { public function trailerAction() { session_write_close(); - $args = ['titre' => $this->notice->getRecordTitle(), 'auteur' => $this->notice->getAuteurPrincipal(), 'clef_oeuvre' => $this->notice->getClefOeuvre(), 'type_doc' => $this->notice->getFamilleId()]; - if ( !$data = Class_WebService_AllServices::runServiceAfi(6, $args)) + $data = Class_WebService_AllServices::runServiceAfiTrailers($args); + if (!$data['player']) return $this->_helper->ajax(); - if ( !isset($data['player']) || (!$html = $data['player'])) - return $this->_helper->ajax(); - - return $this->_helper->ajax(function() use ($html, $data) + return $this->_helper->ajax(function() use ($data) { - $source = isset($data['source']) + $source = $data['source'] ? $data['source'] : $this->_('source inconnue'); - preg_match('/src="([^"]+)"/', $html, $match); + preg_match('/src="([^"]+)"/', $data['player'], $match); return $this->view->renderEmbed($source, $match[1]); }); @@ -649,8 +614,7 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { ->setModel($this->notice) ->collection(); - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($this->view->renderPictures($pictures)); + $this->_ajaxResponseWithScript($this->view->renderPictures($pictures)); } @@ -661,8 +625,7 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { ->setModel($this->notice) ->collection(); - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($this->view->renderTracks($tracks)); + $this->_ajaxResponseWithScript($this->view->renderTracks($tracks)); } @@ -723,6 +686,12 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { return $helper->direct(''); $author_description = new Class_CodifAuteur_Description($author); - $helper->htmlAjaxResponseWithScript($this->view->renderAuthor($author_description)); + $this->_ajaxResponseWithScript($this->view->renderAuthor($author_description)); + } + + + protected function _ajaxResponseWithScript($content) { + $this->_helper->getHelper('HTMLAjaxResponse') + ->htmlAjaxResponseWithScript($content); } } \ No newline at end of file diff --git a/application/modules/telephone/controllers/RechercheController.php b/application/modules/telephone/controllers/RechercheController.php index c9eb13641ccec1e0803b6abdc4b7a40c51d84beb..a30431acf729969d67bee78ee7f26b2b28713f03 100644 --- a/application/modules/telephone/controllers/RechercheController.php +++ b/application/modules/telephone/controllers/RechercheController.php @@ -156,6 +156,7 @@ class Telephone_RechercheController extends RechercheController { $video = Class_WebService_AllServices::runServiceAfiVideo(['titre' => $notice->getTitrePrincipal(), 'auteur' => $notice->getAuteurPrincipal()]); $video_id = null; + if (($html = $video['video']) && 1 == preg_match('/value=\"([^\"\&]+)/', $html, $matches)) { $parts = explode('/', $matches[1]); diff --git a/library/Class/CodifAuteur/Description.php b/library/Class/CodifAuteur/Description.php index a13e00f604dd7b7729eadd7eb12c1cfbfe077eed..65934b7d715e93088d12321c6c122160c129596c 100644 --- a/library/Class/CodifAuteur/Description.php +++ b/library/Class/CodifAuteur/Description.php @@ -123,6 +123,11 @@ class Class_CodifAuteur_Description { } + public function isBiographyEnabled() { + return !$this->isBiographyDisabled(); + } + + public function renderBiographieOn($view) { if (!count($this->getRecords())) return ''; @@ -332,19 +337,21 @@ class Class_CodifAuteur_Description { public function renderThumbnailOn($view) { - if ($this->isBiographyDisabled()) - return ''; - - $this->fetchBiography(); - return $this->_author->getThumbnailUrl() + return $this->isBiographyEnabled() && ($url = $this->getThumbnailUrl()) ? $view->tag('img', null, - ['src' => $this->_author->getThumbnailUrl(), + ['src' => $url, 'alt' => $this->getLabel() . '. ' . $this->_('Source: Wikipedia')]) : ''; } + public function getThumbnailUrl() { + $this->fetchBiography(); + return $this->_author->getThumbnailUrl(); + } + + public function renderWikipediaOn($view) { if ($this->isBiographyDisabled()) return ''; diff --git a/library/Class/WebService/AllServices.php b/library/Class/WebService/AllServices.php index e7d4f9934114f5c01304f6c458b6400421c75f5d..5337721effa14d07e5973a0b1feef09c2dd0d587 100644 --- a/library/Class/WebService/AllServices.php +++ b/library/Class/WebService/AllServices.php @@ -20,11 +20,12 @@ */ class Class_WebService_AllServices { - use Trait_Translator; + use Trait_Translator, Trait_InspectorGadgetAware; const RETOUR_SERVICE_OK = 2, SVC_API = '2.0', + SVC_GET_TRAILER = 6, SVC_GET_BIOGRAPHY = 8, SVC_GET_VIDEO = 9, SVC_GET_INTERVIEW = 7, @@ -84,17 +85,37 @@ class Class_WebService_AllServices { public static function runServiceAfiBiographie($args) { - return static::runServiceAfi(static::SVC_GET_BIOGRAPHY, $args); + return array_merge(['statut_recherche' => 1, + 'erreur' => '', + 'source' => '', + 'url_source' => '', + 'biographie' => '', + 'vignette' => '', + 'image' => '', + 'wikidata_id' => '', + 'youtube_channel_id' => '', + 'isni' => '', + 'ark' => '', + 'biography_disabled' => 0], + static::runServiceAfi(static::SVC_GET_BIOGRAPHY, $args)); } public static function runServiceAfiVideo($args) { - return static::runServiceAfi(static::SVC_GET_VIDEO, $args); + return array_merge(['source' => '', 'video' => ''], + static::runServiceAfi(static::SVC_GET_VIDEO, $args)); } public static function runServiceAfiInterviews($args) { - return static::runServiceAfi(static::SVC_GET_INTERVIEW, $args); + return array_merge(['source' => '', 'videos' => []], + static::runServiceAfi(static::SVC_GET_INTERVIEW, $args)); + } + + + public static function runServiceAfiTrailers($args) { + return array_merge(['source' => '', 'player' => ''], + static::runServiceAfi(static::SVC_GET_TRAILER, $args)); } @@ -217,20 +238,25 @@ class Class_WebService_AllServices { public static function runServiceAfi($service, $args) { if (!$url_service = Class_CosmoVar::get('url_services')) - return false; + return []; if (!$args) - $args = array(); + $args = []; $args['src'] = static::createSecurityKey(); $args['api'] = static::SVC_API; $args['action'] = $service; - $response = json_decode(static::httpGet($url_service, $args), true); - - if ($ig = Zend_Controller_Front::getInstance() - ->getPlugin('ZendAfi_Controller_Plugin_InspectorGadget')) - $ig->log(); + try { + if( !$response = json_decode(static::httpGet($url_service, $args), true)) + $response = []; + static::_inspectorLog(); + } + catch(Exception $e) { + $response = []; + static::_inspectorLogError($url_service. '?' . http_build_query($args), + $e->getMessage()); + } return $response; } diff --git a/library/Trait/InspectorGadgetAware.php b/library/Trait/InspectorGadgetAware.php new file mode 100644 index 0000000000000000000000000000000000000000..accec79e68e34ae583a4e506027eb229a014a73a --- /dev/null +++ b/library/Trait/InspectorGadgetAware.php @@ -0,0 +1,60 @@ +<?php +/** + * Copyright (c) 2012-2021, 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_InspectorGadgetAware { + protected static $_inspector; + + /** @category testing */ + public static function setInspector($inspector) { + static::$_inspector = $inspector; + } + + + protected static function _inspectorLog() { + static::_getInspector()->log(); + } + + + protected static function _inspectorLogError($url, $message) { + static::_getInspector()->logError($url, $message); + + } + + + protected static function _getInspector() { + if (static::$_inspector) + return static::$_inspector; + + return (static::$_inspector = Zend_Controller_Front::getInstance() + ->getPlugin(ZendAfi_Controller_Plugin_InspectorGadget::class)) + ? static::$_inspector + : static::$_inspector = new NullInspector; + } +} + + + + +class NullInspector { + public function log() {} + public function logError($url, $message) {} +} \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Biographie.php b/library/ZendAfi/View/Helper/Biographie.php index 632de6017b4f179d535e23458a12b6fcae86f615..17c8cc6b07f052111bda0c0a88e64fcd0fa3ba7f 100644 --- a/library/ZendAfi/View/Helper/Biographie.php +++ b/library/ZendAfi/View/Helper/Biographie.php @@ -50,7 +50,7 @@ class ZendAfi_View_Helper_Biographie extends ZendAfi_View_Helper_BaseHelper { if (!$data->getbiographie()) $data->setsource($this->_("Aucune information n'a été trouvée")); - $source = $this->view->tag('p', $this->view->_('Source'). ' : ' . $data->getsource()); + $source = $this->view->tag('p', $this->_('Source'). ' : ' . $data->getsource()); $auteur = $notice->getAuteurPrincipal(); $biographie = $data->getbiographie(); diff --git a/library/ZendAfi/View/Helper/Trailer.php b/library/ZendAfi/View/Helper/Trailer.php index a705ddd2e6c31e1159ee5eb2507e79b8e55f6ace..26f265ca69ab0e6602a55196e2b2b798f2564c96 100644 --- a/library/ZendAfi/View/Helper/Trailer.php +++ b/library/ZendAfi/View/Helper/Trailer.php @@ -51,7 +51,8 @@ class ZendAfi_View_Helper_Trailer extends ZendAfi_View_Helper_BaseHelper { 'width' => $width, 'height' => $height]; - $data = Class_WebService_AllServices::runServiceAfi(6, $args); + $trailer_service = (new Class_WebService_AllServices); + $data = $trailer_service->runServiceAfi($trailer_service::SVC_GET_TRAILER, $args); return (new Class_NoticeHtml())->getBandeAnnonce($data['source'], $data['player']); } diff --git a/library/templates/Intonation/Library/InaInterviews.php b/library/templates/Intonation/Library/InaInterviews.php index 82f9fe64fff98a996896aa98e4e2840730d45fb2..32598a5f2e631058f2fdadacefb7f9877123d8e2 100644 --- a/library/templates/Intonation/Library/InaInterviews.php +++ b/library/templates/Intonation/Library/InaInterviews.php @@ -41,9 +41,7 @@ class Intonation_Library_InaInterviews { $data = Class_WebService_AllServices::runServiceAfiInterviews($args); - if (!$data - || !isset($data['videos']) - || (!$videos = $data["videos"])) + if (!$videos = $data["videos"]) return []; $interviews = []; diff --git a/library/templates/Intonation/Library/Trailers.php b/library/templates/Intonation/Library/Trailers.php index 9884dbc3b5faf7210c6d069a70d22f12444102f4..884b2d56d1aa1c14b81bdcfb8f0e1f3edb4c133d 100644 --- a/library/templates/Intonation/Library/Trailers.php +++ b/library/templates/Intonation/Library/Trailers.php @@ -44,7 +44,9 @@ class Intonation_Library_Trailers { 'clef_oeuvre' => $this->_model->getClefOeuvre(), 'type_doc' => $this->_model->getFamilleId()]; - if ( !$data = Class_WebService_AllServices::runServiceAfi(6, $args)) + $trailer_service = (new Class_WebService_AllServices); + $data = $trailer_service->runServiceAfi($trailer_service::SVC_GET_TRAILER, $args); + if ( empty($data) ) return []; if ( !isset($data['player']) || (!$html = $data['player'])) diff --git a/library/templates/Intonation/View/Author/RenderThumbnail.php b/library/templates/Intonation/View/Author/RenderThumbnail.php index 40dea0fdad12a1b46fac3008727e9885b1ed32b2..e9eb992f65cb61d28342552534ddf61864091d9a 100644 --- a/library/templates/Intonation/View/Author/RenderThumbnail.php +++ b/library/templates/Intonation/View/Author/RenderThumbnail.php @@ -22,12 +22,7 @@ class Intonation_View_Author_RenderThumbnail extends ZendAfi_View_Helper_BaseHelper { public function Author_RenderThumbnail($author) { - if ($author->isBiographyDisabled()) - return $this->_defaultIco(); - - $bio = $author->fetchBiography(); - - return ($url = $bio->getvignette()) + return $author->isBiographyEnabled() && ($url = $author->getThumbnailUrl()) ? $this->_div(['onclick' => '$(this).toggleClass(\'modal_image\');'], $this->view->tagImg($url, ['class' => 'img-thumbnail', diff --git a/tests/library/Class/WebService/CacheServerTest.php b/tests/library/Class/WebService/CacheServerTest.php index 98050b450b20e12c18ab65aed0aea7cf6694c6a5..777908b2d3d8b762585ee571c8eab9f5edd59721 100644 --- a/tests/library/Class/WebService/CacheServerTest.php +++ b/tests/library/Class/WebService/CacheServerTest.php @@ -70,6 +70,53 @@ abstract class Class_WebService_CacheServerTestCase extends ModelTestCase { +class Class_WebService_CacheServerUnknownResponseTest + extends Class_WebService_CacheServerTestCase { + + protected + $_storm_default_to_volatile = true, + $_response, + $_inspector; + + + public function setUp() { + parent::setUp(); + $this->_http->whenCalled('open_url') + ->willDo(function() + { + throw new RuntimeException("ouuuups"); + }); + + $this->_inspector = $this->mock() + ->whenCalled('logError') + ->answers(null); + + Class_WebService_AllServices::setInspector($this->_inspector); + $this->_response = Class_WebService_AllServices::runServiceAfiInterviews([]); + } + + + public function tearDown() { + Class_WebService_AllServices::setInspector(null); + parent::tearDown(); + } + + + /** @test */ + public function interviewsShouldAnswerEmptySourceAndVideos() { + $this->assertEquals(['source' => '', 'videos' => []], $this->_response); + } + + + /** @test */ + public function inspectorGadgetShouldLogError() { + $this->assertTrue($this->_inspector->methodHasBeenCalled('logError')); + } +} + + + + class Class_WebService_CacheServerDirectTest extends Class_WebService_CacheServerTestCase {