From 879a0fd4f41bddbc21bafe87049daa5013887061 Mon Sep 17 00:00:00 2001 From: chrode Date: Wed, 24 Jul 2024 20:37:12 +0200 Subject: [PATCH] More robust calling of file_get_contents --- Classes/Controller/BibliografieController.php | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Classes/Controller/BibliografieController.php b/Classes/Controller/BibliografieController.php index 2faf673..8913b8a 100644 --- a/Classes/Controller/BibliografieController.php +++ b/Classes/Controller/BibliografieController.php @@ -225,20 +225,30 @@ public function getApiResults($action='items') : array public function request($url, $requestCount=0) { - $json = file_get_contents($url); - $data = json_decode($json, true); - $this->reIndexArray($data); - - if ($requestCount==0 && count($data)==$this->settings['zotero']['limit']) { - // load only one page more - $url .= '&start='.$this->settings['zotero']['limit']; - $dataNext = $this->request($url, 1); - $data = array_merge($data, $dataNext); + $data = '', + + if ($this->settings['debug'] == true) { + DebugUtility::debug($url, 'Debug: ' . __FILE__ . ' in Line: ' . __LINE__ . ' Function: '. __FUNCTION__); + } + + $json = @file_get_contents($url); + + if($json !== FALSE) { + $data = json_decode($json, true); + $this->reIndexArray($data); + + if ($requestCount==0 && count($data)==$this->settings['zotero']['limit']) { + // load only one page more + $url .= '&start='.$this->settings['zotero']['limit']; + $dataNext = $this->request($url, 1); + $data = array_merge($data, $dataNext); + } } if ($this->settings['debug'] == true) { DebugUtility::debug($data, 'Debug: ' . __FILE__ . ' in Line: ' . __LINE__ . ' Function: '. __FUNCTION__); } + return $data; }