diff --git a/library/Class/Notice.php b/library/Class/Notice.php index c900c1c308b99a5ccc652f9dcb8c030c7954e5f7..572cee73fbf4a38bada0909448d34f1086c6739a 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -405,45 +405,12 @@ class Class_Notice extends Storm_Model_Abstract { public function fetchUrlVignette() { - $service = new Class_WebService_Vignette(); - - if ($this->shouldRetryUrlVignette()) - return $service->getAjaxUrl($this); - - $url = $this->getUrlVignette(); - - return $service->isNoData($url) - ? $this->_rawThumbnailUrl() - : $url; + return (new Class_Notice_Thumbnail())->fetchUrlVignette($this); } public function fetchUrlLocalVignette() { - $service = new Class_WebService_Vignette(); - - if ($this->shouldRetryUrlVignette()) - $service->updateUrlsFromCacheServer($this); - - $url = $this->getUrlVignette(); - - return $service->isNoData($url) - ? $this->_rawThumbnailUrl() - : $service->writeImageCache($this, $url); - } - - - public function shouldRetryUrlVignette() { - $service = new Class_WebService_Vignette(); - return !$this->getUrlVignette() - || ($service->isNoData($this->getUrlVignette()) - && $service->isThirdParty($this)); - } - - - protected function _rawThumbnailUrl() { - return Class_Url::assemble(['controller' => 'recherche', - 'action' => 'raw-thumbnail', - 'id' => $this->getId()]); + return (new Class_Notice_Thumbnail())->fetchUrlLocalVignette($this); } @@ -453,24 +420,7 @@ class Class_Notice extends Storm_Model_Abstract { public function fetchUrlImage() { - $service = new Class_WebService_Vignette(); - - if ($this->shouldRetryUrlImage()) - $service->updateUrlsFromCacheServer($this); - - $url = $this->getUrlImage(); - - return $service->isNoData($url) - ? $this->fetchUrlLocalVignette() - : $url; - } - - - public function shouldRetryUrlImage() { - $service = new Class_WebService_Vignette(); - return !$this->getUrlImage() - || ($service->isNoData($this->getUrlImage()) - && $service->isThirdParty($this)); + return (new Class_Notice_Thumbnail())->fetchUrlImage($this); } diff --git a/library/Class/Notice/Thumbnail.php b/library/Class/Notice/Thumbnail.php new file mode 100644 index 0000000000000000000000000000000000000000..20643eedcd7238aad62277687c503adc606bcedd --- /dev/null +++ b/library/Class/Notice/Thumbnail.php @@ -0,0 +1,79 @@ +<?php +/** + * Copyright (c) 2012-2017, 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 Class_Notice_Thumbnail { + protected $_service; + + public function __construct() { + $this->_service = new Class_WebService_Vignette(); + } + + + public function fetchUrlVignette($record) { + if ($this->_shouldRetry($record, $record->getUrlVignette())) + return $this->_service->getAjaxUrl($record); + + $url = $record->getUrlVignette(); + + return $this->_service->isNoData($url) + ? $this->_rawThumbnailUrl($record) + : $url; + } + + + public function fetchUrlLocalVignette($record) { + if ($this->_shouldRetry($record, $record->getUrlVignette())) + $this->_service->updateUrlsFromCacheServer($record); + + $url = $record->getUrlVignette(); + + return $this->_service->isNoData($url) + ? $this->_rawThumbnailUrl($record) + : $this->_service->writeImageCache($record, $url); + } + + + public function fetchUrlImage($record) { + if ($this->_shouldRetry($record, $record->getUrlImage())) + $this->_service->updateUrlsFromCacheServer($record); + + $url = $record->getUrlImage(); + + return $this->_service->isNoData($url) + ? $this->fetchUrlLocalVignette($record) + : $url; + } + + + protected function _rawThumbnailUrl($record) { + return Class_Url::assemble(['controller' => 'recherche', + 'action' => 'raw-thumbnail', + 'id' => $record->getId()]); + } + + + protected function _shouldRetry($record, $url) { + return !$url + || ($this->_service->isNoData($url) + && $this->_service->isThirdParty($record)); + } +}