@@ -10,88 +10,88 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function install_etape_ldap2_dist() { |
| 17 | - $minipage = new Spip\Afficher\Minipage\Installation(); |
|
| 18 | - echo $minipage->installDebutPage(['onload' => 'document.getElementById(\'suivant\').focus();return false;']); |
|
| 19 | - |
|
| 20 | - $adresse_ldap = _request('adresse_ldap'); |
|
| 21 | - |
|
| 22 | - $port_ldap = _request('port_ldap'); |
|
| 23 | - |
|
| 24 | - $tls_ldap = _request('tls_ldap'); |
|
| 25 | - |
|
| 26 | - $protocole_ldap = _request('protocole_ldap'); |
|
| 27 | - |
|
| 28 | - $login_ldap = _request('login_ldap'); |
|
| 29 | - |
|
| 30 | - $pass_ldap = _request('pass_ldap'); |
|
| 31 | - |
|
| 32 | - $port_ldap = (int) $port_ldap; |
|
| 33 | - |
|
| 34 | - $tls = false; |
|
| 35 | - |
|
| 36 | - if ($tls_ldap == 'oui') { |
|
| 37 | - if ($port_ldap == 636) { |
|
| 38 | - $adresse_ldap = "ldaps://$adresse_ldap"; |
|
| 39 | - } else { |
|
| 40 | - $tls = true; |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - else { |
|
| 44 | - $tls_ldap == 'non'; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // Verifions que l'adresse demandee est valide |
|
| 48 | - $adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: ''; |
|
| 49 | - |
|
| 50 | - $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
|
| 51 | - $erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 52 | - |
|
| 53 | - if ($ldap_link) { |
|
| 54 | - if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) { |
|
| 55 | - $protocole_ldap = 2; |
|
| 56 | - ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap); |
|
| 57 | - } |
|
| 58 | - if ($tls && !ldap_start_tls($ldap_link)) { |
|
| 59 | - $erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link) |
|
| 60 | - . ' ' . spip_htmlspecialchars($adresse_ldap) |
|
| 61 | - . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 62 | - $ldap_link = false; |
|
| 63 | - } |
|
| 64 | - if ($ldap_link) { |
|
| 65 | - $ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 66 | - $erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link) |
|
| 67 | - . "', '" . spip_htmlspecialchars($login_ldap) |
|
| 68 | - . "', '" . spip_htmlspecialchars($pass_ldap) |
|
| 69 | - . "'): " . spip_htmlspecialchars($adresse_ldap) |
|
| 70 | - . ', ' . spip_htmlspecialchars($port_ldap); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if ($ldap_link) { |
|
| 75 | - echo info_etape( |
|
| 76 | - _T('titre_connexion_ldap'), |
|
| 77 | - info_progression_etape(2, 'etape_ldap', 'install/') |
|
| 78 | - ), _T('info_connexion_ldap_ok'); |
|
| 79 | - echo generer_form_ecrire('install', ( |
|
| 80 | - "\n<input type='hidden' name='etape' value='ldap3' />" |
|
| 81 | - . "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />' |
|
| 82 | - . "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />' |
|
| 83 | - . "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />' |
|
| 84 | - . "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />' |
|
| 85 | - . "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />' |
|
| 86 | - . "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />' |
|
| 87 | - . bouton_suivant())); |
|
| 88 | - } else { |
|
| 89 | - echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true), |
|
| 90 | - "<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>', |
|
| 91 | - '<p>' . _T('avis_connexion_ldap_echec_2') . |
|
| 92 | - "<br />\n" . _T('avis_connexion_ldap_echec_3') . |
|
| 93 | - '<br /><br />' . $erreur . '<b> ?</b></p></div>'; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - echo $minipage->installFinPage(); |
|
| 17 | + $minipage = new Spip\Afficher\Minipage\Installation(); |
|
| 18 | + echo $minipage->installDebutPage(['onload' => 'document.getElementById(\'suivant\').focus();return false;']); |
|
| 19 | + |
|
| 20 | + $adresse_ldap = _request('adresse_ldap'); |
|
| 21 | + |
|
| 22 | + $port_ldap = _request('port_ldap'); |
|
| 23 | + |
|
| 24 | + $tls_ldap = _request('tls_ldap'); |
|
| 25 | + |
|
| 26 | + $protocole_ldap = _request('protocole_ldap'); |
|
| 27 | + |
|
| 28 | + $login_ldap = _request('login_ldap'); |
|
| 29 | + |
|
| 30 | + $pass_ldap = _request('pass_ldap'); |
|
| 31 | + |
|
| 32 | + $port_ldap = (int) $port_ldap; |
|
| 33 | + |
|
| 34 | + $tls = false; |
|
| 35 | + |
|
| 36 | + if ($tls_ldap == 'oui') { |
|
| 37 | + if ($port_ldap == 636) { |
|
| 38 | + $adresse_ldap = "ldaps://$adresse_ldap"; |
|
| 39 | + } else { |
|
| 40 | + $tls = true; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + else { |
|
| 44 | + $tls_ldap == 'non'; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // Verifions que l'adresse demandee est valide |
|
| 48 | + $adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: ''; |
|
| 49 | + |
|
| 50 | + $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
|
| 51 | + $erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 52 | + |
|
| 53 | + if ($ldap_link) { |
|
| 54 | + if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) { |
|
| 55 | + $protocole_ldap = 2; |
|
| 56 | + ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap); |
|
| 57 | + } |
|
| 58 | + if ($tls && !ldap_start_tls($ldap_link)) { |
|
| 59 | + $erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link) |
|
| 60 | + . ' ' . spip_htmlspecialchars($adresse_ldap) |
|
| 61 | + . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 62 | + $ldap_link = false; |
|
| 63 | + } |
|
| 64 | + if ($ldap_link) { |
|
| 65 | + $ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 66 | + $erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link) |
|
| 67 | + . "', '" . spip_htmlspecialchars($login_ldap) |
|
| 68 | + . "', '" . spip_htmlspecialchars($pass_ldap) |
|
| 69 | + . "'): " . spip_htmlspecialchars($adresse_ldap) |
|
| 70 | + . ', ' . spip_htmlspecialchars($port_ldap); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if ($ldap_link) { |
|
| 75 | + echo info_etape( |
|
| 76 | + _T('titre_connexion_ldap'), |
|
| 77 | + info_progression_etape(2, 'etape_ldap', 'install/') |
|
| 78 | + ), _T('info_connexion_ldap_ok'); |
|
| 79 | + echo generer_form_ecrire('install', ( |
|
| 80 | + "\n<input type='hidden' name='etape' value='ldap3' />" |
|
| 81 | + . "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />' |
|
| 82 | + . "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />' |
|
| 83 | + . "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />' |
|
| 84 | + . "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />' |
|
| 85 | + . "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />' |
|
| 86 | + . "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />' |
|
| 87 | + . bouton_suivant())); |
|
| 88 | + } else { |
|
| 89 | + echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true), |
|
| 90 | + "<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>', |
|
| 91 | + '<p>' . _T('avis_connexion_ldap_echec_2') . |
|
| 92 | + "<br />\n" . _T('avis_connexion_ldap_echec_3') . |
|
| 93 | + '<br /><br />' . $erreur . '<b> ?</b></p></div>'; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + echo $minipage->installFinPage(); |
|
| 97 | 97 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_spip('inc/headers'); |
@@ -19,61 +19,61 @@ discard block |
||
| 19 | 19 | // Mise en place des fichiers de configuration si ce n'est fait |
| 20 | 20 | |
| 21 | 21 | function install_etape_fin_dist() { |
| 22 | - ecrire_acces(); |
|
| 22 | + ecrire_acces(); |
|
| 23 | 23 | |
| 24 | - $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CHMOD_TMP); |
|
| 25 | - if (file_exists(_FILE_CHMOD_TMP) && !@rename(_FILE_CHMOD_TMP, $f) && @copy(_FILE_CHMOD_TMP, $f)) { |
|
| 26 | - spip_unlink(_FILE_CHMOD_TMP); |
|
| 27 | - } |
|
| 24 | + $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CHMOD_TMP); |
|
| 25 | + if (file_exists(_FILE_CHMOD_TMP) && !@rename(_FILE_CHMOD_TMP, $f) && @copy(_FILE_CHMOD_TMP, $f)) { |
|
| 26 | + spip_unlink(_FILE_CHMOD_TMP); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CONNECT_TMP); |
|
| 30 | - if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 31 | - spip_log("renomme $f"); |
|
| 32 | - if (!@rename(_FILE_CONNECT_TMP, $f) && @copy(_FILE_CONNECT_TMP, $f)) { |
|
| 33 | - @spip_unlink(_FILE_CONNECT_TMP); |
|
| 34 | - } |
|
| 35 | - } |
|
| 29 | + $f = str_replace(_FILE_TMP_SUFFIX, '.php', _FILE_CONNECT_TMP); |
|
| 30 | + if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 31 | + spip_log("renomme $f"); |
|
| 32 | + if (!@rename(_FILE_CONNECT_TMP, $f) && @copy(_FILE_CONNECT_TMP, $f)) { |
|
| 33 | + @spip_unlink(_FILE_CONNECT_TMP); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - // creer le repertoire cache, qui sert partout ! |
|
| 38 | - // deja fait en etape 4 en principe, on garde au cas ou |
|
| 39 | - if (!@file_exists(_DIR_CACHE)) { |
|
| 40 | - $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 41 | - $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 42 | - } |
|
| 37 | + // creer le repertoire cache, qui sert partout ! |
|
| 38 | + // deja fait en etape 4 en principe, on garde au cas ou |
|
| 39 | + if (!@file_exists(_DIR_CACHE)) { |
|
| 40 | + $rep = preg_replace(',' . _DIR_TMP . ',', '', _DIR_CACHE); |
|
| 41 | + $rep = sous_repertoire(_DIR_TMP, $rep, true, true); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // Verifier la securite des htaccess |
|
| 45 | - // Si elle ne fonctionne pas, prevenir |
|
| 46 | - $msg = install_verifier_htaccess(); |
|
| 47 | - if ($msg) { |
|
| 48 | - $cible = _T('public:accueil_site'); |
|
| 49 | - $cible = generer_form_ecrire('accueil', '', '', $cible); |
|
| 50 | - $minipage = new Spip\Afficher\Minipage\Installation(); |
|
| 51 | - echo $minipage->page($msg . $cible); |
|
| 52 | - // ok, deboucher dans l'espace prive |
|
| 53 | - } else { |
|
| 54 | - redirige_url_ecrire('accueil'); |
|
| 55 | - } |
|
| 44 | + // Verifier la securite des htaccess |
|
| 45 | + // Si elle ne fonctionne pas, prevenir |
|
| 46 | + $msg = install_verifier_htaccess(); |
|
| 47 | + if ($msg) { |
|
| 48 | + $cible = _T('public:accueil_site'); |
|
| 49 | + $cible = generer_form_ecrire('accueil', '', '', $cible); |
|
| 50 | + $minipage = new Spip\Afficher\Minipage\Installation(); |
|
| 51 | + echo $minipage->page($msg . $cible); |
|
| 52 | + // ok, deboucher dans l'espace prive |
|
| 53 | + } else { |
|
| 54 | + redirige_url_ecrire('accueil'); |
|
| 55 | + } |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | function install_verifier_htaccess() { |
| 59 | - if ( |
|
| 60 | - verifier_htaccess(_DIR_TMP, true) |
|
| 61 | - && verifier_htaccess(_DIR_CONNECT, true) |
|
| 62 | - && verifier_htaccess(_DIR_VENDOR, true) |
|
| 63 | - ) { |
|
| 64 | - return ''; |
|
| 65 | - } |
|
| 59 | + if ( |
|
| 60 | + verifier_htaccess(_DIR_TMP, true) |
|
| 61 | + && verifier_htaccess(_DIR_CONNECT, true) |
|
| 62 | + && verifier_htaccess(_DIR_VENDOR, true) |
|
| 63 | + ) { |
|
| 64 | + return ''; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - $titre = _T('htaccess_inoperant'); |
|
| 67 | + $titre = _T('htaccess_inoperant'); |
|
| 68 | 68 | |
| 69 | - $averti = _T( |
|
| 70 | - 'htaccess_a_simuler', |
|
| 71 | - [ |
|
| 72 | - 'htaccess' => '<tt>' . _ACCESS_FILE_NAME . '</tt>', |
|
| 73 | - 'constantes' => '<tt>_DIR_TMP & _DIR_CONNECT</tt>', |
|
| 74 | - 'document_root' => '<tt>' . $_SERVER['DOCUMENT_ROOT'] . '</tt>' |
|
| 75 | - ] |
|
| 76 | - ); |
|
| 69 | + $averti = _T( |
|
| 70 | + 'htaccess_a_simuler', |
|
| 71 | + [ |
|
| 72 | + 'htaccess' => '<tt>' . _ACCESS_FILE_NAME . '</tt>', |
|
| 73 | + 'constantes' => '<tt>_DIR_TMP & _DIR_CONNECT</tt>', |
|
| 74 | + 'document_root' => '<tt>' . $_SERVER['DOCUMENT_ROOT'] . '</tt>' |
|
| 75 | + ] |
|
| 76 | + ); |
|
| 77 | 77 | |
| 78 | - return "<div class='error'><h3>$titre</h3><p>$averti</p></div>"; |
|
| 78 | + return "<div class='error'><h3>$titre</h3><p>$averti</p></div>"; |
|
| 79 | 79 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_spip('inc/headers'); |
@@ -18,199 +18,199 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | function install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db) { |
| 20 | 20 | |
| 21 | - // Prefix des tables : |
|
| 22 | - // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 23 | - // a partir de ce qui est envoye a l'installation |
|
| 24 | - if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 25 | - $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 26 | - ? $GLOBALS['table_prefix'] |
|
| 27 | - : preparer_prefixe_tables(_request('tprefix')); |
|
| 28 | - // S'il est vide on remet spip |
|
| 29 | - if (!$table_prefix) { |
|
| 30 | - $table_prefix = 'spip'; |
|
| 31 | - } |
|
| 32 | - } else { |
|
| 33 | - $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - if (preg_match(',(.*):(.*),', $adresse_db, $r)) { |
|
| 37 | - [, $adresse_db, $port] = $r; |
|
| 38 | - } else { |
|
| 39 | - $port = ''; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - $GLOBALS['connexions'][$server_db] |
|
| 43 | - = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
|
| 44 | - |
|
| 45 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 46 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 47 | - |
|
| 48 | - $fquery = sql_serveur('query', $server_db); |
|
| 49 | - if ($choix_db == 'new_spip') { |
|
| 50 | - $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 51 | - if (preg_match($re, $sel_db)) { |
|
| 52 | - $ok = sql_create_base($sel_db, $server_db); |
|
| 53 | - if (!$ok) { |
|
| 54 | - $re = "Impossible de creer la base $re"; |
|
| 55 | - spip_log($re); |
|
| 56 | - return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 57 | - } |
|
| 58 | - } else { |
|
| 59 | - $re = "Le nom de la base doit correspondre a $re"; |
|
| 60 | - spip_log($re); |
|
| 61 | - |
|
| 62 | - return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 67 | - // un sql_mode |
|
| 68 | - install_mode_appel($server_db, false); |
|
| 69 | - $GLOBALS['connexions'][$server_db] |
|
| 70 | - = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
|
| 71 | - |
|
| 72 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 73 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 74 | - |
|
| 75 | - // Completer le tableau decrivant la connexion |
|
| 76 | - |
|
| 77 | - $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 78 | - $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 79 | - |
|
| 80 | - $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 81 | - if ($old) { |
|
| 82 | - $old = sql_fetch($old, $server_db); |
|
| 83 | - } |
|
| 84 | - if (!$old) { |
|
| 85 | - // Si possible, demander au serveur d'envoyer les textes |
|
| 86 | - // dans le codage std de SPIP, |
|
| 87 | - $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 88 | - |
|
| 89 | - if ($charset) { |
|
| 90 | - sql_set_charset($charset['charset'], $server_db); |
|
| 91 | - $GLOBALS['meta']['charset_sql_base'] = |
|
| 92 | - $charset['charset']; |
|
| 93 | - $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 94 | - $charset['collation']; |
|
| 95 | - $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 96 | - $charset['charset']; |
|
| 97 | - $charsetbase = $charset['charset']; |
|
| 98 | - } else { |
|
| 99 | - spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 100 | - $charsetbase = 'standard'; |
|
| 101 | - } |
|
| 102 | - spip_log("Creation des tables. Codage $charsetbase"); |
|
| 103 | - creer_base($server_db); // AT LAST |
|
| 104 | - // memoriser avec quel charset on l'a creee |
|
| 105 | - |
|
| 106 | - if ($charset) { |
|
| 107 | - $t = [ |
|
| 108 | - 'nom' => 'charset_sql_base', |
|
| 109 | - 'valeur' => $charset['charset'], |
|
| 110 | - 'impt' => 'non' |
|
| 111 | - ]; |
|
| 112 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 113 | - $t['nom'] = 'charset_collation_sql_base'; |
|
| 114 | - $t['valeur'] = $charset['collation']; |
|
| 115 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 116 | - $t['nom'] = 'charset_sql_connexion'; |
|
| 117 | - $t['valeur'] = $charset['charset']; |
|
| 118 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 119 | - } |
|
| 120 | - $t = [ |
|
| 121 | - 'nom' => 'version_installee', |
|
| 122 | - 'valeur' => $GLOBALS['spip_version_base'], |
|
| 123 | - 'impt' => 'non' |
|
| 124 | - ]; |
|
| 125 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 126 | - $t['nom'] = 'nouvelle_install'; |
|
| 127 | - $t['valeur'] = 1; |
|
| 128 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 129 | - // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 130 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 131 | - @sql_insertq( |
|
| 132 | - 'spip_meta', |
|
| 133 | - ['nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']], |
|
| 134 | - [], |
|
| 135 | - $server_db |
|
| 136 | - ); |
|
| 137 | - } |
|
| 138 | - } else { |
|
| 139 | - // pour recreer les tables disparues au besoin |
|
| 140 | - spip_log('Table des Meta deja la. Verification des autres.'); |
|
| 141 | - creer_base($server_db); |
|
| 142 | - $fupdateq = sql_serveur('updateq', $server_db); |
|
| 143 | - |
|
| 144 | - $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 145 | - |
|
| 146 | - if ($r) { |
|
| 147 | - $r = sql_fetch($r, $server_db); |
|
| 148 | - } |
|
| 149 | - $version_installee = $r ? (double)$r['valeur'] : 0; |
|
| 150 | - if (!$version_installee || $GLOBALS['spip_version_base'] < $version_installee) { |
|
| 151 | - $fupdateq( |
|
| 152 | - 'spip_meta', |
|
| 153 | - ['valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'], |
|
| 154 | - "nom='version_installee'", |
|
| 155 | - '', |
|
| 156 | - $server_db |
|
| 157 | - ); |
|
| 158 | - spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 159 | - } |
|
| 160 | - // eliminer la derniere operation d'admin mal terminee |
|
| 161 | - // notamment la mise a jour |
|
| 162 | - @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // recuperer le charset de la connexion dans les meta |
|
| 166 | - $charset = ''; |
|
| 167 | - $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db); |
|
| 168 | - if ($r) { |
|
| 169 | - $r = sql_fetch($r, $server_db); |
|
| 170 | - } |
|
| 171 | - if ($r) { |
|
| 172 | - $charset = $r['valeur']; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $ligne_rappel = install_mode_appel($server_db); |
|
| 176 | - |
|
| 177 | - $result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db); |
|
| 178 | - if (!$result_ok) { |
|
| 179 | - return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if ($chmod_db) { |
|
| 183 | - install_fichier_connexion( |
|
| 184 | - _FILE_CHMOD_TMP, |
|
| 185 | - "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 186 | - ); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // si ce fichier existe a cette etape c'est qu'il provient |
|
| 190 | - // d'une installation qui ne l'a pas cree correctement. |
|
| 191 | - // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 192 | - |
|
| 193 | - if (_FILE_CONNECT && file_exists(_FILE_CONNECT)) { |
|
| 194 | - spip_unlink(_FILE_CONNECT); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - install_fichier_connexion( |
|
| 198 | - _FILE_CONNECT_TMP, |
|
| 199 | - $ligne_rappel |
|
| 200 | - . install_connexion( |
|
| 201 | - $adresse_db, |
|
| 202 | - $port, |
|
| 203 | - $login_db, |
|
| 204 | - $pass_db, |
|
| 205 | - $sel_db, |
|
| 206 | - $server_db, |
|
| 207 | - $table_prefix, |
|
| 208 | - '', |
|
| 209 | - $charset |
|
| 210 | - ) |
|
| 211 | - ); |
|
| 212 | - |
|
| 213 | - return ''; |
|
| 21 | + // Prefix des tables : |
|
| 22 | + // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 23 | + // a partir de ce qui est envoye a l'installation |
|
| 24 | + if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 25 | + $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 26 | + ? $GLOBALS['table_prefix'] |
|
| 27 | + : preparer_prefixe_tables(_request('tprefix')); |
|
| 28 | + // S'il est vide on remet spip |
|
| 29 | + if (!$table_prefix) { |
|
| 30 | + $table_prefix = 'spip'; |
|
| 31 | + } |
|
| 32 | + } else { |
|
| 33 | + $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + if (preg_match(',(.*):(.*),', $adresse_db, $r)) { |
|
| 37 | + [, $adresse_db, $port] = $r; |
|
| 38 | + } else { |
|
| 39 | + $port = ''; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + $GLOBALS['connexions'][$server_db] |
|
| 43 | + = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
|
| 44 | + |
|
| 45 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 46 | + = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 47 | + |
|
| 48 | + $fquery = sql_serveur('query', $server_db); |
|
| 49 | + if ($choix_db == 'new_spip') { |
|
| 50 | + $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 51 | + if (preg_match($re, $sel_db)) { |
|
| 52 | + $ok = sql_create_base($sel_db, $server_db); |
|
| 53 | + if (!$ok) { |
|
| 54 | + $re = "Impossible de creer la base $re"; |
|
| 55 | + spip_log($re); |
|
| 56 | + return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 57 | + } |
|
| 58 | + } else { |
|
| 59 | + $re = "Le nom de la base doit correspondre a $re"; |
|
| 60 | + spip_log($re); |
|
| 61 | + |
|
| 62 | + return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 67 | + // un sql_mode |
|
| 68 | + install_mode_appel($server_db, false); |
|
| 69 | + $GLOBALS['connexions'][$server_db] |
|
| 70 | + = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
|
| 71 | + |
|
| 72 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 73 | + = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 74 | + |
|
| 75 | + // Completer le tableau decrivant la connexion |
|
| 76 | + |
|
| 77 | + $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 78 | + $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 79 | + |
|
| 80 | + $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 81 | + if ($old) { |
|
| 82 | + $old = sql_fetch($old, $server_db); |
|
| 83 | + } |
|
| 84 | + if (!$old) { |
|
| 85 | + // Si possible, demander au serveur d'envoyer les textes |
|
| 86 | + // dans le codage std de SPIP, |
|
| 87 | + $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 88 | + |
|
| 89 | + if ($charset) { |
|
| 90 | + sql_set_charset($charset['charset'], $server_db); |
|
| 91 | + $GLOBALS['meta']['charset_sql_base'] = |
|
| 92 | + $charset['charset']; |
|
| 93 | + $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 94 | + $charset['collation']; |
|
| 95 | + $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 96 | + $charset['charset']; |
|
| 97 | + $charsetbase = $charset['charset']; |
|
| 98 | + } else { |
|
| 99 | + spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 100 | + $charsetbase = 'standard'; |
|
| 101 | + } |
|
| 102 | + spip_log("Creation des tables. Codage $charsetbase"); |
|
| 103 | + creer_base($server_db); // AT LAST |
|
| 104 | + // memoriser avec quel charset on l'a creee |
|
| 105 | + |
|
| 106 | + if ($charset) { |
|
| 107 | + $t = [ |
|
| 108 | + 'nom' => 'charset_sql_base', |
|
| 109 | + 'valeur' => $charset['charset'], |
|
| 110 | + 'impt' => 'non' |
|
| 111 | + ]; |
|
| 112 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 113 | + $t['nom'] = 'charset_collation_sql_base'; |
|
| 114 | + $t['valeur'] = $charset['collation']; |
|
| 115 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 116 | + $t['nom'] = 'charset_sql_connexion'; |
|
| 117 | + $t['valeur'] = $charset['charset']; |
|
| 118 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 119 | + } |
|
| 120 | + $t = [ |
|
| 121 | + 'nom' => 'version_installee', |
|
| 122 | + 'valeur' => $GLOBALS['spip_version_base'], |
|
| 123 | + 'impt' => 'non' |
|
| 124 | + ]; |
|
| 125 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 126 | + $t['nom'] = 'nouvelle_install'; |
|
| 127 | + $t['valeur'] = 1; |
|
| 128 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 129 | + // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 130 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 131 | + @sql_insertq( |
|
| 132 | + 'spip_meta', |
|
| 133 | + ['nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']], |
|
| 134 | + [], |
|
| 135 | + $server_db |
|
| 136 | + ); |
|
| 137 | + } |
|
| 138 | + } else { |
|
| 139 | + // pour recreer les tables disparues au besoin |
|
| 140 | + spip_log('Table des Meta deja la. Verification des autres.'); |
|
| 141 | + creer_base($server_db); |
|
| 142 | + $fupdateq = sql_serveur('updateq', $server_db); |
|
| 143 | + |
|
| 144 | + $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 145 | + |
|
| 146 | + if ($r) { |
|
| 147 | + $r = sql_fetch($r, $server_db); |
|
| 148 | + } |
|
| 149 | + $version_installee = $r ? (double)$r['valeur'] : 0; |
|
| 150 | + if (!$version_installee || $GLOBALS['spip_version_base'] < $version_installee) { |
|
| 151 | + $fupdateq( |
|
| 152 | + 'spip_meta', |
|
| 153 | + ['valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'], |
|
| 154 | + "nom='version_installee'", |
|
| 155 | + '', |
|
| 156 | + $server_db |
|
| 157 | + ); |
|
| 158 | + spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 159 | + } |
|
| 160 | + // eliminer la derniere operation d'admin mal terminee |
|
| 161 | + // notamment la mise a jour |
|
| 162 | + @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // recuperer le charset de la connexion dans les meta |
|
| 166 | + $charset = ''; |
|
| 167 | + $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db); |
|
| 168 | + if ($r) { |
|
| 169 | + $r = sql_fetch($r, $server_db); |
|
| 170 | + } |
|
| 171 | + if ($r) { |
|
| 172 | + $charset = $r['valeur']; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + $ligne_rappel = install_mode_appel($server_db); |
|
| 176 | + |
|
| 177 | + $result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db); |
|
| 178 | + if (!$result_ok) { |
|
| 179 | + return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if ($chmod_db) { |
|
| 183 | + install_fichier_connexion( |
|
| 184 | + _FILE_CHMOD_TMP, |
|
| 185 | + "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 186 | + ); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // si ce fichier existe a cette etape c'est qu'il provient |
|
| 190 | + // d'une installation qui ne l'a pas cree correctement. |
|
| 191 | + // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 192 | + |
|
| 193 | + if (_FILE_CONNECT && file_exists(_FILE_CONNECT)) { |
|
| 194 | + spip_unlink(_FILE_CONNECT); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + install_fichier_connexion( |
|
| 198 | + _FILE_CONNECT_TMP, |
|
| 199 | + $ligne_rappel |
|
| 200 | + . install_connexion( |
|
| 201 | + $adresse_db, |
|
| 202 | + $port, |
|
| 203 | + $login_db, |
|
| 204 | + $pass_db, |
|
| 205 | + $sel_db, |
|
| 206 | + $server_db, |
|
| 207 | + $table_prefix, |
|
| 208 | + '', |
|
| 209 | + $charset |
|
| 210 | + ) |
|
| 211 | + ); |
|
| 212 | + |
|
| 213 | + return ''; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -225,166 +225,166 @@ discard block |
||
| 225 | 225 | * @return string Le préfixe corrigé |
| 226 | 226 | */ |
| 227 | 227 | function preparer_prefixe_tables($prefixe) { |
| 228 | - return trim(preg_replace(',^\d+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe)))); |
|
| 228 | + return trim(preg_replace(',^\d+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe)))); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | function install_propose_ldap() { |
| 232 | - return generer_form_ecrire('install', ( |
|
| 233 | - fieldset( |
|
| 234 | - _T('info_authentification_externe'), |
|
| 235 | - [ |
|
| 236 | - 'etape' => [ |
|
| 237 | - 'label' => _T('texte_annuaire_ldap_1'), |
|
| 238 | - 'valeur' => 'ldap1', |
|
| 239 | - 'hidden' => true |
|
| 240 | - ] |
|
| 241 | - ], |
|
| 242 | - bouton_suivant(_T('bouton_acces_ldap')) |
|
| 243 | - ))); |
|
| 232 | + return generer_form_ecrire('install', ( |
|
| 233 | + fieldset( |
|
| 234 | + _T('info_authentification_externe'), |
|
| 235 | + [ |
|
| 236 | + 'etape' => [ |
|
| 237 | + 'label' => _T('texte_annuaire_ldap_1'), |
|
| 238 | + 'valeur' => 'ldap1', |
|
| 239 | + 'hidden' => true |
|
| 240 | + ] |
|
| 241 | + ], |
|
| 242 | + bouton_suivant(_T('bouton_acces_ldap')) |
|
| 243 | + ))); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | |
| 247 | 247 | function install_premier_auteur($email, $login, $nom, #[\SensitiveParameter] $pass, $hidden, $auteur_obligatoire) { |
| 248 | - return info_progression_etape(3, 'etape_', 'install/') . |
|
| 249 | - info_etape( |
|
| 250 | - _T('info_informations_personnelles'), |
|
| 251 | - '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 252 | - aider('install5', true) . |
|
| 253 | - '<p>' . |
|
| 254 | - ($auteur_obligatoire ? |
|
| 255 | - '' |
|
| 256 | - : |
|
| 257 | - _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 258 | - ) |
|
| 259 | - ) |
|
| 260 | - . generer_form_ecrire('install', ( |
|
| 261 | - "\n<input type='hidden' name='etape' value='3b' />" |
|
| 262 | - . $hidden |
|
| 263 | - . fieldset( |
|
| 264 | - _T('info_identification_publique'), |
|
| 265 | - [ |
|
| 266 | - 'nom' => [ |
|
| 267 | - 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 268 | - 'valeur' => $nom, |
|
| 269 | - 'required' => $auteur_obligatoire, |
|
| 270 | - ], |
|
| 271 | - 'email' => [ |
|
| 272 | - 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 273 | - 'valeur' => $email, |
|
| 274 | - ] |
|
| 275 | - ] |
|
| 276 | - ) |
|
| 277 | - |
|
| 278 | - . fieldset( |
|
| 279 | - _T('entree_identifiants_connexion'), |
|
| 280 | - [ |
|
| 281 | - 'login' => [ |
|
| 282 | - 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 283 | - 'info_login_trop_court_car_pluriel', |
|
| 284 | - ['nb' => _LOGIN_TROP_COURT] |
|
| 285 | - ) . "\n", |
|
| 286 | - 'valeur' => $login, |
|
| 287 | - 'required' => $auteur_obligatoire, |
|
| 288 | - ], |
|
| 289 | - 'pass' => [ |
|
| 290 | - 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 291 | - 'info_passe_trop_court_car_pluriel', |
|
| 292 | - ['nb' => _PASS_LONGUEUR_MINI] |
|
| 293 | - ) . "\n", |
|
| 294 | - 'valeur' => $pass, |
|
| 295 | - 'required' => $auteur_obligatoire, |
|
| 296 | - ], |
|
| 297 | - 'pass_verif' => [ |
|
| 298 | - 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 299 | - 'valeur' => $pass, |
|
| 300 | - 'required' => $auteur_obligatoire, |
|
| 301 | - ] |
|
| 302 | - ] |
|
| 303 | - ) |
|
| 304 | - . bouton_suivant())); |
|
| 248 | + return info_progression_etape(3, 'etape_', 'install/') . |
|
| 249 | + info_etape( |
|
| 250 | + _T('info_informations_personnelles'), |
|
| 251 | + '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 252 | + aider('install5', true) . |
|
| 253 | + '<p>' . |
|
| 254 | + ($auteur_obligatoire ? |
|
| 255 | + '' |
|
| 256 | + : |
|
| 257 | + _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 258 | + ) |
|
| 259 | + ) |
|
| 260 | + . generer_form_ecrire('install', ( |
|
| 261 | + "\n<input type='hidden' name='etape' value='3b' />" |
|
| 262 | + . $hidden |
|
| 263 | + . fieldset( |
|
| 264 | + _T('info_identification_publique'), |
|
| 265 | + [ |
|
| 266 | + 'nom' => [ |
|
| 267 | + 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 268 | + 'valeur' => $nom, |
|
| 269 | + 'required' => $auteur_obligatoire, |
|
| 270 | + ], |
|
| 271 | + 'email' => [ |
|
| 272 | + 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 273 | + 'valeur' => $email, |
|
| 274 | + ] |
|
| 275 | + ] |
|
| 276 | + ) |
|
| 277 | + |
|
| 278 | + . fieldset( |
|
| 279 | + _T('entree_identifiants_connexion'), |
|
| 280 | + [ |
|
| 281 | + 'login' => [ |
|
| 282 | + 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 283 | + 'info_login_trop_court_car_pluriel', |
|
| 284 | + ['nb' => _LOGIN_TROP_COURT] |
|
| 285 | + ) . "\n", |
|
| 286 | + 'valeur' => $login, |
|
| 287 | + 'required' => $auteur_obligatoire, |
|
| 288 | + ], |
|
| 289 | + 'pass' => [ |
|
| 290 | + 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 291 | + 'info_passe_trop_court_car_pluriel', |
|
| 292 | + ['nb' => _PASS_LONGUEUR_MINI] |
|
| 293 | + ) . "\n", |
|
| 294 | + 'valeur' => $pass, |
|
| 295 | + 'required' => $auteur_obligatoire, |
|
| 296 | + ], |
|
| 297 | + 'pass_verif' => [ |
|
| 298 | + 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 299 | + 'valeur' => $pass, |
|
| 300 | + 'required' => $auteur_obligatoire, |
|
| 301 | + ] |
|
| 302 | + ] |
|
| 303 | + ) |
|
| 304 | + . bouton_suivant())); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | function install_etape_3_dist() { |
| 308 | - $ldap_present = _request('ldap_present'); |
|
| 309 | - |
|
| 310 | - if (!$ldap_present) { |
|
| 311 | - $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 312 | - ? _INSTALL_HOST_DB |
|
| 313 | - : _request('adresse_db'); |
|
| 314 | - |
|
| 315 | - $login_db = defined('_INSTALL_USER_DB') |
|
| 316 | - ? _INSTALL_USER_DB |
|
| 317 | - : _request('login_db'); |
|
| 318 | - |
|
| 319 | - $pass_db = defined('_INSTALL_PASS_DB') |
|
| 320 | - ? _INSTALL_PASS_DB |
|
| 321 | - : _request('pass_db'); |
|
| 322 | - |
|
| 323 | - $server_db = defined('_INSTALL_SERVER_DB') |
|
| 324 | - ? _INSTALL_SERVER_DB |
|
| 325 | - : _request('server_db'); |
|
| 326 | - |
|
| 327 | - $chmod_db = defined('_SPIP_CHMOD') |
|
| 328 | - ? _SPIP_CHMOD |
|
| 329 | - : _request('chmod'); |
|
| 330 | - |
|
| 331 | - $choix_db = defined('_INSTALL_NAME_DB') |
|
| 332 | - ? _INSTALL_NAME_DB |
|
| 333 | - : _request('choix_db'); |
|
| 334 | - |
|
| 335 | - $sel_db = ($choix_db == 'new_spip') |
|
| 336 | - ? _request('table_new') : $choix_db; |
|
| 337 | - |
|
| 338 | - $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 339 | - |
|
| 340 | - if ($res) { |
|
| 341 | - $res = info_progression_etape(2, 'etape_', 'install/', true) |
|
| 342 | - . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 343 | - . $res |
|
| 344 | - . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 345 | - . '</div>'; |
|
| 346 | - } |
|
| 347 | - } else { |
|
| 348 | - $res = ''; |
|
| 349 | - [$adresse_db, $login_db, $pass_db, $sel_db, $server_db] = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 350 | - $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if (!$res) { |
|
| 354 | - if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 355 | - include(_FILE_CONNECT_TMP); |
|
| 356 | - } else { |
|
| 357 | - redirige_url_ecrire('install'); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 361 | - include(_FILE_CHMOD_TMP); |
|
| 362 | - } else { |
|
| 363 | - redirige_url_ecrire('install'); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 367 | - . (defined('_INSTALL_NAME_DB') ? '' |
|
| 368 | - : "\n<input type='hidden' name='sel_db' value=\"" . spip_htmlspecialchars($sel_db) . '" />'); |
|
| 369 | - |
|
| 370 | - $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
|
| 371 | - |
|
| 372 | - $res = "<div class='success'><b>" |
|
| 373 | - . _T('info_base_installee') |
|
| 374 | - . '</b></div>' |
|
| 375 | - . install_premier_auteur( |
|
| 376 | - _request('email'), |
|
| 377 | - _request('login'), |
|
| 378 | - _request('nom'), |
|
| 379 | - _request('pass'), |
|
| 380 | - $hidden, |
|
| 381 | - $auteur_obligatoire |
|
| 382 | - ) |
|
| 383 | - . (($ldap_present || !function_exists('ldap_connect')) |
|
| 384 | - ? '' : install_propose_ldap()); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - $minipage = new Spip\Afficher\Minipage\Installation(); |
|
| 389 | - echo $minipage->page($res); |
|
| 308 | + $ldap_present = _request('ldap_present'); |
|
| 309 | + |
|
| 310 | + if (!$ldap_present) { |
|
| 311 | + $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 312 | + ? _INSTALL_HOST_DB |
|
| 313 | + : _request('adresse_db'); |
|
| 314 | + |
|
| 315 | + $login_db = defined('_INSTALL_USER_DB') |
|
| 316 | + ? _INSTALL_USER_DB |
|
| 317 | + : _request('login_db'); |
|
| 318 | + |
|
| 319 | + $pass_db = defined('_INSTALL_PASS_DB') |
|
| 320 | + ? _INSTALL_PASS_DB |
|
| 321 | + : _request('pass_db'); |
|
| 322 | + |
|
| 323 | + $server_db = defined('_INSTALL_SERVER_DB') |
|
| 324 | + ? _INSTALL_SERVER_DB |
|
| 325 | + : _request('server_db'); |
|
| 326 | + |
|
| 327 | + $chmod_db = defined('_SPIP_CHMOD') |
|
| 328 | + ? _SPIP_CHMOD |
|
| 329 | + : _request('chmod'); |
|
| 330 | + |
|
| 331 | + $choix_db = defined('_INSTALL_NAME_DB') |
|
| 332 | + ? _INSTALL_NAME_DB |
|
| 333 | + : _request('choix_db'); |
|
| 334 | + |
|
| 335 | + $sel_db = ($choix_db == 'new_spip') |
|
| 336 | + ? _request('table_new') : $choix_db; |
|
| 337 | + |
|
| 338 | + $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 339 | + |
|
| 340 | + if ($res) { |
|
| 341 | + $res = info_progression_etape(2, 'etape_', 'install/', true) |
|
| 342 | + . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 343 | + . $res |
|
| 344 | + . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 345 | + . '</div>'; |
|
| 346 | + } |
|
| 347 | + } else { |
|
| 348 | + $res = ''; |
|
| 349 | + [$adresse_db, $login_db, $pass_db, $sel_db, $server_db] = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 350 | + $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if (!$res) { |
|
| 354 | + if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 355 | + include(_FILE_CONNECT_TMP); |
|
| 356 | + } else { |
|
| 357 | + redirige_url_ecrire('install'); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 361 | + include(_FILE_CHMOD_TMP); |
|
| 362 | + } else { |
|
| 363 | + redirige_url_ecrire('install'); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 367 | + . (defined('_INSTALL_NAME_DB') ? '' |
|
| 368 | + : "\n<input type='hidden' name='sel_db' value=\"" . spip_htmlspecialchars($sel_db) . '" />'); |
|
| 369 | + |
|
| 370 | + $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
|
| 371 | + |
|
| 372 | + $res = "<div class='success'><b>" |
|
| 373 | + . _T('info_base_installee') |
|
| 374 | + . '</b></div>' |
|
| 375 | + . install_premier_auteur( |
|
| 376 | + _request('email'), |
|
| 377 | + _request('login'), |
|
| 378 | + _request('nom'), |
|
| 379 | + _request('pass'), |
|
| 380 | + $hidden, |
|
| 381 | + $auteur_obligatoire |
|
| 382 | + ) |
|
| 383 | + . (($ldap_present || !function_exists('ldap_connect')) |
|
| 384 | + ? '' : install_propose_ldap()); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + $minipage = new Spip\Afficher\Minipage\Installation(); |
|
| 389 | + echo $minipage->page($res); |
|
| 390 | 390 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -34,45 +34,45 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function install_etape_1_dist() { |
| 36 | 36 | |
| 37 | - $minipage = new Spip\Afficher\Minipage\Installation(); |
|
| 38 | - echo $minipage->installDebutPage(); |
|
| 37 | + $minipage = new Spip\Afficher\Minipage\Installation(); |
|
| 38 | + echo $minipage->installDebutPage(); |
|
| 39 | 39 | |
| 40 | - // stopper en cas de grosse incompatibilite de l'hebergement |
|
| 41 | - tester_compatibilite_hebergement(); |
|
| 40 | + // stopper en cas de grosse incompatibilite de l'hebergement |
|
| 41 | + tester_compatibilite_hebergement(); |
|
| 42 | 42 | |
| 43 | - // Recuperer les anciennes donnees pour plus de facilite (si presentes) |
|
| 44 | - $s = @is_readable(_FILE_CONNECT_TMP) ? analyse_fichier_connection(_FILE_CONNECT_TMP) : ''; |
|
| 43 | + // Recuperer les anciennes donnees pour plus de facilite (si presentes) |
|
| 44 | + $s = @is_readable(_FILE_CONNECT_TMP) ? analyse_fichier_connection(_FILE_CONNECT_TMP) : ''; |
|
| 45 | 45 | |
| 46 | - [$adresse_db, $login_db] = $s ?: ['localhost', '']; |
|
| 46 | + [$adresse_db, $login_db] = $s ?: ['localhost', '']; |
|
| 47 | 47 | |
| 48 | - $chmod = (isset($_GET['chmod']) && preg_match(',^\d+$,', $_GET['chmod'])) ? |
|
| 49 | - sprintf('%04o', $_GET['chmod']) : '0777'; |
|
| 48 | + $chmod = (isset($_GET['chmod']) && preg_match(',^\d+$,', $_GET['chmod'])) ? |
|
| 49 | + sprintf('%04o', $_GET['chmod']) : '0777'; |
|
| 50 | 50 | |
| 51 | - if (@is_readable(_FILE_CHMOD_TMP)) { |
|
| 52 | - $s = @implode('', @file(_FILE_CHMOD_TMP)); |
|
| 53 | - if (preg_match("#define\('_SPIP_CHMOD', (.*)\)#", $s, $regs)) { |
|
| 54 | - $chmod = $regs[1]; |
|
| 55 | - } |
|
| 56 | - } |
|
| 51 | + if (@is_readable(_FILE_CHMOD_TMP)) { |
|
| 52 | + $s = @implode('', @file(_FILE_CHMOD_TMP)); |
|
| 53 | + if (preg_match("#define\('_SPIP_CHMOD', (.*)\)#", $s, $regs)) { |
|
| 54 | + $chmod = $regs[1]; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | - $db = [$adresse_db, _T('entree_base_donnee_2')]; |
|
| 60 | - $login = [$login_db, _T('entree_login_connexion_2')]; |
|
| 61 | - $pass = ['', _T('entree_mot_passe_2')]; |
|
| 59 | + $db = [$adresse_db, _T('entree_base_donnee_2')]; |
|
| 60 | + $login = [$login_db, _T('entree_login_connexion_2')]; |
|
| 61 | + $pass = ['', _T('entree_mot_passe_2')]; |
|
| 62 | 62 | |
| 63 | - $predef = [ |
|
| 64 | - defined('_INSTALL_SERVER_DB') ? _INSTALL_SERVER_DB : '', |
|
| 65 | - defined('_INSTALL_HOST_DB'), |
|
| 66 | - defined('_INSTALL_USER_DB'), |
|
| 67 | - defined('_INSTALL_PASS_DB') |
|
| 68 | - ]; |
|
| 63 | + $predef = [ |
|
| 64 | + defined('_INSTALL_SERVER_DB') ? _INSTALL_SERVER_DB : '', |
|
| 65 | + defined('_INSTALL_HOST_DB'), |
|
| 66 | + defined('_INSTALL_USER_DB'), |
|
| 67 | + defined('_INSTALL_PASS_DB') |
|
| 68 | + ]; |
|
| 69 | 69 | |
| 70 | 70 | |
| 71 | - echo info_progression_etape(1, 'etape_', 'install/'); |
|
| 71 | + echo info_progression_etape(1, 'etape_', 'install/'); |
|
| 72 | 72 | |
| 73 | - // ces deux chaines de langues doivent etre reecrites |
|
| 73 | + // ces deux chaines de langues doivent etre reecrites |
|
| 74 | 74 | # echo info_etape(_T('info_connexion_mysql'), _T('texte_connexion_mysql').aide ("install1", true)); |
| 75 | - echo info_etape(_T('info_connexion_base_donnee')); |
|
| 76 | - echo install_connexion_form($db, $login, $pass, $predef, "\n<input type='hidden' name='chmod' value='$chmod' />", 2); |
|
| 77 | - echo $minipage->installFinPage(); |
|
| 75 | + echo info_etape(_T('info_connexion_base_donnee')); |
|
| 76 | + echo install_connexion_form($db, $login, $pass, $predef, "\n<input type='hidden' name='chmod' value='$chmod' />", 2); |
|
| 77 | + echo $minipage->installFinPage(); |
|
| 78 | 78 | } |
@@ -20,188 +20,188 @@ |
||
| 20 | 20 | // par souci de compatiilite). |
| 21 | 21 | |
| 22 | 22 | if (isset($GLOBALS['_INC_PUBLIC']) && $GLOBALS['_INC_PUBLIC']) { |
| 23 | - echo recuperer_fond($fond, $contexte_inclus, [], _request('connect') ?? ''); |
|
| 23 | + echo recuperer_fond($fond, $contexte_inclus, [], _request('connect') ?? ''); |
|
| 24 | 24 | } else { |
| 25 | - $GLOBALS['_INC_PUBLIC'] = 1; |
|
| 26 | - define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : ''); |
|
| 27 | - |
|
| 28 | - // Faut-il initialiser SPIP ? (oui dans le cas general) |
|
| 29 | - if (!defined('_DIR_RESTREINT_ABS')) { |
|
| 30 | - if ( |
|
| 31 | - defined('_DIR_RESTREINT') |
|
| 32 | - && @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 33 | - ) { |
|
| 34 | - include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 35 | - } else { |
|
| 36 | - die('inc_version absent ?'); |
|
| 37 | - } |
|
| 38 | - } // $fond defini dans le fichier d'appel ? |
|
| 39 | - |
|
| 40 | - else { |
|
| 41 | - if (isset($fond) && !_request('fond')) { |
|
| 42 | - } // fond demande dans l'url par page=xxxx ? |
|
| 43 | - else { |
|
| 44 | - if (isset($_GET[_SPIP_PAGE])) { |
|
| 45 | - $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 46 | - |
|
| 47 | - // Securite |
|
| 48 | - if ( |
|
| 49 | - strstr($fond, '/') |
|
| 50 | - && !(isset($GLOBALS['visiteur_session']) && include_spip('inc/autoriser') && autoriser('webmestre')) |
|
| 51 | - ) { |
|
| 52 | - include_spip('inc/minipres'); |
|
| 53 | - echo minipres(); |
|
| 54 | - exit; |
|
| 55 | - } |
|
| 56 | - // l'argument Page a priorite sur l'argument action |
|
| 57 | - // le cas se presente a cause des RewriteRule d'Apache |
|
| 58 | - // qui permettent d'ajouter un argument dans la QueryString |
|
| 59 | - // mais pas d'en retirer un en conservant les autres. |
|
| 60 | - if (isset($_GET['action']) && $_GET['action'] === $fond) { |
|
| 61 | - unset($_GET['action']); |
|
| 62 | - } |
|
| 63 | - # sinon, fond par defaut |
|
| 64 | - } else { |
|
| 65 | - // sinon fond par defaut (cf. assembler.php) |
|
| 66 | - $fond = pipeline('detecter_fond_par_defaut', ''); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $tableau_des_temps = []; |
|
| 72 | - |
|
| 73 | - // Particularites de certains squelettes |
|
| 74 | - if ($fond == 'login') { |
|
| 75 | - $forcer_lang = true; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if ( |
|
| 79 | - isset($forcer_lang) && $forcer_lang && $forcer_lang !== 'non' |
|
| 80 | - && !_request('action') |
|
| 81 | - && $_SERVER['REQUEST_METHOD'] != 'POST' |
|
| 82 | - ) { |
|
| 83 | - include_spip('inc/lang'); |
|
| 84 | - verifier_lang_url(); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $lang = isset($_GET['lang']) ? lang_select($_GET['lang']) : ''; |
|
| 88 | - |
|
| 89 | - // Charger l'aiguilleur des traitements derogatoires |
|
| 90 | - // (action en base SQL, formulaires CVT, AJax) |
|
| 91 | - if (_request('action') || _request('var_ajax') || _request('formulaire_action')) { |
|
| 92 | - include_spip('public/aiguiller'); |
|
| 93 | - if ( |
|
| 94 | - // cas des appels actions ?action=xxx |
|
| 95 | - traiter_appels_actions() |
|
| 96 | - // cas des hits ajax sur les inclusions ajax |
|
| 97 | - || traiter_appels_inclusions_ajax() |
|
| 98 | - // cas des formulaires charger/verifier/traiter |
|
| 99 | - || traiter_formulaires_dynamiques() |
|
| 100 | - ) { |
|
| 101 | - // lancer les taches sur affichage final, comme le cron |
|
| 102 | - // mais sans rien afficher |
|
| 103 | - $GLOBALS['html'] = false; // ne rien afficher |
|
| 104 | - pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 105 | - exit; // le hit est fini ! |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // Il y a du texte a produire, charger le metteur en page |
|
| 110 | - include_spip('public/assembler'); |
|
| 111 | - $page = assembler($fond, _request('connect') ?? ''); |
|
| 112 | - |
|
| 113 | - if (isset($page['status'])) { |
|
| 114 | - include_spip('inc/headers'); |
|
| 115 | - http_response_code($page['status']); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // Content-Type ? |
|
| 119 | - if (!isset($page['entetes']['Content-Type'])) { |
|
| 120 | - $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
|
| 121 | - $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 122 | - $html = true; |
|
| 123 | - } else { |
|
| 124 | - $html = preg_match(',^\s*text/html,', $page['entetes']['Content-Type']); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // Tester si on est admin et il y a des choses supplementaires a dire |
|
| 128 | - // type tableau pour y mettre des choses au besoin. |
|
| 129 | - $debug = (_request('var_mode') == 'debug' || $tableau_des_temps) ? [1] : []; |
|
| 130 | - |
|
| 131 | - // affiche-t-on les boutons d'administration ? voir f_admin() |
|
| 132 | - $affiche_boutons_admin = ($html && ( |
|
| 133 | - isset($_COOKIE['spip_admin']) && (!isset($flag_preserver) || !$flag_preserver) |
|
| 134 | - || $debug && include_spip('inc/autoriser') && autoriser('debug') |
|
| 135 | - || defined('_VAR_PREVIEW') && _VAR_PREVIEW) |
|
| 136 | - ); |
|
| 137 | - |
|
| 138 | - if ($affiche_boutons_admin) { |
|
| 139 | - include_spip('balise/formulaire_admin'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - // Execution de la page calculee |
|
| 144 | - |
|
| 145 | - // traitements sur les entetes avant envoi |
|
| 146 | - // peut servir pour le plugin de stats |
|
| 147 | - $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - // eval $page et affecte $res |
|
| 151 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 152 | - envoyer_entetes($page['entetes']); |
|
| 153 | - if ($res === false) { |
|
| 154 | - include_spip('inc/autoriser'); |
|
| 155 | - $err = _T('zbug_erreur_execution_page'); |
|
| 156 | - if (autoriser('webmestre')) { |
|
| 157 | - $err .= "\n<hr />\n" |
|
| 158 | - . highlight_string($page['codephp'], true) |
|
| 159 | - . "\n<hr />\n"; |
|
| 160 | - } |
|
| 161 | - $msg = [$err]; |
|
| 162 | - erreur_squelette($msg); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // |
|
| 166 | - // Envoyer le resultat apres post-traitements |
|
| 167 | - // |
|
| 168 | - // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
|
| 169 | - // cf. public/assembler.php) |
|
| 170 | - echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 171 | - |
|
| 172 | - if ($lang) { |
|
| 173 | - lang_select(); |
|
| 174 | - } |
|
| 175 | - // l'affichage de la page a pu lever des erreurs (inclusion manquante) |
|
| 176 | - // il faut tester a nouveau |
|
| 177 | - $debug = (_request('var_mode') == 'debug' || $tableau_des_temps) ? [1] : []; |
|
| 178 | - |
|
| 179 | - // Appel au debusqueur en cas d'erreurs ou de demande de trace |
|
| 180 | - // at last |
|
| 181 | - if ($debug) { |
|
| 182 | - // en cas d'erreur, retester l'affichage |
|
| 183 | - if ($html && ($affiche_boutons_admin || $debug)) { |
|
| 184 | - $var_mode_affiche = _request('var_mode_affiche'); |
|
| 185 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 186 | - $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 187 | - echo erreur_squelette(false); |
|
| 188 | - } |
|
| 189 | - } else { |
|
| 190 | - if ( |
|
| 191 | - isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 192 | - && $GLOBALS['meta']['date_prochain_postdate'] <= time() |
|
| 193 | - ) { |
|
| 194 | - include_spip('inc/rubriques'); |
|
| 195 | - calculer_prochain_postdate(true); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - // Effectuer une tache de fond ? |
|
| 199 | - // si _DIRECT_CRON_FORCE est present, on force l'appel |
|
| 200 | - if (defined('_DIRECT_CRON_FORCE')) { |
|
| 201 | - cron(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // sauver le cache chemin si necessaire |
|
| 205 | - save_path_cache(); |
|
| 206 | - } |
|
| 25 | + $GLOBALS['_INC_PUBLIC'] = 1; |
|
| 26 | + define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : ''); |
|
| 27 | + |
|
| 28 | + // Faut-il initialiser SPIP ? (oui dans le cas general) |
|
| 29 | + if (!defined('_DIR_RESTREINT_ABS')) { |
|
| 30 | + if ( |
|
| 31 | + defined('_DIR_RESTREINT') |
|
| 32 | + && @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 33 | + ) { |
|
| 34 | + include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 35 | + } else { |
|
| 36 | + die('inc_version absent ?'); |
|
| 37 | + } |
|
| 38 | + } // $fond defini dans le fichier d'appel ? |
|
| 39 | + |
|
| 40 | + else { |
|
| 41 | + if (isset($fond) && !_request('fond')) { |
|
| 42 | + } // fond demande dans l'url par page=xxxx ? |
|
| 43 | + else { |
|
| 44 | + if (isset($_GET[_SPIP_PAGE])) { |
|
| 45 | + $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 46 | + |
|
| 47 | + // Securite |
|
| 48 | + if ( |
|
| 49 | + strstr($fond, '/') |
|
| 50 | + && !(isset($GLOBALS['visiteur_session']) && include_spip('inc/autoriser') && autoriser('webmestre')) |
|
| 51 | + ) { |
|
| 52 | + include_spip('inc/minipres'); |
|
| 53 | + echo minipres(); |
|
| 54 | + exit; |
|
| 55 | + } |
|
| 56 | + // l'argument Page a priorite sur l'argument action |
|
| 57 | + // le cas se presente a cause des RewriteRule d'Apache |
|
| 58 | + // qui permettent d'ajouter un argument dans la QueryString |
|
| 59 | + // mais pas d'en retirer un en conservant les autres. |
|
| 60 | + if (isset($_GET['action']) && $_GET['action'] === $fond) { |
|
| 61 | + unset($_GET['action']); |
|
| 62 | + } |
|
| 63 | + # sinon, fond par defaut |
|
| 64 | + } else { |
|
| 65 | + // sinon fond par defaut (cf. assembler.php) |
|
| 66 | + $fond = pipeline('detecter_fond_par_defaut', ''); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $tableau_des_temps = []; |
|
| 72 | + |
|
| 73 | + // Particularites de certains squelettes |
|
| 74 | + if ($fond == 'login') { |
|
| 75 | + $forcer_lang = true; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if ( |
|
| 79 | + isset($forcer_lang) && $forcer_lang && $forcer_lang !== 'non' |
|
| 80 | + && !_request('action') |
|
| 81 | + && $_SERVER['REQUEST_METHOD'] != 'POST' |
|
| 82 | + ) { |
|
| 83 | + include_spip('inc/lang'); |
|
| 84 | + verifier_lang_url(); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $lang = isset($_GET['lang']) ? lang_select($_GET['lang']) : ''; |
|
| 88 | + |
|
| 89 | + // Charger l'aiguilleur des traitements derogatoires |
|
| 90 | + // (action en base SQL, formulaires CVT, AJax) |
|
| 91 | + if (_request('action') || _request('var_ajax') || _request('formulaire_action')) { |
|
| 92 | + include_spip('public/aiguiller'); |
|
| 93 | + if ( |
|
| 94 | + // cas des appels actions ?action=xxx |
|
| 95 | + traiter_appels_actions() |
|
| 96 | + // cas des hits ajax sur les inclusions ajax |
|
| 97 | + || traiter_appels_inclusions_ajax() |
|
| 98 | + // cas des formulaires charger/verifier/traiter |
|
| 99 | + || traiter_formulaires_dynamiques() |
|
| 100 | + ) { |
|
| 101 | + // lancer les taches sur affichage final, comme le cron |
|
| 102 | + // mais sans rien afficher |
|
| 103 | + $GLOBALS['html'] = false; // ne rien afficher |
|
| 104 | + pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 105 | + exit; // le hit est fini ! |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // Il y a du texte a produire, charger le metteur en page |
|
| 110 | + include_spip('public/assembler'); |
|
| 111 | + $page = assembler($fond, _request('connect') ?? ''); |
|
| 112 | + |
|
| 113 | + if (isset($page['status'])) { |
|
| 114 | + include_spip('inc/headers'); |
|
| 115 | + http_response_code($page['status']); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // Content-Type ? |
|
| 119 | + if (!isset($page['entetes']['Content-Type'])) { |
|
| 120 | + $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
|
| 121 | + $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 122 | + $html = true; |
|
| 123 | + } else { |
|
| 124 | + $html = preg_match(',^\s*text/html,', $page['entetes']['Content-Type']); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // Tester si on est admin et il y a des choses supplementaires a dire |
|
| 128 | + // type tableau pour y mettre des choses au besoin. |
|
| 129 | + $debug = (_request('var_mode') == 'debug' || $tableau_des_temps) ? [1] : []; |
|
| 130 | + |
|
| 131 | + // affiche-t-on les boutons d'administration ? voir f_admin() |
|
| 132 | + $affiche_boutons_admin = ($html && ( |
|
| 133 | + isset($_COOKIE['spip_admin']) && (!isset($flag_preserver) || !$flag_preserver) |
|
| 134 | + || $debug && include_spip('inc/autoriser') && autoriser('debug') |
|
| 135 | + || defined('_VAR_PREVIEW') && _VAR_PREVIEW) |
|
| 136 | + ); |
|
| 137 | + |
|
| 138 | + if ($affiche_boutons_admin) { |
|
| 139 | + include_spip('balise/formulaire_admin'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + // Execution de la page calculee |
|
| 144 | + |
|
| 145 | + // traitements sur les entetes avant envoi |
|
| 146 | + // peut servir pour le plugin de stats |
|
| 147 | + $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + // eval $page et affecte $res |
|
| 151 | + include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 152 | + envoyer_entetes($page['entetes']); |
|
| 153 | + if ($res === false) { |
|
| 154 | + include_spip('inc/autoriser'); |
|
| 155 | + $err = _T('zbug_erreur_execution_page'); |
|
| 156 | + if (autoriser('webmestre')) { |
|
| 157 | + $err .= "\n<hr />\n" |
|
| 158 | + . highlight_string($page['codephp'], true) |
|
| 159 | + . "\n<hr />\n"; |
|
| 160 | + } |
|
| 161 | + $msg = [$err]; |
|
| 162 | + erreur_squelette($msg); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // |
|
| 166 | + // Envoyer le resultat apres post-traitements |
|
| 167 | + // |
|
| 168 | + // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
|
| 169 | + // cf. public/assembler.php) |
|
| 170 | + echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 171 | + |
|
| 172 | + if ($lang) { |
|
| 173 | + lang_select(); |
|
| 174 | + } |
|
| 175 | + // l'affichage de la page a pu lever des erreurs (inclusion manquante) |
|
| 176 | + // il faut tester a nouveau |
|
| 177 | + $debug = (_request('var_mode') == 'debug' || $tableau_des_temps) ? [1] : []; |
|
| 178 | + |
|
| 179 | + // Appel au debusqueur en cas d'erreurs ou de demande de trace |
|
| 180 | + // at last |
|
| 181 | + if ($debug) { |
|
| 182 | + // en cas d'erreur, retester l'affichage |
|
| 183 | + if ($html && ($affiche_boutons_admin || $debug)) { |
|
| 184 | + $var_mode_affiche = _request('var_mode_affiche'); |
|
| 185 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 186 | + $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 187 | + echo erreur_squelette(false); |
|
| 188 | + } |
|
| 189 | + } else { |
|
| 190 | + if ( |
|
| 191 | + isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 192 | + && $GLOBALS['meta']['date_prochain_postdate'] <= time() |
|
| 193 | + ) { |
|
| 194 | + include_spip('inc/rubriques'); |
|
| 195 | + calculer_prochain_postdate(true); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + // Effectuer une tache de fond ? |
|
| 199 | + // si _DIRECT_CRON_FORCE est present, on force l'appel |
|
| 200 | + if (defined('_DIRECT_CRON_FORCE')) { |
|
| 201 | + cron(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // sauver le cache chemin si necessaire |
|
| 205 | + save_path_cache(); |
|
| 206 | + } |
|
| 207 | 207 | } |
@@ -10,73 +10,73 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | // Correction typographique francaise |
| 17 | 17 | |
| 18 | 18 | function typographie_fr_dist($letexte) { |
| 19 | 19 | |
| 20 | - static $trans; |
|
| 20 | + static $trans; |
|
| 21 | 21 | |
| 22 | - // Nettoyer 160 = nbsp ; 187 = raquo ; 171 = laquo ; 176 = deg ; |
|
| 23 | - // 147 = ldquo; 148 = rdquo; ' = zouli apostrophe |
|
| 24 | - if (!$trans) { |
|
| 25 | - $trans = [ |
|
| 26 | - "'" => '’', |
|
| 27 | - ' ' => '~', |
|
| 28 | - '»' => '»', |
|
| 29 | - '«' => '«', |
|
| 30 | - '”' => '”', |
|
| 31 | - '“' => '“', |
|
| 32 | - '°' => '°' |
|
| 33 | - ]; |
|
| 34 | - $chars = [160 => '~', 187 => '»', 171 => '«', 148 => '”', 147 => '“', 176 => '°']; |
|
| 35 | - $chars_trans = array_keys($chars); |
|
| 36 | - $chars = array_values($chars); |
|
| 37 | - $chars_trans = implode(' ', array_map('chr', $chars_trans)); |
|
| 38 | - $chars_trans = unicode2charset(charset2unicode($chars_trans, 'iso-8859-1', 'forcer')); |
|
| 39 | - $chars_trans = explode(' ', $chars_trans); |
|
| 40 | - foreach ($chars as $k => $r) { |
|
| 41 | - $trans[$chars_trans[$k]] = $r; |
|
| 42 | - } |
|
| 43 | - } |
|
| 22 | + // Nettoyer 160 = nbsp ; 187 = raquo ; 171 = laquo ; 176 = deg ; |
|
| 23 | + // 147 = ldquo; 148 = rdquo; ' = zouli apostrophe |
|
| 24 | + if (!$trans) { |
|
| 25 | + $trans = [ |
|
| 26 | + "'" => '’', |
|
| 27 | + ' ' => '~', |
|
| 28 | + '»' => '»', |
|
| 29 | + '«' => '«', |
|
| 30 | + '”' => '”', |
|
| 31 | + '“' => '“', |
|
| 32 | + '°' => '°' |
|
| 33 | + ]; |
|
| 34 | + $chars = [160 => '~', 187 => '»', 171 => '«', 148 => '”', 147 => '“', 176 => '°']; |
|
| 35 | + $chars_trans = array_keys($chars); |
|
| 36 | + $chars = array_values($chars); |
|
| 37 | + $chars_trans = implode(' ', array_map('chr', $chars_trans)); |
|
| 38 | + $chars_trans = unicode2charset(charset2unicode($chars_trans, 'iso-8859-1', 'forcer')); |
|
| 39 | + $chars_trans = explode(' ', $chars_trans); |
|
| 40 | + foreach ($chars as $k => $r) { |
|
| 41 | + $trans[$chars_trans[$k]] = $r; |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - $letexte = strtr($letexte, $trans); |
|
| 45 | + $letexte = strtr($letexte, $trans); |
|
| 46 | 46 | |
| 47 | - $cherche1 = [ |
|
| 48 | - /* 1 */ |
|
| 49 | - '/((?:^|[^\#0-9a-zA-Z\&])[\#0-9a-zA-Z]*)\;/S', |
|
| 50 | - /* 2 */ |
|
| 51 | - '/»| --?,|(?::(?!:)| %)(?:\W|$)/S', |
|
| 52 | - /* 3 */ |
|
| 53 | - '/([^[<(!?.])([!?][!?\.]*)/iS', |
|
| 54 | - /* 4 */ |
|
| 55 | - '/«|(?:M(?:M?\.|mes?|r\.?)|[MnN]°) /S' |
|
| 56 | - ]; |
|
| 57 | - $remplace1 = [ |
|
| 58 | - /* 1 */ |
|
| 59 | - '\1~;', |
|
| 60 | - /* 2 */ |
|
| 61 | - '~\0', |
|
| 62 | - /* 3 */ |
|
| 63 | - '\1~\2', |
|
| 64 | - /* 4 */ |
|
| 65 | - '\0~' |
|
| 66 | - ]; |
|
| 67 | - $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 68 | - $letexte = preg_replace('/ *~+ */S', '~', $letexte); |
|
| 47 | + $cherche1 = [ |
|
| 48 | + /* 1 */ |
|
| 49 | + '/((?:^|[^\#0-9a-zA-Z\&])[\#0-9a-zA-Z]*)\;/S', |
|
| 50 | + /* 2 */ |
|
| 51 | + '/»| --?,|(?::(?!:)| %)(?:\W|$)/S', |
|
| 52 | + /* 3 */ |
|
| 53 | + '/([^[<(!?.])([!?][!?\.]*)/iS', |
|
| 54 | + /* 4 */ |
|
| 55 | + '/«|(?:M(?:M?\.|mes?|r\.?)|[MnN]°) /S' |
|
| 56 | + ]; |
|
| 57 | + $remplace1 = [ |
|
| 58 | + /* 1 */ |
|
| 59 | + '\1~;', |
|
| 60 | + /* 2 */ |
|
| 61 | + '~\0', |
|
| 62 | + /* 3 */ |
|
| 63 | + '\1~\2', |
|
| 64 | + /* 4 */ |
|
| 65 | + '\0~' |
|
| 66 | + ]; |
|
| 67 | + $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 68 | + $letexte = preg_replace('/ *~+ */S', '~', $letexte); |
|
| 69 | 69 | |
| 70 | - $cherche2 = [ |
|
| 71 | - '/([^-\n]|^)--([^-]|$)/S', |
|
| 72 | - ',(' . _PROTOCOLES_STD . ')~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S', |
|
| 73 | - '/~/' |
|
| 74 | - ]; |
|
| 75 | - $remplace2 = [ |
|
| 76 | - '\1—\2', |
|
| 77 | - '\1\3\4', |
|
| 78 | - ' ' |
|
| 79 | - ]; |
|
| 70 | + $cherche2 = [ |
|
| 71 | + '/([^-\n]|^)--([^-]|$)/S', |
|
| 72 | + ',(' . _PROTOCOLES_STD . ')~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S', |
|
| 73 | + '/~/' |
|
| 74 | + ]; |
|
| 75 | + $remplace2 = [ |
|
| 76 | + '\1—\2', |
|
| 77 | + '\1\3\4', |
|
| 78 | + ' ' |
|
| 79 | + ]; |
|
| 80 | 80 | |
| 81 | - return preg_replace($cherche2, $remplace2, $letexte); |
|
| 81 | + return preg_replace($cherche2, $remplace2, $letexte); |
|
| 82 | 82 | } |
@@ -10,35 +10,35 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | // rien sauf les "~" et "-," |
| 17 | 17 | |
| 18 | 18 | function typographie_en_dist($letexte) { |
| 19 | 19 | |
| 20 | - // zouli apostrophe |
|
| 21 | - $letexte = str_replace("'", '’', $letexte); |
|
| 22 | - |
|
| 23 | - $cherche1 = [ |
|
| 24 | - '/ --?,/S' |
|
| 25 | - ]; |
|
| 26 | - $remplace1 = [ |
|
| 27 | - '~\0' |
|
| 28 | - ]; |
|
| 29 | - $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 30 | - |
|
| 31 | - $letexte = str_replace(' ', '~', $letexte); |
|
| 32 | - $letexte = preg_replace('/ *~+ */', '~', $letexte); |
|
| 33 | - |
|
| 34 | - $cherche2 = [ |
|
| 35 | - '/([^-\n]|^)--([^-]|$)/', |
|
| 36 | - '/~/' |
|
| 37 | - ]; |
|
| 38 | - $remplace2 = [ |
|
| 39 | - '\1—\2', |
|
| 40 | - ' ' |
|
| 41 | - ]; |
|
| 42 | - |
|
| 43 | - return preg_replace($cherche2, $remplace2, $letexte); |
|
| 20 | + // zouli apostrophe |
|
| 21 | + $letexte = str_replace("'", '’', $letexte); |
|
| 22 | + |
|
| 23 | + $cherche1 = [ |
|
| 24 | + '/ --?,/S' |
|
| 25 | + ]; |
|
| 26 | + $remplace1 = [ |
|
| 27 | + '~\0' |
|
| 28 | + ]; |
|
| 29 | + $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 30 | + |
|
| 31 | + $letexte = str_replace(' ', '~', $letexte); |
|
| 32 | + $letexte = preg_replace('/ *~+ */', '~', $letexte); |
|
| 33 | + |
|
| 34 | + $cherche2 = [ |
|
| 35 | + '/([^-\n]|^)--([^-]|$)/', |
|
| 36 | + '/~/' |
|
| 37 | + ]; |
|
| 38 | + $remplace2 = [ |
|
| 39 | + '\1—\2', |
|
| 40 | + ' ' |
|
| 41 | + ]; |
|
| 42 | + |
|
| 43 | + return preg_replace($cherche2, $remplace2, $letexte); |
|
| 44 | 44 | } |
@@ -10,53 +10,53 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | // Fonction appelee par divers pipelines |
| 17 | 17 | function notifications_instituerarticle_dist($quoi, $id_article, $options) { |
| 18 | 18 | |
| 19 | - // ne devrait jamais se produire |
|
| 20 | - if ($options['statut'] == $options['statut_ancien']) { |
|
| 21 | - spip_log('statut inchange', 'notifications'); |
|
| 22 | - |
|
| 23 | - return; |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - include_spip('inc/texte'); |
|
| 27 | - |
|
| 28 | - $modele = ''; |
|
| 29 | - if ($options['statut'] == 'publie') { |
|
| 30 | - if ( |
|
| 31 | - $GLOBALS['meta']['post_dates'] == 'non' |
|
| 32 | - && strtotime($options['date']) > time() |
|
| 33 | - ) { |
|
| 34 | - $modele = 'notifications/article_valide'; |
|
| 35 | - } else { |
|
| 36 | - $modele = 'notifications/article_publie'; |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - if ($options['statut'] == 'prop' && $options['statut_ancien'] != 'publie') { |
|
| 41 | - $modele = 'notifications/article_propose'; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - if ($modele) { |
|
| 45 | - $destinataires = []; |
|
| 46 | - if ($GLOBALS['meta']['suivi_edito'] == 'oui') { |
|
| 47 | - $destinataires = explode(',', $GLOBALS['meta']['adresse_suivi']); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - $destinataires = pipeline( |
|
| 52 | - 'notifications_destinataires', |
|
| 53 | - [ |
|
| 54 | - 'args' => ['quoi' => $quoi, 'id' => $id_article, 'options' => $options], |
|
| 55 | - 'data' => $destinataires |
|
| 56 | - ] |
|
| 57 | - ); |
|
| 58 | - |
|
| 59 | - $texte = email_notification_article($id_article, $modele); |
|
| 60 | - notifications_envoyer_mails($destinataires, $texte); |
|
| 61 | - } |
|
| 19 | + // ne devrait jamais se produire |
|
| 20 | + if ($options['statut'] == $options['statut_ancien']) { |
|
| 21 | + spip_log('statut inchange', 'notifications'); |
|
| 22 | + |
|
| 23 | + return; |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + include_spip('inc/texte'); |
|
| 27 | + |
|
| 28 | + $modele = ''; |
|
| 29 | + if ($options['statut'] == 'publie') { |
|
| 30 | + if ( |
|
| 31 | + $GLOBALS['meta']['post_dates'] == 'non' |
|
| 32 | + && strtotime($options['date']) > time() |
|
| 33 | + ) { |
|
| 34 | + $modele = 'notifications/article_valide'; |
|
| 35 | + } else { |
|
| 36 | + $modele = 'notifications/article_publie'; |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + if ($options['statut'] == 'prop' && $options['statut_ancien'] != 'publie') { |
|
| 41 | + $modele = 'notifications/article_propose'; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + if ($modele) { |
|
| 45 | + $destinataires = []; |
|
| 46 | + if ($GLOBALS['meta']['suivi_edito'] == 'oui') { |
|
| 47 | + $destinataires = explode(',', $GLOBALS['meta']['adresse_suivi']); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + $destinataires = pipeline( |
|
| 52 | + 'notifications_destinataires', |
|
| 53 | + [ |
|
| 54 | + 'args' => ['quoi' => $quoi, 'id' => $id_article, 'options' => $options], |
|
| 55 | + 'data' => $destinataires |
|
| 56 | + ] |
|
| 57 | + ); |
|
| 58 | + |
|
| 59 | + $texte = email_notification_article($id_article, $modele); |
|
| 60 | + notifications_envoyer_mails($destinataires, $texte); |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -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 | |
@@ -34,11 +34,11 @@ discard block |
||
| 34 | 34 | * Chaine sinon : le nom du champ (non décomposable donc) |
| 35 | 35 | */ |
| 36 | 36 | function decompose_champ_id_objet($champ) { |
| 37 | - if ($champ !== 'id_objet' && preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 38 | - return ['id_objet', 'objet', objet_type($champ)]; |
|
| 39 | - } |
|
| 37 | + if ($champ !== 'id_objet' && preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 38 | + return ['id_objet', 'objet', objet_type($champ)]; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - return $champ; |
|
| 41 | + return $champ; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -57,21 +57,21 @@ discard block |
||
| 57 | 57 | * - array(id_objet, objet), si le champ n'existe pas mais qu'on peut décomposer |
| 58 | 58 | */ |
| 59 | 59 | function trouver_champs_decomposes($champ, $desc) { |
| 60 | - if ( |
|
| 61 | - !is_array($desc) |
|
| 62 | - || array_key_exists($champ, $desc['field']) |
|
| 63 | - ) { |
|
| 64 | - return [$champ]; |
|
| 65 | - } |
|
| 66 | - // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 67 | - if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 68 | - array_pop($decompose); |
|
| 69 | - if (count(array_intersect($decompose, array_keys($desc['field']))) === count($decompose)) { |
|
| 70 | - return $decompose; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return [$champ]; |
|
| 60 | + if ( |
|
| 61 | + !is_array($desc) |
|
| 62 | + || array_key_exists($champ, $desc['field']) |
|
| 63 | + ) { |
|
| 64 | + return [$champ]; |
|
| 65 | + } |
|
| 66 | + // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 67 | + if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 68 | + array_pop($decompose); |
|
| 69 | + if (count(array_intersect($decompose, array_keys($desc['field']))) === count($decompose)) { |
|
| 70 | + return $decompose; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return [$champ]; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
@@ -101,23 +101,23 @@ discard block |
||
| 101 | 101 | * Alias de la table de jointure (Lx) |
| 102 | 102 | */ |
| 103 | 103 | function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens = 5) { |
| 104 | - // les jointures minimales sont optimales : |
|
| 105 | - // on contraint le nombre d'etapes en l'augmentant |
|
| 106 | - // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 107 | - $max = 1; |
|
| 108 | - $res = false; |
|
| 109 | - $milieu_exclus = ($col ?: []); |
|
| 110 | - while ($max <= $max_liens && !$res) { |
|
| 111 | - $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 112 | - $max++; |
|
| 113 | - } |
|
| 114 | - if (!$res) { |
|
| 115 | - return ''; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - [$nom, $desc] = $depart; |
|
| 119 | - |
|
| 120 | - return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 104 | + // les jointures minimales sont optimales : |
|
| 105 | + // on contraint le nombre d'etapes en l'augmentant |
|
| 106 | + // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 107 | + $max = 1; |
|
| 108 | + $res = false; |
|
| 109 | + $milieu_exclus = ($col ?: []); |
|
| 110 | + while ($max <= $max_liens && !$res) { |
|
| 111 | + $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 112 | + $max++; |
|
| 113 | + } |
|
| 114 | + if (!$res) { |
|
| 115 | + return ''; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + [$nom, $desc] = $depart; |
|
| 119 | + |
|
| 120 | + return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -156,78 +156,78 @@ discard block |
||
| 156 | 156 | * Alias de la table de jointure (Lx) |
| 157 | 157 | */ |
| 158 | 158 | function fabrique_jointures(&$boucle, $res, $cond = false, $desc = [], $nom = '', $col = '', $echap = true) { |
| 159 | - $a = []; |
|
| 160 | - $j = null; |
|
| 161 | - $n = null; |
|
| 162 | - static $num = []; |
|
| 163 | - $id_table = ''; |
|
| 164 | - $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 165 | - foreach ($res as $cle => $r) { |
|
| 166 | - [$d, $a, $j] = $r; |
|
| 167 | - if (!$id_table) { |
|
| 168 | - $id_table = $d; |
|
| 169 | - } |
|
| 170 | - $n = ++$cpt; |
|
| 171 | - if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 172 | - [$j1, $j2, $obj, $type] = $j; |
|
| 173 | - // trouver de quel cote est (id_objet,objet) |
|
| 174 | - $obj = $j1 == "id_$obj" ? "$id_table.$obj" : "L$n.$obj"; |
|
| 175 | - // le where complementaire est envoye dans la jointure et dans le where |
|
| 176 | - // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 177 | - // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 178 | - $boucle->where["JOIN-L$n"] = |
|
| 179 | - $echap ? |
|
| 180 | - ["'='","'$obj'","sql_quote('$type')"] |
|
| 181 | - : |
|
| 182 | - ['=',"$obj",sql_quote($type)]; |
|
| 183 | - $boucle->join["L$n"] = |
|
| 184 | - $echap ? |
|
| 185 | - ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 186 | - : |
|
| 187 | - [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 188 | - } else { |
|
| 189 | - $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 190 | - } |
|
| 191 | - $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - // pas besoin de group by |
|
| 196 | - // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 197 | - // si une seule jointure et sur une table avec primary key formee |
|
| 198 | - // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 199 | - // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 200 | - |
|
| 201 | - if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 202 | - $pk = nogroupby_if($desc, $a[1], $col); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // pas de group by |
|
| 206 | - // si une seule jointure |
|
| 207 | - // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 208 | - if ( |
|
| 209 | - !$pk |
|
| 210 | - && count($boucle->from) == 2 |
|
| 211 | - && isset($a[1]['key']['PRIMARY KEY']) |
|
| 212 | - && $j == $a[1]['key']['PRIMARY KEY'] |
|
| 213 | - ) { |
|
| 214 | - $pk = true; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 218 | - $groups = liste_champs_jointures($nom, $desc, true); |
|
| 219 | - if (!$pk) { |
|
| 220 | - foreach ($groups as $id_prim) { |
|
| 221 | - $id_field = $nom . '.' . $id_prim; |
|
| 222 | - if (!in_array($id_field, $boucle->group)) { |
|
| 223 | - $boucle->group[] = $id_field; |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - $boucle->modificateur['lien'] = true; |
|
| 229 | - |
|
| 230 | - return "L$n"; |
|
| 159 | + $a = []; |
|
| 160 | + $j = null; |
|
| 161 | + $n = null; |
|
| 162 | + static $num = []; |
|
| 163 | + $id_table = ''; |
|
| 164 | + $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 165 | + foreach ($res as $cle => $r) { |
|
| 166 | + [$d, $a, $j] = $r; |
|
| 167 | + if (!$id_table) { |
|
| 168 | + $id_table = $d; |
|
| 169 | + } |
|
| 170 | + $n = ++$cpt; |
|
| 171 | + if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 172 | + [$j1, $j2, $obj, $type] = $j; |
|
| 173 | + // trouver de quel cote est (id_objet,objet) |
|
| 174 | + $obj = $j1 == "id_$obj" ? "$id_table.$obj" : "L$n.$obj"; |
|
| 175 | + // le where complementaire est envoye dans la jointure et dans le where |
|
| 176 | + // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 177 | + // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 178 | + $boucle->where["JOIN-L$n"] = |
|
| 179 | + $echap ? |
|
| 180 | + ["'='","'$obj'","sql_quote('$type')"] |
|
| 181 | + : |
|
| 182 | + ['=',"$obj",sql_quote($type)]; |
|
| 183 | + $boucle->join["L$n"] = |
|
| 184 | + $echap ? |
|
| 185 | + ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 186 | + : |
|
| 187 | + [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 188 | + } else { |
|
| 189 | + $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 190 | + } |
|
| 191 | + $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + // pas besoin de group by |
|
| 196 | + // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 197 | + // si une seule jointure et sur une table avec primary key formee |
|
| 198 | + // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 199 | + // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 200 | + |
|
| 201 | + if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 202 | + $pk = nogroupby_if($desc, $a[1], $col); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // pas de group by |
|
| 206 | + // si une seule jointure |
|
| 207 | + // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 208 | + if ( |
|
| 209 | + !$pk |
|
| 210 | + && count($boucle->from) == 2 |
|
| 211 | + && isset($a[1]['key']['PRIMARY KEY']) |
|
| 212 | + && $j == $a[1]['key']['PRIMARY KEY'] |
|
| 213 | + ) { |
|
| 214 | + $pk = true; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 218 | + $groups = liste_champs_jointures($nom, $desc, true); |
|
| 219 | + if (!$pk) { |
|
| 220 | + foreach ($groups as $id_prim) { |
|
| 221 | + $id_field = $nom . '.' . $id_prim; |
|
| 222 | + if (!in_array($id_field, $boucle->group)) { |
|
| 223 | + $boucle->group[] = $id_field; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + $boucle->modificateur['lien'] = true; |
|
| 229 | + |
|
| 230 | + return "L$n"; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -242,18 +242,18 @@ discard block |
||
| 242 | 242 | * @return bool |
| 243 | 243 | */ |
| 244 | 244 | function nogroupby_if($depart, $arrivee, $col) { |
| 245 | - if ( |
|
| 246 | - empty($arrivee['key']['PRIMARY KEY']) |
|
| 247 | - || !($pk = $arrivee['key']['PRIMARY KEY']) |
|
| 248 | - || empty($depart['key']['PRIMARY KEY']) |
|
| 249 | - ) { |
|
| 250 | - return false; |
|
| 251 | - } |
|
| 252 | - $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 253 | - if (is_array($col)) { |
|
| 254 | - $col = implode(', *', $col); |
|
| 255 | - } // cas id_objet, objet |
|
| 256 | - return (preg_match("/^$id_primary, *$col$/", $pk) || preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 245 | + if ( |
|
| 246 | + empty($arrivee['key']['PRIMARY KEY']) |
|
| 247 | + || !($pk = $arrivee['key']['PRIMARY KEY']) |
|
| 248 | + || empty($depart['key']['PRIMARY KEY']) |
|
| 249 | + ) { |
|
| 250 | + return false; |
|
| 251 | + } |
|
| 252 | + $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 253 | + if (is_array($col)) { |
|
| 254 | + $col = implode(', *', $col); |
|
| 255 | + } // cas id_objet, objet |
|
| 256 | + return (preg_match("/^$id_primary, *$col$/", $pk) || preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -271,46 +271,46 @@ discard block |
||
| 271 | 271 | */ |
| 272 | 272 | function liste_champs_jointures($nom, $desc, $primary = false) { |
| 273 | 273 | |
| 274 | - static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 274 | + static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 275 | 275 | |
| 276 | - // si cle primaire demandee, la privilegier |
|
| 277 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 278 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 279 | - } |
|
| 276 | + // si cle primaire demandee, la privilegier |
|
| 277 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 278 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - // les champs declares explicitement pour les jointures |
|
| 282 | - if (isset($desc['join'])) { |
|
| 283 | - return $desc['join']; |
|
| 284 | - } |
|
| 285 | - /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 281 | + // les champs declares explicitement pour les jointures |
|
| 282 | + if (isset($desc['join'])) { |
|
| 283 | + return $desc['join']; |
|
| 284 | + } |
|
| 285 | + /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 286 | 286 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 287 | 287 | |
| 288 | - // si pas de cle, c'est fichu |
|
| 289 | - if (!isset($desc['key'])) { |
|
| 290 | - return []; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // si cle primaire |
|
| 294 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 295 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - // ici on se rabat sur les cles secondaires, |
|
| 299 | - // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 300 | - // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 301 | - // il faut declarer explicitement le champ 'join' de sa description |
|
| 302 | - |
|
| 303 | - $join = []; |
|
| 304 | - foreach ($desc['key'] as $v) { |
|
| 305 | - $join = split_key($v, $join); |
|
| 306 | - } |
|
| 307 | - foreach ($join as $k) { |
|
| 308 | - if (in_array($k, $nojoin)) { |
|
| 309 | - unset($join[$k]); |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return $join; |
|
| 288 | + // si pas de cle, c'est fichu |
|
| 289 | + if (!isset($desc['key'])) { |
|
| 290 | + return []; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // si cle primaire |
|
| 294 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 295 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + // ici on se rabat sur les cles secondaires, |
|
| 299 | + // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 300 | + // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 301 | + // il faut declarer explicitement le champ 'join' de sa description |
|
| 302 | + |
|
| 303 | + $join = []; |
|
| 304 | + foreach ($desc['key'] as $v) { |
|
| 305 | + $join = split_key($v, $join); |
|
| 306 | + } |
|
| 307 | + foreach ($join as $k) { |
|
| 308 | + if (in_array($k, $nojoin)) { |
|
| 309 | + unset($join[$k]); |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return $join; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -321,14 +321,14 @@ discard block |
||
| 321 | 321 | * @return array |
| 322 | 322 | */ |
| 323 | 323 | function split_key($v, $join = []) { |
| 324 | - foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 325 | - if (str_contains($k, '(')) { |
|
| 326 | - $k = explode('(', $k); |
|
| 327 | - $k = trim(reset($k)); |
|
| 328 | - } |
|
| 329 | - $join[$k] = $k; |
|
| 330 | - } |
|
| 331 | - return $join; |
|
| 324 | + foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 325 | + if (str_contains($k, '(')) { |
|
| 326 | + $k = explode('(', $k); |
|
| 327 | + $k = trim(reset($k)); |
|
| 328 | + } |
|
| 329 | + $join[$k] = $k; |
|
| 330 | + } |
|
| 331 | + return $join; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -351,134 +351,134 @@ discard block |
||
| 351 | 351 | * @return array |
| 352 | 352 | */ |
| 353 | 353 | function calculer_chaine_jointures( |
| 354 | - &$boucle, |
|
| 355 | - $depart, |
|
| 356 | - $arrivee, |
|
| 357 | - $vu = [], |
|
| 358 | - $milieu_exclus = [], |
|
| 359 | - $max_liens = 5 |
|
| 354 | + &$boucle, |
|
| 355 | + $depart, |
|
| 356 | + $arrivee, |
|
| 357 | + $vu = [], |
|
| 358 | + $milieu_exclus = [], |
|
| 359 | + $max_liens = 5 |
|
| 360 | 360 | ) { |
| 361 | - static $trouver_table; |
|
| 362 | - if (!$trouver_table) { |
|
| 363 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - if (is_string($milieu_exclus)) { |
|
| 367 | - $milieu_exclus = [$milieu_exclus]; |
|
| 368 | - } |
|
| 369 | - // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 370 | - // faire une jointure sur objet tout seul n'a pas de sens |
|
| 371 | - if (in_array('id_objet', $milieu_exclus) && !in_array('objet', $milieu_exclus)) { |
|
| 372 | - $milieu_exclus[] = 'objet'; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - [$dnom, $ddesc] = $depart; |
|
| 376 | - [$anom, $adesc] = $arrivee; |
|
| 377 | - if ($vu === []) { |
|
| 378 | - $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 379 | - $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - $akeys = []; |
|
| 383 | - foreach ($adesc['key'] as $k) { |
|
| 384 | - // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 385 | - $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - // enlever les cles d'arrivee exclues par l'appel |
|
| 389 | - $akeys = array_diff($akeys, $milieu_exclus); |
|
| 390 | - |
|
| 391 | - // cles candidates au depart |
|
| 392 | - $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 393 | - // enlever les cles dde depart exclues par l'appel |
|
| 394 | - $keys = array_diff($keys, $milieu_exclus); |
|
| 395 | - |
|
| 396 | - $v = $keys ? array_intersect(array_values($keys), $akeys) : false; |
|
| 397 | - |
|
| 398 | - if ($v) { |
|
| 399 | - return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 403 | - if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 404 | - // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 405 | - // id_objet,objet |
|
| 406 | - // si oui on la prend |
|
| 407 | - foreach ($akeys as $key) { |
|
| 408 | - $v = decompose_champ_id_objet($key); |
|
| 409 | - if (is_array($v)) { |
|
| 410 | - $objet = array_shift($v); // objet,'article' |
|
| 411 | - array_unshift($v, $key); // id_article,objet,'article' |
|
| 412 | - array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 413 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - } else { |
|
| 417 | - // regarder si l'une des cles de depart peut se decomposer en |
|
| 418 | - // id_objet,objet a l'arrivee |
|
| 419 | - // si oui on la prend |
|
| 420 | - foreach ($keys as $key) { |
|
| 421 | - if (count($v = trouver_champs_decomposes($key, $adesc)) > 1 && count($v) == count(array_intersect($v, $akeys))) { |
|
| 422 | - $v = decompose_champ_id_objet($key); |
|
| 423 | - // id_objet,objet,'article' |
|
| 424 | - array_unshift($v, $key); |
|
| 425 | - // id_article,id_objet,objet,'article' |
|
| 426 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - // si l'on voulait une jointure direct, c'est rate ! |
|
| 431 | - if ($max_liens <= 1) { |
|
| 432 | - return []; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // sinon essayer de passer par une autre table |
|
| 436 | - $new = $vu; |
|
| 437 | - foreach ($boucle->jointures as $v) { |
|
| 438 | - if ( |
|
| 439 | - $v |
|
| 440 | - && !in_array($v, $vu) |
|
| 441 | - && ($def = $trouver_table($v, $boucle->sql_serveur)) |
|
| 442 | - && !in_array($def['table_sql'], $vu) |
|
| 443 | - ) { |
|
| 444 | - // ne pas tester les cles qui sont exclues a l'appel |
|
| 445 | - // ie la cle de la jointure precedente |
|
| 446 | - $test_cles = $milieu_exclus; |
|
| 447 | - $new[] = $v; |
|
| 448 | - $max_iter = 50; // securite |
|
| 449 | - while ( |
|
| 450 | - count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 451 | - $boucle, |
|
| 452 | - $depart, |
|
| 453 | - [$v, $def], |
|
| 454 | - $vu, |
|
| 455 | - $test_cles, |
|
| 456 | - 1 |
|
| 457 | - )) && $max_iter-- |
|
| 458 | - ) { |
|
| 459 | - $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 460 | - $milieu = end($jointure_directe_possible); |
|
| 461 | - $exclure_fin = $milieu_exclus; |
|
| 462 | - if (is_string($milieu)) { |
|
| 463 | - $exclure_fin[] = $milieu; |
|
| 464 | - $test_cles[] = $milieu; |
|
| 465 | - } else { |
|
| 466 | - $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 467 | - $test_cles = array_merge($test_cles, $milieu); |
|
| 468 | - } |
|
| 469 | - // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 470 | - // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 471 | - $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 472 | - if ($r) { |
|
| 473 | - array_unshift($r, $jointure_directe_possible); |
|
| 474 | - |
|
| 475 | - return $r; |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - return []; |
|
| 361 | + static $trouver_table; |
|
| 362 | + if (!$trouver_table) { |
|
| 363 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + if (is_string($milieu_exclus)) { |
|
| 367 | + $milieu_exclus = [$milieu_exclus]; |
|
| 368 | + } |
|
| 369 | + // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 370 | + // faire une jointure sur objet tout seul n'a pas de sens |
|
| 371 | + if (in_array('id_objet', $milieu_exclus) && !in_array('objet', $milieu_exclus)) { |
|
| 372 | + $milieu_exclus[] = 'objet'; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + [$dnom, $ddesc] = $depart; |
|
| 376 | + [$anom, $adesc] = $arrivee; |
|
| 377 | + if ($vu === []) { |
|
| 378 | + $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 379 | + $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + $akeys = []; |
|
| 383 | + foreach ($adesc['key'] as $k) { |
|
| 384 | + // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 385 | + $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + // enlever les cles d'arrivee exclues par l'appel |
|
| 389 | + $akeys = array_diff($akeys, $milieu_exclus); |
|
| 390 | + |
|
| 391 | + // cles candidates au depart |
|
| 392 | + $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 393 | + // enlever les cles dde depart exclues par l'appel |
|
| 394 | + $keys = array_diff($keys, $milieu_exclus); |
|
| 395 | + |
|
| 396 | + $v = $keys ? array_intersect(array_values($keys), $akeys) : false; |
|
| 397 | + |
|
| 398 | + if ($v) { |
|
| 399 | + return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 403 | + if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 404 | + // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 405 | + // id_objet,objet |
|
| 406 | + // si oui on la prend |
|
| 407 | + foreach ($akeys as $key) { |
|
| 408 | + $v = decompose_champ_id_objet($key); |
|
| 409 | + if (is_array($v)) { |
|
| 410 | + $objet = array_shift($v); // objet,'article' |
|
| 411 | + array_unshift($v, $key); // id_article,objet,'article' |
|
| 412 | + array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 413 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + } else { |
|
| 417 | + // regarder si l'une des cles de depart peut se decomposer en |
|
| 418 | + // id_objet,objet a l'arrivee |
|
| 419 | + // si oui on la prend |
|
| 420 | + foreach ($keys as $key) { |
|
| 421 | + if (count($v = trouver_champs_decomposes($key, $adesc)) > 1 && count($v) == count(array_intersect($v, $akeys))) { |
|
| 422 | + $v = decompose_champ_id_objet($key); |
|
| 423 | + // id_objet,objet,'article' |
|
| 424 | + array_unshift($v, $key); |
|
| 425 | + // id_article,id_objet,objet,'article' |
|
| 426 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + // si l'on voulait une jointure direct, c'est rate ! |
|
| 431 | + if ($max_liens <= 1) { |
|
| 432 | + return []; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // sinon essayer de passer par une autre table |
|
| 436 | + $new = $vu; |
|
| 437 | + foreach ($boucle->jointures as $v) { |
|
| 438 | + if ( |
|
| 439 | + $v |
|
| 440 | + && !in_array($v, $vu) |
|
| 441 | + && ($def = $trouver_table($v, $boucle->sql_serveur)) |
|
| 442 | + && !in_array($def['table_sql'], $vu) |
|
| 443 | + ) { |
|
| 444 | + // ne pas tester les cles qui sont exclues a l'appel |
|
| 445 | + // ie la cle de la jointure precedente |
|
| 446 | + $test_cles = $milieu_exclus; |
|
| 447 | + $new[] = $v; |
|
| 448 | + $max_iter = 50; // securite |
|
| 449 | + while ( |
|
| 450 | + count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 451 | + $boucle, |
|
| 452 | + $depart, |
|
| 453 | + [$v, $def], |
|
| 454 | + $vu, |
|
| 455 | + $test_cles, |
|
| 456 | + 1 |
|
| 457 | + )) && $max_iter-- |
|
| 458 | + ) { |
|
| 459 | + $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 460 | + $milieu = end($jointure_directe_possible); |
|
| 461 | + $exclure_fin = $milieu_exclus; |
|
| 462 | + if (is_string($milieu)) { |
|
| 463 | + $exclure_fin[] = $milieu; |
|
| 464 | + $test_cles[] = $milieu; |
|
| 465 | + } else { |
|
| 466 | + $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 467 | + $test_cles = array_merge($test_cles, $milieu); |
|
| 468 | + } |
|
| 469 | + // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 470 | + // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 471 | + $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 472 | + if ($r) { |
|
| 473 | + array_unshift($r, $jointure_directe_possible); |
|
| 474 | + |
|
| 475 | + return $r; |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + return []; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | /** |
@@ -489,18 +489,18 @@ discard block |
||
| 489 | 489 | * @return array |
| 490 | 490 | */ |
| 491 | 491 | function trouver_cles_table($keys) { |
| 492 | - $res = []; |
|
| 493 | - foreach ($keys as $v) { |
|
| 494 | - if (!strpos($v, ',')) { |
|
| 495 | - $res[$v] = 1; |
|
| 496 | - } else { |
|
| 497 | - foreach (preg_split('/\s*,\s*/', $v) as $k) { |
|
| 498 | - $res[$k] = 1; |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - return array_keys($res); |
|
| 492 | + $res = []; |
|
| 493 | + foreach ($keys as $v) { |
|
| 494 | + if (!strpos($v, ',')) { |
|
| 495 | + $res[$v] = 1; |
|
| 496 | + } else { |
|
| 497 | + foreach (preg_split('/\s*,\s*/', $v) as $k) { |
|
| 498 | + $res[$k] = 1; |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + return array_keys($res); |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | |
@@ -527,34 +527,34 @@ discard block |
||
| 527 | 527 | * - 'alias' : alias utilisé pour la table (si pertinent. ie: avec `$boucle->from` transmis par exemple) |
| 528 | 528 | */ |
| 529 | 529 | function chercher_champ_dans_tables($cle, $tables, $connect, $checkarrivee = false) { |
| 530 | - static $trouver_table = ''; |
|
| 531 | - if (!$trouver_table) { |
|
| 532 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - if (!is_array($cle)) { |
|
| 536 | - $cle = [$cle]; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - foreach ($tables as $k => $table) { |
|
| 540 | - if ( |
|
| 541 | - $table |
|
| 542 | - && ($desc = $trouver_table($table, $connect)) |
|
| 543 | - && ( |
|
| 544 | - isset($desc['field']) |
|
| 545 | - && count(array_intersect($cle, array_keys($desc['field']))) === count($cle) |
|
| 546 | - && ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 547 | - ) |
|
| 548 | - ) { |
|
| 549 | - return [ |
|
| 550 | - 'desc' => $desc, |
|
| 551 | - 'table' => $desc['table'], |
|
| 552 | - 'alias' => $k, |
|
| 553 | - ]; |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - return false; |
|
| 530 | + static $trouver_table = ''; |
|
| 531 | + if (!$trouver_table) { |
|
| 532 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + if (!is_array($cle)) { |
|
| 536 | + $cle = [$cle]; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + foreach ($tables as $k => $table) { |
|
| 540 | + if ( |
|
| 541 | + $table |
|
| 542 | + && ($desc = $trouver_table($table, $connect)) |
|
| 543 | + && ( |
|
| 544 | + isset($desc['field']) |
|
| 545 | + && count(array_intersect($cle, array_keys($desc['field']))) === count($cle) |
|
| 546 | + && ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 547 | + ) |
|
| 548 | + ) { |
|
| 549 | + return [ |
|
| 550 | + 'desc' => $desc, |
|
| 551 | + 'table' => $desc['table'], |
|
| 552 | + 'alias' => $k, |
|
| 553 | + ]; |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + return false; |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | /** |
@@ -580,52 +580,52 @@ discard block |
||
| 580 | 580 | */ |
| 581 | 581 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false) { |
| 582 | 582 | |
| 583 | - // support de la recherche multi champ : |
|
| 584 | - // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 585 | - // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 586 | - // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 587 | - if (!is_array($cle)) { |
|
| 588 | - $cle = [$cle]; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 592 | - return [$infos['table'], $infos['desc'], $cle]; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - // au premier coup, on essaye de decomposer, si possible |
|
| 596 | - if ( |
|
| 597 | - count($cle) == 1 |
|
| 598 | - && ($c = reset($cle)) |
|
| 599 | - && is_array($decompose = decompose_champ_id_objet($c)) |
|
| 600 | - ) { |
|
| 601 | - $desc = $boucle->show; |
|
| 602 | - |
|
| 603 | - // cas 1 : la cle id_xx est dans la table de depart |
|
| 604 | - // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 605 | - if (isset($desc['field'][$c])) { |
|
| 606 | - $cle = []; |
|
| 607 | - $cle[] = array_shift($decompose); // id_objet |
|
| 608 | - $cle[] = array_shift($decompose); // objet |
|
| 609 | - return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 610 | - } |
|
| 611 | - // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 612 | - // -> il faut trouver une cle de depart zzz telle que |
|
| 613 | - // id_objet,objet,zzz soit a l'arrivee |
|
| 614 | - else { |
|
| 615 | - $depart = liste_champs_jointures(($desc['table'] ?? ''), $desc); |
|
| 616 | - foreach ($depart as $d) { |
|
| 617 | - $cle = []; |
|
| 618 | - $cle[] = array_shift($decompose); // id_objet |
|
| 619 | - $cle[] = array_shift($decompose); // objet |
|
| 620 | - $cle[] = $d; |
|
| 621 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 622 | - return $ext; |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - return ''; |
|
| 583 | + // support de la recherche multi champ : |
|
| 584 | + // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 585 | + // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 586 | + // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 587 | + if (!is_array($cle)) { |
|
| 588 | + $cle = [$cle]; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 592 | + return [$infos['table'], $infos['desc'], $cle]; |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + // au premier coup, on essaye de decomposer, si possible |
|
| 596 | + if ( |
|
| 597 | + count($cle) == 1 |
|
| 598 | + && ($c = reset($cle)) |
|
| 599 | + && is_array($decompose = decompose_champ_id_objet($c)) |
|
| 600 | + ) { |
|
| 601 | + $desc = $boucle->show; |
|
| 602 | + |
|
| 603 | + // cas 1 : la cle id_xx est dans la table de depart |
|
| 604 | + // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 605 | + if (isset($desc['field'][$c])) { |
|
| 606 | + $cle = []; |
|
| 607 | + $cle[] = array_shift($decompose); // id_objet |
|
| 608 | + $cle[] = array_shift($decompose); // objet |
|
| 609 | + return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 610 | + } |
|
| 611 | + // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 612 | + // -> il faut trouver une cle de depart zzz telle que |
|
| 613 | + // id_objet,objet,zzz soit a l'arrivee |
|
| 614 | + else { |
|
| 615 | + $depart = liste_champs_jointures(($desc['table'] ?? ''), $desc); |
|
| 616 | + foreach ($depart as $d) { |
|
| 617 | + $cle = []; |
|
| 618 | + $cle[] = array_shift($decompose); // id_objet |
|
| 619 | + $cle[] = array_shift($decompose); // objet |
|
| 620 | + $cle[] = $d; |
|
| 621 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 622 | + return $ext; |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + return ''; |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | /** |
@@ -657,21 +657,21 @@ discard block |
||
| 657 | 657 | * @return string |
| 658 | 658 | */ |
| 659 | 659 | function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false, $checkarrivee = false) { |
| 660 | - if ($jointures === false) { |
|
| 661 | - $jointures = $boucle->jointures; |
|
| 662 | - } |
|
| 663 | - // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 664 | - // mais pas poour construire la jointure ensuite |
|
| 665 | - $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 666 | - if ($arrivee) { |
|
| 667 | - $desc = $boucle->show; |
|
| 668 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 669 | - $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 670 | - if ($cle) { |
|
| 671 | - return $cle; |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 675 | - |
|
| 676 | - return ''; |
|
| 660 | + if ($jointures === false) { |
|
| 661 | + $jointures = $boucle->jointures; |
|
| 662 | + } |
|
| 663 | + // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 664 | + // mais pas poour construire la jointure ensuite |
|
| 665 | + $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 666 | + if ($arrivee) { |
|
| 667 | + $desc = $boucle->show; |
|
| 668 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 669 | + $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 670 | + if ($cle) { |
|
| 671 | + return $cle; |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 675 | + |
|
| 676 | + return ''; |
|
| 677 | 677 | } |