| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * This file is part of dispositif/wikibot application (@github) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * 2019/2020 © Philippe M. <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * For the full copyright and MIT license information, please view the license file. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | namespace App\Domain\Publisher; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | class OpenGraphMapper implements MapperInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     use ExternConverterTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * Mapping from Open Graph and Dublin Core meta tags | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * https://ogp.me/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * https://www.dublincore.org/schemas/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * todo extract DC ? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @param array $meta | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @throws Exception | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     public function process($meta): array | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |         return [ | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |             'DATA-TYPE' => 'Open Graph/Dublin Core', | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |             'DATA-ARTICLE' => $this->isAnArticle($meta['og:type'] ?? ''), | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |             'site' => $this->clean($meta['og:site_name'] ?? null), | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |             'titre' => $this->clean($meta['og:title'] ?? $meta['twitter:title'] ?? $meta['DC.title'] ?? null), | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |             'url' => $meta['og:url'] ?? $meta['URL'] ?? null, | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |             'langue' => $this->convertLangue( | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |                 $meta['og:locale'] ?? $meta['DC.language'] ?? $meta['citation_language'] ?? null | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |             ), | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |             'consulté le' => date('d-m-Y'), | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |             'auteur' => $this->clean( | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |                 $meta['og:article:author'] ?? $meta['article:author'] ?? $meta['citation_author'] ?? null | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |             ), | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |             'format' => $this->convertOGtype2format($meta['og:type'] ?? null), | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |             'date' => $this->convertDate( | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |                 $meta['og:article:published_time'] ?? | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |                 $meta['article:published_time'] ?? $meta['DC.date'] ?? $meta['citation_date'] ?? null | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |             ), | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             'url-access' => $this->convertURLaccess($meta), | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |             // DUBLIN CORE ONLY | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |             'périodique' => $this->clean($meta['DC.isPartOf'] ?? $meta['citation_journal_title'] ?? null), | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |             'et al.' => $this->authorsEtAl( | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |                 $meta['citation_authors'] ?? $meta['DC.Contributor'] ?? null, | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |                 true | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |             ), | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |             'auteur1' => $this->wikifyPressAgency( | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |                 $this->clean( | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |                     $this->authorsEtAl( | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |                         $meta['citation_authors'] ?? $meta['DC.Contributor'] ?? null | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |                     ) | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |                 ) | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |             ), | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |             'volume' => $meta['citation_volume'] ?? null, | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |             'numéro' => $meta['citation_issue'] ?? null, | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |             'page' => $this->convertDCpage($meta), | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |             'doi' => $meta['citation_doi'] ?? null, | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |             'éditeur' => $meta['DC.publisher'] ?? null, // Persée dégeulasse todo? | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |             'pmid' => $meta['citation_pmid'] ?? null, | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |             'issn' => $meta["citation_issn"] ?? null, | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |             'isbn' => $meta["citation_isbn"] ?? null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             // "prism.eIssn" => "2262-7197" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |  |