@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -28,51 +28,51 @@ discard block |
||
| 28 | 28 | * @return string Erreur éventuelle |
| 29 | 29 | */ |
| 30 | 30 | function inc_completer_traduction_dist($objet, $id_objet, $id_trad) { |
| 31 | - // dupliquer tous les liens sauf les auteurs : le nouvel auteur est celui qui traduit |
|
| 32 | - // cf API editer_liens |
|
| 33 | - include_spip('action/editer_liens'); |
|
| 34 | - objet_dupliquer_liens($objet, $id_trad, $id_objet, null, ['auteur']); |
|
| 35 | - $_id_table = id_table_objet($objet); |
|
| 31 | + // dupliquer tous les liens sauf les auteurs : le nouvel auteur est celui qui traduit |
|
| 32 | + // cf API editer_liens |
|
| 33 | + include_spip('action/editer_liens'); |
|
| 34 | + objet_dupliquer_liens($objet, $id_trad, $id_objet, null, ['auteur']); |
|
| 35 | + $_id_table = id_table_objet($objet); |
|
| 36 | 36 | |
| 37 | - // recuperer le logo |
|
| 38 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 39 | - include_spip('action/editer_logo'); |
|
| 40 | - foreach (['on', 'off'] as $etat) { |
|
| 41 | - $logo = $chercher_logo($id_trad, $_id_table, $etat); |
|
| 42 | - if ($logo && ($file = reset($logo))) { |
|
| 43 | - logo_modifier($objet, $id_objet, $etat, $file); |
|
| 44 | - } |
|
| 45 | - } |
|
| 37 | + // recuperer le logo |
|
| 38 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 39 | + include_spip('action/editer_logo'); |
|
| 40 | + foreach (['on', 'off'] as $etat) { |
|
| 41 | + $logo = $chercher_logo($id_trad, $_id_table, $etat); |
|
| 42 | + if ($logo && ($file = reset($logo))) { |
|
| 43 | + logo_modifier($objet, $id_objet, $etat, $file); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - // dupliquer certains champs |
|
| 48 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 49 | - $desc = $trouver_table(table_objet_sql($objet)); |
|
| 50 | - $champs = $set = []; |
|
| 47 | + // dupliquer certains champs |
|
| 48 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 49 | + $desc = $trouver_table(table_objet_sql($objet)); |
|
| 50 | + $champs = $set = []; |
|
| 51 | 51 | |
| 52 | - // un éventuel champ 'virtuel' (redirections) |
|
| 53 | - if (!empty($desc['field']['virtuel'])) { |
|
| 54 | - $champs[] = 'virtuel'; |
|
| 55 | - } |
|
| 52 | + // un éventuel champ 'virtuel' (redirections) |
|
| 53 | + if (!empty($desc['field']['virtuel'])) { |
|
| 54 | + $champs[] = 'virtuel'; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $data = sql_fetsel('*', $desc['table'], $_id_table . '=' . (int) $id_trad); |
|
| 57 | + $data = sql_fetsel('*', $desc['table'], $_id_table . '=' . (int) $id_trad); |
|
| 58 | 58 | |
| 59 | - foreach ($champs as $c) { |
|
| 60 | - $set[$c] = $data[$c]; |
|
| 61 | - } |
|
| 59 | + foreach ($champs as $c) { |
|
| 60 | + $set[$c] = $data[$c]; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /* |
|
| 63 | + /* |
|
| 64 | 64 | * Le pipeline 'pre_edition' sera appelé avec l'action 'completer_traduction'. |
| 65 | 65 | * Des plugins pourront ainsi compléter les champs d'un objet traduit lors d'une nouvelle traduction. |
| 66 | 66 | */ |
| 67 | - $err = objet_modifier_champs( |
|
| 68 | - $objet, |
|
| 69 | - $id_objet, |
|
| 70 | - [ |
|
| 71 | - 'data' => $data, |
|
| 72 | - 'action' => 'completer_traduction', |
|
| 73 | - ], |
|
| 74 | - $set |
|
| 75 | - ); |
|
| 67 | + $err = objet_modifier_champs( |
|
| 68 | + $objet, |
|
| 69 | + $id_objet, |
|
| 70 | + [ |
|
| 71 | + 'data' => $data, |
|
| 72 | + 'action' => 'completer_traduction', |
|
| 73 | + ], |
|
| 74 | + $set |
|
| 75 | + ); |
|
| 76 | 76 | |
| 77 | - return $err; |
|
| 77 | + return $err; |
|
| 78 | 78 | } |
@@ -10,101 +10,101 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function inc_log_dist($message, $logname = null, $logdir = null, $logsuf = null) { |
| 17 | - static $test_repertoire = []; |
|
| 18 | - static $compteur = []; |
|
| 19 | - static $debugverb = ''; // pour ne pas le recalculer au reappel |
|
| 20 | - |
|
| 21 | - if (is_null($logname) || !is_string($logname)) { |
|
| 22 | - $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; |
|
| 23 | - } |
|
| 24 | - if (!isset($compteur[$logname])) { |
|
| 25 | - $compteur[$logname] = 0; |
|
| 26 | - } |
|
| 27 | - if ( |
|
| 28 | - $logname != 'maj' |
|
| 29 | - && defined('_MAX_LOG') |
|
| 30 | - && ($compteur[$logname]++ > _MAX_LOG || !$GLOBALS['nombre_de_logs'] || !$GLOBALS['taille_des_logs']) |
|
| 31 | - ) { |
|
| 32 | - return; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
|
| 36 | - $logfile = |
|
| 37 | - ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 38 | - . $logname |
|
| 39 | - . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
|
| 40 | - |
|
| 41 | - if (!isset($test_repertoire[$d = dirname($logfile)])) { |
|
| 42 | - $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire |
|
| 43 | - $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire( |
|
| 44 | - $d, |
|
| 45 | - '', |
|
| 46 | - false, |
|
| 47 | - true |
|
| 48 | - ) : false)); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - // Si le repertoire défini n'existe pas, poser dans tmp/ |
|
| 52 | - if (!$test_repertoire[$d]) { |
|
| 53 | - $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $rotate = 0; |
|
| 57 | - $pid = '(pid ' . @getmypid() . ')'; |
|
| 58 | - |
|
| 59 | - // accepter spip_log( Array ) |
|
| 60 | - if (!is_string($message)) { |
|
| 61 | - $message = var_export($message, true); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - if (!$debugverb && defined('_LOG_FILELINE') && _LOG_FILELINE) { |
|
| 65 | - $debug = debug_backtrace(); |
|
| 66 | - $l = $debug[1]['line']; |
|
| 67 | - $fi = $debug[1]['file']; |
|
| 68 | - if (str_starts_with($fi, _ROOT_RACINE)) { |
|
| 69 | - $fi = substr($fi, strlen(_ROOT_RACINE)); |
|
| 70 | - } |
|
| 71 | - $fu = $debug[2]['function'] ?? ''; |
|
| 72 | - $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 76 | - //distinguer les logs prives et publics dans les grep |
|
| 77 | - . $debugverb |
|
| 78 | - . (test_espace_prive() ? ':Pri:' : ':Pub:') |
|
| 79 | - . preg_replace("/\n*$/", "\n", $message); |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - if ( |
|
| 83 | - @is_readable($logfile) |
|
| 84 | - && ((!$s = @filesize($logfile)) || $s > $GLOBALS['taille_des_logs'] * 1024) |
|
| 85 | - ) { |
|
| 86 | - $rotate = $GLOBALS['nombre_de_logs']; |
|
| 87 | - $m .= "[-- rotate --]\n"; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $f = @fopen($logfile, 'ab'); |
|
| 91 | - if ($f) { |
|
| 92 | - fwrite($f, (defined('_LOG_BRUT') && _LOG_BRUT) ? $m : str_replace('<', '<', $m)); |
|
| 93 | - fclose($f); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if ( |
|
| 97 | - $rotate-- > 0 && function_exists('spip_unlink') |
|
| 98 | - ) { |
|
| 99 | - spip_unlink($logfile . '.' . $rotate); |
|
| 100 | - while ($rotate--) { |
|
| 101 | - @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // Dupliquer les erreurs specifiques dans le log general |
|
| 106 | - if (defined('_FILE_LOG') && $logname !== _FILE_LOG) { |
|
| 107 | - inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message); |
|
| 108 | - } |
|
| 109 | - $debugverb = ''; |
|
| 17 | + static $test_repertoire = []; |
|
| 18 | + static $compteur = []; |
|
| 19 | + static $debugverb = ''; // pour ne pas le recalculer au reappel |
|
| 20 | + |
|
| 21 | + if (is_null($logname) || !is_string($logname)) { |
|
| 22 | + $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; |
|
| 23 | + } |
|
| 24 | + if (!isset($compteur[$logname])) { |
|
| 25 | + $compteur[$logname] = 0; |
|
| 26 | + } |
|
| 27 | + if ( |
|
| 28 | + $logname != 'maj' |
|
| 29 | + && defined('_MAX_LOG') |
|
| 30 | + && ($compteur[$logname]++ > _MAX_LOG || !$GLOBALS['nombre_de_logs'] || !$GLOBALS['taille_des_logs']) |
|
| 31 | + ) { |
|
| 32 | + return; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
|
| 36 | + $logfile = |
|
| 37 | + ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 38 | + . $logname |
|
| 39 | + . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
|
| 40 | + |
|
| 41 | + if (!isset($test_repertoire[$d = dirname($logfile)])) { |
|
| 42 | + $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire |
|
| 43 | + $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire( |
|
| 44 | + $d, |
|
| 45 | + '', |
|
| 46 | + false, |
|
| 47 | + true |
|
| 48 | + ) : false)); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + // Si le repertoire défini n'existe pas, poser dans tmp/ |
|
| 52 | + if (!$test_repertoire[$d]) { |
|
| 53 | + $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $rotate = 0; |
|
| 57 | + $pid = '(pid ' . @getmypid() . ')'; |
|
| 58 | + |
|
| 59 | + // accepter spip_log( Array ) |
|
| 60 | + if (!is_string($message)) { |
|
| 61 | + $message = var_export($message, true); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + if (!$debugverb && defined('_LOG_FILELINE') && _LOG_FILELINE) { |
|
| 65 | + $debug = debug_backtrace(); |
|
| 66 | + $l = $debug[1]['line']; |
|
| 67 | + $fi = $debug[1]['file']; |
|
| 68 | + if (str_starts_with($fi, _ROOT_RACINE)) { |
|
| 69 | + $fi = substr($fi, strlen(_ROOT_RACINE)); |
|
| 70 | + } |
|
| 71 | + $fu = $debug[2]['function'] ?? ''; |
|
| 72 | + $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 76 | + //distinguer les logs prives et publics dans les grep |
|
| 77 | + . $debugverb |
|
| 78 | + . (test_espace_prive() ? ':Pri:' : ':Pub:') |
|
| 79 | + . preg_replace("/\n*$/", "\n", $message); |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + if ( |
|
| 83 | + @is_readable($logfile) |
|
| 84 | + && ((!$s = @filesize($logfile)) || $s > $GLOBALS['taille_des_logs'] * 1024) |
|
| 85 | + ) { |
|
| 86 | + $rotate = $GLOBALS['nombre_de_logs']; |
|
| 87 | + $m .= "[-- rotate --]\n"; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $f = @fopen($logfile, 'ab'); |
|
| 91 | + if ($f) { |
|
| 92 | + fwrite($f, (defined('_LOG_BRUT') && _LOG_BRUT) ? $m : str_replace('<', '<', $m)); |
|
| 93 | + fclose($f); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if ( |
|
| 97 | + $rotate-- > 0 && function_exists('spip_unlink') |
|
| 98 | + ) { |
|
| 99 | + spip_unlink($logfile . '.' . $rotate); |
|
| 100 | + while ($rotate--) { |
|
| 101 | + @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // Dupliquer les erreurs specifiques dans le log general |
|
| 106 | + if (defined('_FILE_LOG') && $logname !== _FILE_LOG) { |
|
| 107 | + inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message); |
|
| 108 | + } |
|
| 109 | + $debugverb = ''; |
|
| 110 | 110 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -42,25 +42,25 @@ discard block |
||
| 42 | 42 | * @return string Code HTML |
| 43 | 43 | **/ |
| 44 | 44 | function inc_commencer_page_dist( |
| 45 | - $titre = '', |
|
| 46 | - $rubrique = 'accueil', |
|
| 47 | - $sous_rubrique = 'accueil', |
|
| 48 | - $id_rubrique = '', |
|
| 49 | - $menu = true, |
|
| 50 | - $minipres = false, |
|
| 51 | - $alertes = true |
|
| 45 | + $titre = '', |
|
| 46 | + $rubrique = 'accueil', |
|
| 47 | + $sous_rubrique = 'accueil', |
|
| 48 | + $id_rubrique = '', |
|
| 49 | + $menu = true, |
|
| 50 | + $minipres = false, |
|
| 51 | + $alertes = true |
|
| 52 | 52 | ) { |
| 53 | 53 | |
| 54 | - include_spip('inc/headers'); |
|
| 54 | + include_spip('inc/headers'); |
|
| 55 | 55 | |
| 56 | - http_no_cache(); |
|
| 56 | + http_no_cache(); |
|
| 57 | 57 | |
| 58 | - return init_entete($titre, $id_rubrique, $minipres) |
|
| 59 | - . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 60 | - . "<div id='page'>" |
|
| 61 | - . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 62 | - . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 63 | - . '<div class="largeur">'; |
|
| 58 | + return init_entete($titre, $id_rubrique, $minipres) |
|
| 59 | + . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 60 | + . "<div id='page'>" |
|
| 61 | + . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 62 | + . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 63 | + . '<div class="largeur">'; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -81,21 +81,21 @@ discard block |
||
| 81 | 81 | * Entête du fichier HTML avec le DOCTYPE |
| 82 | 82 | */ |
| 83 | 83 | function init_entete($titre = '', $dummy = 0, $minipres = false) { |
| 84 | - include_spip('inc/texte'); |
|
| 85 | - if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 86 | - $nom_site_spip = _T('info_mon_site_spip'); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $titre = '[' |
|
| 90 | - . $nom_site_spip |
|
| 91 | - . ']' |
|
| 92 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 93 | - |
|
| 94 | - return _DOCTYPE_ECRIRE |
|
| 95 | - . html_lang_attributes() |
|
| 96 | - . "<head>\n" |
|
| 97 | - . init_head($titre, $dummy, $minipres) |
|
| 98 | - . "</head>\n"; |
|
| 84 | + include_spip('inc/texte'); |
|
| 85 | + if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 86 | + $nom_site_spip = _T('info_mon_site_spip'); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $titre = '[' |
|
| 90 | + . $nom_site_spip |
|
| 91 | + . ']' |
|
| 92 | + . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 93 | + |
|
| 94 | + return _DOCTYPE_ECRIRE |
|
| 95 | + . html_lang_attributes() |
|
| 96 | + . "<head>\n" |
|
| 97 | + . init_head($titre, $dummy, $minipres) |
|
| 98 | + . "</head>\n"; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @return string |
| 110 | 110 | */ |
| 111 | 111 | function init_head($titre = '', $dummy = 0, $minipres = false) { |
| 112 | - return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 112 | + return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -131,20 +131,20 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 133 | 133 | |
| 134 | - $res = pipeline('body_prive', "<body class='" |
|
| 135 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 136 | - . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 137 | - . '>'); |
|
| 134 | + $res = pipeline('body_prive', "<body class='" |
|
| 135 | + . init_body_class() . ' ' . _request('exec') . "'" |
|
| 136 | + . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 137 | + . '>'); |
|
| 138 | 138 | |
| 139 | - if (!$menu) { |
|
| 140 | - return $res; |
|
| 141 | - } |
|
| 139 | + if (!$menu) { |
|
| 140 | + return $res; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | |
| 144 | - $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 144 | + $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 145 | 145 | |
| 146 | - return $res |
|
| 147 | - . $bandeau(); |
|
| 146 | + return $res |
|
| 147 | + . $bandeau(); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -156,23 +156,23 @@ discard block |
||
| 156 | 156 | * @return string Classes CSS (séparées par des espaces) |
| 157 | 157 | */ |
| 158 | 158 | function init_body_class() { |
| 159 | - $display_modes = [ |
|
| 160 | - 0 => 'icones_img_texte' // défaut. |
|
| 161 | - /*init*/, |
|
| 162 | - 1 => 'icones_texte', |
|
| 163 | - 2 => 'icones_img_texte', |
|
| 164 | - 3 => 'icones_img' |
|
| 165 | - ]; |
|
| 159 | + $display_modes = [ |
|
| 160 | + 0 => 'icones_img_texte' // défaut. |
|
| 161 | + /*init*/, |
|
| 162 | + 1 => 'icones_texte', |
|
| 163 | + 2 => 'icones_img_texte', |
|
| 164 | + 3 => 'icones_img' |
|
| 165 | + ]; |
|
| 166 | 166 | |
| 167 | - $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 167 | + $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 168 | 168 | |
| 169 | - $display_mode = $display_modes[(int) ($prefs['display'] ?? 0)] ?? $display_modes[0]; |
|
| 170 | - $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 169 | + $display_mode = $display_modes[(int) ($prefs['display'] ?? 0)] ?? $display_modes[0]; |
|
| 170 | + $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 171 | 171 | |
| 172 | - $couleur = (int) ($prefs['couleur'] ?? 2); |
|
| 172 | + $couleur = (int) ($prefs['couleur'] ?? 2); |
|
| 173 | 173 | |
| 174 | - $classes = "spip-theme-colors-$couleur $spip_display_navigation $display_mode"; |
|
| 175 | - return spip_sanitize_classname($classes); |
|
| 174 | + $classes = "spip-theme-colors-$couleur $spip_display_navigation $display_mode"; |
|
| 175 | + return spip_sanitize_classname($classes); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -183,5 +183,5 @@ discard block |
||
| 183 | 183 | * @return string |
| 184 | 184 | */ |
| 185 | 185 | function auteurs_recemment_connectes($id_auteur) { |
| 186 | - return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 186 | + return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 187 | 187 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Fichier |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /** |
@@ -35,28 +35,28 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function spip_livrer_fichier($fichier, $content_type = 'application/octet-stream', $options = []) { |
| 37 | 37 | |
| 38 | - $defaut = [ |
|
| 39 | - 'attachment' => false, |
|
| 40 | - 'expires' => 3600, |
|
| 41 | - 'range' => null, |
|
| 42 | - ]; |
|
| 43 | - $options = array_merge($defaut, $options); |
|
| 44 | - if (is_numeric($options['expires']) && $options['expires'] > 0) { |
|
| 45 | - $options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']) . ' GMT'; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - if (is_null($options) && isset($_SERVER['HTTP_RANGE'])) { |
|
| 49 | - $options['range'] = $_SERVER['HTTP_RANGE']; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - spip_livrer_fichier_entetes($fichier, $content_type, ($options['attachment'] && !$options['range']) ? $options['attachment'] : false, $options['expires']); |
|
| 53 | - |
|
| 54 | - if (!is_null($options['range'])) { |
|
| 55 | - spip_livrer_fichier_partie($fichier, $options['range']); |
|
| 56 | - } |
|
| 57 | - else { |
|
| 58 | - spip_livrer_fichier_entier($fichier); |
|
| 59 | - } |
|
| 38 | + $defaut = [ |
|
| 39 | + 'attachment' => false, |
|
| 40 | + 'expires' => 3600, |
|
| 41 | + 'range' => null, |
|
| 42 | + ]; |
|
| 43 | + $options = array_merge($defaut, $options); |
|
| 44 | + if (is_numeric($options['expires']) && $options['expires'] > 0) { |
|
| 45 | + $options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']) . ' GMT'; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + if (is_null($options) && isset($_SERVER['HTTP_RANGE'])) { |
|
| 49 | + $options['range'] = $_SERVER['HTTP_RANGE']; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + spip_livrer_fichier_entetes($fichier, $content_type, ($options['attachment'] && !$options['range']) ? $options['attachment'] : false, $options['expires']); |
|
| 53 | + |
|
| 54 | + if (!is_null($options['range'])) { |
|
| 55 | + spip_livrer_fichier_partie($fichier, $options['range']); |
|
| 56 | + } |
|
| 57 | + else { |
|
| 58 | + spip_livrer_fichier_entier($fichier); |
|
| 59 | + } |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -69,33 +69,33 @@ discard block |
||
| 69 | 69 | * @param int|string $expires |
| 70 | 70 | */ |
| 71 | 71 | function spip_livrer_fichier_entetes($fichier, $content_type = 'application/octet-stream', $attachment = false, $expires = 0) { |
| 72 | - // toujours envoyer un content type, meme vide ! |
|
| 73 | - header('Accept-Ranges: bytes'); |
|
| 74 | - header('Content-Type: ' . $content_type); |
|
| 75 | - |
|
| 76 | - if (($fs = stat($fichier)) && !empty($fs['size']) && !empty($fs['mtime'])) { |
|
| 77 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $fs['mtime']) . ' GMT'); |
|
| 78 | - header(sprintf('Etag: "%x-%x"', $fs['size'], str_pad($fs['mtime'], 16, '0'))); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if ($attachment) { |
|
| 82 | - $f = (is_string($attachment) ? $attachment : basename($fichier)); |
|
| 83 | - // ce content-type est necessaire pour eviter des corruptions de zip dans ie6 |
|
| 84 | - header('Content-Type: application/octet-stream'); |
|
| 85 | - |
|
| 86 | - header("Content-Disposition: attachment; filename=\"$f\";"); |
|
| 87 | - header('Content-Transfer-Encoding: binary'); |
|
| 88 | - |
|
| 89 | - // fix for IE caching or PHP bug issue |
|
| 90 | - header('Expires: 0'); // set expiration time |
|
| 91 | - header('Pragma: public'); |
|
| 92 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 93 | - } |
|
| 94 | - else { |
|
| 95 | - $f = (is_string($attachment) ? $attachment : basename($fichier)); |
|
| 96 | - header("Content-Disposition: inline; filename=\"$f\";"); |
|
| 97 | - header('Expires: ' . $expires); // set expiration time |
|
| 98 | - } |
|
| 72 | + // toujours envoyer un content type, meme vide ! |
|
| 73 | + header('Accept-Ranges: bytes'); |
|
| 74 | + header('Content-Type: ' . $content_type); |
|
| 75 | + |
|
| 76 | + if (($fs = stat($fichier)) && !empty($fs['size']) && !empty($fs['mtime'])) { |
|
| 77 | + header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $fs['mtime']) . ' GMT'); |
|
| 78 | + header(sprintf('Etag: "%x-%x"', $fs['size'], str_pad($fs['mtime'], 16, '0'))); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if ($attachment) { |
|
| 82 | + $f = (is_string($attachment) ? $attachment : basename($fichier)); |
|
| 83 | + // ce content-type est necessaire pour eviter des corruptions de zip dans ie6 |
|
| 84 | + header('Content-Type: application/octet-stream'); |
|
| 85 | + |
|
| 86 | + header("Content-Disposition: attachment; filename=\"$f\";"); |
|
| 87 | + header('Content-Transfer-Encoding: binary'); |
|
| 88 | + |
|
| 89 | + // fix for IE caching or PHP bug issue |
|
| 90 | + header('Expires: 0'); // set expiration time |
|
| 91 | + header('Pragma: public'); |
|
| 92 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 93 | + } |
|
| 94 | + else { |
|
| 95 | + $f = (is_string($attachment) ? $attachment : basename($fichier)); |
|
| 96 | + header("Content-Disposition: inline; filename=\"$f\";"); |
|
| 97 | + header('Expires: ' . $expires); // set expiration time |
|
| 98 | + } |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -103,20 +103,20 @@ discard block |
||
| 103 | 103 | * @param string $fichier |
| 104 | 104 | */ |
| 105 | 105 | function spip_livrer_fichier_entier($fichier) { |
| 106 | - if (!file_exists($fichier)) { |
|
| 107 | - throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 108 | - } |
|
| 106 | + if (!file_exists($fichier)) { |
|
| 107 | + throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - if (!is_readable($fichier)) { |
|
| 111 | - throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 112 | - } |
|
| 110 | + if (!is_readable($fichier)) { |
|
| 111 | + throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - if ($size = filesize($fichier)) { |
|
| 115 | - header(sprintf('Content-Length: %d', $size)); |
|
| 116 | - } |
|
| 114 | + if ($size = filesize($fichier)) { |
|
| 115 | + header(sprintf('Content-Length: %d', $size)); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - readfile($fichier); |
|
| 119 | - exit(); |
|
| 118 | + readfile($fichier); |
|
| 119 | + exit(); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -129,98 +129,98 @@ discard block |
||
| 129 | 129 | * @throws Exception |
| 130 | 130 | */ |
| 131 | 131 | function spip_livrer_fichier_partie($fichier, $range = null) { |
| 132 | - if (!file_exists($fichier)) { |
|
| 133 | - throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 134 | - } |
|
| 132 | + if (!file_exists($fichier)) { |
|
| 133 | + throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - if (!is_readable($fichier)) { |
|
| 137 | - throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 138 | - } |
|
| 136 | + if (!is_readable($fichier)) { |
|
| 137 | + throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | |
| 141 | - // Par defaut on envoie tout |
|
| 142 | - $byteOffset = 0; |
|
| 143 | - $byteLength = $fileSize = filesize($fichier); |
|
| 141 | + // Par defaut on envoie tout |
|
| 142 | + $byteOffset = 0; |
|
| 143 | + $byteLength = $fileSize = filesize($fichier); |
|
| 144 | 144 | |
| 145 | 145 | |
| 146 | - // Parse Content-Range header for byte offsets, looks like "bytes=11525-" OR "bytes=11525-12451" |
|
| 147 | - if ($range && preg_match('%bytes=(\d+)-(\d+)?%i', $range, $match)) { |
|
| 148 | - ### Offset signifies where we should begin to read the file |
|
| 149 | - $byteOffset = (int)$match[1]; |
|
| 146 | + // Parse Content-Range header for byte offsets, looks like "bytes=11525-" OR "bytes=11525-12451" |
|
| 147 | + if ($range && preg_match('%bytes=(\d+)-(\d+)?%i', $range, $match)) { |
|
| 148 | + ### Offset signifies where we should begin to read the file |
|
| 149 | + $byteOffset = (int)$match[1]; |
|
| 150 | 150 | |
| 151 | 151 | |
| 152 | - ### Length is for how long we should read the file according to the browser, and can never go beyond the file size |
|
| 153 | - if (isset($match[2])) { |
|
| 154 | - $finishBytes = (int)$match[2]; |
|
| 155 | - $byteLength = $finishBytes + 1; |
|
| 156 | - } else { |
|
| 157 | - $finishBytes = $fileSize - 1; |
|
| 158 | - } |
|
| 152 | + ### Length is for how long we should read the file according to the browser, and can never go beyond the file size |
|
| 153 | + if (isset($match[2])) { |
|
| 154 | + $finishBytes = (int)$match[2]; |
|
| 155 | + $byteLength = $finishBytes + 1; |
|
| 156 | + } else { |
|
| 157 | + $finishBytes = $fileSize - 1; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - $cr_header = sprintf('Content-Range: bytes %d-%d/%d', $byteOffset, $finishBytes, $fileSize); |
|
| 161 | - } |
|
| 162 | - else { |
|
| 163 | - // si pas de range valide, on delegue a la methode d'envoi complet |
|
| 164 | - spip_livrer_fichier_entier($fichier); |
|
| 165 | - // redondant, mais facilite la comprehension du code |
|
| 166 | - exit(); |
|
| 167 | - } |
|
| 160 | + $cr_header = sprintf('Content-Range: bytes %d-%d/%d', $byteOffset, $finishBytes, $fileSize); |
|
| 161 | + } |
|
| 162 | + else { |
|
| 163 | + // si pas de range valide, on delegue a la methode d'envoi complet |
|
| 164 | + spip_livrer_fichier_entier($fichier); |
|
| 165 | + // redondant, mais facilite la comprehension du code |
|
| 166 | + exit(); |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - // Remove headers that might unnecessarily clutter up the output |
|
| 170 | - header_remove('Cache-Control'); |
|
| 171 | - header_remove('Pragma'); |
|
| 169 | + // Remove headers that might unnecessarily clutter up the output |
|
| 170 | + header_remove('Cache-Control'); |
|
| 171 | + header_remove('Pragma'); |
|
| 172 | 172 | |
| 173 | - // partial content |
|
| 174 | - header('HTTP/1.1 206 Partial content'); |
|
| 175 | - header($cr_header); ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent |
|
| 173 | + // partial content |
|
| 174 | + header('HTTP/1.1 206 Partial content'); |
|
| 175 | + header($cr_header); ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent |
|
| 176 | 176 | |
| 177 | 177 | |
| 178 | - $byteRange = $byteLength - $byteOffset; |
|
| 178 | + $byteRange = $byteLength - $byteOffset; |
|
| 179 | 179 | |
| 180 | - header(sprintf('Content-Length: %d', $byteRange)); |
|
| 180 | + header(sprintf('Content-Length: %d', $byteRange)); |
|
| 181 | 181 | |
| 182 | - // Variable containing the buffer |
|
| 183 | - $buffer = ''; |
|
| 184 | - // Just a reasonable buffer size |
|
| 185 | - $bufferSize = 512 * 16; |
|
| 186 | - // Contains how much is left to read of the byteRange |
|
| 187 | - $bytePool = $byteRange; |
|
| 182 | + // Variable containing the buffer |
|
| 183 | + $buffer = ''; |
|
| 184 | + // Just a reasonable buffer size |
|
| 185 | + $bufferSize = 512 * 16; |
|
| 186 | + // Contains how much is left to read of the byteRange |
|
| 187 | + $bytePool = $byteRange; |
|
| 188 | 188 | |
| 189 | - if (!$handle = fopen($fichier, 'r')) { |
|
| 190 | - throw new \Exception(sprintf('Could not get handle for file %s', $fichier)); |
|
| 191 | - } |
|
| 189 | + if (!$handle = fopen($fichier, 'r')) { |
|
| 190 | + throw new \Exception(sprintf('Could not get handle for file %s', $fichier)); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - if (fseek($handle, $byteOffset, SEEK_SET) == -1) { |
|
| 194 | - throw new \Exception(sprintf('Could not seek to byte offset %d', $byteOffset)); |
|
| 195 | - } |
|
| 193 | + if (fseek($handle, $byteOffset, SEEK_SET) == -1) { |
|
| 194 | + throw new \Exception(sprintf('Could not seek to byte offset %d', $byteOffset)); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | 197 | |
| 198 | - while ($bytePool > 0) { |
|
| 199 | - // How many bytes we request on this iteration |
|
| 200 | - $chunkSizeRequested = min($bufferSize, $bytePool); |
|
| 198 | + while ($bytePool > 0) { |
|
| 199 | + // How many bytes we request on this iteration |
|
| 200 | + $chunkSizeRequested = min($bufferSize, $bytePool); |
|
| 201 | 201 | |
| 202 | - // Try readin $chunkSizeRequested bytes from $handle and put data in $buffer |
|
| 203 | - $buffer = fread($handle, $chunkSizeRequested); |
|
| 202 | + // Try readin $chunkSizeRequested bytes from $handle and put data in $buffer |
|
| 203 | + $buffer = fread($handle, $chunkSizeRequested); |
|
| 204 | 204 | |
| 205 | - // Store how many bytes were actually read |
|
| 206 | - $chunkSizeActual = strlen($buffer); |
|
| 205 | + // Store how many bytes were actually read |
|
| 206 | + $chunkSizeActual = strlen($buffer); |
|
| 207 | 207 | |
| 208 | - // If we didn't get any bytes that means something unexpected has happened since $bytePool should be zero already |
|
| 209 | - if ($chunkSizeActual == 0) { |
|
| 210 | - // For production servers this should go in your php error log, since it will break the output |
|
| 211 | - trigger_error('Chunksize became 0', E_USER_WARNING); |
|
| 212 | - break; |
|
| 213 | - } |
|
| 208 | + // If we didn't get any bytes that means something unexpected has happened since $bytePool should be zero already |
|
| 209 | + if ($chunkSizeActual == 0) { |
|
| 210 | + // For production servers this should go in your php error log, since it will break the output |
|
| 211 | + trigger_error('Chunksize became 0', E_USER_WARNING); |
|
| 212 | + break; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - // Decrease byte pool with amount of bytes that were read during this iteration |
|
| 216 | - $bytePool -= $chunkSizeActual; |
|
| 215 | + // Decrease byte pool with amount of bytes that were read during this iteration |
|
| 216 | + $bytePool -= $chunkSizeActual; |
|
| 217 | 217 | |
| 218 | - // Write the buffer to output |
|
| 219 | - print $buffer; |
|
| 218 | + // Write the buffer to output |
|
| 219 | + print $buffer; |
|
| 220 | 220 | |
| 221 | - // Try to output the data to the client immediately |
|
| 222 | - flush(); |
|
| 223 | - } |
|
| 221 | + // Try to output the data to the client immediately |
|
| 222 | + flush(); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - exit(); |
|
| 225 | + exit(); |
|
| 226 | 226 | } |
@@ -15,22 +15,22 @@ |
||
| 15 | 15 | * Présentation des pages simplifiées pour installer SPIP |
| 16 | 16 | **/ |
| 17 | 17 | class Installation extends Admin { |
| 18 | - public const TYPE = 'installation'; |
|
| 18 | + public const TYPE = 'installation'; |
|
| 19 | 19 | |
| 20 | - protected function setOptions(array $options) { |
|
| 21 | - $options['titre'] ??= ''; |
|
| 22 | - if (!$options['titre'] || $options['titre'] === 'AUTO') { |
|
| 23 | - $options['titre'] = _T('info_installation_systeme_publication'); |
|
| 24 | - } |
|
| 25 | - $options = parent::setOptions($options); |
|
| 26 | - $options['couleur_fond'] = '#a1124d'; |
|
| 27 | - $options['css_files'][] = find_in_theme('installation.css'); |
|
| 28 | - $options['footer'] = ''; |
|
| 29 | - return $options; |
|
| 30 | - } |
|
| 20 | + protected function setOptions(array $options) { |
|
| 21 | + $options['titre'] ??= ''; |
|
| 22 | + if (!$options['titre'] || $options['titre'] === 'AUTO') { |
|
| 23 | + $options['titre'] = _T('info_installation_systeme_publication'); |
|
| 24 | + } |
|
| 25 | + $options = parent::setOptions($options); |
|
| 26 | + $options['couleur_fond'] = '#a1124d'; |
|
| 27 | + $options['css_files'][] = find_in_theme('installation.css'); |
|
| 28 | + $options['footer'] = ''; |
|
| 29 | + return $options; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function page($corps = '', $options = []) { |
|
| 33 | - $options['titre'] ??= 'AUTO'; |
|
| 34 | - return parent::page($corps, $options); |
|
| 35 | - } |
|
| 32 | + public function page($corps = '', $options = []) { |
|
| 33 | + $options['titre'] ??= 'AUTO'; |
|
| 34 | + return parent::page($corps, $options); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -15,146 +15,146 @@ |
||
| 15 | 15 | * Présentation des pages simplifiées d’admin pour envoyer un message à un utilisateur |
| 16 | 16 | **/ |
| 17 | 17 | class Admin extends Page { |
| 18 | - public const TYPE = 'admin'; |
|
| 19 | - protected function setOptions(array $options) { |
|
| 20 | - $options['couleur_fond'] = '#999'; |
|
| 21 | - if (empty($options['css_files'])) { |
|
| 22 | - $options['css_files'] = []; |
|
| 23 | - } |
|
| 24 | - array_unshift($options['css_files'], find_in_theme('minipres.css')); |
|
| 25 | - |
|
| 26 | - $options['page_title'] = ($options['titre'] ?? ''); |
|
| 27 | - |
|
| 28 | - return $options; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Retourne le début d'une page HTML minimale (de type installation ou erreur) |
|
| 34 | - * |
|
| 35 | - * @param array $options |
|
| 36 | - * @return string |
|
| 37 | - * Code HTML |
|
| 38 | - */ |
|
| 39 | - public function installDebutPage($options = []) { |
|
| 40 | - |
|
| 41 | - $options = $this->setOptions($options); |
|
| 42 | - return parent::ouvreBody($options) |
|
| 43 | - . parent::ouvreCorps($options); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Retourne le fin d'une page HTML minimale (de type installation ou erreur) |
|
| 48 | - * |
|
| 49 | - * @param array $options |
|
| 50 | - * @return string |
|
| 51 | - * Code HTML |
|
| 52 | - */ |
|
| 53 | - public function installFinPage($options = []) { |
|
| 54 | - |
|
| 55 | - $options = $this->setOptions($options); |
|
| 56 | - return parent::fermeCorps($options) |
|
| 57 | - . parent::fermeBody(); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Retourne une page HTML contenant, dans une présentation minimale, |
|
| 63 | - * le contenu transmis dans `$corps`. |
|
| 64 | - * |
|
| 65 | - * Appelée pour afficher un message d’erreur (l’utilisateur n’a pas |
|
| 66 | - * accès à cette page par exemple). |
|
| 67 | - * |
|
| 68 | - * Lorsqu’aucun argument n’est transmis, un header 403 est renvoyé, |
|
| 69 | - * ainsi qu’un message indiquant une interdiction d’accès. |
|
| 70 | - * |
|
| 71 | - * @param string $corps |
|
| 72 | - * Corps de la page |
|
| 73 | - * @param array $options |
|
| 74 | - * @return string |
|
| 75 | - * HTML de la page |
|
| 76 | - * @see ouvreBody() |
|
| 77 | - * string $titre : Titre à l'affichage (différent de $page_title) |
|
| 78 | - * int $status : status de la page |
|
| 79 | - * string $footer : pied de la box en remplacement du bouton retour par défaut |
|
| 80 | - * @uses ouvreBody() |
|
| 81 | - * @uses fermeBody() |
|
| 82 | - * |
|
| 83 | - */ |
|
| 84 | - public function page($corps = '', $options = []) { |
|
| 85 | - |
|
| 86 | - $footer = ''; |
|
| 87 | - |
|
| 88 | - $titre = $options['titre'] ?? ''; |
|
| 89 | - if (!$titre) { |
|
| 90 | - if (empty($corps) && !isset($options['status'])) { |
|
| 91 | - $options['status'] = 403; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if ( |
|
| 95 | - !$titre = _request('action') |
|
| 96 | - && !$titre = _request('exec') |
|
| 97 | - && !$titre = _request('page') |
|
| 98 | - ) { |
|
| 99 | - $titre = '?'; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $titre = spip_htmlspecialchars($titre); |
|
| 103 | - |
|
| 104 | - $titre = ($titre == 'install') |
|
| 105 | - ? _T('avis_espace_interdit') |
|
| 106 | - : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 107 | - |
|
| 108 | - $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 109 | - $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 110 | - |
|
| 111 | - if ($statut != '0minirezo') { |
|
| 112 | - $titre = _T('info_acces_interdit'); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if ($statut && test_espace_prive()) { |
|
| 116 | - $footer = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 117 | - } |
|
| 118 | - elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 119 | - $footer = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 120 | - } |
|
| 121 | - else { |
|
| 122 | - $footer = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site'] ?? ''); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - spip_log($nom . " $titre " . $_SERVER['REQUEST_URI'], 'minipres'); |
|
| 126 | - |
|
| 127 | - $options['footer'] = $footer; |
|
| 128 | - if (empty($corps)) { |
|
| 129 | - $corps = "<div class='msg-alert error'>" |
|
| 130 | - . $titre |
|
| 131 | - . '</div>'; |
|
| 132 | - $options['titre'] = ''; |
|
| 133 | - } |
|
| 134 | - else { |
|
| 135 | - $options['titre'] = $titre; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - else { |
|
| 139 | - $options['titre'] = $titre; |
|
| 140 | - } |
|
| 141 | - $options['page_title'] = $titre; |
|
| 142 | - |
|
| 143 | - $options = $this->setOptions($options); |
|
| 144 | - |
|
| 145 | - $html = parent::page($corps, $options); |
|
| 146 | - |
|
| 147 | - if (!_AJAX) { |
|
| 148 | - return $html; |
|
| 149 | - } else { |
|
| 150 | - include_spip('inc/headers'); |
|
| 151 | - include_spip('inc/actions'); |
|
| 152 | - $url = self('&', true); |
|
| 153 | - foreach ($_POST as $v => $c) { |
|
| 154 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 155 | - } |
|
| 156 | - ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 157 | - return ''; |
|
| 158 | - } |
|
| 159 | - } |
|
| 18 | + public const TYPE = 'admin'; |
|
| 19 | + protected function setOptions(array $options) { |
|
| 20 | + $options['couleur_fond'] = '#999'; |
|
| 21 | + if (empty($options['css_files'])) { |
|
| 22 | + $options['css_files'] = []; |
|
| 23 | + } |
|
| 24 | + array_unshift($options['css_files'], find_in_theme('minipres.css')); |
|
| 25 | + |
|
| 26 | + $options['page_title'] = ($options['titre'] ?? ''); |
|
| 27 | + |
|
| 28 | + return $options; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Retourne le début d'une page HTML minimale (de type installation ou erreur) |
|
| 34 | + * |
|
| 35 | + * @param array $options |
|
| 36 | + * @return string |
|
| 37 | + * Code HTML |
|
| 38 | + */ |
|
| 39 | + public function installDebutPage($options = []) { |
|
| 40 | + |
|
| 41 | + $options = $this->setOptions($options); |
|
| 42 | + return parent::ouvreBody($options) |
|
| 43 | + . parent::ouvreCorps($options); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Retourne le fin d'une page HTML minimale (de type installation ou erreur) |
|
| 48 | + * |
|
| 49 | + * @param array $options |
|
| 50 | + * @return string |
|
| 51 | + * Code HTML |
|
| 52 | + */ |
|
| 53 | + public function installFinPage($options = []) { |
|
| 54 | + |
|
| 55 | + $options = $this->setOptions($options); |
|
| 56 | + return parent::fermeCorps($options) |
|
| 57 | + . parent::fermeBody(); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Retourne une page HTML contenant, dans une présentation minimale, |
|
| 63 | + * le contenu transmis dans `$corps`. |
|
| 64 | + * |
|
| 65 | + * Appelée pour afficher un message d’erreur (l’utilisateur n’a pas |
|
| 66 | + * accès à cette page par exemple). |
|
| 67 | + * |
|
| 68 | + * Lorsqu’aucun argument n’est transmis, un header 403 est renvoyé, |
|
| 69 | + * ainsi qu’un message indiquant une interdiction d’accès. |
|
| 70 | + * |
|
| 71 | + * @param string $corps |
|
| 72 | + * Corps de la page |
|
| 73 | + * @param array $options |
|
| 74 | + * @return string |
|
| 75 | + * HTML de la page |
|
| 76 | + * @see ouvreBody() |
|
| 77 | + * string $titre : Titre à l'affichage (différent de $page_title) |
|
| 78 | + * int $status : status de la page |
|
| 79 | + * string $footer : pied de la box en remplacement du bouton retour par défaut |
|
| 80 | + * @uses ouvreBody() |
|
| 81 | + * @uses fermeBody() |
|
| 82 | + * |
|
| 83 | + */ |
|
| 84 | + public function page($corps = '', $options = []) { |
|
| 85 | + |
|
| 86 | + $footer = ''; |
|
| 87 | + |
|
| 88 | + $titre = $options['titre'] ?? ''; |
|
| 89 | + if (!$titre) { |
|
| 90 | + if (empty($corps) && !isset($options['status'])) { |
|
| 91 | + $options['status'] = 403; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if ( |
|
| 95 | + !$titre = _request('action') |
|
| 96 | + && !$titre = _request('exec') |
|
| 97 | + && !$titre = _request('page') |
|
| 98 | + ) { |
|
| 99 | + $titre = '?'; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $titre = spip_htmlspecialchars($titre); |
|
| 103 | + |
|
| 104 | + $titre = ($titre == 'install') |
|
| 105 | + ? _T('avis_espace_interdit') |
|
| 106 | + : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 107 | + |
|
| 108 | + $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 109 | + $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 110 | + |
|
| 111 | + if ($statut != '0minirezo') { |
|
| 112 | + $titre = _T('info_acces_interdit'); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if ($statut && test_espace_prive()) { |
|
| 116 | + $footer = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 117 | + } |
|
| 118 | + elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 119 | + $footer = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 120 | + } |
|
| 121 | + else { |
|
| 122 | + $footer = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site'] ?? ''); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + spip_log($nom . " $titre " . $_SERVER['REQUEST_URI'], 'minipres'); |
|
| 126 | + |
|
| 127 | + $options['footer'] = $footer; |
|
| 128 | + if (empty($corps)) { |
|
| 129 | + $corps = "<div class='msg-alert error'>" |
|
| 130 | + . $titre |
|
| 131 | + . '</div>'; |
|
| 132 | + $options['titre'] = ''; |
|
| 133 | + } |
|
| 134 | + else { |
|
| 135 | + $options['titre'] = $titre; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + else { |
|
| 139 | + $options['titre'] = $titre; |
|
| 140 | + } |
|
| 141 | + $options['page_title'] = $titre; |
|
| 142 | + |
|
| 143 | + $options = $this->setOptions($options); |
|
| 144 | + |
|
| 145 | + $html = parent::page($corps, $options); |
|
| 146 | + |
|
| 147 | + if (!_AJAX) { |
|
| 148 | + return $html; |
|
| 149 | + } else { |
|
| 150 | + include_spip('inc/headers'); |
|
| 151 | + include_spip('inc/actions'); |
|
| 152 | + $url = self('&', true); |
|
| 153 | + foreach ($_POST as $v => $c) { |
|
| 154 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 155 | + } |
|
| 156 | + ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 157 | + return ''; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -8,112 +8,112 @@ |
||
| 8 | 8 | **/ |
| 9 | 9 | class Sqlite |
| 10 | 10 | { |
| 11 | - /** @var Requeteur[] Liste des instances de requêteurs créés */ |
|
| 12 | - public static $requeteurs = []; |
|
| 13 | - /** @var bool[] Pour chaque connexion, flag pour savoir si une transaction est en cours */ |
|
| 14 | - public static $transaction_en_cours = []; |
|
| 11 | + /** @var Requeteur[] Liste des instances de requêteurs créés */ |
|
| 12 | + public static $requeteurs = []; |
|
| 13 | + /** @var bool[] Pour chaque connexion, flag pour savoir si une transaction est en cours */ |
|
| 14 | + public static $transaction_en_cours = []; |
|
| 15 | 15 | |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Retourne une unique instance du requêteur |
|
| 19 | - * |
|
| 20 | - * Retourne une instance unique du requêteur pour une connexion SQLite |
|
| 21 | - * donnée |
|
| 22 | - * |
|
| 23 | - * @param string $serveur |
|
| 24 | - * Nom du connecteur |
|
| 25 | - * @return Requeteur |
|
| 26 | - * Instance unique du requêteur |
|
| 27 | - **/ |
|
| 28 | - public static function requeteur($serveur) { |
|
| 29 | - if (!isset(static::$requeteurs[$serveur])) { |
|
| 30 | - static::$requeteurs[$serveur] = new Requeteur($serveur); |
|
| 31 | - } |
|
| 17 | + /** |
|
| 18 | + * Retourne une unique instance du requêteur |
|
| 19 | + * |
|
| 20 | + * Retourne une instance unique du requêteur pour une connexion SQLite |
|
| 21 | + * donnée |
|
| 22 | + * |
|
| 23 | + * @param string $serveur |
|
| 24 | + * Nom du connecteur |
|
| 25 | + * @return Requeteur |
|
| 26 | + * Instance unique du requêteur |
|
| 27 | + **/ |
|
| 28 | + public static function requeteur($serveur) { |
|
| 29 | + if (!isset(static::$requeteurs[$serveur])) { |
|
| 30 | + static::$requeteurs[$serveur] = new Requeteur($serveur); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - return static::$requeteurs[$serveur]; |
|
| 34 | - } |
|
| 33 | + return static::$requeteurs[$serveur]; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Prépare le texte d'une requête avant son exécution |
|
| 38 | - * |
|
| 39 | - * Adapte la requête au format plus ou moins MySQL par un format |
|
| 40 | - * compris de SQLite. |
|
| 41 | - * |
|
| 42 | - * Change les préfixes de tables SPIP par ceux véritables |
|
| 43 | - * |
|
| 44 | - * @param string $query Requête à préparer |
|
| 45 | - * @param string $serveur Nom de la connexion |
|
| 46 | - * @return string Requête préparée |
|
| 47 | - */ |
|
| 48 | - public static function traduire_requete($query, $serveur) { |
|
| 49 | - $requeteur = static::requeteur($serveur); |
|
| 50 | - $traducteur = new Traducteur($query, $requeteur->prefixe, $requeteur->sqlite_version); |
|
| 36 | + /** |
|
| 37 | + * Prépare le texte d'une requête avant son exécution |
|
| 38 | + * |
|
| 39 | + * Adapte la requête au format plus ou moins MySQL par un format |
|
| 40 | + * compris de SQLite. |
|
| 41 | + * |
|
| 42 | + * Change les préfixes de tables SPIP par ceux véritables |
|
| 43 | + * |
|
| 44 | + * @param string $query Requête à préparer |
|
| 45 | + * @param string $serveur Nom de la connexion |
|
| 46 | + * @return string Requête préparée |
|
| 47 | + */ |
|
| 48 | + public static function traduire_requete($query, $serveur) { |
|
| 49 | + $requeteur = static::requeteur($serveur); |
|
| 50 | + $traducteur = new Traducteur($query, $requeteur->prefixe, $requeteur->sqlite_version); |
|
| 51 | 51 | |
| 52 | - return $traducteur->traduire_requete(); |
|
| 53 | - } |
|
| 52 | + return $traducteur->traduire_requete(); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Démarre une transaction |
|
| 57 | - * |
|
| 58 | - * @param string $serveur Nom de la connexion |
|
| 59 | - **/ |
|
| 60 | - public static function demarrer_transaction($serveur) { |
|
| 61 | - Sqlite::executer_requete('BEGIN TRANSACTION', $serveur); |
|
| 62 | - Sqlite::$transaction_en_cours[$serveur] = true; |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * Démarre une transaction |
|
| 57 | + * |
|
| 58 | + * @param string $serveur Nom de la connexion |
|
| 59 | + **/ |
|
| 60 | + public static function demarrer_transaction($serveur) { |
|
| 61 | + Sqlite::executer_requete('BEGIN TRANSACTION', $serveur); |
|
| 62 | + Sqlite::$transaction_en_cours[$serveur] = true; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Exécute la requête donnée |
|
| 67 | - * |
|
| 68 | - * @param string $query Requête |
|
| 69 | - * @param string $serveur Nom de la connexion |
|
| 70 | - * @param null|bool $tracer Demander des statistiques (temps) ? |
|
| 71 | - **/ |
|
| 72 | - public static function executer_requete($query, $serveur, $tracer = null) { |
|
| 73 | - $requeteur = Sqlite::requeteur($serveur); |
|
| 65 | + /** |
|
| 66 | + * Exécute la requête donnée |
|
| 67 | + * |
|
| 68 | + * @param string $query Requête |
|
| 69 | + * @param string $serveur Nom de la connexion |
|
| 70 | + * @param null|bool $tracer Demander des statistiques (temps) ? |
|
| 71 | + **/ |
|
| 72 | + public static function executer_requete($query, $serveur, $tracer = null) { |
|
| 73 | + $requeteur = Sqlite::requeteur($serveur); |
|
| 74 | 74 | |
| 75 | - return $requeteur->executer_requete($query, $tracer); |
|
| 76 | - } |
|
| 75 | + return $requeteur->executer_requete($query, $tracer); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Obtient l'identifiant de la dernière ligne insérée ou modifiée |
|
| 80 | - * |
|
| 81 | - * @param string $serveur Nom de la connexion |
|
| 82 | - * return int Identifiant |
|
| 83 | - **/ |
|
| 84 | - public static function last_insert_id($serveur) { |
|
| 85 | - $requeteur = Sqlite::requeteur($serveur); |
|
| 78 | + /** |
|
| 79 | + * Obtient l'identifiant de la dernière ligne insérée ou modifiée |
|
| 80 | + * |
|
| 81 | + * @param string $serveur Nom de la connexion |
|
| 82 | + * return int Identifiant |
|
| 83 | + **/ |
|
| 84 | + public static function last_insert_id($serveur) { |
|
| 85 | + $requeteur = Sqlite::requeteur($serveur); |
|
| 86 | 86 | |
| 87 | - return $requeteur->last_insert_id(); |
|
| 88 | - } |
|
| 87 | + return $requeteur->last_insert_id(); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Annule une transaction |
|
| 92 | - * |
|
| 93 | - * @param string $serveur Nom de la connexion |
|
| 94 | - **/ |
|
| 95 | - public static function annuler_transaction($serveur) { |
|
| 96 | - Sqlite::executer_requete('ROLLBACK', $serveur); |
|
| 97 | - Sqlite::$transaction_en_cours[$serveur] = false; |
|
| 98 | - } |
|
| 90 | + /** |
|
| 91 | + * Annule une transaction |
|
| 92 | + * |
|
| 93 | + * @param string $serveur Nom de la connexion |
|
| 94 | + **/ |
|
| 95 | + public static function annuler_transaction($serveur) { |
|
| 96 | + Sqlite::executer_requete('ROLLBACK', $serveur); |
|
| 97 | + Sqlite::$transaction_en_cours[$serveur] = false; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Termine une transaction |
|
| 102 | - * |
|
| 103 | - * @param string $serveur Nom de la connexion |
|
| 104 | - **/ |
|
| 105 | - public static function finir_transaction($serveur) { |
|
| 106 | - // si pas de transaction en cours, ne rien faire et le dire |
|
| 107 | - if ( |
|
| 108 | - !isset(Sqlite::$transaction_en_cours[$serveur]) |
|
| 109 | - || Sqlite::$transaction_en_cours[$serveur] == false |
|
| 110 | - ) { |
|
| 111 | - return false; |
|
| 112 | - } |
|
| 113 | - // sinon fermer la transaction et retourner true |
|
| 114 | - Sqlite::executer_requete('COMMIT', $serveur); |
|
| 115 | - Sqlite::$transaction_en_cours[$serveur] = false; |
|
| 100 | + /** |
|
| 101 | + * Termine une transaction |
|
| 102 | + * |
|
| 103 | + * @param string $serveur Nom de la connexion |
|
| 104 | + **/ |
|
| 105 | + public static function finir_transaction($serveur) { |
|
| 106 | + // si pas de transaction en cours, ne rien faire et le dire |
|
| 107 | + if ( |
|
| 108 | + !isset(Sqlite::$transaction_en_cours[$serveur]) |
|
| 109 | + || Sqlite::$transaction_en_cours[$serveur] == false |
|
| 110 | + ) { |
|
| 111 | + return false; |
|
| 112 | + } |
|
| 113 | + // sinon fermer la transaction et retourner true |
|
| 114 | + Sqlite::executer_requete('COMMIT', $serveur); |
|
| 115 | + Sqlite::$transaction_en_cours[$serveur] = false; |
|
| 116 | 116 | |
| 117 | - return true; |
|
| 118 | - } |
|
| 117 | + return true; |
|
| 118 | + } |
|
| 119 | 119 | } |
@@ -6,10 +6,10 @@ |
||
| 6 | 6 | * Pouvoir retrouver le PDO utilisé pour générer un résultat de requête. |
| 7 | 7 | */ |
| 8 | 8 | final class PDOStatement extends \PDOStatement { |
| 9 | - private function __construct(private \PDO &$PDO) { |
|
| 10 | - } |
|
| 9 | + private function __construct(private \PDO &$PDO) { |
|
| 10 | + } |
|
| 11 | 11 | |
| 12 | - public function getPDO(): \PDO { |
|
| 13 | - return $this->PDO; |
|
| 14 | - } |
|
| 12 | + public function getPDO(): \PDO { |
|
| 13 | + return $this->PDO; |
|
| 14 | + } |
|
| 15 | 15 | } |
@@ -13,109 +13,109 @@ |
||
| 13 | 13 | |
| 14 | 14 | class Requeteur |
| 15 | 15 | { |
| 16 | - /** @var string texte de la requête */ |
|
| 17 | - public $query = ''; // la requete |
|
| 18 | - /** @var string Nom de la connexion */ |
|
| 19 | - public $serveur = ''; |
|
| 20 | - /** @var \PDO|null Identifiant de la connexion SQLite */ |
|
| 21 | - public $link = null; |
|
| 22 | - /** @var string Prefixe des tables SPIP */ |
|
| 23 | - public $prefixe = ''; |
|
| 24 | - /** @var string Nom de la base de donnée */ |
|
| 25 | - public $db = ''; |
|
| 26 | - /** @var bool Doit-on tracer les requetes (var_profile) ? */ |
|
| 27 | - public $tracer = false; // doit-on tracer les requetes (var_profile) |
|
| 28 | - |
|
| 29 | - /** @var string Version de SQLite (2 ou 3) */ |
|
| 30 | - public $sqlite_version = ''; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Constructeur |
|
| 34 | - * |
|
| 35 | - * @param string $serveur |
|
| 36 | - */ |
|
| 37 | - public function __construct($serveur = '') { |
|
| 38 | - _sqlite_init(); |
|
| 39 | - $this->serveur = strtolower($serveur); |
|
| 40 | - |
|
| 41 | - if (!($this->link = _sqlite_link($this->serveur)) && (!defined('_ECRIRE_INSTALL') || !_ECRIRE_INSTALL)) { |
|
| 42 | - spip_log('Aucune connexion sqlite (link)', 'sqlite.' . _LOG_ERREUR); |
|
| 43 | - |
|
| 44 | - return; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - $this->sqlite_version = _sqlite_is_version('', $this->link); |
|
| 48 | - |
|
| 49 | - $this->prefixe = $GLOBALS['connexions'][$this->serveur ?: 0]['prefixe']; |
|
| 50 | - $this->db = $GLOBALS['connexions'][$this->serveur ?: 0]['db']; |
|
| 51 | - |
|
| 52 | - // tracage des requetes ? |
|
| 53 | - $this->tracer = (isset($_GET['var_profile']) && $_GET['var_profile']); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Lancer la requête transmise et faire le tracage si demandé |
|
| 58 | - * |
|
| 59 | - * @param string $query |
|
| 60 | - * Requête à exécuter |
|
| 61 | - * @param bool|null $tracer |
|
| 62 | - * true pour tracer la requête |
|
| 63 | - * @return bool|\PDOStatement|array |
|
| 64 | - */ |
|
| 65 | - public function executer_requete($query, $tracer = null) { |
|
| 66 | - if (is_null($tracer)) { |
|
| 67 | - $tracer = $this->tracer; |
|
| 68 | - } |
|
| 69 | - $err = ''; |
|
| 70 | - $t = 0; |
|
| 71 | - if ($tracer || defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) { |
|
| 72 | - include_spip('public/tracer'); |
|
| 73 | - $t = trace_query_start(); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - # spip_log("requete: $this->serveur >> $query",'sqlite.'._LOG_DEBUG); // boum ? pourquoi ? |
|
| 77 | - if ($this->link) { |
|
| 78 | - // memoriser la derniere erreur PHP vue |
|
| 79 | - $last_error = (function_exists('error_get_last') ? error_get_last() : ''); |
|
| 80 | - $e = null; |
|
| 81 | - // sauver la derniere requete |
|
| 82 | - $GLOBALS['connexions'][$this->serveur ?: 0]['last'] = $query; |
|
| 83 | - $GLOBALS['connexions'][$this->serveur ?: 0]['total_requetes']++; |
|
| 84 | - |
|
| 85 | - try { |
|
| 86 | - $r = $this->link->query($query); |
|
| 87 | - } catch (\PDOException $e) { |
|
| 88 | - spip_log('PDOException: ' . $e->getMessage(), 'sqlite.' . _LOG_DEBUG); |
|
| 89 | - $r = false; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // loger les warnings/erreurs eventuels de sqlite remontant dans PHP |
|
| 93 | - if ($e && $e instanceof \PDOException) { |
|
| 94 | - $err = strip_tags($e->getMessage()) . ' in ' . $e->getFile() . ' line ' . $e->getLine(); |
|
| 95 | - spip_log("$err - " . $query, 'sqlite.' . _LOG_ERREUR); |
|
| 96 | - } elseif (($err = (function_exists('error_get_last') ? error_get_last() : '')) && $err != $last_error) { |
|
| 97 | - $err = strip_tags($err['message']) . ' in ' . $err['file'] . ' line ' . $err['line']; |
|
| 98 | - spip_log("$err - " . $query, 'sqlite.' . _LOG_ERREUR); |
|
| 99 | - } else { |
|
| 100 | - $err = ''; |
|
| 101 | - } |
|
| 102 | - } else { |
|
| 103 | - $r = false; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if (spip_sqlite_errno($this->serveur)) { |
|
| 107 | - $err .= spip_sqlite_error($query, $this->serveur); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return $t ? trace_query_end($query, $t, $r, $err, $this->serveur) : $r; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Obtient l'identifiant de la dernière ligne insérée ou modifiée |
|
| 115 | - * |
|
| 116 | - * @return string|false |
|
| 117 | - **/ |
|
| 118 | - public function last_insert_id() { |
|
| 119 | - return $this->link->lastInsertId(); |
|
| 120 | - } |
|
| 16 | + /** @var string texte de la requête */ |
|
| 17 | + public $query = ''; // la requete |
|
| 18 | + /** @var string Nom de la connexion */ |
|
| 19 | + public $serveur = ''; |
|
| 20 | + /** @var \PDO|null Identifiant de la connexion SQLite */ |
|
| 21 | + public $link = null; |
|
| 22 | + /** @var string Prefixe des tables SPIP */ |
|
| 23 | + public $prefixe = ''; |
|
| 24 | + /** @var string Nom de la base de donnée */ |
|
| 25 | + public $db = ''; |
|
| 26 | + /** @var bool Doit-on tracer les requetes (var_profile) ? */ |
|
| 27 | + public $tracer = false; // doit-on tracer les requetes (var_profile) |
|
| 28 | + |
|
| 29 | + /** @var string Version de SQLite (2 ou 3) */ |
|
| 30 | + public $sqlite_version = ''; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Constructeur |
|
| 34 | + * |
|
| 35 | + * @param string $serveur |
|
| 36 | + */ |
|
| 37 | + public function __construct($serveur = '') { |
|
| 38 | + _sqlite_init(); |
|
| 39 | + $this->serveur = strtolower($serveur); |
|
| 40 | + |
|
| 41 | + if (!($this->link = _sqlite_link($this->serveur)) && (!defined('_ECRIRE_INSTALL') || !_ECRIRE_INSTALL)) { |
|
| 42 | + spip_log('Aucune connexion sqlite (link)', 'sqlite.' . _LOG_ERREUR); |
|
| 43 | + |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + $this->sqlite_version = _sqlite_is_version('', $this->link); |
|
| 48 | + |
|
| 49 | + $this->prefixe = $GLOBALS['connexions'][$this->serveur ?: 0]['prefixe']; |
|
| 50 | + $this->db = $GLOBALS['connexions'][$this->serveur ?: 0]['db']; |
|
| 51 | + |
|
| 52 | + // tracage des requetes ? |
|
| 53 | + $this->tracer = (isset($_GET['var_profile']) && $_GET['var_profile']); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Lancer la requête transmise et faire le tracage si demandé |
|
| 58 | + * |
|
| 59 | + * @param string $query |
|
| 60 | + * Requête à exécuter |
|
| 61 | + * @param bool|null $tracer |
|
| 62 | + * true pour tracer la requête |
|
| 63 | + * @return bool|\PDOStatement|array |
|
| 64 | + */ |
|
| 65 | + public function executer_requete($query, $tracer = null) { |
|
| 66 | + if (is_null($tracer)) { |
|
| 67 | + $tracer = $this->tracer; |
|
| 68 | + } |
|
| 69 | + $err = ''; |
|
| 70 | + $t = 0; |
|
| 71 | + if ($tracer || defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) { |
|
| 72 | + include_spip('public/tracer'); |
|
| 73 | + $t = trace_query_start(); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + # spip_log("requete: $this->serveur >> $query",'sqlite.'._LOG_DEBUG); // boum ? pourquoi ? |
|
| 77 | + if ($this->link) { |
|
| 78 | + // memoriser la derniere erreur PHP vue |
|
| 79 | + $last_error = (function_exists('error_get_last') ? error_get_last() : ''); |
|
| 80 | + $e = null; |
|
| 81 | + // sauver la derniere requete |
|
| 82 | + $GLOBALS['connexions'][$this->serveur ?: 0]['last'] = $query; |
|
| 83 | + $GLOBALS['connexions'][$this->serveur ?: 0]['total_requetes']++; |
|
| 84 | + |
|
| 85 | + try { |
|
| 86 | + $r = $this->link->query($query); |
|
| 87 | + } catch (\PDOException $e) { |
|
| 88 | + spip_log('PDOException: ' . $e->getMessage(), 'sqlite.' . _LOG_DEBUG); |
|
| 89 | + $r = false; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // loger les warnings/erreurs eventuels de sqlite remontant dans PHP |
|
| 93 | + if ($e && $e instanceof \PDOException) { |
|
| 94 | + $err = strip_tags($e->getMessage()) . ' in ' . $e->getFile() . ' line ' . $e->getLine(); |
|
| 95 | + spip_log("$err - " . $query, 'sqlite.' . _LOG_ERREUR); |
|
| 96 | + } elseif (($err = (function_exists('error_get_last') ? error_get_last() : '')) && $err != $last_error) { |
|
| 97 | + $err = strip_tags($err['message']) . ' in ' . $err['file'] . ' line ' . $err['line']; |
|
| 98 | + spip_log("$err - " . $query, 'sqlite.' . _LOG_ERREUR); |
|
| 99 | + } else { |
|
| 100 | + $err = ''; |
|
| 101 | + } |
|
| 102 | + } else { |
|
| 103 | + $r = false; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if (spip_sqlite_errno($this->serveur)) { |
|
| 107 | + $err .= spip_sqlite_error($query, $this->serveur); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return $t ? trace_query_end($query, $t, $r, $err, $this->serveur) : $r; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Obtient l'identifiant de la dernière ligne insérée ou modifiée |
|
| 115 | + * |
|
| 116 | + * @return string|false |
|
| 117 | + **/ |
|
| 118 | + public function last_insert_id() { |
|
| 119 | + return $this->link->lastInsertId(); |
|
| 120 | + } |
|
| 121 | 121 | } |