@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Queue |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | define('_JQ_SCHEDULED', 1); |
@@ -49,101 +49,101 @@ discard block |
||
| 49 | 49 | * id of job |
| 50 | 50 | */ |
| 51 | 51 | function queue_add_job( |
| 52 | - $function, |
|
| 53 | - $description, |
|
| 54 | - $arguments = [], |
|
| 55 | - $file = '', |
|
| 56 | - $no_duplicate = false, |
|
| 57 | - $time = 0, |
|
| 58 | - $priority = 0 |
|
| 52 | + $function, |
|
| 53 | + $description, |
|
| 54 | + $arguments = [], |
|
| 55 | + $file = '', |
|
| 56 | + $no_duplicate = false, |
|
| 57 | + $time = 0, |
|
| 58 | + $priority = 0 |
|
| 59 | 59 | ) { |
| 60 | - include_spip('base/abstract_sql'); |
|
| 61 | - |
|
| 62 | - // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 63 | - if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 64 | - $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // serialiser les arguments |
|
| 68 | - $arguments = serialize($arguments); |
|
| 69 | - $md5args = md5($arguments); |
|
| 70 | - |
|
| 71 | - // si pas de date programee, des que possible |
|
| 72 | - $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 73 | - if (!$time) { |
|
| 74 | - $time = time(); |
|
| 75 | - $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 76 | - } |
|
| 77 | - $date = date('Y-m-d H:i:s', $time); |
|
| 78 | - |
|
| 79 | - $set_job = [ |
|
| 80 | - 'fonction' => $function, |
|
| 81 | - 'descriptif' => $description, |
|
| 82 | - 'args' => $arguments, |
|
| 83 | - 'md5args' => $md5args, |
|
| 84 | - 'inclure' => $file, |
|
| 85 | - 'priorite' => max(-10, min(10, intval($priority))), |
|
| 86 | - 'date' => $date, |
|
| 87 | - 'status' => _JQ_SCHEDULED, |
|
| 88 | - ]; |
|
| 89 | - // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 90 | - // avec les memes args et file |
|
| 91 | - if ( |
|
| 92 | - $no_duplicate |
|
| 93 | - && ($id_job = sql_getfetsel( |
|
| 94 | - 'id_job', |
|
| 95 | - 'spip_jobs', |
|
| 96 | - $duplicate_where = |
|
| 97 | - $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 98 | - . (($no_duplicate === 'function_only') ? '' : |
|
| 99 | - ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file)) |
|
| 100 | - )) |
|
| 101 | - ) { |
|
| 102 | - return $id_job; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 106 | - // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 107 | - // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 108 | - // doit s'effacer |
|
| 109 | - if ( |
|
| 110 | - $no_duplicate |
|
| 111 | - && ($id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where")) |
|
| 112 | - ) { |
|
| 113 | - sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 114 | - |
|
| 115 | - return $id_prev; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 119 | - // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 120 | - |
|
| 121 | - // une option de debug pour verifier que les arguments en base sont bons |
|
| 122 | - // ie cas d'un char non acceptables sur certains type de champs |
|
| 123 | - // qui coupe la valeur |
|
| 124 | - if (defined('_JQ_INSERT_CHECK_ARGS') && $id_job) { |
|
| 125 | - $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 126 | - if ($args !== $arguments) { |
|
| 127 | - spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export( |
|
| 128 | - $arguments, |
|
| 129 | - true |
|
| 130 | - ), 'queue'); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - if ($id_job) { |
|
| 135 | - queue_update_next_job_time($time); |
|
| 136 | - } |
|
| 137 | - // si la mise en file d'attente du job echoue, |
|
| 138 | - // il ne faut pas perdre l'execution de la fonction |
|
| 139 | - // on la lance immediatement, c'est un fallback |
|
| 140 | - // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 141 | - elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 142 | - $set_job['id_job'] = 0; |
|
| 143 | - queue_start_job($set_job); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $id_job; |
|
| 60 | + include_spip('base/abstract_sql'); |
|
| 61 | + |
|
| 62 | + // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 63 | + if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 64 | + $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // serialiser les arguments |
|
| 68 | + $arguments = serialize($arguments); |
|
| 69 | + $md5args = md5($arguments); |
|
| 70 | + |
|
| 71 | + // si pas de date programee, des que possible |
|
| 72 | + $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 73 | + if (!$time) { |
|
| 74 | + $time = time(); |
|
| 75 | + $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 76 | + } |
|
| 77 | + $date = date('Y-m-d H:i:s', $time); |
|
| 78 | + |
|
| 79 | + $set_job = [ |
|
| 80 | + 'fonction' => $function, |
|
| 81 | + 'descriptif' => $description, |
|
| 82 | + 'args' => $arguments, |
|
| 83 | + 'md5args' => $md5args, |
|
| 84 | + 'inclure' => $file, |
|
| 85 | + 'priorite' => max(-10, min(10, intval($priority))), |
|
| 86 | + 'date' => $date, |
|
| 87 | + 'status' => _JQ_SCHEDULED, |
|
| 88 | + ]; |
|
| 89 | + // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 90 | + // avec les memes args et file |
|
| 91 | + if ( |
|
| 92 | + $no_duplicate |
|
| 93 | + && ($id_job = sql_getfetsel( |
|
| 94 | + 'id_job', |
|
| 95 | + 'spip_jobs', |
|
| 96 | + $duplicate_where = |
|
| 97 | + $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 98 | + . (($no_duplicate === 'function_only') ? '' : |
|
| 99 | + ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file)) |
|
| 100 | + )) |
|
| 101 | + ) { |
|
| 102 | + return $id_job; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 106 | + // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 107 | + // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 108 | + // doit s'effacer |
|
| 109 | + if ( |
|
| 110 | + $no_duplicate |
|
| 111 | + && ($id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where")) |
|
| 112 | + ) { |
|
| 113 | + sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 114 | + |
|
| 115 | + return $id_prev; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 119 | + // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 120 | + |
|
| 121 | + // une option de debug pour verifier que les arguments en base sont bons |
|
| 122 | + // ie cas d'un char non acceptables sur certains type de champs |
|
| 123 | + // qui coupe la valeur |
|
| 124 | + if (defined('_JQ_INSERT_CHECK_ARGS') && $id_job) { |
|
| 125 | + $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 126 | + if ($args !== $arguments) { |
|
| 127 | + spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export( |
|
| 128 | + $arguments, |
|
| 129 | + true |
|
| 130 | + ), 'queue'); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + if ($id_job) { |
|
| 135 | + queue_update_next_job_time($time); |
|
| 136 | + } |
|
| 137 | + // si la mise en file d'attente du job echoue, |
|
| 138 | + // il ne faut pas perdre l'execution de la fonction |
|
| 139 | + // on la lance immediatement, c'est un fallback |
|
| 140 | + // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 141 | + elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 142 | + $set_job['id_job'] = 0; |
|
| 143 | + queue_start_job($set_job); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $id_job; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -152,11 +152,11 @@ discard block |
||
| 152 | 152 | * @return void |
| 153 | 153 | */ |
| 154 | 154 | function queue_purger() { |
| 155 | - include_spip('base/abstract_sql'); |
|
| 156 | - sql_delete('spip_jobs'); |
|
| 157 | - sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')'); |
|
| 158 | - include_spip('inc/genie'); |
|
| 159 | - genie_queue_watch_dist(); |
|
| 155 | + include_spip('base/abstract_sql'); |
|
| 156 | + sql_delete('spip_jobs'); |
|
| 157 | + sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')'); |
|
| 158 | + include_spip('inc/genie'); |
|
| 159 | + genie_queue_watch_dist(); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -167,25 +167,25 @@ discard block |
||
| 167 | 167 | * @return int|bool |
| 168 | 168 | */ |
| 169 | 169 | function queue_remove_job($id_job) { |
| 170 | - include_spip('base/abstract_sql'); |
|
| 171 | - |
|
| 172 | - if ( |
|
| 173 | - ($row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job))) |
|
| 174 | - && ($res = sql_delete('spip_jobs', 'id_job=' . intval($id_job))) |
|
| 175 | - ) { |
|
| 176 | - queue_unlink_job($id_job); |
|
| 177 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 178 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 179 | - // relancer avec les nouveaux arguments de temps |
|
| 180 | - include_spip('inc/genie'); |
|
| 181 | - // relancer avec la periode prevue |
|
| 182 | - queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 183 | - } |
|
| 184 | - queue_update_next_job_time(); |
|
| 185 | - return $res; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return false; |
|
| 170 | + include_spip('base/abstract_sql'); |
|
| 171 | + |
|
| 172 | + if ( |
|
| 173 | + ($row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job))) |
|
| 174 | + && ($res = sql_delete('spip_jobs', 'id_job=' . intval($id_job))) |
|
| 175 | + ) { |
|
| 176 | + queue_unlink_job($id_job); |
|
| 177 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 178 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 179 | + // relancer avec les nouveaux arguments de temps |
|
| 180 | + include_spip('inc/genie'); |
|
| 181 | + // relancer avec la periode prevue |
|
| 182 | + queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 183 | + } |
|
| 184 | + queue_update_next_job_time(); |
|
| 185 | + return $res; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return false; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -198,18 +198,18 @@ discard block |
||
| 198 | 198 | * ou un tableau composé de tableaux simples pour lieur plusieurs objets en une fois |
| 199 | 199 | */ |
| 200 | 200 | function queue_link_job($id_job, $objets) { |
| 201 | - include_spip('base/abstract_sql'); |
|
| 202 | - |
|
| 203 | - if (is_array($objets) && count($objets)) { |
|
| 204 | - if (is_array(reset($objets))) { |
|
| 205 | - foreach ($objets as $k => $o) { |
|
| 206 | - $objets[$k]['id_job'] = $id_job; |
|
| 207 | - } |
|
| 208 | - sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 209 | - } else { |
|
| 210 | - sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets)); |
|
| 211 | - } |
|
| 212 | - } |
|
| 201 | + include_spip('base/abstract_sql'); |
|
| 202 | + |
|
| 203 | + if (is_array($objets) && count($objets)) { |
|
| 204 | + if (is_array(reset($objets))) { |
|
| 205 | + foreach ($objets as $k => $o) { |
|
| 206 | + $objets[$k]['id_job'] = $id_job; |
|
| 207 | + } |
|
| 208 | + sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 209 | + } else { |
|
| 210 | + sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets)); |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | * resultat du sql_delete |
| 222 | 222 | */ |
| 223 | 223 | function queue_unlink_job($id_job) { |
| 224 | - return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job)); |
|
| 224 | + return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job)); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -234,36 +234,36 @@ discard block |
||
| 234 | 234 | */ |
| 235 | 235 | function queue_start_job($row) { |
| 236 | 236 | |
| 237 | - // deserialiser les arguments |
|
| 238 | - $args = unserialize($row['args']); |
|
| 239 | - if (!is_array($args)) { |
|
| 240 | - spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 241 | - return false; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - $fonction = $row['fonction']; |
|
| 245 | - if (strlen($inclure = trim($row['inclure']))) { |
|
| 246 | - if (str_ends_with($inclure, '/')) { // c'est un chemin pour charger_fonction |
|
| 247 | - $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 248 | - if ($f) { |
|
| 249 | - $fonction = $f; |
|
| 250 | - } |
|
| 251 | - } else { |
|
| 252 | - include_spip($inclure); |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - if (!function_exists($fonction)) { |
|
| 257 | - spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 258 | - |
|
| 259 | - return false; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 263 | - $res = $fonction(...$args); |
|
| 264 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 265 | - |
|
| 266 | - return $res; |
|
| 237 | + // deserialiser les arguments |
|
| 238 | + $args = unserialize($row['args']); |
|
| 239 | + if (!is_array($args)) { |
|
| 240 | + spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 241 | + return false; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + $fonction = $row['fonction']; |
|
| 245 | + if (strlen($inclure = trim($row['inclure']))) { |
|
| 246 | + if (str_ends_with($inclure, '/')) { // c'est un chemin pour charger_fonction |
|
| 247 | + $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 248 | + if ($f) { |
|
| 249 | + $fonction = $f; |
|
| 250 | + } |
|
| 251 | + } else { |
|
| 252 | + include_spip($inclure); |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + if (!function_exists($fonction)) { |
|
| 257 | + spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 258 | + |
|
| 259 | + return false; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 263 | + $res = $fonction(...$args); |
|
| 264 | + spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 265 | + |
|
| 266 | + return $res; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -290,89 +290,89 @@ discard block |
||
| 290 | 290 | * - true : une planification a été faite. |
| 291 | 291 | */ |
| 292 | 292 | function queue_schedule($force_jobs = null) { |
| 293 | - $time = time(); |
|
| 294 | - if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 295 | - spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG); |
|
| 296 | - |
|
| 297 | - return; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - // rien a faire si le prochain job est encore dans le futur |
|
| 301 | - if (queue_sleep_time_to_next_job() > 0 && (!$force_jobs || !count($force_jobs))) { |
|
| 302 | - spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG); |
|
| 303 | - |
|
| 304 | - return; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - include_spip('base/abstract_sql'); |
|
| 308 | - // on ne peut rien faire si pas de connexion SQL |
|
| 309 | - if (!spip_connect()) { |
|
| 310 | - return false; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 314 | - $max_time = ini_get('max_execution_time') / 2; |
|
| 315 | - // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 316 | - if (!$max_time) { |
|
| 317 | - $max_time = 5; |
|
| 318 | - } |
|
| 319 | - define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 320 | - } |
|
| 321 | - $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 322 | - |
|
| 323 | - spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 324 | - |
|
| 325 | - if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 326 | - define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 327 | - } |
|
| 328 | - $nbj = 0; |
|
| 329 | - // attraper les jobs |
|
| 330 | - // dont la date est passee (echus en attente), |
|
| 331 | - // par ordre : |
|
| 332 | - // - de priorite |
|
| 333 | - // - de date |
|
| 334 | - // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 335 | - // pour qu'il ne bloque pas les autres jobs en attente |
|
| 336 | - if (is_array($force_jobs) && count($force_jobs)) { |
|
| 337 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs); |
|
| 338 | - } else { |
|
| 339 | - $now = date('Y-m-d H:i:s', $time); |
|
| 340 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 344 | - $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 345 | - do { |
|
| 346 | - if ($row = array_shift($res)) { |
|
| 347 | - $nbj++; |
|
| 348 | - // il faut un verrou, a base de sql_delete |
|
| 349 | - if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) { |
|
| 350 | - #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 351 | - // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 352 | - $row['status'] = _JQ_PENDING; |
|
| 353 | - $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 354 | - sql_insertq('spip_jobs', $row); |
|
| 355 | - |
|
| 356 | - // on a la main sur le job : |
|
| 357 | - // l'executer |
|
| 358 | - $result = queue_start_job($row); |
|
| 359 | - |
|
| 360 | - $time = time(); |
|
| 361 | - queue_close_job($row, $time, $result); |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG); |
|
| 365 | - } while ($nbj < _JQ_MAX_JOBS_EXECUTE && $row && $time < $end_time); |
|
| 366 | - spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG); |
|
| 367 | - |
|
| 368 | - if ($row = array_shift($res)) { |
|
| 369 | - queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 370 | - spip_log('JQ encore !', 'jq' . _LOG_DEBUG); |
|
| 371 | - } else { |
|
| 372 | - queue_update_next_job_time(); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - return true; |
|
| 293 | + $time = time(); |
|
| 294 | + if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 295 | + spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG); |
|
| 296 | + |
|
| 297 | + return; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + // rien a faire si le prochain job est encore dans le futur |
|
| 301 | + if (queue_sleep_time_to_next_job() > 0 && (!$force_jobs || !count($force_jobs))) { |
|
| 302 | + spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG); |
|
| 303 | + |
|
| 304 | + return; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + include_spip('base/abstract_sql'); |
|
| 308 | + // on ne peut rien faire si pas de connexion SQL |
|
| 309 | + if (!spip_connect()) { |
|
| 310 | + return false; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 314 | + $max_time = ini_get('max_execution_time') / 2; |
|
| 315 | + // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 316 | + if (!$max_time) { |
|
| 317 | + $max_time = 5; |
|
| 318 | + } |
|
| 319 | + define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 320 | + } |
|
| 321 | + $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 322 | + |
|
| 323 | + spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 324 | + |
|
| 325 | + if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 326 | + define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 327 | + } |
|
| 328 | + $nbj = 0; |
|
| 329 | + // attraper les jobs |
|
| 330 | + // dont la date est passee (echus en attente), |
|
| 331 | + // par ordre : |
|
| 332 | + // - de priorite |
|
| 333 | + // - de date |
|
| 334 | + // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 335 | + // pour qu'il ne bloque pas les autres jobs en attente |
|
| 336 | + if (is_array($force_jobs) && count($force_jobs)) { |
|
| 337 | + $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs); |
|
| 338 | + } else { |
|
| 339 | + $now = date('Y-m-d H:i:s', $time); |
|
| 340 | + $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 344 | + $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 345 | + do { |
|
| 346 | + if ($row = array_shift($res)) { |
|
| 347 | + $nbj++; |
|
| 348 | + // il faut un verrou, a base de sql_delete |
|
| 349 | + if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) { |
|
| 350 | + #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 351 | + // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 352 | + $row['status'] = _JQ_PENDING; |
|
| 353 | + $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 354 | + sql_insertq('spip_jobs', $row); |
|
| 355 | + |
|
| 356 | + // on a la main sur le job : |
|
| 357 | + // l'executer |
|
| 358 | + $result = queue_start_job($row); |
|
| 359 | + |
|
| 360 | + $time = time(); |
|
| 361 | + queue_close_job($row, $time, $result); |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG); |
|
| 365 | + } while ($nbj < _JQ_MAX_JOBS_EXECUTE && $row && $time < $end_time); |
|
| 366 | + spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG); |
|
| 367 | + |
|
| 368 | + if ($row = array_shift($res)) { |
|
| 369 | + queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 370 | + spip_log('JQ encore !', 'jq' . _LOG_DEBUG); |
|
| 371 | + } else { |
|
| 372 | + queue_update_next_job_time(); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + return true; |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | /** |
@@ -390,21 +390,21 @@ discard block |
||
| 390 | 390 | * @param int $result |
| 391 | 391 | */ |
| 392 | 392 | function queue_close_job(&$row, $time, $result = 0) { |
| 393 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 394 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 395 | - // relancer avec les nouveaux arguments de temps |
|
| 396 | - include_spip('inc/genie'); |
|
| 397 | - if ($result < 0) { // relancer tout de suite, mais en baissant la priorite |
|
| 398 | - queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 399 | - } else // relancer avec la periode prevue |
|
| 400 | - { |
|
| 401 | - queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - // purger ses liens eventuels avec des objets |
|
| 405 | - sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job'])); |
|
| 406 | - // supprimer le job fini |
|
| 407 | - sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 393 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 394 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 395 | + // relancer avec les nouveaux arguments de temps |
|
| 396 | + include_spip('inc/genie'); |
|
| 397 | + if ($result < 0) { // relancer tout de suite, mais en baissant la priorite |
|
| 398 | + queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 399 | + } else // relancer avec la periode prevue |
|
| 400 | + { |
|
| 401 | + queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + // purger ses liens eventuels avec des objets |
|
| 405 | + sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job'])); |
|
| 406 | + // supprimer le job fini |
|
| 407 | + sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
@@ -414,10 +414,10 @@ discard block |
||
| 414 | 414 | * @uses queue_update_next_job_time() |
| 415 | 415 | */ |
| 416 | 416 | function queue_error_handler() { |
| 417 | - // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 418 | - chdir(_ROOT_CWD); |
|
| 417 | + // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 418 | + chdir(_ROOT_CWD); |
|
| 419 | 419 | |
| 420 | - queue_update_next_job_time(); |
|
| 420 | + queue_update_next_job_time(); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | |
@@ -434,18 +434,18 @@ discard block |
||
| 434 | 434 | * Périodicité de la tâche en secondes, si tâche périodique, sinon false. |
| 435 | 435 | */ |
| 436 | 436 | function queue_is_cron_job($function, $inclure) { |
| 437 | - static $taches = null; |
|
| 438 | - if (str_starts_with($inclure, 'genie/')) { |
|
| 439 | - if (is_null($taches)) { |
|
| 440 | - include_spip('inc/genie'); |
|
| 441 | - $taches = taches_generales(); |
|
| 442 | - } |
|
| 443 | - if (isset($taches[$function])) { |
|
| 444 | - return $taches[$function]; |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - return false; |
|
| 437 | + static $taches = null; |
|
| 438 | + if (str_starts_with($inclure, 'genie/')) { |
|
| 439 | + if (is_null($taches)) { |
|
| 440 | + include_spip('inc/genie'); |
|
| 441 | + $taches = taches_generales(); |
|
| 442 | + } |
|
| 443 | + if (isset($taches[$function])) { |
|
| 444 | + return $taches[$function]; |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + return false; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -459,62 +459,62 @@ discard block |
||
| 459 | 459 | * temps de la tache ajoutee ou 0 pour ASAP |
| 460 | 460 | */ |
| 461 | 461 | function queue_update_next_job_time($next_time = null) { |
| 462 | - static $nb_jobs_scheduled = null; |
|
| 463 | - static $deja_la = false; |
|
| 464 | - // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 465 | - static $next = null; |
|
| 466 | - // queue_close_job peut etre reentrant ici |
|
| 467 | - if ($deja_la) { |
|
| 468 | - return; |
|
| 469 | - } |
|
| 470 | - $deja_la = true; |
|
| 471 | - |
|
| 472 | - include_spip('base/abstract_sql'); |
|
| 473 | - $time = time(); |
|
| 474 | - |
|
| 475 | - // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 476 | - // pour cause de timeout ou autre erreur fatale |
|
| 477 | - $res = sql_allfetsel( |
|
| 478 | - '*', |
|
| 479 | - 'spip_jobs', |
|
| 480 | - 'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 481 | - ); |
|
| 482 | - if (is_array($res)) { |
|
| 483 | - foreach ($res as $row) { |
|
| 484 | - queue_close_job($row, $time); |
|
| 485 | - spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, true), 'job_mort' . _LOG_ERREUR); |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - // chercher la date du prochain job si pas connu |
|
| 490 | - if (is_null($next) || is_null(queue_sleep_time_to_next_job())) { |
|
| 491 | - $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 492 | - $next = strtotime($date); |
|
| 493 | - } |
|
| 494 | - if (!is_null($next_time)) { |
|
| 495 | - if (is_null($next) || $next > $next_time) { |
|
| 496 | - $next = $next_time; |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - if ($next) { |
|
| 501 | - if (is_null($nb_jobs_scheduled)) { |
|
| 502 | - $nb_jobs_scheduled = sql_countsel( |
|
| 503 | - 'spip_jobs', |
|
| 504 | - 'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 505 | - ); |
|
| 506 | - } elseif ($next <= $time) { |
|
| 507 | - $nb_jobs_scheduled++; |
|
| 508 | - } |
|
| 509 | - // si trop de jobs en attente, on force la purge en fin de hit |
|
| 510 | - // pour assurer le coup |
|
| 511 | - if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 512 | - define('_DIRECT_CRON_FORCE', true); |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - queue_set_next_job_time($next); |
|
| 517 | - $deja_la = false; |
|
| 462 | + static $nb_jobs_scheduled = null; |
|
| 463 | + static $deja_la = false; |
|
| 464 | + // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 465 | + static $next = null; |
|
| 466 | + // queue_close_job peut etre reentrant ici |
|
| 467 | + if ($deja_la) { |
|
| 468 | + return; |
|
| 469 | + } |
|
| 470 | + $deja_la = true; |
|
| 471 | + |
|
| 472 | + include_spip('base/abstract_sql'); |
|
| 473 | + $time = time(); |
|
| 474 | + |
|
| 475 | + // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 476 | + // pour cause de timeout ou autre erreur fatale |
|
| 477 | + $res = sql_allfetsel( |
|
| 478 | + '*', |
|
| 479 | + 'spip_jobs', |
|
| 480 | + 'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 481 | + ); |
|
| 482 | + if (is_array($res)) { |
|
| 483 | + foreach ($res as $row) { |
|
| 484 | + queue_close_job($row, $time); |
|
| 485 | + spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, true), 'job_mort' . _LOG_ERREUR); |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + // chercher la date du prochain job si pas connu |
|
| 490 | + if (is_null($next) || is_null(queue_sleep_time_to_next_job())) { |
|
| 491 | + $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 492 | + $next = strtotime($date); |
|
| 493 | + } |
|
| 494 | + if (!is_null($next_time)) { |
|
| 495 | + if (is_null($next) || $next > $next_time) { |
|
| 496 | + $next = $next_time; |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + if ($next) { |
|
| 501 | + if (is_null($nb_jobs_scheduled)) { |
|
| 502 | + $nb_jobs_scheduled = sql_countsel( |
|
| 503 | + 'spip_jobs', |
|
| 504 | + 'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 505 | + ); |
|
| 506 | + } elseif ($next <= $time) { |
|
| 507 | + $nb_jobs_scheduled++; |
|
| 508 | + } |
|
| 509 | + // si trop de jobs en attente, on force la purge en fin de hit |
|
| 510 | + // pour assurer le coup |
|
| 511 | + if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 512 | + define('_DIRECT_CRON_FORCE', true); |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + queue_set_next_job_time($next); |
|
| 517 | + $deja_la = false; |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | |
@@ -525,26 +525,26 @@ discard block |
||
| 525 | 525 | */ |
| 526 | 526 | function queue_set_next_job_time($next) { |
| 527 | 527 | |
| 528 | - // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 529 | - $time = time(); |
|
| 530 | - |
|
| 531 | - // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 532 | - // et ne mettre a jour que si il y a un interet a le faire |
|
| 533 | - // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 534 | - $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 535 | - if ( |
|
| 536 | - $curr_next <= $time && $next > $time // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 537 | - || $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 538 | - ) { |
|
| 539 | - if (function_exists('cache_set') && defined('_MEMOIZE_MEMORY') && _MEMOIZE_MEMORY) { |
|
| 540 | - cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 541 | - } else { |
|
| 542 | - ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 543 | - } |
|
| 544 | - queue_sleep_time_to_next_job($next); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - return queue_sleep_time_to_next_job(); |
|
| 528 | + // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 529 | + $time = time(); |
|
| 530 | + |
|
| 531 | + // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 532 | + // et ne mettre a jour que si il y a un interet a le faire |
|
| 533 | + // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 534 | + $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 535 | + if ( |
|
| 536 | + $curr_next <= $time && $next > $time // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 537 | + || $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 538 | + ) { |
|
| 539 | + if (function_exists('cache_set') && defined('_MEMOIZE_MEMORY') && _MEMOIZE_MEMORY) { |
|
| 540 | + cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 541 | + } else { |
|
| 542 | + ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 543 | + } |
|
| 544 | + queue_sleep_time_to_next_job($next); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + return queue_sleep_time_to_next_job(); |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | /** |
@@ -561,60 +561,60 @@ discard block |
||
| 561 | 561 | * @return string |
| 562 | 562 | */ |
| 563 | 563 | function queue_affichage_cron() { |
| 564 | - $texte = ''; |
|
| 565 | - |
|
| 566 | - $time_to_next = queue_sleep_time_to_next_job(); |
|
| 567 | - // rien a faire si le prochain job est encore dans le futur |
|
| 568 | - if ($time_to_next > 0 || defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 569 | - return $texte; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 573 | - if (file_exists($lock = _DIR_TMP . 'cron.lock') && !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 574 | - return $texte; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - @touch($lock); |
|
| 578 | - |
|
| 579 | - // il y a des taches en attentes |
|
| 580 | - // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 581 | - // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 582 | - $urgent = false; |
|
| 583 | - if ($time_to_next < -300) { |
|
| 584 | - $urgent = true; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - $url_cron = generer_url_action('cron', '', false, true); |
|
| 588 | - |
|
| 589 | - if (!defined('_HTML_BG_CRON_FORCE') || !_HTML_BG_CRON_FORCE) { |
|
| 590 | - if (queue_lancer_url_http_async($url_cron) && !$urgent) { |
|
| 591 | - return $texte; |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - // si deja force, on retourne sans rien |
|
| 596 | - if (defined('_DIRECT_CRON_FORCE')) { |
|
| 597 | - return $texte; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - // si c'est un bot |
|
| 601 | - // inutile de faire un appel par image background, |
|
| 602 | - // on force un appel direct en fin de hit |
|
| 603 | - if ((defined('_IS_BOT') && _IS_BOT)) { |
|
| 604 | - define('_DIRECT_CRON_FORCE', true); |
|
| 605 | - |
|
| 606 | - return $texte; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - if (!defined('_HTML_BG_CRON_INHIB') || !_HTML_BG_CRON_INHIB) { |
|
| 610 | - // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 611 | - $url_cron = generer_url_action('cron'); |
|
| 612 | - $texte = '<!-- SPIP-CRON -->' |
|
| 613 | - . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 614 | - . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return $texte; |
|
| 564 | + $texte = ''; |
|
| 565 | + |
|
| 566 | + $time_to_next = queue_sleep_time_to_next_job(); |
|
| 567 | + // rien a faire si le prochain job est encore dans le futur |
|
| 568 | + if ($time_to_next > 0 || defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 569 | + return $texte; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 573 | + if (file_exists($lock = _DIR_TMP . 'cron.lock') && !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 574 | + return $texte; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + @touch($lock); |
|
| 578 | + |
|
| 579 | + // il y a des taches en attentes |
|
| 580 | + // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 581 | + // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 582 | + $urgent = false; |
|
| 583 | + if ($time_to_next < -300) { |
|
| 584 | + $urgent = true; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + $url_cron = generer_url_action('cron', '', false, true); |
|
| 588 | + |
|
| 589 | + if (!defined('_HTML_BG_CRON_FORCE') || !_HTML_BG_CRON_FORCE) { |
|
| 590 | + if (queue_lancer_url_http_async($url_cron) && !$urgent) { |
|
| 591 | + return $texte; |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + // si deja force, on retourne sans rien |
|
| 596 | + if (defined('_DIRECT_CRON_FORCE')) { |
|
| 597 | + return $texte; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + // si c'est un bot |
|
| 601 | + // inutile de faire un appel par image background, |
|
| 602 | + // on force un appel direct en fin de hit |
|
| 603 | + if ((defined('_IS_BOT') && _IS_BOT)) { |
|
| 604 | + define('_DIRECT_CRON_FORCE', true); |
|
| 605 | + |
|
| 606 | + return $texte; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + if (!defined('_HTML_BG_CRON_INHIB') || !_HTML_BG_CRON_INHIB) { |
|
| 610 | + // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 611 | + $url_cron = generer_url_action('cron'); |
|
| 612 | + $texte = '<!-- SPIP-CRON -->' |
|
| 613 | + . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 614 | + . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return $texte; |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -623,73 +623,73 @@ discard block |
||
| 623 | 623 | * @return bool : true si l'url a pu être appelée en asynchrone, false sinon |
| 624 | 624 | */ |
| 625 | 625 | function queue_lancer_url_http_async($url_cron) { |
| 626 | - // methode la plus rapide : |
|
| 627 | - // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 628 | - // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 629 | - // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 630 | - // mais on renvoie false direct |
|
| 631 | - if (function_exists('fsockopen')) { |
|
| 632 | - $parts = parse_url($url_cron); |
|
| 633 | - |
|
| 634 | - switch ($parts['scheme']) { |
|
| 635 | - case 'https': |
|
| 636 | - $scheme = 'ssl://'; |
|
| 637 | - $port = 443; |
|
| 638 | - break; |
|
| 639 | - case 'http': |
|
| 640 | - default: |
|
| 641 | - $scheme = ''; |
|
| 642 | - $port = 80; |
|
| 643 | - } |
|
| 644 | - $fp = @fsockopen( |
|
| 645 | - $scheme . $parts['host'], |
|
| 646 | - $parts['port'] ?? $port, |
|
| 647 | - $errno, |
|
| 648 | - $errstr, |
|
| 649 | - 1 |
|
| 650 | - ); |
|
| 651 | - |
|
| 652 | - if ($fp) { |
|
| 653 | - $host_sent = $parts['host']; |
|
| 654 | - if (isset($parts['port']) && $parts['port'] !== $port) { |
|
| 655 | - $host_sent .= ':' . $parts['port']; |
|
| 656 | - } |
|
| 657 | - $timeout = 200; // ms |
|
| 658 | - stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 659 | - $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : ''); |
|
| 660 | - $out = 'GET ' . $query . " HTTP/1.1\r\n"; |
|
| 661 | - $out .= 'Host: ' . $host_sent . "\r\n"; |
|
| 662 | - $out .= "Connection: Close\r\n\r\n"; |
|
| 663 | - fwrite($fp, $out); |
|
| 664 | - spip_timer('read'); |
|
| 665 | - $t = 0; |
|
| 666 | - // on lit la reponse si possible pour fermer proprement la connexion |
|
| 667 | - // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 668 | - while (!feof($fp) && $t < $timeout) { |
|
| 669 | - @fgets($fp, 1024); |
|
| 670 | - $t += spip_timer('read', true); |
|
| 671 | - spip_timer('read'); |
|
| 672 | - } |
|
| 673 | - fclose($fp); |
|
| 674 | - return true; |
|
| 675 | - } |
|
| 676 | - } |
|
| 677 | - // si fsockopen n'est pas dispo on essaye cURL : |
|
| 678 | - // lancer le cron par un cURL asynchrone si cURL est present |
|
| 679 | - elseif (function_exists('curl_init')) { |
|
| 680 | - //setting the curl parameters. |
|
| 681 | - $ch = curl_init($url_cron); |
|
| 682 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 683 | - // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 684 | - curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 685 | - // valeur mini pour que la requete soit lancee |
|
| 686 | - curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 687 | - // lancer |
|
| 688 | - curl_exec($ch); |
|
| 689 | - // fermer |
|
| 690 | - curl_close($ch); |
|
| 691 | - return true; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - return false; |
|
| 626 | + // methode la plus rapide : |
|
| 627 | + // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 628 | + // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 629 | + // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 630 | + // mais on renvoie false direct |
|
| 631 | + if (function_exists('fsockopen')) { |
|
| 632 | + $parts = parse_url($url_cron); |
|
| 633 | + |
|
| 634 | + switch ($parts['scheme']) { |
|
| 635 | + case 'https': |
|
| 636 | + $scheme = 'ssl://'; |
|
| 637 | + $port = 443; |
|
| 638 | + break; |
|
| 639 | + case 'http': |
|
| 640 | + default: |
|
| 641 | + $scheme = ''; |
|
| 642 | + $port = 80; |
|
| 643 | + } |
|
| 644 | + $fp = @fsockopen( |
|
| 645 | + $scheme . $parts['host'], |
|
| 646 | + $parts['port'] ?? $port, |
|
| 647 | + $errno, |
|
| 648 | + $errstr, |
|
| 649 | + 1 |
|
| 650 | + ); |
|
| 651 | + |
|
| 652 | + if ($fp) { |
|
| 653 | + $host_sent = $parts['host']; |
|
| 654 | + if (isset($parts['port']) && $parts['port'] !== $port) { |
|
| 655 | + $host_sent .= ':' . $parts['port']; |
|
| 656 | + } |
|
| 657 | + $timeout = 200; // ms |
|
| 658 | + stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 659 | + $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : ''); |
|
| 660 | + $out = 'GET ' . $query . " HTTP/1.1\r\n"; |
|
| 661 | + $out .= 'Host: ' . $host_sent . "\r\n"; |
|
| 662 | + $out .= "Connection: Close\r\n\r\n"; |
|
| 663 | + fwrite($fp, $out); |
|
| 664 | + spip_timer('read'); |
|
| 665 | + $t = 0; |
|
| 666 | + // on lit la reponse si possible pour fermer proprement la connexion |
|
| 667 | + // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 668 | + while (!feof($fp) && $t < $timeout) { |
|
| 669 | + @fgets($fp, 1024); |
|
| 670 | + $t += spip_timer('read', true); |
|
| 671 | + spip_timer('read'); |
|
| 672 | + } |
|
| 673 | + fclose($fp); |
|
| 674 | + return true; |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | + // si fsockopen n'est pas dispo on essaye cURL : |
|
| 678 | + // lancer le cron par un cURL asynchrone si cURL est present |
|
| 679 | + elseif (function_exists('curl_init')) { |
|
| 680 | + //setting the curl parameters. |
|
| 681 | + $ch = curl_init($url_cron); |
|
| 682 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 683 | + // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 684 | + curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 685 | + // valeur mini pour que la requete soit lancee |
|
| 686 | + curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 687 | + // lancer |
|
| 688 | + curl_exec($ch); |
|
| 689 | + // fermer |
|
| 690 | + curl_close($ch); |
|
| 691 | + return true; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + return false; |
|
| 695 | 695 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @package SPIP\Core\Filtres |
| 21 | 21 | **/ |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | include_spip('inc/charsets'); |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | * @return string Fonction PHP correspondante du filtre |
| 47 | 47 | */ |
| 48 | 48 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 49 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 50 | - return chercher_filtre($fonc, $default); |
|
| 49 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 50 | + return chercher_filtre($fonc, $default); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @return string texte |
| 58 | 58 | **/ |
| 59 | 59 | function filtre_identite_dist($texte) { |
| 60 | - return $texte; |
|
| 60 | + return $texte; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -81,33 +81,33 @@ discard block |
||
| 81 | 81 | * Fonction PHP correspondante du filtre demandé |
| 82 | 82 | */ |
| 83 | 83 | function chercher_filtre($fonc, $default = null) { |
| 84 | - if (!$fonc) { |
|
| 85 | - return $default; |
|
| 86 | - } |
|
| 87 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 88 | - // Foo::Bar |
|
| 89 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 90 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 91 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 92 | - $f = chercher_filtre($nom); |
|
| 93 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 94 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 95 | - if (!$f && $nom !== $fonc) { |
|
| 96 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return $f; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - include_fichiers_fonctions(); |
|
| 103 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 104 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 105 | - if (is_callable($f)) { |
|
| 106 | - return $f; |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return $default; |
|
| 84 | + if (!$fonc) { |
|
| 85 | + return $default; |
|
| 86 | + } |
|
| 87 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 88 | + // Foo::Bar |
|
| 89 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 90 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 91 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 92 | + $f = chercher_filtre($nom); |
|
| 93 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 94 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 95 | + if (!$f && $nom !== $fonc) { |
|
| 96 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return $f; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + include_fichiers_fonctions(); |
|
| 103 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 104 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 105 | + if (is_callable($f)) { |
|
| 106 | + return $f; |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return $default; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | * Chaîne vide sinon. |
| 152 | 152 | **/ |
| 153 | 153 | function appliquer_filtre(mixed $arg, $filtre) { |
| 154 | - $args = func_get_args(); |
|
| 155 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 154 | + $args = func_get_args(); |
|
| 155 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -177,8 +177,8 @@ discard block |
||
| 177 | 177 | * texte d'origine sinon |
| 178 | 178 | **/ |
| 179 | 179 | function appliquer_si_filtre(mixed $arg, $filtre) { |
| 180 | - $args = func_get_args(); |
|
| 181 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 180 | + $args = func_get_args(); |
|
| 181 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -194,12 +194,12 @@ discard block |
||
| 194 | 194 | * Version de SPIP |
| 195 | 195 | **/ |
| 196 | 196 | function spip_version() { |
| 197 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 198 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 199 | - $version .= " $vcs_version"; |
|
| 200 | - } |
|
| 197 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 198 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 199 | + $version .= " $vcs_version"; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - return $version; |
|
| 202 | + return $version; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -211,11 +211,11 @@ discard block |
||
| 211 | 211 | * @return string |
| 212 | 212 | */ |
| 213 | 213 | function header_silencieux($version): string { |
| 214 | - if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 215 | - $version = ''; |
|
| 216 | - } |
|
| 214 | + if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 215 | + $version = ''; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - return (string) $version; |
|
| 218 | + return (string) $version; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -228,16 +228,16 @@ discard block |
||
| 228 | 228 | * - string|null si $raw = false |
| 229 | 229 | */ |
| 230 | 230 | function version_vcs_courante($dir, $raw = false) { |
| 231 | - $desc = decrire_version_git($dir); |
|
| 232 | - if ($desc === null || $raw) { |
|
| 233 | - return $desc; |
|
| 234 | - } |
|
| 235 | - // affichage "GIT [master: abcdef]" |
|
| 236 | - $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 237 | - if ($desc['branch']) { |
|
| 238 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 239 | - } |
|
| 240 | - return "{$desc['vcs']} [$commit]"; |
|
| 231 | + $desc = decrire_version_git($dir); |
|
| 232 | + if ($desc === null || $raw) { |
|
| 233 | + return $desc; |
|
| 234 | + } |
|
| 235 | + // affichage "GIT [master: abcdef]" |
|
| 236 | + $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 237 | + if ($desc['branch']) { |
|
| 238 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 239 | + } |
|
| 240 | + return "{$desc['vcs']} [$commit]"; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -249,26 +249,26 @@ discard block |
||
| 249 | 249 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 250 | 250 | **/ |
| 251 | 251 | function decrire_version_git($dir) { |
| 252 | - $c = null; |
|
| 253 | - $hash = null; |
|
| 254 | - if (!$dir) { |
|
| 255 | - $dir = '.'; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - // version installee par GIT |
|
| 259 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 260 | - $currentHead = trim(substr((string) $c, 4)); |
|
| 261 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 262 | - return [ |
|
| 263 | - 'vcs' => 'GIT', |
|
| 264 | - 'branch' => basename($currentHead), |
|
| 265 | - 'commit' => trim((string) $hash), |
|
| 266 | - 'commit_short' => substr(trim((string) $hash), 0, 8), |
|
| 267 | - ]; |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - return null; |
|
| 252 | + $c = null; |
|
| 253 | + $hash = null; |
|
| 254 | + if (!$dir) { |
|
| 255 | + $dir = '.'; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + // version installee par GIT |
|
| 259 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 260 | + $currentHead = trim(substr((string) $c, 4)); |
|
| 261 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 262 | + return [ |
|
| 263 | + 'vcs' => 'GIT', |
|
| 264 | + 'branch' => basename($currentHead), |
|
| 265 | + 'commit' => trim((string) $hash), |
|
| 266 | + 'commit_short' => substr(trim((string) $hash), 0, 8), |
|
| 267 | + ]; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + return null; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -315,18 +315,18 @@ discard block |
||
| 315 | 315 | * Code HTML retourné par le filtre |
| 316 | 316 | **/ |
| 317 | 317 | function filtrer($filtre) { |
| 318 | - $tous = func_get_args(); |
|
| 319 | - if (trouver_filtre_matrice($filtre) && str_starts_with($filtre, 'image_')) { |
|
| 320 | - return image_filtrer($tous); |
|
| 321 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 322 | - array_shift($tous); |
|
| 323 | - return $f(...$tous); |
|
| 324 | - } else { |
|
| 325 | - // le filtre n'existe pas, on provoque une erreur |
|
| 326 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 327 | - erreur_squelette($msg); |
|
| 328 | - return ''; |
|
| 329 | - } |
|
| 318 | + $tous = func_get_args(); |
|
| 319 | + if (trouver_filtre_matrice($filtre) && str_starts_with($filtre, 'image_')) { |
|
| 320 | + return image_filtrer($tous); |
|
| 321 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 322 | + array_shift($tous); |
|
| 323 | + return $f(...$tous); |
|
| 324 | + } else { |
|
| 325 | + // le filtre n'existe pas, on provoque une erreur |
|
| 326 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 327 | + erreur_squelette($msg); |
|
| 328 | + return ''; |
|
| 329 | + } |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
@@ -343,11 +343,11 @@ discard block |
||
| 343 | 343 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 344 | 344 | */ |
| 345 | 345 | function trouver_filtre_matrice($filtre) { |
| 346 | - if (isset($GLOBALS['spip_matrice'][$filtre]) && is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 347 | - find_in_path($f, '', true); |
|
| 348 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 349 | - } |
|
| 350 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 346 | + if (isset($GLOBALS['spip_matrice'][$filtre]) && is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 347 | + find_in_path($f, '', true); |
|
| 348 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 349 | + } |
|
| 350 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | |
@@ -375,8 +375,8 @@ discard block |
||
| 375 | 375 | * @return mixed |
| 376 | 376 | */ |
| 377 | 377 | function filtre_set(&$Pile, mixed $val, $key, $continue = null) { |
| 378 | - $Pile['vars'][$key] = $val; |
|
| 379 | - return $continue ? $val : ''; |
|
| 378 | + $Pile['vars'][$key] = $val; |
|
| 379 | + return $continue ? $val : ''; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | /** |
@@ -402,8 +402,8 @@ discard block |
||
| 402 | 402 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 403 | 403 | */ |
| 404 | 404 | function filtre_setenv(&$Pile, mixed $val, mixed $key, $continue = null) { |
| 405 | - $Pile[0][$key] = $val; |
|
| 406 | - return $continue ? $val : ''; |
|
| 405 | + $Pile[0][$key] = $val; |
|
| 406 | + return $continue ? $val : ''; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -412,8 +412,8 @@ discard block |
||
| 412 | 412 | * @return string |
| 413 | 413 | */ |
| 414 | 414 | function filtre_sanitize_env(&$Pile, $keys) { |
| 415 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 416 | - return ''; |
|
| 415 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 416 | + return ''; |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | |
@@ -436,18 +436,18 @@ discard block |
||
| 436 | 436 | * @return mixed Retourne la valeur (sans la modifier). |
| 437 | 437 | */ |
| 438 | 438 | function filtre_debug(mixed $val, $key = null) { |
| 439 | - $debug = ( |
|
| 440 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 441 | - ) . var_export($val, true); |
|
| 439 | + $debug = ( |
|
| 440 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 441 | + ) . var_export($val, true); |
|
| 442 | 442 | |
| 443 | - include_spip('inc/autoriser'); |
|
| 444 | - if (autoriser('webmestre')) { |
|
| 445 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 446 | - } |
|
| 443 | + include_spip('inc/autoriser'); |
|
| 444 | + if (autoriser('webmestre')) { |
|
| 445 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 446 | + } |
|
| 447 | 447 | |
| 448 | - spip_log($debug, 'debug'); |
|
| 448 | + spip_log($debug, 'debug'); |
|
| 449 | 449 | |
| 450 | - return $val; |
|
| 450 | + return $val; |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | |
@@ -477,81 +477,81 @@ discard block |
||
| 477 | 477 | * texte qui a reçu les filtres |
| 478 | 478 | **/ |
| 479 | 479 | function image_filtrer($args) { |
| 480 | - $filtre = array_shift($args); # enlever $filtre |
|
| 481 | - $texte = array_shift($args); |
|
| 482 | - if ($texte === null || !strlen((string) $texte)) { |
|
| 483 | - return ''; |
|
| 484 | - } |
|
| 485 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 486 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 487 | - // Cas du nom de fichier local |
|
| 488 | - $is_file = trim((string) $texte); |
|
| 489 | - if ( |
|
| 490 | - str_contains(substr($is_file, strlen(_DIR_RACINE)), '..') |
|
| 491 | - || strpbrk($is_file, "<>\n\r\t") !== false |
|
| 492 | - || str_starts_with($is_file, '/') |
|
| 493 | - ) { |
|
| 494 | - $is_file = false; |
|
| 495 | - } |
|
| 496 | - if ($is_file) { |
|
| 497 | - $is_local_file = function ($path) { |
|
| 498 | - if (str_contains($path, '?')) { |
|
| 499 | - $path = supprimer_timestamp($path); |
|
| 500 | - // remove ?24px added by find_in_theme on .svg files |
|
| 501 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 502 | - } |
|
| 503 | - return file_exists($path); |
|
| 504 | - }; |
|
| 505 | - if ($is_local_file($is_file) || tester_url_absolue($is_file)) { |
|
| 506 | - $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 507 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 508 | - return $res; |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 513 | - if ( |
|
| 514 | - preg_match_all( |
|
| 515 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 516 | - (string) $texte, |
|
| 517 | - $tags, |
|
| 518 | - PREG_SET_ORDER |
|
| 519 | - ) |
|
| 520 | - ) { |
|
| 521 | - foreach ($tags as $tag) { |
|
| 522 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 523 | - if ( |
|
| 524 | - (!$class || !str_contains($class, 'filtre_inactif')) |
|
| 525 | - && ($reduit = $filtre($tag[3], ...$args)) |
|
| 526 | - ) { |
|
| 527 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 528 | - if ($tag[1]) { |
|
| 529 | - $w = extraire_attribut($reduit, 'width'); |
|
| 530 | - if (!$w && preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 531 | - $w = $regs[1]; |
|
| 532 | - } |
|
| 533 | - if ($w && ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 534 | - $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 535 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 536 | - $texte = str_replace($tag[1], $replace, (string) $texte); |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - // traiter aussi un eventuel mouseover |
|
| 540 | - if ( |
|
| 541 | - ($mouseover = extraire_attribut($reduit, 'onmouseover')) |
|
| 542 | - && preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match) |
|
| 543 | - ) { |
|
| 544 | - $srcover = $match[1]; |
|
| 545 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 546 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 547 | - $reduit = str_replace($srcover, $srcover_filter, (string) $reduit); |
|
| 548 | - } |
|
| 549 | - $texte = str_replace($tag[3], $reduit, (string) $texte); |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 554 | - return $texte; |
|
| 480 | + $filtre = array_shift($args); # enlever $filtre |
|
| 481 | + $texte = array_shift($args); |
|
| 482 | + if ($texte === null || !strlen((string) $texte)) { |
|
| 483 | + return ''; |
|
| 484 | + } |
|
| 485 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 486 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 487 | + // Cas du nom de fichier local |
|
| 488 | + $is_file = trim((string) $texte); |
|
| 489 | + if ( |
|
| 490 | + str_contains(substr($is_file, strlen(_DIR_RACINE)), '..') |
|
| 491 | + || strpbrk($is_file, "<>\n\r\t") !== false |
|
| 492 | + || str_starts_with($is_file, '/') |
|
| 493 | + ) { |
|
| 494 | + $is_file = false; |
|
| 495 | + } |
|
| 496 | + if ($is_file) { |
|
| 497 | + $is_local_file = function ($path) { |
|
| 498 | + if (str_contains($path, '?')) { |
|
| 499 | + $path = supprimer_timestamp($path); |
|
| 500 | + // remove ?24px added by find_in_theme on .svg files |
|
| 501 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 502 | + } |
|
| 503 | + return file_exists($path); |
|
| 504 | + }; |
|
| 505 | + if ($is_local_file($is_file) || tester_url_absolue($is_file)) { |
|
| 506 | + $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 507 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 508 | + return $res; |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 513 | + if ( |
|
| 514 | + preg_match_all( |
|
| 515 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 516 | + (string) $texte, |
|
| 517 | + $tags, |
|
| 518 | + PREG_SET_ORDER |
|
| 519 | + ) |
|
| 520 | + ) { |
|
| 521 | + foreach ($tags as $tag) { |
|
| 522 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 523 | + if ( |
|
| 524 | + (!$class || !str_contains($class, 'filtre_inactif')) |
|
| 525 | + && ($reduit = $filtre($tag[3], ...$args)) |
|
| 526 | + ) { |
|
| 527 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 528 | + if ($tag[1]) { |
|
| 529 | + $w = extraire_attribut($reduit, 'width'); |
|
| 530 | + if (!$w && preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 531 | + $w = $regs[1]; |
|
| 532 | + } |
|
| 533 | + if ($w && ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 534 | + $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 535 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 536 | + $texte = str_replace($tag[1], $replace, (string) $texte); |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + // traiter aussi un eventuel mouseover |
|
| 540 | + if ( |
|
| 541 | + ($mouseover = extraire_attribut($reduit, 'onmouseover')) |
|
| 542 | + && preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match) |
|
| 543 | + ) { |
|
| 544 | + $srcover = $match[1]; |
|
| 545 | + $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 546 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 547 | + $reduit = str_replace($srcover, $srcover_filter, (string) $reduit); |
|
| 548 | + } |
|
| 549 | + $texte = str_replace($tag[3], $reduit, (string) $texte); |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 554 | + return $texte; |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | /** |
@@ -568,94 +568,94 @@ discard block |
||
| 568 | 568 | **/ |
| 569 | 569 | function infos_image($img, $force_refresh = false) { |
| 570 | 570 | |
| 571 | - static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 572 | - $srcWidth = 0; |
|
| 573 | - $srcHeight = 0; |
|
| 574 | - $srcSize = null; |
|
| 575 | - $valeurs = null; |
|
| 576 | - |
|
| 577 | - $src = extraire_attribut($img, 'src'); |
|
| 578 | - |
|
| 579 | - if (!$src) { |
|
| 580 | - $src = $img; |
|
| 581 | - } else { |
|
| 582 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 583 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 584 | - if (!ctype_digit((string) $srcWidth) || !ctype_digit((string) $srcHeight)) { |
|
| 585 | - $srcWidth = $srcHeight = 0; |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 590 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 591 | - if (tester_url_absolue($src)) { |
|
| 592 | - include_spip('inc/distant'); |
|
| 593 | - $fichier = copie_locale($src); |
|
| 594 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 595 | - } |
|
| 596 | - if (($p = strpos($src, '?')) !== false) { |
|
| 597 | - $src = substr($src, 0, $p); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - $imagesize = false; |
|
| 601 | - if (isset($largeur_img[$src]) && !$force_refresh) { |
|
| 602 | - $srcWidth = $largeur_img[$src]; |
|
| 603 | - } |
|
| 604 | - if (isset($hauteur_img[$src]) && !$force_refresh) { |
|
| 605 | - $srcHeight = $hauteur_img[$src]; |
|
| 606 | - } |
|
| 607 | - if (isset($poids_img[$src]) && !$force_refresh) { |
|
| 608 | - $srcSize = $poids_img[$src]; |
|
| 609 | - } |
|
| 610 | - if (!$srcWidth || !$srcHeight || is_null($srcSize)) { |
|
| 611 | - if ( |
|
| 612 | - file_exists($src) && ($imagesize = spip_getimagesize($src)) |
|
| 613 | - ) { |
|
| 614 | - if (!$srcWidth) { |
|
| 615 | - $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 616 | - } |
|
| 617 | - if (!$srcHeight) { |
|
| 618 | - $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 619 | - } |
|
| 620 | - if (!$srcSize) { |
|
| 621 | - $poids_img[$src] = filesize($src); |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - elseif (str_contains($src, '<svg')) { |
|
| 625 | - include_spip('inc/svg'); |
|
| 626 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 627 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 628 | - if (!$srcWidth) { |
|
| 629 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 630 | - } |
|
| 631 | - if (!$srcHeight) { |
|
| 632 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 633 | - } |
|
| 634 | - if (!$srcSize) { |
|
| 635 | - $poids_img[$src] = $srcSize = strlen($src); |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 640 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 641 | - elseif ( |
|
| 642 | - @file_exists($f = "$src.src") |
|
| 643 | - && lire_fichier($f, $valeurs) |
|
| 644 | - && ($valeurs = unserialize($valeurs)) |
|
| 645 | - ) { |
|
| 646 | - if (!$srcWidth) { |
|
| 647 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 648 | - } |
|
| 649 | - if (!$srcHeight) { |
|
| 650 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 651 | - } |
|
| 652 | - if (!$srcSize) { |
|
| 653 | - $poids_img[$src] = $srcSize = 0; |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 571 | + static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 572 | + $srcWidth = 0; |
|
| 573 | + $srcHeight = 0; |
|
| 574 | + $srcSize = null; |
|
| 575 | + $valeurs = null; |
|
| 576 | + |
|
| 577 | + $src = extraire_attribut($img, 'src'); |
|
| 578 | + |
|
| 579 | + if (!$src) { |
|
| 580 | + $src = $img; |
|
| 581 | + } else { |
|
| 582 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 583 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 584 | + if (!ctype_digit((string) $srcWidth) || !ctype_digit((string) $srcHeight)) { |
|
| 585 | + $srcWidth = $srcHeight = 0; |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 590 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 591 | + if (tester_url_absolue($src)) { |
|
| 592 | + include_spip('inc/distant'); |
|
| 593 | + $fichier = copie_locale($src); |
|
| 594 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 595 | + } |
|
| 596 | + if (($p = strpos($src, '?')) !== false) { |
|
| 597 | + $src = substr($src, 0, $p); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + $imagesize = false; |
|
| 601 | + if (isset($largeur_img[$src]) && !$force_refresh) { |
|
| 602 | + $srcWidth = $largeur_img[$src]; |
|
| 603 | + } |
|
| 604 | + if (isset($hauteur_img[$src]) && !$force_refresh) { |
|
| 605 | + $srcHeight = $hauteur_img[$src]; |
|
| 606 | + } |
|
| 607 | + if (isset($poids_img[$src]) && !$force_refresh) { |
|
| 608 | + $srcSize = $poids_img[$src]; |
|
| 609 | + } |
|
| 610 | + if (!$srcWidth || !$srcHeight || is_null($srcSize)) { |
|
| 611 | + if ( |
|
| 612 | + file_exists($src) && ($imagesize = spip_getimagesize($src)) |
|
| 613 | + ) { |
|
| 614 | + if (!$srcWidth) { |
|
| 615 | + $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 616 | + } |
|
| 617 | + if (!$srcHeight) { |
|
| 618 | + $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 619 | + } |
|
| 620 | + if (!$srcSize) { |
|
| 621 | + $poids_img[$src] = filesize($src); |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + elseif (str_contains($src, '<svg')) { |
|
| 625 | + include_spip('inc/svg'); |
|
| 626 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 627 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 628 | + if (!$srcWidth) { |
|
| 629 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 630 | + } |
|
| 631 | + if (!$srcHeight) { |
|
| 632 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 633 | + } |
|
| 634 | + if (!$srcSize) { |
|
| 635 | + $poids_img[$src] = $srcSize = strlen($src); |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 640 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 641 | + elseif ( |
|
| 642 | + @file_exists($f = "$src.src") |
|
| 643 | + && lire_fichier($f, $valeurs) |
|
| 644 | + && ($valeurs = unserialize($valeurs)) |
|
| 645 | + ) { |
|
| 646 | + if (!$srcWidth) { |
|
| 647 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 648 | + } |
|
| 649 | + if (!$srcHeight) { |
|
| 650 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 651 | + } |
|
| 652 | + if (!$srcSize) { |
|
| 653 | + $poids_img[$src] = $srcSize = 0; |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | /** |
@@ -671,13 +671,13 @@ discard block |
||
| 671 | 671 | * poids |
| 672 | 672 | **/ |
| 673 | 673 | function poids_image($img, $force_refresh = false) { |
| 674 | - $infos = infos_image($img, $force_refresh); |
|
| 675 | - return $infos['poids']; |
|
| 674 | + $infos = infos_image($img, $force_refresh); |
|
| 675 | + return $infos['poids']; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | function taille_image($img, $force_refresh = false) { |
| 679 | - $infos = infos_image($img, $force_refresh); |
|
| 680 | - return [$infos['hauteur'], $infos['largeur']]; |
|
| 679 | + $infos = infos_image($img, $force_refresh); |
|
| 680 | + return [$infos['hauteur'], $infos['largeur']]; |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | /** |
@@ -694,12 +694,12 @@ discard block |
||
| 694 | 694 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 695 | 695 | **/ |
| 696 | 696 | function largeur($img) { |
| 697 | - if (!$img) { |
|
| 698 | - return; |
|
| 699 | - } |
|
| 700 | - [$h, $l] = taille_image($img); |
|
| 697 | + if (!$img) { |
|
| 698 | + return; |
|
| 699 | + } |
|
| 700 | + [$h, $l] = taille_image($img); |
|
| 701 | 701 | |
| 702 | - return $l; |
|
| 702 | + return $l; |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | /** |
@@ -716,12 +716,12 @@ discard block |
||
| 716 | 716 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 717 | 717 | **/ |
| 718 | 718 | function hauteur($img) { |
| 719 | - if (!$img) { |
|
| 720 | - return; |
|
| 721 | - } |
|
| 722 | - [$h, $l] = taille_image($img); |
|
| 719 | + if (!$img) { |
|
| 720 | + return; |
|
| 721 | + } |
|
| 722 | + [$h, $l] = taille_image($img); |
|
| 723 | 723 | |
| 724 | - return $h; |
|
| 724 | + return $h; |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | |
@@ -741,11 +741,11 @@ discard block |
||
| 741 | 741 | * @return string |
| 742 | 742 | **/ |
| 743 | 743 | function corriger_entites_html($texte) { |
| 744 | - if (!str_contains($texte, '&')) { |
|
| 745 | - return $texte; |
|
| 746 | - } |
|
| 744 | + if (!str_contains($texte, '&')) { |
|
| 745 | + return $texte; |
|
| 746 | + } |
|
| 747 | 747 | |
| 748 | - return preg_replace(',&(#\d\d\d+;|amp;),iS', '&\1', $texte); |
|
| 748 | + return preg_replace(',&(#\d\d\d+;|amp;),iS', '&\1', $texte); |
|
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | /** |
@@ -760,11 +760,11 @@ discard block |
||
| 760 | 760 | * @return string |
| 761 | 761 | **/ |
| 762 | 762 | function corriger_toutes_entites_html($texte) { |
| 763 | - if (!str_contains($texte, '&')) { |
|
| 764 | - return $texte; |
|
| 765 | - } |
|
| 763 | + if (!str_contains($texte, '&')) { |
|
| 764 | + return $texte; |
|
| 765 | + } |
|
| 766 | 766 | |
| 767 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 767 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
@@ -774,7 +774,7 @@ discard block |
||
| 774 | 774 | * @return string |
| 775 | 775 | **/ |
| 776 | 776 | function proteger_amp($texte) { |
| 777 | - return str_replace('&', '&', $texte); |
|
| 777 | + return str_replace('&', '&', $texte); |
|
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | |
@@ -805,20 +805,20 @@ discard block |
||
| 805 | 805 | * @return mixed|string |
| 806 | 806 | */ |
| 807 | 807 | function entites_html($texte, $tout = false, $quote = true) { |
| 808 | - if (!is_string($texte) || !$texte || strpbrk($texte, "&\"'<>") == false) { |
|
| 809 | - return $texte; |
|
| 810 | - } |
|
| 811 | - include_spip('inc/texte'); |
|
| 812 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 813 | - $flags |= ENT_HTML401; |
|
| 814 | - $texte = CollecteurHtmlTag::proteger_balisesHtml($texte); |
|
| 815 | - $texte = CollecteurHtmlTag::retablir_depuisHtmlBase64($texte, '', 'proteger_amp'); |
|
| 816 | - $texte = spip_htmlspecialchars($texte, $flags); |
|
| 817 | - if ($tout) { |
|
| 818 | - return corriger_toutes_entites_html($texte); |
|
| 819 | - } else { |
|
| 820 | - return corriger_entites_html($texte); |
|
| 821 | - } |
|
| 808 | + if (!is_string($texte) || !$texte || strpbrk($texte, "&\"'<>") == false) { |
|
| 809 | + return $texte; |
|
| 810 | + } |
|
| 811 | + include_spip('inc/texte'); |
|
| 812 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 813 | + $flags |= ENT_HTML401; |
|
| 814 | + $texte = CollecteurHtmlTag::proteger_balisesHtml($texte); |
|
| 815 | + $texte = CollecteurHtmlTag::retablir_depuisHtmlBase64($texte, '', 'proteger_amp'); |
|
| 816 | + $texte = spip_htmlspecialchars($texte, $flags); |
|
| 817 | + if ($tout) { |
|
| 818 | + return corriger_toutes_entites_html($texte); |
|
| 819 | + } else { |
|
| 820 | + return corriger_entites_html($texte); |
|
| 821 | + } |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | /** |
@@ -837,38 +837,38 @@ discard block |
||
| 837 | 837 | * texte converti |
| 838 | 838 | **/ |
| 839 | 839 | function filtrer_entites(?string $texte): string { |
| 840 | - $texte ??= ''; |
|
| 841 | - if (!str_contains($texte, '&')) { |
|
| 842 | - return $texte; |
|
| 843 | - } |
|
| 844 | - // filtrer |
|
| 845 | - $texte = html2unicode($texte); |
|
| 846 | - // remettre le tout dans le charset cible |
|
| 847 | - $texte = unicode2charset($texte); |
|
| 848 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 849 | - // (on le faisait deja avec un ") |
|
| 850 | - if (str_contains($texte, '&#')) { |
|
| 851 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 852 | - } |
|
| 840 | + $texte ??= ''; |
|
| 841 | + if (!str_contains($texte, '&')) { |
|
| 842 | + return $texte; |
|
| 843 | + } |
|
| 844 | + // filtrer |
|
| 845 | + $texte = html2unicode($texte); |
|
| 846 | + // remettre le tout dans le charset cible |
|
| 847 | + $texte = unicode2charset($texte); |
|
| 848 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 849 | + // (on le faisait deja avec un ") |
|
| 850 | + if (str_contains($texte, '&#')) { |
|
| 851 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 852 | + } |
|
| 853 | 853 | |
| 854 | - return $texte; |
|
| 854 | + return $texte; |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | |
| 858 | 858 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 859 | - /** |
|
| 860 | - * Version sécurisée de filtrer_entites |
|
| 861 | - * |
|
| 862 | - * @uses interdire_scripts() |
|
| 863 | - * @uses filtrer_entites() |
|
| 864 | - * |
|
| 865 | - * @param string $t |
|
| 866 | - * @return string |
|
| 867 | - */ |
|
| 868 | - function filtre_filtrer_entites_dist($t) { |
|
| 869 | - include_spip('inc/texte'); |
|
| 870 | - return interdire_scripts(filtrer_entites($t)); |
|
| 871 | - } |
|
| 859 | + /** |
|
| 860 | + * Version sécurisée de filtrer_entites |
|
| 861 | + * |
|
| 862 | + * @uses interdire_scripts() |
|
| 863 | + * @uses filtrer_entites() |
|
| 864 | + * |
|
| 865 | + * @param string $t |
|
| 866 | + * @return string |
|
| 867 | + */ |
|
| 868 | + function filtre_filtrer_entites_dist($t) { |
|
| 869 | + include_spip('inc/texte'); |
|
| 870 | + return interdire_scripts(filtrer_entites($t)); |
|
| 871 | + } |
|
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | |
@@ -883,18 +883,18 @@ discard block |
||
| 883 | 883 | * @return string|array |
| 884 | 884 | **/ |
| 885 | 885 | function supprimer_caracteres_illegaux($texte) { |
| 886 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 887 | - static $to = null; |
|
| 886 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 887 | + static $to = null; |
|
| 888 | 888 | |
| 889 | - if (is_array($texte)) { |
|
| 890 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 891 | - } |
|
| 889 | + if (is_array($texte)) { |
|
| 890 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 891 | + } |
|
| 892 | 892 | |
| 893 | - if (!$to) { |
|
| 894 | - $to = str_repeat('-', strlen((string) $from)); |
|
| 895 | - } |
|
| 893 | + if (!$to) { |
|
| 894 | + $to = str_repeat('-', strlen((string) $from)); |
|
| 895 | + } |
|
| 896 | 896 | |
| 897 | - return strtr($texte, $from, $to); |
|
| 897 | + return strtr($texte, $from, $to); |
|
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | /** |
@@ -906,9 +906,9 @@ discard block |
||
| 906 | 906 | * @return string|array |
| 907 | 907 | **/ |
| 908 | 908 | function corriger_caracteres($texte) { |
| 909 | - $texte = corriger_caracteres_windows($texte); |
|
| 909 | + $texte = corriger_caracteres_windows($texte); |
|
| 910 | 910 | |
| 911 | - return supprimer_caracteres_illegaux($texte); |
|
| 911 | + return supprimer_caracteres_illegaux($texte); |
|
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | /** |
@@ -925,44 +925,44 @@ discard block |
||
| 925 | 925 | * texte encodé pour XML |
| 926 | 926 | */ |
| 927 | 927 | function texte_backend(?string $texte): string { |
| 928 | - if ($texte === null || $texte === '') { |
|
| 929 | - return ''; |
|
| 930 | - } |
|
| 928 | + if ($texte === null || $texte === '') { |
|
| 929 | + return ''; |
|
| 930 | + } |
|
| 931 | 931 | |
| 932 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 932 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 933 | 933 | |
| 934 | - // si on a des liens ou des images, les passer en absolu |
|
| 935 | - $texte = liens_absolus($texte); |
|
| 934 | + // si on a des liens ou des images, les passer en absolu |
|
| 935 | + $texte = liens_absolus($texte); |
|
| 936 | 936 | |
| 937 | - // echapper les tags > < |
|
| 938 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 937 | + // echapper les tags > < |
|
| 938 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 939 | 939 | |
| 940 | - // importer les é |
|
| 941 | - $texte = filtrer_entites($texte); |
|
| 940 | + // importer les é |
|
| 941 | + $texte = filtrer_entites($texte); |
|
| 942 | 942 | |
| 943 | - // " -> " et tout ce genre de choses |
|
| 944 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 945 | - $texte = str_replace(' ', ' ', $texte); |
|
| 946 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 947 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 948 | - $texte = entites_html($texte, false, false); |
|
| 949 | - // mais bien echapper les double quotes ! |
|
| 950 | - $texte = str_replace('"', '"', (string) $texte); |
|
| 943 | + // " -> " et tout ce genre de choses |
|
| 944 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 945 | + $texte = str_replace(' ', ' ', $texte); |
|
| 946 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 947 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 948 | + $texte = entites_html($texte, false, false); |
|
| 949 | + // mais bien echapper les double quotes ! |
|
| 950 | + $texte = str_replace('"', '"', (string) $texte); |
|
| 951 | 951 | |
| 952 | - // verifier le charset |
|
| 953 | - $texte = charset2unicode($texte); |
|
| 952 | + // verifier le charset |
|
| 953 | + $texte = charset2unicode($texte); |
|
| 954 | 954 | |
| 955 | - // Caracteres problematiques en iso-latin 1 |
|
| 956 | - if (isset($GLOBALS['meta']['charset']) && $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 957 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 958 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 959 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 960 | - } |
|
| 955 | + // Caracteres problematiques en iso-latin 1 |
|
| 956 | + if (isset($GLOBALS['meta']['charset']) && $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 957 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 958 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 959 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 960 | + } |
|
| 961 | 961 | |
| 962 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 963 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 964 | - // ==> on les remplace par l'entite HTML |
|
| 965 | - return str_replace($apostrophe, "'", $texte); |
|
| 962 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 963 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 964 | + // ==> on les remplace par l'entite HTML |
|
| 965 | + return str_replace($apostrophe, "'", $texte); |
|
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | /** |
@@ -979,7 +979,7 @@ discard block |
||
| 979 | 979 | * texte encodé et quote pour XML |
| 980 | 980 | */ |
| 981 | 981 | function texte_backendq(?string $texte): string { |
| 982 | - return addslashes(texte_backend($texte)); |
|
| 982 | + return addslashes(texte_backend($texte)); |
|
| 983 | 983 | } |
| 984 | 984 | |
| 985 | 985 | |
@@ -1001,14 +1001,14 @@ discard block |
||
| 1001 | 1001 | * Texte sans son numéro éventuel |
| 1002 | 1002 | **/ |
| 1003 | 1003 | function supprimer_numero(?string $texte): string { |
| 1004 | - if ($texte === null || $texte === '') { |
|
| 1005 | - return ''; |
|
| 1006 | - } |
|
| 1007 | - return preg_replace( |
|
| 1008 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1009 | - '', |
|
| 1010 | - $texte |
|
| 1011 | - ); |
|
| 1004 | + if ($texte === null || $texte === '') { |
|
| 1005 | + return ''; |
|
| 1006 | + } |
|
| 1007 | + return preg_replace( |
|
| 1008 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1009 | + '', |
|
| 1010 | + $texte |
|
| 1011 | + ); |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | /** |
@@ -1031,19 +1031,19 @@ discard block |
||
| 1031 | 1031 | * Numéro de titre, sinon chaîne vide |
| 1032 | 1032 | **/ |
| 1033 | 1033 | function recuperer_numero(?string $texte): string { |
| 1034 | - if ($texte === null || $texte === '') { |
|
| 1035 | - return ''; |
|
| 1036 | - } |
|
| 1037 | - if (preg_match( |
|
| 1038 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1039 | - $texte, |
|
| 1040 | - $regs |
|
| 1041 | - ) |
|
| 1042 | - ) { |
|
| 1043 | - return (string) $regs[1]; |
|
| 1044 | - } |
|
| 1034 | + if ($texte === null || $texte === '') { |
|
| 1035 | + return ''; |
|
| 1036 | + } |
|
| 1037 | + if (preg_match( |
|
| 1038 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1039 | + $texte, |
|
| 1040 | + $regs |
|
| 1041 | + ) |
|
| 1042 | + ) { |
|
| 1043 | + return (string) $regs[1]; |
|
| 1044 | + } |
|
| 1045 | 1045 | |
| 1046 | - return ''; |
|
| 1046 | + return ''; |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | /** |
@@ -1070,16 +1070,16 @@ discard block |
||
| 1070 | 1070 | * texte ou tableau de textes converti |
| 1071 | 1071 | **/ |
| 1072 | 1072 | function supprimer_tags($texte, $rempl = '') { |
| 1073 | - if ($texte === null || $texte === '') { |
|
| 1074 | - return ''; |
|
| 1075 | - } |
|
| 1076 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1077 | - // ne pas oublier un < final non ferme car coupe |
|
| 1078 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1079 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1080 | - $texte = str_replace('<', '<', $texte); |
|
| 1073 | + if ($texte === null || $texte === '') { |
|
| 1074 | + return ''; |
|
| 1075 | + } |
|
| 1076 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1077 | + // ne pas oublier un < final non ferme car coupe |
|
| 1078 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1079 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1080 | + $texte = str_replace('<', '<', $texte); |
|
| 1081 | 1081 | |
| 1082 | - return $texte; |
|
| 1082 | + return $texte; |
|
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | /** |
@@ -1102,7 +1102,7 @@ discard block |
||
| 1102 | 1102 | * texte converti |
| 1103 | 1103 | **/ |
| 1104 | 1104 | function echapper_tags($texte, $rempl = '') { |
| 1105 | - return preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1105 | + return preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | /** |
@@ -1123,21 +1123,21 @@ discard block |
||
| 1123 | 1123 | * texte converti |
| 1124 | 1124 | **/ |
| 1125 | 1125 | function textebrut($texte) { |
| 1126 | - if ($texte === null || $texte === '') { |
|
| 1127 | - return ''; |
|
| 1128 | - } |
|
| 1129 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1130 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1131 | - $texte = preg_replace('/<(p|br)( [^>]*)?>/iS', "\n\n", $texte); |
|
| 1132 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1133 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1134 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1135 | - $texte = supprimer_tags($texte); |
|
| 1136 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1137 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1138 | - $texte = str_replace('’', "'", $texte); |
|
| 1126 | + if ($texte === null || $texte === '') { |
|
| 1127 | + return ''; |
|
| 1128 | + } |
|
| 1129 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1130 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1131 | + $texte = preg_replace('/<(p|br)( [^>]*)?>/iS', "\n\n", $texte); |
|
| 1132 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1133 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1134 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1135 | + $texte = supprimer_tags($texte); |
|
| 1136 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1137 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1138 | + $texte = str_replace('’', "'", $texte); |
|
| 1139 | 1139 | |
| 1140 | - return $texte; |
|
| 1140 | + return $texte; |
|
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 1143 | |
@@ -1153,26 +1153,26 @@ discard block |
||
| 1153 | 1153 | * texte avec liens ouvrants |
| 1154 | 1154 | **/ |
| 1155 | 1155 | function liens_ouvrants($texte) { |
| 1156 | - if ($texte === null || $texte === '') { |
|
| 1157 | - return ''; |
|
| 1158 | - } |
|
| 1159 | - if ( |
|
| 1160 | - preg_match_all( |
|
| 1161 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1162 | - $texte, |
|
| 1163 | - $liens, |
|
| 1164 | - PREG_PATTERN_ORDER |
|
| 1165 | - ) |
|
| 1166 | - ) { |
|
| 1167 | - foreach ($liens[0] as $a) { |
|
| 1168 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1169 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1170 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1171 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1172 | - } |
|
| 1173 | - } |
|
| 1174 | - |
|
| 1175 | - return $texte; |
|
| 1156 | + if ($texte === null || $texte === '') { |
|
| 1157 | + return ''; |
|
| 1158 | + } |
|
| 1159 | + if ( |
|
| 1160 | + preg_match_all( |
|
| 1161 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1162 | + $texte, |
|
| 1163 | + $liens, |
|
| 1164 | + PREG_PATTERN_ORDER |
|
| 1165 | + ) |
|
| 1166 | + ) { |
|
| 1167 | + foreach ($liens[0] as $a) { |
|
| 1168 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1169 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1170 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1171 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1172 | + } |
|
| 1173 | + } |
|
| 1174 | + |
|
| 1175 | + return $texte; |
|
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | /** |
@@ -1182,25 +1182,25 @@ discard block |
||
| 1182 | 1182 | * @return string |
| 1183 | 1183 | */ |
| 1184 | 1184 | function liens_nofollow($texte) { |
| 1185 | - if ($texte === null || $texte === '') { |
|
| 1186 | - return ''; |
|
| 1187 | - } |
|
| 1188 | - if (stripos($texte, '<a') === false) { |
|
| 1189 | - return $texte; |
|
| 1190 | - } |
|
| 1185 | + if ($texte === null || $texte === '') { |
|
| 1186 | + return ''; |
|
| 1187 | + } |
|
| 1188 | + if (stripos($texte, '<a') === false) { |
|
| 1189 | + return $texte; |
|
| 1190 | + } |
|
| 1191 | 1191 | |
| 1192 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1193 | - foreach ($regs[0] as $a) { |
|
| 1194 | - $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1195 | - if (!str_contains($rel, 'nofollow')) { |
|
| 1196 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1197 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1198 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1199 | - } |
|
| 1200 | - } |
|
| 1201 | - } |
|
| 1192 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1193 | + foreach ($regs[0] as $a) { |
|
| 1194 | + $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1195 | + if (!str_contains($rel, 'nofollow')) { |
|
| 1196 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1197 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1198 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1199 | + } |
|
| 1200 | + } |
|
| 1201 | + } |
|
| 1202 | 1202 | |
| 1203 | - return $texte; |
|
| 1203 | + return $texte; |
|
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | 1206 | /** |
@@ -1219,14 +1219,14 @@ discard block |
||
| 1219 | 1219 | * texte sans paraghaphes |
| 1220 | 1220 | **/ |
| 1221 | 1221 | function PtoBR($texte) { |
| 1222 | - if ($texte === null || $texte === '') { |
|
| 1223 | - return ''; |
|
| 1224 | - } |
|
| 1225 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1226 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1227 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1222 | + if ($texte === null || $texte === '') { |
|
| 1223 | + return ''; |
|
| 1224 | + } |
|
| 1225 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1226 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1227 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1228 | 1228 | |
| 1229 | - return preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1229 | + return preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | /** |
@@ -1245,30 +1245,30 @@ discard block |
||
| 1245 | 1245 | * @return string texte en majuscule |
| 1246 | 1246 | */ |
| 1247 | 1247 | function majuscules($texte) { |
| 1248 | - if ($texte === null || $texte === '') { |
|
| 1249 | - return ''; |
|
| 1250 | - } |
|
| 1248 | + if ($texte === null || $texte === '') { |
|
| 1249 | + return ''; |
|
| 1250 | + } |
|
| 1251 | 1251 | |
| 1252 | - // Cas du turc |
|
| 1253 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1254 | - # remplacer hors des tags et des entites |
|
| 1255 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1256 | - foreach ($regs as $n => $match) { |
|
| 1257 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1258 | - } |
|
| 1259 | - } |
|
| 1252 | + // Cas du turc |
|
| 1253 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1254 | + # remplacer hors des tags et des entites |
|
| 1255 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1256 | + foreach ($regs as $n => $match) { |
|
| 1257 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1258 | + } |
|
| 1259 | + } |
|
| 1260 | 1260 | |
| 1261 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1261 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1262 | 1262 | |
| 1263 | - if ($regs) { |
|
| 1264 | - foreach ($regs as $n => $match) { |
|
| 1265 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1266 | - } |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1263 | + if ($regs) { |
|
| 1264 | + foreach ($regs as $n => $match) { |
|
| 1265 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1266 | + } |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | 1269 | |
| 1270 | - // Cas general |
|
| 1271 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1270 | + // Cas general |
|
| 1271 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | 1274 | /** |
@@ -1290,38 +1290,38 @@ discard block |
||
| 1290 | 1290 | */ |
| 1291 | 1291 | function taille_en_octets($octets, $systeme = 'BI') { |
| 1292 | 1292 | |
| 1293 | - // Texte à afficher pour la taille |
|
| 1294 | - $affichage = ''; |
|
| 1293 | + // Texte à afficher pour la taille |
|
| 1294 | + $affichage = ''; |
|
| 1295 | 1295 | |
| 1296 | - static $unites = ['octets', 'ko', 'mo', 'go']; |
|
| 1297 | - static $precisions = [0, 1, 1, 2]; |
|
| 1296 | + static $unites = ['octets', 'ko', 'mo', 'go']; |
|
| 1297 | + static $precisions = [0, 1, 1, 2]; |
|
| 1298 | 1298 | |
| 1299 | - if ($octets >= 1) { |
|
| 1300 | - // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi |
|
| 1301 | - $systeme = strtolower($systeme); |
|
| 1302 | - if ($systeme === 'bi') { |
|
| 1303 | - $kilo = 1024; |
|
| 1304 | - $suffixe_item = "_$systeme"; |
|
| 1305 | - } elseif ($systeme === 'si') { |
|
| 1306 | - $kilo = 1000; |
|
| 1307 | - $suffixe_item = ''; |
|
| 1308 | - } else { |
|
| 1309 | - return $affichage; |
|
| 1310 | - } |
|
| 1299 | + if ($octets >= 1) { |
|
| 1300 | + // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi |
|
| 1301 | + $systeme = strtolower($systeme); |
|
| 1302 | + if ($systeme === 'bi') { |
|
| 1303 | + $kilo = 1024; |
|
| 1304 | + $suffixe_item = "_$systeme"; |
|
| 1305 | + } elseif ($systeme === 'si') { |
|
| 1306 | + $kilo = 1000; |
|
| 1307 | + $suffixe_item = ''; |
|
| 1308 | + } else { |
|
| 1309 | + return $affichage; |
|
| 1310 | + } |
|
| 1311 | 1311 | |
| 1312 | - // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée |
|
| 1313 | - $puissance = floor(log($octets, $kilo)); |
|
| 1312 | + // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée |
|
| 1313 | + $puissance = floor(log($octets, $kilo)); |
|
| 1314 | 1314 | |
| 1315 | - // Calcul de la taille et choix de l'unité |
|
| 1316 | - $affichage = _T( |
|
| 1317 | - 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1318 | - [ |
|
| 1319 | - 'taille' => round($octets / $kilo ** $puissance, $precisions[$puissance]) |
|
| 1320 | - ] |
|
| 1321 | - ); |
|
| 1322 | - } |
|
| 1315 | + // Calcul de la taille et choix de l'unité |
|
| 1316 | + $affichage = _T( |
|
| 1317 | + 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1318 | + [ |
|
| 1319 | + 'taille' => round($octets / $kilo ** $puissance, $precisions[$puissance]) |
|
| 1320 | + ] |
|
| 1321 | + ); |
|
| 1322 | + } |
|
| 1323 | 1323 | |
| 1324 | - return $affichage; |
|
| 1324 | + return $affichage; |
|
| 1325 | 1325 | } |
| 1326 | 1326 | |
| 1327 | 1327 | |
@@ -1343,21 +1343,21 @@ discard block |
||
| 1343 | 1343 | * texte prêt pour être utilisé en attribut HTML |
| 1344 | 1344 | **/ |
| 1345 | 1345 | function attribut_html(?string $texte, $textebrut = true): string { |
| 1346 | - if ($texte === null || $texte === '') { |
|
| 1347 | - return ''; |
|
| 1348 | - } |
|
| 1349 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1350 | - if ($textebrut) { |
|
| 1351 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1352 | - } |
|
| 1353 | - $texte = texte_backend($texte); |
|
| 1354 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1346 | + if ($texte === null || $texte === '') { |
|
| 1347 | + return ''; |
|
| 1348 | + } |
|
| 1349 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1350 | + if ($textebrut) { |
|
| 1351 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1352 | + } |
|
| 1353 | + $texte = texte_backend($texte); |
|
| 1354 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1355 | 1355 | |
| 1356 | - return preg_replace( |
|
| 1357 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1358 | - ['&', '&'], |
|
| 1359 | - $texte |
|
| 1360 | - ); |
|
| 1356 | + return preg_replace( |
|
| 1357 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1358 | + ['&', '&'], |
|
| 1359 | + $texte |
|
| 1360 | + ); |
|
| 1361 | 1361 | } |
| 1362 | 1362 | |
| 1363 | 1363 | |
@@ -1377,15 +1377,15 @@ discard block |
||
| 1377 | 1377 | * URL ou chaîne vide |
| 1378 | 1378 | **/ |
| 1379 | 1379 | function vider_url(?string $url, $entites = true): string { |
| 1380 | - if ($url === null || $url === '') { |
|
| 1381 | - return ''; |
|
| 1382 | - } |
|
| 1383 | - # un message pour abs_url |
|
| 1384 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1385 | - $url = trim($url); |
|
| 1386 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1380 | + if ($url === null || $url === '') { |
|
| 1381 | + return ''; |
|
| 1382 | + } |
|
| 1383 | + # un message pour abs_url |
|
| 1384 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1385 | + $url = trim($url); |
|
| 1386 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1387 | 1387 | |
| 1388 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1388 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1389 | 1389 | } |
| 1390 | 1390 | |
| 1391 | 1391 | |
@@ -1400,10 +1400,10 @@ discard block |
||
| 1400 | 1400 | * @return string Adresse email maquillée |
| 1401 | 1401 | **/ |
| 1402 | 1402 | function antispam($texte) { |
| 1403 | - include_spip('inc/acces'); |
|
| 1404 | - $masque = creer_pass_aleatoire(3); |
|
| 1403 | + include_spip('inc/acces'); |
|
| 1404 | + $masque = creer_pass_aleatoire(3); |
|
| 1405 | 1405 | |
| 1406 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1406 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1407 | 1407 | } |
| 1408 | 1408 | |
| 1409 | 1409 | /** |
@@ -1435,8 +1435,8 @@ discard block |
||
| 1435 | 1435 | * True si on a le droit d'accès, false sinon. |
| 1436 | 1436 | **/ |
| 1437 | 1437 | function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1438 | - include_spip('inc/acces'); |
|
| 1439 | - return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1438 | + include_spip('inc/acces'); |
|
| 1439 | + return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | 1442 | /** |
@@ -1460,13 +1460,13 @@ discard block |
||
| 1460 | 1460 | * Retourne $texte, sinon $sinon. |
| 1461 | 1461 | **/ |
| 1462 | 1462 | function sinon(mixed $texte, mixed $sinon = '') { |
| 1463 | - if ($texte) { |
|
| 1464 | - return $texte; |
|
| 1465 | - } elseif (is_scalar($texte) && strlen($texte)) { |
|
| 1466 | - return $texte; |
|
| 1467 | - } |
|
| 1463 | + if ($texte) { |
|
| 1464 | + return $texte; |
|
| 1465 | + } elseif (is_scalar($texte) && strlen($texte)) { |
|
| 1466 | + return $texte; |
|
| 1467 | + } |
|
| 1468 | 1468 | |
| 1469 | - return $sinon; |
|
| 1469 | + return $sinon; |
|
| 1470 | 1470 | } |
| 1471 | 1471 | |
| 1472 | 1472 | /** |
@@ -1490,7 +1490,7 @@ discard block |
||
| 1490 | 1490 | * @return mixed |
| 1491 | 1491 | **/ |
| 1492 | 1492 | function choixsivide(mixed $a, mixed $vide, mixed $pasvide) { |
| 1493 | - return $a ? $pasvide : $vide; |
|
| 1493 | + return $a ? $pasvide : $vide; |
|
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 1496 | 1496 | /** |
@@ -1514,7 +1514,7 @@ discard block |
||
| 1514 | 1514 | * @return mixed |
| 1515 | 1515 | **/ |
| 1516 | 1516 | function choixsiegal(mixed $a1, mixed $a2, mixed $v, mixed $f) { |
| 1517 | - return ($a1 == $a2) ? $v : $f; |
|
| 1517 | + return ($a1 == $a2) ? $v : $f; |
|
| 1518 | 1518 | } |
| 1519 | 1519 | |
| 1520 | 1520 | // |
@@ -1533,15 +1533,15 @@ discard block |
||
| 1533 | 1533 | * @return string |
| 1534 | 1534 | **/ |
| 1535 | 1535 | function filtrer_ical($texte) { |
| 1536 | - if ($texte === null || $texte === '') { |
|
| 1537 | - return ''; |
|
| 1538 | - } |
|
| 1539 | - #include_spip('inc/charsets'); |
|
| 1540 | - $texte = html2unicode($texte); |
|
| 1541 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1542 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1536 | + if ($texte === null || $texte === '') { |
|
| 1537 | + return ''; |
|
| 1538 | + } |
|
| 1539 | + #include_spip('inc/charsets'); |
|
| 1540 | + $texte = html2unicode($texte); |
|
| 1541 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1542 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1543 | 1543 | |
| 1544 | - return preg_replace('/,/', '\,', $texte); |
|
| 1544 | + return preg_replace('/,/', '\,', $texte); |
|
| 1545 | 1545 | } |
| 1546 | 1546 | |
| 1547 | 1547 | |
@@ -1566,56 +1566,56 @@ discard block |
||
| 1566 | 1566 | * @return string |
| 1567 | 1567 | **/ |
| 1568 | 1568 | function post_autobr($texte, $delim = "\n_ ") { |
| 1569 | - if (!function_exists('echappe_html')) { |
|
| 1570 | - include_spip('inc/texte_mini'); |
|
| 1571 | - } |
|
| 1572 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1573 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1574 | - |
|
| 1575 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1576 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1577 | - } else { |
|
| 1578 | - $fin = ''; |
|
| 1579 | - } |
|
| 1580 | - |
|
| 1581 | - $texte = CollecteurHtmlTag::proteger_balisesHtml($texte); |
|
| 1582 | - |
|
| 1583 | - // echapper les modeles |
|
| 1584 | - $collecteurModeles = null; |
|
| 1585 | - if (str_contains($texte, '<')) { |
|
| 1586 | - $collecteurModeles = new CollecteurModeles(); |
|
| 1587 | - $texte = $collecteurModeles->echapper($texte); |
|
| 1588 | - } |
|
| 1589 | - |
|
| 1590 | - $debut = ''; |
|
| 1591 | - $suite = $texte; |
|
| 1592 | - while ($t = strpos((string) ('-' . $suite), "\n", 1)) { |
|
| 1593 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1594 | - $suite = substr($suite, $t); |
|
| 1595 | - $car = substr($suite, 0, 1); |
|
| 1596 | - if ( |
|
| 1597 | - $car != '-' && $car != '_' && $car != "\n" && $car != '|' && $car != '}' |
|
| 1598 | - && !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1599 | - && !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1600 | - ) { |
|
| 1601 | - $debut .= $delim; |
|
| 1602 | - } else { |
|
| 1603 | - $debut .= "\n"; |
|
| 1604 | - } |
|
| 1605 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1606 | - $debut .= $regs[0]; |
|
| 1607 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1608 | - } |
|
| 1609 | - } |
|
| 1610 | - $texte = $debut . $suite; |
|
| 1611 | - |
|
| 1612 | - if ($collecteurModeles) { |
|
| 1613 | - $texte = $collecteurModeles->retablir($texte); |
|
| 1614 | - } |
|
| 1615 | - |
|
| 1616 | - $texte = CollecteurHtmlTag::retablir_depuisHtmlBase64($texte); |
|
| 1617 | - |
|
| 1618 | - return $texte . $fin; |
|
| 1569 | + if (!function_exists('echappe_html')) { |
|
| 1570 | + include_spip('inc/texte_mini'); |
|
| 1571 | + } |
|
| 1572 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1573 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1574 | + |
|
| 1575 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1576 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1577 | + } else { |
|
| 1578 | + $fin = ''; |
|
| 1579 | + } |
|
| 1580 | + |
|
| 1581 | + $texte = CollecteurHtmlTag::proteger_balisesHtml($texte); |
|
| 1582 | + |
|
| 1583 | + // echapper les modeles |
|
| 1584 | + $collecteurModeles = null; |
|
| 1585 | + if (str_contains($texte, '<')) { |
|
| 1586 | + $collecteurModeles = new CollecteurModeles(); |
|
| 1587 | + $texte = $collecteurModeles->echapper($texte); |
|
| 1588 | + } |
|
| 1589 | + |
|
| 1590 | + $debut = ''; |
|
| 1591 | + $suite = $texte; |
|
| 1592 | + while ($t = strpos((string) ('-' . $suite), "\n", 1)) { |
|
| 1593 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1594 | + $suite = substr($suite, $t); |
|
| 1595 | + $car = substr($suite, 0, 1); |
|
| 1596 | + if ( |
|
| 1597 | + $car != '-' && $car != '_' && $car != "\n" && $car != '|' && $car != '}' |
|
| 1598 | + && !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1599 | + && !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1600 | + ) { |
|
| 1601 | + $debut .= $delim; |
|
| 1602 | + } else { |
|
| 1603 | + $debut .= "\n"; |
|
| 1604 | + } |
|
| 1605 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1606 | + $debut .= $regs[0]; |
|
| 1607 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1608 | + } |
|
| 1609 | + } |
|
| 1610 | + $texte = $debut . $suite; |
|
| 1611 | + |
|
| 1612 | + if ($collecteurModeles) { |
|
| 1613 | + $texte = $collecteurModeles->retablir($texte); |
|
| 1614 | + } |
|
| 1615 | + |
|
| 1616 | + $texte = CollecteurHtmlTag::retablir_depuisHtmlBase64($texte); |
|
| 1617 | + |
|
| 1618 | + return $texte . $fin; |
|
| 1619 | 1619 | } |
| 1620 | 1620 | |
| 1621 | 1621 | |
@@ -1648,25 +1648,25 @@ discard block |
||
| 1648 | 1648 | **/ |
| 1649 | 1649 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1650 | 1650 | |
| 1651 | - if ($letexte && str_contains($letexte, '<:')) { |
|
| 1652 | - if (!$lang) { |
|
| 1653 | - $lang = $GLOBALS['spip_lang']; |
|
| 1654 | - } |
|
| 1655 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1656 | - if (is_bool($options)) { |
|
| 1657 | - trigger_deprecation('spip', '5.0', 'Using boolean $options parameter in "%s()" function is deprecated. Use %s array parameter instead.', __FUNCTION__, '[\'echappe_span\' => ' . var_export($options, true) . ']'); |
|
| 1658 | - $options = ['echappe_span' => $options]; |
|
| 1659 | - } |
|
| 1660 | - if (!isset($options['echappe_span'])) { |
|
| 1661 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1662 | - } |
|
| 1663 | - $options['lang'] = $lang; |
|
| 1651 | + if ($letexte && str_contains($letexte, '<:')) { |
|
| 1652 | + if (!$lang) { |
|
| 1653 | + $lang = $GLOBALS['spip_lang']; |
|
| 1654 | + } |
|
| 1655 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1656 | + if (is_bool($options)) { |
|
| 1657 | + trigger_deprecation('spip', '5.0', 'Using boolean $options parameter in "%s()" function is deprecated. Use %s array parameter instead.', __FUNCTION__, '[\'echappe_span\' => ' . var_export($options, true) . ']'); |
|
| 1658 | + $options = ['echappe_span' => $options]; |
|
| 1659 | + } |
|
| 1660 | + if (!isset($options['echappe_span'])) { |
|
| 1661 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1662 | + } |
|
| 1663 | + $options['lang'] = $lang; |
|
| 1664 | 1664 | |
| 1665 | - $collecteurIdiomes = new CollecteurIdiomes(); |
|
| 1665 | + $collecteurIdiomes = new CollecteurIdiomes(); |
|
| 1666 | 1666 | |
| 1667 | - $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1668 | - } |
|
| 1669 | - return $letexte; |
|
| 1667 | + $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1668 | + } |
|
| 1669 | + return $letexte; |
|
| 1670 | 1670 | } |
| 1671 | 1671 | |
| 1672 | 1672 | /** |
@@ -1704,30 +1704,30 @@ discard block |
||
| 1704 | 1704 | **/ |
| 1705 | 1705 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1706 | 1706 | |
| 1707 | - if ($letexte && stripos($letexte, '<multi') !== false) { |
|
| 1708 | - if (!$lang) { |
|
| 1709 | - $lang = $GLOBALS['spip_lang']; |
|
| 1710 | - } |
|
| 1707 | + if ($letexte && stripos($letexte, '<multi') !== false) { |
|
| 1708 | + if (!$lang) { |
|
| 1709 | + $lang = $GLOBALS['spip_lang']; |
|
| 1710 | + } |
|
| 1711 | 1711 | |
| 1712 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1713 | - if (is_bool($options)) { |
|
| 1714 | - trigger_deprecation('spip', '5.0', 'Using boolean $options parameter in "%s()" function is deprecated. Use %s array parameter instead.', __FUNCTION__, '[\'echappe_span\' => ' . var_export($options, true) . ']'); |
|
| 1715 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1716 | - } |
|
| 1717 | - if (!isset($options['echappe_span'])) { |
|
| 1718 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1719 | - } |
|
| 1720 | - if (!isset($options['lang_defaut'])) { |
|
| 1721 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1722 | - } |
|
| 1723 | - $options['lang'] = $lang; |
|
| 1712 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1713 | + if (is_bool($options)) { |
|
| 1714 | + trigger_deprecation('spip', '5.0', 'Using boolean $options parameter in "%s()" function is deprecated. Use %s array parameter instead.', __FUNCTION__, '[\'echappe_span\' => ' . var_export($options, true) . ']'); |
|
| 1715 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1716 | + } |
|
| 1717 | + if (!isset($options['echappe_span'])) { |
|
| 1718 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1719 | + } |
|
| 1720 | + if (!isset($options['lang_defaut'])) { |
|
| 1721 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1722 | + } |
|
| 1723 | + $options['lang'] = $lang; |
|
| 1724 | 1724 | |
| 1725 | - $collecteurMultis = new CollecteurMultis(); |
|
| 1725 | + $collecteurMultis = new CollecteurMultis(); |
|
| 1726 | 1726 | |
| 1727 | - $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1728 | - } |
|
| 1727 | + $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1728 | + } |
|
| 1729 | 1729 | |
| 1730 | - return $letexte; |
|
| 1730 | + return $letexte; |
|
| 1731 | 1731 | } |
| 1732 | 1732 | |
| 1733 | 1733 | /** |
@@ -1737,7 +1737,7 @@ discard block |
||
| 1737 | 1737 | * @return string L'initiale en majuscule |
| 1738 | 1738 | */ |
| 1739 | 1739 | function filtre_initiale($nom) { |
| 1740 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1740 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1741 | 1741 | } |
| 1742 | 1742 | |
| 1743 | 1743 | |
@@ -1782,33 +1782,33 @@ discard block |
||
| 1782 | 1782 | * - null (interne) : si on empile |
| 1783 | 1783 | **/ |
| 1784 | 1784 | function unique($donnee, $famille = '', $cpt = false) { |
| 1785 | - static $mem = []; |
|
| 1786 | - // permettre de vider la pile et de la restaurer |
|
| 1787 | - // pour le calcul de introduction... |
|
| 1788 | - if ($famille == '_spip_raz_') { |
|
| 1789 | - $tmp = $mem; |
|
| 1790 | - $mem = []; |
|
| 1791 | - |
|
| 1792 | - return $tmp; |
|
| 1793 | - } elseif ($famille == '_spip_set_') { |
|
| 1794 | - $mem = $donnee; |
|
| 1795 | - |
|
| 1796 | - return; |
|
| 1797 | - } |
|
| 1798 | - // eviter une notice |
|
| 1799 | - if (!isset($mem[$famille])) { |
|
| 1800 | - $mem[$famille] = []; |
|
| 1801 | - } |
|
| 1802 | - if ($cpt) { |
|
| 1803 | - return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1804 | - } |
|
| 1805 | - // eviter une notice |
|
| 1806 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1807 | - $mem[$famille][$donnee] = 0; |
|
| 1808 | - } |
|
| 1809 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1810 | - return $donnee; |
|
| 1811 | - } |
|
| 1785 | + static $mem = []; |
|
| 1786 | + // permettre de vider la pile et de la restaurer |
|
| 1787 | + // pour le calcul de introduction... |
|
| 1788 | + if ($famille == '_spip_raz_') { |
|
| 1789 | + $tmp = $mem; |
|
| 1790 | + $mem = []; |
|
| 1791 | + |
|
| 1792 | + return $tmp; |
|
| 1793 | + } elseif ($famille == '_spip_set_') { |
|
| 1794 | + $mem = $donnee; |
|
| 1795 | + |
|
| 1796 | + return; |
|
| 1797 | + } |
|
| 1798 | + // eviter une notice |
|
| 1799 | + if (!isset($mem[$famille])) { |
|
| 1800 | + $mem[$famille] = []; |
|
| 1801 | + } |
|
| 1802 | + if ($cpt) { |
|
| 1803 | + return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1804 | + } |
|
| 1805 | + // eviter une notice |
|
| 1806 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1807 | + $mem[$famille][$donnee] = 0; |
|
| 1808 | + } |
|
| 1809 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1810 | + return $donnee; |
|
| 1811 | + } |
|
| 1812 | 1812 | } |
| 1813 | 1813 | |
| 1814 | 1814 | |
@@ -1838,20 +1838,20 @@ discard block |
||
| 1838 | 1838 | * Une des valeurs en fonction du compteur. |
| 1839 | 1839 | **/ |
| 1840 | 1840 | function alterner($i, ...$args) { |
| 1841 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1842 | - $num = count($args); |
|
| 1841 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1842 | + $num = count($args); |
|
| 1843 | 1843 | |
| 1844 | - if ($num === 1 && is_array($args[0])) { |
|
| 1845 | - // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1846 | - $args = array_values($args[0]); |
|
| 1847 | - $num = count($args); |
|
| 1848 | - } |
|
| 1844 | + if ($num === 1 && is_array($args[0])) { |
|
| 1845 | + // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1846 | + $args = array_values($args[0]); |
|
| 1847 | + $num = count($args); |
|
| 1848 | + } |
|
| 1849 | 1849 | |
| 1850 | - // un index compris entre 0 et num exclus |
|
| 1851 | - $i = (((int) $i - 1) % $num); // dans ]-$num;$num[ |
|
| 1852 | - $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1853 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1854 | - return $args[$i]; |
|
| 1850 | + // un index compris entre 0 et num exclus |
|
| 1851 | + $i = (((int) $i - 1) % $num); // dans ]-$num;$num[ |
|
| 1852 | + $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1853 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1854 | + return $args[$i]; |
|
| 1855 | 1855 | } |
| 1856 | 1856 | |
| 1857 | 1857 | |
@@ -1877,52 +1877,52 @@ discard block |
||
| 1877 | 1877 | * - null lorsque l’attribut n’existe pas. |
| 1878 | 1878 | **/ |
| 1879 | 1879 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1880 | - if (is_array($balise)) { |
|
| 1881 | - array_walk( |
|
| 1882 | - $balise, |
|
| 1883 | - function (&$a, $key, $t) { |
|
| 1884 | - $a = extraire_attribut($a, $t); |
|
| 1885 | - }, |
|
| 1886 | - $attribut |
|
| 1887 | - ); |
|
| 1888 | - |
|
| 1889 | - return $balise; |
|
| 1890 | - } |
|
| 1891 | - if ( |
|
| 1892 | - $balise |
|
| 1893 | - && stripos($balise, $attribut) !== false |
|
| 1894 | - && preg_match( |
|
| 1895 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1896 | - . $attribut |
|
| 1897 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1898 | - $balise, |
|
| 1899 | - $r |
|
| 1900 | - ) |
|
| 1901 | - ) { |
|
| 1902 | - if (isset($r[3][0]) && ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1903 | - $r[4] = substr($r[3], 1, -1); |
|
| 1904 | - $r[3] = $r[3][0]; |
|
| 1905 | - } elseif ($r[3] !== '') { |
|
| 1906 | - $r[4] = $r[3]; |
|
| 1907 | - $r[3] = ''; |
|
| 1908 | - } else { |
|
| 1909 | - $r[4] = trim($r[2]); |
|
| 1910 | - } |
|
| 1911 | - $att = $r[4]; |
|
| 1912 | - if (str_contains($att, '&#')) { |
|
| 1913 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1914 | - } |
|
| 1915 | - $att = filtrer_entites($att); |
|
| 1916 | - } else { |
|
| 1917 | - $att = null; |
|
| 1918 | - $r = []; |
|
| 1919 | - } |
|
| 1920 | - |
|
| 1921 | - if ($complet) { |
|
| 1922 | - return [$att, $r]; |
|
| 1923 | - } else { |
|
| 1924 | - return $att; |
|
| 1925 | - } |
|
| 1880 | + if (is_array($balise)) { |
|
| 1881 | + array_walk( |
|
| 1882 | + $balise, |
|
| 1883 | + function (&$a, $key, $t) { |
|
| 1884 | + $a = extraire_attribut($a, $t); |
|
| 1885 | + }, |
|
| 1886 | + $attribut |
|
| 1887 | + ); |
|
| 1888 | + |
|
| 1889 | + return $balise; |
|
| 1890 | + } |
|
| 1891 | + if ( |
|
| 1892 | + $balise |
|
| 1893 | + && stripos($balise, $attribut) !== false |
|
| 1894 | + && preg_match( |
|
| 1895 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1896 | + . $attribut |
|
| 1897 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1898 | + $balise, |
|
| 1899 | + $r |
|
| 1900 | + ) |
|
| 1901 | + ) { |
|
| 1902 | + if (isset($r[3][0]) && ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1903 | + $r[4] = substr($r[3], 1, -1); |
|
| 1904 | + $r[3] = $r[3][0]; |
|
| 1905 | + } elseif ($r[3] !== '') { |
|
| 1906 | + $r[4] = $r[3]; |
|
| 1907 | + $r[3] = ''; |
|
| 1908 | + } else { |
|
| 1909 | + $r[4] = trim($r[2]); |
|
| 1910 | + } |
|
| 1911 | + $att = $r[4]; |
|
| 1912 | + if (str_contains($att, '&#')) { |
|
| 1913 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1914 | + } |
|
| 1915 | + $att = filtrer_entites($att); |
|
| 1916 | + } else { |
|
| 1917 | + $att = null; |
|
| 1918 | + $r = []; |
|
| 1919 | + } |
|
| 1920 | + |
|
| 1921 | + if ($complet) { |
|
| 1922 | + return [$att, $r]; |
|
| 1923 | + } else { |
|
| 1924 | + return $att; |
|
| 1925 | + } |
|
| 1926 | 1926 | } |
| 1927 | 1927 | |
| 1928 | 1928 | /** |
@@ -1955,37 +1955,37 @@ discard block |
||
| 1955 | 1955 | **/ |
| 1956 | 1956 | function inserer_attribut(?string $balise, string $attribut, ?string $val, bool $proteger = true, bool $vider = false): string { |
| 1957 | 1957 | |
| 1958 | - if ($balise === null || $balise === '') { |
|
| 1959 | - return ''; |
|
| 1960 | - } |
|
| 1958 | + if ($balise === null || $balise === '') { |
|
| 1959 | + return ''; |
|
| 1960 | + } |
|
| 1961 | 1961 | |
| 1962 | - // preparer l'attribut |
|
| 1963 | - // supprimer les etc mais pas les balises html |
|
| 1964 | - // qui ont un sens dans un attribut value d'un input |
|
| 1965 | - if ($proteger) { |
|
| 1966 | - $val = attribut_html($val, false); |
|
| 1967 | - } |
|
| 1962 | + // preparer l'attribut |
|
| 1963 | + // supprimer les etc mais pas les balises html |
|
| 1964 | + // qui ont un sens dans un attribut value d'un input |
|
| 1965 | + if ($proteger) { |
|
| 1966 | + $val = attribut_html($val, false); |
|
| 1967 | + } |
|
| 1968 | 1968 | |
| 1969 | - // echapper les ' pour eviter tout bug |
|
| 1970 | - $val = str_replace("'", ''', $val ?? ''); |
|
| 1971 | - $insert = $vider && (string) $val === '' ? '' : " $attribut='$val'"; |
|
| 1969 | + // echapper les ' pour eviter tout bug |
|
| 1970 | + $val = str_replace("'", ''', $val ?? ''); |
|
| 1971 | + $insert = $vider && (string) $val === '' ? '' : " $attribut='$val'"; |
|
| 1972 | 1972 | |
| 1973 | - [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 1973 | + [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 1974 | 1974 | |
| 1975 | - if ($old !== null) { |
|
| 1976 | - // Remplacer l'ancien attribut du meme nom |
|
| 1977 | - $balise = $r[1] . $insert . $r[5]; |
|
| 1978 | - } else { |
|
| 1979 | - // preferer une balise " />" (comme <img />) |
|
| 1980 | - if (preg_match(',/>,', $balise)) { |
|
| 1981 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 1982 | - } // sinon une balise <a ...> ... </a> |
|
| 1983 | - else { |
|
| 1984 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 1985 | - } |
|
| 1986 | - } |
|
| 1975 | + if ($old !== null) { |
|
| 1976 | + // Remplacer l'ancien attribut du meme nom |
|
| 1977 | + $balise = $r[1] . $insert . $r[5]; |
|
| 1978 | + } else { |
|
| 1979 | + // preferer une balise " />" (comme <img />) |
|
| 1980 | + if (preg_match(',/>,', $balise)) { |
|
| 1981 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 1982 | + } // sinon une balise <a ...> ... </a> |
|
| 1983 | + else { |
|
| 1984 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 1985 | + } |
|
| 1986 | + } |
|
| 1987 | 1987 | |
| 1988 | - return $balise; |
|
| 1988 | + return $balise; |
|
| 1989 | 1989 | } |
| 1990 | 1990 | |
| 1991 | 1991 | /** |
@@ -2003,7 +2003,7 @@ discard block |
||
| 2003 | 2003 | * @return string Code HTML sans l'attribut |
| 2004 | 2004 | **/ |
| 2005 | 2005 | function vider_attribut(?string $balise, string $attribut): string { |
| 2006 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2006 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2007 | 2007 | } |
| 2008 | 2008 | |
| 2009 | 2009 | /** |
@@ -2015,50 +2015,50 @@ discard block |
||
| 2015 | 2015 | * @return string |
| 2016 | 2016 | */ |
| 2017 | 2017 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2018 | - if (is_string($class)) { |
|
| 2019 | - $class = explode(' ', trim($class)); |
|
| 2020 | - } |
|
| 2021 | - $class = array_filter($class); |
|
| 2022 | - $class = array_unique($class); |
|
| 2023 | - if (!$class) { |
|
| 2024 | - return $balise; |
|
| 2025 | - } |
|
| 2026 | - |
|
| 2027 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2028 | - $class_new = $class_courante; |
|
| 2029 | - foreach ($class as $c) { |
|
| 2030 | - $is_class_presente = false; |
|
| 2031 | - if ( |
|
| 2032 | - $class_courante |
|
| 2033 | - && str_contains($class_courante, (string) $c) |
|
| 2034 | - && in_array($c, preg_split(',\s+,', $class_courante)) |
|
| 2035 | - ) { |
|
| 2036 | - $is_class_presente = true; |
|
| 2037 | - } |
|
| 2038 | - if ( |
|
| 2039 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2040 | - && !$is_class_presente |
|
| 2041 | - ) { |
|
| 2042 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2043 | - } elseif ( |
|
| 2044 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2045 | - && $is_class_presente |
|
| 2046 | - ) { |
|
| 2047 | - $class_new = preg_split(',\s+,', $class_new); |
|
| 2048 | - $class_new = array_diff($class_new, [$c]); |
|
| 2049 | - $class_new = implode(' ', $class_new); |
|
| 2050 | - } |
|
| 2051 | - } |
|
| 2052 | - |
|
| 2053 | - if ($class_new !== $class_courante) { |
|
| 2054 | - if (strlen($class_new)) { |
|
| 2055 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2056 | - } elseif ($class_courante) { |
|
| 2057 | - $balise = vider_attribut($balise, 'class'); |
|
| 2058 | - } |
|
| 2059 | - } |
|
| 2060 | - |
|
| 2061 | - return $balise; |
|
| 2018 | + if (is_string($class)) { |
|
| 2019 | + $class = explode(' ', trim($class)); |
|
| 2020 | + } |
|
| 2021 | + $class = array_filter($class); |
|
| 2022 | + $class = array_unique($class); |
|
| 2023 | + if (!$class) { |
|
| 2024 | + return $balise; |
|
| 2025 | + } |
|
| 2026 | + |
|
| 2027 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2028 | + $class_new = $class_courante; |
|
| 2029 | + foreach ($class as $c) { |
|
| 2030 | + $is_class_presente = false; |
|
| 2031 | + if ( |
|
| 2032 | + $class_courante |
|
| 2033 | + && str_contains($class_courante, (string) $c) |
|
| 2034 | + && in_array($c, preg_split(',\s+,', $class_courante)) |
|
| 2035 | + ) { |
|
| 2036 | + $is_class_presente = true; |
|
| 2037 | + } |
|
| 2038 | + if ( |
|
| 2039 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2040 | + && !$is_class_presente |
|
| 2041 | + ) { |
|
| 2042 | + $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2043 | + } elseif ( |
|
| 2044 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2045 | + && $is_class_presente |
|
| 2046 | + ) { |
|
| 2047 | + $class_new = preg_split(',\s+,', $class_new); |
|
| 2048 | + $class_new = array_diff($class_new, [$c]); |
|
| 2049 | + $class_new = implode(' ', $class_new); |
|
| 2050 | + } |
|
| 2051 | + } |
|
| 2052 | + |
|
| 2053 | + if ($class_new !== $class_courante) { |
|
| 2054 | + if (strlen($class_new)) { |
|
| 2055 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2056 | + } elseif ($class_courante) { |
|
| 2057 | + $balise = vider_attribut($balise, 'class'); |
|
| 2058 | + } |
|
| 2059 | + } |
|
| 2060 | + |
|
| 2061 | + return $balise; |
|
| 2062 | 2062 | } |
| 2063 | 2063 | |
| 2064 | 2064 | /** |
@@ -2068,7 +2068,7 @@ discard block |
||
| 2068 | 2068 | * @return string |
| 2069 | 2069 | */ |
| 2070 | 2070 | function ajouter_class($balise, $class) { |
| 2071 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2071 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2072 | 2072 | } |
| 2073 | 2073 | |
| 2074 | 2074 | /** |
@@ -2078,7 +2078,7 @@ discard block |
||
| 2078 | 2078 | * @return string |
| 2079 | 2079 | */ |
| 2080 | 2080 | function supprimer_class($balise, $class) { |
| 2081 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2081 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2082 | 2082 | } |
| 2083 | 2083 | |
| 2084 | 2084 | /** |
@@ -2089,7 +2089,7 @@ discard block |
||
| 2089 | 2089 | * @return string |
| 2090 | 2090 | */ |
| 2091 | 2091 | function commuter_class($balise, $class) { |
| 2092 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2092 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2093 | 2093 | } |
| 2094 | 2094 | |
| 2095 | 2095 | /** |
@@ -2100,19 +2100,19 @@ discard block |
||
| 2100 | 2100 | * @return string |
| 2101 | 2101 | */ |
| 2102 | 2102 | function tester_config($id, $mode = '') { |
| 2103 | - include_spip('action/inscrire_auteur'); |
|
| 2103 | + include_spip('action/inscrire_auteur'); |
|
| 2104 | 2104 | |
| 2105 | - return tester_statut_inscription($mode, $id); |
|
| 2105 | + return tester_statut_inscription($mode, $id); |
|
| 2106 | 2106 | } |
| 2107 | 2107 | |
| 2108 | 2108 | // |
| 2109 | 2109 | // Quelques fonctions de calcul arithmetique |
| 2110 | 2110 | // |
| 2111 | 2111 | function floatstr($a) { |
| 2112 | - return str_replace(',', '.', (string)(float) $a); |
|
| 2112 | + return str_replace(',', '.', (string)(float) $a); |
|
| 2113 | 2113 | } |
| 2114 | 2114 | function strize($f, $a, $b) { |
| 2115 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2115 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2116 | 2116 | } |
| 2117 | 2117 | |
| 2118 | 2118 | /** |
@@ -2131,11 +2131,11 @@ discard block |
||
| 2131 | 2131 | * @return int $a+$b |
| 2132 | 2132 | **/ |
| 2133 | 2133 | function plus($a, $b) { |
| 2134 | - return $a + $b; |
|
| 2134 | + return $a + $b; |
|
| 2135 | 2135 | } |
| 2136 | 2136 | |
| 2137 | 2137 | function strplus($a, $b) { |
| 2138 | - return strize('plus', $a, $b); |
|
| 2138 | + return strize('plus', $a, $b); |
|
| 2139 | 2139 | } |
| 2140 | 2140 | |
| 2141 | 2141 | /** |
@@ -2154,11 +2154,11 @@ discard block |
||
| 2154 | 2154 | * @return int $a-$b |
| 2155 | 2155 | **/ |
| 2156 | 2156 | function moins($a, $b) { |
| 2157 | - return $a - $b; |
|
| 2157 | + return $a - $b; |
|
| 2158 | 2158 | } |
| 2159 | 2159 | |
| 2160 | 2160 | function strmoins($a, $b) { |
| 2161 | - return strize('moins', $a, $b); |
|
| 2161 | + return strize('moins', $a, $b); |
|
| 2162 | 2162 | } |
| 2163 | 2163 | |
| 2164 | 2164 | /** |
@@ -2178,11 +2178,11 @@ discard block |
||
| 2178 | 2178 | * @return int $a*$b |
| 2179 | 2179 | **/ |
| 2180 | 2180 | function mult($a, $b) { |
| 2181 | - return $a * $b; |
|
| 2181 | + return $a * $b; |
|
| 2182 | 2182 | } |
| 2183 | 2183 | |
| 2184 | 2184 | function strmult($a, $b) { |
| 2185 | - return strize('mult', $a, $b); |
|
| 2185 | + return strize('mult', $a, $b); |
|
| 2186 | 2186 | } |
| 2187 | 2187 | |
| 2188 | 2188 | /** |
@@ -2202,11 +2202,11 @@ discard block |
||
| 2202 | 2202 | * @return int $a/$b (ou 0 si $b est nul) |
| 2203 | 2203 | **/ |
| 2204 | 2204 | function div($a, $b) { |
| 2205 | - return $b ? $a / $b : 0; |
|
| 2205 | + return $b ? $a / $b : 0; |
|
| 2206 | 2206 | } |
| 2207 | 2207 | |
| 2208 | 2208 | function strdiv($a, $b) { |
| 2209 | - return strize('div', $a, $b); |
|
| 2209 | + return strize('div', $a, $b); |
|
| 2210 | 2210 | } |
| 2211 | 2211 | |
| 2212 | 2212 | /** |
@@ -2227,7 +2227,7 @@ discard block |
||
| 2227 | 2227 | * @return int ($nb % $mod) + $add |
| 2228 | 2228 | **/ |
| 2229 | 2229 | function modulo($nb, $mod, $add = 0) { |
| 2230 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2230 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2231 | 2231 | } |
| 2232 | 2232 | |
| 2233 | 2233 | |
@@ -2242,26 +2242,26 @@ discard block |
||
| 2242 | 2242 | * - true sinon |
| 2243 | 2243 | **/ |
| 2244 | 2244 | function nom_acceptable($nom) { |
| 2245 | - $remp2 = []; |
|
| 2246 | - $remp1 = []; |
|
| 2247 | - if (!is_string($nom)) { |
|
| 2248 | - return false; |
|
| 2249 | - } |
|
| 2250 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2251 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2252 | - } |
|
| 2253 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2254 | - foreach ($tags_acceptes as $tag) { |
|
| 2255 | - if (strlen($tag)) { |
|
| 2256 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2257 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2258 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2259 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2260 | - } |
|
| 2261 | - } |
|
| 2262 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2263 | - |
|
| 2264 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2245 | + $remp2 = []; |
|
| 2246 | + $remp1 = []; |
|
| 2247 | + if (!is_string($nom)) { |
|
| 2248 | + return false; |
|
| 2249 | + } |
|
| 2250 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2251 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2252 | + } |
|
| 2253 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2254 | + foreach ($tags_acceptes as $tag) { |
|
| 2255 | + if (strlen($tag)) { |
|
| 2256 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2257 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2258 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2259 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2260 | + } |
|
| 2261 | + } |
|
| 2262 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2263 | + |
|
| 2264 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2265 | 2265 | } |
| 2266 | 2266 | |
| 2267 | 2267 | |
@@ -2277,13 +2277,13 @@ discard block |
||
| 2277 | 2277 | * - renvoie un tableau si l'entree est un tableau |
| 2278 | 2278 | **/ |
| 2279 | 2279 | function email_valide($adresses) { |
| 2280 | - if (is_array($adresses)) { |
|
| 2281 | - $adresses = array_map('email_valide', $adresses); |
|
| 2282 | - return array_filter($adresses); |
|
| 2283 | - } |
|
| 2280 | + if (is_array($adresses)) { |
|
| 2281 | + $adresses = array_map('email_valide', $adresses); |
|
| 2282 | + return array_filter($adresses); |
|
| 2283 | + } |
|
| 2284 | 2284 | |
| 2285 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2286 | - return $email_valide($adresses); |
|
| 2285 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2286 | + return $email_valide($adresses); |
|
| 2287 | 2287 | } |
| 2288 | 2288 | |
| 2289 | 2289 | /** |
@@ -2297,29 +2297,29 @@ discard block |
||
| 2297 | 2297 | * @return string texte |
| 2298 | 2298 | **/ |
| 2299 | 2299 | function afficher_enclosures($tags) { |
| 2300 | - $s = []; |
|
| 2301 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2302 | - if ( |
|
| 2303 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2304 | - && ($t = extraire_attribut($tag, 'href')) |
|
| 2305 | - ) { |
|
| 2306 | - $s[] = preg_replace( |
|
| 2307 | - ',>[^<]+</a>,S', |
|
| 2308 | - '>' |
|
| 2309 | - . http_img_pack( |
|
| 2310 | - 'attachment-16.png', |
|
| 2311 | - $t, |
|
| 2312 | - '', |
|
| 2313 | - $t, |
|
| 2314 | - ['utiliser_suffixe_size' => true] |
|
| 2315 | - ) |
|
| 2316 | - . '</a>', |
|
| 2317 | - (string) $tag |
|
| 2318 | - ); |
|
| 2319 | - } |
|
| 2320 | - } |
|
| 2321 | - |
|
| 2322 | - return implode(' ', $s); |
|
| 2300 | + $s = []; |
|
| 2301 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2302 | + if ( |
|
| 2303 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2304 | + && ($t = extraire_attribut($tag, 'href')) |
|
| 2305 | + ) { |
|
| 2306 | + $s[] = preg_replace( |
|
| 2307 | + ',>[^<]+</a>,S', |
|
| 2308 | + '>' |
|
| 2309 | + . http_img_pack( |
|
| 2310 | + 'attachment-16.png', |
|
| 2311 | + $t, |
|
| 2312 | + '', |
|
| 2313 | + $t, |
|
| 2314 | + ['utiliser_suffixe_size' => true] |
|
| 2315 | + ) |
|
| 2316 | + . '</a>', |
|
| 2317 | + (string) $tag |
|
| 2318 | + ); |
|
| 2319 | + } |
|
| 2320 | + } |
|
| 2321 | + |
|
| 2322 | + return implode(' ', $s); |
|
| 2323 | 2323 | } |
| 2324 | 2324 | |
| 2325 | 2325 | /** |
@@ -2334,15 +2334,15 @@ discard block |
||
| 2334 | 2334 | * @return string Liens trouvés |
| 2335 | 2335 | **/ |
| 2336 | 2336 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2337 | - $s = []; |
|
| 2338 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2339 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2340 | - if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2341 | - $s[] = $tag; |
|
| 2342 | - } |
|
| 2343 | - } |
|
| 2337 | + $s = []; |
|
| 2338 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2339 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2340 | + if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2341 | + $s[] = $tag; |
|
| 2342 | + } |
|
| 2343 | + } |
|
| 2344 | 2344 | |
| 2345 | - return implode(', ', $s); |
|
| 2345 | + return implode(', ', $s); |
|
| 2346 | 2346 | } |
| 2347 | 2347 | |
| 2348 | 2348 | |
@@ -2364,21 +2364,21 @@ discard block |
||
| 2364 | 2364 | * @return string Tag HTML `<a>` avec microformat. |
| 2365 | 2365 | **/ |
| 2366 | 2366 | function enclosure2microformat($e) { |
| 2367 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2368 | - $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2369 | - } |
|
| 2370 | - $type = extraire_attribut($e, 'type'); |
|
| 2371 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2372 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2373 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2374 | - } |
|
| 2375 | - $fichier = basename($url); |
|
| 2367 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2368 | + $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2369 | + } |
|
| 2370 | + $type = extraire_attribut($e, 'type'); |
|
| 2371 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2372 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2373 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2374 | + } |
|
| 2375 | + $fichier = basename($url); |
|
| 2376 | 2376 | |
| 2377 | - return '<a rel="enclosure"' |
|
| 2378 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2379 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2380 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2381 | - . '>' . $fichier . '</a>'; |
|
| 2377 | + return '<a rel="enclosure"' |
|
| 2378 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2379 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2380 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2381 | + . '>' . $fichier . '</a>'; |
|
| 2382 | 2382 | } |
| 2383 | 2383 | |
| 2384 | 2384 | /** |
@@ -2396,24 +2396,24 @@ discard block |
||
| 2396 | 2396 | * @return string Tags RSS `<enclosure>`. |
| 2397 | 2397 | **/ |
| 2398 | 2398 | function microformat2enclosure($tags) { |
| 2399 | - $enclosures = []; |
|
| 2400 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2401 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2402 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2403 | - $type = extraire_attribut($e, 'type'); |
|
| 2404 | - if (!$length = (int) extraire_attribut($e, 'title')) { |
|
| 2405 | - $length = (int) extraire_attribut($e, 'length'); |
|
| 2406 | - } # vieux data |
|
| 2407 | - $fichier = basename($url); |
|
| 2408 | - $enclosures[] = '<enclosure' |
|
| 2409 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2410 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2411 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2412 | - . ' />'; |
|
| 2413 | - } |
|
| 2414 | - } |
|
| 2399 | + $enclosures = []; |
|
| 2400 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2401 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2402 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2403 | + $type = extraire_attribut($e, 'type'); |
|
| 2404 | + if (!$length = (int) extraire_attribut($e, 'title')) { |
|
| 2405 | + $length = (int) extraire_attribut($e, 'length'); |
|
| 2406 | + } # vieux data |
|
| 2407 | + $fichier = basename($url); |
|
| 2408 | + $enclosures[] = '<enclosure' |
|
| 2409 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2410 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2411 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2412 | + . ' />'; |
|
| 2413 | + } |
|
| 2414 | + } |
|
| 2415 | 2415 | |
| 2416 | - return implode("\n", $enclosures); |
|
| 2416 | + return implode("\n", $enclosures); |
|
| 2417 | 2417 | } |
| 2418 | 2418 | |
| 2419 | 2419 | |
@@ -2429,16 +2429,16 @@ discard block |
||
| 2429 | 2429 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2430 | 2430 | **/ |
| 2431 | 2431 | function tags2dcsubject($tags) { |
| 2432 | - $subjects = ''; |
|
| 2433 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2434 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2435 | - $subjects .= '<dc:subject>' |
|
| 2436 | - . texte_backend(textebrut($e)) |
|
| 2437 | - . '</dc:subject>' . "\n"; |
|
| 2438 | - } |
|
| 2439 | - } |
|
| 2432 | + $subjects = ''; |
|
| 2433 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2434 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2435 | + $subjects .= '<dc:subject>' |
|
| 2436 | + . texte_backend(textebrut($e)) |
|
| 2437 | + . '</dc:subject>' . "\n"; |
|
| 2438 | + } |
|
| 2439 | + } |
|
| 2440 | 2440 | |
| 2441 | - return $subjects; |
|
| 2441 | + return $subjects; |
|
| 2442 | 2442 | } |
| 2443 | 2443 | |
| 2444 | 2444 | /** |
@@ -2467,12 +2467,12 @@ discard block |
||
| 2467 | 2467 | * - Tableau de résultats, si tableau en entrée. |
| 2468 | 2468 | **/ |
| 2469 | 2469 | function extraire_balise($texte, $tag = 'a', $profondeur = 1) { |
| 2470 | - $balises = extraire_balises($texte, $tag, ['nb_max' => 1, 'profondeur' => $profondeur]); |
|
| 2471 | - if (is_array($texte)) { |
|
| 2472 | - return array_map(fn (array $a) => empty($a) ? '' : reset($a), $balises); |
|
| 2473 | - } |
|
| 2470 | + $balises = extraire_balises($texte, $tag, ['nb_max' => 1, 'profondeur' => $profondeur]); |
|
| 2471 | + if (is_array($texte)) { |
|
| 2472 | + return array_map(fn (array $a) => empty($a) ? '' : reset($a), $balises); |
|
| 2473 | + } |
|
| 2474 | 2474 | |
| 2475 | - return (empty($balises) ? '' : reset($balises)); |
|
| 2475 | + return (empty($balises) ? '' : reset($balises)); |
|
| 2476 | 2476 | } |
| 2477 | 2477 | |
| 2478 | 2478 | /** |
@@ -2500,25 +2500,25 @@ discard block |
||
| 2500 | 2500 | * - Tableau de résultats, si tableau en entrée. |
| 2501 | 2501 | **/ |
| 2502 | 2502 | function extraire_balises($texte, $tag = 'a', $options = []) { |
| 2503 | - if (is_array($texte)) { |
|
| 2504 | - array_walk( |
|
| 2505 | - $texte, |
|
| 2506 | - function (&$a, $key, $t) { |
|
| 2507 | - $a = extraire_balises($a, $t); |
|
| 2508 | - }, |
|
| 2509 | - $tag |
|
| 2510 | - ); |
|
| 2503 | + if (is_array($texte)) { |
|
| 2504 | + array_walk( |
|
| 2505 | + $texte, |
|
| 2506 | + function (&$a, $key, $t) { |
|
| 2507 | + $a = extraire_balises($a, $t); |
|
| 2508 | + }, |
|
| 2509 | + $tag |
|
| 2510 | + ); |
|
| 2511 | 2511 | |
| 2512 | - return $texte; |
|
| 2513 | - } |
|
| 2512 | + return $texte; |
|
| 2513 | + } |
|
| 2514 | 2514 | |
| 2515 | - $htmlTagCollecteur = new CollecteurHtmlTag($tag); |
|
| 2516 | - $collection = $htmlTagCollecteur->collecter($texte, $options); |
|
| 2517 | - if (!empty($collection)) { |
|
| 2518 | - return array_column($collection, 'raw'); |
|
| 2519 | - } |
|
| 2515 | + $htmlTagCollecteur = new CollecteurHtmlTag($tag); |
|
| 2516 | + $collection = $htmlTagCollecteur->collecter($texte, $options); |
|
| 2517 | + if (!empty($collection)) { |
|
| 2518 | + return array_column($collection, 'raw'); |
|
| 2519 | + } |
|
| 2520 | 2520 | |
| 2521 | - return []; |
|
| 2521 | + return []; |
|
| 2522 | 2522 | } |
| 2523 | 2523 | |
| 2524 | 2524 | /** |
@@ -2547,11 +2547,11 @@ discard block |
||
| 2547 | 2547 | * - `$def` si on n'a pas transmis de tableau |
| 2548 | 2548 | **/ |
| 2549 | 2549 | function in_any($val, $vals, $def = '') { |
| 2550 | - if (!is_array($vals) && $vals && ($v = unserialize($vals))) { |
|
| 2551 | - $vals = $v; |
|
| 2552 | - } |
|
| 2550 | + if (!is_array($vals) && $vals && ($v = unserialize($vals))) { |
|
| 2551 | + $vals = $v; |
|
| 2552 | + } |
|
| 2553 | 2553 | |
| 2554 | - return (is_array($vals) ? (in_array($val, $vals) ? ' ' : '') : ($def)); |
|
| 2554 | + return (is_array($vals) ? (in_array($val, $vals) ? ' ' : '') : ($def)); |
|
| 2555 | 2555 | } |
| 2556 | 2556 | |
| 2557 | 2557 | |
@@ -2572,12 +2572,12 @@ discard block |
||
| 2572 | 2572 | * Résultat du calcul |
| 2573 | 2573 | **/ |
| 2574 | 2574 | function valeur_numerique($expr) { |
| 2575 | - $a = 0; |
|
| 2576 | - if (preg_match(',^\d+(\s*[+*-]\s*\d+)*$,S', trim($expr))) { |
|
| 2577 | - eval("\$a = $expr;"); |
|
| 2578 | - } |
|
| 2575 | + $a = 0; |
|
| 2576 | + if (preg_match(',^\d+(\s*[+*-]\s*\d+)*$,S', trim($expr))) { |
|
| 2577 | + eval("\$a = $expr;"); |
|
| 2578 | + } |
|
| 2579 | 2579 | |
| 2580 | - return (int) $a; |
|
| 2580 | + return (int) $a; |
|
| 2581 | 2581 | } |
| 2582 | 2582 | |
| 2583 | 2583 | /** |
@@ -2596,7 +2596,7 @@ discard block |
||
| 2596 | 2596 | * Retourne `$a*$b/$c` |
| 2597 | 2597 | **/ |
| 2598 | 2598 | function regledetrois($a, $b, $c) { |
| 2599 | - return round($a * $b / $c); |
|
| 2599 | + return round($a * $b / $c); |
|
| 2600 | 2600 | } |
| 2601 | 2601 | |
| 2602 | 2602 | |
@@ -2619,79 +2619,79 @@ discard block |
||
| 2619 | 2619 | * @return string Suite de champs input hidden |
| 2620 | 2620 | **/ |
| 2621 | 2621 | function form_hidden(?string $action = ''): string { |
| 2622 | - $action ??= ''; |
|
| 2623 | - |
|
| 2624 | - $contexte = []; |
|
| 2625 | - include_spip('inc/urls'); |
|
| 2626 | - if ( |
|
| 2627 | - ($p = urls_decoder_url($action, '')) |
|
| 2628 | - && reset($p) |
|
| 2629 | - ) { |
|
| 2630 | - $fond = array_shift($p); |
|
| 2631 | - if ($fond != '404') { |
|
| 2632 | - $contexte = array_shift($p); |
|
| 2633 | - $contexte['page'] = $fond; |
|
| 2634 | - $action = preg_replace('/([?]' . preg_quote((string) $fond, '/') . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2635 | - } |
|
| 2636 | - } |
|
| 2637 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2638 | - if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) { |
|
| 2639 | - unset($contexte['type']); |
|
| 2640 | - } |
|
| 2641 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2642 | - unset($contexte['type-page']); |
|
| 2643 | - } |
|
| 2644 | - |
|
| 2645 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2646 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2647 | - $values = []; |
|
| 2648 | - |
|
| 2649 | - // d'abord avec celles de l'url |
|
| 2650 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2651 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2652 | - $c = explode('=', (string) $c, 2); |
|
| 2653 | - $var = array_shift($c); |
|
| 2654 | - $val = array_shift($c) ?? ''; |
|
| 2655 | - if ($var) { |
|
| 2656 | - $val = rawurldecode($val); |
|
| 2657 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2658 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2659 | - $values[] = [$var, $val]; |
|
| 2660 | - } else { |
|
| 2661 | - if (!isset($values[$var])) { |
|
| 2662 | - $values[$var] = [$var, $val]; |
|
| 2663 | - } |
|
| 2664 | - } |
|
| 2665 | - } |
|
| 2666 | - } |
|
| 2667 | - } |
|
| 2668 | - |
|
| 2669 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2670 | - foreach ($contexte as $var => $val) { |
|
| 2671 | - if (preg_match(',\[\]$,S', (string) $var)) { |
|
| 2672 | - $values[] = [$var, $val]; |
|
| 2673 | - } else { |
|
| 2674 | - if (!isset($values[$var])) { |
|
| 2675 | - $values[$var] = [$var, $val]; |
|
| 2676 | - } |
|
| 2677 | - } |
|
| 2678 | - } |
|
| 2679 | - |
|
| 2680 | - // puis on rassemble le tout |
|
| 2681 | - $hidden = []; |
|
| 2682 | - foreach ($values as $value) { |
|
| 2683 | - [$var, $val] = $value; |
|
| 2684 | - $hidden[] = '<input name="' |
|
| 2685 | - . entites_html($var) |
|
| 2686 | - . '"' |
|
| 2687 | - . (is_null($val) |
|
| 2688 | - ? '' |
|
| 2689 | - : ' value="' . entites_html($val) . '"' |
|
| 2690 | - ) |
|
| 2691 | - . ' type="hidden"' . "\n/>"; |
|
| 2692 | - } |
|
| 2693 | - |
|
| 2694 | - return implode('', $hidden); |
|
| 2622 | + $action ??= ''; |
|
| 2623 | + |
|
| 2624 | + $contexte = []; |
|
| 2625 | + include_spip('inc/urls'); |
|
| 2626 | + if ( |
|
| 2627 | + ($p = urls_decoder_url($action, '')) |
|
| 2628 | + && reset($p) |
|
| 2629 | + ) { |
|
| 2630 | + $fond = array_shift($p); |
|
| 2631 | + if ($fond != '404') { |
|
| 2632 | + $contexte = array_shift($p); |
|
| 2633 | + $contexte['page'] = $fond; |
|
| 2634 | + $action = preg_replace('/([?]' . preg_quote((string) $fond, '/') . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2635 | + } |
|
| 2636 | + } |
|
| 2637 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2638 | + if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) { |
|
| 2639 | + unset($contexte['type']); |
|
| 2640 | + } |
|
| 2641 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2642 | + unset($contexte['type-page']); |
|
| 2643 | + } |
|
| 2644 | + |
|
| 2645 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2646 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2647 | + $values = []; |
|
| 2648 | + |
|
| 2649 | + // d'abord avec celles de l'url |
|
| 2650 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2651 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2652 | + $c = explode('=', (string) $c, 2); |
|
| 2653 | + $var = array_shift($c); |
|
| 2654 | + $val = array_shift($c) ?? ''; |
|
| 2655 | + if ($var) { |
|
| 2656 | + $val = rawurldecode($val); |
|
| 2657 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2658 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2659 | + $values[] = [$var, $val]; |
|
| 2660 | + } else { |
|
| 2661 | + if (!isset($values[$var])) { |
|
| 2662 | + $values[$var] = [$var, $val]; |
|
| 2663 | + } |
|
| 2664 | + } |
|
| 2665 | + } |
|
| 2666 | + } |
|
| 2667 | + } |
|
| 2668 | + |
|
| 2669 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2670 | + foreach ($contexte as $var => $val) { |
|
| 2671 | + if (preg_match(',\[\]$,S', (string) $var)) { |
|
| 2672 | + $values[] = [$var, $val]; |
|
| 2673 | + } else { |
|
| 2674 | + if (!isset($values[$var])) { |
|
| 2675 | + $values[$var] = [$var, $val]; |
|
| 2676 | + } |
|
| 2677 | + } |
|
| 2678 | + } |
|
| 2679 | + |
|
| 2680 | + // puis on rassemble le tout |
|
| 2681 | + $hidden = []; |
|
| 2682 | + foreach ($values as $value) { |
|
| 2683 | + [$var, $val] = $value; |
|
| 2684 | + $hidden[] = '<input name="' |
|
| 2685 | + . entites_html($var) |
|
| 2686 | + . '"' |
|
| 2687 | + . (is_null($val) |
|
| 2688 | + ? '' |
|
| 2689 | + : ' value="' . entites_html($val) . '"' |
|
| 2690 | + ) |
|
| 2691 | + . ' type="hidden"' . "\n/>"; |
|
| 2692 | + } |
|
| 2693 | + |
|
| 2694 | + return implode('', $hidden); |
|
| 2695 | 2695 | } |
| 2696 | 2696 | |
| 2697 | 2697 | |
@@ -2713,7 +2713,7 @@ discard block |
||
| 2713 | 2713 | * - la première valeur du tableau sinon. |
| 2714 | 2714 | **/ |
| 2715 | 2715 | function filtre_reset($array) { |
| 2716 | - return is_array($array) ? reset($array) : null; |
|
| 2716 | + return is_array($array) ? reset($array) : null; |
|
| 2717 | 2717 | } |
| 2718 | 2718 | |
| 2719 | 2719 | /** |
@@ -2734,7 +2734,7 @@ discard block |
||
| 2734 | 2734 | * - la dernière valeur du tableau sinon. |
| 2735 | 2735 | **/ |
| 2736 | 2736 | function filtre_end($array) { |
| 2737 | - return is_array($array) ? end($array) : null; |
|
| 2737 | + return is_array($array) ? end($array) : null; |
|
| 2738 | 2738 | } |
| 2739 | 2739 | |
| 2740 | 2740 | /** |
@@ -2754,11 +2754,11 @@ discard block |
||
| 2754 | 2754 | * |
| 2755 | 2755 | **/ |
| 2756 | 2756 | function filtre_push($array, mixed $val) { |
| 2757 | - if (!is_array($array) || !array_push($array, $val)) { |
|
| 2758 | - return ''; |
|
| 2759 | - } |
|
| 2757 | + if (!is_array($array) || !array_push($array, $val)) { |
|
| 2758 | + return ''; |
|
| 2759 | + } |
|
| 2760 | 2760 | |
| 2761 | - return $array; |
|
| 2761 | + return $array; |
|
| 2762 | 2762 | } |
| 2763 | 2763 | |
| 2764 | 2764 | /** |
@@ -2777,7 +2777,7 @@ discard block |
||
| 2777 | 2777 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2778 | 2778 | **/ |
| 2779 | 2779 | function filtre_find($array, mixed $val) { |
| 2780 | - return (is_array($array) && in_array($val, $array)); |
|
| 2780 | + return (is_array($array) && in_array($val, $array)); |
|
| 2781 | 2781 | } |
| 2782 | 2782 | |
| 2783 | 2783 | |
@@ -2794,13 +2794,13 @@ discard block |
||
| 2794 | 2794 | * Contenu avec urls en absolus |
| 2795 | 2795 | **/ |
| 2796 | 2796 | function urls_absolues_css($contenu, $source) { |
| 2797 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2797 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2798 | 2798 | |
| 2799 | - return preg_replace_callback( |
|
| 2800 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2801 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2802 | - $contenu |
|
| 2803 | - ); |
|
| 2799 | + return preg_replace_callback( |
|
| 2800 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2801 | + fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2802 | + $contenu |
|
| 2803 | + ); |
|
| 2804 | 2804 | } |
| 2805 | 2805 | |
| 2806 | 2806 | |
@@ -2829,123 +2829,123 @@ discard block |
||
| 2829 | 2829 | * Chemin du fichier CSS inversé |
| 2830 | 2830 | **/ |
| 2831 | 2831 | function direction_css($css, $voulue = '') { |
| 2832 | - if (!$css) { |
|
| 2833 | - return ''; |
|
| 2834 | - } |
|
| 2835 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2836 | - return $css; |
|
| 2837 | - } |
|
| 2838 | - include_spip('inc/lang'); |
|
| 2839 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2840 | - if ($voulue = strtolower($voulue)) { |
|
| 2841 | - if ($voulue != 'rtl' && $voulue != 'ltr') { |
|
| 2842 | - $voulue = lang_dir($voulue); |
|
| 2843 | - } |
|
| 2844 | - } else { |
|
| 2845 | - $voulue = lang_dir(); |
|
| 2846 | - } |
|
| 2847 | - |
|
| 2848 | - $r = count($r) > 1; |
|
| 2849 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2850 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2851 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2852 | - |
|
| 2853 | - if ($voulue == $dir) { |
|
| 2854 | - return $css; |
|
| 2855 | - } |
|
| 2856 | - |
|
| 2857 | - if ( |
|
| 2858 | - // url absolue |
|
| 2859 | - preg_match(',^https?:,i', $css) |
|
| 2860 | - // ou qui contient un ? |
|
| 2861 | - || ($p = strpos($css, '?')) !== false |
|
| 2862 | - ) { |
|
| 2863 | - $distant = true; |
|
| 2864 | - $cssf = parse_url($css); |
|
| 2865 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2866 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2867 | - } else { |
|
| 2868 | - $distant = false; |
|
| 2869 | - $cssf = $css; |
|
| 2870 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2871 | - //propose (rien a faire dans ce cas) |
|
| 2872 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2873 | - if (@file_exists($f)) { |
|
| 2874 | - return $f; |
|
| 2875 | - } |
|
| 2876 | - } |
|
| 2877 | - |
|
| 2878 | - // 2. |
|
| 2879 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2880 | - $f = $dir_var |
|
| 2881 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2882 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2883 | - |
|
| 2884 | - // la css peut etre distante (url absolue !) |
|
| 2885 | - $contenu = null; |
|
| 2886 | - if ($distant) { |
|
| 2887 | - include_spip('inc/distant'); |
|
| 2888 | - $res = recuperer_url($css); |
|
| 2889 | - if (!$res || !($contenu = $res['page'])) { |
|
| 2890 | - return $css; |
|
| 2891 | - } |
|
| 2892 | - } else { |
|
| 2893 | - if ( |
|
| 2894 | - @filemtime($f) > @filemtime($css) |
|
| 2895 | - && _VAR_MODE != 'recalcul' |
|
| 2896 | - ) { |
|
| 2897 | - return $f; |
|
| 2898 | - } |
|
| 2899 | - if (!lire_fichier($css, $contenu)) { |
|
| 2900 | - return $css; |
|
| 2901 | - } |
|
| 2902 | - } |
|
| 2903 | - |
|
| 2904 | - |
|
| 2905 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2906 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 2907 | - $parser = new csstidy(); |
|
| 2908 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 2909 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 2910 | - $parser->parse($contenu); |
|
| 2911 | - |
|
| 2912 | - $contenu = $parser->print->plain(); |
|
| 2913 | - |
|
| 2914 | - |
|
| 2915 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 2916 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", (string) $contenu, $regs); |
|
| 2917 | - $src = []; |
|
| 2918 | - $src_direction_css = []; |
|
| 2919 | - $src_faux_abs = []; |
|
| 2920 | - $d = dirname($css); |
|
| 2921 | - foreach ($regs[1] as $k => $import_css) { |
|
| 2922 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2923 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2924 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2925 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2926 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2927 | - elseif (str_starts_with($css_direction, $dir_var)) { |
|
| 2928 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2929 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2930 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2931 | - } |
|
| 2932 | - $src[] = $regs[0][$k]; |
|
| 2933 | - $src_direction_css[] = str_replace($import_css, $css_direction, (string) $regs[0][$k]); |
|
| 2934 | - } |
|
| 2935 | - $contenu = str_replace($src, $src_direction_css, (string) $contenu); |
|
| 2936 | - |
|
| 2937 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2938 | - |
|
| 2939 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 2940 | - if ($src_faux_abs !== []) { |
|
| 2941 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2942 | - } |
|
| 2943 | - |
|
| 2944 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 2945 | - return $css; |
|
| 2946 | - } |
|
| 2947 | - |
|
| 2948 | - return $f; |
|
| 2832 | + if (!$css) { |
|
| 2833 | + return ''; |
|
| 2834 | + } |
|
| 2835 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2836 | + return $css; |
|
| 2837 | + } |
|
| 2838 | + include_spip('inc/lang'); |
|
| 2839 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2840 | + if ($voulue = strtolower($voulue)) { |
|
| 2841 | + if ($voulue != 'rtl' && $voulue != 'ltr') { |
|
| 2842 | + $voulue = lang_dir($voulue); |
|
| 2843 | + } |
|
| 2844 | + } else { |
|
| 2845 | + $voulue = lang_dir(); |
|
| 2846 | + } |
|
| 2847 | + |
|
| 2848 | + $r = count($r) > 1; |
|
| 2849 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2850 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2851 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2852 | + |
|
| 2853 | + if ($voulue == $dir) { |
|
| 2854 | + return $css; |
|
| 2855 | + } |
|
| 2856 | + |
|
| 2857 | + if ( |
|
| 2858 | + // url absolue |
|
| 2859 | + preg_match(',^https?:,i', $css) |
|
| 2860 | + // ou qui contient un ? |
|
| 2861 | + || ($p = strpos($css, '?')) !== false |
|
| 2862 | + ) { |
|
| 2863 | + $distant = true; |
|
| 2864 | + $cssf = parse_url($css); |
|
| 2865 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2866 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2867 | + } else { |
|
| 2868 | + $distant = false; |
|
| 2869 | + $cssf = $css; |
|
| 2870 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2871 | + //propose (rien a faire dans ce cas) |
|
| 2872 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2873 | + if (@file_exists($f)) { |
|
| 2874 | + return $f; |
|
| 2875 | + } |
|
| 2876 | + } |
|
| 2877 | + |
|
| 2878 | + // 2. |
|
| 2879 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2880 | + $f = $dir_var |
|
| 2881 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2882 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2883 | + |
|
| 2884 | + // la css peut etre distante (url absolue !) |
|
| 2885 | + $contenu = null; |
|
| 2886 | + if ($distant) { |
|
| 2887 | + include_spip('inc/distant'); |
|
| 2888 | + $res = recuperer_url($css); |
|
| 2889 | + if (!$res || !($contenu = $res['page'])) { |
|
| 2890 | + return $css; |
|
| 2891 | + } |
|
| 2892 | + } else { |
|
| 2893 | + if ( |
|
| 2894 | + @filemtime($f) > @filemtime($css) |
|
| 2895 | + && _VAR_MODE != 'recalcul' |
|
| 2896 | + ) { |
|
| 2897 | + return $f; |
|
| 2898 | + } |
|
| 2899 | + if (!lire_fichier($css, $contenu)) { |
|
| 2900 | + return $css; |
|
| 2901 | + } |
|
| 2902 | + } |
|
| 2903 | + |
|
| 2904 | + |
|
| 2905 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2906 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 2907 | + $parser = new csstidy(); |
|
| 2908 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 2909 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 2910 | + $parser->parse($contenu); |
|
| 2911 | + |
|
| 2912 | + $contenu = $parser->print->plain(); |
|
| 2913 | + |
|
| 2914 | + |
|
| 2915 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 2916 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", (string) $contenu, $regs); |
|
| 2917 | + $src = []; |
|
| 2918 | + $src_direction_css = []; |
|
| 2919 | + $src_faux_abs = []; |
|
| 2920 | + $d = dirname($css); |
|
| 2921 | + foreach ($regs[1] as $k => $import_css) { |
|
| 2922 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2923 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2924 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2925 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2926 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2927 | + elseif (str_starts_with($css_direction, $dir_var)) { |
|
| 2928 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2929 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2930 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2931 | + } |
|
| 2932 | + $src[] = $regs[0][$k]; |
|
| 2933 | + $src_direction_css[] = str_replace($import_css, $css_direction, (string) $regs[0][$k]); |
|
| 2934 | + } |
|
| 2935 | + $contenu = str_replace($src, $src_direction_css, (string) $contenu); |
|
| 2936 | + |
|
| 2937 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2938 | + |
|
| 2939 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 2940 | + if ($src_faux_abs !== []) { |
|
| 2941 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2942 | + } |
|
| 2943 | + |
|
| 2944 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 2945 | + return $css; |
|
| 2946 | + } |
|
| 2947 | + |
|
| 2948 | + return $f; |
|
| 2949 | 2949 | } |
| 2950 | 2950 | |
| 2951 | 2951 | |
@@ -2968,47 +2968,47 @@ discard block |
||
| 2968 | 2968 | * - Chemin ou URL du fichier CSS source sinon. |
| 2969 | 2969 | **/ |
| 2970 | 2970 | function url_absolue_css($css) { |
| 2971 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 2972 | - return $css; |
|
| 2973 | - } |
|
| 2971 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 2972 | + return $css; |
|
| 2973 | + } |
|
| 2974 | 2974 | |
| 2975 | - $url_absolue_css = url_absolue($css); |
|
| 2975 | + $url_absolue_css = url_absolue($css); |
|
| 2976 | 2976 | |
| 2977 | - $f = basename($css, '.css'); |
|
| 2978 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 2979 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 2980 | - . '.css'; |
|
| 2977 | + $f = basename($css, '.css'); |
|
| 2978 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 2979 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 2980 | + . '.css'; |
|
| 2981 | 2981 | |
| 2982 | - if (@filemtime($f) > @filemtime($css) && _VAR_MODE != 'recalcul') { |
|
| 2983 | - return $f; |
|
| 2984 | - } |
|
| 2982 | + if (@filemtime($f) > @filemtime($css) && _VAR_MODE != 'recalcul') { |
|
| 2983 | + return $f; |
|
| 2984 | + } |
|
| 2985 | 2985 | |
| 2986 | - $contenu = null; |
|
| 2987 | - if ($url_absolue_css == $css) { |
|
| 2988 | - if ( |
|
| 2989 | - strncmp((string) $GLOBALS['meta']['adresse_site'], $css, $l = strlen((string) $GLOBALS['meta']['adresse_site'])) != 0 |
|
| 2990 | - || !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 2991 | - ) { |
|
| 2992 | - include_spip('inc/distant'); |
|
| 2993 | - $contenu = recuperer_url($css); |
|
| 2994 | - $contenu = $contenu['page'] ?? ''; |
|
| 2995 | - if (!$contenu) { |
|
| 2996 | - return $css; |
|
| 2997 | - } |
|
| 2998 | - } |
|
| 2999 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3000 | - return $css; |
|
| 3001 | - } |
|
| 2986 | + $contenu = null; |
|
| 2987 | + if ($url_absolue_css == $css) { |
|
| 2988 | + if ( |
|
| 2989 | + strncmp((string) $GLOBALS['meta']['adresse_site'], $css, $l = strlen((string) $GLOBALS['meta']['adresse_site'])) != 0 |
|
| 2990 | + || !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 2991 | + ) { |
|
| 2992 | + include_spip('inc/distant'); |
|
| 2993 | + $contenu = recuperer_url($css); |
|
| 2994 | + $contenu = $contenu['page'] ?? ''; |
|
| 2995 | + if (!$contenu) { |
|
| 2996 | + return $css; |
|
| 2997 | + } |
|
| 2998 | + } |
|
| 2999 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3000 | + return $css; |
|
| 3001 | + } |
|
| 3002 | 3002 | |
| 3003 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3004 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3003 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3004 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3005 | 3005 | |
| 3006 | - // ecrire la css |
|
| 3007 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3008 | - return $css; |
|
| 3009 | - } |
|
| 3006 | + // ecrire la css |
|
| 3007 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3008 | + return $css; |
|
| 3009 | + } |
|
| 3010 | 3010 | |
| 3011 | - return $f; |
|
| 3011 | + return $f; |
|
| 3012 | 3012 | } |
| 3013 | 3013 | |
| 3014 | 3014 | |
@@ -3042,24 +3042,24 @@ discard block |
||
| 3042 | 3042 | * Valeur trouvée ou valeur par défaut. |
| 3043 | 3043 | **/ |
| 3044 | 3044 | function table_valeur(mixed $table, $cle, mixed $defaut = '', $conserver_null = false) { |
| 3045 | - foreach (explode('/', $cle) as $k) { |
|
| 3046 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3045 | + foreach (explode('/', $cle) as $k) { |
|
| 3046 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3047 | 3047 | |
| 3048 | - if (is_object($table)) { |
|
| 3049 | - $table = ($k !== '' && isset($table->$k)) ? $table->$k : $defaut; |
|
| 3050 | - } elseif (is_array($table)) { |
|
| 3051 | - if ($conserver_null) { |
|
| 3052 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3053 | - } else { |
|
| 3054 | - $table = ($table[$k] ?? $defaut); |
|
| 3055 | - } |
|
| 3056 | - } else { |
|
| 3057 | - $table = $defaut; |
|
| 3058 | - break; |
|
| 3059 | - } |
|
| 3060 | - } |
|
| 3048 | + if (is_object($table)) { |
|
| 3049 | + $table = ($k !== '' && isset($table->$k)) ? $table->$k : $defaut; |
|
| 3050 | + } elseif (is_array($table)) { |
|
| 3051 | + if ($conserver_null) { |
|
| 3052 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3053 | + } else { |
|
| 3054 | + $table = ($table[$k] ?? $defaut); |
|
| 3055 | + } |
|
| 3056 | + } else { |
|
| 3057 | + $table = $defaut; |
|
| 3058 | + break; |
|
| 3059 | + } |
|
| 3060 | + } |
|
| 3061 | 3061 | |
| 3062 | - return $table; |
|
| 3062 | + return $table; |
|
| 3063 | 3063 | } |
| 3064 | 3064 | |
| 3065 | 3065 | /** |
@@ -3092,22 +3092,22 @@ discard block |
||
| 3092 | 3092 | * - string : expression trouvée. |
| 3093 | 3093 | **/ |
| 3094 | 3094 | function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) { |
| 3095 | - if ((int) $modif && $capte == 0) { |
|
| 3096 | - $capte = $modif; |
|
| 3097 | - $modif = 'UuimsS'; |
|
| 3098 | - } |
|
| 3099 | - $expression = str_replace('\/', '/', $expression); |
|
| 3100 | - $expression = str_replace('/', '\/', $expression); |
|
| 3095 | + if ((int) $modif && $capte == 0) { |
|
| 3096 | + $capte = $modif; |
|
| 3097 | + $modif = 'UuimsS'; |
|
| 3098 | + } |
|
| 3099 | + $expression = str_replace('\/', '/', $expression); |
|
| 3100 | + $expression = str_replace('/', '\/', $expression); |
|
| 3101 | 3101 | |
| 3102 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3103 | - if (isset($r[$capte])) { |
|
| 3104 | - return $r[$capte]; |
|
| 3105 | - } else { |
|
| 3106 | - return true; |
|
| 3107 | - } |
|
| 3108 | - } |
|
| 3102 | + if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3103 | + if (isset($r[$capte])) { |
|
| 3104 | + return $r[$capte]; |
|
| 3105 | + } else { |
|
| 3106 | + return true; |
|
| 3107 | + } |
|
| 3108 | + } |
|
| 3109 | 3109 | |
| 3110 | - return false; |
|
| 3110 | + return false; |
|
| 3111 | 3111 | } |
| 3112 | 3112 | |
| 3113 | 3113 | |
@@ -3134,14 +3134,14 @@ discard block |
||
| 3134 | 3134 | * Texte |
| 3135 | 3135 | **/ |
| 3136 | 3136 | function replace(?string $texte, string $expression, string $replace = '', string $modif = 'UimsS'): string { |
| 3137 | - if (null === $texte) { |
|
| 3138 | - return ''; |
|
| 3139 | - } |
|
| 3137 | + if (null === $texte) { |
|
| 3138 | + return ''; |
|
| 3139 | + } |
|
| 3140 | 3140 | |
| 3141 | - $expression = str_replace('\/', '/', $expression); |
|
| 3142 | - $expression = str_replace('/', '\/', $expression); |
|
| 3141 | + $expression = str_replace('\/', '/', $expression); |
|
| 3142 | + $expression = str_replace('/', '\/', $expression); |
|
| 3143 | 3143 | |
| 3144 | - return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3144 | + return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3145 | 3145 | } |
| 3146 | 3146 | |
| 3147 | 3147 | |
@@ -3159,25 +3159,25 @@ discard block |
||
| 3159 | 3159 | **/ |
| 3160 | 3160 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3161 | 3161 | |
| 3162 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3163 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3162 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3163 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3164 | 3164 | |
| 3165 | - if ( |
|
| 3166 | - strstr($t, 'spip_document_') |
|
| 3167 | - && preg_match_all( |
|
| 3168 | - ',<[^>]+\sclass=["\']spip_document_(\d+)[\s"\'],imsS', |
|
| 3169 | - $t, |
|
| 3170 | - $matches, |
|
| 3171 | - PREG_PATTERN_ORDER |
|
| 3172 | - ) |
|
| 3173 | - ) { |
|
| 3174 | - if (!isset($doublons['documents'])) { |
|
| 3175 | - $doublons['documents'] = ''; |
|
| 3176 | - } |
|
| 3177 | - $doublons['documents'] .= ',' . implode(',', $matches[1]); |
|
| 3178 | - } |
|
| 3165 | + if ( |
|
| 3166 | + strstr($t, 'spip_document_') |
|
| 3167 | + && preg_match_all( |
|
| 3168 | + ',<[^>]+\sclass=["\']spip_document_(\d+)[\s"\'],imsS', |
|
| 3169 | + $t, |
|
| 3170 | + $matches, |
|
| 3171 | + PREG_PATTERN_ORDER |
|
| 3172 | + ) |
|
| 3173 | + ) { |
|
| 3174 | + if (!isset($doublons['documents'])) { |
|
| 3175 | + $doublons['documents'] = ''; |
|
| 3176 | + } |
|
| 3177 | + $doublons['documents'] .= ',' . implode(',', $matches[1]); |
|
| 3178 | + } |
|
| 3179 | 3179 | |
| 3180 | - return $letexte; |
|
| 3180 | + return $letexte; |
|
| 3181 | 3181 | } |
| 3182 | 3182 | |
| 3183 | 3183 | /** |
@@ -3191,7 +3191,7 @@ discard block |
||
| 3191 | 3191 | * @return string Chaîne vide |
| 3192 | 3192 | **/ |
| 3193 | 3193 | function vide(mixed $texte) { |
| 3194 | - return ''; |
|
| 3194 | + return ''; |
|
| 3195 | 3195 | } |
| 3196 | 3196 | |
| 3197 | 3197 | // |
@@ -3220,23 +3220,23 @@ discard block |
||
| 3220 | 3220 | * Code HTML résultant |
| 3221 | 3221 | **/ |
| 3222 | 3222 | function env_to_params($env, $ignore_params = []) { |
| 3223 | - $ignore_params = array_merge( |
|
| 3224 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3225 | - $ignore_params |
|
| 3226 | - ); |
|
| 3227 | - if (!is_array($env)) { |
|
| 3228 | - $env = unserialize($env); |
|
| 3229 | - } |
|
| 3230 | - $texte = ''; |
|
| 3231 | - if ($env) { |
|
| 3232 | - foreach ($env as $i => $j) { |
|
| 3233 | - if (is_string($j) && !in_array($i, $ignore_params)) { |
|
| 3234 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3235 | - } |
|
| 3236 | - } |
|
| 3237 | - } |
|
| 3238 | - |
|
| 3239 | - return $texte; |
|
| 3223 | + $ignore_params = array_merge( |
|
| 3224 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3225 | + $ignore_params |
|
| 3226 | + ); |
|
| 3227 | + if (!is_array($env)) { |
|
| 3228 | + $env = unserialize($env); |
|
| 3229 | + } |
|
| 3230 | + $texte = ''; |
|
| 3231 | + if ($env) { |
|
| 3232 | + foreach ($env as $i => $j) { |
|
| 3233 | + if (is_string($j) && !in_array($i, $ignore_params)) { |
|
| 3234 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3235 | + } |
|
| 3236 | + } |
|
| 3237 | + } |
|
| 3238 | + |
|
| 3239 | + return $texte; |
|
| 3240 | 3240 | } |
| 3241 | 3241 | |
| 3242 | 3242 | /** |
@@ -3259,23 +3259,23 @@ discard block |
||
| 3259 | 3259 | * Code HTML résultant |
| 3260 | 3260 | **/ |
| 3261 | 3261 | function env_to_attributs($env, $ignore_params = []) { |
| 3262 | - $ignore_params = array_merge( |
|
| 3263 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3264 | - $ignore_params |
|
| 3265 | - ); |
|
| 3266 | - if (!is_array($env)) { |
|
| 3267 | - $env = unserialize($env); |
|
| 3268 | - } |
|
| 3269 | - $texte = ''; |
|
| 3270 | - if ($env) { |
|
| 3271 | - foreach ($env as $i => $j) { |
|
| 3272 | - if (is_string($j) && !in_array($i, $ignore_params)) { |
|
| 3273 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3274 | - } |
|
| 3275 | - } |
|
| 3276 | - } |
|
| 3262 | + $ignore_params = array_merge( |
|
| 3263 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3264 | + $ignore_params |
|
| 3265 | + ); |
|
| 3266 | + if (!is_array($env)) { |
|
| 3267 | + $env = unserialize($env); |
|
| 3268 | + } |
|
| 3269 | + $texte = ''; |
|
| 3270 | + if ($env) { |
|
| 3271 | + foreach ($env as $i => $j) { |
|
| 3272 | + if (is_string($j) && !in_array($i, $ignore_params)) { |
|
| 3273 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3274 | + } |
|
| 3275 | + } |
|
| 3276 | + } |
|
| 3277 | 3277 | |
| 3278 | - return $texte; |
|
| 3278 | + return $texte; |
|
| 3279 | 3279 | } |
| 3280 | 3280 | |
| 3281 | 3281 | |
@@ -3293,7 +3293,7 @@ discard block |
||
| 3293 | 3293 | * @return string Chaînes concaténés |
| 3294 | 3294 | **/ |
| 3295 | 3295 | function concat(...$args): string { |
| 3296 | - return implode('', $args); |
|
| 3296 | + return implode('', $args); |
|
| 3297 | 3297 | } |
| 3298 | 3298 | |
| 3299 | 3299 | |
@@ -3313,23 +3313,23 @@ discard block |
||
| 3313 | 3313 | * Contenu du ou des fichiers, concaténé |
| 3314 | 3314 | **/ |
| 3315 | 3315 | function charge_scripts($files, $script = true) { |
| 3316 | - $flux = ''; |
|
| 3317 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3318 | - if (!is_string($file)) { |
|
| 3319 | - continue; |
|
| 3320 | - } |
|
| 3321 | - if ($script) { |
|
| 3322 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3323 | - } |
|
| 3324 | - if ($file) { |
|
| 3325 | - $path = find_in_path($file); |
|
| 3326 | - if ($path) { |
|
| 3327 | - $flux .= spip_file_get_contents($path); |
|
| 3328 | - } |
|
| 3329 | - } |
|
| 3330 | - } |
|
| 3331 | - |
|
| 3332 | - return $flux; |
|
| 3316 | + $flux = ''; |
|
| 3317 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3318 | + if (!is_string($file)) { |
|
| 3319 | + continue; |
|
| 3320 | + } |
|
| 3321 | + if ($script) { |
|
| 3322 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3323 | + } |
|
| 3324 | + if ($file) { |
|
| 3325 | + $path = find_in_path($file); |
|
| 3326 | + if ($path) { |
|
| 3327 | + $flux .= spip_file_get_contents($path); |
|
| 3328 | + } |
|
| 3329 | + } |
|
| 3330 | + } |
|
| 3331 | + |
|
| 3332 | + return $flux; |
|
| 3333 | 3333 | } |
| 3334 | 3334 | |
| 3335 | 3335 | /** |
@@ -3340,24 +3340,24 @@ discard block |
||
| 3340 | 3340 | * @return string |
| 3341 | 3341 | */ |
| 3342 | 3342 | function http_img_variante_svg_si_possible($img_file) { |
| 3343 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3344 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3345 | - if ( |
|
| 3346 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3347 | - && ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 3348 | - && file_exists($variante_svg_generique) |
|
| 3349 | - ) { |
|
| 3350 | - if ( |
|
| 3351 | - ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg') |
|
| 3352 | - && file_exists($variante_svg_size) |
|
| 3353 | - ) { |
|
| 3354 | - $img_file = $variante_svg_size; |
|
| 3355 | - } else { |
|
| 3356 | - $img_file = $variante_svg_generique; |
|
| 3357 | - } |
|
| 3358 | - } |
|
| 3359 | - |
|
| 3360 | - return $img_file; |
|
| 3343 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3344 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3345 | + if ( |
|
| 3346 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3347 | + && ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 3348 | + && file_exists($variante_svg_generique) |
|
| 3349 | + ) { |
|
| 3350 | + if ( |
|
| 3351 | + ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg') |
|
| 3352 | + && file_exists($variante_svg_size) |
|
| 3353 | + ) { |
|
| 3354 | + $img_file = $variante_svg_size; |
|
| 3355 | + } else { |
|
| 3356 | + $img_file = $variante_svg_generique; |
|
| 3357 | + } |
|
| 3358 | + } |
|
| 3359 | + |
|
| 3360 | + return $img_file; |
|
| 3361 | 3361 | } |
| 3362 | 3362 | |
| 3363 | 3363 | /** |
@@ -3378,51 +3378,51 @@ discard block |
||
| 3378 | 3378 | */ |
| 3379 | 3379 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3380 | 3380 | |
| 3381 | - $img_file = $img; |
|
| 3382 | - if ($p = strpos($img_file, '?')) { |
|
| 3383 | - $img_file = substr($img_file, 0, $p); |
|
| 3384 | - } |
|
| 3385 | - if (!isset($options['chemin_image']) || $options['chemin_image'] == true) { |
|
| 3386 | - $img_file = chemin_image($img); |
|
| 3387 | - } |
|
| 3388 | - else { |
|
| 3389 | - if (!isset($options['variante_svg_si_possible']) || $options['variante_svg_si_possible'] == true) { |
|
| 3390 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3391 | - } |
|
| 3392 | - } |
|
| 3393 | - if (stripos($atts, 'width') === false) { |
|
| 3394 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3395 | - if ( |
|
| 3396 | - (!isset($options['utiliser_suffixe_size']) || $options['utiliser_suffixe_size'] == true || str_contains($img_file, '-xx.svg')) |
|
| 3397 | - && (preg_match(',-(\d+)[.](png|gif|svg)$,', $img, $regs) || preg_match(',\?(\d+)px$,', $img, $regs)) |
|
| 3398 | - ) { |
|
| 3399 | - $largeur = $hauteur = (int) $regs[1]; |
|
| 3400 | - } else { |
|
| 3401 | - $taille = taille_image($img_file); |
|
| 3402 | - [$hauteur, $largeur] = $taille; |
|
| 3403 | - if (!$hauteur || !$largeur) { |
|
| 3404 | - return ''; |
|
| 3405 | - } |
|
| 3406 | - } |
|
| 3407 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3408 | - } |
|
| 3409 | - |
|
| 3410 | - if (file_exists($img_file)) { |
|
| 3411 | - $img_file = timestamp($img_file); |
|
| 3412 | - } |
|
| 3413 | - if ($alt === false) { |
|
| 3414 | - $alt = ''; |
|
| 3415 | - } |
|
| 3416 | - elseif ($alt || $alt === '') { |
|
| 3417 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3418 | - } |
|
| 3419 | - else { |
|
| 3420 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3421 | - } |
|
| 3422 | - return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3423 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3424 | - . ' ' . ltrim($atts) |
|
| 3425 | - . ' />'; |
|
| 3381 | + $img_file = $img; |
|
| 3382 | + if ($p = strpos($img_file, '?')) { |
|
| 3383 | + $img_file = substr($img_file, 0, $p); |
|
| 3384 | + } |
|
| 3385 | + if (!isset($options['chemin_image']) || $options['chemin_image'] == true) { |
|
| 3386 | + $img_file = chemin_image($img); |
|
| 3387 | + } |
|
| 3388 | + else { |
|
| 3389 | + if (!isset($options['variante_svg_si_possible']) || $options['variante_svg_si_possible'] == true) { |
|
| 3390 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3391 | + } |
|
| 3392 | + } |
|
| 3393 | + if (stripos($atts, 'width') === false) { |
|
| 3394 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3395 | + if ( |
|
| 3396 | + (!isset($options['utiliser_suffixe_size']) || $options['utiliser_suffixe_size'] == true || str_contains($img_file, '-xx.svg')) |
|
| 3397 | + && (preg_match(',-(\d+)[.](png|gif|svg)$,', $img, $regs) || preg_match(',\?(\d+)px$,', $img, $regs)) |
|
| 3398 | + ) { |
|
| 3399 | + $largeur = $hauteur = (int) $regs[1]; |
|
| 3400 | + } else { |
|
| 3401 | + $taille = taille_image($img_file); |
|
| 3402 | + [$hauteur, $largeur] = $taille; |
|
| 3403 | + if (!$hauteur || !$largeur) { |
|
| 3404 | + return ''; |
|
| 3405 | + } |
|
| 3406 | + } |
|
| 3407 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3408 | + } |
|
| 3409 | + |
|
| 3410 | + if (file_exists($img_file)) { |
|
| 3411 | + $img_file = timestamp($img_file); |
|
| 3412 | + } |
|
| 3413 | + if ($alt === false) { |
|
| 3414 | + $alt = ''; |
|
| 3415 | + } |
|
| 3416 | + elseif ($alt || $alt === '') { |
|
| 3417 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3418 | + } |
|
| 3419 | + else { |
|
| 3420 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3421 | + } |
|
| 3422 | + return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3423 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3424 | + . ' ' . ltrim($atts) |
|
| 3425 | + . ' />'; |
|
| 3426 | 3426 | } |
| 3427 | 3427 | |
| 3428 | 3428 | /** |
@@ -3434,70 +3434,70 @@ discard block |
||
| 3434 | 3434 | * @return string |
| 3435 | 3435 | */ |
| 3436 | 3436 | function http_style_background($img, $att = '', $size = null) { |
| 3437 | - if ($size && is_numeric($size)) { |
|
| 3438 | - $size = trim($size) . 'px'; |
|
| 3439 | - } |
|
| 3440 | - return " style='background" . |
|
| 3441 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3442 | - . ($size ? "background-size:{$size};" : '') |
|
| 3443 | - . "'"; |
|
| 3437 | + if ($size && is_numeric($size)) { |
|
| 3438 | + $size = trim($size) . 'px'; |
|
| 3439 | + } |
|
| 3440 | + return " style='background" . |
|
| 3441 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3442 | + . ($size ? "background-size:{$size};" : '') |
|
| 3443 | + . "'"; |
|
| 3444 | 3444 | } |
| 3445 | 3445 | |
| 3446 | 3446 | |
| 3447 | 3447 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3448 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3449 | - while (is_null(end($args)) && count($args)) { |
|
| 3450 | - array_pop($args); |
|
| 3451 | - } |
|
| 3452 | - if ($args === []) { |
|
| 3453 | - return [null, null, null]; |
|
| 3454 | - } |
|
| 3455 | - if (count($args) < 3) { |
|
| 3456 | - $maybe_size = array_pop($args); |
|
| 3457 | - // @2x |
|
| 3458 | - // @1.5x |
|
| 3459 | - // 512 |
|
| 3460 | - // 512x* |
|
| 3461 | - // 512x300 |
|
| 3462 | - if ( |
|
| 3463 | - !strlen((string) $maybe_size) |
|
| 3464 | - || !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim((string) $maybe_size)) |
|
| 3465 | - ) { |
|
| 3466 | - $args[] = $maybe_size; |
|
| 3467 | - $maybe_size = null; |
|
| 3468 | - } |
|
| 3469 | - while (count($args) < 2) { |
|
| 3470 | - $args[] = null; // default alt or class |
|
| 3471 | - } |
|
| 3472 | - $args[] = $maybe_size; |
|
| 3473 | - } |
|
| 3474 | - return $args; |
|
| 3448 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3449 | + while (is_null(end($args)) && count($args)) { |
|
| 3450 | + array_pop($args); |
|
| 3451 | + } |
|
| 3452 | + if ($args === []) { |
|
| 3453 | + return [null, null, null]; |
|
| 3454 | + } |
|
| 3455 | + if (count($args) < 3) { |
|
| 3456 | + $maybe_size = array_pop($args); |
|
| 3457 | + // @2x |
|
| 3458 | + // @1.5x |
|
| 3459 | + // 512 |
|
| 3460 | + // 512x* |
|
| 3461 | + // 512x300 |
|
| 3462 | + if ( |
|
| 3463 | + !strlen((string) $maybe_size) |
|
| 3464 | + || !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim((string) $maybe_size)) |
|
| 3465 | + ) { |
|
| 3466 | + $args[] = $maybe_size; |
|
| 3467 | + $maybe_size = null; |
|
| 3468 | + } |
|
| 3469 | + while (count($args) < 2) { |
|
| 3470 | + $args[] = null; // default alt or class |
|
| 3471 | + } |
|
| 3472 | + $args[] = $maybe_size; |
|
| 3473 | + } |
|
| 3474 | + return $args; |
|
| 3475 | 3475 | } |
| 3476 | 3476 | |
| 3477 | 3477 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3478 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3479 | - if (str_starts_with((string) $size, '@') && str_ends_with((string) $size, 'x')) { |
|
| 3480 | - $coef = (float) substr((string) $size, 1, -1); |
|
| 3481 | - [$h, $w] = taille_image($img); |
|
| 3482 | - $height = (int) round($h / $coef); |
|
| 3483 | - $width = (int) round($w / $coef); |
|
| 3484 | - } |
|
| 3485 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3486 | - else { |
|
| 3487 | - $size = explode('x', (string) $size, 2); |
|
| 3488 | - $size = array_map('trim', $size); |
|
| 3489 | - $height = $width = (int) array_shift($size); |
|
| 3490 | - |
|
| 3491 | - if (count($size) && reset($size)) { |
|
| 3492 | - $height = array_shift($size); |
|
| 3493 | - if ($height === '*') { |
|
| 3494 | - [$h, $w] = taille_image($img); |
|
| 3495 | - $height = (int) round($h * $width / $w); |
|
| 3496 | - } |
|
| 3497 | - } |
|
| 3498 | - } |
|
| 3499 | - |
|
| 3500 | - return [$width, $height]; |
|
| 3478 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3479 | + if (str_starts_with((string) $size, '@') && str_ends_with((string) $size, 'x')) { |
|
| 3480 | + $coef = (float) substr((string) $size, 1, -1); |
|
| 3481 | + [$h, $w] = taille_image($img); |
|
| 3482 | + $height = (int) round($h / $coef); |
|
| 3483 | + $width = (int) round($w / $coef); |
|
| 3484 | + } |
|
| 3485 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3486 | + else { |
|
| 3487 | + $size = explode('x', (string) $size, 2); |
|
| 3488 | + $size = array_map('trim', $size); |
|
| 3489 | + $height = $width = (int) array_shift($size); |
|
| 3490 | + |
|
| 3491 | + if (count($size) && reset($size)) { |
|
| 3492 | + $height = array_shift($size); |
|
| 3493 | + if ($height === '*') { |
|
| 3494 | + [$h, $w] = taille_image($img); |
|
| 3495 | + $height = (int) round($h * $width / $w); |
|
| 3496 | + } |
|
| 3497 | + } |
|
| 3498 | + } |
|
| 3499 | + |
|
| 3500 | + return [$width, $height]; |
|
| 3501 | 3501 | } |
| 3502 | 3502 | |
| 3503 | 3503 | /** |
@@ -3533,38 +3533,38 @@ discard block |
||
| 3533 | 3533 | */ |
| 3534 | 3534 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3535 | 3535 | |
| 3536 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3536 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3537 | 3537 | |
| 3538 | - $img = trim((string) $img); |
|
| 3539 | - if (str_starts_with($img, '<img')) { |
|
| 3540 | - if (!is_null($alt)) { |
|
| 3541 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3542 | - } |
|
| 3543 | - if (!is_null($class)) { |
|
| 3544 | - $img = strlen((string) $class) ? inserer_attribut($img, 'class', $class) : vider_attribut($img, 'class'); |
|
| 3545 | - } |
|
| 3546 | - } |
|
| 3547 | - else { |
|
| 3548 | - $img = http_img_pack( |
|
| 3549 | - $img, |
|
| 3550 | - $alt, |
|
| 3551 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3552 | - '', |
|
| 3553 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3554 | - ); |
|
| 3555 | - if (is_null($alt)) { |
|
| 3556 | - $img = vider_attribut($img, 'alt'); |
|
| 3557 | - } |
|
| 3558 | - } |
|
| 3538 | + $img = trim((string) $img); |
|
| 3539 | + if (str_starts_with($img, '<img')) { |
|
| 3540 | + if (!is_null($alt)) { |
|
| 3541 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3542 | + } |
|
| 3543 | + if (!is_null($class)) { |
|
| 3544 | + $img = strlen((string) $class) ? inserer_attribut($img, 'class', $class) : vider_attribut($img, 'class'); |
|
| 3545 | + } |
|
| 3546 | + } |
|
| 3547 | + else { |
|
| 3548 | + $img = http_img_pack( |
|
| 3549 | + $img, |
|
| 3550 | + $alt, |
|
| 3551 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3552 | + '', |
|
| 3553 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3554 | + ); |
|
| 3555 | + if (is_null($alt)) { |
|
| 3556 | + $img = vider_attribut($img, 'alt'); |
|
| 3557 | + } |
|
| 3558 | + } |
|
| 3559 | 3559 | |
| 3560 | - if ($img && !is_null($size) && strlen($size = trim((string) $size))) { |
|
| 3561 | - [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3560 | + if ($img && !is_null($size) && strlen($size = trim((string) $size))) { |
|
| 3561 | + [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3562 | 3562 | |
| 3563 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3564 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3565 | - } |
|
| 3563 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3564 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3565 | + } |
|
| 3566 | 3566 | |
| 3567 | - return $img; |
|
| 3567 | + return $img; |
|
| 3568 | 3568 | } |
| 3569 | 3569 | |
| 3570 | 3570 | |
@@ -3598,77 +3598,77 @@ discard block |
||
| 3598 | 3598 | */ |
| 3599 | 3599 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3600 | 3600 | |
| 3601 | - $svg = null; |
|
| 3602 | - $img = trim($img); |
|
| 3603 | - $img_file = $img; |
|
| 3604 | - if (!str_contains($img, '<svg')) { |
|
| 3605 | - if ($p = strpos($img_file, '?')) { |
|
| 3606 | - $img_file = substr($img_file, 0, $p); |
|
| 3607 | - } |
|
| 3608 | - |
|
| 3609 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3610 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3611 | - if (tester_url_absolue($img_file)) { |
|
| 3612 | - include_spip('inc/distant'); |
|
| 3613 | - $fichier = copie_locale($img_file); |
|
| 3614 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3615 | - } |
|
| 3616 | - |
|
| 3617 | - if ( |
|
| 3618 | - !$img_file |
|
| 3619 | - || !file_exists($img_file) |
|
| 3620 | - || !$svg = file_get_contents($img_file) |
|
| 3621 | - ) { |
|
| 3622 | - return ''; |
|
| 3623 | - } |
|
| 3624 | - } |
|
| 3625 | - |
|
| 3626 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3627 | - return ''; |
|
| 3628 | - } |
|
| 3629 | - |
|
| 3630 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3631 | - |
|
| 3632 | - $balise_svg = $match[0]; |
|
| 3633 | - $balise_svg_source = $balise_svg; |
|
| 3634 | - |
|
| 3635 | - // entete XML à supprimer |
|
| 3636 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?>,', '', $svg); |
|
| 3637 | - |
|
| 3638 | - // IE est toujours mon ami |
|
| 3639 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3640 | - |
|
| 3641 | - // regler la classe |
|
| 3642 | - if (!is_null($class)) { |
|
| 3643 | - $balise_svg = strlen((string) $class) |
|
| 3644 | - ? inserer_attribut($balise_svg, 'class', $class) |
|
| 3645 | - : vider_attribut($balise_svg, 'class'); |
|
| 3646 | - } |
|
| 3647 | - |
|
| 3648 | - // regler le alt |
|
| 3649 | - if ($alt) { |
|
| 3650 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3651 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3652 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3653 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3654 | - $balise_svg .= $title; |
|
| 3655 | - } |
|
| 3656 | - else { |
|
| 3657 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3658 | - } |
|
| 3659 | - |
|
| 3660 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3661 | - |
|
| 3662 | - if (!is_null($size) && strlen($size = trim((string) $size))) { |
|
| 3663 | - [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3664 | - |
|
| 3665 | - if (!function_exists('svg_redimensionner')) { |
|
| 3666 | - include_spip('inc/svg'); |
|
| 3667 | - } |
|
| 3668 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3669 | - } |
|
| 3670 | - |
|
| 3671 | - return $svg; |
|
| 3601 | + $svg = null; |
|
| 3602 | + $img = trim($img); |
|
| 3603 | + $img_file = $img; |
|
| 3604 | + if (!str_contains($img, '<svg')) { |
|
| 3605 | + if ($p = strpos($img_file, '?')) { |
|
| 3606 | + $img_file = substr($img_file, 0, $p); |
|
| 3607 | + } |
|
| 3608 | + |
|
| 3609 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3610 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3611 | + if (tester_url_absolue($img_file)) { |
|
| 3612 | + include_spip('inc/distant'); |
|
| 3613 | + $fichier = copie_locale($img_file); |
|
| 3614 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3615 | + } |
|
| 3616 | + |
|
| 3617 | + if ( |
|
| 3618 | + !$img_file |
|
| 3619 | + || !file_exists($img_file) |
|
| 3620 | + || !$svg = file_get_contents($img_file) |
|
| 3621 | + ) { |
|
| 3622 | + return ''; |
|
| 3623 | + } |
|
| 3624 | + } |
|
| 3625 | + |
|
| 3626 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3627 | + return ''; |
|
| 3628 | + } |
|
| 3629 | + |
|
| 3630 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3631 | + |
|
| 3632 | + $balise_svg = $match[0]; |
|
| 3633 | + $balise_svg_source = $balise_svg; |
|
| 3634 | + |
|
| 3635 | + // entete XML à supprimer |
|
| 3636 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?>,', '', $svg); |
|
| 3637 | + |
|
| 3638 | + // IE est toujours mon ami |
|
| 3639 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3640 | + |
|
| 3641 | + // regler la classe |
|
| 3642 | + if (!is_null($class)) { |
|
| 3643 | + $balise_svg = strlen((string) $class) |
|
| 3644 | + ? inserer_attribut($balise_svg, 'class', $class) |
|
| 3645 | + : vider_attribut($balise_svg, 'class'); |
|
| 3646 | + } |
|
| 3647 | + |
|
| 3648 | + // regler le alt |
|
| 3649 | + if ($alt) { |
|
| 3650 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3651 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3652 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3653 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3654 | + $balise_svg .= $title; |
|
| 3655 | + } |
|
| 3656 | + else { |
|
| 3657 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3658 | + } |
|
| 3659 | + |
|
| 3660 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3661 | + |
|
| 3662 | + if (!is_null($size) && strlen($size = trim((string) $size))) { |
|
| 3663 | + [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3664 | + |
|
| 3665 | + if (!function_exists('svg_redimensionner')) { |
|
| 3666 | + include_spip('inc/svg'); |
|
| 3667 | + } |
|
| 3668 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3669 | + } |
|
| 3670 | + |
|
| 3671 | + return $svg; |
|
| 3672 | 3672 | } |
| 3673 | 3673 | |
| 3674 | 3674 | /** |
@@ -3692,37 +3692,37 @@ discard block |
||
| 3692 | 3692 | * - tout : retourne toutes les informations du plugin actif |
| 3693 | 3693 | **/ |
| 3694 | 3694 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3695 | - include_spip('inc/plugin'); |
|
| 3696 | - $plugin = strtoupper($plugin); |
|
| 3697 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3698 | - |
|
| 3699 | - if (!$plugin) { |
|
| 3700 | - return serialize(array_keys($plugins_actifs)); |
|
| 3701 | - } elseif (empty($plugins_actifs[$plugin]) && !$reload) { |
|
| 3702 | - return ''; |
|
| 3703 | - } elseif ($type_info == 'est_actif' && !$reload) { |
|
| 3704 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3705 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) && !$reload) { |
|
| 3706 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3707 | - } else { |
|
| 3708 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3709 | - // On prend en compte les extensions |
|
| 3710 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3711 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3712 | - } else { |
|
| 3713 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3714 | - } |
|
| 3715 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3716 | - return ''; |
|
| 3717 | - } |
|
| 3718 | - if ($type_info == 'tout') { |
|
| 3719 | - return $infos; |
|
| 3720 | - } elseif ($type_info == 'est_actif') { |
|
| 3721 | - return $infos ? 1 : 0; |
|
| 3722 | - } else { |
|
| 3723 | - return (string) $infos[$type_info]; |
|
| 3724 | - } |
|
| 3725 | - } |
|
| 3695 | + include_spip('inc/plugin'); |
|
| 3696 | + $plugin = strtoupper($plugin); |
|
| 3697 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3698 | + |
|
| 3699 | + if (!$plugin) { |
|
| 3700 | + return serialize(array_keys($plugins_actifs)); |
|
| 3701 | + } elseif (empty($plugins_actifs[$plugin]) && !$reload) { |
|
| 3702 | + return ''; |
|
| 3703 | + } elseif ($type_info == 'est_actif' && !$reload) { |
|
| 3704 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3705 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) && !$reload) { |
|
| 3706 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3707 | + } else { |
|
| 3708 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3709 | + // On prend en compte les extensions |
|
| 3710 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3711 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3712 | + } else { |
|
| 3713 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3714 | + } |
|
| 3715 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3716 | + return ''; |
|
| 3717 | + } |
|
| 3718 | + if ($type_info == 'tout') { |
|
| 3719 | + return $infos; |
|
| 3720 | + } elseif ($type_info == 'est_actif') { |
|
| 3721 | + return $infos ? 1 : 0; |
|
| 3722 | + } else { |
|
| 3723 | + return (string) $infos[$type_info]; |
|
| 3724 | + } |
|
| 3725 | + } |
|
| 3726 | 3726 | } |
| 3727 | 3727 | |
| 3728 | 3728 | |
@@ -3749,9 +3749,9 @@ discard block |
||
| 3749 | 3749 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3750 | 3750 | */ |
| 3751 | 3751 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3752 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3752 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3753 | 3753 | |
| 3754 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3754 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3755 | 3755 | } |
| 3756 | 3756 | |
| 3757 | 3757 | |
@@ -3781,19 +3781,19 @@ discard block |
||
| 3781 | 3781 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3782 | 3782 | */ |
| 3783 | 3783 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3784 | - static $puce_statut = null; |
|
| 3785 | - if (!$puce_statut) { |
|
| 3786 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3787 | - } |
|
| 3784 | + static $puce_statut = null; |
|
| 3785 | + if (!$puce_statut) { |
|
| 3786 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3787 | + } |
|
| 3788 | 3788 | |
| 3789 | - return $puce_statut( |
|
| 3790 | - $id_objet, |
|
| 3791 | - $statut, |
|
| 3792 | - $id_parent, |
|
| 3793 | - $objet, |
|
| 3794 | - false, |
|
| 3795 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3796 | - ); |
|
| 3789 | + return $puce_statut( |
|
| 3790 | + $id_objet, |
|
| 3791 | + $statut, |
|
| 3792 | + $id_parent, |
|
| 3793 | + $objet, |
|
| 3794 | + false, |
|
| 3795 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3796 | + ); |
|
| 3797 | 3797 | } |
| 3798 | 3798 | |
| 3799 | 3799 | |
@@ -3820,95 +3820,95 @@ discard block |
||
| 3820 | 3820 | * hash du contexte |
| 3821 | 3821 | */ |
| 3822 | 3822 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 3823 | - $env = null; |
|
| 3824 | - if (is_string($c) && @unserialize($c) !== false) { |
|
| 3825 | - $c = unserialize($c); |
|
| 3826 | - } |
|
| 3827 | - |
|
| 3828 | - // supprimer les parametres debut_x |
|
| 3829 | - // pour que la pagination ajax ne soit pas plantee |
|
| 3830 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3831 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3832 | - if (is_array($c)) { |
|
| 3833 | - foreach (array_keys($c) as $k) { |
|
| 3834 | - if (str_starts_with($k, 'debut_')) { |
|
| 3835 | - unset($c[$k]); |
|
| 3836 | - } |
|
| 3837 | - } |
|
| 3838 | - } |
|
| 3839 | - |
|
| 3840 | - if (!function_exists('calculer_cle_action')) { |
|
| 3841 | - include_spip('inc/securiser_action'); |
|
| 3842 | - } |
|
| 3843 | - |
|
| 3844 | - $c = serialize($c); |
|
| 3845 | - $cle = calculer_cle_action($form . $c); |
|
| 3846 | - $c = "$cle:$c"; |
|
| 3847 | - |
|
| 3848 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3849 | - // par defaut, sauf si cette configuration a été forcée |
|
| 3850 | - // OU que la longueur de l’argument géneré est plus long |
|
| 3851 | - // que ce qui est toléré. |
|
| 3852 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX); |
|
| 3853 | - if (!$cache_contextes_ajax) { |
|
| 3854 | - $env = $c; |
|
| 3855 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3856 | - $env = gzdeflate($env); |
|
| 3857 | - } |
|
| 3858 | - $env = _xor($env); |
|
| 3859 | - $env = base64_encode($env); |
|
| 3860 | - $len = strlen($env); |
|
| 3861 | - // Si l’url est trop longue pour le navigateur |
|
| 3862 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3863 | - if ($len > $max_len) { |
|
| 3864 | - $cache_contextes_ajax = true; |
|
| 3865 | - spip_log( |
|
| 3866 | - 'Contextes AJAX forces en fichiers !' |
|
| 3867 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3868 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3869 | - _LOG_AVERTISSEMENT |
|
| 3870 | - ); |
|
| 3871 | - } |
|
| 3872 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3873 | - elseif ( |
|
| 3874 | - ($max_len = @ini_get('suhosin.get.max_value_length')) |
|
| 3875 | - && $max_len < $len |
|
| 3876 | - ) { |
|
| 3877 | - $cache_contextes_ajax = true; |
|
| 3878 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 3879 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3880 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3881 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3882 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3883 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3884 | - } |
|
| 3885 | - } |
|
| 3886 | - |
|
| 3887 | - if ($cache_contextes_ajax) { |
|
| 3888 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3889 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3890 | - $md5 = md5($c); |
|
| 3891 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 3892 | - $env = $md5; |
|
| 3893 | - } |
|
| 3894 | - |
|
| 3895 | - if ($emboite === null) { |
|
| 3896 | - return $env; |
|
| 3897 | - } |
|
| 3898 | - if (!trim($emboite)) { |
|
| 3899 | - return ''; |
|
| 3900 | - } |
|
| 3901 | - // toujours encoder l'url source dans le bloc ajax |
|
| 3902 | - $r = self(); |
|
| 3903 | - $r = ' data-origin="' . $r . '"'; |
|
| 3904 | - $class = 'ajaxbloc'; |
|
| 3905 | - if ($ajaxid && is_string($ajaxid)) { |
|
| 3906 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 3907 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 3908 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3909 | - } |
|
| 3910 | - |
|
| 3911 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3823 | + $env = null; |
|
| 3824 | + if (is_string($c) && @unserialize($c) !== false) { |
|
| 3825 | + $c = unserialize($c); |
|
| 3826 | + } |
|
| 3827 | + |
|
| 3828 | + // supprimer les parametres debut_x |
|
| 3829 | + // pour que la pagination ajax ne soit pas plantee |
|
| 3830 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3831 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3832 | + if (is_array($c)) { |
|
| 3833 | + foreach (array_keys($c) as $k) { |
|
| 3834 | + if (str_starts_with($k, 'debut_')) { |
|
| 3835 | + unset($c[$k]); |
|
| 3836 | + } |
|
| 3837 | + } |
|
| 3838 | + } |
|
| 3839 | + |
|
| 3840 | + if (!function_exists('calculer_cle_action')) { |
|
| 3841 | + include_spip('inc/securiser_action'); |
|
| 3842 | + } |
|
| 3843 | + |
|
| 3844 | + $c = serialize($c); |
|
| 3845 | + $cle = calculer_cle_action($form . $c); |
|
| 3846 | + $c = "$cle:$c"; |
|
| 3847 | + |
|
| 3848 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3849 | + // par defaut, sauf si cette configuration a été forcée |
|
| 3850 | + // OU que la longueur de l’argument géneré est plus long |
|
| 3851 | + // que ce qui est toléré. |
|
| 3852 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX); |
|
| 3853 | + if (!$cache_contextes_ajax) { |
|
| 3854 | + $env = $c; |
|
| 3855 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3856 | + $env = gzdeflate($env); |
|
| 3857 | + } |
|
| 3858 | + $env = _xor($env); |
|
| 3859 | + $env = base64_encode($env); |
|
| 3860 | + $len = strlen($env); |
|
| 3861 | + // Si l’url est trop longue pour le navigateur |
|
| 3862 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3863 | + if ($len > $max_len) { |
|
| 3864 | + $cache_contextes_ajax = true; |
|
| 3865 | + spip_log( |
|
| 3866 | + 'Contextes AJAX forces en fichiers !' |
|
| 3867 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3868 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3869 | + _LOG_AVERTISSEMENT |
|
| 3870 | + ); |
|
| 3871 | + } |
|
| 3872 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3873 | + elseif ( |
|
| 3874 | + ($max_len = @ini_get('suhosin.get.max_value_length')) |
|
| 3875 | + && $max_len < $len |
|
| 3876 | + ) { |
|
| 3877 | + $cache_contextes_ajax = true; |
|
| 3878 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 3879 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3880 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3881 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3882 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3883 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3884 | + } |
|
| 3885 | + } |
|
| 3886 | + |
|
| 3887 | + if ($cache_contextes_ajax) { |
|
| 3888 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3889 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3890 | + $md5 = md5($c); |
|
| 3891 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 3892 | + $env = $md5; |
|
| 3893 | + } |
|
| 3894 | + |
|
| 3895 | + if ($emboite === null) { |
|
| 3896 | + return $env; |
|
| 3897 | + } |
|
| 3898 | + if (!trim($emboite)) { |
|
| 3899 | + return ''; |
|
| 3900 | + } |
|
| 3901 | + // toujours encoder l'url source dans le bloc ajax |
|
| 3902 | + $r = self(); |
|
| 3903 | + $r = ' data-origin="' . $r . '"'; |
|
| 3904 | + $class = 'ajaxbloc'; |
|
| 3905 | + if ($ajaxid && is_string($ajaxid)) { |
|
| 3906 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 3907 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 3908 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3909 | + } |
|
| 3910 | + |
|
| 3911 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3912 | 3912 | } |
| 3913 | 3913 | |
| 3914 | 3914 | /** |
@@ -3928,37 +3928,37 @@ discard block |
||
| 3928 | 3928 | * - false : erreur de décodage |
| 3929 | 3929 | */ |
| 3930 | 3930 | function decoder_contexte_ajax($c, $form = '') { |
| 3931 | - $contexte = null; |
|
| 3932 | - if (!function_exists('calculer_cle_action')) { |
|
| 3933 | - include_spip('inc/securiser_action'); |
|
| 3934 | - } |
|
| 3935 | - if ( |
|
| 3936 | - (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX || strlen($c) == 32) |
|
| 3937 | - && ($dir = sous_repertoire(_DIR_CACHE, 'contextes')) |
|
| 3938 | - && lire_fichier("$dir/c$c", $contexte) |
|
| 3939 | - ) { |
|
| 3940 | - $c = $contexte; |
|
| 3941 | - } else { |
|
| 3942 | - $c = @base64_decode($c); |
|
| 3943 | - $c = _xor($c); |
|
| 3944 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3945 | - $c = @gzinflate($c); |
|
| 3946 | - } |
|
| 3947 | - } |
|
| 3948 | - |
|
| 3949 | - // extraire la signature en debut de contexte |
|
| 3950 | - // et la verifier avant de deserializer |
|
| 3951 | - // format : signature:donneesserializees |
|
| 3952 | - if ($p = strpos((string) $c, ':')) { |
|
| 3953 | - $cle = substr((string) $c, 0, $p); |
|
| 3954 | - $c = substr((string) $c, $p + 1); |
|
| 3955 | - |
|
| 3956 | - if ($cle === calculer_cle_action($form . $c)) { |
|
| 3957 | - return @unserialize($c); |
|
| 3958 | - } |
|
| 3959 | - } |
|
| 3960 | - |
|
| 3961 | - return false; |
|
| 3931 | + $contexte = null; |
|
| 3932 | + if (!function_exists('calculer_cle_action')) { |
|
| 3933 | + include_spip('inc/securiser_action'); |
|
| 3934 | + } |
|
| 3935 | + if ( |
|
| 3936 | + (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX || strlen($c) == 32) |
|
| 3937 | + && ($dir = sous_repertoire(_DIR_CACHE, 'contextes')) |
|
| 3938 | + && lire_fichier("$dir/c$c", $contexte) |
|
| 3939 | + ) { |
|
| 3940 | + $c = $contexte; |
|
| 3941 | + } else { |
|
| 3942 | + $c = @base64_decode($c); |
|
| 3943 | + $c = _xor($c); |
|
| 3944 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3945 | + $c = @gzinflate($c); |
|
| 3946 | + } |
|
| 3947 | + } |
|
| 3948 | + |
|
| 3949 | + // extraire la signature en debut de contexte |
|
| 3950 | + // et la verifier avant de deserializer |
|
| 3951 | + // format : signature:donneesserializees |
|
| 3952 | + if ($p = strpos((string) $c, ':')) { |
|
| 3953 | + $cle = substr((string) $c, 0, $p); |
|
| 3954 | + $c = substr((string) $c, $p + 1); |
|
| 3955 | + |
|
| 3956 | + if ($cle === calculer_cle_action($form . $c)) { |
|
| 3957 | + return @unserialize($c); |
|
| 3958 | + } |
|
| 3959 | + } |
|
| 3960 | + |
|
| 3961 | + return false; |
|
| 3962 | 3962 | } |
| 3963 | 3963 | |
| 3964 | 3964 | |
@@ -3976,20 +3976,20 @@ discard block |
||
| 3976 | 3976 | * Message décrypté ou encrypté |
| 3977 | 3977 | **/ |
| 3978 | 3978 | function _xor($message, $key = null) { |
| 3979 | - if (is_null($key)) { |
|
| 3980 | - if (!function_exists('calculer_cle_action')) { |
|
| 3981 | - include_spip('inc/securiser_action'); |
|
| 3982 | - } |
|
| 3983 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 3984 | - } |
|
| 3979 | + if (is_null($key)) { |
|
| 3980 | + if (!function_exists('calculer_cle_action')) { |
|
| 3981 | + include_spip('inc/securiser_action'); |
|
| 3982 | + } |
|
| 3983 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 3984 | + } |
|
| 3985 | 3985 | |
| 3986 | - $keylen = strlen($key); |
|
| 3987 | - $messagelen = strlen($message); |
|
| 3988 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 3989 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 3990 | - } |
|
| 3986 | + $keylen = strlen($key); |
|
| 3987 | + $messagelen = strlen($message); |
|
| 3988 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 3989 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 3990 | + } |
|
| 3991 | 3991 | |
| 3992 | - return $message; |
|
| 3992 | + return $message; |
|
| 3993 | 3993 | } |
| 3994 | 3994 | |
| 3995 | 3995 | /** |
@@ -4003,7 +4003,7 @@ discard block |
||
| 4003 | 4003 | * @return string |
| 4004 | 4004 | */ |
| 4005 | 4005 | function url_reponse_forum($texte) { |
| 4006 | - return $texte; |
|
| 4006 | + return $texte; |
|
| 4007 | 4007 | } |
| 4008 | 4008 | |
| 4009 | 4009 | /** |
@@ -4017,7 +4017,7 @@ discard block |
||
| 4017 | 4017 | * @return string |
| 4018 | 4018 | */ |
| 4019 | 4019 | function url_rss_forum($texte) { |
| 4020 | - return $texte; |
|
| 4020 | + return $texte; |
|
| 4021 | 4021 | } |
| 4022 | 4022 | |
| 4023 | 4023 | |
@@ -4056,37 +4056,37 @@ discard block |
||
| 4056 | 4056 | * Code HTML |
| 4057 | 4057 | */ |
| 4058 | 4058 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4059 | - if ($on) { |
|
| 4060 | - $bal = 'strong'; |
|
| 4061 | - $class = ''; |
|
| 4062 | - $att = ''; |
|
| 4063 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4064 | - // a.active span.selected.active etc.... |
|
| 4065 | - if (is_string($on) && (str_starts_with($on, 'a') || str_starts_with($on, 'span') || str_starts_with($on, 'strong'))) { |
|
| 4066 | - $on = explode('.', $on); |
|
| 4067 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4068 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4069 | - $bal = array_shift($on); |
|
| 4070 | - $class = implode(' ', $on); |
|
| 4071 | - if ($bal == 'a') { |
|
| 4072 | - $att = 'href="#" '; |
|
| 4073 | - } |
|
| 4074 | - } |
|
| 4075 | - } |
|
| 4076 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4077 | - } else { |
|
| 4078 | - $bal = 'a'; |
|
| 4079 | - $att = "href='$url'" |
|
| 4080 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4081 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4082 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4083 | - . $evt; |
|
| 4084 | - } |
|
| 4085 | - if ($libelle === null) { |
|
| 4086 | - $libelle = $url; |
|
| 4087 | - } |
|
| 4088 | - |
|
| 4089 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4059 | + if ($on) { |
|
| 4060 | + $bal = 'strong'; |
|
| 4061 | + $class = ''; |
|
| 4062 | + $att = ''; |
|
| 4063 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4064 | + // a.active span.selected.active etc.... |
|
| 4065 | + if (is_string($on) && (str_starts_with($on, 'a') || str_starts_with($on, 'span') || str_starts_with($on, 'strong'))) { |
|
| 4066 | + $on = explode('.', $on); |
|
| 4067 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4068 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4069 | + $bal = array_shift($on); |
|
| 4070 | + $class = implode(' ', $on); |
|
| 4071 | + if ($bal == 'a') { |
|
| 4072 | + $att = 'href="#" '; |
|
| 4073 | + } |
|
| 4074 | + } |
|
| 4075 | + } |
|
| 4076 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4077 | + } else { |
|
| 4078 | + $bal = 'a'; |
|
| 4079 | + $att = "href='$url'" |
|
| 4080 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4081 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4082 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4083 | + . $evt; |
|
| 4084 | + } |
|
| 4085 | + if ($libelle === null) { |
|
| 4086 | + $libelle = $url; |
|
| 4087 | + } |
|
| 4088 | + |
|
| 4089 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4090 | 4090 | } |
| 4091 | 4091 | |
| 4092 | 4092 | |
@@ -4103,39 +4103,39 @@ discard block |
||
| 4103 | 4103 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4104 | 4104 | */ |
| 4105 | 4105 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4106 | - static $local_singulier_ou_pluriel = []; |
|
| 4107 | - |
|
| 4108 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4109 | - if (!is_numeric($nb) || $nb == 0) { |
|
| 4110 | - return ''; |
|
| 4111 | - } |
|
| 4112 | - if (!is_array($vars)) { |
|
| 4113 | - return ''; |
|
| 4114 | - } |
|
| 4115 | - |
|
| 4116 | - $langue = $GLOBALS['spip_lang']; |
|
| 4117 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4118 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4119 | - if ( |
|
| 4120 | - ($f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)) |
|
| 4121 | - || ($f = charger_fonction('singulier_ou_pluriel', 'inc', true)) |
|
| 4122 | - ) { |
|
| 4123 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4124 | - } |
|
| 4125 | - } |
|
| 4126 | - |
|
| 4127 | - // si on a une surcharge on l'utilise |
|
| 4128 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4129 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4130 | - } |
|
| 4131 | - |
|
| 4132 | - // sinon traitement par defaut |
|
| 4133 | - $vars[$var] = $nb; |
|
| 4134 | - if ($nb >= 2) { |
|
| 4135 | - return _T($chaine_plusieurs, $vars); |
|
| 4136 | - } else { |
|
| 4137 | - return _T($chaine_un, $vars); |
|
| 4138 | - } |
|
| 4106 | + static $local_singulier_ou_pluriel = []; |
|
| 4107 | + |
|
| 4108 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4109 | + if (!is_numeric($nb) || $nb == 0) { |
|
| 4110 | + return ''; |
|
| 4111 | + } |
|
| 4112 | + if (!is_array($vars)) { |
|
| 4113 | + return ''; |
|
| 4114 | + } |
|
| 4115 | + |
|
| 4116 | + $langue = $GLOBALS['spip_lang']; |
|
| 4117 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4118 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4119 | + if ( |
|
| 4120 | + ($f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)) |
|
| 4121 | + || ($f = charger_fonction('singulier_ou_pluriel', 'inc', true)) |
|
| 4122 | + ) { |
|
| 4123 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4124 | + } |
|
| 4125 | + } |
|
| 4126 | + |
|
| 4127 | + // si on a une surcharge on l'utilise |
|
| 4128 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4129 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4130 | + } |
|
| 4131 | + |
|
| 4132 | + // sinon traitement par defaut |
|
| 4133 | + $vars[$var] = $nb; |
|
| 4134 | + if ($nb >= 2) { |
|
| 4135 | + return _T($chaine_plusieurs, $vars); |
|
| 4136 | + } else { |
|
| 4137 | + return _T($chaine_un, $vars); |
|
| 4138 | + } |
|
| 4139 | 4139 | } |
| 4140 | 4140 | |
| 4141 | 4141 | |
@@ -4163,71 +4163,71 @@ discard block |
||
| 4163 | 4163 | */ |
| 4164 | 4164 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4165 | 4165 | |
| 4166 | - $class_lien = $class_bouton = $class; |
|
| 4167 | - |
|
| 4168 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4169 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4170 | - $class_lien .= ' danger'; |
|
| 4171 | - $class_bouton .= ' btn_danger'; |
|
| 4172 | - } elseif ($fonction == 'rien.gif') { |
|
| 4173 | - $fonction = ''; |
|
| 4174 | - } elseif ($fonction == 'delsafe') { |
|
| 4175 | - $fonction = 'del'; |
|
| 4176 | - } |
|
| 4177 | - |
|
| 4178 | - $fond_origine = $fond; |
|
| 4179 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4180 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4181 | - [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4182 | - } |
|
| 4183 | - |
|
| 4184 | - // Ajouter le type d'objet dans la classe |
|
| 4185 | - $objet_type = substr(basename((string) $fond), 0, -4); |
|
| 4186 | - $class_lien .= " $objet_type"; |
|
| 4187 | - $class_bouton .= " $objet_type"; |
|
| 4188 | - |
|
| 4189 | - // texte |
|
| 4190 | - $alt = attribut_html($texte); |
|
| 4191 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4192 | - |
|
| 4193 | - // Liens : préparer les classes ajax |
|
| 4194 | - $ajax = ''; |
|
| 4195 | - if ($type === 'lien' && str_contains($class_lien, 'ajax')) { |
|
| 4196 | - $ajax = 'ajax'; |
|
| 4197 | - if (str_contains($class_lien, 'preload')) { |
|
| 4198 | - $ajax .= ' preload'; |
|
| 4199 | - } |
|
| 4200 | - if (str_contains($class_lien, 'nocache')) { |
|
| 4201 | - $ajax .= ' nocache'; |
|
| 4202 | - } |
|
| 4203 | - $ajax = " class='$ajax'"; |
|
| 4204 | - } |
|
| 4205 | - |
|
| 4206 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4207 | - $size = 24; |
|
| 4208 | - if ( |
|
| 4209 | - preg_match('/-(\d{1,3})[.](gif|png|svg)$/i', (string) $fond, $match) |
|
| 4210 | - || preg_match('/-(\d{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4211 | - ) { |
|
| 4212 | - $size = $match[1]; |
|
| 4213 | - } |
|
| 4214 | - $class_lien .= " s$size"; |
|
| 4215 | - $class_bouton .= " s$size"; |
|
| 4216 | - |
|
| 4217 | - // Icône |
|
| 4218 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4219 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4220 | - |
|
| 4221 | - // Markup final |
|
| 4222 | - if ($type == 'lien') { |
|
| 4223 | - return "<span class='icone $class_lien'>" |
|
| 4224 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4225 | - . $icone |
|
| 4226 | - . "<b>$texte</b>" |
|
| 4227 | - . "</a></span>\n"; |
|
| 4228 | - } else { |
|
| 4229 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4230 | - } |
|
| 4166 | + $class_lien = $class_bouton = $class; |
|
| 4167 | + |
|
| 4168 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4169 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4170 | + $class_lien .= ' danger'; |
|
| 4171 | + $class_bouton .= ' btn_danger'; |
|
| 4172 | + } elseif ($fonction == 'rien.gif') { |
|
| 4173 | + $fonction = ''; |
|
| 4174 | + } elseif ($fonction == 'delsafe') { |
|
| 4175 | + $fonction = 'del'; |
|
| 4176 | + } |
|
| 4177 | + |
|
| 4178 | + $fond_origine = $fond; |
|
| 4179 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4180 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4181 | + [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4182 | + } |
|
| 4183 | + |
|
| 4184 | + // Ajouter le type d'objet dans la classe |
|
| 4185 | + $objet_type = substr(basename((string) $fond), 0, -4); |
|
| 4186 | + $class_lien .= " $objet_type"; |
|
| 4187 | + $class_bouton .= " $objet_type"; |
|
| 4188 | + |
|
| 4189 | + // texte |
|
| 4190 | + $alt = attribut_html($texte); |
|
| 4191 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4192 | + |
|
| 4193 | + // Liens : préparer les classes ajax |
|
| 4194 | + $ajax = ''; |
|
| 4195 | + if ($type === 'lien' && str_contains($class_lien, 'ajax')) { |
|
| 4196 | + $ajax = 'ajax'; |
|
| 4197 | + if (str_contains($class_lien, 'preload')) { |
|
| 4198 | + $ajax .= ' preload'; |
|
| 4199 | + } |
|
| 4200 | + if (str_contains($class_lien, 'nocache')) { |
|
| 4201 | + $ajax .= ' nocache'; |
|
| 4202 | + } |
|
| 4203 | + $ajax = " class='$ajax'"; |
|
| 4204 | + } |
|
| 4205 | + |
|
| 4206 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4207 | + $size = 24; |
|
| 4208 | + if ( |
|
| 4209 | + preg_match('/-(\d{1,3})[.](gif|png|svg)$/i', (string) $fond, $match) |
|
| 4210 | + || preg_match('/-(\d{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4211 | + ) { |
|
| 4212 | + $size = $match[1]; |
|
| 4213 | + } |
|
| 4214 | + $class_lien .= " s$size"; |
|
| 4215 | + $class_bouton .= " s$size"; |
|
| 4216 | + |
|
| 4217 | + // Icône |
|
| 4218 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4219 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4220 | + |
|
| 4221 | + // Markup final |
|
| 4222 | + if ($type == 'lien') { |
|
| 4223 | + return "<span class='icone $class_lien'>" |
|
| 4224 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4225 | + . $icone |
|
| 4226 | + . "<b>$texte</b>" |
|
| 4227 | + . "</a></span>\n"; |
|
| 4228 | + } else { |
|
| 4229 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4230 | + } |
|
| 4231 | 4231 | } |
| 4232 | 4232 | |
| 4233 | 4233 | /** |
@@ -4251,7 +4251,7 @@ discard block |
||
| 4251 | 4251 | * Code HTML du lien |
| 4252 | 4252 | **/ |
| 4253 | 4253 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4254 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4254 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4255 | 4255 | } |
| 4256 | 4256 | |
| 4257 | 4257 | /** |
@@ -4286,7 +4286,7 @@ discard block |
||
| 4286 | 4286 | * Code HTML du lien |
| 4287 | 4287 | **/ |
| 4288 | 4288 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4289 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4289 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4290 | 4290 | } |
| 4291 | 4291 | |
| 4292 | 4292 | /** |
@@ -4331,7 +4331,7 @@ discard block |
||
| 4331 | 4331 | * Code HTML du lien |
| 4332 | 4332 | **/ |
| 4333 | 4333 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4334 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4334 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4335 | 4335 | } |
| 4336 | 4336 | |
| 4337 | 4337 | /** |
@@ -4362,7 +4362,7 @@ discard block |
||
| 4362 | 4362 | * Code HTML du lien |
| 4363 | 4363 | **/ |
| 4364 | 4364 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4365 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4365 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4366 | 4366 | } |
| 4367 | 4367 | |
| 4368 | 4368 | /** |
@@ -4393,7 +4393,7 @@ discard block |
||
| 4393 | 4393 | * Code HTML du lien |
| 4394 | 4394 | */ |
| 4395 | 4395 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4396 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4396 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4397 | 4397 | } |
| 4398 | 4398 | |
| 4399 | 4399 | |
@@ -4415,7 +4415,7 @@ discard block |
||
| 4415 | 4415 | * @return array Liste des éléments |
| 4416 | 4416 | */ |
| 4417 | 4417 | function filtre_explode_dist($a, $b) { |
| 4418 | - return explode($b, (string) $a); |
|
| 4418 | + return explode($b, (string) $a); |
|
| 4419 | 4419 | } |
| 4420 | 4420 | |
| 4421 | 4421 | /** |
@@ -4436,7 +4436,7 @@ discard block |
||
| 4436 | 4436 | * @return string texte |
| 4437 | 4437 | */ |
| 4438 | 4438 | function filtre_implode_dist($a, $b) { |
| 4439 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4439 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4440 | 4440 | } |
| 4441 | 4441 | |
| 4442 | 4442 | /** |
@@ -4445,22 +4445,22 @@ discard block |
||
| 4445 | 4445 | * @return string Code CSS |
| 4446 | 4446 | */ |
| 4447 | 4447 | function bando_images_background() { |
| 4448 | - include_spip('inc/bandeau'); |
|
| 4449 | - // recuperer tous les boutons et leurs images |
|
| 4450 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4448 | + include_spip('inc/bandeau'); |
|
| 4449 | + // recuperer tous les boutons et leurs images |
|
| 4450 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4451 | 4451 | |
| 4452 | - $res = ''; |
|
| 4453 | - foreach ($boutons as $page => $detail) { |
|
| 4454 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4455 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4456 | - if ($sousdetail->icone && strlen(trim((string) $sousdetail->icone))) { |
|
| 4457 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4458 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4459 | - } |
|
| 4460 | - } |
|
| 4461 | - } |
|
| 4452 | + $res = ''; |
|
| 4453 | + foreach ($boutons as $page => $detail) { |
|
| 4454 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4455 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4456 | + if ($sousdetail->icone && strlen(trim((string) $sousdetail->icone))) { |
|
| 4457 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4458 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4459 | + } |
|
| 4460 | + } |
|
| 4461 | + } |
|
| 4462 | 4462 | |
| 4463 | - return $res; |
|
| 4463 | + return $res; |
|
| 4464 | 4464 | } |
| 4465 | 4465 | |
| 4466 | 4466 | /** |
@@ -4485,23 +4485,23 @@ discard block |
||
| 4485 | 4485 | */ |
| 4486 | 4486 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4487 | 4487 | |
| 4488 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4489 | - $class_form = ''; |
|
| 4490 | - if (str_contains($class, 'ajax')) { |
|
| 4491 | - $class_form = 'ajax'; |
|
| 4492 | - $class = str_replace('ajax', '', $class); |
|
| 4493 | - } |
|
| 4494 | - $class_btn = 'submit ' . trim($class); |
|
| 4488 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4489 | + $class_form = ''; |
|
| 4490 | + if (str_contains($class, 'ajax')) { |
|
| 4491 | + $class_form = 'ajax'; |
|
| 4492 | + $class = str_replace('ajax', '', $class); |
|
| 4493 | + } |
|
| 4494 | + $class_btn = 'submit ' . trim($class); |
|
| 4495 | 4495 | |
| 4496 | - if ($confirm) { |
|
| 4497 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4498 | - $callback = $callback ? "$confirm?($callback):false" : $confirm; |
|
| 4499 | - } |
|
| 4500 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4501 | - $title = $title ? " title='$title'" : ''; |
|
| 4496 | + if ($confirm) { |
|
| 4497 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4498 | + $callback = $callback ? "$confirm?($callback):false" : $confirm; |
|
| 4499 | + } |
|
| 4500 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4501 | + $title = $title ? " title='$title'" : ''; |
|
| 4502 | 4502 | |
| 4503 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4504 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4503 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4504 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4505 | 4505 | } |
| 4506 | 4506 | |
| 4507 | 4507 | /** |
@@ -4524,104 +4524,104 @@ discard block |
||
| 4524 | 4524 | * @return string |
| 4525 | 4525 | */ |
| 4526 | 4526 | function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string { |
| 4527 | - static $trouver_table = null; |
|
| 4528 | - static $objets; |
|
| 4529 | - |
|
| 4530 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4531 | - $id_objet = (int) $id_objet; |
|
| 4532 | - if (!($id_objet && $type_objet && $info)) { |
|
| 4533 | - return ''; |
|
| 4534 | - } |
|
| 4535 | - |
|
| 4536 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4537 | - if (isset($objets[$type_objet]) && $objets[$type_objet] === false) { |
|
| 4538 | - return ''; |
|
| 4539 | - } |
|
| 4540 | - |
|
| 4541 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4542 | - if ($info == 'url') { |
|
| 4543 | - return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4544 | - } |
|
| 4545 | - |
|
| 4546 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4547 | - $demande_titre = ($info === 'titre'); |
|
| 4548 | - $demande_introduction = ($info === 'introduction'); |
|
| 4549 | - |
|
| 4550 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4551 | - if ( |
|
| 4552 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4553 | - || $demande_titre && !isset($objets[$type_objet][$id_objet]['titre']) |
|
| 4554 | - ) { |
|
| 4555 | - if (!$trouver_table) { |
|
| 4556 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4557 | - } |
|
| 4558 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4559 | - if (!$desc) { |
|
| 4560 | - return $objets[$type_objet] = false; |
|
| 4561 | - } |
|
| 4562 | - |
|
| 4563 | - // Si on demande le titre, on le gere en interne |
|
| 4564 | - $champ_titre = ''; |
|
| 4565 | - if ($demande_titre) { |
|
| 4566 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4567 | - $champ_titre = (empty($desc['titre'])) ? '' : ', ' . $desc['titre']; |
|
| 4568 | - } |
|
| 4569 | - include_spip('base/abstract_sql'); |
|
| 4570 | - include_spip('base/connect_sql'); |
|
| 4571 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4572 | - '*' . $champ_titre, |
|
| 4573 | - $desc['table_sql'], |
|
| 4574 | - id_table_objet($type_objet) . ' = ' . (int) $id_objet |
|
| 4575 | - ); |
|
| 4576 | - |
|
| 4577 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4578 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4579 | - } |
|
| 4580 | - |
|
| 4581 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4582 | - // ajouter la longueur au début des params supplémentaires |
|
| 4583 | - if ($demande_introduction) { |
|
| 4584 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4585 | - array_unshift($params, $introduction_longueur); |
|
| 4586 | - } |
|
| 4587 | - |
|
| 4588 | - $row = ($objets[$type_objet][$id_objet] ?? []) ?: []; |
|
| 4589 | - // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4590 | - if ($generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)) { |
|
| 4591 | - $info_generee = $generer($id_objet, $row, ...$params); |
|
| 4592 | - } |
|
| 4593 | - // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4594 | - elseif ($generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)) { |
|
| 4595 | - trigger_deprecation('spip', '4.1', 'Using "%s" function naming is deprecated, rename "%s" instead', "generer_{$info}_{$type_objet}", "generer_{$type_objet}_{$info}"); |
|
| 4596 | - $info_generee = $generer($id_objet, $row, ...$params); |
|
| 4597 | - } |
|
| 4598 | - // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4599 | - elseif ($generer = charger_fonction("generer_objet_{$info}", '', true)) { |
|
| 4600 | - $info_generee = $generer($id_objet, $type_objet, $row, ...$params); |
|
| 4601 | - } |
|
| 4602 | - // @deprecated 4.1 generer_TRUC_entite |
|
| 4603 | - elseif ($generer = charger_fonction("generer_{$info}_entite", '', true)) { |
|
| 4604 | - trigger_deprecation('spip', '4.1', 'Using "%s" function naming is deprecated, rename "%s" instead', "generer_{$info}_entite", "generer_objet_{$info}"); |
|
| 4605 | - $info_generee = $generer($id_objet, $type_objet, $row, ...$params); |
|
| 4606 | - } |
|
| 4607 | - // Sinon on prend directement le champ SQL tel quel |
|
| 4608 | - else { |
|
| 4609 | - $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4610 | - } |
|
| 4611 | - |
|
| 4612 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4613 | - if (!$etoile) { |
|
| 4614 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4615 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4616 | - $info_generee = appliquer_traitement_champ( |
|
| 4617 | - $info_generee, |
|
| 4618 | - $info, |
|
| 4619 | - table_objet($type_objet), |
|
| 4620 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4621 | - ); |
|
| 4622 | - } |
|
| 4623 | - |
|
| 4624 | - return $info_generee; |
|
| 4527 | + static $trouver_table = null; |
|
| 4528 | + static $objets; |
|
| 4529 | + |
|
| 4530 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4531 | + $id_objet = (int) $id_objet; |
|
| 4532 | + if (!($id_objet && $type_objet && $info)) { |
|
| 4533 | + return ''; |
|
| 4534 | + } |
|
| 4535 | + |
|
| 4536 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4537 | + if (isset($objets[$type_objet]) && $objets[$type_objet] === false) { |
|
| 4538 | + return ''; |
|
| 4539 | + } |
|
| 4540 | + |
|
| 4541 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4542 | + if ($info == 'url') { |
|
| 4543 | + return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4544 | + } |
|
| 4545 | + |
|
| 4546 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4547 | + $demande_titre = ($info === 'titre'); |
|
| 4548 | + $demande_introduction = ($info === 'introduction'); |
|
| 4549 | + |
|
| 4550 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4551 | + if ( |
|
| 4552 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4553 | + || $demande_titre && !isset($objets[$type_objet][$id_objet]['titre']) |
|
| 4554 | + ) { |
|
| 4555 | + if (!$trouver_table) { |
|
| 4556 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4557 | + } |
|
| 4558 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4559 | + if (!$desc) { |
|
| 4560 | + return $objets[$type_objet] = false; |
|
| 4561 | + } |
|
| 4562 | + |
|
| 4563 | + // Si on demande le titre, on le gere en interne |
|
| 4564 | + $champ_titre = ''; |
|
| 4565 | + if ($demande_titre) { |
|
| 4566 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4567 | + $champ_titre = (empty($desc['titre'])) ? '' : ', ' . $desc['titre']; |
|
| 4568 | + } |
|
| 4569 | + include_spip('base/abstract_sql'); |
|
| 4570 | + include_spip('base/connect_sql'); |
|
| 4571 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4572 | + '*' . $champ_titre, |
|
| 4573 | + $desc['table_sql'], |
|
| 4574 | + id_table_objet($type_objet) . ' = ' . (int) $id_objet |
|
| 4575 | + ); |
|
| 4576 | + |
|
| 4577 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4578 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4579 | + } |
|
| 4580 | + |
|
| 4581 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4582 | + // ajouter la longueur au début des params supplémentaires |
|
| 4583 | + if ($demande_introduction) { |
|
| 4584 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4585 | + array_unshift($params, $introduction_longueur); |
|
| 4586 | + } |
|
| 4587 | + |
|
| 4588 | + $row = ($objets[$type_objet][$id_objet] ?? []) ?: []; |
|
| 4589 | + // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4590 | + if ($generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)) { |
|
| 4591 | + $info_generee = $generer($id_objet, $row, ...$params); |
|
| 4592 | + } |
|
| 4593 | + // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4594 | + elseif ($generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)) { |
|
| 4595 | + trigger_deprecation('spip', '4.1', 'Using "%s" function naming is deprecated, rename "%s" instead', "generer_{$info}_{$type_objet}", "generer_{$type_objet}_{$info}"); |
|
| 4596 | + $info_generee = $generer($id_objet, $row, ...$params); |
|
| 4597 | + } |
|
| 4598 | + // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4599 | + elseif ($generer = charger_fonction("generer_objet_{$info}", '', true)) { |
|
| 4600 | + $info_generee = $generer($id_objet, $type_objet, $row, ...$params); |
|
| 4601 | + } |
|
| 4602 | + // @deprecated 4.1 generer_TRUC_entite |
|
| 4603 | + elseif ($generer = charger_fonction("generer_{$info}_entite", '', true)) { |
|
| 4604 | + trigger_deprecation('spip', '4.1', 'Using "%s" function naming is deprecated, rename "%s" instead', "generer_{$info}_entite", "generer_objet_{$info}"); |
|
| 4605 | + $info_generee = $generer($id_objet, $type_objet, $row, ...$params); |
|
| 4606 | + } |
|
| 4607 | + // Sinon on prend directement le champ SQL tel quel |
|
| 4608 | + else { |
|
| 4609 | + $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4610 | + } |
|
| 4611 | + |
|
| 4612 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4613 | + if (!$etoile) { |
|
| 4614 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4615 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4616 | + $info_generee = appliquer_traitement_champ( |
|
| 4617 | + $info_generee, |
|
| 4618 | + $info, |
|
| 4619 | + table_objet($type_objet), |
|
| 4620 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4621 | + ); |
|
| 4622 | + } |
|
| 4623 | + |
|
| 4624 | + return $info_generee; |
|
| 4625 | 4625 | } |
| 4626 | 4626 | |
| 4627 | 4627 | /** |
@@ -4654,34 +4654,34 @@ discard block |
||
| 4654 | 4654 | */ |
| 4655 | 4655 | function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string { |
| 4656 | 4656 | |
| 4657 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4658 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4659 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4660 | - if (isset($ligne_sql['chapo'])) { |
|
| 4661 | - $chapo = $ligne_sql['chapo']; |
|
| 4662 | - $texte = strlen((string) $descriptif) ? |
|
| 4663 | - '' : |
|
| 4664 | - "$chapo \n\n $texte"; |
|
| 4665 | - } |
|
| 4657 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4658 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4659 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4660 | + if (isset($ligne_sql['chapo'])) { |
|
| 4661 | + $chapo = $ligne_sql['chapo']; |
|
| 4662 | + $texte = strlen((string) $descriptif) ? |
|
| 4663 | + '' : |
|
| 4664 | + "$chapo \n\n $texte"; |
|
| 4665 | + } |
|
| 4666 | 4666 | |
| 4667 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4668 | - if (!(int) $longueur_ou_suite) { |
|
| 4669 | - $longueur = (int) ($introduction_longueur ?: 600); |
|
| 4670 | - } else { |
|
| 4671 | - $longueur = (int) $longueur_ou_suite; |
|
| 4672 | - } |
|
| 4667 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4668 | + if (!(int) $longueur_ou_suite) { |
|
| 4669 | + $longueur = (int) ($introduction_longueur ?: 600); |
|
| 4670 | + } else { |
|
| 4671 | + $longueur = (int) $longueur_ou_suite; |
|
| 4672 | + } |
|
| 4673 | 4673 | |
| 4674 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4675 | - // Ex : #INTRODUCTION{...} |
|
| 4676 | - if ( |
|
| 4677 | - is_null($suite) && !(int) $longueur_ou_suite |
|
| 4678 | - ) { |
|
| 4679 | - $suite = $longueur_ou_suite; |
|
| 4680 | - } |
|
| 4674 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4675 | + // Ex : #INTRODUCTION{...} |
|
| 4676 | + if ( |
|
| 4677 | + is_null($suite) && !(int) $longueur_ou_suite |
|
| 4678 | + ) { |
|
| 4679 | + $suite = $longueur_ou_suite; |
|
| 4680 | + } |
|
| 4681 | 4681 | |
| 4682 | - $f = chercher_filtre('introduction'); |
|
| 4682 | + $f = chercher_filtre('introduction'); |
|
| 4683 | 4683 | |
| 4684 | - return $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4684 | + return $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4685 | 4685 | } |
| 4686 | 4686 | |
| 4687 | 4687 | /** |
@@ -4694,49 +4694,49 @@ discard block |
||
| 4694 | 4694 | * @return string |
| 4695 | 4695 | */ |
| 4696 | 4696 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') { |
| 4697 | - if (!$champ) { |
|
| 4698 | - return $texte; |
|
| 4699 | - } |
|
| 4697 | + if (!$champ) { |
|
| 4698 | + return $texte; |
|
| 4699 | + } |
|
| 4700 | 4700 | |
| 4701 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4702 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4703 | - include_fichiers_fonctions(); |
|
| 4701 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4702 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4703 | + include_fichiers_fonctions(); |
|
| 4704 | 4704 | |
| 4705 | - $champ = strtoupper($champ); |
|
| 4706 | - $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4707 | - if (!$traitements || !is_array($traitements)) { |
|
| 4708 | - return $texte; |
|
| 4709 | - } |
|
| 4705 | + $champ = strtoupper($champ); |
|
| 4706 | + $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4707 | + if (!$traitements || !is_array($traitements)) { |
|
| 4708 | + return $texte; |
|
| 4709 | + } |
|
| 4710 | 4710 | |
| 4711 | - $traitement = ''; |
|
| 4712 | - if ($table_objet && (!isset($traitements[0]) || count($traitements) > 1)) { |
|
| 4713 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4714 | - $table_objet = table_objet($table_objet); |
|
| 4715 | - if (isset($traitements[$table_objet])) { |
|
| 4716 | - $traitement = $traitements[$table_objet]; |
|
| 4717 | - } |
|
| 4718 | - } |
|
| 4719 | - if (!$traitement && isset($traitements[0])) { |
|
| 4720 | - $traitement = $traitements[0]; |
|
| 4721 | - } |
|
| 4722 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4711 | + $traitement = ''; |
|
| 4712 | + if ($table_objet && (!isset($traitements[0]) || count($traitements) > 1)) { |
|
| 4713 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4714 | + $table_objet = table_objet($table_objet); |
|
| 4715 | + if (isset($traitements[$table_objet])) { |
|
| 4716 | + $traitement = $traitements[$table_objet]; |
|
| 4717 | + } |
|
| 4718 | + } |
|
| 4719 | + if (!$traitement && isset($traitements[0])) { |
|
| 4720 | + $traitement = $traitements[0]; |
|
| 4721 | + } |
|
| 4722 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4723 | 4723 | |
| 4724 | - if (!$traitement) { |
|
| 4725 | - return $texte; |
|
| 4726 | - } |
|
| 4724 | + if (!$traitement) { |
|
| 4725 | + return $texte; |
|
| 4726 | + } |
|
| 4727 | 4727 | |
| 4728 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", (string) $traitement); |
|
| 4728 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", (string) $traitement); |
|
| 4729 | 4729 | |
| 4730 | - // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4731 | - if (test_espace_prive()) { |
|
| 4732 | - $env['espace_prive'] = 1; |
|
| 4733 | - } |
|
| 4730 | + // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4731 | + if (test_espace_prive()) { |
|
| 4732 | + $env['espace_prive'] = 1; |
|
| 4733 | + } |
|
| 4734 | 4734 | |
| 4735 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4736 | - $Pile = [0 => $env]; |
|
| 4737 | - eval("\$texte = $traitement;"); |
|
| 4735 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4736 | + $Pile = [0 => $env]; |
|
| 4737 | + eval("\$texte = $traitement;"); |
|
| 4738 | 4738 | |
| 4739 | - return $texte; |
|
| 4739 | + return $texte; |
|
| 4740 | 4740 | } |
| 4741 | 4741 | |
| 4742 | 4742 | |
@@ -4747,21 +4747,21 @@ discard block |
||
| 4747 | 4747 | * @return string |
| 4748 | 4748 | */ |
| 4749 | 4749 | function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string { |
| 4750 | - include_spip('inc/liens'); |
|
| 4751 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4752 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4753 | - // le raccourcis n'est plus valide |
|
| 4754 | - $titre = typo($titre['titre'] ?? ''); |
|
| 4755 | - // on essaye avec generer_objet_info ? |
|
| 4756 | - if (!strlen($titre) && !$connect) { |
|
| 4757 | - $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4758 | - } |
|
| 4759 | - if (!strlen($titre)) { |
|
| 4760 | - $titre = _T('info_sans_titre'); |
|
| 4761 | - } |
|
| 4762 | - $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4750 | + include_spip('inc/liens'); |
|
| 4751 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4752 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4753 | + // le raccourcis n'est plus valide |
|
| 4754 | + $titre = typo($titre['titre'] ?? ''); |
|
| 4755 | + // on essaye avec generer_objet_info ? |
|
| 4756 | + if (!strlen($titre) && !$connect) { |
|
| 4757 | + $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4758 | + } |
|
| 4759 | + if (!strlen($titre)) { |
|
| 4760 | + $titre = _T('info_sans_titre'); |
|
| 4761 | + } |
|
| 4762 | + $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4763 | 4763 | |
| 4764 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4764 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4765 | 4765 | } |
| 4766 | 4766 | |
| 4767 | 4767 | /** |
@@ -4777,15 +4777,15 @@ discard block |
||
| 4777 | 4777 | * @return string |
| 4778 | 4778 | */ |
| 4779 | 4779 | function wrap($texte, $wrap) { |
| 4780 | - $balises = extraire_balises($wrap); |
|
| 4781 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4782 | - $texte = $wrap . $texte; |
|
| 4783 | - $regs = array_reverse($regs[1]); |
|
| 4784 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4785 | - $texte .= $wrap; |
|
| 4786 | - } |
|
| 4780 | + $balises = extraire_balises($wrap); |
|
| 4781 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4782 | + $texte = $wrap . $texte; |
|
| 4783 | + $regs = array_reverse($regs[1]); |
|
| 4784 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4785 | + $texte .= $wrap; |
|
| 4786 | + } |
|
| 4787 | 4787 | |
| 4788 | - return $texte; |
|
| 4788 | + return $texte; |
|
| 4789 | 4789 | } |
| 4790 | 4790 | |
| 4791 | 4791 | |
@@ -4805,42 +4805,42 @@ discard block |
||
| 4805 | 4805 | * @return array|mixed|string |
| 4806 | 4806 | */ |
| 4807 | 4807 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 4808 | - if (is_string($u)) { |
|
| 4809 | - return typo($u); |
|
| 4810 | - } |
|
| 4811 | - |
|
| 4812 | - // caster $u en array si besoin |
|
| 4813 | - if (is_object($u)) { |
|
| 4814 | - $u = (array)$u; |
|
| 4815 | - } |
|
| 4816 | - |
|
| 4817 | - if (is_array($u)) { |
|
| 4818 | - $out = ''; |
|
| 4819 | - // toutes les cles sont numeriques ? |
|
| 4820 | - // et aucun enfant n'est un tableau |
|
| 4821 | - // liste simple separee par des virgules |
|
| 4822 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4823 | - $array_values = array_map('is_array', $u); |
|
| 4824 | - $object_values = array_map('is_object', $u); |
|
| 4825 | - if ( |
|
| 4826 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 4827 | - && !array_sum($array_values) |
|
| 4828 | - && !array_sum($object_values) |
|
| 4829 | - ) { |
|
| 4830 | - return implode(', ', array_map('filtre_print_dist', $u)); |
|
| 4831 | - } |
|
| 4832 | - |
|
| 4833 | - // sinon on passe a la ligne et on indente |
|
| 4834 | - $i_str = str_pad('', $indent, ' '); |
|
| 4835 | - foreach ($u as $k => $v) { |
|
| 4836 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4837 | - } |
|
| 4838 | - |
|
| 4839 | - return $out; |
|
| 4840 | - } |
|
| 4841 | - |
|
| 4842 | - // on sait pas quoi faire... |
|
| 4843 | - return $u; |
|
| 4808 | + if (is_string($u)) { |
|
| 4809 | + return typo($u); |
|
| 4810 | + } |
|
| 4811 | + |
|
| 4812 | + // caster $u en array si besoin |
|
| 4813 | + if (is_object($u)) { |
|
| 4814 | + $u = (array)$u; |
|
| 4815 | + } |
|
| 4816 | + |
|
| 4817 | + if (is_array($u)) { |
|
| 4818 | + $out = ''; |
|
| 4819 | + // toutes les cles sont numeriques ? |
|
| 4820 | + // et aucun enfant n'est un tableau |
|
| 4821 | + // liste simple separee par des virgules |
|
| 4822 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4823 | + $array_values = array_map('is_array', $u); |
|
| 4824 | + $object_values = array_map('is_object', $u); |
|
| 4825 | + if ( |
|
| 4826 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 4827 | + && !array_sum($array_values) |
|
| 4828 | + && !array_sum($object_values) |
|
| 4829 | + ) { |
|
| 4830 | + return implode(', ', array_map('filtre_print_dist', $u)); |
|
| 4831 | + } |
|
| 4832 | + |
|
| 4833 | + // sinon on passe a la ligne et on indente |
|
| 4834 | + $i_str = str_pad('', $indent, ' '); |
|
| 4835 | + foreach ($u as $k => $v) { |
|
| 4836 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4837 | + } |
|
| 4838 | + |
|
| 4839 | + return $out; |
|
| 4840 | + } |
|
| 4841 | + |
|
| 4842 | + // on sait pas quoi faire... |
|
| 4843 | + return $u; |
|
| 4844 | 4844 | } |
| 4845 | 4845 | |
| 4846 | 4846 | |
@@ -4853,10 +4853,10 @@ discard block |
||
| 4853 | 4853 | * @return string|array |
| 4854 | 4854 | */ |
| 4855 | 4855 | function objet_info($objet, $info) { |
| 4856 | - $table = table_objet_sql($objet); |
|
| 4857 | - $infos = lister_tables_objets_sql($table); |
|
| 4856 | + $table = table_objet_sql($objet); |
|
| 4857 | + $infos = lister_tables_objets_sql($table); |
|
| 4858 | 4858 | |
| 4859 | - return ($infos[$info] ?? ''); |
|
| 4859 | + return ($infos[$info] ?? ''); |
|
| 4860 | 4860 | } |
| 4861 | 4861 | |
| 4862 | 4862 | /** |
@@ -4871,11 +4871,11 @@ discard block |
||
| 4871 | 4871 | * texte traduit du comptage, tel que '3 articles' |
| 4872 | 4872 | */ |
| 4873 | 4873 | function objet_afficher_nb($nb, $objet) { |
| 4874 | - if (!$nb) { |
|
| 4875 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 4876 | - } else { |
|
| 4877 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 4878 | - } |
|
| 4874 | + if (!$nb) { |
|
| 4875 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 4876 | + } else { |
|
| 4877 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 4878 | + } |
|
| 4879 | 4879 | } |
| 4880 | 4880 | |
| 4881 | 4881 | /** |
@@ -4887,11 +4887,11 @@ discard block |
||
| 4887 | 4887 | * @return string |
| 4888 | 4888 | */ |
| 4889 | 4889 | function objet_icone($objet, $taille = 24, $class = '') { |
| 4890 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 4891 | - $icone = chemin_image($icone); |
|
| 4892 | - $balise_img = charger_filtre('balise_img'); |
|
| 4890 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 4891 | + $icone = chemin_image($icone); |
|
| 4892 | + $balise_img = charger_filtre('balise_img'); |
|
| 4893 | 4893 | |
| 4894 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 4894 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 4895 | 4895 | } |
| 4896 | 4896 | |
| 4897 | 4897 | /** |
@@ -4912,12 +4912,12 @@ discard block |
||
| 4912 | 4912 | * @return string |
| 4913 | 4913 | */ |
| 4914 | 4914 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 4915 | - $chaine = explode(':', $chaine); |
|
| 4916 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 4917 | - return $t; |
|
| 4918 | - } |
|
| 4919 | - $chaine = implode(':', $chaine); |
|
| 4920 | - return _T($chaine, $args, $options); |
|
| 4915 | + $chaine = explode(':', $chaine); |
|
| 4916 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 4917 | + return $t; |
|
| 4918 | + } |
|
| 4919 | + $chaine = implode(':', $chaine); |
|
| 4920 | + return _T($chaine, $args, $options); |
|
| 4921 | 4921 | } |
| 4922 | 4922 | |
| 4923 | 4923 | /** |
@@ -4931,18 +4931,18 @@ discard block |
||
| 4931 | 4931 | * @return string Code HTML |
| 4932 | 4932 | */ |
| 4933 | 4933 | function insert_head_css_conditionnel($flux) { |
| 4934 | - if ( |
|
| 4935 | - !str_contains($flux, '<!-- insert_head_css -->') |
|
| 4936 | - && ($p = strpos($flux, '<!-- insert_head -->')) |
|
| 4937 | - ) { |
|
| 4938 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 4939 | - if (($p1 = stripos($flux, '<script src=')) && $p1 < $p) { |
|
| 4940 | - $p = $p1; |
|
| 4941 | - } |
|
| 4942 | - $flux = substr_replace($flux, (string) pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 4943 | - } |
|
| 4934 | + if ( |
|
| 4935 | + !str_contains($flux, '<!-- insert_head_css -->') |
|
| 4936 | + && ($p = strpos($flux, '<!-- insert_head -->')) |
|
| 4937 | + ) { |
|
| 4938 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 4939 | + if (($p1 = stripos($flux, '<script src=')) && $p1 < $p) { |
|
| 4940 | + $p = $p1; |
|
| 4941 | + } |
|
| 4942 | + $flux = substr_replace($flux, (string) pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 4943 | + } |
|
| 4944 | 4944 | |
| 4945 | - return $flux; |
|
| 4945 | + return $flux; |
|
| 4946 | 4946 | } |
| 4947 | 4947 | |
| 4948 | 4948 | /** |
@@ -4965,75 +4965,75 @@ discard block |
||
| 4965 | 4965 | * @return string |
| 4966 | 4966 | */ |
| 4967 | 4967 | function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') { |
| 4968 | - if (isset($contexte['format'])) { |
|
| 4969 | - $extension = $contexte['format']; |
|
| 4970 | - unset($contexte['format']); |
|
| 4971 | - } else { |
|
| 4972 | - $extension = 'html'; |
|
| 4973 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 4974 | - $extension = $m[1]; |
|
| 4975 | - } |
|
| 4976 | - } |
|
| 4977 | - // recuperer le contenu produit par le squelette |
|
| 4978 | - $options['raw'] = true; |
|
| 4979 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 4980 | - |
|
| 4981 | - // calculer le nom de la css |
|
| 4982 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 4983 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 4984 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 4985 | - |
|
| 4986 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 4987 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 4988 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 4989 | - if (isset($options['hash_on_content']) && $options['hash_on_content']) { |
|
| 4990 | - $hash = md5((string) ($contexte_implicite['host'] . '::' . $cache)); |
|
| 4991 | - } |
|
| 4992 | - else { |
|
| 4993 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 4994 | - ksort($contexte); |
|
| 4995 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 4996 | - } |
|
| 4997 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 4998 | - |
|
| 4999 | - // mettre a jour le fichier si il n'existe pas |
|
| 5000 | - // ou trop ancien |
|
| 5001 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5002 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5003 | - if ( |
|
| 5004 | - !file_exists($filename) |
|
| 5005 | - || !file_exists($filename . '.last') |
|
| 5006 | - || isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename . '.last') < $cache['lastmodified'] |
|
| 5007 | - || defined('_VAR_MODE') && _VAR_MODE == 'recalcul' |
|
| 5008 | - ) { |
|
| 5009 | - $contenu = $cache['texte']; |
|
| 5010 | - // passer les urls en absolu si c'est une css |
|
| 5011 | - if ($extension == 'css') { |
|
| 5012 | - $contenu = urls_absolues_css( |
|
| 5013 | - $contenu, |
|
| 5014 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5015 | - ); |
|
| 5016 | - } |
|
| 5017 | - |
|
| 5018 | - $comment = ''; |
|
| 5019 | - // ne pas insérer de commentaire sur certains formats |
|
| 5020 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5021 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5022 | - foreach ($contexte as $k => $v) { |
|
| 5023 | - if (is_array($v)) { |
|
| 5024 | - $v = var_export($v, true); |
|
| 5025 | - } |
|
| 5026 | - $comment .= ",$k=$v"; |
|
| 5027 | - } |
|
| 5028 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5029 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5030 | - $comment .= "}\n md5:" . md5((string) $contenu) . " */\n"; |
|
| 5031 | - } |
|
| 5032 | - // et ecrire le fichier si il change |
|
| 5033 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5034 | - } |
|
| 5035 | - |
|
| 5036 | - return timestamp($filename); |
|
| 4968 | + if (isset($contexte['format'])) { |
|
| 4969 | + $extension = $contexte['format']; |
|
| 4970 | + unset($contexte['format']); |
|
| 4971 | + } else { |
|
| 4972 | + $extension = 'html'; |
|
| 4973 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 4974 | + $extension = $m[1]; |
|
| 4975 | + } |
|
| 4976 | + } |
|
| 4977 | + // recuperer le contenu produit par le squelette |
|
| 4978 | + $options['raw'] = true; |
|
| 4979 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 4980 | + |
|
| 4981 | + // calculer le nom de la css |
|
| 4982 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 4983 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 4984 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 4985 | + |
|
| 4986 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 4987 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 4988 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 4989 | + if (isset($options['hash_on_content']) && $options['hash_on_content']) { |
|
| 4990 | + $hash = md5((string) ($contexte_implicite['host'] . '::' . $cache)); |
|
| 4991 | + } |
|
| 4992 | + else { |
|
| 4993 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 4994 | + ksort($contexte); |
|
| 4995 | + $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 4996 | + } |
|
| 4997 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 4998 | + |
|
| 4999 | + // mettre a jour le fichier si il n'existe pas |
|
| 5000 | + // ou trop ancien |
|
| 5001 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5002 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5003 | + if ( |
|
| 5004 | + !file_exists($filename) |
|
| 5005 | + || !file_exists($filename . '.last') |
|
| 5006 | + || isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename . '.last') < $cache['lastmodified'] |
|
| 5007 | + || defined('_VAR_MODE') && _VAR_MODE == 'recalcul' |
|
| 5008 | + ) { |
|
| 5009 | + $contenu = $cache['texte']; |
|
| 5010 | + // passer les urls en absolu si c'est une css |
|
| 5011 | + if ($extension == 'css') { |
|
| 5012 | + $contenu = urls_absolues_css( |
|
| 5013 | + $contenu, |
|
| 5014 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5015 | + ); |
|
| 5016 | + } |
|
| 5017 | + |
|
| 5018 | + $comment = ''; |
|
| 5019 | + // ne pas insérer de commentaire sur certains formats |
|
| 5020 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5021 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5022 | + foreach ($contexte as $k => $v) { |
|
| 5023 | + if (is_array($v)) { |
|
| 5024 | + $v = var_export($v, true); |
|
| 5025 | + } |
|
| 5026 | + $comment .= ",$k=$v"; |
|
| 5027 | + } |
|
| 5028 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5029 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5030 | + $comment .= "}\n md5:" . md5((string) $contenu) . " */\n"; |
|
| 5031 | + } |
|
| 5032 | + // et ecrire le fichier si il change |
|
| 5033 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5034 | + } |
|
| 5035 | + |
|
| 5036 | + return timestamp($filename); |
|
| 5037 | 5037 | } |
| 5038 | 5038 | |
| 5039 | 5039 | /** |
@@ -5046,11 +5046,11 @@ discard block |
||
| 5046 | 5046 | * $fichier auquel on a ajouté le timestamp |
| 5047 | 5047 | */ |
| 5048 | 5048 | function timestamp($fichier) { |
| 5049 | - if (!$fichier || !file_exists($fichier) || !$m = filemtime($fichier)) { |
|
| 5050 | - return $fichier; |
|
| 5051 | - } |
|
| 5049 | + if (!$fichier || !file_exists($fichier) || !$m = filemtime($fichier)) { |
|
| 5050 | + return $fichier; |
|
| 5051 | + } |
|
| 5052 | 5052 | |
| 5053 | - return "$fichier?$m"; |
|
| 5053 | + return "$fichier?$m"; |
|
| 5054 | 5054 | } |
| 5055 | 5055 | |
| 5056 | 5056 | /** |
@@ -5060,11 +5060,11 @@ discard block |
||
| 5060 | 5060 | * @return string |
| 5061 | 5061 | */ |
| 5062 | 5062 | function supprimer_timestamp($url) { |
| 5063 | - if (!str_contains($url, '?')) { |
|
| 5064 | - return $url; |
|
| 5065 | - } |
|
| 5063 | + if (!str_contains($url, '?')) { |
|
| 5064 | + return $url; |
|
| 5065 | + } |
|
| 5066 | 5066 | |
| 5067 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5067 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5068 | 5068 | } |
| 5069 | 5069 | |
| 5070 | 5070 | /** |
@@ -5079,15 +5079,15 @@ discard block |
||
| 5079 | 5079 | * @return string |
| 5080 | 5080 | */ |
| 5081 | 5081 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5082 | - include_spip('inc/envoyer_mail'); |
|
| 5082 | + include_spip('inc/envoyer_mail'); |
|
| 5083 | 5083 | |
| 5084 | - $titre = nettoyer_titre_email($titre); |
|
| 5085 | - // on est dans un squelette : securiser le retour |
|
| 5086 | - if (str_contains($titre, '<')) { |
|
| 5087 | - $titre = interdire_scripts($titre); |
|
| 5088 | - } |
|
| 5084 | + $titre = nettoyer_titre_email($titre); |
|
| 5085 | + // on est dans un squelette : securiser le retour |
|
| 5086 | + if (str_contains($titre, '<')) { |
|
| 5087 | + $titre = interdire_scripts($titre); |
|
| 5088 | + } |
|
| 5089 | 5089 | |
| 5090 | - return $titre; |
|
| 5090 | + return $titre; |
|
| 5091 | 5091 | } |
| 5092 | 5092 | |
| 5093 | 5093 | /** |
@@ -5109,27 +5109,27 @@ discard block |
||
| 5109 | 5109 | * @return string |
| 5110 | 5110 | */ |
| 5111 | 5111 | function filtre_chercher_rubrique_dist( |
| 5112 | - $titre, |
|
| 5113 | - $id_objet, |
|
| 5114 | - $id_parent, |
|
| 5115 | - $objet, |
|
| 5116 | - $id_secteur, |
|
| 5117 | - $restreint, |
|
| 5118 | - $actionable = false, |
|
| 5119 | - $retour_sans_cadre = false |
|
| 5112 | + $titre, |
|
| 5113 | + $id_objet, |
|
| 5114 | + $id_parent, |
|
| 5115 | + $objet, |
|
| 5116 | + $id_secteur, |
|
| 5117 | + $restreint, |
|
| 5118 | + $actionable = false, |
|
| 5119 | + $retour_sans_cadre = false |
|
| 5120 | 5120 | ) { |
| 5121 | - include_spip('inc/filtres_ecrire'); |
|
| 5121 | + include_spip('inc/filtres_ecrire'); |
|
| 5122 | 5122 | |
| 5123 | - return chercher_rubrique( |
|
| 5124 | - $titre, |
|
| 5125 | - $id_objet, |
|
| 5126 | - $id_parent, |
|
| 5127 | - $objet, |
|
| 5128 | - $id_secteur, |
|
| 5129 | - $restreint, |
|
| 5130 | - $actionable, |
|
| 5131 | - $retour_sans_cadre |
|
| 5132 | - ); |
|
| 5123 | + return chercher_rubrique( |
|
| 5124 | + $titre, |
|
| 5125 | + $id_objet, |
|
| 5126 | + $id_parent, |
|
| 5127 | + $objet, |
|
| 5128 | + $id_secteur, |
|
| 5129 | + $restreint, |
|
| 5130 | + $actionable, |
|
| 5131 | + $retour_sans_cadre |
|
| 5132 | + ); |
|
| 5133 | 5133 | } |
| 5134 | 5134 | |
| 5135 | 5135 | /** |
@@ -5158,56 +5158,56 @@ discard block |
||
| 5158 | 5158 | * Chaîne vide si l'accès est autorisé |
| 5159 | 5159 | */ |
| 5160 | 5160 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5161 | - if ($ok) { |
|
| 5162 | - return ''; |
|
| 5163 | - } |
|
| 5164 | - |
|
| 5165 | - // Vider tous les tampons |
|
| 5166 | - $level = @ob_get_level(); |
|
| 5167 | - while ($level--) { |
|
| 5168 | - @ob_end_clean(); |
|
| 5169 | - } |
|
| 5170 | - |
|
| 5171 | - include_spip('inc/headers'); |
|
| 5172 | - |
|
| 5173 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5174 | - if ($url) { |
|
| 5175 | - redirige_par_entete($url, '', $statut); |
|
| 5176 | - } |
|
| 5177 | - |
|
| 5178 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5179 | - if (!is_numeric($statut) && is_null($message)) { |
|
| 5180 | - $message = $statut; |
|
| 5181 | - $statut = 0; |
|
| 5182 | - } |
|
| 5183 | - if (!$message) { |
|
| 5184 | - $message = ''; |
|
| 5185 | - } |
|
| 5186 | - $statut = (int) $statut; |
|
| 5187 | - |
|
| 5188 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5189 | - if (test_espace_prive()) { |
|
| 5190 | - if (!$statut || !in_array($statut, [404, 403])) { |
|
| 5191 | - $statut = 403; |
|
| 5192 | - } |
|
| 5193 | - http_response_code(403); |
|
| 5194 | - $echec = charger_fonction('403', 'exec'); |
|
| 5195 | - $echec($message); |
|
| 5196 | - } else { |
|
| 5197 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5198 | - if (!$statut) { |
|
| 5199 | - $statut = 404; |
|
| 5200 | - } |
|
| 5201 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5202 | - http_response_code($statut); |
|
| 5203 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5204 | - if ($statut >= 400) { |
|
| 5205 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5206 | - } |
|
| 5207 | - } |
|
| 5208 | - |
|
| 5209 | - |
|
| 5210 | - exit; |
|
| 5161 | + if ($ok) { |
|
| 5162 | + return ''; |
|
| 5163 | + } |
|
| 5164 | + |
|
| 5165 | + // Vider tous les tampons |
|
| 5166 | + $level = @ob_get_level(); |
|
| 5167 | + while ($level--) { |
|
| 5168 | + @ob_end_clean(); |
|
| 5169 | + } |
|
| 5170 | + |
|
| 5171 | + include_spip('inc/headers'); |
|
| 5172 | + |
|
| 5173 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5174 | + if ($url) { |
|
| 5175 | + redirige_par_entete($url, '', $statut); |
|
| 5176 | + } |
|
| 5177 | + |
|
| 5178 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5179 | + if (!is_numeric($statut) && is_null($message)) { |
|
| 5180 | + $message = $statut; |
|
| 5181 | + $statut = 0; |
|
| 5182 | + } |
|
| 5183 | + if (!$message) { |
|
| 5184 | + $message = ''; |
|
| 5185 | + } |
|
| 5186 | + $statut = (int) $statut; |
|
| 5187 | + |
|
| 5188 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5189 | + if (test_espace_prive()) { |
|
| 5190 | + if (!$statut || !in_array($statut, [404, 403])) { |
|
| 5191 | + $statut = 403; |
|
| 5192 | + } |
|
| 5193 | + http_response_code(403); |
|
| 5194 | + $echec = charger_fonction('403', 'exec'); |
|
| 5195 | + $echec($message); |
|
| 5196 | + } else { |
|
| 5197 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5198 | + if (!$statut) { |
|
| 5199 | + $statut = 404; |
|
| 5200 | + } |
|
| 5201 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5202 | + http_response_code($statut); |
|
| 5203 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5204 | + if ($statut >= 400) { |
|
| 5205 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5206 | + } |
|
| 5207 | + } |
|
| 5208 | + |
|
| 5209 | + |
|
| 5210 | + exit; |
|
| 5211 | 5211 | } |
| 5212 | 5212 | |
| 5213 | 5213 | /** |
@@ -5218,11 +5218,11 @@ discard block |
||
| 5218 | 5218 | * @return string |
| 5219 | 5219 | */ |
| 5220 | 5220 | function filtre_compacte_dist($source, $format = null) { |
| 5221 | - if (function_exists('minifier')) { |
|
| 5222 | - return minifier($source, $format); |
|
| 5223 | - } |
|
| 5221 | + if (function_exists('minifier')) { |
|
| 5222 | + return minifier($source, $format); |
|
| 5223 | + } |
|
| 5224 | 5224 | |
| 5225 | - return $source; |
|
| 5225 | + return $source; |
|
| 5226 | 5226 | } |
| 5227 | 5227 | |
| 5228 | 5228 | |
@@ -5232,32 +5232,32 @@ discard block |
||
| 5232 | 5232 | * @return string |
| 5233 | 5233 | */ |
| 5234 | 5234 | function spip_affiche_mot_de_passe_masque(#[\SensitiveParameter] ?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string { |
| 5235 | - $passe ??= ''; |
|
| 5236 | - $l = strlen($passe); |
|
| 5237 | - |
|
| 5238 | - if ($l <= 8 || !$afficher_partiellement) { |
|
| 5239 | - if (!$l) { |
|
| 5240 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5241 | - } |
|
| 5242 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5243 | - } |
|
| 5244 | - |
|
| 5245 | - if (is_null($portion_pourcent)) { |
|
| 5246 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5247 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5248 | - } |
|
| 5249 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5250 | - } |
|
| 5251 | - if ($portion_pourcent >= 100) { |
|
| 5252 | - return $passe; |
|
| 5253 | - } |
|
| 5254 | - $e = (int) ceil($l * $portion_pourcent / 100 / 2); |
|
| 5255 | - $e = max($e, 0); |
|
| 5256 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5257 | - if ($e > 0 && strlen($mid) > 8) { |
|
| 5258 | - $mid = '***...***'; |
|
| 5259 | - } |
|
| 5260 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5235 | + $passe ??= ''; |
|
| 5236 | + $l = strlen($passe); |
|
| 5237 | + |
|
| 5238 | + if ($l <= 8 || !$afficher_partiellement) { |
|
| 5239 | + if (!$l) { |
|
| 5240 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5241 | + } |
|
| 5242 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5243 | + } |
|
| 5244 | + |
|
| 5245 | + if (is_null($portion_pourcent)) { |
|
| 5246 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5247 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5248 | + } |
|
| 5249 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5250 | + } |
|
| 5251 | + if ($portion_pourcent >= 100) { |
|
| 5252 | + return $passe; |
|
| 5253 | + } |
|
| 5254 | + $e = (int) ceil($l * $portion_pourcent / 100 / 2); |
|
| 5255 | + $e = max($e, 0); |
|
| 5256 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5257 | + if ($e > 0 && strlen($mid) > 8) { |
|
| 5258 | + $mid = '***...***'; |
|
| 5259 | + } |
|
| 5260 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5261 | 5261 | } |
| 5262 | 5262 | |
| 5263 | 5263 | |
@@ -5278,64 +5278,64 @@ discard block |
||
| 5278 | 5278 | */ |
| 5279 | 5279 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5280 | 5280 | |
| 5281 | - $original = $texte; |
|
| 5282 | - $separateur = ($options['separateur'] ?? '_'); |
|
| 5283 | - $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5284 | - $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5281 | + $original = $texte; |
|
| 5282 | + $separateur = ($options['separateur'] ?? '_'); |
|
| 5283 | + $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5284 | + $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5285 | 5285 | |
| 5286 | - if (!function_exists('translitteration')) { |
|
| 5287 | - include_spip('inc/charsets'); |
|
| 5288 | - } |
|
| 5286 | + if (!function_exists('translitteration')) { |
|
| 5287 | + include_spip('inc/charsets'); |
|
| 5288 | + } |
|
| 5289 | 5289 | |
| 5290 | - // pas de balise html |
|
| 5291 | - if (str_contains($texte, '<')) { |
|
| 5292 | - $texte = strip_tags($texte); |
|
| 5293 | - } |
|
| 5294 | - if (str_contains($texte, '&')) { |
|
| 5295 | - $texte = unicode2charset($texte); |
|
| 5296 | - } |
|
| 5297 | - // On enlève les espaces indésirables |
|
| 5298 | - $texte = trim($texte); |
|
| 5290 | + // pas de balise html |
|
| 5291 | + if (str_contains($texte, '<')) { |
|
| 5292 | + $texte = strip_tags($texte); |
|
| 5293 | + } |
|
| 5294 | + if (str_contains($texte, '&')) { |
|
| 5295 | + $texte = unicode2charset($texte); |
|
| 5296 | + } |
|
| 5297 | + // On enlève les espaces indésirables |
|
| 5298 | + $texte = trim($texte); |
|
| 5299 | 5299 | |
| 5300 | - // On enlève les accents et cie |
|
| 5301 | - $texte = translitteration($texte); |
|
| 5300 | + // On enlève les accents et cie |
|
| 5301 | + $texte = translitteration($texte); |
|
| 5302 | 5302 | |
| 5303 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5304 | - $texte = preg_replace(',[\W_]+,ms', (string) $separateur, $texte); |
|
| 5303 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5304 | + $texte = preg_replace(',[\W_]+,ms', (string) $separateur, $texte); |
|
| 5305 | 5305 | |
| 5306 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5307 | - while (str_contains($texte, (string) "$separateur$separateur")) { |
|
| 5308 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5309 | - } |
|
| 5306 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5307 | + while (str_contains($texte, (string) "$separateur$separateur")) { |
|
| 5308 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5309 | + } |
|
| 5310 | 5310 | |
| 5311 | - // pas de separateur au debut ni a la fin |
|
| 5312 | - $texte = trim($texte, $separateur); |
|
| 5311 | + // pas de separateur au debut ni a la fin |
|
| 5312 | + $texte = trim($texte, $separateur); |
|
| 5313 | 5313 | |
| 5314 | - // en minuscules |
|
| 5315 | - $texte = strtolower($texte); |
|
| 5314 | + // en minuscules |
|
| 5315 | + $texte = strtolower($texte); |
|
| 5316 | 5316 | |
| 5317 | - switch ($type) { |
|
| 5318 | - case 'class': |
|
| 5319 | - case 'id': |
|
| 5320 | - case 'anchor': |
|
| 5321 | - if (preg_match(',^\d,', $texte)) { |
|
| 5322 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5323 | - } |
|
| 5324 | - } |
|
| 5317 | + switch ($type) { |
|
| 5318 | + case 'class': |
|
| 5319 | + case 'id': |
|
| 5320 | + case 'anchor': |
|
| 5321 | + if (preg_match(',^\d,', $texte)) { |
|
| 5322 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5323 | + } |
|
| 5324 | + } |
|
| 5325 | 5325 | |
| 5326 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5327 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5328 | - } |
|
| 5326 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5327 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5328 | + } |
|
| 5329 | 5329 | |
| 5330 | - if (strlen($texte) < $longueur_mini && $longueur_mini < $longueur_maxi) { |
|
| 5331 | - if (preg_match(',^\d,', $texte)) { |
|
| 5332 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5333 | - } |
|
| 5334 | - $texte .= $separateur . md5($original); |
|
| 5335 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5336 | - } |
|
| 5330 | + if (strlen($texte) < $longueur_mini && $longueur_mini < $longueur_maxi) { |
|
| 5331 | + if (preg_match(',^\d,', $texte)) { |
|
| 5332 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5333 | + } |
|
| 5334 | + $texte .= $separateur . md5($original); |
|
| 5335 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5336 | + } |
|
| 5337 | 5337 | |
| 5338 | - return $texte; |
|
| 5338 | + return $texte; |
|
| 5339 | 5339 | } |
| 5340 | 5340 | |
| 5341 | 5341 | |
@@ -5356,11 +5356,11 @@ discard block |
||
| 5356 | 5356 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5357 | 5357 | */ |
| 5358 | 5358 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5359 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5360 | - if ($ucfirst) { |
|
| 5361 | - $label = spip_ucfirst($label); |
|
| 5362 | - } |
|
| 5363 | - return $label; |
|
| 5359 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5360 | + if ($ucfirst) { |
|
| 5361 | + $label = spip_ucfirst($label); |
|
| 5362 | + } |
|
| 5363 | + return $label; |
|
| 5364 | 5364 | } |
| 5365 | 5365 | |
| 5366 | 5366 | /** |
@@ -5373,8 +5373,8 @@ discard block |
||
| 5373 | 5373 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5374 | 5374 | */ |
| 5375 | 5375 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5376 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5377 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5376 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5377 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5378 | 5378 | } |
| 5379 | 5379 | |
| 5380 | 5380 | |
@@ -5387,19 +5387,19 @@ discard block |
||
| 5387 | 5387 | * @return array |
| 5388 | 5388 | */ |
| 5389 | 5389 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5390 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5391 | - return []; |
|
| 5392 | - } |
|
| 5390 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5391 | + return []; |
|
| 5392 | + } |
|
| 5393 | 5393 | |
| 5394 | - // compatibilite signature inversee |
|
| 5395 | - if (is_numeric($objet) && !is_numeric($id_objet)) { |
|
| 5396 | - [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5397 | - } |
|
| 5394 | + // compatibilite signature inversee |
|
| 5395 | + if (is_numeric($objet) && !is_numeric($id_objet)) { |
|
| 5396 | + [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5397 | + } |
|
| 5398 | 5398 | |
| 5399 | - if (!function_exists($fonction)) { |
|
| 5400 | - include_spip('base/objets'); |
|
| 5401 | - } |
|
| 5402 | - return $fonction($objet, $id_objet); |
|
| 5399 | + if (!function_exists($fonction)) { |
|
| 5400 | + include_spip('base/objets'); |
|
| 5401 | + } |
|
| 5402 | + return $fonction($objet, $id_objet); |
|
| 5403 | 5403 | } |
| 5404 | 5404 | |
| 5405 | 5405 | |
@@ -5414,7 +5414,7 @@ discard block |
||
| 5414 | 5414 | * @return array |
| 5415 | 5415 | */ |
| 5416 | 5416 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5417 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5417 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5418 | 5418 | } |
| 5419 | 5419 | |
| 5420 | 5420 | /** |
@@ -5428,7 +5428,7 @@ discard block |
||
| 5428 | 5428 | * @return array |
| 5429 | 5429 | */ |
| 5430 | 5430 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5431 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5431 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5432 | 5432 | } |
| 5433 | 5433 | |
| 5434 | 5434 | /** |
@@ -5442,7 +5442,7 @@ discard block |
||
| 5442 | 5442 | * @return array |
| 5443 | 5443 | */ |
| 5444 | 5444 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5445 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5445 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5446 | 5446 | } |
| 5447 | 5447 | |
| 5448 | 5448 | /** |
@@ -5456,5 +5456,5 @@ discard block |
||
| 5456 | 5456 | * @return array |
| 5457 | 5457 | */ |
| 5458 | 5458 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5459 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5459 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5460 | 5460 | } |
@@ -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 | include_spip('base/abstract_sql'); |
| 22 | 22 | |
@@ -58,56 +58,56 @@ discard block |
||
| 58 | 58 | * Retour des traitements. |
| 59 | 59 | **/ |
| 60 | 60 | function formulaires_editer_objet_traiter( |
| 61 | - $type, |
|
| 62 | - $id = 'new', |
|
| 63 | - $id_parent = 0, |
|
| 64 | - $lier_trad = 0, |
|
| 65 | - $retour = '', |
|
| 66 | - $config_fonc = 'articles_edit_config', |
|
| 67 | - $row = [], |
|
| 68 | - $hidden = '' |
|
| 61 | + $type, |
|
| 62 | + $id = 'new', |
|
| 63 | + $id_parent = 0, |
|
| 64 | + $lier_trad = 0, |
|
| 65 | + $retour = '', |
|
| 66 | + $config_fonc = 'articles_edit_config', |
|
| 67 | + $row = [], |
|
| 68 | + $hidden = '' |
|
| 69 | 69 | ) { |
| 70 | 70 | |
| 71 | - $res = []; |
|
| 72 | - // eviter la redirection forcee par l'action... |
|
| 73 | - set_request('redirect'); |
|
| 74 | - if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 75 | - [$id, $err] = $action_editer($id); |
|
| 76 | - } else { |
|
| 77 | - $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 78 | - [$id, $err] = $action_editer($id, $type); |
|
| 79 | - } |
|
| 80 | - $id_table_objet = id_table_objet($type); |
|
| 81 | - $res[$id_table_objet] = $id; |
|
| 82 | - if ($err || !$id) { |
|
| 83 | - $res['message_erreur'] = ($err ?: _T('erreur')); |
|
| 84 | - } else { |
|
| 85 | - // Un lien de trad a prendre en compte |
|
| 86 | - if ($lier_trad) { |
|
| 87 | - // referencer la traduction |
|
| 88 | - $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 89 | - $referencer_traduction($type, $id, $lier_trad); |
|
| 90 | - // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 91 | - $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 92 | - $err = $completer_traduction($type, $id, $lier_trad); |
|
| 93 | - if ($err) { |
|
| 94 | - $res['message_erreur'] = $err; |
|
| 95 | - return $res; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 100 | - if ($retour) { |
|
| 101 | - if (str_starts_with($retour, 'javascript:')) { |
|
| 102 | - $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 103 | - $res['editable'] = true; |
|
| 104 | - } else { |
|
| 105 | - $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return $res; |
|
| 71 | + $res = []; |
|
| 72 | + // eviter la redirection forcee par l'action... |
|
| 73 | + set_request('redirect'); |
|
| 74 | + if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 75 | + [$id, $err] = $action_editer($id); |
|
| 76 | + } else { |
|
| 77 | + $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 78 | + [$id, $err] = $action_editer($id, $type); |
|
| 79 | + } |
|
| 80 | + $id_table_objet = id_table_objet($type); |
|
| 81 | + $res[$id_table_objet] = $id; |
|
| 82 | + if ($err || !$id) { |
|
| 83 | + $res['message_erreur'] = ($err ?: _T('erreur')); |
|
| 84 | + } else { |
|
| 85 | + // Un lien de trad a prendre en compte |
|
| 86 | + if ($lier_trad) { |
|
| 87 | + // referencer la traduction |
|
| 88 | + $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 89 | + $referencer_traduction($type, $id, $lier_trad); |
|
| 90 | + // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 91 | + $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 92 | + $err = $completer_traduction($type, $id, $lier_trad); |
|
| 93 | + if ($err) { |
|
| 94 | + $res['message_erreur'] = $err; |
|
| 95 | + return $res; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 100 | + if ($retour) { |
|
| 101 | + if (str_starts_with($retour, 'javascript:')) { |
|
| 102 | + $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 103 | + $res['editable'] = true; |
|
| 104 | + } else { |
|
| 105 | + $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return $res; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -131,29 +131,29 @@ discard block |
||
| 131 | 131 | * Tableau des erreurs |
| 132 | 132 | **/ |
| 133 | 133 | function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = []) { |
| 134 | - $erreurs = []; |
|
| 135 | - if ((int) $id) { |
|
| 136 | - $conflits = controler_contenu($type, $id); |
|
| 137 | - if ($conflits && (is_countable($conflits) ? count($conflits) : 0)) { |
|
| 138 | - foreach ($conflits as $champ => $conflit) { |
|
| 139 | - if (!isset($erreurs[$champ])) { |
|
| 140 | - $erreurs[$champ] = ''; |
|
| 141 | - } |
|
| 142 | - $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - foreach ($oblis as $obli) { |
|
| 147 | - $value = _request($obli); |
|
| 148 | - if (is_null($value) || !(is_array($value) ? count($value) : strlen((string) $value))) { |
|
| 149 | - if (!isset($erreurs[$obli])) { |
|
| 150 | - $erreurs[$obli] = ''; |
|
| 151 | - } |
|
| 152 | - $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return $erreurs; |
|
| 134 | + $erreurs = []; |
|
| 135 | + if ((int) $id) { |
|
| 136 | + $conflits = controler_contenu($type, $id); |
|
| 137 | + if ($conflits && (is_countable($conflits) ? count($conflits) : 0)) { |
|
| 138 | + foreach ($conflits as $champ => $conflit) { |
|
| 139 | + if (!isset($erreurs[$champ])) { |
|
| 140 | + $erreurs[$champ] = ''; |
|
| 141 | + } |
|
| 142 | + $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + foreach ($oblis as $obli) { |
|
| 147 | + $value = _request($obli); |
|
| 148 | + if (is_null($value) || !(is_array($value) ? count($value) : strlen((string) $value))) { |
|
| 149 | + if (!isset($erreurs[$obli])) { |
|
| 150 | + $erreurs[$obli] = ''; |
|
| 151 | + } |
|
| 152 | + $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return $erreurs; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -198,151 +198,151 @@ discard block |
||
| 198 | 198 | * Environnement du formulaire. |
| 199 | 199 | **/ |
| 200 | 200 | function formulaires_editer_objet_charger( |
| 201 | - $type, |
|
| 202 | - $id = 'new', |
|
| 203 | - $id_parent = 0, |
|
| 204 | - $lier_trad = 0, |
|
| 205 | - $retour = '', |
|
| 206 | - $config_fonc = 'articles_edit_config', |
|
| 207 | - $row = [], |
|
| 208 | - $hidden = '' |
|
| 201 | + $type, |
|
| 202 | + $id = 'new', |
|
| 203 | + $id_parent = 0, |
|
| 204 | + $lier_trad = 0, |
|
| 205 | + $retour = '', |
|
| 206 | + $config_fonc = 'articles_edit_config', |
|
| 207 | + $row = [], |
|
| 208 | + $hidden = '' |
|
| 209 | 209 | ) { |
| 210 | 210 | |
| 211 | - $table_objet = table_objet($type); |
|
| 212 | - $table_objet_sql = table_objet_sql($type); |
|
| 213 | - $id_table_objet = id_table_objet($type); |
|
| 214 | - if (!is_array($row)) { |
|
| 215 | - $row = []; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // on accepte pas une fonction de config inconnue si elle vient d'un modele |
|
| 219 | - if ( |
|
| 220 | - $config_fonc |
|
| 221 | - && !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
|
| 222 | - && $config_fonc !== $table_objet . '_edit_config' |
|
| 223 | - && ($args = test_formulaire_inclus_par_modele()) |
|
| 224 | - && in_array($config_fonc, $args) |
|
| 225 | - ) { |
|
| 226 | - $config_fonc = ''; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $new = !is_numeric($id); |
|
| 230 | - $lang_default = ''; |
|
| 231 | - // Appel direct dans un squelette |
|
| 232 | - if (!$row) { |
|
| 233 | - if (!$new || $lier_trad) { |
|
| 234 | - if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 235 | - $row = $select($id, $id_parent, $lier_trad); |
|
| 236 | - // si on a une fonction precharger, elle pu faire un reglage de langue |
|
| 237 | - $lang_default = (empty($row['lang']) ? null : $row['lang']); |
|
| 238 | - } else { |
|
| 239 | - $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id); |
|
| 240 | - } |
|
| 241 | - if (!$new) { |
|
| 242 | - $md5 = controles_md5($row ?: []); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - if (!$row) { |
|
| 246 | - $row = []; |
|
| 247 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 248 | - if ($desc = $trouver_table($table_objet)) { |
|
| 249 | - foreach ($desc['field'] as $k => $v) { |
|
| 250 | - $row[$k] = ''; |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 257 | - // (et donc: pas de lien de traduction) |
|
| 258 | - $id = ($new || $lier_trad) |
|
| 259 | - ? 'oui' |
|
| 260 | - : $row[$id_table_objet]; |
|
| 261 | - $row[$id_table_objet] = $id; |
|
| 262 | - |
|
| 263 | - $contexte = $row; |
|
| 264 | - if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) || $new)) { |
|
| 265 | - if (!isset($contexte['id_parent'])) { |
|
| 266 | - unset($contexte['id_rubrique']); |
|
| 267 | - } |
|
| 268 | - $contexte['id_parent'] = $id_parent; |
|
| 269 | - } elseif (!isset($contexte['id_parent'])) { |
|
| 270 | - // id_rubrique dans id_parent si possible |
|
| 271 | - if (isset($contexte['id_rubrique'])) { |
|
| 272 | - $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 273 | - unset($contexte['id_rubrique']); |
|
| 274 | - } else { |
|
| 275 | - $contexte['id_parent'] = ''; |
|
| 276 | - } |
|
| 277 | - if ( |
|
| 278 | - !$contexte['id_parent'] |
|
| 279 | - && ($preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)) |
|
| 280 | - ) { |
|
| 281 | - $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - $config = []; |
|
| 286 | - if ($config_fonc) { |
|
| 287 | - $contexte['config'] = $config = $config_fonc($contexte); |
|
| 288 | - if (!$lang_default) { |
|
| 289 | - include_spip('inc/session'); |
|
| 290 | - $lang_default = $config['langue'] ?? session_get('lang') ; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - $config += [ |
|
| 294 | - 'lignes' => 0, |
|
| 295 | - 'langue' => '', |
|
| 296 | - ]; |
|
| 297 | - |
|
| 298 | - $att_text = " class='textarea' " |
|
| 299 | - . " rows='" |
|
| 300 | - . ($config['lignes'] + 15) |
|
| 301 | - . "' cols='40'"; |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - // on veut conserver la langue de l'interface ; |
|
| 305 | - // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 306 | - // voudrait l'exploiter |
|
| 307 | - if (isset($contexte['lang'])) { |
|
| 308 | - $contexte['langue'] = $contexte['lang']; |
|
| 309 | - unset($contexte['lang']); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 313 | - ($lier_trad |
|
| 314 | - ? "\n<input type='hidden' name='lier_trad' value='" . |
|
| 315 | - $lier_trad . |
|
| 316 | - "' />" . |
|
| 317 | - "\n<input type='hidden' name='changer_lang' value='" . |
|
| 318 | - $lang_default . |
|
| 319 | - "' />" |
|
| 320 | - : '') |
|
| 321 | - . $hidden |
|
| 322 | - . ($md5 ?? ''); |
|
| 323 | - |
|
| 324 | - // preciser que le formulaire doit passer dans un pipeline |
|
| 325 | - $contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]]; |
|
| 326 | - |
|
| 327 | - // preciser que le formulaire doit etre securise auteur/action |
|
| 328 | - // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 329 | - // on le garde pour compat |
|
| 330 | - $contexte['_action'] = ["editer_$type", $id]; |
|
| 331 | - |
|
| 332 | - // et in fine placer l'autorisation |
|
| 333 | - include_spip('inc/autoriser'); |
|
| 334 | - if ((int) $id) { |
|
| 335 | - if (!autoriser('modifier', $type, (int) $id)) { |
|
| 336 | - $contexte['editable'] = ''; |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - else { |
|
| 340 | - if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) { |
|
| 341 | - $contexte['editable'] = ''; |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - return $contexte; |
|
| 211 | + $table_objet = table_objet($type); |
|
| 212 | + $table_objet_sql = table_objet_sql($type); |
|
| 213 | + $id_table_objet = id_table_objet($type); |
|
| 214 | + if (!is_array($row)) { |
|
| 215 | + $row = []; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // on accepte pas une fonction de config inconnue si elle vient d'un modele |
|
| 219 | + if ( |
|
| 220 | + $config_fonc |
|
| 221 | + && !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
|
| 222 | + && $config_fonc !== $table_objet . '_edit_config' |
|
| 223 | + && ($args = test_formulaire_inclus_par_modele()) |
|
| 224 | + && in_array($config_fonc, $args) |
|
| 225 | + ) { |
|
| 226 | + $config_fonc = ''; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $new = !is_numeric($id); |
|
| 230 | + $lang_default = ''; |
|
| 231 | + // Appel direct dans un squelette |
|
| 232 | + if (!$row) { |
|
| 233 | + if (!$new || $lier_trad) { |
|
| 234 | + if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 235 | + $row = $select($id, $id_parent, $lier_trad); |
|
| 236 | + // si on a une fonction precharger, elle pu faire un reglage de langue |
|
| 237 | + $lang_default = (empty($row['lang']) ? null : $row['lang']); |
|
| 238 | + } else { |
|
| 239 | + $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id); |
|
| 240 | + } |
|
| 241 | + if (!$new) { |
|
| 242 | + $md5 = controles_md5($row ?: []); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + if (!$row) { |
|
| 246 | + $row = []; |
|
| 247 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 248 | + if ($desc = $trouver_table($table_objet)) { |
|
| 249 | + foreach ($desc['field'] as $k => $v) { |
|
| 250 | + $row[$k] = ''; |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 257 | + // (et donc: pas de lien de traduction) |
|
| 258 | + $id = ($new || $lier_trad) |
|
| 259 | + ? 'oui' |
|
| 260 | + : $row[$id_table_objet]; |
|
| 261 | + $row[$id_table_objet] = $id; |
|
| 262 | + |
|
| 263 | + $contexte = $row; |
|
| 264 | + if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) || $new)) { |
|
| 265 | + if (!isset($contexte['id_parent'])) { |
|
| 266 | + unset($contexte['id_rubrique']); |
|
| 267 | + } |
|
| 268 | + $contexte['id_parent'] = $id_parent; |
|
| 269 | + } elseif (!isset($contexte['id_parent'])) { |
|
| 270 | + // id_rubrique dans id_parent si possible |
|
| 271 | + if (isset($contexte['id_rubrique'])) { |
|
| 272 | + $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 273 | + unset($contexte['id_rubrique']); |
|
| 274 | + } else { |
|
| 275 | + $contexte['id_parent'] = ''; |
|
| 276 | + } |
|
| 277 | + if ( |
|
| 278 | + !$contexte['id_parent'] |
|
| 279 | + && ($preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)) |
|
| 280 | + ) { |
|
| 281 | + $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + $config = []; |
|
| 286 | + if ($config_fonc) { |
|
| 287 | + $contexte['config'] = $config = $config_fonc($contexte); |
|
| 288 | + if (!$lang_default) { |
|
| 289 | + include_spip('inc/session'); |
|
| 290 | + $lang_default = $config['langue'] ?? session_get('lang') ; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + $config += [ |
|
| 294 | + 'lignes' => 0, |
|
| 295 | + 'langue' => '', |
|
| 296 | + ]; |
|
| 297 | + |
|
| 298 | + $att_text = " class='textarea' " |
|
| 299 | + . " rows='" |
|
| 300 | + . ($config['lignes'] + 15) |
|
| 301 | + . "' cols='40'"; |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + // on veut conserver la langue de l'interface ; |
|
| 305 | + // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 306 | + // voudrait l'exploiter |
|
| 307 | + if (isset($contexte['lang'])) { |
|
| 308 | + $contexte['langue'] = $contexte['lang']; |
|
| 309 | + unset($contexte['lang']); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 313 | + ($lier_trad |
|
| 314 | + ? "\n<input type='hidden' name='lier_trad' value='" . |
|
| 315 | + $lier_trad . |
|
| 316 | + "' />" . |
|
| 317 | + "\n<input type='hidden' name='changer_lang' value='" . |
|
| 318 | + $lang_default . |
|
| 319 | + "' />" |
|
| 320 | + : '') |
|
| 321 | + . $hidden |
|
| 322 | + . ($md5 ?? ''); |
|
| 323 | + |
|
| 324 | + // preciser que le formulaire doit passer dans un pipeline |
|
| 325 | + $contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]]; |
|
| 326 | + |
|
| 327 | + // preciser que le formulaire doit etre securise auteur/action |
|
| 328 | + // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 329 | + // on le garde pour compat |
|
| 330 | + $contexte['_action'] = ["editer_$type", $id]; |
|
| 331 | + |
|
| 332 | + // et in fine placer l'autorisation |
|
| 333 | + include_spip('inc/autoriser'); |
|
| 334 | + if ((int) $id) { |
|
| 335 | + if (!autoriser('modifier', $type, (int) $id)) { |
|
| 336 | + $contexte['editable'] = ''; |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + else { |
|
| 340 | + if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) { |
|
| 341 | + $contexte['editable'] = ''; |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + return $contexte; |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | /** |
@@ -353,29 +353,29 @@ discard block |
||
| 353 | 353 | * @return array |
| 354 | 354 | */ |
| 355 | 355 | function coupe_trop_long($texte) { |
| 356 | - $aider = charger_fonction('aider', 'inc'); |
|
| 357 | - if (strlen($texte) > 28 * 1024) { |
|
| 358 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 359 | - $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 360 | - if ($pos > 0 && $pos < 32 * 1024) { |
|
| 361 | - $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 362 | - $suite = substr($texte, $pos + 2); |
|
| 363 | - } else { |
|
| 364 | - $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 365 | - if (!($pos > 0 && $pos < 32 * 1024)) { |
|
| 366 | - $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 367 | - $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 368 | - } else { |
|
| 369 | - $decalage = 1; |
|
| 370 | - } |
|
| 371 | - $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 372 | - $suite = substr($texte, $pos + $decalage); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - return ([$debut, $suite]); |
|
| 376 | - } else { |
|
| 377 | - return ([$texte, '']); |
|
| 378 | - } |
|
| 356 | + $aider = charger_fonction('aider', 'inc'); |
|
| 357 | + if (strlen($texte) > 28 * 1024) { |
|
| 358 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 359 | + $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 360 | + if ($pos > 0 && $pos < 32 * 1024) { |
|
| 361 | + $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 362 | + $suite = substr($texte, $pos + 2); |
|
| 363 | + } else { |
|
| 364 | + $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 365 | + if (!($pos > 0 && $pos < 32 * 1024)) { |
|
| 366 | + $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 367 | + $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 368 | + } else { |
|
| 369 | + $decalage = 1; |
|
| 370 | + } |
|
| 371 | + $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 372 | + $suite = substr($texte, $pos + $decalage); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + return ([$debut, $suite]); |
|
| 376 | + } else { |
|
| 377 | + return ([$texte, '']); |
|
| 378 | + } |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -386,13 +386,13 @@ discard block |
||
| 386 | 386 | * @param int $longueur |
| 387 | 387 | */ |
| 388 | 388 | function titre_automatique($champ_titre, $champs_contenu, $longueur = null) { |
| 389 | - if (!_request($champ_titre)) { |
|
| 390 | - $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 391 | - $t = is_null($longueur) ? $titrer_contenu($champs_contenu) : $titrer_contenu($champs_contenu, null, $longueur); |
|
| 392 | - if ($t) { |
|
| 393 | - set_request($champ_titre, $t); |
|
| 394 | - } |
|
| 395 | - } |
|
| 389 | + if (!_request($champ_titre)) { |
|
| 390 | + $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 391 | + $t = is_null($longueur) ? $titrer_contenu($champs_contenu) : $titrer_contenu($champs_contenu, null, $longueur); |
|
| 392 | + if ($t) { |
|
| 393 | + set_request($champ_titre, $t); |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -412,20 +412,20 @@ discard block |
||
| 412 | 412 | * @return string |
| 413 | 413 | */ |
| 414 | 414 | function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) { |
| 415 | - // trouver un champ texte non vide |
|
| 416 | - $t = ''; |
|
| 417 | - foreach ($champs_contenu as $champ) { |
|
| 418 | - if ($t = _request($champ, $c)) { |
|
| 419 | - break; |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - if ($t) { |
|
| 424 | - include_spip('inc/texte_mini'); |
|
| 425 | - $t = couper($t, $longueur, '...'); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - return $t; |
|
| 415 | + // trouver un champ texte non vide |
|
| 416 | + $t = ''; |
|
| 417 | + foreach ($champs_contenu as $champ) { |
|
| 418 | + if ($t = _request($champ, $c)) { |
|
| 419 | + break; |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + if ($t) { |
|
| 424 | + include_spip('inc/texte_mini'); |
|
| 425 | + $t = couper($t, $longueur, '...'); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + return $t; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -447,22 +447,22 @@ discard block |
||
| 447 | 447 | * - array sinon couples ('$prefixe$colonne => md5) |
| 448 | 448 | **/ |
| 449 | 449 | function controles_md5(array $data, string $prefixe = 'ctr_', string $format = 'html') { |
| 450 | - $ctr = []; |
|
| 451 | - foreach ($data as $key => $val) { |
|
| 452 | - $m = md5($val ?? ''); |
|
| 453 | - $k = $prefixe . $key; |
|
| 454 | - |
|
| 455 | - $ctr[$k] = match ($format) { |
|
| 456 | - 'html' => "<input type='hidden' value='$m' name='$k' />", |
|
| 457 | - default => $m, |
|
| 458 | - }; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - if ($format === 'html') { |
|
| 462 | - return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n"; |
|
| 463 | - } else { |
|
| 464 | - return $ctr; |
|
| 465 | - } |
|
| 450 | + $ctr = []; |
|
| 451 | + foreach ($data as $key => $val) { |
|
| 452 | + $m = md5($val ?? ''); |
|
| 453 | + $k = $prefixe . $key; |
|
| 454 | + |
|
| 455 | + $ctr[$k] = match ($format) { |
|
| 456 | + 'html' => "<input type='hidden' value='$m' name='$k' />", |
|
| 457 | + default => $m, |
|
| 458 | + }; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + if ($format === 'html') { |
|
| 462 | + return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n"; |
|
| 463 | + } else { |
|
| 464 | + return $ctr; |
|
| 465 | + } |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -501,80 +501,80 @@ discard block |
||
| 501 | 501 | * - post : le contenu posté |
| 502 | 502 | **/ |
| 503 | 503 | function controler_contenu($type, $id, $options = [], $c = false, $serveur = '') { |
| 504 | - include_spip('inc/filtres'); |
|
| 505 | - |
|
| 506 | - $table_objet = table_objet($type); |
|
| 507 | - $spip_table_objet = table_objet_sql($type); |
|
| 508 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 509 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 510 | - |
|
| 511 | - // Appels incomplets (sans $c) |
|
| 512 | - if (!is_array($c)) { |
|
| 513 | - $c = []; |
|
| 514 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 515 | - if (_request($champ)) { |
|
| 516 | - $c[$champ] = _request($champ); |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 522 | - // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 523 | - // il faut passer par instituer_XX() |
|
| 524 | - // TODO: faut-il passer ces variables interdites |
|
| 525 | - // dans un fichier de description separe ? |
|
| 526 | - unset($c['statut']); |
|
| 527 | - unset($c['id_parent']); |
|
| 528 | - unset($c['id_rubrique']); |
|
| 529 | - unset($c['id_secteur']); |
|
| 530 | - |
|
| 531 | - // Gerer les champs non vides |
|
| 532 | - if (isset($options['nonvide']) && is_array($options['nonvide'])) { |
|
| 533 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 534 | - if ($c[$champ] === '') { |
|
| 535 | - $c[$champ] = $sinon; |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // N'accepter que les champs qui existent |
|
| 541 | - // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 542 | - $champs = []; |
|
| 543 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 544 | - if (isset($c[$champ])) { |
|
| 545 | - $champs[$champ] = $c[$champ]; |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - // Nettoyer les valeurs |
|
| 550 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 551 | - |
|
| 552 | - // Envoyer aux plugins |
|
| 553 | - $champs = pipeline( |
|
| 554 | - 'pre_edition', |
|
| 555 | - [ |
|
| 556 | - 'args' => [ |
|
| 557 | - 'table' => $spip_table_objet, // compatibilite |
|
| 558 | - 'table_objet' => $table_objet, |
|
| 559 | - 'spip_table_objet' => $spip_table_objet, |
|
| 560 | - 'type' => $type, |
|
| 561 | - 'id_objet' => $id, |
|
| 562 | - 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 563 | - 'action' => 'controler', |
|
| 564 | - 'serveur' => $serveur, |
|
| 565 | - ], |
|
| 566 | - 'data' => $champs |
|
| 567 | - ] |
|
| 568 | - ); |
|
| 569 | - |
|
| 570 | - if (!$champs) { |
|
| 571 | - return false; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 575 | - $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, $options['prefix'] ?? 'ctr_'); |
|
| 576 | - |
|
| 577 | - return $conflits; |
|
| 504 | + include_spip('inc/filtres'); |
|
| 505 | + |
|
| 506 | + $table_objet = table_objet($type); |
|
| 507 | + $spip_table_objet = table_objet_sql($type); |
|
| 508 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 509 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 510 | + |
|
| 511 | + // Appels incomplets (sans $c) |
|
| 512 | + if (!is_array($c)) { |
|
| 513 | + $c = []; |
|
| 514 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 515 | + if (_request($champ)) { |
|
| 516 | + $c[$champ] = _request($champ); |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 522 | + // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 523 | + // il faut passer par instituer_XX() |
|
| 524 | + // TODO: faut-il passer ces variables interdites |
|
| 525 | + // dans un fichier de description separe ? |
|
| 526 | + unset($c['statut']); |
|
| 527 | + unset($c['id_parent']); |
|
| 528 | + unset($c['id_rubrique']); |
|
| 529 | + unset($c['id_secteur']); |
|
| 530 | + |
|
| 531 | + // Gerer les champs non vides |
|
| 532 | + if (isset($options['nonvide']) && is_array($options['nonvide'])) { |
|
| 533 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 534 | + if ($c[$champ] === '') { |
|
| 535 | + $c[$champ] = $sinon; |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // N'accepter que les champs qui existent |
|
| 541 | + // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 542 | + $champs = []; |
|
| 543 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 544 | + if (isset($c[$champ])) { |
|
| 545 | + $champs[$champ] = $c[$champ]; |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + // Nettoyer les valeurs |
|
| 550 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 551 | + |
|
| 552 | + // Envoyer aux plugins |
|
| 553 | + $champs = pipeline( |
|
| 554 | + 'pre_edition', |
|
| 555 | + [ |
|
| 556 | + 'args' => [ |
|
| 557 | + 'table' => $spip_table_objet, // compatibilite |
|
| 558 | + 'table_objet' => $table_objet, |
|
| 559 | + 'spip_table_objet' => $spip_table_objet, |
|
| 560 | + 'type' => $type, |
|
| 561 | + 'id_objet' => $id, |
|
| 562 | + 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 563 | + 'action' => 'controler', |
|
| 564 | + 'serveur' => $serveur, |
|
| 565 | + ], |
|
| 566 | + 'data' => $champs |
|
| 567 | + ] |
|
| 568 | + ); |
|
| 569 | + |
|
| 570 | + if (!$champs) { |
|
| 571 | + return false; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 575 | + $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, $options['prefix'] ?? 'ctr_'); |
|
| 576 | + |
|
| 577 | + return $conflits; |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | |
@@ -604,66 +604,66 @@ discard block |
||
| 604 | 604 | * - post : le contenu posté |
| 605 | 605 | **/ |
| 606 | 606 | function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') { |
| 607 | - $spip_table_objet = table_objet_sql($type); |
|
| 608 | - $id_table_objet = id_table_objet($type); |
|
| 609 | - |
|
| 610 | - // Controle des MD5 envoyes |
|
| 611 | - // On elimine les donnees non modifiees par le formulaire (mais |
|
| 612 | - // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 613 | - foreach ($champs as $key => $val) { |
|
| 614 | - if ( |
|
| 615 | - isset($ctr[$prefix . $key]) |
|
| 616 | - && ($m = $ctr[$prefix . $key]) |
|
| 617 | - && (is_scalar($val) && $m == md5($val)) |
|
| 618 | - ) { |
|
| 619 | - unset($champs[$key]); |
|
| 620 | - } |
|
| 621 | - } |
|
| 622 | - if (!$champs) { |
|
| 623 | - return; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - // On veut savoir si notre modif va avoir un impact |
|
| 627 | - // par rapport aux donnees contenues dans la base |
|
| 628 | - // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 629 | - $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 630 | - $intact = true; |
|
| 631 | - foreach ($champs as $ch => $val) { |
|
| 632 | - $intact &= ($s[$ch] == $val); |
|
| 633 | - } |
|
| 634 | - if ($intact) { |
|
| 635 | - return; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - // Detection de conflits : |
|
| 639 | - // On verifie si notre modif ne provient pas d'un formulaire |
|
| 640 | - // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 641 | - // on compare a ce qui est dans la base, et on bloque en cas |
|
| 642 | - // de conflit. |
|
| 643 | - $ctrh = $ctrq = $conflits = []; |
|
| 644 | - foreach (array_keys($champs) as $key) { |
|
| 645 | - if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) { |
|
| 646 | - $ctrh[$key] = $m; |
|
| 647 | - $ctrq[] = $key; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - if ($ctrq) { |
|
| 651 | - $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 652 | - foreach ($ctrh as $key => $m) { |
|
| 653 | - if ( |
|
| 654 | - $m != md5((string) $ctrq[$key]) |
|
| 655 | - && $champs[$key] !== $ctrq[$key] |
|
| 656 | - ) { |
|
| 657 | - $conflits[$key] = [ |
|
| 658 | - 'base' => $ctrq[$key], |
|
| 659 | - 'post' => $champs[$key] |
|
| 660 | - ]; |
|
| 661 | - unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - return $conflits; |
|
| 607 | + $spip_table_objet = table_objet_sql($type); |
|
| 608 | + $id_table_objet = id_table_objet($type); |
|
| 609 | + |
|
| 610 | + // Controle des MD5 envoyes |
|
| 611 | + // On elimine les donnees non modifiees par le formulaire (mais |
|
| 612 | + // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 613 | + foreach ($champs as $key => $val) { |
|
| 614 | + if ( |
|
| 615 | + isset($ctr[$prefix . $key]) |
|
| 616 | + && ($m = $ctr[$prefix . $key]) |
|
| 617 | + && (is_scalar($val) && $m == md5($val)) |
|
| 618 | + ) { |
|
| 619 | + unset($champs[$key]); |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | + if (!$champs) { |
|
| 623 | + return; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + // On veut savoir si notre modif va avoir un impact |
|
| 627 | + // par rapport aux donnees contenues dans la base |
|
| 628 | + // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 629 | + $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 630 | + $intact = true; |
|
| 631 | + foreach ($champs as $ch => $val) { |
|
| 632 | + $intact &= ($s[$ch] == $val); |
|
| 633 | + } |
|
| 634 | + if ($intact) { |
|
| 635 | + return; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + // Detection de conflits : |
|
| 639 | + // On verifie si notre modif ne provient pas d'un formulaire |
|
| 640 | + // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 641 | + // on compare a ce qui est dans la base, et on bloque en cas |
|
| 642 | + // de conflit. |
|
| 643 | + $ctrh = $ctrq = $conflits = []; |
|
| 644 | + foreach (array_keys($champs) as $key) { |
|
| 645 | + if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) { |
|
| 646 | + $ctrh[$key] = $m; |
|
| 647 | + $ctrq[] = $key; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + if ($ctrq) { |
|
| 651 | + $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 652 | + foreach ($ctrh as $key => $m) { |
|
| 653 | + if ( |
|
| 654 | + $m != md5((string) $ctrq[$key]) |
|
| 655 | + && $champs[$key] !== $ctrq[$key] |
|
| 656 | + ) { |
|
| 657 | + $conflits[$key] = [ |
|
| 658 | + 'base' => $ctrq[$key], |
|
| 659 | + 'post' => $champs[$key] |
|
| 660 | + ]; |
|
| 661 | + unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + return $conflits; |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | /** |
@@ -675,9 +675,9 @@ discard block |
||
| 675 | 675 | * @return string |
| 676 | 676 | */ |
| 677 | 677 | function display_conflit_champ($x) { |
| 678 | - if (strstr($x, "\n") || strlen($x) > 80) { |
|
| 679 | - return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 680 | - } else { |
|
| 681 | - return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 682 | - } |
|
| 678 | + if (strstr($x, "\n") || strlen($x) > 80) { |
|
| 679 | + return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 680 | + } else { |
|
| 681 | + return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 682 | + } |
|
| 683 | 683 | } |
@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** l'adresse du repertoire de telechargement et de decompactage des plugins */ |
| 23 | 23 | if (!defined('_DIR_PLUGINS_AUTO')) { |
| 24 | - define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 24 | + define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins. |
@@ -46,27 +46,27 @@ discard block |
||
| 46 | 46 | * @return array |
| 47 | 47 | **/ |
| 48 | 48 | function liste_plugin_files($dir_plugins = null) { |
| 49 | - static $plugin_files = []; |
|
| 50 | - if (is_null($dir_plugins)) { |
|
| 51 | - $dir_plugins = _DIR_PLUGINS; |
|
| 52 | - } |
|
| 53 | - if ( |
|
| 54 | - !isset($plugin_files[$dir_plugins]) |
|
| 55 | - || (is_countable($plugin_files[$dir_plugins]) ? count($plugin_files[$dir_plugins]) : 0) == 0 |
|
| 56 | - ) { |
|
| 57 | - $plugin_files[$dir_plugins] = []; |
|
| 58 | - foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 59 | - $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - sort($plugin_files[$dir_plugins]); |
|
| 63 | - // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 64 | - // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 65 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 66 | - $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - return $plugin_files[$dir_plugins]; |
|
| 49 | + static $plugin_files = []; |
|
| 50 | + if (is_null($dir_plugins)) { |
|
| 51 | + $dir_plugins = _DIR_PLUGINS; |
|
| 52 | + } |
|
| 53 | + if ( |
|
| 54 | + !isset($plugin_files[$dir_plugins]) |
|
| 55 | + || (is_countable($plugin_files[$dir_plugins]) ? count($plugin_files[$dir_plugins]) : 0) == 0 |
|
| 56 | + ) { |
|
| 57 | + $plugin_files[$dir_plugins] = []; |
|
| 58 | + foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 59 | + $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + sort($plugin_files[$dir_plugins]); |
|
| 63 | + // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 64 | + // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 65 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 66 | + $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + return $plugin_files[$dir_plugins]; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -82,44 +82,44 @@ discard block |
||
| 82 | 82 | * Liste complète des répeertoires |
| 83 | 83 | **/ |
| 84 | 84 | function fast_find_plugin_dirs($dir, $max_prof = 100) { |
| 85 | - $fichiers = []; |
|
| 86 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 87 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 88 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 89 | - if ($dir == '') { |
|
| 90 | - $dir = '.'; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - if (!is_dir($dir)) { |
|
| 94 | - return $fichiers; |
|
| 95 | - } |
|
| 96 | - if (is_plugin_dir($dir, '')) { |
|
| 97 | - $fichiers[] = $dir; |
|
| 98 | - |
|
| 99 | - return $fichiers; |
|
| 100 | - } |
|
| 101 | - if ($max_prof <= 0) { |
|
| 102 | - return $fichiers; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $subdirs = []; |
|
| 106 | - if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 107 | - while (($f = readdir($d)) !== false) { |
|
| 108 | - if ( |
|
| 109 | - $f[0] != '.' |
|
| 110 | - && is_dir($f = "$dir/$f") |
|
| 111 | - ) { |
|
| 112 | - $subdirs[] = $f; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - closedir($d); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - foreach ($subdirs as $d) { |
|
| 119 | - $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return $fichiers; |
|
| 85 | + $fichiers = []; |
|
| 86 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 87 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 88 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 89 | + if ($dir == '') { |
|
| 90 | + $dir = '.'; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + if (!is_dir($dir)) { |
|
| 94 | + return $fichiers; |
|
| 95 | + } |
|
| 96 | + if (is_plugin_dir($dir, '')) { |
|
| 97 | + $fichiers[] = $dir; |
|
| 98 | + |
|
| 99 | + return $fichiers; |
|
| 100 | + } |
|
| 101 | + if ($max_prof <= 0) { |
|
| 102 | + return $fichiers; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $subdirs = []; |
|
| 106 | + if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 107 | + while (($f = readdir($d)) !== false) { |
|
| 108 | + if ( |
|
| 109 | + $f[0] != '.' |
|
| 110 | + && is_dir($f = "$dir/$f") |
|
| 111 | + ) { |
|
| 112 | + $subdirs[] = $f; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + closedir($d); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + foreach ($subdirs as $d) { |
|
| 119 | + $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return $fichiers; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -140,27 +140,27 @@ discard block |
||
| 140 | 140 | **/ |
| 141 | 141 | function is_plugin_dir($dir, $dir_plugins = null) { |
| 142 | 142 | |
| 143 | - if (is_array($dir)) { |
|
| 144 | - foreach ($dir as $k => $d) { |
|
| 145 | - if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 146 | - unset($dir[$k]); |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $dir; |
|
| 151 | - } |
|
| 152 | - if (is_null($dir_plugins)) { |
|
| 153 | - $dir_plugins = _DIR_PLUGINS; |
|
| 154 | - } |
|
| 155 | - $search = ["$dir_plugins$dir/paquet.xml"]; |
|
| 156 | - |
|
| 157 | - foreach ($search as $s) { |
|
| 158 | - if (file_exists($s)) { |
|
| 159 | - return $dir; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return ''; |
|
| 143 | + if (is_array($dir)) { |
|
| 144 | + foreach ($dir as $k => $d) { |
|
| 145 | + if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 146 | + unset($dir[$k]); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $dir; |
|
| 151 | + } |
|
| 152 | + if (is_null($dir_plugins)) { |
|
| 153 | + $dir_plugins = _DIR_PLUGINS; |
|
| 154 | + } |
|
| 155 | + $search = ["$dir_plugins$dir/paquet.xml"]; |
|
| 156 | + |
|
| 157 | + foreach ($search as $s) { |
|
| 158 | + if (file_exists($s)) { |
|
| 159 | + return $dir; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return ''; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** Regexp d'extraction des informations d'un intervalle de compatibilité */ |
@@ -187,51 +187,51 @@ discard block |
||
| 187 | 187 | **/ |
| 188 | 188 | function plugin_version_compatible($intervalle, $version, $avec_quoi = '') { |
| 189 | 189 | |
| 190 | - if (!strlen($intervalle)) { |
|
| 191 | - return true; |
|
| 192 | - } |
|
| 193 | - if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 194 | - return false; |
|
| 195 | - } |
|
| 196 | - // Extraction des bornes et traitement de * pour la borne sup : |
|
| 197 | - // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 198 | - $minimum = $regs[1]; |
|
| 199 | - $maximum = $regs[2]; |
|
| 200 | - |
|
| 201 | - // si une version SPIP de compatibilité a été définie (dans |
|
| 202 | - // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 203 | - // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 204 | - // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 205 | - // entre plugins) |
|
| 206 | - if (defined('_DEV_VERSION_SPIP_COMPAT') && $avec_quoi == 'spip' && $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 207 | - if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 208 | - return true; |
|
| 209 | - } |
|
| 210 | - // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 211 | - // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $minimum_inc = $intervalle[0] == '['; |
|
| 215 | - $maximum_inc = str_ends_with($intervalle, ']'); |
|
| 216 | - |
|
| 217 | - if (strlen($minimum)) { |
|
| 218 | - if ($minimum_inc && spip_version_compare($version, $minimum, '<')) { |
|
| 219 | - return false; |
|
| 220 | - } |
|
| 221 | - if (!$minimum_inc && spip_version_compare($version, $minimum, '<=')) { |
|
| 222 | - return false; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - if (strlen($maximum)) { |
|
| 226 | - if ($maximum_inc && spip_version_compare($version, $maximum, '>')) { |
|
| 227 | - return false; |
|
| 228 | - } |
|
| 229 | - if (!$maximum_inc && spip_version_compare($version, $maximum, '>=')) { |
|
| 230 | - return false; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - return true; |
|
| 190 | + if (!strlen($intervalle)) { |
|
| 191 | + return true; |
|
| 192 | + } |
|
| 193 | + if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + // Extraction des bornes et traitement de * pour la borne sup : |
|
| 197 | + // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 198 | + $minimum = $regs[1]; |
|
| 199 | + $maximum = $regs[2]; |
|
| 200 | + |
|
| 201 | + // si une version SPIP de compatibilité a été définie (dans |
|
| 202 | + // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 203 | + // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 204 | + // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 205 | + // entre plugins) |
|
| 206 | + if (defined('_DEV_VERSION_SPIP_COMPAT') && $avec_quoi == 'spip' && $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 207 | + if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 208 | + return true; |
|
| 209 | + } |
|
| 210 | + // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 211 | + // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $minimum_inc = $intervalle[0] == '['; |
|
| 215 | + $maximum_inc = str_ends_with($intervalle, ']'); |
|
| 216 | + |
|
| 217 | + if (strlen($minimum)) { |
|
| 218 | + if ($minimum_inc && spip_version_compare($version, $minimum, '<')) { |
|
| 219 | + return false; |
|
| 220 | + } |
|
| 221 | + if (!$minimum_inc && spip_version_compare($version, $minimum, '<=')) { |
|
| 222 | + return false; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + if (strlen($maximum)) { |
|
| 226 | + if ($maximum_inc && spip_version_compare($version, $maximum, '>')) { |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 229 | + if (!$maximum_inc && spip_version_compare($version, $maximum, '>=')) { |
|
| 230 | + return false; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + return true; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -248,62 +248,62 @@ discard block |
||
| 248 | 248 | * @return array |
| 249 | 249 | */ |
| 250 | 250 | function liste_plugin_valides($liste_plug, $force = false) { |
| 251 | - $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 252 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 253 | - $infos = [ |
|
| 254 | - // lister les extensions qui sont automatiquement actives |
|
| 255 | - '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 256 | - '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 257 | - ]; |
|
| 258 | - |
|
| 259 | - // creer une premiere liste non ordonnee mais qui ne retient |
|
| 260 | - // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 261 | - $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 262 | - $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 263 | - $infos['_DIR_RESTREINT']['SPIP']['chemin'] = []; |
|
| 264 | - $liste_non_classee = [ |
|
| 265 | - 'SPIP' => [ |
|
| 266 | - 'nom' => 'SPIP', |
|
| 267 | - 'etat' => 'stable', |
|
| 268 | - 'version' => $GLOBALS['spip_version_branche'], |
|
| 269 | - 'dir_type' => '_DIR_RESTREINT', |
|
| 270 | - 'dir' => '', |
|
| 271 | - ] |
|
| 272 | - ]; |
|
| 273 | - |
|
| 274 | - $invalides = []; |
|
| 275 | - foreach ($liste_ext as $plug) { |
|
| 276 | - if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 277 | - plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - foreach ($liste_plug as $plug) { |
|
| 281 | - if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 282 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 283 | - if (is_array($r)) { |
|
| 284 | - $invalides = array_merge($invalides, $r); |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 290 | - $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 291 | - foreach ($liste_plug as $plug) { |
|
| 292 | - if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 293 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 294 | - if (is_array($r)) { |
|
| 295 | - $invalides = array_merge($invalides, $r); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - plugin_fixer_procure($liste_non_classee, $infos); |
|
| 302 | - |
|
| 303 | - // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 304 | - $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 305 | - |
|
| 306 | - return [$infos, $liste_non_classee, $invalides]; |
|
| 251 | + $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 252 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 253 | + $infos = [ |
|
| 254 | + // lister les extensions qui sont automatiquement actives |
|
| 255 | + '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 256 | + '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 257 | + ]; |
|
| 258 | + |
|
| 259 | + // creer une premiere liste non ordonnee mais qui ne retient |
|
| 260 | + // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 261 | + $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 262 | + $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 263 | + $infos['_DIR_RESTREINT']['SPIP']['chemin'] = []; |
|
| 264 | + $liste_non_classee = [ |
|
| 265 | + 'SPIP' => [ |
|
| 266 | + 'nom' => 'SPIP', |
|
| 267 | + 'etat' => 'stable', |
|
| 268 | + 'version' => $GLOBALS['spip_version_branche'], |
|
| 269 | + 'dir_type' => '_DIR_RESTREINT', |
|
| 270 | + 'dir' => '', |
|
| 271 | + ] |
|
| 272 | + ]; |
|
| 273 | + |
|
| 274 | + $invalides = []; |
|
| 275 | + foreach ($liste_ext as $plug) { |
|
| 276 | + if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 277 | + plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + foreach ($liste_plug as $plug) { |
|
| 281 | + if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 282 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 283 | + if (is_array($r)) { |
|
| 284 | + $invalides = array_merge($invalides, $r); |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 290 | + $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 291 | + foreach ($liste_plug as $plug) { |
|
| 292 | + if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 293 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 294 | + if (is_array($r)) { |
|
| 295 | + $invalides = array_merge($invalides, $r); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + plugin_fixer_procure($liste_non_classee, $infos); |
|
| 302 | + |
|
| 303 | + // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 304 | + $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 305 | + |
|
| 306 | + return [$infos, $liste_non_classee, $invalides]; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -323,37 +323,37 @@ discard block |
||
| 323 | 323 | * array description short si on ne le retient pas (pour memorisation dans une table des erreurs) |
| 324 | 324 | */ |
| 325 | 325 | function plugin_valide_resume(&$liste, $plug, $infos, $dir_type) { |
| 326 | - $i = $infos[$dir_type][$plug]; |
|
| 327 | - // minimum syndical pour afficher si le xml avait des erreurs éventuelles |
|
| 328 | - $short_desc = [ |
|
| 329 | - 'dir' => $plug, |
|
| 330 | - 'dir_type' => $dir_type |
|
| 331 | - ]; |
|
| 332 | - if (empty($i['prefix'])) { |
|
| 333 | - // erreur xml ? mais sans connaissance du prefix, on retourne le chemin… |
|
| 334 | - $short_desc['erreur'] = $i['erreur'] ?? ['?']; |
|
| 335 | - return [$plug => $short_desc]; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $p = strtoupper($i['prefix']); |
|
| 339 | - $short_desc['nom'] = $i['nom']; |
|
| 340 | - $short_desc['etat'] = $i['etat']; |
|
| 341 | - $short_desc['version'] = $i['version']; |
|
| 342 | - |
|
| 343 | - if (isset($i['erreur']) && $i['erreur']) { |
|
| 344 | - $short_desc['erreur'] = $i['erreur']; |
|
| 345 | - return [$p => $short_desc]; |
|
| 346 | - } |
|
| 347 | - if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 348 | - return [$p => $short_desc]; |
|
| 349 | - } |
|
| 350 | - if ( |
|
| 351 | - !isset($liste[$p]) || spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 352 | - ) { |
|
| 353 | - $liste[$p] = $short_desc; |
|
| 354 | - } |
|
| 355 | - // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 356 | - return $p; |
|
| 326 | + $i = $infos[$dir_type][$plug]; |
|
| 327 | + // minimum syndical pour afficher si le xml avait des erreurs éventuelles |
|
| 328 | + $short_desc = [ |
|
| 329 | + 'dir' => $plug, |
|
| 330 | + 'dir_type' => $dir_type |
|
| 331 | + ]; |
|
| 332 | + if (empty($i['prefix'])) { |
|
| 333 | + // erreur xml ? mais sans connaissance du prefix, on retourne le chemin… |
|
| 334 | + $short_desc['erreur'] = $i['erreur'] ?? ['?']; |
|
| 335 | + return [$plug => $short_desc]; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + $p = strtoupper($i['prefix']); |
|
| 339 | + $short_desc['nom'] = $i['nom']; |
|
| 340 | + $short_desc['etat'] = $i['etat']; |
|
| 341 | + $short_desc['version'] = $i['version']; |
|
| 342 | + |
|
| 343 | + if (isset($i['erreur']) && $i['erreur']) { |
|
| 344 | + $short_desc['erreur'] = $i['erreur']; |
|
| 345 | + return [$p => $short_desc]; |
|
| 346 | + } |
|
| 347 | + if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 348 | + return [$p => $short_desc]; |
|
| 349 | + } |
|
| 350 | + if ( |
|
| 351 | + !isset($liste[$p]) || spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 352 | + ) { |
|
| 353 | + $liste[$p] = $short_desc; |
|
| 354 | + } |
|
| 355 | + // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 356 | + return $p; |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -369,47 +369,47 @@ discard block |
||
| 369 | 369 | * @param array $infos |
| 370 | 370 | */ |
| 371 | 371 | function plugin_fixer_procure(&$liste, &$infos) { |
| 372 | - foreach ($liste as $p => $resume) { |
|
| 373 | - $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 374 | - if (isset($i['procure']) && $i['procure']) { |
|
| 375 | - foreach ($i['procure'] as $procure) { |
|
| 376 | - $p = strtoupper($procure['nom']); |
|
| 377 | - $dir = $resume['dir']; |
|
| 378 | - if ($dir) { |
|
| 379 | - $dir .= '/'; |
|
| 380 | - } |
|
| 381 | - $dir .= 'procure:' . $procure['nom']; |
|
| 382 | - |
|
| 383 | - $procure['etat'] = '?'; |
|
| 384 | - $procure['dir_type'] = $resume['dir_type']; |
|
| 385 | - $procure['dir'] = $dir; |
|
| 386 | - |
|
| 387 | - // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 388 | - // on ajoute cette version a la liste |
|
| 389 | - if ( |
|
| 390 | - !isset($liste[$p]) |
|
| 391 | - || spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 392 | - ) { |
|
| 393 | - $liste[$p] = $procure; |
|
| 394 | - |
|
| 395 | - // on fournit une information minimale pour ne pas perturber la compilation |
|
| 396 | - $infos[$resume['dir_type']][$dir] = [ |
|
| 397 | - 'prefix' => $procure['nom'], |
|
| 398 | - 'nom' => $procure['nom'], |
|
| 399 | - 'etat' => $procure['etat'], |
|
| 400 | - 'version' => $procure['version'], |
|
| 401 | - 'chemin' => [], |
|
| 402 | - 'necessite' => [], |
|
| 403 | - 'utilise' => [], |
|
| 404 | - 'lib' => [], |
|
| 405 | - 'menu' => [], |
|
| 406 | - 'onglet' => [], |
|
| 407 | - 'procure' => [], |
|
| 408 | - ]; |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - } |
|
| 372 | + foreach ($liste as $p => $resume) { |
|
| 373 | + $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 374 | + if (isset($i['procure']) && $i['procure']) { |
|
| 375 | + foreach ($i['procure'] as $procure) { |
|
| 376 | + $p = strtoupper($procure['nom']); |
|
| 377 | + $dir = $resume['dir']; |
|
| 378 | + if ($dir) { |
|
| 379 | + $dir .= '/'; |
|
| 380 | + } |
|
| 381 | + $dir .= 'procure:' . $procure['nom']; |
|
| 382 | + |
|
| 383 | + $procure['etat'] = '?'; |
|
| 384 | + $procure['dir_type'] = $resume['dir_type']; |
|
| 385 | + $procure['dir'] = $dir; |
|
| 386 | + |
|
| 387 | + // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 388 | + // on ajoute cette version a la liste |
|
| 389 | + if ( |
|
| 390 | + !isset($liste[$p]) |
|
| 391 | + || spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 392 | + ) { |
|
| 393 | + $liste[$p] = $procure; |
|
| 394 | + |
|
| 395 | + // on fournit une information minimale pour ne pas perturber la compilation |
|
| 396 | + $infos[$resume['dir_type']][$dir] = [ |
|
| 397 | + 'prefix' => $procure['nom'], |
|
| 398 | + 'nom' => $procure['nom'], |
|
| 399 | + 'etat' => $procure['etat'], |
|
| 400 | + 'version' => $procure['version'], |
|
| 401 | + 'chemin' => [], |
|
| 402 | + 'necessite' => [], |
|
| 403 | + 'utilise' => [], |
|
| 404 | + 'lib' => [], |
|
| 405 | + 'menu' => [], |
|
| 406 | + 'onglet' => [], |
|
| 407 | + 'procure' => [], |
|
| 408 | + ]; |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * @return array |
| 424 | 424 | */ |
| 425 | 425 | function liste_chemin_plugin($liste, $dir_plugins = _DIR_PLUGINS) { |
| 426 | - foreach ($liste as $prefix => $infos) { |
|
| 427 | - if ( |
|
| 428 | - !$dir_plugins || defined($infos['dir_type']) && constant($infos['dir_type']) == $dir_plugins |
|
| 429 | - ) { |
|
| 430 | - $liste[$prefix] = $infos['dir']; |
|
| 431 | - } else { |
|
| 432 | - unset($liste[$prefix]); |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return $liste; |
|
| 426 | + foreach ($liste as $prefix => $infos) { |
|
| 427 | + if ( |
|
| 428 | + !$dir_plugins || defined($infos['dir_type']) && constant($infos['dir_type']) == $dir_plugins |
|
| 429 | + ) { |
|
| 430 | + $liste[$prefix] = $infos['dir']; |
|
| 431 | + } else { |
|
| 432 | + unset($liste[$prefix]); |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return $liste; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | /** |
@@ -448,9 +448,9 @@ discard block |
||
| 448 | 448 | * @return array |
| 449 | 449 | */ |
| 450 | 450 | function liste_chemin_plugin_actifs($dir_plugins = _DIR_PLUGINS) { |
| 451 | - include_spip('plugins/installer'); |
|
| 451 | + include_spip('plugins/installer'); |
|
| 452 | 452 | |
| 453 | - return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 453 | + return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /** |
@@ -481,53 +481,53 @@ discard block |
||
| 481 | 481 | * qui n'ont pas satisfait leurs dépendances |
| 482 | 482 | **/ |
| 483 | 483 | function plugin_trier($infos, $liste_non_classee) { |
| 484 | - $toute_la_liste = $liste_non_classee; |
|
| 485 | - $liste = $ordre = []; |
|
| 486 | - $count = 0; |
|
| 487 | - |
|
| 488 | - while (($c = count($liste_non_classee)) && $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 489 | - #echo "tour::";var_dump($liste_non_classee); |
|
| 490 | - $count = $c; |
|
| 491 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 492 | - $plug = $resume['dir']; |
|
| 493 | - $dir_type = $resume['dir_type']; |
|
| 494 | - $info1 = $infos[$dir_type][$plug]; |
|
| 495 | - // si des plugins sont necessaires, |
|
| 496 | - // on ne peut inserer qu'apres eux |
|
| 497 | - foreach ($info1['necessite'] as $need) { |
|
| 498 | - $nom = strtoupper($need['nom']); |
|
| 499 | - $compat = $need['compatibilite'] ?? ''; |
|
| 500 | - if (!isset($liste[$nom]) || !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 501 | - $info1 = false; |
|
| 502 | - break; |
|
| 503 | - } |
|
| 504 | - } |
|
| 505 | - if (!$info1) { |
|
| 506 | - continue; |
|
| 507 | - } |
|
| 508 | - // idem si des plugins sont utiles, |
|
| 509 | - // sauf si ils sont de toute facon absents de la liste |
|
| 510 | - foreach ($info1['utilise'] as $need) { |
|
| 511 | - $nom = strtoupper($need['nom']); |
|
| 512 | - $compat = $need['compatibilite'] ?? ''; |
|
| 513 | - if (isset($toute_la_liste[$nom])) { |
|
| 514 | - if ( |
|
| 515 | - !isset($liste[$nom]) || !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 516 | - ) { |
|
| 517 | - $info1 = false; |
|
| 518 | - break; |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - if ($info1) { |
|
| 523 | - $ordre[$p] = $info1; |
|
| 524 | - $liste[$p] = $liste_non_classee[$p]; |
|
| 525 | - unset($liste_non_classee[$p]); |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - return [$liste, $ordre, $liste_non_classee]; |
|
| 484 | + $toute_la_liste = $liste_non_classee; |
|
| 485 | + $liste = $ordre = []; |
|
| 486 | + $count = 0; |
|
| 487 | + |
|
| 488 | + while (($c = count($liste_non_classee)) && $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 489 | + #echo "tour::";var_dump($liste_non_classee); |
|
| 490 | + $count = $c; |
|
| 491 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 492 | + $plug = $resume['dir']; |
|
| 493 | + $dir_type = $resume['dir_type']; |
|
| 494 | + $info1 = $infos[$dir_type][$plug]; |
|
| 495 | + // si des plugins sont necessaires, |
|
| 496 | + // on ne peut inserer qu'apres eux |
|
| 497 | + foreach ($info1['necessite'] as $need) { |
|
| 498 | + $nom = strtoupper($need['nom']); |
|
| 499 | + $compat = $need['compatibilite'] ?? ''; |
|
| 500 | + if (!isset($liste[$nom]) || !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 501 | + $info1 = false; |
|
| 502 | + break; |
|
| 503 | + } |
|
| 504 | + } |
|
| 505 | + if (!$info1) { |
|
| 506 | + continue; |
|
| 507 | + } |
|
| 508 | + // idem si des plugins sont utiles, |
|
| 509 | + // sauf si ils sont de toute facon absents de la liste |
|
| 510 | + foreach ($info1['utilise'] as $need) { |
|
| 511 | + $nom = strtoupper($need['nom']); |
|
| 512 | + $compat = $need['compatibilite'] ?? ''; |
|
| 513 | + if (isset($toute_la_liste[$nom])) { |
|
| 514 | + if ( |
|
| 515 | + !isset($liste[$nom]) || !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 516 | + ) { |
|
| 517 | + $info1 = false; |
|
| 518 | + break; |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + if ($info1) { |
|
| 523 | + $ordre[$p] = $info1; |
|
| 524 | + $liste[$p] = $liste_non_classee[$p]; |
|
| 525 | + unset($liste_non_classee[$p]); |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + return [$liste, $ordre, $liste_non_classee]; |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | /** |
@@ -544,40 +544,40 @@ discard block |
||
| 544 | 544 | * Répertoire (plugins, plugins-dist, ...) => Couples (prefixes => infos completes) des plugins qu'ils contiennent |
| 545 | 545 | **/ |
| 546 | 546 | function plugins_erreurs($liste_non_classee, $liste, $infos, $msg = []) { |
| 547 | - static $erreurs = []; |
|
| 548 | - |
|
| 549 | - if (!is_array($liste)) { |
|
| 550 | - $liste = []; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 554 | - $liste = array_diff_key($liste, $liste_non_classee); |
|
| 555 | - |
|
| 556 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 557 | - $dir_type = $resume['dir_type']; |
|
| 558 | - $plug = $resume['dir']; |
|
| 559 | - $k = $infos[$dir_type][$plug]; |
|
| 560 | - |
|
| 561 | - $plug = constant($dir_type) . $plug; |
|
| 562 | - if (!isset($msg[$p])) { |
|
| 563 | - if (isset($resume['erreur']) && $resume['erreur']) { |
|
| 564 | - $msg[$p] = [$resume['erreur']]; |
|
| 565 | - } |
|
| 566 | - elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 567 | - $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
|
| 568 | - } |
|
| 569 | - elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 570 | - $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 571 | - } |
|
| 572 | - } else { |
|
| 573 | - foreach ($msg[$p] as $c => $l) { |
|
| 574 | - $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - $erreurs[$plug] = $msg[$p]; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 547 | + static $erreurs = []; |
|
| 548 | + |
|
| 549 | + if (!is_array($liste)) { |
|
| 550 | + $liste = []; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 554 | + $liste = array_diff_key($liste, $liste_non_classee); |
|
| 555 | + |
|
| 556 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 557 | + $dir_type = $resume['dir_type']; |
|
| 558 | + $plug = $resume['dir']; |
|
| 559 | + $k = $infos[$dir_type][$plug]; |
|
| 560 | + |
|
| 561 | + $plug = constant($dir_type) . $plug; |
|
| 562 | + if (!isset($msg[$p])) { |
|
| 563 | + if (isset($resume['erreur']) && $resume['erreur']) { |
|
| 564 | + $msg[$p] = [$resume['erreur']]; |
|
| 565 | + } |
|
| 566 | + elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 567 | + $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
|
| 568 | + } |
|
| 569 | + elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 570 | + $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 571 | + } |
|
| 572 | + } else { |
|
| 573 | + foreach ($msg[$p] as $c => $l) { |
|
| 574 | + $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + $erreurs[$plug] = $msg[$p]; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | /** |
@@ -592,25 +592,25 @@ discard block |
||
| 592 | 592 | * - Liste des erreurs ou code HTML des erreurs |
| 593 | 593 | **/ |
| 594 | 594 | function plugin_donne_erreurs($raw = false, $raz = true) { |
| 595 | - if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 596 | - return $raw ? [] : ''; |
|
| 597 | - } |
|
| 598 | - $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 599 | - // Compat ancienne version |
|
| 600 | - if (!$list) { |
|
| 601 | - $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 602 | - } elseif (!$raw) { |
|
| 603 | - foreach ($list as $plug => $msg) { |
|
| 604 | - $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 605 | - . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 606 | - } |
|
| 607 | - $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 608 | - } |
|
| 609 | - if ($raz) { |
|
| 610 | - effacer_meta('plugin_erreur_activation'); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - return $list; |
|
| 595 | + if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 596 | + return $raw ? [] : ''; |
|
| 597 | + } |
|
| 598 | + $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 599 | + // Compat ancienne version |
|
| 600 | + if (!$list) { |
|
| 601 | + $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 602 | + } elseif (!$raw) { |
|
| 603 | + foreach ($list as $plug => $msg) { |
|
| 604 | + $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 605 | + . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 606 | + } |
|
| 607 | + $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 608 | + } |
|
| 609 | + if ($raz) { |
|
| 610 | + effacer_meta('plugin_erreur_activation'); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + return $list; |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -630,21 +630,21 @@ discard block |
||
| 630 | 630 | * |
| 631 | 631 | **/ |
| 632 | 632 | function plugin_necessite($n, $liste, $balise = 'necessite') { |
| 633 | - $msg = []; |
|
| 634 | - foreach ($n as $need) { |
|
| 635 | - $id = strtoupper($need['nom']); |
|
| 636 | - $r = plugin_controler_necessite( |
|
| 637 | - $liste, |
|
| 638 | - $id, |
|
| 639 | - $need['compatibilite'] ?? '', |
|
| 640 | - $balise |
|
| 641 | - ); |
|
| 642 | - if ($r) { |
|
| 643 | - $msg[] = $r; |
|
| 644 | - } |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - return $msg; |
|
| 633 | + $msg = []; |
|
| 634 | + foreach ($n as $need) { |
|
| 635 | + $id = strtoupper($need['nom']); |
|
| 636 | + $r = plugin_controler_necessite( |
|
| 637 | + $liste, |
|
| 638 | + $id, |
|
| 639 | + $need['compatibilite'] ?? '', |
|
| 640 | + $balise |
|
| 641 | + ); |
|
| 642 | + if ($r) { |
|
| 643 | + $msg[] = $r; |
|
| 644 | + } |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + return $msg; |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | /** |
@@ -666,19 +666,19 @@ discard block |
||
| 666 | 666 | * Message d'erreur lorsque la dépendance est absente. |
| 667 | 667 | **/ |
| 668 | 668 | function plugin_controler_necessite($liste, $nom, $intervalle, $balise) { |
| 669 | - if (isset($liste[$nom]) && plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 670 | - return ''; |
|
| 671 | - } |
|
| 672 | - // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 673 | - if ($balise === 'utilise' && !isset($liste[$nom])) { |
|
| 674 | - return ''; |
|
| 675 | - } |
|
| 676 | - return plugin_message_incompatibilite( |
|
| 677 | - $intervalle, |
|
| 678 | - (isset($liste[$nom]) ? $liste[$nom]['version'] : ''), |
|
| 679 | - $nom, |
|
| 680 | - $balise |
|
| 681 | - ); |
|
| 669 | + if (isset($liste[$nom]) && plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 670 | + return ''; |
|
| 671 | + } |
|
| 672 | + // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 673 | + if ($balise === 'utilise' && !isset($liste[$nom])) { |
|
| 674 | + return ''; |
|
| 675 | + } |
|
| 676 | + return plugin_message_incompatibilite( |
|
| 677 | + $intervalle, |
|
| 678 | + (isset($liste[$nom]) ? $liste[$nom]['version'] : ''), |
|
| 679 | + $nom, |
|
| 680 | + $balise |
|
| 681 | + ); |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | /** |
@@ -695,70 +695,70 @@ discard block |
||
| 695 | 695 | */ |
| 696 | 696 | function plugin_message_incompatibilite($intervalle, $version, $nom, $balise) { |
| 697 | 697 | |
| 698 | - // prendre en compte les erreurs de dépendances à PHP |
|
| 699 | - // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 700 | - $type = 'plugin'; |
|
| 701 | - if ($nom === 'SPIP') { |
|
| 702 | - $type = 'spip'; |
|
| 703 | - } elseif ($nom === 'PHP') { |
|
| 704 | - $type = 'php'; |
|
| 705 | - } elseif (str_starts_with($nom, 'PHP:')) { |
|
| 706 | - $type = 'extension_php'; |
|
| 707 | - [, $nom] = explode(':', $nom, 2); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 711 | - $minimum = $regs[1]; |
|
| 712 | - $maximum = $regs[2]; |
|
| 713 | - |
|
| 714 | - $minimum_inclus = $intervalle[0] == '['; |
|
| 715 | - $maximum_inclus = str_ends_with($intervalle, ']'); |
|
| 716 | - |
|
| 717 | - if (strlen($minimum)) { |
|
| 718 | - if ($minimum_inclus && spip_version_compare($version, $minimum, '<')) { |
|
| 719 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 720 | - 'plugin' => $nom, |
|
| 721 | - 'version' => ' ≥ ' . $minimum |
|
| 722 | - ]); |
|
| 723 | - } |
|
| 724 | - if (!$minimum_inclus && spip_version_compare($version, $minimum, '<=')) { |
|
| 725 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 726 | - 'plugin' => $nom, |
|
| 727 | - 'version' => ' > ' . $minimum |
|
| 728 | - ]); |
|
| 729 | - } |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - if (strlen($maximum)) { |
|
| 733 | - if ($maximum_inclus && spip_version_compare($version, $maximum, '>')) { |
|
| 734 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 735 | - 'plugin' => $nom, |
|
| 736 | - 'version' => ' ≤ ' . $maximum |
|
| 737 | - ]); |
|
| 738 | - } |
|
| 739 | - if (!$maximum_inclus && spip_version_compare($version, $maximum, '>=')) { |
|
| 740 | - return _T("plugin_{$balise}_plugin", [ |
|
| 741 | - 'plugin' => $nom, |
|
| 742 | - 'version' => ' < ' . $maximum |
|
| 743 | - ]); |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - // note : il ne peut pas y avoir d'erreur sur |
|
| 749 | - // - un 'utilise' sans version. |
|
| 750 | - // - un 'php' sans version. |
|
| 751 | - return _T("plugin_necessite_{$type}_sans_version", ['plugin' => $nom]); |
|
| 698 | + // prendre en compte les erreurs de dépendances à PHP |
|
| 699 | + // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 700 | + $type = 'plugin'; |
|
| 701 | + if ($nom === 'SPIP') { |
|
| 702 | + $type = 'spip'; |
|
| 703 | + } elseif ($nom === 'PHP') { |
|
| 704 | + $type = 'php'; |
|
| 705 | + } elseif (str_starts_with($nom, 'PHP:')) { |
|
| 706 | + $type = 'extension_php'; |
|
| 707 | + [, $nom] = explode(':', $nom, 2); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 711 | + $minimum = $regs[1]; |
|
| 712 | + $maximum = $regs[2]; |
|
| 713 | + |
|
| 714 | + $minimum_inclus = $intervalle[0] == '['; |
|
| 715 | + $maximum_inclus = str_ends_with($intervalle, ']'); |
|
| 716 | + |
|
| 717 | + if (strlen($minimum)) { |
|
| 718 | + if ($minimum_inclus && spip_version_compare($version, $minimum, '<')) { |
|
| 719 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 720 | + 'plugin' => $nom, |
|
| 721 | + 'version' => ' ≥ ' . $minimum |
|
| 722 | + ]); |
|
| 723 | + } |
|
| 724 | + if (!$minimum_inclus && spip_version_compare($version, $minimum, '<=')) { |
|
| 725 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 726 | + 'plugin' => $nom, |
|
| 727 | + 'version' => ' > ' . $minimum |
|
| 728 | + ]); |
|
| 729 | + } |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + if (strlen($maximum)) { |
|
| 733 | + if ($maximum_inclus && spip_version_compare($version, $maximum, '>')) { |
|
| 734 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 735 | + 'plugin' => $nom, |
|
| 736 | + 'version' => ' ≤ ' . $maximum |
|
| 737 | + ]); |
|
| 738 | + } |
|
| 739 | + if (!$maximum_inclus && spip_version_compare($version, $maximum, '>=')) { |
|
| 740 | + return _T("plugin_{$balise}_plugin", [ |
|
| 741 | + 'plugin' => $nom, |
|
| 742 | + 'version' => ' < ' . $maximum |
|
| 743 | + ]); |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + // note : il ne peut pas y avoir d'erreur sur |
|
| 749 | + // - un 'utilise' sans version. |
|
| 750 | + // - un 'php' sans version. |
|
| 751 | + return _T("plugin_necessite_{$type}_sans_version", ['plugin' => $nom]); |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | |
| 755 | 755 | function plugin_controler_lib($lib, $url) { |
| 756 | - /* Feature sortie du core, voir STP |
|
| 756 | + /* Feature sortie du core, voir STP |
|
| 757 | 757 | * if ($url) { |
| 758 | 758 | include_spip('inc/charger_plugin'); |
| 759 | 759 | $url = '<br />' . bouton_telechargement_plugin($url, 'lib'); |
| 760 | 760 | }*/ |
| 761 | - return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 761 | + return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | * true si il y a eu des modifications sur la liste des plugins actifs, false sinon |
| 774 | 774 | **/ |
| 775 | 775 | function actualise_plugins_actifs($pipe_recherche = false) { |
| 776 | - return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 776 | + return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | |
@@ -800,115 +800,115 @@ discard block |
||
| 800 | 800 | **/ |
| 801 | 801 | function ecrire_plugin_actifs($plugin, $pipe_recherche = false, $operation = 'raz') { |
| 802 | 802 | |
| 803 | - // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 804 | - $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 805 | - |
|
| 806 | - // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 807 | - if (!$cache && !spip_connect()) { |
|
| 808 | - return false; |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - if ($operation != 'raz') { |
|
| 812 | - $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 813 | - $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 814 | - if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 815 | - $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 816 | - $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 817 | - $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 818 | - } |
|
| 819 | - // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 820 | - // on les reinjecte ici |
|
| 821 | - if ( |
|
| 822 | - isset($GLOBALS['meta']['plugin_attente']) && ($a = unserialize($GLOBALS['meta']['plugin_attente'])) |
|
| 823 | - ) { |
|
| 824 | - $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - if ($operation == 'ajoute') { |
|
| 828 | - $plugin = array_merge($plugin_valides, $plugin); |
|
| 829 | - } elseif ($operation == 'enleve') { |
|
| 830 | - $plugin = array_diff($plugin_valides, $plugin); |
|
| 831 | - } else { |
|
| 832 | - $plugin = $plugin_valides; |
|
| 833 | - } |
|
| 834 | - } |
|
| 835 | - $actifs_avant = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 836 | - |
|
| 837 | - // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 838 | - if ($ajouter_dependances = charger_fonction('ajouter_dependances', 'plugins', true)) { |
|
| 839 | - $plugin = $ajouter_dependances($plugin); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - // recharger le xml des plugins a activer |
|
| 843 | - // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 844 | - // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 845 | - // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 846 | - // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 847 | - [$infos, $liste, $invalides] = liste_plugin_valides($plugin, true); |
|
| 848 | - // trouver l'ordre d'activation |
|
| 849 | - [$plugin_valides, $ordre, $reste] = plugin_trier($infos, $liste); |
|
| 850 | - if ($invalides || $reste) { |
|
| 851 | - plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - // Ignorer les plugins necessitant une lib absente |
|
| 855 | - // et preparer la meta d'entete Http |
|
| 856 | - $err = $msg = $header = []; |
|
| 857 | - foreach ($plugin_valides as $p => $resume) { |
|
| 858 | - // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 859 | - if (!str_starts_with($p, 'PHP:') && $p !== 'PHP') { |
|
| 860 | - $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 861 | - } |
|
| 862 | - if ($resume['dir']) { |
|
| 863 | - foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 864 | - if (!find_in_path($l['nom'], 'lib/')) { |
|
| 865 | - $err[$p] = $resume; |
|
| 866 | - $msg[$p][] = $l; |
|
| 867 | - unset($plugin_valides[$p]); |
|
| 868 | - } |
|
| 869 | - } |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - if ($err) { |
|
| 873 | - plugins_erreurs($err, '', $infos, $msg); |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 877 | - effacer_meta('message_crash_plugins'); |
|
| 878 | - } |
|
| 879 | - ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 880 | - $liste = array_diff_key($liste, $plugin_valides); |
|
| 881 | - ecrire_meta('plugin_attente', serialize($liste)); |
|
| 882 | - $header = strtolower(implode(',', $header)); |
|
| 883 | - if (!isset($GLOBALS['spip_header_silencieux']) || !$GLOBALS['spip_header_silencieux']) { |
|
| 884 | - ecrire_fichier( |
|
| 885 | - _DIR_VAR . 'config.txt', |
|
| 886 | - (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 887 | - ); |
|
| 888 | - } else { |
|
| 889 | - @unlink(_DIR_VAR . 'config.txt'); |
|
| 890 | - } |
|
| 891 | - // generer charger_plugins_chemin.php |
|
| 892 | - plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 893 | - // generer les fichiers |
|
| 894 | - // - charger_plugins_options.php |
|
| 895 | - // - charger_plugins_fonctions.php |
|
| 896 | - plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 897 | - // charger les chemins des plugins et les fichiers d'options |
|
| 898 | - // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 899 | - plugins_amorcer_plugins_actifs(); |
|
| 900 | - // mise a jour de la matrice des pipelines |
|
| 901 | - $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 902 | - // generer le fichier _CACHE_PIPELINE |
|
| 903 | - pipeline_precompile($prepend_code); |
|
| 904 | - |
|
| 905 | - if (spip_connect()) { |
|
| 906 | - // lancer et initialiser les nouveaux crons ! |
|
| 907 | - include_spip('inc/genie'); |
|
| 908 | - genie_queue_watch_dist(); |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 803 | + // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 804 | + $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 805 | + |
|
| 806 | + // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 807 | + if (!$cache && !spip_connect()) { |
|
| 808 | + return false; |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + if ($operation != 'raz') { |
|
| 812 | + $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 813 | + $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 814 | + if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 815 | + $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 816 | + $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 817 | + $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 818 | + } |
|
| 819 | + // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 820 | + // on les reinjecte ici |
|
| 821 | + if ( |
|
| 822 | + isset($GLOBALS['meta']['plugin_attente']) && ($a = unserialize($GLOBALS['meta']['plugin_attente'])) |
|
| 823 | + ) { |
|
| 824 | + $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + if ($operation == 'ajoute') { |
|
| 828 | + $plugin = array_merge($plugin_valides, $plugin); |
|
| 829 | + } elseif ($operation == 'enleve') { |
|
| 830 | + $plugin = array_diff($plugin_valides, $plugin); |
|
| 831 | + } else { |
|
| 832 | + $plugin = $plugin_valides; |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + $actifs_avant = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 836 | + |
|
| 837 | + // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 838 | + if ($ajouter_dependances = charger_fonction('ajouter_dependances', 'plugins', true)) { |
|
| 839 | + $plugin = $ajouter_dependances($plugin); |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + // recharger le xml des plugins a activer |
|
| 843 | + // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 844 | + // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 845 | + // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 846 | + // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 847 | + [$infos, $liste, $invalides] = liste_plugin_valides($plugin, true); |
|
| 848 | + // trouver l'ordre d'activation |
|
| 849 | + [$plugin_valides, $ordre, $reste] = plugin_trier($infos, $liste); |
|
| 850 | + if ($invalides || $reste) { |
|
| 851 | + plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + // Ignorer les plugins necessitant une lib absente |
|
| 855 | + // et preparer la meta d'entete Http |
|
| 856 | + $err = $msg = $header = []; |
|
| 857 | + foreach ($plugin_valides as $p => $resume) { |
|
| 858 | + // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 859 | + if (!str_starts_with($p, 'PHP:') && $p !== 'PHP') { |
|
| 860 | + $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 861 | + } |
|
| 862 | + if ($resume['dir']) { |
|
| 863 | + foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 864 | + if (!find_in_path($l['nom'], 'lib/')) { |
|
| 865 | + $err[$p] = $resume; |
|
| 866 | + $msg[$p][] = $l; |
|
| 867 | + unset($plugin_valides[$p]); |
|
| 868 | + } |
|
| 869 | + } |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + if ($err) { |
|
| 873 | + plugins_erreurs($err, '', $infos, $msg); |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 877 | + effacer_meta('message_crash_plugins'); |
|
| 878 | + } |
|
| 879 | + ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 880 | + $liste = array_diff_key($liste, $plugin_valides); |
|
| 881 | + ecrire_meta('plugin_attente', serialize($liste)); |
|
| 882 | + $header = strtolower(implode(',', $header)); |
|
| 883 | + if (!isset($GLOBALS['spip_header_silencieux']) || !$GLOBALS['spip_header_silencieux']) { |
|
| 884 | + ecrire_fichier( |
|
| 885 | + _DIR_VAR . 'config.txt', |
|
| 886 | + (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 887 | + ); |
|
| 888 | + } else { |
|
| 889 | + @unlink(_DIR_VAR . 'config.txt'); |
|
| 890 | + } |
|
| 891 | + // generer charger_plugins_chemin.php |
|
| 892 | + plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 893 | + // generer les fichiers |
|
| 894 | + // - charger_plugins_options.php |
|
| 895 | + // - charger_plugins_fonctions.php |
|
| 896 | + plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 897 | + // charger les chemins des plugins et les fichiers d'options |
|
| 898 | + // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 899 | + plugins_amorcer_plugins_actifs(); |
|
| 900 | + // mise a jour de la matrice des pipelines |
|
| 901 | + $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 902 | + // generer le fichier _CACHE_PIPELINE |
|
| 903 | + pipeline_precompile($prepend_code); |
|
| 904 | + |
|
| 905 | + if (spip_connect()) { |
|
| 906 | + // lancer et initialiser les nouveaux crons ! |
|
| 907 | + include_spip('inc/genie'); |
|
| 908 | + genie_queue_watch_dist(); |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | /** |
@@ -927,75 +927,75 @@ discard block |
||
| 927 | 927 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 928 | 928 | **/ |
| 929 | 929 | function plugins_precompile_chemin($plugin_valides, $ordre) { |
| 930 | - $chemins = [ |
|
| 931 | - 'public' => [], |
|
| 932 | - 'prive' => [] |
|
| 933 | - ]; |
|
| 934 | - $contenu = ''; |
|
| 935 | - foreach ($ordre as $p => $info) { |
|
| 936 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 937 | - if (isset($plugin_valides[$p])) { |
|
| 938 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 939 | - $plug = $plugin_valides[$p]['dir']; |
|
| 940 | - // definir le plugin, donc le path avant l'include du fichier options |
|
| 941 | - // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 942 | - |
|
| 943 | - $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 944 | - |
|
| 945 | - $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 946 | - if ( |
|
| 947 | - $prefix !== 'SPIP' |
|
| 948 | - && !str_contains($dir, ':') // exclure le cas des procure: |
|
| 949 | - ) { |
|
| 950 | - $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 951 | - if (!$info['chemin']) { |
|
| 952 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 953 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 954 | - if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 955 | - $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 956 | - } |
|
| 957 | - } |
|
| 958 | - else { |
|
| 959 | - foreach ($info['chemin'] as $chemin) { |
|
| 960 | - if ( |
|
| 961 | - !isset($chemin['version']) |
|
| 962 | - || plugin_version_compatible( |
|
| 963 | - $chemin['version'], |
|
| 964 | - $GLOBALS['spip_version_branche'], |
|
| 965 | - 'spip' |
|
| 966 | - ) |
|
| 967 | - ) { |
|
| 968 | - $dir = $chemin['path']; |
|
| 969 | - if (strlen($dir) && $dir[0] == '/') { |
|
| 970 | - $dir = substr($dir, 1); |
|
| 971 | - } |
|
| 972 | - if (strlen($dir) && $dir == './') { |
|
| 973 | - $dir = ''; |
|
| 974 | - } |
|
| 975 | - if (strlen($dir)) { |
|
| 976 | - $dir = rtrim($dir, '/') . '/'; |
|
| 977 | - } |
|
| 978 | - if (!isset($chemin['type']) || $chemin['type'] == 'public') { |
|
| 979 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 980 | - } |
|
| 981 | - if (!isset($chemin['type']) || $chemin['type'] == 'prive') { |
|
| 982 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 983 | - } |
|
| 984 | - } |
|
| 985 | - } |
|
| 986 | - } |
|
| 987 | - } |
|
| 988 | - } |
|
| 989 | - } |
|
| 990 | - if (count($chemins['public']) || count($chemins['prive'])) { |
|
| 991 | - $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 992 | - ',', |
|
| 993 | - array_reverse($chemins['public']) |
|
| 994 | - ) . "]);\n" |
|
| 995 | - . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 930 | + $chemins = [ |
|
| 931 | + 'public' => [], |
|
| 932 | + 'prive' => [] |
|
| 933 | + ]; |
|
| 934 | + $contenu = ''; |
|
| 935 | + foreach ($ordre as $p => $info) { |
|
| 936 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 937 | + if (isset($plugin_valides[$p])) { |
|
| 938 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 939 | + $plug = $plugin_valides[$p]['dir']; |
|
| 940 | + // definir le plugin, donc le path avant l'include du fichier options |
|
| 941 | + // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 942 | + |
|
| 943 | + $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 944 | + |
|
| 945 | + $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 946 | + if ( |
|
| 947 | + $prefix !== 'SPIP' |
|
| 948 | + && !str_contains($dir, ':') // exclure le cas des procure: |
|
| 949 | + ) { |
|
| 950 | + $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 951 | + if (!$info['chemin']) { |
|
| 952 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 953 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 954 | + if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 955 | + $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 956 | + } |
|
| 957 | + } |
|
| 958 | + else { |
|
| 959 | + foreach ($info['chemin'] as $chemin) { |
|
| 960 | + if ( |
|
| 961 | + !isset($chemin['version']) |
|
| 962 | + || plugin_version_compatible( |
|
| 963 | + $chemin['version'], |
|
| 964 | + $GLOBALS['spip_version_branche'], |
|
| 965 | + 'spip' |
|
| 966 | + ) |
|
| 967 | + ) { |
|
| 968 | + $dir = $chemin['path']; |
|
| 969 | + if (strlen($dir) && $dir[0] == '/') { |
|
| 970 | + $dir = substr($dir, 1); |
|
| 971 | + } |
|
| 972 | + if (strlen($dir) && $dir == './') { |
|
| 973 | + $dir = ''; |
|
| 974 | + } |
|
| 975 | + if (strlen($dir)) { |
|
| 976 | + $dir = rtrim($dir, '/') . '/'; |
|
| 977 | + } |
|
| 978 | + if (!isset($chemin['type']) || $chemin['type'] == 'public') { |
|
| 979 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 980 | + } |
|
| 981 | + if (!isset($chemin['type']) || $chemin['type'] == 'prive') { |
|
| 982 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 983 | + } |
|
| 984 | + } |
|
| 985 | + } |
|
| 986 | + } |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | + } |
|
| 990 | + if (count($chemins['public']) || count($chemins['prive'])) { |
|
| 991 | + $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 992 | + ',', |
|
| 993 | + array_reverse($chemins['public']) |
|
| 994 | + ) . "]);\n" |
|
| 995 | + . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | /** |
@@ -1013,65 +1013,65 @@ discard block |
||
| 1013 | 1013 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 1014 | 1014 | **/ |
| 1015 | 1015 | function plugins_precompile_xxxtions($plugin_valides, $ordre) { |
| 1016 | - $contenu = ['options' => '', 'fonctions' => '']; |
|
| 1017 | - $boutons = []; |
|
| 1018 | - $onglets = []; |
|
| 1019 | - $sign = ''; |
|
| 1020 | - |
|
| 1021 | - foreach ($ordre as $p => $info) { |
|
| 1022 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1023 | - if (isset($plugin_valides[$p])) { |
|
| 1024 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1025 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1026 | - $dir = constant($dir_type); |
|
| 1027 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1028 | - if ($info['menu']) { |
|
| 1029 | - $boutons = array_merge($boutons, $info['menu']); |
|
| 1030 | - } |
|
| 1031 | - if ($info['onglet']) { |
|
| 1032 | - $onglets = array_merge($onglets, $info['onglet']); |
|
| 1033 | - } |
|
| 1034 | - foreach ($contenu as $charge => $v) { |
|
| 1035 | - // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1036 | - // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1037 | - // donc ni sa relecture, ni sa detection |
|
| 1038 | - if ( |
|
| 1039 | - !isset($info[$charge]) |
|
| 1040 | - && $dir |
|
| 1041 | - && !str_contains($dir, ':') |
|
| 1042 | - && file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1043 | - ) { |
|
| 1044 | - if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1045 | - $info[$charge] = [$file]; |
|
| 1046 | - } |
|
| 1047 | - } |
|
| 1048 | - if (isset($info[$charge])) { |
|
| 1049 | - $files = $info[$charge]; |
|
| 1050 | - foreach ($files as $k => $file) { |
|
| 1051 | - // on genere un if file_exists devant chaque include |
|
| 1052 | - // pour pouvoir garder le meme niveau d'erreur general |
|
| 1053 | - $file = trim($file); |
|
| 1054 | - if ( |
|
| 1055 | - !is_readable("$dir$plug/$file") && file_exists("$dir$plug/paquet.xml") |
|
| 1056 | - ) { |
|
| 1057 | - unset($info[$charge][$k]); |
|
| 1058 | - } else { |
|
| 1059 | - $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1060 | - $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1061 | - } |
|
| 1062 | - } |
|
| 1063 | - } |
|
| 1064 | - } |
|
| 1065 | - $sign .= md5(serialize($info)); |
|
| 1066 | - } |
|
| 1067 | - } |
|
| 1068 | - |
|
| 1069 | - $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1070 | - $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
|
| 1071 | - . plugin_ongletbouton('onglets_plugins', $onglets); |
|
| 1072 | - |
|
| 1073 | - ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1074 | - ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1016 | + $contenu = ['options' => '', 'fonctions' => '']; |
|
| 1017 | + $boutons = []; |
|
| 1018 | + $onglets = []; |
|
| 1019 | + $sign = ''; |
|
| 1020 | + |
|
| 1021 | + foreach ($ordre as $p => $info) { |
|
| 1022 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1023 | + if (isset($plugin_valides[$p])) { |
|
| 1024 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1025 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1026 | + $dir = constant($dir_type); |
|
| 1027 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1028 | + if ($info['menu']) { |
|
| 1029 | + $boutons = array_merge($boutons, $info['menu']); |
|
| 1030 | + } |
|
| 1031 | + if ($info['onglet']) { |
|
| 1032 | + $onglets = array_merge($onglets, $info['onglet']); |
|
| 1033 | + } |
|
| 1034 | + foreach ($contenu as $charge => $v) { |
|
| 1035 | + // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1036 | + // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1037 | + // donc ni sa relecture, ni sa detection |
|
| 1038 | + if ( |
|
| 1039 | + !isset($info[$charge]) |
|
| 1040 | + && $dir |
|
| 1041 | + && !str_contains($dir, ':') |
|
| 1042 | + && file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1043 | + ) { |
|
| 1044 | + if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1045 | + $info[$charge] = [$file]; |
|
| 1046 | + } |
|
| 1047 | + } |
|
| 1048 | + if (isset($info[$charge])) { |
|
| 1049 | + $files = $info[$charge]; |
|
| 1050 | + foreach ($files as $k => $file) { |
|
| 1051 | + // on genere un if file_exists devant chaque include |
|
| 1052 | + // pour pouvoir garder le meme niveau d'erreur general |
|
| 1053 | + $file = trim($file); |
|
| 1054 | + if ( |
|
| 1055 | + !is_readable("$dir$plug/$file") && file_exists("$dir$plug/paquet.xml") |
|
| 1056 | + ) { |
|
| 1057 | + unset($info[$charge][$k]); |
|
| 1058 | + } else { |
|
| 1059 | + $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1060 | + $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1061 | + } |
|
| 1062 | + } |
|
| 1063 | + } |
|
| 1064 | + } |
|
| 1065 | + $sign .= md5(serialize($info)); |
|
| 1066 | + } |
|
| 1067 | + } |
|
| 1068 | + |
|
| 1069 | + $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1070 | + $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
|
| 1071 | + . plugin_ongletbouton('onglets_plugins', $onglets); |
|
| 1072 | + |
|
| 1073 | + ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1074 | + ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | /** |
@@ -1090,24 +1090,24 @@ discard block |
||
| 1090 | 1090 | * @return string Code php |
| 1091 | 1091 | */ |
| 1092 | 1092 | function plugin_ongletbouton($nom, $val) { |
| 1093 | - if (!$val) { |
|
| 1094 | - $val = []; |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - $val = serialize($val); |
|
| 1098 | - $md5 = md5($val); |
|
| 1099 | - |
|
| 1100 | - if (!defined("_UPDATED_$nom")) { |
|
| 1101 | - define("_UPDATED_$nom", $val); |
|
| 1102 | - define("_UPDATED_md5_$nom", $md5); |
|
| 1103 | - } |
|
| 1104 | - $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1105 | - |
|
| 1106 | - return |
|
| 1107 | - "if (!function_exists('$nom')) {\n" |
|
| 1108 | - . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1109 | - . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1110 | - . "}\n"; |
|
| 1093 | + if (!$val) { |
|
| 1094 | + $val = []; |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + $val = serialize($val); |
|
| 1098 | + $md5 = md5($val); |
|
| 1099 | + |
|
| 1100 | + if (!defined("_UPDATED_$nom")) { |
|
| 1101 | + define("_UPDATED_$nom", $val); |
|
| 1102 | + define("_UPDATED_md5_$nom", $md5); |
|
| 1103 | + } |
|
| 1104 | + $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1105 | + |
|
| 1106 | + return |
|
| 1107 | + "if (!function_exists('$nom')) {\n" |
|
| 1108 | + . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1109 | + . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1110 | + . "}\n"; |
|
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | 1113 | /** |
@@ -1122,15 +1122,15 @@ discard block |
||
| 1122 | 1122 | **/ |
| 1123 | 1123 | function plugins_amorcer_plugins_actifs() { |
| 1124 | 1124 | |
| 1125 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1126 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1127 | - } |
|
| 1125 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1126 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1127 | + } |
|
| 1128 | 1128 | |
| 1129 | - if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1130 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 1131 | - } else { |
|
| 1132 | - spip_log('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1133 | - } |
|
| 1129 | + if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1130 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 1131 | + } else { |
|
| 1132 | + spip_log('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1133 | + } |
|
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | /** |
@@ -1153,140 +1153,140 @@ discard block |
||
| 1153 | 1153 | * Couples (nom du pipeline => Code PHP à insérer au début du pipeline) |
| 1154 | 1154 | **/ |
| 1155 | 1155 | function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche) { |
| 1156 | - static $liste_pipe_manquants = []; |
|
| 1157 | - if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1158 | - $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1159 | - } |
|
| 1160 | - |
|
| 1161 | - $prepend_code = []; |
|
| 1162 | - |
|
| 1163 | - foreach ($ordre as $p => $info) { |
|
| 1164 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1165 | - if (isset($plugin_valides[$p])) { |
|
| 1166 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1167 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1168 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1169 | - $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1170 | - if (isset($info['pipeline']) && is_array($info['pipeline'])) { |
|
| 1171 | - foreach ($info['pipeline'] as $pipe) { |
|
| 1172 | - $nom = $pipe['nom']; |
|
| 1173 | - if (isset($pipe['action'])) { |
|
| 1174 | - $action = $pipe['action']; |
|
| 1175 | - } else { |
|
| 1176 | - $action = $nom; |
|
| 1177 | - } |
|
| 1178 | - $nomlower = strtolower($nom); |
|
| 1179 | - if ( |
|
| 1180 | - $nomlower != $nom |
|
| 1181 | - && isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1182 | - && !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1183 | - ) { |
|
| 1184 | - $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1185 | - unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1186 | - } |
|
| 1187 | - $nom = $nomlower; |
|
| 1188 | - // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1189 | - if (!isset($GLOBALS['spip_pipeline'][$nom])) { // creer le pipeline eventuel |
|
| 1190 | - $GLOBALS['spip_pipeline'][$nom] = ''; |
|
| 1191 | - } |
|
| 1192 | - if ($action) { |
|
| 1193 | - if (!str_contains($GLOBALS['spip_pipeline'][$nom], (string) "|$prefix$action")) { |
|
| 1194 | - $GLOBALS['spip_pipeline'][$nom] = preg_replace( |
|
| 1195 | - ',(\|\||$),', |
|
| 1196 | - "|$prefix$action\\1", |
|
| 1197 | - $GLOBALS['spip_pipeline'][$nom], |
|
| 1198 | - 1 |
|
| 1199 | - ); |
|
| 1200 | - } |
|
| 1201 | - if (isset($pipe['inclure'])) { |
|
| 1202 | - $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1203 | - "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1204 | - } |
|
| 1205 | - } |
|
| 1206 | - } |
|
| 1207 | - } |
|
| 1208 | - if (isset($info['genie']) && (is_countable($info['genie']) ? count($info['genie']) : 0)) { |
|
| 1209 | - if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1210 | - $prepend_code['taches_generales_cron'] = ''; |
|
| 1211 | - } |
|
| 1212 | - foreach ($info['genie'] as $genie) { |
|
| 1213 | - $nom = $prefix . $genie['nom']; |
|
| 1214 | - $periode = max(60, intval($genie['periode'])); |
|
| 1215 | - if (charger_fonction($nom, 'genie', true)) { |
|
| 1216 | - $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1217 | - } else { |
|
| 1218 | - spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1219 | - } |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - if (isset($info['style']) && (is_countable($info['style']) ? count($info['style']) : 0)) { |
|
| 1223 | - if (!isset($prepend_code['insert_head_css'])) { |
|
| 1224 | - $prepend_code['insert_head_css'] = ''; |
|
| 1225 | - } |
|
| 1226 | - if (!isset($prepend_code['header_prive_css'])) { |
|
| 1227 | - $prepend_code['header_prive_css'] = ''; |
|
| 1228 | - } |
|
| 1229 | - foreach ($info['style'] as $style) { |
|
| 1230 | - if (isset($style['path']) && $style['path']) { |
|
| 1231 | - $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1232 | - } else { |
|
| 1233 | - $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1234 | - } |
|
| 1235 | - $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1236 | - if (isset($style['media']) && strlen($style['media'])) { |
|
| 1237 | - $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1238 | - } |
|
| 1239 | - $code .= "/>';\n"; |
|
| 1240 | - if ($style['type'] != 'prive') { |
|
| 1241 | - $prepend_code['insert_head_css'] .= $code; |
|
| 1242 | - } |
|
| 1243 | - if ($style['type'] != 'public') { |
|
| 1244 | - $prepend_code['header_prive_css'] .= $code; |
|
| 1245 | - } |
|
| 1246 | - } |
|
| 1247 | - } |
|
| 1248 | - if (!isset($prepend_code['insert_head'])) { |
|
| 1249 | - $prepend_code['insert_head'] = ''; |
|
| 1250 | - } |
|
| 1251 | - if (!isset($prepend_code['header_prive'])) { |
|
| 1252 | - $prepend_code['header_prive'] = ''; |
|
| 1253 | - } |
|
| 1254 | - if (isset($info['script']) && (is_countable($info['script']) ? count($info['script']) : 0)) { |
|
| 1255 | - foreach ($info['script'] as $script) { |
|
| 1256 | - if (isset($script['path']) && $script['path']) { |
|
| 1257 | - $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1258 | - } else { |
|
| 1259 | - $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1260 | - } |
|
| 1261 | - $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1262 | - if ($script['type'] != 'prive') { |
|
| 1263 | - $prepend_code['insert_head'] .= $code; |
|
| 1264 | - } |
|
| 1265 | - if ($script['type'] != 'public') { |
|
| 1266 | - $prepend_code['header_prive'] .= $code; |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - } |
|
| 1270 | - } |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - $prepend_code['insert_head'] = |
|
| 1274 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1275 | - . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1276 | - . $prepend_code['insert_head']; |
|
| 1277 | - $prepend_code['header_prive'] = |
|
| 1278 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1279 | - . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1280 | - . $prepend_code['header_prive']; |
|
| 1281 | - |
|
| 1282 | - // on ajoute les pipe qui ont ete recenses manquants |
|
| 1283 | - foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1284 | - if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1285 | - $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1286 | - } |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - return $prepend_code; |
|
| 1156 | + static $liste_pipe_manquants = []; |
|
| 1157 | + if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1158 | + $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1159 | + } |
|
| 1160 | + |
|
| 1161 | + $prepend_code = []; |
|
| 1162 | + |
|
| 1163 | + foreach ($ordre as $p => $info) { |
|
| 1164 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1165 | + if (isset($plugin_valides[$p])) { |
|
| 1166 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1167 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1168 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1169 | + $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1170 | + if (isset($info['pipeline']) && is_array($info['pipeline'])) { |
|
| 1171 | + foreach ($info['pipeline'] as $pipe) { |
|
| 1172 | + $nom = $pipe['nom']; |
|
| 1173 | + if (isset($pipe['action'])) { |
|
| 1174 | + $action = $pipe['action']; |
|
| 1175 | + } else { |
|
| 1176 | + $action = $nom; |
|
| 1177 | + } |
|
| 1178 | + $nomlower = strtolower($nom); |
|
| 1179 | + if ( |
|
| 1180 | + $nomlower != $nom |
|
| 1181 | + && isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1182 | + && !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1183 | + ) { |
|
| 1184 | + $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1185 | + unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1186 | + } |
|
| 1187 | + $nom = $nomlower; |
|
| 1188 | + // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1189 | + if (!isset($GLOBALS['spip_pipeline'][$nom])) { // creer le pipeline eventuel |
|
| 1190 | + $GLOBALS['spip_pipeline'][$nom] = ''; |
|
| 1191 | + } |
|
| 1192 | + if ($action) { |
|
| 1193 | + if (!str_contains($GLOBALS['spip_pipeline'][$nom], (string) "|$prefix$action")) { |
|
| 1194 | + $GLOBALS['spip_pipeline'][$nom] = preg_replace( |
|
| 1195 | + ',(\|\||$),', |
|
| 1196 | + "|$prefix$action\\1", |
|
| 1197 | + $GLOBALS['spip_pipeline'][$nom], |
|
| 1198 | + 1 |
|
| 1199 | + ); |
|
| 1200 | + } |
|
| 1201 | + if (isset($pipe['inclure'])) { |
|
| 1202 | + $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1203 | + "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1204 | + } |
|
| 1205 | + } |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + if (isset($info['genie']) && (is_countable($info['genie']) ? count($info['genie']) : 0)) { |
|
| 1209 | + if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1210 | + $prepend_code['taches_generales_cron'] = ''; |
|
| 1211 | + } |
|
| 1212 | + foreach ($info['genie'] as $genie) { |
|
| 1213 | + $nom = $prefix . $genie['nom']; |
|
| 1214 | + $periode = max(60, intval($genie['periode'])); |
|
| 1215 | + if (charger_fonction($nom, 'genie', true)) { |
|
| 1216 | + $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1217 | + } else { |
|
| 1218 | + spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1219 | + } |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + if (isset($info['style']) && (is_countable($info['style']) ? count($info['style']) : 0)) { |
|
| 1223 | + if (!isset($prepend_code['insert_head_css'])) { |
|
| 1224 | + $prepend_code['insert_head_css'] = ''; |
|
| 1225 | + } |
|
| 1226 | + if (!isset($prepend_code['header_prive_css'])) { |
|
| 1227 | + $prepend_code['header_prive_css'] = ''; |
|
| 1228 | + } |
|
| 1229 | + foreach ($info['style'] as $style) { |
|
| 1230 | + if (isset($style['path']) && $style['path']) { |
|
| 1231 | + $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1232 | + } else { |
|
| 1233 | + $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1234 | + } |
|
| 1235 | + $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1236 | + if (isset($style['media']) && strlen($style['media'])) { |
|
| 1237 | + $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1238 | + } |
|
| 1239 | + $code .= "/>';\n"; |
|
| 1240 | + if ($style['type'] != 'prive') { |
|
| 1241 | + $prepend_code['insert_head_css'] .= $code; |
|
| 1242 | + } |
|
| 1243 | + if ($style['type'] != 'public') { |
|
| 1244 | + $prepend_code['header_prive_css'] .= $code; |
|
| 1245 | + } |
|
| 1246 | + } |
|
| 1247 | + } |
|
| 1248 | + if (!isset($prepend_code['insert_head'])) { |
|
| 1249 | + $prepend_code['insert_head'] = ''; |
|
| 1250 | + } |
|
| 1251 | + if (!isset($prepend_code['header_prive'])) { |
|
| 1252 | + $prepend_code['header_prive'] = ''; |
|
| 1253 | + } |
|
| 1254 | + if (isset($info['script']) && (is_countable($info['script']) ? count($info['script']) : 0)) { |
|
| 1255 | + foreach ($info['script'] as $script) { |
|
| 1256 | + if (isset($script['path']) && $script['path']) { |
|
| 1257 | + $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1258 | + } else { |
|
| 1259 | + $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1260 | + } |
|
| 1261 | + $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1262 | + if ($script['type'] != 'prive') { |
|
| 1263 | + $prepend_code['insert_head'] .= $code; |
|
| 1264 | + } |
|
| 1265 | + if ($script['type'] != 'public') { |
|
| 1266 | + $prepend_code['header_prive'] .= $code; |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + } |
|
| 1270 | + } |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + $prepend_code['insert_head'] = |
|
| 1274 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1275 | + . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1276 | + . $prepend_code['insert_head']; |
|
| 1277 | + $prepend_code['header_prive'] = |
|
| 1278 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1279 | + . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1280 | + . $prepend_code['header_prive']; |
|
| 1281 | + |
|
| 1282 | + // on ajoute les pipe qui ont ete recenses manquants |
|
| 1283 | + foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1284 | + if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1285 | + $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1286 | + } |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + return $prepend_code; |
|
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | 1292 | /** |
@@ -1313,62 +1313,62 @@ discard block |
||
| 1313 | 1313 | **/ |
| 1314 | 1314 | function pipeline_precompile($prepend_code = []) { |
| 1315 | 1315 | |
| 1316 | - $all_pipes = $all_pipes_end = ''; |
|
| 1317 | - if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1318 | - $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1319 | - unset($GLOBALS['spip_pipeline']['all']); |
|
| 1320 | - $all_pipes = trim(array_shift($a)); |
|
| 1321 | - if ($all_pipes) { |
|
| 1322 | - $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1323 | - } |
|
| 1324 | - if (count($a)) { |
|
| 1325 | - $all_pipes_end = '||' . array_shift($a); |
|
| 1326 | - } |
|
| 1327 | - } |
|
| 1328 | - $content = ''; |
|
| 1329 | - foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1330 | - $s_inc = ''; |
|
| 1331 | - $s_call = ''; |
|
| 1332 | - if ($all_pipes) { |
|
| 1333 | - $pipeline = preg_replace(',(\|\||$),', "$all_pipes\\1", $pipeline, 1); |
|
| 1334 | - } |
|
| 1335 | - if ($all_pipes_end) { |
|
| 1336 | - $pipeline .= $all_pipes_end; |
|
| 1337 | - } |
|
| 1338 | - $pipe = array_filter(explode('|', $pipeline)); |
|
| 1339 | - // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1340 | - foreach ($pipe as $fonc) { |
|
| 1341 | - $fonc = trim($fonc); |
|
| 1342 | - $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1343 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1344 | - $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1345 | - $file = "'$file'"; |
|
| 1346 | - // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1347 | - if (preg_match(',(_(DIR|ROOT)_[A-Z_]+):,Ums', $file, $regs)) { |
|
| 1348 | - $dir = $regs[1]; |
|
| 1349 | - $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1350 | - if (defined($root_dir)) { |
|
| 1351 | - $dir = $root_dir; |
|
| 1352 | - } |
|
| 1353 | - $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1354 | - $file = str_replace("''.", '', $file); |
|
| 1355 | - $file = str_replace(constant($dir), '', $file); |
|
| 1356 | - } |
|
| 1357 | - $s_inc .= "include_once_check($file);\n"; |
|
| 1358 | - } |
|
| 1359 | - } |
|
| 1360 | - if (strlen($s_inc)) { |
|
| 1361 | - $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1362 | - } |
|
| 1363 | - $content .= "// Pipeline $action \n" |
|
| 1364 | - . "function execute_pipeline_$action(&\$val){\n" |
|
| 1365 | - . $s_inc |
|
| 1366 | - . ((isset($prepend_code[$action]) && strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1367 | - . $s_call |
|
| 1368 | - . "return \$val;\n}\n"; |
|
| 1369 | - } |
|
| 1370 | - ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1371 | - clear_path_cache(); |
|
| 1316 | + $all_pipes = $all_pipes_end = ''; |
|
| 1317 | + if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1318 | + $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1319 | + unset($GLOBALS['spip_pipeline']['all']); |
|
| 1320 | + $all_pipes = trim(array_shift($a)); |
|
| 1321 | + if ($all_pipes) { |
|
| 1322 | + $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1323 | + } |
|
| 1324 | + if (count($a)) { |
|
| 1325 | + $all_pipes_end = '||' . array_shift($a); |
|
| 1326 | + } |
|
| 1327 | + } |
|
| 1328 | + $content = ''; |
|
| 1329 | + foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1330 | + $s_inc = ''; |
|
| 1331 | + $s_call = ''; |
|
| 1332 | + if ($all_pipes) { |
|
| 1333 | + $pipeline = preg_replace(',(\|\||$),', "$all_pipes\\1", $pipeline, 1); |
|
| 1334 | + } |
|
| 1335 | + if ($all_pipes_end) { |
|
| 1336 | + $pipeline .= $all_pipes_end; |
|
| 1337 | + } |
|
| 1338 | + $pipe = array_filter(explode('|', $pipeline)); |
|
| 1339 | + // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1340 | + foreach ($pipe as $fonc) { |
|
| 1341 | + $fonc = trim($fonc); |
|
| 1342 | + $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1343 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1344 | + $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1345 | + $file = "'$file'"; |
|
| 1346 | + // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1347 | + if (preg_match(',(_(DIR|ROOT)_[A-Z_]+):,Ums', $file, $regs)) { |
|
| 1348 | + $dir = $regs[1]; |
|
| 1349 | + $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1350 | + if (defined($root_dir)) { |
|
| 1351 | + $dir = $root_dir; |
|
| 1352 | + } |
|
| 1353 | + $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1354 | + $file = str_replace("''.", '', $file); |
|
| 1355 | + $file = str_replace(constant($dir), '', $file); |
|
| 1356 | + } |
|
| 1357 | + $s_inc .= "include_once_check($file);\n"; |
|
| 1358 | + } |
|
| 1359 | + } |
|
| 1360 | + if (strlen($s_inc)) { |
|
| 1361 | + $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1362 | + } |
|
| 1363 | + $content .= "// Pipeline $action \n" |
|
| 1364 | + . "function execute_pipeline_$action(&\$val){\n" |
|
| 1365 | + . $s_inc |
|
| 1366 | + . ((isset($prepend_code[$action]) && strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1367 | + . $s_call |
|
| 1368 | + . "return \$val;\n}\n"; |
|
| 1369 | + } |
|
| 1370 | + ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1371 | + clear_path_cache(); |
|
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | 1374 | |
@@ -1381,12 +1381,12 @@ discard block |
||
| 1381 | 1381 | * true si le plugin est actif, false sinon |
| 1382 | 1382 | **/ |
| 1383 | 1383 | function plugin_est_installe($plug_path) { |
| 1384 | - $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : []; |
|
| 1385 | - if (!$plugin_installes) { |
|
| 1386 | - return false; |
|
| 1387 | - } |
|
| 1384 | + $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : []; |
|
| 1385 | + if (!$plugin_installes) { |
|
| 1386 | + return false; |
|
| 1387 | + } |
|
| 1388 | 1388 | |
| 1389 | - return in_array($plug_path, $plugin_installes); |
|
| 1389 | + return in_array($plug_path, $plugin_installes); |
|
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | 1392 | |
@@ -1399,46 +1399,46 @@ discard block |
||
| 1399 | 1399 | * @uses plugins_installer_dist() |
| 1400 | 1400 | **/ |
| 1401 | 1401 | function plugin_installes_meta() { |
| 1402 | - if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1403 | - // attendre eventuellement l'invalidation du cache opcode |
|
| 1404 | - spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1405 | - } |
|
| 1406 | - |
|
| 1407 | - $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1408 | - $meta_plug_installes = []; |
|
| 1409 | - foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1410 | - if ($plug = $resume['dir']) { |
|
| 1411 | - $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1412 | - if ($infos) { |
|
| 1413 | - if (!is_array($infos) || $infos['install_test'][0]) { |
|
| 1414 | - $meta_plug_installes[] = $plug; |
|
| 1415 | - } |
|
| 1416 | - if (is_array($infos)) { |
|
| 1417 | - [$ok, $trace] = $infos['install_test']; |
|
| 1418 | - $titre = _T('plugin_titre_installation', ['plugin' => typo($infos['nom'])]); |
|
| 1419 | - $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
|
| 1420 | - if (_IS_CLI) { |
|
| 1421 | - include_spip('inc/filtres'); |
|
| 1422 | - $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1423 | - $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1424 | - echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1425 | - $trace, |
|
| 1426 | - "\n"; |
|
| 1427 | - } |
|
| 1428 | - else { |
|
| 1429 | - include_spip('inc/filtres_boites'); |
|
| 1430 | - echo "<div class='install-plugins svp_retour'>" |
|
| 1431 | - . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
|
| 1432 | - . $trace |
|
| 1433 | - . "<div class='result'>$result</div>" |
|
| 1434 | - . boite_fermer() |
|
| 1435 | - . '</div>'; |
|
| 1436 | - } |
|
| 1437 | - } |
|
| 1438 | - } |
|
| 1439 | - } |
|
| 1440 | - } |
|
| 1441 | - ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1402 | + if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1403 | + // attendre eventuellement l'invalidation du cache opcode |
|
| 1404 | + spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1405 | + } |
|
| 1406 | + |
|
| 1407 | + $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1408 | + $meta_plug_installes = []; |
|
| 1409 | + foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1410 | + if ($plug = $resume['dir']) { |
|
| 1411 | + $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1412 | + if ($infos) { |
|
| 1413 | + if (!is_array($infos) || $infos['install_test'][0]) { |
|
| 1414 | + $meta_plug_installes[] = $plug; |
|
| 1415 | + } |
|
| 1416 | + if (is_array($infos)) { |
|
| 1417 | + [$ok, $trace] = $infos['install_test']; |
|
| 1418 | + $titre = _T('plugin_titre_installation', ['plugin' => typo($infos['nom'])]); |
|
| 1419 | + $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
|
| 1420 | + if (_IS_CLI) { |
|
| 1421 | + include_spip('inc/filtres'); |
|
| 1422 | + $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1423 | + $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1424 | + echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1425 | + $trace, |
|
| 1426 | + "\n"; |
|
| 1427 | + } |
|
| 1428 | + else { |
|
| 1429 | + include_spip('inc/filtres_boites'); |
|
| 1430 | + echo "<div class='install-plugins svp_retour'>" |
|
| 1431 | + . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
|
| 1432 | + . $trace |
|
| 1433 | + . "<div class='result'>$result</div>" |
|
| 1434 | + . boite_fermer() |
|
| 1435 | + . '</div>'; |
|
| 1436 | + } |
|
| 1437 | + } |
|
| 1438 | + } |
|
| 1439 | + } |
|
| 1440 | + } |
|
| 1441 | + ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1442 | 1442 | } |
| 1443 | 1443 | |
| 1444 | 1444 | /** |
@@ -1452,29 +1452,29 @@ discard block |
||
| 1452 | 1452 | * Commentaire : code écrit en tout début de fichier, après la balise PHP ouvrante |
| 1453 | 1453 | **/ |
| 1454 | 1454 | function ecrire_fichier_php($nom, $contenu, $comment = '') { |
| 1455 | - if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1456 | - $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1460 | - // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1461 | - // si pas de modif on ne touche pas au fichier initial |
|
| 1462 | - if (file_exists($nom)) { |
|
| 1463 | - if (str_ends_with($nom, '.php')) { |
|
| 1464 | - $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1465 | - } |
|
| 1466 | - else { |
|
| 1467 | - $fichier_tmp = $nom . '.tmp'; |
|
| 1468 | - } |
|
| 1469 | - file_put_contents($fichier_tmp, $contenu); |
|
| 1470 | - if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1471 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1472 | - @unlink($fichier_tmp); |
|
| 1473 | - return; |
|
| 1474 | - } |
|
| 1475 | - @unlink($fichier_tmp); |
|
| 1476 | - } |
|
| 1477 | - ecrire_fichier($nom, $contenu); |
|
| 1478 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1479 | - spip_clear_opcode_cache(realpath($nom)); |
|
| 1455 | + if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1456 | + $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1460 | + // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1461 | + // si pas de modif on ne touche pas au fichier initial |
|
| 1462 | + if (file_exists($nom)) { |
|
| 1463 | + if (str_ends_with($nom, '.php')) { |
|
| 1464 | + $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1465 | + } |
|
| 1466 | + else { |
|
| 1467 | + $fichier_tmp = $nom . '.tmp'; |
|
| 1468 | + } |
|
| 1469 | + file_put_contents($fichier_tmp, $contenu); |
|
| 1470 | + if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1471 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1472 | + @unlink($fichier_tmp); |
|
| 1473 | + return; |
|
| 1474 | + } |
|
| 1475 | + @unlink($fichier_tmp); |
|
| 1476 | + } |
|
| 1477 | + ecrire_fichier($nom, $contenu); |
|
| 1478 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1479 | + spip_clear_opcode_cache(realpath($nom)); |
|
| 1480 | 1480 | } |
@@ -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,33 +34,33 @@ discard block |
||
| 34 | 34 | * - une chaîne vide si autorisation à pénétrer dans l'espace privé. |
| 35 | 35 | */ |
| 36 | 36 | function inc_auth_dist() { |
| 37 | - $row = auth_mode(); |
|
| 37 | + $row = auth_mode(); |
|
| 38 | 38 | |
| 39 | - if ($row) { |
|
| 40 | - return auth_init_droits($row); |
|
| 41 | - } |
|
| 39 | + if ($row) { |
|
| 40 | + return auth_init_droits($row); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - if (!$GLOBALS['connect_login']) { |
|
| 44 | - return auth_a_loger(); |
|
| 45 | - } |
|
| 43 | + if (!$GLOBALS['connect_login']) { |
|
| 44 | + return auth_a_loger(); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - // Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui |
|
| 48 | - // C'est soit parce que la base est inutilisable, |
|
| 49 | - // soit parce que la table des auteurs a changee (restauration etc) |
|
| 50 | - // Pas la peine d'insister. |
|
| 51 | - // Renvoyer le nom fautif et une URL de remise a zero |
|
| 47 | + // Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui |
|
| 48 | + // C'est soit parce que la base est inutilisable, |
|
| 49 | + // soit parce que la table des auteurs a changee (restauration etc) |
|
| 50 | + // Pas la peine d'insister. |
|
| 51 | + // Renvoyer le nom fautif et une URL de remise a zero |
|
| 52 | 52 | |
| 53 | - if (spip_connect()) { |
|
| 54 | - return [ |
|
| 55 | - 'login' => $GLOBALS['connect_login'], |
|
| 56 | - 'site' => generer_url_public('', 'action=logout&logout=prive') |
|
| 57 | - ]; |
|
| 58 | - } |
|
| 53 | + if (spip_connect()) { |
|
| 54 | + return [ |
|
| 55 | + 'login' => $GLOBALS['connect_login'], |
|
| 56 | + 'site' => generer_url_public('', 'action=logout&logout=prive') |
|
| 57 | + ]; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $n = (int) sql_errno(); |
|
| 61 | - spip_log("Erreur base de donnees $n " . sql_error()); |
|
| 60 | + $n = (int) sql_errno(); |
|
| 61 | + spip_log("Erreur base de donnees $n " . sql_error()); |
|
| 62 | 62 | |
| 63 | - return $n ?: 1; |
|
| 63 | + return $n ?: 1; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -69,15 +69,15 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | function auth_controler_password_auteur_connecte(#[\SensitiveParameter] string $password): bool { |
| 71 | 71 | |
| 72 | - if ( |
|
| 73 | - empty($GLOBALS['visiteur_session']['id_auteur']) |
|
| 74 | - || empty($GLOBALS['visiteur_session']['login']) |
|
| 75 | - ) { |
|
| 76 | - return false; |
|
| 77 | - } |
|
| 72 | + if ( |
|
| 73 | + empty($GLOBALS['visiteur_session']['id_auteur']) |
|
| 74 | + || empty($GLOBALS['visiteur_session']['login']) |
|
| 75 | + ) { |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - $auth = auth_identifier_login($GLOBALS['visiteur_session']['login'], $password, '', true); |
|
| 80 | - return is_array($auth) && $auth['id_auteur'] == $GLOBALS['visiteur_session']['id_auteur']; |
|
| 79 | + $auth = auth_identifier_login($GLOBALS['visiteur_session']['login'], $password, '', true); |
|
| 80 | + return is_array($auth) && $auth['id_auteur'] == $GLOBALS['visiteur_session']['id_auteur']; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -89,47 +89,47 @@ discard block |
||
| 89 | 89 | * @return array|string |
| 90 | 90 | */ |
| 91 | 91 | function auth_echec($raison) { |
| 92 | - include_spip('inc/minipres'); |
|
| 93 | - include_spip('inc/headers'); |
|
| 94 | - // pas authentifie. Pourquoi ? |
|
| 95 | - if (is_string($raison)) { |
|
| 96 | - // redirection vers une page d'authentification |
|
| 97 | - // on ne revient pas de cette fonction |
|
| 98 | - // sauf si pb de header |
|
| 99 | - $raison = redirige_formulaire($raison); |
|
| 100 | - } elseif (is_int($raison)) { |
|
| 101 | - // erreur SQL a afficher |
|
| 102 | - $raison = minipres( |
|
| 103 | - _T('info_travaux_titre'), |
|
| 104 | - _T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>' |
|
| 105 | - ); |
|
| 106 | - } elseif (@$raison['statut']) { |
|
| 107 | - // un simple visiteur n'a pas acces a l'espace prive |
|
| 108 | - spip_log('connexion refusee a ' . @$raison['id_auteur']); |
|
| 109 | - $est_connecte = (!empty($GLOBALS['visiteur_session']['login']) && !empty($GLOBALS['visiteur_session']['statut'])); // idem test balise #URL_LOGOUT |
|
| 110 | - $raison = minipres( |
|
| 111 | - _T('avis_erreur_connexion'), |
|
| 112 | - _T('avis_erreur_visiteur') |
|
| 113 | - // Lien vers le site public |
|
| 114 | - . '<br /><a href="' . url_de_base() . '">' . _T('login_retour_public') . '</a>' |
|
| 115 | - // Si la personne est connectée, lien de déconnexion ramenant vers la page de login |
|
| 116 | - . ($est_connecte ? ' | <a href="' . generer_url_public('', 'action=logout&logout=prive') . '">' . _T('icone_deconnecter') . '</a>' : '') |
|
| 117 | - ); |
|
| 118 | - } else { |
|
| 119 | - // auteur en fin de droits ... |
|
| 120 | - $h = $raison['site']; |
|
| 121 | - $raison = minipres( |
|
| 122 | - _T('avis_erreur_connexion'), |
|
| 123 | - '<br /><br /><p>' |
|
| 124 | - . _T('texte_inc_auth_1', ['auth_login' => $raison['login']]) |
|
| 125 | - . " <a href='$h'>" |
|
| 126 | - . _T('texte_inc_auth_2') |
|
| 127 | - . '</a>' |
|
| 128 | - . _T('texte_inc_auth_3') |
|
| 129 | - ); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return $raison; |
|
| 92 | + include_spip('inc/minipres'); |
|
| 93 | + include_spip('inc/headers'); |
|
| 94 | + // pas authentifie. Pourquoi ? |
|
| 95 | + if (is_string($raison)) { |
|
| 96 | + // redirection vers une page d'authentification |
|
| 97 | + // on ne revient pas de cette fonction |
|
| 98 | + // sauf si pb de header |
|
| 99 | + $raison = redirige_formulaire($raison); |
|
| 100 | + } elseif (is_int($raison)) { |
|
| 101 | + // erreur SQL a afficher |
|
| 102 | + $raison = minipres( |
|
| 103 | + _T('info_travaux_titre'), |
|
| 104 | + _T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>' |
|
| 105 | + ); |
|
| 106 | + } elseif (@$raison['statut']) { |
|
| 107 | + // un simple visiteur n'a pas acces a l'espace prive |
|
| 108 | + spip_log('connexion refusee a ' . @$raison['id_auteur']); |
|
| 109 | + $est_connecte = (!empty($GLOBALS['visiteur_session']['login']) && !empty($GLOBALS['visiteur_session']['statut'])); // idem test balise #URL_LOGOUT |
|
| 110 | + $raison = minipres( |
|
| 111 | + _T('avis_erreur_connexion'), |
|
| 112 | + _T('avis_erreur_visiteur') |
|
| 113 | + // Lien vers le site public |
|
| 114 | + . '<br /><a href="' . url_de_base() . '">' . _T('login_retour_public') . '</a>' |
|
| 115 | + // Si la personne est connectée, lien de déconnexion ramenant vers la page de login |
|
| 116 | + . ($est_connecte ? ' | <a href="' . generer_url_public('', 'action=logout&logout=prive') . '">' . _T('icone_deconnecter') . '</a>' : '') |
|
| 117 | + ); |
|
| 118 | + } else { |
|
| 119 | + // auteur en fin de droits ... |
|
| 120 | + $h = $raison['site']; |
|
| 121 | + $raison = minipres( |
|
| 122 | + _T('avis_erreur_connexion'), |
|
| 123 | + '<br /><br /><p>' |
|
| 124 | + . _T('texte_inc_auth_1', ['auth_login' => $raison['login']]) |
|
| 125 | + . " <a href='$h'>" |
|
| 126 | + . _T('texte_inc_auth_2') |
|
| 127 | + . '</a>' |
|
| 128 | + . _T('texte_inc_auth_3') |
|
| 129 | + ); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return $raison; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -139,79 +139,79 @@ discard block |
||
| 139 | 139 | * @return array|bool|string |
| 140 | 140 | */ |
| 141 | 141 | function auth_mode() { |
| 142 | - // |
|
| 143 | - // Initialiser variables (eviter hacks par URL) |
|
| 144 | - // |
|
| 145 | - $GLOBALS['connect_login'] = ''; |
|
| 146 | - $id_auteur = null; |
|
| 147 | - $GLOBALS['auth_can_disconnect'] = false; |
|
| 148 | - |
|
| 149 | - // |
|
| 150 | - // Recuperer les donnees d'identification |
|
| 151 | - // |
|
| 152 | - include_spip('inc/session'); |
|
| 153 | - // Session valide en cours ? |
|
| 154 | - if ($cookie = lire_cookie_session()) { |
|
| 155 | - $session = charger_fonction('session', 'inc'); |
|
| 156 | - if ( |
|
| 157 | - ($id_auteur = $session()) || $id_auteur === 0 // reprise sur restauration |
|
| 158 | - ) { |
|
| 159 | - $GLOBALS['auth_can_disconnect'] = true; |
|
| 160 | - $GLOBALS['connect_login'] = session_get('login'); |
|
| 161 | - } else { |
|
| 162 | - unset($_COOKIE['spip_session']); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // Essayer auth http si significatif |
|
| 167 | - // (ignorer les login d'intranet independants de spip) |
|
| 168 | - if (!$GLOBALS['ignore_auth_http']) { |
|
| 169 | - if ( |
|
| 170 | - isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) |
|
| 171 | - && ($r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) |
|
| 172 | - // Si auth http differtente de basic, PHP_AUTH_PW |
|
| 173 | - // est indisponible mais tentons quand meme pour |
|
| 174 | - // autocreation via LDAP |
|
| 175 | - || isset($_SERVER['REMOTE_USER']) |
|
| 176 | - && ($r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], '')) |
|
| 177 | - ) { |
|
| 178 | - if (!$id_auteur) { |
|
| 179 | - $_SERVER['PHP_AUTH_PW'] = ''; |
|
| 180 | - $GLOBALS['auth_can_disconnect'] = true; |
|
| 181 | - $GLOBALS['visiteur_session'] = $r; |
|
| 182 | - $GLOBALS['connect_login'] = session_get('login'); |
|
| 183 | - $id_auteur = $r['id_auteur']; |
|
| 184 | - } else { |
|
| 185 | - // cas de la session en plus de PHP_AUTH |
|
| 186 | - /* if ($id_auteur != $r['id_auteur']){ |
|
| 142 | + // |
|
| 143 | + // Initialiser variables (eviter hacks par URL) |
|
| 144 | + // |
|
| 145 | + $GLOBALS['connect_login'] = ''; |
|
| 146 | + $id_auteur = null; |
|
| 147 | + $GLOBALS['auth_can_disconnect'] = false; |
|
| 148 | + |
|
| 149 | + // |
|
| 150 | + // Recuperer les donnees d'identification |
|
| 151 | + // |
|
| 152 | + include_spip('inc/session'); |
|
| 153 | + // Session valide en cours ? |
|
| 154 | + if ($cookie = lire_cookie_session()) { |
|
| 155 | + $session = charger_fonction('session', 'inc'); |
|
| 156 | + if ( |
|
| 157 | + ($id_auteur = $session()) || $id_auteur === 0 // reprise sur restauration |
|
| 158 | + ) { |
|
| 159 | + $GLOBALS['auth_can_disconnect'] = true; |
|
| 160 | + $GLOBALS['connect_login'] = session_get('login'); |
|
| 161 | + } else { |
|
| 162 | + unset($_COOKIE['spip_session']); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // Essayer auth http si significatif |
|
| 167 | + // (ignorer les login d'intranet independants de spip) |
|
| 168 | + if (!$GLOBALS['ignore_auth_http']) { |
|
| 169 | + if ( |
|
| 170 | + isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) |
|
| 171 | + && ($r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) |
|
| 172 | + // Si auth http differtente de basic, PHP_AUTH_PW |
|
| 173 | + // est indisponible mais tentons quand meme pour |
|
| 174 | + // autocreation via LDAP |
|
| 175 | + || isset($_SERVER['REMOTE_USER']) |
|
| 176 | + && ($r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], '')) |
|
| 177 | + ) { |
|
| 178 | + if (!$id_auteur) { |
|
| 179 | + $_SERVER['PHP_AUTH_PW'] = ''; |
|
| 180 | + $GLOBALS['auth_can_disconnect'] = true; |
|
| 181 | + $GLOBALS['visiteur_session'] = $r; |
|
| 182 | + $GLOBALS['connect_login'] = session_get('login'); |
|
| 183 | + $id_auteur = $r['id_auteur']; |
|
| 184 | + } else { |
|
| 185 | + // cas de la session en plus de PHP_AUTH |
|
| 186 | + /* if ($id_auteur != $r['id_auteur']){ |
|
| 187 | 187 | spip_log("vol de session $id_auteur" . join(', ', $r)); |
| 188 | 188 | unset($_COOKIE['spip_session']); |
| 189 | 189 | $id_auteur = ''; |
| 190 | 190 | } */ |
| 191 | - } |
|
| 192 | - } else { |
|
| 193 | - // Authentification .htaccess old style, car .htaccess semble |
|
| 194 | - // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW |
|
| 195 | - if (isset($_SERVER['REMOTE_USER'])) { |
|
| 196 | - $GLOBALS['connect_login'] = $_SERVER['REMOTE_USER']; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - $where = (is_numeric($id_auteur) |
|
| 202 | - /*AND $id_auteur>0*/ // reprise lors des restaurations |
|
| 203 | - ) ? |
|
| 204 | - "id_auteur=$id_auteur" : |
|
| 205 | - (strlen((string) $GLOBALS['connect_login']) ? 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text') : ''); |
|
| 206 | - |
|
| 207 | - if (!$where) { |
|
| 208 | - return ''; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - // Trouver les autres infos dans la table auteurs. |
|
| 212 | - // le champ 'quand' est utilise par l'agenda |
|
| 213 | - |
|
| 214 | - return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'"); |
|
| 191 | + } |
|
| 192 | + } else { |
|
| 193 | + // Authentification .htaccess old style, car .htaccess semble |
|
| 194 | + // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW |
|
| 195 | + if (isset($_SERVER['REMOTE_USER'])) { |
|
| 196 | + $GLOBALS['connect_login'] = $_SERVER['REMOTE_USER']; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + $where = (is_numeric($id_auteur) |
|
| 202 | + /*AND $id_auteur>0*/ // reprise lors des restaurations |
|
| 203 | + ) ? |
|
| 204 | + "id_auteur=$id_auteur" : |
|
| 205 | + (strlen((string) $GLOBALS['connect_login']) ? 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text') : ''); |
|
| 206 | + |
|
| 207 | + if (!$where) { |
|
| 208 | + return ''; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + // Trouver les autres infos dans la table auteurs. |
|
| 212 | + // le champ 'quand' est utilise par l'agenda |
|
| 213 | + |
|
| 214 | + return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'"); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -229,96 +229,96 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | function auth_init_droits($row) { |
| 231 | 231 | |
| 232 | - include_spip('inc/autoriser'); |
|
| 233 | - if (!autoriser('loger', '', 0, $row)) { |
|
| 234 | - return false; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - if ($row['statut'] == 'nouveau') { |
|
| 239 | - include_spip('action/inscrire_auteur'); |
|
| 240 | - $row = confirmer_statut_inscription($row); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - $GLOBALS['connect_id_auteur'] = $row['id_auteur']; |
|
| 244 | - $GLOBALS['connect_login'] = $row['login']; |
|
| 245 | - $GLOBALS['connect_statut'] = $row['statut']; |
|
| 246 | - |
|
| 247 | - $GLOBALS['visiteur_session'] = array_merge((array) $GLOBALS['visiteur_session'], $row); |
|
| 248 | - |
|
| 249 | - // au cas ou : ne pas memoriser les champs sensibles |
|
| 250 | - $GLOBALS['visiteur_session'] = auth_desensibiliser_session($GLOBALS['visiteur_session']); |
|
| 251 | - |
|
| 252 | - // creer la session au besoin |
|
| 253 | - include_spip('inc/session'); |
|
| 254 | - if (!lire_cookie_session()) { |
|
| 255 | - $session = charger_fonction('session', 'inc'); |
|
| 256 | - $spip_session = $session($row); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - // reinjecter les preferences_auteur apres le reset de spip_session |
|
| 260 | - // car utilisees au retour par auth_loger() |
|
| 261 | - $r = @unserialize($row['prefs']); |
|
| 262 | - $GLOBALS['visiteur_session']['prefs'] = ($r ?: []); |
|
| 263 | - // si prefs pas definies, les definir par defaut |
|
| 264 | - if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) { |
|
| 265 | - $GLOBALS['visiteur_session']['prefs']['couleur'] = 2; |
|
| 266 | - $GLOBALS['visiteur_session']['prefs']['display'] = 2; |
|
| 267 | - $GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones'; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - $GLOBALS['visiteur_session'] = pipeline( |
|
| 271 | - 'preparer_visiteur_session', |
|
| 272 | - ['args' => ['row' => $row], |
|
| 273 | - 'data' => $GLOBALS['visiteur_session']] |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - // Etablir les droits selon le codage attendu |
|
| 277 | - // dans ecrire/index.php ecrire/prive.php |
|
| 278 | - |
|
| 279 | - // Pas autorise a acceder a ecrire ? renvoyer le tableau |
|
| 280 | - // A noter : le premier appel a autoriser() a le bon gout |
|
| 281 | - // d'initialiser $GLOBALS['visiteur_session']['restreint'], |
|
| 282 | - // qui ne figure pas dans le fichier de session |
|
| 283 | - |
|
| 284 | - if (!autoriser('ecrire')) { |
|
| 285 | - return $row; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - // autoriser('ecrire') ne laisse passer que les Admin et les Redac |
|
| 289 | - |
|
| 290 | - auth_trace($row); |
|
| 291 | - |
|
| 292 | - // Administrateurs |
|
| 293 | - if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) { |
|
| 294 | - if ( |
|
| 295 | - isset($GLOBALS['visiteur_session']['restreint']) |
|
| 296 | - && is_array($GLOBALS['visiteur_session']['restreint']) |
|
| 297 | - ) { |
|
| 298 | - $GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint']; |
|
| 299 | - } |
|
| 300 | - if ($GLOBALS['connect_statut'] == '0minirezo') { |
|
| 301 | - $GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique']; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - // Pour les redacteurs, inc_version a fait l'initialisation minimale |
|
| 306 | - |
|
| 307 | - return ''; // i.e. pas de pb. |
|
| 232 | + include_spip('inc/autoriser'); |
|
| 233 | + if (!autoriser('loger', '', 0, $row)) { |
|
| 234 | + return false; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + if ($row['statut'] == 'nouveau') { |
|
| 239 | + include_spip('action/inscrire_auteur'); |
|
| 240 | + $row = confirmer_statut_inscription($row); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + $GLOBALS['connect_id_auteur'] = $row['id_auteur']; |
|
| 244 | + $GLOBALS['connect_login'] = $row['login']; |
|
| 245 | + $GLOBALS['connect_statut'] = $row['statut']; |
|
| 246 | + |
|
| 247 | + $GLOBALS['visiteur_session'] = array_merge((array) $GLOBALS['visiteur_session'], $row); |
|
| 248 | + |
|
| 249 | + // au cas ou : ne pas memoriser les champs sensibles |
|
| 250 | + $GLOBALS['visiteur_session'] = auth_desensibiliser_session($GLOBALS['visiteur_session']); |
|
| 251 | + |
|
| 252 | + // creer la session au besoin |
|
| 253 | + include_spip('inc/session'); |
|
| 254 | + if (!lire_cookie_session()) { |
|
| 255 | + $session = charger_fonction('session', 'inc'); |
|
| 256 | + $spip_session = $session($row); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + // reinjecter les preferences_auteur apres le reset de spip_session |
|
| 260 | + // car utilisees au retour par auth_loger() |
|
| 261 | + $r = @unserialize($row['prefs']); |
|
| 262 | + $GLOBALS['visiteur_session']['prefs'] = ($r ?: []); |
|
| 263 | + // si prefs pas definies, les definir par defaut |
|
| 264 | + if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) { |
|
| 265 | + $GLOBALS['visiteur_session']['prefs']['couleur'] = 2; |
|
| 266 | + $GLOBALS['visiteur_session']['prefs']['display'] = 2; |
|
| 267 | + $GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones'; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + $GLOBALS['visiteur_session'] = pipeline( |
|
| 271 | + 'preparer_visiteur_session', |
|
| 272 | + ['args' => ['row' => $row], |
|
| 273 | + 'data' => $GLOBALS['visiteur_session']] |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + // Etablir les droits selon le codage attendu |
|
| 277 | + // dans ecrire/index.php ecrire/prive.php |
|
| 278 | + |
|
| 279 | + // Pas autorise a acceder a ecrire ? renvoyer le tableau |
|
| 280 | + // A noter : le premier appel a autoriser() a le bon gout |
|
| 281 | + // d'initialiser $GLOBALS['visiteur_session']['restreint'], |
|
| 282 | + // qui ne figure pas dans le fichier de session |
|
| 283 | + |
|
| 284 | + if (!autoriser('ecrire')) { |
|
| 285 | + return $row; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + // autoriser('ecrire') ne laisse passer que les Admin et les Redac |
|
| 289 | + |
|
| 290 | + auth_trace($row); |
|
| 291 | + |
|
| 292 | + // Administrateurs |
|
| 293 | + if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) { |
|
| 294 | + if ( |
|
| 295 | + isset($GLOBALS['visiteur_session']['restreint']) |
|
| 296 | + && is_array($GLOBALS['visiteur_session']['restreint']) |
|
| 297 | + ) { |
|
| 298 | + $GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint']; |
|
| 299 | + } |
|
| 300 | + if ($GLOBALS['connect_statut'] == '0minirezo') { |
|
| 301 | + $GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique']; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + // Pour les redacteurs, inc_version a fait l'initialisation minimale |
|
| 306 | + |
|
| 307 | + return ''; // i.e. pas de pb. |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
| 311 | 311 | * Enlever les clés sensibles d'une ligne auteur |
| 312 | 312 | */ |
| 313 | 313 | function auth_desensibiliser_session(array $auteur): array { |
| 314 | - $cles_sensibles = ['pass', 'htpass', 'low_sec', 'alea_actuel', 'alea_futur', 'ldap_password', 'backup_cles']; |
|
| 315 | - foreach ($cles_sensibles as $cle) { |
|
| 316 | - if (array_key_exists($cle, $auteur)) { |
|
| 317 | - unset($auteur[$cle]); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - return $auteur; |
|
| 314 | + $cles_sensibles = ['pass', 'htpass', 'low_sec', 'alea_actuel', 'alea_futur', 'ldap_password', 'backup_cles']; |
|
| 315 | + foreach ($cles_sensibles as $cle) { |
|
| 316 | + if (array_key_exists($cle, $auteur)) { |
|
| 317 | + unset($auteur[$cle]); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + return $auteur; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -327,23 +327,23 @@ discard block |
||
| 327 | 327 | * @return string |
| 328 | 328 | */ |
| 329 | 329 | function auth_a_loger() { |
| 330 | - $redirect = generer_url_public('login', 'url=' . rawurlencode((string) self('&', true)), true); |
|
| 331 | - |
|
| 332 | - // un echec au "bonjour" (login initial) quand le statut est |
|
| 333 | - // inconnu signale sans doute un probleme de cookies |
|
| 334 | - if (isset($_GET['bonjour'])) { |
|
| 335 | - $redirect = parametre_url( |
|
| 336 | - $redirect, |
|
| 337 | - 'var_erreur', |
|
| 338 | - (isset($GLOBALS['visiteur_session']['statut']) |
|
| 339 | - ? 'statut' |
|
| 340 | - : 'cookie' |
|
| 341 | - ), |
|
| 342 | - '&' |
|
| 343 | - ); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - return $redirect; |
|
| 330 | + $redirect = generer_url_public('login', 'url=' . rawurlencode((string) self('&', true)), true); |
|
| 331 | + |
|
| 332 | + // un echec au "bonjour" (login initial) quand le statut est |
|
| 333 | + // inconnu signale sans doute un probleme de cookies |
|
| 334 | + if (isset($_GET['bonjour'])) { |
|
| 335 | + $redirect = parametre_url( |
|
| 336 | + $redirect, |
|
| 337 | + 'var_erreur', |
|
| 338 | + (isset($GLOBALS['visiteur_session']['statut']) |
|
| 339 | + ? 'statut' |
|
| 340 | + : 'cookie' |
|
| 341 | + ), |
|
| 342 | + '&' |
|
| 343 | + ); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + return $redirect; |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -355,19 +355,19 @@ discard block |
||
| 355 | 355 | * @param null|string $date |
| 356 | 356 | */ |
| 357 | 357 | function auth_trace($row, $date = null) { |
| 358 | - // Indiquer la connexion. A la minute pres ca suffit. |
|
| 359 | - if (!is_numeric($connect_quand = $row['quand'] ?? '')) { |
|
| 360 | - $connect_quand = strtotime((string) $connect_quand); |
|
| 361 | - } |
|
| 358 | + // Indiquer la connexion. A la minute pres ca suffit. |
|
| 359 | + if (!is_numeric($connect_quand = $row['quand'] ?? '')) { |
|
| 360 | + $connect_quand = strtotime((string) $connect_quand); |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | - $date ??= date('Y-m-d H:i:s'); |
|
| 363 | + $date ??= date('Y-m-d H:i:s'); |
|
| 364 | 364 | |
| 365 | - if (abs(strtotime($date) - $connect_quand) >= 60) { |
|
| 366 | - sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 367 | - $row['en_ligne'] = $date; |
|
| 368 | - } |
|
| 365 | + if (abs(strtotime($date) - $connect_quand) >= 60) { |
|
| 366 | + sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 367 | + $row['en_ligne'] = $date; |
|
| 368 | + } |
|
| 369 | 369 | |
| 370 | - pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]); |
|
| 370 | + pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | |
@@ -393,27 +393,27 @@ discard block |
||
| 393 | 393 | * @return mixed |
| 394 | 394 | */ |
| 395 | 395 | function auth_administrer($fonction, $args, mixed $defaut = false) { |
| 396 | - $auth_methode = array_shift($args); |
|
| 397 | - $auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou |
|
| 398 | - if ( |
|
| 399 | - ($auth = charger_fonction($auth_methode, 'auth', true)) |
|
| 400 | - && function_exists($f = "auth_{$auth_methode}_$fonction") |
|
| 401 | - ) { |
|
| 402 | - $res = $f(...$args); |
|
| 403 | - } else { |
|
| 404 | - $res = $defaut; |
|
| 405 | - } |
|
| 406 | - return pipeline( |
|
| 407 | - 'auth_administrer', |
|
| 408 | - [ |
|
| 409 | - 'args' => [ |
|
| 410 | - 'fonction' => $fonction, |
|
| 411 | - 'methode' => $auth_methode, |
|
| 412 | - 'args' => $args |
|
| 413 | - ], |
|
| 414 | - 'data' => $res |
|
| 415 | - ] |
|
| 416 | - ); |
|
| 396 | + $auth_methode = array_shift($args); |
|
| 397 | + $auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou |
|
| 398 | + if ( |
|
| 399 | + ($auth = charger_fonction($auth_methode, 'auth', true)) |
|
| 400 | + && function_exists($f = "auth_{$auth_methode}_$fonction") |
|
| 401 | + ) { |
|
| 402 | + $res = $f(...$args); |
|
| 403 | + } else { |
|
| 404 | + $res = $defaut; |
|
| 405 | + } |
|
| 406 | + return pipeline( |
|
| 407 | + 'auth_administrer', |
|
| 408 | + [ |
|
| 409 | + 'args' => [ |
|
| 410 | + 'fonction' => $fonction, |
|
| 411 | + 'methode' => $auth_methode, |
|
| 412 | + 'args' => $args |
|
| 413 | + ], |
|
| 414 | + 'data' => $res |
|
| 415 | + ] |
|
| 416 | + ); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | /** |
@@ -423,11 +423,11 @@ discard block |
||
| 423 | 423 | * @return array |
| 424 | 424 | */ |
| 425 | 425 | function auth_formulaire_login($flux) { |
| 426 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 427 | - $flux = auth_administrer('formulaire_login', [$methode, $flux], $flux); |
|
| 428 | - } |
|
| 426 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 427 | + $flux = auth_administrer('formulaire_login', [$methode, $flux], $flux); |
|
| 428 | + } |
|
| 429 | 429 | |
| 430 | - return $flux; |
|
| 430 | + return $flux; |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | |
@@ -441,19 +441,19 @@ discard block |
||
| 441 | 441 | * @return string/bool |
| 442 | 442 | */ |
| 443 | 443 | function auth_retrouver_login($login, $serveur = '') { |
| 444 | - if (!spip_connect($serveur)) { |
|
| 445 | - include_spip('inc/minipres'); |
|
| 446 | - echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique')); |
|
| 447 | - exit; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 451 | - if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) { |
|
| 452 | - return $auteur; |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - return false; |
|
| 444 | + if (!spip_connect($serveur)) { |
|
| 445 | + include_spip('inc/minipres'); |
|
| 446 | + echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique')); |
|
| 447 | + exit; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 451 | + if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) { |
|
| 452 | + return $auteur; |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + return false; |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | /** |
@@ -468,35 +468,35 @@ discard block |
||
| 468 | 468 | * @return array |
| 469 | 469 | */ |
| 470 | 470 | function auth_informer_login($login, $serveur = '') { |
| 471 | - if ( |
|
| 472 | - !$login |
|
| 473 | - || !($login_base = auth_retrouver_login($login, $serveur)) |
|
| 474 | - || !($row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur)) |
|
| 475 | - ) { |
|
| 476 | - // generer de fausses infos, mais credibles, pour eviter une attaque |
|
| 477 | - // https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691 |
|
| 478 | - |
|
| 479 | - $row = [ |
|
| 480 | - 'login' => $login, |
|
| 481 | - 'cnx' => '0', |
|
| 482 | - 'logo' => '', |
|
| 483 | - ]; |
|
| 484 | - |
|
| 485 | - return $row; |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - $prefs = @unserialize($row['prefs']); |
|
| 489 | - $row = auth_desensibiliser_session($row); |
|
| 490 | - $infos = [ |
|
| 491 | - 'id_auteur' => $row['id_auteur'], |
|
| 492 | - 'login' => $row['login'], |
|
| 493 | - 'cnx' => (isset($prefs['cnx']) && $prefs['cnx'] === 'perma') ? '1' : '0', |
|
| 494 | - 'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row), |
|
| 495 | - ]; |
|
| 496 | - |
|
| 497 | - verifier_visiteur(); |
|
| 498 | - |
|
| 499 | - return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos); |
|
| 471 | + if ( |
|
| 472 | + !$login |
|
| 473 | + || !($login_base = auth_retrouver_login($login, $serveur)) |
|
| 474 | + || !($row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur)) |
|
| 475 | + ) { |
|
| 476 | + // generer de fausses infos, mais credibles, pour eviter une attaque |
|
| 477 | + // https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691 |
|
| 478 | + |
|
| 479 | + $row = [ |
|
| 480 | + 'login' => $login, |
|
| 481 | + 'cnx' => '0', |
|
| 482 | + 'logo' => '', |
|
| 483 | + ]; |
|
| 484 | + |
|
| 485 | + return $row; |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + $prefs = @unserialize($row['prefs']); |
|
| 489 | + $row = auth_desensibiliser_session($row); |
|
| 490 | + $infos = [ |
|
| 491 | + 'id_auteur' => $row['id_auteur'], |
|
| 492 | + 'login' => $row['login'], |
|
| 493 | + 'cnx' => (isset($prefs['cnx']) && $prefs['cnx'] === 'perma') ? '1' : '0', |
|
| 494 | + 'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row), |
|
| 495 | + ]; |
|
| 496 | + |
|
| 497 | + verifier_visiteur(); |
|
| 498 | + |
|
| 499 | + return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | |
@@ -510,21 +510,21 @@ discard block |
||
| 510 | 510 | * @return mixed |
| 511 | 511 | */ |
| 512 | 512 | function auth_identifier_login($login, #[\SensitiveParameter] $password, $serveur = '', bool $phpauth = false) { |
| 513 | - $erreur = ''; |
|
| 514 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 515 | - if ($auth = charger_fonction($methode, 'auth', true)) { |
|
| 516 | - $auteur = $auth($login, $password, $serveur, $phpauth); |
|
| 517 | - if (is_array($auteur) && count($auteur)) { |
|
| 518 | - spip_log("connexion de $login par methode $methode"); |
|
| 519 | - $auteur['auth'] = $methode; |
|
| 520 | - return $auteur; |
|
| 521 | - } elseif (is_string($auteur)) { |
|
| 522 | - $erreur .= "$auteur "; |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - return $erreur; |
|
| 513 | + $erreur = ''; |
|
| 514 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 515 | + if ($auth = charger_fonction($methode, 'auth', true)) { |
|
| 516 | + $auteur = $auth($login, $password, $serveur, $phpauth); |
|
| 517 | + if (is_array($auteur) && count($auteur)) { |
|
| 518 | + spip_log("connexion de $login par methode $methode"); |
|
| 519 | + $auteur['auth'] = $methode; |
|
| 520 | + return $auteur; |
|
| 521 | + } elseif (is_string($auteur)) { |
|
| 522 | + $erreur .= "$auteur "; |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + return $erreur; |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -538,8 +538,8 @@ discard block |
||
| 538 | 538 | * @return string |
| 539 | 539 | */ |
| 540 | 540 | function auth_url_retour_login($auth_methode, $login, $redirect = '', $serveur = '') { |
| 541 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 542 | - return $securiser_action('auth', "$auth_methode/$login", $redirect, true); |
|
| 541 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 542 | + return $securiser_action('auth', "$auth_methode/$login", $redirect, true); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | /** |
@@ -553,8 +553,8 @@ discard block |
||
| 553 | 553 | * @return mixed |
| 554 | 554 | */ |
| 555 | 555 | function auth_terminer_identifier_login($auth_methode, $login, $serveur = '') { |
| 556 | - $args = func_get_args(); |
|
| 557 | - return auth_administrer('terminer_identifier_login', $args); |
|
| 556 | + $args = func_get_args(); |
|
| 557 | + return auth_administrer('terminer_identifier_login', $args); |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | /** |
@@ -564,29 +564,29 @@ discard block |
||
| 564 | 564 | * @return bool |
| 565 | 565 | */ |
| 566 | 566 | function auth_loger($auteur) { |
| 567 | - if (!is_array($auteur) || $auteur === []) { |
|
| 568 | - return false; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - // initialiser et poser le cookie de session |
|
| 572 | - unset($_COOKIE['spip_session']); |
|
| 573 | - if (auth_init_droits($auteur) === false) { |
|
| 574 | - return false; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - // initialiser les prefs |
|
| 578 | - $p = $GLOBALS['visiteur_session']['prefs']; |
|
| 579 | - $p['cnx'] = (isset($auteur['cookie']) && $auteur['cookie'] == 'oui') ? 'perma' : ''; |
|
| 580 | - |
|
| 581 | - sql_updateq( |
|
| 582 | - 'spip_auteurs', |
|
| 583 | - ['prefs' => serialize($p)], |
|
| 584 | - 'id_auteur=' . (int) $auteur['id_auteur'] |
|
| 585 | - ); |
|
| 586 | - |
|
| 587 | - // bloquer ici le visiteur qui tente d'abuser de ses droits |
|
| 588 | - verifier_visiteur(); |
|
| 589 | - return true; |
|
| 567 | + if (!is_array($auteur) || $auteur === []) { |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + // initialiser et poser le cookie de session |
|
| 572 | + unset($_COOKIE['spip_session']); |
|
| 573 | + if (auth_init_droits($auteur) === false) { |
|
| 574 | + return false; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + // initialiser les prefs |
|
| 578 | + $p = $GLOBALS['visiteur_session']['prefs']; |
|
| 579 | + $p['cnx'] = (isset($auteur['cookie']) && $auteur['cookie'] == 'oui') ? 'perma' : ''; |
|
| 580 | + |
|
| 581 | + sql_updateq( |
|
| 582 | + 'spip_auteurs', |
|
| 583 | + ['prefs' => serialize($p)], |
|
| 584 | + 'id_auteur=' . (int) $auteur['id_auteur'] |
|
| 585 | + ); |
|
| 586 | + |
|
| 587 | + // bloquer ici le visiteur qui tente d'abuser de ses droits |
|
| 588 | + verifier_visiteur(); |
|
| 589 | + return true; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | /** |
@@ -596,8 +596,8 @@ discard block |
||
| 596 | 596 | * return void |
| 597 | 597 | **/ |
| 598 | 598 | function auth_deloger() { |
| 599 | - $logout = charger_fonction('logout', 'action'); |
|
| 600 | - $logout(); |
|
| 599 | + $logout = charger_fonction('logout', 'action'); |
|
| 600 | + $logout(); |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | /** |
@@ -611,8 +611,8 @@ discard block |
||
| 611 | 611 | * @return bool |
| 612 | 612 | */ |
| 613 | 613 | function auth_autoriser_modifier_login($auth_methode, $serveur = '') { |
| 614 | - $args = func_get_args(); |
|
| 615 | - return auth_administrer('autoriser_modifier_login', $args); |
|
| 614 | + $args = func_get_args(); |
|
| 615 | + return auth_administrer('autoriser_modifier_login', $args); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -627,8 +627,8 @@ discard block |
||
| 627 | 627 | * message d'erreur ou chaine vide si pas d'erreur |
| 628 | 628 | */ |
| 629 | 629 | function auth_verifier_login($auth_methode, $new_login, $id_auteur = 0, $serveur = '') { |
| 630 | - $args = func_get_args(); |
|
| 631 | - return auth_administrer('verifier_login', $args, ''); |
|
| 630 | + $args = func_get_args(); |
|
| 631 | + return auth_administrer('verifier_login', $args, ''); |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | /** |
@@ -641,8 +641,8 @@ discard block |
||
| 641 | 641 | * @return bool |
| 642 | 642 | */ |
| 643 | 643 | function auth_modifier_login($auth_methode, $new_login, $id_auteur, $serveur = '') { |
| 644 | - $args = func_get_args(); |
|
| 645 | - return auth_administrer('modifier_login', $args); |
|
| 644 | + $args = func_get_args(); |
|
| 645 | + return auth_administrer('modifier_login', $args); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | /** |
@@ -657,8 +657,8 @@ discard block |
||
| 657 | 657 | * succès ou échec |
| 658 | 658 | */ |
| 659 | 659 | function auth_autoriser_modifier_pass($auth_methode, $serveur = '') { |
| 660 | - $args = func_get_args(); |
|
| 661 | - return auth_administrer('autoriser_modifier_pass', $args); |
|
| 660 | + $args = func_get_args(); |
|
| 661 | + return auth_administrer('autoriser_modifier_pass', $args); |
|
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | /** |
@@ -674,8 +674,8 @@ discard block |
||
| 674 | 674 | * message d'erreur ou chaine vide si pas d'erreur |
| 675 | 675 | */ |
| 676 | 676 | function auth_verifier_pass($auth_methode, $login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') { |
| 677 | - $args = func_get_args(); |
|
| 678 | - return auth_administrer('verifier_pass', $args, ''); |
|
| 677 | + $args = func_get_args(); |
|
| 678 | + return auth_administrer('verifier_pass', $args, ''); |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | /** |
@@ -691,8 +691,8 @@ discard block |
||
| 691 | 691 | * succes ou echec |
| 692 | 692 | */ |
| 693 | 693 | function auth_modifier_pass($auth_methode, $login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') { |
| 694 | - $args = func_get_args(); |
|
| 695 | - return auth_administrer('modifier_pass', $args); |
|
| 694 | + $args = func_get_args(); |
|
| 695 | + return auth_administrer('modifier_pass', $args); |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |
@@ -708,24 +708,24 @@ discard block |
||
| 708 | 708 | * @return void |
| 709 | 709 | */ |
| 710 | 710 | function auth_synchroniser_distant( |
| 711 | - $auth_methode = true, |
|
| 712 | - $id_auteur = 0, |
|
| 713 | - $champs = [], |
|
| 714 | - $options = [], |
|
| 715 | - $serveur = '' |
|
| 711 | + $auth_methode = true, |
|
| 712 | + $id_auteur = 0, |
|
| 713 | + $champs = [], |
|
| 714 | + $options = [], |
|
| 715 | + $serveur = '' |
|
| 716 | 716 | ) { |
| 717 | - $args = func_get_args(); |
|
| 718 | - if ($auth_methode === true || isset($options['all']) && $options['all'] == true) { |
|
| 719 | - $options['all'] = true; // ajouter une option all=>true pour chaque auth |
|
| 720 | - $args = [true, $id_auteur, $champs, $options, $serveur]; |
|
| 721 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 722 | - array_shift($args); |
|
| 723 | - array_unshift($args, $methode); |
|
| 724 | - auth_administrer('synchroniser_distant', $args); |
|
| 725 | - } |
|
| 726 | - } else { |
|
| 727 | - auth_administrer('synchroniser_distant', $args); |
|
| 728 | - } |
|
| 717 | + $args = func_get_args(); |
|
| 718 | + if ($auth_methode === true || isset($options['all']) && $options['all'] == true) { |
|
| 719 | + $options['all'] = true; // ajouter une option all=>true pour chaque auth |
|
| 720 | + $args = [true, $id_auteur, $champs, $options, $serveur]; |
|
| 721 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 722 | + array_shift($args); |
|
| 723 | + array_unshift($args, $methode); |
|
| 724 | + auth_administrer('synchroniser_distant', $args); |
|
| 725 | + } |
|
| 726 | + } else { |
|
| 727 | + auth_administrer('synchroniser_distant', $args); |
|
| 728 | + } |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | |
@@ -738,46 +738,46 @@ discard block |
||
| 738 | 738 | * @return array|bool |
| 739 | 739 | */ |
| 740 | 740 | function lire_php_auth($login, #[\SensitiveParameter] $pw, $serveur = '') { |
| 741 | - if ( |
|
| 742 | - !$login |
|
| 743 | - || !$login_base = auth_retrouver_login($login, $serveur) |
|
| 744 | - ) { |
|
| 745 | - return false; |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur); |
|
| 749 | - |
|
| 750 | - if (!$row) { |
|
| 751 | - if ( |
|
| 752 | - include_spip('inc/auth') |
|
| 753 | - && auth_ldap_connect($serveur) |
|
| 754 | - && ($auth_ldap = charger_fonction('ldap', 'auth', true)) |
|
| 755 | - ) { |
|
| 756 | - return $auth_ldap($login_base, $pw, $serveur, true); |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - return false; |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - // si pas de source definie |
|
| 763 | - // ou auth/xxx introuvable, utiliser 'spip' ou autre et avec le login passé par PHP_AUTH_USER |
|
| 764 | - if ( |
|
| 765 | - !($auth_methode = $row['source']) |
|
| 766 | - || !($auth = charger_fonction($auth_methode, 'auth', true)) |
|
| 767 | - ) { |
|
| 768 | - $auth = charger_fonction('spip', 'auth', true); |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - $auteur = ''; |
|
| 772 | - if ($auth) { |
|
| 773 | - $auteur = $auth($login, $pw, $serveur, true); |
|
| 774 | - } |
|
| 775 | - // verifier que ce n'est pas un message d'erreur |
|
| 776 | - if (is_array($auteur) && count($auteur)) { |
|
| 777 | - return $auteur; |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - return false; |
|
| 741 | + if ( |
|
| 742 | + !$login |
|
| 743 | + || !$login_base = auth_retrouver_login($login, $serveur) |
|
| 744 | + ) { |
|
| 745 | + return false; |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur); |
|
| 749 | + |
|
| 750 | + if (!$row) { |
|
| 751 | + if ( |
|
| 752 | + include_spip('inc/auth') |
|
| 753 | + && auth_ldap_connect($serveur) |
|
| 754 | + && ($auth_ldap = charger_fonction('ldap', 'auth', true)) |
|
| 755 | + ) { |
|
| 756 | + return $auth_ldap($login_base, $pw, $serveur, true); |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + return false; |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + // si pas de source definie |
|
| 763 | + // ou auth/xxx introuvable, utiliser 'spip' ou autre et avec le login passé par PHP_AUTH_USER |
|
| 764 | + if ( |
|
| 765 | + !($auth_methode = $row['source']) |
|
| 766 | + || !($auth = charger_fonction($auth_methode, 'auth', true)) |
|
| 767 | + ) { |
|
| 768 | + $auth = charger_fonction('spip', 'auth', true); |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + $auteur = ''; |
|
| 772 | + if ($auth) { |
|
| 773 | + $auteur = $auth($login, $pw, $serveur, true); |
|
| 774 | + } |
|
| 775 | + // verifier que ce n'est pas un message d'erreur |
|
| 776 | + if (is_array($auteur) && count($auteur)) { |
|
| 777 | + return $auteur; |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + return false; |
|
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | /** |
@@ -793,21 +793,21 @@ discard block |
||
| 793 | 793 | * @param string $lien |
| 794 | 794 | */ |
| 795 | 795 | function ask_php_auth($pb, $raison, $retour = '', $url = '', $re = '', $lien = '') { |
| 796 | - @Header('WWW-Authenticate: Basic realm="espace prive"'); |
|
| 797 | - @Header('HTTP/1.0 401 Unauthorized'); |
|
| 798 | - $corps = ''; |
|
| 799 | - $public = generer_url_public(); |
|
| 800 | - $ecrire = generer_url_ecrire(); |
|
| 801 | - $retour = $retour ?: _T('icone_retour'); |
|
| 802 | - $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] "; |
|
| 803 | - if ($url) { |
|
| 804 | - $corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]"; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - if ($lien) { |
|
| 808 | - $corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]'; |
|
| 809 | - } |
|
| 810 | - include_spip('inc/minipres'); |
|
| 811 | - echo minipres($pb, $corps); |
|
| 812 | - exit; |
|
| 796 | + @Header('WWW-Authenticate: Basic realm="espace prive"'); |
|
| 797 | + @Header('HTTP/1.0 401 Unauthorized'); |
|
| 798 | + $corps = ''; |
|
| 799 | + $public = generer_url_public(); |
|
| 800 | + $ecrire = generer_url_ecrire(); |
|
| 801 | + $retour = $retour ?: _T('icone_retour'); |
|
| 802 | + $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] "; |
|
| 803 | + if ($url) { |
|
| 804 | + $corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]"; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + if ($lien) { |
|
| 808 | + $corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]'; |
|
| 809 | + } |
|
| 810 | + include_spip('inc/minipres'); |
|
| 811 | + echo minipres($pb, $corps); |
|
| 812 | + exit; |
|
| 813 | 813 | } |
@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('_TEST_FILE_EXISTS')) { |
| 23 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 24 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 23 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 24 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 30 | 30 | |
| 31 | 31 | if (_SPIP_LOCK_MODE == 2) { |
| 32 | - include_spip('inc/nfslock'); |
|
| 32 | + include_spip('inc/nfslock'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $GLOBALS['liste_verrous'] = []; |
@@ -52,24 +52,24 @@ discard block |
||
| 52 | 52 | * Ressource sur le fichier ouvert, sinon false. |
| 53 | 53 | **/ |
| 54 | 54 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 55 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 56 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 57 | - // verrou |
|
| 58 | - @flock($fl, $verrou); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - return $fl; |
|
| 62 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 63 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 64 | - $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 65 | - |
|
| 66 | - return $fl; |
|
| 67 | - } else { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return @fopen($fichier, $mode); |
|
| 55 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 56 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 57 | + // verrou |
|
| 58 | + @flock($fl, $verrou); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + return $fl; |
|
| 62 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 63 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 64 | + $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 65 | + |
|
| 66 | + return $fl; |
|
| 67 | + } else { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return @fopen($fichier, $mode); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -84,14 +84,14 @@ discard block |
||
| 84 | 84 | * true si succès, false sinon. |
| 85 | 85 | **/ |
| 86 | 86 | function spip_fclose_unlock($handle) { |
| 87 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 88 | - @flock($handle, LOCK_UN); |
|
| 89 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 90 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 91 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return @fclose($handle); |
|
| 87 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 88 | + @flock($handle, LOCK_UN); |
|
| 89 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 90 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 91 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return @fclose($handle); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -105,23 +105,23 @@ discard block |
||
| 105 | 105 | * Contenu du fichier |
| 106 | 106 | **/ |
| 107 | 107 | function spip_file_get_contents($fichier) { |
| 108 | - if (!str_ends_with($fichier, '.gz')) { |
|
| 109 | - if (function_exists('file_get_contents')) { |
|
| 110 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 111 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 112 | - // sinon on fait un file() pour avoir le coeur net |
|
| 113 | - $contenu = @file_get_contents($fichier); |
|
| 114 | - if (!$contenu && _OS_SERVEUR == 'windows') { |
|
| 115 | - $contenu = @file($fichier); |
|
| 116 | - } |
|
| 117 | - } else { |
|
| 118 | - $contenu = @file($fichier); |
|
| 119 | - } |
|
| 120 | - } else { |
|
| 121 | - $contenu = @gzfile($fichier); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return is_array($contenu) ? implode('', $contenu) : (string)$contenu; |
|
| 108 | + if (!str_ends_with($fichier, '.gz')) { |
|
| 109 | + if (function_exists('file_get_contents')) { |
|
| 110 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 111 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 112 | + // sinon on fait un file() pour avoir le coeur net |
|
| 113 | + $contenu = @file_get_contents($fichier); |
|
| 114 | + if (!$contenu && _OS_SERVEUR == 'windows') { |
|
| 115 | + $contenu = @file($fichier); |
|
| 116 | + } |
|
| 117 | + } else { |
|
| 118 | + $contenu = @file($fichier); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + $contenu = @gzfile($fichier); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return is_array($contenu) ? implode('', $contenu) : (string)$contenu; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
@@ -146,48 +146,48 @@ discard block |
||
| 146 | 146 | * true si l'opération a réussie, false sinon. |
| 147 | 147 | **/ |
| 148 | 148 | function lire_fichier($fichier, &$contenu, $options = []) { |
| 149 | - $contenu = ''; |
|
| 150 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 151 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 152 | - if (_TEST_FILE_EXISTS && !@file_exists($fichier)) { |
|
| 153 | - return false; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - #spip_timer('lire_fichier'); |
|
| 157 | - |
|
| 158 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 159 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 160 | - // lire le fichier avant tout |
|
| 161 | - $contenu = spip_file_get_contents($fichier); |
|
| 162 | - |
|
| 163 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 164 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 165 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 166 | - // et eviter un acces disque |
|
| 167 | - if (!$contenu && !@file_exists($fichier)) { |
|
| 168 | - spip_fclose_unlock($fl); |
|
| 169 | - |
|
| 170 | - return false; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - // liberer le verrou |
|
| 174 | - spip_fclose_unlock($fl); |
|
| 175 | - |
|
| 176 | - // Verifications |
|
| 177 | - $ok = true; |
|
| 178 | - if (isset($options['phpcheck']) && $options['phpcheck'] == 'oui') { |
|
| 179 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 183 | - if (!$ok) { |
|
| 184 | - spip_log("echec lecture $fichier"); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $ok; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return false; |
|
| 149 | + $contenu = ''; |
|
| 150 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 151 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 152 | + if (_TEST_FILE_EXISTS && !@file_exists($fichier)) { |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + #spip_timer('lire_fichier'); |
|
| 157 | + |
|
| 158 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 159 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 160 | + // lire le fichier avant tout |
|
| 161 | + $contenu = spip_file_get_contents($fichier); |
|
| 162 | + |
|
| 163 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 164 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 165 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 166 | + // et eviter un acces disque |
|
| 167 | + if (!$contenu && !@file_exists($fichier)) { |
|
| 168 | + spip_fclose_unlock($fl); |
|
| 169 | + |
|
| 170 | + return false; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + // liberer le verrou |
|
| 174 | + spip_fclose_unlock($fl); |
|
| 175 | + |
|
| 176 | + // Verifications |
|
| 177 | + $ok = true; |
|
| 178 | + if (isset($options['phpcheck']) && $options['phpcheck'] == 'oui') { |
|
| 179 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 183 | + if (!$ok) { |
|
| 184 | + spip_log("echec lecture $fichier"); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $ok; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return false; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -215,92 +215,92 @@ discard block |
||
| 215 | 215 | **/ |
| 216 | 216 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 217 | 217 | |
| 218 | - #spip_timer('ecrire_fichier'); |
|
| 219 | - |
|
| 220 | - // verrouiller le fichier destination |
|
| 221 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 222 | - // ecrire les donnees, compressees le cas echeant |
|
| 223 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 224 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 225 | - if (str_ends_with($fichier, '.gz')) { |
|
| 226 | - $contenu = gzencode($contenu); |
|
| 227 | - } |
|
| 228 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 229 | - // pour etre sur d'avoir une operation atomique |
|
| 230 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 231 | - // sauf sous wintruc ou ca ne marche pas |
|
| 232 | - $ok = false; |
|
| 233 | - if ($truncate && _OS_SERVEUR != 'windows') { |
|
| 234 | - if (!function_exists('creer_uniqid')) { |
|
| 235 | - include_spip('inc/acces'); |
|
| 236 | - } |
|
| 237 | - $id = creer_uniqid(); |
|
| 238 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 239 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 240 | - $s = @fwrite($fp2, (string) $contenu, $a = strlen((string) $contenu)); |
|
| 241 | - $ok = ($s === $a); |
|
| 242 | - spip_fclose_unlock($fp2); |
|
| 243 | - spip_fclose_unlock($fp); |
|
| 244 | - $fp = null; |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS || @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - $fp = null; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - // sinon ou si methode precedente a echoueee |
|
| 266 | - // on se rabat sur la methode ancienne |
|
| 267 | - if (!$ok && !is_null($fp)) { |
|
| 268 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 269 | - if ($truncate) { |
|
| 270 | - @ftruncate($fp, 0); |
|
| 271 | - } |
|
| 272 | - $s = @fwrite($fp, $contenu, $a = strlen($contenu)); |
|
| 273 | - |
|
| 274 | - $ok = ($s == $a); |
|
| 275 | - spip_fclose_unlock($fp); |
|
| 276 | - } |
|
| 277 | - // on tente une dernière fois file_put_contents |
|
| 278 | - if (!$ok) { |
|
| 279 | - $l = file_put_contents($fichier, $contenu, $truncate ? LOCK_EX : LOCK_EX | FILE_APPEND); |
|
| 280 | - $ok = ($l === strlen($contenu)); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // liberer le verrou et fermer le fichier |
|
| 284 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 285 | - if ($ok) { |
|
| 286 | - if (str_contains($fichier, '.php')) { |
|
| 287 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - return $ok; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if (!$ignorer_echec) { |
|
| 295 | - include_spip('inc/autoriser'); |
|
| 296 | - if (autoriser('chargerftp')) { |
|
| 297 | - raler_fichier($fichier); |
|
| 298 | - } |
|
| 299 | - spip_unlink($fichier); |
|
| 300 | - } |
|
| 301 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 302 | - |
|
| 303 | - return false; |
|
| 218 | + #spip_timer('ecrire_fichier'); |
|
| 219 | + |
|
| 220 | + // verrouiller le fichier destination |
|
| 221 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 222 | + // ecrire les donnees, compressees le cas echeant |
|
| 223 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 224 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 225 | + if (str_ends_with($fichier, '.gz')) { |
|
| 226 | + $contenu = gzencode($contenu); |
|
| 227 | + } |
|
| 228 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 229 | + // pour etre sur d'avoir une operation atomique |
|
| 230 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 231 | + // sauf sous wintruc ou ca ne marche pas |
|
| 232 | + $ok = false; |
|
| 233 | + if ($truncate && _OS_SERVEUR != 'windows') { |
|
| 234 | + if (!function_exists('creer_uniqid')) { |
|
| 235 | + include_spip('inc/acces'); |
|
| 236 | + } |
|
| 237 | + $id = creer_uniqid(); |
|
| 238 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 239 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 240 | + $s = @fwrite($fp2, (string) $contenu, $a = strlen((string) $contenu)); |
|
| 241 | + $ok = ($s === $a); |
|
| 242 | + spip_fclose_unlock($fp2); |
|
| 243 | + spip_fclose_unlock($fp); |
|
| 244 | + $fp = null; |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS || @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + $fp = null; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + // sinon ou si methode precedente a echoueee |
|
| 266 | + // on se rabat sur la methode ancienne |
|
| 267 | + if (!$ok && !is_null($fp)) { |
|
| 268 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 269 | + if ($truncate) { |
|
| 270 | + @ftruncate($fp, 0); |
|
| 271 | + } |
|
| 272 | + $s = @fwrite($fp, $contenu, $a = strlen($contenu)); |
|
| 273 | + |
|
| 274 | + $ok = ($s == $a); |
|
| 275 | + spip_fclose_unlock($fp); |
|
| 276 | + } |
|
| 277 | + // on tente une dernière fois file_put_contents |
|
| 278 | + if (!$ok) { |
|
| 279 | + $l = file_put_contents($fichier, $contenu, $truncate ? LOCK_EX : LOCK_EX | FILE_APPEND); |
|
| 280 | + $ok = ($l === strlen($contenu)); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // liberer le verrou et fermer le fichier |
|
| 284 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 285 | + if ($ok) { |
|
| 286 | + if (str_contains($fichier, '.php')) { |
|
| 287 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + return $ok; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if (!$ignorer_echec) { |
|
| 295 | + include_spip('inc/autoriser'); |
|
| 296 | + if (autoriser('chargerftp')) { |
|
| 297 | + raler_fichier($fichier); |
|
| 298 | + } |
|
| 299 | + spip_unlink($fichier); |
|
| 300 | + } |
|
| 301 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 302 | + |
|
| 303 | + return false; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -320,12 +320,12 @@ discard block |
||
| 320 | 320 | * Écriture avec troncation ? |
| 321 | 321 | */ |
| 322 | 322 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 323 | - if (!str_ends_with($fichier, '.php')) { |
|
| 324 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 325 | - } |
|
| 326 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 323 | + if (!str_ends_with($fichier, '.php')) { |
|
| 324 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 325 | + } |
|
| 326 | + $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 327 | 327 | |
| 328 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 328 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | |
@@ -336,25 +336,25 @@ discard block |
||
| 336 | 336 | * @return bool |
| 337 | 337 | */ |
| 338 | 338 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
| 339 | - $fichier_tmp = $fichier . '.last'; |
|
| 340 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 341 | - return false; |
|
| 342 | - } |
|
| 343 | - if ( |
|
| 344 | - $force |
|
| 345 | - || !file_exists($fichier) |
|
| 346 | - || md5_file($fichier) !== md5_file($fichier_tmp) |
|
| 347 | - ) { |
|
| 348 | - if ($use_copy) { |
|
| 349 | - @copy($fichier_tmp, $fichier); |
|
| 350 | - } |
|
| 351 | - else { |
|
| 352 | - @rename($fichier_tmp, $fichier); |
|
| 353 | - } |
|
| 354 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 355 | - clearstatcache(true, $fichier); |
|
| 356 | - } |
|
| 357 | - return true; |
|
| 339 | + $fichier_tmp = $fichier . '.last'; |
|
| 340 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 341 | + return false; |
|
| 342 | + } |
|
| 343 | + if ( |
|
| 344 | + $force |
|
| 345 | + || !file_exists($fichier) |
|
| 346 | + || md5_file($fichier) !== md5_file($fichier_tmp) |
|
| 347 | + ) { |
|
| 348 | + if ($use_copy) { |
|
| 349 | + @copy($fichier_tmp, $fichier); |
|
| 350 | + } |
|
| 351 | + else { |
|
| 352 | + @rename($fichier_tmp, $fichier); |
|
| 353 | + } |
|
| 354 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 355 | + clearstatcache(true, $fichier); |
|
| 356 | + } |
|
| 357 | + return true; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | |
@@ -375,12 +375,12 @@ discard block |
||
| 375 | 375 | * true si l'opération a réussie, false sinon. |
| 376 | 376 | */ |
| 377 | 377 | function lire_fichier_securise($fichier, &$contenu, $options = []) { |
| 378 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 379 | - $contenu = substr((string) $contenu, strlen('<?php die (\'Acces interdit\'); ?> |
|
| 378 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 379 | + $contenu = substr((string) $contenu, strlen('<?php die (\'Acces interdit\'); ?> |
|
| 380 | 380 | ')); |
| 381 | - } |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | - return $res; |
|
| 383 | + return $res; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -392,25 +392,25 @@ discard block |
||
| 392 | 392 | * @uses minipres() Pour afficher le message |
| 393 | 393 | **/ |
| 394 | 394 | function raler_fichier(string $fichier): never { |
| 395 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 396 | - spip_initialisation_suite(); |
|
| 397 | - } |
|
| 398 | - include_spip('inc/minipres'); |
|
| 399 | - $dir = dirname($fichier); |
|
| 400 | - http_response_code(401); |
|
| 401 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 402 | - . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 403 | - . " <a href='" |
|
| 404 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 405 | - . "'>" |
|
| 406 | - . _T('texte_inc_meta_2') |
|
| 407 | - . '</a> ' |
|
| 408 | - . _T( |
|
| 409 | - 'texte_inc_meta_3', |
|
| 410 | - ['repertoire' => joli_repertoire($dir)] |
|
| 411 | - ) |
|
| 412 | - . "</h4>\n"); |
|
| 413 | - exit; |
|
| 395 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 396 | + spip_initialisation_suite(); |
|
| 397 | + } |
|
| 398 | + include_spip('inc/minipres'); |
|
| 399 | + $dir = dirname($fichier); |
|
| 400 | + http_response_code(401); |
|
| 401 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 402 | + . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 403 | + . " <a href='" |
|
| 404 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 405 | + . "'>" |
|
| 406 | + . _T('texte_inc_meta_2') |
|
| 407 | + . '</a> ' |
|
| 408 | + . _T( |
|
| 409 | + 'texte_inc_meta_3', |
|
| 410 | + ['repertoire' => joli_repertoire($dir)] |
|
| 411 | + ) |
|
| 412 | + . "</h4>\n"); |
|
| 413 | + exit; |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | |
@@ -425,14 +425,14 @@ discard block |
||
| 425 | 425 | * - true si récent, false sinon |
| 426 | 426 | */ |
| 427 | 427 | function jeune_fichier($fichier, $n) { |
| 428 | - if (!file_exists($fichier)) { |
|
| 429 | - return false; |
|
| 430 | - } |
|
| 431 | - if (!$c = @filemtime($fichier)) { |
|
| 432 | - return false; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - return (time() - $n <= $c); |
|
| 428 | + if (!file_exists($fichier)) { |
|
| 429 | + return false; |
|
| 430 | + } |
|
| 431 | + if (!$c = @filemtime($fichier)) { |
|
| 432 | + return false; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + return (time() - $n <= $c); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
@@ -447,22 +447,22 @@ discard block |
||
| 447 | 447 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 448 | 448 | */ |
| 449 | 449 | function supprimer_fichier($fichier, $lock = true) { |
| 450 | - if (!@file_exists($fichier)) { |
|
| 451 | - return true; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - if ($lock) { |
|
| 455 | - // verrouiller le fichier destination |
|
| 456 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 457 | - return false; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - // liberer le verrou |
|
| 461 | - spip_fclose_unlock($fp); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - // supprimer |
|
| 465 | - return @unlink($fichier); |
|
| 450 | + if (!@file_exists($fichier)) { |
|
| 451 | + return true; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + if ($lock) { |
|
| 455 | + // verrouiller le fichier destination |
|
| 456 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 457 | + return false; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + // liberer le verrou |
|
| 461 | + spip_fclose_unlock($fp); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + // supprimer |
|
| 465 | + return @unlink($fichier); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -472,12 +472,12 @@ discard block |
||
| 472 | 472 | * Chemin du fichier |
| 473 | 473 | */ |
| 474 | 474 | function spip_unlink($f) { |
| 475 | - if (!is_dir($f)) { |
|
| 476 | - supprimer_fichier($f, false); |
|
| 477 | - } else { |
|
| 478 | - @unlink("$f/.ok"); |
|
| 479 | - @rmdir($f); |
|
| 480 | - } |
|
| 475 | + if (!is_dir($f)) { |
|
| 476 | + supprimer_fichier($f, false); |
|
| 477 | + } else { |
|
| 478 | + @unlink("$f/.ok"); |
|
| 479 | + @rmdir($f); |
|
| 480 | + } |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
@@ -491,26 +491,26 @@ discard block |
||
| 491 | 491 | * The absolute path of the PHP file to invalidate. |
| 492 | 492 | */ |
| 493 | 493 | function spip_clear_opcode_cache($filepath) { |
| 494 | - clearstatcache(true, $filepath); |
|
| 495 | - |
|
| 496 | - // Zend OPcache |
|
| 497 | - if (function_exists('opcache_invalidate')) { |
|
| 498 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 499 | - // si l'invalidation a echoue lever un flag |
|
| 500 | - if (!$invalidate && !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 501 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | - } |
|
| 503 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 504 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 505 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 506 | - } |
|
| 507 | - // APC. |
|
| 508 | - if (function_exists('apc_delete_file')) { |
|
| 509 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 510 | - // not compiled yet. |
|
| 511 | - // @see http://php.net/apc-delete-file |
|
| 512 | - @apc_delete_file($filepath); |
|
| 513 | - } |
|
| 494 | + clearstatcache(true, $filepath); |
|
| 495 | + |
|
| 496 | + // Zend OPcache |
|
| 497 | + if (function_exists('opcache_invalidate')) { |
|
| 498 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 499 | + // si l'invalidation a echoue lever un flag |
|
| 500 | + if (!$invalidate && !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 501 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | + } |
|
| 503 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 504 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 505 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 506 | + } |
|
| 507 | + // APC. |
|
| 508 | + if (function_exists('apc_delete_file')) { |
|
| 509 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 510 | + // not compiled yet. |
|
| 511 | + // @see http://php.net/apc-delete-file |
|
| 512 | + @apc_delete_file($filepath); |
|
| 513 | + } |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
@@ -533,25 +533,25 @@ discard block |
||
| 533 | 533 | * |
| 534 | 534 | */ |
| 535 | 535 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 536 | - if ( |
|
| 537 | - function_exists('opcache_get_configuration') |
|
| 538 | - && @ini_get('opcache.enable') |
|
| 539 | - && @ini_get('opcache.validate_timestamps') |
|
| 540 | - && (($duree = (int) @ini_get('opcache.revalidate_freq')) || ($duree = 2)) |
|
| 541 | - && defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 542 | - ) { |
|
| 543 | - $wait = $duree + 1; |
|
| 544 | - if ($timestamp) { |
|
| 545 | - $wait -= (time() - $timestamp); |
|
| 546 | - if ($wait < 0) { |
|
| 547 | - $wait = 0; |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 551 | - if ($wait) { |
|
| 552 | - sleep($duree + 1); |
|
| 553 | - } |
|
| 554 | - } |
|
| 536 | + if ( |
|
| 537 | + function_exists('opcache_get_configuration') |
|
| 538 | + && @ini_get('opcache.enable') |
|
| 539 | + && @ini_get('opcache.validate_timestamps') |
|
| 540 | + && (($duree = (int) @ini_get('opcache.revalidate_freq')) || ($duree = 2)) |
|
| 541 | + && defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 542 | + ) { |
|
| 543 | + $wait = $duree + 1; |
|
| 544 | + if ($timestamp) { |
|
| 545 | + $wait -= (time() - $timestamp); |
|
| 546 | + if ($wait < 0) { |
|
| 547 | + $wait = 0; |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 551 | + if ($wait) { |
|
| 552 | + sleep($duree + 1); |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | |
@@ -564,26 +564,26 @@ discard block |
||
| 564 | 564 | * @return bool Suppression reussie. |
| 565 | 565 | */ |
| 566 | 566 | function supprimer_repertoire($dir) { |
| 567 | - if (!file_exists($dir)) { |
|
| 568 | - return true; |
|
| 569 | - } |
|
| 570 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 571 | - return @unlink($dir); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - foreach (scandir($dir) as $item) { |
|
| 575 | - if ($item == '.' || $item == '..') { |
|
| 576 | - continue; |
|
| 577 | - } |
|
| 578 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 579 | - @chmod($dir . '/' . $item, 0777); |
|
| 580 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 581 | - return false; |
|
| 582 | - } |
|
| 583 | - }; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - return @rmdir($dir); |
|
| 567 | + if (!file_exists($dir)) { |
|
| 568 | + return true; |
|
| 569 | + } |
|
| 570 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 571 | + return @unlink($dir); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + foreach (scandir($dir) as $item) { |
|
| 575 | + if ($item == '.' || $item == '..') { |
|
| 576 | + continue; |
|
| 577 | + } |
|
| 578 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 579 | + @chmod($dir . '/' . $item, 0777); |
|
| 580 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 581 | + return false; |
|
| 582 | + } |
|
| 583 | + }; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + return @rmdir($dir); |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | |
@@ -612,58 +612,58 @@ discard block |
||
| 612 | 612 | * Chemin du répertoire créé. |
| 613 | 613 | **/ |
| 614 | 614 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false): string { |
| 615 | - static $dirs = []; |
|
| 616 | - |
|
| 617 | - $base = str_replace('//', '/', $base); |
|
| 618 | - |
|
| 619 | - # suppr le dernier caractere si c'est un / |
|
| 620 | - $base = rtrim($base, '/'); |
|
| 621 | - |
|
| 622 | - if (!strlen($subdir)) { |
|
| 623 | - $n = strrpos($base, '/'); |
|
| 624 | - if ($n === false) { |
|
| 625 | - return $nobase ? '' : ($base . '/'); |
|
| 626 | - } |
|
| 627 | - $subdir = substr($base, $n + 1); |
|
| 628 | - $base = substr($base, 0, $n + 1); |
|
| 629 | - } else { |
|
| 630 | - $base .= '/'; |
|
| 631 | - $subdir = str_replace('/', '', $subdir); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - $baseaff = $nobase ? '' : $base; |
|
| 635 | - if (isset($dirs[$base . $subdir])) { |
|
| 636 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 640 | - |
|
| 641 | - if (file_exists("$path/.ok")) { |
|
| 642 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - @mkdir($path, _SPIP_CHMOD); |
|
| 646 | - @chmod($path, _SPIP_CHMOD); |
|
| 647 | - |
|
| 648 | - if (is_dir($path) && is_writable($path)) { |
|
| 649 | - @touch("$path/.ok"); |
|
| 650 | - spip_log("creation $base$subdir/"); |
|
| 651 | - |
|
| 652 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 656 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 657 | - spip_log("echec creation $base{$subdir}"); |
|
| 658 | - if ($tantpis) { |
|
| 659 | - return ''; |
|
| 660 | - } |
|
| 661 | - // FIXME: throw an Exception… |
|
| 662 | - if (!_DIR_RESTREINT) { |
|
| 663 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 664 | - } |
|
| 665 | - $base .= $subdir; |
|
| 666 | - raler_fichier($base . '/.ok'); |
|
| 615 | + static $dirs = []; |
|
| 616 | + |
|
| 617 | + $base = str_replace('//', '/', $base); |
|
| 618 | + |
|
| 619 | + # suppr le dernier caractere si c'est un / |
|
| 620 | + $base = rtrim($base, '/'); |
|
| 621 | + |
|
| 622 | + if (!strlen($subdir)) { |
|
| 623 | + $n = strrpos($base, '/'); |
|
| 624 | + if ($n === false) { |
|
| 625 | + return $nobase ? '' : ($base . '/'); |
|
| 626 | + } |
|
| 627 | + $subdir = substr($base, $n + 1); |
|
| 628 | + $base = substr($base, 0, $n + 1); |
|
| 629 | + } else { |
|
| 630 | + $base .= '/'; |
|
| 631 | + $subdir = str_replace('/', '', $subdir); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + $baseaff = $nobase ? '' : $base; |
|
| 635 | + if (isset($dirs[$base . $subdir])) { |
|
| 636 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 640 | + |
|
| 641 | + if (file_exists("$path/.ok")) { |
|
| 642 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + @mkdir($path, _SPIP_CHMOD); |
|
| 646 | + @chmod($path, _SPIP_CHMOD); |
|
| 647 | + |
|
| 648 | + if (is_dir($path) && is_writable($path)) { |
|
| 649 | + @touch("$path/.ok"); |
|
| 650 | + spip_log("creation $base$subdir/"); |
|
| 651 | + |
|
| 652 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 656 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 657 | + spip_log("echec creation $base{$subdir}"); |
|
| 658 | + if ($tantpis) { |
|
| 659 | + return ''; |
|
| 660 | + } |
|
| 661 | + // FIXME: throw an Exception… |
|
| 662 | + if (!_DIR_RESTREINT) { |
|
| 663 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 664 | + } |
|
| 665 | + $base .= $subdir; |
|
| 666 | + raler_fichier($base . '/.ok'); |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | |
@@ -696,55 +696,55 @@ discard block |
||
| 696 | 696 | * Chemins des fichiers trouvés. |
| 697 | 697 | **/ |
| 698 | 698 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) { |
| 699 | - $nbfiles = 0; |
|
| 700 | - if ($pattern == -1) { |
|
| 701 | - $pattern = ''; |
|
| 702 | - } |
|
| 703 | - $fichiers = []; |
|
| 704 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 705 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 706 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 707 | - if ($dir == '') { |
|
| 708 | - $dir = '.'; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 712 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 713 | - if ( |
|
| 714 | - $f[0] != '.' |
|
| 715 | - && $f != 'remove.txt' |
|
| 716 | - && is_readable($f = "$dir/$f") |
|
| 717 | - ) { |
|
| 718 | - if (is_file($f)) { |
|
| 719 | - if (!$pattern || preg_match(";$pattern;iS", $f)) { |
|
| 720 | - $fichiers[] = $f; |
|
| 721 | - $nbfiles++; |
|
| 722 | - } |
|
| 723 | - } else { |
|
| 724 | - if (is_dir($f) && is_array($recurs)) { |
|
| 725 | - $rp = @realpath($f); |
|
| 726 | - if (!is_string($rp) || !strlen($rp)) { |
|
| 727 | - $rp = $f; |
|
| 728 | - } # realpath n'est peut etre pas autorise |
|
| 729 | - if (!isset($recurs[$rp])) { |
|
| 730 | - $recurs[$rp] = true; |
|
| 731 | - $beginning = $fichiers; |
|
| 732 | - $end = preg_files( |
|
| 733 | - "$f/", |
|
| 734 | - $pattern, |
|
| 735 | - $maxfiles - $nbfiles, |
|
| 736 | - $recurs |
|
| 737 | - ); |
|
| 738 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 739 | - $nbfiles = count($fichiers); |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - } |
|
| 744 | - } |
|
| 745 | - closedir($d); |
|
| 746 | - } |
|
| 747 | - sort($fichiers); |
|
| 748 | - |
|
| 749 | - return $fichiers; |
|
| 699 | + $nbfiles = 0; |
|
| 700 | + if ($pattern == -1) { |
|
| 701 | + $pattern = ''; |
|
| 702 | + } |
|
| 703 | + $fichiers = []; |
|
| 704 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 705 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 706 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 707 | + if ($dir == '') { |
|
| 708 | + $dir = '.'; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 712 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 713 | + if ( |
|
| 714 | + $f[0] != '.' |
|
| 715 | + && $f != 'remove.txt' |
|
| 716 | + && is_readable($f = "$dir/$f") |
|
| 717 | + ) { |
|
| 718 | + if (is_file($f)) { |
|
| 719 | + if (!$pattern || preg_match(";$pattern;iS", $f)) { |
|
| 720 | + $fichiers[] = $f; |
|
| 721 | + $nbfiles++; |
|
| 722 | + } |
|
| 723 | + } else { |
|
| 724 | + if (is_dir($f) && is_array($recurs)) { |
|
| 725 | + $rp = @realpath($f); |
|
| 726 | + if (!is_string($rp) || !strlen($rp)) { |
|
| 727 | + $rp = $f; |
|
| 728 | + } # realpath n'est peut etre pas autorise |
|
| 729 | + if (!isset($recurs[$rp])) { |
|
| 730 | + $recurs[$rp] = true; |
|
| 731 | + $beginning = $fichiers; |
|
| 732 | + $end = preg_files( |
|
| 733 | + "$f/", |
|
| 734 | + $pattern, |
|
| 735 | + $maxfiles - $nbfiles, |
|
| 736 | + $recurs |
|
| 737 | + ); |
|
| 738 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 739 | + $nbfiles = count($fichiers); |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | + } |
|
| 745 | + closedir($d); |
|
| 746 | + } |
|
| 747 | + sort($fichiers); |
|
| 748 | + |
|
| 749 | + return $fichiers; |
|
| 750 | 750 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Notifications |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | |
@@ -32,16 +32,16 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function inc_notifications_dist($quoi, $id = 0, $options = []) { |
| 34 | 34 | |
| 35 | - // charger les fichiers qui veulent ajouter des definitions |
|
| 36 | - // ou faire des trucs aussi dans le pipeline, ca fait deux api pour le prix d'une ... |
|
| 37 | - pipeline('notifications', ['args' => ['quoi' => $quoi, 'id' => $id, 'options' => $options]]); |
|
| 35 | + // charger les fichiers qui veulent ajouter des definitions |
|
| 36 | + // ou faire des trucs aussi dans le pipeline, ca fait deux api pour le prix d'une ... |
|
| 37 | + pipeline('notifications', ['args' => ['quoi' => $quoi, 'id' => $id, 'options' => $options]]); |
|
| 38 | 38 | |
| 39 | - if ($notification = charger_fonction($quoi, 'notifications', true)) { |
|
| 40 | - spip_log("$notification($quoi,$id" |
|
| 41 | - . ($options ? ',' . serialize($options) : '') |
|
| 42 | - . ')', 'notifications'); |
|
| 43 | - $notification($quoi, $id, $options); |
|
| 44 | - } |
|
| 39 | + if ($notification = charger_fonction($quoi, 'notifications', true)) { |
|
| 40 | + spip_log("$notification($quoi,$id" |
|
| 41 | + . ($options ? ',' . serialize($options) : '') |
|
| 42 | + . ')', 'notifications'); |
|
| 43 | + $notification($quoi, $id, $options); |
|
| 44 | + } |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -55,15 +55,15 @@ discard block |
||
| 55 | 55 | * @param array $exclure |
| 56 | 56 | */ |
| 57 | 57 | function notifications_nettoyer_emails(&$emails, $exclure = []) { |
| 58 | - // filtrer et unifier |
|
| 59 | - include_spip('inc/filtres'); |
|
| 60 | - $emails = array_unique(array_filter(array_map('email_valide', array_map('trim', $emails)))); |
|
| 61 | - if ($exclure && count($exclure)) { |
|
| 62 | - // nettoyer les exclusions d'abord |
|
| 63 | - notifications_nettoyer_emails($exclure); |
|
| 64 | - // faire un diff |
|
| 65 | - $emails = array_diff($emails, $exclure); |
|
| 66 | - } |
|
| 58 | + // filtrer et unifier |
|
| 59 | + include_spip('inc/filtres'); |
|
| 60 | + $emails = array_unique(array_filter(array_map('email_valide', array_map('trim', $emails)))); |
|
| 61 | + if ($exclure && count($exclure)) { |
|
| 62 | + // nettoyer les exclusions d'abord |
|
| 63 | + notifications_nettoyer_emails($exclure); |
|
| 64 | + // faire un diff |
|
| 65 | + $emails = array_diff($emails, $exclure); |
|
| 66 | + } |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -78,90 +78,90 @@ discard block |
||
| 78 | 78 | * @param string $headers |
| 79 | 79 | */ |
| 80 | 80 | function notifications_envoyer_mails($emails, $texte, $sujet = '', $from = '', $headers = '') { |
| 81 | - // rien a faire si pas de texte ! |
|
| 82 | - if (!strlen($texte)) { |
|
| 83 | - return; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // si on ne specifie qu'un email, le mettre dans un tableau |
|
| 87 | - if (!is_array($emails)) { |
|
| 88 | - $emails = explode(',', $emails); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - notifications_nettoyer_emails($emails); |
|
| 92 | - |
|
| 93 | - // tester si le mail est deja en html |
|
| 94 | - if ( |
|
| 95 | - str_contains($texte, '<') |
|
| 96 | - && ($ttrim = trim($texte)) |
|
| 97 | - && str_starts_with($ttrim, '<') |
|
| 98 | - && str_ends_with($ttrim, '>') |
|
| 99 | - && stripos($ttrim, '</html>') !== false |
|
| 100 | - ) { |
|
| 101 | - if (!strlen($sujet)) { |
|
| 102 | - // dans ce cas on ruse un peu : extraire le sujet du title |
|
| 103 | - if (preg_match(',<title>(.*)</title>,Uims', $texte, $m)) { |
|
| 104 | - $sujet = $m[1]; |
|
| 105 | - } else { |
|
| 106 | - // fallback, on prend le body si on le trouve |
|
| 107 | - if (preg_match(',<body[^>]*>(.*)</body>,Uims', $texte, $m)) { |
|
| 108 | - $ttrim = $m[1]; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // et on extrait la premiere ligne de vrai texte... |
|
| 112 | - // nettoyer le html et les retours chariots |
|
| 113 | - $ttrim = textebrut($ttrim); |
|
| 114 | - $ttrim = str_replace("\r\n", "\r", $ttrim); |
|
| 115 | - $ttrim = str_replace("\r", "\n", $ttrim); |
|
| 116 | - // decouper |
|
| 117 | - $ttrim = explode("\n", trim($ttrim)); |
|
| 118 | - // extraire la premiere ligne de texte brut |
|
| 119 | - $sujet = array_shift($ttrim); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // si besoin on ajoute le content-type dans les headers |
|
| 124 | - if (stripos($headers, 'Content-Type') === false) { |
|
| 125 | - $headers .= "Content-Type: text/html\n"; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // si le sujet est vide, extraire la premiere ligne du corps |
|
| 130 | - // du mail qui est donc du texte |
|
| 131 | - if (!strlen($sujet)) { |
|
| 132 | - // nettoyer un peu les retours chariots |
|
| 133 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 134 | - $texte = str_replace("\r", "\n", $texte); |
|
| 135 | - // decouper |
|
| 136 | - $texte = explode("\n", trim($texte)); |
|
| 137 | - // extraire la premiere ligne |
|
| 138 | - $sujet = array_shift($texte); |
|
| 139 | - $texte = trim(implode("\n", $texte)); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); |
|
| 143 | - foreach ($emails as $email) { |
|
| 144 | - // passer dans un pipeline qui permet un ajout eventuel |
|
| 145 | - // (url de suivi des notifications par exemple) |
|
| 146 | - $envoi = pipeline( |
|
| 147 | - 'notifications_envoyer_mails', |
|
| 148 | - [ |
|
| 149 | - 'email' => $email, |
|
| 150 | - 'sujet' => $sujet, |
|
| 151 | - 'texte' => $texte, |
|
| 152 | - 'from' => $from, |
|
| 153 | - 'headers' => $headers, |
|
| 154 | - ] |
|
| 155 | - ); |
|
| 156 | - $email = $envoi['email']; |
|
| 157 | - |
|
| 158 | - job_queue_add( |
|
| 159 | - 'envoyer_mail', |
|
| 160 | - ">$email : " . $envoi['sujet'], |
|
| 161 | - [$email, $envoi['sujet'], $envoi['texte'], $envoi['from'], $envoi['headers']], |
|
| 162 | - 'inc/' |
|
| 163 | - ); |
|
| 164 | - } |
|
| 81 | + // rien a faire si pas de texte ! |
|
| 82 | + if (!strlen($texte)) { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // si on ne specifie qu'un email, le mettre dans un tableau |
|
| 87 | + if (!is_array($emails)) { |
|
| 88 | + $emails = explode(',', $emails); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + notifications_nettoyer_emails($emails); |
|
| 92 | + |
|
| 93 | + // tester si le mail est deja en html |
|
| 94 | + if ( |
|
| 95 | + str_contains($texte, '<') |
|
| 96 | + && ($ttrim = trim($texte)) |
|
| 97 | + && str_starts_with($ttrim, '<') |
|
| 98 | + && str_ends_with($ttrim, '>') |
|
| 99 | + && stripos($ttrim, '</html>') !== false |
|
| 100 | + ) { |
|
| 101 | + if (!strlen($sujet)) { |
|
| 102 | + // dans ce cas on ruse un peu : extraire le sujet du title |
|
| 103 | + if (preg_match(',<title>(.*)</title>,Uims', $texte, $m)) { |
|
| 104 | + $sujet = $m[1]; |
|
| 105 | + } else { |
|
| 106 | + // fallback, on prend le body si on le trouve |
|
| 107 | + if (preg_match(',<body[^>]*>(.*)</body>,Uims', $texte, $m)) { |
|
| 108 | + $ttrim = $m[1]; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // et on extrait la premiere ligne de vrai texte... |
|
| 112 | + // nettoyer le html et les retours chariots |
|
| 113 | + $ttrim = textebrut($ttrim); |
|
| 114 | + $ttrim = str_replace("\r\n", "\r", $ttrim); |
|
| 115 | + $ttrim = str_replace("\r", "\n", $ttrim); |
|
| 116 | + // decouper |
|
| 117 | + $ttrim = explode("\n", trim($ttrim)); |
|
| 118 | + // extraire la premiere ligne de texte brut |
|
| 119 | + $sujet = array_shift($ttrim); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // si besoin on ajoute le content-type dans les headers |
|
| 124 | + if (stripos($headers, 'Content-Type') === false) { |
|
| 125 | + $headers .= "Content-Type: text/html\n"; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // si le sujet est vide, extraire la premiere ligne du corps |
|
| 130 | + // du mail qui est donc du texte |
|
| 131 | + if (!strlen($sujet)) { |
|
| 132 | + // nettoyer un peu les retours chariots |
|
| 133 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 134 | + $texte = str_replace("\r", "\n", $texte); |
|
| 135 | + // decouper |
|
| 136 | + $texte = explode("\n", trim($texte)); |
|
| 137 | + // extraire la premiere ligne |
|
| 138 | + $sujet = array_shift($texte); |
|
| 139 | + $texte = trim(implode("\n", $texte)); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); |
|
| 143 | + foreach ($emails as $email) { |
|
| 144 | + // passer dans un pipeline qui permet un ajout eventuel |
|
| 145 | + // (url de suivi des notifications par exemple) |
|
| 146 | + $envoi = pipeline( |
|
| 147 | + 'notifications_envoyer_mails', |
|
| 148 | + [ |
|
| 149 | + 'email' => $email, |
|
| 150 | + 'sujet' => $sujet, |
|
| 151 | + 'texte' => $texte, |
|
| 152 | + 'from' => $from, |
|
| 153 | + 'headers' => $headers, |
|
| 154 | + ] |
|
| 155 | + ); |
|
| 156 | + $email = $envoi['email']; |
|
| 157 | + |
|
| 158 | + job_queue_add( |
|
| 159 | + 'envoyer_mail', |
|
| 160 | + ">$email : " . $envoi['sujet'], |
|
| 161 | + [$email, $envoi['sujet'], $envoi['texte'], $envoi['from'], $envoi['headers']], |
|
| 162 | + 'inc/' |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -177,10 +177,10 @@ discard block |
||
| 177 | 177 | * @return string |
| 178 | 178 | */ |
| 179 | 179 | function email_notification_objet($id_objet, $type_objet, $modele) { |
| 180 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 181 | - $id_type = id_table_objet($type_objet); |
|
| 180 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 181 | + $id_type = id_table_objet($type_objet); |
|
| 182 | 182 | |
| 183 | - return recuperer_fond($modele, [$id_type => $id_objet, 'id' => $id_objet]); |
|
| 183 | + return recuperer_fond($modele, [$id_type => $id_objet, 'id' => $id_objet]); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | 197 | function email_notification_article($id_article, $modele) { |
| 198 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 198 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 199 | 199 | |
| 200 | - return recuperer_fond($modele, ['id_article' => $id_article]); |
|
| 200 | + return recuperer_fond($modele, ['id_article' => $id_article]); |
|
| 201 | 201 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Autorisations |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('base/abstract_sql'); |
@@ -37,89 +37,89 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | |
| 39 | 39 | if (!function_exists('autoriser')) { |
| 40 | - /** |
|
| 41 | - * Autoriser une action |
|
| 42 | - * |
|
| 43 | - * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 44 | - * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 45 | - * les autorisations. |
|
| 46 | - * |
|
| 47 | - * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 48 | - * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 49 | - * dans cet ordre : |
|
| 50 | - * |
|
| 51 | - * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 52 | - * - autoriser_{type}, sinon avec _dist |
|
| 53 | - * - autoriser_{faire}, sinon avec _dist |
|
| 54 | - * - autoriser_{defaut}, sinon avec _dist |
|
| 55 | - * |
|
| 56 | - * Seul le premier argument est obligatoire. |
|
| 57 | - * |
|
| 58 | - * @note |
|
| 59 | - * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 60 | - * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 61 | - * cette valeur. |
|
| 62 | - * |
|
| 63 | - * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 64 | - * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 65 | - * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 66 | - * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 67 | - * |
|
| 68 | - * @note |
|
| 69 | - * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 70 | - * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 71 | - * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 72 | - * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 73 | - * quel serait le type, quel serait l'action ? |
|
| 74 | - * |
|
| 75 | - * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 76 | - * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 77 | - * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 78 | - * |
|
| 79 | - * @api |
|
| 80 | - * @see autoriser_dist() |
|
| 81 | - * @see objet_type() |
|
| 82 | - * |
|
| 83 | - * @param string $faire |
|
| 84 | - * une action ('modifier', 'publier'...) |
|
| 85 | - * @param string|null $type |
|
| 86 | - * Type d’objet ou élément sur lequel appliquer l’action. |
|
| 87 | - * - null: indifférent à tout type d’élément ou objet éditorial |
|
| 88 | - * - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée) |
|
| 89 | - * - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()). |
|
| 90 | - * Les soulignés seront retirés (cf. la note). |
|
| 91 | - * @param string|int|null $id |
|
| 92 | - * id de l'objet ou élément sur lequel on veut agir, si pertinent. |
|
| 93 | - * - null: non utile pour l’autorisation |
|
| 94 | - * - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP) |
|
| 95 | - * - string: identifiant textuel |
|
| 96 | - * @param null|int|array $qui |
|
| 97 | - * - si null on prend alors visiteur_session |
|
| 98 | - * - un id_auteur (on regarde dans la base) |
|
| 99 | - * - un tableau auteur complet, y compris [restreint] |
|
| 100 | - * @param array $opt |
|
| 101 | - * options sous forme de tableau associatif |
|
| 102 | - * @return bool |
|
| 103 | - * true si la personne peut effectuer l'action |
|
| 104 | - */ |
|
| 105 | - function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool { |
|
| 106 | - // Charger les fonctions d'autorisation supplementaires |
|
| 107 | - static $pipe; |
|
| 108 | - if (!isset($pipe)) { |
|
| 109 | - $pipe = 1; |
|
| 110 | - pipeline('autoriser'); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return autoriser_dist($faire, $type, $id, $qui, $opt); |
|
| 114 | - } |
|
| 40 | + /** |
|
| 41 | + * Autoriser une action |
|
| 42 | + * |
|
| 43 | + * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 44 | + * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 45 | + * les autorisations. |
|
| 46 | + * |
|
| 47 | + * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 48 | + * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 49 | + * dans cet ordre : |
|
| 50 | + * |
|
| 51 | + * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 52 | + * - autoriser_{type}, sinon avec _dist |
|
| 53 | + * - autoriser_{faire}, sinon avec _dist |
|
| 54 | + * - autoriser_{defaut}, sinon avec _dist |
|
| 55 | + * |
|
| 56 | + * Seul le premier argument est obligatoire. |
|
| 57 | + * |
|
| 58 | + * @note |
|
| 59 | + * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 60 | + * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 61 | + * cette valeur. |
|
| 62 | + * |
|
| 63 | + * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 64 | + * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 65 | + * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 66 | + * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 67 | + * |
|
| 68 | + * @note |
|
| 69 | + * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 70 | + * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 71 | + * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 72 | + * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 73 | + * quel serait le type, quel serait l'action ? |
|
| 74 | + * |
|
| 75 | + * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 76 | + * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 77 | + * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 78 | + * |
|
| 79 | + * @api |
|
| 80 | + * @see autoriser_dist() |
|
| 81 | + * @see objet_type() |
|
| 82 | + * |
|
| 83 | + * @param string $faire |
|
| 84 | + * une action ('modifier', 'publier'...) |
|
| 85 | + * @param string|null $type |
|
| 86 | + * Type d’objet ou élément sur lequel appliquer l’action. |
|
| 87 | + * - null: indifférent à tout type d’élément ou objet éditorial |
|
| 88 | + * - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée) |
|
| 89 | + * - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()). |
|
| 90 | + * Les soulignés seront retirés (cf. la note). |
|
| 91 | + * @param string|int|null $id |
|
| 92 | + * id de l'objet ou élément sur lequel on veut agir, si pertinent. |
|
| 93 | + * - null: non utile pour l’autorisation |
|
| 94 | + * - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP) |
|
| 95 | + * - string: identifiant textuel |
|
| 96 | + * @param null|int|array $qui |
|
| 97 | + * - si null on prend alors visiteur_session |
|
| 98 | + * - un id_auteur (on regarde dans la base) |
|
| 99 | + * - un tableau auteur complet, y compris [restreint] |
|
| 100 | + * @param array $opt |
|
| 101 | + * options sous forme de tableau associatif |
|
| 102 | + * @return bool |
|
| 103 | + * true si la personne peut effectuer l'action |
|
| 104 | + */ |
|
| 105 | + function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool { |
|
| 106 | + // Charger les fonctions d'autorisation supplementaires |
|
| 107 | + static $pipe; |
|
| 108 | + if (!isset($pipe)) { |
|
| 109 | + $pipe = 1; |
|
| 110 | + pipeline('autoriser'); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return autoriser_dist($faire, $type, $id, $qui, $opt); |
|
| 114 | + } |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | // mes_fonctions peut aussi declarer des autorisations, il faut donc le charger |
| 119 | 119 | // mais apres la fonction autoriser() |
| 120 | 120 | if ($f = find_in_path('mes_fonctions.php')) { |
| 121 | - global $dossier_squelettes; |
|
| 122 | - include_once(_ROOT_CWD . $f); |
|
| 121 | + global $dossier_squelettes; |
|
| 122 | + include_once(_ROOT_CWD . $f); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
@@ -150,90 +150,90 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | function autoriser_dist(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool { |
| 152 | 152 | |
| 153 | - if ($type === null) { |
|
| 154 | - $type = ''; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // Qui ? visiteur_session ? |
|
| 158 | - // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 159 | - if ($qui === null || $qui === '') { |
|
| 160 | - $qui = $GLOBALS['visiteur_session'] ?: []; |
|
| 161 | - $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
|
| 162 | - } elseif (is_numeric($qui)) { |
|
| 163 | - $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 164 | - if (!$qui) { |
|
| 165 | - return false; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // Admins restreints, on construit ici (pas generique mais...) |
|
| 170 | - // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 171 | - if (_ADMINS_RESTREINTS && is_array($qui)) { |
|
| 172 | - $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : []; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - spip_log( |
|
| 176 | - "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 177 | - 'autoriser' . _LOG_DEBUG |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - // passer par objet_type pour avoir les alias |
|
| 181 | - // sauf si _ est le premier caractère. |
|
| 182 | - if ($type && $type[0] !== '_') { |
|
| 183 | - $type = objet_type($type, false); |
|
| 184 | - } |
|
| 185 | - // et supprimer les _ |
|
| 186 | - $type = str_replace('_', '', (string) $type); |
|
| 187 | - |
|
| 188 | - // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 189 | - if ( |
|
| 190 | - isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) |
|
| 191 | - && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier') |
|
| 192 | - ) { |
|
| 193 | - spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 194 | - return true; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // Chercher une fonction d'autorisation |
|
| 198 | - // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 199 | - // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 200 | - $fonctions = $type |
|
| 201 | - ? [ |
|
| 202 | - 'autoriser_' . $type . '_' . $faire, |
|
| 203 | - 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 204 | - 'autoriser_' . $type, |
|
| 205 | - 'autoriser_' . $type . '_dist', |
|
| 206 | - 'autoriser_' . $faire, |
|
| 207 | - 'autoriser_' . $faire . '_dist', |
|
| 208 | - 'autoriser_defaut', |
|
| 209 | - 'autoriser_defaut_dist' |
|
| 210 | - ] |
|
| 211 | - : [ |
|
| 212 | - 'autoriser_' . $faire, |
|
| 213 | - 'autoriser_' . $faire . '_dist', |
|
| 214 | - 'autoriser_defaut', |
|
| 215 | - 'autoriser_defaut_dist' |
|
| 216 | - ]; |
|
| 217 | - |
|
| 218 | - $a = false; |
|
| 219 | - foreach ($fonctions as $f) { |
|
| 220 | - if (function_exists($f)) { |
|
| 221 | - $a = $f($faire, $type, $id, $qui, $opt); |
|
| 222 | - break; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - spip_log( |
|
| 227 | - "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 228 | - 'autoriser' . _LOG_DEBUG |
|
| 229 | - ); |
|
| 230 | - |
|
| 231 | - if (!is_bool($a)) { |
|
| 232 | - trigger_error(sprintf('Function %s should returns a boolean instead of %s (casts as boolean). This will trigger fatal error in future versions.', $f, gettype($a)), \E_USER_DEPRECATED); |
|
| 233 | - $a = (bool) $a; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - return $a; |
|
| 153 | + if ($type === null) { |
|
| 154 | + $type = ''; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // Qui ? visiteur_session ? |
|
| 158 | + // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 159 | + if ($qui === null || $qui === '') { |
|
| 160 | + $qui = $GLOBALS['visiteur_session'] ?: []; |
|
| 161 | + $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
|
| 162 | + } elseif (is_numeric($qui)) { |
|
| 163 | + $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 164 | + if (!$qui) { |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // Admins restreints, on construit ici (pas generique mais...) |
|
| 170 | + // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 171 | + if (_ADMINS_RESTREINTS && is_array($qui)) { |
|
| 172 | + $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : []; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + spip_log( |
|
| 176 | + "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 177 | + 'autoriser' . _LOG_DEBUG |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + // passer par objet_type pour avoir les alias |
|
| 181 | + // sauf si _ est le premier caractère. |
|
| 182 | + if ($type && $type[0] !== '_') { |
|
| 183 | + $type = objet_type($type, false); |
|
| 184 | + } |
|
| 185 | + // et supprimer les _ |
|
| 186 | + $type = str_replace('_', '', (string) $type); |
|
| 187 | + |
|
| 188 | + // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 189 | + if ( |
|
| 190 | + isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) |
|
| 191 | + && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier') |
|
| 192 | + ) { |
|
| 193 | + spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 194 | + return true; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // Chercher une fonction d'autorisation |
|
| 198 | + // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 199 | + // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 200 | + $fonctions = $type |
|
| 201 | + ? [ |
|
| 202 | + 'autoriser_' . $type . '_' . $faire, |
|
| 203 | + 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 204 | + 'autoriser_' . $type, |
|
| 205 | + 'autoriser_' . $type . '_dist', |
|
| 206 | + 'autoriser_' . $faire, |
|
| 207 | + 'autoriser_' . $faire . '_dist', |
|
| 208 | + 'autoriser_defaut', |
|
| 209 | + 'autoriser_defaut_dist' |
|
| 210 | + ] |
|
| 211 | + : [ |
|
| 212 | + 'autoriser_' . $faire, |
|
| 213 | + 'autoriser_' . $faire . '_dist', |
|
| 214 | + 'autoriser_defaut', |
|
| 215 | + 'autoriser_defaut_dist' |
|
| 216 | + ]; |
|
| 217 | + |
|
| 218 | + $a = false; |
|
| 219 | + foreach ($fonctions as $f) { |
|
| 220 | + if (function_exists($f)) { |
|
| 221 | + $a = $f($faire, $type, $id, $qui, $opt); |
|
| 222 | + break; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + spip_log( |
|
| 227 | + "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 228 | + 'autoriser' . _LOG_DEBUG |
|
| 229 | + ); |
|
| 230 | + |
|
| 231 | + if (!is_bool($a)) { |
|
| 232 | + trigger_error(sprintf('Function %s should returns a boolean instead of %s (casts as boolean). This will trigger fatal error in future versions.', $f, gettype($a)), \E_USER_DEPRECATED); |
|
| 233 | + $a = (bool) $a; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + return $a; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // une globale pour aller au plus vite dans la fonction generique ci dessus |
@@ -253,33 +253,33 @@ discard block |
||
| 253 | 253 | * @return bool |
| 254 | 254 | */ |
| 255 | 255 | function autoriser_exception(string $faire, ?string $type = '', $id = null, $autoriser = true): bool { |
| 256 | - // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 257 | - static $autorisation; |
|
| 258 | - // Tolérance avec certains appels |
|
| 259 | - if ($type === null) { |
|
| 260 | - $type = ''; |
|
| 261 | - } |
|
| 262 | - if ($id === null) { |
|
| 263 | - $id = 0; |
|
| 264 | - } |
|
| 265 | - if ($autoriser === 'verifier') { |
|
| 266 | - return isset($autorisation[$faire][$type][$id]); |
|
| 267 | - } |
|
| 268 | - if ($autoriser === true) { |
|
| 269 | - $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 270 | - } |
|
| 271 | - if ($autoriser === false) { |
|
| 272 | - if ($id === '*') { |
|
| 273 | - unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 274 | - unset($autorisation[$faire][$type]); |
|
| 275 | - } |
|
| 276 | - else { |
|
| 277 | - unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 278 | - unset($autorisation[$faire][$type][$id]); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - return false; |
|
| 256 | + // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 257 | + static $autorisation; |
|
| 258 | + // Tolérance avec certains appels |
|
| 259 | + if ($type === null) { |
|
| 260 | + $type = ''; |
|
| 261 | + } |
|
| 262 | + if ($id === null) { |
|
| 263 | + $id = 0; |
|
| 264 | + } |
|
| 265 | + if ($autoriser === 'verifier') { |
|
| 266 | + return isset($autorisation[$faire][$type][$id]); |
|
| 267 | + } |
|
| 268 | + if ($autoriser === true) { |
|
| 269 | + $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 270 | + } |
|
| 271 | + if ($autoriser === false) { |
|
| 272 | + if ($id === '*') { |
|
| 273 | + unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 274 | + unset($autorisation[$faire][$type]); |
|
| 275 | + } |
|
| 276 | + else { |
|
| 277 | + unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 278 | + unset($autorisation[$faire][$type][$id]); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + return false; |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | * @return bool true s'il a le droit, false sinon |
| 299 | 299 | **/ |
| 300 | 300 | function autoriser_defaut_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 301 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 301 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | * @return bool true s'il a le droit, false sinon |
| 319 | 319 | */ |
| 320 | 320 | function autoriser_loger_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 321 | - return $qui['statut'] !== '5poubelle'; |
|
| 321 | + return $qui['statut'] !== '5poubelle'; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | * @return bool true s'il a le droit, false sinon |
| 335 | 335 | **/ |
| 336 | 336 | function autoriser_ecrire_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 337 | - return isset($qui['statut']) && in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 337 | + return isset($qui['statut']) && in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | * @return bool true s'il a le droit, false sinon |
| 354 | 354 | **/ |
| 355 | 355 | function autoriser_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 356 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 356 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -373,14 +373,14 @@ discard block |
||
| 373 | 373 | **/ |
| 374 | 374 | function autoriser_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 375 | 375 | |
| 376 | - // Le visiteur a-t-il un statut prevu par la config ? |
|
| 377 | - if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) { |
|
| 378 | - return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 379 | - } |
|
| 376 | + // Le visiteur a-t-il un statut prevu par la config ? |
|
| 377 | + if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) { |
|
| 378 | + return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | - // A-t-on un token de prévisualisation valable ? |
|
| 382 | - include_spip('inc/securiser_action'); |
|
| 383 | - return (bool) decrire_token_previsu(); |
|
| 381 | + // A-t-on un token de prévisualisation valable ? |
|
| 382 | + include_spip('inc/securiser_action'); |
|
| 383 | + return (bool) decrire_token_previsu(); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -409,58 +409,58 @@ discard block |
||
| 409 | 409 | */ |
| 410 | 410 | function test_previsualiser_objet_champ(string $type = '', $id = null, array $qui = [], array $opt = []): bool { |
| 411 | 411 | |
| 412 | - // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 413 | - if (!$type) { |
|
| 414 | - return true; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - include_spip('base/objets'); |
|
| 418 | - $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 419 | - if (isset($infos['statut'])) { |
|
| 420 | - foreach ($infos['statut'] as $c) { |
|
| 421 | - if (isset($c['publie'])) { |
|
| 422 | - if (!isset($c['previsu'])) { |
|
| 423 | - return false; |
|
| 424 | - } // pas de previsu definie => NIET |
|
| 425 | - $champ = $c['champ']; |
|
| 426 | - if (!isset($opt[$champ])) { |
|
| 427 | - return false; |
|
| 428 | - } // pas de champ passe a la demande => NIET |
|
| 429 | - $previsu = explode(',', (string) $c['previsu']); |
|
| 430 | - // regarder si ce statut est autorise pour l'auteur |
|
| 431 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 432 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 433 | - // sinon l’auteur en session |
|
| 434 | - include_spip('inc/securiser_action'); |
|
| 435 | - if ($desc = decrire_token_previsu()) { |
|
| 436 | - $id_auteur = $desc['id_auteur']; |
|
| 437 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 438 | - $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 439 | - } else { |
|
| 440 | - $id_auteur = null; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - if (!$id_auteur) { |
|
| 444 | - return false; |
|
| 445 | - } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 446 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 447 | - } elseif ( |
|
| 448 | - !sql_countsel( |
|
| 449 | - 'spip_auteurs_liens', |
|
| 450 | - 'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id |
|
| 451 | - ) |
|
| 452 | - ) { |
|
| 453 | - return false; |
|
| 454 | - } // pas auteur de cet objet => NIET |
|
| 455 | - } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 456 | - // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 457 | - return false; |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - return true; |
|
| 412 | + // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 413 | + if (!$type) { |
|
| 414 | + return true; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + include_spip('base/objets'); |
|
| 418 | + $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 419 | + if (isset($infos['statut'])) { |
|
| 420 | + foreach ($infos['statut'] as $c) { |
|
| 421 | + if (isset($c['publie'])) { |
|
| 422 | + if (!isset($c['previsu'])) { |
|
| 423 | + return false; |
|
| 424 | + } // pas de previsu definie => NIET |
|
| 425 | + $champ = $c['champ']; |
|
| 426 | + if (!isset($opt[$champ])) { |
|
| 427 | + return false; |
|
| 428 | + } // pas de champ passe a la demande => NIET |
|
| 429 | + $previsu = explode(',', (string) $c['previsu']); |
|
| 430 | + // regarder si ce statut est autorise pour l'auteur |
|
| 431 | + if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 432 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 433 | + // sinon l’auteur en session |
|
| 434 | + include_spip('inc/securiser_action'); |
|
| 435 | + if ($desc = decrire_token_previsu()) { |
|
| 436 | + $id_auteur = $desc['id_auteur']; |
|
| 437 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 438 | + $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 439 | + } else { |
|
| 440 | + $id_auteur = null; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + if (!$id_auteur) { |
|
| 444 | + return false; |
|
| 445 | + } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 446 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 447 | + } elseif ( |
|
| 448 | + !sql_countsel( |
|
| 449 | + 'spip_auteurs_liens', |
|
| 450 | + 'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id |
|
| 451 | + ) |
|
| 452 | + ) { |
|
| 453 | + return false; |
|
| 454 | + } // pas auteur de cet objet => NIET |
|
| 455 | + } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 456 | + // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 457 | + return false; |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + return true; |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** |
@@ -476,49 +476,49 @@ discard block |
||
| 476 | 476 | * @return bool true s'il a le droit, false sinon |
| 477 | 477 | **/ |
| 478 | 478 | function autoriser_changerlangue_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 479 | - $multi_objets = explode(',', (string) lire_config('multi_objets')); |
|
| 480 | - $gerer_trad_objets = explode(',', (string) lire_config('gerer_trad_objets')); |
|
| 481 | - $table = table_objet_sql($type); |
|
| 482 | - if ( |
|
| 483 | - in_array($table, $multi_objets) |
|
| 484 | - || in_array($table, $gerer_trad_objets) |
|
| 485 | - ) { // affichage du formulaire si la configuration l'accepte |
|
| 486 | - $multi_secteurs = lire_config('multi_secteurs'); |
|
| 487 | - $champs = objet_info($type, 'field'); |
|
| 488 | - if ( |
|
| 489 | - $multi_secteurs === 'oui' |
|
| 490 | - && array_key_exists('id_rubrique', $champs) |
|
| 491 | - ) { |
|
| 492 | - // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 493 | - $primary = id_table_objet($type); |
|
| 494 | - $id_rubrique = $table != 'spip_rubriques' |
|
| 495 | - ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id) |
|
| 496 | - : $id; |
|
| 497 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 498 | - if (!$id_secteur > 0) { |
|
| 499 | - $id_secteur = $id_rubrique; |
|
| 500 | - } |
|
| 501 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur); |
|
| 502 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id); |
|
| 503 | - if ($langue_secteur != $langue_objet) { |
|
| 504 | - // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 505 | - return true; |
|
| 506 | - } |
|
| 507 | - if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 508 | - return false; |
|
| 509 | - } else { |
|
| 510 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id); |
|
| 511 | - if ($id_parent != 0) { |
|
| 512 | - // sous-rubriques : pas de choix de langue |
|
| 513 | - return false; |
|
| 514 | - } |
|
| 515 | - } |
|
| 516 | - } |
|
| 517 | - } else { |
|
| 518 | - return false; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 479 | + $multi_objets = explode(',', (string) lire_config('multi_objets')); |
|
| 480 | + $gerer_trad_objets = explode(',', (string) lire_config('gerer_trad_objets')); |
|
| 481 | + $table = table_objet_sql($type); |
|
| 482 | + if ( |
|
| 483 | + in_array($table, $multi_objets) |
|
| 484 | + || in_array($table, $gerer_trad_objets) |
|
| 485 | + ) { // affichage du formulaire si la configuration l'accepte |
|
| 486 | + $multi_secteurs = lire_config('multi_secteurs'); |
|
| 487 | + $champs = objet_info($type, 'field'); |
|
| 488 | + if ( |
|
| 489 | + $multi_secteurs === 'oui' |
|
| 490 | + && array_key_exists('id_rubrique', $champs) |
|
| 491 | + ) { |
|
| 492 | + // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 493 | + $primary = id_table_objet($type); |
|
| 494 | + $id_rubrique = $table != 'spip_rubriques' |
|
| 495 | + ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id) |
|
| 496 | + : $id; |
|
| 497 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 498 | + if (!$id_secteur > 0) { |
|
| 499 | + $id_secteur = $id_rubrique; |
|
| 500 | + } |
|
| 501 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur); |
|
| 502 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id); |
|
| 503 | + if ($langue_secteur != $langue_objet) { |
|
| 504 | + // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 505 | + return true; |
|
| 506 | + } |
|
| 507 | + if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 508 | + return false; |
|
| 509 | + } else { |
|
| 510 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id); |
|
| 511 | + if ($id_parent != 0) { |
|
| 512 | + // sous-rubriques : pas de choix de langue |
|
| 513 | + return false; |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + } |
|
| 517 | + } else { |
|
| 518 | + return false; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | /** |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | * @return bool true s'il a le droit, false sinon |
| 535 | 535 | **/ |
| 536 | 536 | function autoriser_changertraduction_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 537 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 537 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | /** |
@@ -550,38 +550,38 @@ discard block |
||
| 550 | 550 | * @return bool true s'il a le droit, false sinon |
| 551 | 551 | **/ |
| 552 | 552 | function autoriser_dater_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 553 | - $table = table_objet($type); |
|
| 554 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 555 | - $desc = $trouver_table($table); |
|
| 556 | - if (!$desc) { |
|
| 557 | - return false; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - if (!isset($opt['statut'])) { |
|
| 561 | - if (isset($desc['field']['statut'])) { |
|
| 562 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id); |
|
| 563 | - } else { |
|
| 564 | - $statut = 'publie'; |
|
| 565 | - } // pas de statut => publie |
|
| 566 | - } else { |
|
| 567 | - $statut = $opt['statut']; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - // Liste des statuts publiés pour cet objet |
|
| 571 | - // Sinon en dur le statut "publie" |
|
| 572 | - $statuts_publies = isset($desc['statut'][0]['publie']) |
|
| 573 | - ? explode(',', (string) $desc['statut'][0]['publie']) |
|
| 574 | - : ['publie']; |
|
| 575 | - |
|
| 576 | - if ( |
|
| 577 | - in_array($statut, $statuts_publies) |
|
| 578 | - // Ou cas particulier géré en dur ici pour les articles |
|
| 579 | - || $statut === 'prop' && $type === 'article' && $GLOBALS['meta']['post_dates'] === 'non' |
|
| 580 | - ) { |
|
| 581 | - return autoriser('modifier', $type, $id); |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - return false; |
|
| 553 | + $table = table_objet($type); |
|
| 554 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 555 | + $desc = $trouver_table($table); |
|
| 556 | + if (!$desc) { |
|
| 557 | + return false; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + if (!isset($opt['statut'])) { |
|
| 561 | + if (isset($desc['field']['statut'])) { |
|
| 562 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id); |
|
| 563 | + } else { |
|
| 564 | + $statut = 'publie'; |
|
| 565 | + } // pas de statut => publie |
|
| 566 | + } else { |
|
| 567 | + $statut = $opt['statut']; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + // Liste des statuts publiés pour cet objet |
|
| 571 | + // Sinon en dur le statut "publie" |
|
| 572 | + $statuts_publies = isset($desc['statut'][0]['publie']) |
|
| 573 | + ? explode(',', (string) $desc['statut'][0]['publie']) |
|
| 574 | + : ['publie']; |
|
| 575 | + |
|
| 576 | + if ( |
|
| 577 | + in_array($statut, $statuts_publies) |
|
| 578 | + // Ou cas particulier géré en dur ici pour les articles |
|
| 579 | + || $statut === 'prop' && $type === 'article' && $GLOBALS['meta']['post_dates'] === 'non' |
|
| 580 | + ) { |
|
| 581 | + return autoriser('modifier', $type, $id); |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + return false; |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | /** |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | * @return bool true s'il a le droit, false sinon |
| 601 | 601 | **/ |
| 602 | 602 | function autoriser_instituer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 603 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 603 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | /** |
@@ -618,9 +618,9 @@ discard block |
||
| 618 | 618 | * @return bool true s'il a le droit, false sinon |
| 619 | 619 | **/ |
| 620 | 620 | function autoriser_rubrique_publierdans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 621 | - return |
|
| 622 | - $qui['statut'] === '0minirezo' |
|
| 623 | - && (!$qui['restreint'] || !$id || in_array($id, $qui['restreint'])); |
|
| 621 | + return |
|
| 622 | + $qui['statut'] === '0minirezo' |
|
| 623 | + && (!$qui['restreint'] || !$id || in_array($id, $qui['restreint'])); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | /** |
@@ -638,12 +638,12 @@ discard block |
||
| 638 | 638 | * @return bool true s'il a le droit, false sinon |
| 639 | 639 | **/ |
| 640 | 640 | function autoriser_rubrique_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 641 | - if (!empty($opt['id_parent'])) { |
|
| 642 | - return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 643 | - } |
|
| 644 | - else { |
|
| 645 | - return autoriser('defaut', null, 0, $qui, $opt); |
|
| 646 | - } |
|
| 641 | + if (!empty($opt['id_parent'])) { |
|
| 642 | + return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 643 | + } |
|
| 644 | + else { |
|
| 645 | + return autoriser('defaut', null, 0, $qui, $opt); |
|
| 646 | + } |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 649 | /** |
@@ -661,8 +661,8 @@ discard block |
||
| 661 | 661 | * @return bool true s'il a le droit, false sinon |
| 662 | 662 | **/ |
| 663 | 663 | function autoriser_rubrique_creerrubriquedans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 664 | - return |
|
| 665 | - ($id || $qui['statut'] === '0minirezo' && !$qui['restreint']) && autoriser('voir', 'rubrique', $id) && autoriser('publierdans', 'rubrique', $id); |
|
| 664 | + return |
|
| 665 | + ($id || $qui['statut'] === '0minirezo' && !$qui['restreint']) && autoriser('voir', 'rubrique', $id) && autoriser('publierdans', 'rubrique', $id); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | /** |
@@ -680,10 +680,10 @@ discard block |
||
| 680 | 680 | * @return bool true s'il a le droit, false sinon |
| 681 | 681 | **/ |
| 682 | 682 | function autoriser_rubrique_creerarticledans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 683 | - return |
|
| 684 | - $id |
|
| 685 | - && autoriser('voir', 'rubrique', $id) |
|
| 686 | - && autoriser('creer', 'article'); |
|
| 683 | + return |
|
| 684 | + $id |
|
| 685 | + && autoriser('voir', 'rubrique', $id) |
|
| 686 | + && autoriser('creer', 'article'); |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | * @return bool true s'il a le droit, false sinon |
| 703 | 703 | **/ |
| 704 | 704 | function autoriser_rubrique_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 705 | - return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 705 | + return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | /** |
@@ -720,29 +720,29 @@ discard block |
||
| 720 | 720 | * @return bool true s'il a le droit, false sinon |
| 721 | 721 | **/ |
| 722 | 722 | function autoriser_rubrique_supprimer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 723 | - if (!$id = (int) $id) { |
|
| 724 | - return false; |
|
| 725 | - } |
|
| 723 | + if (!$id = (int) $id) { |
|
| 724 | + return false; |
|
| 725 | + } |
|
| 726 | 726 | |
| 727 | - if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) { |
|
| 728 | - return false; |
|
| 729 | - } |
|
| 727 | + if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) { |
|
| 728 | + return false; |
|
| 729 | + } |
|
| 730 | 730 | |
| 731 | - if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) { |
|
| 732 | - return false; |
|
| 733 | - } |
|
| 731 | + if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) { |
|
| 732 | + return false; |
|
| 733 | + } |
|
| 734 | 734 | |
| 735 | - $compte = pipeline( |
|
| 736 | - 'objet_compte_enfants', |
|
| 737 | - ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 738 | - ); |
|
| 739 | - foreach ($compte as $objet => $n) { |
|
| 740 | - if ($n) { |
|
| 741 | - return false; |
|
| 742 | - } |
|
| 743 | - } |
|
| 735 | + $compte = pipeline( |
|
| 736 | + 'objet_compte_enfants', |
|
| 737 | + ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 738 | + ); |
|
| 739 | + foreach ($compte as $objet => $n) { |
|
| 740 | + if ($n) { |
|
| 741 | + return false; |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | 744 | |
| 745 | - return autoriser('modifier', 'rubrique', $id); |
|
| 745 | + return autoriser('modifier', 'rubrique', $id); |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | |
@@ -762,20 +762,20 @@ discard block |
||
| 762 | 762 | * @return bool true s'il a le droit, false sinon |
| 763 | 763 | **/ |
| 764 | 764 | function autoriser_article_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 765 | - if (!$id) { |
|
| 766 | - return false; |
|
| 767 | - } |
|
| 768 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 765 | + if (!$id) { |
|
| 766 | + return false; |
|
| 767 | + } |
|
| 768 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 769 | 769 | |
| 770 | - return $r && ( |
|
| 771 | - autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 772 | - || ( |
|
| 773 | - (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true)) |
|
| 774 | - && in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 775 | - && in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 776 | - && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 777 | - ) |
|
| 778 | - ); |
|
| 770 | + return $r && ( |
|
| 771 | + autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 772 | + || ( |
|
| 773 | + (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true)) |
|
| 774 | + && in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 775 | + && in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 776 | + && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 777 | + ) |
|
| 778 | + ); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | /** |
@@ -793,13 +793,13 @@ discard block |
||
| 793 | 793 | * @return bool true s'il a le droit, false sinon |
| 794 | 794 | **/ |
| 795 | 795 | function autoriser_article_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 796 | - if (!empty($opt['id_parent'])) { |
|
| 797 | - // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 798 | - return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 799 | - } |
|
| 800 | - else { |
|
| 801 | - return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 802 | - } |
|
| 796 | + if (!empty($opt['id_parent'])) { |
|
| 797 | + // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 798 | + return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 799 | + } |
|
| 800 | + else { |
|
| 801 | + return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 802 | + } |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | /** |
@@ -821,26 +821,26 @@ discard block |
||
| 821 | 821 | * @return bool true s'il a le droit, false sinon |
| 822 | 822 | */ |
| 823 | 823 | function autoriser_article_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 824 | - if ($qui['statut'] === '0minirezo') { |
|
| 825 | - return true; |
|
| 826 | - } |
|
| 827 | - // cas des articles : depend du statut de l'article et de l'auteur |
|
| 828 | - if (isset($opt['statut'])) { |
|
| 829 | - $statut = $opt['statut']; |
|
| 830 | - } else { |
|
| 831 | - if (!$id) { |
|
| 832 | - return false; |
|
| 833 | - } |
|
| 834 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id); |
|
| 835 | - } |
|
| 824 | + if ($qui['statut'] === '0minirezo') { |
|
| 825 | + return true; |
|
| 826 | + } |
|
| 827 | + // cas des articles : depend du statut de l'article et de l'auteur |
|
| 828 | + if (isset($opt['statut'])) { |
|
| 829 | + $statut = $opt['statut']; |
|
| 830 | + } else { |
|
| 831 | + if (!$id) { |
|
| 832 | + return false; |
|
| 833 | + } |
|
| 834 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id); |
|
| 835 | + } |
|
| 836 | 836 | |
| 837 | - return |
|
| 838 | - // si on est pas auteur de l'article, |
|
| 839 | - // seuls les propose et publies sont visibles |
|
| 840 | - in_array($statut, ['prop', 'publie']) |
|
| 841 | - // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 837 | + return |
|
| 838 | + // si on est pas auteur de l'article, |
|
| 839 | + // seuls les propose et publies sont visibles |
|
| 840 | + in_array($statut, ['prop', 'publie']) |
|
| 841 | + // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 842 | 842 | |
| 843 | - || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']); |
|
| 843 | + || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']); |
|
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | |
@@ -859,24 +859,24 @@ discard block |
||
| 859 | 859 | * @return bool true s'il a le droit, false sinon |
| 860 | 860 | **/ |
| 861 | 861 | function autoriser_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 862 | - # securite, mais on aurait pas du arriver ici ! |
|
| 863 | - if ( |
|
| 864 | - function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 865 | - || function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 866 | - ) { |
|
| 867 | - return $f($faire, $type, $id, $qui, $opt); |
|
| 868 | - } |
|
| 862 | + # securite, mais on aurait pas du arriver ici ! |
|
| 863 | + if ( |
|
| 864 | + function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 865 | + || function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 866 | + ) { |
|
| 867 | + return $f($faire, $type, $id, $qui, $opt); |
|
| 868 | + } |
|
| 869 | 869 | |
| 870 | - if ($qui['statut'] === '0minirezo') { |
|
| 871 | - return true; |
|
| 872 | - } |
|
| 873 | - // admins et redacteurs peuvent voir un auteur |
|
| 874 | - if ($type === 'auteur') { |
|
| 875 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 876 | - } |
|
| 877 | - // sinon par defaut tout est visible |
|
| 878 | - // sauf cas particuliers traites separemment (ie article) |
|
| 879 | - return true; |
|
| 870 | + if ($qui['statut'] === '0minirezo') { |
|
| 871 | + return true; |
|
| 872 | + } |
|
| 873 | + // admins et redacteurs peuvent voir un auteur |
|
| 874 | + if ($type === 'auteur') { |
|
| 875 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 876 | + } |
|
| 877 | + // sinon par defaut tout est visible |
|
| 878 | + // sauf cas particuliers traites separemment (ie article) |
|
| 879 | + return true; |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | |
@@ -898,10 +898,10 @@ discard block |
||
| 898 | 898 | * @return bool true s'il a le droit, false sinon |
| 899 | 899 | **/ |
| 900 | 900 | function autoriser_webmestre_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 901 | - return |
|
| 902 | - $qui['webmestre'] === 'oui' |
|
| 903 | - && $qui['statut'] === '0minirezo' |
|
| 904 | - && !$qui['restreint']; |
|
| 901 | + return |
|
| 902 | + $qui['webmestre'] === 'oui' |
|
| 903 | + && $qui['statut'] === '0minirezo' |
|
| 904 | + && !$qui['restreint']; |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -919,7 +919,7 @@ discard block |
||
| 919 | 919 | * @return bool true s'il a le droit, false sinon |
| 920 | 920 | **/ |
| 921 | 921 | function autoriser_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 922 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 922 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | /** |
@@ -937,7 +937,7 @@ discard block |
||
| 937 | 937 | * @return bool true s'il a le droit, false sinon |
| 938 | 938 | **/ |
| 939 | 939 | function autoriser_sauvegarder_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 940 | - return $qui['statut'] === '0minirezo'; |
|
| 940 | + return $qui['statut'] === '0minirezo'; |
|
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | /** |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | * @return bool true s'il a le droit, false sinon |
| 956 | 956 | **/ |
| 957 | 957 | function autoriser_detruire_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 958 | - return autoriser('webmestre', null, 0, $qui, $opt); |
|
| 958 | + return autoriser('webmestre', null, 0, $qui, $opt); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -974,23 +974,23 @@ discard block |
||
| 974 | 974 | * @return bool true s'il a le droit, false sinon |
| 975 | 975 | **/ |
| 976 | 976 | function autoriser_auteur_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 977 | - // les admins peuvent "previsualiser" une page auteur |
|
| 978 | - if ( |
|
| 979 | - $qui['statut'] === '0minirezo' |
|
| 980 | - && !$qui['restreint'] |
|
| 981 | - ) { |
|
| 982 | - return true; |
|
| 983 | - } elseif ($id === 0) { |
|
| 984 | - return false; |
|
| 985 | - } |
|
| 986 | - // "Voir en ligne" si l'auteur a un article publie |
|
| 987 | - $n = sql_fetsel( |
|
| 988 | - 'A.id_article', |
|
| 989 | - 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 990 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 991 | - ); |
|
| 977 | + // les admins peuvent "previsualiser" une page auteur |
|
| 978 | + if ( |
|
| 979 | + $qui['statut'] === '0minirezo' |
|
| 980 | + && !$qui['restreint'] |
|
| 981 | + ) { |
|
| 982 | + return true; |
|
| 983 | + } elseif ($id === 0) { |
|
| 984 | + return false; |
|
| 985 | + } |
|
| 986 | + // "Voir en ligne" si l'auteur a un article publie |
|
| 987 | + $n = sql_fetsel( |
|
| 988 | + 'A.id_article', |
|
| 989 | + 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 990 | + "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 991 | + ); |
|
| 992 | 992 | |
| 993 | - return (bool) $n; |
|
| 993 | + return (bool) $n; |
|
| 994 | 994 | } |
| 995 | 995 | |
| 996 | 996 | |
@@ -1019,7 +1019,7 @@ discard block |
||
| 1019 | 1019 | * @return bool true s'il a le droit, false sinon |
| 1020 | 1020 | **/ |
| 1021 | 1021 | function autoriser_auteur_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1022 | - return ($qui['statut'] === '0minirezo'); |
|
| 1022 | + return ($qui['statut'] === '0minirezo'); |
|
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | 1025 | |
@@ -1040,62 +1040,62 @@ discard block |
||
| 1040 | 1040 | * @return bool true s'il a le droit, false sinon |
| 1041 | 1041 | **/ |
| 1042 | 1042 | function autoriser_auteur_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1043 | - $id = (int) $id; |
|
| 1044 | - |
|
| 1045 | - // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1046 | - // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1047 | - if ($qui['statut'] != '0minirezo') { |
|
| 1048 | - return $id == $qui['id_auteur'] |
|
| 1049 | - && empty($opt['statut']) |
|
| 1050 | - && empty($opt['webmestre']) |
|
| 1051 | - && empty($opt['restreintes']) |
|
| 1052 | - && empty($opt['login']); |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1056 | - // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1057 | - if ($qui['restreint']) { |
|
| 1058 | - if (isset($opt['webmestre']) && $opt['webmestre']) { |
|
| 1059 | - return false; |
|
| 1060 | - } elseif ( |
|
| 1061 | - isset($opt['statut']) && $opt['statut'] === '0minirezo' || isset($opt['restreintes']) && $opt['restreintes'] |
|
| 1062 | - ) { |
|
| 1063 | - return false; |
|
| 1064 | - } else { |
|
| 1065 | - if ($id == $qui['id_auteur']) { |
|
| 1066 | - if (isset($opt['statut']) && $opt['statut']) { |
|
| 1067 | - return false; |
|
| 1068 | - } else { |
|
| 1069 | - return true; |
|
| 1070 | - } |
|
| 1071 | - } else { |
|
| 1072 | - if ($id_auteur = (int) $id) { |
|
| 1073 | - $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1074 | - if ($t && $t['statut'] != '0minirezo') { |
|
| 1075 | - return true; |
|
| 1076 | - } else { |
|
| 1077 | - return false; |
|
| 1078 | - } |
|
| 1079 | - } else { |
|
| 1080 | - // id = 0 => creation |
|
| 1081 | - return true; |
|
| 1082 | - } |
|
| 1083 | - } |
|
| 1084 | - } |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - // Un admin complet fait ce qu'il veut, sauf se degrader |
|
| 1088 | - if ($id == $qui['id_auteur'] && (isset($opt['statut']) && $opt['statut'])) { |
|
| 1089 | - return false; |
|
| 1090 | - } elseif (isset($opt['webmestre']) && $opt['webmestre'] && !autoriser('webmestre')) { |
|
| 1091 | - // et toucher au statut webmestre si il ne l'est pas lui même |
|
| 1092 | - return false; |
|
| 1093 | - } elseif ((int) $id && !autoriser('webmestre') && autoriser('webmestre', '', 0, $id)) { |
|
| 1094 | - // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1095 | - return false; |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - return true; |
|
| 1043 | + $id = (int) $id; |
|
| 1044 | + |
|
| 1045 | + // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1046 | + // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1047 | + if ($qui['statut'] != '0minirezo') { |
|
| 1048 | + return $id == $qui['id_auteur'] |
|
| 1049 | + && empty($opt['statut']) |
|
| 1050 | + && empty($opt['webmestre']) |
|
| 1051 | + && empty($opt['restreintes']) |
|
| 1052 | + && empty($opt['login']); |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1056 | + // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1057 | + if ($qui['restreint']) { |
|
| 1058 | + if (isset($opt['webmestre']) && $opt['webmestre']) { |
|
| 1059 | + return false; |
|
| 1060 | + } elseif ( |
|
| 1061 | + isset($opt['statut']) && $opt['statut'] === '0minirezo' || isset($opt['restreintes']) && $opt['restreintes'] |
|
| 1062 | + ) { |
|
| 1063 | + return false; |
|
| 1064 | + } else { |
|
| 1065 | + if ($id == $qui['id_auteur']) { |
|
| 1066 | + if (isset($opt['statut']) && $opt['statut']) { |
|
| 1067 | + return false; |
|
| 1068 | + } else { |
|
| 1069 | + return true; |
|
| 1070 | + } |
|
| 1071 | + } else { |
|
| 1072 | + if ($id_auteur = (int) $id) { |
|
| 1073 | + $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1074 | + if ($t && $t['statut'] != '0minirezo') { |
|
| 1075 | + return true; |
|
| 1076 | + } else { |
|
| 1077 | + return false; |
|
| 1078 | + } |
|
| 1079 | + } else { |
|
| 1080 | + // id = 0 => creation |
|
| 1081 | + return true; |
|
| 1082 | + } |
|
| 1083 | + } |
|
| 1084 | + } |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + // Un admin complet fait ce qu'il veut, sauf se degrader |
|
| 1088 | + if ($id == $qui['id_auteur'] && (isset($opt['statut']) && $opt['statut'])) { |
|
| 1089 | + return false; |
|
| 1090 | + } elseif (isset($opt['webmestre']) && $opt['webmestre'] && !autoriser('webmestre')) { |
|
| 1091 | + // et toucher au statut webmestre si il ne l'est pas lui même |
|
| 1092 | + return false; |
|
| 1093 | + } elseif ((int) $id && !autoriser('webmestre') && autoriser('webmestre', '', 0, $id)) { |
|
| 1094 | + // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1095 | + return false; |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + return true; |
|
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | 1101 | |
@@ -1114,7 +1114,7 @@ discard block |
||
| 1114 | 1114 | * @return bool true s'il a le droit, false sinon |
| 1115 | 1115 | **/ |
| 1116 | 1116 | function autoriser_associerauteurs_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1117 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1117 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | 1120 | |
@@ -1133,7 +1133,7 @@ discard block |
||
| 1133 | 1133 | * @return bool true s'il a le droit, false sinon |
| 1134 | 1134 | **/ |
| 1135 | 1135 | function autoriser_chargerftp_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1136 | - return $qui['statut'] === '0minirezo'; |
|
| 1136 | + return $qui['statut'] === '0minirezo'; |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | /** |
@@ -1151,7 +1151,7 @@ discard block |
||
| 1151 | 1151 | * @return bool true s'il a le droit, false sinon |
| 1152 | 1152 | **/ |
| 1153 | 1153 | function autoriser_debug_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1154 | - return $qui['statut'] === '0minirezo'; |
|
| 1154 | + return $qui['statut'] === '0minirezo'; |
|
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | 1157 | /** |
@@ -1168,53 +1168,53 @@ discard block |
||
| 1168 | 1168 | * @return array Liste des rubriques |
| 1169 | 1169 | **/ |
| 1170 | 1170 | function liste_rubriques_auteur($id_auteur, $raz = false) { |
| 1171 | - static $restreint = []; |
|
| 1172 | - |
|
| 1173 | - if (!$id_auteur = (int) $id_auteur) { |
|
| 1174 | - return []; |
|
| 1175 | - } |
|
| 1176 | - if ($raz) { |
|
| 1177 | - unset($restreint[$id_auteur]); |
|
| 1178 | - } elseif (isset($restreint[$id_auteur])) { |
|
| 1179 | - return $restreint[$id_auteur]; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - $rubriques = []; |
|
| 1183 | - if ( |
|
| 1184 | - (!isset($GLOBALS['meta']['version_installee']) || $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1185 | - && ($r = sql_allfetsel( |
|
| 1186 | - 'id_objet', |
|
| 1187 | - 'spip_auteurs_liens', |
|
| 1188 | - 'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0" |
|
| 1189 | - )) |
|
| 1190 | - && (is_countable($r) ? count($r) : 0) |
|
| 1191 | - ) { |
|
| 1192 | - $r = array_column($r, 'id_objet'); |
|
| 1193 | - |
|
| 1194 | - // recuperer toute la branche, au format chaine enumeration |
|
| 1195 | - include_spip('inc/rubriques'); |
|
| 1196 | - $r = calcul_branche_in($r); |
|
| 1197 | - $r = explode(',', (string) $r); |
|
| 1198 | - |
|
| 1199 | - // passer les rubriques en index, elimine les doublons |
|
| 1200 | - $r = array_flip($r); |
|
| 1201 | - // recuperer les index seuls |
|
| 1202 | - $r = array_keys($r); |
|
| 1203 | - // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1204 | - // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1205 | - $rubriques = array_combine($r, $r); |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - // Affecter l'auteur session le cas echeant |
|
| 1209 | - if ( |
|
| 1210 | - isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1211 | - && $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1212 | - ) { |
|
| 1213 | - $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - |
|
| 1217 | - return $restreint[$id_auteur] = $rubriques; |
|
| 1171 | + static $restreint = []; |
|
| 1172 | + |
|
| 1173 | + if (!$id_auteur = (int) $id_auteur) { |
|
| 1174 | + return []; |
|
| 1175 | + } |
|
| 1176 | + if ($raz) { |
|
| 1177 | + unset($restreint[$id_auteur]); |
|
| 1178 | + } elseif (isset($restreint[$id_auteur])) { |
|
| 1179 | + return $restreint[$id_auteur]; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + $rubriques = []; |
|
| 1183 | + if ( |
|
| 1184 | + (!isset($GLOBALS['meta']['version_installee']) || $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1185 | + && ($r = sql_allfetsel( |
|
| 1186 | + 'id_objet', |
|
| 1187 | + 'spip_auteurs_liens', |
|
| 1188 | + 'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0" |
|
| 1189 | + )) |
|
| 1190 | + && (is_countable($r) ? count($r) : 0) |
|
| 1191 | + ) { |
|
| 1192 | + $r = array_column($r, 'id_objet'); |
|
| 1193 | + |
|
| 1194 | + // recuperer toute la branche, au format chaine enumeration |
|
| 1195 | + include_spip('inc/rubriques'); |
|
| 1196 | + $r = calcul_branche_in($r); |
|
| 1197 | + $r = explode(',', (string) $r); |
|
| 1198 | + |
|
| 1199 | + // passer les rubriques en index, elimine les doublons |
|
| 1200 | + $r = array_flip($r); |
|
| 1201 | + // recuperer les index seuls |
|
| 1202 | + $r = array_keys($r); |
|
| 1203 | + // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1204 | + // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1205 | + $rubriques = array_combine($r, $r); |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + // Affecter l'auteur session le cas echeant |
|
| 1209 | + if ( |
|
| 1210 | + isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1211 | + && $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1212 | + ) { |
|
| 1213 | + $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + |
|
| 1217 | + return $restreint[$id_auteur] = $rubriques; |
|
| 1218 | 1218 | } |
| 1219 | 1219 | |
| 1220 | 1220 | /** |
@@ -1232,7 +1232,7 @@ discard block |
||
| 1232 | 1232 | * @return bool true s'il a le droit, false sinon |
| 1233 | 1233 | **/ |
| 1234 | 1234 | function autoriser_rubrique_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1235 | - return autoriser('previsualiser'); |
|
| 1235 | + return autoriser('previsualiser'); |
|
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | /** |
@@ -1250,7 +1250,7 @@ discard block |
||
| 1250 | 1250 | * @return bool true s'il a le droit, false sinon |
| 1251 | 1251 | **/ |
| 1252 | 1252 | function autoriser_rubrique_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1253 | - return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1253 | + return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | 1256 | /** |
@@ -1268,8 +1268,8 @@ discard block |
||
| 1268 | 1268 | * @return bool true s'il a le droit, false sinon |
| 1269 | 1269 | **/ |
| 1270 | 1270 | function autoriser_auteur_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1271 | - $id = (int) $id; |
|
| 1272 | - return ($id == $qui['id_auteur'] || $qui['statut'] === '0minirezo' && !$qui['restreint']); |
|
| 1271 | + $id = (int) $id; |
|
| 1272 | + return ($id == $qui['id_auteur'] || $qui['statut'] === '0minirezo' && !$qui['restreint']); |
|
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | 1275 | /** |
@@ -1287,8 +1287,8 @@ discard block |
||
| 1287 | 1287 | * @return bool true s'il a le droit, false sinon |
| 1288 | 1288 | **/ |
| 1289 | 1289 | function autoriser_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1290 | - // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1291 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1290 | + // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1291 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | 1294 | |
@@ -1308,7 +1308,7 @@ discard block |
||
| 1308 | 1308 | * @return true |
| 1309 | 1309 | **/ |
| 1310 | 1310 | function autoriser_ok_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1311 | - return true; |
|
| 1311 | + return true; |
|
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | 1314 | /** |
@@ -1327,7 +1327,7 @@ discard block |
||
| 1327 | 1327 | * @return false |
| 1328 | 1328 | **/ |
| 1329 | 1329 | function autoriser_niet_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1330 | - return false; |
|
| 1330 | + return false; |
|
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | 1333 | /** |
@@ -1345,7 +1345,7 @@ discard block |
||
| 1345 | 1345 | * @return bool true s'il a le droit, false sinon |
| 1346 | 1346 | **/ |
| 1347 | 1347 | function autoriser_base_reparer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1348 | - return autoriser('detruire') && !_request('reinstall'); |
|
| 1348 | + return autoriser('detruire') && !_request('reinstall'); |
|
| 1349 | 1349 | } |
| 1350 | 1350 | |
| 1351 | 1351 | /** |
@@ -1363,7 +1363,7 @@ discard block |
||
| 1363 | 1363 | * @return true |
| 1364 | 1364 | **/ |
| 1365 | 1365 | function autoriser_infosperso_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1366 | - return true; |
|
| 1366 | + return true; |
|
| 1367 | 1367 | } |
| 1368 | 1368 | |
| 1369 | 1369 | /** |
@@ -1381,7 +1381,7 @@ discard block |
||
| 1381 | 1381 | * @return true |
| 1382 | 1382 | **/ |
| 1383 | 1383 | function autoriser_langage_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1384 | - return true; |
|
| 1384 | + return true; |
|
| 1385 | 1385 | } |
| 1386 | 1386 | |
| 1387 | 1387 | /** |
@@ -1399,7 +1399,7 @@ discard block |
||
| 1399 | 1399 | * @return bool true s'il a le droit, false sinon |
| 1400 | 1400 | **/ |
| 1401 | 1401 | function autoriser_configurerlangage_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1402 | - return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1402 | + return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | 1405 | /** |
@@ -1417,7 +1417,7 @@ discard block |
||
| 1417 | 1417 | * @return true |
| 1418 | 1418 | **/ |
| 1419 | 1419 | function autoriser_preferences_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1420 | - return true; |
|
| 1420 | + return true; |
|
| 1421 | 1421 | } |
| 1422 | 1422 | |
| 1423 | 1423 | /** |
@@ -1435,7 +1435,7 @@ discard block |
||
| 1435 | 1435 | * @return bool true s'il a le droit, false sinon |
| 1436 | 1436 | **/ |
| 1437 | 1437 | function autoriser_configurerpreferences_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1438 | - return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1438 | + return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1439 | 1439 | } |
| 1440 | 1440 | |
| 1441 | 1441 | /** |
@@ -1453,7 +1453,7 @@ discard block |
||
| 1453 | 1453 | * @return bool true s'il a le droit, false sinon |
| 1454 | 1454 | **/ |
| 1455 | 1455 | function autoriser_menudeveloppement_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1456 | - return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) && $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui'); |
|
| 1456 | + return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) && $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui'); |
|
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | 1459 | /** |
@@ -1472,7 +1472,7 @@ discard block |
||
| 1472 | 1472 | * @return true |
| 1473 | 1473 | **/ |
| 1474 | 1474 | function autoriser_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1475 | - return true; |
|
| 1475 | + return true; |
|
| 1476 | 1476 | } |
| 1477 | 1477 | |
| 1478 | 1478 | /** |
@@ -1490,7 +1490,7 @@ discard block |
||
| 1490 | 1490 | * @return true |
| 1491 | 1491 | **/ |
| 1492 | 1492 | function autoriser_auteurs_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1493 | - return true; |
|
| 1493 | + return true; |
|
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 1496 | 1496 | /** |
@@ -1508,7 +1508,7 @@ discard block |
||
| 1508 | 1508 | * @return bool true s'il a le droit, false sinon |
| 1509 | 1509 | **/ |
| 1510 | 1510 | function autoriser_auteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1511 | - return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1511 | + return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | 1514 | /** |
@@ -1526,7 +1526,7 @@ discard block |
||
| 1526 | 1526 | * @return true |
| 1527 | 1527 | **/ |
| 1528 | 1528 | function autoriser_articles_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1529 | - return true; |
|
| 1529 | + return true; |
|
| 1530 | 1530 | } |
| 1531 | 1531 | |
| 1532 | 1532 | /** |
@@ -1544,7 +1544,7 @@ discard block |
||
| 1544 | 1544 | * @return bool true s'il a le droit, false sinon |
| 1545 | 1545 | **/ |
| 1546 | 1546 | function autoriser_articles_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1547 | - return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1547 | + return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1548 | 1548 | } |
| 1549 | 1549 | |
| 1550 | 1550 | /** |
@@ -1562,7 +1562,7 @@ discard block |
||
| 1562 | 1562 | * @return true |
| 1563 | 1563 | **/ |
| 1564 | 1564 | function autoriser_rubriques_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1565 | - return true; |
|
| 1565 | + return true; |
|
| 1566 | 1566 | } |
| 1567 | 1567 | |
| 1568 | 1568 | /** |
@@ -1580,7 +1580,7 @@ discard block |
||
| 1580 | 1580 | * @return bool true s'il a le droit, false sinon |
| 1581 | 1581 | **/ |
| 1582 | 1582 | function autoriser_rubriques_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1583 | - return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1583 | + return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1584 | 1584 | } |
| 1585 | 1585 | |
| 1586 | 1586 | /** |
@@ -1598,7 +1598,7 @@ discard block |
||
| 1598 | 1598 | * @return bool true s'il a le droit, false sinon |
| 1599 | 1599 | **/ |
| 1600 | 1600 | function autoriser_articlecreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1601 | - return verifier_table_non_vide(); |
|
| 1601 | + return verifier_table_non_vide(); |
|
| 1602 | 1602 | } |
| 1603 | 1603 | |
| 1604 | 1604 | |
@@ -1619,7 +1619,7 @@ discard block |
||
| 1619 | 1619 | * @return bool true s'il a le droit, false sinon |
| 1620 | 1620 | **/ |
| 1621 | 1621 | function autoriser_auteurcreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1622 | - return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1622 | + return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1623 | 1623 | } |
| 1624 | 1624 | |
| 1625 | 1625 | /** |
@@ -1637,11 +1637,11 @@ discard block |
||
| 1637 | 1637 | * @return bool true s'il a le droit, false sinon |
| 1638 | 1638 | **/ |
| 1639 | 1639 | function autoriser_visiteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1640 | - include_spip('base/abstract_sql'); |
|
| 1641 | - return |
|
| 1642 | - $qui['statut'] === '0minirezo' |
|
| 1643 | - && !$qui['restreint'] |
|
| 1644 | - && ($GLOBALS['meta']['accepter_visiteurs'] != 'non' || sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0); |
|
| 1640 | + include_spip('base/abstract_sql'); |
|
| 1641 | + return |
|
| 1642 | + $qui['statut'] === '0minirezo' |
|
| 1643 | + && !$qui['restreint'] |
|
| 1644 | + && ($GLOBALS['meta']['accepter_visiteurs'] != 'non' || sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0); |
|
| 1645 | 1645 | } |
| 1646 | 1646 | |
| 1647 | 1647 | /** |
@@ -1659,7 +1659,7 @@ discard block |
||
| 1659 | 1659 | * @return bool true s'il a le droit, false sinon |
| 1660 | 1660 | **/ |
| 1661 | 1661 | function autoriser_suiviedito_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1662 | - return $qui['statut'] === '0minirezo'; |
|
| 1662 | + return $qui['statut'] === '0minirezo'; |
|
| 1663 | 1663 | } |
| 1664 | 1664 | |
| 1665 | 1665 | /** |
@@ -1677,7 +1677,7 @@ discard block |
||
| 1677 | 1677 | * @return bool true s'il a le droit, false sinon |
| 1678 | 1678 | **/ |
| 1679 | 1679 | function autoriser_synchro_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1680 | - return $qui['statut'] === '0minirezo'; |
|
| 1680 | + return $qui['statut'] === '0minirezo'; |
|
| 1681 | 1681 | } |
| 1682 | 1682 | |
| 1683 | 1683 | /** |
@@ -1695,7 +1695,7 @@ discard block |
||
| 1695 | 1695 | * @return bool true s'il a le droit, false sinon |
| 1696 | 1696 | **/ |
| 1697 | 1697 | function autoriser_configurerinteractions_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1698 | - return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1698 | + return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1699 | 1699 | } |
| 1700 | 1700 | |
| 1701 | 1701 | /** |
@@ -1713,7 +1713,7 @@ discard block |
||
| 1713 | 1713 | * @return bool true s'il a le droit, false sinon |
| 1714 | 1714 | **/ |
| 1715 | 1715 | function autoriser_configurerlangue_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1716 | - return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1716 | + return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1717 | 1717 | } |
| 1718 | 1718 | |
| 1719 | 1719 | /** |
@@ -1731,7 +1731,7 @@ discard block |
||
| 1731 | 1731 | * @return bool true s'il a le droit, false sinon |
| 1732 | 1732 | **/ |
| 1733 | 1733 | function autoriser_configurermultilinguisme_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1734 | - return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1734 | + return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1735 | 1735 | } |
| 1736 | 1736 | |
| 1737 | 1737 | /** |
@@ -1749,7 +1749,7 @@ discard block |
||
| 1749 | 1749 | * @return bool true s'il a le droit, false sinon |
| 1750 | 1750 | **/ |
| 1751 | 1751 | function autoriser_configurercontenu_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1752 | - return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1752 | + return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1753 | 1753 | } |
| 1754 | 1754 | |
| 1755 | 1755 | /** |
@@ -1767,7 +1767,7 @@ discard block |
||
| 1767 | 1767 | * @return bool true s'il a le droit, false sinon |
| 1768 | 1768 | **/ |
| 1769 | 1769 | function autoriser_configureravancees_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1770 | - return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1770 | + return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1771 | 1771 | } |
| 1772 | 1772 | |
| 1773 | 1773 | /** |
@@ -1785,7 +1785,7 @@ discard block |
||
| 1785 | 1785 | * @return bool true s'il a le droit, false sinon |
| 1786 | 1786 | **/ |
| 1787 | 1787 | function autoriser_adminplugin_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1788 | - return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1788 | + return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1789 | 1789 | } |
| 1790 | 1790 | |
| 1791 | 1791 | /** |
@@ -1803,7 +1803,7 @@ discard block |
||
| 1803 | 1803 | * @return bool true s'il a le droit, false sinon |
| 1804 | 1804 | **/ |
| 1805 | 1805 | function autoriser_admintech_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1806 | - return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1806 | + return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1807 | 1807 | } |
| 1808 | 1808 | |
| 1809 | 1809 | /** |
@@ -1821,7 +1821,7 @@ discard block |
||
| 1821 | 1821 | * @return bool true s'il a le droit, false sinon |
| 1822 | 1822 | **/ |
| 1823 | 1823 | function autoriser_queue_purger_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1824 | - return autoriser('webmestre'); |
|
| 1824 | + return autoriser('webmestre'); |
|
| 1825 | 1825 | } |
| 1826 | 1826 | |
| 1827 | 1827 | |
@@ -1841,11 +1841,11 @@ discard block |
||
| 1841 | 1841 | * @return bool true s'il a le droit, false sinon |
| 1842 | 1842 | **/ |
| 1843 | 1843 | function autoriser_echafauder_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1844 | - if (test_espace_prive()) { |
|
| 1845 | - return (bool) (int) $qui['id_auteur']; |
|
| 1846 | - } else { |
|
| 1847 | - return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1848 | - } |
|
| 1844 | + if (test_espace_prive()) { |
|
| 1845 | + return (bool) (int) $qui['id_auteur']; |
|
| 1846 | + } else { |
|
| 1847 | + return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1848 | + } |
|
| 1849 | 1849 | } |
| 1850 | 1850 | |
| 1851 | 1851 | |
@@ -1860,27 +1860,27 @@ discard block |
||
| 1860 | 1860 | * Identifiants d'auteurs |
| 1861 | 1861 | */ |
| 1862 | 1862 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1863 | - $objet = objet_type($objet); |
|
| 1864 | - $where = [ |
|
| 1865 | - 'objet=' . sql_quote($objet), |
|
| 1866 | - 'id_objet=' . (int) $id_objet |
|
| 1867 | - ]; |
|
| 1868 | - if (!empty($cond)) { |
|
| 1869 | - if (is_array($cond)) { |
|
| 1870 | - $where = array_merge($where, $cond); |
|
| 1871 | - } else { |
|
| 1872 | - $where[] = $cond; |
|
| 1873 | - } |
|
| 1874 | - } |
|
| 1875 | - $auteurs = sql_allfetsel( |
|
| 1876 | - 'id_auteur', |
|
| 1877 | - 'spip_auteurs_liens', |
|
| 1878 | - $where |
|
| 1879 | - ); |
|
| 1880 | - if (is_array($auteurs)) { |
|
| 1881 | - return array_column($auteurs, 'id_auteur'); |
|
| 1882 | - } |
|
| 1883 | - return []; |
|
| 1863 | + $objet = objet_type($objet); |
|
| 1864 | + $where = [ |
|
| 1865 | + 'objet=' . sql_quote($objet), |
|
| 1866 | + 'id_objet=' . (int) $id_objet |
|
| 1867 | + ]; |
|
| 1868 | + if (!empty($cond)) { |
|
| 1869 | + if (is_array($cond)) { |
|
| 1870 | + $where = array_merge($where, $cond); |
|
| 1871 | + } else { |
|
| 1872 | + $where[] = $cond; |
|
| 1873 | + } |
|
| 1874 | + } |
|
| 1875 | + $auteurs = sql_allfetsel( |
|
| 1876 | + 'id_auteur', |
|
| 1877 | + 'spip_auteurs_liens', |
|
| 1878 | + $where |
|
| 1879 | + ); |
|
| 1880 | + if (is_array($auteurs)) { |
|
| 1881 | + return array_column($auteurs, 'id_auteur'); |
|
| 1882 | + } |
|
| 1883 | + return []; |
|
| 1884 | 1884 | } |
| 1885 | 1885 | |
| 1886 | 1886 | /** |
@@ -1893,7 +1893,7 @@ discard block |
||
| 1893 | 1893 | */ |
| 1894 | 1894 | function acces_restreint_rubrique($id_rubrique) { |
| 1895 | 1895 | |
| 1896 | - return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1896 | + return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1897 | 1897 | } |
| 1898 | 1898 | |
| 1899 | 1899 | |
@@ -1906,12 +1906,12 @@ discard block |
||
| 1906 | 1906 | * @return bool true si un parent existe |
| 1907 | 1907 | */ |
| 1908 | 1908 | function verifier_table_non_vide($table = 'spip_rubriques') { |
| 1909 | - static $done = []; |
|
| 1910 | - if (!isset($done[$table])) { |
|
| 1911 | - $done[$table] = sql_countsel($table) > 0; |
|
| 1912 | - } |
|
| 1909 | + static $done = []; |
|
| 1910 | + if (!isset($done[$table])) { |
|
| 1911 | + $done[$table] = sql_countsel($table) > 0; |
|
| 1912 | + } |
|
| 1913 | 1913 | |
| 1914 | - return $done[$table]; |
|
| 1914 | + return $done[$table]; |
|
| 1915 | 1915 | } |
| 1916 | 1916 | |
| 1917 | 1917 | /** |
@@ -1938,12 +1938,12 @@ discard block |
||
| 1938 | 1938 | */ |
| 1939 | 1939 | function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) { |
| 1940 | 1940 | |
| 1941 | - $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1942 | - return match ($s) { |
|
| 1943 | - 'info_redacteurs' => $GLOBALS['meta']['accepter_inscriptions'] === 'oui', |
|
| 1944 | - 'info_visiteurs' => $GLOBALS['meta']['accepter_visiteurs'] === 'oui' || $GLOBALS['meta']['forums_publics'] === 'abo', |
|
| 1945 | - default => false, |
|
| 1946 | - }; |
|
| 1941 | + $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1942 | + return match ($s) { |
|
| 1943 | + 'info_redacteurs' => $GLOBALS['meta']['accepter_inscriptions'] === 'oui', |
|
| 1944 | + 'info_visiteurs' => $GLOBALS['meta']['accepter_visiteurs'] === 'oui' || $GLOBALS['meta']['forums_publics'] === 'abo', |
|
| 1945 | + default => false, |
|
| 1946 | + }; |
|
| 1947 | 1947 | } |
| 1948 | 1948 | |
| 1949 | 1949 | /** |
@@ -1961,7 +1961,7 @@ discard block |
||
| 1961 | 1961 | * @return bool true s'il a le droit, false sinon |
| 1962 | 1962 | **/ |
| 1963 | 1963 | function autoriser_inscription_relancer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1964 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 1964 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 1965 | 1965 | } |
| 1966 | 1966 | |
| 1967 | 1967 | /** |
@@ -1979,5 +1979,5 @@ discard block |
||
| 1979 | 1979 | * @return bool true s'il a le droit, false sinon |
| 1980 | 1980 | **/ |
| 1981 | 1981 | function autoriser_phpinfos_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1982 | - return autoriser('webmestre'); |
|
| 1982 | + return autoriser('webmestre'); |
|
| 1983 | 1983 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * @package SPIP\Core\Minipres |
| 18 | 18 | **/ |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -37,19 +37,19 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | function install_debut_html($titre = 'AUTO', $onLoad = '', $all_inline = false) { |
| 39 | 39 | |
| 40 | - if ($onLoad) { |
|
| 41 | - include_spip('inc/filtres'); |
|
| 42 | - $onLoad = extraire_attribut("<body $onLoad>", 'onload'); |
|
| 43 | - } |
|
| 40 | + if ($onLoad) { |
|
| 41 | + include_spip('inc/filtres'); |
|
| 42 | + $onLoad = extraire_attribut("<body $onLoad>", 'onload'); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - $options = [ |
|
| 46 | - 'all_inline' => $all_inline, |
|
| 47 | - 'onload' => $onLoad, |
|
| 48 | - 'titre' => $titre, |
|
| 49 | - ]; |
|
| 45 | + $options = [ |
|
| 46 | + 'all_inline' => $all_inline, |
|
| 47 | + 'onload' => $onLoad, |
|
| 48 | + 'titre' => $titre, |
|
| 49 | + ]; |
|
| 50 | 50 | |
| 51 | - $minipage = new Admin(); |
|
| 52 | - return $minipage->installDebutPage($options); |
|
| 51 | + $minipage = new Admin(); |
|
| 52 | + return $minipage->installDebutPage($options); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | * @return string Code HTML |
| 62 | 62 | */ |
| 63 | 63 | function install_fin_html() { |
| 64 | - $minipage = new Admin(); |
|
| 65 | - return $minipage->installFinPage(); |
|
| 64 | + $minipage = new Admin(); |
|
| 65 | + return $minipage->installFinPage(); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | |
@@ -101,23 +101,23 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | function minipres($titre = '', $corps = '', $options = []) { |
| 103 | 103 | |
| 104 | - // compat signature old |
|
| 105 | - // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 106 | - $args = func_get_args(); |
|
| 107 | - if (isset($args[2]) && is_string($args[2])) { |
|
| 108 | - $options = ['onload' => $args[2]]; |
|
| 109 | - } |
|
| 110 | - if (isset($args[3])) { |
|
| 111 | - $options['all_inline'] = $args[3]; |
|
| 112 | - } |
|
| 104 | + // compat signature old |
|
| 105 | + // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 106 | + $args = func_get_args(); |
|
| 107 | + if (isset($args[2]) && is_string($args[2])) { |
|
| 108 | + $options = ['onload' => $args[2]]; |
|
| 109 | + } |
|
| 110 | + if (isset($args[3])) { |
|
| 111 | + $options['all_inline'] = $args[3]; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - $options = array_merge([ |
|
| 115 | - 'onload' => '', |
|
| 116 | - 'all_inline' => false, |
|
| 117 | - ], $options); |
|
| 114 | + $options = array_merge([ |
|
| 115 | + 'onload' => '', |
|
| 116 | + 'all_inline' => false, |
|
| 117 | + ], $options); |
|
| 118 | 118 | |
| 119 | - $options['titre'] = $titre; |
|
| 119 | + $options['titre'] = $titre; |
|
| 120 | 120 | |
| 121 | - $minipage = new Admin(); |
|
| 122 | - return $minipage->page($corps, $options); |
|
| 121 | + $minipage = new Admin(); |
|
| 122 | + return $minipage->page($corps, $options); |
|
| 123 | 123 | } |