diff --git a/configuration.php b/configuration.php index b5dd8a3..a8ac348 100644 --- a/configuration.php +++ b/configuration.php @@ -4,7 +4,7 @@ Gestion de la configuration */ -$version = "1.0.17"; +$version = "1.0.18"; // état de la configuration (= valeur par défaut) $configuration = [ diff --git a/modules/mod_wrms.php b/modules/mod_wrms.php index 099c232..246cead 100644 --- a/modules/mod_wrms.php +++ b/modules/mod_wrms.php @@ -4,9 +4,17 @@ Module pour wrms (non classification) */ +// retourne le nom du modèle Bioref associé à GBIF (théoriquement peut dépendre du rang) +function wrms_bioref($rang=null) { + return "WRMS"; +} +// retourne le nom de la classification pour Taxobox début +function wrms_classif() { + return "WoRMS"; +} // déclaration du module function m_wrms_init() { - return declare_module("wrms", false, true, true); + return declare_module("wrms", true, true, true, 996); } // conversion rang WRMS / WP @@ -81,19 +89,114 @@ function wrms_rang($rang) { } } +// liste des "règnes" et traduction selon WP +$wrms_regnes = [ + 'Animalia' => 'animal', + 'Archaea' => 'archaea', + 'Bacteria' => 'bactérie', + 'Fungi' => 'champignon', + 'Plantae' => 'végétal', + 'Viruses' => 'virus', + 'Incertae sedis' => 'neutre', + 'Protozoa' => 'protiste', + 'Chromista' => 'algue', +]; +function wrms_charte($nom) { + global $wrms_regnes; + if (!isset($wrms_regnes[$nom])) { + return 'neutre'; + } + return $wrms_regnes[$nom]; +} + // extraction des infos de la page WRMS function wrms_extraire($page, $id) { $out = []; $out['id'] = $id; $tbl = explode("\n", $page); - $full_name = false; foreach($tbl as $idx => $ligne) { $ligne = trim($ligne); + // nom complet (parfois nécessaire) + if (strpos($ligne, 'Accepted Name<') !== false) { + $tmp = explode('"', $tbl[$idx+5]); + if (isset($tmp[1])) { + $x = explode("=", $tmp[1]); + if (isset($x[2])) { + $out['cible'] = $x[2]; + } + } + $out['rang'] = wrms_rang(trim($tbl[$idx+5])); + continue; + } + // auteur + if (strpos($ligne, 'div id="Authority') !== false) { + $out['auteur'] = trim($tbl[$idx+4]); + } // rang if (strpos($ligne, '
Status<') !== false) { + $out['statut'] = trim(strip_tags($tbl[$idx+5])); + } + // basionyme + if (strpos($ligne, '>Orig. name<') !== false) { + $x = explode('"', $tbl[$idx+5]); + if (isset($x[1])) { + $y = explode("=", $x[1]); + if (isset($y[2])) { + $out['basionyme'] = $y[2]; + } + } + //$out['basionyme'] = trim(strip_tags($tbl[$idx+5])); + } + // vernaculaires + if (strpos($ligne, 'aphia_ct_vernacular_') !== false) { + if (strpos($ligne, '>French<') !== false) { + $x = trim(strip_tags($tbl[$idx+1])); + if (!empty($x)) { + if (!isset($out['vernaculaire'])) { + $out['vernaculaire'] = []; + } + $out['vernaculaire'][] = $x; + } + } + } + // synonymes + if (strpos($ligne, '>Synonymised names<') !== false) { + $i = $idx + 4; + unset($out['synonymes']); + while(true) { + if (!isset($tbl[$i])) { + break; + } + $tmp = trim($tbl[$i]); + if (strpos($tmp, 'class="aphia_core_line_spacer') !== false) { + break; + } + if (strpos($tmp, 'aphia_ct_tu_') === false) { + $i++; + continue; + } + $x = explode('"', $tmp); + if (isset($x[5])) { + $y = explode(":", $x[5]); + if (isset($y[4])) { + if (!isset($out['synonymes'])) { + $out['synonymes'] = []; + } + $out['synonymes'][] = $y[4]; + } + } + $i++; + } + } // classification if (strpos($ligne, 'for="Classification">') !== false) { $out['classification'] = []; @@ -116,27 +219,57 @@ function wrms_extraire($page, $id) { $blob['nom'] = $ns; $blob['rang'] = wrms_rang($p2); if ($blob['rang'] != 'royaume') { - // on ne traite pas ce rang $out['classification'][] = $blob; + } else { + // on ne traite pas ce rang mais il sert pour la charte + $out['charte'] = wrms_charte($ns); } $der_nom = $ns; $der_rang = $p2; $i++; } - // récupération de l'auteur - if ($full_name) { - $tmp = strip_tags($full_name); - $auteur = str_replace($der_nom, '', $tmp); - $out['auteur'] = trim($auteur); - $out['nom'] = trim($der_nom); - } // on vire le dernier (qui est égal au taxon) - array_pop($out['classification']); + $tmp = array_pop($out['classification']); + // on récupère le nom du taxon + $out['nom'] = $tmp['nom']; } - // nom + auteur - if (strpos($ligne, '/", "", $tmp); + $x = preg_replace("/<\/span>.*$/", "", $x); + $x = str_replace("<em>", "", $x); + $x = str_replace("</em>", "", $x); + // on cherche un éventuel lien vers la ressource + $tbl = explode('href=', $tmp); + foreach($tbl as $el) { + if (strpos($el, 'http') === false) { + continue; + } + $z = substr($el, 0, 1); + $y = explode($z, $el); + if (isset($y[1])) { + if (strpos($y[1], "aphia") === false) { + $x .= " [" . $y[1] . " lire]"; + } + } + } + $out['description'] = $x; + $i++; + } } // sous-taxons if (strpos($ligne, '>Direct children') !== false) { @@ -148,9 +281,13 @@ function wrms_extraire($page, $id) { } $blob = []; $tmp = trim($tbl[$i]); - if ($tmp == "") { + if (strpos($tmp, 'class="aphia_core_line_spacer') !== false) { break; } + if (strpos($tmp, 'class="aphia_core_pb-3') === false) { + $i++; + continue; + } $p1 = preg_replace(',Synonymised names') !== false) { - $i = $idx + 5; - $out['synonymes'] = []; - while(true) { - if (!isset($tbl[$i])) { - break; - } - $tmp = trim($tbl[$i]); - if ($tmp == '
') { - break; - } - - $i++; - } + } + if (!isset($out['auteur'])) { + if (isset($out['nom-complet'])) { + $tmp = str_replace($out['nom'], "", $out['nom-complet']); + $out['auteur'] = trim($tmp); } } + // si le basionyme est identique on l'enlève + if ($out['basionyme'] == $id) { + unset($out['basionyme']); + } return $out; } - // récupération des infos. Résultats à stocker dans $struct. Si $classif=TRUE doit // gérer la classification également function m_wrms_infos(&$struct, $classif) { $taxon = $struct['taxon']['nom']; - // on récupère la page de recherche - $url = "http://www.marinespecies.org/aphia.php?p=search"; + // on récupère la page de recherche (cookie) + $url = "https://www.marinespecies.org/aphia.php?p=search"; $ret = get_data($url); // on cherche le taxon - $url = "http://www.marinespecies.org/aphia.php?p=taxlist"; - $post = "searchpar=0&tComp=begins&tName=" . str_replace(" ", "+", $taxon) . + $url = "https://www.marinespecies.org/aphia.php?p=taxlist"; + $post = "searchpar=0&tComp=is&tName=" . str_replace(" ", "+", $taxon) . "&action=search&rSkips=0&adv=0"; - $ret = post_data_header($url, $post); + $header = [ 'Referer: https://www.marinespecies.org/aphia.php?p=search', + 'Sec-Fetch-Dest: document', + 'Sec-Fetch-Mode: navigate', + 'Sec-Fetch-Site: same-origin', + 'Sec-Fetch-User: ?1', + 'TE: trailers', + 'Content-Type: application/x-www-form-urlencoded', + 'Origin: https://www.marinespecies.org', + 'Cookie: vliz_webc=vliz_webc1; limit_marine=0; limit_extant=0', + 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8', + 'Accept-Encoding: gzip, deflate, br', + 'Upgrade-Insecure-Requests: 1']; + $ret = post_data_header($url, $post, $header, false); if ($ret === false) { logs("WRMS: échec de la recherche"); return false; @@ -213,13 +355,14 @@ function m_wrms_infos(&$struct, $classif) { return false; } if (!is_numeric($trouve)) { - logs("WRMS: taxon non trouvé"); + logs("WRMS: taxon non trouvé (2)"); return false; } // on note l'identifiant $blob = []; $blob['id'] = $trouve; // on récupère la page pour avoir les autres infos + $url = "https://www.marinespecies.org/aphia.php?p=taxdetails&id=" . $trouve; $ret = get_data($url); if ($ret === false) { logs("WRMS: échec de récupération de la page d'informations"); @@ -241,33 +384,161 @@ function m_wrms_infos(&$struct, $classif) { $struct['liens']['wrms'] = $blob; return false; } - - $struct['liens']['wrms'] = $res; - // on extrait la classification - if (isset($struct['liens']['wrms']['classification'])) { - $classification = $struct['liens']['wrms']['classification']; - unset($struct['liens']['wrms']['classification']); + + $tmp = []; + if (isset($res['nom'])) { + $tmp['nom'] = $res['nom']; } else { - $classification = false; + $tmp['nom'] = $taxon; } - if (isset($struct['liens']['wrms']['sous-taxons'])) { - $st = $struct['liens']['wrms']['sous-taxons']; - unset($struct['liens']['wrms']['sous-taxons']); + if (isset($res['rang'])) { + $tmp['rang'] = $res['nom']; } else { - $st = false; + if (isset($struct['taxon']['rang'])) { + $tmp['rang'] = $struct['taxon']['rang']; + } + } + if (isset($res['auteur'])) { + $tmp['auteur'] = $res['auteur']; + } else { + if (isset($struct['taxon']['auteur'])) { + $tmp['auteur'] = $struct['taxon']['auteur']; + } + } + if (isset($res['cible'])) { + $tmp['synonyme'] = true; } + $tmp['id'] = $res['id']; + $struct['liens']['wrms'] = $tmp; + + // pas classification : terminé if (!$classif) { return true; } - // on instancie les infos de classification + + // il faut la charte/règne + if (!isset($res['charte'])) { + logs("WRMS: charte/règne non trouvé"); + return false; + } + $struct['regne'] = $res['charte']; + + // partie taxon + $struct['taxon']['nom'] = $res['nom']; + $struct['taxon']['auteur'] = $res['auteur']; + $struct['taxon']['rang'] = $res['rang']; + + // classification : si synonyme on fait le suivi + if (isset($res['cible']) and get_config("suivre-synonymes")) { + // on récupère le nom du synonyme + $url = "https://www.marinespecies.org/aphia.php?p=taxdetails&id=" . $res['cible']; + $ret = get_data($url); + if ($ret === false) { + logs("WRMS: échec de récupération du synonyme"); + return false; + } + // extraction des infos + $res = wrms_extraire($ret, $res['cible']); + if ($res === false) { + logs("WRMS: échec d'analyse du synonyme"); + return false; + } + // on se ré-appelle sur la cible + return(m_wrms_infos($struct, $classif)); + } + + // infos générales $struct['classification'] = 'WRMS'; - $struct['classification-taxobox'] = 'wrms'; - if ($classification) { - $struct['rangs'] = $classification; + $struct['classification-taxobox'] = wrms_classif(); + + if (isset($res['classification'])) { + $struct['rangs'] = array_reverse($res['classification']); + } else { + logs("WRMS: pas de classification trouvée"); + return false; } - if ($st) { - $struct['sous-taxons'] = $st; + + // vernaculaires + if (isset($res['vernaculaire'])) { + $struct['vernaculaire'][wrms_bioref()] = $res['vernaculaire']; } + + // publication originale + if (isset($res['description'])) { + $struct['originale'] = $res['description']; + } + + // basionyme + if (isset($res['basionyme'])) { + $url = "https://www.marinespecies.org/aphia.php?p=taxdetails&id=" . $res['basionyme']; + $ret = get_data($url); + if ($ret === false) { + logs("WRMS: échec de récupération d'information sur le basionyme. Ignoré"); + } else { + $tmp = wrms_extraire($ret, $res['basionyme']); + if ($tmp === false) { + logs("WRMS: échec de récupération d'information sur le basionyme (2). Ignoré"); + } else { + $struct['basionyme']['nom'] = $tmp['nom']; + $struct['basionyme']['auteur'] = $tmp['auteur']; + $struct['basionyme']['source'] = wrms_bioref(); + } + } + } + + // synonymes + if (isset($res['synonymes'])) { + $lst = []; + foreach($res['synonymes'] as $syn) { + $url = "https://www.marinespecies.org/aphia.php?p=taxdetails&id=" . $syn; + $ret = get_data($url); + if ($ret === false) { + logs("WRMS: échec de récupération d'information sur un synonyme. Ignoré"); + } else { + $tmp = wrms_extraire($ret, $syn); + if ($tmp === false) { + logs("WRMS: échec de récupération d'information sur un synonyme (2). Ignoré"); + } else { + $x = []; + $x['nom'] = $tmp['nom']; + $x['auteur'] = $tmp['auteur']; + $x['rang'] = $tmp['rang']; + $lst[] = $x; + } + } + } + $struct['synonymes']['liste'] = $lst; + $struct['synonymes']['source'] = wrms_bioref(); + } + + // sous-taxons + if (isset($res['sous-taxons'])) { + $lst = []; + foreach($res['sous-taxons'] as $syn) { + $url = "https://www.marinespecies.org/aphia.php?p=taxdetails&id=" . $syn; + $ret = get_data($url); + if ($ret === false) { + logs("WRMS: échec de récupération d'information sur un sous-taxon. Ignoré"); + } else { + $tmp = wrms_extraire($ret, $syn); + if ($tmp === false) { + logs("WRMS: échec de récupération d'information sur un sous-taxon (2). Ignoré"); + } else { + $x = []; + $x['nom'] = $tmp['nom']; + $x['auteur'] = $tmp['auteur']; + $x['rang'] = $tmp['rang']; + $lst[] = $x; + } + } + } + $struct['sous-taxons']['liste'] = $lst; + $struct['sous-taxons']['source'] = wrms_bioref(); + } + + /* à faire : + sous-taxons (idem) + */ return true; } diff --git a/rendu.php b/rendu.php index 8463cf3..745d9cd 100644 --- a/rendu.php +++ b/rendu.php @@ -328,6 +328,27 @@ function rendu_distribution($struct) { return $resu; } +// rendu publication originale +function rendu_originale($struct) { + if (!isset($struct['originale'])) { + return ""; + } + + if (is_array($struct['originale']) and (count($struct['originale']) > 1)) { + $resu = "\n== Publications originales ==\n"; + } else { + $resu = "\n== Publication originale ==\n"; + } + if (is_array($struct['originale'])) { + foreach($struct['originale'] as $pub) { + $resu .= "* " . $pub . "\n"; + } + } else { + $resu .= "* " . $struct['originale'] . "\n"; + } + return $resu; +} + // rendu de la zone voir aussi function rendu_voir_aussi($struct) { global $gauto; @@ -446,6 +467,8 @@ function rendu($struct) { $ret .= rendu_inf($struct); // informations additionnelles $ret .= rendu_supp($struct); + // publication originale + $ret .= rendu_originale($struct); // partie voir aussi $ret .= rendu_voir_aussi($struct); // partie finale