@@ -26,85 +26,85 @@ discard block |
||
| 26 | 26 | * ``` |
| 27 | 27 | */ |
| 28 | 28 | function spip_logger(?string $name = null): LoggerInterface { |
| 29 | - /* @var array<string,LoggerInterface> */ |
|
| 30 | - static $loggers = []; |
|
| 31 | - /* @var ?Factory */ |
|
| 32 | - static $loggerFactory = null; |
|
| 33 | - |
|
| 34 | - $name ??= 'spip'; |
|
| 35 | - |
|
| 36 | - if ($loggerFactory === null) { |
|
| 37 | - $spipToMonologLevels = [ |
|
| 38 | - Level::Emergency, // _LOG_HS |
|
| 39 | - Level::Alert, // _LOG_ALERTE_ROUGE |
|
| 40 | - Level::Critical, // _LOG_CRITIQUE |
|
| 41 | - Level::Error, // _LOG_ERREUR |
|
| 42 | - Level::Warning, // _LOG_AVERTISSEMENT |
|
| 43 | - Level::Notice, // _LOG_INFO_IMPORTANTE |
|
| 44 | - Level::Info, // _LOG_INFO |
|
| 45 | - Level::Debug, // _LOG_DEBUG |
|
| 46 | - ]; |
|
| 47 | - |
|
| 48 | - $config = [ |
|
| 49 | - 'siteDir' => _ROOT_RACINE, |
|
| 50 | - 'filesystem' => new Filesystem(), |
|
| 51 | - // max log par hit |
|
| 52 | - 'max_log' => defined('_MAX_LOG') ? constant('_MAX_LOG') : null, |
|
| 53 | - // pour indiquer le chemin du fichier qui envoie le log |
|
| 54 | - 'fileline' => defined('_LOG_FILELINE') ? constant('_LOG_FILELINE') : null, |
|
| 55 | - // échappement des log |
|
| 56 | - 'brut' => defined('_LOG_BRUT') ? constant('_LOG_BRUT') : null, |
|
| 57 | - // à quel level on commence à logguer |
|
| 58 | - 'max_level' => (function() use ($spipToMonologLevels): Level { |
|
| 59 | - if (!defined('_LOG_FILTRE_GRAVITE')) { |
|
| 60 | - return Level::Notice; |
|
| 61 | - } |
|
| 62 | - $level = constant('_LOG_FILTRE_GRAVITE'); |
|
| 63 | - if ($level instanceof Level) { |
|
| 64 | - return $level; |
|
| 65 | - } |
|
| 66 | - if (isset($spipToMonologLevels[$level])) { |
|
| 67 | - return $spipToMonologLevels[$level]; |
|
| 68 | - } |
|
| 69 | - return match($level) { |
|
| 70 | - LogLevel::EMERGENCY => Level::Emergency, |
|
| 71 | - LogLevel::ALERT => Level::Alert, |
|
| 72 | - LogLevel::CRITICAL => Level::Critical, |
|
| 73 | - LogLevel::CRITICAL => Level::Error, |
|
| 74 | - LogLevel::CRITICAL => Level::Warning, |
|
| 75 | - LogLevel::CRITICAL => Level::Notice, |
|
| 76 | - LogLevel::CRITICAL => Level::Info, |
|
| 77 | - LogLevel::CRITICAL => Level::Debug, |
|
| 78 | - default => Level::Notice, |
|
| 79 | - }; |
|
| 80 | - })(), |
|
| 81 | - // rotation: nombre de fichiers |
|
| 82 | - 'max_files' => $GLOBALS['nombre_de_logs'] ??= 4, |
|
| 83 | - // rotation: taille max d’un fichier |
|
| 84 | - 'max_size' => ($GLOBALS['taille_des_logs'] ??= 100) * 1024, |
|
| 85 | - // chemin du fichier de log |
|
| 86 | - 'log_path' => (function() { |
|
| 87 | - $log_dir = defined('_DIR_LOG') ? str_replace(_DIR_RACINE, '', constant('_DIR_LOG')) : 'tmp/log/'; |
|
| 88 | - $log_file = defined('_FILE_LOG') ? constant('_FILE_LOG') : 'spip'; |
|
| 89 | - $log_suffix = defined('_FILE_LOG_SUFFIX') ? constant('_FILE_LOG_SUFFIX') : '.log'; |
|
| 90 | - |
|
| 91 | - $log_file = str_replace('spip', '%s', $log_file); |
|
| 92 | - return sprintf('%s%s%s', $log_dir, $log_file, $log_suffix); |
|
| 93 | - })(), |
|
| 94 | - ]; |
|
| 95 | - $env = getenv('APP_ENV') ?? 'prod'; |
|
| 96 | - if ($env === 'dev') { |
|
| 97 | - $config = [ |
|
| 98 | - ...$config, |
|
| 99 | - 'fileline' => true, |
|
| 100 | - 'max_level' => Level::Debug, |
|
| 101 | - ]; |
|
| 102 | - } |
|
| 103 | - $config = array_filter($config); |
|
| 104 | - |
|
| 105 | - $loggerFactory = new Factory(new Config(...$config), new LineFormatter()); |
|
| 106 | - unset($args, $env, $spipToMonologLevels); |
|
| 107 | - } |
|
| 29 | + /* @var array<string,LoggerInterface> */ |
|
| 30 | + static $loggers = []; |
|
| 31 | + /* @var ?Factory */ |
|
| 32 | + static $loggerFactory = null; |
|
| 33 | + |
|
| 34 | + $name ??= 'spip'; |
|
| 35 | + |
|
| 36 | + if ($loggerFactory === null) { |
|
| 37 | + $spipToMonologLevels = [ |
|
| 38 | + Level::Emergency, // _LOG_HS |
|
| 39 | + Level::Alert, // _LOG_ALERTE_ROUGE |
|
| 40 | + Level::Critical, // _LOG_CRITIQUE |
|
| 41 | + Level::Error, // _LOG_ERREUR |
|
| 42 | + Level::Warning, // _LOG_AVERTISSEMENT |
|
| 43 | + Level::Notice, // _LOG_INFO_IMPORTANTE |
|
| 44 | + Level::Info, // _LOG_INFO |
|
| 45 | + Level::Debug, // _LOG_DEBUG |
|
| 46 | + ]; |
|
| 47 | + |
|
| 48 | + $config = [ |
|
| 49 | + 'siteDir' => _ROOT_RACINE, |
|
| 50 | + 'filesystem' => new Filesystem(), |
|
| 51 | + // max log par hit |
|
| 52 | + 'max_log' => defined('_MAX_LOG') ? constant('_MAX_LOG') : null, |
|
| 53 | + // pour indiquer le chemin du fichier qui envoie le log |
|
| 54 | + 'fileline' => defined('_LOG_FILELINE') ? constant('_LOG_FILELINE') : null, |
|
| 55 | + // échappement des log |
|
| 56 | + 'brut' => defined('_LOG_BRUT') ? constant('_LOG_BRUT') : null, |
|
| 57 | + // à quel level on commence à logguer |
|
| 58 | + 'max_level' => (function() use ($spipToMonologLevels): Level { |
|
| 59 | + if (!defined('_LOG_FILTRE_GRAVITE')) { |
|
| 60 | + return Level::Notice; |
|
| 61 | + } |
|
| 62 | + $level = constant('_LOG_FILTRE_GRAVITE'); |
|
| 63 | + if ($level instanceof Level) { |
|
| 64 | + return $level; |
|
| 65 | + } |
|
| 66 | + if (isset($spipToMonologLevels[$level])) { |
|
| 67 | + return $spipToMonologLevels[$level]; |
|
| 68 | + } |
|
| 69 | + return match($level) { |
|
| 70 | + LogLevel::EMERGENCY => Level::Emergency, |
|
| 71 | + LogLevel::ALERT => Level::Alert, |
|
| 72 | + LogLevel::CRITICAL => Level::Critical, |
|
| 73 | + LogLevel::CRITICAL => Level::Error, |
|
| 74 | + LogLevel::CRITICAL => Level::Warning, |
|
| 75 | + LogLevel::CRITICAL => Level::Notice, |
|
| 76 | + LogLevel::CRITICAL => Level::Info, |
|
| 77 | + LogLevel::CRITICAL => Level::Debug, |
|
| 78 | + default => Level::Notice, |
|
| 79 | + }; |
|
| 80 | + })(), |
|
| 81 | + // rotation: nombre de fichiers |
|
| 82 | + 'max_files' => $GLOBALS['nombre_de_logs'] ??= 4, |
|
| 83 | + // rotation: taille max d’un fichier |
|
| 84 | + 'max_size' => ($GLOBALS['taille_des_logs'] ??= 100) * 1024, |
|
| 85 | + // chemin du fichier de log |
|
| 86 | + 'log_path' => (function() { |
|
| 87 | + $log_dir = defined('_DIR_LOG') ? str_replace(_DIR_RACINE, '', constant('_DIR_LOG')) : 'tmp/log/'; |
|
| 88 | + $log_file = defined('_FILE_LOG') ? constant('_FILE_LOG') : 'spip'; |
|
| 89 | + $log_suffix = defined('_FILE_LOG_SUFFIX') ? constant('_FILE_LOG_SUFFIX') : '.log'; |
|
| 90 | + |
|
| 91 | + $log_file = str_replace('spip', '%s', $log_file); |
|
| 92 | + return sprintf('%s%s%s', $log_dir, $log_file, $log_suffix); |
|
| 93 | + })(), |
|
| 94 | + ]; |
|
| 95 | + $env = getenv('APP_ENV') ?? 'prod'; |
|
| 96 | + if ($env === 'dev') { |
|
| 97 | + $config = [ |
|
| 98 | + ...$config, |
|
| 99 | + 'fileline' => true, |
|
| 100 | + 'max_level' => Level::Debug, |
|
| 101 | + ]; |
|
| 102 | + } |
|
| 103 | + $config = array_filter($config); |
|
| 104 | + |
|
| 105 | + $loggerFactory = new Factory(new Config(...$config), new LineFormatter()); |
|
| 106 | + unset($args, $env, $spipToMonologLevels); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | return $loggers[$name] ??= $loggerFactory->createFromFilename($name); |
| 110 | 110 | } |
@@ -135,18 +135,18 @@ discard block |
||
| 135 | 135 | function spip_log($message, $name = null): void |
| 136 | 136 | { |
| 137 | 137 | static $spipToMonologLevels = [ |
| 138 | - Level::Emergency, // _LOG_HS |
|
| 139 | - Level::Alert, // _LOG_ALERTE_ROUGE |
|
| 140 | - Level::Critical, // _LOG_CRITIQUE |
|
| 141 | - Level::Error, // _LOG_ERREUR |
|
| 142 | - Level::Warning, // _LOG_AVERTISSEMENT |
|
| 143 | - Level::Notice, // _LOG_INFO_IMPORTANTE |
|
| 144 | - Level::Info, // _LOG_INFO |
|
| 145 | - Level::Debug, // _LOG_DEBUG |
|
| 138 | + Level::Emergency, // _LOG_HS |
|
| 139 | + Level::Alert, // _LOG_ALERTE_ROUGE |
|
| 140 | + Level::Critical, // _LOG_CRITIQUE |
|
| 141 | + Level::Error, // _LOG_ERREUR |
|
| 142 | + Level::Warning, // _LOG_AVERTISSEMENT |
|
| 143 | + Level::Notice, // _LOG_INFO_IMPORTANTE |
|
| 144 | + Level::Info, // _LOG_INFO |
|
| 145 | + Level::Debug, // _LOG_DEBUG |
|
| 146 | 146 | ]; |
| 147 | 147 | |
| 148 | - # Éviter de trop polluer les logs de dépréciation |
|
| 149 | - static $deprecated = []; |
|
| 148 | + # Éviter de trop polluer les logs de dépréciation |
|
| 149 | + static $deprecated = []; |
|
| 150 | 150 | |
| 151 | 151 | preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string) $name, $regs); |
| 152 | 152 | $logFile = 'spip'; |
@@ -154,46 +154,46 @@ discard block |
||
| 154 | 154 | $logFile = $regs[1]; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - if (!isset($regs[2])) { |
|
| 158 | - $level = Level::Info; |
|
| 159 | - } else { |
|
| 160 | - $level = $spipToMonologLevels[intval($regs[2])] ?? Level::Info; |
|
| 161 | - } |
|
| 157 | + if (!isset($regs[2])) { |
|
| 158 | + $level = Level::Info; |
|
| 159 | + } else { |
|
| 160 | + $level = $spipToMonologLevels[intval($regs[2])] ?? Level::Info; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - $logger = spip_logger($logFile); |
|
| 164 | - $logger->log($level, preg_replace( |
|
| 163 | + $logger = spip_logger($logFile); |
|
| 164 | + $logger->log($level, preg_replace( |
|
| 165 | 165 | "/\n*$/", |
| 166 | 166 | "\n", |
| 167 | 167 | is_string($message) ? $message : print_r($message, true) |
| 168 | 168 | )); |
| 169 | 169 | |
| 170 | 170 | |
| 171 | - if (!array_key_exists($logFile, $deprecated)) { |
|
| 172 | - $deprecated[$logFile] = true; |
|
| 173 | - if ($logFile === 'spip') { |
|
| 174 | - trigger_deprecation( |
|
| 175 | - 'spip', |
|
| 176 | - '5.0', |
|
| 177 | - sprintf( |
|
| 178 | - 'spip_log(\'message\') function is deprecated ; use spip_logger().' |
|
| 179 | - . ' Example: spip_logger()->info(\'message\').', |
|
| 180 | - $logFile, |
|
| 181 | - $logFile, |
|
| 182 | - ) |
|
| 183 | - ); |
|
| 184 | - } else { |
|
| 185 | - trigger_deprecation( |
|
| 186 | - 'spip', |
|
| 187 | - '5.0', |
|
| 188 | - sprintf( |
|
| 189 | - 'spip_log(\'message\', \'%s\') function is deprecated ; use spip_logger().' |
|
| 190 | - . ' Example: spip_logger(\'%s\')->info(\'message\').', |
|
| 191 | - $logFile, |
|
| 192 | - $logFile, |
|
| 193 | - ) |
|
| 194 | - ); |
|
| 195 | - } |
|
| 196 | - } |
|
| 171 | + if (!array_key_exists($logFile, $deprecated)) { |
|
| 172 | + $deprecated[$logFile] = true; |
|
| 173 | + if ($logFile === 'spip') { |
|
| 174 | + trigger_deprecation( |
|
| 175 | + 'spip', |
|
| 176 | + '5.0', |
|
| 177 | + sprintf( |
|
| 178 | + 'spip_log(\'message\') function is deprecated ; use spip_logger().' |
|
| 179 | + . ' Example: spip_logger()->info(\'message\').', |
|
| 180 | + $logFile, |
|
| 181 | + $logFile, |
|
| 182 | + ) |
|
| 183 | + ); |
|
| 184 | + } else { |
|
| 185 | + trigger_deprecation( |
|
| 186 | + 'spip', |
|
| 187 | + '5.0', |
|
| 188 | + sprintf( |
|
| 189 | + 'spip_log(\'message\', \'%s\') function is deprecated ; use spip_logger().' |
|
| 190 | + . ' Example: spip_logger(\'%s\')->info(\'message\').', |
|
| 191 | + $logFile, |
|
| 192 | + $logFile, |
|
| 193 | + ) |
|
| 194 | + ); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | |
@@ -205,6 +205,6 @@ discard block |
||
| 205 | 205 | * @param array $opt Tableau d'options |
| 206 | 206 | **/ |
| 207 | 207 | function journal($phrase, $opt = []) { |
| 208 | - $journal = charger_fonction('journal', 'inc'); |
|
| 209 | - $journal($phrase, $opt); |
|
| 208 | + $journal = charger_fonction('journal', 'inc'); |
|
| 209 | + $journal($phrase, $opt); |
|
| 210 | 210 | } |
@@ -36,13 +36,13 @@ discard block |
||
| 36 | 36 | if ($loggerFactory === null) { |
| 37 | 37 | $spipToMonologLevels = [ |
| 38 | 38 | Level::Emergency, // _LOG_HS |
| 39 | - Level::Alert, // _LOG_ALERTE_ROUGE |
|
| 40 | - Level::Critical, // _LOG_CRITIQUE |
|
| 41 | - Level::Error, // _LOG_ERREUR |
|
| 42 | - Level::Warning, // _LOG_AVERTISSEMENT |
|
| 43 | - Level::Notice, // _LOG_INFO_IMPORTANTE |
|
| 44 | - Level::Info, // _LOG_INFO |
|
| 45 | - Level::Debug, // _LOG_DEBUG |
|
| 39 | + Level::Alert, // _LOG_ALERTE_ROUGE |
|
| 40 | + Level::Critical, // _LOG_CRITIQUE |
|
| 41 | + Level::Error, // _LOG_ERREUR |
|
| 42 | + Level::Warning, // _LOG_AVERTISSEMENT |
|
| 43 | + Level::Notice, // _LOG_INFO_IMPORTANTE |
|
| 44 | + Level::Info, // _LOG_INFO |
|
| 45 | + Level::Debug, // _LOG_DEBUG |
|
| 46 | 46 | ]; |
| 47 | 47 | |
| 48 | 48 | $config = [ |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | // échappement des log |
| 56 | 56 | 'brut' => defined('_LOG_BRUT') ? constant('_LOG_BRUT') : null, |
| 57 | 57 | // à quel level on commence à logguer |
| 58 | - 'max_level' => (function() use ($spipToMonologLevels): Level { |
|
| 58 | + 'max_level' => (function() use ($spipToMonologLevels) : Level { |
|
| 59 | 59 | if (!defined('_LOG_FILTRE_GRAVITE')) { |
| 60 | 60 | return Level::Notice; |
| 61 | 61 | } |
@@ -136,13 +136,13 @@ discard block |
||
| 136 | 136 | { |
| 137 | 137 | static $spipToMonologLevels = [ |
| 138 | 138 | Level::Emergency, // _LOG_HS |
| 139 | - Level::Alert, // _LOG_ALERTE_ROUGE |
|
| 140 | - Level::Critical, // _LOG_CRITIQUE |
|
| 141 | - Level::Error, // _LOG_ERREUR |
|
| 142 | - Level::Warning, // _LOG_AVERTISSEMENT |
|
| 143 | - Level::Notice, // _LOG_INFO_IMPORTANTE |
|
| 144 | - Level::Info, // _LOG_INFO |
|
| 145 | - Level::Debug, // _LOG_DEBUG |
|
| 139 | + Level::Alert, // _LOG_ALERTE_ROUGE |
|
| 140 | + Level::Critical, // _LOG_CRITIQUE |
|
| 141 | + Level::Error, // _LOG_ERREUR |
|
| 142 | + Level::Warning, // _LOG_AVERTISSEMENT |
|
| 143 | + Level::Notice, // _LOG_INFO_IMPORTANTE |
|
| 144 | + Level::Info, // _LOG_INFO |
|
| 145 | + Level::Debug, // _LOG_DEBUG |
|
| 146 | 146 | ]; |
| 147 | 147 | |
| 148 | 148 | # Éviter de trop polluer les logs de dépréciation |
@@ -8,11 +8,11 @@ discard block |
||
| 8 | 8 | * @return string |
| 9 | 9 | */ |
| 10 | 10 | function quote_amp($u) { |
| 11 | - return preg_replace( |
|
| 12 | - '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i', |
|
| 13 | - '&', |
|
| 14 | - $u |
|
| 15 | - ); |
|
| 11 | + return preg_replace( |
|
| 12 | + '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i', |
|
| 13 | + '&', |
|
| 14 | + $u |
|
| 15 | + ); |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | /** |
@@ -20,23 +20,22 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * On est sur le web, on exclut certains protocoles, |
| 22 | 22 | * notamment 'file://', 'php://' et d'autres… |
| 23 | - |
|
| 24 | 23 | * @param string $url |
| 25 | 24 | * @return bool |
| 26 | 25 | */ |
| 27 | 26 | function tester_url_absolue($url) { |
| 28 | - $url = trim($url ?? ''); |
|
| 29 | - if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) { |
|
| 30 | - if ( |
|
| 31 | - isset($m[1]) |
|
| 32 | - && ($p = strtolower(rtrim($m[1], ':'))) |
|
| 33 | - && in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip']) |
|
| 34 | - ) { |
|
| 35 | - return false; |
|
| 36 | - } |
|
| 37 | - return true; |
|
| 38 | - } |
|
| 39 | - return false; |
|
| 27 | + $url = trim($url ?? ''); |
|
| 28 | + if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) { |
|
| 29 | + if ( |
|
| 30 | + isset($m[1]) |
|
| 31 | + && ($p = strtolower(rtrim($m[1], ':'))) |
|
| 32 | + && in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip']) |
|
| 33 | + ) { |
|
| 34 | + return false; |
|
| 35 | + } |
|
| 36 | + return true; |
|
| 37 | + } |
|
| 38 | + return false; |
|
| 40 | 39 | } |
| 41 | 40 | |
| 42 | 41 | /** |
@@ -58,100 +57,100 @@ discard block |
||
| 58 | 57 | * @return string URL |
| 59 | 58 | */ |
| 60 | 59 | function parametre_url($url, $c, $v = null, $sep = '&') { |
| 61 | - // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 62 | - if (str_contains($c, '|') && is_null($v)) { |
|
| 63 | - return null; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // lever l'#ancre |
|
| 67 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 68 | - $url = $r[1]; |
|
| 69 | - $ancre = $r[2]; |
|
| 70 | - } else { |
|
| 71 | - $ancre = ''; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // eclater |
|
| 75 | - $url = preg_split(',[?]|&|&,', $url); |
|
| 76 | - |
|
| 77 | - // recuperer la base |
|
| 78 | - $a = array_shift($url); |
|
| 79 | - if (!$a) { |
|
| 80 | - $a = './'; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // preparer la regexp de maniere securisee |
|
| 84 | - $regexp = explode('|', $c); |
|
| 85 | - foreach ($regexp as $r => $e) { |
|
| 86 | - $regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\d\[\]-],', '', $e)); |
|
| 87 | - } |
|
| 88 | - $regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,'; |
|
| 89 | - $ajouts = array_flip(explode('|', $c)); |
|
| 90 | - $u = is_array($v) ? $v : rawurlencode((string) $v); |
|
| 91 | - $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
|
| 92 | - $v_read = null; |
|
| 93 | - // lire les variables et agir |
|
| 94 | - foreach ($url as $n => $val) { |
|
| 95 | - if (preg_match($regexp, urldecode($val), $r)) { |
|
| 96 | - $r = array_pad($r, 3, null); |
|
| 97 | - if ($v === null) { |
|
| 98 | - // c'est un tableau, on memorise les valeurs |
|
| 99 | - if (str_ends_with($r[1], '[]')) { |
|
| 100 | - if (!$v_read) { |
|
| 101 | - $v_read = []; |
|
| 102 | - } |
|
| 103 | - $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 104 | - } // c'est un scalaire, on retourne direct |
|
| 105 | - else { |
|
| 106 | - return $r[2] ? substr($r[2], 1) : ''; |
|
| 107 | - } |
|
| 108 | - } // suppression |
|
| 109 | - elseif (!$testv) { |
|
| 110 | - unset($url[$n]); |
|
| 111 | - } |
|
| 112 | - // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 113 | - // pour un tableau ce sera fait dans la prochaine boucle |
|
| 114 | - elseif (!str_ends_with($r[1], '[]')) { |
|
| 115 | - $url[$n] = $r[1] . '=' . $u; |
|
| 116 | - unset($ajouts[$r[1]]); |
|
| 117 | - } |
|
| 118 | - // Pour les tableaux on laisse tomber les valeurs de |
|
| 119 | - // départ, on remplira à l'étape suivante |
|
| 120 | - else { |
|
| 121 | - unset($url[$n]); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // traiter les parametres pas encore trouves |
|
| 127 | - if ( |
|
| 128 | - $v === null |
|
| 129 | - && ($args = func_get_args()) |
|
| 130 | - && count($args) == 2 |
|
| 131 | - ) { |
|
| 132 | - return $v_read; // rien trouve ou un tableau |
|
| 133 | - } elseif ($testv) { |
|
| 134 | - foreach ($ajouts as $k => $n) { |
|
| 135 | - if (!is_array($v)) { |
|
| 136 | - $url[] = $k . '=' . $u; |
|
| 137 | - } else { |
|
| 138 | - $id = (str_ends_with($k, '[]')) ? $k : ($k . '[]'); |
|
| 139 | - foreach ($v as $w) { |
|
| 140 | - $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - // eliminer les vides |
|
| 147 | - $url = array_filter($url); |
|
| 148 | - |
|
| 149 | - // recomposer l'adresse |
|
| 150 | - if ($url) { |
|
| 151 | - $a .= '?' . join($sep, $url); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return $a . $ancre; |
|
| 60 | + // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 61 | + if (str_contains($c, '|') && is_null($v)) { |
|
| 62 | + return null; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + // lever l'#ancre |
|
| 66 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 67 | + $url = $r[1]; |
|
| 68 | + $ancre = $r[2]; |
|
| 69 | + } else { |
|
| 70 | + $ancre = ''; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // eclater |
|
| 74 | + $url = preg_split(',[?]|&|&,', $url); |
|
| 75 | + |
|
| 76 | + // recuperer la base |
|
| 77 | + $a = array_shift($url); |
|
| 78 | + if (!$a) { |
|
| 79 | + $a = './'; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + // preparer la regexp de maniere securisee |
|
| 83 | + $regexp = explode('|', $c); |
|
| 84 | + foreach ($regexp as $r => $e) { |
|
| 85 | + $regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\d\[\]-],', '', $e)); |
|
| 86 | + } |
|
| 87 | + $regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,'; |
|
| 88 | + $ajouts = array_flip(explode('|', $c)); |
|
| 89 | + $u = is_array($v) ? $v : rawurlencode((string) $v); |
|
| 90 | + $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
|
| 91 | + $v_read = null; |
|
| 92 | + // lire les variables et agir |
|
| 93 | + foreach ($url as $n => $val) { |
|
| 94 | + if (preg_match($regexp, urldecode($val), $r)) { |
|
| 95 | + $r = array_pad($r, 3, null); |
|
| 96 | + if ($v === null) { |
|
| 97 | + // c'est un tableau, on memorise les valeurs |
|
| 98 | + if (str_ends_with($r[1], '[]')) { |
|
| 99 | + if (!$v_read) { |
|
| 100 | + $v_read = []; |
|
| 101 | + } |
|
| 102 | + $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 103 | + } // c'est un scalaire, on retourne direct |
|
| 104 | + else { |
|
| 105 | + return $r[2] ? substr($r[2], 1) : ''; |
|
| 106 | + } |
|
| 107 | + } // suppression |
|
| 108 | + elseif (!$testv) { |
|
| 109 | + unset($url[$n]); |
|
| 110 | + } |
|
| 111 | + // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 112 | + // pour un tableau ce sera fait dans la prochaine boucle |
|
| 113 | + elseif (!str_ends_with($r[1], '[]')) { |
|
| 114 | + $url[$n] = $r[1] . '=' . $u; |
|
| 115 | + unset($ajouts[$r[1]]); |
|
| 116 | + } |
|
| 117 | + // Pour les tableaux on laisse tomber les valeurs de |
|
| 118 | + // départ, on remplira à l'étape suivante |
|
| 119 | + else { |
|
| 120 | + unset($url[$n]); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + // traiter les parametres pas encore trouves |
|
| 126 | + if ( |
|
| 127 | + $v === null |
|
| 128 | + && ($args = func_get_args()) |
|
| 129 | + && count($args) == 2 |
|
| 130 | + ) { |
|
| 131 | + return $v_read; // rien trouve ou un tableau |
|
| 132 | + } elseif ($testv) { |
|
| 133 | + foreach ($ajouts as $k => $n) { |
|
| 134 | + if (!is_array($v)) { |
|
| 135 | + $url[] = $k . '=' . $u; |
|
| 136 | + } else { |
|
| 137 | + $id = (str_ends_with($k, '[]')) ? $k : ($k . '[]'); |
|
| 138 | + foreach ($v as $w) { |
|
| 139 | + $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // eliminer les vides |
|
| 146 | + $url = array_filter($url); |
|
| 147 | + |
|
| 148 | + // recomposer l'adresse |
|
| 149 | + if ($url) { |
|
| 150 | + $a .= '?' . join($sep, $url); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $a . $ancre; |
|
| 155 | 154 | } |
| 156 | 155 | |
| 157 | 156 | /** |
@@ -166,22 +165,22 @@ discard block |
||
| 166 | 165 | * @uses translitteration() |
| 167 | 166 | */ |
| 168 | 167 | function ancre_url(string $url, ?string $ancre = ''): string { |
| 169 | - $ancre ??= ''; |
|
| 170 | - // lever l'#ancre |
|
| 171 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 172 | - $url = $r[1]; |
|
| 173 | - } |
|
| 174 | - if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 175 | - if (!function_exists('translitteration')) { |
|
| 176 | - include_spip('inc/charsets'); |
|
| 177 | - } |
|
| 178 | - $ancre = preg_replace( |
|
| 179 | - ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'], |
|
| 180 | - ['', '-'], |
|
| 181 | - translitteration($ancre) |
|
| 182 | - ); |
|
| 183 | - } |
|
| 184 | - return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 168 | + $ancre ??= ''; |
|
| 169 | + // lever l'#ancre |
|
| 170 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 171 | + $url = $r[1]; |
|
| 172 | + } |
|
| 173 | + if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 174 | + if (!function_exists('translitteration')) { |
|
| 175 | + include_spip('inc/charsets'); |
|
| 176 | + } |
|
| 177 | + $ancre = preg_replace( |
|
| 178 | + ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'], |
|
| 179 | + ['', '-'], |
|
| 180 | + translitteration($ancre) |
|
| 181 | + ); |
|
| 182 | + } |
|
| 183 | + return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 185 | 184 | } |
| 186 | 185 | |
| 187 | 186 | /** |
@@ -191,16 +190,16 @@ discard block |
||
| 191 | 190 | * @return string |
| 192 | 191 | */ |
| 193 | 192 | function nettoyer_uri($reset = null) { |
| 194 | - static $done = false; |
|
| 195 | - static $propre = ''; |
|
| 196 | - if (!is_null($reset)) { |
|
| 197 | - return $propre = $reset; |
|
| 198 | - } |
|
| 199 | - if ($done) { |
|
| 200 | - return $propre; |
|
| 201 | - } |
|
| 202 | - $done = true; |
|
| 203 | - return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 193 | + static $done = false; |
|
| 194 | + static $propre = ''; |
|
| 195 | + if (!is_null($reset)) { |
|
| 196 | + return $propre = $reset; |
|
| 197 | + } |
|
| 198 | + if ($done) { |
|
| 199 | + return $propre; |
|
| 200 | + } |
|
| 201 | + $done = true; |
|
| 202 | + return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 204 | 203 | } |
| 205 | 204 | |
| 206 | 205 | /** |
@@ -215,36 +214,36 @@ discard block |
||
| 215 | 214 | * @return string |
| 216 | 215 | */ |
| 217 | 216 | function nettoyer_uri_var($request_uri) { |
| 218 | - static $preg_nettoyer; |
|
| 219 | - if (!defined('_CONTEXTE_IGNORE_LISTE_VARIABLES')) { |
|
| 220 | - /** @var array<string> Liste (regexp) de noms de variables à ignorer d’une URI */ |
|
| 221 | - define('_CONTEXTE_IGNORE_LISTE_VARIABLES', ['^var_', '^PHPSESSID$', '^fbclid$', '^utm_']); |
|
| 222 | - } |
|
| 223 | - if (empty($preg_nettoyer)) { |
|
| 224 | - $preg_nettoyer_vars = _CONTEXTE_IGNORE_LISTE_VARIABLES; |
|
| 225 | - foreach ($preg_nettoyer_vars as &$var) { |
|
| 226 | - if (str_starts_with($var, '^')) { |
|
| 227 | - $var = substr($var, 1); |
|
| 228 | - } else { |
|
| 229 | - $var = '[^=&]*' . $var; |
|
| 230 | - } |
|
| 231 | - if (str_ends_with($var, '$')) { |
|
| 232 | - $var = substr($var, 0, -1); |
|
| 233 | - } else { |
|
| 234 | - $var .= '[^=&]*'; |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - $preg_nettoyer = ',([?&])(' . implode('|', $preg_nettoyer_vars) . ')=[^&]*(&|$),i'; |
|
| 238 | - } |
|
| 239 | - if (empty($request_uri)) { |
|
| 240 | - return $request_uri; |
|
| 241 | - } |
|
| 242 | - $uri1 = $request_uri; |
|
| 243 | - do { |
|
| 244 | - $uri = $uri1; |
|
| 245 | - $uri1 = preg_replace($preg_nettoyer, '\1', $uri); |
|
| 246 | - } while ($uri <> $uri1); |
|
| 247 | - return rtrim($uri1, '?&'); |
|
| 217 | + static $preg_nettoyer; |
|
| 218 | + if (!defined('_CONTEXTE_IGNORE_LISTE_VARIABLES')) { |
|
| 219 | + /** @var array<string> Liste (regexp) de noms de variables à ignorer d’une URI */ |
|
| 220 | + define('_CONTEXTE_IGNORE_LISTE_VARIABLES', ['^var_', '^PHPSESSID$', '^fbclid$', '^utm_']); |
|
| 221 | + } |
|
| 222 | + if (empty($preg_nettoyer)) { |
|
| 223 | + $preg_nettoyer_vars = _CONTEXTE_IGNORE_LISTE_VARIABLES; |
|
| 224 | + foreach ($preg_nettoyer_vars as &$var) { |
|
| 225 | + if (str_starts_with($var, '^')) { |
|
| 226 | + $var = substr($var, 1); |
|
| 227 | + } else { |
|
| 228 | + $var = '[^=&]*' . $var; |
|
| 229 | + } |
|
| 230 | + if (str_ends_with($var, '$')) { |
|
| 231 | + $var = substr($var, 0, -1); |
|
| 232 | + } else { |
|
| 233 | + $var .= '[^=&]*'; |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + $preg_nettoyer = ',([?&])(' . implode('|', $preg_nettoyer_vars) . ')=[^&]*(&|$),i'; |
|
| 237 | + } |
|
| 238 | + if (empty($request_uri)) { |
|
| 239 | + return $request_uri; |
|
| 240 | + } |
|
| 241 | + $uri1 = $request_uri; |
|
| 242 | + do { |
|
| 243 | + $uri = $uri1; |
|
| 244 | + $uri1 = preg_replace($preg_nettoyer, '\1', $uri); |
|
| 245 | + } while ($uri <> $uri1); |
|
| 246 | + return rtrim($uri1, '?&'); |
|
| 248 | 247 | } |
| 249 | 248 | |
| 250 | 249 | |
@@ -258,49 +257,49 @@ discard block |
||
| 258 | 257 | * URL vers soi-même |
| 259 | 258 | **/ |
| 260 | 259 | function self($amp = '&', $root = false) { |
| 261 | - $url = nettoyer_uri(); |
|
| 262 | - if ( |
|
| 263 | - !$root |
|
| 264 | - && ( |
|
| 265 | - // si pas de profondeur on peut tronquer |
|
| 266 | - $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 267 | - // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 268 | - || defined('_SET_HTML_BASE') && !_SET_HTML_BASE |
|
| 269 | - ) |
|
| 270 | - ) { |
|
| 271 | - $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 272 | - } |
|
| 273 | - // ajouter le cas echeant les variables _POST['id_...'] |
|
| 274 | - foreach ($_POST as $v => $c) { |
|
| 275 | - if (str_starts_with($v, 'id_')) { |
|
| 276 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - // supprimer les variables sans interet |
|
| 281 | - if (test_espace_prive()) { |
|
| 282 | - $url = preg_replace(',([?&])(' |
|
| 283 | - . 'lang|show_docs|' |
|
| 284 | - . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 285 | - $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 286 | - $url = preg_replace(',[&]$,', '\1', $url); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - // eviter les hacks |
|
| 290 | - include_spip('inc/filtres_mini'); |
|
| 291 | - $url = spip_htmlspecialchars($url); |
|
| 292 | - |
|
| 293 | - $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url); |
|
| 294 | - |
|
| 295 | - // & ? |
|
| 296 | - if ($amp != '&') { |
|
| 297 | - $url = str_replace('&', $amp, $url); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - // Si ca demarre par ? ou vide, donner './' |
|
| 301 | - $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 302 | - |
|
| 303 | - return $url; |
|
| 260 | + $url = nettoyer_uri(); |
|
| 261 | + if ( |
|
| 262 | + !$root |
|
| 263 | + && ( |
|
| 264 | + // si pas de profondeur on peut tronquer |
|
| 265 | + $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 266 | + // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 267 | + || defined('_SET_HTML_BASE') && !_SET_HTML_BASE |
|
| 268 | + ) |
|
| 269 | + ) { |
|
| 270 | + $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 271 | + } |
|
| 272 | + // ajouter le cas echeant les variables _POST['id_...'] |
|
| 273 | + foreach ($_POST as $v => $c) { |
|
| 274 | + if (str_starts_with($v, 'id_')) { |
|
| 275 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + // supprimer les variables sans interet |
|
| 280 | + if (test_espace_prive()) { |
|
| 281 | + $url = preg_replace(',([?&])(' |
|
| 282 | + . 'lang|show_docs|' |
|
| 283 | + . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 284 | + $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 285 | + $url = preg_replace(',[&]$,', '\1', $url); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + // eviter les hacks |
|
| 289 | + include_spip('inc/filtres_mini'); |
|
| 290 | + $url = spip_htmlspecialchars($url); |
|
| 291 | + |
|
| 292 | + $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url); |
|
| 293 | + |
|
| 294 | + // & ? |
|
| 295 | + if ($amp != '&') { |
|
| 296 | + $url = str_replace('&', $amp, $url); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + // Si ca demarre par ? ou vide, donner './' |
|
| 300 | + $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 301 | + |
|
| 302 | + return $url; |
|
| 304 | 303 | } |
| 305 | 304 | |
| 306 | 305 | /** |
@@ -325,48 +324,48 @@ discard block |
||
| 325 | 324 | * url codee ou fonction de decodage |
| 326 | 325 | */ |
| 327 | 326 | function generer_objet_url($id, string $entite, string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string { |
| 328 | - if ($public === null) { |
|
| 329 | - $public = !test_espace_prive(); |
|
| 330 | - } |
|
| 331 | - $id = intval($id); |
|
| 332 | - $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 333 | - |
|
| 334 | - if (!$public) { |
|
| 335 | - if (!$entite) { |
|
| 336 | - return ''; |
|
| 337 | - } |
|
| 338 | - if (!function_exists('generer_objet_url_ecrire')) { |
|
| 339 | - include_spip('inc/urls'); |
|
| 340 | - } |
|
| 341 | - $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect); |
|
| 342 | - } else { |
|
| 343 | - $f = charger_fonction_url('objet', $type ?? ''); |
|
| 344 | - |
|
| 345 | - // @deprecated si $entite='', on veut la fonction de passage URL ==> id |
|
| 346 | - // @see charger_fonction_url |
|
| 347 | - if (!$entite) { |
|
| 348 | - return $f; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // mais d'abord il faut tester le cas des urls sur une |
|
| 352 | - // base distante |
|
| 353 | - if ( |
|
| 354 | - $connect |
|
| 355 | - && ($g = charger_fonction('connect', 'urls', true)) |
|
| 356 | - ) { |
|
| 357 | - $f = $g; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect); |
|
| 361 | - } |
|
| 362 | - if ($res) { |
|
| 363 | - return $res; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // On a ete gentil mais la .... |
|
| 367 | - spip_logger()->error("generer_objet_url: entite $entite " . ($public ? "($f)" : '') . " inconnue $type $public $connect"); |
|
| 368 | - |
|
| 369 | - return ''; |
|
| 327 | + if ($public === null) { |
|
| 328 | + $public = !test_espace_prive(); |
|
| 329 | + } |
|
| 330 | + $id = intval($id); |
|
| 331 | + $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 332 | + |
|
| 333 | + if (!$public) { |
|
| 334 | + if (!$entite) { |
|
| 335 | + return ''; |
|
| 336 | + } |
|
| 337 | + if (!function_exists('generer_objet_url_ecrire')) { |
|
| 338 | + include_spip('inc/urls'); |
|
| 339 | + } |
|
| 340 | + $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect); |
|
| 341 | + } else { |
|
| 342 | + $f = charger_fonction_url('objet', $type ?? ''); |
|
| 343 | + |
|
| 344 | + // @deprecated si $entite='', on veut la fonction de passage URL ==> id |
|
| 345 | + // @see charger_fonction_url |
|
| 346 | + if (!$entite) { |
|
| 347 | + return $f; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + // mais d'abord il faut tester le cas des urls sur une |
|
| 351 | + // base distante |
|
| 352 | + if ( |
|
| 353 | + $connect |
|
| 354 | + && ($g = charger_fonction('connect', 'urls', true)) |
|
| 355 | + ) { |
|
| 356 | + $f = $g; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect); |
|
| 360 | + } |
|
| 361 | + if ($res) { |
|
| 362 | + return $res; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + // On a ete gentil mais la .... |
|
| 366 | + spip_logger()->error("generer_objet_url: entite $entite " . ($public ? "($f)" : '') . " inconnue $type $public $connect"); |
|
| 367 | + |
|
| 368 | + return ''; |
|
| 370 | 369 | } |
| 371 | 370 | |
| 372 | 371 | /** |
@@ -374,11 +373,11 @@ discard block |
||
| 374 | 373 | * @see generer_objet_url |
| 375 | 374 | */ |
| 376 | 375 | function generer_url_entite($id = 0, $entite = '', $args = '', $ancre = '', $public = null, $type = null) { |
| 377 | - trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url'); |
|
| 378 | - if ($public && is_string($public)) { |
|
| 379 | - return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public); |
|
| 380 | - } |
|
| 381 | - return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? ''); |
|
| 376 | + trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url'); |
|
| 377 | + if ($public && is_string($public)) { |
|
| 378 | + return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public); |
|
| 379 | + } |
|
| 380 | + return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? ''); |
|
| 382 | 381 | } |
| 383 | 382 | |
| 384 | 383 | /** |
@@ -386,19 +385,19 @@ discard block |
||
| 386 | 385 | * @param int|string|null $id |
| 387 | 386 | */ |
| 388 | 387 | function generer_objet_url_ecrire_edit($id, string $entite, string $args = '', string $ancre = ''): string { |
| 389 | - $id = intval($id); |
|
| 390 | - $exec = objet_info($entite, 'url_edit'); |
|
| 391 | - $url = generer_url_ecrire($exec, $args); |
|
| 392 | - if (intval($id)) { |
|
| 393 | - $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 394 | - } else { |
|
| 395 | - $url = parametre_url($url, 'new', 'oui'); |
|
| 396 | - } |
|
| 397 | - if ($ancre) { |
|
| 398 | - $url = ancre_url($url, $ancre); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - return $url; |
|
| 388 | + $id = intval($id); |
|
| 389 | + $exec = objet_info($entite, 'url_edit'); |
|
| 390 | + $url = generer_url_ecrire($exec, $args); |
|
| 391 | + if (intval($id)) { |
|
| 392 | + $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 393 | + } else { |
|
| 394 | + $url = parametre_url($url, 'new', 'oui'); |
|
| 395 | + } |
|
| 396 | + if ($ancre) { |
|
| 397 | + $url = ancre_url($url, $ancre); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + return $url; |
|
| 402 | 401 | } |
| 403 | 402 | |
| 404 | 403 | /** |
@@ -406,19 +405,19 @@ discard block |
||
| 406 | 405 | * @see generer_objet_url_ecrire_edit |
| 407 | 406 | */ |
| 408 | 407 | function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') { |
| 409 | - trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_ecrire_edit'); |
|
| 410 | - return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre); |
|
| 408 | + trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_ecrire_edit'); |
|
| 409 | + return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre); |
|
| 411 | 410 | } |
| 412 | 411 | |
| 413 | 412 | |
| 414 | 413 | function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) { |
| 415 | - include_spip('base/connect_sql'); |
|
| 416 | - $id_type = id_table_objet($entite, $public); |
|
| 414 | + include_spip('base/connect_sql'); |
|
| 415 | + $id_type = id_table_objet($entite, $public); |
|
| 417 | 416 | |
| 418 | - return _DIR_RACINE . get_spip_script('./') |
|
| 419 | - . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 420 | - . (!$args ? '' : "&$args") |
|
| 421 | - . (!$ancre ? '' : "#$ancre"); |
|
| 417 | + return _DIR_RACINE . get_spip_script('./') |
|
| 418 | + . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 419 | + . (!$args ? '' : "&$args") |
|
| 420 | + . (!$ancre ? '' : "#$ancre"); |
|
| 422 | 421 | } |
| 423 | 422 | |
| 424 | 423 | |
@@ -429,18 +428,18 @@ discard block |
||
| 429 | 428 | * @return string |
| 430 | 429 | */ |
| 431 | 430 | function urlencode_1738($url) { |
| 432 | - if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 433 | - $uri = ''; |
|
| 434 | - for ($i = 0; $i < strlen($url); $i++) { |
|
| 435 | - if (ord($a = $url[$i]) > 127) { |
|
| 436 | - $a = rawurlencode($a); |
|
| 437 | - } |
|
| 438 | - $uri .= $a; |
|
| 439 | - } |
|
| 440 | - $url = $uri; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - return quote_amp($url); |
|
| 431 | + if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 432 | + $uri = ''; |
|
| 433 | + for ($i = 0; $i < strlen($url); $i++) { |
|
| 434 | + if (ord($a = $url[$i]) > 127) { |
|
| 435 | + $a = rawurlencode($a); |
|
| 436 | + } |
|
| 437 | + $uri .= $a; |
|
| 438 | + } |
|
| 439 | + $url = $uri; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + return quote_amp($url); |
|
| 444 | 443 | } |
| 445 | 444 | |
| 446 | 445 | /** |
@@ -449,14 +448,14 @@ discard block |
||
| 449 | 448 | * @param int|string|null $id |
| 450 | 449 | */ |
| 451 | 450 | function generer_objet_url_absolue($id = 0, string $entite = '', string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string { |
| 452 | - $id = intval($id); |
|
| 453 | - $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect); |
|
| 454 | - if (!preg_match(',^\w+:,', $h)) { |
|
| 455 | - include_spip('inc/filtres_mini'); |
|
| 456 | - $h = url_absolue($h); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - return $h; |
|
| 451 | + $id = intval($id); |
|
| 452 | + $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect); |
|
| 453 | + if (!preg_match(',^\w+:,', $h)) { |
|
| 454 | + include_spip('inc/filtres_mini'); |
|
| 455 | + $h = url_absolue($h); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + return $h; |
|
| 460 | 459 | } |
| 461 | 460 | |
| 462 | 461 | /** |
@@ -464,8 +463,8 @@ discard block |
||
| 464 | 463 | * @see generer_objet_url_absolue |
| 465 | 464 | */ |
| 466 | 465 | function generer_url_entite_absolue($id = 0, $entite = '', $args = '', $ancre = '', $connect = null) { |
| 467 | - trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_absolue'); |
|
| 468 | - return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? ''); |
|
| 466 | + trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_absolue'); |
|
| 467 | + return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? ''); |
|
| 469 | 468 | } |
| 470 | 469 | |
| 471 | 470 | |
@@ -494,89 +493,89 @@ discard block |
||
| 494 | 493 | */ |
| 495 | 494 | function url_de_base($profondeur = null) { |
| 496 | 495 | |
| 497 | - static $url = []; |
|
| 498 | - if (is_array($profondeur)) { |
|
| 499 | - return $url = $profondeur; |
|
| 500 | - } |
|
| 501 | - if ($profondeur === false) { |
|
| 502 | - return $url; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - if (is_null($profondeur)) { |
|
| 506 | - $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - if (isset($url[$profondeur])) { |
|
| 510 | - return $url[$profondeur]; |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - $http = 'http'; |
|
| 514 | - |
|
| 515 | - if ( |
|
| 516 | - isset($_SERVER['SCRIPT_URI']) |
|
| 517 | - && str_starts_with($_SERVER['SCRIPT_URI'], 'https') |
|
| 518 | - ) { |
|
| 519 | - $http = 'https'; |
|
| 520 | - } elseif ( |
|
| 521 | - isset($_SERVER['HTTPS']) |
|
| 522 | - && test_valeur_serveur($_SERVER['HTTPS']) |
|
| 523 | - ) { |
|
| 524 | - $http = 'https'; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - // note : HTTP_HOST contient le :port si necessaire |
|
| 528 | - if ($host = $_SERVER['HTTP_HOST'] ?? null) { |
|
| 529 | - // Filtrer $host pour proteger d'attaques d'entete HTTP |
|
| 530 | - $host = (filter_var($host, FILTER_SANITIZE_URL) ?: null); |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 534 | - if (is_null($host) && isset($GLOBALS['meta']['adresse_site'])) { |
|
| 535 | - $host = $GLOBALS['meta']['adresse_site']; |
|
| 536 | - if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 537 | - $http = $scheme; |
|
| 538 | - $host = str_replace("{$scheme}://", '', $host); |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - if ( |
|
| 542 | - isset($_SERVER['SERVER_PORT']) |
|
| 543 | - && ($port = $_SERVER['SERVER_PORT']) |
|
| 544 | - && !str_contains($host, ':') |
|
| 545 | - ) { |
|
| 546 | - if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 547 | - define('_PORT_HTTP_STANDARD', '80'); |
|
| 548 | - } |
|
| 549 | - if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 550 | - define('_PORT_HTTPS_STANDARD', '443'); |
|
| 551 | - } |
|
| 552 | - if ($http == 'http' && !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 553 | - $host .= ":$port"; |
|
| 554 | - } |
|
| 555 | - if ($http == 'https' && !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 556 | - $host .= ":$port"; |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - if (!$GLOBALS['REQUEST_URI']) { |
|
| 561 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 562 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 563 | - } else { |
|
| 564 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 565 | - if ( |
|
| 566 | - !empty($_SERVER['QUERY_STRING']) |
|
| 567 | - && !str_contains($_SERVER['REQUEST_URI'], '?') |
|
| 568 | - ) { |
|
| 569 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - // Et nettoyer l'url |
|
| 575 | - $GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: ''); |
|
| 576 | - |
|
| 577 | - $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 578 | - |
|
| 579 | - return $url[$profondeur]; |
|
| 496 | + static $url = []; |
|
| 497 | + if (is_array($profondeur)) { |
|
| 498 | + return $url = $profondeur; |
|
| 499 | + } |
|
| 500 | + if ($profondeur === false) { |
|
| 501 | + return $url; |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + if (is_null($profondeur)) { |
|
| 505 | + $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + if (isset($url[$profondeur])) { |
|
| 509 | + return $url[$profondeur]; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + $http = 'http'; |
|
| 513 | + |
|
| 514 | + if ( |
|
| 515 | + isset($_SERVER['SCRIPT_URI']) |
|
| 516 | + && str_starts_with($_SERVER['SCRIPT_URI'], 'https') |
|
| 517 | + ) { |
|
| 518 | + $http = 'https'; |
|
| 519 | + } elseif ( |
|
| 520 | + isset($_SERVER['HTTPS']) |
|
| 521 | + && test_valeur_serveur($_SERVER['HTTPS']) |
|
| 522 | + ) { |
|
| 523 | + $http = 'https'; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + // note : HTTP_HOST contient le :port si necessaire |
|
| 527 | + if ($host = $_SERVER['HTTP_HOST'] ?? null) { |
|
| 528 | + // Filtrer $host pour proteger d'attaques d'entete HTTP |
|
| 529 | + $host = (filter_var($host, FILTER_SANITIZE_URL) ?: null); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 533 | + if (is_null($host) && isset($GLOBALS['meta']['adresse_site'])) { |
|
| 534 | + $host = $GLOBALS['meta']['adresse_site']; |
|
| 535 | + if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 536 | + $http = $scheme; |
|
| 537 | + $host = str_replace("{$scheme}://", '', $host); |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + if ( |
|
| 541 | + isset($_SERVER['SERVER_PORT']) |
|
| 542 | + && ($port = $_SERVER['SERVER_PORT']) |
|
| 543 | + && !str_contains($host, ':') |
|
| 544 | + ) { |
|
| 545 | + if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 546 | + define('_PORT_HTTP_STANDARD', '80'); |
|
| 547 | + } |
|
| 548 | + if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 549 | + define('_PORT_HTTPS_STANDARD', '443'); |
|
| 550 | + } |
|
| 551 | + if ($http == 'http' && !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 552 | + $host .= ":$port"; |
|
| 553 | + } |
|
| 554 | + if ($http == 'https' && !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 555 | + $host .= ":$port"; |
|
| 556 | + } |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + if (!$GLOBALS['REQUEST_URI']) { |
|
| 560 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 561 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 562 | + } else { |
|
| 563 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 564 | + if ( |
|
| 565 | + !empty($_SERVER['QUERY_STRING']) |
|
| 566 | + && !str_contains($_SERVER['REQUEST_URI'], '?') |
|
| 567 | + ) { |
|
| 568 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + // Et nettoyer l'url |
|
| 574 | + $GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: ''); |
|
| 575 | + |
|
| 576 | + $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 577 | + |
|
| 578 | + return $url[$profondeur]; |
|
| 580 | 579 | } |
| 581 | 580 | |
| 582 | 581 | /** |
@@ -589,26 +588,26 @@ discard block |
||
| 589 | 588 | * @return string |
| 590 | 589 | */ |
| 591 | 590 | function url_de_($http, $host, $request, $prof = 0) { |
| 592 | - $prof = max($prof, 0); |
|
| 593 | - |
|
| 594 | - $myself = ltrim($request, '/'); |
|
| 595 | - # supprimer la chaine de GET |
|
| 596 | - [$myself] = explode('?', $myself); |
|
| 597 | - // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 598 | - // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 599 | - if (str_contains($myself, '://')) { |
|
| 600 | - $myself = explode('://', $myself); |
|
| 601 | - array_shift($myself); |
|
| 602 | - $myself = implode('://', $myself); |
|
| 603 | - $myself = explode('/', $myself); |
|
| 604 | - array_shift($myself); |
|
| 605 | - $myself = implode('/', $myself); |
|
| 606 | - } |
|
| 607 | - $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 608 | - |
|
| 609 | - $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 610 | - |
|
| 611 | - return $url; |
|
| 591 | + $prof = max($prof, 0); |
|
| 592 | + |
|
| 593 | + $myself = ltrim($request, '/'); |
|
| 594 | + # supprimer la chaine de GET |
|
| 595 | + [$myself] = explode('?', $myself); |
|
| 596 | + // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 597 | + // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 598 | + if (str_contains($myself, '://')) { |
|
| 599 | + $myself = explode('://', $myself); |
|
| 600 | + array_shift($myself); |
|
| 601 | + $myself = implode('://', $myself); |
|
| 602 | + $myself = explode('/', $myself); |
|
| 603 | + array_shift($myself); |
|
| 604 | + $myself = implode('/', $myself); |
|
| 605 | + } |
|
| 606 | + $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 607 | + |
|
| 608 | + $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 609 | + |
|
| 610 | + return $url; |
|
| 612 | 611 | } |
| 613 | 612 | |
| 614 | 613 | |
@@ -643,26 +642,26 @@ discard block |
||
| 643 | 642 | * @return string URL |
| 644 | 643 | **/ |
| 645 | 644 | function generer_url_ecrire(?string $script = '', $args = '', $no_entities = false, $rel = false) { |
| 646 | - $script ??= ''; |
|
| 647 | - if (!$rel) { |
|
| 648 | - $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 649 | - } else { |
|
| 650 | - if (!is_string($rel)) { |
|
| 651 | - $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT; |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - [$script, $ancre] = array_pad(explode('#', $script), 2, null); |
|
| 656 | - if ($script && ($script <> 'accueil' || $rel)) { |
|
| 657 | - $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 658 | - } elseif ($args) { |
|
| 659 | - $args = "?$args"; |
|
| 660 | - } |
|
| 661 | - if ($ancre) { |
|
| 662 | - $args .= "#$ancre"; |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 645 | + $script ??= ''; |
|
| 646 | + if (!$rel) { |
|
| 647 | + $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 648 | + } else { |
|
| 649 | + if (!is_string($rel)) { |
|
| 650 | + $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT; |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + [$script, $ancre] = array_pad(explode('#', $script), 2, null); |
|
| 655 | + if ($script && ($script <> 'accueil' || $rel)) { |
|
| 656 | + $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 657 | + } elseif ($args) { |
|
| 658 | + $args = "?$args"; |
|
| 659 | + } |
|
| 660 | + if ($ancre) { |
|
| 661 | + $args .= "#$ancre"; |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 666 | 665 | } |
| 667 | 666 | |
| 668 | 667 | // |
@@ -684,15 +683,15 @@ discard block |
||
| 684 | 683 | * Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut |
| 685 | 684 | **/ |
| 686 | 685 | function get_spip_script($default = '') { |
| 687 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 688 | - return 'spip.php'; |
|
| 689 | - } |
|
| 690 | - # cas define('_SPIP_SCRIPT', ''); |
|
| 691 | - if (_SPIP_SCRIPT) { |
|
| 692 | - return _SPIP_SCRIPT; |
|
| 693 | - } else { |
|
| 694 | - return $default; |
|
| 695 | - } |
|
| 686 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 687 | + return 'spip.php'; |
|
| 688 | + } |
|
| 689 | + # cas define('_SPIP_SCRIPT', ''); |
|
| 690 | + if (_SPIP_SCRIPT) { |
|
| 691 | + return _SPIP_SCRIPT; |
|
| 692 | + } else { |
|
| 693 | + return $default; |
|
| 694 | + } |
|
| 696 | 695 | } |
| 697 | 696 | |
| 698 | 697 | /** |
@@ -721,45 +720,45 @@ discard block |
||
| 721 | 720 | * @return string URL |
| 722 | 721 | **/ |
| 723 | 722 | function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') { |
| 724 | - // si le script est une action (spip_pass, spip_inscription), |
|
| 725 | - // standardiser vers la nouvelle API |
|
| 726 | - |
|
| 727 | - if (is_array($args)) { |
|
| 728 | - $args = http_build_query($args); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - $url = ''; |
|
| 732 | - if ($f = charger_fonction_url('page')) { |
|
| 733 | - $url = $f($script, $args); |
|
| 734 | - if ($url && !$rel) { |
|
| 735 | - include_spip('inc/filtres_mini'); |
|
| 736 | - $url = url_absolue($url); |
|
| 737 | - } |
|
| 738 | - } |
|
| 739 | - if (!$url) { |
|
| 740 | - if (!$action) { |
|
| 741 | - $action = get_spip_script(); |
|
| 742 | - } |
|
| 743 | - if ($script) { |
|
| 744 | - $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 745 | - } |
|
| 746 | - if ($args) { |
|
| 747 | - $action .= (str_contains($action, '?') ? '&' : '?') . $args; |
|
| 748 | - } |
|
| 749 | - // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 750 | - $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - if (!$no_entities) { |
|
| 754 | - $url = quote_amp($url); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - return $url; |
|
| 723 | + // si le script est une action (spip_pass, spip_inscription), |
|
| 724 | + // standardiser vers la nouvelle API |
|
| 725 | + |
|
| 726 | + if (is_array($args)) { |
|
| 727 | + $args = http_build_query($args); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + $url = ''; |
|
| 731 | + if ($f = charger_fonction_url('page')) { |
|
| 732 | + $url = $f($script, $args); |
|
| 733 | + if ($url && !$rel) { |
|
| 734 | + include_spip('inc/filtres_mini'); |
|
| 735 | + $url = url_absolue($url); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + if (!$url) { |
|
| 739 | + if (!$action) { |
|
| 740 | + $action = get_spip_script(); |
|
| 741 | + } |
|
| 742 | + if ($script) { |
|
| 743 | + $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 744 | + } |
|
| 745 | + if ($args) { |
|
| 746 | + $action .= (str_contains($action, '?') ? '&' : '?') . $args; |
|
| 747 | + } |
|
| 748 | + // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 749 | + $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + if (!$no_entities) { |
|
| 753 | + $url = quote_amp($url); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + return $url; |
|
| 758 | 757 | } |
| 759 | 758 | |
| 760 | 759 | function generer_url_prive($script, $args = '', $no_entities = false) { |
| 761 | 760 | |
| 762 | - return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 761 | + return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 763 | 762 | } |
| 764 | 763 | |
| 765 | 764 | |
@@ -779,22 +778,22 @@ discard block |
||
| 779 | 778 | * URL |
| 780 | 779 | */ |
| 781 | 780 | function generer_url_action($script, $args = '', $no_entities = false, $public = false) { |
| 782 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 783 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 784 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 785 | - $url = (_DIR_RACINE && !$public) |
|
| 786 | - ? generer_url_ecrire(_request('exec')) |
|
| 787 | - : generer_url_public('', '', false, false); |
|
| 788 | - $url = parametre_url($url, 'action', $script); |
|
| 789 | - if ($args) { |
|
| 790 | - $url .= quote_amp('&' . $args); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - if ($no_entities) { |
|
| 794 | - $url = str_replace('&', '&', $url); |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - return $url; |
|
| 781 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 782 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 783 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 784 | + $url = (_DIR_RACINE && !$public) |
|
| 785 | + ? generer_url_ecrire(_request('exec')) |
|
| 786 | + : generer_url_public('', '', false, false); |
|
| 787 | + $url = parametre_url($url, 'action', $script); |
|
| 788 | + if ($args) { |
|
| 789 | + $url .= quote_amp('&' . $args); |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + if ($no_entities) { |
|
| 793 | + $url = str_replace('&', '&', $url); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + return $url; |
|
| 798 | 797 | } |
| 799 | 798 | |
| 800 | 799 | |
@@ -813,21 +812,21 @@ discard block |
||
| 813 | 812 | * URL |
| 814 | 813 | */ |
| 815 | 814 | function generer_url_api(string $script, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 816 | - if (is_null($public)) { |
|
| 817 | - $public = (_DIR_RACINE ? false : true); |
|
| 818 | - } |
|
| 819 | - if (!str_ends_with($script, '.api')) { |
|
| 820 | - $script .= '.api'; |
|
| 821 | - } |
|
| 822 | - $url = |
|
| 823 | - (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './') |
|
| 824 | - . $script . '/' |
|
| 825 | - . ($path ? trim($path, '/') : '') |
|
| 826 | - . ($args ? '?' . quote_amp($args) : ''); |
|
| 827 | - |
|
| 828 | - if ($no_entities) { |
|
| 829 | - $url = str_replace('&', '&', $url); |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - return $url; |
|
| 815 | + if (is_null($public)) { |
|
| 816 | + $public = (_DIR_RACINE ? false : true); |
|
| 817 | + } |
|
| 818 | + if (!str_ends_with($script, '.api')) { |
|
| 819 | + $script .= '.api'; |
|
| 820 | + } |
|
| 821 | + $url = |
|
| 822 | + (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './') |
|
| 823 | + . $script . '/' |
|
| 824 | + . ($path ? trim($path, '/') : '') |
|
| 825 | + . ($args ? '?' . quote_amp($args) : ''); |
|
| 826 | + |
|
| 827 | + if ($no_entities) { |
|
| 828 | + $url = str_replace('&', '&', $url); |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + return $url; |
|
| 833 | 832 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | foreach ($regexp as $r => $e) { |
| 86 | 86 | $regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\d\[\]-],', '', $e)); |
| 87 | 87 | } |
| 88 | - $regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,'; |
|
| 88 | + $regexp = ',^('.implode('|', $regexp).'[[]?[]]?)(=.*)?$,'; |
|
| 89 | 89 | $ajouts = array_flip(explode('|', $c)); |
| 90 | 90 | $u = is_array($v) ? $v : rawurlencode((string) $v); |
| 91 | 91 | $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | // Ajout. Pour une variable, remplacer au meme endroit, |
| 113 | 113 | // pour un tableau ce sera fait dans la prochaine boucle |
| 114 | 114 | elseif (!str_ends_with($r[1], '[]')) { |
| 115 | - $url[$n] = $r[1] . '=' . $u; |
|
| 115 | + $url[$n] = $r[1].'='.$u; |
|
| 116 | 116 | unset($ajouts[$r[1]]); |
| 117 | 117 | } |
| 118 | 118 | // Pour les tableaux on laisse tomber les valeurs de |
@@ -133,11 +133,11 @@ discard block |
||
| 133 | 133 | } elseif ($testv) { |
| 134 | 134 | foreach ($ajouts as $k => $n) { |
| 135 | 135 | if (!is_array($v)) { |
| 136 | - $url[] = $k . '=' . $u; |
|
| 136 | + $url[] = $k.'='.$u; |
|
| 137 | 137 | } else { |
| 138 | - $id = (str_ends_with($k, '[]')) ? $k : ($k . '[]'); |
|
| 138 | + $id = (str_ends_with($k, '[]')) ? $k : ($k.'[]'); |
|
| 139 | 139 | foreach ($v as $w) { |
| 140 | - $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 140 | + $url[] = $id.'='.(is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | } |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | // recomposer l'adresse |
| 150 | 150 | if ($url) { |
| 151 | - $a .= '?' . join($sep, $url); |
|
| 151 | + $a .= '?'.join($sep, $url); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - return $a . $ancre; |
|
| 154 | + return $a.$ancre; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | translitteration($ancre) |
| 182 | 182 | ); |
| 183 | 183 | } |
| 184 | - return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 184 | + return $url.(strlen($ancre) ? '#'.$ancre : ''); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | if (str_starts_with($var, '^')) { |
| 227 | 227 | $var = substr($var, 1); |
| 228 | 228 | } else { |
| 229 | - $var = '[^=&]*' . $var; |
|
| 229 | + $var = '[^=&]*'.$var; |
|
| 230 | 230 | } |
| 231 | 231 | if (str_ends_with($var, '$')) { |
| 232 | 232 | $var = substr($var, 0, -1); |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | $var .= '[^=&]*'; |
| 235 | 235 | } |
| 236 | 236 | } |
| 237 | - $preg_nettoyer = ',([?&])(' . implode('|', $preg_nettoyer_vars) . ')=[^&]*(&|$),i'; |
|
| 237 | + $preg_nettoyer = ',([?&])('.implode('|', $preg_nettoyer_vars).')=[^&]*(&|$),i'; |
|
| 238 | 238 | } |
| 239 | 239 | if (empty($request_uri)) { |
| 240 | 240 | return $request_uri; |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | // On a ete gentil mais la .... |
| 367 | - spip_logger()->error("generer_objet_url: entite $entite " . ($public ? "($f)" : '') . " inconnue $type $public $connect"); |
|
| 367 | + spip_logger()->error("generer_objet_url: entite $entite ".($public ? "($f)" : '')." inconnue $type $public $connect"); |
|
| 368 | 368 | |
| 369 | 369 | return ''; |
| 370 | 370 | } |
@@ -415,8 +415,8 @@ discard block |
||
| 415 | 415 | include_spip('base/connect_sql'); |
| 416 | 416 | $id_type = id_table_objet($entite, $public); |
| 417 | 417 | |
| 418 | - return _DIR_RACINE . get_spip_script('./') |
|
| 419 | - . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 418 | + return _DIR_RACINE.get_spip_script('./') |
|
| 419 | + . '?'._SPIP_PAGE."=$entite&$id_type=$i&connect=$public" |
|
| 420 | 420 | . (!$args ? '' : "&$args") |
| 421 | 421 | . (!$ancre ? '' : "#$ancre"); |
| 422 | 422 | } |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | !empty($_SERVER['QUERY_STRING']) |
| 567 | 567 | && !str_contains($_SERVER['REQUEST_URI'], '?') |
| 568 | 568 | ) { |
| 569 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 569 | + $GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING']; |
|
| 570 | 570 | } |
| 571 | 571 | } |
| 572 | 572 | } |
@@ -604,9 +604,9 @@ discard block |
||
| 604 | 604 | array_shift($myself); |
| 605 | 605 | $myself = implode('/', $myself); |
| 606 | 606 | } |
| 607 | - $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 607 | + $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)).'/'; |
|
| 608 | 608 | |
| 609 | - $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 609 | + $url = $http.'://'.rtrim($host, '/').'/'.ltrim($url, '/'); |
|
| 610 | 610 | |
| 611 | 611 | return $url; |
| 612 | 612 | } |
@@ -645,16 +645,16 @@ discard block |
||
| 645 | 645 | function generer_url_ecrire(?string $script = '', $args = '', $no_entities = false, $rel = false) { |
| 646 | 646 | $script ??= ''; |
| 647 | 647 | if (!$rel) { |
| 648 | - $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 648 | + $rel = url_de_base()._DIR_RESTREINT_ABS._SPIP_ECRIRE_SCRIPT; |
|
| 649 | 649 | } else { |
| 650 | 650 | if (!is_string($rel)) { |
| 651 | - $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT; |
|
| 651 | + $rel = _DIR_RESTREINT ?: './'._SPIP_ECRIRE_SCRIPT; |
|
| 652 | 652 | } |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | [$script, $ancre] = array_pad(explode('#', $script), 2, null); |
| 656 | 656 | if ($script && ($script <> 'accueil' || $rel)) { |
| 657 | - $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 657 | + $args = "?exec=$script".(!$args ? '' : "&$args"); |
|
| 658 | 658 | } elseif ($args) { |
| 659 | 659 | $args = "?$args"; |
| 660 | 660 | } |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | $args .= "#$ancre"; |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | - return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 665 | + return $rel.($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | // |
@@ -744,10 +744,10 @@ discard block |
||
| 744 | 744 | $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
| 745 | 745 | } |
| 746 | 746 | if ($args) { |
| 747 | - $action .= (str_contains($action, '?') ? '&' : '?') . $args; |
|
| 747 | + $action .= (str_contains($action, '?') ? '&' : '?').$args; |
|
| 748 | 748 | } |
| 749 | 749 | // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
| 750 | - $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 750 | + $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/').preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | if (!$no_entities) { |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | |
| 760 | 760 | function generer_url_prive($script, $args = '', $no_entities = false) { |
| 761 | 761 | |
| 762 | - return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 762 | + return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS.'prive.php'); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | : generer_url_public('', '', false, false); |
| 788 | 788 | $url = parametre_url($url, 'action', $script); |
| 789 | 789 | if ($args) { |
| 790 | - $url .= quote_amp('&' . $args); |
|
| 790 | + $url .= quote_amp('&'.$args); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | if ($no_entities) { |
@@ -821,9 +821,9 @@ discard block |
||
| 821 | 821 | } |
| 822 | 822 | $url = |
| 823 | 823 | (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './') |
| 824 | - . $script . '/' |
|
| 824 | + . $script.'/' |
|
| 825 | 825 | . ($path ? trim($path, '/') : '') |
| 826 | - . ($args ? '?' . quote_amp($args) : ''); |
|
| 826 | + . ($args ? '?'.quote_amp($args) : ''); |
|
| 827 | 827 | |
| 828 | 828 | if ($no_entities) { |
| 829 | 829 | $url = str_replace('&', '&', $url); |
@@ -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 | include_spip('base/abstract_sql'); |
@@ -34,26 +34,26 @@ discard block |
||
| 34 | 34 | **/ |
| 35 | 35 | function genie_optimiser_dist($t) { |
| 36 | 36 | |
| 37 | - optimiser_base_une_table(); |
|
| 38 | - optimiser_base(); |
|
| 39 | - optimiser_caches_contextes(); |
|
| 37 | + optimiser_base_une_table(); |
|
| 38 | + optimiser_base(); |
|
| 39 | + optimiser_caches_contextes(); |
|
| 40 | 40 | |
| 41 | - // la date souhaitee pour le tour suivant = apres-demain a 4h du mat ; |
|
| 42 | - // sachant qu'on a un delai de 48h, on renvoie aujourd'hui a 4h du mat |
|
| 43 | - // avec une periode de flou entre 2h et 6h pour ne pas saturer un hebergeur |
|
| 44 | - // qui aurait beaucoup de sites SPIP |
|
| 45 | - return -(mktime(2, 0, 0) + random_int(0, 3600 * 4)); |
|
| 41 | + // la date souhaitee pour le tour suivant = apres-demain a 4h du mat ; |
|
| 42 | + // sachant qu'on a un delai de 48h, on renvoie aujourd'hui a 4h du mat |
|
| 43 | + // avec une periode de flou entre 2h et 6h pour ne pas saturer un hebergeur |
|
| 44 | + // qui aurait beaucoup de sites SPIP |
|
| 45 | + return -(mktime(2, 0, 0) + random_int(0, 3600 * 4)); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * Vider les contextes ajax de plus de 48h |
| 50 | 50 | */ |
| 51 | 51 | function optimiser_caches_contextes() { |
| 52 | - sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 53 | - if (is_dir($d = _DIR_CACHE . 'contextes')) { |
|
| 54 | - include_spip('inc/invalideur'); |
|
| 55 | - purger_repertoire($d, ['mtime' => time() - 48 * 3600, 'limit' => 10000]); |
|
| 56 | - } |
|
| 52 | + sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 53 | + if (is_dir($d = _DIR_CACHE . 'contextes')) { |
|
| 54 | + include_spip('inc/invalideur'); |
|
| 55 | + purger_repertoire($d, ['mtime' => time() - 48 * 3600, 'limit' => 10000]); |
|
| 56 | + } |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @return void |
| 69 | 69 | **/ |
| 70 | 70 | function optimiser_base($attente = 86400) { |
| 71 | - optimiser_base_disparus($attente); |
|
| 71 | + optimiser_base_disparus($attente); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
@@ -85,29 +85,29 @@ discard block |
||
| 85 | 85 | **/ |
| 86 | 86 | function optimiser_base_une_table() { |
| 87 | 87 | |
| 88 | - $tables = []; |
|
| 89 | - $result = sql_showbase(); |
|
| 90 | - |
|
| 91 | - // on n'optimise qu'une seule table a chaque fois, |
|
| 92 | - // pour ne pas vautrer le systeme |
|
| 93 | - // lire http://dev.mysql.com/doc/refman/5.0/fr/optimize-table.html |
|
| 94 | - while ($row = sql_fetch($result)) { |
|
| 95 | - $tables[] = array_shift($row); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $logger = spip_logger('genie'); |
|
| 99 | - $logger->debug('optimiser_base_une_table ' . json_encode($tables, JSON_THROW_ON_ERROR)); |
|
| 100 | - if ($tables) { |
|
| 101 | - $table_op = (int) (lire_config('optimiser_table', 0) + 1) % count($tables); |
|
| 102 | - ecrire_config('optimiser_table', $table_op); |
|
| 103 | - $q = $tables[$table_op]; |
|
| 104 | - $logger->debug("optimiser_base_une_table : debut d'optimisation de la table $q"); |
|
| 105 | - if (sql_optimize($q)) { |
|
| 106 | - $logger->debug("optimiser_base_une_table : fin d'optimisation de la table $q"); |
|
| 107 | - } else { |
|
| 108 | - $logger->debug("optimiser_base_une_table : Pas d'optimiseur necessaire"); |
|
| 109 | - } |
|
| 110 | - } |
|
| 88 | + $tables = []; |
|
| 89 | + $result = sql_showbase(); |
|
| 90 | + |
|
| 91 | + // on n'optimise qu'une seule table a chaque fois, |
|
| 92 | + // pour ne pas vautrer le systeme |
|
| 93 | + // lire http://dev.mysql.com/doc/refman/5.0/fr/optimize-table.html |
|
| 94 | + while ($row = sql_fetch($result)) { |
|
| 95 | + $tables[] = array_shift($row); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $logger = spip_logger('genie'); |
|
| 99 | + $logger->debug('optimiser_base_une_table ' . json_encode($tables, JSON_THROW_ON_ERROR)); |
|
| 100 | + if ($tables) { |
|
| 101 | + $table_op = (int) (lire_config('optimiser_table', 0) + 1) % count($tables); |
|
| 102 | + ecrire_config('optimiser_table', $table_op); |
|
| 103 | + $q = $tables[$table_op]; |
|
| 104 | + $logger->debug("optimiser_base_une_table : debut d'optimisation de la table $q"); |
|
| 105 | + if (sql_optimize($q)) { |
|
| 106 | + $logger->debug("optimiser_base_une_table : fin d'optimisation de la table $q"); |
|
| 107 | + } else { |
|
| 108 | + $logger->debug("optimiser_base_une_table : Pas d'optimiseur necessaire"); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | |
@@ -133,18 +133,18 @@ discard block |
||
| 133 | 133 | * Nombre de suppressions |
| 134 | 134 | **/ |
| 135 | 135 | function optimiser_sansref($table, $id, $sel, $and = '') { |
| 136 | - $in = []; |
|
| 137 | - while ($row = sql_fetch($sel)) { |
|
| 138 | - $in[$row['id']] = true; |
|
| 139 | - } |
|
| 140 | - sql_free($sel); |
|
| 141 | - |
|
| 142 | - if ($in) { |
|
| 143 | - sql_delete($table, sql_in($id, array_keys($in)) . ($and ? " AND $and" : '')); |
|
| 144 | - spip_logger('genie')->debug("optimiser_sansref: Numeros des entrees $id supprimees dans la table $table: " . implode(', ', array_keys($in))); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return count($in); |
|
| 136 | + $in = []; |
|
| 137 | + while ($row = sql_fetch($sel)) { |
|
| 138 | + $in[$row['id']] = true; |
|
| 139 | + } |
|
| 140 | + sql_free($sel); |
|
| 141 | + |
|
| 142 | + if ($in) { |
|
| 143 | + sql_delete($table, sql_in($id, array_keys($in)) . ($and ? " AND $and" : '')); |
|
| 144 | + spip_logger('genie')->debug("optimiser_sansref: Numeros des entrees $id supprimees dans la table $table: " . implode(', ', array_keys($in))); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return count($in); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
@@ -166,81 +166,81 @@ discard block |
||
| 166 | 166 | **/ |
| 167 | 167 | function optimiser_base_disparus($attente = 86400) { |
| 168 | 168 | |
| 169 | - # format = 20060610110141, si on veut forcer une optimisation tout de suite |
|
| 170 | - $mydate = date('Y-m-d H:i:s', time() - $attente); |
|
| 171 | - $mydate_quote = sql_quote($mydate); |
|
| 169 | + # format = 20060610110141, si on veut forcer une optimisation tout de suite |
|
| 170 | + $mydate = date('Y-m-d H:i:s', time() - $attente); |
|
| 171 | + $mydate_quote = sql_quote($mydate); |
|
| 172 | 172 | |
| 173 | - $n = 0; |
|
| 173 | + $n = 0; |
|
| 174 | 174 | |
| 175 | - // |
|
| 176 | - // Rubriques |
|
| 177 | - // |
|
| 175 | + // |
|
| 176 | + // Rubriques |
|
| 177 | + // |
|
| 178 | 178 | |
| 179 | - # les articles qui sont dans une id_rubrique inexistante |
|
| 180 | - # attention on controle id_rubrique>0 pour ne pas tuer les articles |
|
| 181 | - # specialement affectes a une rubrique non-existante (plugin, |
|
| 182 | - # cf. https://core.spip.net/issues/1549 ) |
|
| 183 | - $res = sql_select( |
|
| 184 | - 'A.id_article AS id', |
|
| 185 | - 'spip_articles AS A |
|
| 179 | + # les articles qui sont dans une id_rubrique inexistante |
|
| 180 | + # attention on controle id_rubrique>0 pour ne pas tuer les articles |
|
| 181 | + # specialement affectes a une rubrique non-existante (plugin, |
|
| 182 | + # cf. https://core.spip.net/issues/1549 ) |
|
| 183 | + $res = sql_select( |
|
| 184 | + 'A.id_article AS id', |
|
| 185 | + 'spip_articles AS A |
|
| 186 | 186 | LEFT JOIN spip_rubriques AS R |
| 187 | 187 | ON A.id_rubrique=R.id_rubrique', |
| 188 | - "A.id_rubrique > 0 |
|
| 188 | + "A.id_rubrique > 0 |
|
| 189 | 189 | AND R.id_rubrique IS NULL |
| 190 | 190 | AND A.maj < $mydate_quote" |
| 191 | - ); |
|
| 191 | + ); |
|
| 192 | 192 | |
| 193 | - $n += optimiser_sansref('spip_articles', 'id_article', $res); |
|
| 193 | + $n += optimiser_sansref('spip_articles', 'id_article', $res); |
|
| 194 | 194 | |
| 195 | - // les articles a la poubelle |
|
| 196 | - sql_delete('spip_articles', "statut='poubelle' AND maj < $mydate_quote"); |
|
| 195 | + // les articles a la poubelle |
|
| 196 | + sql_delete('spip_articles', "statut='poubelle' AND maj < $mydate_quote"); |
|
| 197 | 197 | |
| 198 | - // |
|
| 199 | - // Auteurs |
|
| 200 | - // |
|
| 198 | + // |
|
| 199 | + // Auteurs |
|
| 200 | + // |
|
| 201 | 201 | |
| 202 | - include_spip('action/editer_liens'); |
|
| 203 | - // optimiser les liens de tous les auteurs vers des objets effaces |
|
| 204 | - // et depuis des auteurs effaces |
|
| 205 | - $n += objet_optimiser_liens(['auteur' => '*'], '*'); |
|
| 202 | + include_spip('action/editer_liens'); |
|
| 203 | + // optimiser les liens de tous les auteurs vers des objets effaces |
|
| 204 | + // et depuis des auteurs effaces |
|
| 205 | + $n += objet_optimiser_liens(['auteur' => '*'], '*'); |
|
| 206 | 206 | |
| 207 | - # effacer les auteurs poubelle qui ne sont lies a rien |
|
| 208 | - $res = sql_select( |
|
| 209 | - 'A.id_auteur AS id', |
|
| 210 | - 'spip_auteurs AS A |
|
| 207 | + # effacer les auteurs poubelle qui ne sont lies a rien |
|
| 208 | + $res = sql_select( |
|
| 209 | + 'A.id_auteur AS id', |
|
| 210 | + 'spip_auteurs AS A |
|
| 211 | 211 | LEFT JOIN spip_auteurs_liens AS L |
| 212 | 212 | ON L.id_auteur=A.id_auteur', |
| 213 | - "L.id_auteur IS NULL |
|
| 213 | + "L.id_auteur IS NULL |
|
| 214 | 214 | AND A.statut='5poubelle' AND A.maj < $mydate_quote" |
| 215 | - ); |
|
| 216 | - |
|
| 217 | - $n += optimiser_sansref('spip_auteurs', 'id_auteur', $res); |
|
| 218 | - |
|
| 219 | - # supprimer les auteurs 'nouveau' qui n'ont jamais donne suite |
|
| 220 | - # au mail de confirmation (45 jours pour repondre, ca devrait suffire) |
|
| 221 | - if (!defined('_AUTEURS_DELAI_REJET_NOUVEAU')) { |
|
| 222 | - define('_AUTEURS_DELAI_REJET_NOUVEAU', 45 * 24 * 3600); |
|
| 223 | - } |
|
| 224 | - sql_delete('spip_auteurs', "statut='nouveau' AND maj < " . sql_quote(date('Y-m-d', time() - (int) _AUTEURS_DELAI_REJET_NOUVEAU))); |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Permet aux plugins de compléter l'optimisation suite aux éléments disparus |
|
| 228 | - * |
|
| 229 | - * L'index 'data' est un entier indiquant le nombre d'optimisations |
|
| 230 | - * qui ont été réalisées (par exemple le nombre de suppressions faites) |
|
| 231 | - * et qui doit être incrémenté par les fonctions |
|
| 232 | - * utilisant ce pipeline si elles suppriment des éléments. |
|
| 233 | - * |
|
| 234 | - * @pipeline_appel optimiser_base_disparus |
|
| 235 | - */ |
|
| 236 | - $n = pipeline('optimiser_base_disparus', [ |
|
| 237 | - 'args' => [ |
|
| 238 | - 'attente' => $attente, |
|
| 239 | - 'date' => $mydate |
|
| 240 | - ], |
|
| 241 | - 'data' => $n |
|
| 242 | - ]); |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - spip_logger('genie')->debug("optimiser_base_disparus : {$n} lien(s) mort(s)"); |
|
| 215 | + ); |
|
| 216 | + |
|
| 217 | + $n += optimiser_sansref('spip_auteurs', 'id_auteur', $res); |
|
| 218 | + |
|
| 219 | + # supprimer les auteurs 'nouveau' qui n'ont jamais donne suite |
|
| 220 | + # au mail de confirmation (45 jours pour repondre, ca devrait suffire) |
|
| 221 | + if (!defined('_AUTEURS_DELAI_REJET_NOUVEAU')) { |
|
| 222 | + define('_AUTEURS_DELAI_REJET_NOUVEAU', 45 * 24 * 3600); |
|
| 223 | + } |
|
| 224 | + sql_delete('spip_auteurs', "statut='nouveau' AND maj < " . sql_quote(date('Y-m-d', time() - (int) _AUTEURS_DELAI_REJET_NOUVEAU))); |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Permet aux plugins de compléter l'optimisation suite aux éléments disparus |
|
| 228 | + * |
|
| 229 | + * L'index 'data' est un entier indiquant le nombre d'optimisations |
|
| 230 | + * qui ont été réalisées (par exemple le nombre de suppressions faites) |
|
| 231 | + * et qui doit être incrémenté par les fonctions |
|
| 232 | + * utilisant ce pipeline si elles suppriment des éléments. |
|
| 233 | + * |
|
| 234 | + * @pipeline_appel optimiser_base_disparus |
|
| 235 | + */ |
|
| 236 | + $n = pipeline('optimiser_base_disparus', [ |
|
| 237 | + 'args' => [ |
|
| 238 | + 'attente' => $attente, |
|
| 239 | + 'date' => $mydate |
|
| 240 | + ], |
|
| 241 | + 'data' => $n |
|
| 242 | + ]); |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + spip_logger('genie')->debug("optimiser_base_disparus : {$n} lien(s) mort(s)"); |
|
| 246 | 246 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | function optimiser_caches_contextes() { |
| 52 | 52 | sous_repertoire(_DIR_CACHE, 'contextes'); |
| 53 | - if (is_dir($d = _DIR_CACHE . 'contextes')) { |
|
| 53 | + if (is_dir($d = _DIR_CACHE.'contextes')) { |
|
| 54 | 54 | include_spip('inc/invalideur'); |
| 55 | 55 | purger_repertoire($d, ['mtime' => time() - 48 * 3600, 'limit' => 10000]); |
| 56 | 56 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | $logger = spip_logger('genie'); |
| 99 | - $logger->debug('optimiser_base_une_table ' . json_encode($tables, JSON_THROW_ON_ERROR)); |
|
| 99 | + $logger->debug('optimiser_base_une_table '.json_encode($tables, JSON_THROW_ON_ERROR)); |
|
| 100 | 100 | if ($tables) { |
| 101 | 101 | $table_op = (int) (lire_config('optimiser_table', 0) + 1) % count($tables); |
| 102 | 102 | ecrire_config('optimiser_table', $table_op); |
@@ -140,8 +140,8 @@ discard block |
||
| 140 | 140 | sql_free($sel); |
| 141 | 141 | |
| 142 | 142 | if ($in) { |
| 143 | - sql_delete($table, sql_in($id, array_keys($in)) . ($and ? " AND $and" : '')); |
|
| 144 | - spip_logger('genie')->debug("optimiser_sansref: Numeros des entrees $id supprimees dans la table $table: " . implode(', ', array_keys($in))); |
|
| 143 | + sql_delete($table, sql_in($id, array_keys($in)).($and ? " AND $and" : '')); |
|
| 144 | + spip_logger('genie')->debug("optimiser_sansref: Numeros des entrees $id supprimees dans la table $table: ".implode(', ', array_keys($in))); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | return count($in); |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | if (!defined('_AUTEURS_DELAI_REJET_NOUVEAU')) { |
| 222 | 222 | define('_AUTEURS_DELAI_REJET_NOUVEAU', 45 * 24 * 3600); |
| 223 | 223 | } |
| 224 | - sql_delete('spip_auteurs', "statut='nouveau' AND maj < " . sql_quote(date('Y-m-d', time() - (int) _AUTEURS_DELAI_REJET_NOUVEAU))); |
|
| 224 | + sql_delete('spip_auteurs', "statut='nouveau' AND maj < ".sql_quote(date('Y-m-d', time() - (int) _AUTEURS_DELAI_REJET_NOUVEAU))); |
|
| 225 | 225 | |
| 226 | 226 | /** |
| 227 | 227 | * Permet aux plugins de compléter l'optimisation suite aux éléments disparus |
@@ -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 | /** |
@@ -26,15 +26,15 @@ discard block |
||
| 26 | 26 | * @return int |
| 27 | 27 | */ |
| 28 | 28 | function genie_mise_a_jour_dist($t) { |
| 29 | - include_spip('inc/meta'); |
|
| 30 | - $maj = info_maj($GLOBALS['spip_version_branche']); |
|
| 31 | - ecrire_meta('info_maj_spip', $maj ? ($GLOBALS['spip_version_branche'] . "|$maj") : '', 'non'); |
|
| 29 | + include_spip('inc/meta'); |
|
| 30 | + $maj = info_maj($GLOBALS['spip_version_branche']); |
|
| 31 | + ecrire_meta('info_maj_spip', $maj ? ($GLOBALS['spip_version_branche'] . "|$maj") : '', 'non'); |
|
| 32 | 32 | |
| 33 | - mise_a_jour_ecran_securite(); |
|
| 33 | + mise_a_jour_ecran_securite(); |
|
| 34 | 34 | |
| 35 | - spip_logger('verifie_maj')->info('Verification version SPIP : ' . ($maj ?: 'version a jour')); |
|
| 35 | + spip_logger('verifie_maj')->info('Verification version SPIP : ' . ($maj ?: 'version a jour')); |
|
| 36 | 36 | |
| 37 | - return 1; |
|
| 37 | + return 1; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // TODO : fournir une URL sur spip.net pour maitriser la diffusion d'une nouvelle version de l'ecran via l'update auto |
@@ -51,46 +51,46 @@ discard block |
||
| 51 | 51 | * ou de ne repondre une 304 que si le md5 est bon |
| 52 | 52 | */ |
| 53 | 53 | function mise_a_jour_ecran_securite() { |
| 54 | - // TODO : url https avec verification du certificat |
|
| 55 | - return; |
|
| 56 | - |
|
| 57 | - // si l'ecran n'est pas deja present ou pas updatable, sortir |
|
| 58 | - if ( |
|
| 59 | - !_URL_ECRAN_SECURITE |
|
| 60 | - || !file_exists($filename = _DIR_ETC . 'ecran_securite.php') |
|
| 61 | - || !is_writable($filename) |
|
| 62 | - || !($last_modified = filemtime($filename)) |
|
| 63 | - || !($md5 = md5_file($filename)) |
|
| 64 | - ) { |
|
| 65 | - return false; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - include_spip('inc/distant'); |
|
| 69 | - $tmp_file = _DIR_TMP . 'ecran_securite.php'; |
|
| 70 | - $url = parametre_url(_URL_ECRAN_SECURITE, 'md5', $md5); |
|
| 71 | - $url = parametre_url($url, 'vspip', $GLOBALS['spip_version_branche']); |
|
| 72 | - $res = recuperer_url($url, [ |
|
| 73 | - 'if_modified_since' => $last_modified, |
|
| 74 | - 'file' => $tmp_file |
|
| 75 | - ]); |
|
| 76 | - |
|
| 77 | - // si il y a une version plus recente que l'on a recu correctement |
|
| 78 | - if ( |
|
| 79 | - $res['status'] == 200 |
|
| 80 | - && $res['length'] |
|
| 81 | - && ($tmp_file = $res['file']) |
|
| 82 | - ) { |
|
| 83 | - if ($md5 !== md5_file($tmp_file)) { |
|
| 84 | - // on essaye de l'inclure pour verifier que ca ne fait pas erreur fatale |
|
| 85 | - include_once $tmp_file; |
|
| 86 | - // ok, on le copie a la place de l'ecran existant |
|
| 87 | - // en backupant l'ecran avant, au cas ou |
|
| 88 | - @copy($filename, $filename . '-bck-' . date('Y-m-d-His', $last_modified)); |
|
| 89 | - @rename($tmp_file, $filename); |
|
| 90 | - } else { |
|
| 91 | - @unlink($tmp_file); |
|
| 92 | - } |
|
| 93 | - } |
|
| 54 | + // TODO : url https avec verification du certificat |
|
| 55 | + return; |
|
| 56 | + |
|
| 57 | + // si l'ecran n'est pas deja present ou pas updatable, sortir |
|
| 58 | + if ( |
|
| 59 | + !_URL_ECRAN_SECURITE |
|
| 60 | + || !file_exists($filename = _DIR_ETC . 'ecran_securite.php') |
|
| 61 | + || !is_writable($filename) |
|
| 62 | + || !($last_modified = filemtime($filename)) |
|
| 63 | + || !($md5 = md5_file($filename)) |
|
| 64 | + ) { |
|
| 65 | + return false; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + include_spip('inc/distant'); |
|
| 69 | + $tmp_file = _DIR_TMP . 'ecran_securite.php'; |
|
| 70 | + $url = parametre_url(_URL_ECRAN_SECURITE, 'md5', $md5); |
|
| 71 | + $url = parametre_url($url, 'vspip', $GLOBALS['spip_version_branche']); |
|
| 72 | + $res = recuperer_url($url, [ |
|
| 73 | + 'if_modified_since' => $last_modified, |
|
| 74 | + 'file' => $tmp_file |
|
| 75 | + ]); |
|
| 76 | + |
|
| 77 | + // si il y a une version plus recente que l'on a recu correctement |
|
| 78 | + if ( |
|
| 79 | + $res['status'] == 200 |
|
| 80 | + && $res['length'] |
|
| 81 | + && ($tmp_file = $res['file']) |
|
| 82 | + ) { |
|
| 83 | + if ($md5 !== md5_file($tmp_file)) { |
|
| 84 | + // on essaye de l'inclure pour verifier que ca ne fait pas erreur fatale |
|
| 85 | + include_once $tmp_file; |
|
| 86 | + // ok, on le copie a la place de l'ecran existant |
|
| 87 | + // en backupant l'ecran avant, au cas ou |
|
| 88 | + @copy($filename, $filename . '-bck-' . date('Y-m-d-His', $last_modified)); |
|
| 89 | + @rename($tmp_file, $filename); |
|
| 90 | + } else { |
|
| 91 | + @unlink($tmp_file); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -106,28 +106,28 @@ discard block |
||
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | 108 | function info_maj(string $version): string { |
| 109 | - include_spip('inc/plugin'); |
|
| 110 | - |
|
| 111 | - // API V1 |
|
| 112 | - $contenu = info_maj_cache(); |
|
| 113 | - if (!$contenu) { |
|
| 114 | - return ''; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $maj = info_maj_versions($version, array_keys($contenu['versions'] ?? [])); |
|
| 118 | - if (!$maj['mineure'] && !$maj['majeure']) { |
|
| 119 | - return ''; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $message = []; |
|
| 123 | - if ($maj['mineure']) { |
|
| 124 | - $message[] = _T('nouvelle_version_spip', ['version' => $maj['mineure']]); |
|
| 125 | - } |
|
| 126 | - if ($maj['majeure']) { |
|
| 127 | - $message[] = _T('nouvelle_version_spip_majeure', ['version' => $maj['majeure']]); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - return '<a class="info_maj_spip" href="https://www.spip.net/fr_update" title="' . $maj['mineure'] . '">' . implode(' | ', $message) . '</a>'; |
|
| 109 | + include_spip('inc/plugin'); |
|
| 110 | + |
|
| 111 | + // API V1 |
|
| 112 | + $contenu = info_maj_cache(); |
|
| 113 | + if (!$contenu) { |
|
| 114 | + return ''; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $maj = info_maj_versions($version, array_keys($contenu['versions'] ?? [])); |
|
| 118 | + if (!$maj['mineure'] && !$maj['majeure']) { |
|
| 119 | + return ''; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $message = []; |
|
| 123 | + if ($maj['mineure']) { |
|
| 124 | + $message[] = _T('nouvelle_version_spip', ['version' => $maj['mineure']]); |
|
| 125 | + } |
|
| 126 | + if ($maj['majeure']) { |
|
| 127 | + $message[] = _T('nouvelle_version_spip_majeure', ['version' => $maj['majeure']]); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + return '<a class="info_maj_spip" href="https://www.spip.net/fr_update" title="' . $maj['mineure'] . '">' . implode(' | ', $message) . '</a>'; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -142,34 +142,34 @@ discard block |
||
| 142 | 142 | * @return array|null Contenu du fichier de cache de l'info de maj de SPIP. |
| 143 | 143 | */ |
| 144 | 144 | function info_maj_cache(): ?array { |
| 145 | - $contenu = ''; |
|
| 146 | - $options = []; |
|
| 147 | - $nom = _DIR_CACHE . _VERSIONS_LISTE; |
|
| 148 | - if (file_exists($nom)) { |
|
| 149 | - $contenu = file_get_contents($nom); |
|
| 150 | - $options['if_modified_since'] = filemtime($nom); |
|
| 151 | - } |
|
| 152 | - include_spip('inc/distant'); |
|
| 153 | - $res = recuperer_url_cache(_VERSIONS_SERVEUR, $options); |
|
| 154 | - |
|
| 155 | - // Si rien de neuf (ou inaccessible), garder l'ancienne |
|
| 156 | - if ($res && $res['page']) { |
|
| 157 | - $contenu = $res['page']; |
|
| 158 | - ecrire_fichier($nom, $contenu); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if (!$contenu) { |
|
| 162 | - return null; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - try { |
|
| 166 | - $json = json_decode((string) $contenu, true, 512, JSON_THROW_ON_ERROR); |
|
| 167 | - } catch (JsonException $e) { |
|
| 168 | - spip_logger('verifie_maj')->info('Failed to parse Json data : ' . $e->getMessage()); |
|
| 169 | - return null; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - return $json; |
|
| 145 | + $contenu = ''; |
|
| 146 | + $options = []; |
|
| 147 | + $nom = _DIR_CACHE . _VERSIONS_LISTE; |
|
| 148 | + if (file_exists($nom)) { |
|
| 149 | + $contenu = file_get_contents($nom); |
|
| 150 | + $options['if_modified_since'] = filemtime($nom); |
|
| 151 | + } |
|
| 152 | + include_spip('inc/distant'); |
|
| 153 | + $res = recuperer_url_cache(_VERSIONS_SERVEUR, $options); |
|
| 154 | + |
|
| 155 | + // Si rien de neuf (ou inaccessible), garder l'ancienne |
|
| 156 | + if ($res && $res['page']) { |
|
| 157 | + $contenu = $res['page']; |
|
| 158 | + ecrire_fichier($nom, $contenu); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if (!$contenu) { |
|
| 162 | + return null; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + try { |
|
| 166 | + $json = json_decode((string) $contenu, true, 512, JSON_THROW_ON_ERROR); |
|
| 167 | + } catch (JsonException $e) { |
|
| 168 | + spip_logger('verifie_maj')->info('Failed to parse Json data : ' . $e->getMessage()); |
|
| 169 | + return null; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + return $json; |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -184,40 +184,40 @@ discard block |
||
| 184 | 184 | * @return array<string, string> Version mineure supérieure, version majeure supérieure |
| 185 | 185 | */ |
| 186 | 186 | function info_maj_versions(string $version, array $versions): array { |
| 187 | - $maj = ['mineure' => '', 'majeure' => '']; |
|
| 188 | - if (!$version) { |
|
| 189 | - return $maj; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // pas de version dev |
|
| 193 | - $versions = array_diff($versions, ['dev']); |
|
| 194 | - |
|
| 195 | - // branche en cours d'utilisation |
|
| 196 | - $branche = implode('.', array_slice(explode('.', $version, 3), 0, 2)); |
|
| 197 | - |
|
| 198 | - foreach ($versions as $v) { |
|
| 199 | - [$maj2, $min2, $rev2] = explode('.', $v); |
|
| 200 | - $branche_maj = $maj2 . '.' . $min2; |
|
| 201 | - $version_maj = $maj2 . '.' . $min2 . '.' . $rev2; |
|
| 202 | - $is_version_stable = is_numeric($rev2); |
|
| 203 | - // d'abord les mises à jour de la même branche (version mineure) |
|
| 204 | - if ( |
|
| 205 | - spip_version_compare($version, $version_maj, '<') |
|
| 206 | - && spip_version_compare($maj['mineure'], $version_maj, '<') |
|
| 207 | - && spip_version_compare($branche, $branche_maj, '=') |
|
| 208 | - ) { |
|
| 209 | - $maj['mineure'] = $version_maj; |
|
| 210 | - } |
|
| 211 | - // puis les mises à jours majeures |
|
| 212 | - if ( |
|
| 213 | - $is_version_stable |
|
| 214 | - && spip_version_compare($version, $version_maj, '<') |
|
| 215 | - && spip_version_compare($maj['majeure'], $version_maj, '<') |
|
| 216 | - && spip_version_compare($branche, $branche_maj, '<') |
|
| 217 | - ) { |
|
| 218 | - $maj['majeure'] = $version_maj; |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - return $maj; |
|
| 187 | + $maj = ['mineure' => '', 'majeure' => '']; |
|
| 188 | + if (!$version) { |
|
| 189 | + return $maj; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // pas de version dev |
|
| 193 | + $versions = array_diff($versions, ['dev']); |
|
| 194 | + |
|
| 195 | + // branche en cours d'utilisation |
|
| 196 | + $branche = implode('.', array_slice(explode('.', $version, 3), 0, 2)); |
|
| 197 | + |
|
| 198 | + foreach ($versions as $v) { |
|
| 199 | + [$maj2, $min2, $rev2] = explode('.', $v); |
|
| 200 | + $branche_maj = $maj2 . '.' . $min2; |
|
| 201 | + $version_maj = $maj2 . '.' . $min2 . '.' . $rev2; |
|
| 202 | + $is_version_stable = is_numeric($rev2); |
|
| 203 | + // d'abord les mises à jour de la même branche (version mineure) |
|
| 204 | + if ( |
|
| 205 | + spip_version_compare($version, $version_maj, '<') |
|
| 206 | + && spip_version_compare($maj['mineure'], $version_maj, '<') |
|
| 207 | + && spip_version_compare($branche, $branche_maj, '=') |
|
| 208 | + ) { |
|
| 209 | + $maj['mineure'] = $version_maj; |
|
| 210 | + } |
|
| 211 | + // puis les mises à jours majeures |
|
| 212 | + if ( |
|
| 213 | + $is_version_stable |
|
| 214 | + && spip_version_compare($version, $version_maj, '<') |
|
| 215 | + && spip_version_compare($maj['majeure'], $version_maj, '<') |
|
| 216 | + && spip_version_compare($branche, $branche_maj, '<') |
|
| 217 | + ) { |
|
| 218 | + $maj['majeure'] = $version_maj; |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + return $maj; |
|
| 223 | 223 | } |
@@ -28,11 +28,11 @@ discard block |
||
| 28 | 28 | function genie_mise_a_jour_dist($t) { |
| 29 | 29 | include_spip('inc/meta'); |
| 30 | 30 | $maj = info_maj($GLOBALS['spip_version_branche']); |
| 31 | - ecrire_meta('info_maj_spip', $maj ? ($GLOBALS['spip_version_branche'] . "|$maj") : '', 'non'); |
|
| 31 | + ecrire_meta('info_maj_spip', $maj ? ($GLOBALS['spip_version_branche']."|$maj") : '', 'non'); |
|
| 32 | 32 | |
| 33 | 33 | mise_a_jour_ecran_securite(); |
| 34 | 34 | |
| 35 | - spip_logger('verifie_maj')->info('Verification version SPIP : ' . ($maj ?: 'version a jour')); |
|
| 35 | + spip_logger('verifie_maj')->info('Verification version SPIP : '.($maj ?: 'version a jour')); |
|
| 36 | 36 | |
| 37 | 37 | return 1; |
| 38 | 38 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | // si l'ecran n'est pas deja present ou pas updatable, sortir |
| 58 | 58 | if ( |
| 59 | 59 | !_URL_ECRAN_SECURITE |
| 60 | - || !file_exists($filename = _DIR_ETC . 'ecran_securite.php') |
|
| 60 | + || !file_exists($filename = _DIR_ETC.'ecran_securite.php') |
|
| 61 | 61 | || !is_writable($filename) |
| 62 | 62 | || !($last_modified = filemtime($filename)) |
| 63 | 63 | || !($md5 = md5_file($filename)) |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | include_spip('inc/distant'); |
| 69 | - $tmp_file = _DIR_TMP . 'ecran_securite.php'; |
|
| 69 | + $tmp_file = _DIR_TMP.'ecran_securite.php'; |
|
| 70 | 70 | $url = parametre_url(_URL_ECRAN_SECURITE, 'md5', $md5); |
| 71 | 71 | $url = parametre_url($url, 'vspip', $GLOBALS['spip_version_branche']); |
| 72 | 72 | $res = recuperer_url($url, [ |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | include_once $tmp_file; |
| 86 | 86 | // ok, on le copie a la place de l'ecran existant |
| 87 | 87 | // en backupant l'ecran avant, au cas ou |
| 88 | - @copy($filename, $filename . '-bck-' . date('Y-m-d-His', $last_modified)); |
|
| 88 | + @copy($filename, $filename.'-bck-'.date('Y-m-d-His', $last_modified)); |
|
| 89 | 89 | @rename($tmp_file, $filename); |
| 90 | 90 | } else { |
| 91 | 91 | @unlink($tmp_file); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $message[] = _T('nouvelle_version_spip_majeure', ['version' => $maj['majeure']]); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - return '<a class="info_maj_spip" href="https://www.spip.net/fr_update" title="' . $maj['mineure'] . '">' . implode(' | ', $message) . '</a>'; |
|
| 130 | + return '<a class="info_maj_spip" href="https://www.spip.net/fr_update" title="'.$maj['mineure'].'">'.implode(' | ', $message).'</a>'; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | function info_maj_cache(): ?array { |
| 145 | 145 | $contenu = ''; |
| 146 | 146 | $options = []; |
| 147 | - $nom = _DIR_CACHE . _VERSIONS_LISTE; |
|
| 147 | + $nom = _DIR_CACHE._VERSIONS_LISTE; |
|
| 148 | 148 | if (file_exists($nom)) { |
| 149 | 149 | $contenu = file_get_contents($nom); |
| 150 | 150 | $options['if_modified_since'] = filemtime($nom); |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | try { |
| 166 | 166 | $json = json_decode((string) $contenu, true, 512, JSON_THROW_ON_ERROR); |
| 167 | 167 | } catch (JsonException $e) { |
| 168 | - spip_logger('verifie_maj')->info('Failed to parse Json data : ' . $e->getMessage()); |
|
| 168 | + spip_logger('verifie_maj')->info('Failed to parse Json data : '.$e->getMessage()); |
|
| 169 | 169 | return null; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -197,8 +197,8 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | foreach ($versions as $v) { |
| 199 | 199 | [$maj2, $min2, $rev2] = explode('.', $v); |
| 200 | - $branche_maj = $maj2 . '.' . $min2; |
|
| 201 | - $version_maj = $maj2 . '.' . $min2 . '.' . $rev2; |
|
| 200 | + $branche_maj = $maj2.'.'.$min2; |
|
| 201 | + $version_maj = $maj2.'.'.$min2.'.'.$rev2; |
|
| 202 | 202 | $is_version_stable = is_numeric($rev2); |
| 203 | 203 | // d'abord les mises à jour de la même branche (version mineure) |
| 204 | 204 | if ( |
@@ -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 | /** |
@@ -34,19 +34,19 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function genie_maintenance_dist($t) { |
| 36 | 36 | |
| 37 | - // (re)mettre .htaccess avec deny from all |
|
| 38 | - // dans les deux repertoires dits inaccessibles par http |
|
| 39 | - include_spip('inc/acces'); |
|
| 40 | - verifier_htaccess(_DIR_ETC); |
|
| 41 | - verifier_htaccess(_DIR_TMP); |
|
| 42 | - verifier_htaccess(_DIR_VENDOR); |
|
| 37 | + // (re)mettre .htaccess avec deny from all |
|
| 38 | + // dans les deux repertoires dits inaccessibles par http |
|
| 39 | + include_spip('inc/acces'); |
|
| 40 | + verifier_htaccess(_DIR_ETC); |
|
| 41 | + verifier_htaccess(_DIR_TMP); |
|
| 42 | + verifier_htaccess(_DIR_VENDOR); |
|
| 43 | 43 | |
| 44 | - // Verifier qu'aucune table n'est crashee |
|
| 45 | - if (!_request('reinstall')) { |
|
| 46 | - verifier_crash_tables(); |
|
| 47 | - } |
|
| 44 | + // Verifier qu'aucune table n'est crashee |
|
| 45 | + if (!_request('reinstall')) { |
|
| 46 | + verifier_crash_tables(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return 1; |
|
| 49 | + return 1; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | |
@@ -63,34 +63,34 @@ discard block |
||
| 63 | 63 | * des tables qui ont crashé. |
| 64 | 64 | */ |
| 65 | 65 | function verifier_crash_tables() { |
| 66 | - if (spip_connect()) { |
|
| 67 | - include_spip('base/serial'); |
|
| 68 | - include_spip('base/auxiliaires'); |
|
| 69 | - $crash = []; |
|
| 70 | - foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 71 | - foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 72 | - if ( |
|
| 73 | - !sql_select('*', $table, '', '', '', 1) |
|
| 74 | - && !defined('spip_interdire_cache') |
|
| 75 | - ) { # cas "LOST CONNECTION" |
|
| 76 | - $crash[] = $table; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - #$crash[] = 'test'; |
|
| 81 | - if ($crash) { |
|
| 82 | - ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 83 | - $logger = spip_logger('err'); |
|
| 84 | - $logger->info('crash des tables'); |
|
| 85 | - $logger->info($crash); |
|
| 86 | - } else { |
|
| 87 | - effacer_meta('message_crash_tables'); |
|
| 88 | - } |
|
| 66 | + if (spip_connect()) { |
|
| 67 | + include_spip('base/serial'); |
|
| 68 | + include_spip('base/auxiliaires'); |
|
| 69 | + $crash = []; |
|
| 70 | + foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 71 | + foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 72 | + if ( |
|
| 73 | + !sql_select('*', $table, '', '', '', 1) |
|
| 74 | + && !defined('spip_interdire_cache') |
|
| 75 | + ) { # cas "LOST CONNECTION" |
|
| 76 | + $crash[] = $table; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + #$crash[] = 'test'; |
|
| 81 | + if ($crash) { |
|
| 82 | + ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 83 | + $logger = spip_logger('err'); |
|
| 84 | + $logger->info('crash des tables'); |
|
| 85 | + $logger->info($crash); |
|
| 86 | + } else { |
|
| 87 | + effacer_meta('message_crash_tables'); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - return $crash; |
|
| 91 | - } |
|
| 90 | + return $crash; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return false; |
|
| 93 | + return false; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -106,16 +106,16 @@ discard block |
||
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | 108 | function message_crash_tables() { |
| 109 | - if ($crash = verifier_crash_tables()) { |
|
| 110 | - return |
|
| 111 | - '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 112 | - . ' <tt>' . implode(', ', $crash) . '</tt><br />' |
|
| 113 | - . generer_form_ecrire( |
|
| 114 | - 'base_repair', |
|
| 115 | - _T('texte_crash_base'), |
|
| 116 | - '', |
|
| 117 | - _T('bouton_tenter_recuperation') |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - return ''; |
|
| 109 | + if ($crash = verifier_crash_tables()) { |
|
| 110 | + return |
|
| 111 | + '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 112 | + . ' <tt>' . implode(', ', $crash) . '</tt><br />' |
|
| 113 | + . generer_form_ecrire( |
|
| 114 | + 'base_repair', |
|
| 115 | + _T('texte_crash_base'), |
|
| 116 | + '', |
|
| 117 | + _T('bouton_tenter_recuperation') |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + return ''; |
|
| 121 | 121 | } |
@@ -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 | /** |
@@ -31,35 +31,35 @@ discard block |
||
| 31 | 31 | * @return int |
| 32 | 32 | */ |
| 33 | 33 | function genie_mail_dist($t) { |
| 34 | - $adresse_neuf = $GLOBALS['meta']['adresse_neuf']; |
|
| 35 | - $jours_neuf = $GLOBALS['meta']['jours_neuf']; |
|
| 34 | + $adresse_neuf = $GLOBALS['meta']['adresse_neuf']; |
|
| 35 | + $jours_neuf = $GLOBALS['meta']['jours_neuf']; |
|
| 36 | 36 | |
| 37 | - $now = time(); |
|
| 38 | - if (!isset($GLOBALS['meta']['dernier_envoi_neuf'])) { |
|
| 39 | - ecrire_meta('dernier_envoi_neuf', date('Y-m-d H:i:s', $now - (3600 * 24 * $jours_neuf))); |
|
| 40 | - } |
|
| 37 | + $now = time(); |
|
| 38 | + if (!isset($GLOBALS['meta']['dernier_envoi_neuf'])) { |
|
| 39 | + ecrire_meta('dernier_envoi_neuf', date('Y-m-d H:i:s', $now - (3600 * 24 * $jours_neuf))); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $page = recuperer_fond( |
|
| 43 | - 'nouveautes', |
|
| 44 | - ['date' => $GLOBALS['meta']['dernier_envoi_neuf'], 'jours_neuf' => $jours_neuf], |
|
| 45 | - ['raw' => true] |
|
| 46 | - ); |
|
| 42 | + $page = recuperer_fond( |
|
| 43 | + 'nouveautes', |
|
| 44 | + ['date' => $GLOBALS['meta']['dernier_envoi_neuf'], 'jours_neuf' => $jours_neuf], |
|
| 45 | + ['raw' => true] |
|
| 46 | + ); |
|
| 47 | 47 | |
| 48 | - if (strlen(trim((string) $page['texte']))) { |
|
| 49 | - // recuperer les entetes envoyes par #HTTP_HEADER |
|
| 50 | - $headers = ''; |
|
| 51 | - if (isset($page['entetes']) && (is_countable($page['entetes']) ? count($page['entetes']) : 0)) { |
|
| 52 | - foreach ($page['entetes'] as $k => $v) { |
|
| 53 | - $headers .= (strlen((string) $v) ? "$k: $v" : $k) . "\n"; |
|
| 54 | - } |
|
| 55 | - } |
|
| 48 | + if (strlen(trim((string) $page['texte']))) { |
|
| 49 | + // recuperer les entetes envoyes par #HTTP_HEADER |
|
| 50 | + $headers = ''; |
|
| 51 | + if (isset($page['entetes']) && (is_countable($page['entetes']) ? count($page['entetes']) : 0)) { |
|
| 52 | + foreach ($page['entetes'] as $k => $v) { |
|
| 53 | + $headers .= (strlen((string) $v) ? "$k: $v" : $k) . "\n"; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - include_spip('inc/notifications'); |
|
| 58 | - notifications_envoyer_mails($adresse_neuf, $page['texte'], '', '', $headers); |
|
| 59 | - ecrire_meta('dernier_envoi_neuf', date('Y-m-d H:i:s', $now)); |
|
| 60 | - } else { |
|
| 61 | - spip_logger()->info("mail nouveautes : rien de neuf depuis $jours_neuf jours"); |
|
| 62 | - } |
|
| 57 | + include_spip('inc/notifications'); |
|
| 58 | + notifications_envoyer_mails($adresse_neuf, $page['texte'], '', '', $headers); |
|
| 59 | + ecrire_meta('dernier_envoi_neuf', date('Y-m-d H:i:s', $now)); |
|
| 60 | + } else { |
|
| 61 | + spip_logger()->info("mail nouveautes : rien de neuf depuis $jours_neuf jours"); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return 1; |
|
| 64 | + return 1; |
|
| 65 | 65 | } |
@@ -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 | |
@@ -48,38 +48,38 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | function balise_ID_LOGO__dist($p) { |
| 50 | 50 | |
| 51 | - preg_match(',^ID_LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 52 | - $type = strtolower($regs[1]); |
|
| 53 | - $suite_logo = $regs[2]; |
|
| 54 | - |
|
| 55 | - // cas de #ID_LOGO_SITE_SPIP |
|
| 56 | - if ($type == 'site_spip') { |
|
| 57 | - $type = 'site'; |
|
| 58 | - $_id_objet = "\"'0'\""; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - $id_objet = id_table_objet($type); |
|
| 62 | - if (!isset($_id_objet)) { |
|
| 63 | - $_id_objet = champ_sql($id_objet, $p); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 67 | - if ($type == 'document') { |
|
| 68 | - $qconnect = _q($connect); |
|
| 69 | - $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 70 | - $code = "table_valeur($doc, 'id_vignette')"; |
|
| 71 | - } elseif ($connect) { |
|
| 72 | - $code = "''"; |
|
| 73 | - spip_logger()->info('Les logos distants ne sont pas prevus'); |
|
| 74 | - } else { |
|
| 75 | - $champ_logo = 'id'; |
|
| 76 | - $code = generer_code_logo($id_objet, $_id_objet, $type, '', "''", $p, $suite_logo, $champ_logo); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - $p->code = $code; |
|
| 80 | - $p->interdire_scripts = false; |
|
| 81 | - |
|
| 82 | - return $p; |
|
| 51 | + preg_match(',^ID_LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 52 | + $type = strtolower($regs[1]); |
|
| 53 | + $suite_logo = $regs[2]; |
|
| 54 | + |
|
| 55 | + // cas de #ID_LOGO_SITE_SPIP |
|
| 56 | + if ($type == 'site_spip') { |
|
| 57 | + $type = 'site'; |
|
| 58 | + $_id_objet = "\"'0'\""; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + $id_objet = id_table_objet($type); |
|
| 62 | + if (!isset($_id_objet)) { |
|
| 63 | + $_id_objet = champ_sql($id_objet, $p); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 67 | + if ($type == 'document') { |
|
| 68 | + $qconnect = _q($connect); |
|
| 69 | + $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 70 | + $code = "table_valeur($doc, 'id_vignette')"; |
|
| 71 | + } elseif ($connect) { |
|
| 72 | + $code = "''"; |
|
| 73 | + spip_logger()->info('Les logos distants ne sont pas prevus'); |
|
| 74 | + } else { |
|
| 75 | + $champ_logo = 'id'; |
|
| 76 | + $code = generer_code_logo($id_objet, $_id_objet, $type, '', "''", $p, $suite_logo, $champ_logo); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + $p->code = $code; |
|
| 80 | + $p->interdire_scripts = false; |
|
| 81 | + |
|
| 82 | + return $p; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -108,28 +108,28 @@ discard block |
||
| 108 | 108 | * Code compilé retournant le chemin du logo ou le code HTML du logo. |
| 109 | 109 | **/ |
| 110 | 110 | function generer_code_logo($id_objet, $_id_objet, $type, $align, $_lien, $p, $suite, string $champ = ''): string { |
| 111 | - $onoff = 'ON'; |
|
| 112 | - $_id_rubrique = "''"; |
|
| 111 | + $onoff = 'ON'; |
|
| 112 | + $_id_rubrique = "''"; |
|
| 113 | 113 | |
| 114 | - if ($type === 'rubrique') { |
|
| 115 | - $_id_rubrique = "quete_parent($_id_objet)"; |
|
| 116 | - } |
|
| 114 | + if ($type === 'rubrique') { |
|
| 115 | + $_id_rubrique = "quete_parent($_id_objet)"; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - if ($suite === '_SURVOL') { |
|
| 119 | - $onoff = 'off'; |
|
| 120 | - } elseif ($suite === '_NORMAL') { |
|
| 121 | - $onoff = 'on'; |
|
| 122 | - } elseif ($suite === '_RUBRIQUE') { |
|
| 123 | - $_id_rubrique = champ_sql('id_rubrique', $p); |
|
| 124 | - } |
|
| 118 | + if ($suite === '_SURVOL') { |
|
| 119 | + $onoff = 'off'; |
|
| 120 | + } elseif ($suite === '_NORMAL') { |
|
| 121 | + $onoff = 'on'; |
|
| 122 | + } elseif ($suite === '_RUBRIQUE') { |
|
| 123 | + $_id_rubrique = champ_sql('id_rubrique', $p); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - $code = "quete_logo('$id_objet', '$onoff', $_id_objet, $_id_rubrique)"; |
|
| 126 | + $code = "quete_logo('$id_objet', '$onoff', $_id_objet, $_id_rubrique)"; |
|
| 127 | 127 | |
| 128 | - if ($champ) { |
|
| 129 | - return "table_valeur($code, '" . addslashes($champ) . "')"; |
|
| 130 | - } |
|
| 128 | + if ($champ) { |
|
| 129 | + return "table_valeur($code, '" . addslashes($champ) . "')"; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - $align = preg_replace(',\W,', '', $align); |
|
| 132 | + $align = preg_replace(',\W,', '', $align); |
|
| 133 | 133 | |
| 134 | - return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')'; |
|
| 134 | + return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')'; |
|
| 135 | 135 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -36,14 +36,14 @@ discard block |
||
| 36 | 36 | * Code compilé |
| 37 | 37 | **/ |
| 38 | 38 | function generer_generer_url($type, $p) { |
| 39 | - $_id = interprete_argument_balise(1, $p); |
|
| 39 | + $_id = interprete_argument_balise(1, $p); |
|
| 40 | 40 | |
| 41 | - if (!$_id) { |
|
| 42 | - $primary = id_table_objet($type); |
|
| 43 | - $_id = champ_sql($primary, $p); |
|
| 44 | - } |
|
| 41 | + if (!$_id) { |
|
| 42 | + $primary = id_table_objet($type); |
|
| 43 | + $_id = champ_sql($primary, $p); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - return generer_generer_url_arg($type, $p, $_id); |
|
| 46 | + return generer_generer_url_arg($type, $p, $_id); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -72,28 +72,28 @@ discard block |
||
| 72 | 72 | * Code compilé |
| 73 | 73 | **/ |
| 74 | 74 | function generer_generer_url_arg($type, $p, $_id) { |
| 75 | - if ($s = trouver_nom_serveur_distant($p)) { |
|
| 76 | - // si une fonction de generation des url a ete definie pour ce connect l'utiliser |
|
| 77 | - if (function_exists($f = 'generer_generer_url_' . $s)) { |
|
| 78 | - return $f($type, $_id, $s); |
|
| 79 | - } |
|
| 80 | - if (!$GLOBALS['connexions'][strtolower((string) $s)]['spip_connect_version']) { |
|
| 81 | - return null; |
|
| 82 | - } |
|
| 83 | - $s = _q($s); |
|
| 84 | - # exception des urls de documents sur un serveur distant... |
|
| 85 | - if ($type == 'document') { |
|
| 86 | - return |
|
| 87 | - "quete_meta('adresse_site', $s) . '/' .\n\t" . |
|
| 88 | - "quete_meta('dir_img', $s) . \n\t" . |
|
| 89 | - "quete_fichier($_id,$s)"; |
|
| 90 | - } |
|
| 91 | - $s = ", '', '', $s, quete_meta('type_urls', $s)"; |
|
| 92 | - } else { |
|
| 93 | - $s = ", '', '', true"; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return "urlencode_1738(generer_objet_url($_id, '$type'$s))"; |
|
| 75 | + if ($s = trouver_nom_serveur_distant($p)) { |
|
| 76 | + // si une fonction de generation des url a ete definie pour ce connect l'utiliser |
|
| 77 | + if (function_exists($f = 'generer_generer_url_' . $s)) { |
|
| 78 | + return $f($type, $_id, $s); |
|
| 79 | + } |
|
| 80 | + if (!$GLOBALS['connexions'][strtolower((string) $s)]['spip_connect_version']) { |
|
| 81 | + return null; |
|
| 82 | + } |
|
| 83 | + $s = _q($s); |
|
| 84 | + # exception des urls de documents sur un serveur distant... |
|
| 85 | + if ($type == 'document') { |
|
| 86 | + return |
|
| 87 | + "quete_meta('adresse_site', $s) . '/' .\n\t" . |
|
| 88 | + "quete_meta('dir_img', $s) . \n\t" . |
|
| 89 | + "quete_fichier($_id,$s)"; |
|
| 90 | + } |
|
| 91 | + $s = ", '', '', $s, quete_meta('type_urls', $s)"; |
|
| 92 | + } else { |
|
| 93 | + $s = ", '', '', true"; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return "urlencode_1738(generer_objet_url($_id, '$type'$s))"; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
@@ -118,27 +118,27 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | function balise_URL__dist($p) { |
| 120 | 120 | |
| 121 | - $nom = $p->nom_champ; |
|
| 122 | - if ($nom === 'URL_') { |
|
| 123 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' URL_']]; |
|
| 124 | - erreur_squelette($msg, $p); |
|
| 125 | - $p->interdire_scripts = false; |
|
| 126 | - |
|
| 127 | - return $p; |
|
| 128 | - } elseif ($f = charger_fonction($nom, 'balise', true)) { |
|
| 129 | - return $f($p); |
|
| 130 | - } else { |
|
| 131 | - $nom = strtolower((string) $nom); |
|
| 132 | - $code = generer_generer_url(substr($nom, 4), $p); |
|
| 133 | - $code = champ_sql($nom, $p, $code); |
|
| 134 | - $p->code = $code; |
|
| 135 | - if (!$p->etoile) { |
|
| 136 | - $p->code = "vider_url($code)"; |
|
| 137 | - } |
|
| 138 | - $p->interdire_scripts = false; |
|
| 139 | - |
|
| 140 | - return $p; |
|
| 141 | - } |
|
| 121 | + $nom = $p->nom_champ; |
|
| 122 | + if ($nom === 'URL_') { |
|
| 123 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' URL_']]; |
|
| 124 | + erreur_squelette($msg, $p); |
|
| 125 | + $p->interdire_scripts = false; |
|
| 126 | + |
|
| 127 | + return $p; |
|
| 128 | + } elseif ($f = charger_fonction($nom, 'balise', true)) { |
|
| 129 | + return $f($p); |
|
| 130 | + } else { |
|
| 131 | + $nom = strtolower((string) $nom); |
|
| 132 | + $code = generer_generer_url(substr($nom, 4), $p); |
|
| 133 | + $code = champ_sql($nom, $p, $code); |
|
| 134 | + $p->code = $code; |
|
| 135 | + if (!$p->etoile) { |
|
| 136 | + $p->code = "vider_url($code)"; |
|
| 137 | + } |
|
| 138 | + $p->interdire_scripts = false; |
|
| 139 | + |
|
| 140 | + return $p; |
|
| 141 | + } |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -162,16 +162,16 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | function balise_URL_ARTICLE_dist($p) { |
| 164 | 164 | |
| 165 | - // Cas particulier des boucles (SYNDIC_ARTICLES) |
|
| 166 | - $code = $p->type_requete == 'syndic_articles' ? champ_sql('url', $p) : generer_generer_url('article', $p); |
|
| 165 | + // Cas particulier des boucles (SYNDIC_ARTICLES) |
|
| 166 | + $code = $p->type_requete == 'syndic_articles' ? champ_sql('url', $p) : generer_generer_url('article', $p); |
|
| 167 | 167 | |
| 168 | - $p->code = $code; |
|
| 169 | - if (!$p->etoile) { |
|
| 170 | - $p->code = "vider_url($code)"; |
|
| 171 | - } |
|
| 172 | - $p->interdire_scripts = false; |
|
| 168 | + $p->code = $code; |
|
| 169 | + if (!$p->etoile) { |
|
| 170 | + $p->code = "vider_url($code)"; |
|
| 171 | + } |
|
| 172 | + $p->interdire_scripts = false; |
|
| 173 | 173 | |
| 174 | - return $p; |
|
| 174 | + return $p; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -191,21 +191,21 @@ discard block |
||
| 191 | 191 | * Pile complétée par le code à générer |
| 192 | 192 | */ |
| 193 | 193 | function balise_URL_SITE_dist($p) { |
| 194 | - $code = champ_sql('url_site', $p, ''); |
|
| 195 | - if (!$code) { |
|
| 196 | - $code = generer_generer_url('site', $p); |
|
| 197 | - if ($code === null) { |
|
| 198 | - return null; |
|
| 199 | - } |
|
| 200 | - } else { |
|
| 201 | - if (!$p->etoile) { |
|
| 202 | - $code = "calculer_url($code,'','url', \$connect)"; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - $p->code = $code; |
|
| 206 | - $p->interdire_scripts = false; |
|
| 207 | - |
|
| 208 | - return $p; |
|
| 194 | + $code = champ_sql('url_site', $p, ''); |
|
| 195 | + if (!$code) { |
|
| 196 | + $code = generer_generer_url('site', $p); |
|
| 197 | + if ($code === null) { |
|
| 198 | + return null; |
|
| 199 | + } |
|
| 200 | + } else { |
|
| 201 | + if (!$p->etoile) { |
|
| 202 | + $code = "calculer_url($code,'','url', \$connect)"; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + $p->code = $code; |
|
| 206 | + $p->interdire_scripts = false; |
|
| 207 | + |
|
| 208 | + return $p; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | // Autres balises URL_*, qui ne concernent pas une table |
@@ -224,11 +224,11 @@ discard block |
||
| 224 | 224 | * Pile complétée par le code à générer |
| 225 | 225 | */ |
| 226 | 226 | function balise_URL_SITE_SPIP_dist($p) { |
| 227 | - $p->code = "sinon(\$GLOBALS['meta']['adresse_site'],'.')"; |
|
| 228 | - $p->code = 'spip_htmlspecialchars(' . $p->code . ')'; |
|
| 229 | - $p->interdire_scripts = false; |
|
| 227 | + $p->code = "sinon(\$GLOBALS['meta']['adresse_site'],'.')"; |
|
| 228 | + $p->code = 'spip_htmlspecialchars(' . $p->code . ')'; |
|
| 229 | + $p->interdire_scripts = false; |
|
| 230 | 230 | |
| 231 | - return $p; |
|
| 231 | + return $p; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | |
@@ -257,42 +257,42 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | function balise_URL_PAGE_dist($p) { |
| 259 | 259 | |
| 260 | - $code = interprete_argument_balise(1, $p); |
|
| 261 | - $args = interprete_argument_balise(2, $p); |
|
| 262 | - if ($args == null) { |
|
| 263 | - $args = "''"; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - if ($s = trouver_nom_serveur_distant($p)) { |
|
| 267 | - // si une fonction de generation des url a ete definie pour ce connect l'utiliser |
|
| 268 | - // elle devra aussi traiter le cas derogatoire type=page |
|
| 269 | - if (function_exists($f = 'generer_generer_url_' . $s)) { |
|
| 270 | - if ($args && $args !== "''") { |
|
| 271 | - $code .= ", $args"; |
|
| 272 | - } |
|
| 273 | - $code = $f('page', $code, $s); |
|
| 274 | - $p->code = $code; |
|
| 275 | - return $p; |
|
| 276 | - } |
|
| 277 | - $s = 'connect=' . addslashes((string) $s); |
|
| 278 | - $args = (($args && $args !== "''") ? "$args . '&$s'" : "'$s'"); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - if (!$code) { |
|
| 282 | - $noentities = $p->etoile ? "'&'" : ''; |
|
| 283 | - $code = "url_de_base() . preg_replace(',^./,', '', self($noentities))"; |
|
| 284 | - } else { |
|
| 285 | - if (!$args) { |
|
| 286 | - $args = "''"; |
|
| 287 | - } |
|
| 288 | - $noentities = $p->etoile ? ', true' : ''; |
|
| 289 | - $code = "generer_url_public($code, $args$noentities)"; |
|
| 290 | - } |
|
| 291 | - $p->code = $code; |
|
| 292 | - spip_logger()->info("Calcul url page : connect vaut $s ca donne :" . $p->code . " args $args"); |
|
| 293 | - |
|
| 294 | - #$p->interdire_scripts = true; |
|
| 295 | - return $p; |
|
| 260 | + $code = interprete_argument_balise(1, $p); |
|
| 261 | + $args = interprete_argument_balise(2, $p); |
|
| 262 | + if ($args == null) { |
|
| 263 | + $args = "''"; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + if ($s = trouver_nom_serveur_distant($p)) { |
|
| 267 | + // si une fonction de generation des url a ete definie pour ce connect l'utiliser |
|
| 268 | + // elle devra aussi traiter le cas derogatoire type=page |
|
| 269 | + if (function_exists($f = 'generer_generer_url_' . $s)) { |
|
| 270 | + if ($args && $args !== "''") { |
|
| 271 | + $code .= ", $args"; |
|
| 272 | + } |
|
| 273 | + $code = $f('page', $code, $s); |
|
| 274 | + $p->code = $code; |
|
| 275 | + return $p; |
|
| 276 | + } |
|
| 277 | + $s = 'connect=' . addslashes((string) $s); |
|
| 278 | + $args = (($args && $args !== "''") ? "$args . '&$s'" : "'$s'"); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + if (!$code) { |
|
| 282 | + $noentities = $p->etoile ? "'&'" : ''; |
|
| 283 | + $code = "url_de_base() . preg_replace(',^./,', '', self($noentities))"; |
|
| 284 | + } else { |
|
| 285 | + if (!$args) { |
|
| 286 | + $args = "''"; |
|
| 287 | + } |
|
| 288 | + $noentities = $p->etoile ? ', true' : ''; |
|
| 289 | + $code = "generer_url_public($code, $args$noentities)"; |
|
| 290 | + } |
|
| 291 | + $p->code = $code; |
|
| 292 | + spip_logger()->info("Calcul url page : connect vaut $s ca donne :" . $p->code . " args $args"); |
|
| 293 | + |
|
| 294 | + #$p->interdire_scripts = true; |
|
| 295 | + return $p; |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | |
@@ -319,24 +319,24 @@ discard block |
||
| 319 | 319 | */ |
| 320 | 320 | function balise_URL_ECRIRE_dist($p) { |
| 321 | 321 | |
| 322 | - $code = interprete_argument_balise(1, $p); |
|
| 323 | - if (!$code) { |
|
| 324 | - $fonc = "''"; |
|
| 325 | - } else { |
|
| 326 | - $fonc = $code; |
|
| 327 | - $args = interprete_argument_balise(2, $p); |
|
| 328 | - if ($args === null) { |
|
| 329 | - $args = "''"; |
|
| 330 | - } |
|
| 331 | - $noentities = $p->etoile ? ', true' : ''; |
|
| 332 | - if ($args != "''" || $noentities) { |
|
| 333 | - $fonc .= ",$args$noentities"; |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - $p->code = 'generer_url_ecrire(' . $fonc . ')'; |
|
| 337 | - $p->interdire_scripts = false; |
|
| 338 | - |
|
| 339 | - return $p; |
|
| 322 | + $code = interprete_argument_balise(1, $p); |
|
| 323 | + if (!$code) { |
|
| 324 | + $fonc = "''"; |
|
| 325 | + } else { |
|
| 326 | + $fonc = $code; |
|
| 327 | + $args = interprete_argument_balise(2, $p); |
|
| 328 | + if ($args === null) { |
|
| 329 | + $args = "''"; |
|
| 330 | + } |
|
| 331 | + $noentities = $p->etoile ? ', true' : ''; |
|
| 332 | + if ($args != "''" || $noentities) { |
|
| 333 | + $fonc .= ",$args$noentities"; |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + $p->code = 'generer_url_ecrire(' . $fonc . ')'; |
|
| 337 | + $p->interdire_scripts = false; |
|
| 338 | + |
|
| 339 | + return $p; |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | |
@@ -362,24 +362,24 @@ discard block |
||
| 362 | 362 | * Pile complétée par le code à générer |
| 363 | 363 | */ |
| 364 | 364 | function balise_URL_ACTION_AUTEUR_dist($p) { |
| 365 | - $p->descr['session'] = true; |
|
| 366 | - |
|
| 367 | - $p->code = interprete_argument_balise(1, $p); |
|
| 368 | - |
|
| 369 | - $args = interprete_argument_balise(2, $p); |
|
| 370 | - if ($args != "''" && $args !== null) { |
|
| 371 | - $p->code .= ',' . $args; |
|
| 372 | - } |
|
| 373 | - $redirect = interprete_argument_balise(3, $p); |
|
| 374 | - if ($redirect != "''" && $redirect !== null) { |
|
| 375 | - if ($args == "''" || $args === null) { |
|
| 376 | - $p->code .= ",''"; |
|
| 377 | - } |
|
| 378 | - $p->code .= ',' . $redirect; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - $p->code = 'generer_action_auteur(' . $p->code . ')'; |
|
| 382 | - $p->interdire_scripts = false; |
|
| 383 | - |
|
| 384 | - return $p; |
|
| 365 | + $p->descr['session'] = true; |
|
| 366 | + |
|
| 367 | + $p->code = interprete_argument_balise(1, $p); |
|
| 368 | + |
|
| 369 | + $args = interprete_argument_balise(2, $p); |
|
| 370 | + if ($args != "''" && $args !== null) { |
|
| 371 | + $p->code .= ',' . $args; |
|
| 372 | + } |
|
| 373 | + $redirect = interprete_argument_balise(3, $p); |
|
| 374 | + if ($redirect != "''" && $redirect !== null) { |
|
| 375 | + if ($args == "''" || $args === null) { |
|
| 376 | + $p->code .= ",''"; |
|
| 377 | + } |
|
| 378 | + $p->code .= ',' . $redirect; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + $p->code = 'generer_action_auteur(' . $p->code . ')'; |
|
| 382 | + $p->interdire_scripts = false; |
|
| 383 | + |
|
| 384 | + return $p; |
|
| 385 | 385 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | function generer_generer_url_arg($type, $p, $_id) { |
| 75 | 75 | if ($s = trouver_nom_serveur_distant($p)) { |
| 76 | 76 | // si une fonction de generation des url a ete definie pour ce connect l'utiliser |
| 77 | - if (function_exists($f = 'generer_generer_url_' . $s)) { |
|
| 77 | + if (function_exists($f = 'generer_generer_url_'.$s)) { |
|
| 78 | 78 | return $f($type, $_id, $s); |
| 79 | 79 | } |
| 80 | 80 | if (!$GLOBALS['connexions'][strtolower((string) $s)]['spip_connect_version']) { |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | # exception des urls de documents sur un serveur distant... |
| 85 | 85 | if ($type == 'document') { |
| 86 | 86 | return |
| 87 | - "quete_meta('adresse_site', $s) . '/' .\n\t" . |
|
| 88 | - "quete_meta('dir_img', $s) . \n\t" . |
|
| 87 | + "quete_meta('adresse_site', $s) . '/' .\n\t". |
|
| 88 | + "quete_meta('dir_img', $s) . \n\t". |
|
| 89 | 89 | "quete_fichier($_id,$s)"; |
| 90 | 90 | } |
| 91 | 91 | $s = ", '', '', $s, quete_meta('type_urls', $s)"; |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | function balise_URL_SITE_SPIP_dist($p) { |
| 227 | 227 | $p->code = "sinon(\$GLOBALS['meta']['adresse_site'],'.')"; |
| 228 | - $p->code = 'spip_htmlspecialchars(' . $p->code . ')'; |
|
| 228 | + $p->code = 'spip_htmlspecialchars('.$p->code.')'; |
|
| 229 | 229 | $p->interdire_scripts = false; |
| 230 | 230 | |
| 231 | 231 | return $p; |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | if ($s = trouver_nom_serveur_distant($p)) { |
| 267 | 267 | // si une fonction de generation des url a ete definie pour ce connect l'utiliser |
| 268 | 268 | // elle devra aussi traiter le cas derogatoire type=page |
| 269 | - if (function_exists($f = 'generer_generer_url_' . $s)) { |
|
| 269 | + if (function_exists($f = 'generer_generer_url_'.$s)) { |
|
| 270 | 270 | if ($args && $args !== "''") { |
| 271 | 271 | $code .= ", $args"; |
| 272 | 272 | } |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | $p->code = $code; |
| 275 | 275 | return $p; |
| 276 | 276 | } |
| 277 | - $s = 'connect=' . addslashes((string) $s); |
|
| 277 | + $s = 'connect='.addslashes((string) $s); |
|
| 278 | 278 | $args = (($args && $args !== "''") ? "$args . '&$s'" : "'$s'"); |
| 279 | 279 | } |
| 280 | 280 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | $code = "generer_url_public($code, $args$noentities)"; |
| 290 | 290 | } |
| 291 | 291 | $p->code = $code; |
| 292 | - spip_logger()->info("Calcul url page : connect vaut $s ca donne :" . $p->code . " args $args"); |
|
| 292 | + spip_logger()->info("Calcul url page : connect vaut $s ca donne :".$p->code." args $args"); |
|
| 293 | 293 | |
| 294 | 294 | #$p->interdire_scripts = true; |
| 295 | 295 | return $p; |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | $fonc .= ",$args$noentities"; |
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | - $p->code = 'generer_url_ecrire(' . $fonc . ')'; |
|
| 336 | + $p->code = 'generer_url_ecrire('.$fonc.')'; |
|
| 337 | 337 | $p->interdire_scripts = false; |
| 338 | 338 | |
| 339 | 339 | return $p; |
@@ -368,17 +368,17 @@ discard block |
||
| 368 | 368 | |
| 369 | 369 | $args = interprete_argument_balise(2, $p); |
| 370 | 370 | if ($args != "''" && $args !== null) { |
| 371 | - $p->code .= ',' . $args; |
|
| 371 | + $p->code .= ','.$args; |
|
| 372 | 372 | } |
| 373 | 373 | $redirect = interprete_argument_balise(3, $p); |
| 374 | 374 | if ($redirect != "''" && $redirect !== null) { |
| 375 | 375 | if ($args == "''" || $args === null) { |
| 376 | 376 | $p->code .= ",''"; |
| 377 | 377 | } |
| 378 | - $p->code .= ',' . $redirect; |
|
| 378 | + $p->code .= ','.$redirect; |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - $p->code = 'generer_action_auteur(' . $p->code . ')'; |
|
| 381 | + $p->code = 'generer_action_auteur('.$p->code.')'; |
|
| 382 | 382 | $p->interdire_scripts = false; |
| 383 | 383 | |
| 384 | 384 | return $p; |
@@ -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 | |
@@ -55,88 +55,88 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function balise_LOGO__dist($p) { |
| 57 | 57 | |
| 58 | - preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 59 | - $type = strtolower($regs[1]); |
|
| 60 | - $suite_logo = $regs[2]; |
|
| 61 | - |
|
| 62 | - // cas de #LOGO_SITE_SPIP |
|
| 63 | - if ($type == 'site_spip') { |
|
| 64 | - $type = 'site'; |
|
| 65 | - $_id_objet = "\"'0'\""; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $id_objet = id_table_objet($type); |
|
| 69 | - if (!isset($_id_objet)) { |
|
| 70 | - $_id_objet = champ_sql($id_objet, $p); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $fichier = ($p->etoile === '**') ? -1 : 0; |
|
| 74 | - $coord = []; |
|
| 75 | - $align = $lien = ''; |
|
| 76 | - $mode_logo = ''; |
|
| 77 | - |
|
| 78 | - if ($p->param && !$p->param[0][0]) { |
|
| 79 | - $params = $p->param[0]; |
|
| 80 | - array_shift($params); |
|
| 81 | - foreach ($params as $a) { |
|
| 82 | - if ($a[0]->type === 'texte') { |
|
| 83 | - $n = $a[0]->texte; |
|
| 84 | - if (is_numeric($n)) { |
|
| 85 | - $coord[] = $n; |
|
| 86 | - } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) { |
|
| 87 | - $align = $n; |
|
| 88 | - } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) { |
|
| 89 | - $mode_logo = $n; |
|
| 90 | - } |
|
| 91 | - } else { |
|
| 92 | - $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $coord_x = $coord ? (int) array_shift($coord) : 0; |
|
| 98 | - $coord_y = $coord ? (int) array_shift($coord) : 0; |
|
| 99 | - |
|
| 100 | - if ($p->etoile === '*') { |
|
| 101 | - include_spip('balise/url_'); |
|
| 102 | - $lien = generer_generer_url_arg($type, $p, $_id_objet); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 106 | - if ($type == 'document') { |
|
| 107 | - $qconnect = _q($connect); |
|
| 108 | - $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 109 | - if ($fichier) { |
|
| 110 | - $code = "quete_logo_file($doc, $qconnect)"; |
|
| 111 | - } else { |
|
| 112 | - $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 113 | - } |
|
| 114 | - // (x=non-faux ? y : '') pour affecter x en retournant y |
|
| 115 | - if ($p->descr['documents']) { |
|
| 116 | - $code = '(($doublons["documents"] .= ",". ' |
|
| 117 | - . $_id_objet |
|
| 118 | - . ") ? $code : '')"; |
|
| 119 | - } |
|
| 120 | - } elseif ($connect) { |
|
| 121 | - $code = "''"; |
|
| 122 | - spip_logger()->info('Les logos distants ne sont pas prevus'); |
|
| 123 | - } else { |
|
| 124 | - // pour generer_code_logo |
|
| 125 | - include_spip('balise/id_logo_'); |
|
| 126 | - $champ_logo = ''; |
|
| 127 | - if ($fichier) { |
|
| 128 | - $champ_logo = 'fichier'; |
|
| 129 | - } |
|
| 130 | - $code = generer_code_logo($id_objet, $_id_objet, $type, $align, $lien, $p, $suite_logo, $champ_logo); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
|
| 134 | - if ($coord_x || $coord_y) { |
|
| 135 | - $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $p->code = $code; |
|
| 139 | - $p->interdire_scripts = false; |
|
| 140 | - |
|
| 141 | - return $p; |
|
| 58 | + preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 59 | + $type = strtolower($regs[1]); |
|
| 60 | + $suite_logo = $regs[2]; |
|
| 61 | + |
|
| 62 | + // cas de #LOGO_SITE_SPIP |
|
| 63 | + if ($type == 'site_spip') { |
|
| 64 | + $type = 'site'; |
|
| 65 | + $_id_objet = "\"'0'\""; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $id_objet = id_table_objet($type); |
|
| 69 | + if (!isset($_id_objet)) { |
|
| 70 | + $_id_objet = champ_sql($id_objet, $p); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $fichier = ($p->etoile === '**') ? -1 : 0; |
|
| 74 | + $coord = []; |
|
| 75 | + $align = $lien = ''; |
|
| 76 | + $mode_logo = ''; |
|
| 77 | + |
|
| 78 | + if ($p->param && !$p->param[0][0]) { |
|
| 79 | + $params = $p->param[0]; |
|
| 80 | + array_shift($params); |
|
| 81 | + foreach ($params as $a) { |
|
| 82 | + if ($a[0]->type === 'texte') { |
|
| 83 | + $n = $a[0]->texte; |
|
| 84 | + if (is_numeric($n)) { |
|
| 85 | + $coord[] = $n; |
|
| 86 | + } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) { |
|
| 87 | + $align = $n; |
|
| 88 | + } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) { |
|
| 89 | + $mode_logo = $n; |
|
| 90 | + } |
|
| 91 | + } else { |
|
| 92 | + $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $coord_x = $coord ? (int) array_shift($coord) : 0; |
|
| 98 | + $coord_y = $coord ? (int) array_shift($coord) : 0; |
|
| 99 | + |
|
| 100 | + if ($p->etoile === '*') { |
|
| 101 | + include_spip('balise/url_'); |
|
| 102 | + $lien = generer_generer_url_arg($type, $p, $_id_objet); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 106 | + if ($type == 'document') { |
|
| 107 | + $qconnect = _q($connect); |
|
| 108 | + $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 109 | + if ($fichier) { |
|
| 110 | + $code = "quete_logo_file($doc, $qconnect)"; |
|
| 111 | + } else { |
|
| 112 | + $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 113 | + } |
|
| 114 | + // (x=non-faux ? y : '') pour affecter x en retournant y |
|
| 115 | + if ($p->descr['documents']) { |
|
| 116 | + $code = '(($doublons["documents"] .= ",". ' |
|
| 117 | + . $_id_objet |
|
| 118 | + . ") ? $code : '')"; |
|
| 119 | + } |
|
| 120 | + } elseif ($connect) { |
|
| 121 | + $code = "''"; |
|
| 122 | + spip_logger()->info('Les logos distants ne sont pas prevus'); |
|
| 123 | + } else { |
|
| 124 | + // pour generer_code_logo |
|
| 125 | + include_spip('balise/id_logo_'); |
|
| 126 | + $champ_logo = ''; |
|
| 127 | + if ($fichier) { |
|
| 128 | + $champ_logo = 'fichier'; |
|
| 129 | + } |
|
| 130 | + $code = generer_code_logo($id_objet, $_id_objet, $type, $align, $lien, $p, $suite_logo, $champ_logo); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
|
| 134 | + if ($coord_x || $coord_y) { |
|
| 135 | + $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $p->code = $code; |
|
| 139 | + $p->interdire_scripts = false; |
|
| 140 | + |
|
| 141 | + return $p; |
|
| 142 | 142 | } |