@@ -11,173 +11,173 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/headers'); |
| 18 | 18 | |
| 19 | 19 | function install_etape_3b_dist() { |
| 20 | - $auth_spip = null; |
|
| 21 | - $session = null; |
|
| 22 | - $row = null; |
|
| 23 | - $login = _request('login'); |
|
| 24 | - $email = _request('email'); |
|
| 25 | - $nom = _request('nom'); |
|
| 26 | - $pass = _request('pass'); |
|
| 27 | - $pass_verif = _request('pass_verif'); |
|
| 28 | - |
|
| 29 | - $server_db = defined('_INSTALL_SERVER_DB') |
|
| 30 | - ? _INSTALL_SERVER_DB |
|
| 31 | - : _request('server_db'); |
|
| 32 | - |
|
| 33 | - if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 34 | - define('_PASS_LONGUEUR_MINI', 6); |
|
| 35 | - } |
|
| 36 | - if (!defined('_LOGIN_TROP_COURT')) { |
|
| 37 | - define('_LOGIN_TROP_COURT', 4); |
|
| 38 | - } |
|
| 39 | - if ($login) { |
|
| 40 | - $echec = ($pass != $pass_verif) ? |
|
| 41 | - _T('info_passes_identiques') |
|
| 42 | - : ((strlen($pass) < _PASS_LONGUEUR_MINI) ? |
|
| 43 | - _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]) |
|
| 44 | - : ((strlen($login) < _LOGIN_TROP_COURT) ? |
|
| 45 | - _T('info_login_trop_court') |
|
| 46 | - : '')); |
|
| 47 | - include_spip('inc/filtres'); |
|
| 48 | - if (!$echec and $email and !email_valide($email)) { |
|
| 49 | - $echec = _T('form_email_non_valide'); |
|
| 50 | - } |
|
| 51 | - if ($echec) { |
|
| 52 | - echouer_etape_3b($echec); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - if (@file_exists(_FILE_CHMOD_TMP)) { |
|
| 57 | - include(_FILE_CHMOD_TMP); |
|
| 58 | - } else { |
|
| 59 | - redirige_url_ecrire('install'); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - if (!@file_exists(_FILE_CONNECT_TMP)) { |
|
| 63 | - redirige_url_ecrire('install'); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - # maintenant on connait le vrai charset du site s'il est deja configure |
|
| 67 | - # sinon par defaut lire_meta reglera _DEFAULT_CHARSET |
|
| 68 | - # (les donnees arrivent de toute facon postees en _DEFAULT_CHARSET) |
|
| 69 | - |
|
| 70 | - lire_metas(); |
|
| 71 | - if ($login) { |
|
| 72 | - include_spip('inc/charsets'); |
|
| 73 | - |
|
| 74 | - $nom = (importer_charset($nom, _DEFAULT_CHARSET)); |
|
| 75 | - $login = (importer_charset($login, _DEFAULT_CHARSET)); |
|
| 76 | - $email = (importer_charset($email, _DEFAULT_CHARSET)); |
|
| 77 | - # pour le passwd, bizarrement il faut le convertir comme s'il avait |
|
| 78 | - # ete tape en iso-8859-1 ; car c'est en fait ce que voit md5.js |
|
| 79 | - $pass = unicode2charset(utf_8_to_unicode($pass), 'iso-8859-1'); |
|
| 80 | - |
|
| 81 | - include_spip('auth/spip'); |
|
| 82 | - // prelablement, creer le champ webmestre si il n'existe pas (install neuve |
|
| 83 | - // sur une vieille base |
|
| 84 | - $t = sql_showtable('spip_auteurs', true); |
|
| 85 | - if (!isset($t['field']['webmestre'])) { |
|
| 86 | - @sql_alter("TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - // il faut avoir une cle des auth valide pour creer un nouvel auteur webmestre |
|
| 90 | - include_spip('inc/chiffrer'); |
|
| 91 | - $cles = \Spip\Chiffrer\SpipCles::instance(); |
|
| 92 | - $secret = $cles->getSecretAuth(); |
|
| 93 | - |
|
| 94 | - $id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($login)); |
|
| 95 | - if ($id_auteur !== null) { |
|
| 96 | - // c'est un auteur connu : si on a pas de secret il faut absolument qu'il se reconnecte avec le meme mot de passe |
|
| 97 | - // pour restaurer la copie des cles |
|
| 98 | - if (!$secret and !auth_spip_initialiser_secret()) { |
|
| 99 | - $row = sql_fetsel('backup_cles, pass', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 100 | - if (empty($row['backup_cles']) or !$cles->restore($row['backup_cles'], $pass, $row['pass'], $id_auteur)) { |
|
| 101 | - $echec = _T('avis_connexion_erreur_fichier_cle_manquant_1'); |
|
| 102 | - echouer_etape_3b($echec); |
|
| 103 | - } |
|
| 104 | - spip_log("Les cles secretes ont ete restaurées avec le backup du webmestre #$id_auteur", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 105 | - $cles->save(); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - sql_updateq('spip_auteurs', [ |
|
| 109 | - 'nom' => $nom, |
|
| 110 | - 'email' => $email, |
|
| 111 | - 'login' => $login, |
|
| 112 | - 'statut' => '0minirezo' |
|
| 113 | - ], 'id_auteur=' . intval($id_auteur)); |
|
| 114 | - // le passer webmestre separement du reste, au cas ou l'alter n'aurait pas fonctionne |
|
| 115 | - @sql_updateq('spip_auteurs', ['webmestre' => 'oui'], "id_auteur=$id_auteur"); |
|
| 116 | - if (!auth_spip_modifier_pass($login, $pass, $id_auteur)) { |
|
| 117 | - $echec = _T('avis_erreur_creation_compte'); |
|
| 118 | - echouer_etape_3b($echec); |
|
| 119 | - } |
|
| 120 | - } else { |
|
| 121 | - // Si on a pas de cle et qu'on ne sait pas la creer, on ne peut pas creer de nouveau compte : |
|
| 122 | - // il faut qu'un webmestre avec un backup fasse l'install |
|
| 123 | - if (!$secret and !auth_spip_initialiser_secret()) { |
|
| 124 | - $echec = _T('avis_connexion_erreur_fichier_cle_manquant_2'); |
|
| 125 | - echouer_etape_3b($echec); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $id_auteur = sql_insertq('spip_auteurs', [ |
|
| 129 | - 'nom' => $nom, |
|
| 130 | - 'email' => $email, |
|
| 131 | - 'login' => $login, |
|
| 132 | - 'statut' => '0minirezo' |
|
| 133 | - ]); |
|
| 134 | - // le passer webmestre separrement du reste, au cas ou l'alter n'aurait pas fonctionne |
|
| 135 | - @sql_updateq('spip_auteurs', ['webmestre' => 'oui'], "id_auteur=$id_auteur"); |
|
| 136 | - if (!auth_spip_modifier_pass($login, $pass, $id_auteur)) { |
|
| 137 | - $echec = _T('avis_erreur_creation_compte'); |
|
| 138 | - echouer_etape_3b($echec); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // inserer email comme email webmaster principal |
|
| 143 | - // (sauf s'il est vide: cas de la re-installation) |
|
| 144 | - if ($email) { |
|
| 145 | - ecrire_meta('email_webmaster', $email); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - // Connecter directement celui qui vient de (re)donner son login |
|
| 149 | - // mais sans cookie d'admin ni connexion longue |
|
| 150 | - include_spip('inc/auth'); |
|
| 151 | - if ( |
|
| 152 | - !$auteur = auth_identifier_login($login, $pass) |
|
| 153 | - or !auth_loger($auteur) |
|
| 154 | - ) { |
|
| 155 | - spip_log("login automatique impossible $auth_spip $session" . (is_countable($row) ? count($row) : 0)); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // installer les metas |
|
| 160 | - $config = charger_fonction('config', 'inc'); |
|
| 161 | - $config(); |
|
| 162 | - |
|
| 163 | - // activer les plugins |
|
| 164 | - // leur installation ne peut pas se faire sur le meme hit, il faudra donc |
|
| 165 | - // poursuivre au hit suivant |
|
| 166 | - include_spip('inc/plugin'); |
|
| 167 | - actualise_plugins_actifs(); |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - include_spip('inc/distant'); |
|
| 171 | - redirige_par_entete(parametre_url(self(), 'etape', '4', '&')); |
|
| 20 | + $auth_spip = null; |
|
| 21 | + $session = null; |
|
| 22 | + $row = null; |
|
| 23 | + $login = _request('login'); |
|
| 24 | + $email = _request('email'); |
|
| 25 | + $nom = _request('nom'); |
|
| 26 | + $pass = _request('pass'); |
|
| 27 | + $pass_verif = _request('pass_verif'); |
|
| 28 | + |
|
| 29 | + $server_db = defined('_INSTALL_SERVER_DB') |
|
| 30 | + ? _INSTALL_SERVER_DB |
|
| 31 | + : _request('server_db'); |
|
| 32 | + |
|
| 33 | + if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 34 | + define('_PASS_LONGUEUR_MINI', 6); |
|
| 35 | + } |
|
| 36 | + if (!defined('_LOGIN_TROP_COURT')) { |
|
| 37 | + define('_LOGIN_TROP_COURT', 4); |
|
| 38 | + } |
|
| 39 | + if ($login) { |
|
| 40 | + $echec = ($pass != $pass_verif) ? |
|
| 41 | + _T('info_passes_identiques') |
|
| 42 | + : ((strlen($pass) < _PASS_LONGUEUR_MINI) ? |
|
| 43 | + _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]) |
|
| 44 | + : ((strlen($login) < _LOGIN_TROP_COURT) ? |
|
| 45 | + _T('info_login_trop_court') |
|
| 46 | + : '')); |
|
| 47 | + include_spip('inc/filtres'); |
|
| 48 | + if (!$echec and $email and !email_valide($email)) { |
|
| 49 | + $echec = _T('form_email_non_valide'); |
|
| 50 | + } |
|
| 51 | + if ($echec) { |
|
| 52 | + echouer_etape_3b($echec); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + if (@file_exists(_FILE_CHMOD_TMP)) { |
|
| 57 | + include(_FILE_CHMOD_TMP); |
|
| 58 | + } else { |
|
| 59 | + redirige_url_ecrire('install'); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + if (!@file_exists(_FILE_CONNECT_TMP)) { |
|
| 63 | + redirige_url_ecrire('install'); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + # maintenant on connait le vrai charset du site s'il est deja configure |
|
| 67 | + # sinon par defaut lire_meta reglera _DEFAULT_CHARSET |
|
| 68 | + # (les donnees arrivent de toute facon postees en _DEFAULT_CHARSET) |
|
| 69 | + |
|
| 70 | + lire_metas(); |
|
| 71 | + if ($login) { |
|
| 72 | + include_spip('inc/charsets'); |
|
| 73 | + |
|
| 74 | + $nom = (importer_charset($nom, _DEFAULT_CHARSET)); |
|
| 75 | + $login = (importer_charset($login, _DEFAULT_CHARSET)); |
|
| 76 | + $email = (importer_charset($email, _DEFAULT_CHARSET)); |
|
| 77 | + # pour le passwd, bizarrement il faut le convertir comme s'il avait |
|
| 78 | + # ete tape en iso-8859-1 ; car c'est en fait ce que voit md5.js |
|
| 79 | + $pass = unicode2charset(utf_8_to_unicode($pass), 'iso-8859-1'); |
|
| 80 | + |
|
| 81 | + include_spip('auth/spip'); |
|
| 82 | + // prelablement, creer le champ webmestre si il n'existe pas (install neuve |
|
| 83 | + // sur une vieille base |
|
| 84 | + $t = sql_showtable('spip_auteurs', true); |
|
| 85 | + if (!isset($t['field']['webmestre'])) { |
|
| 86 | + @sql_alter("TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + // il faut avoir une cle des auth valide pour creer un nouvel auteur webmestre |
|
| 90 | + include_spip('inc/chiffrer'); |
|
| 91 | + $cles = \Spip\Chiffrer\SpipCles::instance(); |
|
| 92 | + $secret = $cles->getSecretAuth(); |
|
| 93 | + |
|
| 94 | + $id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($login)); |
|
| 95 | + if ($id_auteur !== null) { |
|
| 96 | + // c'est un auteur connu : si on a pas de secret il faut absolument qu'il se reconnecte avec le meme mot de passe |
|
| 97 | + // pour restaurer la copie des cles |
|
| 98 | + if (!$secret and !auth_spip_initialiser_secret()) { |
|
| 99 | + $row = sql_fetsel('backup_cles, pass', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 100 | + if (empty($row['backup_cles']) or !$cles->restore($row['backup_cles'], $pass, $row['pass'], $id_auteur)) { |
|
| 101 | + $echec = _T('avis_connexion_erreur_fichier_cle_manquant_1'); |
|
| 102 | + echouer_etape_3b($echec); |
|
| 103 | + } |
|
| 104 | + spip_log("Les cles secretes ont ete restaurées avec le backup du webmestre #$id_auteur", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 105 | + $cles->save(); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + sql_updateq('spip_auteurs', [ |
|
| 109 | + 'nom' => $nom, |
|
| 110 | + 'email' => $email, |
|
| 111 | + 'login' => $login, |
|
| 112 | + 'statut' => '0minirezo' |
|
| 113 | + ], 'id_auteur=' . intval($id_auteur)); |
|
| 114 | + // le passer webmestre separement du reste, au cas ou l'alter n'aurait pas fonctionne |
|
| 115 | + @sql_updateq('spip_auteurs', ['webmestre' => 'oui'], "id_auteur=$id_auteur"); |
|
| 116 | + if (!auth_spip_modifier_pass($login, $pass, $id_auteur)) { |
|
| 117 | + $echec = _T('avis_erreur_creation_compte'); |
|
| 118 | + echouer_etape_3b($echec); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + // Si on a pas de cle et qu'on ne sait pas la creer, on ne peut pas creer de nouveau compte : |
|
| 122 | + // il faut qu'un webmestre avec un backup fasse l'install |
|
| 123 | + if (!$secret and !auth_spip_initialiser_secret()) { |
|
| 124 | + $echec = _T('avis_connexion_erreur_fichier_cle_manquant_2'); |
|
| 125 | + echouer_etape_3b($echec); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $id_auteur = sql_insertq('spip_auteurs', [ |
|
| 129 | + 'nom' => $nom, |
|
| 130 | + 'email' => $email, |
|
| 131 | + 'login' => $login, |
|
| 132 | + 'statut' => '0minirezo' |
|
| 133 | + ]); |
|
| 134 | + // le passer webmestre separrement du reste, au cas ou l'alter n'aurait pas fonctionne |
|
| 135 | + @sql_updateq('spip_auteurs', ['webmestre' => 'oui'], "id_auteur=$id_auteur"); |
|
| 136 | + if (!auth_spip_modifier_pass($login, $pass, $id_auteur)) { |
|
| 137 | + $echec = _T('avis_erreur_creation_compte'); |
|
| 138 | + echouer_etape_3b($echec); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // inserer email comme email webmaster principal |
|
| 143 | + // (sauf s'il est vide: cas de la re-installation) |
|
| 144 | + if ($email) { |
|
| 145 | + ecrire_meta('email_webmaster', $email); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + // Connecter directement celui qui vient de (re)donner son login |
|
| 149 | + // mais sans cookie d'admin ni connexion longue |
|
| 150 | + include_spip('inc/auth'); |
|
| 151 | + if ( |
|
| 152 | + !$auteur = auth_identifier_login($login, $pass) |
|
| 153 | + or !auth_loger($auteur) |
|
| 154 | + ) { |
|
| 155 | + spip_log("login automatique impossible $auth_spip $session" . (is_countable($row) ? count($row) : 0)); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // installer les metas |
|
| 160 | + $config = charger_fonction('config', 'inc'); |
|
| 161 | + $config(); |
|
| 162 | + |
|
| 163 | + // activer les plugins |
|
| 164 | + // leur installation ne peut pas se faire sur le meme hit, il faudra donc |
|
| 165 | + // poursuivre au hit suivant |
|
| 166 | + include_spip('inc/plugin'); |
|
| 167 | + actualise_plugins_actifs(); |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + include_spip('inc/distant'); |
|
| 171 | + redirige_par_entete(parametre_url(self(), 'etape', '4', '&')); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | function echouer_etape_3b($echec) { |
| 175 | - echo minipres( |
|
| 176 | - 'AUTO', |
|
| 177 | - info_progression_etape(3, 'etape_', 'install/', true) . |
|
| 178 | - "<div class='error'><h3>$echec</h3>\n" . |
|
| 179 | - '<p>' . _T('avis_connexion_echec_2') . '</p>' . |
|
| 180 | - '</div>' |
|
| 181 | - ); |
|
| 182 | - exit; |
|
| 175 | + echo minipres( |
|
| 176 | + 'AUTO', |
|
| 177 | + info_progression_etape(3, 'etape_', 'install/', true) . |
|
| 178 | + "<div class='error'><h3>$echec</h3>\n" . |
|
| 179 | + '<p>' . _T('avis_connexion_echec_2') . '</p>' . |
|
| 180 | + '</div>' |
|
| 181 | + ); |
|
| 182 | + exit; |
|
| 183 | 183 | } |
@@ -91,17 +91,17 @@ discard block |
||
| 91 | 91 | $cles = \Spip\Chiffrer\SpipCles::instance(); |
| 92 | 92 | $secret = $cles->getSecretAuth(); |
| 93 | 93 | |
| 94 | - $id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($login)); |
|
| 94 | + $id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login='.sql_quote($login)); |
|
| 95 | 95 | if ($id_auteur !== null) { |
| 96 | 96 | // c'est un auteur connu : si on a pas de secret il faut absolument qu'il se reconnecte avec le meme mot de passe |
| 97 | 97 | // pour restaurer la copie des cles |
| 98 | 98 | if (!$secret and !auth_spip_initialiser_secret()) { |
| 99 | - $row = sql_fetsel('backup_cles, pass', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 99 | + $row = sql_fetsel('backup_cles, pass', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 100 | 100 | if (empty($row['backup_cles']) or !$cles->restore($row['backup_cles'], $pass, $row['pass'], $id_auteur)) { |
| 101 | 101 | $echec = _T('avis_connexion_erreur_fichier_cle_manquant_1'); |
| 102 | 102 | echouer_etape_3b($echec); |
| 103 | 103 | } |
| 104 | - spip_log("Les cles secretes ont ete restaurées avec le backup du webmestre #$id_auteur", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 104 | + spip_log("Les cles secretes ont ete restaurées avec le backup du webmestre #$id_auteur", 'auth'._LOG_INFO_IMPORTANTE); |
|
| 105 | 105 | $cles->save(); |
| 106 | 106 | } |
| 107 | 107 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | 'email' => $email, |
| 111 | 111 | 'login' => $login, |
| 112 | 112 | 'statut' => '0minirezo' |
| 113 | - ], 'id_auteur=' . intval($id_auteur)); |
|
| 113 | + ], 'id_auteur='.intval($id_auteur)); |
|
| 114 | 114 | // le passer webmestre separement du reste, au cas ou l'alter n'aurait pas fonctionne |
| 115 | 115 | @sql_updateq('spip_auteurs', ['webmestre' => 'oui'], "id_auteur=$id_auteur"); |
| 116 | 116 | if (!auth_spip_modifier_pass($login, $pass, $id_auteur)) { |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | !$auteur = auth_identifier_login($login, $pass) |
| 153 | 153 | or !auth_loger($auteur) |
| 154 | 154 | ) { |
| 155 | - spip_log("login automatique impossible $auth_spip $session" . (is_countable($row) ? count($row) : 0)); |
|
| 155 | + spip_log("login automatique impossible $auth_spip $session".(is_countable($row) ? count($row) : 0)); |
|
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | |
@@ -174,9 +174,9 @@ discard block |
||
| 174 | 174 | function echouer_etape_3b($echec) { |
| 175 | 175 | echo minipres( |
| 176 | 176 | 'AUTO', |
| 177 | - info_progression_etape(3, 'etape_', 'install/', true) . |
|
| 178 | - "<div class='error'><h3>$echec</h3>\n" . |
|
| 179 | - '<p>' . _T('avis_connexion_echec_2') . '</p>' . |
|
| 177 | + info_progression_etape(3, 'etape_', 'install/', true). |
|
| 178 | + "<div class='error'><h3>$echec</h3>\n". |
|
| 179 | + '<p>'._T('avis_connexion_echec_2').'</p>'. |
|
| 180 | 180 | '</div>' |
| 181 | 181 | ); |
| 182 | 182 | exit; |
@@ -14,57 +14,57 @@ |
||
| 14 | 14 | |
| 15 | 15 | /** Vérification et hachage de mot de passe */ |
| 16 | 16 | class Password { |
| 17 | - /** |
|
| 18 | - * verifier qu'un mot de passe en clair est correct a l'aide de son hash |
|
| 19 | - * |
|
| 20 | - * Le mot de passe est poivre via la cle secret_des_auth |
|
| 21 | - * |
|
| 22 | - * @param string $password_clair |
|
| 23 | - * @param string $password_hash |
|
| 24 | - * @param string $key |
|
| 25 | - * @return bool |
|
| 26 | - */ |
|
| 27 | - public static function verifier( |
|
| 28 | - #[\SensitiveParameter] |
|
| 29 | - string $password_clair, |
|
| 30 | - #[\SensitiveParameter] |
|
| 31 | - string $password_hash, |
|
| 32 | - #[\SensitiveParameter] |
|
| 33 | - ?string $key = null |
|
| 34 | - ): bool { |
|
| 35 | - $key ??= self::getDefaultKey(); |
|
| 36 | - if ($key) { |
|
| 37 | - $pass_poivre = hash_hmac('sha256', $password_clair, $key); |
|
| 38 | - return password_verify($pass_poivre, $password_hash); |
|
| 39 | - } |
|
| 40 | - spip_log('Aucune clé pour vérifier le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 41 | - return false; |
|
| 42 | - } |
|
| 17 | + /** |
|
| 18 | + * verifier qu'un mot de passe en clair est correct a l'aide de son hash |
|
| 19 | + * |
|
| 20 | + * Le mot de passe est poivre via la cle secret_des_auth |
|
| 21 | + * |
|
| 22 | + * @param string $password_clair |
|
| 23 | + * @param string $password_hash |
|
| 24 | + * @param string $key |
|
| 25 | + * @return bool |
|
| 26 | + */ |
|
| 27 | + public static function verifier( |
|
| 28 | + #[\SensitiveParameter] |
|
| 29 | + string $password_clair, |
|
| 30 | + #[\SensitiveParameter] |
|
| 31 | + string $password_hash, |
|
| 32 | + #[\SensitiveParameter] |
|
| 33 | + ?string $key = null |
|
| 34 | + ): bool { |
|
| 35 | + $key ??= self::getDefaultKey(); |
|
| 36 | + if ($key) { |
|
| 37 | + $pass_poivre = hash_hmac('sha256', $password_clair, $key); |
|
| 38 | + return password_verify($pass_poivre, $password_hash); |
|
| 39 | + } |
|
| 40 | + spip_log('Aucune clé pour vérifier le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Calculer un hash salé du mot de passe |
|
| 46 | - * @param string $password_clair |
|
| 47 | - * @param string $salt |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - public static function hacher( |
|
| 51 | - #[\SensitiveParameter] |
|
| 52 | - string $password_clair, |
|
| 53 | - #[\SensitiveParameter] |
|
| 54 | - ?string $key = null |
|
| 55 | - ): ?string { |
|
| 56 | - $key ??= self::getDefaultKey(); |
|
| 57 | - // ne pas fournir un hash errone si la cle nous manque |
|
| 58 | - if ($key) { |
|
| 59 | - $pass_poivre = hash_hmac('sha256', $password_clair, $key); |
|
| 60 | - return password_hash($pass_poivre, PASSWORD_DEFAULT); |
|
| 61 | - } |
|
| 62 | - spip_log('Aucune clé pour chiffrer le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 63 | - return null; |
|
| 64 | - } |
|
| 44 | + /** |
|
| 45 | + * Calculer un hash salé du mot de passe |
|
| 46 | + * @param string $password_clair |
|
| 47 | + * @param string $salt |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + public static function hacher( |
|
| 51 | + #[\SensitiveParameter] |
|
| 52 | + string $password_clair, |
|
| 53 | + #[\SensitiveParameter] |
|
| 54 | + ?string $key = null |
|
| 55 | + ): ?string { |
|
| 56 | + $key ??= self::getDefaultKey(); |
|
| 57 | + // ne pas fournir un hash errone si la cle nous manque |
|
| 58 | + if ($key) { |
|
| 59 | + $pass_poivre = hash_hmac('sha256', $password_clair, $key); |
|
| 60 | + return password_hash($pass_poivre, PASSWORD_DEFAULT); |
|
| 61 | + } |
|
| 62 | + spip_log('Aucune clé pour chiffrer le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 63 | + return null; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - private static function getDefaultKey(): ?string { |
|
| 67 | - $keys = SpipCles::instance(); |
|
| 68 | - return $keys->getSecretAuth(); |
|
| 69 | - } |
|
| 66 | + private static function getDefaultKey(): ?string { |
|
| 67 | + $keys = SpipCles::instance(); |
|
| 68 | + return $keys->getSecretAuth(); |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $pass_poivre = hash_hmac('sha256', $password_clair, $key); |
| 38 | 38 | return password_verify($pass_poivre, $password_hash); |
| 39 | 39 | } |
| 40 | - spip_log('Aucune clé pour vérifier le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 40 | + spip_log('Aucune clé pour vérifier le mot de passe', 'chiffrer'._LOG_INFO_IMPORTANTE); |
|
| 41 | 41 | return false; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | $pass_poivre = hash_hmac('sha256', $password_clair, $key); |
| 60 | 60 | return password_hash($pass_poivre, PASSWORD_DEFAULT); |
| 61 | 61 | } |
| 62 | - spip_log('Aucune clé pour chiffrer le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 62 | + spip_log('Aucune clé pour chiffrer le mot de passe', 'chiffrer'._LOG_INFO_IMPORTANTE); |
|
| 63 | 63 | return null; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | public function generate(string $name): string { |
| 31 | 31 | $key = Chiffrement::keygen(); |
| 32 | 32 | $this->keys[$name] = $key; |
| 33 | - spip_log("Création de la cle $name", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 33 | + spip_log("Création de la cle $name", 'chiffrer'._LOG_INFO_IMPORTANTE); |
|
| 34 | 34 | return $key; |
| 35 | 35 | } |
| 36 | 36 | |
@@ -14,48 +14,48 @@ |
||
| 14 | 14 | |
| 15 | 15 | /** Conteneur de clés (chiffrement, authentification) */ |
| 16 | 16 | class Cles implements \Countable /* , ContainerInterface */ { |
| 17 | - private array $keys; |
|
| 18 | - public function __construct(array $keys) { |
|
| 19 | - $this->keys = $keys; |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - public function has(string $name): bool { |
|
| 23 | - return array_key_exists($name, $this->keys); |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - public function get(string $name): ?string { |
|
| 27 | - return $this->keys[$name] ?? null; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - public function generate(string $name): string { |
|
| 31 | - $key = Chiffrement::keygen(); |
|
| 32 | - $this->keys[$name] = $key; |
|
| 33 | - spip_log("Création de la cle $name", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 34 | - return $key; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function set( |
|
| 38 | - string $name, |
|
| 39 | - #[\SensitiveParameter] |
|
| 40 | - string $key |
|
| 41 | - ): void { |
|
| 42 | - $this->keys[$name] = $key; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function delete(string $name): bool { |
|
| 46 | - if (isset($this->keys[$name])) { |
|
| 47 | - unset($this->keys[$name]); |
|
| 48 | - return true; |
|
| 49 | - }; |
|
| 50 | - return false; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function count(): int { |
|
| 54 | - return count($this->keys); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function toJson(): string { |
|
| 58 | - $json = array_map('base64_encode', $this->keys); |
|
| 59 | - return \json_encode($json); |
|
| 60 | - } |
|
| 17 | + private array $keys; |
|
| 18 | + public function __construct(array $keys) { |
|
| 19 | + $this->keys = $keys; |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + public function has(string $name): bool { |
|
| 23 | + return array_key_exists($name, $this->keys); |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + public function get(string $name): ?string { |
|
| 27 | + return $this->keys[$name] ?? null; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + public function generate(string $name): string { |
|
| 31 | + $key = Chiffrement::keygen(); |
|
| 32 | + $this->keys[$name] = $key; |
|
| 33 | + spip_log("Création de la cle $name", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 34 | + return $key; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function set( |
|
| 38 | + string $name, |
|
| 39 | + #[\SensitiveParameter] |
|
| 40 | + string $key |
|
| 41 | + ): void { |
|
| 42 | + $this->keys[$name] = $key; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function delete(string $name): bool { |
|
| 46 | + if (isset($this->keys[$name])) { |
|
| 47 | + unset($this->keys[$name]); |
|
| 48 | + return true; |
|
| 49 | + }; |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function count(): int { |
|
| 54 | + return count($this->keys); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function toJson(): string { |
|
| 58 | + $json = array_map('base64_encode', $this->keys); |
|
| 59 | + return \json_encode($json); |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | include_spip('base/abstract_sql'); |
| 64 | - $res = sql_select('statut, id_auteur, login, email, nom', 'spip_auteurs', 'email=' . sql_quote($desc['email'])); |
|
| 64 | + $res = sql_select('statut, id_auteur, login, email, nom', 'spip_auteurs', 'email='.sql_quote($desc['email'])); |
|
| 65 | 65 | // erreur ? |
| 66 | 66 | if (!$res) { |
| 67 | 67 | return _T('titre_probleme_technique'); |
@@ -217,11 +217,11 @@ discard block |
||
| 217 | 217 | |
| 218 | 218 | $login = $login_base; |
| 219 | 219 | |
| 220 | - for ($i = 1;; $i++) { |
|
| 220 | + for ($i = 1; ; $i++) { |
|
| 221 | 221 | if (!sql_countsel('spip_auteurs', "login='$login'")) { |
| 222 | 222 | return $login; |
| 223 | 223 | } |
| 224 | - $login = $login_base . $i; |
|
| 224 | + $login = $login_base.$i; |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | |
@@ -361,11 +361,11 @@ discard block |
||
| 361 | 361 | do { |
| 362 | 362 | // Un morceau du jeton est lisible en bdd pour éviter de devoir déchiffrer |
| 363 | 363 | // tous les jetons connus pour vérifier le jeton d’un auteur. |
| 364 | - $public = substr(creer_uniqid(), 0, 7) . '.'; |
|
| 365 | - $jeton = $public . creer_uniqid(); |
|
| 366 | - $jeton_chiffre_prefixe = $public . Chiffrement::chiffrer($jeton, SpipCles::secret_du_site()); |
|
| 367 | - sql_updateq('spip_auteurs', ['cookie_oubli' => $jeton_chiffre_prefixe], 'id_auteur=' . intval($id_auteur)); |
|
| 368 | - } while (sql_countsel('spip_auteurs', 'cookie_oubli=' . sql_quote($jeton_chiffre_prefixe, '', 'string')) > 1); |
|
| 364 | + $public = substr(creer_uniqid(), 0, 7).'.'; |
|
| 365 | + $jeton = $public.creer_uniqid(); |
|
| 366 | + $jeton_chiffre_prefixe = $public.Chiffrement::chiffrer($jeton, SpipCles::secret_du_site()); |
|
| 367 | + sql_updateq('spip_auteurs', ['cookie_oubli' => $jeton_chiffre_prefixe], 'id_auteur='.intval($id_auteur)); |
|
| 368 | + } while (sql_countsel('spip_auteurs', 'cookie_oubli='.sql_quote($jeton_chiffre_prefixe, '', 'string')) > 1); |
|
| 369 | 369 | |
| 370 | 370 | return $jeton; |
| 371 | 371 | } |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | */ |
| 383 | 383 | function auteur_lire_jeton(int $id_auteur, bool $autoInit = false): ?string { |
| 384 | 384 | include_spip('base/abstract_sql'); |
| 385 | - $jeton_chiffre_prefixe = sql_getfetsel('cookie_oubli', 'spip_auteurs', 'id_auteur=' . $id_auteur); |
|
| 385 | + $jeton_chiffre_prefixe = sql_getfetsel('cookie_oubli', 'spip_auteurs', 'id_auteur='.$id_auteur); |
|
| 386 | 386 | if ($jeton_chiffre_prefixe) { |
| 387 | 387 | include_spip('inc/chiffrer'); |
| 388 | 388 | $jeton_chiffre = substr($jeton_chiffre_prefixe, 8); |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | $public = substr($jeton, 0, 8); |
| 415 | 415 | |
| 416 | 416 | // Les auteurs qui ont un jetons ressemblant |
| 417 | - $auteurs = sql_allfetsel('*', 'spip_auteurs', 'cookie_oubli LIKE ' . sql_quote($public . '%')); |
|
| 417 | + $auteurs = sql_allfetsel('*', 'spip_auteurs', 'cookie_oubli LIKE '.sql_quote($public.'%')); |
|
| 418 | 418 | foreach ($auteurs as $auteur) { |
| 419 | 419 | $jeton_chiffre = substr($auteur['cookie_oubli'], 8); |
| 420 | 420 | $_jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site()); |
@@ -433,5 +433,5 @@ discard block |
||
| 433 | 433 | */ |
| 434 | 434 | function auteur_effacer_jeton($id_auteur) { |
| 435 | 435 | include_spip('base/abstract_sql'); |
| 436 | - return sql_updateq('spip_auteurs', ['cookie_oubli' => ''], 'id_auteur=' . intval($id_auteur)); |
|
| 436 | + return sql_updateq('spip_auteurs', ['cookie_oubli' => ''], 'id_auteur='.intval($id_auteur)); |
|
| 437 | 437 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -44,70 +44,70 @@ discard block |
||
| 44 | 44 | * @return array|string |
| 45 | 45 | */ |
| 46 | 46 | function action_inscrire_auteur_dist($statut, $mail_complet, $nom, $options = []) { |
| 47 | - if (!is_array($options)) { |
|
| 48 | - $options = ['id' => $options]; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - if (function_exists('test_inscription')) { |
|
| 52 | - $f = 'test_inscription'; |
|
| 53 | - } else { |
|
| 54 | - $f = 'test_inscription_dist'; |
|
| 55 | - } |
|
| 56 | - $desc = $f($statut, $mail_complet, $nom, $options); |
|
| 57 | - |
|
| 58 | - // erreur ? |
|
| 59 | - if (!is_array($desc)) { |
|
| 60 | - return _T($desc); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - include_spip('base/abstract_sql'); |
|
| 64 | - $res = sql_select('statut, id_auteur, login, email, nom', 'spip_auteurs', 'email=' . sql_quote($desc['email'])); |
|
| 65 | - // erreur ? |
|
| 66 | - if (!$res) { |
|
| 67 | - return _T('titre_probleme_technique'); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $row = sql_fetch($res); |
|
| 71 | - sql_free($res); |
|
| 72 | - if ($row) { |
|
| 73 | - if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) { |
|
| 74 | - $desc['id_auteur'] = $row['id_auteur']; |
|
| 75 | - $desc = inscription_nouveau($desc); |
|
| 76 | - } else { |
|
| 77 | - $desc = $row; |
|
| 78 | - } |
|
| 79 | - } else // s'il n'existe pas deja, creer les identifiants |
|
| 80 | - { |
|
| 81 | - $desc = inscription_nouveau($desc); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - // erreur ? |
|
| 85 | - if (!is_array($desc)) { |
|
| 86 | - return $desc; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - // generer le mot de passe (ou le refaire si compte inutilise) |
|
| 91 | - $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']); |
|
| 92 | - |
|
| 93 | - // attribuer un jeton pour confirmation par clic sur un lien |
|
| 94 | - $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']); |
|
| 95 | - |
|
| 96 | - // charger de suite cette fonction, pour ses utilitaires |
|
| 97 | - $envoyer_inscription = charger_fonction('envoyer_inscription', ''); |
|
| 98 | - [$sujet, $msg, $from, $head] = $envoyer_inscription($desc, $nom, $statut, $options); |
|
| 99 | - |
|
| 100 | - $notifications = charger_fonction('notifications', 'inc'); |
|
| 101 | - notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head); |
|
| 102 | - |
|
| 103 | - // Notifications |
|
| 104 | - $notifications( |
|
| 105 | - 'inscription', |
|
| 106 | - $desc['id_auteur'], |
|
| 107 | - ['nom' => $desc['nom'], 'email' => $desc['email']] |
|
| 108 | - ); |
|
| 109 | - |
|
| 110 | - return $desc; |
|
| 47 | + if (!is_array($options)) { |
|
| 48 | + $options = ['id' => $options]; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + if (function_exists('test_inscription')) { |
|
| 52 | + $f = 'test_inscription'; |
|
| 53 | + } else { |
|
| 54 | + $f = 'test_inscription_dist'; |
|
| 55 | + } |
|
| 56 | + $desc = $f($statut, $mail_complet, $nom, $options); |
|
| 57 | + |
|
| 58 | + // erreur ? |
|
| 59 | + if (!is_array($desc)) { |
|
| 60 | + return _T($desc); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + include_spip('base/abstract_sql'); |
|
| 64 | + $res = sql_select('statut, id_auteur, login, email, nom', 'spip_auteurs', 'email=' . sql_quote($desc['email'])); |
|
| 65 | + // erreur ? |
|
| 66 | + if (!$res) { |
|
| 67 | + return _T('titre_probleme_technique'); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $row = sql_fetch($res); |
|
| 71 | + sql_free($res); |
|
| 72 | + if ($row) { |
|
| 73 | + if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) { |
|
| 74 | + $desc['id_auteur'] = $row['id_auteur']; |
|
| 75 | + $desc = inscription_nouveau($desc); |
|
| 76 | + } else { |
|
| 77 | + $desc = $row; |
|
| 78 | + } |
|
| 79 | + } else // s'il n'existe pas deja, creer les identifiants |
|
| 80 | + { |
|
| 81 | + $desc = inscription_nouveau($desc); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + // erreur ? |
|
| 85 | + if (!is_array($desc)) { |
|
| 86 | + return $desc; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + // generer le mot de passe (ou le refaire si compte inutilise) |
|
| 91 | + $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']); |
|
| 92 | + |
|
| 93 | + // attribuer un jeton pour confirmation par clic sur un lien |
|
| 94 | + $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']); |
|
| 95 | + |
|
| 96 | + // charger de suite cette fonction, pour ses utilitaires |
|
| 97 | + $envoyer_inscription = charger_fonction('envoyer_inscription', ''); |
|
| 98 | + [$sujet, $msg, $from, $head] = $envoyer_inscription($desc, $nom, $statut, $options); |
|
| 99 | + |
|
| 100 | + $notifications = charger_fonction('notifications', 'inc'); |
|
| 101 | + notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head); |
|
| 102 | + |
|
| 103 | + // Notifications |
|
| 104 | + $notifications( |
|
| 105 | + 'inscription', |
|
| 106 | + $desc['id_auteur'], |
|
| 107 | + ['nom' => $desc['nom'], 'email' => $desc['email']] |
|
| 108 | + ); |
|
| 109 | + |
|
| 110 | + return $desc; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | |
@@ -130,23 +130,23 @@ discard block |
||
| 130 | 130 | * |
| 131 | 131 | */ |
| 132 | 132 | function test_inscription_dist($statut, $mail, $nom, $options) { |
| 133 | - include_spip('inc/filtres'); |
|
| 134 | - if (!$r = email_valide($mail)) { |
|
| 135 | - return 'info_email_invalide'; |
|
| 136 | - } |
|
| 137 | - $nom = trim(corriger_caracteres($nom)); |
|
| 138 | - $res = ['email' => $r, 'nom' => $nom, 'prefs' => $statut]; |
|
| 139 | - if (isset($options['login'])) { |
|
| 140 | - $login = trim(corriger_caracteres($options['login'])); |
|
| 141 | - if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) { |
|
| 142 | - $res['login'] = $login; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) { |
|
| 146 | - return 'ecrire:info_login_trop_court'; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $res; |
|
| 133 | + include_spip('inc/filtres'); |
|
| 134 | + if (!$r = email_valide($mail)) { |
|
| 135 | + return 'info_email_invalide'; |
|
| 136 | + } |
|
| 137 | + $nom = trim(corriger_caracteres($nom)); |
|
| 138 | + $res = ['email' => $r, 'nom' => $nom, 'prefs' => $statut]; |
|
| 139 | + if (isset($options['login'])) { |
|
| 140 | + $login = trim(corriger_caracteres($options['login'])); |
|
| 141 | + if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) { |
|
| 142 | + $res['login'] = $login; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) { |
|
| 146 | + return 'ecrire:info_login_trop_court'; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $res; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
@@ -159,33 +159,33 @@ discard block |
||
| 159 | 159 | * @return mixed|string |
| 160 | 160 | */ |
| 161 | 161 | function inscription_nouveau($desc) { |
| 162 | - if (!isset($desc['login']) or !strlen($desc['login'])) { |
|
| 163 | - $desc['login'] = test_login($desc['nom'], $desc['email']); |
|
| 164 | - } |
|
| 162 | + if (!isset($desc['login']) or !strlen($desc['login'])) { |
|
| 163 | + $desc['login'] = test_login($desc['nom'], $desc['email']); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - $desc['statut'] = 'nouveau'; |
|
| 167 | - include_spip('action/editer_auteur'); |
|
| 168 | - if (isset($desc['id_auteur'])) { |
|
| 169 | - $id_auteur = $desc['id_auteur']; |
|
| 170 | - } else { |
|
| 171 | - $id_auteur = auteur_inserer(); |
|
| 172 | - } |
|
| 166 | + $desc['statut'] = 'nouveau'; |
|
| 167 | + include_spip('action/editer_auteur'); |
|
| 168 | + if (isset($desc['id_auteur'])) { |
|
| 169 | + $id_auteur = $desc['id_auteur']; |
|
| 170 | + } else { |
|
| 171 | + $id_auteur = auteur_inserer(); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - if (!$id_auteur) { |
|
| 175 | - return _T('titre_probleme_technique'); |
|
| 176 | - } |
|
| 174 | + if (!$id_auteur) { |
|
| 175 | + return _T('titre_probleme_technique'); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - $desc['lang'] = $GLOBALS['spip_lang']; |
|
| 178 | + $desc['lang'] = $GLOBALS['spip_lang']; |
|
| 179 | 179 | |
| 180 | - include_spip('inc/autoriser'); |
|
| 181 | - // lever l'autorisation pour pouvoir modifier le statut |
|
| 182 | - autoriser_exception('modifier', 'auteur', $id_auteur); |
|
| 183 | - auteur_modifier($id_auteur, $desc); |
|
| 184 | - autoriser_exception('modifier', 'auteur', $id_auteur, false); |
|
| 180 | + include_spip('inc/autoriser'); |
|
| 181 | + // lever l'autorisation pour pouvoir modifier le statut |
|
| 182 | + autoriser_exception('modifier', 'auteur', $id_auteur); |
|
| 183 | + auteur_modifier($id_auteur, $desc); |
|
| 184 | + autoriser_exception('modifier', 'auteur', $id_auteur, false); |
|
| 185 | 185 | |
| 186 | - $desc['id_auteur'] = $id_auteur; |
|
| 186 | + $desc['id_auteur'] = $id_auteur; |
|
| 187 | 187 | |
| 188 | - return $desc; |
|
| 188 | + return $desc; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
@@ -202,27 +202,27 @@ discard block |
||
| 202 | 202 | * @return string |
| 203 | 203 | */ |
| 204 | 204 | function test_login($nom, $mail) { |
| 205 | - include_spip('inc/charsets'); |
|
| 206 | - $nom = strtolower(translitteration($nom)); |
|
| 207 | - $login_base = preg_replace('/[^\w\d_]/', '_', $nom); |
|
| 208 | - |
|
| 209 | - // il faut eviter que le login soit vraiment trop court |
|
| 210 | - if (strlen($login_base) < 3) { |
|
| 211 | - $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail))); |
|
| 212 | - $login_base = preg_replace('/[^\w\d]/', '_', $mail); |
|
| 213 | - } |
|
| 214 | - if (strlen($login_base) < 3) { |
|
| 215 | - $login_base = 'user'; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $login = $login_base; |
|
| 219 | - |
|
| 220 | - for ($i = 1;; $i++) { |
|
| 221 | - if (!sql_countsel('spip_auteurs', "login='$login'")) { |
|
| 222 | - return $login; |
|
| 223 | - } |
|
| 224 | - $login = $login_base . $i; |
|
| 225 | - } |
|
| 205 | + include_spip('inc/charsets'); |
|
| 206 | + $nom = strtolower(translitteration($nom)); |
|
| 207 | + $login_base = preg_replace('/[^\w\d_]/', '_', $nom); |
|
| 208 | + |
|
| 209 | + // il faut eviter que le login soit vraiment trop court |
|
| 210 | + if (strlen($login_base) < 3) { |
|
| 211 | + $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail))); |
|
| 212 | + $login_base = preg_replace('/[^\w\d]/', '_', $mail); |
|
| 213 | + } |
|
| 214 | + if (strlen($login_base) < 3) { |
|
| 215 | + $login_base = 'user'; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $login = $login_base; |
|
| 219 | + |
|
| 220 | + for ($i = 1;; $i++) { |
|
| 221 | + if (!sql_countsel('spip_auteurs', "login='$login'")) { |
|
| 222 | + return $login; |
|
| 223 | + } |
|
| 224 | + $login = $login_base . $i; |
|
| 225 | + } |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
@@ -240,26 +240,26 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | function envoyer_inscription_dist($desc, $nom, $mode, $options = []) { |
| 242 | 242 | |
| 243 | - $contexte = array_merge($desc, $options); |
|
| 244 | - $contexte['nom'] = $nom; |
|
| 245 | - $contexte['mode'] = $mode; |
|
| 246 | - $contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true); |
|
| 247 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']); |
|
| 248 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']); |
|
| 249 | - // S'il y a l'option redirect, on l'ajoute directement ici |
|
| 250 | - if (isset($options['redirect'])) { |
|
| 251 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'redirect', $options['redirect']); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - $modele_mail = 'modeles/mail_inscription'; |
|
| 255 | - if (isset($options['modele_mail']) and $options['modele_mail']) { |
|
| 256 | - $modele_mail = $options['modele_mail']; |
|
| 257 | - } |
|
| 258 | - $message = recuperer_fond($modele_mail, $contexte); |
|
| 259 | - $from = ($options['from'] ?? ''); |
|
| 260 | - $head = ''; |
|
| 261 | - |
|
| 262 | - return ['', $message, $from, $head]; |
|
| 243 | + $contexte = array_merge($desc, $options); |
|
| 244 | + $contexte['nom'] = $nom; |
|
| 245 | + $contexte['mode'] = $mode; |
|
| 246 | + $contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true); |
|
| 247 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']); |
|
| 248 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']); |
|
| 249 | + // S'il y a l'option redirect, on l'ajoute directement ici |
|
| 250 | + if (isset($options['redirect'])) { |
|
| 251 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'redirect', $options['redirect']); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + $modele_mail = 'modeles/mail_inscription'; |
|
| 255 | + if (isset($options['modele_mail']) and $options['modele_mail']) { |
|
| 256 | + $modele_mail = $options['modele_mail']; |
|
| 257 | + } |
|
| 258 | + $message = recuperer_fond($modele_mail, $contexte); |
|
| 259 | + $from = ($options['from'] ?? ''); |
|
| 260 | + $head = ''; |
|
| 261 | + |
|
| 262 | + return ['', $message, $from, $head]; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -270,12 +270,12 @@ discard block |
||
| 270 | 270 | * @return string |
| 271 | 271 | */ |
| 272 | 272 | function creer_pass_pour_auteur($id_auteur) { |
| 273 | - include_spip('inc/acces'); |
|
| 274 | - $pass = creer_pass_aleatoire(max(_PASS_LONGUEUR_MINI, 16), $id_auteur); |
|
| 275 | - include_spip('action/editer_auteur'); |
|
| 276 | - auteur_instituer($id_auteur, ['pass' => $pass]); |
|
| 273 | + include_spip('inc/acces'); |
|
| 274 | + $pass = creer_pass_aleatoire(max(_PASS_LONGUEUR_MINI, 16), $id_auteur); |
|
| 275 | + include_spip('action/editer_auteur'); |
|
| 276 | + auteur_instituer($id_auteur, ['pass' => $pass]); |
|
| 277 | 277 | |
| 278 | - return $pass; |
|
| 278 | + return $pass; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -288,17 +288,17 @@ discard block |
||
| 288 | 288 | * @return string |
| 289 | 289 | */ |
| 290 | 290 | function tester_statut_inscription($statut_tmp, $id) { |
| 291 | - include_spip('inc/autoriser'); |
|
| 292 | - if ($statut_tmp) { |
|
| 293 | - return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : ''; |
|
| 294 | - } elseif ( |
|
| 295 | - autoriser('inscrireauteur', $statut_tmp = '1comite', $id) |
|
| 296 | - or autoriser('inscrireauteur', $statut_tmp = '6forum', $id) |
|
| 297 | - ) { |
|
| 298 | - return $statut_tmp; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - return ''; |
|
| 291 | + include_spip('inc/autoriser'); |
|
| 292 | + if ($statut_tmp) { |
|
| 293 | + return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : ''; |
|
| 294 | + } elseif ( |
|
| 295 | + autoriser('inscrireauteur', $statut_tmp = '1comite', $id) |
|
| 296 | + or autoriser('inscrireauteur', $statut_tmp = '6forum', $id) |
|
| 297 | + ) { |
|
| 298 | + return $statut_tmp; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + return ''; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | |
@@ -312,35 +312,35 @@ discard block |
||
| 312 | 312 | * @return array |
| 313 | 313 | */ |
| 314 | 314 | function confirmer_statut_inscription($auteur) { |
| 315 | - // securite |
|
| 316 | - if ($auteur['statut'] != 'nouveau') { |
|
| 317 | - return $auteur; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - $s = $auteur['prefs']; |
|
| 321 | - // securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize) |
|
| 322 | - if (!preg_match(',^\w+$,', $s)) { |
|
| 323 | - $s = '6forum'; |
|
| 324 | - } |
|
| 325 | - include_spip('inc/autoriser'); |
|
| 326 | - if (!autoriser('inscrireauteur', $s)) { |
|
| 327 | - return $auteur; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - include_spip('inc/autoriser'); |
|
| 331 | - // accorder l'autorisation de modif du statut auteur |
|
| 332 | - autoriser_exception('modifier', 'auteur', $auteur['id_auteur']); |
|
| 333 | - include_spip('action/editer_auteur'); |
|
| 334 | - // changer le statut |
|
| 335 | - auteur_modifier($auteur['id_auteur'], ['statut' => $s]); |
|
| 336 | - unset($_COOKIE['spip_session']); // forcer la maj de la session |
|
| 337 | - // lever l'autorisation de modif du statut auteur |
|
| 338 | - autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false); |
|
| 339 | - |
|
| 340 | - // mettre a jour le statut |
|
| 341 | - $auteur['statut'] = $s; |
|
| 342 | - |
|
| 343 | - return $auteur; |
|
| 315 | + // securite |
|
| 316 | + if ($auteur['statut'] != 'nouveau') { |
|
| 317 | + return $auteur; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + $s = $auteur['prefs']; |
|
| 321 | + // securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize) |
|
| 322 | + if (!preg_match(',^\w+$,', $s)) { |
|
| 323 | + $s = '6forum'; |
|
| 324 | + } |
|
| 325 | + include_spip('inc/autoriser'); |
|
| 326 | + if (!autoriser('inscrireauteur', $s)) { |
|
| 327 | + return $auteur; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + include_spip('inc/autoriser'); |
|
| 331 | + // accorder l'autorisation de modif du statut auteur |
|
| 332 | + autoriser_exception('modifier', 'auteur', $auteur['id_auteur']); |
|
| 333 | + include_spip('action/editer_auteur'); |
|
| 334 | + // changer le statut |
|
| 335 | + auteur_modifier($auteur['id_auteur'], ['statut' => $s]); |
|
| 336 | + unset($_COOKIE['spip_session']); // forcer la maj de la session |
|
| 337 | + // lever l'autorisation de modif du statut auteur |
|
| 338 | + autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false); |
|
| 339 | + |
|
| 340 | + // mettre a jour le statut |
|
| 341 | + $auteur['statut'] = $s; |
|
| 342 | + |
|
| 343 | + return $auteur; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | |
@@ -354,20 +354,20 @@ discard block |
||
| 354 | 354 | * @return string |
| 355 | 355 | */ |
| 356 | 356 | function auteur_attribuer_jeton($id_auteur): string { |
| 357 | - include_spip('base/abstract_sql'); |
|
| 358 | - include_spip('inc/acces'); |
|
| 359 | - include_spip('inc/chiffrer'); |
|
| 360 | - // s'assurer de l'unicite du jeton pour le couple (email,cookie) |
|
| 361 | - do { |
|
| 362 | - // Un morceau du jeton est lisible en bdd pour éviter de devoir déchiffrer |
|
| 363 | - // tous les jetons connus pour vérifier le jeton d’un auteur. |
|
| 364 | - $public = substr(creer_uniqid(), 0, 7) . '.'; |
|
| 365 | - $jeton = $public . creer_uniqid(); |
|
| 366 | - $jeton_chiffre_prefixe = $public . Chiffrement::chiffrer($jeton, SpipCles::secret_du_site()); |
|
| 367 | - sql_updateq('spip_auteurs', ['cookie_oubli' => $jeton_chiffre_prefixe], 'id_auteur=' . intval($id_auteur)); |
|
| 368 | - } while (sql_countsel('spip_auteurs', 'cookie_oubli=' . sql_quote($jeton_chiffre_prefixe, '', 'string')) > 1); |
|
| 369 | - |
|
| 370 | - return $jeton; |
|
| 357 | + include_spip('base/abstract_sql'); |
|
| 358 | + include_spip('inc/acces'); |
|
| 359 | + include_spip('inc/chiffrer'); |
|
| 360 | + // s'assurer de l'unicite du jeton pour le couple (email,cookie) |
|
| 361 | + do { |
|
| 362 | + // Un morceau du jeton est lisible en bdd pour éviter de devoir déchiffrer |
|
| 363 | + // tous les jetons connus pour vérifier le jeton d’un auteur. |
|
| 364 | + $public = substr(creer_uniqid(), 0, 7) . '.'; |
|
| 365 | + $jeton = $public . creer_uniqid(); |
|
| 366 | + $jeton_chiffre_prefixe = $public . Chiffrement::chiffrer($jeton, SpipCles::secret_du_site()); |
|
| 367 | + sql_updateq('spip_auteurs', ['cookie_oubli' => $jeton_chiffre_prefixe], 'id_auteur=' . intval($id_auteur)); |
|
| 368 | + } while (sql_countsel('spip_auteurs', 'cookie_oubli=' . sql_quote($jeton_chiffre_prefixe, '', 'string')) > 1); |
|
| 369 | + |
|
| 370 | + return $jeton; |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
@@ -381,20 +381,20 @@ discard block |
||
| 381 | 381 | * @return string|null |
| 382 | 382 | */ |
| 383 | 383 | function auteur_lire_jeton(int $id_auteur, bool $autoInit = false): ?string { |
| 384 | - include_spip('base/abstract_sql'); |
|
| 385 | - $jeton_chiffre_prefixe = sql_getfetsel('cookie_oubli', 'spip_auteurs', 'id_auteur=' . $id_auteur); |
|
| 386 | - if ($jeton_chiffre_prefixe) { |
|
| 387 | - include_spip('inc/chiffrer'); |
|
| 388 | - $jeton_chiffre = substr($jeton_chiffre_prefixe, 8); |
|
| 389 | - $jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site()); |
|
| 390 | - if ($jeton) { |
|
| 391 | - return $jeton; |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - if ($autoInit) { |
|
| 395 | - return auteur_attribuer_jeton($id_auteur); |
|
| 396 | - } |
|
| 397 | - return null; |
|
| 384 | + include_spip('base/abstract_sql'); |
|
| 385 | + $jeton_chiffre_prefixe = sql_getfetsel('cookie_oubli', 'spip_auteurs', 'id_auteur=' . $id_auteur); |
|
| 386 | + if ($jeton_chiffre_prefixe) { |
|
| 387 | + include_spip('inc/chiffrer'); |
|
| 388 | + $jeton_chiffre = substr($jeton_chiffre_prefixe, 8); |
|
| 389 | + $jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site()); |
|
| 390 | + if ($jeton) { |
|
| 391 | + return $jeton; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + if ($autoInit) { |
|
| 395 | + return auteur_attribuer_jeton($id_auteur); |
|
| 396 | + } |
|
| 397 | + return null; |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | /** |
@@ -404,25 +404,25 @@ discard block |
||
| 404 | 404 | * @return array|bool |
| 405 | 405 | */ |
| 406 | 406 | function auteur_verifier_jeton($jeton) { |
| 407 | - // refuser un jeton corrompu |
|
| 408 | - if (preg_match(',[^0-9a-f.],i', $jeton)) { |
|
| 409 | - return false; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - include_spip('base/abstract_sql'); |
|
| 413 | - include_spip('inc/chiffrer'); |
|
| 414 | - $public = substr($jeton, 0, 8); |
|
| 415 | - |
|
| 416 | - // Les auteurs qui ont un jetons ressemblant |
|
| 417 | - $auteurs = sql_allfetsel('*', 'spip_auteurs', 'cookie_oubli LIKE ' . sql_quote($public . '%')); |
|
| 418 | - foreach ($auteurs as $auteur) { |
|
| 419 | - $jeton_chiffre = substr($auteur['cookie_oubli'], 8); |
|
| 420 | - $_jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site()); |
|
| 421 | - if ($_jeton and hash_equals($jeton, $_jeton)) { |
|
| 422 | - return $auteur; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - return false; |
|
| 407 | + // refuser un jeton corrompu |
|
| 408 | + if (preg_match(',[^0-9a-f.],i', $jeton)) { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + include_spip('base/abstract_sql'); |
|
| 413 | + include_spip('inc/chiffrer'); |
|
| 414 | + $public = substr($jeton, 0, 8); |
|
| 415 | + |
|
| 416 | + // Les auteurs qui ont un jetons ressemblant |
|
| 417 | + $auteurs = sql_allfetsel('*', 'spip_auteurs', 'cookie_oubli LIKE ' . sql_quote($public . '%')); |
|
| 418 | + foreach ($auteurs as $auteur) { |
|
| 419 | + $jeton_chiffre = substr($auteur['cookie_oubli'], 8); |
|
| 420 | + $_jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site()); |
|
| 421 | + if ($_jeton and hash_equals($jeton, $_jeton)) { |
|
| 422 | + return $auteur; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + return false; |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
@@ -432,6 +432,6 @@ discard block |
||
| 432 | 432 | * @return bool |
| 433 | 433 | */ |
| 434 | 434 | function auteur_effacer_jeton($id_auteur) { |
| 435 | - include_spip('base/abstract_sql'); |
|
| 436 | - return sql_updateq('spip_auteurs', ['cookie_oubli' => ''], 'id_auteur=' . intval($id_auteur)); |
|
| 435 | + include_spip('base/abstract_sql'); |
|
| 436 | + return sql_updateq('spip_auteurs', ['cookie_oubli' => ''], 'id_auteur=' . intval($id_auteur)); |
|
| 437 | 437 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/autoriser'); |
@@ -30,80 +30,80 @@ discard block |
||
| 30 | 30 | * Un tableau des sous rubriques |
| 31 | 31 | */ |
| 32 | 32 | function enfant_rub($collection, $debut = 0, $limite = 500) { |
| 33 | - $voir_logo = (isset($GLOBALS['meta']['image_process']) and $GLOBALS['meta']['image_process'] != 'non'); |
|
| 34 | - $logo = ''; |
|
| 35 | - |
|
| 36 | - if ($voir_logo) { |
|
| 37 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 38 | - include_spip('inc/filtres_images_mini'); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - $res = []; |
|
| 42 | - |
|
| 43 | - $result = sql_select( |
|
| 44 | - 'id_rubrique, id_parent, titre, descriptif, lang', |
|
| 45 | - 'spip_rubriques', |
|
| 46 | - 'id_parent=' . intval($collection), |
|
| 47 | - '', |
|
| 48 | - '0+titre,titre', |
|
| 49 | - $debut == -1 ? '' : "$debut,$limite" |
|
| 50 | - ); |
|
| 51 | - while ($row = sql_fetch($result)) { |
|
| 52 | - $id_rubrique = $row['id_rubrique']; |
|
| 53 | - $id_parent = $row['id_parent']; |
|
| 54 | - // pour etre sur de passer par tous les traitements |
|
| 55 | - $titre = generer_objet_info($id_rubrique, 'rubrique', 'titre'); |
|
| 56 | - if ('' !== ($rang = recuperer_numero($row['titre']))) { |
|
| 57 | - $rang = "<span class='rang'>$rang.</span> "; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if (autoriser('voir', 'rubrique', $id_rubrique)) { |
|
| 61 | - $les_sous_enfants = sous_enfant_rub($id_rubrique); |
|
| 62 | - |
|
| 63 | - changer_typo($row['lang']); |
|
| 64 | - $lang_dir = lang_dir($row['lang']); |
|
| 65 | - $descriptif = propre($row['descriptif']); |
|
| 66 | - |
|
| 67 | - if ($voir_logo) { |
|
| 68 | - if ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on')) { |
|
| 69 | - [$fid, $dir, $nom, $format] = $logo; |
|
| 70 | - $logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70); |
|
| 71 | - if ($logo) { |
|
| 72 | - $logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">'); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $lib_bouton = (!acces_restreint_rubrique($id_rubrique) ? '' : |
|
| 78 | - http_img_pack( |
|
| 79 | - 'auteur-0minirezo-16.png', |
|
| 80 | - '', |
|
| 81 | - " width='16' height='16'", |
|
| 82 | - _T('image_administrer_rubrique') |
|
| 83 | - )) . |
|
| 84 | - " <a class='titremlien' dir='$lang_dir'" . |
|
| 85 | - ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 86 | - " href='" . |
|
| 87 | - generer_objet_url($id_rubrique, 'rubrique') . |
|
| 88 | - "'><span class='titre'>" . |
|
| 89 | - $rang . $titre |
|
| 90 | - . '</span>' |
|
| 91 | - . (is_string($logo) ? $logo : '') |
|
| 92 | - . '</a>'; |
|
| 93 | - |
|
| 94 | - $titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique") |
|
| 95 | - . (!$descriptif ? '' : "\n<div class='descriptif'>$descriptif</div>") |
|
| 96 | - ; |
|
| 97 | - |
|
| 98 | - $res[] = |
|
| 99 | - debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 100 | - $les_sous_enfants . |
|
| 101 | - fin_cadre_sous_rub(); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite |
|
| 106 | - return $res; |
|
| 33 | + $voir_logo = (isset($GLOBALS['meta']['image_process']) and $GLOBALS['meta']['image_process'] != 'non'); |
|
| 34 | + $logo = ''; |
|
| 35 | + |
|
| 36 | + if ($voir_logo) { |
|
| 37 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 38 | + include_spip('inc/filtres_images_mini'); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + $res = []; |
|
| 42 | + |
|
| 43 | + $result = sql_select( |
|
| 44 | + 'id_rubrique, id_parent, titre, descriptif, lang', |
|
| 45 | + 'spip_rubriques', |
|
| 46 | + 'id_parent=' . intval($collection), |
|
| 47 | + '', |
|
| 48 | + '0+titre,titre', |
|
| 49 | + $debut == -1 ? '' : "$debut,$limite" |
|
| 50 | + ); |
|
| 51 | + while ($row = sql_fetch($result)) { |
|
| 52 | + $id_rubrique = $row['id_rubrique']; |
|
| 53 | + $id_parent = $row['id_parent']; |
|
| 54 | + // pour etre sur de passer par tous les traitements |
|
| 55 | + $titre = generer_objet_info($id_rubrique, 'rubrique', 'titre'); |
|
| 56 | + if ('' !== ($rang = recuperer_numero($row['titre']))) { |
|
| 57 | + $rang = "<span class='rang'>$rang.</span> "; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if (autoriser('voir', 'rubrique', $id_rubrique)) { |
|
| 61 | + $les_sous_enfants = sous_enfant_rub($id_rubrique); |
|
| 62 | + |
|
| 63 | + changer_typo($row['lang']); |
|
| 64 | + $lang_dir = lang_dir($row['lang']); |
|
| 65 | + $descriptif = propre($row['descriptif']); |
|
| 66 | + |
|
| 67 | + if ($voir_logo) { |
|
| 68 | + if ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on')) { |
|
| 69 | + [$fid, $dir, $nom, $format] = $logo; |
|
| 70 | + $logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70); |
|
| 71 | + if ($logo) { |
|
| 72 | + $logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">'); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $lib_bouton = (!acces_restreint_rubrique($id_rubrique) ? '' : |
|
| 78 | + http_img_pack( |
|
| 79 | + 'auteur-0minirezo-16.png', |
|
| 80 | + '', |
|
| 81 | + " width='16' height='16'", |
|
| 82 | + _T('image_administrer_rubrique') |
|
| 83 | + )) . |
|
| 84 | + " <a class='titremlien' dir='$lang_dir'" . |
|
| 85 | + ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 86 | + " href='" . |
|
| 87 | + generer_objet_url($id_rubrique, 'rubrique') . |
|
| 88 | + "'><span class='titre'>" . |
|
| 89 | + $rang . $titre |
|
| 90 | + . '</span>' |
|
| 91 | + . (is_string($logo) ? $logo : '') |
|
| 92 | + . '</a>'; |
|
| 93 | + |
|
| 94 | + $titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique") |
|
| 95 | + . (!$descriptif ? '' : "\n<div class='descriptif'>$descriptif</div>") |
|
| 96 | + ; |
|
| 97 | + |
|
| 98 | + $res[] = |
|
| 99 | + debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 100 | + $les_sous_enfants . |
|
| 101 | + fin_cadre_sous_rub(); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite |
|
| 106 | + return $res; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -116,71 +116,71 @@ discard block |
||
| 116 | 116 | * Le contenu du bloc dépliable |
| 117 | 117 | */ |
| 118 | 118 | function sous_enfant_rub($collection2) { |
| 119 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($collection2)); |
|
| 120 | - |
|
| 121 | - $retour = ''; |
|
| 122 | - $pagination = ''; |
|
| 123 | - $debut = 0; |
|
| 124 | - $limite = 500; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * On ne va afficher que 500 résultats max |
|
| 128 | - * Si > 500 on affiche une pagination |
|
| 129 | - */ |
|
| 130 | - if ($nb > $limite) { |
|
| 131 | - $debut = _request('debut_rubrique' . $collection2) ?: $debut; |
|
| 132 | - $pagination = chercher_filtre('pagination'); |
|
| 133 | - $pagination = '<nav class="pagination">' . $pagination( |
|
| 134 | - $nb, |
|
| 135 | - '_rubrique' . $collection2, |
|
| 136 | - $debut, |
|
| 137 | - $limite, |
|
| 138 | - true, |
|
| 139 | - 'prive' |
|
| 140 | - ) . '</nav>'; |
|
| 141 | - $limite = $debut + $limite; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $result = sql_select( |
|
| 145 | - 'id_rubrique, id_parent, titre, lang', |
|
| 146 | - 'spip_rubriques', |
|
| 147 | - 'id_parent=' . intval($collection2), |
|
| 148 | - '', |
|
| 149 | - '0+titre,titre', |
|
| 150 | - $debut == -1 ? '' : "$debut,$limite" |
|
| 151 | - ); |
|
| 152 | - |
|
| 153 | - while ($row = sql_fetch($result)) { |
|
| 154 | - $id_rubrique2 = $row['id_rubrique']; |
|
| 155 | - $titre2 = generer_objet_info( |
|
| 156 | - $id_rubrique2, |
|
| 157 | - 'rubrique', |
|
| 158 | - 'titre' |
|
| 159 | - ); // pour etre sur de passer par tous les traitements |
|
| 160 | - if ('' !== ($rang2 = recuperer_numero($row['titre']))) { |
|
| 161 | - $rang2 = "<span class='rang'>$rang2.</span> "; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - changer_typo($row['lang']); |
|
| 165 | - $lang_dir = lang_dir($row['lang']); |
|
| 166 | - if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
|
| 167 | - $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url( |
|
| 168 | - $id_rubrique2, |
|
| 169 | - 'rubrique' |
|
| 170 | - ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $retour = $pagination . $retour . $pagination; |
|
| 175 | - |
|
| 176 | - if (!$retour) { |
|
| 177 | - return ''; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return debut_block_depliable($debut > 0 ? true : false, "enfants$collection2") |
|
| 181 | - . "\n<ul class='liste-items sous-sous-rub'>\n" |
|
| 182 | - . $retour |
|
| 183 | - . "</ul>\n" . fin_block() . "\n\n"; |
|
| 119 | + $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($collection2)); |
|
| 120 | + |
|
| 121 | + $retour = ''; |
|
| 122 | + $pagination = ''; |
|
| 123 | + $debut = 0; |
|
| 124 | + $limite = 500; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * On ne va afficher que 500 résultats max |
|
| 128 | + * Si > 500 on affiche une pagination |
|
| 129 | + */ |
|
| 130 | + if ($nb > $limite) { |
|
| 131 | + $debut = _request('debut_rubrique' . $collection2) ?: $debut; |
|
| 132 | + $pagination = chercher_filtre('pagination'); |
|
| 133 | + $pagination = '<nav class="pagination">' . $pagination( |
|
| 134 | + $nb, |
|
| 135 | + '_rubrique' . $collection2, |
|
| 136 | + $debut, |
|
| 137 | + $limite, |
|
| 138 | + true, |
|
| 139 | + 'prive' |
|
| 140 | + ) . '</nav>'; |
|
| 141 | + $limite = $debut + $limite; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $result = sql_select( |
|
| 145 | + 'id_rubrique, id_parent, titre, lang', |
|
| 146 | + 'spip_rubriques', |
|
| 147 | + 'id_parent=' . intval($collection2), |
|
| 148 | + '', |
|
| 149 | + '0+titre,titre', |
|
| 150 | + $debut == -1 ? '' : "$debut,$limite" |
|
| 151 | + ); |
|
| 152 | + |
|
| 153 | + while ($row = sql_fetch($result)) { |
|
| 154 | + $id_rubrique2 = $row['id_rubrique']; |
|
| 155 | + $titre2 = generer_objet_info( |
|
| 156 | + $id_rubrique2, |
|
| 157 | + 'rubrique', |
|
| 158 | + 'titre' |
|
| 159 | + ); // pour etre sur de passer par tous les traitements |
|
| 160 | + if ('' !== ($rang2 = recuperer_numero($row['titre']))) { |
|
| 161 | + $rang2 = "<span class='rang'>$rang2.</span> "; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + changer_typo($row['lang']); |
|
| 165 | + $lang_dir = lang_dir($row['lang']); |
|
| 166 | + if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
|
| 167 | + $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url( |
|
| 168 | + $id_rubrique2, |
|
| 169 | + 'rubrique' |
|
| 170 | + ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $retour = $pagination . $retour . $pagination; |
|
| 175 | + |
|
| 176 | + if (!$retour) { |
|
| 177 | + return ''; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return debut_block_depliable($debut > 0 ? true : false, "enfants$collection2") |
|
| 181 | + . "\n<ul class='liste-items sous-sous-rub'>\n" |
|
| 182 | + . $retour |
|
| 183 | + . "</ul>\n" . fin_block() . "\n\n"; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -195,44 +195,44 @@ discard block |
||
| 195 | 195 | * Le contenu textuel affiché, la liste des sous rubriques |
| 196 | 196 | */ |
| 197 | 197 | function afficher_enfant_rub($id_rubrique = 0) { |
| 198 | - $pagination = ''; |
|
| 199 | - $debut = 0; |
|
| 200 | - $limite = 500; |
|
| 201 | - |
|
| 202 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique)); |
|
| 203 | - |
|
| 204 | - if ($nb > $limite) { |
|
| 205 | - $debut = _request('debut_rubrique' . $id_rubrique) ?: $debut; |
|
| 206 | - $pagination = chercher_filtre('pagination'); |
|
| 207 | - $pagination = '<br class="nettoyeur"><nav class="pagination">' . |
|
| 208 | - $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 209 | - '</nav>'; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $les_enfants = enfant_rub($id_rubrique, $debut, $limite); |
|
| 213 | - |
|
| 214 | - if (!$n = count($les_enfants)) { |
|
| 215 | - return ''; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - if ($n == 1) { |
|
| 219 | - $les_enfants = reset($les_enfants); |
|
| 220 | - $les_enfants2 = ''; |
|
| 221 | - } else { |
|
| 222 | - $n = ceil($n / 2); |
|
| 223 | - $les_enfants2 = implode('', array_slice($les_enfants, $n)); |
|
| 224 | - $les_enfants = implode('', array_slice($les_enfants, 0, $n)); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $res = |
|
| 228 | - $pagination |
|
| 229 | - . "<div class='gauche'>" |
|
| 230 | - . $les_enfants |
|
| 231 | - . '</div>' |
|
| 232 | - . "<div class='droite'>" |
|
| 233 | - . $les_enfants2 |
|
| 234 | - . '</div>' |
|
| 235 | - . $pagination; |
|
| 236 | - |
|
| 237 | - return $res; |
|
| 198 | + $pagination = ''; |
|
| 199 | + $debut = 0; |
|
| 200 | + $limite = 500; |
|
| 201 | + |
|
| 202 | + $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique)); |
|
| 203 | + |
|
| 204 | + if ($nb > $limite) { |
|
| 205 | + $debut = _request('debut_rubrique' . $id_rubrique) ?: $debut; |
|
| 206 | + $pagination = chercher_filtre('pagination'); |
|
| 207 | + $pagination = '<br class="nettoyeur"><nav class="pagination">' . |
|
| 208 | + $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 209 | + '</nav>'; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $les_enfants = enfant_rub($id_rubrique, $debut, $limite); |
|
| 213 | + |
|
| 214 | + if (!$n = count($les_enfants)) { |
|
| 215 | + return ''; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + if ($n == 1) { |
|
| 219 | + $les_enfants = reset($les_enfants); |
|
| 220 | + $les_enfants2 = ''; |
|
| 221 | + } else { |
|
| 222 | + $n = ceil($n / 2); |
|
| 223 | + $les_enfants2 = implode('', array_slice($les_enfants, $n)); |
|
| 224 | + $les_enfants = implode('', array_slice($les_enfants, 0, $n)); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $res = |
|
| 228 | + $pagination |
|
| 229 | + . "<div class='gauche'>" |
|
| 230 | + . $les_enfants |
|
| 231 | + . '</div>' |
|
| 232 | + . "<div class='droite'>" |
|
| 233 | + . $les_enfants2 |
|
| 234 | + . '</div>' |
|
| 235 | + . $pagination; |
|
| 236 | + |
|
| 237 | + return $res; |
|
| 238 | 238 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $result = sql_select( |
| 44 | 44 | 'id_rubrique, id_parent, titre, descriptif, lang', |
| 45 | 45 | 'spip_rubriques', |
| 46 | - 'id_parent=' . intval($collection), |
|
| 46 | + 'id_parent='.intval($collection), |
|
| 47 | 47 | '', |
| 48 | 48 | '0+titre,titre', |
| 49 | 49 | $debut == -1 ? '' : "$debut,$limite" |
@@ -74,19 +74,18 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $lib_bouton = (!acces_restreint_rubrique($id_rubrique) ? '' : |
|
| 78 | - http_img_pack( |
|
| 77 | + $lib_bouton = (!acces_restreint_rubrique($id_rubrique) ? '' : http_img_pack( |
|
| 79 | 78 | 'auteur-0minirezo-16.png', |
| 80 | 79 | '', |
| 81 | 80 | " width='16' height='16'", |
| 82 | 81 | _T('image_administrer_rubrique') |
| 83 | - )) . |
|
| 84 | - " <a class='titremlien' dir='$lang_dir'" . |
|
| 85 | - ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 86 | - " href='" . |
|
| 87 | - generer_objet_url($id_rubrique, 'rubrique') . |
|
| 88 | - "'><span class='titre'>" . |
|
| 89 | - $rang . $titre |
|
| 82 | + )). |
|
| 83 | + " <a class='titremlien' dir='$lang_dir'". |
|
| 84 | + ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='".$row['lang']."'" : ''). |
|
| 85 | + " href='". |
|
| 86 | + generer_objet_url($id_rubrique, 'rubrique'). |
|
| 87 | + "'><span class='titre'>". |
|
| 88 | + $rang.$titre |
|
| 90 | 89 | . '</span>' |
| 91 | 90 | . (is_string($logo) ? $logo : '') |
| 92 | 91 | . '</a>'; |
@@ -96,8 +95,8 @@ discard block |
||
| 96 | 95 | ; |
| 97 | 96 | |
| 98 | 97 | $res[] = |
| 99 | - debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 100 | - $les_sous_enfants . |
|
| 98 | + debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre). |
|
| 99 | + $les_sous_enfants. |
|
| 101 | 100 | fin_cadre_sous_rub(); |
| 102 | 101 | } |
| 103 | 102 | } |
@@ -116,7 +115,7 @@ discard block |
||
| 116 | 115 | * Le contenu du bloc dépliable |
| 117 | 116 | */ |
| 118 | 117 | function sous_enfant_rub($collection2) { |
| 119 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($collection2)); |
|
| 118 | + $nb = sql_countsel('spip_rubriques', 'id_parent='.intval($collection2)); |
|
| 120 | 119 | |
| 121 | 120 | $retour = ''; |
| 122 | 121 | $pagination = ''; |
@@ -128,23 +127,23 @@ discard block |
||
| 128 | 127 | * Si > 500 on affiche une pagination |
| 129 | 128 | */ |
| 130 | 129 | if ($nb > $limite) { |
| 131 | - $debut = _request('debut_rubrique' . $collection2) ?: $debut; |
|
| 130 | + $debut = _request('debut_rubrique'.$collection2) ?: $debut; |
|
| 132 | 131 | $pagination = chercher_filtre('pagination'); |
| 133 | - $pagination = '<nav class="pagination">' . $pagination( |
|
| 132 | + $pagination = '<nav class="pagination">'.$pagination( |
|
| 134 | 133 | $nb, |
| 135 | - '_rubrique' . $collection2, |
|
| 134 | + '_rubrique'.$collection2, |
|
| 136 | 135 | $debut, |
| 137 | 136 | $limite, |
| 138 | 137 | true, |
| 139 | 138 | 'prive' |
| 140 | - ) . '</nav>'; |
|
| 139 | + ).'</nav>'; |
|
| 141 | 140 | $limite = $debut + $limite; |
| 142 | 141 | } |
| 143 | 142 | |
| 144 | 143 | $result = sql_select( |
| 145 | 144 | 'id_rubrique, id_parent, titre, lang', |
| 146 | 145 | 'spip_rubriques', |
| 147 | - 'id_parent=' . intval($collection2), |
|
| 146 | + 'id_parent='.intval($collection2), |
|
| 148 | 147 | '', |
| 149 | 148 | '0+titre,titre', |
| 150 | 149 | $debut == -1 ? '' : "$debut,$limite" |
@@ -164,14 +163,14 @@ discard block |
||
| 164 | 163 | changer_typo($row['lang']); |
| 165 | 164 | $lang_dir = lang_dir($row['lang']); |
| 166 | 165 | if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
| 167 | - $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url( |
|
| 166 | + $retour .= "\n<li class='item' dir='$lang_dir'><a href='".generer_objet_url( |
|
| 168 | 167 | $id_rubrique2, |
| 169 | 168 | 'rubrique' |
| 170 | - ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 169 | + )."'>".$rang2.$titre2."</a></li>\n"; |
|
| 171 | 170 | } |
| 172 | 171 | } |
| 173 | 172 | |
| 174 | - $retour = $pagination . $retour . $pagination; |
|
| 173 | + $retour = $pagination.$retour.$pagination; |
|
| 175 | 174 | |
| 176 | 175 | if (!$retour) { |
| 177 | 176 | return ''; |
@@ -180,7 +179,7 @@ discard block |
||
| 180 | 179 | return debut_block_depliable($debut > 0 ? true : false, "enfants$collection2") |
| 181 | 180 | . "\n<ul class='liste-items sous-sous-rub'>\n" |
| 182 | 181 | . $retour |
| 183 | - . "</ul>\n" . fin_block() . "\n\n"; |
|
| 182 | + . "</ul>\n".fin_block()."\n\n"; |
|
| 184 | 183 | } |
| 185 | 184 | |
| 186 | 185 | /** |
@@ -199,13 +198,13 @@ discard block |
||
| 199 | 198 | $debut = 0; |
| 200 | 199 | $limite = 500; |
| 201 | 200 | |
| 202 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique)); |
|
| 201 | + $nb = sql_countsel('spip_rubriques', 'id_parent='.intval($id_rubrique)); |
|
| 203 | 202 | |
| 204 | 203 | if ($nb > $limite) { |
| 205 | - $debut = _request('debut_rubrique' . $id_rubrique) ?: $debut; |
|
| 204 | + $debut = _request('debut_rubrique'.$id_rubrique) ?: $debut; |
|
| 206 | 205 | $pagination = chercher_filtre('pagination'); |
| 207 | - $pagination = '<br class="nettoyeur"><nav class="pagination">' . |
|
| 208 | - $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 206 | + $pagination = '<br class="nettoyeur"><nav class="pagination">'. |
|
| 207 | + $pagination($nb, '_rubrique'.$id_rubrique, $debut, $limite, true, 'prive'). |
|
| 209 | 208 | '</nav>'; |
| 210 | 209 | } |
| 211 | 210 | |
@@ -11,129 +11,129 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Decompilation de l'arbre de syntaxe abstraite d'un squelette SPIP |
| 18 | 18 | |
| 19 | 19 | function decompiler_boucle($struct, $fmt = '', $prof = 0) { |
| 20 | - $nom = $struct->id_boucle; |
|
| 21 | - $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | - $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | - $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | - $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | - |
|
| 28 | - $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | - $type .= ($struct->type_requete ?: $struct->table_optionnelle); |
|
| 30 | - |
|
| 31 | - if ($struct->jointures_explicites) { |
|
| 32 | - $type .= ' ' . $struct->jointures_explicites; |
|
| 33 | - } |
|
| 34 | - if ($struct->table_optionnelle) { |
|
| 35 | - $type .= '?'; |
|
| 36 | - } |
|
| 37 | - // Revoir le cas de la boucle recursive |
|
| 38 | - |
|
| 39 | - $crit = $struct->param; |
|
| 40 | - if ($crit and !is_array($crit[0])) { |
|
| 41 | - $type = strtolower($type) . array_shift($crit); |
|
| 42 | - } |
|
| 43 | - $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 44 | - |
|
| 45 | - $f = 'format_boucle_' . $fmt; |
|
| 46 | - |
|
| 47 | - return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 20 | + $nom = $struct->id_boucle; |
|
| 21 | + $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | + $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | + $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | + $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | + |
|
| 28 | + $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | + $type .= ($struct->type_requete ?: $struct->table_optionnelle); |
|
| 30 | + |
|
| 31 | + if ($struct->jointures_explicites) { |
|
| 32 | + $type .= ' ' . $struct->jointures_explicites; |
|
| 33 | + } |
|
| 34 | + if ($struct->table_optionnelle) { |
|
| 35 | + $type .= '?'; |
|
| 36 | + } |
|
| 37 | + // Revoir le cas de la boucle recursive |
|
| 38 | + |
|
| 39 | + $crit = $struct->param; |
|
| 40 | + if ($crit and !is_array($crit[0])) { |
|
| 41 | + $type = strtolower($type) . array_shift($crit); |
|
| 42 | + } |
|
| 43 | + $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 44 | + |
|
| 45 | + $f = 'format_boucle_' . $fmt; |
|
| 46 | + |
|
| 47 | + return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | function decompiler_include($struct, $fmt = '', $prof = 0) { |
| 51 | - $res = []; |
|
| 52 | - foreach ($struct->param ?: [] as $couple) { |
|
| 53 | - array_shift($couple); |
|
| 54 | - foreach ($couple as $v) { |
|
| 55 | - $res[] = decompiler_($v, $fmt, $prof); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 59 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 60 | - $f = 'format_inclure_' . $fmt; |
|
| 61 | - |
|
| 62 | - return $f($file, $res, $prof); |
|
| 51 | + $res = []; |
|
| 52 | + foreach ($struct->param ?: [] as $couple) { |
|
| 53 | + array_shift($couple); |
|
| 54 | + foreach ($couple as $v) { |
|
| 55 | + $res[] = decompiler_($v, $fmt, $prof); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + $file = is_string($struct->texte) ? $struct->texte : |
|
| 59 | + decompiler_($struct->texte, $fmt, $prof); |
|
| 60 | + $f = 'format_inclure_' . $fmt; |
|
| 61 | + |
|
| 62 | + return $f($file, $res, $prof); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 66 | - $f = 'format_texte_' . $fmt; |
|
| 66 | + $f = 'format_texte_' . $fmt; |
|
| 67 | 67 | |
| 68 | - return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 68 | + return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 72 | - $f = 'format_polyglotte_' . $fmt; |
|
| 72 | + $f = 'format_polyglotte_' . $fmt; |
|
| 73 | 73 | |
| 74 | - return $f($struct->traductions, $prof); |
|
| 74 | + return $f($struct->traductions, $prof); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function decompiler_idiome($struct, $fmt = '', $prof = 0) { |
| 78 | - $args = []; |
|
| 79 | - foreach ($struct->arg as $k => $v) { |
|
| 80 | - $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 81 | - } |
|
| 78 | + $args = []; |
|
| 79 | + foreach ($struct->arg as $k => $v) { |
|
| 80 | + $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 83 | + $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 84 | 84 | |
| 85 | - $f = 'format_idiome_' . $fmt; |
|
| 85 | + $f = 'format_idiome_' . $fmt; |
|
| 86 | 86 | |
| 87 | - return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 87 | + return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function decompiler_champ($struct, $fmt = '', $prof = 0) { |
| 91 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 92 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 93 | - $args = $filtres = ''; |
|
| 94 | - if ($p = $struct->param) { |
|
| 95 | - if ($p[0][0] === '') { |
|
| 96 | - $args = decompiler_liste([array_shift($p)], $fmt, $prof); |
|
| 97 | - } |
|
| 98 | - $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 99 | - } |
|
| 100 | - $f = 'format_champ_' . $fmt; |
|
| 101 | - |
|
| 102 | - return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 91 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 92 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 93 | + $args = $filtres = ''; |
|
| 94 | + if ($p = $struct->param) { |
|
| 95 | + if ($p[0][0] === '') { |
|
| 96 | + $args = decompiler_liste([array_shift($p)], $fmt, $prof); |
|
| 97 | + } |
|
| 98 | + $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 99 | + } |
|
| 100 | + $f = 'format_champ_' . $fmt; |
|
| 101 | + |
|
| 102 | + return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | function decompiler_liste($sources, $fmt = '', $prof = 0) { |
| 106 | - if (!is_array($sources)) { |
|
| 107 | - return ''; |
|
| 108 | - } |
|
| 109 | - $f = 'format_liste_' . $fmt; |
|
| 110 | - $res = ''; |
|
| 111 | - foreach ($sources as $arg) { |
|
| 112 | - if (!is_array($arg)) { |
|
| 113 | - continue; // ne devrait pas arriver. |
|
| 114 | - } else { |
|
| 115 | - $r = array_shift($arg); |
|
| 116 | - } |
|
| 117 | - $args = []; |
|
| 118 | - foreach ($arg as $v) { |
|
| 119 | - // cas des arguments entoures de ' ou " |
|
| 120 | - if ( |
|
| 121 | - ((is_countable($v) ? count($v) : 0) == 1) |
|
| 122 | - and $v[0]->type == 'texte' |
|
| 123 | - and (strlen($v[0]->apres) == 1) |
|
| 124 | - and $v[0]->apres == $v[0]->avant |
|
| 125 | - ) { |
|
| 126 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 127 | - } else { |
|
| 128 | - $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - if (($r !== '') or $args) { |
|
| 132 | - $res .= $f($r, $args, $prof); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return $res; |
|
| 106 | + if (!is_array($sources)) { |
|
| 107 | + return ''; |
|
| 108 | + } |
|
| 109 | + $f = 'format_liste_' . $fmt; |
|
| 110 | + $res = ''; |
|
| 111 | + foreach ($sources as $arg) { |
|
| 112 | + if (!is_array($arg)) { |
|
| 113 | + continue; // ne devrait pas arriver. |
|
| 114 | + } else { |
|
| 115 | + $r = array_shift($arg); |
|
| 116 | + } |
|
| 117 | + $args = []; |
|
| 118 | + foreach ($arg as $v) { |
|
| 119 | + // cas des arguments entoures de ' ou " |
|
| 120 | + if ( |
|
| 121 | + ((is_countable($v) ? count($v) : 0) == 1) |
|
| 122 | + and $v[0]->type == 'texte' |
|
| 123 | + and (strlen($v[0]->apres) == 1) |
|
| 124 | + and $v[0]->apres == $v[0]->avant |
|
| 125 | + ) { |
|
| 126 | + $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 127 | + } else { |
|
| 128 | + $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + if (($r !== '') or $args) { |
|
| 132 | + $res .= $f($r, $args, $prof); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return $res; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Decompilation des criteres: on triche et on deroge: |
@@ -141,93 +141,93 @@ discard block |
||
| 141 | 141 | // - le champ apres signale le critere {"separateur"} ou {'separateur'} |
| 142 | 142 | // - les champs sont implicitement etendus (crochets implicites mais interdits) |
| 143 | 143 | function decompiler_criteres($boucle, $fmt = '', $prof = 0) { |
| 144 | - $sources = $boucle->param; |
|
| 145 | - if (!is_array($sources)) { |
|
| 146 | - return ''; |
|
| 147 | - } |
|
| 148 | - $res = ''; |
|
| 149 | - $f = 'format_critere_' . $fmt; |
|
| 150 | - foreach ($sources as $crit) { |
|
| 151 | - if (!is_array($crit)) { |
|
| 152 | - continue; |
|
| 153 | - } // boucle recursive |
|
| 154 | - array_shift($crit); |
|
| 155 | - $args = []; |
|
| 156 | - foreach ($crit as $i => $v) { |
|
| 157 | - if ( |
|
| 158 | - ((is_countable($v) ? count($v) : 0) == 1) |
|
| 159 | - and $v[0]->type == 'texte' |
|
| 160 | - and $v[0]->apres |
|
| 161 | - ) { |
|
| 162 | - $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 163 | - } else { |
|
| 164 | - $res2 = []; |
|
| 165 | - foreach ($v as $k => $p) { |
|
| 166 | - if ( |
|
| 167 | - isset($p->type) |
|
| 168 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 169 | - ) { |
|
| 170 | - $r = $d($p, $fmt, (0 - $prof)); |
|
| 171 | - $res2[] = [$p->type, $r]; |
|
| 172 | - } else { |
|
| 173 | - spip_log("critere $i / $k mal forme"); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - $args[] = $res2; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - $res .= $f($args); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return $res; |
|
| 144 | + $sources = $boucle->param; |
|
| 145 | + if (!is_array($sources)) { |
|
| 146 | + return ''; |
|
| 147 | + } |
|
| 148 | + $res = ''; |
|
| 149 | + $f = 'format_critere_' . $fmt; |
|
| 150 | + foreach ($sources as $crit) { |
|
| 151 | + if (!is_array($crit)) { |
|
| 152 | + continue; |
|
| 153 | + } // boucle recursive |
|
| 154 | + array_shift($crit); |
|
| 155 | + $args = []; |
|
| 156 | + foreach ($crit as $i => $v) { |
|
| 157 | + if ( |
|
| 158 | + ((is_countable($v) ? count($v) : 0) == 1) |
|
| 159 | + and $v[0]->type == 'texte' |
|
| 160 | + and $v[0]->apres |
|
| 161 | + ) { |
|
| 162 | + $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 163 | + } else { |
|
| 164 | + $res2 = []; |
|
| 165 | + foreach ($v as $k => $p) { |
|
| 166 | + if ( |
|
| 167 | + isset($p->type) |
|
| 168 | + and function_exists($d = 'decompiler_' . $p->type) |
|
| 169 | + ) { |
|
| 170 | + $r = $d($p, $fmt, (0 - $prof)); |
|
| 171 | + $res2[] = [$p->type, $r]; |
|
| 172 | + } else { |
|
| 173 | + spip_log("critere $i / $k mal forme"); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + $args[] = $res2; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + $res .= $f($args); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return $res; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
| 186 | 186 | function decompiler_($liste, $fmt = '', $prof = 0) { |
| 187 | - if (!is_array($liste)) { |
|
| 188 | - return ''; |
|
| 189 | - } |
|
| 190 | - $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 191 | - $contenu = []; |
|
| 192 | - foreach ($liste as $k => $p) { |
|
| 193 | - if (!isset($p->type)) { |
|
| 194 | - continue; |
|
| 195 | - } #?????? |
|
| 196 | - $d = 'decompiler_' . $p->type; |
|
| 197 | - $next = $liste[$k + 1] ?? false; |
|
| 198 | - // Forcer le champ etendu si son source (pas les reecritures) |
|
| 199 | - // contenait des args et s'il est suivi d'espaces, |
|
| 200 | - // le champ simple les eliminant est un bug helas perenne. |
|
| 201 | - |
|
| 202 | - if ( |
|
| 203 | - $next |
|
| 204 | - and ($next->type == 'texte') |
|
| 205 | - and $p->type == 'champ' |
|
| 206 | - and !$p->apres |
|
| 207 | - and !$p->avant |
|
| 208 | - and $p->fonctions |
|
| 209 | - ) { |
|
| 210 | - $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 211 | - if ($n) { |
|
| 212 | - $champ = new Texte(); |
|
| 213 | - $champ->texte = substr($next->texte, 0, $n); |
|
| 214 | - $champ->ligne = $p->ligne; |
|
| 215 | - $p->apres = [$champ]; |
|
| 216 | - $next->texte = substr($next->texte, $n); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
|
| 220 | - } |
|
| 221 | - $f = 'format_suite_' . $fmt; |
|
| 222 | - |
|
| 223 | - return $f($contenu); |
|
| 187 | + if (!is_array($liste)) { |
|
| 188 | + return ''; |
|
| 189 | + } |
|
| 190 | + $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 191 | + $contenu = []; |
|
| 192 | + foreach ($liste as $k => $p) { |
|
| 193 | + if (!isset($p->type)) { |
|
| 194 | + continue; |
|
| 195 | + } #?????? |
|
| 196 | + $d = 'decompiler_' . $p->type; |
|
| 197 | + $next = $liste[$k + 1] ?? false; |
|
| 198 | + // Forcer le champ etendu si son source (pas les reecritures) |
|
| 199 | + // contenait des args et s'il est suivi d'espaces, |
|
| 200 | + // le champ simple les eliminant est un bug helas perenne. |
|
| 201 | + |
|
| 202 | + if ( |
|
| 203 | + $next |
|
| 204 | + and ($next->type == 'texte') |
|
| 205 | + and $p->type == 'champ' |
|
| 206 | + and !$p->apres |
|
| 207 | + and !$p->avant |
|
| 208 | + and $p->fonctions |
|
| 209 | + ) { |
|
| 210 | + $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 211 | + if ($n) { |
|
| 212 | + $champ = new Texte(); |
|
| 213 | + $champ->texte = substr($next->texte, 0, $n); |
|
| 214 | + $champ->ligne = $p->ligne; |
|
| 215 | + $p->apres = [$champ]; |
|
| 216 | + $next->texte = substr($next->texte, $n); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
|
| 220 | + } |
|
| 221 | + $f = 'format_suite_' . $fmt; |
|
| 222 | + |
|
| 223 | + return $f($contenu); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 227 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 228 | - return "'$fmt'?"; |
|
| 229 | - } |
|
| 230 | - $f = 'decompiler_' . $quoi; |
|
| 227 | + if (!include_spip('public/format_' . $fmt)) { |
|
| 228 | + return "'$fmt'?"; |
|
| 229 | + } |
|
| 230 | + $f = 'decompiler_' . $quoi; |
|
| 231 | 231 | |
| 232 | - return $f($liste, $fmt, $prof); |
|
| 232 | + return $f($liste, $fmt, $prof); |
|
| 233 | 233 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | $type .= ($struct->type_requete ?: $struct->table_optionnelle); |
| 30 | 30 | |
| 31 | 31 | if ($struct->jointures_explicites) { |
| 32 | - $type .= ' ' . $struct->jointures_explicites; |
|
| 32 | + $type .= ' '.$struct->jointures_explicites; |
|
| 33 | 33 | } |
| 34 | 34 | if ($struct->table_optionnelle) { |
| 35 | 35 | $type .= '?'; |
@@ -38,11 +38,11 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | $crit = $struct->param; |
| 40 | 40 | if ($crit and !is_array($crit[0])) { |
| 41 | - $type = strtolower($type) . array_shift($crit); |
|
| 41 | + $type = strtolower($type).array_shift($crit); |
|
| 42 | 42 | } |
| 43 | 43 | $crit = decompiler_criteres($struct, $fmt, $prof); |
| 44 | 44 | |
| 45 | - $f = 'format_boucle_' . $fmt; |
|
| 45 | + $f = 'format_boucle_'.$fmt; |
|
| 46 | 46 | |
| 47 | 47 | return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
| 48 | 48 | } |
@@ -55,21 +55,20 @@ discard block |
||
| 55 | 55 | $res[] = decompiler_($v, $fmt, $prof); |
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 59 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 60 | - $f = 'format_inclure_' . $fmt; |
|
| 58 | + $file = is_string($struct->texte) ? $struct->texte : decompiler_($struct->texte, $fmt, $prof); |
|
| 59 | + $f = 'format_inclure_'.$fmt; |
|
| 61 | 60 | |
| 62 | 61 | return $f($file, $res, $prof); |
| 63 | 62 | } |
| 64 | 63 | |
| 65 | 64 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 66 | - $f = 'format_texte_' . $fmt; |
|
| 65 | + $f = 'format_texte_'.$fmt; |
|
| 67 | 66 | |
| 68 | 67 | return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
| 69 | 68 | } |
| 70 | 69 | |
| 71 | 70 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 72 | - $f = 'format_polyglotte_' . $fmt; |
|
| 71 | + $f = 'format_polyglotte_'.$fmt; |
|
| 73 | 72 | |
| 74 | 73 | return $f($struct->traductions, $prof); |
| 75 | 74 | } |
@@ -82,7 +81,7 @@ discard block |
||
| 82 | 81 | |
| 83 | 82 | $filtres = decompiler_liste($struct->param, $fmt, $prof); |
| 84 | 83 | |
| 85 | - $f = 'format_idiome_' . $fmt; |
|
| 84 | + $f = 'format_idiome_'.$fmt; |
|
| 86 | 85 | |
| 87 | 86 | return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
| 88 | 87 | } |
@@ -97,7 +96,7 @@ discard block |
||
| 97 | 96 | } |
| 98 | 97 | $filtres = decompiler_liste($p, $fmt, $prof); |
| 99 | 98 | } |
| 100 | - $f = 'format_champ_' . $fmt; |
|
| 99 | + $f = 'format_champ_'.$fmt; |
|
| 101 | 100 | |
| 102 | 101 | return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
| 103 | 102 | } |
@@ -106,7 +105,7 @@ discard block |
||
| 106 | 105 | if (!is_array($sources)) { |
| 107 | 106 | return ''; |
| 108 | 107 | } |
| 109 | - $f = 'format_liste_' . $fmt; |
|
| 108 | + $f = 'format_liste_'.$fmt; |
|
| 110 | 109 | $res = ''; |
| 111 | 110 | foreach ($sources as $arg) { |
| 112 | 111 | if (!is_array($arg)) { |
@@ -123,7 +122,7 @@ discard block |
||
| 123 | 122 | and (strlen($v[0]->apres) == 1) |
| 124 | 123 | and $v[0]->apres == $v[0]->avant |
| 125 | 124 | ) { |
| 126 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 125 | + $args[] = $v[0]->avant.$v[0]->texte.$v[0]->apres; |
|
| 127 | 126 | } else { |
| 128 | 127 | $args[] = decompiler_($v, $fmt, 0 - $prof); |
| 129 | 128 | } |
@@ -146,7 +145,7 @@ discard block |
||
| 146 | 145 | return ''; |
| 147 | 146 | } |
| 148 | 147 | $res = ''; |
| 149 | - $f = 'format_critere_' . $fmt; |
|
| 148 | + $f = 'format_critere_'.$fmt; |
|
| 150 | 149 | foreach ($sources as $crit) { |
| 151 | 150 | if (!is_array($crit)) { |
| 152 | 151 | continue; |
@@ -159,13 +158,13 @@ discard block |
||
| 159 | 158 | and $v[0]->type == 'texte' |
| 160 | 159 | and $v[0]->apres |
| 161 | 160 | ) { |
| 162 | - $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 161 | + $args[] = [['texte', ($v[0]->apres.$v[0]->texte.$v[0]->apres)]]; |
|
| 163 | 162 | } else { |
| 164 | 163 | $res2 = []; |
| 165 | 164 | foreach ($v as $k => $p) { |
| 166 | 165 | if ( |
| 167 | 166 | isset($p->type) |
| 168 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 167 | + and function_exists($d = 'decompiler_'.$p->type) |
|
| 169 | 168 | ) { |
| 170 | 169 | $r = $d($p, $fmt, (0 - $prof)); |
| 171 | 170 | $res2[] = [$p->type, $r]; |
@@ -193,7 +192,7 @@ discard block |
||
| 193 | 192 | if (!isset($p->type)) { |
| 194 | 193 | continue; |
| 195 | 194 | } #?????? |
| 196 | - $d = 'decompiler_' . $p->type; |
|
| 195 | + $d = 'decompiler_'.$p->type; |
|
| 197 | 196 | $next = $liste[$k + 1] ?? false; |
| 198 | 197 | // Forcer le champ etendu si son source (pas les reecritures) |
| 199 | 198 | // contenait des args et s'il est suivi d'espaces, |
@@ -218,16 +217,16 @@ discard block |
||
| 218 | 217 | } |
| 219 | 218 | $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
| 220 | 219 | } |
| 221 | - $f = 'format_suite_' . $fmt; |
|
| 220 | + $f = 'format_suite_'.$fmt; |
|
| 222 | 221 | |
| 223 | 222 | return $f($contenu); |
| 224 | 223 | } |
| 225 | 224 | |
| 226 | 225 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 227 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 226 | + if (!include_spip('public/format_'.$fmt)) { |
|
| 228 | 227 | return "'$fmt'?"; |
| 229 | 228 | } |
| 230 | - $f = 'decompiler_' . $quoi; |
|
| 229 | + $f = 'decompiler_'.$quoi; |
|
| 231 | 230 | |
| 232 | 231 | return $f($liste, $fmt, $prof); |
| 233 | 232 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Queue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | define('_JQ_SCHEDULED', 1); |
@@ -50,103 +50,103 @@ discard block |
||
| 50 | 50 | * id of job |
| 51 | 51 | */ |
| 52 | 52 | function queue_add_job( |
| 53 | - $function, |
|
| 54 | - $description, |
|
| 55 | - $arguments = [], |
|
| 56 | - $file = '', |
|
| 57 | - $no_duplicate = false, |
|
| 58 | - $time = 0, |
|
| 59 | - $priority = 0 |
|
| 53 | + $function, |
|
| 54 | + $description, |
|
| 55 | + $arguments = [], |
|
| 56 | + $file = '', |
|
| 57 | + $no_duplicate = false, |
|
| 58 | + $time = 0, |
|
| 59 | + $priority = 0 |
|
| 60 | 60 | ) { |
| 61 | - include_spip('base/abstract_sql'); |
|
| 62 | - |
|
| 63 | - // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 64 | - if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 65 | - $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // serialiser les arguments |
|
| 69 | - $arguments = serialize($arguments); |
|
| 70 | - $md5args = md5($arguments); |
|
| 71 | - |
|
| 72 | - // si pas de date programee, des que possible |
|
| 73 | - $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 74 | - if (!$time) { |
|
| 75 | - $time = time(); |
|
| 76 | - $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 77 | - } |
|
| 78 | - $date = date('Y-m-d H:i:s', $time); |
|
| 79 | - |
|
| 80 | - $set_job = [ |
|
| 81 | - 'fonction' => $function, |
|
| 82 | - 'descriptif' => $description, |
|
| 83 | - 'args' => $arguments, |
|
| 84 | - 'md5args' => $md5args, |
|
| 85 | - 'inclure' => $file, |
|
| 86 | - 'priorite' => max(-10, min(10, intval($priority))), |
|
| 87 | - 'date' => $date, |
|
| 88 | - 'status' => _JQ_SCHEDULED, |
|
| 89 | - ]; |
|
| 90 | - // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 91 | - // avec les memes args et file |
|
| 92 | - if ( |
|
| 93 | - $no_duplicate |
|
| 94 | - and |
|
| 95 | - $id_job = sql_getfetsel( |
|
| 96 | - 'id_job', |
|
| 97 | - 'spip_jobs', |
|
| 98 | - $duplicate_where = |
|
| 99 | - $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 100 | - . (($no_duplicate === 'function_only') ? '' : |
|
| 101 | - ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file)) |
|
| 102 | - ) |
|
| 103 | - ) { |
|
| 104 | - return $id_job; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 108 | - // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 109 | - // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 110 | - // doit s'effacer |
|
| 111 | - if ( |
|
| 112 | - $no_duplicate |
|
| 113 | - and |
|
| 114 | - $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where") |
|
| 115 | - ) { |
|
| 116 | - sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 117 | - |
|
| 118 | - return $id_prev; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 122 | - // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 123 | - |
|
| 124 | - // une option de debug pour verifier que les arguments en base sont bons |
|
| 125 | - // ie cas d'un char non acceptables sur certains type de champs |
|
| 126 | - // qui coupe la valeur |
|
| 127 | - if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
|
| 128 | - $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 129 | - if ($args !== $arguments) { |
|
| 130 | - spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export( |
|
| 131 | - $arguments, |
|
| 132 | - true |
|
| 133 | - ), 'queue'); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - if ($id_job) { |
|
| 138 | - queue_update_next_job_time($time); |
|
| 139 | - } |
|
| 140 | - // si la mise en file d'attente du job echoue, |
|
| 141 | - // il ne faut pas perdre l'execution de la fonction |
|
| 142 | - // on la lance immediatement, c'est un fallback |
|
| 143 | - // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 144 | - elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 145 | - $set_job['id_job'] = 0; |
|
| 146 | - queue_start_job($set_job); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $id_job; |
|
| 61 | + include_spip('base/abstract_sql'); |
|
| 62 | + |
|
| 63 | + // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 64 | + if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 65 | + $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // serialiser les arguments |
|
| 69 | + $arguments = serialize($arguments); |
|
| 70 | + $md5args = md5($arguments); |
|
| 71 | + |
|
| 72 | + // si pas de date programee, des que possible |
|
| 73 | + $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 74 | + if (!$time) { |
|
| 75 | + $time = time(); |
|
| 76 | + $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 77 | + } |
|
| 78 | + $date = date('Y-m-d H:i:s', $time); |
|
| 79 | + |
|
| 80 | + $set_job = [ |
|
| 81 | + 'fonction' => $function, |
|
| 82 | + 'descriptif' => $description, |
|
| 83 | + 'args' => $arguments, |
|
| 84 | + 'md5args' => $md5args, |
|
| 85 | + 'inclure' => $file, |
|
| 86 | + 'priorite' => max(-10, min(10, intval($priority))), |
|
| 87 | + 'date' => $date, |
|
| 88 | + 'status' => _JQ_SCHEDULED, |
|
| 89 | + ]; |
|
| 90 | + // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 91 | + // avec les memes args et file |
|
| 92 | + if ( |
|
| 93 | + $no_duplicate |
|
| 94 | + and |
|
| 95 | + $id_job = sql_getfetsel( |
|
| 96 | + 'id_job', |
|
| 97 | + 'spip_jobs', |
|
| 98 | + $duplicate_where = |
|
| 99 | + $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 100 | + . (($no_duplicate === 'function_only') ? '' : |
|
| 101 | + ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file)) |
|
| 102 | + ) |
|
| 103 | + ) { |
|
| 104 | + return $id_job; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 108 | + // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 109 | + // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 110 | + // doit s'effacer |
|
| 111 | + if ( |
|
| 112 | + $no_duplicate |
|
| 113 | + and |
|
| 114 | + $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where") |
|
| 115 | + ) { |
|
| 116 | + sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 117 | + |
|
| 118 | + return $id_prev; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 122 | + // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 123 | + |
|
| 124 | + // une option de debug pour verifier que les arguments en base sont bons |
|
| 125 | + // ie cas d'un char non acceptables sur certains type de champs |
|
| 126 | + // qui coupe la valeur |
|
| 127 | + if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
|
| 128 | + $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 129 | + if ($args !== $arguments) { |
|
| 130 | + spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export( |
|
| 131 | + $arguments, |
|
| 132 | + true |
|
| 133 | + ), 'queue'); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + if ($id_job) { |
|
| 138 | + queue_update_next_job_time($time); |
|
| 139 | + } |
|
| 140 | + // si la mise en file d'attente du job echoue, |
|
| 141 | + // il ne faut pas perdre l'execution de la fonction |
|
| 142 | + // on la lance immediatement, c'est un fallback |
|
| 143 | + // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 144 | + elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 145 | + $set_job['id_job'] = 0; |
|
| 146 | + queue_start_job($set_job); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $id_job; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -155,11 +155,11 @@ discard block |
||
| 155 | 155 | * @return void |
| 156 | 156 | */ |
| 157 | 157 | function queue_purger() { |
| 158 | - include_spip('base/abstract_sql'); |
|
| 159 | - sql_delete('spip_jobs'); |
|
| 160 | - sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')'); |
|
| 161 | - include_spip('inc/genie'); |
|
| 162 | - genie_queue_watch_dist(); |
|
| 158 | + include_spip('base/abstract_sql'); |
|
| 159 | + sql_delete('spip_jobs'); |
|
| 160 | + sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')'); |
|
| 161 | + include_spip('inc/genie'); |
|
| 162 | + genie_queue_watch_dist(); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -170,25 +170,25 @@ discard block |
||
| 170 | 170 | * @return int|bool |
| 171 | 171 | */ |
| 172 | 172 | function queue_remove_job($id_job) { |
| 173 | - include_spip('base/abstract_sql'); |
|
| 174 | - |
|
| 175 | - if ( |
|
| 176 | - $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 177 | - and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 178 | - ) { |
|
| 179 | - queue_unlink_job($id_job); |
|
| 180 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 181 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 182 | - // relancer avec les nouveaux arguments de temps |
|
| 183 | - include_spip('inc/genie'); |
|
| 184 | - // relancer avec la periode prevue |
|
| 185 | - queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 186 | - } |
|
| 187 | - queue_update_next_job_time(); |
|
| 188 | - return $res; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 173 | + include_spip('base/abstract_sql'); |
|
| 174 | + |
|
| 175 | + if ( |
|
| 176 | + $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 177 | + and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 178 | + ) { |
|
| 179 | + queue_unlink_job($id_job); |
|
| 180 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 181 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 182 | + // relancer avec les nouveaux arguments de temps |
|
| 183 | + include_spip('inc/genie'); |
|
| 184 | + // relancer avec la periode prevue |
|
| 185 | + queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 186 | + } |
|
| 187 | + queue_update_next_job_time(); |
|
| 188 | + return $res; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -201,18 +201,18 @@ discard block |
||
| 201 | 201 | * ou un tableau composé de tableaux simples pour lieur plusieurs objets en une fois |
| 202 | 202 | */ |
| 203 | 203 | function queue_link_job($id_job, $objets) { |
| 204 | - include_spip('base/abstract_sql'); |
|
| 205 | - |
|
| 206 | - if (is_array($objets) and count($objets)) { |
|
| 207 | - if (is_array(reset($objets))) { |
|
| 208 | - foreach ($objets as $k => $o) { |
|
| 209 | - $objets[$k]['id_job'] = $id_job; |
|
| 210 | - } |
|
| 211 | - sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 212 | - } else { |
|
| 213 | - sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets)); |
|
| 214 | - } |
|
| 215 | - } |
|
| 204 | + include_spip('base/abstract_sql'); |
|
| 205 | + |
|
| 206 | + if (is_array($objets) and count($objets)) { |
|
| 207 | + if (is_array(reset($objets))) { |
|
| 208 | + foreach ($objets as $k => $o) { |
|
| 209 | + $objets[$k]['id_job'] = $id_job; |
|
| 210 | + } |
|
| 211 | + sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 212 | + } else { |
|
| 213 | + sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets)); |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * resultat du sql_delete |
| 225 | 225 | */ |
| 226 | 226 | function queue_unlink_job($id_job) { |
| 227 | - return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job)); |
|
| 227 | + return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job)); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -237,36 +237,36 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | function queue_start_job($row) { |
| 239 | 239 | |
| 240 | - // deserialiser les arguments |
|
| 241 | - $args = unserialize($row['args']); |
|
| 242 | - if (!is_array($args)) { |
|
| 243 | - spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 244 | - $args = []; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - $fonction = $row['fonction']; |
|
| 248 | - if (strlen($inclure = trim($row['inclure']))) { |
|
| 249 | - if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction |
|
| 250 | - $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 251 | - if ($f) { |
|
| 252 | - $fonction = $f; |
|
| 253 | - } |
|
| 254 | - } else { |
|
| 255 | - include_spip($inclure); |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - if (!function_exists($fonction)) { |
|
| 260 | - spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 261 | - |
|
| 262 | - return false; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 266 | - $res = $fonction(...$args); |
|
| 267 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 268 | - |
|
| 269 | - return $res; |
|
| 240 | + // deserialiser les arguments |
|
| 241 | + $args = unserialize($row['args']); |
|
| 242 | + if (!is_array($args)) { |
|
| 243 | + spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 244 | + $args = []; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + $fonction = $row['fonction']; |
|
| 248 | + if (strlen($inclure = trim($row['inclure']))) { |
|
| 249 | + if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction |
|
| 250 | + $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 251 | + if ($f) { |
|
| 252 | + $fonction = $f; |
|
| 253 | + } |
|
| 254 | + } else { |
|
| 255 | + include_spip($inclure); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + if (!function_exists($fonction)) { |
|
| 260 | + spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 261 | + |
|
| 262 | + return false; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 266 | + $res = $fonction(...$args); |
|
| 267 | + spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 268 | + |
|
| 269 | + return $res; |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -293,89 +293,89 @@ discard block |
||
| 293 | 293 | * - true : une planification a été faite. |
| 294 | 294 | */ |
| 295 | 295 | function queue_schedule($force_jobs = null) { |
| 296 | - $time = time(); |
|
| 297 | - if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 298 | - spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG); |
|
| 299 | - |
|
| 300 | - return; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - // rien a faire si le prochain job est encore dans le futur |
|
| 304 | - if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
|
| 305 | - spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG); |
|
| 306 | - |
|
| 307 | - return; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - include_spip('base/abstract_sql'); |
|
| 311 | - // on ne peut rien faire si pas de connexion SQL |
|
| 312 | - if (!spip_connect()) { |
|
| 313 | - return false; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 317 | - $max_time = ini_get('max_execution_time') / 2; |
|
| 318 | - // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 319 | - if (!$max_time) { |
|
| 320 | - $max_time = 5; |
|
| 321 | - } |
|
| 322 | - define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 323 | - } |
|
| 324 | - $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 325 | - |
|
| 326 | - spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 327 | - |
|
| 328 | - if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 329 | - define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 330 | - } |
|
| 331 | - $nbj = 0; |
|
| 332 | - // attraper les jobs |
|
| 333 | - // dont la date est passee (echus en attente), |
|
| 334 | - // par ordre : |
|
| 335 | - // - de priorite |
|
| 336 | - // - de date |
|
| 337 | - // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 338 | - // pour qu'il ne bloque pas les autres jobs en attente |
|
| 339 | - if (is_array($force_jobs) and count($force_jobs)) { |
|
| 340 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs); |
|
| 341 | - } else { |
|
| 342 | - $now = date('Y-m-d H:i:s', $time); |
|
| 343 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 347 | - $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 348 | - do { |
|
| 349 | - if ($row = array_shift($res)) { |
|
| 350 | - $nbj++; |
|
| 351 | - // il faut un verrou, a base de sql_delete |
|
| 352 | - if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) { |
|
| 353 | - #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 354 | - // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 355 | - $row['status'] = _JQ_PENDING; |
|
| 356 | - $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 357 | - sql_insertq('spip_jobs', $row); |
|
| 358 | - |
|
| 359 | - // on a la main sur le job : |
|
| 360 | - // l'executer |
|
| 361 | - $result = queue_start_job($row); |
|
| 362 | - |
|
| 363 | - $time = time(); |
|
| 364 | - queue_close_job($row, $time, $result); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG); |
|
| 368 | - } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
|
| 369 | - spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG); |
|
| 370 | - |
|
| 371 | - if ($row = array_shift($res)) { |
|
| 372 | - queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 373 | - spip_log('JQ encore !', 'jq' . _LOG_DEBUG); |
|
| 374 | - } else { |
|
| 375 | - queue_update_next_job_time(); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - return true; |
|
| 296 | + $time = time(); |
|
| 297 | + if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 298 | + spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG); |
|
| 299 | + |
|
| 300 | + return; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + // rien a faire si le prochain job est encore dans le futur |
|
| 304 | + if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
|
| 305 | + spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG); |
|
| 306 | + |
|
| 307 | + return; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + include_spip('base/abstract_sql'); |
|
| 311 | + // on ne peut rien faire si pas de connexion SQL |
|
| 312 | + if (!spip_connect()) { |
|
| 313 | + return false; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 317 | + $max_time = ini_get('max_execution_time') / 2; |
|
| 318 | + // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 319 | + if (!$max_time) { |
|
| 320 | + $max_time = 5; |
|
| 321 | + } |
|
| 322 | + define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 323 | + } |
|
| 324 | + $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 325 | + |
|
| 326 | + spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 327 | + |
|
| 328 | + if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 329 | + define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 330 | + } |
|
| 331 | + $nbj = 0; |
|
| 332 | + // attraper les jobs |
|
| 333 | + // dont la date est passee (echus en attente), |
|
| 334 | + // par ordre : |
|
| 335 | + // - de priorite |
|
| 336 | + // - de date |
|
| 337 | + // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 338 | + // pour qu'il ne bloque pas les autres jobs en attente |
|
| 339 | + if (is_array($force_jobs) and count($force_jobs)) { |
|
| 340 | + $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs); |
|
| 341 | + } else { |
|
| 342 | + $now = date('Y-m-d H:i:s', $time); |
|
| 343 | + $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 347 | + $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 348 | + do { |
|
| 349 | + if ($row = array_shift($res)) { |
|
| 350 | + $nbj++; |
|
| 351 | + // il faut un verrou, a base de sql_delete |
|
| 352 | + if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) { |
|
| 353 | + #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 354 | + // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 355 | + $row['status'] = _JQ_PENDING; |
|
| 356 | + $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 357 | + sql_insertq('spip_jobs', $row); |
|
| 358 | + |
|
| 359 | + // on a la main sur le job : |
|
| 360 | + // l'executer |
|
| 361 | + $result = queue_start_job($row); |
|
| 362 | + |
|
| 363 | + $time = time(); |
|
| 364 | + queue_close_job($row, $time, $result); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG); |
|
| 368 | + } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
|
| 369 | + spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG); |
|
| 370 | + |
|
| 371 | + if ($row = array_shift($res)) { |
|
| 372 | + queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 373 | + spip_log('JQ encore !', 'jq' . _LOG_DEBUG); |
|
| 374 | + } else { |
|
| 375 | + queue_update_next_job_time(); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + return true; |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -393,21 +393,21 @@ discard block |
||
| 393 | 393 | * @param int $result |
| 394 | 394 | */ |
| 395 | 395 | function queue_close_job(&$row, $time, $result = 0) { |
| 396 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 397 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 398 | - // relancer avec les nouveaux arguments de temps |
|
| 399 | - include_spip('inc/genie'); |
|
| 400 | - if ($result < 0) { // relancer tout de suite, mais en baissant la priorite |
|
| 401 | - queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 402 | - } else // relancer avec la periode prevue |
|
| 403 | - { |
|
| 404 | - queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - // purger ses liens eventuels avec des objets |
|
| 408 | - sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job'])); |
|
| 409 | - // supprimer le job fini |
|
| 410 | - sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 396 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 397 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 398 | + // relancer avec les nouveaux arguments de temps |
|
| 399 | + include_spip('inc/genie'); |
|
| 400 | + if ($result < 0) { // relancer tout de suite, mais en baissant la priorite |
|
| 401 | + queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 402 | + } else // relancer avec la periode prevue |
|
| 403 | + { |
|
| 404 | + queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + // purger ses liens eventuels avec des objets |
|
| 408 | + sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job'])); |
|
| 409 | + // supprimer le job fini |
|
| 410 | + sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -417,10 +417,10 @@ discard block |
||
| 417 | 417 | * @uses queue_update_next_job_time() |
| 418 | 418 | */ |
| 419 | 419 | function queue_error_handler() { |
| 420 | - // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 421 | - chdir(_ROOT_CWD); |
|
| 420 | + // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 421 | + chdir(_ROOT_CWD); |
|
| 422 | 422 | |
| 423 | - queue_update_next_job_time(); |
|
| 423 | + queue_update_next_job_time(); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | |
@@ -437,18 +437,18 @@ discard block |
||
| 437 | 437 | * Périodicité de la tâche en secondes, si tâche périodique, sinon false. |
| 438 | 438 | */ |
| 439 | 439 | function queue_is_cron_job($function, $inclure) { |
| 440 | - static $taches = null; |
|
| 441 | - if (strncmp($inclure, 'genie/', 6) == 0) { |
|
| 442 | - if (is_null($taches)) { |
|
| 443 | - include_spip('inc/genie'); |
|
| 444 | - $taches = taches_generales(); |
|
| 445 | - } |
|
| 446 | - if (isset($taches[$function])) { |
|
| 447 | - return $taches[$function]; |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - return false; |
|
| 440 | + static $taches = null; |
|
| 441 | + if (strncmp($inclure, 'genie/', 6) == 0) { |
|
| 442 | + if (is_null($taches)) { |
|
| 443 | + include_spip('inc/genie'); |
|
| 444 | + $taches = taches_generales(); |
|
| 445 | + } |
|
| 446 | + if (isset($taches[$function])) { |
|
| 447 | + return $taches[$function]; |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + return false; |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | /** |
@@ -462,62 +462,62 @@ discard block |
||
| 462 | 462 | * temps de la tache ajoutee ou 0 pour ASAP |
| 463 | 463 | */ |
| 464 | 464 | function queue_update_next_job_time($next_time = null) { |
| 465 | - static $nb_jobs_scheduled = null; |
|
| 466 | - static $deja_la = false; |
|
| 467 | - // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 468 | - static $next = null; |
|
| 469 | - // queue_close_job peut etre reentrant ici |
|
| 470 | - if ($deja_la) { |
|
| 471 | - return; |
|
| 472 | - } |
|
| 473 | - $deja_la = true; |
|
| 474 | - |
|
| 475 | - include_spip('base/abstract_sql'); |
|
| 476 | - $time = time(); |
|
| 477 | - |
|
| 478 | - // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 479 | - // pour cause de timeout ou autre erreur fatale |
|
| 480 | - $res = sql_allfetsel( |
|
| 481 | - '*', |
|
| 482 | - 'spip_jobs', |
|
| 483 | - 'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 484 | - ); |
|
| 485 | - if (is_array($res)) { |
|
| 486 | - foreach ($res as $row) { |
|
| 487 | - queue_close_job($row, $time); |
|
| 488 | - spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR); |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - // chercher la date du prochain job si pas connu |
|
| 493 | - if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
|
| 494 | - $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 495 | - $next = strtotime($date); |
|
| 496 | - } |
|
| 497 | - if (!is_null($next_time)) { |
|
| 498 | - if (is_null($next) or $next > $next_time) { |
|
| 499 | - $next = $next_time; |
|
| 500 | - } |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - if ($next) { |
|
| 504 | - if (is_null($nb_jobs_scheduled)) { |
|
| 505 | - $nb_jobs_scheduled = sql_countsel( |
|
| 506 | - 'spip_jobs', |
|
| 507 | - 'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 508 | - ); |
|
| 509 | - } elseif ($next <= $time) { |
|
| 510 | - $nb_jobs_scheduled++; |
|
| 511 | - } |
|
| 512 | - // si trop de jobs en attente, on force la purge en fin de hit |
|
| 513 | - // pour assurer le coup |
|
| 514 | - if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 515 | - define('_DIRECT_CRON_FORCE', true); |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - queue_set_next_job_time($next); |
|
| 520 | - $deja_la = false; |
|
| 465 | + static $nb_jobs_scheduled = null; |
|
| 466 | + static $deja_la = false; |
|
| 467 | + // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 468 | + static $next = null; |
|
| 469 | + // queue_close_job peut etre reentrant ici |
|
| 470 | + if ($deja_la) { |
|
| 471 | + return; |
|
| 472 | + } |
|
| 473 | + $deja_la = true; |
|
| 474 | + |
|
| 475 | + include_spip('base/abstract_sql'); |
|
| 476 | + $time = time(); |
|
| 477 | + |
|
| 478 | + // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 479 | + // pour cause de timeout ou autre erreur fatale |
|
| 480 | + $res = sql_allfetsel( |
|
| 481 | + '*', |
|
| 482 | + 'spip_jobs', |
|
| 483 | + 'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 484 | + ); |
|
| 485 | + if (is_array($res)) { |
|
| 486 | + foreach ($res as $row) { |
|
| 487 | + queue_close_job($row, $time); |
|
| 488 | + spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR); |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + // chercher la date du prochain job si pas connu |
|
| 493 | + if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
|
| 494 | + $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 495 | + $next = strtotime($date); |
|
| 496 | + } |
|
| 497 | + if (!is_null($next_time)) { |
|
| 498 | + if (is_null($next) or $next > $next_time) { |
|
| 499 | + $next = $next_time; |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + if ($next) { |
|
| 504 | + if (is_null($nb_jobs_scheduled)) { |
|
| 505 | + $nb_jobs_scheduled = sql_countsel( |
|
| 506 | + 'spip_jobs', |
|
| 507 | + 'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 508 | + ); |
|
| 509 | + } elseif ($next <= $time) { |
|
| 510 | + $nb_jobs_scheduled++; |
|
| 511 | + } |
|
| 512 | + // si trop de jobs en attente, on force la purge en fin de hit |
|
| 513 | + // pour assurer le coup |
|
| 514 | + if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 515 | + define('_DIRECT_CRON_FORCE', true); |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + queue_set_next_job_time($next); |
|
| 520 | + $deja_la = false; |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | |
@@ -528,26 +528,26 @@ discard block |
||
| 528 | 528 | */ |
| 529 | 529 | function queue_set_next_job_time($next) { |
| 530 | 530 | |
| 531 | - // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 532 | - $time = time(); |
|
| 533 | - |
|
| 534 | - // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 535 | - // et ne mettre a jour que si il y a un interet a le faire |
|
| 536 | - // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 537 | - $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 538 | - if ( |
|
| 539 | - ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 540 | - or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 541 | - ) { |
|
| 542 | - if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 543 | - cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 544 | - } else { |
|
| 545 | - ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 546 | - } |
|
| 547 | - queue_sleep_time_to_next_job($next); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - return queue_sleep_time_to_next_job(); |
|
| 531 | + // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 532 | + $time = time(); |
|
| 533 | + |
|
| 534 | + // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 535 | + // et ne mettre a jour que si il y a un interet a le faire |
|
| 536 | + // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 537 | + $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 538 | + if ( |
|
| 539 | + ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 540 | + or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 541 | + ) { |
|
| 542 | + if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 543 | + cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 544 | + } else { |
|
| 545 | + ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 546 | + } |
|
| 547 | + queue_sleep_time_to_next_job($next); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + return queue_sleep_time_to_next_job(); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -564,60 +564,60 @@ discard block |
||
| 564 | 564 | * @return string |
| 565 | 565 | */ |
| 566 | 566 | function queue_affichage_cron() { |
| 567 | - $texte = ''; |
|
| 568 | - |
|
| 569 | - $time_to_next = queue_sleep_time_to_next_job(); |
|
| 570 | - // rien a faire si le prochain job est encore dans le futur |
|
| 571 | - if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 572 | - return $texte; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 576 | - if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 577 | - return $texte; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - @touch($lock); |
|
| 581 | - |
|
| 582 | - // il y a des taches en attentes |
|
| 583 | - // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 584 | - // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 585 | - $urgent = false; |
|
| 586 | - if ($time_to_next < -300) { |
|
| 587 | - $urgent = true; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - $url_cron = generer_url_action('cron', '', false, true); |
|
| 591 | - |
|
| 592 | - if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) { |
|
| 593 | - if (queue_lancer_url_http_async($url_cron) and !$urgent) { |
|
| 594 | - return $texte; |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - // si deja force, on retourne sans rien |
|
| 599 | - if (defined('_DIRECT_CRON_FORCE')) { |
|
| 600 | - return $texte; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - // si c'est un bot |
|
| 604 | - // inutile de faire un appel par image background, |
|
| 605 | - // on force un appel direct en fin de hit |
|
| 606 | - if ((defined('_IS_BOT') and _IS_BOT)) { |
|
| 607 | - define('_DIRECT_CRON_FORCE', true); |
|
| 608 | - |
|
| 609 | - return $texte; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) { |
|
| 613 | - // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 614 | - $url_cron = generer_url_action('cron'); |
|
| 615 | - $texte = '<!-- SPIP-CRON -->' |
|
| 616 | - . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 617 | - . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - return $texte; |
|
| 567 | + $texte = ''; |
|
| 568 | + |
|
| 569 | + $time_to_next = queue_sleep_time_to_next_job(); |
|
| 570 | + // rien a faire si le prochain job est encore dans le futur |
|
| 571 | + if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 572 | + return $texte; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 576 | + if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 577 | + return $texte; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + @touch($lock); |
|
| 581 | + |
|
| 582 | + // il y a des taches en attentes |
|
| 583 | + // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 584 | + // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 585 | + $urgent = false; |
|
| 586 | + if ($time_to_next < -300) { |
|
| 587 | + $urgent = true; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + $url_cron = generer_url_action('cron', '', false, true); |
|
| 591 | + |
|
| 592 | + if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) { |
|
| 593 | + if (queue_lancer_url_http_async($url_cron) and !$urgent) { |
|
| 594 | + return $texte; |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + // si deja force, on retourne sans rien |
|
| 599 | + if (defined('_DIRECT_CRON_FORCE')) { |
|
| 600 | + return $texte; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + // si c'est un bot |
|
| 604 | + // inutile de faire un appel par image background, |
|
| 605 | + // on force un appel direct en fin de hit |
|
| 606 | + if ((defined('_IS_BOT') and _IS_BOT)) { |
|
| 607 | + define('_DIRECT_CRON_FORCE', true); |
|
| 608 | + |
|
| 609 | + return $texte; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) { |
|
| 613 | + // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 614 | + $url_cron = generer_url_action('cron'); |
|
| 615 | + $texte = '<!-- SPIP-CRON -->' |
|
| 616 | + . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 617 | + . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + return $texte; |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | /** |
@@ -626,73 +626,73 @@ discard block |
||
| 626 | 626 | * @return bool : true si l'url a pu être appelée en asynchrone, false sinon |
| 627 | 627 | */ |
| 628 | 628 | function queue_lancer_url_http_async($url_cron) { |
| 629 | - // methode la plus rapide : |
|
| 630 | - // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 631 | - // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 632 | - // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 633 | - // mais on renvoie false direct |
|
| 634 | - if (function_exists('fsockopen')) { |
|
| 635 | - $parts = parse_url($url_cron); |
|
| 636 | - |
|
| 637 | - switch ($parts['scheme']) { |
|
| 638 | - case 'https': |
|
| 639 | - $scheme = 'ssl://'; |
|
| 640 | - $port = 443; |
|
| 641 | - break; |
|
| 642 | - case 'http': |
|
| 643 | - default: |
|
| 644 | - $scheme = ''; |
|
| 645 | - $port = 80; |
|
| 646 | - } |
|
| 647 | - $fp = @fsockopen( |
|
| 648 | - $scheme . $parts['host'], |
|
| 649 | - $parts['port'] ?? $port, |
|
| 650 | - $errno, |
|
| 651 | - $errstr, |
|
| 652 | - 1 |
|
| 653 | - ); |
|
| 654 | - |
|
| 655 | - if ($fp) { |
|
| 656 | - $host_sent = $parts['host']; |
|
| 657 | - if (isset($parts['port']) and $parts['port'] !== $port) { |
|
| 658 | - $host_sent .= ':' . $parts['port']; |
|
| 659 | - } |
|
| 660 | - $timeout = 200; // ms |
|
| 661 | - stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 662 | - $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : ''); |
|
| 663 | - $out = 'GET ' . $query . " HTTP/1.1\r\n"; |
|
| 664 | - $out .= 'Host: ' . $host_sent . "\r\n"; |
|
| 665 | - $out .= "Connection: Close\r\n\r\n"; |
|
| 666 | - fwrite($fp, $out); |
|
| 667 | - spip_timer('read'); |
|
| 668 | - $t = 0; |
|
| 669 | - // on lit la reponse si possible pour fermer proprement la connexion |
|
| 670 | - // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 671 | - while (!feof($fp) and $t < $timeout) { |
|
| 672 | - @fgets($fp, 1024); |
|
| 673 | - $t += spip_timer('read', true); |
|
| 674 | - spip_timer('read'); |
|
| 675 | - } |
|
| 676 | - fclose($fp); |
|
| 677 | - return true; |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - // si fsockopen n'est pas dispo on essaye cURL : |
|
| 681 | - // lancer le cron par un cURL asynchrone si cURL est present |
|
| 682 | - elseif (function_exists('curl_init')) { |
|
| 683 | - //setting the curl parameters. |
|
| 684 | - $ch = curl_init($url_cron); |
|
| 685 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 686 | - // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 687 | - curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 688 | - // valeur mini pour que la requete soit lancee |
|
| 689 | - curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 690 | - // lancer |
|
| 691 | - curl_exec($ch); |
|
| 692 | - // fermer |
|
| 693 | - curl_close($ch); |
|
| 694 | - return true; |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - return false; |
|
| 629 | + // methode la plus rapide : |
|
| 630 | + // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 631 | + // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 632 | + // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 633 | + // mais on renvoie false direct |
|
| 634 | + if (function_exists('fsockopen')) { |
|
| 635 | + $parts = parse_url($url_cron); |
|
| 636 | + |
|
| 637 | + switch ($parts['scheme']) { |
|
| 638 | + case 'https': |
|
| 639 | + $scheme = 'ssl://'; |
|
| 640 | + $port = 443; |
|
| 641 | + break; |
|
| 642 | + case 'http': |
|
| 643 | + default: |
|
| 644 | + $scheme = ''; |
|
| 645 | + $port = 80; |
|
| 646 | + } |
|
| 647 | + $fp = @fsockopen( |
|
| 648 | + $scheme . $parts['host'], |
|
| 649 | + $parts['port'] ?? $port, |
|
| 650 | + $errno, |
|
| 651 | + $errstr, |
|
| 652 | + 1 |
|
| 653 | + ); |
|
| 654 | + |
|
| 655 | + if ($fp) { |
|
| 656 | + $host_sent = $parts['host']; |
|
| 657 | + if (isset($parts['port']) and $parts['port'] !== $port) { |
|
| 658 | + $host_sent .= ':' . $parts['port']; |
|
| 659 | + } |
|
| 660 | + $timeout = 200; // ms |
|
| 661 | + stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 662 | + $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : ''); |
|
| 663 | + $out = 'GET ' . $query . " HTTP/1.1\r\n"; |
|
| 664 | + $out .= 'Host: ' . $host_sent . "\r\n"; |
|
| 665 | + $out .= "Connection: Close\r\n\r\n"; |
|
| 666 | + fwrite($fp, $out); |
|
| 667 | + spip_timer('read'); |
|
| 668 | + $t = 0; |
|
| 669 | + // on lit la reponse si possible pour fermer proprement la connexion |
|
| 670 | + // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 671 | + while (!feof($fp) and $t < $timeout) { |
|
| 672 | + @fgets($fp, 1024); |
|
| 673 | + $t += spip_timer('read', true); |
|
| 674 | + spip_timer('read'); |
|
| 675 | + } |
|
| 676 | + fclose($fp); |
|
| 677 | + return true; |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + // si fsockopen n'est pas dispo on essaye cURL : |
|
| 681 | + // lancer le cron par un cURL asynchrone si cURL est present |
|
| 682 | + elseif (function_exists('curl_init')) { |
|
| 683 | + //setting the curl parameters. |
|
| 684 | + $ch = curl_init($url_cron); |
|
| 685 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 686 | + // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 687 | + curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 688 | + // valeur mini pour que la requete soit lancee |
|
| 689 | + curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 690 | + // lancer |
|
| 691 | + curl_exec($ch); |
|
| 692 | + // fermer |
|
| 693 | + curl_close($ch); |
|
| 694 | + return true; |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + return false; |
|
| 698 | 698 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $md5args = md5($arguments); |
| 71 | 71 | |
| 72 | 72 | // si pas de date programee, des que possible |
| 73 | - $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 73 | + $duplicate_where = 'status='.intval(_JQ_SCHEDULED).' AND '; |
|
| 74 | 74 | if (!$time) { |
| 75 | 75 | $time = time(); |
| 76 | 76 | $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution |
@@ -96,9 +96,8 @@ discard block |
||
| 96 | 96 | 'id_job', |
| 97 | 97 | 'spip_jobs', |
| 98 | 98 | $duplicate_where = |
| 99 | - $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 100 | - . (($no_duplicate === 'function_only') ? '' : |
|
| 101 | - ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file)) |
|
| 99 | + $duplicate_where.'fonction='.sql_quote($function) |
|
| 100 | + . (($no_duplicate === 'function_only') ? '' : ' AND md5args='.sql_quote($md5args).' AND inclure='.sql_quote($file)) |
|
| 102 | 101 | ) |
| 103 | 102 | ) { |
| 104 | 103 | return $id_job; |
@@ -111,9 +110,9 @@ discard block |
||
| 111 | 110 | if ( |
| 112 | 111 | $no_duplicate |
| 113 | 112 | and |
| 114 | - $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where") |
|
| 113 | + $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<'.intval($id_job)." AND $duplicate_where") |
|
| 115 | 114 | ) { |
| 116 | - sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 115 | + sql_delete('spip_jobs', 'id_job='.intval($id_job)); |
|
| 117 | 116 | |
| 118 | 117 | return $id_prev; |
| 119 | 118 | } |
@@ -125,9 +124,9 @@ discard block |
||
| 125 | 124 | // ie cas d'un char non acceptables sur certains type de champs |
| 126 | 125 | // qui coupe la valeur |
| 127 | 126 | if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
| 128 | - $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 127 | + $args = sql_getfetsel('args', 'spip_jobs', 'id_job='.intval($id_job)); |
|
| 129 | 128 | if ($args !== $arguments) { |
| 130 | - spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export( |
|
| 129 | + spip_log('arguments job errones / longueur '.strlen($args).' vs '.strlen($arguments).' / valeur : '.var_export( |
|
| 131 | 130 | $arguments, |
| 132 | 131 | true |
| 133 | 132 | ), 'queue'); |
@@ -157,7 +156,7 @@ discard block |
||
| 157 | 156 | function queue_purger() { |
| 158 | 157 | include_spip('base/abstract_sql'); |
| 159 | 158 | sql_delete('spip_jobs'); |
| 160 | - sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')'); |
|
| 159 | + sql_delete('spip_jobs_liens', 'id_job NOT IN ('.sql_get_select('id_job', 'spip_jobs').')'); |
|
| 161 | 160 | include_spip('inc/genie'); |
| 162 | 161 | genie_queue_watch_dist(); |
| 163 | 162 | } |
@@ -173,8 +172,8 @@ discard block |
||
| 173 | 172 | include_spip('base/abstract_sql'); |
| 174 | 173 | |
| 175 | 174 | if ( |
| 176 | - $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 177 | - and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 175 | + $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job='.intval($id_job)) |
|
| 176 | + and $res = sql_delete('spip_jobs', 'id_job='.intval($id_job)) |
|
| 178 | 177 | ) { |
| 179 | 178 | queue_unlink_job($id_job); |
| 180 | 179 | // est-ce une tache cron qu'il faut relancer ? |
@@ -224,7 +223,7 @@ discard block |
||
| 224 | 223 | * resultat du sql_delete |
| 225 | 224 | */ |
| 226 | 225 | function queue_unlink_job($id_job) { |
| 227 | - return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job)); |
|
| 226 | + return sql_delete('spip_jobs_liens', 'id_job='.intval($id_job)); |
|
| 228 | 227 | } |
| 229 | 228 | |
| 230 | 229 | /** |
@@ -240,7 +239,7 @@ discard block |
||
| 240 | 239 | // deserialiser les arguments |
| 241 | 240 | $args = unserialize($row['args']); |
| 242 | 241 | if (!is_array($args)) { |
| 243 | - spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 242 | + spip_log('arguments job errones '.var_export($row, true), 'queue'); |
|
| 244 | 243 | $args = []; |
| 245 | 244 | } |
| 246 | 245 | |
@@ -257,14 +256,14 @@ discard block |
||
| 257 | 256 | } |
| 258 | 257 | |
| 259 | 258 | if (!function_exists($fonction)) { |
| 260 | - spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 259 | + spip_log("fonction $fonction ($inclure) inexistante ".var_export($row, true), 'queue'); |
|
| 261 | 260 | |
| 262 | 261 | return false; |
| 263 | 262 | } |
| 264 | 263 | |
| 265 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 264 | + spip_log('queue ['.$row['id_job']."]: $fonction() start", 'queue'); |
|
| 266 | 265 | $res = $fonction(...$args); |
| 267 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 266 | + spip_log('queue ['.$row['id_job']."]: $fonction() end", 'queue'); |
|
| 268 | 267 | |
| 269 | 268 | return $res; |
| 270 | 269 | } |
@@ -295,14 +294,14 @@ discard block |
||
| 295 | 294 | function queue_schedule($force_jobs = null) { |
| 296 | 295 | $time = time(); |
| 297 | 296 | if (defined('_DEBUG_BLOCK_QUEUE')) { |
| 298 | - spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG); |
|
| 297 | + spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq'._LOG_DEBUG); |
|
| 299 | 298 | |
| 300 | 299 | return; |
| 301 | 300 | } |
| 302 | 301 | |
| 303 | 302 | // rien a faire si le prochain job est encore dans le futur |
| 304 | 303 | if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
| 305 | - spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG); |
|
| 304 | + spip_log('queue_sleep_time_to_next_job', 'jq'._LOG_DEBUG); |
|
| 306 | 305 | |
| 307 | 306 | return; |
| 308 | 307 | } |
@@ -323,7 +322,7 @@ discard block |
||
| 323 | 322 | } |
| 324 | 323 | $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
| 325 | 324 | |
| 326 | - spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 325 | + spip_log("JQ schedule $time / $end_time", 'jq'._LOG_DEBUG); |
|
| 327 | 326 | |
| 328 | 327 | if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
| 329 | 328 | define('_JQ_MAX_JOBS_EXECUTE', 200); |
@@ -337,19 +336,19 @@ discard block |
||
| 337 | 336 | // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
| 338 | 337 | // pour qu'il ne bloque pas les autres jobs en attente |
| 339 | 338 | if (is_array($force_jobs) and count($force_jobs)) { |
| 340 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs); |
|
| 339 | + $cond = 'status='.intval(_JQ_SCHEDULED).' AND '.sql_in('id_job', $force_jobs); |
|
| 341 | 340 | } else { |
| 342 | 341 | $now = date('Y-m-d H:i:s', $time); |
| 343 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now); |
|
| 342 | + $cond = 'status='.intval(_JQ_SCHEDULED).' AND date<='.sql_quote($now); |
|
| 344 | 343 | } |
| 345 | 344 | |
| 346 | 345 | register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
| 347 | - $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 346 | + $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,'.(_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 348 | 347 | do { |
| 349 | 348 | if ($row = array_shift($res)) { |
| 350 | 349 | $nbj++; |
| 351 | 350 | // il faut un verrou, a base de sql_delete |
| 352 | - if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) { |
|
| 351 | + if (sql_delete('spip_jobs', 'id_job='.intval($row['id_job']).' AND status='.intval(_JQ_SCHEDULED))) { |
|
| 353 | 352 | #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
| 354 | 353 | // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
| 355 | 354 | $row['status'] = _JQ_PENDING; |
@@ -364,13 +363,13 @@ discard block |
||
| 364 | 363 | queue_close_job($row, $time, $result); |
| 365 | 364 | } |
| 366 | 365 | } |
| 367 | - spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG); |
|
| 366 | + spip_log('JQ schedule job end time '.$time, 'jq'._LOG_DEBUG); |
|
| 368 | 367 | } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
| 369 | - spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG); |
|
| 368 | + spip_log('JQ schedule end time '.time(), 'jq'._LOG_DEBUG); |
|
| 370 | 369 | |
| 371 | 370 | if ($row = array_shift($res)) { |
| 372 | 371 | queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
| 373 | - spip_log('JQ encore !', 'jq' . _LOG_DEBUG); |
|
| 372 | + spip_log('JQ encore !', 'jq'._LOG_DEBUG); |
|
| 374 | 373 | } else { |
| 375 | 374 | queue_update_next_job_time(); |
| 376 | 375 | } |
@@ -405,9 +404,9 @@ discard block |
||
| 405 | 404 | } |
| 406 | 405 | } |
| 407 | 406 | // purger ses liens eventuels avec des objets |
| 408 | - sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job'])); |
|
| 407 | + sql_delete('spip_jobs_liens', 'id_job='.intval($row['id_job'])); |
|
| 409 | 408 | // supprimer le job fini |
| 410 | - sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 409 | + sql_delete('spip_jobs', 'id_job='.intval($row['id_job'])); |
|
| 411 | 410 | } |
| 412 | 411 | |
| 413 | 412 | /** |
@@ -480,18 +479,18 @@ discard block |
||
| 480 | 479 | $res = sql_allfetsel( |
| 481 | 480 | '*', |
| 482 | 481 | 'spip_jobs', |
| 483 | - 'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 482 | + 'status='.intval(_JQ_PENDING).' AND date<'.sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 484 | 483 | ); |
| 485 | 484 | if (is_array($res)) { |
| 486 | 485 | foreach ($res as $row) { |
| 487 | 486 | queue_close_job($row, $time); |
| 488 | - spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR); |
|
| 487 | + spip_log('queue_close_job car _JQ_PENDING depuis +180s : '.print_r($row, 1), 'job_mort'._LOG_ERREUR); |
|
| 489 | 488 | } |
| 490 | 489 | } |
| 491 | 490 | |
| 492 | 491 | // chercher la date du prochain job si pas connu |
| 493 | 492 | if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
| 494 | - $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 493 | + $date = sql_getfetsel('date', 'spip_jobs', 'status='.intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 495 | 494 | $next = strtotime($date); |
| 496 | 495 | } |
| 497 | 496 | if (!is_null($next_time)) { |
@@ -504,7 +503,7 @@ discard block |
||
| 504 | 503 | if (is_null($nb_jobs_scheduled)) { |
| 505 | 504 | $nb_jobs_scheduled = sql_countsel( |
| 506 | 505 | 'spip_jobs', |
| 507 | - 'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 506 | + 'status='.intval(_JQ_SCHEDULED).' AND date<'.sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 508 | 507 | ); |
| 509 | 508 | } elseif ($next <= $time) { |
| 510 | 509 | $nb_jobs_scheduled++; |
@@ -573,7 +572,7 @@ discard block |
||
| 573 | 572 | } |
| 574 | 573 | |
| 575 | 574 | // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
| 576 | - if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 575 | + if (file_exists($lock = _DIR_TMP.'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 577 | 576 | return $texte; |
| 578 | 577 | } |
| 579 | 578 | |
@@ -645,7 +644,7 @@ discard block |
||
| 645 | 644 | $port = 80; |
| 646 | 645 | } |
| 647 | 646 | $fp = @fsockopen( |
| 648 | - $scheme . $parts['host'], |
|
| 647 | + $scheme.$parts['host'], |
|
| 649 | 648 | $parts['port'] ?? $port, |
| 650 | 649 | $errno, |
| 651 | 650 | $errstr, |
@@ -655,13 +654,13 @@ discard block |
||
| 655 | 654 | if ($fp) { |
| 656 | 655 | $host_sent = $parts['host']; |
| 657 | 656 | if (isset($parts['port']) and $parts['port'] !== $port) { |
| 658 | - $host_sent .= ':' . $parts['port']; |
|
| 657 | + $host_sent .= ':'.$parts['port']; |
|
| 659 | 658 | } |
| 660 | 659 | $timeout = 200; // ms |
| 661 | 660 | stream_set_timeout($fp, 0, $timeout * 1000); |
| 662 | - $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : ''); |
|
| 663 | - $out = 'GET ' . $query . " HTTP/1.1\r\n"; |
|
| 664 | - $out .= 'Host: ' . $host_sent . "\r\n"; |
|
| 661 | + $query = $parts['path'].($parts['query'] ? '?'.$parts['query'] : ''); |
|
| 662 | + $out = 'GET '.$query." HTTP/1.1\r\n"; |
|
| 663 | + $out .= 'Host: '.$host_sent."\r\n"; |
|
| 665 | 664 | $out .= "Connection: Close\r\n\r\n"; |
| 666 | 665 | fwrite($fp, $out); |
| 667 | 666 | spip_timer('read'); |
@@ -39,8 +39,7 @@ |
||
| 39 | 39 | } else { |
| 40 | 40 | $tls = true; |
| 41 | 41 | } |
| 42 | - } |
|
| 43 | - else { |
|
| 42 | + } else { |
|
| 44 | 43 | $tls_ldap == 'non'; |
| 45 | 44 | } |
| 46 | 45 | |
@@ -11,89 +11,89 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function install_etape_ldap2_dist() { |
| 18 | - echo install_debut_html('AUTO', ' 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 = intval($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 === true) { |
|
| 59 | - if (!ldap_start_tls($ldap_link)) { |
|
| 60 | - $erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link) |
|
| 61 | - . ' ' . spip_htmlspecialchars($adresse_ldap) |
|
| 62 | - . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 63 | - $ldap_link = false; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - if ($ldap_link) { |
|
| 67 | - $ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 68 | - $erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link) |
|
| 69 | - . "', '" . spip_htmlspecialchars($login_ldap) |
|
| 70 | - . "', '" . spip_htmlspecialchars($pass_ldap) |
|
| 71 | - . "'): " . spip_htmlspecialchars($adresse_ldap) |
|
| 72 | - . ', ' . spip_htmlspecialchars($port_ldap); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if ($ldap_link) { |
|
| 77 | - echo info_etape( |
|
| 78 | - _T('titre_connexion_ldap'), |
|
| 79 | - info_progression_etape(2, 'etape_ldap', 'install/') |
|
| 80 | - ), _T('info_connexion_ldap_ok'); |
|
| 81 | - echo generer_form_ecrire('install', ( |
|
| 82 | - "\n<input type='hidden' name='etape' value='ldap3' />" |
|
| 83 | - . "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />' |
|
| 84 | - . "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />' |
|
| 85 | - . "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />' |
|
| 86 | - . "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />' |
|
| 87 | - . "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />' |
|
| 88 | - . "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />' |
|
| 89 | - . bouton_suivant())); |
|
| 90 | - } else { |
|
| 91 | - echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true), |
|
| 92 | - "<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>', |
|
| 93 | - '<p>' . _T('avis_connexion_ldap_echec_2') . |
|
| 94 | - "<br />\n" . _T('avis_connexion_ldap_echec_3') . |
|
| 95 | - '<br /><br />' . $erreur . '<b> ?</b></p></div>'; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - echo install_fin_html(); |
|
| 18 | + echo install_debut_html('AUTO', ' 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 = intval($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 === true) { |
|
| 59 | + if (!ldap_start_tls($ldap_link)) { |
|
| 60 | + $erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link) |
|
| 61 | + . ' ' . spip_htmlspecialchars($adresse_ldap) |
|
| 62 | + . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 63 | + $ldap_link = false; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + if ($ldap_link) { |
|
| 67 | + $ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 68 | + $erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link) |
|
| 69 | + . "', '" . spip_htmlspecialchars($login_ldap) |
|
| 70 | + . "', '" . spip_htmlspecialchars($pass_ldap) |
|
| 71 | + . "'): " . spip_htmlspecialchars($adresse_ldap) |
|
| 72 | + . ', ' . spip_htmlspecialchars($port_ldap); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if ($ldap_link) { |
|
| 77 | + echo info_etape( |
|
| 78 | + _T('titre_connexion_ldap'), |
|
| 79 | + info_progression_etape(2, 'etape_ldap', 'install/') |
|
| 80 | + ), _T('info_connexion_ldap_ok'); |
|
| 81 | + echo generer_form_ecrire('install', ( |
|
| 82 | + "\n<input type='hidden' name='etape' value='ldap3' />" |
|
| 83 | + . "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />' |
|
| 84 | + . "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />' |
|
| 85 | + . "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />' |
|
| 86 | + . "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />' |
|
| 87 | + . "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />' |
|
| 88 | + . "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />' |
|
| 89 | + . bouton_suivant())); |
|
| 90 | + } else { |
|
| 91 | + echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true), |
|
| 92 | + "<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>', |
|
| 93 | + '<p>' . _T('avis_connexion_ldap_echec_2') . |
|
| 94 | + "<br />\n" . _T('avis_connexion_ldap_echec_3') . |
|
| 95 | + '<br /><br />' . $erreur . '<b> ?</b></p></div>'; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + echo install_fin_html(); |
|
| 99 | 99 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: ''; |
| 49 | 49 | |
| 50 | 50 | $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
| 51 | - $erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 51 | + $erreur = 'ldap_connect('.spip_htmlspecialchars($adresse_ldap).', '.spip_htmlspecialchars($port_ldap).')'; |
|
| 52 | 52 | |
| 53 | 53 | if ($ldap_link) { |
| 54 | 54 | if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) { |
@@ -57,19 +57,19 @@ discard block |
||
| 57 | 57 | } |
| 58 | 58 | if ($tls === true) { |
| 59 | 59 | if (!ldap_start_tls($ldap_link)) { |
| 60 | - $erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link) |
|
| 61 | - . ' ' . spip_htmlspecialchars($adresse_ldap) |
|
| 62 | - . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 60 | + $erreur = 'ldap_start_tls('.spip_htmlspecialchars($ldap_link) |
|
| 61 | + . ' '.spip_htmlspecialchars($adresse_ldap) |
|
| 62 | + . ', '.spip_htmlspecialchars($port_ldap).')'; |
|
| 63 | 63 | $ldap_link = false; |
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | if ($ldap_link) { |
| 67 | 67 | $ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
| 68 | - $erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link) |
|
| 69 | - . "', '" . spip_htmlspecialchars($login_ldap) |
|
| 70 | - . "', '" . spip_htmlspecialchars($pass_ldap) |
|
| 71 | - . "'): " . spip_htmlspecialchars($adresse_ldap) |
|
| 72 | - . ', ' . spip_htmlspecialchars($port_ldap); |
|
| 68 | + $erreur = "ldap_bind('".spip_htmlspecialchars($ldap_link) |
|
| 69 | + . "', '".spip_htmlspecialchars($login_ldap) |
|
| 70 | + . "', '".spip_htmlspecialchars($pass_ldap) |
|
| 71 | + . "'): ".spip_htmlspecialchars($adresse_ldap) |
|
| 72 | + . ', '.spip_htmlspecialchars($port_ldap); |
|
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
@@ -77,22 +77,22 @@ discard block |
||
| 77 | 77 | echo info_etape( |
| 78 | 78 | _T('titre_connexion_ldap'), |
| 79 | 79 | info_progression_etape(2, 'etape_ldap', 'install/') |
| 80 | - ), _T('info_connexion_ldap_ok'); |
|
| 80 | + ), _T('info_connexion_ldap_ok'); |
|
| 81 | 81 | echo generer_form_ecrire('install', ( |
| 82 | 82 | "\n<input type='hidden' name='etape' value='ldap3' />" |
| 83 | - . "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />' |
|
| 84 | - . "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />' |
|
| 85 | - . "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />' |
|
| 86 | - . "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />' |
|
| 87 | - . "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />' |
|
| 88 | - . "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />' |
|
| 83 | + . "\n<input type='hidden' name='adresse_ldap' value=\"".spip_htmlspecialchars($adresse_ldap).'" />' |
|
| 84 | + . "\n<input type='hidden' name='port_ldap' value=\"".spip_htmlspecialchars($port_ldap).'" />' |
|
| 85 | + . "\n<input type='hidden' name='login_ldap' value=\"".spip_htmlspecialchars($login_ldap).'" />' |
|
| 86 | + . "\n<input type='hidden' name='pass_ldap' value=\"".spip_htmlspecialchars($pass_ldap).'" />' |
|
| 87 | + . "\n<input type='hidden' name='protocole_ldap' value=\"".spip_htmlspecialchars($protocole_ldap).'" />' |
|
| 88 | + . "\n<input type='hidden' name='tls_ldap' value=\"".spip_htmlspecialchars($tls_ldap).'" />' |
|
| 89 | 89 | . bouton_suivant())); |
| 90 | 90 | } else { |
| 91 | 91 | echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true), |
| 92 | - "<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>', |
|
| 93 | - '<p>' . _T('avis_connexion_ldap_echec_2') . |
|
| 94 | - "<br />\n" . _T('avis_connexion_ldap_echec_3') . |
|
| 95 | - '<br /><br />' . $erreur . '<b> ?</b></p></div>'; |
|
| 92 | + "<div class='error'><p>"._T('avis_connexion_ldap_echec_1').'</p>', |
|
| 93 | + '<p>'._T('avis_connexion_ldap_echec_2'). |
|
| 94 | + "<br />\n"._T('avis_connexion_ldap_echec_3'). |
|
| 95 | + '<br /><br />'.$erreur.'<b> ?</b></p></div>'; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | echo install_fin_html(); |
@@ -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 | |
@@ -52,68 +52,68 @@ discard block |
||
| 52 | 52 | * cookie sécurisé ou non ? |
| 53 | 53 | **/ |
| 54 | 54 | function spip_setcookie($name = '', $value = '', $options = []) { |
| 55 | - static $to_secure_list = ['spip_session']; |
|
| 56 | - if (defined('_COOKIE_SECURE_LIST') and is_array(_COOKIE_SECURE_LIST)) { |
|
| 57 | - $to_secure_list = array_merge($to_secure_list, _COOKIE_SECURE_LIST); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if (!is_array($options)) { |
|
| 61 | - // anciens paramètres : |
|
| 62 | - # spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 63 | - $opt = func_get_args(); |
|
| 64 | - $opt = array_slice($opt, 2); |
|
| 65 | - $options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !); |
|
| 66 | - if (isset($opt[0])) { |
|
| 67 | - $options['expires'] = $opt[0]; |
|
| 68 | - } |
|
| 69 | - if (isset($opt[1])) { |
|
| 70 | - $options['path'] = $opt[1]; |
|
| 71 | - } |
|
| 72 | - if (isset($opt[2])) { |
|
| 73 | - $options['domain'] = $opt[2]; |
|
| 74 | - } |
|
| 75 | - if (isset($opt[3])) { |
|
| 76 | - $options['secure'] = $opt[3]; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // expires |
|
| 81 | - if (!isset($options['expires'])) { |
|
| 82 | - $options['expires'] = 0; |
|
| 83 | - } |
|
| 84 | - if (!isset($options['path']) or $options['path'] === 'AUTO') { |
|
| 85 | - if (defined('_COOKIE_PATH')) { |
|
| 86 | - $options['path'] = _COOKIE_PATH; |
|
| 87 | - } else { |
|
| 88 | - $options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) { |
|
| 92 | - $options['domain'] = _COOKIE_DOMAIN; |
|
| 93 | - } |
|
| 94 | - if (in_array($name, $to_secure_list)) { |
|
| 95 | - if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) { |
|
| 96 | - $options['secure'] = true; |
|
| 97 | - } |
|
| 98 | - if (empty($options['httponly'])) { |
|
| 99 | - $options['httponly'] = true; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - if (empty($options['samesite'])) { |
|
| 103 | - $options['samesite'] = 'Lax'; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // in fine renommer le prefixe si besoin |
|
| 107 | - if (strpos($name, 'spip_') === 0) { |
|
| 108 | - $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
|
| 112 | - $a = @setcookie($name, $value, $options); |
|
| 113 | - |
|
| 114 | - spip_cookie_envoye(true); |
|
| 115 | - |
|
| 116 | - return $a; |
|
| 55 | + static $to_secure_list = ['spip_session']; |
|
| 56 | + if (defined('_COOKIE_SECURE_LIST') and is_array(_COOKIE_SECURE_LIST)) { |
|
| 57 | + $to_secure_list = array_merge($to_secure_list, _COOKIE_SECURE_LIST); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if (!is_array($options)) { |
|
| 61 | + // anciens paramètres : |
|
| 62 | + # spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 63 | + $opt = func_get_args(); |
|
| 64 | + $opt = array_slice($opt, 2); |
|
| 65 | + $options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !); |
|
| 66 | + if (isset($opt[0])) { |
|
| 67 | + $options['expires'] = $opt[0]; |
|
| 68 | + } |
|
| 69 | + if (isset($opt[1])) { |
|
| 70 | + $options['path'] = $opt[1]; |
|
| 71 | + } |
|
| 72 | + if (isset($opt[2])) { |
|
| 73 | + $options['domain'] = $opt[2]; |
|
| 74 | + } |
|
| 75 | + if (isset($opt[3])) { |
|
| 76 | + $options['secure'] = $opt[3]; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // expires |
|
| 81 | + if (!isset($options['expires'])) { |
|
| 82 | + $options['expires'] = 0; |
|
| 83 | + } |
|
| 84 | + if (!isset($options['path']) or $options['path'] === 'AUTO') { |
|
| 85 | + if (defined('_COOKIE_PATH')) { |
|
| 86 | + $options['path'] = _COOKIE_PATH; |
|
| 87 | + } else { |
|
| 88 | + $options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) { |
|
| 92 | + $options['domain'] = _COOKIE_DOMAIN; |
|
| 93 | + } |
|
| 94 | + if (in_array($name, $to_secure_list)) { |
|
| 95 | + if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) { |
|
| 96 | + $options['secure'] = true; |
|
| 97 | + } |
|
| 98 | + if (empty($options['httponly'])) { |
|
| 99 | + $options['httponly'] = true; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + if (empty($options['samesite'])) { |
|
| 103 | + $options['samesite'] = 'Lax'; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // in fine renommer le prefixe si besoin |
|
| 107 | + if (strpos($name, 'spip_') === 0) { |
|
| 108 | + $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
|
| 112 | + $a = @setcookie($name, $value, $options); |
|
| 113 | + |
|
| 114 | + spip_cookie_envoye(true); |
|
| 115 | + |
|
| 116 | + return $a; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | * @return bool |
| 130 | 130 | **/ |
| 131 | 131 | function spip_cookie_envoye($set = '') { |
| 132 | - static $envoye = false; |
|
| 133 | - if ($set) { |
|
| 134 | - $envoye = true; |
|
| 135 | - } |
|
| 132 | + static $envoye = false; |
|
| 133 | + if ($set) { |
|
| 134 | + $envoye = true; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - return $envoye; |
|
| 137 | + return $envoye; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -153,21 +153,21 @@ discard block |
||
| 153 | 153 | * Préfixe des cookies de SPIP |
| 154 | 154 | **/ |
| 155 | 155 | function recuperer_cookies_spip($cookie_prefix) { |
| 156 | - $prefix_long = strlen($cookie_prefix); |
|
| 157 | - |
|
| 158 | - foreach ($_COOKIE as $name => $value) { |
|
| 159 | - if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 160 | - unset($_COOKIE[$name]); |
|
| 161 | - unset($GLOBALS[$name]); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - foreach ($_COOKIE as $name => $value) { |
|
| 165 | - if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 166 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 167 | - $_COOKIE[$spipname] = $value; |
|
| 168 | - $GLOBALS[$spipname] = $value; |
|
| 169 | - } |
|
| 170 | - } |
|
| 156 | + $prefix_long = strlen($cookie_prefix); |
|
| 157 | + |
|
| 158 | + foreach ($_COOKIE as $name => $value) { |
|
| 159 | + if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 160 | + unset($_COOKIE[$name]); |
|
| 161 | + unset($GLOBALS[$name]); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + foreach ($_COOKIE as $name => $value) { |
|
| 165 | + if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 166 | + $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 167 | + $_COOKIE[$spipname] = $value; |
|
| 168 | + $GLOBALS[$spipname] = $value; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -186,18 +186,18 @@ discard block |
||
| 186 | 186 | * |
| 187 | 187 | **/ |
| 188 | 188 | function exec_test_ajax_dist() { |
| 189 | - switch (_request('js')) { |
|
| 190 | - // on est appele par <noscript> |
|
| 191 | - case -1: |
|
| 192 | - spip_setcookie('spip_accepte_ajax', -1); |
|
| 193 | - include_spip('inc/headers'); |
|
| 194 | - redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 195 | - break; |
|
| 196 | - |
|
| 197 | - // ou par ajax |
|
| 198 | - case 1: |
|
| 199 | - default: |
|
| 200 | - spip_setcookie('spip_accepte_ajax', 1); |
|
| 201 | - break; |
|
| 202 | - } |
|
| 189 | + switch (_request('js')) { |
|
| 190 | + // on est appele par <noscript> |
|
| 191 | + case -1: |
|
| 192 | + spip_setcookie('spip_accepte_ajax', -1); |
|
| 193 | + include_spip('inc/headers'); |
|
| 194 | + redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 195 | + break; |
|
| 196 | + |
|
| 197 | + // ou par ajax |
|
| 198 | + case 1: |
|
| 199 | + default: |
|
| 200 | + spip_setcookie('spip_accepte_ajax', 1); |
|
| 201 | + break; |
|
| 202 | + } |
|
| 203 | 203 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | // in fine renommer le prefixe si besoin |
| 107 | 107 | if (strpos($name, 'spip_') === 0) { |
| 108 | - $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 108 | + $name = $GLOBALS['cookie_prefix'].'_'.substr($name, 5); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | foreach ($_COOKIE as $name => $value) { |
| 165 | 165 | if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
| 166 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 166 | + $spipname = preg_replace('/^'.$cookie_prefix.'_/', 'spip_', $name); |
|
| 167 | 167 | $_COOKIE[$spipname] = $value; |
| 168 | 168 | $GLOBALS[$spipname] = $value; |
| 169 | 169 | } |