From 3d27bf9d5726f698bcd0bde33a44dddbbff2cb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=ADvia=20Gouv=C3=AAa?= Date: Mon, 25 Dec 2023 18:48:22 -0300 Subject: [PATCH] =?UTF-8?q?Ajusta=20grava=C3=A7=C3=A3o=20de=20t=C3=ADtulo?= =?UTF-8?q?=20para=20contemplar=20multi-idiomas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Parser/Article.php | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/Parser/Article.php b/src/Parser/Article.php index 32ca6d0..7ec31eb 100644 --- a/src/Parser/Article.php +++ b/src/Parser/Article.php @@ -96,17 +96,39 @@ private function incrementMetadata(Crawler $crawler, string $currentLang) ]); } } + $nodes = $crawler->filter('meta[name="citation_title"]'); + if ($nodes->count()) { + $this->setTitle($nodes->attr('content'), $currentLang); + $titlesExtra = $crawler->filter('h2[class="article-title"]')->each(function ($node, $i) {return $node->text();}); - if (!$this->getTitle($currentLang)) { - $nodes = $crawler->filter('meta[name="citation_title"]'); - if ($nodes->count()) { - $this->setTitle($nodes->attr('content'), $currentLang); - } else { - $this->logger->error('Without Title', [ - 'method' => 'ScieloClient::getArticleMetadata', - 'directory' => $this->getBasedir() - ]); + if($currentLang == "pt_BR"){ + $langs = ["en_US", "es_ES"]; + } + if($currentLang == "en_US"){ + if(count($titlesExtra) > 1){ + $langs = ["pt_BR", "es_ES"]; + }else{ + $langs = ["pt_BR"]; + } + } + if($currentLang == "es_ES"){ + if(count($titlesExtra) > 1){ + $langs = ["en_US", "pt_BR"]; + }else{ + $langs = ["pt_BR"]; + } } + if($titlesExtra){ + foreach($titlesExtra as $key => $value){ + $this->setTitle($value, $langs[$key]); + next($langs); + } + } + } else { + $this->logger->error('Without Title', [ + 'method' => 'ScieloClient::getArticleMetadata', + 'directory' => $this->getBasedir() + ]); } if (!$this->getPublished()) { $nodes = $crawler->filter('meta[name="citation_publication_date"]');