@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | **/ |
| 8 | 8 | |
| 9 | 9 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 10 | - return; |
|
| 10 | + return; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | include_spip('inc/acces'); |
@@ -101,93 +101,93 @@ discard block |
||
| 101 | 101 | * @return int|bool Timestamp du verrou, false si erreur |
| 102 | 102 | */ |
| 103 | 103 | function spip_nfslock($fichier, $max_age = 0) { |
| 104 | - $tries = 0; |
|
| 104 | + $tries = 0; |
|
| 105 | 105 | |
| 106 | - if (!$max_age) { |
|
| 107 | - $max_age = _DEFAULT_LOCKTIME; |
|
| 108 | - } |
|
| 109 | - $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 106 | + if (!$max_age) { |
|
| 107 | + $max_age = _DEFAULT_LOCKTIME; |
|
| 108 | + } |
|
| 109 | + $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - /* |
|
| 112 | + /* |
|
| 113 | 113 | * 1. create a tmp file with a psuedo random file name. we also make |
| 114 | 114 | * tpath which is a buffer to store the full pathname of the tmp file. |
| 115 | 115 | */ |
| 116 | 116 | |
| 117 | - $id = creer_uniqid(); |
|
| 118 | - $tpath = _DIR_TMP . "slock.$id"; |
|
| 119 | - $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ... |
|
| 120 | - if (!$tmpfd) { /* open failed */ |
|
| 121 | - @fclose($tmpfd); |
|
| 122 | - spip_unlink($tpath); |
|
| 117 | + $id = creer_uniqid(); |
|
| 118 | + $tpath = _DIR_TMP . "slock.$id"; |
|
| 119 | + $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ... |
|
| 120 | + if (!$tmpfd) { /* open failed */ |
|
| 121 | + @fclose($tmpfd); |
|
| 122 | + spip_unlink($tpath); |
|
| 123 | 123 | |
| 124 | - return false; //NFSL_SYSF |
|
| 125 | - } |
|
| 124 | + return false; //NFSL_SYSF |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /* |
|
| 127 | + /* |
|
| 128 | 128 | * 2. make fullpath, a buffer for the full pathname of the lock file. |
| 129 | 129 | * then start looping trying to lock it |
| 130 | 130 | */ |
| 131 | 131 | |
| 132 | - while ($tries < 10) { |
|
| 133 | - /* |
|
| 132 | + while ($tries < 10) { |
|
| 133 | + /* |
|
| 134 | 134 | * 3. link tmp file to lock file. if it goes, we win and we clean |
| 135 | 135 | * up and return the st_ctime of the lock file. |
| 136 | 136 | */ |
| 137 | 137 | |
| 138 | - if (link($tpath, $lock_file) == 1) { |
|
| 139 | - spip_unlink($tpath); /* got it! */ |
|
| 140 | - @fclose($tmpfd); |
|
| 141 | - if (($our_tmp = lstat($lock_file)) == false) { /* stat failed... shouldn't happen */ |
|
| 142 | - spip_unlink($lock_file); |
|
| 138 | + if (link($tpath, $lock_file) == 1) { |
|
| 139 | + spip_unlink($tpath); /* got it! */ |
|
| 140 | + @fclose($tmpfd); |
|
| 141 | + if (($our_tmp = lstat($lock_file)) == false) { /* stat failed... shouldn't happen */ |
|
| 142 | + spip_unlink($lock_file); |
|
| 143 | 143 | |
| 144 | - return false; // (NFSL_SYSF); |
|
| 145 | - } |
|
| 144 | + return false; // (NFSL_SYSF); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - return ($our_tmp['ctime']); |
|
| 148 | - } |
|
| 147 | + return ($our_tmp['ctime']); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /* |
|
| 150 | + /* |
|
| 151 | 151 | * 4. the lock failed. check for a stale lock file, being mindful |
| 152 | 152 | * of NFS and the fact the time is set from the NFS server. we |
| 153 | 153 | * do a write on the tmp file to update its time to the server's |
| 154 | 154 | * idea of "now." |
| 155 | 155 | */ |
| 156 | 156 | |
| 157 | - $old_stat = lstat($lock_file); |
|
| 158 | - if (@fputs($tmpfd, 'zz', 2) != 2 || !$our_tmp = fstat($tmpfd)) { |
|
| 159 | - break; |
|
| 160 | - } /* something bogus is going on */ |
|
| 157 | + $old_stat = lstat($lock_file); |
|
| 158 | + if (@fputs($tmpfd, 'zz', 2) != 2 || !$our_tmp = fstat($tmpfd)) { |
|
| 159 | + break; |
|
| 160 | + } /* something bogus is going on */ |
|
| 161 | 161 | |
| 162 | 162 | |
| 163 | - if ($old_stat != false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) { |
|
| 164 | - spip_unlink($lock_file); /* break the stale lock */ |
|
| 165 | - $tries++; |
|
| 166 | - /* It is CRITICAL that we sleep after breaking |
|
| 163 | + if ($old_stat != false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) { |
|
| 164 | + spip_unlink($lock_file); /* break the stale lock */ |
|
| 165 | + $tries++; |
|
| 166 | + /* It is CRITICAL that we sleep after breaking |
|
| 167 | 167 | * the lock. Otherwise, we could race with |
| 168 | 168 | * another process and unlink it's newly- |
| 169 | 169 | * created file. |
| 170 | 170 | */ |
| 171 | - sleep(1 + random_int(0, 4)); |
|
| 172 | - continue; |
|
| 173 | - } |
|
| 171 | + sleep(1 + random_int(0, 4)); |
|
| 172 | + continue; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /* |
|
| 175 | + /* |
|
| 176 | 176 | * 5. try again |
| 177 | 177 | */ |
| 178 | 178 | |
| 179 | - $tries++; |
|
| 180 | - sleep(1 + random_int(0, 4)); |
|
| 181 | - } |
|
| 179 | + $tries++; |
|
| 180 | + sleep(1 + random_int(0, 4)); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /* |
|
| 183 | + /* |
|
| 184 | 184 | * 6. give up, failure. |
| 185 | 185 | */ |
| 186 | 186 | |
| 187 | - spip_unlink($tpath); |
|
| 188 | - @fclose($tmpfd); |
|
| 187 | + spip_unlink($tpath); |
|
| 188 | + @fclose($tmpfd); |
|
| 189 | 189 | |
| 190 | - return false; //(NFSL_LOCKED); |
|
| 190 | + return false; //(NFSL_LOCKED); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -231,75 +231,75 @@ discard block |
||
| 231 | 231 | * return bool true si déverrouillé, false sinon |
| 232 | 232 | */ |
| 233 | 233 | function spip_nfsunlock($fichier, $birth, $max_age = 0, $test = false) { |
| 234 | - $id = creer_uniqid(); |
|
| 235 | - if (!$max_age) { |
|
| 236 | - $max_age = _DEFAULT_LOCKTIME; |
|
| 237 | - } |
|
| 234 | + $id = creer_uniqid(); |
|
| 235 | + if (!$max_age) { |
|
| 236 | + $max_age = _DEFAULT_LOCKTIME; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /* |
|
| 239 | + /* |
|
| 240 | 240 | * 1. Build a temp file and stat that to get an idea of what the server |
| 241 | 241 | * thinks the current time is (our_tmp.st_ctime).. |
| 242 | 242 | */ |
| 243 | 243 | |
| 244 | - $tpath = _DIR_TMP . "stime.$id"; |
|
| 245 | - $tmpfd = @fopen($tpath, 'w'); |
|
| 246 | - if ( |
|
| 247 | - (!$tmpfd) |
|
| 248 | - or (@fputs($tmpfd, 'zz', 2) != 2) |
|
| 249 | - or !($our_tmp = fstat($tmpfd)) |
|
| 250 | - ) { |
|
| 251 | - /* The open failed, or we can't write the file, or we can't stat it */ |
|
| 252 | - @fclose($tmpfd); |
|
| 253 | - spip_unlink($tpath); |
|
| 244 | + $tpath = _DIR_TMP . "stime.$id"; |
|
| 245 | + $tmpfd = @fopen($tpath, 'w'); |
|
| 246 | + if ( |
|
| 247 | + (!$tmpfd) |
|
| 248 | + or (@fputs($tmpfd, 'zz', 2) != 2) |
|
| 249 | + or !($our_tmp = fstat($tmpfd)) |
|
| 250 | + ) { |
|
| 251 | + /* The open failed, or we can't write the file, or we can't stat it */ |
|
| 252 | + @fclose($tmpfd); |
|
| 253 | + spip_unlink($tpath); |
|
| 254 | 254 | |
| 255 | - return false; //(NFSL_SYSF); |
|
| 256 | - } |
|
| 255 | + return false; //(NFSL_SYSF); |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 259 | - spip_unlink($tpath); |
|
| 258 | + @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 259 | + spip_unlink($tpath); |
|
| 260 | 260 | |
| 261 | - /* |
|
| 261 | + /* |
|
| 262 | 262 | * 2. make fullpath, a buffer for the full pathname of the lock file |
| 263 | 263 | */ |
| 264 | 264 | |
| 265 | - $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 265 | + $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 266 | 266 | |
| 267 | - /* |
|
| 267 | + /* |
|
| 268 | 268 | * 3. If the ctime hasn't been modified, unlink the file and return. If the |
| 269 | 269 | * lock has expired, sleep the usual random interval before returning. |
| 270 | 270 | * If we didn't sleep, there could be a race if the caller immediately |
| 271 | 271 | * tries to relock the file. |
| 272 | 272 | */ |
| 273 | 273 | |
| 274 | - if ( |
|
| 275 | - ($old_stat = @lstat($lock_file)) /* stat succeeds so file is there */ |
|
| 276 | - && ($old_stat['ctime'] == $birth) |
|
| 277 | - ) { /* hasn't been modified since birth */ |
|
| 278 | - if (!$test) { |
|
| 279 | - spip_unlink($lock_file); |
|
| 280 | - } /* so the lock is ours to remove */ |
|
| 281 | - if ($our_tmp['ctime'] >= $birth + $max_age) { /* the lock has expired */ |
|
| 282 | - if (!$test) { |
|
| 283 | - return false; |
|
| 284 | - } //(NFSL_LOST); |
|
| 285 | - sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - return true;//(NFSL_OK); /* success */ |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /* |
|
| 274 | + if ( |
|
| 275 | + ($old_stat = @lstat($lock_file)) /* stat succeeds so file is there */ |
|
| 276 | + && ($old_stat['ctime'] == $birth) |
|
| 277 | + ) { /* hasn't been modified since birth */ |
|
| 278 | + if (!$test) { |
|
| 279 | + spip_unlink($lock_file); |
|
| 280 | + } /* so the lock is ours to remove */ |
|
| 281 | + if ($our_tmp['ctime'] >= $birth + $max_age) { /* the lock has expired */ |
|
| 282 | + if (!$test) { |
|
| 283 | + return false; |
|
| 284 | + } //(NFSL_LOST); |
|
| 285 | + sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + return true;//(NFSL_OK); /* success */ |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /* |
|
| 292 | 292 | * 4. Either ctime has been modified, or the entire lock file is missing. |
| 293 | 293 | * If the lock should still be ours, based on the ctime of the temp |
| 294 | 294 | * file, return with NFSL_STOLEN. If not, then our lock is expired and |
| 295 | 295 | * someone else has grabbed the file, so return NFSL_LOST. |
| 296 | 296 | */ |
| 297 | 297 | |
| 298 | - if ($our_tmp['ctime'] < $birth + $max_age) { /* lock was stolen */ |
|
| 299 | - return false; |
|
| 300 | - } //(NFSL_STOLEN); |
|
| 298 | + if ($our_tmp['ctime'] < $birth + $max_age) { /* lock was stolen */ |
|
| 299 | + return false; |
|
| 300 | + } //(NFSL_STOLEN); |
|
| 301 | 301 | |
| 302 | - return false; //(NFSL_LOST); /* The lock must have expired first. */ |
|
| 302 | + return false; //(NFSL_LOST); /* The lock must have expired first. */ |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | |
@@ -323,5 +323,5 @@ discard block |
||
| 323 | 323 | * return bool true si déverrouillé, false sinon |
| 324 | 324 | */ |
| 325 | 325 | function spip_nfslock_test($fichier, $birth, $max_age = 0) { |
| 326 | - return spip_nfsunlock($fichier, $birth, $max_age, true); |
|
| 326 | + return spip_nfsunlock($fichier, $birth, $max_age, true); |
|
| 327 | 327 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -33,118 +33,118 @@ discard block |
||
| 33 | 33 | **/ |
| 34 | 34 | function analyse_csv($t) { |
| 35 | 35 | |
| 36 | - // Quel est le séparateur ? |
|
| 37 | - $virg = substr_count($t, ','); |
|
| 38 | - $pvirg = substr_count($t, ';'); |
|
| 39 | - $tab = substr_count($t, "\t"); |
|
| 40 | - if ($virg > $pvirg) { |
|
| 41 | - $sep = ','; |
|
| 42 | - $hs = ','; |
|
| 43 | - } else { |
|
| 44 | - $sep = ';'; |
|
| 45 | - $hs = ';'; |
|
| 46 | - $virg = $pvirg; |
|
| 47 | - } |
|
| 48 | - // un certain nombre de tab => le séparateur est tab |
|
| 49 | - if ($tab > $virg / 10) { |
|
| 50 | - $sep = "\t"; |
|
| 51 | - $hs = "\t"; |
|
| 52 | - } |
|
| 36 | + // Quel est le séparateur ? |
|
| 37 | + $virg = substr_count($t, ','); |
|
| 38 | + $pvirg = substr_count($t, ';'); |
|
| 39 | + $tab = substr_count($t, "\t"); |
|
| 40 | + if ($virg > $pvirg) { |
|
| 41 | + $sep = ','; |
|
| 42 | + $hs = ','; |
|
| 43 | + } else { |
|
| 44 | + $sep = ';'; |
|
| 45 | + $hs = ';'; |
|
| 46 | + $virg = $pvirg; |
|
| 47 | + } |
|
| 48 | + // un certain nombre de tab => le séparateur est tab |
|
| 49 | + if ($tab > $virg / 10) { |
|
| 50 | + $sep = "\t"; |
|
| 51 | + $hs = "\t"; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - // un separateur suivi de 3 guillemets attention ! |
|
| 55 | - // attention au ; ou , suceptible d'etre confondu avec un separateur |
|
| 56 | - // on substitue un # et on remplacera a la fin |
|
| 57 | - $t = preg_replace("/([\n$sep])\"\"\"/", '\\1""#', $t); |
|
| 58 | - $t = str_replace('""', '"#', $t); |
|
| 59 | - preg_match_all('/"[^"]*"/', $t, $r); |
|
| 60 | - foreach ($r[0] as $cell) { |
|
| 61 | - $t = str_replace( |
|
| 62 | - $cell, |
|
| 63 | - str_replace( |
|
| 64 | - $sep, |
|
| 65 | - $hs, |
|
| 66 | - str_replace( |
|
| 67 | - "\n", |
|
| 68 | - '``**``', // échapper les saut de lignes, on les remettra après. |
|
| 69 | - substr($cell, 1, -1) |
|
| 70 | - ) |
|
| 71 | - ), |
|
| 72 | - $t |
|
| 73 | - ); |
|
| 74 | - } |
|
| 54 | + // un separateur suivi de 3 guillemets attention ! |
|
| 55 | + // attention au ; ou , suceptible d'etre confondu avec un separateur |
|
| 56 | + // on substitue un # et on remplacera a la fin |
|
| 57 | + $t = preg_replace("/([\n$sep])\"\"\"/", '\\1""#', $t); |
|
| 58 | + $t = str_replace('""', '"#', $t); |
|
| 59 | + preg_match_all('/"[^"]*"/', $t, $r); |
|
| 60 | + foreach ($r[0] as $cell) { |
|
| 61 | + $t = str_replace( |
|
| 62 | + $cell, |
|
| 63 | + str_replace( |
|
| 64 | + $sep, |
|
| 65 | + $hs, |
|
| 66 | + str_replace( |
|
| 67 | + "\n", |
|
| 68 | + '``**``', // échapper les saut de lignes, on les remettra après. |
|
| 69 | + substr($cell, 1, -1) |
|
| 70 | + ) |
|
| 71 | + ), |
|
| 72 | + $t |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $t = preg_replace( |
|
| 77 | - '/\r?\n/', |
|
| 78 | - "\n", |
|
| 79 | - preg_replace('/[\r\n]+/', "\n", $t) |
|
| 80 | - ); |
|
| 76 | + $t = preg_replace( |
|
| 77 | + '/\r?\n/', |
|
| 78 | + "\n", |
|
| 79 | + preg_replace('/[\r\n]+/', "\n", $t) |
|
| 80 | + ); |
|
| 81 | 81 | |
| 82 | - [$entete, $corps] = explode("\n", $t, 2); |
|
| 83 | - $caption = ''; |
|
| 84 | - // sauter la ligne de tete formee seulement de separateurs |
|
| 85 | - if (substr_count($entete, $sep) == strlen($entete)) { |
|
| 86 | - [$entete, $corps] = explode("\n", $corps, 2); |
|
| 87 | - } |
|
| 88 | - // si une seule colonne, en faire le titre |
|
| 89 | - if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) { |
|
| 90 | - $caption = "\n||" . $l[1] . '|'; |
|
| 91 | - [$entete, $corps] = explode("\n", $corps, 2); |
|
| 92 | - } |
|
| 93 | - // si premiere colonne vide, le raccourci doit quand meme produire <th... |
|
| 94 | - if ($entete[0] == $sep) { |
|
| 95 | - $entete = ' ' . $entete; |
|
| 96 | - } |
|
| 82 | + [$entete, $corps] = explode("\n", $t, 2); |
|
| 83 | + $caption = ''; |
|
| 84 | + // sauter la ligne de tete formee seulement de separateurs |
|
| 85 | + if (substr_count($entete, $sep) == strlen($entete)) { |
|
| 86 | + [$entete, $corps] = explode("\n", $corps, 2); |
|
| 87 | + } |
|
| 88 | + // si une seule colonne, en faire le titre |
|
| 89 | + if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) { |
|
| 90 | + $caption = "\n||" . $l[1] . '|'; |
|
| 91 | + [$entete, $corps] = explode("\n", $corps, 2); |
|
| 92 | + } |
|
| 93 | + // si premiere colonne vide, le raccourci doit quand meme produire <th... |
|
| 94 | + if ($entete[0] == $sep) { |
|
| 95 | + $entete = ' ' . $entete; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - $lignes = explode("\n", $corps); |
|
| 98 | + $lignes = explode("\n", $corps); |
|
| 99 | 99 | |
| 100 | - // retrait des lignes vides finales |
|
| 101 | - while ( |
|
| 102 | - count($lignes) > 0 |
|
| 103 | - and preg_match("/^$sep*$/", $lignes[count($lignes) - 1]) |
|
| 104 | - ) { |
|
| 105 | - unset($lignes[count($lignes) - 1]); |
|
| 106 | - } |
|
| 107 | - // calcul du nombre de colonne a chaque ligne |
|
| 108 | - $nbcols = []; |
|
| 109 | - $max = $mil = substr_count($entete, $sep); |
|
| 110 | - foreach ($lignes as $k => $v) { |
|
| 111 | - if ($max <> ($nbcols[$k] = substr_count($v, $sep))) { |
|
| 112 | - if ($max > $nbcols[$k]) { |
|
| 113 | - $mil = $nbcols[$k]; |
|
| 114 | - } else { |
|
| 115 | - $mil = $max; |
|
| 116 | - $max = $nbcols[$k]; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - // Si pas le meme nombre, cadrer au nombre max |
|
| 121 | - if ($mil <> $max) { |
|
| 122 | - foreach ($nbcols as $k => $v) { |
|
| 123 | - if ($v < $max) { |
|
| 124 | - $lignes[$k] .= str_repeat($sep, $max - $v); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - // et retirer les colonnes integralement vides |
|
| 129 | - while (true) { |
|
| 130 | - $nbcols = ($entete[strlen($entete) - 1] === $sep); |
|
| 131 | - foreach ($lignes as $v) { |
|
| 132 | - $nbcols &= ($v[strlen($v) - 1] === $sep); |
|
| 133 | - } |
|
| 134 | - if (!$nbcols) { |
|
| 135 | - break; |
|
| 136 | - } |
|
| 137 | - $entete = substr($entete, 0, -1); |
|
| 138 | - foreach ($lignes as $k => $v) { |
|
| 139 | - $lignes[$k] = substr($v, 0, -1); |
|
| 140 | - } |
|
| 141 | - } |
|
| 100 | + // retrait des lignes vides finales |
|
| 101 | + while ( |
|
| 102 | + count($lignes) > 0 |
|
| 103 | + and preg_match("/^$sep*$/", $lignes[count($lignes) - 1]) |
|
| 104 | + ) { |
|
| 105 | + unset($lignes[count($lignes) - 1]); |
|
| 106 | + } |
|
| 107 | + // calcul du nombre de colonne a chaque ligne |
|
| 108 | + $nbcols = []; |
|
| 109 | + $max = $mil = substr_count($entete, $sep); |
|
| 110 | + foreach ($lignes as $k => $v) { |
|
| 111 | + if ($max <> ($nbcols[$k] = substr_count($v, $sep))) { |
|
| 112 | + if ($max > $nbcols[$k]) { |
|
| 113 | + $mil = $nbcols[$k]; |
|
| 114 | + } else { |
|
| 115 | + $mil = $max; |
|
| 116 | + $max = $nbcols[$k]; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + // Si pas le meme nombre, cadrer au nombre max |
|
| 121 | + if ($mil <> $max) { |
|
| 122 | + foreach ($nbcols as $k => $v) { |
|
| 123 | + if ($v < $max) { |
|
| 124 | + $lignes[$k] .= str_repeat($sep, $max - $v); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + // et retirer les colonnes integralement vides |
|
| 129 | + while (true) { |
|
| 130 | + $nbcols = ($entete[strlen($entete) - 1] === $sep); |
|
| 131 | + foreach ($lignes as $v) { |
|
| 132 | + $nbcols &= ($v[strlen($v) - 1] === $sep); |
|
| 133 | + } |
|
| 134 | + if (!$nbcols) { |
|
| 135 | + break; |
|
| 136 | + } |
|
| 137 | + $entete = substr($entete, 0, -1); |
|
| 138 | + foreach ($lignes as $k => $v) { |
|
| 139 | + $lignes[$k] = substr($v, 0, -1); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - foreach ($lignes as &$l) { |
|
| 144 | - $l = str_replace('"#', '"', $l); |
|
| 145 | - $l = str_replace('``**``', "\n", $l); |
|
| 146 | - $l = explode($sep, $l); |
|
| 147 | - } |
|
| 143 | + foreach ($lignes as &$l) { |
|
| 144 | + $l = str_replace('"#', '"', $l); |
|
| 145 | + $l = str_replace('``**``', "\n", $l); |
|
| 146 | + $l = explode($sep, $l); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - return [explode($sep, $entete), $lignes, $caption]; |
|
| 149 | + return [explode($sep, $entete), $lignes, $caption]; |
|
| 150 | 150 | } |
@@ -18,18 +18,18 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ACTIVER_PUCE_RAPIDE')) { |
| 25 | - /** |
|
| 26 | - * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 27 | - * |
|
| 28 | - * Peut ralentir un site sur des listes très longues. |
|
| 29 | - * |
|
| 30 | - * @var bool |
|
| 31 | - **/ |
|
| 32 | - define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 25 | + /** |
|
| 26 | + * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 27 | + * |
|
| 28 | + * Peut ralentir un site sur des listes très longues. |
|
| 29 | + * |
|
| 30 | + * @var bool |
|
| 31 | + **/ |
|
| 32 | + define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -57,31 +57,31 @@ discard block |
||
| 57 | 57 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 58 | 58 | */ |
| 59 | 59 | function inc_puce_statut_dist( |
| 60 | - $id_objet, |
|
| 61 | - $statut, |
|
| 62 | - $id_parent, |
|
| 63 | - $type, |
|
| 64 | - $ajax = false, |
|
| 65 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 60 | + $id_objet, |
|
| 61 | + $statut, |
|
| 62 | + $id_parent, |
|
| 63 | + $type, |
|
| 64 | + $ajax = false, |
|
| 65 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 66 | 66 | ) { |
| 67 | - static $f_puce_statut = []; |
|
| 68 | - $type = objet_type($type); |
|
| 69 | - // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 70 | - if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) { |
|
| 71 | - $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 72 | - } |
|
| 73 | - if ($f_puce_statut[$type]) { |
|
| 74 | - return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 78 | - // composer une puce, avec si possible changement rapide |
|
| 79 | - elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 80 | - return $puce; |
|
| 81 | - } // sinon fausse puce avec le type de l'image |
|
| 82 | - else { |
|
| 83 | - return http_img_pack("$type-16.png", ''); |
|
| 84 | - } |
|
| 67 | + static $f_puce_statut = []; |
|
| 68 | + $type = objet_type($type); |
|
| 69 | + // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 70 | + if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) { |
|
| 71 | + $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 72 | + } |
|
| 73 | + if ($f_puce_statut[$type]) { |
|
| 74 | + return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 78 | + // composer une puce, avec si possible changement rapide |
|
| 79 | + elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 80 | + return $puce; |
|
| 81 | + } // sinon fausse puce avec le type de l'image |
|
| 82 | + else { |
|
| 83 | + return http_img_pack("$type-16.png", ''); |
|
| 84 | + } |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -110,41 +110,41 @@ discard block |
||
| 110 | 110 | * null si pas capable de déterminer l'image |
| 111 | 111 | */ |
| 112 | 112 | function statut_image($objet, $statut) { |
| 113 | - $src = null; |
|
| 114 | - $table = table_objet_sql($objet); |
|
| 115 | - $desc = lister_tables_objets_sql($table); |
|
| 116 | - if (isset($desc['statut_images'])) { |
|
| 117 | - // si une declaration statut_images |
|
| 118 | - // mais rien pour le statut demande, ne rien afficher |
|
| 119 | - $src = ''; |
|
| 120 | - if (isset($desc['statut_images'][$statut])) { |
|
| 121 | - $src = $desc['statut_images'][$statut]; |
|
| 122 | - } // sinon image par defaut ? |
|
| 123 | - elseif (isset($desc['statut_images'][0])) { |
|
| 124 | - $src = $desc['statut_images'][0]; |
|
| 125 | - } |
|
| 126 | - } else { |
|
| 127 | - switch ($statut) { |
|
| 128 | - case 'prepa': |
|
| 129 | - $src = 'puce-preparer-xx.svg?12px'; |
|
| 130 | - break; |
|
| 131 | - case 'prop': |
|
| 132 | - $src = 'puce-proposer-xx.svg?12px'; |
|
| 133 | - break; |
|
| 134 | - case 'publie': |
|
| 135 | - $src = 'puce-publier-xx.svg?12px'; |
|
| 136 | - break; |
|
| 137 | - case 'refuse': |
|
| 138 | - $src = 'puce-refuser-xx.svg?12px'; |
|
| 139 | - break; |
|
| 140 | - case 'poubelle': |
|
| 141 | - case 'poub': |
|
| 142 | - $src = 'puce-supprimer-xx.svg?12px'; |
|
| 143 | - break; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return $src; |
|
| 113 | + $src = null; |
|
| 114 | + $table = table_objet_sql($objet); |
|
| 115 | + $desc = lister_tables_objets_sql($table); |
|
| 116 | + if (isset($desc['statut_images'])) { |
|
| 117 | + // si une declaration statut_images |
|
| 118 | + // mais rien pour le statut demande, ne rien afficher |
|
| 119 | + $src = ''; |
|
| 120 | + if (isset($desc['statut_images'][$statut])) { |
|
| 121 | + $src = $desc['statut_images'][$statut]; |
|
| 122 | + } // sinon image par defaut ? |
|
| 123 | + elseif (isset($desc['statut_images'][0])) { |
|
| 124 | + $src = $desc['statut_images'][0]; |
|
| 125 | + } |
|
| 126 | + } else { |
|
| 127 | + switch ($statut) { |
|
| 128 | + case 'prepa': |
|
| 129 | + $src = 'puce-preparer-xx.svg?12px'; |
|
| 130 | + break; |
|
| 131 | + case 'prop': |
|
| 132 | + $src = 'puce-proposer-xx.svg?12px'; |
|
| 133 | + break; |
|
| 134 | + case 'publie': |
|
| 135 | + $src = 'puce-publier-xx.svg?12px'; |
|
| 136 | + break; |
|
| 137 | + case 'refuse': |
|
| 138 | + $src = 'puce-refuser-xx.svg?12px'; |
|
| 139 | + break; |
|
| 140 | + case 'poubelle': |
|
| 141 | + case 'poub': |
|
| 142 | + $src = 'puce-supprimer-xx.svg?12px'; |
|
| 143 | + break; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return $src; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -172,40 +172,40 @@ discard block |
||
| 172 | 172 | * @return string |
| 173 | 173 | */ |
| 174 | 174 | function statut_titre($objet, $statut) { |
| 175 | - $titre = ''; |
|
| 176 | - $table = table_objet_sql($objet); |
|
| 177 | - $desc = lister_tables_objets_sql($table); |
|
| 178 | - if (isset($desc['statut_titres'])) { |
|
| 179 | - // si une declaration statut_titres |
|
| 180 | - // mais rien pour le statut demande, ne rien afficher |
|
| 181 | - if (isset($desc['statut_titres'][$statut])) { |
|
| 182 | - $titre = $desc['statut_titres'][$statut]; |
|
| 183 | - } // sinon image par defaut ? |
|
| 184 | - elseif (isset($desc['statut_titres'][0])) { |
|
| 185 | - $titre = $desc['statut_titres'][0]; |
|
| 186 | - } |
|
| 187 | - } else { |
|
| 188 | - switch ($statut) { |
|
| 189 | - case 'prepa': |
|
| 190 | - $titre = 'texte_statut_en_cours_redaction'; |
|
| 191 | - break; |
|
| 192 | - case 'prop': |
|
| 193 | - $titre = 'texte_statut_propose_evaluation'; |
|
| 194 | - break; |
|
| 195 | - case 'publie': |
|
| 196 | - $titre = 'texte_statut_publie'; |
|
| 197 | - break; |
|
| 198 | - case 'refuse': |
|
| 199 | - $titre = 'texte_statut_refuse'; |
|
| 200 | - break; |
|
| 201 | - case 'poubelle': |
|
| 202 | - case 'poub': |
|
| 203 | - $titre = 'texte_statut_poubelle'; |
|
| 204 | - break; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return $titre ? _T($titre) : ''; |
|
| 175 | + $titre = ''; |
|
| 176 | + $table = table_objet_sql($objet); |
|
| 177 | + $desc = lister_tables_objets_sql($table); |
|
| 178 | + if (isset($desc['statut_titres'])) { |
|
| 179 | + // si une declaration statut_titres |
|
| 180 | + // mais rien pour le statut demande, ne rien afficher |
|
| 181 | + if (isset($desc['statut_titres'][$statut])) { |
|
| 182 | + $titre = $desc['statut_titres'][$statut]; |
|
| 183 | + } // sinon image par defaut ? |
|
| 184 | + elseif (isset($desc['statut_titres'][0])) { |
|
| 185 | + $titre = $desc['statut_titres'][0]; |
|
| 186 | + } |
|
| 187 | + } else { |
|
| 188 | + switch ($statut) { |
|
| 189 | + case 'prepa': |
|
| 190 | + $titre = 'texte_statut_en_cours_redaction'; |
|
| 191 | + break; |
|
| 192 | + case 'prop': |
|
| 193 | + $titre = 'texte_statut_propose_evaluation'; |
|
| 194 | + break; |
|
| 195 | + case 'publie': |
|
| 196 | + $titre = 'texte_statut_publie'; |
|
| 197 | + break; |
|
| 198 | + case 'refuse': |
|
| 199 | + $titre = 'texte_statut_refuse'; |
|
| 200 | + break; |
|
| 201 | + case 'poubelle': |
|
| 202 | + case 'poub': |
|
| 203 | + $titre = 'texte_statut_poubelle'; |
|
| 204 | + break; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return $titre ? _T($titre) : ''; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | |
@@ -225,37 +225,37 @@ discard block |
||
| 225 | 225 | * @return string |
| 226 | 226 | */ |
| 227 | 227 | function statut_texte_instituer($objet, $statut) { |
| 228 | - $texte = ''; |
|
| 229 | - $table = table_objet_sql($objet); |
|
| 230 | - $desc = lister_tables_objets_sql($table); |
|
| 231 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 232 | - // si une declaration statut_titres |
|
| 233 | - // mais rien pour le statut demande, ne rien afficher |
|
| 234 | - if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 235 | - $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 236 | - } |
|
| 237 | - } else { |
|
| 238 | - switch ($statut) { |
|
| 239 | - case 'prepa': |
|
| 240 | - $texte = 'texte_statut_en_cours_redaction'; |
|
| 241 | - break; |
|
| 242 | - case 'prop': |
|
| 243 | - $texte = 'texte_statut_propose_evaluation'; |
|
| 244 | - break; |
|
| 245 | - case 'publie': |
|
| 246 | - $texte = 'texte_statut_publie'; |
|
| 247 | - break; |
|
| 248 | - case 'refuse': |
|
| 249 | - $texte = 'texte_statut_refuse'; |
|
| 250 | - break; |
|
| 251 | - case 'poubelle': |
|
| 252 | - case 'poub': |
|
| 253 | - $texte = 'texte_statut_poubelle'; |
|
| 254 | - break; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $texte ? _T($texte) : ''; |
|
| 228 | + $texte = ''; |
|
| 229 | + $table = table_objet_sql($objet); |
|
| 230 | + $desc = lister_tables_objets_sql($table); |
|
| 231 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 232 | + // si une declaration statut_titres |
|
| 233 | + // mais rien pour le statut demande, ne rien afficher |
|
| 234 | + if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 235 | + $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 236 | + } |
|
| 237 | + } else { |
|
| 238 | + switch ($statut) { |
|
| 239 | + case 'prepa': |
|
| 240 | + $texte = 'texte_statut_en_cours_redaction'; |
|
| 241 | + break; |
|
| 242 | + case 'prop': |
|
| 243 | + $texte = 'texte_statut_propose_evaluation'; |
|
| 244 | + break; |
|
| 245 | + case 'publie': |
|
| 246 | + $texte = 'texte_statut_publie'; |
|
| 247 | + break; |
|
| 248 | + case 'refuse': |
|
| 249 | + $texte = 'texte_statut_refuse'; |
|
| 250 | + break; |
|
| 251 | + case 'poubelle': |
|
| 252 | + case 'poub': |
|
| 253 | + $texte = 'texte_statut_poubelle'; |
|
| 254 | + break; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $texte ? _T($texte) : ''; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | |
@@ -275,16 +275,16 @@ discard block |
||
| 275 | 275 | * @return string |
| 276 | 276 | */ |
| 277 | 277 | function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 278 | - $img = statut_image('auteur', $statut); |
|
| 279 | - if (!$img) { |
|
| 280 | - return ''; |
|
| 281 | - } |
|
| 282 | - $alt = statut_titre('auteur', $statut); |
|
| 278 | + $img = statut_image('auteur', $statut); |
|
| 279 | + if (!$img) { |
|
| 280 | + return ''; |
|
| 281 | + } |
|
| 282 | + $alt = statut_titre('auteur', $statut); |
|
| 283 | 283 | |
| 284 | - $fond = ''; |
|
| 285 | - $titre = ''; |
|
| 284 | + $fond = ''; |
|
| 285 | + $titre = ''; |
|
| 286 | 286 | |
| 287 | - /* |
|
| 287 | + /* |
|
| 288 | 288 | if ($type != 'auteur') { |
| 289 | 289 | $img2 = chemin_image('del-16.png'); |
| 290 | 290 | $titre = _T('titre_image_redacteur'); |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | } |
| 295 | 295 | */ |
| 296 | 296 | |
| 297 | - return http_img_pack($img, $alt, $fond, $alt); |
|
| 297 | + return http_img_pack($img, $alt, $fond, $alt); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
| 301 | 301 | function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 302 | - return http_img_pack('rubrique-16.png', ''); |
|
| 302 | + return http_img_pack('rubrique-16.png', ''); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -323,110 +323,110 @@ discard block |
||
| 323 | 323 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 324 | 324 | **/ |
| 325 | 325 | function puce_statut_changement_rapide( |
| 326 | - $id, |
|
| 327 | - $statut, |
|
| 328 | - $id_rubrique, |
|
| 329 | - $type = 'article', |
|
| 330 | - $ajax = false, |
|
| 331 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 326 | + $id, |
|
| 327 | + $statut, |
|
| 328 | + $id_rubrique, |
|
| 329 | + $type = 'article', |
|
| 330 | + $ajax = false, |
|
| 331 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 332 | 332 | ) { |
| 333 | - $src = statut_image($type, $statut); |
|
| 334 | - if (!$src) { |
|
| 335 | - return $src; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - if ( |
|
| 339 | - !$id |
|
| 340 | - or !_SPIP_AJAX |
|
| 341 | - or !$menu_rapide |
|
| 342 | - ) { |
|
| 343 | - $ajax_node = ''; |
|
| 344 | - } else { |
|
| 345 | - $ajax_node = " class='imgstatut$type$id'"; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - $t = statut_titre($type, $statut); |
|
| 350 | - $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 351 | - |
|
| 352 | - if (!$ajax_node) { |
|
| 353 | - return $inser_puce; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - $table = table_objet_sql($type); |
|
| 357 | - $desc = lister_tables_objets_sql($table); |
|
| 358 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 359 | - return $inser_puce; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - if (!function_exists('autoriser')) { |
|
| 363 | - include_spip('inc/autoriser'); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 367 | - if ($id_rubrique) { |
|
| 368 | - if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 369 | - return $inser_puce; |
|
| 370 | - } |
|
| 371 | - } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 372 | - else { |
|
| 373 | - if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 374 | - return $inser_puce; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 379 | - if (!isset($coord[$statut])) { |
|
| 380 | - return $inser_puce; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 384 | - ; |
|
| 385 | - $margin = 0; /* marge a gauche + droite */ |
|
| 386 | - $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 387 | - ; |
|
| 388 | - $clip = $zero + ($unit * $coord[$statut]); |
|
| 389 | - |
|
| 390 | - if ($ajax) { |
|
| 391 | - $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin; |
|
| 392 | - $out = "<span class='puce_objet_fixe $type'>" |
|
| 393 | - . $inser_puce |
|
| 394 | - . '</span>' |
|
| 395 | - . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 396 | - $i = 0; |
|
| 397 | - foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 398 | - $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 399 | - } |
|
| 400 | - $out .= '</span>'; |
|
| 401 | - |
|
| 402 | - return $out; |
|
| 403 | - } else { |
|
| 404 | - $nom = 'puce_statut_'; |
|
| 405 | - $action = generer_url_ecrire('puce_statut', '', true); |
|
| 406 | - $lang_dir = lang_dir(lang_typo()); |
|
| 407 | - |
|
| 408 | - return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 409 | - . $inser_puce |
|
| 410 | - . '</span>'; |
|
| 411 | - } |
|
| 333 | + $src = statut_image($type, $statut); |
|
| 334 | + if (!$src) { |
|
| 335 | + return $src; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + if ( |
|
| 339 | + !$id |
|
| 340 | + or !_SPIP_AJAX |
|
| 341 | + or !$menu_rapide |
|
| 342 | + ) { |
|
| 343 | + $ajax_node = ''; |
|
| 344 | + } else { |
|
| 345 | + $ajax_node = " class='imgstatut$type$id'"; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + $t = statut_titre($type, $statut); |
|
| 350 | + $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 351 | + |
|
| 352 | + if (!$ajax_node) { |
|
| 353 | + return $inser_puce; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + $table = table_objet_sql($type); |
|
| 357 | + $desc = lister_tables_objets_sql($table); |
|
| 358 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 359 | + return $inser_puce; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + if (!function_exists('autoriser')) { |
|
| 363 | + include_spip('inc/autoriser'); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 367 | + if ($id_rubrique) { |
|
| 368 | + if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 369 | + return $inser_puce; |
|
| 370 | + } |
|
| 371 | + } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 372 | + else { |
|
| 373 | + if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 374 | + return $inser_puce; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 379 | + if (!isset($coord[$statut])) { |
|
| 380 | + return $inser_puce; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 384 | + ; |
|
| 385 | + $margin = 0; /* marge a gauche + droite */ |
|
| 386 | + $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 387 | + ; |
|
| 388 | + $clip = $zero + ($unit * $coord[$statut]); |
|
| 389 | + |
|
| 390 | + if ($ajax) { |
|
| 391 | + $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin; |
|
| 392 | + $out = "<span class='puce_objet_fixe $type'>" |
|
| 393 | + . $inser_puce |
|
| 394 | + . '</span>' |
|
| 395 | + . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 396 | + $i = 0; |
|
| 397 | + foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 398 | + $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 399 | + } |
|
| 400 | + $out .= '</span>'; |
|
| 401 | + |
|
| 402 | + return $out; |
|
| 403 | + } else { |
|
| 404 | + $nom = 'puce_statut_'; |
|
| 405 | + $action = generer_url_ecrire('puce_statut', '', true); |
|
| 406 | + $lang_dir = lang_dir(lang_typo()); |
|
| 407 | + |
|
| 408 | + return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 409 | + . $inser_puce |
|
| 410 | + . '</span>'; |
|
| 411 | + } |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | |
| 415 | 415 | function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') { |
| 416 | - $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 417 | - $t = supprimer_tags($titre); |
|
| 416 | + $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 417 | + $t = supprimer_tags($titre); |
|
| 418 | 418 | |
| 419 | - return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 419 | + return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | // compat |
| 423 | 423 | // La couleur du statut |
| 424 | 424 | |
| 425 | 425 | function puce_statut($statut, $atts = '') { |
| 426 | - $src = statut_image('article', $statut); |
|
| 427 | - if (!$src) { |
|
| 428 | - return ''; |
|
| 429 | - } |
|
| 426 | + $src = statut_image('article', $statut); |
|
| 427 | + if (!$src) { |
|
| 428 | + return ''; |
|
| 429 | + } |
|
| 430 | 430 | |
| 431 | - return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 431 | + return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 432 | 432 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -50,19 +50,19 @@ discard block |
||
| 50 | 50 | * @return array|string |
| 51 | 51 | */ |
| 52 | 52 | function inc_securiser_action_dist($action = '', $arg = '', $redirect = '', $mode = false, $att = '', $public = false) { |
| 53 | - if ($action) { |
|
| 54 | - return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public); |
|
| 55 | - } else { |
|
| 56 | - $arg = _request('arg'); |
|
| 57 | - $hash = _request('hash'); |
|
| 58 | - $action = _request('action') ?: _request('formulaire_action'); |
|
| 59 | - if ($a = verifier_action_auteur("$action-$arg", $hash)) { |
|
| 60 | - return $arg; |
|
| 61 | - } |
|
| 62 | - include_spip('inc/minipres'); |
|
| 63 | - echo minipres(); |
|
| 64 | - exit; |
|
| 65 | - } |
|
| 53 | + if ($action) { |
|
| 54 | + return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public); |
|
| 55 | + } else { |
|
| 56 | + $arg = _request('arg'); |
|
| 57 | + $hash = _request('hash'); |
|
| 58 | + $action = _request('action') ?: _request('formulaire_action'); |
|
| 59 | + if ($a = verifier_action_auteur("$action-$arg", $hash)) { |
|
| 60 | + return $arg; |
|
| 61 | + } |
|
| 62 | + include_spip('inc/minipres'); |
|
| 63 | + echo minipres(); |
|
| 64 | + exit; |
|
| 65 | + } |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -81,29 +81,29 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | function demander_confirmation_avant_action($titre, $titre_bouton, $url_action = null) { |
| 83 | 83 | |
| 84 | - if (!$url_action) { |
|
| 85 | - $url_action = self(); |
|
| 86 | - $action = _request('action'); |
|
| 87 | - $url_action = parametre_url($url_action, 'action', $action, '&'); |
|
| 88 | - } |
|
| 89 | - else { |
|
| 90 | - $action = parametre_url($url_action, 'action'); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $arg = parametre_url($url_action, 'arg'); |
|
| 94 | - $confirm = md5("$action:$arg:" . realpath(__FILE__)); |
|
| 95 | - if (_request('confirm_action') === $confirm) { |
|
| 96 | - return true; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $url_confirm = parametre_url($url_action, 'confirm_action', $confirm, '&'); |
|
| 100 | - include_spip('inc/filtres'); |
|
| 101 | - $bouton_action = bouton_action($titre_bouton, $url_confirm); |
|
| 102 | - $corps = "<div style='text-align:center;'>$bouton_action</div>"; |
|
| 103 | - |
|
| 104 | - include_spip('inc/minipres'); |
|
| 105 | - echo minipres($titre, $corps); |
|
| 106 | - exit; |
|
| 84 | + if (!$url_action) { |
|
| 85 | + $url_action = self(); |
|
| 86 | + $action = _request('action'); |
|
| 87 | + $url_action = parametre_url($url_action, 'action', $action, '&'); |
|
| 88 | + } |
|
| 89 | + else { |
|
| 90 | + $action = parametre_url($url_action, 'action'); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $arg = parametre_url($url_action, 'arg'); |
|
| 94 | + $confirm = md5("$action:$arg:" . realpath(__FILE__)); |
|
| 95 | + if (_request('confirm_action') === $confirm) { |
|
| 96 | + return true; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $url_confirm = parametre_url($url_action, 'confirm_action', $confirm, '&'); |
|
| 100 | + include_spip('inc/filtres'); |
|
| 101 | + $bouton_action = bouton_action($titre_bouton, $url_confirm); |
|
| 102 | + $corps = "<div style='text-align:center;'>$bouton_action</div>"; |
|
| 103 | + |
|
| 104 | + include_spip('inc/minipres'); |
|
| 105 | + echo minipres($titre, $corps); |
|
| 106 | + exit; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -135,34 +135,34 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | function securiser_action_auteur($action, $arg, $redirect = '', $mode = false, $att = '', $public = false) { |
| 137 | 137 | |
| 138 | - // mode URL ou array |
|
| 139 | - if (!is_string($mode)) { |
|
| 140 | - $hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null); |
|
| 141 | - |
|
| 142 | - $r = rawurlencode($redirect); |
|
| 143 | - if ($mode === -1) { |
|
| 144 | - return ['action' => $action, 'arg' => $arg, 'hash' => $hash]; |
|
| 145 | - } else { |
|
| 146 | - return generer_url_action( |
|
| 147 | - $action, |
|
| 148 | - 'arg=' . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"), |
|
| 149 | - $mode, |
|
| 150 | - $public |
|
| 151 | - ); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // mode formulaire |
|
| 156 | - $hash = calculer_action_auteur("$action-$arg"); |
|
| 157 | - $att .= " style='margin: 0px; border: 0px'"; |
|
| 158 | - if ($redirect) { |
|
| 159 | - $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", ''', $redirect) . "' />"; |
|
| 160 | - } |
|
| 161 | - $mode .= $redirect . " |
|
| 138 | + // mode URL ou array |
|
| 139 | + if (!is_string($mode)) { |
|
| 140 | + $hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null); |
|
| 141 | + |
|
| 142 | + $r = rawurlencode($redirect); |
|
| 143 | + if ($mode === -1) { |
|
| 144 | + return ['action' => $action, 'arg' => $arg, 'hash' => $hash]; |
|
| 145 | + } else { |
|
| 146 | + return generer_url_action( |
|
| 147 | + $action, |
|
| 148 | + 'arg=' . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"), |
|
| 149 | + $mode, |
|
| 150 | + $public |
|
| 151 | + ); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // mode formulaire |
|
| 156 | + $hash = calculer_action_auteur("$action-$arg"); |
|
| 157 | + $att .= " style='margin: 0px; border: 0px'"; |
|
| 158 | + if ($redirect) { |
|
| 159 | + $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", ''', $redirect) . "' />"; |
|
| 160 | + } |
|
| 161 | + $mode .= $redirect . " |
|
| 162 | 162 | <input name='hash' type='hidden' value='$hash' /> |
| 163 | 163 | <input name='arg' type='hidden' value='$arg' />"; |
| 164 | 164 | |
| 165 | - return generer_form_action($action, $mode, $att, $public); |
|
| 165 | + return generer_form_action($action, $mode, $att, $public); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -172,48 +172,48 @@ discard block |
||
| 172 | 172 | * @return array |
| 173 | 173 | */ |
| 174 | 174 | function caracteriser_auteur($id_auteur = null) { |
| 175 | - static $caracterisation = []; |
|
| 176 | - |
|
| 177 | - if (is_null($id_auteur) and !isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 178 | - // si l'auteur courant n'est pas connu alors qu'il peut demander une action |
|
| 179 | - // c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie. |
|
| 180 | - // S'il n'avait pas le droit de realiser cette action, le hash sera faux. |
|
| 181 | - if ( |
|
| 182 | - isset($_COOKIE['spip_session']) |
|
| 183 | - and (preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r)) |
|
| 184 | - ) { |
|
| 185 | - return [$r[1], '']; |
|
| 186 | - // Necessaire aux forums anonymes. |
|
| 187 | - // Pour le reste, ca echouera. |
|
| 188 | - } else { |
|
| 189 | - return ['0', '']; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - // Eviter l'acces SQL si le pass est connu de PHP |
|
| 193 | - if (is_null($id_auteur)) { |
|
| 194 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 195 | - if (isset($GLOBALS['visiteur_session']['pass']) and $GLOBALS['visiteur_session']['pass']) { |
|
| 196 | - return $caracterisation[$id_auteur] = [$id_auteur, $GLOBALS['visiteur_session']['pass']]; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (isset($caracterisation[$id_auteur])) { |
|
| 201 | - return $caracterisation[$id_auteur]; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if ($id_auteur) { |
|
| 205 | - include_spip('base/abstract_sql'); |
|
| 206 | - $t = sql_fetsel('id_auteur, pass', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 207 | - if ($t) { |
|
| 208 | - return $caracterisation[$id_auteur] = [$t['id_auteur'], $t['pass']]; |
|
| 209 | - } |
|
| 210 | - include_spip('inc/minipres'); |
|
| 211 | - echo minipres(); |
|
| 212 | - exit; |
|
| 213 | - } // Visiteur anonyme, pour ls forums par exemple |
|
| 214 | - else { |
|
| 215 | - return ['0', '']; |
|
| 216 | - } |
|
| 175 | + static $caracterisation = []; |
|
| 176 | + |
|
| 177 | + if (is_null($id_auteur) and !isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 178 | + // si l'auteur courant n'est pas connu alors qu'il peut demander une action |
|
| 179 | + // c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie. |
|
| 180 | + // S'il n'avait pas le droit de realiser cette action, le hash sera faux. |
|
| 181 | + if ( |
|
| 182 | + isset($_COOKIE['spip_session']) |
|
| 183 | + and (preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r)) |
|
| 184 | + ) { |
|
| 185 | + return [$r[1], '']; |
|
| 186 | + // Necessaire aux forums anonymes. |
|
| 187 | + // Pour le reste, ca echouera. |
|
| 188 | + } else { |
|
| 189 | + return ['0', '']; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + // Eviter l'acces SQL si le pass est connu de PHP |
|
| 193 | + if (is_null($id_auteur)) { |
|
| 194 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 195 | + if (isset($GLOBALS['visiteur_session']['pass']) and $GLOBALS['visiteur_session']['pass']) { |
|
| 196 | + return $caracterisation[$id_auteur] = [$id_auteur, $GLOBALS['visiteur_session']['pass']]; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if (isset($caracterisation[$id_auteur])) { |
|
| 201 | + return $caracterisation[$id_auteur]; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if ($id_auteur) { |
|
| 205 | + include_spip('base/abstract_sql'); |
|
| 206 | + $t = sql_fetsel('id_auteur, pass', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 207 | + if ($t) { |
|
| 208 | + return $caracterisation[$id_auteur] = [$t['id_auteur'], $t['pass']]; |
|
| 209 | + } |
|
| 210 | + include_spip('inc/minipres'); |
|
| 211 | + echo minipres(); |
|
| 212 | + exit; |
|
| 213 | + } // Visiteur anonyme, pour ls forums par exemple |
|
| 214 | + else { |
|
| 215 | + return ['0', '']; |
|
| 216 | + } |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -228,28 +228,28 @@ discard block |
||
| 228 | 228 | * @return string |
| 229 | 229 | */ |
| 230 | 230 | function _action_auteur($action, $id_auteur, $pass, $alea) { |
| 231 | - static $sha = []; |
|
| 232 | - if (!isset($sha[$id_auteur . $pass . $alea])) { |
|
| 233 | - if (!isset($GLOBALS['meta'][$alea])) { |
|
| 234 | - if (!$exec = _request('exec') or !autoriser_sans_cookie($exec)) { |
|
| 235 | - include_spip('inc/acces'); |
|
| 236 | - charger_aleas(); |
|
| 237 | - if (empty($GLOBALS['meta'][$alea])) { |
|
| 238 | - include_spip('inc/minipres'); |
|
| 239 | - echo minipres(); |
|
| 240 | - spip_log("$alea indisponible"); |
|
| 241 | - exit; |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - include_spip('auth/sha256.inc'); |
|
| 246 | - $sha[$id_auteur . $pass . $alea] = spip_sha256($id_auteur . $pass . @$GLOBALS['meta'][$alea]); |
|
| 247 | - } |
|
| 248 | - if (function_exists('sha1')) { |
|
| 249 | - return sha1($action . $sha[$id_auteur . $pass . $alea]); |
|
| 250 | - } else { |
|
| 251 | - return md5($action . $sha[$id_auteur . $pass . $alea]); |
|
| 252 | - } |
|
| 231 | + static $sha = []; |
|
| 232 | + if (!isset($sha[$id_auteur . $pass . $alea])) { |
|
| 233 | + if (!isset($GLOBALS['meta'][$alea])) { |
|
| 234 | + if (!$exec = _request('exec') or !autoriser_sans_cookie($exec)) { |
|
| 235 | + include_spip('inc/acces'); |
|
| 236 | + charger_aleas(); |
|
| 237 | + if (empty($GLOBALS['meta'][$alea])) { |
|
| 238 | + include_spip('inc/minipres'); |
|
| 239 | + echo minipres(); |
|
| 240 | + spip_log("$alea indisponible"); |
|
| 241 | + exit; |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + include_spip('auth/sha256.inc'); |
|
| 246 | + $sha[$id_auteur . $pass . $alea] = spip_sha256($id_auteur . $pass . @$GLOBALS['meta'][$alea]); |
|
| 247 | + } |
|
| 248 | + if (function_exists('sha1')) { |
|
| 249 | + return sha1($action . $sha[$id_auteur . $pass . $alea]); |
|
| 250 | + } else { |
|
| 251 | + return md5($action . $sha[$id_auteur . $pass . $alea]); |
|
| 252 | + } |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -260,9 +260,9 @@ discard block |
||
| 260 | 260 | * @return string |
| 261 | 261 | */ |
| 262 | 262 | function calculer_action_auteur($action, $id_auteur = null) { |
| 263 | - [$id_auteur, $pass] = caracteriser_auteur($id_auteur); |
|
| 263 | + [$id_auteur, $pass] = caracteriser_auteur($id_auteur); |
|
| 264 | 264 | |
| 265 | - return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere'); |
|
| 265 | + return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere'); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | |
@@ -275,15 +275,15 @@ discard block |
||
| 275 | 275 | * @return bool |
| 276 | 276 | */ |
| 277 | 277 | function verifier_action_auteur($action, $hash) { |
| 278 | - [$id_auteur, $pass] = caracteriser_auteur(); |
|
| 279 | - if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere')) { |
|
| 280 | - return true; |
|
| 281 | - } |
|
| 282 | - if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien')) { |
|
| 283 | - return true; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - return false; |
|
| 278 | + [$id_auteur, $pass] = caracteriser_auteur(); |
|
| 279 | + if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere')) { |
|
| 280 | + return true; |
|
| 281 | + } |
|
| 282 | + if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien')) { |
|
| 283 | + return true; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + return false; |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | // |
@@ -299,29 +299,29 @@ discard block |
||
| 299 | 299 | * @return string |
| 300 | 300 | */ |
| 301 | 301 | function secret_du_site() { |
| 302 | - if (!isset($GLOBALS['meta']['secret_du_site'])) { |
|
| 303 | - include_spip('base/abstract_sql'); |
|
| 304 | - $GLOBALS['meta']['secret_du_site'] = sql_getfetsel('valeur', 'spip_meta', "nom='secret_du_site'"); |
|
| 305 | - } |
|
| 306 | - if ( |
|
| 307 | - !isset($GLOBALS['meta']['secret_du_site']) |
|
| 308 | - or (strlen($GLOBALS['meta']['secret_du_site']) < 64) |
|
| 309 | - ) { |
|
| 310 | - include_spip('inc/acces'); |
|
| 311 | - include_spip('auth/sha256.inc'); |
|
| 312 | - ecrire_meta( |
|
| 313 | - 'secret_du_site', |
|
| 314 | - spip_sha256( |
|
| 315 | - $_SERVER['DOCUMENT_ROOT'] |
|
| 316 | - . ($_SERVER['SERVER_SIGNATURE'] ?? '') |
|
| 317 | - . creer_uniqid() |
|
| 318 | - ), |
|
| 319 | - 'non' |
|
| 320 | - ); |
|
| 321 | - lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - return $GLOBALS['meta']['secret_du_site']; |
|
| 302 | + if (!isset($GLOBALS['meta']['secret_du_site'])) { |
|
| 303 | + include_spip('base/abstract_sql'); |
|
| 304 | + $GLOBALS['meta']['secret_du_site'] = sql_getfetsel('valeur', 'spip_meta', "nom='secret_du_site'"); |
|
| 305 | + } |
|
| 306 | + if ( |
|
| 307 | + !isset($GLOBALS['meta']['secret_du_site']) |
|
| 308 | + or (strlen($GLOBALS['meta']['secret_du_site']) < 64) |
|
| 309 | + ) { |
|
| 310 | + include_spip('inc/acces'); |
|
| 311 | + include_spip('auth/sha256.inc'); |
|
| 312 | + ecrire_meta( |
|
| 313 | + 'secret_du_site', |
|
| 314 | + spip_sha256( |
|
| 315 | + $_SERVER['DOCUMENT_ROOT'] |
|
| 316 | + . ($_SERVER['SERVER_SIGNATURE'] ?? '') |
|
| 317 | + . creer_uniqid() |
|
| 318 | + ), |
|
| 319 | + 'non' |
|
| 320 | + ); |
|
| 321 | + lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + return $GLOBALS['meta']['secret_du_site']; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -331,11 +331,11 @@ discard block |
||
| 331 | 331 | * @return string |
| 332 | 332 | */ |
| 333 | 333 | function calculer_cle_action($action) { |
| 334 | - if (function_exists('sha1')) { |
|
| 335 | - return sha1($action . secret_du_site()); |
|
| 336 | - } else { |
|
| 337 | - return md5($action . secret_du_site()); |
|
| 338 | - } |
|
| 334 | + if (function_exists('sha1')) { |
|
| 335 | + return sha1($action . secret_du_site()); |
|
| 336 | + } else { |
|
| 337 | + return md5($action . secret_du_site()); |
|
| 338 | + } |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | * @return bool |
| 347 | 347 | */ |
| 348 | 348 | function verifier_cle_action($action, $cle) { |
| 349 | - return ($cle == calculer_cle_action($action)); |
|
| 349 | + return ($cle == calculer_cle_action($action)); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | |
@@ -363,19 +363,19 @@ discard block |
||
| 363 | 363 | * @return string Token, de la forme "{id}*{hash}" |
| 364 | 364 | */ |
| 365 | 365 | function calculer_token_previsu($url, $id_auteur = null, $alea = 'alea_ephemere') { |
| 366 | - if (is_null($id_auteur)) { |
|
| 367 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 368 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 372 | - return ''; |
|
| 373 | - } |
|
| 374 | - // On nettoie l’URL de tous les var_. |
|
| 375 | - $url = nettoyer_uri_var($url); |
|
| 376 | - |
|
| 377 | - $token = _action_auteur('previsualiser-' . $url, $id_auteur, null, $alea); |
|
| 378 | - return "$id_auteur-$token"; |
|
| 366 | + if (is_null($id_auteur)) { |
|
| 367 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 368 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 372 | + return ''; |
|
| 373 | + } |
|
| 374 | + // On nettoie l’URL de tous les var_. |
|
| 375 | + $url = nettoyer_uri_var($url); |
|
| 376 | + |
|
| 377 | + $token = _action_auteur('previsualiser-' . $url, $id_auteur, null, $alea); |
|
| 378 | + return "$id_auteur-$token"; |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | |
@@ -393,31 +393,31 @@ discard block |
||
| 393 | 393 | * + Tableau (id auteur, type d’objet, id_objet) sinon. |
| 394 | 394 | */ |
| 395 | 395 | function verifier_token_previsu($token) { |
| 396 | - // retrouver auteur / hash |
|
| 397 | - $e = explode('-', $token, 2); |
|
| 398 | - if (count($e) == 2 and is_numeric(reset($e))) { |
|
| 399 | - $id_auteur = intval(reset($e)); |
|
| 400 | - } else { |
|
| 401 | - return false; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - // calculer le type et id de l’url actuelle |
|
| 405 | - include_spip('inc/urls'); |
|
| 406 | - include_spip('inc/filtres_mini'); |
|
| 407 | - $url = url_absolue(self()); |
|
| 408 | - |
|
| 409 | - // verifier le token |
|
| 410 | - $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere'); |
|
| 411 | - if (!$_token or $token !== $_token) { |
|
| 412 | - $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien'); |
|
| 413 | - if (!$_token or $token !== $_token) { |
|
| 414 | - return false; |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - return [ |
|
| 419 | - 'id_auteur' => $id_auteur, |
|
| 420 | - ]; |
|
| 396 | + // retrouver auteur / hash |
|
| 397 | + $e = explode('-', $token, 2); |
|
| 398 | + if (count($e) == 2 and is_numeric(reset($e))) { |
|
| 399 | + $id_auteur = intval(reset($e)); |
|
| 400 | + } else { |
|
| 401 | + return false; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + // calculer le type et id de l’url actuelle |
|
| 405 | + include_spip('inc/urls'); |
|
| 406 | + include_spip('inc/filtres_mini'); |
|
| 407 | + $url = url_absolue(self()); |
|
| 408 | + |
|
| 409 | + // verifier le token |
|
| 410 | + $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere'); |
|
| 411 | + if (!$_token or $token !== $_token) { |
|
| 412 | + $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien'); |
|
| 413 | + if (!$_token or $token !== $_token) { |
|
| 414 | + return false; |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + return [ |
|
| 419 | + 'id_auteur' => $id_auteur, |
|
| 420 | + ]; |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -426,13 +426,13 @@ discard block |
||
| 426 | 426 | * @return bool|array |
| 427 | 427 | */ |
| 428 | 428 | function decrire_token_previsu() { |
| 429 | - static $desc = null; |
|
| 430 | - if (is_null($desc)) { |
|
| 431 | - if ($token = _request('var_previewtoken')) { |
|
| 432 | - $desc = verifier_token_previsu($token); |
|
| 433 | - } else { |
|
| 434 | - $desc = false; |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - return $desc; |
|
| 429 | + static $desc = null; |
|
| 430 | + if (is_null($desc)) { |
|
| 431 | + if ($token = _request('var_previewtoken')) { |
|
| 432 | + $desc = verifier_token_previsu($token); |
|
| 433 | + } else { |
|
| 434 | + $desc = false; |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + return $desc; |
|
| 438 | 438 | } |
@@ -17,13 +17,13 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('IMG_SVG')) { |
| 24 | - // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 25 | - define('IMG_SVG', 128); |
|
| 26 | - define('IMAGETYPE_SVG', 19); |
|
| 24 | + // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 25 | + define('IMG_SVG', 128); |
|
| 26 | + define('IMAGETYPE_SVG', 19); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -39,39 +39,39 @@ discard block |
||
| 39 | 39 | * false si on a pas pu charger l'image |
| 40 | 40 | */ |
| 41 | 41 | function svg_charger($fichier, $maxlen = null) { |
| 42 | - if (strpos($fichier, 'data:image/svg+xml') === 0) { |
|
| 43 | - $image = explode(';', $fichier, 2); |
|
| 44 | - $image = end($image); |
|
| 45 | - if (strpos($image, 'base64,') === 0) { |
|
| 46 | - $image = base64_decode(substr($image, 7)); |
|
| 47 | - } |
|
| 48 | - if (strpos($image, '<svg') !== false) { |
|
| 49 | - return $image; |
|
| 50 | - } |
|
| 51 | - // encodage inconnu ou autre format d'image ? |
|
| 52 | - return false; |
|
| 53 | - } |
|
| 54 | - // c'est peut etre deja une image svg ? |
|
| 55 | - if (strpos($fichier, '<svg') !== false) { |
|
| 56 | - return $fichier; |
|
| 57 | - } |
|
| 58 | - if (!file_exists($fichier)) { |
|
| 59 | - $fichier = supprimer_timestamp($fichier); |
|
| 60 | - if (!file_exists($fichier)) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - if (is_null($maxlen)) { |
|
| 65 | - $image = file_get_contents($fichier); |
|
| 66 | - } |
|
| 67 | - else { |
|
| 68 | - $image = file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 69 | - } |
|
| 70 | - // est-ce bien une image svg ? |
|
| 71 | - if (strpos($image, '<svg') !== false) { |
|
| 72 | - return $image; |
|
| 73 | - } |
|
| 74 | - return false; |
|
| 42 | + if (strpos($fichier, 'data:image/svg+xml') === 0) { |
|
| 43 | + $image = explode(';', $fichier, 2); |
|
| 44 | + $image = end($image); |
|
| 45 | + if (strpos($image, 'base64,') === 0) { |
|
| 46 | + $image = base64_decode(substr($image, 7)); |
|
| 47 | + } |
|
| 48 | + if (strpos($image, '<svg') !== false) { |
|
| 49 | + return $image; |
|
| 50 | + } |
|
| 51 | + // encodage inconnu ou autre format d'image ? |
|
| 52 | + return false; |
|
| 53 | + } |
|
| 54 | + // c'est peut etre deja une image svg ? |
|
| 55 | + if (strpos($fichier, '<svg') !== false) { |
|
| 56 | + return $fichier; |
|
| 57 | + } |
|
| 58 | + if (!file_exists($fichier)) { |
|
| 59 | + $fichier = supprimer_timestamp($fichier); |
|
| 60 | + if (!file_exists($fichier)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + if (is_null($maxlen)) { |
|
| 65 | + $image = file_get_contents($fichier); |
|
| 66 | + } |
|
| 67 | + else { |
|
| 68 | + $image = file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 69 | + } |
|
| 70 | + // est-ce bien une image svg ? |
|
| 71 | + if (strpos($image, '<svg') !== false) { |
|
| 72 | + return $image; |
|
| 73 | + } |
|
| 74 | + return false; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -80,28 +80,28 @@ discard block |
||
| 80 | 80 | * @return array|bool |
| 81 | 81 | */ |
| 82 | 82 | function svg_lire_balise_svg($fichier) { |
| 83 | - if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 88 | - $pe = stripos($debut_fichier, '>', $ps); |
|
| 89 | - $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 90 | - |
|
| 91 | - if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 92 | - if (!function_exists('extraire_attribut')) { |
|
| 93 | - include_spip('inc/filtres'); |
|
| 94 | - } |
|
| 95 | - $attributs = []; |
|
| 96 | - foreach ($matches[1] as $att) { |
|
| 97 | - $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return [$balise_svg, $attributs]; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return false; |
|
| 83 | + if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 88 | + $pe = stripos($debut_fichier, '>', $ps); |
|
| 89 | + $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 90 | + |
|
| 91 | + if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 92 | + if (!function_exists('extraire_attribut')) { |
|
| 93 | + include_spip('inc/filtres'); |
|
| 94 | + } |
|
| 95 | + $attributs = []; |
|
| 96 | + foreach ($matches[1] as $att) { |
|
| 97 | + $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return [$balise_svg, $attributs]; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return false; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | function svg_lire_attributs($img) { |
| 113 | 113 | |
| 114 | - if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 115 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 116 | - return $attributs; |
|
| 117 | - } |
|
| 114 | + if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 115 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 116 | + return $attributs; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return false; |
|
| 119 | + return false; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -126,38 +126,38 @@ discard block |
||
| 126 | 126 | * @return bool|float|int |
| 127 | 127 | */ |
| 128 | 128 | function svg_dimension_to_pixels($dimension, $precision = 2) { |
| 129 | - if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 130 | - switch (strtolower($m[2])) { |
|
| 131 | - case '%': |
|
| 132 | - // on ne sait pas faire :( |
|
| 133 | - return false; |
|
| 134 | - break; |
|
| 135 | - case 'em': |
|
| 136 | - return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 137 | - break; |
|
| 138 | - case 'ex': |
|
| 139 | - return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 140 | - break; |
|
| 141 | - case 'pc': |
|
| 142 | - return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 143 | - break; |
|
| 144 | - case 'cm': |
|
| 145 | - return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm; |
|
| 146 | - break; |
|
| 147 | - case 'mm': |
|
| 148 | - return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm; |
|
| 149 | - break; |
|
| 150 | - case 'in': |
|
| 151 | - return round($m[1] * 96, $precision); // 1 inch = 96px in CSS |
|
| 152 | - break; |
|
| 153 | - case 'px': |
|
| 154 | - case 'pt': |
|
| 155 | - default: |
|
| 156 | - return $m[1]; |
|
| 157 | - break; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - return false; |
|
| 129 | + if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 130 | + switch (strtolower($m[2])) { |
|
| 131 | + case '%': |
|
| 132 | + // on ne sait pas faire :( |
|
| 133 | + return false; |
|
| 134 | + break; |
|
| 135 | + case 'em': |
|
| 136 | + return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 137 | + break; |
|
| 138 | + case 'ex': |
|
| 139 | + return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 140 | + break; |
|
| 141 | + case 'pc': |
|
| 142 | + return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 143 | + break; |
|
| 144 | + case 'cm': |
|
| 145 | + return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm; |
|
| 146 | + break; |
|
| 147 | + case 'mm': |
|
| 148 | + return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm; |
|
| 149 | + break; |
|
| 150 | + case 'in': |
|
| 151 | + return round($m[1] * 96, $precision); // 1 inch = 96px in CSS |
|
| 152 | + break; |
|
| 153 | + case 'px': |
|
| 154 | + case 'pt': |
|
| 155 | + default: |
|
| 156 | + return $m[1]; |
|
| 157 | + break; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + return false; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -168,15 +168,15 @@ discard block |
||
| 168 | 168 | * @return string |
| 169 | 169 | */ |
| 170 | 170 | function svg_change_balise_svg($svg, $old_balise_svg, $attributs) { |
| 171 | - $new_balise_svg = '<svg'; |
|
| 172 | - foreach ($attributs as $k => $v) { |
|
| 173 | - $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 174 | - } |
|
| 175 | - $new_balise_svg .= '>'; |
|
| 176 | - |
|
| 177 | - $p = strpos($svg, $old_balise_svg); |
|
| 178 | - $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 179 | - return $svg; |
|
| 171 | + $new_balise_svg = '<svg'; |
|
| 172 | + foreach ($attributs as $k => $v) { |
|
| 173 | + $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 174 | + } |
|
| 175 | + $new_balise_svg .= '>'; |
|
| 176 | + |
|
| 177 | + $p = strpos($svg, $old_balise_svg); |
|
| 178 | + $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 179 | + return $svg; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -188,15 +188,15 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | function svg_insert_shapes($svg, $shapes, $start = true) { |
| 190 | 190 | |
| 191 | - if ($start === false or $start === 'end') { |
|
| 192 | - $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 193 | - } |
|
| 194 | - else { |
|
| 195 | - $p = stripos($svg, '<svg'); |
|
| 196 | - $p = strpos($svg, '>', $p); |
|
| 197 | - $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 198 | - } |
|
| 199 | - return $svg; |
|
| 191 | + if ($start === false or $start === 'end') { |
|
| 192 | + $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 193 | + } |
|
| 194 | + else { |
|
| 195 | + $p = stripos($svg, '<svg'); |
|
| 196 | + $p = strpos($svg, '>', $p); |
|
| 197 | + $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 198 | + } |
|
| 199 | + return $svg; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -209,13 +209,13 @@ discard block |
||
| 209 | 209 | * @return string |
| 210 | 210 | */ |
| 211 | 211 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 212 | - $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 213 | - $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 214 | - $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 215 | - $g = "<g clip-path=\"url(#$id)\">"; |
|
| 216 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 217 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 218 | - return $svg; |
|
| 212 | + $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 213 | + $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 214 | + $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 215 | + $g = "<g clip-path=\"url(#$id)\">"; |
|
| 216 | + $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 217 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 218 | + return $svg; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -226,22 +226,22 @@ discard block |
||
| 226 | 226 | * @return bool|string |
| 227 | 227 | */ |
| 228 | 228 | function svg_redimensionner($img, $new_width, $new_height) { |
| 229 | - if ( |
|
| 230 | - $svg = svg_charger($img) |
|
| 231 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 232 | - ) { |
|
| 233 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 234 | - if (!isset($attributs['viewBox'])) { |
|
| 235 | - $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 236 | - } |
|
| 237 | - $attributs['width'] = strval($new_width); |
|
| 238 | - $attributs['height'] = strval($new_height); |
|
| 239 | - |
|
| 240 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 241 | - return $svg; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - return $img; |
|
| 229 | + if ( |
|
| 230 | + $svg = svg_charger($img) |
|
| 231 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 232 | + ) { |
|
| 233 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 234 | + if (!isset($attributs['viewBox'])) { |
|
| 235 | + $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 236 | + } |
|
| 237 | + $attributs['width'] = strval($new_width); |
|
| 238 | + $attributs['height'] = strval($new_height); |
|
| 239 | + |
|
| 240 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 241 | + return $svg; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + return $img; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -250,15 +250,15 @@ discard block |
||
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | 252 | function svg_couleur_to_hexa($couleur) { |
| 253 | - if (strpos($couleur, 'rgb(') === 0) { |
|
| 254 | - $c = explode(',', substr($couleur, 4)); |
|
| 255 | - $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
|
| 256 | - } |
|
| 257 | - else { |
|
| 258 | - $couleur = couleur_html_to_hex($couleur); |
|
| 259 | - } |
|
| 260 | - $couleur = '#' . ltrim($couleur, '#'); |
|
| 261 | - return $couleur; |
|
| 253 | + if (strpos($couleur, 'rgb(') === 0) { |
|
| 254 | + $c = explode(',', substr($couleur, 4)); |
|
| 255 | + $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
|
| 256 | + } |
|
| 257 | + else { |
|
| 258 | + $couleur = couleur_html_to_hex($couleur); |
|
| 259 | + } |
|
| 260 | + $couleur = '#' . ltrim($couleur, '#'); |
|
| 261 | + return $couleur; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -267,11 +267,11 @@ discard block |
||
| 267 | 267 | * @return array |
| 268 | 268 | */ |
| 269 | 269 | function svg_couleur_to_rgb($couleur) { |
| 270 | - if (strpos($couleur, 'rgb(') === 0) { |
|
| 271 | - $c = explode(',', substr($couleur, 4)); |
|
| 272 | - return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])]; |
|
| 273 | - } |
|
| 274 | - return _couleur_hex_to_dec($couleur); |
|
| 270 | + if (strpos($couleur, 'rgb(') === 0) { |
|
| 271 | + $c = explode(',', substr($couleur, 4)); |
|
| 272 | + return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])]; |
|
| 273 | + } |
|
| 274 | + return _couleur_hex_to_dec($couleur); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | |
@@ -281,70 +281,70 @@ discard block |
||
| 281 | 281 | * @return array |
| 282 | 282 | */ |
| 283 | 283 | function svg_getimagesize_from_attr($attributs) { |
| 284 | - $width = 350; // default width |
|
| 285 | - $height = 150; // default height |
|
| 286 | - |
|
| 287 | - $viewBox = "0 0 $width $height"; |
|
| 288 | - if (isset($attributs['viewBox'])) { |
|
| 289 | - $viewBox = $attributs['viewBox']; |
|
| 290 | - $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 291 | - } |
|
| 292 | - // et on la convertit en px |
|
| 293 | - $viewBox = explode(' ', $viewBox); |
|
| 294 | - $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 295 | - if (!$viewBox[2]) { |
|
| 296 | - $viewBox[2] = $width; |
|
| 297 | - } |
|
| 298 | - if (!$viewBox[3]) { |
|
| 299 | - $viewBox[3] = $height; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - $coeff = 1; |
|
| 303 | - if ( |
|
| 304 | - isset($attributs['width']) |
|
| 305 | - and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 306 | - ) { |
|
| 307 | - $width = $w; |
|
| 308 | - } |
|
| 309 | - else { |
|
| 310 | - // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 311 | - $width = $viewBox[2]; |
|
| 312 | - if ($width < 1) { |
|
| 313 | - $coeff = max($coeff, 1000); |
|
| 314 | - } |
|
| 315 | - elseif ($width < 10) { |
|
| 316 | - $coeff = max($coeff, 100); |
|
| 317 | - } |
|
| 318 | - elseif ($width < 100) { |
|
| 319 | - $coeff = max($coeff, 10); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - if ( |
|
| 323 | - isset($attributs['height']) |
|
| 324 | - and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 325 | - ) { |
|
| 326 | - $height = $h; |
|
| 327 | - } |
|
| 328 | - else { |
|
| 329 | - $height = $viewBox[3]; |
|
| 330 | - if ($height < 1) { |
|
| 331 | - $coeff = max($coeff, 1000); |
|
| 332 | - } |
|
| 333 | - elseif ($height < 10) { |
|
| 334 | - $coeff = max($coeff, 100); |
|
| 335 | - } |
|
| 336 | - elseif ($height < 100) { |
|
| 337 | - $coeff = max($coeff, 10); |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - // arrondir le width et height en pixel in fine |
|
| 342 | - $width = round($coeff * $width); |
|
| 343 | - $height = round($coeff * $height); |
|
| 344 | - |
|
| 345 | - $viewBox = implode(' ', $viewBox); |
|
| 346 | - |
|
| 347 | - return [$width, $height, $viewBox]; |
|
| 284 | + $width = 350; // default width |
|
| 285 | + $height = 150; // default height |
|
| 286 | + |
|
| 287 | + $viewBox = "0 0 $width $height"; |
|
| 288 | + if (isset($attributs['viewBox'])) { |
|
| 289 | + $viewBox = $attributs['viewBox']; |
|
| 290 | + $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 291 | + } |
|
| 292 | + // et on la convertit en px |
|
| 293 | + $viewBox = explode(' ', $viewBox); |
|
| 294 | + $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 295 | + if (!$viewBox[2]) { |
|
| 296 | + $viewBox[2] = $width; |
|
| 297 | + } |
|
| 298 | + if (!$viewBox[3]) { |
|
| 299 | + $viewBox[3] = $height; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + $coeff = 1; |
|
| 303 | + if ( |
|
| 304 | + isset($attributs['width']) |
|
| 305 | + and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 306 | + ) { |
|
| 307 | + $width = $w; |
|
| 308 | + } |
|
| 309 | + else { |
|
| 310 | + // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 311 | + $width = $viewBox[2]; |
|
| 312 | + if ($width < 1) { |
|
| 313 | + $coeff = max($coeff, 1000); |
|
| 314 | + } |
|
| 315 | + elseif ($width < 10) { |
|
| 316 | + $coeff = max($coeff, 100); |
|
| 317 | + } |
|
| 318 | + elseif ($width < 100) { |
|
| 319 | + $coeff = max($coeff, 10); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + if ( |
|
| 323 | + isset($attributs['height']) |
|
| 324 | + and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 325 | + ) { |
|
| 326 | + $height = $h; |
|
| 327 | + } |
|
| 328 | + else { |
|
| 329 | + $height = $viewBox[3]; |
|
| 330 | + if ($height < 1) { |
|
| 331 | + $coeff = max($coeff, 1000); |
|
| 332 | + } |
|
| 333 | + elseif ($height < 10) { |
|
| 334 | + $coeff = max($coeff, 100); |
|
| 335 | + } |
|
| 336 | + elseif ($height < 100) { |
|
| 337 | + $coeff = max($coeff, 10); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + // arrondir le width et height en pixel in fine |
|
| 342 | + $width = round($coeff * $width); |
|
| 343 | + $height = round($coeff * $height); |
|
| 344 | + |
|
| 345 | + $viewBox = implode(' ', $viewBox); |
|
| 346 | + |
|
| 347 | + return [$width, $height, $viewBox]; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -360,25 +360,25 @@ discard block |
||
| 360 | 360 | * @return string |
| 361 | 361 | */ |
| 362 | 362 | function svg_force_viewBox_px($img, $force_width_and_height = false) { |
| 363 | - if ( |
|
| 364 | - $svg = svg_charger($img) |
|
| 365 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 366 | - ) { |
|
| 367 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 363 | + if ( |
|
| 364 | + $svg = svg_charger($img) |
|
| 365 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 366 | + ) { |
|
| 367 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 368 | 368 | |
| 369 | - [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 369 | + [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 370 | 370 | |
| 371 | - if ($force_width_and_height) { |
|
| 372 | - $attributs['width'] = $width; |
|
| 373 | - $attributs['height'] = $height; |
|
| 374 | - } |
|
| 371 | + if ($force_width_and_height) { |
|
| 372 | + $attributs['width'] = $width; |
|
| 373 | + $attributs['height'] = $height; |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - $attributs['viewBox'] = $viewBox; |
|
| 376 | + $attributs['viewBox'] = $viewBox; |
|
| 377 | 377 | |
| 378 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 379 | - return $svg; |
|
| 380 | - } |
|
| 381 | - return $img; |
|
| 378 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 379 | + return $svg; |
|
| 380 | + } |
|
| 381 | + return $img; |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
@@ -387,12 +387,12 @@ discard block |
||
| 387 | 387 | * @return array|mixed |
| 388 | 388 | */ |
| 389 | 389 | function svg_extract_couleurs($img) { |
| 390 | - if ($svg = svg_charger($img)) { |
|
| 391 | - if (preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)) { |
|
| 392 | - return $matches[0]; |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - return []; |
|
| 390 | + if ($svg = svg_charger($img)) { |
|
| 391 | + if (preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)) { |
|
| 392 | + return $matches[0]; |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + return []; |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -403,58 +403,58 @@ discard block |
||
| 403 | 403 | * @return bool|string |
| 404 | 404 | */ |
| 405 | 405 | function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') { |
| 406 | - if ( |
|
| 407 | - $svg = svg_force_viewBox_px($img) |
|
| 408 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 409 | - ) { |
|
| 410 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 411 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 412 | - |
|
| 413 | - $viewport_w = $new_width; |
|
| 414 | - $viewport_h = $new_height; |
|
| 415 | - $viewport_ox = $offset_width; |
|
| 416 | - $viewport_oy = $offset_height; |
|
| 417 | - |
|
| 418 | - // si on a un width/height qui rescale, il faut rescaler |
|
| 419 | - if ( |
|
| 420 | - isset($attributs['width']) |
|
| 421 | - and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 422 | - and isset($attributs['height']) |
|
| 423 | - and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 424 | - ) { |
|
| 425 | - $xscale = $viewBox[2] / $w; |
|
| 426 | - $viewport_w = round($viewport_w * $xscale, 2); |
|
| 427 | - $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 428 | - $yscale = $viewBox[3] / $h; |
|
| 429 | - $viewport_h = round($viewport_h * $yscale, 2); |
|
| 430 | - $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) { |
|
| 434 | - $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - // maintenant on redefinit la viewBox |
|
| 438 | - $viewBox[0] += $viewport_ox; |
|
| 439 | - $viewBox[1] += $viewport_oy; |
|
| 440 | - $viewBox[2] = $viewport_w; |
|
| 441 | - $viewBox[3] = $viewport_h; |
|
| 442 | - |
|
| 443 | - $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 444 | - $attributs['width'] = strval($new_width); |
|
| 445 | - $attributs['height'] = strval($new_height); |
|
| 446 | - |
|
| 447 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 448 | - |
|
| 449 | - // ajouter un background |
|
| 450 | - if ($background_color and $background_color !== 'transparent') { |
|
| 451 | - $svg = svg_ajouter_background($svg, $background_color); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - return $svg; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - return $img; |
|
| 406 | + if ( |
|
| 407 | + $svg = svg_force_viewBox_px($img) |
|
| 408 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 409 | + ) { |
|
| 410 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 411 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 412 | + |
|
| 413 | + $viewport_w = $new_width; |
|
| 414 | + $viewport_h = $new_height; |
|
| 415 | + $viewport_ox = $offset_width; |
|
| 416 | + $viewport_oy = $offset_height; |
|
| 417 | + |
|
| 418 | + // si on a un width/height qui rescale, il faut rescaler |
|
| 419 | + if ( |
|
| 420 | + isset($attributs['width']) |
|
| 421 | + and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 422 | + and isset($attributs['height']) |
|
| 423 | + and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 424 | + ) { |
|
| 425 | + $xscale = $viewBox[2] / $w; |
|
| 426 | + $viewport_w = round($viewport_w * $xscale, 2); |
|
| 427 | + $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 428 | + $yscale = $viewBox[3] / $h; |
|
| 429 | + $viewport_h = round($viewport_h * $yscale, 2); |
|
| 430 | + $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) { |
|
| 434 | + $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + // maintenant on redefinit la viewBox |
|
| 438 | + $viewBox[0] += $viewport_ox; |
|
| 439 | + $viewBox[1] += $viewport_oy; |
|
| 440 | + $viewBox[2] = $viewport_w; |
|
| 441 | + $viewBox[3] = $viewport_h; |
|
| 442 | + |
|
| 443 | + $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 444 | + $attributs['width'] = strval($new_width); |
|
| 445 | + $attributs['height'] = strval($new_height); |
|
| 446 | + |
|
| 447 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 448 | + |
|
| 449 | + // ajouter un background |
|
| 450 | + if ($background_color and $background_color !== 'transparent') { |
|
| 451 | + $svg = svg_ajouter_background($svg, $background_color); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + return $svg; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + return $img; |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -464,26 +464,26 @@ discard block |
||
| 464 | 464 | * @return bool|string |
| 465 | 465 | */ |
| 466 | 466 | function svg_ajouter_background($img, $background_color) { |
| 467 | - if ( |
|
| 468 | - $svg = svg_charger($img) |
|
| 469 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 470 | - ) { |
|
| 471 | - if ($background_color and $background_color !== 'transparent') { |
|
| 472 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 473 | - |
|
| 474 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 475 | - if (isset($attributs['viewBox'])) { |
|
| 476 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 477 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 478 | - } |
|
| 479 | - else { |
|
| 480 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 481 | - } |
|
| 482 | - $svg = svg_insert_shapes($svg, $rect); |
|
| 483 | - } |
|
| 484 | - return $svg; |
|
| 485 | - } |
|
| 486 | - return $img; |
|
| 467 | + if ( |
|
| 468 | + $svg = svg_charger($img) |
|
| 469 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 470 | + ) { |
|
| 471 | + if ($background_color and $background_color !== 'transparent') { |
|
| 472 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 473 | + |
|
| 474 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 475 | + if (isset($attributs['viewBox'])) { |
|
| 476 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 477 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 478 | + } |
|
| 479 | + else { |
|
| 480 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 481 | + } |
|
| 482 | + $svg = svg_insert_shapes($svg, $rect); |
|
| 483 | + } |
|
| 484 | + return $svg; |
|
| 485 | + } |
|
| 486 | + return $img; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -494,26 +494,26 @@ discard block |
||
| 494 | 494 | * @return bool|string |
| 495 | 495 | */ |
| 496 | 496 | function svg_ajouter_voile($img, $background_color, $opacity) { |
| 497 | - if ( |
|
| 498 | - $svg = svg_charger($img) |
|
| 499 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 500 | - ) { |
|
| 501 | - if ($background_color and $background_color !== 'transparent') { |
|
| 502 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 503 | - |
|
| 504 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 505 | - if (isset($attributs['viewBox'])) { |
|
| 506 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 507 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 508 | - } |
|
| 509 | - else { |
|
| 510 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 511 | - } |
|
| 512 | - $svg = svg_insert_shapes($svg, $rect, false); |
|
| 513 | - } |
|
| 514 | - return $svg; |
|
| 515 | - } |
|
| 516 | - return $img; |
|
| 497 | + if ( |
|
| 498 | + $svg = svg_charger($img) |
|
| 499 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 500 | + ) { |
|
| 501 | + if ($background_color and $background_color !== 'transparent') { |
|
| 502 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 503 | + |
|
| 504 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 505 | + if (isset($attributs['viewBox'])) { |
|
| 506 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 507 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 508 | + } |
|
| 509 | + else { |
|
| 510 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 511 | + } |
|
| 512 | + $svg = svg_insert_shapes($svg, $rect, false); |
|
| 513 | + } |
|
| 514 | + return $svg; |
|
| 515 | + } |
|
| 516 | + return $img; |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | |
@@ -524,27 +524,27 @@ discard block |
||
| 524 | 524 | * @return bool|string |
| 525 | 525 | */ |
| 526 | 526 | function svg_transformer($img, $attributs) { |
| 527 | - if ( |
|
| 528 | - $svg = svg_charger($img) |
|
| 529 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 530 | - ) { |
|
| 531 | - if ($attributs) { |
|
| 532 | - [$balise_svg, ] = $svg_infos; |
|
| 533 | - $g = '<g'; |
|
| 534 | - foreach ($attributs as $k => $v) { |
|
| 535 | - if (strlen($v)) { |
|
| 536 | - $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - if (strlen($g) > 2) { |
|
| 540 | - $g .= '>'; |
|
| 541 | - $svg = svg_insert_shapes($svg, $g); |
|
| 542 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - return $svg; |
|
| 546 | - } |
|
| 547 | - return $img; |
|
| 527 | + if ( |
|
| 528 | + $svg = svg_charger($img) |
|
| 529 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 530 | + ) { |
|
| 531 | + if ($attributs) { |
|
| 532 | + [$balise_svg, ] = $svg_infos; |
|
| 533 | + $g = '<g'; |
|
| 534 | + foreach ($attributs as $k => $v) { |
|
| 535 | + if (strlen($v)) { |
|
| 536 | + $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + if (strlen($g) > 2) { |
|
| 540 | + $g .= '>'; |
|
| 541 | + $svg = svg_insert_shapes($svg, $g); |
|
| 542 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + return $svg; |
|
| 546 | + } |
|
| 547 | + return $img; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | /** |
@@ -555,21 +555,21 @@ discard block |
||
| 555 | 555 | * @return bool|string |
| 556 | 556 | */ |
| 557 | 557 | function svg_apply_filter($img, $filter_def) { |
| 558 | - if ( |
|
| 559 | - $svg = svg_charger($img) |
|
| 560 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 561 | - ) { |
|
| 562 | - if ($filter_def) { |
|
| 563 | - [$balise_svg, ] = $svg_infos; |
|
| 564 | - $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 565 | - $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 566 | - $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 567 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 568 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 569 | - } |
|
| 570 | - return $svg; |
|
| 571 | - } |
|
| 572 | - return $img; |
|
| 558 | + if ( |
|
| 559 | + $svg = svg_charger($img) |
|
| 560 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 561 | + ) { |
|
| 562 | + if ($filter_def) { |
|
| 563 | + [$balise_svg, ] = $svg_infos; |
|
| 564 | + $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 565 | + $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 566 | + $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 567 | + $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 568 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 569 | + } |
|
| 570 | + return $svg; |
|
| 571 | + } |
|
| 572 | + return $img; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -579,8 +579,8 @@ discard block |
||
| 579 | 579 | * @return string |
| 580 | 580 | */ |
| 581 | 581 | function svg_filter_blur($img, $blur_width) { |
| 582 | - $blur_width = intval($blur_width); |
|
| 583 | - return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 582 | + $blur_width = intval($blur_width); |
|
| 583 | + return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | /** |
@@ -590,10 +590,10 @@ discard block |
||
| 590 | 590 | * @return bool|string |
| 591 | 591 | */ |
| 592 | 592 | function svg_filter_grayscale($img, $intensity) { |
| 593 | - $value = round(1.0 - $intensity, 2); |
|
| 594 | - //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 595 | - $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 596 | - return svg_apply_filter($img, $filter); |
|
| 593 | + $value = round(1.0 - $intensity, 2); |
|
| 594 | + //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 595 | + $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 596 | + return svg_apply_filter($img, $filter); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -603,8 +603,8 @@ discard block |
||
| 603 | 603 | * @return bool|string |
| 604 | 604 | */ |
| 605 | 605 | function svg_filter_sepia($img, $intensity) { |
| 606 | - $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 607 | - return svg_apply_filter($img, $filter); |
|
| 606 | + $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 607 | + return svg_apply_filter($img, $filter); |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | /** |
@@ -614,31 +614,31 @@ discard block |
||
| 614 | 614 | * @return bool|string |
| 615 | 615 | */ |
| 616 | 616 | function svg_flip($img, $HorV) { |
| 617 | - if ( |
|
| 618 | - $svg = svg_force_viewBox_px($img) |
|
| 619 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 620 | - ) { |
|
| 621 | - [$balise_svg, $atts] = $svg_infos; |
|
| 622 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 623 | - |
|
| 624 | - if (!in_array($HorV, ['h', 'H'])) { |
|
| 625 | - $transform = 'scale(-1,1)'; |
|
| 626 | - |
|
| 627 | - $x = intval($viewBox[0]) + intval($viewBox[2] / 2); |
|
| 628 | - $mx = -$x; |
|
| 629 | - $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 630 | - } |
|
| 631 | - else { |
|
| 632 | - $transform = 'scale(1,-1)'; |
|
| 633 | - |
|
| 634 | - $y = intval($viewBox[1]) + intval($viewBox[3] / 2); |
|
| 635 | - $my = -$y; |
|
| 636 | - $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 637 | - } |
|
| 638 | - $svg = svg_transformer($svg, ['transform' => $transform]); |
|
| 639 | - return $svg; |
|
| 640 | - } |
|
| 641 | - return $img; |
|
| 617 | + if ( |
|
| 618 | + $svg = svg_force_viewBox_px($img) |
|
| 619 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 620 | + ) { |
|
| 621 | + [$balise_svg, $atts] = $svg_infos; |
|
| 622 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 623 | + |
|
| 624 | + if (!in_array($HorV, ['h', 'H'])) { |
|
| 625 | + $transform = 'scale(-1,1)'; |
|
| 626 | + |
|
| 627 | + $x = intval($viewBox[0]) + intval($viewBox[2] / 2); |
|
| 628 | + $mx = -$x; |
|
| 629 | + $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 630 | + } |
|
| 631 | + else { |
|
| 632 | + $transform = 'scale(1,-1)'; |
|
| 633 | + |
|
| 634 | + $y = intval($viewBox[1]) + intval($viewBox[3] / 2); |
|
| 635 | + $my = -$y; |
|
| 636 | + $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 637 | + } |
|
| 638 | + $svg = svg_transformer($svg, ['transform' => $transform]); |
|
| 639 | + return $svg; |
|
| 640 | + } |
|
| 641 | + return $img; |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | /** |
@@ -652,20 +652,20 @@ discard block |
||
| 652 | 652 | * @return bool|string |
| 653 | 653 | */ |
| 654 | 654 | function svg_rotate($img, $angle, $center_x, $center_y) { |
| 655 | - if ( |
|
| 656 | - $svg = svg_force_viewBox_px($img) |
|
| 657 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 658 | - ) { |
|
| 659 | - [$balise_svg, $atts] = $svg_infos; |
|
| 660 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 661 | - |
|
| 662 | - $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 663 | - $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 664 | - $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 665 | - |
|
| 666 | - return $svg; |
|
| 667 | - } |
|
| 668 | - return $img; |
|
| 655 | + if ( |
|
| 656 | + $svg = svg_force_viewBox_px($img) |
|
| 657 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 658 | + ) { |
|
| 659 | + [$balise_svg, $atts] = $svg_infos; |
|
| 660 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 661 | + |
|
| 662 | + $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 663 | + $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 664 | + $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 665 | + |
|
| 666 | + return $svg; |
|
| 667 | + } |
|
| 668 | + return $img; |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -677,41 +677,41 @@ discard block |
||
| 677 | 677 | * @return bool|mixed|string |
| 678 | 678 | */ |
| 679 | 679 | function svg_filtrer_couleurs($img, $callback_filter) { |
| 680 | - if ( |
|
| 681 | - $svg = svg_force_viewBox_px($img) |
|
| 682 | - and $colors = svg_extract_couleurs($svg) |
|
| 683 | - ) { |
|
| 684 | - $colors = array_unique($colors); |
|
| 685 | - |
|
| 686 | - $short = []; |
|
| 687 | - $long = []; |
|
| 688 | - while (count($colors)) { |
|
| 689 | - $c = array_shift($colors); |
|
| 690 | - if (strlen($c) == 4) { |
|
| 691 | - $short[] = $c; |
|
| 692 | - } |
|
| 693 | - else { |
|
| 694 | - $long[] = $c; |
|
| 695 | - } |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - $colors = [...$long, ...$short]; |
|
| 699 | - $new_colors = []; |
|
| 700 | - $colors = array_flip($colors); |
|
| 701 | - foreach ($colors as $c => $k) { |
|
| 702 | - $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - foreach ($colors as $original => $replace) { |
|
| 707 | - $new = svg_couleur_to_hexa($original); |
|
| 708 | - $new_colors[$replace] = $callback_filter($new); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 712 | - $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 713 | - |
|
| 714 | - return $svg; |
|
| 715 | - } |
|
| 716 | - return $img; |
|
| 680 | + if ( |
|
| 681 | + $svg = svg_force_viewBox_px($img) |
|
| 682 | + and $colors = svg_extract_couleurs($svg) |
|
| 683 | + ) { |
|
| 684 | + $colors = array_unique($colors); |
|
| 685 | + |
|
| 686 | + $short = []; |
|
| 687 | + $long = []; |
|
| 688 | + while (count($colors)) { |
|
| 689 | + $c = array_shift($colors); |
|
| 690 | + if (strlen($c) == 4) { |
|
| 691 | + $short[] = $c; |
|
| 692 | + } |
|
| 693 | + else { |
|
| 694 | + $long[] = $c; |
|
| 695 | + } |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + $colors = [...$long, ...$short]; |
|
| 699 | + $new_colors = []; |
|
| 700 | + $colors = array_flip($colors); |
|
| 701 | + foreach ($colors as $c => $k) { |
|
| 702 | + $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + foreach ($colors as $original => $replace) { |
|
| 707 | + $new = svg_couleur_to_hexa($original); |
|
| 708 | + $new_colors[$replace] = $callback_filter($new); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 712 | + $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 713 | + |
|
| 714 | + return $svg; |
|
| 715 | + } |
|
| 716 | + return $img; |
|
| 717 | 717 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -44,18 +44,18 @@ discard block |
||
| 44 | 44 | * Pile complétée par le code à générer |
| 45 | 45 | */ |
| 46 | 46 | function balise_BOITE_OUVRIR_dist($p) { |
| 47 | - $_titre = interprete_argument_balise(1, $p); |
|
| 48 | - $_class = interprete_argument_balise(2, $p); |
|
| 49 | - $_head_class = interprete_argument_balise(3, $p); |
|
| 50 | - $_titre = ($_titre ?: "''"); |
|
| 51 | - $_class = ($_class ? ", $_class" : ", 'simple'"); |
|
| 52 | - $_head_class = ($_head_class ? ", $_head_class" : ''); |
|
| 53 | - |
|
| 54 | - $f = chercher_filtre('boite_ouvrir'); |
|
| 55 | - $p->code = "$f($_titre$_class$_head_class)"; |
|
| 56 | - $p->interdire_scripts = false; |
|
| 57 | - |
|
| 58 | - return $p; |
|
| 47 | + $_titre = interprete_argument_balise(1, $p); |
|
| 48 | + $_class = interprete_argument_balise(2, $p); |
|
| 49 | + $_head_class = interprete_argument_balise(3, $p); |
|
| 50 | + $_titre = ($_titre ?: "''"); |
|
| 51 | + $_class = ($_class ? ", $_class" : ", 'simple'"); |
|
| 52 | + $_head_class = ($_head_class ? ", $_head_class" : ''); |
|
| 53 | + |
|
| 54 | + $f = chercher_filtre('boite_ouvrir'); |
|
| 55 | + $p->code = "$f($_titre$_class$_head_class)"; |
|
| 56 | + $p->interdire_scripts = false; |
|
| 57 | + |
|
| 58 | + return $p; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -75,14 +75,14 @@ discard block |
||
| 75 | 75 | * Pile complétée par le code à générer |
| 76 | 76 | */ |
| 77 | 77 | function balise_BOITE_PIED_dist($p) { |
| 78 | - $_class = interprete_argument_balise(1, $p); |
|
| 79 | - $_class = ($_class ? "$_class" : ''); |
|
| 78 | + $_class = interprete_argument_balise(1, $p); |
|
| 79 | + $_class = ($_class ? "$_class" : ''); |
|
| 80 | 80 | |
| 81 | - $f = chercher_filtre('boite_pied'); |
|
| 82 | - $p->code = "$f($_class)"; |
|
| 83 | - $p->interdire_scripts = false; |
|
| 81 | + $f = chercher_filtre('boite_pied'); |
|
| 82 | + $p->code = "$f($_class)"; |
|
| 83 | + $p->interdire_scripts = false; |
|
| 84 | 84 | |
| 85 | - return $p; |
|
| 85 | + return $p; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | * Pile complétée par le code à générer |
| 103 | 103 | */ |
| 104 | 104 | function balise_BOITE_FERMER_dist($p) { |
| 105 | - $f = chercher_filtre('boite_fermer'); |
|
| 106 | - $p->code = "$f()"; |
|
| 107 | - $p->interdire_scripts = false; |
|
| 105 | + $f = chercher_filtre('boite_fermer'); |
|
| 106 | + $p->code = "$f()"; |
|
| 107 | + $p->interdire_scripts = false; |
|
| 108 | 108 | |
| 109 | - return $p; |
|
| 109 | + return $p; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -128,16 +128,16 @@ discard block |
||
| 128 | 128 | * HTML du début de la boîte |
| 129 | 129 | */ |
| 130 | 130 | function boite_ouvrir($titre, $class = '', $head_class = '', $id = '') { |
| 131 | - $class = "box $class"; |
|
| 132 | - $head_class = "box__header $head_class clearfix"; |
|
| 133 | - // dans l'espace prive, titrer en h3 si pas de balise <hn> |
|
| 134 | - if (test_espace_prive() and strlen($titre) and strpos($titre, '<h') === false) { |
|
| 135 | - $titre = "<h3>$titre</h3>"; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return '<div class="' . $class . ($id ? "\" id=\"$id" : '') . '">' |
|
| 139 | - . ($titre ? "<div class=\"$head_class\">$titre<!--/hd--></div>" : '') |
|
| 140 | - . '<div class="box__body clearfix">'; |
|
| 131 | + $class = "box $class"; |
|
| 132 | + $head_class = "box__header $head_class clearfix"; |
|
| 133 | + // dans l'espace prive, titrer en h3 si pas de balise <hn> |
|
| 134 | + if (test_espace_prive() and strlen($titre) and strpos($titre, '<h') === false) { |
|
| 135 | + $titre = "<h3>$titre</h3>"; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return '<div class="' . $class . ($id ? "\" id=\"$id" : '') . '">' |
|
| 139 | + . ($titre ? "<div class=\"$head_class\">$titre<!--/hd--></div>" : '') |
|
| 140 | + . '<div class="box__body clearfix">'; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | |
@@ -154,10 +154,10 @@ discard block |
||
| 154 | 154 | * HTML de transition vers le pied de la boîte |
| 155 | 155 | */ |
| 156 | 156 | function boite_pied($class = 'act') { |
| 157 | - $class = "box__footer $class"; |
|
| 157 | + $class = "box__footer $class"; |
|
| 158 | 158 | |
| 159 | - return '</div>' |
|
| 160 | - . "<div class=\"$class clearfix\">"; |
|
| 159 | + return '</div>' |
|
| 160 | + . "<div class=\"$class clearfix\">"; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
@@ -172,6 +172,6 @@ discard block |
||
| 172 | 172 | * HTML de fin de la boîte |
| 173 | 173 | */ |
| 174 | 174 | function boite_fermer() { |
| 175 | - return '</div>' |
|
| 176 | - . '</div>'; |
|
| 175 | + return '</div>' |
|
| 176 | + . '</div>'; |
|
| 177 | 177 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -25,51 +25,51 @@ discard block |
||
| 25 | 25 | * privée ou dans un de ses sous menus |
| 26 | 26 | */ |
| 27 | 27 | class Bouton { |
| 28 | - /** @var string L'icone à mettre dans le bouton */ |
|
| 29 | - public $icone; |
|
| 30 | - |
|
| 31 | - /** @var string Le nom de l'entrée d'i18n associé */ |
|
| 32 | - public $libelle; |
|
| 33 | - |
|
| 34 | - /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | - public $url = null; |
|
| 36 | - |
|
| 37 | - /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | - public $urlArg = null; |
|
| 39 | - |
|
| 40 | - /** @var null|string URL du javascript */ |
|
| 41 | - public $url2 = null; |
|
| 42 | - |
|
| 43 | - /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | - public $target = null; |
|
| 45 | - |
|
| 46 | - /** @var null|mixed Sous-barre de boutons / onglets */ |
|
| 47 | - public $sousmenu = null; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Définit un bouton |
|
| 51 | - * |
|
| 52 | - * @param string $icone |
|
| 53 | - * L'icone à mettre dans le bouton |
|
| 54 | - * @param string $libelle |
|
| 55 | - * Le nom de l'entrée i18n associé |
|
| 56 | - * @param null|string $url |
|
| 57 | - * L'URL de la page |
|
| 58 | - * @param null|string|array $urlArg |
|
| 59 | - * Arguments supplémentaires de l'URL |
|
| 60 | - * @param null|string $url2 |
|
| 61 | - * URL du javascript |
|
| 62 | - * @param null|mixed $target |
|
| 63 | - * Pour ouvrir une fenêtre à part |
|
| 64 | - */ |
|
| 65 | - public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 66 | - $this->icone = $icone; |
|
| 67 | - $this->libelle = $libelle; |
|
| 68 | - $this->url = $url; |
|
| 69 | - $this->urlArg = $urlArg; |
|
| 70 | - $this->url2 = $url2; |
|
| 71 | - $this->target = $target; |
|
| 72 | - } |
|
| 28 | + /** @var string L'icone à mettre dans le bouton */ |
|
| 29 | + public $icone; |
|
| 30 | + |
|
| 31 | + /** @var string Le nom de l'entrée d'i18n associé */ |
|
| 32 | + public $libelle; |
|
| 33 | + |
|
| 34 | + /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | + public $url = null; |
|
| 36 | + |
|
| 37 | + /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | + public $urlArg = null; |
|
| 39 | + |
|
| 40 | + /** @var null|string URL du javascript */ |
|
| 41 | + public $url2 = null; |
|
| 42 | + |
|
| 43 | + /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | + public $target = null; |
|
| 45 | + |
|
| 46 | + /** @var null|mixed Sous-barre de boutons / onglets */ |
|
| 47 | + public $sousmenu = null; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Définit un bouton |
|
| 51 | + * |
|
| 52 | + * @param string $icone |
|
| 53 | + * L'icone à mettre dans le bouton |
|
| 54 | + * @param string $libelle |
|
| 55 | + * Le nom de l'entrée i18n associé |
|
| 56 | + * @param null|string $url |
|
| 57 | + * L'URL de la page |
|
| 58 | + * @param null|string|array $urlArg |
|
| 59 | + * Arguments supplémentaires de l'URL |
|
| 60 | + * @param null|string $url2 |
|
| 61 | + * URL du javascript |
|
| 62 | + * @param null|mixed $target |
|
| 63 | + * Pour ouvrir une fenêtre à part |
|
| 64 | + */ |
|
| 65 | + public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 66 | + $this->icone = $icone; |
|
| 67 | + $this->libelle = $libelle; |
|
| 68 | + $this->url = $url; |
|
| 69 | + $this->urlArg = $urlArg; |
|
| 70 | + $this->url2 = $url2; |
|
| 71 | + $this->target = $target; |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -86,35 +86,35 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | function definir_barre_onglets($script) { |
| 88 | 88 | |
| 89 | - $onglets = []; |
|
| 90 | - $liste_onglets = []; |
|
| 91 | - |
|
| 92 | - // ajouter les onglets issus des plugin via paquet.xml |
|
| 93 | - if (function_exists('onglets_plugins')) { |
|
| 94 | - $liste_onglets = onglets_plugins(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - foreach ($liste_onglets as $id => $infos) { |
|
| 99 | - if ( |
|
| 100 | - ($parent = $infos['parent']) |
|
| 101 | - && $parent == $script |
|
| 102 | - && autoriser('onglet', "_$id") |
|
| 103 | - ) { |
|
| 104 | - $onglets[$id] = new Bouton( |
|
| 105 | - isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | - $infos['titre'], // titre |
|
| 107 | - (isset($infos['action']) and $infos['action']) |
|
| 108 | - ? generer_url_ecrire( |
|
| 109 | - $infos['action'], |
|
| 110 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 111 | - ) |
|
| 112 | - : null |
|
| 113 | - ); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 89 | + $onglets = []; |
|
| 90 | + $liste_onglets = []; |
|
| 91 | + |
|
| 92 | + // ajouter les onglets issus des plugin via paquet.xml |
|
| 93 | + if (function_exists('onglets_plugins')) { |
|
| 94 | + $liste_onglets = onglets_plugins(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + foreach ($liste_onglets as $id => $infos) { |
|
| 99 | + if ( |
|
| 100 | + ($parent = $infos['parent']) |
|
| 101 | + && $parent == $script |
|
| 102 | + && autoriser('onglet', "_$id") |
|
| 103 | + ) { |
|
| 104 | + $onglets[$id] = new Bouton( |
|
| 105 | + isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | + $infos['titre'], // titre |
|
| 107 | + (isset($infos['action']) and $infos['action']) |
|
| 108 | + ? generer_url_ecrire( |
|
| 109 | + $infos['action'], |
|
| 110 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 111 | + ) |
|
| 112 | + : null |
|
| 113 | + ); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -133,14 +133,14 @@ discard block |
||
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | 135 | function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') { |
| 136 | - include_spip('inc/presentation'); |
|
| 136 | + include_spip('inc/presentation'); |
|
| 137 | 137 | |
| 138 | - $res = ''; |
|
| 138 | + $res = ''; |
|
| 139 | 139 | |
| 140 | - foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 141 | - $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 142 | - $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 143 | - } |
|
| 140 | + foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 141 | + $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 142 | + $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 145 | + return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 146 | 146 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | // securité |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | // se faciliter la lecture du charset |
@@ -42,45 +42,45 @@ discard block |
||
| 42 | 42 | * - false si le charset n'est pas décrit dans le répertoire charsets/ |
| 43 | 43 | **/ |
| 44 | 44 | function load_charset($charset = 'AUTO') { |
| 45 | - if ($charset == 'AUTO') { |
|
| 46 | - $charset = $GLOBALS['meta']['charset']; |
|
| 47 | - } |
|
| 48 | - $charset = trim(strtolower($charset)); |
|
| 49 | - if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 50 | - return $charset; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if ($charset == 'utf-8') { |
|
| 54 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 55 | - |
|
| 56 | - return $charset; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // Quelques synonymes |
|
| 60 | - if ($charset == '') { |
|
| 61 | - $charset = 'iso-8859-1'; |
|
| 62 | - } else { |
|
| 63 | - if ($charset == 'windows-1250') { |
|
| 64 | - $charset = 'cp1250'; |
|
| 65 | - } else { |
|
| 66 | - if ($charset == 'windows-1251') { |
|
| 67 | - $charset = 'cp1251'; |
|
| 68 | - } else { |
|
| 69 | - if ($charset == 'windows-1256') { |
|
| 70 | - $charset = 'cp1256'; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 77 | - return $charset; |
|
| 78 | - } else { |
|
| 79 | - spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 80 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 81 | - |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 45 | + if ($charset == 'AUTO') { |
|
| 46 | + $charset = $GLOBALS['meta']['charset']; |
|
| 47 | + } |
|
| 48 | + $charset = trim(strtolower($charset)); |
|
| 49 | + if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 50 | + return $charset; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if ($charset == 'utf-8') { |
|
| 54 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 55 | + |
|
| 56 | + return $charset; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // Quelques synonymes |
|
| 60 | + if ($charset == '') { |
|
| 61 | + $charset = 'iso-8859-1'; |
|
| 62 | + } else { |
|
| 63 | + if ($charset == 'windows-1250') { |
|
| 64 | + $charset = 'cp1250'; |
|
| 65 | + } else { |
|
| 66 | + if ($charset == 'windows-1251') { |
|
| 67 | + $charset = 'cp1251'; |
|
| 68 | + } else { |
|
| 69 | + if ($charset == 'windows-1256') { |
|
| 70 | + $charset = 'cp1256'; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 77 | + return $charset; |
|
| 78 | + } else { |
|
| 79 | + spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 80 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 81 | + |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -91,31 +91,31 @@ discard block |
||
| 91 | 91 | * true si toutes les fonctions mb nécessaires sont présentes |
| 92 | 92 | **/ |
| 93 | 93 | function init_mb_string() { |
| 94 | - static $mb; |
|
| 95 | - |
|
| 96 | - // verifier que tout est present (fonctions mb_string pour php >= 4.0.6) |
|
| 97 | - // et que le charset interne est connu de mb_string |
|
| 98 | - if (!$mb) { |
|
| 99 | - if ( |
|
| 100 | - function_exists('mb_internal_encoding') |
|
| 101 | - and function_exists('mb_detect_order') |
|
| 102 | - and function_exists('mb_substr') |
|
| 103 | - and function_exists('mb_strlen') |
|
| 104 | - and function_exists('mb_strtolower') |
|
| 105 | - and function_exists('mb_strtoupper') |
|
| 106 | - and function_exists('mb_encode_mimeheader') |
|
| 107 | - and function_exists('mb_encode_numericentity') |
|
| 108 | - and function_exists('mb_decode_numericentity') |
|
| 109 | - and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET)) |
|
| 110 | - ) { |
|
| 111 | - mb_internal_encoding('utf-8'); |
|
| 112 | - $mb = 1; |
|
| 113 | - } else { |
|
| 114 | - $mb = -1; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return ($mb == 1); |
|
| 94 | + static $mb; |
|
| 95 | + |
|
| 96 | + // verifier que tout est present (fonctions mb_string pour php >= 4.0.6) |
|
| 97 | + // et que le charset interne est connu de mb_string |
|
| 98 | + if (!$mb) { |
|
| 99 | + if ( |
|
| 100 | + function_exists('mb_internal_encoding') |
|
| 101 | + and function_exists('mb_detect_order') |
|
| 102 | + and function_exists('mb_substr') |
|
| 103 | + and function_exists('mb_strlen') |
|
| 104 | + and function_exists('mb_strtolower') |
|
| 105 | + and function_exists('mb_strtoupper') |
|
| 106 | + and function_exists('mb_encode_mimeheader') |
|
| 107 | + and function_exists('mb_encode_numericentity') |
|
| 108 | + and function_exists('mb_decode_numericentity') |
|
| 109 | + and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET)) |
|
| 110 | + ) { |
|
| 111 | + mb_internal_encoding('utf-8'); |
|
| 112 | + $mb = 1; |
|
| 113 | + } else { |
|
| 114 | + $mb = -1; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return ($mb == 1); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -130,21 +130,21 @@ discard block |
||
| 130 | 130 | * true si iconv fonctionne correctement |
| 131 | 131 | **/ |
| 132 | 132 | function test_iconv() { |
| 133 | - static $iconv_ok; |
|
| 134 | - |
|
| 135 | - if (!$iconv_ok) { |
|
| 136 | - if (!function_exists('iconv')) { |
|
| 137 | - $iconv_ok = -1; |
|
| 138 | - } else { |
|
| 139 | - if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') { |
|
| 140 | - $iconv_ok = 1; |
|
| 141 | - } else { |
|
| 142 | - $iconv_ok = -1; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return ($iconv_ok == 1); |
|
| 133 | + static $iconv_ok; |
|
| 134 | + |
|
| 135 | + if (!$iconv_ok) { |
|
| 136 | + if (!function_exists('iconv')) { |
|
| 137 | + $iconv_ok = -1; |
|
| 138 | + } else { |
|
| 139 | + if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') { |
|
| 140 | + $iconv_ok = 1; |
|
| 141 | + } else { |
|
| 142 | + $iconv_ok = -1; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return ($iconv_ok == 1); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
@@ -157,18 +157,18 @@ discard block |
||
| 157 | 157 | * true si PCRE supporte l'UTF-8 correctement |
| 158 | 158 | **/ |
| 159 | 159 | function test_pcre_unicode() { |
| 160 | - static $pcre_ok = 0; |
|
| 161 | - |
|
| 162 | - if (!$pcre_ok) { |
|
| 163 | - $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' '; |
|
| 164 | - if (preg_match(',\W...\W,u', $s)) { |
|
| 165 | - $pcre_ok = 1; |
|
| 166 | - } else { |
|
| 167 | - $pcre_ok = -1; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - return $pcre_ok == 1; |
|
| 160 | + static $pcre_ok = 0; |
|
| 161 | + |
|
| 162 | + if (!$pcre_ok) { |
|
| 163 | + $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' '; |
|
| 164 | + if (preg_match(',\W...\W,u', $s)) { |
|
| 165 | + $pcre_ok = 1; |
|
| 166 | + } else { |
|
| 167 | + $pcre_ok = -1; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + return $pcre_ok == 1; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -184,22 +184,22 @@ discard block |
||
| 184 | 184 | * Plage de caractères |
| 185 | 185 | **/ |
| 186 | 186 | function pcre_lettres_unicode() { |
| 187 | - static $plage_unicode; |
|
| 188 | - |
|
| 189 | - if (!$plage_unicode) { |
|
| 190 | - if (test_pcre_unicode()) { |
|
| 191 | - // cf. http://www.unicode.org/charts/ |
|
| 192 | - $plage_unicode = '\w' // iso-latin |
|
| 193 | - . '\x{100}-\x{24f}' // europeen etendu |
|
| 194 | - . '\x{300}-\x{1cff}' // des tas de trucs |
|
| 195 | - ; |
|
| 196 | - } else { |
|
| 197 | - // fallback a trois sous |
|
| 198 | - $plage_unicode = '\w'; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $plage_unicode; |
|
| 187 | + static $plage_unicode; |
|
| 188 | + |
|
| 189 | + if (!$plage_unicode) { |
|
| 190 | + if (test_pcre_unicode()) { |
|
| 191 | + // cf. http://www.unicode.org/charts/ |
|
| 192 | + $plage_unicode = '\w' // iso-latin |
|
| 193 | + . '\x{100}-\x{24f}' // europeen etendu |
|
| 194 | + . '\x{300}-\x{1cff}' // des tas de trucs |
|
| 195 | + ; |
|
| 196 | + } else { |
|
| 197 | + // fallback a trois sous |
|
| 198 | + $plage_unicode = '\w'; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $plage_unicode; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * Plage de caractères |
| 218 | 218 | **/ |
| 219 | 219 | function plage_punct_unicode() { |
| 220 | - return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])'; |
|
| 220 | + return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])'; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -237,75 +237,75 @@ discard block |
||
| 237 | 237 | * Texte corrigé |
| 238 | 238 | **/ |
| 239 | 239 | function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') { |
| 240 | - static $trans; |
|
| 241 | - |
|
| 242 | - if (is_array($texte)) { |
|
| 243 | - return array_map('corriger_caracteres_windows', $texte); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - if ($charset == 'AUTO') { |
|
| 247 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 248 | - } |
|
| 249 | - if ($charset == 'utf-8') { |
|
| 250 | - $p = chr(194); |
|
| 251 | - if (strpos($texte, $p) == false) { |
|
| 252 | - return $texte; |
|
| 253 | - } |
|
| 254 | - } else { |
|
| 255 | - if ($charset == 'iso-8859-1') { |
|
| 256 | - $p = ''; |
|
| 257 | - } else { |
|
| 258 | - return $texte; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - if (!isset($trans[$charset][$charset_cible])) { |
|
| 263 | - $trans[$charset][$charset_cible] = [ |
|
| 264 | - $p . chr(128) => '€', |
|
| 265 | - $p . chr(129) => ' ', # pas affecte |
|
| 266 | - $p . chr(130) => '‚', |
|
| 267 | - $p . chr(131) => 'ƒ', |
|
| 268 | - $p . chr(132) => '„', |
|
| 269 | - $p . chr(133) => '…', |
|
| 270 | - $p . chr(134) => '†', |
|
| 271 | - $p . chr(135) => '‡', |
|
| 272 | - $p . chr(136) => 'ˆ', |
|
| 273 | - $p . chr(137) => '‰', |
|
| 274 | - $p . chr(138) => 'Š', |
|
| 275 | - $p . chr(139) => '‹', |
|
| 276 | - $p . chr(140) => 'Œ', |
|
| 277 | - $p . chr(141) => ' ', # pas affecte |
|
| 278 | - $p . chr(142) => 'Ž', |
|
| 279 | - $p . chr(143) => ' ', # pas affecte |
|
| 280 | - $p . chr(144) => ' ', # pas affecte |
|
| 281 | - $p . chr(145) => '‘', |
|
| 282 | - $p . chr(146) => '’', |
|
| 283 | - $p . chr(147) => '“', |
|
| 284 | - $p . chr(148) => '”', |
|
| 285 | - $p . chr(149) => '•', |
|
| 286 | - $p . chr(150) => '–', |
|
| 287 | - $p . chr(151) => '—', |
|
| 288 | - $p . chr(152) => '˜', |
|
| 289 | - $p . chr(153) => '™', |
|
| 290 | - $p . chr(154) => 'š', |
|
| 291 | - $p . chr(155) => '›', |
|
| 292 | - $p . chr(156) => 'œ', |
|
| 293 | - $p . chr(157) => ' ', # pas affecte |
|
| 294 | - $p . chr(158) => 'ž', |
|
| 295 | - $p . chr(159) => 'Ÿ', |
|
| 296 | - ]; |
|
| 297 | - if ($charset_cible != 'unicode') { |
|
| 298 | - foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 299 | - $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return @str_replace( |
|
| 305 | - array_keys($trans[$charset][$charset_cible]), |
|
| 306 | - array_values($trans[$charset][$charset_cible]), |
|
| 307 | - $texte |
|
| 308 | - ); |
|
| 240 | + static $trans; |
|
| 241 | + |
|
| 242 | + if (is_array($texte)) { |
|
| 243 | + return array_map('corriger_caracteres_windows', $texte); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + if ($charset == 'AUTO') { |
|
| 247 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 248 | + } |
|
| 249 | + if ($charset == 'utf-8') { |
|
| 250 | + $p = chr(194); |
|
| 251 | + if (strpos($texte, $p) == false) { |
|
| 252 | + return $texte; |
|
| 253 | + } |
|
| 254 | + } else { |
|
| 255 | + if ($charset == 'iso-8859-1') { |
|
| 256 | + $p = ''; |
|
| 257 | + } else { |
|
| 258 | + return $texte; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + if (!isset($trans[$charset][$charset_cible])) { |
|
| 263 | + $trans[$charset][$charset_cible] = [ |
|
| 264 | + $p . chr(128) => '€', |
|
| 265 | + $p . chr(129) => ' ', # pas affecte |
|
| 266 | + $p . chr(130) => '‚', |
|
| 267 | + $p . chr(131) => 'ƒ', |
|
| 268 | + $p . chr(132) => '„', |
|
| 269 | + $p . chr(133) => '…', |
|
| 270 | + $p . chr(134) => '†', |
|
| 271 | + $p . chr(135) => '‡', |
|
| 272 | + $p . chr(136) => 'ˆ', |
|
| 273 | + $p . chr(137) => '‰', |
|
| 274 | + $p . chr(138) => 'Š', |
|
| 275 | + $p . chr(139) => '‹', |
|
| 276 | + $p . chr(140) => 'Œ', |
|
| 277 | + $p . chr(141) => ' ', # pas affecte |
|
| 278 | + $p . chr(142) => 'Ž', |
|
| 279 | + $p . chr(143) => ' ', # pas affecte |
|
| 280 | + $p . chr(144) => ' ', # pas affecte |
|
| 281 | + $p . chr(145) => '‘', |
|
| 282 | + $p . chr(146) => '’', |
|
| 283 | + $p . chr(147) => '“', |
|
| 284 | + $p . chr(148) => '”', |
|
| 285 | + $p . chr(149) => '•', |
|
| 286 | + $p . chr(150) => '–', |
|
| 287 | + $p . chr(151) => '—', |
|
| 288 | + $p . chr(152) => '˜', |
|
| 289 | + $p . chr(153) => '™', |
|
| 290 | + $p . chr(154) => 'š', |
|
| 291 | + $p . chr(155) => '›', |
|
| 292 | + $p . chr(156) => 'œ', |
|
| 293 | + $p . chr(157) => ' ', # pas affecte |
|
| 294 | + $p . chr(158) => 'ž', |
|
| 295 | + $p . chr(159) => 'Ÿ', |
|
| 296 | + ]; |
|
| 297 | + if ($charset_cible != 'unicode') { |
|
| 298 | + foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 299 | + $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return @str_replace( |
|
| 305 | + array_keys($trans[$charset][$charset_cible]), |
|
| 306 | + array_values($trans[$charset][$charset_cible]), |
|
| 307 | + $texte |
|
| 308 | + ); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | |
@@ -322,26 +322,26 @@ discard block |
||
| 322 | 322 | * Texte converti |
| 323 | 323 | **/ |
| 324 | 324 | function html2unicode($texte, $secure = false) { |
| 325 | - if (strpos($texte, '&') === false) { |
|
| 326 | - return $texte; |
|
| 327 | - } |
|
| 328 | - static $trans = []; |
|
| 329 | - if (!$trans) { |
|
| 330 | - load_charset('html'); |
|
| 331 | - foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 332 | - $trans["&$key;"] = $val; |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - if ($secure) { |
|
| 337 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 338 | - } else { |
|
| 339 | - return str_replace( |
|
| 340 | - ['&', '"', '<', '>'], |
|
| 341 | - ['&', '"', '<', '>'], |
|
| 342 | - str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 343 | - ); |
|
| 344 | - } |
|
| 325 | + if (strpos($texte, '&') === false) { |
|
| 326 | + return $texte; |
|
| 327 | + } |
|
| 328 | + static $trans = []; |
|
| 329 | + if (!$trans) { |
|
| 330 | + load_charset('html'); |
|
| 331 | + foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 332 | + $trans["&$key;"] = $val; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + if ($secure) { |
|
| 337 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 338 | + } else { |
|
| 339 | + return str_replace( |
|
| 340 | + ['&', '"', '<', '>'], |
|
| 341 | + ['&', '"', '<', '>'], |
|
| 342 | + str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 343 | + ); |
|
| 344 | + } |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | |
@@ -356,16 +356,16 @@ discard block |
||
| 356 | 356 | * Texte converti |
| 357 | 357 | **/ |
| 358 | 358 | function mathml2unicode($texte) { |
| 359 | - static $trans; |
|
| 360 | - if (!$trans) { |
|
| 361 | - load_charset('mathml'); |
|
| 359 | + static $trans; |
|
| 360 | + if (!$trans) { |
|
| 361 | + load_charset('mathml'); |
|
| 362 | 362 | |
| 363 | - foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 364 | - $trans["&$key;"] = $val; |
|
| 365 | - } |
|
| 366 | - } |
|
| 363 | + foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 364 | + $trans["&$key;"] = $val; |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 368 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | |
@@ -387,75 +387,75 @@ discard block |
||
| 387 | 387 | * Texte converti en unicode |
| 388 | 388 | **/ |
| 389 | 389 | function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) { |
| 390 | - static $trans; |
|
| 391 | - |
|
| 392 | - if ($charset == 'AUTO') { |
|
| 393 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - if ($charset == '') { |
|
| 397 | - $charset = 'iso-8859-1'; |
|
| 398 | - } |
|
| 399 | - $charset = strtolower($charset); |
|
| 400 | - |
|
| 401 | - switch ($charset) { |
|
| 402 | - case 'utf-8': |
|
| 403 | - case 'utf8': |
|
| 404 | - return utf_8_to_unicode($texte); |
|
| 405 | - |
|
| 406 | - case 'iso-8859-1': |
|
| 407 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 408 | - // pas de break; ici, on suit sur default: |
|
| 409 | - |
|
| 410 | - default: |
|
| 411 | - // mbstring presente ? |
|
| 412 | - if (init_mb_string()) { |
|
| 413 | - $order = mb_detect_order(); |
|
| 414 | - try { |
|
| 415 | - # mb_string connait-il $charset? |
|
| 416 | - if ($order and mb_detect_order($charset)) { |
|
| 417 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 418 | - if ($s && $s != $texte) { |
|
| 419 | - return utf_8_to_unicode($s); |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - } catch (\Error $e) { |
|
| 423 | - // Le charset n'existe probablement pas |
|
| 424 | - } finally { |
|
| 425 | - mb_detect_order($order); # remettre comme precedemment |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 430 | - if (!isset($trans[$charset])) { |
|
| 431 | - if ( |
|
| 432 | - $cset = load_charset($charset) |
|
| 433 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 434 | - ) { |
|
| 435 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 436 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 441 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 445 | - // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 446 | - // surtout en utf-8, gere ci-dessus) |
|
| 447 | - if (test_iconv()) { |
|
| 448 | - $s = iconv($charset, 'utf-32le', $texte); |
|
| 449 | - if ($s) { |
|
| 450 | - return utf_32_to_unicode($s); |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // Au pire ne rien faire |
|
| 455 | - spip_log("erreur charset '$charset' non supporte"); |
|
| 456 | - |
|
| 457 | - return $texte; |
|
| 458 | - } |
|
| 390 | + static $trans; |
|
| 391 | + |
|
| 392 | + if ($charset == 'AUTO') { |
|
| 393 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + if ($charset == '') { |
|
| 397 | + $charset = 'iso-8859-1'; |
|
| 398 | + } |
|
| 399 | + $charset = strtolower($charset); |
|
| 400 | + |
|
| 401 | + switch ($charset) { |
|
| 402 | + case 'utf-8': |
|
| 403 | + case 'utf8': |
|
| 404 | + return utf_8_to_unicode($texte); |
|
| 405 | + |
|
| 406 | + case 'iso-8859-1': |
|
| 407 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 408 | + // pas de break; ici, on suit sur default: |
|
| 409 | + |
|
| 410 | + default: |
|
| 411 | + // mbstring presente ? |
|
| 412 | + if (init_mb_string()) { |
|
| 413 | + $order = mb_detect_order(); |
|
| 414 | + try { |
|
| 415 | + # mb_string connait-il $charset? |
|
| 416 | + if ($order and mb_detect_order($charset)) { |
|
| 417 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 418 | + if ($s && $s != $texte) { |
|
| 419 | + return utf_8_to_unicode($s); |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + } catch (\Error $e) { |
|
| 423 | + // Le charset n'existe probablement pas |
|
| 424 | + } finally { |
|
| 425 | + mb_detect_order($order); # remettre comme precedemment |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 430 | + if (!isset($trans[$charset])) { |
|
| 431 | + if ( |
|
| 432 | + $cset = load_charset($charset) |
|
| 433 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 434 | + ) { |
|
| 435 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 436 | + $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 441 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 445 | + // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 446 | + // surtout en utf-8, gere ci-dessus) |
|
| 447 | + if (test_iconv()) { |
|
| 448 | + $s = iconv($charset, 'utf-32le', $texte); |
|
| 449 | + if ($s) { |
|
| 450 | + return utf_32_to_unicode($s); |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // Au pire ne rien faire |
|
| 455 | + spip_log("erreur charset '$charset' non supporte"); |
|
| 456 | + |
|
| 457 | + return $texte; |
|
| 458 | + } |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | |
@@ -474,44 +474,44 @@ discard block |
||
| 474 | 474 | * Texte transformé dans le charset souhaité |
| 475 | 475 | **/ |
| 476 | 476 | function unicode2charset($texte, $charset = 'AUTO') { |
| 477 | - static $CHARSET_REVERSE = []; |
|
| 478 | - static $trans = []; |
|
| 479 | - |
|
| 480 | - if ($charset == 'AUTO') { |
|
| 481 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - switch ($charset) { |
|
| 485 | - case 'utf-8': |
|
| 486 | - return unicode_to_utf_8($texte); |
|
| 487 | - break; |
|
| 488 | - |
|
| 489 | - default: |
|
| 490 | - $charset = load_charset($charset); |
|
| 491 | - |
|
| 492 | - if (empty($CHARSET_REVERSE[$charset])) { |
|
| 493 | - $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - if (!isset($trans[$charset])) { |
|
| 497 | - $trans[$charset] = []; |
|
| 498 | - $t = &$trans[$charset]; |
|
| 499 | - for ($e = 128; $e < 255; $e++) { |
|
| 500 | - $h = dechex($e); |
|
| 501 | - if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 502 | - $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 503 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 504 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 505 | - } else { |
|
| 506 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 507 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 512 | - |
|
| 513 | - return $texte; |
|
| 514 | - } |
|
| 477 | + static $CHARSET_REVERSE = []; |
|
| 478 | + static $trans = []; |
|
| 479 | + |
|
| 480 | + if ($charset == 'AUTO') { |
|
| 481 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + switch ($charset) { |
|
| 485 | + case 'utf-8': |
|
| 486 | + return unicode_to_utf_8($texte); |
|
| 487 | + break; |
|
| 488 | + |
|
| 489 | + default: |
|
| 490 | + $charset = load_charset($charset); |
|
| 491 | + |
|
| 492 | + if (empty($CHARSET_REVERSE[$charset])) { |
|
| 493 | + $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + if (!isset($trans[$charset])) { |
|
| 497 | + $trans[$charset] = []; |
|
| 498 | + $t = &$trans[$charset]; |
|
| 499 | + for ($e = 128; $e < 255; $e++) { |
|
| 500 | + $h = dechex($e); |
|
| 501 | + if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 502 | + $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 503 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 504 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 505 | + } else { |
|
| 506 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 507 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 512 | + |
|
| 513 | + return $texte; |
|
| 514 | + } |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | |
@@ -529,40 +529,40 @@ discard block |
||
| 529 | 529 | * Texte transformé dans le charset site |
| 530 | 530 | **/ |
| 531 | 531 | function importer_charset($texte, $charset = 'AUTO') { |
| 532 | - $s = null; |
|
| 533 | - static $trans = []; |
|
| 534 | - // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 535 | - if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 536 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 537 | - if (init_mb_string()) { |
|
| 538 | - if ( |
|
| 539 | - $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 540 | - and mb_detect_order($charset) |
|
| 541 | - ) { |
|
| 542 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 543 | - } |
|
| 544 | - mb_detect_order($order); # remettre comme precedemment |
|
| 545 | - return $s; |
|
| 546 | - } |
|
| 547 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 548 | - if (!isset($trans[$charset])) { |
|
| 549 | - if ( |
|
| 550 | - $cset = load_charset($charset) |
|
| 551 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 552 | - ) { |
|
| 553 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 554 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - } |
|
| 558 | - if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 559 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return $texte; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - return unicode2charset(charset2unicode($texte, $charset)); |
|
| 532 | + $s = null; |
|
| 533 | + static $trans = []; |
|
| 534 | + // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 535 | + if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 536 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 537 | + if (init_mb_string()) { |
|
| 538 | + if ( |
|
| 539 | + $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 540 | + and mb_detect_order($charset) |
|
| 541 | + ) { |
|
| 542 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 543 | + } |
|
| 544 | + mb_detect_order($order); # remettre comme precedemment |
|
| 545 | + return $s; |
|
| 546 | + } |
|
| 547 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 548 | + if (!isset($trans[$charset])) { |
|
| 549 | + if ( |
|
| 550 | + $cset = load_charset($charset) |
|
| 551 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 552 | + ) { |
|
| 553 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 554 | + $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + } |
|
| 558 | + if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 559 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return $texte; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + return unicode2charset(charset2unicode($texte, $charset)); |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | |
@@ -578,92 +578,92 @@ discard block |
||
| 578 | 578 | **/ |
| 579 | 579 | function utf_8_to_unicode($source) { |
| 580 | 580 | |
| 581 | - // mb_string : methode rapide |
|
| 582 | - if (init_mb_string()) { |
|
| 583 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 584 | - |
|
| 585 | - return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - // Sinon methode pas a pas |
|
| 589 | - static $decrement; |
|
| 590 | - static $shift; |
|
| 591 | - |
|
| 592 | - // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 593 | - if (!is_array($decrement)) { |
|
| 594 | - // array used to figure what number to decrement from character order value |
|
| 595 | - // according to number of characters used to map unicode to ascii by utf-8 |
|
| 596 | - $decrement[4] = 240; |
|
| 597 | - $decrement[3] = 224; |
|
| 598 | - $decrement[2] = 192; |
|
| 599 | - $decrement[1] = 0; |
|
| 600 | - // the number of bits to shift each charNum by |
|
| 601 | - $shift[1][0] = 0; |
|
| 602 | - $shift[2][0] = 6; |
|
| 603 | - $shift[2][1] = 0; |
|
| 604 | - $shift[3][0] = 12; |
|
| 605 | - $shift[3][1] = 6; |
|
| 606 | - $shift[3][2] = 0; |
|
| 607 | - $shift[4][0] = 18; |
|
| 608 | - $shift[4][1] = 12; |
|
| 609 | - $shift[4][2] = 6; |
|
| 610 | - $shift[4][3] = 0; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - $pos = 0; |
|
| 614 | - $len = strlen($source); |
|
| 615 | - $encodedString = ''; |
|
| 616 | - while ($pos < $len) { |
|
| 617 | - $char = ''; |
|
| 618 | - $ischar = false; |
|
| 619 | - $asciiPos = ord(substr($source, $pos, 1)); |
|
| 620 | - if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 621 | - // 4 chars representing one unicode character |
|
| 622 | - $thisLetter = substr($source, $pos, 4); |
|
| 623 | - $pos += 4; |
|
| 624 | - } else { |
|
| 625 | - if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 626 | - // 3 chars representing one unicode character |
|
| 627 | - $thisLetter = substr($source, $pos, 3); |
|
| 628 | - $pos += 3; |
|
| 629 | - } else { |
|
| 630 | - if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 631 | - // 2 chars representing one unicode character |
|
| 632 | - $thisLetter = substr($source, $pos, 2); |
|
| 633 | - $pos += 2; |
|
| 634 | - } else { |
|
| 635 | - // 1 char (lower ascii) |
|
| 636 | - $thisLetter = substr($source, $pos, 1); |
|
| 637 | - $pos += 1; |
|
| 638 | - $char = $thisLetter; |
|
| 639 | - $ischar = true; |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - if ($ischar) { |
|
| 645 | - $encodedString .= $char; |
|
| 646 | - } else { // process the string representing the letter to a unicode entity |
|
| 647 | - $thisLen = strlen($thisLetter); |
|
| 648 | - $thisPos = 0; |
|
| 649 | - $decimalCode = 0; |
|
| 650 | - while ($thisPos < $thisLen) { |
|
| 651 | - $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 652 | - if ($thisPos == 0) { |
|
| 653 | - $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 654 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 655 | - } else { |
|
| 656 | - $charNum = intval($thisCharOrd - 128); |
|
| 657 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 658 | - } |
|
| 659 | - $thisPos++; |
|
| 660 | - } |
|
| 661 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 662 | - $encodedString .= $encodedLetter; |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - return $encodedString; |
|
| 581 | + // mb_string : methode rapide |
|
| 582 | + if (init_mb_string()) { |
|
| 583 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 584 | + |
|
| 585 | + return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + // Sinon methode pas a pas |
|
| 589 | + static $decrement; |
|
| 590 | + static $shift; |
|
| 591 | + |
|
| 592 | + // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 593 | + if (!is_array($decrement)) { |
|
| 594 | + // array used to figure what number to decrement from character order value |
|
| 595 | + // according to number of characters used to map unicode to ascii by utf-8 |
|
| 596 | + $decrement[4] = 240; |
|
| 597 | + $decrement[3] = 224; |
|
| 598 | + $decrement[2] = 192; |
|
| 599 | + $decrement[1] = 0; |
|
| 600 | + // the number of bits to shift each charNum by |
|
| 601 | + $shift[1][0] = 0; |
|
| 602 | + $shift[2][0] = 6; |
|
| 603 | + $shift[2][1] = 0; |
|
| 604 | + $shift[3][0] = 12; |
|
| 605 | + $shift[3][1] = 6; |
|
| 606 | + $shift[3][2] = 0; |
|
| 607 | + $shift[4][0] = 18; |
|
| 608 | + $shift[4][1] = 12; |
|
| 609 | + $shift[4][2] = 6; |
|
| 610 | + $shift[4][3] = 0; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + $pos = 0; |
|
| 614 | + $len = strlen($source); |
|
| 615 | + $encodedString = ''; |
|
| 616 | + while ($pos < $len) { |
|
| 617 | + $char = ''; |
|
| 618 | + $ischar = false; |
|
| 619 | + $asciiPos = ord(substr($source, $pos, 1)); |
|
| 620 | + if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 621 | + // 4 chars representing one unicode character |
|
| 622 | + $thisLetter = substr($source, $pos, 4); |
|
| 623 | + $pos += 4; |
|
| 624 | + } else { |
|
| 625 | + if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 626 | + // 3 chars representing one unicode character |
|
| 627 | + $thisLetter = substr($source, $pos, 3); |
|
| 628 | + $pos += 3; |
|
| 629 | + } else { |
|
| 630 | + if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 631 | + // 2 chars representing one unicode character |
|
| 632 | + $thisLetter = substr($source, $pos, 2); |
|
| 633 | + $pos += 2; |
|
| 634 | + } else { |
|
| 635 | + // 1 char (lower ascii) |
|
| 636 | + $thisLetter = substr($source, $pos, 1); |
|
| 637 | + $pos += 1; |
|
| 638 | + $char = $thisLetter; |
|
| 639 | + $ischar = true; |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + if ($ischar) { |
|
| 645 | + $encodedString .= $char; |
|
| 646 | + } else { // process the string representing the letter to a unicode entity |
|
| 647 | + $thisLen = strlen($thisLetter); |
|
| 648 | + $thisPos = 0; |
|
| 649 | + $decimalCode = 0; |
|
| 650 | + while ($thisPos < $thisLen) { |
|
| 651 | + $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 652 | + if ($thisPos == 0) { |
|
| 653 | + $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 654 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 655 | + } else { |
|
| 656 | + $charNum = intval($thisCharOrd - 128); |
|
| 657 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 658 | + } |
|
| 659 | + $thisPos++; |
|
| 660 | + } |
|
| 661 | + $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 662 | + $encodedString .= $encodedLetter; |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + return $encodedString; |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | /** |
@@ -682,32 +682,32 @@ discard block |
||
| 682 | 682 | **/ |
| 683 | 683 | function utf_32_to_unicode($source) { |
| 684 | 684 | |
| 685 | - // mb_string : methode rapide |
|
| 686 | - if (init_mb_string()) { |
|
| 687 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 688 | - $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 689 | - |
|
| 690 | - return str_replace(chr(0), '', $source); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - // Sinon methode lente |
|
| 694 | - $texte = ''; |
|
| 695 | - while ($source) { |
|
| 696 | - $words = unpack('V*', substr($source, 0, 1024)); |
|
| 697 | - $source = substr($source, 1024); |
|
| 698 | - foreach ($words as $word) { |
|
| 699 | - if ($word < 128) { |
|
| 700 | - $texte .= chr($word); |
|
| 701 | - } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 702 | - else { |
|
| 703 | - if ($word != 65279) { |
|
| 704 | - $texte .= '&#' . $word . ';'; |
|
| 705 | - } |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - return $texte; |
|
| 685 | + // mb_string : methode rapide |
|
| 686 | + if (init_mb_string()) { |
|
| 687 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 688 | + $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 689 | + |
|
| 690 | + return str_replace(chr(0), '', $source); |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + // Sinon methode lente |
|
| 694 | + $texte = ''; |
|
| 695 | + while ($source) { |
|
| 696 | + $words = unpack('V*', substr($source, 0, 1024)); |
|
| 697 | + $source = substr($source, 1024); |
|
| 698 | + foreach ($words as $word) { |
|
| 699 | + if ($word < 128) { |
|
| 700 | + $texte .= chr($word); |
|
| 701 | + } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 702 | + else { |
|
| 703 | + if ($word != 65279) { |
|
| 704 | + $texte .= '&#' . $word . ';'; |
|
| 705 | + } |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + return $texte; |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | |
@@ -724,21 +724,21 @@ discard block |
||
| 724 | 724 | * Caractère utf8 si trouvé, '' sinon |
| 725 | 725 | **/ |
| 726 | 726 | function caractere_utf_8($num) { |
| 727 | - $num = intval($num); |
|
| 728 | - if ($num < 128) { |
|
| 729 | - return chr($num); |
|
| 730 | - } |
|
| 731 | - if ($num < 2048) { |
|
| 732 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 733 | - } |
|
| 734 | - if ($num < 65536) { |
|
| 735 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 736 | - } |
|
| 737 | - if ($num < 1_114_112) { |
|
| 738 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - return ''; |
|
| 727 | + $num = intval($num); |
|
| 728 | + if ($num < 128) { |
|
| 729 | + return chr($num); |
|
| 730 | + } |
|
| 731 | + if ($num < 2048) { |
|
| 732 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 733 | + } |
|
| 734 | + if ($num < 65536) { |
|
| 735 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 736 | + } |
|
| 737 | + if ($num < 1_114_112) { |
|
| 738 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + return ''; |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | /** |
@@ -751,42 +751,42 @@ discard block |
||
| 751 | 751 | **/ |
| 752 | 752 | function unicode_to_utf_8($texte) { |
| 753 | 753 | |
| 754 | - // 1. Entites € et suivantes |
|
| 755 | - $vu = []; |
|
| 756 | - if ( |
|
| 757 | - preg_match_all( |
|
| 758 | - ',�*([1-9][0-9][0-9]+);,S', |
|
| 759 | - $texte, |
|
| 760 | - $regs, |
|
| 761 | - PREG_SET_ORDER |
|
| 762 | - ) |
|
| 763 | - ) { |
|
| 764 | - foreach ($regs as $reg) { |
|
| 765 | - if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 766 | - $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 771 | - |
|
| 772 | - // 2. Entites > ÿ |
|
| 773 | - //$vu = array(); |
|
| 774 | - if ( |
|
| 775 | - preg_match_all( |
|
| 776 | - ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 777 | - $texte, |
|
| 778 | - $regs, |
|
| 779 | - PREG_SET_ORDER |
|
| 780 | - ) |
|
| 781 | - ) { |
|
| 782 | - foreach ($regs as $reg) { |
|
| 783 | - if (!isset($vu[$reg[0]])) { |
|
| 784 | - $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 754 | + // 1. Entites € et suivantes |
|
| 755 | + $vu = []; |
|
| 756 | + if ( |
|
| 757 | + preg_match_all( |
|
| 758 | + ',�*([1-9][0-9][0-9]+);,S', |
|
| 759 | + $texte, |
|
| 760 | + $regs, |
|
| 761 | + PREG_SET_ORDER |
|
| 762 | + ) |
|
| 763 | + ) { |
|
| 764 | + foreach ($regs as $reg) { |
|
| 765 | + if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 766 | + $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 771 | + |
|
| 772 | + // 2. Entites > ÿ |
|
| 773 | + //$vu = array(); |
|
| 774 | + if ( |
|
| 775 | + preg_match_all( |
|
| 776 | + ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 777 | + $texte, |
|
| 778 | + $regs, |
|
| 779 | + PREG_SET_ORDER |
|
| 780 | + ) |
|
| 781 | + ) { |
|
| 782 | + foreach ($regs as $reg) { |
|
| 783 | + if (!isset($vu[$reg[0]])) { |
|
| 784 | + $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | /** |
@@ -798,15 +798,15 @@ discard block |
||
| 798 | 798 | * Texte converti |
| 799 | 799 | **/ |
| 800 | 800 | function unicode_to_javascript($texte) { |
| 801 | - $vu = []; |
|
| 802 | - while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 803 | - $num = $regs[1]; |
|
| 804 | - $vu[$num] = true; |
|
| 805 | - $s = '\u' . sprintf('%04x', $num); |
|
| 806 | - $texte = str_replace($regs[0], $s, $texte); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - return $texte; |
|
| 801 | + $vu = []; |
|
| 802 | + while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 803 | + $num = $regs[1]; |
|
| 804 | + $vu[$num] = true; |
|
| 805 | + $s = '\u' . sprintf('%04x', $num); |
|
| 806 | + $texte = str_replace($regs[0], $s, $texte); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + return $texte; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -818,11 +818,11 @@ discard block |
||
| 818 | 818 | * Texte converti |
| 819 | 819 | **/ |
| 820 | 820 | function javascript_to_unicode($texte) { |
| 821 | - while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 822 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 823 | - } |
|
| 821 | + while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 822 | + $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 823 | + } |
|
| 824 | 824 | |
| 825 | - return $texte; |
|
| 825 | + return $texte; |
|
| 826 | 826 | } |
| 827 | 827 | |
| 828 | 828 | /** |
@@ -834,11 +834,11 @@ discard block |
||
| 834 | 834 | * Texte converti |
| 835 | 835 | **/ |
| 836 | 836 | function javascript_to_binary($texte) { |
| 837 | - while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 838 | - $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 839 | - } |
|
| 837 | + while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 838 | + $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 839 | + } |
|
| 840 | 840 | |
| 841 | - return $texte; |
|
| 841 | + return $texte; |
|
| 842 | 842 | } |
| 843 | 843 | |
| 844 | 844 | |
@@ -856,26 +856,26 @@ discard block |
||
| 856 | 856 | * @return string |
| 857 | 857 | */ |
| 858 | 858 | function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') { |
| 859 | - static $trans = []; |
|
| 860 | - if ($charset == 'AUTO') { |
|
| 861 | - $charset = $GLOBALS['meta']['charset']; |
|
| 862 | - } |
|
| 863 | - if (!strlen($texte)) { |
|
| 864 | - return $texte; |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - $table_translit = 'translit' . $complexe; |
|
| 868 | - |
|
| 869 | - // 2. Translitterer grace a la table predefinie |
|
| 870 | - if (!isset($trans[$complexe])) { |
|
| 871 | - $trans[$complexe] = []; |
|
| 872 | - load_charset($table_translit); |
|
| 873 | - foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 874 | - $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 875 | - } |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 859 | + static $trans = []; |
|
| 860 | + if ($charset == 'AUTO') { |
|
| 861 | + $charset = $GLOBALS['meta']['charset']; |
|
| 862 | + } |
|
| 863 | + if (!strlen($texte)) { |
|
| 864 | + return $texte; |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + $table_translit = 'translit' . $complexe; |
|
| 868 | + |
|
| 869 | + // 2. Translitterer grace a la table predefinie |
|
| 870 | + if (!isset($trans[$complexe])) { |
|
| 871 | + $trans[$complexe] = []; |
|
| 872 | + load_charset($table_translit); |
|
| 873 | + foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 874 | + $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 875 | + } |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | /** |
@@ -898,14 +898,14 @@ discard block |
||
| 898 | 898 | * @return string |
| 899 | 899 | */ |
| 900 | 900 | function translitteration($texte, $charset = 'AUTO', $complexe = '') { |
| 901 | - // 0. Supprimer les caracteres illegaux |
|
| 902 | - include_spip('inc/filtres'); |
|
| 903 | - $texte = corriger_caracteres($texte); |
|
| 901 | + // 0. Supprimer les caracteres illegaux |
|
| 902 | + include_spip('inc/filtres'); |
|
| 903 | + $texte = corriger_caracteres($texte); |
|
| 904 | 904 | |
| 905 | - // 1. Passer le charset et les é en utf-8 |
|
| 906 | - $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 905 | + // 1. Passer le charset et les é en utf-8 |
|
| 906 | + $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 907 | 907 | |
| 908 | - return translitteration_rapide($texte, $charset, $complexe); |
|
| 908 | + return translitteration_rapide($texte, $charset, $complexe); |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | /** |
@@ -920,17 +920,17 @@ discard block |
||
| 920 | 920 | * @return string |
| 921 | 921 | */ |
| 922 | 922 | function translitteration_complexe($texte, $chiffres = false) { |
| 923 | - $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 923 | + $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 924 | 924 | |
| 925 | - if ($chiffres) { |
|
| 926 | - $texte = preg_replace_callback( |
|
| 927 | - "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 928 | - fn($m) => translitteration_chiffree($m[0]), |
|
| 929 | - $texte |
|
| 930 | - ); |
|
| 931 | - } |
|
| 925 | + if ($chiffres) { |
|
| 926 | + $texte = preg_replace_callback( |
|
| 927 | + "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 928 | + fn($m) => translitteration_chiffree($m[0]), |
|
| 929 | + $texte |
|
| 930 | + ); |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | - return $texte; |
|
| 933 | + return $texte; |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | * @return string |
| 943 | 943 | */ |
| 944 | 944 | function translitteration_chiffree($car) { |
| 945 | - return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 945 | + return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | * true s'il a un BOM |
| 956 | 956 | **/ |
| 957 | 957 | function bom_utf8($texte) { |
| 958 | - return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 958 | + return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -972,21 +972,21 @@ discard block |
||
| 972 | 972 | * true si c'est le cas |
| 973 | 973 | **/ |
| 974 | 974 | function is_utf8($string) { |
| 975 | - return !strlen( |
|
| 976 | - preg_replace( |
|
| 977 | - ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 978 | - . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 979 | - . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 980 | - . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 981 | - . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 982 | - . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 983 | - . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 984 | - . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 985 | - . ',sS', |
|
| 986 | - '', |
|
| 987 | - $string |
|
| 988 | - ) |
|
| 989 | - ); |
|
| 975 | + return !strlen( |
|
| 976 | + preg_replace( |
|
| 977 | + ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 978 | + . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 979 | + . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 980 | + . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 981 | + . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 982 | + . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 983 | + . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 984 | + . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 985 | + . ',sS', |
|
| 986 | + '', |
|
| 987 | + $string |
|
| 988 | + ) |
|
| 989 | + ); |
|
| 990 | 990 | } |
| 991 | 991 | |
| 992 | 992 | /** |
@@ -998,13 +998,13 @@ discard block |
||
| 998 | 998 | * true si c'est le cas |
| 999 | 999 | **/ |
| 1000 | 1000 | function is_ascii($string) { |
| 1001 | - return !strlen( |
|
| 1002 | - preg_replace( |
|
| 1003 | - ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 1004 | - '', |
|
| 1005 | - $string |
|
| 1006 | - ) |
|
| 1007 | - ); |
|
| 1001 | + return !strlen( |
|
| 1002 | + preg_replace( |
|
| 1003 | + ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 1004 | + '', |
|
| 1005 | + $string |
|
| 1006 | + ) |
|
| 1007 | + ); |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | /** |
@@ -1023,53 +1023,53 @@ discard block |
||
| 1023 | 1023 | **/ |
| 1024 | 1024 | function transcoder_page($texte, $headers = '') { |
| 1025 | 1025 | |
| 1026 | - // Si tout est < 128 pas la peine d'aller plus loin |
|
| 1027 | - if (is_ascii($texte)) { |
|
| 1028 | - #spip_log('charset: ascii'); |
|
| 1029 | - return $texte; |
|
| 1030 | - } |
|
| 1031 | - |
|
| 1032 | - if (bom_utf8($texte)) { |
|
| 1033 | - // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1034 | - $charset = 'utf-8'; |
|
| 1035 | - $texte = substr($texte, 3); |
|
| 1036 | - } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1037 | - // charset precise par le contenu (xml) |
|
| 1038 | - $charset = trim(strtolower($regs[1])); |
|
| 1039 | - } elseif ( |
|
| 1040 | - // charset precise par le contenu (html) |
|
| 1041 | - preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 1042 | - # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 1043 | - and false === strpos($regs[2], '#') |
|
| 1044 | - and $tmp = trim(strtolower($regs[2])) |
|
| 1045 | - ) { |
|
| 1046 | - $charset = $tmp; |
|
| 1047 | - } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1048 | - // charset de la reponse http |
|
| 1049 | - $charset = trim(strtolower($regs[1])); |
|
| 1050 | - } else { |
|
| 1051 | - $charset = ''; |
|
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - |
|
| 1055 | - // normaliser les noms du shif-jis japonais |
|
| 1056 | - if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1057 | - $charset = 'shift-jis'; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - if ($charset) { |
|
| 1061 | - spip_log("charset: $charset"); |
|
| 1062 | - } else { |
|
| 1063 | - // valeur par defaut |
|
| 1064 | - if (is_utf8($texte)) { |
|
| 1065 | - $charset = 'utf-8'; |
|
| 1066 | - } else { |
|
| 1067 | - $charset = 'iso-8859-1'; |
|
| 1068 | - } |
|
| 1069 | - spip_log("charset probable: $charset"); |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - return importer_charset($texte, $charset); |
|
| 1026 | + // Si tout est < 128 pas la peine d'aller plus loin |
|
| 1027 | + if (is_ascii($texte)) { |
|
| 1028 | + #spip_log('charset: ascii'); |
|
| 1029 | + return $texte; |
|
| 1030 | + } |
|
| 1031 | + |
|
| 1032 | + if (bom_utf8($texte)) { |
|
| 1033 | + // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1034 | + $charset = 'utf-8'; |
|
| 1035 | + $texte = substr($texte, 3); |
|
| 1036 | + } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1037 | + // charset precise par le contenu (xml) |
|
| 1038 | + $charset = trim(strtolower($regs[1])); |
|
| 1039 | + } elseif ( |
|
| 1040 | + // charset precise par le contenu (html) |
|
| 1041 | + preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 1042 | + # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 1043 | + and false === strpos($regs[2], '#') |
|
| 1044 | + and $tmp = trim(strtolower($regs[2])) |
|
| 1045 | + ) { |
|
| 1046 | + $charset = $tmp; |
|
| 1047 | + } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1048 | + // charset de la reponse http |
|
| 1049 | + $charset = trim(strtolower($regs[1])); |
|
| 1050 | + } else { |
|
| 1051 | + $charset = ''; |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + |
|
| 1055 | + // normaliser les noms du shif-jis japonais |
|
| 1056 | + if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1057 | + $charset = 'shift-jis'; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + if ($charset) { |
|
| 1061 | + spip_log("charset: $charset"); |
|
| 1062 | + } else { |
|
| 1063 | + // valeur par defaut |
|
| 1064 | + if (is_utf8($texte)) { |
|
| 1065 | + $charset = 'utf-8'; |
|
| 1066 | + } else { |
|
| 1067 | + $charset = 'iso-8859-1'; |
|
| 1068 | + } |
|
| 1069 | + spip_log("charset probable: $charset"); |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + return importer_charset($texte, $charset); |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | |
@@ -1093,26 +1093,26 @@ discard block |
||
| 1093 | 1093 | * Le texte coupé |
| 1094 | 1094 | **/ |
| 1095 | 1095 | function spip_substr($c, $start = 0, $length = null) { |
| 1096 | - // Si ce n'est pas utf-8, utiliser substr |
|
| 1097 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1098 | - if ($length) { |
|
| 1099 | - return substr($c, $start, $length); |
|
| 1100 | - } else { |
|
| 1101 | - substr($c, $start); |
|
| 1102 | - } |
|
| 1103 | - } |
|
| 1104 | - |
|
| 1105 | - // Si utf-8, voir si on dispose de mb_string |
|
| 1106 | - if (init_mb_string()) { |
|
| 1107 | - if ($length) { |
|
| 1108 | - return mb_substr($c, $start, $length); |
|
| 1109 | - } else { |
|
| 1110 | - return mb_substr($c, $start); |
|
| 1111 | - } |
|
| 1112 | - } |
|
| 1113 | - |
|
| 1114 | - // Version manuelle (cf. ci-dessous) |
|
| 1115 | - return spip_substr_manuelle($c, $start, $length); |
|
| 1096 | + // Si ce n'est pas utf-8, utiliser substr |
|
| 1097 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1098 | + if ($length) { |
|
| 1099 | + return substr($c, $start, $length); |
|
| 1100 | + } else { |
|
| 1101 | + substr($c, $start); |
|
| 1102 | + } |
|
| 1103 | + } |
|
| 1104 | + |
|
| 1105 | + // Si utf-8, voir si on dispose de mb_string |
|
| 1106 | + if (init_mb_string()) { |
|
| 1107 | + if ($length) { |
|
| 1108 | + return mb_substr($c, $start, $length); |
|
| 1109 | + } else { |
|
| 1110 | + return mb_substr($c, $start); |
|
| 1111 | + } |
|
| 1112 | + } |
|
| 1113 | + |
|
| 1114 | + // Version manuelle (cf. ci-dessous) |
|
| 1115 | + return spip_substr_manuelle($c, $start, $length); |
|
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | |
@@ -1131,40 +1131,40 @@ discard block |
||
| 1131 | 1131 | **/ |
| 1132 | 1132 | function spip_substr_manuelle($c, $start, $length = null) { |
| 1133 | 1133 | |
| 1134 | - // Cas pathologique |
|
| 1135 | - if ($length === 0) { |
|
| 1136 | - return ''; |
|
| 1137 | - } |
|
| 1138 | - |
|
| 1139 | - // S'il y a un demarrage, on se positionne |
|
| 1140 | - if ($start > 0) { |
|
| 1141 | - $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1142 | - } elseif ($start < 0) { |
|
| 1143 | - return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - if (!$length) { |
|
| 1147 | - return $c; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - if ($length > 0) { |
|
| 1151 | - // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1152 | - // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1153 | - $n = 0; |
|
| 1154 | - while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1155 | - ; |
|
| 1156 | - } |
|
| 1157 | - $c = substr($c, 0, $n * $length); |
|
| 1158 | - // puis, tant qu'on est trop long, on coupe... |
|
| 1159 | - while (($l = spip_strlen($c)) > $length) { |
|
| 1160 | - $c = substr($c, 0, $length - $l); |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - return $c; |
|
| 1164 | - } |
|
| 1165 | - |
|
| 1166 | - // $length < 0 |
|
| 1167 | - return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1134 | + // Cas pathologique |
|
| 1135 | + if ($length === 0) { |
|
| 1136 | + return ''; |
|
| 1137 | + } |
|
| 1138 | + |
|
| 1139 | + // S'il y a un demarrage, on se positionne |
|
| 1140 | + if ($start > 0) { |
|
| 1141 | + $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1142 | + } elseif ($start < 0) { |
|
| 1143 | + return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + if (!$length) { |
|
| 1147 | + return $c; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + if ($length > 0) { |
|
| 1151 | + // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1152 | + // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1153 | + $n = 0; |
|
| 1154 | + while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1155 | + ; |
|
| 1156 | + } |
|
| 1157 | + $c = substr($c, 0, $n * $length); |
|
| 1158 | + // puis, tant qu'on est trop long, on coupe... |
|
| 1159 | + while (($l = spip_strlen($c)) > $length) { |
|
| 1160 | + $c = substr($c, 0, $length - $l); |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + return $c; |
|
| 1164 | + } |
|
| 1165 | + |
|
| 1166 | + // $length < 0 |
|
| 1167 | + return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | 1170 | /** |
@@ -1178,14 +1178,14 @@ discard block |
||
| 1178 | 1178 | * La chaîne avec une majuscule sur le premier mot |
| 1179 | 1179 | */ |
| 1180 | 1180 | function spip_ucfirst($c) { |
| 1181 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1182 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1183 | - return ucfirst($c); |
|
| 1184 | - } |
|
| 1181 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1182 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1183 | + return ucfirst($c); |
|
| 1184 | + } |
|
| 1185 | 1185 | |
| 1186 | - $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1186 | + $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1187 | 1187 | |
| 1188 | - return $lettre1 . spip_substr($c, 1); |
|
| 1188 | + return $lettre1 . spip_substr($c, 1); |
|
| 1189 | 1189 | } |
| 1190 | 1190 | |
| 1191 | 1191 | /** |
@@ -1199,12 +1199,12 @@ discard block |
||
| 1199 | 1199 | * La chaîne en minuscules |
| 1200 | 1200 | */ |
| 1201 | 1201 | function spip_strtolower($c) { |
| 1202 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1203 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1204 | - return strtolower($c); |
|
| 1205 | - } |
|
| 1202 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1203 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1204 | + return strtolower($c); |
|
| 1205 | + } |
|
| 1206 | 1206 | |
| 1207 | - return mb_strtolower($c); |
|
| 1207 | + return mb_strtolower($c); |
|
| 1208 | 1208 | } |
| 1209 | 1209 | |
| 1210 | 1210 | /** |
@@ -1218,23 +1218,23 @@ discard block |
||
| 1218 | 1218 | * Longueur de la chaîne |
| 1219 | 1219 | */ |
| 1220 | 1220 | function spip_strlen($c) { |
| 1221 | - // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1222 | - $c = str_replace("\r\n", "\n", $c); |
|
| 1223 | - |
|
| 1224 | - // Si ce n'est pas utf-8, utiliser strlen |
|
| 1225 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1226 | - return strlen($c); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - // Sinon, utiliser mb_strlen() si disponible |
|
| 1230 | - if (init_mb_string()) { |
|
| 1231 | - return mb_strlen($c); |
|
| 1232 | - } |
|
| 1233 | - |
|
| 1234 | - // Methode manuelle : on supprime les bytes 10......, |
|
| 1235 | - // on compte donc les ascii (0.......) et les demarrages |
|
| 1236 | - // de caracteres utf-8 (11......) |
|
| 1237 | - return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1221 | + // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1222 | + $c = str_replace("\r\n", "\n", $c); |
|
| 1223 | + |
|
| 1224 | + // Si ce n'est pas utf-8, utiliser strlen |
|
| 1225 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1226 | + return strlen($c); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + // Sinon, utiliser mb_strlen() si disponible |
|
| 1230 | + if (init_mb_string()) { |
|
| 1231 | + return mb_strlen($c); |
|
| 1232 | + } |
|
| 1233 | + |
|
| 1234 | + // Methode manuelle : on supprime les bytes 10......, |
|
| 1235 | + // on compte donc les ascii (0.......) et les demarrages |
|
| 1236 | + // de caracteres utf-8 (11......) |
|
| 1237 | + return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1238 | 1238 | } |
| 1239 | 1239 | |
| 1240 | 1240 | // Initialisation |
@@ -1244,16 +1244,16 @@ discard block |
||
| 1244 | 1244 | // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
| 1245 | 1245 | // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
| 1246 | 1246 | if ( |
| 1247 | - !isset($GLOBALS['meta']['pcre_u']) |
|
| 1248 | - or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1247 | + !isset($GLOBALS['meta']['pcre_u']) |
|
| 1248 | + or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1249 | 1249 | ) { |
| 1250 | - include_spip('inc/meta'); |
|
| 1251 | - ecrire_meta( |
|
| 1252 | - 'pcre_u', |
|
| 1253 | - $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1254 | - and test_pcre_unicode()) |
|
| 1255 | - ? 'u' : '' |
|
| 1256 | - ); |
|
| 1250 | + include_spip('inc/meta'); |
|
| 1251 | + ecrire_meta( |
|
| 1252 | + 'pcre_u', |
|
| 1253 | + $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1254 | + and test_pcre_unicode()) |
|
| 1255 | + ? 'u' : '' |
|
| 1256 | + ); |
|
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | 1259 | |
@@ -1269,17 +1269,17 @@ discard block |
||
| 1269 | 1269 | * en unicode : 💩 |
| 1270 | 1270 | */ |
| 1271 | 1271 | function utf8_noplanes($x) { |
| 1272 | - $regexp_utf8_4bytes = '/( |
|
| 1272 | + $regexp_utf8_4bytes = '/( |
|
| 1273 | 1273 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 1274 | 1274 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 1275 | 1275 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 1276 | 1276 | )/xS'; |
| 1277 | - if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1278 | - foreach ($z[0] as $k) { |
|
| 1279 | - $ku = utf_8_to_unicode($k); |
|
| 1280 | - $x = str_replace($k, $ku, $x); |
|
| 1281 | - } |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - return $x; |
|
| 1277 | + if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1278 | + foreach ($z[0] as $k) { |
|
| 1279 | + $ku = utf_8_to_unicode($k); |
|
| 1280 | + $x = str_replace($k, $ku, $x); |
|
| 1281 | + } |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + return $x; |
|
| 1285 | 1285 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | |
| 68 | 68 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 69 | - return; |
|
| 69 | + return; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -77,46 +77,46 @@ discard block |
||
| 77 | 77 | * @return array |
| 78 | 78 | */ |
| 79 | 79 | function cvtmulti_recuperer_post_precedents($form) { |
| 80 | - include_spip('inc/filtres'); |
|
| 81 | - if ( |
|
| 82 | - $form |
|
| 83 | - and $c = _request('cvtm_prev_post') |
|
| 84 | - and $c = decoder_contexte_ajax($c, $form) |
|
| 85 | - ) { |
|
| 86 | - #var_dump($c); |
|
| 80 | + include_spip('inc/filtres'); |
|
| 81 | + if ( |
|
| 82 | + $form |
|
| 83 | + and $c = _request('cvtm_prev_post') |
|
| 84 | + and $c = decoder_contexte_ajax($c, $form) |
|
| 85 | + ) { |
|
| 86 | + #var_dump($c); |
|
| 87 | 87 | |
| 88 | - # reinjecter dans la bonne variable pour permettre de retrouver |
|
| 89 | - # toutes les saisies dans un seul tableau |
|
| 90 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 91 | - $store = &$_POST; |
|
| 92 | - } else { |
|
| 93 | - $store = &$_GET; |
|
| 94 | - } |
|
| 88 | + # reinjecter dans la bonne variable pour permettre de retrouver |
|
| 89 | + # toutes les saisies dans un seul tableau |
|
| 90 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 91 | + $store = &$_POST; |
|
| 92 | + } else { |
|
| 93 | + $store = &$_GET; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau ! |
|
| 97 | - if (!isset($store[$k])) { |
|
| 98 | - $_REQUEST[$k] = $store[$k] = $v; |
|
| 99 | - } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie |
|
| 100 | - elseif ( |
|
| 101 | - is_array($store[$k]) |
|
| 102 | - and is_array($v) |
|
| 103 | - and $z = array_keys($v) |
|
| 104 | - and !is_numeric(reset($z)) |
|
| 105 | - and $z = array_keys($store[$k]) |
|
| 106 | - and !is_numeric(reset($z)) |
|
| 107 | - ) { |
|
| 108 | - $_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]); |
|
| 109 | - } |
|
| 110 | - } |
|
| 96 | + foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau ! |
|
| 97 | + if (!isset($store[$k])) { |
|
| 98 | + $_REQUEST[$k] = $store[$k] = $v; |
|
| 99 | + } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie |
|
| 100 | + elseif ( |
|
| 101 | + is_array($store[$k]) |
|
| 102 | + and is_array($v) |
|
| 103 | + and $z = array_keys($v) |
|
| 104 | + and !is_numeric(reset($z)) |
|
| 105 | + and $z = array_keys($store[$k]) |
|
| 106 | + and !is_numeric(reset($z)) |
|
| 107 | + ) { |
|
| 108 | + $_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - // vider pour eviter un second appel a verifier_n |
|
| 113 | - // en cas de double implementation (unipotence) |
|
| 114 | - set_request('cvtm_prev_post'); |
|
| 112 | + // vider pour eviter un second appel a verifier_n |
|
| 113 | + // en cas de double implementation (unipotence) |
|
| 114 | + set_request('cvtm_prev_post'); |
|
| 115 | 115 | |
| 116 | - return [$c['_etape'], $c['_etapes']]; |
|
| 117 | - } |
|
| 116 | + return [$c['_etape'], $c['_etapes']]; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return false; |
|
| 119 | + return false; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -129,28 +129,28 @@ discard block |
||
| 129 | 129 | * @return array |
| 130 | 130 | */ |
| 131 | 131 | function cvtmulti_sauver_post($form, $je_suis_poste, &$valeurs) { |
| 132 | - if (!isset($valeurs['_cvtm_prev_post'])) { |
|
| 133 | - $post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']]; |
|
| 134 | - foreach (array_keys($valeurs) as $champ) { |
|
| 135 | - if (substr($champ, 0, 1) !== '_') { |
|
| 136 | - if ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) { |
|
| 137 | - if (($v = _request($champ)) !== null) { |
|
| 138 | - $post[$champ] = $v; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - include_spip('inc/filtres'); |
|
| 144 | - $c = encoder_contexte_ajax($post, $form); |
|
| 145 | - if (!isset($valeurs['_hidden'])) { |
|
| 146 | - $valeurs['_hidden'] = ''; |
|
| 147 | - } |
|
| 148 | - $valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />"; |
|
| 149 | - // marquer comme fait, pour eviter double encodage (unipotence) |
|
| 150 | - $valeurs['_cvtm_prev_post'] = true; |
|
| 151 | - } |
|
| 132 | + if (!isset($valeurs['_cvtm_prev_post'])) { |
|
| 133 | + $post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']]; |
|
| 134 | + foreach (array_keys($valeurs) as $champ) { |
|
| 135 | + if (substr($champ, 0, 1) !== '_') { |
|
| 136 | + if ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) { |
|
| 137 | + if (($v = _request($champ)) !== null) { |
|
| 138 | + $post[$champ] = $v; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + include_spip('inc/filtres'); |
|
| 144 | + $c = encoder_contexte_ajax($post, $form); |
|
| 145 | + if (!isset($valeurs['_hidden'])) { |
|
| 146 | + $valeurs['_hidden'] = ''; |
|
| 147 | + } |
|
| 148 | + $valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />"; |
|
| 149 | + // marquer comme fait, pour eviter double encodage (unipotence) |
|
| 150 | + $valeurs['_cvtm_prev_post'] = true; |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return $valeurs; |
|
| 153 | + return $valeurs; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -164,14 +164,14 @@ discard block |
||
| 164 | 164 | * @return array |
| 165 | 165 | */ |
| 166 | 166 | function cvtmulti_formulaire_charger($flux) { |
| 167 | - if ( |
|
| 168 | - is_array($flux['data']) |
|
| 169 | - and isset($flux['data']['_etapes']) |
|
| 170 | - ) { |
|
| 171 | - $flux['data'] = cvtmulti_formulaire_charger_etapes($flux['args'], $flux['data']); |
|
| 172 | - } |
|
| 167 | + if ( |
|
| 168 | + is_array($flux['data']) |
|
| 169 | + and isset($flux['data']['_etapes']) |
|
| 170 | + ) { |
|
| 171 | + $flux['data'] = cvtmulti_formulaire_charger_etapes($flux['args'], $flux['data']); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - return $flux; |
|
| 174 | + return $flux; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -181,19 +181,19 @@ discard block |
||
| 181 | 181 | * @return array |
| 182 | 182 | */ |
| 183 | 183 | function cvtmulti_formulaire_charger_etapes($args, $valeurs) { |
| 184 | - if (!isset($valeurs['_etape'])) { |
|
| 185 | - $form = $args['form']; |
|
| 186 | - $je_suis_poste = $args['je_suis_poste']; |
|
| 187 | - $nb_etapes = $valeurs['_etapes']; |
|
| 188 | - $etape = _request('_etape'); |
|
| 189 | - $etape = min(max($etape, 1), $nb_etapes); |
|
| 190 | - set_request('_etape', $etape); |
|
| 191 | - $valeurs['_etape'] = $etape; |
|
| 184 | + if (!isset($valeurs['_etape'])) { |
|
| 185 | + $form = $args['form']; |
|
| 186 | + $je_suis_poste = $args['je_suis_poste']; |
|
| 187 | + $nb_etapes = $valeurs['_etapes']; |
|
| 188 | + $etape = _request('_etape'); |
|
| 189 | + $etape = min(max($etape, 1), $nb_etapes); |
|
| 190 | + set_request('_etape', $etape); |
|
| 191 | + $valeurs['_etape'] = $etape; |
|
| 192 | 192 | |
| 193 | - // sauver les posts de cette etape pour les avoir a la prochaine etape |
|
| 194 | - $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs); |
|
| 195 | - } |
|
| 196 | - return $valeurs; |
|
| 193 | + // sauver les posts de cette etape pour les avoir a la prochaine etape |
|
| 194 | + $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs); |
|
| 195 | + } |
|
| 196 | + return $valeurs; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | |
@@ -206,8 +206,8 @@ discard block |
||
| 206 | 206 | * @return array |
| 207 | 207 | */ |
| 208 | 208 | function cvtmulti_formulaire_verifier($flux) { |
| 209 | - $flux['data'] = cvtmulti_formulaire_verifier_etapes($flux['args'], $flux['data']); |
|
| 210 | - return $flux; |
|
| 209 | + $flux['data'] = cvtmulti_formulaire_verifier_etapes($flux['args'], $flux['data']); |
|
| 210 | + return $flux; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -218,87 +218,87 @@ discard block |
||
| 218 | 218 | * @return array |
| 219 | 219 | */ |
| 220 | 220 | function cvtmulti_formulaire_verifier_etapes($args, $erreurs) { |
| 221 | - #var_dump('Pipe verifier'); |
|
| 221 | + #var_dump('Pipe verifier'); |
|
| 222 | 222 | |
| 223 | - if ( |
|
| 224 | - $form = $args['form'] |
|
| 225 | - and ($e = cvtmulti_recuperer_post_precedents($form)) !== false |
|
| 226 | - ) { |
|
| 227 | - // recuperer l'etape saisie et le nombre d'etapes total |
|
| 228 | - [$etape, $etapes] = $e; |
|
| 229 | - $etape_demandee = intval(_request('aller_a_etape')); // possibilite de poster un entier dans aller_a_etape |
|
| 223 | + if ( |
|
| 224 | + $form = $args['form'] |
|
| 225 | + and ($e = cvtmulti_recuperer_post_precedents($form)) !== false |
|
| 226 | + ) { |
|
| 227 | + // recuperer l'etape saisie et le nombre d'etapes total |
|
| 228 | + [$etape, $etapes] = $e; |
|
| 229 | + $etape_demandee = intval(_request('aller_a_etape')); // possibilite de poster un entier dans aller_a_etape |
|
| 230 | 230 | |
| 231 | - $args['etape_saisie'] = $etape; |
|
| 232 | - $args['etapes'] = $etapes; |
|
| 233 | - // lancer les verifs pour chaque etape deja saisie de 1 a $etape |
|
| 234 | - $erreurs_etapes = []; |
|
| 235 | - $derniere_etape_ok = 0; |
|
| 236 | - $e = 0; |
|
| 237 | - while ($e < max($etape, $etape_demandee - 1) and $e < $etapes) { |
|
| 238 | - $e++; |
|
| 239 | - $erreurs_etapes[$e] = []; |
|
| 240 | - if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) { |
|
| 241 | - $erreurs_etapes[$e] = call_user_func_array($verifier, $args['args']); |
|
| 242 | - } elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) { |
|
| 243 | - $a = $args['args']; |
|
| 244 | - array_unshift($a, $e); |
|
| 245 | - $erreurs_etapes[$e] = call_user_func_array($verifier, $a); |
|
| 246 | - } |
|
| 247 | - // et on appelle un pipeline dedie aux etapes, plus easy |
|
| 248 | - $args['etape'] = $e; |
|
| 249 | - $args['etape_demandee'] = $etape_demandee; |
|
| 250 | - $erreurs_etapes[$e] = pipeline( |
|
| 251 | - 'formulaire_verifier_etape', |
|
| 252 | - [ |
|
| 253 | - 'args' => $args, |
|
| 254 | - 'data' => $erreurs_etapes[$e] |
|
| 255 | - ] |
|
| 256 | - ); |
|
| 231 | + $args['etape_saisie'] = $etape; |
|
| 232 | + $args['etapes'] = $etapes; |
|
| 233 | + // lancer les verifs pour chaque etape deja saisie de 1 a $etape |
|
| 234 | + $erreurs_etapes = []; |
|
| 235 | + $derniere_etape_ok = 0; |
|
| 236 | + $e = 0; |
|
| 237 | + while ($e < max($etape, $etape_demandee - 1) and $e < $etapes) { |
|
| 238 | + $e++; |
|
| 239 | + $erreurs_etapes[$e] = []; |
|
| 240 | + if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) { |
|
| 241 | + $erreurs_etapes[$e] = call_user_func_array($verifier, $args['args']); |
|
| 242 | + } elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) { |
|
| 243 | + $a = $args['args']; |
|
| 244 | + array_unshift($a, $e); |
|
| 245 | + $erreurs_etapes[$e] = call_user_func_array($verifier, $a); |
|
| 246 | + } |
|
| 247 | + // et on appelle un pipeline dedie aux etapes, plus easy |
|
| 248 | + $args['etape'] = $e; |
|
| 249 | + $args['etape_demandee'] = $etape_demandee; |
|
| 250 | + $erreurs_etapes[$e] = pipeline( |
|
| 251 | + 'formulaire_verifier_etape', |
|
| 252 | + [ |
|
| 253 | + 'args' => $args, |
|
| 254 | + 'data' => $erreurs_etapes[$e] |
|
| 255 | + ] |
|
| 256 | + ); |
|
| 257 | 257 | |
| 258 | - if ($derniere_etape_ok == $e - 1 and !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) { |
|
| 259 | - $derniere_etape_ok = $e; |
|
| 260 | - } |
|
| 261 | - // possibilite de poster dans _retour_etape_x ou aller_a_etape |
|
| 262 | - if (!is_null(_request("_retour_etape_$e"))) { |
|
| 263 | - $etape_demandee = $e; |
|
| 264 | - } |
|
| 265 | - // Il se peut que les verifications ait décidé de faire sauter des étapes |
|
| 266 | - if ($aller_a_etape = intval(_request('aller_a_etape'))) { |
|
| 267 | - $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape |
|
| 268 | - } |
|
| 269 | - } |
|
| 258 | + if ($derniere_etape_ok == $e - 1 and !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) { |
|
| 259 | + $derniere_etape_ok = $e; |
|
| 260 | + } |
|
| 261 | + // possibilite de poster dans _retour_etape_x ou aller_a_etape |
|
| 262 | + if (!is_null(_request("_retour_etape_$e"))) { |
|
| 263 | + $etape_demandee = $e; |
|
| 264 | + } |
|
| 265 | + // Il se peut que les verifications ait décidé de faire sauter des étapes |
|
| 266 | + if ($aller_a_etape = intval(_request('aller_a_etape'))) { |
|
| 267 | + $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | 271 | |
| 272 | - // si la derniere etape OK etait la derniere |
|
| 273 | - // on renvoie le flux inchange et ca declenche traiter |
|
| 274 | - if ( |
|
| 275 | - $derniere_etape_ok == $etapes |
|
| 276 | - and (!$etape_demandee or $etape_demandee >= $etapes) |
|
| 277 | - ) { |
|
| 278 | - return $erreurs; |
|
| 279 | - } else { |
|
| 280 | - $etape = $derniere_etape_ok + 1; |
|
| 281 | - if ($etape_demandee > 0 and $etape_demandee < $etape) { |
|
| 282 | - $etape = $etape_demandee; |
|
| 283 | - } |
|
| 284 | - $etape = min($etape, $etapes); |
|
| 285 | - #var_dump("prochaine etape $etape"); |
|
| 286 | - // retourner les erreurs de l'etape ciblee |
|
| 287 | - $erreurs = $erreurs_etapes[$etape] ?? []; |
|
| 288 | - // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur ! |
|
| 289 | - if ($erreurs) { |
|
| 290 | - if (!isset($erreurs['message_erreur'])) { |
|
| 291 | - $erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 292 | - } |
|
| 293 | - } else { |
|
| 294 | - $erreurs['message_erreur'] = ''; |
|
| 295 | - } |
|
| 296 | - $erreurs['_etapes'] = "etape suivante $etape"; |
|
| 297 | - set_request('_etape', $etape); |
|
| 298 | - } |
|
| 299 | - } |
|
| 272 | + // si la derniere etape OK etait la derniere |
|
| 273 | + // on renvoie le flux inchange et ca declenche traiter |
|
| 274 | + if ( |
|
| 275 | + $derniere_etape_ok == $etapes |
|
| 276 | + and (!$etape_demandee or $etape_demandee >= $etapes) |
|
| 277 | + ) { |
|
| 278 | + return $erreurs; |
|
| 279 | + } else { |
|
| 280 | + $etape = $derniere_etape_ok + 1; |
|
| 281 | + if ($etape_demandee > 0 and $etape_demandee < $etape) { |
|
| 282 | + $etape = $etape_demandee; |
|
| 283 | + } |
|
| 284 | + $etape = min($etape, $etapes); |
|
| 285 | + #var_dump("prochaine etape $etape"); |
|
| 286 | + // retourner les erreurs de l'etape ciblee |
|
| 287 | + $erreurs = $erreurs_etapes[$etape] ?? []; |
|
| 288 | + // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur ! |
|
| 289 | + if ($erreurs) { |
|
| 290 | + if (!isset($erreurs['message_erreur'])) { |
|
| 291 | + $erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 292 | + } |
|
| 293 | + } else { |
|
| 294 | + $erreurs['message_erreur'] = ''; |
|
| 295 | + } |
|
| 296 | + $erreurs['_etapes'] = "etape suivante $etape"; |
|
| 297 | + set_request('_etape', $etape); |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - return $erreurs; |
|
| 301 | + return $erreurs; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -310,17 +310,17 @@ discard block |
||
| 310 | 310 | * @return array |
| 311 | 311 | */ |
| 312 | 312 | function cvtmulti_styliser($flux) { |
| 313 | - if ( |
|
| 314 | - strncmp($flux['args']['fond'], 'formulaires/', 12) == 0 |
|
| 315 | - and isset($flux['args']['contexte']['_etapes']) |
|
| 316 | - and isset($flux['args']['contexte']['_etape']) |
|
| 317 | - and ($e = $flux['args']['contexte']['_etape']) > 1 |
|
| 318 | - and $ext = $flux['args']['ext'] |
|
| 319 | - and $f = $flux['data'] |
|
| 320 | - and file_exists($f . "_$e.$ext") |
|
| 321 | - ) { |
|
| 322 | - $flux['data'] = $f . "_$e"; |
|
| 323 | - } |
|
| 313 | + if ( |
|
| 314 | + strncmp($flux['args']['fond'], 'formulaires/', 12) == 0 |
|
| 315 | + and isset($flux['args']['contexte']['_etapes']) |
|
| 316 | + and isset($flux['args']['contexte']['_etape']) |
|
| 317 | + and ($e = $flux['args']['contexte']['_etape']) > 1 |
|
| 318 | + and $ext = $flux['args']['ext'] |
|
| 319 | + and $f = $flux['data'] |
|
| 320 | + and file_exists($f . "_$e.$ext") |
|
| 321 | + ) { |
|
| 322 | + $flux['data'] = $f . "_$e"; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - return $flux; |
|
| 325 | + return $flux; |
|
| 326 | 326 | } |