1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of dispositif/wikibot application (@github) |
4
|
|
|
* 2019-2023 © Philippe M./Irønie <[email protected]> |
5
|
|
|
* For the full copyright and MIT license information, view the license file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace App\Domain\ExternLink; |
11
|
|
|
|
12
|
|
|
use App\Domain\Models\Wiki\ArticleTemplate; |
13
|
|
|
use App\Domain\Models\Wiki\LienWebTemplate; |
14
|
|
|
use App\Domain\Models\Wiki\OuvrageTemplate; |
15
|
|
|
use App\Domain\Utils\WikiTextUtil; |
16
|
|
|
use Symfony\Component\Yaml\Yaml; |
17
|
|
|
|
18
|
|
|
trait PublisherLogicTrait |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* todo extract Infra getcont form file + inject |
22
|
|
|
*/ |
23
|
|
|
protected function importConfigAndData(): void |
24
|
|
|
{ |
25
|
|
|
// todo REFAC DataObject[] |
26
|
|
|
$this->config = Yaml::parseFile(self::CONFIG_PRESSE); |
|
|
|
|
27
|
|
|
$skipFromFile = file( |
28
|
|
|
self::SKIP_DOMAIN_FILENAME, |
|
|
|
|
29
|
|
|
FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES |
30
|
|
|
); |
31
|
|
|
$this->skip_domain = $skipFromFile ?: []; |
|
|
|
|
32
|
|
|
|
33
|
|
|
$this->publisherData['newspaper'] = json_decode(file_get_contents(self::CONFIG_NEWSPAPER_JSON), true, 512, JSON_THROW_ON_ERROR); |
|
|
|
|
34
|
|
|
$this->publisherData['scientific domain'] = json_decode( |
35
|
|
|
file_get_contents(self::CONFIG_SCIENTIFIC_JSON), |
|
|
|
|
36
|
|
|
true, |
37
|
|
|
512, |
38
|
|
|
JSON_THROW_ON_ERROR |
39
|
|
|
); |
40
|
|
|
$this->publisherData['scientific wiki'] = json_decode( |
41
|
|
|
file_get_contents(self::CONFIG_SCIENTIFIC_WIKI_JSON), |
|
|
|
|
42
|
|
|
true, |
43
|
|
|
512, |
44
|
|
|
JSON_THROW_ON_ERROR |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* TODO rename/move Postprocess data site/périodique |
50
|
|
|
* Logique : remplacement titre périodique ou nom du site |
51
|
|
|
* |
52
|
|
|
* @param array $mapData |
53
|
|
|
* @param $template |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
protected function replaceSitenameByConfig(array $mapData, $template): array |
58
|
|
|
{ |
59
|
|
|
// from wikidata URL of newspapers |
60
|
|
|
if (!empty($this->publisherData['newspaper'][$this->registrableDomain])) { |
61
|
|
|
$frwiki = $this->publisherData['newspaper'][$this->registrableDomain]['frwiki']; |
62
|
|
|
$label = $this->publisherData['newspaper'][$this->registrableDomain]['fr']; |
63
|
|
|
if (isset($mapData['site']) || $template instanceof LienWebTemplate) { |
64
|
|
|
$mapData['site'] = WikiTextUtil::wikilink($label, $frwiki); |
65
|
|
|
} |
66
|
|
|
if (isset($mapData['périodique']) || $template instanceof ArticleTemplate) { |
67
|
|
|
$mapData['périodique'] = WikiTextUtil::wikilink($label, $frwiki); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
// from wikidata of scientific journals |
72
|
|
|
if (isset($mapData['périodique']) && isset($this->publisherData['scientific wiki'][$mapData['périodique']])) { |
73
|
|
|
$mapData['périodique'] = WikiTextUtil::wikilink( |
74
|
|
|
$mapData['périodique'], |
75
|
|
|
$this->publisherData['scientific wiki'][$mapData['périodique']] |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
// from YAML config |
80
|
|
|
if (!empty($this->config[$this->registrableDomain]['site']) && $template instanceof LienWebTemplate) { |
81
|
|
|
$mapData['site'] = $this->config[$this->registrableDomain]['site']; |
82
|
|
|
} |
83
|
|
|
if (!empty($this->config[$this->registrableDomain]['périodique']) |
84
|
|
|
&& (!empty($mapData['périodique']) |
85
|
|
|
|| $template instanceof OuvrageTemplate) |
86
|
|
|
) { |
87
|
|
|
$mapData['périodique'] = $this->config[$this->registrableDomain]['périodique']; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $mapData; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
protected function isScientificDomain(): bool |
94
|
|
|
{ |
95
|
|
|
if (isset($this->publisherData['scientific domain'][$this->registrableDomain])) { |
96
|
|
|
return true; |
97
|
|
|
} |
98
|
|
|
return strpos('.revues.org', $this->registrableDomain) > 0; |
99
|
|
|
} |
100
|
|
|
} |