@@ -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 | } |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('IMG_SVG')) { |
| 23 | - // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 24 | - define('IMG_SVG', 128); |
|
| 25 | - define('IMAGETYPE_SVG', 19); |
|
| 23 | + // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 24 | + define('IMG_SVG', 128); |
|
| 25 | + define('IMAGETYPE_SVG', 19); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -38,34 +38,34 @@ discard block |
||
| 38 | 38 | * false si on a pas pu charger l'image |
| 39 | 39 | */ |
| 40 | 40 | function svg_charger($fichier, $maxlen = null) { |
| 41 | - if (str_starts_with($fichier, 'data:image/svg+xml')) { |
|
| 42 | - $image = explode(';', $fichier, 2); |
|
| 43 | - $image = end($image); |
|
| 44 | - if (str_starts_with($image, 'base64,')) { |
|
| 45 | - $image = base64_decode(substr($image, 7)); |
|
| 46 | - } |
|
| 47 | - if (str_contains($image, '<svg')) { |
|
| 48 | - return $image; |
|
| 49 | - } |
|
| 50 | - // encodage inconnu ou autre format d'image ? |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 53 | - // c'est peut etre deja une image svg ? |
|
| 54 | - if (str_contains($fichier, '<svg')) { |
|
| 55 | - return $fichier; |
|
| 56 | - } |
|
| 57 | - if (!file_exists($fichier)) { |
|
| 58 | - $fichier = supprimer_timestamp($fichier); |
|
| 59 | - if (!file_exists($fichier)) { |
|
| 60 | - return false; |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - $image = is_null($maxlen) ? file_get_contents($fichier) : file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 64 | - // est-ce bien une image svg ? |
|
| 65 | - if (str_contains($image, '<svg')) { |
|
| 66 | - return $image; |
|
| 67 | - } |
|
| 68 | - return false; |
|
| 41 | + if (str_starts_with($fichier, 'data:image/svg+xml')) { |
|
| 42 | + $image = explode(';', $fichier, 2); |
|
| 43 | + $image = end($image); |
|
| 44 | + if (str_starts_with($image, 'base64,')) { |
|
| 45 | + $image = base64_decode(substr($image, 7)); |
|
| 46 | + } |
|
| 47 | + if (str_contains($image, '<svg')) { |
|
| 48 | + return $image; |
|
| 49 | + } |
|
| 50 | + // encodage inconnu ou autre format d'image ? |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | + // c'est peut etre deja une image svg ? |
|
| 54 | + if (str_contains($fichier, '<svg')) { |
|
| 55 | + return $fichier; |
|
| 56 | + } |
|
| 57 | + if (!file_exists($fichier)) { |
|
| 58 | + $fichier = supprimer_timestamp($fichier); |
|
| 59 | + if (!file_exists($fichier)) { |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + $image = is_null($maxlen) ? file_get_contents($fichier) : file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 64 | + // est-ce bien une image svg ? |
|
| 65 | + if (str_contains($image, '<svg')) { |
|
| 66 | + return $image; |
|
| 67 | + } |
|
| 68 | + return false; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -74,28 +74,28 @@ discard block |
||
| 74 | 74 | * @return array|bool |
| 75 | 75 | */ |
| 76 | 76 | function svg_lire_balise_svg($fichier) { |
| 77 | - if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 82 | - $pe = stripos($debut_fichier, '>', $ps); |
|
| 83 | - $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 84 | - |
|
| 85 | - if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 86 | - if (!function_exists('extraire_attribut')) { |
|
| 87 | - include_spip('inc/filtres'); |
|
| 88 | - } |
|
| 89 | - $attributs = []; |
|
| 90 | - foreach ($matches[1] as $att) { |
|
| 91 | - $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return [$balise_svg, $attributs]; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - return false; |
|
| 77 | + if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 82 | + $pe = stripos($debut_fichier, '>', $ps); |
|
| 83 | + $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 84 | + |
|
| 85 | + if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 86 | + if (!function_exists('extraire_attribut')) { |
|
| 87 | + include_spip('inc/filtres'); |
|
| 88 | + } |
|
| 89 | + $attributs = []; |
|
| 90 | + foreach ($matches[1] as $att) { |
|
| 91 | + $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return [$balise_svg, $attributs]; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + return false; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -105,12 +105,12 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | function svg_lire_attributs($img) { |
| 107 | 107 | |
| 108 | - if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 109 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 110 | - return $attributs; |
|
| 111 | - } |
|
| 108 | + if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 109 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 110 | + return $attributs; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - return false; |
|
| 113 | + return false; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -120,19 +120,19 @@ discard block |
||
| 120 | 120 | * @return bool|float|int |
| 121 | 121 | */ |
| 122 | 122 | function svg_dimension_to_pixels($dimension, $precision = 2) { |
| 123 | - if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 124 | - return match (strtolower($m[2])) { |
|
| 125 | - '%' => false, |
|
| 126 | - 'em' => round($m[1] * 16, $precision), |
|
| 127 | - 'ex' => round($m[1] * 16, $precision), |
|
| 128 | - 'pc' => round($m[1] * 16, $precision), |
|
| 129 | - 'cm' => round($m[1] * 96 / 2.54, $precision), |
|
| 130 | - 'mm' => round($m[1] * 96 / 25.4, $precision), |
|
| 131 | - 'in' => round($m[1] * 96, $precision), |
|
| 132 | - default => $m[1], |
|
| 133 | - }; |
|
| 134 | - } |
|
| 135 | - return false; |
|
| 123 | + if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 124 | + return match (strtolower($m[2])) { |
|
| 125 | + '%' => false, |
|
| 126 | + 'em' => round($m[1] * 16, $precision), |
|
| 127 | + 'ex' => round($m[1] * 16, $precision), |
|
| 128 | + 'pc' => round($m[1] * 16, $precision), |
|
| 129 | + 'cm' => round($m[1] * 96 / 2.54, $precision), |
|
| 130 | + 'mm' => round($m[1] * 96 / 25.4, $precision), |
|
| 131 | + 'in' => round($m[1] * 96, $precision), |
|
| 132 | + default => $m[1], |
|
| 133 | + }; |
|
| 134 | + } |
|
| 135 | + return false; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -143,14 +143,14 @@ discard block |
||
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | 145 | function svg_change_balise_svg($svg, $old_balise_svg, $attributs) { |
| 146 | - $new_balise_svg = '<svg'; |
|
| 147 | - foreach ($attributs as $k => $v) { |
|
| 148 | - $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 149 | - } |
|
| 150 | - $new_balise_svg .= '>'; |
|
| 151 | - |
|
| 152 | - $p = strpos($svg, $old_balise_svg); |
|
| 153 | - return substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 146 | + $new_balise_svg = '<svg'; |
|
| 147 | + foreach ($attributs as $k => $v) { |
|
| 148 | + $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 149 | + } |
|
| 150 | + $new_balise_svg .= '>'; |
|
| 151 | + |
|
| 152 | + $p = strpos($svg, $old_balise_svg); |
|
| 153 | + return substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -162,15 +162,15 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | function svg_insert_shapes($svg, $shapes, $start = true) { |
| 164 | 164 | |
| 165 | - if ($start === false || $start === 'end') { |
|
| 166 | - $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 167 | - } |
|
| 168 | - else { |
|
| 169 | - $p = stripos($svg, '<svg'); |
|
| 170 | - $p = strpos($svg, '>', $p); |
|
| 171 | - $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 172 | - } |
|
| 173 | - return $svg; |
|
| 165 | + if ($start === false || $start === 'end') { |
|
| 166 | + $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 167 | + } |
|
| 168 | + else { |
|
| 169 | + $p = stripos($svg, '<svg'); |
|
| 170 | + $p = strpos($svg, '>', $p); |
|
| 171 | + $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 172 | + } |
|
| 173 | + return $svg; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -183,12 +183,12 @@ discard block |
||
| 183 | 183 | * @return string |
| 184 | 184 | */ |
| 185 | 185 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 186 | - $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 187 | - $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 188 | - $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 189 | - $g = "<g clip-path=\"url(#$id)\">"; |
|
| 190 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 191 | - return svg_insert_shapes($svg, '</g>', false); |
|
| 186 | + $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 187 | + $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 188 | + $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 189 | + $g = "<g clip-path=\"url(#$id)\">"; |
|
| 190 | + $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 191 | + return svg_insert_shapes($svg, '</g>', false); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -199,20 +199,20 @@ discard block |
||
| 199 | 199 | * @return bool|string |
| 200 | 200 | */ |
| 201 | 201 | function svg_redimensionner($img, $new_width, $new_height) { |
| 202 | - if ( |
|
| 203 | - ($svg = svg_charger($img)) |
|
| 204 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 205 | - ) { |
|
| 206 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 207 | - if (!isset($attributs['viewBox'])) { |
|
| 208 | - $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 209 | - } |
|
| 210 | - $attributs['width'] = (string) $new_width; |
|
| 211 | - $attributs['height'] = (string) $new_height; |
|
| 212 | - return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - return $img; |
|
| 202 | + if ( |
|
| 203 | + ($svg = svg_charger($img)) |
|
| 204 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 205 | + ) { |
|
| 206 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 207 | + if (!isset($attributs['viewBox'])) { |
|
| 208 | + $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 209 | + } |
|
| 210 | + $attributs['width'] = (string) $new_width; |
|
| 211 | + $attributs['height'] = (string) $new_height; |
|
| 212 | + return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + return $img; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -221,14 +221,14 @@ discard block |
||
| 221 | 221 | * @return string |
| 222 | 222 | */ |
| 223 | 223 | function svg_couleur_to_hexa($couleur) { |
| 224 | - if (str_starts_with($couleur, 'rgb(')) { |
|
| 225 | - $c = explode(',', substr($couleur, 4)); |
|
| 226 | - $couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]); |
|
| 227 | - } |
|
| 228 | - else { |
|
| 229 | - $couleur = couleur_html_to_hex($couleur); |
|
| 230 | - } |
|
| 231 | - return '#' . ltrim($couleur, '#'); |
|
| 224 | + if (str_starts_with($couleur, 'rgb(')) { |
|
| 225 | + $c = explode(',', substr($couleur, 4)); |
|
| 226 | + $couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]); |
|
| 227 | + } |
|
| 228 | + else { |
|
| 229 | + $couleur = couleur_html_to_hex($couleur); |
|
| 230 | + } |
|
| 231 | + return '#' . ltrim($couleur, '#'); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
@@ -237,11 +237,11 @@ discard block |
||
| 237 | 237 | * @return array |
| 238 | 238 | */ |
| 239 | 239 | function svg_couleur_to_rgb($couleur) { |
| 240 | - if (str_starts_with($couleur, 'rgb(')) { |
|
| 241 | - $c = explode(',', substr($couleur, 4)); |
|
| 242 | - return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]]; |
|
| 243 | - } |
|
| 244 | - return _couleur_hex_to_dec($couleur); |
|
| 240 | + if (str_starts_with($couleur, 'rgb(')) { |
|
| 241 | + $c = explode(',', substr($couleur, 4)); |
|
| 242 | + return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]]; |
|
| 243 | + } |
|
| 244 | + return _couleur_hex_to_dec($couleur); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
@@ -251,80 +251,80 @@ discard block |
||
| 251 | 251 | * @return array |
| 252 | 252 | */ |
| 253 | 253 | function svg_getimagesize_from_attr($attributs) { |
| 254 | - $width = 350; // default width |
|
| 255 | - $height = 150; // default height |
|
| 256 | - |
|
| 257 | - $viewBox = "0 0 $width $height"; |
|
| 258 | - if (isset($attributs['viewBox'])) { |
|
| 259 | - $viewBox = $attributs['viewBox']; |
|
| 260 | - $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 261 | - } |
|
| 262 | - // et on la convertit en px |
|
| 263 | - $viewBox = explode(' ', $viewBox); |
|
| 264 | - $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 265 | - if (!$viewBox[2]) { |
|
| 266 | - $viewBox[2] = $width; |
|
| 267 | - } |
|
| 268 | - if (!$viewBox[3]) { |
|
| 269 | - $viewBox[3] = $height; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - $coeff = 1; |
|
| 273 | - if ( |
|
| 274 | - isset($attributs['width']) |
|
| 275 | - && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 276 | - ) { |
|
| 277 | - $width = $w; |
|
| 278 | - // si on avait pas de viewBox, la construire a partir de ce width |
|
| 279 | - if (empty($attributs['viewBox'])) { |
|
| 280 | - $viewBox[2] = $width; |
|
| 281 | - // si pas de height valide, on suppose l'image carree |
|
| 282 | - $viewBox[3] = $width; |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - else { |
|
| 286 | - // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 287 | - $width = $viewBox[2]; |
|
| 288 | - if ($width < 1) { |
|
| 289 | - $coeff = max($coeff, 1000); |
|
| 290 | - } |
|
| 291 | - elseif ($width < 10) { |
|
| 292 | - $coeff = max($coeff, 100); |
|
| 293 | - } |
|
| 294 | - elseif ($width < 100) { |
|
| 295 | - $coeff = max($coeff, 10); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - if ( |
|
| 299 | - isset($attributs['height']) |
|
| 300 | - && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 301 | - ) { |
|
| 302 | - $height = $h; |
|
| 303 | - // si on avait pas de viewBox, la construire a partir de ce height |
|
| 304 | - if (empty($attributs['viewBox'])) { |
|
| 305 | - $viewBox[3] = $height; |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - else { |
|
| 309 | - $height = $viewBox[3]; |
|
| 310 | - if ($height < 1) { |
|
| 311 | - $coeff = max($coeff, 1000); |
|
| 312 | - } |
|
| 313 | - elseif ($height < 10) { |
|
| 314 | - $coeff = max($coeff, 100); |
|
| 315 | - } |
|
| 316 | - elseif ($height < 100) { |
|
| 317 | - $coeff = max($coeff, 10); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - // arrondir le width et height en pixel in fine |
|
| 322 | - $width = round($coeff * $width); |
|
| 323 | - $height = round($coeff * $height); |
|
| 324 | - |
|
| 325 | - $viewBox = implode(' ', $viewBox); |
|
| 326 | - |
|
| 327 | - return [$width, $height, $viewBox]; |
|
| 254 | + $width = 350; // default width |
|
| 255 | + $height = 150; // default height |
|
| 256 | + |
|
| 257 | + $viewBox = "0 0 $width $height"; |
|
| 258 | + if (isset($attributs['viewBox'])) { |
|
| 259 | + $viewBox = $attributs['viewBox']; |
|
| 260 | + $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 261 | + } |
|
| 262 | + // et on la convertit en px |
|
| 263 | + $viewBox = explode(' ', $viewBox); |
|
| 264 | + $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 265 | + if (!$viewBox[2]) { |
|
| 266 | + $viewBox[2] = $width; |
|
| 267 | + } |
|
| 268 | + if (!$viewBox[3]) { |
|
| 269 | + $viewBox[3] = $height; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + $coeff = 1; |
|
| 273 | + if ( |
|
| 274 | + isset($attributs['width']) |
|
| 275 | + && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 276 | + ) { |
|
| 277 | + $width = $w; |
|
| 278 | + // si on avait pas de viewBox, la construire a partir de ce width |
|
| 279 | + if (empty($attributs['viewBox'])) { |
|
| 280 | + $viewBox[2] = $width; |
|
| 281 | + // si pas de height valide, on suppose l'image carree |
|
| 282 | + $viewBox[3] = $width; |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + else { |
|
| 286 | + // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 287 | + $width = $viewBox[2]; |
|
| 288 | + if ($width < 1) { |
|
| 289 | + $coeff = max($coeff, 1000); |
|
| 290 | + } |
|
| 291 | + elseif ($width < 10) { |
|
| 292 | + $coeff = max($coeff, 100); |
|
| 293 | + } |
|
| 294 | + elseif ($width < 100) { |
|
| 295 | + $coeff = max($coeff, 10); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + if ( |
|
| 299 | + isset($attributs['height']) |
|
| 300 | + && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 301 | + ) { |
|
| 302 | + $height = $h; |
|
| 303 | + // si on avait pas de viewBox, la construire a partir de ce height |
|
| 304 | + if (empty($attributs['viewBox'])) { |
|
| 305 | + $viewBox[3] = $height; |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + else { |
|
| 309 | + $height = $viewBox[3]; |
|
| 310 | + if ($height < 1) { |
|
| 311 | + $coeff = max($coeff, 1000); |
|
| 312 | + } |
|
| 313 | + elseif ($height < 10) { |
|
| 314 | + $coeff = max($coeff, 100); |
|
| 315 | + } |
|
| 316 | + elseif ($height < 100) { |
|
| 317 | + $coeff = max($coeff, 10); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + // arrondir le width et height en pixel in fine |
|
| 322 | + $width = round($coeff * $width); |
|
| 323 | + $height = round($coeff * $height); |
|
| 324 | + |
|
| 325 | + $viewBox = implode(' ', $viewBox); |
|
| 326 | + |
|
| 327 | + return [$width, $height, $viewBox]; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -340,23 +340,23 @@ discard block |
||
| 340 | 340 | * @return string |
| 341 | 341 | */ |
| 342 | 342 | function svg_force_viewBox_px($img, $force_width_and_height = false) { |
| 343 | - if ( |
|
| 344 | - ($svg = svg_charger($img)) |
|
| 345 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 346 | - ) { |
|
| 347 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 348 | - |
|
| 349 | - [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 350 | - |
|
| 351 | - if ($force_width_and_height) { |
|
| 352 | - $attributs['width'] = $width; |
|
| 353 | - $attributs['height'] = $height; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - $attributs['viewBox'] = $viewBox; |
|
| 357 | - return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 358 | - } |
|
| 359 | - return $img; |
|
| 343 | + if ( |
|
| 344 | + ($svg = svg_charger($img)) |
|
| 345 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 346 | + ) { |
|
| 347 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 348 | + |
|
| 349 | + [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 350 | + |
|
| 351 | + if ($force_width_and_height) { |
|
| 352 | + $attributs['width'] = $width; |
|
| 353 | + $attributs['height'] = $height; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + $attributs['viewBox'] = $viewBox; |
|
| 357 | + return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 358 | + } |
|
| 359 | + return $img; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -365,13 +365,13 @@ discard block |
||
| 365 | 365 | * @return array|mixed |
| 366 | 366 | */ |
| 367 | 367 | function svg_extract_couleurs($img) { |
| 368 | - if ( |
|
| 369 | - ($svg = svg_charger($img)) |
|
| 370 | - && preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches) |
|
| 371 | - ) { |
|
| 372 | - return $matches[0]; |
|
| 373 | - } |
|
| 374 | - return []; |
|
| 368 | + if ( |
|
| 369 | + ($svg = svg_charger($img)) |
|
| 370 | + && preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches) |
|
| 371 | + ) { |
|
| 372 | + return $matches[0]; |
|
| 373 | + } |
|
| 374 | + return []; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -382,58 +382,58 @@ discard block |
||
| 382 | 382 | * @return bool|string |
| 383 | 383 | */ |
| 384 | 384 | function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') { |
| 385 | - if ( |
|
| 386 | - ($svg = svg_force_viewBox_px($img)) |
|
| 387 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 388 | - ) { |
|
| 389 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 390 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 391 | - |
|
| 392 | - $viewport_w = $new_width; |
|
| 393 | - $viewport_h = $new_height; |
|
| 394 | - $viewport_ox = $offset_width; |
|
| 395 | - $viewport_oy = $offset_height; |
|
| 396 | - |
|
| 397 | - // si on a un width/height qui rescale, il faut rescaler |
|
| 398 | - if ( |
|
| 399 | - isset($attributs['width']) |
|
| 400 | - && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 401 | - && isset($attributs['height']) |
|
| 402 | - && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 403 | - ) { |
|
| 404 | - $xscale = $viewBox[2] / $w; |
|
| 405 | - $viewport_w = round($viewport_w * $xscale, 2); |
|
| 406 | - $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 407 | - $yscale = $viewBox[3] / $h; |
|
| 408 | - $viewport_h = round($viewport_h * $yscale, 2); |
|
| 409 | - $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - if ($viewport_w > $viewBox[2] || $viewport_h > $viewBox[3]) { |
|
| 413 | - $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - // maintenant on redefinit la viewBox |
|
| 417 | - $viewBox[0] += $viewport_ox; |
|
| 418 | - $viewBox[1] += $viewport_oy; |
|
| 419 | - $viewBox[2] = $viewport_w; |
|
| 420 | - $viewBox[3] = $viewport_h; |
|
| 421 | - |
|
| 422 | - $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 423 | - $attributs['width'] = (string) $new_width; |
|
| 424 | - $attributs['height'] = (string) $new_height; |
|
| 425 | - |
|
| 426 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 427 | - |
|
| 428 | - // ajouter un background |
|
| 429 | - if ($background_color && $background_color !== 'transparent') { |
|
| 430 | - $svg = svg_ajouter_background($svg, $background_color); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - return $svg; |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return $img; |
|
| 385 | + if ( |
|
| 386 | + ($svg = svg_force_viewBox_px($img)) |
|
| 387 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 388 | + ) { |
|
| 389 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 390 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 391 | + |
|
| 392 | + $viewport_w = $new_width; |
|
| 393 | + $viewport_h = $new_height; |
|
| 394 | + $viewport_ox = $offset_width; |
|
| 395 | + $viewport_oy = $offset_height; |
|
| 396 | + |
|
| 397 | + // si on a un width/height qui rescale, il faut rescaler |
|
| 398 | + if ( |
|
| 399 | + isset($attributs['width']) |
|
| 400 | + && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 401 | + && isset($attributs['height']) |
|
| 402 | + && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 403 | + ) { |
|
| 404 | + $xscale = $viewBox[2] / $w; |
|
| 405 | + $viewport_w = round($viewport_w * $xscale, 2); |
|
| 406 | + $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 407 | + $yscale = $viewBox[3] / $h; |
|
| 408 | + $viewport_h = round($viewport_h * $yscale, 2); |
|
| 409 | + $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + if ($viewport_w > $viewBox[2] || $viewport_h > $viewBox[3]) { |
|
| 413 | + $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + // maintenant on redefinit la viewBox |
|
| 417 | + $viewBox[0] += $viewport_ox; |
|
| 418 | + $viewBox[1] += $viewport_oy; |
|
| 419 | + $viewBox[2] = $viewport_w; |
|
| 420 | + $viewBox[3] = $viewport_h; |
|
| 421 | + |
|
| 422 | + $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 423 | + $attributs['width'] = (string) $new_width; |
|
| 424 | + $attributs['height'] = (string) $new_height; |
|
| 425 | + |
|
| 426 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 427 | + |
|
| 428 | + // ajouter un background |
|
| 429 | + if ($background_color && $background_color !== 'transparent') { |
|
| 430 | + $svg = svg_ajouter_background($svg, $background_color); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + return $svg; |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return $img; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | /** |
@@ -443,26 +443,26 @@ discard block |
||
| 443 | 443 | * @return bool|string |
| 444 | 444 | */ |
| 445 | 445 | function svg_ajouter_background($img, $background_color) { |
| 446 | - if ( |
|
| 447 | - ($svg = svg_charger($img)) |
|
| 448 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 449 | - ) { |
|
| 450 | - if ($background_color && $background_color !== 'transparent') { |
|
| 451 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 452 | - |
|
| 453 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 454 | - if (isset($attributs['viewBox'])) { |
|
| 455 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 456 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 457 | - } |
|
| 458 | - else { |
|
| 459 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 460 | - } |
|
| 461 | - $svg = svg_insert_shapes($svg, $rect); |
|
| 462 | - } |
|
| 463 | - return $svg; |
|
| 464 | - } |
|
| 465 | - return $img; |
|
| 446 | + if ( |
|
| 447 | + ($svg = svg_charger($img)) |
|
| 448 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 449 | + ) { |
|
| 450 | + if ($background_color && $background_color !== 'transparent') { |
|
| 451 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 452 | + |
|
| 453 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 454 | + if (isset($attributs['viewBox'])) { |
|
| 455 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 456 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 457 | + } |
|
| 458 | + else { |
|
| 459 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 460 | + } |
|
| 461 | + $svg = svg_insert_shapes($svg, $rect); |
|
| 462 | + } |
|
| 463 | + return $svg; |
|
| 464 | + } |
|
| 465 | + return $img; |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | |
@@ -473,26 +473,26 @@ discard block |
||
| 473 | 473 | * @return bool|string |
| 474 | 474 | */ |
| 475 | 475 | function svg_ajouter_voile($img, $background_color, $opacity) { |
| 476 | - if ( |
|
| 477 | - ($svg = svg_charger($img)) |
|
| 478 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 479 | - ) { |
|
| 480 | - if ($background_color && $background_color !== 'transparent') { |
|
| 481 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 482 | - |
|
| 483 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 484 | - if (isset($attributs['viewBox'])) { |
|
| 485 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 486 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 487 | - } |
|
| 488 | - else { |
|
| 489 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 490 | - } |
|
| 491 | - $svg = svg_insert_shapes($svg, $rect, false); |
|
| 492 | - } |
|
| 493 | - return $svg; |
|
| 494 | - } |
|
| 495 | - return $img; |
|
| 476 | + if ( |
|
| 477 | + ($svg = svg_charger($img)) |
|
| 478 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 479 | + ) { |
|
| 480 | + if ($background_color && $background_color !== 'transparent') { |
|
| 481 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 482 | + |
|
| 483 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 484 | + if (isset($attributs['viewBox'])) { |
|
| 485 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 486 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 487 | + } |
|
| 488 | + else { |
|
| 489 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 490 | + } |
|
| 491 | + $svg = svg_insert_shapes($svg, $rect, false); |
|
| 492 | + } |
|
| 493 | + return $svg; |
|
| 494 | + } |
|
| 495 | + return $img; |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | |
@@ -503,27 +503,27 @@ discard block |
||
| 503 | 503 | * @return bool|string |
| 504 | 504 | */ |
| 505 | 505 | function svg_transformer($img, $attributs) { |
| 506 | - if ( |
|
| 507 | - ($svg = svg_charger($img)) |
|
| 508 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 509 | - ) { |
|
| 510 | - if ($attributs) { |
|
| 511 | - [$balise_svg, ] = $svg_infos; |
|
| 512 | - $g = '<g'; |
|
| 513 | - foreach ($attributs as $k => $v) { |
|
| 514 | - if (strlen($v)) { |
|
| 515 | - $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - if (strlen($g) > 2) { |
|
| 519 | - $g .= '>'; |
|
| 520 | - $svg = svg_insert_shapes($svg, $g); |
|
| 521 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - return $svg; |
|
| 525 | - } |
|
| 526 | - return $img; |
|
| 506 | + if ( |
|
| 507 | + ($svg = svg_charger($img)) |
|
| 508 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 509 | + ) { |
|
| 510 | + if ($attributs) { |
|
| 511 | + [$balise_svg, ] = $svg_infos; |
|
| 512 | + $g = '<g'; |
|
| 513 | + foreach ($attributs as $k => $v) { |
|
| 514 | + if (strlen($v)) { |
|
| 515 | + $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + if (strlen($g) > 2) { |
|
| 519 | + $g .= '>'; |
|
| 520 | + $svg = svg_insert_shapes($svg, $g); |
|
| 521 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + return $svg; |
|
| 525 | + } |
|
| 526 | + return $img; |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /** |
@@ -534,21 +534,21 @@ discard block |
||
| 534 | 534 | * @return bool|string |
| 535 | 535 | */ |
| 536 | 536 | function svg_apply_filter($img, $filter_def) { |
| 537 | - if ( |
|
| 538 | - ($svg = svg_charger($img)) |
|
| 539 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 540 | - ) { |
|
| 541 | - if ($filter_def) { |
|
| 542 | - [$balise_svg, ] = $svg_infos; |
|
| 543 | - $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 544 | - $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 545 | - $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 546 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 547 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 548 | - } |
|
| 549 | - return $svg; |
|
| 550 | - } |
|
| 551 | - return $img; |
|
| 537 | + if ( |
|
| 538 | + ($svg = svg_charger($img)) |
|
| 539 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 540 | + ) { |
|
| 541 | + if ($filter_def) { |
|
| 542 | + [$balise_svg, ] = $svg_infos; |
|
| 543 | + $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 544 | + $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 545 | + $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 546 | + $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 547 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 548 | + } |
|
| 549 | + return $svg; |
|
| 550 | + } |
|
| 551 | + return $img; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | /** |
@@ -558,8 +558,8 @@ discard block |
||
| 558 | 558 | * @return string |
| 559 | 559 | */ |
| 560 | 560 | function svg_filter_blur($img, $blur_width) { |
| 561 | - $blur_width = (int) $blur_width; |
|
| 562 | - return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 561 | + $blur_width = (int) $blur_width; |
|
| 562 | + return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | /** |
@@ -569,10 +569,10 @@ discard block |
||
| 569 | 569 | * @return bool|string |
| 570 | 570 | */ |
| 571 | 571 | function svg_filter_grayscale($img, $intensity) { |
| 572 | - $value = round(1.0 - $intensity, 2); |
|
| 573 | - //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 574 | - $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 575 | - return svg_apply_filter($img, $filter); |
|
| 572 | + $value = round(1.0 - $intensity, 2); |
|
| 573 | + //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 574 | + $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 575 | + return svg_apply_filter($img, $filter); |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | /** |
@@ -582,8 +582,8 @@ discard block |
||
| 582 | 582 | * @return bool|string |
| 583 | 583 | */ |
| 584 | 584 | function svg_filter_sepia($img, $intensity) { |
| 585 | - $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 586 | - return svg_apply_filter($img, $filter); |
|
| 585 | + $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 586 | + return svg_apply_filter($img, $filter); |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | /** |
@@ -593,30 +593,30 @@ discard block |
||
| 593 | 593 | * @return bool|string |
| 594 | 594 | */ |
| 595 | 595 | function svg_flip($img, $HorV) { |
| 596 | - if ( |
|
| 597 | - ($svg = svg_force_viewBox_px($img)) |
|
| 598 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 599 | - ) { |
|
| 600 | - [$balise_svg, $atts] = $svg_infos; |
|
| 601 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 602 | - |
|
| 603 | - if (!in_array($HorV, ['h', 'H'])) { |
|
| 604 | - $transform = 'scale(-1,1)'; |
|
| 605 | - |
|
| 606 | - $x = (int) $viewBox[0] + (int) ($viewBox[2] / 2); |
|
| 607 | - $mx = -$x; |
|
| 608 | - $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 609 | - } |
|
| 610 | - else { |
|
| 611 | - $transform = 'scale(1,-1)'; |
|
| 612 | - |
|
| 613 | - $y = (int) $viewBox[1] + (int) ($viewBox[3] / 2); |
|
| 614 | - $my = -$y; |
|
| 615 | - $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 616 | - } |
|
| 617 | - return svg_transformer($svg, ['transform' => $transform]); |
|
| 618 | - } |
|
| 619 | - return $img; |
|
| 596 | + if ( |
|
| 597 | + ($svg = svg_force_viewBox_px($img)) |
|
| 598 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 599 | + ) { |
|
| 600 | + [$balise_svg, $atts] = $svg_infos; |
|
| 601 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 602 | + |
|
| 603 | + if (!in_array($HorV, ['h', 'H'])) { |
|
| 604 | + $transform = 'scale(-1,1)'; |
|
| 605 | + |
|
| 606 | + $x = (int) $viewBox[0] + (int) ($viewBox[2] / 2); |
|
| 607 | + $mx = -$x; |
|
| 608 | + $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 609 | + } |
|
| 610 | + else { |
|
| 611 | + $transform = 'scale(1,-1)'; |
|
| 612 | + |
|
| 613 | + $y = (int) $viewBox[1] + (int) ($viewBox[3] / 2); |
|
| 614 | + $my = -$y; |
|
| 615 | + $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 616 | + } |
|
| 617 | + return svg_transformer($svg, ['transform' => $transform]); |
|
| 618 | + } |
|
| 619 | + return $img; |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -630,19 +630,19 @@ discard block |
||
| 630 | 630 | * @return bool|string |
| 631 | 631 | */ |
| 632 | 632 | function svg_rotate($img, $angle, $center_x, $center_y) { |
| 633 | - if ( |
|
| 634 | - ($svg = svg_force_viewBox_px($img)) |
|
| 635 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 636 | - ) { |
|
| 637 | - [$balise_svg, $atts] = $svg_infos; |
|
| 638 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 639 | - |
|
| 640 | - $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 641 | - $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 642 | - |
|
| 643 | - return svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 644 | - } |
|
| 645 | - return $img; |
|
| 633 | + if ( |
|
| 634 | + ($svg = svg_force_viewBox_px($img)) |
|
| 635 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 636 | + ) { |
|
| 637 | + [$balise_svg, $atts] = $svg_infos; |
|
| 638 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 639 | + |
|
| 640 | + $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 641 | + $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 642 | + |
|
| 643 | + return svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 644 | + } |
|
| 645 | + return $img; |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | /** |
@@ -654,40 +654,40 @@ discard block |
||
| 654 | 654 | * @return bool|mixed|string |
| 655 | 655 | */ |
| 656 | 656 | function svg_filtrer_couleurs($img, $callback_filter) { |
| 657 | - if ( |
|
| 658 | - ($svg = svg_force_viewBox_px($img)) |
|
| 659 | - && ($colors = svg_extract_couleurs($svg)) |
|
| 660 | - ) { |
|
| 661 | - $colors = array_unique($colors); |
|
| 662 | - |
|
| 663 | - $short = []; |
|
| 664 | - $long = []; |
|
| 665 | - while (count($colors)) { |
|
| 666 | - $c = array_shift($colors); |
|
| 667 | - if (strlen($c) == 4) { |
|
| 668 | - $short[] = $c; |
|
| 669 | - } |
|
| 670 | - else { |
|
| 671 | - $long[] = $c; |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - $colors = [...$long, ...$short]; |
|
| 676 | - $new_colors = []; |
|
| 677 | - $colors = array_flip($colors); |
|
| 678 | - foreach ($colors as $c => $k) { |
|
| 679 | - $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - foreach ($colors as $original => $replace) { |
|
| 684 | - $new = svg_couleur_to_hexa($original); |
|
| 685 | - $new_colors[$replace] = $callback_filter($new); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 689 | - |
|
| 690 | - return str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 691 | - } |
|
| 692 | - return $img; |
|
| 657 | + if ( |
|
| 658 | + ($svg = svg_force_viewBox_px($img)) |
|
| 659 | + && ($colors = svg_extract_couleurs($svg)) |
|
| 660 | + ) { |
|
| 661 | + $colors = array_unique($colors); |
|
| 662 | + |
|
| 663 | + $short = []; |
|
| 664 | + $long = []; |
|
| 665 | + while (count($colors)) { |
|
| 666 | + $c = array_shift($colors); |
|
| 667 | + if (strlen($c) == 4) { |
|
| 668 | + $short[] = $c; |
|
| 669 | + } |
|
| 670 | + else { |
|
| 671 | + $long[] = $c; |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + $colors = [...$long, ...$short]; |
|
| 676 | + $new_colors = []; |
|
| 677 | + $colors = array_flip($colors); |
|
| 678 | + foreach ($colors as $c => $k) { |
|
| 679 | + $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + foreach ($colors as $original => $replace) { |
|
| 684 | + $new = svg_couleur_to_hexa($original); |
|
| 685 | + $new_colors[$replace] = $callback_filter($new); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 689 | + |
|
| 690 | + return str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 691 | + } |
|
| 692 | + return $img; |
|
| 693 | 693 | } |
@@ -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 | } |