@@ -92,86 +92,86 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | // http://doc.spip.org/@spip_nfslock |
| 94 | 94 | function spip_nfslock($fichier,$max_age=0) { |
| 95 | - $tries = 0; |
|
| 95 | + $tries = 0; |
|
| 96 | 96 | |
| 97 | - if (!$max_age) $max_age = _DEFAULT_LOCKTIME; |
|
| 98 | - $lock_file = _DIR_TMP . _NAME_LOCK . "-" . substr(md5($fichier),0,8); |
|
| 97 | + if (!$max_age) $max_age = _DEFAULT_LOCKTIME; |
|
| 98 | + $lock_file = _DIR_TMP . _NAME_LOCK . "-" . substr(md5($fichier),0,8); |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | - /* |
|
| 101 | + /* |
|
| 102 | 102 | * 1. create a tmp file with a psuedo random file name. we also make |
| 103 | 103 | * tpath which is a buffer to store the full pathname of the tmp file. |
| 104 | 104 | */ |
| 105 | 105 | |
| 106 | - $id = creer_uniqid(); |
|
| 107 | - $tpath = _DIR_TMP."slock.$id"; |
|
| 108 | - $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ... |
|
| 109 | - if (!$tmpfd) { /* open failed */ |
|
| 110 | - @fclose($tmpfd); |
|
| 111 | - spip_unlink($tpath); |
|
| 112 | - return false; //NFSL_SYSF |
|
| 113 | - } |
|
| 106 | + $id = creer_uniqid(); |
|
| 107 | + $tpath = _DIR_TMP."slock.$id"; |
|
| 108 | + $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ... |
|
| 109 | + if (!$tmpfd) { /* open failed */ |
|
| 110 | + @fclose($tmpfd); |
|
| 111 | + spip_unlink($tpath); |
|
| 112 | + return false; //NFSL_SYSF |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /* |
|
| 115 | + /* |
|
| 116 | 116 | * 2. make fullpath, a buffer for the full pathname of the lock file. |
| 117 | 117 | * then start looping trying to lock it |
| 118 | 118 | */ |
| 119 | 119 | |
| 120 | - while ($tries < 10) { |
|
| 121 | - /* |
|
| 120 | + while ($tries < 10) { |
|
| 121 | + /* |
|
| 122 | 122 | * 3. link tmp file to lock file. if it goes, we win and we clean |
| 123 | 123 | * up and return the st_ctime of the lock file. |
| 124 | 124 | */ |
| 125 | 125 | |
| 126 | - if (link($tpath, $lock_file) == 1) { |
|
| 127 | - spip_unlink($tpath); /* got it! */ |
|
| 128 | - @fclose($tmpfd); |
|
| 129 | - if (($our_tmp = lstat($lock_file))==false) { /* stat failed... shouldn't happen */ |
|
| 130 | - spip_unlink($lock_file); |
|
| 131 | - return false; // (NFSL_SYSF); |
|
| 132 | - } |
|
| 133 | - return($our_tmp['ctime']); |
|
| 134 | - } |
|
| 126 | + if (link($tpath, $lock_file) == 1) { |
|
| 127 | + spip_unlink($tpath); /* got it! */ |
|
| 128 | + @fclose($tmpfd); |
|
| 129 | + if (($our_tmp = lstat($lock_file))==false) { /* stat failed... shouldn't happen */ |
|
| 130 | + spip_unlink($lock_file); |
|
| 131 | + return false; // (NFSL_SYSF); |
|
| 132 | + } |
|
| 133 | + return($our_tmp['ctime']); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /* |
|
| 136 | + /* |
|
| 137 | 137 | * 4. the lock failed. check for a stale lock file, being mindful |
| 138 | 138 | * of NFS and the fact the time is set from the NFS server. we |
| 139 | 139 | * do a write on the tmp file to update its time to the server's |
| 140 | 140 | * idea of "now." |
| 141 | 141 | */ |
| 142 | 142 | |
| 143 | - $old_stat = lstat($lock_file); |
|
| 144 | - if (@fputs($tmpfd, "zz", 2)!=2 || !$our_tmp=fstat($tmpfd)) |
|
| 145 | - break; /* something bogus is going on */ |
|
| 143 | + $old_stat = lstat($lock_file); |
|
| 144 | + if (@fputs($tmpfd, "zz", 2)!=2 || !$our_tmp=fstat($tmpfd)) |
|
| 145 | + break; /* something bogus is going on */ |
|
| 146 | 146 | |
| 147 | 147 | |
| 148 | - if ($old_stat!=false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) { |
|
| 149 | - spip_unlink($lock_file); /* break the stale lock */ |
|
| 150 | - $tries++; |
|
| 151 | - /* It is CRITICAL that we sleep after breaking |
|
| 148 | + if ($old_stat!=false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) { |
|
| 149 | + spip_unlink($lock_file); /* break the stale lock */ |
|
| 150 | + $tries++; |
|
| 151 | + /* It is CRITICAL that we sleep after breaking |
|
| 152 | 152 | * the lock. Otherwise, we could race with |
| 153 | 153 | * another process and unlink it's newly- |
| 154 | 154 | * created file. |
| 155 | 155 | */ |
| 156 | - sleep(1+rand(0,4)); |
|
| 157 | - continue; |
|
| 158 | - } |
|
| 156 | + sleep(1+rand(0,4)); |
|
| 157 | + continue; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - /* |
|
| 160 | + /* |
|
| 161 | 161 | * 5. try again |
| 162 | 162 | */ |
| 163 | 163 | |
| 164 | 164 | $tries++; |
| 165 | - sleep(1+rand(0,4)); |
|
| 166 | - } |
|
| 165 | + sleep(1+rand(0,4)); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /* |
|
| 168 | + /* |
|
| 169 | 169 | * 6. give up, failure. |
| 170 | 170 | */ |
| 171 | 171 | |
| 172 | - spip_unlink($tpath); |
|
| 173 | - @fclose($tmpfd); |
|
| 174 | - return false; //(NFSL_LOCKED); |
|
| 172 | + spip_unlink($tpath); |
|
| 173 | + @fclose($tmpfd); |
|
| 174 | + return false; //(NFSL_LOCKED); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /* |
@@ -212,63 +212,63 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | // http://doc.spip.org/@spip_nfsunlock |
| 214 | 214 | function spip_nfsunlock($fichier, $birth, $max_age=0, $test = false) { |
| 215 | - $id = creer_uniqid(); |
|
| 216 | - if (!$max_age) $max_age = _DEFAULT_LOCKTIME; |
|
| 215 | + $id = creer_uniqid(); |
|
| 216 | + if (!$max_age) $max_age = _DEFAULT_LOCKTIME; |
|
| 217 | 217 | |
| 218 | - /* |
|
| 218 | + /* |
|
| 219 | 219 | * 1. Build a temp file and stat that to get an idea of what the server |
| 220 | 220 | * thinks the current time is (our_tmp.st_ctime).. |
| 221 | 221 | */ |
| 222 | 222 | |
| 223 | - $tpath = _DIR_TMP."stime.$id"; |
|
| 224 | - $tmpfd = @fopen($tpath,'w'); |
|
| 225 | - if ((!$tmpfd) |
|
| 223 | + $tpath = _DIR_TMP."stime.$id"; |
|
| 224 | + $tmpfd = @fopen($tpath,'w'); |
|
| 225 | + if ((!$tmpfd) |
|
| 226 | 226 | OR (@fputs($tmpfd, "zz", 2) != 2) |
| 227 | - OR !($our_tmp = fstat($tmpfd))) { |
|
| 228 | - /* The open failed, or we can't write the file, or we can't stat it */ |
|
| 229 | - @fclose($tmpfd); |
|
| 230 | - spip_unlink($tpath); |
|
| 231 | - return false; //(NFSL_SYSF); |
|
| 232 | - } |
|
| 227 | + OR !($our_tmp = fstat($tmpfd))) { |
|
| 228 | + /* The open failed, or we can't write the file, or we can't stat it */ |
|
| 229 | + @fclose($tmpfd); |
|
| 230 | + spip_unlink($tpath); |
|
| 231 | + return false; //(NFSL_SYSF); |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 235 | - spip_unlink($tpath); |
|
| 234 | + @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 235 | + spip_unlink($tpath); |
|
| 236 | 236 | |
| 237 | - /* |
|
| 237 | + /* |
|
| 238 | 238 | * 2. make fullpath, a buffer for the full pathname of the lock file |
| 239 | 239 | */ |
| 240 | 240 | |
| 241 | - $lock_file = _DIR_TMP . _NAME_LOCK . "-" . substr(md5($fichier),0,8); |
|
| 241 | + $lock_file = _DIR_TMP . _NAME_LOCK . "-" . substr(md5($fichier),0,8); |
|
| 242 | 242 | |
| 243 | - /* |
|
| 243 | + /* |
|
| 244 | 244 | * 3. If the ctime hasn't been modified, unlink the file and return. If the |
| 245 | 245 | * lock has expired, sleep the usual random interval before returning. |
| 246 | 246 | * If we didn't sleep, there could be a race if the caller immediately |
| 247 | 247 | * tries to relock the file. |
| 248 | 248 | */ |
| 249 | 249 | |
| 250 | - if ( ($old_stat=@lstat($lock_file)) /* stat succeeds so file is there */ |
|
| 251 | - && ($old_stat['ctime'] == $birth)) { /* hasn't been modified since birth */ |
|
| 252 | - if (!$test) |
|
| 253 | - spip_unlink($lock_file); /* so the lock is ours to remove */ |
|
| 250 | + if ( ($old_stat=@lstat($lock_file)) /* stat succeeds so file is there */ |
|
| 251 | + && ($old_stat['ctime'] == $birth)) { /* hasn't been modified since birth */ |
|
| 252 | + if (!$test) |
|
| 253 | + spip_unlink($lock_file); /* so the lock is ours to remove */ |
|
| 254 | 254 | if ($our_tmp['ctime'] >= $birth + $max_age){ /* the lock has expired */ |
| 255 | - if (!$test) return false; //(NFSL_LOST); |
|
| 256 | - sleep(1+(random(0,4))); /* so sleep a bit */ |
|
| 255 | + if (!$test) return false; //(NFSL_LOST); |
|
| 256 | + sleep(1+(random(0,4))); /* so sleep a bit */ |
|
| 257 | + } |
|
| 258 | + return true;//(NFSL_OK); /* success */ |
|
| 257 | 259 | } |
| 258 | - return true;//(NFSL_OK); /* success */ |
|
| 259 | - } |
|
| 260 | 260 | |
| 261 | - /* |
|
| 261 | + /* |
|
| 262 | 262 | * 4. Either ctime has been modified, or the entire lock file is missing. |
| 263 | 263 | * If the lock should still be ours, based on the ctime of the temp |
| 264 | 264 | * file, return with NFSL_STOLEN. If not, then our lock is expired and |
| 265 | 265 | * someone else has grabbed the file, so return NFSL_LOST. |
| 266 | 266 | */ |
| 267 | 267 | |
| 268 | - if ($our_tmp['ctime'] < $birth + $max_age) /* lock was stolen */ |
|
| 269 | - return false; //(NFSL_STOLEN); |
|
| 268 | + if ($our_tmp['ctime'] < $birth + $max_age) /* lock was stolen */ |
|
| 269 | + return false; //(NFSL_STOLEN); |
|
| 270 | 270 | |
| 271 | - return false; //(NFSL_LOST); /* The lock must have expired first. */ |
|
| 271 | + return false; //(NFSL_LOST); /* The lock must have expired first. */ |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | |
| 292 | 292 | // http://doc.spip.org/@spip_nfslock_test |
| 293 | 293 | function spip_nfslock_test($fichier, $birth, $max_age=0) { |
| 294 | - return spip_nfsunlock($fichier, $birth, $max_age, true); |
|
| 294 | + return spip_nfsunlock($fichier, $birth, $max_age, true); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | ?> |
@@ -16,95 +16,95 @@ |
||
| 16 | 16 | |
| 17 | 17 | // http://doc.spip.org/@inc_plonger_dist |
| 18 | 18 | function inc_plonger_dist($id_rubrique, $idom="", $list=array(), $col = 1, $exclu=0, $do='aff') { |
| 19 | - global $spip_lang_left; |
|
| 19 | + global $spip_lang_left; |
|
| 20 | 20 | |
| 21 | - if ($list) $id_rubrique = $list[$col-1]; |
|
| 21 | + if ($list) $id_rubrique = $list[$col-1]; |
|
| 22 | 22 | |
| 23 | - $ret = ''; |
|
| 23 | + $ret = ''; |
|
| 24 | 24 | |
| 25 | - # recherche les filles et petites-filles de la rubrique donnee |
|
| 26 | - # en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on |
|
| 27 | - # deplace une rubrique, on peut la deplacer partout a partir de la |
|
| 28 | - # racine... sauf vers elle-meme ou sa propre branche) |
|
| 29 | - $ordre = array(); |
|
| 30 | - $rub = array(); |
|
| 25 | + # recherche les filles et petites-filles de la rubrique donnee |
|
| 26 | + # en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on |
|
| 27 | + # deplace une rubrique, on peut la deplacer partout a partir de la |
|
| 28 | + # racine... sauf vers elle-meme ou sa propre branche) |
|
| 29 | + $ordre = array(); |
|
| 30 | + $rub = array(); |
|
| 31 | 31 | |
| 32 | - $res = sql_select("rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant", |
|
| 33 | - "spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)", |
|
| 34 | - "rub1.id_parent = ".sql_quote($id_rubrique)." |
|
| 32 | + $res = sql_select("rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant", |
|
| 33 | + "spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)", |
|
| 34 | + "rub1.id_parent = ".sql_quote($id_rubrique)." |
|
| 35 | 35 | AND rub1.id_rubrique!=".sql_quote($exclu)." |
| 36 | 36 | AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=".sql_quote($exclu).")", "", "0+rub1.titre,rub1.titre"); |
| 37 | 37 | |
| 38 | - while ($row = sql_fetch($res)) { |
|
| 39 | - if (autoriser('voir','rubrique',$row['id_rubrique'])){ |
|
| 40 | - $rub[$row['id_rubrique']]['enfants'] = $row['id_enfant']; |
|
| 41 | - if ($row['id_parent'] == $id_rubrique) { |
|
| 42 | - $t = trim(typo(supprimer_numero($row['titre']))); |
|
| 43 | - if ($row['langue_choisie'] != 'oui') |
|
| 44 | - $t .= ' <small title="' |
|
| 45 | - .traduire_nom_langue($row['lang']) |
|
| 46 | - .'">[' . $row['lang'] . ']</small>'; |
|
| 47 | - $ordre[$row['id_rubrique']] = $t; |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - $next = isset($list[$col]) ? $list[$col] : 0; |
|
| 52 | - if ($ordre) { |
|
| 53 | - $rec = generer_url_ecrire('plonger',"rac=$idom&exclus=$exclu&do=$do&col=".($col+1)); |
|
| 54 | - $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
|
| 55 | - $args = "'$idom',this,$col,'$spip_lang_left','$info',event"; |
|
| 56 | - while (list($id, $titrebrut) = each($ordre)) { |
|
| 38 | + while ($row = sql_fetch($res)) { |
|
| 39 | + if (autoriser('voir','rubrique',$row['id_rubrique'])){ |
|
| 40 | + $rub[$row['id_rubrique']]['enfants'] = $row['id_enfant']; |
|
| 41 | + if ($row['id_parent'] == $id_rubrique) { |
|
| 42 | + $t = trim(typo(supprimer_numero($row['titre']))); |
|
| 43 | + if ($row['langue_choisie'] != 'oui') |
|
| 44 | + $t .= ' <small title="' |
|
| 45 | + .traduire_nom_langue($row['lang']) |
|
| 46 | + .'">[' . $row['lang'] . ']</small>'; |
|
| 47 | + $ordre[$row['id_rubrique']] = $t; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + $next = isset($list[$col]) ? $list[$col] : 0; |
|
| 52 | + if ($ordre) { |
|
| 53 | + $rec = generer_url_ecrire('plonger',"rac=$idom&exclus=$exclu&do=$do&col=".($col+1)); |
|
| 54 | + $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
|
| 55 | + $args = "'$idom',this,$col,'$spip_lang_left','$info',event"; |
|
| 56 | + while (list($id, $titrebrut) = each($ordre)) { |
|
| 57 | 57 | |
| 58 | - $titre = supprimer_numero($titrebrut); |
|
| 58 | + $titre = supprimer_numero($titrebrut); |
|
| 59 | 59 | |
| 60 | - $classe1 = $id_rubrique ? 'petite-rubrique' : "petit-secteur"; |
|
| 61 | - if (isset($rub[$id]["enfants"])) { |
|
| 62 | - $classe2 = " class='rub-ouverte'"; |
|
| 63 | - $url = "\nhref='$rec&id=$id'" ; |
|
| 64 | - } else { $url = $classe2 = '' ; } |
|
| 60 | + $classe1 = $id_rubrique ? 'petite-rubrique' : "petit-secteur"; |
|
| 61 | + if (isset($rub[$id]["enfants"])) { |
|
| 62 | + $classe2 = " class='rub-ouverte'"; |
|
| 63 | + $url = "\nhref='$rec&id=$id'" ; |
|
| 64 | + } else { $url = $classe2 = '' ; } |
|
| 65 | 65 | |
| 66 | - $js_func = $do . '_selection_titre'; |
|
| 67 | - $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn " |
|
| 68 | - . (!is_array($list) ? ' false' |
|
| 69 | - : "aff_selection_provisoire($id,$args)") |
|
| 66 | + $js_func = $do . '_selection_titre'; |
|
| 67 | + $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn " |
|
| 68 | + . (!is_array($list) ? ' false' |
|
| 69 | + : "aff_selection_provisoire($id,$args)") |
|
| 70 | 70 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 71 | 71 | # et l'affichage de son titre dans le bandeau |
| 72 | - . "\"\nondblclick=\"" |
|
| 73 | - . "$js_func(this." |
|
| 74 | - . "firstChild.nodeValue," |
|
| 75 | - . $id |
|
| 76 | - . ",'selection_rubrique','id_parent');" |
|
| 77 | - . "\nreturn aff_selection_provisoire($id,$args);" |
|
| 78 | - . "\""; |
|
| 72 | + . "\"\nondblclick=\"" |
|
| 73 | + . "$js_func(this." |
|
| 74 | + . "firstChild.nodeValue," |
|
| 75 | + . $id |
|
| 76 | + . ",'selection_rubrique','id_parent');" |
|
| 77 | + . "\nreturn aff_selection_provisoire($id,$args);" |
|
| 78 | + . "\""; |
|
| 79 | 79 | |
| 80 | - $ret .= "<div class='" |
|
| 81 | - . (($id == $next) ? "item on" : "item") |
|
| 82 | - . "'><div class='" |
|
| 83 | - . $classe1 |
|
| 84 | - . "'><div$classe2><a" |
|
| 85 | - . $url |
|
| 86 | - . $click |
|
| 87 | - . ">" |
|
| 88 | - . $titre |
|
| 89 | - . "</a></div></div></div>"; |
|
| 90 | - } |
|
| 91 | - } |
|
| 80 | + $ret .= "<div class='" |
|
| 81 | + . (($id == $next) ? "item on" : "item") |
|
| 82 | + . "'><div class='" |
|
| 83 | + . $classe1 |
|
| 84 | + . "'><div$classe2><a" |
|
| 85 | + . $url |
|
| 86 | + . $click |
|
| 87 | + . ">" |
|
| 88 | + . $titre |
|
| 89 | + . "</a></div></div></div>"; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $idom2 = $idom . "_col_".($col+1); |
|
| 94 | - $left = ($col*150); |
|
| 93 | + $idom2 = $idom . "_col_".($col+1); |
|
| 94 | + $left = ($col*150); |
|
| 95 | 95 | |
| 96 | - return http_img_pack("searching.gif", "*", "style='visibility: hidden; position: absolute; $spip_lang_left: " |
|
| 97 | - . ($left-30) |
|
| 98 | - . "px; top: 2px; z-index: 2;' id='img_$idom2'") |
|
| 99 | - . "<div style='width: 150px; height: 100%; overflow: auto; position: absolute; top: 0px; $spip_lang_left: " |
|
| 100 | - .($left-150) |
|
| 101 | - ."px;'>" |
|
| 102 | - . $ret |
|
| 103 | - . "\n</div>\n<div id='$idom2'>" |
|
| 104 | - . ($next |
|
| 105 | - ? inc_plonger_dist($id_rubrique, $idom, $list, $col+1, $exclu) |
|
| 106 | - : "") |
|
| 107 | - . "\n</div>"; |
|
| 96 | + return http_img_pack("searching.gif", "*", "style='visibility: hidden; position: absolute; $spip_lang_left: " |
|
| 97 | + . ($left-30) |
|
| 98 | + . "px; top: 2px; z-index: 2;' id='img_$idom2'") |
|
| 99 | + . "<div style='width: 150px; height: 100%; overflow: auto; position: absolute; top: 0px; $spip_lang_left: " |
|
| 100 | + .($left-150) |
|
| 101 | + ."px;'>" |
|
| 102 | + . $ret |
|
| 103 | + . "\n</div>\n<div id='$idom2'>" |
|
| 104 | + . ($next |
|
| 105 | + ? inc_plonger_dist($id_rubrique, $idom, $list, $col+1, $exclu) |
|
| 106 | + : "") |
|
| 107 | + . "\n</div>"; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | ?> |
@@ -22,34 +22,34 @@ discard block |
||
| 22 | 22 | // Le tableau ci-dessous donne le repere correspondant a ces informations. |
| 23 | 23 | |
| 24 | 24 | $GLOBALS['aider_index'] = array( |
| 25 | - 'editer_article.html' => array ( |
|
| 26 | - 'surtitre' => 'arttitre', |
|
| 27 | - 'titre' => 'arttitre', |
|
| 28 | - 'soustitre' => 'arttitre', |
|
| 29 | - 'id_parent' => 'artrub', |
|
| 30 | - 'descriptif' => 'artdesc', |
|
| 31 | - 'virtuel' => 'artvirt', |
|
| 32 | - 'chapo' => 'arttitre', |
|
| 33 | - 'text_area' => 'arttexte'), |
|
| 25 | + 'editer_article.html' => array ( |
|
| 26 | + 'surtitre' => 'arttitre', |
|
| 27 | + 'titre' => 'arttitre', |
|
| 28 | + 'soustitre' => 'arttitre', |
|
| 29 | + 'id_parent' => 'artrub', |
|
| 30 | + 'descriptif' => 'artdesc', |
|
| 31 | + 'virtuel' => 'artvirt', |
|
| 32 | + 'chapo' => 'arttitre', |
|
| 33 | + 'text_area' => 'arttexte'), |
|
| 34 | 34 | |
| 35 | - 'editer_breve.html' => array( |
|
| 36 | - 'id_parent' => 'brevesrub', |
|
| 37 | - 'lien_titre' => 'breveslien', |
|
| 38 | - 'statut' => 'brevesstatut'), |
|
| 35 | + 'editer_breve.html' => array( |
|
| 36 | + 'id_parent' => 'brevesrub', |
|
| 37 | + 'lien_titre' => 'breveslien', |
|
| 38 | + 'statut' => 'brevesstatut'), |
|
| 39 | 39 | |
| 40 | - 'editer_groupe_mot.html' => array( |
|
| 41 | - 'titre' => 'motsgroupes'), |
|
| 40 | + 'editer_groupe_mot.html' => array( |
|
| 41 | + 'titre' => 'motsgroupes'), |
|
| 42 | 42 | |
| 43 | - 'editer_mot.html' => array( |
|
| 44 | - 'titre' => 'mots', |
|
| 45 | - 'id_groupe' => 'motsgroupes'), |
|
| 43 | + 'editer_mot.html' => array( |
|
| 44 | + 'titre' => 'mots', |
|
| 45 | + 'id_groupe' => 'motsgroupes'), |
|
| 46 | 46 | |
| 47 | - 'editer_rubrique.html' => array( |
|
| 48 | - 'titre' => 'arttitre', |
|
| 49 | - 'id_parent' => 'rubrub', |
|
| 50 | - 'text_area' => 'raccourcis') |
|
| 47 | + 'editer_rubrique.html' => array( |
|
| 48 | + 'titre' => 'arttitre', |
|
| 49 | + 'id_parent' => 'rubrub', |
|
| 50 | + 'text_area' => 'raccourcis') |
|
| 51 | 51 | |
| 52 | - ); |
|
| 52 | + ); |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | 55 | |
@@ -68,51 +68,51 @@ discard block |
||
| 68 | 68 | * @return |
| 69 | 69 | **/ |
| 70 | 70 | function inc_aider_dist($aide='', $skel='', $env=array(), $aide_spip_directe = false) { |
| 71 | - global $spip_lang, $aider_index; |
|
| 72 | - |
|
| 73 | - if (($skel = basename($skel)) |
|
| 74 | - AND isset($aider_index[$skel]) |
|
| 75 | - AND isset($aider_index[$skel][$aide])) |
|
| 76 | - $aide = $aider_index[$skel][$aide]; |
|
| 77 | - |
|
| 78 | - if ($aide_spip_directe) { |
|
| 79 | - // on suppose que spip.net est le premier present |
|
| 80 | - // dans la liste des serveurs. C'est forcement le cas |
|
| 81 | - // a l'installation tout du moins |
|
| 82 | - $help_server = $GLOBALS['help_server']; |
|
| 83 | - $url = array_shift($help_server) . '/'; |
|
| 84 | - $url = parametre_url($url, 'exec', 'aide'); |
|
| 85 | - $url = parametre_url($url, 'aide', $aide); |
|
| 86 | - $url = parametre_url($url, 'var_lang', $spip_lang); |
|
| 87 | - } else { |
|
| 88 | - $args = "aide=$aide&var_lang=$spip_lang"; |
|
| 89 | - $url = generer_url_ecrire("aide", $args); |
|
| 90 | - } |
|
| 71 | + global $spip_lang, $aider_index; |
|
| 72 | + |
|
| 73 | + if (($skel = basename($skel)) |
|
| 74 | + AND isset($aider_index[$skel]) |
|
| 75 | + AND isset($aider_index[$skel][$aide])) |
|
| 76 | + $aide = $aider_index[$skel][$aide]; |
|
| 77 | + |
|
| 78 | + if ($aide_spip_directe) { |
|
| 79 | + // on suppose que spip.net est le premier present |
|
| 80 | + // dans la liste des serveurs. C'est forcement le cas |
|
| 81 | + // a l'installation tout du moins |
|
| 82 | + $help_server = $GLOBALS['help_server']; |
|
| 83 | + $url = array_shift($help_server) . '/'; |
|
| 84 | + $url = parametre_url($url, 'exec', 'aide'); |
|
| 85 | + $url = parametre_url($url, 'aide', $aide); |
|
| 86 | + $url = parametre_url($url, 'var_lang', $spip_lang); |
|
| 87 | + } else { |
|
| 88 | + $args = "aide=$aide&var_lang=$spip_lang"; |
|
| 89 | + $url = generer_url_ecrire("aide", $args); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return aider_icone($url); |
|
| 92 | + return aider_icone($url); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | function aider_icone($url, $clic= '') |
| 96 | 96 | { |
| 97 | - global $spip_lang, $spip_lang_rtl; |
|
| 98 | - |
|
| 99 | - if (!$clic) { |
|
| 100 | - $t = _T('titre_image_aide'); |
|
| 101 | - $clic = http_img_pack("aide".aide_lang_dir($spip_lang,$spip_lang_rtl)."-16.png", |
|
| 102 | - _T('info_image_aide'), |
|
| 103 | - " title=\"$t\" class='aide'"); |
|
| 104 | - } |
|
| 105 | - return "\n <a class='aide popin'\nhref='" |
|
| 106 | - . $url |
|
| 107 | - . "' target='_blank'>" |
|
| 108 | - . $clic |
|
| 109 | - . "</a>"; |
|
| 97 | + global $spip_lang, $spip_lang_rtl; |
|
| 98 | + |
|
| 99 | + if (!$clic) { |
|
| 100 | + $t = _T('titre_image_aide'); |
|
| 101 | + $clic = http_img_pack("aide".aide_lang_dir($spip_lang,$spip_lang_rtl)."-16.png", |
|
| 102 | + _T('info_image_aide'), |
|
| 103 | + " title=\"$t\" class='aide'"); |
|
| 104 | + } |
|
| 105 | + return "\n <a class='aide popin'\nhref='" |
|
| 106 | + . $url |
|
| 107 | + . "' target='_blank'>" |
|
| 108 | + . $clic |
|
| 109 | + . "</a>"; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // en hebreu le ? ne doit pas etre inverse |
| 113 | 113 | // http://doc.spip.org/@aide_lang_dir |
| 114 | 114 | function aide_lang_dir($spip_lang,$spip_lang_rtl) { |
| 115 | - return ($spip_lang<>'he') ? $spip_lang_rtl : ''; |
|
| 115 | + return ($spip_lang<>'he') ? $spip_lang_rtl : ''; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // Les sections d'un fichier aide sont reperees ainsi: |
@@ -120,85 +120,85 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | function aide_fichier($path, $help_server) { |
| 122 | 122 | |
| 123 | - $md5 = md5(serialize($help_server)); |
|
| 124 | - $fichier_aide = _DIR_AIDE . substr($md5,0,16) . "-" . $path; |
|
| 125 | - $lastm = @filemtime($fichier_aide); |
|
| 126 | - $lastversion = @filemtime(_DIR_RESTREINT . 'inc_version.php'); |
|
| 127 | - $here = @(is_readable($fichier_aide) AND ($lastm >= $lastversion)); |
|
| 128 | - $contenu = ''; |
|
| 129 | - |
|
| 130 | - if ($here) { |
|
| 131 | - lire_fichier($fichier_aide, $contenu); |
|
| 132 | - return array($contenu, $lastm); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // mettre en cache (tant pis si echec) |
|
| 136 | - sous_repertoire(_DIR_AIDE,'','',true); |
|
| 137 | - $contenu = array(); |
|
| 138 | - include_spip('inc/distant'); |
|
| 139 | - foreach ($help_server as $k => $server) { |
|
| 140 | - // Remplacer les liens aux images par leur gestionnaire de cache |
|
| 141 | - $url = "$server/$path"; |
|
| 142 | - $local = _DIR_AIDE.substr(md5($url),0,8)."-".preg_replace(",[^\w.]+,i","_",$url); |
|
| 143 | - $local = _DIR_RACINE . copie_locale($url, 'modif', $local); |
|
| 144 | - |
|
| 145 | - lire_fichier($local,$page); |
|
| 146 | - $page = aide_fixe_img($page,$server); |
|
| 147 | - // les liens internes ne doivent pas etre deguises en externes |
|
| 148 | - $url = parse_url($url); |
|
| 149 | - $re = '@(<a\b[^>]*\s+href=["\'])' . |
|
| 150 | - '(?:' . $url['scheme'] . '://' . $url['host'] . ')?' . |
|
| 151 | - $url['path'] . '([^"\']*)@ims'; |
|
| 152 | - $page = preg_replace($re,'\\1\\2', $page); |
|
| 153 | - |
|
| 154 | - preg_match_all(_SECTIONS_AIDE, $page, $sections, PREG_SET_ORDER); |
|
| 155 | - // Fusionner les aides ayant meme nom de section |
|
| 156 | - $vus = array(); |
|
| 157 | - foreach ($sections as $section) { |
|
| 158 | - list($tout,$prof, $sujet,) = $section; |
|
| 159 | - if (in_array($sujet, $vus)) continue; |
|
| 160 | - $corps = aide_section($sujet, $page, $prof); |
|
| 161 | - foreach ($contenu as $k => $s) { |
|
| 162 | - if ($sujet == $k) { |
|
| 163 | - // Section deja vue qu'il faut completer |
|
| 164 | - // Si le complement a des sous-sections, |
|
| 165 | - // ne pas en tenir compte quand on les rencontrera |
|
| 166 | - // lors des prochains passages dans la boucle |
|
| 167 | - preg_match_all(_SECTIONS_AIDE, $corps, $s, PREG_PATTERN_ORDER); |
|
| 168 | - if ($s) {$vus = array_merge($vus, $s[2]);} |
|
| 169 | - $contenu[$k] .= $corps; |
|
| 170 | - $corps = ''; |
|
| 171 | - break; |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - // Si totalement nouveau, inserer le titre |
|
| 175 | - // mais pas le corps s'il contient des sous-sections: |
|
| 176 | - // elles vont venir dans les passages suivants |
|
| 177 | - if ($corps) { |
|
| 178 | - $corps = aide_section($sujet, $page); |
|
| 179 | - $contenu[$sujet] = $tout . "\n" . $corps; |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - $contenu = '<div>' . join('',$contenu) . '</div>'; |
|
| 185 | - |
|
| 186 | - // Renvoyer les liens vraiment externes dans une autre fenetre |
|
| 187 | - $contenu = preg_replace('@<a href="(http://[^"]+)"([^>]*)>@', |
|
| 188 | - '<a href="\\1"\\2 target="_blank">', |
|
| 189 | - $contenu); |
|
| 190 | - |
|
| 191 | - // Correction typo dans la langue demandee |
|
| 192 | - #changer_typo($lang_aide); |
|
| 193 | - $contenu = '<body>' . $contenu . '</body>'; |
|
| 194 | - |
|
| 195 | - if (strlen($contenu) <= 100) return array(false, false); |
|
| 196 | - ecrire_fichier ($fichier_aide, $contenu); |
|
| 197 | - return array($contenu, time()); |
|
| 123 | + $md5 = md5(serialize($help_server)); |
|
| 124 | + $fichier_aide = _DIR_AIDE . substr($md5,0,16) . "-" . $path; |
|
| 125 | + $lastm = @filemtime($fichier_aide); |
|
| 126 | + $lastversion = @filemtime(_DIR_RESTREINT . 'inc_version.php'); |
|
| 127 | + $here = @(is_readable($fichier_aide) AND ($lastm >= $lastversion)); |
|
| 128 | + $contenu = ''; |
|
| 129 | + |
|
| 130 | + if ($here) { |
|
| 131 | + lire_fichier($fichier_aide, $contenu); |
|
| 132 | + return array($contenu, $lastm); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // mettre en cache (tant pis si echec) |
|
| 136 | + sous_repertoire(_DIR_AIDE,'','',true); |
|
| 137 | + $contenu = array(); |
|
| 138 | + include_spip('inc/distant'); |
|
| 139 | + foreach ($help_server as $k => $server) { |
|
| 140 | + // Remplacer les liens aux images par leur gestionnaire de cache |
|
| 141 | + $url = "$server/$path"; |
|
| 142 | + $local = _DIR_AIDE.substr(md5($url),0,8)."-".preg_replace(",[^\w.]+,i","_",$url); |
|
| 143 | + $local = _DIR_RACINE . copie_locale($url, 'modif', $local); |
|
| 144 | + |
|
| 145 | + lire_fichier($local,$page); |
|
| 146 | + $page = aide_fixe_img($page,$server); |
|
| 147 | + // les liens internes ne doivent pas etre deguises en externes |
|
| 148 | + $url = parse_url($url); |
|
| 149 | + $re = '@(<a\b[^>]*\s+href=["\'])' . |
|
| 150 | + '(?:' . $url['scheme'] . '://' . $url['host'] . ')?' . |
|
| 151 | + $url['path'] . '([^"\']*)@ims'; |
|
| 152 | + $page = preg_replace($re,'\\1\\2', $page); |
|
| 153 | + |
|
| 154 | + preg_match_all(_SECTIONS_AIDE, $page, $sections, PREG_SET_ORDER); |
|
| 155 | + // Fusionner les aides ayant meme nom de section |
|
| 156 | + $vus = array(); |
|
| 157 | + foreach ($sections as $section) { |
|
| 158 | + list($tout,$prof, $sujet,) = $section; |
|
| 159 | + if (in_array($sujet, $vus)) continue; |
|
| 160 | + $corps = aide_section($sujet, $page, $prof); |
|
| 161 | + foreach ($contenu as $k => $s) { |
|
| 162 | + if ($sujet == $k) { |
|
| 163 | + // Section deja vue qu'il faut completer |
|
| 164 | + // Si le complement a des sous-sections, |
|
| 165 | + // ne pas en tenir compte quand on les rencontrera |
|
| 166 | + // lors des prochains passages dans la boucle |
|
| 167 | + preg_match_all(_SECTIONS_AIDE, $corps, $s, PREG_PATTERN_ORDER); |
|
| 168 | + if ($s) {$vus = array_merge($vus, $s[2]);} |
|
| 169 | + $contenu[$k] .= $corps; |
|
| 170 | + $corps = ''; |
|
| 171 | + break; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + // Si totalement nouveau, inserer le titre |
|
| 175 | + // mais pas le corps s'il contient des sous-sections: |
|
| 176 | + // elles vont venir dans les passages suivants |
|
| 177 | + if ($corps) { |
|
| 178 | + $corps = aide_section($sujet, $page); |
|
| 179 | + $contenu[$sujet] = $tout . "\n" . $corps; |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + $contenu = '<div>' . join('',$contenu) . '</div>'; |
|
| 185 | + |
|
| 186 | + // Renvoyer les liens vraiment externes dans une autre fenetre |
|
| 187 | + $contenu = preg_replace('@<a href="(http://[^"]+)"([^>]*)>@', |
|
| 188 | + '<a href="\\1"\\2 target="_blank">', |
|
| 189 | + $contenu); |
|
| 190 | + |
|
| 191 | + // Correction typo dans la langue demandee |
|
| 192 | + #changer_typo($lang_aide); |
|
| 193 | + $contenu = '<body>' . $contenu . '</body>'; |
|
| 194 | + |
|
| 195 | + if (strlen($contenu) <= 100) return array(false, false); |
|
| 196 | + ecrire_fichier ($fichier_aide, $contenu); |
|
| 197 | + return array($contenu, time()); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | function generer_url_aide_img($args){ |
| 201 | - return generer_url_action('aide_img', $args, false, true); |
|
| 201 | + return generer_url_action('aide_img', $args, false, true); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | |
@@ -208,18 +208,18 @@ discard block |
||
| 208 | 208 | |
| 209 | 209 | // Remplacer les URL des images par l'URL du gestionnaire de cache local |
| 210 | 210 | function aide_fixe_img($contenu, $server){ |
| 211 | - $html = ""; |
|
| 212 | - $re = "@(<img([^<>]* +)?\s*src=['\"])((AIDE|IMG|local)/([-_a-zA-Z0-9]*/?)([^'\"<>]*))@imsS"; |
|
| 213 | - while (preg_match($re, $contenu, $r)) { |
|
| 214 | - $p = strpos($contenu, $r[0]); |
|
| 215 | - $i = $server . '/' . $r[3]; |
|
| 216 | - $html .= substr($contenu, 0, $p) . $r[1] . $i; |
|
| 217 | - $contenu = substr($contenu, $p + strlen($r[0])); |
|
| 218 | - } |
|
| 219 | - $html .= $contenu; |
|
| 220 | - |
|
| 221 | - // traiter les vieilles doc |
|
| 222 | - return preg_replace(_REPLACE_IMG_PACK,"\\1"._DIR_IMG_PACK, $html); |
|
| 211 | + $html = ""; |
|
| 212 | + $re = "@(<img([^<>]* +)?\s*src=['\"])((AIDE|IMG|local)/([-_a-zA-Z0-9]*/?)([^'\"<>]*))@imsS"; |
|
| 213 | + while (preg_match($re, $contenu, $r)) { |
|
| 214 | + $p = strpos($contenu, $r[0]); |
|
| 215 | + $i = $server . '/' . $r[3]; |
|
| 216 | + $html .= substr($contenu, 0, $p) . $r[1] . $i; |
|
| 217 | + $contenu = substr($contenu, $p + strlen($r[0])); |
|
| 218 | + } |
|
| 219 | + $html .= $contenu; |
|
| 220 | + |
|
| 221 | + // traiter les vieilles doc |
|
| 222 | + return preg_replace(_REPLACE_IMG_PACK,"\\1"._DIR_IMG_PACK, $html); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | |
@@ -228,14 +228,14 @@ discard block |
||
| 228 | 228 | // et se termine par la prochaine balise h2 ou h1 ou le /body final. |
| 229 | 229 | |
| 230 | 230 | function aide_section($aide, $contenu, $prof=2){ |
| 231 | - $maxprof = ($prof >=2) ? "12" : "1"; |
|
| 232 | - $r = "@<h$prof" . '(?: class="spip")?' . '>\s*' . $aide |
|
| 233 | - ."\s*(?:/.+?)?</h$prof>(.*?)<(?:(?:h[$maxprof])|/body)@ism"; |
|
| 231 | + $maxprof = ($prof >=2) ? "12" : "1"; |
|
| 232 | + $r = "@<h$prof" . '(?: class="spip")?' . '>\s*' . $aide |
|
| 233 | + ."\s*(?:/.+?)?</h$prof>(.*?)<(?:(?:h[$maxprof])|/body)@ism"; |
|
| 234 | 234 | |
| 235 | - if (preg_match($r, $contenu, $m)) |
|
| 236 | - return $m[1]; |
|
| 235 | + if (preg_match($r, $contenu, $m)) |
|
| 236 | + return $m[1]; |
|
| 237 | 237 | # spip_log("aide inconnue $r dans " . substr($contenu, 0, 150)); |
| 238 | - return ''; |
|
| 238 | + return ''; |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | |
@@ -16,10 +16,10 @@ |
||
| 16 | 16 | |
| 17 | 17 | // http://doc.spip.org/@inc_iconifier_dist |
| 18 | 18 | function inc_iconifier_dist($objet, $id, $script, $visible=false, $flag_modif=true) { |
| 19 | - // compat avec anciens appels |
|
| 20 | - $objet = objet_type($objet); |
|
| 19 | + // compat avec anciens appels |
|
| 20 | + $objet = objet_type($objet); |
|
| 21 | 21 | |
| 22 | - return recuperer_fond('prive/objets/editer/logo',array('objet'=>$objet,'id_objet'=>$id,'editable'=>$flag_modif)); |
|
| 22 | + return recuperer_fond('prive/objets/editer/logo',array('objet'=>$objet,'id_objet'=>$id,'editable'=>$flag_modif)); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | ?> |
@@ -25,27 +25,27 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | // http://doc.spip.org/@filtre_text_txt_dist |
| 27 | 27 | function filtre_text_dist($t) { |
| 28 | - static $t1 = array('&', '<', '>'); |
|
| 29 | - static $t2 = array('&', '<', '>'); |
|
| 30 | - return '<pre>' . str_replace($t1, $t2, $t) . '</pre>'; |
|
| 28 | + static $t1 = array('&', '<', '>'); |
|
| 29 | + static $t2 = array('&', '<', '>'); |
|
| 30 | + return '<pre>' . str_replace($t1, $t2, $t) . '</pre>'; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | // http://doc.spip.org/@filtre_text_csv_dist |
| 34 | 34 | function filtre_text_csv_dist($t) { |
| 35 | - include_spip('inc/csv'); |
|
| 36 | - list($entete, $lignes) = analyse_csv($t); |
|
| 37 | - foreach ($lignes as &$l) |
|
| 38 | - $l = join('|', $l); |
|
| 39 | - $corps = join("\n", $lignes) . "\n"; |
|
| 40 | - $corps = $caption . |
|
| 41 | - "\n|{{" . |
|
| 42 | - join('}}|{{',$entete) . |
|
| 43 | - "}}|" . |
|
| 44 | - "\n|" . |
|
| 45 | - str_replace("\n", "|\n|",$corps); |
|
| 46 | - $corps = str_replace('"#','"',$corps); |
|
| 47 | - include_spip('inc/texte'); |
|
| 48 | - return propre($corps); |
|
| 35 | + include_spip('inc/csv'); |
|
| 36 | + list($entete, $lignes) = analyse_csv($t); |
|
| 37 | + foreach ($lignes as &$l) |
|
| 38 | + $l = join('|', $l); |
|
| 39 | + $corps = join("\n", $lignes) . "\n"; |
|
| 40 | + $corps = $caption . |
|
| 41 | + "\n|{{" . |
|
| 42 | + join('}}|{{',$entete) . |
|
| 43 | + "}}|" . |
|
| 44 | + "\n|" . |
|
| 45 | + str_replace("\n", "|\n|",$corps); |
|
| 46 | + $corps = str_replace('"#','"',$corps); |
|
| 47 | + include_spip('inc/texte'); |
|
| 48 | + return propre($corps); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | // Incrustation de HTML, si on est capable de le securiser |
@@ -53,33 +53,33 @@ discard block |
||
| 53 | 53 | // http://doc.spip.org/@filtre_text_html_dist |
| 54 | 54 | function filtre_text_html_dist($t) |
| 55 | 55 | { |
| 56 | - if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) |
|
| 57 | - return appliquer_filtre($t,'text/plain'); |
|
| 56 | + if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) |
|
| 57 | + return appliquer_filtre($t,'text/plain'); |
|
| 58 | 58 | |
| 59 | - list(,$h,$t) = $r; |
|
| 59 | + list(,$h,$t) = $r; |
|
| 60 | 60 | |
| 61 | - $style = ''; |
|
| 62 | - // recuperer les styles internes |
|
| 63 | - if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) |
|
| 64 | - $style = join("\n",$r[1]); |
|
| 65 | - // ... et externes |
|
| 61 | + $style = ''; |
|
| 62 | + // recuperer les styles internes |
|
| 63 | + if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) |
|
| 64 | + $style = join("\n",$r[1]); |
|
| 65 | + // ... et externes |
|
| 66 | 66 | |
| 67 | - include_spip('inc/distant'); |
|
| 68 | - if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) |
|
| 69 | - foreach($r[0] as $l) { |
|
| 70 | - preg_match("/href='([^']*)'/", str_replace('"',"'",$l), $m); |
|
| 71 | - $style .= "\n/* $l */\n" |
|
| 72 | - . str_replace('<','',recuperer_page($m[1])); |
|
| 73 | - } |
|
| 74 | - // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 75 | - $t = safehtml(preg_replace(',<script'.'.*?</script>,is','',$t)); |
|
| 76 | - return (!$style ? '' : "\n<style>".$style."</style>") . $t; |
|
| 67 | + include_spip('inc/distant'); |
|
| 68 | + if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) |
|
| 69 | + foreach($r[0] as $l) { |
|
| 70 | + preg_match("/href='([^']*)'/", str_replace('"',"'",$l), $m); |
|
| 71 | + $style .= "\n/* $l */\n" |
|
| 72 | + . str_replace('<','',recuperer_page($m[1])); |
|
| 73 | + } |
|
| 74 | + // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 75 | + $t = safehtml(preg_replace(',<script'.'.*?</script>,is','',$t)); |
|
| 76 | + return (!$style ? '' : "\n<style>".$style."</style>") . $t; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | // http://doc.spip.org/@filtre_audio_x_pn_realaudio |
| 80 | 80 | function filtre_audio_x_pn_realaudio($id) |
| 81 | 81 | { |
| 82 | - return " |
|
| 82 | + return " |
|
| 83 | 83 | <param name='controls' value='PositionSlider' /> |
| 84 | 84 | <param name='controls' value='ImageWindow' /> |
| 85 | 85 | <param name='controls' value='PlayButton' /> |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | * @return string |
| 28 | 28 | */ |
| 29 | 29 | function charger_filtre($fonc, $default='filtre_identite_dist') { |
| 30 | - include_spip('public/parametrer'); // inclure les fichiers fonctions |
|
| 31 | - return chercher_filtre($fonc, $default); |
|
| 30 | + include_spip('public/parametrer'); // inclure les fichiers fonctions |
|
| 31 | + return chercher_filtre($fonc, $default); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | function filtre_identite_dist($texte){return $texte;} |
@@ -41,31 +41,31 @@ discard block |
||
| 41 | 41 | * @return string |
| 42 | 42 | */ |
| 43 | 43 | function chercher_filtre($fonc, $default=NULL) { |
| 44 | - if (!$fonc) return $default; |
|
| 45 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 46 | - // Foo::Bar |
|
| 47 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 48 | - if (preg_match(',^[\w]+/,',$fonc)){ |
|
| 49 | - $nom = preg_replace(',\W,','_', $fonc); |
|
| 50 | - $f = chercher_filtre($nom); |
|
| 51 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 52 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 53 | - if (!$f AND $nom!==$fonc) |
|
| 54 | - $f = chercher_filtre(preg_replace(',\W.*$,','', $fonc)); |
|
| 55 | - return $f; |
|
| 56 | - } |
|
| 57 | - foreach ( |
|
| 58 | - array('filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc) as $f){ |
|
| 59 | - if (isset( $GLOBALS['spip_matrice'][$f]) AND is_string($g = $GLOBALS['spip_matrice'][$f])) |
|
| 60 | - find_in_path($g,'', true); |
|
| 61 | - if (function_exists($f) |
|
| 62 | - OR (preg_match("/^(\w*)::(\w*)$/", $f, $regs) |
|
| 63 | - AND is_callable(array($regs[1], $regs[2])) |
|
| 64 | - )) { |
|
| 65 | - return $f; |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - return $default; |
|
| 44 | + if (!$fonc) return $default; |
|
| 45 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 46 | + // Foo::Bar |
|
| 47 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 48 | + if (preg_match(',^[\w]+/,',$fonc)){ |
|
| 49 | + $nom = preg_replace(',\W,','_', $fonc); |
|
| 50 | + $f = chercher_filtre($nom); |
|
| 51 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 52 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 53 | + if (!$f AND $nom!==$fonc) |
|
| 54 | + $f = chercher_filtre(preg_replace(',\W.*$,','', $fonc)); |
|
| 55 | + return $f; |
|
| 56 | + } |
|
| 57 | + foreach ( |
|
| 58 | + array('filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc) as $f){ |
|
| 59 | + if (isset( $GLOBALS['spip_matrice'][$f]) AND is_string($g = $GLOBALS['spip_matrice'][$f])) |
|
| 60 | + find_in_path($g,'', true); |
|
| 61 | + if (function_exists($f) |
|
| 62 | + OR (preg_match("/^(\w*)::(\w*)$/", $f, $regs) |
|
| 63 | + AND is_callable(array($regs[1], $regs[2])) |
|
| 64 | + )) { |
|
| 65 | + return $f; |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + return $default; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -90,25 +90,25 @@ discard block |
||
| 90 | 90 | * Chaîne vide si le filtre n'a pas été trouvé et que $force a été fourni. |
| 91 | 91 | **/ |
| 92 | 92 | function appliquer_filtre($arg, $filtre, $force=NULL) { |
| 93 | - $f = chercher_filtre($filtre); |
|
| 94 | - if (!$f) { |
|
| 95 | - if (!$force) return ''; |
|
| 96 | - else return $arg; |
|
| 97 | - } |
|
| 93 | + $f = chercher_filtre($filtre); |
|
| 94 | + if (!$f) { |
|
| 95 | + if (!$force) return ''; |
|
| 96 | + else return $arg; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - $args = func_get_args(); |
|
| 100 | - array_shift($args); // enlever $arg |
|
| 101 | - array_shift($args); // enlever $filtre |
|
| 102 | - array_unshift($args, $arg); // remettre $arg |
|
| 103 | - return call_user_func_array($f,$args); |
|
| 99 | + $args = func_get_args(); |
|
| 100 | + array_shift($args); // enlever $arg |
|
| 101 | + array_shift($args); // enlever $filtre |
|
| 102 | + array_unshift($args, $arg); // remettre $arg |
|
| 103 | + return call_user_func_array($f,$args); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // http://doc.spip.org/@spip_version |
| 107 | 107 | function spip_version() { |
| 108 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 109 | - if ($svn_revision = version_svn_courante(_DIR_RACINE)) |
|
| 110 | - $version .= ($svn_revision<0 ? ' SVN':'').' ['.abs($svn_revision).']'; |
|
| 111 | - return $version; |
|
| 108 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 109 | + if ($svn_revision = version_svn_courante(_DIR_RACINE)) |
|
| 110 | + $version .= ($svn_revision<0 ? ' SVN':'').' ['.abs($svn_revision).']'; |
|
| 111 | + return $version; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | |
@@ -118,28 +118,28 @@ discard block |
||
| 118 | 118 | // on est negatif si on est sur .svn, et positif si on utilise svn.revision |
| 119 | 119 | // http://doc.spip.org/@version_svn_courante |
| 120 | 120 | function version_svn_courante($dir) { |
| 121 | - if (!$dir) $dir = '.'; |
|
| 122 | - |
|
| 123 | - // version installee par paquet ZIP |
|
| 124 | - if (lire_fichier($dir.'/svn.revision', $c) |
|
| 125 | - AND preg_match(',Revision: (\d+),', $c, $d)) |
|
| 126 | - return intval($d[1]); |
|
| 127 | - |
|
| 128 | - // version installee par SVN |
|
| 129 | - if (lire_fichier($dir . '/.svn/entries', $c) |
|
| 130 | - AND ( |
|
| 131 | - (preg_match_all( |
|
| 132 | - ',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER) |
|
| 133 | - AND $v = max($r1[1]) |
|
| 134 | - ) |
|
| 135 | - OR |
|
| 136 | - (preg_match(',^\d.*dir[\r\n]+(\d+),ms', $c, $r1) # svn >= 1.4 |
|
| 137 | - AND $v = $r1[1] |
|
| 138 | - ))) |
|
| 139 | - return -$v; |
|
| 140 | - |
|
| 141 | - // Bug ou paquet fait main |
|
| 142 | - return 0; |
|
| 121 | + if (!$dir) $dir = '.'; |
|
| 122 | + |
|
| 123 | + // version installee par paquet ZIP |
|
| 124 | + if (lire_fichier($dir.'/svn.revision', $c) |
|
| 125 | + AND preg_match(',Revision: (\d+),', $c, $d)) |
|
| 126 | + return intval($d[1]); |
|
| 127 | + |
|
| 128 | + // version installee par SVN |
|
| 129 | + if (lire_fichier($dir . '/.svn/entries', $c) |
|
| 130 | + AND ( |
|
| 131 | + (preg_match_all( |
|
| 132 | + ',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER) |
|
| 133 | + AND $v = max($r1[1]) |
|
| 134 | + ) |
|
| 135 | + OR |
|
| 136 | + (preg_match(',^\d.*dir[\r\n]+(\d+),ms', $c, $r1) # svn >= 1.4 |
|
| 137 | + AND $v = $r1[1] |
|
| 138 | + ))) |
|
| 139 | + return -$v; |
|
| 140 | + |
|
| 141 | + // Bug ou paquet fait main |
|
| 142 | + return 0; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -170,23 +170,23 @@ discard block |
||
| 170 | 170 | // charge les fonctions graphiques et applique celle demandee |
| 171 | 171 | // http://doc.spip.org/@filtrer |
| 172 | 172 | function filtrer($filtre) { |
| 173 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])){ |
|
| 174 | - find_in_path($f,'', true); |
|
| 175 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 176 | - } |
|
| 177 | - $tous = func_get_args(); |
|
| 178 | - if (substr($filtre,0,6)=='image_' && $GLOBALS['spip_matrice'][$filtre]) |
|
| 179 | - return image_filtrer($tous); |
|
| 180 | - elseif($f = chercher_filtre($filtre)) { |
|
| 181 | - array_shift($tous); |
|
| 182 | - return call_user_func_array($f, $tous); |
|
| 183 | - } |
|
| 184 | - else { |
|
| 185 | - // le filtre n'existe pas, on provoque une erreur |
|
| 186 | - $msg = array('zbug_erreur_filtre', array('filtre'=>texte_script($filtre))); |
|
| 187 | - erreur_squelette($msg); |
|
| 188 | - return ''; |
|
| 189 | - } |
|
| 173 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])){ |
|
| 174 | + find_in_path($f,'', true); |
|
| 175 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 176 | + } |
|
| 177 | + $tous = func_get_args(); |
|
| 178 | + if (substr($filtre,0,6)=='image_' && $GLOBALS['spip_matrice'][$filtre]) |
|
| 179 | + return image_filtrer($tous); |
|
| 180 | + elseif($f = chercher_filtre($filtre)) { |
|
| 181 | + array_shift($tous); |
|
| 182 | + return call_user_func_array($f, $tous); |
|
| 183 | + } |
|
| 184 | + else { |
|
| 185 | + // le filtre n'existe pas, on provoque une erreur |
|
| 186 | + $msg = array('zbug_erreur_filtre', array('filtre'=>texte_script($filtre))); |
|
| 187 | + erreur_squelette($msg); |
|
| 188 | + return ''; |
|
| 189 | + } |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /* |
@@ -199,8 +199,8 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | */ |
| 201 | 201 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 202 | - $Pile['vars'][$key] = $val; |
|
| 203 | - return $continue ? $val : ''; |
|
| 202 | + $Pile['vars'][$key] = $val; |
|
| 203 | + return $continue ? $val : ''; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /* |
@@ -208,17 +208,17 @@ discard block |
||
| 208 | 208 | * la valeur de #TRUC avant et après le calcul |
| 209 | 209 | */ |
| 210 | 210 | function filtre_debug($val, $key=null) { |
| 211 | - $debug = ( |
|
| 212 | - is_null($key) ? '' : (var_export($key,true)." = ") |
|
| 213 | - ) . var_export($val, true); |
|
| 211 | + $debug = ( |
|
| 212 | + is_null($key) ? '' : (var_export($key,true)." = ") |
|
| 213 | + ) . var_export($val, true); |
|
| 214 | 214 | |
| 215 | - include_spip('inc/autoriser'); |
|
| 216 | - if (autoriser('webmestre')) |
|
| 217 | - echo "<div class='spip_debug'>\n",$debug,"</div>\n"; |
|
| 215 | + include_spip('inc/autoriser'); |
|
| 216 | + if (autoriser('webmestre')) |
|
| 217 | + echo "<div class='spip_debug'>\n",$debug,"</div>\n"; |
|
| 218 | 218 | |
| 219 | - spip_log($debug, 'debug'); |
|
| 219 | + spip_log($debug, 'debug'); |
|
| 220 | 220 | |
| 221 | - return $val; |
|
| 221 | + return $val; |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | |
@@ -230,63 +230,63 @@ discard block |
||
| 230 | 230 | |
| 231 | 231 | // http://doc.spip.org/@image_filtrer |
| 232 | 232 | function image_filtrer($args){ |
| 233 | - $filtre = array_shift($args); # enlever $filtre |
|
| 234 | - $texte = array_shift($args); |
|
| 235 | - if (!strlen($texte)) return; |
|
| 236 | - find_in_path('filtres_images_mini.php','inc/', true); |
|
| 237 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 238 | - // Cas du nom de fichier local |
|
| 239 | - if ( strpos(substr($texte,strlen(_DIR_RACINE)),'..')===FALSE |
|
| 240 | - AND !preg_match(',^/|[<>]|\s,S', $texte) |
|
| 241 | - AND ( |
|
| 242 | - file_exists(preg_replace(',[?].*$,','',$texte)) |
|
| 243 | - OR preg_match(';^(\w{3,7}://);', $texte) |
|
| 244 | - )) { |
|
| 245 | - array_unshift($args,"<img src='$texte' />"); |
|
| 246 | - $res = call_user_func_array($filtre, $args); |
|
| 247 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 248 | - return $res; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 252 | - if (preg_match_all( |
|
| 253 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 254 | - $texte, $tags, PREG_SET_ORDER)) { |
|
| 255 | - foreach ($tags as $tag) { |
|
| 256 | - $class = extraire_attribut($tag[3],'class'); |
|
| 257 | - if (!$class || (strpos($class,'no_image_filtrer')===FALSE)){ |
|
| 258 | - array_unshift($args,$tag[3]); |
|
| 259 | - if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 260 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 261 | - if($tag[1]){ |
|
| 262 | - $w = extraire_attribut($reduit, 'width'); |
|
| 263 | - if (!$w AND preg_match(",width:\s*(\d+)px,S",extraire_attribut($reduit,'style'),$regs)) |
|
| 264 | - $w = $regs[1]; |
|
| 265 | - if ($w AND ($style = extraire_attribut($tag[1], 'style'))){ |
|
| 266 | - $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style); |
|
| 267 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 268 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - // traiter aussi un eventuel mouseover |
|
| 272 | - if ($mouseover = extraire_attribut($reduit,'onmouseover')){ |
|
| 273 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)){ |
|
| 274 | - $srcover = $match[1]; |
|
| 275 | - array_shift($args); |
|
| 276 | - array_unshift($args,"<img src='".$match[1]."' />"); |
|
| 277 | - $srcover_filter = call_user_func_array($filtre, $args); |
|
| 278 | - $srcover_filter = extraire_attribut($srcover_filter,'src'); |
|
| 279 | - $reduit = str_replace($srcover,$srcover_filter,$reduit); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 283 | - } |
|
| 284 | - array_shift($args); |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 289 | - return $texte; |
|
| 233 | + $filtre = array_shift($args); # enlever $filtre |
|
| 234 | + $texte = array_shift($args); |
|
| 235 | + if (!strlen($texte)) return; |
|
| 236 | + find_in_path('filtres_images_mini.php','inc/', true); |
|
| 237 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 238 | + // Cas du nom de fichier local |
|
| 239 | + if ( strpos(substr($texte,strlen(_DIR_RACINE)),'..')===FALSE |
|
| 240 | + AND !preg_match(',^/|[<>]|\s,S', $texte) |
|
| 241 | + AND ( |
|
| 242 | + file_exists(preg_replace(',[?].*$,','',$texte)) |
|
| 243 | + OR preg_match(';^(\w{3,7}://);', $texte) |
|
| 244 | + )) { |
|
| 245 | + array_unshift($args,"<img src='$texte' />"); |
|
| 246 | + $res = call_user_func_array($filtre, $args); |
|
| 247 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 248 | + return $res; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 252 | + if (preg_match_all( |
|
| 253 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 254 | + $texte, $tags, PREG_SET_ORDER)) { |
|
| 255 | + foreach ($tags as $tag) { |
|
| 256 | + $class = extraire_attribut($tag[3],'class'); |
|
| 257 | + if (!$class || (strpos($class,'no_image_filtrer')===FALSE)){ |
|
| 258 | + array_unshift($args,$tag[3]); |
|
| 259 | + if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 260 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 261 | + if($tag[1]){ |
|
| 262 | + $w = extraire_attribut($reduit, 'width'); |
|
| 263 | + if (!$w AND preg_match(",width:\s*(\d+)px,S",extraire_attribut($reduit,'style'),$regs)) |
|
| 264 | + $w = $regs[1]; |
|
| 265 | + if ($w AND ($style = extraire_attribut($tag[1], 'style'))){ |
|
| 266 | + $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style); |
|
| 267 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 268 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + // traiter aussi un eventuel mouseover |
|
| 272 | + if ($mouseover = extraire_attribut($reduit,'onmouseover')){ |
|
| 273 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)){ |
|
| 274 | + $srcover = $match[1]; |
|
| 275 | + array_shift($args); |
|
| 276 | + array_unshift($args,"<img src='".$match[1]."' />"); |
|
| 277 | + $srcover_filter = call_user_func_array($filtre, $args); |
|
| 278 | + $srcover_filter = extraire_attribut($srcover_filter,'src'); |
|
| 279 | + $reduit = str_replace($srcover,$srcover_filter,$reduit); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 283 | + } |
|
| 284 | + array_shift($args); |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 289 | + return $texte; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | // |
@@ -296,61 +296,61 @@ discard block |
||
| 296 | 296 | // http://doc.spip.org/@taille_image |
| 297 | 297 | function taille_image($img) { |
| 298 | 298 | |
| 299 | - static $largeur_img =array(), $hauteur_img= array(); |
|
| 300 | - $srcWidth = 0; |
|
| 301 | - $srcHeight = 0; |
|
| 302 | - |
|
| 303 | - $logo = extraire_attribut($img,'src'); |
|
| 304 | - |
|
| 305 | - if (!$logo) $logo = $img; |
|
| 306 | - else { |
|
| 307 | - $srcWidth = extraire_attribut($img,'width'); |
|
| 308 | - $srcHeight = extraire_attribut($img,'height'); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 312 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 313 | - if (preg_match(';^(\w{3,7}://);', $logo)){ |
|
| 314 | - include_spip('inc/distant'); |
|
| 315 | - $fichier = copie_locale($logo); |
|
| 316 | - $logo = $fichier ? _DIR_RACINE . $fichier : $logo; |
|
| 317 | - } |
|
| 318 | - if (($p=strpos($logo,'?'))!==FALSE) |
|
| 319 | - $logo=substr($logo,0,$p); |
|
| 320 | - |
|
| 321 | - $srcsize = false; |
|
| 322 | - if (isset($largeur_img[$logo])) |
|
| 323 | - $srcWidth = $largeur_img[$logo]; |
|
| 324 | - if (isset($hauteur_img[$logo])) |
|
| 325 | - $srcHeight = $hauteur_img[$logo]; |
|
| 326 | - if (!$srcWidth OR !$srcHeight){ |
|
| 327 | - if (file_exists($logo) |
|
| 328 | - AND $srcsize = @getimagesize($logo)){ |
|
| 329 | - if (!$srcWidth) $largeur_img[$logo] = $srcWidth = $srcsize[0]; |
|
| 330 | - if (!$srcHeight) $hauteur_img[$logo] = $srcHeight = $srcsize[1]; |
|
| 331 | - } |
|
| 332 | - // $logo peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 333 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 334 | - elseif(@file_exists($f = "$logo.src") |
|
| 335 | - AND lire_fichier($f,$valeurs) |
|
| 336 | - AND $valeurs=unserialize($valeurs)) { |
|
| 337 | - if (!$srcWidth) $largeur_img[$logo] = $srcWidth = $valeurs["largeur_dest"]; |
|
| 338 | - if (!$srcHeight) $hauteur_img[$logo] = $srcHeight = $valeurs["hauteur_dest"]; |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - return array($srcHeight, $srcWidth); |
|
| 299 | + static $largeur_img =array(), $hauteur_img= array(); |
|
| 300 | + $srcWidth = 0; |
|
| 301 | + $srcHeight = 0; |
|
| 302 | + |
|
| 303 | + $logo = extraire_attribut($img,'src'); |
|
| 304 | + |
|
| 305 | + if (!$logo) $logo = $img; |
|
| 306 | + else { |
|
| 307 | + $srcWidth = extraire_attribut($img,'width'); |
|
| 308 | + $srcHeight = extraire_attribut($img,'height'); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 312 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 313 | + if (preg_match(';^(\w{3,7}://);', $logo)){ |
|
| 314 | + include_spip('inc/distant'); |
|
| 315 | + $fichier = copie_locale($logo); |
|
| 316 | + $logo = $fichier ? _DIR_RACINE . $fichier : $logo; |
|
| 317 | + } |
|
| 318 | + if (($p=strpos($logo,'?'))!==FALSE) |
|
| 319 | + $logo=substr($logo,0,$p); |
|
| 320 | + |
|
| 321 | + $srcsize = false; |
|
| 322 | + if (isset($largeur_img[$logo])) |
|
| 323 | + $srcWidth = $largeur_img[$logo]; |
|
| 324 | + if (isset($hauteur_img[$logo])) |
|
| 325 | + $srcHeight = $hauteur_img[$logo]; |
|
| 326 | + if (!$srcWidth OR !$srcHeight){ |
|
| 327 | + if (file_exists($logo) |
|
| 328 | + AND $srcsize = @getimagesize($logo)){ |
|
| 329 | + if (!$srcWidth) $largeur_img[$logo] = $srcWidth = $srcsize[0]; |
|
| 330 | + if (!$srcHeight) $hauteur_img[$logo] = $srcHeight = $srcsize[1]; |
|
| 331 | + } |
|
| 332 | + // $logo peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 333 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 334 | + elseif(@file_exists($f = "$logo.src") |
|
| 335 | + AND lire_fichier($f,$valeurs) |
|
| 336 | + AND $valeurs=unserialize($valeurs)) { |
|
| 337 | + if (!$srcWidth) $largeur_img[$logo] = $srcWidth = $valeurs["largeur_dest"]; |
|
| 338 | + if (!$srcHeight) $hauteur_img[$logo] = $srcHeight = $valeurs["hauteur_dest"]; |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + return array($srcHeight, $srcWidth); |
|
| 342 | 342 | } |
| 343 | 343 | // http://doc.spip.org/@largeur |
| 344 | 344 | function largeur($img) { |
| 345 | - if (!$img) return; |
|
| 346 | - list ($h,$l) = taille_image($img); |
|
| 347 | - return $l; |
|
| 345 | + if (!$img) return; |
|
| 346 | + list ($h,$l) = taille_image($img); |
|
| 347 | + return $l; |
|
| 348 | 348 | } |
| 349 | 349 | // http://doc.spip.org/@hauteur |
| 350 | 350 | function hauteur($img) { |
| 351 | - if (!$img) return; |
|
| 352 | - list ($h,$l) = taille_image($img); |
|
| 353 | - return $h; |
|
| 351 | + if (!$img) return; |
|
| 352 | + list ($h,$l) = taille_image($img); |
|
| 353 | + return $h; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | |
@@ -364,19 +364,19 @@ discard block |
||
| 364 | 364 | // et au cas particulier de & qui devient &amp; dans les url |
| 365 | 365 | // http://doc.spip.org/@corriger_entites_html |
| 366 | 366 | function corriger_entites_html($texte) { |
| 367 | - if (strpos($texte,'&') === false) return $texte; |
|
| 368 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 367 | + if (strpos($texte,'&') === false) return $texte; |
|
| 368 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 369 | 369 | } |
| 370 | 370 | // idem mais corriger aussi les &eacute; en é |
| 371 | 371 | // http://doc.spip.org/@corriger_toutes_entites_html |
| 372 | 372 | function corriger_toutes_entites_html($texte) { |
| 373 | - if (strpos($texte,'&') === false) return $texte; |
|
| 374 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 373 | + if (strpos($texte,'&') === false) return $texte; |
|
| 374 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | // http://doc.spip.org/@proteger_amp |
| 378 | 378 | function proteger_amp($texte){ |
| 379 | - return str_replace('&','&',$texte); |
|
| 379 | + return str_replace('&','&',$texte); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | // |
@@ -392,31 +392,31 @@ discard block |
||
| 392 | 392 | * @return mixed|string |
| 393 | 393 | */ |
| 394 | 394 | function entites_html($texte, $tout=false, $quote=true) { |
| 395 | - if (!is_string($texte) OR !$texte |
|
| 396 | - OR strpbrk($texte, "&\"'<>")==false |
|
| 397 | - ) return $texte; |
|
| 398 | - include_spip('inc/texte'); |
|
| 399 | - $flags = !defined('PHP_VERSION_ID') OR PHP_VERSION_ID < 50400 ? ENT_COMPAT : ENT_COMPAT|ENT_HTML401; |
|
| 400 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $quote?ENT_QUOTES:$flags); |
|
| 401 | - if ($tout) |
|
| 402 | - return corriger_toutes_entites_html($texte); |
|
| 403 | - else |
|
| 404 | - return corriger_entites_html($texte); |
|
| 395 | + if (!is_string($texte) OR !$texte |
|
| 396 | + OR strpbrk($texte, "&\"'<>")==false |
|
| 397 | + ) return $texte; |
|
| 398 | + include_spip('inc/texte'); |
|
| 399 | + $flags = !defined('PHP_VERSION_ID') OR PHP_VERSION_ID < 50400 ? ENT_COMPAT : ENT_COMPAT|ENT_HTML401; |
|
| 400 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $quote?ENT_QUOTES:$flags); |
|
| 401 | + if ($tout) |
|
| 402 | + return corriger_toutes_entites_html($texte); |
|
| 403 | + else |
|
| 404 | + return corriger_entites_html($texte); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | // Transformer les é dans le charset local |
| 408 | 408 | // http://doc.spip.org/@filtrer_entites |
| 409 | 409 | function filtrer_entites($texte) { |
| 410 | - if (strpos($texte,'&') === false) return $texte; |
|
| 411 | - // filtrer |
|
| 412 | - $texte = html2unicode($texte); |
|
| 413 | - // remettre le tout dans le charset cible |
|
| 414 | - $texte = unicode2charset($texte); |
|
| 415 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 416 | - // (on le faisait deja avec un ") |
|
| 417 | - if (strpos($texte,"&#")!==false) |
|
| 418 | - $texte = str_replace(array("'","'",""","""), array("'","'",'"','"'), $texte); |
|
| 419 | - return $texte; |
|
| 410 | + if (strpos($texte,'&') === false) return $texte; |
|
| 411 | + // filtrer |
|
| 412 | + $texte = html2unicode($texte); |
|
| 413 | + // remettre le tout dans le charset cible |
|
| 414 | + $texte = unicode2charset($texte); |
|
| 415 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 416 | + // (on le faisait deja avec un ") |
|
| 417 | + if (strpos($texte,"&#")!==false) |
|
| 418 | + $texte = str_replace(array("'","'",""","""), array("'","'",'"','"'), $texte); |
|
| 419 | + return $texte; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -425,33 +425,33 @@ discard block |
||
| 425 | 425 | * @return string |
| 426 | 426 | */ |
| 427 | 427 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 428 | - function filtre_filtrer_entites_dist($t) { |
|
| 429 | - include_spip('inc/texte'); |
|
| 430 | - return interdire_scripts(filtrer_entites($t)); |
|
| 431 | - } |
|
| 428 | + function filtre_filtrer_entites_dist($t) { |
|
| 429 | + include_spip('inc/texte'); |
|
| 430 | + return interdire_scripts(filtrer_entites($t)); |
|
| 431 | + } |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | |
| 435 | 435 | // caracteres de controle - http://www.w3.org/TR/REC-xml/#charsets |
| 436 | 436 | // http://doc.spip.org/@supprimer_caracteres_illegaux |
| 437 | 437 | function supprimer_caracteres_illegaux($texte) { |
| 438 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 439 | - static $to = null; |
|
| 438 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 439 | + static $to = null; |
|
| 440 | 440 | |
| 441 | - if (is_array($texte)) { |
|
| 442 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 443 | - } |
|
| 441 | + if (is_array($texte)) { |
|
| 442 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 443 | + } |
|
| 444 | 444 | |
| 445 | - if (!$to) $to = str_repeat('-', strlen($from)); |
|
| 446 | - return strtr($texte, $from, $to); |
|
| 445 | + if (!$to) $to = str_repeat('-', strlen($from)); |
|
| 446 | + return strtr($texte, $from, $to); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | // Supprimer caracteres windows et les caracteres de controle ILLEGAUX |
| 450 | 450 | // http://doc.spip.org/@corriger_caracteres |
| 451 | 451 | function corriger_caracteres ($texte) { |
| 452 | - $texte = corriger_caracteres_windows($texte); |
|
| 453 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 454 | - return $texte; |
|
| 452 | + $texte = corriger_caracteres_windows($texte); |
|
| 453 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 454 | + return $texte; |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | /** |
@@ -465,105 +465,105 @@ discard block |
||
| 465 | 465 | */ |
| 466 | 466 | function texte_backend($texte) { |
| 467 | 467 | |
| 468 | - static $apostrophe = array("’", "'"); # n'allouer qu'une fois |
|
| 468 | + static $apostrophe = array("’", "'"); # n'allouer qu'une fois |
|
| 469 | 469 | |
| 470 | - // si on a des liens ou des images, les passer en absolu |
|
| 471 | - $texte = liens_absolus($texte); |
|
| 470 | + // si on a des liens ou des images, les passer en absolu |
|
| 471 | + $texte = liens_absolus($texte); |
|
| 472 | 472 | |
| 473 | - // echapper les tags > < |
|
| 474 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 473 | + // echapper les tags > < |
|
| 474 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 475 | 475 | |
| 476 | - // importer les é |
|
| 477 | - $texte = filtrer_entites($texte); |
|
| 476 | + // importer les é |
|
| 477 | + $texte = filtrer_entites($texte); |
|
| 478 | 478 | |
| 479 | - // " -> " et tout ce genre de choses |
|
| 480 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 481 | - $texte = str_replace(" ", " ", $texte); |
|
| 482 | - $texte = preg_replace('/\s{2,}/S'.$u, " ", $texte); |
|
| 483 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 484 | - $texte = entites_html($texte, false, false); |
|
| 485 | - // mais bien echapper les double quotes ! |
|
| 486 | - $texte = str_replace('"','"',$texte); |
|
| 479 | + // " -> " et tout ce genre de choses |
|
| 480 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 481 | + $texte = str_replace(" ", " ", $texte); |
|
| 482 | + $texte = preg_replace('/\s{2,}/S'.$u, " ", $texte); |
|
| 483 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 484 | + $texte = entites_html($texte, false, false); |
|
| 485 | + // mais bien echapper les double quotes ! |
|
| 486 | + $texte = str_replace('"','"',$texte); |
|
| 487 | 487 | |
| 488 | - // verifier le charset |
|
| 489 | - $texte = charset2unicode($texte); |
|
| 488 | + // verifier le charset |
|
| 489 | + $texte = charset2unicode($texte); |
|
| 490 | 490 | |
| 491 | - // Caracteres problematiques en iso-latin 1 |
|
| 492 | - if ($GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 493 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 494 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 495 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 496 | - } |
|
| 491 | + // Caracteres problematiques en iso-latin 1 |
|
| 492 | + if ($GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 493 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 494 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 495 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 496 | + } |
|
| 497 | 497 | |
| 498 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 499 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 500 | - // ==> on les remplace par l'entite HTML |
|
| 501 | - return str_replace($apostrophe, "'", $texte); |
|
| 498 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 499 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 500 | + // ==> on les remplace par l'entite HTML |
|
| 501 | + return str_replace($apostrophe, "'", $texte); |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | // Comme ci-dessus, mais avec addslashes final pour squelettes avec PHP (rss) |
| 505 | 505 | |
| 506 | 506 | function texte_backendq($texte) { |
| 507 | - return addslashes(texte_backend($texte)); |
|
| 507 | + return addslashes(texte_backend($texte)); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | // Enleve le numero des titres numerotes ("1. Titre" -> "Titre") |
| 511 | 511 | // http://doc.spip.org/@supprimer_numero |
| 512 | 512 | function supprimer_numero($texte) { |
| 513 | - return preg_replace( |
|
| 514 | - ",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S", |
|
| 515 | - "", $texte); |
|
| 513 | + return preg_replace( |
|
| 514 | + ",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S", |
|
| 515 | + "", $texte); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | // et la fonction inverse |
| 519 | 519 | // http://doc.spip.org/@recuperer_numero |
| 520 | 520 | function recuperer_numero($texte) { |
| 521 | - if (preg_match( |
|
| 522 | - ",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S", |
|
| 523 | - $texte, $regs)) |
|
| 524 | - return strval($regs[1]); |
|
| 525 | - else |
|
| 526 | - return ''; |
|
| 521 | + if (preg_match( |
|
| 522 | + ",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S", |
|
| 523 | + $texte, $regs)) |
|
| 524 | + return strval($regs[1]); |
|
| 525 | + else |
|
| 526 | + return ''; |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | // Suppression basique et brutale de tous les <...> |
| 530 | 530 | // http://doc.spip.org/@supprimer_tags |
| 531 | 531 | function supprimer_tags($texte, $rempl = "") { |
| 532 | - $texte = preg_replace(",<[^>]*>,US", $rempl, $texte); |
|
| 533 | - // ne pas oublier un < final non ferme |
|
| 534 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 535 | - $texte = str_replace('<', ' ', $texte); |
|
| 536 | - return $texte; |
|
| 532 | + $texte = preg_replace(",<[^>]*>,US", $rempl, $texte); |
|
| 533 | + // ne pas oublier un < final non ferme |
|
| 534 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 535 | + $texte = str_replace('<', ' ', $texte); |
|
| 536 | + return $texte; |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | // Convertit les <...> en la version lisible en HTML |
| 540 | 540 | // http://doc.spip.org/@echapper_tags |
| 541 | 541 | function echapper_tags($texte, $rempl = "") { |
| 542 | - $texte = preg_replace("/<([^>]*)>/", "<\\1>", $texte); |
|
| 543 | - return $texte; |
|
| 542 | + $texte = preg_replace("/<([^>]*)>/", "<\\1>", $texte); |
|
| 543 | + return $texte; |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | // Convertit un texte HTML en texte brut |
| 547 | 547 | // http://doc.spip.org/@textebrut |
| 548 | 548 | function textebrut($texte) { |
| 549 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 550 | - $texte = preg_replace('/\s+/S'.$u, " ", $texte); |
|
| 551 | - $texte = preg_replace("/<(p|br)( [^>]*)?".">/iS", "\n\n", $texte); |
|
| 552 | - $texte = preg_replace("/^\n+/", "", $texte); |
|
| 553 | - $texte = preg_replace("/\n+$/", "", $texte); |
|
| 554 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 555 | - $texte = supprimer_tags($texte); |
|
| 556 | - $texte = preg_replace("/( | )+/S", " ", $texte); |
|
| 557 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 558 | - $texte = str_replace("’","'",$texte); |
|
| 559 | - return $texte; |
|
| 549 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 550 | + $texte = preg_replace('/\s+/S'.$u, " ", $texte); |
|
| 551 | + $texte = preg_replace("/<(p|br)( [^>]*)?".">/iS", "\n\n", $texte); |
|
| 552 | + $texte = preg_replace("/^\n+/", "", $texte); |
|
| 553 | + $texte = preg_replace("/\n+$/", "", $texte); |
|
| 554 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 555 | + $texte = supprimer_tags($texte); |
|
| 556 | + $texte = preg_replace("/( | )+/S", " ", $texte); |
|
| 557 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 558 | + $texte = str_replace("’","'",$texte); |
|
| 559 | + return $texte; |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | // Remplace les liens SPIP en liens ouvrant dans une nouvelle fenetre (target=blank) |
| 563 | 563 | // http://doc.spip.org/@liens_ouvrants |
| 564 | 564 | function liens_ouvrants ($texte) { |
| 565 | - return preg_replace(",<a\s+([^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+)>,", |
|
| 566 | - "<a \\1 target=\"_blank\">", $texte); |
|
| 565 | + return preg_replace(",<a\s+([^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+)>,", |
|
| 566 | + "<a \\1 target=\"_blank\">", $texte); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | /** |
@@ -572,31 +572,31 @@ discard block |
||
| 572 | 572 | * @return string |
| 573 | 573 | */ |
| 574 | 574 | function liens_nofollow($texte) { |
| 575 | - if (stripos($texte,"<a")===false) |
|
| 576 | - return $texte; |
|
| 575 | + if (stripos($texte,"<a")===false) |
|
| 576 | + return $texte; |
|
| 577 | 577 | |
| 578 | - if (preg_match_all(",<a\b[^>]*>,UimsS",$texte, $regs, PREG_PATTERN_ORDER)){ |
|
| 579 | - foreach($regs[0] as $a){ |
|
| 580 | - $rel = extraire_attribut($a,"rel"); |
|
| 581 | - if (strpos($rel,"nofollow")===false){ |
|
| 582 | - $rel = "nofollow" . ($rel?" $rel":""); |
|
| 583 | - $anofollow = inserer_attribut($a,"rel",$rel); |
|
| 584 | - $texte = str_replace($a,$anofollow,$texte); |
|
| 585 | - } |
|
| 586 | - } |
|
| 587 | - } |
|
| 578 | + if (preg_match_all(",<a\b[^>]*>,UimsS",$texte, $regs, PREG_PATTERN_ORDER)){ |
|
| 579 | + foreach($regs[0] as $a){ |
|
| 580 | + $rel = extraire_attribut($a,"rel"); |
|
| 581 | + if (strpos($rel,"nofollow")===false){ |
|
| 582 | + $rel = "nofollow" . ($rel?" $rel":""); |
|
| 583 | + $anofollow = inserer_attribut($a,"rel",$rel); |
|
| 584 | + $texte = str_replace($a,$anofollow,$texte); |
|
| 585 | + } |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | 588 | |
| 589 | - return $texte; |
|
| 589 | + return $texte; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | // Transformer les sauts de paragraphe en simples passages a la ligne |
| 593 | 593 | // http://doc.spip.org/@PtoBR |
| 594 | 594 | function PtoBR($texte){ |
| 595 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 596 | - $texte = preg_replace("@</p>@iS", "\n", $texte); |
|
| 597 | - $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte); |
|
| 598 | - $texte = preg_replace("@^\s*<br />@S".$u, "", $texte); |
|
| 599 | - return $texte; |
|
| 595 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 596 | + $texte = preg_replace("@</p>@iS", "\n", $texte); |
|
| 597 | + $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte); |
|
| 598 | + $texte = preg_replace("@^\s*<br />@S".$u, "", $texte); |
|
| 599 | + return $texte; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | |
@@ -616,98 +616,98 @@ discard block |
||
| 616 | 616 | * @return string |
| 617 | 617 | */ |
| 618 | 618 | function lignes_longues($texte) { |
| 619 | - if (!strlen(trim($texte))) return $texte; |
|
| 620 | - include_spip('inc/texte'); |
|
| 621 | - $tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ? |
|
| 622 | - 'div' : 'span'; |
|
| 619 | + if (!strlen(trim($texte))) return $texte; |
|
| 620 | + include_spip('inc/texte'); |
|
| 621 | + $tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ? |
|
| 622 | + 'div' : 'span'; |
|
| 623 | 623 | |
| 624 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 624 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | // Majuscules y compris accents, en HTML |
| 628 | 628 | // http://doc.spip.org/@majuscules |
| 629 | 629 | function majuscules($texte) { |
| 630 | - if (!strlen($texte)) return ''; |
|
| 630 | + if (!strlen($texte)) return ''; |
|
| 631 | 631 | |
| 632 | - // Cas du turc |
|
| 633 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 634 | - # remplacer hors des tags et des entites |
|
| 635 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) |
|
| 636 | - foreach ($regs as $n => $match) |
|
| 637 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 632 | + // Cas du turc |
|
| 633 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 634 | + # remplacer hors des tags et des entites |
|
| 635 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) |
|
| 636 | + foreach ($regs as $n => $match) |
|
| 637 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 638 | 638 | |
| 639 | - $texte = str_replace('i', 'İ', $texte); |
|
| 639 | + $texte = str_replace('i', 'İ', $texte); |
|
| 640 | 640 | |
| 641 | - if ($regs) |
|
| 642 | - foreach ($regs as $n => $match) |
|
| 643 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 644 | - } |
|
| 641 | + if ($regs) |
|
| 642 | + foreach ($regs as $n => $match) |
|
| 643 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 644 | + } |
|
| 645 | 645 | |
| 646 | - // Cas general |
|
| 647 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 646 | + // Cas general |
|
| 647 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | // "127.4 ko" ou "3.1 Mo" |
| 651 | 651 | // http://doc.spip.org/@taille_en_octets |
| 652 | 652 | function taille_en_octets ($taille) { |
| 653 | - if ($taille < 1) return ''; |
|
| 654 | - if ($taille < 1024) {$taille = _T('taille_octets', array('taille' => $taille));} |
|
| 655 | - else if ($taille < 1024*1024) { |
|
| 656 | - $taille = _T('taille_ko', array('taille' => round($taille/1024, 1))); |
|
| 657 | - } else if ($taille < 1024*1024*1024) { |
|
| 658 | - $taille = _T('taille_mo', array('taille' => round($taille/1024/1024, 1))); |
|
| 659 | - } else { |
|
| 660 | - $taille = _T('taille_go', array('taille' => round($taille/1024/1024/1024, 2))); |
|
| 661 | - } |
|
| 662 | - return $taille; |
|
| 653 | + if ($taille < 1) return ''; |
|
| 654 | + if ($taille < 1024) {$taille = _T('taille_octets', array('taille' => $taille));} |
|
| 655 | + else if ($taille < 1024*1024) { |
|
| 656 | + $taille = _T('taille_ko', array('taille' => round($taille/1024, 1))); |
|
| 657 | + } else if ($taille < 1024*1024*1024) { |
|
| 658 | + $taille = _T('taille_mo', array('taille' => round($taille/1024/1024, 1))); |
|
| 659 | + } else { |
|
| 660 | + $taille = _T('taille_go', array('taille' => round($taille/1024/1024/1024, 2))); |
|
| 661 | + } |
|
| 662 | + return $taille; |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | |
| 666 | 666 | // Rend une chaine utilisable sans dommage comme attribut HTML |
| 667 | 667 | // http://doc.spip.org/@attribut_html |
| 668 | 668 | function attribut_html($texte,$textebrut = true) { |
| 669 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 670 | - if ($textebrut) |
|
| 671 | - $texte = preg_replace(array(",\n,",",\s(?=\s),msS".$u),array(" ",""),textebrut($texte)); |
|
| 672 | - $texte = texte_backend($texte); |
|
| 673 | - $texte = str_replace(array("'",'"'),array(''', '"'), $texte); |
|
| 669 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 670 | + if ($textebrut) |
|
| 671 | + $texte = preg_replace(array(",\n,",",\s(?=\s),msS".$u),array(" ",""),textebrut($texte)); |
|
| 672 | + $texte = texte_backend($texte); |
|
| 673 | + $texte = str_replace(array("'",'"'),array(''', '"'), $texte); |
|
| 674 | 674 | |
| 675 | - return preg_replace(array("/&(amp;|#38;)/","/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"),array("&","&") , $texte); |
|
| 675 | + return preg_replace(array("/&(amp;|#38;)/","/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"),array("&","&") , $texte); |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | // Vider les url nulles comme 'http://' ou 'mailto:' |
| 679 | 679 | // et leur appliquer un htmlspecialchars() + gerer les & |
| 680 | 680 | // http://doc.spip.org/@vider_url |
| 681 | 681 | function vider_url($url, $entites = true) { |
| 682 | - # un message pour abs_url |
|
| 683 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 684 | - $url = trim($url); |
|
| 685 | - $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 686 | - return preg_match($r, $url) ? '': ($entites ? entites_html($url) : $url); |
|
| 682 | + # un message pour abs_url |
|
| 683 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 684 | + $url = trim($url); |
|
| 685 | + $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 686 | + return preg_match($r, $url) ? '': ($entites ? entites_html($url) : $url); |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | // Extraire une date de n'importe quel champ (a completer...) |
| 690 | 690 | // http://doc.spip.org/@extraire_date |
| 691 | 691 | function extraire_date($texte) { |
| 692 | - // format = 2001-08 |
|
| 693 | - if (preg_match(",([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),",$texte,$regs)) |
|
| 694 | - return $regs[1]."-".sprintf("%02d", $regs[2])."-01"; |
|
| 692 | + // format = 2001-08 |
|
| 693 | + if (preg_match(",([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),",$texte,$regs)) |
|
| 694 | + return $regs[1]."-".sprintf("%02d", $regs[2])."-01"; |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | // Maquiller une adresse e-mail |
| 698 | 698 | // http://doc.spip.org/@antispam |
| 699 | 699 | function antispam($texte) { |
| 700 | - include_spip('inc/acces'); |
|
| 701 | - $masque = creer_pass_aleatoire(3); |
|
| 702 | - return preg_replace("/@/", " $masque ", $texte); |
|
| 700 | + include_spip('inc/acces'); |
|
| 701 | + $masque = creer_pass_aleatoire(3); |
|
| 702 | + return preg_replace("/@/", " $masque ", $texte); |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | // http://doc.spip.org/@securiser_acces |
| 706 | 706 | function securiser_acces($id_auteur, $cle, $dir, $op='', $args='') |
| 707 | 707 | { |
| 708 | - include_spip('inc/acces'); |
|
| 709 | - if ($op) $dir .= " $op $args"; |
|
| 710 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 708 | + include_spip('inc/acces'); |
|
| 709 | + if ($op) $dir .= " $op $args"; |
|
| 710 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | /** |
@@ -728,22 +728,22 @@ discard block |
||
| 728 | 728 | * Retourne $texte, sinon $sinon. |
| 729 | 729 | **/ |
| 730 | 730 | function sinon ($texte, $sinon='') { |
| 731 | - if ($texte OR (!is_array($texte) AND strlen($texte))) |
|
| 732 | - return $texte; |
|
| 733 | - else |
|
| 734 | - return $sinon; |
|
| 731 | + if ($texte OR (!is_array($texte) AND strlen($texte))) |
|
| 732 | + return $texte; |
|
| 733 | + else |
|
| 734 | + return $sinon; |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | // |choixsivide{vide,pasvide} affiche pasvide si la chaine n'est pas vide... |
| 738 | 738 | // http://doc.spip.org/@choixsivide |
| 739 | 739 | function choixsivide($a, $vide, $pasvide) { |
| 740 | - return $a ? $pasvide : $vide; |
|
| 740 | + return $a ? $pasvide : $vide; |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | // |choixsiegal{aquoi,oui,non} affiche oui si la chaine est egal a aquoi ... |
| 744 | 744 | // http://doc.spip.org/@choixsiegal |
| 745 | 745 | function choixsiegal($a1,$a2,$v,$f) { |
| 746 | - return ($a1 == $a2) ? $v : $f; |
|
| 746 | + return ($a1 == $a2) ? $v : $f; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | |
@@ -754,224 +754,224 @@ discard block |
||
| 754 | 754 | // on normalise la date, si elle vient du contexte (public/parametrer.php), on force le jour |
| 755 | 755 | // http://doc.spip.org/@normaliser_date |
| 756 | 756 | function normaliser_date($date, $forcer_jour = false) { |
| 757 | - $date = vider_date($date); |
|
| 758 | - if ($date) { |
|
| 759 | - if (preg_match("/^[0-9]{8,10}$/", $date)) |
|
| 760 | - $date = date("Y-m-d H:i:s", $date); |
|
| 761 | - if (preg_match("#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#", $date, $regs)) |
|
| 762 | - $date = $regs[1]."-00-00".$regs[3]; |
|
| 763 | - else if (preg_match("#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#", $date, $regs)) |
|
| 764 | - $date = preg_replace("@/@","-",$regs[1])."-00".$regs[3]; |
|
| 765 | - else |
|
| 766 | - $date = date("Y-m-d H:i:s", strtotime($date)); |
|
| 767 | - |
|
| 768 | - if ($forcer_jour) |
|
| 769 | - $date = str_replace('-00', '-01', $date); |
|
| 770 | - } |
|
| 771 | - return $date; |
|
| 757 | + $date = vider_date($date); |
|
| 758 | + if ($date) { |
|
| 759 | + if (preg_match("/^[0-9]{8,10}$/", $date)) |
|
| 760 | + $date = date("Y-m-d H:i:s", $date); |
|
| 761 | + if (preg_match("#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#", $date, $regs)) |
|
| 762 | + $date = $regs[1]."-00-00".$regs[3]; |
|
| 763 | + else if (preg_match("#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#", $date, $regs)) |
|
| 764 | + $date = preg_replace("@/@","-",$regs[1])."-00".$regs[3]; |
|
| 765 | + else |
|
| 766 | + $date = date("Y-m-d H:i:s", strtotime($date)); |
|
| 767 | + |
|
| 768 | + if ($forcer_jour) |
|
| 769 | + $date = str_replace('-00', '-01', $date); |
|
| 770 | + } |
|
| 771 | + return $date; |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | // http://doc.spip.org/@vider_date |
| 775 | 775 | function vider_date($letexte) { |
| 776 | - if (strncmp("0000-00-00", $letexte,10)==0) return ''; |
|
| 777 | - if (strncmp("0001-01-01", $letexte,10)==0) return ''; |
|
| 778 | - if (strncmp("1970-01-01", $letexte,10)==0) return ''; // eviter le bug GMT-1 |
|
| 779 | - return $letexte; |
|
| 776 | + if (strncmp("0000-00-00", $letexte,10)==0) return ''; |
|
| 777 | + if (strncmp("0001-01-01", $letexte,10)==0) return ''; |
|
| 778 | + if (strncmp("1970-01-01", $letexte,10)==0) return ''; // eviter le bug GMT-1 |
|
| 779 | + return $letexte; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | // http://doc.spip.org/@recup_heure |
| 783 | 783 | function recup_heure($date){ |
| 784 | 784 | |
| 785 | - static $d = array(0,0,0); |
|
| 786 | - if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) |
|
| 787 | - return $d; |
|
| 785 | + static $d = array(0,0,0); |
|
| 786 | + if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) |
|
| 787 | + return $d; |
|
| 788 | 788 | |
| 789 | - array_shift($r); |
|
| 790 | - return $r; |
|
| 789 | + array_shift($r); |
|
| 790 | + return $r; |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | // http://doc.spip.org/@heures |
| 794 | 794 | function heures($numdate) { |
| 795 | - $date_array = recup_heure($numdate); |
|
| 796 | - if ($date_array) |
|
| 797 | - list($heures, $minutes, $secondes) = $date_array; |
|
| 798 | - return $heures; |
|
| 795 | + $date_array = recup_heure($numdate); |
|
| 796 | + if ($date_array) |
|
| 797 | + list($heures, $minutes, $secondes) = $date_array; |
|
| 798 | + return $heures; |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | // http://doc.spip.org/@minutes |
| 802 | 802 | function minutes($numdate) { |
| 803 | - $date_array = recup_heure($numdate); |
|
| 804 | - if ($date_array) |
|
| 805 | - list($heures, $minutes, $secondes) = $date_array; |
|
| 806 | - return $minutes; |
|
| 803 | + $date_array = recup_heure($numdate); |
|
| 804 | + if ($date_array) |
|
| 805 | + list($heures, $minutes, $secondes) = $date_array; |
|
| 806 | + return $minutes; |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | // http://doc.spip.org/@secondes |
| 810 | 810 | function secondes($numdate) { |
| 811 | - $date_array = recup_heure($numdate); |
|
| 812 | - if ($date_array) |
|
| 813 | - list($heures,$minutes,$secondes) = $date_array; |
|
| 814 | - return $secondes; |
|
| 811 | + $date_array = recup_heure($numdate); |
|
| 812 | + if ($date_array) |
|
| 813 | + list($heures,$minutes,$secondes) = $date_array; |
|
| 814 | + return $secondes; |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | // http://doc.spip.org/@heures_minutes |
| 818 | 818 | function heures_minutes($numdate) { |
| 819 | - return _T('date_fmt_heures_minutes', array('h'=> heures($numdate), 'm'=> minutes($numdate))); |
|
| 819 | + return _T('date_fmt_heures_minutes', array('h'=> heures($numdate), 'm'=> minutes($numdate))); |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | // http://doc.spip.org/@recup_date |
| 823 | 823 | function recup_date($numdate, $forcer_jour = true){ |
| 824 | - if (!$numdate) return ''; |
|
| 825 | - $heures = $minutes = $secondes = 0; |
|
| 826 | - if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 827 | - $jour = $regs[1]; |
|
| 828 | - $mois = $regs[2]; |
|
| 829 | - $annee = $regs[3]; |
|
| 830 | - if ($annee < 90){ |
|
| 831 | - $annee = 2000 + $annee; |
|
| 832 | - } elseif ($annee<100) { |
|
| 833 | - $annee = 1900 + $annee ; |
|
| 834 | - } |
|
| 835 | - list($heures, $minutes, $secondes) = recup_heure($numdate); |
|
| 836 | - |
|
| 837 | - } |
|
| 838 | - elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#',$numdate, $regs)) { |
|
| 839 | - $annee = $regs[1]; |
|
| 840 | - $mois = $regs[2]; |
|
| 841 | - $jour = $regs[3]; |
|
| 842 | - list($heures, $minutes, $secondes) = recup_heure($numdate); |
|
| 843 | - } |
|
| 844 | - elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)){ |
|
| 845 | - $annee = $regs[1]; |
|
| 846 | - $mois = $regs[2]; |
|
| 847 | - $jour =''; |
|
| 848 | - list($heures, $minutes, $secondes) = recup_heure($numdate); |
|
| 849 | - } |
|
| 850 | - elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)){ |
|
| 851 | - $annee = $regs[1]; |
|
| 852 | - $mois = $regs[2]; |
|
| 853 | - $jour = $regs[3]; |
|
| 854 | - $heures = $regs[4]; |
|
| 855 | - $minutes = $regs[5]; |
|
| 856 | - $secondes = $regs[6]; |
|
| 857 | - } else $annee = $mois = $jour =''; |
|
| 858 | - if ($annee > 4000) $annee -= 9000; |
|
| 859 | - if (substr($jour, 0, 1) == '0') $jour = substr($jour, 1); |
|
| 860 | - |
|
| 861 | - if ($forcer_jour AND $jour == '0') $jour = '1'; |
|
| 862 | - if ($forcer_jour AND $mois == '0') $mois = '1'; |
|
| 863 | - if ($annee OR $mois OR $jour OR $heures OR $minutes OR $secondes) |
|
| 864 | - return array($annee, $mois, $jour, $heures, $minutes, $secondes); |
|
| 824 | + if (!$numdate) return ''; |
|
| 825 | + $heures = $minutes = $secondes = 0; |
|
| 826 | + if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 827 | + $jour = $regs[1]; |
|
| 828 | + $mois = $regs[2]; |
|
| 829 | + $annee = $regs[3]; |
|
| 830 | + if ($annee < 90){ |
|
| 831 | + $annee = 2000 + $annee; |
|
| 832 | + } elseif ($annee<100) { |
|
| 833 | + $annee = 1900 + $annee ; |
|
| 834 | + } |
|
| 835 | + list($heures, $minutes, $secondes) = recup_heure($numdate); |
|
| 836 | + |
|
| 837 | + } |
|
| 838 | + elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#',$numdate, $regs)) { |
|
| 839 | + $annee = $regs[1]; |
|
| 840 | + $mois = $regs[2]; |
|
| 841 | + $jour = $regs[3]; |
|
| 842 | + list($heures, $minutes, $secondes) = recup_heure($numdate); |
|
| 843 | + } |
|
| 844 | + elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)){ |
|
| 845 | + $annee = $regs[1]; |
|
| 846 | + $mois = $regs[2]; |
|
| 847 | + $jour =''; |
|
| 848 | + list($heures, $minutes, $secondes) = recup_heure($numdate); |
|
| 849 | + } |
|
| 850 | + elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)){ |
|
| 851 | + $annee = $regs[1]; |
|
| 852 | + $mois = $regs[2]; |
|
| 853 | + $jour = $regs[3]; |
|
| 854 | + $heures = $regs[4]; |
|
| 855 | + $minutes = $regs[5]; |
|
| 856 | + $secondes = $regs[6]; |
|
| 857 | + } else $annee = $mois = $jour =''; |
|
| 858 | + if ($annee > 4000) $annee -= 9000; |
|
| 859 | + if (substr($jour, 0, 1) == '0') $jour = substr($jour, 1); |
|
| 860 | + |
|
| 861 | + if ($forcer_jour AND $jour == '0') $jour = '1'; |
|
| 862 | + if ($forcer_jour AND $mois == '0') $mois = '1'; |
|
| 863 | + if ($annee OR $mois OR $jour OR $heures OR $minutes OR $secondes) |
|
| 864 | + return array($annee, $mois, $jour, $heures, $minutes, $secondes); |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | // une date pour l'interface : utilise date_relative si le decalage |
| 868 | 868 | // avec time() est de moins de douze heures, sinon la date complete |
| 869 | 869 | // http://doc.spip.org/@date_interface |
| 870 | 870 | function date_interface($date, $decalage_maxi = 43200/* 12*3600 */) { |
| 871 | - return sinon( |
|
| 872 | - date_relative($date, $decalage_maxi), |
|
| 873 | - affdate_heure($date) |
|
| 874 | - ); |
|
| 871 | + return sinon( |
|
| 872 | + date_relative($date, $decalage_maxi), |
|
| 873 | + affdate_heure($date) |
|
| 874 | + ); |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | 877 | // http://doc.spip.org/@date_relative |
| 878 | 878 | function date_relative($date, $decalage_maxi=0,$ref_date=null) { |
| 879 | 879 | |
| 880 | - if (is_null($ref_date)) |
|
| 881 | - $ref_time = time(); |
|
| 882 | - else |
|
| 883 | - $ref_time = strtotime($ref_date); |
|
| 880 | + if (is_null($ref_date)) |
|
| 881 | + $ref_time = time(); |
|
| 882 | + else |
|
| 883 | + $ref_time = strtotime($ref_date); |
|
| 884 | 884 | |
| 885 | - if (!$date) return; |
|
| 886 | - $decal = date("U",$ref_time) - date("U", strtotime($date)); |
|
| 887 | - |
|
| 888 | - if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0)) |
|
| 889 | - return ''; |
|
| 890 | - |
|
| 891 | - if ($decal < 0) { |
|
| 892 | - $il_y_a = "date_dans"; |
|
| 893 | - $decal = -1 * $decal; |
|
| 894 | - } else { |
|
| 895 | - $il_y_a = "date_il_y_a"; |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - if ($decal > 3600 * 24 * 30 * 6) |
|
| 899 | - return affdate_court($date); |
|
| 900 | - |
|
| 901 | - if ($decal > 3600 * 24 * 30) { |
|
| 902 | - $mois = floor ($decal / (3600 * 24 * 30)); |
|
| 903 | - if ($mois < 2) |
|
| 904 | - $delai = "$mois "._T("date_un_mois"); |
|
| 905 | - else |
|
| 906 | - $delai = "$mois "._T("date_mois"); |
|
| 907 | - } |
|
| 908 | - else if ($decal > 3600 * 24 * 7) { |
|
| 909 | - $semaines = floor ($decal / (3600 * 24 * 7)); |
|
| 910 | - if ($semaines < 2) |
|
| 911 | - $delai = "$semaines "._T("date_une_semaine"); |
|
| 912 | - else |
|
| 913 | - $delai = "$semaines "._T("date_semaines"); |
|
| 914 | - } |
|
| 915 | - else if ($decal > 3600 * 24) { |
|
| 916 | - $jours = floor ($decal / (3600 * 24)); |
|
| 917 | - if ($jours < 2) |
|
| 918 | - return $il_y_a=="date_dans"?_T("date_demain"):_T("date_hier"); |
|
| 919 | - else |
|
| 920 | - $delai = "$jours "._T("date_jours"); |
|
| 921 | - } |
|
| 922 | - else if ($decal >= 3600) { |
|
| 923 | - $heures = floor ($decal / 3600); |
|
| 924 | - if ($heures < 2) |
|
| 925 | - $delai = "$heures "._T("date_une_heure"); |
|
| 926 | - else |
|
| 927 | - $delai = "$heures "._T("date_heures"); |
|
| 928 | - } |
|
| 929 | - else if ($decal >= 60) { |
|
| 930 | - $minutes = floor($decal / 60); |
|
| 931 | - if ($minutes < 2) |
|
| 932 | - $delai = "$minutes "._T("date_une_minute"); |
|
| 933 | - else |
|
| 934 | - $delai = "$minutes "._T("date_minutes"); |
|
| 935 | - } else { |
|
| 936 | - $secondes = ceil($decal); |
|
| 937 | - if ($secondes < 2) |
|
| 938 | - $delai = "$secondes "._T("date_une_seconde"); |
|
| 939 | - else |
|
| 940 | - $delai = "$secondes "._T("date_secondes"); |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - return _T($il_y_a, array("delai"=> $delai)); |
|
| 885 | + if (!$date) return; |
|
| 886 | + $decal = date("U",$ref_time) - date("U", strtotime($date)); |
|
| 887 | + |
|
| 888 | + if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0)) |
|
| 889 | + return ''; |
|
| 890 | + |
|
| 891 | + if ($decal < 0) { |
|
| 892 | + $il_y_a = "date_dans"; |
|
| 893 | + $decal = -1 * $decal; |
|
| 894 | + } else { |
|
| 895 | + $il_y_a = "date_il_y_a"; |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + if ($decal > 3600 * 24 * 30 * 6) |
|
| 899 | + return affdate_court($date); |
|
| 900 | + |
|
| 901 | + if ($decal > 3600 * 24 * 30) { |
|
| 902 | + $mois = floor ($decal / (3600 * 24 * 30)); |
|
| 903 | + if ($mois < 2) |
|
| 904 | + $delai = "$mois "._T("date_un_mois"); |
|
| 905 | + else |
|
| 906 | + $delai = "$mois "._T("date_mois"); |
|
| 907 | + } |
|
| 908 | + else if ($decal > 3600 * 24 * 7) { |
|
| 909 | + $semaines = floor ($decal / (3600 * 24 * 7)); |
|
| 910 | + if ($semaines < 2) |
|
| 911 | + $delai = "$semaines "._T("date_une_semaine"); |
|
| 912 | + else |
|
| 913 | + $delai = "$semaines "._T("date_semaines"); |
|
| 914 | + } |
|
| 915 | + else if ($decal > 3600 * 24) { |
|
| 916 | + $jours = floor ($decal / (3600 * 24)); |
|
| 917 | + if ($jours < 2) |
|
| 918 | + return $il_y_a=="date_dans"?_T("date_demain"):_T("date_hier"); |
|
| 919 | + else |
|
| 920 | + $delai = "$jours "._T("date_jours"); |
|
| 921 | + } |
|
| 922 | + else if ($decal >= 3600) { |
|
| 923 | + $heures = floor ($decal / 3600); |
|
| 924 | + if ($heures < 2) |
|
| 925 | + $delai = "$heures "._T("date_une_heure"); |
|
| 926 | + else |
|
| 927 | + $delai = "$heures "._T("date_heures"); |
|
| 928 | + } |
|
| 929 | + else if ($decal >= 60) { |
|
| 930 | + $minutes = floor($decal / 60); |
|
| 931 | + if ($minutes < 2) |
|
| 932 | + $delai = "$minutes "._T("date_une_minute"); |
|
| 933 | + else |
|
| 934 | + $delai = "$minutes "._T("date_minutes"); |
|
| 935 | + } else { |
|
| 936 | + $secondes = ceil($decal); |
|
| 937 | + if ($secondes < 2) |
|
| 938 | + $delai = "$secondes "._T("date_une_seconde"); |
|
| 939 | + else |
|
| 940 | + $delai = "$secondes "._T("date_secondes"); |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + return _T($il_y_a, array("delai"=> $delai)); |
|
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | |
| 947 | 947 | // http://doc.spip.org/@date_relativecourt |
| 948 | 948 | function date_relativecourt($date, $decalage_maxi=0) { |
| 949 | 949 | |
| 950 | - if (!$date) return; |
|
| 951 | - $decal = date("U",strtotime(date('Y-m-d'))-strtotime(date('Y-m-d',strtotime($date)))); |
|
| 950 | + if (!$date) return; |
|
| 951 | + $decal = date("U",strtotime(date('Y-m-d'))-strtotime(date('Y-m-d',strtotime($date)))); |
|
| 952 | 952 | |
| 953 | - if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0)) |
|
| 954 | - return ''; |
|
| 953 | + if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0)) |
|
| 954 | + return ''; |
|
| 955 | 955 | |
| 956 | - if ($decal < -24*3600) { |
|
| 957 | - $retour = date_relative($date, $decalage_maxi); |
|
| 958 | - } |
|
| 959 | - elseif ($decal < 0) { |
|
| 960 | - $retour = _T("date_demain"); |
|
| 961 | - } |
|
| 962 | - else if ($decal < (3600 * 24) ) { |
|
| 963 | - $retour = _T("date_aujourdhui"); |
|
| 964 | - } |
|
| 965 | - else if ($decal < (3600 * 24 *2) ) { |
|
| 966 | - $retour = _T("date_hier"); |
|
| 967 | - } |
|
| 968 | - else { |
|
| 969 | - $retour = date_relative($date, $decalage_maxi); |
|
| 970 | - } |
|
| 956 | + if ($decal < -24*3600) { |
|
| 957 | + $retour = date_relative($date, $decalage_maxi); |
|
| 958 | + } |
|
| 959 | + elseif ($decal < 0) { |
|
| 960 | + $retour = _T("date_demain"); |
|
| 961 | + } |
|
| 962 | + else if ($decal < (3600 * 24) ) { |
|
| 963 | + $retour = _T("date_aujourdhui"); |
|
| 964 | + } |
|
| 965 | + else if ($decal < (3600 * 24 *2) ) { |
|
| 966 | + $retour = _T("date_hier"); |
|
| 967 | + } |
|
| 968 | + else { |
|
| 969 | + $retour = date_relative($date, $decalage_maxi); |
|
| 970 | + } |
|
| 971 | 971 | |
| 972 | 972 | |
| 973 | 973 | |
| 974 | - return $retour; |
|
| 974 | + return $retour; |
|
| 975 | 975 | } |
| 976 | 976 | |
| 977 | 977 | /** |
@@ -986,183 +986,183 @@ discard block |
||
| 986 | 986 | * @return mixed|string |
| 987 | 987 | */ |
| 988 | 988 | function affdate_base($numdate, $vue, $options = array()) { |
| 989 | - if (is_string($options)) |
|
| 990 | - $options = array('param'=>$options); |
|
| 991 | - $date_array = recup_date($numdate, false); |
|
| 992 | - if (!$date_array) return; |
|
| 993 | - list($annee, $mois, $jour, $heures, $minutes, $secondes)= $date_array; |
|
| 994 | - |
|
| 995 | - // 1er, 21st, etc. |
|
| 996 | - $journum = $jour; |
|
| 997 | - |
|
| 998 | - if ($jour == 0) { |
|
| 999 | - $jour = ''; |
|
| 1000 | - } else { |
|
| 1001 | - $njour = intval($jour); |
|
| 1002 | - if ($jourth = _T('date_jnum'.$jour)) |
|
| 1003 | - $jour = $jourth; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - $mois = intval($mois); |
|
| 1007 | - if ($mois > 0 AND $mois < 13) { |
|
| 1008 | - $nommois = _T('date_mois_'.$mois); |
|
| 1009 | - if ($jour) |
|
| 1010 | - $jourmois = _T('date_de_mois_'.$mois, array('j'=>$jour, 'nommois'=>$nommois)); |
|
| 1011 | - else |
|
| 1012 | - $jourmois = $nommois; |
|
| 1013 | - } else $nommois = ''; |
|
| 1014 | - |
|
| 1015 | - if ($annee < 0) { |
|
| 1016 | - $annee = -$annee." "._T('date_avant_jc'); |
|
| 1017 | - $avjc = true; |
|
| 1018 | - } |
|
| 1019 | - else $avjc = false; |
|
| 1020 | - |
|
| 1021 | - switch ($vue) { |
|
| 1022 | - case 'saison': |
|
| 1023 | - case 'saison_annee': |
|
| 1024 | - $saison = ''; |
|
| 1025 | - if ($mois > 0){ |
|
| 1026 | - $saison = 1; |
|
| 1027 | - if (($mois == 3 AND $jour >= 21) OR $mois > 3) $saison = 2; |
|
| 1028 | - if (($mois == 6 AND $jour >= 21) OR $mois > 6) $saison = 3; |
|
| 1029 | - if (($mois == 9 AND $jour >= 21) OR $mois > 9) $saison = 4; |
|
| 1030 | - if (($mois == 12 AND $jour >= 21) OR $mois > 12) $saison = 1; |
|
| 1031 | - } |
|
| 1032 | - if($vue == 'saison') |
|
| 1033 | - return $saison?_T('date_saison_'.$saison):''; |
|
| 1034 | - else |
|
| 1035 | - return $saison?trim(_T('date_fmt_saison_annee', array('saison'=>_T('date_saison_'.$saison), 'annee'=>$annee))) :''; |
|
| 1036 | - |
|
| 1037 | - case 'court': |
|
| 1038 | - if ($avjc) return $annee; |
|
| 1039 | - $a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y')); |
|
| 1040 | - if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee; |
|
| 1041 | - if ($annee != $a) return _T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>spip_ucfirst($nommois), 'annee'=>$annee)); |
|
| 1042 | - return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)); |
|
| 1043 | - |
|
| 1044 | - case 'jourcourt': |
|
| 1045 | - if ($avjc) return $annee; |
|
| 1046 | - $a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y')); |
|
| 1047 | - if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee; |
|
| 1048 | - if ($annee != $a) return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)); |
|
| 1049 | - return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)); |
|
| 1050 | - |
|
| 1051 | - case 'entier': |
|
| 1052 | - if ($avjc) return $annee; |
|
| 1053 | - if ($jour) |
|
| 1054 | - return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)); |
|
| 1055 | - elseif ($mois) |
|
| 1056 | - return trim(_T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee))); |
|
| 1057 | - else |
|
| 1058 | - return $annee; |
|
| 1059 | - |
|
| 1060 | - case 'nom_mois': |
|
| 1061 | - $param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : ''); |
|
| 1062 | - if ($param and $mois) { |
|
| 1063 | - return _T('date_mois_'.$mois.$param); |
|
| 1064 | - } |
|
| 1065 | - return $nommois; |
|
| 1066 | - |
|
| 1067 | - case 'mois': |
|
| 1068 | - return sprintf("%02s",$mois); |
|
| 1069 | - |
|
| 1070 | - case 'jour': |
|
| 1071 | - return $jour; |
|
| 1072 | - |
|
| 1073 | - case 'journum': |
|
| 1074 | - return $journum; |
|
| 1075 | - |
|
| 1076 | - case 'nom_jour': |
|
| 1077 | - if (!$mois OR !$njour) |
|
| 1078 | - return ''; |
|
| 1079 | - $nom = mktime(1,1,1,$mois,$njour,$annee); |
|
| 1080 | - $nom = 1+date('w',$nom); |
|
| 1081 | - $param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : ''); |
|
| 1082 | - return _T('date_jour_'.$nom.$param); |
|
| 1083 | - |
|
| 1084 | - case 'mois_annee': |
|
| 1085 | - if ($avjc) return $annee; |
|
| 1086 | - return trim(_T('date_fmt_mois_annee', array('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee))); |
|
| 1087 | - |
|
| 1088 | - case 'annee': |
|
| 1089 | - return $annee; |
|
| 1090 | - |
|
| 1091 | - // Cas d'une vue non definie : retomber sur le format |
|
| 1092 | - // de date propose par http://www.php.net/date |
|
| 1093 | - default: |
|
| 1094 | - return date($vue, strtotime($numdate)); |
|
| 1095 | - } |
|
| 989 | + if (is_string($options)) |
|
| 990 | + $options = array('param'=>$options); |
|
| 991 | + $date_array = recup_date($numdate, false); |
|
| 992 | + if (!$date_array) return; |
|
| 993 | + list($annee, $mois, $jour, $heures, $minutes, $secondes)= $date_array; |
|
| 994 | + |
|
| 995 | + // 1er, 21st, etc. |
|
| 996 | + $journum = $jour; |
|
| 997 | + |
|
| 998 | + if ($jour == 0) { |
|
| 999 | + $jour = ''; |
|
| 1000 | + } else { |
|
| 1001 | + $njour = intval($jour); |
|
| 1002 | + if ($jourth = _T('date_jnum'.$jour)) |
|
| 1003 | + $jour = $jourth; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + $mois = intval($mois); |
|
| 1007 | + if ($mois > 0 AND $mois < 13) { |
|
| 1008 | + $nommois = _T('date_mois_'.$mois); |
|
| 1009 | + if ($jour) |
|
| 1010 | + $jourmois = _T('date_de_mois_'.$mois, array('j'=>$jour, 'nommois'=>$nommois)); |
|
| 1011 | + else |
|
| 1012 | + $jourmois = $nommois; |
|
| 1013 | + } else $nommois = ''; |
|
| 1014 | + |
|
| 1015 | + if ($annee < 0) { |
|
| 1016 | + $annee = -$annee." "._T('date_avant_jc'); |
|
| 1017 | + $avjc = true; |
|
| 1018 | + } |
|
| 1019 | + else $avjc = false; |
|
| 1020 | + |
|
| 1021 | + switch ($vue) { |
|
| 1022 | + case 'saison': |
|
| 1023 | + case 'saison_annee': |
|
| 1024 | + $saison = ''; |
|
| 1025 | + if ($mois > 0){ |
|
| 1026 | + $saison = 1; |
|
| 1027 | + if (($mois == 3 AND $jour >= 21) OR $mois > 3) $saison = 2; |
|
| 1028 | + if (($mois == 6 AND $jour >= 21) OR $mois > 6) $saison = 3; |
|
| 1029 | + if (($mois == 9 AND $jour >= 21) OR $mois > 9) $saison = 4; |
|
| 1030 | + if (($mois == 12 AND $jour >= 21) OR $mois > 12) $saison = 1; |
|
| 1031 | + } |
|
| 1032 | + if($vue == 'saison') |
|
| 1033 | + return $saison?_T('date_saison_'.$saison):''; |
|
| 1034 | + else |
|
| 1035 | + return $saison?trim(_T('date_fmt_saison_annee', array('saison'=>_T('date_saison_'.$saison), 'annee'=>$annee))) :''; |
|
| 1036 | + |
|
| 1037 | + case 'court': |
|
| 1038 | + if ($avjc) return $annee; |
|
| 1039 | + $a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y')); |
|
| 1040 | + if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee; |
|
| 1041 | + if ($annee != $a) return _T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>spip_ucfirst($nommois), 'annee'=>$annee)); |
|
| 1042 | + return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)); |
|
| 1043 | + |
|
| 1044 | + case 'jourcourt': |
|
| 1045 | + if ($avjc) return $annee; |
|
| 1046 | + $a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y')); |
|
| 1047 | + if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee; |
|
| 1048 | + if ($annee != $a) return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)); |
|
| 1049 | + return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)); |
|
| 1050 | + |
|
| 1051 | + case 'entier': |
|
| 1052 | + if ($avjc) return $annee; |
|
| 1053 | + if ($jour) |
|
| 1054 | + return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)); |
|
| 1055 | + elseif ($mois) |
|
| 1056 | + return trim(_T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee))); |
|
| 1057 | + else |
|
| 1058 | + return $annee; |
|
| 1059 | + |
|
| 1060 | + case 'nom_mois': |
|
| 1061 | + $param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : ''); |
|
| 1062 | + if ($param and $mois) { |
|
| 1063 | + return _T('date_mois_'.$mois.$param); |
|
| 1064 | + } |
|
| 1065 | + return $nommois; |
|
| 1066 | + |
|
| 1067 | + case 'mois': |
|
| 1068 | + return sprintf("%02s",$mois); |
|
| 1069 | + |
|
| 1070 | + case 'jour': |
|
| 1071 | + return $jour; |
|
| 1072 | + |
|
| 1073 | + case 'journum': |
|
| 1074 | + return $journum; |
|
| 1075 | + |
|
| 1076 | + case 'nom_jour': |
|
| 1077 | + if (!$mois OR !$njour) |
|
| 1078 | + return ''; |
|
| 1079 | + $nom = mktime(1,1,1,$mois,$njour,$annee); |
|
| 1080 | + $nom = 1+date('w',$nom); |
|
| 1081 | + $param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : ''); |
|
| 1082 | + return _T('date_jour_'.$nom.$param); |
|
| 1083 | + |
|
| 1084 | + case 'mois_annee': |
|
| 1085 | + if ($avjc) return $annee; |
|
| 1086 | + return trim(_T('date_fmt_mois_annee', array('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee))); |
|
| 1087 | + |
|
| 1088 | + case 'annee': |
|
| 1089 | + return $annee; |
|
| 1090 | + |
|
| 1091 | + // Cas d'une vue non definie : retomber sur le format |
|
| 1092 | + // de date propose par http://www.php.net/date |
|
| 1093 | + default: |
|
| 1094 | + return date($vue, strtotime($numdate)); |
|
| 1095 | + } |
|
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | 1098 | // http://doc.spip.org/@nom_jour |
| 1099 | 1099 | function nom_jour($numdate, $forme = '') { |
| 1100 | - if(!($forme == 'abbr' OR $forme == 'initiale')) $forme = ''; |
|
| 1101 | - return affdate_base($numdate, 'nom_jour', $forme); |
|
| 1100 | + if(!($forme == 'abbr' OR $forme == 'initiale')) $forme = ''; |
|
| 1101 | + return affdate_base($numdate, 'nom_jour', $forme); |
|
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | // http://doc.spip.org/@jour |
| 1105 | 1105 | function jour($numdate) { |
| 1106 | - return affdate_base($numdate, 'jour'); |
|
| 1106 | + return affdate_base($numdate, 'jour'); |
|
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | // http://doc.spip.org/@journum |
| 1110 | 1110 | function journum($numdate) { |
| 1111 | - return affdate_base($numdate, 'journum'); |
|
| 1111 | + return affdate_base($numdate, 'journum'); |
|
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | // http://doc.spip.org/@mois |
| 1115 | 1115 | function mois($numdate) { |
| 1116 | - return affdate_base($numdate, 'mois'); |
|
| 1116 | + return affdate_base($numdate, 'mois'); |
|
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | // http://doc.spip.org/@nom_mois |
| 1120 | 1120 | function nom_mois($numdate, $forme='') { |
| 1121 | - if(!($forme == 'abbr')) $forme = ''; |
|
| 1122 | - return affdate_base($numdate, 'nom_mois', $forme); |
|
| 1121 | + if(!($forme == 'abbr')) $forme = ''; |
|
| 1122 | + return affdate_base($numdate, 'nom_mois', $forme); |
|
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | // http://doc.spip.org/@annee |
| 1126 | 1126 | function annee($numdate) { |
| 1127 | - return affdate_base($numdate, 'annee'); |
|
| 1127 | + return affdate_base($numdate, 'annee'); |
|
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | // http://doc.spip.org/@saison |
| 1131 | 1131 | function saison($numdate) { |
| 1132 | - return affdate_base($numdate, 'saison'); |
|
| 1132 | + return affdate_base($numdate, 'saison'); |
|
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | // http://doc.spip.org/@saison_annee |
| 1136 | 1136 | function saison_annee($numdate) { |
| 1137 | - return affdate_base($numdate, 'saison_annee'); |
|
| 1137 | + return affdate_base($numdate, 'saison_annee'); |
|
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | 1140 | // http://doc.spip.org/@affdate |
| 1141 | 1141 | function affdate($numdate, $format='entier') { |
| 1142 | - return affdate_base($numdate, $format); |
|
| 1142 | + return affdate_base($numdate, $format); |
|
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | // http://doc.spip.org/@affdate_court |
| 1146 | 1146 | function affdate_court($numdate, $annee_courante=null) { |
| 1147 | - return affdate_base($numdate, 'court', array('annee_courante'=>$annee_courante)); |
|
| 1147 | + return affdate_base($numdate, 'court', array('annee_courante'=>$annee_courante)); |
|
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | // http://doc.spip.org/@affdate_jourcourt |
| 1151 | 1151 | function affdate_jourcourt($numdate, $annee_courante=null) { |
| 1152 | - return affdate_base($numdate, 'jourcourt', array('annee_courante'=>$annee_courante)); |
|
| 1152 | + return affdate_base($numdate, 'jourcourt', array('annee_courante'=>$annee_courante)); |
|
| 1153 | 1153 | } |
| 1154 | 1154 | |
| 1155 | 1155 | // http://doc.spip.org/@affdate_mois_annee |
| 1156 | 1156 | function affdate_mois_annee($numdate) { |
| 1157 | - return affdate_base($numdate, 'mois_annee'); |
|
| 1157 | + return affdate_base($numdate, 'mois_annee'); |
|
| 1158 | 1158 | } |
| 1159 | 1159 | |
| 1160 | 1160 | // http://doc.spip.org/@affdate_heure |
| 1161 | 1161 | function affdate_heure($numdate) { |
| 1162 | - $date_array = recup_date($numdate); |
|
| 1163 | - if (!$date_array) return; |
|
| 1164 | - list($annee, $mois, $jour, $heures, $minutes, $sec)= $date_array; |
|
| 1165 | - return _T('date_fmt_jour_heure', array('jour' => affdate($numdate), 'heure' => _T('date_fmt_heures_minutes', array('h'=> $heures, 'm'=> $minutes)))); |
|
| 1162 | + $date_array = recup_date($numdate); |
|
| 1163 | + if (!$date_array) return; |
|
| 1164 | + list($annee, $mois, $jour, $heures, $minutes, $sec)= $date_array; |
|
| 1165 | + return _T('date_fmt_jour_heure', array('jour' => affdate($numdate), 'heure' => _T('date_fmt_heures_minutes', array('h'=> $heures, 'm'=> $minutes)))); |
|
| 1166 | 1166 | } |
| 1167 | 1167 | |
| 1168 | 1168 | /** |
@@ -1190,94 +1190,94 @@ discard block |
||
| 1190 | 1190 | * @return string |
| 1191 | 1191 | */ |
| 1192 | 1192 | function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme=''){ |
| 1193 | - $abbr = $jour = ''; |
|
| 1194 | - $affdate = "affdate_jourcourt"; |
|
| 1195 | - if (strpos($forme,'abbr') !==false) $abbr = 'abbr'; |
|
| 1196 | - if (strpos($forme,'annee')!==false) $affdate = 'affdate'; |
|
| 1197 | - if (strpos($forme,'jour') !==false) $jour = 'jour'; |
|
| 1193 | + $abbr = $jour = ''; |
|
| 1194 | + $affdate = "affdate_jourcourt"; |
|
| 1195 | + if (strpos($forme,'abbr') !==false) $abbr = 'abbr'; |
|
| 1196 | + if (strpos($forme,'annee')!==false) $affdate = 'affdate'; |
|
| 1197 | + if (strpos($forme,'jour') !==false) $jour = 'jour'; |
|
| 1198 | 1198 | |
| 1199 | - $dtstart = $dtend = $dtabbr = ""; |
|
| 1200 | - if (strpos($forme,'hcal')!==false) { |
|
| 1201 | - $dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>"; |
|
| 1202 | - $dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>"; |
|
| 1203 | - $dtabbr = "</abbr>"; |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - $date_debut = strtotime($date_debut); |
|
| 1207 | - $date_fin = strtotime($date_fin); |
|
| 1208 | - $d = date("Y-m-d", $date_debut); |
|
| 1209 | - $f = date("Y-m-d", $date_fin); |
|
| 1210 | - $h = ($horaire==='oui' OR $horaire===true); |
|
| 1211 | - $hd = _T('date_fmt_heures_minutes_court', array('h'=> date("H",$date_debut), 'm'=> date("i",$date_debut))); |
|
| 1212 | - $hf = _T('date_fmt_heures_minutes_court', array('h'=> date("H",$date_fin), 'm'=> date("i",$date_fin))); |
|
| 1213 | - |
|
| 1214 | - if ($d==$f) |
|
| 1215 | - { // meme jour |
|
| 1216 | - $nomjour = nom_jour($d,$abbr); |
|
| 1217 | - $s = $affdate($d); |
|
| 1218 | - $s = _T('date_fmt_jour',array('nomjour'=>$nomjour,'jour' => $s)); |
|
| 1219 | - if ($h){ |
|
| 1220 | - if ($hd==$hf){ |
|
| 1221 | - // Lundi 20 fevrier a 18h25 |
|
| 1222 | - $s = spip_ucfirst(_T('date_fmt_jour_heure',array('jour'=>$s,'heure'=>$hd))); |
|
| 1223 | - $s = "$dtstart$s$dtabbr"; |
|
| 1224 | - }else{ |
|
| 1225 | - // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1226 | - if($dtabbr && $dtstart && $dtend) |
|
| 1227 | - $s = _T('date_fmt_jour_heure_debut_fin_abbr',array('jour'=>spip_ucfirst($s),'heure_debut'=>$hd,'heure_fin'=>$hf,'dtstart'=>$dtstart,'dtend'=>$dtend,'dtabbr'=>$dtabbr)); |
|
| 1228 | - // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1229 | - else |
|
| 1230 | - $s = spip_ucfirst(_T('date_fmt_jour_heure_debut_fin',array('jour'=>$s,'heure_debut'=>$hd,'heure_fin'=>$hf))); |
|
| 1231 | - } |
|
| 1232 | - }else{ |
|
| 1233 | - if($dtabbr && $dtstart) |
|
| 1234 | - $s = $dtstart.spip_ucfirst($s).$dtabbr; |
|
| 1235 | - else |
|
| 1236 | - $s = spip_ucfirst($s); |
|
| 1237 | - } |
|
| 1238 | - } |
|
| 1239 | - else if ((date("Y-m",$date_debut))==date("Y-m",$date_fin)) |
|
| 1240 | - { // meme annee et mois, jours differents |
|
| 1241 | - if(!$h) |
|
| 1242 | - $date_debut = jour($d); |
|
| 1243 | - else |
|
| 1244 | - $date_debut = affdate_jourcourt($d,date("Y",$date_fin)); |
|
| 1245 | - $date_fin = $affdate($f); |
|
| 1246 | - if($jour){ |
|
| 1247 | - $nomjour_debut = nom_jour($d,$abbr); |
|
| 1248 | - $date_debut = _T('date_fmt_jour',array('nomjour'=>$nomjour_debut,'jour' => $date_debut)); |
|
| 1249 | - $nomjour_fin = nom_jour($f,$abbr); |
|
| 1250 | - $date_fin = _T('date_fmt_jour',array('nomjour'=>$nomjour_fin,'jour' => $date_fin)); |
|
| 1251 | - } |
|
| 1252 | - if ($h){ |
|
| 1253 | - $date_debut = _T('date_fmt_jour_heure',array('jour'=>$date_debut,'heure'=>$hd)); |
|
| 1254 | - $date_fin = _T('date_fmt_jour_heure',array('jour'=>$date_fin,'heure'=>$hf)); |
|
| 1255 | - } |
|
| 1256 | - $date_debut = $dtstart.$date_debut.$dtabbr; |
|
| 1257 | - $date_fin = $dtend.$date_fin.$dtabbr; |
|
| 1199 | + $dtstart = $dtend = $dtabbr = ""; |
|
| 1200 | + if (strpos($forme,'hcal')!==false) { |
|
| 1201 | + $dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>"; |
|
| 1202 | + $dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>"; |
|
| 1203 | + $dtabbr = "</abbr>"; |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + $date_debut = strtotime($date_debut); |
|
| 1207 | + $date_fin = strtotime($date_fin); |
|
| 1208 | + $d = date("Y-m-d", $date_debut); |
|
| 1209 | + $f = date("Y-m-d", $date_fin); |
|
| 1210 | + $h = ($horaire==='oui' OR $horaire===true); |
|
| 1211 | + $hd = _T('date_fmt_heures_minutes_court', array('h'=> date("H",$date_debut), 'm'=> date("i",$date_debut))); |
|
| 1212 | + $hf = _T('date_fmt_heures_minutes_court', array('h'=> date("H",$date_fin), 'm'=> date("i",$date_fin))); |
|
| 1213 | + |
|
| 1214 | + if ($d==$f) |
|
| 1215 | + { // meme jour |
|
| 1216 | + $nomjour = nom_jour($d,$abbr); |
|
| 1217 | + $s = $affdate($d); |
|
| 1218 | + $s = _T('date_fmt_jour',array('nomjour'=>$nomjour,'jour' => $s)); |
|
| 1219 | + if ($h){ |
|
| 1220 | + if ($hd==$hf){ |
|
| 1221 | + // Lundi 20 fevrier a 18h25 |
|
| 1222 | + $s = spip_ucfirst(_T('date_fmt_jour_heure',array('jour'=>$s,'heure'=>$hd))); |
|
| 1223 | + $s = "$dtstart$s$dtabbr"; |
|
| 1224 | + }else{ |
|
| 1225 | + // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1226 | + if($dtabbr && $dtstart && $dtend) |
|
| 1227 | + $s = _T('date_fmt_jour_heure_debut_fin_abbr',array('jour'=>spip_ucfirst($s),'heure_debut'=>$hd,'heure_fin'=>$hf,'dtstart'=>$dtstart,'dtend'=>$dtend,'dtabbr'=>$dtabbr)); |
|
| 1228 | + // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1229 | + else |
|
| 1230 | + $s = spip_ucfirst(_T('date_fmt_jour_heure_debut_fin',array('jour'=>$s,'heure_debut'=>$hd,'heure_fin'=>$hf))); |
|
| 1231 | + } |
|
| 1232 | + }else{ |
|
| 1233 | + if($dtabbr && $dtstart) |
|
| 1234 | + $s = $dtstart.spip_ucfirst($s).$dtabbr; |
|
| 1235 | + else |
|
| 1236 | + $s = spip_ucfirst($s); |
|
| 1237 | + } |
|
| 1238 | + } |
|
| 1239 | + else if ((date("Y-m",$date_debut))==date("Y-m",$date_fin)) |
|
| 1240 | + { // meme annee et mois, jours differents |
|
| 1241 | + if(!$h) |
|
| 1242 | + $date_debut = jour($d); |
|
| 1243 | + else |
|
| 1244 | + $date_debut = affdate_jourcourt($d,date("Y",$date_fin)); |
|
| 1245 | + $date_fin = $affdate($f); |
|
| 1246 | + if($jour){ |
|
| 1247 | + $nomjour_debut = nom_jour($d,$abbr); |
|
| 1248 | + $date_debut = _T('date_fmt_jour',array('nomjour'=>$nomjour_debut,'jour' => $date_debut)); |
|
| 1249 | + $nomjour_fin = nom_jour($f,$abbr); |
|
| 1250 | + $date_fin = _T('date_fmt_jour',array('nomjour'=>$nomjour_fin,'jour' => $date_fin)); |
|
| 1251 | + } |
|
| 1252 | + if ($h){ |
|
| 1253 | + $date_debut = _T('date_fmt_jour_heure',array('jour'=>$date_debut,'heure'=>$hd)); |
|
| 1254 | + $date_fin = _T('date_fmt_jour_heure',array('jour'=>$date_fin,'heure'=>$hf)); |
|
| 1255 | + } |
|
| 1256 | + $date_debut = $dtstart.$date_debut.$dtabbr; |
|
| 1257 | + $date_fin = $dtend.$date_fin.$dtabbr; |
|
| 1258 | 1258 | |
| 1259 | - $s = _T('date_fmt_periode',array('date_debut' => $date_debut,'date_fin'=>$date_fin)); |
|
| 1260 | - } |
|
| 1261 | - else { |
|
| 1262 | - $date_debut = affdate_jourcourt($d,date("Y",$date_fin)); |
|
| 1263 | - $date_fin = $affdate($f); |
|
| 1264 | - if($jour){ |
|
| 1265 | - $nomjour_debut = nom_jour($d,$abbr); |
|
| 1266 | - $date_debut = _T('date_fmt_jour',array('nomjour'=>$nomjour_debut,'jour' => $date_debut)); |
|
| 1267 | - $nomjour_fin = nom_jour($f,$abbr); |
|
| 1268 | - $date_fin = _T('date_fmt_jour',array('nomjour'=>$nomjour_fin,'jour' => $date_fin)); |
|
| 1269 | - } |
|
| 1270 | - if ($h){ |
|
| 1271 | - $date_debut = _T('date_fmt_jour_heure',array('jour'=>$date_debut,'heure'=>$hd)); |
|
| 1272 | - $date_fin = _T('date_fmt_jour_heure',array('jour'=>$date_fin,'heure'=>$hf)); |
|
| 1273 | - } |
|
| 1259 | + $s = _T('date_fmt_periode',array('date_debut' => $date_debut,'date_fin'=>$date_fin)); |
|
| 1260 | + } |
|
| 1261 | + else { |
|
| 1262 | + $date_debut = affdate_jourcourt($d,date("Y",$date_fin)); |
|
| 1263 | + $date_fin = $affdate($f); |
|
| 1264 | + if($jour){ |
|
| 1265 | + $nomjour_debut = nom_jour($d,$abbr); |
|
| 1266 | + $date_debut = _T('date_fmt_jour',array('nomjour'=>$nomjour_debut,'jour' => $date_debut)); |
|
| 1267 | + $nomjour_fin = nom_jour($f,$abbr); |
|
| 1268 | + $date_fin = _T('date_fmt_jour',array('nomjour'=>$nomjour_fin,'jour' => $date_fin)); |
|
| 1269 | + } |
|
| 1270 | + if ($h){ |
|
| 1271 | + $date_debut = _T('date_fmt_jour_heure',array('jour'=>$date_debut,'heure'=>$hd)); |
|
| 1272 | + $date_fin = _T('date_fmt_jour_heure',array('jour'=>$date_fin,'heure'=>$hf)); |
|
| 1273 | + } |
|
| 1274 | 1274 | |
| 1275 | - $date_debut = $dtstart.$date_debut.$dtabbr; |
|
| 1276 | - $date_fin=$dtend.$date_fin.$dtabbr; |
|
| 1277 | - $s = _T('date_fmt_periode',array('date_debut' => $date_debut,'date_fin'=>$date_fin)); |
|
| 1275 | + $date_debut = $dtstart.$date_debut.$dtabbr; |
|
| 1276 | + $date_fin=$dtend.$date_fin.$dtabbr; |
|
| 1277 | + $s = _T('date_fmt_periode',array('date_debut' => $date_debut,'date_fin'=>$date_fin)); |
|
| 1278 | 1278 | |
| 1279 | - } |
|
| 1280 | - return $s; |
|
| 1279 | + } |
|
| 1280 | + return $s; |
|
| 1281 | 1281 | } |
| 1282 | 1282 | |
| 1283 | 1283 | /** |
@@ -1291,15 +1291,15 @@ discard block |
||
| 1291 | 1291 | * @return string |
| 1292 | 1292 | */ |
| 1293 | 1293 | function aligner($letexte, $justif='') { |
| 1294 | - $letexte = trim($letexte); |
|
| 1295 | - if (!strlen($letexte)) return ''; |
|
| 1294 | + $letexte = trim($letexte); |
|
| 1295 | + if (!strlen($letexte)) return ''; |
|
| 1296 | 1296 | |
| 1297 | - // Paragrapher rapidement |
|
| 1298 | - $letexte = "<div style='text-align:$justif'>" |
|
| 1299 | - . $letexte |
|
| 1300 | - ."</div>"; |
|
| 1297 | + // Paragrapher rapidement |
|
| 1298 | + $letexte = "<div style='text-align:$justif'>" |
|
| 1299 | + . $letexte |
|
| 1300 | + ."</div>"; |
|
| 1301 | 1301 | |
| 1302 | - return $letexte; |
|
| 1302 | + return $letexte; |
|
| 1303 | 1303 | } |
| 1304 | 1304 | // http://doc.spip.org/@justifier |
| 1305 | 1305 | function justifier($letexte) { return aligner($letexte,'justify');} |
@@ -1312,8 +1312,8 @@ discard block |
||
| 1312 | 1312 | |
| 1313 | 1313 | // http://doc.spip.org/@style_align |
| 1314 | 1314 | function style_align($bof) { |
| 1315 | - global $spip_lang_left; |
|
| 1316 | - return "text-align: $spip_lang_left"; |
|
| 1315 | + global $spip_lang_left; |
|
| 1316 | + return "text-align: $spip_lang_left"; |
|
| 1317 | 1317 | } |
| 1318 | 1318 | |
| 1319 | 1319 | // |
@@ -1322,69 +1322,69 @@ discard block |
||
| 1322 | 1322 | |
| 1323 | 1323 | // http://doc.spip.org/@filtrer_ical |
| 1324 | 1324 | function filtrer_ical($texte) { |
| 1325 | - #include_spip('inc/charsets'); |
|
| 1326 | - $texte = html2unicode($texte); |
|
| 1327 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8'); |
|
| 1328 | - $texte = preg_replace("/\n/", " ", $texte); |
|
| 1329 | - $texte = preg_replace("/,/", "\,", $texte); |
|
| 1325 | + #include_spip('inc/charsets'); |
|
| 1326 | + $texte = html2unicode($texte); |
|
| 1327 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8'); |
|
| 1328 | + $texte = preg_replace("/\n/", " ", $texte); |
|
| 1329 | + $texte = preg_replace("/,/", "\,", $texte); |
|
| 1330 | 1330 | |
| 1331 | - return $texte; |
|
| 1331 | + return $texte; |
|
| 1332 | 1332 | } |
| 1333 | 1333 | |
| 1334 | 1334 | // http://doc.spip.org/@date_ical |
| 1335 | 1335 | function date_ical($date, $addminutes = 0) { |
| 1336 | - list($heures, $minutes, $secondes) = recup_heure($date); |
|
| 1337 | - list($annee, $mois, $jour) = recup_date($date); |
|
| 1336 | + list($heures, $minutes, $secondes) = recup_heure($date); |
|
| 1337 | + list($annee, $mois, $jour) = recup_date($date); |
|
| 1338 | 1338 | |
| 1339 | - return gmdate("Ymd\THis\Z", mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1339 | + return gmdate("Ymd\THis\Z", mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1340 | 1340 | } |
| 1341 | 1341 | |
| 1342 | 1342 | // date_iso retourne la date au format "RFC 3339" / "ISO 8601" |
| 1343 | 1343 | // voir http://www.php.net/manual/fr/ref.datetime.php#datetime.constants |
| 1344 | 1344 | // http://doc.spip.org/@date_iso |
| 1345 | 1345 | function date_iso($date_heure) { |
| 1346 | - list($annee, $mois, $jour) = recup_date($date_heure); |
|
| 1347 | - list($heures, $minutes, $secondes) = recup_heure($date_heure); |
|
| 1348 | - $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1349 | - return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1346 | + list($annee, $mois, $jour) = recup_date($date_heure); |
|
| 1347 | + list($heures, $minutes, $secondes) = recup_heure($date_heure); |
|
| 1348 | + $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1349 | + return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1350 | 1350 | } |
| 1351 | 1351 | |
| 1352 | 1352 | // date_822 retourne la date au format "RFC 822" |
| 1353 | 1353 | // utilise pour <pubdate> dans certains feeds RSS |
| 1354 | 1354 | // http://doc.spip.org/@date_822 |
| 1355 | 1355 | function date_822($date_heure) { |
| 1356 | - list($annee, $mois, $jour) = recup_date($date_heure); |
|
| 1357 | - list($heures, $minutes, $secondes) = recup_heure($date_heure); |
|
| 1358 | - $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1359 | - return date('r', $time); |
|
| 1356 | + list($annee, $mois, $jour) = recup_date($date_heure); |
|
| 1357 | + list($heures, $minutes, $secondes) = recup_heure($date_heure); |
|
| 1358 | + $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1359 | + return date('r', $time); |
|
| 1360 | 1360 | } |
| 1361 | 1361 | |
| 1362 | 1362 | // http://doc.spip.org/@date_anneemoisjour |
| 1363 | 1363 | function date_anneemoisjour($d) { |
| 1364 | - if (!$d) $d = date("Y-m-d"); |
|
| 1365 | - return substr($d, 0, 4) . substr($d, 5, 2) .substr($d, 8, 2); |
|
| 1364 | + if (!$d) $d = date("Y-m-d"); |
|
| 1365 | + return substr($d, 0, 4) . substr($d, 5, 2) .substr($d, 8, 2); |
|
| 1366 | 1366 | } |
| 1367 | 1367 | |
| 1368 | 1368 | // http://doc.spip.org/@date_anneemois |
| 1369 | 1369 | function date_anneemois($d) { |
| 1370 | - if (!$d) $d = date("Y-m-d"); |
|
| 1371 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1370 | + if (!$d) $d = date("Y-m-d"); |
|
| 1371 | + return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | 1374 | // http://doc.spip.org/@date_debut_semaine |
| 1375 | 1375 | function date_debut_semaine($annee, $mois, $jour) { |
| 1376 | - $w_day = date("w", mktime(0,0,0,$mois, $jour, $annee)); |
|
| 1377 | - if ($w_day == 0) $w_day = 7; // Gaffe: le dimanche est zero |
|
| 1378 | - $debut = $jour-$w_day+1; |
|
| 1379 | - return date("Ymd", mktime(0,0,0,$mois,$debut,$annee)); |
|
| 1376 | + $w_day = date("w", mktime(0,0,0,$mois, $jour, $annee)); |
|
| 1377 | + if ($w_day == 0) $w_day = 7; // Gaffe: le dimanche est zero |
|
| 1378 | + $debut = $jour-$w_day+1; |
|
| 1379 | + return date("Ymd", mktime(0,0,0,$mois,$debut,$annee)); |
|
| 1380 | 1380 | } |
| 1381 | 1381 | |
| 1382 | 1382 | // http://doc.spip.org/@date_fin_semaine |
| 1383 | 1383 | function date_fin_semaine($annee, $mois, $jour) { |
| 1384 | - $w_day = date("w", mktime(0,0,0,$mois, $jour, $annee)); |
|
| 1385 | - if ($w_day == 0) $w_day = 7; // Gaffe: le dimanche est zero |
|
| 1386 | - $debut = $jour-$w_day+1; |
|
| 1387 | - return date("Ymd", mktime(0,0,0,$mois,$debut+6,$annee)); |
|
| 1384 | + $w_day = date("w", mktime(0,0,0,$mois, $jour, $annee)); |
|
| 1385 | + if ($w_day == 0) $w_day = 7; // Gaffe: le dimanche est zero |
|
| 1386 | + $debut = $jour-$w_day+1; |
|
| 1387 | + return date("Ymd", mktime(0,0,0,$mois,$debut+6,$annee)); |
|
| 1388 | 1388 | } |
| 1389 | 1389 | |
| 1390 | 1390 | |
@@ -1394,55 +1394,55 @@ discard block |
||
| 1394 | 1394 | // |
| 1395 | 1395 | // http://doc.spip.org/@extra |
| 1396 | 1396 | function extra($letexte, $champ) { |
| 1397 | - $champs = unserialize($letexte); |
|
| 1398 | - return $champs[$champ]; |
|
| 1397 | + $champs = unserialize($letexte); |
|
| 1398 | + return $champs[$champ]; |
|
| 1399 | 1399 | } |
| 1400 | 1400 | |
| 1401 | 1401 | // postautobr : transforme les sauts de ligne en _ |
| 1402 | 1402 | // http://doc.spip.org/@post_autobr |
| 1403 | 1403 | function post_autobr($texte, $delim="\n_ ") { |
| 1404 | - if (!function_exists('echappe_html')) |
|
| 1405 | - include_spip('inc/texte_mini'); |
|
| 1406 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1407 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1408 | - |
|
| 1409 | - if (preg_match(",\n+$,", $texte, $fin)) |
|
| 1410 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1411 | - else |
|
| 1412 | - $fin = ''; |
|
| 1413 | - |
|
| 1414 | - $texte = echappe_html($texte, '', true); |
|
| 1415 | - |
|
| 1416 | - // echapper les modeles |
|
| 1417 | - if (strpos($texte,"<")!==false){ |
|
| 1418 | - include_spip('inc/lien'); |
|
| 1419 | - if (defined('_PREG_MODELE')){ |
|
| 1420 | - $preg_modeles = "@"._PREG_MODELE."@imsS"; |
|
| 1421 | - $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1422 | - } |
|
| 1423 | - } |
|
| 1424 | - |
|
| 1425 | - $debut = ''; |
|
| 1426 | - $suite = $texte; |
|
| 1427 | - while ($t = strpos('-'.$suite, "\n", 1)) { |
|
| 1428 | - $debut .= substr($suite, 0, $t-1); |
|
| 1429 | - $suite = substr($suite, $t); |
|
| 1430 | - $car = substr($suite, 0, 1); |
|
| 1431 | - if (($car<>'-') AND ($car<>'_') AND ($car<>"\n") AND ($car<>"|") AND ($car<>"}") |
|
| 1432 | - AND !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S',($suite)) |
|
| 1433 | - AND !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)) { |
|
| 1434 | - $debut .= $delim; |
|
| 1435 | - } else |
|
| 1436 | - $debut .= "\n"; |
|
| 1437 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1438 | - $debut.=$regs[0]; |
|
| 1439 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1440 | - } |
|
| 1441 | - } |
|
| 1442 | - $texte = $debut.$suite; |
|
| 1443 | - |
|
| 1444 | - $texte = echappe_retour($texte); |
|
| 1445 | - return $texte.$fin; |
|
| 1404 | + if (!function_exists('echappe_html')) |
|
| 1405 | + include_spip('inc/texte_mini'); |
|
| 1406 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1407 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1408 | + |
|
| 1409 | + if (preg_match(",\n+$,", $texte, $fin)) |
|
| 1410 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1411 | + else |
|
| 1412 | + $fin = ''; |
|
| 1413 | + |
|
| 1414 | + $texte = echappe_html($texte, '', true); |
|
| 1415 | + |
|
| 1416 | + // echapper les modeles |
|
| 1417 | + if (strpos($texte,"<")!==false){ |
|
| 1418 | + include_spip('inc/lien'); |
|
| 1419 | + if (defined('_PREG_MODELE')){ |
|
| 1420 | + $preg_modeles = "@"._PREG_MODELE."@imsS"; |
|
| 1421 | + $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1422 | + } |
|
| 1423 | + } |
|
| 1424 | + |
|
| 1425 | + $debut = ''; |
|
| 1426 | + $suite = $texte; |
|
| 1427 | + while ($t = strpos('-'.$suite, "\n", 1)) { |
|
| 1428 | + $debut .= substr($suite, 0, $t-1); |
|
| 1429 | + $suite = substr($suite, $t); |
|
| 1430 | + $car = substr($suite, 0, 1); |
|
| 1431 | + if (($car<>'-') AND ($car<>'_') AND ($car<>"\n") AND ($car<>"|") AND ($car<>"}") |
|
| 1432 | + AND !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S',($suite)) |
|
| 1433 | + AND !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)) { |
|
| 1434 | + $debut .= $delim; |
|
| 1435 | + } else |
|
| 1436 | + $debut .= "\n"; |
|
| 1437 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1438 | + $debut.=$regs[0]; |
|
| 1439 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | + $texte = $debut.$suite; |
|
| 1443 | + |
|
| 1444 | + $texte = echappe_retour($texte); |
|
| 1445 | + return $texte.$fin; |
|
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | 1448 | |
@@ -1452,63 +1452,63 @@ discard block |
||
| 1452 | 1452 | // pour ne pas mettre de span@lang=fr si on est deja en fr |
| 1453 | 1453 | // http://doc.spip.org/@extraire_multi |
| 1454 | 1454 | function extraire_multi($letexte, $lang=null, $echappe_span=false) { |
| 1455 | - if (preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 1456 | - if (!$lang) $lang = $GLOBALS['spip_lang']; |
|
| 1457 | - |
|
| 1458 | - foreach ($regs as $reg) { |
|
| 1459 | - // chercher la version de la langue courante |
|
| 1460 | - $trads = extraire_trads($reg[1]); |
|
| 1461 | - if ($l = approcher_langue($trads, $lang)) { |
|
| 1462 | - $trad = $trads[$l]; |
|
| 1463 | - } else { |
|
| 1464 | - include_spip('inc/texte'); |
|
| 1465 | - // langue absente, prendre la premiere dispo |
|
| 1466 | - // mais typographier le texte selon les regles de celle-ci |
|
| 1467 | - // Attention aux blocs multi sur plusieurs lignes |
|
| 1468 | - $l = key($trads); |
|
| 1469 | - $trad = $trads[$l]; |
|
| 1470 | - $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1471 | - $trad = $typographie($trad); |
|
| 1472 | - include_spip('inc/texte'); |
|
| 1473 | - // Tester si on echappe en span ou en div |
|
| 1474 | - // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1475 | - $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims","",propre($trad)); |
|
| 1476 | - $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1477 | - $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1478 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1479 | - if (lang_dir($l) !== lang_dir($lang)) |
|
| 1480 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1481 | - if (!$echappe_span) |
|
| 1482 | - $trad = echappe_retour($trad, 'multi'); |
|
| 1483 | - } |
|
| 1484 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1485 | - } |
|
| 1486 | - } |
|
| 1487 | - |
|
| 1488 | - return $letexte; |
|
| 1455 | + if (preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 1456 | + if (!$lang) $lang = $GLOBALS['spip_lang']; |
|
| 1457 | + |
|
| 1458 | + foreach ($regs as $reg) { |
|
| 1459 | + // chercher la version de la langue courante |
|
| 1460 | + $trads = extraire_trads($reg[1]); |
|
| 1461 | + if ($l = approcher_langue($trads, $lang)) { |
|
| 1462 | + $trad = $trads[$l]; |
|
| 1463 | + } else { |
|
| 1464 | + include_spip('inc/texte'); |
|
| 1465 | + // langue absente, prendre la premiere dispo |
|
| 1466 | + // mais typographier le texte selon les regles de celle-ci |
|
| 1467 | + // Attention aux blocs multi sur plusieurs lignes |
|
| 1468 | + $l = key($trads); |
|
| 1469 | + $trad = $trads[$l]; |
|
| 1470 | + $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1471 | + $trad = $typographie($trad); |
|
| 1472 | + include_spip('inc/texte'); |
|
| 1473 | + // Tester si on echappe en span ou en div |
|
| 1474 | + // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1475 | + $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims","",propre($trad)); |
|
| 1476 | + $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1477 | + $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1478 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1479 | + if (lang_dir($l) !== lang_dir($lang)) |
|
| 1480 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1481 | + if (!$echappe_span) |
|
| 1482 | + $trad = echappe_retour($trad, 'multi'); |
|
| 1483 | + } |
|
| 1484 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1485 | + } |
|
| 1486 | + } |
|
| 1487 | + |
|
| 1488 | + return $letexte; |
|
| 1489 | 1489 | } |
| 1490 | 1490 | |
| 1491 | 1491 | // convertit le contenu d'une balise multi en un tableau |
| 1492 | 1492 | // http://doc.spip.org/@extraire_trad |
| 1493 | 1493 | function extraire_trads($bloc) { |
| 1494 | - $lang = ''; |
|
| 1494 | + $lang = ''; |
|
| 1495 | 1495 | // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ |
| 1496 | 1496 | // while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) { |
| 1497 | - while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) { |
|
| 1498 | - $texte = trim($regs[1]); |
|
| 1499 | - if ($texte OR $lang) |
|
| 1500 | - $trads[$lang] = $texte; |
|
| 1501 | - $bloc = substr($bloc, strlen($regs[0])); |
|
| 1502 | - $lang = $regs[2]; |
|
| 1503 | - } |
|
| 1504 | - $trads[$lang] = $bloc; |
|
| 1497 | + while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) { |
|
| 1498 | + $texte = trim($regs[1]); |
|
| 1499 | + if ($texte OR $lang) |
|
| 1500 | + $trads[$lang] = $texte; |
|
| 1501 | + $bloc = substr($bloc, strlen($regs[0])); |
|
| 1502 | + $lang = $regs[2]; |
|
| 1503 | + } |
|
| 1504 | + $trads[$lang] = $bloc; |
|
| 1505 | 1505 | |
| 1506 | - return $trads; |
|
| 1506 | + return $trads; |
|
| 1507 | 1507 | } |
| 1508 | 1508 | |
| 1509 | 1509 | // Calculer l'initiale d'un nom |
| 1510 | 1510 | function initiale($nom){ |
| 1511 | - return spip_substr(trim(strtoupper(extraire_multi($nom))),0,1); |
|
| 1511 | + return spip_substr(trim(strtoupper(extraire_multi($nom))),0,1); |
|
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | 1514 | // |
@@ -1522,31 +1522,31 @@ discard block |
||
| 1522 | 1522 | // http://www.spip.net/@unique |
| 1523 | 1523 | // http://doc.spip.org/@unique |
| 1524 | 1524 | function unique($donnee, $famille='', $cpt = false) { |
| 1525 | - static $mem = array(); |
|
| 1526 | - // permettre de vider la pile et de la restaurer |
|
| 1527 | - // pour le calcul de introduction... |
|
| 1528 | - if ($famille=='_spip_raz_'){ |
|
| 1529 | - $tmp = $mem; |
|
| 1530 | - $mem = array(); |
|
| 1531 | - return $tmp; |
|
| 1532 | - } elseif ($famille=='_spip_set_'){ |
|
| 1533 | - $mem = $donnee; |
|
| 1534 | - return; |
|
| 1535 | - } |
|
| 1536 | - // eviter une notice |
|
| 1537 | - if (!isset($mem[$famille])) { |
|
| 1538 | - $mem[$famille] = array(); |
|
| 1539 | - } |
|
| 1540 | - if ($cpt) { |
|
| 1541 | - return count($mem[$famille]); |
|
| 1542 | - } |
|
| 1543 | - // eviter une notice |
|
| 1544 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1545 | - $mem[$famille][$donnee] = 0; |
|
| 1546 | - } |
|
| 1547 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1548 | - return $donnee; |
|
| 1549 | - } |
|
| 1525 | + static $mem = array(); |
|
| 1526 | + // permettre de vider la pile et de la restaurer |
|
| 1527 | + // pour le calcul de introduction... |
|
| 1528 | + if ($famille=='_spip_raz_'){ |
|
| 1529 | + $tmp = $mem; |
|
| 1530 | + $mem = array(); |
|
| 1531 | + return $tmp; |
|
| 1532 | + } elseif ($famille=='_spip_set_'){ |
|
| 1533 | + $mem = $donnee; |
|
| 1534 | + return; |
|
| 1535 | + } |
|
| 1536 | + // eviter une notice |
|
| 1537 | + if (!isset($mem[$famille])) { |
|
| 1538 | + $mem[$famille] = array(); |
|
| 1539 | + } |
|
| 1540 | + if ($cpt) { |
|
| 1541 | + return count($mem[$famille]); |
|
| 1542 | + } |
|
| 1543 | + // eviter une notice |
|
| 1544 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1545 | + $mem[$famille][$donnee] = 0; |
|
| 1546 | + } |
|
| 1547 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1548 | + return $donnee; |
|
| 1549 | + } |
|
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | 1552 | // |
@@ -1556,18 +1556,18 @@ discard block |
||
| 1556 | 1556 | // |
| 1557 | 1557 | // http://doc.spip.org/@alterner |
| 1558 | 1558 | function alterner($i) { |
| 1559 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1560 | - $num = func_num_args(); |
|
| 1561 | - $args = func_get_args(); |
|
| 1559 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1560 | + $num = func_num_args(); |
|
| 1561 | + $args = func_get_args(); |
|
| 1562 | 1562 | |
| 1563 | - if($num == 2 && is_array($args[1])) { |
|
| 1563 | + if($num == 2 && is_array($args[1])) { |
|
| 1564 | 1564 | $args = $args[1]; |
| 1565 | 1565 | array_unshift($args,''); |
| 1566 | 1566 | $num = count($args); |
| 1567 | - } |
|
| 1567 | + } |
|
| 1568 | 1568 | |
| 1569 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1570 | - return $args[(intval($i)-1)%($num-1)+1]; |
|
| 1569 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1570 | + return $args[(intval($i)-1)%($num-1)+1]; |
|
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | 1573 | // recuperer un attribut d'une balise html |
@@ -1577,41 +1577,41 @@ discard block |
||
| 1577 | 1577 | // (dans ce cas l'option $complet n'est pas disponible) |
| 1578 | 1578 | // http://doc.spip.org/@extraire_attribut |
| 1579 | 1579 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1580 | - if (is_array($balise)) { |
|
| 1581 | - array_walk($balise, |
|
| 1582 | - create_function('&$a,$key,$t', |
|
| 1583 | - '$a = extraire_attribut($a,$t);' |
|
| 1584 | - ), |
|
| 1585 | - $attribut); |
|
| 1586 | - return $balise; |
|
| 1587 | - } |
|
| 1588 | - if (preg_match( |
|
| 1589 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1590 | - .$attribut |
|
| 1591 | - .'(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()([^>]*>.*),isS', |
|
| 1592 | - |
|
| 1593 | - $balise, $r)) { |
|
| 1594 | - if ($r[3][0] == '"' || $r[3][0] == "'") { |
|
| 1595 | - $r[4] = substr($r[3], 1, -1); |
|
| 1596 | - $r[3] = $r[3][0]; |
|
| 1597 | - } elseif ($r[3]!=='') { |
|
| 1598 | - $r[4] = $r[3]; |
|
| 1599 | - $r[3] = ''; |
|
| 1600 | - } else { |
|
| 1601 | - $r[4] = trim($r[2]); |
|
| 1602 | - } |
|
| 1603 | - $att = $r[4]; |
|
| 1604 | - if (strpos($att,"&#")!==false) |
|
| 1605 | - $att = str_replace(array("'","'",""","""), array("'","'",'"','"'), $att); |
|
| 1606 | - $att = filtrer_entites($att); |
|
| 1607 | - } |
|
| 1608 | - else |
|
| 1609 | - $att = NULL; |
|
| 1610 | - |
|
| 1611 | - if ($complet) |
|
| 1612 | - return array($att, $r); |
|
| 1613 | - else |
|
| 1614 | - return $att; |
|
| 1580 | + if (is_array($balise)) { |
|
| 1581 | + array_walk($balise, |
|
| 1582 | + create_function('&$a,$key,$t', |
|
| 1583 | + '$a = extraire_attribut($a,$t);' |
|
| 1584 | + ), |
|
| 1585 | + $attribut); |
|
| 1586 | + return $balise; |
|
| 1587 | + } |
|
| 1588 | + if (preg_match( |
|
| 1589 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1590 | + .$attribut |
|
| 1591 | + .'(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()([^>]*>.*),isS', |
|
| 1592 | + |
|
| 1593 | + $balise, $r)) { |
|
| 1594 | + if ($r[3][0] == '"' || $r[3][0] == "'") { |
|
| 1595 | + $r[4] = substr($r[3], 1, -1); |
|
| 1596 | + $r[3] = $r[3][0]; |
|
| 1597 | + } elseif ($r[3]!=='') { |
|
| 1598 | + $r[4] = $r[3]; |
|
| 1599 | + $r[3] = ''; |
|
| 1600 | + } else { |
|
| 1601 | + $r[4] = trim($r[2]); |
|
| 1602 | + } |
|
| 1603 | + $att = $r[4]; |
|
| 1604 | + if (strpos($att,"&#")!==false) |
|
| 1605 | + $att = str_replace(array("'","'",""","""), array("'","'",'"','"'), $att); |
|
| 1606 | + $att = filtrer_entites($att); |
|
| 1607 | + } |
|
| 1608 | + else |
|
| 1609 | + $att = NULL; |
|
| 1610 | + |
|
| 1611 | + if ($complet) |
|
| 1612 | + return array($att, $r); |
|
| 1613 | + else |
|
| 1614 | + return $att; |
|
| 1615 | 1615 | } |
| 1616 | 1616 | |
| 1617 | 1617 | /** |
@@ -1627,39 +1627,39 @@ discard block |
||
| 1627 | 1627 | * @return string |
| 1628 | 1628 | */ |
| 1629 | 1629 | function inserer_attribut($balise, $attribut, $val, $proteger=true, $vider=false) { |
| 1630 | - // preparer l'attribut |
|
| 1631 | - // supprimer les etc mais pas les balises html |
|
| 1632 | - // qui ont un sens dans un attribut value d'un input |
|
| 1633 | - if ($proteger) $val = attribut_html($val,false); |
|
| 1634 | - |
|
| 1635 | - // echapper les ' pour eviter tout bug |
|
| 1636 | - $val = str_replace("'", "'", $val); |
|
| 1637 | - if ($vider AND strlen($val)==0) |
|
| 1638 | - $insert = ''; |
|
| 1639 | - else |
|
| 1640 | - $insert = " $attribut='$val'"; |
|
| 1641 | - |
|
| 1642 | - list($old, $r) = extraire_attribut($balise, $attribut, true); |
|
| 1643 | - |
|
| 1644 | - if ($old !== NULL) { |
|
| 1645 | - // Remplacer l'ancien attribut du meme nom |
|
| 1646 | - $balise = $r[1].$insert.$r[5]; |
|
| 1647 | - } |
|
| 1648 | - else { |
|
| 1649 | - // preferer une balise " />" (comme <img />) |
|
| 1650 | - if (preg_match(',/>,', $balise)) |
|
| 1651 | - $balise = preg_replace(",\s?/>,S", $insert." />", $balise, 1); |
|
| 1652 | - // sinon une balise <a ...> ... </a> |
|
| 1653 | - else |
|
| 1654 | - $balise = preg_replace(",\s?>,S", $insert.">", $balise, 1); |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - return $balise; |
|
| 1630 | + // preparer l'attribut |
|
| 1631 | + // supprimer les etc mais pas les balises html |
|
| 1632 | + // qui ont un sens dans un attribut value d'un input |
|
| 1633 | + if ($proteger) $val = attribut_html($val,false); |
|
| 1634 | + |
|
| 1635 | + // echapper les ' pour eviter tout bug |
|
| 1636 | + $val = str_replace("'", "'", $val); |
|
| 1637 | + if ($vider AND strlen($val)==0) |
|
| 1638 | + $insert = ''; |
|
| 1639 | + else |
|
| 1640 | + $insert = " $attribut='$val'"; |
|
| 1641 | + |
|
| 1642 | + list($old, $r) = extraire_attribut($balise, $attribut, true); |
|
| 1643 | + |
|
| 1644 | + if ($old !== NULL) { |
|
| 1645 | + // Remplacer l'ancien attribut du meme nom |
|
| 1646 | + $balise = $r[1].$insert.$r[5]; |
|
| 1647 | + } |
|
| 1648 | + else { |
|
| 1649 | + // preferer une balise " />" (comme <img />) |
|
| 1650 | + if (preg_match(',/>,', $balise)) |
|
| 1651 | + $balise = preg_replace(",\s?/>,S", $insert." />", $balise, 1); |
|
| 1652 | + // sinon une balise <a ...> ... </a> |
|
| 1653 | + else |
|
| 1654 | + $balise = preg_replace(",\s?>,S", $insert.">", $balise, 1); |
|
| 1655 | + } |
|
| 1656 | + |
|
| 1657 | + return $balise; |
|
| 1658 | 1658 | } |
| 1659 | 1659 | |
| 1660 | 1660 | // http://doc.spip.org/@vider_attribut |
| 1661 | 1661 | function vider_attribut ($balise, $attribut) { |
| 1662 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 1662 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 1663 | 1663 | } |
| 1664 | 1664 | |
| 1665 | 1665 | |
@@ -1671,8 +1671,8 @@ discard block |
||
| 1671 | 1671 | * @return string |
| 1672 | 1672 | */ |
| 1673 | 1673 | function tester_config($id, $mode='') { |
| 1674 | - include_spip('action/inscrire_auteur'); |
|
| 1675 | - return tester_statut_inscription($mode, $id); |
|
| 1674 | + include_spip('action/inscrire_auteur'); |
|
| 1675 | + return tester_statut_inscription($mode, $id); |
|
| 1676 | 1676 | } |
| 1677 | 1677 | |
| 1678 | 1678 | // |
@@ -1680,23 +1680,23 @@ discard block |
||
| 1680 | 1680 | // |
| 1681 | 1681 | // http://doc.spip.org/@plus |
| 1682 | 1682 | function plus($a,$b) { |
| 1683 | - return $a+$b; |
|
| 1683 | + return $a+$b; |
|
| 1684 | 1684 | } |
| 1685 | 1685 | // http://doc.spip.org/@moins |
| 1686 | 1686 | function moins($a,$b) { |
| 1687 | - return $a-$b; |
|
| 1687 | + return $a-$b; |
|
| 1688 | 1688 | } |
| 1689 | 1689 | // http://doc.spip.org/@mult |
| 1690 | 1690 | function mult($a,$b) { |
| 1691 | - return $a*$b; |
|
| 1691 | + return $a*$b; |
|
| 1692 | 1692 | } |
| 1693 | 1693 | // http://doc.spip.org/@div |
| 1694 | 1694 | function div($a,$b) { |
| 1695 | - return $b?$a/$b:0; |
|
| 1695 | + return $b?$a/$b:0; |
|
| 1696 | 1696 | } |
| 1697 | 1697 | // http://doc.spip.org/@modulo |
| 1698 | 1698 | function modulo($nb, $mod, $add=0) { |
| 1699 | - return ($mod?$nb%$mod:0)+$add; |
|
| 1699 | + return ($mod?$nb%$mod:0)+$add; |
|
| 1700 | 1700 | } |
| 1701 | 1701 | |
| 1702 | 1702 | |
@@ -1711,72 +1711,72 @@ discard block |
||
| 1711 | 1711 | * - true sinon |
| 1712 | 1712 | **/ |
| 1713 | 1713 | function nom_acceptable($nom) { |
| 1714 | - if (!is_string($nom)) { |
|
| 1715 | - return false; |
|
| 1716 | - } |
|
| 1717 | - if (!defined('_TAGS_NOM_AUTEUR')) define('_TAGS_NOM_AUTEUR',''); |
|
| 1718 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 1719 | - foreach($tags_acceptes as $tag) { |
|
| 1720 | - if (strlen($tag)) { |
|
| 1721 | - $remp1[] = '<'.trim($tag).'>'; |
|
| 1722 | - $remp1[] = '</'.trim($tag).'>'; |
|
| 1723 | - $remp2[] = '\x60'.trim($tag).'\x61'; |
|
| 1724 | - $remp2[] = '\x60/'.trim($tag).'\x61'; |
|
| 1725 | - } |
|
| 1726 | - } |
|
| 1727 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 1728 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 1714 | + if (!is_string($nom)) { |
|
| 1715 | + return false; |
|
| 1716 | + } |
|
| 1717 | + if (!defined('_TAGS_NOM_AUTEUR')) define('_TAGS_NOM_AUTEUR',''); |
|
| 1718 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 1719 | + foreach($tags_acceptes as $tag) { |
|
| 1720 | + if (strlen($tag)) { |
|
| 1721 | + $remp1[] = '<'.trim($tag).'>'; |
|
| 1722 | + $remp1[] = '</'.trim($tag).'>'; |
|
| 1723 | + $remp2[] = '\x60'.trim($tag).'\x61'; |
|
| 1724 | + $remp2[] = '\x60/'.trim($tag).'\x61'; |
|
| 1725 | + } |
|
| 1726 | + } |
|
| 1727 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 1728 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 1729 | 1729 | } |
| 1730 | 1730 | |
| 1731 | 1731 | // Verifier la conformite d'une ou plusieurs adresses email |
| 1732 | 1732 | // retourne false ou la normalisation de la derniere adresse donnee |
| 1733 | 1733 | // http://doc.spip.org/@email_valide |
| 1734 | 1734 | function email_valide($adresses) { |
| 1735 | - // eviter d'injecter n'importe quoi dans preg_match |
|
| 1736 | - if (!is_string($adresses)) |
|
| 1737 | - return false; |
|
| 1738 | - |
|
| 1739 | - // Si c'est un spammeur autant arreter tout de suite |
|
| 1740 | - if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) { |
|
| 1741 | - spip_log("Tentative d'injection de mail : $adresses"); |
|
| 1742 | - return false; |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - foreach (explode(',', $adresses) as $v) { |
|
| 1746 | - // nettoyer certains formats |
|
| 1747 | - // "Marie Toto <[email protected]>" |
|
| 1748 | - $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v)); |
|
| 1749 | - // RFC 822 |
|
| 1750 | - if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) |
|
| 1751 | - return false; |
|
| 1752 | - } |
|
| 1753 | - return $adresse; |
|
| 1735 | + // eviter d'injecter n'importe quoi dans preg_match |
|
| 1736 | + if (!is_string($adresses)) |
|
| 1737 | + return false; |
|
| 1738 | + |
|
| 1739 | + // Si c'est un spammeur autant arreter tout de suite |
|
| 1740 | + if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) { |
|
| 1741 | + spip_log("Tentative d'injection de mail : $adresses"); |
|
| 1742 | + return false; |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + foreach (explode(',', $adresses) as $v) { |
|
| 1746 | + // nettoyer certains formats |
|
| 1747 | + // "Marie Toto <[email protected]>" |
|
| 1748 | + $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v)); |
|
| 1749 | + // RFC 822 |
|
| 1750 | + if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) |
|
| 1751 | + return false; |
|
| 1752 | + } |
|
| 1753 | + return $adresse; |
|
| 1754 | 1754 | } |
| 1755 | 1755 | |
| 1756 | 1756 | // http://doc.spip.org/@afficher_enclosures |
| 1757 | 1757 | function afficher_enclosures($tags) { |
| 1758 | - $s = array(); |
|
| 1759 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 1760 | - if (extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 1761 | - AND $t = extraire_attribut($tag, 'href')) { |
|
| 1762 | - $s[] = preg_replace(',>[^<]+</a>,S', |
|
| 1763 | - '>' |
|
| 1764 | - .http_img_pack('attachment-16.png', $t, |
|
| 1765 | - 'title="'.attribut_html($t).'"') |
|
| 1766 | - .'</a>', $tag); |
|
| 1767 | - } |
|
| 1768 | - } |
|
| 1769 | - return join(' ', $s); |
|
| 1758 | + $s = array(); |
|
| 1759 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 1760 | + if (extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 1761 | + AND $t = extraire_attribut($tag, 'href')) { |
|
| 1762 | + $s[] = preg_replace(',>[^<]+</a>,S', |
|
| 1763 | + '>' |
|
| 1764 | + .http_img_pack('attachment-16.png', $t, |
|
| 1765 | + 'title="'.attribut_html($t).'"') |
|
| 1766 | + .'</a>', $tag); |
|
| 1767 | + } |
|
| 1768 | + } |
|
| 1769 | + return join(' ', $s); |
|
| 1770 | 1770 | } |
| 1771 | 1771 | // http://doc.spip.org/@afficher_tags |
| 1772 | 1772 | function afficher_tags($tags, $rels='tag,directory') { |
| 1773 | - $s = array(); |
|
| 1774 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 1775 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 1776 | - if (strstr(",$rels,", ",$rel,")) |
|
| 1777 | - $s[] = $tag; |
|
| 1778 | - } |
|
| 1779 | - return join(', ', $s); |
|
| 1773 | + $s = array(); |
|
| 1774 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 1775 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 1776 | + if (strstr(",$rels,", ",$rel,")) |
|
| 1777 | + $s[] = $tag; |
|
| 1778 | + } |
|
| 1779 | + return join(', ', $s); |
|
| 1780 | 1780 | } |
| 1781 | 1781 | |
| 1782 | 1782 | // Passe un <enclosure url="fichier" length="5588242" type="audio/mpeg"/> |
@@ -1784,51 +1784,51 @@ discard block |
||
| 1784 | 1784 | // attention length="zz" devient title="zz", pour rester conforme |
| 1785 | 1785 | // http://doc.spip.org/@enclosure2microformat |
| 1786 | 1786 | function enclosure2microformat($e) { |
| 1787 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) |
|
| 1788 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 1789 | - $type = extraire_attribut($e, 'type'); |
|
| 1790 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 1791 | - # <media:content : longeur dans fileSize. On tente. |
|
| 1792 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 1793 | - } |
|
| 1794 | - $fichier = basename($url); |
|
| 1795 | - return '<a rel="enclosure"' |
|
| 1796 | - . ($url? ' href="'.spip_htmlspecialchars($url).'"' : '') |
|
| 1797 | - . ($type? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 1798 | - . ($length? ' title="'.spip_htmlspecialchars($length).'"' : '') |
|
| 1799 | - . '>'.$fichier.'</a>'; |
|
| 1787 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) |
|
| 1788 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 1789 | + $type = extraire_attribut($e, 'type'); |
|
| 1790 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 1791 | + # <media:content : longeur dans fileSize. On tente. |
|
| 1792 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 1793 | + } |
|
| 1794 | + $fichier = basename($url); |
|
| 1795 | + return '<a rel="enclosure"' |
|
| 1796 | + . ($url? ' href="'.spip_htmlspecialchars($url).'"' : '') |
|
| 1797 | + . ($type? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 1798 | + . ($length? ' title="'.spip_htmlspecialchars($length).'"' : '') |
|
| 1799 | + . '>'.$fichier.'</a>'; |
|
| 1800 | 1800 | } |
| 1801 | 1801 | // La fonction inverse |
| 1802 | 1802 | // http://doc.spip.org/@microformat2enclosure |
| 1803 | 1803 | function microformat2enclosure($tags) { |
| 1804 | - $enclosures = array(); |
|
| 1805 | - foreach (extraire_balises($tags, 'a') as $e) |
|
| 1806 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 1807 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 1808 | - $type = extraire_attribut($e, 'type'); |
|
| 1809 | - if (!$length = intval(extraire_attribut($e, 'title'))) |
|
| 1810 | - $length = intval(extraire_attribut($e, 'length')); # vieux data |
|
| 1811 | - $fichier = basename($url); |
|
| 1812 | - $enclosures[] = '<enclosure' |
|
| 1813 | - . ($url? ' url="'.spip_htmlspecialchars($url).'"' : '') |
|
| 1814 | - . ($type? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 1815 | - . ($length? ' length="'.$length.'"' : '') |
|
| 1816 | - . ' />'; |
|
| 1817 | - } |
|
| 1818 | - return join("\n", $enclosures); |
|
| 1804 | + $enclosures = array(); |
|
| 1805 | + foreach (extraire_balises($tags, 'a') as $e) |
|
| 1806 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 1807 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 1808 | + $type = extraire_attribut($e, 'type'); |
|
| 1809 | + if (!$length = intval(extraire_attribut($e, 'title'))) |
|
| 1810 | + $length = intval(extraire_attribut($e, 'length')); # vieux data |
|
| 1811 | + $fichier = basename($url); |
|
| 1812 | + $enclosures[] = '<enclosure' |
|
| 1813 | + . ($url? ' url="'.spip_htmlspecialchars($url).'"' : '') |
|
| 1814 | + . ($type? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 1815 | + . ($length? ' length="'.$length.'"' : '') |
|
| 1816 | + . ' />'; |
|
| 1817 | + } |
|
| 1818 | + return join("\n", $enclosures); |
|
| 1819 | 1819 | } |
| 1820 | 1820 | // Creer les elements ATOM <dc:subject> a partir des tags |
| 1821 | 1821 | // http://doc.spip.org/@tags2dcsubject |
| 1822 | 1822 | function tags2dcsubject($tags) { |
| 1823 | - $subjects = ''; |
|
| 1824 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 1825 | - if (extraire_attribut($e, rel) == 'tag') { |
|
| 1826 | - $subjects .= '<dc:subject>' |
|
| 1827 | - . texte_backend(textebrut($e)) |
|
| 1828 | - . '</dc:subject>'."\n"; |
|
| 1829 | - } |
|
| 1830 | - } |
|
| 1831 | - return $subjects; |
|
| 1823 | + $subjects = ''; |
|
| 1824 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 1825 | + if (extraire_attribut($e, rel) == 'tag') { |
|
| 1826 | + $subjects .= '<dc:subject>' |
|
| 1827 | + . texte_backend(textebrut($e)) |
|
| 1828 | + . '</dc:subject>'."\n"; |
|
| 1829 | + } |
|
| 1830 | + } |
|
| 1831 | + return $subjects; |
|
| 1832 | 1832 | } |
| 1833 | 1833 | |
| 1834 | 1834 | // retourne la premiere balise du type demande |
@@ -1836,36 +1836,36 @@ discard block |
||
| 1836 | 1836 | // Si on a passe un tableau de textes, renvoyer un tableau de resultats |
| 1837 | 1837 | // http://doc.spip.org/@extraire_balise |
| 1838 | 1838 | function extraire_balise($texte, $tag='a') { |
| 1839 | - if (is_array($texte)) { |
|
| 1840 | - array_walk($texte, |
|
| 1841 | - create_function('&$a,$key,$t', '$a = extraire_balise($a,$t);'), |
|
| 1842 | - $tag); |
|
| 1843 | - return $texte; |
|
| 1844 | - } |
|
| 1839 | + if (is_array($texte)) { |
|
| 1840 | + array_walk($texte, |
|
| 1841 | + create_function('&$a,$key,$t', '$a = extraire_balise($a,$t);'), |
|
| 1842 | + $tag); |
|
| 1843 | + return $texte; |
|
| 1844 | + } |
|
| 1845 | 1845 | |
| 1846 | - if (preg_match( |
|
| 1847 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 1848 | - $texte, $regs)) |
|
| 1849 | - return $regs[0]; |
|
| 1846 | + if (preg_match( |
|
| 1847 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 1848 | + $texte, $regs)) |
|
| 1849 | + return $regs[0]; |
|
| 1850 | 1850 | } |
| 1851 | 1851 | |
| 1852 | 1852 | // extraire toutes les balises du type demande, sous forme de tableau |
| 1853 | 1853 | // Si on a passe un tableau de textes, renvoyer un tableau de resultats |
| 1854 | 1854 | // http://doc.spip.org/@extraire_balises |
| 1855 | 1855 | function extraire_balises($texte, $tag='a') { |
| 1856 | - if (is_array($texte)) { |
|
| 1857 | - array_walk($texte, |
|
| 1858 | - create_function('&$a,$key,$t', '$a = extraire_balises($a,$t);'), |
|
| 1859 | - $tag); |
|
| 1860 | - return $texte; |
|
| 1861 | - } |
|
| 1856 | + if (is_array($texte)) { |
|
| 1857 | + array_walk($texte, |
|
| 1858 | + create_function('&$a,$key,$t', '$a = extraire_balises($a,$t);'), |
|
| 1859 | + $tag); |
|
| 1860 | + return $texte; |
|
| 1861 | + } |
|
| 1862 | 1862 | |
| 1863 | - if (preg_match_all( |
|
| 1864 | - ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 1865 | - $texte, $regs, PREG_PATTERN_ORDER)) |
|
| 1866 | - return $regs[0]; |
|
| 1867 | - else |
|
| 1868 | - return array(); |
|
| 1863 | + if (preg_match_all( |
|
| 1864 | + ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 1865 | + $texte, $regs, PREG_PATTERN_ORDER)) |
|
| 1866 | + return $regs[0]; |
|
| 1867 | + else |
|
| 1868 | + return array(); |
|
| 1869 | 1869 | } |
| 1870 | 1870 | |
| 1871 | 1871 | // comme in_array mais renvoie son 3e arg si le 2er arg n'est pas un tableau |
@@ -1873,24 +1873,24 @@ discard block |
||
| 1873 | 1873 | |
| 1874 | 1874 | // http://doc.spip.org/@in_any |
| 1875 | 1875 | function in_any($val, $vals, $def='') { |
| 1876 | - if (!is_array($vals) AND $v=unserialize($vals)) $vals = $v; |
|
| 1877 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 1876 | + if (!is_array($vals) AND $v=unserialize($vals)) $vals = $v; |
|
| 1877 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 1878 | 1878 | } |
| 1879 | 1879 | |
| 1880 | 1880 | // valeur_numerique("3*2") => 6 |
| 1881 | 1881 | // n'accepte que les *, + et - (a ameliorer si on l'utilise vraiment) |
| 1882 | 1882 | // http://doc.spip.org/@valeur_numerique |
| 1883 | 1883 | function valeur_numerique($expr) { |
| 1884 | - $a = 0; |
|
| 1885 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) |
|
| 1886 | - eval("\$a = $expr;"); |
|
| 1887 | - return intval($a); |
|
| 1884 | + $a = 0; |
|
| 1885 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) |
|
| 1886 | + eval("\$a = $expr;"); |
|
| 1887 | + return intval($a); |
|
| 1888 | 1888 | } |
| 1889 | 1889 | |
| 1890 | 1890 | // http://doc.spip.org/@regledetrois |
| 1891 | 1891 | function regledetrois($a,$b,$c) |
| 1892 | 1892 | { |
| 1893 | - return round($a*$b/$c); |
|
| 1893 | + return round($a*$b/$c); |
|
| 1894 | 1894 | } |
| 1895 | 1895 | |
| 1896 | 1896 | // Fournit la suite de Input-Hidden correspondant aux parametres de |
@@ -1899,74 +1899,74 @@ discard block |
||
| 1899 | 1899 | // http://doc.spip.org/@form_hidden |
| 1900 | 1900 | function form_hidden($action) { |
| 1901 | 1901 | |
| 1902 | - $contexte = array(); |
|
| 1903 | - include_spip('inc/urls'); |
|
| 1904 | - if ($p = urls_decoder_url($action, '') |
|
| 1905 | - AND reset($p)) { |
|
| 1906 | - $fond = array_shift($p); |
|
| 1907 | - if ($fond!='404'){ |
|
| 1908 | - $contexte = array_shift($p); |
|
| 1909 | - $contexte['page'] = $fond; |
|
| 1910 | - $action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 1911 | - } |
|
| 1912 | - } |
|
| 1913 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 1914 | - if (defined('_DEFINIR_CONTEXTE_TYPE') AND _DEFINIR_CONTEXTE_TYPE) |
|
| 1915 | - unset($contexte['type']); |
|
| 1916 | - if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') AND _DEFINIR_CONTEXTE_TYPE_PAGE) |
|
| 1917 | - unset($contexte['type-page']); |
|
| 1918 | - |
|
| 1919 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 1920 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 1921 | - $values = array(); |
|
| 1922 | - |
|
| 1923 | - // d'abord avec celles de l'url |
|
| 1924 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 1925 | - foreach(preg_split('/&(amp;)?/S',substr($action,$p+1)) as $c){ |
|
| 1926 | - list($var,$val) = explode('=', $c, 2); |
|
| 1927 | - if ($var) { |
|
| 1928 | - $val = rawurldecode($val); |
|
| 1929 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 1930 | - if (preg_match(',\[\]$,S', $var)) |
|
| 1931 | - $values[] = array($var, $val); |
|
| 1932 | - else if (!isset($values[$var])) |
|
| 1933 | - $values[$var] = array($var, $val); |
|
| 1934 | - } |
|
| 1935 | - } |
|
| 1936 | - } |
|
| 1937 | - |
|
| 1938 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 1939 | - foreach($contexte as $var=>$val) |
|
| 1940 | - if (preg_match(',\[\]$,S', $var)) |
|
| 1941 | - $values[] = array($var, $val); |
|
| 1942 | - else if (!isset($values[$var])) |
|
| 1943 | - $values[$var] = array($var, $val); |
|
| 1944 | - |
|
| 1945 | - // puis on rassemble le tout |
|
| 1946 | - $hidden = array(); |
|
| 1947 | - foreach($values as $value) { |
|
| 1948 | - list($var,$val) = $value; |
|
| 1949 | - $hidden[] = '<input name="' |
|
| 1950 | - . entites_html($var) |
|
| 1951 | - .'"' |
|
| 1952 | - . (is_null($val) |
|
| 1953 | - ? '' |
|
| 1954 | - : ' value="'.entites_html($val).'"' |
|
| 1955 | - ) |
|
| 1956 | - . ' type="hidden"'."\n/>"; |
|
| 1957 | - } |
|
| 1958 | - return join("", $hidden); |
|
| 1902 | + $contexte = array(); |
|
| 1903 | + include_spip('inc/urls'); |
|
| 1904 | + if ($p = urls_decoder_url($action, '') |
|
| 1905 | + AND reset($p)) { |
|
| 1906 | + $fond = array_shift($p); |
|
| 1907 | + if ($fond!='404'){ |
|
| 1908 | + $contexte = array_shift($p); |
|
| 1909 | + $contexte['page'] = $fond; |
|
| 1910 | + $action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 1911 | + } |
|
| 1912 | + } |
|
| 1913 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 1914 | + if (defined('_DEFINIR_CONTEXTE_TYPE') AND _DEFINIR_CONTEXTE_TYPE) |
|
| 1915 | + unset($contexte['type']); |
|
| 1916 | + if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') AND _DEFINIR_CONTEXTE_TYPE_PAGE) |
|
| 1917 | + unset($contexte['type-page']); |
|
| 1918 | + |
|
| 1919 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 1920 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 1921 | + $values = array(); |
|
| 1922 | + |
|
| 1923 | + // d'abord avec celles de l'url |
|
| 1924 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 1925 | + foreach(preg_split('/&(amp;)?/S',substr($action,$p+1)) as $c){ |
|
| 1926 | + list($var,$val) = explode('=', $c, 2); |
|
| 1927 | + if ($var) { |
|
| 1928 | + $val = rawurldecode($val); |
|
| 1929 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 1930 | + if (preg_match(',\[\]$,S', $var)) |
|
| 1931 | + $values[] = array($var, $val); |
|
| 1932 | + else if (!isset($values[$var])) |
|
| 1933 | + $values[$var] = array($var, $val); |
|
| 1934 | + } |
|
| 1935 | + } |
|
| 1936 | + } |
|
| 1937 | + |
|
| 1938 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 1939 | + foreach($contexte as $var=>$val) |
|
| 1940 | + if (preg_match(',\[\]$,S', $var)) |
|
| 1941 | + $values[] = array($var, $val); |
|
| 1942 | + else if (!isset($values[$var])) |
|
| 1943 | + $values[$var] = array($var, $val); |
|
| 1944 | + |
|
| 1945 | + // puis on rassemble le tout |
|
| 1946 | + $hidden = array(); |
|
| 1947 | + foreach($values as $value) { |
|
| 1948 | + list($var,$val) = $value; |
|
| 1949 | + $hidden[] = '<input name="' |
|
| 1950 | + . entites_html($var) |
|
| 1951 | + .'"' |
|
| 1952 | + . (is_null($val) |
|
| 1953 | + ? '' |
|
| 1954 | + : ' value="'.entites_html($val).'"' |
|
| 1955 | + ) |
|
| 1956 | + . ' type="hidden"'."\n/>"; |
|
| 1957 | + } |
|
| 1958 | + return join("", $hidden); |
|
| 1959 | 1959 | } |
| 1960 | 1960 | |
| 1961 | 1961 | // http://doc.spip.org/@filtre_bornes_pagination_dist |
| 1962 | 1962 | function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) { |
| 1963 | - if($max<=0 OR $max>=$nombre) |
|
| 1964 | - return array(1, $nombre); |
|
| 1963 | + if($max<=0 OR $max>=$nombre) |
|
| 1964 | + return array(1, $nombre); |
|
| 1965 | 1965 | |
| 1966 | - $premiere = max(1, $courante-floor(($max-1)/2)); |
|
| 1967 | - $derniere = min($nombre, $premiere+$max-2); |
|
| 1968 | - $premiere = $derniere == $nombre ? $derniere-$max+1 : $premiere; |
|
| 1969 | - return array($premiere, $derniere); |
|
| 1966 | + $premiere = max(1, $courante-floor(($max-1)/2)); |
|
| 1967 | + $derniere = min($nombre, $premiere+$max-2); |
|
| 1968 | + $premiere = $derniere == $nombre ? $derniere-$max+1 : $premiere; |
|
| 1969 | + return array($premiere, $derniere); |
|
| 1970 | 1970 | } |
| 1971 | 1971 | |
| 1972 | 1972 | |
@@ -1975,29 +1975,29 @@ discard block |
||
| 1975 | 1975 | // pour la pagination (mais peut-etre a refaire plus simplement) |
| 1976 | 1976 | // http://doc.spip.org/@filtre_valeur_tableau |
| 1977 | 1977 | function filtre_valeur_tableau($array, $index) { |
| 1978 | - if (!is_array($array) |
|
| 1979 | - OR !isset($array[$index])) |
|
| 1980 | - return null; |
|
| 1981 | - return $array[$index]; |
|
| 1978 | + if (!is_array($array) |
|
| 1979 | + OR !isset($array[$index])) |
|
| 1980 | + return null; |
|
| 1981 | + return $array[$index]; |
|
| 1982 | 1982 | } |
| 1983 | 1983 | // http://doc.spip.org/@filtre_reset |
| 1984 | 1984 | function filtre_reset($array) { |
| 1985 | - return !is_array($array) ? null : reset($array); |
|
| 1985 | + return !is_array($array) ? null : reset($array); |
|
| 1986 | 1986 | } |
| 1987 | 1987 | // http://doc.spip.org/@filtre_end |
| 1988 | 1988 | function filtre_end($array) { |
| 1989 | - return !is_array($array) ? null : end($array); |
|
| 1989 | + return !is_array($array) ? null : end($array); |
|
| 1990 | 1990 | } |
| 1991 | 1991 | |
| 1992 | 1992 | // http://doc.spip.org/@filtre_push |
| 1993 | 1993 | function filtre_push($array, $val) { |
| 1994 | - if($array == '' OR !array_push($array, $val)) return ''; |
|
| 1995 | - return $array; |
|
| 1994 | + if($array == '' OR !array_push($array, $val)) return ''; |
|
| 1995 | + return $array; |
|
| 1996 | 1996 | } |
| 1997 | 1997 | |
| 1998 | 1998 | // http://doc.spip.org/@filtre_find |
| 1999 | 1999 | function filtre_find($array, $val) { |
| 2000 | - return (is_array($array) AND in_array($val, $array)); |
|
| 2000 | + return (is_array($array) AND in_array($val, $array)); |
|
| 2001 | 2001 | } |
| 2002 | 2002 | |
| 2003 | 2003 | |
@@ -2008,52 +2008,52 @@ discard block |
||
| 2008 | 2008 | |
| 2009 | 2009 | // http://doc.spip.org/@filtre_pagination_dist |
| 2010 | 2010 | function filtre_pagination_dist($total, $nom, $position, $pas, $liste = true, $modele='', $connect='', $env=array()) { |
| 2011 | - static $ancres = array(); |
|
| 2012 | - if ($pas<1) return ''; |
|
| 2013 | - $ancre = 'pagination'.$nom; // #pagination_articles |
|
| 2014 | - $debut = 'debut'.$nom; // 'debut_articles' |
|
| 2015 | - |
|
| 2016 | - // n'afficher l'ancre qu'une fois |
|
| 2017 | - if (!isset($ancres[$ancre])) |
|
| 2018 | - $bloc_ancre = $ancres[$ancre] = "<a name='".$ancre."' id='".$ancre."'></a>"; |
|
| 2019 | - else $bloc_ancre = ''; |
|
| 2020 | - // liste = false : on ne veut que l'ancre |
|
| 2021 | - if (!$liste) |
|
| 2022 | - return $ancres[$ancre]; |
|
| 2023 | - |
|
| 2024 | - $pagination = array( |
|
| 2025 | - 'debut' => $debut, |
|
| 2026 | - 'url' => parametre_url(self(),'fragment',''), // nettoyer l'id ahah eventuel |
|
| 2027 | - 'total' => $total, |
|
| 2028 | - 'position' => intval($position), |
|
| 2029 | - 'pas' => $pas, |
|
| 2030 | - 'nombre_pages' => floor(($total-1)/$pas)+1, |
|
| 2031 | - 'page_courante' => floor(intval($position)/$pas)+1, |
|
| 2032 | - 'ancre' => $ancre, |
|
| 2033 | - 'bloc_ancre' => $bloc_ancre |
|
| 2034 | - ); |
|
| 2035 | - if (is_array($env)) |
|
| 2036 | - $pagination = array_merge($env,$pagination); |
|
| 2037 | - |
|
| 2038 | - // Pas de pagination |
|
| 2039 | - if ($pagination['nombre_pages']<=1) |
|
| 2040 | - return ''; |
|
| 2041 | - |
|
| 2042 | - if ($modele) $modele = '_'.$modele; |
|
| 2043 | - |
|
| 2044 | - return recuperer_fond("modeles/pagination$modele", $pagination, array('trim'=>true), $connect); |
|
| 2011 | + static $ancres = array(); |
|
| 2012 | + if ($pas<1) return ''; |
|
| 2013 | + $ancre = 'pagination'.$nom; // #pagination_articles |
|
| 2014 | + $debut = 'debut'.$nom; // 'debut_articles' |
|
| 2015 | + |
|
| 2016 | + // n'afficher l'ancre qu'une fois |
|
| 2017 | + if (!isset($ancres[$ancre])) |
|
| 2018 | + $bloc_ancre = $ancres[$ancre] = "<a name='".$ancre."' id='".$ancre."'></a>"; |
|
| 2019 | + else $bloc_ancre = ''; |
|
| 2020 | + // liste = false : on ne veut que l'ancre |
|
| 2021 | + if (!$liste) |
|
| 2022 | + return $ancres[$ancre]; |
|
| 2023 | + |
|
| 2024 | + $pagination = array( |
|
| 2025 | + 'debut' => $debut, |
|
| 2026 | + 'url' => parametre_url(self(),'fragment',''), // nettoyer l'id ahah eventuel |
|
| 2027 | + 'total' => $total, |
|
| 2028 | + 'position' => intval($position), |
|
| 2029 | + 'pas' => $pas, |
|
| 2030 | + 'nombre_pages' => floor(($total-1)/$pas)+1, |
|
| 2031 | + 'page_courante' => floor(intval($position)/$pas)+1, |
|
| 2032 | + 'ancre' => $ancre, |
|
| 2033 | + 'bloc_ancre' => $bloc_ancre |
|
| 2034 | + ); |
|
| 2035 | + if (is_array($env)) |
|
| 2036 | + $pagination = array_merge($env,$pagination); |
|
| 2037 | + |
|
| 2038 | + // Pas de pagination |
|
| 2039 | + if ($pagination['nombre_pages']<=1) |
|
| 2040 | + return ''; |
|
| 2041 | + |
|
| 2042 | + if ($modele) $modele = '_'.$modele; |
|
| 2043 | + |
|
| 2044 | + return recuperer_fond("modeles/pagination$modele", $pagination, array('trim'=>true), $connect); |
|
| 2045 | 2045 | } |
| 2046 | 2046 | |
| 2047 | 2047 | // passer les url relatives a la css d'origine en url absolues |
| 2048 | 2048 | // http://doc.spip.org/@urls_absolues_css |
| 2049 | 2049 | function urls_absolues_css($contenu, $source) { |
| 2050 | - $path = suivre_lien(url_absolue($source),'./'); |
|
| 2050 | + $path = suivre_lien(url_absolue($source),'./'); |
|
| 2051 | 2051 | |
| 2052 | - return preg_replace_callback( |
|
| 2053 | - ",url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", |
|
| 2054 | - create_function('$x', |
|
| 2055 | - 'return "url(\"".suivre_lien("'.$path.'",$x[1])."\")";' |
|
| 2056 | - ), $contenu); |
|
| 2052 | + return preg_replace_callback( |
|
| 2053 | + ",url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", |
|
| 2054 | + create_function('$x', |
|
| 2055 | + 'return "url(\"".suivre_lien("'.$path.'",$x[1])."\")";' |
|
| 2056 | + ), $contenu); |
|
| 2057 | 2057 | } |
| 2058 | 2058 | |
| 2059 | 2059 | // recuperere le chemin d'une css existante et : |
@@ -2062,136 +2062,136 @@ discard block |
||
| 2062 | 2062 | // SI on lui donne a manger une feuille nommee _rtl.css il va faire l'inverse |
| 2063 | 2063 | // http://doc.spip.org/@direction_css |
| 2064 | 2064 | function direction_css ($css, $voulue='') { |
| 2065 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) return $css; |
|
| 2066 | - |
|
| 2067 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2068 | - if ($voulue = strtolower($voulue)) { |
|
| 2069 | - if ($voulue != 'rtl' AND $voulue != 'ltr') |
|
| 2070 | - $voulue = lang_dir($voulue); |
|
| 2071 | - } |
|
| 2072 | - else |
|
| 2073 | - $voulue = lang_dir(); |
|
| 2074 | - |
|
| 2075 | - $r = count($r) > 1; |
|
| 2076 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2077 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2078 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2079 | - |
|
| 2080 | - if ($voulue == $dir) |
|
| 2081 | - return $css; |
|
| 2082 | - |
|
| 2083 | - if ( |
|
| 2084 | - // url absolue |
|
| 2085 | - preg_match(",^http:,i",$css) |
|
| 2086 | - // ou qui contient un ? |
|
| 2087 | - OR (($p=strpos($css,'?'))!==FALSE)) { |
|
| 2088 | - $distant = true; |
|
| 2089 | - $cssf = parse_url($css); |
|
| 2090 | - $cssf = $cssf['path'].($cssf['query']?"?".$cssf['query']:""); |
|
| 2091 | - $cssf = preg_replace(',[?:&=],', "_", $cssf); |
|
| 2092 | - } |
|
| 2093 | - else { |
|
| 2094 | - $distant = false; |
|
| 2095 | - $cssf = $css; |
|
| 2096 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2097 | - //propose (rien a faire dans ce cas) |
|
| 2098 | - $f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css); |
|
| 2099 | - if (@file_exists($f)) |
|
| 2100 | - return $f; |
|
| 2101 | - } |
|
| 2102 | - |
|
| 2103 | - // 2. |
|
| 2104 | - $dir_var = sous_repertoire (_DIR_VAR, 'cache-css'); |
|
| 2105 | - $f = $dir_var |
|
| 2106 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2107 | - . '.' . substr(md5($cssf), 0,4) . '_' . $ndir . '.css'; |
|
| 2108 | - |
|
| 2109 | - // la css peut etre distante (url absolue !) |
|
| 2110 | - if ($distant){ |
|
| 2111 | - include_spip('inc/distant'); |
|
| 2112 | - $contenu = recuperer_page($css); |
|
| 2113 | - if (!$contenu) return $css; |
|
| 2114 | - } |
|
| 2115 | - else { |
|
| 2116 | - if ((@filemtime($f) > @filemtime($css)) |
|
| 2117 | - AND (_VAR_MODE != 'recalcul')) |
|
| 2118 | - return $f; |
|
| 2119 | - if (!lire_fichier($css, $contenu)) |
|
| 2120 | - return $css; |
|
| 2121 | - } |
|
| 2122 | - |
|
| 2123 | - $contenu = str_replace( |
|
| 2124 | - array('right', 'left', '@@@@L E F T@@@@'), |
|
| 2125 | - array('@@@@L E F T@@@@', 'right', 'left'), |
|
| 2126 | - $contenu); |
|
| 2065 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) return $css; |
|
| 2066 | + |
|
| 2067 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2068 | + if ($voulue = strtolower($voulue)) { |
|
| 2069 | + if ($voulue != 'rtl' AND $voulue != 'ltr') |
|
| 2070 | + $voulue = lang_dir($voulue); |
|
| 2071 | + } |
|
| 2072 | + else |
|
| 2073 | + $voulue = lang_dir(); |
|
| 2074 | + |
|
| 2075 | + $r = count($r) > 1; |
|
| 2076 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2077 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2078 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2079 | + |
|
| 2080 | + if ($voulue == $dir) |
|
| 2081 | + return $css; |
|
| 2082 | + |
|
| 2083 | + if ( |
|
| 2084 | + // url absolue |
|
| 2085 | + preg_match(",^http:,i",$css) |
|
| 2086 | + // ou qui contient un ? |
|
| 2087 | + OR (($p=strpos($css,'?'))!==FALSE)) { |
|
| 2088 | + $distant = true; |
|
| 2089 | + $cssf = parse_url($css); |
|
| 2090 | + $cssf = $cssf['path'].($cssf['query']?"?".$cssf['query']:""); |
|
| 2091 | + $cssf = preg_replace(',[?:&=],', "_", $cssf); |
|
| 2092 | + } |
|
| 2093 | + else { |
|
| 2094 | + $distant = false; |
|
| 2095 | + $cssf = $css; |
|
| 2096 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2097 | + //propose (rien a faire dans ce cas) |
|
| 2098 | + $f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css); |
|
| 2099 | + if (@file_exists($f)) |
|
| 2100 | + return $f; |
|
| 2101 | + } |
|
| 2102 | + |
|
| 2103 | + // 2. |
|
| 2104 | + $dir_var = sous_repertoire (_DIR_VAR, 'cache-css'); |
|
| 2105 | + $f = $dir_var |
|
| 2106 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2107 | + . '.' . substr(md5($cssf), 0,4) . '_' . $ndir . '.css'; |
|
| 2108 | + |
|
| 2109 | + // la css peut etre distante (url absolue !) |
|
| 2110 | + if ($distant){ |
|
| 2111 | + include_spip('inc/distant'); |
|
| 2112 | + $contenu = recuperer_page($css); |
|
| 2113 | + if (!$contenu) return $css; |
|
| 2114 | + } |
|
| 2115 | + else { |
|
| 2116 | + if ((@filemtime($f) > @filemtime($css)) |
|
| 2117 | + AND (_VAR_MODE != 'recalcul')) |
|
| 2118 | + return $f; |
|
| 2119 | + if (!lire_fichier($css, $contenu)) |
|
| 2120 | + return $css; |
|
| 2121 | + } |
|
| 2122 | + |
|
| 2123 | + $contenu = str_replace( |
|
| 2124 | + array('right', 'left', '@@@@L E F T@@@@'), |
|
| 2125 | + array('@@@@L E F T@@@@', 'right', 'left'), |
|
| 2126 | + $contenu); |
|
| 2127 | 2127 | |
| 2128 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 2129 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims",$contenu,$regs); |
|
| 2130 | - $src = array();$src_direction_css = array();$src_faux_abs=array(); |
|
| 2131 | - $d = dirname($css); |
|
| 2132 | - foreach($regs[1] as $k=>$import_css){ |
|
| 2133 | - $css_direction = direction_css("$d/$import_css",$voulue); |
|
| 2134 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2135 | - if (substr($css_direction,0,strlen($d)+1)=="$d/") $css_direction = substr($css_direction,strlen($d)+1); |
|
| 2136 | - // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2137 | - elseif (substr($css_direction,0,strlen($dir_var))==$dir_var) { |
|
| 2138 | - $css_direction = substr($css_direction,strlen($dir_var)); |
|
| 2139 | - $src_faux_abs["/@@@@@@/".$css_direction] = $css_direction; |
|
| 2140 | - $css_direction = "/@@@@@@/".$css_direction; |
|
| 2141 | - } |
|
| 2142 | - $src[] = $regs[0][$k]; |
|
| 2143 | - $src_direction_css[] = str_replace($import_css,$css_direction,$regs[0][$k]); |
|
| 2144 | - } |
|
| 2145 | - $contenu = str_replace($src,$src_direction_css,$contenu); |
|
| 2146 | - |
|
| 2147 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2148 | - |
|
| 2149 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 2150 | - if (count($src_faux_abs)) |
|
| 2151 | - $contenu = str_replace(array_keys($src_faux_abs),$src_faux_abs,$contenu); |
|
| 2152 | - |
|
| 2153 | - if (!ecrire_fichier($f, $contenu)) |
|
| 2154 | - return $css; |
|
| 2155 | - |
|
| 2156 | - return $f; |
|
| 2128 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 2129 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims",$contenu,$regs); |
|
| 2130 | + $src = array();$src_direction_css = array();$src_faux_abs=array(); |
|
| 2131 | + $d = dirname($css); |
|
| 2132 | + foreach($regs[1] as $k=>$import_css){ |
|
| 2133 | + $css_direction = direction_css("$d/$import_css",$voulue); |
|
| 2134 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2135 | + if (substr($css_direction,0,strlen($d)+1)=="$d/") $css_direction = substr($css_direction,strlen($d)+1); |
|
| 2136 | + // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2137 | + elseif (substr($css_direction,0,strlen($dir_var))==$dir_var) { |
|
| 2138 | + $css_direction = substr($css_direction,strlen($dir_var)); |
|
| 2139 | + $src_faux_abs["/@@@@@@/".$css_direction] = $css_direction; |
|
| 2140 | + $css_direction = "/@@@@@@/".$css_direction; |
|
| 2141 | + } |
|
| 2142 | + $src[] = $regs[0][$k]; |
|
| 2143 | + $src_direction_css[] = str_replace($import_css,$css_direction,$regs[0][$k]); |
|
| 2144 | + } |
|
| 2145 | + $contenu = str_replace($src,$src_direction_css,$contenu); |
|
| 2146 | + |
|
| 2147 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2148 | + |
|
| 2149 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 2150 | + if (count($src_faux_abs)) |
|
| 2151 | + $contenu = str_replace(array_keys($src_faux_abs),$src_faux_abs,$contenu); |
|
| 2152 | + |
|
| 2153 | + if (!ecrire_fichier($f, $contenu)) |
|
| 2154 | + return $css; |
|
| 2155 | + |
|
| 2156 | + return $f; |
|
| 2157 | 2157 | } |
| 2158 | 2158 | |
| 2159 | 2159 | // recuperere le chemin d'une css existante et : |
| 2160 | 2160 | // cree (ou recree) dans _DIR_VAR/cache_css/ une css dont les url relatives sont passees en url absolues |
| 2161 | 2161 | // http://doc.spip.org/@url_absolue_css |
| 2162 | 2162 | function url_absolue_css ($css) { |
| 2163 | - if (!preg_match(',\.css$,i', $css, $r)) return $css; |
|
| 2163 | + if (!preg_match(',\.css$,i', $css, $r)) return $css; |
|
| 2164 | 2164 | |
| 2165 | - $url_absolue_css = url_absolue($css); |
|
| 2165 | + $url_absolue_css = url_absolue($css); |
|
| 2166 | 2166 | |
| 2167 | - $f = basename($css,'.css'); |
|
| 2168 | - $f = sous_repertoire (_DIR_VAR, 'cache-css') |
|
| 2169 | - . preg_replace(",(.*?)(_rtl|_ltr)?$,","\\1-urlabs-" . substr(md5("$css-urlabs"), 0,4) . "\\2",$f) |
|
| 2170 | - . '.css'; |
|
| 2167 | + $f = basename($css,'.css'); |
|
| 2168 | + $f = sous_repertoire (_DIR_VAR, 'cache-css') |
|
| 2169 | + . preg_replace(",(.*?)(_rtl|_ltr)?$,","\\1-urlabs-" . substr(md5("$css-urlabs"), 0,4) . "\\2",$f) |
|
| 2170 | + . '.css'; |
|
| 2171 | 2171 | |
| 2172 | - if ((@filemtime($f) > @filemtime($css)) |
|
| 2173 | - AND (_VAR_MODE != 'recalcul')) |
|
| 2174 | - return $f; |
|
| 2172 | + if ((@filemtime($f) > @filemtime($css)) |
|
| 2173 | + AND (_VAR_MODE != 'recalcul')) |
|
| 2174 | + return $f; |
|
| 2175 | 2175 | |
| 2176 | - if ($url_absolue_css==$css){ |
|
| 2177 | - if (strncmp($GLOBALS['meta']['adresse_site'],$css,$l=strlen($GLOBALS['meta']['adresse_site']))!=0 |
|
| 2178 | - OR !lire_fichier(_DIR_RACINE . substr($css,$l), $contenu)){ |
|
| 2179 | - include_spip('inc/distant'); |
|
| 2180 | - if (!$contenu = recuperer_page($css)) |
|
| 2181 | - return $css; |
|
| 2182 | - } |
|
| 2183 | - } |
|
| 2184 | - elseif (!lire_fichier($css, $contenu)) |
|
| 2185 | - return $css; |
|
| 2176 | + if ($url_absolue_css==$css){ |
|
| 2177 | + if (strncmp($GLOBALS['meta']['adresse_site'],$css,$l=strlen($GLOBALS['meta']['adresse_site']))!=0 |
|
| 2178 | + OR !lire_fichier(_DIR_RACINE . substr($css,$l), $contenu)){ |
|
| 2179 | + include_spip('inc/distant'); |
|
| 2180 | + if (!$contenu = recuperer_page($css)) |
|
| 2181 | + return $css; |
|
| 2182 | + } |
|
| 2183 | + } |
|
| 2184 | + elseif (!lire_fichier($css, $contenu)) |
|
| 2185 | + return $css; |
|
| 2186 | 2186 | |
| 2187 | - // passer les url relatives a la css d'origine en url absolues |
|
| 2188 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2187 | + // passer les url relatives a la css d'origine en url absolues |
|
| 2188 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2189 | 2189 | |
| 2190 | - // ecrire la css |
|
| 2191 | - if (!ecrire_fichier($f, $contenu)) |
|
| 2192 | - return $css; |
|
| 2190 | + // ecrire la css |
|
| 2191 | + if (!ecrire_fichier($f, $contenu)) |
|
| 2192 | + return $css; |
|
| 2193 | 2193 | |
| 2194 | - return $f; |
|
| 2194 | + return $f; |
|
| 2195 | 2195 | } |
| 2196 | 2196 | |
| 2197 | 2197 | |
@@ -2222,24 +2222,24 @@ discard block |
||
| 2222 | 2222 | * @return mixed Valeur trouvee ou valeur par defaut. |
| 2223 | 2223 | **/ |
| 2224 | 2224 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 2225 | - foreach (explode('/', $cle) as $k) { |
|
| 2225 | + foreach (explode('/', $cle) as $k) { |
|
| 2226 | 2226 | |
| 2227 | - $table = is_string($table) ? @unserialize($table) : $table; |
|
| 2227 | + $table = is_string($table) ? @unserialize($table) : $table; |
|
| 2228 | 2228 | |
| 2229 | - if (is_object($table)) { |
|
| 2230 | - $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut; |
|
| 2231 | - } elseif (is_array($table)) { |
|
| 2232 | - if ($conserver_null) { |
|
| 2233 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 2234 | - } else { |
|
| 2235 | - $table = isset($table[$k]) ? $table[$k] : $defaut; |
|
| 2236 | - } |
|
| 2237 | - } else { |
|
| 2238 | - $table = $defaut; |
|
| 2239 | - } |
|
| 2240 | - } |
|
| 2229 | + if (is_object($table)) { |
|
| 2230 | + $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut; |
|
| 2231 | + } elseif (is_array($table)) { |
|
| 2232 | + if ($conserver_null) { |
|
| 2233 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 2234 | + } else { |
|
| 2235 | + $table = isset($table[$k]) ? $table[$k] : $defaut; |
|
| 2236 | + } |
|
| 2237 | + } else { |
|
| 2238 | + $table = $defaut; |
|
| 2239 | + } |
|
| 2240 | + } |
|
| 2241 | 2241 | |
| 2242 | - return $table; |
|
| 2242 | + return $table; |
|
| 2243 | 2243 | } |
| 2244 | 2244 | |
| 2245 | 2245 | // filtre match pour faire des tests avec expression reguliere |
@@ -2249,29 +2249,29 @@ discard block |
||
| 2249 | 2249 | // accepte egalement la syntaxe #TRUC|match{truc(...)$,1} ou le modificateur n'est pas passe en second argument |
| 2250 | 2250 | // http://doc.spip.org/@match |
| 2251 | 2251 | function match($texte, $expression, $modif="UimsS",$capte=0) { |
| 2252 | - if (intval($modif) AND $capte==0){ |
|
| 2253 | - $capte = $modif; |
|
| 2254 | - $modif = "UimsS"; |
|
| 2255 | - } |
|
| 2256 | - $expression=str_replace("\/","/",$expression); |
|
| 2257 | - $expression=str_replace("/","\/",$expression); |
|
| 2258 | - |
|
| 2259 | - if (preg_match('/' . $expression . '/' . $modif,$texte, $r)) { |
|
| 2260 | - if (isset($r[$capte])) |
|
| 2261 | - return $r[$capte]; |
|
| 2262 | - else |
|
| 2263 | - return true; |
|
| 2264 | - } |
|
| 2265 | - return false; |
|
| 2252 | + if (intval($modif) AND $capte==0){ |
|
| 2253 | + $capte = $modif; |
|
| 2254 | + $modif = "UimsS"; |
|
| 2255 | + } |
|
| 2256 | + $expression=str_replace("\/","/",$expression); |
|
| 2257 | + $expression=str_replace("/","\/",$expression); |
|
| 2258 | + |
|
| 2259 | + if (preg_match('/' . $expression . '/' . $modif,$texte, $r)) { |
|
| 2260 | + if (isset($r[$capte])) |
|
| 2261 | + return $r[$capte]; |
|
| 2262 | + else |
|
| 2263 | + return true; |
|
| 2264 | + } |
|
| 2265 | + return false; |
|
| 2266 | 2266 | } |
| 2267 | 2267 | |
| 2268 | 2268 | // filtre replace pour faire des operations avec expression reguliere |
| 2269 | 2269 | // [(#TEXTE|replace{^ceci$,cela,UimsS})] |
| 2270 | 2270 | // http://doc.spip.org/@replace |
| 2271 | 2271 | function replace($texte, $expression, $replace='', $modif="UimsS") { |
| 2272 | - $expression=str_replace("\/","/", $expression); |
|
| 2273 | - $expression=str_replace("/","\/",$expression); |
|
| 2274 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 2272 | + $expression=str_replace("\/","/", $expression); |
|
| 2273 | + $expression=str_replace("/","\/",$expression); |
|
| 2274 | + return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 2275 | 2275 | } |
| 2276 | 2276 | |
| 2277 | 2277 | |
@@ -2281,22 +2281,22 @@ discard block |
||
| 2281 | 2281 | // http://doc.spip.org/@traiter_doublons_documents |
| 2282 | 2282 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 2283 | 2283 | |
| 2284 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 2285 | - $t = $letexte.$GLOBALS['les_notes']; |
|
| 2284 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 2285 | + $t = $letexte.$GLOBALS['les_notes']; |
|
| 2286 | 2286 | |
| 2287 | - if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 2288 | - AND preg_match_all( |
|
| 2289 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 2290 | - $t, $matches, PREG_PATTERN_ORDER)) |
|
| 2291 | - $doublons['documents'] .= "," . join(',', $matches[1]); |
|
| 2287 | + if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 2288 | + AND preg_match_all( |
|
| 2289 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 2290 | + $t, $matches, PREG_PATTERN_ORDER)) |
|
| 2291 | + $doublons['documents'] .= "," . join(',', $matches[1]); |
|
| 2292 | 2292 | |
| 2293 | - return $letexte; |
|
| 2293 | + return $letexte; |
|
| 2294 | 2294 | } |
| 2295 | 2295 | |
| 2296 | 2296 | // filtre vide qui ne renvoie rien |
| 2297 | 2297 | // http://doc.spip.org/@vide |
| 2298 | 2298 | function vide($texte){ |
| 2299 | - return ""; |
|
| 2299 | + return ""; |
|
| 2300 | 2300 | } |
| 2301 | 2301 | |
| 2302 | 2302 | // |
@@ -2306,51 +2306,51 @@ discard block |
||
| 2306 | 2306 | // A partir d'un #ENV, retourne des <param ...> |
| 2307 | 2307 | // http://doc.spip.org/@env_to_params |
| 2308 | 2308 | function env_to_params ($texte, $ignore_params=array()) { |
| 2309 | - $ignore_params = array_merge ( |
|
| 2310 | - array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 2311 | - $ignore_params); |
|
| 2312 | - $tableau = unserialize($texte); |
|
| 2313 | - $texte = ""; |
|
| 2314 | - foreach ($tableau as $i => $j) |
|
| 2315 | - if (is_string($j) AND !in_array($i,$ignore_params)) |
|
| 2316 | - $texte .= "<param name='".$i."'\n\tvalue='".$j."' />"; |
|
| 2317 | - return $texte; |
|
| 2309 | + $ignore_params = array_merge ( |
|
| 2310 | + array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 2311 | + $ignore_params); |
|
| 2312 | + $tableau = unserialize($texte); |
|
| 2313 | + $texte = ""; |
|
| 2314 | + foreach ($tableau as $i => $j) |
|
| 2315 | + if (is_string($j) AND !in_array($i,$ignore_params)) |
|
| 2316 | + $texte .= "<param name='".$i."'\n\tvalue='".$j."' />"; |
|
| 2317 | + return $texte; |
|
| 2318 | 2318 | } |
| 2319 | 2319 | // A partir d'un #ENV, retourne des attributs |
| 2320 | 2320 | // http://doc.spip.org/@env_to_attributs |
| 2321 | 2321 | function env_to_attributs ($texte, $ignore_params=array()) { |
| 2322 | - $ignore_params = array_merge ( |
|
| 2323 | - array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 2324 | - $ignore_params); |
|
| 2325 | - $tableau = unserialize($texte); |
|
| 2326 | - $texte = ""; |
|
| 2327 | - foreach ($tableau as $i => $j) |
|
| 2328 | - if (is_string($j) AND !in_array($i,$ignore_params)) |
|
| 2329 | - $texte .= $i."='".$j."' "; |
|
| 2330 | - return $texte; |
|
| 2322 | + $ignore_params = array_merge ( |
|
| 2323 | + array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 2324 | + $ignore_params); |
|
| 2325 | + $tableau = unserialize($texte); |
|
| 2326 | + $texte = ""; |
|
| 2327 | + foreach ($tableau as $i => $j) |
|
| 2328 | + if (is_string($j) AND !in_array($i,$ignore_params)) |
|
| 2329 | + $texte .= $i."='".$j."' "; |
|
| 2330 | + return $texte; |
|
| 2331 | 2331 | } |
| 2332 | 2332 | |
| 2333 | 2333 | // Concatener des chaines |
| 2334 | 2334 | // #TEXTE|concat{texte1,texte2,...} |
| 2335 | 2335 | // http://doc.spip.org/@concat |
| 2336 | 2336 | function concat(){ |
| 2337 | - $args = func_get_args(); |
|
| 2338 | - return join('', $args); |
|
| 2337 | + $args = func_get_args(); |
|
| 2338 | + return join('', $args); |
|
| 2339 | 2339 | } |
| 2340 | 2340 | |
| 2341 | 2341 | |
| 2342 | 2342 | // http://doc.spip.org/@charge_scripts |
| 2343 | 2343 | // http://doc.spip.org/@charge_scripts |
| 2344 | 2344 | function charge_scripts($files, $script = true) { |
| 2345 | - $flux = ""; |
|
| 2346 | - foreach(is_array($files)?$files:explode("|",$files) as $file) { |
|
| 2347 | - if (!is_string($file)) continue; |
|
| 2348 | - if ($script) |
|
| 2349 | - $file = preg_match(",^\w+$,",$file) ? "javascript/$file.js" : ''; |
|
| 2350 | - if ($file) $path = find_in_path($file); |
|
| 2351 | - if ($path) $flux .= spip_file_get_contents($path); |
|
| 2352 | - } |
|
| 2353 | - return $flux; |
|
| 2345 | + $flux = ""; |
|
| 2346 | + foreach(is_array($files)?$files:explode("|",$files) as $file) { |
|
| 2347 | + if (!is_string($file)) continue; |
|
| 2348 | + if ($script) |
|
| 2349 | + $file = preg_match(",^\w+$,",$file) ? "javascript/$file.js" : ''; |
|
| 2350 | + if ($file) $path = find_in_path($file); |
|
| 2351 | + if ($path) $flux .= spip_file_get_contents($path); |
|
| 2352 | + } |
|
| 2353 | + return $flux; |
|
| 2354 | 2354 | } |
| 2355 | 2355 | |
| 2356 | 2356 | |
@@ -2372,26 +2372,26 @@ discard block |
||
| 2372 | 2372 | * @return string |
| 2373 | 2373 | */ |
| 2374 | 2374 | function http_img_pack($img, $alt, $atts='', $title='', $options = array()) { |
| 2375 | - if (!isset($options['chemin_image']) OR $options['chemin_image']==true) |
|
| 2376 | - $img = chemin_image($img); |
|
| 2377 | - if (stripos($atts, 'width')===false){ |
|
| 2378 | - // utiliser directement l'info de taille presente dans le nom |
|
| 2379 | - if ((!isset($options['utiliser_suffixe_size']) OR $options['utiliser_suffixe_size']==true) |
|
| 2380 | - AND preg_match(',-([0-9]+)[.](png|gif)$,',$img,$regs)){ |
|
| 2381 | - $largeur = $hauteur = intval($regs[1]); |
|
| 2382 | - } |
|
| 2383 | - else{ |
|
| 2384 | - $taille = taille_image($img); |
|
| 2385 | - list($hauteur,$largeur) = $taille; |
|
| 2386 | - if (!$hauteur OR !$largeur) |
|
| 2387 | - return ""; |
|
| 2388 | - } |
|
| 2389 | - $atts.=" width='".$largeur."' height='".$hauteur."'"; |
|
| 2390 | - } |
|
| 2391 | - return "<img src='$img' alt='" . attribut_html($alt ? $alt : $title) . "'" |
|
| 2392 | - . ($title ? ' title="'.attribut_html($title).'"' : '') |
|
| 2393 | - . " ".ltrim($atts) |
|
| 2394 | - . " />"; |
|
| 2375 | + if (!isset($options['chemin_image']) OR $options['chemin_image']==true) |
|
| 2376 | + $img = chemin_image($img); |
|
| 2377 | + if (stripos($atts, 'width')===false){ |
|
| 2378 | + // utiliser directement l'info de taille presente dans le nom |
|
| 2379 | + if ((!isset($options['utiliser_suffixe_size']) OR $options['utiliser_suffixe_size']==true) |
|
| 2380 | + AND preg_match(',-([0-9]+)[.](png|gif)$,',$img,$regs)){ |
|
| 2381 | + $largeur = $hauteur = intval($regs[1]); |
|
| 2382 | + } |
|
| 2383 | + else{ |
|
| 2384 | + $taille = taille_image($img); |
|
| 2385 | + list($hauteur,$largeur) = $taille; |
|
| 2386 | + if (!$hauteur OR !$largeur) |
|
| 2387 | + return ""; |
|
| 2388 | + } |
|
| 2389 | + $atts.=" width='".$largeur."' height='".$hauteur."'"; |
|
| 2390 | + } |
|
| 2391 | + return "<img src='$img' alt='" . attribut_html($alt ? $alt : $title) . "'" |
|
| 2392 | + . ($title ? ' title="'.attribut_html($title).'"' : '') |
|
| 2393 | + . " ".ltrim($atts) |
|
| 2394 | + . " />"; |
|
| 2395 | 2395 | } |
| 2396 | 2396 | |
| 2397 | 2397 | /** |
@@ -2404,7 +2404,7 @@ discard block |
||
| 2404 | 2404 | * @return string |
| 2405 | 2405 | */ |
| 2406 | 2406 | function http_style_background($img, $att=''){ |
| 2407 | - return " style='background".($att?"":"-image").": url(\"".chemin_image($img)."\")" . ($att ? (' ' . $att) : '') . ";'"; |
|
| 2407 | + return " style='background".($att?"":"-image").": url(\"".chemin_image($img)."\")" . ($att ? (' ' . $att) : '') . ";'"; |
|
| 2408 | 2408 | } |
| 2409 | 2409 | |
| 2410 | 2410 | /** |
@@ -2416,22 +2416,22 @@ discard block |
||
| 2416 | 2416 | * @return string |
| 2417 | 2417 | */ |
| 2418 | 2418 | function filtre_balise_img_dist($img,$alt="",$class=""){ |
| 2419 | - return http_img_pack($img, $alt, $class?" class='".attribut_html($class)."'":'', '', array('chemin_image'=>false,'utiliser_suffixe_size'=>false)); |
|
| 2419 | + return http_img_pack($img, $alt, $class?" class='".attribut_html($class)."'":'', '', array('chemin_image'=>false,'utiliser_suffixe_size'=>false)); |
|
| 2420 | 2420 | } |
| 2421 | 2421 | |
| 2422 | 2422 | |
| 2423 | 2423 | //[(#ENV*|unserialize|foreach)] |
| 2424 | 2424 | // http://doc.spip.org/@filtre_foreach_dist |
| 2425 | 2425 | function filtre_foreach_dist($balise_deserializee, $modele = 'foreach') { |
| 2426 | - $texte = ''; |
|
| 2427 | - if(is_array($balise_deserializee)) |
|
| 2428 | - foreach($balise_deserializee as $k => $v) { |
|
| 2429 | - $res = recuperer_fond('modeles/'.$modele, |
|
| 2430 | - array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v))) |
|
| 2431 | - ); |
|
| 2432 | - $texte .= $res; |
|
| 2433 | - } |
|
| 2434 | - return $texte; |
|
| 2426 | + $texte = ''; |
|
| 2427 | + if(is_array($balise_deserializee)) |
|
| 2428 | + foreach($balise_deserializee as $k => $v) { |
|
| 2429 | + $res = recuperer_fond('modeles/'.$modele, |
|
| 2430 | + array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v))) |
|
| 2431 | + ); |
|
| 2432 | + $texte .= $res; |
|
| 2433 | + } |
|
| 2434 | + return $texte; |
|
| 2435 | 2435 | } |
| 2436 | 2436 | |
| 2437 | 2437 | // renvoie la liste des plugins actifs du site |
@@ -2441,39 +2441,39 @@ discard block |
||
| 2441 | 2441 | // appelee par la balise #PLUGIN |
| 2442 | 2442 | // http://doc.spip.org/@filtre_info_plugin_dist |
| 2443 | 2443 | function filtre_info_plugin_dist($plugin, $type_info) { |
| 2444 | - include_spip('inc/plugin'); |
|
| 2445 | - $plugin = strtoupper($plugin); |
|
| 2446 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 2447 | - |
|
| 2448 | - if (!$plugin) |
|
| 2449 | - return serialize(array_keys($plugins_actifs)); |
|
| 2450 | - elseif (empty($plugins_actifs[$plugin])) |
|
| 2451 | - return ''; |
|
| 2452 | - elseif ($type_info == 'est_actif') |
|
| 2453 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 2454 | - elseif (isset($plugins_actifs[$plugin][$type_info])) |
|
| 2455 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 2456 | - else { |
|
| 2457 | - $get_infos = charger_fonction('get_infos','plugins'); |
|
| 2458 | - // On prend en compte les extensions |
|
| 2459 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) |
|
| 2460 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 2461 | - else |
|
| 2462 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 2463 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], false, $dir_plugins)) |
|
| 2464 | - return ''; |
|
| 2465 | - if ($type_info == 'tout') |
|
| 2466 | - return $infos; |
|
| 2467 | - else |
|
| 2468 | - return strval($infos[$type_info]); |
|
| 2469 | - } |
|
| 2444 | + include_spip('inc/plugin'); |
|
| 2445 | + $plugin = strtoupper($plugin); |
|
| 2446 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 2447 | + |
|
| 2448 | + if (!$plugin) |
|
| 2449 | + return serialize(array_keys($plugins_actifs)); |
|
| 2450 | + elseif (empty($plugins_actifs[$plugin])) |
|
| 2451 | + return ''; |
|
| 2452 | + elseif ($type_info == 'est_actif') |
|
| 2453 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 2454 | + elseif (isset($plugins_actifs[$plugin][$type_info])) |
|
| 2455 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 2456 | + else { |
|
| 2457 | + $get_infos = charger_fonction('get_infos','plugins'); |
|
| 2458 | + // On prend en compte les extensions |
|
| 2459 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) |
|
| 2460 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 2461 | + else |
|
| 2462 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 2463 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], false, $dir_plugins)) |
|
| 2464 | + return ''; |
|
| 2465 | + if ($type_info == 'tout') |
|
| 2466 | + return $infos; |
|
| 2467 | + else |
|
| 2468 | + return strval($infos[$type_info]); |
|
| 2469 | + } |
|
| 2470 | 2470 | } |
| 2471 | 2471 | |
| 2472 | 2472 | |
| 2473 | 2473 | // http://doc.spip.org/@puce_changement_statut |
| 2474 | 2474 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax=false){ |
| 2475 | - $puce_statut = charger_fonction('puce_statut','inc'); |
|
| 2476 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 2475 | + $puce_statut = charger_fonction('puce_statut','inc'); |
|
| 2476 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 2477 | 2477 | } |
| 2478 | 2478 | |
| 2479 | 2479 | /** |
@@ -2488,10 +2488,10 @@ discard block |
||
| 2488 | 2488 | * @return string |
| 2489 | 2489 | */ |
| 2490 | 2490 | function filtre_puce_statut_dist($statut,$objet,$id_objet=0,$id_parent=0){ |
| 2491 | - static $puce_statut = null; |
|
| 2492 | - if (!$puce_statut) |
|
| 2493 | - $puce_statut = charger_fonction('puce_statut','inc'); |
|
| 2494 | - return $puce_statut($id_objet, $statut, $id_parent, $objet, false, objet_info($objet,'editable')?_ACTIVER_PUCE_RAPIDE:false); |
|
| 2491 | + static $puce_statut = null; |
|
| 2492 | + if (!$puce_statut) |
|
| 2493 | + $puce_statut = charger_fonction('puce_statut','inc'); |
|
| 2494 | + return $puce_statut($id_objet, $statut, $id_parent, $objet, false, objet_info($objet,'editable')?_ACTIVER_PUCE_RAPIDE:false); |
|
| 2495 | 2495 | } |
| 2496 | 2496 | |
| 2497 | 2497 | |
@@ -2513,128 +2513,128 @@ discard block |
||
| 2513 | 2513 | * @return string |
| 2514 | 2514 | */ |
| 2515 | 2515 | function encoder_contexte_ajax($c,$form='', $emboite=NULL, $ajaxid='') { |
| 2516 | - if (is_string($c) |
|
| 2517 | - AND !is_null(@unserialize($c))) { |
|
| 2518 | - $c = unserialize($c); |
|
| 2519 | - } |
|
| 2520 | - |
|
| 2521 | - // supprimer les parametres debut_x |
|
| 2522 | - // pour que la pagination ajax ne soit pas plantee |
|
| 2523 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 2524 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 2525 | - foreach ($c as $k => $v) { |
|
| 2526 | - if (strpos($k,'debut_') === 0) { |
|
| 2527 | - unset($c[$k]); |
|
| 2528 | - } |
|
| 2529 | - } |
|
| 2516 | + if (is_string($c) |
|
| 2517 | + AND !is_null(@unserialize($c))) { |
|
| 2518 | + $c = unserialize($c); |
|
| 2519 | + } |
|
| 2520 | + |
|
| 2521 | + // supprimer les parametres debut_x |
|
| 2522 | + // pour que la pagination ajax ne soit pas plantee |
|
| 2523 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 2524 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 2525 | + foreach ($c as $k => $v) { |
|
| 2526 | + if (strpos($k,'debut_') === 0) { |
|
| 2527 | + unset($c[$k]); |
|
| 2528 | + } |
|
| 2529 | + } |
|
| 2530 | 2530 | |
| 2531 | - if (!function_exists('calculer_cle_action')) |
|
| 2532 | - include_spip("inc/securiser_action"); |
|
| 2533 | - |
|
| 2534 | - $c = serialize($c); |
|
| 2535 | - $cle = calculer_cle_action($form . $c); |
|
| 2536 | - $c = "$cle:$c"; |
|
| 2537 | - |
|
| 2538 | - // on ne stocke pas les contextes dans des fichiers caches |
|
| 2539 | - // par defaut, sauf si cette configuration a ete forcee |
|
| 2540 | - // OU que la longueur de l''argument generee est plus long |
|
| 2541 | - // que ce que telere Suhosin. |
|
| 2542 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') AND _CACHE_CONTEXTES_AJAX); |
|
| 2543 | - if (!$cache_contextes_ajax) { |
|
| 2544 | - $env = $c; |
|
| 2545 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 2546 | - $env = gzdeflate($env); |
|
| 2547 | - // http://core.spip.org/issues/2667 | https://bugs.php.net/bug.php?id=61287 |
|
| 2548 | - if (substr(phpversion(),0,5) == '5.4.0' AND !@gzinflate($env)) { |
|
| 2549 | - $cache_contextes_ajax = true; |
|
| 2550 | - spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT); |
|
| 2551 | - } |
|
| 2552 | - } |
|
| 2553 | - $env = _xor($env); |
|
| 2554 | - $env = base64_encode($env); |
|
| 2555 | - // tester Suhosin et la valeur maximale des variables en GET... |
|
| 2556 | - if ($max_len = @ini_get('suhosin.get.max_value_length') |
|
| 2557 | - and $max_len < ($len = strlen($env))) { |
|
| 2558 | - $cache_contextes_ajax = true; |
|
| 2559 | - spip_log("Contextes AJAX forces en fichiers !" |
|
| 2560 | - . " Cela arrive lorsque la valeur du contexte" |
|
| 2561 | - . " depasse la longueur maximale autorisee par Suhosin" |
|
| 2562 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 2563 | - . " Vous devriez modifier les parametres de Suhosin" |
|
| 2564 | - . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT); |
|
| 2565 | - } |
|
| 2566 | - } |
|
| 2531 | + if (!function_exists('calculer_cle_action')) |
|
| 2532 | + include_spip("inc/securiser_action"); |
|
| 2533 | + |
|
| 2534 | + $c = serialize($c); |
|
| 2535 | + $cle = calculer_cle_action($form . $c); |
|
| 2536 | + $c = "$cle:$c"; |
|
| 2537 | + |
|
| 2538 | + // on ne stocke pas les contextes dans des fichiers caches |
|
| 2539 | + // par defaut, sauf si cette configuration a ete forcee |
|
| 2540 | + // OU que la longueur de l''argument generee est plus long |
|
| 2541 | + // que ce que telere Suhosin. |
|
| 2542 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') AND _CACHE_CONTEXTES_AJAX); |
|
| 2543 | + if (!$cache_contextes_ajax) { |
|
| 2544 | + $env = $c; |
|
| 2545 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 2546 | + $env = gzdeflate($env); |
|
| 2547 | + // http://core.spip.org/issues/2667 | https://bugs.php.net/bug.php?id=61287 |
|
| 2548 | + if (substr(phpversion(),0,5) == '5.4.0' AND !@gzinflate($env)) { |
|
| 2549 | + $cache_contextes_ajax = true; |
|
| 2550 | + spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT); |
|
| 2551 | + } |
|
| 2552 | + } |
|
| 2553 | + $env = _xor($env); |
|
| 2554 | + $env = base64_encode($env); |
|
| 2555 | + // tester Suhosin et la valeur maximale des variables en GET... |
|
| 2556 | + if ($max_len = @ini_get('suhosin.get.max_value_length') |
|
| 2557 | + and $max_len < ($len = strlen($env))) { |
|
| 2558 | + $cache_contextes_ajax = true; |
|
| 2559 | + spip_log("Contextes AJAX forces en fichiers !" |
|
| 2560 | + . " Cela arrive lorsque la valeur du contexte" |
|
| 2561 | + . " depasse la longueur maximale autorisee par Suhosin" |
|
| 2562 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 2563 | + . " Vous devriez modifier les parametres de Suhosin" |
|
| 2564 | + . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT); |
|
| 2565 | + } |
|
| 2566 | + } |
|
| 2567 | 2567 | |
| 2568 | - if ($cache_contextes_ajax) { |
|
| 2569 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 2570 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 2571 | - $md5 = md5($c); |
|
| 2572 | - ecrire_fichier("$dir/c$md5",$c); |
|
| 2573 | - $env = $md5; |
|
| 2574 | - } |
|
| 2568 | + if ($cache_contextes_ajax) { |
|
| 2569 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 2570 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 2571 | + $md5 = md5($c); |
|
| 2572 | + ecrire_fichier("$dir/c$md5",$c); |
|
| 2573 | + $env = $md5; |
|
| 2574 | + } |
|
| 2575 | 2575 | |
| 2576 | - if ($emboite === NULL) return $env; |
|
| 2577 | - if (!trim($emboite)) return ""; |
|
| 2578 | - // toujours encoder l'url source dans le bloc ajax |
|
| 2579 | - $r = self(); |
|
| 2580 | - $r = ' data-origin="'.$r.'"'; |
|
| 2581 | - $class = 'ajaxbloc'; |
|
| 2582 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 2583 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 2584 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 2585 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 2586 | - } |
|
| 2587 | - return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 2576 | + if ($emboite === NULL) return $env; |
|
| 2577 | + if (!trim($emboite)) return ""; |
|
| 2578 | + // toujours encoder l'url source dans le bloc ajax |
|
| 2579 | + $r = self(); |
|
| 2580 | + $r = ' data-origin="'.$r.'"'; |
|
| 2581 | + $class = 'ajaxbloc'; |
|
| 2582 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 2583 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 2584 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 2585 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 2586 | + } |
|
| 2587 | + return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 2588 | 2588 | } |
| 2589 | 2589 | |
| 2590 | 2590 | // la procedure inverse de encoder_contexte_ajax() |
| 2591 | 2591 | // http://doc.spip.org/@decoder_contexte_ajax |
| 2592 | 2592 | function decoder_contexte_ajax($c,$form='') { |
| 2593 | - if (!function_exists('calculer_cle_action')) |
|
| 2594 | - include_spip("inc/securiser_action"); |
|
| 2595 | - if (( (defined('_CACHE_CONTEXTES_AJAX') AND _CACHE_CONTEXTES_AJAX) OR strlen($c)==32) |
|
| 2596 | - AND $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 2597 | - AND lire_fichier("$dir/c$c",$contexte)) { |
|
| 2598 | - $c = $contexte; |
|
| 2599 | - } else { |
|
| 2600 | - $c = @base64_decode($c); |
|
| 2601 | - $c = _xor($c); |
|
| 2602 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) |
|
| 2603 | - $c = @gzinflate($c); |
|
| 2604 | - } |
|
| 2605 | - |
|
| 2606 | - // extraire la signature en debut de contexte |
|
| 2607 | - // et la verifier avant de deserializer |
|
| 2608 | - // format : signature:donneesserializees |
|
| 2609 | - if ($p = strpos($c,":")){ |
|
| 2610 | - $cle = substr($c,0,$p); |
|
| 2611 | - $c = substr($c,$p+1); |
|
| 2612 | - |
|
| 2613 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 2614 | - $env = @unserialize($c); |
|
| 2615 | - return $env; |
|
| 2616 | - } |
|
| 2617 | - } |
|
| 2618 | - |
|
| 2619 | - return false; |
|
| 2593 | + if (!function_exists('calculer_cle_action')) |
|
| 2594 | + include_spip("inc/securiser_action"); |
|
| 2595 | + if (( (defined('_CACHE_CONTEXTES_AJAX') AND _CACHE_CONTEXTES_AJAX) OR strlen($c)==32) |
|
| 2596 | + AND $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 2597 | + AND lire_fichier("$dir/c$c",$contexte)) { |
|
| 2598 | + $c = $contexte; |
|
| 2599 | + } else { |
|
| 2600 | + $c = @base64_decode($c); |
|
| 2601 | + $c = _xor($c); |
|
| 2602 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) |
|
| 2603 | + $c = @gzinflate($c); |
|
| 2604 | + } |
|
| 2605 | + |
|
| 2606 | + // extraire la signature en debut de contexte |
|
| 2607 | + // et la verifier avant de deserializer |
|
| 2608 | + // format : signature:donneesserializees |
|
| 2609 | + if ($p = strpos($c,":")){ |
|
| 2610 | + $cle = substr($c,0,$p); |
|
| 2611 | + $c = substr($c,$p+1); |
|
| 2612 | + |
|
| 2613 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 2614 | + $env = @unserialize($c); |
|
| 2615 | + return $env; |
|
| 2616 | + } |
|
| 2617 | + } |
|
| 2618 | + |
|
| 2619 | + return false; |
|
| 2620 | 2620 | } |
| 2621 | 2621 | |
| 2622 | 2622 | // encrypter/decrypter un message |
| 2623 | 2623 | // http://www.php.net/manual/fr/language.operators.bitwise.php#81358 |
| 2624 | 2624 | // http://doc.spip.org/@_xor |
| 2625 | 2625 | function _xor($message, $key=null){ |
| 2626 | - if (is_null($key)) { |
|
| 2627 | - if (!function_exists('calculer_cle_action')) |
|
| 2628 | - include_spip("inc/securiser_action"); |
|
| 2629 | - $key = pack("H*", calculer_cle_action('_xor')); |
|
| 2630 | - } |
|
| 2626 | + if (is_null($key)) { |
|
| 2627 | + if (!function_exists('calculer_cle_action')) |
|
| 2628 | + include_spip("inc/securiser_action"); |
|
| 2629 | + $key = pack("H*", calculer_cle_action('_xor')); |
|
| 2630 | + } |
|
| 2631 | 2631 | |
| 2632 | - $keylen = strlen($key); |
|
| 2633 | - $messagelen = strlen($message); |
|
| 2634 | - for($i=0; $i<$messagelen; $i++) |
|
| 2635 | - $message[$i] = ~($message[$i]^$key[$i%$keylen]); |
|
| 2632 | + $keylen = strlen($key); |
|
| 2633 | + $messagelen = strlen($message); |
|
| 2634 | + for($i=0; $i<$messagelen; $i++) |
|
| 2635 | + $message[$i] = ~($message[$i]^$key[$i%$keylen]); |
|
| 2636 | 2636 | |
| 2637 | - return $message; |
|
| 2637 | + return $message; |
|
| 2638 | 2638 | } |
| 2639 | 2639 | |
| 2640 | 2640 | // Les vrai fonctions sont dans le plugin forum, mais on evite ici une erreur du compilateur |
@@ -2660,20 +2660,20 @@ discard block |
||
| 2660 | 2660 | * @return string |
| 2661 | 2661 | */ |
| 2662 | 2662 | function lien_ou_expose($url,$libelle=NULL,$on=false,$class="",$title="",$rel="", $evt=''){ |
| 2663 | - if ($on) { |
|
| 2664 | - $bal = "strong"; |
|
| 2665 | - $att = "class='on'"; |
|
| 2666 | - } else { |
|
| 2667 | - $bal = 'a'; |
|
| 2668 | - $att = "href='$url'" |
|
| 2669 | - .($title?" title='".attribut_html($title)."'":'') |
|
| 2670 | - .($class?" class='".attribut_html($class)."'":'') |
|
| 2671 | - .($rel?" rel='".attribut_html($rel)."'":'') |
|
| 2672 | - .$evt; |
|
| 2673 | - } |
|
| 2674 | - if ($libelle === NULL) |
|
| 2675 | - $libelle = $url; |
|
| 2676 | - return "<$bal $att>$libelle</$bal>"; |
|
| 2663 | + if ($on) { |
|
| 2664 | + $bal = "strong"; |
|
| 2665 | + $att = "class='on'"; |
|
| 2666 | + } else { |
|
| 2667 | + $bal = 'a'; |
|
| 2668 | + $att = "href='$url'" |
|
| 2669 | + .($title?" title='".attribut_html($title)."'":'') |
|
| 2670 | + .($class?" class='".attribut_html($class)."'":'') |
|
| 2671 | + .($rel?" rel='".attribut_html($rel)."'":'') |
|
| 2672 | + .$evt; |
|
| 2673 | + } |
|
| 2674 | + if ($libelle === NULL) |
|
| 2675 | + $libelle = $url; |
|
| 2676 | + return "<$bal $att>$libelle</$bal>"; |
|
| 2677 | 2677 | } |
| 2678 | 2678 | |
| 2679 | 2679 | |
@@ -2690,11 +2690,11 @@ discard block |
||
| 2690 | 2690 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 2691 | 2691 | */ |
| 2692 | 2692 | function singulier_ou_pluriel($nb,$chaine_un,$chaine_plusieurs,$var='nb',$vars=array()){ |
| 2693 | - if (!$nb=intval($nb)) return ""; |
|
| 2694 | - if (!is_array($vars)) return ""; |
|
| 2695 | - $vars[$var] = $nb; |
|
| 2696 | - if ($nb>1) return _T($chaine_plusieurs, $vars); |
|
| 2697 | - else return _T($chaine_un,$vars); |
|
| 2693 | + if (!$nb=intval($nb)) return ""; |
|
| 2694 | + if (!is_array($vars)) return ""; |
|
| 2695 | + $vars[$var] = $nb; |
|
| 2696 | + if ($nb>1) return _T($chaine_plusieurs, $vars); |
|
| 2697 | + else return _T($chaine_un,$vars); |
|
| 2698 | 2698 | } |
| 2699 | 2699 | |
| 2700 | 2700 | |
@@ -2719,77 +2719,77 @@ discard block |
||
| 2719 | 2719 | * @return string |
| 2720 | 2720 | */ |
| 2721 | 2721 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction="", $class="",$javascript=""){ |
| 2722 | - if (in_array($fonction,array("del","supprimer.gif"))) |
|
| 2723 | - $class .= ' danger'; |
|
| 2724 | - elseif ($fonction == "rien.gif") |
|
| 2725 | - $fonction = ""; |
|
| 2726 | - elseif ($fonction == "delsafe") |
|
| 2727 | - $fonction = "del"; |
|
| 2728 | - |
|
| 2729 | - // remappage des icone : article-24.png+new => article-new-24.png |
|
| 2730 | - if ($icone_renommer = charger_fonction('icone_renommer','inc',true)) |
|
| 2731 | - list($fond,$fonction) = $icone_renommer($fond,$fonction); |
|
| 2732 | - |
|
| 2733 | - // ajouter le type d'objet dans la class de l'icone |
|
| 2734 | - $class .= " " . substr(basename($fond),0,-4); |
|
| 2735 | - |
|
| 2736 | - $alt = attribut_html($texte); |
|
| 2737 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 2738 | - |
|
| 2739 | - $ajax = ""; |
|
| 2740 | - if (strpos($class,"ajax")!==false) { |
|
| 2741 | - $ajax="ajax"; |
|
| 2742 | - if (strpos($class,"preload")!==false) |
|
| 2743 | - $ajax.=" preload"; |
|
| 2744 | - if (strpos($class,"nocache")!==false) |
|
| 2745 | - $ajax.=" nocache"; |
|
| 2746 | - $ajax=" class='$ajax'"; |
|
| 2747 | - } |
|
| 2748 | - |
|
| 2749 | - $size = 24; |
|
| 2750 | - if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i",$fond,$match)) |
|
| 2751 | - $size = $match[1]; |
|
| 2752 | - |
|
| 2753 | - if ($fonction){ |
|
| 2754 | - // 2 images pour composer l'icone : le fond (article) en background, |
|
| 2755 | - // la fonction (new) en image |
|
| 2756 | - $icone = http_img_pack($fonction, $alt, "width='$size' height='$size'\n" . |
|
| 2757 | - http_style_background($fond)); |
|
| 2758 | - } |
|
| 2759 | - else { |
|
| 2760 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 2761 | - } |
|
| 2762 | - |
|
| 2763 | - if ($type=='lien') |
|
| 2764 | - return "<span class='icone s$size $class'>" |
|
| 2765 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 2766 | - . $icone |
|
| 2767 | - . "<b>$texte</b>" |
|
| 2768 | - . "</a></span>\n"; |
|
| 2769 | - |
|
| 2770 | - else |
|
| 2771 | - return bouton_action("$icone<b>$texte</b>",$lien,"icone s$size $class",$javascript,$alt); |
|
| 2722 | + if (in_array($fonction,array("del","supprimer.gif"))) |
|
| 2723 | + $class .= ' danger'; |
|
| 2724 | + elseif ($fonction == "rien.gif") |
|
| 2725 | + $fonction = ""; |
|
| 2726 | + elseif ($fonction == "delsafe") |
|
| 2727 | + $fonction = "del"; |
|
| 2728 | + |
|
| 2729 | + // remappage des icone : article-24.png+new => article-new-24.png |
|
| 2730 | + if ($icone_renommer = charger_fonction('icone_renommer','inc',true)) |
|
| 2731 | + list($fond,$fonction) = $icone_renommer($fond,$fonction); |
|
| 2732 | + |
|
| 2733 | + // ajouter le type d'objet dans la class de l'icone |
|
| 2734 | + $class .= " " . substr(basename($fond),0,-4); |
|
| 2735 | + |
|
| 2736 | + $alt = attribut_html($texte); |
|
| 2737 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 2738 | + |
|
| 2739 | + $ajax = ""; |
|
| 2740 | + if (strpos($class,"ajax")!==false) { |
|
| 2741 | + $ajax="ajax"; |
|
| 2742 | + if (strpos($class,"preload")!==false) |
|
| 2743 | + $ajax.=" preload"; |
|
| 2744 | + if (strpos($class,"nocache")!==false) |
|
| 2745 | + $ajax.=" nocache"; |
|
| 2746 | + $ajax=" class='$ajax'"; |
|
| 2747 | + } |
|
| 2748 | + |
|
| 2749 | + $size = 24; |
|
| 2750 | + if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i",$fond,$match)) |
|
| 2751 | + $size = $match[1]; |
|
| 2752 | + |
|
| 2753 | + if ($fonction){ |
|
| 2754 | + // 2 images pour composer l'icone : le fond (article) en background, |
|
| 2755 | + // la fonction (new) en image |
|
| 2756 | + $icone = http_img_pack($fonction, $alt, "width='$size' height='$size'\n" . |
|
| 2757 | + http_style_background($fond)); |
|
| 2758 | + } |
|
| 2759 | + else { |
|
| 2760 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 2761 | + } |
|
| 2762 | + |
|
| 2763 | + if ($type=='lien') |
|
| 2764 | + return "<span class='icone s$size $class'>" |
|
| 2765 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 2766 | + . $icone |
|
| 2767 | + . "<b>$texte</b>" |
|
| 2768 | + . "</a></span>\n"; |
|
| 2769 | + |
|
| 2770 | + else |
|
| 2771 | + return bouton_action("$icone<b>$texte</b>",$lien,"icone s$size $class",$javascript,$alt); |
|
| 2772 | 2772 | } |
| 2773 | 2773 | |
| 2774 | 2774 | function icone_base($lien, $texte, $fond, $fonction="", $class="",$javascript=""){ |
| 2775 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 2775 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 2776 | 2776 | } |
| 2777 | 2777 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction="", $class="",$javascript=""){ |
| 2778 | - return icone_base($lien,$texte,$fond,$fonction,"verticale $class",$javascript); |
|
| 2778 | + return icone_base($lien,$texte,$fond,$fonction,"verticale $class",$javascript); |
|
| 2779 | 2779 | } |
| 2780 | 2780 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction="", $class="",$javascript=""){ |
| 2781 | - return icone_base($lien,$texte,$fond,$fonction,"horizontale $class",$javascript); |
|
| 2781 | + return icone_base($lien,$texte,$fond,$fonction,"horizontale $class",$javascript); |
|
| 2782 | 2782 | } |
| 2783 | 2783 | |
| 2784 | 2784 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction="", $class="",$confirm=""){ |
| 2785 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm); |
|
| 2785 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm); |
|
| 2786 | 2786 | } |
| 2787 | 2787 | /* |
| 2788 | 2788 | * Filtre icone pour compatibilite |
| 2789 | 2789 | * mappe sur icone_base |
| 2790 | 2790 | */ |
| 2791 | 2791 | function filtre_icone_dist($lien, $texte, $fond, $align="", $fonction="", $class="",$javascript=""){ |
| 2792 | - return icone_base($lien,$texte,$fond,$fonction,"verticale $align $class",$javascript); |
|
| 2792 | + return icone_base($lien,$texte,$fond,$fonction,"verticale $align $class",$javascript); |
|
| 2793 | 2793 | } |
| 2794 | 2794 | |
| 2795 | 2795 | |
@@ -2818,21 +2818,21 @@ discard block |
||
| 2818 | 2818 | * @return string |
| 2819 | 2819 | */ |
| 2820 | 2820 | function bando_images_background(){ |
| 2821 | - include_spip('inc/bandeau'); |
|
| 2822 | - // recuperer tous les boutons et leurs images |
|
| 2823 | - $boutons = definir_barre_boutons(definir_barre_contexte(),true,false); |
|
| 2824 | - |
|
| 2825 | - $res = ""; |
|
| 2826 | - foreach($boutons as $page => $detail){ |
|
| 2827 | - if ($detail->icone AND strlen(trim($detail->icone))) |
|
| 2828 | - $res .="\n.navigation_avec_icones #bando1_$page {background-image:url(".$detail->icone.");}"; |
|
| 2829 | - $selecteur = (in_array($page,array('outils_rapides','outils_collaboratifs'))?"":".navigation_avec_icones "); |
|
| 2830 | - if (is_array($detail->sousmenu)) |
|
| 2831 | - foreach($detail->sousmenu as $souspage=>$sousdetail) |
|
| 2832 | - if ($sousdetail->icone AND strlen(trim($sousdetail->icone))) |
|
| 2833 | - $res .="\n$selecteur.bando2_$souspage {background-image:url(".$sousdetail->icone.");}"; |
|
| 2834 | - } |
|
| 2835 | - return $res; |
|
| 2821 | + include_spip('inc/bandeau'); |
|
| 2822 | + // recuperer tous les boutons et leurs images |
|
| 2823 | + $boutons = definir_barre_boutons(definir_barre_contexte(),true,false); |
|
| 2824 | + |
|
| 2825 | + $res = ""; |
|
| 2826 | + foreach($boutons as $page => $detail){ |
|
| 2827 | + if ($detail->icone AND strlen(trim($detail->icone))) |
|
| 2828 | + $res .="\n.navigation_avec_icones #bando1_$page {background-image:url(".$detail->icone.");}"; |
|
| 2829 | + $selecteur = (in_array($page,array('outils_rapides','outils_collaboratifs'))?"":".navigation_avec_icones "); |
|
| 2830 | + if (is_array($detail->sousmenu)) |
|
| 2831 | + foreach($detail->sousmenu as $souspage=>$sousdetail) |
|
| 2832 | + if ($sousdetail->icone AND strlen(trim($sousdetail->icone))) |
|
| 2833 | + $res .="\n$selecteur.bando2_$souspage {background-image:url(".$sousdetail->icone.");}"; |
|
| 2834 | + } |
|
| 2835 | + return $res; |
|
| 2836 | 2836 | } |
| 2837 | 2837 | |
| 2838 | 2838 | /** |
@@ -2851,17 +2851,17 @@ discard block |
||
| 2851 | 2851 | * @return string |
| 2852 | 2852 | */ |
| 2853 | 2853 | function bouton_action($libelle, $url, $class="", $confirm="", $title="", $callback=""){ |
| 2854 | - if ($confirm) { |
|
| 2855 | - $confirm = "confirm(\"" . attribut_html($confirm) . "\")"; |
|
| 2856 | - if ($callback) |
|
| 2857 | - $callback = "$confirm?($callback):false"; |
|
| 2858 | - else |
|
| 2859 | - $callback = $confirm; |
|
| 2860 | - } |
|
| 2861 | - $onclick = $callback?" onclick='return ".addcslashes($callback,"'")."'":""; |
|
| 2862 | - $title = $title ? " title='$title'" : ""; |
|
| 2863 | - return "<form class='bouton_action_post $class' method='post' action='$url'><div>".form_hidden($url) |
|
| 2864 | - ."<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>"; |
|
| 2854 | + if ($confirm) { |
|
| 2855 | + $confirm = "confirm(\"" . attribut_html($confirm) . "\")"; |
|
| 2856 | + if ($callback) |
|
| 2857 | + $callback = "$confirm?($callback):false"; |
|
| 2858 | + else |
|
| 2859 | + $callback = $confirm; |
|
| 2860 | + } |
|
| 2861 | + $onclick = $callback?" onclick='return ".addcslashes($callback,"'")."'":""; |
|
| 2862 | + $title = $title ? " title='$title'" : ""; |
|
| 2863 | + return "<form class='bouton_action_post $class' method='post' action='$url'><div>".form_hidden($url) |
|
| 2864 | + ."<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>"; |
|
| 2865 | 2865 | } |
| 2866 | 2866 | |
| 2867 | 2867 | |
@@ -2872,7 +2872,7 @@ discard block |
||
| 2872 | 2872 | * @return string |
| 2873 | 2873 | */ |
| 2874 | 2874 | function tri_protege_champ($t){ |
| 2875 | - return preg_replace(',[^\s\w.+],','',$t); |
|
| 2875 | + return preg_replace(',[^\s\w.+],','',$t); |
|
| 2876 | 2876 | } |
| 2877 | 2877 | |
| 2878 | 2878 | /** |
@@ -2884,31 +2884,31 @@ discard block |
||
| 2884 | 2884 | * @return string |
| 2885 | 2885 | */ |
| 2886 | 2886 | function tri_champ_order($t, $from=null){ |
| 2887 | - if(strncmp($t,'multi ',6)==0){ |
|
| 2888 | - return "multi"; |
|
| 2889 | - } |
|
| 2890 | - |
|
| 2891 | - $champ = $t; |
|
| 2892 | - |
|
| 2893 | - if (strncmp($t,'num ',4)==0) |
|
| 2894 | - $champ = substr($t,4); |
|
| 2895 | - // enlever les autres espaces non evacues par tri_protege_champ |
|
| 2896 | - $champ = preg_replace(',\s,','',$champ); |
|
| 2897 | - |
|
| 2898 | - if (is_array($from)){ |
|
| 2899 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 2900 | - foreach($from as $idt=>$table_sql){ |
|
| 2901 | - if ($desc = $trouver_table($table_sql) |
|
| 2902 | - AND isset($desc['field'][$champ])){ |
|
| 2903 | - $champ = "$idt.$champ"; |
|
| 2904 | - break; |
|
| 2905 | - } |
|
| 2906 | - } |
|
| 2907 | - } |
|
| 2908 | - if (strncmp($t,'num ',4)==0) |
|
| 2909 | - return "0+$champ"; |
|
| 2910 | - else |
|
| 2911 | - return $champ; |
|
| 2887 | + if(strncmp($t,'multi ',6)==0){ |
|
| 2888 | + return "multi"; |
|
| 2889 | + } |
|
| 2890 | + |
|
| 2891 | + $champ = $t; |
|
| 2892 | + |
|
| 2893 | + if (strncmp($t,'num ',4)==0) |
|
| 2894 | + $champ = substr($t,4); |
|
| 2895 | + // enlever les autres espaces non evacues par tri_protege_champ |
|
| 2896 | + $champ = preg_replace(',\s,','',$champ); |
|
| 2897 | + |
|
| 2898 | + if (is_array($from)){ |
|
| 2899 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 2900 | + foreach($from as $idt=>$table_sql){ |
|
| 2901 | + if ($desc = $trouver_table($table_sql) |
|
| 2902 | + AND isset($desc['field'][$champ])){ |
|
| 2903 | + $champ = "$idt.$champ"; |
|
| 2904 | + break; |
|
| 2905 | + } |
|
| 2906 | + } |
|
| 2907 | + } |
|
| 2908 | + if (strncmp($t,'num ',4)==0) |
|
| 2909 | + return "0+$champ"; |
|
| 2910 | + else |
|
| 2911 | + return $champ; |
|
| 2912 | 2912 | } |
| 2913 | 2913 | |
| 2914 | 2914 | /** |
@@ -2922,16 +2922,16 @@ discard block |
||
| 2922 | 2922 | * @return string |
| 2923 | 2923 | */ |
| 2924 | 2924 | function tri_champ_select($t){ |
| 2925 | - if(strncmp($t,'multi ',6)==0){ |
|
| 2926 | - $t = substr($t,6); |
|
| 2927 | - $t = preg_replace(',\s,','',$t); |
|
| 2928 | - $t = sql_multi($t,$GLOBALS['spip_lang']); |
|
| 2929 | - return $t; |
|
| 2930 | - } |
|
| 2931 | - if(trim($t)=='hasard'){ |
|
| 2932 | - return 'rand() AS hasard'; |
|
| 2933 | - } |
|
| 2934 | - return "''"; |
|
| 2925 | + if(strncmp($t,'multi ',6)==0){ |
|
| 2926 | + $t = substr($t,6); |
|
| 2927 | + $t = preg_replace(',\s,','',$t); |
|
| 2928 | + $t = sql_multi($t,$GLOBALS['spip_lang']); |
|
| 2929 | + return $t; |
|
| 2930 | + } |
|
| 2931 | + if(trim($t)=='hasard'){ |
|
| 2932 | + return 'rand() AS hasard'; |
|
| 2933 | + } |
|
| 2934 | + return "''"; |
|
| 2935 | 2935 | } |
| 2936 | 2936 | |
| 2937 | 2937 | |
@@ -2953,80 +2953,80 @@ discard block |
||
| 2953 | 2953 | * @return string |
| 2954 | 2954 | */ |
| 2955 | 2955 | function generer_info_entite($id_objet, $type_objet, $info, $etoile=""){ |
| 2956 | - global $table_des_traitements; |
|
| 2957 | - static $trouver_table=null; |
|
| 2958 | - static $objets; |
|
| 2959 | - |
|
| 2960 | - // On verifie qu'on a tout ce qu'il faut |
|
| 2961 | - $id_objet = intval($id_objet); |
|
| 2962 | - if (!($id_objet and $type_objet and $info)) |
|
| 2963 | - return ''; |
|
| 2964 | - |
|
| 2965 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 2966 | - if (isset($objets[$type_objet]) AND $objets[$type_objet]===false) |
|
| 2967 | - return ''; |
|
| 2968 | - |
|
| 2969 | - // Si on demande l'url, on retourne direct la fonction |
|
| 2970 | - if ($info == 'url') |
|
| 2971 | - return generer_url_entite($id_objet, $type_objet); |
|
| 2972 | - |
|
| 2973 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 2974 | - $demande_titre = ($info == 'titre'); |
|
| 2975 | - |
|
| 2976 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 2977 | - if (!isset($objets[$type_objet][$id_objet]) |
|
| 2978 | - OR |
|
| 2979 | - ($demande_titre AND !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 2980 | - ){ |
|
| 2981 | - if (!$trouver_table) |
|
| 2982 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 2983 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 2984 | - if (!$desc) |
|
| 2985 | - return $objets[$type_objet] = false; |
|
| 2986 | - |
|
| 2987 | - // Si on demande le titre, on le gere en interne |
|
| 2988 | - $champ_titre = ""; |
|
| 2989 | - if ($demande_titre){ |
|
| 2990 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 2991 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre']:''; |
|
| 2992 | - } |
|
| 2993 | - include_spip('base/abstract_sql'); |
|
| 2994 | - include_spip('base/connect_sql'); |
|
| 2995 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 2996 | - '*'.$champ_titre, |
|
| 2997 | - $desc['table_sql'], |
|
| 2998 | - id_table_objet($type_objet).' = '.intval($id_objet) |
|
| 2999 | - ); |
|
| 3000 | - } |
|
| 3001 | - |
|
| 3002 | - // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee |
|
| 3003 | - if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) |
|
| 3004 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]); |
|
| 3005 | - // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee |
|
| 3006 | - else if ($generer = charger_fonction("generer_${info}_entite", '', true)) |
|
| 3007 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]); |
|
| 3008 | - // Sinon on prend directement le champ SQL tel quel |
|
| 3009 | - else |
|
| 3010 | - $info_generee = (isset($objets[$type_objet][$id_objet][$info])?$objets[$type_objet][$id_objet][$info]:''); |
|
| 3011 | - |
|
| 3012 | - // On va ensuite chercher les traitements automatiques a faire |
|
| 3013 | - $champ = strtoupper($info); |
|
| 3014 | - $traitement = isset($table_des_traitements[$champ]) ? $table_des_traitements[$champ] : false; |
|
| 3015 | - $table_sql = table_objet_sql($type_objet); |
|
| 3016 | - |
|
| 3017 | - if (!$etoile |
|
| 3018 | - AND is_array($traitement) |
|
| 3019 | - AND (isset($traitement[$table_sql]) OR isset($traitement[0]))){ |
|
| 3020 | - include_spip('inc/texte'); |
|
| 3021 | - $traitement = $traitement[isset($traitement[$table_sql]) ? $table_sql : 0]; |
|
| 3022 | - $traitement = str_replace('%s', "'".texte_script($info_generee)."'", $traitement); |
|
| 3023 | - // FIXME: $connect et $Pile[0] font souvent partie des traitements. |
|
| 3024 | - // on les definit pour eviter des notices, mais ce fonctionnement est a ameliorer ! |
|
| 3025 | - $connect = ""; $Pile = array(0 => array('id_objet'=>$id_objet,'objet'=>$type_objet)); |
|
| 3026 | - eval("\$info_generee = $traitement;"); |
|
| 3027 | - } |
|
| 3028 | - |
|
| 3029 | - return $info_generee; |
|
| 2956 | + global $table_des_traitements; |
|
| 2957 | + static $trouver_table=null; |
|
| 2958 | + static $objets; |
|
| 2959 | + |
|
| 2960 | + // On verifie qu'on a tout ce qu'il faut |
|
| 2961 | + $id_objet = intval($id_objet); |
|
| 2962 | + if (!($id_objet and $type_objet and $info)) |
|
| 2963 | + return ''; |
|
| 2964 | + |
|
| 2965 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 2966 | + if (isset($objets[$type_objet]) AND $objets[$type_objet]===false) |
|
| 2967 | + return ''; |
|
| 2968 | + |
|
| 2969 | + // Si on demande l'url, on retourne direct la fonction |
|
| 2970 | + if ($info == 'url') |
|
| 2971 | + return generer_url_entite($id_objet, $type_objet); |
|
| 2972 | + |
|
| 2973 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 2974 | + $demande_titre = ($info == 'titre'); |
|
| 2975 | + |
|
| 2976 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 2977 | + if (!isset($objets[$type_objet][$id_objet]) |
|
| 2978 | + OR |
|
| 2979 | + ($demande_titre AND !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 2980 | + ){ |
|
| 2981 | + if (!$trouver_table) |
|
| 2982 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 2983 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 2984 | + if (!$desc) |
|
| 2985 | + return $objets[$type_objet] = false; |
|
| 2986 | + |
|
| 2987 | + // Si on demande le titre, on le gere en interne |
|
| 2988 | + $champ_titre = ""; |
|
| 2989 | + if ($demande_titre){ |
|
| 2990 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 2991 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre']:''; |
|
| 2992 | + } |
|
| 2993 | + include_spip('base/abstract_sql'); |
|
| 2994 | + include_spip('base/connect_sql'); |
|
| 2995 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 2996 | + '*'.$champ_titre, |
|
| 2997 | + $desc['table_sql'], |
|
| 2998 | + id_table_objet($type_objet).' = '.intval($id_objet) |
|
| 2999 | + ); |
|
| 3000 | + } |
|
| 3001 | + |
|
| 3002 | + // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee |
|
| 3003 | + if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) |
|
| 3004 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]); |
|
| 3005 | + // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee |
|
| 3006 | + else if ($generer = charger_fonction("generer_${info}_entite", '', true)) |
|
| 3007 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]); |
|
| 3008 | + // Sinon on prend directement le champ SQL tel quel |
|
| 3009 | + else |
|
| 3010 | + $info_generee = (isset($objets[$type_objet][$id_objet][$info])?$objets[$type_objet][$id_objet][$info]:''); |
|
| 3011 | + |
|
| 3012 | + // On va ensuite chercher les traitements automatiques a faire |
|
| 3013 | + $champ = strtoupper($info); |
|
| 3014 | + $traitement = isset($table_des_traitements[$champ]) ? $table_des_traitements[$champ] : false; |
|
| 3015 | + $table_sql = table_objet_sql($type_objet); |
|
| 3016 | + |
|
| 3017 | + if (!$etoile |
|
| 3018 | + AND is_array($traitement) |
|
| 3019 | + AND (isset($traitement[$table_sql]) OR isset($traitement[0]))){ |
|
| 3020 | + include_spip('inc/texte'); |
|
| 3021 | + $traitement = $traitement[isset($traitement[$table_sql]) ? $table_sql : 0]; |
|
| 3022 | + $traitement = str_replace('%s', "'".texte_script($info_generee)."'", $traitement); |
|
| 3023 | + // FIXME: $connect et $Pile[0] font souvent partie des traitements. |
|
| 3024 | + // on les definit pour eviter des notices, mais ce fonctionnement est a ameliorer ! |
|
| 3025 | + $connect = ""; $Pile = array(0 => array('id_objet'=>$id_objet,'objet'=>$type_objet)); |
|
| 3026 | + eval("\$info_generee = $traitement;"); |
|
| 3027 | + } |
|
| 3028 | + |
|
| 3029 | + return $info_generee; |
|
| 3030 | 3030 | } |
| 3031 | 3031 | |
| 3032 | 3032 | /** |
@@ -3037,14 +3037,14 @@ discard block |
||
| 3037 | 3037 | * @return string |
| 3038 | 3038 | */ |
| 3039 | 3039 | function wrap($texte,$wrap) { |
| 3040 | - $balises = extraire_balises($wrap); |
|
| 3041 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS",$wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 3042 | - $texte = $wrap . $texte; |
|
| 3043 | - $regs = array_reverse($regs[1]); |
|
| 3044 | - $wrap = "</".implode("></",$regs).">"; |
|
| 3045 | - $texte = $texte . $wrap; |
|
| 3046 | - } |
|
| 3047 | - return $texte; |
|
| 3040 | + $balises = extraire_balises($wrap); |
|
| 3041 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS",$wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 3042 | + $texte = $wrap . $texte; |
|
| 3043 | + $regs = array_reverse($regs[1]); |
|
| 3044 | + $wrap = "</".implode("></",$regs).">"; |
|
| 3045 | + $texte = $texte . $wrap; |
|
| 3046 | + } |
|
| 3047 | + return $texte; |
|
| 3048 | 3048 | } |
| 3049 | 3049 | |
| 3050 | 3050 | |
@@ -3064,39 +3064,39 @@ discard block |
||
| 3064 | 3064 | * @return array|mixed|string |
| 3065 | 3065 | */ |
| 3066 | 3066 | function filtre_print_dist($u, $join="<br />", $indent=0) { |
| 3067 | - if (is_string($u)){ |
|
| 3068 | - $u = typo($u); |
|
| 3069 | - return $u; |
|
| 3070 | - } |
|
| 3071 | - |
|
| 3072 | - // caster $u en array si besoin |
|
| 3073 | - if (is_object($u)) |
|
| 3074 | - $u = (array) $u; |
|
| 3075 | - |
|
| 3076 | - if (is_array($u)){ |
|
| 3077 | - $out = ""; |
|
| 3078 | - // toutes les cles sont numeriques ? |
|
| 3079 | - // et aucun enfant n'est un tableau |
|
| 3080 | - // liste simple separee par des virgules |
|
| 3081 | - $numeric_keys = array_map('is_numeric',array_keys($u)); |
|
| 3082 | - $array_values = array_map('is_array',$u); |
|
| 3083 | - $object_values = array_map('is_object',$u); |
|
| 3084 | - if (array_sum($numeric_keys)==count($numeric_keys) |
|
| 3085 | - AND !array_sum($array_values) |
|
| 3086 | - AND !array_sum($object_values)){ |
|
| 3087 | - return join(", ", array_map('filtre_print_dist', $u)); |
|
| 3088 | - } |
|
| 3089 | - |
|
| 3090 | - // sinon on passe a la ligne et on indente |
|
| 3091 | - $i_str = str_pad("",$indent," "); |
|
| 3092 | - foreach($u as $k => $v){ |
|
| 3093 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v,$join,$indent+2); |
|
| 3094 | - } |
|
| 3095 | - return $out; |
|
| 3096 | - } |
|
| 3097 | - |
|
| 3098 | - // on sait pas quoi faire... |
|
| 3099 | - return $u; |
|
| 3067 | + if (is_string($u)){ |
|
| 3068 | + $u = typo($u); |
|
| 3069 | + return $u; |
|
| 3070 | + } |
|
| 3071 | + |
|
| 3072 | + // caster $u en array si besoin |
|
| 3073 | + if (is_object($u)) |
|
| 3074 | + $u = (array) $u; |
|
| 3075 | + |
|
| 3076 | + if (is_array($u)){ |
|
| 3077 | + $out = ""; |
|
| 3078 | + // toutes les cles sont numeriques ? |
|
| 3079 | + // et aucun enfant n'est un tableau |
|
| 3080 | + // liste simple separee par des virgules |
|
| 3081 | + $numeric_keys = array_map('is_numeric',array_keys($u)); |
|
| 3082 | + $array_values = array_map('is_array',$u); |
|
| 3083 | + $object_values = array_map('is_object',$u); |
|
| 3084 | + if (array_sum($numeric_keys)==count($numeric_keys) |
|
| 3085 | + AND !array_sum($array_values) |
|
| 3086 | + AND !array_sum($object_values)){ |
|
| 3087 | + return join(", ", array_map('filtre_print_dist', $u)); |
|
| 3088 | + } |
|
| 3089 | + |
|
| 3090 | + // sinon on passe a la ligne et on indente |
|
| 3091 | + $i_str = str_pad("",$indent," "); |
|
| 3092 | + foreach($u as $k => $v){ |
|
| 3093 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v,$join,$indent+2); |
|
| 3094 | + } |
|
| 3095 | + return $out; |
|
| 3096 | + } |
|
| 3097 | + |
|
| 3098 | + // on sait pas quoi faire... |
|
| 3099 | + return $u; |
|
| 3100 | 3100 | } |
| 3101 | 3101 | |
| 3102 | 3102 | |
@@ -3109,9 +3109,9 @@ discard block |
||
| 3109 | 3109 | * @return string |
| 3110 | 3110 | */ |
| 3111 | 3111 | function objet_info($objet,$info){ |
| 3112 | - $table = table_objet_sql($objet); |
|
| 3113 | - $infos = lister_tables_objets_sql($table); |
|
| 3114 | - return (isset($infos[$info])?$infos[$info]:''); |
|
| 3112 | + $table = table_objet_sql($objet); |
|
| 3113 | + $infos = lister_tables_objets_sql($table); |
|
| 3114 | + return (isset($infos[$info])?$infos[$info]:''); |
|
| 3115 | 3115 | } |
| 3116 | 3116 | |
| 3117 | 3117 | /** |
@@ -3122,10 +3122,10 @@ discard block |
||
| 3122 | 3122 | * @return mixed|string |
| 3123 | 3123 | */ |
| 3124 | 3124 | function objet_afficher_nb($nb, $objet){ |
| 3125 | - if (!$nb) |
|
| 3126 | - return _T(objet_info($objet,'info_aucun_objet')); |
|
| 3127 | - else |
|
| 3128 | - return _T(objet_info($objet,$nb==1?'info_1_objet':'info_nb_objets'),array('nb'=>$nb)); |
|
| 3125 | + if (!$nb) |
|
| 3126 | + return _T(objet_info($objet,'info_aucun_objet')); |
|
| 3127 | + else |
|
| 3128 | + return _T(objet_info($objet,$nb==1?'info_1_objet':'info_nb_objets'),array('nb'=>$nb)); |
|
| 3129 | 3129 | } |
| 3130 | 3130 | |
| 3131 | 3131 | /** |
@@ -3136,10 +3136,10 @@ discard block |
||
| 3136 | 3136 | * @return string |
| 3137 | 3137 | */ |
| 3138 | 3138 | function objet_icone($objet,$taille=24){ |
| 3139 | - $icone = objet_info($objet,'icone_objet')."-".$taille.".png"; |
|
| 3140 | - $icone = chemin_image($icone); |
|
| 3141 | - $balise_img = charger_filtre('balise_img'); |
|
| 3142 | - return $icone?$balise_img($icone,_T(objet_info($objet,'texte_objet'))):''; |
|
| 3139 | + $icone = objet_info($objet,'icone_objet')."-".$taille.".png"; |
|
| 3140 | + $icone = chemin_image($icone); |
|
| 3141 | + $balise_img = charger_filtre('balise_img'); |
|
| 3142 | + return $icone?$balise_img($icone,_T(objet_info($objet,'texte_objet'))):''; |
|
| 3143 | 3143 | } |
| 3144 | 3144 | |
| 3145 | 3145 | /** |
@@ -3153,14 +3153,14 @@ discard block |
||
| 3153 | 3153 | * @return string Code HTML |
| 3154 | 3154 | */ |
| 3155 | 3155 | function insert_head_css_conditionnel($flux){ |
| 3156 | - if (strpos($flux,'<!-- insert_head_css -->')===false |
|
| 3157 | - AND $p=strpos($flux,'<!-- insert_head -->')){ |
|
| 3158 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 3159 | - if ($p1 = stripos($flux,'<script src=') AND $p1<$p) |
|
| 3160 | - $p = $p1; |
|
| 3161 | - $flux = substr_replace($flux,pipeline('insert_head_css','<!-- insert_head_css -->'),$p,0); |
|
| 3162 | - } |
|
| 3163 | - return $flux; |
|
| 3156 | + if (strpos($flux,'<!-- insert_head_css -->')===false |
|
| 3157 | + AND $p=strpos($flux,'<!-- insert_head -->')){ |
|
| 3158 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 3159 | + if ($p1 = stripos($flux,'<script src=') AND $p1<$p) |
|
| 3160 | + $p = $p1; |
|
| 3161 | + $flux = substr_replace($flux,pipeline('insert_head_css','<!-- insert_head_css -->'),$p,0); |
|
| 3162 | + } |
|
| 3163 | + return $flux; |
|
| 3164 | 3164 | } |
| 3165 | 3165 | |
| 3166 | 3166 | /** |
@@ -3178,57 +3178,57 @@ discard block |
||
| 3178 | 3178 | * @return string |
| 3179 | 3179 | */ |
| 3180 | 3180 | function produire_fond_statique($fond, $contexte=array(), $options = array(), $connect=''){ |
| 3181 | - if (isset($contexte['format'])){ |
|
| 3182 | - $extension = $contexte['format']; |
|
| 3183 | - unset($contexte['format']); |
|
| 3184 | - } |
|
| 3185 | - else { |
|
| 3186 | - $extension = "html"; |
|
| 3187 | - if (preg_match(',[.](css|js|json)$,',$fond,$m)) |
|
| 3188 | - $extension = $m[1]; |
|
| 3189 | - } |
|
| 3190 | - // recuperer le contenu produit par le squelette |
|
| 3191 | - $options['raw'] = true; |
|
| 3192 | - $cache = recuperer_fond($fond,$contexte,$options,$connect); |
|
| 3181 | + if (isset($contexte['format'])){ |
|
| 3182 | + $extension = $contexte['format']; |
|
| 3183 | + unset($contexte['format']); |
|
| 3184 | + } |
|
| 3185 | + else { |
|
| 3186 | + $extension = "html"; |
|
| 3187 | + if (preg_match(',[.](css|js|json)$,',$fond,$m)) |
|
| 3188 | + $extension = $m[1]; |
|
| 3189 | + } |
|
| 3190 | + // recuperer le contenu produit par le squelette |
|
| 3191 | + $options['raw'] = true; |
|
| 3192 | + $cache = recuperer_fond($fond,$contexte,$options,$connect); |
|
| 3193 | 3193 | |
| 3194 | - // calculer le nom de la css |
|
| 3195 | - $dir_var = sous_repertoire (_DIR_VAR, 'cache-'.$extension); |
|
| 3196 | - $nom_safe = preg_replace(",\W,",'_',str_replace('.','_',$fond)); |
|
| 3197 | - $filename = $dir_var . $extension."dyn-$nom_safe-".substr(md5($fond.serialize($contexte).$connect),0,8) .".$extension"; |
|
| 3198 | - |
|
| 3199 | - // mettre a jour le fichier si il n'existe pas |
|
| 3200 | - // ou trop ancien |
|
| 3201 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 3202 | - // et recopie sur le fichier cible uniquement si il change |
|
| 3203 | - if (!file_exists($filename) |
|
| 3204 | - OR !file_exists($filename.".last") |
|
| 3205 | - OR (isset($cache['lastmodified']) AND $cache['lastmodified'] AND filemtime($filename.".last")<$cache['lastmodified']) |
|
| 3206 | - OR (defined('_VAR_MODE') AND _VAR_MODE=='recalcul')) { |
|
| 3207 | - $contenu = $cache['texte']; |
|
| 3208 | - // passer les urls en absolu si c'est une css |
|
| 3209 | - if ($extension=="css") |
|
| 3210 | - $contenu = urls_absolues_css($contenu, test_espace_prive()?generer_url_ecrire('accueil'):generer_url_public($fond)); |
|
| 3194 | + // calculer le nom de la css |
|
| 3195 | + $dir_var = sous_repertoire (_DIR_VAR, 'cache-'.$extension); |
|
| 3196 | + $nom_safe = preg_replace(",\W,",'_',str_replace('.','_',$fond)); |
|
| 3197 | + $filename = $dir_var . $extension."dyn-$nom_safe-".substr(md5($fond.serialize($contexte).$connect),0,8) .".$extension"; |
|
| 3198 | + |
|
| 3199 | + // mettre a jour le fichier si il n'existe pas |
|
| 3200 | + // ou trop ancien |
|
| 3201 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 3202 | + // et recopie sur le fichier cible uniquement si il change |
|
| 3203 | + if (!file_exists($filename) |
|
| 3204 | + OR !file_exists($filename.".last") |
|
| 3205 | + OR (isset($cache['lastmodified']) AND $cache['lastmodified'] AND filemtime($filename.".last")<$cache['lastmodified']) |
|
| 3206 | + OR (defined('_VAR_MODE') AND _VAR_MODE=='recalcul')) { |
|
| 3207 | + $contenu = $cache['texte']; |
|
| 3208 | + // passer les urls en absolu si c'est une css |
|
| 3209 | + if ($extension=="css") |
|
| 3210 | + $contenu = urls_absolues_css($contenu, test_espace_prive()?generer_url_ecrire('accueil'):generer_url_public($fond)); |
|
| 3211 | 3211 | |
| 3212 | - // ne pas insérer de commentaire si c'est du json |
|
| 3213 | - if ($extension!="json") { |
|
| 3214 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 3215 | - foreach($contexte as $k=>$v) |
|
| 3216 | - $comment .= ",$k=$v"; |
|
| 3217 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 3218 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 3219 | - $comment .="}\n md5:".md5($contenu)." */\n"; |
|
| 3220 | - } |
|
| 3221 | - // et ecrire le fichier |
|
| 3222 | - ecrire_fichier($filename.".last",$comment.$contenu); |
|
| 3223 | - // regarder si on recopie |
|
| 3224 | - if (!file_exists($filename) |
|
| 3225 | - OR md5_file($filename)!==md5_file($filename.".last")){ |
|
| 3226 | - @copy($filename.".last",$filename); |
|
| 3227 | - spip_clearstatcache(true,$filename); // eviter que PHP ne reserve le vieux timestamp |
|
| 3228 | - } |
|
| 3229 | - } |
|
| 3212 | + // ne pas insérer de commentaire si c'est du json |
|
| 3213 | + if ($extension!="json") { |
|
| 3214 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 3215 | + foreach($contexte as $k=>$v) |
|
| 3216 | + $comment .= ",$k=$v"; |
|
| 3217 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 3218 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 3219 | + $comment .="}\n md5:".md5($contenu)." */\n"; |
|
| 3220 | + } |
|
| 3221 | + // et ecrire le fichier |
|
| 3222 | + ecrire_fichier($filename.".last",$comment.$contenu); |
|
| 3223 | + // regarder si on recopie |
|
| 3224 | + if (!file_exists($filename) |
|
| 3225 | + OR md5_file($filename)!==md5_file($filename.".last")){ |
|
| 3226 | + @copy($filename.".last",$filename); |
|
| 3227 | + spip_clearstatcache(true,$filename); // eviter que PHP ne reserve le vieux timestamp |
|
| 3228 | + } |
|
| 3229 | + } |
|
| 3230 | 3230 | |
| 3231 | - return $filename; |
|
| 3231 | + return $filename; |
|
| 3232 | 3232 | } |
| 3233 | 3233 | |
| 3234 | 3234 | /** |
@@ -3239,9 +3239,9 @@ discard block |
||
| 3239 | 3239 | * @return string |
| 3240 | 3240 | */ |
| 3241 | 3241 | function timestamp($fichier){ |
| 3242 | - if (!$fichier OR !file_exists($fichier)) return $fichier; |
|
| 3243 | - $m = filemtime($fichier); |
|
| 3244 | - return "$fichier?$m"; |
|
| 3242 | + if (!$fichier OR !file_exists($fichier)) return $fichier; |
|
| 3243 | + $m = filemtime($fichier); |
|
| 3244 | + return "$fichier?$m"; |
|
| 3245 | 3245 | } |
| 3246 | 3246 | |
| 3247 | 3247 | /** |
@@ -3251,8 +3251,8 @@ discard block |
||
| 3251 | 3251 | * @return mixed |
| 3252 | 3252 | */ |
| 3253 | 3253 | function filtre_nettoyer_titre_email_dist($titre){ |
| 3254 | - include_spip('inc/envoyer_mail'); |
|
| 3255 | - return nettoyer_titre_email($titre); |
|
| 3254 | + include_spip('inc/envoyer_mail'); |
|
| 3255 | + return nettoyer_titre_email($titre); |
|
| 3256 | 3256 | } |
| 3257 | 3257 | |
| 3258 | 3258 | /** |
@@ -3272,8 +3272,8 @@ discard block |
||
| 3272 | 3272 | * @return string |
| 3273 | 3273 | */ |
| 3274 | 3274 | function filtre_chercher_rubrique_dist($titre,$id_objet, $id_parent, $objet, $id_secteur, $restreint,$actionable = false, $retour_sans_cadre=false){ |
| 3275 | - include_spip('inc/filtres_ecrire'); |
|
| 3276 | - return chercher_rubrique($titre,$id_objet, $id_parent, $objet, $id_secteur, $restreint,$actionable, $retour_sans_cadre); |
|
| 3275 | + include_spip('inc/filtres_ecrire'); |
|
| 3276 | + return chercher_rubrique($titre,$id_objet, $id_parent, $objet, $id_secteur, $restreint,$actionable, $retour_sans_cadre); |
|
| 3277 | 3277 | } |
| 3278 | 3278 | |
| 3279 | 3279 | /** |
@@ -3289,45 +3289,45 @@ discard block |
||
| 3289 | 3289 | * @return string |
| 3290 | 3290 | */ |
| 3291 | 3291 | function sinon_interdire_acces($ok=false, $url='', $statut=0){ |
| 3292 | - if ($ok) return ''; |
|
| 3292 | + if ($ok) return ''; |
|
| 3293 | 3293 | |
| 3294 | - // Vider tous les tampons |
|
| 3295 | - $level = @ob_get_level(); |
|
| 3296 | - while ($level--) |
|
| 3297 | - @ob_end_clean(); |
|
| 3294 | + // Vider tous les tampons |
|
| 3295 | + $level = @ob_get_level(); |
|
| 3296 | + while ($level--) |
|
| 3297 | + @ob_end_clean(); |
|
| 3298 | 3298 | |
| 3299 | - include_spip('inc/headers'); |
|
| 3300 | - $statut = intval($statut); |
|
| 3299 | + include_spip('inc/headers'); |
|
| 3300 | + $statut = intval($statut); |
|
| 3301 | 3301 | |
| 3302 | - // Si aucun argument on essaye de deviner quoi faire par défaut |
|
| 3303 | - if (!$url and !$statut){ |
|
| 3304 | - // Si on est dans l'espace privé, on génère du 403 Forbidden |
|
| 3305 | - if (test_espace_prive()){ |
|
| 3306 | - http_status(403); |
|
| 3307 | - $echec = charger_fonction('403','exec'); |
|
| 3308 | - $echec(); |
|
| 3309 | - } |
|
| 3310 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 3311 | - else{ |
|
| 3312 | - $statut = 404; |
|
| 3313 | - } |
|
| 3314 | - } |
|
| 3302 | + // Si aucun argument on essaye de deviner quoi faire par défaut |
|
| 3303 | + if (!$url and !$statut){ |
|
| 3304 | + // Si on est dans l'espace privé, on génère du 403 Forbidden |
|
| 3305 | + if (test_espace_prive()){ |
|
| 3306 | + http_status(403); |
|
| 3307 | + $echec = charger_fonction('403','exec'); |
|
| 3308 | + $echec(); |
|
| 3309 | + } |
|
| 3310 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 3311 | + else{ |
|
| 3312 | + $statut = 404; |
|
| 3313 | + } |
|
| 3314 | + } |
|
| 3315 | 3315 | |
| 3316 | - // On suit les directives indiquées dans les deux arguments |
|
| 3316 | + // On suit les directives indiquées dans les deux arguments |
|
| 3317 | 3317 | |
| 3318 | - // S'il y a un statut |
|
| 3319 | - if ($statut){ |
|
| 3320 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 3321 | - http_status($statut); |
|
| 3322 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 3323 | - if ($statut >= 400 and !$url) |
|
| 3324 | - echo recuperer_fond("$statut"); |
|
| 3325 | - } |
|
| 3318 | + // S'il y a un statut |
|
| 3319 | + if ($statut){ |
|
| 3320 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 3321 | + http_status($statut); |
|
| 3322 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 3323 | + if ($statut >= 400 and !$url) |
|
| 3324 | + echo recuperer_fond("$statut"); |
|
| 3325 | + } |
|
| 3326 | 3326 | |
| 3327 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 3328 | - if ($url) redirige_par_entete($url, '', $statut); |
|
| 3327 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 3328 | + if ($url) redirige_par_entete($url, '', $statut); |
|
| 3329 | 3329 | |
| 3330 | - exit; |
|
| 3330 | + exit; |
|
| 3331 | 3331 | } |
| 3332 | 3332 | |
| 3333 | 3333 | /** |
@@ -3337,9 +3337,9 @@ discard block |
||
| 3337 | 3337 | * @return string |
| 3338 | 3338 | */ |
| 3339 | 3339 | function filtre_compacte_dist($source, $format = null){ |
| 3340 | - if (function_exists('compacte')) |
|
| 3341 | - return compacte($source, $format); |
|
| 3342 | - return $source; |
|
| 3340 | + if (function_exists('compacte')) |
|
| 3341 | + return compacte($source, $format); |
|
| 3342 | + return $source; |
|
| 3343 | 3343 | } |
| 3344 | 3344 | |
| 3345 | 3345 | ?> |
@@ -23,59 +23,59 @@ |
||
| 23 | 23 | |
| 24 | 24 | // http://doc.spip.org/@var2js |
| 25 | 25 | function var2js($var) { |
| 26 | - $asso = false; |
|
| 27 | - switch (true) { |
|
| 28 | - case is_null($var) : |
|
| 29 | - return 'null'; |
|
| 30 | - case is_string($var) : |
|
| 31 | - return '"' .addcslashes($var, "\"\\\n\r/") . '"'; |
|
| 32 | - case is_bool($var) : |
|
| 33 | - return $var ? 'true' : 'false'; |
|
| 34 | - case is_scalar($var) : |
|
| 35 | - return (string)$var; |
|
| 36 | - case is_object( $var) : |
|
| 37 | - $var = get_object_vars($var); |
|
| 38 | - $asso = true; |
|
| 39 | - case is_array($var) : |
|
| 40 | - $keys = array_keys($var); |
|
| 41 | - $ikey = count($keys); |
|
| 42 | - while (!$asso && $ikey--) { |
|
| 43 | - $asso = $ikey !== $keys[$ikey]; |
|
| 44 | - } |
|
| 45 | - $sep = ''; |
|
| 46 | - if ($asso) { |
|
| 47 | - $ret = '{'; |
|
| 48 | - foreach ($var as $key => $elt) { |
|
| 49 | - $ret .= $sep . '"' . $key . '":' . var2js($elt); |
|
| 50 | - $sep = ','; |
|
| 51 | - } |
|
| 52 | - return $ret ."}"; |
|
| 53 | - } else { |
|
| 54 | - $ret = '['; |
|
| 55 | - foreach ($var as $elt) { |
|
| 56 | - $ret .= $sep . var2js($elt); |
|
| 57 | - $sep = ','; |
|
| 58 | - } |
|
| 59 | - return $ret ."]"; |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - return false; |
|
| 26 | + $asso = false; |
|
| 27 | + switch (true) { |
|
| 28 | + case is_null($var) : |
|
| 29 | + return 'null'; |
|
| 30 | + case is_string($var) : |
|
| 31 | + return '"' .addcslashes($var, "\"\\\n\r/") . '"'; |
|
| 32 | + case is_bool($var) : |
|
| 33 | + return $var ? 'true' : 'false'; |
|
| 34 | + case is_scalar($var) : |
|
| 35 | + return (string)$var; |
|
| 36 | + case is_object( $var) : |
|
| 37 | + $var = get_object_vars($var); |
|
| 38 | + $asso = true; |
|
| 39 | + case is_array($var) : |
|
| 40 | + $keys = array_keys($var); |
|
| 41 | + $ikey = count($keys); |
|
| 42 | + while (!$asso && $ikey--) { |
|
| 43 | + $asso = $ikey !== $keys[$ikey]; |
|
| 44 | + } |
|
| 45 | + $sep = ''; |
|
| 46 | + if ($asso) { |
|
| 47 | + $ret = '{'; |
|
| 48 | + foreach ($var as $key => $elt) { |
|
| 49 | + $ret .= $sep . '"' . $key . '":' . var2js($elt); |
|
| 50 | + $sep = ','; |
|
| 51 | + } |
|
| 52 | + return $ret ."}"; |
|
| 53 | + } else { |
|
| 54 | + $ret = '['; |
|
| 55 | + foreach ($var as $elt) { |
|
| 56 | + $ret .= $sep . var2js($elt); |
|
| 57 | + $sep = ','; |
|
| 58 | + } |
|
| 59 | + return $ret ."]"; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + return false; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | if(!function_exists('json_encode')) { |
| 66 | - function json_encode($v) { return var2js($v); } |
|
| 66 | + function json_encode($v) { return var2js($v); } |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | // http://doc.spip.org/@json_export |
| 70 | 70 | function json_export($var) { |
| 71 | - $var = json_encode($var); |
|
| 71 | + $var = json_encode($var); |
|
| 72 | 72 | |
| 73 | - // flag indiquant qu'on est en iframe et qu'il faut proteger nos |
|
| 74 | - // donnees dans un <textarea> ; attention $_FILES a ete vide par array_pop |
|
| 75 | - if (defined('FILE_UPLOAD')) |
|
| 76 | - return "<textarea>".spip_htmlspecialchars($var)."</textarea>"; |
|
| 77 | - else |
|
| 78 | - return $var; |
|
| 73 | + // flag indiquant qu'on est en iframe et qu'il faut proteger nos |
|
| 74 | + // donnees dans un <textarea> ; attention $_FILES a ete vide par array_pop |
|
| 75 | + if (defined('FILE_UPLOAD')) |
|
| 76 | + return "<textarea>".spip_htmlspecialchars($var)."</textarea>"; |
|
| 77 | + else |
|
| 78 | + return $var; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
@@ -16,157 +16,157 @@ discard block |
||
| 16 | 16 | // http://doc.spip.org/@formulaires_editer_objet_traiter |
| 17 | 17 | function formulaires_editer_objet_traiter($type, $id='new', $id_parent=0, $lier_trad=0, $retour='', $config_fonc='articles_edit_config', $row=array(), $hidden=''){ |
| 18 | 18 | |
| 19 | - $res = array(); |
|
| 20 | - // eviter la redirection forcee par l'action... |
|
| 21 | - set_request('redirect'); |
|
| 22 | - if ($action_editer = charger_fonction("editer_$type",'action',true)) { |
|
| 23 | - list($id,$err) = $action_editer($id); |
|
| 24 | - } |
|
| 25 | - else { |
|
| 26 | - $action_editer = charger_fonction("editer_objet",'action'); |
|
| 27 | - list($id,$err) = $action_editer($id,$type); |
|
| 28 | - } |
|
| 29 | - $id_table_objet = id_table_objet($type); |
|
| 30 | - $res[$id_table_objet] = $id; |
|
| 31 | - if ($err OR !$id){ |
|
| 32 | - $res['message_erreur'] = ($err?$err:_T('erreur')); |
|
| 33 | - } |
|
| 34 | - else{ |
|
| 35 | - // Un lien de trad a prendre en compte |
|
| 36 | - if ($lier_trad){ |
|
| 37 | - // referencer la traduction |
|
| 38 | - $referencer_traduction = charger_fonction('referencer_traduction','action'); |
|
| 39 | - $referencer_traduction($type, $id, $lier_trad); |
|
| 40 | - // dupliquer tous les liens sauf les auteurs : le nouvel auteur est celui qui traduit |
|
| 41 | - // cf API editer_liens |
|
| 42 | - include_spip('action/editer_liens'); |
|
| 43 | - objet_dupliquer_liens($type,$lier_trad,$id,null,array('auteur')); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 47 | - if ($retour) { |
|
| 48 | - if (strncmp($retour,'javascript:',11)==0){ |
|
| 49 | - $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/'.substr($retour,11).'/*]]>*/</script>'; |
|
| 50 | - $res['editable'] = true; |
|
| 51 | - } |
|
| 52 | - else |
|
| 53 | - $res['redirect'] = parametre_url($retour,$id_table_objet,$id); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - return $res; |
|
| 19 | + $res = array(); |
|
| 20 | + // eviter la redirection forcee par l'action... |
|
| 21 | + set_request('redirect'); |
|
| 22 | + if ($action_editer = charger_fonction("editer_$type",'action',true)) { |
|
| 23 | + list($id,$err) = $action_editer($id); |
|
| 24 | + } |
|
| 25 | + else { |
|
| 26 | + $action_editer = charger_fonction("editer_objet",'action'); |
|
| 27 | + list($id,$err) = $action_editer($id,$type); |
|
| 28 | + } |
|
| 29 | + $id_table_objet = id_table_objet($type); |
|
| 30 | + $res[$id_table_objet] = $id; |
|
| 31 | + if ($err OR !$id){ |
|
| 32 | + $res['message_erreur'] = ($err?$err:_T('erreur')); |
|
| 33 | + } |
|
| 34 | + else{ |
|
| 35 | + // Un lien de trad a prendre en compte |
|
| 36 | + if ($lier_trad){ |
|
| 37 | + // referencer la traduction |
|
| 38 | + $referencer_traduction = charger_fonction('referencer_traduction','action'); |
|
| 39 | + $referencer_traduction($type, $id, $lier_trad); |
|
| 40 | + // dupliquer tous les liens sauf les auteurs : le nouvel auteur est celui qui traduit |
|
| 41 | + // cf API editer_liens |
|
| 42 | + include_spip('action/editer_liens'); |
|
| 43 | + objet_dupliquer_liens($type,$lier_trad,$id,null,array('auteur')); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 47 | + if ($retour) { |
|
| 48 | + if (strncmp($retour,'javascript:',11)==0){ |
|
| 49 | + $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/'.substr($retour,11).'/*]]>*/</script>'; |
|
| 50 | + $res['editable'] = true; |
|
| 51 | + } |
|
| 52 | + else |
|
| 53 | + $res['redirect'] = parametre_url($retour,$id_table_objet,$id); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + return $res; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // http://doc.spip.org/@formulaires_editer_objet_verifier |
| 60 | 60 | function formulaires_editer_objet_verifier($type,$id='new', $oblis = array()){ |
| 61 | - $erreurs = array(); |
|
| 62 | - if (intval($id)) { |
|
| 63 | - $conflits = controler_contenu($type,$id); |
|
| 64 | - if ($conflits AND count($conflits)) { |
|
| 65 | - foreach($conflits as $champ=>$conflit) { |
|
| 66 | - if (!isset($erreurs[$champ])) { $erreurs[$champ] = ''; } |
|
| 67 | - $erreurs[$champ] .= _T("alerte_modif_info_concourante")."<br /><textarea readonly='readonly' class='forml'>".$conflit['base']."</textarea>"; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - foreach($oblis as $obli) { |
|
| 72 | - $value = _request($obli); |
|
| 73 | - if (is_null($value) OR !(is_array($value)?count($value):strlen($value))) { |
|
| 74 | - if (!isset($erreurs[$obli])) { $erreurs[$obli] = ''; } |
|
| 75 | - $erreurs[$obli] .= _T("info_obligatoire"); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - return $erreurs; |
|
| 61 | + $erreurs = array(); |
|
| 62 | + if (intval($id)) { |
|
| 63 | + $conflits = controler_contenu($type,$id); |
|
| 64 | + if ($conflits AND count($conflits)) { |
|
| 65 | + foreach($conflits as $champ=>$conflit) { |
|
| 66 | + if (!isset($erreurs[$champ])) { $erreurs[$champ] = ''; } |
|
| 67 | + $erreurs[$champ] .= _T("alerte_modif_info_concourante")."<br /><textarea readonly='readonly' class='forml'>".$conflit['base']."</textarea>"; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + foreach($oblis as $obli) { |
|
| 72 | + $value = _request($obli); |
|
| 73 | + if (is_null($value) OR !(is_array($value)?count($value):strlen($value))) { |
|
| 74 | + if (!isset($erreurs[$obli])) { $erreurs[$obli] = ''; } |
|
| 75 | + $erreurs[$obli] .= _T("info_obligatoire"); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + return $erreurs; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // http://doc.spip.org/@formulaires_editer_objet_charger |
| 82 | 82 | function formulaires_editer_objet_charger($type, $id='new', $id_parent=0, $lier_trad=0, $retour='', $config_fonc='articles_edit_config', $row=array(), $hidden=''){ |
| 83 | - $table_objet = table_objet($type); |
|
| 84 | - $table_objet_sql = table_objet_sql($type); |
|
| 85 | - $id_table_objet = id_table_objet($type); |
|
| 86 | - $new = !is_numeric($id); |
|
| 87 | - // Appel direct dans un squelette |
|
| 88 | - if (!$row) { |
|
| 89 | - if (!$new OR $lier_trad) { |
|
| 90 | - if ($select = charger_fonction("precharger_" . $type, 'inc', true)) |
|
| 91 | - $row = $select($id, $id_parent, $lier_trad); |
|
| 92 | - else $row = sql_fetsel('*',$table_objet_sql,$id_table_objet."=".intval($id)); |
|
| 93 | - if (!$new) |
|
| 94 | - $md5 = controles_md5($row); |
|
| 95 | - } |
|
| 96 | - if (!$row) { |
|
| 97 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 98 | - if ($desc = $trouver_table($table_objet)) |
|
| 99 | - foreach($desc['field'] as $k=>$v) $row[$k]=''; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 104 | - // (et donc: pas de lien de traduction) |
|
| 105 | - $id = ($new OR $lier_trad) |
|
| 106 | - ? 'oui' |
|
| 107 | - : $row[$id_table_objet]; |
|
| 108 | - $row[$id_table_objet] = $id; |
|
| 109 | - |
|
| 110 | - $contexte = $row; |
|
| 111 | - if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) OR $new)){ |
|
| 112 | - if (!isset($contexte['id_parent'])) unset($contexte['id_rubrique']); |
|
| 113 | - $contexte['id_parent']=$id_parent; |
|
| 114 | - } |
|
| 115 | - elseif (!isset($contexte['id_parent'])){ |
|
| 116 | - // id_rubrique dans id_parent si possible |
|
| 117 | - if (isset($contexte['id_rubrique'])) { |
|
| 118 | - $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 119 | - unset($contexte['id_rubrique']); |
|
| 120 | - } |
|
| 121 | - else{ |
|
| 122 | - $contexte['id_parent'] = ''; |
|
| 123 | - } |
|
| 124 | - if (!$contexte['id_parent'] |
|
| 125 | - AND $preselectionner_parent_nouvel_objet = charger_fonction("preselectionner_parent_nouvel_objet","inc",true)) |
|
| 126 | - $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type,$row); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - if ($config_fonc) |
|
| 130 | - $contexte['config'] = $config = $config_fonc($contexte); |
|
| 131 | - if (!isset($config['lignes'])) $config['lignes'] = 0; |
|
| 132 | - $att_text = " class='textarea' " |
|
| 133 | - . " rows='" |
|
| 134 | - . ($config['lignes'] +15) |
|
| 135 | - . "' cols='40'"; |
|
| 136 | - if (isset($contexte['texte'])) |
|
| 137 | - list($contexte['texte'],$contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'],$att_text); |
|
| 138 | - |
|
| 139 | - // on veut conserver la langue de l'interface ; |
|
| 140 | - // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 141 | - // voudrait l'exploiter |
|
| 142 | - if (isset($contexte['lang'])) { |
|
| 143 | - $contexte['langue'] = $contexte['lang']; |
|
| 144 | - unset($contexte['lang']); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 148 | - (!$lier_trad ? '' : |
|
| 149 | - ("\n<input type='hidden' name='lier_trad' value='" . |
|
| 150 | - $lier_trad . |
|
| 151 | - "' />" . |
|
| 152 | - "\n<input type='hidden' name='changer_lang' value='" . |
|
| 153 | - $config['langue'] . |
|
| 154 | - "' />")) |
|
| 155 | - . $hidden |
|
| 156 | - . (isset($md5) ? $md5 : ''); |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - if (isset($contexte['extra'])) |
|
| 160 | - $contexte['extra'] = unserialize($contexte['extra']); |
|
| 161 | - // preciser que le formulaire doit passer dans un pipeline |
|
| 162 | - $contexte['_pipeline'] = array('editer_contenu_objet',array('type'=>$type,'id'=>$id)); |
|
| 163 | - |
|
| 164 | - // preciser que le formulaire doit etre securise auteur/action |
|
| 165 | - // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 166 | - // on le garde pour compat |
|
| 167 | - $contexte['_action'] = array("editer_$type",$id); |
|
| 168 | - |
|
| 169 | - return $contexte; |
|
| 83 | + $table_objet = table_objet($type); |
|
| 84 | + $table_objet_sql = table_objet_sql($type); |
|
| 85 | + $id_table_objet = id_table_objet($type); |
|
| 86 | + $new = !is_numeric($id); |
|
| 87 | + // Appel direct dans un squelette |
|
| 88 | + if (!$row) { |
|
| 89 | + if (!$new OR $lier_trad) { |
|
| 90 | + if ($select = charger_fonction("precharger_" . $type, 'inc', true)) |
|
| 91 | + $row = $select($id, $id_parent, $lier_trad); |
|
| 92 | + else $row = sql_fetsel('*',$table_objet_sql,$id_table_objet."=".intval($id)); |
|
| 93 | + if (!$new) |
|
| 94 | + $md5 = controles_md5($row); |
|
| 95 | + } |
|
| 96 | + if (!$row) { |
|
| 97 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 98 | + if ($desc = $trouver_table($table_objet)) |
|
| 99 | + foreach($desc['field'] as $k=>$v) $row[$k]=''; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 104 | + // (et donc: pas de lien de traduction) |
|
| 105 | + $id = ($new OR $lier_trad) |
|
| 106 | + ? 'oui' |
|
| 107 | + : $row[$id_table_objet]; |
|
| 108 | + $row[$id_table_objet] = $id; |
|
| 109 | + |
|
| 110 | + $contexte = $row; |
|
| 111 | + if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) OR $new)){ |
|
| 112 | + if (!isset($contexte['id_parent'])) unset($contexte['id_rubrique']); |
|
| 113 | + $contexte['id_parent']=$id_parent; |
|
| 114 | + } |
|
| 115 | + elseif (!isset($contexte['id_parent'])){ |
|
| 116 | + // id_rubrique dans id_parent si possible |
|
| 117 | + if (isset($contexte['id_rubrique'])) { |
|
| 118 | + $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 119 | + unset($contexte['id_rubrique']); |
|
| 120 | + } |
|
| 121 | + else{ |
|
| 122 | + $contexte['id_parent'] = ''; |
|
| 123 | + } |
|
| 124 | + if (!$contexte['id_parent'] |
|
| 125 | + AND $preselectionner_parent_nouvel_objet = charger_fonction("preselectionner_parent_nouvel_objet","inc",true)) |
|
| 126 | + $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type,$row); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + if ($config_fonc) |
|
| 130 | + $contexte['config'] = $config = $config_fonc($contexte); |
|
| 131 | + if (!isset($config['lignes'])) $config['lignes'] = 0; |
|
| 132 | + $att_text = " class='textarea' " |
|
| 133 | + . " rows='" |
|
| 134 | + . ($config['lignes'] +15) |
|
| 135 | + . "' cols='40'"; |
|
| 136 | + if (isset($contexte['texte'])) |
|
| 137 | + list($contexte['texte'],$contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'],$att_text); |
|
| 138 | + |
|
| 139 | + // on veut conserver la langue de l'interface ; |
|
| 140 | + // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 141 | + // voudrait l'exploiter |
|
| 142 | + if (isset($contexte['lang'])) { |
|
| 143 | + $contexte['langue'] = $contexte['lang']; |
|
| 144 | + unset($contexte['lang']); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 148 | + (!$lier_trad ? '' : |
|
| 149 | + ("\n<input type='hidden' name='lier_trad' value='" . |
|
| 150 | + $lier_trad . |
|
| 151 | + "' />" . |
|
| 152 | + "\n<input type='hidden' name='changer_lang' value='" . |
|
| 153 | + $config['langue'] . |
|
| 154 | + "' />")) |
|
| 155 | + . $hidden |
|
| 156 | + . (isset($md5) ? $md5 : ''); |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + if (isset($contexte['extra'])) |
|
| 160 | + $contexte['extra'] = unserialize($contexte['extra']); |
|
| 161 | + // preciser que le formulaire doit passer dans un pipeline |
|
| 162 | + $contexte['_pipeline'] = array('editer_contenu_objet',array('type'=>$type,'id'=>$id)); |
|
| 163 | + |
|
| 164 | + // preciser que le formulaire doit etre securise auteur/action |
|
| 165 | + // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 166 | + // on le garde pour compat |
|
| 167 | + $contexte['_action'] = array("editer_$type",$id); |
|
| 168 | + |
|
| 169 | + return $contexte; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // |
@@ -175,48 +175,48 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | // http://doc.spip.org/@coupe_trop_long |
| 177 | 177 | function coupe_trop_long($texte){ |
| 178 | - $aider = charger_fonction('aider', 'inc'); |
|
| 179 | - if (strlen($texte) > 28*1024) { |
|
| 180 | - $texte = str_replace("\r\n","\n",$texte); |
|
| 181 | - $pos = strpos($texte, "\n\n", 28*1024); // coupe para > 28 ko |
|
| 182 | - if ($pos > 0 and $pos < 32 * 1024) { |
|
| 183 | - $debut = substr($texte, 0, $pos)."\n\n<!--SPIP-->\n"; |
|
| 184 | - $suite = substr($texte, $pos + 2); |
|
| 185 | - } else { |
|
| 186 | - $pos = strpos($texte, " ", 28*1024); // sinon coupe espace |
|
| 187 | - if (!($pos > 0 and $pos < 32 * 1024)) { |
|
| 188 | - $pos = 28*1024; // au pire (pas d'espace trouv'e) |
|
| 189 | - $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 190 | - } else { |
|
| 191 | - $decalage = 1; |
|
| 192 | - } |
|
| 193 | - $debut = substr($texte,0,$pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 194 | - $suite = substr($texte,$pos + $decalage); |
|
| 195 | - } |
|
| 196 | - return (array($debut,$suite)); |
|
| 197 | - } |
|
| 198 | - else |
|
| 199 | - return (array($texte,'')); |
|
| 178 | + $aider = charger_fonction('aider', 'inc'); |
|
| 179 | + if (strlen($texte) > 28*1024) { |
|
| 180 | + $texte = str_replace("\r\n","\n",$texte); |
|
| 181 | + $pos = strpos($texte, "\n\n", 28*1024); // coupe para > 28 ko |
|
| 182 | + if ($pos > 0 and $pos < 32 * 1024) { |
|
| 183 | + $debut = substr($texte, 0, $pos)."\n\n<!--SPIP-->\n"; |
|
| 184 | + $suite = substr($texte, $pos + 2); |
|
| 185 | + } else { |
|
| 186 | + $pos = strpos($texte, " ", 28*1024); // sinon coupe espace |
|
| 187 | + if (!($pos > 0 and $pos < 32 * 1024)) { |
|
| 188 | + $pos = 28*1024; // au pire (pas d'espace trouv'e) |
|
| 189 | + $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 190 | + } else { |
|
| 191 | + $decalage = 1; |
|
| 192 | + } |
|
| 193 | + $debut = substr($texte,0,$pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 194 | + $suite = substr($texte,$pos + $decalage); |
|
| 195 | + } |
|
| 196 | + return (array($debut,$suite)); |
|
| 197 | + } |
|
| 198 | + else |
|
| 199 | + return (array($texte,'')); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // http://doc.spip.org/@editer_texte_recolle |
| 203 | 203 | function editer_texte_recolle($texte, $att_text) |
| 204 | 204 | { |
| 205 | - if ((strlen($texte)<29*1024) |
|
| 206 | - OR (include_spip('inc/layer') AND ($GLOBALS['browser_name']!="MSIE")) ) |
|
| 207 | - return array($texte,""); |
|
| 208 | - |
|
| 209 | - include_spip('inc/barre'); |
|
| 210 | - $textes_supplement = "<br /><span style='color: red'>"._T('info_texte_long')."</span>\n"; |
|
| 211 | - $nombre = 0; |
|
| 212 | - |
|
| 213 | - while (strlen($texte)>29*1024) { |
|
| 214 | - $nombre ++; |
|
| 215 | - list($texte1,$texte) = coupe_trop_long($texte); |
|
| 216 | - $textes_supplement .= "<br />" . |
|
| 217 | - "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n"; |
|
| 218 | - } |
|
| 219 | - return array($texte,$textes_supplement); |
|
| 205 | + if ((strlen($texte)<29*1024) |
|
| 206 | + OR (include_spip('inc/layer') AND ($GLOBALS['browser_name']!="MSIE")) ) |
|
| 207 | + return array($texte,""); |
|
| 208 | + |
|
| 209 | + include_spip('inc/barre'); |
|
| 210 | + $textes_supplement = "<br /><span style='color: red'>"._T('info_texte_long')."</span>\n"; |
|
| 211 | + $nombre = 0; |
|
| 212 | + |
|
| 213 | + while (strlen($texte)>29*1024) { |
|
| 214 | + $nombre ++; |
|
| 215 | + list($texte1,$texte) = coupe_trop_long($texte); |
|
| 216 | + $textes_supplement .= "<br />" . |
|
| 217 | + "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n"; |
|
| 218 | + } |
|
| 219 | + return array($texte,$textes_supplement); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -227,15 +227,15 @@ discard block |
||
| 227 | 227 | * @param int $longueur |
| 228 | 228 | */ |
| 229 | 229 | function titre_automatique($champ_titre,$champs_contenu,$longueur=null){ |
| 230 | - if (!_request($champ_titre)){ |
|
| 231 | - $titrer_contenu = charger_fonction('titrer_contenu','inc'); |
|
| 232 | - if (!is_null($longueur)) |
|
| 233 | - $t = $titrer_contenu($champs_contenu,null,$longueur); |
|
| 234 | - else |
|
| 235 | - $t = $titrer_contenu($champs_contenu); |
|
| 236 | - if ($t) |
|
| 237 | - set_request($champ_titre,$t); |
|
| 238 | - } |
|
| 230 | + if (!_request($champ_titre)){ |
|
| 231 | + $titrer_contenu = charger_fonction('titrer_contenu','inc'); |
|
| 232 | + if (!is_null($longueur)) |
|
| 233 | + $t = $titrer_contenu($champs_contenu,null,$longueur); |
|
| 234 | + else |
|
| 235 | + $t = $titrer_contenu($champs_contenu); |
|
| 236 | + if ($t) |
|
| 237 | + set_request($champ_titre,$t); |
|
| 238 | + } |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -252,233 +252,233 @@ discard block |
||
| 252 | 252 | * @return string |
| 253 | 253 | */ |
| 254 | 254 | function inc_titrer_contenu_dist($champs_contenu, $c=null, $longueur=50){ |
| 255 | - // trouver un champ texte non vide |
|
| 256 | - $t = ""; |
|
| 257 | - foreach($champs_contenu as $champ){ |
|
| 258 | - if ($t = _request($champ,$c)) |
|
| 259 | - break; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - if ($t){ |
|
| 263 | - include_spip('inc/texte_mini'); |
|
| 264 | - $t = couper($t,$longueur,"..."); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - return $t; |
|
| 255 | + // trouver un champ texte non vide |
|
| 256 | + $t = ""; |
|
| 257 | + foreach($champs_contenu as $champ){ |
|
| 258 | + if ($t = _request($champ,$c)) |
|
| 259 | + break; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + if ($t){ |
|
| 263 | + include_spip('inc/texte_mini'); |
|
| 264 | + $t = couper($t,$longueur,"..."); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + return $t; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // Produit la liste des md5 d'un tableau de donnees, sous forme |
| 271 | 271 | // de inputs html |
| 272 | 272 | // http://doc.spip.org/@controles_md5 |
| 273 | 273 | function controles_md5($data, $prefixe='ctr_', $format='html'){ |
| 274 | - if (!is_array($data)) |
|
| 275 | - return false; |
|
| 276 | - |
|
| 277 | - $ctr = array(); |
|
| 278 | - foreach ($data as $key => $val) { |
|
| 279 | - $m = md5($val); |
|
| 280 | - $k = $prefixe.$key; |
|
| 281 | - |
|
| 282 | - switch ($format) { |
|
| 283 | - case 'html': |
|
| 284 | - $ctr[$k] = "<input type='hidden' value='$m' name='$k' />"; |
|
| 285 | - break; |
|
| 286 | - default: |
|
| 287 | - $ctr[$k] = $m; |
|
| 288 | - break; |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if ($format == 'html') |
|
| 293 | - return "\n\n<!-- controles md5 -->\n".join("\n", $ctr)."\n\n"; |
|
| 294 | - else |
|
| 295 | - return $ctr; |
|
| 274 | + if (!is_array($data)) |
|
| 275 | + return false; |
|
| 276 | + |
|
| 277 | + $ctr = array(); |
|
| 278 | + foreach ($data as $key => $val) { |
|
| 279 | + $m = md5($val); |
|
| 280 | + $k = $prefixe.$key; |
|
| 281 | + |
|
| 282 | + switch ($format) { |
|
| 283 | + case 'html': |
|
| 284 | + $ctr[$k] = "<input type='hidden' value='$m' name='$k' />"; |
|
| 285 | + break; |
|
| 286 | + default: |
|
| 287 | + $ctr[$k] = $m; |
|
| 288 | + break; |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if ($format == 'html') |
|
| 293 | + return "\n\n<!-- controles md5 -->\n".join("\n", $ctr)."\n\n"; |
|
| 294 | + else |
|
| 295 | + return $ctr; |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | // http://doc.spip.org/@controler_contenu |
| 299 | 299 | function controler_contenu($type, $id, $options=array(), $c=false, $serveur='') { |
| 300 | - include_spip('inc/filtres'); |
|
| 301 | - |
|
| 302 | - $table_objet = table_objet($type); |
|
| 303 | - $spip_table_objet = table_objet_sql($type); |
|
| 304 | - $id_table_objet = id_table_objet($type); |
|
| 305 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 306 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 307 | - |
|
| 308 | - // Appels incomplets (sans $c) |
|
| 309 | - if (!is_array($c)) { |
|
| 310 | - foreach($desc['field'] as $champ=>$ignore) |
|
| 311 | - if(_request($champ)) |
|
| 312 | - $c[$champ] = _request($champ); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 316 | - // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 317 | - // il faut passer par instituer_XX() |
|
| 318 | - // TODO: faut-il passer ces variables interdites |
|
| 319 | - // dans un fichier de description separe ? |
|
| 320 | - unset($c['statut']); |
|
| 321 | - unset($c['id_parent']); |
|
| 322 | - unset($c['id_rubrique']); |
|
| 323 | - unset($c['id_secteur']); |
|
| 324 | - |
|
| 325 | - // Gerer les champs non vides |
|
| 326 | - if (isset($options['nonvide']) AND is_array($options['nonvide'])) |
|
| 327 | - foreach ($options['nonvide'] as $champ => $sinon) |
|
| 328 | - if ($c[$champ] === '') |
|
| 329 | - $c[$champ] = $sinon; |
|
| 330 | - |
|
| 331 | - // N'accepter que les champs qui existent |
|
| 332 | - // TODO: ici aussi on peut valider les contenus |
|
| 333 | - // en fonction du type |
|
| 334 | - $champs = array(); |
|
| 335 | - foreach($desc['field'] as $champ => $ignore) |
|
| 336 | - if (isset($c[$champ])) |
|
| 337 | - $champs[$champ] = $c[$champ]; |
|
| 338 | - |
|
| 339 | - // Nettoyer les valeurs |
|
| 340 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 341 | - |
|
| 342 | - // Envoyer aux plugins |
|
| 343 | - $champs = pipeline('pre_edition', |
|
| 344 | - array( |
|
| 345 | - 'args' => array( |
|
| 346 | - 'table' => $spip_table_objet, // compatibilite |
|
| 347 | - 'table_objet' => $table_objet, |
|
| 348 | - 'spip_table_objet' => $spip_table_objet, |
|
| 349 | - 'type' =>$type, |
|
| 350 | - 'id_objet' => $id, |
|
| 351 | - 'champs' => isset($options['champs'])?$options['champs']:array(), // [doc] c'est quoi ? |
|
| 352 | - 'action' => 'controler' |
|
| 353 | - ), |
|
| 354 | - 'data' => $champs |
|
| 355 | - ) |
|
| 356 | - ); |
|
| 357 | - |
|
| 358 | - if (!$champs) return false; |
|
| 359 | - |
|
| 360 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 361 | - $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix'])?$options['prefix']:'ctr_'); |
|
| 362 | - |
|
| 363 | - return $conflits; |
|
| 300 | + include_spip('inc/filtres'); |
|
| 301 | + |
|
| 302 | + $table_objet = table_objet($type); |
|
| 303 | + $spip_table_objet = table_objet_sql($type); |
|
| 304 | + $id_table_objet = id_table_objet($type); |
|
| 305 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 306 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 307 | + |
|
| 308 | + // Appels incomplets (sans $c) |
|
| 309 | + if (!is_array($c)) { |
|
| 310 | + foreach($desc['field'] as $champ=>$ignore) |
|
| 311 | + if(_request($champ)) |
|
| 312 | + $c[$champ] = _request($champ); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 316 | + // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 317 | + // il faut passer par instituer_XX() |
|
| 318 | + // TODO: faut-il passer ces variables interdites |
|
| 319 | + // dans un fichier de description separe ? |
|
| 320 | + unset($c['statut']); |
|
| 321 | + unset($c['id_parent']); |
|
| 322 | + unset($c['id_rubrique']); |
|
| 323 | + unset($c['id_secteur']); |
|
| 324 | + |
|
| 325 | + // Gerer les champs non vides |
|
| 326 | + if (isset($options['nonvide']) AND is_array($options['nonvide'])) |
|
| 327 | + foreach ($options['nonvide'] as $champ => $sinon) |
|
| 328 | + if ($c[$champ] === '') |
|
| 329 | + $c[$champ] = $sinon; |
|
| 330 | + |
|
| 331 | + // N'accepter que les champs qui existent |
|
| 332 | + // TODO: ici aussi on peut valider les contenus |
|
| 333 | + // en fonction du type |
|
| 334 | + $champs = array(); |
|
| 335 | + foreach($desc['field'] as $champ => $ignore) |
|
| 336 | + if (isset($c[$champ])) |
|
| 337 | + $champs[$champ] = $c[$champ]; |
|
| 338 | + |
|
| 339 | + // Nettoyer les valeurs |
|
| 340 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 341 | + |
|
| 342 | + // Envoyer aux plugins |
|
| 343 | + $champs = pipeline('pre_edition', |
|
| 344 | + array( |
|
| 345 | + 'args' => array( |
|
| 346 | + 'table' => $spip_table_objet, // compatibilite |
|
| 347 | + 'table_objet' => $table_objet, |
|
| 348 | + 'spip_table_objet' => $spip_table_objet, |
|
| 349 | + 'type' =>$type, |
|
| 350 | + 'id_objet' => $id, |
|
| 351 | + 'champs' => isset($options['champs'])?$options['champs']:array(), // [doc] c'est quoi ? |
|
| 352 | + 'action' => 'controler' |
|
| 353 | + ), |
|
| 354 | + 'data' => $champs |
|
| 355 | + ) |
|
| 356 | + ); |
|
| 357 | + |
|
| 358 | + if (!$champs) return false; |
|
| 359 | + |
|
| 360 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 361 | + $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix'])?$options['prefix']:'ctr_'); |
|
| 362 | + |
|
| 363 | + return $conflits; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | // Controle la liste des md5 envoyes, supprime les inchanges, |
| 367 | 367 | // signale les modifies depuis telle date |
| 368 | 368 | // http://doc.spip.org/@controler_md5 |
| 369 | 369 | function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') { |
| 370 | - $table_objet = table_objet($type); |
|
| 371 | - $spip_table_objet = table_objet_sql($type); |
|
| 372 | - $id_table_objet = id_table_objet($type); |
|
| 373 | - |
|
| 374 | - // Controle des MD5 envoyes |
|
| 375 | - // On elimine les donnees non modifiees par le formulaire (mais |
|
| 376 | - // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 377 | - foreach ($champs as $key => $val) { |
|
| 378 | - if (isset($ctr[$prefix.$key]) AND $m = $ctr[$prefix.$key]) { |
|
| 379 | - if ($m == md5($val)) |
|
| 380 | - unset ($champs[$key]); |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - if (!$champs) return; |
|
| 384 | - |
|
| 385 | - // On veut savoir si notre modif va avoir un impact |
|
| 386 | - // par rapport aux donnees contenues dans la base |
|
| 387 | - // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 388 | - $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 389 | - $intact = true; |
|
| 390 | - foreach ($champs as $ch => $val) |
|
| 391 | - $intact &= ($s[$ch] == $val); |
|
| 392 | - if ($intact) return; |
|
| 393 | - |
|
| 394 | - // Detection de conflits : |
|
| 395 | - // On verifie si notre modif ne provient pas d'un formulaire |
|
| 396 | - // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 397 | - // on compare a ce qui est dans la base, et on bloque en cas |
|
| 398 | - // de conflit. |
|
| 399 | - $ctrh = $ctrq = $conflits = array(); |
|
| 400 | - foreach (array_keys($champs) as $key) { |
|
| 401 | - if (isset($ctr[$prefix.$key]) AND $m = $ctr[$prefix.$key]) { |
|
| 402 | - $ctrh[$key] = $m; |
|
| 403 | - $ctrq[] = $key; |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - if ($ctrq) { |
|
| 407 | - $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 408 | - foreach ($ctrh as $key => $m) { |
|
| 409 | - if ($m != md5($ctrq[$key]) |
|
| 410 | - AND $champs[$key] !== $ctrq[$key]) { |
|
| 411 | - $conflits[$key] = array( |
|
| 412 | - 'base' => $ctrq[$key], |
|
| 413 | - 'post' => $champs[$key] |
|
| 414 | - ); |
|
| 415 | - unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - return $conflits; |
|
| 370 | + $table_objet = table_objet($type); |
|
| 371 | + $spip_table_objet = table_objet_sql($type); |
|
| 372 | + $id_table_objet = id_table_objet($type); |
|
| 373 | + |
|
| 374 | + // Controle des MD5 envoyes |
|
| 375 | + // On elimine les donnees non modifiees par le formulaire (mais |
|
| 376 | + // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 377 | + foreach ($champs as $key => $val) { |
|
| 378 | + if (isset($ctr[$prefix.$key]) AND $m = $ctr[$prefix.$key]) { |
|
| 379 | + if ($m == md5($val)) |
|
| 380 | + unset ($champs[$key]); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + if (!$champs) return; |
|
| 384 | + |
|
| 385 | + // On veut savoir si notre modif va avoir un impact |
|
| 386 | + // par rapport aux donnees contenues dans la base |
|
| 387 | + // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 388 | + $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 389 | + $intact = true; |
|
| 390 | + foreach ($champs as $ch => $val) |
|
| 391 | + $intact &= ($s[$ch] == $val); |
|
| 392 | + if ($intact) return; |
|
| 393 | + |
|
| 394 | + // Detection de conflits : |
|
| 395 | + // On verifie si notre modif ne provient pas d'un formulaire |
|
| 396 | + // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 397 | + // on compare a ce qui est dans la base, et on bloque en cas |
|
| 398 | + // de conflit. |
|
| 399 | + $ctrh = $ctrq = $conflits = array(); |
|
| 400 | + foreach (array_keys($champs) as $key) { |
|
| 401 | + if (isset($ctr[$prefix.$key]) AND $m = $ctr[$prefix.$key]) { |
|
| 402 | + $ctrh[$key] = $m; |
|
| 403 | + $ctrq[] = $key; |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + if ($ctrq) { |
|
| 407 | + $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 408 | + foreach ($ctrh as $key => $m) { |
|
| 409 | + if ($m != md5($ctrq[$key]) |
|
| 410 | + AND $champs[$key] !== $ctrq[$key]) { |
|
| 411 | + $conflits[$key] = array( |
|
| 412 | + 'base' => $ctrq[$key], |
|
| 413 | + 'post' => $champs[$key] |
|
| 414 | + ); |
|
| 415 | + unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + return $conflits; |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | // http://doc.spip.org/@display_conflit_champ |
| 424 | 424 | function display_conflit_champ($x) { |
| 425 | - if (strstr($x, "\n") OR strlen($x)>80) |
|
| 426 | - return "<textarea style='width:99%; height:10em;'>".entites_html($x)."</textarea>\n"; |
|
| 427 | - else |
|
| 428 | - return "<input type='text' size='40' style='width:99%' value=\"".entites_html($x)."\" />\n"; |
|
| 425 | + if (strstr($x, "\n") OR strlen($x)>80) |
|
| 426 | + return "<textarea style='width:99%; height:10em;'>".entites_html($x)."</textarea>\n"; |
|
| 427 | + else |
|
| 428 | + return "<input type='text' size='40' style='width:99%' value=\"".entites_html($x)."\" />\n"; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | // http://doc.spip.org/@signaler_conflits_edition |
| 432 | 432 | function signaler_conflits_edition($conflits, $redirect='') { |
| 433 | - include_spip('inc/minipres'); |
|
| 434 | - include_spip('inc/revisions'); |
|
| 435 | - include_spip('afficher_diff/champ'); |
|
| 436 | - include_spip('inc/suivi_versions'); |
|
| 437 | - include_spip('inc/diff'); |
|
| 438 | - foreach ($conflits as $champ=>$a) { |
|
| 439 | - // probleme de stockage ou conflit d'edition ? |
|
| 440 | - $base = isset($a['save']) ? $a['save'] : $a['base']; |
|
| 441 | - |
|
| 442 | - $diff = new Diff(new DiffTexte); |
|
| 443 | - $n = preparer_diff($a['post']); |
|
| 444 | - $o = preparer_diff($base); |
|
| 445 | - $d = propre_diff( |
|
| 446 | - afficher_para_modifies(afficher_diff($diff->comparer($n,$o)))); |
|
| 447 | - |
|
| 448 | - $titre = isset($a['save']) ? _L('Echec lors de l\'enregistrement du champ @champ@', array('champ' => $champ)) : $champ; |
|
| 449 | - |
|
| 450 | - $diffs[] = "<h2>$titre</h2>\n" |
|
| 451 | - . "<h3>"._T('info_conflit_edition_differences')."</h3>\n" |
|
| 452 | - . "<div style='max-height:8em; overflow: auto; width:99%;'>".$d."</div>\n" |
|
| 453 | - . "<h4>"._T('info_conflit_edition_votre_version')."</h4>" |
|
| 454 | - . display_conflit_champ($a['post']) |
|
| 455 | - . "<h4>"._T('info_conflit_edition_version_enregistree')."</h4>" |
|
| 456 | - . display_conflit_champ($base); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - if ($redirect) { |
|
| 460 | - $id = uniqid(rand()); |
|
| 461 | - $redirect = "<form action='$redirect' method='get' |
|
| 433 | + include_spip('inc/minipres'); |
|
| 434 | + include_spip('inc/revisions'); |
|
| 435 | + include_spip('afficher_diff/champ'); |
|
| 436 | + include_spip('inc/suivi_versions'); |
|
| 437 | + include_spip('inc/diff'); |
|
| 438 | + foreach ($conflits as $champ=>$a) { |
|
| 439 | + // probleme de stockage ou conflit d'edition ? |
|
| 440 | + $base = isset($a['save']) ? $a['save'] : $a['base']; |
|
| 441 | + |
|
| 442 | + $diff = new Diff(new DiffTexte); |
|
| 443 | + $n = preparer_diff($a['post']); |
|
| 444 | + $o = preparer_diff($base); |
|
| 445 | + $d = propre_diff( |
|
| 446 | + afficher_para_modifies(afficher_diff($diff->comparer($n,$o)))); |
|
| 447 | + |
|
| 448 | + $titre = isset($a['save']) ? _L('Echec lors de l\'enregistrement du champ @champ@', array('champ' => $champ)) : $champ; |
|
| 449 | + |
|
| 450 | + $diffs[] = "<h2>$titre</h2>\n" |
|
| 451 | + . "<h3>"._T('info_conflit_edition_differences')."</h3>\n" |
|
| 452 | + . "<div style='max-height:8em; overflow: auto; width:99%;'>".$d."</div>\n" |
|
| 453 | + . "<h4>"._T('info_conflit_edition_votre_version')."</h4>" |
|
| 454 | + . display_conflit_champ($a['post']) |
|
| 455 | + . "<h4>"._T('info_conflit_edition_version_enregistree')."</h4>" |
|
| 456 | + . display_conflit_champ($base); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + if ($redirect) { |
|
| 460 | + $id = uniqid(rand()); |
|
| 461 | + $redirect = "<form action='$redirect' method='get' |
|
| 462 | 462 | id='$id' |
| 463 | 463 | style='float:".$GLOBALS['spip_lang_right']."; margin-top:2em;'>\n" |
| 464 | - .form_hidden($redirect) |
|
| 465 | - ."<input type='submit' value='"._T('icone_retour')."' /> |
|
| 464 | + .form_hidden($redirect) |
|
| 465 | + ."<input type='submit' value='"._T('icone_retour')."' /> |
|
| 466 | 466 | </form>\n"; |
| 467 | 467 | |
| 468 | - // pour les documents, on est probablement en ajax : il faut ajaxer |
|
| 469 | - if (_AJAX) |
|
| 470 | - $redirect .= '<script type="text/javascript">' |
|
| 471 | - .'setTimeout(function(){$("#'.$id.'") |
|
| 468 | + // pour les documents, on est probablement en ajax : il faut ajaxer |
|
| 469 | + if (_AJAX) |
|
| 470 | + $redirect .= '<script type="text/javascript">' |
|
| 471 | + .'setTimeout(function(){$("#'.$id.'") |
|
| 472 | 472 | .ajaxForm({target:$("#'.$id.'").parent()}); |
| 473 | 473 | }, 200);' |
| 474 | - ."</script>\n"; |
|
| 474 | + ."</script>\n"; |
|
| 475 | 475 | |
| 476 | - } |
|
| 476 | + } |
|
| 477 | 477 | |
| 478 | - echo minipres( |
|
| 479 | - _T('titre_conflit_edition'), |
|
| 478 | + echo minipres( |
|
| 479 | + _T('titre_conflit_edition'), |
|
| 480 | 480 | |
| 481 | - '<style> |
|
| 481 | + '<style> |
|
| 482 | 482 | .diff-para-deplace { background: #e8e8ff; } |
| 483 | 483 | .diff-para-ajoute { background: #d0ffc0; color: #000; } |
| 484 | 484 | .diff-para-supprime { background: #ffd0c0; color: #904040; text-decoration: line-through; } |
@@ -489,14 +489,14 @@ discard block |
||
| 489 | 489 | .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; } |
| 490 | 490 | .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; } |
| 491 | 491 | </style>' |
| 492 | - .'<p>'._T('info_conflit_edition_avis_non_sauvegarde').'</p>' |
|
| 493 | - .'<p>'._T('texte_conflit_edition_correction').'</p>' |
|
| 494 | - ."<div style='text-align:".$GLOBALS['spip_lang_left'].";'>" |
|
| 495 | - . join("\n",$diffs) |
|
| 496 | - ."</div>\n" |
|
| 497 | - |
|
| 498 | - . $redirect |
|
| 499 | - ); |
|
| 492 | + .'<p>'._T('info_conflit_edition_avis_non_sauvegarde').'</p>' |
|
| 493 | + .'<p>'._T('texte_conflit_edition_correction').'</p>' |
|
| 494 | + ."<div style='text-align:".$GLOBALS['spip_lang_left'].";'>" |
|
| 495 | + . join("\n",$diffs) |
|
| 496 | + ."</div>\n" |
|
| 497 | + |
|
| 498 | + . $redirect |
|
| 499 | + ); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | ?> |
@@ -21,36 +21,36 @@ discard block |
||
| 21 | 21 | // http://doc.spip.org/@inc_meta_dist |
| 22 | 22 | function inc_meta_dist($table='meta') |
| 23 | 23 | { |
| 24 | - // Lire les meta, en cache si present, valide et lisible |
|
| 25 | - // en cas d'install ne pas faire confiance au meta_cache eventuel |
|
| 26 | - $cache = cache_meta($table); |
|
| 27 | - |
|
| 28 | - if ((_request('exec')!=='install' OR !test_espace_prive()) |
|
| 29 | - AND $new = jeune_fichier($cache, _META_CACHE_TIME) |
|
| 30 | - AND lire_fichier_securise($cache, $meta) |
|
| 31 | - AND $meta = @unserialize($meta)) |
|
| 32 | - $GLOBALS[$table] = $meta; |
|
| 33 | - |
|
| 34 | - if (isset($GLOBALS[$table]['touch']) |
|
| 35 | - AND ($GLOBALS[$table]['touch']<time()-_META_CACHE_TIME)) |
|
| 36 | - $GLOBALS[$table] = array(); |
|
| 37 | - // sinon lire en base |
|
| 38 | - if (!$GLOBALS[$table]) $new = !lire_metas($table); |
|
| 39 | - |
|
| 40 | - // renouveller l'alea general si trop vieux ou sur demande explicite |
|
| 41 | - if ((test_espace_prive() || isset($_GET['renouvelle_alea'])) |
|
| 42 | - AND $GLOBALS[$table] |
|
| 43 | - AND (time() > _RENOUVELLE_ALEA + $GLOBALS['meta']['alea_ephemere_date'])) { |
|
| 44 | - // si on n'a pas l'acces en ecriture sur le cache, |
|
| 45 | - // ne pas renouveller l'alea sinon le cache devient faux |
|
| 46 | - if (supprimer_fichier($cache)) { |
|
| 47 | - include_spip('inc/acces'); |
|
| 48 | - renouvelle_alea(); |
|
| 49 | - $new = false; |
|
| 50 | - } else spip_log("impossible d'ecrire dans " . $cache); |
|
| 51 | - } |
|
| 52 | - // et refaire le cache si on a du lire en base |
|
| 53 | - if (!$new) touch_meta(false, $table); |
|
| 24 | + // Lire les meta, en cache si present, valide et lisible |
|
| 25 | + // en cas d'install ne pas faire confiance au meta_cache eventuel |
|
| 26 | + $cache = cache_meta($table); |
|
| 27 | + |
|
| 28 | + if ((_request('exec')!=='install' OR !test_espace_prive()) |
|
| 29 | + AND $new = jeune_fichier($cache, _META_CACHE_TIME) |
|
| 30 | + AND lire_fichier_securise($cache, $meta) |
|
| 31 | + AND $meta = @unserialize($meta)) |
|
| 32 | + $GLOBALS[$table] = $meta; |
|
| 33 | + |
|
| 34 | + if (isset($GLOBALS[$table]['touch']) |
|
| 35 | + AND ($GLOBALS[$table]['touch']<time()-_META_CACHE_TIME)) |
|
| 36 | + $GLOBALS[$table] = array(); |
|
| 37 | + // sinon lire en base |
|
| 38 | + if (!$GLOBALS[$table]) $new = !lire_metas($table); |
|
| 39 | + |
|
| 40 | + // renouveller l'alea general si trop vieux ou sur demande explicite |
|
| 41 | + if ((test_espace_prive() || isset($_GET['renouvelle_alea'])) |
|
| 42 | + AND $GLOBALS[$table] |
|
| 43 | + AND (time() > _RENOUVELLE_ALEA + $GLOBALS['meta']['alea_ephemere_date'])) { |
|
| 44 | + // si on n'a pas l'acces en ecriture sur le cache, |
|
| 45 | + // ne pas renouveller l'alea sinon le cache devient faux |
|
| 46 | + if (supprimer_fichier($cache)) { |
|
| 47 | + include_spip('inc/acces'); |
|
| 48 | + renouvelle_alea(); |
|
| 49 | + $new = false; |
|
| 50 | + } else spip_log("impossible d'ecrire dans " . $cache); |
|
| 51 | + } |
|
| 52 | + // et refaire le cache si on a du lire en base |
|
| 53 | + if (!$new) touch_meta(false, $table); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // fonctions aussi appelees a l'install ==> spip_query en premiere requete |
@@ -59,101 +59,101 @@ discard block |
||
| 59 | 59 | // http://doc.spip.org/@lire_metas |
| 60 | 60 | function lire_metas($table='meta') { |
| 61 | 61 | |
| 62 | - if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) { |
|
| 63 | - include_spip('base/abstract_sql'); |
|
| 64 | - $GLOBALS[$table] = array(); |
|
| 65 | - while ($row = sql_fetch($result)) |
|
| 66 | - $GLOBALS[$table][$row['nom']] = $row['valeur']; |
|
| 62 | + if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) { |
|
| 63 | + include_spip('base/abstract_sql'); |
|
| 64 | + $GLOBALS[$table] = array(); |
|
| 65 | + while ($row = sql_fetch($result)) |
|
| 66 | + $GLOBALS[$table][$row['nom']] = $row['valeur']; |
|
| 67 | 67 | sql_free($result); |
| 68 | 68 | |
| 69 | - if (!$GLOBALS[$table]['charset'] |
|
| 70 | - OR $GLOBALS[$table]['charset']=='_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install |
|
| 71 | - ) |
|
| 72 | - ecrire_meta('charset', _DEFAULT_CHARSET, NULL, $table); |
|
| 73 | - |
|
| 74 | - // noter cette table de configuration dans les meta de SPIP |
|
| 75 | - if ($table!=='meta') { |
|
| 76 | - $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 77 | - if (!$liste) |
|
| 78 | - $liste = array(); |
|
| 79 | - if (!in_array($table, $liste)) { |
|
| 80 | - $liste[] = $table; |
|
| 81 | - ecrire_meta('tables_config', serialize($liste)); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - return $GLOBALS[$table]; |
|
| 69 | + if (!$GLOBALS[$table]['charset'] |
|
| 70 | + OR $GLOBALS[$table]['charset']=='_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install |
|
| 71 | + ) |
|
| 72 | + ecrire_meta('charset', _DEFAULT_CHARSET, NULL, $table); |
|
| 73 | + |
|
| 74 | + // noter cette table de configuration dans les meta de SPIP |
|
| 75 | + if ($table!=='meta') { |
|
| 76 | + $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 77 | + if (!$liste) |
|
| 78 | + $liste = array(); |
|
| 79 | + if (!in_array($table, $liste)) { |
|
| 80 | + $liste[] = $table; |
|
| 81 | + ecrire_meta('tables_config', serialize($liste)); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + return $GLOBALS[$table]; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // Mettre en cache la liste des meta, sauf les valeurs sensibles |
| 89 | 89 | // pour qu'elles ne soient pas visibiles dans un fichier.souvent en 777 |
| 90 | 90 | // http://doc.spip.org/@touch_meta |
| 91 | 91 | function touch_meta($antidate= false, $table='meta'){ |
| 92 | - $file = cache_meta($table); |
|
| 93 | - if (!$antidate OR !@touch($file, $antidate)) { |
|
| 94 | - $r = $GLOBALS[$table]; |
|
| 95 | - unset($r['alea_ephemere']); |
|
| 96 | - unset($r['alea_ephemere_ancien']); |
|
| 97 | - // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables |
|
| 98 | - // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique |
|
| 99 | - // meme si son squelette est en cache |
|
| 100 | - //unset($r['secret_du_site']); |
|
| 101 | - if ($antidate) $r['touch']= $antidate; |
|
| 102 | - ecrire_fichier_securise($file, serialize($r)); |
|
| 103 | - } |
|
| 92 | + $file = cache_meta($table); |
|
| 93 | + if (!$antidate OR !@touch($file, $antidate)) { |
|
| 94 | + $r = $GLOBALS[$table]; |
|
| 95 | + unset($r['alea_ephemere']); |
|
| 96 | + unset($r['alea_ephemere_ancien']); |
|
| 97 | + // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables |
|
| 98 | + // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique |
|
| 99 | + // meme si son squelette est en cache |
|
| 100 | + //unset($r['secret_du_site']); |
|
| 101 | + if ($antidate) $r['touch']= $antidate; |
|
| 102 | + ecrire_fichier_securise($file, serialize($r)); |
|
| 103 | + } |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // http://doc.spip.org/@effacer_meta |
| 107 | 107 | function effacer_meta($nom, $table='meta') { |
| 108 | - // section critique sur le cache: |
|
| 109 | - // l'invalider avant et apres la MAJ de la BD |
|
| 110 | - // c'est un peu moins bien qu'un vrai verrou mais ca suffira |
|
| 111 | - // et utiliser une statique pour eviter des acces disques a repetition |
|
| 112 | - static $touch = array(); |
|
| 113 | - $antidate = time() - (_META_CACHE_TIME<<4); |
|
| 114 | - if (!isset($touch[$table])) {touch_meta($antidate, $table);} |
|
| 115 | - sql_delete('spip_' . $table, "nom='$nom'"); |
|
| 116 | - unset($GLOBALS[$table][$nom]); |
|
| 117 | - if (!isset($touch[$table])) {touch_meta($antidate, $table); $touch[$table] = false;} |
|
| 108 | + // section critique sur le cache: |
|
| 109 | + // l'invalider avant et apres la MAJ de la BD |
|
| 110 | + // c'est un peu moins bien qu'un vrai verrou mais ca suffira |
|
| 111 | + // et utiliser une statique pour eviter des acces disques a repetition |
|
| 112 | + static $touch = array(); |
|
| 113 | + $antidate = time() - (_META_CACHE_TIME<<4); |
|
| 114 | + if (!isset($touch[$table])) {touch_meta($antidate, $table);} |
|
| 115 | + sql_delete('spip_' . $table, "nom='$nom'"); |
|
| 116 | + unset($GLOBALS[$table][$nom]); |
|
| 117 | + if (!isset($touch[$table])) {touch_meta($antidate, $table); $touch[$table] = false;} |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // http://doc.spip.org/@ecrire_meta |
| 121 | 121 | function ecrire_meta($nom, $valeur, $importable = NULL, $table='meta') { |
| 122 | 122 | |
| 123 | - static $touch = array(); |
|
| 124 | - if (!$nom) return; |
|
| 125 | - include_spip('base/abstract_sql'); |
|
| 126 | - $res = sql_select("*",'spip_' . $table,"nom=" . sql_quote($nom),'','','','','','continue'); |
|
| 127 | - // table pas encore installee, travailler en php seulement |
|
| 128 | - if (!$res) { |
|
| 129 | - $GLOBALS[$table][$nom] = $valeur; |
|
| 130 | - return; |
|
| 131 | - } |
|
| 132 | - $row = sql_fetch($res); |
|
| 123 | + static $touch = array(); |
|
| 124 | + if (!$nom) return; |
|
| 125 | + include_spip('base/abstract_sql'); |
|
| 126 | + $res = sql_select("*",'spip_' . $table,"nom=" . sql_quote($nom),'','','','','','continue'); |
|
| 127 | + // table pas encore installee, travailler en php seulement |
|
| 128 | + if (!$res) { |
|
| 129 | + $GLOBALS[$table][$nom] = $valeur; |
|
| 130 | + return; |
|
| 131 | + } |
|
| 132 | + $row = sql_fetch($res); |
|
| 133 | 133 | sql_free($res); |
| 134 | 134 | |
| 135 | - // ne pas invalider le cache si affectation a l'identique |
|
| 136 | - // (tant pis si impt aurait du changer) |
|
| 137 | - if ($row AND $valeur == $row['valeur'] AND $GLOBALS[$table][$nom] == $valeur) return; |
|
| 138 | - |
|
| 139 | - $GLOBALS[$table][$nom] = $valeur; |
|
| 140 | - // cf effacer pour comprendre le double touch |
|
| 141 | - $antidate = time() - (_META_CACHE_TIME<<1); |
|
| 142 | - if (!isset($touch[$table])) {touch_meta($antidate, $table);} |
|
| 143 | - $r = array('nom' => $nom, 'valeur' => $valeur); |
|
| 144 | - // Gaffe aux tables sans impt (vieilles versions de SPIP notamment) |
|
| 145 | - if ($importable AND isset($row['impt'])) $r['impt'] = $importable; |
|
| 146 | - if ($row) { |
|
| 147 | - sql_updateq('spip_' . $table, $r,"nom=" . sql_quote($nom)); |
|
| 148 | - } else { |
|
| 149 | - sql_insertq('spip_' . $table, $r); |
|
| 150 | - } |
|
| 151 | - if (!isset($touch[$table])) {touch_meta($antidate, $table); $touch[$table] = false;} |
|
| 135 | + // ne pas invalider le cache si affectation a l'identique |
|
| 136 | + // (tant pis si impt aurait du changer) |
|
| 137 | + if ($row AND $valeur == $row['valeur'] AND $GLOBALS[$table][$nom] == $valeur) return; |
|
| 138 | + |
|
| 139 | + $GLOBALS[$table][$nom] = $valeur; |
|
| 140 | + // cf effacer pour comprendre le double touch |
|
| 141 | + $antidate = time() - (_META_CACHE_TIME<<1); |
|
| 142 | + if (!isset($touch[$table])) {touch_meta($antidate, $table);} |
|
| 143 | + $r = array('nom' => $nom, 'valeur' => $valeur); |
|
| 144 | + // Gaffe aux tables sans impt (vieilles versions de SPIP notamment) |
|
| 145 | + if ($importable AND isset($row['impt'])) $r['impt'] = $importable; |
|
| 146 | + if ($row) { |
|
| 147 | + sql_updateq('spip_' . $table, $r,"nom=" . sql_quote($nom)); |
|
| 148 | + } else { |
|
| 149 | + sql_insertq('spip_' . $table, $r); |
|
| 150 | + } |
|
| 151 | + if (!isset($touch[$table])) {touch_meta($antidate, $table); $touch[$table] = false;} |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | function cache_meta($table='meta') |
| 155 | 155 | { |
| 156 | - return ($table=='meta') ? _FILE_META : (_DIR_CACHE . $table . '.php'); |
|
| 156 | + return ($table=='meta') ? _FILE_META : (_DIR_CACHE . $table . '.php'); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -161,14 +161,14 @@ discard block |
||
| 161 | 161 | * @param string $table |
| 162 | 162 | */ |
| 163 | 163 | function installer_table_meta($table) { |
| 164 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 165 | - if (!$trouver_table("spip_$table")) { |
|
| 166 | - include_spip('base/auxiliaires'); |
|
| 167 | - include_spip('base/create'); |
|
| 168 | - creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false); |
|
| 169 | - $trouver_table(''); |
|
| 170 | - } |
|
| 171 | - lire_metas($table); |
|
| 164 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 165 | + if (!$trouver_table("spip_$table")) { |
|
| 166 | + include_spip('base/auxiliaires'); |
|
| 167 | + include_spip('base/create'); |
|
| 168 | + creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false); |
|
| 169 | + $trouver_table(''); |
|
| 170 | + } |
|
| 171 | + lire_metas($table); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -179,14 +179,14 @@ discard block |
||
| 179 | 179 | * @param bool $force |
| 180 | 180 | */ |
| 181 | 181 | function supprimer_table_meta($table, $force=false) { |
| 182 | - if ($table=='meta') return; // interdit ! |
|
| 183 | - |
|
| 184 | - if ($force OR !sql_countsel("spip_$table")) { |
|
| 185 | - unset($GLOBALS[$table]); |
|
| 186 | - sql_drop_table("spip_$table"); |
|
| 187 | - // vider le cache des tables |
|
| 188 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 189 | - $trouver_table(''); |
|
| 190 | - } |
|
| 182 | + if ($table=='meta') return; // interdit ! |
|
| 183 | + |
|
| 184 | + if ($force OR !sql_countsel("spip_$table")) { |
|
| 185 | + unset($GLOBALS[$table]); |
|
| 186 | + sql_drop_table("spip_$table"); |
|
| 187 | + // vider le cache des tables |
|
| 188 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 189 | + $trouver_table(''); |
|
| 190 | + } |
|
| 191 | 191 | } |
| 192 | 192 | ?> |