@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | \***************************************************************************/ |
| 13 | 13 | |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | include_spip('inc/headers'); |
@@ -21,61 +21,61 @@ discard block |
||
| 21 | 21 | // Mise en place des fichiers de configuration si ce n'est fait |
| 22 | 22 | |
| 23 | 23 | function install_etape_fin_dist() { |
| 24 | - ecrire_acces(); |
|
| 24 | + ecrire_acces(); |
|
| 25 | 25 | |
| 26 | - $f = str_replace(_FILE_TMP_SUFFIX, '.php', (string) _FILE_CHMOD_TMP); |
|
| 27 | - if (file_exists(_FILE_CHMOD_TMP) && !@rename(_FILE_CHMOD_TMP, $f) && @copy(_FILE_CHMOD_TMP, $f)) { |
|
| 28 | - spip_unlink(_FILE_CHMOD_TMP); |
|
| 29 | - } |
|
| 26 | + $f = str_replace(_FILE_TMP_SUFFIX, '.php', (string) _FILE_CHMOD_TMP); |
|
| 27 | + if (file_exists(_FILE_CHMOD_TMP) && !@rename(_FILE_CHMOD_TMP, $f) && @copy(_FILE_CHMOD_TMP, $f)) { |
|
| 28 | + spip_unlink(_FILE_CHMOD_TMP); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - $f = str_replace(_FILE_TMP_SUFFIX, '.php', (string) _FILE_CONNECT_TMP); |
|
| 32 | - if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 33 | - spip_log("renomme $f"); |
|
| 34 | - if (!@rename(_FILE_CONNECT_TMP, $f) && @copy(_FILE_CONNECT_TMP, $f)) { |
|
| 35 | - @spip_unlink(_FILE_CONNECT_TMP); |
|
| 36 | - } |
|
| 37 | - } |
|
| 31 | + $f = str_replace(_FILE_TMP_SUFFIX, '.php', (string) _FILE_CONNECT_TMP); |
|
| 32 | + if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 33 | + spip_log("renomme $f"); |
|
| 34 | + if (!@rename(_FILE_CONNECT_TMP, $f) && @copy(_FILE_CONNECT_TMP, $f)) { |
|
| 35 | + @spip_unlink(_FILE_CONNECT_TMP); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - // creer le repertoire cache, qui sert partout ! |
|
| 40 | - // deja fait en etape 4 en principe, on garde au cas ou |
|
| 41 | - if (!@file_exists(_DIR_CACHE)) { |
|
| 42 | - $rep = preg_replace(',' . _DIR_TMP . ',', '', (string) _DIR_CACHE); |
|
| 43 | - $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 44 | - } |
|
| 39 | + // creer le repertoire cache, qui sert partout ! |
|
| 40 | + // deja fait en etape 4 en principe, on garde au cas ou |
|
| 41 | + if (!@file_exists(_DIR_CACHE)) { |
|
| 42 | + $rep = preg_replace(',' . _DIR_TMP . ',', '', (string) _DIR_CACHE); |
|
| 43 | + $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - // Verifier la securite des htaccess |
|
| 47 | - // Si elle ne fonctionne pas, prevenir |
|
| 48 | - $msg = install_verifier_htaccess(); |
|
| 49 | - if ($msg) { |
|
| 50 | - $cible = _T('public:accueil_site'); |
|
| 51 | - $cible = generer_form_ecrire('accueil', '', '', $cible); |
|
| 52 | - $minipage = new Installation(); |
|
| 53 | - echo $minipage->page($msg . $cible); |
|
| 54 | - // ok, deboucher dans l'espace prive |
|
| 55 | - } else { |
|
| 56 | - redirige_url_ecrire('accueil'); |
|
| 57 | - } |
|
| 46 | + // Verifier la securite des htaccess |
|
| 47 | + // Si elle ne fonctionne pas, prevenir |
|
| 48 | + $msg = install_verifier_htaccess(); |
|
| 49 | + if ($msg) { |
|
| 50 | + $cible = _T('public:accueil_site'); |
|
| 51 | + $cible = generer_form_ecrire('accueil', '', '', $cible); |
|
| 52 | + $minipage = new Installation(); |
|
| 53 | + echo $minipage->page($msg . $cible); |
|
| 54 | + // ok, deboucher dans l'espace prive |
|
| 55 | + } else { |
|
| 56 | + redirige_url_ecrire('accueil'); |
|
| 57 | + } |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | function install_verifier_htaccess() { |
| 61 | - if ( |
|
| 62 | - verifier_htaccess(_DIR_TMP, true) |
|
| 63 | - && verifier_htaccess(_DIR_CONNECT, true) |
|
| 64 | - && verifier_htaccess(_DIR_VENDOR, true) |
|
| 65 | - ) { |
|
| 66 | - return ''; |
|
| 67 | - } |
|
| 61 | + if ( |
|
| 62 | + verifier_htaccess(_DIR_TMP, true) |
|
| 63 | + && verifier_htaccess(_DIR_CONNECT, true) |
|
| 64 | + && verifier_htaccess(_DIR_VENDOR, true) |
|
| 65 | + ) { |
|
| 66 | + return ''; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $titre = _T('htaccess_inoperant'); |
|
| 69 | + $titre = _T('htaccess_inoperant'); |
|
| 70 | 70 | |
| 71 | - $averti = _T( |
|
| 72 | - 'htaccess_a_simuler', |
|
| 73 | - [ |
|
| 74 | - 'htaccess' => '<tt>' . _ACCESS_FILE_NAME . '</tt>', |
|
| 75 | - 'constantes' => '<tt>_DIR_TMP & _DIR_CONNECT</tt>', |
|
| 76 | - 'document_root' => '<tt>' . $_SERVER['DOCUMENT_ROOT'] . '</tt>' |
|
| 77 | - ] |
|
| 78 | - ); |
|
| 71 | + $averti = _T( |
|
| 72 | + 'htaccess_a_simuler', |
|
| 73 | + [ |
|
| 74 | + 'htaccess' => '<tt>' . _ACCESS_FILE_NAME . '</tt>', |
|
| 75 | + 'constantes' => '<tt>_DIR_TMP & _DIR_CONNECT</tt>', |
|
| 76 | + 'document_root' => '<tt>' . $_SERVER['DOCUMENT_ROOT'] . '</tt>' |
|
| 77 | + ] |
|
| 78 | + ); |
|
| 79 | 79 | |
| 80 | - return "<div class='error'><h3>$titre</h3><p>$averti</p></div>"; |
|
| 80 | + return "<div class='error'><h3>$titre</h3><p>$averti</p></div>"; |
|
| 81 | 81 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | // creer le repertoire cache, qui sert partout ! |
| 40 | 40 | // deja fait en etape 4 en principe, on garde au cas ou |
| 41 | 41 | if (!@file_exists(_DIR_CACHE)) { |
| 42 | - $rep = preg_replace(',' . _DIR_TMP . ',', '', (string) _DIR_CACHE); |
|
| 42 | + $rep = preg_replace(','._DIR_TMP.',', '', (string) _DIR_CACHE); |
|
| 43 | 43 | $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $cible = _T('public:accueil_site'); |
| 51 | 51 | $cible = generer_form_ecrire('accueil', '', '', $cible); |
| 52 | 52 | $minipage = new Installation(); |
| 53 | - echo $minipage->page($msg . $cible); |
|
| 53 | + echo $minipage->page($msg.$cible); |
|
| 54 | 54 | // ok, deboucher dans l'espace prive |
| 55 | 55 | } else { |
| 56 | 56 | redirige_url_ecrire('accueil'); |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | $averti = _T( |
| 72 | 72 | 'htaccess_a_simuler', |
| 73 | 73 | [ |
| 74 | - 'htaccess' => '<tt>' . _ACCESS_FILE_NAME . '</tt>', |
|
| 74 | + 'htaccess' => '<tt>'._ACCESS_FILE_NAME.'</tt>', |
|
| 75 | 75 | 'constantes' => '<tt>_DIR_TMP & _DIR_CONNECT</tt>', |
| 76 | - 'document_root' => '<tt>' . $_SERVER['DOCUMENT_ROOT'] . '</tt>' |
|
| 76 | + 'document_root' => '<tt>'.$_SERVER['DOCUMENT_ROOT'].'</tt>' |
|
| 77 | 77 | ] |
| 78 | 78 | ); |
| 79 | 79 | |
@@ -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 | /** |
@@ -27,20 +27,20 @@ discard block |
||
| 27 | 27 | * @uses info_copyright() |
| 28 | 28 | **/ |
| 29 | 29 | function install_etape__dist() { |
| 30 | - utiliser_langue_visiteur(); |
|
| 31 | - $menu_langues = menu_langues('var_lang_ecrire'); |
|
| 32 | - if (!$menu_langues) { |
|
| 33 | - redirige_url_ecrire('install', 'etape=chmod'); |
|
| 34 | - } else { |
|
| 35 | - include_spip('inc/presentation'); // pour info_copyright |
|
| 30 | + utiliser_langue_visiteur(); |
|
| 31 | + $menu_langues = menu_langues('var_lang_ecrire'); |
|
| 32 | + if (!$menu_langues) { |
|
| 33 | + redirige_url_ecrire('install', 'etape=chmod'); |
|
| 34 | + } else { |
|
| 35 | + include_spip('inc/presentation'); // pour info_copyright |
|
| 36 | 36 | |
| 37 | - $res = "<div class='petit-centre'><img alt='SPIP' class='logo' src='" . chemin_image('logo-spip.png') . "' />\n" . |
|
| 38 | - "<p class='small'>" . info_copyright() . "</p></div>\n" . |
|
| 39 | - '<p>' . _T('install_select_langue') . '</p>' . |
|
| 40 | - '<div>' . $menu_langues . "</div>\n" . |
|
| 41 | - generer_form_ecrire('install', "<input type='hidden' name='etape' value='chmod' />" . bouton_suivant()); |
|
| 37 | + $res = "<div class='petit-centre'><img alt='SPIP' class='logo' src='" . chemin_image('logo-spip.png') . "' />\n" . |
|
| 38 | + "<p class='small'>" . info_copyright() . "</p></div>\n" . |
|
| 39 | + '<p>' . _T('install_select_langue') . '</p>' . |
|
| 40 | + '<div>' . $menu_langues . "</div>\n" . |
|
| 41 | + generer_form_ecrire('install', "<input type='hidden' name='etape' value='chmod' />" . bouton_suivant()); |
|
| 42 | 42 | |
| 43 | - $minipage = new Installation(); |
|
| 44 | - echo $minipage->page($res); |
|
| 45 | - } |
|
| 43 | + $minipage = new Installation(); |
|
| 44 | + echo $minipage->page($res); |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -34,11 +34,11 @@ |
||
| 34 | 34 | } else { |
| 35 | 35 | include_spip('inc/presentation'); // pour info_copyright |
| 36 | 36 | |
| 37 | - $res = "<div class='petit-centre'><img alt='SPIP' class='logo' src='" . chemin_image('logo-spip.png') . "' />\n" . |
|
| 38 | - "<p class='small'>" . info_copyright() . "</p></div>\n" . |
|
| 39 | - '<p>' . _T('install_select_langue') . '</p>' . |
|
| 40 | - '<div>' . $menu_langues . "</div>\n" . |
|
| 41 | - generer_form_ecrire('install', "<input type='hidden' name='etape' value='chmod' />" . bouton_suivant()); |
|
| 37 | + $res = "<div class='petit-centre'><img alt='SPIP' class='logo' src='".chemin_image('logo-spip.png')."' />\n". |
|
| 38 | + "<p class='small'>".info_copyright()."</p></div>\n". |
|
| 39 | + '<p>'._T('install_select_langue').'</p>'. |
|
| 40 | + '<div>'.$menu_langues."</div>\n". |
|
| 41 | + generer_form_ecrire('install', "<input type='hidden' name='etape' value='chmod' />".bouton_suivant()); |
|
| 42 | 42 | |
| 43 | 43 | $minipage = new Installation(); |
| 44 | 44 | echo $minipage->page($res); |
@@ -12,167 +12,167 @@ |
||
| 12 | 12 | \***************************************************************************/ |
| 13 | 13 | |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | include_spip('base/abstract_sql'); |
| 19 | 19 | |
| 20 | 20 | function install_etape_2_dist() { |
| 21 | - $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 22 | - ? _INSTALL_HOST_DB |
|
| 23 | - : _request('adresse_db'); |
|
| 21 | + $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 22 | + ? _INSTALL_HOST_DB |
|
| 23 | + : _request('adresse_db'); |
|
| 24 | 24 | |
| 25 | - if (preg_match(',(.*):(.*),', (string) $adresse_db, $r)) { |
|
| 26 | - [, $adresse_db, $port] = $r; |
|
| 27 | - } else { |
|
| 28 | - $port = ''; |
|
| 29 | - } |
|
| 25 | + if (preg_match(',(.*):(.*),', (string) $adresse_db, $r)) { |
|
| 26 | + [, $adresse_db, $port] = $r; |
|
| 27 | + } else { |
|
| 28 | + $port = ''; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - $login_db = defined('_INSTALL_USER_DB') |
|
| 32 | - ? _INSTALL_USER_DB |
|
| 33 | - : _request('login_db'); |
|
| 31 | + $login_db = defined('_INSTALL_USER_DB') |
|
| 32 | + ? _INSTALL_USER_DB |
|
| 33 | + : _request('login_db'); |
|
| 34 | 34 | |
| 35 | - $pass_db = defined('_INSTALL_PASS_DB') |
|
| 36 | - ? _INSTALL_PASS_DB |
|
| 37 | - : _request('pass_db'); |
|
| 35 | + $pass_db = defined('_INSTALL_PASS_DB') |
|
| 36 | + ? _INSTALL_PASS_DB |
|
| 37 | + : _request('pass_db'); |
|
| 38 | 38 | |
| 39 | - $server_db = defined('_INSTALL_SERVER_DB') |
|
| 40 | - ? _INSTALL_SERVER_DB |
|
| 41 | - : _request('server_db'); |
|
| 39 | + $server_db = defined('_INSTALL_SERVER_DB') |
|
| 40 | + ? _INSTALL_SERVER_DB |
|
| 41 | + : _request('server_db'); |
|
| 42 | 42 | |
| 43 | - $name_db = defined('_INSTALL_NAME_DB') |
|
| 44 | - ? _INSTALL_NAME_DB |
|
| 45 | - : ''; |
|
| 43 | + $name_db = defined('_INSTALL_NAME_DB') |
|
| 44 | + ? _INSTALL_NAME_DB |
|
| 45 | + : ''; |
|
| 46 | 46 | |
| 47 | - $chmod = _request('chmod'); |
|
| 47 | + $chmod = _request('chmod'); |
|
| 48 | 48 | |
| 49 | - $link = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $name_db, $server_db); |
|
| 50 | - $GLOBALS['connexions'][$server_db] = $link; |
|
| 49 | + $link = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $name_db, $server_db); |
|
| 50 | + $GLOBALS['connexions'][$server_db] = $link; |
|
| 51 | 51 | |
| 52 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 53 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 52 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 53 | + = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 54 | 54 | |
| 55 | - $minipage = new Installation(); |
|
| 56 | - echo $minipage->installDebutPage(); |
|
| 55 | + $minipage = new Installation(); |
|
| 56 | + echo $minipage->installDebutPage(); |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | // prenons toutes les dispositions possibles pour que rien ne s'affiche ! |
| 60 | 60 | |
| 61 | - /* |
|
| 61 | + /* |
|
| 62 | 62 | * /!\ sqlite3/PDO : erreur sur join(', ', $link) |
| 63 | 63 | * L'objet PDO ne peut pas etre transformee en chaine |
| 64 | 64 | * Un echo $link ne fonctionne pas non plus |
| 65 | 65 | * Il faut utiliser par exemple print_r($link) |
| 66 | 66 | */ |
| 67 | - //echo "\n<!--\n", join(', ', $link), " $login_db "; |
|
| 68 | - $db_connect = 0; // revoirfunction_exists($ferrno) ? $ferrno() : 0; |
|
| 69 | - //echo join(', ', $GLOBALS['connexions'][$server_db]); |
|
| 70 | - //echo "\n-->\n"; |
|
| 67 | + //echo "\n<!--\n", join(', ', $link), " $login_db "; |
|
| 68 | + $db_connect = 0; // revoirfunction_exists($ferrno) ? $ferrno() : 0; |
|
| 69 | + //echo join(', ', $GLOBALS['connexions'][$server_db]); |
|
| 70 | + //echo "\n-->\n"; |
|
| 71 | 71 | |
| 72 | - if (($db_connect == '0') && $link) { |
|
| 73 | - echo "<div class='success'><b>" . _T('info_connexion_ok') . '</b></div>'; |
|
| 74 | - echo info_progression_etape(2, 'etape_', 'install/'); |
|
| 72 | + if (($db_connect == '0') && $link) { |
|
| 73 | + echo "<div class='success'><b>" . _T('info_connexion_ok') . '</b></div>'; |
|
| 74 | + echo info_progression_etape(2, 'etape_', 'install/'); |
|
| 75 | 75 | |
| 76 | - echo info_etape(_T('menu_aide_installation_choix_base') . aider('install2', true)); |
|
| 76 | + echo info_etape(_T('menu_aide_installation_choix_base') . aider('install2', true)); |
|
| 77 | 77 | |
| 78 | - echo "\n", '<!-- ', sql_version($server_db), ' -->'; |
|
| 79 | - [$checked, $res] = install_etape_2_bases($login_db, $server_db); |
|
| 78 | + echo "\n", '<!-- ', sql_version($server_db), ' -->'; |
|
| 79 | + [$checked, $res] = install_etape_2_bases($login_db, $server_db); |
|
| 80 | 80 | |
| 81 | - $hidden = (defined('_SPIP_CHMOD') |
|
| 82 | - ? '' |
|
| 83 | - : ("\n<input type='hidden' name='chmod' value='" . spip_htmlspecialchars($chmod) . "' />")) |
|
| 84 | - . predef_ou_cache($adresse_db . ($port ? ':' . $port : ''), $login_db, $pass_db, $server_db); |
|
| 81 | + $hidden = (defined('_SPIP_CHMOD') |
|
| 82 | + ? '' |
|
| 83 | + : ("\n<input type='hidden' name='chmod' value='" . spip_htmlspecialchars($chmod) . "' />")) |
|
| 84 | + . predef_ou_cache($adresse_db . ($port ? ':' . $port : ''), $login_db, $pass_db, $server_db); |
|
| 85 | 85 | |
| 86 | - echo install_etape_2_form($hidden, $checked, $res, 3); |
|
| 87 | - } else { |
|
| 88 | - echo info_progression_etape(1, 'etape_', 'install/', true); |
|
| 86 | + echo install_etape_2_form($hidden, $checked, $res, 3); |
|
| 87 | + } else { |
|
| 88 | + echo info_progression_etape(1, 'etape_', 'install/', true); |
|
| 89 | 89 | |
| 90 | - echo "<div class='error'>"; |
|
| 91 | - echo info_etape(_T('info_connexion_base')); |
|
| 92 | - echo '<h3>' . _T('avis_connexion_echec_1') . '</h3>'; |
|
| 93 | - echo '<p>' . _T('avis_connexion_echec_2') . '</p>'; |
|
| 90 | + echo "<div class='error'>"; |
|
| 91 | + echo info_etape(_T('info_connexion_base')); |
|
| 92 | + echo '<h3>' . _T('avis_connexion_echec_1') . '</h3>'; |
|
| 93 | + echo '<p>' . _T('avis_connexion_echec_2') . '</p>'; |
|
| 94 | 94 | |
| 95 | - echo "<p style='font-size: small;'>", |
|
| 96 | - _T('avis_connexion_echec_3'), |
|
| 97 | - '</p></div>'; |
|
| 98 | - } |
|
| 95 | + echo "<p style='font-size: small;'>", |
|
| 96 | + _T('avis_connexion_echec_3'), |
|
| 97 | + '</p></div>'; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - echo $minipage->installFinPage(); |
|
| 100 | + echo $minipage->installFinPage(); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | // Liste les bases accessibles, |
| 104 | 104 | // avec une heuristique pour preselectionner la plus probable |
| 105 | 105 | |
| 106 | 106 | function install_etape_2_bases($login_db, $server_db) { |
| 107 | - $res = install_etape_liste_bases($server_db, $login_db); |
|
| 108 | - if ($res) { |
|
| 109 | - [$checked, $bases] = $res; |
|
| 110 | - |
|
| 111 | - return [ |
|
| 112 | - $checked, |
|
| 113 | - "<label for='choix_db'><b>" |
|
| 114 | - . _T('texte_choix_base_2') |
|
| 115 | - . '</b><br />' |
|
| 116 | - . _T('texte_choix_base_3') |
|
| 117 | - . '</label>' |
|
| 118 | - . "<ul>\n<li>" |
|
| 119 | - . implode("</li>\n<li>", $bases) |
|
| 120 | - . "</li>\n</ul><p>" |
|
| 121 | - . _T('info_ou') |
|
| 122 | - . ' ' |
|
| 123 | - ]; |
|
| 124 | - } |
|
| 125 | - $res = '<b>' . _T('avis_lecture_noms_bases_1') . '</b> |
|
| 107 | + $res = install_etape_liste_bases($server_db, $login_db); |
|
| 108 | + if ($res) { |
|
| 109 | + [$checked, $bases] = $res; |
|
| 110 | + |
|
| 111 | + return [ |
|
| 112 | + $checked, |
|
| 113 | + "<label for='choix_db'><b>" |
|
| 114 | + . _T('texte_choix_base_2') |
|
| 115 | + . '</b><br />' |
|
| 116 | + . _T('texte_choix_base_3') |
|
| 117 | + . '</label>' |
|
| 118 | + . "<ul>\n<li>" |
|
| 119 | + . implode("</li>\n<li>", $bases) |
|
| 120 | + . "</li>\n</ul><p>" |
|
| 121 | + . _T('info_ou') |
|
| 122 | + . ' ' |
|
| 123 | + ]; |
|
| 124 | + } |
|
| 125 | + $res = '<b>' . _T('avis_lecture_noms_bases_1') . '</b> |
|
| 126 | 126 | ' . _T('avis_lecture_noms_bases_2') . '<p>'; |
| 127 | 127 | |
| 128 | - $checked = false; |
|
| 129 | - if ($login_db) { |
|
| 130 | - // Si un login comporte un point, le nom de la base est plus |
|
| 131 | - // probablement le login sans le point -- testons pour savoir |
|
| 132 | - $test_base = $login_db; |
|
| 133 | - $ok = sql_selectdb($test_base, $server_db); |
|
| 134 | - $test_base2 = str_replace('.', '_', (string) $test_base); |
|
| 135 | - if (sql_selectdb($test_base2, $server_db)) { |
|
| 136 | - $test_base = $test_base2; |
|
| 137 | - $ok = true; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - if ($ok) { |
|
| 141 | - $res .= _T('avis_lecture_noms_bases_3') |
|
| 142 | - . '<ul>' |
|
| 143 | - . '<li><input name="choix_db" value="' . $test_base . "\" type='radio' id='stand' checked='checked' />" |
|
| 144 | - . "<label for='stand'>" . $test_base . "</label></li>\n" |
|
| 145 | - . '</ul>' |
|
| 146 | - . '<p>' . _T('info_ou') . ' '; |
|
| 147 | - $checked = true; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - return [$checked, $res]; |
|
| 128 | + $checked = false; |
|
| 129 | + if ($login_db) { |
|
| 130 | + // Si un login comporte un point, le nom de la base est plus |
|
| 131 | + // probablement le login sans le point -- testons pour savoir |
|
| 132 | + $test_base = $login_db; |
|
| 133 | + $ok = sql_selectdb($test_base, $server_db); |
|
| 134 | + $test_base2 = str_replace('.', '_', (string) $test_base); |
|
| 135 | + if (sql_selectdb($test_base2, $server_db)) { |
|
| 136 | + $test_base = $test_base2; |
|
| 137 | + $ok = true; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + if ($ok) { |
|
| 141 | + $res .= _T('avis_lecture_noms_bases_3') |
|
| 142 | + . '<ul>' |
|
| 143 | + . '<li><input name="choix_db" value="' . $test_base . "\" type='radio' id='stand' checked='checked' />" |
|
| 144 | + . "<label for='stand'>" . $test_base . "</label></li>\n" |
|
| 145 | + . '</ul>' |
|
| 146 | + . '<p>' . _T('info_ou') . ' '; |
|
| 147 | + $checked = true; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + return [$checked, $res]; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | function install_etape_2_form($hidden, $checked, $res, $etape) { |
| 155 | - return generer_form_ecrire('install', ( |
|
| 156 | - "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 157 | - . $hidden |
|
| 158 | - . (defined('_INSTALL_NAME_DB') |
|
| 159 | - ? '<h3>' . _T('install_nom_base_hebergeur') . ' <tt>' . _INSTALL_NAME_DB . '</tt>' . '</h3>' |
|
| 160 | - : "\n<fieldset><legend>" . _T('texte_choix_base_1') . "</legend>\n" |
|
| 161 | - . $res |
|
| 162 | - . "\n<input name=\"choix_db\" value=\"new_spip\" type='radio' id='nou'" |
|
| 163 | - . ($checked ? '' : " checked='checked'") |
|
| 164 | - . " />\n<label for='nou'>" . _T('info_creer_base') . "</label></p>\n<p>" |
|
| 165 | - . "\n<input type='text' name='table_new' class='text' value=\"spip\" size='20' /></p></fieldset>\n" |
|
| 166 | - ) |
|
| 167 | - |
|
| 168 | - . ((defined('_INSTALL_TABLE_PREFIX') || $GLOBALS['table_prefix'] != 'spip') |
|
| 169 | - ? '<h3>' . _T('install_table_prefix_hebergeur') . ' <tt>' . $GLOBALS['table_prefix'] . '</tt>' . '</h3>' |
|
| 170 | - : '<fieldset><legend>' . _T('texte_choix_table_prefix') . "</legend>\n" |
|
| 171 | - . "<p><label for='table_prefix'>" . _T('info_table_prefix') . '</label></p><p>' |
|
| 172 | - . "\n<input type='text' id='tprefix' name='tprefix' class='text' value='" |
|
| 173 | - . 'spip' # valeur par defaut |
|
| 174 | - . "' size='20' /></p></fieldset>" |
|
| 175 | - ) |
|
| 176 | - |
|
| 177 | - . bouton_suivant())); |
|
| 155 | + return generer_form_ecrire('install', ( |
|
| 156 | + "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 157 | + . $hidden |
|
| 158 | + . (defined('_INSTALL_NAME_DB') |
|
| 159 | + ? '<h3>' . _T('install_nom_base_hebergeur') . ' <tt>' . _INSTALL_NAME_DB . '</tt>' . '</h3>' |
|
| 160 | + : "\n<fieldset><legend>" . _T('texte_choix_base_1') . "</legend>\n" |
|
| 161 | + . $res |
|
| 162 | + . "\n<input name=\"choix_db\" value=\"new_spip\" type='radio' id='nou'" |
|
| 163 | + . ($checked ? '' : " checked='checked'") |
|
| 164 | + . " />\n<label for='nou'>" . _T('info_creer_base') . "</label></p>\n<p>" |
|
| 165 | + . "\n<input type='text' name='table_new' class='text' value=\"spip\" size='20' /></p></fieldset>\n" |
|
| 166 | + ) |
|
| 167 | + |
|
| 168 | + . ((defined('_INSTALL_TABLE_PREFIX') || $GLOBALS['table_prefix'] != 'spip') |
|
| 169 | + ? '<h3>' . _T('install_table_prefix_hebergeur') . ' <tt>' . $GLOBALS['table_prefix'] . '</tt>' . '</h3>' |
|
| 170 | + : '<fieldset><legend>' . _T('texte_choix_table_prefix') . "</legend>\n" |
|
| 171 | + . "<p><label for='table_prefix'>" . _T('info_table_prefix') . '</label></p><p>' |
|
| 172 | + . "\n<input type='text' id='tprefix' name='tprefix' class='text' value='" |
|
| 173 | + . 'spip' # valeur par defaut |
|
| 174 | + . "' size='20' /></p></fieldset>" |
|
| 175 | + ) |
|
| 176 | + |
|
| 177 | + . bouton_suivant())); |
|
| 178 | 178 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $GLOBALS['connexions'][$server_db] = $link; |
| 51 | 51 | |
| 52 | 52 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
| 53 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 53 | + = $GLOBALS['spip_'.$server_db.'_functions_'.$GLOBALS['spip_sql_version']]; |
|
| 54 | 54 | |
| 55 | 55 | $minipage = new Installation(); |
| 56 | 56 | echo $minipage->installDebutPage(); |
@@ -70,18 +70,18 @@ discard block |
||
| 70 | 70 | //echo "\n-->\n"; |
| 71 | 71 | |
| 72 | 72 | if (($db_connect == '0') && $link) { |
| 73 | - echo "<div class='success'><b>" . _T('info_connexion_ok') . '</b></div>'; |
|
| 73 | + echo "<div class='success'><b>"._T('info_connexion_ok').'</b></div>'; |
|
| 74 | 74 | echo info_progression_etape(2, 'etape_', 'install/'); |
| 75 | 75 | |
| 76 | - echo info_etape(_T('menu_aide_installation_choix_base') . aider('install2', true)); |
|
| 76 | + echo info_etape(_T('menu_aide_installation_choix_base').aider('install2', true)); |
|
| 77 | 77 | |
| 78 | 78 | echo "\n", '<!-- ', sql_version($server_db), ' -->'; |
| 79 | 79 | [$checked, $res] = install_etape_2_bases($login_db, $server_db); |
| 80 | 80 | |
| 81 | 81 | $hidden = (defined('_SPIP_CHMOD') |
| 82 | 82 | ? '' |
| 83 | - : ("\n<input type='hidden' name='chmod' value='" . spip_htmlspecialchars($chmod) . "' />")) |
|
| 84 | - . predef_ou_cache($adresse_db . ($port ? ':' . $port : ''), $login_db, $pass_db, $server_db); |
|
| 83 | + : ("\n<input type='hidden' name='chmod' value='".spip_htmlspecialchars($chmod)."' />")) |
|
| 84 | + . predef_ou_cache($adresse_db.($port ? ':'.$port : ''), $login_db, $pass_db, $server_db); |
|
| 85 | 85 | |
| 86 | 86 | echo install_etape_2_form($hidden, $checked, $res, 3); |
| 87 | 87 | } else { |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | echo "<div class='error'>"; |
| 91 | 91 | echo info_etape(_T('info_connexion_base')); |
| 92 | - echo '<h3>' . _T('avis_connexion_echec_1') . '</h3>'; |
|
| 93 | - echo '<p>' . _T('avis_connexion_echec_2') . '</p>'; |
|
| 92 | + echo '<h3>'._T('avis_connexion_echec_1').'</h3>'; |
|
| 93 | + echo '<p>'._T('avis_connexion_echec_2').'</p>'; |
|
| 94 | 94 | |
| 95 | 95 | echo "<p style='font-size: small;'>", |
| 96 | 96 | _T('avis_connexion_echec_3'), |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | . ' ' |
| 123 | 123 | ]; |
| 124 | 124 | } |
| 125 | - $res = '<b>' . _T('avis_lecture_noms_bases_1') . '</b> |
|
| 126 | - ' . _T('avis_lecture_noms_bases_2') . '<p>'; |
|
| 125 | + $res = '<b>'._T('avis_lecture_noms_bases_1').'</b> |
|
| 126 | + ' . _T('avis_lecture_noms_bases_2').'<p>'; |
|
| 127 | 127 | |
| 128 | 128 | $checked = false; |
| 129 | 129 | if ($login_db) { |
@@ -140,10 +140,10 @@ discard block |
||
| 140 | 140 | if ($ok) { |
| 141 | 141 | $res .= _T('avis_lecture_noms_bases_3') |
| 142 | 142 | . '<ul>' |
| 143 | - . '<li><input name="choix_db" value="' . $test_base . "\" type='radio' id='stand' checked='checked' />" |
|
| 144 | - . "<label for='stand'>" . $test_base . "</label></li>\n" |
|
| 143 | + . '<li><input name="choix_db" value="'.$test_base."\" type='radio' id='stand' checked='checked' />" |
|
| 144 | + . "<label for='stand'>".$test_base."</label></li>\n" |
|
| 145 | 145 | . '</ul>' |
| 146 | - . '<p>' . _T('info_ou') . ' '; |
|
| 146 | + . '<p>'._T('info_ou').' '; |
|
| 147 | 147 | $checked = true; |
| 148 | 148 | } |
| 149 | 149 | } |
@@ -156,19 +156,19 @@ discard block |
||
| 156 | 156 | "\n<input type='hidden' name='etape' value='$etape' />" |
| 157 | 157 | . $hidden |
| 158 | 158 | . (defined('_INSTALL_NAME_DB') |
| 159 | - ? '<h3>' . _T('install_nom_base_hebergeur') . ' <tt>' . _INSTALL_NAME_DB . '</tt>' . '</h3>' |
|
| 160 | - : "\n<fieldset><legend>" . _T('texte_choix_base_1') . "</legend>\n" |
|
| 159 | + ? '<h3>'._T('install_nom_base_hebergeur').' <tt>'._INSTALL_NAME_DB.'</tt>'.'</h3>' |
|
| 160 | + : "\n<fieldset><legend>"._T('texte_choix_base_1')."</legend>\n" |
|
| 161 | 161 | . $res |
| 162 | 162 | . "\n<input name=\"choix_db\" value=\"new_spip\" type='radio' id='nou'" |
| 163 | 163 | . ($checked ? '' : " checked='checked'") |
| 164 | - . " />\n<label for='nou'>" . _T('info_creer_base') . "</label></p>\n<p>" |
|
| 164 | + . " />\n<label for='nou'>"._T('info_creer_base')."</label></p>\n<p>" |
|
| 165 | 165 | . "\n<input type='text' name='table_new' class='text' value=\"spip\" size='20' /></p></fieldset>\n" |
| 166 | 166 | ) |
| 167 | 167 | |
| 168 | 168 | . ((defined('_INSTALL_TABLE_PREFIX') || $GLOBALS['table_prefix'] != 'spip') |
| 169 | - ? '<h3>' . _T('install_table_prefix_hebergeur') . ' <tt>' . $GLOBALS['table_prefix'] . '</tt>' . '</h3>' |
|
| 170 | - : '<fieldset><legend>' . _T('texte_choix_table_prefix') . "</legend>\n" |
|
| 171 | - . "<p><label for='table_prefix'>" . _T('info_table_prefix') . '</label></p><p>' |
|
| 169 | + ? '<h3>'._T('install_table_prefix_hebergeur').' <tt>'.$GLOBALS['table_prefix'].'</tt>'.'</h3>' |
|
| 170 | + : '<fieldset><legend>'._T('texte_choix_table_prefix')."</legend>\n" |
|
| 171 | + . "<p><label for='table_prefix'>"._T('info_table_prefix').'</label></p><p>' |
|
| 172 | 172 | . "\n<input type='text' id='tprefix' name='tprefix' class='text' value='" |
| 173 | 173 | . 'spip' # valeur par defaut |
| 174 | 174 | . "' size='20' /></p></fieldset>" |
@@ -13,169 +13,169 @@ |
||
| 13 | 13 | |
| 14 | 14 | /** Gestion des clés d’authentification / chiffrement de SPIP */ |
| 15 | 15 | final class SpipCles { |
| 16 | - private static array $instances = []; |
|
| 17 | - |
|
| 18 | - private string $file = _DIR_ETC . 'cles.php'; |
|
| 19 | - private readonly Cles $cles; |
|
| 20 | - |
|
| 21 | - public static function instance(string $file = ''): self { |
|
| 22 | - if (empty(self::$instances[$file])) { |
|
| 23 | - self::$instances[$file] = new self($file); |
|
| 24 | - } |
|
| 25 | - return self::$instances[$file]; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Retourne le secret du site (shorthand) |
|
| 30 | - * @uses self::getSecretSite() |
|
| 31 | - */ |
|
| 32 | - public static function secret_du_site(): ?string { |
|
| 33 | - return (self::instance())->getSecretSite(); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - private function __construct(string $file = '') { |
|
| 37 | - if ($file) { |
|
| 38 | - $this->file = $file; |
|
| 39 | - } |
|
| 40 | - $this->cles = new Cles($this->read()); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Renvoyer le secret du site |
|
| 45 | - * |
|
| 46 | - * Le secret du site doit rester aussi secret que possible, et est eternel |
|
| 47 | - * On ne doit pas l'exporter |
|
| 48 | - * |
|
| 49 | - * Le secret est partagé entre une clé disque et une clé bdd |
|
| 50 | - * |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - public function getSecretSite(bool $autoInit = true): ?string { |
|
| 54 | - $key = $this->getKey('secret_du_site', $autoInit); |
|
| 55 | - $meta = $this->getMetaKey('secret_du_site', $autoInit); |
|
| 56 | - // conserve la même longeur. |
|
| 57 | - return $key ^ $meta; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** Renvoyer le secret des authentifications */ |
|
| 61 | - public function getSecretAuth(bool $autoInit = false): ?string { |
|
| 62 | - return $this->getKey('secret_des_auth', $autoInit); |
|
| 63 | - } |
|
| 64 | - public function save(): bool { |
|
| 65 | - return ecrire_fichier_securise($this->file, $this->cles->toJson()); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Fournir une sauvegarde chiffree des cles (a l'aide d'une autre clé, comme le pass d'un auteur) |
|
| 70 | - * |
|
| 71 | - * @param string $withKey Clé de chiffrage de la sauvegarde |
|
| 72 | - * @return string Contenu de la sauvegarde chiffrée générée |
|
| 73 | - */ |
|
| 74 | - public function backup( |
|
| 75 | - #[\SensitiveParameter] |
|
| 76 | - string $withKey |
|
| 77 | - ): string { |
|
| 78 | - if (count($this->cles)) { |
|
| 79 | - return Chiffrement::chiffrer($this->cles->toJson(), $withKey); |
|
| 80 | - } |
|
| 81 | - return ''; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Restaurer les cles manquantes depuis une sauvegarde chiffree des cles |
|
| 86 | - * (si la sauvegarde est bien valide) |
|
| 87 | - */ |
|
| 88 | - public function restore( |
|
| 89 | - /** Sauvegarde chiffrée (générée par backup()) */ |
|
| 90 | - string $backup, |
|
| 91 | - #[\SensitiveParameter] |
|
| 92 | - string $password_clair, |
|
| 93 | - #[\SensitiveParameter] |
|
| 94 | - string $password_hash, |
|
| 95 | - int $id_auteur |
|
| 96 | - ): bool { |
|
| 97 | - if (empty($backup)) { |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $sauvegarde = Chiffrement::dechiffrer($backup, $password_clair); |
|
| 102 | - $json = json_decode($sauvegarde, true, 512, JSON_THROW_ON_ERROR); |
|
| 103 | - if (!$json) { |
|
| 104 | - return false; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - // cela semble une sauvegarde valide |
|
| 108 | - $cles_potentielles = array_map('base64_decode', $json); |
|
| 109 | - |
|
| 110 | - // il faut faire une double verif sur secret_des_auth |
|
| 111 | - // pour s'assurer qu'elle permet bien de decrypter le pass de l'auteur qui fournit la sauvegarde |
|
| 112 | - // et par extension tous les passwords |
|
| 113 | - if ( |
|
| 114 | - !empty($cles_potentielles['secret_des_auth']) |
|
| 115 | - && !Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth']) |
|
| 116 | - ) { |
|
| 117 | - spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 118 | - unset($cles_potentielles['secret_des_auth']); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // on merge les cles pour recuperer les cles manquantes |
|
| 122 | - $restauration = false; |
|
| 123 | - foreach ($cles_potentielles as $name => $key) { |
|
| 124 | - if (!$this->cles->has($name)) { |
|
| 125 | - $this->cles->set($name, $key); |
|
| 126 | - spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 127 | - $restauration = true; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - return $restauration; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - private function getKey(string $name, bool $autoInit): ?string { |
|
| 134 | - if ($this->cles->has($name)) { |
|
| 135 | - return $this->cles->get($name); |
|
| 136 | - } |
|
| 137 | - if ($autoInit) { |
|
| 138 | - $this->cles->generate($name); |
|
| 139 | - // si l'ecriture de fichier a bien marche on peut utiliser la cle |
|
| 140 | - if ($this->save()) { |
|
| 141 | - return $this->cles->get($name); |
|
| 142 | - } |
|
| 143 | - // sinon loger et annule la cle generee car il ne faut pas l'utiliser |
|
| 144 | - spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR); |
|
| 145 | - $this->cles->delete($name); |
|
| 146 | - } |
|
| 147 | - return null; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - private function getMetaKey(string $name, bool $autoInit = true): ?string { |
|
| 151 | - if (!isset($GLOBALS['meta'][$name])) { |
|
| 152 | - include_spip('base/abstract_sql'); |
|
| 153 | - $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string')); |
|
| 154 | - } |
|
| 155 | - $key = base64_decode($GLOBALS['meta'][$name] ?? ''); |
|
| 156 | - if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 157 | - return $key; |
|
| 158 | - } |
|
| 159 | - if (!$autoInit) { |
|
| 160 | - return null; |
|
| 161 | - } |
|
| 162 | - $key = Chiffrement::keygen(); |
|
| 163 | - ecrire_meta($name, base64_encode($key), 'non'); |
|
| 164 | - lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas |
|
| 165 | - |
|
| 166 | - return $key; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - private function read(): array { |
|
| 170 | - $json = null; |
|
| 171 | - lire_fichier_securise($this->file, $json); |
|
| 172 | - if ( |
|
| 173 | - $json |
|
| 174 | - && ($json = \json_decode($json, true, 512, JSON_THROW_ON_ERROR)) |
|
| 175 | - && is_array($json) |
|
| 176 | - ) { |
|
| 177 | - return array_map('base64_decode', $json); |
|
| 178 | - } |
|
| 179 | - return []; |
|
| 180 | - } |
|
| 16 | + private static array $instances = []; |
|
| 17 | + |
|
| 18 | + private string $file = _DIR_ETC . 'cles.php'; |
|
| 19 | + private readonly Cles $cles; |
|
| 20 | + |
|
| 21 | + public static function instance(string $file = ''): self { |
|
| 22 | + if (empty(self::$instances[$file])) { |
|
| 23 | + self::$instances[$file] = new self($file); |
|
| 24 | + } |
|
| 25 | + return self::$instances[$file]; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Retourne le secret du site (shorthand) |
|
| 30 | + * @uses self::getSecretSite() |
|
| 31 | + */ |
|
| 32 | + public static function secret_du_site(): ?string { |
|
| 33 | + return (self::instance())->getSecretSite(); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + private function __construct(string $file = '') { |
|
| 37 | + if ($file) { |
|
| 38 | + $this->file = $file; |
|
| 39 | + } |
|
| 40 | + $this->cles = new Cles($this->read()); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Renvoyer le secret du site |
|
| 45 | + * |
|
| 46 | + * Le secret du site doit rester aussi secret que possible, et est eternel |
|
| 47 | + * On ne doit pas l'exporter |
|
| 48 | + * |
|
| 49 | + * Le secret est partagé entre une clé disque et une clé bdd |
|
| 50 | + * |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + public function getSecretSite(bool $autoInit = true): ?string { |
|
| 54 | + $key = $this->getKey('secret_du_site', $autoInit); |
|
| 55 | + $meta = $this->getMetaKey('secret_du_site', $autoInit); |
|
| 56 | + // conserve la même longeur. |
|
| 57 | + return $key ^ $meta; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** Renvoyer le secret des authentifications */ |
|
| 61 | + public function getSecretAuth(bool $autoInit = false): ?string { |
|
| 62 | + return $this->getKey('secret_des_auth', $autoInit); |
|
| 63 | + } |
|
| 64 | + public function save(): bool { |
|
| 65 | + return ecrire_fichier_securise($this->file, $this->cles->toJson()); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Fournir une sauvegarde chiffree des cles (a l'aide d'une autre clé, comme le pass d'un auteur) |
|
| 70 | + * |
|
| 71 | + * @param string $withKey Clé de chiffrage de la sauvegarde |
|
| 72 | + * @return string Contenu de la sauvegarde chiffrée générée |
|
| 73 | + */ |
|
| 74 | + public function backup( |
|
| 75 | + #[\SensitiveParameter] |
|
| 76 | + string $withKey |
|
| 77 | + ): string { |
|
| 78 | + if (count($this->cles)) { |
|
| 79 | + return Chiffrement::chiffrer($this->cles->toJson(), $withKey); |
|
| 80 | + } |
|
| 81 | + return ''; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Restaurer les cles manquantes depuis une sauvegarde chiffree des cles |
|
| 86 | + * (si la sauvegarde est bien valide) |
|
| 87 | + */ |
|
| 88 | + public function restore( |
|
| 89 | + /** Sauvegarde chiffrée (générée par backup()) */ |
|
| 90 | + string $backup, |
|
| 91 | + #[\SensitiveParameter] |
|
| 92 | + string $password_clair, |
|
| 93 | + #[\SensitiveParameter] |
|
| 94 | + string $password_hash, |
|
| 95 | + int $id_auteur |
|
| 96 | + ): bool { |
|
| 97 | + if (empty($backup)) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $sauvegarde = Chiffrement::dechiffrer($backup, $password_clair); |
|
| 102 | + $json = json_decode($sauvegarde, true, 512, JSON_THROW_ON_ERROR); |
|
| 103 | + if (!$json) { |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + // cela semble une sauvegarde valide |
|
| 108 | + $cles_potentielles = array_map('base64_decode', $json); |
|
| 109 | + |
|
| 110 | + // il faut faire une double verif sur secret_des_auth |
|
| 111 | + // pour s'assurer qu'elle permet bien de decrypter le pass de l'auteur qui fournit la sauvegarde |
|
| 112 | + // et par extension tous les passwords |
|
| 113 | + if ( |
|
| 114 | + !empty($cles_potentielles['secret_des_auth']) |
|
| 115 | + && !Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth']) |
|
| 116 | + ) { |
|
| 117 | + spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 118 | + unset($cles_potentielles['secret_des_auth']); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // on merge les cles pour recuperer les cles manquantes |
|
| 122 | + $restauration = false; |
|
| 123 | + foreach ($cles_potentielles as $name => $key) { |
|
| 124 | + if (!$this->cles->has($name)) { |
|
| 125 | + $this->cles->set($name, $key); |
|
| 126 | + spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 127 | + $restauration = true; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + return $restauration; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + private function getKey(string $name, bool $autoInit): ?string { |
|
| 134 | + if ($this->cles->has($name)) { |
|
| 135 | + return $this->cles->get($name); |
|
| 136 | + } |
|
| 137 | + if ($autoInit) { |
|
| 138 | + $this->cles->generate($name); |
|
| 139 | + // si l'ecriture de fichier a bien marche on peut utiliser la cle |
|
| 140 | + if ($this->save()) { |
|
| 141 | + return $this->cles->get($name); |
|
| 142 | + } |
|
| 143 | + // sinon loger et annule la cle generee car il ne faut pas l'utiliser |
|
| 144 | + spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR); |
|
| 145 | + $this->cles->delete($name); |
|
| 146 | + } |
|
| 147 | + return null; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + private function getMetaKey(string $name, bool $autoInit = true): ?string { |
|
| 151 | + if (!isset($GLOBALS['meta'][$name])) { |
|
| 152 | + include_spip('base/abstract_sql'); |
|
| 153 | + $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string')); |
|
| 154 | + } |
|
| 155 | + $key = base64_decode($GLOBALS['meta'][$name] ?? ''); |
|
| 156 | + if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 157 | + return $key; |
|
| 158 | + } |
|
| 159 | + if (!$autoInit) { |
|
| 160 | + return null; |
|
| 161 | + } |
|
| 162 | + $key = Chiffrement::keygen(); |
|
| 163 | + ecrire_meta($name, base64_encode($key), 'non'); |
|
| 164 | + lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas |
|
| 165 | + |
|
| 166 | + return $key; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + private function read(): array { |
|
| 170 | + $json = null; |
|
| 171 | + lire_fichier_securise($this->file, $json); |
|
| 172 | + if ( |
|
| 173 | + $json |
|
| 174 | + && ($json = \json_decode($json, true, 512, JSON_THROW_ON_ERROR)) |
|
| 175 | + && is_array($json) |
|
| 176 | + ) { |
|
| 177 | + return array_map('base64_decode', $json); |
|
| 178 | + } |
|
| 179 | + return []; |
|
| 180 | + } |
|
| 181 | 181 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | final class SpipCles { |
| 16 | 16 | private static array $instances = []; |
| 17 | 17 | |
| 18 | - private string $file = _DIR_ETC . 'cles.php'; |
|
| 18 | + private string $file = _DIR_ETC.'cles.php'; |
|
| 19 | 19 | private readonly Cles $cles; |
| 20 | 20 | |
| 21 | 21 | public static function instance(string $file = ''): self { |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | !empty($cles_potentielles['secret_des_auth']) |
| 115 | 115 | && !Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth']) |
| 116 | 116 | ) { |
| 117 | - spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 117 | + spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer'._LOG_INFO_IMPORTANTE); |
|
| 118 | 118 | unset($cles_potentielles['secret_des_auth']); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | foreach ($cles_potentielles as $name => $key) { |
| 124 | 124 | if (!$this->cles->has($name)) { |
| 125 | 125 | $this->cles->set($name, $key); |
| 126 | - spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 126 | + spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer'._LOG_INFO_IMPORTANTE); |
|
| 127 | 127 | $restauration = true; |
| 128 | 128 | } |
| 129 | 129 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | return $this->cles->get($name); |
| 142 | 142 | } |
| 143 | 143 | // sinon loger et annule la cle generee car il ne faut pas l'utiliser |
| 144 | - spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR); |
|
| 144 | + spip_log('Echec ecriture du fichier cle '.$this->file." ; impossible de generer une cle $name", 'chiffrer'._LOG_ERREUR); |
|
| 145 | 145 | $this->cles->delete($name); |
| 146 | 146 | } |
| 147 | 147 | return null; |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | private function getMetaKey(string $name, bool $autoInit = true): ?string { |
| 151 | 151 | if (!isset($GLOBALS['meta'][$name])) { |
| 152 | 152 | include_spip('base/abstract_sql'); |
| 153 | - $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string')); |
|
| 153 | + $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = '.sql_quote($name, '', 'string')); |
|
| 154 | 154 | } |
| 155 | 155 | $key = base64_decode($GLOBALS['meta'][$name] ?? ''); |
| 156 | 156 | if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
@@ -7,33 +7,33 @@ |
||
| 7 | 7 | * @internal |
| 8 | 8 | */ |
| 9 | 9 | final class ErrorHandler { |
| 10 | - static bool $done = false; |
|
| 10 | + static bool $done = false; |
|
| 11 | 11 | |
| 12 | - public static function setup(?int $error_level = null): void { |
|
| 13 | - if (!self::$done) { |
|
| 14 | - self::$done = true; |
|
| 15 | - error_reporting($error_level); |
|
| 16 | - set_error_handler(self::user_deprecated(...), E_USER_DEPRECATED); |
|
| 17 | - } |
|
| 18 | - } |
|
| 12 | + public static function setup(?int $error_level = null): void { |
|
| 13 | + if (!self::$done) { |
|
| 14 | + self::$done = true; |
|
| 15 | + error_reporting($error_level); |
|
| 16 | + set_error_handler(self::user_deprecated(...), E_USER_DEPRECATED); |
|
| 17 | + } |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - /** Loger les `trigger_deprecated()` */ |
|
| 21 | - private static function user_deprecated(int $errno, string $errstr, string $errfile, int $errline): bool { |
|
| 22 | - if (!(\E_USER_DEPRECATED & $errno)) { |
|
| 23 | - return false; |
|
| 24 | - } |
|
| 20 | + /** Loger les `trigger_deprecated()` */ |
|
| 21 | + private static function user_deprecated(int $errno, string $errstr, string $errfile, int $errline): bool { |
|
| 22 | + if (!(\E_USER_DEPRECATED & $errno)) { |
|
| 23 | + return false; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - $backtrace = debug_backtrace(); |
|
| 27 | - array_shift($backtrace); |
|
| 28 | - do { |
|
| 29 | - $t = array_shift($backtrace); |
|
| 30 | - $fqdn = ($t['class'] ?? '') . ($t['type'] ?? '') . ($t['function'] ?? ''); |
|
| 31 | - } while (in_array($fqdn, ['trigger_error', 'trigger_deprecation'])); |
|
| 26 | + $backtrace = debug_backtrace(); |
|
| 27 | + array_shift($backtrace); |
|
| 28 | + do { |
|
| 29 | + $t = array_shift($backtrace); |
|
| 30 | + $fqdn = ($t['class'] ?? '') . ($t['type'] ?? '') . ($t['function'] ?? ''); |
|
| 31 | + } while (in_array($fqdn, ['trigger_error', 'trigger_deprecation'])); |
|
| 32 | 32 | |
| 33 | - $errfile = $t['file']; |
|
| 34 | - $errline = $t['line']; |
|
| 33 | + $errfile = $t['file']; |
|
| 34 | + $errline = $t['line']; |
|
| 35 | 35 | |
| 36 | - spip_log(sprintf('%s in %s on line %s', $errstr, $errfile, $errline), 'deprecated.' . _LOG_INFO); |
|
| 37 | - return false; |
|
| 38 | - } |
|
| 36 | + spip_log(sprintf('%s in %s on line %s', $errstr, $errfile, $errline), 'deprecated.' . _LOG_INFO); |
|
| 37 | + return false; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -27,13 +27,13 @@ |
||
| 27 | 27 | array_shift($backtrace); |
| 28 | 28 | do { |
| 29 | 29 | $t = array_shift($backtrace); |
| 30 | - $fqdn = ($t['class'] ?? '') . ($t['type'] ?? '') . ($t['function'] ?? ''); |
|
| 30 | + $fqdn = ($t['class'] ?? '').($t['type'] ?? '').($t['function'] ?? ''); |
|
| 31 | 31 | } while (in_array($fqdn, ['trigger_error', 'trigger_deprecation'])); |
| 32 | 32 | |
| 33 | 33 | $errfile = $t['file']; |
| 34 | 34 | $errline = $t['line']; |
| 35 | 35 | |
| 36 | - spip_log(sprintf('%s in %s on line %s', $errstr, $errfile, $errline), 'deprecated.' . _LOG_INFO); |
|
| 36 | + spip_log(sprintf('%s in %s on line %s', $errstr, $errfile, $errline), 'deprecated.'._LOG_INFO); |
|
| 37 | 37 | return false; |
| 38 | 38 | } |
| 39 | 39 | } |
@@ -17,210 +17,210 @@ |
||
| 17 | 17 | * @see extraire_balises() |
| 18 | 18 | */ |
| 19 | 19 | class HtmlTag extends AbstractCollecteur { |
| 20 | - protected static string $markPrefix = 'HTMLTAG'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * La preg pour découper et collecter les modèles |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - protected string $preg_openingtag; |
|
| 27 | - protected string $preg_closingtag; |
|
| 28 | - protected string $tag; |
|
| 29 | - |
|
| 30 | - public static array $listeBalisesAProteger = ['html', 'pre', 'code', 'cadre', 'frame', 'script', 'style']; |
|
| 31 | - |
|
| 32 | - public function __construct(string $tag, ?string $preg_openingtag = null, ?string $preg_closingtag = null) { |
|
| 33 | - |
|
| 34 | - $tag = strtolower($tag); |
|
| 35 | - $this->tag = $tag; |
|
| 36 | - $this->preg_openingtag = ($preg_openingtag ?: "@<{$tag}\b([^>]*?)(/?)>@isS"); |
|
| 37 | - $this->preg_closingtag = ($preg_closingtag ?? "@</{$tag}\b[^>]*>@isS"); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @param string $texte |
|
| 42 | - * @param array $options |
|
| 43 | - * bool $detecter_presence |
|
| 44 | - * bool $nb_max |
|
| 45 | - * int $profondeur |
|
| 46 | - * @return array |
|
| 47 | - */ |
|
| 48 | - public function collecter(string $texte, array $options = []): array { |
|
| 49 | - if (!$texte) { |
|
| 50 | - return []; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - $upperTag = strtoupper($this->tag); |
|
| 54 | - $hasUpperCaseTags = ($upperTag !== $this->tag && (str_contains($texte, '<' . $upperTag) || str_contains($texte, '</' . $upperTag))); |
|
| 55 | - |
|
| 56 | - // collecter les balises ouvrantes |
|
| 57 | - $opening = static::collecteur($texte, '', $hasUpperCaseTags ? '<' : '<' . $this->tag, $this->preg_openingtag, empty($options['detecter_presence']) ? 0 : 1); |
|
| 58 | - if (!$opening) { |
|
| 59 | - return []; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // si c'est un tag autofermant ou vide qui se repère avec une seule regexp, on va plus vite |
|
| 63 | - if (!$this->preg_closingtag) { |
|
| 64 | - return $opening; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // collecter les balises fermantes |
|
| 68 | - $closing = static::collecteur($texte, '', $hasUpperCaseTags ? '</' : '</' . $this->tag, $this->preg_closingtag); |
|
| 69 | - |
|
| 70 | - $profondeur = ($options['profondeur'] ?? 1); |
|
| 71 | - $tags = []; |
|
| 72 | - while (!empty($opening)) { |
|
| 73 | - $first_opening = array_shift($opening); |
|
| 74 | - // self closing ? |
|
| 75 | - if (str_contains($first_opening['raw'], '/>')) { |
|
| 76 | - $tag = $first_opening; |
|
| 77 | - $tag['opening'] = $tag['raw']; |
|
| 78 | - $tag['closing'] = ''; |
|
| 79 | - $tag['innerHtml'] = ''; |
|
| 80 | - $tag['attributs'] = trim(substr($tag['opening'], strlen($this->tag) + 1, -2)); |
|
| 81 | - $tags[] = $tag; |
|
| 82 | - } |
|
| 83 | - else { |
|
| 84 | - // enlever les closing qui sont avant le premier opening, car ils n'ont pas de sens |
|
| 85 | - while ( |
|
| 86 | - !empty($closing) |
|
| 87 | - && ($first_closing = reset($closing)) |
|
| 88 | - && $first_closing['pos'] < $first_opening['pos'] |
|
| 89 | - ) { |
|
| 90 | - array_shift($closing); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $need_closing = 0; |
|
| 94 | - $next_closing = reset($closing); |
|
| 95 | - $next_opening = reset($opening); |
|
| 96 | - // certaines balises comme <code> neutralisent le contenant, donc tout ce qui est avant le prochain closing doit etre ignoré |
|
| 97 | - if (in_array($this->tag, ['code'])) { |
|
| 98 | - while ($next_opening && $next_closing && $next_opening['pos'] < $next_closing['pos']) { |
|
| 99 | - array_shift($opening); |
|
| 100 | - $next_opening = reset($opening); |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - else { |
|
| 104 | - while ($next_opening && $next_closing && $next_opening['pos'] < $next_closing['pos']) { |
|
| 105 | - while ($next_opening && $next_opening['pos'] < $next_closing['pos']) { |
|
| 106 | - // si pas self closing, il faut un closing de plus |
|
| 107 | - if (!str_contains($next_opening['raw'], '/>')) { |
|
| 108 | - $need_closing++; |
|
| 109 | - } |
|
| 110 | - array_shift($opening); |
|
| 111 | - $next_opening = reset($opening); |
|
| 112 | - } |
|
| 113 | - // il faut depiler les balises fermantes autant de fois que nécessaire et tant qu'on a pas une nouvelle balise ouvrante |
|
| 114 | - while ($need_closing && $next_closing && (!$next_opening || $next_closing['pos'] < $next_opening['pos'])) { |
|
| 115 | - array_shift($closing); |
|
| 116 | - $need_closing--; |
|
| 117 | - $next_closing = reset($closing); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - // si pas de fermeture, c'est une autofermante mal fermée... |
|
| 122 | - if (!$next_closing || $need_closing) { |
|
| 123 | - $tag = $first_opening; |
|
| 124 | - $tag['opening'] = $tag['raw']; |
|
| 125 | - $tag['closing'] = ''; |
|
| 126 | - $tag['innerHtml'] = ''; |
|
| 127 | - $tag['attributs'] = trim(substr($tag['opening'], strlen($this->tag) + 1, -1)); |
|
| 128 | - $tags[] = $tag; |
|
| 129 | - } |
|
| 130 | - else { |
|
| 131 | - $tag = $first_opening; |
|
| 132 | - $next_closing = array_shift($closing); |
|
| 133 | - $innerHtml = substr($texte, $tag['pos'] + $tag['length'], $next_closing['pos'] - $tag['pos'] - $tag['length']); |
|
| 134 | - $tag['length'] = $next_closing['pos'] - $tag['pos'] + $next_closing['length']; |
|
| 135 | - $tag['opening'] = $tag['raw']; |
|
| 136 | - $tag['raw'] = substr($texte, $tag['pos'], $tag['length']); |
|
| 137 | - $tag['innerHtml'] = $innerHtml; |
|
| 138 | - $tag['closing'] = $next_closing['raw']; |
|
| 139 | - $tag['attributs'] = trim(substr($tag['opening'], strlen($this->tag) + 1, -1)); |
|
| 140 | - $tags[] = $tag; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - if ((!empty($options['detecter_presence']) && count($tags))) { |
|
| 144 | - return $tags; |
|
| 145 | - } |
|
| 146 | - if (($profondeur == 1 && !empty($options['nb_max']) && count($tags) >= $options['nb_max'])) { |
|
| 147 | - break; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - while (--$profondeur > 0) { |
|
| 152 | - $outerTags = $tags; |
|
| 153 | - $tags = []; |
|
| 154 | - $options['profondeur'] = 1; |
|
| 155 | - foreach ($outerTags as $outerTag) { |
|
| 156 | - if (!empty($outerTag['innerHtml'])) { |
|
| 157 | - $offsetPos = $outerTag['pos'] + strlen($outerTag['opening']); |
|
| 158 | - $innerTags = $this->collecter($outerTag['innerHtml'], $options); |
|
| 159 | - if (!empty($innerTags)) { |
|
| 160 | - foreach ($innerTags as $tag) { |
|
| 161 | - $tag['pos'] += $offsetPos; |
|
| 162 | - $tags[] = $tag; |
|
| 163 | - } |
|
| 164 | - if (($profondeur == 1 && !empty($options['nb_max']) && count($tags) >= $options['nb_max'])) { |
|
| 165 | - return $tags; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - return $tags; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param callable|null $callback_function |
|
| 178 | - */ |
|
| 179 | - public function echapper_enHtmlBase64(string $texte, string $source = '', $callback_function = null, array $callback_options = []): string { |
|
| 180 | - if ($callback_function) { |
|
| 181 | - $legacy_callback = $callback_function; |
|
| 182 | - // si on est dans un cas evident de preg perso, ne pas essayer de mapper le match car on ne sait pas ce qu'il contient |
|
| 183 | - // et on aura pas non plus de innerHtml si pas de preg_closingtag |
|
| 184 | - if ($this->preg_closingtag) { |
|
| 185 | - $tag = $this->tag; |
|
| 186 | - $legacy_callback = function ($c, $options) use ($tag, $callback_function) { |
|
| 187 | - // legacy : renseigner les infos correspondantes aux matchs de l'ancienne regexp |
|
| 188 | - $regs = [ |
|
| 189 | - 0 => $c['raw'], |
|
| 190 | - 1 => $tag, |
|
| 191 | - 2 => $c['match'][1] . $c['match'][2], |
|
| 192 | - 3 => $c['innerHtml'], |
|
| 193 | - 'tag' => $this->tag, |
|
| 194 | - ] + $c; |
|
| 195 | - return $callback_function($regs, $options); |
|
| 196 | - }; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - return parent::echapper_enHtmlBase64($texte, $source, $callback_function ? $legacy_callback : null, $callback_options); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * pour $source voir commentaire infra (echappe_retour) |
|
| 205 | - * pour $no_transform voir le filtre post_autobr dans inc/filtres |
|
| 206 | - */ |
|
| 207 | - public static function proteger_balisesHtml(string $texte, string $source = '', ?array $html_tags = null, array $callbacks_function = [], array $callback_options = []): string { |
|
| 208 | - if ($texte === '') { |
|
| 209 | - return ''; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $html_tags = $html_tags ?: self::$listeBalisesAProteger; |
|
| 213 | - |
|
| 214 | - $tags_todo = $html_tags; |
|
| 215 | - while ( |
|
| 216 | - !empty($tags_todo) |
|
| 217 | - && ($tag = array_shift($tags_todo)) |
|
| 218 | - && str_contains($texte, '<') |
|
| 219 | - ) { |
|
| 220 | - $htmlTagCollecteur = new self($tag); |
|
| 221 | - $texte = $htmlTagCollecteur->echapper_enHtmlBase64($texte, $source, $callbacks_function[$tag] ?? null, $callback_options); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - return $texte; |
|
| 225 | - } |
|
| 20 | + protected static string $markPrefix = 'HTMLTAG'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * La preg pour découper et collecter les modèles |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + protected string $preg_openingtag; |
|
| 27 | + protected string $preg_closingtag; |
|
| 28 | + protected string $tag; |
|
| 29 | + |
|
| 30 | + public static array $listeBalisesAProteger = ['html', 'pre', 'code', 'cadre', 'frame', 'script', 'style']; |
|
| 31 | + |
|
| 32 | + public function __construct(string $tag, ?string $preg_openingtag = null, ?string $preg_closingtag = null) { |
|
| 33 | + |
|
| 34 | + $tag = strtolower($tag); |
|
| 35 | + $this->tag = $tag; |
|
| 36 | + $this->preg_openingtag = ($preg_openingtag ?: "@<{$tag}\b([^>]*?)(/?)>@isS"); |
|
| 37 | + $this->preg_closingtag = ($preg_closingtag ?? "@</{$tag}\b[^>]*>@isS"); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @param string $texte |
|
| 42 | + * @param array $options |
|
| 43 | + * bool $detecter_presence |
|
| 44 | + * bool $nb_max |
|
| 45 | + * int $profondeur |
|
| 46 | + * @return array |
|
| 47 | + */ |
|
| 48 | + public function collecter(string $texte, array $options = []): array { |
|
| 49 | + if (!$texte) { |
|
| 50 | + return []; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + $upperTag = strtoupper($this->tag); |
|
| 54 | + $hasUpperCaseTags = ($upperTag !== $this->tag && (str_contains($texte, '<' . $upperTag) || str_contains($texte, '</' . $upperTag))); |
|
| 55 | + |
|
| 56 | + // collecter les balises ouvrantes |
|
| 57 | + $opening = static::collecteur($texte, '', $hasUpperCaseTags ? '<' : '<' . $this->tag, $this->preg_openingtag, empty($options['detecter_presence']) ? 0 : 1); |
|
| 58 | + if (!$opening) { |
|
| 59 | + return []; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // si c'est un tag autofermant ou vide qui se repère avec une seule regexp, on va plus vite |
|
| 63 | + if (!$this->preg_closingtag) { |
|
| 64 | + return $opening; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // collecter les balises fermantes |
|
| 68 | + $closing = static::collecteur($texte, '', $hasUpperCaseTags ? '</' : '</' . $this->tag, $this->preg_closingtag); |
|
| 69 | + |
|
| 70 | + $profondeur = ($options['profondeur'] ?? 1); |
|
| 71 | + $tags = []; |
|
| 72 | + while (!empty($opening)) { |
|
| 73 | + $first_opening = array_shift($opening); |
|
| 74 | + // self closing ? |
|
| 75 | + if (str_contains($first_opening['raw'], '/>')) { |
|
| 76 | + $tag = $first_opening; |
|
| 77 | + $tag['opening'] = $tag['raw']; |
|
| 78 | + $tag['closing'] = ''; |
|
| 79 | + $tag['innerHtml'] = ''; |
|
| 80 | + $tag['attributs'] = trim(substr($tag['opening'], strlen($this->tag) + 1, -2)); |
|
| 81 | + $tags[] = $tag; |
|
| 82 | + } |
|
| 83 | + else { |
|
| 84 | + // enlever les closing qui sont avant le premier opening, car ils n'ont pas de sens |
|
| 85 | + while ( |
|
| 86 | + !empty($closing) |
|
| 87 | + && ($first_closing = reset($closing)) |
|
| 88 | + && $first_closing['pos'] < $first_opening['pos'] |
|
| 89 | + ) { |
|
| 90 | + array_shift($closing); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $need_closing = 0; |
|
| 94 | + $next_closing = reset($closing); |
|
| 95 | + $next_opening = reset($opening); |
|
| 96 | + // certaines balises comme <code> neutralisent le contenant, donc tout ce qui est avant le prochain closing doit etre ignoré |
|
| 97 | + if (in_array($this->tag, ['code'])) { |
|
| 98 | + while ($next_opening && $next_closing && $next_opening['pos'] < $next_closing['pos']) { |
|
| 99 | + array_shift($opening); |
|
| 100 | + $next_opening = reset($opening); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + else { |
|
| 104 | + while ($next_opening && $next_closing && $next_opening['pos'] < $next_closing['pos']) { |
|
| 105 | + while ($next_opening && $next_opening['pos'] < $next_closing['pos']) { |
|
| 106 | + // si pas self closing, il faut un closing de plus |
|
| 107 | + if (!str_contains($next_opening['raw'], '/>')) { |
|
| 108 | + $need_closing++; |
|
| 109 | + } |
|
| 110 | + array_shift($opening); |
|
| 111 | + $next_opening = reset($opening); |
|
| 112 | + } |
|
| 113 | + // il faut depiler les balises fermantes autant de fois que nécessaire et tant qu'on a pas une nouvelle balise ouvrante |
|
| 114 | + while ($need_closing && $next_closing && (!$next_opening || $next_closing['pos'] < $next_opening['pos'])) { |
|
| 115 | + array_shift($closing); |
|
| 116 | + $need_closing--; |
|
| 117 | + $next_closing = reset($closing); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + // si pas de fermeture, c'est une autofermante mal fermée... |
|
| 122 | + if (!$next_closing || $need_closing) { |
|
| 123 | + $tag = $first_opening; |
|
| 124 | + $tag['opening'] = $tag['raw']; |
|
| 125 | + $tag['closing'] = ''; |
|
| 126 | + $tag['innerHtml'] = ''; |
|
| 127 | + $tag['attributs'] = trim(substr($tag['opening'], strlen($this->tag) + 1, -1)); |
|
| 128 | + $tags[] = $tag; |
|
| 129 | + } |
|
| 130 | + else { |
|
| 131 | + $tag = $first_opening; |
|
| 132 | + $next_closing = array_shift($closing); |
|
| 133 | + $innerHtml = substr($texte, $tag['pos'] + $tag['length'], $next_closing['pos'] - $tag['pos'] - $tag['length']); |
|
| 134 | + $tag['length'] = $next_closing['pos'] - $tag['pos'] + $next_closing['length']; |
|
| 135 | + $tag['opening'] = $tag['raw']; |
|
| 136 | + $tag['raw'] = substr($texte, $tag['pos'], $tag['length']); |
|
| 137 | + $tag['innerHtml'] = $innerHtml; |
|
| 138 | + $tag['closing'] = $next_closing['raw']; |
|
| 139 | + $tag['attributs'] = trim(substr($tag['opening'], strlen($this->tag) + 1, -1)); |
|
| 140 | + $tags[] = $tag; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + if ((!empty($options['detecter_presence']) && count($tags))) { |
|
| 144 | + return $tags; |
|
| 145 | + } |
|
| 146 | + if (($profondeur == 1 && !empty($options['nb_max']) && count($tags) >= $options['nb_max'])) { |
|
| 147 | + break; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + while (--$profondeur > 0) { |
|
| 152 | + $outerTags = $tags; |
|
| 153 | + $tags = []; |
|
| 154 | + $options['profondeur'] = 1; |
|
| 155 | + foreach ($outerTags as $outerTag) { |
|
| 156 | + if (!empty($outerTag['innerHtml'])) { |
|
| 157 | + $offsetPos = $outerTag['pos'] + strlen($outerTag['opening']); |
|
| 158 | + $innerTags = $this->collecter($outerTag['innerHtml'], $options); |
|
| 159 | + if (!empty($innerTags)) { |
|
| 160 | + foreach ($innerTags as $tag) { |
|
| 161 | + $tag['pos'] += $offsetPos; |
|
| 162 | + $tags[] = $tag; |
|
| 163 | + } |
|
| 164 | + if (($profondeur == 1 && !empty($options['nb_max']) && count($tags) >= $options['nb_max'])) { |
|
| 165 | + return $tags; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + return $tags; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param callable|null $callback_function |
|
| 178 | + */ |
|
| 179 | + public function echapper_enHtmlBase64(string $texte, string $source = '', $callback_function = null, array $callback_options = []): string { |
|
| 180 | + if ($callback_function) { |
|
| 181 | + $legacy_callback = $callback_function; |
|
| 182 | + // si on est dans un cas evident de preg perso, ne pas essayer de mapper le match car on ne sait pas ce qu'il contient |
|
| 183 | + // et on aura pas non plus de innerHtml si pas de preg_closingtag |
|
| 184 | + if ($this->preg_closingtag) { |
|
| 185 | + $tag = $this->tag; |
|
| 186 | + $legacy_callback = function ($c, $options) use ($tag, $callback_function) { |
|
| 187 | + // legacy : renseigner les infos correspondantes aux matchs de l'ancienne regexp |
|
| 188 | + $regs = [ |
|
| 189 | + 0 => $c['raw'], |
|
| 190 | + 1 => $tag, |
|
| 191 | + 2 => $c['match'][1] . $c['match'][2], |
|
| 192 | + 3 => $c['innerHtml'], |
|
| 193 | + 'tag' => $this->tag, |
|
| 194 | + ] + $c; |
|
| 195 | + return $callback_function($regs, $options); |
|
| 196 | + }; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + return parent::echapper_enHtmlBase64($texte, $source, $callback_function ? $legacy_callback : null, $callback_options); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * pour $source voir commentaire infra (echappe_retour) |
|
| 205 | + * pour $no_transform voir le filtre post_autobr dans inc/filtres |
|
| 206 | + */ |
|
| 207 | + public static function proteger_balisesHtml(string $texte, string $source = '', ?array $html_tags = null, array $callbacks_function = [], array $callback_options = []): string { |
|
| 208 | + if ($texte === '') { |
|
| 209 | + return ''; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $html_tags = $html_tags ?: self::$listeBalisesAProteger; |
|
| 213 | + |
|
| 214 | + $tags_todo = $html_tags; |
|
| 215 | + while ( |
|
| 216 | + !empty($tags_todo) |
|
| 217 | + && ($tag = array_shift($tags_todo)) |
|
| 218 | + && str_contains($texte, '<') |
|
| 219 | + ) { |
|
| 220 | + $htmlTagCollecteur = new self($tag); |
|
| 221 | + $texte = $htmlTagCollecteur->echapper_enHtmlBase64($texte, $source, $callbacks_function[$tag] ?? null, $callback_options); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + return $texte; |
|
| 225 | + } |
|
| 226 | 226 | } |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $upperTag = strtoupper($this->tag); |
| 54 | - $hasUpperCaseTags = ($upperTag !== $this->tag && (str_contains($texte, '<' . $upperTag) || str_contains($texte, '</' . $upperTag))); |
|
| 54 | + $hasUpperCaseTags = ($upperTag !== $this->tag && (str_contains($texte, '<'.$upperTag) || str_contains($texte, '</'.$upperTag))); |
|
| 55 | 55 | |
| 56 | 56 | // collecter les balises ouvrantes |
| 57 | - $opening = static::collecteur($texte, '', $hasUpperCaseTags ? '<' : '<' . $this->tag, $this->preg_openingtag, empty($options['detecter_presence']) ? 0 : 1); |
|
| 57 | + $opening = static::collecteur($texte, '', $hasUpperCaseTags ? '<' : '<'.$this->tag, $this->preg_openingtag, empty($options['detecter_presence']) ? 0 : 1); |
|
| 58 | 58 | if (!$opening) { |
| 59 | 59 | return []; |
| 60 | 60 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // collecter les balises fermantes |
| 68 | - $closing = static::collecteur($texte, '', $hasUpperCaseTags ? '</' : '</' . $this->tag, $this->preg_closingtag); |
|
| 68 | + $closing = static::collecteur($texte, '', $hasUpperCaseTags ? '</' : '</'.$this->tag, $this->preg_closingtag); |
|
| 69 | 69 | |
| 70 | 70 | $profondeur = ($options['profondeur'] ?? 1); |
| 71 | 71 | $tags = []; |
@@ -183,12 +183,12 @@ discard block |
||
| 183 | 183 | // et on aura pas non plus de innerHtml si pas de preg_closingtag |
| 184 | 184 | if ($this->preg_closingtag) { |
| 185 | 185 | $tag = $this->tag; |
| 186 | - $legacy_callback = function ($c, $options) use ($tag, $callback_function) { |
|
| 186 | + $legacy_callback = function($c, $options) use ($tag, $callback_function) { |
|
| 187 | 187 | // legacy : renseigner les infos correspondantes aux matchs de l'ancienne regexp |
| 188 | 188 | $regs = [ |
| 189 | 189 | 0 => $c['raw'], |
| 190 | 190 | 1 => $tag, |
| 191 | - 2 => $c['match'][1] . $c['match'][2], |
|
| 191 | + 2 => $c['match'][1].$c['match'][2], |
|
| 192 | 192 | 3 => $c['innerHtml'], |
| 193 | 193 | 'tag' => $this->tag, |
| 194 | 194 | ] + $c; |
@@ -79,8 +79,7 @@ discard block |
||
| 79 | 79 | $tag['innerHtml'] = ''; |
| 80 | 80 | $tag['attributs'] = trim(substr($tag['opening'], strlen($this->tag) + 1, -2)); |
| 81 | 81 | $tags[] = $tag; |
| 82 | - } |
|
| 83 | - else { |
|
| 82 | + } else { |
|
| 84 | 83 | // enlever les closing qui sont avant le premier opening, car ils n'ont pas de sens |
| 85 | 84 | while ( |
| 86 | 85 | !empty($closing) |
@@ -99,8 +98,7 @@ discard block |
||
| 99 | 98 | array_shift($opening); |
| 100 | 99 | $next_opening = reset($opening); |
| 101 | 100 | } |
| 102 | - } |
|
| 103 | - else { |
|
| 101 | + } else { |
|
| 104 | 102 | while ($next_opening && $next_closing && $next_opening['pos'] < $next_closing['pos']) { |
| 105 | 103 | while ($next_opening && $next_opening['pos'] < $next_closing['pos']) { |
| 106 | 104 | // si pas self closing, il faut un closing de plus |
@@ -126,8 +124,7 @@ discard block |
||
| 126 | 124 | $tag['innerHtml'] = ''; |
| 127 | 125 | $tag['attributs'] = trim(substr($tag['opening'], strlen($this->tag) + 1, -1)); |
| 128 | 126 | $tags[] = $tag; |
| 129 | - } |
|
| 130 | - else { |
|
| 127 | + } else { |
|
| 131 | 128 | $tag = $first_opening; |
| 132 | 129 | $next_closing = array_shift($closing); |
| 133 | 130 | $innerHtml = substr($texte, $tag['pos'] + $tag['length'], $next_closing['pos'] - $tag['pos'] - $tag['length']); |
@@ -12,60 +12,60 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class Factory |
| 14 | 14 | { |
| 15 | - public static function create($iterateur, $command, $info = null) { |
|
| 16 | - $iter = null; |
|
| 17 | - // cas des SI {si expression} analises tres tot |
|
| 18 | - // pour eviter le chargement de tout iterateur |
|
| 19 | - if (isset($command['si'])) { |
|
| 20 | - foreach ($command['si'] as $si) { |
|
| 21 | - if (!$si) { |
|
| 22 | - // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 23 | - // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 24 | - return new Decorator(new EmptyIterator(), [], $info); |
|
| 25 | - } |
|
| 26 | - } |
|
| 27 | - } |
|
| 15 | + public static function create($iterateur, $command, $info = null) { |
|
| 16 | + $iter = null; |
|
| 17 | + // cas des SI {si expression} analises tres tot |
|
| 18 | + // pour eviter le chargement de tout iterateur |
|
| 19 | + if (isset($command['si'])) { |
|
| 20 | + foreach ($command['si'] as $si) { |
|
| 21 | + if (!$si) { |
|
| 22 | + // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 23 | + // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 24 | + return new Decorator(new EmptyIterator(), [], $info); |
|
| 25 | + } |
|
| 26 | + } |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 30 | - // (il faudrait passer l'argument ->sql_serveur |
|
| 31 | - // pour etre certain qu'on est sur un "php:") |
|
| 32 | - if (class_exists($iterateur)) { |
|
| 33 | - $a = $command['args'] ?? []; |
|
| 29 | + // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 30 | + // (il faudrait passer l'argument ->sql_serveur |
|
| 31 | + // pour etre certain qu'on est sur un "php:") |
|
| 32 | + if (class_exists($iterateur)) { |
|
| 33 | + $a = $command['args'] ?? []; |
|
| 34 | 34 | |
| 35 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 36 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 37 | - if ((is_countable($a) ? count($a) : 0) == 1 && is_object($a[0]) && is_subclass_of($a[0], \Iterator::class)) { |
|
| 38 | - $iter = $a[0]; |
|
| 39 | - } else { |
|
| 40 | - // sinon, on cree un iterateur du type donne |
|
| 41 | - // arguments de creation de l'iterateur... |
|
| 42 | - try { |
|
| 43 | - $iter = new $iterateur(...$a); |
|
| 44 | - } catch (Exception $e) { |
|
| 45 | - spip_log("Erreur de chargement de l'iterateur {$iterateur}"); |
|
| 46 | - spip_log($e->getMessage()); |
|
| 47 | - $iter = new EmptyIterator(); |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - } else { |
|
| 51 | - // chercher la classe d'iterateur Iterateur/XXX |
|
| 52 | - // definie dans le fichier src/Compilateur/Iterateur/xxx.php |
|
| 53 | - // FIXME: déclarer quelque part les iterateurs supplémentaires |
|
| 54 | - $class = __NAMESPACE__ . '\\' . ucfirst(strtolower((string) $iterateur)); |
|
| 55 | - if (!class_exists($class)) { |
|
| 56 | - // historique |
|
| 57 | - // Chercher IterateurXXX |
|
| 58 | - include_spip('iterateur/' . strtolower($iterateur)); |
|
| 59 | - $class = 'Iterateur' . $iterateur; |
|
| 60 | - if (!class_exists($class)) { |
|
| 61 | - exit("Iterateur {$iterateur} non trouvé"); |
|
| 62 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 63 | - // $iter = new EmptyIterator(); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - $iter = new $class($command, $info); |
|
| 67 | - } |
|
| 35 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 36 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 37 | + if ((is_countable($a) ? count($a) : 0) == 1 && is_object($a[0]) && is_subclass_of($a[0], \Iterator::class)) { |
|
| 38 | + $iter = $a[0]; |
|
| 39 | + } else { |
|
| 40 | + // sinon, on cree un iterateur du type donne |
|
| 41 | + // arguments de creation de l'iterateur... |
|
| 42 | + try { |
|
| 43 | + $iter = new $iterateur(...$a); |
|
| 44 | + } catch (Exception $e) { |
|
| 45 | + spip_log("Erreur de chargement de l'iterateur {$iterateur}"); |
|
| 46 | + spip_log($e->getMessage()); |
|
| 47 | + $iter = new EmptyIterator(); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + } else { |
|
| 51 | + // chercher la classe d'iterateur Iterateur/XXX |
|
| 52 | + // definie dans le fichier src/Compilateur/Iterateur/xxx.php |
|
| 53 | + // FIXME: déclarer quelque part les iterateurs supplémentaires |
|
| 54 | + $class = __NAMESPACE__ . '\\' . ucfirst(strtolower((string) $iterateur)); |
|
| 55 | + if (!class_exists($class)) { |
|
| 56 | + // historique |
|
| 57 | + // Chercher IterateurXXX |
|
| 58 | + include_spip('iterateur/' . strtolower($iterateur)); |
|
| 59 | + $class = 'Iterateur' . $iterateur; |
|
| 60 | + if (!class_exists($class)) { |
|
| 61 | + exit("Iterateur {$iterateur} non trouvé"); |
|
| 62 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 63 | + // $iter = new EmptyIterator(); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + $iter = new $class($command, $info); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - return new Decorator($iter, $command, $info); |
|
| 70 | - } |
|
| 69 | + return new Decorator($iter, $command, $info); |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -51,12 +51,12 @@ |
||
| 51 | 51 | // chercher la classe d'iterateur Iterateur/XXX |
| 52 | 52 | // definie dans le fichier src/Compilateur/Iterateur/xxx.php |
| 53 | 53 | // FIXME: déclarer quelque part les iterateurs supplémentaires |
| 54 | - $class = __NAMESPACE__ . '\\' . ucfirst(strtolower((string) $iterateur)); |
|
| 54 | + $class = __NAMESPACE__.'\\'.ucfirst(strtolower((string) $iterateur)); |
|
| 55 | 55 | if (!class_exists($class)) { |
| 56 | 56 | // historique |
| 57 | 57 | // Chercher IterateurXXX |
| 58 | - include_spip('iterateur/' . strtolower($iterateur)); |
|
| 59 | - $class = 'Iterateur' . $iterateur; |
|
| 58 | + include_spip('iterateur/'.strtolower($iterateur)); |
|
| 59 | + $class = 'Iterateur'.$iterateur; |
|
| 60 | 60 | if (!class_exists($class)) { |
| 61 | 61 | exit("Iterateur {$iterateur} non trouvé"); |
| 62 | 62 | // si l'iterateur n'existe pas, on se rabat sur le generique |
@@ -11,187 +11,187 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Sql extends AbstractIterateur implements Iterator |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Ressource sql. |
|
| 16 | - * |
|
| 17 | - * @var bool|object |
|
| 18 | - */ |
|
| 19 | - protected $sqlresult = false; |
|
| 14 | + /** |
|
| 15 | + * Ressource sql. |
|
| 16 | + * |
|
| 17 | + * @var bool|object |
|
| 18 | + */ |
|
| 19 | + protected $sqlresult = false; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * row sql courante. |
|
| 23 | - * |
|
| 24 | - * @var null|array |
|
| 25 | - */ |
|
| 26 | - protected $row; |
|
| 21 | + /** |
|
| 22 | + * row sql courante. |
|
| 23 | + * |
|
| 24 | + * @var null|array |
|
| 25 | + */ |
|
| 26 | + protected $row; |
|
| 27 | 27 | |
| 28 | - protected bool $firstseek = false; |
|
| 28 | + protected bool $firstseek = false; |
|
| 29 | 29 | |
| 30 | - protected int $pos = -1; |
|
| 30 | + protected int $pos = -1; |
|
| 31 | 31 | |
| 32 | - /* |
|
| 32 | + /* |
|
| 33 | 33 | * array command: les commandes d'initialisation |
| 34 | 34 | * array info: les infos sur le squelette |
| 35 | 35 | */ |
| 36 | - public function __construct(array $command, array $info = []) { |
|
| 37 | - $this->type = 'SQL'; |
|
| 38 | - parent::__construct($command, $info); |
|
| 39 | - |
|
| 40 | - $this->select(); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Rembobiner. |
|
| 45 | - * |
|
| 46 | - * @return bool |
|
| 47 | - */ |
|
| 48 | - public function rewind(): void { |
|
| 49 | - if ($this->pos > 0) { |
|
| 50 | - $this->seek(0); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Verifier l'etat de l'iterateur. |
|
| 56 | - */ |
|
| 57 | - public function valid(): bool { |
|
| 58 | - if ($this->err) { |
|
| 59 | - return false; |
|
| 60 | - } |
|
| 61 | - if (!$this->firstseek) { |
|
| 62 | - $this->next(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return is_array($this->row); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Valeurs sur la position courante. |
|
| 70 | - * |
|
| 71 | - * @return array |
|
| 72 | - */ |
|
| 73 | - public function current(): ?array { |
|
| 74 | - return $this->row; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public function key(): int { |
|
| 78 | - return $this->pos; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Sauter a une position absolue. |
|
| 83 | - * |
|
| 84 | - * @param int $n |
|
| 85 | - * @param null|string $continue |
|
| 86 | - */ |
|
| 87 | - public function seek($n = 0, $continue = null): bool { |
|
| 88 | - if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 89 | - // SQLite ne sait pas seek(), il faut relancer la query |
|
| 90 | - // si la position courante est apres la position visee |
|
| 91 | - // il faut relancer la requete |
|
| 92 | - if ($this->pos > $n) { |
|
| 93 | - $this->free(); |
|
| 94 | - $this->select(); |
|
| 95 | - $this->valid(); |
|
| 96 | - } |
|
| 97 | - // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 98 | - // (sera fait en cas d'echec de cette fonction) |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 102 | - $this->pos = min($n, $this->count()); |
|
| 103 | - |
|
| 104 | - return true; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Avancer d'un cran. |
|
| 109 | - */ |
|
| 110 | - public function next(): void { |
|
| 111 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 112 | - ++$this->pos; |
|
| 113 | - $this->firstseek = true; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Avancer et retourner les donnees pour le nouvel element. |
|
| 118 | - * |
|
| 119 | - * @return null|array|bool |
|
| 120 | - */ |
|
| 121 | - public function fetch() { |
|
| 122 | - if ($this->valid()) { |
|
| 123 | - $r = $this->current(); |
|
| 124 | - $this->next(); |
|
| 125 | - } else { |
|
| 126 | - $r = false; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - return $r; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * liberer les ressources. |
|
| 134 | - * |
|
| 135 | - * @return bool |
|
| 136 | - */ |
|
| 137 | - public function free() { |
|
| 138 | - if (!$this->sqlresult) { |
|
| 139 | - return true; |
|
| 140 | - } |
|
| 141 | - $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 142 | - $this->sqlresult = null; |
|
| 143 | - |
|
| 144 | - return $a; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Compter le nombre de resultats. |
|
| 149 | - */ |
|
| 150 | - public function count(): int { |
|
| 151 | - if (is_null($this->total)) { |
|
| 152 | - if (!$this->sqlresult) { |
|
| 153 | - $this->total = 0; |
|
| 154 | - } else { |
|
| 155 | - // cas count(*) |
|
| 156 | - if (in_array('count(*)', $this->command['select'])) { |
|
| 157 | - $this->valid(); |
|
| 158 | - $s = $this->current(); |
|
| 159 | - $this->total = (int) $s['count(*)']; |
|
| 160 | - } else { |
|
| 161 | - $this->total = (int) sql_count($this->sqlresult, $this->command['connect']); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - return $this->total; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * selectionner les donnees, ie faire la requete SQL. |
|
| 171 | - */ |
|
| 172 | - protected function select() { |
|
| 173 | - $this->row = null; |
|
| 174 | - $v = &$this->command; |
|
| 175 | - $this->sqlresult = calculer_select( |
|
| 176 | - $v['select'], |
|
| 177 | - $v['from'], |
|
| 178 | - $v['type'], |
|
| 179 | - $v['where'], |
|
| 180 | - $v['join'], |
|
| 181 | - $v['groupby'], |
|
| 182 | - $v['orderby'], |
|
| 183 | - $v['limit'], |
|
| 184 | - $v['having'], |
|
| 185 | - $v['table'], |
|
| 186 | - $v['id'], |
|
| 187 | - $v['connect'], |
|
| 188 | - $this->info |
|
| 189 | - ); |
|
| 190 | - $this->err = !$this->sqlresult; |
|
| 191 | - $this->firstseek = false; |
|
| 192 | - $this->pos = -1; |
|
| 193 | - |
|
| 194 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 195 | - //$this->total = $this->count(); |
|
| 196 | - } |
|
| 36 | + public function __construct(array $command, array $info = []) { |
|
| 37 | + $this->type = 'SQL'; |
|
| 38 | + parent::__construct($command, $info); |
|
| 39 | + |
|
| 40 | + $this->select(); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Rembobiner. |
|
| 45 | + * |
|
| 46 | + * @return bool |
|
| 47 | + */ |
|
| 48 | + public function rewind(): void { |
|
| 49 | + if ($this->pos > 0) { |
|
| 50 | + $this->seek(0); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Verifier l'etat de l'iterateur. |
|
| 56 | + */ |
|
| 57 | + public function valid(): bool { |
|
| 58 | + if ($this->err) { |
|
| 59 | + return false; |
|
| 60 | + } |
|
| 61 | + if (!$this->firstseek) { |
|
| 62 | + $this->next(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return is_array($this->row); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Valeurs sur la position courante. |
|
| 70 | + * |
|
| 71 | + * @return array |
|
| 72 | + */ |
|
| 73 | + public function current(): ?array { |
|
| 74 | + return $this->row; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public function key(): int { |
|
| 78 | + return $this->pos; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Sauter a une position absolue. |
|
| 83 | + * |
|
| 84 | + * @param int $n |
|
| 85 | + * @param null|string $continue |
|
| 86 | + */ |
|
| 87 | + public function seek($n = 0, $continue = null): bool { |
|
| 88 | + if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 89 | + // SQLite ne sait pas seek(), il faut relancer la query |
|
| 90 | + // si la position courante est apres la position visee |
|
| 91 | + // il faut relancer la requete |
|
| 92 | + if ($this->pos > $n) { |
|
| 93 | + $this->free(); |
|
| 94 | + $this->select(); |
|
| 95 | + $this->valid(); |
|
| 96 | + } |
|
| 97 | + // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 98 | + // (sera fait en cas d'echec de cette fonction) |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 102 | + $this->pos = min($n, $this->count()); |
|
| 103 | + |
|
| 104 | + return true; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Avancer d'un cran. |
|
| 109 | + */ |
|
| 110 | + public function next(): void { |
|
| 111 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 112 | + ++$this->pos; |
|
| 113 | + $this->firstseek = true; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Avancer et retourner les donnees pour le nouvel element. |
|
| 118 | + * |
|
| 119 | + * @return null|array|bool |
|
| 120 | + */ |
|
| 121 | + public function fetch() { |
|
| 122 | + if ($this->valid()) { |
|
| 123 | + $r = $this->current(); |
|
| 124 | + $this->next(); |
|
| 125 | + } else { |
|
| 126 | + $r = false; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + return $r; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * liberer les ressources. |
|
| 134 | + * |
|
| 135 | + * @return bool |
|
| 136 | + */ |
|
| 137 | + public function free() { |
|
| 138 | + if (!$this->sqlresult) { |
|
| 139 | + return true; |
|
| 140 | + } |
|
| 141 | + $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 142 | + $this->sqlresult = null; |
|
| 143 | + |
|
| 144 | + return $a; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Compter le nombre de resultats. |
|
| 149 | + */ |
|
| 150 | + public function count(): int { |
|
| 151 | + if (is_null($this->total)) { |
|
| 152 | + if (!$this->sqlresult) { |
|
| 153 | + $this->total = 0; |
|
| 154 | + } else { |
|
| 155 | + // cas count(*) |
|
| 156 | + if (in_array('count(*)', $this->command['select'])) { |
|
| 157 | + $this->valid(); |
|
| 158 | + $s = $this->current(); |
|
| 159 | + $this->total = (int) $s['count(*)']; |
|
| 160 | + } else { |
|
| 161 | + $this->total = (int) sql_count($this->sqlresult, $this->command['connect']); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + return $this->total; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * selectionner les donnees, ie faire la requete SQL. |
|
| 171 | + */ |
|
| 172 | + protected function select() { |
|
| 173 | + $this->row = null; |
|
| 174 | + $v = &$this->command; |
|
| 175 | + $this->sqlresult = calculer_select( |
|
| 176 | + $v['select'], |
|
| 177 | + $v['from'], |
|
| 178 | + $v['type'], |
|
| 179 | + $v['where'], |
|
| 180 | + $v['join'], |
|
| 181 | + $v['groupby'], |
|
| 182 | + $v['orderby'], |
|
| 183 | + $v['limit'], |
|
| 184 | + $v['having'], |
|
| 185 | + $v['table'], |
|
| 186 | + $v['id'], |
|
| 187 | + $v['connect'], |
|
| 188 | + $this->info |
|
| 189 | + ); |
|
| 190 | + $this->err = !$this->sqlresult; |
|
| 191 | + $this->firstseek = false; |
|
| 192 | + $this->pos = -1; |
|
| 193 | + |
|
| 194 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 195 | + //$this->total = $this->count(); |
|
| 196 | + } |
|
| 197 | 197 | } |
@@ -7,368 +7,368 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Boucle |
| 9 | 9 | { |
| 10 | - /** Type de noeud */ |
|
| 11 | - public string $type = 'boucle'; |
|
| 12 | - |
|
| 13 | - /** Identifiant de la boucle */ |
|
| 14 | - public string $id_boucle; |
|
| 15 | - |
|
| 16 | - /** Identifiant de la boucle parente */ |
|
| 17 | - public string $id_parent = ''; |
|
| 18 | - |
|
| 19 | - /** Un nom explicite qui peut être affecté manuellement à certaines boucles générées */ |
|
| 20 | - public string $nom = ''; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Partie avant toujours affichee |
|
| 24 | - * |
|
| 25 | - * @var string|array |
|
| 26 | - */ |
|
| 27 | - public $preaff = ''; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Partie optionnelle avant |
|
| 31 | - * |
|
| 32 | - * @var string|array |
|
| 33 | - */ |
|
| 34 | - public $avant = ''; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Pour chaque élément |
|
| 38 | - * |
|
| 39 | - * @var string|array |
|
| 40 | - */ |
|
| 41 | - public $milieu = ''; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Partie optionnelle après |
|
| 45 | - * |
|
| 46 | - * @var string|array |
|
| 47 | - */ |
|
| 48 | - public $apres = ''; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Partie alternative, si pas de résultat dans la boucle |
|
| 52 | - * |
|
| 53 | - * @var string|array |
|
| 54 | - */ |
|
| 55 | - public $altern = ''; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Partie apres toujours affichee |
|
| 59 | - * |
|
| 60 | - * @var string|array |
|
| 61 | - */ |
|
| 62 | - public $postaff = ''; |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * La boucle doit-elle sélectionner la langue ? |
|
| 67 | - * |
|
| 68 | - * Valeurs : '', 'oui', 'non' |
|
| 69 | - */ |
|
| 70 | - public string $lang_select = ''; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 74 | - * |
|
| 75 | - * FIXME: un seul typage (string ?) |
|
| 76 | - * |
|
| 77 | - * @var string|false|null |
|
| 78 | - */ |
|
| 79 | - public $type_requete = null; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * La table est elle optionnelle ? |
|
| 83 | - * |
|
| 84 | - * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 85 | - */ |
|
| 86 | - public bool $table_optionnelle = false; |
|
| 87 | - public string $type_table_optionnelle = ''; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Nom du fichier de connexion |
|
| 91 | - */ |
|
| 92 | - public string $sql_serveur = ''; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Paramètres de la boucle |
|
| 96 | - * |
|
| 97 | - * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 98 | - * au calcul des critères |
|
| 99 | - * |
|
| 100 | - * FIXME: type unique. |
|
| 101 | - * @var false|array |
|
| 102 | - * - false: erreur de syntaxe |
|
| 103 | - */ |
|
| 104 | - public $param = []; |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Critères de la boucle |
|
| 108 | - * |
|
| 109 | - * FIXME: type array unique. |
|
| 110 | - * |
|
| 111 | - * @var string|Critere[] |
|
| 112 | - * - string: phrasage (code brut). Il reste si erreur de critère |
|
| 113 | - * - array: analyse correcte des critères... |
|
| 114 | - */ |
|
| 115 | - public $criteres = []; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 119 | - * |
|
| 120 | - * @var string[] |
|
| 121 | - */ |
|
| 122 | - public array $separateur = []; |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Liste des jointures possibles avec cette table |
|
| 126 | - * |
|
| 127 | - * Les jointures par défaut de la table sont complétées en priorité |
|
| 128 | - * des jointures déclarées explicitement sur la boucle |
|
| 129 | - * |
|
| 130 | - * @see base_trouver_table_dist() |
|
| 131 | - */ |
|
| 132 | - public array $jointures = []; |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Jointures explicites avec cette table |
|
| 136 | - * |
|
| 137 | - * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 138 | - * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 139 | - * à la boucle. |
|
| 140 | - * |
|
| 141 | - * @var string|bool |
|
| 142 | - */ |
|
| 143 | - public $jointures_explicites = false; |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 147 | - */ |
|
| 148 | - public string $doublons = ''; |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Code PHP ajouté au début de chaque itération de boucle. |
|
| 152 | - * |
|
| 153 | - * Utilisé entre autre par les critères {pagination}, {n-a,b}, {a/b}... |
|
| 154 | - */ |
|
| 155 | - public string $partie = ''; |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Nombre de divisions de la boucle, d'éléments à afficher, |
|
| 159 | - * ou de soustractions d'éléments à faire |
|
| 160 | - * |
|
| 161 | - * Dans les critères limitant le nombre d'éléments affichés |
|
| 162 | - * {a,b}, {a,n-b}, {a/b}, {pagination b}, b est affecté à total_parties. |
|
| 163 | - */ |
|
| 164 | - public string $total_parties = ''; |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Code PHP ajouté avant l'itération de boucle. |
|
| 168 | - * |
|
| 169 | - * Utilisé entre autre par les critères {pagination}, {a,b}, {a/b} |
|
| 170 | - * pour initialiser les variables de début et de fin d'itération. |
|
| 171 | - */ |
|
| 172 | - public string $mode_partie = ''; |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Identifiant d'une boucle qui appelle celle-ci de manière récursive |
|
| 176 | - * |
|
| 177 | - * Si une boucle est appelée de manière récursive quelque part par |
|
| 178 | - * une autre boucle comme <BOUCLE_rec(boucle_identifiant) />, cette |
|
| 179 | - * boucle (identifiant) reçoit dans cette propriété l'identifiant |
|
| 180 | - * de l'appelant (rec) |
|
| 181 | - */ |
|
| 182 | - public string $externe = ''; |
|
| 183 | - |
|
| 184 | - // champs pour la construction de la requete SQL |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Liste des champs à récupérer par la boucle |
|
| 188 | - * |
|
| 189 | - * Expression 'table.nom_champ' ou calculée 'nom_champ AS x' |
|
| 190 | - * |
|
| 191 | - * @var string[] |
|
| 192 | - */ |
|
| 193 | - public array $select = []; |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Liste des alias / tables SQL utilisées dans la boucle |
|
| 197 | - * |
|
| 198 | - * L'index est un identifiant (xx dans spip_xx assez souvent) qui servira |
|
| 199 | - * d'alias au nom de la table ; la valeur est le nom de la table SQL désirée. |
|
| 200 | - * |
|
| 201 | - * L'index 0 peut définir le type de sources de données de l'itérateur DATA |
|
| 202 | - * |
|
| 203 | - * @var string[] |
|
| 204 | - */ |
|
| 205 | - public array $from = []; |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Liste des alias / type de jointures utilisées dans la boucle |
|
| 209 | - * |
|
| 210 | - * L'index est le nom d'alias (comme pour la propriété $from), et la valeur |
|
| 211 | - * un type de jointure parmi 'INNER', 'LEFT', 'RIGHT', 'OUTER'. |
|
| 212 | - * |
|
| 213 | - * Lorsque le type n'est pas déclaré pour un alias, c'est 'INNER' |
|
| 214 | - * qui sera utilisé par défaut (créant donc un INNER JOIN). |
|
| 215 | - * |
|
| 216 | - * @var string[] |
|
| 217 | - */ |
|
| 218 | - public array $from_type = []; |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Liste des conditions WHERE de la boucle |
|
| 222 | - * |
|
| 223 | - * Permet de restreindre les éléments retournés par une boucle |
|
| 224 | - * en fonctions des conditions transmises dans ce tableau. |
|
| 225 | - * |
|
| 226 | - * Ce tableau peut avoir plusieurs niveaux de profondeur. |
|
| 227 | - * |
|
| 228 | - * Les éléments du premier niveau sont reliés par des AND, donc |
|
| 229 | - * chaque élément ajouté directement au where par |
|
| 230 | - * $boucle->where[] = array(...) ou $boucle->where[] = "'expression'" |
|
| 231 | - * est une condition AND en plus. |
|
| 232 | - * |
|
| 233 | - * Par contre, lorsqu'on indique un tableau, il peut décrire des relations |
|
| 234 | - * internes différentes. Soit $expr un tableau d'expressions quelconques de 3 valeurs : |
|
| 235 | - * $expr = array(operateur, val1, val2) |
|
| 236 | - * |
|
| 237 | - * Ces 3 valeurs sont des expressions PHP. L'index 0 désigne l'opérateur |
|
| 238 | - * à réaliser tel que : |
|
| 239 | - * |
|
| 240 | - * - "'='" , "'>='", "'<'", "'IN'", "'REGEXP'", "'LIKE'", ... : |
|
| 241 | - * val1 et val2 sont des champs et valeurs à utiliser dans la comparaison |
|
| 242 | - * suivant cet ordre : "val1 operateur val2". |
|
| 243 | - * Exemple : $boucle->where[] = array("'='", "'articles.statut'", "'\"publie\"'"); |
|
| 244 | - * - "'AND'", "'OR'", "'NOT'" : |
|
| 245 | - * dans ce cas val1 et val2 sont également des expressions |
|
| 246 | - * de comparaison complètes, et peuvent être eux-même des tableaux comme $expr |
|
| 247 | - * Exemples : |
|
| 248 | - * $boucle->where[] = array("'OR'", $expr1, $expr2); |
|
| 249 | - * $boucle->where[] = array("'NOT'", $expr); // val2 n'existe pas avec NOT |
|
| 250 | - * |
|
| 251 | - * D'autres noms sont possibles pour l'opérateur (le nombre de valeurs diffère) : |
|
| 252 | - * - "'SELF'", "'SUBSELECT'" : indiquent des sous requêtes |
|
| 253 | - * - "'?'" : indique une condition à faire évaluer (val1 ? val2 : val3) |
|
| 254 | - */ |
|
| 255 | - public array $where = []; |
|
| 256 | - |
|
| 257 | - public array $join = []; |
|
| 258 | - public array $having = []; |
|
| 259 | - public $limit = ''; |
|
| 260 | - public array $group = []; |
|
| 261 | - public array $order = []; |
|
| 262 | - public array $default_order = []; |
|
| 263 | - public string $date = 'date'; |
|
| 264 | - public string $hash = ''; |
|
| 265 | - public $in = ''; |
|
| 266 | - public bool $sous_requete = false; |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Code PHP qui sera ajouté en tout début de la fonction de boucle |
|
| 270 | - * |
|
| 271 | - * Il sert à insérer le code calculant une hierarchie |
|
| 272 | - */ |
|
| 273 | - public string $hierarchie = ''; |
|
| 274 | - |
|
| 275 | - // champs pour la construction du corps PHP |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Description des sources de données de la boucle |
|
| 279 | - * |
|
| 280 | - * Description des données de la boucle issu de trouver_table |
|
| 281 | - * dans le cadre de l'itérateur SQL et contenant au moins l'index 'field'. |
|
| 282 | - * |
|
| 283 | - * @see base_trouver_table_dist() |
|
| 284 | - */ |
|
| 285 | - public array $show = []; |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Nom de la table SQL principale de la boucle, sans son préfixe |
|
| 289 | - */ |
|
| 290 | - public string $id_table = ''; |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Nom de la clé primaire de la table SQL principale de la boucle |
|
| 294 | - */ |
|
| 295 | - public string $primary = ''; |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Code PHP compilé de la boucle |
|
| 299 | - * |
|
| 300 | - * FIXME: un seul type (string ?) |
|
| 301 | - * |
|
| 302 | - * - false: boucle fautive ? |
|
| 303 | - * |
|
| 304 | - * @var string|false |
|
| 305 | - */ |
|
| 306 | - public $return = ''; |
|
| 307 | - |
|
| 308 | - public $numrows = false; |
|
| 309 | - public $cptrows = false; |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Description du squelette |
|
| 313 | - * |
|
| 314 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 315 | - * |
|
| 316 | - * Peut contenir les index : |
|
| 317 | - * |
|
| 318 | - * - nom : Nom du fichier de cache |
|
| 319 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 320 | - * - sourcefile : Chemin du squelette |
|
| 321 | - * - squelette : Code du squelette |
|
| 322 | - * - id_mere : Identifiant de la boucle parente |
|
| 323 | - * - documents : Pour embed et img dans les textes |
|
| 324 | - * - session : Pour un cache sessionné par auteur |
|
| 325 | - * - niv : Niveau de tabulation |
|
| 326 | - */ |
|
| 327 | - public array $descr = []; |
|
| 328 | - |
|
| 329 | - /** Numéro de ligne dans le code source du squelette */ |
|
| 330 | - public int $ligne = 0; |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * table pour stocker les modificateurs de boucle tels que tout, plat ..., |
|
| 335 | - * utilisable par les plugins egalement |
|
| 336 | - * |
|
| 337 | - * @var array<string, mixed> |
|
| 338 | - */ |
|
| 339 | - public array $modificateur = []; |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Type d'itérateur utilisé pour cette boucle |
|
| 343 | - * |
|
| 344 | - * - 'SQL' dans le cadre d'une boucle sur une table SQL |
|
| 345 | - * - 'DATA' pour l'itérateur DATA, ... |
|
| 346 | - * |
|
| 347 | - * @var string |
|
| 348 | - */ |
|
| 349 | - public string $iterateur = ''; // type d'iterateur |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * @var array $debug Textes qui seront insérés dans l’entête de boucle du mode debug |
|
| 353 | - */ |
|
| 354 | - public array $debug = []; |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Index de la boucle dont le champ présent dans cette boucle est originaire, |
|
| 358 | - * notamment si le champ a été trouve dans une boucle parente |
|
| 359 | - * |
|
| 360 | - * Tableau nom du champ => index de boucle |
|
| 361 | - */ |
|
| 362 | - public array $index_champ = []; |
|
| 363 | - |
|
| 364 | - /** Résultat de la compilation (?) (sert au débusqueur) */ |
|
| 365 | - public string $code = ''; |
|
| 366 | - |
|
| 367 | - /** Source des filtres (compatibilité) (?) */ |
|
| 368 | - public array $fonctions = []; |
|
| 369 | - |
|
| 370 | - // obsoletes, conserves provisoirement pour compatibilite |
|
| 371 | - public $tout = false; |
|
| 372 | - public $plat = false; |
|
| 373 | - public $lien = false; |
|
| 10 | + /** Type de noeud */ |
|
| 11 | + public string $type = 'boucle'; |
|
| 12 | + |
|
| 13 | + /** Identifiant de la boucle */ |
|
| 14 | + public string $id_boucle; |
|
| 15 | + |
|
| 16 | + /** Identifiant de la boucle parente */ |
|
| 17 | + public string $id_parent = ''; |
|
| 18 | + |
|
| 19 | + /** Un nom explicite qui peut être affecté manuellement à certaines boucles générées */ |
|
| 20 | + public string $nom = ''; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Partie avant toujours affichee |
|
| 24 | + * |
|
| 25 | + * @var string|array |
|
| 26 | + */ |
|
| 27 | + public $preaff = ''; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Partie optionnelle avant |
|
| 31 | + * |
|
| 32 | + * @var string|array |
|
| 33 | + */ |
|
| 34 | + public $avant = ''; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Pour chaque élément |
|
| 38 | + * |
|
| 39 | + * @var string|array |
|
| 40 | + */ |
|
| 41 | + public $milieu = ''; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Partie optionnelle après |
|
| 45 | + * |
|
| 46 | + * @var string|array |
|
| 47 | + */ |
|
| 48 | + public $apres = ''; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Partie alternative, si pas de résultat dans la boucle |
|
| 52 | + * |
|
| 53 | + * @var string|array |
|
| 54 | + */ |
|
| 55 | + public $altern = ''; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Partie apres toujours affichee |
|
| 59 | + * |
|
| 60 | + * @var string|array |
|
| 61 | + */ |
|
| 62 | + public $postaff = ''; |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * La boucle doit-elle sélectionner la langue ? |
|
| 67 | + * |
|
| 68 | + * Valeurs : '', 'oui', 'non' |
|
| 69 | + */ |
|
| 70 | + public string $lang_select = ''; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 74 | + * |
|
| 75 | + * FIXME: un seul typage (string ?) |
|
| 76 | + * |
|
| 77 | + * @var string|false|null |
|
| 78 | + */ |
|
| 79 | + public $type_requete = null; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * La table est elle optionnelle ? |
|
| 83 | + * |
|
| 84 | + * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 85 | + */ |
|
| 86 | + public bool $table_optionnelle = false; |
|
| 87 | + public string $type_table_optionnelle = ''; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Nom du fichier de connexion |
|
| 91 | + */ |
|
| 92 | + public string $sql_serveur = ''; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Paramètres de la boucle |
|
| 96 | + * |
|
| 97 | + * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 98 | + * au calcul des critères |
|
| 99 | + * |
|
| 100 | + * FIXME: type unique. |
|
| 101 | + * @var false|array |
|
| 102 | + * - false: erreur de syntaxe |
|
| 103 | + */ |
|
| 104 | + public $param = []; |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Critères de la boucle |
|
| 108 | + * |
|
| 109 | + * FIXME: type array unique. |
|
| 110 | + * |
|
| 111 | + * @var string|Critere[] |
|
| 112 | + * - string: phrasage (code brut). Il reste si erreur de critère |
|
| 113 | + * - array: analyse correcte des critères... |
|
| 114 | + */ |
|
| 115 | + public $criteres = []; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 119 | + * |
|
| 120 | + * @var string[] |
|
| 121 | + */ |
|
| 122 | + public array $separateur = []; |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Liste des jointures possibles avec cette table |
|
| 126 | + * |
|
| 127 | + * Les jointures par défaut de la table sont complétées en priorité |
|
| 128 | + * des jointures déclarées explicitement sur la boucle |
|
| 129 | + * |
|
| 130 | + * @see base_trouver_table_dist() |
|
| 131 | + */ |
|
| 132 | + public array $jointures = []; |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Jointures explicites avec cette table |
|
| 136 | + * |
|
| 137 | + * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 138 | + * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 139 | + * à la boucle. |
|
| 140 | + * |
|
| 141 | + * @var string|bool |
|
| 142 | + */ |
|
| 143 | + public $jointures_explicites = false; |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 147 | + */ |
|
| 148 | + public string $doublons = ''; |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Code PHP ajouté au début de chaque itération de boucle. |
|
| 152 | + * |
|
| 153 | + * Utilisé entre autre par les critères {pagination}, {n-a,b}, {a/b}... |
|
| 154 | + */ |
|
| 155 | + public string $partie = ''; |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Nombre de divisions de la boucle, d'éléments à afficher, |
|
| 159 | + * ou de soustractions d'éléments à faire |
|
| 160 | + * |
|
| 161 | + * Dans les critères limitant le nombre d'éléments affichés |
|
| 162 | + * {a,b}, {a,n-b}, {a/b}, {pagination b}, b est affecté à total_parties. |
|
| 163 | + */ |
|
| 164 | + public string $total_parties = ''; |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Code PHP ajouté avant l'itération de boucle. |
|
| 168 | + * |
|
| 169 | + * Utilisé entre autre par les critères {pagination}, {a,b}, {a/b} |
|
| 170 | + * pour initialiser les variables de début et de fin d'itération. |
|
| 171 | + */ |
|
| 172 | + public string $mode_partie = ''; |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Identifiant d'une boucle qui appelle celle-ci de manière récursive |
|
| 176 | + * |
|
| 177 | + * Si une boucle est appelée de manière récursive quelque part par |
|
| 178 | + * une autre boucle comme <BOUCLE_rec(boucle_identifiant) />, cette |
|
| 179 | + * boucle (identifiant) reçoit dans cette propriété l'identifiant |
|
| 180 | + * de l'appelant (rec) |
|
| 181 | + */ |
|
| 182 | + public string $externe = ''; |
|
| 183 | + |
|
| 184 | + // champs pour la construction de la requete SQL |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Liste des champs à récupérer par la boucle |
|
| 188 | + * |
|
| 189 | + * Expression 'table.nom_champ' ou calculée 'nom_champ AS x' |
|
| 190 | + * |
|
| 191 | + * @var string[] |
|
| 192 | + */ |
|
| 193 | + public array $select = []; |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Liste des alias / tables SQL utilisées dans la boucle |
|
| 197 | + * |
|
| 198 | + * L'index est un identifiant (xx dans spip_xx assez souvent) qui servira |
|
| 199 | + * d'alias au nom de la table ; la valeur est le nom de la table SQL désirée. |
|
| 200 | + * |
|
| 201 | + * L'index 0 peut définir le type de sources de données de l'itérateur DATA |
|
| 202 | + * |
|
| 203 | + * @var string[] |
|
| 204 | + */ |
|
| 205 | + public array $from = []; |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Liste des alias / type de jointures utilisées dans la boucle |
|
| 209 | + * |
|
| 210 | + * L'index est le nom d'alias (comme pour la propriété $from), et la valeur |
|
| 211 | + * un type de jointure parmi 'INNER', 'LEFT', 'RIGHT', 'OUTER'. |
|
| 212 | + * |
|
| 213 | + * Lorsque le type n'est pas déclaré pour un alias, c'est 'INNER' |
|
| 214 | + * qui sera utilisé par défaut (créant donc un INNER JOIN). |
|
| 215 | + * |
|
| 216 | + * @var string[] |
|
| 217 | + */ |
|
| 218 | + public array $from_type = []; |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Liste des conditions WHERE de la boucle |
|
| 222 | + * |
|
| 223 | + * Permet de restreindre les éléments retournés par une boucle |
|
| 224 | + * en fonctions des conditions transmises dans ce tableau. |
|
| 225 | + * |
|
| 226 | + * Ce tableau peut avoir plusieurs niveaux de profondeur. |
|
| 227 | + * |
|
| 228 | + * Les éléments du premier niveau sont reliés par des AND, donc |
|
| 229 | + * chaque élément ajouté directement au where par |
|
| 230 | + * $boucle->where[] = array(...) ou $boucle->where[] = "'expression'" |
|
| 231 | + * est une condition AND en plus. |
|
| 232 | + * |
|
| 233 | + * Par contre, lorsqu'on indique un tableau, il peut décrire des relations |
|
| 234 | + * internes différentes. Soit $expr un tableau d'expressions quelconques de 3 valeurs : |
|
| 235 | + * $expr = array(operateur, val1, val2) |
|
| 236 | + * |
|
| 237 | + * Ces 3 valeurs sont des expressions PHP. L'index 0 désigne l'opérateur |
|
| 238 | + * à réaliser tel que : |
|
| 239 | + * |
|
| 240 | + * - "'='" , "'>='", "'<'", "'IN'", "'REGEXP'", "'LIKE'", ... : |
|
| 241 | + * val1 et val2 sont des champs et valeurs à utiliser dans la comparaison |
|
| 242 | + * suivant cet ordre : "val1 operateur val2". |
|
| 243 | + * Exemple : $boucle->where[] = array("'='", "'articles.statut'", "'\"publie\"'"); |
|
| 244 | + * - "'AND'", "'OR'", "'NOT'" : |
|
| 245 | + * dans ce cas val1 et val2 sont également des expressions |
|
| 246 | + * de comparaison complètes, et peuvent être eux-même des tableaux comme $expr |
|
| 247 | + * Exemples : |
|
| 248 | + * $boucle->where[] = array("'OR'", $expr1, $expr2); |
|
| 249 | + * $boucle->where[] = array("'NOT'", $expr); // val2 n'existe pas avec NOT |
|
| 250 | + * |
|
| 251 | + * D'autres noms sont possibles pour l'opérateur (le nombre de valeurs diffère) : |
|
| 252 | + * - "'SELF'", "'SUBSELECT'" : indiquent des sous requêtes |
|
| 253 | + * - "'?'" : indique une condition à faire évaluer (val1 ? val2 : val3) |
|
| 254 | + */ |
|
| 255 | + public array $where = []; |
|
| 256 | + |
|
| 257 | + public array $join = []; |
|
| 258 | + public array $having = []; |
|
| 259 | + public $limit = ''; |
|
| 260 | + public array $group = []; |
|
| 261 | + public array $order = []; |
|
| 262 | + public array $default_order = []; |
|
| 263 | + public string $date = 'date'; |
|
| 264 | + public string $hash = ''; |
|
| 265 | + public $in = ''; |
|
| 266 | + public bool $sous_requete = false; |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Code PHP qui sera ajouté en tout début de la fonction de boucle |
|
| 270 | + * |
|
| 271 | + * Il sert à insérer le code calculant une hierarchie |
|
| 272 | + */ |
|
| 273 | + public string $hierarchie = ''; |
|
| 274 | + |
|
| 275 | + // champs pour la construction du corps PHP |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Description des sources de données de la boucle |
|
| 279 | + * |
|
| 280 | + * Description des données de la boucle issu de trouver_table |
|
| 281 | + * dans le cadre de l'itérateur SQL et contenant au moins l'index 'field'. |
|
| 282 | + * |
|
| 283 | + * @see base_trouver_table_dist() |
|
| 284 | + */ |
|
| 285 | + public array $show = []; |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Nom de la table SQL principale de la boucle, sans son préfixe |
|
| 289 | + */ |
|
| 290 | + public string $id_table = ''; |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Nom de la clé primaire de la table SQL principale de la boucle |
|
| 294 | + */ |
|
| 295 | + public string $primary = ''; |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Code PHP compilé de la boucle |
|
| 299 | + * |
|
| 300 | + * FIXME: un seul type (string ?) |
|
| 301 | + * |
|
| 302 | + * - false: boucle fautive ? |
|
| 303 | + * |
|
| 304 | + * @var string|false |
|
| 305 | + */ |
|
| 306 | + public $return = ''; |
|
| 307 | + |
|
| 308 | + public $numrows = false; |
|
| 309 | + public $cptrows = false; |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Description du squelette |
|
| 313 | + * |
|
| 314 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 315 | + * |
|
| 316 | + * Peut contenir les index : |
|
| 317 | + * |
|
| 318 | + * - nom : Nom du fichier de cache |
|
| 319 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 320 | + * - sourcefile : Chemin du squelette |
|
| 321 | + * - squelette : Code du squelette |
|
| 322 | + * - id_mere : Identifiant de la boucle parente |
|
| 323 | + * - documents : Pour embed et img dans les textes |
|
| 324 | + * - session : Pour un cache sessionné par auteur |
|
| 325 | + * - niv : Niveau de tabulation |
|
| 326 | + */ |
|
| 327 | + public array $descr = []; |
|
| 328 | + |
|
| 329 | + /** Numéro de ligne dans le code source du squelette */ |
|
| 330 | + public int $ligne = 0; |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * table pour stocker les modificateurs de boucle tels que tout, plat ..., |
|
| 335 | + * utilisable par les plugins egalement |
|
| 336 | + * |
|
| 337 | + * @var array<string, mixed> |
|
| 338 | + */ |
|
| 339 | + public array $modificateur = []; |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Type d'itérateur utilisé pour cette boucle |
|
| 343 | + * |
|
| 344 | + * - 'SQL' dans le cadre d'une boucle sur une table SQL |
|
| 345 | + * - 'DATA' pour l'itérateur DATA, ... |
|
| 346 | + * |
|
| 347 | + * @var string |
|
| 348 | + */ |
|
| 349 | + public string $iterateur = ''; // type d'iterateur |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * @var array $debug Textes qui seront insérés dans l’entête de boucle du mode debug |
|
| 353 | + */ |
|
| 354 | + public array $debug = []; |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Index de la boucle dont le champ présent dans cette boucle est originaire, |
|
| 358 | + * notamment si le champ a été trouve dans une boucle parente |
|
| 359 | + * |
|
| 360 | + * Tableau nom du champ => index de boucle |
|
| 361 | + */ |
|
| 362 | + public array $index_champ = []; |
|
| 363 | + |
|
| 364 | + /** Résultat de la compilation (?) (sert au débusqueur) */ |
|
| 365 | + public string $code = ''; |
|
| 366 | + |
|
| 367 | + /** Source des filtres (compatibilité) (?) */ |
|
| 368 | + public array $fonctions = []; |
|
| 369 | + |
|
| 370 | + // obsoletes, conserves provisoirement pour compatibilite |
|
| 371 | + public $tout = false; |
|
| 372 | + public $plat = false; |
|
| 373 | + public $lien = false; |
|
| 374 | 374 | } |