@@ -4,118 +4,118 @@ |
||
| 4 | 4 | |
| 5 | 5 | return [ |
| 6 | 6 | |
| 7 | - // A |
|
| 8 | - 'accueil_site' => 'Accueil', |
|
| 9 | - 'article' => 'Article', |
|
| 10 | - 'articles' => 'Articles', |
|
| 11 | - 'articles_auteur' => 'Articles de cet auteur', |
|
| 12 | - 'articles_populaires' => 'Articles les plus populaires', |
|
| 13 | - 'articles_rubrique' => 'Articles de cette rubrique', |
|
| 14 | - 'aucun_article' => 'Il n’y a pas d’article à cette adresse', |
|
| 15 | - 'aucun_auteur' => 'Il n’y a pas d’auteur à cette adresse', |
|
| 16 | - 'aucun_site' => 'Il n’y a pas de site à cette adresse', |
|
| 17 | - 'aucune_breve' => 'Il n’y a pas de brève à cette adresse', |
|
| 18 | - 'aucune_rubrique' => 'Il n’y a pas de rubrique à cette adresse', |
|
| 19 | - 'auteur' => 'Auteur', |
|
| 20 | - 'autres' => 'Autres', |
|
| 21 | - 'autres_breves' => 'Autres brèves', |
|
| 22 | - 'autres_groupes_mots_clefs' => 'Autres groupes de mots-clés', |
|
| 23 | - 'autres_sites' => 'Autres sites', |
|
| 24 | - |
|
| 25 | - // B |
|
| 26 | - 'bonjour' => 'Bonjour', |
|
| 27 | - |
|
| 28 | - // C |
|
| 29 | - 'commenter_site' => 'Commenter ce site', |
|
| 30 | - 'contact' => 'Contact', |
|
| 31 | - 'copie_document_impossible' => 'Impossible de copier le document', |
|
| 32 | - |
|
| 33 | - // D |
|
| 34 | - 'date' => 'Date', |
|
| 35 | - 'dernier_ajout' => 'Dernier ajout', |
|
| 36 | - 'dernieres_breves' => 'Dernières brèves', |
|
| 37 | - 'derniers_articles' => 'Derniers articles', |
|
| 38 | - 'derniers_commentaires' => 'Derniers commentaires', |
|
| 39 | - 'derniers_messages_forum' => 'Derniers messages publiés dans les forums', |
|
| 40 | - |
|
| 41 | - // E |
|
| 42 | - 'edition_mode_texte' => 'Édition en mode texte de', |
|
| 43 | - 'en_reponse' => 'En réponse à :', |
|
| 44 | - 'en_resume' => 'En résumé', |
|
| 45 | - 'envoyer_message' => 'Envoyer un message', |
|
| 46 | - 'espace_prive' => 'Espace privé', |
|
| 47 | - |
|
| 48 | - // F |
|
| 49 | - 'formats_acceptes' => 'Formats acceptés : @formats@.', |
|
| 50 | - |
|
| 51 | - // H |
|
| 52 | - 'hierarchie_site' => 'Hiérarchie du site', |
|
| 53 | - |
|
| 54 | - // J |
|
| 55 | - 'jours' => 'jours', |
|
| 56 | - |
|
| 57 | - // L |
|
| 58 | - 'lien_connecter' => 'Se connecter', |
|
| 59 | - |
|
| 60 | - // M |
|
| 61 | - 'meme_auteur' => 'Du même auteur', |
|
| 62 | - 'meme_rubrique' => 'Dans la même rubrique', |
|
| 63 | - 'memes_auteurs' => 'Des mêmes auteurs', |
|
| 64 | - 'message' => 'Message', |
|
| 65 | - 'messages_forum' => 'Messages', |
|
| 66 | - 'messages_recents' => 'Messages de forums les plus récents', |
|
| 67 | - 'mots_clef' => 'Mot-clé', |
|
| 68 | - 'mots_clefs' => 'Mots-clés', |
|
| 69 | - 'mots_clefs_meme_groupe' => 'Mots-clés dans le même groupe', |
|
| 70 | - |
|
| 71 | - // N |
|
| 72 | - 'navigation' => 'Navigation', |
|
| 73 | - 'nom' => 'Nom', |
|
| 74 | - 'nouveautes' => 'Les nouveautés', |
|
| 75 | - 'nouveautes_web' => 'Nouveautés sur le Web', |
|
| 76 | - 'nouveaux_articles' => 'Nouveaux articles', |
|
| 77 | - 'nouvelles_breves' => 'Nouvelles brèves', |
|
| 78 | - |
|
| 79 | - // P |
|
| 80 | - 'page_precedente' => 'page précédente', |
|
| 81 | - 'page_suivante' => 'page suivante', |
|
| 82 | - 'par_auteur' => 'par ', |
|
| 83 | - 'participer_site' => 'Vous pouvez participer à la vie de ce site et proposer vos propres articles en vous inscrivant ci-dessous. Vous recevrez immédiatement un email vous indiquant vos codes d’accès à l’espace privé du site.', |
|
| 84 | - 'plan_site' => 'Plan du site', |
|
| 85 | - 'popularite' => 'Popularité', |
|
| 86 | - 'poster_message' => 'Poster un message', |
|
| 87 | - 'proposer_site' => 'Vous pouvez proposer un site à ajouter dans cette rubrique :', |
|
| 88 | - |
|
| 89 | - // R |
|
| 90 | - 'repondre_article' => 'Répondre à cet article', |
|
| 91 | - 'repondre_breve' => 'Répondre à cette brève', |
|
| 92 | - 'resultats_recherche' => 'Résultats de la recherche', |
|
| 93 | - 'retour_debut_forums' => 'Retour au début des forums', |
|
| 94 | - 'rss_abonnement' => 'Copiez l’URL suivante dans votre agrégateur :', |
|
| 95 | - 'rss_abonnement_titre' => 'S’abonner', |
|
| 96 | - 'rss_abonnement_titre_page' => 'S’abonner à', |
|
| 97 | - 'rss_explication' => 'Un fil RSS recueille les informations de mise à jour d’un site. Il fournit le contenu des billets ou des commentaires ou un extrait de ceux-ci, ainsi qu’un lien vers les versions complètes et quelques autres informations. Ce fil a pour vocation d’être lu par un agrégateur RSS.', |
|
| 98 | - 'rss_explication_titre' => 'Qu’est-ce qu’un flux RSS ?', |
|
| 99 | - 'rubrique' => 'Rubrique', |
|
| 100 | - 'rubriques' => 'Rubriques', |
|
| 101 | - |
|
| 102 | - // S |
|
| 103 | - 'signatures_petition' => 'Signatures', |
|
| 104 | - 'site_realise_avec_spip' => 'Site réalisé avec SPIP', |
|
| 105 | - 'sites_web' => 'Sites Web', |
|
| 106 | - 'sous_rubriques' => 'Sous-rubriques', |
|
| 107 | - 'spam' => 'Spam', |
|
| 108 | - 'suite' => 'suite', |
|
| 109 | - 'sur_web' => 'Sur le Web', |
|
| 110 | - 'syndiquer_rubrique' => 'Syndiquer cette rubrique', |
|
| 111 | - 'syndiquer_site' => 'Syndiquer tout le site', |
|
| 112 | - |
|
| 113 | - // T |
|
| 114 | - 'texte_lettre_information' => 'Voici la lettre d’information du site', |
|
| 115 | - 'texte_lettre_information_2' => 'Cette lettre recense les nouveautés publiées depuis', |
|
| 116 | - |
|
| 117 | - // V |
|
| 118 | - 'ver_imprimer' => 'Version à imprimer', |
|
| 119 | - 'voir_en_ligne' => 'Voir en ligne', |
|
| 120 | - 'voir_squelette' => 'voir le squelette de cette page', |
|
| 7 | + // A |
|
| 8 | + 'accueil_site' => 'Accueil', |
|
| 9 | + 'article' => 'Article', |
|
| 10 | + 'articles' => 'Articles', |
|
| 11 | + 'articles_auteur' => 'Articles de cet auteur', |
|
| 12 | + 'articles_populaires' => 'Articles les plus populaires', |
|
| 13 | + 'articles_rubrique' => 'Articles de cette rubrique', |
|
| 14 | + 'aucun_article' => 'Il n’y a pas d’article à cette adresse', |
|
| 15 | + 'aucun_auteur' => 'Il n’y a pas d’auteur à cette adresse', |
|
| 16 | + 'aucun_site' => 'Il n’y a pas de site à cette adresse', |
|
| 17 | + 'aucune_breve' => 'Il n’y a pas de brève à cette adresse', |
|
| 18 | + 'aucune_rubrique' => 'Il n’y a pas de rubrique à cette adresse', |
|
| 19 | + 'auteur' => 'Auteur', |
|
| 20 | + 'autres' => 'Autres', |
|
| 21 | + 'autres_breves' => 'Autres brèves', |
|
| 22 | + 'autres_groupes_mots_clefs' => 'Autres groupes de mots-clés', |
|
| 23 | + 'autres_sites' => 'Autres sites', |
|
| 24 | + |
|
| 25 | + // B |
|
| 26 | + 'bonjour' => 'Bonjour', |
|
| 27 | + |
|
| 28 | + // C |
|
| 29 | + 'commenter_site' => 'Commenter ce site', |
|
| 30 | + 'contact' => 'Contact', |
|
| 31 | + 'copie_document_impossible' => 'Impossible de copier le document', |
|
| 32 | + |
|
| 33 | + // D |
|
| 34 | + 'date' => 'Date', |
|
| 35 | + 'dernier_ajout' => 'Dernier ajout', |
|
| 36 | + 'dernieres_breves' => 'Dernières brèves', |
|
| 37 | + 'derniers_articles' => 'Derniers articles', |
|
| 38 | + 'derniers_commentaires' => 'Derniers commentaires', |
|
| 39 | + 'derniers_messages_forum' => 'Derniers messages publiés dans les forums', |
|
| 40 | + |
|
| 41 | + // E |
|
| 42 | + 'edition_mode_texte' => 'Édition en mode texte de', |
|
| 43 | + 'en_reponse' => 'En réponse à :', |
|
| 44 | + 'en_resume' => 'En résumé', |
|
| 45 | + 'envoyer_message' => 'Envoyer un message', |
|
| 46 | + 'espace_prive' => 'Espace privé', |
|
| 47 | + |
|
| 48 | + // F |
|
| 49 | + 'formats_acceptes' => 'Formats acceptés : @formats@.', |
|
| 50 | + |
|
| 51 | + // H |
|
| 52 | + 'hierarchie_site' => 'Hiérarchie du site', |
|
| 53 | + |
|
| 54 | + // J |
|
| 55 | + 'jours' => 'jours', |
|
| 56 | + |
|
| 57 | + // L |
|
| 58 | + 'lien_connecter' => 'Se connecter', |
|
| 59 | + |
|
| 60 | + // M |
|
| 61 | + 'meme_auteur' => 'Du même auteur', |
|
| 62 | + 'meme_rubrique' => 'Dans la même rubrique', |
|
| 63 | + 'memes_auteurs' => 'Des mêmes auteurs', |
|
| 64 | + 'message' => 'Message', |
|
| 65 | + 'messages_forum' => 'Messages', |
|
| 66 | + 'messages_recents' => 'Messages de forums les plus récents', |
|
| 67 | + 'mots_clef' => 'Mot-clé', |
|
| 68 | + 'mots_clefs' => 'Mots-clés', |
|
| 69 | + 'mots_clefs_meme_groupe' => 'Mots-clés dans le même groupe', |
|
| 70 | + |
|
| 71 | + // N |
|
| 72 | + 'navigation' => 'Navigation', |
|
| 73 | + 'nom' => 'Nom', |
|
| 74 | + 'nouveautes' => 'Les nouveautés', |
|
| 75 | + 'nouveautes_web' => 'Nouveautés sur le Web', |
|
| 76 | + 'nouveaux_articles' => 'Nouveaux articles', |
|
| 77 | + 'nouvelles_breves' => 'Nouvelles brèves', |
|
| 78 | + |
|
| 79 | + // P |
|
| 80 | + 'page_precedente' => 'page précédente', |
|
| 81 | + 'page_suivante' => 'page suivante', |
|
| 82 | + 'par_auteur' => 'par ', |
|
| 83 | + 'participer_site' => 'Vous pouvez participer à la vie de ce site et proposer vos propres articles en vous inscrivant ci-dessous. Vous recevrez immédiatement un email vous indiquant vos codes d’accès à l’espace privé du site.', |
|
| 84 | + 'plan_site' => 'Plan du site', |
|
| 85 | + 'popularite' => 'Popularité', |
|
| 86 | + 'poster_message' => 'Poster un message', |
|
| 87 | + 'proposer_site' => 'Vous pouvez proposer un site à ajouter dans cette rubrique :', |
|
| 88 | + |
|
| 89 | + // R |
|
| 90 | + 'repondre_article' => 'Répondre à cet article', |
|
| 91 | + 'repondre_breve' => 'Répondre à cette brève', |
|
| 92 | + 'resultats_recherche' => 'Résultats de la recherche', |
|
| 93 | + 'retour_debut_forums' => 'Retour au début des forums', |
|
| 94 | + 'rss_abonnement' => 'Copiez l’URL suivante dans votre agrégateur :', |
|
| 95 | + 'rss_abonnement_titre' => 'S’abonner', |
|
| 96 | + 'rss_abonnement_titre_page' => 'S’abonner à', |
|
| 97 | + 'rss_explication' => 'Un fil RSS recueille les informations de mise à jour d’un site. Il fournit le contenu des billets ou des commentaires ou un extrait de ceux-ci, ainsi qu’un lien vers les versions complètes et quelques autres informations. Ce fil a pour vocation d’être lu par un agrégateur RSS.', |
|
| 98 | + 'rss_explication_titre' => 'Qu’est-ce qu’un flux RSS ?', |
|
| 99 | + 'rubrique' => 'Rubrique', |
|
| 100 | + 'rubriques' => 'Rubriques', |
|
| 101 | + |
|
| 102 | + // S |
|
| 103 | + 'signatures_petition' => 'Signatures', |
|
| 104 | + 'site_realise_avec_spip' => 'Site réalisé avec SPIP', |
|
| 105 | + 'sites_web' => 'Sites Web', |
|
| 106 | + 'sous_rubriques' => 'Sous-rubriques', |
|
| 107 | + 'spam' => 'Spam', |
|
| 108 | + 'suite' => 'suite', |
|
| 109 | + 'sur_web' => 'Sur le Web', |
|
| 110 | + 'syndiquer_rubrique' => 'Syndiquer cette rubrique', |
|
| 111 | + 'syndiquer_site' => 'Syndiquer tout le site', |
|
| 112 | + |
|
| 113 | + // T |
|
| 114 | + 'texte_lettre_information' => 'Voici la lettre d’information du site', |
|
| 115 | + 'texte_lettre_information_2' => 'Cette lettre recense les nouveautés publiées depuis', |
|
| 116 | + |
|
| 117 | + // V |
|
| 118 | + 'ver_imprimer' => 'Version à imprimer', |
|
| 119 | + 'voir_en_ligne' => 'Voir en ligne', |
|
| 120 | + 'voir_squelette' => 'voir le squelette de cette page', |
|
| 121 | 121 | ]; |
@@ -562,11 +562,9 @@ discard block |
||
| 562 | 562 | if (!isset($msg[$p])) { |
| 563 | 563 | if (isset($resume['erreur']) && $resume['erreur']) { |
| 564 | 564 | $msg[$p] = [$resume['erreur']]; |
| 565 | - } |
|
| 566 | - elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 565 | + } elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 567 | 566 | $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
| 568 | - } |
|
| 569 | - elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 567 | + } elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 570 | 568 | $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
| 571 | 569 | } |
| 572 | 570 | } else { |
@@ -954,8 +952,7 @@ discard block |
||
| 954 | 952 | if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
| 955 | 953 | $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
| 956 | 954 | } |
| 957 | - } |
|
| 958 | - else { |
|
| 955 | + } else { |
|
| 959 | 956 | foreach ($info['chemin'] as $chemin) { |
| 960 | 957 | if ( |
| 961 | 958 | !isset($chemin['version']) |
@@ -1424,8 +1421,7 @@ discard block |
||
| 1424 | 1421 | echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
| 1425 | 1422 | $trace, |
| 1426 | 1423 | "\n"; |
| 1427 | - } |
|
| 1428 | - else { |
|
| 1424 | + } else { |
|
| 1429 | 1425 | include_spip('inc/filtres_boites'); |
| 1430 | 1426 | echo "<div class='install-plugins svp_retour'>" |
| 1431 | 1427 | . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
@@ -1462,8 +1458,7 @@ discard block |
||
| 1462 | 1458 | if (file_exists($nom)) { |
| 1463 | 1459 | if (str_ends_with($nom, '.php')) { |
| 1464 | 1460 | $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
| 1465 | - } |
|
| 1466 | - else { |
|
| 1461 | + } else { |
|
| 1467 | 1462 | $fichier_tmp = $nom . '.tmp'; |
| 1468 | 1463 | } |
| 1469 | 1464 | file_put_contents($fichier_tmp, $contenu); |
@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** l'adresse du repertoire de telechargement et de decompactage des plugins */ |
| 23 | 23 | if (!defined('_DIR_PLUGINS_AUTO')) { |
| 24 | - define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 24 | + define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins. |
@@ -46,27 +46,27 @@ discard block |
||
| 46 | 46 | * @return array |
| 47 | 47 | **/ |
| 48 | 48 | function liste_plugin_files($dir_plugins = null) { |
| 49 | - static $plugin_files = []; |
|
| 50 | - if (is_null($dir_plugins)) { |
|
| 51 | - $dir_plugins = _DIR_PLUGINS; |
|
| 52 | - } |
|
| 53 | - if ( |
|
| 54 | - !isset($plugin_files[$dir_plugins]) |
|
| 55 | - || (is_countable($plugin_files[$dir_plugins]) ? count($plugin_files[$dir_plugins]) : 0) == 0 |
|
| 56 | - ) { |
|
| 57 | - $plugin_files[$dir_plugins] = []; |
|
| 58 | - foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 59 | - $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - sort($plugin_files[$dir_plugins]); |
|
| 63 | - // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 64 | - // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 65 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 66 | - $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - return $plugin_files[$dir_plugins]; |
|
| 49 | + static $plugin_files = []; |
|
| 50 | + if (is_null($dir_plugins)) { |
|
| 51 | + $dir_plugins = _DIR_PLUGINS; |
|
| 52 | + } |
|
| 53 | + if ( |
|
| 54 | + !isset($plugin_files[$dir_plugins]) |
|
| 55 | + || (is_countable($plugin_files[$dir_plugins]) ? count($plugin_files[$dir_plugins]) : 0) == 0 |
|
| 56 | + ) { |
|
| 57 | + $plugin_files[$dir_plugins] = []; |
|
| 58 | + foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 59 | + $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + sort($plugin_files[$dir_plugins]); |
|
| 63 | + // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 64 | + // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 65 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 66 | + $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + return $plugin_files[$dir_plugins]; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -82,44 +82,44 @@ discard block |
||
| 82 | 82 | * Liste complète des répeertoires |
| 83 | 83 | **/ |
| 84 | 84 | function fast_find_plugin_dirs($dir, $max_prof = 100) { |
| 85 | - $fichiers = []; |
|
| 86 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 87 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 88 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 89 | - if ($dir == '') { |
|
| 90 | - $dir = '.'; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - if (!is_dir($dir)) { |
|
| 94 | - return $fichiers; |
|
| 95 | - } |
|
| 96 | - if (is_plugin_dir($dir, '')) { |
|
| 97 | - $fichiers[] = $dir; |
|
| 98 | - |
|
| 99 | - return $fichiers; |
|
| 100 | - } |
|
| 101 | - if ($max_prof <= 0) { |
|
| 102 | - return $fichiers; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $subdirs = []; |
|
| 106 | - if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 107 | - while (($f = readdir($d)) !== false) { |
|
| 108 | - if ( |
|
| 109 | - $f[0] != '.' |
|
| 110 | - && is_dir($f = "$dir/$f") |
|
| 111 | - ) { |
|
| 112 | - $subdirs[] = $f; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - closedir($d); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - foreach ($subdirs as $d) { |
|
| 119 | - $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return $fichiers; |
|
| 85 | + $fichiers = []; |
|
| 86 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 87 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 88 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 89 | + if ($dir == '') { |
|
| 90 | + $dir = '.'; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + if (!is_dir($dir)) { |
|
| 94 | + return $fichiers; |
|
| 95 | + } |
|
| 96 | + if (is_plugin_dir($dir, '')) { |
|
| 97 | + $fichiers[] = $dir; |
|
| 98 | + |
|
| 99 | + return $fichiers; |
|
| 100 | + } |
|
| 101 | + if ($max_prof <= 0) { |
|
| 102 | + return $fichiers; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $subdirs = []; |
|
| 106 | + if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 107 | + while (($f = readdir($d)) !== false) { |
|
| 108 | + if ( |
|
| 109 | + $f[0] != '.' |
|
| 110 | + && is_dir($f = "$dir/$f") |
|
| 111 | + ) { |
|
| 112 | + $subdirs[] = $f; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + closedir($d); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + foreach ($subdirs as $d) { |
|
| 119 | + $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return $fichiers; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -140,27 +140,27 @@ discard block |
||
| 140 | 140 | **/ |
| 141 | 141 | function is_plugin_dir($dir, $dir_plugins = null) { |
| 142 | 142 | |
| 143 | - if (is_array($dir)) { |
|
| 144 | - foreach ($dir as $k => $d) { |
|
| 145 | - if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 146 | - unset($dir[$k]); |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $dir; |
|
| 151 | - } |
|
| 152 | - if (is_null($dir_plugins)) { |
|
| 153 | - $dir_plugins = _DIR_PLUGINS; |
|
| 154 | - } |
|
| 155 | - $search = ["$dir_plugins$dir/paquet.xml"]; |
|
| 156 | - |
|
| 157 | - foreach ($search as $s) { |
|
| 158 | - if (file_exists($s)) { |
|
| 159 | - return $dir; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return ''; |
|
| 143 | + if (is_array($dir)) { |
|
| 144 | + foreach ($dir as $k => $d) { |
|
| 145 | + if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 146 | + unset($dir[$k]); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $dir; |
|
| 151 | + } |
|
| 152 | + if (is_null($dir_plugins)) { |
|
| 153 | + $dir_plugins = _DIR_PLUGINS; |
|
| 154 | + } |
|
| 155 | + $search = ["$dir_plugins$dir/paquet.xml"]; |
|
| 156 | + |
|
| 157 | + foreach ($search as $s) { |
|
| 158 | + if (file_exists($s)) { |
|
| 159 | + return $dir; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return ''; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** Regexp d'extraction des informations d'un intervalle de compatibilité */ |
@@ -187,51 +187,51 @@ discard block |
||
| 187 | 187 | **/ |
| 188 | 188 | function plugin_version_compatible($intervalle, $version, $avec_quoi = '') { |
| 189 | 189 | |
| 190 | - if (!strlen($intervalle)) { |
|
| 191 | - return true; |
|
| 192 | - } |
|
| 193 | - if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 194 | - return false; |
|
| 195 | - } |
|
| 196 | - // Extraction des bornes et traitement de * pour la borne sup : |
|
| 197 | - // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 198 | - $minimum = $regs[1]; |
|
| 199 | - $maximum = $regs[2]; |
|
| 200 | - |
|
| 201 | - // si une version SPIP de compatibilité a été définie (dans |
|
| 202 | - // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 203 | - // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 204 | - // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 205 | - // entre plugins) |
|
| 206 | - if (defined('_DEV_VERSION_SPIP_COMPAT') && $avec_quoi == 'spip' && $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 207 | - if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 208 | - return true; |
|
| 209 | - } |
|
| 210 | - // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 211 | - // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $minimum_inc = $intervalle[0] == '['; |
|
| 215 | - $maximum_inc = str_ends_with($intervalle, ']'); |
|
| 216 | - |
|
| 217 | - if (strlen($minimum)) { |
|
| 218 | - if ($minimum_inc && spip_version_compare($version, $minimum, '<')) { |
|
| 219 | - return false; |
|
| 220 | - } |
|
| 221 | - if (!$minimum_inc && spip_version_compare($version, $minimum, '<=')) { |
|
| 222 | - return false; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - if (strlen($maximum)) { |
|
| 226 | - if ($maximum_inc && spip_version_compare($version, $maximum, '>')) { |
|
| 227 | - return false; |
|
| 228 | - } |
|
| 229 | - if (!$maximum_inc && spip_version_compare($version, $maximum, '>=')) { |
|
| 230 | - return false; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - return true; |
|
| 190 | + if (!strlen($intervalle)) { |
|
| 191 | + return true; |
|
| 192 | + } |
|
| 193 | + if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + // Extraction des bornes et traitement de * pour la borne sup : |
|
| 197 | + // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 198 | + $minimum = $regs[1]; |
|
| 199 | + $maximum = $regs[2]; |
|
| 200 | + |
|
| 201 | + // si une version SPIP de compatibilité a été définie (dans |
|
| 202 | + // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 203 | + // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 204 | + // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 205 | + // entre plugins) |
|
| 206 | + if (defined('_DEV_VERSION_SPIP_COMPAT') && $avec_quoi == 'spip' && $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 207 | + if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 208 | + return true; |
|
| 209 | + } |
|
| 210 | + // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 211 | + // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $minimum_inc = $intervalle[0] == '['; |
|
| 215 | + $maximum_inc = str_ends_with($intervalle, ']'); |
|
| 216 | + |
|
| 217 | + if (strlen($minimum)) { |
|
| 218 | + if ($minimum_inc && spip_version_compare($version, $minimum, '<')) { |
|
| 219 | + return false; |
|
| 220 | + } |
|
| 221 | + if (!$minimum_inc && spip_version_compare($version, $minimum, '<=')) { |
|
| 222 | + return false; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + if (strlen($maximum)) { |
|
| 226 | + if ($maximum_inc && spip_version_compare($version, $maximum, '>')) { |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 229 | + if (!$maximum_inc && spip_version_compare($version, $maximum, '>=')) { |
|
| 230 | + return false; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + return true; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -248,62 +248,62 @@ discard block |
||
| 248 | 248 | * @return array |
| 249 | 249 | */ |
| 250 | 250 | function liste_plugin_valides($liste_plug, $force = false) { |
| 251 | - $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 252 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 253 | - $infos = [ |
|
| 254 | - // lister les extensions qui sont automatiquement actives |
|
| 255 | - '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 256 | - '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 257 | - ]; |
|
| 258 | - |
|
| 259 | - // creer une premiere liste non ordonnee mais qui ne retient |
|
| 260 | - // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 261 | - $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 262 | - $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 263 | - $infos['_DIR_RESTREINT']['SPIP']['chemin'] = []; |
|
| 264 | - $liste_non_classee = [ |
|
| 265 | - 'SPIP' => [ |
|
| 266 | - 'nom' => 'SPIP', |
|
| 267 | - 'etat' => 'stable', |
|
| 268 | - 'version' => $GLOBALS['spip_version_branche'], |
|
| 269 | - 'dir_type' => '_DIR_RESTREINT', |
|
| 270 | - 'dir' => '', |
|
| 271 | - ] |
|
| 272 | - ]; |
|
| 273 | - |
|
| 274 | - $invalides = []; |
|
| 275 | - foreach ($liste_ext as $plug) { |
|
| 276 | - if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 277 | - plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - foreach ($liste_plug as $plug) { |
|
| 281 | - if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 282 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 283 | - if (is_array($r)) { |
|
| 284 | - $invalides = array_merge($invalides, $r); |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 290 | - $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 291 | - foreach ($liste_plug as $plug) { |
|
| 292 | - if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 293 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 294 | - if (is_array($r)) { |
|
| 295 | - $invalides = array_merge($invalides, $r); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - plugin_fixer_procure($liste_non_classee, $infos); |
|
| 302 | - |
|
| 303 | - // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 304 | - $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 305 | - |
|
| 306 | - return [$infos, $liste_non_classee, $invalides]; |
|
| 251 | + $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 252 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 253 | + $infos = [ |
|
| 254 | + // lister les extensions qui sont automatiquement actives |
|
| 255 | + '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 256 | + '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 257 | + ]; |
|
| 258 | + |
|
| 259 | + // creer une premiere liste non ordonnee mais qui ne retient |
|
| 260 | + // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 261 | + $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 262 | + $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 263 | + $infos['_DIR_RESTREINT']['SPIP']['chemin'] = []; |
|
| 264 | + $liste_non_classee = [ |
|
| 265 | + 'SPIP' => [ |
|
| 266 | + 'nom' => 'SPIP', |
|
| 267 | + 'etat' => 'stable', |
|
| 268 | + 'version' => $GLOBALS['spip_version_branche'], |
|
| 269 | + 'dir_type' => '_DIR_RESTREINT', |
|
| 270 | + 'dir' => '', |
|
| 271 | + ] |
|
| 272 | + ]; |
|
| 273 | + |
|
| 274 | + $invalides = []; |
|
| 275 | + foreach ($liste_ext as $plug) { |
|
| 276 | + if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 277 | + plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + foreach ($liste_plug as $plug) { |
|
| 281 | + if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 282 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 283 | + if (is_array($r)) { |
|
| 284 | + $invalides = array_merge($invalides, $r); |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 290 | + $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 291 | + foreach ($liste_plug as $plug) { |
|
| 292 | + if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 293 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 294 | + if (is_array($r)) { |
|
| 295 | + $invalides = array_merge($invalides, $r); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + plugin_fixer_procure($liste_non_classee, $infos); |
|
| 302 | + |
|
| 303 | + // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 304 | + $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 305 | + |
|
| 306 | + return [$infos, $liste_non_classee, $invalides]; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -323,37 +323,37 @@ discard block |
||
| 323 | 323 | * array description short si on ne le retient pas (pour memorisation dans une table des erreurs) |
| 324 | 324 | */ |
| 325 | 325 | function plugin_valide_resume(&$liste, $plug, $infos, $dir_type) { |
| 326 | - $i = $infos[$dir_type][$plug]; |
|
| 327 | - // minimum syndical pour afficher si le xml avait des erreurs éventuelles |
|
| 328 | - $short_desc = [ |
|
| 329 | - 'dir' => $plug, |
|
| 330 | - 'dir_type' => $dir_type |
|
| 331 | - ]; |
|
| 332 | - if (empty($i['prefix'])) { |
|
| 333 | - // erreur xml ? mais sans connaissance du prefix, on retourne le chemin… |
|
| 334 | - $short_desc['erreur'] = $i['erreur'] ?? ['?']; |
|
| 335 | - return [$plug => $short_desc]; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $p = strtoupper($i['prefix']); |
|
| 339 | - $short_desc['nom'] = $i['nom']; |
|
| 340 | - $short_desc['etat'] = $i['etat']; |
|
| 341 | - $short_desc['version'] = $i['version']; |
|
| 342 | - |
|
| 343 | - if (isset($i['erreur']) && $i['erreur']) { |
|
| 344 | - $short_desc['erreur'] = $i['erreur']; |
|
| 345 | - return [$p => $short_desc]; |
|
| 346 | - } |
|
| 347 | - if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 348 | - return [$p => $short_desc]; |
|
| 349 | - } |
|
| 350 | - if ( |
|
| 351 | - !isset($liste[$p]) || spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 352 | - ) { |
|
| 353 | - $liste[$p] = $short_desc; |
|
| 354 | - } |
|
| 355 | - // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 356 | - return $p; |
|
| 326 | + $i = $infos[$dir_type][$plug]; |
|
| 327 | + // minimum syndical pour afficher si le xml avait des erreurs éventuelles |
|
| 328 | + $short_desc = [ |
|
| 329 | + 'dir' => $plug, |
|
| 330 | + 'dir_type' => $dir_type |
|
| 331 | + ]; |
|
| 332 | + if (empty($i['prefix'])) { |
|
| 333 | + // erreur xml ? mais sans connaissance du prefix, on retourne le chemin… |
|
| 334 | + $short_desc['erreur'] = $i['erreur'] ?? ['?']; |
|
| 335 | + return [$plug => $short_desc]; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + $p = strtoupper($i['prefix']); |
|
| 339 | + $short_desc['nom'] = $i['nom']; |
|
| 340 | + $short_desc['etat'] = $i['etat']; |
|
| 341 | + $short_desc['version'] = $i['version']; |
|
| 342 | + |
|
| 343 | + if (isset($i['erreur']) && $i['erreur']) { |
|
| 344 | + $short_desc['erreur'] = $i['erreur']; |
|
| 345 | + return [$p => $short_desc]; |
|
| 346 | + } |
|
| 347 | + if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 348 | + return [$p => $short_desc]; |
|
| 349 | + } |
|
| 350 | + if ( |
|
| 351 | + !isset($liste[$p]) || spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 352 | + ) { |
|
| 353 | + $liste[$p] = $short_desc; |
|
| 354 | + } |
|
| 355 | + // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 356 | + return $p; |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -369,47 +369,47 @@ discard block |
||
| 369 | 369 | * @param array $infos |
| 370 | 370 | */ |
| 371 | 371 | function plugin_fixer_procure(&$liste, &$infos) { |
| 372 | - foreach ($liste as $p => $resume) { |
|
| 373 | - $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 374 | - if (isset($i['procure']) && $i['procure']) { |
|
| 375 | - foreach ($i['procure'] as $procure) { |
|
| 376 | - $p = strtoupper($procure['nom']); |
|
| 377 | - $dir = $resume['dir']; |
|
| 378 | - if ($dir) { |
|
| 379 | - $dir .= '/'; |
|
| 380 | - } |
|
| 381 | - $dir .= 'procure:' . $procure['nom']; |
|
| 382 | - |
|
| 383 | - $procure['etat'] = '?'; |
|
| 384 | - $procure['dir_type'] = $resume['dir_type']; |
|
| 385 | - $procure['dir'] = $dir; |
|
| 386 | - |
|
| 387 | - // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 388 | - // on ajoute cette version a la liste |
|
| 389 | - if ( |
|
| 390 | - !isset($liste[$p]) |
|
| 391 | - || spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 392 | - ) { |
|
| 393 | - $liste[$p] = $procure; |
|
| 394 | - |
|
| 395 | - // on fournit une information minimale pour ne pas perturber la compilation |
|
| 396 | - $infos[$resume['dir_type']][$dir] = [ |
|
| 397 | - 'prefix' => $procure['nom'], |
|
| 398 | - 'nom' => $procure['nom'], |
|
| 399 | - 'etat' => $procure['etat'], |
|
| 400 | - 'version' => $procure['version'], |
|
| 401 | - 'chemin' => [], |
|
| 402 | - 'necessite' => [], |
|
| 403 | - 'utilise' => [], |
|
| 404 | - 'lib' => [], |
|
| 405 | - 'menu' => [], |
|
| 406 | - 'onglet' => [], |
|
| 407 | - 'procure' => [], |
|
| 408 | - ]; |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - } |
|
| 372 | + foreach ($liste as $p => $resume) { |
|
| 373 | + $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 374 | + if (isset($i['procure']) && $i['procure']) { |
|
| 375 | + foreach ($i['procure'] as $procure) { |
|
| 376 | + $p = strtoupper($procure['nom']); |
|
| 377 | + $dir = $resume['dir']; |
|
| 378 | + if ($dir) { |
|
| 379 | + $dir .= '/'; |
|
| 380 | + } |
|
| 381 | + $dir .= 'procure:' . $procure['nom']; |
|
| 382 | + |
|
| 383 | + $procure['etat'] = '?'; |
|
| 384 | + $procure['dir_type'] = $resume['dir_type']; |
|
| 385 | + $procure['dir'] = $dir; |
|
| 386 | + |
|
| 387 | + // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 388 | + // on ajoute cette version a la liste |
|
| 389 | + if ( |
|
| 390 | + !isset($liste[$p]) |
|
| 391 | + || spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 392 | + ) { |
|
| 393 | + $liste[$p] = $procure; |
|
| 394 | + |
|
| 395 | + // on fournit une information minimale pour ne pas perturber la compilation |
|
| 396 | + $infos[$resume['dir_type']][$dir] = [ |
|
| 397 | + 'prefix' => $procure['nom'], |
|
| 398 | + 'nom' => $procure['nom'], |
|
| 399 | + 'etat' => $procure['etat'], |
|
| 400 | + 'version' => $procure['version'], |
|
| 401 | + 'chemin' => [], |
|
| 402 | + 'necessite' => [], |
|
| 403 | + 'utilise' => [], |
|
| 404 | + 'lib' => [], |
|
| 405 | + 'menu' => [], |
|
| 406 | + 'onglet' => [], |
|
| 407 | + 'procure' => [], |
|
| 408 | + ]; |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * @return array |
| 424 | 424 | */ |
| 425 | 425 | function liste_chemin_plugin($liste, $dir_plugins = _DIR_PLUGINS) { |
| 426 | - foreach ($liste as $prefix => $infos) { |
|
| 427 | - if ( |
|
| 428 | - !$dir_plugins || defined($infos['dir_type']) && constant($infos['dir_type']) == $dir_plugins |
|
| 429 | - ) { |
|
| 430 | - $liste[$prefix] = $infos['dir']; |
|
| 431 | - } else { |
|
| 432 | - unset($liste[$prefix]); |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return $liste; |
|
| 426 | + foreach ($liste as $prefix => $infos) { |
|
| 427 | + if ( |
|
| 428 | + !$dir_plugins || defined($infos['dir_type']) && constant($infos['dir_type']) == $dir_plugins |
|
| 429 | + ) { |
|
| 430 | + $liste[$prefix] = $infos['dir']; |
|
| 431 | + } else { |
|
| 432 | + unset($liste[$prefix]); |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return $liste; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | /** |
@@ -448,9 +448,9 @@ discard block |
||
| 448 | 448 | * @return array |
| 449 | 449 | */ |
| 450 | 450 | function liste_chemin_plugin_actifs($dir_plugins = _DIR_PLUGINS) { |
| 451 | - include_spip('plugins/installer'); |
|
| 451 | + include_spip('plugins/installer'); |
|
| 452 | 452 | |
| 453 | - return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 453 | + return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /** |
@@ -481,53 +481,53 @@ discard block |
||
| 481 | 481 | * qui n'ont pas satisfait leurs dépendances |
| 482 | 482 | **/ |
| 483 | 483 | function plugin_trier($infos, $liste_non_classee) { |
| 484 | - $toute_la_liste = $liste_non_classee; |
|
| 485 | - $liste = $ordre = []; |
|
| 486 | - $count = 0; |
|
| 487 | - |
|
| 488 | - while (($c = count($liste_non_classee)) && $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 489 | - #echo "tour::";var_dump($liste_non_classee); |
|
| 490 | - $count = $c; |
|
| 491 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 492 | - $plug = $resume['dir']; |
|
| 493 | - $dir_type = $resume['dir_type']; |
|
| 494 | - $info1 = $infos[$dir_type][$plug]; |
|
| 495 | - // si des plugins sont necessaires, |
|
| 496 | - // on ne peut inserer qu'apres eux |
|
| 497 | - foreach ($info1['necessite'] as $need) { |
|
| 498 | - $nom = strtoupper($need['nom']); |
|
| 499 | - $compat = $need['compatibilite'] ?? ''; |
|
| 500 | - if (!isset($liste[$nom]) || !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 501 | - $info1 = false; |
|
| 502 | - break; |
|
| 503 | - } |
|
| 504 | - } |
|
| 505 | - if (!$info1) { |
|
| 506 | - continue; |
|
| 507 | - } |
|
| 508 | - // idem si des plugins sont utiles, |
|
| 509 | - // sauf si ils sont de toute facon absents de la liste |
|
| 510 | - foreach ($info1['utilise'] as $need) { |
|
| 511 | - $nom = strtoupper($need['nom']); |
|
| 512 | - $compat = $need['compatibilite'] ?? ''; |
|
| 513 | - if (isset($toute_la_liste[$nom])) { |
|
| 514 | - if ( |
|
| 515 | - !isset($liste[$nom]) || !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 516 | - ) { |
|
| 517 | - $info1 = false; |
|
| 518 | - break; |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - if ($info1) { |
|
| 523 | - $ordre[$p] = $info1; |
|
| 524 | - $liste[$p] = $liste_non_classee[$p]; |
|
| 525 | - unset($liste_non_classee[$p]); |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - return [$liste, $ordre, $liste_non_classee]; |
|
| 484 | + $toute_la_liste = $liste_non_classee; |
|
| 485 | + $liste = $ordre = []; |
|
| 486 | + $count = 0; |
|
| 487 | + |
|
| 488 | + while (($c = count($liste_non_classee)) && $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 489 | + #echo "tour::";var_dump($liste_non_classee); |
|
| 490 | + $count = $c; |
|
| 491 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 492 | + $plug = $resume['dir']; |
|
| 493 | + $dir_type = $resume['dir_type']; |
|
| 494 | + $info1 = $infos[$dir_type][$plug]; |
|
| 495 | + // si des plugins sont necessaires, |
|
| 496 | + // on ne peut inserer qu'apres eux |
|
| 497 | + foreach ($info1['necessite'] as $need) { |
|
| 498 | + $nom = strtoupper($need['nom']); |
|
| 499 | + $compat = $need['compatibilite'] ?? ''; |
|
| 500 | + if (!isset($liste[$nom]) || !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 501 | + $info1 = false; |
|
| 502 | + break; |
|
| 503 | + } |
|
| 504 | + } |
|
| 505 | + if (!$info1) { |
|
| 506 | + continue; |
|
| 507 | + } |
|
| 508 | + // idem si des plugins sont utiles, |
|
| 509 | + // sauf si ils sont de toute facon absents de la liste |
|
| 510 | + foreach ($info1['utilise'] as $need) { |
|
| 511 | + $nom = strtoupper($need['nom']); |
|
| 512 | + $compat = $need['compatibilite'] ?? ''; |
|
| 513 | + if (isset($toute_la_liste[$nom])) { |
|
| 514 | + if ( |
|
| 515 | + !isset($liste[$nom]) || !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 516 | + ) { |
|
| 517 | + $info1 = false; |
|
| 518 | + break; |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + if ($info1) { |
|
| 523 | + $ordre[$p] = $info1; |
|
| 524 | + $liste[$p] = $liste_non_classee[$p]; |
|
| 525 | + unset($liste_non_classee[$p]); |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + return [$liste, $ordre, $liste_non_classee]; |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | /** |
@@ -544,40 +544,40 @@ discard block |
||
| 544 | 544 | * Répertoire (plugins, plugins-dist, ...) => Couples (prefixes => infos completes) des plugins qu'ils contiennent |
| 545 | 545 | **/ |
| 546 | 546 | function plugins_erreurs($liste_non_classee, $liste, $infos, $msg = []) { |
| 547 | - static $erreurs = []; |
|
| 548 | - |
|
| 549 | - if (!is_array($liste)) { |
|
| 550 | - $liste = []; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 554 | - $liste = array_diff_key($liste, $liste_non_classee); |
|
| 555 | - |
|
| 556 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 557 | - $dir_type = $resume['dir_type']; |
|
| 558 | - $plug = $resume['dir']; |
|
| 559 | - $k = $infos[$dir_type][$plug]; |
|
| 560 | - |
|
| 561 | - $plug = constant($dir_type) . $plug; |
|
| 562 | - if (!isset($msg[$p])) { |
|
| 563 | - if (isset($resume['erreur']) && $resume['erreur']) { |
|
| 564 | - $msg[$p] = [$resume['erreur']]; |
|
| 565 | - } |
|
| 566 | - elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 567 | - $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
|
| 568 | - } |
|
| 569 | - elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 570 | - $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 571 | - } |
|
| 572 | - } else { |
|
| 573 | - foreach ($msg[$p] as $c => $l) { |
|
| 574 | - $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - $erreurs[$plug] = $msg[$p]; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 547 | + static $erreurs = []; |
|
| 548 | + |
|
| 549 | + if (!is_array($liste)) { |
|
| 550 | + $liste = []; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 554 | + $liste = array_diff_key($liste, $liste_non_classee); |
|
| 555 | + |
|
| 556 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 557 | + $dir_type = $resume['dir_type']; |
|
| 558 | + $plug = $resume['dir']; |
|
| 559 | + $k = $infos[$dir_type][$plug]; |
|
| 560 | + |
|
| 561 | + $plug = constant($dir_type) . $plug; |
|
| 562 | + if (!isset($msg[$p])) { |
|
| 563 | + if (isset($resume['erreur']) && $resume['erreur']) { |
|
| 564 | + $msg[$p] = [$resume['erreur']]; |
|
| 565 | + } |
|
| 566 | + elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 567 | + $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
|
| 568 | + } |
|
| 569 | + elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 570 | + $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 571 | + } |
|
| 572 | + } else { |
|
| 573 | + foreach ($msg[$p] as $c => $l) { |
|
| 574 | + $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + $erreurs[$plug] = $msg[$p]; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | /** |
@@ -592,25 +592,25 @@ discard block |
||
| 592 | 592 | * - Liste des erreurs ou code HTML des erreurs |
| 593 | 593 | **/ |
| 594 | 594 | function plugin_donne_erreurs($raw = false, $raz = true) { |
| 595 | - if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 596 | - return $raw ? [] : ''; |
|
| 597 | - } |
|
| 598 | - $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 599 | - // Compat ancienne version |
|
| 600 | - if (!$list) { |
|
| 601 | - $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 602 | - } elseif (!$raw) { |
|
| 603 | - foreach ($list as $plug => $msg) { |
|
| 604 | - $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 605 | - . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 606 | - } |
|
| 607 | - $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 608 | - } |
|
| 609 | - if ($raz) { |
|
| 610 | - effacer_meta('plugin_erreur_activation'); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - return $list; |
|
| 595 | + if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 596 | + return $raw ? [] : ''; |
|
| 597 | + } |
|
| 598 | + $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 599 | + // Compat ancienne version |
|
| 600 | + if (!$list) { |
|
| 601 | + $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 602 | + } elseif (!$raw) { |
|
| 603 | + foreach ($list as $plug => $msg) { |
|
| 604 | + $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 605 | + . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 606 | + } |
|
| 607 | + $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 608 | + } |
|
| 609 | + if ($raz) { |
|
| 610 | + effacer_meta('plugin_erreur_activation'); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + return $list; |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -630,21 +630,21 @@ discard block |
||
| 630 | 630 | * |
| 631 | 631 | **/ |
| 632 | 632 | function plugin_necessite($n, $liste, $balise = 'necessite') { |
| 633 | - $msg = []; |
|
| 634 | - foreach ($n as $need) { |
|
| 635 | - $id = strtoupper($need['nom']); |
|
| 636 | - $r = plugin_controler_necessite( |
|
| 637 | - $liste, |
|
| 638 | - $id, |
|
| 639 | - $need['compatibilite'] ?? '', |
|
| 640 | - $balise |
|
| 641 | - ); |
|
| 642 | - if ($r) { |
|
| 643 | - $msg[] = $r; |
|
| 644 | - } |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - return $msg; |
|
| 633 | + $msg = []; |
|
| 634 | + foreach ($n as $need) { |
|
| 635 | + $id = strtoupper($need['nom']); |
|
| 636 | + $r = plugin_controler_necessite( |
|
| 637 | + $liste, |
|
| 638 | + $id, |
|
| 639 | + $need['compatibilite'] ?? '', |
|
| 640 | + $balise |
|
| 641 | + ); |
|
| 642 | + if ($r) { |
|
| 643 | + $msg[] = $r; |
|
| 644 | + } |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + return $msg; |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | /** |
@@ -666,19 +666,19 @@ discard block |
||
| 666 | 666 | * Message d'erreur lorsque la dépendance est absente. |
| 667 | 667 | **/ |
| 668 | 668 | function plugin_controler_necessite($liste, $nom, $intervalle, $balise) { |
| 669 | - if (isset($liste[$nom]) && plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 670 | - return ''; |
|
| 671 | - } |
|
| 672 | - // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 673 | - if ($balise === 'utilise' && !isset($liste[$nom])) { |
|
| 674 | - return ''; |
|
| 675 | - } |
|
| 676 | - return plugin_message_incompatibilite( |
|
| 677 | - $intervalle, |
|
| 678 | - (isset($liste[$nom]) ? $liste[$nom]['version'] : ''), |
|
| 679 | - $nom, |
|
| 680 | - $balise |
|
| 681 | - ); |
|
| 669 | + if (isset($liste[$nom]) && plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 670 | + return ''; |
|
| 671 | + } |
|
| 672 | + // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 673 | + if ($balise === 'utilise' && !isset($liste[$nom])) { |
|
| 674 | + return ''; |
|
| 675 | + } |
|
| 676 | + return plugin_message_incompatibilite( |
|
| 677 | + $intervalle, |
|
| 678 | + (isset($liste[$nom]) ? $liste[$nom]['version'] : ''), |
|
| 679 | + $nom, |
|
| 680 | + $balise |
|
| 681 | + ); |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | /** |
@@ -695,70 +695,70 @@ discard block |
||
| 695 | 695 | */ |
| 696 | 696 | function plugin_message_incompatibilite($intervalle, $version, $nom, $balise) { |
| 697 | 697 | |
| 698 | - // prendre en compte les erreurs de dépendances à PHP |
|
| 699 | - // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 700 | - $type = 'plugin'; |
|
| 701 | - if ($nom === 'SPIP') { |
|
| 702 | - $type = 'spip'; |
|
| 703 | - } elseif ($nom === 'PHP') { |
|
| 704 | - $type = 'php'; |
|
| 705 | - } elseif (str_starts_with($nom, 'PHP:')) { |
|
| 706 | - $type = 'extension_php'; |
|
| 707 | - [, $nom] = explode(':', $nom, 2); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 711 | - $minimum = $regs[1]; |
|
| 712 | - $maximum = $regs[2]; |
|
| 713 | - |
|
| 714 | - $minimum_inclus = $intervalle[0] == '['; |
|
| 715 | - $maximum_inclus = str_ends_with($intervalle, ']'); |
|
| 716 | - |
|
| 717 | - if (strlen($minimum)) { |
|
| 718 | - if ($minimum_inclus && spip_version_compare($version, $minimum, '<')) { |
|
| 719 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 720 | - 'plugin' => $nom, |
|
| 721 | - 'version' => ' ≥ ' . $minimum |
|
| 722 | - ]); |
|
| 723 | - } |
|
| 724 | - if (!$minimum_inclus && spip_version_compare($version, $minimum, '<=')) { |
|
| 725 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 726 | - 'plugin' => $nom, |
|
| 727 | - 'version' => ' > ' . $minimum |
|
| 728 | - ]); |
|
| 729 | - } |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - if (strlen($maximum)) { |
|
| 733 | - if ($maximum_inclus && spip_version_compare($version, $maximum, '>')) { |
|
| 734 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 735 | - 'plugin' => $nom, |
|
| 736 | - 'version' => ' ≤ ' . $maximum |
|
| 737 | - ]); |
|
| 738 | - } |
|
| 739 | - if (!$maximum_inclus && spip_version_compare($version, $maximum, '>=')) { |
|
| 740 | - return _T("plugin_{$balise}_plugin", [ |
|
| 741 | - 'plugin' => $nom, |
|
| 742 | - 'version' => ' < ' . $maximum |
|
| 743 | - ]); |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - // note : il ne peut pas y avoir d'erreur sur |
|
| 749 | - // - un 'utilise' sans version. |
|
| 750 | - // - un 'php' sans version. |
|
| 751 | - return _T("plugin_necessite_{$type}_sans_version", ['plugin' => $nom]); |
|
| 698 | + // prendre en compte les erreurs de dépendances à PHP |
|
| 699 | + // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 700 | + $type = 'plugin'; |
|
| 701 | + if ($nom === 'SPIP') { |
|
| 702 | + $type = 'spip'; |
|
| 703 | + } elseif ($nom === 'PHP') { |
|
| 704 | + $type = 'php'; |
|
| 705 | + } elseif (str_starts_with($nom, 'PHP:')) { |
|
| 706 | + $type = 'extension_php'; |
|
| 707 | + [, $nom] = explode(':', $nom, 2); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 711 | + $minimum = $regs[1]; |
|
| 712 | + $maximum = $regs[2]; |
|
| 713 | + |
|
| 714 | + $minimum_inclus = $intervalle[0] == '['; |
|
| 715 | + $maximum_inclus = str_ends_with($intervalle, ']'); |
|
| 716 | + |
|
| 717 | + if (strlen($minimum)) { |
|
| 718 | + if ($minimum_inclus && spip_version_compare($version, $minimum, '<')) { |
|
| 719 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 720 | + 'plugin' => $nom, |
|
| 721 | + 'version' => ' ≥ ' . $minimum |
|
| 722 | + ]); |
|
| 723 | + } |
|
| 724 | + if (!$minimum_inclus && spip_version_compare($version, $minimum, '<=')) { |
|
| 725 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 726 | + 'plugin' => $nom, |
|
| 727 | + 'version' => ' > ' . $minimum |
|
| 728 | + ]); |
|
| 729 | + } |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + if (strlen($maximum)) { |
|
| 733 | + if ($maximum_inclus && spip_version_compare($version, $maximum, '>')) { |
|
| 734 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 735 | + 'plugin' => $nom, |
|
| 736 | + 'version' => ' ≤ ' . $maximum |
|
| 737 | + ]); |
|
| 738 | + } |
|
| 739 | + if (!$maximum_inclus && spip_version_compare($version, $maximum, '>=')) { |
|
| 740 | + return _T("plugin_{$balise}_plugin", [ |
|
| 741 | + 'plugin' => $nom, |
|
| 742 | + 'version' => ' < ' . $maximum |
|
| 743 | + ]); |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + // note : il ne peut pas y avoir d'erreur sur |
|
| 749 | + // - un 'utilise' sans version. |
|
| 750 | + // - un 'php' sans version. |
|
| 751 | + return _T("plugin_necessite_{$type}_sans_version", ['plugin' => $nom]); |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | |
| 755 | 755 | function plugin_controler_lib($lib, $url) { |
| 756 | - /* Feature sortie du core, voir STP |
|
| 756 | + /* Feature sortie du core, voir STP |
|
| 757 | 757 | * if ($url) { |
| 758 | 758 | include_spip('inc/charger_plugin'); |
| 759 | 759 | $url = '<br />' . bouton_telechargement_plugin($url, 'lib'); |
| 760 | 760 | }*/ |
| 761 | - return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 761 | + return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | * true si il y a eu des modifications sur la liste des plugins actifs, false sinon |
| 774 | 774 | **/ |
| 775 | 775 | function actualise_plugins_actifs($pipe_recherche = false) { |
| 776 | - return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 776 | + return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | |
@@ -800,115 +800,115 @@ discard block |
||
| 800 | 800 | **/ |
| 801 | 801 | function ecrire_plugin_actifs($plugin, $pipe_recherche = false, $operation = 'raz') { |
| 802 | 802 | |
| 803 | - // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 804 | - $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 805 | - |
|
| 806 | - // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 807 | - if (!$cache && !spip_connect()) { |
|
| 808 | - return false; |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - if ($operation != 'raz') { |
|
| 812 | - $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 813 | - $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 814 | - if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 815 | - $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 816 | - $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 817 | - $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 818 | - } |
|
| 819 | - // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 820 | - // on les reinjecte ici |
|
| 821 | - if ( |
|
| 822 | - isset($GLOBALS['meta']['plugin_attente']) && ($a = unserialize($GLOBALS['meta']['plugin_attente'])) |
|
| 823 | - ) { |
|
| 824 | - $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - if ($operation == 'ajoute') { |
|
| 828 | - $plugin = array_merge($plugin_valides, $plugin); |
|
| 829 | - } elseif ($operation == 'enleve') { |
|
| 830 | - $plugin = array_diff($plugin_valides, $plugin); |
|
| 831 | - } else { |
|
| 832 | - $plugin = $plugin_valides; |
|
| 833 | - } |
|
| 834 | - } |
|
| 835 | - $actifs_avant = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 836 | - |
|
| 837 | - // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 838 | - if ($ajouter_dependances = charger_fonction('ajouter_dependances', 'plugins', true)) { |
|
| 839 | - $plugin = $ajouter_dependances($plugin); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - // recharger le xml des plugins a activer |
|
| 843 | - // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 844 | - // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 845 | - // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 846 | - // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 847 | - [$infos, $liste, $invalides] = liste_plugin_valides($plugin, true); |
|
| 848 | - // trouver l'ordre d'activation |
|
| 849 | - [$plugin_valides, $ordre, $reste] = plugin_trier($infos, $liste); |
|
| 850 | - if ($invalides || $reste) { |
|
| 851 | - plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - // Ignorer les plugins necessitant une lib absente |
|
| 855 | - // et preparer la meta d'entete Http |
|
| 856 | - $err = $msg = $header = []; |
|
| 857 | - foreach ($plugin_valides as $p => $resume) { |
|
| 858 | - // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 859 | - if (!str_starts_with($p, 'PHP:') && $p !== 'PHP') { |
|
| 860 | - $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 861 | - } |
|
| 862 | - if ($resume['dir']) { |
|
| 863 | - foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 864 | - if (!find_in_path($l['nom'], 'lib/')) { |
|
| 865 | - $err[$p] = $resume; |
|
| 866 | - $msg[$p][] = $l; |
|
| 867 | - unset($plugin_valides[$p]); |
|
| 868 | - } |
|
| 869 | - } |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - if ($err) { |
|
| 873 | - plugins_erreurs($err, '', $infos, $msg); |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 877 | - effacer_meta('message_crash_plugins'); |
|
| 878 | - } |
|
| 879 | - ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 880 | - $liste = array_diff_key($liste, $plugin_valides); |
|
| 881 | - ecrire_meta('plugin_attente', serialize($liste)); |
|
| 882 | - $header = strtolower(implode(',', $header)); |
|
| 883 | - if (!isset($GLOBALS['spip_header_silencieux']) || !$GLOBALS['spip_header_silencieux']) { |
|
| 884 | - ecrire_fichier( |
|
| 885 | - _DIR_VAR . 'config.txt', |
|
| 886 | - (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 887 | - ); |
|
| 888 | - } else { |
|
| 889 | - @unlink(_DIR_VAR . 'config.txt'); |
|
| 890 | - } |
|
| 891 | - // generer charger_plugins_chemin.php |
|
| 892 | - plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 893 | - // generer les fichiers |
|
| 894 | - // - charger_plugins_options.php |
|
| 895 | - // - charger_plugins_fonctions.php |
|
| 896 | - plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 897 | - // charger les chemins des plugins et les fichiers d'options |
|
| 898 | - // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 899 | - plugins_amorcer_plugins_actifs(); |
|
| 900 | - // mise a jour de la matrice des pipelines |
|
| 901 | - $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 902 | - // generer le fichier _CACHE_PIPELINE |
|
| 903 | - pipeline_precompile($prepend_code); |
|
| 904 | - |
|
| 905 | - if (spip_connect()) { |
|
| 906 | - // lancer et initialiser les nouveaux crons ! |
|
| 907 | - include_spip('inc/genie'); |
|
| 908 | - genie_queue_watch_dist(); |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 803 | + // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 804 | + $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 805 | + |
|
| 806 | + // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 807 | + if (!$cache && !spip_connect()) { |
|
| 808 | + return false; |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + if ($operation != 'raz') { |
|
| 812 | + $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 813 | + $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 814 | + if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 815 | + $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 816 | + $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 817 | + $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 818 | + } |
|
| 819 | + // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 820 | + // on les reinjecte ici |
|
| 821 | + if ( |
|
| 822 | + isset($GLOBALS['meta']['plugin_attente']) && ($a = unserialize($GLOBALS['meta']['plugin_attente'])) |
|
| 823 | + ) { |
|
| 824 | + $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + if ($operation == 'ajoute') { |
|
| 828 | + $plugin = array_merge($plugin_valides, $plugin); |
|
| 829 | + } elseif ($operation == 'enleve') { |
|
| 830 | + $plugin = array_diff($plugin_valides, $plugin); |
|
| 831 | + } else { |
|
| 832 | + $plugin = $plugin_valides; |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + $actifs_avant = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 836 | + |
|
| 837 | + // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 838 | + if ($ajouter_dependances = charger_fonction('ajouter_dependances', 'plugins', true)) { |
|
| 839 | + $plugin = $ajouter_dependances($plugin); |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + // recharger le xml des plugins a activer |
|
| 843 | + // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 844 | + // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 845 | + // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 846 | + // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 847 | + [$infos, $liste, $invalides] = liste_plugin_valides($plugin, true); |
|
| 848 | + // trouver l'ordre d'activation |
|
| 849 | + [$plugin_valides, $ordre, $reste] = plugin_trier($infos, $liste); |
|
| 850 | + if ($invalides || $reste) { |
|
| 851 | + plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + // Ignorer les plugins necessitant une lib absente |
|
| 855 | + // et preparer la meta d'entete Http |
|
| 856 | + $err = $msg = $header = []; |
|
| 857 | + foreach ($plugin_valides as $p => $resume) { |
|
| 858 | + // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 859 | + if (!str_starts_with($p, 'PHP:') && $p !== 'PHP') { |
|
| 860 | + $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 861 | + } |
|
| 862 | + if ($resume['dir']) { |
|
| 863 | + foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 864 | + if (!find_in_path($l['nom'], 'lib/')) { |
|
| 865 | + $err[$p] = $resume; |
|
| 866 | + $msg[$p][] = $l; |
|
| 867 | + unset($plugin_valides[$p]); |
|
| 868 | + } |
|
| 869 | + } |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + if ($err) { |
|
| 873 | + plugins_erreurs($err, '', $infos, $msg); |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 877 | + effacer_meta('message_crash_plugins'); |
|
| 878 | + } |
|
| 879 | + ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 880 | + $liste = array_diff_key($liste, $plugin_valides); |
|
| 881 | + ecrire_meta('plugin_attente', serialize($liste)); |
|
| 882 | + $header = strtolower(implode(',', $header)); |
|
| 883 | + if (!isset($GLOBALS['spip_header_silencieux']) || !$GLOBALS['spip_header_silencieux']) { |
|
| 884 | + ecrire_fichier( |
|
| 885 | + _DIR_VAR . 'config.txt', |
|
| 886 | + (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 887 | + ); |
|
| 888 | + } else { |
|
| 889 | + @unlink(_DIR_VAR . 'config.txt'); |
|
| 890 | + } |
|
| 891 | + // generer charger_plugins_chemin.php |
|
| 892 | + plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 893 | + // generer les fichiers |
|
| 894 | + // - charger_plugins_options.php |
|
| 895 | + // - charger_plugins_fonctions.php |
|
| 896 | + plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 897 | + // charger les chemins des plugins et les fichiers d'options |
|
| 898 | + // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 899 | + plugins_amorcer_plugins_actifs(); |
|
| 900 | + // mise a jour de la matrice des pipelines |
|
| 901 | + $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 902 | + // generer le fichier _CACHE_PIPELINE |
|
| 903 | + pipeline_precompile($prepend_code); |
|
| 904 | + |
|
| 905 | + if (spip_connect()) { |
|
| 906 | + // lancer et initialiser les nouveaux crons ! |
|
| 907 | + include_spip('inc/genie'); |
|
| 908 | + genie_queue_watch_dist(); |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | /** |
@@ -927,75 +927,75 @@ discard block |
||
| 927 | 927 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 928 | 928 | **/ |
| 929 | 929 | function plugins_precompile_chemin($plugin_valides, $ordre) { |
| 930 | - $chemins = [ |
|
| 931 | - 'public' => [], |
|
| 932 | - 'prive' => [] |
|
| 933 | - ]; |
|
| 934 | - $contenu = ''; |
|
| 935 | - foreach ($ordre as $p => $info) { |
|
| 936 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 937 | - if (isset($plugin_valides[$p])) { |
|
| 938 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 939 | - $plug = $plugin_valides[$p]['dir']; |
|
| 940 | - // definir le plugin, donc le path avant l'include du fichier options |
|
| 941 | - // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 942 | - |
|
| 943 | - $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 944 | - |
|
| 945 | - $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 946 | - if ( |
|
| 947 | - $prefix !== 'SPIP' |
|
| 948 | - && !str_contains($dir, ':') // exclure le cas des procure: |
|
| 949 | - ) { |
|
| 950 | - $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 951 | - if (!$info['chemin']) { |
|
| 952 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 953 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 954 | - if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 955 | - $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 956 | - } |
|
| 957 | - } |
|
| 958 | - else { |
|
| 959 | - foreach ($info['chemin'] as $chemin) { |
|
| 960 | - if ( |
|
| 961 | - !isset($chemin['version']) |
|
| 962 | - || plugin_version_compatible( |
|
| 963 | - $chemin['version'], |
|
| 964 | - $GLOBALS['spip_version_branche'], |
|
| 965 | - 'spip' |
|
| 966 | - ) |
|
| 967 | - ) { |
|
| 968 | - $dir = $chemin['path']; |
|
| 969 | - if (strlen($dir) && $dir[0] == '/') { |
|
| 970 | - $dir = substr($dir, 1); |
|
| 971 | - } |
|
| 972 | - if (strlen($dir) && $dir == './') { |
|
| 973 | - $dir = ''; |
|
| 974 | - } |
|
| 975 | - if (strlen($dir)) { |
|
| 976 | - $dir = rtrim($dir, '/') . '/'; |
|
| 977 | - } |
|
| 978 | - if (!isset($chemin['type']) || $chemin['type'] == 'public') { |
|
| 979 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 980 | - } |
|
| 981 | - if (!isset($chemin['type']) || $chemin['type'] == 'prive') { |
|
| 982 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 983 | - } |
|
| 984 | - } |
|
| 985 | - } |
|
| 986 | - } |
|
| 987 | - } |
|
| 988 | - } |
|
| 989 | - } |
|
| 990 | - if (count($chemins['public']) || count($chemins['prive'])) { |
|
| 991 | - $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 992 | - ',', |
|
| 993 | - array_reverse($chemins['public']) |
|
| 994 | - ) . "]);\n" |
|
| 995 | - . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 930 | + $chemins = [ |
|
| 931 | + 'public' => [], |
|
| 932 | + 'prive' => [] |
|
| 933 | + ]; |
|
| 934 | + $contenu = ''; |
|
| 935 | + foreach ($ordre as $p => $info) { |
|
| 936 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 937 | + if (isset($plugin_valides[$p])) { |
|
| 938 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 939 | + $plug = $plugin_valides[$p]['dir']; |
|
| 940 | + // definir le plugin, donc le path avant l'include du fichier options |
|
| 941 | + // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 942 | + |
|
| 943 | + $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 944 | + |
|
| 945 | + $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 946 | + if ( |
|
| 947 | + $prefix !== 'SPIP' |
|
| 948 | + && !str_contains($dir, ':') // exclure le cas des procure: |
|
| 949 | + ) { |
|
| 950 | + $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 951 | + if (!$info['chemin']) { |
|
| 952 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 953 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 954 | + if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 955 | + $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 956 | + } |
|
| 957 | + } |
|
| 958 | + else { |
|
| 959 | + foreach ($info['chemin'] as $chemin) { |
|
| 960 | + if ( |
|
| 961 | + !isset($chemin['version']) |
|
| 962 | + || plugin_version_compatible( |
|
| 963 | + $chemin['version'], |
|
| 964 | + $GLOBALS['spip_version_branche'], |
|
| 965 | + 'spip' |
|
| 966 | + ) |
|
| 967 | + ) { |
|
| 968 | + $dir = $chemin['path']; |
|
| 969 | + if (strlen($dir) && $dir[0] == '/') { |
|
| 970 | + $dir = substr($dir, 1); |
|
| 971 | + } |
|
| 972 | + if (strlen($dir) && $dir == './') { |
|
| 973 | + $dir = ''; |
|
| 974 | + } |
|
| 975 | + if (strlen($dir)) { |
|
| 976 | + $dir = rtrim($dir, '/') . '/'; |
|
| 977 | + } |
|
| 978 | + if (!isset($chemin['type']) || $chemin['type'] == 'public') { |
|
| 979 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 980 | + } |
|
| 981 | + if (!isset($chemin['type']) || $chemin['type'] == 'prive') { |
|
| 982 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 983 | + } |
|
| 984 | + } |
|
| 985 | + } |
|
| 986 | + } |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | + } |
|
| 990 | + if (count($chemins['public']) || count($chemins['prive'])) { |
|
| 991 | + $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 992 | + ',', |
|
| 993 | + array_reverse($chemins['public']) |
|
| 994 | + ) . "]);\n" |
|
| 995 | + . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | /** |
@@ -1013,65 +1013,65 @@ discard block |
||
| 1013 | 1013 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 1014 | 1014 | **/ |
| 1015 | 1015 | function plugins_precompile_xxxtions($plugin_valides, $ordre) { |
| 1016 | - $contenu = ['options' => '', 'fonctions' => '']; |
|
| 1017 | - $boutons = []; |
|
| 1018 | - $onglets = []; |
|
| 1019 | - $sign = ''; |
|
| 1020 | - |
|
| 1021 | - foreach ($ordre as $p => $info) { |
|
| 1022 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1023 | - if (isset($plugin_valides[$p])) { |
|
| 1024 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1025 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1026 | - $dir = constant($dir_type); |
|
| 1027 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1028 | - if ($info['menu']) { |
|
| 1029 | - $boutons = array_merge($boutons, $info['menu']); |
|
| 1030 | - } |
|
| 1031 | - if ($info['onglet']) { |
|
| 1032 | - $onglets = array_merge($onglets, $info['onglet']); |
|
| 1033 | - } |
|
| 1034 | - foreach ($contenu as $charge => $v) { |
|
| 1035 | - // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1036 | - // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1037 | - // donc ni sa relecture, ni sa detection |
|
| 1038 | - if ( |
|
| 1039 | - !isset($info[$charge]) |
|
| 1040 | - && $dir |
|
| 1041 | - && !str_contains($dir, ':') |
|
| 1042 | - && file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1043 | - ) { |
|
| 1044 | - if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1045 | - $info[$charge] = [$file]; |
|
| 1046 | - } |
|
| 1047 | - } |
|
| 1048 | - if (isset($info[$charge])) { |
|
| 1049 | - $files = $info[$charge]; |
|
| 1050 | - foreach ($files as $k => $file) { |
|
| 1051 | - // on genere un if file_exists devant chaque include |
|
| 1052 | - // pour pouvoir garder le meme niveau d'erreur general |
|
| 1053 | - $file = trim($file); |
|
| 1054 | - if ( |
|
| 1055 | - !is_readable("$dir$plug/$file") && file_exists("$dir$plug/paquet.xml") |
|
| 1056 | - ) { |
|
| 1057 | - unset($info[$charge][$k]); |
|
| 1058 | - } else { |
|
| 1059 | - $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1060 | - $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1061 | - } |
|
| 1062 | - } |
|
| 1063 | - } |
|
| 1064 | - } |
|
| 1065 | - $sign .= md5(serialize($info)); |
|
| 1066 | - } |
|
| 1067 | - } |
|
| 1068 | - |
|
| 1069 | - $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1070 | - $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
|
| 1071 | - . plugin_ongletbouton('onglets_plugins', $onglets); |
|
| 1072 | - |
|
| 1073 | - ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1074 | - ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1016 | + $contenu = ['options' => '', 'fonctions' => '']; |
|
| 1017 | + $boutons = []; |
|
| 1018 | + $onglets = []; |
|
| 1019 | + $sign = ''; |
|
| 1020 | + |
|
| 1021 | + foreach ($ordre as $p => $info) { |
|
| 1022 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1023 | + if (isset($plugin_valides[$p])) { |
|
| 1024 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1025 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1026 | + $dir = constant($dir_type); |
|
| 1027 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1028 | + if ($info['menu']) { |
|
| 1029 | + $boutons = array_merge($boutons, $info['menu']); |
|
| 1030 | + } |
|
| 1031 | + if ($info['onglet']) { |
|
| 1032 | + $onglets = array_merge($onglets, $info['onglet']); |
|
| 1033 | + } |
|
| 1034 | + foreach ($contenu as $charge => $v) { |
|
| 1035 | + // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1036 | + // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1037 | + // donc ni sa relecture, ni sa detection |
|
| 1038 | + if ( |
|
| 1039 | + !isset($info[$charge]) |
|
| 1040 | + && $dir |
|
| 1041 | + && !str_contains($dir, ':') |
|
| 1042 | + && file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1043 | + ) { |
|
| 1044 | + if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1045 | + $info[$charge] = [$file]; |
|
| 1046 | + } |
|
| 1047 | + } |
|
| 1048 | + if (isset($info[$charge])) { |
|
| 1049 | + $files = $info[$charge]; |
|
| 1050 | + foreach ($files as $k => $file) { |
|
| 1051 | + // on genere un if file_exists devant chaque include |
|
| 1052 | + // pour pouvoir garder le meme niveau d'erreur general |
|
| 1053 | + $file = trim($file); |
|
| 1054 | + if ( |
|
| 1055 | + !is_readable("$dir$plug/$file") && file_exists("$dir$plug/paquet.xml") |
|
| 1056 | + ) { |
|
| 1057 | + unset($info[$charge][$k]); |
|
| 1058 | + } else { |
|
| 1059 | + $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1060 | + $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1061 | + } |
|
| 1062 | + } |
|
| 1063 | + } |
|
| 1064 | + } |
|
| 1065 | + $sign .= md5(serialize($info)); |
|
| 1066 | + } |
|
| 1067 | + } |
|
| 1068 | + |
|
| 1069 | + $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1070 | + $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
|
| 1071 | + . plugin_ongletbouton('onglets_plugins', $onglets); |
|
| 1072 | + |
|
| 1073 | + ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1074 | + ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | /** |
@@ -1090,24 +1090,24 @@ discard block |
||
| 1090 | 1090 | * @return string Code php |
| 1091 | 1091 | */ |
| 1092 | 1092 | function plugin_ongletbouton($nom, $val) { |
| 1093 | - if (!$val) { |
|
| 1094 | - $val = []; |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - $val = serialize($val); |
|
| 1098 | - $md5 = md5($val); |
|
| 1099 | - |
|
| 1100 | - if (!defined("_UPDATED_$nom")) { |
|
| 1101 | - define("_UPDATED_$nom", $val); |
|
| 1102 | - define("_UPDATED_md5_$nom", $md5); |
|
| 1103 | - } |
|
| 1104 | - $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1105 | - |
|
| 1106 | - return |
|
| 1107 | - "if (!function_exists('$nom')) {\n" |
|
| 1108 | - . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1109 | - . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1110 | - . "}\n"; |
|
| 1093 | + if (!$val) { |
|
| 1094 | + $val = []; |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + $val = serialize($val); |
|
| 1098 | + $md5 = md5($val); |
|
| 1099 | + |
|
| 1100 | + if (!defined("_UPDATED_$nom")) { |
|
| 1101 | + define("_UPDATED_$nom", $val); |
|
| 1102 | + define("_UPDATED_md5_$nom", $md5); |
|
| 1103 | + } |
|
| 1104 | + $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1105 | + |
|
| 1106 | + return |
|
| 1107 | + "if (!function_exists('$nom')) {\n" |
|
| 1108 | + . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1109 | + . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1110 | + . "}\n"; |
|
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | 1113 | /** |
@@ -1122,15 +1122,15 @@ discard block |
||
| 1122 | 1122 | **/ |
| 1123 | 1123 | function plugins_amorcer_plugins_actifs() { |
| 1124 | 1124 | |
| 1125 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1126 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1127 | - } |
|
| 1125 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1126 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1127 | + } |
|
| 1128 | 1128 | |
| 1129 | - if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1130 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 1131 | - } else { |
|
| 1132 | - spip_logger()->info('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1133 | - } |
|
| 1129 | + if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1130 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 1131 | + } else { |
|
| 1132 | + spip_logger()->info('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1133 | + } |
|
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | /** |
@@ -1153,140 +1153,140 @@ discard block |
||
| 1153 | 1153 | * Couples (nom du pipeline => Code PHP à insérer au début du pipeline) |
| 1154 | 1154 | **/ |
| 1155 | 1155 | function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche) { |
| 1156 | - static $liste_pipe_manquants = []; |
|
| 1157 | - if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1158 | - $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1159 | - } |
|
| 1160 | - |
|
| 1161 | - $prepend_code = []; |
|
| 1162 | - |
|
| 1163 | - foreach ($ordre as $p => $info) { |
|
| 1164 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1165 | - if (isset($plugin_valides[$p])) { |
|
| 1166 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1167 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1168 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1169 | - $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1170 | - if (isset($info['pipeline']) && is_array($info['pipeline'])) { |
|
| 1171 | - foreach ($info['pipeline'] as $pipe) { |
|
| 1172 | - $nom = $pipe['nom']; |
|
| 1173 | - if (isset($pipe['action'])) { |
|
| 1174 | - $action = $pipe['action']; |
|
| 1175 | - } else { |
|
| 1176 | - $action = $nom; |
|
| 1177 | - } |
|
| 1178 | - $nomlower = strtolower($nom); |
|
| 1179 | - if ( |
|
| 1180 | - $nomlower != $nom |
|
| 1181 | - && isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1182 | - && !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1183 | - ) { |
|
| 1184 | - $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1185 | - unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1186 | - } |
|
| 1187 | - $nom = $nomlower; |
|
| 1188 | - // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1189 | - if (!isset($GLOBALS['spip_pipeline'][$nom])) { // creer le pipeline eventuel |
|
| 1190 | - $GLOBALS['spip_pipeline'][$nom] = ''; |
|
| 1191 | - } |
|
| 1192 | - if ($action) { |
|
| 1193 | - if (!str_contains($GLOBALS['spip_pipeline'][$nom], (string) "|$prefix$action")) { |
|
| 1194 | - $GLOBALS['spip_pipeline'][$nom] = preg_replace( |
|
| 1195 | - ',(\|\||$),', |
|
| 1196 | - "|$prefix$action\\1", |
|
| 1197 | - $GLOBALS['spip_pipeline'][$nom], |
|
| 1198 | - 1 |
|
| 1199 | - ); |
|
| 1200 | - } |
|
| 1201 | - if (isset($pipe['inclure'])) { |
|
| 1202 | - $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1203 | - "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1204 | - } |
|
| 1205 | - } |
|
| 1206 | - } |
|
| 1207 | - } |
|
| 1208 | - if (isset($info['genie']) && (is_countable($info['genie']) ? count($info['genie']) : 0)) { |
|
| 1209 | - if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1210 | - $prepend_code['taches_generales_cron'] = ''; |
|
| 1211 | - } |
|
| 1212 | - foreach ($info['genie'] as $genie) { |
|
| 1213 | - $nom = $prefix . $genie['nom']; |
|
| 1214 | - $periode = max(60, intval($genie['periode'])); |
|
| 1215 | - if (charger_fonction($nom, 'genie', true)) { |
|
| 1216 | - $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1217 | - } else { |
|
| 1218 | - spip_logger()->error("Fonction genie_$nom introuvable"); |
|
| 1219 | - } |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - if (isset($info['style']) && (is_countable($info['style']) ? count($info['style']) : 0)) { |
|
| 1223 | - if (!isset($prepend_code['insert_head_css'])) { |
|
| 1224 | - $prepend_code['insert_head_css'] = ''; |
|
| 1225 | - } |
|
| 1226 | - if (!isset($prepend_code['header_prive_css'])) { |
|
| 1227 | - $prepend_code['header_prive_css'] = ''; |
|
| 1228 | - } |
|
| 1229 | - foreach ($info['style'] as $style) { |
|
| 1230 | - if (isset($style['path']) && $style['path']) { |
|
| 1231 | - $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1232 | - } else { |
|
| 1233 | - $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1234 | - } |
|
| 1235 | - $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1236 | - if (isset($style['media']) && strlen($style['media'])) { |
|
| 1237 | - $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1238 | - } |
|
| 1239 | - $code .= "/>';\n"; |
|
| 1240 | - if ($style['type'] != 'prive') { |
|
| 1241 | - $prepend_code['insert_head_css'] .= $code; |
|
| 1242 | - } |
|
| 1243 | - if ($style['type'] != 'public') { |
|
| 1244 | - $prepend_code['header_prive_css'] .= $code; |
|
| 1245 | - } |
|
| 1246 | - } |
|
| 1247 | - } |
|
| 1248 | - if (!isset($prepend_code['insert_head'])) { |
|
| 1249 | - $prepend_code['insert_head'] = ''; |
|
| 1250 | - } |
|
| 1251 | - if (!isset($prepend_code['header_prive'])) { |
|
| 1252 | - $prepend_code['header_prive'] = ''; |
|
| 1253 | - } |
|
| 1254 | - if (isset($info['script']) && (is_countable($info['script']) ? count($info['script']) : 0)) { |
|
| 1255 | - foreach ($info['script'] as $script) { |
|
| 1256 | - if (isset($script['path']) && $script['path']) { |
|
| 1257 | - $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1258 | - } else { |
|
| 1259 | - $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1260 | - } |
|
| 1261 | - $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1262 | - if ($script['type'] != 'prive') { |
|
| 1263 | - $prepend_code['insert_head'] .= $code; |
|
| 1264 | - } |
|
| 1265 | - if ($script['type'] != 'public') { |
|
| 1266 | - $prepend_code['header_prive'] .= $code; |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - } |
|
| 1270 | - } |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - $prepend_code['insert_head'] = |
|
| 1274 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1275 | - . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1276 | - . $prepend_code['insert_head']; |
|
| 1277 | - $prepend_code['header_prive'] = |
|
| 1278 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1279 | - . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1280 | - . $prepend_code['header_prive']; |
|
| 1281 | - |
|
| 1282 | - // on ajoute les pipe qui ont ete recenses manquants |
|
| 1283 | - foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1284 | - if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1285 | - $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1286 | - } |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - return $prepend_code; |
|
| 1156 | + static $liste_pipe_manquants = []; |
|
| 1157 | + if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1158 | + $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1159 | + } |
|
| 1160 | + |
|
| 1161 | + $prepend_code = []; |
|
| 1162 | + |
|
| 1163 | + foreach ($ordre as $p => $info) { |
|
| 1164 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1165 | + if (isset($plugin_valides[$p])) { |
|
| 1166 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1167 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1168 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1169 | + $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1170 | + if (isset($info['pipeline']) && is_array($info['pipeline'])) { |
|
| 1171 | + foreach ($info['pipeline'] as $pipe) { |
|
| 1172 | + $nom = $pipe['nom']; |
|
| 1173 | + if (isset($pipe['action'])) { |
|
| 1174 | + $action = $pipe['action']; |
|
| 1175 | + } else { |
|
| 1176 | + $action = $nom; |
|
| 1177 | + } |
|
| 1178 | + $nomlower = strtolower($nom); |
|
| 1179 | + if ( |
|
| 1180 | + $nomlower != $nom |
|
| 1181 | + && isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1182 | + && !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1183 | + ) { |
|
| 1184 | + $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1185 | + unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1186 | + } |
|
| 1187 | + $nom = $nomlower; |
|
| 1188 | + // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1189 | + if (!isset($GLOBALS['spip_pipeline'][$nom])) { // creer le pipeline eventuel |
|
| 1190 | + $GLOBALS['spip_pipeline'][$nom] = ''; |
|
| 1191 | + } |
|
| 1192 | + if ($action) { |
|
| 1193 | + if (!str_contains($GLOBALS['spip_pipeline'][$nom], (string) "|$prefix$action")) { |
|
| 1194 | + $GLOBALS['spip_pipeline'][$nom] = preg_replace( |
|
| 1195 | + ',(\|\||$),', |
|
| 1196 | + "|$prefix$action\\1", |
|
| 1197 | + $GLOBALS['spip_pipeline'][$nom], |
|
| 1198 | + 1 |
|
| 1199 | + ); |
|
| 1200 | + } |
|
| 1201 | + if (isset($pipe['inclure'])) { |
|
| 1202 | + $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1203 | + "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1204 | + } |
|
| 1205 | + } |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + if (isset($info['genie']) && (is_countable($info['genie']) ? count($info['genie']) : 0)) { |
|
| 1209 | + if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1210 | + $prepend_code['taches_generales_cron'] = ''; |
|
| 1211 | + } |
|
| 1212 | + foreach ($info['genie'] as $genie) { |
|
| 1213 | + $nom = $prefix . $genie['nom']; |
|
| 1214 | + $periode = max(60, intval($genie['periode'])); |
|
| 1215 | + if (charger_fonction($nom, 'genie', true)) { |
|
| 1216 | + $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1217 | + } else { |
|
| 1218 | + spip_logger()->error("Fonction genie_$nom introuvable"); |
|
| 1219 | + } |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + if (isset($info['style']) && (is_countable($info['style']) ? count($info['style']) : 0)) { |
|
| 1223 | + if (!isset($prepend_code['insert_head_css'])) { |
|
| 1224 | + $prepend_code['insert_head_css'] = ''; |
|
| 1225 | + } |
|
| 1226 | + if (!isset($prepend_code['header_prive_css'])) { |
|
| 1227 | + $prepend_code['header_prive_css'] = ''; |
|
| 1228 | + } |
|
| 1229 | + foreach ($info['style'] as $style) { |
|
| 1230 | + if (isset($style['path']) && $style['path']) { |
|
| 1231 | + $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1232 | + } else { |
|
| 1233 | + $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1234 | + } |
|
| 1235 | + $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1236 | + if (isset($style['media']) && strlen($style['media'])) { |
|
| 1237 | + $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1238 | + } |
|
| 1239 | + $code .= "/>';\n"; |
|
| 1240 | + if ($style['type'] != 'prive') { |
|
| 1241 | + $prepend_code['insert_head_css'] .= $code; |
|
| 1242 | + } |
|
| 1243 | + if ($style['type'] != 'public') { |
|
| 1244 | + $prepend_code['header_prive_css'] .= $code; |
|
| 1245 | + } |
|
| 1246 | + } |
|
| 1247 | + } |
|
| 1248 | + if (!isset($prepend_code['insert_head'])) { |
|
| 1249 | + $prepend_code['insert_head'] = ''; |
|
| 1250 | + } |
|
| 1251 | + if (!isset($prepend_code['header_prive'])) { |
|
| 1252 | + $prepend_code['header_prive'] = ''; |
|
| 1253 | + } |
|
| 1254 | + if (isset($info['script']) && (is_countable($info['script']) ? count($info['script']) : 0)) { |
|
| 1255 | + foreach ($info['script'] as $script) { |
|
| 1256 | + if (isset($script['path']) && $script['path']) { |
|
| 1257 | + $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1258 | + } else { |
|
| 1259 | + $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1260 | + } |
|
| 1261 | + $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1262 | + if ($script['type'] != 'prive') { |
|
| 1263 | + $prepend_code['insert_head'] .= $code; |
|
| 1264 | + } |
|
| 1265 | + if ($script['type'] != 'public') { |
|
| 1266 | + $prepend_code['header_prive'] .= $code; |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + } |
|
| 1270 | + } |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + $prepend_code['insert_head'] = |
|
| 1274 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1275 | + . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1276 | + . $prepend_code['insert_head']; |
|
| 1277 | + $prepend_code['header_prive'] = |
|
| 1278 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1279 | + . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1280 | + . $prepend_code['header_prive']; |
|
| 1281 | + |
|
| 1282 | + // on ajoute les pipe qui ont ete recenses manquants |
|
| 1283 | + foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1284 | + if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1285 | + $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1286 | + } |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + return $prepend_code; |
|
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | 1292 | /** |
@@ -1313,62 +1313,62 @@ discard block |
||
| 1313 | 1313 | **/ |
| 1314 | 1314 | function pipeline_precompile($prepend_code = []) { |
| 1315 | 1315 | |
| 1316 | - $all_pipes = $all_pipes_end = ''; |
|
| 1317 | - if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1318 | - $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1319 | - unset($GLOBALS['spip_pipeline']['all']); |
|
| 1320 | - $all_pipes = trim(array_shift($a)); |
|
| 1321 | - if ($all_pipes) { |
|
| 1322 | - $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1323 | - } |
|
| 1324 | - if (count($a)) { |
|
| 1325 | - $all_pipes_end = '||' . array_shift($a); |
|
| 1326 | - } |
|
| 1327 | - } |
|
| 1328 | - $content = ''; |
|
| 1329 | - foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1330 | - $s_inc = ''; |
|
| 1331 | - $s_call = ''; |
|
| 1332 | - if ($all_pipes) { |
|
| 1333 | - $pipeline = preg_replace(',(\|\||$),', "$all_pipes\\1", $pipeline, 1); |
|
| 1334 | - } |
|
| 1335 | - if ($all_pipes_end) { |
|
| 1336 | - $pipeline .= $all_pipes_end; |
|
| 1337 | - } |
|
| 1338 | - $pipe = array_filter(explode('|', $pipeline)); |
|
| 1339 | - // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1340 | - foreach ($pipe as $fonc) { |
|
| 1341 | - $fonc = trim($fonc); |
|
| 1342 | - $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1343 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1344 | - $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1345 | - $file = "'$file'"; |
|
| 1346 | - // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1347 | - if (preg_match(',(_(DIR|ROOT)_[A-Z_]+):,Ums', $file, $regs)) { |
|
| 1348 | - $dir = $regs[1]; |
|
| 1349 | - $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1350 | - if (defined($root_dir)) { |
|
| 1351 | - $dir = $root_dir; |
|
| 1352 | - } |
|
| 1353 | - $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1354 | - $file = str_replace("''.", '', $file); |
|
| 1355 | - $file = str_replace(constant($dir), '', $file); |
|
| 1356 | - } |
|
| 1357 | - $s_inc .= "include_once_check($file);\n"; |
|
| 1358 | - } |
|
| 1359 | - } |
|
| 1360 | - if (strlen($s_inc)) { |
|
| 1361 | - $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1362 | - } |
|
| 1363 | - $content .= "// Pipeline $action \n" |
|
| 1364 | - . "function execute_pipeline_$action(&\$val){\n" |
|
| 1365 | - . $s_inc |
|
| 1366 | - . ((isset($prepend_code[$action]) && strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1367 | - . $s_call |
|
| 1368 | - . "return \$val;\n}\n"; |
|
| 1369 | - } |
|
| 1370 | - ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1371 | - clear_path_cache(); |
|
| 1316 | + $all_pipes = $all_pipes_end = ''; |
|
| 1317 | + if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1318 | + $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1319 | + unset($GLOBALS['spip_pipeline']['all']); |
|
| 1320 | + $all_pipes = trim(array_shift($a)); |
|
| 1321 | + if ($all_pipes) { |
|
| 1322 | + $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1323 | + } |
|
| 1324 | + if (count($a)) { |
|
| 1325 | + $all_pipes_end = '||' . array_shift($a); |
|
| 1326 | + } |
|
| 1327 | + } |
|
| 1328 | + $content = ''; |
|
| 1329 | + foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1330 | + $s_inc = ''; |
|
| 1331 | + $s_call = ''; |
|
| 1332 | + if ($all_pipes) { |
|
| 1333 | + $pipeline = preg_replace(',(\|\||$),', "$all_pipes\\1", $pipeline, 1); |
|
| 1334 | + } |
|
| 1335 | + if ($all_pipes_end) { |
|
| 1336 | + $pipeline .= $all_pipes_end; |
|
| 1337 | + } |
|
| 1338 | + $pipe = array_filter(explode('|', $pipeline)); |
|
| 1339 | + // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1340 | + foreach ($pipe as $fonc) { |
|
| 1341 | + $fonc = trim($fonc); |
|
| 1342 | + $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1343 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1344 | + $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1345 | + $file = "'$file'"; |
|
| 1346 | + // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1347 | + if (preg_match(',(_(DIR|ROOT)_[A-Z_]+):,Ums', $file, $regs)) { |
|
| 1348 | + $dir = $regs[1]; |
|
| 1349 | + $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1350 | + if (defined($root_dir)) { |
|
| 1351 | + $dir = $root_dir; |
|
| 1352 | + } |
|
| 1353 | + $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1354 | + $file = str_replace("''.", '', $file); |
|
| 1355 | + $file = str_replace(constant($dir), '', $file); |
|
| 1356 | + } |
|
| 1357 | + $s_inc .= "include_once_check($file);\n"; |
|
| 1358 | + } |
|
| 1359 | + } |
|
| 1360 | + if (strlen($s_inc)) { |
|
| 1361 | + $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1362 | + } |
|
| 1363 | + $content .= "// Pipeline $action \n" |
|
| 1364 | + . "function execute_pipeline_$action(&\$val){\n" |
|
| 1365 | + . $s_inc |
|
| 1366 | + . ((isset($prepend_code[$action]) && strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1367 | + . $s_call |
|
| 1368 | + . "return \$val;\n}\n"; |
|
| 1369 | + } |
|
| 1370 | + ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1371 | + clear_path_cache(); |
|
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | 1374 | |
@@ -1381,12 +1381,12 @@ discard block |
||
| 1381 | 1381 | * true si le plugin est actif, false sinon |
| 1382 | 1382 | **/ |
| 1383 | 1383 | function plugin_est_installe($plug_path) { |
| 1384 | - $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : []; |
|
| 1385 | - if (!$plugin_installes) { |
|
| 1386 | - return false; |
|
| 1387 | - } |
|
| 1384 | + $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : []; |
|
| 1385 | + if (!$plugin_installes) { |
|
| 1386 | + return false; |
|
| 1387 | + } |
|
| 1388 | 1388 | |
| 1389 | - return in_array($plug_path, $plugin_installes); |
|
| 1389 | + return in_array($plug_path, $plugin_installes); |
|
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | 1392 | |
@@ -1399,46 +1399,46 @@ discard block |
||
| 1399 | 1399 | * @uses plugins_installer_dist() |
| 1400 | 1400 | **/ |
| 1401 | 1401 | function plugin_installes_meta() { |
| 1402 | - if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1403 | - // attendre eventuellement l'invalidation du cache opcode |
|
| 1404 | - spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1405 | - } |
|
| 1406 | - |
|
| 1407 | - $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1408 | - $meta_plug_installes = []; |
|
| 1409 | - foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1410 | - if ($plug = $resume['dir']) { |
|
| 1411 | - $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1412 | - if ($infos) { |
|
| 1413 | - if (!is_array($infos) || $infos['install_test'][0]) { |
|
| 1414 | - $meta_plug_installes[] = $plug; |
|
| 1415 | - } |
|
| 1416 | - if (is_array($infos)) { |
|
| 1417 | - [$ok, $trace] = $infos['install_test']; |
|
| 1418 | - $titre = _T('plugin_titre_installation', ['plugin' => typo($infos['nom'])]); |
|
| 1419 | - $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
|
| 1420 | - if (_IS_CLI) { |
|
| 1421 | - include_spip('inc/filtres'); |
|
| 1422 | - $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1423 | - $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1424 | - echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1425 | - $trace, |
|
| 1426 | - "\n"; |
|
| 1427 | - } |
|
| 1428 | - else { |
|
| 1429 | - include_spip('inc/filtres_boites'); |
|
| 1430 | - echo "<div class='install-plugins svp_retour'>" |
|
| 1431 | - . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
|
| 1432 | - . $trace |
|
| 1433 | - . "<div class='result'>$result</div>" |
|
| 1434 | - . boite_fermer() |
|
| 1435 | - . '</div>'; |
|
| 1436 | - } |
|
| 1437 | - } |
|
| 1438 | - } |
|
| 1439 | - } |
|
| 1440 | - } |
|
| 1441 | - ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1402 | + if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1403 | + // attendre eventuellement l'invalidation du cache opcode |
|
| 1404 | + spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1405 | + } |
|
| 1406 | + |
|
| 1407 | + $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1408 | + $meta_plug_installes = []; |
|
| 1409 | + foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1410 | + if ($plug = $resume['dir']) { |
|
| 1411 | + $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1412 | + if ($infos) { |
|
| 1413 | + if (!is_array($infos) || $infos['install_test'][0]) { |
|
| 1414 | + $meta_plug_installes[] = $plug; |
|
| 1415 | + } |
|
| 1416 | + if (is_array($infos)) { |
|
| 1417 | + [$ok, $trace] = $infos['install_test']; |
|
| 1418 | + $titre = _T('plugin_titre_installation', ['plugin' => typo($infos['nom'])]); |
|
| 1419 | + $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
|
| 1420 | + if (_IS_CLI) { |
|
| 1421 | + include_spip('inc/filtres'); |
|
| 1422 | + $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1423 | + $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1424 | + echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1425 | + $trace, |
|
| 1426 | + "\n"; |
|
| 1427 | + } |
|
| 1428 | + else { |
|
| 1429 | + include_spip('inc/filtres_boites'); |
|
| 1430 | + echo "<div class='install-plugins svp_retour'>" |
|
| 1431 | + . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
|
| 1432 | + . $trace |
|
| 1433 | + . "<div class='result'>$result</div>" |
|
| 1434 | + . boite_fermer() |
|
| 1435 | + . '</div>'; |
|
| 1436 | + } |
|
| 1437 | + } |
|
| 1438 | + } |
|
| 1439 | + } |
|
| 1440 | + } |
|
| 1441 | + ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1442 | 1442 | } |
| 1443 | 1443 | |
| 1444 | 1444 | /** |
@@ -1452,29 +1452,29 @@ discard block |
||
| 1452 | 1452 | * Commentaire : code écrit en tout début de fichier, après la balise PHP ouvrante |
| 1453 | 1453 | **/ |
| 1454 | 1454 | function ecrire_fichier_php($nom, $contenu, $comment = '') { |
| 1455 | - if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1456 | - $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1460 | - // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1461 | - // si pas de modif on ne touche pas au fichier initial |
|
| 1462 | - if (file_exists($nom)) { |
|
| 1463 | - if (str_ends_with($nom, '.php')) { |
|
| 1464 | - $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1465 | - } |
|
| 1466 | - else { |
|
| 1467 | - $fichier_tmp = $nom . '.tmp'; |
|
| 1468 | - } |
|
| 1469 | - file_put_contents($fichier_tmp, $contenu); |
|
| 1470 | - if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1471 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1472 | - @unlink($fichier_tmp); |
|
| 1473 | - return; |
|
| 1474 | - } |
|
| 1475 | - @unlink($fichier_tmp); |
|
| 1476 | - } |
|
| 1477 | - ecrire_fichier($nom, $contenu); |
|
| 1478 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1479 | - spip_clear_opcode_cache(realpath($nom)); |
|
| 1455 | + if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1456 | + $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1460 | + // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1461 | + // si pas de modif on ne touche pas au fichier initial |
|
| 1462 | + if (file_exists($nom)) { |
|
| 1463 | + if (str_ends_with($nom, '.php')) { |
|
| 1464 | + $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1465 | + } |
|
| 1466 | + else { |
|
| 1467 | + $fichier_tmp = $nom . '.tmp'; |
|
| 1468 | + } |
|
| 1469 | + file_put_contents($fichier_tmp, $contenu); |
|
| 1470 | + if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1471 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1472 | + @unlink($fichier_tmp); |
|
| 1473 | + return; |
|
| 1474 | + } |
|
| 1475 | + @unlink($fichier_tmp); |
|
| 1476 | + } |
|
| 1477 | + ecrire_fichier($nom, $contenu); |
|
| 1478 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1479 | + spip_clear_opcode_cache(realpath($nom)); |
|
| 1480 | 1480 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | /** l'adresse du repertoire de telechargement et de decompactage des plugins */ |
| 23 | 23 | if (!defined('_DIR_PLUGINS_AUTO')) { |
| 24 | - define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 24 | + define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS.'auto/'); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins. |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | if ($dir) { |
| 379 | 379 | $dir .= '/'; |
| 380 | 380 | } |
| 381 | - $dir .= 'procure:' . $procure['nom']; |
|
| 381 | + $dir .= 'procure:'.$procure['nom']; |
|
| 382 | 382 | |
| 383 | 383 | $procure['etat'] = '?'; |
| 384 | 384 | $procure['dir_type'] = $resume['dir_type']; |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | $plug = $resume['dir']; |
| 559 | 559 | $k = $infos[$dir_type][$plug]; |
| 560 | 560 | |
| 561 | - $plug = constant($dir_type) . $plug; |
|
| 561 | + $plug = constant($dir_type).$plug; |
|
| 562 | 562 | if (!isset($msg[$p])) { |
| 563 | 563 | if (isset($resume['erreur']) && $resume['erreur']) { |
| 564 | 564 | $msg[$p] = [$resume['erreur']]; |
@@ -601,10 +601,10 @@ discard block |
||
| 601 | 601 | $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
| 602 | 602 | } elseif (!$raw) { |
| 603 | 603 | foreach ($list as $plug => $msg) { |
| 604 | - $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 605 | - . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 604 | + $list[$plug] = '<li>'._T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 605 | + . '<ul><li>'.implode('</li><li>', $msg).'</li></ul></li>'; |
|
| 606 | 606 | } |
| 607 | - $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 607 | + $list = '<ul>'.join("\n", $list).'</ul>'; |
|
| 608 | 608 | } |
| 609 | 609 | if ($raz) { |
| 610 | 610 | effacer_meta('plugin_erreur_activation'); |
@@ -718,13 +718,13 @@ discard block |
||
| 718 | 718 | if ($minimum_inclus && spip_version_compare($version, $minimum, '<')) { |
| 719 | 719 | return _T("plugin_{$balise}_{$type}", [ |
| 720 | 720 | 'plugin' => $nom, |
| 721 | - 'version' => ' ≥ ' . $minimum |
|
| 721 | + 'version' => ' ≥ '.$minimum |
|
| 722 | 722 | ]); |
| 723 | 723 | } |
| 724 | 724 | if (!$minimum_inclus && spip_version_compare($version, $minimum, '<=')) { |
| 725 | 725 | return _T("plugin_{$balise}_{$type}", [ |
| 726 | 726 | 'plugin' => $nom, |
| 727 | - 'version' => ' > ' . $minimum |
|
| 727 | + 'version' => ' > '.$minimum |
|
| 728 | 728 | ]); |
| 729 | 729 | } |
| 730 | 730 | } |
@@ -733,13 +733,13 @@ discard block |
||
| 733 | 733 | if ($maximum_inclus && spip_version_compare($version, $maximum, '>')) { |
| 734 | 734 | return _T("plugin_{$balise}_{$type}", [ |
| 735 | 735 | 'plugin' => $nom, |
| 736 | - 'version' => ' ≤ ' . $maximum |
|
| 736 | + 'version' => ' ≤ '.$maximum |
|
| 737 | 737 | ]); |
| 738 | 738 | } |
| 739 | 739 | if (!$maximum_inclus && spip_version_compare($version, $maximum, '>=')) { |
| 740 | 740 | return _T("plugin_{$balise}_plugin", [ |
| 741 | 741 | 'plugin' => $nom, |
| 742 | - 'version' => ' < ' . $maximum |
|
| 742 | + 'version' => ' < '.$maximum |
|
| 743 | 743 | ]); |
| 744 | 744 | } |
| 745 | 745 | } |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | include_spip('inc/charger_plugin'); |
| 759 | 759 | $url = '<br />' . bouton_telechargement_plugin($url, 'lib'); |
| 760 | 760 | }*/ |
| 761 | - return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 761 | + return _T('plugin_necessite_lib', ['lib' => $lib])." <a href='$url'>$url</a>"; |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | foreach ($plugin_valides as $p => $resume) { |
| 858 | 858 | // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
| 859 | 859 | if (!str_starts_with($p, 'PHP:') && $p !== 'PHP') { |
| 860 | - $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 860 | + $header[] = $p.($resume['version'] ? '('.$resume['version'].')' : ''); |
|
| 861 | 861 | } |
| 862 | 862 | if ($resume['dir']) { |
| 863 | 863 | foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
@@ -882,11 +882,11 @@ discard block |
||
| 882 | 882 | $header = strtolower(implode(',', $header)); |
| 883 | 883 | if (!isset($GLOBALS['spip_header_silencieux']) || !$GLOBALS['spip_header_silencieux']) { |
| 884 | 884 | ecrire_fichier( |
| 885 | - _DIR_VAR . 'config.txt', |
|
| 886 | - (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 885 | + _DIR_VAR.'config.txt', |
|
| 886 | + (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP').' '.$GLOBALS['spip_version_affichee'].' @ www.spip.net + '.$header |
|
| 887 | 887 | ); |
| 888 | 888 | } else { |
| 889 | - @unlink(_DIR_VAR . 'config.txt'); |
|
| 889 | + @unlink(_DIR_VAR.'config.txt'); |
|
| 890 | 890 | } |
| 891 | 891 | // generer charger_plugins_chemin.php |
| 892 | 892 | plugins_precompile_chemin($plugin_valides, $ordre); |
@@ -940,7 +940,7 @@ discard block |
||
| 940 | 940 | // definir le plugin, donc le path avant l'include du fichier options |
| 941 | 941 | // permet de faire des include_spip pour attraper un inc_ du plugin |
| 942 | 942 | |
| 943 | - $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 943 | + $dir = $dir_type.".'".$plug."/'"; |
|
| 944 | 944 | |
| 945 | 945 | $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
| 946 | 946 | if ( |
@@ -951,7 +951,7 @@ discard block |
||
| 951 | 951 | if (!$info['chemin']) { |
| 952 | 952 | $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
| 953 | 953 | $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
| 954 | - if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 954 | + if (is_dir(constant($dir_type).$plug.'/squelettes/')) { |
|
| 955 | 955 | $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
| 956 | 956 | } |
| 957 | 957 | } |
@@ -973,13 +973,13 @@ discard block |
||
| 973 | 973 | $dir = ''; |
| 974 | 974 | } |
| 975 | 975 | if (strlen($dir)) { |
| 976 | - $dir = rtrim($dir, '/') . '/'; |
|
| 976 | + $dir = rtrim($dir, '/').'/'; |
|
| 977 | 977 | } |
| 978 | 978 | if (!isset($chemin['type']) || $chemin['type'] == 'public') { |
| 979 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 979 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : ''); |
|
| 980 | 980 | } |
| 981 | 981 | if (!isset($chemin['type']) || $chemin['type'] == 'prive') { |
| 982 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 982 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : ''); |
|
| 983 | 983 | } |
| 984 | 984 | } |
| 985 | 985 | } |
@@ -988,11 +988,11 @@ discard block |
||
| 988 | 988 | } |
| 989 | 989 | } |
| 990 | 990 | if (count($chemins['public']) || count($chemins['prive'])) { |
| 991 | - $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 991 | + $contenu .= 'if (_DIR_RESTREINT) _chemin(['.implode( |
|
| 992 | 992 | ',', |
| 993 | 993 | array_reverse($chemins['public']) |
| 994 | - ) . "]);\n" |
|
| 995 | - . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 994 | + )."]);\n" |
|
| 995 | + . 'else _chemin(['.implode(',', array_reverse($chemins['prive']))."]);\n"; |
|
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
@@ -1041,7 +1041,7 @@ discard block |
||
| 1041 | 1041 | && !str_contains($dir, ':') |
| 1042 | 1042 | && file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
| 1043 | 1043 | ) { |
| 1044 | - if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1044 | + if (is_readable("$dir$plug/".($file = $info['prefix'].'_'.$charge.'.php'))) { |
|
| 1045 | 1045 | $info[$charge] = [$file]; |
| 1046 | 1046 | } |
| 1047 | 1047 | } |
@@ -1056,7 +1056,7 @@ discard block |
||
| 1056 | 1056 | ) { |
| 1057 | 1057 | unset($info[$charge][$k]); |
| 1058 | 1058 | } else { |
| 1059 | - $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1059 | + $_file = $root_dir_type.".'$plug/$file'"; |
|
| 1060 | 1060 | $contenu[$charge] .= "include_once_check($_file);\n"; |
| 1061 | 1061 | } |
| 1062 | 1062 | } |
@@ -1066,7 +1066,7 @@ discard block |
||
| 1066 | 1066 | } |
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | - $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1069 | + $contenu['options'] = "define('_PLUGINS_HASH','".md5($sign)."');\n".$contenu['options']; |
|
| 1070 | 1070 | $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
| 1071 | 1071 | . plugin_ongletbouton('onglets_plugins', $onglets); |
| 1072 | 1072 | |
@@ -1101,12 +1101,12 @@ discard block |
||
| 1101 | 1101 | define("_UPDATED_$nom", $val); |
| 1102 | 1102 | define("_UPDATED_md5_$nom", $md5); |
| 1103 | 1103 | } |
| 1104 | - $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1104 | + $val = "unserialize('".str_replace("'", "\'", $val)."')"; |
|
| 1105 | 1105 | |
| 1106 | 1106 | return |
| 1107 | 1107 | "if (!function_exists('$nom')) {\n" |
| 1108 | 1108 | . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
| 1109 | - . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1109 | + . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'".$md5."';}\n" |
|
| 1110 | 1110 | . "}\n"; |
| 1111 | 1111 | } |
| 1112 | 1112 | |
@@ -1129,7 +1129,7 @@ discard block |
||
| 1129 | 1129 | if (@is_readable(_CACHE_PLUGINS_OPT)) { |
| 1130 | 1130 | include_once(_CACHE_PLUGINS_OPT); |
| 1131 | 1131 | } else { |
| 1132 | - spip_logger()->info('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1132 | + spip_logger()->info('pipelines desactives: impossible de produire '._CACHE_PLUGINS_OPT); |
|
| 1133 | 1133 | } |
| 1134 | 1134 | } |
| 1135 | 1135 | |
@@ -1166,7 +1166,7 @@ discard block |
||
| 1166 | 1166 | $dir_type = $plugin_valides[$p]['dir_type']; |
| 1167 | 1167 | $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
| 1168 | 1168 | $plug = $plugin_valides[$p]['dir']; |
| 1169 | - $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1169 | + $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'].'_'); |
|
| 1170 | 1170 | if (isset($info['pipeline']) && is_array($info['pipeline'])) { |
| 1171 | 1171 | foreach ($info['pipeline'] as $pipe) { |
| 1172 | 1172 | $nom = $pipe['nom']; |
@@ -1200,7 +1200,7 @@ discard block |
||
| 1200 | 1200 | } |
| 1201 | 1201 | if (isset($pipe['inclure'])) { |
| 1202 | 1202 | $GLOBALS['spip_matrice']["$prefix$action"] = |
| 1203 | - "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1203 | + "$root_dir_type:$plug/".$pipe['inclure']; |
|
| 1204 | 1204 | } |
| 1205 | 1205 | } |
| 1206 | 1206 | } |
@@ -1210,7 +1210,7 @@ discard block |
||
| 1210 | 1210 | $prepend_code['taches_generales_cron'] = ''; |
| 1211 | 1211 | } |
| 1212 | 1212 | foreach ($info['genie'] as $genie) { |
| 1213 | - $nom = $prefix . $genie['nom']; |
|
| 1213 | + $nom = $prefix.$genie['nom']; |
|
| 1214 | 1214 | $periode = max(60, intval($genie['periode'])); |
| 1215 | 1215 | if (charger_fonction($nom, 'genie', true)) { |
| 1216 | 1216 | $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
@@ -1228,13 +1228,13 @@ discard block |
||
| 1228 | 1228 | } |
| 1229 | 1229 | foreach ($info['style'] as $style) { |
| 1230 | 1230 | if (isset($style['path']) && $style['path']) { |
| 1231 | - $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1231 | + $code = "if (\$f=timestamp(direction_css(find_in_path('".addslashes($style['path'])."')))) "; |
|
| 1232 | 1232 | } else { |
| 1233 | - $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1233 | + $code = "if (\$f='".addslashes($style['url'])."') "; |
|
| 1234 | 1234 | } |
| 1235 | 1235 | $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
| 1236 | 1236 | if (isset($style['media']) && strlen($style['media'])) { |
| 1237 | - $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1237 | + $code .= ' media="'.addslashes($style['media']).'"'; |
|
| 1238 | 1238 | } |
| 1239 | 1239 | $code .= "/>';\n"; |
| 1240 | 1240 | if ($style['type'] != 'prive') { |
@@ -1254,9 +1254,9 @@ discard block |
||
| 1254 | 1254 | if (isset($info['script']) && (is_countable($info['script']) ? count($info['script']) : 0)) { |
| 1255 | 1255 | foreach ($info['script'] as $script) { |
| 1256 | 1256 | if (isset($script['path']) && $script['path']) { |
| 1257 | - $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1257 | + $code = "if (\$f=timestamp(find_in_path('".addslashes($script['path'])."'))) "; |
|
| 1258 | 1258 | } else { |
| 1259 | - $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1259 | + $code = "if (\$f='".addslashes($script['url'])."') "; |
|
| 1260 | 1260 | } |
| 1261 | 1261 | $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
| 1262 | 1262 | if ($script['type'] != 'prive') { |
@@ -1319,10 +1319,10 @@ discard block |
||
| 1319 | 1319 | unset($GLOBALS['spip_pipeline']['all']); |
| 1320 | 1320 | $all_pipes = trim(array_shift($a)); |
| 1321 | 1321 | if ($all_pipes) { |
| 1322 | - $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1322 | + $all_pipes = '|'.ltrim($all_pipes, '|'); |
|
| 1323 | 1323 | } |
| 1324 | 1324 | if (count($a)) { |
| 1325 | - $all_pipes_end = '||' . array_shift($a); |
|
| 1325 | + $all_pipes_end = '||'.array_shift($a); |
|
| 1326 | 1326 | } |
| 1327 | 1327 | } |
| 1328 | 1328 | $content = ''; |
@@ -1339,7 +1339,7 @@ discard block |
||
| 1339 | 1339 | // Eclater le pipeline en filtres et appliquer chaque filtre |
| 1340 | 1340 | foreach ($pipe as $fonc) { |
| 1341 | 1341 | $fonc = trim($fonc); |
| 1342 | - $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1342 | + $s_call .= '$val = minipipe(\''.$fonc.'\', $val);'."\n"; |
|
| 1343 | 1343 | if (isset($GLOBALS['spip_matrice'][$fonc])) { |
| 1344 | 1344 | $file = $GLOBALS['spip_matrice'][$fonc]; |
| 1345 | 1345 | $file = "'$file'"; |
@@ -1350,7 +1350,7 @@ discard block |
||
| 1350 | 1350 | if (defined($root_dir)) { |
| 1351 | 1351 | $dir = $root_dir; |
| 1352 | 1352 | } |
| 1353 | - $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1353 | + $file = str_replace($regs[0], "'.".$dir.".'", $file); |
|
| 1354 | 1354 | $file = str_replace("''.", '', $file); |
| 1355 | 1355 | $file = str_replace(constant($dir), '', $file); |
| 1356 | 1356 | } |
@@ -1363,7 +1363,7 @@ discard block |
||
| 1363 | 1363 | $content .= "// Pipeline $action \n" |
| 1364 | 1364 | . "function execute_pipeline_$action(&\$val){\n" |
| 1365 | 1365 | . $s_inc |
| 1366 | - . ((isset($prepend_code[$action]) && strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1366 | + . ((isset($prepend_code[$action]) && strlen($prepend_code[$action])) ? trim($prepend_code[$action])."\n" : '') |
|
| 1367 | 1367 | . $s_call |
| 1368 | 1368 | . "return \$val;\n}\n"; |
| 1369 | 1369 | } |
@@ -1419,9 +1419,9 @@ discard block |
||
| 1419 | 1419 | $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
| 1420 | 1420 | if (_IS_CLI) { |
| 1421 | 1421 | include_spip('inc/filtres'); |
| 1422 | - $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1423 | - $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1424 | - echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1422 | + $trace = ltrim(textebrut($trace)."\n".$result); |
|
| 1423 | + $trace = ' '.str_replace("\n", "\n ", $trace); |
|
| 1424 | + echo "\n".($ok ? 'OK ' : '/!\ ').textebrut($titre)."\n", |
|
| 1425 | 1425 | $trace, |
| 1426 | 1426 | "\n"; |
| 1427 | 1427 | } |
@@ -1456,15 +1456,15 @@ discard block |
||
| 1456 | 1456 | $GLOBALS['fichier_php_compile_recent'] = 0; |
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | - $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1459 | + $contenu = '<'.'?php'."\n".$comment."\nif (defined('_ECRIRE_INC_VERSION')) {\n".$contenu."}\n?".'>'; |
|
| 1460 | 1460 | // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
| 1461 | 1461 | // si pas de modif on ne touche pas au fichier initial |
| 1462 | 1462 | if (file_exists($nom)) { |
| 1463 | 1463 | if (str_ends_with($nom, '.php')) { |
| 1464 | - $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1464 | + $fichier_tmp = substr($nom, 0, -4).'.tmp.php'; |
|
| 1465 | 1465 | } |
| 1466 | 1466 | else { |
| 1467 | - $fichier_tmp = $nom . '.tmp'; |
|
| 1467 | + $fichier_tmp = $nom.'.tmp'; |
|
| 1468 | 1468 | } |
| 1469 | 1469 | file_put_contents($fichier_tmp, $contenu); |
| 1470 | 1470 | if (md5_file($nom) == md5_file($fichier_tmp)) { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * @package SPIP\Core\Minipres |
| 18 | 18 | **/ |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -37,19 +37,19 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | function install_debut_html($titre = 'AUTO', $onLoad = '', $all_inline = false) { |
| 39 | 39 | |
| 40 | - if ($onLoad) { |
|
| 41 | - include_spip('inc/filtres'); |
|
| 42 | - $onLoad = extraire_attribut("<body $onLoad>", 'onload'); |
|
| 43 | - } |
|
| 40 | + if ($onLoad) { |
|
| 41 | + include_spip('inc/filtres'); |
|
| 42 | + $onLoad = extraire_attribut("<body $onLoad>", 'onload'); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - $options = [ |
|
| 46 | - 'all_inline' => $all_inline, |
|
| 47 | - 'onload' => $onLoad, |
|
| 48 | - 'titre' => $titre, |
|
| 49 | - ]; |
|
| 45 | + $options = [ |
|
| 46 | + 'all_inline' => $all_inline, |
|
| 47 | + 'onload' => $onLoad, |
|
| 48 | + 'titre' => $titre, |
|
| 49 | + ]; |
|
| 50 | 50 | |
| 51 | - $minipage = new Admin(); |
|
| 52 | - return $minipage->installDebutPage($options); |
|
| 51 | + $minipage = new Admin(); |
|
| 52 | + return $minipage->installDebutPage($options); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | * @return string Code HTML |
| 62 | 62 | */ |
| 63 | 63 | function install_fin_html() { |
| 64 | - $minipage = new Admin(); |
|
| 65 | - return $minipage->installFinPage(); |
|
| 64 | + $minipage = new Admin(); |
|
| 65 | + return $minipage->installFinPage(); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | |
@@ -101,23 +101,23 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | function minipres($titre = '', $corps = '', $options = []) { |
| 103 | 103 | |
| 104 | - // compat signature old |
|
| 105 | - // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 106 | - $args = func_get_args(); |
|
| 107 | - if (isset($args[2]) && is_string($args[2])) { |
|
| 108 | - $options = ['onload' => $args[2]]; |
|
| 109 | - } |
|
| 110 | - if (isset($args[3])) { |
|
| 111 | - $options['all_inline'] = $args[3]; |
|
| 112 | - } |
|
| 104 | + // compat signature old |
|
| 105 | + // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 106 | + $args = func_get_args(); |
|
| 107 | + if (isset($args[2]) && is_string($args[2])) { |
|
| 108 | + $options = ['onload' => $args[2]]; |
|
| 109 | + } |
|
| 110 | + if (isset($args[3])) { |
|
| 111 | + $options['all_inline'] = $args[3]; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - $options = array_merge([ |
|
| 115 | - 'onload' => '', |
|
| 116 | - 'all_inline' => false, |
|
| 117 | - ], $options); |
|
| 114 | + $options = array_merge([ |
|
| 115 | + 'onload' => '', |
|
| 116 | + 'all_inline' => false, |
|
| 117 | + ], $options); |
|
| 118 | 118 | |
| 119 | - $options['titre'] = $titre; |
|
| 119 | + $options['titre'] = $titre; |
|
| 120 | 120 | |
| 121 | - $minipage = new Admin(); |
|
| 122 | - return $minipage->page($corps, $options); |
|
| 121 | + $minipage = new Admin(); |
|
| 122 | + return $minipage->page($corps, $options); |
|
| 123 | 123 | } |
@@ -43,13 +43,13 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | if (is_null($liste_langues)) { |
| 46 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 46 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '').','.($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 47 | 47 | } else { |
| 48 | 48 | if (is_array($liste_langues)) { |
| 49 | 49 | $liste_langues = implode(',', $liste_langues); |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 52 | + $liste_langues = ','.$liste_langues.','; |
|
| 53 | 53 | |
| 54 | 54 | // Si la langue demandee n'existe pas, on essaie d'autres variantes |
| 55 | 55 | // Exemple : 'pt-br' => 'pt_br' => 'pt' |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | } |
| 192 | 192 | foreach ($langues as $l) { |
| 193 | 193 | $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
| 194 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 194 | + $ret .= "<option value='$l'$selected>[".$l.'] '.traduire_nom_langue($l)."</option>\n"; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | if (!test_espace_prive()) { |
@@ -209,21 +209,20 @@ discard block |
||
| 209 | 209 | $base, |
| 210 | 210 | $cible, |
| 211 | 211 | (select_langues($nom_select, $change, $ret) |
| 212 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 212 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='"._T('bouton_changer')."' /></div></noscript>"), |
|
| 213 | 213 | " method='post'" |
| 214 | 214 | ); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | function select_langues($nom_select, $change, $options, $label = '') { |
| 218 | 218 | static $cpt = 0; |
| 219 | - $id = 'menu_langues' . $cpt++; |
|
| 219 | + $id = 'menu_langues'.$cpt++; |
|
| 220 | 220 | |
| 221 | 221 | return |
| 222 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 222 | + "<label for='$id'>".($label ?: _T('info_langues')).'</label> '. |
|
| 223 | 223 | "<select name='$nom_select' id='$id' " |
| 224 | 224 | . ((test_espace_prive()) ? |
| 225 | - (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 226 | - ("class='forml menu_langues'")) |
|
| 225 | + (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : ("class='forml menu_langues'")) |
|
| 227 | 226 | . $change |
| 228 | 227 | . ">\n" |
| 229 | 228 | . $options |
@@ -346,7 +345,7 @@ discard block |
||
| 346 | 345 | isset($GLOBALS['meta']['langue_site']) |
| 347 | 346 | && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
| 348 | 347 | ) { |
| 349 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 348 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues); //@:install |
|
| 350 | 349 | } |
| 351 | 350 | // en theorie là, la globale est définie, sinon c'est un problème. |
| 352 | 351 | if (!isset($GLOBALS['spip_lang'])) { |
@@ -458,7 +457,7 @@ discard block |
||
| 458 | 457 | if (!isset($GLOBALS['meta']['langue_site'])) { |
| 459 | 458 | // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
| 460 | 459 | $GLOBALS['meta']['langue_site'] = $tout = |
| 461 | - (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 460 | + (!$all_langs || str_contains(','._LANGUE_PAR_DEFAUT.',', (string) ",$all_langs,")) |
|
| 462 | 461 | ? _LANGUE_PAR_DEFAUT |
| 463 | 462 | : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
| 464 | 463 | ecrire_meta('langue_site', $tout); |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Langue |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | |
@@ -38,35 +38,35 @@ discard block |
||
| 38 | 38 | **/ |
| 39 | 39 | function changer_langue($lang, $liste_langues = null) { |
| 40 | 40 | |
| 41 | - if (empty($lang)) { |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if (is_null($liste_langues)) { |
|
| 46 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 47 | - } else { |
|
| 48 | - if (is_array($liste_langues)) { |
|
| 49 | - $liste_langues = implode(',', $liste_langues); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 53 | - |
|
| 54 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 55 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 56 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 57 | - |
|
| 58 | - if ( |
|
| 59 | - str_contains($liste_langues, (string) ",$lang,") |
|
| 60 | - || ($lang = preg_replace(',_.*,', '', $lang)) && str_contains($liste_langues, (string) ",$lang,") |
|
| 61 | - ) { |
|
| 62 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 63 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 64 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 65 | - |
|
| 66 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 67 | - } else { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 41 | + if (empty($lang)) { |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if (is_null($liste_langues)) { |
|
| 46 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 47 | + } else { |
|
| 48 | + if (is_array($liste_langues)) { |
|
| 49 | + $liste_langues = implode(',', $liste_langues); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + $liste_langues = ',' . $liste_langues . ','; |
|
| 53 | + |
|
| 54 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 55 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 56 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 57 | + |
|
| 58 | + if ( |
|
| 59 | + str_contains($liste_langues, (string) ",$lang,") |
|
| 60 | + || ($lang = preg_replace(',_.*,', '', $lang)) && str_contains($liste_langues, (string) ",$lang,") |
|
| 61 | + ) { |
|
| 62 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 63 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 64 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 65 | + |
|
| 66 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 67 | + } else { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | // |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 80 | 80 | |
| 81 | 81 | function choisir_traduction($trads, $lang = '') { |
| 82 | - $k = approcher_langue($trads, $lang); |
|
| 82 | + $k = approcher_langue($trads, $lang); |
|
| 83 | 83 | |
| 84 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 84 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // retourne son 2e argument si c'est un index du premier |
@@ -89,21 +89,21 @@ discard block |
||
| 89 | 89 | // la langue X etant consideree comme une approche de X_Y |
| 90 | 90 | function approcher_langue($trads, $lang = '') { |
| 91 | 91 | |
| 92 | - if (!$lang) { |
|
| 93 | - $lang = $GLOBALS['spip_lang']; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if (isset($trads[$lang])) { |
|
| 97 | - return $lang; |
|
| 98 | - } // cas des langues xx_yy |
|
| 99 | - else { |
|
| 100 | - $r = explode('_', (string) $lang); |
|
| 101 | - if (isset($trads[$r[0]])) { |
|
| 102 | - return $r[0]; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return ''; |
|
| 92 | + if (!$lang) { |
|
| 93 | + $lang = $GLOBALS['spip_lang']; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if (isset($trads[$lang])) { |
|
| 97 | + return $lang; |
|
| 98 | + } // cas des langues xx_yy |
|
| 99 | + else { |
|
| 100 | + $r = explode('_', (string) $lang); |
|
| 101 | + if (isset($trads[$r[0]])) { |
|
| 102 | + return $r[0]; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return ''; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -118,10 +118,10 @@ discard block |
||
| 118 | 118 | * Nom de la langue, sinon son code. |
| 119 | 119 | **/ |
| 120 | 120 | function traduire_nom_langue($lang) { |
| 121 | - include_spip('inc/lang_liste'); |
|
| 122 | - include_spip('inc/charsets'); |
|
| 121 | + include_spip('inc/lang_liste'); |
|
| 122 | + include_spip('inc/charsets'); |
|
| 123 | 123 | |
| 124 | - return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 124 | + return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | // hebreu a priori), 'droitier' sinon. |
| 135 | 135 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 136 | 136 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 137 | - static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 137 | + static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 138 | 138 | |
| 139 | - return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 140 | - $gaucher : $droitier; |
|
| 139 | + return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 140 | + $gaucher : $droitier; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | // typo francaise ou anglaise ? |
@@ -146,29 +146,29 @@ discard block |
||
| 146 | 146 | // sinon determiner la typo en fonction de la langue courante |
| 147 | 147 | |
| 148 | 148 | function lang_typo($lang = '') { |
| 149 | - if (!$lang) { |
|
| 150 | - $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 151 | - } |
|
| 152 | - if ( |
|
| 153 | - $lang == 'eo' |
|
| 154 | - || $lang == 'fr' |
|
| 155 | - || str_starts_with((string) $lang, 'fr_') |
|
| 156 | - || $lang == 'cpf' |
|
| 157 | - ) { |
|
| 158 | - return 'fr'; |
|
| 159 | - } else { |
|
| 160 | - return 'en'; |
|
| 161 | - } |
|
| 149 | + if (!$lang) { |
|
| 150 | + $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 151 | + } |
|
| 152 | + if ( |
|
| 153 | + $lang == 'eo' |
|
| 154 | + || $lang == 'fr' |
|
| 155 | + || str_starts_with((string) $lang, 'fr_') |
|
| 156 | + || $lang == 'cpf' |
|
| 157 | + ) { |
|
| 158 | + return 'fr'; |
|
| 159 | + } else { |
|
| 160 | + return 'en'; |
|
| 161 | + } |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 165 | 165 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 166 | 166 | function changer_typo($lang = '') { |
| 167 | - if ($lang) { |
|
| 168 | - $GLOBALS['lang_objet'] = $lang; |
|
| 169 | - } else { |
|
| 170 | - unset($GLOBALS['lang_objet']); |
|
| 171 | - } |
|
| 167 | + if ($lang) { |
|
| 168 | + $GLOBALS['lang_objet'] = $lang; |
|
| 169 | + } else { |
|
| 170 | + unset($GLOBALS['lang_objet']); |
|
| 171 | + } |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // |
@@ -178,56 +178,56 @@ discard block |
||
| 178 | 178 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 179 | 179 | // |
| 180 | 180 | function menu_langues($nom_select, $default = '') { |
| 181 | - include_spip('inc/actions'); |
|
| 182 | - |
|
| 183 | - $langues = liste_options_langues($nom_select); |
|
| 184 | - $ret = ''; |
|
| 185 | - if ($langues === []) { |
|
| 186 | - return ''; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - if (!$default) { |
|
| 190 | - $default = $GLOBALS['spip_lang']; |
|
| 191 | - } |
|
| 192 | - foreach ($langues as $l) { |
|
| 193 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 194 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - if (!test_espace_prive()) { |
|
| 198 | - $cible = self(); |
|
| 199 | - $base = ''; |
|
| 200 | - } else { |
|
| 201 | - $cible = self(); |
|
| 202 | - $base = spip_connect() ? 'base' : ''; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 206 | - |
|
| 207 | - return generer_action_auteur( |
|
| 208 | - 'converser', |
|
| 209 | - $base, |
|
| 210 | - $cible, |
|
| 211 | - (select_langues($nom_select, $change, $ret) |
|
| 212 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 213 | - " method='post'" |
|
| 214 | - ); |
|
| 181 | + include_spip('inc/actions'); |
|
| 182 | + |
|
| 183 | + $langues = liste_options_langues($nom_select); |
|
| 184 | + $ret = ''; |
|
| 185 | + if ($langues === []) { |
|
| 186 | + return ''; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + if (!$default) { |
|
| 190 | + $default = $GLOBALS['spip_lang']; |
|
| 191 | + } |
|
| 192 | + foreach ($langues as $l) { |
|
| 193 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 194 | + $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + if (!test_espace_prive()) { |
|
| 198 | + $cible = self(); |
|
| 199 | + $base = ''; |
|
| 200 | + } else { |
|
| 201 | + $cible = self(); |
|
| 202 | + $base = spip_connect() ? 'base' : ''; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 206 | + |
|
| 207 | + return generer_action_auteur( |
|
| 208 | + 'converser', |
|
| 209 | + $base, |
|
| 210 | + $cible, |
|
| 211 | + (select_langues($nom_select, $change, $ret) |
|
| 212 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 213 | + " method='post'" |
|
| 214 | + ); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | function select_langues($nom_select, $change, $options, $label = '') { |
| 218 | - static $cpt = 0; |
|
| 219 | - $id = 'menu_langues' . $cpt++; |
|
| 220 | - |
|
| 221 | - return |
|
| 222 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 223 | - "<select name='$nom_select' id='$id' " |
|
| 224 | - . ((test_espace_prive()) ? |
|
| 225 | - (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 226 | - ("class='forml menu_langues'")) |
|
| 227 | - . $change |
|
| 228 | - . ">\n" |
|
| 229 | - . $options |
|
| 230 | - . '</select>'; |
|
| 218 | + static $cpt = 0; |
|
| 219 | + $id = 'menu_langues' . $cpt++; |
|
| 220 | + |
|
| 221 | + return |
|
| 222 | + "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 223 | + "<select name='$nom_select' id='$id' " |
|
| 224 | + . ((test_espace_prive()) ? |
|
| 225 | + (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 226 | + ("class='forml menu_langues'")) |
|
| 227 | + . $change |
|
| 228 | + . ">\n" |
|
| 229 | + . $options |
|
| 230 | + . '</select>'; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -249,34 +249,34 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | function liste_options_langues($nom_select) { |
| 251 | 251 | |
| 252 | - switch ($nom_select) { |
|
| 253 | - # #MENU_LANG |
|
| 254 | - case 'var_lang': |
|
| 255 | - # menu de changement de la langue d'un article |
|
| 256 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 257 | - case 'changer_lang': |
|
| 258 | - $langues = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 259 | - break; |
|
| 260 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 261 | - # les langues presentes sous forme de fichiers de langue |
|
| 262 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 263 | - case 'var_lang_ecrire': |
|
| 264 | - default: |
|
| 265 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 266 | - init_langues(); |
|
| 267 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 268 | - break; |
|
| 252 | + switch ($nom_select) { |
|
| 253 | + # #MENU_LANG |
|
| 254 | + case 'var_lang': |
|
| 255 | + # menu de changement de la langue d'un article |
|
| 256 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 257 | + case 'changer_lang': |
|
| 258 | + $langues = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 259 | + break; |
|
| 260 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 261 | + # les langues presentes sous forme de fichiers de langue |
|
| 262 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 263 | + case 'var_lang_ecrire': |
|
| 264 | + default: |
|
| 265 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 266 | + init_langues(); |
|
| 267 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 268 | + break; |
|
| 269 | 269 | |
| 270 | 270 | # dernier choix possible : toutes les langues = langues_proposees |
| 271 | 271 | # + langues_multilingues ; mais, ne sert pas |
| 272 | 272 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 273 | - } |
|
| 274 | - if (count($langues) <= 1) { |
|
| 275 | - return []; |
|
| 276 | - } |
|
| 277 | - sort($langues); |
|
| 273 | + } |
|
| 274 | + if (count($langues) <= 1) { |
|
| 275 | + return []; |
|
| 276 | + } |
|
| 277 | + sort($langues); |
|
| 278 | 278 | |
| 279 | - return $langues; |
|
| 279 | + return $langues; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | |
@@ -291,39 +291,39 @@ discard block |
||
| 291 | 291 | **/ |
| 292 | 292 | function verifier_lang_url() { |
| 293 | 293 | |
| 294 | - // quelle langue est demandee ? |
|
| 295 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 296 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 297 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 298 | - } |
|
| 299 | - if (!test_espace_prive() && isset($_COOKIE['spip_lang'])) { |
|
| 300 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 301 | - } |
|
| 302 | - if (isset($_GET['lang'])) { |
|
| 303 | - $lang_demandee = $_GET['lang']; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 307 | - if ( |
|
| 308 | - $GLOBALS['spip_lang'] != $lang_demandee |
|
| 309 | - && changer_langue($lang_demandee) |
|
| 310 | - && $lang_demandee != @$_GET['lang'] |
|
| 311 | - ) { |
|
| 312 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 313 | - // ici on a besoin des var_truc |
|
| 314 | - foreach ($_GET as $var => $val) { |
|
| 315 | - if (!strncmp('var_', $var, 4)) { |
|
| 316 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - include_spip('inc/headers'); |
|
| 320 | - redirige_par_entete($destination); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 324 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 325 | - // (pour criteres {lang}). |
|
| 326 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 294 | + // quelle langue est demandee ? |
|
| 295 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 296 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 297 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 298 | + } |
|
| 299 | + if (!test_espace_prive() && isset($_COOKIE['spip_lang'])) { |
|
| 300 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 301 | + } |
|
| 302 | + if (isset($_GET['lang'])) { |
|
| 303 | + $lang_demandee = $_GET['lang']; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 307 | + if ( |
|
| 308 | + $GLOBALS['spip_lang'] != $lang_demandee |
|
| 309 | + && changer_langue($lang_demandee) |
|
| 310 | + && $lang_demandee != @$_GET['lang'] |
|
| 311 | + ) { |
|
| 312 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 313 | + // ici on a besoin des var_truc |
|
| 314 | + foreach ($_GET as $var => $val) { |
|
| 315 | + if (!strncmp('var_', $var, 4)) { |
|
| 316 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + include_spip('inc/headers'); |
|
| 320 | + redirige_par_entete($destination); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 324 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 325 | + // (pour criteres {lang}). |
|
| 326 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | |
@@ -341,19 +341,19 @@ discard block |
||
| 341 | 341 | * La langue sélectionnée |
| 342 | 342 | **/ |
| 343 | 343 | function utiliser_langue_site($liste_langues = null) { |
| 344 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 345 | - if ( |
|
| 346 | - isset($GLOBALS['meta']['langue_site']) |
|
| 347 | - && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 348 | - ) { |
|
| 349 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 350 | - } |
|
| 351 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 352 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 353 | - spip_logger()->error('La globale spip_lang est indéfinie dans utiliser_langue_site() !'); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - return $GLOBALS['spip_lang']; |
|
| 344 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 345 | + if ( |
|
| 346 | + isset($GLOBALS['meta']['langue_site']) |
|
| 347 | + && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 348 | + ) { |
|
| 349 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 350 | + } |
|
| 351 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 352 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 353 | + spip_logger()->error('La globale spip_lang est indéfinie dans utiliser_langue_site() !'); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + return $GLOBALS['spip_lang']; |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -372,38 +372,38 @@ discard block |
||
| 372 | 372 | **/ |
| 373 | 373 | function utiliser_langue_visiteur($liste_langues = null) { |
| 374 | 374 | |
| 375 | - // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 376 | - if (is_null($liste_langues) && !test_espace_prive() && !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 377 | - $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - $l = (test_espace_prive() ? 'spip_lang_ecrire' : 'spip_lang'); |
|
| 381 | - if ( |
|
| 382 | - isset($_COOKIE[$l]) |
|
| 383 | - && changer_langue($l = $_COOKIE[$l], $liste_langues) |
|
| 384 | - ) { |
|
| 385 | - return $l; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if ( |
|
| 389 | - isset($GLOBALS['visiteur_session']['lang']) |
|
| 390 | - && changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues) |
|
| 391 | - ) { |
|
| 392 | - return $l; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 396 | - foreach (explode(',', (string) $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 397 | - if ( |
|
| 398 | - preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r) |
|
| 399 | - && changer_langue($l = strtolower($r[1]), $liste_langues) |
|
| 400 | - ) { |
|
| 401 | - return $l; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - return utiliser_langue_site($liste_langues); |
|
| 375 | + // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 376 | + if (is_null($liste_langues) && !test_espace_prive() && !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 377 | + $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + $l = (test_espace_prive() ? 'spip_lang_ecrire' : 'spip_lang'); |
|
| 381 | + if ( |
|
| 382 | + isset($_COOKIE[$l]) |
|
| 383 | + && changer_langue($l = $_COOKIE[$l], $liste_langues) |
|
| 384 | + ) { |
|
| 385 | + return $l; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if ( |
|
| 389 | + isset($GLOBALS['visiteur_session']['lang']) |
|
| 390 | + && changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues) |
|
| 391 | + ) { |
|
| 392 | + return $l; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 396 | + foreach (explode(',', (string) $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 397 | + if ( |
|
| 398 | + preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r) |
|
| 399 | + && changer_langue($l = strtolower($r[1]), $liste_langues) |
|
| 400 | + ) { |
|
| 401 | + return $l; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + return utiliser_langue_site($liste_langues); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | * @return int |
| 414 | 414 | */ |
| 415 | 415 | function match_langue($chaine) { |
| 416 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 416 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | /** |
@@ -431,38 +431,38 @@ discard block |
||
| 431 | 431 | **/ |
| 432 | 432 | function init_langues() { |
| 433 | 433 | |
| 434 | - // liste des langues dans les meta, sauf a l'install |
|
| 435 | - $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 436 | - |
|
| 437 | - $tout = []; |
|
| 438 | - if (!$all_langs) { |
|
| 439 | - // trouver tous les modules lang/spip_xx.php |
|
| 440 | - $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 441 | - foreach (array_keys($modules) as $name) { |
|
| 442 | - if ( |
|
| 443 | - preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs) |
|
| 444 | - && match_langue($regs[1]) |
|
| 445 | - ) { |
|
| 446 | - $tout[] = $regs[1]; |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - sort($tout); |
|
| 450 | - $tout = implode(',', $tout); |
|
| 451 | - // Si les langues n'ont pas change, ne rien faire |
|
| 452 | - if ($tout != $all_langs) { |
|
| 453 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 454 | - include_spip('inc/meta'); |
|
| 455 | - ecrire_meta('langues_proposees', $tout); |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 459 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 460 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 461 | - (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 462 | - ? _LANGUE_PAR_DEFAUT |
|
| 463 | - : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
|
| 464 | - ecrire_meta('langue_site', $tout); |
|
| 465 | - } |
|
| 434 | + // liste des langues dans les meta, sauf a l'install |
|
| 435 | + $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 436 | + |
|
| 437 | + $tout = []; |
|
| 438 | + if (!$all_langs) { |
|
| 439 | + // trouver tous les modules lang/spip_xx.php |
|
| 440 | + $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 441 | + foreach (array_keys($modules) as $name) { |
|
| 442 | + if ( |
|
| 443 | + preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs) |
|
| 444 | + && match_langue($regs[1]) |
|
| 445 | + ) { |
|
| 446 | + $tout[] = $regs[1]; |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + sort($tout); |
|
| 450 | + $tout = implode(',', $tout); |
|
| 451 | + // Si les langues n'ont pas change, ne rien faire |
|
| 452 | + if ($tout != $all_langs) { |
|
| 453 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 454 | + include_spip('inc/meta'); |
|
| 455 | + ecrire_meta('langues_proposees', $tout); |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 459 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 460 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 461 | + (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 462 | + ? _LANGUE_PAR_DEFAUT |
|
| 463 | + : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
|
| 464 | + ecrire_meta('langue_site', $tout); |
|
| 465 | + } |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -476,10 +476,10 @@ discard block |
||
| 476 | 476 | * Code html de la balise <html> |
| 477 | 477 | **/ |
| 478 | 478 | function html_lang_attributes() { |
| 479 | - $lang = $GLOBALS['spip_lang']; |
|
| 480 | - $dir = lang_dir($lang); |
|
| 479 | + $lang = $GLOBALS['spip_lang']; |
|
| 480 | + $dir = lang_dir($lang); |
|
| 481 | 481 | |
| 482 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 482 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | * @return string |
| 494 | 494 | */ |
| 495 | 495 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 496 | - return ($spip_lang != 'he') ? $spip_lang_rtl : ''; |
|
| 496 | + return ($spip_lang != 'he') ? $spip_lang_rtl : ''; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - return $x . $texte; |
|
| 66 | + return $x.$texte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
| 141 | - $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 141 | + $insert = "\n".pipeline('insert_head', '<!-- f_insert_head -->')."\n"; |
|
| 142 | 142 | $texte = substr_replace($texte, $insert, $pos, 0); |
| 143 | 143 | } |
| 144 | 144 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | $texte = substr_replace($texte, $x, $pos, 0); |
| 172 | 172 | // pas de preview en fenetre enfant |
| 173 | - $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 173 | + $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='".addslashes((string) $GLOBALS['meta']['adresse_site'])."';}</script>"; |
|
| 174 | 174 | if ((!$pos = stripos($texte, '<head')) || (!$pos = strpos($texte, '>', $pos))) { |
| 175 | 175 | $pos = -1; |
| 176 | 176 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
| 243 | 243 | if (($p = strpos($texte, '</body>')) !== false) { |
| 244 | - $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 244 | + $texte = substr($texte, 0, $p).$code.substr($texte, $p); |
|
| 245 | 245 | } else { |
| 246 | 246 | $texte .= $code; |
| 247 | 247 | } |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Pipelines |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | if (test_espace_prive()) { |
| 21 | - include_spip('inc/pipelines_ecrire'); |
|
| 21 | + include_spip('inc/pipelines_ecrire'); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -44,26 +44,26 @@ discard block |
||
| 44 | 44 | * @return string Contenu qui sera inséré dans le head HTML |
| 45 | 45 | **/ |
| 46 | 46 | function f_jQuery($texte) { |
| 47 | - $x = ''; |
|
| 48 | - $jquery_plugins = pipeline( |
|
| 49 | - 'jquery_plugins', |
|
| 50 | - [ |
|
| 51 | - 'javascript/jquery.js', |
|
| 52 | - 'javascript/jquery.form.js', |
|
| 53 | - 'javascript/jquery.autosave.js', |
|
| 54 | - 'javascript/jquery.placeholder-label.js', |
|
| 55 | - 'javascript/ajaxCallback.js', |
|
| 56 | - 'javascript/js.cookie.js', |
|
| 57 | - ] |
|
| 58 | - ); |
|
| 59 | - foreach (array_unique($jquery_plugins) as $script) { |
|
| 60 | - if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 61 | - $script = timestamp($script); |
|
| 62 | - $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - return $x . $texte; |
|
| 47 | + $x = ''; |
|
| 48 | + $jquery_plugins = pipeline( |
|
| 49 | + 'jquery_plugins', |
|
| 50 | + [ |
|
| 51 | + 'javascript/jquery.js', |
|
| 52 | + 'javascript/jquery.form.js', |
|
| 53 | + 'javascript/jquery.autosave.js', |
|
| 54 | + 'javascript/jquery.placeholder-label.js', |
|
| 55 | + 'javascript/ajaxCallback.js', |
|
| 56 | + 'javascript/js.cookie.js', |
|
| 57 | + ] |
|
| 58 | + ); |
|
| 59 | + foreach (array_unique($jquery_plugins) as $script) { |
|
| 60 | + if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 61 | + $script = timestamp($script); |
|
| 62 | + $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + return $x . $texte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -80,33 +80,33 @@ discard block |
||
| 80 | 80 | * @return string Contenu de la page envoyée au navigateur |
| 81 | 81 | **/ |
| 82 | 82 | function f_tidy($texte) { |
| 83 | - /** |
|
| 84 | - * Indentation à faire ? |
|
| 85 | - * |
|
| 86 | - * - true : actif. |
|
| 87 | - * - false par défaut. |
|
| 88 | - */ |
|
| 89 | - |
|
| 90 | - if ( |
|
| 91 | - $GLOBALS['xhtml'] |
|
| 92 | - && $GLOBALS['html'] |
|
| 93 | - && strlen($texte) |
|
| 94 | - && !headers_sent() |
|
| 95 | - ) { |
|
| 96 | - # Compatibilite ascendante |
|
| 97 | - if (!is_string($GLOBALS['xhtml'])) { |
|
| 98 | - $GLOBALS['xhtml'] = 'tidy'; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 102 | - spip_logger()->info("tidy absent, l'indenteur SPIP le remplace"); |
|
| 103 | - $f = charger_fonction('sax', 'xml'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $f($texte); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - return $texte; |
|
| 83 | + /** |
|
| 84 | + * Indentation à faire ? |
|
| 85 | + * |
|
| 86 | + * - true : actif. |
|
| 87 | + * - false par défaut. |
|
| 88 | + */ |
|
| 89 | + |
|
| 90 | + if ( |
|
| 91 | + $GLOBALS['xhtml'] |
|
| 92 | + && $GLOBALS['html'] |
|
| 93 | + && strlen($texte) |
|
| 94 | + && !headers_sent() |
|
| 95 | + ) { |
|
| 96 | + # Compatibilite ascendante |
|
| 97 | + if (!is_string($GLOBALS['xhtml'])) { |
|
| 98 | + $GLOBALS['xhtml'] = 'tidy'; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 102 | + spip_logger()->info("tidy absent, l'indenteur SPIP le remplace"); |
|
| 103 | + $f = charger_fonction('sax', 'xml'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $f($texte); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + return $texte; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -125,24 +125,24 @@ discard block |
||
| 125 | 125 | * @return string Contenu de la page envoyée au navigateur |
| 126 | 126 | **/ |
| 127 | 127 | function f_insert_head($texte) { |
| 128 | - if (!$GLOBALS['html']) { |
|
| 129 | - return $texte; |
|
| 130 | - } |
|
| 131 | - include_spip('public/admin'); // pour strripos |
|
| 132 | - |
|
| 133 | - if ( |
|
| 134 | - !($pos = stripos($texte, '</head>')) |
|
| 135 | - && !($pos = stripos($texte, '<body>')) |
|
| 136 | - ) { |
|
| 137 | - $pos = 0; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 141 | - $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 142 | - $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return $texte; |
|
| 128 | + if (!$GLOBALS['html']) { |
|
| 129 | + return $texte; |
|
| 130 | + } |
|
| 131 | + include_spip('public/admin'); // pour strripos |
|
| 132 | + |
|
| 133 | + if ( |
|
| 134 | + !($pos = stripos($texte, '</head>')) |
|
| 135 | + && !($pos = stripos($texte, '<body>')) |
|
| 136 | + ) { |
|
| 137 | + $pos = 0; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 141 | + $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 142 | + $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return $texte; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | |
@@ -158,34 +158,34 @@ discard block |
||
| 158 | 158 | * @return string Contenu de la page envoyée au navigateur |
| 159 | 159 | **/ |
| 160 | 160 | function f_admin($texte) { |
| 161 | - if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && $GLOBALS['html']) { |
|
| 162 | - include_spip('inc/filtres'); // pour http_img_pack |
|
| 163 | - $x = "<div class='spip-previsu' " |
|
| 164 | - . http_style_background('preview-32.png', '', 32) |
|
| 165 | - . '>' |
|
| 166 | - . _T('previsualisation') |
|
| 167 | - . '</div>'; |
|
| 168 | - if (!$pos = stripos($texte, '</body>')) { |
|
| 169 | - $pos = strlen($texte); |
|
| 170 | - } |
|
| 171 | - $texte = substr_replace($texte, $x, $pos, 0); |
|
| 172 | - // pas de preview en fenetre enfant |
|
| 173 | - $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 174 | - if ((!$pos = stripos($texte, '<head')) || (!$pos = strpos($texte, '>', $pos))) { |
|
| 175 | - $pos = -1; |
|
| 176 | - } |
|
| 177 | - $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - if (isset($GLOBALS['affiche_boutons_admin']) && $GLOBALS['affiche_boutons_admin']) { |
|
| 181 | - include_spip('public/admin'); |
|
| 182 | - $texte = affiche_boutons_admin($texte); |
|
| 183 | - } |
|
| 184 | - if (_request('var_mode') == 'noajax') { |
|
| 185 | - $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $texte; |
|
| 161 | + if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && $GLOBALS['html']) { |
|
| 162 | + include_spip('inc/filtres'); // pour http_img_pack |
|
| 163 | + $x = "<div class='spip-previsu' " |
|
| 164 | + . http_style_background('preview-32.png', '', 32) |
|
| 165 | + . '>' |
|
| 166 | + . _T('previsualisation') |
|
| 167 | + . '</div>'; |
|
| 168 | + if (!$pos = stripos($texte, '</body>')) { |
|
| 169 | + $pos = strlen($texte); |
|
| 170 | + } |
|
| 171 | + $texte = substr_replace($texte, $x, $pos, 0); |
|
| 172 | + // pas de preview en fenetre enfant |
|
| 173 | + $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 174 | + if ((!$pos = stripos($texte, '<head')) || (!$pos = strpos($texte, '>', $pos))) { |
|
| 175 | + $pos = -1; |
|
| 176 | + } |
|
| 177 | + $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + if (isset($GLOBALS['affiche_boutons_admin']) && $GLOBALS['affiche_boutons_admin']) { |
|
| 181 | + include_spip('public/admin'); |
|
| 182 | + $texte = affiche_boutons_admin($texte); |
|
| 183 | + } |
|
| 184 | + if (_request('var_mode') == 'noajax') { |
|
| 185 | + $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $texte; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | * @return array $flux Description et contenu de l'inclusion |
| 204 | 204 | **/ |
| 205 | 205 | function f_recuperer_fond($flux) { |
| 206 | - if (!test_espace_prive()) { |
|
| 207 | - return $flux; |
|
| 208 | - } |
|
| 206 | + if (!test_espace_prive()) { |
|
| 207 | + return $flux; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - return f_afficher_blocs_ecrire($flux); |
|
| 210 | + return f_afficher_blocs_ecrire($flux); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -221,30 +221,30 @@ discard block |
||
| 221 | 221 | * @return string Contenu de la page envoyée au navigateur |
| 222 | 222 | */ |
| 223 | 223 | function f_queue($texte) { |
| 224 | - // eviter une inclusion si rien a faire |
|
| 225 | - if ( |
|
| 226 | - _request('action') == 'cron' |
|
| 227 | - || queue_sleep_time_to_next_job() > 0 |
|
| 228 | - || defined('_DEBUG_BLOCK_QUEUE') |
|
| 229 | - ) { |
|
| 230 | - return $texte; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - include_spip('inc/queue'); |
|
| 234 | - $code = queue_affichage_cron(); |
|
| 235 | - |
|
| 236 | - // si rien a afficher |
|
| 237 | - // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 238 | - if (!$code || !isset($GLOBALS['html']) || !$GLOBALS['html']) { |
|
| 239 | - return $texte; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 243 | - if (($p = strpos($texte, '</body>')) !== false) { |
|
| 244 | - $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 245 | - } else { |
|
| 246 | - $texte .= $code; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - return $texte; |
|
| 224 | + // eviter une inclusion si rien a faire |
|
| 225 | + if ( |
|
| 226 | + _request('action') == 'cron' |
|
| 227 | + || queue_sleep_time_to_next_job() > 0 |
|
| 228 | + || defined('_DEBUG_BLOCK_QUEUE') |
|
| 229 | + ) { |
|
| 230 | + return $texte; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + include_spip('inc/queue'); |
|
| 234 | + $code = queue_affichage_cron(); |
|
| 235 | + |
|
| 236 | + // si rien a afficher |
|
| 237 | + // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 238 | + if (!$code || !isset($GLOBALS['html']) || !$GLOBALS['html']) { |
|
| 239 | + return $texte; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 243 | + if (($p = strpos($texte, '</body>')) !== false) { |
|
| 244 | + $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 245 | + } else { |
|
| 246 | + $texte .= $code; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + return $texte; |
|
| 250 | 250 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/texte_mini'); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @return array Tablea ('','') |
| 36 | 36 | */ |
| 37 | 37 | function definir_raccourcis_alineas() { |
| 38 | - return ['', '']; |
|
| 38 | + return ['', '']; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @return string |
| 49 | 49 | */ |
| 50 | 50 | function traiter_tableau($bloc) { |
| 51 | - return $bloc; |
|
| 51 | + return $bloc; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @return string |
| 63 | 63 | */ |
| 64 | 64 | function traiter_listes($texte) { |
| 65 | - return $texte; |
|
| 65 | + return $texte; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -78,16 +78,16 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | function traiter_raccourcis($letexte) { |
| 80 | 80 | |
| 81 | - // Appeler les fonctions de pre_traitement |
|
| 82 | - $letexte = pipeline('pre_propre', $letexte); |
|
| 81 | + // Appeler les fonctions de pre_traitement |
|
| 82 | + $letexte = pipeline('pre_propre', $letexte); |
|
| 83 | 83 | |
| 84 | - // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 85 | - // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 84 | + // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 85 | + // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 86 | 86 | |
| 87 | - // Appeler les fonctions de post-traitement |
|
| 88 | - $letexte = pipeline('post_propre', $letexte); |
|
| 87 | + // Appeler les fonctions de post-traitement |
|
| 88 | + $letexte = pipeline('post_propre', $letexte); |
|
| 89 | 89 | |
| 90 | - return $letexte; |
|
| 90 | + return $letexte; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /************************************************************************************************************************* |
@@ -103,22 +103,22 @@ discard block |
||
| 103 | 103 | * @return string |
| 104 | 104 | */ |
| 105 | 105 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 106 | - foreach (['script', 'iframe'] as $tag) { |
|
| 107 | - if ( |
|
| 108 | - stripos($t, (string) "<$tag") !== false |
|
| 109 | - && preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 110 | - ) { |
|
| 111 | - foreach ($r as $regs) { |
|
| 112 | - $t = str_replace( |
|
| 113 | - $regs[0], |
|
| 114 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 115 | - $t |
|
| 116 | - ); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - return $t; |
|
| 106 | + foreach (['script', 'iframe'] as $tag) { |
|
| 107 | + if ( |
|
| 108 | + stripos($t, (string) "<$tag") !== false |
|
| 109 | + && preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 110 | + ) { |
|
| 111 | + foreach ($r as $regs) { |
|
| 112 | + $t = str_replace( |
|
| 113 | + $regs[0], |
|
| 114 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 115 | + $t |
|
| 116 | + ); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + return $t; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
@@ -147,55 +147,55 @@ discard block |
||
| 147 | 147 | * Code protégé |
| 148 | 148 | **/ |
| 149 | 149 | function interdire_scripts($arg, $mode_filtre = null) { |
| 150 | - // on memorise le resultat sur les arguments non triviaux |
|
| 151 | - static $dejavu = []; |
|
| 152 | - |
|
| 153 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 154 | - if (!$arg || !is_string($arg) || !strstr($arg, '<')) { |
|
| 155 | - return $arg; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - if (is_null($mode_filtre) || !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 159 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 163 | - return $dejavu[$mode_filtre][$arg]; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // echapper les tags asp/php |
|
| 167 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 168 | - |
|
| 169 | - // echapper le php |
|
| 170 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 171 | - |
|
| 172 | - // echapper le < script language=php > |
|
| 173 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 174 | - |
|
| 175 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 176 | - switch ($mode_filtre) { |
|
| 177 | - case 0: |
|
| 178 | - if (!_DIR_RESTREINT) { |
|
| 179 | - $t = echappe_js($t); |
|
| 180 | - } |
|
| 181 | - break; |
|
| 182 | - case -1: |
|
| 183 | - $t = echappe_js($t); |
|
| 184 | - break; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - // pas de <base href /> svp ! |
|
| 188 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 189 | - |
|
| 190 | - // Reinserer les echappements des modeles |
|
| 191 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 192 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 193 | - } |
|
| 194 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 195 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 150 | + // on memorise le resultat sur les arguments non triviaux |
|
| 151 | + static $dejavu = []; |
|
| 152 | + |
|
| 153 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 154 | + if (!$arg || !is_string($arg) || !strstr($arg, '<')) { |
|
| 155 | + return $arg; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + if (is_null($mode_filtre) || !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 159 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 163 | + return $dejavu[$mode_filtre][$arg]; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // echapper les tags asp/php |
|
| 167 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 168 | + |
|
| 169 | + // echapper le php |
|
| 170 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 171 | + |
|
| 172 | + // echapper le < script language=php > |
|
| 173 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 174 | + |
|
| 175 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 176 | + switch ($mode_filtre) { |
|
| 177 | + case 0: |
|
| 178 | + if (!_DIR_RESTREINT) { |
|
| 179 | + $t = echappe_js($t); |
|
| 180 | + } |
|
| 181 | + break; |
|
| 182 | + case -1: |
|
| 183 | + $t = echappe_js($t); |
|
| 184 | + break; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + // pas de <base href /> svp ! |
|
| 188 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 189 | + |
|
| 190 | + // Reinserer les echappements des modeles |
|
| 191 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 192 | + $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 193 | + } |
|
| 194 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 195 | + $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | |
@@ -224,66 +224,66 @@ discard block |
||
| 224 | 224 | * texte transformé |
| 225 | 225 | **/ |
| 226 | 226 | function typo($letexte, $echapper = true, $connect = null, $env = []) { |
| 227 | - // Plus vite ! |
|
| 228 | - if (!$letexte) { |
|
| 229 | - return $letexte; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 233 | - // prive etant historiquement ecrit sans argment $connect |
|
| 234 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 235 | - // ou il faut passer interdire_script explicitement |
|
| 236 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 237 | - // ne seront pas perturbes |
|
| 238 | - $interdire_script = false; |
|
| 239 | - if (is_null($connect)) { |
|
| 240 | - $connect = ''; |
|
| 241 | - $interdire_script = true; |
|
| 242 | - $env['espace_prive'] = test_espace_prive(); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - // Echapper les codes <html> etc |
|
| 246 | - if ($echapper) { |
|
| 247 | - $letexte = CollecteurHtmlTag::proteger_balisesHtml($letexte, 'TYPO'); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - // |
|
| 251 | - // Installer les modeles, notamment images et documents ; |
|
| 252 | - // |
|
| 253 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 254 | - // cf. inc/lien |
|
| 255 | - |
|
| 256 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env); |
|
| 257 | - if ($letexte != $mem) { |
|
| 258 | - $echapper = true; |
|
| 259 | - } |
|
| 260 | - unset($mem); |
|
| 261 | - |
|
| 262 | - $letexte = corriger_typo($letexte); |
|
| 263 | - $letexte = echapper_faux_tags($letexte); |
|
| 264 | - |
|
| 265 | - // reintegrer les echappements |
|
| 266 | - if ($echapper) { |
|
| 267 | - $letexte = CollecteurHtmlTag::retablir_depuisHtmlBase64($letexte, 'TYPO'); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 271 | - if ($interdire_script) { |
|
| 272 | - $letexte = interdire_scripts($letexte); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 276 | - // https://core.spip.net/issues/3371 |
|
| 277 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 278 | - // https://core.spip.net/issues/4166 |
|
| 279 | - if ( |
|
| 280 | - $GLOBALS['filtrer_javascript'] == -1 |
|
| 281 | - || isset($env['espace_prive']) && $env['espace_prive'] && $GLOBALS['filtrer_javascript'] <= 0 |
|
| 282 | - ) { |
|
| 283 | - $letexte = echapper_html_suspect($letexte, [], $connect, $env); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - return $letexte; |
|
| 227 | + // Plus vite ! |
|
| 228 | + if (!$letexte) { |
|
| 229 | + return $letexte; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 233 | + // prive etant historiquement ecrit sans argment $connect |
|
| 234 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 235 | + // ou il faut passer interdire_script explicitement |
|
| 236 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 237 | + // ne seront pas perturbes |
|
| 238 | + $interdire_script = false; |
|
| 239 | + if (is_null($connect)) { |
|
| 240 | + $connect = ''; |
|
| 241 | + $interdire_script = true; |
|
| 242 | + $env['espace_prive'] = test_espace_prive(); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + // Echapper les codes <html> etc |
|
| 246 | + if ($echapper) { |
|
| 247 | + $letexte = CollecteurHtmlTag::proteger_balisesHtml($letexte, 'TYPO'); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + // |
|
| 251 | + // Installer les modeles, notamment images et documents ; |
|
| 252 | + // |
|
| 253 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 254 | + // cf. inc/lien |
|
| 255 | + |
|
| 256 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env); |
|
| 257 | + if ($letexte != $mem) { |
|
| 258 | + $echapper = true; |
|
| 259 | + } |
|
| 260 | + unset($mem); |
|
| 261 | + |
|
| 262 | + $letexte = corriger_typo($letexte); |
|
| 263 | + $letexte = echapper_faux_tags($letexte); |
|
| 264 | + |
|
| 265 | + // reintegrer les echappements |
|
| 266 | + if ($echapper) { |
|
| 267 | + $letexte = CollecteurHtmlTag::retablir_depuisHtmlBase64($letexte, 'TYPO'); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 271 | + if ($interdire_script) { |
|
| 272 | + $letexte = interdire_scripts($letexte); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 276 | + // https://core.spip.net/issues/3371 |
|
| 277 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 278 | + // https://core.spip.net/issues/4166 |
|
| 279 | + if ( |
|
| 280 | + $GLOBALS['filtrer_javascript'] == -1 |
|
| 281 | + || isset($env['espace_prive']) && $env['espace_prive'] && $GLOBALS['filtrer_javascript'] <= 0 |
|
| 282 | + ) { |
|
| 283 | + $letexte = echapper_html_suspect($letexte, [], $connect, $env); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + return $letexte; |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | // Correcteur typographique |
@@ -308,57 +308,57 @@ discard block |
||
| 308 | 308 | */ |
| 309 | 309 | function corriger_typo($letexte, $lang = '') { |
| 310 | 310 | |
| 311 | - // Plus vite ! |
|
| 312 | - if (!$letexte) { |
|
| 313 | - return $letexte; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 317 | - |
|
| 318 | - // Caracteres de controle "illegaux" |
|
| 319 | - $letexte = corriger_caracteres($letexte); |
|
| 320 | - |
|
| 321 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 322 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 323 | - foreach ($regs as $reg) { |
|
| 324 | - $insert = $reg[0]; |
|
| 325 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 326 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 327 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 328 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - // trouver les blocs idiomes et les traiter à part |
|
| 333 | - $letexte = extraire_idiome($ei = $letexte, $lang, ['echappe_span' => true]); |
|
| 334 | - $ei = ($ei !== $letexte); |
|
| 335 | - |
|
| 336 | - // trouver les blocs multi et les traiter a part |
|
| 337 | - $letexte = extraire_multi($em = $letexte, $lang, ['echappe_span' => true]); |
|
| 338 | - $em = ($em !== $letexte); |
|
| 339 | - |
|
| 340 | - // Charger & appliquer les fonctions de typographie |
|
| 341 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 342 | - $letexte = $typographie($letexte); |
|
| 343 | - |
|
| 344 | - // Les citations en une autre langue, s'il y a lieu |
|
| 345 | - if ($em) { |
|
| 346 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 347 | - } |
|
| 348 | - if ($ei) { |
|
| 349 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - // Retablir les caracteres proteges |
|
| 353 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 354 | - |
|
| 355 | - // pipeline |
|
| 356 | - $letexte = pipeline('post_typo', $letexte); |
|
| 357 | - |
|
| 358 | - # un message pour abs_url - on est passe en mode texte |
|
| 359 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 360 | - |
|
| 361 | - return $letexte; |
|
| 311 | + // Plus vite ! |
|
| 312 | + if (!$letexte) { |
|
| 313 | + return $letexte; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 317 | + |
|
| 318 | + // Caracteres de controle "illegaux" |
|
| 319 | + $letexte = corriger_caracteres($letexte); |
|
| 320 | + |
|
| 321 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 322 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 323 | + foreach ($regs as $reg) { |
|
| 324 | + $insert = $reg[0]; |
|
| 325 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 326 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 327 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 328 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + // trouver les blocs idiomes et les traiter à part |
|
| 333 | + $letexte = extraire_idiome($ei = $letexte, $lang, ['echappe_span' => true]); |
|
| 334 | + $ei = ($ei !== $letexte); |
|
| 335 | + |
|
| 336 | + // trouver les blocs multi et les traiter a part |
|
| 337 | + $letexte = extraire_multi($em = $letexte, $lang, ['echappe_span' => true]); |
|
| 338 | + $em = ($em !== $letexte); |
|
| 339 | + |
|
| 340 | + // Charger & appliquer les fonctions de typographie |
|
| 341 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 342 | + $letexte = $typographie($letexte); |
|
| 343 | + |
|
| 344 | + // Les citations en une autre langue, s'il y a lieu |
|
| 345 | + if ($em) { |
|
| 346 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 347 | + } |
|
| 348 | + if ($ei) { |
|
| 349 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + // Retablir les caracteres proteges |
|
| 353 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 354 | + |
|
| 355 | + // pipeline |
|
| 356 | + $letexte = pipeline('post_typo', $letexte); |
|
| 357 | + |
|
| 358 | + # un message pour abs_url - on est passe en mode texte |
|
| 359 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 360 | + |
|
| 361 | + return $letexte; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | * @return string |
| 375 | 375 | */ |
| 376 | 376 | function paragrapher($letexte, $forcer = true) { |
| 377 | - return $letexte; |
|
| 377 | + return $letexte; |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -386,11 +386,11 @@ discard block |
||
| 386 | 386 | * @return string texte |
| 387 | 387 | **/ |
| 388 | 388 | function traiter_retours_chariots($letexte) { |
| 389 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 390 | - $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 391 | - $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 389 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 390 | + $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 391 | + $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 392 | 392 | |
| 393 | - return $letexte; |
|
| 393 | + return $letexte; |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | |
@@ -416,41 +416,41 @@ discard block |
||
| 416 | 416 | * texte transformé |
| 417 | 417 | **/ |
| 418 | 418 | function propre($t, $connect = null, $env = []) { |
| 419 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 420 | - // prive etant historiquement ecrits sans argment $connect |
|
| 421 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 422 | - // ou il faut passer interdire_script explicitement |
|
| 423 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 424 | - // ne seront pas perturbes |
|
| 425 | - // FIXME: Trouver une solution pour avoir un type (string) unique sur $connect. |
|
| 426 | - $interdire_script = false; |
|
| 427 | - if (is_null($connect)) { |
|
| 428 | - $connect = ''; |
|
| 429 | - $interdire_script = true; |
|
| 430 | - $env['espace_prive'] = true; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - if (!$t) { |
|
| 434 | - return strval($t); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 438 | - // avant echappement des balises <html> |
|
| 439 | - // https://core.spip.net/issues/3371 |
|
| 440 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 441 | - // https://core.spip.net/issues/4166 |
|
| 442 | - if ( |
|
| 443 | - $interdire_script |
|
| 444 | - || $GLOBALS['filtrer_javascript'] == -1 |
|
| 445 | - || !empty($env['espace_prive']) && $GLOBALS['filtrer_javascript'] <= 0 |
|
| 446 | - || !empty($env['wysiwyg']) && $env['wysiwyg'] && $GLOBALS['filtrer_javascript'] <= 0 |
|
| 447 | - ) { |
|
| 448 | - $t = echapper_html_suspect($t, ['strict' => false], $connect, $env); |
|
| 449 | - } |
|
| 450 | - $t = echappe_html($t); |
|
| 451 | - $t = expanser_liens($t, $connect ?? '', $env); |
|
| 452 | - $t = traiter_raccourcis($t); |
|
| 453 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 454 | - |
|
| 455 | - return $t; |
|
| 419 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 420 | + // prive etant historiquement ecrits sans argment $connect |
|
| 421 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 422 | + // ou il faut passer interdire_script explicitement |
|
| 423 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 424 | + // ne seront pas perturbes |
|
| 425 | + // FIXME: Trouver une solution pour avoir un type (string) unique sur $connect. |
|
| 426 | + $interdire_script = false; |
|
| 427 | + if (is_null($connect)) { |
|
| 428 | + $connect = ''; |
|
| 429 | + $interdire_script = true; |
|
| 430 | + $env['espace_prive'] = true; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + if (!$t) { |
|
| 434 | + return strval($t); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 438 | + // avant echappement des balises <html> |
|
| 439 | + // https://core.spip.net/issues/3371 |
|
| 440 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 441 | + // https://core.spip.net/issues/4166 |
|
| 442 | + if ( |
|
| 443 | + $interdire_script |
|
| 444 | + || $GLOBALS['filtrer_javascript'] == -1 |
|
| 445 | + || !empty($env['espace_prive']) && $GLOBALS['filtrer_javascript'] <= 0 |
|
| 446 | + || !empty($env['wysiwyg']) && $env['wysiwyg'] && $GLOBALS['filtrer_javascript'] <= 0 |
|
| 447 | + ) { |
|
| 448 | + $t = echapper_html_suspect($t, ['strict' => false], $connect, $env); |
|
| 449 | + } |
|
| 450 | + $t = echappe_html($t); |
|
| 451 | + $t = expanser_liens($t, $connect ?? '', $env); |
|
| 452 | + $t = traiter_raccourcis($t); |
|
| 453 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 454 | + |
|
| 455 | + return $t; |
|
| 456 | 456 | } |
@@ -106,12 +106,12 @@ discard block |
||
| 106 | 106 | foreach (['script', 'iframe'] as $tag) { |
| 107 | 107 | if ( |
| 108 | 108 | stripos($t, (string) "<$tag") !== false |
| 109 | - && preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | + && preg_match_all(',<'.$tag.'.*?($|</'.$tag.'.),isS', $t, $r, PREG_SET_ORDER) |
|
| 110 | 110 | ) { |
| 111 | 111 | foreach ($r as $regs) { |
| 112 | 112 | $t = str_replace( |
| 113 | 113 | $regs[0], |
| 114 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | + "<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>', |
|
| 115 | 115 | $t |
| 116 | 116 | ); |
| 117 | 117 | } |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // echapper les tags asp/php |
| 167 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | + $t = str_replace('<'.'%', '<%', $arg); |
|
| 168 | 168 | |
| 169 | 169 | // echapper le php |
| 170 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | + $t = str_replace('<'.'?', '<?', $t); |
|
| 171 | 171 | |
| 172 | 172 | // echapper le < script language=php > |
| 173 | 173 | $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
@@ -189,10 +189,10 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | // Reinserer les echappements des modeles |
| 191 | 191 | if (defined('_PROTEGE_JS_MODELES')) { |
| 192 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | + $t = echappe_retour($t, 'javascript'._PROTEGE_JS_MODELES); |
|
| 193 | 193 | } |
| 194 | 194 | if (defined('_PROTEGE_PHP_MODELES')) { |
| 195 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | + $t = echappe_retour($t, 'php'._PROTEGE_PHP_MODELES); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | return $dejavu[$mode_filtre][$arg] = $t; |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | define('_TYPO_PROTEGER', "!':;?~%-"); |
| 291 | 291 | define('_TYPO_PROTECTEUR', "\x1\x2\x3\x4\x5\x6\x7\x8"); |
| 292 | 292 | |
| 293 | -define('_TYPO_BALISE', ',</?[a-z!][^<>]*[' . preg_quote(_TYPO_PROTEGER) . '][^<>]*>,imsS'); |
|
| 293 | +define('_TYPO_BALISE', ',</?[a-z!][^<>]*['.preg_quote(_TYPO_PROTEGER).'][^<>]*>,imsS'); |
|
| 294 | 294 | |
| 295 | 295 | /** |
| 296 | 296 | * Corrige la typographie |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Filtres |
| 16 | 16 | */ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('inc/filtres_boites'); |
@@ -40,25 +40,25 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | function parametres_css_prive() { |
| 42 | 42 | |
| 43 | - $args = []; |
|
| 44 | - $args['v'] = $GLOBALS['spip_version_code']; |
|
| 45 | - $args['p'] = substr(md5((string) $GLOBALS['meta']['plugin']), 0, 4); |
|
| 46 | - $args['themes'] = implode(',', lister_themes_prives()); |
|
| 47 | - $args['ltr'] = $GLOBALS['spip_lang_left']; |
|
| 48 | - // un md5 des menus : si un menu change il faut maj la css |
|
| 49 | - $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : ''); |
|
| 43 | + $args = []; |
|
| 44 | + $args['v'] = $GLOBALS['spip_version_code']; |
|
| 45 | + $args['p'] = substr(md5((string) $GLOBALS['meta']['plugin']), 0, 4); |
|
| 46 | + $args['themes'] = implode(',', lister_themes_prives()); |
|
| 47 | + $args['ltr'] = $GLOBALS['spip_lang_left']; |
|
| 48 | + // un md5 des menus : si un menu change il faut maj la css |
|
| 49 | + $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : ''); |
|
| 50 | 50 | |
| 51 | - $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2; |
|
| 51 | + $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2; |
|
| 52 | 52 | |
| 53 | - $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 54 | - parse_str((string) $couleurs($c), $c); |
|
| 55 | - $args = array_merge($args, $c); |
|
| 53 | + $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 54 | + parse_str((string) $couleurs($c), $c); |
|
| 55 | + $args = array_merge($args, $c); |
|
| 56 | 56 | |
| 57 | - if (_request('var_mode') == 'recalcul' || defined('_VAR_MODE') && _VAR_MODE == 'recalcul') { |
|
| 58 | - $args['var_mode'] = 'recalcul'; |
|
| 59 | - } |
|
| 57 | + if (_request('var_mode') == 'recalcul' || defined('_VAR_MODE') && _VAR_MODE == 'recalcul') { |
|
| 58 | + $args['var_mode'] = 'recalcul'; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - return http_build_query($args); |
|
| 61 | + return http_build_query($args); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
@@ -81,95 +81,95 @@ discard block |
||
| 81 | 81 | * @return string |
| 82 | 82 | */ |
| 83 | 83 | function chercher_rubrique( |
| 84 | - $titre, |
|
| 85 | - $id_objet, |
|
| 86 | - $id_parent, |
|
| 87 | - $objet, |
|
| 88 | - $id_secteur, |
|
| 89 | - $restreint, |
|
| 90 | - $actionable = false, |
|
| 91 | - $retour_sans_cadre = false |
|
| 84 | + $titre, |
|
| 85 | + $id_objet, |
|
| 86 | + $id_parent, |
|
| 87 | + $objet, |
|
| 88 | + $id_secteur, |
|
| 89 | + $restreint, |
|
| 90 | + $actionable = false, |
|
| 91 | + $retour_sans_cadre = false |
|
| 92 | 92 | ) { |
| 93 | 93 | |
| 94 | - include_spip('inc/autoriser'); |
|
| 95 | - if ((int) $id_objet && !autoriser('modifier', $objet, $id_objet)) { |
|
| 96 | - return ''; |
|
| 97 | - } |
|
| 98 | - if (!sql_countsel('spip_rubriques')) { |
|
| 99 | - return ''; |
|
| 100 | - } |
|
| 101 | - $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc'); |
|
| 102 | - $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0); |
|
| 103 | - |
|
| 104 | - if ($id_parent == 0) { |
|
| 105 | - $logo = 'racine-24.png'; |
|
| 106 | - } elseif ($id_secteur == $id_parent) { |
|
| 107 | - $logo = 'secteur-24.png'; |
|
| 108 | - } else { |
|
| 109 | - $logo = 'rubrique-24.png'; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - $confirm = ''; |
|
| 113 | - if ($objet == 'rubrique') { |
|
| 114 | - // FIXME: Migration plus adapté vers le plugin Brèves ? |
|
| 115 | - // si c'est une rubrique-secteur contenant des breves, demander la |
|
| 116 | - // confirmation du deplacement |
|
| 117 | - if ( |
|
| 118 | - sql_table_exists('spip_breves') |
|
| 119 | - && ($contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . (int) $id_objet)) |
|
| 120 | - && $contient_breves > 0 |
|
| 121 | - ) { |
|
| 122 | - // FIXME: utiliser singulier_ou_pluriel, migrer dans plugin Brèves |
|
| 123 | - $scb = ($contient_breves > 1 ? 's' : ''); |
|
| 124 | - $scb = _T( |
|
| 125 | - 'avis_deplacement_rubrique', |
|
| 126 | - [ |
|
| 127 | - 'contient_breves' => $contient_breves, |
|
| 128 | - 'scb' => $scb |
|
| 129 | - ] |
|
| 130 | - ); |
|
| 131 | - $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
|
| 132 | - . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
|
| 133 | - . $scb . |
|
| 134 | - "</label></div></div>\n"; |
|
| 135 | - } else { |
|
| 136 | - $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - $form .= $confirm; |
|
| 140 | - if ($actionable) { |
|
| 141 | - if (str_contains($form, '<select')) { |
|
| 142 | - $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 143 | - . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 144 | - . '</div>'; |
|
| 145 | - } |
|
| 146 | - $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 147 | - if ($action = charger_fonction("editer_$objet", 'action', true)) { |
|
| 148 | - $form = generer_action_auteur( |
|
| 149 | - "editer_$objet", |
|
| 150 | - $id_objet, |
|
| 151 | - self(), |
|
| 152 | - $form, |
|
| 153 | - " method='post' class='submit_plongeur'" |
|
| 154 | - ); |
|
| 155 | - } else { |
|
| 156 | - $form = generer_action_auteur( |
|
| 157 | - 'editer_objet', |
|
| 158 | - "$objet/$id_objet", |
|
| 159 | - self(), |
|
| 160 | - $form, |
|
| 161 | - " method='post' class='submit_plongeur'" |
|
| 162 | - ); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if ($retour_sans_cadre) { |
|
| 167 | - return $form; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - include_spip('inc/presentation'); |
|
| 171 | - |
|
| 172 | - return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 94 | + include_spip('inc/autoriser'); |
|
| 95 | + if ((int) $id_objet && !autoriser('modifier', $objet, $id_objet)) { |
|
| 96 | + return ''; |
|
| 97 | + } |
|
| 98 | + if (!sql_countsel('spip_rubriques')) { |
|
| 99 | + return ''; |
|
| 100 | + } |
|
| 101 | + $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc'); |
|
| 102 | + $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0); |
|
| 103 | + |
|
| 104 | + if ($id_parent == 0) { |
|
| 105 | + $logo = 'racine-24.png'; |
|
| 106 | + } elseif ($id_secteur == $id_parent) { |
|
| 107 | + $logo = 'secteur-24.png'; |
|
| 108 | + } else { |
|
| 109 | + $logo = 'rubrique-24.png'; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + $confirm = ''; |
|
| 113 | + if ($objet == 'rubrique') { |
|
| 114 | + // FIXME: Migration plus adapté vers le plugin Brèves ? |
|
| 115 | + // si c'est une rubrique-secteur contenant des breves, demander la |
|
| 116 | + // confirmation du deplacement |
|
| 117 | + if ( |
|
| 118 | + sql_table_exists('spip_breves') |
|
| 119 | + && ($contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . (int) $id_objet)) |
|
| 120 | + && $contient_breves > 0 |
|
| 121 | + ) { |
|
| 122 | + // FIXME: utiliser singulier_ou_pluriel, migrer dans plugin Brèves |
|
| 123 | + $scb = ($contient_breves > 1 ? 's' : ''); |
|
| 124 | + $scb = _T( |
|
| 125 | + 'avis_deplacement_rubrique', |
|
| 126 | + [ |
|
| 127 | + 'contient_breves' => $contient_breves, |
|
| 128 | + 'scb' => $scb |
|
| 129 | + ] |
|
| 130 | + ); |
|
| 131 | + $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
|
| 132 | + . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
|
| 133 | + . $scb . |
|
| 134 | + "</label></div></div>\n"; |
|
| 135 | + } else { |
|
| 136 | + $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + $form .= $confirm; |
|
| 140 | + if ($actionable) { |
|
| 141 | + if (str_contains($form, '<select')) { |
|
| 142 | + $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 143 | + . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 144 | + . '</div>'; |
|
| 145 | + } |
|
| 146 | + $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 147 | + if ($action = charger_fonction("editer_$objet", 'action', true)) { |
|
| 148 | + $form = generer_action_auteur( |
|
| 149 | + "editer_$objet", |
|
| 150 | + $id_objet, |
|
| 151 | + self(), |
|
| 152 | + $form, |
|
| 153 | + " method='post' class='submit_plongeur'" |
|
| 154 | + ); |
|
| 155 | + } else { |
|
| 156 | + $form = generer_action_auteur( |
|
| 157 | + 'editer_objet', |
|
| 158 | + "$objet/$id_objet", |
|
| 159 | + self(), |
|
| 160 | + $form, |
|
| 161 | + " method='post' class='submit_plongeur'" |
|
| 162 | + ); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if ($retour_sans_cadre) { |
|
| 167 | + return $form; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + include_spip('inc/presentation'); |
|
| 171 | + |
|
| 172 | + return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
@@ -183,24 +183,24 @@ discard block |
||
| 183 | 183 | * @return bool |
| 184 | 184 | */ |
| 185 | 185 | function avoir_visiteurs($past = false, $accepter = true) { |
| 186 | - if ($GLOBALS['meta']['forums_publics'] == 'abo') { |
|
| 187 | - return true; |
|
| 188 | - } |
|
| 189 | - if ($accepter && $GLOBALS['meta']['accepter_visiteurs'] != 'non') { |
|
| 190 | - return true; |
|
| 191 | - } |
|
| 192 | - if (sql_countsel('spip_articles', "accepter_forum='abo'")) { |
|
| 193 | - return true; |
|
| 194 | - } |
|
| 195 | - if (!$past) { |
|
| 196 | - return false; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return sql_countsel( |
|
| 200 | - 'spip_auteurs', |
|
| 201 | - "statut NOT IN ('0minirezo','1comite', '5poubelle') |
|
| 186 | + if ($GLOBALS['meta']['forums_publics'] == 'abo') { |
|
| 187 | + return true; |
|
| 188 | + } |
|
| 189 | + if ($accepter && $GLOBALS['meta']['accepter_visiteurs'] != 'non') { |
|
| 190 | + return true; |
|
| 191 | + } |
|
| 192 | + if (sql_countsel('spip_articles', "accepter_forum='abo'")) { |
|
| 193 | + return true; |
|
| 194 | + } |
|
| 195 | + if (!$past) { |
|
| 196 | + return false; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return sql_countsel( |
|
| 200 | + 'spip_auteurs', |
|
| 201 | + "statut NOT IN ('0minirezo','1comite', '5poubelle') |
|
| 202 | 202 | AND (statut<>'nouveau' OR prefs NOT IN ('0minirezo','1comite', '5poubelle'))" |
| 203 | - ); |
|
| 203 | + ); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -216,18 +216,18 @@ discard block |
||
| 216 | 216 | * @return array |
| 217 | 217 | */ |
| 218 | 218 | function statuts_articles_visibles($statut_auteur) { |
| 219 | - static $auth = []; |
|
| 220 | - if (!isset($auth[$statut_auteur])) { |
|
| 221 | - $auth[$statut_auteur] = []; |
|
| 222 | - $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut'); |
|
| 223 | - foreach ($statuts as $s) { |
|
| 224 | - if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) { |
|
| 225 | - $auth[$statut_auteur][] = $s; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - return $auth[$statut_auteur]; |
|
| 219 | + static $auth = []; |
|
| 220 | + if (!isset($auth[$statut_auteur])) { |
|
| 221 | + $auth[$statut_auteur] = []; |
|
| 222 | + $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut'); |
|
| 223 | + foreach ($statuts as $s) { |
|
| 224 | + if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) { |
|
| 225 | + $auth[$statut_auteur][] = $s; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + return $auth[$statut_auteur]; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -241,38 +241,38 @@ discard block |
||
| 241 | 241 | * @return string |
| 242 | 242 | */ |
| 243 | 243 | function traduire_statut_auteur($statut, $attente = '') { |
| 244 | - $plus = ''; |
|
| 245 | - if ($statut == 'nouveau') { |
|
| 246 | - if ($attente) { |
|
| 247 | - $statut = $attente; |
|
| 248 | - $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 249 | - } else { |
|
| 250 | - return _T('info_statut_auteur_a_confirmer'); |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - $recom = [ |
|
| 255 | - 'info_administrateurs' => _T('item_administrateur_2'), |
|
| 256 | - 'info_redacteurs' => _T('intem_redacteur'), |
|
| 257 | - 'info_visiteurs' => _T('item_visiteur'), |
|
| 258 | - '5poubelle' => _T('texte_statut_poubelle'), // bouh |
|
| 259 | - ]; |
|
| 260 | - if (isset($recom[$statut])) { |
|
| 261 | - return $recom[$statut] . $plus; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - // retrouver directement par le statut sinon |
|
| 265 | - if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
|
| 266 | - if (isset($recom[$t])) { |
|
| 267 | - return $recom[$t] . $plus; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - return _T($t) . $plus; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // si on a pas reussi a le traduire, retournons la chaine telle quelle |
|
| 274 | - // c'est toujours plus informatif que rien du tout |
|
| 275 | - return $statut; |
|
| 244 | + $plus = ''; |
|
| 245 | + if ($statut == 'nouveau') { |
|
| 246 | + if ($attente) { |
|
| 247 | + $statut = $attente; |
|
| 248 | + $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 249 | + } else { |
|
| 250 | + return _T('info_statut_auteur_a_confirmer'); |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + $recom = [ |
|
| 255 | + 'info_administrateurs' => _T('item_administrateur_2'), |
|
| 256 | + 'info_redacteurs' => _T('intem_redacteur'), |
|
| 257 | + 'info_visiteurs' => _T('item_visiteur'), |
|
| 258 | + '5poubelle' => _T('texte_statut_poubelle'), // bouh |
|
| 259 | + ]; |
|
| 260 | + if (isset($recom[$statut])) { |
|
| 261 | + return $recom[$statut] . $plus; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + // retrouver directement par le statut sinon |
|
| 265 | + if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
|
| 266 | + if (isset($recom[$t])) { |
|
| 267 | + return $recom[$t] . $plus; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + return _T($t) . $plus; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // si on a pas reussi a le traduire, retournons la chaine telle quelle |
|
| 274 | + // c'est toujours plus informatif que rien du tout |
|
| 275 | + return $statut; |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -283,29 +283,29 @@ discard block |
||
| 283 | 283 | * @return string |
| 284 | 284 | */ |
| 285 | 285 | function afficher_qui_edite($id_objet, $objet): string { |
| 286 | - static $qui = []; |
|
| 287 | - if (isset($qui[$objet][$id_objet])) { |
|
| 288 | - return $qui[$objet][$id_objet]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - include_spip('inc/config'); |
|
| 292 | - if (lire_config('articles_modif', 'non') === 'non') { |
|
| 293 | - return $qui[$objet][$id_objet] = ''; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - include_spip('inc/drapeau_edition'); |
|
| 297 | - $modif = mention_qui_edite($id_objet, $objet); |
|
| 298 | - if (!$modif) { |
|
| 299 | - return $qui[$objet][$id_objet] = ''; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - include_spip('base/objets'); |
|
| 303 | - $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 304 | - if (isset($infos['texte_signale_edition'])) { |
|
| 305 | - return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif); |
|
| 286 | + static $qui = []; |
|
| 287 | + if (isset($qui[$objet][$id_objet])) { |
|
| 288 | + return $qui[$objet][$id_objet]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + include_spip('inc/config'); |
|
| 292 | + if (lire_config('articles_modif', 'non') === 'non') { |
|
| 293 | + return $qui[$objet][$id_objet] = ''; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + include_spip('inc/drapeau_edition'); |
|
| 297 | + $modif = mention_qui_edite($id_objet, $objet); |
|
| 298 | + if (!$modif) { |
|
| 299 | + return $qui[$objet][$id_objet] = ''; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + include_spip('base/objets'); |
|
| 303 | + $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 304 | + if (isset($infos['texte_signale_edition'])) { |
|
| 305 | + return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -323,53 +323,53 @@ discard block |
||
| 323 | 323 | * @return array |
| 324 | 324 | */ |
| 325 | 325 | function auteurs_lister_statuts($quoi = 'tous', $en_base = true): array { |
| 326 | - if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 327 | - define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - switch ($quoi) { |
|
| 331 | - case 'redacteurs': |
|
| 332 | - $statut = AUTEURS_MIN_REDAC; |
|
| 333 | - $statut = explode(',', (string) $statut); |
|
| 334 | - if ($en_base) { |
|
| 335 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 336 | - $retire = array_diff($statut, $check); |
|
| 337 | - $statut = array_diff($statut, $retire); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - return array_unique($statut); |
|
| 341 | - |
|
| 342 | - case 'visiteurs': |
|
| 343 | - $statut = []; |
|
| 344 | - $exclus = AUTEURS_MIN_REDAC; |
|
| 345 | - $exclus = explode(',', (string) $exclus); |
|
| 346 | - if (!$en_base) { |
|
| 347 | - // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 348 | - $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 349 | - } |
|
| 350 | - $s_complement = array_column( |
|
| 351 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 352 | - 'statut' |
|
| 353 | - ); |
|
| 354 | - |
|
| 355 | - return array_unique([...$statut, ...$s_complement]); |
|
| 356 | - |
|
| 357 | - default: |
|
| 358 | - case 'tous': |
|
| 359 | - $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 360 | - $s_complement = array_column( |
|
| 361 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 362 | - 'statut' |
|
| 363 | - ); |
|
| 364 | - $statut = [...$statut, ...$s_complement]; |
|
| 365 | - if ($en_base) { |
|
| 366 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 367 | - $retire = array_diff($statut, $check); |
|
| 368 | - $statut = array_diff($statut, $retire); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - return array_unique($statut); |
|
| 372 | - } |
|
| 326 | + if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 327 | + define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + switch ($quoi) { |
|
| 331 | + case 'redacteurs': |
|
| 332 | + $statut = AUTEURS_MIN_REDAC; |
|
| 333 | + $statut = explode(',', (string) $statut); |
|
| 334 | + if ($en_base) { |
|
| 335 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 336 | + $retire = array_diff($statut, $check); |
|
| 337 | + $statut = array_diff($statut, $retire); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + return array_unique($statut); |
|
| 341 | + |
|
| 342 | + case 'visiteurs': |
|
| 343 | + $statut = []; |
|
| 344 | + $exclus = AUTEURS_MIN_REDAC; |
|
| 345 | + $exclus = explode(',', (string) $exclus); |
|
| 346 | + if (!$en_base) { |
|
| 347 | + // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 348 | + $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 349 | + } |
|
| 350 | + $s_complement = array_column( |
|
| 351 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 352 | + 'statut' |
|
| 353 | + ); |
|
| 354 | + |
|
| 355 | + return array_unique([...$statut, ...$s_complement]); |
|
| 356 | + |
|
| 357 | + default: |
|
| 358 | + case 'tous': |
|
| 359 | + $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 360 | + $s_complement = array_column( |
|
| 361 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 362 | + 'statut' |
|
| 363 | + ); |
|
| 364 | + $statut = [...$statut, ...$s_complement]; |
|
| 365 | + if ($en_base) { |
|
| 366 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 367 | + $retire = array_diff($statut, $check); |
|
| 368 | + $statut = array_diff($statut, $retire); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + return array_unique($statut); |
|
| 372 | + } |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -385,28 +385,28 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | function trouver_rubrique_creer_objet($id_rubrique, $objet) { |
| 387 | 387 | |
| 388 | - if (!$id_rubrique && defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') && _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 389 | - $in = (is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 390 | - ? ' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']) |
|
| 391 | - : ''; |
|
| 392 | - |
|
| 393 | - // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 394 | - if ($objet == 'rubrique') { |
|
| 395 | - $id_rubrique = 0; |
|
| 396 | - } else { |
|
| 397 | - $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 401 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 402 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 403 | - while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 404 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return $id_rubrique; |
|
| 388 | + if (!$id_rubrique && defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') && _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 389 | + $in = (is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 390 | + ? ' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']) |
|
| 391 | + : ''; |
|
| 392 | + |
|
| 393 | + // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 394 | + if ($objet == 'rubrique') { |
|
| 395 | + $id_rubrique = 0; |
|
| 396 | + } else { |
|
| 397 | + $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 401 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 402 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 403 | + while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 404 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return $id_rubrique; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -417,25 +417,25 @@ discard block |
||
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | 419 | function lien_article_virtuel($virtuel) { |
| 420 | - include_spip('inc/lien'); |
|
| 421 | - if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 422 | - return ''; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - $joli = $virtuel; |
|
| 426 | - $parts = parse_url($virtuel); |
|
| 427 | - if (!empty($parts['query']) && str_contains($parts['query'], ']')) { |
|
| 428 | - $query = str_replace(['[', ']'], [urlencode('['), urlencode(']')], $parts['query']); |
|
| 429 | - $virtuel = str_replace('?' . $parts['query'], "?$query", $virtuel); |
|
| 430 | - } |
|
| 431 | - if ($virtuel !== $joli) { |
|
| 432 | - $joli = propre('[' . $joli . ' -> ' . $virtuel . ']'); |
|
| 433 | - } |
|
| 434 | - else { |
|
| 435 | - $joli = propre('[->' . $virtuel . ']'); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - return $joli; |
|
| 420 | + include_spip('inc/lien'); |
|
| 421 | + if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 422 | + return ''; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + $joli = $virtuel; |
|
| 426 | + $parts = parse_url($virtuel); |
|
| 427 | + if (!empty($parts['query']) && str_contains($parts['query'], ']')) { |
|
| 428 | + $query = str_replace(['[', ']'], [urlencode('['), urlencode(']')], $parts['query']); |
|
| 429 | + $virtuel = str_replace('?' . $parts['query'], "?$query", $virtuel); |
|
| 430 | + } |
|
| 431 | + if ($virtuel !== $joli) { |
|
| 432 | + $joli = propre('[' . $joli . ' -> ' . $virtuel . ']'); |
|
| 433 | + } |
|
| 434 | + else { |
|
| 435 | + $joli = propre('[->' . $virtuel . ']'); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + return $joli; |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | |
@@ -458,11 +458,11 @@ discard block |
||
| 458 | 458 | * @filtre |
| 459 | 459 | */ |
| 460 | 460 | function bouton_spip_rss($op, $args = [], $lang = '', $title = 'RSS') { |
| 461 | - include_spip('inc/acces'); |
|
| 462 | - $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 461 | + include_spip('inc/acces'); |
|
| 462 | + $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 463 | 463 | |
| 464 | - $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
|
| 465 | - return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 464 | + $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
|
| 465 | + return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | |
@@ -474,72 +474,72 @@ discard block |
||
| 474 | 474 | */ |
| 475 | 475 | function alertes_auteur($id_auteur): string { |
| 476 | 476 | |
| 477 | - $alertes = []; |
|
| 478 | - |
|
| 479 | - if ( |
|
| 480 | - isset($GLOBALS['meta']['message_crash_tables']) |
|
| 481 | - && autoriser('detruire', null, null, $id_auteur) |
|
| 482 | - ) { |
|
| 483 | - include_spip('genie/maintenance'); |
|
| 484 | - if ($msg = message_crash_tables()) { |
|
| 485 | - $alertes[] = $msg; |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - if ( |
|
| 490 | - isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 491 | - && $GLOBALS['meta']['message_crash_plugins'] |
|
| 492 | - && autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 493 | - && is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 494 | - ) { |
|
| 495 | - $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 496 | - $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 500 | - if ($a && is_array($a = unserialize($a)) && count($a)) { |
|
| 501 | - $update = false; |
|
| 502 | - if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 503 | - $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 504 | - unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 505 | - $update = true; |
|
| 506 | - } |
|
| 507 | - if (isset($a[''])) { |
|
| 508 | - $alertes = array_merge($alertes, $a['']); |
|
| 509 | - unset($a['']); |
|
| 510 | - $update = true; |
|
| 511 | - } |
|
| 512 | - if ($update) { |
|
| 513 | - ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 514 | - } |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - if ( |
|
| 518 | - isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 519 | - && autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 520 | - ) { |
|
| 521 | - include_spip('inc/plugin'); |
|
| 522 | - $alertes[] = plugin_donne_erreurs(); |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $alertes = pipeline( |
|
| 526 | - 'alertes_auteur', |
|
| 527 | - [ |
|
| 528 | - 'args' => [ |
|
| 529 | - 'id_auteur' => $id_auteur, |
|
| 530 | - 'exec' => _request('exec'), |
|
| 531 | - ], |
|
| 532 | - 'data' => $alertes |
|
| 533 | - ] |
|
| 534 | - ); |
|
| 535 | - |
|
| 536 | - if ($alertes = array_filter($alertes)) { |
|
| 537 | - return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 538 | - implode(' | ', $alertes) |
|
| 539 | - . '</div></div>'; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - return ''; |
|
| 477 | + $alertes = []; |
|
| 478 | + |
|
| 479 | + if ( |
|
| 480 | + isset($GLOBALS['meta']['message_crash_tables']) |
|
| 481 | + && autoriser('detruire', null, null, $id_auteur) |
|
| 482 | + ) { |
|
| 483 | + include_spip('genie/maintenance'); |
|
| 484 | + if ($msg = message_crash_tables()) { |
|
| 485 | + $alertes[] = $msg; |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + if ( |
|
| 490 | + isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 491 | + && $GLOBALS['meta']['message_crash_plugins'] |
|
| 492 | + && autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 493 | + && is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 494 | + ) { |
|
| 495 | + $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 496 | + $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 500 | + if ($a && is_array($a = unserialize($a)) && count($a)) { |
|
| 501 | + $update = false; |
|
| 502 | + if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 503 | + $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 504 | + unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 505 | + $update = true; |
|
| 506 | + } |
|
| 507 | + if (isset($a[''])) { |
|
| 508 | + $alertes = array_merge($alertes, $a['']); |
|
| 509 | + unset($a['']); |
|
| 510 | + $update = true; |
|
| 511 | + } |
|
| 512 | + if ($update) { |
|
| 513 | + ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + if ( |
|
| 518 | + isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 519 | + && autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 520 | + ) { |
|
| 521 | + include_spip('inc/plugin'); |
|
| 522 | + $alertes[] = plugin_donne_erreurs(); |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $alertes = pipeline( |
|
| 526 | + 'alertes_auteur', |
|
| 527 | + [ |
|
| 528 | + 'args' => [ |
|
| 529 | + 'id_auteur' => $id_auteur, |
|
| 530 | + 'exec' => _request('exec'), |
|
| 531 | + ], |
|
| 532 | + 'data' => $alertes |
|
| 533 | + ] |
|
| 534 | + ); |
|
| 535 | + |
|
| 536 | + if ($alertes = array_filter($alertes)) { |
|
| 537 | + return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 538 | + implode(' | ', $alertes) |
|
| 539 | + . '</div></div>'; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + return ''; |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | /** |
@@ -549,9 +549,9 @@ discard block |
||
| 549 | 549 | * @return string |
| 550 | 550 | */ |
| 551 | 551 | function filtre_afficher_enfant_rub_dist($id_rubrique) { |
| 552 | - include_spip('inc/presenter_enfants'); |
|
| 552 | + include_spip('inc/presenter_enfants'); |
|
| 553 | 553 | |
| 554 | - return afficher_enfant_rub((int) $id_rubrique); |
|
| 554 | + return afficher_enfant_rub((int) $id_rubrique); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | /** |
@@ -569,15 +569,15 @@ discard block |
||
| 569 | 569 | * @return string |
| 570 | 570 | */ |
| 571 | 571 | function afficher_plus_info($lien, $titre = '+', $titre_lien = '') { |
| 572 | - $titre = attribut_html($titre); |
|
| 573 | - $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 574 | - http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 575 | - |
|
| 576 | - if (!$titre_lien) { |
|
| 577 | - return $icone; |
|
| 578 | - } else { |
|
| 579 | - return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 580 | - } |
|
| 572 | + $titre = attribut_html($titre); |
|
| 573 | + $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 574 | + http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 575 | + |
|
| 576 | + if (!$titre_lien) { |
|
| 577 | + return $icone; |
|
| 578 | + } else { |
|
| 579 | + return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 580 | + } |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | |
@@ -596,20 +596,20 @@ discard block |
||
| 596 | 596 | * @return array |
| 597 | 597 | */ |
| 598 | 598 | function lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien) { |
| 599 | - $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 600 | - if (!(is_countable($res) ? count($res) : 0)) { |
|
| 601 | - return []; |
|
| 602 | - } |
|
| 603 | - $r = reset($res); |
|
| 604 | - $colonne_id = ($objet_source == $objet_lien ? id_table_objet($objet_source) : 'id_objet'); |
|
| 605 | - if (isset($r['rang_lien'])) { |
|
| 606 | - $l = array_column($res, 'rang_lien', $colonne_id); |
|
| 607 | - asort($l); |
|
| 608 | - $l = array_keys($l); |
|
| 609 | - } else { |
|
| 610 | - // Si les liens qu'on cherche sont ceux de la table de lien, l'info est dans la clé de l'objet |
|
| 611 | - // Sinon c'est dans "id_objet" |
|
| 612 | - $l = array_column($res, $colonne_id); |
|
| 613 | - } |
|
| 614 | - return $l; |
|
| 599 | + $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 600 | + if (!(is_countable($res) ? count($res) : 0)) { |
|
| 601 | + return []; |
|
| 602 | + } |
|
| 603 | + $r = reset($res); |
|
| 604 | + $colonne_id = ($objet_source == $objet_lien ? id_table_objet($objet_source) : 'id_objet'); |
|
| 605 | + if (isset($r['rang_lien'])) { |
|
| 606 | + $l = array_column($res, 'rang_lien', $colonne_id); |
|
| 607 | + asort($l); |
|
| 608 | + $l = array_keys($l); |
|
| 609 | + } else { |
|
| 610 | + // Si les liens qu'on cherche sont ceux de la table de lien, l'info est dans la clé de l'objet |
|
| 611 | + // Sinon c'est dans "id_objet" |
|
| 612 | + $l = array_column($res, $colonne_id); |
|
| 613 | + } |
|
| 614 | + return $l; |
|
| 615 | 615 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | // confirmation du deplacement |
| 117 | 117 | if ( |
| 118 | 118 | sql_table_exists('spip_breves') |
| 119 | - && ($contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . (int) $id_objet)) |
|
| 119 | + && ($contient_breves = sql_countsel('spip_breves', 'id_rubrique='.(int) $id_objet)) |
|
| 120 | 120 | && $contient_breves > 0 |
| 121 | 121 | ) { |
| 122 | 122 | // FIXME: utiliser singulier_ou_pluriel, migrer dans plugin Brèves |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | ); |
| 131 | 131 | $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
| 132 | 132 | . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
| 133 | - . $scb . |
|
| 133 | + . $scb. |
|
| 134 | 134 | "</label></div></div>\n"; |
| 135 | 135 | } else { |
| 136 | 136 | $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | $form .= $confirm; |
| 140 | 140 | if ($actionable) { |
| 141 | 141 | if (str_contains($form, '<select')) { |
| 142 | - $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 143 | - . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 142 | + $form .= "<div style='text-align: ".$GLOBALS['spip_lang_right'].";'>" |
|
| 143 | + . '<input class="fondo submit btn" type="submit" value="'._T('bouton_choisir').'"/>' |
|
| 144 | 144 | . '</div>'; |
| 145 | 145 | } |
| 146 | - $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 146 | + $form = "<input type='hidden' name='editer_$objet' value='oui' />\n".$form; |
|
| 147 | 147 | if ($action = charger_fonction("editer_$objet", 'action', true)) { |
| 148 | 148 | $form = generer_action_auteur( |
| 149 | 149 | "editer_$objet", |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | include_spip('inc/presentation'); |
| 171 | 171 | |
| 172 | - return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 172 | + return debut_cadre_couleur($logo, true, '', $titre).$form.fin_cadre_couleur(); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | if ($statut == 'nouveau') { |
| 246 | 246 | if ($attente) { |
| 247 | 247 | $statut = $attente; |
| 248 | - $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 248 | + $plus = ' ('._T('info_statut_auteur_a_confirmer').')'; |
|
| 249 | 249 | } else { |
| 250 | 250 | return _T('info_statut_auteur_a_confirmer'); |
| 251 | 251 | } |
@@ -258,16 +258,16 @@ discard block |
||
| 258 | 258 | '5poubelle' => _T('texte_statut_poubelle'), // bouh |
| 259 | 259 | ]; |
| 260 | 260 | if (isset($recom[$statut])) { |
| 261 | - return $recom[$statut] . $plus; |
|
| 261 | + return $recom[$statut].$plus; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // retrouver directement par le statut sinon |
| 265 | 265 | if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
| 266 | 266 | if (isset($recom[$t])) { |
| 267 | - return $recom[$t] . $plus; |
|
| 267 | + return $recom[$t].$plus; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - return _T($t) . $plus; |
|
| 270 | + return _T($t).$plus; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // si on a pas reussi a le traduire, retournons la chaine telle quelle |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | |
| 388 | 388 | if (!$id_rubrique && defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') && _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
| 389 | 389 | $in = (is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
| 390 | - ? ' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']) |
|
| 390 | + ? ' AND '.sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']) |
|
| 391 | 391 | : ''; |
| 392 | 392 | |
| 393 | 393 | // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
@@ -426,13 +426,13 @@ discard block |
||
| 426 | 426 | $parts = parse_url($virtuel); |
| 427 | 427 | if (!empty($parts['query']) && str_contains($parts['query'], ']')) { |
| 428 | 428 | $query = str_replace(['[', ']'], [urlencode('['), urlencode(']')], $parts['query']); |
| 429 | - $virtuel = str_replace('?' . $parts['query'], "?$query", $virtuel); |
|
| 429 | + $virtuel = str_replace('?'.$parts['query'], "?$query", $virtuel); |
|
| 430 | 430 | } |
| 431 | 431 | if ($virtuel !== $joli) { |
| 432 | - $joli = propre('[' . $joli . ' -> ' . $virtuel . ']'); |
|
| 432 | + $joli = propre('['.$joli.' -> '.$virtuel.']'); |
|
| 433 | 433 | } |
| 434 | 434 | else { |
| 435 | - $joli = propre('[->' . $virtuel . ']'); |
|
| 435 | + $joli = propre('[->'.$virtuel.']'); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | return $joli; |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
| 463 | 463 | |
| 464 | 464 | $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
| 465 | - return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 465 | + return "<a style='float: ".$GLOBALS['spip_lang_right'].";' href='$url'>$clic</a>"; |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | ); |
| 535 | 535 | |
| 536 | 536 | if ($alertes = array_filter($alertes)) { |
| 537 | - return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 537 | + return "<div class='wrap-messages-alertes'><div class='messages-alertes'>". |
|
| 538 | 538 | implode(' | ', $alertes) |
| 539 | 539 | . '</div></div>'; |
| 540 | 540 | } |
@@ -570,13 +570,13 @@ discard block |
||
| 570 | 570 | */ |
| 571 | 571 | function afficher_plus_info($lien, $titre = '+', $titre_lien = '') { |
| 572 | 572 | $titre = attribut_html($titre); |
| 573 | - $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 574 | - http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 573 | + $icone = "\n<a href='$lien' title='$titre' class='plus_info'>". |
|
| 574 | + http_img_pack('information-16.png', $titre).'</a>'; |
|
| 575 | 575 | |
| 576 | 576 | if (!$titre_lien) { |
| 577 | 577 | return $icone; |
| 578 | 578 | } else { |
| 579 | - return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 579 | + return $icone."\n<a href='$lien'>$titre_lien</a>"; |
|
| 580 | 580 | } |
| 581 | 581 | } |
| 582 | 582 | |
@@ -430,8 +430,7 @@ |
||
| 430 | 430 | } |
| 431 | 431 | if ($virtuel !== $joli) { |
| 432 | 432 | $joli = propre('[' . $joli . ' -> ' . $virtuel . ']'); |
| 433 | - } |
|
| 434 | - else { |
|
| 433 | + } else { |
|
| 435 | 434 | $joli = propre('[->' . $virtuel . ']'); |
| 436 | 435 | } |
| 437 | 436 | |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | ) { |
| 193 | 193 | $r = nettoyer_url_page($url, $contexte); |
| 194 | 194 | if ($r) { |
| 195 | - [$contexte, $type, , , $suite] = $r; |
|
| 195 | + [$contexte, $type,,, $suite] = $r; |
|
| 196 | 196 | $_id = id_table_objet($type); |
| 197 | 197 | $id_objet = $contexte[$_id]; |
| 198 | 198 | $url_propre = generer_objet_url($id_objet, $type); |
@@ -263,9 +263,9 @@ discard block |
||
| 263 | 263 | */ |
| 264 | 264 | function nettoyer_url_page($url, $contexte = []) { |
| 265 | 265 | $url_objets = urls_liste_objets(); |
| 266 | - $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 267 | - $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 268 | - $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,'; |
|
| 266 | + $raccourci_url_page_html = ',^(?:[^?]*/)?('.$url_objets.')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 267 | + $raccourci_url_page_id = ',^(?:[^?]*/)?('.$url_objets.')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 268 | + $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?]('.$url_objets.')([0-9]+)=?(&.*)?$,'; |
|
| 269 | 269 | |
| 270 | 270 | if ( |
| 271 | 271 | preg_match($raccourci_url_page_html, $url, $regs) |
@@ -303,9 +303,9 @@ discard block |
||
| 303 | 303 | $id = intval($id); |
| 304 | 304 | if (!isset($furls[$objet])) { |
| 305 | 305 | if ( |
| 306 | - function_exists($f = 'generer_' . $objet . '_url_ecrire') |
|
| 306 | + function_exists($f = 'generer_'.$objet.'_url_ecrire') |
|
| 307 | 307 | || ($f = charger_fonction($f, 'urls', true)) |
| 308 | - || function_exists($f = 'generer_url_ecrire_' . $objet) // deprecated |
|
| 308 | + || function_exists($f = 'generer_url_ecrire_'.$objet) // deprecated |
|
| 309 | 309 | || ($f = charger_fonction($f, 'urls', true)) // deprecated |
| 310 | 310 | ) { |
| 311 | 311 | $furls[$objet] = $f; |
@@ -324,10 +324,10 @@ discard block |
||
| 324 | 324 | if ($public || $connect) { |
| 325 | 325 | return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect); |
| 326 | 326 | } |
| 327 | - $a = id_table_objet($objet) . '=' . intval($id); |
|
| 327 | + $a = id_table_objet($objet).'='.intval($id); |
|
| 328 | 328 | if (!function_exists('objet_info')) { |
| 329 | 329 | include_spip('inc/filtres'); |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : ''); |
|
| 332 | + return generer_url_ecrire(objet_info($objet, 'url_voir'), $a.($args ? "&$args" : '')).($ancre ? "#$ancre" : ''); |
|
| 333 | 333 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | include_spip('base/objets'); |
| 22 | 22 | |
@@ -56,106 +56,106 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | */ |
| 58 | 58 | function urls_decoder_url($url, $fond = '', $contexte = [], $assembler = false) { |
| 59 | - static $current_base = null; |
|
| 59 | + static $current_base = null; |
|
| 60 | 60 | |
| 61 | - // les anciennes fonctions modifient directement les globales |
|
| 62 | - // on les sauve avant l'appel, et on les retablit apres ! |
|
| 63 | - $save = [ |
|
| 64 | - $GLOBALS['fond'] ?? null, |
|
| 65 | - $GLOBALS['contexte'] ?? null, |
|
| 66 | - $_SERVER['REDIRECT_url_propre'] ?? null, |
|
| 67 | - $_ENV['url_propre'] ?? null, |
|
| 68 | - $GLOBALS['profondeur_url'] |
|
| 69 | - ]; |
|
| 61 | + // les anciennes fonctions modifient directement les globales |
|
| 62 | + // on les sauve avant l'appel, et on les retablit apres ! |
|
| 63 | + $save = [ |
|
| 64 | + $GLOBALS['fond'] ?? null, |
|
| 65 | + $GLOBALS['contexte'] ?? null, |
|
| 66 | + $_SERVER['REDIRECT_url_propre'] ?? null, |
|
| 67 | + $_ENV['url_propre'] ?? null, |
|
| 68 | + $GLOBALS['profondeur_url'] |
|
| 69 | + ]; |
|
| 70 | 70 | |
| 71 | - if (is_null($current_base)) { |
|
| 72 | - include_spip('inc/filtres_mini'); |
|
| 73 | - // le decodage des urls se fait toujours par rapport au site public |
|
| 74 | - $current_base = url_absolue(_DIR_RACINE ?: './'); |
|
| 75 | - } |
|
| 76 | - if (str_starts_with($url, $current_base)) { |
|
| 77 | - $url = substr($url, strlen($current_base)); |
|
| 78 | - } |
|
| 71 | + if (is_null($current_base)) { |
|
| 72 | + include_spip('inc/filtres_mini'); |
|
| 73 | + // le decodage des urls se fait toujours par rapport au site public |
|
| 74 | + $current_base = url_absolue(_DIR_RACINE ?: './'); |
|
| 75 | + } |
|
| 76 | + if (str_starts_with($url, $current_base)) { |
|
| 77 | + $url = substr($url, strlen($current_base)); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - // si on est en train d'assembler la page principale, |
|
| 81 | - // recuperer l'url depuis les globales url propres si fournies |
|
| 82 | - // sinon extraire la bonne portion d'url |
|
| 83 | - if ($assembler) { |
|
| 84 | - if (isset($_SERVER['REDIRECT_url_propre'])) { |
|
| 85 | - $url = $_SERVER['REDIRECT_url_propre']; |
|
| 86 | - } elseif (isset($_ENV['url_propre'])) { |
|
| 87 | - $url = $_ENV['url_propre']; |
|
| 88 | - } else { |
|
| 89 | - $qs = explode('?', $url); |
|
| 90 | - // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee |
|
| 91 | - $url = ltrim($qs[0], '/'); |
|
| 92 | - $url = explode('/', $url); |
|
| 93 | - while (count($url) > $GLOBALS['profondeur_url'] + 1) { |
|
| 94 | - array_shift($url); |
|
| 95 | - } |
|
| 96 | - $qs[0] = implode('/', $url); |
|
| 97 | - $url = implode('?', $qs); |
|
| 98 | - } |
|
| 99 | - } |
|
| 80 | + // si on est en train d'assembler la page principale, |
|
| 81 | + // recuperer l'url depuis les globales url propres si fournies |
|
| 82 | + // sinon extraire la bonne portion d'url |
|
| 83 | + if ($assembler) { |
|
| 84 | + if (isset($_SERVER['REDIRECT_url_propre'])) { |
|
| 85 | + $url = $_SERVER['REDIRECT_url_propre']; |
|
| 86 | + } elseif (isset($_ENV['url_propre'])) { |
|
| 87 | + $url = $_ENV['url_propre']; |
|
| 88 | + } else { |
|
| 89 | + $qs = explode('?', $url); |
|
| 90 | + // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee |
|
| 91 | + $url = ltrim($qs[0], '/'); |
|
| 92 | + $url = explode('/', $url); |
|
| 93 | + while (count($url) > $GLOBALS['profondeur_url'] + 1) { |
|
| 94 | + array_shift($url); |
|
| 95 | + } |
|
| 96 | + $qs[0] = implode('/', $url); |
|
| 97 | + $url = implode('?', $qs); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - unset($_SERVER['REDIRECT_url_propre']); |
|
| 102 | - unset($_ENV['url_propre']); |
|
| 103 | - include_spip('inc/filtres_mini'); |
|
| 104 | - if (!str_contains($url, '://')) { |
|
| 105 | - $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/'); |
|
| 106 | - } else { |
|
| 107 | - $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/')); |
|
| 108 | - } |
|
| 101 | + unset($_SERVER['REDIRECT_url_propre']); |
|
| 102 | + unset($_ENV['url_propre']); |
|
| 103 | + include_spip('inc/filtres_mini'); |
|
| 104 | + if (!str_contains($url, '://')) { |
|
| 105 | + $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/'); |
|
| 106 | + } else { |
|
| 107 | + $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/')); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - $url_redirect = ''; |
|
| 111 | - $decoder = charger_fonction_url('decoder'); |
|
| 112 | - if ($decoder) { |
|
| 113 | - $a = $decoder($url, $fond, $contexte); |
|
| 114 | - if (is_array($a)) { |
|
| 115 | - [$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null); |
|
| 116 | - $url_redirect ??= ''; |
|
| 117 | - if ($url_redirect === $url) { |
|
| 118 | - $url_redirect = ''; |
|
| 119 | - } // securite pour eviter une redirection infinie |
|
| 120 | - if ($assembler && strlen($url_redirect)) { |
|
| 121 | - spip_logger()->info("Redirige $url vers $url_redirect"); |
|
| 122 | - include_spip('inc/headers'); |
|
| 123 | - redirige_par_entete($url_redirect, '', 301); |
|
| 124 | - } |
|
| 125 | - if (isset($nfond)) { |
|
| 126 | - $fond = $nfond; |
|
| 127 | - } else { |
|
| 128 | - if ( |
|
| 129 | - $fond == '' |
|
| 130 | - || $fond == 'type_urls' /* compat avec htaccess 2.0.0 */ |
|
| 131 | - ) { |
|
| 132 | - $fond = $type; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - if (isset($ncontexte)) { |
|
| 136 | - $contexte = $ncontexte; |
|
| 137 | - } |
|
| 138 | - if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) { |
|
| 139 | - $contexte['type'] = $type; |
|
| 140 | - } |
|
| 141 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 142 | - $contexte['type-page'] = $type; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 110 | + $url_redirect = ''; |
|
| 111 | + $decoder = charger_fonction_url('decoder'); |
|
| 112 | + if ($decoder) { |
|
| 113 | + $a = $decoder($url, $fond, $contexte); |
|
| 114 | + if (is_array($a)) { |
|
| 115 | + [$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null); |
|
| 116 | + $url_redirect ??= ''; |
|
| 117 | + if ($url_redirect === $url) { |
|
| 118 | + $url_redirect = ''; |
|
| 119 | + } // securite pour eviter une redirection infinie |
|
| 120 | + if ($assembler && strlen($url_redirect)) { |
|
| 121 | + spip_logger()->info("Redirige $url vers $url_redirect"); |
|
| 122 | + include_spip('inc/headers'); |
|
| 123 | + redirige_par_entete($url_redirect, '', 301); |
|
| 124 | + } |
|
| 125 | + if (isset($nfond)) { |
|
| 126 | + $fond = $nfond; |
|
| 127 | + } else { |
|
| 128 | + if ( |
|
| 129 | + $fond == '' |
|
| 130 | + || $fond == 'type_urls' /* compat avec htaccess 2.0.0 */ |
|
| 131 | + ) { |
|
| 132 | + $fond = $type; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + if (isset($ncontexte)) { |
|
| 136 | + $contexte = $ncontexte; |
|
| 137 | + } |
|
| 138 | + if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) { |
|
| 139 | + $contexte['type'] = $type; |
|
| 140 | + } |
|
| 141 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 142 | + $contexte['type-page'] = $type; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - // retablir les globales |
|
| 148 | - [$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save; |
|
| 147 | + // retablir les globales |
|
| 148 | + [$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save; |
|
| 149 | 149 | |
| 150 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 151 | - // d'inversion url => objet |
|
| 152 | - // maintenir pour compat ? |
|
| 153 | - #if ($assembler) { |
|
| 154 | - # unset($_SERVER['REDIRECT_url_propre']); |
|
| 155 | - # unset($_ENV['url_propre']); |
|
| 156 | - #} |
|
| 150 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 151 | + // d'inversion url => objet |
|
| 152 | + // maintenir pour compat ? |
|
| 153 | + #if ($assembler) { |
|
| 154 | + # unset($_SERVER['REDIRECT_url_propre']); |
|
| 155 | + # unset($_ENV['url_propre']); |
|
| 156 | + #} |
|
| 157 | 157 | |
| 158 | - return [$fond, $contexte, $url_redirect]; |
|
| 158 | + return [$fond, $contexte, $url_redirect]; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -163,20 +163,20 @@ discard block |
||
| 163 | 163 | * le mode 'urls-propres' vers les modes 'urls-standard' et 'url-html' |
| 164 | 164 | */ |
| 165 | 165 | function urls_transition_retrouver_anciennes_url_propres(string $url_propre, string $entite, array $contexte = []): array { |
| 166 | - if ($url_propre) { |
|
| 167 | - if ($GLOBALS['profondeur_url'] <= 0) { |
|
| 168 | - $urls_anciennes = charger_fonction_url('decoder', 'propres'); |
|
| 169 | - } else { |
|
| 170 | - $urls_anciennes = charger_fonction_url('decoder', 'arbo'); |
|
| 171 | - } |
|
| 166 | + if ($url_propre) { |
|
| 167 | + if ($GLOBALS['profondeur_url'] <= 0) { |
|
| 168 | + $urls_anciennes = charger_fonction_url('decoder', 'propres'); |
|
| 169 | + } else { |
|
| 170 | + $urls_anciennes = charger_fonction_url('decoder', 'arbo'); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - if ($urls_anciennes) { |
|
| 174 | - $urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte); |
|
| 175 | - } |
|
| 176 | - return $urls_anciennes ?: []; |
|
| 177 | - } |
|
| 173 | + if ($urls_anciennes) { |
|
| 174 | + $urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte); |
|
| 175 | + } |
|
| 176 | + return $urls_anciennes ?: []; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - return []; |
|
| 179 | + return []; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -184,41 +184,41 @@ discard block |
||
| 184 | 184 | * le mode 'urls-html/standard' vers les modes 'urls propres|arbos' |
| 185 | 185 | */ |
| 186 | 186 | function urls_transition_retrouver_anciennes_url_html(string $url, string $entite, array $contexte = []): array { |
| 187 | - // Migration depuis anciennes URLs ? |
|
| 188 | - // traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23 |
|
| 189 | - if ( |
|
| 190 | - $url |
|
| 191 | - && $GLOBALS['profondeur_url'] <= 0 |
|
| 192 | - ) { |
|
| 193 | - $r = nettoyer_url_page($url, $contexte); |
|
| 194 | - if ($r) { |
|
| 195 | - [$contexte, $type, , , $suite] = $r; |
|
| 196 | - $_id = id_table_objet($type); |
|
| 197 | - $id_objet = $contexte[$_id]; |
|
| 198 | - $url_propre = generer_objet_url($id_objet, $type); |
|
| 199 | - if ( |
|
| 200 | - strlen($url_propre) |
|
| 201 | - && !strstr($url, (string) $url_propre) |
|
| 202 | - && ( |
|
| 203 | - objet_test_si_publie($type, $id_objet) |
|
| 204 | - || defined('_VAR_PREVIEW') && _VAR_PREVIEW && autoriser('voir', $type, $id_objet) |
|
| 205 | - ) |
|
| 206 | - ) { |
|
| 207 | - [, $hash] = array_pad(explode('#', $url_propre), 2, ''); |
|
| 208 | - $args = []; |
|
| 209 | - foreach (array_filter(explode('&', $suite ?? '')) as $fragment) { |
|
| 210 | - if ($fragment != "$_id=$id_objet") { |
|
| 211 | - $args[] = $fragment; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - $url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash); |
|
| 187 | + // Migration depuis anciennes URLs ? |
|
| 188 | + // traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23 |
|
| 189 | + if ( |
|
| 190 | + $url |
|
| 191 | + && $GLOBALS['profondeur_url'] <= 0 |
|
| 192 | + ) { |
|
| 193 | + $r = nettoyer_url_page($url, $contexte); |
|
| 194 | + if ($r) { |
|
| 195 | + [$contexte, $type, , , $suite] = $r; |
|
| 196 | + $_id = id_table_objet($type); |
|
| 197 | + $id_objet = $contexte[$_id]; |
|
| 198 | + $url_propre = generer_objet_url($id_objet, $type); |
|
| 199 | + if ( |
|
| 200 | + strlen($url_propre) |
|
| 201 | + && !strstr($url, (string) $url_propre) |
|
| 202 | + && ( |
|
| 203 | + objet_test_si_publie($type, $id_objet) |
|
| 204 | + || defined('_VAR_PREVIEW') && _VAR_PREVIEW && autoriser('voir', $type, $id_objet) |
|
| 205 | + ) |
|
| 206 | + ) { |
|
| 207 | + [, $hash] = array_pad(explode('#', $url_propre), 2, ''); |
|
| 208 | + $args = []; |
|
| 209 | + foreach (array_filter(explode('&', $suite ?? '')) as $fragment) { |
|
| 210 | + if ($fragment != "$_id=$id_objet") { |
|
| 211 | + $args[] = $fragment; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + $url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash); |
|
| 215 | 215 | |
| 216 | - return [$contexte, $type, $url_redirect, $type]; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - /* Fin compatibilite anciennes urls */ |
|
| 221 | - return []; |
|
| 216 | + return [$contexte, $type, $url_redirect, $type]; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + /* Fin compatibilite anciennes urls */ |
|
| 221 | + return []; |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -231,24 +231,24 @@ discard block |
||
| 231 | 231 | * @return string|array |
| 232 | 232 | */ |
| 233 | 233 | function urls_liste_objets($preg = true) { |
| 234 | - static $url_objets = null; |
|
| 235 | - if (is_null($url_objets)) { |
|
| 236 | - $url_objets = []; |
|
| 237 | - // recuperer les tables_objets_sql declarees |
|
| 238 | - $tables_objets = lister_tables_objets_sql(); |
|
| 239 | - foreach ($tables_objets as $t => $infos) { |
|
| 240 | - if ($infos['page']) { |
|
| 241 | - $url_objets[] = $infos['type']; |
|
| 242 | - $url_objets = array_merge($url_objets, $infos['type_surnoms']); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - $url_objets = pipeline('declarer_url_objets', $url_objets); |
|
| 246 | - } |
|
| 247 | - if (!$preg) { |
|
| 248 | - return $url_objets; |
|
| 249 | - } |
|
| 234 | + static $url_objets = null; |
|
| 235 | + if (is_null($url_objets)) { |
|
| 236 | + $url_objets = []; |
|
| 237 | + // recuperer les tables_objets_sql declarees |
|
| 238 | + $tables_objets = lister_tables_objets_sql(); |
|
| 239 | + foreach ($tables_objets as $t => $infos) { |
|
| 240 | + if ($infos['page']) { |
|
| 241 | + $url_objets[] = $infos['type']; |
|
| 242 | + $url_objets = array_merge($url_objets, $infos['type_surnoms']); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + $url_objets = pipeline('declarer_url_objets', $url_objets); |
|
| 246 | + } |
|
| 247 | + if (!$preg) { |
|
| 248 | + return $url_objets; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - return implode('|', array_map('preg_quote', $url_objets)); |
|
| 251 | + return implode('|', array_map('preg_quote', $url_objets)); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -262,26 +262,26 @@ discard block |
||
| 262 | 262 | * @return array |
| 263 | 263 | */ |
| 264 | 264 | function nettoyer_url_page($url, $contexte = []) { |
| 265 | - $url_objets = urls_liste_objets(); |
|
| 266 | - $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 267 | - $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 268 | - $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,'; |
|
| 265 | + $url_objets = urls_liste_objets(); |
|
| 266 | + $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 267 | + $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 268 | + $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,'; |
|
| 269 | 269 | |
| 270 | - if ( |
|
| 271 | - preg_match($raccourci_url_page_html, $url, $regs) |
|
| 272 | - || preg_match($raccourci_url_page_id, $url, $regs) |
|
| 273 | - || preg_match($raccourci_url_page_spip, $url, $regs) |
|
| 274 | - ) { |
|
| 275 | - $regs = array_pad($regs, 4, null); |
|
| 276 | - $type = objet_type($regs[1]); |
|
| 277 | - $_id = id_table_objet($type); |
|
| 278 | - $contexte[$_id] = $regs[2]; |
|
| 279 | - $suite = $regs[3]; |
|
| 270 | + if ( |
|
| 271 | + preg_match($raccourci_url_page_html, $url, $regs) |
|
| 272 | + || preg_match($raccourci_url_page_id, $url, $regs) |
|
| 273 | + || preg_match($raccourci_url_page_spip, $url, $regs) |
|
| 274 | + ) { |
|
| 275 | + $regs = array_pad($regs, 4, null); |
|
| 276 | + $type = objet_type($regs[1]); |
|
| 277 | + $_id = id_table_objet($type); |
|
| 278 | + $contexte[$_id] = $regs[2]; |
|
| 279 | + $suite = $regs[3]; |
|
| 280 | 280 | |
| 281 | - return [$contexte, $type, null, $type, $suite]; |
|
| 282 | - } |
|
| 281 | + return [$contexte, $type, null, $type, $suite]; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - return []; |
|
| 284 | + return []; |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -299,35 +299,35 @@ discard block |
||
| 299 | 299 | * @return string |
| 300 | 300 | */ |
| 301 | 301 | function generer_objet_url_ecrire($id, string $objet, string $args = '', string $ancre = '', ?bool $public = null, string $connect = ''): string { |
| 302 | - static $furls = []; |
|
| 303 | - $id = intval($id); |
|
| 304 | - if (!isset($furls[$objet])) { |
|
| 305 | - if ( |
|
| 306 | - function_exists($f = 'generer_' . $objet . '_url_ecrire') |
|
| 307 | - || ($f = charger_fonction($f, 'urls', true)) |
|
| 308 | - || function_exists($f = 'generer_url_ecrire_' . $objet) // deprecated |
|
| 309 | - || ($f = charger_fonction($f, 'urls', true)) // deprecated |
|
| 310 | - ) { |
|
| 311 | - $furls[$objet] = $f; |
|
| 312 | - } else { |
|
| 313 | - $furls[$objet] = ''; |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - if ($furls[$objet]) { |
|
| 317 | - return $furls[$objet]($id, $args, $ancre, $public, $connect); |
|
| 318 | - } |
|
| 319 | - // si pas de flag public fourni |
|
| 320 | - // le calculer en fonction de la declaration de statut |
|
| 321 | - if (is_null($public) && !$connect) { |
|
| 322 | - $public = objet_test_si_publie($objet, $id, $connect); |
|
| 323 | - } |
|
| 324 | - if ($public || $connect) { |
|
| 325 | - return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect); |
|
| 326 | - } |
|
| 327 | - $a = id_table_objet($objet) . '=' . intval($id); |
|
| 328 | - if (!function_exists('objet_info')) { |
|
| 329 | - include_spip('inc/filtres'); |
|
| 330 | - } |
|
| 302 | + static $furls = []; |
|
| 303 | + $id = intval($id); |
|
| 304 | + if (!isset($furls[$objet])) { |
|
| 305 | + if ( |
|
| 306 | + function_exists($f = 'generer_' . $objet . '_url_ecrire') |
|
| 307 | + || ($f = charger_fonction($f, 'urls', true)) |
|
| 308 | + || function_exists($f = 'generer_url_ecrire_' . $objet) // deprecated |
|
| 309 | + || ($f = charger_fonction($f, 'urls', true)) // deprecated |
|
| 310 | + ) { |
|
| 311 | + $furls[$objet] = $f; |
|
| 312 | + } else { |
|
| 313 | + $furls[$objet] = ''; |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + if ($furls[$objet]) { |
|
| 317 | + return $furls[$objet]($id, $args, $ancre, $public, $connect); |
|
| 318 | + } |
|
| 319 | + // si pas de flag public fourni |
|
| 320 | + // le calculer en fonction de la declaration de statut |
|
| 321 | + if (is_null($public) && !$connect) { |
|
| 322 | + $public = objet_test_si_publie($objet, $id, $connect); |
|
| 323 | + } |
|
| 324 | + if ($public || $connect) { |
|
| 325 | + return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect); |
|
| 326 | + } |
|
| 327 | + $a = id_table_objet($objet) . '=' . intval($id); |
|
| 328 | + if (!function_exists('objet_info')) { |
|
| 329 | + include_spip('inc/filtres'); |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : ''); |
|
| 332 | + return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : ''); |
|
| 333 | 333 | } |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | // celle du texte) et public (spip_lang est la langue du texte) |
| 50 | 50 | $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
| 51 | 51 | |
| 52 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 52 | + $p = 'puce'.(test_espace_prive() ? '_prive' : ''); |
|
| 53 | 53 | if ($dir == 'rtl') { |
| 54 | 54 | $p .= '_rtl'; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | if (!isset($GLOBALS[$p])) { |
| 58 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 58 | + $GLOBALS[$p] = '<span class="spip-puce '.$dir.'"><b>–</b></span>'; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | return $GLOBALS[$p]; |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = ''): string { |
| 68 | 68 | |
| 69 | 69 | $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
| 70 | - $class = 'spip_code ' . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 70 | + $class = 'spip_code '.($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 71 | 71 | if ($attributs) { |
| 72 | - $attributs = ' ' . trim($attributs); |
|
| 72 | + $attributs = ' '.trim($attributs); |
|
| 73 | 73 | } |
| 74 | 74 | if ($langage) { |
| 75 | 75 | $class .= " language-$langage"; |
| 76 | - $attributs .= ' data-language="' . $langage . '"'; |
|
| 76 | + $attributs .= ' data-language="'.$langage.'"'; |
|
| 77 | 77 | } |
| 78 | 78 | if ($bloc) { |
| 79 | 79 | $html = '<div class="precode">' |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | } else { |
| 87 | 87 | $echap = str_replace("\t", ' ', $echap); |
| 88 | 88 | $echap = str_replace(' ', ' ', $echap); |
| 89 | - $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 89 | + $html = "<code class=\"$class\" dir=\"ltr\"$attributs>".$echap.'</code>'; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | return $html; |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | // XHTML - Preserver les balises-bloc : on liste ici tous les elements |
| 97 | 97 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 98 | 98 | defined('_BALISES_BLOCS') || define('_BALISES_BLOCS', implode('|', CollecteurHtmlTag::$listeBalisesBloc)); |
| 99 | -defined('_BALISES_BLOCS_REGEXP') || define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 99 | +defined('_BALISES_BLOCS_REGEXP') || define('_BALISES_BLOCS_REGEXP', ',</?('._BALISES_BLOCS.')[>[:space:]],iS'); |
|
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * Echapper les elements perilleux en les passant en base64 |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | return ''; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - return CollecteurHtmlTag::echappementHtmlBase64((string)$rempl, (string)$source, in_array($mode, ['div', 'span']) ? $mode === 'div' : null); |
|
| 119 | + return CollecteurHtmlTag::echappementHtmlBase64((string) $rempl, (string) $source, in_array($mode, ['div', 'span']) ? $mode === 'div' : null); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $collections = $collecteurCode->collecter($pre); |
| 137 | 137 | $collections = array_reverse($collections); |
| 138 | 138 | foreach ($collections as $c) { |
| 139 | - $code = $c['opening'] . spip_htmlspecialchars($c['innerHtml']) . $c['closing']; |
|
| 139 | + $code = $c['opening'].spip_htmlspecialchars($c['innerHtml']).$c['closing']; |
|
| 140 | 140 | $pre = substr_replace($pre, $code, $c['pos'], $c['length']); |
| 141 | 141 | } |
| 142 | 142 | } |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | return $regs['raw']; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | -defined('_PROTEGE_BLOCS') || define('_PROTEGE_BLOCS', ',<(' . implode('|', CollecteurHtmlTag::$listeBalisesAProteger) . ')(\b[^>]*)?>(.*)</\1>,UimsS'); |
|
| 194 | +defined('_PROTEGE_BLOCS') || define('_PROTEGE_BLOCS', ',<('.implode('|', CollecteurHtmlTag::$listeBalisesAProteger).')(\b[^>]*)?>(.*)</\1>,UimsS'); |
|
| 195 | 195 | |
| 196 | 196 | /** |
| 197 | 197 | * pour $source voir commentaire infra (echappe_retour) |
@@ -242,11 +242,11 @@ discard block |
||
| 242 | 242 | $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
| 243 | 243 | foreach ($html_tags ?: CollecteurHtmlTag::$listeBalisesAProteger as $tag) { |
| 244 | 244 | if ( |
| 245 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . $tag) |
|
| 246 | - || function_exists($f = $f . '_dist') |
|
| 245 | + function_exists($f = $callback_prefix.$callback_secure_prefix.'traiter_echap_'.$tag) |
|
| 246 | + || function_exists($f = $f.'_dist') |
|
| 247 | 247 | || $callback_secure_prefix && ( |
| 248 | - function_exists($f = $callback_prefix . 'traiter_echap_' . $tag) |
|
| 249 | - || function_exists($f = $f . '_dist') |
|
| 248 | + function_exists($f = $callback_prefix.'traiter_echap_'.$tag) |
|
| 249 | + || function_exists($f = $f.'_dist') |
|
| 250 | 250 | ) |
| 251 | 251 | ) { |
| 252 | 252 | $callbacks[$tag] = $f; |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | if (!is_string($letexte) || !strlen($letexte)) { |
| 287 | 287 | return $letexte; |
| 288 | 288 | } |
| 289 | - return CollecteurHtmlTag::retablir_depuisHtmlBase64((string)$letexte, (string)$source, (string)$filtre); |
|
| 289 | + return CollecteurHtmlTag::retablir_depuisHtmlBase64((string) $letexte, (string) $source, (string) $filtre); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | // Reinserer le javascript de confiance (venant des modeles) |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | if (!is_string($letexte) || !strlen($letexte)) { |
| 296 | 296 | return $letexte; |
| 297 | 297 | } |
| 298 | - $letexte = CollecteurHtmlTag::retablir_depuisHtmlBase64((string)$letexte); |
|
| 298 | + $letexte = CollecteurHtmlTag::retablir_depuisHtmlBase64((string) $letexte); |
|
| 299 | 299 | |
| 300 | 300 | // Dans les appels directs hors squelette, securiser aussi ici |
| 301 | 301 | // c'est interdire_scripts() qui rétablit les scripts des modeles echappés avec _PROTEGE_JS_MODELES et _PROTEGE_PHP_MODELES |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | $texte = nettoyer_raccourcis_typo($texte); |
| 365 | 365 | |
| 366 | 366 | // balises de sauts de ligne et paragraphe |
| 367 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 368 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 367 | + $texte = preg_replace('/<p( [^>]*)?'.'>/', "\r\r", $texte); |
|
| 368 | + $texte = preg_replace('/<br( [^>]*)?'.'>/', "\n", $texte); |
|
| 369 | 369 | |
| 370 | 370 | // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
| 371 | 371 | $texte = str_replace("\n\n", "\r\r", $texte); |
@@ -390,15 +390,15 @@ discard block |
||
| 390 | 390 | // excédentaire est ensuite supprimé par l'appel à preg_replace() |
| 391 | 391 | $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
| 392 | 392 | $u = $GLOBALS['meta']['pcre_u']; |
| 393 | - $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 393 | + $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D'.$u, "\\2", $long); |
|
| 394 | 394 | $points = $suite; |
| 395 | 395 | |
| 396 | 396 | // trop court ? ne pas faire de (...) |
| 397 | 397 | if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
| 398 | 398 | $points = ''; |
| 399 | 399 | $long = spip_substr($texte, 0, $taille + 1); |
| 400 | - preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 401 | - $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 400 | + preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D'.$u, $long, $m); |
|
| 401 | + $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D'.$u, "\\2", $long); |
|
| 402 | 402 | // encore trop court ? couper au caractere |
| 403 | 403 | if (spip_strlen($texte) < 0.75 * $taille) { |
| 404 | 404 | $texte = spip_substr($long, 0, $taille); |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | // supprimer l'eventuelle entite finale mal coupee |
| 415 | 415 | $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
| 416 | 416 | |
| 417 | - return quote_amp(trim($texte)) . $points; |
|
| 417 | + return quote_amp(trim($texte)).$points; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | |
@@ -422,16 +422,16 @@ discard block |
||
| 422 | 422 | if (isset($GLOBALS['visiteur_session']) && str_contains($texte, '<')) { |
| 423 | 423 | $tags = [ |
| 424 | 424 | 'javascript' => ['tag' => 'script', 'preg' => ',<script.*?($|</script.),isS', 'c' => '_PROTEGE_JS_MODELES'], |
| 425 | - 'php' => ['tag' => '?php', 'preg' => ',<\?php.*?($|\?' . '>),isS', 'c' => '_PROTEGE_PHP_MODELES'], |
|
| 425 | + 'php' => ['tag' => '?php', 'preg' => ',<\?php.*?($|\?'.'>),isS', 'c' => '_PROTEGE_PHP_MODELES'], |
|
| 426 | 426 | ]; |
| 427 | 427 | foreach ($tags as $k => $t) { |
| 428 | - if (stripos($texte, '<' . $t['tag']) !== false) { |
|
| 428 | + if (stripos($texte, '<'.$t['tag']) !== false) { |
|
| 429 | 429 | if (!defined($t['c'])) { |
| 430 | 430 | include_spip('inc/acces'); |
| 431 | 431 | define($t['c'], creer_uniqid()); |
| 432 | 432 | } |
| 433 | 433 | $collecteurHtmlTag = new CollecteurHtmlTag($t['tag'], $t['preg'], ''); |
| 434 | - $texte = $collecteurHtmlTag->echapper_enHtmlBase64($texte, $k . constant($t['c'])); |
|
| 434 | + $texte = $collecteurHtmlTag->echapper_enHtmlBase64($texte, $k.constant($t['c'])); |
|
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | 437 | } |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | if (!empty($options['wrap_suspect'])) { |
| 545 | 545 | $texte = wrap($texte, $options['wrap_suspect']); |
| 546 | 546 | } |
| 547 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 547 | + $texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | $texte = $collecteurModeles->retablir($texte); |
@@ -687,11 +687,11 @@ discard block |
||
| 687 | 687 | **/ |
| 688 | 688 | function supprime_img($letexte, $message = null) { |
| 689 | 689 | if ($message === null) { |
| 690 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 690 | + $message = '('._T('img_indisponible').')'; |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | return preg_replace( |
| 694 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 694 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i', |
|
| 695 | 695 | $message, |
| 696 | 696 | $letexte |
| 697 | 697 | ); |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | **/ |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | include_spip('inc/filtres'); |
| 28 | 28 | include_spip('inc/lang'); |
@@ -44,21 +44,21 @@ discard block |
||
| 44 | 44 | **/ |
| 45 | 45 | function definir_puce() { |
| 46 | 46 | |
| 47 | - // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 48 | - // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 49 | - // celle du texte) et public (spip_lang est la langue du texte) |
|
| 50 | - $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 47 | + // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 48 | + // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 49 | + // celle du texte) et public (spip_lang est la langue du texte) |
|
| 50 | + $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 51 | 51 | |
| 52 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 53 | - if ($dir == 'rtl') { |
|
| 54 | - $p .= '_rtl'; |
|
| 55 | - } |
|
| 52 | + $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 53 | + if ($dir == 'rtl') { |
|
| 54 | + $p .= '_rtl'; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - if (!isset($GLOBALS[$p])) { |
|
| 58 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 59 | - } |
|
| 57 | + if (!isset($GLOBALS[$p])) { |
|
| 58 | + $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - return $GLOBALS[$p]; |
|
| 61 | + return $GLOBALS[$p]; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -66,30 +66,30 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = ''): string { |
| 68 | 68 | |
| 69 | - $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 70 | - $class = 'spip_code ' . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 71 | - if ($attributs) { |
|
| 72 | - $attributs = ' ' . trim($attributs); |
|
| 73 | - } |
|
| 74 | - if ($langage) { |
|
| 75 | - $class .= " language-$langage"; |
|
| 76 | - $attributs .= ' data-language="' . $langage . '"'; |
|
| 77 | - } |
|
| 78 | - if ($bloc) { |
|
| 79 | - $html = '<div class="precode">' |
|
| 80 | - . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>" |
|
| 81 | - . '<code>' |
|
| 82 | - . $echap |
|
| 83 | - . '</code>' |
|
| 84 | - . '</pre>' |
|
| 85 | - . '</div>'; |
|
| 86 | - } else { |
|
| 87 | - $echap = str_replace("\t", ' ', $echap); |
|
| 88 | - $echap = str_replace(' ', ' ', $echap); |
|
| 89 | - $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - return $html; |
|
| 69 | + $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 70 | + $class = 'spip_code ' . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 71 | + if ($attributs) { |
|
| 72 | + $attributs = ' ' . trim($attributs); |
|
| 73 | + } |
|
| 74 | + if ($langage) { |
|
| 75 | + $class .= " language-$langage"; |
|
| 76 | + $attributs .= ' data-language="' . $langage . '"'; |
|
| 77 | + } |
|
| 78 | + if ($bloc) { |
|
| 79 | + $html = '<div class="precode">' |
|
| 80 | + . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>" |
|
| 81 | + . '<code>' |
|
| 82 | + . $echap |
|
| 83 | + . '</code>' |
|
| 84 | + . '</pre>' |
|
| 85 | + . '</div>'; |
|
| 86 | + } else { |
|
| 87 | + $echap = str_replace("\t", ' ', $echap); |
|
| 88 | + $echap = str_replace(' ', ' ', $echap); |
|
| 89 | + $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + return $html; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
@@ -112,83 +112,83 @@ discard block |
||
| 112 | 112 | * @return string |
| 113 | 113 | */ |
| 114 | 114 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 115 | - if (!is_string($rempl) || !strlen($rempl)) { |
|
| 116 | - return ''; |
|
| 117 | - } |
|
| 115 | + if (!is_string($rempl) || !strlen($rempl)) { |
|
| 116 | + return ''; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return CollecteurHtmlTag::echappementHtmlBase64((string)$rempl, (string)$source, in_array($mode, ['div', 'span']) ? $mode === 'div' : null); |
|
| 119 | + return CollecteurHtmlTag::echappementHtmlBase64((string)$rempl, (string)$source, in_array($mode, ['div', 'span']) ? $mode === 'div' : null); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | |
| 123 | 123 | // Echapper les <html>...</ html> |
| 124 | 124 | function traiter_echap_html_dist($regs, $options = []) { |
| 125 | - return $regs['innerHtml']; |
|
| 125 | + return $regs['innerHtml']; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Echapper les <pre>...</ pre> |
| 129 | 129 | function traiter_echap_pre_dist($regs, $options = []) { |
| 130 | - // echapper les <code> dans <pre> |
|
| 131 | - $pre = $regs['innerHtml']; |
|
| 132 | - |
|
| 133 | - // echapper les < dans <code> |
|
| 134 | - if (str_contains($pre, '<')) { |
|
| 135 | - $collecteurCode = new CollecteurHtmlTag('code'); |
|
| 136 | - $collections = $collecteurCode->collecter($pre); |
|
| 137 | - $collections = array_reverse($collections); |
|
| 138 | - foreach ($collections as $c) { |
|
| 139 | - $code = $c['opening'] . spip_htmlspecialchars($c['innerHtml']) . $c['closing']; |
|
| 140 | - $pre = substr_replace($pre, $code, $c['pos'], $c['length']); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - return "<pre>$pre</pre>"; |
|
| 130 | + // echapper les <code> dans <pre> |
|
| 131 | + $pre = $regs['innerHtml']; |
|
| 132 | + |
|
| 133 | + // echapper les < dans <code> |
|
| 134 | + if (str_contains($pre, '<')) { |
|
| 135 | + $collecteurCode = new CollecteurHtmlTag('code'); |
|
| 136 | + $collections = $collecteurCode->collecter($pre); |
|
| 137 | + $collections = array_reverse($collections); |
|
| 138 | + foreach ($collections as $c) { |
|
| 139 | + $code = $c['opening'] . spip_htmlspecialchars($c['innerHtml']) . $c['closing']; |
|
| 140 | + $pre = substr_replace($pre, $code, $c['pos'], $c['length']); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + return "<pre>$pre</pre>"; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | // Echapper les <code>...</ code> |
| 147 | 147 | function traiter_echap_code_dist($regs, $options = []) { |
| 148 | - $corps = $regs['innerHtml']; |
|
| 149 | - $att = $regs['attributs']; |
|
| 148 | + $corps = $regs['innerHtml']; |
|
| 149 | + $att = $regs['attributs']; |
|
| 150 | 150 | |
| 151 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 152 | - if (str_contains($corps, "\n")) { |
|
| 153 | - // supprimer les sauts de ligne debut/fin |
|
| 154 | - // (mais pas les espaces => ascii art). |
|
| 155 | - $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps); |
|
| 151 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 152 | + if (str_contains($corps, "\n")) { |
|
| 153 | + // supprimer les sauts de ligne debut/fin |
|
| 154 | + // (mais pas les espaces => ascii art). |
|
| 155 | + $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps); |
|
| 156 | 156 | |
| 157 | - $echap = spip_balisage_code($corps, true, $att); |
|
| 158 | - } else { |
|
| 159 | - $echap = spip_balisage_code($corps, false, $att); |
|
| 160 | - } |
|
| 157 | + $echap = spip_balisage_code($corps, true, $att); |
|
| 158 | + } else { |
|
| 159 | + $echap = spip_balisage_code($corps, false, $att); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return $echap; |
|
| 162 | + return $echap; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 166 | 166 | function traiter_echap_cadre_dist($regs, $options = []) { |
| 167 | - $echap = trim(entites_html($regs['innerHtml'])); |
|
| 168 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 169 | - $lignes = explode("\n", trim($echap)); |
|
| 170 | - $n = 0; |
|
| 171 | - foreach ($lignes as $l) { |
|
| 172 | - $n += floor(strlen($l) / 60) + 1; |
|
| 173 | - } |
|
| 174 | - $n = max($n, 2); |
|
| 175 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>"; |
|
| 176 | - |
|
| 177 | - return $echap; |
|
| 167 | + $echap = trim(entites_html($regs['innerHtml'])); |
|
| 168 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 169 | + $lignes = explode("\n", trim($echap)); |
|
| 170 | + $n = 0; |
|
| 171 | + foreach ($lignes as $l) { |
|
| 172 | + $n += floor(strlen($l) / 60) + 1; |
|
| 173 | + } |
|
| 174 | + $n = max($n, 2); |
|
| 175 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>"; |
|
| 176 | + |
|
| 177 | + return $echap; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | function traiter_echap_frame_dist($regs, $options = []) { |
| 181 | - return traiter_echap_cadre_dist($regs); |
|
| 181 | + return traiter_echap_cadre_dist($regs); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function traiter_echap_script_dist($regs, $options = []) { |
| 185 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 186 | - if (strpos($regs['opening'], 'php')) { |
|
| 187 | - return highlight_string($regs['raw'], true); |
|
| 188 | - } |
|
| 185 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 186 | + if (strpos($regs['opening'], 'php')) { |
|
| 187 | + return highlight_string($regs['raw'], true); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - // Cas normal : le script passe tel quel |
|
| 191 | - return $regs['raw']; |
|
| 190 | + // Cas normal : le script passe tel quel |
|
| 191 | + return $regs['raw']; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | defined('_PROTEGE_BLOCS') || define('_PROTEGE_BLOCS', ',<(' . implode('|', CollecteurHtmlTag::$listeBalisesAProteger) . ')(\b[^>]*)?>(.*)</\1>,UimsS'); |
@@ -207,69 +207,69 @@ discard block |
||
| 207 | 207 | * @return string|string[] |
| 208 | 208 | */ |
| 209 | 209 | function echappe_html( |
| 210 | - $letexte, |
|
| 211 | - $source = '', |
|
| 212 | - $no_transform = false, |
|
| 213 | - $html_tags = null, |
|
| 214 | - $callback_prefix = '', |
|
| 215 | - $callback_options = [] |
|
| 210 | + $letexte, |
|
| 211 | + $source = '', |
|
| 212 | + $no_transform = false, |
|
| 213 | + $html_tags = null, |
|
| 214 | + $callback_prefix = '', |
|
| 215 | + $callback_options = [] |
|
| 216 | 216 | ) { |
| 217 | - if (!is_string($letexte) || !strlen($letexte)) { |
|
| 218 | - return $letexte; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - if ($no_transform !== false) { |
|
| 222 | - trigger_deprecation('spip', '5.0', 'Using "%s" arg is deprecated, use directly "%s" instead.', '$no_transform', 'Spip\Texte\Collecteur\HtmlTag::proteger_balisesHtml', __FUNCTION__); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - // appels legacy avec un '' |
|
| 226 | - if (empty($html_tags)) { |
|
| 227 | - $html_tags = null; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - // legacy : les appels fournissaient une preg pour repérer les balises HTML |
|
| 231 | - if ($html_tags && !is_array($html_tags)) { |
|
| 232 | - trigger_deprecation('spip', '5.0', 'Using a preg for "%s" arg is deprecated, use a tag array instead.', '$html_tags', __FUNCTION__); |
|
| 233 | - $t = explode(')', $html_tags, 2); |
|
| 234 | - $t = reset($t); |
|
| 235 | - $t = explode('(', $t, 2); |
|
| 236 | - $t = end($t); |
|
| 237 | - $html_tags = explode('|', $t); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - $callbacks = []; |
|
| 241 | - if (!$no_transform) { |
|
| 242 | - $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 243 | - foreach ($html_tags ?: CollecteurHtmlTag::$listeBalisesAProteger as $tag) { |
|
| 244 | - if ( |
|
| 245 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . $tag) |
|
| 246 | - || function_exists($f = $f . '_dist') |
|
| 247 | - || $callback_secure_prefix && ( |
|
| 248 | - function_exists($f = $callback_prefix . 'traiter_echap_' . $tag) |
|
| 249 | - || function_exists($f = $f . '_dist') |
|
| 250 | - ) |
|
| 251 | - ) { |
|
| 252 | - $callbacks[$tag] = $f; |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - $letexte = CollecteurHtmlTag::proteger_balisesHtml($letexte, $source, $html_tags, $callbacks, $callback_options); |
|
| 258 | - |
|
| 259 | - if ($no_transform) { |
|
| 260 | - return $letexte; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 264 | - // seulement si on a echappe les <script> |
|
| 265 | - // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 266 | - // dans une callback autonommee + la preg pour collecter est un peu spécifique |
|
| 267 | - if (in_array('script', $html_tags ?: CollecteurHtmlTag::$listeBalisesAProteger)) { |
|
| 268 | - $htmlTagCollecteur = new CollecteurHtmlTag('?', '@<[?].*($|[?]>)@UsS', ''); |
|
| 269 | - $letexte = $htmlTagCollecteur->echapper_enHtmlBase64($letexte, $source, fn ($c, $o) => highlight_string($c['raw'], true)); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - return $letexte; |
|
| 217 | + if (!is_string($letexte) || !strlen($letexte)) { |
|
| 218 | + return $letexte; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + if ($no_transform !== false) { |
|
| 222 | + trigger_deprecation('spip', '5.0', 'Using "%s" arg is deprecated, use directly "%s" instead.', '$no_transform', 'Spip\Texte\Collecteur\HtmlTag::proteger_balisesHtml', __FUNCTION__); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + // appels legacy avec un '' |
|
| 226 | + if (empty($html_tags)) { |
|
| 227 | + $html_tags = null; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + // legacy : les appels fournissaient une preg pour repérer les balises HTML |
|
| 231 | + if ($html_tags && !is_array($html_tags)) { |
|
| 232 | + trigger_deprecation('spip', '5.0', 'Using a preg for "%s" arg is deprecated, use a tag array instead.', '$html_tags', __FUNCTION__); |
|
| 233 | + $t = explode(')', $html_tags, 2); |
|
| 234 | + $t = reset($t); |
|
| 235 | + $t = explode('(', $t, 2); |
|
| 236 | + $t = end($t); |
|
| 237 | + $html_tags = explode('|', $t); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + $callbacks = []; |
|
| 241 | + if (!$no_transform) { |
|
| 242 | + $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 243 | + foreach ($html_tags ?: CollecteurHtmlTag::$listeBalisesAProteger as $tag) { |
|
| 244 | + if ( |
|
| 245 | + function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . $tag) |
|
| 246 | + || function_exists($f = $f . '_dist') |
|
| 247 | + || $callback_secure_prefix && ( |
|
| 248 | + function_exists($f = $callback_prefix . 'traiter_echap_' . $tag) |
|
| 249 | + || function_exists($f = $f . '_dist') |
|
| 250 | + ) |
|
| 251 | + ) { |
|
| 252 | + $callbacks[$tag] = $f; |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + $letexte = CollecteurHtmlTag::proteger_balisesHtml($letexte, $source, $html_tags, $callbacks, $callback_options); |
|
| 258 | + |
|
| 259 | + if ($no_transform) { |
|
| 260 | + return $letexte; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 264 | + // seulement si on a echappe les <script> |
|
| 265 | + // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 266 | + // dans une callback autonommee + la preg pour collecter est un peu spécifique |
|
| 267 | + if (in_array('script', $html_tags ?: CollecteurHtmlTag::$listeBalisesAProteger)) { |
|
| 268 | + $htmlTagCollecteur = new CollecteurHtmlTag('?', '@<[?].*($|[?]>)@UsS', ''); |
|
| 269 | + $letexte = $htmlTagCollecteur->echapper_enHtmlBase64($letexte, $source, fn ($c, $o) => highlight_string($c['raw'], true)); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + return $letexte; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -283,27 +283,27 @@ discard block |
||
| 283 | 283 | * @return array|mixed|string|string[] |
| 284 | 284 | */ |
| 285 | 285 | function echappe_retour($letexte, $source = '', $filtre = '') { |
| 286 | - if (!is_string($letexte) || !strlen($letexte)) { |
|
| 287 | - return $letexte; |
|
| 288 | - } |
|
| 289 | - return CollecteurHtmlTag::retablir_depuisHtmlBase64((string)$letexte, (string)$source, (string)$filtre); |
|
| 286 | + if (!is_string($letexte) || !strlen($letexte)) { |
|
| 287 | + return $letexte; |
|
| 288 | + } |
|
| 289 | + return CollecteurHtmlTag::retablir_depuisHtmlBase64((string)$letexte, (string)$source, (string)$filtre); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | // Reinserer le javascript de confiance (venant des modeles) |
| 293 | 293 | |
| 294 | 294 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 295 | - if (!is_string($letexte) || !strlen($letexte)) { |
|
| 296 | - return $letexte; |
|
| 297 | - } |
|
| 298 | - $letexte = CollecteurHtmlTag::retablir_depuisHtmlBase64((string)$letexte); |
|
| 299 | - |
|
| 300 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 301 | - // c'est interdire_scripts() qui rétablit les scripts des modeles echappés avec _PROTEGE_JS_MODELES et _PROTEGE_PHP_MODELES |
|
| 302 | - if ($interdire_scripts) { |
|
| 303 | - $letexte = interdire_scripts($letexte); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - return trim($letexte); |
|
| 295 | + if (!is_string($letexte) || !strlen($letexte)) { |
|
| 296 | + return $letexte; |
|
| 297 | + } |
|
| 298 | + $letexte = CollecteurHtmlTag::retablir_depuisHtmlBase64((string)$letexte); |
|
| 299 | + |
|
| 300 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 301 | + // c'est interdire_scripts() qui rétablit les scripts des modeles echappés avec _PROTEGE_JS_MODELES et _PROTEGE_PHP_MODELES |
|
| 302 | + if ($interdire_scripts) { |
|
| 303 | + $letexte = interdire_scripts($letexte); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + return trim($letexte); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | |
@@ -331,129 +331,129 @@ discard block |
||
| 331 | 331 | * texte coupé |
| 332 | 332 | **/ |
| 333 | 333 | function couper($texte, $taille = 50, $suite = null) { |
| 334 | - if ($taille <= 0) { |
|
| 335 | - return ''; |
|
| 336 | - } |
|
| 337 | - $length = spip_strlen($texte); |
|
| 338 | - if (!$length) { |
|
| 339 | - return ''; |
|
| 340 | - } |
|
| 341 | - $offset = 400 + 2 * $taille; |
|
| 342 | - while ( |
|
| 343 | - $offset < $length |
|
| 344 | - && spip_strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', spip_substr($texte, 0, $offset))) < $taille |
|
| 345 | - ) { |
|
| 346 | - $offset *= 2; |
|
| 347 | - } |
|
| 348 | - if ( |
|
| 349 | - $offset < $length |
|
| 350 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 351 | - ) { |
|
| 352 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 353 | - // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 354 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 355 | - $offset = $p_tag_fermant + 1; |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - // éviter de travailler sur 10ko pour extraire 150 caractères |
|
| 359 | - $texte = spip_substr($texte, 0, $offset); |
|
| 360 | - |
|
| 361 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 362 | - include_spip('inc/lien'); |
|
| 363 | - } |
|
| 364 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 365 | - |
|
| 366 | - // balises de sauts de ligne et paragraphe |
|
| 367 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 368 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 369 | - |
|
| 370 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 371 | - $texte = str_replace("\n\n", "\r\r", $texte); |
|
| 372 | - |
|
| 373 | - // supprimer les tags |
|
| 374 | - $texte = supprimer_tags($texte); |
|
| 375 | - $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 376 | - |
|
| 377 | - // tester s'il est nécessaire de couper le texte |
|
| 378 | - if (spip_strlen($texte) <= $taille) { |
|
| 379 | - $points = ''; |
|
| 380 | - } else { |
|
| 381 | - // points de suite |
|
| 382 | - if (is_null($suite)) { |
|
| 383 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 384 | - } |
|
| 385 | - $taille_suite = spip_strlen(filtrer_entites($suite)); |
|
| 386 | - |
|
| 387 | - // couper au mot precedent (ou au début de la chaîne si c'est le premier mot) |
|
| 388 | - // on coupe avec un caractère de plus que la taille demandée afin de pouvoir |
|
| 389 | - // détecter si le dernier mot du texte coupé est complet ou non. ce caractère |
|
| 390 | - // excédentaire est ensuite supprimé par l'appel à preg_replace() |
|
| 391 | - $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
|
| 392 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 393 | - $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 394 | - $points = $suite; |
|
| 395 | - |
|
| 396 | - // trop court ? ne pas faire de (...) |
|
| 397 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 398 | - $points = ''; |
|
| 399 | - $long = spip_substr($texte, 0, $taille + 1); |
|
| 400 | - preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 401 | - $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 402 | - // encore trop court ? couper au caractere |
|
| 403 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 404 | - $texte = spip_substr($long, 0, $taille); |
|
| 405 | - } |
|
| 406 | - } else { |
|
| 407 | - $texte = $court; |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - // remettre les paragraphes |
|
| 412 | - $texte = preg_replace("/\r\r+/", "\n\n", $texte); |
|
| 413 | - |
|
| 414 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 415 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 416 | - |
|
| 417 | - return quote_amp(trim($texte)) . $points; |
|
| 334 | + if ($taille <= 0) { |
|
| 335 | + return ''; |
|
| 336 | + } |
|
| 337 | + $length = spip_strlen($texte); |
|
| 338 | + if (!$length) { |
|
| 339 | + return ''; |
|
| 340 | + } |
|
| 341 | + $offset = 400 + 2 * $taille; |
|
| 342 | + while ( |
|
| 343 | + $offset < $length |
|
| 344 | + && spip_strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', spip_substr($texte, 0, $offset))) < $taille |
|
| 345 | + ) { |
|
| 346 | + $offset *= 2; |
|
| 347 | + } |
|
| 348 | + if ( |
|
| 349 | + $offset < $length |
|
| 350 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 351 | + ) { |
|
| 352 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 353 | + // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 354 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 355 | + $offset = $p_tag_fermant + 1; |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + // éviter de travailler sur 10ko pour extraire 150 caractères |
|
| 359 | + $texte = spip_substr($texte, 0, $offset); |
|
| 360 | + |
|
| 361 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 362 | + include_spip('inc/lien'); |
|
| 363 | + } |
|
| 364 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 365 | + |
|
| 366 | + // balises de sauts de ligne et paragraphe |
|
| 367 | + $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 368 | + $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 369 | + |
|
| 370 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 371 | + $texte = str_replace("\n\n", "\r\r", $texte); |
|
| 372 | + |
|
| 373 | + // supprimer les tags |
|
| 374 | + $texte = supprimer_tags($texte); |
|
| 375 | + $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 376 | + |
|
| 377 | + // tester s'il est nécessaire de couper le texte |
|
| 378 | + if (spip_strlen($texte) <= $taille) { |
|
| 379 | + $points = ''; |
|
| 380 | + } else { |
|
| 381 | + // points de suite |
|
| 382 | + if (is_null($suite)) { |
|
| 383 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 384 | + } |
|
| 385 | + $taille_suite = spip_strlen(filtrer_entites($suite)); |
|
| 386 | + |
|
| 387 | + // couper au mot precedent (ou au début de la chaîne si c'est le premier mot) |
|
| 388 | + // on coupe avec un caractère de plus que la taille demandée afin de pouvoir |
|
| 389 | + // détecter si le dernier mot du texte coupé est complet ou non. ce caractère |
|
| 390 | + // excédentaire est ensuite supprimé par l'appel à preg_replace() |
|
| 391 | + $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
|
| 392 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 393 | + $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 394 | + $points = $suite; |
|
| 395 | + |
|
| 396 | + // trop court ? ne pas faire de (...) |
|
| 397 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 398 | + $points = ''; |
|
| 399 | + $long = spip_substr($texte, 0, $taille + 1); |
|
| 400 | + preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 401 | + $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 402 | + // encore trop court ? couper au caractere |
|
| 403 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 404 | + $texte = spip_substr($long, 0, $taille); |
|
| 405 | + } |
|
| 406 | + } else { |
|
| 407 | + $texte = $court; |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + // remettre les paragraphes |
|
| 412 | + $texte = preg_replace("/\r\r+/", "\n\n", $texte); |
|
| 413 | + |
|
| 414 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 415 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 416 | + |
|
| 417 | + return quote_amp(trim($texte)) . $points; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | |
| 421 | 421 | function protege_js_modeles($texte) { |
| 422 | - if (isset($GLOBALS['visiteur_session']) && str_contains($texte, '<')) { |
|
| 423 | - $tags = [ |
|
| 424 | - 'javascript' => ['tag' => 'script', 'preg' => ',<script.*?($|</script.),isS', 'c' => '_PROTEGE_JS_MODELES'], |
|
| 425 | - 'php' => ['tag' => '?php', 'preg' => ',<\?php.*?($|\?' . '>),isS', 'c' => '_PROTEGE_PHP_MODELES'], |
|
| 426 | - ]; |
|
| 427 | - foreach ($tags as $k => $t) { |
|
| 428 | - if (stripos($texte, '<' . $t['tag']) !== false) { |
|
| 429 | - if (!defined($t['c'])) { |
|
| 430 | - include_spip('inc/acces'); |
|
| 431 | - define($t['c'], creer_uniqid()); |
|
| 432 | - } |
|
| 433 | - $collecteurHtmlTag = new CollecteurHtmlTag($t['tag'], $t['preg'], ''); |
|
| 434 | - $texte = $collecteurHtmlTag->echapper_enHtmlBase64($texte, $k . constant($t['c'])); |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - return $texte; |
|
| 422 | + if (isset($GLOBALS['visiteur_session']) && str_contains($texte, '<')) { |
|
| 423 | + $tags = [ |
|
| 424 | + 'javascript' => ['tag' => 'script', 'preg' => ',<script.*?($|</script.),isS', 'c' => '_PROTEGE_JS_MODELES'], |
|
| 425 | + 'php' => ['tag' => '?php', 'preg' => ',<\?php.*?($|\?' . '>),isS', 'c' => '_PROTEGE_PHP_MODELES'], |
|
| 426 | + ]; |
|
| 427 | + foreach ($tags as $k => $t) { |
|
| 428 | + if (stripos($texte, '<' . $t['tag']) !== false) { |
|
| 429 | + if (!defined($t['c'])) { |
|
| 430 | + include_spip('inc/acces'); |
|
| 431 | + define($t['c'], creer_uniqid()); |
|
| 432 | + } |
|
| 433 | + $collecteurHtmlTag = new CollecteurHtmlTag($t['tag'], $t['preg'], ''); |
|
| 434 | + $texte = $collecteurHtmlTag->echapper_enHtmlBase64($texte, $k . constant($t['c'])); |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + return $texte; |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | |
| 442 | 442 | function echapper_faux_tags($letexte) { |
| 443 | - if (!str_contains($letexte, '<')) { |
|
| 444 | - return $letexte; |
|
| 445 | - } |
|
| 446 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 447 | - |
|
| 448 | - $letexte = ''; |
|
| 449 | - while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 450 | - // un texte a echapper |
|
| 451 | - $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 452 | - // un tag html qui a servit a faite le split |
|
| 453 | - $letexte .= array_shift($textMatches); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - return $letexte; |
|
| 443 | + if (!str_contains($letexte, '<')) { |
|
| 444 | + return $letexte; |
|
| 445 | + } |
|
| 446 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 447 | + |
|
| 448 | + $letexte = ''; |
|
| 449 | + while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 450 | + // un texte a echapper |
|
| 451 | + $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 452 | + // un tag html qui a servit a faite le split |
|
| 453 | + $letexte .= array_shift($textMatches); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + return $letexte; |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | /** |
@@ -473,107 +473,107 @@ discard block |
||
| 473 | 473 | * @return string |
| 474 | 474 | */ |
| 475 | 475 | function echapper_html_suspect($texte, $options = [], $connect = null, $env = []) { |
| 476 | - static $echapper_html_suspect; |
|
| 477 | - if (!$texte || !is_string($texte)) { |
|
| 478 | - return $texte; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - if (!isset($echapper_html_suspect)) { |
|
| 482 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 483 | - } |
|
| 484 | - // si fonction personalisee, on delegue |
|
| 485 | - if ($echapper_html_suspect) { |
|
| 486 | - // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 487 | - $args = [$texte, $options]; |
|
| 488 | - if ($connect || !empty($env)) { |
|
| 489 | - $args[] = $connect; |
|
| 490 | - } |
|
| 491 | - if (!empty($env)) { |
|
| 492 | - $args[] = $env; |
|
| 493 | - } |
|
| 494 | - return $echapper_html_suspect(...$args); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - if (is_bool($options)) { |
|
| 498 | - $options = ['strict' => $options]; |
|
| 499 | - } |
|
| 500 | - $strict = $options['strict'] ?? true; |
|
| 501 | - |
|
| 502 | - // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 503 | - if ( |
|
| 504 | - !str_contains($texte, '<') |
|
| 505 | - || !str_contains($texte, '=') |
|
| 506 | - ) { |
|
| 507 | - return $texte; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 511 | - if (!isset($env['espace_prive'])) { |
|
| 512 | - // conserver le comportement historique en cas d'appel court sans env |
|
| 513 | - $env['espace_prive'] = test_espace_prive(); |
|
| 514 | - } |
|
| 515 | - if (!empty($env['espace_prive']) || !empty($env['wysiwyg'])) { |
|
| 516 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 517 | - // car sinon on declenche sur les modeles ou ressources |
|
| 518 | - if ( |
|
| 519 | - !$strict && (!str_contains($texte, 'on') || !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 520 | - ) { |
|
| 521 | - return $texte; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $collecteurModeles = new CollecteurModeles(); |
|
| 525 | - $texte = $collecteurModeles->echapper($texte); |
|
| 526 | - $texte = echappe_js($texte); |
|
| 527 | - |
|
| 528 | - $texte_to_check = $texte; |
|
| 529 | - // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 530 | - // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 531 | - // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 532 | - if (!empty($options['expanser_liens'])) { |
|
| 533 | - $texte_to_check = expanser_liens($texte_to_check, $connect, $env); |
|
| 534 | - } |
|
| 535 | - if (!is_html_safe($texte_to_check)) { |
|
| 536 | - $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 537 | - $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 538 | - $texte = str_replace('<', '<', $texte); |
|
| 539 | - $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 540 | - $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 541 | - if (!function_exists('attribut_html')) { |
|
| 542 | - include_spip('inc/filtres'); |
|
| 543 | - } |
|
| 544 | - if (!empty($options['wrap_suspect'])) { |
|
| 545 | - $texte = wrap($texte, $options['wrap_suspect']); |
|
| 546 | - } |
|
| 547 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - $texte = $collecteurModeles->retablir($texte); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - // si on est là dans le public c'est le mode parano |
|
| 554 | - // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 555 | - else { |
|
| 556 | - $collecteurLiens = $collecteurModeles = null; |
|
| 557 | - if (!empty($options['expanser_liens'])) { |
|
| 558 | - $texte = expanser_liens($texte, $connect, $env); |
|
| 559 | - } |
|
| 560 | - else { |
|
| 561 | - $collecteurLiens = new CollecteurLiens(); |
|
| 562 | - $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 563 | - |
|
| 564 | - $collecteurModeles = new CollecteurModeles(); |
|
| 565 | - $texte = $collecteurModeles->echapper($texte); |
|
| 566 | - } |
|
| 567 | - $texte = safehtml($texte); |
|
| 568 | - if ($collecteurModeles) { |
|
| 569 | - $texte = $collecteurModeles->retablir($texte); |
|
| 570 | - } |
|
| 571 | - if ($collecteurLiens) { |
|
| 572 | - $texte = $collecteurLiens->retablir($texte); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - return $texte; |
|
| 476 | + static $echapper_html_suspect; |
|
| 477 | + if (!$texte || !is_string($texte)) { |
|
| 478 | + return $texte; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + if (!isset($echapper_html_suspect)) { |
|
| 482 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 483 | + } |
|
| 484 | + // si fonction personalisee, on delegue |
|
| 485 | + if ($echapper_html_suspect) { |
|
| 486 | + // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 487 | + $args = [$texte, $options]; |
|
| 488 | + if ($connect || !empty($env)) { |
|
| 489 | + $args[] = $connect; |
|
| 490 | + } |
|
| 491 | + if (!empty($env)) { |
|
| 492 | + $args[] = $env; |
|
| 493 | + } |
|
| 494 | + return $echapper_html_suspect(...$args); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + if (is_bool($options)) { |
|
| 498 | + $options = ['strict' => $options]; |
|
| 499 | + } |
|
| 500 | + $strict = $options['strict'] ?? true; |
|
| 501 | + |
|
| 502 | + // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 503 | + if ( |
|
| 504 | + !str_contains($texte, '<') |
|
| 505 | + || !str_contains($texte, '=') |
|
| 506 | + ) { |
|
| 507 | + return $texte; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 511 | + if (!isset($env['espace_prive'])) { |
|
| 512 | + // conserver le comportement historique en cas d'appel court sans env |
|
| 513 | + $env['espace_prive'] = test_espace_prive(); |
|
| 514 | + } |
|
| 515 | + if (!empty($env['espace_prive']) || !empty($env['wysiwyg'])) { |
|
| 516 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 517 | + // car sinon on declenche sur les modeles ou ressources |
|
| 518 | + if ( |
|
| 519 | + !$strict && (!str_contains($texte, 'on') || !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 520 | + ) { |
|
| 521 | + return $texte; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $collecteurModeles = new CollecteurModeles(); |
|
| 525 | + $texte = $collecteurModeles->echapper($texte); |
|
| 526 | + $texte = echappe_js($texte); |
|
| 527 | + |
|
| 528 | + $texte_to_check = $texte; |
|
| 529 | + // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 530 | + // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 531 | + // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 532 | + if (!empty($options['expanser_liens'])) { |
|
| 533 | + $texte_to_check = expanser_liens($texte_to_check, $connect, $env); |
|
| 534 | + } |
|
| 535 | + if (!is_html_safe($texte_to_check)) { |
|
| 536 | + $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 537 | + $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 538 | + $texte = str_replace('<', '<', $texte); |
|
| 539 | + $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 540 | + $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 541 | + if (!function_exists('attribut_html')) { |
|
| 542 | + include_spip('inc/filtres'); |
|
| 543 | + } |
|
| 544 | + if (!empty($options['wrap_suspect'])) { |
|
| 545 | + $texte = wrap($texte, $options['wrap_suspect']); |
|
| 546 | + } |
|
| 547 | + $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + $texte = $collecteurModeles->retablir($texte); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + // si on est là dans le public c'est le mode parano |
|
| 554 | + // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 555 | + else { |
|
| 556 | + $collecteurLiens = $collecteurModeles = null; |
|
| 557 | + if (!empty($options['expanser_liens'])) { |
|
| 558 | + $texte = expanser_liens($texte, $connect, $env); |
|
| 559 | + } |
|
| 560 | + else { |
|
| 561 | + $collecteurLiens = new CollecteurLiens(); |
|
| 562 | + $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 563 | + |
|
| 564 | + $collecteurModeles = new CollecteurModeles(); |
|
| 565 | + $texte = $collecteurModeles->echapper($texte); |
|
| 566 | + } |
|
| 567 | + $texte = safehtml($texte); |
|
| 568 | + if ($collecteurModeles) { |
|
| 569 | + $texte = $collecteurModeles->retablir($texte); |
|
| 570 | + } |
|
| 571 | + if ($collecteurLiens) { |
|
| 572 | + $texte = $collecteurLiens->retablir($texte); |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + return $texte; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | |
@@ -594,48 +594,48 @@ discard block |
||
| 594 | 594 | * texte sécurisé |
| 595 | 595 | **/ |
| 596 | 596 | function safehtml($t) { |
| 597 | - static $safehtml; |
|
| 598 | - |
|
| 599 | - if (!$t || !is_string($t)) { |
|
| 600 | - return $t; |
|
| 601 | - } |
|
| 602 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 603 | - if (!str_contains($t, '<')) { |
|
| 604 | - return str_replace("\x00", '', $t); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - $collecteurIdiomes = null; |
|
| 608 | - if (stripos($t, '<:') !== false) { |
|
| 609 | - $collecteurIdiomes = new CollecteurIdiomes(); |
|
| 610 | - $t = $collecteurIdiomes->echapper($t); |
|
| 611 | - } |
|
| 612 | - $collecteurMultis = null; |
|
| 613 | - if (stripos($t, '<multi') !== false) { |
|
| 614 | - $collecteurMultis = new CollecteurMultis(); |
|
| 615 | - $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - if (!function_exists('interdire_scripts')) { |
|
| 619 | - include_spip('inc/texte'); |
|
| 620 | - } |
|
| 621 | - $t = interdire_scripts($t); // jolifier le php |
|
| 622 | - $t = echappe_js($t); |
|
| 623 | - |
|
| 624 | - if (!isset($safehtml)) { |
|
| 625 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 626 | - } |
|
| 627 | - if ($safehtml) { |
|
| 628 | - $t = $safehtml($t); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - if ($collecteurMultis) { |
|
| 632 | - $t = $collecteurMultis->retablir($t); |
|
| 633 | - } |
|
| 634 | - if ($collecteurIdiomes) { |
|
| 635 | - $t = $collecteurIdiomes->retablir($t); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 597 | + static $safehtml; |
|
| 598 | + |
|
| 599 | + if (!$t || !is_string($t)) { |
|
| 600 | + return $t; |
|
| 601 | + } |
|
| 602 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 603 | + if (!str_contains($t, '<')) { |
|
| 604 | + return str_replace("\x00", '', $t); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + $collecteurIdiomes = null; |
|
| 608 | + if (stripos($t, '<:') !== false) { |
|
| 609 | + $collecteurIdiomes = new CollecteurIdiomes(); |
|
| 610 | + $t = $collecteurIdiomes->echapper($t); |
|
| 611 | + } |
|
| 612 | + $collecteurMultis = null; |
|
| 613 | + if (stripos($t, '<multi') !== false) { |
|
| 614 | + $collecteurMultis = new CollecteurMultis(); |
|
| 615 | + $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + if (!function_exists('interdire_scripts')) { |
|
| 619 | + include_spip('inc/texte'); |
|
| 620 | + } |
|
| 621 | + $t = interdire_scripts($t); // jolifier le php |
|
| 622 | + $t = echappe_js($t); |
|
| 623 | + |
|
| 624 | + if (!isset($safehtml)) { |
|
| 625 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 626 | + } |
|
| 627 | + if ($safehtml) { |
|
| 628 | + $t = $safehtml($t); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + if ($collecteurMultis) { |
|
| 632 | + $t = $collecteurMultis->retablir($t); |
|
| 633 | + } |
|
| 634 | + if ($collecteurIdiomes) { |
|
| 635 | + $t = $collecteurIdiomes->retablir($t); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | |
@@ -643,29 +643,29 @@ discard block |
||
| 643 | 643 | * Detecter si un texte est "safe" ie non modifie significativement par safehtml() |
| 644 | 644 | */ |
| 645 | 645 | function is_html_safe(string $texte): bool { |
| 646 | - if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 647 | - return $is_html_safe($texte); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 651 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 652 | - // safehtml reduit aussi potentiellement les |
|
| 653 | - $texte = str_replace(' ', ' ', $texte); |
|
| 654 | - // safehtml remplace les entités html |
|
| 655 | - if (str_contains($texte, '&') && str_contains($texte, ';')) { |
|
| 656 | - $texte = html2unicode($texte, true); |
|
| 657 | - } |
|
| 658 | - // safehtml remplace les entités numériques |
|
| 659 | - if (str_contains($texte, '&#')) { |
|
| 660 | - $texte = unicode2charset($texte); |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - $texte_safe = safehtml($texte); |
|
| 664 | - |
|
| 665 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 666 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 667 | - // donc un test d'egalite est trop strict |
|
| 668 | - return strlen($texte_safe) === strlen($texte); |
|
| 646 | + if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 647 | + return $is_html_safe($texte); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 651 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 652 | + // safehtml reduit aussi potentiellement les |
|
| 653 | + $texte = str_replace(' ', ' ', $texte); |
|
| 654 | + // safehtml remplace les entités html |
|
| 655 | + if (str_contains($texte, '&') && str_contains($texte, ';')) { |
|
| 656 | + $texte = html2unicode($texte, true); |
|
| 657 | + } |
|
| 658 | + // safehtml remplace les entités numériques |
|
| 659 | + if (str_contains($texte, '&#')) { |
|
| 660 | + $texte = unicode2charset($texte); |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + $texte_safe = safehtml($texte); |
|
| 664 | + |
|
| 665 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 666 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 667 | + // donc un test d'egalite est trop strict |
|
| 668 | + return strlen($texte_safe) === strlen($texte); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -686,13 +686,13 @@ discard block |
||
| 686 | 686 | * texte sans les modèles d'image |
| 687 | 687 | **/ |
| 688 | 688 | function supprime_img($letexte, $message = null) { |
| 689 | - if ($message === null) { |
|
| 690 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - return preg_replace( |
|
| 694 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 695 | - $message, |
|
| 696 | - $letexte |
|
| 697 | - ); |
|
| 689 | + if ($message === null) { |
|
| 690 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + return preg_replace( |
|
| 694 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 695 | + $message, |
|
| 696 | + $letexte |
|
| 697 | + ); |
|
| 698 | 698 | } |
@@ -556,8 +556,7 @@ |
||
| 556 | 556 | $collecteurLiens = $collecteurModeles = null; |
| 557 | 557 | if (!empty($options['expanser_liens'])) { |
| 558 | 558 | $texte = expanser_liens($texte, $connect, $env); |
| 559 | - } |
|
| 560 | - else { |
|
| 559 | + } else { |
|
| 561 | 560 | $collecteurLiens = new CollecteurLiens(); |
| 562 | 561 | $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
| 563 | 562 | |